1cfortran.doc 4.3 2http://www-zeus.desy.de/~burow/cfortran/ 3Burkhard Burow burow@desy.de 1990 - 2001. 4 5 cfortran.h : Interfacing C or C++ and FORTRAN 6 7Supports: Alpha and VAX VMS, Alpha OSF, DECstation and VAX Ultrix, IBM RS/6000, 8 Silicon Graphics, Sun, CRAY, Apollo, HP9000, LynxOS, Convex, Absoft, 9 f2c, g77, NAG f90, PowerStation Fortran with Visual C++, NEC SX-4, 10 Portland Group. 11 12C and C++ are generally equivalent as far as cfortran.h is concerned. 13Unless explicitly noted otherwise, mention of C implicitly includes C++. 14C++ compilers tested include: 15 SunOS> CC +p +w # Clean compiles. 16 IRIX> CC # Clean compiles. 17 IRIX> CC -fullwarn # Still some warnings to be overcome. 18 GNU> g++ -Wall # Compiles are clean, other than warnings for unused 19 # cfortran.h static routines. 20 21N.B.: The best documentation on interfacing C or C++ and Fortran is in 22 the chapter named something like 'Interfacing C and Fortran' 23 to be found in the user's guide of almost every Fortran compiler. 24 Understanding this information for one or more Fortran compilers 25 greatly clarifies the aims and actions of cfortran.h. 26 Such a chapter generally also addresses issues orthogonal to cfortran.h, 27 for example the order of array indices, the index of the first element, 28 as well as compiling and linking issues. 29 30 310 Short Summary of the Syntax Required to Create the Interface 32-------------------------------------------------------------- 33 34e.g. Prototyping a FORTRAN subroutine for C: 35 36/* PROTOCCALLSFSUBn is optional for C, but mandatory for C++. */ 37 38 PROTOCCALLSFSUB2(SUB_NAME,sub_name,STRING,PINT) 39#define SUB_NAME(A,B) CCALLSFSUB2(SUB_NAME,sub_name,STRING,PINT, A,B) 40 41 ^ - - 42 number of arguments _____| | STRING BYTE PBYTE BYTEV(..)| 43 / | STRINGV DOUBLE PDOUBLE DOUBLEV(..)| 44 / | PSTRING FLOAT PFLOAT FLOATV(..)| 45 types of arguments ____ / | PNSTRING INT PINT INTV(..)| 46 \ | PPSTRING LOGICAL PLOGICAL LOGICALV(..)| 47 \ | PSTRINGV LONG PLONG LONGV(..)| 48 \ | ZTRINGV SHORT PSHORT SHORTV(..)| 49 | PZTRINGV ROUTINE PVOID SIMPLE | 50 - - 51 52 53e.g. Prototyping a FORTRAN function for C: 54/* PROTOCCALLSFFUNn is mandatory for both C and C++. */ 55PROTOCCALLSFFUN1(INT,FUN_NAME,fun_name,STRING) 56#define FUN_NAME(A) CCALLSFFUN1(FUN_NAME,fun_name,STRING, A) 57 58e.g. calling FUN_NAME from C: {int a; a = FUN_NAME("hello");} 59 60 61e.g. Creating a FORTRAN-callable wrapper for 62 a C function returning void, with a 7 dimensional integer array argument: 63 [Not supported from C++.] 64FCALLSCSUB1(csub_name,CSUB_NAME,csub_name,INTVVVVVVV) 65 66 67e.g. Creating a FORTRAN-callable wrapper for other C functions: 68FCALLSCFUN1(STRING,cfun_name,CFUN_NAME,cfun_name,INT) 69 [ ^-- BYTE, DOUBLE, FLOAT, INT, LOGICAL, LONG, SHORT, VOID 70 are other types returned by functions. ] 71 72 73e.g. COMMON BLOCKs: 74FORTRAN: common /fcb/ v,w,x 75 character *(13) v, w(4), x(3,2) 76C: 77typedef struct { char v[13],w[4][13],x[2][3][13]; } FCB_DEF; 78#define FCB COMMON_BLOCK(FCB,fcb) 79COMMON_BLOCK_DEF(FCB_DEF,FCB); 80FCB_DEF FCB; /* Define, i.e. allocate memory, in exactly one *.c file. */ 81 82e.g. accessing FCB in C: printf("%.13s",FCB.v); 83 84 85 86I Introduction 87-------------- 88 89cfortran.h is an easy-to-use powerful bridge between C and FORTRAN. 90It provides a completely transparent, machine independent interface between 91C and FORTRAN routines (= subroutines and/or functions) and global data, 92i.e. structures and COMMON blocks. 93 94The complete cfortran.h package consists of 4 files: the documentation in 95cfortran.doc, the engine cfortran.h, examples in cfortest.c and 96cfortex.f/or. [cfortex.for under VMS, cfortex.f on other machines.] 97 98The cfortran.h package continues to be developed. The most recent version is 99available via www at http://www-zeus.desy.de/~burow/cfortran/ 100 101The examples may be run using one of the following sets of instructions: 102 103N.B. Unlike earlier versions, cfortran.h 3.0 and later versions 104 automatically uses the correct ANSI ## or pre-ANSI /**/ 105 preprocessor operator as required by the C compiler. 106 107N.B. As a general rule when trying to determine how to link C and Fortran, 108 link a trivial Fortran program using the Fortran compilers verbose option, 109 in order to see how the Fortran compiler drives the linker. e.g. 110 unix> cat f.f 111 END 112 unix> f77 -v f.f 113 .. lots of info. follows ... 114 115N.B. If using a C main(), i.e. Fortran PROGRAM is not entry of the executable, 116 and if the link bombs with a complaint about 117 a missing "MAIN" (e.g. MAIN__, MAIN_, f90_main or similar), 118 then Fortran has hijacked the entry point to the executable 119 and wishes to call the rest of the executable via "MAIN". 120 This can usually be satisfied by doing e.g. 'cc -Dmain=MAIN__ ...' 121 but often kills the command line arguments in argv and argc. 122 The f77 verbose option, usually -v, may point to a solution. 123 124 125RS/6000> # Users are strongly urged to use f77 -qextname and cc -Dextname 126RS/6000> # Use -Dextname=extname if extname is a symbol used in the C code. 127RS/6000> xlf -c -qextname cfortex.f 128RS/6000> cc -c -Dextname cfortest.c 129RS/6000> xlf -o cfortest cfortest.o cfortex.o && cfortest 130 131DECFortran> #Only DECstations with DECFortran for Ultrix RISC Systems. 132DECFortran> cc -c -DDECFortran cfortest.c 133DECFortran> f77 -o cfortest cfortest.o cfortex.f && cfortest 134 135IRIX xxxxxx 5.2 02282015 IP20 mips 136MIPS> # DECstations and Silicon Graphics using the MIPS compilers. 137MIPS> cc -o cfortest cfortest.c cfortex.f -lI77 -lU77 -lF77 && cfortest 138MIPS> # Can also let f77 drive linking, e.g. 139MIPS> cc -c cfortest.c 140MIPS> f77 -o cfortest cfortest.o cfortex.f && cfortest 141 142Apollo> # Some 'C compiler 68K Rev6.8' break. [See Section II o) Notes: Apollo] 143Apollo> f77 -c cfortex.f && cc -o cfortest cfortest.c cfortex.o && cfortest 144 145VMS> define lnk$library sys$library:vaxcrtl 146VMS> cc cfortest.c 147VMS> fortran cfortex.for 148VMS> link/exec=cfortest cfortest,cfortex 149VMS> run cfortest 150 151OSF1 xxxxxx V3.0 347 alpha 152Alpha/OSF> # Probably better to let cc drive linking, e.g. 153Alpha/OSF> f77 -c cfortex.f 154Alpha/OSF> cc -o cfortest cfortest.c cfortex.o -lUfor -lfor -lFutil -lots -lm 155Alpha/OSF> cfortest 156Alpha/OSF> # Else may need 'cc -Dmain=MAIN__' to let f77 drive linking. 157 158Sun> # Some old cc(1) need a little help. [See Section II o) Notes: Sun] 159Sun> f77 -o cfortest cfortest.c cfortex.f -lc -lm && cfortest 160Sun> # Some older f77 may require 'cc -Dmain=MAIN_'. 161 162CRAY> cft77 cfortex.f 163CRAY> cc -c cfortest.c 164CRAY> segldr -o cfortest.e cfortest.o cfortex.o 165CRAY> ./cfortest.e 166 167NEC> cc -c -Xa cfortest.c 168NEC> f77 -o cfortest cfortest.o cfortex.f && cfortest 169 170VAX/Ultrix/cc> # For cc on VAX Ultrix only, do the following once to cfortran.h. 171VAX/Ultrix/cc> mv cfortran.h cftmp.h && grep -v "^#pragma" <cftmp.h >cfortran.h 172 173VAX/Ultrix/f77> # In the following, 'CC' is either 'cc' or 'gcc -ansi'. NOT'vcc' 174VAX/Ultrix/f77> CC -c -Dmain=MAIN_ cfortest.c 175VAX/Ultrix/f77> f77 -o cfortest cfortex.f cfortest.o && cfortest 176 177LynxOS> # In the following, 'CC' is either 'cc' or 'gcc -ansi'. 178LynxOS> # Unfortunately cc is easily overwhelmed by cfortran.h, 179LynxOS> # and won't compile some of the cfortest.c demos. 180LynxOS> f2c -R cfortex.f 181LynxOS> CC -Dlynx -o cfortest cfortest.c cfortex.c -lf2c && cfortest 182 183HP9000> # Tested with HP-UX 7.05 B 9000/380 and with A.08.07 A 9000/730 184HP9000> # CC may be either 'c89 -Aa' or 'cc -Aa' 185HP9000> # Depending on the compiler version, you may need to include the 186HP9000> # option '-tp,/lib/cpp' or worse, you'll have to stick to the K&R C. 187HP9000> # [See Section II o) Notes: HP9000] 188HP9000> # Users are strongly urged to use f77 +ppu and cc -Dextname 189HP9000> # Use -Dextname=extname if extname is a symbol used in the C code. 190HP9000> CC -Dextname -c cfortest.c 191HP9000> f77 +ppu cfortex.f -o cfortest cfortest.o && cfortest 192HP9000> # Older f77 may need 193HP9000> f77 -c cfortex.f 194HP9000> CC -o cfortest cfortest.c cfortex.o -lI77 -lF77 && cfortest 195 196HP0000> # If old-style f77 +800 compiled objects are required: 197HP9000> # #define hpuxFortran800 198HP9000> cc -c -Aa -DhpuxFortran800 cfortest.c 199HP9000> f77 +800 -o cfortest cfortest.o cfortex.f 200 201f2c> # In the following, 'CC' is any C compiler. 202f2c> f2c -R cfortex.f 203f2c> CC -o cfortest -Df2cFortran cfortest.c cfortex.c -lf2c && cfortest 204 205Portland Group $ # Presumably other C compilers also work. 206Portland Group $ pgcc -DpgiFortran -c cfortest.c 207Portland Group $ pgf77 -o cfortest cfortex.f cfortest.o && cfortest 208 209NAGf90> # cfortex.f is distributed with Fortran 77 style comments. 210NAGf90> # To convert to f90 style comments do the following once to cfortex.f: 211NAGf90> mv cfortex.f cf_temp.f && sed 's/^C/\!/g' cf_temp.f > cfortex.f 212NAGf90> # In the following, 'CC' is any C compiler. 213NAGf90> CC -c -DNAGf90Fortran cfortest.c 214NAGf90> f90 -o cfortest cfortest.o cfortex.f && cfortest 215 216PC> # On a PC with PowerStation Fortran and Visual_C++ 217PC> cl /c cftest.c 218PC> fl32 cftest.obj cftex.for 219 220GNU> # GNU Fortran 221GNU> # See Section VI caveat on using 'gcc -traditional'. 222GNU> gcc -ansi -Wall -O -c -Df2cFortran cfortest.c 223GNU> g77 -ff2c -o cfortest cfortest.o cfortex.f && cfortest 224 225AbsoftUNIX> # Absoft Fortran for all UNIX based operating systems. 226AbsoftUNIX> # e.g. Linux or Next on Intel or Motorola68000. 227AbsoftUNIX> # Absoft f77 -k allows Fortran routines to be safely called from C. 228AbsoftUNIX> gcc -ansi -Wall -O -c -DAbsoftUNIXFortran cfortest.c 229AbsoftUNIX> f77 -k -o cfortest cfortest.o cfortex.f && cfortest 230 231AbsoftPro> # Absoft Pro Fortran for MacOS 232AbsoftPro> # Use #define AbsoftProFortran 233 234CLIPPER> # INTERGRAPH CLIX using CLIPPER C and Fortran compilers. 235CLIPPER> # N.B. - User, not cfortran.h, is responsible for 236CLIPPER> # f77initio() and f77uninitio() if required. 237CLIPPER> # - LOGICAL values are not mentioned in CLIPPER doc.s, 238CLIPPER> # so they may not yet be correct in cfortran.h. 239CLIPPER> # - K&R mode (-knr or Ac=knr) breaks FLOAT functions 240CLIPPER> # (see CLIPPER doc.s) and cfortran.h does not fix it up. 241CLIPPER> # [cfortran.h ok for old sun C which made the same mistake.] 242CLIPPER> acc cfortest.c -c -DCLIPPERFortran 243CLIPPER> af77 cfortex.f cfortest.o -o cfortest 244 245 246By changing the SELECTion ifdef of cfortest.c and recompiling one can try out 247a few dozen different few-line examples. 248 249 250 251The benefits of using cfortran.h include: 2521. Machine/OS/compiler independent mixing of C and FORTRAN. 253 2542. Identical (within syntax) calls across languages, e.g. 255C FORTRAN 256 CALL HBOOK1(1,'pT spectrum of pi+',100,0.,5.,0.) 257/* C*/ 258 HBOOK1(1,"pT spectrum of pi+",100,0.,5.,0.); 259 2603. Each routine need only be set up once in its lifetime. e.g. 261/* Setting up a FORTRAN routine to be called by C. 262 ID,...,VMX are merely the names of arguments. 263 These tags must be unique w.r.t. each other but are otherwise arbitrary. */ 264PROTOCCALLSFSUB6(HBOOK1,hbook1,INT,STRING,INT,FLOAT,FLOAT,FLOAT) 265#define HBOOK1(ID,CHTITLE,NX,XMI,XMA,VMX) \ 266 CCALLSFSUB6(HBOOK1,hbook1,INT,STRING,INT,FLOAT,FLOAT,FLOAT, \ 267 ID,CHTITLE,NX,XMI,XMA,VMX) 268 2694. Source code is NOT required for the C routines exported to FORTRAN, nor for 270 the FORTRAN routines imported to C. In fact, routines are most easily 271 prototyped using the information in the routines' documentation. 272 2735. Routines, and the code calling them, can be coded naturally in the language 274 of choice. C routines may be coded with the natural assumption of being 275 called only by C code. cfortran.h does all the required work for FORTRAN 276 code to call C routines. Similarly it also does all the work required for C 277 to call FORTRAN routines. Therefore: 278 - C programmers need not embed FORTRAN argument passing mechanisms into 279 their code. 280 - FORTRAN code need not be converted into C code. i.e. The honed and 281 time-honored FORTRAN routines are called by C. 282 2836. cfortran.h is a single ~1700 line C include file; portable to most 284 remaining, if not all, platforms. 285 2867. STRINGS and VECTORS of STRINGS along with the usual simple arguments to 287 routines are supported as are functions returning STRINGS or numbers. Arrays 288 of pointers to strings and values of structures as C arguments, will soon be 289 implemented. After learning the machinery of cfortran.h, users can expand 290 it to create custom types of arguments. [This requires no modification to 291 cfortran.h, all the preprocessor directives required to implement the 292 custom types can be defined outside cfortran.h] 293 2948. cfortran.h requires each routine to be exported to be explicitly set up. 295 While is usually only be done once in a header file it would be best if 296 applications were required to do no work at all in order to cross languages. 297 cfortran.h's simple syntax could be a convenient back-end for a program 298 which would export FORTRAN or C routines directly from the source code. 299 300 301 ----- 302 303Example 1 - cfortran.h has been used to make the C header file hbook.h, 304 which then gives any C programmer, e.g. example.c, full and 305 completely transparent access to CERN's HBOOK library of routines. 306 Each HBOOK routine required about 3 lines of simple code in 307 hbook.h. The example also demonstrates how FORTRAN common blocks 308 are defined and used. 309 310/* hbook.h */ 311#include "cfortran.h" 312 : 313PROTOCCALLSFSUB6(HBOOK1,hbook1,INT,STRING,INT,FLOAT,FLOAT,FLOAT) 314#define HBOOK1(ID,CHTITLE,NX,XMI,XMA,VMX) \ 315 CCALLSFSUB6(HBOOK1,hbook1,INT,STRING,INT,FLOAT,FLOAT,FLOAT, \ 316 ID,CHTITLE,NX,XMI,XMA,VMX) 317 : 318/* end hbook.h */ 319 320/* example.c */ 321#include "hbook.h" 322 : 323typedef struct { 324 int lines; 325 int status[SIZE]; 326 float p[SIZE]; /* momentum */ 327} FAKE_DEF; 328#define FAKE COMMON_BLOCK(FAKE,fake) 329COMMON_BLOCK_DEF(FAKE_DEF,FAKE); 330 : 331main () 332{ 333 : 334 HBOOK1(1,"pT spectrum of pi+",100,0.,5.,0.); 335/* c.f. the call in FORTRAN: 336 CALL HBOOK1(1,'pT spectrum of pi+',100,0.,5.,0.) 337*/ 338 : 339 FAKE.p[7]=1.0; 340 : 341} 342 343N.B. i) The routine is language independent. 344 ii) hbook.h is machine independent. 345 iii) Applications using routines via cfortran.h are machine independent. 346 347 ----- 348 349Example 2 - Many VMS System calls are most easily called from FORTRAN, but 350 cfortran.h now gives that ease in C. 351 352#include "cfortran.h" 353 354PROTOCCALLSFSUB3(LIB$SPAWN,lib$spawn,STRING,STRING,STRING) 355#define LIB$SPAWN(command,input_file,output_file) \ 356 CCALLSFSUB3(LIB$SPAWN,lib$spawn,STRING,STRING,STRING, \ 357 command,input_file,output_file) 358 359main () 360{ 361LIB$SPAWN("set term/width=132","",""); 362} 363 364Obviously the cfortran.h command above could be put into a header file along 365with the description of the other system calls, but as this example shows, it's 366not much hassle to set up cfortran.h for even a single call. 367 368 ----- 369 370Example 3 - cfortran.h and the source cstring.c create the cstring.obj library 371 which gives FORTRAN access to all the functions in C's system 372 library described by the system's C header file string.h. 373 374C EXAMPLE.FOR 375 PROGRAM EXAMPLE 376 DIMENSION I(20), J(30) 377 : 378 CALL MEMCPY(I,J,7) 379 : 380 END 381 382/* cstring.c */ 383#include <string.h> /* string.h prototypes memcpy() */ 384#include "cfortran.h" 385 386 : 387FCALLSCSUB3(memcpy,MEMCPY,memcpy,PVOID,PVOID,INT) 388 : 389 390 391The simplicity exhibited in the above example exists for many but not all 392machines. Note 4. of Section II ii) details the limitations and describes tools 393which try to maintain the best possible interface when FORTRAN calls C 394routines. 395 396 ----- 397 398 399II Using cfortran.h 400------------------- 401 402The user is asked to look at the source files cfortest.c and cfortex.f 403for clarification by example. 404 405o) Notes: 406 407o Specifying the Fortran compiler 408 cfortran.h generates interfaces for the default Fortran compiler. The default 409can be overridden by defining, 410 . in the code, e.g.: #define NAGf90Fortran 411 OR . in the compile directive, e.g.: unix> cc -DNAGf90Fortran 412one of the following before including cfortran.h: 413 NAGf90Fortran f2cFortran hpuxFortran apolloFortran sunFortran 414 IBMR2Fortran CRAYFortran mipsFortran DECFortran vmsFortran 415 CONVEXFortran PowerStationFortran AbsoftUNIXFortran 416 SXFortran pgiFortran AbsoftProFortran 417This also allows crosscompilation. 418If wanted, NAGf90Fortran, f2cFortran, DECFortran, AbsoftUNIXFortran, 419AbsoftProFortran and pgiFortran must be requested by the user. 420 421o /**/ 422 cfortran.h (ab)uses the comment kludge /**/ when the ANSI C preprocessor 423catenation operator ## doesn't exist. In at least MIPS C, this kludge is 424sensitive to blanks surrounding arguments to macros. 425 Therefore, for applications using non-ANSI C compilers, the argtype_i, 426routine_name, routine_type and common_block_name arguments to the 427PROTOCCALLSFFUNn, CCALLSFSUB/FUNn, FCALLSCSUB/FUNn and COMMON_BLOCK macros 428--- MUST NOT --- be followed by any white space characters such as 429blanks, tabs or newlines. 430 431o LOGICAL 432 FORTRAN LOGICAL values of .TRUE. and .FALSE. do not agree with the C 433representation of TRUE and FALSE on all machines. cfortran.h does the 434conversion for LOGICAL and PLOGICAL arguments and for functions returning 435LOGICAL. Users must convert arrays of LOGICALs from C to FORTRAN with the 436C2FLOGICALV(array_name, elements_in_array); macro. Similarly, arrays of LOGICAL 437values may be converted from the FORTRAN into C representation by using 438F2CLOGICALV(array_name, elements_in_array); 439 440 When C passes or returns LOGICAL values to FORTRAN, by default cfortran.h 441only makes the minimal changes required to the value. [e.g. Set/Unset the 442single relevant bit or do nothing for FORTRAN compilers which use 0 as FALSE 443and treat all other values as TRUE.] Therefore cfortran.h will pass LOGICALs 444to FORTRAN which do not have an identical representation to .TRUE. or .FALSE. 445This is fine except for abuses of FORTRAN/77 in the style of: 446 logical l 447 if (l .eq. .TRUE.) ! (1) 448instead of the correct: 449 if (l .eqv. .TRUE.) ! (2) 450or: 451 if (l) ! (3) 452For FORTRAN code which treats LOGICALs from C in the method of (1), 453LOGICAL_STRICT must be defined before including cfortran.h, either in the 454code, "#define LOGICAL_STRICT", or compile with "cc -DLOGICAL_STRICT". 455There is no reason to use LOGICAL_STRICT for FORTRAN code which does not do (1). 456At least the IBM's xlf and the Apollo's f77 do not even allow code along the 457lines of (1). 458 459 DECstations' DECFortran and MIPS FORTRAN compilers use different internal 460representations for LOGICAL values. [Both compilers are usually called f77, 461although when both are installed on a single machine the MIPS' one is usually 462renamed. (e.g. f772.1 for version 2.10.)] cc doesn't know which FORTRAN 463compiler is present, so cfortran.h assumes MIPS f77. To use cc with DECFortran 464define the preprocessor constant 'DECFortran'. 465e.g. i) cc -DDECFortran -c the_code.c 466 or ii) #define DECFortran /* in the C code or add to cfortran.h. */ 467 468 MIPS f77 [SGI and DECstations], f2c, and f77 on VAX Ultrix treat 469.eqv./.neqv. as .eq./.ne.. Therefore, for these compilers, LOGICAL_STRICT is 470defined by default in cfortran.h. [The Sun and HP compilers have not been 471tested, so they may also require LOGICAL_STRICT as the default.] 472 473o SHORT and BYTE 474 They are irrelevant for the CRAY where FORTRAN has no equivalent to C's short. 475Similarly BYTE is irrelevant for f2c and for VAX Ultrix f77 and fort. The 476author has tested SHORT and BYTE with a modified cfortest.c/cfortex.f on all 477machines supported except for the HP9000 and the Sun. 478 479 BYTE is a signed 8-bit quantity, i.e. values are -128 to 127, on all machines 480except for the SGI [at least for MIPS Computer Systems 2.0.] On the SGI it is 481an unsigned 8-bit quantity, i.e. values are 0 to 255, although the SGI 'FORTRAN 48277 Programmers Guide' claims BYTE is signed. Perhaps MIPS 2.0 is dated, since 483the DECstations using MIPS 2.10 f77 have a signed BYTE. 484 485 To minimize the difficulties of signed and unsigned BYTE, cfortran.h creates 486the type 'INTEGER_BYTE' to agree with FORTRAN's BYTE. Users may define 487SIGNED_BYTE or UNSIGNED_BYTE, before including cfortran.h, to specify FORTRAN's 488BYTE. If neither is defined, cfortran.h assumes SIGNED_BYTE. 489 490o CRAY 491 The type DOUBLE in cfortran.h corresponds to FORTRAN's DOUBLE PRECISION. 492 The type FLOAT in cfortran.h corresponds to FORTRAN's REAL. 493 494On a classic CRAY [i.e. all models except for the t3e]: 495( 64 bit) C float == C double == Fortran REAL 496(128 bit) C long double == Fortran DOUBLE PRECISION 497Therefore when moving a mixed C and FORTRAN app. to/from a classic CRAY, 498either the C code will have to change, 499or the FORTRAN code and cfortran.h declarations will have to change. 500DOUBLE_PRECISION is a cfortran.h macro which provides the former option, 501i.e. the C code is automatically changed. 502DOUBLE_PRECISION is 'long double' on classic CRAY and 'double' elsewhere. 503DOUBLE_PRECISION thus corresponds to FORTRAN's DOUBLE PRECISION 504on all machines, including classic CRAY. 505 506On a classic CRAY with the fortran compiler flag '-dp': 507Fortran DOUBLE PRECISION thus is also the faster 64bit type. 508(This switch is often used since the application is usually satisfied by 509 64 bit precision and the application needs the speed.) 510DOUBLE_PRECISION is thus not required in this case, 511since the classic CRAY behaves like all other machines. 512If DOUBLE_PRECISION is used nonetheless, then on the classic CRAY 513the default cfortran.h behavior must be overridden, 514for example by the C compiler option '-DDOUBLE_PRECISION=double'. 515 516On a CRAY t3e: 517(32 bit) C float == Fortran Unavailable 518(64 bit) C double == C long double == Fortran REAL == Fortran DOUBLE PRECISION 519Notes: 520- (32 bit) is available as Fortran REAL*4 and 521 (64 bit) is available as Fortran REAL*8. 522 Since cfortran.h is all about more portability, not about less portability, 523 the use of the nonstandard REAL*4 and REAL*8 is strongly discouraged. 524- Fortran DOUBLE PRECISION is folded to REAL with the following warning: 525 'DOUBLE PRECISION is not supported on this platform. REAL will be used.' 526 Similarly, Fortran REAL*16 is mapped to REAL*8 with a warning. 527This behavior differs from that of other machines, including the classic CRAY. 528FORTRAN_REAL is thus introduced for the t3e, 529just as DOUBLE_PRECISION is introduced for the classic CRAY. 530FORTRAN_REAL is 'double' on t3e and 'float' elsewhere. 531FORTRAN_REAL thus corresponds to FORTRAN's REAL on all machines, including t3e. 532 533 534o f2c 535 f2c, by default promotes REAL functions to double. cfortran.h does not (yet) 536support this, so the f2c -R option must be used to turn this promotion off. 537 538o f2c 539[Thanks to Dario Autiero for pointing out the following.] 540f2c has a strange feature in that either one or two underscores are appended 541to a Fortran name of a routine or common block, 542depending on whether or not the original name contains an underscore. 543 544 S.I. Feldman et al., "A fortran to C converter", 545 Computing Science Technical Report No. 149. 546 547 page 2, chapter 2: INTERLANGUAGE conventions 548 ........... 549 To avoid conflict with the names of library routines and with names that 550 f2c generates, 551 Fortran names may have one or two underscores appended. Fortran names are 552 forced to lower case (unless the -U option described in Appendix B is in 553 effect); external names, i.e. the names of fortran procedures and common 554 blocks, have a single underscore appended if they do not contain any 555 underscore and have a pair of underscores appended if they do contain 556 underscores. Thus fortran subroutines names ABC, A_B_C and A_B_C_ result 557 in C functions named abc_, a_b_c__ and a_b_c___. 558 ........... 559 560cfortran.h is unable to change the naming convention on a name by name basis. 561Fortran routine and common block names which do not contain an underscore 562are unaffected by this feature. 563Names which do contain an underscore may use the following work-around: 564 565/* First 2 lines are a completely standard cfortran.h interface 566 to the Fortran routine E_ASY . */ 567 PROTOCCALLSFSUB2(E_ASY,e_asy, PINT, INT) 568#define E_ASY(A,B) CCALLSFSUB2(E_ASY,e_asy, PINT, INT, A, B) 569#ifdef f2cFortran 570#define e_asy_ e_asy__ 571#endif 572/* Last three lines are a work-around for the strange f2c naming feature. */ 573 574o NAG f90 575 The Fortran 77 subset of Fortran 90 is supported. Extending cfortran.h to 576interface C with all of Fortran 90 has not yet been examined. 577 The NAG f90 library hijacks the main() of any program and starts the user's 578program with a call to: void f90_main(void); 579While this in itself is only a minor hassle, a major problem arises because 580NAG f90 provides no mechanism to access command line arguments. 581 At least version 'NAGWare f90 compiler Version 1.1(334)' appended _CB to 582common block names instead of the usual _. To fix, add this to cfortran.h: 583#ifdef old_NAG_f90_CB_COMMON 584#define COMMON_BLOCK CFC_ /* for all other Fortran compilers */ 585#else 586#define COMMON_BLOCK(UN,LN) _(LN,_CB) 587#endif 588 589o RS/6000 590 Using "xlf -qextname ...", which appends an underscore, '_', to all FORTRAN 591external references, requires "cc -Dextname ..." so that cfortran.h also 592generates these underscores. 593Use -Dextname=extname if extname is a symbol used in the C code. 594The use of "xlf -qextname" is STRONGLY ENCOURAGED, since it allows for 595transparent naming schemes when mixing C and Fortran. 596 597o HP9000 598 Using "f77 +ppu ...", which appends an underscore, '_', to all FORTRAN 599external references, requires "cc -Dextname ..." so that cfortran.h also 600generates these underscores. 601Use -Dextname=extname if extname is a symbol used in the C code. 602The use of "f77 +ppu" is STRONGLY ENCOURAGED, since it allows for 603transparent naming schemes when mixing C and Fortran. 604 605 At least one release of the HP /lib/cpp.ansi preprocessor is broken and will 606go into an infinite loop when trying to process cfortran.h with the 607## catenation operator. The K&R version of cfortran.h must then be used and the 608K&R preprocessor must be specified. e.g. 609 HP9000> cc -Aa -tp,/lib/cpp -c source.c 610The same problem with a similar solution exists on the Apollo. 611An irrelevant error message '0: extraneous name /usr/include' will appear for 612each source file due to another HP bug, and can be safely ignored. 613e.g. 'cc -v -c -Aa -tp,/lib/cpp cfortest.c' will show that the driver passes 614'-I /usr/include' instead of '-I/usr/include' to /lib/cpp 615 616On some machines the above error causes compilation to stop; one must then use 617K&R C, as with old HP compilers which don't support function prototyping. 618cfortran.h has to be informed that K&R C is to being used, e.g. 619HP9000> cc -D__CF__KnR -c source.c 620 621o AbsoftUNIXFortran 622By default, cfortran.h follows the default AbsoftUNIX/ProFortran and prepends _C 623to each COMMON BLOCK name. To override the cfortran.h behavior 624#define COMMON_BLOCK(UN,LN) before #including cfortran.h. 625[Search for COMMON_BLOCK in cfortran.h for examples.] 626 627o Apollo 628On at least one release, 'C compiler 68K Rev6.8(168)', the default C 629preprocessor, from cc -A xansi or cc -A ansi, enters an infinite loop when 630using cfortran.h. This Apollo bug can be circumvented by using: 631 . cc -DANSI_C_preprocessor=0 to force use of /**/, instead of '##'. 632 AND . The pre-ANSI preprocessor, i.e. use cc -Yp,/usr/lib 633The same problem with a similar solution exists on the HP. 634 635o Sun 636Old versions of cc(1), say <~1986, may require help for cfortran.h applications: 637 . #pragma may not be understood, hence cfortran.h and cfortest.c may require 638 sun> mv cfortran.h cftmp.h && grep -v "^#pragma" <cftmp.h >cfortran.h 639 sun> mv cfortest.c cftmp.c && grep -v "^#pragma" <cftmp.c >cfortest.c 640 . Old copies of math.h may not include the following from a newer math.h. 641 [For an ancient math.h on a 386 or sparc, get similar from a new math.h.] 642 #ifdef mc68000 /* 5 lines Copyright (c) 1988 by Sun Microsystems, Inc. */ 643 #define FLOATFUNCTIONTYPE int 644 #define RETURNFLOAT(x) return (*(int *)(&(x))) 645 #define ASSIGNFLOAT(x,y) *(int *)(&x) = y 646 #endif 647 648o CRAY, Sun, Apollo [pre 6.8 cc], VAX Ultrix and HP9000 649 Only FORTRAN routines with less than 15 arguments can be prototyped for C, 650since these compilers don't allow more than 31 arguments to a C macro. This can 651be overcome, [see Section IV], with access to any C compiler without this 652limitation, e.g. gcc, on ANY machine. 653 654o VAX Ultrix 655 vcc (1) with f77 is not supported. Although: 656VAXUltrix> f77 -c cfortex.f 657VAXUltrix> vcc -o cfortest cfortest.c cfortex.o -lI77 -lU77 -lF77 && cfortest 658will link and run. However, the FORTRAN standard I/O is NOT merged with the 659stdin and stdout of C, and instead uses the files fort.6 and fort.5. For vcc, 660f77 can't drive the linking, as for gcc and cc, since vcc objects must be 661linked using lk (1). f77 -v doesn't tell much, and without VAX Ultrix manuals, 662the author can only wait for the info. required. 663 664 fort (1) is not supported. Without VAX Ultrix manuals the author cannot 665convince vcc/gcc/cc and fort to generate names of routines and COMMON blocks 666that match at the linker, lk (1). i.e. vcc/gcc/cc prepend a single underscore 667to external references, e.g. NAME becomes _NAME, while fort does not modify the 668references. So ... either fort has prepend an underscore to external 669references, or vcc/gcc/cc have to generate unmodified names. man 1 fort 670mentions JBL, is JBL the only way? 671 672o VAX VMS C 673 The compiler 'easily' exhausts its table space and generates: 674%CC-F-BUGCHECK, Compiler bug check during parser phase . 675 Submit an SPR with a problem description. 676 At line number 777 in DISK:[DIR]FILE.C;1. 677where the line given, '777', includes a call across C and FORTRAN via 678cfortran.h, usually with >7 arguments and/or very long argument expressions. 679This SPR can be staved off, with the simple modification to cfortran.h, such 680that the relevant CCALLSFSUBn (or CCALLSFFUNn or FCALLSCFUNn) is not 681cascaded up to CCALLSFSUB14, and instead has its own copy of the contents of 682CCALLSFSUB14. [If these instructions are not obvious after examining cfortran.h 683please contact the author.] 684[Thanks go to Mark Kyprianou (kyp@stsci.edu) for this solution.] 685 686o Mips compilers 687 e.g. DECstations and SGI, require applications with a C main() and calls to 688GETARG(3F), i.e. FORTRAN routines returning the command line arguments, to use 689two macros as shown: 690 : 691CF_DECLARE_GETARG; /* This must be external to all routines. */ 692 : 693main(int argc, char *argv[]) 694{ 695 : 696CF_SET_GETARG(argc,argv); /* This must precede any calls to GETARG(3F). */ 697 : 698} 699The macros are null and benign on all other systems. Sun's GETARG(3F) also 700doesn't work with a generic C main() and perhaps a workaround similar to the 701Mips' one exists. 702 703o Alpha/OSF 704Using the DEC Fortran and the DEC C compilers of DEC OSF/1 [RT] V1.2 (Rev. 10), 705Fortran, when called from C, has occasional trouble using a routine received as 706a dummy argument. 707 708e.g. In the following the Fortran routine 'e' will crash when it tries to use 709 the C routine 'c' or the Fortran routine 'f'. 710 The example works on other systems. 711 712C FORTRAN /* C */ 713 integer function f() #include <stdio.h> 714 f = 2 int f_(); 715 return int e_(int (*u)()); 716 end 717 int c(){ return 1;} 718 integer function e(u) int d (int (*u)()) { return u();} 719 integer u 720 external u main() 721 e=u() { /* Calls to d work. */ 722 return printf("d (c ) returns %d.\n",d (c )); 723 end printf("d (f_) returns %d.\n",d (f_)); 724 /* Calls to e_ crash. */ 725 printf("e_(c ) returns %d.\n",e_(c )); 726 printf("e_(f_) returns %d.\n",e_(f_)); 727 } 728 729Solutions to the problem are welcomed! 730A kludge which allows the above example to work correctly, requires an extra 731argument to be given when calling the dummy argument function. 732i.e. Replacing 'e=u()' by 'e=u(1)' allows the above example to work. 733 734 735o The FORTRAN routines are called using macro expansions, therefore the usual 736caveats for expressions in arguments apply. The expressions to the routines may 737be evaluated more than once, leading to lower performance and in the worst case 738bizarre bugs. 739 740o For those who wish to use cfortran.h in large applications. [See Section IV.] 741This release is intended to make it easy to get applications up and running. 742This implies that applications are not as efficient as they could be: 743- The current mechanism is inefficient if a single header file is used to 744 describe a large library of FORTRAN functions. Code for a static wrapper fn. 745 is generated in each piece of C source code for each FORTRAN function 746 specified with the CCALLSFFUNn statement, irrespective of whether or not the 747 function is ever called. 748- Code for several static utility routines internal to cfortran.h is placed 749 into any source code which #includes cfortran.h. These routines should 750 probably be in a library. 751 752 753i) Calling FORTRAN routines from C: 754 -------------------------------- 755 756The FORTRAN routines are defined by one of the following two instructions: 757 758for a SUBROUTINE: 759/* PROTOCCALLSFSUBn is optional for C, but mandatory for C++. */ 760PROTOCCALLSFSUBn(ROUTINE_NAME,routine_name,argtype_1,...,argtype_n) 761#define Routine_name(argname_1,..,argname_n) \ 762CCALLSFSUBn(ROUTINE_NAME,routine_name,argtype_1,...,argtype_n, \ 763 argname_1,..,argname_n) 764 765for a FUNCTION: 766PROTOCCALLSFFUNn(routine_type,ROUTINE_NAME,routine_name,argtype_1,...,argtype_n) 767#define Routine_name(argname_1,..,argname_n) \ 768CCALLSFFUNn(ROUTINE_NAME,routine_name,argtype_1,...,argtype_n, \ 769 argname_1,..,argname_n) 770 771Where: 772'n' = 0->14 [SUBROUTINE's ->27] (easily expanded in cfortran.h to > 14 [27]) is 773 the number of arguments to the routine. 774Routine_name = C name of the routine (IN UPPER CASE LETTERS).[see 2.below] 775ROUTINE_NAME = FORTRAN name of the routine (IN UPPER CASE LETTERS). 776routine_name = FORTRAN name of the routine (IN lower case LETTERS). 777routine_type = the type of argument returned by FORTRAN functions. 778 = BYTE, DOUBLE, FLOAT, INT, LOGICAL, LONG, SHORT, STRING, VOID. 779 [Instead of VOID one would usually use CCALLSFSUBn. 780 VOID forces a wrapper function to be used.] 781argtype_i = the type of argument passed to the FORTRAN routine and must be 782 consistent in the definition and prototyping of the routine s.a. 783 = BYTE, DOUBLE, FLOAT, INT, LOGICAL, LONG, SHORT, STRING. 784 For vectors, i.e. 1 dim. arrays use 785 = BYTEV, DOUBLEV, FLOATV, INTV, LOGICALV, LONGV, SHORTV, 786 STRINGV, ZTRINGV. 787 For vectors of vectors, i.e. 2 dim. arrays use 788 = BYTEVV, DOUBLEVV, FLOATVV, INTVV, LOGICALVV, LONGVV, SHORTVV. 789 For n-dim. arrays, 1<=n<=7 [7 is the maximum in Fortran 77], 790 = BYTEV..nV's..V, DOUBLEV..V, FLOATV..V, INTV..V, LOGICALV..V, 791 LONGV..V, SHORTV..V. 792 N.B. Array dimensions and types are checked by the C compiler. 793 For routines changing the values of an argument, the keyword is 794 prepended by a 'P'. 795 = PBYTE, PDOUBLE, PFLOAT, PINT, PLOGICAL, PLONG, PSHORT, 796 PSTRING, PSTRINGV, PZTRINGV. 797 For EXTERNAL procedures passed as arguments use 798 = ROUTINE. 799 For exceptional arguments which require no massaging to fit the 800 argument passing mechanisms use 801 = PVOID. 802 The argument is cast and passed as (void *). 803 Although PVOID could be used to describe all array arguments on 804 most (all?) machines , it shouldn't be because the C compiler 805 can no longer check the type and dimension of the array. 806argname_i = any valid unique C tag, but must be consistent in the definition 807 as shown. 808 809Notes: 810 8111. cfortran.h may be expanded to handle a more argument type. To suppport new 812arguments requiring complicated massaging when passed between Fortran and C, 813the user will have to understand cfortran.h and follow its code and mechanisms. 814 815To define types requiring little or no massaging when passed between Fortran 816and C, the pseudo argument type SIMPLE may be used. 817For a user defined type called 'newtype', the definitions required are: 818 819/* The following 7 lines are required verbatim. 820 'newtype' is the name of the new user defined argument type. 821*/ 822#define newtype_cfV( T,A,B,F) SIMPLE_cfV(T,A,B,F) 823#define newtype_cfSEP(T, B) SIMPLE_cfSEP(T,B) 824#define newtype_cfINT(N,A,B,X,Y,Z) SIMPLE_cfINT(N,A,B,X,Y,Z) 825#define newtype_cfSTR(N,T,A,B,C,D,E) SIMPLE_cfSTR(N,T,A,B,C,D,E) 826#define newtype_cfCC( T,A,B) SIMPLE_cfCC(T,A,B) 827#define newtype_cfAA( T,A,B) newtype_cfB(T,A) /* Argument B not used. */ 828#define newtype_cfU( T,A) newtype_cfN(T,A) 829 830/* 'parameter_type(A)' is a declaration for 'A' and describes the type of the 831parameter expected by the Fortran function. This type will be used in the 832prototype for the function, if using ANSI C, and to declare the argument used 833by the intermediate function if calling a Fortran FUNCTION. 834Valid 'parameter_type(A)' include: int A 835 void (*A)() 836 double A[17] 837*/ 838#define newtype_cfN( T,A) parameter_type(A) /* Argument T not used. */ 839 840/* Before any argument of the new type is passed to the Fortran routine, it may 841be massaged as given by 'massage(A)'. 842*/ 843#define newtype_cfB( T,A) massage(A) /* Argument T not used. */ 844 845An example of a simple user defined type is given cfortex.f and cfortest.c. 846Two uses of SIMPLE user defined types are [don't show the 7 verbatim #defines]: 847 848/* Pass the address of a structure, using a type called PSTRUCT */ 849#define PSTRUCT_cfN( T,A) void *A 850#define PSTRUCT_cfB( T,A) (void *) &(A) 851 852/* Pass an integer by value, (not standard F77 ), using a type called INTVAL */ 853#define INTVAL_cfN( T,A) int A 854#define INTVAL_cfB( T,A) (A) 855 856[If using VAX VMS, surrounding the #defines with "#pragma (no)standard" allows 857 the %CC-I-PARAMNOTUSED messages to be avoided.] 858 859Upgrades to cfortran.h try to be, and have been, backwards compatible. This 860compatibility cannot be offered to user defined types. SIMPLE user defined 861types are less of a risk since they require so little effort in their creation. 862If a user defined type is required in more than one C header file of interfaces 863to libraries of Fortran routines, good programming practice, and ease of code 864maintenance, suggests keeping any user defined type within a single file which 865is #included as required. To date, changes to the SIMPLE macros were introduced 866in versions 2.6, 3.0 and 3.2 of cfortran.h. 867 868 8692. Routine_name is the name of the macro which the C programmer will use in 870order to call a FORTRAN routine. In theory Routine_name could be any valid and 871unique name, but in practice, the name of the FORTRAN routine in UPPER CASE 872works everywhere and would seem to be an obvious choice. 873 874 8753. <BYTE|DOUBLE|BYTE|DOUBLE|FLOAT|INT|LOGICAL|LONG|SHORT><V|VV|VVV|...> 876 877cfortran.h encourages the exact specification of the type and dimension of 878array parameters because it allows the C compiler to detect errors in the 879arguments when calling the routine. 880 881cfortran.h does not strictly require the exact specification since the argument 882is merely the address of the array and is passed on to the calling routine. 883Any array parameter could be declared as PVOID, but this circumvents 884C's compiletime ability to check the correctness of arguments and is therefore 885discouraged. 886 887Passing the address of these arguments implies that PBYTEV, PFLOATV, ... , 888PDOUBLEVV, ... don't exist in cfortran.h, since by default the routine and the 889calling code share the same array, i.e. the same values at the same memory 890location. 891 892These comments do NOT apply to arrays of (P)S/ZTRINGV. For these parameters, 893cfortran.h passes a massaged copy of the array to the routine. When the routine 894returns, S/ZTRINGV ignores the copy, while PS/ZTRINGV replaces the calling 895code's original array with copy, which may have been modified by the called 896routine. 897 898 8994. (P)STRING(V): 900- STRING - If the argument is a fixed length character array, e.g. char ar[8];, 901the string is blank, ' ', padded on the right to fill out the array before 902being passed to the FORTRAN routine. The useful size of the string is the same 903in both languages, e.g. ar[8] is passed as character*7. If the argument is a 904pointer, the string cannot be blank padded, so the length is passed as 905strlen(argument). On return from the FORTRAN routine, pointer arguments are not 906disturbed, but arrays have the terminating '\0' replaced to its original 907position. i.e. The padding blanks are never visible to the C code. 908 909- PSTRING - The argument is massaged as with STRING before being passed to the 910FORTRAN routine. On return, the argument has all trailing blanks removed, 911regardless of whether the argument was a pointer or an array. 912 913- (P)STRINGV - Passes a 1- or 2-dimensional char array. e.g. char a[7],b[6][8]; 914STRINGV may thus also pass a string constant, e.g. "hiho". 915(P)STRINGV does NOT pass a pointer, e.g. char *, to either a 1- or a 9162-dimensional array, since it cannot determine the array dimensions. 917A pointer can only be passed using (P)ZTRINGV. 918N.B. If a C routine receives a character array argument, e.g. char a[2][3], 919 such an argument is actually a pointer and my thus not be passed by 920 (P)STRINGV. Instead (P)ZTRINGV must be used. 921 922- STRINGV - The elements of the argument are copied into space malloc'd, and 923each element is padded with blanks. The useful size of each element is the same 924in both languages. Therefore char bb[6][8]; is equivalent to character*7 bb(6). 925On return from the routine the malloc'd space is simply released. 926 927- PSTRINGV - Since FORTRAN has no trailing '\0', elements in an array of 928strings are contiguous. Therefore each element of the C array is padded with 929blanks and strip out C's trailing '\0'. After returning from the routine, the 930trailing '\0' is reinserted and kill the trailing blanks in each element. 931 932- SUMMARY: STRING(V) arguments are blank padded during the call to the FORTRAN 933routine, but remain original in the C code. (P)STRINGV arguments are blank 934padded for the FORTRAN call, and after returning from FORTRAN trailing blanks 935are stripped off. 936 937 9385. (P)ZTRINGV: 939- (P)ZTRINGV - is identical to (P)STRINGV, 940except that the dimensions of the array of strings is explicitly specified, 941which thus also allows a pointer to be passed. 942(P)ZTRINGV can thus pass a 1- or 2-dimensional char array, e.g. char b[6][8], 943or it can pass a pointer to such an array, e.g. char *p;. 944ZTRINGV may thus also pass a string constant, e.g. "hiho". 945If passing a 1-dimensional array, routine_name_ELEMS_j (see below) must be 1. 946[Users of (P)ZTRINGV should examine cfortest.c for examples.]: 947 948- (P)ZTRINGV must thus be used instead of (P)STRINGV whenever sizeof() 949can't be used to determine the dimensions of the array of string or strings. 950e.g. when calling FORTRAN from C with a char * received by C as an argument. 951 952- There is no (P)ZTRING type, since (P)ZTRINGV can pass a 1-dimensional 953array or a pointer to such an array, e.g. char a[7], *b; 954If passing a 1-dimensional array, routine_name_ELEMS_j (see below) must be 1. 955 956- To specify the numbers of elements, 957routine_name_ELEMS_j and routine_name_ELEMLEN_j must be defined as shown below 958before interfacing the routine with CCALLSFSUBn, PROTOCCALLSFFUNn, etc. 959 960#define routine_name_ELEMS_j ZTRINGV_ARGS(k) 961 [..ARGS for subroutines, ..ARGF for functions.] 962or 963#define routine_name_ELEMS_j ZTRINGV_NUM(l) 964Where: routine_name is as above. 965 j [1-n], is the argument being specifying. 966 k [1-n], the value of the k'th argument is the dynamic number 967 of elements for argument j. The k'th argument must be 968 of type BYTE, DOUBLE, FLOAT, INT, LONG or SHORT. 969 l the number of elements for argument j. This must be an 970 integer constant available at compile time. 971 i.e. it is static. 972 973- Similarly to specify the useful length, [i.e. don't count C's trailing '\0',] 974of each element: 975#define routine_name_ELEMLEN_j ZTRINGV_ARGS(m) 976 [..ARGS for subroutines, ..ARGF for functions.] 977or 978#define routine_name_ELEMLEN_j ZTRINGV_NUM(q) 979Where: m [1-n], as for k but this is the length of each element. 980 q as for l but this is the length of each element. 981 982 9836. ROUTINE 984The argument is an EXTERNAL procedure. 985 986When C passes a routine to Fortran, the language of the function must be 987specified as follows: [The case of some_*_function must be given as shown.] 988 989When C passes a C routine to a Fortran: 990 FORTRAN_ROUTINE(arg1, .... , 991 C_FUNCTION(SOME_C_FUNCTION,some_c_function), 992 ...., argn); 993 994and similarly when C passes a Fortran routine to Fortran: 995 FORTRAN_ROUTINE(arg1, .... , 996 FORTRAN_FUNCTION(SOME_FORT_FUNCTION,some_fort_function), 997 ...., argn); 998 999If fcallsc has been redefined; the same definition of fcallsc used when creating 1000the wrapper for 'some_c_function' must also be defined when C_FUNCTION is used. 1001See ii) 4. of this section for when and how to redefine fcallsc. 1002 1003ROUTINE was introduced with cfortran.h version 2.6. Earlier versions of 1004cfortran.h used PVOID to pass external procedures as arguments. Using PVOID for 1005this purpose is no longer recommended since it won't work 'as is' for 1006apolloFortran, hpuxFortran800, AbsoftUNIXFortran, AbsoftProFortran. 1007 10087. CRAY only: 1009In a given piece of source code, where FFUNC is any FORTRAN routine, 1010FORTRAN_FUNCTION(FFUNC,ffunc) 1011disallows a previous 1012#define FFUNC(..) CCALLSFSUBn(FFUNC,ffunc,...) [ or CCALLSFFUNn] 1013in order to make the UPPER CASE FFUNC callable from C. 1014#define Ffunc(..) ... is OK though, as are obviously any other names. 1015 1016 1017ii) Calling C routines from FORTRAN: 1018 -------------------------------- 1019 1020Each of the following two statements to export a C routine to FORTRAN create 1021FORTRAN 'wrappers', written in C, which must be compiled and linked along with 1022the original C routines and with the FORTRAN calling code. 1023 1024FORTRAN callable 'wrappers' may also be created for C macros. i.e. in this 1025section, the term 'C function' may be replaced by 'C macro'. 1026 1027for C functions returning void: 1028FCALLSCSUBn( Routine_name,ROUTINE_NAME,routine_name,argtype_1,...,argtype_n) 1029 1030for all other C functions: 1031FCALLSCFUNn(routine_type,Routine_name,ROUTINE_NAME,routine_name,argtype_1,...,argtype_n) 1032 1033Where: 1034'n' = 0->27 (easily expanded to > 27) stands for the number of arguments to the 1035 routine. 1036Routine_name = the C name of the routine. [see 9. below] 1037ROUTINE_NAME = the FORTRAN name of the routine (IN UPPER CASE LETTERS). 1038routine_name = the FORTRAN name of the routine (IN lower case LETTERS). 1039routine_type = the type of argument returned by C functions. 1040 = BYTE, DOUBLE, FLOAT, INT, LOGICAL, LONG, SHORT, STRING, VOID. 1041 [Instead of VOID, FCALLSCSUBn is recommended.] 1042argtype_i = the type of argument passed to the FORTRAN routine and must be 1043 consistent in the definition and prototyping of the routine 1044 = BYTE, DOUBLE, FLOAT, INT, LOGICAL, LONG, SHORT, STRING. 1045 For vectors, i.e. 1 dim. arrays use 1046 = BYTEV, DOUBLEV, FLOATV, INTV, LOGICALV, LONGV, SHORTV, STRINGV. 1047 For vectors of vectors, 2 dim. arrays use 1048 = BYTEVV, DOUBLEVV, FLOATVV, INTVV, LOGICALVV, LONGVV, SHORTVV. 1049 For n-dim. arrays use 1050 = BYTEV..nV's..V, DOUBLEV..V, FLOATV..V, INTV..V, LOGICALV..V, 1051 LONGV..V, SHORTV..V. 1052 For routines changing the values of an argument, the keyword is 1053 prepended by a 'P'. 1054 = PBYTE, PDOUBLE, PFLOAT, PINT, PLOGICAL, PLONG, PSHORT, 1055 PSTRING, PNSTRING, PPSTRING, PSTRINGV. 1056 For EXTERNAL procedures passed as arguments use 1057 = ROUTINE. 1058 For exceptional arguments which require no massaging to fit the 1059 argument passing mechanisms use 1060 = PVOID. 1061 The argument is cast and passed as (void *). 1062 1063 1064Notes: 1065 10660. For Fortran calling C++ routines, C++ does NOT easily allow support for: 1067 STRINGV. 1068 BYTEVV, DOUBLEVV, FLOATVV, INTVV, LOGICALVV, LONGVV, SHORTVV. 1069 BYTEV..V, DOUBLEV..V, FLOATV..V, INTV..V, LOGICALV..V, LONGV..V, SHORTV..V. 1070Though there are ways to get around this restriction, 1071the restriction is not serious since these types are unlikely to be used as 1072arguments for a C++ routine. 1073 10741. FCALLSCSUB/FUNn expect that the routine to be 'wrapped' has been properly 1075prototyped, or at least declared. 1076 1077 10782. cfortran.h may be expanded to handle a new argument type not already among 1079the above. 1080 1081 10823. <BYTE|DOUBLE|BYTE|DOUBLE|FLOAT|INT|LOGICAL|LONG|SHORT><V|VV|VVV|...> 1083 1084cfortran.h encourages the exact specification of the type and dimension of 1085array parameters because it allows the C compiler to detect errors in the 1086arguments when declaring the routine using FCALLSCSUB/FUNn, assuming the 1087routine to be 'wrapped' has been properly prototyped. 1088 1089cfortran.h does not strictly require the exact specification since the argument 1090is merely the address of the array and is passed on to the calling routine. 1091Any array parameter could be declared as PVOID, but this circumvents 1092C's compiletime ability to check the correctness of arguments and is therefore 1093discouraged. 1094 1095Passing the address of these arguments implies that PBYTEV, PFLOATV, ... , 1096PDOUBLEVV, ... don't exist in cfortran.h, since by default the routine and the 1097calling code share the same array, i.e. the same values at the same memory 1098location. 1099 1100These comments do NOT apply to arrays of (P)STRINGV. For these parameters, 1101cfortran.h passes a massaged copy of the array to the routine. When the routine 1102returns, STRINGV ignores the copy, while PSTRINGV replaces the calling 1103code's original array with copy, which may have been modified by the called 1104routine. 1105 1106 11074. (P(N))STRING arguments have any trailing blanks removed before being passed 1108to C, the same holds true for each element in (P)STRINGV. Space is malloc'd in 1109all cases big enough to hold the original string (elements) as well as C's 1110terminating '\0'. i.e. The useful size of the string (elements) is the same in 1111both languages. P(N)STRING(V) => the string (elements) will be copied from the 1112malloc'd space back into the FORTRAN bytes. If one of the two escape mechanisms 1113mentioned below for PNSTRING has been used, the copying back to FORTRAN is 1114obviously not relevant. 1115 1116 11175. (PN)STRING's, [NOT PSTRING's nor (P)STRINGV's,] behavior may be overridden 1118in two cases. In both cases PNSTRING and STRING behave identically. 1119 1120a) If a (PN)STRING argument's first 4 bytes are all the NUL character, 1121i.e. '\0\0\0\0' the NULL pointer is passed to the C routine. 1122 1123b) If the characters of a (PN)STRING argument contain at least one HEX-00, i.e. 1124the NUL character, i.e. C strings' terminating '\0', the address of the string 1125is simply passed to the C routine. i.e. The argument is treated in this case as 1126it would be with PPSTRING, to which we refer the reader for more detail. 1127 1128Mechanism a) overrides b). Therefore, to use this mechanism to pass the NULL 1129string, "", to C, the first character of the string must obviously be the NUL 1130character, but of the first 4 characters in the string, at least one must not 1131be HEX-00. 1132 1133Example: 1134C FORTRAN /* C */ 1135 character*40 str #include "cfortran.h" 1136C Set up a NULL as : void cs(char *s) {if (s) printf("%s.\n",s);} 1137C i) 4 NUL characters. FCALLSCSUB1(cs,CS,cs,STRING) 1138C ii) NULL pointer. 1139 character*4 NULL 1140 NULL = CHAR(0)//CHAR(0)//CHAR(0)//CHAR(0) 1141 1142 data str/'just some string'/ 1143 1144C Passing the NULL pointer to cs. 1145 call cs(NULL) 1146C Passing a copy of 'str' to cs. 1147 call cs(str) 1148C Passing address of 'str' to cs. Trailing blanks NOT killed. 1149 str(40:) = NULL 1150 call cs(str) 1151 end 1152 1153Strings passed from Fortran to C via (PN)STRING must not have undefined 1154contents, otherwise undefined behavior will result, since one of the above two 1155escape mechanisms may occur depending on the contents of the string. 1156 1157This is not be a problem for STRING arguments, which are read-only in the C 1158routine and hence must have a well defined value when being passed in. 1159 1160PNSTRING arguments require special care. Even if they are write-only in the C 1161routine, PNSTRING's above two escape mechanisms require that the value of the 1162argument be well defined when being passed in from Fortran to C. Therefore, 1163unless one or both of PNSTRING's escape mechanisms are required, PSTRING should 1164be used instead of PNSTRING. 1165Prior to version 2.8, PSTRING did have the above two escape mechanisms, 1166but they were removed from PSTRING to allow strings with undefined contents to 1167be passed in. PNSTRING behaves like the old PSTRING. 1168[Thanks go to Paul Dubois (dubios@icf.llnl.gov) for pointing out that PSTRING 1169 must allow for strings with undefined contents to be passed in.] 1170 1171Example: 1172C FORTRAN /* C */ 1173 character*10 s,sn #include "cfortran.h" 1174 void ps(char *s) {strcpy(s,"hello");} 1175C Can call ps with undef. s. FCALLSCSUB1(ps,PS,ps,PSTRING) 1176 call ps(s) FCALLSCSUB1(ps,PNS,pns,PNSTRING) 1177 print *,s,'=s' 1178 1179C Can't call pns with undef. s. 1180C e.g. If first 4 bytes of s were 1181C "\0\0\0\0", ps would try 1182C to copy to NULL because 1183C of PNSTRING mechanism. 1184 sn = "" 1185 call pns(sn) 1186 print *,sn,'=sn' 1187 1188 end 1189 1190 11916. PPSTRING 1192The address of the string argument is simply passed to the C routine. Therefore 1193the C routine and the FORTRAN calling code share the same string at the same 1194memory location. If the C routine modifies the string, the string will also be 1195modified for the FORTRAN calling code. 1196The user is responsible for negociating the differences in representation of a 1197string in Fortran and in C, i.e. the differences are not automatically resolved 1198as they are for (P(N)STRING(V). 1199This mechanism is provided for two reasons: 1200 - Some C routines require the string to exist at the given memory location, 1201 after the C routine has exited. Recall that for the usual (P(N)STRING(V) 1202 mechanism, a copy of the FORTRAN string is given to the C routine, and this 1203 copy ceases to exist after returning to the FORTRAN calling code. 1204 - This mechanism can save runtime CPU cycles over (P(N)STRING(V), since it 1205 does not perform their malloc, copy and kill trailing blanks of the string 1206 to be passed. 1207 Only in a small minority of cases does the potential benefit of the saved 1208 CPU cycles outweigh the programming effort required to manually resolve 1209 the differences in representation of a string in Fortran and in C. 1210 1211For arguments passed via PPSTRING, the argument passed may also be an array of 1212strings. 1213 1214 12157. ROUTINE 1216ANSI C requires that the type of the value returned by the routine be known, 1217For all ROUTINE arguments passed from Fortran to C, the type of ROUTINE is 1218specified by defining a cast as follows: 1219 1220#undef ROUTINE_j 1221#define ROUTINE_j (cast) 1222where: 1223 j [1-n], is the argument being specifying. 1224 (cast) is a cast matching that of the argument expected by the C 1225 function protoytpe for which a wrapper is being defined. 1226 1227e.g. To create a Fortran wrapper for qsort(3C): 1228#undef ROUTINE_4 1229#define ROUTINE_4 (int (*)(void *,void *)) 1230FCALLSCSUB4(qsort,FQSORT,fqsort,PVOID,INT,INT,ROUTINE) 1231 1232In order to maintain backward compatibility, cfortran.h defines a generic cast 1233for ROUTINE_1, ROUTINE_2, ..., ROUTINE_27. The user's definition is therefore 1234strictly required only for DEC C, which at the moment is the only compiler 1235which insists on the correct cast for pointers to functions. 1236 1237When using the ROUTINE argument inside some Fortran code: 1238- it is difficult to pass a C routine as the parameter, 1239 since in many Fortran implementations, 1240 Fortran has no access to the normal C namespace. 1241 e.g. For most UNIX, 1242 Fortran implicitly only has access to C routines ending in _. 1243 If the calling Fortran code receives the routine as a parameter 1244 it can of course easily pass it along. 1245- if a Fortran routine is passed directly as the parameter, 1246 the called C routine must call the parameter routine 1247 using the Fortran argument passing conventions. 1248- if a Fortran routine is to be passed as the parameter, 1249 but if Fortran can be made to pass a C routine as the parameter, 1250 then it may be best to pass a C-callable wrapper for the Fortran routine. 1251 The called C routine is thus spared all Fortran argument passing conventions. 1252 cfortran.h can be used to create such a C-callable wrapper 1253 to the parameter Fortran routine. 1254 1255ONLY PowerStationFortran: 1256This Fortran provides no easy way to pass a Fortran routine as an argument to a 1257C routine. The problem arises because in Fortran the stack is cleared by the 1258called routine, while in C/C++ it is cleared by the caller. 1259The C/C++ stack clearing behavior can be changed to that of Fortran by using 1260stdcall__ in the function prototype. The stdcall__ cannot be applied in this 1261case since the called C routine expects the ROUTINE parameter to be a C routine 1262and does not know that it should apply stdcall__. 1263In principle the cfortran.h generated Fortran callable wrapper for the called C 1264routine should be able to massage the ROUTINE argument such that stdcall__ is 1265performed, but it is not yet known how this could be easily done. 1266 1267 12688. THE FOLLOWING INSTRUCTIONS ARE NOT REQUIRED FOR VAX VMS 1269 ------------ 1270(P)STRINGV information [NOT required for VAX VMS]: cfortran.h cannot convert 1271the FORTRAN vector of STRINGS to the required C vector of STRINGS without 1272explicitly knowing the number of elements in the vector. The application must 1273do one of the following for each (P)STRINGV argument in a routine before that 1274routine's FCALLSCFUNn/SUBn is called: 1275 1276#define routine_name_STRV_Ai NUM_ELEMS(j) 1277 or 1278#define routine_name_STRV_Ai NUM_ELEM_ARG(k) 1279 or 1280#define routine_name_STRV_Ai TERM_CHARS(l,m) 1281 1282where: routine_name is as above. 1283 i [i=1->n.] specifies the argument number of a STRING VECTOR. 1284 j would specify a fixed number of elements. 1285 k [k=1->n. k!=i] would specify an integer argument which specifies the 1286 number of elements. 1287 l [char] the terminating character at the beginning of an 1288 element, indicating to cfortran.h that the preceding 1289 elements in the vector are the valid ones. 1290 m [m=1-...] the number of terminating characters required to appear 1291 at the beginning of the terminating string element. 1292 The terminating element is NOT passed on to 1293 the C routine. 1294 1295e.g. #define ce_STRV_A1 TERM_CHARS(' ',2) 1296 FCALLSCSUB1(ce,CE,ce,STRINGV) 1297 1298cfortran.h will pass on all elements, in the 1st and only argument to the C 1299routine ce, of the STRING VECTOR until, but not including, the first string 1300element beginning with 2 blank, ' ', characters. 1301 1302 13039. INSTRUCTIONS REQUIRED ONLY FOR FORTRAN COMPILERS WHICH GENERATE 1304 ------------- 1305 ROUTINE NAMES WHICH ARE UNDISTINGUISHABLE FROM C ROUTINE NAMES 1306 i.e. VAX VMS 1307 AbsoftUNIXFortran (AbsoftProFortran ok, since it uses Uppercase names.) 1308 HP9000 if not using the +ppu option of f77 1309 IBM RS/6000 if not using the -qextname option of xlf 1310 Call them the same_namespace compilers. 1311 1312FCALLSCSUBn(...) and FCALLSCFUNn(...), when compiled, are expanded into 1313'wrapper' functions, so called because they wrap around the original C 1314functions and interface the format of the original C functions' arguments and 1315return values with the format of the FORTRAN call. 1316 1317Ideally one wants to be able to call the C routine from FORTRAN using the same 1318name as the original C name. This is not a problem for FORTRAN compilers which 1319append an underscore, '_', to the names of routines, since the original C 1320routine has the name 'name', and the FORTRAN wrapper is called 'name_'. 1321Similarly, if the FORTRAN compiler generates upper case names for routines, the 1322original C routine 'name' can have a wrapper called 'NAME', [Assuming the C 1323routine name is not in upper case.] For these compilers, e.g. Mips, CRAY, IBM 1324RS/6000 'xlf -qextname', HP-UX 'f77 +ppu', the naming of the wrappers is done 1325automatically. 1326 1327For same_namespace compilers things are not as simple, but cfortran.h tries to 1328provide tools and guidelines to minimize the costs involved in meeting their 1329constraints. The following two options can provide same_namespace compilers 1330with distinct names for the wrapper and the original C function. 1331 1332These compilers are flagged by cfortran.h with the CF_SAME_NAMESPACE constant, 1333so that the change in the C name occurs only when required. 1334 1335For the remainder of the discussion, routine names generated by FORTRAN 1336compilers are referred to in lower case, these names should be read as upper 1337case for the appropriate compilers. 1338 1339 1340HP9000: (When f77 +ppu is not used.) 1341f77 has a -U option which forces uppercase external names to be generated. 1342Unfortunately, cc does not handle recursive macros. Hence, if one wished to use 1343-U for separate C and FORTRAN namespaces, one would have to adopt a different 1344convention of naming the macros which allow C to call FORTRAN subroutines. 1345(Functions are not a problem.) The macros are currently the uppercase of the 1346original FORTRAN name, and would have to be changed to lower case or mixed 1347case, or to a different name. (Lower case would of course cause conflicts on 1348many other machines.) Therefore, it is suggested that f77 -U not be used, and 1349instead that Option a) or Option b) outlined below be used. 1350 1351 1352VAX/VMS: 1353For the name used by FORTRAN in calling a C routine to be the same as that of 1354the C routine, the source code of the C routine is required. A preprocessor 1355directive can then force the C compiler to generate a different name for the C 1356routine. 1357e.g. #if defined(vms) 1358 #define name name_ 1359 #endif 1360 void name() {printf("name: was called.\n");} 1361 FCALLSCSUB0(name,NAME,name) 1362 1363In the above, the C compiler generates the original routine with the name 1364'name_' and a wrapper called 'NAME'. This assumes that the name of the routine, 1365as seen by the C programmer, is not in upper case. The VAX VMS linker is not 1366case sensitive, allowing cfortran.h to export the upper case name as the 1367wrapper, which then doesn't conflict with the routine name in C. Since the IBM, 1368HP and AbsoftUNIXFortran platforms have case sensitive linkers 1369this technique is not available to them. 1370 1371The above technique is required even if the C name is in mixed case, see 1372Option a) for the other compilers, but is obviously not required when 1373Option b) is used. 1374 1375 1376Option a) Mixed Case names for the C routines to be called by FORTRAN. 1377 1378If the original C routines have mixed case names, there are no name space 1379conflicts. 1380 1381Nevertheless for VAX/VMS, the technique outlined above must also used. 1382 1383 1384Option b) Modifying the names of C routines when used by FORTRAN: 1385 1386The more robust naming mechanism, which guarantees portability to all machines, 1387'renames' C routines when called by FORTRAN. Indeed, one must change the names 1388on same_namespace compilers when FORTRAN calls C routines for which the source 1389is unavailable. [Even when the source is available, renaming may be preferable 1390to Option a) for large libraries of C routines.] 1391 1392Obviously, if done for a single type of machine, it must be done for all 1393machines since the names of routines used in FORTRAN code cannot be easily 1394redefined for different machines. 1395 1396The simplest way to achieve this end is to do explicitly give the modified 1397FORTRAN name in the FCALLSCSUBn(...) and FCALLSCFUNn(...) declarations. e.g. 1398 1399FCALLSCSUB0(name,CFNAME,cfname) 1400 1401This allows FORTRAN to call the C routine 'name' as 'cfname'. Any name can of 1402course be used for a given routine when it is called from FORTRAN, although 1403this is discouraged due to the confusion it is sure to cause. e.g. Bizarre, 1404but valid and allowing C's 'call_back' routine to be called from FORTRAN as 1405'abcd': 1406 1407FCALLSCSUB0(call_back,ABCD,abcd) 1408 1409 1410cfortran.h also provides preprocessor directives for a systematic 'renaming' of 1411the C routines when they are called from FORTRAN. This is done by redefining 1412the fcallsc macro before the FCALLSCSUB/FUN/n declarations as follows: 1413 1414#undef fcallsc 1415#define fcallsc(UN,LN) preface_fcallsc(CF,cf,UN,LN) 1416 1417FCALLSCSUB0(hello,HELLO,hello) 1418 1419Will cause C's routine 'hello' to be known in FORTRAN as 'cfhello'. Similarly 1420all subsequent FCALLSCSUB/FUN/n declarations will generate wrappers to allow 1421FORTRAN to call C with the C routine's name prefaced by 'cf'. The following has 1422the same effect, with subsequent FCALLSCSUB/FUN/n's appending the modifier to 1423the original C routines name. 1424 1425#undef fcallsc 1426#define fcallsc(UN,LN) append_fcallsc(Y,y,UN,LN) 1427 1428FCALLSCSUB0(Xroutine,ROUTINE,routine) 1429 1430Hence, C's Xroutine is called from FORTRAN as: 1431 CALL XROUTINEY() 1432 1433The original behavior of FCALLSCSUB/FUN/n, where FORTRAN routine names are left 1434identical to those of C, is returned using: 1435 1436#undef fcallsc 1437#define fcallsc(UN,LN) orig_fcallsc(UN,LN) 1438 1439 1440In C, when passing a C routine, i.e. its wrapper, as an argument to a FORTRAN 1441routine, the FORTRAN name declared is used and the correct fcallsc must be in 1442effect. E.g. Passing 'name' and 'routine' of the above examples to the FORTRAN 1443routines, FT1 and FT2, respectively: 1444 1445/* This might not be needed if fcallsc is already orig_fcallsc. */ 1446#undef fcallsc 1447#define fcallsc(UN,LN) orig_fcallsc(UN,LN) 1448FT1(C_FUNCTION(CFNAME,cfname)); 1449 1450#undef fcallsc 1451#define fcallsc(UN,LN) append_fcallsc(Y,y,UN,LN) 1452FT1(C_FUNCTION(XROUTINE,xroutine)); 1453 1454If the names of C routines are modified when used by FORTRAN, fcallsc would 1455usually be defined once in a header_file.h for the application. This definition 1456would then be used and be valid for the entire application and fcallsc would at 1457no point need to be redefined. 1458 1459 1460ONCE AGAIN: THE DEFINITIONS, INSTRUCTIONS, DECLARATIONS AND DIFFICULTIES 1461DESCRIBED HERE, NOTE 9. of II ii), 1462APPLY ONLY FOR VAX VMS, 1463 IBM RS/6000 WITHOUT THE -qextname OPTION FOR xlf, OR 1464 HP-UX WITHOUT THE +ppu OPTION FOR f77 1465 AbsoftUNIXFortran 1466AND APPLY ONLY WHEN CREATING WRAPPERS WHICH ENABLE FORTRAN TO CALL C ROUTINES. 1467 1468 1469 1470iii) Using C to manipulate FORTRAN COMMON BLOCKS: 1471 ------------------------------------------------------- 1472 1473FORTRAN common blocks are set up with the following three constructs: 1474 14751. 1476#define Common_block_name COMMON_BLOCK(COMMON_BLOCK_NAME,common_block_name) 1477 1478Common_block_name is in UPPER CASE. 1479COMMON_BLOCK_NAME is in UPPER CASE. 1480common_block_name is in lower case. 1481[Common_block_name actually follows the same 'rules' as Routine_name in Note 2. 1482 of II i).] This construct exists to ensure that C code accessing the common 1483block is machine independent. 1484 14852. 1486COMMON_BLOCK_DEF(TYPEDEF_OF_STRUCT, Common_block_name); 1487 1488where 1489typedef { ... } TYPEDEF_OF_STRUCT; 1490declares the structure which maps on to the common block. The #define of 1491Common_block_name must come before the use of COMMON_BLOCK_DEF. 1492 14933. 1494In exactly one of the C source files, storage should be set aside for the 1495common block with the definition: 1496 1497TYPEDEF_OF_STRUCT Common_block_name; 1498 1499The above definition may have to be omitted on some machines for a common block 1500which is initialized by Fortran BLOCK DATA or is declared with a smaller size 1501in the C routines than in the Fortran routines. 1502 1503The rules for common blocks are not well defined when linking/loading a mixture 1504of C and Fortran, but the following information may help resolve problems. 1505 1506From the 2nd or ANSI ed. of K&R C, p.31, last paragraph: 1507i) 1508 An external variable must be defined, exactly once, outside of any function; 1509 this sets aside storage for it. 1510ii) 1511 The variable must also be declared in each function that wants to access it; 1512 ... 1513 The declaration ... may be implicit from context. 1514 1515In Fortran, every routine says 'common /bar/ foo', 1516i.e. part ii) of the above, but there's no part i) requirement. 1517cc/ld on some machines don't require i) either. 1518Therefore, when handling Fortran, and sometimes C, 1519the loader/linker must automagically set aside storage for common blocks. 1520 1521Some loaders, including at least one for the CRAY, turn off the 1522'automagically set aside storage' capability for Fortran common blocks, 1523if any C object declares that common block. 1524Therefore, C code should define, i.e. set aside storage, 1525for the the common block as shown above. 1526 1527e.g. 1528C Fortran 1529 common /fcb/ v,w,x 1530 character *(13) v, w(4), x(3,2) 1531 1532/* C */ 1533typedef struct { char v[13],w[4][13],x[2][3][13]; } FCB_DEF; 1534#define Fcb COMMON_BLOCK(FCB,fcb) 1535COMMON_BLOCK_DEF(FCB_DEF,Fcb); 1536FCB_DEF Fcb; /* Definition, which sets aside storage for Fcb, */ 1537 /* may appear in at most one C source file. */ 1538 1539 1540C programs can place a string (or a multidimensional array of strings) into a 1541FORTRAN common block using the following call: 1542 1543C2FCBSTR( CSTR, FSTR,DIMENSIONS); 1544 1545where: 1546 1547CSTR is a pointer to the first element of C's copy of the string (array). 1548 The C code must use a duplicate of, not the original, common block string, 1549 because the FORTRAN common block does not allocate space for C strings' 1550 terminating '\0'. 1551 1552FSTR is a pointer to the first element of the string (array) in the common 1553 block. 1554 1555DIMENSIONS is the number of dimensions of string array. 1556 e.g. char a[10] has DIMENSIONS=0. 1557 char aa[10][17] has DIMENSIONS=1. 1558 etc... 1559 1560C2FCBSTR will copy the string (array) from CSTR to FSTR, padding with blanks, 1561' ', the trailing characters as required. C2FCBSTR uses DIMENSIONS and FSTR to 1562determine the lengths of the individual string elements and the total number of 1563elements in the string array. 1564 1565Note that: 1566- the number of string elements in CSTR and FSTR are identical. 1567- for arrays of strings, the useful lengths of strings in CSTR and FSTR must be 1568 the same. i.e. CSTR elements each have 1 extra character to accommodate the 1569 terminating '\0'. 1570- On most non-ANSI compilers, the DIMENSION argument cannot be prepended by any 1571 blanks. 1572 1573 1574FCB2CSTR( FSTR, CSTR,DIMENSIONS) 1575 1576is the inverse of C2FCBSTR, and shares the same arguments and caveats. 1577FCB2CSTR copies each string element of FSTR to CSTR, minus FORTRAN strings' 1578trailing blanks. 1579 1580 1581cfortran.h USERS ARE STRONGLY URGED TO EXAMINE THE COMMON BLOCK EXAMPLES IN 1582cfortest.c AND cfortex.f. The use of strings in common blocks is 1583demonstrated, along with a suggested way for C to imitate FORTRAN EQUIVALENCE'd 1584variables. 1585 1586 1587 ===> USERS OF CFORTRAN.H NEED READ NO FURTHER <=== 1588 1589 1590III Some Musings 1591---------------- 1592 1593cfortran.h is simple enough to be used by the most basic of applications, i.e. 1594making a single C/FORTRAN routine available to the FORTRAN/C programmers. Yet 1595cfortran.h is powerful enough to easily make entire C/FORTRAN libraries 1596available to FORTRAN/C programmers. 1597 1598 1599cfortran.h is the ideal tool for FORTRAN libraries which are being (re)written 1600in C, but are to (continue to) support FORTRAN users. It allows the routines to 1601be written in 'natural C', without having to consider the FORTRAN argument 1602passing mechanisms of any machine. It also allows C code accessing these 1603rewritten routines, to use the C entry point. Without cfortran.h, one risks the 1604perverse practice of C code calling a C function using FORTRAN argument passing 1605mechanisms! 1606 1607 1608Perhaps the philosophy and mechanisms of cfortran.h could be used and extended 1609to create other language bridges such as ADAFORTRAN, CPASCAL, COCCAM, etc. 1610 1611 1612The code generation machinery inside cfortran.h, i.e. the global structure is 1613quite good, being clean and workable as seen by its ability to meet the needs 1614and constraints of many different compilers. Though the individual instructions 1615of the A..., C..., T..., R... and K... tables deserve to be cleaned up. 1616 1617 1618 1619IV Getting Serious with cfortran.h 1620----------------------------------- 1621 1622cfortran.h is set up to be as simple as possible for the casual user. While 1623this ease of use will always be present, 'hooks', i.e. preprocessor directives, 1624are required in cfortran.h so that some of the following 'inefficiencies' can 1625be eliminated if they cause difficulties: 1626 1627o cfortran.h contains a few small routines for string manipulation. These 1628routines are declared static and are included and compiled in all source code 1629which uses cfortran.h. Hooks should be provided in cfortran.h to create an 1630object file of these routines, allowing cfortran.h to merely prototypes 1631these routines in the application source code. This is the only 'problem' which 1632afflicts both halves of cfortran.h. The remaining discussion refers to the C 1633calls FORTRAN half only. 1634 1635o Similar to the above routines, cfortran.h generates code for a 'wrapper' 1636routine for each FUNCTION exported from FORTRAN. Again cfortran.h needs 1637preprocessor directives to create a single object file of these routines, 1638and to merely prototype them in the applications. 1639 1640o Libraries often contain hundreds of routines. While the preprocessor makes 1641quick work of generating the required interface code from cfortran.h and the 1642application.h's, it may be convenient for very large stable libraries to have 1643final_application.h's which already contain the interface code, i.e. these 1644final_application.h's would not require cfortran.h. [The convenience can be 1645imagined for the VAX VMS CC compiler which has a fixed amount of memory for 1646preprocessor directives. Not requiring cfortran.h, with its hundreds of 1647directives, could help prevent this compiler from choking on its internal 1648limits quite so often.] 1649 1650With a similar goal in mind, cfortran.h defines 100's of preprocessor 1651directives. There is always the potential that these will clash with other tags 1652in the users code, so final_applications.h, which don't require cfortran.h, 1653also provide the solution. 1654 1655In the same vein, routines with more than 14 arguments can not be interfaced by 1656cfortran.h with compilers which limit C macros to 31 arguments. To resolve this 1657difficulty, final_application.h's can be created on a compiler without this 1658limitation. 1659 1660Therefore, new machinery is required to do: 1661 1662application.h + cfortran.h => final_application.h 1663 1664The following example may help clarify the means and ends: 1665 1666If the following definition of the HBOOK1 routine, the /*commented_out_part*/, 1667is passed through the preprocessor [perhaps #undefing and #defining preprocessor 1668constants if creating an application.h for compiler other than that of the 1669preprocessor being used, e.g. cpp -Umips -DCRAY ... ] : 1670 1671#include "cfortran.h" 1672PROTOCCALLSFSUB6(HBOOK1,hbook1,INT,STRING,INT,FLOAT,FLOAT,FLOAT) 1673/*#define HBOOK1(ID,CHTITLE,NX,XMI,XMA,VMX) \*/ 1674 CCALLSFSUB6(HBOOK1,hbook1,INT,STRING,INT,FLOAT,FLOAT,FLOAT, \ 1675 ID,CHTITLE,NX,XMI,XMA,VMX) 1676 1677A function prototype is produced by the PROTOCCALLSFSUB6(...). 1678Interface code is produced, based on the 'variables', 1679ID,CHTITLE,NX,XMI,XMA,VMX, which will correctly massage a HBOOK1 call. 1680Therefore, adding the #define line: 1681 1682'prototype code' 1683#define HBOOK1(ID,CHTITLE,NX,XMI,XMA,VMX) \ 1684 'interface code'(ID,CHTITLE,NX,XMI,XMA,VMX) 1685 1686which is placed into final_application.h. 1687 1688The only known limitation of the above method does not allow the 'variable' 1689names to include B1,B2,...,B9,BA,BB,... 1690 1691Obviously the machinery to automatically generate final_applications.h from 1692cfortran.h and applications.h needs more than just some preprocessor 1693directives, but a fairly simple unix shell script should be sufficient. Any 1694takers? 1695 1696 1697 1698V Machine Dependencies of cfortran.h 1699------------------------------------ 1700 1701Porting cfortran.h applications, e.g. the hbook.h and cstring.c mentioned 1702above, to other machines is trivial since they are machine independent. Porting 1703cfortran.h requires a solid knowledge of the new machines C preprocessor, and 1704its FORTRAN argument passing mechanisms. Logically cfortran.h exists as two 1705halves, a "C CALLS FORTRAN" and a "FORTRAN CALLS C" utility. In some cases it 1706may be perfectly reasonable to port only 'one half' of cfortran.h onto a new 1707system. 1708 1709 1710The lucky programmer porting cfortran.h to a new machine, must discover the 1711FORTRAN argument passing mechanisms. A safe starting point is to assume that 1712variables and arrays are simply passed by reference, but nothing is guaranteed. 1713Strings, and n-dimensional arrays of strings are a different story. It is 1714doubtful that any systems do it quite like VAX VMS does it, so that a UNIX or 1715f2c versions may provide an easier starting point. 1716 1717 1718cfortran.h uses and abuses the preprocessor's ## operator. Although the ## 1719operator does not exist in many compilers, many kludges do. cfortran.h uses 1720/**/ with no space allowed between the slashes, '/', and the macros or tags 1721to be concatenated. e.g. 1722#define concat(a,b) a/**/b /* works*/ 1723main() 1724{ 1725 concat(pri,ntf)("hello"); /* e.g. */ 1726} 1727N.B. On some compilers without ##, /**/ may also not work. The author may be 1728able to offer alternate kludges. 1729 1730 1731 1732VI Bugs in vendors C compilers and other curiosities 1733---------------------------------------------------- 1734 17351. ULTRIX xxxxxx 4.3 1 RISC 1736 1737Condolences to long suffering ultrix users! 1738DEC supplies a working C front end for alpha/OSF, but not for ultrix. 1739 1740From K&R ANSI C p. 231: 1741 ultrix> cat cat.c 1742 #define cat(x, y) x ## y 1743 #define xcat(x,y) cat(x,y) 1744 cat(cat(1,2),3) 1745 xcat(xcat(1,2),3) 1746 ultrix> cc -E cat.c 1747 123 <---- Should be: cat(1,2)3 1748 123 <---- Correct. 1749 ultrix> 1750 1751The problem for cfortran.h, preventing use of -std and -std1: 1752 ultrix> cat c.c 1753 #define cat(x, y) x ## y 1754 #define xcat(x,y) cat(x,y) 1755 #define AB(X) X+X 1756 #define C(E,F,G) cat(E,F)(G) 1757 #define X(E,F,G) xcat(E,F)(G) 1758 C(A,B,2) 1759 X(A,B,2) 1760 ultrix> cc -std1 -E c.c 1761 2+2 1762 AB (2) <---- ????????????? 1763 ultrix> 1764 ultrix> cc -std0 -E c.c 1765 2+2 1766 AB(2) <---- ????????????? 1767 ultrix> 1768 1769Due to further ultrix preprocessor problems, 1770for all definitions of definitions with arguments, 1771cfortran.h >= 3.0 includes the arguments and recommends the same, 1772even though it is not required by ANSI C. 1773e.g. Users are advised to do 1774 #define fcallsc(UN,LN) orig_fcallsc(UN,LN) 1775instead of 1776 #define fcallsc orig_fcallsc 1777since ultrix fails to properly preprocess the latter example. 1778CRAY used to (still does?) occasionally trip up on this problem. 1779 1780 17812. ConvexOS convex C210 11.0 convex 1782 1783In a program with a C main, output to LUN=6=* from Fortran goes into 1784$pwd/fort.6 instead of stdout. Presumably, a magic incantation can be called 1785from the C main in order to properly initialize the Fortran I/O. 1786 1787 17883. SunOS 5.3 Generic_101318-69 sun4m sparc 1789 1790The default data and code alignments produced by cc, gcc and f77 are compatible. 1791If deviating from the defaults, consistent alignment options must be used 1792across all objects compiled by cc and f77. [Does gcc provide such options?] 1793 1794 17954. SunOS 5.3 Generic_101318-69 sun4m sparc with cc: SC3.0.1 13 Jul 1994 1796 or equivalently 1797 ULTRIX 4.4 0 RISC using cc -oldc 1798 are K&R C preprocessors that suffer from infinite loop macros, e.g. 1799 1800 zedy03> cat src.c 1801 #include "cfortran.h" 1802 PROTOCCALLSFFUN1(INT,FREV,frev, INTV) 1803 #define FREV(A1) CCALLSFFUN1( FREV,frev, INTV, A1) 1804 /* To avoid the problem, deletete these ---^^^^--- spaces. */ 1805 main() { static int a[] = {1,2}; FREV(a); return EXIT_SUCCESS; } 1806 1807 zedy03> cc -c -Xs -v -DMAX_PREPRO_ARGS=31 -D__CF__KnR src.c 1808 "src.c", line 4: FREV: actuals too long 1809 "src.c", line 4: FREV: actuals too long 1810 .... 3427 more lines of the same message 1811 "src.c", line 4: FREV: actuals too long 1812 cc : Fatal error in /usr/ccs/lib/cpp 1813 Segmentation fault (core dumped) 1814 1815 18165. Older sun C compilers 1817 1818To link to f77 objects, older sun C compilers require the math.h macros: 1819 1820#define RETURNFLOAT(x) { union {double _d; float _f; } _kluge; \ 1821 _kluge._f = (x); return _kluge._d; } 1822#define ASSIGNFLOAT(x,y) { union {double _d; float _f; } _kluge; \ 1823 _kluge._d = (y); x = _kluge._f; } 1824 1825Unfortunately, in at least some copies of the sun math.h, the semi-colon 1826for 'float _f;' is left out, leading to compiler warnings. 1827 1828The solution is to correct math.h, or to change cfortran.h to #define 1829RETURNFLOAT(x) and ASSIGNFLOAT(x,y) instead of including math.h. 1830 1831 18326. gcc version 2.6.3 and probably all other versions as well 1833 1834Unlike all other C compilers supported by cfortran.h, 1835'gcc -traditional' promotes to double all functions returning float 1836as demonstrated bu the following example. 1837 1838/* m.c */ 1839#include <stdio.h> 1840int main() { FLOAT_FUNCTION d(); float f; f = d(); printf("%f\n",f); return 0; } 1841 1842/* d.c */ 1843float d() { return -123.124; } 1844 1845burow[29] gcc -c -traditional d.c 1846burow[30] gcc -DFLOAT_FUNCTION=float m.c d.o && a.out 18470.000000 1848burow[31] gcc -DFLOAT_FUNCTION=double m.c d.o && a.out 1849-123.124001 1850burow[32] 1851 1852Thus, 'gcc -traditional' is not supported by cfortran.h. 1853Support would require the same RETURNFLOAT, etc. macro machinery 1854present in old sun math.h, before sun gave up the same promotion. 1855 1856 18577. CRAY 1858 1859At least some versions of the t3e and t3d C preprocessor are broken 1860in the fashion described below. 1861At least some versions of the t90 C preprocessor do not have this problem. 1862 1863On the CRAY, all Fortran names are converted to uppercase. 1864Generally the uppercase name is also used for the macro interface 1865created by cfortran.h. 1866 1867For example, in the following interface, 1868EASY is both the name of the macro in the original C code 1869and EASY is the name of the resulting function to be called. 1870 1871#define EASY(A,B) CCALLSFSUB2(EASY,easy, PINT, INTV, A, B) 1872 1873The fact that a macro called EASY() expands to a function called EASY() 1874is not a problem for a working C preprocessor. 1875From Kernighan and Ritchie, 2nd edition, p.230: 1876 1877 In both kinds of macro, the replacement token sequence is repeatedly 1878 rescanned for more identifiers. However, once a given identifier has been 1879 replaced in a given expansion, it is not replaced if it turns up again during 1880 rescanning; instead it is left unchanged. 1881 1882Unfortunately, some CRAY preprocessors are broken and don't obey the above rule. 1883A work-around is for the user to NOT use the uppercase name 1884of the name of the macro interface provided by cfortran.h. For example: 1885 1886#define Easy(A,B) CCALLSFSUB2(EASY,easy, PINT, INTV, A, B) 1887 1888Luckily, the above work-around is not required since the following 1889work-around within cfortran.h also circumvents the bug: 1890 1891 /* (UN), not UN, is required in order to get around CRAY preprocessor bug.*/ 1892 #define CFC_(UN,LN) (UN) /* Uppercase FORTRAN symbols. */ 1893 1894Aside: The Visual C++ compiler is happy with UN, but barfs on (UN), 1895 so either (UN) causes nonstandard C/C++ or Visual C++ is broken. 1896 1897 1898VII History and Acknowledgements 1899-------------------------------- 1900 19011.0 - Supports VAX VMS using C 3.1 and FORTRAN 5.4. Oct. '90. 19021.0 - Supports Silicon Graphics w. Mips Computer 2.0 f77 and cc. Feb. '91. 1903 [Port of C calls FORTRAN half only.] 19041.1 - Supports Mips Computer System 2.0 f77 and cc. Mar. '91. 1905 [Runs on at least: Silicon Graphics IRIX 3.3.1 1906 DECstations with Ultrix V4.1] 19071.2 - Internals made simpler, smaller, faster, stronger. May '91. 1908 - Mips version works on IBM RS/6000, this is now called the unix version. 19091.3 - UNIX and VAX VMS versions are merged into a single cfortran.h. July '91. 1910 - C can help manipulate (arrays of) strings in FORTRAN common blocks. 1911 - Dimensions of string arrays arguments can be explicit. 1912 - Supports Apollo DomainOS 10.2 (sys5.3) with f77 10.7 and cc 6.7. 1913 19142.0 - Improved code generation machinery creates K&R or ANSI C. Aug. '91. 1915 - Supports Sun, CRAY. f2c with vcc on VAX Ultrix. 1916 - cfortran.h macros now require routine and COMMON block names in both 1917 upper and lower case. No changes required to applications though. 1918 - PROTOCCALLSFSUBn is eliminated, with no loss to cfortran.h performance. 1919 - Improved tools and guidelines for naming C routines called by FORTRAN. 19202.1 - LOGICAL correctly supported across all machines. Oct. '91. 1921 - Improved support for DOUBLE PRECISION on the CRAY. 1922 - HP9000 fully supported. 1923 - VAX Ultrix cc or gcc with f77 now supported. 19242.2 - SHORT, i.e. INTEGER*2, and BYTE now supported. Dec. '91. 1925 - LOGICAL_STRICT introduced. More compact and robust internal tables. 1926 - typeV and typeVV for type = BYTE, DOUBLE, FLOAT, INT, LOGICAL, LONG,SHORT. 1927 - FORTRAN passing strings and NULL pointer to C routines improved. 19282.3 - Extraneous arguments removed from many internal tables. May '92. 1929 - Introduce pseudo argument type SIMPLE for user defined types. 1930 - LynxOS using f2c supported. (Tested with LynxOS 2.0 386/AT.) 19312.4 - Separation of internal C and Fortran compilation directives. Oct. '92. 1932 - f2c and NAG f90 supported on all machines. 19332.5 - Minor mod.s to source and/or doc for HP9000, f2c, and NAG f90. Nov. '92. 19342.6 - Support external procedures as arguments with type ROUTINE. Dec. '92. 19352.7 - Support Alpha VMS. Support HP9000 f77 +ppu Jan. '93. 1936 - Support arrays with up to 7 dimensions. 1937 - Minor mod. of Fortran NULL to C via (P)STRING. 1938 - Specify the type of ROUTINE passed from Fortran to C [ANSI C requirement.] 1939 - Macros never receive a null parameter [RS/6000 requirement.] 19402.8 - PSTRING for Fortran calls C no longer provides escape to pass April'93. 1941 NULL pointer nor to pass address of original string. 1942 PNSTRING introduced with old PSTRING's behavior. 1943 PPSTRING introduced to always pass original address of string. 1944 - Support Alpha/OSF. 1945 - Document that common blocks used in C should be declared AND defined. 1946 19473.0 - Automagic handling of ANSI ## versus K&R /**/ preprocessor op. March'95. 1948 - Less chance of name space collisions between cfortran.h and other codes. 1949 - SIMPLE macros, supporting user defined types, have changed names. 19503.1 - Internal macro name _INT not used. Conflicted with IRIX 5.3. May '95. 1951 - SunOS, all versions, should work out of the box. 1952 - ZTRINGV_ARGS|F(k) may no longer point to a PDOUBLE or PFLOAT argument. 1953 - ConvexOS 11.0 supported. 19543.2 - __hpux no longer needs to be restricted to MAX_PREPRO_ARGS=31. Oct. '95. 1955 - PSTRING bug fixed. 1956 - ZTRINGV_ARGS|F(k) may not point to a PBYTE,PINT,PLONG or PSHORT argument. 1957 - (P)ZTRINGV machinery improved. Should lead to fewer compiler warnings. 1958 (P)ZTRINGV no longer limits recursion or the nesting of routines. 1959 - SIMPLE macros, supporting user defined types, have changed slightly. 19603.3 - Supports PowerStation Fortran with Visual C++. Nov. '95. 1961 - g77 should work using f2cFortran, though no changes made for it. 1962 - (PROTO)CCALLSFFUN10 extended to (PROTO)CCALLSFFUN14. 1963 - FCALLSCFUN10 and SUB10 extended to FCALLSCFUN14 and SUB14. 19643.4 - C++ supported, Dec. '95. 1965 but it required the reintroduction of PROTOCCALLSFSUBn for users. 1966 - HP-UX f77 +800 supported. 19673.5 - Absoft UNIX Fortran supported. Sept.'96. 19683.6 - Minor corrections to cfortran.doc. Oct. '96. 1969 - Fixed bug for 15th argument. [Thanks to Tom Epperly at Aspen Tech.] 1970 - For AbsoftUNIXFortran, obey default of prepending _C to COMMON BLOCK name. 1971 - Fortran calling C with ROUTINE argument fixed and cleaned up. 19723.7 - Circumvent IBM and HP "null argument" preprocessor warning. Oct. '96 19733.8 - (P)STRINGV and (P)ZTRINGV can pass a 1- or 2-dim. char array. Feb. '97 1974 (P)ZTRINGV thus effectively also provides (P)ZTRING. 1975 - (P)ZTRINGV accepts a (char *) pointer. 19763.9 - Bug fixed for *VVVVV. May '97 1977 - f2c: Work-around for strange underscore-dependent naming feature. 1978 - NEC SX-4 supported. 1979 - CRAY: LOGICAL conversion uses _btol and _ltob from CRAY's fortran.h. 1980 - CRAY: Avoid bug of some versions of the C preprocessor. 1981 - CRAY T3E: FORTRAN_REAL introduced. 1982 19834.0 - new/delete now used for C++. malloc/free still used for C. Jan. '98 1984 - FALSE no longer is defined by cfortran.h . 1985 - Absoft Pro Fortran for MacOS supported. 19864.1 - COMMA and COLON no longer are defined by cfortran.h . April'98 1987 - Bug fixed when 10th arg. or beyond is a string. 1988 [Rob Lucchesi of NASA-Goddard pointed out this bug.] 1989 - CCALLSFSUB/FUN extended from 14 to 27 arguments. 1990 - Workaround SunOS CC 4.2 cast bug. [Thanks to Savrak SAR of CERN.] 19914.2 - Portland Group needs -DpgiFortran . [Thank George Lai of NASA.] June '98 19924.3 - (PROTO)CCALLSFSUB extended from 20 to 27 arguments. July '98 1993 1994 1995['Support' implies these and more recent releases of the respective 1996 OS/compilers/linkers can be used with cfortran.h. 1997 Earlier releases may also work.] 1998 1999 2000Acknowledgements: 2001- CERN very generously sponsored a week in 1994 for me to work on cfortran.h. 2002- M.L.Luvisetto (Istituto Nazionale Fisica Nucleare - Centro Nazionale 2003 Analisi Fotogrammi, Bologna, Italy) provided all the support for the port to 2004 the CRAY. Marisa's encouragement and enthusiasm was also much appreciated. 2005- J.Bunn (CERN) supported the port to PowerStation Fortran with Visual C++. 2006- Paul Schenk (UC Riverside, CERN PPE/OPAL) in June 1993 extended cfortran.h 2.7 2007 to have C++ call Fortran. This was the starting point for full C++ in 3.4. 2008- Glenn P.Davis of University Corp. for Atmospheric Research (UCAR) / Unidata 2009 supported the NEC SX-4 port and helped understand the CRAY. 2010- Tony Goelz of Absoft Corporation ported cfortran.h to Absoft. 2011- Though cfortran.h has been created in my 'copious' free time, I thank 2012 NSERC for their generous support of my grad. student and postdoc years. 2013- Univ.Toronto, DESY, CERN and others have provided time on their computers. 2014 2015 2016THIS PACKAGE, I.E. CFORTRAN.H, THIS DOCUMENT, AND THE CFORTRAN.H EXAMPLE 2017PROGRAMS ARE PROPERTY OF THE AUTHOR WHO RESERVES ALL RIGHTS. THIS PACKAGE AND 2018THE CODE IT PRODUCES MAY BE FREELY DISTRIBUTED WITHOUT FEES, SUBJECT TO THE 2019FOLLOWING RESTRICTIONS: 2020- YOU MUST ACCOMPANY ANY COPIES OR DISTRIBUTION WITH THIS (UNALTERED) NOTICE. 2021- YOU MAY NOT RECEIVE MONEY FOR THE DISTRIBUTION OR FOR ITS MEDIA 2022 (E.G. TAPE, DISK, COMPUTER, PAPER.) 2023- YOU MAY NOT PREVENT OTHERS FROM COPYING IT FREELY. 2024- YOU MAY NOT DISTRIBUTE MODIFIED VERSIONS WITHOUT CLEARLY DOCUMENTING YOUR 2025 CHANGES AND NOTIFYING THE AUTHOR. 2026- YOU MAY NOT MISREPRESENTED THE ORIGIN OF THIS SOFTWARE, EITHER BY EXPLICIT 2027 CLAIM OR BY OMISSION. 2028 2029THE INTENT OF THE ABOVE TERMS IS TO ENSURE THAT THE CFORTRAN.H PACKAGE NOT BE 2030USED FOR PROFIT MAKING ACTIVITIES UNLESS SOME ROYALTY ARRANGEMENT IS ENTERED 2031INTO WITH ITS AUTHOR. 2032 2033THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER 2034EXPRESSED OR IMPLIED. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE 2035SOFTWARE IS WITH YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST 2036OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. THE AUTHOR IS NOT RESPONSIBLE 2037FOR ANY SUPPORT OR SERVICE OF THE CFORTRAN.H PACKAGE. 2038 2039 Burkhard Burow 2040 burow@desy.de 2041 2042P.S. Your comments and questions are welcomed and usually promptly answered. 2043 2044VAX VMS and Ultrix, Alpha, OSF, Silicon Graphics (SGI), DECstation, Mips RISC, 2045Sun, CRAY, Convex, IBM RS/6000, Apollo DomainOS, HP, LynxOS, f2c, NAG, Absoft, 2046NEC SX-4, PowerStation and Visual C++ are registered trademarks of their 2047respective owners. 2048 2049/* end: cfortran.doc */ 2050