#include "dims.h" ! subroutine readsource(ier) ! ! Read source history. ! use input_module,only: source,tempdir,source_start,output,start, | f107,f107a,power,ctpoten use hist_module,only: nsource,nhist,ioutfile,ncid,iprint,h implicit none #include "params.h" #include "fgcom.h" #include "grid.h" #include "index.h" ! ! Arg: integer,intent(out) :: ier ! ! Local: integer :: lu,nth,ncid_source,j,i real :: fmin,fmax,fminj,fmaxj ! ier = 0 ! ! If source file was provided, open read-only, and close afterwards. ! If source file not provided, open first output file, and leave it ! open for possible appending later by output_hist. ! ! Source was provided -- read source history from source file: if (nsource==1) then call rdsource(source,tempdir,source_start,ncid,nth, | .false.,iprint) nhist = 0 ! no histories on output file ioutfile = 0 ! no output file currently in use ! ! Source file was not provided -- search 1st output file: else call rdsource(output(1),tempdir,start(:,1),ncid,nth,.true., | iprint) nhist = nth ! number of histories on current output file ioutfile = 1 ! current output file name is output(ioutfile) endif ! if (ncid==0) then ier = 1 return endif ! ! Update gpi vars: ! f107 = h%f107d ! f107a = h%f107a ! power = h%hpower ! ctpoten = h%ctpoten ! ! Debug lat min,max: ! write(6,"('readsource: call fgmnmx after reading netcdf', ! | ' source: ixtimep=',i2)") ixtimep ! do j=1,nlat ! call fgmnmx(0,'DUM',1,ndisk,j,ixtimep) ! enddo ! ! Debug 3d min,max: ! write(6,"('readsource: call fminmaxspv after reading netcdf', ! | ' source: ixtimep=',i2)") ixtimep ! do i=1,ndisk ! fmin = 1.e36 ! fmax = -1.e36 ! do j=1,nlat ! call fminmaxspv(fg(1,ndexa(i+1)+1,j,ixtimep),zimxp*zkmxp, ! | fminj,fmaxj,spval) ! if (fminj < fmin) fmin = fminj ! if (fmaxj > fmax) fmax = fmaxj ! enddo ! write(6,"('readsource: Read field ',a,' 3d min,max = ', ! | 2e12.4)") nflds_lab(i),fmin,fmax ! enddo end subroutine readsource !------------------------------------------------------------------- subroutine rdsource(filepath,tempdir,mtime,ncid,nthist, | reopen_append,iprint) ! ! Acquire and read source history: ! ! On input: ! filepath = mss path to history file ! tempdir = path to a temporary directory ! mtime(3) = model time of requested source history ! reopen_append: if true, reopen the file for later writing after ! reading the history. ! iprint: if > 0, report to stdout ! ! On output: ! ncid = file id of history file ! nthist = source history is nth history on the file ! global history structure h is defined (see nc_rdhist) ! use netcdf_module,only: nc_open,nc_close,nc_rdhist implicit none ! ! Args: character(len=*),intent(in) :: filepath,tempdir integer,intent(in) :: mtime(3),iprint integer,intent(out) :: nthist,ncid logical,intent(in) :: reopen_append ! ! Local: integer :: | mday,mhour,mmin, ! model day,hour,minute from header | j, ! latitude loop index | ier ! error flag real :: dum,rj character(len=120) :: diskfile ! ! Acquire source file: call mkdiskflnm(filepath,diskfile) call getms(filepath,diskfile,tempdir,' ') write(6,"('Acquired source history file ',a, | /,' (disk file is ',a,')')") trim(filepath),trim(diskfile) ! ! Open existing netcdf file for read-only: call nc_open(ncid,diskfile,'OLD','READ') if (ncid==0) then write(6,"(/,'>>> rdsource: error opening ',a,' as a ', | 'netcdf file.')") trim(diskfile) return endif ! ! Search for and read the source history: call nc_rdhist(ncid,diskfile,mtime,nthist,ier) if (ier > 0) then write(6,"(/,'>>> ERROR return from nc_rdhist reading')") write(6,"(' source file ',a,' from ncid=',i8,' mtime=', | 3i4)") trim(diskfile),ncid,mtime stop 'nc_rdhist' endif call nc_close(ncid) ! ! Reopen file for writing if necessary: if (reopen_append) call nc_open(ncid,diskfile,'OLD','WRITE') end subroutine rdsource