      SUBROUTINE FILE(MAMP,IOUT,MX,MXT2)
C
C     THIS SUBROUTINE OPENS THE SCRATCH AND OUTPUT FILES GENERATED BY 
C     COUPLE 
C 
C     RECL=16*MX*MX IS NEEDED TO WRITE A MX*MX COMPLEX MATRIX 
C     (2*MX*MX 8 BYTE (64 BIT) WORDS) ON UNIT 1,2,3 AND 8
C
      IMPLICIT REAL*8 (A-H,O-Z)
c
c     Increase maximum number of files to 30 in SVS Fortran
c
cc      integer i, numfiles, _init_handle_count
cc      numfiles=30
cc      i = _init_handle_count(%VAL(numfiles))
cc      print*,'i,numfiles= ',i,numfiles
c
C
CCC      NRECL=16*MX*MX
CCC      OPEN(1,STATUS='SCRATCH',RECL=NRECL,FORM='UNFORMATTED')
CCC      OPEN(2,STATUS='SCRATCH',RECL=NRECL,FORM='UNFORMATTED')
CCC      OPEN(3,STATUS='SCRATCH',RECL=NRECL,FORM='UNFORMATTED')
CCC      OPEN(8,STATUS='SCRATCH',RECL=NRECL,FORM='UNFORMATTED')
C
      OPEN(21,STATUS='SCRATCH',FORM='UNFORMATTED',IOSTAT=I21)
      OPEN(2,STATUS='SCRATCH',FORM='UNFORMATTED',IOSTAT=I2)
      OPEN(3,STATUS='SCRATCH',FORM='UNFORMATTED',IOSTAT=I3)
      OPEN(8,STATUS='SCRATCH',FORM='UNFORMATTED',IOSTAT=I8)
C
C     OPEN DIRECT ACCESS FILE FOR STORAGE OR RETRIEVAL OF
C     EIGENVALUES WITH IREIG .NE. 0
C
      IRECL=16*MX
      OPEN(18,STATUS='SCRATCH',FORM='UNFORMATTED',ACCESS='DIRECT',
     1        RECL=IRECL,IOSTAT=I18)
C
CCC      NRECL=16*MXT2*MXT2
CCC      OPEN(4,STATUS='SCRATCH',RECL=NRECL,FORM='UNFORMATTED')
C
      OPEN(4,STATUS='SCRATCH',FORM='UNFORMATTED',IOSTAT=I4)
C
      OPEN(10,FILE='COUPLE.TL',FORM='FORMATTED',IOSTAT=I10)
      IF(MAMP .GT. 0) OPEN(11,FILE='COUPLE.AMP',FORM='FORMATTED')
      OPEN(7 ,FILE='COUPLE.CPR',FORM='UNFORMATTED',IOSTAT=I7)
C
      IF(IOUT .NE. 1) THEN 
      OPEN(12,FILE='COUPLEO.TL',FORM='FORMATTED',IOSTAT=I12)
      OPEN(13,FILE='COUPLEI.TL',FORM='FORMATTED',IOSTAT=I13)
      OPEN(17,FILE='COUPLES.TL',FORM='FORMATTED',IOSTAT=I17)
C
      OPEN(14,FILE='COUPLEO.CPR',FORM='UNFORMATTED',IOSTAT=I14)
      OPEN(15,FILE='COUPLEI.CPR',FORM='UNFORMATTED',IOSTAT=I15)
      OPEN(16,FILE='COUPLES.CPR',FORM='UNFORMATTED',IOSTAT=I16)
      END IF
C
      RETURN
      END
