Skip to content

Commit

Permalink
Merge branch 'concepts/write-ic-at-init-date' into 'concepts/main' (!15)
Browse files Browse the repository at this point in the history
cicecore: correct initial condition metadata (CICE-Consortium#818)

Closes #19
  • Loading branch information
phil-blain committed Sep 7, 2023
2 parents 1da7aca + d63f6b4 commit 31b1219
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ subroutine ice_write_hist(ns)
trim(avail_hist_fields(n)%vcomment)

if (histfreq(ns) == '1' .or. .not. hist_avg &
.or. write_ic &
.or. n==n_divu(ns) .or. n==n_shear(ns) & ! snapshots
.or. n==n_sig1(ns) .or. n==n_sig2(ns) &
.or. n==n_sigP(ns) .or. n==n_trsig(ns) &
Expand Down Expand Up @@ -186,7 +187,7 @@ subroutine ice_write_hist(ns)
write (nu_hdr, 994) nrec,trim(avail_hist_fields(n)%vname), &
trim(avail_hist_fields(n)%vdesc),trim(avail_hist_fields(n)%vunit),nn

if (histfreq(ns) == '1' .or. .not. hist_avg) then
if (histfreq(ns) == '1' .or. .not. hist_avg .or. write_ic) then
write (nu_hdr, 996) nrec,trim(avail_hist_fields(n)%vname), &
'time_rep','instantaneous'
else
Expand All @@ -210,7 +211,7 @@ subroutine ice_write_hist(ns)
write (nu_hdr, 993) nrec,trim(avail_hist_fields(n)%vname), &
trim(avail_hist_fields(n)%vdesc),trim(avail_hist_fields(n)%vunit),k

if (histfreq(ns) == '1' .or. .not. hist_avg) then
if (histfreq(ns) == '1' .or. .not. hist_avg .or. write_ic) then
write (nu_hdr, 996) nrec,trim(avail_hist_fields(n)%vname), &
'time_rep','instantaneous'
else
Expand All @@ -234,7 +235,7 @@ subroutine ice_write_hist(ns)
write (nu_hdr, 993) nrec,trim(avail_hist_fields(n)%vname), &
trim(avail_hist_fields(n)%vdesc),trim(avail_hist_fields(n)%vunit),nn,k

if (histfreq(ns) == '1' .or. .not. hist_avg) then
if (histfreq(ns) == '1' .or. .not. hist_avg .or. write_ic) then
write (nu_hdr, 996) nrec,trim(avail_hist_fields(n)%vname), &
'time_rep','instantaneous'
else
Expand All @@ -258,7 +259,7 @@ subroutine ice_write_hist(ns)
write (nu_hdr, 993) nrec,trim(avail_hist_fields(n)%vname), &
trim(avail_hist_fields(n)%vdesc),trim(avail_hist_fields(n)%vunit),nn,k

if (histfreq(ns) == '1' .or. .not. hist_avg) then
if (histfreq(ns) == '1' .or. .not. hist_avg .or. write_ic) then
write (nu_hdr, 996) nrec,trim(avail_hist_fields(n)%vname), &
'time_rep','instantaneous'
else
Expand All @@ -282,7 +283,7 @@ subroutine ice_write_hist(ns)
write (nu_hdr, 993) nrec,trim(avail_hist_fields(n)%vname), &
trim(avail_hist_fields(n)%vdesc),trim(avail_hist_fields(n)%vunit),nn,k

if (histfreq(ns) == '1' .or. .not. hist_avg) then
if (histfreq(ns) == '1' .or. .not. hist_avg .or. write_ic) then
write (nu_hdr, 996) nrec,trim(avail_hist_fields(n)%vname), &
'time_rep','instantaneous'
else
Expand All @@ -307,7 +308,7 @@ subroutine ice_write_hist(ns)
write (nu_hdr, 993) nrec,trim(avail_hist_fields(n)%vname), &
trim(avail_hist_fields(n)%vdesc),trim(avail_hist_fields(n)%vunit),nn,k

if (histfreq(ns) == '1' .or. .not. hist_avg) then
if (histfreq(ns) == '1' .or. .not. hist_avg .or. write_ic) then
write (nu_hdr, 996) nrec,trim(avail_hist_fields(n)%vname), &
'time_rep','instantaneous'
else
Expand All @@ -333,7 +334,7 @@ subroutine ice_write_hist(ns)
write (nu_hdr, 993) nrec,trim(avail_hist_fields(n)%vname), &
trim(avail_hist_fields(n)%vdesc),trim(avail_hist_fields(n)%vunit),nn,k

if (histfreq(ns) == '1' .or. .not. hist_avg) then
if (histfreq(ns) == '1' .or. .not. hist_avg .or. write_ic) then
write (nu_hdr, 996) nrec,trim(avail_hist_fields(n)%vname), &
'time_rep','instantaneous'
else
Expand All @@ -359,7 +360,7 @@ subroutine ice_write_hist(ns)
write (nu_hdr, 993) nrec,trim(avail_hist_fields(n)%vname), &
trim(avail_hist_fields(n)%vdesc),trim(avail_hist_fields(n)%vunit),nn,k

if (histfreq(ns) == '1' .or. .not. hist_avg) then
if (histfreq(ns) == '1' .or. .not. hist_avg .or. write_ic) then
write (nu_hdr, 996) nrec,trim(avail_hist_fields(n)%vname), &
'time_rep','instantaneous'
else
Expand Down
28 changes: 14 additions & 14 deletions cicecore/cicedynB/infrastructure/io/io_netcdf/ice_history_write.F90
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ subroutine ice_write_hist (ns)
! define dimensions
!-----------------------------------------------------------------

if (hist_avg) then
if (hist_avg .and. .not. write_ic) then
status = nf90_def_dim(ncid,'d2',2,boundid)
if (status /= nf90_noerr) call abort_ice(subname// &
'ERROR: defining dim d2')
Expand Down Expand Up @@ -235,7 +235,7 @@ subroutine ice_write_hist (ns)
call abort_ice(subname//'ERROR: invalid calendar settings')
endif

if (hist_avg) then
if (hist_avg .and. .not. write_ic) then
status = nf90_put_att(ncid,varid,'bounds','time_bounds')
if (status /= nf90_noerr) call abort_ice(subname// &
'ERROR: time bounds')
Expand All @@ -245,7 +245,7 @@ subroutine ice_write_hist (ns)
! Define attributes for time bounds if hist_avg is true
!-----------------------------------------------------------------

if (hist_avg) then
if (hist_avg .and. .not. write_ic) then
dimid(1) = boundid
dimid(2) = timid
status = nf90_def_var(ncid,'time_bounds',lprecision,dimid(1:2),varid)
Expand Down Expand Up @@ -488,7 +488,7 @@ subroutine ice_write_hist (ns)
!-----------------------------------------------------------------
! Add cell_methods attribute to variables if averaged
!-----------------------------------------------------------------
if (hist_avg) then
if (hist_avg .and. .not. write_ic) then
if (TRIM(avail_hist_fields(n)%vname)/='sig1' &
.or.TRIM(avail_hist_fields(n)%vname)/='sig2' &
.or.TRIM(avail_hist_fields(n)%vname)/='sistreave' &
Expand All @@ -501,7 +501,7 @@ subroutine ice_write_hist (ns)
endif

if ((histfreq(ns) == '1' .and. histfreq_n(ns) == 1) &
.or..not. hist_avg &
.or..not. hist_avg .or. write_ic &
.or. n==n_divu(ns) .or. n==n_shear(ns) & ! snapshots
.or. n==n_sig1(ns) .or. n==n_sig2(ns) &
.or. n==n_sigP(ns) .or. n==n_trsig(ns) &
Expand Down Expand Up @@ -547,14 +547,14 @@ subroutine ice_write_hist (ns)
!-----------------------------------------------------------------
! Add cell_methods attribute to variables if averaged
!-----------------------------------------------------------------
if (hist_avg) then
if (hist_avg .and. .not. write_ic) then
status = nf90_put_att(ncid,varid,'cell_methods','time: mean')
if (status /= nf90_noerr) call abort_ice(subname// &
'ERROR: defining cell methods for '//avail_hist_fields(n)%vname)
endif

if ((histfreq(ns) == '1' .and. histfreq_n(ns) == 1) &
.or..not. hist_avg) then
.or..not. hist_avg .or. write_ic) then
status = nf90_put_att(ncid,varid,'time_rep','instantaneous')
else
status = nf90_put_att(ncid,varid,'time_rep','averaged')
Expand Down Expand Up @@ -724,14 +724,14 @@ subroutine ice_write_hist (ns)
!-----------------------------------------------------------------
! Add cell_methods attribute to variables if averaged
!-----------------------------------------------------------------
if (hist_avg) then
if (hist_avg .and. .not. write_ic) then
status = nf90_put_att(ncid,varid,'cell_methods','time: mean')
if (status /= nf90_noerr) call abort_ice(subname// &
'ERROR: defining cell methods for '//avail_hist_fields(n)%vname)
endif

if ((histfreq(ns) == '1' .and. histfreq_n(ns) == 1) &
.or..not. hist_avg) then
.or..not. hist_avg .or. write_ic) then
status = nf90_put_att(ncid,varid,'time_rep','instantaneous')
else
status = nf90_put_att(ncid,varid,'time_rep','averaged')
Expand Down Expand Up @@ -773,14 +773,14 @@ subroutine ice_write_hist (ns)
!-----------------------------------------------------------------
! Add cell_methods attribute to variables if averaged
!-----------------------------------------------------------------
if (hist_avg) then
if (hist_avg .and. .not. write_ic) then
status = nf90_put_att(ncid,varid,'cell_methods','time: mean')
if (status /= nf90_noerr) call abort_ice(subname// &
'ERROR: defining cell methods for '//avail_hist_fields(n)%vname)
endif

if ((histfreq(ns) == '1' .and. histfreq_n(ns) == 1) &
.or..not. hist_avg) then
.or..not. hist_avg .or. write_ic) then
status = nf90_put_att(ncid,varid,'time_rep','instantaneous')
else
status = nf90_put_att(ncid,varid,'time_rep','averaged')
Expand Down Expand Up @@ -822,14 +822,14 @@ subroutine ice_write_hist (ns)
!-----------------------------------------------------------------
! Add cell_methods attribute to variables if averaged
!-----------------------------------------------------------------
if (hist_avg) then
if (hist_avg .and. .not. write_ic) then
status = nf90_put_att(ncid,varid,'cell_methods','time: mean')
if (status /= nf90_noerr) call abort_ice(subname// &
'ERROR: defining cell methods for '//avail_hist_fields(n)%vname)
endif

if ((histfreq(ns) == '1' .and. histfreq_n(ns) == 1) &
.or..not. hist_avg) then
.or..not. hist_avg .or. write_ic) then
status = nf90_put_att(ncid,varid,'time_rep','instantaneous')
else
status = nf90_put_att(ncid,varid,'time_rep','averaged')
Expand Down Expand Up @@ -924,7 +924,7 @@ subroutine ice_write_hist (ns)
! write time_bounds info
!-----------------------------------------------------------------

if (hist_avg) then
if (hist_avg .and. .not. write_ic) then
status = nf90_inq_varid(ncid,'time_bounds',varid)
if (status /= nf90_noerr) call abort_ice(subname// &
'ERROR: getting time_bounds id')
Expand Down
44 changes: 22 additions & 22 deletions cicecore/cicedynB/infrastructure/io/io_pio2/ice_history_write.F90
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ subroutine ice_write_hist (ns)
! define dimensions
!-----------------------------------------------------------------

if (hist_avg) then
if (hist_avg .and. .not. write_ic) then
status = pio_def_dim(File,'d2',2,boundid)
endif

Expand Down Expand Up @@ -228,12 +228,12 @@ subroutine ice_write_hist (ns)
call abort_ice(subname//'ERROR: invalid calendar settings')
endif

if (hist_avg) then
if (hist_avg .and. .not. write_ic) then
status = pio_put_att(File,varid,'bounds','time_bounds')
endif

! Define attributes for time_bounds if hist_avg is true
if (hist_avg) then
if (hist_avg .and. .not. write_ic) then
dimid2(1) = boundid
dimid2(2) = timid
status = pio_def_var(File,'time_bounds',pio_double,dimid2,varid)
Expand Down Expand Up @@ -441,7 +441,7 @@ subroutine ice_write_hist (ns)
call ice_write_hist_fill(File,varid,avail_hist_fields(n)%vname,history_precision)

! Add cell_methods attribute to variables if averaged
if (hist_avg) then
if (hist_avg .and. .not. write_ic) then
if (TRIM(avail_hist_fields(n)%vname)/='sig1' &
.or.TRIM(avail_hist_fields(n)%vname)/='sig2' &
.or.TRIM(avail_hist_fields(n)%vname)/='sistreave' &
Expand All @@ -452,7 +452,7 @@ subroutine ice_write_hist (ns)
endif

if ((histfreq(ns) == '1' .and. histfreq_n(ns) == 1) &
.or..not. hist_avg &
.or..not. hist_avg .or. write_ic &
.or. n==n_divu(ns) .or. n==n_shear(ns) & ! snapshots
.or. n==n_sig1(ns) .or. n==n_sig2(ns) &
.or. n==n_sigP(ns) .or. n==n_trsig(ns) &
Expand Down Expand Up @@ -490,12 +490,12 @@ subroutine ice_write_hist (ns)
call ice_write_hist_fill(File,varid,avail_hist_fields(n)%vname,history_precision)

! Add cell_methods attribute to variables if averaged
if (hist_avg) then
if (hist_avg .and. .not. write_ic) then
status = pio_put_att(File,varid,'cell_methods','time: mean')
endif

if ((histfreq(ns) == '1' .and. histfreq_n(ns) == 1) &
.or..not. hist_avg) then
.or..not. hist_avg .or. write_ic) then
status = pio_put_att(File,varid,'time_rep','instantaneous')
else
status = pio_put_att(File,varid,'time_rep','averaged')
Expand Down Expand Up @@ -527,12 +527,12 @@ subroutine ice_write_hist (ns)
call ice_write_hist_fill(File,varid,avail_hist_fields(n)%vname,history_precision)

! Add cell_methods attribute to variables if averaged
if (hist_avg) then
if (hist_avg .and. .not. write_ic) then
status = pio_put_att(File,varid,'cell_methods','time: mean')
endif

if ((histfreq(ns) == '1' .and. histfreq_n(ns) == 1) &
.or..not. hist_avg) then
.or..not. hist_avg .or. write_ic) then
status = pio_put_att(File,varid,'time_rep','instantaneous')
else
status = pio_put_att(File,varid,'time_rep','averaged')
Expand Down Expand Up @@ -564,12 +564,12 @@ subroutine ice_write_hist (ns)
call ice_write_hist_fill(File,varid,avail_hist_fields(n)%vname,history_precision)

! Add cell_methods attribute to variables if averaged
if (hist_avg) then
if (hist_avg .and. .not. write_ic) then
status = pio_put_att(File,varid,'cell_methods','time: mean')
endif

if ((histfreq(ns) == '1' .and. histfreq_n(ns) == 1) &
.or..not. hist_avg) then
.or..not. hist_avg .or. write_ic) then
status = pio_put_att(File,varid,'time_rep','instantaneous')
else
status = pio_put_att(File,varid,'time_rep','averaged')
Expand Down Expand Up @@ -601,12 +601,12 @@ subroutine ice_write_hist (ns)
call ice_write_hist_fill(File,varid,avail_hist_fields(n)%vname,history_precision)

! Add cell_methods attribute to variables if averaged
if (hist_avg) then
if (hist_avg .and. .not. write_ic) then
status = pio_put_att(File,varid,'cell_methods','time: mean')
endif

if ((histfreq(ns) == '1' .and. histfreq_n(ns) == 1) &
.or..not. hist_avg) then
.or..not. hist_avg .or. write_ic) then
status = pio_put_att(File,varid,'time_rep','instantaneous')
else
status = pio_put_att(File,varid,'time_rep','averaged')
Expand Down Expand Up @@ -638,12 +638,12 @@ subroutine ice_write_hist (ns)
call ice_write_hist_fill(File,varid,avail_hist_fields(n)%vname,history_precision)

! Add cell_methods attribute to variables if averaged
if (hist_avg) then
if (hist_avg .and. .not. write_ic) then
status = pio_put_att(File,varid,'cell_methods','time: mean')
endif

if ((histfreq(ns) == '1' .and. histfreq_n(ns) == 1) &
.or..not. hist_avg) then
.or..not. hist_avg .or. write_ic) then
status = pio_put_att(File,varid,'time_rep','instantaneous')
else
status = pio_put_att(File,varid,'time_rep','averaged')
Expand Down Expand Up @@ -681,12 +681,12 @@ subroutine ice_write_hist (ns)
call ice_write_hist_fill(File,varid,avail_hist_fields(n)%vname,history_precision)

! Add cell_methods attribute to variables if averaged
if (hist_avg) then
if (hist_avg .and. .not. write_ic) then
status = pio_put_att(File,varid,'cell_methods','time: mean')
endif

if ((histfreq(ns) == '1' .and. histfreq_n(ns) == 1) &
.or..not. hist_avg) then
.or..not. hist_avg .or. write_ic) then
status = pio_put_att(File,varid,'time_rep','instantaneous')
else
status = pio_put_att(File,varid,'time_rep','averaged')
Expand Down Expand Up @@ -719,12 +719,12 @@ subroutine ice_write_hist (ns)
call ice_write_hist_fill(File,varid,avail_hist_fields(n)%vname,history_precision)

! Add cell_methods attribute to variables if averaged
if (hist_avg) then
if (hist_avg .and. .not. write_ic) then
status = pio_put_att(File,varid,'cell_methods','time: mean')
endif

if ((histfreq(ns) == '1' .and. histfreq_n(ns) == 1) &
.or..not. hist_avg) then
.or..not. hist_avg .or. write_ic) then
status = pio_put_att(File,varid,'time_rep','instantaneous')
else
status = pio_put_att(File,varid,'time_rep','averaged')
Expand Down Expand Up @@ -758,12 +758,12 @@ subroutine ice_write_hist (ns)
call ice_write_hist_fill(File,varid,avail_hist_fields(n)%vname,history_precision)

! Add cell_methods attribute to variables if averaged
if (hist_avg) then
if (hist_avg .and. .not. write_ic) then
status = pio_put_att(File,varid,'cell_methods','time: mean')
endif

if ((histfreq(ns) == '1' .and. histfreq_n(ns) == 1) &
.or..not. hist_avg) then
.or..not. hist_avg .or. write_ic) then
status = pio_put_att(File,varid,'time_rep','instantaneous')
else
status = pio_put_att(File,varid,'time_rep','averaged')
Expand Down Expand Up @@ -836,7 +836,7 @@ subroutine ice_write_hist (ns)
! write time_bounds info
!-----------------------------------------------------------------

if (hist_avg) then
if (hist_avg .and. .not. write_ic) then
status = pio_inq_varid(File,'time_bounds',varid)
time_bounds=(/time_beg(ns),time_end(ns)/)
bnd_start = (/1,1/)
Expand Down
4 changes: 2 additions & 2 deletions cicecore/drivers/direct/nemo_concepts/CICE_InitMod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,8 @@ subroutine cice_init
if (trim(runtype) == 'continue' .or. restart) &
call init_shortwave ! initialize radiative transfer

if (write_ic) call accum_hist(dt) ! write initial conditions

! determine the time and date at the end of the first timestep
call advance_timestep()

Expand Down Expand Up @@ -215,8 +217,6 @@ subroutine cice_init
call init_flux_atm ! initialize atmosphere fluxes sent to coupler
call init_flux_ocn ! initialize ocean fluxes sent to coupler

if (write_ic) call accum_hist(dt) ! write initial conditions

end subroutine cice_init

!=======================================================================
Expand Down
Loading

0 comments on commit 31b1219

Please sign in to comment.