irtn = c_read( getfilep( unitn ), inbyte, 1 ) |
|||
c_read |
C function |
Input |
User’s own C function. See example. |
unitn |
INTEGER*4 |
Input |
External unit number. |
getfilep |
INTEGER*4 or INTEGER*8 |
Return value |
File pointer if the file is connected; -1 if the file is not connected.An INTEGER*8 value is returned when compiling for 64-bit environments |
This function is used for mixing standard Fortran I/O with C I/O. Such a mix is nonportable, and is not guaranteed for subsequent releases of the operating system or Fortran. Use of this function is not recommended, and no direct interface is provided. You must create your own C routine to use the value returned by getfilep. A sample C routine is shown below.
Example: Fortran uses getfilep by passing it to a C function:
demo% cat tgetfilepF.f character*1 inbyte integer*4 c_read, getfilep, unitn / 5 / external getfilep write(*,’(a,$)’) ’What is the digit? ’ irtn = c_read( getfilep( unitn ), inbyte, 1 ) write(*,9) inbyte 9 format(’The digit read by C is ’, a ) end |
Sample C function actually using getfilep:
demo% cat tgetfilepC.c #include <stdio.h> int c_read_ ( fd, buf, nbytes, buf_len ) FILE **fd ; char *buf ; int *nbytes, buf_len ; { return fread( buf, 1, *nbytes, *fd ) ; } |
A sample compile-build-run is:
demo% cc -c tgetfilepC.c demo% f95 tgetfilepC.o tgetfilepF.f demo% a.out What is the digit? 3 The digit read by C is 3 demo% |
For more information, read the chapter on the C-Fortran interface in the Fortran Programming Guide. See also open(2).