Howto fortran
=============

# programm structure:
program myprog
code
end program myprog

# use modules:
use module_name

# cout:
print *, 'Hello'

# compile:
gfortran -o hello hello.f90

# comments:
! This is a comment
print *, 'Hello' ! This is a inline comment

# continue program line:
command line &
    continued line

# exponentials:
12e-5

# booleans:
.true.
.false.

# strings:
'This is a string'

# variable declaration:
INTEGER :: Zip, Total, counter
REAL :: average, x, difference
LOGICAL :: Condition, OK
COMPLEX :: Conjugate
CHARACTER(LEN=20) :: Answer, Quote
type(csv_file) :: f

# parameter declaration:
INTEGER, PARAMETER :: MAXIMUM = 10
REAL, PARAMETER :: PI = 3.1415926, E = 2.17828
LOGICAL, PARAMETER :: TRUE = .true., FALSE = .false.
CHARACTER(LEN=3), PARAMETER :: YES = “yes” ! Len = 3
CHARACTER(LEN=2), PARAMETER :: NO = “no” ! Len = 2
CHARACTER(LEN=*), PARAMETER :: PROMPT = “What do you want?” ! Len = 17

# operators:
arithmetic: +,-,*,/
rekational: <,<=,>,>=,==,/=
logical: .not.,.and.,.or.,.eqv.,.neqv.

# assignment:
variable=expression

# functions:
abs(x)
sqrt(x)
exp(x)
log(x)
int(x)
real(x)
min(x)
max(x)
mod(x)

# read from command line:
read (*,*) v1,v2,...,vn

# write to command line:
write (*,*) v1,v2,...,vn

# concatenate strings:
ans = string1 // string2

# define tab as seperator in csv-file:
CHARACTER :: tab
tab=CHAR(9)
write(unitnumber;*) var1,tab,var2

# open file to write:
OPEN(unit=1,file='result.csv',action='write',status='new',position='append')

# write to open file
WRITE(1,*) 'Hello'

# write to csv-file:
install flibs: https://sourceforge.net/projects/flibs/files/?source=navbar
USE csv_file
OPEN (unit=1, file='test.csv', ...)
CALL csv_write(1,variable1,variable2,.true.)
CLOSE (1)
alternativ:
!CALL csv_write(1,'Zeit','N1','N2',.true.)
!CALL f%add(['Zeit','N1','N2'])
!CALL f%next_row()
!CALL f%add([i,n1,n2],real_fmt='(F5.3)')
!CALL f%add(.true.)
!CALL f%next_row()

# close file:
CLOSE(1)

# do-loop:
DO index variable = start, end, step
       statements
   END DO

# while-loop:
DO WHILE (logical argument)
      statements
   END DO

# if:
IF (Bedingung) THEN
    code
END IF

http://www.pcc.qub.ac.uk/tec/courses/f90/ohp/header_ohMIF_10.html

https://en.wikibooks.org/wiki/Fortran/Hello_world