include_and_use_in_fortran

This commit is contained in:
guanjihuan 2023-07-19 16:10:52 +08:00
parent 1b6c125217
commit 11852442db
3 changed files with 83 additions and 0 deletions

View File

@ -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'

View File

@ -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

View File

@ -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