cfortran-4.4/0040755000175000017500000000000007574533122013427 5ustar kmccartykmccartycfortran-4.4/cfortran.doc0100644000175000017500000026772306634251625015753 0ustar kmccartykmccarty/* cfortran.doc 4.3 */ /* www-zeus.desy.de/~burow OR anonymous ftp@zebra.desy.de */ /* Burkhard Burow burow@desy.de 1990 - 1998. */ cfortran.h : Interfacing C or C++ and FORTRAN Supports: Alpha and VAX VMS, Alpha OSF, DECstation and VAX Ultrix, IBM RS/6000, Silicon Graphics, Sun, CRAY, Apollo, HP9000, LynxOS, Convex, Absoft, f2c, g77, NAG f90, PowerStation Fortran with Visual C++, NEC SX-4, Portland Group. C and C++ are generally equivalent as far as cfortran.h is concerned. Unless explicitly noted otherwise, mention of C implicitly includes C++. C++ compilers tested include: SunOS> CC +p +w # Clean compiles. IRIX> CC # Clean compiles. IRIX> CC -fullwarn # Still some warnings to be overcome. GNU> g++ -Wall # Compiles are clean, other than warnings for unused # cfortran.h static routines. N.B.: The best documentation on interfacing C or C++ and Fortran is in the chapter named something like 'Interfacing C and Fortran' to be found in the user's guide of almost every Fortran compiler. Understanding this information for one or more Fortran compilers greatly clarifies the aims and actions of cfortran.h. Such a chapter generally also addresses issues orthogonal to cfortran.h, for example the order of array indices, the index of the first element, as well as compiling and linking issues. 0 Short Summary of the Syntax Required to Create the Interface -------------------------------------------------------------- e.g. Prototyping a FORTRAN subroutine for C: /* PROTOCCALLSFSUBn is optional for C, but mandatory for C++. */ PROTOCCALLSFSUB2(SUB_NAME,sub_name,STRING,PINT) #define SUB_NAME(A,B) CCALLSFSUB2(SUB_NAME,sub_name,STRING,PINT, A,B) ^ - - number of arguments _____| | STRING BYTE PBYTE BYTEV(..)| / | STRINGV DOUBLE PDOUBLE DOUBLEV(..)| / | PSTRING FLOAT PFLOAT FLOATV(..)| types of arguments ____ / | PNSTRING INT PINT INTV(..)| \ | PPSTRING LOGICAL PLOGICAL LOGICALV(..)| \ | PSTRINGV LONG PLONG LONGV(..)| \ | ZTRINGV SHORT PSHORT SHORTV(..)| | PZTRINGV ROUTINE PVOID SIMPLE | - - e.g. Prototyping a FORTRAN function for C: /* PROTOCCALLSFFUNn is mandatory for both C and C++. */ PROTOCCALLSFFUN1(INT,FUN_NAME,fun_name,STRING) #define FUN_NAME(A) CCALLSFFUN1(FUN_NAME,fun_name,STRING, A) e.g. calling FUN_NAME from C: {int a; a = FUN_NAME("hello");} e.g. Creating a FORTRAN-callable wrapper for a C function returning void, with a 7 dimensional integer array argument: [Not supported from C++.] FCALLSCSUB1(csub_name,CSUB_NAME,csub_name,INTVVVVVVV) e.g. Creating a FORTRAN-callable wrapper for other C functions: FCALLSCFUN1(STRING,cfun_name,CFUN_NAME,cfun_name,INT) [ ^-- BYTE, DOUBLE, FLOAT, INT, LOGICAL, LONG, SHORT, VOID are other types returned by functions. ] e.g. COMMON BLOCKs: FORTRAN: common /fcb/ v,w,x character *(13) v, w(4), x(3,2) C: typedef struct { char v[13],w[4][13],x[2][3][13]; } FCB_DEF; #define FCB COMMON_BLOCK(FCB,fcb) COMMON_BLOCK_DEF(FCB_DEF,FCB); FCB_DEF FCB; /* Define, i.e. allocate memory, in exactly one *.c file. */ e.g. accessing FCB in C: printf("%.13s",FCB.v); I Introduction -------------- cfortran.h is an easy-to-use powerful bridge between C and FORTRAN. It provides a completely transparent, machine independent interface between C and FORTRAN routines (= subroutines and/or functions) and global data, i.e. structures and COMMON blocks. The complete cfortran.h package consists of 4 files: the documentation in cfortran.doc, the engine cfortran.h, examples in cfortest.c and cfortex.f/or. [cfortex.for under VMS, cfortex.f on other machines.] The cfortran.h package continues to be developed. The most recent version is available via www at http://www-zeus.desy.de/~burow or via anonymous ftp at zebra.desy.de (131.169.2.244). The examples may be run using one of the following sets of instructions: N.B. Unlike earlier versions, cfortran.h 3.0 and later versions automatically uses the correct ANSI ## or pre-ANSI /**/ preprocessor operator as required by the C compiler. N.B. As a general rule when trying to determine how to link C and Fortran, link a trivial Fortran program using the Fortran compilers verbose option, in order to see how the Fortran compiler drives the linker. e.g. unix> cat f.f END unix> f77 -v f.f .. lots of info. follows ... N.B. If using a C main(), i.e. Fortran PROGRAM is not entry of the executable, and if the link bombs with a complaint about a missing "MAIN" (e.g. MAIN__, MAIN_, f90_main or similar), then Fortran has hijacked the entry point to the executable and wishes to call the rest of the executable via "MAIN". This can usually be satisfied by doing e.g. 'cc -Dmain=MAIN__ ...' but often kills the command line arguments in argv and argc. The f77 verbose option, usually -v, may point to a solution. RS/6000> # Users are strongly urged to use f77 -qextname and cc -Dextname RS/6000> # Use -Dextname=extname if extname is a symbol used in the C code. RS/6000> xlf -c -qextname cfortex.f RS/6000> cc -c -Dextname cfortest.c RS/6000> xlf -o cfortest cfortest.o cfortex.o && cfortest DECFortran> #Only DECstations with DECFortran for Ultrix RISC Systems. DECFortran> cc -c -DDECFortran cfortest.c DECFortran> f77 -o cfortest cfortest.o cfortex.f && cfortest IRIX xxxxxx 5.2 02282015 IP20 mips MIPS> # DECstations and Silicon Graphics using the MIPS compilers. MIPS> cc -o cfortest cfortest.c cfortex.f -lI77 -lU77 -lF77 && cfortest MIPS> # Can also let f77 drive linking, e.g. MIPS> cc -c cfortest.c MIPS> f77 -o cfortest cfortest.o cfortex.f && cfortest Apollo> # Some 'C compiler 68K Rev6.8' break. [See Section II o) Notes: Apollo] Apollo> f77 -c cfortex.f && cc -o cfortest cfortest.c cfortex.o && cfortest VMS> define lnk$library sys$library:vaxcrtl VMS> cc cfortest.c VMS> fortran cfortex.for VMS> link/exec=cfortest cfortest,cfortex VMS> run cfortest OSF1 xxxxxx V3.0 347 alpha Alpha/OSF> # Probably better to let cc drive linking, e.g. Alpha/OSF> f77 -c cfortex.f Alpha/OSF> cc -o cfortest cfortest.c cfortex.o -lUfor -lfor -lFutil -lots -lm Alpha/OSF> cfortest Alpha/OSF> # Else may need 'cc -Dmain=MAIN__' to let f77 drive linking. Sun> # Some old cc(1) need a little help. [See Section II o) Notes: Sun] Sun> f77 -o cfortest cfortest.c cfortex.f -lc -lm && cfortest Sun> # Some older f77 may require 'cc -Dmain=MAIN_'. CRAY> cft77 cfortex.f CRAY> cc -c cfortest.c CRAY> segldr -o cfortest.e cfortest.o cfortex.o CRAY> ./cfortest.e NEC> cc -c -Xa cfortest.c NEC> f77 -o cfortest cfortest.o cfortex.f && cfortest VAX/Ultrix/cc> # For cc on VAX Ultrix only, do the following once to cfortran.h. VAX/Ultrix/cc> mv cfortran.h cftmp.h && grep -v "^#pragma" cfortran.h VAX/Ultrix/f77> # In the following, 'CC' is either 'cc' or 'gcc -ansi'. NOT'vcc' VAX/Ultrix/f77> CC -c -Dmain=MAIN_ cfortest.c VAX/Ultrix/f77> f77 -o cfortest cfortex.f cfortest.o && cfortest LynxOS> # In the following, 'CC' is either 'cc' or 'gcc -ansi'. LynxOS> # Unfortunately cc is easily overwhelmed by cfortran.h, LynxOS> # and won't compile some of the cfortest.c demos. LynxOS> f2c -R cfortex.f LynxOS> CC -Dlynx -o cfortest cfortest.c cfortex.c -lf2c && cfortest HP9000> # Tested with HP-UX 7.05 B 9000/380 and with A.08.07 A 9000/730 HP9000> # CC may be either 'c89 -Aa' or 'cc -Aa' HP9000> # Depending on the compiler version, you may need to include the HP9000> # option '-tp,/lib/cpp' or worse, you'll have to stick to the K&R C. HP9000> # [See Section II o) Notes: HP9000] HP9000> # Users are strongly urged to use f77 +ppu and cc -Dextname HP9000> # Use -Dextname=extname if extname is a symbol used in the C code. HP9000> CC -Dextname -c cfortest.c HP9000> f77 +ppu cfortex.f -o cfortest cfortest.o && cfortest HP9000> # Older f77 may need HP9000> f77 -c cfortex.f HP9000> CC -o cfortest cfortest.c cfortex.o -lI77 -lF77 && cfortest HP0000> # If old-style f77 +800 compiled objects are required: HP9000> # #define hpuxFortran800 HP9000> cc -c -Aa -DhpuxFortran800 cfortest.c HP9000> f77 +800 -o cfortest cfortest.o cfortex.f f2c> # In the following, 'CC' is any C compiler. f2c> f2c -R cfortex.f f2c> CC -o cfortest -Df2cFortran cfortest.c cfortex.c -lf2c && cfortest Portland Group $ # Presumably other C compilers also work. Portland Group $ pgcc -DpgiFortran -c cfortest.c Portland Group $ pgf77 -o cfortest cfortex.f cfortest.o && cfortest NAGf90> # cfortex.f is distributed with Fortran 77 style comments. NAGf90> # To convert to f90 style comments do the following once to cfortex.f: NAGf90> mv cfortex.f cf_temp.f && sed 's/^C/\!/g' cf_temp.f > cfortex.f NAGf90> # In the following, 'CC' is any C compiler. NAGf90> CC -c -DNAGf90Fortran cfortest.c NAGf90> f90 -o cfortest cfortest.o cfortex.f && cfortest PC> # On a PC with PowerStation Fortran and Visual_C++ PC> cl /c cftest.c PC> fl32 cftest.obj cftex.for GNU> # GNU Fortran GNU> # See Section VI caveat on using 'gcc -traditional'. GNU> gcc -ansi -Wall -O -c -Df2cFortran cfortest.c GNU> g77 -ff2c -o cfortest cfortest.o cfortex.f && cfortest AbsoftUNIX> # Absoft Fortran for all UNIX based operating systems. AbsoftUNIX> # e.g. Linux or Next on Intel or Motorola68000. AbsoftUNIX> # Absoft f77 -k allows Fortran routines to be safely called from C. AbsoftUNIX> gcc -ansi -Wall -O -c -DAbsoftUNIXFortran cfortest.c AbsoftUNIX> f77 -k -o cfortest cfortest.o cfortex.f && cfortest AbsoftPro> # Absoft Pro Fortran for MacOS AbsoftPro> # Use #define AbsoftProFortran CLIPPER> # INTERGRAPH CLIX using CLIPPER C and Fortran compilers. CLIPPER> # N.B. - User, not cfortran.h, is responsible for CLIPPER> # f77initio() and f77uninitio() if required. CLIPPER> # - LOGICAL values are not mentioned in CLIPPER doc.s, CLIPPER> # so they may not yet be correct in cfortran.h. CLIPPER> # - K&R mode (-knr or Ac=knr) breaks FLOAT functions CLIPPER> # (see CLIPPER doc.s) and cfortran.h does not fix it up. CLIPPER> # [cfortran.h ok for old sun C which made the same mistake.] CLIPPER> acc cfortest.c -c -DCLIPPERFortran CLIPPER> af77 cfortex.f cfortest.o -o cfortest By changing the SELECTion ifdef of cfortest.c and recompiling one can try out a few dozen different few-line examples. The benefits of using cfortran.h include: 1. Machine/OS/compiler independent mixing of C and FORTRAN. 2. Identical (within syntax) calls across languages, e.g. C FORTRAN CALL HBOOK1(1,'pT spectrum of pi+',100,0.,5.,0.) /* C*/ HBOOK1(1,"pT spectrum of pi+",100,0.,5.,0.); 3. Each routine need only be set up once in its lifetime. e.g. /* Setting up a FORTRAN routine to be called by C. ID,...,VMX are merely the names of arguments. These tags must be unique w.r.t. each other but are otherwise arbitrary. */ PROTOCCALLSFSUB6(HBOOK1,hbook1,INT,STRING,INT,FLOAT,FLOAT,FLOAT) #define HBOOK1(ID,CHTITLE,NX,XMI,XMA,VMX) \ CCALLSFSUB6(HBOOK1,hbook1,INT,STRING,INT,FLOAT,FLOAT,FLOAT, \ ID,CHTITLE,NX,XMI,XMA,VMX) 4. Source code is NOT required for the C routines exported to FORTRAN, nor for the FORTRAN routines imported to C. In fact, routines are most easily prototyped using the information in the routines' documentation. 5. Routines, and the code calling them, can be coded naturally in the language of choice. C routines may be coded with the natural assumption of being called only by C code. cfortran.h does all the required work for FORTRAN code to call C routines. Similarly it also does all the work required for C to call FORTRAN routines. Therefore: - C programmers need not embed FORTRAN argument passing mechanisms into their code. - FORTRAN code need not be converted into C code. i.e. The honed and time-honored FORTRAN routines are called by C. 6. cfortran.h is a single ~1700 line C include file; portable to most remaining, if not all, platforms. 7. STRINGS and VECTORS of STRINGS along with the usual simple arguments to routines are supported as are functions returning STRINGS or numbers. Arrays of pointers to strings and values of structures as C arguments, will soon be implemented. After learning the machinery of cfortran.h, users can expand it to create custom types of arguments. [This requires no modification to cfortran.h, all the preprocessor directives required to implement the custom types can be defined outside cfortran.h] 8. cfortran.h requires each routine to be exported to be explicitly set up. While is usually only be done once in a header file it would be best if applications were required to do no work at all in order to cross languages. cfortran.h's simple syntax could be a convenient back-end for a program which would export FORTRAN or C routines directly from the source code. ----- Example 1 - cfortran.h has been used to make the C header file hbook.h, which then gives any C programmer, e.g. example.c, full and completely transparent access to CERN's HBOOK library of routines. Each HBOOK routine required about 3 lines of simple code in hbook.h. The example also demonstrates how FORTRAN common blocks are defined and used. /* hbook.h */ #include "cfortran.h" : PROTOCCALLSFSUB6(HBOOK1,hbook1,INT,STRING,INT,FLOAT,FLOAT,FLOAT) #define HBOOK1(ID,CHTITLE,NX,XMI,XMA,VMX) \ CCALLSFSUB6(HBOOK1,hbook1,INT,STRING,INT,FLOAT,FLOAT,FLOAT, \ ID,CHTITLE,NX,XMI,XMA,VMX) : /* end hbook.h */ /* example.c */ #include "hbook.h" : typedef struct { int lines; int status[SIZE]; float p[SIZE]; /* momentum */ } FAKE_DEF; #define FAKE COMMON_BLOCK(FAKE,fake) COMMON_BLOCK_DEF(FAKE_DEF,FAKE); : main () { : HBOOK1(1,"pT spectrum of pi+",100,0.,5.,0.); /* c.f. the call in FORTRAN: CALL HBOOK1(1,'pT spectrum of pi+',100,0.,5.,0.) */ : FAKE.p[7]=1.0; : } N.B. i) The routine is language independent. ii) hbook.h is machine independent. iii) Applications using routines via cfortran.h are machine independent. ----- Example 2 - Many VMS System calls are most easily called from FORTRAN, but cfortran.h now gives that ease in C. #include "cfortran.h" PROTOCCALLSFSUB3(LIB$SPAWN,lib$spawn,STRING,STRING,STRING) #define LIB$SPAWN(command,input_file,output_file) \ CCALLSFSUB3(LIB$SPAWN,lib$spawn,STRING,STRING,STRING, \ command,input_file,output_file) main () { LIB$SPAWN("set term/width=132","",""); } Obviously the cfortran.h command above could be put into a header file along with the description of the other system calls, but as this example shows, it's not much hassle to set up cfortran.h for even a single call. ----- Example 3 - cfortran.h and the source cstring.c create the cstring.obj library which gives FORTRAN access to all the functions in C's system library described by the system's C header file string.h. C EXAMPLE.FOR PROGRAM EXAMPLE DIMENSION I(20), J(30) : CALL MEMCPY(I,J,7) : END /* cstring.c */ #include /* string.h prototypes memcpy() */ #include "cfortran.h" : FCALLSCSUB3(memcpy,MEMCPY,memcpy,PVOID,PVOID,INT) : The simplicity exhibited in the above example exists for many but not all machines. Note 4. of Section II ii) details the limitations and describes tools which try to maintain the best possible interface when FORTRAN calls C routines. ----- II Using cfortran.h ------------------- The user is asked to look at the source files cfortest.c and cfortex.f for clarification by example. o) Notes: o Specifying the Fortran compiler cfortran.h generates interfaces for the default Fortran compiler. The default can be overridden by defining, . in the code, e.g.: #define NAGf90Fortran OR . in the compile directive, e.g.: unix> cc -DNAGf90Fortran one of the following before including cfortran.h: NAGf90Fortran f2cFortran hpuxFortran apolloFortran sunFortran IBMR2Fortran CRAYFortran mipsFortran DECFortran vmsFortran CONVEXFortran PowerStationFortran AbsoftUNIXFortran SXFortran pgiFortran AbsoftProFortran This also allows crosscompilation. If wanted, NAGf90Fortran, f2cFortran, DECFortran, AbsoftUNIXFortran, AbsoftProFortran and pgiFortran must be requested by the user. o /**/ cfortran.h (ab)uses the comment kludge /**/ when the ANSI C preprocessor catenation operator ## doesn't exist. In at least MIPS C, this kludge is sensitive to blanks surrounding arguments to macros. Therefore, for applications using non-ANSI C compilers, the argtype_i, routine_name, routine_type and common_block_name arguments to the PROTOCCALLSFFUNn, CCALLSFSUB/FUNn, FCALLSCSUB/FUNn and COMMON_BLOCK macros --- MUST NOT --- be followed by any white space characters such as blanks, tabs or newlines. o LOGICAL FORTRAN LOGICAL values of .TRUE. and .FALSE. do not agree with the C representation of TRUE and FALSE on all machines. cfortran.h does the conversion for LOGICAL and PLOGICAL arguments and for functions returning LOGICAL. Users must convert arrays of LOGICALs from C to FORTRAN with the C2FLOGICALV(array_name, elements_in_array); macro. Similarly, arrays of LOGICAL values may be converted from the FORTRAN into C representation by using F2CLOGICALV(array_name, elements_in_array); When C passes or returns LOGICAL values to FORTRAN, by default cfortran.h only makes the minimal changes required to the value. [e.g. Set/Unset the single relevant bit or do nothing for FORTRAN compilers which use 0 as FALSE and treat all other values as TRUE.] Therefore cfortran.h will pass LOGICALs to FORTRAN which do not have an identical representation to .TRUE. or .FALSE. This is fine except for abuses of FORTRAN/77 in the style of: logical l if (l .eq. .TRUE.) ! (1) instead of the correct: if (l .eqv. .TRUE.) ! (2) or: if (l) ! (3) For FORTRAN code which treats LOGICALs from C in the method of (1), LOGICAL_STRICT must be defined before including cfortran.h, either in the code, "#define LOGICAL_STRICT", or compile with "cc -DLOGICAL_STRICT". There is no reason to use LOGICAL_STRICT for FORTRAN code which does not do (1). At least the IBM's xlf and the Apollo's f77 do not even allow code along the lines of (1). DECstations' DECFortran and MIPS FORTRAN compilers use different internal representations for LOGICAL values. [Both compilers are usually called f77, although when both are installed on a single machine the MIPS' one is usually renamed. (e.g. f772.1 for version 2.10.)] cc doesn't know which FORTRAN compiler is present, so cfortran.h assumes MIPS f77. To use cc with DECFortran define the preprocessor constant 'DECFortran'. e.g. i) cc -DDECFortran -c the_code.c or ii) #define DECFortran /* in the C code or add to cfortran.h. */ MIPS f77 [SGI and DECstations], f2c, and f77 on VAX Ultrix treat .eqv./.neqv. as .eq./.ne.. Therefore, for these compilers, LOGICAL_STRICT is defined by default in cfortran.h. [The Sun and HP compilers have not been tested, so they may also require LOGICAL_STRICT as the default.] o SHORT and BYTE They are irrelevant for the CRAY where FORTRAN has no equivalent to C's short. Similarly BYTE is irrelevant for f2c and for VAX Ultrix f77 and fort. The author has tested SHORT and BYTE with a modified cfortest.c/cfortex.f on all machines supported except for the HP9000 and the Sun. BYTE is a signed 8-bit quantity, i.e. values are -128 to 127, on all machines except for the SGI [at least for MIPS Computer Systems 2.0.] On the SGI it is an unsigned 8-bit quantity, i.e. values are 0 to 255, although the SGI 'FORTRAN 77 Programmers Guide' claims BYTE is signed. Perhaps MIPS 2.0 is dated, since the DECstations using MIPS 2.10 f77 have a signed BYTE. To minimize the difficulties of signed and unsigned BYTE, cfortran.h creates the type 'INTEGER_BYTE' to agree with FORTRAN's BYTE. Users may define SIGNED_BYTE or UNSIGNED_BYTE, before including cfortran.h, to specify FORTRAN's BYTE. If neither is defined, cfortran.h assumes SIGNED_BYTE. o CRAY The type DOUBLE in cfortran.h corresponds to FORTRAN's DOUBLE PRECISION. The type FLOAT in cfortran.h corresponds to FORTRAN's REAL. On a classic CRAY [i.e. all models except for the t3e]: ( 64 bit) C float == C double == Fortran REAL (128 bit) C long double == Fortran DOUBLE PRECISION Therefore when moving a mixed C and FORTRAN app. to/from a classic CRAY, either the C code will have to change, or the FORTRAN code and cfortran.h declarations will have to change. DOUBLE_PRECISION is a cfortran.h macro which provides the former option, i.e. the C code is automatically changed. DOUBLE_PRECISION is 'long double' on classic CRAY and 'double' elsewhere. DOUBLE_PRECISION thus corresponds to FORTRAN's DOUBLE PRECISION on all machines, including classic CRAY. On a classic CRAY with the fortran compiler flag '-dp': Fortran DOUBLE PRECISION thus is also the faster 64bit type. (This switch is often used since the application is usually satisfied by 64 bit precision and the application needs the speed.) DOUBLE_PRECISION is thus not required in this case, since the classic CRAY behaves like all other machines. If DOUBLE_PRECISION is used nonetheless, then on the classic CRAY the default cfortran.h behavior must be overridden, for example by the C compiler option '-DDOUBLE_PRECISION=double'. On a CRAY t3e: (32 bit) C float == Fortran Unavailable (64 bit) C double == C long double == Fortran REAL == Fortran DOUBLE PRECISION Notes: - (32 bit) is available as Fortran REAL*4 and (64 bit) is available as Fortran REAL*8. Since cfortran.h is all about more portability, not about less portability, the use of the nonstandard REAL*4 and REAL*8 is strongly discouraged. - Fortran DOUBLE PRECISION is folded to REAL with the following warning: 'DOUBLE PRECISION is not supported on this platform. REAL will be used.' Similarly, Fortran REAL*16 is mapped to REAL*8 with a warning. This behavior differs from that of other machines, including the classic CRAY. FORTRAN_REAL is thus introduced for the t3e, just as DOUBLE_PRECISION is introduced for the classic CRAY. FORTRAN_REAL is 'double' on t3e and 'float' elsewhere. FORTRAN_REAL thus corresponds to FORTRAN's REAL on all machines, including t3e. o f2c f2c, by default promotes REAL functions to double. cfortran.h does not (yet) support this, so the f2c -R option must be used to turn this promotion off. o f2c [Thanks to Dario Autiero for pointing out the following.] f2c has a strange feature in that either one or two underscores are appended to a Fortran name of a routine or common block, depending on whether or not the original name contains an underscore. S.I. Feldman et al., "A fortran to C converter", Computing Science Technical Report No. 149. page 2, chapter 2: INTERLANGUAGE conventions ........... To avoid conflict with the names of library routines and with names that f2c generates, Fortran names may have one or two underscores appended. Fortran names are forced to lower case (unless the -U option described in Appendix B is in effect); external names, i.e. the names of fortran procedures and common blocks, have a single underscore appended if they do not contain any underscore and have a pair of underscores appended if they do contain underscores. Thus fortran subroutines names ABC, A_B_C and A_B_C_ result in C functions named abc_, a_b_c__ and a_b_c___. ........... cfortran.h is unable to change the naming convention on a name by name basis. Fortran routine and common block names which do not contain an underscore are unaffected by this feature. Names which do contain an underscore may use the following work-around: /* First 2 lines are a completely standard cfortran.h interface to the Fortran routine E_ASY . */ PROTOCCALLSFSUB2(E_ASY,e_asy, PINT, INT) #define E_ASY(A,B) CCALLSFSUB2(E_ASY,e_asy, PINT, INT, A, B) #ifdef f2cFortran #define e_asy_ e_asy__ #endif /* Last three lines are a work-around for the strange f2c naming feature. */ o NAG f90 The Fortran 77 subset of Fortran 90 is supported. Extending cfortran.h to interface C with all of Fortran 90 has not yet been examined. The NAG f90 library hijacks the main() of any program and starts the user's program with a call to: void f90_main(void); While this in itself is only a minor hassle, a major problem arises because NAG f90 provides no mechanism to access command line arguments. At least version 'NAGWare f90 compiler Version 1.1(334)' appended _CB to common block names instead of the usual _. To fix, add this to cfortran.h: #ifdef old_NAG_f90_CB_COMMON #define COMMON_BLOCK CFC_ /* for all other Fortran compilers */ #else #define COMMON_BLOCK(UN,LN) _(LN,_CB) #endif o RS/6000 Using "xlf -qextname ...", which appends an underscore, '_', to all FORTRAN external references, requires "cc -Dextname ..." so that cfortran.h also generates these underscores. Use -Dextname=extname if extname is a symbol used in the C code. The use of "xlf -qextname" is STRONGLY ENCOURAGED, since it allows for transparent naming schemes when mixing C and Fortran. o HP9000 Using "f77 +ppu ...", which appends an underscore, '_', to all FORTRAN external references, requires "cc -Dextname ..." so that cfortran.h also generates these underscores. Use -Dextname=extname if extname is a symbol used in the C code. The use of "f77 +ppu" is STRONGLY ENCOURAGED, since it allows for transparent naming schemes when mixing C and Fortran. At least one release of the HP /lib/cpp.ansi preprocessor is broken and will go into an infinite loop when trying to process cfortran.h with the ## catenation operator. The K&R version of cfortran.h must then be used and the K&R preprocessor must be specified. e.g. HP9000> cc -Aa -tp,/lib/cpp -c source.c The same problem with a similar solution exists on the Apollo. An irrelevant error message '0: extraneous name /usr/include' will appear for each source file due to another HP bug, and can be safely ignored. e.g. 'cc -v -c -Aa -tp,/lib/cpp cfortest.c' will show that the driver passes '-I /usr/include' instead of '-I/usr/include' to /lib/cpp On some machines the above error causes compilation to stop; one must then use K&R C, as with old HP compilers which don't support function prototyping. cfortran.h has to be informed that K&R C is to being used, e.g. HP9000> cc -D__CF__KnR -c source.c o AbsoftUNIXFortran By default, cfortran.h follows the default AbsoftUNIX/ProFortran and prepends _C to each COMMON BLOCK name. To override the cfortran.h behavior #define COMMON_BLOCK(UN,LN) before #including cfortran.h. [Search for COMMON_BLOCK in cfortran.h for examples.] o Apollo On at least one release, 'C compiler 68K Rev6.8(168)', the default C preprocessor, from cc -A xansi or cc -A ansi, enters an infinite loop when using cfortran.h. This Apollo bug can be circumvented by using: . cc -DANSI_C_preprocessor=0 to force use of /**/, instead of '##'. AND . The pre-ANSI preprocessor, i.e. use cc -Yp,/usr/lib The same problem with a similar solution exists on the HP. o Sun Old versions of cc(1), say <~1986, may require help for cfortran.h applications: . #pragma may not be understood, hence cfortran.h and cfortest.c may require sun> mv cfortran.h cftmp.h && grep -v "^#pragma" cfortran.h sun> mv cfortest.c cftmp.c && grep -v "^#pragma" cfortest.c . Old copies of math.h may not include the following from a newer math.h. [For an ancient math.h on a 386 or sparc, get similar from a new math.h.] #ifdef mc68000 /* 5 lines Copyright (c) 1988 by Sun Microsystems, Inc. */ #define FLOATFUNCTIONTYPE int #define RETURNFLOAT(x) return (*(int *)(&(x))) #define ASSIGNFLOAT(x,y) *(int *)(&x) = y #endif o CRAY, Sun, Apollo [pre 6.8 cc], VAX Ultrix and HP9000 Only FORTRAN routines with less than 15 arguments can be prototyped for C, since these compilers don't allow more than 31 arguments to a C macro. This can be overcome, [see Section IV], with access to any C compiler without this limitation, e.g. gcc, on ANY machine. o VAX Ultrix vcc (1) with f77 is not supported. Although: VAXUltrix> f77 -c cfortex.f VAXUltrix> vcc -o cfortest cfortest.c cfortex.o -lI77 -lU77 -lF77 && cfortest will link and run. However, the FORTRAN standard I/O is NOT merged with the stdin and stdout of C, and instead uses the files fort.6 and fort.5. For vcc, f77 can't drive the linking, as for gcc and cc, since vcc objects must be linked using lk (1). f77 -v doesn't tell much, and without VAX Ultrix manuals, the author can only wait for the info. required. fort (1) is not supported. Without VAX Ultrix manuals the author cannot convince vcc/gcc/cc and fort to generate names of routines and COMMON blocks that match at the linker, lk (1). i.e. vcc/gcc/cc prepend a single underscore to external references, e.g. NAME becomes _NAME, while fort does not modify the references. So ... either fort has prepend an underscore to external references, or vcc/gcc/cc have to generate unmodified names. man 1 fort mentions JBL, is JBL the only way? o VAX VMS C The compiler 'easily' exhausts its table space and generates: %CC-F-BUGCHECK, Compiler bug check during parser phase . Submit an SPR with a problem description. At line number 777 in DISK:[DIR]FILE.C;1. where the line given, '777', includes a call across C and FORTRAN via cfortran.h, usually with >7 arguments and/or very long argument expressions. This SPR can be staved off, with the simple modification to cfortran.h, such that the relevant CCALLSFSUBn (or CCALLSFFUNn or FCALLSCFUNn) is not cascaded up to CCALLSFSUB14, and instead has its own copy of the contents of CCALLSFSUB14. [If these instructions are not obvious after examining cfortran.h please contact the author.] [Thanks go to Mark Kyprianou (kyp@stsci.edu) for this solution.] o Mips compilers e.g. DECstations and SGI, require applications with a C main() and calls to GETARG(3F), i.e. FORTRAN routines returning the command line arguments, to use two macros as shown: : CF_DECLARE_GETARG; /* This must be external to all routines. */ : main(int argc, char *argv[]) { : CF_SET_GETARG(argc,argv); /* This must precede any calls to GETARG(3F). */ : } The macros are null and benign on all other systems. Sun's GETARG(3F) also doesn't work with a generic C main() and perhaps a workaround similar to the Mips' one exists. o Alpha/OSF Using the DEC Fortran and the DEC C compilers of DEC OSF/1 [RT] V1.2 (Rev. 10), Fortran, when called from C, has occasional trouble using a routine received as a dummy argument. e.g. In the following the Fortran routine 'e' will crash when it tries to use the C routine 'c' or the Fortran routine 'f'. The example works on other systems. C FORTRAN /* C */ integer function f() #include f = 2 int f_(); return int e_(int (*u)()); end int c(){ return 1;} integer function e(u) int d (int (*u)()) { return u();} integer u external u main() e=u() { /* Calls to d work. */ return printf("d (c ) returns %d.\n",d (c )); end printf("d (f_) returns %d.\n",d (f_)); /* Calls to e_ crash. */ printf("e_(c ) returns %d.\n",e_(c )); printf("e_(f_) returns %d.\n",e_(f_)); } Solutions to the problem are welcomed! A kludge which allows the above example to work correctly, requires an extra argument to be given when calling the dummy argument function. i.e. Replacing 'e=u()' by 'e=u(1)' allows the above example to work. o The FORTRAN routines are called using macro expansions, therefore the usual caveats for expressions in arguments apply. The expressions to the routines may be evaluated more than once, leading to lower performance and in the worst case bizarre bugs. o For those who wish to use cfortran.h in large applications. [See Section IV.] This release is intended to make it easy to get applications up and running. This implies that applications are not as efficient as they could be: - The current mechanism is inefficient if a single header file is used to describe a large library of FORTRAN functions. Code for a static wrapper fn. is generated in each piece of C source code for each FORTRAN function specified with the CCALLSFFUNn statement, irrespective of whether or not the function is ever called. - Code for several static utility routines internal to cfortran.h is placed into any source code which #includes cfortran.h. These routines should probably be in a library. i) Calling FORTRAN routines from C: -------------------------------- The FORTRAN routines are defined by one of the following two instructions: for a SUBROUTINE: /* PROTOCCALLSFSUBn is optional for C, but mandatory for C++. */ PROTOCCALLSFSUBn(ROUTINE_NAME,routine_name,argtype_1,...,argtype_n) #define Routine_name(argname_1,..,argname_n) \ CCALLSFSUBn(ROUTINE_NAME,routine_name,argtype_1,...,argtype_n, \ argname_1,..,argname_n) for a FUNCTION: PROTOCCALLSFFUNn(routine_type,ROUTINE_NAME,routine_name,argtype_1,...,argtype_n) #define Routine_name(argname_1,..,argname_n) \ CCALLSFFUNn(ROUTINE_NAME,routine_name,argtype_1,...,argtype_n, \ argname_1,..,argname_n) Where: 'n' = 0->14 [SUBROUTINE's ->27] (easily expanded in cfortran.h to > 14 [27]) is the number of arguments to the routine. Routine_name = C name of the routine (IN UPPER CASE LETTERS).[see 2.below] ROUTINE_NAME = FORTRAN name of the routine (IN UPPER CASE LETTERS). routine_name = FORTRAN name of the routine (IN lower case LETTERS). routine_type = the type of argument returned by FORTRAN functions. = BYTE, DOUBLE, FLOAT, INT, LOGICAL, LONG, SHORT, STRING, VOID. [Instead of VOID one would usually use CCALLSFSUBn. VOID forces a wrapper function to be used.] argtype_i = the type of argument passed to the FORTRAN routine and must be consistent in the definition and prototyping of the routine s.a. = BYTE, DOUBLE, FLOAT, INT, LOGICAL, LONG, SHORT, STRING. For vectors, i.e. 1 dim. arrays use = BYTEV, DOUBLEV, FLOATV, INTV, LOGICALV, LONGV, SHORTV, STRINGV, ZTRINGV. For vectors of vectors, i.e. 2 dim. arrays use = BYTEVV, DOUBLEVV, FLOATVV, INTVV, LOGICALVV, LONGVV, SHORTVV. For n-dim. arrays, 1<=n<=7 [7 is the maximum in Fortran 77], = BYTEV..nV's..V, DOUBLEV..V, FLOATV..V, INTV..V, LOGICALV..V, LONGV..V, SHORTV..V. N.B. Array dimensions and types are checked by the C compiler. For routines changing the values of an argument, the keyword is prepended by a 'P'. = PBYTE, PDOUBLE, PFLOAT, PINT, PLOGICAL, PLONG, PSHORT, PSTRING, PSTRINGV, PZTRINGV. For EXTERNAL procedures passed as arguments use = ROUTINE. For exceptional arguments which require no massaging to fit the argument passing mechanisms use = PVOID. The argument is cast and passed as (void *). Although PVOID could be used to describe all array arguments on most (all?) machines , it shouldn't be because the C compiler can no longer check the type and dimension of the array. argname_i = any valid unique C tag, but must be consistent in the definition as shown. Notes: 1. cfortran.h may be expanded to handle a more argument type. To suppport new arguments requiring complicated massaging when passed between Fortran and C, the user will have to understand cfortran.h and follow its code and mechanisms. To define types requiring little or no massaging when passed between Fortran and C, the pseudo argument type SIMPLE may be used. For a user defined type called 'newtype', the definitions required are: /* The following 7 lines are required verbatim. 'newtype' is the name of the new user defined argument type. */ #define newtype_cfV( T,A,B,F) SIMPLE_cfV(T,A,B,F) #define newtype_cfSEP(T, B) SIMPLE_cfSEP(T,B) #define newtype_cfINT(N,A,B,X,Y,Z) SIMPLE_cfINT(N,A,B,X,Y,Z) #define newtype_cfSTR(N,T,A,B,C,D,E) SIMPLE_cfSTR(N,T,A,B,C,D,E) #define newtype_cfCC( T,A,B) SIMPLE_cfCC(T,A,B) #define newtype_cfAA( T,A,B) newtype_cfB(T,A) /* Argument B not used. */ #define newtype_cfU( T,A) newtype_cfN(T,A) /* 'parameter_type(A)' is a declaration for 'A' and describes the type of the parameter expected by the Fortran function. This type will be used in the prototype for the function, if using ANSI C, and to declare the argument used by the intermediate function if calling a Fortran FUNCTION. Valid 'parameter_type(A)' include: int A void (*A)() double A[17] */ #define newtype_cfN( T,A) parameter_type(A) /* Argument T not used. */ /* Before any argument of the new type is passed to the Fortran routine, it may be massaged as given by 'massage(A)'. */ #define newtype_cfB( T,A) massage(A) /* Argument T not used. */ An example of a simple user defined type is given cfortex.f and cfortest.c. Two uses of SIMPLE user defined types are [don't show the 7 verbatim #defines]: /* Pass the address of a structure, using a type called PSTRUCT */ #define PSTRUCT_cfN( T,A) void *A #define PSTRUCT_cfB( T,A) (void *) &(A) /* Pass an integer by value, (not standard F77 ), using a type called INTVAL */ #define INTVAL_cfN( T,A) int A #define INTVAL_cfB( T,A) (A) [If using VAX VMS, surrounding the #defines with "#pragma (no)standard" allows the %CC-I-PARAMNOTUSED messages to be avoided.] Upgrades to cfortran.h try to be, and have been, backwards compatible. This compatibility cannot be offered to user defined types. SIMPLE user defined types are less of a risk since they require so little effort in their creation. If a user defined type is required in more than one C header file of interfaces to libraries of Fortran routines, good programming practice, and ease of code maintenance, suggests keeping any user defined type within a single file which is #included as required. To date, changes to the SIMPLE macros were introduced in versions 2.6, 3.0 and 3.2 of cfortran.h. 2. Routine_name is the name of the macro which the C programmer will use in order to call a FORTRAN routine. In theory Routine_name could be any valid and unique name, but in practice, the name of the FORTRAN routine in UPPER CASE works everywhere and would seem to be an obvious choice. 3. cfortran.h encourages the exact specification of the type and dimension of array parameters because it allows the C compiler to detect errors in the arguments when calling the routine. cfortran.h does not strictly require the exact specification since the argument is merely the address of the array and is passed on to the calling routine. Any array parameter could be declared as PVOID, but this circumvents C's compiletime ability to check the correctness of arguments and is therefore discouraged. Passing the address of these arguments implies that PBYTEV, PFLOATV, ... , PDOUBLEVV, ... don't exist in cfortran.h, since by default the routine and the calling code share the same array, i.e. the same values at the same memory location. These comments do NOT apply to arrays of (P)S/ZTRINGV. For these parameters, cfortran.h passes a massaged copy of the array to the routine. When the routine returns, S/ZTRINGV ignores the copy, while PS/ZTRINGV replaces the calling code's original array with copy, which may have been modified by the called routine. 4. (P)STRING(V): - STRING - If the argument is a fixed length character array, e.g. char ar[8];, the string is blank, ' ', padded on the right to fill out the array before being passed to the FORTRAN routine. The useful size of the string is the same in both languages, e.g. ar[8] is passed as character*7. If the argument is a pointer, the string cannot be blank padded, so the length is passed as strlen(argument). On return from the FORTRAN routine, pointer arguments are not disturbed, but arrays have the terminating '\0' replaced to its original position. i.e. The padding blanks are never visible to the C code. - PSTRING - The argument is massaged as with STRING before being passed to the FORTRAN routine. On return, the argument has all trailing blanks removed, regardless of whether the argument was a pointer or an array. - (P)STRINGV - Passes a 1- or 2-dimensional char array. e.g. char a[7],b[6][8]; STRINGV may thus also pass a string constant, e.g. "hiho". (P)STRINGV does NOT pass a pointer, e.g. char *, to either a 1- or a 2-dimensional array, since it cannot determine the array dimensions. A pointer can only be passed using (P)ZTRINGV. N.B. If a C routine receives a character array argument, e.g. char a[2][3], such an argument is actually a pointer and my thus not be passed by (P)STRINGV. Instead (P)ZTRINGV must be used. - STRINGV - The elements of the argument are copied into space malloc'd, and each element is padded with blanks. The useful size of each element is the same in both languages. Therefore char bb[6][8]; is equivalent to character*7 bb(6). On return from the routine the malloc'd space is simply released. - PSTRINGV - Since FORTRAN has no trailing '\0', elements in an array of strings are contiguous. Therefore each element of the C array is padded with blanks and strip out C's trailing '\0'. After returning from the routine, the trailing '\0' is reinserted and kill the trailing blanks in each element. - SUMMARY: STRING(V) arguments are blank padded during the call to the FORTRAN routine, but remain original in the C code. (P)STRINGV arguments are blank padded for the FORTRAN call, and after returning from FORTRAN trailing blanks are stripped off. 5. (P)ZTRINGV: - (P)ZTRINGV - is identical to (P)STRINGV, except that the dimensions of the array of strings is explicitly specified, which thus also allows a pointer to be passed. (P)ZTRINGV can thus pass a 1- or 2-dimensional char array, e.g. char b[6][8], or it can pass a pointer to such an array, e.g. char *p;. ZTRINGV may thus also pass a string constant, e.g. "hiho". If passing a 1-dimensional array, routine_name_ELEMS_j (see below) must be 1. [Users of (P)ZTRINGV should examine cfortest.c for examples.]: - (P)ZTRINGV must thus be used instead of (P)STRINGV whenever sizeof() can't be used to determine the dimensions of the array of string or strings. e.g. when calling FORTRAN from C with a char * received by C as an argument. - There is no (P)ZTRING type, since (P)ZTRINGV can pass a 1-dimensional array or a pointer to such an array, e.g. char a[7], *b; If passing a 1-dimensional array, routine_name_ELEMS_j (see below) must be 1. - To specify the numbers of elements, routine_name_ELEMS_j and routine_name_ELEMLEN_j must be defined as shown below before interfacing the routine with CCALLSFSUBn, PROTOCCALLSFFUNn, etc. #define routine_name_ELEMS_j ZTRINGV_ARGS(k) [..ARGS for subroutines, ..ARGF for functions.] or #define routine_name_ELEMS_j ZTRINGV_NUM(l) Where: routine_name is as above. j [1-n], is the argument being specifying. k [1-n], the value of the k'th argument is the dynamic number of elements for argument j. The k'th argument must be of type BYTE, DOUBLE, FLOAT, INT, LONG or SHORT. l the number of elements for argument j. This must be an integer constant available at compile time. i.e. it is static. - Similarly to specify the useful length, [i.e. don't count C's trailing '\0',] of each element: #define routine_name_ELEMLEN_j ZTRINGV_ARGS(m) [..ARGS for subroutines, ..ARGF for functions.] or #define routine_name_ELEMLEN_j ZTRINGV_NUM(q) Where: m [1-n], as for k but this is the length of each element. q as for l but this is the length of each element. 6. ROUTINE The argument is an EXTERNAL procedure. When C passes a routine to Fortran, the language of the function must be specified as follows: [The case of some_*_function must be given as shown.] When C passes a C routine to a Fortran: FORTRAN_ROUTINE(arg1, .... , C_FUNCTION(SOME_C_FUNCTION,some_c_function), ...., argn); and similarly when C passes a Fortran routine to Fortran: FORTRAN_ROUTINE(arg1, .... , FORTRAN_FUNCTION(SOME_FORT_FUNCTION,some_fort_function), ...., argn); If fcallsc has been redefined; the same definition of fcallsc used when creating the wrapper for 'some_c_function' must also be defined when C_FUNCTION is used. See ii) 4. of this section for when and how to redefine fcallsc. ROUTINE was introduced with cfortran.h version 2.6. Earlier versions of cfortran.h used PVOID to pass external procedures as arguments. Using PVOID for this purpose is no longer recommended since it won't work 'as is' for apolloFortran, hpuxFortran800, AbsoftUNIXFortran, AbsoftProFortran. 7. CRAY only: In a given piece of source code, where FFUNC is any FORTRAN routine, FORTRAN_FUNCTION(FFUNC,ffunc) disallows a previous #define FFUNC(..) CCALLSFSUBn(FFUNC,ffunc,...) [ or CCALLSFFUNn] in order to make the UPPER CASE FFUNC callable from C. #define Ffunc(..) ... is OK though, as are obviously any other names. ii) Calling C routines from FORTRAN: -------------------------------- Each of the following two statements to export a C routine to FORTRAN create FORTRAN 'wrappers', written in C, which must be compiled and linked along with the original C routines and with the FORTRAN calling code. FORTRAN callable 'wrappers' may also be created for C macros. i.e. in this section, the term 'C function' may be replaced by 'C macro'. for C functions returning void: FCALLSCSUBn( Routine_name,ROUTINE_NAME,routine_name,argtype_1,...,argtype_n) for all other C functions: FCALLSCFUNn(routine_type,Routine_name,ROUTINE_NAME,routine_name,argtype_1,...,argtype_n) Where: 'n' = 0->27 (easily expanded to > 27) stands for the number of arguments to the routine. Routine_name = the C name of the routine. [see 9. below] ROUTINE_NAME = the FORTRAN name of the routine (IN UPPER CASE LETTERS). routine_name = the FORTRAN name of the routine (IN lower case LETTERS). routine_type = the type of argument returned by C functions. = BYTE, DOUBLE, FLOAT, INT, LOGICAL, LONG, SHORT, STRING, VOID. [Instead of VOID, FCALLSCSUBn is recommended.] argtype_i = the type of argument passed to the FORTRAN routine and must be consistent in the definition and prototyping of the routine = BYTE, DOUBLE, FLOAT, INT, LOGICAL, LONG, SHORT, STRING. For vectors, i.e. 1 dim. arrays use = BYTEV, DOUBLEV, FLOATV, INTV, LOGICALV, LONGV, SHORTV, STRINGV. For vectors of vectors, 2 dim. arrays use = BYTEVV, DOUBLEVV, FLOATVV, INTVV, LOGICALVV, LONGVV, SHORTVV. For n-dim. arrays use = BYTEV..nV's..V, DOUBLEV..V, FLOATV..V, INTV..V, LOGICALV..V, LONGV..V, SHORTV..V. For routines changing the values of an argument, the keyword is prepended by a 'P'. = PBYTE, PDOUBLE, PFLOAT, PINT, PLOGICAL, PLONG, PSHORT, PSTRING, PNSTRING, PPSTRING, PSTRINGV. For EXTERNAL procedures passed as arguments use = ROUTINE. For exceptional arguments which require no massaging to fit the argument passing mechanisms use = PVOID. The argument is cast and passed as (void *). Notes: 0. For Fortran calling C++ routines, C++ does NOT easily allow support for: STRINGV. BYTEVV, DOUBLEVV, FLOATVV, INTVV, LOGICALVV, LONGVV, SHORTVV. BYTEV..V, DOUBLEV..V, FLOATV..V, INTV..V, LOGICALV..V, LONGV..V, SHORTV..V. Though there are ways to get around this restriction, the restriction is not serious since these types are unlikely to be used as arguments for a C++ routine. 1. FCALLSCSUB/FUNn expect that the routine to be 'wrapped' has been properly prototyped, or at least declared. 2. cfortran.h may be expanded to handle a new argument type not already among the above. 3. cfortran.h encourages the exact specification of the type and dimension of array parameters because it allows the C compiler to detect errors in the arguments when declaring the routine using FCALLSCSUB/FUNn, assuming the routine to be 'wrapped' has been properly prototyped. cfortran.h does not strictly require the exact specification since the argument is merely the address of the array and is passed on to the calling routine. Any array parameter could be declared as PVOID, but this circumvents C's compiletime ability to check the correctness of arguments and is therefore discouraged. Passing the address of these arguments implies that PBYTEV, PFLOATV, ... , PDOUBLEVV, ... don't exist in cfortran.h, since by default the routine and the calling code share the same array, i.e. the same values at the same memory location. These comments do NOT apply to arrays of (P)STRINGV. For these parameters, cfortran.h passes a massaged copy of the array to the routine. When the routine returns, STRINGV ignores the copy, while PSTRINGV replaces the calling code's original array with copy, which may have been modified by the called routine. 4. (P(N))STRING arguments have any trailing blanks removed before being passed to C, the same holds true for each element in (P)STRINGV. Space is malloc'd in all cases big enough to hold the original string (elements) as well as C's terminating '\0'. i.e. The useful size of the string (elements) is the same in both languages. P(N)STRING(V) => the string (elements) will be copied from the malloc'd space back into the FORTRAN bytes. If one of the two escape mechanisms mentioned below for PNSTRING has been used, the copying back to FORTRAN is obviously not relevant. 5. (PN)STRING's, [NOT PSTRING's nor (P)STRINGV's,] behavior may be overridden in two cases. In both cases PNSTRING and STRING behave identically. a) If a (PN)STRING argument's first 4 bytes are all the NUL character, i.e. '\0\0\0\0' the NULL pointer is passed to the C routine. b) If the characters of a (PN)STRING argument contain at least one HEX-00, i.e. the NUL character, i.e. C strings' terminating '\0', the address of the string is simply passed to the C routine. i.e. The argument is treated in this case as it would be with PPSTRING, to which we refer the reader for more detail. Mechanism a) overrides b). Therefore, to use this mechanism to pass the NULL string, "", to C, the first character of the string must obviously be the NUL character, but of the first 4 characters in the string, at least one must not be HEX-00. Example: C FORTRAN /* C */ character*40 str #include "cfortran.h" C Set up a NULL as : void cs(char *s) {if (s) printf("%s.\n",s);} C i) 4 NUL characters. FCALLSCSUB1(cs,CS,cs,STRING) C ii) NULL pointer. character*4 NULL NULL = CHAR(0)//CHAR(0)//CHAR(0)//CHAR(0) data str/'just some string'/ C Passing the NULL pointer to cs. call cs(NULL) C Passing a copy of 'str' to cs. call cs(str) C Passing address of 'str' to cs. Trailing blanks NOT killed. str(40:) = NULL call cs(str) end Strings passed from Fortran to C via (PN)STRING must not have undefined contents, otherwise undefined behavior will result, since one of the above two escape mechanisms may occur depending on the contents of the string. This is not be a problem for STRING arguments, which are read-only in the C routine and hence must have a well defined value when being passed in. PNSTRING arguments require special care. Even if they are write-only in the C routine, PNSTRING's above two escape mechanisms require that the value of the argument be well defined when being passed in from Fortran to C. Therefore, unless one or both of PNSTRING's escape mechanisms are required, PSTRING should be used instead of PNSTRING. Prior to version 2.8, PSTRING did have the above two escape mechanisms, but they were removed from PSTRING to allow strings with undefined contents to be passed in. PNSTRING behaves like the old PSTRING. [Thanks go to Paul Dubois (dubios@icf.llnl.gov) for pointing out that PSTRING must allow for strings with undefined contents to be passed in.] Example: C FORTRAN /* C */ character*10 s,sn #include "cfortran.h" void ps(char *s) {strcpy(s,"hello");} C Can call ps with undef. s. FCALLSCSUB1(ps,PS,ps,PSTRING) call ps(s) FCALLSCSUB1(ps,PNS,pns,PNSTRING) print *,s,'=s' C Can't call pns with undef. s. C e.g. If first 4 bytes of s were C "\0\0\0\0", ps would try C to copy to NULL because C of PNSTRING mechanism. sn = "" call pns(sn) print *,sn,'=sn' end 6. PPSTRING The address of the string argument is simply passed to the C routine. Therefore the C routine and the FORTRAN calling code share the same string at the same memory location. If the C routine modifies the string, the string will also be modified for the FORTRAN calling code. The user is responsible for negociating the differences in representation of a string in Fortran and in C, i.e. the differences are not automatically resolved as they are for (P(N)STRING(V). This mechanism is provided for two reasons: - Some C routines require the string to exist at the given memory location, after the C routine has exited. Recall that for the usual (P(N)STRING(V) mechanism, a copy of the FORTRAN string is given to the C routine, and this copy ceases to exist after returning to the FORTRAN calling code. - This mechanism can save runtime CPU cycles over (P(N)STRING(V), since it does not perform their malloc, copy and kill trailing blanks of the string to be passed. Only in a small minority of cases does the potential benefit of the saved CPU cycles outweigh the programming effort required to manually resolve the differences in representation of a string in Fortran and in C. For arguments passed via PPSTRING, the argument passed may also be an array of strings. 7. ROUTINE ANSI C requires that the type of the value returned by the routine be known, For all ROUTINE arguments passed from Fortran to C, the type of ROUTINE is specified by defining a cast as follows: #undef ROUTINE_j #define ROUTINE_j (cast) where: j [1-n], is the argument being specifying. (cast) is a cast matching that of the argument expected by the C function protoytpe for which a wrapper is being defined. e.g. To create a Fortran wrapper for qsort(3C): #undef ROUTINE_4 #define ROUTINE_4 (int (*)(void *,void *)) FCALLSCSUB4(qsort,FQSORT,fqsort,PVOID,INT,INT,ROUTINE) In order to maintain backward compatibility, cfortran.h defines a generic cast for ROUTINE_1, ROUTINE_2, ..., ROUTINE_27. The user's definition is therefore strictly required only for DEC C, which at the moment is the only compiler which insists on the correct cast for pointers to functions. When using the ROUTINE argument inside some Fortran code: - it is difficult to pass a C routine as the parameter, since in many Fortran implementations, Fortran has no access to the normal C namespace. e.g. For most UNIX, Fortran implicitly only has access to C routines ending in _. If the calling Fortran code receives the routine as a parameter it can of course easily pass it along. - if a Fortran routine is passed directly as the parameter, the called C routine must call the parameter routine using the Fortran argument passing conventions. - if a Fortran routine is to be passed as the parameter, but if Fortran can be made to pass a C routine as the parameter, then it may be best to pass a C-callable wrapper for the Fortran routine. The called C routine is thus spared all Fortran argument passing conventions. cfortran.h can be used to create such a C-callable wrapper to the parameter Fortran routine. ONLY PowerStationFortran: This Fortran provides no easy way to pass a Fortran routine as an argument to a C routine. The problem arises because in Fortran the stack is cleared by the called routine, while in C/C++ it is cleared by the caller. The C/C++ stack clearing behavior can be changed to that of Fortran by using stdcall__ in the function prototype. The stdcall__ cannot be applied in this case since the called C routine expects the ROUTINE parameter to be a C routine and does not know that it should apply stdcall__. In principle the cfortran.h generated Fortran callable wrapper for the called C routine should be able to massage the ROUTINE argument such that stdcall__ is performed, but it is not yet known how this could be easily done. 8. THE FOLLOWING INSTRUCTIONS ARE NOT REQUIRED FOR VAX VMS ------------ (P)STRINGV information [NOT required for VAX VMS]: cfortran.h cannot convert the FORTRAN vector of STRINGS to the required C vector of STRINGS without explicitly knowing the number of elements in the vector. The application must do one of the following for each (P)STRINGV argument in a routine before that routine's FCALLSCFUNn/SUBn is called: #define routine_name_STRV_Ai NUM_ELEMS(j) or #define routine_name_STRV_Ai NUM_ELEM_ARG(k) or #define routine_name_STRV_Ai TERM_CHARS(l,m) where: routine_name is as above. i [i=1->n.] specifies the argument number of a STRING VECTOR. j would specify a fixed number of elements. k [k=1->n. k!=i] would specify an integer argument which specifies the number of elements. l [char] the terminating character at the beginning of an element, indicating to cfortran.h that the preceding elements in the vector are the valid ones. m [m=1-...] the number of terminating characters required to appear at the beginning of the terminating string element. The terminating element is NOT passed on to the C routine. e.g. #define ce_STRV_A1 TERM_CHARS(' ',2) FCALLSCSUB1(ce,CE,ce,STRINGV) cfortran.h will pass on all elements, in the 1st and only argument to the C routine ce, of the STRING VECTOR until, but not including, the first string element beginning with 2 blank, ' ', characters. 9. INSTRUCTIONS REQUIRED ONLY FOR FORTRAN COMPILERS WHICH GENERATE ------------- ROUTINE NAMES WHICH ARE UNDISTINGUISHABLE FROM C ROUTINE NAMES i.e. VAX VMS AbsoftUNIXFortran (AbsoftProFortran ok, since it uses Uppercase names.) HP9000 if not using the +ppu option of f77 IBM RS/6000 if not using the -qextname option of xlf Call them the same_namespace compilers. FCALLSCSUBn(...) and FCALLSCFUNn(...), when compiled, are expanded into 'wrapper' functions, so called because they wrap around the original C functions and interface the format of the original C functions' arguments and return values with the format of the FORTRAN call. Ideally one wants to be able to call the C routine from FORTRAN using the same name as the original C name. This is not a problem for FORTRAN compilers which append an underscore, '_', to the names of routines, since the original C routine has the name 'name', and the FORTRAN wrapper is called 'name_'. Similarly, if the FORTRAN compiler generates upper case names for routines, the original C routine 'name' can have a wrapper called 'NAME', [Assuming the C routine name is not in upper case.] For these compilers, e.g. Mips, CRAY, IBM RS/6000 'xlf -qextname', HP-UX 'f77 +ppu', the naming of the wrappers is done automatically. For same_namespace compilers things are not as simple, but cfortran.h tries to provide tools and guidelines to minimize the costs involved in meeting their constraints. The following two options can provide same_namespace compilers with distinct names for the wrapper and the original C function. These compilers are flagged by cfortran.h with the CF_SAME_NAMESPACE constant, so that the change in the C name occurs only when required. For the remainder of the discussion, routine names generated by FORTRAN compilers are referred to in lower case, these names should be read as upper case for the appropriate compilers. HP9000: (When f77 +ppu is not used.) f77 has a -U option which forces uppercase external names to be generated. Unfortunately, cc does not handle recursive macros. Hence, if one wished to use -U for separate C and FORTRAN namespaces, one would have to adopt a different convention of naming the macros which allow C to call FORTRAN subroutines. (Functions are not a problem.) The macros are currently the uppercase of the original FORTRAN name, and would have to be changed to lower case or mixed case, or to a different name. (Lower case would of course cause conflicts on many other machines.) Therefore, it is suggested that f77 -U not be used, and instead that Option a) or Option b) outlined below be used. VAX/VMS: For the name used by FORTRAN in calling a C routine to be the same as that of the C routine, the source code of the C routine is required. A preprocessor directive can then force the C compiler to generate a different name for the C routine. e.g. #if defined(vms) #define name name_ #endif void name() {printf("name: was called.\n");} FCALLSCSUB0(name,NAME,name) In the above, the C compiler generates the original routine with the name 'name_' and a wrapper called 'NAME'. This assumes that the name of the routine, as seen by the C programmer, is not in upper case. The VAX VMS linker is not case sensitive, allowing cfortran.h to export the upper case name as the wrapper, which then doesn't conflict with the routine name in C. Since the IBM, HP and AbsoftUNIXFortran platforms have case sensitive linkers this technique is not available to them. The above technique is required even if the C name is in mixed case, see Option a) for the other compilers, but is obviously not required when Option b) is used. Option a) Mixed Case names for the C routines to be called by FORTRAN. If the original C routines have mixed case names, there are no name space conflicts. Nevertheless for VAX/VMS, the technique outlined above must also used. Option b) Modifying the names of C routines when used by FORTRAN: The more robust naming mechanism, which guarantees portability to all machines, 'renames' C routines when called by FORTRAN. Indeed, one must change the names on same_namespace compilers when FORTRAN calls C routines for which the source is unavailable. [Even when the source is available, renaming may be preferable to Option a) for large libraries of C routines.] Obviously, if done for a single type of machine, it must be done for all machines since the names of routines used in FORTRAN code cannot be easily redefined for different machines. The simplest way to achieve this end is to do explicitly give the modified FORTRAN name in the FCALLSCSUBn(...) and FCALLSCFUNn(...) declarations. e.g. FCALLSCSUB0(name,CFNAME,cfname) This allows FORTRAN to call the C routine 'name' as 'cfname'. Any name can of course be used for a given routine when it is called from FORTRAN, although this is discouraged due to the confusion it is sure to cause. e.g. Bizarre, but valid and allowing C's 'call_back' routine to be called from FORTRAN as 'abcd': FCALLSCSUB0(call_back,ABCD,abcd) cfortran.h also provides preprocessor directives for a systematic 'renaming' of the C routines when they are called from FORTRAN. This is done by redefining the fcallsc macro before the FCALLSCSUB/FUN/n declarations as follows: #undef fcallsc #define fcallsc(UN,LN) preface_fcallsc(CF,cf,UN,LN) FCALLSCSUB0(hello,HELLO,hello) Will cause C's routine 'hello' to be known in FORTRAN as 'cfhello'. Similarly all subsequent FCALLSCSUB/FUN/n declarations will generate wrappers to allow FORTRAN to call C with the C routine's name prefaced by 'cf'. The following has the same effect, with subsequent FCALLSCSUB/FUN/n's appending the modifier to the original C routines name. #undef fcallsc #define fcallsc(UN,LN) append_fcallsc(Y,y,UN,LN) FCALLSCSUB0(Xroutine,ROUTINE,routine) Hence, C's Xroutine is called from FORTRAN as: CALL XROUTINEY() The original behavior of FCALLSCSUB/FUN/n, where FORTRAN routine names are left identical to those of C, is returned using: #undef fcallsc #define fcallsc(UN,LN) orig_fcallsc(UN,LN) In C, when passing a C routine, i.e. its wrapper, as an argument to a FORTRAN routine, the FORTRAN name declared is used and the correct fcallsc must be in effect. E.g. Passing 'name' and 'routine' of the above examples to the FORTRAN routines, FT1 and FT2, respectively: /* This might not be needed if fcallsc is already orig_fcallsc. */ #undef fcallsc #define fcallsc(UN,LN) orig_fcallsc(UN,LN) FT1(C_FUNCTION(CFNAME,cfname)); #undef fcallsc #define fcallsc(UN,LN) append_fcallsc(Y,y,UN,LN) FT1(C_FUNCTION(XROUTINE,xroutine)); If the names of C routines are modified when used by FORTRAN, fcallsc would usually be defined once in a header_file.h for the application. This definition would then be used and be valid for the entire application and fcallsc would at no point need to be redefined. ONCE AGAIN: THE DEFINITIONS, INSTRUCTIONS, DECLARATIONS AND DIFFICULTIES DESCRIBED HERE, NOTE 9. of II ii), APPLY ONLY FOR VAX VMS, IBM RS/6000 WITHOUT THE -qextname OPTION FOR xlf, OR HP-UX WITHOUT THE +ppu OPTION FOR f77 AbsoftUNIXFortran AND APPLY ONLY WHEN CREATING WRAPPERS WHICH ENABLE FORTRAN TO CALL C ROUTINES. iii) Using C to manipulate FORTRAN COMMON BLOCKS: ------------------------------------------------------- FORTRAN common blocks are set up with the following three constructs: 1. #define Common_block_name COMMON_BLOCK(COMMON_BLOCK_NAME,common_block_name) Common_block_name is in UPPER CASE. COMMON_BLOCK_NAME is in UPPER CASE. common_block_name is in lower case. [Common_block_name actually follows the same 'rules' as Routine_name in Note 2. of II i).] This construct exists to ensure that C code accessing the common block is machine independent. 2. COMMON_BLOCK_DEF(TYPEDEF_OF_STRUCT, Common_block_name); where typedef { ... } TYPEDEF_OF_STRUCT; declares the structure which maps on to the common block. The #define of Common_block_name must come before the use of COMMON_BLOCK_DEF. 3. In exactly one of the C source files, storage should be set aside for the common block with the definition: TYPEDEF_OF_STRUCT Common_block_name; The above definition may have to be omitted on some machines for a common block which is initialized by Fortran BLOCK DATA or is declared with a smaller size in the C routines than in the Fortran routines. The rules for common blocks are not well defined when linking/loading a mixture of C and Fortran, but the following information may help resolve problems. From the 2nd or ANSI ed. of K&R C, p.31, last paragraph: i) An external variable must be defined, exactly once, outside of any function; this sets aside storage for it. ii) The variable must also be declared in each function that wants to access it; ... The declaration ... may be implicit from context. In Fortran, every routine says 'common /bar/ foo', i.e. part ii) of the above, but there's no part i) requirement. cc/ld on some machines don't require i) either. Therefore, when handling Fortran, and sometimes C, the loader/linker must automagically set aside storage for common blocks. Some loaders, including at least one for the CRAY, turn off the 'automagically set aside storage' capability for Fortran common blocks, if any C object declares that common block. Therefore, C code should define, i.e. set aside storage, for the the common block as shown above. e.g. C Fortran common /fcb/ v,w,x character *(13) v, w(4), x(3,2) /* C */ typedef struct { char v[13],w[4][13],x[2][3][13]; } FCB_DEF; #define Fcb COMMON_BLOCK(FCB,fcb) COMMON_BLOCK_DEF(FCB_DEF,Fcb); FCB_DEF Fcb; /* Definition, which sets aside storage for Fcb, */ /* may appear in at most one C source file. */ C programs can place a string (or a multidimensional array of strings) into a FORTRAN common block using the following call: C2FCBSTR( CSTR, FSTR,DIMENSIONS); where: CSTR is a pointer to the first element of C's copy of the string (array). The C code must use a duplicate of, not the original, common block string, because the FORTRAN common block does not allocate space for C strings' terminating '\0'. FSTR is a pointer to the first element of the string (array) in the common block. DIMENSIONS is the number of dimensions of string array. e.g. char a[10] has DIMENSIONS=0. char aa[10][17] has DIMENSIONS=1. etc... C2FCBSTR will copy the string (array) from CSTR to FSTR, padding with blanks, ' ', the trailing characters as required. C2FCBSTR uses DIMENSIONS and FSTR to determine the lengths of the individual string elements and the total number of elements in the string array. Note that: - the number of string elements in CSTR and FSTR are identical. - for arrays of strings, the useful lengths of strings in CSTR and FSTR must be the same. i.e. CSTR elements each have 1 extra character to accommodate the terminating '\0'. - On most non-ANSI compilers, the DIMENSION argument cannot be prepended by any blanks. FCB2CSTR( FSTR, CSTR,DIMENSIONS) is the inverse of C2FCBSTR, and shares the same arguments and caveats. FCB2CSTR copies each string element of FSTR to CSTR, minus FORTRAN strings' trailing blanks. cfortran.h USERS ARE STRONGLY URGED TO EXAMINE THE COMMON BLOCK EXAMPLES IN cfortest.c AND cfortex.f. The use of strings in common blocks is demonstrated, along with a suggested way for C to imitate FORTRAN EQUIVALENCE'd variables. ===> USERS OF CFORTRAN.H NEED READ NO FURTHER <=== III Some Musings ---------------- cfortran.h is simple enough to be used by the most basic of applications, i.e. making a single C/FORTRAN routine available to the FORTRAN/C programmers. Yet cfortran.h is powerful enough to easily make entire C/FORTRAN libraries available to FORTRAN/C programmers. cfortran.h is the ideal tool for FORTRAN libraries which are being (re)written in C, but are to (continue to) support FORTRAN users. It allows the routines to be written in 'natural C', without having to consider the FORTRAN argument passing mechanisms of any machine. It also allows C code accessing these rewritten routines, to use the C entry point. Without cfortran.h, one risks the perverse practice of C code calling a C function using FORTRAN argument passing mechanisms! Perhaps the philosophy and mechanisms of cfortran.h could be used and extended to create other language bridges such as ADAFORTRAN, CPASCAL, COCCAM, etc. The code generation machinery inside cfortran.h, i.e. the global structure is quite good, being clean and workable as seen by its ability to meet the needs and constraints of many different compilers. Though the individual instructions of the A..., C..., T..., R... and K... tables deserve to be cleaned up. IV Getting Serious with cfortran.h ----------------------------------- cfortran.h is set up to be as simple as possible for the casual user. While this ease of use will always be present, 'hooks', i.e. preprocessor directives, are required in cfortran.h so that some of the following 'inefficiencies' can be eliminated if they cause difficulties: o cfortran.h contains a few small routines for string manipulation. These routines are declared static and are included and compiled in all source code which uses cfortran.h. Hooks should be provided in cfortran.h to create an object file of these routines, allowing cfortran.h to merely prototypes these routines in the application source code. This is the only 'problem' which afflicts both halves of cfortran.h. The remaining discussion refers to the C calls FORTRAN half only. o Similar to the above routines, cfortran.h generates code for a 'wrapper' routine for each FUNCTION exported from FORTRAN. Again cfortran.h needs preprocessor directives to create a single object file of these routines, and to merely prototype them in the applications. o Libraries often contain hundreds of routines. While the preprocessor makes quick work of generating the required interface code from cfortran.h and the application.h's, it may be convenient for very large stable libraries to have final_application.h's which already contain the interface code, i.e. these final_application.h's would not require cfortran.h. [The convenience can be imagined for the VAX VMS CC compiler which has a fixed amount of memory for preprocessor directives. Not requiring cfortran.h, with its hundreds of directives, could help prevent this compiler from choking on its internal limits quite so often.] With a similar goal in mind, cfortran.h defines 100's of preprocessor directives. There is always the potential that these will clash with other tags in the users code, so final_applications.h, which don't require cfortran.h, also provide the solution. In the same vein, routines with more than 14 arguments can not be interfaced by cfortran.h with compilers which limit C macros to 31 arguments. To resolve this difficulty, final_application.h's can be created on a compiler without this limitation. Therefore, new machinery is required to do: application.h + cfortran.h => final_application.h The following example may help clarify the means and ends: If the following definition of the HBOOK1 routine, the /*commented_out_part*/, is passed through the preprocessor [perhaps #undefing and #defining preprocessor constants if creating an application.h for compiler other than that of the preprocessor being used, e.g. cpp -Umips -DCRAY ... ] : #include "cfortran.h" PROTOCCALLSFSUB6(HBOOK1,hbook1,INT,STRING,INT,FLOAT,FLOAT,FLOAT) /*#define HBOOK1(ID,CHTITLE,NX,XMI,XMA,VMX) \*/ CCALLSFSUB6(HBOOK1,hbook1,INT,STRING,INT,FLOAT,FLOAT,FLOAT, \ ID,CHTITLE,NX,XMI,XMA,VMX) A function prototype is produced by the PROTOCCALLSFSUB6(...). Interface code is produced, based on the 'variables', ID,CHTITLE,NX,XMI,XMA,VMX, which will correctly massage a HBOOK1 call. Therefore, adding the #define line: 'prototype code' #define HBOOK1(ID,CHTITLE,NX,XMI,XMA,VMX) \ 'interface code'(ID,CHTITLE,NX,XMI,XMA,VMX) which is placed into final_application.h. The only known limitation of the above method does not allow the 'variable' names to include B1,B2,...,B9,BA,BB,... Obviously the machinery to automatically generate final_applications.h from cfortran.h and applications.h needs more than just some preprocessor directives, but a fairly simple unix shell script should be sufficient. Any takers? V Machine Dependencies of cfortran.h ------------------------------------ Porting cfortran.h applications, e.g. the hbook.h and cstring.c mentioned above, to other machines is trivial since they are machine independent. Porting cfortran.h requires a solid knowledge of the new machines C preprocessor, and its FORTRAN argument passing mechanisms. Logically cfortran.h exists as two halves, a "C CALLS FORTRAN" and a "FORTRAN CALLS C" utility. In some cases it may be perfectly reasonable to port only 'one half' of cfortran.h onto a new system. The lucky programmer porting cfortran.h to a new machine, must discover the FORTRAN argument passing mechanisms. A safe starting point is to assume that variables and arrays are simply passed by reference, but nothing is guaranteed. Strings, and n-dimensional arrays of strings are a different story. It is doubtful that any systems do it quite like VAX VMS does it, so that a UNIX or f2c versions may provide an easier starting point. cfortran.h uses and abuses the preprocessor's ## operator. Although the ## operator does not exist in many compilers, many kludges do. cfortran.h uses /**/ with no space allowed between the slashes, '/', and the macros or tags to be concatenated. e.g. #define concat(a,b) a/**/b /* works*/ main() { concat(pri,ntf)("hello"); /* e.g. */ } N.B. On some compilers without ##, /**/ may also not work. The author may be able to offer alternate kludges. VI Bugs in vendors C compilers and other curiosities ---------------------------------------------------- 1. ULTRIX xxxxxx 4.3 1 RISC Condolences to long suffering ultrix users! DEC supplies a working C front end for alpha/OSF, but not for ultrix. From K&R ANSI C p. 231: ultrix> cat cat.c #define cat(x, y) x ## y #define xcat(x,y) cat(x,y) cat(cat(1,2),3) xcat(xcat(1,2),3) ultrix> cc -E cat.c 123 <---- Should be: cat(1,2)3 123 <---- Correct. ultrix> The problem for cfortran.h, preventing use of -std and -std1: ultrix> cat c.c #define cat(x, y) x ## y #define xcat(x,y) cat(x,y) #define AB(X) X+X #define C(E,F,G) cat(E,F)(G) #define X(E,F,G) xcat(E,F)(G) C(A,B,2) X(A,B,2) ultrix> cc -std1 -E c.c 2+2 AB (2) <---- ????????????? ultrix> ultrix> cc -std0 -E c.c 2+2 AB(2) <---- ????????????? ultrix> Due to further ultrix preprocessor problems, for all definitions of definitions with arguments, cfortran.h >= 3.0 includes the arguments and recommends the same, even though it is not required by ANSI C. e.g. Users are advised to do #define fcallsc(UN,LN) orig_fcallsc(UN,LN) instead of #define fcallsc orig_fcallsc since ultrix fails to properly preprocess the latter example. CRAY used to (still does?) occasionally trip up on this problem. 2. ConvexOS convex C210 11.0 convex In a program with a C main, output to LUN=6=* from Fortran goes into $pwd/fort.6 instead of stdout. Presumably, a magic incantation can be called from the C main in order to properly initialize the Fortran I/O. 3. SunOS 5.3 Generic_101318-69 sun4m sparc The default data and code alignments produced by cc, gcc and f77 are compatible. If deviating from the defaults, consistent alignment options must be used across all objects compiled by cc and f77. [Does gcc provide such options?] 4. SunOS 5.3 Generic_101318-69 sun4m sparc with cc: SC3.0.1 13 Jul 1994 or equivalently ULTRIX 4.4 0 RISC using cc -oldc are K&R C preprocessors that suffer from infinite loop macros, e.g. zedy03> cat src.c #include "cfortran.h" PROTOCCALLSFFUN1(INT,FREV,frev, INTV) #define FREV(A1) CCALLSFFUN1( FREV,frev, INTV, A1) /* To avoid the problem, deletete these ---^^^^--- spaces. */ main() { static int a[] = {1,2}; FREV(a); return EXIT_SUCCESS; } zedy03> cc -c -Xs -v -DMAX_PREPRO_ARGS=31 -D__CF__KnR src.c "src.c", line 4: FREV: actuals too long "src.c", line 4: FREV: actuals too long .... 3427 more lines of the same message "src.c", line 4: FREV: actuals too long cc : Fatal error in /usr/ccs/lib/cpp Segmentation fault (core dumped) 5. Older sun C compilers To link to f77 objects, older sun C compilers require the math.h macros: #define RETURNFLOAT(x) { union {double _d; float _f; } _kluge; \ _kluge._f = (x); return _kluge._d; } #define ASSIGNFLOAT(x,y) { union {double _d; float _f; } _kluge; \ _kluge._d = (y); x = _kluge._f; } Unfortunately, in at least some copies of the sun math.h, the semi-colon for 'float _f;' is left out, leading to compiler warnings. The solution is to correct math.h, or to change cfortran.h to #define RETURNFLOAT(x) and ASSIGNFLOAT(x,y) instead of including math.h. 6. gcc version 2.6.3 and probably all other versions as well Unlike all other C compilers supported by cfortran.h, 'gcc -traditional' promotes to double all functions returning float as demonstrated bu the following example. /* m.c */ #include int main() { FLOAT_FUNCTION d(); float f; f = d(); printf("%f\n",f); return 0; } /* d.c */ float d() { return -123.124; } burow[29] gcc -c -traditional d.c burow[30] gcc -DFLOAT_FUNCTION=float m.c d.o && a.out 0.000000 burow[31] gcc -DFLOAT_FUNCTION=double m.c d.o && a.out -123.124001 burow[32] Thus, 'gcc -traditional' is not supported by cfortran.h. Support would require the same RETURNFLOAT, etc. macro machinery present in old sun math.h, before sun gave up the same promotion. 7. CRAY At least some versions of the t3e and t3d C preprocessor are broken in the fashion described below. At least some versions of the t90 C preprocessor do not have this problem. On the CRAY, all Fortran names are converted to uppercase. Generally the uppercase name is also used for the macro interface created by cfortran.h. For example, in the following interface, EASY is both the name of the macro in the original C code and EASY is the name of the resulting function to be called. #define EASY(A,B) CCALLSFSUB2(EASY,easy, PINT, INTV, A, B) The fact that a macro called EASY() expands to a function called EASY() is not a problem for a working C preprocessor. From Kernighan and Ritchie, 2nd edition, p.230: In both kinds of macro, the replacement token sequence is repeatedly rescanned for more identifiers. However, once a given identifier has been replaced in a given expansion, it is not replaced if it turns up again during rescanning; instead it is left unchanged. Unfortunately, some CRAY preprocessors are broken and don't obey the above rule. A work-around is for the user to NOT use the uppercase name of the name of the macro interface provided by cfortran.h. For example: #define Easy(A,B) CCALLSFSUB2(EASY,easy, PINT, INTV, A, B) Luckily, the above work-around is not required since the following work-around within cfortran.h also circumvents the bug: /* (UN), not UN, is required in order to get around CRAY preprocessor bug.*/ #define CFC_(UN,LN) (UN) /* Uppercase FORTRAN symbols. */ Aside: The Visual C++ compiler is happy with UN, but barfs on (UN), so either (UN) causes nonstandard C/C++ or Visual C++ is broken. VII History and Acknowledgements -------------------------------- 1.0 - Supports VAX VMS using C 3.1 and FORTRAN 5.4. Oct. '90. 1.0 - Supports Silicon Graphics w. Mips Computer 2.0 f77 and cc. Feb. '91. [Port of C calls FORTRAN half only.] 1.1 - Supports Mips Computer System 2.0 f77 and cc. Mar. '91. [Runs on at least: Silicon Graphics IRIX 3.3.1 DECstations with Ultrix V4.1] 1.2 - Internals made simpler, smaller, faster, stronger. May '91. - Mips version works on IBM RS/6000, this is now called the unix version. 1.3 - UNIX and VAX VMS versions are merged into a single cfortran.h. July '91. - C can help manipulate (arrays of) strings in FORTRAN common blocks. - Dimensions of string arrays arguments can be explicit. - Supports Apollo DomainOS 10.2 (sys5.3) with f77 10.7 and cc 6.7. 2.0 - Improved code generation machinery creates K&R or ANSI C. Aug. '91. - Supports Sun, CRAY. f2c with vcc on VAX Ultrix. - cfortran.h macros now require routine and COMMON block names in both upper and lower case. No changes required to applications though. - PROTOCCALLSFSUBn is eliminated, with no loss to cfortran.h performance. - Improved tools and guidelines for naming C routines called by FORTRAN. 2.1 - LOGICAL correctly supported across all machines. Oct. '91. - Improved support for DOUBLE PRECISION on the CRAY. - HP9000 fully supported. - VAX Ultrix cc or gcc with f77 now supported. 2.2 - SHORT, i.e. INTEGER*2, and BYTE now supported. Dec. '91. - LOGICAL_STRICT introduced. More compact and robust internal tables. - typeV and typeVV for type = BYTE, DOUBLE, FLOAT, INT, LOGICAL, LONG,SHORT. - FORTRAN passing strings and NULL pointer to C routines improved. 2.3 - Extraneous arguments removed from many internal tables. May '92. - Introduce pseudo argument type SIMPLE for user defined types. - LynxOS using f2c supported. (Tested with LynxOS 2.0 386/AT.) 2.4 - Separation of internal C and Fortran compilation directives. Oct. '92. - f2c and NAG f90 supported on all machines. 2.5 - Minor mod.s to source and/or doc for HP9000, f2c, and NAG f90. Nov. '92. 2.6 - Support external procedures as arguments with type ROUTINE. Dec. '92. 2.7 - Support Alpha VMS. Support HP9000 f77 +ppu Jan. '93. - Support arrays with up to 7 dimensions. - Minor mod. of Fortran NULL to C via (P)STRING. - Specify the type of ROUTINE passed from Fortran to C [ANSI C requirement.] - Macros never receive a null parameter [RS/6000 requirement.] 2.8 - PSTRING for Fortran calls C no longer provides escape to pass April'93. NULL pointer nor to pass address of original string. PNSTRING introduced with old PSTRING's behavior. PPSTRING introduced to always pass original address of string. - Support Alpha/OSF. - Document that common blocks used in C should be declared AND defined. 3.0 - Automagic handling of ANSI ## versus K&R /**/ preprocessor op. March'95. - Less chance of name space collisions between cfortran.h and other codes. - SIMPLE macros, supporting user defined types, have changed names. 3.1 - Internal macro name _INT not used. Conflicted with IRIX 5.3. May '95. - SunOS, all versions, should work out of the box. - ZTRINGV_ARGS|F(k) may no longer point to a PDOUBLE or PFLOAT argument. - ConvexOS 11.0 supported. 3.2 - __hpux no longer needs to be restricted to MAX_PREPRO_ARGS=31. Oct. '95. - PSTRING bug fixed. - ZTRINGV_ARGS|F(k) may not point to a PBYTE,PINT,PLONG or PSHORT argument. - (P)ZTRINGV machinery improved. Should lead to fewer compiler warnings. (P)ZTRINGV no longer limits recursion or the nesting of routines. - SIMPLE macros, supporting user defined types, have changed slightly. 3.3 - Supports PowerStation Fortran with Visual C++. Nov. '95. - g77 should work using f2cFortran, though no changes made for it. - (PROTO)CCALLSFFUN10 extended to (PROTO)CCALLSFFUN14. - FCALLSCFUN10 and SUB10 extended to FCALLSCFUN14 and SUB14. 3.4 - C++ supported, Dec. '95. but it required the reintroduction of PROTOCCALLSFSUBn for users. - HP-UX f77 +800 supported. 3.5 - Absoft UNIX Fortran supported. Sept.'96. 3.6 - Minor corrections to cfortran.doc. Oct. '96. - Fixed bug for 15th argument. [Thanks to Tom Epperly at Aspen Tech.] - For AbsoftUNIXFortran, obey default of prepending _C to COMMON BLOCK name. - Fortran calling C with ROUTINE argument fixed and cleaned up. 3.7 - Circumvent IBM and HP "null argument" preprocessor warning. Oct. '96 3.8 - (P)STRINGV and (P)ZTRINGV can pass a 1- or 2-dim. char array. Feb. '97 (P)ZTRINGV thus effectively also provides (P)ZTRING. - (P)ZTRINGV accepts a (char *) pointer. 3.9 - Bug fixed for *VVVVV. May '97 - f2c: Work-around for strange underscore-dependent naming feature. - NEC SX-4 supported. - CRAY: LOGICAL conversion uses _btol and _ltob from CRAY's fortran.h. - CRAY: Avoid bug of some versions of the C preprocessor. - CRAY T3E: FORTRAN_REAL introduced. 4.0 - new/delete now used for C++. malloc/free still used for C. Jan. '98 - FALSE no longer is defined by cfortran.h . - Absoft Pro Fortran for MacOS supported. 4.1 - COMMA and COLON no longer are defined by cfortran.h . April'98 - Bug fixed when 10th arg. or beyond is a string. [Rob Lucchesi of NASA-Goddard pointed out this bug.] - CCALLSFSUB/FUN extended from 14 to 27 arguments. - Workaround SunOS CC 4.2 cast bug. [Thanks to Savrak SAR of CERN.] 4.2 - Portland Group needs -DpgiFortran . [Thank George Lai of NASA.] June '98 4.3 - (PROTO)CCALLSFSUB extended from 20 to 27 arguments. July '98 ['Support' implies these and more recent releases of the respective OS/compilers/linkers can be used with cfortran.h. Earlier releases may also work.] Acknowledgements: - CERN very generously sponsored a week in 1994 for me to work on cfortran.h. - M.L.Luvisetto (Istituto Nazionale Fisica Nucleare - Centro Nazionale Analisi Fotogrammi, Bologna, Italy) provided all the support for the port to the CRAY. Marisa's encouragement and enthusiasm was also much appreciated. - J.Bunn (CERN) supported the port to PowerStation Fortran with Visual C++. - Paul Schenk (UC Riverside, CERN PPE/OPAL) in June 1993 extended cfortran.h 2.7 to have C++ call Fortran. This was the starting point for full C++ in 3.4. - Glenn P.Davis of University Corp. for Atmospheric Research (UCAR) / Unidata supported the NEC SX-4 port and helped understand the CRAY. - Tony Goelz of Absoft Corporation ported cfortran.h to Absoft. - Though cfortran.h has been created in my 'copious' free time, I thank NSERC for their generous support of my grad. student and postdoc years. - Univ.Toronto, DESY, CERN and others have provided time on their computers. THIS PACKAGE, I.E. CFORTRAN.H, THIS DOCUMENT, AND THE CFORTRAN.H EXAMPLE PROGRAMS ARE PROPERTY OF THE AUTHOR WHO RESERVES ALL RIGHTS. THIS PACKAGE AND THE CODE IT PRODUCES MAY BE FREELY DISTRIBUTED WITHOUT FEES, SUBJECT TO THE FOLLOWING RESTRICTIONS: - YOU MUST ACCOMPANY ANY COPIES OR DISTRIBUTION WITH THIS (UNALTERED) NOTICE. - YOU MAY NOT RECEIVE MONEY FOR THE DISTRIBUTION OR FOR ITS MEDIA (E.G. TAPE, DISK, COMPUTER, PAPER.) - YOU MAY NOT PREVENT OTHERS FROM COPYING IT FREELY. - YOU MAY NOT DISTRIBUTE MODIFIED VERSIONS WITHOUT CLEARLY DOCUMENTING YOUR CHANGES AND NOTIFYING THE AUTHOR. - YOU MAY NOT MISREPRESENTED THE ORIGIN OF THIS SOFTWARE, EITHER BY EXPLICIT CLAIM OR BY OMISSION. THE INTENT OF THE ABOVE TERMS IS TO ENSURE THAT THE CFORTRAN.H PACKAGE NOT BE USED FOR PROFIT MAKING ACTIVITIES UNLESS SOME ROYALTY ARRANGEMENT IS ENTERED INTO WITH ITS AUTHOR. THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. THE AUTHOR IS NOT RESPONSIBLE FOR ANY SUPPORT OR SERVICE OF THE CFORTRAN.H PACKAGE. Burkhard Burow burow@desy.de P.S. Your comments and questions are welcomed and usually promptly answered. VAX VMS and Ultrix, Alpha, OSF, Silicon Graphics (SGI), DECstation, Mips RISC, Sun, CRAY, Convex, IBM RS/6000, Apollo DomainOS, HP, LynxOS, f2c, NAG, Absoft, NEC SX-4, PowerStation and Visual C++ are registered trademarks of their respective owners. /* end: cfortran.doc */ cfortran-4.4/cfortran.h0100644000175000017500000036726207440724141015426 0ustar kmccartykmccarty/* cfortran.h 4.4 */ /* http://www-zeus.desy.de/~burow/cfortran/ */ /* Burkhard Burow burow@desy.de 1990 - 2002. */ #ifndef __CFORTRAN_LOADED #define __CFORTRAN_LOADED /* THIS FILE IS PROPERTY OF BURKHARD BUROW. IF YOU ARE USING THIS FILE YOU SHOULD ALSO HAVE ACCESS TO CFORTRAN.DOC WHICH PROVIDES TERMS FOR USING, MODIFYING, COPYING AND DISTRIBUTING THE CFORTRAN.H PACKAGE. */ /* Avoid symbols already used by compilers and system *.h: __ - OSF1 zukal06 V3.0 347 alpha, cc -c -std1 cfortest.c */ /* First prepare for the C compiler. */ #ifndef ANSI_C_preprocessor /* i.e. user can override. */ #ifdef __CF__KnR #define ANSI_C_preprocessor 0 #else #ifdef __STDC__ #define ANSI_C_preprocessor 1 #else #define _cfleft 1 #define _cfright #define _cfleft_cfright 0 #define ANSI_C_preprocessor _cfleft/**/_cfright #endif #endif #endif #if ANSI_C_preprocessor #define _0(A,B) A##B #define _(A,B) _0(A,B) /* see cat,xcat of K&R ANSI C p. 231 */ #define _2(A,B) A##B /* K&R ANSI C p.230: .. identifier is not replaced */ #define _3(A,B,C) _(A,_(B,C)) #else /* if it turns up again during rescanning. */ #define _(A,B) A/**/B #define _2(A,B) A/**/B #define _3(A,B,C) A/**/B/**/C #endif #if (defined(vax)&&defined(unix)) || (defined(__vax__)&&defined(__unix__)) #define VAXUltrix #endif #include /* NULL [in all machines stdio.h] */ #include /* strlen, memset, memcpy, memchr. */ #if !( defined(VAXUltrix) || defined(sun) || (defined(apollo)&&!defined(__STDCPP__)) ) #include /* malloc,free */ #else #include /* Had to be removed for DomainOS h105 10.4 sys5.3 425t*/ #ifdef apollo #define __CF__APOLLO67 /* __STDCPP__ is in Apollo 6.8 (i.e. ANSI) and onwards */ #endif #endif #if !defined(__GNUC__) && !defined(__sun) && (defined(sun)||defined(VAXUltrix)||defined(lynx)) #define __CF__KnR /* Sun, LynxOS and VAX Ultrix cc only supports K&R. */ /* Manually define __CF__KnR for HP if desired/required.*/ #endif /* i.e. We will generate Kernighan and Ritchie C. */ /* Note that you may define __CF__KnR before #include cfortran.h, in order to generate K&R C instead of the default ANSI C. The differences are mainly in the function prototypes and declarations. All machines, except the Apollo, work with either style. The Apollo's argument promotion rules require ANSI or use of the obsolete std_$call which we have not implemented here. Hence on the Apollo, only C calling FORTRAN subroutines will work using K&R style.*/ /* Remainder of cfortran.h depends on the Fortran compiler. */ #if defined(CLIPPERFortran) || defined(pgiFortran) #define f2cFortran #endif /* VAX/VMS does not let us \-split long #if lines. */ /* Split #if into 2 because some HP-UX can't handle long #if */ #if !(defined(NAGf90Fortran)||defined(f2cFortran)||defined(hpuxFortran)||defined(apolloFortran)||defined(sunFortran)||defined(IBMR2Fortran)||defined(CRAYFortran)) #if !(defined(mipsFortran)||defined(DECFortran)||defined(vmsFortran)||defined(CONVEXFortran)||defined(PowerStationFortran)||defined(AbsoftUNIXFortran)||defined(AbsoftProFortran)||defined(SXFortran)) /* If no Fortran compiler is given, we choose one for the machines we know. */ #if defined(lynx) || defined(VAXUltrix) #define f2cFortran /* Lynx: Only support f2c at the moment. VAXUltrix: f77 behaves like f2c. Support f2c or f77 with gcc, vcc with f2c. f77 with vcc works, missing link magic for f77 I/O.*/ #endif #if defined(__hpux) /* 921107: Use __hpux instead of __hp9000s300 */ #define hpuxFortran /* Should also allow hp9000s7/800 use.*/ #endif #if defined(apollo) #define apolloFortran /* __CF__APOLLO67 also defines some behavior. */ #endif #if defined(sun) || defined(__sun) #define sunFortran #endif #if defined(_IBMR2) #define IBMR2Fortran #endif #if defined(_CRAY) #define CRAYFortran /* _CRAYT3E also defines some behavior. */ #endif #if defined(_SX) #define SXFortran #endif #if defined(mips) || defined(__mips) #define mipsFortran #endif #if defined(vms) || defined(__vms) #define vmsFortran #endif #if defined(__alpha) && defined(__unix__) #define DECFortran #endif #if defined(__convex__) #define CONVEXFortran #endif #if defined(VISUAL_CPLUSPLUS) #define PowerStationFortran #endif #endif /* ...Fortran */ #endif /* ...Fortran */ /* Split #if into 2 because some HP-UX can't handle long #if */ #if !(defined(NAGf90Fortran)||defined(f2cFortran)||defined(hpuxFortran)||defined(apolloFortran)||defined(sunFortran)||defined(IBMR2Fortran)||defined(CRAYFortran)) #if !(defined(mipsFortran)||defined(DECFortran)||defined(vmsFortran)||defined(CONVEXFortran)||defined(PowerStationFortran)||defined(AbsoftUNIXFortran)||defined(AbsoftProFortran)||defined(SXFortran)) /* If your compiler barfs on ' #error', replace # with the trigraph for # */ #error "cfortran.h: Can't find your environment among:\ - MIPS cc and f77 2.0. (e.g. Silicon Graphics, DECstations, ...) \ - IBM AIX XL C and FORTRAN Compiler/6000 Version 01.01.0000.0000 \ - VAX VMS CC 3.1 and FORTRAN 5.4. \ - Alpha VMS DEC C 1.3 and DEC FORTRAN 6.0. \ - Alpha OSF DEC C and DEC Fortran for OSF/1 AXP Version 1.2 \ - Apollo DomainOS 10.2 (sys5.3) with f77 10.7 and cc 6.7. \ - CRAY \ - NEC SX-4 SUPER-UX \ - CONVEX \ - Sun \ - PowerStation Fortran with Visual C++ \ - HP9000s300/s700/s800 Latest test with: HP-UX A.08.07 A 9000/730 \ - LynxOS: cc or gcc with f2c. \ - VAXUltrix: vcc,cc or gcc with f2c. gcc or cc with f77. \ - f77 with vcc works; but missing link magic for f77 I/O. \ - NO fort. None of gcc, cc or vcc generate required names.\ - f2c : Use #define f2cFortran, or cc -Df2cFortran \ - NAG f90: Use #define NAGf90Fortran, or cc -DNAGf90Fortran \ - Absoft UNIX F77: Use #define AbsoftUNIXFortran or cc -DAbsoftUNIXFortran \ - Absoft Pro Fortran: Use #define AbsoftProFortran \ - Portland Group Fortran: Use #define pgiFortran" /* Compiler must throw us out at this point! */ #endif #endif #if defined(VAXC) && !defined(__VAXC) #define OLD_VAXC #pragma nostandard /* Prevent %CC-I-PARAMNOTUSED. */ #endif /* Throughout cfortran.h we use: UN = Uppercase Name. LN = Lowercase Name. */ #if defined(f2cFortran) || defined(NAGf90Fortran) || defined(DECFortran) || defined(mipsFortran) || defined(apolloFortran) || defined(sunFortran) || defined(CONVEXFortran) || defined(SXFortran) || defined(extname) #define CFC_(UN,LN) _(LN,_) /* Lowercase FORTRAN symbols. */ #define orig_fcallsc(UN,LN) CFC_(UN,LN) #else #if defined(CRAYFortran) || defined(PowerStationFortran) || defined(AbsoftProFortran) #ifdef _CRAY /* (UN), not UN, circumvents CRAY preprocessor bug. */ #define CFC_(UN,LN) (UN) /* Uppercase FORTRAN symbols. */ #else /* At least VISUAL_CPLUSPLUS barfs on (UN), so need UN. */ #define CFC_(UN,LN) UN /* Uppercase FORTRAN symbols. */ #endif #define orig_fcallsc(UN,LN) CFC_(UN,LN) /* CRAY insists on arg.'s here. */ #else /* For following machines one may wish to change the fcallsc default. */ #define CF_SAME_NAMESPACE #ifdef vmsFortran #define CFC_(UN,LN) LN /* Either case FORTRAN symbols. */ /* BUT we usually use UN for C macro to FORTRAN routines, so use LN here,*/ /* because VAX/VMS doesn't do recursive macros. */ #define orig_fcallsc(UN,LN) UN #else /* HP-UX without +ppu or IBMR2 without -qextname. NOT reccomended. */ #define CFC_(UN,LN) LN /* Lowercase FORTRAN symbols. */ #define orig_fcallsc(UN,LN) CFC_(UN,LN) #endif /* vmsFortran */ #endif /* CRAYFortran PowerStationFortran */ #endif /* ....Fortran */ #define fcallsc(UN,LN) orig_fcallsc(UN,LN) #define preface_fcallsc(P,p,UN,LN) CFC_(_(P,UN),_(p,LN)) #define append_fcallsc(P,p,UN,LN) CFC_(_(UN,P),_(LN,p)) #define C_FUNCTION(UN,LN) fcallsc(UN,LN) #define FORTRAN_FUNCTION(UN,LN) CFC_(UN,LN) #ifndef COMMON_BLOCK #ifndef CONVEXFortran #ifndef CLIPPERFortran #if !(defined(AbsoftUNIXFortran)||defined(AbsoftProFortran)) #define COMMON_BLOCK(UN,LN) CFC_(UN,LN) #else #define COMMON_BLOCK(UN,LN) _(_C,LN) #endif /* AbsoftUNIXFortran or AbsoftProFortran */ #else #define COMMON_BLOCK(UN,LN) _(LN,__) #endif /* CLIPPERFortran */ #else #define COMMON_BLOCK(UN,LN) _3(_,LN,_) #endif /* CONVEXFortran */ #endif /* COMMON_BLOCK */ #ifndef DOUBLE_PRECISION #if defined(CRAYFortran) && !defined(_CRAYT3E) #define DOUBLE_PRECISION long double #else #define DOUBLE_PRECISION double #endif #endif #ifndef FORTRAN_REAL #if defined(CRAYFortran) && defined(_CRAYT3E) #define FORTRAN_REAL double #else #define FORTRAN_REAL float #endif #endif #ifdef CRAYFortran #ifdef _CRAY #include #else #include "fortran.h" /* i.e. if crosscompiling assume user has file. */ #endif #define FLOATVVVVVVV_cfPP (FORTRAN_REAL *) /* Used for C calls FORTRAN. */ /* CRAY's double==float but CRAY says pointers to doubles and floats are diff.*/ #define VOIDP (void *) /* When FORTRAN calls C, we don't know if C routine arg.'s have been declared float *, or double *. */ #else #define FLOATVVVVVVV_cfPP #define VOIDP #endif #ifdef vmsFortran #if defined(vms) || defined(__vms) #include #else #include "descrip.h" /* i.e. if crosscompiling assume user has file. */ #endif #endif #ifdef sunFortran #if defined(sun) || defined(__sun) #include /* Sun's FLOATFUNCTIONTYPE, ASSIGNFLOAT, RETURNFLOAT. */ #else #include "math.h" /* i.e. if crosscompiling assume user has file. */ #endif /* At least starting with the default C compiler SC3.0.1 of SunOS 5.3, * FLOATFUNCTIONTYPE, ASSIGNFLOAT, RETURNFLOAT are not required and not in * , since sun C no longer promotes C float return values to doubles. * Therefore, only use them if defined. * Even if gcc is being used, assume that it exhibits the Sun C compiler * behavior in order to be able to use *.o from the Sun C compiler. * i.e. If FLOATFUNCTIONTYPE, etc. are in math.h, they required by gcc. */ #endif #ifndef apolloFortran #define COMMON_BLOCK_DEF(DEFINITION, NAME) extern DEFINITION NAME #define CF_NULL_PROTO #else /* HP doesn't understand #elif. */ /* Without ANSI prototyping, Apollo promotes float functions to double. */ /* Note that VAX/VMS, IBM, Mips choke on 'type function(...);' prototypes. */ #define CF_NULL_PROTO ... #ifndef __CF__APOLLO67 #define COMMON_BLOCK_DEF(DEFINITION, NAME) \ DEFINITION NAME __attribute((__section(NAME))) #else #define COMMON_BLOCK_DEF(DEFINITION, NAME) \ DEFINITION NAME #attribute[section(NAME)] #endif #endif #ifdef __cplusplus #undef CF_NULL_PROTO #define CF_NULL_PROTO ... #endif #ifndef USE_NEW_DELETE #ifdef __cplusplus #define USE_NEW_DELETE 1 #else #define USE_NEW_DELETE 0 #endif #endif #if USE_NEW_DELETE #define _cf_malloc(N) new char[N] #define _cf_free(P) delete[] P #else #define _cf_malloc(N) (char *)malloc(N) #define _cf_free(P) free(P) #endif #ifdef mipsFortran #define CF_DECLARE_GETARG int f77argc; char **f77argv #define CF_SET_GETARG(ARGC,ARGV) f77argc = ARGC; f77argv = ARGV #else #define CF_DECLARE_GETARG #define CF_SET_GETARG(ARGC,ARGV) #endif #ifdef OLD_VAXC /* Allow %CC-I-PARAMNOTUSED. */ #pragma standard #endif #define AcfCOMMA , #define AcfCOLON ; /*-------------------------------------------------------------------------*/ /* UTILITIES USED WITHIN CFORTRAN.H */ #define _cfMIN(A,B) (As) { /* Need this to handle NULL string.*/ while (e>s && *--e==t); /* Don't follow t's past beginning. */ e[*e==t?0:1] = '\0'; /* Handle s[0]=t correctly. */ } return s; } /* kill_trailingn(s,t,e) will kill the trailing t's in string s. e normally points to the terminating '\0' of s, but may actually point to anywhere in s. s's new '\0' will be placed at e or earlier in order to remove any trailing t's. If es) { /* Watch out for neg. length string.*/ while (e>s && *--e==t); /* Don't follow t's past beginning. */ e[*e==t?0:1] = '\0'; /* Handle s[0]=t correctly. */ } return s; } /* Note the following assumes that any element which has t's to be chopped off, does indeed fill the entire element. */ #ifndef __CF__KnR static char *vkill_trailing(char* cstr, int elem_len, int sizeofcstr, char t) #else static char *vkill_trailing( cstr, elem_len, sizeofcstr, t) char* cstr; int elem_len; int sizeofcstr; char t; #endif { int i; for (i=0; i= 4.3 gives message: zow35> cc -c -DDECFortran cfortest.c cfe: Fatal: Out of memory: cfortest.c zow35> Old __hpux had the problem, but new 'HP-UX A.09.03 A 9000/735' is fine if using -Aa, otherwise we have a problem. */ #ifndef MAX_PREPRO_ARGS #if !defined(__GNUC__) && (defined(VAXUltrix) || defined(__CF__APOLLO67) || (defined(sun)&&!defined(__sun)) || defined(_CRAY) || defined(__ultrix__) || (defined(__hpux)&&defined(__CF__KnR))) #define MAX_PREPRO_ARGS 31 #else #define MAX_PREPRO_ARGS 99 #endif #endif #if defined(AbsoftUNIXFortran) || defined(AbsoftProFortran) /* In addition to explicit Absoft stuff, only Absoft requires: - DEFAULT coming from _cfSTR. DEFAULT could have been called e.g. INT, but keep it for clarity. - M term in CFARGT14 and CFARGT14FS. */ #define ABSOFT_cf1(T0) _(T0,_cfSTR)(0,ABSOFT1,0,0,0,0,0) #define ABSOFT_cf2(T0) _(T0,_cfSTR)(0,ABSOFT2,0,0,0,0,0) #define ABSOFT_cf3(T0) _(T0,_cfSTR)(0,ABSOFT3,0,0,0,0,0) #define DEFAULT_cfABSOFT1 #define LOGICAL_cfABSOFT1 #define STRING_cfABSOFT1 ,MAX_LEN_FORTRAN_FUNCTION_STRING #define DEFAULT_cfABSOFT2 #define LOGICAL_cfABSOFT2 #define STRING_cfABSOFT2 ,unsigned D0 #define DEFAULT_cfABSOFT3 #define LOGICAL_cfABSOFT3 #define STRING_cfABSOFT3 ,D0 #else #define ABSOFT_cf1(T0) #define ABSOFT_cf2(T0) #define ABSOFT_cf3(T0) #endif /* _Z introduced to cicumvent IBM and HP silly preprocessor warning. e.g. "Macro CFARGT14 invoked with a null argument." */ #define _Z #define CFARGT14S(S,T1,T2,T3,T4,T5,T6,T7,T8,T9,TA,TB,TC,TD,TE) \ S(T1,1) S(T2,2) S(T3,3) S(T4,4) S(T5,5) S(T6,6) S(T7,7) \ S(T8,8) S(T9,9) S(TA,10) S(TB,11) S(TC,12) S(TD,13) S(TE,14) #define CFARGT27S(S,T1,T2,T3,T4,T5,T6,T7,T8,T9,TA,TB,TC,TD,TE,TF,TG,TH,TI,TJ,TK,TL,TM,TN,TO,TP,TQ,TR) \ S(T1,1) S(T2,2) S(T3,3) S(T4,4) S(T5,5) S(T6,6) S(T7,7) \ S(T8,8) S(T9,9) S(TA,10) S(TB,11) S(TC,12) S(TD,13) S(TE,14) \ S(TF,15) S(TG,16) S(TH,17) S(TI,18) S(TJ,19) S(TK,20) S(TL,21) \ S(TM,22) S(TN,23) S(TO,24) S(TP,25) S(TQ,26) S(TR,27) #define CFARGT14FS(F,S,M,T1,T2,T3,T4,T5,T6,T7,T8,T9,TA,TB,TC,TD,TE) \ F(T1,1,0) F(T2,2,1) F(T3,3,1) F(T4,4,1) F(T5,5,1) F(T6,6,1) F(T7,7,1) \ F(T8,8,1) F(T9,9,1) F(TA,10,1) F(TB,11,1) F(TC,12,1) F(TD,13,1) F(TE,14,1) \ M CFARGT14S(S,T1,T2,T3,T4,T5,T6,T7,T8,T9,TA,TB,TC,TD,TE) #define CFARGT27FS(F,S,M,T1,T2,T3,T4,T5,T6,T7,T8,T9,TA,TB,TC,TD,TE,TF,TG,TH,TI,TJ,TK,TL,TM,TN,TO,TP,TQ,TR) \ F(T1,1,0) F(T2,2,1) F(T3,3,1) F(T4,4,1) F(T5,5,1) F(T6,6,1) F(T7,7,1) \ F(T8,8,1) F(T9,9,1) F(TA,10,1) F(TB,11,1) F(TC,12,1) F(TD,13,1) F(TE,14,1) \ F(TF,15,1) F(TG,16,1) F(TH,17,1) F(TI,18,1) F(TJ,19,1) F(TK,20,1) F(TL,21,1) \ F(TM,22,1) F(TN,23,1) F(TO,24,1) F(TP,25,1) F(TQ,26,1) F(TR,27,1) \ M CFARGT27S(S,T1,T2,T3,T4,T5,T6,T7,T8,T9,TA,TB,TC,TD,TE,TF,TG,TH,TI,TJ,TK,TL,TM,TN,TO,TP,TQ,TR) #if !(defined(PowerStationFortran)||defined(hpuxFortran800)) /* Old CFARGT14 -> CFARGT14FS as seen below, for Absoft cross-compile yields: SunOS> cc -c -Xa -DAbsoftUNIXFortran c.c "c.c", line 406: warning: argument mismatch Haven't checked if this is ANSI C or a SunOS bug. SunOS -Xs works ok. Behavior is most clearly seen in example: #define A 1 , 2 #define C(X,Y,Z) x=X. y=Y. z=Z. #define D(X,Y,Z) C(X,Y,Z) D(x,A,z) Output from preprocessor is: x = x . y = 1 . z = 2 . #define CFARGT14(F,S,M,T1,T2,T3,T4,T5,T6,T7,T8,T9,TA,TB,TC,TD,TE) \ CFARGT14FS(F,S,M,T1,T2,T3,T4,T5,T6,T7,T8,T9,TA,TB,TC,TD,TE) */ #define CFARGT14(F,S,M,T1,T2,T3,T4,T5,T6,T7,T8,T9,TA,TB,TC,TD,TE) \ F(T1,1,0) F(T2,2,1) F(T3,3,1) F(T4,4,1) F(T5,5,1) F(T6,6,1) F(T7,7,1) \ F(T8,8,1) F(T9,9,1) F(TA,10,1) F(TB,11,1) F(TC,12,1) F(TD,13,1) F(TE,14,1) \ M CFARGT14S(S,T1,T2,T3,T4,T5,T6,T7,T8,T9,TA,TB,TC,TD,TE) #define CFARGT27(F,S,M,T1,T2,T3,T4,T5,T6,T7,T8,T9,TA,TB,TC,TD,TE,TF,TG,TH,TI,TJ,TK,TL,TM,TN,TO,TP,TQ,TR) \ F(T1,1,0) F(T2,2,1) F(T3,3,1) F(T4,4,1) F(T5,5,1) F(T6,6,1) F(T7,7,1) \ F(T8,8,1) F(T9,9,1) F(TA,10,1) F(TB,11,1) F(TC,12,1) F(TD,13,1) F(TE,14,1) \ F(TF,15,1) F(TG,16,1) F(TH,17,1) F(TI,18,1) F(TJ,19,1) F(TK,20,1) F(TL,21,1) \ F(TM,22,1) F(TN,23,1) F(TO,24,1) F(TP,25,1) F(TQ,26,1) F(TR,27,1) \ M CFARGT27S(S,T1,T2,T3,T4,T5,T6,T7,T8,T9,TA,TB,TC,TD,TE,TF,TG,TH,TI,TJ,TK,TL,TM,TN,TO,TP,TQ,TR) #define CFARGT20(F,S,M,T1,T2,T3,T4,T5,T6,T7,T8,T9,TA,TB,TC,TD,TE,TF,TG,TH,TI,TJ,TK) \ F(T1,1,0) F(T2,2,1) F(T3,3,1) F(T4,4,1) F(T5,5,1) F(T6,6,1) F(T7,7,1) \ F(T8,8,1) F(T9,9,1) F(TA,10,1) F(TB,11,1) F(TC,12,1) F(TD,13,1) F(TE,14,1) \ F(TF,15,1) F(TG,16,1) F(TH,17,1) F(TI,18,1) F(TJ,19,1) F(TK,20,1) \ S(T1,1) S(T2,2) S(T3,3) S(T4,4) S(T5,5) S(T6,6) S(T7,7) \ S(T8,8) S(T9,9) S(TA,10) S(TB,11) S(TC,12) S(TD,13) S(TE,14) \ S(TF,15) S(TG,16) S(TH,17) S(TI,18) S(TJ,19) S(TK,20) #define CFARGTA14(F,S,T1,T2,T3,T4,T5,T6,T7,T8,T9,TA,TB,TC,TD,TE,A1,A2,A3,A4,A5,A6,A7,A8,A9,AA,AB,AC,AD,AE) \ F(T1,A1,1,0) F(T2,A2,2,1) F(T3,A3,3,1) F(T4,A4,4,1) F(T5,A5,5,1) F(T6,A6,6,1) \ F(T7,A7,7,1) F(T8,A8,8,1) F(T9,A9,9,1) F(TA,AA,10,1) F(TB,AB,11,1) F(TC,AC,12,1) \ F(TD,AD,13,1) F(TE,AE,14,1) S(T1,1) S(T2,2) S(T3,3) S(T4,4) \ S(T5,5) S(T6,6) S(T7,7) S(T8,8) S(T9,9) S(TA,10) \ S(TB,11) S(TC,12) S(TD,13) S(TE,14) #if MAX_PREPRO_ARGS>31 #define CFARGTA20(F,S,T1,T2,T3,T4,T5,T6,T7,T8,T9,TA,TB,TC,TD,TE,TF,TG,TH,TI,TJ,TK,A1,A2,A3,A4,A5,A6,A7,A8,A9,AA,AB,AC,AD,AE,AF,AG,AH,AI,AJ,AK) \ F(T1,A1,1,0) F(T2,A2,2,1) F(T3,A3,3,1) F(T4,A4,4,1) F(T5,A5,5,1) F(T6,A6,6,1) \ F(T7,A7,7,1) F(T8,A8,8,1) F(T9,A9,9,1) F(TA,AA,10,1) F(TB,AB,11,1) F(TC,AC,12,1) \ F(TD,AD,13,1) F(TE,AE,14,1) F(TF,AF,15,1) F(TG,AG,16,1) F(TH,AH,17,1) F(TI,AI,18,1) \ F(TJ,AJ,19,1) F(TK,AK,20,1) S(T1,1) S(T2,2) S(T3,3) S(T4,4) \ S(T5,5) S(T6,6) S(T7,7) S(T8,8) S(T9,9) S(TA,10) \ S(TB,11) S(TC,12) S(TD,13) S(TE,14) S(TF,15) S(TG,16) \ S(TH,17) S(TI,18) S(TJ,19) S(TK,20) #define CFARGTA27(F,S,T1,T2,T3,T4,T5,T6,T7,T8,T9,TA,TB,TC,TD,TE,TF,TG,TH,TI,TJ,TK,TL,TM,TN,TO,TP,TQ,TR,A1,A2,A3,A4,A5,A6,A7,A8,A9,AA,AB,AC,AD,AE,AF,AG,AH,AI,AJ,AK,AL,AM,AN,AO,AP,AQ,AR) \ F(T1,A1,1,0) F(T2,A2,2,1) F(T3,A3,3,1) F(T4,A4,4,1) F(T5,A5,5,1) F(T6,A6,6,1) \ F(T7,A7,7,1) F(T8,A8,8,1) F(T9,A9,9,1) F(TA,AA,10,1) F(TB,AB,11,1) F(TC,AC,12,1) \ F(TD,AD,13,1) F(TE,AE,14,1) F(TF,AF,15,1) F(TG,AG,16,1) F(TH,AH,17,1) F(TI,AI,18,1) \ F(TJ,AJ,19,1) F(TK,AK,20,1) F(TL,AL,21,1) F(TM,AM,22,1) F(TN,AN,23,1) F(TO,AO,24,1) \ F(TP,AP,25,1) F(TQ,AQ,26,1) F(TR,AR,27,1) S(T1,1) S(T2,2) S(T3,3) \ S(T4,4) S(T5,5) S(T6,6) S(T7,7) S(T8,8) S(T9,9) \ S(TA,10) S(TB,11) S(TC,12) S(TD,13) S(TE,14) S(TF,15) \ S(TG,16) S(TH,17) S(TI,18) S(TJ,19) S(TK,20) S(TL,21) \ S(TM,22) S(TN,23) S(TO,24) S(TP,25) S(TQ,26) S(TR,27) #endif #else #define CFARGT14(F,S,M,T1,T2,T3,T4,T5,T6,T7,T8,T9,TA,TB,TC,TD,TE) \ F(T1,1,0) S(T1,1) F(T2,2,1) S(T2,2) F(T3,3,1) S(T3,3) F(T4,4,1) S(T4,4) \ F(T5,5,1) S(T5,5) F(T6,6,1) S(T6,6) F(T7,7,1) S(T7,7) F(T8,8,1) S(T8,8) \ F(T9,9,1) S(T9,9) F(TA,10,1) S(TA,10) F(TB,11,1) S(TB,11) F(TC,12,1) S(TC,12) \ F(TD,13,1) S(TD,13) F(TE,14,1) S(TE,14) #define CFARGT27(F,S,M,T1,T2,T3,T4,T5,T6,T7,T8,T9,TA,TB,TC,TD,TE,TF,TG,TH,TI,TJ,TK,TL,TM,TN,TO,TP,TQ,TR) \ F(T1,1,0) S(T1,1) F(T2,2,1) S(T2,2) F(T3,3,1) S(T3,3) F(T4,4,1) S(T4,4) \ F(T5,5,1) S(T5,5) F(T6,6,1) S(T6,6) F(T7,7,1) S(T7,7) F(T8,8,1) S(T8,8) \ F(T9,9,1) S(T9,9) F(TA,10,1) S(TA,10) F(TB,11,1) S(TB,11) F(TC,12,1) S(TC,12) \ F(TD,13,1) S(TD,13) F(TE,14,1) S(TE,14) F(TF,15,1) S(TF,15) F(TG,16,1) S(TG,16) \ F(TH,17,1) S(TH,17) F(TI,18,1) S(TI,18) F(TJ,19,1) S(TJ,19) F(TK,20,1) S(TK,20) \ F(TL,21,1) S(TL,21) F(TM,22,1) S(TM,22) F(TN,23,1) S(TN,23) F(TO,24,1) S(TO,24) \ F(TP,25,1) S(TP,25) F(TQ,26,1) S(TQ,26) F(TR,27,1) S(TR,27) #define CFARGT20(F,S,M,T1,T2,T3,T4,T5,T6,T7,T8,T9,TA,TB,TC,TD,TE,TF,TG,TH,TI,TJ,TK) \ F(T1,1,0) S(T1,1) F(T2,2,1) S(T2,2) F(T3,3,1) S(T3,3) F(T4,4,1) S(T4,4) \ F(T5,5,1) S(T5,5) F(T6,6,1) S(T6,6) F(T7,7,1) S(T7,7) F(T8,8,1) S(T8,8) \ F(T9,9,1) S(T9,9) F(TA,10,1) S(TA,10) F(TB,11,1) S(TB,11) F(TC,12,1) S(TC,12) \ F(TD,13,1) S(TD,13) F(TE,14,1) S(TE,14) F(TF,15,1) S(TF,15) F(TG,16,1) S(TG,16) \ F(TH,17,1) S(TH,17) F(TI,18,1) S(TI,18) F(TJ,19,1) S(TJ,19) F(TK,20,1) S(TK,20) #define CFARGTA14(F,S,T1,T2,T3,T4,T5,T6,T7,T8,T9,TA,TB,TC,TD,TE,A1,A2,A3,A4,A5,A6,A7,A8,A9,AA,AB,AC,AD,AE) \ F(T1,A1,1,0) S(T1,1) F(T2,A2,2,1) S(T2,2) F(T3,A3,3,1) S(T3,3) \ F(T4,A4,4,1) S(T4,4) F(T5,A5,5,1) S(T5,5) F(T6,A6,6,1) S(T6,6) \ F(T7,A7,7,1) S(T7,7) F(T8,A8,8,1) S(T8,8) F(T9,A9,9,1) S(T9,9) \ F(TA,AA,10,1) S(TA,10) F(TB,AB,11,1) S(TB,11) F(TC,AC,12,1) S(TC,12) \ F(TD,AD,13,1) S(TD,13) F(TE,AE,14,1) S(TE,14) #if MAX_PREPRO_ARGS>31 #define CFARGTA20(F,S,T1,T2,T3,T4,T5,T6,T7,T8,T9,TA,TB,TC,TD,TE,TF,TG,TH,TI,TJ,TK,A1,A2,A3,A4,A5,A6,A7,A8,A9,AA,AB,AC,AD,AE,AF,AG,AH,AI,AJ,AK) \ F(T1,A1,1,0) S(T1,1) F(T2,A2,2,1) S(T2,2) F(T3,A3,3,1) S(T3,3) \ F(T4,A4,4,1) S(T4,4) F(T5,A5,5,1) S(T5,5) F(T6,A6,6,1) S(T6,6) \ F(T7,A7,7,1) S(T7,7) F(T8,A8,8,1) S(T8,8) F(T9,A9,9,1) S(T9,9) \ F(TA,AA,10,1) S(TA,10) F(TB,AB,11,1) S(TB,11) F(TC,AC,12,1) S(TC,12) \ F(TD,AD,13,1) S(TD,13) F(TE,AE,14,1) S(TE,14) F(TF,AF,15,1) S(TF,15) \ F(TG,AG,16,1) S(TG,16) F(TH,AH,17,1) S(TH,17) F(TI,AI,18,1) S(TI,18) \ F(TJ,AJ,19,1) S(TJ,19) F(TK,AK,20,1) S(TK,20) #define CFARGTA27(F,S,T1,T2,T3,T4,T5,T6,T7,T8,T9,TA,TB,TC,TD,TE,TF,TG,TH,TI,TJ,TK,TL,TM,TN,TO,TP,TQ,TR,A1,A2,A3,A4,A5,A6,A7,A8,A9,AA,AB,AC,AD,AE,AF,AG,AH,AI,AJ,AK,AL,AM,AN,AO,AP,AQ,AR) \ F(T1,A1,1,0) S(T1,1) F(T2,A2,2,1) S(T2,2) F(T3,A3,3,1) S(T3,3) \ F(T4,A4,4,1) S(T4,4) F(T5,A5,5,1) S(T5,5) F(T6,A6,6,1) S(T6,6) \ F(T7,A7,7,1) S(T7,7) F(T8,A8,8,1) S(T8,8) F(T9,A9,9,1) S(T9,9) \ F(TA,AA,10,1) S(TA,10) F(TB,AB,11,1) S(TB,11) F(TC,AC,12,1) S(TC,12) \ F(TD,AD,13,1) S(TD,13) F(TE,AE,14,1) S(TE,14) F(TF,AF,15,1) S(TF,15) \ F(TG,AG,16,1) S(TG,16) F(TH,AH,17,1) S(TH,17) F(TI,AI,18,1) S(TI,18) \ F(TJ,AJ,19,1) S(TJ,19) F(TK,AK,20,1) S(TK,20) F(TL,AL,21,1) S(TL,21) \ F(TM,AM,22,1) S(TM,22) F(TN,AN,23,1) S(TN,23) F(TO,AO,24,1) S(TO,24) \ F(TP,AP,25,1) S(TP,25) F(TQ,AQ,26,1) S(TQ,26) F(TR,AR,27,1) S(TR,27) #endif #endif #define PROTOCCALLSFSUB1( UN,LN,T1) \ PROTOCCALLSFSUB14(UN,LN,T1,CF_0,CF_0,CF_0,CF_0,CF_0,CF_0,CF_0,CF_0,CF_0,CF_0,CF_0,CF_0,CF_0) #define PROTOCCALLSFSUB2( UN,LN,T1,T2) \ PROTOCCALLSFSUB14(UN,LN,T1,T2,CF_0,CF_0,CF_0,CF_0,CF_0,CF_0,CF_0,CF_0,CF_0,CF_0,CF_0,CF_0) #define PROTOCCALLSFSUB3( UN,LN,T1,T2,T3) \ PROTOCCALLSFSUB14(UN,LN,T1,T2,T3,CF_0,CF_0,CF_0,CF_0,CF_0,CF_0,CF_0,CF_0,CF_0,CF_0,CF_0) #define PROTOCCALLSFSUB4( UN,LN,T1,T2,T3,T4) \ PROTOCCALLSFSUB14(UN,LN,T1,T2,T3,T4,CF_0,CF_0,CF_0,CF_0,CF_0,CF_0,CF_0,CF_0,CF_0,CF_0) #define PROTOCCALLSFSUB5( UN,LN,T1,T2,T3,T4,T5) \ PROTOCCALLSFSUB14(UN,LN,T1,T2,T3,T4,T5,CF_0,CF_0,CF_0,CF_0,CF_0,CF_0,CF_0,CF_0,CF_0) #define PROTOCCALLSFSUB6( UN,LN,T1,T2,T3,T4,T5,T6) \ PROTOCCALLSFSUB14(UN,LN,T1,T2,T3,T4,T5,T6,CF_0,CF_0,CF_0,CF_0,CF_0,CF_0,CF_0,CF_0) #define PROTOCCALLSFSUB7( UN,LN,T1,T2,T3,T4,T5,T6,T7) \ PROTOCCALLSFSUB14(UN,LN,T1,T2,T3,T4,T5,T6,T7,CF_0,CF_0,CF_0,CF_0,CF_0,CF_0,CF_0) #define PROTOCCALLSFSUB8( UN,LN,T1,T2,T3,T4,T5,T6,T7,T8) \ PROTOCCALLSFSUB14(UN,LN,T1,T2,T3,T4,T5,T6,T7,T8,CF_0,CF_0,CF_0,CF_0,CF_0,CF_0) #define PROTOCCALLSFSUB9( UN,LN,T1,T2,T3,T4,T5,T6,T7,T8,T9) \ PROTOCCALLSFSUB14(UN,LN,T1,T2,T3,T4,T5,T6,T7,T8,T9,CF_0,CF_0,CF_0,CF_0,CF_0) #define PROTOCCALLSFSUB10(UN,LN,T1,T2,T3,T4,T5,T6,T7,T8,T9,TA) \ PROTOCCALLSFSUB14(UN,LN,T1,T2,T3,T4,T5,T6,T7,T8,T9,TA,CF_0,CF_0,CF_0,CF_0) #define PROTOCCALLSFSUB11(UN,LN,T1,T2,T3,T4,T5,T6,T7,T8,T9,TA,TB) \ PROTOCCALLSFSUB14(UN,LN,T1,T2,T3,T4,T5,T6,T7,T8,T9,TA,TB,CF_0,CF_0,CF_0) #define PROTOCCALLSFSUB12(UN,LN,T1,T2,T3,T4,T5,T6,T7,T8,T9,TA,TB,TC) \ PROTOCCALLSFSUB14(UN,LN,T1,T2,T3,T4,T5,T6,T7,T8,T9,TA,TB,TC,CF_0,CF_0) #define PROTOCCALLSFSUB13(UN,LN,T1,T2,T3,T4,T5,T6,T7,T8,T9,TA,TB,TC,TD) \ PROTOCCALLSFSUB14(UN,LN,T1,T2,T3,T4,T5,T6,T7,T8,T9,TA,TB,TC,TD,CF_0) #define PROTOCCALLSFSUB15(UN,LN,T1,T2,T3,T4,T5,T6,T7,T8,T9,TA,TB,TC,TD,TE,TF) \ PROTOCCALLSFSUB20(UN,LN,T1,T2,T3,T4,T5,T6,T7,T8,T9,TA,TB,TC,TD,TE,TF,CF_0,CF_0,CF_0,CF_0,CF_0) #define PROTOCCALLSFSUB16(UN,LN,T1,T2,T3,T4,T5,T6,T7,T8,T9,TA,TB,TC,TD,TE,TF,TG) \ PROTOCCALLSFSUB20(UN,LN,T1,T2,T3,T4,T5,T6,T7,T8,T9,TA,TB,TC,TD,TE,TF,TG,CF_0,CF_0,CF_0,CF_0) #define PROTOCCALLSFSUB17(UN,LN,T1,T2,T3,T4,T5,T6,T7,T8,T9,TA,TB,TC,TD,TE,TF,TG,TH) \ PROTOCCALLSFSUB20(UN,LN,T1,T2,T3,T4,T5,T6,T7,T8,T9,TA,TB,TC,TD,TE,TF,TG,TH,CF_0,CF_0,CF_0) #define PROTOCCALLSFSUB18(UN,LN,T1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CALLSFSUB27(UN,LN,T1,T2,T3,T4,T5,T6,T7,T8,T9,TA,TB,TC,TD,TE,TF,TG,TH,TI,TJ,TK,TL,TM,TN,TO,CF_0,CF_0,CF_0) #define PROTOCCALLSFSUB25(UN,LN,T1,T2,T3,T4,T5,T6,T7,T8,T9,TA,TB,TC,TD,TE,TF,TG,TH,TI,TJ,TK,TL,TM,TN,TO,TP) \ PROTOCCALLSFSUB27(UN,LN,T1,T2,T3,T4,T5,T6,T7,T8,T9,TA,TB,TC,TD,TE,TF,TG,TH,TI,TJ,TK,TL,TM,TN,TO,TP,CF_0,CF_0) #define PROTOCCALLSFSUB26(UN,LN,T1,T2,T3,T4,T5,T6,T7,T8,T9,TA,TB,TC,TD,TE,TF,TG,TH,TI,TJ,TK,TL,TM,TN,TO,TP,TQ) \ PROTOCCALLSFSUB27(UN,LN,T1,T2,T3,T4,T5,T6,T7,T8,T9,TA,TB,TC,TD,TE,TF,TG,TH,TI,TJ,TK,TL,TM,TN,TO,TP,TQ,CF_0) #ifndef FCALLSC_QUALIFIER #ifdef VISUAL_CPLUSPLUS #define FCALLSC_QUALIFIER __stdcall #else #define FCALLSC_QUALIFIER #endif #endif #ifdef __cplusplus #define CFextern extern "C" #else #define CFextern extern #endif #ifdef CFSUBASFUN #define PROTOCCALLSFSUB0(UN,LN) \ PROTOCCALLSFFUN0( VOID,UN,LN) #define PROTOCCALLSFSUB14(UN,LN,T1,T2,T3,T4,T5,T6,T7,T8,T9,TA,TB,TC,TD,TE) \ PROTOCCALLSFFUN14(VOID,UN,LN,T1,T2,T3,T4,T5,T6,T7,T8,T9,TA,TB,TC,TD,TE) #define PROTOCCALLSFSUB20(UN,LN,T1,T2,T3,T4,T5,T6,T7,T8,T9,TA,TB,TC,TD,TE,TF,TG,TH,TI,TJ,TK)\ PROTOCCALLSFFUN20(VOID,UN,LN,T1,T2,T3,T4,T5,T6,T7,T8,T9,TA,TB,TC,TD,TE,TF,TG,TH,TI,TJ,TK) #define PROTOCCALLSFSUB27(UN,LN,T1,T2,T3,T4,T5,T6,T7,T8,T9,TA,TB,TC,TD,TE,TF,TG,TH,TI,TJ,TK,TL,TM,TN,TO,TP,TQ,TR)\ PROTOCCALLSFFUN27(VOID,UN,LN,T1,T2,T3,T4,T5,T6,T7,T8,T9,TA,TB,TC,TD,TE,TF,TG,TH,TI,TJ,TK,TL,TM,TN,TO,TP,TQ,TR) #else /* Note: Prevent compiler warnings, null #define PROTOCCALLSFSUB14/20 after #include-ing cfortran.h if calling the FORTRAN wrapper within the same source code where the wrapper is created. */ #define PROTOCCALLSFSUB0(UN,LN) _(VOID,_cfPU)(CFC_(UN,LN))(); #ifndef __CF__KnR #define PROTOCCALLSFSUB14(UN,LN,T1,T2,T3,T4,T5,T6,T7,T8,T9,TA,TB,TC,TD,TE) \ _(VOID,_cfPU)(CFC_(UN,LN))( CFARGT14(NCF,KCF,_Z,T1,T2,T3,T4,T5,T6,T7,T8,T9,TA,TB,TC,TD,TE) ); #define PROTOCCALLSFSUB20(UN,LN,T1,T2,T3,T4,T5,T6,T7,T8,T9,TA,TB,TC,TD,TE,TF,TG,TH,TI,TJ,TK)\ _(VOID,_cfPU)(CFC_(UN,LN))( CFARGT20(NCF,KCF,_Z,T1,T2,T3,T4,T5,T6,T7,T8,T9,TA,TB,TC,TD,TE,TF,TG,TH,TI,TJ,TK) ); #define PROTOCCALLSFSUB27(UN,LN,T1,T2,T3,T4,T5,T6,T7,T8,T9,TA,TB,TC,TD,TE,TF,TG,TH,TI,TJ,TK,TL,TM,TN,TO,TP,TQ,TR)\ _(VOID,_cfPU)(CFC_(UN,LN))( CFARGT27(NCF,KCF,_Z,T1,T2,T3,T4,T5,T6,T7,T8,T9,TA,TB,TC,TD,TE,TF,TG,TH,TI,TJ,TK,TL,TM,TN,TO,TP,TQ,TR) ); #else #define PROTOCCALLSFSUB14(UN,LN,T1,T2,T3,T4,T5,T6,T7,T8,T9,TA,TB,TC,TD,TE) \ PROTOCCALLSFSUB0(UN,LN) #define PROTOCCALLSFSUB20(UN,LN,T1,T2,T3,T4,T5,T6,T7,T8,T9,TA,TB,TC,TD,TE,TF,TG,TH,TI,TJ,TK) \ PROTOCCALLSFSUB0(UN,LN) #define PROTOCCALLSFSUB27(UN,LN,T1,T2,T3,T4,T5,T6,T7,T8,T9,TA,TB,TC,TD,TE,TF,TG,TH,TI,TJ,TK,TL,TM,TN,TO,TP,TQ,TR) \ PROTOCCALLSFSUB0(UN,LN) #endif #endif #ifdef OLD_VAXC /* Allow %CC-I-PARAMNOTUSED. */ #pragma standard #endif #define CCALLSFSUB1( UN,LN,T1, A1) \ CCALLSFSUB5 (UN,LN,T1,CF_0,CF_0,CF_0,CF_0,A1,0,0,0,0) #define CCALLSFSUB2( UN,LN,T1,T2, A1,A2) \ CCALLSFSUB5 (UN,LN,T1,T2,CF_0,CF_0,CF_0,A1,A2,0,0,0) #define CCALLSFSUB3( UN,LN,T1,T2,T3, A1,A2,A3) \ CCALLSFSUB5 (UN,LN,T1,T2,T3,CF_0,CF_0,A1,A2,A3,0,0) #define CCALLSFSUB4( UN,LN,T1,T2,T3,T4, A1,A2,A3,A4)\ CCALLSFSUB5 (UN,LN,T1,T2,T3,T4,CF_0,A1,A2,A3,A4,0) #define CCALLSFSUB5( UN,LN,T1,T2,T3,T4,T5, A1,A2,A3,A4,A5) \ CCALLSFSUB10(UN,LN,T1,T2,T3,T4,T5,CF_0,CF_0,CF_0,CF_0,CF_0,A1,A2,A3,A4,A5,0,0,0,0,0) #define CCALLSFSUB6( UN,LN,T1,T2,T3,T4,T5,T6, A1,A2,A3,A4,A5,A6) \ CCALLSFSUB10(UN,LN,T1,T2,T3,T4,T5,T6,CF_0,CF_0,CF_0,CF_0,A1,A2,A3,A4,A5,A6,0,0,0,0) #define CCALLSFSUB7( UN,LN,T1,T2,T3,T4,T5,T6,T7, A1,A2,A3,A4,A5,A6,A7) \ CCALLSFSUB10(UN,LN,T1,T2,T3,T4,T5,T6,T7,CF_0,CF_0,CF_0,A1,A2,A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,T6,T7,T8,T9,TA,TB,TC,TD,CF_0,A1,A2,A3,A4,A5,A6,A7,A8,A9,AA,AB,AC,AD,0) #ifdef __cplusplus #define CPPPROTOCLSFSUB0( UN,LN) #define CPPPROTOCLSFSUB14(UN,LN,T1,T2,T3,T4,T5,T6,T7,T8,T9,TA,TB,TC,TD,TE) #define CPPPROTOCLSFSUB20(UN,LN,T1,T2,T3,T4,T5,T6,T7,T8,T9,TA,TB,TC,TD,TE,TF,TG,TH,TI,TJ,TK) #define CPPPROTOCLSFSUB27(UN,LN,T1,T2,T3,T4,T5,T6,T7,T8,T9,TA,TB,TC,TD,TE,TF,TG,TH,TI,TJ,TK,TL,TM,TN,TO,TP,TQ,TR) #else #define CPPPROTOCLSFSUB0(UN,LN) \ PROTOCCALLSFSUB0(UN,LN) #define CPPPROTOCLSFSUB14(UN,LN,T1,T2,T3,T4,T5,T6,T7,T8,T9,TA,TB,TC,TD,TE) \ PROTOCCALLSFSUB14(UN,LN,T1,T2,T3,T4,T5,T6,T7,T8,T9,TA,TB,TC,TD,TE) #define CPPPROTOCLSFSUB20(UN,LN,T1,T2,T3,T4,T5,T6,T7,T8,T9,TA,TB,TC,TD,TE,TF,TG,TH,TI,TJ,TK) \ PROTOCCALLSFSUB20(UN,LN,T1,T2,T3,T4,T5,T6,T7,T8,T9,TA,TB,TC,TD,TE,TF,TG,TH,TI,TJ,TK) #define CPPPROTOCLSFSUB27(UN,LN,T1,T2,T3,T4,T5,T6,T7,T8,T9,TA,TB,TC,TD,TE,TF,TG,TH,TI,TJ,TK,TL,TM,TN,TO,TP,TQ,TR) \ PROTOCCALLSFSUB27(UN,LN,T1,T2,T3,T4,T5,T6,T7,T8,T9,TA,TB,TC,TD,TE,TF,TG,TH,TI,TJ,TK,TL,TM,TN,TO,TP,TQ,TR) #endif #ifdef CFSUBASFUN #define CCALLSFSUB0(UN,LN) CCALLSFFUN0(UN,LN) #define CCALLSFSUB14(UN,LN,T1,T2,T3,T4,T5,T6,T7,T8,T9,TA,TB,TC,TD,TE,A1,A2,A3,A4,A5,A6,A7,A8,A9,AA,AB,AC,AD,AE)\ CCALLSFFUN14(UN,LN,T1,T2,T3,T4,T5,T6,T7,T8,T9,TA,TB,TC,TD,TE,A1,A2,A3,A4,A5,A6,A7,A8,A9,AA,AB,AC,AD,AE) #else /* do{...}while(0) allows if(a==b) FORT(); else BORT(); */ #define CCALLSFSUB0( UN,LN) do{CPPPROTOCLSFSUB0(UN,LN) CFC_(UN,LN)();}while(0) #define CCALLSFSUB14(UN,LN,T1,T2,T3,T4,T5,T6,T7,T8,T9,TA,TB,TC,TD,TE,A1,A2,A3,A4,A5,A6,A7,A8,A9,AA,AB,AC,AD,AE)\ do{VVCF(T1,A1,B1) VVCF(T2,A2,B2) VVCF(T3,A3,B3) VVCF(T4,A4,B4) VVCF(T5,A5,B5) \ VVCF(T6,A6,B6) VVCF(T7,A7,B7) VVCF(T8,A8,B8) VVCF(T9,A9,B9) VVCF(TA,AA,B10) \ VVCF(TB,AB,B11) VVCF(TC,AC,B12) VVCF(TD,AD,B13) VVCF(TE,AE,B14) \ CPPPROTOCLSFSUB14(UN,LN,T1,T2,T3,T4,T5,T6,T7,T8,T9,TA,TB,TC,TD,TE) \ ACF(LN,T1,A1,1) ACF(LN,T2,A2,2) ACF(LN,T3,A3,3) \ ACF(LN,T4,A4,4) ACF(LN,T5,A5,5) ACF(LN,T6,A6,6) ACF(LN,T7,A7,7) \ ACF(LN,T8,A8,8) ACF(LN,T9,A9,9) ACF(LN,TA,AA,10) ACF(LN,TB,AB,11) \ ACF(LN,TC,AC,12) ACF(LN,TD,AD,13) ACF(LN,TE,AE,14) \ CFC_(UN,LN)( CFARGTA14(AACF,JCF,T1,T2,T3,T4,T5,T6,T7,T8,T9,TA,TB,TC,TD,TE,A1,A2,A3,A4,A5,A6,A7,A8,A9,AA,AB,AC,AD,AE) );\ WCF(T1,A1,1) WCF(T2,A2,2) WCF(T3,A3,3) WCF(T4,A4,4) WCF(T5,A5,5) \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 VVCF(TB,AB,B11) VVCF(TC,AC,B12) VVCF(TD,AD,B13) VVCF(TE,AE,B14) VVCF(TF,AF,B15) \ VVCF(TG,AG,B16) VVCF(TH,AH,B17) VVCF(TI,AI,B18) VVCF(TJ,AJ,B19) VVCF(TK,AK,B20) \ CPPPROTOCLSFSUB20(UN,LN,T1,T2,T3,T4,T5,T6,T7,T8,T9,TA,TB,TC,TD,TE,TF,TG,TH,TI,TJ,TK) \ ACF(LN,T1,A1,1) ACF(LN,T2,A2,2) ACF(LN,T3,A3,3) ACF(LN,T4,A4,4) \ ACF(LN,T5,A5,5) ACF(LN,T6,A6,6) ACF(LN,T7,A7,7) ACF(LN,T8,A8,8) \ ACF(LN,T9,A9,9) ACF(LN,TA,AA,10) ACF(LN,TB,AB,11) ACF(LN,TC,AC,12) \ ACF(LN,TD,AD,13) ACF(LN,TE,AE,14) ACF(LN,TF,AF,15) ACF(LN,TG,AG,16) \ ACF(LN,TH,AH,17) ACF(LN,TI,AI,18) ACF(LN,TJ,AJ,19) ACF(LN,TK,AK,20) \ CFC_(UN,LN)( CFARGTA20(AACF,JCF,T1,T2,T3,T4,T5,T6,T7,T8,T9,TA,TB,TC,TD,TE,TF,TG,TH,TI,TJ,TK,A1,A2,A3,A4,A5,A6,A7,A8,A9,AA,AB,AC,AD,AE,AF,AG,AH,AI,AJ,AK) ); \ WCF(T1,A1,1) WCF(T2,A2,2) WCF(T3,A3,3) WCF(T4,A4,4) WCF(T5,A5,5) WCF(T6,A6,6) \ WCF(T7,A7,7) WCF(T8,A8,8) WCF(T9,A9,9) WCF(TA,AA,10) WCF(TB,AB,11) WCF(TC,AC,12) \ WCF(TD,AD,13) WCF(TE,AE,14) WCF(TF,AF,15) WCF(TG,AG,16) WCF(TH,AH,17) WCF(TI,AI,18) \ WCF(TJ,AJ,19) WCF(TK,AK,20) }while(0) #endif #endif /* MAX_PREPRO_ARGS */ #if MAX_PREPRO_ARGS>31 #define CCALLSFSUB21(UN,LN,T1,T2,T3,T4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F(TR,AR,27) }while(0) #endif #endif /* MAX_PREPRO_ARGS */ /*-------------------------------------------------------------------------*/ /* UTILITIES FOR C TO CALL FORTRAN FUNCTIONS */ /*N.B. PROTOCCALLSFFUNn(..) generates code, whether or not the FORTRAN function is called. Therefore, especially for creator's of C header files for large FORTRAN libraries which include many functions, to reduce compile time and object code size, it may be desirable to create preprocessor directives to allow users to create code for only those functions which they use. */ /* The following defines the maximum length string that a function can return. Of course it may be undefine-d and re-define-d before individual PROTOCCALLSFFUNn(..) as required. It would also be nice to have this derived from the individual machines' limits. */ #define MAX_LEN_FORTRAN_FUNCTION_STRING 0x4FE /* The following defines a character used by CFORTRAN.H to flag the end of a string coming out of a FORTRAN routine. */ #define CFORTRAN_NON_CHAR 0x7F #ifdef OLD_VAXC /* Prevent %CC-I-PARAMNOTUSED. */ #pragma nostandard #endif #define _SEP_(TN,C,cfCOMMA) _(__SEP_,C)(TN,cfCOMMA) #define __SEP_0(TN,cfCOMMA) #define __SEP_1(TN,cfCOMMA) _Icf(2,SEP,TN,cfCOMMA,0) #define INT_cfSEP(T,B) _(A,B) #define INTV_cfSEP(T,B) INT_cfSEP(T,B) #define INTVV_cfSEP(T,B) INT_cfSEP(T,B) #define INTVVV_cfSEP(T,B) INT_cfSEP(T,B) #define INTVVVV_cfSEP(T,B) INT_cfSEP(T,B) #define INTVVVVV_cfSEP(T,B) INT_cfSEP(T,B) #define INTVVVVVV_cfSEP(T,B) INT_cfSEP(T,B) #define INTVVVVVVV_cfSEP(T,B) INT_cfSEP(T,B) #define PINT_cfSEP(T,B) INT_cfSEP(T,B) #define PVOID_cfSEP(T,B) INT_cfSEP(T,B) #define ROUTINE_cfSEP(T,B) INT_cfSEP(T,B) #define SIMPLE_cfSEP(T,B) INT_cfSEP(T,B) #define VOID_cfSEP(T,B) INT_cfSEP(T,B) /* For FORTRAN calls C subr.s.*/ #define STRING_cfSEP(T,B) INT_cfSEP(T,B) #define STRINGV_cfSEP(T,B) INT_cfSEP(T,B) #define PSTRING_cfSEP(T,B) INT_cfSEP(T,B) #define PSTRINGV_cfSEP(T,B) INT_cfSEP(T,B) #define PNSTRING_cfSEP(T,B) INT_cfSEP(T,B) #define PPSTRING_cfSEP(T,B) INT_cfSEP(T,B) #define ZTRINGV_cfSEP(T,B) INT_cfSEP(T,B) #define PZTRINGV_cfSEP(T,B) INT_cfSEP(T,B) #if defined(SIGNED_BYTE) || !defined(UNSIGNED_BYTE) #ifdef OLD_VAXC #define INTEGER_BYTE char /* Old VAXC barfs on 'signed char' */ #else #define INTEGER_BYTE signed char /* default */ #endif #else #define INTEGER_BYTE unsigned char #endif #define BYTEVVVVVVV_cfTYPE INTEGER_BYTE #define DOUBLEVVVVVVV_cfTYPE DOUBLE_PRECISION #define FLOATVVVVVVV_cfTYPE FORTRAN_REAL #define INTVVVVVVV_cfTYPE int #define LOGICALVVVVVVV_cfTYPE int #define LONGVVVVVVV_cfTYPE long #define SHORTVVVVVVV_cfTYPE short #define PBYTE_cfTYPE INTEGER_BYTE #define PDOUBLE_cfTYPE DOUBLE_PRECISION #define PFLOAT_cfTYPE FORTRAN_REAL #define PINT_cfTYPE int #define PLOGICAL_cfTYPE int #define PLONG_cfTYPE long #define PSHORT_cfTYPE short #define CFARGS0(A,T,V,W,X,Y,Z) _3(T,_cf,A) #define CFARGS1(A,T,V,W,X,Y,Z) _3(T,_cf,A)(V) #define CFARGS2(A,T,V,W,X,Y,Z) _3(T,_cf,A)(V,W) #define CFARGS3(A,T,V,W,X,Y,Z) _3(T,_cf,A)(V,W,X) #define CFARGS4(A,T,V,W,X,Y,Z) _3(T,_cf,A)(V,W,X,Y) #define CFARGS5(A,T,V,W,X,Y,Z) _3(T,_cf,A)(V,W,X,Y,Z) #define _Icf(N,T,I,X,Y) _(I,_cfINT)(N,T,I,X,Y,0) #define _Icf4(N,T,I,X,Y,Z) _(I,_cfINT)(N,T,I,X,Y,Z) #define BYTE_cfINT(N,A,B,X,Y,Z) DOUBLE_cfINT(N,A,B,X,Y,Z) #define DOUBLE_cfINT(N,A,B,X,Y,Z) _(CFARGS,N)(A,INT,B,X,Y,Z,0) #define FLOAT_cfINT(N,A,B,X,Y,Z) DOUBLE_cfINT(N,A,B,X,Y,Z) #define INT_cfINT(N,A,B,X,Y,Z) DOUBLE_cfINT(N,A,B,X,Y,Z) #define LOGICAL_cfINT(N,A,B,X,Y,Z) DOUBLE_cfINT(N,A,B,X,Y,Z) #define LONG_cfINT(N,A,B,X,Y,Z) DOUBLE_cfINT(N,A,B,X,Y,Z) #define SHORT_cfINT(N,A,B,X,Y,Z) DOUBLE_cfINT(N,A,B,X,Y,Z) #define PBYTE_cfINT(N,A,B,X,Y,Z) PDOUBLE_cfINT(N,A,B,X,Y,Z) #define PDOUBLE_cfINT(N,A,B,X,Y,Z) _(CFARGS,N)(A,PINT,B,X,Y,Z,0) #define PFLOAT_cfINT(N,A,B,X,Y,Z) PDOUBLE_cfINT(N,A,B,X,Y,Z) #define PINT_cfINT(N,A,B,X,Y,Z) PDOUBLE_cfINT(N,A,B,X,Y,Z) #define PLOGICAL_cfINT(N,A,B,X,Y,Z) PDOUBLE_cfINT(N,A,B,X,Y,Z) #define PLONG_cfINT(N,A,B,X,Y,Z) PDOUBLE_cfINT(N,A,B,X,Y,Z) #define PSHORT_cfINT(N,A,B,X,Y,Z) PDOUBLE_cfINT(N,A,B,X,Y,Z) #define BYTEV_cfINT(N,A,B,X,Y,Z) DOUBLEV_cfINT(N,A,B,X,Y,Z) #define BYTEVV_cfINT(N,A,B,X,Y,Z) DOUBLEVV_cfINT(N,A,B,X,Y,Z) #define BYTEVVV_cfINT(N,A,B,X,Y,Z) DOUBLEVVV_cfINT(N,A,B,X,Y,Z) #define BYTEVVVV_cfINT(N,A,B,X,Y,Z) DOUBLEVVVV_cfINT(N,A,B,X,Y,Z) #define BYTEVVVVV_cfINT(N,A,B,X,Y,Z) DOUBLEVVVVV_cfINT(N,A,B,X,Y,Z) #define BYTEVVVVVV_cfINT(N,A,B,X,Y,Z) DOUBLEVVVVVV_cfINT(N,A,B,X,Y,Z) #define BYTEVVVVVVV_cfINT(N,A,B,X,Y,Z) DOUBLEVVVVVVV_cfINT(N,A,B,X,Y,Z) #define DOUBLEV_cfINT(N,A,B,X,Y,Z) _(CFARGS,N)(A,INTV,B,X,Y,Z,0) #define DOUBLEVV_cfINT(N,A,B,X,Y,Z) _(CFARGS,N)(A,INTVV,B,X,Y,Z,0) #define DOUBLEVVV_cfINT(N,A,B,X,Y,Z) _(CFARGS,N)(A,INTVVV,B,X,Y,Z,0) #define DOUBLEVVVV_cfINT(N,A,B,X,Y,Z) _(CFARGS,N)(A,INTVVVV,B,X,Y,Z,0) #define DOUBLEVVVVV_cfINT(N,A,B,X,Y,Z) _(CFARGS,N)(A,INTVVVVV,B,X,Y,Z,0) #define DOUBLEVVVVVV_cfINT(N,A,B,X,Y,Z) _(CFARGS,N)(A,INTVVVVVV,B,X,Y,Z,0) #define DOUBLEVVVVVVV_cfINT(N,A,B,X,Y,Z) _(CFARGS,N)(A,INTVVVVVVV,B,X,Y,Z,0) #define FLOATV_cfINT(N,A,B,X,Y,Z) DOUBLEV_cfINT(N,A,B,X,Y,Z) #define FLOATVV_cfINT(N,A,B,X,Y,Z) DOUBLEVV_cfINT(N,A,B,X,Y,Z) #define FLOATVVV_cfINT(N,A,B,X,Y,Z) DOUBLEVVV_cfINT(N,A,B,X,Y,Z) #define FLOATVVVV_cfINT(N,A,B,X,Y,Z) DOUBLEVVVV_cfINT(N,A,B,X,Y,Z) #define FLOATVVVVV_cfINT(N,A,B,X,Y,Z) DOUBLEVVVVV_cfINT(N,A,B,X,Y,Z) #define FLOATVVVVVV_cfINT(N,A,B,X,Y,Z) DOUBLEVVVVVV_cfINT(N,A,B,X,Y,Z) #define FLOATVVVVVVV_cfINT(N,A,B,X,Y,Z) DOUBLEVVVVVVV_cfINT(N,A,B,X,Y,Z) #define INTV_cfINT(N,A,B,X,Y,Z) DOUBLEV_cfINT(N,A,B,X,Y,Z) #define INTVV_cfINT(N,A,B,X,Y,Z) DOUBLEVV_cfINT(N,A,B,X,Y,Z) #define INTVVV_cfINT(N,A,B,X,Y,Z) DOUBLEVVV_cfINT(N,A,B,X,Y,Z) #define INTVVVV_cfINT(N,A,B,X,Y,Z) DOUBLEVVVV_cfINT(N,A,B,X,Y,Z) #define INTVVVVV_cfINT(N,A,B,X,Y,Z) DOUBLEVVVVV_cfINT(N,A,B,X,Y,Z) #define INTVVVVVV_cfINT(N,A,B,X,Y,Z) DOUBLEVVVVVV_cfINT(N,A,B,X,Y,Z) #define INTVVVVVVV_cfINT(N,A,B,X,Y,Z) DOUBLEVVVVVVV_cfINT(N,A,B,X,Y,Z) #define LOGICALV_cfINT(N,A,B,X,Y,Z) DOUBLEV_cfINT(N,A,B,X,Y,Z) #define LOGICALVV_cfINT(N,A,B,X,Y,Z) DOUBLEVV_cfINT(N,A,B,X,Y,Z) #define LOGICALVVV_cfINT(N,A,B,X,Y,Z) DOUBLEVVV_cfINT(N,A,B,X,Y,Z) #define LOGICALVVVV_cfINT(N,A,B,X,Y,Z) DOUBLEVVVV_cfINT(N,A,B,X,Y,Z) #define LOGICALVVVVV_cfINT(N,A,B,X,Y,Z) DOUBLEVVVVV_cfINT(N,A,B,X,Y,Z) #define LOGICALVVVVVV_cfINT(N,A,B,X,Y,Z) DOUBLEVVVVVV_cfINT(N,A,B,X,Y,Z) #define LOGICALVVVVVVV_cfINT(N,A,B,X,Y,Z) DOUBLEVVVVVVV_cfINT(N,A,B,X,Y,Z) #define LONGV_cfINT(N,A,B,X,Y,Z) DOUBLEV_cfINT(N,A,B,X,Y,Z) #define LONGVV_cfINT(N,A,B,X,Y,Z) DOUBLEVV_cfINT(N,A,B,X,Y,Z) #define LONGVVV_cfINT(N,A,B,X,Y,Z) DOUBLEVVV_cfINT(N,A,B,X,Y,Z) #define LONGVVVV_cfINT(N,A,B,X,Y,Z) DOUBLEVVVV_cfINT(N,A,B,X,Y,Z) #define LONGVVVVV_cfINT(N,A,B,X,Y,Z) DOUBLEVVVVV_cfINT(N,A,B,X,Y,Z) #define LONGVVVVVV_cfINT(N,A,B,X,Y,Z) DOUBLEVVVVVV_cfINT(N,A,B,X,Y,Z) #define LONGVVVVVVV_cfINT(N,A,B,X,Y,Z) DOUBLEVVVVVVV_cfINT(N,A,B,X,Y,Z) #define SHORTV_cfINT(N,A,B,X,Y,Z) DOUBLEV_cfINT(N,A,B,X,Y,Z) #define SHORTVV_cfINT(N,A,B,X,Y,Z) DOUBLEVV_cfINT(N,A,B,X,Y,Z) #define SHORTVVV_cfINT(N,A,B,X,Y,Z) DOUBLEVVV_cfINT(N,A,B,X,Y,Z) #define SHORTVVVV_cfINT(N,A,B,X,Y,Z) DOUBLEVVVV_cfINT(N,A,B,X,Y,Z) #define SHORTVVVVV_cfINT(N,A,B,X,Y,Z) DOUBLEVVVVV_cfINT(N,A,B,X,Y,Z) #define SHORTVVVVVV_cfINT(N,A,B,X,Y,Z) DOUBLEVVVVVV_cfINT(N,A,B,X,Y,Z) #define SHORTVVVVVVV_cfINT(N,A,B,X,Y,Z) DOUBLEVVVVVVV_cfINT(N,A,B,X,Y,Z) #define PVOID_cfINT(N,A,B,X,Y,Z) _(CFARGS,N)(A,B,B,X,Y,Z,0) #define ROUTINE_cfINT(N,A,B,X,Y,Z) PVOID_cfINT(N,A,B,X,Y,Z) /*CRAY coughs on the first, i.e. the usual trouble of not being able to define macros to macros with arguments. New ultrix is worse, it coughs on all such uses. */ /*#define SIMPLE_cfINT PVOID_cfINT*/ #define SIMPLE_cfINT(N,A,B,X,Y,Z) PVOID_cfINT(N,A,B,X,Y,Z) #define VOID_cfINT(N,A,B,X,Y,Z) PVOID_cfINT(N,A,B,X,Y,Z) #define STRING_cfINT(N,A,B,X,Y,Z) PVOID_cfINT(N,A,B,X,Y,Z) #define STRINGV_cfINT(N,A,B,X,Y,Z) PVOID_cfINT(N,A,B,X,Y,Z) #define PSTRING_cfINT(N,A,B,X,Y,Z) PVOID_cfINT(N,A,B,X,Y,Z) #define PSTRINGV_cfINT(N,A,B,X,Y,Z) PVOID_cfINT(N,A,B,X,Y,Z) #define PNSTRING_cfINT(N,A,B,X,Y,Z) PVOID_cfINT(N,A,B,X,Y,Z) #define PPSTRING_cfINT(N,A,B,X,Y,Z) PVOID_cfINT(N,A,B,X,Y,Z) #define ZTRINGV_cfINT(N,A,B,X,Y,Z) PVOID_cfINT(N,A,B,X,Y,Z) #define PZTRINGV_cfINT(N,A,B,X,Y,Z) PVOID_cfINT(N,A,B,X,Y,Z) #define CF_0_cfINT(N,A,B,X,Y,Z) #define UCF(TN,I,C) _SEP_(TN,C,cfCOMMA) _Icf(2,U,TN,_(A,I),0) #define UUCF(TN,I,C) _SEP_(TN,C,cfCOMMA) _SEP_(TN,1,I) #define UUUCF(TN,I,C) _SEP_(TN,C,cfCOLON) _Icf(2,U,TN,_(A,I),0) #define INT_cfU(T,A) _(T,VVVVVVV_cfTYPE) A #define INTV_cfU(T,A) _(T,VVVVVV_cfTYPE) * A #define INTVV_cfU(T,A) _(T,VVVVV_cfTYPE) * A #define INTVVV_cfU(T,A) _(T,VVVV_cfTYPE) * A #define INTVVVV_cfU(T,A) _(T,VVV_cfTYPE) * A #define INTVVVVV_cfU(T,A) _(T,VV_cfTYPE) * A #define INTVVVVVV_cfU(T,A) _(T,V_cfTYPE) * A #define INTVVVVVVV_cfU(T,A) _(T,_cfTYPE) * A #define PINT_cfU(T,A) _(T,_cfTYPE) * A #define PVOID_cfU(T,A) void *A #define ROUTINE_cfU(T,A) void (*A)(CF_NULL_PROTO) #define VOID_cfU(T,A) void A /* Needed for C calls FORTRAN sub.s. */ #define STRING_cfU(T,A) char *A /* via VOID and wrapper. */ #define STRINGV_cfU(T,A) char *A #define PSTRING_cfU(T,A) char *A #define PSTRINGV_cfU(T,A) char *A #define ZTRINGV_cfU(T,A) char *A #define PZTRINGV_cfU(T,A) char *A /* VOID breaks U into U and UU. */ #define INT_cfUU(T,A) _(T,VVVVVVV_cfTYPE) A #define VOID_cfUU(T,A) /* Needed for FORTRAN calls C sub.s. */ #define STRING_cfUU(T,A) char *A #define BYTE_cfPU(A) CFextern INTEGER_BYTE FCALLSC_QUALIFIER A #define DOUBLE_cfPU(A) CFextern DOUBLE_PRECISION FCALLSC_QUALIFIER A #if ! (defined(FLOATFUNCTIONTYPE)&&defined(ASSIGNFLOAT)&&defined(RETURNFLOAT)) #define FLOAT_cfPU(A) CFextern FORTRAN_REAL FCALLSC_QUALIFIER A #else #define FLOAT_cfPU(A) CFextern FLOATFUNCTIONTYPE FCALLSC_QUALIFIER A #endif #define INT_cfPU(A) CFextern int FCALLSC_QUALIFIER A #define LOGICAL_cfPU(A) CFextern int FCALLSC_QUALIFIER A #define LONG_cfPU(A) CFextern long FCALLSC_QUALIFIER A #define SHORT_cfPU(A) CFextern short FCALLSC_QUALIFIER A #define STRING_cfPU(A) CFextern void FCALLSC_QUALIFIER A #define VOID_cfPU(A) CFextern void FCALLSC_QUALIFIER A #define BYTE_cfE INTEGER_BYTE A0; #define DOUBLE_cfE DOUBLE_PRECISION A0; #if ! (defined(FLOATFUNCTIONTYPE)&&defined(ASSIGNFLOAT)&&defined(RETURNFLOAT)) #define FLOAT_cfE FORTRAN_REAL A0; #else #define FLOAT_cfE FORTRAN_REAL AA0; FLOATFUNCTIONTYPE A0; #endif #define INT_cfE int A0; #define LOGICAL_cfE int A0; #define LONG_cfE long A0; #define SHORT_cfE short A0; #define VOID_cfE #ifdef vmsFortran #define STRING_cfE static char AA0[1+MAX_LEN_FORTRAN_FUNCTION_STRING]; \ static fstring A0 = \ {MAX_LEN_FORTRAN_FUNCTION_STRING,DSC$K_DTYPE_T,DSC$K_CLASS_S,AA0};\ memset(AA0, CFORTRAN_NON_CHAR, MAX_LEN_FORTRAN_FUNCTION_STRING);\ *(AA0+MAX_LEN_FORTRAN_FUNCTION_STRING)='\0'; #else #ifdef CRAYFortran #define STRING_cfE static char AA0[1+MAX_LEN_FORTRAN_FUNCTION_STRING]; \ static _fcd A0; *(AA0+MAX_LEN_FORTRAN_FUNCTION_STRING)='\0';\ memset(AA0,CFORTRAN_NON_CHAR, MAX_LEN_FORTRAN_FUNCTION_STRING);\ A0 = _cptofcd(AA0,MAX_LEN_FORTRAN_FUNCTION_STRING); #else /* 'cc: SC3.0.1 13 Jul 1994' barfs on char A0[0x4FE+1]; * char A0[0x4FE +1]; char A0[1+0x4FE]; are both OK. */ #define STRING_cfE static char A0[1+MAX_LEN_FORTRAN_FUNCTION_STRING]; \ memset(A0, CFORTRAN_NON_CHAR, \ MAX_LEN_FORTRAN_FUNCTION_STRING); \ *(A0+MAX_LEN_FORTRAN_FUNCTION_STRING)='\0'; #endif #endif /* ESTRING must use static char. array which is guaranteed to exist after function returns. */ /* N.B.i) The diff. for 0 (Zero) and >=1 arguments. ii)That the following create an unmatched bracket, i.e. '(', which must of course be matched in the call. iii)Commas must be handled very carefully */ #define INT_cfGZ(T,UN,LN) A0=CFC_(UN,LN)( #define VOID_cfGZ(T,UN,LN) CFC_(UN,LN)( #ifdef vmsFortran #define STRING_cfGZ(T,UN,LN) CFC_(UN,LN)(&A0 #else #if defined(CRAYFortran) || defined(AbsoftUNIXFortran) || defined(AbsoftProFortran) #define STRING_cfGZ(T,UN,LN) CFC_(UN,LN)( A0 #else #define STRING_cfGZ(T,UN,LN) CFC_(UN,LN)( A0,MAX_LEN_FORTRAN_FUNCTION_STRING #endif #endif #define INT_cfG(T,UN,LN) INT_cfGZ(T,UN,LN) #define VOID_cfG(T,UN,LN) VOID_cfGZ(T,UN,LN) #define STRING_cfG(T,UN,LN) STRING_cfGZ(T,UN,LN), /*, is only diff. from _cfG*/ #define BYTEVVVVVVV_cfPP #define INTVVVVVVV_cfPP /* These complement FLOATVVVVVVV_cfPP. */ #define DOUBLEVVVVVVV_cfPP #define LOGICALVVVVVVV_cfPP #define LONGVVVVVVV_cfPP #define SHORTVVVVVVV_cfPP #define PBYTE_cfPP #define PINT_cfPP #define PDOUBLE_cfPP #define PLOGICAL_cfPP #define PLONG_cfPP #define PSHORT_cfPP #define PFLOAT_cfPP FLOATVVVVVVV_cfPP #define BCF(TN,AN,C) _SEP_(TN,C,cfCOMMA) _Icf(2,B,TN,AN,0) #define INT_cfB(T,A) (_(T,VVVVVVV_cfTYPE)) A #define INTV_cfB(T,A) A #define INTVV_cfB(T,A) (A)[0] #define INTVVV_cfB(T,A) (A)[0][0] #define INTVVVV_cfB(T,A) (A)[0][0][0] #define INTVVVVV_cfB(T,A) (A)[0][0][0][0] #define INTVVVVVV_cfB(T,A) (A)[0][0][0][0][0] #define INTVVVVVVV_cfB(T,A) (A)[0][0][0][0][0][0] #define PINT_cfB(T,A) _(T,_cfPP)&A #define STRING_cfB(T,A) (char *) A #define STRINGV_cfB(T,A) (char *) A #define PSTRING_cfB(T,A) (char *) A #define PSTRINGV_cfB(T,A) (char *) A #define PVOID_cfB(T,A) (void *) A #define ROUTINE_cfB(T,A) (cfCAST_FUNCTION)A #define ZTRINGV_cfB(T,A) (char *) A #define PZTRINGV_cfB(T,A) (char *) A #define SCF(TN,NAME,I,A) _(TN,_cfSTR)(3,S,NAME,I,A,0,0) #define DEFAULT_cfS(M,I,A) #define LOGICAL_cfS(M,I,A) #define PLOGICAL_cfS(M,I,A) #define STRING_cfS(M,I,A) ,sizeof(A) #define STRINGV_cfS(M,I,A) ,( (unsigned)0xFFFF*firstindexlength(A) \ +secondindexlength(A)) #define PSTRING_cfS(M,I,A) ,sizeof(A) #define PSTRINGV_cfS(M,I,A) STRINGV_cfS(M,I,A) #define ZTRINGV_cfS(M,I,A) #define PZTRINGV_cfS(M,I,A) #define HCF(TN,I) _(TN,_cfSTR)(3,H,cfCOMMA, H,_(C,I),0,0) #define HHCF(TN,I) _(TN,_cfSTR)(3,H,cfCOMMA,HH,_(C,I),0,0) #define HHHCF(TN,I) _(TN,_cfSTR)(3,H,cfCOLON, H,_(C,I),0,0) #define H_CF_SPECIAL unsigned #define HH_CF_SPECIAL #define DEFAULT_cfH(M,I,A) #define LOGICAL_cfH(S,U,B) #define PLOGICAL_cfH(S,U,B) #define STRING_cfH(S,U,B) _(A,S) _(U,_CF_SPECIAL) B #define STRINGV_cfH(S,U,B) STRING_cfH(S,U,B) #define PSTRING_cfH(S,U,B) STRING_cfH(S,U,B) #define PSTRINGV_cfH(S,U,B) STRING_cfH(S,U,B) #define PNSTRING_cfH(S,U,B) STRING_cfH(S,U,B) #define PPSTRING_cfH(S,U,B) STRING_cfH(S,U,B) #define ZTRINGV_cfH(S,U,B) #define PZTRINGV_cfH(S,U,B) /* Need VOID_cfSTR because Absoft forced function types go through _cfSTR. */ /* No spaces inside expansion. They screws up macro catenation kludge. */ #define VOID_cfSTR(N,T,A,B,C,D,E) _(CFARGS,N)(T,DEFAULT,A,B,C,D,E) #define BYTE_cfSTR(N,T,A,B,C,D,E) _(CFARGS,N)(T,DEFAULT,A,B,C,D,E) #define DOUBLE_cfSTR(N,T,A,B,C,D,E) _(CFARGS,N)(T,DEFAULT,A,B,C,D,E) #define FLOAT_cfSTR(N,T,A,B,C,D,E) _(CFARGS,N)(T,DEFAULT,A,B,C,D,E) #define INT_cfSTR(N,T,A,B,C,D,E) _(CFARGS,N)(T,DEFAULT,A,B,C,D,E) #define LOGICAL_cfSTR(N,T,A,B,C,D,E) _(CFARGS,N)(T,LOGICAL,A,B,C,D,E) #define LONG_cfSTR(N,T,A,B,C,D,E) _(CFARGS,N)(T,DEFAULT,A,B,C,D,E) #define SHORT_cfSTR(N,T,A,B,C,D,E) _(CFARGS,N)(T,DEFAULT,A,B,C,D,E) #define BYTEV_cfSTR(N,T,A,B,C,D,E) _(CFARGS,N)(T,DEFAULT,A,B,C,D,E) #define BYTEVV_cfSTR(N,T,A,B,C,D,E) _(CFARGS,N)(T,DEFAULT,A,B,C,D,E) #define BYTEVVV_cfSTR(N,T,A,B,C,D,E) _(CFARGS,N)(T,DEFAULT,A,B,C,D,E) #define BYTEVVVV_cfSTR(N,T,A,B,C,D,E) _(CFARGS,N)(T,DEFAULT,A,B,C,D,E) #define BYTEVVVVV_cfSTR(N,T,A,B,C,D,E) _(CFARGS,N)(T,DEFAULT,A,B,C,D,E) #define BYTEVVVVVV_cfSTR(N,T,A,B,C,D,E) _(CFARGS,N)(T,DEFAULT,A,B,C,D,E) #define BYTEVVVVVVV_cfSTR(N,T,A,B,C,D,E) _(CFARGS,N)(T,DEFAULT,A,B,C,D,E) #define DOUBLEV_cfSTR(N,T,A,B,C,D,E) _(CFARGS,N)(T,DEFAULT,A,B,C,D,E) #define DOUBLEVV_cfSTR(N,T,A,B,C,D,E) _(CFARGS,N)(T,DEFAULT,A,B,C,D,E) #define DOUBLEVVV_cfSTR(N,T,A,B,C,D,E) _(CFARGS,N)(T,DEFAULT,A,B,C,D,E) #define DOUBLEVVVV_cfSTR(N,T,A,B,C,D,E) _(CFARGS,N)(T,DEFAULT,A,B,C,D,E) #define DOUBLEVVVVV_cfSTR(N,T,A,B,C,D,E) _(CFARGS,N)(T,DEFAULT,A,B,C,D,E) #define DOUBLEVVVVVV_cfSTR(N,T,A,B,C,D,E) _(CFARGS,N)(T,DEFAULT,A,B,C,D,E) #define DOUBLEVVVVVVV_cfSTR(N,T,A,B,C,D,E) _(CFARGS,N)(T,DEFAULT,A,B,C,D,E) #define FLOATV_cfSTR(N,T,A,B,C,D,E) _(CFARGS,N)(T,DEFAULT,A,B,C,D,E) #define FLOATVV_cfSTR(N,T,A,B,C,D,E) _(CFARGS,N)(T,DEFAULT,A,B,C,D,E) #define FLOATVVV_cfSTR(N,T,A,B,C,D,E) _(CFARGS,N)(T,DEFAULT,A,B,C,D,E) #define FLOATVVVV_cfSTR(N,T,A,B,C,D,E) _(CFARGS,N)(T,DEFAULT,A,B,C,D,E) #define FLOATVVVVV_cfSTR(N,T,A,B,C,D,E) _(CFARGS,N)(T,DEFAULT,A,B,C,D,E) #define FLOATVVVVVV_cfSTR(N,T,A,B,C,D,E) _(CFARGS,N)(T,DEFAULT,A,B,C,D,E) #define FLOATVVVVVVV_cfSTR(N,T,A,B,C,D,E) _(CFARGS,N)(T,DEFAULT,A,B,C,D,E) #define INTV_cfSTR(N,T,A,B,C,D,E) _(CFARGS,N)(T,DEFAULT,A,B,C,D,E) #define INTVV_cfSTR(N,T,A,B,C,D,E) _(CFARGS,N)(T,DEFAULT,A,B,C,D,E) #define INTVVV_cfSTR(N,T,A,B,C,D,E) _(CFARGS,N)(T,DEFAULT,A,B,C,D,E) #define INTVVVV_cfSTR(N,T,A,B,C,D,E) _(CFARGS,N)(T,DEFAULT,A,B,C,D,E) #define INTVVVVV_cfSTR(N,T,A,B,C,D,E) _(CFARGS,N)(T,DEFAULT,A,B,C,D,E) #define INTVVVVVV_cfSTR(N,T,A,B,C,D,E) _(CFARGS,N)(T,DEFAULT,A,B,C,D,E) #define INTVVVVVVV_cfSTR(N,T,A,B,C,D,E) _(CFARGS,N)(T,DEFAULT,A,B,C,D,E) #define LOGICALV_cfSTR(N,T,A,B,C,D,E) _(CFARGS,N)(T,DEFAULT,A,B,C,D,E) #define LOGICALVV_cfSTR(N,T,A,B,C,D,E) _(CFARGS,N)(T,DEFAULT,A,B,C,D,E) #define LOGICALVVV_cfSTR(N,T,A,B,C,D,E) _(CFARGS,N)(T,DEFAULT,A,B,C,D,E) #define LOGICALVVVV_cfSTR(N,T,A,B,C,D,E) _(CFARGS,N)(T,DEFAULT,A,B,C,D,E) #define LOGICALVVVVV_cfSTR(N,T,A,B,C,D,E) _(CFARGS,N)(T,DEFAULT,A,B,C,D,E) #define LOGICALVVVVVV_cfSTR(N,T,A,B,C,D,E) _(CFARGS,N)(T,DEFAULT,A,B,C,D,E) #define LOGICALVVVVVVV_cfSTR(N,T,A,B,C,D,E) _(CFARGS,N)(T,DEFAULT,A,B,C,D,E) #define LONGV_cfSTR(N,T,A,B,C,D,E) _(CFARGS,N)(T,DEFAULT,A,B,C,D,E) #define LONGVV_cfSTR(N,T,A,B,C,D,E) _(CFARGS,N)(T,DEFAULT,A,B,C,D,E) #define LONGVVV_cfSTR(N,T,A,B,C,D,E) _(CFARGS,N)(T,DEFAULT,A,B,C,D,E) #define LONGVVVV_cfSTR(N,T,A,B,C,D,E) _(CFARGS,N)(T,DEFAULT,A,B,C,D,E) #define LONGVVVVV_cfSTR(N,T,A,B,C,D,E) _(CFARGS,N)(T,DEFAULT,A,B,C,D,E) #define LONGVVVVVV_cfSTR(N,T,A,B,C,D,E) _(CFARGS,N)(T,DEFAULT,A,B,C,D,E) #define LONGVVVVVVV_cfSTR(N,T,A,B,C,D,E) _(CFARGS,N)(T,DEFAULT,A,B,C,D,E) #define SHORTV_cfSTR(N,T,A,B,C,D,E) _(CFARGS,N)(T,DEFAULT,A,B,C,D,E) #define SHORTVV_cfSTR(N,T,A,B,C,D,E) _(CFARGS,N)(T,DEFAULT,A,B,C,D,E) #define SHORTVVV_cfSTR(N,T,A,B,C,D,E) _(CFARGS,N)(T,DEFAULT,A,B,C,D,E) #define SHORTVVVV_cfSTR(N,T,A,B,C,D,E) _(CFARGS,N)(T,DEFAULT,A,B,C,D,E) #define SHORTVVVVV_cfSTR(N,T,A,B,C,D,E) _(CFARGS,N)(T,DEFAULT,A,B,C,D,E) #define SHORTVVVVVV_cfSTR(N,T,A,B,C,D,E) _(CFARGS,N)(T,DEFAULT,A,B,C,D,E) #define SHORTVVVVVVV_cfSTR(N,T,A,B,C,D,E) _(CFARGS,N)(T,DEFAULT,A,B,C,D,E) #define PBYTE_cfSTR(N,T,A,B,C,D,E) _(CFARGS,N)(T,DEFAULT,A,B,C,D,E) #define PDOUBLE_cfSTR(N,T,A,B,C,D,E) _(CFARGS,N)(T,DEFAULT,A,B,C,D,E) #define PFLOAT_cfSTR(N,T,A,B,C,D,E) _(CFARGS,N)(T,DEFAULT,A,B,C,D,E) #define PINT_cfSTR(N,T,A,B,C,D,E) _(CFARGS,N)(T,DEFAULT,A,B,C,D,E) #define PLOGICAL_cfSTR(N,T,A,B,C,D,E) _(CFARGS,N)(T,PLOGICAL,A,B,C,D,E) #define PLONG_cfSTR(N,T,A,B,C,D,E) _(CFARGS,N)(T,DEFAULT,A,B,C,D,E) #define PSHORT_cfSTR(N,T,A,B,C,D,E) _(CFARGS,N)(T,DEFAULT,A,B,C,D,E) #define STRING_cfSTR(N,T,A,B,C,D,E) _(CFARGS,N)(T,STRING,A,B,C,D,E) #define PSTRING_cfSTR(N,T,A,B,C,D,E) _(CFARGS,N)(T,PSTRING,A,B,C,D,E) #define STRINGV_cfSTR(N,T,A,B,C,D,E) _(CFARGS,N)(T,STRINGV,A,B,C,D,E) #define PSTRINGV_cfSTR(N,T,A,B,C,D,E) _(CFARGS,N)(T,PSTRINGV,A,B,C,D,E) #define PNSTRING_cfSTR(N,T,A,B,C,D,E) _(CFARGS,N)(T,PNSTRING,A,B,C,D,E) #define PPSTRING_cfSTR(N,T,A,B,C,D,E) _(CFARGS,N)(T,PPSTRING,A,B,C,D,E) #define PVOID_cfSTR(N,T,A,B,C,D,E) _(CFARGS,N)(T,DEFAULT,A,B,C,D,E) #define ROUTINE_cfSTR(N,T,A,B,C,D,E) _(CFARGS,N)(T,DEFAULT,A,B,C,D,E) #define SIMPLE_cfSTR(N,T,A,B,C,D,E) _(CFARGS,N)(T,DEFAULT,A,B,C,D,E) #define ZTRINGV_cfSTR(N,T,A,B,C,D,E) _(CFARGS,N)(T,ZTRINGV,A,B,C,D,E) #define PZTRINGV_cfSTR(N,T,A,B,C,D,E) _(CFARGS,N)(T,PZTRINGV,A,B,C,D,E) #define CF_0_cfSTR(N,T,A,B,C,D,E) /* See ACF table comments, which explain why CCF was split into two. */ #define CCF(NAME,TN,I) _(TN,_cfSTR)(5,C,NAME,I,_(A,I),_(B,I),_(C,I)) #define DEFAULT_cfC(M,I,A,B,C) #define LOGICAL_cfC(M,I,A,B,C) A=C2FLOGICAL( A); #define PLOGICAL_cfC(M,I,A,B,C) *A=C2FLOGICAL(*A); #ifdef vmsFortran #define STRING_cfC(M,I,A,B,C) (B.clen=strlen(A),B.f.dsc$a_pointer=A, \ C==sizeof(char*)||C==(unsigned)(B.clen+1)?B.f.dsc$w_length=B.clen: \ (memset((A)+B.clen,' ',C-B.clen-1),A[B.f.dsc$w_length=C-1]='\0')); /* PSTRING_cfC to beware of array A which does not contain any \0. */ #define PSTRING_cfC(M,I,A,B,C) (B.dsc$a_pointer=A, C==sizeof(char*) ? \ B.dsc$w_length=strlen(A): (A[C-1]='\0',B.dsc$w_length=strlen(A), \ memset((A)+B.dsc$w_length,' ',C-B.dsc$w_length-1), B.dsc$w_length=C-1)); #else #define STRING_cfC(M,I,A,B,C) (B.nombre=A,B.clen=strlen(A), \ C==sizeof(char*)||C==(unsigned)(B.clen+1)?B.flen=B.clen: \ (memset(B.nombre+B.clen,' ',C-B.clen-1),B.nombre[B.flen=C-1]='\0')); #define PSTRING_cfC(M,I,A,B,C) (C==sizeof(char*)? B=strlen(A): \ (A[C-1]='\0',B=strlen(A),memset((A)+B,' ',C-B-1),B=C-1)); #endif /* For CRAYFortran for (P)STRINGV_cfC, B.fs is set, but irrelevant. */ #define STRINGV_cfC(M,I,A,B,C) \ AATRINGV_cfA( A,B,(C/0xFFFF)*(C%0xFFFF),C/0xFFFF,C%0xFFFF) #define PSTRINGV_cfC(M,I,A,B,C) \ APATRINGV_cfA( A,B,(C/0xFFFF)*(C%0xFFFF),C/0xFFFF,C%0xFFFF) #define ZTRINGV_cfC(M,I,A,B,C) \ AATRINGV_cfA( A,B, (_3(M,_ELEMS_,I))*((_3(M,_ELEMLEN_,I))+1), \ (_3(M,_ELEMS_,I)), (_3(M,_ELEMLEN_,I))+1 ) #define PZTRINGV_cfC(M,I,A,B,C) \ APATRINGV_cfA( A,B, (_3(M,_ELEMS_,I))*((_3(M,_ELEMLEN_,I))+1), \ (_3(M,_ELEMS_,I)), (_3(M,_ELEMLEN_,I))+1 ) #define BYTE_cfCCC(A,B) &A #define DOUBLE_cfCCC(A,B) &A #if !defined(__CF__KnR) #define FLOAT_cfCCC(A,B) &A /* Although the VAX doesn't, at least the */ #else /* HP and K&R mips promote float arg.'s of */ #define FLOAT_cfCCC(A,B) &B /* unprototyped functions to double. Cannot */ #endif /* use A here to pass the argument to FORTRAN. */ #define INT_cfCCC(A,B) &A #define LOGICAL_cfCCC(A,B) &A #define LONG_cfCCC(A,B) &A #define SHORT_cfCCC(A,B) &A #define PBYTE_cfCCC(A,B) A #define PDOUBLE_cfCCC(A,B) A #define PFLOAT_cfCCC(A,B) A #define PINT_cfCCC(A,B) A #define PLOGICAL_cfCCC(A,B) B=A /* B used to keep a common W table. */ #define PLONG_cfCCC(A,B) A #define PSHORT_cfCCC(A,B) A #define CCCF(TN,I,M) _SEP_(TN,M,cfCOMMA) _Icf(3,CC,TN,_(A,I),_(B,I)) #define INT_cfCC(T,A,B) _(T,_cfCCC)(A,B) #define INTV_cfCC(T,A,B) A #define INTVV_cfCC(T,A,B) A #define INTVVV_cfCC(T,A,B) A #define INTVVVV_cfCC(T,A,B) A #define INTVVVVV_cfCC(T,A,B) A #define INTVVVVVV_cfCC(T,A,B) A #define INTVVVVVVV_cfCC(T,A,B) A #define PINT_cfCC(T,A,B) _(T,_cfCCC)(A,B) #define PVOID_cfCC(T,A,B) A #if defined(apolloFortran) || defined(hpuxFortran800) || defined(AbsoftUNIXFortran) #define ROUTINE_cfCC(T,A,B) &A #else #define ROUTINE_cfCC(T,A,B) A #endif #define SIMPLE_cfCC(T,A,B) A #ifdef vmsFortran #define STRING_cfCC(T,A,B) &B.f #define STRINGV_cfCC(T,A,B) &B #define PSTRING_cfCC(T,A,B) &B #define PSTRINGV_cfCC(T,A,B) &B #else #ifdef CRAYFortran #define STRING_cfCC(T,A,B) _cptofcd(A,B.flen) #define STRINGV_cfCC(T,A,B) _cptofcd(B.s,B.flen) #define PSTRING_cfCC(T,A,B) _cptofcd(A,B) #define PSTRINGV_cfCC(T,A,B) _cptofcd(A,B.flen) #else #define STRING_cfCC(T,A,B) A #define STRINGV_cfCC(T,A,B) B.fs #define PSTRING_cfCC(T,A,B) A #define PSTRINGV_cfCC(T,A,B) B.fs #endif #endif #define ZTRINGV_cfCC(T,A,B) STRINGV_cfCC(T,A,B) #define PZTRINGV_cfCC(T,A,B) PSTRINGV_cfCC(T,A,B) #define BYTE_cfX return A0; #define DOUBLE_cfX return A0; #if ! (defined(FLOATFUNCTIONTYPE)&&defined(ASSIGNFLOAT)&&defined(RETURNFLOAT)) #define FLOAT_cfX return A0; #else #define FLOAT_cfX ASSIGNFLOAT(AA0,A0); return AA0; #endif #define INT_cfX return A0; #define LOGICAL_cfX return F2CLOGICAL(A0); #define LONG_cfX return A0; #define SHORT_cfX return A0; #define VOID_cfX return ; #if defined(vmsFortran) || defined(CRAYFortran) #define STRING_cfX return kill_trailing( \ kill_trailing(AA0,CFORTRAN_NON_CHAR),' '); #else #define STRING_cfX return kill_trailing( \ kill_trailing( A0,CFORTRAN_NON_CHAR),' '); #endif #define CFFUN(NAME) _(__cf__,NAME) /* Note that we don't use LN here, but we keep it for consistency. */ #define CCALLSFFUN0(UN,LN) CFFUN(UN)() #ifdef OLD_VAXC /* Allow %CC-I-PARAMNOTUSED. */ #pragma standard #endif #define CCALLSFFUN1( UN,LN,T1, A1) \ CCALLSFFUN5 (UN,LN,T1,CF_0,CF_0,CF_0,CF_0,A1,0,0,0,0) #define CCALLSFFUN2( UN,LN,T1,T2, A1,A2) \ CCALLSFFUN5 (UN,LN,T1,T2,CF_0,CF_0,CF_0,A1,A2,0,0,0) #define CCALLSFFUN3( UN,LN,T1,T2,T3, A1,A2,A3) \ CCALLSFFUN5 (UN,LN,T1,T2,T3,CF_0,CF_0,A1,A2,A3,0,0) #define CCALLSFFUN4( UN,LN,T1,T2,T3,T4, A1,A2,A3,A4)\ CCALLSFFUN5 (UN,LN,T1,T2,T3,T4,CF_0,A1,A2,A3,A4,0) #define CCALLSFFUN5( UN,LN,T1,T2,T3,T4,T5, A1,A2,A3,A4,A5) \ CCALLSFFUN10(UN,LN,T1,T2,T3,T4,T5,CF_0,CF_0,CF_0,CF_0,CF_0,A1,A2,A3,A4,A5,0,0,0,0,0) #define CCALLSFF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7,A8,A9,AA,AB,AC)\ CCALLSFFUN14(UN,LN,T1,T2,T3,T4,T5,T6,T7,T8,T9,TA,TB,TC,CF_0,CF_0,A1,A2,A3,A4,A5,A6,A7,A8,A9,AA,AB,AC,0,0) #define CCALLSFFUN13(UN,LN,T1,T2,T3,T4,T5,T6,T7,T8,T9,TA,TB,TC,TD,A1,A2,A3,A4,A5,A6,A7,A8,A9,AA,AB,AC,AD)\ CCALLSFFUN14(UN,LN,T1,T2,T3,T4,T5,T6,T7,T8,T9,TA,TB,TC,TD,CF_0,A1,A2,A3,A4,A5,A6,A7,A8,A9,AA,AB,AC,AD,0) #define CCALLSFFUN14(UN,LN,T1,T2,T3,T4,T5,T6,T7,T8,T9,TA,TB,TC,TD,TE,A1,A2,A3,A4,A5,A6,A7,A8,A9,AA,AB,AC,AD,AE)\ ((CFFUN(UN)( BCF(T1,A1,0) BCF(T2,A2,1) BCF(T3,A3,1) BCF(T4,A4,1) BCF(T5,A5,1) \ BCF(T6,A6,1) BCF(T7,A7,1) BCF(T8,A8,1) BCF(T9,A9,1) BCF(TA,AA,1) \ BCF(TB,AB,1) BCF(TC,AC,1) BCF(TD,AD,1) BCF(TE,AE,1) \ SCF(T1,LN,1,A1) SCF(T2,LN,2,A2) SCF(T3,LN,3,A3) SCF(T4,LN,4,A4) \ SCF(T5,LN,5,A5) SCF(T6,LN,6,A6) SCF(T7,LN,7,A7) SCF(T8,LN,8,A8) \ SCF(T9,LN,9,A9) SCF(TA,LN,10,AA) SCF(TB,LN,11,AB) SCF(TC,LN,12,AC) \ SCF(TD,LN,13,AD) SCF(TE,LN,14,AE)))) /* N.B. Create a separate function instead of using (call function, function value here) because in order to create the variables needed for the input arg.'s which may be const.'s one has to do the creation within {}, but these can never be placed within ()'s. Therefore one must create wrapper functions. gcc, on the other hand may be able to avoid the wrapper functions. */ /* Prototypes are needed to correctly handle the value returned correctly. N.B. Can only have prototype arg.'s with difficulty, a la G... table since FORTRAN functions returning strings have extra arg.'s. Don't bother, since this only causes a compiler warning to come up when one uses FCALLSCFUNn and CCALLSFFUNn for the same function in the same source code. Something done by the experts in debugging only.*/ #define PROTOCCALLSFFUN0(F,UN,LN) \ _(F,_cfPU)( CFC_(UN,LN))(CF_NULL_PROTO); \ static _Icf(2,U,F,CFFUN(UN),0)() {_(F,_cfE) _Icf(3,GZ,F,UN,LN) ABSOFT_cf1(F));_(F,_cfX)} #define PROTOCCALLSFFUN1( T0,UN,LN,T1) \ PROTOCCALLSFFUN5 (T0,UN,LN,T1,CF_0,CF_0,CF_0,CF_0) #define PROTOCCALLSFFUN2( T0,UN,LN,T1,T2) \ PROTOCCALLSFFUN5 (T0,UN,LN,T1,T2,CF_0,CF_0,CF_0) #define PROTOCCALLSFFUN3( T0,UN,LN,T1,T2,T3) \ PROTOCCALLSFFUN5 (T0,UN,LN,T1,T2,T3,CF_0,CF_0) #define PROTOCCALLSFFUN4( T0,UN,LN,T1,T2,T3,T4) \ PROTOCCALLSFFUN5 (T0,UN,LN,T1,T2,T3,T4,CF_0) #define PROTOCCALLSFFUN5( T0,UN,LN,T1,T2,T3,T4,T5) \ PROTOCCALLSFFUN10(T0,UN,LN,T1,T2,T3,T4,T5,CF_0,CF_0,CF_0,CF_0,CF_0) #define PROTOCCALLSFFUN6( T0,UN,LN,T1,T2,T3,T4,T5,T6) \ PROTOCCALLSFFUN10(T0,UN,LN,T1,T2,T3,T4,T5,T6,CF_0,CF_0,CF_0,CF_0) #define PROTOCCALLSFFUN7( T0,UN,LN,T1,T2,T3,T4,T5,T6,T7) \ PROTOCCALLSFFUN10(T0,UN,LN,T1,T2,T3,T4,T5,T6,T7,CF_0,CF_0,CF_0) #define PROTOCCALLSFFUN8( T0,UN,LN,T1,T2,T3,T4,T5,T6,T7,T8) \ PROTOCCALLSFFUN10(T0,UN,LN,T1,T2,T3,T4,T5,T6,T7,T8,CF_0,CF_0) #define PROTOCCALLSFFUN9( T0,UN,LN,T1,T2,T3,T4,T5,T6,T7,T8,T9) \ PROTOCCALLSFFUN10(T0,UN,LN,T1,T2,T3,T4,T5,T6,T7,T8,T9,CF_0) #define PROTOCCALLSFFUN10(T0,UN,LN,T1,T2,T3,T4,T5,T6,T7,T8,T9,TA) \ PROTOCCALLSFFUN14(T0,UN,LN,T1,T2,T3,T4,T5,T6,T7,T8,T9,TA,CF_0,CF_0,CF_0,CF_0) #define PROTOCCALLSFFUN11(T0,UN,LN,T1,T2,T3,T4,T5,T6,T7,T8,T9,TA,TB) \ PROTOCCALLSFFUN14(T0,UN,LN,T1,T2,T3,T4,T5,T6,T7,T8,T9,TA,TB,CF_0,CF_0,CF_0) #define PROTOCCALLSFFUN12(T0,UN,LN,T1,T2,T3,T4,T5,T6,T7,T8,T9,TA,TB,TC) \ PROTOCCALLSFFUN14(T0,UN,LN,T1,T2,T3,T4,T5,T6,T7,T8,T9,TA,TB,TC,CF_0,CF_0) #define PROTOCCALLSFFUN13(T0,UN,LN,T1,T2,T3,T4,T5,T6,T7,T8,T9,TA,TB,TC,TD) \ PROTOCCALLSFFUN14(T0,UN,LN,T1,T2,T3,T4,T5,T6,T7,T8,T9,TA,TB,TC,TD,CF_0) /* HP/UX 9.01 cc requires the blank between '_Icf(3,G,T0,UN,LN) CCCF(T1,1,0)' */ #ifndef __CF__KnR #define PROTOCCALLSFFUN14(T0,UN,LN,T1,T2,T3,T4,T5,T6,T7,T8,T9,TA,TB,TC,TD,TE) \ _(T0,_cfPU)(CFC_(UN,LN))(CF_NULL_PROTO); static _Icf(2,U,T0,CFFUN(UN),0)( \ CFARGT14FS(UCF,HCF,_Z,T1,T2,T3,T4,T5,T6,T7,T8,T9,TA,TB,TC,TD,TE) ) \ { CFARGT14S(VCF,T1,T2,T3,T4,T5,T6,T7,T8,T9,TA,TB,TC,TD,TE) _(T0,_cfE) \ CCF(LN,T1,1) CCF(LN,T2,2) CCF(LN,T3,3) CCF(LN,T4,4) CCF(LN,T5,5) \ CCF(LN,T6,6) CCF(LN,T7,7) CCF(LN,T8,8) CCF(LN,T9,9) CCF(LN,TA,10) \ CCF(LN,TB,11) CCF(LN,TC,12) CCF(LN,TD,13) CCF(LN,TE,14) _Icf(3,G,T0,UN,LN) \ CFARGT14(CCCF,JCF,ABSOFT_cf1(T0),T1,T2,T3,T4,T5,T6,T7,T8,T9,TA,TB,TC,TD,TE)); \ WCF(T1,A1,1) WCF(T2,A2,2) WCF(T3,A3,3) WCF(T4,A4,4) WCF(T5,A5,5) \ WCF(T6,A6,6) WCF(T7,A7,7) WCF(T8,A8,8) WCF(T9,A9,9) WCF(TA,A10,10) \ WCF(TB,A11,11) WCF(TC,A12,12) WCF(TD,A13,13) WCF(TE,A14,14) _(T0,_cfX)} #else #define PROTOCCALLSFFUN14(T0,UN,LN,T1,T2,T3,T4,T5,T6,T7,T8,T9,TA,TB,TC,TD,TE) \ _(T0,_cfPU)(CFC_(UN,LN))(CF_NULL_PROTO); static _Icf(2,U,T0,CFFUN(UN),0)( \ CFARGT14FS(UUCF,HHCF,_Z,T1,T2,T3,T4,T5,T6,T7,T8,T9,TA,TB,TC,TD,TE) ) \ CFARGT14FS(UUUCF,HHHCF,_Z,T1,T2,T3,T4,T5,T6,T7,T8,T9,TA,TB,TC,TD,TE) ; \ { CFARGT14S(VCF,T1,T2,T3,T4,T5,T6,T7,T8,T9,TA,TB,TC,TD,TE) _(T0,_cfE) \ CCF(LN,T1,1) CCF(LN,T2,2) CCF(LN,T3,3) CCF(LN,T4,4) CCF(LN,T5,5) \ CCF(LN,T6,6) CCF(LN,T7,7) CCF(LN,T8,8) CCF(LN,T9,9) CCF(LN,TA,10) \ CCF(LN,TB,11) CCF(LN,TC,12) CCF(LN,TD,13) CCF(LN,TE,14) _Icf(3,G,T0,UN,LN) \ CFARGT14(CCCF,JCF,ABSOFT_cf1(T0),T1,T2,T3,T4,T5,T6,T7,T8,T9,TA,TB,TC,TD,TE)); \ WCF(T1,A1,1) WCF(T2,A2,2) WCF(T3,A3,3) WCF(T4,A4,4) WCF(T5,A5,5) \ WCF(T6,A6,6) WCF(T7,A7,7) WCF(T8,A8,8) WCF(T9,A9,9) WCF(TA,A10,10) \ WCF(TB,A11,11) WCF(TC,A12,12) WCF(TD,A13,13) WCF(TE,A14,14) _(T0,_cfX)} #endif /*-------------------------------------------------------------------------*/ /* UTILITIES FOR FORTRAN TO CALL C ROUTINES */ #ifdef OLD_VAXC /* Prevent %CC-I-PARAMNOTUSED. */ #pragma nostandard #endif #if defined(vmsFortran) || defined(CRAYFortran) #define DCF(TN,I) #define DDCF(TN,I) #define DDDCF(TN,I) #else #define DCF(TN,I) HCF(TN,I) #define DDCF(TN,I) HHCF(TN,I) #define DDDCF(TN,I) HHHCF(TN,I) #endif #define QCF(TN,I) _(TN,_cfSTR)(1,Q,_(B,I), 0,0,0,0) #define DEFAULT_cfQ(B) #define LOGICAL_cfQ(B) #define PLOGICAL_cfQ(B) #define STRINGV_cfQ(B) char *B; unsigned int _(B,N); #define STRING_cfQ(B) char *B=NULL; #define PSTRING_cfQ(B) char *B=NULL; #define PSTRINGV_cfQ(B) STRINGV_cfQ(B) #define PNSTRING_cfQ(B) char *B=NULL; #define PPSTRING_cfQ(B) #ifdef __sgi /* Else SGI gives warning 182 contrary to its C LRM A.17.7 */ #define ROUTINE_orig *(void**)& #else #define ROUTINE_orig (void *) #endif #define ROUTINE_1 ROUTINE_orig #define ROUTINE_2 ROUTINE_orig #define ROUTINE_3 ROUTINE_orig #define ROUTINE_4 ROUTINE_orig #define ROUTINE_5 ROUTINE_orig #define ROUTINE_6 ROUTINE_orig #define ROUTINE_7 ROUTINE_orig #define ROUTINE_8 ROUTINE_orig #define ROUTINE_9 ROUTINE_orig #define ROUTINE_10 ROUTINE_orig #define ROUTINE_11 ROUTINE_orig #define ROUTINE_12 ROUTINE_orig #define ROUTINE_13 ROUTINE_orig #define ROUTINE_14 ROUTINE_orig #define ROUTINE_15 ROUTINE_orig #define ROUTINE_16 ROUTINE_orig #define ROUTINE_17 ROUTINE_orig #define ROUTINE_18 ROUTINE_orig #define ROUTINE_19 ROUTINE_orig #define ROUTINE_20 ROUTINE_orig #define ROUTINE_21 ROUTINE_orig #define ROUTINE_22 ROUTINE_orig #define ROUTINE_23 ROUTINE_orig #define ROUTINE_24 ROUTINE_orig #define ROUTINE_25 ROUTINE_orig #define ROUTINE_26 ROUTINE_orig #define ROUTINE_27 ROUTINE_orig #define TCF(NAME,TN,I,M) _SEP_(TN,M,cfCOMMA) _(TN,_cfT)(NAME,I,_(A,I),_(B,I),_(C,I)) #define BYTE_cfT(M,I,A,B,D) *A #define DOUBLE_cfT(M,I,A,B,D) *A #define FLOAT_cfT(M,I,A,B,D) *A #define INT_cfT(M,I,A,B,D) *A #define LOGICAL_cfT(M,I,A,B,D) F2CLOGICAL(*A) #define LONG_cfT(M,I,A,B,D) *A #define SHORT_cfT(M,I,A,B,D) *A #define BYTEV_cfT(M,I,A,B,D) A #define DOUBLEV_cfT(M,I,A,B,D) A #define FLOATV_cfT(M,I,A,B,D) VOIDP A #define INTV_cfT(M,I,A,B,D) A #define LOGICALV_cfT(M,I,A,B,D) A #define LONGV_cfT(M,I,A,B,D) A #define SHORTV_cfT(M,I,A,B,D) A #define BYTEVV_cfT(M,I,A,B,D) (void *)A /* We have to cast to void *,*/ #define BYTEVVV_cfT(M,I,A,B,D) (void *)A /* since we don't know the */ #define BYTEVVVV_cfT(M,I,A,B,D) (void *)A /* dimensions of the array. */ #define BYTEVVVVV_cfT(M,I,A,B,D) (void *)A /* i.e. Unfortunately, can't */ #define BYTEVVVVVV_cfT(M,I,A,B,D) (void *)A /* check that the type */ #define BYTEVVVVVVV_cfT(M,I,A,B,D) (void *)A /* matches the prototype. */ #define DOUBLEVV_cfT(M,I,A,B,D) (void *)A #define DOUBLEVVV_cfT(M,I,A,B,D) (void *)A #define DOUBLEVVVV_cfT(M,I,A,B,D) (void *)A #define DOUBLEVVVVV_cfT(M,I,A,B,D) (void *)A #define DOUBLEVVVVVV_cfT(M,I,A,B,D) (void *)A #define DOUBLEVVVVVVV_cfT(M,I,A,B,D) (void *)A #define FLOATVV_cfT(M,I,A,B,D) (void *)A #define FLOATVVV_cfT(M,I,A,B,D) (void *)A #define FLOATVVVV_cfT(M,I,A,B,D) (void *)A #define FLOATVVVVV_cfT(M,I,A,B,D) (void *)A #define FLOATVVVVVV_cfT(M,I,A,B,D) (void *)A #define FLOATVVVVVVV_cfT(M,I,A,B,D) (void *)A #define INTVV_cfT(M,I,A,B,D) (void *)A #define INTVVV_cfT(M,I,A,B,D) (void *)A #define INTVVVV_cfT(M,I,A,B,D) (void *)A #define INTVVVVV_cfT(M,I,A,B,D) (void *)A #define INTVVVVVV_cfT(M,I,A,B,D) (void *)A #define INTVVVVVVV_cfT(M,I,A,B,D) (void *)A #define LOGICALVV_cfT(M,I,A,B,D) (void *)A #define LOGICALVVV_cfT(M,I,A,B,D) (void *)A #define LOGICALVVVV_cfT(M,I,A,B,D) (void *)A #define LOGICALVVVVV_cfT(M,I,A,B,D) (void *)A #define LOGICALVVVVVV_cfT(M,I,A,B,D) (void *)A #define LOGICALVVVVVVV_cfT(M,I,A,B,D) (void *)A #define LONGVV_cfT(M,I,A,B,D) (void *)A #define LONGVVV_cfT(M,I,A,B,D) (void *)A #define LONGVVVV_cfT(M,I,A,B,D) (void *)A #define LONGVVVVV_cfT(M,I,A,B,D) (void *)A #define LONGVVVVVV_cfT(M,I,A,B,D) (void *)A #define LONGVVVVVVV_cfT(M,I,A,B,D) (void *)A #define SHORTVV_cfT(M,I,A,B,D) (void *)A #define SHORTVVV_cfT(M,I,A,B,D) (void *)A #define SHORTVVVV_cfT(M,I,A,B,D) (void *)A #define SHORTVVVVV_cfT(M,I,A,B,D) (void *)A #define SHORTVVVVVV_cfT(M,I,A,B,D) (void *)A #define SHORTVVVVVVV_cfT(M,I,A,B,D) (void *)A #define PBYTE_cfT(M,I,A,B,D) A #define PDOUBLE_cfT(M,I,A,B,D) A #define PFLOAT_cfT(M,I,A,B,D) VOIDP A #define PINT_cfT(M,I,A,B,D) A #define PLOGICAL_cfT(M,I,A,B,D) ((*A=F2CLOGICAL(*A)),A) #define PLONG_cfT(M,I,A,B,D) A #define PSHORT_cfT(M,I,A,B,D) A #define PVOID_cfT(M,I,A,B,D) A #if defined(apolloFortran) || defined(hpuxFortran800) || defined(AbsoftUNIXFortran) #define ROUTINE_cfT(M,I,A,B,D) _(ROUTINE_,I) (*A) #else #define ROUTINE_cfT(M,I,A,B,D) _(ROUTINE_,I) A #endif /* A == pointer to the characters D == length of the string, or of an element in an array of strings E == number of elements in an array of strings */ #define TTSTR( A,B,D) \ ((B=_cf_malloc(D+1))[D]='\0', memcpy(B,A,D), kill_trailing(B,' ')) #define TTTTSTR( A,B,D) (!(D<4||A[0]||A[1]||A[2]||A[3]))?NULL: \ memchr(A,'\0',D) ?A : TTSTR(A,B,D) #define TTTTSTRV( A,B,D,E) (_(B,N)=E,B=_cf_malloc(_(B,N)*(D+1)), (void *) \ vkill_trailing(f2cstrv(A,B,D+1, _(B,N)*(D+1)), D+1,_(B,N)*(D+1),' ')) #ifdef vmsFortran #define STRING_cfT(M,I,A,B,D) TTTTSTR( A->dsc$a_pointer,B,A->dsc$w_length) #define STRINGV_cfT(M,I,A,B,D) TTTTSTRV(A->dsc$a_pointer, B, \ A->dsc$w_length , A->dsc$l_m[0]) #define PSTRING_cfT(M,I,A,B,D) TTSTR( A->dsc$a_pointer,B,A->dsc$w_length) #define PPSTRING_cfT(M,I,A,B,D) A->dsc$a_pointer #else #ifdef CRAYFortran #define STRING_cfT(M,I,A,B,D) TTTTSTR( _fcdtocp(A),B,_fcdlen(A)) #define STRINGV_cfT(M,I,A,B,D) TTTTSTRV(_fcdtocp(A),B,_fcdlen(A), \ num_elem(_fcdtocp(A),_fcdlen(A),_3(M,_STRV_A,I))) #define PSTRING_cfT(M,I,A,B,D) TTSTR( _fcdtocp(A),B,_fcdlen(A)) #define PPSTRING_cfT(M,I,A,B,D) _fcdtocp(A) #else #define STRING_cfT(M,I,A,B,D) TTTTSTR( A,B,D) #define STRINGV_cfT(M,I,A,B,D) TTTTSTRV(A,B,D, num_elem(A,D,_3(M,_STRV_A,I))) #define PSTRING_cfT(M,I,A,B,D) TTSTR( A,B,D) #define PPSTRING_cfT(M,I,A,B,D) A #endif #endif #define PNSTRING_cfT(M,I,A,B,D) STRING_cfT(M,I,A,B,D) #define PSTRINGV_cfT(M,I,A,B,D) STRINGV_cfT(M,I,A,B,D) #define CF_0_cfT(M,I,A,B,D) #define RCF(TN,I) _(TN,_cfSTR)(3,R,_(A,I),_(B,I),_(C,I),0,0) #define DEFAULT_cfR(A,B,D) #define LOGICAL_cfR(A,B,D) #define PLOGICAL_cfR(A,B,D) *A=C2FLOGICAL(*A); #define STRING_cfR(A,B,D) if (B) _cf_free(B); #define STRINGV_cfR(A,B,D) _cf_free(B); /* A and D as defined above for TSTRING(V) */ #define RRRRPSTR( A,B,D) if (B) memcpy(A,B, _cfMIN(strlen(B),D)), \ (D>strlen(B)?memset(A+strlen(B),' ', D-strlen(B)):0), _cf_free(B); #define RRRRPSTRV(A,B,D) c2fstrv(B,A,D+1,(D+1)*_(B,N)), _cf_free(B); #ifdef vmsFortran #define PSTRING_cfR(A,B,D) RRRRPSTR( A->dsc$a_pointer,B,A->dsc$w_length) #define PSTRINGV_cfR(A,B,D) RRRRPSTRV(A->dsc$a_pointer,B,A->dsc$w_length) #else #ifdef CRAYFortran #define PSTRING_cfR(A,B,D) RRRRPSTR( _fcdtocp(A),B,_fcdlen(A)) #define PSTRINGV_cfR(A,B,D) RRRRPSTRV(_fcdtocp(A),B,_fcdlen(A)) #else #define PSTRING_cfR(A,B,D) RRRRPSTR( A,B,D) #define PSTRINGV_cfR(A,B,D) RRRRPSTRV(A,B,D) #endif #endif #define PNSTRING_cfR(A,B,D) PSTRING_cfR(A,B,D) #define PPSTRING_cfR(A,B,D) #define BYTE_cfFZ(UN,LN) INTEGER_BYTE FCALLSC_QUALIFIER fcallsc(UN,LN)( #define DOUBLE_cfFZ(UN,LN) DOUBLE_PRECISION FCALLSC_QUALIFIER fcallsc(UN,LN)( #define INT_cfFZ(UN,LN) int FCALLSC_QUALIFIER fcallsc(UN,LN)( #define LOGICAL_cfFZ(UN,LN) int FCALLSC_QUALIFIER fcallsc(UN,LN)( #define LONG_cfFZ(UN,LN) long FCALLSC_QUALIFIER fcallsc(UN,LN)( #define SHORT_cfFZ(UN,LN) short FCALLSC_QUALIFIER fcallsc(UN,LN)( #define VOID_cfFZ(UN,LN) void FCALLSC_QUALIFIER fcallsc(UN,LN)( #ifndef __CF__KnR /* The void is req'd by the Apollo, to make this an ANSI function declaration. The Apollo promotes K&R float functions to double. */ #define FLOAT_cfFZ(UN,LN) FORTRAN_REAL FCALLSC_QUALIFIER fcallsc(UN,LN)(void #ifdef vmsFortran #define STRING_cfFZ(UN,LN) void FCALLSC_QUALIFIER fcallsc(UN,LN)(fstring *AS #else #ifdef CRAYFortran #define STRING_cfFZ(UN,LN) void FCALLSC_QUALIFIER fcallsc(UN,LN)(_fcd AS #else #if defined(AbsoftUNIXFortran) || defined(AbsoftProFortran) #define STRING_cfFZ(UN,LN) void FCALLSC_QUALIFIER fcallsc(UN,LN)(char *AS #else #define STRING_cfFZ(UN,LN) void FCALLSC_QUALIFIER fcallsc(UN,LN)(char *AS, unsigned D0 #endif #endif #endif #else #if ! (defined(FLOATFUNCTIONTYPE)&&defined(ASSIGNFLOAT)&&defined(RETURNFLOAT)) #define FLOAT_cfFZ(UN,LN) FORTRAN_REAL FCALLSC_QUALIFIER fcallsc(UN,LN)( #else #define FLOAT_cfFZ(UN,LN) FLOATFUNCTIONTYPE FCALLSC_QUALIFIER fcallsc(UN,LN)( #endif #if defined(vmsFortran) || defined(CRAYFortran) || defined(AbsoftUNIXFortran) #define STRING_cfFZ(UN,LN) void FCALLSC_QUALIFIER fcallsc(UN,LN)(AS #else #define STRING_cfFZ(UN,LN) void FCALLSC_QUALIFIER fcallsc(UN,LN)(AS, D0 #endif #endif #define BYTE_cfF(UN,LN) BYTE_cfFZ(UN,LN) #define DOUBLE_cfF(UN,LN) DOUBLE_cfFZ(UN,LN) #ifndef __CF_KnR #define FLOAT_cfF(UN,LN) FORTRAN_REAL FCALLSC_QUALIFIER fcallsc(UN,LN)( #else #define FLOAT_cfF(UN,LN) FLOAT_cfFZ(UN,LN) #endif #define INT_cfF(UN,LN) INT_cfFZ(UN,LN) #define LOGICAL_cfF(UN,LN) LOGICAL_cfFZ(UN,LN) #define LONG_cfF(UN,LN) LONG_cfFZ(UN,LN) #define SHORT_cfF(UN,LN) SHORT_cfFZ(UN,LN) #define VOID_cfF(UN,LN) VOID_cfFZ(UN,LN) #define STRING_cfF(UN,LN) STRING_cfFZ(UN,LN), #define INT_cfFF #define VOID_cfFF #ifdef vmsFortran #define STRING_cfFF fstring *AS; #else #ifdef CRAYFortran #define STRING_cfFF _fcd AS; #else #define STRING_cfFF char *AS; unsigned D0; #endif #endif #define INT_cfL A0= #define STRING_cfL A0= #define VOID_cfL #define INT_cfK #define VOID_cfK /* KSTRING copies the string into the position provided by the caller. */ #ifdef vmsFortran #define STRING_cfK \ memcpy(AS->dsc$a_pointer,A0,_cfMIN(AS->dsc$w_length,(A0==NULL?0:strlen(A0))));\ AS->dsc$w_length>(A0==NULL?0:strlen(A0))? \ memset(AS->dsc$a_pointer+(A0==NULL?0:strlen(A0)),' ', \ AS->dsc$w_length-(A0==NULL?0:strlen(A0))):0; #else #ifdef CRAYFortran #define STRING_cfK \ memcpy(_fcdtocp(AS),A0, _cfMIN(_fcdlen(AS),(A0==NULL?0:strlen(A0))) ); \ _fcdlen(AS)>(A0==NULL?0:strlen(A0))? \ memset(_fcdtocp(AS)+(A0==NULL?0:strlen(A0)),' ', \ _fcdlen(AS)-(A0==NULL?0:strlen(A0))):0; #else #define STRING_cfK memcpy(AS,A0, _cfMIN(D0,(A0==NULL?0:strlen(A0))) ); \ D0>(A0==NULL?0:strlen(A0))?memset(AS+(A0==NULL?0:strlen(A0)), \ ' ', D0-(A0==NULL?0:strlen(A0))):0; #endif #endif /* Note that K.. and I.. can't be combined since K.. has to access data before R.., in order for functions returning strings which are also passed in as arguments to work correctly. Note that R.. frees and hence may corrupt the string. */ #define BYTE_cfI return A0; #define DOUBLE_cfI return A0; #if ! (defined(FLOATFUNCTIONTYPE)&&defined(ASSIGNFLOAT)&&defined(RETURNFLOAT)) #define FLOAT_cfI return A0; #else #define FLOAT_cfI RETURNFLOAT(A0); #endif #define INT_cfI return A0; #ifdef hpuxFortran800 /* Incredibly, functions must return true as 1, elsewhere .true.==0x01000000. */ #define LOGICAL_cfI return ((A0)?1:0); #else #define LOGICAL_cfI return C2FLOGICAL(A0); #endif #define LONG_cfI return A0; #define SHORT_cfI return A0; #define STRING_cfI return ; #define VOID_cfI return ; #ifdef OLD_VAXC /* Allow %CC-I-PARAMNOTUSED. */ #pragma standard #endif #define FCALLSCSUB0( CN,UN,LN) FCALLSCFUN0(VOID,CN,UN,LN) #define FCALLSCSUB1( CN,UN,LN,T1) FCALLSCFUN1(VOID,CN,UN,LN,T1) #define FCALLSCSUB2( CN,UN,LN,T1,T2) FCALLSCFUN2(VOID,CN,UN,LN,T1,T2) #define FCALLSCSUB3( CN,UN,LN,T1,T2,T3) FCALLSCFUN3(VOID,CN,UN,LN,T1,T2,T3) #define FCALLSCSUB4( CN,UN,LN,T1,T2,T3,T4) \ FCALLSCFUN4(VOID,CN,UN,LN,T1,T2,T3,T4) #define FCALLSCSUB5( CN,UN,LN,T1,T2,T3,T4,T5) \ FCALLSCFUN5(VOID,CN,UN,LN,T1,T2,T3,T4,T5) #define FCALLSCSUB6( CN,UN,LN,T1,T2,T3,T4,T5,T6) \ FCALLSCFUN6(VOID,CN,UN,LN,T1,T2,T3,T4,T5,T6) #define FCALLSCSUB7( CN,UN,LN,T1,T2,T3,T4,T5,T6,T7) \ FCALLSCFUN7(VOID,CN,UN,LN,T1,T2,T3,T4,T5,T6,T7) #define FCALLSCSUB8( CN,UN,LN,T1,T2,T3,T4,T5,T6,T7,T8) \ FCALLSCFUN8(VOID,CN,UN,LN,T1,T2,T3,T4,T5,T6,T7,T8) #define FCALLSCSUB9( CN,UN,LN,T1,T2,T3,T4,T5,T6,T7,T8,T9) \ FCALLSCFUN9(VOID,CN,UN,LN,T1,T2,T3,T4,T5,T6,T7,T8,T9) #define FCALLSCSUB10(CN,UN,LN,T1,T2,T3,T4,T5,T6,T7,T8,T9,TA) \ FCALLSCFUN10(VOID,CN,UN,LN,T1,T2,T3,T4,T5,T6,T7,T8,T9,TA) #define FCALLSCSUB11(CN,UN,LN,T1,T2,T3,T4,T5,T6,T7,T8,T9,TA,TB) \ FCALLSCFUN11(VOID,CN,UN,LN,T1,T2,T3,T4,T5,T6,T7,T8,T9,TA,TB) #define FCALLSCSUB12(CN,UN,LN,T1,T2,T3,T4,T5,T6,T7,T8,T9,TA,TB,TC) \ FCALLSCFUN12(VOID,CN,UN,LN,T1,T2,T3,T4,T5,T6,T7,T8,T9,TA,TB,TC) #define FCALLSCSUB13(CN,UN,LN,T1,T2,T3,T4,T5,T6,T7,T8,T9,TA,TB,TC,TD) \ FCALLSCFUN13(VOID,CN,UN,LN,T1,T2,T3,T4,T5,T6,T7,T8,T9,TA,TB,TC,TD) #define FCALLSCSUB14(CN,UN,LN,T1,T2,T3,T4,T5,T6,T7,T8,T9,TA,TB,TC,TD,TE) \ FCALLSCFUN14(VOID,CN,UN,LN,T1,T2,T3,T4,T5,T6,T7,T8,T9,TA,TB,TC,TD,TE) #define FCALLSCSUB15(CN,UN,LN,T1,T2,T3,T4,T5,T6,T7,T8,T9,TA,TB,TC,TD,TE,TF) \ FCALLSCFUN15(VOID,CN,UN,LN,T1,T2,T3,T4,T5,T6,T7,T8,T9,TA,TB,TC,TD,TE,TF) #define FCALLSCSUB16(CN,UN,LN,T1,T2,T3,T4,T5,T6,T7,T8,T9,TA,TB,TC,TD,TE,TF,TG) \ FCALLSCFUN16(VOID,CN,UN,LN,T1,T2,T3,T4,T5,T6,T7,T8,T9,TA,TB,TC,TD,TE,TF,TG) #define FCALLSCSUB17(CN,UN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_0,CF_0,CF_0) #define FCALLSCFUN2( T0,CN,UN,LN,T1,T2) \ FCALLSCFUN5 (T0,CN,UN,LN,T1,T2,CF_0,CF_0,CF_0) #define FCALLSCFUN3( T0,CN,UN,LN,T1,T2,T3) \ FCALLSCFUN5 (T0,CN,UN,LN,T1,T2,T3,CF_0,CF_0) #define FCALLSCFUN4( T0,CN,UN,LN,T1,T2,T3,T4) \ FCALLSCFUN5 (T0,CN,UN,LN,T1,T2,T3,T4,CF_0) #define FCALLSCFUN5( T0,CN,UN,LN,T1,T2,T3,T4,T5) \ FCALLSCFUN10(T0,CN,UN,LN,T1,T2,T3,T4,T5,CF_0,CF_0,CF_0,CF_0,CF_0) #define FCALLSCFUN6( T0,CN,UN,LN,T1,T2,T3,T4,T5,T6) \ FCALLSCFUN10(T0,CN,UN,LN,T1,T2,T3,T4,T5,T6,CF_0,CF_0,CF_0,CF_0) #define FCALLSCFUN7( T0,CN,UN,LN,T1,T2,T3,T4,T5,T6,T7) \ FCALLSCFUN10(T0,CN,UN,LN,T1,T2,T3,T4,T5,T6,T7,CF_0,CF_0,CF_0) #define FCALLSCFUN8( T0,CN,UN,LN,T1,T2,T3,T4,T5,T6,T7,T8) \ FCALLSCFUN10(T0,CN,UN,LN,T1,T2,T3,T4,T5,T6,T7,T8,CF_0,CF_0) #define FCALLSCFUN9( T0,CN,UN,LN,T1,T2,T3,T4,T5,T6,T7,T8,T9) \ FCALLSCFUN10(T0,CN,UN,LN,T1,T2,T3,T4,T5,T6,T7,T8,T9,CF_0) #define FCALLSCFUN10(T0,CN,UN,LN,T1,T2,T3,T4,T5,T6,T7,T8,T9,TA) \ FCALLSCFUN14(T0,CN,UN,LN,T1,T2,T3,T4,T5,T6,T7,T8,T9,TA,CF_0,CF_0,CF_0,CF_0) #define FCALLSCFUN11(T0,CN,UN,LN,T1,T2,T3,T4,T5,T6,T7,T8,T9,TA,TB) \ FCALLSCFUN14(T0,CN,UN,LN,T1,T2,T3,T4,T5,T6,T7,T8,T9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F,ABSOFT_cf3(T0),T1,T2,T3,T4,T5,T6,T7,T8,T9,TA,TB,TC,TD,TE,TF,TG,TH,TI,TJ,TK,TL,TM,TN,TO,TP,TQ,TR)) _Icf(0,FF,T0,0,0) \ CFARGT27FS(NNNCF,DDDCF,_Z,T1,T2,T3,T4,T5,T6,T7,T8,T9,TA,TB,TC,TD,TE,TF,TG,TH,TI,TJ,TK,TL,TM,TN,TO,TP,TQ,TR); \ { CFARGT27S(QCF,T1,T2,T3,T4,T5,T6,T7,T8,T9,TA,TB,TC,TD,TE,TF,TG,TH,TI,TJ,TK,TL,TM,TN,TO,TP,TQ,TR) \ _Icf(2,UU,T0,A0,0); _Icf(0,L,T0,0,0) CN( TCF(LN,T1,1,0) TCF(LN,T2,2,1) \ TCF(LN,T3,3,1) TCF(LN,T4,4,1) TCF(LN,T5,5,1) TCF(LN,T6,6,1) TCF(LN,T7,7,1) \ TCF(LN,T8,8,1) TCF(LN,T9,9,1) TCF(LN,TA,10,1) TCF(LN,TB,11,1) TCF(LN,TC,12,1) \ TCF(LN,TD,13,1) TCF(LN,TE,14,1) TCF(LN,TF,15,1) TCF(LN,TG,16,1) TCF(LN,TH,17,1) \ TCF(LN,TI,18,1) TCF(LN,TJ,19,1) TCF(LN,TK,20,1) TCF(LN,TL,21,1) TCF(LN,TM,22,1) \ TCF(LN,TN,23,1) TCF(LN,TO,24,1) TCF(LN,TP,25,1) TCF(LN,TQ,26,1) TCF(LN,TR,27,1) ); _Icf(0,K,T0,0,0) \ CFARGT27S(RCF,T1,T2,T3,T4,T5,T6,T7,T8,T9,TA,TB,TC,TD,TE,TF,TG,TH,TI,TJ,TK,TL,TM,TN,TO,TP,TQ,TR) _(T0,_cfI)} #endif #endif /* __CFORTRAN_LOADED */ cfortran-4.4/cfortest.c0100644000175000017500000007601107563721321015424 0ustar kmccartykmccarty/* cfortest.c 4.3 */ /* http://www-zeus.desy.de/~burow/cfortran/ */ /* Burkhard Burow burow@desy.de 1990 - 2001. */ #include #include /* qsort EXIT_SUCCESS */ #ifndef EXIT_SUCCESS #define EXIT_SUCCESS 0 #endif #include "cfortran.h" #define EASY_SELECT /* To see the various examples select one of: EASY_SELECT,SUBT_SELECT, SZ_SELECT, FT_SELECT, FZ_SELECT, SS1_SELECT, ABC_SELECT, RR_SELECT, REV_SELECT, FCB_SELECT, EQ_SELECT, F0_SELECT, FA_SELECT, FB_SELECT, FC_SELECT, FD_SELECT, FE_SELECT, FF_SELECT, FG_SELECT, FH_SELECT, FI_SELECT, FJ_SELECT, FK_SELECT, FL_SELECT, FM_SELECT, FN_SELECT, VV_SELECT, V7_SELECT,FAND_SELECT,FORR_SELECT, STRTOK_SELECT,USER_SELECT, FUN_SELECT, SUB_SELECT. Q_SELECT, E2_SELECT, FSTR_SELECT,CF14_SELECT, F20_SELECT, F27_SELECT, SZ1_SELECT, PZ_SELECT. */ /* FORTRAN_REAL, instead of float, is only required for CRAY T3E. */ /* DOUBLE_PRECISION, instead of double, is only required for CRAY (not T3E). */ #ifdef NAGf90Fortran /* Following is only a C main calling f90-compiled Fortran routines. Irrelevant when Fortran PROGRAM calls C routines. Advice for 'NAGWare f90 compiler Version 2.0a(264)' and presumably also for more recent versions: C main must call f90_init and f90_finish. See kludge below. Initialization and termination behavior of f90 is easily investigated, e.g. burow[9] cat f.f end burow[10] f90 -S f.f burow[11] cat f.c #include int main(argc,argv) int argc; char *argv[]; { f90_init(argc,argv); f90_finish(0); } Advice for earlier incarnations of NAGWare f90: NAG f90 library hijacks main() and the user's program starts with a call to void f90_main(void); No problem for cfortest.c, but woe is the C application which uses command line arguments for which NAG f90 provides no support. */ /* Assume Version 2.0a(264) or more recent. */ main(argc, argv) int argc; char *argv[]; {f90_init(argc,argv); f90_main(argc,argv); f90_finish(0); return EXIT_SUCCESS;} #define main f90_main #endif #ifdef EASY_SELECT PROTOCCALLSFSUB2(EASY,easy, PINT, INT) #define EASY(A,B) CCALLSFSUB2(EASY,easy, PINT, INT, A, B) main() { int a; printf("\nEASY EXAMPLE\n"); EASY(a,7); printf("The FORTRAN routine EASY(a,7) returns a = %d\n", a); return EXIT_SUCCESS; } #endif #ifdef SUBT_SELECT PROTOCCALLSFSUB3(SUBT,subt, PSTRINGV, STRINGV, FLOAT) #define SUBT(A,B,C) CCALLSFSUB3(SUBT,subt, PSTRINGV, STRINGV, FLOAT, A, B, C) int main() { static char v[][5] = {"000 ", "1", "22", " "}; static char w[][9] = {" ", "bb","ccc ","dddd"}; SUBT(v, w, 10.); printf("main:v=%s,%s,%s,%s. PSTRINGV => Has had trailing blanks stripped.\n", v[0],v[1],v[2],v[3]); printf("main:w=%s,%s,%s,%s. STRINGV => malloc'd copy for FORTRAN=> C intact.\n" ,w[0],w[1],w[2],w[3]); return EXIT_SUCCESS; } #endif #ifdef SZ_SELECT #define sz_ELEMS_1 ZTRINGV_ARGS(3) #define sz_ELEMLEN_1 ZTRINGV_NUM(6) #define sz_ELEMS_2 ZTRINGV_NUM(4) #define sz_ELEMLEN_2 ZTRINGV_NUM(8) PROTOCCALLSFSUB3(SZ,sz, PZTRINGV, ZTRINGV, INT) #define SZ(A,B,C) CCALLSFSUB3(SZ,sz, PZTRINGV, ZTRINGV, INT, A, B, C) int main() { static char v[][7] = {"000 ", "1", "22", " "}; static char w[][9] = {" ", "bb","ccc ","dddd"}; SZ(v, w, 4); printf("main:v=%s,%s,%s,%s. PZTRINGV => Has had trailing blanks stripped.\n", v[0],v[1],v[2],v[3]); printf("main:w=%s,%s,%s,%s. ZTRINGV => malloc'd copy for FORTRAN=> C intact.\n" ,w[0],w[1],w[2],w[3]); return EXIT_SUCCESS; } #endif #ifdef FT_SELECT PROTOCCALLSFFUN3(STRING,FT,ft, PSTRINGV, STRINGV, FLOAT) #define FT(A,B,C) CCALLSFFUN3(FT,ft, PSTRINGV, STRINGV, FLOAT, A, B, C) main() { static char v[][5] = {"000 ", "1", "22", " "}; static char w[][9] = {" ", "bb","ccc ","dddd"}; FORTRAN_REAL a = 10.0; printf("FT(v, w, a); returns:%s.\n",FT(v, w, a)); printf("main:v=%s,%s,%s,%s. PSTRINGV => Has had trailing blanks stripped.\n", v[0],v[1],v[2],v[3]); printf("main:w=%s,%s,%s,%s. STRINGV => malloc'd copy for FORTRAN=> C intact.\n" ,w[0],w[1],w[2],w[3]); return EXIT_SUCCESS; } #endif #ifdef FZ_SELECT #define fz_ELEMS_1 ZTRINGV_ARGF(3) #define fz_ELEMLEN_1 ZTRINGV_NUM(6) #define fz_ELEMS_2 ZTRINGV_NUM(4) #define fz_ELEMLEN_2 ZTRINGV_NUM(8) PROTOCCALLSFFUN3(STRING,FZ,fz, PZTRINGV, ZTRINGV, INT) #define FZ(A,B,C) CCALLSFFUN3(FZ,fz, PZTRINGV, ZTRINGV, INT, A, B, C) main() { static char v[][7] = {"000 ", "1", "22", " "}; static char w[][9] = {" ", "bb","ccc ","dddd"}; printf("FZ(v, w, a); returns:%s.\n",FZ(v, w, 4)); printf("main:v=%s,%s,%s,%s. PZTRINGV => Has had trailing blanks stripped.\n", v[0],v[1],v[2],v[3]); printf("main:w=%s,%s,%s,%s. ZTRINGV => malloc'd copy for FORTRAN=> C intact.\n" ,w[0],w[1],w[2],w[3]); return EXIT_SUCCESS; } #endif #ifdef SS1_SELECT PROTOCCALLSFSUB1(SS1,ss1, PSTRING) #define SS1(A1) CCALLSFSUB1(SS1,ss1, PSTRING, A1) PROTOCCALLSFSUB1(FORSTR1,forstr1, PSTRING) #define FORSTR1(A1) CCALLSFSUB1(FORSTR1,forstr1, PSTRING, A1) main() { static char b[] = "abcdefghij", forb[13] = "abcdefghijkl"; SS1(b); FORSTR1(forb); printf("SS1(b) returns b = %s; FORSTR1(forb) = returns forb = %s;\n", b, forb); return EXIT_SUCCESS; } #endif #ifdef ABC_SELECT PROTOCCALLSFSUB3(ABC,abc, STRING, PSTRING, PSTRING) #define ABC(A1,A2,A3) CCALLSFSUB3(ABC,abc, STRING, PSTRING, PSTRING, A1, A2, A3) main() { static char aa[] = "one ", bb[] = "two ", cc[] = "three"; int i; for (i=0; i<10; i++) {printf("%s;%s;%s;\n",aa,bb,cc); ABC(aa,bb,cc);} return EXIT_SUCCESS; } #endif #ifdef RR_SELECT PROTOCCALLSFFUN1(FLOAT,RR,rr,INT) #define RR(A1) CCALLSFFUN1(RR,rr, INT, A1) PROTOCCALLSFFUN0(STRING,FORSTR2,forstr2) #define FORSTR2() CCALLSFFUN0(FORSTR2,forstr2) PROTOCCALLSFFUN1(STRING,FORSTR,forstr,STRING) #define FORSTR(A1) CCALLSFFUN1(FORSTR,forstr, STRING, A1) main() { static char aa[] = "one"; int rrr = 333; printf("RR(rrr=%d) returns int arg. as float:%f\n",rrr,RR(rrr)); printf("FORSTR(aa=%s) returns the string arg. as:%s<-end here\n",aa,FORSTR(aa)); printf("FORSTR2() returns the string constant:%s<-end here\n",FORSTR2()); return EXIT_SUCCESS; } #endif #ifdef REV_SELECT PROTOCCALLSFFUN1(INT,FREV,frev, INTV) #define FREV(A1) CCALLSFFUN1(FREV,frev, INTV, A1) /* K&R mode of SunOS and Ultrix C prepro. dissallow space before FREV, * since they then go into an infinite loop of FREV replacement. */ PROTOCCALLSFSUB1(REV,rev, INTV) #define REV(A1) CCALLSFSUB1(REV,rev, INTV, A1) main() { static int a[] = {1,2}; printf("REV(a[0,1]=%d,%d) receives:",a[0],a[1]); REV(a); printf("a[0,1]=%d,%d\n",a[0],a[1]); printf("FREV(a[0,1]=%d,%d) receives:",a[0],a[1]); printf("%d",FREV(a)); printf(" with a[0,1]=%d,%d\n",a[0],a[1]); return EXIT_SUCCESS; } #endif #ifdef FCB_SELECT PROTOCCALLSFSUB0(FFCB,ffcb) #define FFCB() CCALLSFSUB0(FFCB,ffcb) typedef struct { char v[13],w[4][13],x[2][3][13]; } FCB_DEF; #define Fcb COMMON_BLOCK(FCB,fcb) COMMON_BLOCK_DEF(FCB_DEF,Fcb); FCB_DEF Fcb; main() { char cv[14]; static char cw[4][14] = {"C's w[0]", "C's w[1]", "C's w[2]", "C's w[3]"}; static char cx[2][3][14] = {{"C's x[0][0]", "C's x[0][1]", "C's x[0][2]"}, {"C's x[1][0]", "C's x[1][1]", "C's x[1][2]"}}; C2FCBSTR("C's V" ,Fcb.v,0); C2FCBSTR(cw ,Fcb.w,1); C2FCBSTR(cx ,Fcb.x,2); FFCB(); FCB2CSTR(Fcb.v ,cv ,0); FCB2CSTR(Fcb.w ,cw ,1); FCB2CSTR(Fcb.x ,cx ,2); printf("FFCB returns v = %s.\n",cv); printf("FFCB returns w[1,2,3,4] = %s,%s,%s,%s.\n",cw[0],cw[1],cw[2],cw[3]); printf("FFCB returns x[0,(1,2,3)] = %s,%s,%s.\n",cx[0][0],cx[0][1],cx[0][2]); printf("FFCB returns x[1,(1,2,3)] = %s,%s,%s.\n",cx[1][0],cx[1][1],cx[1][2]); return EXIT_SUCCESS; } #endif #ifdef EQ_SELECT PROTOCCALLSFSUB0(FEQ,feq) #define FEQ() CCALLSFSUB0(FEQ,feq) #define KWBANK 690 typedef struct { int nzebra; FORTRAN_REAL gversn,zversn; int ixstor,ixdiv,ixcons; FORTRAN_REAL fendq[16]; union { struct { int Lmain,Lr1; union {FORTRAN_REAL Ws[KWBANK]; int Iws[2];}u; }s; union { int Lq[80]; struct { int dummy[8]; union {FORTRAN_REAL Q[2]; int Iq[2];}u; }s; }u; }u; } GCBANK_DEF; #define lmain u.s.Lmain #define lr1 u.s.Lr1 #define ws u.s.u.Ws #define iws u.s.u.Iws #define lq u.u.Lq #define q u.u.s.u.Q #define iq u.u.s.u.Iq #define GCbank COMMON_BLOCK(GCBANK,gcbank) COMMON_BLOCK_DEF(GCBANK_DEF,GCbank); GCBANK_DEF GCbank; main() { FEQ(); printf("GCbank.nzebra = %d.\n", GCbank.nzebra); printf("GCbank.gversn = %f.\n", GCbank.gversn); printf("GCbank.zversn = %f.\n", GCbank.zversn); printf("GCbank.ixstor = %d.\n", GCbank.ixstor); printf("GCbank.ixcons = %d.\n", GCbank.ixcons); printf("GCbank.fendq[15] = %f.\n", GCbank.fendq[15]); printf("GCbank.lmain = %d.\n", GCbank.lmain); printf("GCbank.lr1 = %d.\n", GCbank.lr1); printf("GCbank.ws[KWBANK-1] = %f.\n", GCbank.ws[KWBANK-1]); printf("GCbank.iq[0] = %d.\n", GCbank.iq[0]); return EXIT_SUCCESS; } #undef lmain #undef lr1 #undef ws #undef iws #undef lq #undef q #undef iq #undef GCbank #endif /* The following functions, exist through cor, are called by FORTRAN functions, as shown by the remaining examples. */ #ifdef CF_SAME_NAMESPACE /* VAX/VMS HP-UX (without the f77 +ppu option. Ignore the undesirable -U option.) IBMR2 (without the xlf -qextname option.) AbsoftUNIXFortran default. have C and FORTRAN sharing the same name space. The name space is case-insensitive for VAX/VMS. There are several ways, some are described in cfortran.doc, to meet this constraint, which is only a difficulty for C routines to be called by FORTRAN. The conflict is explicitly avoided, as shown, for the routines: ca, cb, cc, cd. For VAX/VMS we need to change the name, (changing the case is not enough since VAX/VMS is case insensitive. This is done implicitly via the defines given below: For the IBM, HP and AbsoftUNIXFortran, we have chosen to name the C routines using a Proper Case notation, i.e: Exist, Ce, Ccff, Ccg, Cch, Ci, Cj, Ck, Cl, Cm, Cn, Cvv, Cv7, Cand, Cor, Cadd, Cfun, Pstru, Pstr, Cf14, Cf27. instead of the usual C convention: exist, ce, ccff, ccg, cch, ci, cj, ck, cl, cm, cn, cvv, cv7, cand, cor, cadd, cfun, pstru, pstr, cf14, cf27. IF 'Exist', ETC. ARE CHANGED TO LOWER CASE, THIS DEMO WILL STILL RUN ON ALL MACHINES, EXCEPT THE HP9000 (when not using f77 +ppu) AND THE IBM RS/6000 (when not using f77 -qextname) AND THE AbsoftUNIXFortran. i.e. Only these two machines, when their Fortran compilers aren't forced to append underscores, can require code to go against C naming norms. */ #ifdef vmsFortran #define Exist EXIST_ /*#define ca CA_*/ /* We don't do this since we've decided to call the routine ca from FORTRAN as CFORTRANCA. */ /*#define cb CB_*/ /* Similarly we call cb as CFCB. */ /*#define cc CC_*/ /* and cc as CFCC. */ /*#define cd CD_*/ /* and cd as CDCFORT. */ #define Ce CE_ #define Ccff CCFF_ #define Ccg CCG_ #define Cch CCH_ #define Ci CI_ #define Cj CJ_ #define Ck CK_ #define Cl CL_ #define Cm CM_ #define Cn CN_ #define Cvv CVV_ #define Cv7 CV7_ #define Cand CAND_ #define Cor COR_ #define Cadd CADD_ #define Cfun CFUN_ #define Pstru PSTRU_ #define Pstr PSTR_ #define Cf14 CF14_ #define Cf27 CF27_ #endif /* vmsFortran */ #endif /* CF_SAME_NAMESPACE */ void Exist() {printf("exist: was called.\n");} FCALLSCSUB0(Exist,EXIST,exist) void ca(i) int i; {printf("ca: had integer argument:%d.\n",i);} FCALLSCSUB1(ca,CFORTRANCA,cfortranca, INT) /* ^ ^-----------^---------FORTRAN name. |__ C name. */ /* With the next 2 lines we tell cfortran.h that for the subsequent FCALLSCSUBn and FCALLSCSUBn declarations, FORTRAN entry points to C routines have the C name prefaced with the characters 'CF', i.e. whereas the C name of the routine is 'cb', the routine is called from FORTRAN as 'CFCB'. Similarly C's cc, is CFCC for FORTRAN. */ #undef fcallsc #define fcallsc(UN,LN) preface_fcallsc(CF,cf,UN,LN) void cb(i) int *i; {printf("cb: had pointer argument to integer:%d.\n",*i); *i*=2;} FCALLSCSUB1(cb,CB,cb, PINT) void cc(s) char *s; {printf("cc: had string argument:%s.\n",s);} FCALLSCSUB1(cc,CC,cc, STRING) /* With the next 2 lines we tell cfortran.h that for the subsequent FCALLSCSUBn and FCALLSCSUBn declarations, FORTRAN entry points to C routines have the C name appended with the characters 'CFORT', i.e. whereas the C name of the routine is 'cd', the routine is called from FORTRAN as 'CDCFORT'. */ #undef fcallsc #define fcallsc(UN,LN) append_fcallsc(CFORT,cfort,UN,LN) void cd(s) char *s; {printf("cd: had string argument:%s.\n",s); strcpy(s,"to you 12345678");} FCALLSCSUB1(cd,CD,cd, PSTRING) #undef fcallsc #define fcallsc(UN,LN) orig_fcallsc(UN,LN) /* The preceeding line returns FORTRAN names to being the original C names. */ void Ce(v) char v[][5]; {printf("ce: had string vector argument:%s,%s,%s.\n",v[0],v[1],v[2]);} #define ce_STRV_A1 TERM_CHARS(' ',1) FCALLSCSUB1(Ce,CE,ce, STRINGV) void Ccff(v, n) char v[][5]; int n; {int i; printf("ccff: had %d string vector argument:",n); for (i=0; ilsave?ls:lsave); /* Switch contents of argument with contents of saved string. */ strcpy(temp,save); strcpy(save,s ); strcpy(s ,temp); free(temp); return; } /* Provide 3 interfaces using the the 3 types of PSTRING. */ FCALLSCSUB1(Pstr,PSTR,pstr, PSTRING) FCALLSCSUB1(Pstr,PNSTR,pnstr, PNSTRING) FCALLSCSUB1(Pstr,PPSTR,ppstr, PPSTRING) void Cf14(a,b,c,d,e,f,g,h,i,j,k,l,m,n) int *a,*b,*c,*d,*e,*f,*g,*h,*i,*j,*k,*l,*m,*n; { *a = 1; *b = 2; *c = 3; *d = 4; *e = 5; *f = 6; *g = 7; *h = 8; *i = 9; *j = 10; *k = 11; *l = 12; *m = 13; *n = 14; return;} FCALLSCSUB14(Cf14,CF14,cf14, PINT,PINT,PINT,PINT,PINT,PINT,PINT,PINT,PINT,PINT,PINT,PINT,PINT,PINT) void Cf27(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,aa) int *a,*b,*c,*d,*e,*f,*g,*h,*i,*j,*k,*l,*m,*n,*o,*p,*q,*r,*s,*t,*u,*v,*w,*x,*y,*z,*aa; { *a = 1; *b = 2; *c = 3; *d = 4; *e = 5; *f = 6; *g = 7; *h = 8; *i = 9; *j = 10; *k = 11; *l = 12; *m = 13; *n = 14; *o = 15; *p = 16; *q = 17; *r = 18; *s = 19; *t = 20; *u = 21; *v = 22; *w = 23; *x = 24; *y = 25; *z = 26; *aa= 27; return;} FCALLSCSUB27(Cf27,CF27,cf27, PINT,PINT,PINT,PINT,PINT,PINT,PINT,PINT,PINT,PINT,PINT,PINT,PINT,PINT, \ PINT,PINT,PINT,PINT,PINT,PINT,PINT,PINT,PINT,PINT,PINT,PINT,PINT) #ifdef F0_SELECT PROTOCCALLSFSUB0(FEXIST,fexist) #define FEXIST() CCALLSFSUB0(FEXIST,fexist) main() {FEXIST(); return EXIT_SUCCESS;} #endif #ifdef FA_SELECT PROTOCCALLSFSUB1(FA,fa, INT) #define FA(A1) CCALLSFSUB1(FA,fa, INT, A1) main() {FA(1234); return EXIT_SUCCESS;} #endif #ifdef FB_SELECT PROTOCCALLSFSUB1(FB,fb, PINT) #define FB(A1) CCALLSFSUB1(FB,fb, PINT, A1) main() {int i,ii; i=ii=1234; FB(ii); printf("MAIN: FB(i=%d) returns with i=%d.\n",i,ii); return EXIT_SUCCESS; } #endif #ifdef FC_SELECT PROTOCCALLSFSUB1(FC,fc, STRING) #define FC(A1) CCALLSFSUB1(FC,fc, STRING, A1) main() {FC("hello"); return EXIT_SUCCESS;} #endif #ifdef FD_SELECT PROTOCCALLSFSUB1(FD,fd, PSTRING) #define FD(A1) CCALLSFSUB1(FD,fd, PSTRING, A1) main() {static char i[] = "happy "; static char ii[] = "happy "; FD(ii); printf("MAIN: FD(i=%s) returns with i=%s.\n",i,ii); return EXIT_SUCCESS; } #endif #ifdef FE_SELECT PROTOCCALLSFSUB1(FE,fe, STRINGV) #define FE(A1) CCALLSFSUB1(FE,fe, STRINGV, A1) main() {static char v[][5] = {"0000", "1", "22", ""}; FE(v); return EXIT_SUCCESS;} #endif #ifdef FF_SELECT PROTOCCALLSFSUB2(FF,ff, STRINGV, INT) #define FF(A1,A2) CCALLSFSUB2(FF,ff, STRINGV, INT, A1, A2) main() {static char v[][5] = {"0000", "1", "22", ""}; FF(v,sizeof(v)/sizeof v[0]); return EXIT_SUCCESS; } #endif #ifdef FG_SELECT PROTOCCALLSFFUN0(INT,FG,fg) #define FG() CCALLSFFUN0(FG,fg) main() {printf("FG() returns %d.\n",FG()); return EXIT_SUCCESS;} #endif #ifdef FH_SELECT PROTOCCALLSFFUN0(STRING,FH,fh) #define FH() CCALLSFFUN0(FH,fh) main() {printf("FH() returns %s.\n",FH()); return EXIT_SUCCESS;} #endif #ifdef FI_SELECT PROTOCCALLSFFUN1(STRING,FI,fi,STRINGV) #define FI(A1) CCALLSFFUN1(FI,fi, STRINGV, A1) main() {static char v[][5] = {"0000", "1", "22", "333", "8", "9"}; printf("FI(v) returns %s.\n",FI(v)); return EXIT_SUCCESS; } #endif #ifdef FJ_SELECT PROTOCCALLSFFUN1(STRING,FJ,fj,INT) #define FJ(A1) CCALLSFFUN1(FJ,fj, INT, A1) main() { printf("FJ(2) returns %s.\n",FJ(2)); return EXIT_SUCCESS;} #endif #ifdef FK_SELECT PROTOCCALLSFFUN0(FLOAT,FK,fk) #define FK() CCALLSFFUN0(FK,fk) main() {printf("FK() returns %f.\n",FK()); return EXIT_SUCCESS;} #endif #ifdef FL_SELECT PROTOCCALLSFFUN0(DOUBLE,FL,fl) #define FL() CCALLSFFUN0(FL,fl) main() {printf("FL() returns %f.\n",(double)FL()); return EXIT_SUCCESS;} #endif /* ^- cast req.d for CRAY. */ #ifdef FM_SELECT PROTOCCALLSFFUN1(FLOAT,FM,fm,FLOAT) #define FM(A) CCALLSFFUN1(FM,fm, FLOAT, A) main() {printf("FM(111.) returns %f.\n",FM(111.)); return EXIT_SUCCESS;} #endif #ifdef FN_SELECT PROTOCCALLSFFUN2(DOUBLE,FN,fn,DOUBLE,DOUBLE) #define FN(A,B) CCALLSFFUN2(FN,fn, DOUBLE, DOUBLE, A, B) main() {printf("FN(1./3, 2./3) returns %f.\n",(double)FN(1./3, 2./3)); return EXIT_SUCCESS; } #endif /* ^- cast req.d for CRAY. */ #ifdef VV_SELECT PROTOCCALLSFSUB3(VV,vv, DOUBLEVV, FLOATVV, INTVV) #define VV(D,F,I) CCALLSFSUB3(VV,vv, DOUBLEVV, FLOATVV, INTVV, D, F, I) main() { DOUBLE_PRECISION d[2][2]; FORTRAN_REAL f[2][2]; int i[2][2]; int j,k; for (j=0; j<2; j++) for (k=0; k<2; k++) { d[j][k] = 100+10*j+k; f[j][k] = 200+10*j+k; i[j][k] = 300+10*j+k; } VV(d,f,i); /* \/- cast req.d for CRAY. */ printf("%4.0f%4.0f%4.0f%4.0f\n",(double)d[0][0],(double)d[0][1], (double)d[1][0],(double)d[1][1]); printf("%4.0f%4.0f%4.0f%4.0f\n",f[0][0],f[0][1],f[1][0],f[1][1]); printf("%4d%4d%4d%4d\n" ,i[0][0],i[0][1],i[1][0],i[1][1]); return EXIT_SUCCESS; } #endif #ifdef V7_SELECT PROTOCCALLSFFUN1(DOUBLE,V7,v7,DOUBLEVVVVVVV) #define V7(D) CCALLSFFUN1(V7,v7, DOUBLEVVVVVVV, D) main() { /* Original d[2][3][5][7][11][13][17] died a SEGV on DECstation MIPS cc 2.10, just like e.g. main() {double d[2][3][5][7][11][13][17], t=0;} */ DOUBLE_PRECISION d[2][3][5][7][11][13][1], t=0, r=1, tf; int i,j,k,l,m,n,o; for ( i=0; i< 2; i++) for ( j=0; j< 3; j++) for ( k=0; k< 5; k++) for ( l=0; l< 7; l++) for ( m=0; m<11; m++) for ( n=0; n<13; n++) for (o=0; o< 1; o++) { r /= 2; t += r; d[i][j][k][l][m][n][o] = r; } tf=V7(d); printf("main() filled array d with a total: %10.9f\n", (double)t ); printf("V7() returned the value: %10.9f\n", (double)tf); return EXIT_SUCCESS; } /* cast req.d for CRAY -^ */ #endif #ifdef FAND_SELECT PROTOCCALLSFFUN2(LOGICAL,FAND,fand,LOGICAL,LOGICAL) #define FAND(A,B) CCALLSFFUN2(FAND,fand, LOGICAL, LOGICAL, A, B) main() {printf("FAND(0, 1) returns %d.\n",FAND(0, 1)); return EXIT_SUCCESS;} #endif #ifdef FORR_SELECT PROTOCCALLSFFUN2(LOGICAL,FORR,forr,PLOGICAL,PLOGICAL) #define FORR(A,B) CCALLSFFUN2(FORR,forr, PLOGICAL, PLOGICAL, A, B) main() {int a=2, b=0; printf("Calling FORR(a=%d, b=%d).\n", a,b); printf("FORR() returned %d.\n", FORR(a, b)); printf("With a=%d, b=%d.\n", a,b); return EXIT_SUCCESS; } #endif #include FCALLSCFUN2(STRING,strtok,CSTRTOK,cstrtok, STRING, STRING) #ifdef STRTOK_SELECT PROTOCCALLSFSUB0(FSTRTOK,fstrtok) #define FSTRTOK() CCALLSFSUB0(FSTRTOK,fstrtok) main() {FSTRTOK(); return EXIT_SUCCESS;} #endif #ifdef USER_SELECT /* We define a new type USERINT. [Same functionality as PINT actually.] */ #ifdef OLD_VAXC /* To avoid %CC-I-PARAMNOTUSED. */ #pragma nostandard #endif #define USERINT_cfV( T,A,B,F) SIMPLE_cfV(T,A,B,F) #define USERINT_cfSEP(T, B) SIMPLE_cfSEP(T,B) #define USERINT_cfINT(N,A,B,X,Y,Z) SIMPLE_cfINT(N,A,B,X,Y,Z) #define USERINT_cfSTR(N,T,A,B,C,D,E) SIMPLE_cfSTR(N,T,A,B,C,D,E) #define USERINT_cfCC( T,A,B) SIMPLE_cfCC(T,A,B) #define USERINT_cfAA( T,A,B) USERINT_cfB(T,A) #define USERINT_cfU( T,A) USERINT_cfN(T,A) #define USERINT_cfN( T,A) int *A #define USERINT_cfB( T,A) &(A) #ifdef OLD_VAXC /* Have avoided %CC-I-PARAMNOTUSED. */ #pragma standard #endif PROTOCCALLSFSUB2(EASY,easy, USERINT, INT) #define EASY(A,B) CCALLSFSUB2(EASY,easy, USERINT, INT, A, B) main() { int a; printf("\nUsing user defined USERINT argument type.\n"); EASY(a,7); printf("The FORTRAN routine EASY(a,7) returns a = %d\n", a); return EXIT_SUCCESS; } #endif #ifdef FUN_SELECT /* Passing C or Fortran Functions to Fortran routines. */ PROTOCCALLSFFUN3(INT,FUNADD,funadd,ROUTINE,INT,INT) #define FUNADD(F,A,B) CCALLSFFUN3(FUNADD,funadd, ROUTINE, INT, INT, F, A, B) int Cadd(a,b) int a; int b; {return a+b;} FCALLSCFUN2(INT,Cadd,CADD,cadd, INT, INT) /* Want fadd to be prototyped, though don't need the wrapper that is created. */ PROTOCCALLSFFUN2(INT,FADD,fadd,INT,INT) main() { printf("\nFUNADD(CADD,1,2) returns %d\n", FUNADD( C_FUNCTION(CADD,cadd),1,2) ); printf("\nFUNADD(FADD,3,4) returns %d\n", FUNADD(FORTRAN_FUNCTION(FADD,fadd),3,4) ); return EXIT_SUCCESS; } #endif #ifdef SUB_SELECT /* Fortran passes routines to C. */ PROTOCCALLSFSUB4(FUNARG,funarg, ROUTINE, INT, INT, PINT) #define FUNARG(F,A,B,C) \ CCALLSFSUB4(FUNARG,funarg, ROUTINE, INT, INT, PINT, F, A, B, C) int Cfun(f,a,b) int (*f)(); int a; int b; {int c; f(&a,&b,&c); return c;} #undef ROUTINE_1 #define ROUTINE_1 (int (*)()) FCALLSCFUN3(INT,Cfun,CFUN,cfun, ROUTINE, INT, INT) main() { int c; FUNARG(C_FUNCTION(CFUN,cfun),1,2,c); printf("\nFUNARG(CFUN,1,2,c) returns with c=%d\n",c); return EXIT_SUCCESS; } #endif #undef ROUTINE_4 #ifdef VISUAL_CPLUSPLUS #define ROUTINE_4 (int (*)(const void *,const void *)) #else #define ROUTINE_4 (int (*)()) #endif FCALLSCSUB4(qsort,FQSORT,fqsort, PVOID, INT, INT, ROUTINE) /* Note that we've assumed in the above that size_t == int */ #ifdef Q_SELECT PROTOCCALLSFSUB1(FQSORTEX,fqsortex, INT) #define FQSORTEX(SIZEOF_INT) CCALLSFSUB1(FQSORTEX,fqsortex, INT, SIZEOF_INT) main() { #ifdef PowerStationFortran printf("\n\ Apologies. As described in cfortran.doc, MSPS Fortran provides no\n\ easy way to pass a Fortran routine as an argument to a C routine,\n\ so this qsort() example crashes for MSPS Fortran.\n\ \n\ As a kludge, the example works on MSPS Fortran by either\n\ - using MSPS Fortran language extensions\n\ or\n\ - by removing the 'integer function cmp(a,b)' routine from cfortex.f\n\ and instead using the following C routine.\n\ int CMP( int *a, int *b) { return *a-*b ; }\n\ \n\ It remains a mystery why the SUB_SELECT example works\n\ for MSPS Fortran, since it should crash due to the same problem.\n\ Presumably the faulty stack clearing is not fatal for SUB_SELECT.\n\ \n"); #else FQSORTEX(sizeof(int)); #endif return EXIT_SUCCESS; } #endif #ifdef E2_SELECT /* Only to demo. that we can force a wrapper to be used for subroutines. */ PROTOCCALLSFFUN2(VOID,EASY,easy,PINT,INT) #define EASY(A,B) CCALLSFFUN2(EASY,easy, PINT, INT, A, B) main() { int a; printf("\nEASY (2) EXAMPLE\n"); EASY(a,7); printf("The FORTRAN routine EASY(a,7) returns a = %d\n", a); return EXIT_SUCCESS; } #endif #ifdef FSTR_SELECT PROTOCCALLSFSUB0(FSTR,fstr) #define FSTR() CCALLSFSUB0(FSTR,fstr) main() { FSTR(); return EXIT_SUCCESS;} #endif #ifdef CF14_SELECT PROTOCCALLSFSUB14(F14,f14, PINT, PINT, PINT, PINT, PINT, PINT, PINT, PINT, PINT, PINT, PINT, PINT, PINT, PINT) #define F14(A,B,C,D,E,F,G,H,I,J,K,L,M,N) \ CCALLSFSUB14(F14,f14, PINT, PINT, PINT, PINT, PINT, PINT, PINT, PINT, PINT, PINT, PINT, PINT, PINT, PINT, A, B, C, D, E, F, G, H, I, J, K, L, M, N) main() { int a=0, b=0, c=0, d=0, e=0, f=0, g=0, h=0, i=0, j=0, k=0, l=0, m=0, n=0; F14( a,b,c,d,e,f,g,h,i,j,k,l,m,n); printf("CF14: %3d%3d%3d%3d%3d%3d%3d%3d%3d%3d%3d%3d%3d%3d.\n", a,b,c,d,e,f,g,h,i,j,k,l,m,n); return EXIT_SUCCESS; } #endif #ifdef F20_SELECT #if MAX_PREPRO_ARGS>31 && !defined(CFSUBASFUN) PROTOCCALLSFSUB20(F20,f20, PINT, PINT, PINT, PINT, PINT, PINT, PINT, PINT, PINT, PINT, PINT, PINT, PINT, PINT, PINT, PINT, PINT, PINT, PINT, PINT) #define F20(A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T) \ CCALLSFSUB20(F20,f20, PINT, PINT, PINT, PINT, PINT, PINT, PINT, PINT, PINT, PINT, PINT, PINT, PINT, PINT, PINT, PINT, PINT, PINT, PINT, PINT, A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T) main() { int a=0, b=0, c=0, d=0, e=0, f=0, g=0, h=0, i=0, j=0, k=0, l=0, m=0, n=0, o=0, p=0, q=0, r=0, s=0, t=0; F20( a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t); printf(" F20: %3d%3d%3d%3d%3d%3d%3d%3d%3d%3d%3d%3d%3d%3d%3d%3d%3d%3d%3d%3d.\n", a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t); return EXIT_SUCCESS; } #else main() { printf("Sorry 14 argument max. via cfortran.h for this C preprocessor or for CFSUBASFUN.\n"); return EXIT_SUCCESS; } #endif #endif #ifdef F27_SELECT #if MAX_PREPRO_ARGS>31 && !defined(CFSUBASFUN) PROTOCCALLSFSUB27(F27,f27, PINT, PINT, PINT, PINT, PINT, PINT, PINT, PINT, PINT, PINT, PINT, PINT, PINT, PINT, PINT, PINT, PINT, PINT, PINT, PINT, PINT, PINT, PINT, PINT, PINT, PINT, PINT) #define F27(A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,AA) \ CCALLSFSUB27(F27,f27, PINT, PINT, PINT, PINT, PINT, PINT, PINT, PINT, PINT, PINT, PINT, PINT, PINT, PINT, PINT, PINT, PINT, PINT, PINT, PINT, PINT, PINT, PINT, PINT, PINT, PINT, PINT, A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z, AA) main() { int a=0, b=0, c=0, d=0, e=0, f=0, g=0, h=0, i=0, j=0, k=0, l=0, m=0, n=0, o=0, p=0, q=0, r=0, s=0, t=0, u=0, v=0, w=0, x=0, y=0, z=0, aa=0; F27( a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,aa); printf(" F27: %3d%3d%3d%3d%3d%3d%3d%3d%3d%3d%3d%3d%3d%3d%3d%3d%3d%3d%3d%3d%3d%3d%3d%3d%3d%3d%3d.\n", a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,aa); return EXIT_SUCCESS; } #else main() { printf("Sorry 14 argument max. via cfortran.h for this C preprocessor or for CFSUBASFUN.\n"); return EXIT_SUCCESS; } #endif #endif #ifdef SZ1_SELECT #define sz1_ELEMS_3 ZTRINGV_ARGS(4) #define sz1_ELEMLEN_3 ZTRINGV_NUM(8) PROTOCCALLSFSUB4(SZ1,sz1, STRINGV,INT,ZTRINGV,INT) #define SZ1(S,IS,Z,IZ) CCALLSFSUB4(SZ1,sz1, STRINGV,INT,ZTRINGV,INT, S,IS,Z,IZ) int main() { char *p; static char s[][7]={"000 ", " "} , os[][3]={"s"}, as[ ]="one element"; static char z[][9]={" ", "bb","ccc "}, oz[][9]={"z"}, az[6]="1234"; /* - z[][9] must match ZTRINGV_NUM(8), while az[6] does not have to since a single element argument may have the wrong length. - For arrays of strings, can pass a pointer for ZTRINGV, but not for STRINGV. i.e. Can't determine sizes for STRINGV, that's why we have ZTRINGV. - NEITHER STRINGV nor ZTRINGV can accept an array of pointers, e.g. NO: { char *p[3]; p[0]=z[0]; p[1]=z[1]; p[2]=z[2]; SZ1(s, 2, p, 3); } */ p = (char *)z; SZ1(s , 2, p , 3); SZ1(s[1], 1, z[1] , 1); SZ1(os , 1, oz , 1); SZ1(as , 1, az , 1); SZ1("hi", 1, "hoho", 1); return EXIT_SUCCESS; } #endif #ifdef PZ_SELECT #define pz_ELEMS_3 ZTRINGV_ARGS(4) #define pz_ELEMLEN_3 ZTRINGV_NUM(8) PROTOCCALLSFSUB4(PZ,pz, PSTRINGV,INT, PZTRINGV,INT) #define PZ(S,IS,Z,IZ) CCALLSFSUB4(PZ,pz, PSTRINGV,INT, PZTRINGV,INT, S,IS,Z,IZ) int main() { char *p; static char s[][7]={"000 ", " "} , as[] ="hihi"; static char z[][9]={" ", "bb","ccc "}, az[99]="hoho"; /* - z[][9] must match ZTRINGV_NUM(8), while az[99] can match or be bigger, since 8 character will be copied back. - Comments in SZ1 example above for Z|STRINGV, also apply for PZ|STRINGV. */ p = (char *)z; PZ(s,2,p,3); PZ(s[1],1,z[2],1); PZ(as,1,az,1); PZ(as,1,az,1); return EXIT_SUCCESS; } #endif cfortran-4.4/cfortex.f0100644000175000017500000003517107563721324015255 0ustar kmccartykmccartyC cfortex.f 4.3 C http://www-zeus.desy.de/~burow/cfortran/ C Burkhard Burow burow@desy.de 1990 - 2001. C NAG f90 only C Uses an exclamation mark, '!', to start comments. Do: C prompt> mv cfortex.f cf_temp.f &&sed 's/^C/\!/g' cf_temp.f >cfortex.f C to convert the comments here into f90 compliant ones. C NAG f90 only subroutine ss1(b) implicit none character*(*) b character*(13) a data a/'first'/ b = a return end subroutine abc(a,b,c) implicit none character*(*) b,a,c character*(13) d d = a a = b b = c c = d return end subroutine forstr1(b) implicit none character*(*) b character*(13) a character*(13) forstr data a/'firs'/ b = forstr(a) return end subroutine EASY(a,b) implicit none integer a,b a = b return end character*(*) function forstr(a) implicit none character*(*) a forstr = a return end real function rr(i) implicit none integer i rr = i return end character*(*) function forstr2() implicit none C character*(13) a VAX/Ultrix complains about these (). character*13 a data a/'first'/ forstr2 = a return end character*(*) function ft(v, w, a) implicit none character *(*) v(4), w(4) real a print*,'FT:len(v(1 or 2 or 3 or 4)) =',len(v(1)) print*,'FT:len(w(1 or 2 or 3)) =',len(w(1)) print*,'FT:a = ',a print*,'FT:v(1,2,3,4) =',v(1),',',v(2),',',v(3),',',v(4) print*,'FT:w(1,2,3,4) =',w(1),',',w(2),',',w(3),',',w(4) ft = v(1) return end character*(*) function fz(v, w, i) implicit none integer i,j character *(*) v(i), w(i) print*,'FZ:len(v(1 or 2 or 3 or 4)) =',len(v(1)) print*,'FZ:len(w(1 or 2 or 3)) =',len(w(1)) do 100 j = 1,i print*,'FZ:v(',j,') =',v(j),' w(',j,') =',w(j) 100 continue fz = v(1) return end subroutine sz(v, w, i) implicit none integer i,j character *(*) v(i), w(i) print*,'SZ:len(v(1 or 2 or 3 or 4)) =',len(v(1)) print*,'SZ:len(w(1 or 2 or 3)) =',len(w(1)) do 100 j = 1,i print*,'SZ:v(',j,') =',v(j),' w(',j,') =',w(j) 100 continue return end subroutine subt(v, w, a) implicit none character *(*) v(4), w(4) real a print*,'SUBT:len(v(1 or 2 or 3 or 4)) =',len(v(1)) print*,'SUBT:len(w(1 or 2 or 3)) =',len(w(1)) print*,'SUBT:a = ',a print*,'SUBT:v(1,2,3,4) =',v(1),',',v(2),',',v(3),',',v(4) print*,'SUBT:w(1,2,3,4) =',w(1),',',w(2),',',w(3),',',w(4) return end subroutine rev(a) implicit none integer a(2),t t = a(1) a(1) = a(2) a(2) = t return end integer function frev(a) implicit none integer a(2) frev = a(1) a(1) = a(2) a(2) = frev return end subroutine ffcb() implicit none common /fcb/ v,w,x character *(13) v, w(4), x(3,2) print*,'FFCB:v =',v,'.' print*,'FFCB:w(1,2,3,4) =',w(1),',',w(2),',',w(3),',',w(4),'.' print*,'FFCB:x([1,2,3],1) =',x(1,1),',',x(2,1),',',x(3,1),'.' print*,'FFCB:x([1,2,3],2) =',x(1,2),',',x(2,2),',',x(3,2),'.' v = 'fcb v' w(1) = 'fcb w(1)' w(2) = 'fcb w(2)' w(3) = 'fcb w(3)' x(1,1) = 'fcb x(1,1)' x(2,1) = 'fcb x(2,1)' x(3,1) = 'fcb x(3,1)' x(1,2) = 'fcb x(1,2)' x(2,2) = 'fcb x(2,2)' x(3,2) = 'fcb x(3,2)' end subroutine feq() parameter (kwbank=690) C The & in the next line is for f90 line continuation. C It is in column 74, i.e. part of f77 comments. common/gcbank/nzebra,gversn,zversn,ixstor,ixdiv,ixcons,fendq(16) & & ,lmain,lr1,ws(kwbank) dimension iq(2),q(2),lq(80),iws(2) equivalence (q(1),iq(1),lq(9)),(lq(1),lmain) ,(iws(1),ws(1)) nzebra = 1 gversn = 2 zversn = 3 ixstor = 4 ixcons = 5 fendq(16) = 6 lmain = 7 lr1 = 8 ws(kwbank) = 9 lq(9) = 10 end subroutine fexist() implicit none print*,'FEXIST: was called' call exist() return end subroutine fa(i) implicit none integer i print*,'FA: integer argument =',i call cfortranca(i) return end subroutine fb(i) implicit none integer i print*,'FB: integer argument =',i i = i*2 call cfcb(i) return end subroutine fc(b) implicit none character*(*) b print*,'FC: string argument =',b call cfcc(b) return end subroutine fd(b) implicit none character*(*) b character*(13) a data a/'birthday'/ b = a call cdcfort(b) return end subroutine fe(v) implicit none character*(*) v(4) print*,'FE:len(v(1 or 2 or 3 or 4)) =',len(v(1)) print*,'FE:v(1,2,3,4) =',v(1),',',v(2),',',v(3),',',v(4) call ce(v) return end subroutine ff(v,n) implicit none integer n character*(*) v(4) print*,'FF:len(v(1 or 2 or 3 or 4)) =',len(v(1)) print*,'FF:v(1,2,3,4) =',v(1),',',v(2),',',v(3),',',v(4) print*,'FF:n =',n call ccff(v,n) return end integer function fg() implicit none integer ccg fg = ccg() return end character*(*) function fh() implicit none character*200 cch fh = cch() return end character*(*) function fi(v) implicit none character*(*) v(6) character*200 ci fi = ci(v) return end character*(*) function fj(v) implicit none integer v character*200 cj print*,'FJ:v =',v fj = cj(v) return end real function fk() implicit none real ck fk = ck() return end double precision function fl() implicit none double precision cl fl = cl() return end real function fm(r) implicit none external cm real cm,r fm = cm(r) return end double precision function fn(a,b) implicit none double precision cn,a,b fn = cn(a,b) return end subroutine vv(d,f,i) implicit none double precision d(2,2) real f(2,2) integer i(2,2) call cvv(d,f,i) return end double precision function v7(d) implicit none external cv7 double precision d(1,13,11,7,5,3,2), cv7 integer i,j,k,l,m,n,o print *, 'function cv7 returns the value ', cv7(d) v7 = 0 do 1 i=1, 2 do 1 j=1, 3 do 1 k=1, 5 do 1 l=1, 7 do 1 m=1, 11 do 1 n=1, 13 do 1 o=1, 1 v7 = v7 + d(o,n,m,l,k,j,i) 1 continue return end logical function fand(a,b) implicit none logical cand,a,b fand = cand(a,b) return end logical function forr(a,b) implicit none logical cor,a,b print *, 'FORTRAN thinks you called forr(a=',a,',b=',b,').' forr = cor(a,b) print *, 'FORTRAN thinks cor(a,b) returned with a=',a,',b=',b,').' if (a.eqv..true.)then print *,'Double check: a is true:',a endif if (a.eqv..false.)then print *,'Double check: a is false:',a endif if (.not.((a.eqv..false.) .or. (a.eqv..true.))) then print *,'Double check: ERROR: a is neither true nor false:',a print *,' Please contact burow@desy.de' endif if (b.eqv..true.)then print *,'Double check: b is true:',b endif if (b.eqv..false.)then print *,'Double check: b is false:',b endif if (.not.((b.eqv..false.) .or. (b.eqv..true.))) then print *,'Double check: ERROR: b is neither true nor false:',b print *,' Please contact burow@desy.de' endif C print *, ' ' C print *, ' Testing non-FORTRAN/77 (b .eq. .true.) which' C print *, ' will not compile on NAG f90 or Apollo or IBM RS/6000.' C print *, ' Compile cfortest.c with LOGICAL_STRICT defined' C print *, ' if you wish this test to work as expected.' C print *, ' This test requires a and b to match the internal ' C print *, ' representation of .TRUE. and .FALSE. exactly.' C if (a.eq..true.)then C print *,'Representation check: a matches .true.' C endif C if (a.eq..false.)then C print *,'Representation check: a matches .false.' C endif C if (.not.(a.eq..false. .or. a.eq..true.)) then C print *,'Representation check: ' C print *,' a matches neither .true. nor .false.' C endif C if (b.eq..true.)then C print *,'Representation check: b matches .true.' C endif C if (b.eq..false.)then C print *,'Representation check: b matches .false.' C endif C if (.not.(b.eq..false. .or. b.eq..true.)) then C print *,'Representation check: ' C print *,' b matches neither .true. nor .false.' C endif C print *,' ' return end subroutine fstrtok() implicit none character*70 cstrtok, a C Setting up NULL as the NULL pointer for cfortran.h using 4 NUL bytes. character NULL*4, NUL(4) equivalence (NULL,NUL) C HP-UX Fortran requires DATA statements to not follow executable statements. DATA a/'first+second-third+forth-fifth-sixth seventh'/ CSUNBUG Have to use an equivalenced NUL array to fill NULL with 4 NUL bytes CSUNBUG since Sun's 'Sep 8 1987 /usr/bin/f77' has a bug which didn't set NULL CSUNBUG to 4 NUL bytes in the following. CSUNBUG NULL = CHAR(0)//CHAR(0)//CHAR(0)//CHAR(0) NUL(1) = CHAR(0) NUL(2) = CHAR(0) NUL(3) = CHAR(0) NUL(4) = CHAR(0) C NUL character in a will force cfortran.h to pass address of a, C not of a copy as it usually does. a(70:) = NULL C String until the first '-', then until the first '+'. print *,cstrtok(a, '-') print *,cstrtok(NULL, '+') C Flush the rest of the string. C Recall cfortran.h kills all trailing blanks. i.e. FORTRAN ' ' -> C "". print *,cstrtok(NULL, ' ') C Further calls return nothing. print *,cstrtok(NULL, ' ') return end integer function fadd(a,b) implicit none integer a,b fadd = a + b return end integer function funadd(fun,a,b) implicit none external fun integer a,b,fun C WARNING FOR Alpha/OSF! C The DEC Fortran and the DEC C compilers of DEC OSF/1 [RT] V1.2 (Rev. 10) C will crash on this example as it stands. C See cfortran.doc for a cleaner example of this misbehavior. C Note that the routine funarg below, whose argument f is also an integer C function, does not have this problem. C This example will work if an extra argument is given to function 'fun'. C i.e. For Alpha/OSF replace the following line with the kludge: C funadd = fun(a,b,1) funadd = fun(a,b) return end subroutine funarg(f,a,b,c) implicit none external fadd3,f integer a,b,c,f c = f(fadd3,a,b) return end subroutine fadd3(a,b,c) implicit none integer a,b,c c = a + b return end subroutine fqsortex(size) implicit none C Because it's convinient here, we let C tell us the size of INTEGER. integer size integer base(10),cmp,i external cmp data base /1,10,2,9,3,8,4,7,5,6/ call fqsort(base,10,size,cmp) print '(10I3)', (base(i), i=1,10) return end integer function cmp(a,b) implicit none integer a,b cmp = a-b return end subroutine fstr() implicit none character*(4) a,b,c character*(1) d(5) character*(5) dd equivalence (d,dd) character*(16) n call pstru(n) print *,n,'<-' a = '1' a(2:2) = CHAR(0) call ppstr(a) b = '22' call pstr(b) print *,b,'<-' call pstr(b) print *,b,'<-' c(1:1) = CHAR(0) c(2:2) = CHAR(0) c(3:3) = CHAR(0) c(4:4) = CHAR(0) call pnstr(c) c = '333' c(4:4) = CHAR(0) call pnstr(c) call pnstr(b) print *,b,'<-' call pnstr(b) print *,b,'<-' c(1:1) = CHAR(0) c(2:2) = CHAR(0) c(3:3) = CHAR(0) c(4:4) = CHAR(0) call pnstr(c) d(1) = '1' d(2) = '2' d(3) = '3' d(4) = '4' d(5) = CHAR(0) C Need to use equivalenced dd because using d causes f90 to complain: C Error: Inconsistent structure for arg 1 in call to PPSTR at line 533 call ppstr(dd) call pstr(b) print *,b,'<-' call pstr(b) print *,b,'<-' return end subroutine f14(a,b,c,d,e,f,g,h,i,j,k,l,m,n) implicit none integer a,b,c,d,e,f,g,h,i,j,k,l,m,n call cf14(a,b,c,d,e,f,g,h,i,j,k,l,m,n) return end subroutine f20(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t) implicit none integer a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t call cf14(a,b,c,d,e,f,g,h,i,j,k,l,m,n) o = 15 p = 16 q = 17 r = 18 s = 19 t = 20 return end subroutine f27(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t + ,u,v,w,x,y,z,aa) implicit none integer a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t + ,u,v,w,x,y,z,aa call cf27(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t + ,u,v,w,x,y,z,aa) return end subroutine sz1(s, is, z, iz) implicit none integer is,iz,j character *(*) s(is), z(iz) print*,'SZ1:len(s(1)) =',len(s(1)), ' len(z(1)) =',len(z(1)) do 100 j = 1,is print*,'SZ1:s(',j,') =',s(j),'.' 100 continue do 200 j = 1,iz print*,'SZ1:z(',j,') =',z(j),'.' 200 continue return end subroutine pz(s, is, z, iz) implicit none integer is,iz,j character *(*) s(is),z(iz) print*,'PZ:len(s(1)) =',len(s(1)), ' len(z(1)) =',len(z(1)) do 100 j = 1,is print*,'PZ:s(',j,') =',s(j),'.' s(j) = '12345678' 100 continue do 200 j = 1,iz print*,'PZ:z(',j,') =',z(j),'.' z(j) = '12345678' 200 continue return end cfortran-4.4/cfortran.html0100644000175000017500000032441407563721253016142 0ustar kmccartykmccarty cfortran.h: Interfacing C or C++ and FORTRAN

cfortran.h: Interfacing C or C++ and FORTRAN


Author:Burkhard Burow
Email: burow@desy.de
www: www-zeus.desy.de/~burow/cfortran

Supports:

          Alpha and VAX VMS, Alpha OSF, DECstation and VAX Ultrix, IBM RS/6000, 
          Silicon Graphics, Sun, CRAY, Apollo, HP9000, LynxOS, Convex, Absoft,
          f2c, g77, NAG f90, PowerStation FORTRAN with Visual C++, NEC SX-4,
          Portland Group.
C and C++ are generally equivalent as far as cfortran.h is concerned. Unless explicitly noted otherwise, mention of C implicitly includes C++. C++ compilers tested include:

  SunOS> CC +p +w      # Clean compiles.
  IRIX>  CC            # Clean compiles.
  IRIX>  CC -fullwarn  # Still some warnings to be overcome.
  GNU>   g++ -Wall     # Compiles are clean, other than warnings for unused
                       #   cfortran.h static routines.
N.B.: The best documentation on interfacing C or C++ and FORTRAN is in the chapter named something like 'Interfacing C and FORTRAN' to be found in the user's guide of almost every FORTRAN compiler. Understanding this information for one or more FORTRAN compilers greatly clarifies the aims and actions of cfortran.h. Such a chapter generally also addresses issues orthogonal to cfortran.h, for example the order of array indices, the index of the first element, as well as compiling and linking issues.

Short Summary of the Syntax Required to Create the Interface

e.g. Prototyping a FORTRAN subroutine for C: PROTOCCALLSFSUBni is optional for C, but mandatory for C++.
                 PROTOCCALLSFSUB2(SUB_NAME,sub_name,STRING,PINT)
#define SUB_NAME(A,B) CCALLSFSUB2(SUB_NAME,sub_name,STRING,PINT, A,B)

                                ^     -                                       -
       number of arguments _____|    |   STRING   BYTE    PBYTE       BYTEV(..)|
                                  /  |   STRINGV  DOUBLE  PDOUBLE   DOUBLEV(..)|
                                 /   |  PSTRING   FLOAT   PFLOAT     FLOATV(..)|
        types of arguments ____ /    | PNSTRING   INT     PINT         INTV(..)|
                                \    | PPSTRING   LOGICAL PLOGICAL LOGICALV(..)|
                                 \   |  PSTRINGV  LONG    PLONG       LONGV(..)|
                                  \  |   ZTRINGV  SHORT   PSHORT     SHORTV(..)|
                                     |  PZTRINGV  ROUTINE PVOID      SIMPLE    |
                                      -                                       -
e.g. Prototyping a FORTRAN function for C:
/* PROTOCCALLSFFUNn is mandatory for both C and C++. */
PROTOCCALLSFFUN1(INT,FUN_NAME,fun_name,STRING)
#define FUN_NAME(A)  CCALLSFFUN1(FUN_NAME,fun_name,STRING, A)
e.g. calling FUN_NAME from C:
    {int a; a = FUN_NAME("hello");}
e.g. Creating a FORTRAN-callable wrapper for a C function returning void, with a 7 dimensional integer array argument: [Not supported from C++.]
FCALLSCSUB1(csub_name,CSUB_NAME,csub_name,INTVVVVVVV)
e.g. Creating a FORTRAN-callable wrapper for other C functions:
FCALLSCFUN1(STRING,cfun_name,CFUN_NAME,cfun_name,INT)
           [ ^-- BYTE, DOUBLE, FLOAT, INT, LOGICAL, LONG, SHORT, VOID  
             are other types returned by functions.       ]
e.g. COMMON BLOCKs:
FORTRAN:

                         common /fcb/  v,w,x
                                 character *(13) v, w(4), x(3,2)

C:

typedef struct { char v[13],w[4][13],x[2][3][13]; } FCB_DEF;
#define FCB COMMON_BLOCK(FCB,fcb)
COMMON_BLOCK_DEF(FCB_DEF,FCB);
FCB_DEF FCB;    /* Define, i.e. allocate memory, in exactly one *.c file. */
e.g. accessing FCB in C:
          printf("%.13s",FCB.v);

I) Introduction

cfortran.h is an easy-to-use powerful bridge between C and FORTRAN. It provides a completely transparent, machine independent interface between C and FORTRAN routines (= subroutines and/or functions) and global data, i.e. structures and COMMON blocks.

The complete cfortran.h package consists of 4 files: the documentation in cfortran.doc, the engine cfortran.h, examples in cfortest.c and cfortex.f/or. [cfortex.for under VMS, cfortex.f on other machines.]

The cfortran.h package continues to be developed. The most recent version is available via WWW at http://www-zeus.desy.de/~burow/cfortran.

The examples may be run using one of the following sets of instructions:

N.B. Unlike earlier versions, cfortran.h 3.0 and later versions automatically uses the correct ANSI ## or pre-ANSI /**/ preprocessor operator as required by the C compiler.

N.B. As a general rule when trying to determine how to link C and FORTRAN, link a trivial FORTRAN program using the FORTRAN compilers verbose option, in order to see how the FORTRAN compiler drives the linker. e.g.

       unix> cat f.f
                END
       unix> f77 -v f.f
       .. lots of info. follows ...

N.B. If using a C main(), i.e. FORTRAN PROGRAM is not entry of the executable, and if the link bombs with a complaint about a missing "MAIN" (e.g. MAIN__, MAIN_, f90_main or similar), then FORTRAN has hijacked the entry point to the executable and wishes to call the rest of the executable via "MAIN". This can usually be satisfied by doing e.g. 'cc -Dmain=MAIN__ ...' but often kills the command line arguments in argv and argc. The f77 verbose option, usually -v, may point to a solution.

RS/6000> # Users are strongly urged to use f77 -qextname and cc -Dextname
RS/6000> # Use -Dextname=extname if extname is a symbol used in the C code.
RS/6000> xlf -c -qextname cfortex.f
RS/6000> cc  -c -Dextname cfortest.c
RS/6000> xlf -o cfortest cfortest.o cfortex.o && cfortest 

DECFortran> #Only DECstations with DECFortran for Ultrix RISC Systems.
DECFortran> cc -c -DDECFortran cfortest.c
DECFortran> f77 -o cfortest cfortest.o cfortex.f  &&  cfortest

IRIX xxxxxx 5.2 02282015 IP20 mips
MIPS> # DECstations and Silicon Graphics using the MIPS compilers.
MIPS> cc -o cfortest cfortest.c cfortex.f -lI77 -lU77 -lF77  &&  cfortest
MIPS> # Can also let f77 drive linking, e.g.
MIPS> cc -c cfortest.c
MIPS> f77 -o cfortest cfortest.o cfortex.f  &&  cfortest

Apollo> # Some 'C compiler 68K Rev6.8' break. [See Section II o) Notes: Apollo]
Apollo> f77 -c cfortex.f && cc -o cfortest cfortest.c cfortex.o  &&  cfortest

VMS> define lnk$library sys$library:vaxcrtl
VMS> cc cfortest.c
VMS> fortran cfortex.for
VMS> link/exec=cfortest cfortest,cfortex
VMS> run cfortest

OSF1 xxxxxx V3.0 347 alpha
Alpha/OSF> # Probably better to let cc drive linking, e.g.
Alpha/OSF> f77 -c cfortex.f
Alpha/OSF> cc  -o cfortest cfortest.c cfortex.o -lUfor -lfor -lFutil -lots -lm
Alpha/OSF> cfortest
Alpha/OSF> # Else may need 'cc -Dmain=MAIN__' to let f77 drive linking.

Sun> # Some old cc(1) need a little help. [See Section II o) Notes: Sun]
Sun> f77 -o cfortest cfortest.c cfortex.f -lc -lm  &&  cfortest
Sun> # Some older f77 may require 'cc -Dmain=MAIN_'.

CRAY> cft77 cfortex.f
CRAY> cc -c cfortest.c
CRAY> segldr -o cfortest.e cfortest.o cfortex.o
CRAY> ./cfortest.e

NEC> cc -c -Xa cfortest.c
NEC> f77 -o cfortest cfortest.o cfortex.f  &&  cfortest

VAX/Ultrix/cc> # For cc on VAX Ultrix only, do the following once to cfortran.h.
VAX/Ultrix/cc> mv cfortran.h cftmp.h && grep -v "^#pragma" cfortran.h
                                            
VAX/Ultrix/f77> # In the following, 'CC' is either 'cc' or 'gcc -ansi'. NOT'vcc'
VAX/Ultrix/f77> CC -c -Dmain=MAIN_ cfortest.c
VAX/Ultrix/f77> f77 -o cfortest cfortex.f cfortest.o  &&  cfortest

LynxOS> # In the following, 'CC' is either 'cc' or 'gcc -ansi'.
LynxOS> # Unfortunately cc is easily overwhelmed by cfortran.h,
LynxOS> #  and won't compile some of the cfortest.c demos.
LynxOS> f2c -R cfortex.f
LynxOS> CC -Dlynx -o cfortest cfortest.c cfortex.c -lf2c  &&  cfortest

HP9000> # Tested with HP-UX 7.05 B 9000/380 and with A.08.07 A 9000/730
HP9000> # CC may be either 'c89 -Aa' or 'cc -Aa'
HP9000> #    Depending on the compiler version, you may need to include the
HP9000> #    option '-tp,/lib/cpp' or worse, you'll have to stick to the K&R C.
HP9000> #    [See Section II o) Notes: HP9000]
HP9000> # Users are strongly urged to use f77 +ppu and cc -Dextname
HP9000> # Use -Dextname=extname if extname is a symbol used in the C code.
HP9000> CC  -Dextname -c cfortest.c
HP9000> f77 +ppu         cfortex.f  -o cfortest cfortest.o && cfortest
HP9000> # Older f77 may need
HP9000> f77 -c cfortex.f
HP9000> CC -o cfortest cfortest.c cfortex.o -lI77 -lF77 && cfortest

HP0000> # If old-style f77 +800 compiled objects are required:
HP9000> # #define hpuxFortran800
HP9000> cc -c -Aa -DhpuxFortran800 cfortest.c
HP9000> f77 +800 -o cfortest cfortest.o cfortex.f

f2c> # In the following, 'CC' is any C compiler.
f2c> f2c -R cfortex.f
f2c> CC -o cfortest -Df2cFortran cfortest.c cfortex.c -lf2c  &&  cfortest

Portland Group $ # Presumably other C compilers also work.
Portland Group $ pgcc -DpgiFortran -c cfortest.c
Portland Group $ pgf77 -o cfortest cfortex.f cfortest.o && cfortest

NAGf90> # cfortex.f is distributed with FORTRAN 77 style comments.
NAGf90> # To convert to f90 style comments do the following once to cfortex.f: 
NAGf90> mv cfortex.f cf_temp.f && sed 's/^C/\!/g' cf_temp.f > cfortex.f
NAGf90> # In the following, 'CC' is any C compiler.
NAGf90> CC -c -DNAGf90Fortran cfortest.c
NAGf90> f90 -o cfortest cfortest.o cfortex.f &&  cfortest

PC> # On a PC with PowerStation FORTRAN and Visual_C++
PC> cl /c cftest.c
PC> fl32  cftest.obj cftex.for

GNU> # GNU FORTRAN
GNU> # See Section VI caveat on using 'gcc -traditional'.
GNU> gcc -ansi -Wall -O -c -Df2cFortran cfortest.c
GNU> g77 -ff2c -o cfortest cfortest.o cfortex.f &&  cfortest

AbsoftUNIX> # Absoft FORTRAN for all UNIX based operating systems.
AbsoftUNIX> # e.g. Linux or Next on Intel or Motorola68000.
AbsoftUNIX> # Absoft f77 -k allows FORTRAN routines to be safely called from C.
AbsoftUNIX> gcc -ansi -Wall -O -c -DAbsoftUNIXFortran cfortest.c
AbsoftUNIX> f77 -k -o cfortest cfortest.o cfortex.f && cfortest

AbsoftPro> # Absoft Pro FORTRAN for MacOS
AbsoftPro> # Use #define AbsoftProFortran

CLIPPER> # INTERGRAPH CLIX using CLIPPER C and FORTRAN compilers.
CLIPPER> # N.B. - User, not cfortran.h, is responsible for
CLIPPER> #        f77initio() and f77uninitio() if required.
CLIPPER> #      - LOGICAL values are not mentioned in CLIPPER doc.s,
CLIPPER> #        so they may not yet be correct in cfortran.h.
CLIPPER> #      - K&R mode (-knr or Ac=knr) breaks FLOAT functions
CLIPPER> #        (see CLIPPER doc.s) and cfortran.h does not fix it up.
CLIPPER> #        [cfortran.h ok for old sun C which made the same mistake.]
CLIPPER> acc cfortest.c -c -DCLIPPERFortran
CLIPPER> af77 cfortex.f cfortest.o -o cfortest
By changing the SELECTion ifdef of cfortest.c and recompiling one can try out a few dozen different few-line examples.

The benefits of using cfortran.h include:

  1. Machine/OS/compiler independent mixing of C and FORTRAN.

  2. Identical (within syntax) calls across languages, e.g.
    FORTRAN:
    
          CALL HBOOK1(1,'pT spectrum of pi+',100,0.,5.,0.)
    
    C:
          HBOOK1(1,"pT spectrum of pi+",100,0.,5.,0.);
    

  3. Each routine need only be set up once in its lifetime. e.g. Setting up a FORTRAN routine to be called by C. ID,...,VMX are merely the names of arguments. These tags must be unique w.r.t. each other but are otherwise arbitrary.
    PROTOCCALLSFSUB6(HBOOK1,hbook1,INT,STRING,INT,FLOAT,FLOAT,FLOAT)
    #define HBOOK1(ID,CHTITLE,NX,XMI,XMA,VMX)                        \
         CCALLSFSUB6(HBOOK1,hbook1,INT,STRING,INT,FLOAT,FLOAT,FLOAT, \
                   ID,CHTITLE,NX,XMI,XMA,VMX) 
    

  4. Source code is NOT required for the C routines exported to FORTRAN, nor for the FORTRAN routines imported to C. In fact, routines are most easily prototyped using the information in the routines' documentation.

  5. Routines, and the code calling them, can be coded naturally in the language of choice. C routines may be coded with the natural assumption of being called only by C code. cfortran.h does all the required work for FORTRAN code to call C routines. Similarly it also does all the work required for C to call FORTRAN routines. Therefore:
    • C programmers need not embed FORTRAN argument passing mechanisms into their code.
    • FORTRAN code need not be converted into C code. i.e. The honed and time-honored FORTRAN routines are called by C.

  6. cfortran.h is a single ~1700 line C include file; portable to most remaining, if not all, platforms.

  7. STRINGS and VECTORS of STRINGS along with the usual simple arguments to routines are supported as are functions returning STRINGS or numbers. Arrays of pointers to strings and values of structures as C arguments, will soon be implemented. After learning the machinery of cfortran.h, users can expand it to create custom types of arguments. [This requires no modification to cfortran.h, all the preprocessor directives required to implement the custom types can be defined outside cfortran.h]

  8. cfortran.h requires each routine to be exported to be explicitly set up. While is usually only be done once in a header file it would be best if applications were required to do no work at all in order to cross languages. cfortran.h's simple syntax could be a convenient back-end for a program which would export FORTRAN or C routines directly from the source code.

Example 1

cfortran.h has been used to make the C header file hbook.h, which then gives any C programmer, e.g. example.c, full and completely transparent access to CERN's HBOOK library of routines. Each HBOOK routine required about 3 lines of simple code in hbook.h. The example also demonstrates how FORTRAN common blocks are defined and used.
/* hbook.h */
#include "cfortran.h"
        :
PROTOCCALLSFSUB6(HBOOK1,hbook1,INT,STRING,INT,FLOAT,FLOAT,FLOAT)
#define HBOOK1(ID,CHTITLE,NX,XMI,XMA,VMX)                        \
     CCALLSFSUB6(HBOOK1,hbook1,INT,STRING,INT,FLOAT,FLOAT,FLOAT, \
               ID,CHTITLE,NX,XMI,XMA,VMX) 
        :
/* end hbook.h */



/* example.c */
#include "hbook.h"
        :
typedef struct {
  int lines;  
  int status[SIZE];
  float p[SIZE];  /* momentum */
} FAKE_DEF;
#define FAKE COMMON_BLOCK(FAKE,fake)
COMMON_BLOCK_DEF(FAKE_DEF,FAKE);
        :
main ()
{
        :
           HBOOK1(1,"pT spectrum of pi+",100,0.,5.,0.);
/* c.f. the call in FORTRAN:
      CALL HBOOK1(1,'pT spectrum of pi+',100,0.,5.,0.)
*/
        :
  FAKE.p[7]=1.0;
	:
}           
N.B.
  1. The routine is language independent.
  2. hbook.h is machine independent.
  3. Applications using routines via cfortran.h are machine independent.

Example 2

Many VMS System calls are most easily called from FORTRAN, but cfortran.h now gives that ease in C.
#include "cfortran.h"

PROTOCCALLSFSUB3(LIB$SPAWN,lib$spawn,STRING,STRING,STRING)
#define LIB$SPAWN(command,input_file,output_file)          \
     CCALLSFSUB3(LIB$SPAWN,lib$spawn,STRING,STRING,STRING, \
                  command,input_file,output_file)

main ()
{
LIB$SPAWN("set term/width=132","","");
}
Obviously the cfortran.h command above could be put into a header file along with the description of the other system calls, but as this example shows, it's not much hassle to set up cfortran.h for even a single call.

Example 3

cfortran.h and the source cstring.c create the cstring.obj library which gives FORTRAN access to all the functions in C's system library described by the system's C header file string.h.
C     EXAMPLE.FOR
      PROGRAM EXAMPLE
      DIMENSION I(20), J(30)
        :
      CALL MEMCPY(I,J,7)
        :
      END

/* cstring.c */
#include              /* string.h prototypes memcpy() */
#include "cfortran.h"

        :
FCALLSCSUB3(memcpy,MEMCPY,memcpy,PVOID,PVOID,INT)
        :
The simplicity exhibited in the above example exists for many but not all machines. Note 4. of Section II ii) details the limitations and describes tools which try to maintain the best possible interface when FORTRAN calls C routines.

II) Using cfortran.h

The user is asked to look at the source files cfortest.c and cfortex.f for clarification by example.

o) Notes:

  • Specifying the FORTRAN compiler

    cfortran.h generates interfaces for the default i FORTRAN compiler. The default can be overridden by defining with one of the follwoing methods,

    • in the code, e.g.: #define NAGf90Fortran

    • in the compile directive, e.g.: unix> cc -DNAGf90Fortran
    one of the following before including cfortran.h:
     NAGf90Fortran   f2cFortran  hpuxFortran  apolloFortran  sunFortran
      IBMR2Fortran  CRAYFortran  mipsFortran     DECFortran  vmsFortran
     CONVEXFortran       PowerStationFortran          AbsoftUNIXFortran
         SXFortran   pgiFortran                        AbsoftProFortran
    
    This also allows crosscompilation.

    If wanted, NAGf90Fortran, f2cFortran, DECFortran, AbsoftUNIXFortran, AbsoftProFortran and pgiFortran must be requested by the user.

  • /**/

    cfortran.h (ab)uses the comment kludge /**/ when the ANSI C preprocessor catenation operator ## doesn't exist. In at least MIPS C, this kludge is sensitive to blanks surrounding arguments to macros. Therefore, for applications using non-ANSI C compilers, the argtype_i, routine_name, routine_type and common_block_name arguments to the PROTOCCALLSFFUNn, CCALLSFSUB/FUNn, FCALLSCSUB/FUNn and COMMON_BLOCK macros must not be followed by any white space characters such as blanks, tabs or newlines.

  • LOGICAL

    FORTRAN LOGICAL values of .TRUE. and .FALSE. do not agree with the C representation of TRUE and FALSE on all machines. cfortran.h does the conversion for LOGICAL and PLOGICAL arguments and for functions returning LOGICAL. Users must convert arrays of LOGICALs from C to FORTRAN with the C2FLOGICALV(array_name, elements_in_array); macro. Similarly, arrays of LOGICAL values may be converted from the FORTRAN into C representation by using F2CLOGICALV(array_name, elements_in_array);

    When C passes or returns LOGICAL values to FORTRAN, by default cfortran.h only makes the minimal changes required to the value. [e.g. Set/Unset the single relevant bit or do nothing for FORTRAN compilers which use 0 as FALSE and treat all other values as TRUE.] Therefore cfortran.h will pass LOGICALs to FORTRAN which do not have an identical representation to .TRUE. or .FALSE. This is fine except for abuses of FORTRAN/77 in the style of:

           logical l
           if (l .eq. .TRUE.)     ! (1)
    
    instead of the correct:
           if (l .eqv. .TRUE.)    ! (2)
    
    or:
           if (l)                 ! (3)
    
    For FORTRAN code which treats LOGICALs from C in the method of (1), LOGICAL_STRICT must be defined before including cfortran.h, either in the code, "#define LOGICAL_STRICT", or compile with "cc -DLOGICAL_STRICT". There is no reason to use LOGICAL_STRICT for FORTRAN code which does not do (1). At least the IBM's xlf and the Apollo's f77 do not even allow code along the lines of (1).

    DECstations' DECFortran and MIPS FORTRAN compilers use different internal representations for LOGICAL values. [Both compilers are usually called f77, although when both are installed on a single machine the MIPS' one is usually renamed. (e.g. f772.1 for version 2.10.)] cc doesn't know which FORTRAN compiler is present, so cfortran.h assumes MIPS f77. To use cc with DECFortran define the preprocessor constant 'DECFortran'. e.g.

                i)  cc -DDECFortran -c the_code.c
    
    or
                ii) #define DECFortran  /* in the C code or add to cfortran.h. */
    
    MIPS f77 [SGI and DECstations], f2c, and f77 on VAX Ultrix treat .eqv./.neqv. as .eq./.ne.. Therefore, for these compilers, LOGICAL_STRICT is defined by default in cfortran.h. [The Sun and HP compilers have not been tested, so they may also require LOGICAL_STRICT as the default.]

  • SHORT and BYTE

    They are irrelevant for the CRAY where FORTRAN has no equivalent to C's short. Similarly BYTE is irrelevant for f2c and for VAX Ultrix f77 and fort. The author has tested SHORT and BYTE with a modified cfortest.c/cfortex.f on all machines supported except for the HP9000 and the Sun.

    BYTE is a signed 8-bit quantity, i.e. values are -128 to 127, on all machines except for the SGI [at least for MIPS Computer Systems 2.0.] On the SGI it is an unsigned 8-bit quantity, i.e. values are 0 to 255, although the SGI 'FORTRAN 77 Programmers Guide' claims BYTE is signed. Perhaps MIPS 2.0 is dated, since the DECstations using MIPS 2.10 f77 have a signed BYTE.

    To minimize the difficulties of signed and unsigned BYTE, cfortran.h creates the type 'INTEGER_BYTE' to agree with FORTRAN's BYTE. Users may define SIGNED_BYTE or UNSIGNED_BYTE, before including cfortran.h, to specify FORTRAN's BYTE. If neither is defined, cfortran.h assumes SIGNED_BYTE.

  • CRAY

    The type DOUBLE in cfortran.h corresponds to FORTRAN's DOUBLE PRECISION. The type FLOAT in cfortran.h corresponds to FORTRAN's REAL.

    On a classic CRAY [i.e. all models except for the t3e]:

    ( 64 bit) C float       == C double == FORTRAN REAL
    (128 bit) C long double             == FORTRAN DOUBLE PRECISION
    
    Therefore when moving a mixed C and FORTRAN app. to/from a classic CRAY, either the C code will have to change, or the FORTRAN code and cfortran.h declarations will have to change. DOUBLE_PRECISION is a cfortran.h macro which provides the former option, i.e. the C code is automatically changed. DOUBLE_PRECISION is 'long double' on classic CRAY and 'double' elsewhere. DOUBLE_PRECISION thus corresponds to FORTRAN's DOUBLE PRECISION on all machines, including classic CRAY.

    On a classic CRAY with the FORTRAN compiler flag '-dp': FORTRAN DOUBLE PRECISION thus is also the faster 64bit type. (This switch is often used since the application is usually satisfied by 64 bit precision and the application needs the speed.) DOUBLE_PRECISION is thus not required in this case, since the classic CRAY behaves like all other machines. If DOUBLE_PRECISION is used nonetheless, then on the classic CRAY the default cfortran.h behavior must be overridden, for example by the C compiler option '-DDOUBLE_PRECISION=double'.

    On a CRAY t3e:

    (32 bit) C float                   == FORTRAN Unavailable
    (64 bit) C double == C long double == FORTRAN REAL == FORTRAN DOUBLE PRECISION
    
    Notes:

    • (32 bit) is available as FORTRAN REAL*4 and (64 bit) is available as FORTRAN REAL*8. Since cfortran.h is all about more portability, not about less portability, the use of the nonstandard REAL*4 and REAL*8 is strongly discouraged.

    • FORTRAN DOUBLE PRECISION is folded to REAL with the following warning:
          DOUBLE PRECISION is not supported on this platform.  REAL will be used.
      
      Similarly, FORTRAN REAL*16 is mapped to REAL*8 with a warning. This behavior differs from that of other machines, including the classic CRAY. FORTRAN_REAL is thus introduced for the t3e, just as DOUBLE_PRECISION is introduced for the classic CRAY. FORTRAN_REAL is 'double' on t3e and 'float' elsewhere. FORTRAN_REAL thus corresponds to FORTRAN's REAL on all machines, including t3e.

  • f2c

    f2c, by default promotes REAL functions to double. cfortran.h does not (yet) support this, so the f2c -R option must be used to turn this promotion off.

  • f2c

    [Thanks to Dario Autiero for pointing out the following.] f2c has a strange feature in that either one or two underscores are appended to a FORTRAN name of a routine or common block, depending on whether or not the original name contains an underscore.

       S.I. Feldman et al., "A FORTRAN to C converter",
       Computing Science Technical Report No. 149.
    
       page 2, chapter 2: INTERLANGUAGE conventions
       ...........
    
    To avoid conflict with the names of library routines and with names that f2c generates, FORTRAN names may have one or two underscores appended. FORTRAN names are forced to lower case (unless the -U option described in Appendix B is in effect); external names, i.e. the names of FORTRAN procedures and common blocks, have a single underscore appended if they do not contain any underscore and have a pair of underscores appended if they do contain underscores. Thus FORTRAN subroutines names ABC, A_B_C and A_B_C_ result in C functions named abc_, a_b_c__ and a_b_c___.

    cfortran.h is unable to change the naming convention on a name by name basis. FORTRAN routine and common block names which do not contain an underscore are unaffected by this feature. Names which do contain an underscore may use the following work-around:

    /* First 2 lines are a completely standard cfortran.h interface
       to the FORTRAN routine E_ASY . */
                      PROTOCCALLSFSUB2(E_ASY,e_asy, PINT, INT)
    #define E_ASY(A,B)     CCALLSFSUB2(E_ASY,e_asy, PINT, INT, A, B)
    #ifdef f2cFortran
    #define e_asy_ e_asy__
    #endif
    /* Last three lines are a work-around for the strange f2c naming feature. */
    

  • NAG f90

    The FORTRAN 77 subset of FORTRAN 90 is supported. Extending cfortran.h to interface C with all of FORTRAN 90 has not yet been examined.
    The NAG f90 library hij acks the main() of any program and starts the user's program with a call to: void f90_main(void);
    While this in itself is only a minor hassle, a major problem arises because NAG f90 provides no mechanism to access command line arguments.
    At least version 'NAGWare f90 compiler Version 1.1(334)' appended _CB to common block names instead of the usual _. To fix, add this to cfortran.h:

    #ifdef old_NAG_f90_CB_COMMON
    #define COMMON_BLOCK                 CFC_  /* for all other Fortran compilers */
    #else
    #define COMMON_BLOCK(UN,LN)          _(LN,_CB)
    #endif
    

  • RS/6000

    Using "xlf -qextname ...", which appends an underscore, '_', to all FORTRAN external references, requires "cc -Dextname ..." so that cfortran.h also generates these underscores. Use i-Dextname=extname if extname is a symbol used in the C code. The use of "xlf -qextname" is strongly encouraged, since it allows for transparent naming schemes when mixing C and FORTRAN.

  • HP9000

    Using "f77 +ppu ...", which appends an underscore, '_', to all FORTRAN external references, requires "cc -Dextname ..." so that cfortran.h also generates these underscores. Use -Dextname=extname if extname is a symbol used in the C code. The use of "f77 +ppu" is strongly encouraged, since it allows for transparent naming schemes when mixing C and FORTRAN.

    At least one release of the HP /lib/cpp.ansi preprocessor is broken and will go into an infinite loop when trying to process cfortran.h with the ## catenation operator. The K&R version of cfortran.h must then be used and the K&R preprocessor must be specified. e.g.

    HP9000> cc -Aa -tp,/lib/cpp -c source.c
    
    The same problem with a similar solution exists on the Apollo. An irrelevant error message '0: extraneous name /usr/include' will appear for each source file due to another HP bug, and can be safely ignored. e.g.
    cc -v -c -Aa -tp,/lib/cpp cfortest.c
    
    will show that the driver passes '-I /usr/include' instead of '-I/usr/include' to /lib/cpp

    On some machines the above error causes compilation to stop; one must then use K&R C, as with old HP compilers which don't support function prototyping. cfortran.h has to be informed that K&R C is to being used, e.g.

    HP9000> cc -D__CF__KnR -c source.c
    

  • AbsoftUNIXFortran

    By default, cfortran.h follows the default AbsoftUNIX/ProFortran and prepends _C to each common block name. To override the cfortran.h behavior #define COMMON_BLOCK(UN,LN) before including cfortran.h. [Search for COMMON_BLOCK in cfortran.h for examples.]

  • Apollo

    On at least one release, 'C compiler 68K Rev6.8(168)', the default C preprocessor, from cc -A xansi or cc -A ansi, enters an infinite loop when using cfortran.h. This Apollo bug can be circumvented by using:

    • cc -DANSI_C_preprocessor=0 to force use of /**/, instead of '##'.

      AND

    • The pre-ANSI preprocessor, i.e. use cc -Yp,/usr/lib

    The same problem with a similar solution exists on the HP.

  • Sun

    Old versions of cc(1), say <~1986, may require help for cfortran.h applications:

    • #pragma may not be understood, hence cfortran.h and cfortest.c may require
      sun> mv cfortran.h cftmp.h && grep -v "^#pragma" cfortran.h
      sun> mv cfortest.c cftmp.c && grep -v "^#pragma" cfortest.c
      

    • Old copies of math.h may not include the following from a newer math.h. [For an ancient math.h on a 386 or sparc, get similar from a new math.h.]
       #ifdef mc68000     /* 5 lines Copyright (c) 1988 by Sun Microsystems, Inc. */
       #define FLOATFUNCTIONTYPE	int
       #define RETURNFLOAT(x) 		return (*(int *)(&(x)))
       #define ASSIGNFLOAT(x,y)	*(int *)(&x) = y
       #endif
    

  • CRAY, Sun, Apollo [pre 6.8 cc], VAX Ultrix and HP9000

    Only FORTRAN routines with less than 15 arguments can be prototyped for C, since these compilers don't allow more than 31 arguments to a C macro. This can be overcome, [see Section IV], with access to any C compiler without this limitation, e.g. gcc, on ANY machine.

  • VAX Ultrix

    vcc (1) with f77 is not supported. Although:

    VAXUltrix> f77 -c cfortex.f
    VAXUltrix> vcc -o cfortest cfortest.c cfortex.o -lI77 -lU77 -lF77  &&  cfortest
    
    will link and run. However, the FORTRAN standard I/O is NOT merged with the stdin and stdout of C, and instead uses the files fort.6 and fort.5. For vcc, f77 can't drive the linking, as for gcc and cc, since vcc objects must be linked using lk (1). f77 -v doesn't tell much, and without VAX Ultrix manuals, the author can only wait for the info. required.

    fort (1) is not supported. Without VAX Ultrix manuals the author cannot convince vcc/gcc/cc and fort to generate names of routines and common blocks that match at the linker, lk (1). i.e. vcc/gcc/cc prepend a single underscore to external references, e.g. NAME becomes _NAME, while fort does not modify the references. So ... either fort has prepend an underscore to external references, or vcc/gcc/cc have to generate unmodified names. man 1 fort mentions JBL, is JBL the only way?

  • VAX VMS C

    The compiler 'easily' exhausts its table space and generates:

    %CC-F-BUGCHECK, Compiler bug check during parser phase    .
                    Submit an SPR with a problem description.
                    At line number 777 in DISK:[DIR]FILE.C;1.
    
    where the line given, '777', includes a call across C and FORTRAN via cfortran.h, usually with >7 arguments and/or very long argument expressions.

    This SPR can be staved off, with the simple modification to cfortran.h, such that the relevant CCALLSFSUBn (or CCALLSFFUNn or FCALLSCFUNn) is not cascaded up to CCALLSFSUB14, and instead has its own copy of the contents of CCALLSFSUB14. [If these instructions are not obvious after examining cfortran.h please contact the author.]
    [Thanks go to Mark Kyprianou (kyp@stsci.edu) for this solution.]

  • Mips compilers

    e.g. DECstations and SGI, require applications with a C main() and calls to GETARG(3F), i.e. FORTRAN routines returning the command line arguments, to use two macros as shown:

            :
    CF_DECLARE_GETARG;              /* This must be external to all routines.     */
            :
    main(int argc, char *argv[])
    {
            :
    CF_SET_GETARG(argc,argv);       /* This must precede any calls to GETARG(3F). */
            :
    }
    
    The macros are null and benign on all other systems. Sun's GETARG(3F) also doesn't work with a generic C main() and perhaps a workaround similar to the Mips' one exists.

  • Alpha/OSF

    Using the DEC FORTRAN and the DEC C compilers of DEC OSF/1 [RT] V1.2 (Rev. 10), FORTRAN, when called from C, has occasional trouble using a routine received as a dummy argument. e.g. In the following the FORTRAN routine 'e' will crash when it tries to use the C routine 'c' or the FORTRAN routine 'f'. The example works on other systems.

    C FORTRAN                           /* C */
          integer function f()          #include 
          f = 2                         int f_();
          return                        int e_(int (*u)());
          end
                                        int c(){ return 1;}
          integer function e(u)         int d (int (*u)()) { return u();}
          integer u
          external u                    main()
          e=u()                         {         /* Calls to d  work.  */
          return                        printf("d (c ) returns %d.\n",d (c ));
          end                           printf("d (f_) returns %d.\n",d (f_));
                                                  /* Calls to e_ crash. */
                                        printf("e_(c ) returns %d.\n",e_(c ));
                                        printf("e_(f_) returns %d.\n",e_(f_));
                                        }
    
    Solutions to the problem are welcomed! A kludge which allows the above example to work correctly, requires an extra argument to be given when calling the dummy argument function. i.e. Replacing 'e=u()' by 'e=u(1)' allows the above example to work.

  • The FORTRAN routines are called using macro expansions, therefore the usual caveats for expressions in arguments apply. The expressions to the routines may be evaluated more than once, leading to lower performance and in the worst case bizarre bugs.

  • For those who wish to use cfortran.h in large applications. [See Section IV.] This release is intended to make it easy to get applications up and running. This implies that applications are not as efficient as they could be:

    • The current mechanism is inefficient if a single header file is used to describe a large library of FORTRAN functions. Code for a static wrapper fn. is generated in each piece of C source code for each FORTRAN function specified with the CCALLSFFUNn statement, irrespective of whether or not the function is ever called.

    • Code for several static utility routines internal to cfortran.h is placed into any source code which #includes cfortran.h. These routines should probably be in a library.

i) Calling FORTRAN routines from C:

The FORTRAN routines are defined by one of the following two instructions:

for a SUBROUTINE:

/* PROTOCCALLSFSUBn is optional for C, but mandatory for C++. */
PROTOCCALLSFSUBn(ROUTINE_NAME,routine_name,argtype_1,...,argtype_n)
#define     Routine_name(argname_1,..,argname_n)               \
CCALLSFSUBn(ROUTINE_NAME,routine_name,argtype_1,...,argtype_n, \
                         argname_1,..,argname_n) 
for a FUNCTION:
PROTOCCALLSFFUNn(routine_type,ROUTINE_NAME,routine_name,argtype_1,...,argtype_n)
#define     Routine_name(argname_1,..,argname_n)               \
CCALLSFFUNn(ROUTINE_NAME,routine_name,argtype_1,...,argtype_n, \
                         argname_1,..,argname_n) 
Where:
'n' = 0->14 [SUBROUTINE's ->27] (easily expanded in cfortran.h to > 14 [27]) is 
    the number of arguments to the routine.
Routine_name = C       name of the routine (IN UPPER CASE LETTERS).[see 2.below]
ROUTINE_NAME = FORTRAN name of the routine (IN UPPER CASE LETTERS).
routine_name = FORTRAN name of the routine (IN lower case LETTERS).
routine_type = the type of argument returned by FORTRAN functions.
             = BYTE, DOUBLE, FLOAT, INT, LOGICAL, LONG, SHORT, STRING, VOID.
               [Instead of VOID one would usually use CCALLSFSUBn.
                VOID forces a wrapper function to be used.]
argtype_i    = the type of argument passed to the FORTRAN routine and must be
               consistent in the definition and prototyping of the routine s.a.
             = BYTE, DOUBLE, FLOAT, INT, LOGICAL, LONG, SHORT, STRING.
             For vectors, i.e. 1 dim. arrays use 
             = BYTEV, DOUBLEV, FLOATV, INTV, LOGICALV, LONGV, SHORTV, 
               STRINGV, ZTRINGV.
             For vectors of vectors, i.e. 2 dim. arrays use
             = BYTEVV, DOUBLEVV, FLOATVV, INTVV, LOGICALVV, LONGVV, SHORTVV.
             For n-dim. arrays, 1<=n<=7 [7 is the maximum in FORTRAN 77],
             = BYTEV..nV's..V, DOUBLEV..V, FLOATV..V, INTV..V, LOGICALV..V, 
               LONGV..V, SHORTV..V.
                N.B. Array dimensions and types are checked by the C compiler.
             For routines changing the values of an argument, the keyword is 
                  prepended by a 'P'.
             = PBYTE, PDOUBLE, PFLOAT, PINT, PLOGICAL, PLONG, PSHORT,
               PSTRING, PSTRINGV, PZTRINGV.
             For EXTERNAL procedures passed as arguments use
             = ROUTINE.
             For exceptional arguments which require no massaging to fit the
                  argument passing mechanisms use
             = PVOID.
                The argument is cast and passed as (void *).
                Although PVOID could be used to describe all array arguments on
                most (all?) machines , it shouldn't be because the C compiler
                can no longer check the type and dimension of the array.
argname_i    = any valid unique C tag, but must be consistent in the definition 
               as shown.
Notes:

  1. cfortran.h may be expanded to handle a more argument type. To suppport new arguments requiring complicated massaging when passed between FORTRAN and C, the user will have to understand cfortran.h and follow its code and mechanisms.

    To define types requiring little or no massaging when passed between FORTRAN and C, the pseudo argument type SIMPLE may be used. For a user defined type called 'newtype', the definitions required are:

    /* The following 7 lines are required verbatim.
       'newtype' is the name of the new user defined argument type.
    */
    #define newtype_cfV(  T,A,B,F)       SIMPLE_cfV(T,A,B,F)
    #define newtype_cfSEP(T,  B)         SIMPLE_cfSEP(T,B)
    #define newtype_cfINT(N,A,B,X,Y,Z)   SIMPLE_cfINT(N,A,B,X,Y,Z)
    #define newtype_cfSTR(N,T,A,B,C,D,E) SIMPLE_cfSTR(N,T,A,B,C,D,E)
    #define newtype_cfCC( T,A,B)         SIMPLE_cfCC(T,A,B)
    #define newtype_cfAA( T,A,B)         newtype_cfB(T,A) /* Argument B not used. */
    #define newtype_cfU(  T,A)           newtype_cfN(T,A)
    
    /* 'parameter_type(A)' is a declaration for 'A' and describes the type of the 
    parameter expected by the FORTRAN function.  This type will be used in the
    prototype for the function, if  using ANSI C, and to declare the argument used
    by the intermediate function if calling a FORTRAN FUNCTION.
    Valid 'parameter_type(A)' include: int A
                                       void (*A)()
                                       double A[17]
    */
    #define newtype_cfN(  T,A)     parameter_type(A)      /* Argument T not used. */
    
    /* Before any argument of the new type is passed to the FORTRAN routine, it may
    be massaged as given by 'massage(A)'.
    */
    #define newtype_cfB(  T,A)     massage(A)             /* Argument T not used. */
    
    An example of a simple user defined type is given cfortex.f and cfortest.c.
    Two uses of SIMPLE user defined types are [don't show the 7 verbatim #defines]:
    
    /* Pass the address of a structure, using a type called PSTRUCT */
    #define PSTRUCT_cfN(  T,A)        void *A
    #define PSTRUCT_cfB(  T,A)       (void *) &(A)
    
    /* Pass an integer by value, (not standard F77 ), using a type called INTVAL */
    #define INTVAL_cfN(   T,A)      int A
    #define INTVAL_cfB(   T,A)         (A)
    
    [If using VAX VMS, surrounding the #defines with "#pragma (no)standard" allows
     the %CC-I-PARAMNOTUSED messages to be avoided.]
    
    Upgrades to cfortran.h try to be, and have been, backwards compatible. This compatibility cannot be offered to user defined types. SIMPLE user defined types are less of a risk since they require so little effort in their creation. If a user defined type is required in more than one C header file of interfaces to libraries of FORTRAN routines, good programming practice, and ease of code maintenance, suggests keeping any user defined type within a single file which is #included as required. To date, changes to the SIMPLE macros were introduced in versions 2.6, 3.0 and 3.2 of cfortran.h.

  2. Routine_name is the name of the macro which the C programmer will use in order to call a FORTRAN routine. In theory Routine_name could be any valid and unique name, but in practice, the name of the FORTRAN routine in UPPER CASE works everywhere and would seem to be an obvious choice.

  3. [BYTE|DOUBLE|BYTE|DOUBLE|FLOAT|INT|LOGICAL|LONG|SHORT][V|VV|VVV|...]

    cfortran.h encourages the exact specification of the type and dimension of array parameters because it allows the C compiler to detect errors in the arguments when calling the routine.

    cfortran.h does not strictly require the exact specification since the argument is merely the address of the array and is passed on to the calling routine. Any array parameter could be declared as PVOID, but this circumvents C's compiletime ability to check the correctness of arguments and is therefore discouraged.

    Passing the address of these arguments implies that PBYTEV, PFLOATV, ... , PDOUBLEVV, ... don't exist in cfortran.h, since by default the routine and the calling code share the same array, i.e. the same values at the same memory location.

    These comments do NOT apply to arrays of (P)S/ZTRINGV. For these parameters, cfortran.h passes a massaged copy of the array to the routine. When the routine returns, S/ZTRINGV ignores the copy, while PS/ZTRINGV replaces the calling code's original array with copy, which may have been modified by the called routine.

  4. (P)STRING(V):

    • STRING

      If the argument is a fixed length character array, e.g. char ar[8];, the string is blank, ' ', padded on the right to fill out the array before being passed to the FORTRAN routine. The useful size of the string is the same in both languages, e.g. ar[8] is passed as character*7. If the argument is a pointer, the string cannot be blank padded, so the length is passed as strlen(argument). On return from the FORTRAN routine, pointer arguments are not disturbed, but arrays have the terminating '\0' replaced to its original position. i.e. The padding blanks are never visible to the C code.

    • PSTRING

      The argument is massaged as with STRING before being passed to the FORTRAN routine. On return, the argument has all trailing blanks removed, regardless of whether the argument was a pointer or an array.

    • (P)STRINGV

      Passes a 1- or 2-dimensional char array. e.g. char a[7],b[6][8]; STRINGV may thus also pass a string constant, e.g. "hiho". (P)STRINGV does NOT pass a pointer, e.g. char *, to either a 1- or a 2-dimensional array, since it cannot determine the array dimensions. A pointer can only be passed using (P)ZTRINGV.

      N.B. If a C routine receives a character array argument, e.g. char a[2][3], such an argument is actually a pointer and my thus not be passed by (P)STRINGV. Instead (P)ZTRINGV must be used.

    • STRINGV

      The elements of the argument are copied into space malloc'd, and each element is padded with blanks. The useful size of each element is the same in both languages. Therefore char bb[6][8]; is equivalent to character*7 bb(6). On return from the routine the malloc'd space is simply released.

    • PSTRINGV

      Since FORTRAN has no trailing '\0', elements in an array of strings are contiguous. Therefore each element of the C array is padded with blanks and strip out C's trailing '\0'. After returning from the routine, the trailing '\0' is reinserted and kill the trailing blanks in each element.

    Summary: STRING(V) arguments are blank padded during the call to the FORTRAN routine, but remain original in the C code. (P)STRINGV arguments are blank padded for the FORTRAN call, and after returning from FORTRAN trailing blanks are stripped off.

  5. (P)ZTRINGV:

    • (P)ZTRINGV - is identical to (P)STRINGV, except that the dimensions of the array of strings is explicitly specified, which thus also allows a pointer to be passed. (P)ZTRINGV can thus pass a 1- or 2-dimensional char array, e.g. char b[6][8], or it can pass a pointer to such an array, e.g. char *p;. ZTRINGV may thus also pass a string constant, e.g. "hiho". If passing a 1-dimensional array, routine_name_ELEMS_j (see below) must be 1. [Users of (P)ZTRINGV should examine cfortest.c for examples.]:

    • (P)ZTRINGV must thus be used instead of (P)STRINGV whenever sizeof() can't be used to determine the dimensions of the array of string or strings. e.g. when calling FORTRAN from C with a char * received by C as an argument.

    • There is no (P)ZTRING type, since (P)ZTRINGV can pass a 1-dimensional array or a pointer to such an array, e.g. char a[7], *b; If passing a 1-dimensional array, routine_name_ELEMS_j (see below) must be 1.

    • To specify the numbers of elements, routine_name_ELEMS_j and routine_name_ELEMLEN_j must be defined as shown below before interfacing the routine with CCALLSFSUBn, PROTOCCALLSFFUNn, etc.
      #define routine_name_ELEMS_j   ZTRINGV_ARGS(k)       
                                       [..ARGS for subroutines, ..ARGF for functions.]
      
      or
      #define routine_name_ELEMS_j   ZTRINGV_NUM(l)
      
      Where:
             routine_name is as above.
             j            [1-n], is the argument being specifying.
             k            [1-n], the value of the k'th argument is the dynamic number
                          of elements for argument j. The k'th argument must be
                          of type BYTE, DOUBLE, FLOAT, INT, LONG or SHORT.
             l            the number of elements for argument j. This must be an
                          integer constant available at compile time.
                          i.e. it is static.
      

    • Similarly to specify the useful length, [i.e. don't count C's trailing '\0',] of each element:
      #define routine_name_ELEMLEN_j ZTRINGV_ARGS(m)
                                       [..ARGS for subroutines, ..ARGF for functions.]
      
      or
      #define routine_name_ELEMLEN_j ZTRINGV_NUM(q)
      
      Where:
             m            [1-n], as for k but this is the length of each element. 
             q            as for l but this is the length of each element. 
      

  6. ROUTINE The argument is an EXTERNAL procedure. When C passes a routine to FORTRAN, the language of the function must be specified as follows: [The case of some_*_function must be given as shown.]

    When C passes a C routine to a FORTRAN:

        FORTRAN_ROUTINE(arg1, .... ,       
                        C_FUNCTION(SOME_C_FUNCTION,some_c_function),
                        ...., argn);
    
    and similarly when C passes a FORTRAN routine to FORTRAN:
        FORTRAN_ROUTINE(arg1, .... ,
                        FORTRAN_FUNCTION(SOME_FORT_FUNCTION,some_fort_function),
                        ...., argn);
    
    If fcallsc has been redefined; the same definition of fcallsc used when creating the wrapper for 'some_c_function' must also be defined when C_FUNCTION is used. See ii) 5. of this section for when and how to redefine fcallsc. ROUTINE was introduced with cfortran.h version 2.6. Earlier versions of cfortran.h used PVOID to pass external procedures as arguments. Using PVOID for this purpose is no longer recommended since it won't work 'as is' for apolloFortran, hpuxFortran800, AbsoftUNIXFortran, AbsoftProFortran.

  7. CRAY only:

    In a given piece of source code, where FFUNC is any FORTRAN routine, FORTRAN_FUNCTION(FFUNC,ffunc) disallows a previous #define FFUNC(..) CCALLSFSUBn(FFUNC,ffunc,...) [ or CCALLSFFUNn] in order to make the UPPER CASE FFUNC callable from C. #define Ffunc(..) ... is OK though, as are obviously any other names.

ii) Calling C routines from FORTRAN:

Each of the following two statements to export a C routine to FORTRAN create FORTRAN 'wrappers', written in C, which must be compiled and linked along with the original C routines and with the FORTRAN calling code.

FORTRAN callable 'wrappers' may also be created for C macros. i.e. in this section, the term 'C function' may be replaced by 'C macro'.

for C functions returning void:

FCALLSCSUBn(             Routine_name,ROUTINE_NAME,routine_name,argtype_1,...,argtype_n)
for all other C functions:
FCALLSCFUNn(routine_type,Routine_name,ROUTINE_NAME,routine_name,argtype_1,...,argtype_n)
Where: 'n' = 0->27 (easily expanded to > 27) stands for the number of arguments to the routine.
Routine_name = the C       name of the routine. [see 9. below]
ROUTINE_NAME = the FORTRAN name of the routine (IN UPPER CASE LETTERS).
routine_name = the FORTRAN name of the routine (IN lower case LETTERS).
routine_type = the type of argument returned by C functions.
             = BYTE, DOUBLE, FLOAT, INT, LOGICAL, LONG, SHORT, STRING, VOID.
               [Instead of VOID, FCALLSCSUBn is recommended.]
argtype_i    = the type of argument passed to the FORTRAN routine and must be
               consistent in the definition and prototyping of the routine
             = BYTE, DOUBLE, FLOAT, INT, LOGICAL, LONG, SHORT, STRING.
             For vectors, i.e. 1 dim. arrays use 
             = BYTEV, DOUBLEV, FLOATV, INTV, LOGICALV, LONGV, SHORTV, STRINGV.
             For vectors of vectors, 2 dim. arrays use
             = BYTEVV, DOUBLEVV, FLOATVV, INTVV, LOGICALVV, LONGVV, SHORTVV.
             For n-dim. arrays use
             = BYTEV..nV's..V, DOUBLEV..V, FLOATV..V, INTV..V, LOGICALV..V, 
               LONGV..V, SHORTV..V.
             For routines changing the values of an argument, the keyword is 
                  prepended by a 'P'.
             = PBYTE, PDOUBLE, PFLOAT, PINT, PLOGICAL, PLONG, PSHORT, 
               PSTRING, PNSTRING, PPSTRING, PSTRINGV.
             For EXTERNAL procedures passed as arguments use
             = ROUTINE.
             For exceptional arguments which require no massaging to fit the
                  argument passing mechanisms use
             = PVOID.
                The argument is cast and passed as (void *).
Notes:

  1. For FORTRAN calling C++ routines, C++ does NOT easily allow support for: STRINGV. BYTEVV, DOUBLEVV, FLOATVV, INTVV, LOGICALVV, LONGVV, SHORTVV. BYTEV..V, DOUBLEV..V, FLOATV..V, INTV..V, LOGICALV..V, LONGV..V, SHORTV..V. Though there are ways to get around this restriction, the restriction is not serious since these types are unlikely to be used as arguments for a C++ routine.

  2. FCALLSCSUB/FUNn expect that the routine to be 'wrapped' has been properly prototyped, or at least declared.

  3. cfortran.h may be expanded to handle a new argument type not already among the above.

  4. [BYTE|DOUBLE|BYTE|DOUBLE|FLOAT|INT|LOGICAL|LONG|SHORT][V|VV|VVV|...]

    cfortran.h encourages the exact specification of the type and dimension of array parameters because it allows the C compiler to detect errors in the arguments when declaring the routine using FCALLSCSUB/FUNn, assuming the routine to be 'wrapped' has been properly prototyped.

    cfortran.h does not strictly require the exact specification since the argument is merely the address of the array and is passed on to the calling routine. Any array parameter could be declared as PVOID, but this circumvents C's compiletime ability to check the correctness of arguments and is therefore discouraged.

    Passing the address of these arguments implies that PBYTEV, PFLOATV, ... , PDOUBLEVV, ... don't exist in cfortran.h, since by default the routine and the calling code share the same array, i.e. the same values at the same memory location.

    These comments do NOT apply to arrays of (P)STRINGV. For these parameters, cfortran.h passes a massaged copy of the array to the routine. When the routine returns, STRINGV ignores the copy, while PSTRINGV replaces the calling code's original array with copy, which may have been modified by the called routine.

  5. (P(N))STRING arguments have any trailing blanks removed before being passed to C, the same holds true for each element in (P)STRINGV. Space is malloc'd in all cases big enough to hold the original string (elements) as well as C's terminating '\0'. i.e. The useful size of the string (elements) is the same in both languages. P(N)STRING(V) => the string (elements) will be copied from the malloc'd space back into the FORTRAN bytes. If one of the two escape mechanisms mentioned below for PNSTRING has been used, the copying back to FORTRAN is obviously not relevant.

  6. (PN)STRING's, [NOT PSTRING's nor (P)STRINGV's,] behavior may be overridden in two cases. In both cases PNSTRING and STRING behave identically.

    1. If a (PN)STRING argument's first 4 bytes are all the NUL character, i.e. '\0\0\0\0' the NULL pointer is passed to the C routine.

    2. the NUL character, i.e. C strings' terminating '\0', the address of the string is simply passed to the C routine. i.e. The argument is treated in this case as it would be with PPSTRING, to which we refer the reader for more detail.

    Mechanism 1. overrides 2. . Therefore, to use this mechanism to pass the NULL string, "", to C, the first character of the string must obviously be the NUL character, but of the first 4 characters in the string, at least one must not be HEX-00.

    Example:

    
    C FORTRAN                                               /* C */
          character*40 str                                  #include "cfortran.h"
    C Set up a NULL as :                                    void cs(char *s) {if (s) printf("%s.\n",s);}
    C    i)  4 NUL characters.                              FCALLSCSUB1(cs,CS,cs,STRING)
    C    ii) NULL pointer.
          character*4 NULL        
          NULL = CHAR(0)//CHAR(0)//CHAR(0)//CHAR(0)
    
          data str/'just some string'/
    
    C Passing the NULL pointer to cs.
          call cs(NULL)
    C Passing a copy of 'str' to cs.
          call cs(str)
    C Passing address of 'str' to cs. Trailing blanks NOT killed.
          str(40:) = NULL
          call cs(str)
          end
    
    Strings passed from FORTRAN to C via (PN)STRING must not have undefined contents, otherwise undefined behavior will result, since one of the above two escape mechanisms may occur depending on the contents of the string.

    This is not be a problem for STRING arguments, which are read-only in the C routine and hence must have a well defined value when being passed in.

    PNSTRING arguments require special care. Even if they are write-only in the C routine, PNSTRING's above two escape mechanisms require that the value of the argument be well defined when being passed in from FORTRAN to C. Therefore, unless one or both of PNSTRING's escape mechanisms are required, PSTRING should be used instead of PNSTRING. Prior to version 2.8, PSTRING did have the above two escape mechanisms, but they were removed from PSTRING to allow strings with undefined contents to be passed in. PNSTRING behaves like the old PSTRING. [Thanks go to Paul Dubois (dubios@icf.llnl.gov) for pointing out that PSTRING must allow for strings with undefined contents to be passed in.]

    Example:

    C FORTRAN                                               /* C */
          character*10 s,sn                                 #include "cfortran.h"
                                                            void ps(char *s) {strcpy(s,"hello");}
    C Can   call ps  with undef. s.                         FCALLSCSUB1(ps,PS,ps,PSTRING)
          call ps(s)                                        FCALLSCSUB1(ps,PNS,pns,PNSTRING)
          print *,s,'=s'
                                  
    C Can't call pns with undef. s.
    C e.g. If first 4 bytes of s were
    C      "\0\0\0\0", ps would try
    C      to copy to NULL because
    C      of PNSTRING mechanism.
          sn = ""
          call pns(sn)
          print *,sn,'=sn'
                                                   
          end
    

  7. PPSTRING The address of the string argument is simply passed to the C routine. Therefore the C routine and the FORTRAN calling code share the same string at the same memory location. If the C routine modifies the string, the string will also be modified for the FORTRAN calling code. The user is responsible for negociating the differences in representation of a string in FORTRAN and in C, i.e. the differences are not automatically resolved as they are for (P(N)STRING(V). This mechanism is provided for two reasons:

    • Some C routines require the string to exist at the given memory location, after the C routine has exited. Recall that for the usual P(N)STRING(V) mechanism, a copy of the FORTRAN string is given to the C routine, and this copy ceases to exist after returning to the FORTRAN calling code.

    • This mechanism can save runtime CPU cycles over (P(N)STRING(V), since it does not perform their malloc, copy and kill trailing blanks of the string to be passed.
      Only in a small minority of cases does the potential benefit of the saved CPU cycles outweigh the programming effort required to manually resolve the differences in representation of a string in FORTRAN and in C.

    For arguments passed via PPSTRING, the argument passed may also be an array of strings.

  8. ROUTINE ANSI C requires that the type of the value returned by the routine be known, For all ROUTINE arguments passed from FORTRAN to C, the type of ROUTINE is specified by defining a cast as follows:
    #undef  ROUTINE_j
    #define ROUTINE_j   (cast)
    
    Where:
           j            [1-n], is the argument being specifying.
           (cast)       is a cast matching that of the argument expected by the C
                        function protoytpe for which a wrapper is being defined.
    
    e.g. To create a FORTRAN wrapper for qsort(3C):
    #undef  ROUTINE_4
    #define ROUTINE_4 (int (*)(void *,void *))
    FCALLSCSUB4(qsort,FQSORT,fqsort,PVOID,INT,INT,ROUTINE)
    
    In order to maintain backward compatibility, cfortran.h defines a generic cast for ROUTINE_1, ROUTINE_2, ..., ROUTINE_27. The user's definition is therefore strictly required only for DEC C, which at the moment is the only compiler which insists on the correct cast for pointers to functions.

    When using the ROUTINE argument inside some FORTRAN code:

    • it is difficult to pass a C routine as the parameter, since in many FORTRAN implementations, FORTRAN has no access to the normal C namespace. e.g. For most UNIX, FORTRAN implicitly only has access to C routines ending in _. If the calling FORTRAN code receives the routine as a parameter it can of course easily pass it along.

    • if a FORTRAN routine is passed directly as the parameter, the called C routine must call the parameter routine using the FORTRAN argument passing conventions.

    • if a FORTRAN routine is to be passed as the parameter, but if FORTRAN can be made to pass a C routine as the parameter, then it may be best to pass a C-callable wrapper for the FORTRAN routine. The called C routine is thus spared all FORTRAN argument passing conventions. cfortran.h can be used to create such a C-callable wrapper to the parameter FORTRAN routine.

    ONLY PowerStationFortran:

    This FORTRAN provides no easy way to pass a FORTRAN routine as an argument to a C routine. The problem arises because in FORTRAN the stack is cleared by the called routine, while in C/C++ it is cleared by the caller. The C/C++ stack clearing behavior can be changed to that of FORTRAN by using stdcall__ in the function prototype. The stdcall__ cannot be applied in this case since the called C routine expects the ROUTINE parameter to be a C routine and does not know that it should apply stdcall__. In principle the cfortran.h generated FORTRAN callable wrapper for the called C routine should be able to massage the ROUTINE argument such that stdcall__ is performed, but it is not yet known how this could be easily done.

  9. The following instructions are not required for VAX/VMS:

    (P)STRINGV information [NOT required for VAX VMS]: cfortran.h cannot convert the FORTRAN vector of STRINGS to the required C vector of STRINGS without explicitly knowing the number of elements in the vector. The application must do one of the following for each (P)STRINGV argument in a routine before that routine's FCALLSCFUNn/SUBn is called:

    #define routine_name_STRV_Ai NUM_ELEMS(j)
     or
    #define routine_name_STRV_Ai NUM_ELEM_ARG(k)
     or
    #define routine_name_STRV_Ai TERM_CHARS(l,m)
    
    where:
           routine_name     is as above.
           i [i=1->n.]      specifies the argument number of a STRING VECTOR.
           j                would specify a fixed number of elements. 
           k [k=1->n. k!=i] would specify an integer argument which specifies the
                            number of elements.
           l [char]         the terminating character at the beginning of an
                            element, indicating to cfortran.h that the preceding
                            elements in the vector are the valid ones.
           m [m=1-...]      the number of terminating characters required to appear
                            at the beginning of the terminating string element.
                            The terminating element is NOT passed on to 
                            the C routine.
    
    e.g.      #define ce_STRV_A1 TERM_CHARS(' ',2)
              FCALLSCSUB1(ce,CE,ce,STRINGV)
    
    cfortran.h will pass on all elements, in the 1st and only argument to the C routine ce, of the STRING VECTOR until, but not including, the first string element beginning with 2 blank, ' ', characters.

  10. Instructions required only for FORTRAN compilers which generate routine names which are undistinguishable from c routine names:
    i.e.
            VAX VMS
            AbsoftUNIXFortran (AbsoftProFortran ok, since it uses Uppercase names.)
            HP9000      if not using the +ppu      option of f77
            IBM RS/6000 if not using the -qextname option of xlf
    
    Call them the same_namespace compilers.

    FCALLSCSUBn(...) and FCALLSCFUNn(...), when compiled, are expanded into 'wrapper' functions, so called because they wrap around the original C functions and interface the format of the original C functions' arguments and return values with the format of the FORTRAN call.

    Ideally one wants to be able to call the C routine from FORTRAN using the same name as the original C name. This is not a problem for FORTRAN compilers which append an underscore, '_', to the names of routines, since the original C routine has the name 'name', and the FORTRAN wrapper is called 'name_'. Similarly, if the FORTRAN compiler generates upper case names for routines, the original C routine 'name' can have a wrapper called 'NAME', [Assuming the C routine name is not in upper case.] For these compilers, e.g. Mips, CRAY, IBM RS/6000 'xlf -qextname', HP-UX 'f77 +ppu', the naming of the wrappers is done automatically.

    For same_namespace compilers things are not as simple, but cfortran.h tries to provide tools and guidelines to minimize the costs involved in meeting their constraints. The following two options can provide same_namespace compilers with distinct names for the wrapper and the original C function.

    These compilers are flagged by cfortran.h with the CF_SAME_NAMESPACE constant, so that the change in the C name occurs only when required.

    For the remainder of the discussion, routine names generated by FORTRAN compilers are referred to in lower case, these names should be read as upper case for the appropriate compilers.

    HP9000 (When f77 +ppu is not used.)

    f77 has a -U option which forces uppercase external names to be generated. Unfortunately, cc does not handle recursive macros. Hence, if one wished to use -U for separate C and FORTRAN namespaces, one would have to adopt a different convention of naming the macros which allow C to call FORTRAN subroutines. (Functions are not a problem.) The macros are currently the uppercase of the original FORTRAN name, and would have to be changed to lower case or mixed case, or to a different name. (Lower case would of course cause conflicts on many other machines.) Therefore, it is suggested that f77 -U not be used, and instead that Option a) or Option b) outlined below be used.

    VAX/VMS:

    For the name used by FORTRAN in calling a C routine to be the same as that of the C routine, the source code of the C routine is required. A preprocessor directive can then force the C compiler to generate a different name for the C routine. e.g.

                        #if defined(vms)
                        #define name name_
                        #endif
                        void name() {printf("name: was called.\n");}
                        FCALLSCSUB0(name,NAME,name)
    
    In the above, the C compiler generates the original routine with the name 'name_' and a wrapper called 'NAME'. This assumes that the name of the routine, as seen by the C programmer, is not in upper case. The VAX VMS linker is not case sensitive, allowing cfortran.h to export the upper case name as the wrapper, which then doesn't conflict with the routine name in C. Since the IBM, HP and AbsoftUNIXFortran platforms have case sensitive linkers this technique is not available to them.

    The above technique is required even if the C name is in mixed case, see Option a) for the other compilers, but is obviously not required when Option b) is used.

    Option a) Mixed Case names for the C routines to be called by FORTRAN.

    If the original C routines have mixed case names, there are no name space conflicts.

    Nevertheless for VAX/VMS, the technique outlined above must also be used.

    Option b) Modifying the names of C routines when used by FORTRAN: The more robust naming mechanism, which guarantees portability to all machines, 'renames' C routines when called by FORTRAN. Indeed, one must change the names on same_namespace compilers when FORTRAN calls C routines for which the source is unavailable. [Even when the source is available, renaming may be preferable to Option a) for large libraries of C routines.]

    Obviously, if done for a single type of machine, it must be done for all machines since the names of routines used in FORTRAN code cannot be easily redefined for different machines.

    The simplest way to achieve this end is to do explicitly give the modified FORTRAN name in the FCALLSCSUBn(...) and FCALLSCFUNn(...) declarations. e.g.

    FCALLSCSUB0(name,CFNAME,cfname)
    
    This allows FORTRAN to call the C routine 'name' as 'cfname'. Any name can of course be used for a given routine when it is called from FORTRAN, although this is discouraged due to the confusion it is sure to cause. e.g. Bizarre, but valid and allowing C's 'call_back' routine to be called from FORTRAN as 'abcd':
    FCALLSCSUB0(call_back,ABCD,abcd)
    
    cfortran.h also provides preprocessor directives for a systematic 'renaming' of the C routines when they are called from FORTRAN. This is done by redefining the fcallsc macro before the FCALLSCSUB/FUN/n declarations as follows:
    #undef  fcallsc
    #define fcallsc(UN,LN) preface_fcallsc(CF,cf,UN,LN)
    
    FCALLSCSUB0(hello,HELLO,hello)
    
    Will cause C's routine 'hello' to be known in FORTRAN as 'cfhello'. Similarly all subsequent FCALLSCSUB/FUN/n declarations will generate wrappers to allow FORTRAN to call C with the C routine's name prefaced by 'cf'. The following has the same effect, with subsequent FCALLSCSUB/FUN/n's appending the modifier to the original C routines name.
    #undef  fcallsc
    #define fcallsc(UN,LN) append_fcallsc(Y,y,UN,LN)
    
    FCALLSCSUB0(Xroutine,ROUTINE,routine)
    
    Hence, C's Xroutine is called from FORTRAN as:
           CALL XROUTINEY()
    
    The original behavior of FCALLSCSUB/FUN/n, where FORTRAN routine names are left identical to those of C, is returned using:
    #undef  fcallsc
    #define fcallsc(UN,LN) orig_fcallsc(UN,LN)
    
    In C, when passing a C routine, i.e. its wrapper, as an argument to a FORTRAN routine, the FORTRAN name declared is used and the correct fcallsc must be in effect. E.g. Passing 'name' and 'routine' of the above examples to the FORTRAN routines, FT1 and FT2, respectively:
    /* This might not be needed if fcallsc is already orig_fcallsc. */
    #undef  fcallsc
    #define fcallsc(UN,LN) orig_fcallsc(UN,LN)
    FT1(C_FUNCTION(CFNAME,cfname));
    
    #undef  fcallsc
    #define fcallsc(UN,LN) append_fcallsc(Y,y,UN,LN)
    FT1(C_FUNCTION(XROUTINE,xroutine));
    
    If the names of C routines are modified when used by FORTRAN, fcallsc would usually be defined once in a header_file.h for the application. This definition would then be used and be valid for the entire application and fcallsc would at no point need to be redefined.

    Once again: the definitions, instructions, declarations and difficulties described here, note 9. OF II ii), apply only for,

                   VAX VMS
                   IBM RS/6000 WITHOUT THE -qextname OPTION FOR xlf, OR
                   HP-UX       WITHOUT THE +ppu      OPTION FOR f77
                   AbsoftUNIXFortran
    
    and apply only when creating wrappers which enable FORTRAN to call c routines.

iii) Using C to manipulate FORTRAN COMMON BLOCKS:

FORTRAN common blocks are set up with the following three constructs:

  1. #define Common_block_name COMMON_BLOCK(COMMON_BLOCK_NAME,common_block_name)
    
    Common_block_name is in UPPER CASE. 
    COMMON_BLOCK_NAME is in UPPER CASE.
    common_block_name is in lower case. 
    
    [Common_block_name actually follows the same 'rules' as Routine_name in Note 2. of II i).] This construct exists to ensure that C code accessing the common block is machine independent.

  2. COMMON_BLOCK_DEF(TYPEDEF_OF_STRUCT, Common_block_name);
    
    where
    typedef { ... } TYPEDEF_OF_STRUCT;
    
    declares the structure which maps on to the common block. The #define of Common_block_name must come before the use of COMMON_BLOCK_DEF.

  3. In exactly one of the C source files, storage should be set aside for the common block with the definition:
    TYPEDEF_OF_STRUCT  Common_block_name;
    
    The above definition may have to be omitted on some machines for a common block which is initialized by FORTRAN BLOCK DATA or is declared with a smaller size in the C routines than in the FORTRAN routines.

    The rules for common blocks are not well defined when linking/loading a mixture of C and FORTRAN, but the following information may help resolve problems.

    From the 2nd or ANSI ed. of K&R C, p.31, last paragraph:

    i) An external variable must be defined, exactly once, outside of any function; this sets aside storage for it.

    ii) The variable must also be declared in each function that wants to access it; ... The declaration ... may be implicit from context.

    In FORTRAN, every routine says 'common /bar/ foo', i.e. part ii) of the above, but there's no part i) requirement. cc/ld on some machines don't require i) either. Therefore, when handling FORTRAN, and sometimes C, the loader/linker must automagically set aside storage for common blocks.

    Some loaders, including at least one for the CRAY, turn off the 'automagically set aside storage' capability for FORTRAN common blocks, if any C object declares that common block. Therefore, C code should define, i.e. set aside storage, for the the common block as shown above. e.g.

    C Fortran
          common /fcb/  v,w,x
          character *(13) v, w(4), x(3,2)
    
    /* C */
    typedef struct { char v[13],w[4][13],x[2][3][13]; } FCB_DEF;
    #define Fcb COMMON_BLOCK(FCB,fcb)
    COMMON_BLOCK_DEF(FCB_DEF,Fcb);
    FCB_DEF Fcb;      /* Definition, which sets aside storage for Fcb, */
                      /* may appear in at most one C source file.      */
    
    C programs can place a string (or a multidimensional array of strings) into a FORTRAN common block using the following call:
    C2FCBSTR( CSTR, FSTR,DIMENSIONS);
    
    where:
    CSTR is a pointer to the first element of C's copy of the string (array). The C code must use a duplicate of, not the original, common block string, because the FORTRAN common block does not allocate space for C strings' terminating '\0'.
    FSTR is a pointer to the first element of the string (array) in the common block.
    DIMENSIONS is the number of dimensions of string array. e.g.
              char a[10]      has DIMENSIONS=0.
              char aa[10][17] has DIMENSIONS=1.
              etc...
    
    C2FCBSTR will copy the string (array) from CSTR to FSTR, padding with blanks, ' ', the trailing characters as required. C2FCBSTR uses DIMENSIONS and FSTR to determine the lengths of the individual string elements and the total number of elements in the string array.

    Note that:

    • the number of string elements in CSTR and FSTR are identical.
    • for arrays of strings, the useful lengths of strings in CSTR and FSTR must be the same. i.e. CSTR elements each have 1 extra character to accommodate the terminating '\0'.
    • On most non-ANSI compilers, the DIMENSION argument cannot be prepended by any blanks.

    FCB2CSTR( FSTR, CSTR,DIMENSIONS) is the inverse of C2FCBSTR, and shares the same arguments and caveats. FCB2CSTR copies each string element of FSTR to CSTR, minus FORTRAN strings' trailing blanks.

    cfortran.h users are strongly urged to examine the common block examples in cfortest.c and cfortex.f. The use of strings in common blocks is demonstrated, along with a suggested way for C to imitate FORTRAN EQUIVALENCE'd variables.

**** USERS OF CFORTRAN.H NEED READ NO FURTHER ****

III) Some Musings

cfortran.h is simple enough to be used by the most basic of applications, i.e. making a single C/FORTRAN routine available to the FORTRAN/C programmers. Yet cfortran.h is powerful enough to easily make entire C/FORTRAN libraries available to FORTRAN/C programmers.

cfortran.h is the ideal tool for FORTRAN libraries which are being (re)written in C, but are to (continue to) support FORTRAN users. It allows the routines to be written in 'natural C', without having to consider the FORTRAN argument passing mechanisms of any machine. It also allows C code accessing these rewritten routines, to use the C entry point. Without cfortran.h, one risks the perverse practice of C code calling a C function using FORTRAN argument passing mechanisms!

Perhaps the philosophy and mechanisms of cfortran.h could be used and extended to create other language bridges such as ADAFORTRAN, CPASCAL, COCCAM, etc.

The code generation machinery inside cfortran.h, i.e. the global structure is quite good, being clean and workable as seen by its ability to meet the needs and constraints of many different compilers. Though the individual instructions of the A..., C..., T..., R... and K... tables deserve to be cleaned up.

IV) Getting Serious with cfortran.h

cfortran.h is set up to be as simple as possible for the casual user. While this ease of use will always be present, 'hooks', i.e. preprocessor directives, are required in cfortran.h so that some of the following 'inefficiencies' can be eliminated if they cause difficulties:

  • cfortran.h contains a few small routines for string manipulation. These routines are declared static and are included and compiled in all source code which uses cfortran.h. Hooks should be provided in cfortran.h to create an object file of these routines, allowing cfortran.h to merely prototypes these routines in the application source code. This is the only 'problem' which afflicts both halves of cfortran.h. The remaining discussion refers to the C calls FORTRAN half only.

  • Similar to the above routines, cfortran.h generates code for a 'wrapper' routine for each FUNCTION exported from FORTRAN. Again cfortran.h needs preprocessor directives to create a single object file of these routines, and to merely prototype them in the applications.

  • Libraries often contain hundreds of routines. While the preprocessor makes quick work of generating the required interface code from cfortran.h and the application.h's, it may be convenient for very large stable libraries to have final_application.h's which already contain the interface code, i.e. these final_application.h's would not require cfortran.h. [The convenience can be imagined for the VAX VMS CC compiler which has a fixed amount of memory for preprocessor directives. Not requiring cfortran.h, with its hundreds of directives, could help prevent this compiler from choking on its internal limits quite so often.]
With a similar goal in mind, cfortran.h defines 100's of preprocessor directives. There is always the potential that these will clash with other tags in the users code, so final_applications.h, which don't require cfortran.h, also provide the solution.

In the same vein, routines with more than 14 arguments can not be interfaced by cfortran.h with compilers which limit C macros to 31 arguments. To resolve this difficulty, final_application.h's can be created on a compiler without this limitation.

Therefore, new machinery is required to do:

application.h + cfortran.h => final_application.h
The following example may help clarify the means and ends:

If the following definition of the HBOOK1 routine, the /*commented_out_part*/, is passed through the preprocessor [perhaps #undefing and #defining preprocessor constants if creating an application.h for compiler other than that of the preprocessor being used, e.g. cpp -Umips -DCRAY ... ] :

#include "cfortran.h"
PROTOCCALLSFSUB6(HBOOK1,hbook1,INT,STRING,INT,FLOAT,FLOAT,FLOAT)
/*#define HBOOK1(ID,CHTITLE,NX,XMI,XMA,VMX)                 \*/
     CCALLSFSUB6(HBOOK1,hbook1,INT,STRING,INT,FLOAT,FLOAT,FLOAT, \
                 ID,CHTITLE,NX,XMI,XMA,VMX) 
A function prototype is produced by the PROTOCCALLSFSUB6(...). Interface code is produced, based on the 'variables', ID,CHTITLE,NX,XMI,XMA,VMX which will correctly massage a HBOOK1 call. Therefore, adding the #define line:
'prototype code'
#define HBOOK1(ID,CHTITLE,NX,XMI,XMA,VMX)                 \
 'interface code'(ID,CHTITLE,NX,XMI,XMA,VMX)
which is placed into final_application.h.

The only known limitation of the above method does not allow the 'variable' names to include B1,B2,...,B9,BA,BB,... Obviously the machinery to automatically generate final_applications.h from cfortran.h and applications.h needs more than just some preprocessor directives, but a fairly simple unix shell script should be sufficient. Any takers?

V) Machine Dependencies of cfortran.h

Porting cfortran.h applications, e.g. the hbook.h and cstring.c mentioned above, to other machines is trivial since they are machine independent. Porting cfortran.h requires a solid knowledge of the new machines C preprocessor, and its FORTRAN argument passing mechanisms. Logically cfortran.h exists as two halves, a "C CALLS FORTRAN" and a "FORTRAN CALLS C" utility. In some cases it may be perfectly reasonable to port only 'one half' of cfortran.h onto a new system.

The lucky programmer porting cfortran.h to a new machine, must discover the FORTRAN argument passing mechanisms. A safe starting point is to assume that variables and arrays are simply passed by reference, but nothing is guaranteed. Strings, and n-dimensional arrays of strings are a different story. It is doubtful that any systems do it quite like VAX VMS does it, so that a UNIX or f2c versions may provide an easier starting point.

cfortran.h uses and abuses the preprocessor's ## operator. Although the ## operator does not exist in many compilers, many kludges do. cfortran.h uses /**/ with no space allowed between the slashes, '/' , and the macros or tags to be concatenated. e.g.

#define concat(a,b) a/**/b   /* works*/
main()
{
  concat(pri,ntf)("hello");           /* e.g. */
}
N.B. On some compilers without ##, /**/ may also not work. The author may be able to offer alternate kludges.

VI) Bugs in vendors C compilers and other curiosities

  1. ULTRIX xxxxxx 4.3 1 RISC
    Condolences to long suffering ultrix users! DEC supplies a working C front end for alpha/OSF, but not for ultrix.

    From K&R ANSI C p. 231:

       ultrix> cat cat.c
       #define cat(x, y) x ## y
       #define xcat(x,y) cat(x,y)
       cat(cat(1,2),3)
       xcat(xcat(1,2),3)
       ultrix> cc -E cat.c
       123                  <---- Should be: cat(1,2)3
       123                  <---- Correct.
       ultrix> 
    
    The problem for cfortran.h, preventing use of -std and -std1:
       ultrix> cat c.c
       #define cat(x, y) x ## y
       #define xcat(x,y) cat(x,y)
       #define AB(X) X+X
       #define C(E,F,G)  cat(E,F)(G)
       #define X(E,F,G) xcat(E,F)(G)
       C(A,B,2)
       X(A,B,2)
       ultrix> cc -std1 -E c.c
       2+2  
       AB  (2)              <---- ?????????????
       ultrix>
       ultrix> cc -std0 -E c.c
       2+2  
       AB(2)                <---- ?????????????
       ultrix>
    
    Due to further ultrix preprocessor problems, for all definitions of definitions with arguments, cfortran.h >= 3.0 includes the arguments and recommends the same, even though it is not required by ANSI C. e.g. Users are advised to do
       #define fcallsc(UN,LN) orig_fcallsc(UN,LN)
    
    instead of
       #define fcallsc        orig_fcallsc
    
    since ultrix fails to properly preprocess the latter example. CRAY used to (still does?) occasionally trip up on this problem.

  2. ConvexOS convex C210 11.0 convex

    In a program with a C main, output to LUN=6=* from FORTRAN goes into $pwd/fort.6 instead of stdout. Presumably, a magic incantation can be called from the C main in order to properly initialize the FORTRAN I/O.

  3. SunOS 5.3 Generic_101318-69 sun4m sparc

    The default data and code alignments produced by cc, gcc and f77 are compatible. If deviating from the defaults, consistent alignment options must be used across all objects compiled by cc and f77. [Does gcc provide such options?]

  4. SunOS 5.3 Generic_101318-69 sun4m sparc with cc: SC3.0.1 13 Jul 1994 or equivalently ULTRIX 4.4 0 RISC using cc -oldc are K&R C preprocessors that suffer from infinite loop macros, e.g.
      zedy03> cat src.c
      #include "cfortran.h"
                                PROTOCCALLSFFUN1(INT,FREV,frev, INTV)
      #define FREV(A1)               CCALLSFFUN1(    FREV,frev, INTV, A1)
      /* To avoid the problem, deletete these ---^^^^--- spaces.    */
      main() { static int a[] = {1,2}; FREV(a); return EXIT_SUCCESS; }
    
      zedy03> cc -c -Xs -v -DMAX_PREPRO_ARGS=31 -D__CF__KnR src.c
      "src.c", line 4: FREV: actuals too long
      "src.c", line 4: FREV: actuals too long
      .... 3427 more lines of the same message
      "src.c", line 4: FREV: actuals too long
      cc : Fatal error in /usr/ccs/lib/cpp
      Segmentation fault (core dumped) 
    

  5. Older sun C compilers

    To link to f77 objects, older sun C compilers require the math.h macros:

    #define RETURNFLOAT(x)   { union {double _d; float _f; } _kluge; \
                               _kluge._f = (x); return _kluge._d;   }
    #define ASSIGNFLOAT(x,y) { union {double _d; float _f; } _kluge; \
                               _kluge._d = (y); x = _kluge._f;      }
    
    Unfortunately, in at least some copies of the sun math.h, the semi-colon for 'float _f;' is left out, leading to compiler warnings.

    The solution is to correct math.h, or to change cfortran.h to #define RETURNFLOAT(x) and ASSIGNFLOAT(x,y) instead of including math.h.

  6. gcc version 2.6.3 and probably all other versions as well:

    Unlike all other C compilers supported by cfortran.h, 'gcc -traditional' promotes to double all functions returning float as demonstrated bu the following example.

    /* m.c */
    #include 
    int main() { FLOAT_FUNCTION d(); float f; f = d(); printf("%f\n",f); return 0; }
    
    /* d.c */
    float d() { return -123.124; }
    
    burow[29] gcc -c -traditional d.c
    burow[30] gcc -DFLOAT_FUNCTION=float m.c d.o && a.out
    0.000000
    burow[31] gcc -DFLOAT_FUNCTION=double m.c d.o && a.out
    -123.124001
    burow[32]
    
    Thus, 'gcc -traditional' is not supported by cfortran.h. Support would require the same RETURNFLOAT, etc. macro machinery present in old sun math.h, before sun gave up the same promotion.

  7. CRAY

    At least some versions of the t3e and t3d C preprocessor are broken in the fashion described below. At least some versions of the t90 C preprocessor do not have this problem.

    On the CRAY, all FORTRAN names are converted to uppercase. Generally the uppercase name is also used for the macro interface created by cfortran.h.

    For example, in the following interface, EASY is both the name of the macro in the original C code and EASY is the name of the resulting function to be called.

    #define EASY(A,B)      CCALLSFSUB2(EASY,easy, PINT, INTV, A, B)
    
    The fact that a macro called EASY() expands to a function called EASY() is not a problem for a working C preprocessor. From Kernighan and Ritchie, 2nd edition, p.230:

    In both kinds of macro, the replacement token sequence is repeatedly rescanned for more identifiers. However, once a given identifier has been replaced in a given expansion, it is not replaced if it turns up again during rescanning; instead it is left unchanged.

    Unfortunately, some CRAY preprocessors are broken and don't obey the above rule. A work-around is for the user to NOT use the uppercase name of the name of the macro interface provided by cfortran.h. For example:

    #define Easy(A,B)      CCALLSFSUB2(EASY,easy, PINT, INTV, A, B)
    
    Luckily, the above work-around is not required since the following work-around within cfortran.h also circumvents the bug:
       /* (UN), not UN, is required in order to get around  CRAY preprocessor bug.*/
       #define CFC_(UN,LN)            (UN)      /* Uppercase FORTRAN symbols.     */
    

    Aside: The Visual C++ compiler is happy with UN, but barfs on (UN), so either (UN) causes nonstandard C/C++ or Visual C++ is broken.

VII) History and Acknowledgements

1.0
  • Supports VAX VMS using C 3.1 and FORTRAN 5.4.
Oct. '90.
1.0
  • Supports Silicon Graphics w. Mips Computer 2.0 f77 and cc. [Port of C calls FORTRAN half only.]
Feb. '91.
1.1
  • Supports Mips Computer System 2.0 f77 and cc. [Runs on at least: Silicon Graphics IRIX 3.3.1 DECstations with Ultrix V4.1]
Mar. '91.
1.2
  • Internals made simpler, smaller, faster, stronger.
  • Mips version works on IBM RS/6000, this is now called the unix version.
May '91.
1.3
  • UNIX and VAX VMS versions are merged into a single cfortran.h.
  • C can help manipulate (arrays of) strings in FORTRAN common blocks.
  • Dimensions of string arrays arguments can be explicit.
  • Supports Apollo DomainOS 10.2 (sys5.3) with f77 10.7 and cc 6.7.
July '91.
2.0
  • Improved code generation machinery creates K&R or ANSI C.
  • Supports Sun, CRAY. f2c with vcc on VAX Ultrix.
  • cfortran.h macros now require routine and COMMON block names in both upper and lower case. No changes required to applications though.
  • PROTOCCALLSFSUBn is eliminated, with no loss to cfortran.h performance.
  • Improved tools and guidelines for naming C routines called by FORTRAN.
Aug. '91.
2.1
  • LOGICAL correctly supported across all machines.
  • Improved support for DOUBLE PRECISION on the CRAY.
  • HP9000 fully supported.
  • VAX Ultrix cc or gcc with f77 now supported.
Oct. '91.
2.2
  • SHORT, i.e. INTEGER*2, and BYTE now supported.
  • LOGICAL_STRICT introduced. More compact and robust internal tables.
  • typeV and typeVV for type = BYTE, DOUBLE, FLOAT, INT, LOGICAL, LONG,SHORT.
  • FORTRAN passing strings and NULL pointer to C routines improved.
Dec. '91.
2.3
  • Extraneous arguments removed from many internal tables.
  • Introduce pseudo argument type SIMPLE for user defined types.
  • LynxOS using f2c supported. (Tested with LynxOS 2.0 386/AT.)
May '92.
2.4
  • Separation of internal C and FORTRAN compilation directives.
  • f2c and NAG f90 supported on all machines.
Oct. '92.
2.5
  • Minor mod.s to source and/or doc for HP9000, f2c, and NAG f90.
Nov. '92.
2.6
  • Support external procedures as arguments with type ROUTINE.
Dec. '92.
2.7
  • Support Alpha VMS. Support HP9000 f77 +ppu
  • Support arrays with up to 7 dimensions.
  • Minor mod. of FORTRAN NULL to C via (P)STRING.
  • Specify the type of ROUTINE passed from FORTRAN to C [ANSI C requirement.]
  • Macros never receive a null parameter [RS/6000 requirement.]
Jan. '93.
2.8
  • PSTRING for FORTRAN calls C no longer provides escape to pass NULL pointer nor to pass address of original string. PNSTRING introduced with old PSTRING's behavior. PPSTRING introduced to always pass original address of string.
  • Support Alpha/OSF.
  • Document that common blocks used in C should be declared AND defined.
April'93.
3.0
  • Automagic handling of ANSI ## versus K&R /**/ preprocessor op.
  • Less chance of name space collisions between cfortran.h and other codes.
  • SIMPLE macros, supporting user defined types, have changed names.
March'95.
3.1
  • Internal macro name _INT not used. Conflicted with IRIX 5.3.
  • SunOS, all versions, should work out of the box.
  • ZTRINGV_ARGS|F(k) may no longer point to a PDOUBLE or PFLOAT argument.
  • ConvexOS 11.0 supported.
May '95.
3.2
  • __hpux no longer needs to be restricted to MAX_PREPRO_ARGS=31.
  • PSTRING bug fixed.
  • ZTRINGV_ARGS|F(k) may not point to a PBYTE,PINT,PLONG or PSHORT argument.
  • (P)ZTRINGV machinery improved. Should lead to fewer compiler warnings. (P)ZTRINGV no longer limits recursion or the nesting of routines.
  • SIMPLE macros, supporting user defined types, have changed slightly.
Oct. '95.
3.3
  • Supports PowerStation FORTRAN with Visual C++.
  • g77 should work using f2cFortran, though no changes made for it.
  • (PROTO)CCALLSFFUN10 extended to (PROTO)CCALLSFFUN14.
  • FCALLSCFUN10 and SUB10 extended to FCALLSCFUN14 and SUB14.
Nov. '95.
3.4
  • C++ supported, but it required the reintroduction of PROTOCCALLSFSUBn for users.
  • HP-UX f77 +800 supported.
Dec. '95.
3.5
  • Absoft UNIX FORTRAN supported.
Sept.'96.
3.6
  • Minor corrections to cfortran.doc.
  • Fixed bug for 15th argument. [Thanks to Tom Epperly at Aspen Tech.]
  • For AbsoftUNIXFortran, obey default of prepending _C to COMMON BLOCK name.
  • FORTRAN calling C with ROUTINE argument fixed and cleaned up.
Oct. '96.
3.7
  • Circumvent IBM and HP "null argument" preprocessor warning.
Oct. '96
3.8
  • (P)STRINGV and (P)ZTRINGV can pass a 1- or 2-dim. char array. (P)ZTRINGV thus effectively also provides (P)ZTRING.
  • (P)ZTRINGV accepts a (char *) pointer.
Feb. '97
3.9
  • Bug fixed for *VVVVV.
  • f2c: Work-around for strange underscore-dependent naming feature.
  • NEC SX-4 supported.
  • CRAY: LOGICAL conversion uses _btol and _ltob from CRAY's fortran.h.
  • CRAY: Avoid bug of some versions of the C preprocessor.
  • CRAY T3E: FORTRAN_REAL introduced.
May '97
4.0
  • new/delete now used for C++. malloc/free still used for C.
  • FALSE no longer is defined by cfortran.h .
  • Absoft Pro FORTRAN for MacOS supported.
Jan. '98
4.1
  • COMMA and COLON no longer are defined by cfortran.h .
  • Bug fixed when 10th arg. or beyond is a string. [Rob Lucchesi of NASA-Goddard pointed out this bug.]
  • CCALLSFSUB/FUN extended from 14 to 27 arguments.
  • Workaround SunOS CC 4.2 cast bug. [Thanks to Savrak SAR of CERN.]
April'98
4.2
  • Portland Group needs -DpgiFortran . [Thank George Lai of NASA.]
June '98
4.3
  • (PROTO)CCALLSFSUB extended from 20 to 27 arguments.
July '98

['Support' implies these and more recent releases of the respective OS/compilers/linkers can be used with cfortran.h. Earlier releases may also work.]

Acknowledgements
  • CERN very generously sponsored a week in 1994 for me to work on cfortran.h.
  • M.L.Luvisetto (Istituto Nazionale Fisica Nucleare - Centro Nazionale Analisi Fotogrammi, Bologna, Italy) provided all the support for the port to the CRAY. Marisa's encouragement and enthusiasm was also much appreciated.
  • J.Bunn (CERN) supported the port to PowerStation FORTRAN with Visual C++.
  • Paul Schenk (UC Riverside, CERN PPE/OPAL) in June 1993 extended cfortran.h 2.7 to have C++ call FORTRAN. This was the starting point for full C++ in 3.4.
  • Glenn P.Davis of University Corp. for Atmospheric Research (UCAR) / Unidata supported the NEC SX-4 port and helped understand the CRAY.
  • Tony Goelz of Absoft Corporation ported cfortran.h to Absoft.
  • Though cfortran.h has been created in my 'copious' free time, I thank NSERC for their generous support of my grad. student and postdoc years.
  • Univ.Toronto, DESY, CERN and others have provided time on their computers.
  • The HTML version of the cfortran.h documentation has been made by Olivier Couet Olivier.Couet@cern.ch.
THIS PACKAGE, I.E. CFORTRAN.H, THIS DOCUMENT, AND THE CFORTRAN.H EXAMPLE
PROGRAMS ARE PROPERTY OF THE AUTHOR WHO RESERVES ALL RIGHTS. THIS PACKAGE AND
THE CODE IT PRODUCES MAY BE FREELY DISTRIBUTED WITHOUT FEES, SUBJECT TO THE
FOLLOWING RESTRICTIONS:
- YOU MUST ACCOMPANY ANY COPIES OR DISTRIBUTION WITH THIS (UNALTERED) NOTICE.
- YOU MAY NOT RECEIVE MONEY FOR THE DISTRIBUTION OR FOR ITS MEDIA 
  (E.G. TAPE, DISK, COMPUTER, PAPER.)
- YOU MAY NOT PREVENT OTHERS FROM COPYING IT FREELY.
- YOU MAY NOT DISTRIBUTE MODIFIED VERSIONS WITHOUT CLEARLY DOCUMENTING YOUR
  CHANGES AND NOTIFYING THE AUTHOR.
- YOU MAY NOT MISREPRESENTED THE ORIGIN OF THIS SOFTWARE, EITHER BY EXPLICIT
  CLAIM OR BY OMISSION.

THE INTENT OF THE ABOVE TERMS IS TO ENSURE THAT THE CFORTRAN.H PACKAGE NOT BE
USED FOR PROFIT MAKING ACTIVITIES UNLESS SOME ROYALTY ARRANGEMENT IS ENTERED
INTO WITH ITS AUTHOR.
              
THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER
EXPRESSED OR IMPLIED. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
SOFTWARE IS WITH YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST
OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. THE AUTHOR IS NOT RESPONSIBLE
FOR ANY SUPPORT OR SERVICE OF THE CFORTRAN.H PACKAGE.

                                              Burkhard Burow 
                                              burow@desy.de
P.S. Your comments and questions are welcomed and usually promptly answered.
VAX VMS and Ultrix, Alpha, OSF, Silicon Graphics (SGI), DECstation, Mips RISC, Sun, CRAY, Convex, IBM RS/6000, Apollo DomainOS, HP, LynxOS, f2c, NAG, Absoft, NEC SX-4, PowerStation and Visual C++ are registered trademarks of their respective owners. cfortran-4.4/index.htm0100644000175000017500000000766107563721371015262 0ustar kmccartykmccarty cfortran.h
 

cfortran.h : Interfacing C or C++ and FORTRAN

cfortran.h is an easy-to-use powerful bridge between C and FORTRAN.
It provides a transparent, machine independent interface between
C and FORTRAN routines and global data.

C and C++ are generally equivalent as far as cfortran.h is concerned.
Unless explicitly noted otherwise, mention of C implicitly includes C++.

The following presentation is a good introduction to mixed language programming.
   Burkhard D. Burow. "Mixed Language Programming",
   In Computing in High Energy Physics (CHEP'95), Rio de Janeiro, Brazil,
   Sept. 1995, editors R. Shellard and T.Nguyen, World Scientific, pp. 610-614.
Here is the paper and the slides of the presentation.
It introduces cfortran.h and alternative methods for mixed language programming
and thus can help you decide if cfortran.h can be of use to you.

Knowing its popularity might help you decide if cfortran.h can be of use to you.
The following is my best estimate of the number of users of cfortran.h.
Since its first release in 1990, I have exchanged e-mails with hundreds of users of cfortran.h.
Assuming that a small fraction of users of cfortran.h ever send me e-mail,
then cfortran.h has a few thousand users. You easily can find users in a www search.


The cfortran.h software consists of the single C header file cfortran.h.

The documentation is the single file cfortran.html.
The documentation also is available at its original location http://wwwinfo.cern.ch/asd/cernlib/cfortran.html.
The documentation also is available as the original ASCII file cfortran.doc.

A variety of small independent applications are available to test and demonstrate cfortran.h.
All the applications are contained in a compressed tar file cfortran.examples.tar.gz.
The following will unpack the applications into a directory named eg/.
The program zcat is the GNU version or compatible.
unix> zcat cfortran.examples.tar.gz | tar xf -

Though NOT recommended for most purposes,
the above applications also are available in a single C file cfortest.c
and a single Fortran file cfortex.f.


If cfortran.h has served you well, you may want to look at the recent instance of graph reduction
described at http://www-zeus.desy.de/~funnel/TSIA/index.htm.
cfortran.h provides an application with transparent mixed language programming.
In other words, cfortran.h hides the details of mixed language programming from the application.
In a similar vein, graph reduction (a.k.a. dataflow) has long promised transparent parallelism,
reliability and other execution features. The promises have not been fulfilled, since graph reduction
lacked a practical implementation. Though not yet widely known, practical graph reduction recently
has been achieved.



Burkhard D. Steinmacher-Burow, Postfach 1163, 73241 Wernau, Germany.
burow@desy.de
http://www-zeus.desy.de/~burow/cfortran/index.htm


cfortran-4.4/cfortran.examples.tar.gz0100644000175000017500000004006307574532643020220 0ustar kmccartykmccarty5]{w:?)8PKM&r™$3,c-H~!icCJl!iK%y~ʚ 2 wn0'nۍ:\c1';]#gUW xWmǰ yƃ3#NyN9/ߨ[&gofH?^NE3so ^s+dUA y'Oid?>\] Z ?8JfxE#ppN\0 ~\8'ԫ}*zt/Μa !CW4M z (3\G8SUI.pt\zCTCvհ>xnzpJklh4wz]m ~{M4m?%?D2qo1?{R?s2F17sw{Wo jgOGĩϫÓ?[9]Oŗ~1$3ar咞wV/y$_=.ո:eUr/cIjtJ|)tF՝J#wͷdjlTDIeJ`ѩS& &Ad c)m/?X@ o*H /y?/{TƔLp2P>)݂Ip+ #!x1bUaݢ*Z]9IrVŜ&p~ޢsUQNMjUnQ p0u[$UD0LtW3Wu.螔WlVz1AjEs-fYpSگ5X3#*g!Rh0U>K_sםT dqLD~)ӲBf92@؂ZzwO'$gN zAtzN|YF;>2?tHKvU6I"oFߛXF ]<q>8`FkJ#{ш(k\٢R~-H$"'YB}x5W^-HR$gH/Ѩ7$9?S5Ro0iCKz!A wa#{=V+8w| rg?y,>{g1!{Ao+0`k_rhRO?X'#R{ڄ$JYžD﹙oN!2f}yrhom@i龤Uf6"_gۍB /?C`Їg F?xm_5 "m?-,?zi?o%?f!@()ww>P_jnc࡭-J3p HWjAlo (!g K$m!V- CN.i?R %??B?2P%͗- /@{' iӦ^zD\Gr; &u糡w4FRBt%5 o +9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