include_and_use_in_fortran
This commit is contained in:
		| @@ -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' | ||||
| @@ -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 | ||||
| @@ -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 | ||||
		Reference in New Issue
	
	Block a user