HP Fortran for OpenVMS
User Manual


Previous Contents Index

7.3.2 Using the IOSTAT Specifier

You can use the IOSTAT specifier to continue program execution after an I/O error and to return information about I/O operations. It can supplement or replace the END, EOR, and ERR transfers. Execution of an I/O statement containing the IOSTAT specifier suppresses printing of an error message and causes the specified integer variable, array element, or scalar field reference to be defined as one of the following:

Following execution of the I/O statement and assignment of an IOSTAT value, control transfers to the END, EOR, or ERR statement label, if any. If there is no control transfer, normal execution continues.

Your program can include the $FORIOSDEF library module from the FORSYSDEF library (automatically searched during compilation) to obtain symbolic definitions for the values of IOSTAT.

The values of the IOSTAT symbols from the $FORIOSDEF library module are not the same as the values of the Fortran condition symbols from the $FORDEF library module.

The symbolic names in the $FORIOSDEF library module have a form similar to the Fortran condition symbols:
Fortran Condition Symbol ($FORDEF) IOSTAT Symbolic Name ($FORIOSDEF)
FOR$_mnemonic FOR$IOS_mnemonic

Example 7-1 uses the ERR and IOSTAT specifiers to handle an OPEN statement error (in the FILE specifier). Condition symbols are included from the $FORIOSDEF library module (in FORSYSDEF).

Example 7-1 Handling OPEN Statement File Name Errors

     CHARACTER(LEN=40) :: FILNM      ! Typed file specification 
     INCLUDE '($FORIOSDEF)'          ! Include condition symbol definitions 
 
     DO I=1,4                        ! Allow four tries 
       FILNM = '' 
       WRITE (6,*)  'Type file name ' 
       READ (5,*) FILNM 
       OPEN (UNIT=1, FILE=FILNM, STATUS='OLD', IOSTAT=IERR, ERR=100) 
       WRITE (6,*) 'Opening file: ', FILNM 
        . 
        .   ! Process records 
        . 
 
       CLOSE (UNIT=1) 
       STOP 
 
 100   IF (IERR .EQ. FOR$IOS_FILNOTFOU) THEN 
         WRITE (6,*) 'File: ', FILNM, ' does not exist ' 
       ELSE IF (IERR .EQ. FOR$IOS_FILNAMSPE) THEN 
          WRITE (6,*) 'File: ', FILNM, ' was bad, enter new file name' 
       ELSE 
         PRINT *, 'Unrecoverable error, code =', IERR 
         STOP 
       END IF 
     END DO 
 
! After four attempts or a Ctrl/Z on the READ statement, allow program restart 
 
     WRITE (6,*) 'File not found. Type DIRECTORY to find file and run again' 
   END PROGRAM 

For More Information:

7.4 List of Run-Time Messages

Table 7-1 lists the Fortran-specific errors processed by the HP Fortran RTL. For each error, the table shows the Fortran-specific message mnemonic (follows either FOR$_ or FOR$IOS_ for condition symbols), the Fortran-specific message number, the severity (fatal, error, or informational), the message text. For more detailed descriptions of errors processed by the HP Fortran RTL, see Table C-1.

Table 7-1 Summary of Run-Time Errors
Mnemonic Number1 Severity Message Text
NOTFORSPE 2 1 F not a Fortran-specific error
BUG_CHECK 8 F internal consistency check failure
SYNERRNAM 17 F syntax error in NAMELIST input
TOOMANVAL 18 F too many values for NAMELIST variable
INVREFVAR 19 F invalid reference to variable in NAMELIST input
REWERR 20 F REWIND error
DUPFILSPE 21 F duplicate file specifications
INPRECTOO 22 F input record too long
BACERR 23 F BACKSPACE error
ENDDURREA 24 F end-of-file during read
RECNUMOUT 25 F record number outside range
OPEDEFREQ 26 F OPEN or DEFINE FILE required
TOOMANREC 27 F too many records in I/O statement
CLOERR 28 F CLOSE error
FILNOTFOU 29 F file not found
OPEFAI 30 F open failure
MIXFILACC 31 F mixed file access modes
INVLOGUNI 32 F invalid logical unit number
ENDFILERR 33 F ENDFILE error
UNIALROPE 34 F unit already open
SEGRECFOR 35 F segmented record format error
ATTACCNON 36 F attempt to access non-existent record
INCRECLEN 37 F inconsistent record length
ERRDURWRI 38 F error during write
ERRDURREA 39 F error during read
RECIO_OPE 40 F recursive I/O operation
INSVIRMEM 41 F insufficient virtual memory
NO_SUCDEV 42 F no such device
FILNAMSPE 43 F file name specification error
INCRECTYP 44 F inconsistent record type
KEYVALERR 45 F keyword value error in OPEN statement
INCOPECLO 46 F inconsistent OPEN/CLOSE parameters
WRIREAFIL 47 F write to READONLY file
INVARGFOR 48 F invalid argument to Fortran Run-Time Library
INVKEYSPE 49 F invalid key specification
INCKEYCHG 50 F inconsistent key change or duplicate key
INCFILORG 51 F inconsistent file organization
SPERECLOC 52 F specified record locked
NO_CURREC 53 F no current record
REWRITERR 54 F REWRITE error
DELERR 55 F DELETE error
UNLERR 56 F UNLOCK error
FINERR 57 F FIND error
FMYSYN 58 I format syntax error at or near xxx
LISIO_SYN 3 59 F list-directed I/O syntax error
INFFORLOO 60 F infinite format loop
FORVARMIS 3 61 F or I 4 format/variable-type mismatch
SYNERRFOR 62 F syntax error in format
OUTCONERR 3,4 63 E or I 4 output conversion error
INPCONERR 3 64 F input conversion error
FLTINV 65 E floating invalid
OUTSTAOVE 66 F output statement overflows record
INPSTAREQ 67 F input statement requires too much data
VFEVALERR 3 68 F variable format expression value error
INTOVF 70 F integer overflow
INTDIV 71 F integer divide by zero
FLTOVF 72 E floating overflow
FLTDIV 73 E floating divide by zero
FLTUND 74 E floating underflow
SUBRNG 77 F subscript out of range
WRONUMARG 80 F wrong number of arguments
INVARGMAT 81 F invalid argument to math library
UNDEXP 5 82 F undefined exponentiation
LOGZERNEG 5 83 F logarithm of zero or negative value
SQUROONEG 5 84 F square root of negative value
SIGLOSMAT 5 87 F significance lost in math library
FLOOVEMAT 5 88 F floating overflow in math library
FLOUNDMAT 89 E floating underflow in math library
ADJARRDIM 6 93 F adjustable array dimension error
INVMATKEY 94 F invalid key match specifier for key direction
FLOCONFAI 95 E floating point conversion failed
FLTINE 140 E floating inexact
ROPRAND 144 F reserved operand
ASSERTERR 145 F assertion error
NULPTRERR 146 F null pointer error
STKOVF 147 F stack overflow
STRLENERR 148 F string length error
SUBSTRERR 149 F substring error
RANGEERR 150 F range error
INVREALLOC 151 F allocatable array is already allocated
RESACQFAI 152 F unresolved contention for HP Fortran RTL global resource
INVDEALLOC 153 F allocatable array is not allocated
INVDEALLOC2 173 F A pointer passed to DEALLOCATE points to an array that cannot be deallocated
SHORTDATEARG 175 F DATE argument to DATE_AND_TIME is too short (LEN=n), required LEN=8
SHORTTIMEARG 176 F TIME argument to DATE_AND_TIME is too short (LEN=n), required LEN=10
SHORTZONEARG 177 F ZONE argument to DATE_AND_TIME is too short (LEN=n), required LEN=5
DIV 178 F divide by zero
ARRSIZEOVF 179 F cannot allocate array --- overflow on array size calculation
UNFIO_FMT 256 F unformatted I/O to unit open for formatted transfers
FMTIO_UNF 257 F formatted I/O to unit open for unformatted transfers
DIRIO_KEY 258 F direct-access I/O to unit open for keyed access
SEQIO_DIR 259 F sequential-access I/O to unit open for direct access
KEYIO_DIR 260 F keyed-access I/O to unit open for direct access
OPERREQDIS 264 F operation requires file to be on disk or tape
OPEREQSEQ 265 F operation requires sequential file organization and access
ENDRECDUR 268 F end of record during read
FLOINEEXC 296 I nn floating inexact traps
FLOINCEXC 297 I nn floating invalid traps
FLOOVREXC 298 I nn floating overflow traps
FLODIV0EXC 299 I nn divide-by-zero traps
FLOUNDEXC 300 I nn floating underflow traps


1Although most error numbers are returned as IOSTAT values, the following are not: 1, 24 (END specifier), 41, 58, 70--75, 77, 80-89, 95, 140--150, 151, 153, 173, 175--177, 179, 266, 268 (EOR specifier), 297, 298, 299, 300. You can use condition symbols (FOR$_mnemonic or FOR$IOS_mnemonic) to obtain the number (see Section 7.3.2). Some of these error numbers are returned as STAT= values in either the ALLOCATE (41, 151, 179) or DEALLOCATE (41, 153, 173) Fortran statement.
2The FOR$_NOTFORSPE error (number 1) indicates an error not reportable through any other message. If you call ERRSNS, an error of this kind returns a value of 1. Use the fifth argument of the call to ERRSNS (condval) to obtain the unique system condition value that identifies the error.
3For error numbers 59, 61, 63, 64, and 68, the ERR transfer is taken after completion of the I/O statement. The resulting file status and record position are the same as if no error had occurred. Other I/O errors take the ERR transfer as soon as the error is detected, and file status and record position are undefined.
4For errors 61 and 63, the severity depends on the /CHECK keywords in effect during compilation (see Section 2.3.11). If no ERR address is defined for error number 63, the program continues and the entire overflowed field is filled with asterisks to indicate the error in the output record.
5Function return values for error numbers 82, 83, 84, 87, 88, and 89 can be modified by means of user-written condition handlers. (See Chapter 14 for information about user-written condition handlers.)
6If error number 93 (FOR$_ADJARRDIM) occurs and a user-written condition handler causes execution to continue, any reference to the array in question may cause an access violation.

The message mnemonic shown in the first column is part of the condition status code symbols signaled by the HP Fortran RTL I/O support routines. You can define these symbolic values in your program by including the library module $FORDEF or $FORIOSDEF from the system-supplied default library FORSYSDEF.TLB:

If you will be using the IOSTAT specifier for error handling, you should include the $FORIOSDEF library module (instead of $FORDEF) from the FORSYSDEF.TLB library (see Section 7.3.2).

The standard HP Fortran error numbers that are generally compatible with other versions of HP Fortran are shown in the second column. Most of these error values are returned to IOSTAT variables when an I/O error is detected.

The codes in the third column indicate the severity of the error conditions (see Section 7.2.2).

For more detailed descriptions of errors processed by the HP Fortran RTL, see Table C-1 or type the following DCL command to obtain a list of mnemonics (such as ADJARRDIM):


$ HELP FORTRAN ERROR RUN_TIME

For More Information:


Previous Next Contents Index