FSEEK — Low level file positioning subroutine#

FSEEK(UNIT, OFFSET, WHENCE, STATUS)#

Moves UNIT to the specified OFFSET. If WHENCE is set to 0, the OFFSET is taken as an absolute value SEEK_SET, if set to 1, OFFSET is taken to be relative to the current position SEEK_CUR, and if set to 2 relative to the end of the file SEEK_END. On error, STATUS is set to a nonzero value. If STATUS the seek fails silently.

Parameters:
  • UNIT – Shall be a scalar of type INTEGER.

  • OFFSET – Shall be a scalar of type INTEGER.

  • WHENCE – Shall be a scalar of type INTEGER. Its value shall be either 0, 1 or 2.

  • STATUS – (Optional) shall be a scalar of type INTEGER(4).

Standard:

GNU extension

Class:

Subroutine

Syntax:
CALL FSEEK(UNIT, OFFSET, WHENCE[, STATUS])
Example:
PROGRAM test_fseek
  INTEGER, PARAMETER :: SEEK_SET = 0, SEEK_CUR = 1, SEEK_END = 2
  INTEGER :: fd, offset, ierr

  ierr   = 0
  offset = 5
  fd     = 10

  OPEN(UNIT=fd, FILE="fseek.test")
  CALL FSEEK(fd, offset, SEEK_SET, ierr)  ! move to OFFSET
  print *, FTELL(fd), ierr

  CALL FSEEK(fd, 0, SEEK_END, ierr)       ! move to end
  print *, FTELL(fd), ierr

  CALL FSEEK(fd, 0, SEEK_SET, ierr)       ! move to beginning
  print *, FTELL(fd), ierr

  CLOSE(UNIT=fd)
END PROGRAM
See also:

FTELL — Current stream position