STRSF3 1L "01 February 1991"

Table of contents


strsf3 - a Fortran to SFTRAN3 translator program.


strsf3 [-a] [-b brk] [-c inc] [-d num] [-e max] [-h hash] [-i] [-m nod] [-n nxt] [-p line] [-s form] [-t lab] file1 file2 ...


strsf3 translates the Fortran program specified by the file list file1, file2, ... (standard input by default) into SFTRAN3, and sends output to the standard output. SFTRAN3 is a Ratfor-like structured programming language developed at the Jet Propulsion Laboratory, which serves as the primary development language for the <PLOT79> scientific line graphics package (see plot79(1L)). Wherever possible, SFTRAN3 control constructs replace the original Fortran. Statement numbers appear only where still necessary. Cosmetic changes are made, including changing Hollerith strings into quoted strings and relational operators into symbols (for example, indented. Note the additional remarks in the section entitled "DETAILS OF OUTPUT FORMATTING" below.

Note that the switch -s is required if the input is standard-form Fortran (that is, it is not Unix free-form). Use of a non-zero argument to the -e option is recommended, to eliminate GOTO statements which are likely to remain if the default is assumed. A typical application would be: strsf3 -e20 -s myprogram.f > myprogram.sf3


If an optional unsigned decimal integer argument associated with an option is not specified, its value is assumed to be 0.
Turn a sequence of ELSE IF commands into a switch of the form:

	{	case pred1: code
		case pred2: code
		case pred3: code
		default: code

The case predicates are tested in order; the code appropriate to only one case is executed (this generalized form of switch statement does not occur in Ratfor).

-b brk
If brk is non-zero, use multilevel breaks. If brk is zero, use single-level breaks only.
-c inc
Increment successive labels in the output program by the nonzero integer inc (default 1).
-d num
Select the amount of debug information printed. The argument num may be composed by adding the following values:
0	no debug information
4	tokens
8	line break decisions
16	Hollerith/string recognitions
32	depth-first searches
64	vxparts at graph nodes
128	structure labels
-e max
Allow a maximum of max nodes to be left in a loop without iterating.
-h hash
Employ a hash table which is hash bytes in length (hash must be prime).
Do not turn computed GOTO statements into CASE statements.
-m nod
Allow a maximum of nod nodes.
-n nxt
If nxt is non-zero, use multilevel NEXT commands. If nxt is zero use single-level NEXT commands only.
-p line
Print a line number every line lines to report on the rate of processing.
-s form
If form is zero, use Unix freeform input (as accepted by f77(1)). If form is one, use standard form input; that is, comments are specified by a c, C, or * in column 1, and continuation lines are specified by a nonzero, nonblank character in column 6.
-t lab
Use lab as the initial label value (default 10).


library files


document(1L), drawit(1L), emacs(1L), pfort(1L), plot79.intro(1L), plot79(1L), pretty(1L), ratfor(1), rdinfo(1L), slides(1L), struct(1)
SFTRAN/3 Installation Guide, Nelson H. F. Beebe, Departments of Physics and Chemistry, University of Utah, Salt Lake City, 1980.
SFTRAN3 Programmer's Reference Manual (JPL Document no. 1846-98), C. L. Lawson and J. Flynn, Jet Propulsion Laboratory, California Institute of Technology, Pasadena, December 1, 1978.


strsf3 preserves the input source code format as much as possible, because its output routine retrieves tokens directly from the original source file, rather than from a list of parsed tokens (which would have lost inter-token spacing information). Non-continued statements which are not indented in the output will have exactly the same spacing; thus comments, type declarations, DATA, and FORMAT statements will not have any special spacing destroyed.

Statements involved in flow-of-control will in general be reformatted, and indented according to the SFTRAN3 nesting level, but continuation lines will usually have their original spacing and indentation preserved. The emacs(1L) SFTRAN3 Mode function ^R FORTRAN Eliminate Multiple Spaces (normally attached to M-space) can be used to reliably reformat such continued statements.

strsf3 attaches comments immediately preceding a labelled statement to that statement, so that they will be moved if the statement is moved. Since most programmers place comments before the statements they refer to, this is the desirable action. However, if comments refer to preceding statements, and are immediately followed by a labelled statement, they may be incorrectly placed in the output, and some manual editing may be necessary.

strsf3 does not do a complete parse of its input Fortran code. In particular, Hollerith and quoted string constants are not identified as such. Consequently, when a continuation line must be generated in the SFTRAN3 output routine, the statement buffer is scanned backwards to find a suitable place to break the statement (after one of the characters contained within the following pair of double quotation marks, including the space character: ",)=/: "), and then the scan continues to find any Hollerith or quoted string constructs which would be split across the line boundary. If no string appears to be split, the break is accepted and a continuation line is generated. If a string split would occur, then if the string is short enough to fit on a continuation line, the break is made before it. Otherwise, the break is made in column 72 and indentation of the continuation line is suppressed so that it begins in column 7. This is adequate for most purposes and has worked quite successfully on the conversion of the entire <PLOT79> source (about 700 routines and 150,000 lines of code). It can, however, fail to recognize Hollerith strings embedded in quoted strings, or vice versa, and may make a bad split.

Code rearrangement may require the negation of the conditions in IF statements, which is accomplished by turning IF (cond) etc into IF (.NOT.(cond)) etc If cond already begins with a .NOT., this generates a double negative which could be removed but is not. Similarly, if cond is of the form (exp1) .relop. (exp2) then .NOT.(cond) could be rewritten by negating the relational operator. This is not done either, since strsf3 has not parsed the conditional expression.

In order to reliably repair these two cases and improve the readability, the emacs(1L) SFTRAN3/Fortran Mode function UnNot can be applied to the source code. It will leave intact any expressions which contain more than one logical or relational operator, and will convert all of the others which begin with ".NOT.(" and ".NOT.(.NOT.". It handles only one expression at a time, so that the user has the opportunity to reformat the statement with M-space.


strsf3 knows Fortran 66 syntax, but not full Fortran 77.

If an input Fortran program contains identifiers which are reserved words in strsf3, the structured version of the program will not be a valid strsf3 program.

Unused FORMAT statements appear without statement numbers, producing compilation errors; these statements must be removed manually.

The ERR=xx exit on I/O statements is not recognized. Consequently, output code contains a branch to a non-existent label. The correct SFTRAN3 syntax is LOGICAL FLAG,EOFILE READ (...,FLAG=ERR,EOFILE=END) ... if (FLAG) ... if (EOFILE) ...

strsf3 produces many inverted logical expressions of the form IF (.NOT.(...)) A partial solution ot this problem is provided in the sed(1) script strsf3.sed, which does regular expression substitutions to simplify such expressions; this script is automatically invoked upon the output. However, because regular expressions cannot count, it is not possible to produce balanced parentheses in complicated expressions. For example, IF (.NOT.(scalar.LE.scalar)) is converted properly, but IF (.NOT.(vector(index).LE.vector(index))) is not. Similarly, because sed(1) cannot recognize expressions split across lines, other logical expressions are missed.

A Fortran statement of the form: IF (expr) n1,n2,n3 will be converted into an SFTRAN3 statement of the form: IF (expr .relop. 0) etc If expr is not of type INTEGER, the IF contains a mixed mode expression.

A computed GOTO in which labels appear more than once, such as: GOTO (10,10,20,30),K will generate an illegal SFTRAN3 CASE statement in which a case number is repeated (as in: CASE 1,2). strsf3 does not duplicate code, so this must be patched manually.

Under certain rare circumstances, strsf3 may move a loop inside another loop which has the same index. The patch is simply to rename the index of the innermost loop.

If an END FOREVER statement immediately precedes the END PROGRAM statement, the SFTRAN3 preprocessor will incorrectly generate an unreachable labelled CONTINUE statement following the GOTO which terminates the loop. In such a case, the RETURN or STOP inside the DO FOREVER ... END FOREVER loop can be changed to an EXIT FOREVER and the RETURN/STOP moved to the end of the program unit, or it may be possible to rewrite the DO FOREVER as a DO UNTIL or DO WHILE.


The strsf3 program was adapted from the UNIX program struct(1) (developed by Brenda Baker of Bell Laboratories for conversion of Fortran to the structured language Ratfor (see ratfor(1)) by Nelson H. F. Beebe, Ph.D. (College of Science Computer, Departments of Chemistry and Physics, University of Utah, Salt Lake City, Utah 84112). Bug repairs and manual page made by: Conrad Huang and R. P. C. Rodgers (Department of Pharmaceutical Chemistry, UCSF School of Pharmacy, San Francisco, CA 94143).