vax fortran to fortran 77 translator

Download VAX Fortran to Fortran 77 translator

Post on 21-Jun-2016

265 views

Category:

Documents

27 download

Embed Size (px)

TRANSCRIPT

  • VAX Fortran to Fortran 77 translator

    RICHARD E. HESSEL and STEPHEN B. CHICO

    Mechanical and Industrial Engineering Department, Clarkson University, Potsdam, NY 136 76, USA

    A Fortran preprocessor is described which maps VAX Fortran into standard Fortran 77. Supported extensions include long variable names, DO WHILE loops, ENDDO loop terminations, Vax Fortran tab convention, INCLUDE f'de processing, and a MODULE facility to limit the access of external programs to subprogram and common block names. The software is available in 'standard' Pascal and Software Tools Pascal form.

    INTRODUCTION

    The Fortran language is much maligned, especially by those in computer science circles, for its deficiencies compared to more modern programming languages. ~'~ We agree with these criticisms. However, as a practical matter almost all engineering software is written in Fortran. The extensive libraries of high quality mathematical software alone are a great incentive to use Fortran in our computations. 3

    While Fortran 77 made a significant step in improving the language, Fortran still suffers from many serious flaws. The next version of the language, Fortran 8x, should remove most of these flaws. 4 In the mean time we are faced with a situation similar to that of the 1970's when many compiler writers supplemented Fortran IV with extensions to overcome its deficiencies.

    Several computer vendors, for example DEC and Gould, have extended their Fortran 77 compilers. The DEC VAX Fortran is a particularly attractive version of Fortran 77. 5 The extensions it supports include long variable names, end of line comments, a general DO-WHILE loop, and an ENDDO statement to eliminate the need for statement numbers as the objects of DO loops. Also included is an IMPLICIT NONE statement which requires the type of every variable to be explicitly declared.

    Experience with this compiler has shown that use of these extensions, especially the long variable names, result in ~nuch more readable programs. However, such programs suffer from lack of portability.

    In the spirit of the multitude of Fortran IV preproces- sors, 6'7 we combined some of our old programs for detecting long variable names and translating DO-WHILE loops to produce input for the macro processor from Software Tools in Pascal by Kernighan and Plaguer a to create a new translator which maps VAX Fortran into Fortran 77.

    The features of this translator include :

    Long names: The program assumes that IMPLICIT NONE has been used (or at least that all variable names that are six characters or longer have been declared in type statements). The program will then attempt to truncate

    Accepted January 1985. Discussion closes September 1985

    names which are longer than six characters to a readable six character name. If the name cannot be shortened without conflict then a unique name is generated.

    DO loops: DO-WHILE loops of the form:

    DO WHILE (condition)

    ENDDO

    are translated into appropriate IF's and GOTO's. Conven- tional DO loops which are terminated with ENDDO's instead of a line with a statement number are translated into the legal Fortran 77 form with statement numbers.

    End of line comments: Any text which appears between an exclamation point (!) which is not in a quoted string and the end of the line is considered to be a comment. These comments are moved to the line preceding the current line as standard Fortran comments. The program understands Fortran continuation lines.

    Include statements: The source file may contain 'C$INCLUDE file' statements which are replaced by the contents of the file before any other processing is done. These statements may be nested, i.e. the included file may contain other include statements. Include statements are used to build source files comprised of many routines in separate files. Common block declarations can be stored in a file and included when needed to avoid typing errors.

    Modules: Fortran 77 supports only one level of global name. This makes it difficult to hide implementation details from users of library routines. Using this option, all global names, i.e. subprogram and common block names, are mapped into special inaccessible names except for those names which the user selects to be 'visible'.

    The writer of a 'module' would specify that certain routines or common blocks could be accessed by other routines outside of the module. All other global names would be transformed into a four letter module name and a two character sequence to form a unique six character name.

    IMPLEMENTATION OF THE TRANSLATOR The translator is implemented in Pascal. Two versions are available: one using 'standard' Pascal and one using the Pascal environment developed in ref. 8.

    The programs were written for portability with carefully isolated system dependent sections, e.g. opening flies.

    The output of the translator is fed to a general purpose macro processor to perform long variable name substitution. A suitable macro processor is 'define' from ref. 8. All of the progra~ns described in ref. 8 are available frown the publisher for a nominal charge. A 'standard' Pascal version is supplied with the translator software.

    The translator makes several passes over the program text. the passes are:

    0141-1195/85/030142-15 $2.00 142 Adv. Eng. Software, 1985, Vol. 7, No. 3 1985 CML Publications

  • Pass 1 : All C$INCLUDE file statements are replaced by the contents of the named file.

    Pass 2: The DO WHILE, ENDDO, and DO without a statement number are translated into IF's, CONTINUE's, and GOTO's. End of line comments are moved in this pass and the VAX Fortran tab convention is converted to blanks.

    Pass 3: Long variable, subprogram, and common block names are mapped into unique names. CSMODULE and CSVISIBLE statements control the visibility of global names.

    Pass 4: The define statements produced in pass 3 to drive the macro processor are merged at the beginning of the program source and are passed to the macro processor.

    Command procedures are provided to illustrate how to implement the translator on VAX/VMS and Unix operating systems.

    Detailed usage instructions may be found in the manual pages. Extensive prologue comments in the code aid in implementing the program on the users system.

    USING THE TRANSLATOR

    The module aspects of the translator are especially useful in writing large programs. The program could be broken into logical sections and written by different programmers. Each program section could access only those subprograms and common blocks of another section which had been made visible. Thus each programmer could use descriptive names for internal .subprograms and common blocks without worrying about possible conflict with other sections of the program.

    Visible names should not be longer than six characters to work properly with most Fortran compilers and linkers. Other subprogram and common block names will be processed the same way as long variable names.

    The translator requires that all variable names which are six characters in length or longer be explicitly declared. Six character names are needed to determine if a long name can safely be truncated to its first six characters. If it cannot then a unique six-letter name is generated. We recommend that all variable names be declared.

    THE PROGRAMS

    Two versions of each program are provided. One uses the Software Tools s primatives while the other is in 'standard' Pascai. The Software Tools version has been tested on VAX/VMS. The 'standard' Pascal version has been tested on VAX/VMS and Unix. Command procedures are supplied for each of these operating systems.

    A version of the define program from ref. 8 in 'standard' Pascal is included.

    A prospective user can port the primatives described in ref. 8 to his or her system and use the Software Tools version and the other tools described in ref. 8. This version is especially useful to users who already are using Software Tools.

    An alternative is to use the 'standard' Pascal versions. These programs should compile without modification on most Pascal compilers.

    The programs include extensive prologue comments w/rich describe in detail the programs. Limitations and possible extensions are enumerated.

    Sample Fortran programs are included to test the programs when they have been installed on a prospective user's computer:

    Program VF2F77 - VAX Fortran to Fortran 77 translator

    Usage VF2F77 infile outfile

    Function VF2F77 reads VAX Fortran source code and outputs

    commands for a macro processor and translated code. After being processed by a macro processor, the output is standard Fortran 77 code.

    VAX DO WHILE (condit ion). . . ENDDO and DO index = il, i2, i3 . . . ENDDO are translated.

    Text following an unquoted exclamation point (!) is moved to the preceding line as a comment.

    IMPLICIT NONE statements are changed into comments. All lower case letters not in quoted strings are mapped

    into upper case. A tab character in columns 1 through 6 causes the next

    character to logically be in column 7 if the character is alphabetic. If the character is a number other than zero (0) it is placed in column 6 to indicate a continuation line.

    All variable names greater than or equal to six characters should be declared in type statements. A list of macro processor commands will be generated to map names longer than six characters into six character names by truncation, if possible, or by generating a unique name.

    The following translator directives are supported:

    C$ INCLUDE 'filename'

    This line will be replaced by the contents of the file 'filename'. Include statements may be nested as deeply as de

Recommended

View more >