C***********************************************************************
C     mcfclo
C***********************************************************************
C
      subroutine mcfclo(NUNIT, FSTAT)
C
C     Subroutine to close a file given the unit number and the status. 
C     If an error occurs when a file is being closed this subprogram
C     will print an error message to FORTRAN unit fu6 and stop.
C     This is a modified version of routine ficlse in Polyrate. Modification
C     consists in changing the include file from param to mcparm.
C     (Titus V Albu January 2002)
C
      IMPLICIT DOUBLE PRECISION (A-H,O-Z)
C
      include 'mcparm.inc'
C
      CHARACTER*20 FSTAT
C
C     Check the value of FSTAT, FSTAT can only be KEEP or DELETE.  If 
C     FSTAT does not have one of these two values, reset to KEEP.
C
      IF (FSTAT .NE. 'KEEP') THEN
         IF (FSTAT .NE. 'DELETE') FSTAT = 'KEEP'
      ENDIF
C
      CLOSE (UNIT=NUNIT, STATUS=FSTAT, ERR=100) 
C
      RETURN
C
100   WRITE (FU6, 1000) NUNIT
1000  FORMAT(/,2X,T5,'Error occurred while closing the file',
     *                  'linked to FORTRAN unit ',I2)
      STOP 'mcfclo 1'
      END
C***********************************************************************
C     mcfope
C***********************************************************************
C
      subroutine mcfope(NUNIT, FISTAT, FINAME, LEXIT)
C
C     Subroutine to open a file given the unit number, the status, 
C     and the filename. 
C     If an error occurrs upon opening a file the logical variable LEXIT
C     is set TRUE.
C     This is a modified version of routine openfi in Polyrate. Modification
C     consists in changing the include file from param to mcparm.
C     (Titus V Albu January 2002)
C
      IMPLICIT DOUBLE PRECISION (A-H,O-Z)
C
      INCLUDE 'mcparm.inc'
C
      CHARACTER*256 FINAME
      CHARACTER*7  FISTAT
      LOGICAL LEXIT
C
      IF (INDEX(FISTAT,'NEW') .NE. 0) THEN
        OPEN(UNIT=NUNIT,FILE=FINAME,STATUS='NEW',FORM='FORMATTED',
     *        ERR=100)
      ELSEIF (INDEX(FISTAT,'OLD') .NE. 0) THEN
        OPEN(UNIT=NUNIT,FILE=FINAME,STATUS='OLD',FORM='FORMATTED',
     *        ERR=100)
      ELSE
        OPEN(UNIT=NUNIT,FILE=FINAME,STATUS='UNKNOWN',FORM='FORMATTED',
     *        ERR=100)
      ENDIF
C
      RETURN
C
100   LEXIT = .TRUE.
      WRITE (FU6, 1000) FINAME, NUNIT
C
      RETURN
C     
1000  FORMAT (/,2X,'Error opening the file ', A10,
     1        ' which is linked to FORTRAN unit ',I3)
C
      END
