====== Projects in Fortran ====== [[https://gcc.gnu.org/fortran/|Fortran]] is a general purpose, imperative programming language which is suited for numerical and scientific computations. It was introduced in mid 1950s. The GNU wiki site has a summary of the [[https://gcc.gnu.org/wiki/GFortranStandards| important standards for Fortran programmers]]. The main functionality has always been reading data, control of flow, looping, evaluating formulas (Hence the name Formula translation) and finally data output. Fortran strengths are simple matrix handling with the DIMENSION statement and simple loops with the DO statements. Following instructions are applicable for ''Mills'' and ''Farber'' clusters. ===== Source in one file ===== Since the Fortran language was designed to give the program control of the computer, it is easiest to put the entire program in one file. Add a compiler suite with a Fortran compile and a unix command to compile the source code. The Unix command will invoke the Fortran compiler, assembler and linker with the options derived from the command line arguments. **''vpkg_require''** //compiler package// **''$FC $FFLAGS''** //source file// **''$LDFLAGS $LDLIBS -o''** //executable// Where, ^^ part of commands ^^ examples ^^ || **''$FC''** || gcc/4.9, intel/2016, pgi/15.9 || || **''$FC''** || gfortran, ifort, pgfortran || || **''$FFLAGS''** || -g -Wall, -O2 || ||//source/ file// || mycode.f90, mycode.f || || **''$LDFLAGS $LDLIBS''** || blank, unless a library is in the environment || || //executable// || Usually the base name of source file || For example, vpkg_require gcc/4.9 gfortran -g -Wall prog.f90 -o prog ===== Source in many files ===== As projects get bigger it becomes important to think about organizing you source file into many files. For example, each subroutine could be in it own file. This will make it easier to debug separately and reuse the code in another project. This is easy if the files are in one directory and the compilation is independent. **''vpkg_require''** //compiler package// **''$FC $FFLAGS''** //source files// **''$LDFLAGS $LDLIBS -o''** //executable// Where, ^^ part of commands ^^ examples ^^ || **''$FC''** || gcc/4.9, intel/2016, pgi/15.9 || || **''$FC''** || gfortran, ifort, pgfortran || || **''$FFLAGS''** || -g -Wall, -O2 || ||//source files// || main.f90 sub.f90|| || **''$LDFLAGS $LDLIBS''** || blank, unless a library is in the environment || || //executable// || Usually the base name of source file || For example, vpkg_require intel/2016 ifort -g -O0 mymain.f90 oursub.f -o prog