FORTRAN vs. C
For programmers interested in converting existing FORTRAN programs to
C, there is a book entitled "From Fortran to C" by J. F. Kerrigan ISBN
0-8306-7661-9, which contains some useful information. It is
organized by Fortran keyword, and in each section gives a C
replacement for the Fortran construct.
I cannot really recommend the book as a reference for going the other
way, (i.e. for C programmers learning about Fortran) because most of
the Fortran examples are not particularly well written. For example,
(1) most of the format statements have hollerith strings in them
(instead of the conceptually simpler, consistent, use of '-delimited
character strings),
(2) variables in common blocks are initialized in data statements
(in f77 such initializations must be localized in block data
subprograms),
(3) named common blocks appear inconsistently in save statements
(in f77 if a block is saved anywhere, it must be saved everywhere),
and
(4) the examples use fortran specific intrinsic functions (a bad
programming practice; generic intrinsics should always be used when
possible to enhance portability).
Another general shortcoming of the book, particularly for scientific
programmers, is that all of the correspondences between Fortran and C
data types are based on a 16-bit microcomputer point of view. For
example, C types "double" and "long double" are both mapped
to Fortran
"double precision" which in turn is associated in the text with
"real*8". (No mention is made of fortran "real*16" which is
supported
on many machines as 128-bit floating point.) However, I think on a
Cray, a C "double" maps to "real", which is really
equivalent to
either of the fortran declarations "real*4" or "real*8", and
C "long
double" maps to "double precision", which is really equivalent to
"real*16". Maybe someone with more C experience on a Cray can correct
this if I'm wrong.
There is also some confusion introduced in the book when C "char" is
identified with Fortran "character". In fact, the C "char"
data type
is really an integer data type. A better correspondence would be C
"char" with the result of the fortran intrinsic ichar() operating on a
character*1 argument. Character variables in Fortran are really
structured entities, with the components of the structure hidden from
the programmer (until cross-language calls are needed, at which time
the actual structure must be dealt with explicitly). This applies to
fortran character values of any length, whereas in C long strings are
associated with char arrays.
As far as I know, this is the only book available that is devoted to
bridging the Fortran to C language gap.
-ron shepard
p.s. I know that nonprogrammers on this bboard may be getting bored
with this discussion, but as long as useful information is being
exchanged, I'm reluctant to encourage its termination. Bear with us
and you'll eventually benefit from the superior code that we write. (:-)