      SUBROUTINE OPESUM(FNAME,NEWFIL,IFAIL)                             OPES001
C-----------------------------------------------------------------------OPES002
C                                                                       OPES003
C  SUBROUTINE OPESUM  -  Open the summary file, reading through to the  OPES004
C                        end if the file already exists                 OPES005
C                                                                       OPES006
C----------------------------------------------------------------------+OPES007
                                                                        OPES008
      CHARACTER*80   IREC                                               OPES009
      CHARACTER*(*)  FNAME                                              OPES010
      LOGICAL        IFAIL, NEWFIL                                      OPES011
                                                                        OPES012
C---- Initialise variables                                              OPES013
      IFAIL = .FALSE.                                                   OPES014
                                                                        OPES015
C---- Open the summary file                                             OPES016
      OPEN(UNIT=14,FILE=FNAME,STATUS='UNKNOWN',ACCESS='SEQUENTIAL',     OPES017
CVAX     -    CARRIAGECONTROL='LIST',                                   OPES018
     &    ERR=900)                                                      OPES019
                                                                        OPES020
C---- If this is an existing file, then read through all its records untOPES021
C     get to the end of file                                            OPES022
      IF (.NOT.NEWFIL) THEN                                             OPES023
C----     Loop through the file until reach the end                     OPES025
 100      CONTINUE                                                      OPES026
             READ(14,110,END=500) IREC                                  OPES027
 110         FORMAT(A)                                                  OPES028
          GO TO 100                                                     OPES029
                                                                        OPES030
C---- If this is a new file, then write the header records to it        OPES031
      ELSE                                                              OPES032
          WRITE(14,120)                                                 OPES033
 120      FORMAT(/,                                                     OPES034
     &        ' +----------<<<  P  R  O  C  H  E  C  K     S  U  M ',   OPES035
     &        ' M  A  R  Y  >>>----------+',/,                          OPES036
     &           ' |                                                  ',OPES037
     &        '                          |')                            OPES038
      ENDIF                                                             OPES039
                                                                        OPES040
C---- End of file reached                                               OPES041
 500  CONTINUE                                                          OPES042
      GO TO 999                                                         OPES044
                                                                        OPES045
 900  CONTINUE                                                          OPES046
      PRINT*, '*** ERROR opening summary file'                          OPES047
      PRINT*, '* ', FNAME                                               OPES048
      GO TO 990                                                         OPES049
                                                                        OPES050
 990  CONTINUE                                                          OPES051
      IFAIL = .TRUE.                                                    OPES052
      GO TO 999                                                         OPES053
                                                                        OPES054
 999  CONTINUE                                                          OPES055
      RETURN                                                            OPES056
      END                                                               OPES057
