Fortran Cheat Sheet



  • Fortran Tutorial
  • Fortran Resources

Programming in C/C and Fortran on all architectures, including Unix platforms and Windows NT platforms. A separate OpenMP reference card for Fortran is also available. n.n.n refers to sections in the OpenMP API Specification available at www.openmp.org.

VI “Cheat” Sheet ACNS Bulletin ED–03 February 1995 File management commands:w name Write edit buffer to file name:wq Write to file and quit:q! Quit without saving changes ZZ Same as:wq:sh Execute shell commands (d) Window motions d Scroll down (half a screen) u Scroll up (half a screen) f Page forward b Page. If somebody is interested - the cheat sheet is now finished:) The guy obviously need to add some things but still this is a great source for beginners! View Entire Discussion (3 Comments) More posts from the fortran community. Fortran 90 Reference Card Michael Goerz Fortran 90.

  • Selected Reading

A Fortran program is made of a collection of program units like a main program, modules, and external subprograms or procedures.

Fortran

Each program contains one main program and may or may not contain other program units. The syntax of the main program is as follows −

A Simple Program in Fortran

Fortran

Let’s write a program that adds two numbers and prints the result −

Fortran cheat sheet free

When you compile and execute the above program, it produces the following result −

Please note that −

  • All Fortran programs start with the keyword program and end with the keyword end program, followed by the name of the program.

  • The implicit none statement allows the compiler to check that all your variable types are declared properly. You must always use implicit none at the start of every program.

  • Comments in Fortran are started with the exclamation mark (!), as all characters after this (except in a character string) are ignored by the compiler.

  • The print * command displays data on the screen.

  • Indentation of code lines is a good practice for keeping a program readable.

  • Fortran allows both uppercase and lowercase letters. Fortran is case-insensitive, except for string literals.

Basics

The basic character set of Fortran contains −

  • the letters A ... Z and a ... z
  • the digits 0 ... 9
  • the underscore (_) character
  • the special characters = : + blank - * / ( ) [ ] , . $ ' ! ' % & ; < > ?
Fortran cheat sheet

Tokens are made of characters in the basic character set. A token could be a keyword, an identifier, a constant, a string literal, or a symbol.

Program statements are made of tokens.

Identifier

An identifier is a name used to identify a variable, procedure, or any other user-defined item. A name in Fortran must follow the following rules −

  • It cannot be longer than 31 characters.

  • It must be composed of alphanumeric characters (all the letters of the alphabet, and the digits 0 to 9) and underscores (_).

  • First character of a name must be a letter.

  • Names are case-insensitive

Keywords

Keywords are special words, reserved for the language. These reserved words cannot be used as identifiers or names.

The following table, lists the Fortran keywords −

Fortran

Fortran Syntax Cheat Sheet

The non-I/O keywords
allocatableallocateassignassignmentblock data
callcasecharactercommoncomplex
containscontinuecycledatadeallocate
defaultdodouble precisionelseelse if
elsewhereend block dataend doend functionend if
end interfaceend moduleend programend selectend subroutine
end typeend whereentryequivalenceexit
externalfunctiongo toif implicit
ininoutintegerintentinterface
intrinsickindlenlogicalmodule
namelistnullifyonlyoperatoroptional
outparameterpausepointerprivate
programpublicrealrecursiveresult
returnsaveselect casestopsubroutine
targetthentypetype()use
WhereWhile
The I/O related keywords
backspacecloseendfileformatinquire
openprintreadrewindWrite