GETFILEP(3F) — FORTRAN LIBRARY ROUTINES
NAME
getfilep − get the file pointer of an external unit number
DESCRIPTION
getfilep returns the file pointer of an external unit number if the unit is connected.
If the unit is not connected, the value returned is -1.
NOTE
This function is used for mixing standard FORTRAN I/O with C I/O. Such mixing in nonportable, and is not guaranteed for subsequent releases of SunOS or FORTRAN. Use of this function is not recommended, and no direct interface is provided. You must enter your own C routine to use the value returned by getfilep. A sample C routine is shown below.
USAGE
Sample FORTRAN main program with getfilep. This is file MixStdinmain.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. This is file MixStdin.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 ) ;
}
Sample compile/build/run:
demo 11% cc -c MixStdin.c
demo 12% f77 MixStdin.o MixStdinmain.f
MixStdinmain.f:
MAIN:
demo 13% a.out
What is the digit? 3
The digit read by C is 3
demo 14%
See the chapter on the C-FORTRAN interface in the Sun FORTRAN User’s Guide .
FILES
libF77.a
SEE ALSO
Sun Release 4.1 — Last change: 5 November 1990