F2C(1)

๐Ÿ‘‘ F2C(1) โ€” like, the iconic Fortran-to-C converter, bestie ๐Ÿ’…

okay so picture this: you've got a dusty old General Commands Manual page called f2c, and it's literally your glow-up guide for dragging Fortran 77 kicking and screaming into the C/C++ world. no cap, this thing ate. let's get into it โœจ


๐ŸŒธ NAME ๐ŸŒธ

f2c โ€” converts Fortran 77 โ†’ C or C++ ๐Ÿฆ‹


๐ŸŽ€ SYNOPSIS ๐ŸŽ€

f2c [ option ...  ] file ...

๐Ÿ’– DESCRIPTION ๐Ÿ’–

so f2c takes Fortran 77 source code from files whose names end in .f or .F and turns it into C (or C++) source files in the current directory, with .c swapped in for the final .f or .F. slay ๐Ÿ’…

and if you don't name any Fortran files at all? it reads Fortran from standard input and writes C on standard output. main character energy, honestly.

oh and โ€” file names ending in .p or .P are treated as prototype files, exactly the kind thing that option -P produces, and those get read first. iykyk ๐Ÿซถ

the options below have the same meaning as in f77(1):

โœจ the options that are giving f77(1) energy โœจ

  • -C โ€” compile the code so subscripts get checked against the declared array bounds. safety first, bestie ๐Ÿ›ก๏ธ
  • -I2 โ€” renders INTEGER and LOGICAL as short, and INTEGER*4 as long int. it assumes the default libF77 and libI77, meaning only INTEGER*4 variables (and no LOGICAL variables) are allowed in INQUIREs. also โ€” option -I4 confirms the default rendering of INTEGER as long int. ๐Ÿ‘
  • -I8 โ€” assumes 8-byte integer and logical, 4-byte REAL, 8-byte double precision and complex, and 16-byte double complex variables. heads up though: appropriate changes to f2c.h may be needed ๐Ÿ˜ญ
  • -Idir โ€” looks for a non-absolute include file first in the directory of the current input file, then in the directories you specified with -I options (one directory per option). but real talk: options -I2, -I4, and -I8 have precedence, so like โ€” if you mean a directory named 2, you gotta say -I./2 ๐Ÿซ 
  • -onetrip โ€” compiles DO loops so they're performed at least once if reached. (because Fortran 77 DO loops aren't performed at all if the upper limit is smaller than the lower limit. yes, that's the vibe. that's the rule.) ๐Ÿ”
  • -U โ€” honors the case of variable and external names. and Fortran keywords must be in lower case, no exceptions ๐Ÿ’€
  • -u โ€” makes the default type of a variable undefined instead of using the default Fortran rules ๐Ÿ‘ป
  • -w โ€” suppresses all warning messages. or, if the option is -w66, just the Fortran 66 compatibility warnings. pick your peace ๐Ÿคซ

๐Ÿฆ‹ the options that are so f2c, nobody else has them ๐Ÿฆ‹

  • -A โ€” produces ANSI C. and that's the default, starting 20020621 btw. for old-style C, use option -K. โญ
  • -a โ€” makes local variables automatic rather than static... unless they show up in a DATA, EQUIVALENCE, NAMELIST, or SAVE statement. exceptions, always exceptions ๐Ÿ™ˆ
  • -C++ โ€” outputs C++ code. periodt ๐Ÿ‘‘
  • -c โ€” includes the original Fortran source as comments ๐Ÿ’ฌ
  • -cd โ€” does not recognize cdabs, cdcos, cdexp, cdlog, cdsin, and cdsqrt as synonyms for the double complex intrinsics zabs, zcos, zexp, zlog, zsin, and zsqrt respectively, and also does not recognize dreal as a synonym for dble. nope. not today. ๐Ÿšซ
  • -cf โ€” doesn't report the current .f file, except in error messages ๐Ÿค
  • -ddir โ€” writes .c files into directory dir instead of the current directory ๐Ÿ“
  • -E โ€” declares uninitialized COMMON to be Extern (overridably defined in f2c.h as extern) ๐Ÿ”ฅ
  • -ec โ€” places uninitialized COMMON blocks in separate files: COMMON /ABC/ appears in file abc_com.c. and option -e1c bundles those separate files into the output file, with comments that give an unbundling sed(1) script. so organized of her ๐Ÿ’–
  • -ext โ€” complains about f77(1) extensions ๐Ÿ˜ค
  • -f โ€” assumes free-format input: accepts text after column 72 and does not pad fixed-format lines shorter than 72 characters with blanks ๐ŸŽ€
  • -72 โ€” treats text appearing after column 72 as an error ๐Ÿšจ
  • -g โ€” includes the original Fortran line numbers in #line lines ๐Ÿ”ข
  • -h โ€” emulates Fortran 66's treatment of Hollerith: tries to align character strings on word boundaries (or, if the option is -hd, on double-word boundaries) ๐Ÿงš
  • -i2 โ€” similar to -I2, but it assumes a modified libF77 and libI77 (compiled with -Df2c_i2), so INTEGER and LOGICAL variables may be assigned by INQUIRE and array lengths are stored in short ints ๐Ÿฉณ
  • -i90 โ€” does not recognize the Fortran 90 bit-manipulation intrinsics btest, iand, ibclr, ibits, ibset, ieor, ior, ishft, and ishftc ๐Ÿšซ
  • -kr โ€” uses temporary values to enforce Fortran expression evaluation where K&R (first edition) parenthesization rules allow rearrangement. and if the option is -krd, it uses double precision temporaries even for single-precision operands ๐Ÿ’…
  • -P โ€” writes a file.P of ANSI (or C++) prototypes for definitions in each input file.f or file.F. when reading Fortran from standard input, it writes the prototypes at the beginning of standard output. and option -Ps implies -P and gives exit status 4 if rerunning f2c may change prototypes or declarations ๐Ÿ‘€
  • -p โ€” supplies preprocessor definitions to make common-block members look like local variables ๐ŸŽญ
  • -R โ€” does not promote REAL functions and operations to DOUBLE PRECISION. option -!R confirms the default, which imitates f77 ๐Ÿ˜Œ
  • -r โ€” casts REAL arguments of intrinsic functions and values of REAL functions (including intrinsics) to REAL ๐Ÿช„
  • -r8 โ€” promotes REAL to DOUBLE PRECISION, and COMPLEX to DOUBLE COMPLEX โฌ†๏ธ
  • -s โ€” preserves multidimensional subscripts. suppressed by option -C. (rude, but okay) ๐Ÿ™ƒ
  • -Tdir โ€” puts temporary files in directory dir ๐Ÿ—‚๏ธ
  • -trapuv โ€” dynamically initializes local variables โ€” except those appearing in SAVE or DATA statements โ€” with values that may help find references to uninitialized variables. for example, with IEEE arithmetic, it initializes local floating-point variables to signaling NaNs. lowkey genius fr fr ๐Ÿ•ต๏ธ
  • -w8 โ€” suppresses warnings when COMMON or EQUIVALENCE forces odd-word alignment of doubles ๐Ÿคซ
  • -Wn โ€” assumes n characters/word (default 4) when initializing numeric variables with character data ๐Ÿ”ค
  • -z โ€” does not implicitly recognize DOUBLE COMPLEX ๐Ÿ’ค
  • -!bs โ€” does not recognize backslash escapes (\", \', \0, \\, \b, \f, \n, \r, \t, \v) in character strings ๐Ÿšซ
  • -!c โ€” inhibits C output, but still produces -P output ๐Ÿคฏ
  • -!I โ€” rejects include statements ๐Ÿ™…
  • -!i8 โ€” disallows INTEGER*8, or, if the option is -!i8const, permits INTEGER*8 but does not promote integer constants to INTEGER*8 when they involve more than 32 bits ๐Ÿ”ข
  • -!it โ€” doesn't infer types of untyped EXTERNAL procedures from use as parameters to previously defined or prototyped procedures ๐Ÿง 
  • -!P โ€” does not attempt to infer ANSI or C++ prototypes from usage ๐Ÿ™ˆ

and the resulting C invokes the support routines of f77; object code should be loaded by f77 or with ld(1) or cc(1) options -lF77 -lI77 -lm. the calling conventions are those of f77: see the reference below, bestie ๐Ÿซถ


๐ŸŒˆ FILES ๐ŸŒˆ

  • file.[fF] โ€” input file ๐Ÿ“ฅ
  • *.c โ€” output file ๐Ÿ“ค
  • /usr/include/f2c.h โ€” header file ๐Ÿ“„
  • /usr/lib/libF77.a โ€” intrinsic function library ๐Ÿงฎ
  • /usr/lib/libI77.a โ€” Fortran I/O library ๐Ÿ’พ
  • /lib/libc.a โ€” C library, see section 3 ๐Ÿ“š

๐Ÿ“ SEE ALSO ๐Ÿ“

S. I. Feldman and P. J. Weinberger, A Portable Fortran 77 Compiler, UNIX Time Sharing System Programmer's Manual, Tenth Edition, Volume 2, AT&T Bell Laboratories, 1990. ๐Ÿ“–โœจ


๐Ÿ’€ DIAGNOSTICS ๐Ÿ’€

the diagnostics produced by f2c are intended to be self-explanatory. so like, read them. they're telling you things. ๐Ÿ˜Œ


๐Ÿงš BUGS ๐Ÿงš

  • Floating-point constant expressions are simplified in the floating-point arithmetic of the machine running f2c, so they are typically accurate to at most 16 or 17 decimal places ๐Ÿ˜ญ
  • Untypable EXTERNAL functions are declared int ๐Ÿซ 
  • There is no notation for INTEGER*8 constants ๐Ÿ’€
  • Some intrinsic functions do not yet work with INTEGER*8 ๐Ÿ™ˆ

okay that's the whole page, bestie ๐ŸŽ€ and for the cute sign-off: this one's filed under F2C(1) in your General Commands Manual, with all that ANSI-C-by-default goodness dated back to 20020621. go forth and convert, you gorgeous nerd ๐Ÿ’œ๐Ÿฆ‹โœจ

๐Ÿ“ฆ where this page comes from