A Trivial Program
- Fortran programs start with the
program <label>statement. - Fortran programs end with the
end program <label>statement. - Always use
implicit noneto prevent implicit typing for variables. - Fortran comments start with
!. - The
-oflag specifies the name of the compiled executable:<compiler_command> -o <executable_name> <source_file.f90>.
Variables
- There are 5 intrinsic data types for Fortran variables:
integer,real,complex,logical, andcharacter. - Fortran variables are declared with the syntax:
<variable_type> :: <variable_name> - Assign a value to a variable with the syntax:
<variable> = <value> - Never assign a value on the same line as a variable is declared.
This gives the variable the
saveattribute. - Parameters are variables whose value can’t be changed:
<variable_type>, parameter :: <variable_name> = <variable_value>.
Maths
- Operators in order of precedance:
**,*,/,+, and-. - List of intrinsic maths functions.
- A numeric variables kind specifies its floating-point precision. 32-bit, 64-bit etc.
- Always specify a kind when defining and assigning values to variables. Otherwise Fortran will default to the compilers single precision.
- Avoid mixing precision and kinds (e.g. integers with reals, or 32-bit with 64-bit). The compiler will implicitly convert the lower precision value to a higher precision value. This can slow down your programs.
Logic
- Th
Strings
- Th