next up [*] print clean
Next: Changes and backward compatibility Up: Table of Contents

SOFTWARE SUPPORT

 ``Ratfor" (RATional FORtran) is a dialect of Fortran that is more concise than raw Fortran. Our present Ratfor ``compiler,'' ratfor90, is a simple word-processing program (written[*] in Perl and freely distributed) that inputs an attractive Fortran-like dialect and outputs Fortran90. Mainly, the word-processor produces Fortran statements like end do, end if, end program and end module, from the Ratfor ``}''. Ratfor source is about 25-30% smaller than the equivalent Fortran, so it is equivalently more readable.

Bare-bones Fortran is our most universal computer language for computational physics. For general programming, however, it has been surpassed by C. Ratfor is Fortran with C-like syntax. Ratfor was invented by the people[*] who invented C. After inventing C, they realized that they had made a mistake (too many semicolons) and they fixed it in Ratfor, although it was too late for C. Otherwise, Ratfor uses C-like syntax, the syntax that is also found in the popular languages C++ and Java.

At SEP we supplemented Ratfor77 by preprocessors to give Fortran77 the ability to allocate memory on the fly. These abilities are built into Fortran90 and are seamlessly included in Ratfor90. To take advantage of Fortran90's new features while maintaining the concise coding style provided by Ratfor, we had to write a new Ratfor preprocessor, Ratfor90, which produces Fortran90 rather than Fortran77 code.

You should be able to read Ratfor if you already know Fortran or any similar computer language. Writing Ratfor is easy if you already know Fortran because written Fortran is valid Ratfor. You can mix Ratfor and Fortran. The Ratfor processor is not a compiler but a simple word-processing program which passes Fortran (which it does not understand) through unchanged. The Ratfor processor converts the Ratfor dialect to Fortran. To maximize the amount of Ratfor, you will need to know its rules. Here they are:

Statements on a line may be separated by ``;''. Statements may be grouped together with braces { }. Do loops do not require statement numbers because { } defines the range. Given that if( ) is true, the statements in the following { } are done. else{ } does what you expect. We may not contract else if to elseif. We may omit the braces { } where they contain only one statement. break (equivalent to the Fortran90 exit) causes premature termination of the enclosing { }. while( ) { } repeats the statements in { } while the condition ( ) is true. Ratfor recognizes repeat { ... } until( ) as a loop that tests at the bottom. next causes skipping to the end of any loop and a retrial of the test condition. next (equivalent to the Fortran90 cycle statement) is rarely used, and the Ratfor90 coder may write either next or cycle. Here we encounter an inconsistency between Fortran and C-language. Where Ratfor uses next, the C-language uses continue (which in Ratfor and Fortran is merely a place holder for labels). The Fortran relational operators .gt., .ge., .ne., etc. may be written >, >=, !=, etc. The logical operators .and. and .or. may be written && and ||. Anything from a # to the end of the line is a comment. A line may be continued in Ratfor by ending it with the underscore charactor ``_'' (like Fortran90's &).

Indentation in Ratfor is used for readability. It is not part of the Ratfor language. Choose your own style. I have overcondensed. There are two pitfalls associated with indentation. The beginner's pitfall is to assume that a do loop ends where the indentation ends. The loop actually ends after the first statement. A larger scope for the do loop is made by enclosing multiple statements in braces. The other pitfall arises in any construction like if() ... if() ... else. The else goes with the last if() regardless of indentation. If you want the else with the earlier if(), you must use braces like if() { if() ... } else .... Ratfor also recognizes the looping statement used in C, C++, and Java. It is for(initialize; condition; reinitialize) { }.


 
next up [*] print clean
Next: Changes and backward compatibility Up: Table of Contents
Stanford Exploration Project
4/27/2004