diff --git a/build/source/netcdf/modelwrite.f90 b/build/source/netcdf/modelwrite.f90 old mode 100755 new mode 100644 index d66e0df02..7c0c1275c --- a/build/source/netcdf/modelwrite.f90 +++ b/build/source/netcdf/modelwrite.f90 @@ -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:& @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/docs/whats-new.md b/docs/whats-new.md index 9702ad8f3..18b5e993e 100644 --- a/docs/whats-new.md +++ b/docs/whats-new.md @@ -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