C******************** START FILE URDERR.FOR ; GROUP UREAD5 ******************
C--------------------------------------------------------------
C&  URDERR  PROCESS READ ERROR IN UREAD INDIRECT INPUT FILE
C
C  ERROR ON READ-- CLOSE FILES
C   ITYP=3 CALL: JUST CLOSE FILES, FEW MESSAGES (CALLER DIRECTED
C   ABORT OF INPUT)
C   ITYP=1 CALL:  FILE READ ERROR
C   ITYP=2 CALL:  FILE OPEN ERROR (DETAILS PREVIOUSLY REPORTED)
C
      SUBROUTINE URDERR(ITYP)
      INCLUDE 'USERIO'
C
C  FORMERLY PART OF UREAD SUBROUTINE
C
C  IF ERROR IS CALLED FROM MAIN VIA CALL UREAD('CLOSE$'), RETURN TO MAIN
C  IF ERROR IS DETECTED IN UREAD4 IN INTERACTIVE MODE, RETURN CONTROL
C  TO USER
C  IF IN BATCH MODE, STOP.
      IF(ITYP.EQ.3) THEN
        WRITE(LUNTRM,9501)
 9501 FORMAT(/
     >'  % INDIRECT FILES CLOSED BY CALL UREAD(''CLOSE$'') IN MAIN'/)
      ELSE
C
        IF(ITYP.EQ.1) WRITE(LUNTRM,9005) LUNTIN(NLUNIN)
 9005 FORMAT(' ? READ ERROR ON UNIT ',I3)
C
C=========
C  ERROR DURING INDIRECT READ-- FLUSH INPUT STACK AND RETURN
C  CONTROL TO USER
C
C  INDIRECT INPUT FILE TRACEBACK
        CALL UTRACE
        INUMO=NLUNIO-1
        IF(NLINDO) WRITE(LUNTRM,9503) INUMO
 9503 FORMAT(1X,I2,
     >' OPEN INDIRECT OUTPUT FILE(S) MAY CONTAIN ERROR **')
        CALL UREADY(1)
        IF(IBATCH.EQ.1) THEN
          ILIM=2
          WRITE(LUNTRM,9505)
 9505 FORMAT(' % BATCH MODE: PROGRAM HALTED, SUBR. UREAD'//)
        ELSE
          ILIM=NLUNIO+1
        ENDIF
      ENDIF
C  CLOSE ALL INPUT FILES
      DO 950 JLUN=NLUNIN,ILIM,-1
        CLOSE(UNIT=LUNTIN(JLUN))
 950  CONTINUE
C
      NLINDI=.FALSE.
      NLUNIN=1
      CALL UCLEAR
      IF((ITYP.EQ.2).OR.(IBATCH.EQ.0)) THEN
CXX	  CALL UPROMR
        RETURN
      ENDIF
C
      CALL URDABO
C
      	END
C******************** END FILE URDERR.FOR ; GROUP UREAD5 ******************
