NAGWare Fortran Tools - f77 Tools - nag_decs

 

Index

NAME
DESCRIPTION
OPTIONS
THE PROGRAM TEMPLATE
DECLARATIVE SECTION FORMAT
RESTRICTIONS
SEE ALSO

 

NAME

nag_decs - Declaration Standardiser

 

DESCRIPTION

nag_decs is the NAGWare f77 Tools Fortran 77 declaration standardiser. This tool can either rebuild the declarative part of a Fortran 77 program unit declaring all names or alternatively add declarations for all implicitly typed names. Name means a variable, common block, function or subroutine, parameter etc.

Upon successful completion each input file is backed up to file.orig and is replaced by the polished output file.

 

OPTIONS

"Rebuild declarations","Declare implicits" (-rebuild, -declare)
If -rebuild is set, the tool operates in rebuild mode. Existing declarations are deleted and replaced by standard sections declaring all names used in the program. The default is -rebuild.

If -declare is set all implicit names in the program are declared explicitly. A section named "Previously untyped names" is added to each program unit's declarations. Otherwise the declarations in the input program are untouched.

"Array declarations in COMMON block (-ardicb)
By default dimensions for arrays in COMMON are declared in type statements. If this option is set then the arrays in COMMON are dimensioned in the COMMON statement. ardicb means ARay Declaration In Common Block.

"Combine character length declarations" (-comb_chlens)
Combine character length declarations. By default separate CHARACTER statements are produced for each length of CHARACTER varaiable. e.g.

      CHARACTER*6 A, C
      CHARACTER*10 B
If this option is set then CHARACTER variable declarations are combined in one CHARACTER statement in each section with a length specifier following each name. e.g.

      CHARACTER A*6, B*10, C*6

"Generify intrinsic functions" (-generify)
Selecting this option causes nag_decs to change all occurances of specific intrinsic functions to the equivalent generic form, for example DMAX1 would be changed to MAX.

"Group common objects with COMMON blocks" (-group_common)
Group declarations of common objects with their common blocks. In rebuild mode, if this option is set then type declarations for COMMON variables immediately follow each COMMON statement in the "Common blocks" section. By default two sections "Scalars in Common" and "Arrays in Common" are generated for the type declaration of COMMON variables.

"Form of type declarations"
"Keywords" (-keywords),
"No conversion" (-noconvert),
"Byte lengths" (-byte_lengths),
"No DOUBLE COMPLEX" (-no_double_complex)
These options control the form used for type declarations. With -keywords type declarations are made using the keyword form, e.g. DOUBLE PRECISION. With -noconvert all existing data types are left unchanged e.g. REAL*4 will be considered different from REAL. With -byte_lengths all datatypes will be given length specifiers. -no_double_complex is the same as -keywords except that COMPLEX*16 is used instead of DOUBLE COMPLEX. The default is keywords.

"Executable statement header" (-exehdr)
Setting this option causes the Declaration Standardiser to generate the section header "Executable Statements", if it does not already exist, immediately before the first executable statement. exehdr means EXEcutable statement HeaDeR.

"Expand include lines" (-expand_include)
Include files are always opened, read and analysed. By default variables defined in include files, however, are not placed in the declarations that are generated by this tool. If this option is set then the variables defined in include files will be declared in the type statements generated by nag_decs and the polish option DELINF is automatically set to .FALSE. suppressing the output of INCLUDE statements. This overrides the definition in the polish option file, if supplied.

"No section trailer comments" (-notrailers)
Suppresses the generation of nag_decs section trailer comments

"Datatype order" (-order code,code,code,code,code,code,code)
Specifies the order in which the type statements should be placed within each section. All seven type codes should be listed in this option. The default is: DOUBLE COMPLEX, DOUBLE PRECISION, COMPLEX, REAL, INTEGER, LOGICAL then CHARACTER.

"Removal of unused names"
"Log removal of unused names" (-logremove),
"Silent removal of unused names" (-silentremove),
"No removal of unused names" (-noremove)
These options allow the user to control the removal of the declaration for any name in the program which is not actually used. If -logremove is specified a warning message will be written on standard error for each name which is removed. -silentremove suppresses the warning. If -noremove is specified then all unused variable declarations are retained. nag_decs will not remove equivalenced or COMMON variables, or dummy arguments. The default is -logremove
 

THE PROGRAM TEMPLATE

nag_decs considers the program unit to begin with an optional program unit header with preceding and following comments, followed by a number (possibly zero) of "declarative sections" and then by the executable statements.

Statement function definitions and DATA statements are considered to be declarative statements and so are placed into their own declarative sections; these sections (if they exist) are always the last declarative sections to be output.

Type statements in a declarative section are ordered according to the nag_decs option settings, and the elements in each type statement are ordered alphabetically. If both scalars and arrays are being typed in a single section, they will be placed in separate type statements.

nag_decs will itself insert all necessary declarative sections which do not appear in the source code.

The order in which the declarative sections occur, if there are any, in the input file is preserved by nag_decs.

 

DECLARATIVE SECTION FORMAT

Each declarative section begins with a nag_decs section header and ends (optionally) with a nag_decs section trailer. The body of a declarative section consists of a number of comments (possibly none) followed by the declarations themselves. nag_decs checks to see if the header and trailer comments exist already and only inserts them if they do not. This allows nag_decs to be applied to a program unit more than once without duplication of comments.

The nag_decs section headers have the form: "C .. Section Name ..", where there may be any number of spaces between the 'C' and the '..', and the rest of the header matches the name of a declarative section. If the text following the '..' doesn't match a section name, then a warning message is issued and the comment is treated as a normal comment. The comparison between the source and the section names is done on a case-insensitive basis, and if a match is found the source form is replaced by the standard form (this has 5 spaces between the C and the first period).

The optional nag_decs section trailer has the form "C .." where there may be any number of spaces between the 'C' and the '..'.

The following list shows the names of all possible declarative sections.

Parameters
Scalar Arguments
Array Arguments
Function Arguments
Subroutine Arguments
Scalars in Common
Arrays in Common
Local Scalars
Local Arrays
External Functions
External Subroutines
Intrinsic Functions
Common blocks
Entry Points
Statement Functions
Equivalences
Save statements
Statement Function Definitions
Executable Statements
Previously untyped names
DATA Statements

 

RESTRICTIONS

nag_decs recognises the ANSI standard Fortran 77 intrinsic functions, the US Military Standard intrinsic functions, and the double complex intrinsics defined in nag_Fortran77. Explicitly typing an intrinsic function will cause a warning message to be issued, and that function name will still be treated as intrinsic. To declare a user-defined function with the same name as an intrinsic function the EXTERNAL statement must be used to prevent nag_decs from thinking that it is an intrinsic.

nag_decs does not check to see whether any of the array parameters are adjustable arrays with the variables in COMMON blocks. As the default order of declarative sections puts the arguments before the common blocks, this could cause illegal Fortran to be generated (if the implicit type of the variable is not integer).

To avoid this problem the "Scalars in Common" declarative section header may be inserted into the program text so that the type declarations for the array arguments will occur after the declarations for the variables used to dimension the arrays.

There are three instances where nag_decs cannot convert an intrinsic function to its generic form:

1. when a function has been used as an actual parameter to another function or subroutine,

2. when the function has been explicitly typed, and

3. when the generic function name it would have been converted to has been used for some other purpose within the program unit, for example as an array name.

In these cases nag_decs will issue a warning message saying that it cannot convert the function for that reason.

 

SEE ALSO

nag_apt, nag_Fortran77, nag_polish, nag_polopt

Copyright, Numerical Algorithms Group, Oxford, 1991-2001