ABC
ABC
-
Identifiers (names of variables, main program unit, procedures, etc.) : 1 to 63 characters,
ABC...Z
orabc...z
,0 1 … 9
, underscore_
, beginning with a letter. For example:pressure
,p_surface, t0
but not:température
2nd_level
-
Nota bene: unlike other languages, Fortran does not distinguish lower and upper case.
x
andX
, for example, refer to the same variable. -
Some special characters play a role in Fortran, namely the blank character and:
= + - * / () [ ] , . ' : ! “ % & < >
-
Other special characters have no meaning in Fortran:
~ \ { } ? `` ^ | $ ## @
So you can only find them in character strings or comments.
-
You should be careful not to use keywords or predefined identifiers of the language for your own identifiers. Cf. list of Fortran keywords and list of intrinsic procedures (§§ 13.7) (126 intrinsic procedures).
-
132 characters at most per line. You can write a statement on several lines: type an ampersand
&
at the end of a line to be continued. -
Comments start after the exclamation mark
!
Alone on one line or at the end of a line, after a statement.
A basic whole program
A text file containing a simple Fortran program looks like this:
PROGRAM name
{declarations}
executable constructs
END PROGRAM name
Advice: use the same name after the keyword program
and for the name
of the file, except there should be a suffix .f
or .f90
(or .F
or .F90
if your file contains pre-processor directives) in the name
of the file.
Note that you can stop in the middle of a program with the following statement:
stop 1
This statement returns the code 1 to the shell that executes your program, so the shell knows that something went wrong.