Already showed that, but here once more to remember.
Example program 1:
program myProgram use myModule implicit none integer :: a,b character(len=*) :: name end program myProgram
Make an example of interpolation use bash, after go to the modules
Compile your first Fortran PROGRAM Again
gfortran myfile.f90 -o program.exe
If you need to run your on a machine which gfortran is not installed
gfortran -static myfile.f -o program.exe
Compiling programs in more than one file
gfortran -c aux.f
gfortran -c diag.f
gfortran flow.f aux.o diag.o -o flow.exe
Compiler Command Options
Modules are one of the structural levels avaliable in Fortran program design:
Program >> Modules >> Procedures >> Statements
Program and statements already discussed in earlier parts.
module myModule ! Explicit is better than implicit, mostly use mySubModule ! makes you think use myIO only: write, read ! nicer way implitict none ! Makes all subprograms private private ! Turn necessary subprograms public explicitly public mySubroutine contains subroutine mySubroutine implicit none . . end subroutine mySubroutine function myFunction implicit none . . end function myFunction end module
subroutine mySubroutine implicit none . . end subroutine mySubroutine
function myFunction implicit none . . end function myFunction
How to pass arrays to subroutines/functions?
It is generally recommend to use assumed-shape as your default way to pass arrays. It will not copy the array.
Static Storage Assumption
save statements makes the local variables persistent, or using
option druing compilation treats each program unit (except those marked as
as if the
save statement were specified for every local variable and array referenced in it.
subroutine mySubroutine(array1, array2) implicit none real(8), intent(in) : array1(:) real(8), intent(out) : array2(:,:)
Using explicit-shape of the arrays might be required or more handy in some cases.
! Subroutine using assumed-shape subroutine mySubroutine1(x) implicit none write(*,*) lbound(x) ! Subroutine using explicit-shapee subroutine mySubroutine2(x, n) implicit none real(8), intent(in) :: x(n(1):n(2)) write(*,*) lbound(x)