ArticleslgStudy

science

Fortran 95 language features

Fortran 95 language features is a science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Fortran 95 language features rather than just read about it. In short: This is an overview of Fortran 95 language features which is based upon the standards document which has been replaced by a newer version. Included are the additional features of TR-15581:Enhanced Data Type Facilities, which have been universally implemented.

Key takeaways

  • Fortran 95 language features belongs to science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Fortran 95 language features to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Fortran 95 language features from memory before moving on to harder problems.

Reference excerpt

This is an overview of Fortran 95 language features which is based upon the standards document which has been replaced by a newer version. Included are the additional features of TR-15581:Enhanced Data Type Facilities, which have been universally implemented. Old features that have been superseded by new ones are not described – few of those historic features are used in modern programs although most have been retained in the language to maintain backward compatibility. The additional features of subsequent standards, up to Fortran 2023, are described in the Fortran 2023 standard document, ISO/IEC 1539-1:2023. Some of its new features are still being implemented in compilers. Details can also be found in a range of textbooks, for instance and see the list at Fortran Resources. Sources for the description in the sections below can be found in the standards documents, textbooks as well as the Bibliography.

Language elements Fortran is case-insensitive. The convention of writing Fortran keywords in upper case and all other names in lower case is adopted in this article; except, by way of contrast, in the input/output descriptions (Data transfer and Operations on external files).

Basics The basic component of the Fortran language is its character set. Its members are

the letters A ... Z and a ... z (which are equivalent outside a character context) the numerals 0 ... 9 the underscore _ the special characters = : + blank - * / ( ) [ ] , . $ ' ! " % & ; < > ? Tokens that have a syntactic meaning to the compiler are built from those components. There are six classes of tokens:

From the tokens, statements are built. These can be coded using the new free source form which does not require positioning in a rigid column structure:

Note the trailing comments and the trailing continuation mark. There may be 39 continuation lines, and 132 characters per line. Blanks are significant. Where a token or character constant is split across two lines:

a leading & on the continued line is also required.

Intrinsic data types Fortran has five intrinsic data types: INTEGER, REAL, COMPLEX, LOGICAL and CHARACTER. Each of those types can be additionally characterized by a kind. Kind, basically, defines internal representation of the type: for the three numeric types, it defines the precision and range, and for the other two, the specifics of storage representation. Thus, it is an abstract concept which models the limits of data types' representation; it is expressed as a member of a set of whole numbers (e.g. it may be {1, 2, 4, 8} for integers, denoting bytes of storage), but those values are not specified by the Standard and not portable. For every type, there is a default kind, which is used if no kind is explicitly specified. For each intrinsic type, there is a corresponding form of literal constant. The numeric types INTEGER and REAL can only be signed (there is no concept of sign for type COMPLEX).

Literal constants and kinds

INTEGER Integer literal constants of the default kind take the form

Kind can be defined as a named constant. If the desired range is ±10kind, the portable syntax for defining the appropriate kind, two_bytes is

that allows subsequent definition of constants of the form

Here, two_bytes is the kind type parameter; it can also be an explicit default integer literal constant, like

but such use is non-portable. The KIND function supplies the value of a kind type parameter:

and the RANGE function supplies the actual decimal range (so the user must make the actual mapping to bytes):

Also, in DATA (initialization) statements, binary (B), octal (O) and hexadecimal (Z) constants may be used (often informally referred to as "BOZ constants"):

REAL There are at least two real kinds – the default and one with greater precision (this replaces DOUBLE PRECISION). SELECTED_REAL_KIND functions returns the kind number for desired range and precision; for at least 9 decimal digits of precision and a range of 10−99 to 1099, it can be specified as:

and literals subsequently specified as

Also, there are the intrinsic functions

that give in turn the kind type value, the actual precision (here at least 9), and the actual range (here at least 99).

COMPLEX COMPLEX data type is built of two integer or real components:

LOGICAL There are only two basic values of logical constants: .TRUE. and .FALSE.. Here, there may also be different kinds. Logicals don't have their own kind inquiry functions, but use the kinds specified for INTEGERs; default kind of LOGICAL is the same as of INTEGER.

and the KIND function operates as expected:

CHARACTER The forms of literal constants for CHARACTER data type are

(the last being an empty string). Different kinds are allowed (for example, to distinguish ASCII and UNICODE strings), but not widely supported by compilers. Again, the kind value is given by the KIND function:

Number model and intrinsic functions The numeric types are based on number models with associated inquiry functions (whose values are independent of the values of their arguments; arguments are used only to provide kind). These functions are important for portable numerical software:

Scalar variables Scalar variables corresponding to the five intrinsic types are specified as follows:

where the optional KIND parameter specifies a non-default kind, and the :: notation delimits the type and attributes from variable name(s) and their optional initial values, allowing full variable specification and initialization to be typed in one statement (in previous standards, attributes and initializers had to be declared in several statements). While it is not required in above examples (as there are no additional attributes and initialization), most Fortran-90 programmers acquire the habit to use it everywhere. LEN= specifier is applicable only to CHARACTERs and specifies the string length (replacing the older *len form). The explicit KIND= and LEN= specifiers are optional:

works just as well. There are some other interesting character features. Just as a substring as in

was previously possible, so now is the substring

Also, zero-length strings are allowed:

Finally, there is a set of intrinsic character functions, examples being

Derived data types For derived data types, the form of the type must be defined first:

and then, variables of that type can be defined:

To select components of a derived type, % qualifier is used:

… excerpt ends here. Continue reading the full article.

Worked examples

Example 1 — a first encounter with Fortran 95 language features

Start with the simplest possible case. Write down what Fortran 95 language features claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Fortran 95 language features before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Fortran 95 language features ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Fortran 95 language features

In research
Fortran 95 language features appears in science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Fortran 95 language features in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Fortran 95 language features is common in secondary-school and first-year university syllabi. It links to neighbouring topics Fortran, so understanding it makes those chapters shorter.
In everyday life
Look for Fortran 95 language features outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Fortran 95 language features” →

How to study Fortran 95 language features in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Fortran 95 language features means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Fortran 95 language features out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Fortran 95 language features in simple terms?

This is an overview of Fortran 95 language features which is based upon the standards document which has been replaced by a newer version. Included are the additional features of TR-15581:Enhanced Data Type Facilities, which have been universally implemented.

Why does Fortran 95 language features matter?

Because it connects several science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Fortran 95 language features?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Fortran 95 language features.

Tags

  • Fortran

Keep exploring