Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 40 additions & 6 deletions build/source/netcdf/modelwrite.f90
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ module modelwrite_module
USE globalData,only:gru_struc ! gru->hru mapping structure

! netcdf deflate level
USE globalData,only: outputCompressionLevel
USE globalData,only: outputCompressionLevel

! provide access to the derived types to define the data structures
USE data_types,only:&
Expand Down Expand Up @@ -65,7 +65,7 @@ module modelwrite_module
! vector lengths
USE var_lookup, only: maxvarFreq ! number of output frequencies
USE var_lookup, only: maxvarStat ! number of statistics


implicit none
private
Expand Down Expand Up @@ -439,7 +439,7 @@ subroutine writeTime(finalizeStats,outputTimestep,meta,dat,err,message)
end subroutine writeTime

! *********************************************************************************************************
! public subroutine printRestartFile: print a re-start file
! public subroutine writeRestart: write a re-start file
! *********************************************************************************************************
subroutine writeRestart(filename, & ! intent(in): name of restart file
nGRU, & ! intent(in): number of GRUs
Expand Down Expand Up @@ -467,7 +467,7 @@ subroutine writeRestart(filename, & ! intent(in): name of restart file
USE netcdf_util_module,only:nc_file_close ! close netcdf file
USE netcdf_util_module,only:nc_file_open ! open netcdf file
USE globalData,only:nTimeDelay ! number of timesteps in the time delay histogram

implicit none
! --------------------------------------------------------------------------------------------------------
! input
Expand Down Expand Up @@ -533,6 +533,10 @@ subroutine writeRestart(filename, & ! intent(in): name of restart file
integer(i4b) :: iVar ! variable index
logical(lgt) :: okLength ! flag to check if the vector length is OK
character(len=256) :: cmessage ! downstream error message

! Declare NetCDF variable ID for hru_id
integer(i4b) :: ncHruIdID ! NetCDF variable ID for hru_id
integer(i4b), allocatable :: hruIds(:) ! Array to store hru_ids as integer(4)
! --------------------------------------------------------------------------------------------------------

! initialize error control
Expand Down Expand Up @@ -567,6 +571,18 @@ subroutine writeRestart(filename, & ! intent(in): name of restart file
! re-initialize error control
err=0; message='writeRestart/'

! Define hruId variable
err = nf90_def_var(ncid, 'hruId', nf90_int, (/hruDimID/), ncHruIdID)
message = 'writeRestart/defining hruId variable'
call netcdf_err(err, message)
if (err /= 0) return

! Add attributes to hruId variable
err = nf90_put_att(ncid, ncHruIdID, 'long_name', 'Hydrologic Response Unit ID')
call netcdf_err(err, message)
err = nf90_put_att(ncid, ncHruIdID, 'units', '1')
call netcdf_err(err, message)

! define prognostic variables
do iVar = 1,nProgVars
if (prog_meta(iVar)%varType==iLookvarType%unknown) cycle
Expand Down Expand Up @@ -617,6 +633,24 @@ subroutine writeRestart(filename, & ! intent(in): name of restart file
! end definition phase
err = nf90_enddef(ncid); call netcdf_err(err,message); if (err/=0) return

! Allocate and fill hruIds array
allocate(hruIds(nHRU))
do iGRU = 1, nGRU
do iHRU = 1, gru_struc(iGRU)%hruCount
cHRU = gru_struc(iGRU)%hruInfo(iHRU)%hru_ix
hruIds(cHRU) = int(gru_struc(iGRU)%hruInfo(iHRU)%hru_id, kind=i4b)
end do
end do

! Write hruId data
err = nf90_put_var(ncid, ncHruIdID, hruIds)
message = 'writeRestart/writing hruId data'
call netcdf_err(err, message)
if (err /= 0) return

! Deallocate hruIds array
deallocate(hruIds)

! write variables
do iGRU = 1,nGRU
do iHRU = 1,gru_struc(iGRU)%hruCount
Expand Down Expand Up @@ -677,10 +711,10 @@ subroutine writeRestart(filename, & ! intent(in): name of restart file
err=nf90_put_var(ncid,ncSoilID,(/indx_data%gru(iGRU)%hru(iHRU)%var(iLookIndex%nSoil)%dat/),start=(/cHRU/),count=(/1/))

end do ! iHRU loop

! write selected basin variables
err=nf90_put_var(ncid,ncVarID(nProgVars+1),(/bvar_data%gru(iGRU)%var(iLookBVAR%routingRunoffFuture)%dat/), start=(/iGRU/),count=(/1,nTimeDelay/))

end do ! iGRU loop

! close file
Expand Down
1 change: 1 addition & 0 deletions docs/whats-new.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ This page provides simple, high-level documentation about what has changed in ea

### Minor changes
- Updated SWE balance check in coupled_em for cases where all snow melts in one of the substeps
- Added writing of hruId to restart files

## Version 3.2.0
### Major changes
Expand Down