MODULE get_GCMInput ! ! Make sure files are open appropriate for current run time and read what is needed as ! inputs to TIME3D and edynamo. ! USE shr_kind_mod, only : r8 => shr_kind_r8 ! 8-byte reals USE namelist, only: nfiles,input_ncfiles,output_ncfiles USE fileInput, only: nFilesIO,inNCFiles,outNCFiles,secPerFile,secRunBeg,secRunEnd IMPLICIT NONE SAVE PUBLIC INTEGER :: iFileOpen ! Sequential number of which input file is currently open CHARACTER(LEN=1024), ALLOCATABLE :: inNCFiles(:) CHARACTER(LEN=1024), ALLOCATABLE :: outNCFiles(:) CONTAINS !----------------------------------------------------------------------- SUBROUTINE get_InGCMFile(iTimeStep,timeStepSec,runTimeSec) ! ! Given the current run time, time step, and last time of current open file (if a file is currently open), ! check if this is the first time step and, if so, open the first file. If not first time step and if ! last time of current file being read is prior to the current run time, open the next file if this is ! not the last input file. If this is the second time of the current file, close the previous file. ! Otherwise, pass back current file netCDF id ! USE netcdf IMPLICIT NONE SAVE INTEGER, INTENT(IN) :: iTimeStep ! Current time step in run INTEGER, INTENT(IN) :: timeStepSec ! Size of time step in seconds INTEGER, INTENT(IN) :: runTimeSec ! Current run time in seconds ! ! Local ! INTEGER :: ncGCMID1 INTEGER :: secFileEnd IF (iTimeStep == 1) THEN istat = nf90_open(inNCFiles(1),NF90_NOWRITE,ncGCMID1) istat = nf90_open(inNCFiles(2),NF90_NOWRITE,ncGCMID2) ! ! Get number of times and first time of second open file: ! iStat = NF90_INQ_DIMID(ncGCMID2,'time',idUnlim) iStat = NF90_INQUIRE_DIMENSION(ncGCMID2,idUnlim,varName,nTime) iStat = NF90_INQ_VARID(ncGCMID2,'time',timeID) iStat = NF90_GET_VAR(ncGCMID2,timeID,fracDaysBeg,(/1/),(/nTime/)) file2FirstTime = fracDaysBeg(1) * 386400 file2LastTime = fracDaysBeg(nTime) * 386400 iFileOpen = 2 ENDIF ! ! If time of run is after first time of second open file, close first file and change first ! file id to second file id ! IF (runTimeSec >= file2FirstTime) THEN istat = nf90_close(ncGCMID1) ncGCMID1 = ncGCMID2 ! ! If this is not the last input file, open the next input file as second file ! IF iFileOpen < nFilesIO THEN istat = nf90_open(inNCFiles(iFileOpen+1),NF90_NOWRITE,ncGCMID2) ! ! Get number of times and first time of new second open file: ! iStat = NF90_INQ_DIMID(ncGCMID2,'time',idUnlim) iStat = NF90_INQUIRE_DIMENSION(ncGCMID2,idUnlim,varName,nTime) iStat = NF90_INQ_VARID(ncGCMID2,'time',timeID) iStat = NF90_GET_VAR(ncGCMID2,timeID,fracDaysBeg,(/1/),(/nTime/)) file2FirstTime = fracDaysBeg(1) * 386400 file2LastTime = fracDaysBeg(nTime) * 386400 iFileOpen = iFileOpen + 1 ENDIF ENDIF END SUBROUTINE get_InGCMFile !----------------------------------------------------------------------- SUBROUTINE get_GCMData() ! ! Need to read data for first two input files if this is the first time step. For ! for following time steps, check if new second file opened and, if so, read data. !