PU0093 CDF-194 M.W. Eaton P. Sinervo K. Chadwick K. Leininger EXPAND and XFORT Macro expanders for CDF Release 4.31 Revised: 14 May 1991 CONTENTS 1 INTRODUCTION . . . . . . . . . . . . . . . . . . . . 3 2 USAGE . . . . . . . . . . . . . . . . . . . . . . . 5 3 MACRO DEFINITIONS . . . . . . . . . . . . . . . . . 7 4 EXTENSIONS TO FORTRAN-77 SYNTAX . . . . . . . . . 11 4.1 Long Variable Names . . . . . . . . . . . . . . 11 4.2 Hexidecimal And Octal Constants . . . . . . . . 12 4.3 Blank Lines, Tabs And Continuation Lines . . . . 12 4.4 Upper And Lower Case Code . . . . . . . . . . . 13 4.5 Exclamation Point Comments . . . . . . . . . . . 13 4.6 Extended DO Loop Syntax . . . . . . . . . . . . 13 5 QUALIFIERS . . . . . . . . . . . . . . . . . . . . 15 5.1 The ADD_COMMENTS Qualifier . . . . . . . . . . . 16 5.2 The COMMENTS Qualifier . . . . . . . . . . . . . 16 5.3 The CONTRACT Qualifier . . . . . . . . . . . . . 16 5.4 The DEBUG Qualifier . . . . . . . . . . . . . . 17 5.5 The DEFAULT_EXTENSIONS Qualifier . . . . . . . . 17 5.6 The EXPAND Qualifier . . . . . . . . . . . . . . 18 5.7 The ENVIRONMENT Qualifier . . . . . . . . . . . 18 5.8 The FORTOPT Qualifier . . . . . . . . . . . . . 19 5.9 The HEADER Qualifier . . . . . . . . . . . . . . 19 5.10 The IMPLICIT Qualifier . . . . . . . . . . . . . 20 5.11 The INCLUDE Qualifier . . . . . . . . . . . . . 20 5.12 The OUTPUT Qualifier . . . . . . . . . . . . . . 20 5.13 The OPTIONS Qualifier . . . . . . . . . . . . . 21 5.14 The PRETTY Qualifier . . . . . . . . . . . . . . 21 5.15 The SPLIT Qualifier . . . . . . . . . . . . . . 21 5.16 The TRANSLATE Qualifier . . . . . . . . . . . . 21 5.17 The WARNING Qualifier . . . . . . . . . . . . . 22 6 IMPLEMENTATION ON NON-VAX OPERATING SYSTEMS . . . 23 6.1 IBM VM/CMS Implementation . . . . . . . . . . . 23 Page 2 6.2 UNIX Implementation . . . . . . . . . . . . . . 25 6.3 Small Version Implementation . . . . . . . . . . 28 7 EXAMPLES . . . . . . . . . . . . . . . . . . . . . 29 7.1 The Simplest Case . . . . . . . . . . . . . . . 30 7.2 Invoking The Fortran Compiler . . . . . . . . . 31 7.3 Use Of Qualifiers . . . . . . . . . . . . . . . 31 7.4 A Complicated Example . . . . . . . . . . . . . 32 7.5 How To Use The /TRANSLATE Feature . . . . . . . 33 7.6 Using The /NOEXPAND Qualifier . . . . . . . . . 35 7.7 Using $$ELSEIF And $$ELSE In Coding Your Macros 37 7.8 Long Name Aliasing . . . . . . . . . . . . . . . 39 7.9 Do-While And Do-Enddo . . . . . . . . . . . . . 40 7.10 The Use Of The $$BLOCK_DATA Macro . . . . . . . 42 8 ERROR MESSAGES . . . . . . . . . . . . . . . . . . 44 8.1 Table Of Error Messages . . . . . . . . . . . . 45 9 RELEASE NOTES . . . . . . . . . . . . . . . . . . 60 9.1 Changes Since Release 4.0 . . . . . . . . . . . 60 9.2 Changes Since Release 3.0 . . . . . . . . . . . 60 9.3 Changes Since Release 2.0 . . . . . . . . . . . 62 9.4 Changes Since Release 1.0 . . . . . . . . . . . 63 Page 3 1 INTRODUCTION The macro expanders EXPAND and XFORT provide a powerful and flexible approach for coding within multiple environments. They offer macro expansion and debugging facilities that are transparent to the Fortran compiler and destination machine architectures. They also allow programmers to use a superset of ANSI standard Fortran-77 syntax that assist in source coding and that improve the readibility and verifiability of the source code. The use of the expanders does not incur overhead during execution time as the compiled code reflects only the expand-time selected options and no others. EXPAND/XFORT introduces roughly 25% overhead during compilation for a program being compiled for the VAX environment and approximately 200% overhead for a program being compiled for a non-VAX environment, with the increase in overhead arising from the need to perform the translation of variable names longer than six characters for the non-VAX environment. The expanders operate on input files that at the simplest level only contain ANSI standard or VAX Fortran-77 source code. In this case, the expanders are completely passive when expanding for a VAX environment and the resultant output file, before compilation, is identical to the input file. For non-VAX environments, the expanders will accept a certain set of extensions to ANSI Fortran-77 and generate output code that is compatible with the targeted environment. The real power of the expanders lies in the ability of the user to embed macro definitions that allow conditional compilation based on expand-time qualifiers. The macro definitions allow a programmer to tailor code in a completely transparent way to a variety of destination machine architectures ("environments") for which the code may be targeted. EXPAND/XFORT are Fortran programs that are written employing many of the features provided by the expanders. As such, they provide a good example of portable software, as the same source code is used for the DEC VAX/VMS ,IBM VM/CMS and UNIX EXPAND/XFORT implementations. The XFORT expander (available only on the VAX) is an amalgamation of EXPAND and the VAX Fortran compiler. After the input file has been expanded, the VAX compiler is invoked on the expanded source file, obviating the need to manage or refer to the expanded intermediate source file. This allows the user to simply replace the Fortran compilation step with XFORT. In addition, the syntax of the command string and the EXPAND/XFORT error messages are similar to those of the VAX Fortran compiler, with which the user is probably familiar. The functionality of XFORT is provided by the COMPILE exec on the IBM VM/CMS operating system. Most users should read this introduction and section 2 on usage fairly carefully, and read the rest of the paper in "browse" mode. The novice should also refer to section 7 for examples of syntax and usage. As one's sophistication increases (or the need arises), one should read the rest of this manuscript in more detail. Page 4 Users of EXPAND on IBM systems should read the section on the VM/CMS implementation for details on how the VAX-oriented file structure is mapped to the VM/CMS mini-disk system. Users of EXPAND on UNIX systems should read the section on the UNIX Implementation. Modifications to this document since the last major revision (indicated by an increment in the arabic numeral to the left of the decimal point in the version number) appear in the release notes section. Note also that there is a "small" version of the expander available with a version denoted as 4.30s. Note that this is exactly the same as the version 4.30 except that the array used to store the expander input files is a factor of 10 smaller to run on many of the experimental machines that have not been configured to run with enough virtual memory for the "regular" version of the expander. See the section entitled Small Version Implementation. Page 5 2 USAGE As mentioned in the introduction, there are two different macro expanders, XFORT and EXPAND, that are very similar in their function. EXPAND does an expansion of the macro definitions contained in the input file and provides translation of non-Fortran-77 syntax when the targeted environment is other than VAX/VMS. To setup expand on the FNAL cluster issue the following command: $ SETUP EXPAND.version where version is one of the versions availabe. For example, to setup expand 4.30 issue the following command: $ SETUP EXPAND.V4_30 or to setup expand 4.30s (the small version of expand 4.30) issue the following command: $ SETUP EXPAND.V4_30S If you simply issue the command: $ SETUP EXPAND you will get the current version of the expander. To find out the current version, you can either set default to the expand_dir area or type the help expand command. To setup expand on the FNALD cluster issue the following command: $ SETUP EXPAND VERSION_4_30 or similarly: $ SETUP EXPAND VERSION_4_30S The only difference between FNAL and FNALD is a slight syntax difference for the two different clusters. The input file type defaults to ".CDF" if a filetype is not specified. The output filetype can be specified by the user, but defaults to ".VAX" for an input filetype of ".CDF" and ".INC" for an input filetype of ".CIN" on the VAX. The default output filetype is ".IBM" for an input filetype of ".CDF" in the IBM implementation of EXPAND. For the MIPS environment, the default output filetype is .f. EXPAND produces its output file in the user's current default directory, and one may then compile this file using the Fortran compiler. XFORT goes one step further in that it actually invokes the Fortran compiler with default qualifiers "OPTIMIZE/LIST" on the expanded output file. Fortran compiler options are discussed in more detail in section 5. Page 6 At the simplest level, one may use the expanders by typing either $ EXPAND or $ XFORT where either expander will prompt you for if it is omitted. may consist of up to 10 files, separated by either ",", if one wishes separate output files, or "+", if one wants them concatenated into a single output file. You may mix both "," and "+", in one command. In addition, may have local qualifiers appended to it, while the expander name (EXPAND/XFORT) may have global qualifiers appended to it. Both the qualifier syntax and the difference between local and global qualifiers are described in section 5. EXPAND/XFORT will modify the input source file so that the output source code conforms to the syntax of the targeted "environment" specified by the user. In this sense, EXPAND supports an augmented syntax of Fortran-77, allowing the use of constructs such as DO WHILE...ENDDO, hexidecimal and octal notation, and some form of IMPLICIT NONE, even when the native compiler in the targeted environment does not support these. The expanders generate Fortran-77 compliant code in place of the augmented syntax. The extensions supported by EXPAND are described in detail in section 4. Page 7 3 MACRO DEFINITIONS Both expanders support the following macro definitions: $$IMPLICIT $$INCLUDE '' $$BLOCK_DATA '' $$IF VAX IBM ABSOFT CYBER FTN77 FPS MIPS RS6000 SUNOS ULTRIX UNIX