From tomba Tue May 19 13:47:15 1998 To: linux-hep@qmw.ac.uk Subject: Fortran to C header file translation Hi, Does anyone know about a program which would translate Fortran header files into C header files? Our group has developed fortran libraries. To use them in fortran program one had to #include fortran header file like for example header.h: INTEGER IVAR, IPAR REAL RFAR, RPAR PARAMETER (IPAR=100,RPAR=3.14) INTEGER*4 IARR(IPAR) REAL*4 RARR(IPAR) COMMON /CMBLK/ IVAR,RVAR,IARR,RARR I would like it to be translated automatically into a human readable C header file, in the case above it would be header_c.h: #define IPAR 100 #define RPAR 3.14 struct cmblk_common { int ivar; float rvar; int iarr[IPAR]; float rarr[IPAR]; } extern cmblk_common cmblk_; --Tomasz Barszczak http://www.ps.uci.edu/~tomba/ From tomba Tue May 19 14:49:06 1998 To: linux-hep@qmw.ac.uk Subject: Re: Fortran to C header file translation > just add 'end' at the bottom and then use f2c to convert it. I tried, but there are several problems with it. After doing cat header.h | f2c -E the result is: Extern struct { integer ivar; real rvar; integer iarr[100]; real rarr[100]; } cmblk_; The problems are: 1. PARAMETER IPAR was converted to number 100, and there is no #define IPAR 100 or other way of using it as an upper limit of a loop for example. 2. The structure cmblk_ is an anonymous structure, I cannot make a pointer to it, which I need (in order to use debugger on it for example). --Tomasz Barszczak http://www.ps.uci.edu/~tomba/ From tomba Wed May 20 15:28:25 1998 To: dmg@bell-labs.com Subject: Fortran to C header file translation Content-Length: 1676 Status: RO I am trying to automatically translate Fortran header files into C header files. Our group has developed Fortran libraries. To use them in Fortran program one had to #include Fortran header file like for example header.h: INTEGER IVAR, IPAR REAL RFAR, RPAR PARAMETER (IPAR=100,RPAR=3.14) INTEGER*4 IARR(IPAR) REAL*4 RARR(IPAR) COMMON /CMBLK/ IVAR,RVAR,IARR,RARR I would like it to be translated automatically into a C header file, in the case above it would be header_c.h: #define IPAR 100 #define RPAR 3.14 struct cmblk_common { int ivar; float rvar; int iarr[IPAR]; float rarr[IPAR]; } extern cmblk_common cmblk_; When I try to do it by adding END at the end of header.h and doing cat header.h | f2c -E the result is: Extern struct { integer ivar; real rvar; integer iarr[100]; real rarr[100]; } cmblk_; There are several problems with this result: 1. PARAMETER IPAR was converted to number 100, and there is no #define IPAR 100 or other way of using it as an upper limit of a loop for example. 2. The structure cmblk_ is an anonymous structure, I cannot make a pointer to it, which I need (in order to use debugger on it for example). I.e. instead of Extern struct { ... } cmblk_; it should be something like Extern struct cmblk_common { ... } cmblk_; Do you know how can this be fixed? I know that f2c was not designed to do this kind of translation, but it gets pretty good results It seems to me like it would be pretty simple to modify it to preserve PARAMETER definitions and have all structures typed. --Tomasz Barszczak http://www.ps.uci.edu/~tomba/