### 4 I/O and error handling

The terminal I/O and error handling have been reviewed. Since Starlink applications will often run under some environment which results in them being detached from standard Fortran units, these areas have to be addressed and made compliant with Starlink methods of message and error handling.

A few of the FFT routines (not the actual FFTPACK routines) have a status argument. It is returned as zero if all went well, and as one if an error occurred.

The DIERCKX/NETLIB routines appear not to make terminal output. Error handling takes the form of returning to the caller with a diagnostic argument set to the appropriate value. These routines therefore have not been changed.

The MINPACK/NETLIB and OPT/NETLIB routines seem to behave similarly. Again no change was made to these routines. It may, however, be necessary for the calling routine to choose argument values such that printing of messages is suppressed.

There was a STOP statement in PDA_RMARIN. This would be executed if either of the two seeds for initialisation of the random number generator were out of range. These seeds are passed by the user to the routine PDA_SA. Instead of printing a message and stopping the program, PDA_SA will now return STATUS equal to 1. STATUS should be given as zero.

The NMS/TIBER routine PDA_UNCMND was changed so that it does not call PDA_XERROR any more. It would have used this to issue warning and error messages. It also returns a diagnostic argument with the same information, so that now it is up to the caller to check and interpret that value. There remain two STOP statements in the PDA_UNCMND algorithm, in routines PDA_D1FCND and PDA_D2FCND. These are dummy routines and never actually called.

The surface fitting routines PDA_DB2INK and PDA_DB2VAL call a routine PDA_DBVAL2. Originally, PDA_DBVAL2 called XERROR when a problem was encountered. These calls have been commented out. The routine now sets variable IFAIL appropriately instead. On exit from PDA_DB2INK and PDA_DB2INK, STATUS is set to 1 if the IFAIL value indicated that a serious fault had occurred. STATUS must have the value 0 when the routines are called.

The surface fitting routines PDA_IDBVIP and PDA_IDSFFT, together with their support routines, have been modified to ensure that STATUS is set to 1 if the internal error status variable ISTAT indicates that a problem was encountered.

The major work in adapting the library to Starlink error reporting is to do with the SLATEC/CAMSUN routines. These routines also form the major part of the library. The SLATEC error handling procedure would be to call PDA_XERMSG. Depending on the severity level passed to this routine and depending on the error report control flag in a global variable, PDA_XERMSG might or might not print messages, and it might or might not execute a Fortran STOP statement.

PDA_XERMSG has been re-written. It now has an additional integer argument in which it returns the a status value of 1. It will also call EMS_REP with a message constructed from the library name, routine name, and message text passed to PDA_XERMSG. PDA_XERMSG will not execute any STOP statement, but always return control to the caller. Since level-2 errors were always considered fatal, routines calling PDA_XERMSG may need to be changed to cope with regaining control after level-2 errors.

Routines calling PDA_XERMSG had to be changed to accommodate the extra returned argument. They also have to pass that status argument back up to their caller. And they must actually return control to their caller before running into exceptions that might crash the program.