Fortran Library Reference

ftell: Return Current Position of File

The function is called by:

INTEGER*4 ftell

n = ftell( lunit )

lunit

INTEGER*4

Input  

Open logical unit  

Return value 

INTEGER*4

or

INTEGER*8

Output  

n>=0: n=Offset in bytes from start of file

n<0: n=System error code

An INTEGER*8 offset value is returned when compiling for a 64-bit environment, such as Solaris 7, with -xarch=v9. ftell and variables receiving this return value should be declared INTEGER*8.

Example: ftell():


    INTEGER*4 ftell, lunit/1/, n
    open( UNIT=lunit, FILE='MyFile' )
    ... 
    n = ftell( lunit )
    if ( n .lt. 0 ) stop 'ftell error'
    ...

Example: Same example in a 64-bit environment and compiled with -xarch=v9:


    INTEGER*4 lunit/1/
    INTEGER*8 ftell, n
    open( UNIT=lunit, FILE='MyFile' )
    ... 
    n = ftell( lunit )
    if ( n .lt. 0 ) stop 'ftell error'
    ...

See also fseek(3S) and perror(3F); also fseeko64(3F) ftello64(3F).