      SUBROUTINE HYOPEN
C--CALLED BY HYPOINV TO OPEN FILES
      INCLUDE 'common.inc'
C--ISTAT2 IS USED BY HYOPEN TO TELL HYP WHETHER FILES EXIST.

C--OPEN PHASE FILE
      IF (JCP.LT.6) CALL OPENR (14,PHSFIL,'F',IOS)
      IF (IOS.NE.0) THEN
C--HERE IS THE ERROR MESSAGE FOR NON-EXISTENT PHASE FILES
        WRITE (6,1010)
1010    FORMAT (' *** ERROR - PHASE FILE DOES NOT EXIST ***')
        ISTAT2=0
        IRES=-61
        RETURN
      END IF

C--OPEN CUSP-ID FILE
      IF (JCP.EQ.7) CALL OPENR (14,PHSFIL,'F',IOS)
      IF (IOS.NE.0) THEN
C--HERE IS THE ERROR MESSAGE FOR NON-EXISTENT CUSP-ID FILE
        WRITE (6,1011)
1011    FORMAT (' *** ERROR - CUSP-ID FILE DOES NOT EXIST ***')
        ISTAT2=0
        IRES=-62
        RETURN
      END IF
      ISTAT2=1

C--OPEN OUTPUT FILES
      IF (LSUM .AND. LAPP(2)) CALL OPENW (12,SUMFIL,'F',IOS,'A')
      IF (LARC .AND. LAPP(3)) CALL OPENW (7,ARCFIL,'F',IOS,'A')
      IF (LPRT .AND. LAPP(1)) CALL OPENW (15,PRTFIL,'F',IOS,'A')

      IF (LSUM .AND. .NOT.LAPP(2)) CALL OPENW (12,SUMFIL,'F',IOS,'S')
      IF (LARC .AND. .NOT.LAPP(3)) CALL OPENW (7,ARCFIL,'F',IOS,'S')
      IF (LPRT .AND. .NOT.LAPP(1)) CALL OPENW (15,PRTFIL,'F',IOS,'S')

      IF (LMAG) CALL OPENW (16,MAGFIL,'F',IOS,'S')
      RETURN

      END
