C ---------------------------------------------------------------------- INTEGER FUNCTION OPENFILE(sim,io) C ---------------------------------------------------------------------- C - Connects the DYNASMART input files (read from .dyn) to C - the appropriate FORTRAN unit numbers so that data can be read by C - the program C - INCLUDED FILES: #include "dyna.inc" #include "sim.inc" #include "io.inc" C - UNMODIFIED ARGUMENTS: ! NONE C - MODIFIED ARGUMENTS: RECORD /Sim_Data/ sim RECORD /Io_Data/ io C - MODIFIED GLOBAL DATA: ! NONE C - LOCAL VARIABLES: LOGICAL exist,itmp CHARACTER description*120,holdit*139,use*2,date*40,network*80 INTEGER ii,i,numfiles,istart,iter,iend INTEGER LTR C - FUNCTIONS CALLED: ! NONE C - RETURN VALUE: ! Simulation Status C ---------------------------------------------------------------------- ii = 0 IF (LTR(io.netfile).EQ.0) THEN io.netfile = 'dynain.dyn' ENDIF 10 INQUIRE(FILE=io.netfile,EXIST=exist) IF (.NOT.exist) THEN IF (ii.EQ.0) THEN ii = 1 WRITE(io.netfile,'(2A)') io.netfile(1:LTR(io.netfile)) + ,'.dyn' GOTO 10 ENDIF WRITE(ostr,'(3A)') '*** NETWORK FILE ' + ,io.netfile(1:LTR(io.netfile)) + ,' NOT FOUND! ***'//CHAR(0) CALL SIMMSG(STATUS,ostr) WRITE(ostr,'(2A)') + 'Network file not found. Please verify it''s location' + ,CHAR(0) CALL DYNA_ERROR(ostr + ,DYNA_NONFATAL_WARNING + ,DYNA_NO_CONTROL_FILE + ,DYNA_MISSING_INPUT_FILE) sim.status = DYNA_NO_CONTROL_FILE OPENFILE = sim.status RETURN ENDIF IF (io.netfile(LTR(io.netfile)-4:LTR(io.netfile)).EQ.'.dyn') THEN OPEN(999,FILE='last_run') WRITE(999,*) io.netfile(1:LTR(io.netfile)-4) ENDIF C --- Initialize the use_file logical flags for the output files so that C --- files are used unless otherwise specified DO i = 1,1000 io.use_file(i) = .FALSE. ENDDO C ---------------------------------------------------------------------- C - READ THE INPUT AND OUTPUT FILE NAMES FROM THE NETWORK FILE AND C - OPEN THEM FOR USE C - The input and output files are read from the network file by C - continually reading entries of the form: C - unit, flag, filename, description (for output files) C - A pointer array is used to keep track of all open files by C - their unit number. C ---------------------------------------------------------------------- OPEN(1000,FILE=io.netfile) numfiles = 0 DO WHILE(.TRUE.) CALL FND(1000) numfiles = numfiles + 1 DO i = 1,LEN(description) description(i:i) = ' ' ENDDO READ(1000,'(I3,1X,A1,1X,A40,A120)',END=20) + io.filepnt(numfiles) + ,use,io.files(numfiles),description IF (io.filepnt(numfiles).GE.1000 + .OR. + io.filepnt(numfiles).EQ.5 !Stdin unit + .OR. + io.filepnt(numfiles).EQ.6 !Stdout unit + ) THEN WRITE(ostr,'(A,I5,A)') 'ERROR: ILLEGAL FILE UNIT NUMBER:' + ,io.filepnt(numfiles),CHAR(0) CALL DYNA_ERROR(ostr + ,DYNA_FATAL_ERROR + ,DYNA_INPUT_ERROR + ,DYNA_ILLEGAL_UNIT_NUMBER) openfile = 1 RETURN ENDIF itmp = .TRUE. IF (use(1:1).EQ.'F'.OR.use(1:1).EQ.'f') itmp = .FALSE. io.use_file(io.filepnt(numfiles)) = itmp IF (LTR(io.files(numfiles)).LE.0) THEN numfiles = numfiles - 1 GOTO 911 ENDIF IF (io.use_file(io.filepnt(numfiles))) THEN IF (use.EQ.'I'.OR.use.EQ.'i') THEN INQUIRE(FILE=io.files(numfiles),EXIST=exist) IF (.NOT.exist) THEN WRITE(ostr,'(3A)') 'Could not locate input file: ' + ,io.files(numfiles)(1:LTR(io.files(numfiles))) + ,CHAR(0) CALL DYNA_ERROR(ostr + ,DYNA_FATAL_ERROR + ,DYNA_INPUT_ERROR + ,DYNA_MISSING_INPUT_FILE) ENDIF ENDIF OPEN(io.filepnt(numfiles),file=io.files(numfiles) + (1:LTR(io.files(numfiles)))) ELSE GOTO 911 ENDIF IF (use.NE.'I'.AND.use.NE.'i') THEN !IF NOT AN INPUT FILE, WRITE OUTPUT TAG CALL FDATE(date) WRITE(io.filepnt(numfiles),600) network(1:LTR(network)) + ,date(1:LTR(date)),io.filepnt(numfiles) + ,io.files(numfiles)(1:LTR(io.files(numfiles))) 600 FORMAT( + '==================================================', + '=============================='/ + ' DYNASMART RUN OF '''A''' NETWORK '/ + ' PERFORMED ON 'A/ + '--------------------------------------------------' + '------------------------------'/ + ' OUTPUT FILE',I4': 'A/ + '..................................................' + '..............................') IF (LTR(description).LE.0) THEN WRITE(io.filepnt(numfiles),601) 601 FORMAT(' No description is was provided for this file') ELSE WRITE(holdit,'(A,A)') 'This file provides ' + ,description istart = 1 iter = 1 iend = 0 550 iend = MIN(iend+80-1,LTR(holdit)+1) !This description lines !are 80 chars wide. 551 IF (holdit(iend:iend).NE.' ') THEN iend = iend - 1 GOTO 551 ENDIF WRITE(io.filepnt(numfiles),602) holdit(istart:iend) 602 FORMAT(2X,A) IF (iend.NE.LTR(holdit)+1) THEN iter = iter + 1 istart = iend + 1 GOTO 550 ENDIF ENDIF WRITE(io.filepnt(numfiles),603) 603 FORMAT( + '==================================================', + '=============================='/) ENDIF 911 ENDDO 20 numfiles = numfiles - 1 OPENFILE = SIM_IN_PROGRESS RETURN END C ---------------------------------------------------------------------- SUBROUTINE READSTAT(str,fileunit) C ---------------------------------------------------------------------- C - Writes a message to the screen about what is being read from a C - given file (specified by its unit number) C - INCLUDED FILES: #include "dyna.inc" C - UNMODIFIED ARGUMENTS: CHARACTER str*(*) INTEGER fileunit ! unit number of file being read C - MODIFIED ARGUMENTS: ! NONE C - MODIFIED GLOBAL DATA: ! ostr (see dyna.inc) C - LOCAL VARIABLES: CHARACTER filename*80 C - FUNCTIONS CALLED: INTEGER LTR ! SIMMSG C - RETURN VALUE: ! N/A C ---------------------------------------------------------------------- INQUIRE(fileunit,NAME=filename) WRITE(ostr,600) str,filename(1:LTR(filename)),CHAR(0) 600 FORMAT('Reading: <'A'> from '''A''''A) CALL SIMMSG(STATUS,ostr) RETURN END