<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Passing C FILE * back to FORTRAN and back to C in Software Archive</title>
    <link>https://community.intel.com/t5/Software-Archive/Passing-C-FILE-back-to-FORTRAN-and-back-to-C/m-p/943511#M17652</link>
    <description>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.  &lt;BR /&gt; &lt;BR /&gt;According to stdio.h: &lt;BR /&gt; &lt;BR /&gt;struct _iobuf  &lt;BR /&gt;{ &lt;BR /&gt;        int            _cnt; &lt;BR /&gt;        char          *_ptr; &lt;BR /&gt;        char          *_base; &lt;BR /&gt;        unsigned char  _flag; &lt;BR /&gt; &lt;BR /&gt;#if __CRTL_VER &amp;gt;= 70000000 &lt;BR /&gt; &lt;BR /&gt;        unsigned char  _padfile;   &lt;BR /&gt;        unsigned char  _pad1; &lt;BR /&gt;        unsigned char  _pad2; &lt;BR /&gt;        int            _file; &lt;BR /&gt;#else &lt;BR /&gt;        unsigned char  _file;   &lt;BR /&gt;        unsigned char  _pad1; &lt;BR /&gt;        unsigned char  _pad2; &lt;BR /&gt;#endif &lt;BR /&gt;}; &lt;BR /&gt; &lt;BR /&gt;#ifndef __FILE_T &lt;BR /&gt;#   define __FILE_T &lt;BR /&gt;typedef struct _iobuf *FILE; &lt;BR /&gt;#endif &lt;BR /&gt; &lt;BR /&gt;An include file for the C routines has  &lt;BR /&gt; &lt;BR /&gt;struct dict { &lt;BR /&gt;    char name[MAXFLDNAMEBUF]; &lt;BR /&gt;    char data_type; &lt;BR /&gt;    short start; &lt;BR /&gt;    short end; &lt;BR /&gt;    short width; &lt;BR /&gt;    short decimals; &lt;BR /&gt;}; &lt;BR /&gt; &lt;BR /&gt;int ini_input(char *data_input_file, char *dictionary_file,  &lt;BR /&gt;	FILE *Data_fp, int *Inrecl, struct dict fld[MAXFLDS]); &lt;BR /&gt;int getdata(void *dictionary_structure_record, FILE *Data_fp,  &lt;BR /&gt;	int *Inrecl, struct dict fld[MAXFLDS]); &lt;BR /&gt; &lt;BR /&gt;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. &lt;BR /&gt; &lt;BR /&gt;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: &lt;BR /&gt; &lt;BR /&gt;      STRUCTURE    /IOBUF/ &lt;BR /&gt;                   INTEGER*4      CNT &lt;BR /&gt;                   INTEGER*4      PTR &lt;BR /&gt;                   INTEGER*4      BASE &lt;BR /&gt;                   BYTE           FLAG &lt;BR /&gt;                   BYTE           FILE &lt;BR /&gt;                   BYTE           PAD1 &lt;BR /&gt;                   BYTE           PAD2 &lt;BR /&gt;      END STRUCTURE &lt;BR /&gt;      RECORD /IOBUF/ FILE_PTR &lt;BR /&gt; &lt;BR /&gt;      INTEGER*4 INI_INPUT &lt;BR /&gt; &lt;BR /&gt;      STATUS = INI_INPUT(%REF(DATATMP), %REF(TMPSTR), %REF(FILE_PTR),  &lt;BR /&gt;     *          FILE_LEN, %REF(REC_DESCR)) &lt;BR /&gt; &lt;BR /&gt;Any help would be appreciated.</description>
    <pubDate>Thu, 22 Mar 2001 10:01:14 GMT</pubDate>
    <dc:creator>Intel_C_Intel</dc:creator>
    <dc:date>2001-03-22T10:01:14Z</dc:date>
    <item>
      <title>Passing C FILE * back to FORTRAN and back to C</title>
      <link>https://community.intel.com/t5/Software-Archive/Passing-C-FILE-back-to-FORTRAN-and-back-to-C/m-p/943511#M17652</link>
      <description>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.  &lt;BR /&gt; &lt;BR /&gt;According to stdio.h: &lt;BR /&gt; &lt;BR /&gt;struct _iobuf  &lt;BR /&gt;{ &lt;BR /&gt;        int            _cnt; &lt;BR /&gt;        char          *_ptr; &lt;BR /&gt;        char          *_base; &lt;BR /&gt;        unsigned char  _flag; &lt;BR /&gt; &lt;BR /&gt;#if __CRTL_VER &amp;gt;= 70000000 &lt;BR /&gt; &lt;BR /&gt;        unsigned char  _padfile;   &lt;BR /&gt;        unsigned char  _pad1; &lt;BR /&gt;        unsigned char  _pad2; &lt;BR /&gt;        int            _file; &lt;BR /&gt;#else &lt;BR /&gt;        unsigned char  _file;   &lt;BR /&gt;        unsigned char  _pad1; &lt;BR /&gt;        unsigned char  _pad2; &lt;BR /&gt;#endif &lt;BR /&gt;}; &lt;BR /&gt; &lt;BR /&gt;#ifndef __FILE_T &lt;BR /&gt;#   define __FILE_T &lt;BR /&gt;typedef struct _iobuf *FILE; &lt;BR /&gt;#endif &lt;BR /&gt; &lt;BR /&gt;An include file for the C routines has  &lt;BR /&gt; &lt;BR /&gt;struct dict { &lt;BR /&gt;    char name[MAXFLDNAMEBUF]; &lt;BR /&gt;    char data_type; &lt;BR /&gt;    short start; &lt;BR /&gt;    short end; &lt;BR /&gt;    short width; &lt;BR /&gt;    short decimals; &lt;BR /&gt;}; &lt;BR /&gt; &lt;BR /&gt;int ini_input(char *data_input_file, char *dictionary_file,  &lt;BR /&gt;	FILE *Data_fp, int *Inrecl, struct dict fld[MAXFLDS]); &lt;BR /&gt;int getdata(void *dictionary_structure_record, FILE *Data_fp,  &lt;BR /&gt;	int *Inrecl, struct dict fld[MAXFLDS]); &lt;BR /&gt; &lt;BR /&gt;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. &lt;BR /&gt; &lt;BR /&gt;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: &lt;BR /&gt; &lt;BR /&gt;      STRUCTURE    /IOBUF/ &lt;BR /&gt;                   INTEGER*4      CNT &lt;BR /&gt;                   INTEGER*4      PTR &lt;BR /&gt;                   INTEGER*4      BASE &lt;BR /&gt;                   BYTE           FLAG &lt;BR /&gt;                   BYTE           FILE &lt;BR /&gt;                   BYTE           PAD1 &lt;BR /&gt;                   BYTE           PAD2 &lt;BR /&gt;      END STRUCTURE &lt;BR /&gt;      RECORD /IOBUF/ FILE_PTR &lt;BR /&gt; &lt;BR /&gt;      INTEGER*4 INI_INPUT &lt;BR /&gt; &lt;BR /&gt;      STATUS = INI_INPUT(%REF(DATATMP), %REF(TMPSTR), %REF(FILE_PTR),  &lt;BR /&gt;     *          FILE_LEN, %REF(REC_DESCR)) &lt;BR /&gt; &lt;BR /&gt;Any help would be appreciated.</description>
      <pubDate>Thu, 22 Mar 2001 10:01:14 GMT</pubDate>
      <guid>https://community.intel.com/t5/Software-Archive/Passing-C-FILE-back-to-FORTRAN-and-back-to-C/m-p/943511#M17652</guid>
      <dc:creator>Intel_C_Intel</dc:creator>
      <dc:date>2001-03-22T10:01:14Z</dc:date>
    </item>
  </channel>
</rss>

