Skip to content

Commit 3466a02

Browse files
authored
Add ability to write out one-time grid history file (CICE-Consortium#1005)
Add ability to write one-time grid file in netCDf and PIO history features - Add grid_outfile logical namelist - Add extra history stream to be used just for grid output file, that stream is designated with the histfreq='g' label. It's turned on with the logical grid_outfile namelist and then automatically turned off after it's written the first time. This happens in ice_history.F90. - Add logic in ice_history_write.F90 to explicitly write the grid fields to the grid history file. - The one time grid filename is iceh_grid.nc - Add grid_outfile=.true. to set_nml.histall - Add external_variables global attribute to history files to note grid fields that are expected to be on other files - Add date_created global attribute Fix bug in PIO where 5d variables had their two "z" axis coordinates reversed when writing the field even though the variable had the correct axes defined in the history file. Detected by comparing netCDF and PIO history files. Set history netcdf attribute Conventions to CF-1.8. Ran history files through a CF checker. This resulted in a couple of warning messages but no errors. If grid variables associated with variable coordinate attributes are removed from the history file, this will result in CF errors even though external_variables are defined. This is sort of a shortcoming in the current CF conventions, but we decided to move ahead anyway. CF compliance will only be broken if grid variables are turned off in history files, and they are defined as part of other variable's coordinate (or similar) attributes. Add axis to the history coord_attributes datatype to provide another attribute on the netcdf file. Set axis to 'X', 'Y', or 'T' to a small subset of history file coordinate variables. Change netcdf "unitless" unit to "1". Update some abort calls in ice_history.F90 Update version_name namelist implementation, was not being broadcast or written to the log file. Affected history file output. Remove hist namelist settings in set_nml.run* files to minimize conflicts with other namelist options groups. Add a test case that allows manual comparison of netCDF and PIO history files. This needs to be done with cprnc. cmp of restart files and diff of log files produce differences even when results are bit-for-bit identical. Update documentation
1 parent 6664680 commit 3466a02

25 files changed

Lines changed: 442 additions & 357 deletions

cicecore/cicedyn/analysis/ice_history.F90

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ subroutine init_hist (dt)
6969
use ice_domain_size, only: max_blocks, max_nstrm, nilyr, nslyr, nblyr, ncat, nfsd
7070
use ice_dyn_shared, only: kdyn
7171
use ice_flux, only: mlt_onset, frz_onset, albcnt, snwcnt
72-
use ice_grid, only: grid_ice, &
72+
use ice_grid, only: grid_ice, grid_outfile, &
7373
grid_atm_thrm, grid_atm_dynu, grid_atm_dynv, &
7474
grid_ocn_thrm, grid_ocn_dynu, grid_ocn_dynv
7575
use ice_history_shared ! everything
@@ -239,15 +239,14 @@ subroutine init_hist (dt)
239239
call get_fileunit(nu_nml)
240240
open (nu_nml, file=trim(nml_filename), status='old',iostat=nml_error)
241241
if (nml_error /= 0) then
242-
call abort_ice(subname//'ERROR: '//trim(nml_name)//' open file '// &
243-
trim(nml_filename), &
244-
file=__FILE__, line=__LINE__)
242+
call abort_ice(subname//' ERROR: '//trim(nml_name)//' open file '// &
243+
trim(nml_filename), file=__FILE__, line=__LINE__)
245244
endif
246245

247246
! seek to this namelist
248247
call goto_nml(nu_nml,trim(nml_name),nml_error)
249248
if (nml_error /= 0) then
250-
call abort_ice(subname//'ERROR: searching for '// trim(nml_name), &
249+
call abort_ice(subname//' ERROR: searching for '// trim(nml_name), &
251250
file=__FILE__, line=__LINE__)
252251
endif
253252

@@ -260,7 +259,7 @@ subroutine init_hist (dt)
260259
! backspace and re-read erroneous line
261260
backspace(nu_nml)
262261
read(nu_nml,fmt='(A)') tmpstr2
263-
call abort_ice(subname//'ERROR: ' // trim(nml_name) // ' reading ' // &
262+
call abort_ice(subname//' ERROR: ' // trim(nml_name) // ' reading ' // &
264263
trim(tmpstr2), file=__FILE__, line=__LINE__)
265264
endif
266265
end do
@@ -278,23 +277,35 @@ subroutine init_hist (dt)
278277
nstreams = nstreams + 1
279278
if (ns >= 2) then
280279
if (histfreq(ns-1) == 'x') then
281-
call abort_ice(subname//'ERROR: histfreq all non x must be at start of array')
280+
call abort_ice(subname//' ERROR: histfreq all non x must be at start of array', &
281+
file=__FILE__, line=__LINE__)
282282
endif
283283
endif
284284
else if (histfreq(ns) /= 'x') then
285-
call abort_ice(subname//'ERROR: histfreq contains illegal element')
285+
write(nu_diag, * ) subname,' ns,histfreq = ',ns,histfreq(ns)
286+
call abort_ice(subname//' ERROR: histfreq contains illegal element', &
287+
file=__FILE__, line=__LINE__)
286288
endif
287289
enddo
288-
if (nstreams == 0) write (nu_diag,*) 'WARNING: No history output'
290+
if (nstreams == 0 .and. my_task == master_task) write (nu_diag,*) subname,' WARNING: No history output'
289291
do ns1 = 1, nstreams
290292
do ns2 = 1, nstreams
291293
if (histfreq(ns1) == histfreq(ns2) .and. ns1/=ns2 &
292294
.and. my_task == master_task) then
293-
call abort_ice(subname//'ERROR: histfreq elements must be unique')
295+
call abort_ice(subname//' ERROR: histfreq elements must be unique', &
296+
file=__FILE__, line=__LINE__)
294297
endif
295298
enddo
296299
enddo
297300

301+
! Turn on one-time grid output file
302+
if (grid_outfile) then
303+
nstreams = nstreams + 1
304+
histfreq(nstreams) = 'g'
305+
hist_avg(nstreams) = .false.
306+
if (my_task == master_task) write (nu_diag,*) subname,' Writing one-time grid file'
307+
endif
308+
298309
if (.not. tr_iage) then
299310
f_iage = 'x'
300311
f_dagedtt = 'x'
@@ -445,14 +456,6 @@ subroutine init_hist (dt)
445456
f_taubyE = f_tauby
446457
endif
447458

448-
! write dimensions for 3D or 4D history variables
449-
! note: list of variables checked here is incomplete
450-
if (f_aicen(1:1) /= 'x' .or. f_vicen(1:1) /= 'x' .or. &
451-
f_Tinz (1:1) /= 'x' .or. f_Sinz (1:1) /= 'x') f_NCAT = .true.
452-
if (f_Tinz (1:1) /= 'x' .or. f_Sinz (1:1) /= 'x') f_VGRDi = .true.
453-
if (f_Tsnz (1:1) /= 'x') f_VGRDs = .true.
454-
if (tr_fsd) f_NFSD = .true.
455-
456459
call broadcast_scalar (f_tlon, master_task)
457460
call broadcast_scalar (f_tlat, master_task)
458461
call broadcast_scalar (f_ulon, master_task)
@@ -4195,6 +4198,13 @@ subroutine accum_hist (dt)
41954198
enddo
41964199

41974200
endif ! write_history or write_ic
4201+
4202+
! Turn off one-time grid output file
4203+
if (histfreq(ns) == 'g') then
4204+
histfreq(ns) = 'x'
4205+
nstreams = nstreams - 1
4206+
endif
4207+
41984208
enddo ! nstreams
41994209

42004210
!$OMP PARALLEL DO PRIVATE(iblk,i,j,ilo,ihi,jlo,jhi,this_block)

cicecore/cicedyn/analysis/ice_history_shared.F90

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -822,12 +822,22 @@ subroutine construct_filename(ncfile,suffix,ns)
822822
write(ncfile,'(a,a,i4.4,a,a)') &
823823
history_file(1:lenstr(history_file))//trim(cstream),'.', &
824824
iyear,'.',trim(suffix)
825+
elseif (histfreq(ns) == 'g') then
826+
write(ncfile,'(a,a,a,a)') &
827+
history_file(1:lenstr(history_file)),'_grid', &
828+
'.',trim(suffix)
825829
endif
826830

827831
else ! instantaneous
828-
write(ncfile,'(a,a,i4.4,a,i2.2,a,i2.2,a,i5.5,a,a)') &
829-
history_file(1:lenstr(history_file))//trim(cstream),'_inst.', &
830-
iyear,'-',imonth,'-',iday,'-',msec,'.',trim(suffix)
832+
if (histfreq(ns) == 'g') then
833+
write(ncfile,'(a,a,a,a)') &
834+
history_file(1:lenstr(history_file)),'_grid', &
835+
'.',trim(suffix)
836+
else
837+
write(ncfile,'(a,a,i4.4,a,i2.2,a,i2.2,a,i5.5,a,a)') &
838+
history_file(1:lenstr(history_file))//trim(cstream),'_inst.', &
839+
iyear,'-',imonth,'-',iday,'-',msec,'.',trim(suffix)
840+
endif
831841
endif
832842

833843
endif

cicecore/cicedyn/general/ice_init.F90

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ subroutine input_data
109109
grid_file, gridcpl_file, kmt_file, &
110110
bathymetry_file, use_bathymetry, &
111111
bathymetry_format, kmt_type, &
112-
grid_type, grid_format, &
112+
grid_type, grid_format, grid_outfile, &
113113
grid_ice, grid_ice_thrm, grid_ice_dynu, grid_ice_dynv, &
114114
grid_ocn, grid_ocn_thrm, grid_ocn_dynu, grid_ocn_dynv, &
115115
grid_atm, grid_atm_thrm, grid_atm_dynu, grid_atm_dynv, &
@@ -217,7 +217,7 @@ subroutine input_data
217217
ncat, nilyr, nslyr, nblyr, &
218218
kcatbound, gridcpl_file, dxrect, dyrect, &
219219
dxscale, dyscale, lonrefrect, latrefrect, &
220-
scale_dxdy, &
220+
scale_dxdy, grid_outfile, &
221221
close_boundaries, orca_halogrid, grid_ice, kmt_type, &
222222
grid_atm, grid_ocn
223223

@@ -332,6 +332,7 @@ subroutine input_data
332332
bfbflag = 'off' ! off = optimized
333333
diag_type = 'stdout'
334334
diag_file = 'ice_diag.d'
335+
histfreq(:) = 'x'
335336
histfreq(1) = '1' ! output frequency option for different streams
336337
histfreq(2) = 'h' ! output frequency option for different streams
337338
histfreq(3) = 'd' ! output frequency option for different streams
@@ -383,6 +384,7 @@ subroutine input_data
383384
grid_atm = 'A' ! underlying atm forcing/coupling grid
384385
grid_ocn = 'A' ! underlying atm forcing/coupling grid
385386
gridcpl_file = 'unknown_gridcpl_file'
387+
grid_outfile = .false. ! write out one-time grid history file
386388
orca_halogrid = .false. ! orca haloed grid - deprecated
387389
bathymetry_file = 'unknown_bathymetry_file'
388390
bathymetry_format = 'default'
@@ -960,6 +962,7 @@ subroutine input_data
960962
call broadcast_scalar(cpl_bgc, master_task)
961963
call broadcast_scalar(incond_dir, master_task)
962964
call broadcast_scalar(incond_file, master_task)
965+
call broadcast_scalar(version_name, master_task)
963966
call broadcast_scalar(dump_last, master_task)
964967
call broadcast_scalar(restart_file, master_task)
965968
call broadcast_scalar(restart, master_task)
@@ -992,6 +995,7 @@ subroutine input_data
992995
call broadcast_scalar(grid_atm, master_task)
993996
call broadcast_scalar(grid_file, master_task)
994997
call broadcast_scalar(gridcpl_file, master_task)
998+
call broadcast_scalar(grid_outfile, master_task)
995999
call broadcast_scalar(orca_halogrid, master_task)
9961000
call broadcast_scalar(bathymetry_file, master_task)
9971001
call broadcast_scalar(bathymetry_format, master_task)
@@ -2529,6 +2533,7 @@ subroutine input_data
25292533
write(nu_diag,*) '===================================== '
25302534
if (trim(runid) /= 'unknown') &
25312535
write(nu_diag,1031) ' runid = ', trim(runid)
2536+
write(nu_diag,1031) ' version_name = ', trim(version_name)
25322537
write(nu_diag,1031) ' runtype = ', trim(runtype)
25332538
write(nu_diag,1021) ' year_init = ', year_init
25342539
write(nu_diag,1021) ' month_init = ', month_init
@@ -2551,11 +2556,12 @@ subroutine input_data
25512556
write(nu_diag,1031) ' bfbflag = ', trim(bfbflag)
25522557
write(nu_diag,1021) ' numin = ', numin
25532558
write(nu_diag,1021) ' numax = ', numax
2554-
write(nu_diag,1033) ' histfreq = ', histfreq(:)
2555-
write(nu_diag,1023) ' histfreq_n = ', histfreq_n(:)
2556-
write(nu_diag,1033) ' histfreq_base = ', histfreq_base(:)
2557-
write(nu_diag,1013) ' hist_avg = ', hist_avg(:)
2558-
write(nu_diag,1033) ' hist_suffix = ', hist_suffix(:)
2559+
write(nu_diag,1011) ' grid_outfile = ', grid_outfile
2560+
write(nu_diag,1033) ' histfreq = ', histfreq(1:max_nstrm-1)
2561+
write(nu_diag,1023) ' histfreq_n = ', histfreq_n(1:max_nstrm-1)
2562+
write(nu_diag,1033) ' histfreq_base = ', histfreq_base(1:max_nstrm-1)
2563+
write(nu_diag,1013) ' hist_avg = ', hist_avg(1:max_nstrm-1)
2564+
write(nu_diag,1033) ' hist_suffix = ', hist_suffix(1:max_nstrm-1)
25592565
write(nu_diag,1031) ' history_dir = ', trim(history_dir)
25602566
write(nu_diag,1031) ' history_file = ', trim(history_file)
25612567
write(nu_diag,1021) ' history_precision= ', history_precision
@@ -2571,9 +2577,9 @@ subroutine input_data
25712577
write(nu_diag,1039) ' Initial condition will be written in ', &
25722578
trim(incond_dir)
25732579
endif
2574-
write(nu_diag,1033) ' dumpfreq = ', dumpfreq(:)
2575-
write(nu_diag,1023) ' dumpfreq_n = ', dumpfreq_n(:)
2576-
write(nu_diag,1033) ' dumpfreq_base = ', dumpfreq_base(:)
2580+
write(nu_diag,1033) ' dumpfreq = ', dumpfreq(1:max_nstrm-1)
2581+
write(nu_diag,1023) ' dumpfreq_n = ', dumpfreq_n(1:max_nstrm-1)
2582+
write(nu_diag,1033) ' dumpfreq_base = ', dumpfreq_base(1:max_nstrm-1)
25772583
write(nu_diag,1011) ' dump_last = ', dump_last
25782584
write(nu_diag,1011) ' restart = ', restart
25792585
write(nu_diag,1031) ' restart_dir = ', trim(restart_dir)

cicecore/cicedyn/infrastructure/ice_grid.F90

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ module ice_grid
150150
kmt ! ocean topography mask for bathymetry (T-cell)
151151

152152
logical (kind=log_kind), public :: &
153+
grid_outfile, & ! flag to write out one-time grid history file
153154
use_bathymetry, & ! flag for reading in bathymetry_file
154155
save_ghte_ghtn, & ! flag for saving global hte and htn during initialization
155156
scale_dxdy ! flag to apply scale factor to vary dx/dy in rectgrid

0 commit comments

Comments
 (0)