Here's help in converting to Fortran 90
by Jeanne
Adams,
Juli Rew, and
Jeff Kuehn
FORTRAN 77
is a subset of Fortran 90. Thus, if you are using standard
FORTRAN 77, you can easily switch to Fortran 90. While there are many
new language features in Fortran 90, you are not required to use
them.
This article emphasizes the differences between the FORTRAN 77 and
Fortran 90 standards and gives some compiling examples to get you
started down the road to converting to Fortran 90. To complement this
article, the SCD Technical Consulting Office has created a new set of
Fortran 90 information on its online ConsultWeb. The URL for
ConsultWeb is:
Select the "Fortran 90 Info" link.
The ConsultWeb Fortran 90 help site emphasizes the practical issues of
migrating from the Cray CF77 to CF90 compiling systems, including
checking your code, compiling and linking, language changes, UNIX
environment, performance issues, new features, source management using
make, reprints from SCD Computing News of Fortran 90
articles by Jeanne Adams, a Fortran 90 Tutorial by Zane Dodson
(University of New Mexico), and a Fortran 90 Frequently Asked
Questions (FAQ) list.
Why convert now?
When the Cray programming environment 2.0 was released this spring,
the Cray Fortran 90 (CF90) compiler replaced the CF77 compiling system
for CRAY PVP systems as the supported Fortran compiler.
Converting to Fortran 90 has become a high priority because SCD
has acquired a Cray C90 that replaced the CRAY Y-MP (antero).
SCD has also acquired a Cray J90se, ouray. The only
Fortran compiler on these machines is the Fortran 90 compiler
(CF90). If other new Crays are acquired, they too will have
CF90 as the only Fortran compiler.
What will happen to CF77?
Although SCD may still be able to provide the CF77 compiling system on
our older systems, such as the CRAY Y-MP (shavano), all new Cray
systems come with CF90 as the default compiling system. CF77 should be
considered as a transitional compiler only, with emphasis on getting
codes running using CF90 as soon as possible. Users planning to run on
the C90 (antero) MUST convert their codes to Fortran 90 now.
Conversion to Fortran 90: Issues and answers
Are you using standard Fortran (77 or 90)? Then conversion should be a
breeze. FORTRAN 77 users will need to make very few changes to a
FORTRAN 77 program to convert it to Fortran 90, provided all the
statements used are bona fide FORTRAN 77 statements.
As mentioned above, Fortran 90 is a superset of the FORTRAN 77
language. Some of the difficulty of converting programs comes from
statements that are Cray extensions to the FORTRAN 77 standard that
are not in the Fortran 90 standard. If the statements are in the
FORTRAN 77 standard, there will be very few changes (if any) to run
using the Fortran 90 compiler. Of course, there are control file and
command line changes that inevitably come with the change to any new
compiler. And any new compiler will have optimization features that
may be dissimilar to any that have been used in the past. The job of
conversion does not require changing DO loops to the Fortran 90 vector
notation (which, by the way, can be done using various conversion
routines). You may take advantage of the new features at a later time,
after your programs are running on the Fortran 90 compiler.
There are different approaches to conversion of a source code
depending on what kind of statement is in question. Standard FORTRAN
77 codes should compile without difficulty, with the exception of a
few caveats discussed below.
Standard FORTRAN 77 statements: A few caveats
- FORTRAN 77 standard statements will compile, with a few
exceptions, on standard Fortran 90. One of the exceptions is with
names of your user-supplied functions that are the same
as new names in the list of standard Fortran 90 functions. An example
might be MATMUL in Fortran 90, which does a matrix multiply on numeric
or logical matrices. If you also have a function named MATMUL and want
to use your own routine, you must declare your routine EXTERNAL or
change its name. Another commonly used name that may cause conflicts
is the Fortran 90 intrinsic function SUM.
- The G format edit descriptor produces 0.0E+00 on output,
whereas Fortran 90 produces a 0.0.
- Fortran 90 does not blank pad after a list-directed
character if the number of characters in the list is less
than the number of characters in the record. FORTRAN 77 left this
processor dependent. If you depend on this feature, use PAD = NO in
the OPEN statement.
- When a real constant is used to initialize a double precision
constant, only the precision of the real constant is used in
Fortran 90. FORTRAN 77 permitted more precision to be used.
- If data is initialized in a DATA statement, Fortran 90 states that
the data has the SAVE attribute; FORTRAN 77 makes this
processor dependent.
Cray Fortran statements that extend Fortran 90 and Cray Fortran statements
that extend FORTRAN 77, but which are not in Fortran 90:
- There is no double complex type in a Fortran standard.
- Cray NAMELIST is different from the Fortran 90
NAMELIST. Both forms are accepted in the Fortran 90 compiler. If you
plan to port your program to another system, use the standard
conforming NAMELIST.
- Single-letter abbreviations like .T. for .TRUE. and .A. for
.AND., etc. are not in the standard, but are allowed in the Cray
CF77 compiler. The Cray CF77 compiler is permissive in these
cases.
- The interpretation of the logical intrinsic operators
results in a logical value (true or false) in Fortran standards.
These are not interpreted as a masking operator in a boolean
expression as in Cray Fortran. .XOR. is an additional operator added
by Cray.
- There are a number of system library routines in Cray CF77
Fortran that are not in the standard. However, these routines will
remain in the Cray Fortran 90 compiler for compatibility.
- Some of the tasking directives in previous Cray CF77
Fortrans have been replaced by EXIT and the CASE construct in standard
Fortran 90. The DO GLOBAL has been replaced by the DO ALL statement,
which is not in standard Fortran 90. The DO ALL statement is Cray
Fortran 90.
- REAL *4, etc. are not standard conforming in Fortran 90;
the KIND parameter is used instead in the standard. However, both
forms are in Cray Fortran 90.
- Recursion was in Cray FORTRAN 77, but in a slightly
different form. In Fortran 90, the word RECURSION must appear on
recursive procedures. It was required in the standard because of
efficiency considerations for compiler writers, since recursion is
generally inefficient and impacts optimization.
- Both Cray pointers and Fortran 90 pointers are in
Cray Fortran 90. While these two implementations are different, they
do not conflict if the user sticks to one form or the other. Cray
pointers are non-standard conforming, however.
- Fortran 90 is more strict with type checking than CF77. Pointers
are not interchangeable with the integer type as in CF77. In Fortran
90, pointers are their own type and point to a particular type of
data.
- Straight translation of Cray Fortran pointers to Fortran 90
standard pointers may add significant overhead due to creating,
copying to, and deallocating temporary arrays.
Fortran 95 draft standard statements
Fortran 95 is still being reviewed and balloted. The final balloting
should be completed in early 1997. There are only a few new features
in this standard. They include the FORALL statement and construct,
PURE and ELEMENTAL functions, a few new intrinsic functions (NULL and
CPU_TIME) and pointer default initialization. Many clarifications were
made to Fortran 90 in preparing the Fortran 95 draft document.
Fortran 90/95 language architecture: Moving on
How to keep a language from growing indefinitely to a very large size
and how to allow old software to run on any new system are two issues
that are difficult to resolve. For this reason, a language
architecture was developed for Fortran 90 that defined what features
were old, new, obsolescent, and not standard anymore (deleted). The
list of obsolescent features was derived from those that were little
used, and/or redundant with another feature, possibly a new one. The
deleted features were chosen each standard revision cycle from the
list of current obsolescent features. However, not all of these
features are deleted, especially if users complain in a public review
cycle. At least one standard revision cycle is required before a
feature is removed from the language.
Table 1. DELETED FEATURES
---------------------------------------------------
From Fortran 95 From Fortran 90 From FORTRAN 77
---------------------------------------------------
Real and double None Hollerith Data
precision DO
variables
Branching to an
ENDIF statement
from outside the
IF block
PAUSE statement
ASSIGN, ASSIGNED
GOTO, and
assigned FORMAT
H edit descriptor
---------------------------------------------------
Dealing with deleted and obsolete features
Add new Fortran 90 features gradually
Control file changes and command lines: Using the
Fortran 90 compiler on the Cray systems
Detailed information on the Cray Fortran 90 compiler can be found
online in the f90 man page, and case-by-case assistance can be
obtained from the SCD Technical Consulting Office.
- Simple compile:
- cf77: cf77 file.f
- cf90: f90 file.f
Note: The default level of optimization under cf77 and
f90 on Cray systems is -O 2 (moderate optimization). By
comparison, no optimization is performed under f77 on a Sparc
platform.
- Rename executable:
- cf77: cf77 -o file.exe file.f
- cf90: f90 -o file.exe file.f
- Turn on automatic multitasking:
- cf77: cf77 -Zp file.f
- cf90: f90 -O task2 file.f
- Do not interpret user multitasking directives:
- cf77: cf77 file.f
- cf90: f90 -O task0 file.f
- Interpret user multitasking directives:
- cf77: cf77 -Zu file.f
- cf90: f90 file.f
- cf90: f90 -O task1 file.f
- Add libraries:
- cf77: cf77 file.f -L/usr/local/lib -lncarm -lncaro
- cf90: f90 file.f -L/usr/local/lib -lncarm -lncaro
- Compile with NCAR Graphics libraries:
- cf77: cf77 file.f -L/usr/local/lib -lncarg -lncarg_gks \
- -lncarg_c -lX11
- cf90: cf90 file.f -L/usr/local/lib -lncarg -lncarg_gks \
- -lncarg_c -lX11
- Compile-only (for use with make):
- cf77: cf77 -c file.f
- cf90: f90 -c file.f
- Link-only (for use with make):
- cf77: cf77 file1.o file2.o
- cf90: f90 file1.o file2.o
- Compile with static memory:
- cf77: cf77: cf77 -a static file.f
- cf90: f90 -e v file.f
- Compile with variables preset to indefinite values:
- cf77: cf77 -e i file.f
- cf90: f90 -e i file.f
For further information
For further information and assistance in converting codes from CF77
to CF90, call the SCD Consultants at 303-497-1278, drop by the
Consulting Office at Mesa Lab Room 17, or send e-mail to
consult1@ncar.ucar.edu.
Back to contents