📄 restfilemod.f90
字号:
#include <misc.h>#include <preproc.h>module restFileMod!----------------------------------------------------------------------- ! ! Purpose: ! Read/Write CLM restart files! ! Method: ! ! Author: Mariana Vertenstein! !-----------------------------------------------------------------------! $Id: restFileMod.F90,v 1.19.6.7.6.1 2002/05/13 19:25:07 erik Exp $!----------------------------------------------------------------------- use precision use clm_varder use clm_varpar, only : nlevsoi, numrad, maxhist, lsmlon, lsmlat, & maxpatch_pft, maxpatch use clm_varmap, only : begpatch, endpatch, numpatch, patchvec, & begland, endland, numland, landvec use clm_varctl, only : nsrest, rpntdir, rpntfil, nrevsn, locfnh, & archive_dir, mss_irt, mss_wpass, csm_doflxave, caseid use fileutils , only : opnfil, putfil, getfil, getavu, relavu, set_filename use histFileMod , only : slfld, mlsoifld, ntim, nbeghis, nhist, ncgetid, ncid use histHandlerMod, only : mcdate_i, mcsec_i, mdcur_i, mscur_i #if (defined SPMD) use spmdMod, only : masterproc, npes, compute_mpigs_patch, compute_mpigs_land use mpishorthand, only : mpir8, mpilog, mpiint, mpicom #else use spmdMod, only : masterproc#endif#if (defined RTM) use RtmMod , only : volr, ncount_rtm, totrunin_ave, prec_ave, evap_ave, & qchan2, qchocn2, ocnrof_vec, prec_global, evap_global, & runlnd_global, runrtm_global, volrtm_global, ocnrtm_global,& ncount_global, yrold#endif#if (defined COUP_CSM) use clm_csmMod#endif implicit none! Methods public :: restrd public :: restwrt private :: write_rest_pfile private :: set_restart_filename! Generic procedures PRIVATE :: readin, wrtout INTERFACE readin MODULE procedure readinsc_log MODULE procedure readinsc_int MODULE procedure readinsc_real MODULE procedure readin1d_int MODULE procedure readin2d_int MODULE procedure readin3d_int MODULE procedure readin1d_real MODULE procedure readin2d_real MODULE procedure readin3d_real END INTERFACE INTERFACE wrtout MODULE procedure wrtoutsc_log MODULE procedure wrtoutsc_int MODULE procedure wrtoutsc_real MODULE procedure wrtout1d_int MODULE procedure wrtout2d_int MODULE procedure wrtout3d_int MODULE procedure wrtout1d_real MODULE procedure wrtout2d_real MODULE procedure wrtout3d_real END INTERFACE integer ,allocatable :: ibuf1d(:) !temporary integer buffer real(r8),allocatable :: buf1d(:) !temporary buffer integer ,allocatable :: ibuf2d(:,:) !temporary integer buffer real(r8),allocatable :: buf2d(:,:) !temporary buffer integer ,allocatable :: ibuf3d(:,:,:) !temporary integer buffer real(r8),allocatable :: buf3d(:,:,:) !temporary buffer integer, private, parameter :: rest_id = 4!=======================================================================CONTAINS!======================================================================= subroutine restrd()!----------------------------------------------------------------------- ! ! Purpose: ! Read CLM restart file. Open history file if needed! ! Method: ! This code reads the clm restart file. If the current history file(s) are! not full, file(s) are opened so that subsequent time samples are added! until the file is full. A new history file is used on a branch run. ! ! Author: Mariana Vertenstein! !----------------------------------------------------------------------- use clm_varcon , only : denice, denh2o#if (defined COUP_CAM) use time_manager, only : get_step_size, get_nstep #else use time_manager, only : get_step_size, get_nstep, & timemgr_read_restart, timemgr_restart#endif #if (defined COUP_CSM) use controlMod , only : csm_dtime !dtime from input namelist#endif include 'netcdf.inc'! ------------------------ local variables ------------------------ integer :: i,j,k,l,m,n !indices integer :: nio !Fortran unit number integer :: nstep !time index integer :: num !number of fields (temporary) character(len=256) :: fnamer !full name of restart file character(len=256) :: fnameh(maxhist) !full name of history file character(len=256) :: locfn !local file name character(len= 16) :: casename !case name read in from restart logical :: flxave_res !flux averaging flag read from restart file integer ier !temporaries #if (defined SPMD) integer :: numsendv(0:npes-1) !vector of items to be sent integer :: numsend !number of items to be sent integer :: numrecv !number of items to be received integer :: numrecvv(0:npes-1) !vector of items to be received integer :: displsv(0:npes-1) !displacement vector real(r8), allocatable :: scatter1d(:) !scatter temporary #endif real(r8):: dtime !step size (seconds) #if (defined COUP_CAM) integer :: clm_nstep !nstep from restart file#endif! ----------------------------------------------------------------- if (masterproc) then write(6,*) 'Attempting to read restart data .....' write(6,'(72a1)') ("-",i=1,60) endif! Get appropriate restart and history file names if continuation run. ! For a restart run, the restart pointer file contains the full ! mass store or local path name of the current restart file ! For a branch run, the variable [nrevsn] is the full mass store ! or local path name of the appropriate restart file if (masterproc) then! Determine restart filename if (nsrest == 1) then !restart nio = getavu() locfn = trim(rpntdir) //'/'// trim(rpntfil) call opnfil (locfn, nio, 'f') read (nio,'(a80)') fnamer call relavu (nio) else !branch run fnamer = nrevsn end if! Obtain and open restart file nio = getavu() call getfil (fnamer, locfn, 0) call opnfil (locfn, nio, 'u') endif! -----------------------------------------------------------------! Read restart file! -----------------------------------------------------------------! Check that restart file id matches that for this code version call readin (nio, n) if (masterproc) then if (n == rest_id) then write(6,*)'RESTRD: using restart file id ',rest_id else write(6,*)'RESTRD: input restart file id ',n, & ' does not match required restart id ',rest_id call endrun endif endif#if (defined COUP_CAM)! read in time step - make check to see that clm restart time step ! is consistent with cam restart time step! note that in cam mode - the time manager restart variables have! already been read in by calls to routines timemgr_read_restart and! timemgr_restart from the cam restart files call readin (nio, clm_nstep) if ((clm_nstep+1) /= get_nstep()) then write(6,*)'(RESTRD): incompatibility in clm and cam restart dates' write(6,*)' restart step from cam = ',get_nstep() write(6,*)' restart step from clm = ',clm_nstep + 1 call endrun endif#else! restart the time manager if (masterproc) then call timemgr_read_restart(nio) endif call timemgr_restart()#endif#if (defined COUP_CSM) if (csm_dtime /= get_step_size()) then write(6,*)'(RESTRD): error ' write(6,*)'namelist dtime on restart does not match input dtime' call endrun endif#endif! set derived type component for dtime (for an initial run, this is set! in routine iniTimeConst.F90) clm(begpatch:endpatch)%dtime = get_step_size()! read in necessary 1d fields allocate ( buf1d(begpatch:endpatch)) allocate (ibuf1d(begpatch:endpatch)) call readin (nio, ibuf1d) clm(begpatch:endpatch)%snl = ibuf1d(begpatch:endpatch) call readin (nio, ibuf1d) clm(begpatch:endpatch)%frac_veg_nosno_alb = ibuf1d(begpatch:endpatch) call readin (nio, buf1d) clm(begpatch:endpatch)%h2osno = buf1d(begpatch:endpatch) call readin (nio, buf1d) clm(begpatch:endpatch)%h2ocan = buf1d(begpatch:endpatch) call readin (nio, buf1d) clm(begpatch:endpatch)%snowdp = buf1d(begpatch:endpatch) call readin (nio, buf1d) clm(begpatch:endpatch)%snowage = buf1d(begpatch:endpatch) call readin (nio, buf1d) clm(begpatch:endpatch)%frac_sno = buf1d(begpatch:endpatch) call readin (nio, buf1d) clm(begpatch:endpatch)%t_veg = buf1d(begpatch:endpatch) call readin (nio, buf1d) clm(begpatch:endpatch)%t_grnd = buf1d(begpatch:endpatch) call readin (nio, buf1d) clm(begpatch:endpatch)%fwet = buf1d(begpatch:endpatch) call readin (nio, buf1d) clm(begpatch:endpatch)%tlai = buf1d(begpatch:endpatch) call readin (nio, buf1d) clm(begpatch:endpatch)%tsai = buf1d(begpatch:endpatch) call readin (nio, buf1d) clm(begpatch:endpatch)%elai = buf1d(begpatch:endpatch) call readin (nio, buf1d) clm(begpatch:endpatch)%esai = buf1d(begpatch:endpatch) call readin (nio, buf1d) clm(begpatch:endpatch)%fsun = buf1d(begpatch:endpatch) call readin (nio, buf1d) clm(begpatch:endpatch)%htop = buf1d(begpatch:endpatch) call readin (nio, buf1d) clm(begpatch:endpatch)%hbot = buf1d(begpatch:endpatch) deallocate (ibuf1d) deallocate ( buf1d)! read in multi level snow only fields allocate (buf2d(-nlevsno+1:0,begpatch:endpatch)) call readin (nio, buf2d, nlevsno) do j = -nlevsno+1,0 clm(begpatch:endpatch)%dz(j) = buf2d(j,begpatch:endpatch) end do call readin (nio, buf2d, nlevsno) do j = -nlevsno+1,0 clm(begpatch:endpatch)%z(j) = buf2d(j,begpatch:endpatch) end do deallocate(buf2d) allocate (buf2d(-nlevsno:0,begpatch:endpatch)) call readin (nio, buf2d, nlevsno+1) do j = -nlevsno,0 clm(begpatch:endpatch)%zi(j) = buf2d(j,begpatch:endpatch) end do deallocate(buf2d)! read in multi level snow-soil fields allocate (buf2d(-nlevsno+1:nlevsoi,begpatch:endpatch)) call readin (nio, buf2d, nlevsno+nlevsoi) do j = -nlevsno+1,nlevsoi clm(begpatch:endpatch)%t_soisno(j) = buf2d(j,begpatch:endpatch) end do call readin (nio, buf2d, nlevsoi+nlevsno) do j = -nlevsno+1,nlevsoi clm(begpatch:endpatch)%h2osoi_liq(j) = buf2d(j,begpatch:endpatch) end do call readin (nio, buf2d, nlevsoi+nlevsno) do j = -nlevsno+1,nlevsoi clm(begpatch:endpatch)%h2osoi_ice(j) = buf2d(j,begpatch:endpatch) end do deallocate(buf2d) allocate (buf2d(1:nlevlak,begpatch:endpatch)) call readin (nio, buf2d, nlevlak) do j = 1,nlevlak clm(begpatch:endpatch)%t_lake(j) = buf2d(j,begpatch:endpatch) end do deallocate(buf2d)! determine volumetric soil water
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -