Styleguide
Jump to navigation
Jump to search
General
- Line-endings: all line-endings should be Windows line-endings (CR-LF), git needs to be set to not change this:
git config --global core.autocrlf true
[1] - Encoding: for historical reasons, all source files should be encoded in ISO-8859-1
Fortran
- Indenting: three-character indents, tabs saved as spaces
- Keywords (e.g.
IF
,FUNCTION
,INTEGER
etc.) should be capitalized. - The keywords
END IF
,END DO
etc. should be written with a space as shown here.
Operators
The modern form of operator syntax should be preferred (e.g. >=
rather than .GE.
). A lot of code currently still uses the old format, though.
Description | Old syntax | New syntax |
---|---|---|
Less than | .LT. |
<
|
Less than or equal to | .LE. |
<=
|
Equal to | .EQ. |
==
|
Not equal to | .NE. |
/=
|
Greater than | .GT. |
>
|
Greater than or equal to | .GE. |
>=
|
General formatting
NOTE: There is still some debate about how code should be formatted. We might look into using an autoformatter such as fprettify in the future.
Funktionen sollten folgendermaßen formatiert werden:
- Vorschlag A
CXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX c Funktionsbeschreibung FUNCTION FOO (BAR) RESULT (LOK) c ................................................................. USE MODULE INTEGER i LOGICAL LOK character(*) str c ................................................................. LOK = .FALSE. c Kommentar DO i = 1, 10 CALL FOOBAR() IF (.NOT. LOK) GOTO 9999 END DO LOK = .TRUE. GOTO 10000 c ................................................................. c Fehlerbehandlung 9999 IF (.NOT. LOK) ERROR = FEHLER(50, ' ', ' ', 0) GOTO 10000 c ................................................................. 10000 RETURN END FUNCTION FOO cxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
- Vorschlag B
C---------------------------------------------------------------------- C MOD_Beispiel: Ein Modul ! c Anmerkung: blabla C---------------------------------------------------------------------- module MOD_Beispiel use MODULE_BLABLAblabla implicit none integer MemberInt contains C---------------------------------------------------------------------- C funktion FOO : Eine unsinnige zu Demonstrationszwecken erstellte virtuelle Fkt c Anmerkung: gibt false zurück wenn Fehler ! C---------------------------------------------------------------------- logical function FOO (BAR) use MODULE_BLABLA integer i logical LOK character(*) str FOO = .FALSE. !--------------------------------------------- !Abschnitt A !--------------------------------------------- do i = 1, 10 CALL FOOBAR() !Wenn fehler dann raus ! IF (.NOT. LOK) ERROR = FEHLER(50, ' ', ' ', 0) return end if end do FOO = .TRUE. return end function FOO end module MOD_Beispiel