
C THIS SUBROUTINE DETERMINES THE INFORMATION ABOUT THE
C LOCATION OF TEH VARIOUS FILES (DEFAULT IS OF COURSE
C THE WORKING DIRECTORY) IN AN ACES2 RUN. THIS OPTION 
C IS PARTICULARLY USEFUL FOR WORKSTATIONS, BUT HAS 
C ALSO SOME BENEFITS ON SUPER COMPUTERS WITH TMPDIR
C DISKS.
C
C IF A FILE IS INTENDED NOT TO BE IN THE WORKING 
C DIRECTORY, THE FULL PATH NAME CAN BE GIVEN IN THE
C FOLLOWING WAY IN THE ZMAT_FILE PRIOR TO THE TITLE
C CARD
C
C  %MOINTS=/work/username/test1/MOINTS
C
C WHICH MEANS THAT MOINTS IS NOW IN THE DIRECTORY
C /work/username/test1. THERE IS ALSO THE POSSIBILITY
C TO RENAME FILES BUT THAT SHOULD BE USED WITH
C COME CAUTION, IN ORDER NOT TO MESS UP THINGS.
C
C JG GOETEBORG SEPT/92

      SUBROUTINE DFILES
      IMPLICIT INTEGER(A-Z)

#include "io_units.par"
#include "linelen.par"

      LOGICAL YESNO,IGNORE
      CHARACTER*(linelen) A
      COMMON/RESTART/IGNORE
C
      IGNORE=.TRUE.
C
C CHECK WHETHER FILE 'FILES EXIST, IF, THEN THERE IS NOTHING TO DO
C
      INQUIRE(FILE='FILES',EXIST=YESNO)
      IF(YESNO) RETURN 
C
      IGNORE=.FALSE.
C
C FIRST OPEN THE ZMAT FILE WHICH IS ALWAYS COPIED
C TO THE WORKING DIRECTORY
C
C  LUZ: UNIT NUMBER FOR ZMAT FILE
C
      OPEN(UNIT=90,FILE='FILES',FORM='FORMATTED',
     &     STATUS='UNKNOWN')
      REWIND(UNIT=90)
C
      INQUIRE(FILE=ZFIL,EXIST=YESNO)
      IF (.NOT.YESNO) THEN
         WRITE(LUOUT,*) '@DFILES: ZMAT file not present.'
         CALL ERREX
      ELSE
         OPEN(UNIT=LUZ,FILE=ZFIL,FORM='FORMATTED',STATUS='OLD')
         REWIND(LUZ)
      END IF
C
C REENTRY POINT FOR NEXT CARD
C
1000  CONTINUE
C
C READ FIRST CARD AS CHARACTER STRING, AT MOST 80 CHARACTERS
C
       READ(4,9001) A
9001   FORMAT(A80)
C
C CHECK IF FIRST CHARACTER IS A % SIGN, INDICATING FILE INFORMATION
C
       IF(A(1:1).EQ.'%') THEN
C
        DO 10 I=2,80
         IF(A(I:I).NE.' ') THEN
          ISTART1=I
          GO TO 11
         ENDIF
10      CONTINUE
11      CONTINUE
        DO 20 I=ISTART1,80
         IF(A(I:I).EQ.'=') THEN
          IEND1=I-1
          GO TO 21
         ENDIF
20      CONTINUE
21      CONTINUE
        ISTART2=IEND1+2
        DO 30 I=ISTART2,80
         IF(A(I:I).EQ.' ') THEN
          IEND2=I-1
          GO TO 31
         ENDIF
30     CONTINUE
31     CONTINUE
C
        WRITE(90,9002) A(ISTART1:IEND1), A(ISTART2:IEND2)
9002    FORMAT(A,1X,A)
        WRITE(6,9003) A(ISTART1:IEND1), A(ISTART2:IEND2)
9003    FORMAT('File ',A,' is ',A,'.')
        GO TO 1000
C
       ENDIF
C
C EVERYTHING DONE, CLOSE ZMAT-FILE
C
       CLOSE(UNIT=LUZ)
       WRITE(90,*)
       CLOSE(UNIT=90)
C
       WRITE(6,*)
C 
       RETURN
       END
