diff --git a/lis/configs/lis.config.adoc b/lis/configs/lis.config.adoc index 271accd18..8a9eeb7c2 100644 --- a/lis/configs/lis.config.adoc +++ b/lis/configs/lis.config.adoc @@ -7993,7 +7993,7 @@ of how to specify a time interval. `Noah-MP.4.0.1 restart file:` specifies the Noah-MP-4.0.1 LSM restart file. `Noah-MP.4.0.1 restart file format:` specifies the Noah-MP-4.0.1 restart -file format (default = netcdf). +file format. Acceptable values are: "`binary`", "`netcdf`", or "`distributed binary`". `Noah-MP.4.0.1 soil parameter table:` specifies the filename of the Noah-MP-4.0.1 soil parameter table. diff --git a/lis/dataassim/perturb/gmaopert/gmaopert_Mod.F90 b/lis/dataassim/perturb/gmaopert/gmaopert_Mod.F90 index f69c9dc07..ecea66508 100644 --- a/lis/dataassim/perturb/gmaopert/gmaopert_Mod.F90 +++ b/lis/dataassim/perturb/gmaopert/gmaopert_Mod.F90 @@ -1834,108 +1834,284 @@ subroutine gmaopert_writerestart(n) real, allocatable :: pertdata1d_patch(:) integer, allocatable :: pertdata1d_int(:) integer, allocatable :: pertdata1d_patch_int(:) - character(len=LIS_CONST_PATH_LEN) :: filen - integer :: ftn + character(len=LIS_CONST_PATH_LEN) :: filen,filenp + character*4 :: temp1 + character*1 :: fproc(4) + integer :: ftn + character*20 :: wformat - if ( LIS_masterproc ) then - - call LIS_create_output_directory('DAPERT') - call LIS_create_dapert_filename(n,filen) - - ftn = LIS_getNextUnitNumber() - write(LIS_logunit,*) '[INFO] Writing Perturbations restart ', & - trim(filen) - open(ftn, file = trim(filen), form='unformatted') - - endif - if(LIS_rc%perturb_forcing .ne."none") then - if(.not. f_xyCorr) then - allocate(pertdata1d(LIS_rc%ntiles(n))) + wformat = "distributed binary" + + if(wformat.eq."binary") then + if ( LIS_masterproc ) then + + call LIS_create_output_directory('DAPERT') + call LIS_create_dapert_filename(n,filen) + + ftn = LIS_getNextUnitNumber() + write(LIS_logunit,*) '[INFO] Writing Perturbations restart ', & + trim(filen) + open(ftn, file = trim(filen), form='unformatted') - k = 1 - do i=1,LIS_rc%nforcepert + endif + if(LIS_rc%perturb_forcing .ne."none") then + if(.not. f_xyCorr) then + allocate(pertdata1d(LIS_rc%ntiles(n))) - do t=1,LIS_rc%ntiles(n) - col = LIS_domain(n)%tile(t)%col - row = LIS_domain(n)%tile(t)%row - ensem = LIS_domain(n)%tile(t)%ensem - pertdata1d(t) = forcpert(n,k)%forcepert_ntrmdt(i,col,row,ensem) + k = 1 + do i=1,LIS_rc%nforcepert + + do t=1,LIS_rc%ntiles(n) + col = LIS_domain(n)%tile(t)%col + row = LIS_domain(n)%tile(t)%row + ensem = LIS_domain(n)%tile(t)%ensem + pertdata1d(t) = forcpert(n,k)%forcepert_ntrmdt(i,col,row,ensem) + enddo + + call LIS_writevar_restart(ftn,n,pertdata1d) enddo - - call LIS_writevar_restart(ftn,n,pertdata1d) - enddo - deallocate(pertdata1d) - allocate(pertdata1d_int(LIS_rc%ntiles(n))) - - do i=1,NRANDSEED - do t=1,LIS_rc%ntiles(n) - col = LIS_domain(n)%tile(t)%col - row = LIS_domain(n)%tile(t)%row - ensem = LIS_domain(n)%tile(t)%ensem - pertdata1d_int(t) = & - forcpert(n,k)%forcepert_rseed(i,col,row,ensem) + + deallocate(pertdata1d) + allocate(pertdata1d_int(LIS_rc%ntiles(n))) + + do i=1,NRANDSEED + do t=1,LIS_rc%ntiles(n) + col = LIS_domain(n)%tile(t)%col + row = LIS_domain(n)%tile(t)%row + ensem = LIS_domain(n)%tile(t)%ensem + pertdata1d_int(t) = & + forcpert(n,k)%forcepert_rseed(i,col,row,ensem) + enddo + call LIS_writevar_restart(ftn,n,pertdata1d_int) enddo - call LIS_writevar_restart(ftn,n,pertdata1d_int) + deallocate(pertdata1d_int) + + else + if(LIS_masterproc) then + k = 1 + do i=1,LIS_rc%nforcepert + write(ftn) forcpert(n,k)%forcepert_ntrmdt(i,:,:,:) + enddo + + do i=1,NRANDSEED + write(ftn) forcpert(n,k)%forcepert_rseed(i,:,:,:) + enddo + endif + endif + endif + + if(.not. p_xyCorr) then + + do k=1,LIS_rc%nperts + allocate(pertdata1d_patch(LIS_rc%npatch(n,LIS_rc%lsm_index))) + + if(trim(LIS_rc%perturb_state(k)).ne."none") then + do i =1, LIS_rc%nstvars(k) + do t=1,LIS_rc%npatch(n,LIS_rc%lsm_index) + col = LIS_surface(n,LIS_rc%lsm_index)%tile(t)%col + row = LIS_surface(n,LIS_rc%lsm_index)%tile(t)%row + ensem = LIS_surface(n,LIS_rc%lsm_index)%tile(t)%ensem + pertdata1d_patch(t) = & + progpert(n,k)%progpert_ntrmdt(i,col,row,ensem) + enddo + + call LIS_writevar_restart(ftn,n,1,pertdata1d_patch) + enddo + endif + + deallocate(pertdata1d_patch) + allocate(pertdata1d_patch_int(LIS_rc%npatch(n,LIS_rc%lsm_index))) + + if(trim(LIS_rc%perturb_state(k)).ne."none") then + do i =1, NRANDSEED + do t=1,LIS_rc%npatch(n,LIS_rc%lsm_index) + col = LIS_surface(n,LIS_rc%lsm_index)%tile(t)%col + row = LIS_surface(n,LIS_rc%lsm_index)%tile(t)%row + ensem = LIS_surface(n,LIS_rc%lsm_index)%tile(t)%ensem + pertdata1d_patch_int(t) = & + progpert(n,k)%progpert_rseed(i,col,row,ensem) + enddo + + call LIS_writevar_restart(ftn,n,1,pertdata1d_patch_int) + enddo + endif + + deallocate(pertdata1d_patch_int) enddo - deallocate(pertdata1d_int) else - if(LIS_masterproc) then + if(LIS_masterproc) then + do k=1,LIS_rc%nperts + if(trim(LIS_rc%perturb_state(k)).ne."none") then + do i =1, LIS_rc%nstvars(k) + write(ftn) & + progpert(n,k)%progpert_ntrmdt(i,:,:,:) + enddo + + do i =1, NRANDSEED + write(ftn) & + progpert(n,k)%progpert_rseed(i,:,:,:) + enddo + endif + enddo + endif + endif + + if(.not. o_xyCorr) then + do k=1,LIS_rc%ndas + if(trim(LIS_rc%perturb_obs(k)).ne."none") then + allocate(pertdata1d(LIS_rc%obs_ngrid(k)*LIS_rc%nensem(n))) + do i=1, nobs(n,k) + do t=1,LIS_rc%obs_ngrid(k) + col = LIS_obs_domain(n,k)%col(t) + row = LIS_obs_domain(n,k)%row(t) + do kk=1,LIS_rc%nensem(n) + pertdata1d(kk+(t-1)*LIS_rc%nensem(n)) = & + obspert(n,k)%obspert_ntrmdt(i,col,row,kk) + enddo + enddo + + call writevar_obspert_restart(ftn,n,k,pertdata1d) + enddo + deallocate(pertdata1d) + + allocate(pertdata1d_int(LIS_rc%obs_ngrid(k)*LIS_rc%nensem(n))) + do i=1, NRANDSEED + do t=1,LIS_rc%obs_ngrid(k) + col = LIS_obs_domain(n,k)%col(t) + row = LIS_obs_domain(n,k)%row(t) + do kk=1,LIS_rc%nensem(n) + pertdata1d_int(kk+(t-1)*LIS_rc%nensem(n)) = & + obspert(n,k)%obspert_rseed(i,col,row,kk) + enddo + enddo + + call writevar_obspert_restart_int(ftn,n,k,pertdata1d_int) + enddo + deallocate(pertdata1d_int) + + endif + enddo + else + if(LIS_masterproc) then + do k=1,LIS_rc%ndas + if(trim(LIS_rc%perturb_obs(k)).ne."none") then + do i=1, nobs(n,k) + write(ftn) obspert(n,k)%obspert_ntrmdt(i,:,:,:) + enddo + do i=1, NRANDSEED + write(ftn) obspert(n,k)%obspert_rseed(i,:,:,:) + enddo + endif + enddo + endif + endif + if(LIS_masterproc) then + call LIS_releaseUnitNumber(ftn) + write(LIS_logunit,*) '[INFO] Done writing Perturbations restart ', & + trim(filen) + endif + elseif(wformat.eq."distributed binary") then + + call LIS_create_output_directory('DAPERT') + + ftn = LIS_getNextUnitNumber() + call LIS_create_dapert_filename(n,filen) + + write(temp1,'(i4.4)') LIS_localPet + read(temp1,fmt='(4a1)') fproc + + filenp = trim(filen)//'.'//fproc(1)//fproc(2)//fproc(3)//fproc(4) + + open(ftn,file=trim(filenp),form='unformatted') + + if(LIS_rc%perturb_forcing .ne."none") then + if(.not. f_xyCorr) then + allocate(pertdata1d(LIS_rc%ntiles(n))) + k = 1 - do i=1,LIS_rc%nforcepert + do i=1,LIS_rc%nforcepert + + do t=1,LIS_rc%ntiles(n) + col = LIS_domain(n)%tile(t)%col + row = LIS_domain(n)%tile(t)%row + ensem = LIS_domain(n)%tile(t)%ensem + pertdata1d(t) = forcpert(n,k)%forcepert_ntrmdt(i,col,row,ensem) + enddo + + write(ftn) pertdata1d + enddo + + deallocate(pertdata1d) + allocate(pertdata1d_int(LIS_rc%ntiles(n))) + + do i=1,NRANDSEED + do t=1,LIS_rc%ntiles(n) + col = LIS_domain(n)%tile(t)%col + row = LIS_domain(n)%tile(t)%row + ensem = LIS_domain(n)%tile(t)%ensem + pertdata1d_int(t) = & + forcpert(n,k)%forcepert_rseed(i,col,row,ensem) + enddo + write(ftn) pertdata1d_int + enddo + deallocate(pertdata1d_int) + + else + k = 1 + do i=1,LIS_rc%nforcepert write(ftn) forcpert(n,k)%forcepert_ntrmdt(i,:,:,:) enddo - + do i=1,NRANDSEED write(ftn) forcpert(n,k)%forcepert_rseed(i,:,:,:) enddo + endif endif - endif + if(.not. p_xyCorr) then - if(.not. p_xyCorr) then + do k=1,LIS_rc%nperts + allocate(pertdata1d_patch(LIS_rc%npatch(n,LIS_rc%lsm_index))) + + if(trim(LIS_rc%perturb_state(k)).ne."none") then + do i =1, LIS_rc%nstvars(k) + do t=1,LIS_rc%npatch(n,LIS_rc%lsm_index) + col = LIS_surface(n,LIS_rc%lsm_index)%tile(t)%col + row = LIS_surface(n,LIS_rc%lsm_index)%tile(t)%row + ensem = LIS_surface(n,LIS_rc%lsm_index)%tile(t)%ensem + pertdata1d_patch(t) = & + progpert(n,k)%progpert_ntrmdt(i,col,row,ensem) + enddo - do k=1,LIS_rc%nperts - allocate(pertdata1d_patch(LIS_rc%npatch(n,LIS_rc%lsm_index))) + write(ftn) pertdata1d_patch - if(trim(LIS_rc%perturb_state(k)).ne."none") then - do i =1, LIS_rc%nstvars(k) - do t=1,LIS_rc%npatch(n,LIS_rc%lsm_index) - col = LIS_surface(n,LIS_rc%lsm_index)%tile(t)%col - row = LIS_surface(n,LIS_rc%lsm_index)%tile(t)%row - ensem = LIS_surface(n,LIS_rc%lsm_index)%tile(t)%ensem - pertdata1d_patch(t) = & - progpert(n,k)%progpert_ntrmdt(i,col,row,ensem) enddo - - call LIS_writevar_restart(ftn,n,1,pertdata1d_patch) - enddo - endif + endif + + deallocate(pertdata1d_patch) + allocate(pertdata1d_patch_int(LIS_rc%npatch(n,LIS_rc%lsm_index))) - deallocate(pertdata1d_patch) - allocate(pertdata1d_patch_int(LIS_rc%npatch(n,LIS_rc%lsm_index))) - - if(trim(LIS_rc%perturb_state(k)).ne."none") then - do i =1, NRANDSEED - do t=1,LIS_rc%npatch(n,LIS_rc%lsm_index) - col = LIS_surface(n,LIS_rc%lsm_index)%tile(t)%col - row = LIS_surface(n,LIS_rc%lsm_index)%tile(t)%row - ensem = LIS_surface(n,LIS_rc%lsm_index)%tile(t)%ensem - pertdata1d_patch_int(t) = & - progpert(n,k)%progpert_rseed(i,col,row,ensem) + if(trim(LIS_rc%perturb_state(k)).ne."none") then + do i =1, NRANDSEED + do t=1,LIS_rc%npatch(n,LIS_rc%lsm_index) + col = LIS_surface(n,LIS_rc%lsm_index)%tile(t)%col + row = LIS_surface(n,LIS_rc%lsm_index)%tile(t)%row + ensem = LIS_surface(n,LIS_rc%lsm_index)%tile(t)%ensem + pertdata1d_patch_int(t) = & + progpert(n,k)%progpert_rseed(i,col,row,ensem) + enddo + + write(ftn) pertdata1d_patch_int enddo - - call LIS_writevar_restart(ftn,n,1,pertdata1d_patch_int) - enddo - endif + endif - deallocate(pertdata1d_patch_int) - enddo + deallocate(pertdata1d_patch_int) + enddo - else - if(LIS_masterproc) then + else do k=1,LIS_rc%nperts - if(trim(LIS_rc%perturb_state(k)).ne."none") then + if(trim(LIS_rc%perturb_state(k)).ne."none") then do i =1, LIS_rc%nstvars(k) write(ftn) & progpert(n,k)%progpert_ntrmdt(i,:,:,:) @@ -1948,47 +2124,43 @@ subroutine gmaopert_writerestart(n) endif enddo endif - endif - if(.not. o_xyCorr) then - do k=1,LIS_rc%ndas - if(trim(LIS_rc%perturb_obs(k)).ne."none") then - allocate(pertdata1d(LIS_rc%obs_ngrid(k)*LIS_rc%nensem(n))) - do i=1, nobs(n,k) - do t=1,LIS_rc%obs_ngrid(k) - col = LIS_obs_domain(n,k)%col(t) - row = LIS_obs_domain(n,k)%row(t) - do kk=1,LIS_rc%nensem(n) - pertdata1d(kk+(t-1)*LIS_rc%nensem(n)) = & - obspert(n,k)%obspert_ntrmdt(i,col,row,kk) + if(.not. o_xyCorr) then + do k=1,LIS_rc%ndas + if(trim(LIS_rc%perturb_obs(k)).ne."none") then + allocate(pertdata1d(LIS_rc%obs_ngrid(k)*LIS_rc%nensem(n))) + do i=1, nobs(n,k) + do t=1,LIS_rc%obs_ngrid(k) + col = LIS_obs_domain(n,k)%col(t) + row = LIS_obs_domain(n,k)%row(t) + do kk=1,LIS_rc%nensem(n) + pertdata1d(kk+(t-1)*LIS_rc%nensem(n)) = & + obspert(n,k)%obspert_ntrmdt(i,col,row,kk) + enddo enddo + write(ftn) pertdata1d enddo + deallocate(pertdata1d) - call writevar_obspert_restart(ftn,n,k,pertdata1d) - enddo - deallocate(pertdata1d) - - allocate(pertdata1d_int(LIS_rc%obs_ngrid(k)*LIS_rc%nensem(n))) - do i=1, NRANDSEED - do t=1,LIS_rc%obs_ngrid(k) - col = LIS_obs_domain(n,k)%col(t) - row = LIS_obs_domain(n,k)%row(t) - do kk=1,LIS_rc%nensem(n) - pertdata1d_int(kk+(t-1)*LIS_rc%nensem(n)) = & - obspert(n,k)%obspert_rseed(i,col,row,kk) + allocate(pertdata1d_int(LIS_rc%obs_ngrid(k)*LIS_rc%nensem(n))) + do i=1, NRANDSEED + do t=1,LIS_rc%obs_ngrid(k) + col = LIS_obs_domain(n,k)%col(t) + row = LIS_obs_domain(n,k)%row(t) + do kk=1,LIS_rc%nensem(n) + pertdata1d_int(kk+(t-1)*LIS_rc%nensem(n)) = & + obspert(n,k)%obspert_rseed(i,col,row,kk) + enddo enddo + write(ftn) pertdata1d_int enddo + deallocate(pertdata1d_int) - call writevar_obspert_restart_int(ftn,n,k,pertdata1d_int) - enddo - deallocate(pertdata1d_int) - - endif - enddo - else - if(LIS_masterproc) then + endif + enddo + else do k=1,LIS_rc%ndas - if(trim(LIS_rc%perturb_obs(k)).ne."none") then + if(trim(LIS_rc%perturb_obs(k)).ne."none") then do i=1, nobs(n,k) write(ftn) obspert(n,k)%obspert_ntrmdt(i,:,:,:) enddo @@ -1997,14 +2169,13 @@ subroutine gmaopert_writerestart(n) enddo endif enddo + endif - endif - if(LIS_masterproc) then call LIS_releaseUnitNumber(ftn) write(LIS_logunit,*) '[INFO] Done writing Perturbations restart ', & - trim(filen) - endif + trim(filenp) + endif end subroutine gmaopert_writerestart !BOP @@ -2027,8 +2198,10 @@ subroutine gmaopert_readrestart() integer :: yr,mo,da,hr,mn,ss, doy integer :: status character(len=LIS_CONST_PATH_LEN) :: filen + character*4 :: temp1 real*8 :: time real :: gmt + character*1 :: fproc(4) real, allocatable :: pertdata1d(:) real, allocatable :: pertdata1d_obs(:) real, allocatable :: pertdata1d_patch(:) @@ -2037,250 +2210,431 @@ subroutine gmaopert_readrestart() integer, allocatable :: pertdata1d_patch_int(:) real, allocatable :: dummy_var(:,:,:) logical :: file_exists + character*20 :: wformat + + wformat = "distributed binary" + + if(wformat.eq."binary") then + do n = 1, LIS_rc%nnest + + ftn = LIS_getNextUnitNumber() + + if(LIS_rc%runmode.eq."ensemble smoother") then + if(LIS_rc%iterationid(n).gt.1) then + if(LIS_rc%pertrestartInterval.eq.2592000) then + call ESMF_TimeGet(LIS_twStartTime,yy=yr,mm=mo,& + dd=da,calendar=LIS_calendar,rc=status) + hr = 0 + mn = 0 + ss = 0 + call LIS_tick(time,doy,gmt,yr,mo,da,hr,mn,ss,(-1)*LIS_rc%ts) + else + call ESMF_TimeGet(LIS_twStartTime,yy=yr,mm=mo,& + dd=da,calendar=LIS_calendar,rc=status) + hr = 0 + mn = 0 + ss = 0 + endif + call LIS_create_dapert_filename(n,filen, yr, mo, da, hr, mn, ss) + LIS_rc%pertRestartFile(n) = filen + endif + endif - do n = 1, LIS_rc%nnest + inquire( file=trim(LIS_rc%pertRestartFile(n)), exist=file_exists ) + if(file_exists .neqv. .true.) then + write(LIS_logunit,*) '[ERR] Reading perturbations restart file MISSING: ',& + trim(LIS_rc%pertRestartFile(n)) + call LIS_endrun() + endif - ftn = LIS_getNextUnitNumber() + open(ftn,file=trim(LIS_rc%pertRestartFile(n)), form='unformatted') + write(LIS_logunit,*) '[INFO] Reading perturbations restart file ',& + trim(LIS_rc%pertRestartFile(n)) + + if(LIS_rc%perturb_forcing .ne."none") then + if(.not. f_xyCorr) then + allocate(pertdata1d(LIS_rc%ntiles(n))) + + k = 1 + do i=1,LIS_rc%nforcepert + + call LIS_readvar_restart(ftn,n,pertdata1d) + + do t=1,LIS_rc%ntiles(n) + col = LIS_domain(n)%tile(t)%col + row = LIS_domain(n)%tile(t)%row + ensem = LIS_domain(n)%tile(t)%ensem + forcpert(n,k)%forcepert_ntrmdt(i,col,row,ensem) = pertdata1d(t) + enddo + enddo + + deallocate(pertdata1d) + + allocate(pertdata1d_int(LIS_rc%ntiles(n))) + + do i=1,NRANDSEED + + call LIS_readvar_restart(ftn,n,pertdata1d_int) + + do t=1,LIS_rc%ntiles(n) + col = LIS_domain(n)%tile(t)%col + row = LIS_domain(n)%tile(t)%row + ensem = LIS_domain(n)%tile(t)%ensem + forcpert(n,k)%forcepert_rseed(i,col,row,ensem) = pertdata1d_int(t) + enddo + enddo + deallocate(pertdata1d_int) - if(LIS_rc%runmode.eq."ensemble smoother") then - if(LIS_rc%iterationid(n).gt.1) then - if(LIS_rc%pertrestartInterval.eq.2592000) then - call ESMF_TimeGet(LIS_twStartTime,yy=yr,mm=mo,& - dd=da,calendar=LIS_calendar,rc=status) - hr = 0 - mn = 0 - ss = 0 - call LIS_tick(time,doy,gmt,yr,mo,da,hr,mn,ss,(-1)*LIS_rc%ts) else - call ESMF_TimeGet(LIS_twStartTime,yy=yr,mm=mo,& - dd=da,calendar=LIS_calendar,rc=status) - hr = 0 - mn = 0 - ss = 0 + if(LIS_masterproc) then + k = 1 + do i=1,LIS_rc%nforcepert + read(ftn) forcpert(n,k)%forcepert_ntrmdt(i,:,:,:) + enddo + do i=1,NRANDSEED + read(ftn) forcpert(n,k)%forcepert_rseed(i,:,:,:) + enddo + else +! to keep the binary reading in sync when there is a mix of file reading that +! happens only on one processor and across processors. + allocate(dummy_var(& + LIS_rc%gnc(n),LIS_rc%gnr(n),LIS_rc%nensem(n))) + do i =1, LIS_rc%nforcepert + read(ftn) dummy_var + enddo + do i =1, NRANDSEED + read(ftn) dummy_var + enddo + deallocate(dummy_var) + endif + endif - call LIS_create_dapert_filename(n,filen, yr, mo, da, hr, mn, ss) - LIS_rc%pertRestartFile(n) = filen endif - endif - - inquire( file=trim(LIS_rc%pertRestartFile(n)), exist=file_exists ) - if(file_exists .neqv. .true.) then - write(LIS_logunit,*) '[ERR] Reading perturbations restart file MISSING: ',& - trim(LIS_rc%pertRestartFile(n)) - call LIS_endrun() - endif + if(.not. p_xyCorr) then + do k=1, LIS_rc%nperts - open(ftn,file=trim(LIS_rc%pertRestartFile(n)), form='unformatted') - write(LIS_logunit,*) '[INFO] Reading perturbations restart file ',& - trim(LIS_rc%pertRestartFile(n)) - - if(LIS_rc%perturb_forcing .ne."none") then - if(.not. f_xyCorr) then - allocate(pertdata1d(LIS_rc%ntiles(n))) - - k = 1 - do i=1,LIS_rc%nforcepert - - call LIS_readvar_restart(ftn,n,pertdata1d) - - do t=1,LIS_rc%ntiles(n) - col = LIS_domain(n)%tile(t)%col - row = LIS_domain(n)%tile(t)%row - ensem = LIS_domain(n)%tile(t)%ensem - forcpert(n,k)%forcepert_ntrmdt(i,col,row,ensem) = pertdata1d(t) - enddo - enddo - - deallocate(pertdata1d) - - allocate(pertdata1d_int(LIS_rc%ntiles(n))) - - do i=1,NRANDSEED - - call LIS_readvar_restart(ftn,n,pertdata1d_int) - - do t=1,LIS_rc%ntiles(n) - col = LIS_domain(n)%tile(t)%col - row = LIS_domain(n)%tile(t)%row - ensem = LIS_domain(n)%tile(t)%ensem - forcpert(n,k)%forcepert_rseed(i,col,row,ensem) = pertdata1d_int(t) - enddo + if(trim(LIS_rc%perturb_state(k)).ne."none") then + allocate(pertdata1d_patch(LIS_rc%npatch(n,LIS_rc%lsm_index))) + + do i =1, LIS_rc%nstvars(k) + call LIS_readvar_restart(ftn,n,1,pertdata1d_patch) + + do t=1,LIS_rc%npatch(n,LIS_rc%lsm_index) + col = LIS_surface(n,LIS_rc%lsm_index)%tile(t)%col + row = LIS_surface(n,LIS_rc%lsm_index)%tile(t)%row + ensem = LIS_surface(n,LIS_rc%lsm_index)%tile(t)%ensem + progpert(n,k)%progpert_ntrmdt(i,col,row,ensem) = & + pertdata1d_patch(t) + enddo + + enddo + deallocate(pertdata1d_patch) + + allocate(pertdata1d_patch_int(LIS_rc%npatch(n,LIS_rc%lsm_index))) + + do i =1, NRANDSEED + call LIS_readvar_restart(ftn,n,1,pertdata1d_patch_int) + + do t=1,LIS_rc%npatch(n,LIS_rc%lsm_index) + col = LIS_surface(n,LIS_rc%lsm_index)%tile(t)%col + row = LIS_surface(n,LIS_rc%lsm_index)%tile(t)%row + ensem = LIS_surface(n,LIS_rc%lsm_index)%tile(t)%ensem + progpert(n,k)%progpert_rseed(i,col,row,ensem) = & + pertdata1d_patch_int(t) + enddo + + enddo + deallocate(pertdata1d_patch_int) + + endif enddo - deallocate(pertdata1d_int) - else if(LIS_masterproc) then - k = 1 - do i=1,LIS_rc%nforcepert - read(ftn) forcpert(n,k)%forcepert_ntrmdt(i,:,:,:) - enddo - do i=1,NRANDSEED - read(ftn) forcpert(n,k)%forcepert_rseed(i,:,:,:) + do k=1, LIS_rc%nperts + if(trim(LIS_rc%perturb_state(k)).ne."none") then + + do i =1, LIS_rc%nstvars(k) + read(ftn) progPert(n,k)%progpert_ntrmdt(i,:,:,:) + enddo + do i =1, NRANDSEED + read(ftn) progPert(n,k)%progpert_rseed(i,:,:,:) + enddo + endif enddo else ! to keep the binary reading in sync when there is a mix of file reading that -! happens only on one processor and across processors. +! happens only on one processor and across processors. allocate(dummy_var(& LIS_rc%gnc(n),LIS_rc%gnr(n),LIS_rc%nensem(n))) - do i =1, LIS_rc%nforcepert - read(ftn) dummy_var - enddo - do i =1, NRANDSEED - read(ftn) dummy_var + do k=1, LIS_rc%nperts + if(trim(LIS_rc%perturb_state(k)).ne."none") then + + do i =1, LIS_rc%nstvars(k) + read(ftn) dummy_var + enddo + do i =1, NRANDSEED + read(ftn) dummy_var + enddo + endif enddo deallocate(dummy_var) endif - endif - endif - if(.not. p_xyCorr) then - do k=1, LIS_rc%nperts - if(trim(LIS_rc%perturb_state(k)).ne."none") then - allocate(pertdata1d_patch(LIS_rc%npatch(n,LIS_rc%lsm_index))) - - do i =1, LIS_rc%nstvars(k) - call LIS_readvar_restart(ftn,n,1,pertdata1d_patch) - - do t=1,LIS_rc%npatch(n,LIS_rc%lsm_index) - col = LIS_surface(n,LIS_rc%lsm_index)%tile(t)%col - row = LIS_surface(n,LIS_rc%lsm_index)%tile(t)%row - ensem = LIS_surface(n,LIS_rc%lsm_index)%tile(t)%ensem - progpert(n,k)%progpert_ntrmdt(i,col,row,ensem) = & - pertdata1d_patch(t) - enddo - - enddo - deallocate(pertdata1d_patch) - - allocate(pertdata1d_patch_int(LIS_rc%npatch(n,LIS_rc%lsm_index))) + if(.not. o_xyCorr) then + do k=1, LIS_rc%ndas - do i =1, NRANDSEED - call LIS_readvar_restart(ftn,n,1,pertdata1d_patch_int) - - do t=1,LIS_rc%npatch(n,LIS_rc%lsm_index) - col = LIS_surface(n,LIS_rc%lsm_index)%tile(t)%col - row = LIS_surface(n,LIS_rc%lsm_index)%tile(t)%row - ensem = LIS_surface(n,LIS_rc%lsm_index)%tile(t)%ensem - progpert(n,k)%progpert_rseed(i,col,row,ensem) = & - pertdata1d_patch_int(t) - enddo - - enddo - deallocate(pertdata1d_patch_int) + if(trim(LIS_rc%perturb_obs(k)).ne."none") then + allocate(pertdata1d_obs(LIS_rc%obs_ngrid(k)*LIS_rc%nensem(n))) - endif - enddo - else - if(LIS_masterproc) then - do k=1, LIS_rc%nperts - if(trim(LIS_rc%perturb_state(k)).ne."none") then - - do i =1, LIS_rc%nstvars(k) - read(ftn) progPert(n,k)%progpert_ntrmdt(i,:,:,:) + do i=1, nobs(n,k) + call readvar_obspert_restart(ftn,n,k,pertdata1d_obs) + + do t=1,LIS_rc%obs_ngrid(k) + col = LIS_obs_domain(n,k)%col(t) + row = LIS_obs_domain(n,k)%row(t) + do kk=1,LIS_rc%nensem(n) + obspert(n,k)%obspert_ntrmdt(i,col,row,kk) = & + pertdata1d_obs(kk+(t-1)*LIS_rc%nensem(n)) + + enddo + enddo enddo - do i =1, NRANDSEED - read(ftn) progPert(n,k)%progpert_rseed(i,:,:,:) + deallocate(pertdata1d_obs) + + allocate(pertdata1d_obs_int(LIS_rc%obs_ngrid(k)*LIS_rc%nensem(n))) + + + do i=1, NRANDSEED + call readvar_obspert_restart_int(ftn,n,k,pertdata1d_obs_int) + + do t=1,LIS_rc%obs_ngrid(k) + col = LIS_obs_domain(n,k)%col(t) + row = LIS_obs_domain(n,k)%row(t) + do kk=1,LIS_rc%nensem(n) + obspert(n,k)%obspert_rseed(i,col,row,kk) = & + pertdata1d_obs_int(kk+(t-1)*LIS_rc%nensem(n)) + + enddo + enddo enddo endif + deallocate(pertdata1d_obs_int) + enddo else -! to keep the binary reading in sync when there is a mix of file reading that -! happens only on one processor and across processors. - allocate(dummy_var(& - LIS_rc%gnc(n),LIS_rc%gnr(n),LIS_rc%nensem(n))) - do k=1, LIS_rc%nperts - if(trim(LIS_rc%perturb_state(k)).ne."none") then - - do i =1, LIS_rc%nstvars(k) - read(ftn) dummy_var - enddo - do i =1, NRANDSEED - read(ftn) dummy_var - enddo + if(LIS_masterproc) then + do k=1, LIS_rc%ndas + if(trim(LIS_rc%perturb_obs(k)).ne."none") then + do i=1, nobs(n,k) + read(ftn) obsPert(n,k)%obspert_ntrmdt(i,:,:,:) + enddo + do i=1, NRANDSEED + read(ftn) obsPert(n,k)%obspert_rseed(i,:,:,:) + enddo + end if + enddo + else + do k=1, LIS_rc%nperts + allocate(dummy_var(& + LIS_rc%obs_gnc(k),LIS_rc%obs_gnr(k),LIS_rc%nensem(n))) + if(trim(LIS_rc%perturb_obs(k)).ne."none") then + do i =1, nobs(n,k) + read(ftn) dummy_var + enddo + do i =1, NRANDSEED + read(ftn) dummy_var + enddo + endif + deallocate(dummy_var) + + enddo + + endif + endif + + call LIS_releaseUnitNumber(ftn) + write(LIS_logunit,*) '[INFO] Finished reading perturbations restart file ',& + trim(LIS_rc%pertRestartFile(n)) + + enddo + elseif(wformat.eq."distributed binary") then + do n = 1, LIS_rc%nnest + + ftn = LIS_getNextUnitNumber() + + if(LIS_rc%runmode.eq."ensemble smoother") then + if(LIS_rc%iterationid(n).gt.1) then + if(LIS_rc%pertrestartInterval.eq.2592000) then + call ESMF_TimeGet(LIS_twStartTime,yy=yr,mm=mo,& + dd=da,calendar=LIS_calendar,rc=status) + hr = 0 + mn = 0 + ss = 0 + call LIS_tick(time,doy,gmt,yr,mo,da,hr,mn,ss,(-1)*LIS_rc%ts) + else + call ESMF_TimeGet(LIS_twStartTime,yy=yr,mm=mo,& + dd=da,calendar=LIS_calendar,rc=status) + hr = 0 + mn = 0 + ss = 0 endif - enddo - deallocate(dummy_var) + call LIS_create_dapert_filename(n,filen, yr, mo, da, hr, mn, ss) + LIS_rc%pertRestartFile(n) = filen + endif endif - endif - if(.not. o_xyCorr) then - do k=1, LIS_rc%ndas + write(temp1,'(i4.4)') LIS_localPet + read(temp1,fmt='(4a1)') fproc - if(trim(LIS_rc%perturb_obs(k)).ne."none") then - allocate(pertdata1d_obs(LIS_rc%obs_ngrid(k)*LIS_rc%nensem(n))) + open(ftn,file=trim(LIS_rc%pertRestartFile(n))//& + '.'//fproc(1)//fproc(2)//fproc(3)//fproc(4), form='unformatted') + write(LIS_logunit,*) '[INFO] Reading perturbations restart file ',& + trim(LIS_rc%pertRestartFile(n)) - do i=1, nobs(n,k) - call readvar_obspert_restart(ftn,n,k,pertdata1d_obs) + if(LIS_rc%perturb_forcing .ne."none") then + if(.not. f_xyCorr) then + allocate(pertdata1d(LIS_rc%ntiles(n))) - do t=1,LIS_rc%obs_ngrid(k) - col = LIS_obs_domain(n,k)%col(t) - row = LIS_obs_domain(n,k)%row(t) - do kk=1,LIS_rc%nensem(n) - obspert(n,k)%obspert_ntrmdt(i,col,row,kk) = & - pertdata1d_obs(kk+(t-1)*LIS_rc%nensem(n)) - - enddo + k = 1 + do i=1,LIS_rc%nforcepert + + read(ftn) pertdata1d + + do t=1,LIS_rc%ntiles(n) + col = LIS_domain(n)%tile(t)%col + row = LIS_domain(n)%tile(t)%row + ensem = LIS_domain(n)%tile(t)%ensem + forcpert(n,k)%forcepert_ntrmdt(i,col,row,ensem) = pertdata1d(t) enddo enddo - deallocate(pertdata1d_obs) - - allocate(pertdata1d_obs_int(LIS_rc%obs_ngrid(k)*LIS_rc%nensem(n))) - - do i=1, NRANDSEED - call readvar_obspert_restart_int(ftn,n,k,pertdata1d_obs_int) + deallocate(pertdata1d) - do t=1,LIS_rc%obs_ngrid(k) - col = LIS_obs_domain(n,k)%col(t) - row = LIS_obs_domain(n,k)%row(t) - do kk=1,LIS_rc%nensem(n) - obspert(n,k)%obspert_rseed(i,col,row,kk) = & - pertdata1d_obs_int(kk+(t-1)*LIS_rc%nensem(n)) - - enddo + allocate(pertdata1d_int(LIS_rc%ntiles(n))) + + do i=1,NRANDSEED + + read(ftn) pertdata1d_int + + do t=1,LIS_rc%ntiles(n) + col = LIS_domain(n)%tile(t)%col + row = LIS_domain(n)%tile(t)%row + ensem = LIS_domain(n)%tile(t)%ensem + forcpert(n,k)%forcepert_rseed(i,col,row,ensem) = pertdata1d_int(t) enddo enddo + deallocate(pertdata1d_int) + + else + print*, 'Restart read with horizontal correlations not supported ' + print*, 'for distributed binary writing format ' + call LIS_endrun() + endif - deallocate(pertdata1d_obs_int) + endif + if(.not. p_xyCorr) then + do k=1, LIS_rc%nperts + + if(trim(LIS_rc%perturb_state(k)).ne."none") then + allocate(pertdata1d_patch(LIS_rc%npatch(n,LIS_rc%lsm_index))) + + do i =1, LIS_rc%nstvars(k) + + read(ftn) pertdata1d_patch + + do t=1,LIS_rc%npatch(n,LIS_rc%lsm_index) + col = LIS_surface(n,LIS_rc%lsm_index)%tile(t)%col + row = LIS_surface(n,LIS_rc%lsm_index)%tile(t)%row + ensem = LIS_surface(n,LIS_rc%lsm_index)%tile(t)%ensem + progpert(n,k)%progpert_ntrmdt(i,col,row,ensem) = & + pertdata1d_patch(t) + enddo - enddo - else - if(LIS_masterproc) then - do k=1, LIS_rc%ndas - if(trim(LIS_rc%perturb_obs(k)).ne."none") then - do i=1, nobs(n,k) - read(ftn) obsPert(n,k)%obspert_ntrmdt(i,:,:,:) enddo - do i=1, NRANDSEED - read(ftn) obsPert(n,k)%obspert_rseed(i,:,:,:) + deallocate(pertdata1d_patch) + + allocate(pertdata1d_patch_int(LIS_rc%npatch(n,LIS_rc%lsm_index))) + + do i =1, NRANDSEED + + read(ftn) pertdata1d_patch_int + + do t=1,LIS_rc%npatch(n,LIS_rc%lsm_index) + col = LIS_surface(n,LIS_rc%lsm_index)%tile(t)%col + row = LIS_surface(n,LIS_rc%lsm_index)%tile(t)%row + ensem = LIS_surface(n,LIS_rc%lsm_index)%tile(t)%ensem + progpert(n,k)%progpert_rseed(i,col,row,ensem) = & + pertdata1d_patch_int(t) + enddo + enddo - end if + deallocate(pertdata1d_patch_int) + + endif enddo else - do k=1, LIS_rc%nperts - allocate(dummy_var(& - LIS_rc%obs_gnc(k),LIS_rc%obs_gnr(k),LIS_rc%nensem(n))) - if(trim(LIS_rc%perturb_obs(k)).ne."none") then - do i =1, nobs(n,k) - read(ftn) dummy_var + print*, 'Restart read with horizontal correlations not supported ' + print*, 'for distributed binary writing format ' + call LIS_endrun() + + endif + + if(.not. o_xyCorr) then + do k=1, LIS_rc%ndas + + if(trim(LIS_rc%perturb_obs(k)).ne."none") then + allocate(pertdata1d_obs(LIS_rc%obs_ngrid(k)*LIS_rc%nensem(n))) + + do i=1, nobs(n,k) + read(ftn) pertdata1d_obs + + do t=1,LIS_rc%obs_ngrid(k) + col = LIS_obs_domain(n,k)%col(t) + row = LIS_obs_domain(n,k)%row(t) + do kk=1,LIS_rc%nensem(n) + obspert(n,k)%obspert_ntrmdt(i,col,row,kk) = & + pertdata1d_obs(kk+(t-1)*LIS_rc%nensem(n)) + + enddo + enddo enddo - do i =1, NRANDSEED - read(ftn) dummy_var + deallocate(pertdata1d_obs) + + allocate(pertdata1d_obs_int(LIS_rc%obs_ngrid(k)*LIS_rc%nensem(n))) + + + do i=1, NRANDSEED + read(ftn) pertdata1d_obs_int + + do t=1,LIS_rc%obs_ngrid(k) + col = LIS_obs_domain(n,k)%col(t) + row = LIS_obs_domain(n,k)%row(t) + do kk=1,LIS_rc%nensem(n) + obspert(n,k)%obspert_rseed(i,col,row,kk) = & + pertdata1d_obs_int(kk+(t-1)*LIS_rc%nensem(n)) + + enddo + enddo enddo endif - deallocate(dummy_var) + deallocate(pertdata1d_obs_int) enddo - + else + print*, 'Restart read with horizontal correlations not supported ' + print*, 'for distributed binary writing format ' + call LIS_endrun() endif - endif - - call LIS_releaseUnitNumber(ftn) - write(LIS_logunit,*) '[INFO] Finished reading perturbations restart file ',& - trim(LIS_rc%pertRestartFile(n)) - enddo + call LIS_releaseUnitNumber(ftn) + write(LIS_logunit,*) '[INFO] Finished reading perturbations restart file ',& + trim(LIS_rc%pertRestartFile(n)) + + enddo + + endif + end subroutine gmaopert_readrestart !BOP diff --git a/lis/surfacemodels/land/noahmp.4.0.1/NoahMP401_readcrd.F90 b/lis/surfacemodels/land/noahmp.4.0.1/NoahMP401_readcrd.F90 index 9f6ef947d..193e768b7 100644 --- a/lis/surfacemodels/land/noahmp.4.0.1/NoahMP401_readcrd.F90 +++ b/lis/surfacemodels/land/noahmp.4.0.1/NoahMP401_readcrd.F90 @@ -420,9 +420,19 @@ subroutine NoahMP401_readcrd() !------------------------------------------------------------------------------------------ ! set default restart format to netcdf - do n=1,LIS_rc%nnest - NOAHMP401_struc(n)%rformat = "netcdf" - enddo + ! do n=1,LIS_rc%nnest + ! NOAHMP401_struc(n)%rformat = "netcdf" + ! enddo + Call ESMF_ConfigFindLabel(LIS_config, & + "Noah-MP.4.0.1 restart file format:", rc=rc) + do n=1,LIS_rc%nnest + call ESMF_ConfigGetAttribute(LIS_config, NOAHMP401_struc(n)%rformat, rc=rc) + call LIS_verify(rc, & + "Noah-MP.4.0.1 restart file format: not defined") + enddo + + + ! restart run, read restart file if (trim(LIS_rc%startcode) == "restart") then Call ESMF_ConfigFindLabel(LIS_config, & diff --git a/lis/surfacemodels/land/noahmp.4.0.1/NoahMP401_readrst.F90 b/lis/surfacemodels/land/noahmp.4.0.1/NoahMP401_readrst.F90 index 606a12682..3869c576d 100644 --- a/lis/surfacemodels/land/noahmp.4.0.1/NoahMP401_readrst.F90 +++ b/lis/surfacemodels/land/noahmp.4.0.1/NoahMP401_readrst.F90 @@ -24,20 +24,20 @@ ! !INTERFACE: subroutine NoahMP401_readrst() ! !USES: - use LIS_coreMod, only : LIS_rc, LIS_masterproc - use LIS_historyMod, only : LIS_readvar_restart - use LIS_logMod, only : LIS_logunit, LIS_endrun, & - LIS_getNextUnitNumber, & - LIS_releaseUnitNumber, & - LIS_verify - use LIS_constantsMod, only : LIS_CONST_PATH_LEN - use NoahMP401_lsmMod - use ESMF - use LIS_fileIOMod - use LIS_timeMgrMod + use LIS_coreMod + use LIS_constantsMod + use LIS_historyMod, only : LIS_readvar_restart + use LIS_logMod, only : LIS_logunit, LIS_endrun, & + LIS_getNextUnitNumber, & + LIS_releaseUnitNumber, & + LIS_verify + use NoahMP401_lsmMod + use ESMF + use LIS_fileIOMod + use LIS_timeMgrMod #if (defined USE_NETCDF3 || defined USE_NETCDF4) - use netcdf + use netcdf #endif ! @@ -107,347 +107,728 @@ subroutine NoahMP401_readrst() ! \end{description} !EOP - implicit none - - integer :: t, l - integer :: nc, nr, npatch - integer :: n - integer :: ftn - integer :: status - real, allocatable :: tmptilen(:) - logical :: file_exists - character*20 :: wformat - character(len=LIS_CONST_PATH_LEN) :: filen - integer :: yr,mo,da,hr,mn,ss,doy - real*8 :: time - real :: gmt - real :: ts + implicit none + + integer :: t, l + integer :: nc, nr, npatch + integer :: n + integer :: ftn + integer :: status + real, allocatable :: tmptilen(:) + logical :: file_exists + character*20 :: wformat + character(len=LIS_CONST_PATH_LEN) :: filen,rfile + character*4 :: temp1 + character*1 :: fproc(4) + integer :: yr,mo,da,hr,mn,ss,doy + real*8 :: time + real :: gmt + real :: ts + + + do n=1, LIS_rc%nnest + wformat = trim(NOAHMP401_struc(n)%rformat) + call NoahMP401_coldstart(LIS_rc%lsm_index) - - do n=1, LIS_rc%nnest - wformat = trim(NOAHMP401_struc(n)%rformat) - ! coldstart - if(LIS_rc%startcode .eq. "coldstart") then - call NoahMP401_coldstart(LIS_rc%lsm_index) ! restart - elseif(LIS_rc%startcode .eq. "restart") then + if(LIS_rc%startcode .eq. "restart") then !---create restart filename based on timewindow for EnKS - if(LIS_rc%runmode.eq."ensemble smoother") then - if(LIS_rc%iterationId(n).gt.1) then - if(NOAHMP401_struc(n)%rstInterval.eq.2592000) then - !create the restart filename based on the timewindow start time - call ESMF_TimeGet(LIS_twStartTime,yy=yr,mm=mo,& - dd=da,calendar=LIS_calendar,rc=status) - hr = 0 - mn = 0 - ss = 0 - call LIS_tick(time,doy,gmt,yr,mo,da,hr,mn,ss,(-1)*LIS_rc%ts) - else - call ESMF_TimeGet(LIS_twStartTime,yy=yr,mm=mo,& - dd=da,calendar=LIS_calendar,rc=status) - hr = 0 - mn = 0 - ss = 0 - endif - - call LIS_create_restart_filename(n,filen,'SURFACEMODEL','NOAHMP401', & - yr,mo,da,hr,mn,ss, wformat=wformat) - NOAHMP401_struc(n)%rfile = filen - endif - endif - - - allocate(tmptilen(LIS_rc%npatch(n, LIS_rc%lsm_index))) - ! check the existance of restart file - inquire(file=NOAHMP401_struc(n)%rfile, exist=file_exists) - If (.not. file_exists) then - write(LIS_logunit,*) "[ERR] NoahMP401 restart file: ", & - trim(NOAHMP401_struc(n)%rfile) - write(LIS_logunit,*) "[ERR] does not exist." - write(LIS_logunit,*) "[ERR] Program stopping ..." - call LIS_endrun - endif - write(LIS_logunit,*) & - "[INFO] Noah-MP.4.0.1 restart file used: ",trim(NOAHMP401_struc(n)%rfile) - - ! open restart file - if(wformat .eq. "binary") then - ftn = LIS_getNextUnitNumber() - open(ftn, file=NOAHMP401_struc(n)%rfile, & - form="unformatted") - read(ftn) nc, nr, npatch !time, veg class, no. tiles - - ! check for grid space conflict - if((nc .ne. LIS_rc%gnc(n)) .or. (nr .ne. LIS_rc%gnr(n))) then - write(LIS_logunit,*) "[ERR]",trim(NOAHMP401_struc(n)%rfile) - write(LIS_logunit,*) "[ERR] grid space mismatch" - write(LIS_logunit,*) "[ERR] Program stopping..." - call LIS_endrun - endif - - if(npatch .ne. LIS_rc%glbnpatch_red(n, LIS_rc%lsm_index)) then - write(LIS_logunit,*) "[ERR]",trim(NOAHMP401_struc(n)%rfile) - write(LIS_logunit,*) "[ERR] tile space mismatch" - write(LIS_logunit,*) "[ERR] Program stopping..." - call LIS_endrun - endif - elseif(wformat .eq. "netcdf") then + if(LIS_rc%runmode.eq."ensemble smoother") then + if(LIS_rc%iterationId(n).gt.1) then + if(NOAHMP401_struc(n)%rstInterval.eq.2592000) then + !create the restart filename based on the timewindow start time + call ESMF_TimeGet(LIS_twStartTime,yy=yr,mm=mo,& + dd=da,calendar=LIS_calendar,rc=status) + hr = 0 + mn = 0 + ss = 0 + call LIS_tick(time,doy,gmt,yr,mo,da,hr,mn,ss,(-1)*LIS_rc%ts) + else + call ESMF_TimeGet(LIS_twStartTime,yy=yr,mm=mo,& + dd=da,calendar=LIS_calendar,rc=status) + hr = 0 + mn = 0 + ss = 0 + endif + + call LIS_create_restart_filename(n,filen,& + 'SURFACEMODEL','NOAHMP401', & + yr,mo,da,hr,mn,ss, wformat=wformat) + NOAHMP401_struc(n)%rfile = filen + endif + endif + + + allocate(tmptilen(LIS_rc%npatch(n, LIS_rc%lsm_index))) + ! check the existance of restart file + if(wformat.eq."distributed binary") then + write(temp1,'(i4.4)') LIS_localPet + read(temp1,fmt='(4a1)') fproc + + rfile = trim(NOAHMP401_struc(n)%rfile)//& + '.'//fproc(1)//fproc(2)//fproc(3)//fproc(4) + else + rfile = NOAHMP401_struc(n)%rfile + endif + + inquire(file=rfile, exist=file_exists) + If (.not. file_exists) then + write(LIS_logunit,*) "[ERR] NoahMP401 restart file: ", & + trim(rfile) + write(LIS_logunit,*) "[ERR] does not exist." + write(LIS_logunit,*) "[ERR] Program stopping ..." + call LIS_endrun + endif + write(LIS_logunit,*) & + "[INFO] Noah-MP.4.0.1 restart file used: ",trim(rfile) + + ! open restart file + if(wformat .eq. "binary") then + ftn = LIS_getNextUnitNumber() + open(ftn, file=rfile, & + form="unformatted") + read(ftn) nc, nr, npatch !time, veg class, no. tiles + + ! check for grid space conflict + if((nc .ne. LIS_rc%gnc(n)) .or. (nr .ne. LIS_rc%gnr(n))) then + write(LIS_logunit,*) "[ERR]",trim(rfile) + write(LIS_logunit,*) "[ERR] grid space mismatch" + write(LIS_logunit,*) "[ERR] Program stopping..." + call LIS_endrun + endif + + if(npatch .ne. LIS_rc%glbnpatch_red(n, LIS_rc%lsm_index)) then + write(LIS_logunit,*) "[ERR]",trim(rfile) + write(LIS_logunit,*) "[ERR] tile space mismatch" + write(LIS_logunit,*) "[ERR] Program stopping..." + call LIS_endrun + endif + elseif(wformat.eq."distributed binary") then + ftn = LIS_getNextUnitNumber() + open(ftn, file=rfile, & + form="unformatted") + + elseif(wformat .eq. "netcdf") then #if (defined USE_NETCDF3 || defined USE_NETCDF4) - status = nf90_open(path=NOAHMP401_struc(n)%rfile, & - mode=NF90_NOWRITE, ncid=ftn) - call LIS_verify(status, "Error opening file "//NOAHMP401_struc(n)%rfile) + status = nf90_open(path=rfile, & + mode=NF90_NOWRITE, ncid=ftn) + call LIS_verify(status, "Error opening file "//trim(rfile)) #endif - endif - - ! read: accumulated surface runoff - call LIS_readvar_restart(ftn, n, LIS_rc%lsm_index, NOAHMP401_struc(n)%noahmp401%sfcrunoff, & - varname="SFCRUNOFF", wformat=wformat) - - ! read: accumulated sub-surface runoff - call LIS_readvar_restart(ftn, n, LIS_rc%lsm_index, NOAHMP401_struc(n)%noahmp401%udrrunoff, & - varname="UDRRUNOFF", wformat=wformat) - - ! read: volumtric soil moisture - do l=1, NOAHMP401_struc(n)%nsoil ! TODO: check loop - call LIS_readvar_restart(ftn, n, LIS_rc%lsm_index, tmptilen, varname="SMC", & - dim=l, vlevels = NOAHMP401_struc(n)%nsoil, wformat=wformat) - do t=1, LIS_rc%npatch(n, LIS_rc%lsm_index) + endif + + if(wformat.eq."distributed binary") then +! if(LIS_rc%npatch(n, LIS_rc%lsm_index).ne.0) then + read(ftn) tmptilen + do t=1,LIS_rc%npatch(n, LIS_rc%lsm_index) + if(tmptilen(t).ne.LIS_rc%udef) then + NOAHMP401_struc(n)%noahmp401(t)%sfcrunoff = tmptilen(t) + endif + enddo + + read(ftn) tmptilen + do t=1,LIS_rc%npatch(n, LIS_rc%lsm_index) + if(tmptilen(t).ne.LIS_rc%udef) then + NOAHMP401_struc(n)%noahmp401(t)%udrrunoff = tmptilen(t) + endif + enddo + + do l=1, NOAHMP401_struc(n)%nsoil ! TODO: check loop + read(ftn) tmptilen + do t=1, LIS_rc%npatch(n, LIS_rc%lsm_index) + if(tmptilen(t).ne.LIS_rc%udef) then NOAHMP401_struc(n)%noahmp401(t)%smc(l) = tmptilen(t) - enddo - enddo - - ! read: volumtric liquid soil moisture - do l=1, NOAHMP401_struc(n)%nsoil ! TODO: check loop - call LIS_readvar_restart(ftn, n, LIS_rc%lsm_index, tmptilen, varname="SH2O", & - dim=l, vlevels = NOAHMP401_struc(n)%nsoil, wformat=wformat) - do t=1, LIS_rc%npatch(n, LIS_rc%lsm_index) + endif + enddo + enddo + do l=1, NOAHMP401_struc(n)%nsoil ! TODO: check loop + read(ftn) tmptilen + do t=1, LIS_rc%npatch(n, LIS_rc%lsm_index) + if(tmptilen(t).ne.LIS_rc%udef) then NOAHMP401_struc(n)%noahmp401(t)%sh2o(l) = tmptilen(t) - enddo - enddo - - ! read: soil temperature - do l=1, NOAHMP401_struc(n)%nsoil ! TODO: check loop - call LIS_readvar_restart(ftn, n, LIS_rc%lsm_index, tmptilen, varname="TSLB", & - dim=l, vlevels = NOAHMP401_struc(n)%nsoil, wformat=wformat) - do t=1, LIS_rc%npatch(n, LIS_rc%lsm_index) + endif + enddo + enddo + ! soil temperature + do l=1, NOAHMP401_struc(n)%nsoil ! TODO: check loop + read(ftn) tmptilen + do t=1, LIS_rc%npatch(n, LIS_rc%lsm_index) + if(tmptilen(t).ne.LIS_rc%udef) then NOAHMP401_struc(n)%noahmp401(t)%tslb(l) = tmptilen(t) - enddo - enddo - - ! read: snow water equivalent - call LIS_readvar_restart(ftn, n, LIS_rc%lsm_index, NOAHMP401_struc(n)%noahmp401%sneqv, & - varname="SNEQV", wformat=wformat) - - ! read: physical snow depth - call LIS_readvar_restart(ftn, n, LIS_rc%lsm_index, NOAHMP401_struc(n)%noahmp401%snowh, & - varname="SNOWH", wformat=wformat) - - ! read: total canopy water + ice - call LIS_readvar_restart(ftn, n, LIS_rc%lsm_index, NOAHMP401_struc(n)%noahmp401%canwat, & - varname="CANWAT", wformat=wformat) - - ! read: accumulated snow melt leaving pack - call LIS_readvar_restart(ftn, n, LIS_rc%lsm_index, NOAHMP401_struc(n)%noahmp401%acsnom, & - varname="ACSNOM", wformat=wformat) - - ! read: accumulated snow on grid - call LIS_readvar_restart(ftn, n, LIS_rc%lsm_index, NOAHMP401_struc(n)%noahmp401%acsnow, & - varname="ACSNOW", wformat=wformat) - - ! read: actual no. of snow layers - call LIS_readvar_restart(ftn, n, LIS_rc%lsm_index, NOAHMP401_struc(n)%noahmp401%isnow, & - varname="ISNOW", wformat=wformat) - - ! read: vegetation leaf temperature - call LIS_readvar_restart(ftn, n, LIS_rc%lsm_index, NOAHMP401_struc(n)%noahmp401%tv, & - varname="TV", wformat=wformat) - - ! read: bulk ground surface temperature - call LIS_readvar_restart(ftn, n, LIS_rc%lsm_index, NOAHMP401_struc(n)%noahmp401%tg, & - varname="TG", wformat=wformat) - - ! read: canopy-intercepted ice - call LIS_readvar_restart(ftn, n, LIS_rc%lsm_index, NOAHMP401_struc(n)%noahmp401%canice, & - varname="CANICE", wformat=wformat) - - ! read: canopy-intercepted liquid water - call LIS_readvar_restart(ftn, n, LIS_rc%lsm_index, NOAHMP401_struc(n)%noahmp401%canliq, & - varname="CANLIQ", wformat=wformat) - - ! read: canopy air vapor pressure - call LIS_readvar_restart(ftn, n, LIS_rc%lsm_index, NOAHMP401_struc(n)%noahmp401%eah, & - varname="EAH", wformat=wformat) - - ! read: canopy air temperature - call LIS_readvar_restart(ftn, n, LIS_rc%lsm_index, NOAHMP401_struc(n)%noahmp401%tah, & - varname="TAH", wformat=wformat) - - ! read: bulk momentum drag coefficient - call LIS_readvar_restart(ftn, n, LIS_rc%lsm_index, NOAHMP401_struc(n)%noahmp401%cm, & - varname="CM", wformat=wformat) - - ! read: bulk sensible heat exchange coefficient - call LIS_readvar_restart(ftn, n, LIS_rc%lsm_index, NOAHMP401_struc(n)%noahmp401%ch, & - varname="CH", wformat=wformat) - - ! read: wetted or snowed fraction of canopy - call LIS_readvar_restart(ftn, n, LIS_rc%lsm_index, NOAHMP401_struc(n)%noahmp401%fwet, & - varname="FWET", wformat=wformat) - - ! read: snow mass at last time step - call LIS_readvar_restart(ftn, n, LIS_rc%lsm_index, NOAHMP401_struc(n)%noahmp401%sneqvo, & - varname="SNEQVO", wformat=wformat) - - ! read: snow albedo at last time step - call LIS_readvar_restart(ftn, n, LIS_rc%lsm_index, NOAHMP401_struc(n)%noahmp401%albold, & - varname="ALBOLD", wformat=wformat) - - ! read: snowfall on the ground - call LIS_readvar_restart(ftn, n, LIS_rc%lsm_index, NOAHMP401_struc(n)%noahmp401%qsnow, & - varname="QSNOW", wformat=wformat) - - ! read: lake water storage - call LIS_readvar_restart(ftn, n, LIS_rc%lsm_index, NOAHMP401_struc(n)%noahmp401%wslake, & - varname="WSLAKE", wformat=wformat) - - ! read: water table depth - call LIS_readvar_restart(ftn, n, LIS_rc%lsm_index, NOAHMP401_struc(n)%noahmp401%zwt, & - varname="ZWT", wformat=wformat) - - ! read: water in the "aquifer" - call LIS_readvar_restart(ftn, n, LIS_rc%lsm_index, NOAHMP401_struc(n)%noahmp401%wa, & - varname="WA", wformat=wformat) - - ! read: water in aquifer and saturated soil - call LIS_readvar_restart(ftn, n, LIS_rc%lsm_index, NOAHMP401_struc(n)%noahmp401%wt, & - varname="WT", wformat=wformat) - - ! read: snow layer temperature - do l=1, NOAHMP401_struc(n)%nsnow ! TODO: check loop - call LIS_readvar_restart(ftn, n, LIS_rc%lsm_index, tmptilen, varname="TSNO", & - dim=l, vlevels = NOAHMP401_struc(n)%nsnow, wformat=wformat) - do t=1, LIS_rc%npatch(n, LIS_rc%lsm_index) + endif + enddo + enddo + read(ftn) tmptilen + do t=1,LIS_rc%npatch(n, LIS_rc%lsm_index) + if(tmptilen(t).ne.LIS_rc%udef) then + NOAHMP401_struc(n)%noahmp401(t)%sneqv = tmptilen(t) + endif + enddo + + read(ftn) tmptilen + do t=1,LIS_rc%npatch(n, LIS_rc%lsm_index) + if(tmptilen(t).ne.LIS_rc%udef) then + NOAHMP401_struc(n)%noahmp401(t)%snowh = tmptilen(t) + endif + enddo + + read(ftn) tmptilen + do t=1,LIS_rc%npatch(n, LIS_rc%lsm_index) + if(tmptilen(t).ne.LIS_rc%udef) then + NOAHMP401_struc(n)%noahmp401(t)%canwat = tmptilen(t) + endif + enddo + + read(ftn) tmptilen + do t=1,LIS_rc%npatch(n, LIS_rc%lsm_index) + if(tmptilen(t).ne.LIS_rc%udef) then + NOAHMP401_struc(n)%noahmp401(t)%acsnom = tmptilen(t) + endif + enddo + + read(ftn) tmptilen + do t=1,LIS_rc%npatch(n, LIS_rc%lsm_index) + if(tmptilen(t).ne.LIS_rc%udef) then + NOAHMP401_struc(n)%noahmp401(t)%acsnow = tmptilen(t) + endif + enddo + + read(ftn) tmptilen + do t=1, LIS_rc%npatch(n, LIS_rc%lsm_index) + if(tmptilen(t).ne.LIS_rc%udef) then + NOAHMP401_struc(n)%noahmp401(t)%isnow = nint(tmptilen(t)) + endif + enddo + + read(ftn) tmptilen + do t=1,LIS_rc%npatch(n, LIS_rc%lsm_index) + if(tmptilen(t).ne.LIS_rc%udef) then + NOAHMP401_struc(n)%noahmp401(t)%tv = tmptilen(t) + endif + enddo + + read(ftn) tmptilen + do t=1,LIS_rc%npatch(n, LIS_rc%lsm_index) + if(tmptilen(t).ne.LIS_rc%udef) then + NOAHMP401_struc(n)%noahmp401(t)%tg = tmptilen(t) + endif + enddo + + read(ftn) tmptilen + do t=1,LIS_rc%npatch(n, LIS_rc%lsm_index) + if(tmptilen(t).ne.LIS_rc%udef) then + NOAHMP401_struc(n)%noahmp401(t)%canice = tmptilen(t) + endif + enddo + + read(ftn) tmptilen + do t=1,LIS_rc%npatch(n, LIS_rc%lsm_index) + if(tmptilen(t).ne.LIS_rc%udef) then + NOAHMP401_struc(n)%noahmp401(t)%canliq = tmptilen(t) + endif + enddo + + read(ftn) tmptilen + do t=1,LIS_rc%npatch(n, LIS_rc%lsm_index) + if(tmptilen(t).ne.LIS_rc%udef) then + NOAHMP401_struc(n)%noahmp401(t)%eah = tmptilen(t) + endif + enddo + + read(ftn) tmptilen + do t=1,LIS_rc%npatch(n, LIS_rc%lsm_index) + if(tmptilen(t).ne.LIS_rc%udef) then + NOAHMP401_struc(n)%noahmp401(t)%tah = tmptilen(t) + endif + enddo + + read(ftn) tmptilen + do t=1,LIS_rc%npatch(n, LIS_rc%lsm_index) + if(tmptilen(t).ne.LIS_rc%udef) then + NOAHMP401_struc(n)%noahmp401(t)%cm = tmptilen(t) + endif + enddo + + read(ftn) tmptilen + do t=1,LIS_rc%npatch(n, LIS_rc%lsm_index) + if(tmptilen(t).ne.LIS_rc%udef) then + NOAHMP401_struc(n)%noahmp401(t)%ch = tmptilen(t) + endif + enddo + + read(ftn) tmptilen + do t=1,LIS_rc%npatch(n, LIS_rc%lsm_index) + if(tmptilen(t).ne.LIS_rc%udef) then + NOAHMP401_struc(n)%noahmp401(t)%fwet = tmptilen(t) + endif + enddo + + read(ftn) tmptilen + do t=1,LIS_rc%npatch(n, LIS_rc%lsm_index) + if(tmptilen(t).ne.LIS_rc%udef) then + NOAHMP401_struc(n)%noahmp401(t)%sneqvo = tmptilen(t) + endif + enddo + + read(ftn) tmptilen + do t=1,LIS_rc%npatch(n, LIS_rc%lsm_index) + if(tmptilen(t).ne.LIS_rc%udef) then + NOAHMP401_struc(n)%noahmp401(t)%albold = tmptilen(t) + endif + enddo + + read(ftn) tmptilen + do t=1,LIS_rc%npatch(n, LIS_rc%lsm_index) + if(tmptilen(t).ne.LIS_rc%udef) then + NOAHMP401_struc(n)%noahmp401(t)%qsnow = tmptilen(t) + endif + enddo + + read(ftn) tmptilen + do t=1,LIS_rc%npatch(n, LIS_rc%lsm_index) + if(tmptilen(t).ne.LIS_rc%udef) then + NOAHMP401_struc(n)%noahmp401(t)%wslake = tmptilen(t) + endif + enddo + + read(ftn) tmptilen + do t=1,LIS_rc%npatch(n, LIS_rc%lsm_index) + if(tmptilen(t).ne.LIS_rc%udef) then + NOAHMP401_struc(n)%noahmp401(t)%zwt = tmptilen(t) + endif + enddo + + read(ftn) tmptilen + do t=1,LIS_rc%npatch(n, LIS_rc%lsm_index) + if(tmptilen(t).ne.LIS_rc%udef) then + NOAHMP401_struc(n)%noahmp401(t)%wa = tmptilen(t) + endif + enddo + + read(ftn) tmptilen + do t=1,LIS_rc%npatch(n, LIS_rc%lsm_index) + if(tmptilen(t).ne.LIS_rc%udef) then + NOAHMP401_struc(n)%noahmp401(t)%wt = tmptilen(t) + endif + enddo + + ! snow layer temperature + do l=1, NOAHMP401_struc(n)%nsnow ! TODO: check loop + read(ftn) tmptilen + do t=1, LIS_rc%npatch(n, LIS_rc%lsm_index) + if(tmptilen(t).ne.LIS_rc%udef) then NOAHMP401_struc(n)%noahmp401(t)%tsno(l) = tmptilen(t) - enddo - enddo - - ! read: snow/soil layer depth from snow surface - do l=1, NOAHMP401_struc(n)%nsnow + NOAHMP401_struc(n)%nsoil - call LIS_readvar_restart(ftn, n, LIS_rc%lsm_index, tmptilen, varname="ZSS", & - dim=l, vlevels = NOAHMP401_struc(n)%nsnow + NOAHMP401_struc(n)%nsoil, wformat=wformat) - do t=1, LIS_rc%npatch(n, LIS_rc%lsm_index) - NOAHMP401_struc(n)%noahmp401(t)%zss(l) = tmptilen(t) - enddo - enddo - - ! read: snow layer ice - do l=1, NOAHMP401_struc(n)%nsnow ! TODO: check loop - call LIS_readvar_restart(ftn, n, LIS_rc%lsm_index, tmptilen, varname="SNOWICE", & - dim=l, vlevels = NOAHMP401_struc(n)%nsnow, wformat=wformat) - do t=1, LIS_rc%npatch(n, LIS_rc%lsm_index) - NOAHMP401_struc(n)%noahmp401(t)%snowice(l) = tmptilen(t) - enddo - enddo - - ! read: snow layer liquid water - do l=1, NOAHMP401_struc(n)%nsnow ! TODO: check loop - call LIS_readvar_restart(ftn, n, LIS_rc%lsm_index, tmptilen, varname="SNOWLIQ", & - dim=l, vlevels = NOAHMP401_struc(n)%nsnow, wformat=wformat) - do t=1, LIS_rc%npatch(n, LIS_rc%lsm_index) - NOAHMP401_struc(n)%noahmp401(t)%snowliq(l) = tmptilen(t) - enddo - enddo - - ! read: leaf mass - call LIS_readvar_restart(ftn, n, LIS_rc%lsm_index, NOAHMP401_struc(n)%noahmp401%lfmass, & - varname="LFMASS", wformat=wformat) - - ! read: mass of fine roots - call LIS_readvar_restart(ftn, n, LIS_rc%lsm_index, NOAHMP401_struc(n)%noahmp401%rtmass, & - varname="RTMASS", wformat=wformat) - - ! read: stem mass - call LIS_readvar_restart(ftn, n, LIS_rc%lsm_index, NOAHMP401_struc(n)%noahmp401%stmass, & - varname="STMASS", wformat=wformat) - - ! read: mass of wood (including woody roots) - call LIS_readvar_restart(ftn, n, LIS_rc%lsm_index, NOAHMP401_struc(n)%noahmp401%wood, & - varname="WOOD", wformat=wformat) - - ! read: stable carbon in deep soil - call LIS_readvar_restart(ftn, n, LIS_rc%lsm_index, NOAHMP401_struc(n)%noahmp401%stblcp, & - varname="STBLCP", wformat=wformat) - - ! read: short-lived carbon in shallow soil - call LIS_readvar_restart(ftn, n, LIS_rc%lsm_index, NOAHMP401_struc(n)%noahmp401%fastcp, & - varname="FASTCP", wformat=wformat) - - ! read: leaf area index - call LIS_readvar_restart(ftn, n, LIS_rc%lsm_index, NOAHMP401_struc(n)%noahmp401%lai, & - varname="LAI", wformat=wformat) - - ! read: stem area index - call LIS_readvar_restart(ftn, n, LIS_rc%lsm_index, NOAHMP401_struc(n)%noahmp401%sai, & - varname="SAI", wformat=wformat) - - ! read: snow age factor - call LIS_readvar_restart(ftn, n, LIS_rc%lsm_index, NOAHMP401_struc(n)%noahmp401%tauss, & - varname="TAUSS", wformat=wformat) - - ! read: equilibrium volumetric soil moisture content - do l=1, NOAHMP401_struc(n)%nsoil ! TODO: check loop - call LIS_readvar_restart(ftn, n, LIS_rc%lsm_index, tmptilen, varname="SMOISEQ", & - dim=l, vlevels = NOAHMP401_struc(n)%nsoil, wformat=wformat) - do t=1, LIS_rc%npatch(n, LIS_rc%lsm_index) + endif + enddo + enddo + ! snow/soil layer depth from snow surface + do l=1, NOAHMP401_struc(n)%nsnow + NOAHMP401_struc(n)%nsoil + read(ftn) tmptilen + + do t=1, LIS_rc%npatch(n, LIS_rc%lsm_index) + if(tmptilen(t).ne.LIS_rc%udef.and.& + tmptilen(t).ne.0) then + NOAHMP401_struc(n)%noahmp401(t)%zss(l)= tmptilen(t) + endif + enddo + enddo + ! snow layer ice + do l=1, NOAHMP401_struc(n)%nsnow ! TODO: check loop + read(ftn) tmptilen + do t=1, LIS_rc%npatch(n, LIS_rc%lsm_index) + if(tmptilen(t).ne.LIS_rc%udef) then + NOAHMP401_struc(n)%noahmp401(t)%snowice(l)= tmptilen(t) + endif + enddo + enddo + ! snow layer liquid water + do l=1, NOAHMP401_struc(n)%nsnow ! TODO: check loop + read(ftn) tmptilen + do t=1, LIS_rc%npatch(n, LIS_rc%lsm_index) + if(tmptilen(t).ne.LIS_rc%udef) then + NOAHMP401_struc(n)%noahmp401(t)%snowliq(l)= tmptilen(t) + endif + enddo + enddo + + read(ftn) tmptilen + do t=1,LIS_rc%npatch(n, LIS_rc%lsm_index) + if(tmptilen(t).ne.LIS_rc%udef) then + NOAHMP401_struc(n)%noahmp401(t)%lfmass = tmptilen(t) + endif + enddo + + read(ftn) tmptilen + do t=1,LIS_rc%npatch(n, LIS_rc%lsm_index) + if(tmptilen(t).ne.LIS_rc%udef) then + NOAHMP401_struc(n)%noahmp401(t)%rtmass = tmptilen(t) + endif + enddo + + read(ftn) tmptilen + do t=1,LIS_rc%npatch(n, LIS_rc%lsm_index) + if(tmptilen(t).ne.LIS_rc%udef) then + NOAHMP401_struc(n)%noahmp401(t)%stmass = tmptilen(t) + endif + enddo + + read(ftn) tmptilen + do t=1,LIS_rc%npatch(n, LIS_rc%lsm_index) + if(tmptilen(t).ne.LIS_rc%udef) then + NOAHMP401_struc(n)%noahmp401(t)%wood = tmptilen(t) + endif + enddo + + read(ftn) tmptilen + do t=1,LIS_rc%npatch(n, LIS_rc%lsm_index) + if(tmptilen(t).ne.LIS_rc%udef) then + NOAHMP401_struc(n)%noahmp401(t)%stblcp = tmptilen(t) + endif + enddo + + read(ftn) tmptilen + do t=1,LIS_rc%npatch(n, LIS_rc%lsm_index) + if(tmptilen(t).ne.LIS_rc%udef) then + NOAHMP401_struc(n)%noahmp401(t)%fastcp = tmptilen(t) + endif + enddo + + read(ftn) tmptilen + do t=1,LIS_rc%npatch(n, LIS_rc%lsm_index) + if(tmptilen(t).ne.LIS_rc%udef) then + NOAHMP401_struc(n)%noahmp401(t)%lai = tmptilen(t) + endif + enddo + + read(ftn) tmptilen + do t=1,LIS_rc%npatch(n, LIS_rc%lsm_index) + if(tmptilen(t).ne.LIS_rc%udef) then + NOAHMP401_struc(n)%noahmp401(t)%sai = tmptilen(t) + endif + enddo + + read(ftn) tmptilen + do t=1,LIS_rc%npatch(n, LIS_rc%lsm_index) + if(tmptilen(t).ne.LIS_rc%udef) then + NOAHMP401_struc(n)%noahmp401(t)%tauss = tmptilen(t) + endif + enddo + + ! equilibrium volumetric soil moisture content + do l=1, NOAHMP401_struc(n)%nsoil ! TODO: check loop + read(ftn) tmptilen + do t=1, LIS_rc%npatch(n, LIS_rc%lsm_index) + if(tmptilen(t).ne.LIS_rc%udef) then NOAHMP401_struc(n)%noahmp401(t)%smoiseq(l) = tmptilen(t) - enddo - enddo - - ! read: soil moisture content in the layer to the water table when deep - call LIS_readvar_restart(ftn, n, LIS_rc%lsm_index, NOAHMP401_struc(n)%noahmp401%smcwtd, & - varname="SMCWTD", wformat=wformat) - - ! read: recharge to the water table when deep - call LIS_readvar_restart(ftn, n, LIS_rc%lsm_index, NOAHMP401_struc(n)%noahmp401%deeprech, & - varname="DEEPRECH", wformat=wformat) - - ! read: recharge to the water table (diagnostic) - call LIS_readvar_restart(ftn, n, LIS_rc%lsm_index, NOAHMP401_struc(n)%noahmp401%rech, & - varname="RECH", wformat=wformat) - - ! read: mass of grain XING - call LIS_readvar_restart(ftn, n, LIS_rc%lsm_index, NOAHMP401_struc(n)%noahmp401%grain, & - varname="GRAIN", wformat=wformat) - - ! read: growing degree days XING (based on 10C) - call LIS_readvar_restart(ftn, n, LIS_rc%lsm_index, NOAHMP401_struc(n)%noahmp401%gdd, & - varname="GDD", wformat=wformat) - - ! read: growing degree days XING - call LIS_readvar_restart(ftn, n, LIS_rc%lsm_index, NOAHMP401_struc(n)%noahmp401%pgs, & - varname="PGS", wformat=wformat) - - ! read: optional gecros crop -! do l=1, 60 ! TODO: check loop -! call LIS_readvar_restart(ftn, n, LIS_rc%lsm_index, tmptilen, varname="GECROS_STATE", & -! dim=l, vlevels = 60, wformat=wformat) -! do t=1, LIS_rc%npatch(n, LIS_rc%lsm_index) -! NOAHMP401_struc(n)%noahmp401(t)%gecros_state(l) = tmptilen(t) -! enddo -! enddo - - ! close restart file - if(wformat .eq. "binary") then - call LIS_releaseUnitNumber(ftn) - elseif(wformat .eq. "netcdf") then + endif + enddo + enddo + + read(ftn) tmptilen + do t=1,LIS_rc%npatch(n, LIS_rc%lsm_index) + if(tmptilen(t).ne.LIS_rc%udef) then + NOAHMP401_struc(n)%noahmp401(t)%smcwtd = tmptilen(t) + endif + enddo + + read(ftn) tmptilen + do t=1,LIS_rc%npatch(n, LIS_rc%lsm_index) + if(tmptilen(t).ne.LIS_rc%udef) then + NOAHMP401_struc(n)%noahmp401(t)%deeprech = tmptilen(t) + endif + enddo + + read(ftn) tmptilen + do t=1,LIS_rc%npatch(n, LIS_rc%lsm_index) + if(tmptilen(t).ne.LIS_rc%udef) then + NOAHMP401_struc(n)%noahmp401(t)%rech = tmptilen(t) + endif + enddo + + read(ftn) tmptilen + do t=1,LIS_rc%npatch(n, LIS_rc%lsm_index) + if(tmptilen(t).ne.LIS_rc%udef) then + NOAHMP401_struc(n)%noahmp401(t)%grain = tmptilen(t) + endif + enddo + + read(ftn) tmptilen + do t=1,LIS_rc%npatch(n, LIS_rc%lsm_index) + if(tmptilen(t).ne.LIS_rc%udef) then + NOAHMP401_struc(n)%noahmp401(t)%gdd = tmptilen(t) + endif + enddo + + read(ftn) tmptilen + do t=1, LIS_rc%npatch(n, LIS_rc%lsm_index) + if(tmptilen(t).ne.LIS_rc%udef) then + NOAHMP401_struc(n)%noahmp401(t)%pgs = nint(tmptilen(t)) + endif + enddo + +! do l=1, 60 ! TODO: check loop +! read(ftn) tmptilen +! do t=1, LIS_rc%npatch(n, LIS_rc%lsm_index) +! if(tmptilen(t).ne.LIS_rc%udef) then +! NOAHMP401_struc(n)%noahmp401(t)%gecros_state(l)= tmptilen(t!) +! endif +! enddo +! enddo +! endif + else + ! read: accumulated surface runoff + call LIS_readvar_restart(ftn, n, LIS_rc%lsm_index, NOAHMP401_struc(n)%noahmp401%sfcrunoff, & + varname="SFCRUNOFF", wformat=wformat) + + ! read: accumulated sub-surface runoff + call LIS_readvar_restart(ftn, n, LIS_rc%lsm_index, NOAHMP401_struc(n)%noahmp401%udrrunoff, & + varname="UDRRUNOFF", wformat=wformat) + + ! read: volumtric soil moisture + do l=1, NOAHMP401_struc(n)%nsoil ! TODO: check loop + call LIS_readvar_restart(ftn, n, LIS_rc%lsm_index, tmptilen, varname="SMC", & + dim=l, vlevels = NOAHMP401_struc(n)%nsoil, wformat=wformat) + do t=1, LIS_rc%npatch(n, LIS_rc%lsm_index) + NOAHMP401_struc(n)%noahmp401(t)%smc(l) = tmptilen(t) + enddo + enddo + + ! read: volumtric liquid soil moisture + do l=1, NOAHMP401_struc(n)%nsoil ! TODO: check loop + call LIS_readvar_restart(ftn, n, LIS_rc%lsm_index, tmptilen, varname="SH2O", & + dim=l, vlevels = NOAHMP401_struc(n)%nsoil, wformat=wformat) + do t=1, LIS_rc%npatch(n, LIS_rc%lsm_index) + NOAHMP401_struc(n)%noahmp401(t)%sh2o(l) = tmptilen(t) + enddo + enddo + + ! read: soil temperature + do l=1, NOAHMP401_struc(n)%nsoil ! TODO: check loop + call LIS_readvar_restart(ftn, n, LIS_rc%lsm_index, tmptilen, varname="TSLB", & + dim=l, vlevels = NOAHMP401_struc(n)%nsoil, wformat=wformat) + do t=1, LIS_rc%npatch(n, LIS_rc%lsm_index) + NOAHMP401_struc(n)%noahmp401(t)%tslb(l) = tmptilen(t) + enddo + enddo + + ! read: snow water equivalent + call LIS_readvar_restart(ftn, n, LIS_rc%lsm_index, NOAHMP401_struc(n)%noahmp401%sneqv, & + varname="SNEQV", wformat=wformat) + + ! read: physical snow depth + call LIS_readvar_restart(ftn, n, LIS_rc%lsm_index, NOAHMP401_struc(n)%noahmp401%snowh, & + varname="SNOWH", wformat=wformat) + + ! read: total canopy water + ice + call LIS_readvar_restart(ftn, n, LIS_rc%lsm_index, NOAHMP401_struc(n)%noahmp401%canwat, & + varname="CANWAT", wformat=wformat) + + ! read: accumulated snow melt leaving pack + call LIS_readvar_restart(ftn, n, LIS_rc%lsm_index, NOAHMP401_struc(n)%noahmp401%acsnom, & + varname="ACSNOM", wformat=wformat) + + ! read: accumulated snow on grid + call LIS_readvar_restart(ftn, n, LIS_rc%lsm_index, NOAHMP401_struc(n)%noahmp401%acsnow, & + varname="ACSNOW", wformat=wformat) + + ! read: actual no. of snow layers + call LIS_readvar_restart(ftn, n, LIS_rc%lsm_index, NOAHMP401_struc(n)%noahmp401%isnow, & + varname="ISNOW", wformat=wformat) + + ! read: vegetation leaf temperature + call LIS_readvar_restart(ftn, n, LIS_rc%lsm_index, NOAHMP401_struc(n)%noahmp401%tv, & + varname="TV", wformat=wformat) + + ! read: bulk ground surface temperature + call LIS_readvar_restart(ftn, n, LIS_rc%lsm_index, NOAHMP401_struc(n)%noahmp401%tg, & + varname="TG", wformat=wformat) + + ! read: canopy-intercepted ice + call LIS_readvar_restart(ftn, n, LIS_rc%lsm_index, NOAHMP401_struc(n)%noahmp401%canice, & + varname="CANICE", wformat=wformat) + + ! read: canopy-intercepted liquid water + call LIS_readvar_restart(ftn, n, LIS_rc%lsm_index, NOAHMP401_struc(n)%noahmp401%canliq, & + varname="CANLIQ", wformat=wformat) + + ! read: canopy air vapor pressure + call LIS_readvar_restart(ftn, n, LIS_rc%lsm_index, NOAHMP401_struc(n)%noahmp401%eah, & + varname="EAH", wformat=wformat) + + ! read: canopy air temperature + call LIS_readvar_restart(ftn, n, LIS_rc%lsm_index, NOAHMP401_struc(n)%noahmp401%tah, & + varname="TAH", wformat=wformat) + + ! read: bulk momentum drag coefficient + call LIS_readvar_restart(ftn, n, LIS_rc%lsm_index, NOAHMP401_struc(n)%noahmp401%cm, & + varname="CM", wformat=wformat) + + ! read: bulk sensible heat exchange coefficient + call LIS_readvar_restart(ftn, n, LIS_rc%lsm_index, NOAHMP401_struc(n)%noahmp401%ch, & + varname="CH", wformat=wformat) + + ! read: wetted or snowed fraction of canopy + call LIS_readvar_restart(ftn, n, LIS_rc%lsm_index, NOAHMP401_struc(n)%noahmp401%fwet, & + varname="FWET", wformat=wformat) + + ! read: snow mass at last time step + call LIS_readvar_restart(ftn, n, LIS_rc%lsm_index, NOAHMP401_struc(n)%noahmp401%sneqvo, & + varname="SNEQVO", wformat=wformat) + + ! read: snow albedo at last time step + call LIS_readvar_restart(ftn, n, LIS_rc%lsm_index, NOAHMP401_struc(n)%noahmp401%albold, & + varname="ALBOLD", wformat=wformat) + + ! read: snowfall on the ground + call LIS_readvar_restart(ftn, n, LIS_rc%lsm_index, NOAHMP401_struc(n)%noahmp401%qsnow, & + varname="QSNOW", wformat=wformat) + + ! read: lake water storage + call LIS_readvar_restart(ftn, n, LIS_rc%lsm_index, NOAHMP401_struc(n)%noahmp401%wslake, & + varname="WSLAKE", wformat=wformat) + + ! read: water table depth + call LIS_readvar_restart(ftn, n, LIS_rc%lsm_index, NOAHMP401_struc(n)%noahmp401%zwt, & + varname="ZWT", wformat=wformat) + + ! read: water in the "aquifer" + call LIS_readvar_restart(ftn, n, LIS_rc%lsm_index, NOAHMP401_struc(n)%noahmp401%wa, & + varname="WA", wformat=wformat) + + ! read: water in aquifer and saturated soil + call LIS_readvar_restart(ftn, n, LIS_rc%lsm_index, NOAHMP401_struc(n)%noahmp401%wt, & + varname="WT", wformat=wformat) + + ! read: snow layer temperature + do l=1, NOAHMP401_struc(n)%nsnow ! TODO: check loop + call LIS_readvar_restart(ftn, n, LIS_rc%lsm_index, tmptilen, varname="TSNO", & + dim=l, vlevels = NOAHMP401_struc(n)%nsnow, wformat=wformat) + do t=1, LIS_rc%npatch(n, LIS_rc%lsm_index) + NOAHMP401_struc(n)%noahmp401(t)%tsno(l) = tmptilen(t) + enddo + enddo + + ! read: snow/soil layer depth from snow surface + do l=1, NOAHMP401_struc(n)%nsnow + NOAHMP401_struc(n)%nsoil + call LIS_readvar_restart(ftn, n, LIS_rc%lsm_index, tmptilen, varname="ZSS", & + dim=l, vlevels = NOAHMP401_struc(n)%nsnow + NOAHMP401_struc(n)%nsoil, wformat=wformat) + do t=1, LIS_rc%npatch(n, LIS_rc%lsm_index) + if(tmptilen(t).ne.0) then + NOAHMP401_struc(n)%noahmp401(t)%zss(l) = tmptilen(t) + endif + enddo + enddo + + ! read: snow layer ice + do l=1, NOAHMP401_struc(n)%nsnow ! TODO: check loop + call LIS_readvar_restart(ftn, n, LIS_rc%lsm_index, tmptilen, varname="SNOWICE", & + dim=l, vlevels = NOAHMP401_struc(n)%nsnow, wformat=wformat) + do t=1, LIS_rc%npatch(n, LIS_rc%lsm_index) + NOAHMP401_struc(n)%noahmp401(t)%snowice(l) = tmptilen(t) + enddo + enddo + + ! read: snow layer liquid water + do l=1, NOAHMP401_struc(n)%nsnow ! TODO: check loop + call LIS_readvar_restart(ftn, n, LIS_rc%lsm_index, tmptilen, varname="SNOWLIQ", & + dim=l, vlevels = NOAHMP401_struc(n)%nsnow, wformat=wformat) + do t=1, LIS_rc%npatch(n, LIS_rc%lsm_index) + NOAHMP401_struc(n)%noahmp401(t)%snowliq(l) = tmptilen(t) + enddo + enddo + + ! read: leaf mass + call LIS_readvar_restart(ftn, n, LIS_rc%lsm_index, NOAHMP401_struc(n)%noahmp401%lfmass, & + varname="LFMASS", wformat=wformat) + + ! read: mass of fine roots + call LIS_readvar_restart(ftn, n, LIS_rc%lsm_index, NOAHMP401_struc(n)%noahmp401%rtmass, & + varname="RTMASS", wformat=wformat) + + ! read: stem mass + call LIS_readvar_restart(ftn, n, LIS_rc%lsm_index, NOAHMP401_struc(n)%noahmp401%stmass, & + varname="STMASS", wformat=wformat) + + ! read: mass of wood (including woody roots) + call LIS_readvar_restart(ftn, n, LIS_rc%lsm_index, NOAHMP401_struc(n)%noahmp401%wood, & + varname="WOOD", wformat=wformat) + + ! read: stable carbon in deep soil + call LIS_readvar_restart(ftn, n, LIS_rc%lsm_index, NOAHMP401_struc(n)%noahmp401%stblcp, & + varname="STBLCP", wformat=wformat) + + ! read: short-lived carbon in shallow soil + call LIS_readvar_restart(ftn, n, LIS_rc%lsm_index, NOAHMP401_struc(n)%noahmp401%fastcp, & + varname="FASTCP", wformat=wformat) + + ! read: leaf area index + call LIS_readvar_restart(ftn, n, LIS_rc%lsm_index, NOAHMP401_struc(n)%noahmp401%lai, & + varname="LAI", wformat=wformat) + + ! read: stem area index + call LIS_readvar_restart(ftn, n, LIS_rc%lsm_index, NOAHMP401_struc(n)%noahmp401%sai, & + varname="SAI", wformat=wformat) + + ! read: snow age factor + call LIS_readvar_restart(ftn, n, LIS_rc%lsm_index, NOAHMP401_struc(n)%noahmp401%tauss, & + varname="TAUSS", wformat=wformat) + + ! read: equilibrium volumetric soil moisture content + do l=1, NOAHMP401_struc(n)%nsoil ! TODO: check loop + call LIS_readvar_restart(ftn, n, LIS_rc%lsm_index, tmptilen, varname="SMOISEQ", & + dim=l, vlevels = NOAHMP401_struc(n)%nsoil, wformat=wformat) + do t=1, LIS_rc%npatch(n, LIS_rc%lsm_index) + NOAHMP401_struc(n)%noahmp401(t)%smoiseq(l) = tmptilen(t) + enddo + enddo + + ! read: soil moisture content in the layer to the water table when deep + call LIS_readvar_restart(ftn, n, LIS_rc%lsm_index, NOAHMP401_struc(n)%noahmp401%smcwtd, & + varname="SMCWTD", wformat=wformat) + + ! read: recharge to the water table when deep + call LIS_readvar_restart(ftn, n, LIS_rc%lsm_index, NOAHMP401_struc(n)%noahmp401%deeprech, & + varname="DEEPRECH", wformat=wformat) + + ! read: recharge to the water table (diagnostic) + call LIS_readvar_restart(ftn, n, LIS_rc%lsm_index, NOAHMP401_struc(n)%noahmp401%rech, & + varname="RECH", wformat=wformat) + + ! read: mass of grain XING + call LIS_readvar_restart(ftn, n, LIS_rc%lsm_index, NOAHMP401_struc(n)%noahmp401%grain, & + varname="GRAIN", wformat=wformat) + + ! read: growing degree days XING (based on 10C) + call LIS_readvar_restart(ftn, n, LIS_rc%lsm_index, NOAHMP401_struc(n)%noahmp401%gdd, & + varname="GDD", wformat=wformat) + + ! read: growing degree days XING + call LIS_readvar_restart(ftn, n, LIS_rc%lsm_index, NOAHMP401_struc(n)%noahmp401%pgs, & + varname="PGS", wformat=wformat) + + ! read: optional gecros crop +! do l=1, 60 ! TODO: check loop +! call LIS_readvar_restart(ftn, n, LIS_rc%lsm_index, tmptilen, varname="GECROS_STATE", & +! dim=l, vlevels = 60, wformat=wformat) +! do t=1, LIS_rc%npatch(n, LIS_rc%lsm_index) +! NOAHMP401_struc(n)%noahmp401(t)%gecros_state(l) = tmptilen(t) +! enddo +! enddo + endif + ! close restart file + if(wformat .eq. "binary") then + call LIS_releaseUnitNumber(ftn) + elseif(wformat .eq. "netcdf") then #if (defined USE_NETCDF3 || defined USE_NETCDF4) - status = nf90_close(ftn) - call LIS_verify(status, & - "Error in nf90_close in NoahMP401_readrst") + status = nf90_close(ftn) + call LIS_verify(status, & + "Error in nf90_close in NoahMP401_readrst") #endif - endif - deallocate(tmptilen) - endif - enddo + elseif(wformat.eq."distributed binary") then + call LIS_releaseUnitNumber(ftn) + + endif + deallocate(tmptilen) + endif + enddo end subroutine NoahMP401_readrst - + diff --git a/lis/surfacemodels/land/noahmp.4.0.1/NoahMP401_writerst.F90 b/lis/surfacemodels/land/noahmp.4.0.1/NoahMP401_writerst.F90 index 66dce6a26..d76c16708 100644 --- a/lis/surfacemodels/land/noahmp.4.0.1/NoahMP401_writerst.F90 +++ b/lis/surfacemodels/land/noahmp.4.0.1/NoahMP401_writerst.F90 @@ -23,7 +23,7 @@ ! !INTERFACE: subroutine NoahMP401_writerst(n) ! !USES: - use LIS_coreMod, only : LIS_rc, LIS_masterproc + use LIS_coreMod use LIS_timeMgrMod, only : LIS_isAlarmRinging use LIS_logMod, only : LIS_logunit, LIS_getNextUnitNumber, & LIS_releaseUnitNumber , LIS_verify @@ -55,7 +55,9 @@ subroutine NoahMP401_writerst(n) ! \end{description} !EOP - character(len=LIS_CONST_PATH_LEN) :: filen + character(len=LIS_CONST_PATH_LEN) :: filen,filenp + character*4 :: temp1 + character*1 :: fproc(4) character*20 :: wformat logical :: alarmCheck integer :: ftn @@ -66,47 +68,300 @@ subroutine NoahMP401_writerst(n) ! set restart file format (read from LIS configration file_ wformat = trim(NOAHMP401_struc(n)%rformat) - + if(alarmCheck .or. (LIS_rc%endtime ==1)) then - If (LIS_masterproc) Then - call LIS_create_output_directory("SURFACEMODEL") - call LIS_create_restart_filename(n, filen, "SURFACEMODEL", & - "NOAHMP401",wformat=wformat) - if(wformat .eq. "binary") then - ftn = LIS_getNextUnitNumber() - open(ftn,file=filen,status="unknown", form="unformatted") - elseif(wformat .eq. "netcdf") then + call LIS_create_output_directory("SURFACEMODEL") + call LIS_create_restart_filename(n, filen, "SURFACEMODEL", & + "NOAHMP401",wformat=wformat) + if(wformat .eq. "binary") then + if(LIS_masterproc) then + ftn = LIS_getNextUnitNumber() + open(ftn,file=filen,status="unknown", form="unformatted") + endif + elseif(wformat .eq. "netcdf") then + if(LIS_masterproc) then #if (defined USE_NETCDF4) - status = nf90_create(path=filen, cmode=nf90_hdf5, ncid = ftn) - call LIS_verify(status, & - "Error in nf90_open in NoahMP401_writerst") + status = nf90_create(path=filen, cmode=nf90_hdf5, ncid = ftn) + call LIS_verify(status, & + "Error in nf90_open in NoahMP401_writerst") #endif #if (defined USE_NETCDF3) - status = nf90_create(Path = filen, cmode = nf90_clobber, ncid = ftn) - call LIS_verify(status, & - "Error in nf90_open in NoahMP401_writerst") + status = nf90_create(Path = filen, cmode = nf90_clobber, ncid = ftn) + call LIS_verify(status, & + "Error in nf90_open in NoahMP401_writerst") #endif - endif - endif - - call NoahMP401_dump_restart(n, ftn, wformat) - - if (LIS_masterproc) then - if(wformat .eq. "binary") then - call LIS_releaseUnitNumber(ftn) - elseif(wformat .eq. "netcdf") then + endif + elseif(wformat.eq."distributed binary") then + ftn = LIS_getNextUnitNumber() + + write(temp1,'(i4.4)') LIS_localPet + read(temp1,fmt='(4a1)') fproc + + filenp = trim(filen)//'.'//fproc(1)//fproc(2)//fproc(3)//fproc(4) + open(ftn,file=trim(filenp),& + form='unformatted') + endif + + if(wformat.eq."distributed binary") then + call NoahMP401_dump_restart_dist(n, ftn, wformat) + else + call NoahMP401_dump_restart(n, ftn, wformat) + endif + + if(wformat .eq. "binary") then + if (LIS_masterproc) then + call LIS_releaseUnitNumber(ftn) + endif + elseif(wformat.eq."distributed binary") then + call LIS_releaseUnitNumber(ftn) + elseif(wformat .eq. "netcdf") then + if(LIS_masterproc) then #if (defined USE_NETCDF3 || defined USE_NETCDF4) - status = nf90_close(ftn) - call LIS_verify(status, & - "Error in nf90_close in NoahMP401_writerst") + status = nf90_close(ftn) + call LIS_verify(status, & + "Error in nf90_close in NoahMP401_writerst") #endif - endif - write(LIS_logunit, *)& - "[INFO] Noah-MP.4.0.1 archive restart written: ",trim(filen) - endif + write(LIS_logunit, *)& + "[INFO] Noah-MP.4.0.1 archive restart written: ",trim(filen) + endif + endif endif end subroutine NoahMP401_writerst +!BOP +! +! !ROUTINE: NoahMP401_dump_restart_dist +! \label{NoahMP401_dump_restart_dist} +! +! !REVISION HISTORY: +! This subroutine is generated with the Model Implementation Toolkit developed +! by Shugong Wang for the NASA Land Information System Version 7. The initial +! specification of the subroutine is defined by Sujay Kumar. +! 10/25/18: Shugong Wang, Zhuo Wang, initial implementation for LIS 7 and NoahMP401 +! !INTERFACE: +subroutine NoahMP401_dump_restart_dist(n, ftn, wformat) + +! !USES: + use LIS_coreMod + use LIS_logMod, only : LIS_logunit + use LIS_historyMod + use NoahMP401_lsmMod + + implicit none + + integer, intent(in) :: ftn + integer, intent(in) :: n + character(len=*), intent(in) :: wformat +! +! !DESCRIPTION: +! This routine gathers the necessary restart variables and performs +! the actual write statements to create the restart files. +! +! The arguments are: +! \begin{description} +! \item[n] +! index of the nest +! \item[ftn] +! unit number for the restart file +! \item[wformat] +! restart file format (binary/netcdf) +! \end{description} +! +! +! The following is the list of variables written in the NoahMP401 +! restart file: +! \begin{verbatim} +! nc, nr, ntiles - grid and tile space dimensions +! sfcrunoff - NoahMP401 accumulated surface runoff [m] +! udrrunoff - NoahMP401 accumulated sub-surface runoff [m] +! smc - NoahMP401 volumtric soil moisture [m3/m3] +! sh2o - NoahMP401 volumtric liquid soil moisture [m3/m3] +! tslb - NoahMP401 soil temperature [K] +! sneqv - NoahMP401 snow water equivalent [mm] +! snowh - NoahMP401 physical snow depth [m] +! canwat - NoahMP401 total canopy water + ice [mm] +! acsnom - NoahMP401 accumulated snow melt leaving pack [-] +! acsnow - NoahMP401 accumulated snow on grid [mm] +! isnow - NoahMP401 actual no. of snow layers [-] +! tv - NoahMP401 vegetation leaf temperature [K] +! tg - NoahMP401 bulk ground surface temperature [K] +! canice - NoahMP401 canopy-intercepted ice [mm] +! canliq - NoahMP401 canopy-intercepted liquid water [mm] +! eah - NoahMP401 canopy air vapor pressure [Pa] +! tah - NoahMP401 canopy air temperature [K] +! cm - NoahMP401 bulk momentum drag coefficient [-] +! ch - NoahMP401 bulk sensible heat exchange coefficient [-] +! fwet - NoahMP401 wetted or snowed fraction of canopy [-] +! sneqvo - NoahMP401 snow mass at last time step [mm h2o] +! albold - NoahMP401 snow albedo at last time step [-] +! qsnow - NoahMP401 snowfall on the ground [mm/s] +! wslake - NoahMP401 lake water storage [mm] +! zwt - NoahMP401 water table depth [m] +! wa - NoahMP401 water in the "aquifer" [mm] +! wt - NoahMP401 water in aquifer and saturated soil [mm] +! tsno - NoahMP401 snow layer temperature [K] +! zss - NoahMP401 snow/soil layer depth from snow surface [m] +! snowice - NoahMP401 snow layer ice [mm] +! snowliq - NoahMP401 snow layer liquid water [mm] +! lfmass - NoahMP401 leaf mass [g/m2] +! rtmass - NoahMP401 mass of fine roots [g/m2] +! stmass - NoahMP401 stem mass [g/m2] +! wood - NoahMP401 mass of wood (including woody roots) [g/m2] +! stblcp - NoahMP401 stable carbon in deep soil [g/m2] +! fastcp - NoahMP401 short-lived carbon in shallow soil [g/m2] +! lai - NoahMP401 leaf area index [-] +! sai - NoahMP401 stem area index [-] +! tauss - NoahMP401 snow age factor [-] +! smoiseq - NoahMP401 equilibrium volumetric soil moisture content [m3/m3] +! smcwtd - NoahMP401 soil moisture content in the layer to the water table when deep [-] +! deeprech - NoahMP401 recharge to the water table when deep [-] +! rech - NoahMP401 recharge to the water table (diagnostic) [-] +! grain - NoahMP401 mass of grain XING [g/m2] +! gdd - NoahMP401 growing degree days XING (based on 10C) [-] +! pgs - NoahMP401 growing degree days XING [-] +! gecros_state - NoahMP401 optional gecros crop [-] +! \end{verbatim} +! +! The routines invoked are: +! \begin{description} +! \item[LIS\_writeGlobalHeader\_restart](\ref{LIS_writeGlobalHeader_restart})\\ +! writes the global header information +! \item[LIS\_writeHeader\_restart](\ref{LIS_writeHeader_restart})\\ +! writes the header information for a variable +! \item[LIS\_closeHeader\_restart](\ref{LIS_closeHeader_restart})\\ +! close the header +! \item[LIS\_writevar\_restart](\ref{LIS_writevar_restart})\\ +! writes a variable to the restart file +! \end{description} +! +!EOP + + integer :: l, t + real :: tmptilen(LIS_rc%npatch(n, LIS_rc%lsm_index)) + + write(ftn) NOAHMP401_struc(n)%noahmp401%sfcrunoff + write(ftn) NOAHMP401_struc(n)%noahmp401%udrrunoff + + do l=1, NOAHMP401_struc(n)%nsoil ! TODO: check loop + tmptilen = 0 + do t=1, LIS_rc%npatch(n, LIS_rc%lsm_index) + tmptilen(t) = NOAHMP401_struc(n)%noahmp401(t)%smc(l) + enddo + write(ftn) tmptilen + enddo + do l=1, NOAHMP401_struc(n)%nsoil ! TODO: check loop + tmptilen = 0 + do t=1, LIS_rc%npatch(n, LIS_rc%lsm_index) + tmptilen(t) = NOAHMP401_struc(n)%noahmp401(t)%sh2o(l) + enddo + write(ftn) tmptilen + enddo + ! soil temperature + do l=1, NOAHMP401_struc(n)%nsoil ! TODO: check loop + tmptilen = 0 + do t=1, LIS_rc%npatch(n, LIS_rc%lsm_index) + tmptilen(t) = NOAHMP401_struc(n)%noahmp401(t)%tslb(l) + enddo + write(ftn) tmptilen + enddo + write(ftn) NOAHMP401_struc(n)%noahmp401%sneqv + write(ftn) NOAHMP401_struc(n)%noahmp401%snowh + write(ftn) NOAHMP401_struc(n)%noahmp401%canwat + write(ftn) NOAHMP401_struc(n)%noahmp401%acsnom + write(ftn) NOAHMP401_struc(n)%noahmp401%acsnow + tmptilen = 0 + do t=1, LIS_rc%npatch(n, LIS_rc%lsm_index) + tmptilen(t) = NOAHMP401_struc(n)%noahmp401(t)%isnow + enddo + write(ftn) tmptilen + write(ftn) NOAHMP401_struc(n)%noahmp401%tv + write(ftn) NOAHMP401_struc(n)%noahmp401%tg + write(ftn) NOAHMP401_struc(n)%noahmp401%canice + write(ftn) NOAHMP401_struc(n)%noahmp401%canliq + write(ftn) NOAHMP401_struc(n)%noahmp401%eah + write(ftn) NOAHMP401_struc(n)%noahmp401%tah + write(ftn) NOAHMP401_struc(n)%noahmp401%cm + write(ftn) NOAHMP401_struc(n)%noahmp401%ch + write(ftn) NOAHMP401_struc(n)%noahmp401%fwet + write(ftn) NOAHMP401_struc(n)%noahmp401%sneqvo + write(ftn) NOAHMP401_struc(n)%noahmp401%albold + write(ftn) NOAHMP401_struc(n)%noahmp401%qsnow + write(ftn) NOAHMP401_struc(n)%noahmp401%wslake + write(ftn) NOAHMP401_struc(n)%noahmp401%zwt + write(ftn) NOAHMP401_struc(n)%noahmp401%wa + write(ftn) NOAHMP401_struc(n)%noahmp401%wt + + ! snow layer temperature + do l=1, NOAHMP401_struc(n)%nsnow ! TODO: check loop + tmptilen = 0 + do t=1, LIS_rc%npatch(n, LIS_rc%lsm_index) + tmptilen(t) = NOAHMP401_struc(n)%noahmp401(t)%tsno(l) + enddo + write(ftn) tmptilen + enddo + ! snow/soil layer depth from snow surface + do l=1, NOAHMP401_struc(n)%nsnow+NOAHMP401_struc(n)%nsoil ! TODO: check loop + tmptilen = 0 + do t=1, LIS_rc%npatch(n, LIS_rc%lsm_index) + tmptilen(t) = NOAHMP401_struc(n)%noahmp401(t)%zss(l) + enddo + write(ftn) tmptilen + enddo + ! snow layer ice + do l=1, NOAHMP401_struc(n)%nsnow ! TODO: check loop + tmptilen = 0 + do t=1, LIS_rc%npatch(n, LIS_rc%lsm_index) + tmptilen(t) = NOAHMP401_struc(n)%noahmp401(t)%snowice(l) + enddo + write(ftn) tmptilen + enddo + ! snow layer liquid water + do l=1, NOAHMP401_struc(n)%nsnow ! TODO: check loop + tmptilen = 0 + do t=1, LIS_rc%npatch(n, LIS_rc%lsm_index) + tmptilen(t) = NOAHMP401_struc(n)%noahmp401(t)%snowliq(l) + enddo + write(ftn) tmptilen + enddo + write(ftn) NOAHMP401_struc(n)%noahmp401%lfmass + write(ftn) NOAHMP401_struc(n)%noahmp401%rtmass + write(ftn) NOAHMP401_struc(n)%noahmp401%stmass + write(ftn) NOAHMP401_struc(n)%noahmp401%wood + write(ftn) NOAHMP401_struc(n)%noahmp401%stblcp + write(ftn) NOAHMP401_struc(n)%noahmp401%fastcp + write(ftn) NOAHMP401_struc(n)%noahmp401%lai + write(ftn) NOAHMP401_struc(n)%noahmp401%sai + write(ftn) NOAHMP401_struc(n)%noahmp401%tauss + + ! equilibrium volumetric soil moisture content + do l=1, NOAHMP401_struc(n)%nsoil ! TODO: check loop + tmptilen = 0 + do t=1, LIS_rc%npatch(n, LIS_rc%lsm_index) + tmptilen(t) = NOAHMP401_struc(n)%noahmp401(t)%smoiseq(l) + enddo + write(ftn) tmptilen + enddo + write(ftn) NOAHMP401_struc(n)%noahmp401%smcwtd + write(ftn) NOAHMP401_struc(n)%noahmp401%deeprech + write(ftn) NOAHMP401_struc(n)%noahmp401%rech + write(ftn) NOAHMP401_struc(n)%noahmp401%grain + write(ftn) NOAHMP401_struc(n)%noahmp401%gdd + + tmptilen = 0 + do t=1, LIS_rc%npatch(n, LIS_rc%lsm_index) + tmptilen(t) = NOAHMP401_struc(n)%noahmp401(t)%pgs + enddo + write(ftn) tmptilen + +! do l=1, 60 ! TODO: check loop +! tmptilen = 0 +! do t=1, LIS_rc%npatch(n, LIS_rc%lsm_index) +! tmptilen(t) = NOAHMP401_struc(n)%noahmp401(t)%gecros_state(l) +! enddo +! write(ftn) tmptilen +! enddo + end subroutine NoahMP401_dump_restart_dist + !BOP ! ! !ROUTINE: NoahMP401_dump_restart