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