VAX Fortran to Fortran 77 translator

Download VAX Fortran to Fortran 77 translator

Post on 21-Jun-2016

254 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 desired.

    CSMODULE xxxx

    Marks the beginning of module xxxx. Global names (subprogram and common block names) which the user wishes to be hidden are mapped into 'hidden names' which begin with xxxx. If xxxx is no longer than four characters it will be truncated. If there is no CSMODULE directive global names will follow the same rules as variable names.

    All global names are hidden unless they appear in a CSVISIBLE statement, cSVISIBLE namel [name2. . . ] .

    The global names listed in this statement are to be unchanged by the translator. These are the global names visible to the rest of the program. As many CSVISIBLE statements as required may be used. Names on the CSVISI- BLE statement are separated by blanks, tabs, or commas.

    Bugs Underscore characters (_) are not supported in variable

    names because most macro processors do not recognize them as characters. Modifications to VF2F77 are documented if your macro processor treats them properly.

    An exclamation point in a Hollerith field, e.g. 5HBUG!, will be treated as an end of line comment indicator. Hollerith fields are not officially part of Fortran 77. 9

    Multiple common blocks are not allowed in the same COMMON statement. E.G. COMMON/BLK1/A,B,C/BLK2/ X,Y.

    Adv. Eng. Software, 1985, Vol. 7, No. 3 143

  • REFERENCES

    1 Dijkstra, E. W. How do we tell troths that might hurt?, Selected Writings on Computing: A Personal Perspective, Springer-Verlag, New York, 1982

    2 Wilson, K. G. Planning for the Future of US Scientific and Engineering Computing, CA CM 1984, 27(4)

    3 IMSL Library General Information, International Mathematical and Statistical Libraries, Inc, Houston, TX, 1983

    4 Smith, B. T. Status Report on Fortran 8x as of August 1983, SIGNUM Newsletter 1983, 18(4)

    5 VAX Fortran Reference Manual 3.0, Digital Equipment Corpora- tion, 1983

    6 Kernighan, B. W. RatJbr - A Preprocessor for a Rational Fortran, Unix Programmer's Manual, Vol. 2B, Bell Telephone Laboratories, Inc., Murray Hill, NJ, 1979

    7 Cook, A. J. and Shustek, L. J. A User's Guide to Mortran 2, Stanford Linear Accelerator Center, California 94305, 1975

    8 Kernighan, B. W. and Plauger, P. J. Software Tools in Pascal. Addison Wesley, 1981

    9 American National Standard Programming Language FORTRAN, ANSI X3.1978

    DIRECTORY OF PROGRAMS

    The first two programs are used to obtain the source and destination files, and send them through the translator programs. The actual program names used in the two driver routines will have to be modified to be compatible with the environment the translator is implemented in. For example:

    'USER1 : [C 100.STEVE.TRANS.STAND] DEFINE.EXE'

    Programs with the .PAS extension are written in 'standard' Pascal, those with the .SFT extention are designed to use the software tools primitives.

    All the following programs read from standard input and write to standard output :

    VF2F77.COM-VAX/VMS command procedure used to run the translator programs.

    UNIX .SCR-Un ix shell script to run the translator pro- grams.

    INCLUDE.PAS-Used to include external files into the main source code. Note: Pascal File 1/O is system dependent and may have to be modified, currently set up for VAX/VMS operating system.

    WH2STD.PAS-Converts non-standard do loops into a form compatible with standard FORTRAN 77, plus processes end of line comments, VAX tab conventions, and maps text not in quotes to upper case.

    LONGNM.PAS- Creates a list of define statements to redefine long variable names. The list should be affixed to the beginning of the output from WH2STD.PAS for use with the define program.

    DEF INE.PAS-Reads from standard input and replaces every occurrence of 'str l ' with 'str2' following the define command: define(strl , str2).

    The following programs perform the same functions as those above, but are designed to work in the software tools environment:

    INCLUDE.SFT WH2STD.SFT LONGNM.SFT DEFINE.SFT

    The next programs are used as test programs. TEST.F is the source, MATADD.SUB, and MATMULT.SUB are separate subroutines that are included with the include program:

    TEST .F - Main program that calls MATADD.SUB and MATMULT.SUB.

    MATADD.SUB - Subroutine that adds two matricies together.

    MATMULT.SUB - Subroutine that multiples two matricies together.

    XX .OUT-The translated output from the three test programs.

    VF2F77.COM VAX/VMS command procedure to run translator programs

    $ ~ VAX/VMS comand procedure to dr,ve tile translat,~! $ ! The source code is passed through the followin~ l,rogram~ $ ! include -- includes external source files. $ I wh2std -- translates while loops $ I longnm -- processes long variable names $ [ define -- processes the define statements generaL~,d by Iongnm $ t $ ! clear the directory of possible conflicting file:~ $ if fSsearch("temp*.txq;*") .nes. "" then $ delet!, lemp*.tKq; ~ $ ~ $ I get input and output fires $ infile =~ pl $ outfile ~= p2 $ if infile .eqs. "" then $ inquire inlile "source ~le" $ if outfile .eqs. "" then $ inquire outfile "output file" $ ~ $ ! if an output file is not mpecified then the output will $ ! go to ~tandard output and no output file will be saved $ ~ $ ! connect standard input and output to the appropriate files $ assign/user_mode "infile" sys$input [ input file spec $ as~ign/umer_mode templ.txq sys$output [ output from include $ run userl : IclO0.~teve.trans.stand] include .exe $ ~ $ a...

Recommended

View more >