Passing C FILE * back to FORTRAN and back to C

Passing C FILE * back to FORTRAN and back to C

I'm rusty on C. I have some C code that was written by someone else several years ago that does file I/O with fopen, fgets, fwrite, etc. The code acts on one file only with the FILE *, record length, and record structure being declared globally. I'm trying to modify the C code to make the FILE *, record length and record structure local to the routines and pass them as arguments from/to FORTRAN calling routines so that the FORTRAN caller can use the same routines for multiple files. My problem is passing the FILE * back to FORTRAN.

According to stdio.h:

struct _iobuf
{
int _cnt;
char *_ptr;
char *_base;
unsigned char _flag;

#if __CRTL_VER >= 70000000

unsigned char _padfile;
unsigned char _pad1;
unsigned char _pad2;
int _file;
#else
unsigned char _file;
unsigned char _pad1;
unsigned char _pad2;
#endif
};

#ifndef __FILE_T
# define __FILE_T
typedef struct _iobuf *FILE;
#endif

An include file for the C routines has

struct dict {
char name[MAXFLDNAMEBUF];
char data_type;
short start;
short end;
short width;
short decimals;
};

int ini_input(char *data_input_file, char *dictionary_file,
FILE *Data_fp, int *Inrecl, struct dict fld[MAXFLDS]);
int getdata(void *dictionary_structure_record, FILE *Data_fp,
int *Inrecl, struct dict fld[MAXFLDS]);

where Data_fp, Inrecl and fld are the file pointer, record length and record structure arguments that I added to the prototype and function declarations in the C code.

I'm having a problem passing back the file pointer structure to the FORTRAN code from ini_input where the file gets opened and the record structure initialized among other things. I need to pass it back to the FORTRAN caller so that the FORTRAN caller can later pass it to the C function getdata which reads a record and does some parsing. I've tried declaring a FORTRAN structure iobuf and passing it by reference, but must not be doing this right:

STRUCTURE /IOBUF/
INTEGER*4 CNT
INTEGER*4 PTR
INTEGER*4 BASE
BYTE FLAG
BYTE FILE
BYTE PAD1
BYTE PAD2
END STRUCTURE
RECORD /IOBUF/ FILE_PTR

INTEGER*4 INI_INPUT

STATUS = INI_INPUT(%REF(DATATMP), %REF(TMPSTR), %REF(FILE_PTR),
* FILE_LEN, %REF(REC_DESCR))

Any help would be appreciated.

1 post / 0 new
For more complete information about compiler optimizations, see our Optimization Notice.