NCEP CCS Conversion Guide
Issues Converting FORTRAN and C/C++ Programs
Back to Main Page
Topic: Using STAT function from FORTRAN
Posted by: Stephen Gilbert
Updated by
Post Date: 08/14/2002
Last Updated: 
Problem:  Some FORTRAN programs use the "C" function STAT to get information about a file such as size, mod time, etc...  The STAT function sets these values in a "struct stat" structure, and for Fortran users, this structure is referenced by an integer array from the calling program.  When using 64 bit addressing (which is the default on gort), some of the elements of the stat structure have a size of 8 bytes instead of 4 bytes, so some values will be in different elements of the output integer array.

Solution: 
For file size in bytes:
     This is returned in integer*4 array element 8 if using 32 bit addressing, but returned in element 11, if using 64 bit addressing.

Caveats:  I haven't mapped out all of the possible values returned.  I only checked file size, since that is all I have seen being used so far.

Example:
 
32-bit addressing (-q32)
-----------------------------
integer(4) STAT,JSTAT(20)
integer istat,filesize 
CHARACTER NFILE*80

nfile="filename"//char(0)

istat=STAT(NFILE,JSTAT)
filesize=JSTAT(8)  

64-bit addressing (-q64)
-----------------
integer(4) STAT,JSTAT(20)
integer istat,filesize
CHARACTER NFILE*80

nfile="filename"//char(0)

istat=STAT(NFILE,JSTAT)
filesize=JSTAT(11)

 

Back to Main Page