promulaFortran
promulaFortran is a software tool that translates FORTRAN source code (source.for) to C source code (source.c).
  1. Promula® FORTRAN to C Translator/Compiler
  2. How Does It Work?
  3. Rationale for Developing promulaFortran
  4. Downsizing Mainframe Codes for Use on the PC DOS Platform
  5. Dealing with FORTRAN Dialect Problems
  6. Dealing with C Types and FORTRAN Types
  7. Dealing with FORTRAN Input/Output in C
  8. Runtime Library
  9. Dealing with COMMON Blocks
  10. Allocation of Local Variables
  11. A Sample Translation to C
  12. Licensing
  13. Pricing
  14. Customer References
   Promula® FORTRAN to C Translator/Compiler
The Promula FORTRAN to C Translator (promulaFortran) is a tool that translates FORTRAN source code to correct (compilable) and clean (readable and maintainable) C source code. The C code produced can then be compiled with almost any C compiler on almost any platform to produce executable code, which in turn will produce results on the target C platform that are identical to the results produced on the source FORTRAN platform. What’s more, the C code is clean and readable so that, if you wish, you can start maintaining your application in C rather than in FORTRAN. And, unlike the original FORTRAN, the C code is portable so you can move it to multiple "open" platforms. In addition, the tool is flexible and configurable to allow extensive user control over both the input FORTRAN dialect accepted and the look of the C output generated.
This tool is intended for those who wish to convert their FORTRAN codes to C automatically; 100 percent conversion rates are achieved routinely. The conversions yield reproducible results and are repeatable and verifiable. A number of input FORTRAN dialects are supported via a dialect definition flag, and the form of the output C code is controlled by a multitude of command-line switches.
The translations are so complete and correct that the tool may also be used in conjunction with a standard C Compiler as a general-purpose, multi-dialect and portable FORTRAN compiler. It runs on multiple platforms and supports both the ANSI FORTRAN 66 and ANSI FORTRAN 77 standard dialects, as well as a large number of extensions found in various commercial FORTRAN compilers. The following FORTRAN dialects are supported: VAX, PDP, SUN, HP, CRAY, PRIME, Data General, UNISYS, and Honeywell. Some FORTRAN 90 extensions are also supported. With this product, existing FORTRAN applications will compile on "open" platforms as is, i.e., without making any changes to the original FORTRAN source code.
Validated by the GSA FORTRAN Compiler Validation Test Suite, the compiler works by translating FORTRAN source code to C source code (from where it derives its portability). It requires a C compiler/linker to produce executable code and is the ideal processor for hybrid FORTRAN/C applications. Symbolic FORTRAN debugging is supported by the symbolic debugger of the host C platform (e.g., the dbx tool for UNIX platforms).

No matter how old or how extended your FORTRAN dialect is, promulaFortran will process it by first translating it to the more versatile and more portable C language. Your long-established FORTRAN programs do not have to be maintenance burdens running inefficiently on old platforms; with promulaFortran, you can give them new life on contemporary platforms where you can take advantage of new technology options, including the option of program maintenance in either FORTRAN or C.
promulaFortran offers a number of advantages over other FORTRAN to C translators:
  1. Multi-Dialect, Multi-Platform Processing. promulaFortran translates both standard and nonstandard dialects of FORTRAN. Both the ANSI FORTRAN 66 and the ANSI FORTRAN 77 dialects are supported, and several Fortran 90 extensions are included as well. Several commercial, extended dialects of FORTRAN -such as VAX, PDP, PRIME, Honeywell, Data general, and SUN -are also supported. The C source code generated can be ported to any platform that supports a standard C compiler. In addition, the translator can be configured to process dialect extensions not included in the default dialect definition.
     
  2. Completeness. The syntax processor handles almost all features of standard and extended FORTRAN dialects, including structures and pointer variables. On the execution side, its comprehensive runtime library covers the full functionality of all of the above FORTRAN dialects (full FORTRAN I/O, complex arithmetic, NAMELIST, DECODE/ENCODE, DEFINE FILE, B-FORMAT, %VAL, %REF, %DESCR, STRUCTURE, RECORD, embedded and inline comments, etc.).
     
  3. Correctness. Since promulaFortran compiles FORTRAN to C, i.e., performs both a syntactic and a semantic transformation of FORTRAN to C, the translated C code is both compilable and "correct,” that is, it yields reproducible results -which is not the case with other translation tools which are limited to simple syntax transformations that yield partial or incorrect translations. The compiler has been tested on several platforms with Version 2.0 of the FORTRAN compiler Validation System from the Federal Software Testing Center and passed the test at the full validation level on all platforms.
     
  4. Software Conversion. promulaFortran is a highly efficient portation tool. It can convert thousands of lines of code per minute, depending on the platform, and achieves 100 percent conversion rates routinely, “right out of the box." By removing the need to make any manual source changes during the conversion, it makes the porting process repeatable and allows for rigorous port verification.
     
  5. Language Migration. promulaFortran is a language migration tool. It helps you migrate from maintaining your applications in FORTRAN to maintaining them in C. You can treat the C code generated by promulaFortran as an intermediate step in a compilation or as the end product of an automatic translation process.
     
  6. Documentation. According to a Computer Language review (October, 1988), “the documentation for promulaFortran is excellent. It meticulously details the translation process, how to create your own dialects, all the runtime library routines, the inner pseudocode into which promulaFortran translates your FORTRAN, how this pseudocode translates back to C, and more." In addition, the language reference component of the documentation describes the actual FORTRAN dialect that promulaFortran supports.
     
  7. Error Processing. When a FORTRAN error occurs, an error message is issued and the user has the option to exit or continue processing. A command-line switch allows the user to select from five different error handling options:
    1. Stop translation when the first error is encountered
    2. Translate all errors into non-compilable FORTRAN ERROR statements
    3. Translate all errors into non-linkable FORTRAN ERROR function calls
    4. Translate all errors into executable print-error-message statements
    5. Translate all errors into warning comments.
The C code produced by promulaFortran is clean, readable and maintainable. The code generator actually offers three major output options (or biases) as well as a multitude of detailed command-line switches:
  1. The FORTRAN bias generates C output which is as close to the original FORTRAN as possible and is aimed at easing the transition of those users who are presently FORTRAN programmers but wish to (or must) become C programmers.
  2. The C bias generates C output which looks much like a standard C program and is aimed at those users who are C programmers but must now take over the maintenance of a FORTRAN code
  3. The optimized bias generates C output which is designed to compile as quickly as possible and to produce an efficient as possible executable module. This output is not very readable and is aimed at those users who wish to continue to program in FORTRAN. For these users, the C output is of no importance as such. It is merely an intermediate step and serves as input to the C compiler.
   How Does It Work?
promulaFortran translates FORTRAN code to C code which can then be compiled via any standard C compiler and linked with the promulaFortran runtime library to produce efficient executable code. The resultant executable code produces the same results on a target platform as the original code does on the source platform.
In designing promulaFortran we took the position that the only difference between a translator and a compiler should be that a compiler converts the source code into machine language while a translator takes it to a higher level language. promulaFortran compiles the FORTRAN source language into a low level pseudo-code. This pseudo-code is much like the output produced by the first, or second, pass of contemporary compilers. Second, it optimizes that code using the same techniques as used during the optimization pass of a compiler. Third, it does code generation; but the code generated is not machine code, it is C.
A more detailed description of the design and methodology of promulaFortran appeared in a series of three technical papers in the Journal of C Language Translation:
  1. “Design of a FORTRAN to C Translator," Fred K. Goodman, Vol. 1, December, 1989 and March, 1990.
  2. “FORTRAN to C: Numerical Issues," Fred K. Goodman, Vol. 2, June, 1990.
  3. “FORTRAN to C: Character Manipulation," Fred K. Goodman, Vol. 2, September, 1990.
   Rationale for Developing promulaFortran
Since the beginning of FORTRAN there has always been a problem -FORTRAN is not transportable from machine to machine or even from one operating system to another.
In contrast, the C language is unique in that it is available for almost every type of computer -from home computers to supercomputers. It is extremely efficient, modular, and portable. It is presently the language of choice for many operating system programmers and compiler designers.
In addition to authoring promulaFortran, we have been developing FORTRAN development tools and FORTRAN applications for clients since 1967. In converting FORTRAN programs from one platform to another, our typical problem was not that we could not find a good FORTRAN 77 compiler for the target platform, but rather that we were confronted by FORTRAN programs that were almost always written in non-standard, non-machine-transportable FORTRAN dialects. The typical mainframe FORTRAN program is not written in standard FORTRAN and makes assumptions about the machine and operating system for which it was originally written. FORTRAN programs are just not portable.
promulaFortran was designed to deal with actual FORTRAN programs, written by “nonstructured" FORTRAN programmers who took advantage of every possible special feature of their particular vendor’s compiler, and who had never known or cared that there was a standard, or two, available.
If you have a relatively small FORTRAN 77 program and wish to use it on a new platform in a C environment, then you have a variety of compilers and/or translators available to you, but we think promulaFortran will give you the best results. However, if you have a serious FORTRAN program and you do not wish to do any changes by hand, then we know that promulaFortran is your only current alternative.
We originally developed promulaFortran for use in our own consulting business because we were unable to find a FORTRAN compiler which would effectively and accurately process the typical FORTRAN programs which we wished to migrate to the PC or other workstations. Having once developed the translator, we discovered that far more than just translation could be achieved during the conversion. Many other problems could also be solved by translating to C.
   Downsizing Mainframe Codes for Use on the PC DOS Platform
Many FORTRAN programs are written with the assumption that a very large memory is available. This is because most machines above the PC class have virtual operating systems. A standard “error-free" translation of a statement like the following

   DIMENSION A(10000,20),B(10000,20)

would be

   static float a[20][10000],b[20][10000];

The fact that this is syntactically error-free is of little significance since no C compiler presently available for the PC will accept it. Faced with this problem, what do you do? In the brute force approach, you would probably go through the code -maybe all 10000 lines of it -and change the references to arrays A and B to some sort of disk reference. You would probably also analyze how these arrays are referenced so that you could make the disk accesses as efficient as possible.

In processing large programs on the limited memory model of the PC-DOS platform, promulaFortran takes a virtual memory approach. In promulaFortran, you can tell the translator that all variables larger than a certain number of bytes should be treated as virtual memory disk variables. The runtime library has a very efficient set of virtual memory management routines, and the translator replaces references to the specified variables with function calls to the virtual memory functions. The subscript calculations are replaced by virtual memory address calculations.
Thus, promulaFortran allows you to bring an entire class of FORTRAN programs to the PC which cannot now be processed easily by any other product available.
   Dealing with FORTRAN Dialect Problems
Other translators deal primarily with FORTRAN 77, require that tokens contain no blanks and be separated, and treat FORTRAN statement names as reserved words. FORTRAN codes not meeting these specifications must be changed by the user manually. Our experience has been that many FORTRAN programs are written in FORTRAN 66 or in some mixed dialect of FORTRAN 66 and FORTRAN 77. Since FORTRAN has no keywords and explicitly ignores all blanks in its source statements, many perfectly readable FORTRAN programs do not meet the above requirements.
promulaFortran translates FORTRAN 66 as well as FORTRAN 77 programs. The user can control those aspects of the two languages which conflict by selecting options in the translation process.
The translator accepts split tokens, token sequences without separators, blank lines, comment lines within continuation sequences, and other potential translation ambiguities. You do not have to “clean up the code" to use promulaFortran. So, if you have an old 66 program punched on a 026 keypunch with a drum card on as few cards as possible and you can get it onto a disk, promulaFortran can process it for you.
Also promulaFortran knows the difference between

   DO10I=1,5 and DO10I=1.5

or

   DO 10 I = 1,5 and DO 10 I = 1.5

and translates them all correctly.

promulaFortran deals with all of the “violations" of standard character manipulation including hiding character values in arithmetic variables, mixing character and non-character variables in COMMON blocks, equivalencing character variables with arithmetic variables, and assuming that CHARACTER*N and CHARACTER*1(N) have the same memory representations.

   Dealing with C Types and FORTRAN Types
promulaFortran gives you access to all of the following standard C types:
  • signed char
  • unsigned char
  • short signed int
  • short unsigned int
  • long signed int
  • long unsigned int
  • float
  • double
and to float complex and double complex structured types.
Though promulaFortran has the usual set of default FORTRAN types, you can specify which FORTRAN type should connect to which C type. If your dialect of FORTRAN includes nonstandard types such as BOOLEAN or BYTE or INTEGER*3, then you can include these. In addition, FORTRAN compilers differ as to whether logical types are bit sequences or simply TRUE/FALSE values. You may also select this. If bit sequences are assumed, the “logical" operators become bit-manipulation operators.
   Dealing with FORTRAN Input/Output in C
The approach taken to FORTRAN input/output statements by promulaFortran is straightforward. The C programs should behave identically to their FORTRAN counterparts. All standard I/O statements are accepted including long FORMAT statements. These tend to be rejected by C compilers because their initialization strings exceed the compiler limit on the length of individual static strings. C input/output is managed via calls to functions in the C library. C has no input/output statements as such. FORTRAN input/output statements are translated into calls to functions in the promulaFortran runtime library. These functions perform input/output the way FORTRAN does.
Though the general form of input/output statements is quite standard throughout the FORTRAN dialect community, no two FORTRAN compilers have the identical set of options. This is the major area in which dialects differ. With the promulaFortran dialect manager you may describe the individual options associated with your particular dialect. In addition, you may specify the form of the function to be referenced in the translation. Then you can simply write the needed function and include it in your version of the runtime library.
   Runtime Library
The promulaFortran runtime library is a set of approximately 300 functions designed for use with the promulaFortran translator. It may also be used by those FORTRAN programmers who wish to program in C, but who do not wish to give up the input/output conventions, formatting controls, and intrinsic functions which they have grown used to.
Initially, C codes using this library can be produced by translating FORTRAN programs into C using the promulaFortran translator. Once in C, the programs may then be maintained by using these functions.
If there is one certainty, it is that no two FORTRANs behave in the same way, especially with regard to their runtime libraries. Thus, if your conventions differ from the ones used here, then you may alter the library code. Alternatively, your version of FORTRAN may contain statements which require runtime support not included in this library. In this case, you can add the additional functions needed.
   Dealing with COMMON Blocks
If there is any aspect of FORTRAN that can destroy the validity of a translation, it is COMMON blocks -especially when combined with EQUIVALENCE statements. Every storage trick ever conceived gets used in the nuances of changing COMMON block definitions through a large FORTRAN program. There is no best way to translate COMMON blocks. Some compilers, for example, insert extra bytes to achieve various types of alignments, and programmers using these compilers will take that fact into account without any warning or comment for the user.
promulaFortran translates COMMON blocks in one of four ways. It is up to you to select the appropriate one depending upon your needs and preferences:
  1. The default is to declare the COMMON block identifiers simply as external void pointers and then to assign them locally to a structure pointer whose members are defined in the same manner as the COMMON definition in the routine. This technique works in all cases except where alignments are needed.
     
  2. In cases where COMMON blocks are always defined in the same manner, the common blocks are simply defined as external structures. This gives more efficient code than the technique above.
     
  3. The most efficient technique can be used when no games are played with the common blocks at all. Then, the blocks themselves are removed and the variables within them become external variables directly.
     
  4. The final technique is used when an exact block layout is required. The COMMON block is declared as an external pointer to a char. The variable positions within the block are calculated with user-supplied alignment and size specifications. Actual variable references then become references to the COMMON block name plus the calculated position.
   Allocation of Local Variables
Most FORTRAN compilers allocate a fixed unique storage location to all variables, be they COMMON or local. The equivalent allocation in C is called “static“, and by default all variables in the translation are declared as static variables. C, however, has two additional storage allocation methods -auto and dynamic.
Auto variables are stored on the program stack automatically when a function is called and are automatically removed when the function is exited. The advantage of these variables is that they occupy memory only when needed and their physical allocation is quick and transparent to the C program. The disadvantage of auto variables is that the program stack tends to be quite short; thus, the number and size of auto variables are very limited.
Dynamic variables are stored on the heap via explicit calls to a function and must also be freed explicitly via a function call. The disadvantage of dynamic variables is that their allocation is slow as compared to auto variables, and the allocation itself must be done explicitly. The advantage is that the heap is generally quite large.
Using promulaFortran you have complete control over the allocation of variables in the translation.
   A Sample Translation to C
The output from promulaFortran does not look like machine translation. To present some of the design features of the translator, consider the following example program which computes the mean and variance of a set of values.

INPUT
   SUBROUTINE EX001(VAL,N,XBAR,VAR)
   DIMENSION VAL(N)
   XBAR=0.0
   VAR=0.0
   DO 10 J = 1,N
   XBAR = XBAR + VAL(J)
10 CONTINUE
   XBAR = XBAR/N
   DO 15 J = 1,N
   S = VAL(J) - XBAR
   VAR = VAR + S*S
15 CONTINUE
   VAR = VAR/(N-1)
   RETURN
   END
OUTPUT
void ex001(val,n,xbar,var)
int n;
float *val,*xbar,*var;
{
    auto int j;
    auto float s;
    *xbar = *var = 0.0;
    for(j=0; j<n; j++) *xbar += *(val+j);
    *xbar /= n;
    for(j=0; j<n; j++) {
        s = *(val+j)-*xbar;
        *var += (s*s);
    }
    *var /= (n-1);
}
NOTES
 
 (1)
 
 
 
 
(2)
(3)-(6)
(5)
(3) (4)
(5)
(7)
(5)
 
Note (1) that the parameter “n" is not declared as a pointer, since it is not changed within the routine. promulaFortran uses what are called “prototypes" of subprogram arguments so that it can generate optimal calling sequences. These “prototypes" may be specified by the user or may be determined internally by the translator. The above was internally determined by the translator.
 
Note (2) that C allows multiple assignments to the same value to be written together. The translator looks for such assignments and combines them whenever possible.
 
Note (3) that in FORTRAN the default base for a subscript is 1. Thus, all do loops which generate subscripts tend to start at 1. In C, however, subscripts start at zero. This fact makes for much more efficient code. The translator looks for do loops whose only purpose is to move through array subscripts and reduces their range to start at zero, thus producing a very natural looking for-statement and optimizing subscript expressions.
 
Note (4) that C has “++" and “--" operators which take advantage of the fact that most computers have increment and decrement operators. The translator uses these operators whenever possible.
 
Note (5) that C has operators like “+=“, “-=“, “*=“, “/=“, etc. The use of these operators ensures that the address of the left-hand-side of the assignment will only be computed as often as necessary. promulaFortran uses these operators.
 
Note (6) that the do loop running to statement 10 in the FORTRAN code is collapsed into a single compound statement, and that the now unneeded statement label is removed.
 
Note (7) that though the do loop statements in loop 15 cannot be reduced to a single statement, the statement label can still be removed.

In summary, promulaFortran looks for every opportunity to simplify and optimize the translation and to make it look as natural as possible in the C language form.
   Licensing
The product includes both the translator/compiler and an extensive FORTRAN Run-time Library (about 300 functions written in portable C source code). The run-time library may be linked into your executables for royalty-free distribution.
A free demo/evaluation service and four license levels are available for the product:
  1. Single User License for use by a single user
  2. Group License (2-5 users) for use by a small group of users
  3. Custom License for use in support of migration projects with specific custom requirements. This includes both product and varying levels of product customization services, as needed by the migration project.
  4. Enterprise License for use by an enterprise in support of large-scale migration projects. This includes both product and software conversion services, as needed by the migration project.
The Demo Service
As part of the Demo Service, we will be happy to do a sample FORTRAN-to-C translation for any client who may be interested in evaluating how well and how completely Promula FORTRAN will translate the client’s particular dialect of FORTRAN source code. If you will send us a sample of your FORTRAN source code -subject to a non-disclosure agreement, if necessary -then we will translate it to C using Promula FORTRAN and show you the resulting C source code for your evaluation. You may include as many lines of FORTRAN code as you wish in the sample. If the sample is a complete application, then the demo will show reproducibility of results by compiling it, linking it into executable form, running it on some target platform, and comparing results.
The Demo Service is provided free of charge. The turnaround for a typical demo translation is 1-2 days.
The Standard License
The Standard License includes the translator software (in executable form) for the target platform and software user documentation (a Compiler Manual and a Translator Manual). It also includes the source code of the Promula FORTRAN Library so that you may compile and link your applications into executable codes on arbitrary target platforms.
The Custom License
The standard version of the translator is capable of translating several dialects of FORTRAN -certainly all those we have seen in the long lifetime of the tool (since 1987). Over the years, thousands of our clients have used the standard version of the translator to port thousands of applications (millions of lines of FORTRAN code) to C. From time to time, however, a client comes along with a "strange" FORTRAN dialect, whose extensions we haven't seen before. For such a client, we will make a custom version of the tool, tailored to handle the "strange" dialect. The custom license allows for varying degrees or levels of tool customization.
The Enterprise License
This is an unlimited multi-user, multi-machine, site license. It is intended for use in large-scale portation projects that may require tailored translations and customized runtime library support. This license includes the Promula FORTRAN to C Translator for a particular platform, the source code for the Promula FORTRAN Runtime Library, and six (6) months of software maintenance and user support (by telephone, fax, mail, or e-mail).
As part of the support services under this license, PDC will revise or configure the translator to produce custom translations that satisfy both local FORTRAN dialect requirements as well as particular programming conventions for the C output.
Consulting Services
In support of our Custom or Site License, for clients wishing to perform their own conversions, we offer consulting services to ensure that their ports are done in an efficient and effective manner to meet their project needs and deadlines. Software upgrade services (e.g., improved user interfaces) for the ported software are also available. Our consulting rates are: $1,200 a day per consultant (plus reasonable travel and living expenses).
For clients wishing to outsource, we will perform turnkey portations and guarantee performance, subject to reproducibility of results. Fixed rates of between $0.20 and $1.00 per line of source code apply, depending upon the number of lines of code to be converted, the complexity (machine dependence) of the application, and its runtime library support needs.
The FORTRAN Library Source
The Promula FORTRAN Runtime Library is a comprehensive library of about 300 functions (written in standard, portable C) which support the full functionality of the FORTRAN language (FORTRAN I/O, complex arithmetic, FORTRAN intrinsic functions, business format for PRIME FORTRAN applications, virtual memory management, etc.). With the source code of this library, C translations can be ported to arbitrary platforms.
As part of the Custom or Site License, PDC will add functionality to this library, as needed in support of particular migration projects.
   Pricing
Pricing information is available upon request.
   Customer References
Click here for a partial list of promulaFortran clients.