diff --git a/language_learning/2023.07.19_include_and_use_in_fortran/example.f90 b/language_learning/2023.07.19_include_and_use_in_fortran/example.f90 new file mode 100644 index 0000000..d8495eb --- /dev/null +++ b/language_learning/2023.07.19_include_and_use_in_fortran/example.f90 @@ -0,0 +1,59 @@ + !this code is supported by the website: https://www.guanjihuan.com + !the newest version of this code is on the web page: https://www.guanjihuan.com/archives/34966 + + +module module_1 + + implicit none + contains ! 模块中包含以下子程序和函数 + + subroutine subroutine_1() ! 模块中的子程序 + write(*,*) 'test_1' + end subroutine subroutine_1 + + function function_1(x) result(y) ! 模块中的函数 + double precision x, y + y = 2.d0*x + end function function_1 + +end module module_1 + + +include 'example_include_1.f90' + + +program main + +use module_1 +use module_2 + +implicit none +double precision x, function_3, function_4 +x = 1.d0 + +call subroutine_1() +write(*,*) function_1(x) + +call subroutine_2() +write(*,*) function_2(x) + +call subroutine_3() +write(*,*) function_3(x) + +call subroutine_4() +write(*,*) function_4(x) + +end program main + + +subroutine subroutine_3() +write(*,*) 'test_3' +end subroutine subroutine_3 + + +function function_3(x) result(y) ! 模块中的函数 +double precision x, y +y = 8.d0*x +end function function_3 + +include 'example_include_2.f90' \ No newline at end of file diff --git a/language_learning/2023.07.19_include_and_use_in_fortran/example_include_1.f90 b/language_learning/2023.07.19_include_and_use_in_fortran/example_include_1.f90 new file mode 100644 index 0000000..ea2b2ab --- /dev/null +++ b/language_learning/2023.07.19_include_and_use_in_fortran/example_include_1.f90 @@ -0,0 +1,15 @@ +module module_2 + + implicit none + contains ! 模块中包含以下子程序和函数 + + subroutine subroutine_2() ! 模块中的子程序 + write(*,*) 'test_2' + end subroutine subroutine_2 + + function function_2(x) result(y) ! 模块中的函数 + double precision x, y + y = 4.d0*x + end function function_2 + +end module module_2 \ No newline at end of file diff --git a/language_learning/2023.07.19_include_and_use_in_fortran/example_include_2.f90 b/language_learning/2023.07.19_include_and_use_in_fortran/example_include_2.f90 new file mode 100644 index 0000000..2fc1bd0 --- /dev/null +++ b/language_learning/2023.07.19_include_and_use_in_fortran/example_include_2.f90 @@ -0,0 +1,9 @@ +subroutine subroutine_4() + write(*,*) 'test_4' +end subroutine subroutine_4 + + +function function_4(x) result(y) + double precision x, y + y = 16.d0*x +end function function_4 \ No newline at end of file