13.07.2015 Views

Fortran 90/95 Programming Manual

Fortran 90/95 Programming Manual

Fortran 90/95 Programming Manual

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>Fortran</strong> <strong>90</strong>/<strong>95</strong> <strong>Programming</strong> <strong>Manual</strong>1. Getting startedType, compile and run the following program (call the file hello.f<strong>90</strong>):program hello! this programs prints "hello world!" to the screenimplicit noneprint * , "Hello world!"end program helloNote the following:••••••a program starts with program program_nameit ends with end program program_nameprint * displays data (in this case, the character string “Hello, world!”) on thescreen.all characters after the exclamation mark (!) (except in a character string) areignored by the compiler. It is good programming practice to include comments.Comments can also start after a statement, for example:print * , “Hello world!” ! this line prints the message “Hello world!”Note the indentation. Indentation is essential to keep a program readable.Additionally, empty lines are allowed and can help to make the program readable.<strong>Fortran</strong> <strong>90</strong> allows both upper and lowercase letters (unlike FORTRAN 77, inwhich only uppercase was allowed).2. Types, Variables, Constants, OperatorsNames in <strong>Fortran</strong> <strong>90</strong>A name or “identifier” in <strong>Fortran</strong> must adhere to fixed rules. They cannot be longer than31 characters, must be composed of alphanumeric characters (all the letters of thealphabet, and the digits 0 to 9) and underscores ( _ ), and the first character must be aletter. Identifiers are case-insensitive (except in character strings like “Hello world!” inthe example above); Thus, PRINT and print are completely identical.TypesA variable is a data object whose value can be defined and redefined (in contrast toconstants, see below). Variables and constants have a type, which can be one of the fiveintrinsic types, or a derived type. Intrinsic types are part of the <strong>Fortran</strong> language. Thereare five different intrinsic types. In <strong>Fortran</strong> <strong>90</strong>, there is additionally the possibility ofdefining derived types, which are defined by the user (see below). The five intrinsictypes are:Integer TypeFor integer values (like 1, 2, 3, 0, -1, -2, …).4

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!