Skip to content

Commit

Permalink
driver: icedrv_restart: Added option for restart files to be read/wri…
Browse files Browse the repository at this point in the history
…tten in NetCDF format (#427)

* Trial fix for netCDF start time problem

* driver: icedrv_history: fix start time for NetCDF history output

The start time for netCDF output was hardcoded to be at 00:00:00
and there was a bug in icedrv_calendar such that idate0 was fixed
at Jan. 1. Both bugs are fixed. NOTE: if dt and istep0 are set
such that the start time contains fractional seconds, they will
be rounded down in the NetCDF output to the nearest integer.

* driver: icedrv_history: fix start time for NetCDF History output

Start of netCDF time axis is fixed at Jan. 01 00:00:00 of
init_year and time value calculation is now fixed.

* Added restart_format variable to icedrv_restart_shared and to namelist.

No functionality implemented yet, just checking it's added correctly.

* need to also add new namelist to icepack_in

* Added error handling for incorrect restart format, should probably update final_restart at some point

* NetCDF restart file created, next need to populate fields

* NetCDF Restart output is now populated

* if block error handling in restartfile

* driver: icedrv_restart: enabled restart/ice_ic files to be written/read as NetCDF

Added the option for restart (aka initial condition) files to be in NetCDF
instead of binary for ease of setting custom inital conditions

* modified set_nml.ionetcdf to default to netcdf restart files if we set ionetcdf

* Fixed error in which some tracers were not being writting. NetCDF restart files are now identical

* fixed istep1 = istep0 but and added test_suite for netcdf

* removed bgc from the netcdf restart test suite

* put netcdf functions into conditional compilation blocks

* Removed unused variables (sec0, h0, m0, s0) from icedrv_history

* Removing unused variables in icedrv_history (after merging in from consortium-main)

* Changed history_cdf namelist to history_format and updated documentation

* Fixed warning message if restart_format is incorrect

* halfway done reorganizing restartfile

* finished reorganization in restartfile, need to do dumpfile next

* Halfway done editing dumpfile

* finished editing dumpfile

* updated namelist settings and documentation. all tests pass

* removed the netcdf_nobgc test suite

* Fix minor issues found during testing
  - icedrv_init write format for history_format
  - dims allocation in icedrv_restart
  - cleaned up some intent lines (old)
  - add return at end of io_suite.ts
  - update namelist documentation of history_format, restart_format
Update to current main trunk

* Update history_format default

Check history_format and restart_format input values

---------

Co-authored-by: apcraig <anthony.p.craig@gmail.com>
  • Loading branch information
davidclemenssewall and apcraig authored Mar 3, 2023
1 parent acfc046 commit 37e215b
Show file tree
Hide file tree
Showing 14 changed files with 853 additions and 177 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,9 @@ doc/build
# Ignore testsuite file/directories
testsuite*
caselist*

# Ignore compiled .mod files
*.mod

# Ignore test case directories (no consistent name so we'll just ignore conda)
conda_*
8 changes: 4 additions & 4 deletions configuration/driver/icedrv_RunMod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ subroutine icedrv_run
use icedrv_forcing, only: get_forcing, get_wave_spec
use icedrv_forcing_bgc, only: faero_default, fiso_default, get_forcing_bgc
use icedrv_flux, only: init_flux_atm_ocn
use icedrv_history, only: history_cdf, history_close
use icedrv_history, only: history_format, history_close

logical (kind=log_kind) :: skl_bgc, z_tracers, tr_aero, tr_zaero, &
wave_spec, tr_fsd, tr_iso
Expand Down Expand Up @@ -63,7 +63,7 @@ subroutine icedrv_run
call calendar(time) ! at the end of the timestep

if (stop_now >= 1) then
if (history_cdf) call history_close()
if (history_format == 'nc') call history_close()
exit timeLoop
endif

Expand Down Expand Up @@ -101,7 +101,7 @@ subroutine ice_step
use icedrv_diagnostics_bgc, only: hbrine_diags, zsal_diags, bgc_diags
use icedrv_flux, only: init_history_therm, init_history_bgc, &
daidtt, daidtd, dvidtt, dvidtd, dagedtt, dagedtd, init_history_dyn
use icedrv_history, only: history_cdf, history_write
use icedrv_history, only: history_format, history_write
use icedrv_restart, only: dumpfile, final_restart
use icedrv_restart_bgc, only: write_restart_bgc
use icedrv_step, only: prep_radiation, step_therm1, step_therm2, &
Expand Down Expand Up @@ -225,7 +225,7 @@ subroutine ice_step
if (tr_brine) call hbrine_diags
endif

if (history_cdf) then
if (history_format == 'nc') then
call history_write()
endif

Expand Down
9 changes: 3 additions & 6 deletions configuration/driver/icedrv_history.F90
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ module icedrv_history

! history output file info

logical (kind=log_kind), public :: history_cdf ! flag to turn on cdf history files
character (len=char_len), public :: &
history_format ! format of history files, only supported type is 'nc'

character (len=char_len_long) :: hist_file ! hist file name

Expand Down Expand Up @@ -68,11 +69,7 @@ subroutine history_write()
count1(1), count2(2), count3(3), count4(4), & ! cdf start/count arrays
varid, & ! cdf varid
status, & ! cdf status flag
iflag, & ! history file attributes
sec0, & ! number of seconds into the day at istep0
h0, & ! start hour
m0, & ! start minute
s0 ! start second
iflag ! history file attributes

character (len=8) :: &
cdate ! date string
Expand Down
28 changes: 21 additions & 7 deletions configuration/driver/icedrv_init.F90
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ subroutine input_data
use icedrv_calendar, only: year_init, istep0
use icedrv_calendar, only: dumpfreq, diagfreq, dump_last
use icedrv_calendar, only: npt, dt, ndtd, days_per_year, use_leap_years
use icedrv_history, only: history_cdf
use icedrv_restart_shared, only: restart, restart_dir, restart_file
use icedrv_history, only: history_format
use icedrv_restart_shared, only: restart, restart_dir, restart_file, restart_format
use icedrv_flux, only: update_ocn_f, l_mpond_fresh, cpl_bgc
use icedrv_flux, only: default_season
use icedrv_forcing, only: precip_units, fyear_init, ycycle
Expand Down Expand Up @@ -133,8 +133,9 @@ subroutine input_data
days_per_year, use_leap_years, year_init, istep0, &
dt, npt, ndtd, dump_last, &
ice_ic, restart, restart_dir, restart_file, &
restart_format, &
dumpfreq, diagfreq, diag_file, cpl_bgc, &
conserv_check, history_cdf
conserv_check, history_format

namelist /grid_nml/ &
kcatbound
Expand Down Expand Up @@ -254,9 +255,10 @@ subroutine input_data
restart = .false. ! if true, read restart files for initialization
restart_dir = './' ! write to executable dir for default
restart_file = 'iced' ! restart file name prefix
history_cdf = .false. ! history netcdf file flag
ice_ic = 'default' ! initial conditions are specified in the code
! otherwise, the filename for reading restarts
restart_format = 'bin' ! default restart format is binary, other option 'nc'
history_format = 'none' ! if 'nc', write history files. Otherwise do nothing
ice_ic = 'default' ! initial conditions are specified in the code
! otherwise, the filename for reading restarts
ndtd = 1 ! dynamic time steps per thermodynamic time step
l_mpond_fresh = .false. ! logical switch for including meltpond freshwater
! flux feedback to ocean model
Expand Down Expand Up @@ -544,6 +546,16 @@ subroutine input_data
call icedrv_system_abort(file=__FILE__,line=__LINE__)
endif

if (restart_format /= 'bin' .and. restart_format /= 'nc') then
write (nu_diag,*) 'WARNING: restart_format value unknown '//trim(restart_format)
call icedrv_system_abort(file=__FILE__,line=__LINE__)
endif

if (history_format /= 'none' .and. history_format /= 'nc') then
write (nu_diag,*) 'WARNING: history_format value unknown '//trim(history_format)
call icedrv_system_abort(file=__FILE__,line=__LINE__)
endif

if (tr_aero .and. trim(shortwave) /= 'dEdd') then
write (nu_diag,*) 'WARNING: aerosols activated but dEdd'
write (nu_diag,*) 'WARNING: shortwave is not.'
Expand Down Expand Up @@ -645,7 +657,9 @@ subroutine input_data
trim(restart_dir)
write(nu_diag,*) ' restart_file = ', &
trim(restart_file)
write(nu_diag,1010) ' history_cdf = ', history_cdf
write(nu_diag,1030) ' restart_format = ', &
trim(restart_format)
write(nu_diag,1030) ' history_format = ', trim(history_format)
write(nu_diag,*) ' ice_ic = ', &
trim(ice_ic)
write(nu_diag,1010) ' conserv_check = ', conserv_check
Expand Down
Loading

0 comments on commit 37e215b

Please sign in to comment.