Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to write out one-time grid history file #1005

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
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
38 changes: 28 additions & 10 deletions cicecore/cicedyn/analysis/ice_history.F90
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ subroutine init_hist (dt)
use ice_domain_size, only: max_blocks, max_nstrm, nilyr, nslyr, nblyr, ncat, nfsd
use ice_dyn_shared, only: kdyn
use ice_flux, only: mlt_onset, frz_onset, albcnt, snwcnt
use ice_grid, only: grid_ice, &
use ice_grid, only: grid_ice, grid_outfile, &
grid_atm_thrm, grid_atm_dynu, grid_atm_dynv, &
grid_ocn_thrm, grid_ocn_dynu, grid_ocn_dynv
use ice_history_shared ! everything
Expand Down Expand Up @@ -239,15 +239,14 @@ subroutine init_hist (dt)
call get_fileunit(nu_nml)
open (nu_nml, file=trim(nml_filename), status='old',iostat=nml_error)
if (nml_error /= 0) then
call abort_ice(subname//'ERROR: '//trim(nml_name)//' open file '// &
trim(nml_filename), &
file=__FILE__, line=__LINE__)
call abort_ice(subname//' ERROR: '//trim(nml_name)//' open file '// &
trim(nml_filename), file=__FILE__, line=__LINE__)
endif

! seek to this namelist
call goto_nml(nu_nml,trim(nml_name),nml_error)
if (nml_error /= 0) then
call abort_ice(subname//'ERROR: searching for '// trim(nml_name), &
call abort_ice(subname//' ERROR: searching for '// trim(nml_name), &
file=__FILE__, line=__LINE__)
endif

Expand All @@ -260,7 +259,7 @@ subroutine init_hist (dt)
! backspace and re-read erroneous line
backspace(nu_nml)
read(nu_nml,fmt='(A)') tmpstr2
call abort_ice(subname//'ERROR: ' // trim(nml_name) // ' reading ' // &
call abort_ice(subname//' ERROR: ' // trim(nml_name) // ' reading ' // &
trim(tmpstr2), file=__FILE__, line=__LINE__)
endif
end do
Expand All @@ -278,23 +277,35 @@ subroutine init_hist (dt)
nstreams = nstreams + 1
if (ns >= 2) then
if (histfreq(ns-1) == 'x') then
call abort_ice(subname//'ERROR: histfreq all non x must be at start of array')
call abort_ice(subname//' ERROR: histfreq all non x must be at start of array', &
file=__FILE__, line=__LINE__)
endif
endif
else if (histfreq(ns) /= 'x') then
call abort_ice(subname//'ERROR: histfreq contains illegal element')
write(nu_diag, * ) subname,' ns,histfreq = ',ns,histfreq(ns)
call abort_ice(subname//' ERROR: histfreq contains illegal element', &
file=__FILE__, line=__LINE__)
endif
enddo
if (nstreams == 0) write (nu_diag,*) 'WARNING: No history output'
if (nstreams == 0 .and. my_task == master_task) write (nu_diag,*) subname,' WARNING: No history output'
do ns1 = 1, nstreams
do ns2 = 1, nstreams
if (histfreq(ns1) == histfreq(ns2) .and. ns1/=ns2 &
.and. my_task == master_task) then
call abort_ice(subname//'ERROR: histfreq elements must be unique')
call abort_ice(subname//' ERROR: histfreq elements must be unique', &
file=__FILE__, line=__LINE__)
endif
enddo
enddo

! Turn on one-time grid output file
if (grid_outfile) then
nstreams = nstreams + 1
histfreq(nstreams) = 'g'
hist_avg(nstreams) = .false.
if (my_task == master_task) write (nu_diag,*) subname,' Writing one-time grid file'
endif

if (.not. tr_iage) then
f_iage = 'x'
f_dagedtt = 'x'
Expand Down Expand Up @@ -4195,6 +4206,13 @@ subroutine accum_hist (dt)
enddo

endif ! write_history or write_ic

! Turn off one-time grid output file
if (histfreq(ns) == 'g') then
histfreq(ns) = 'x'
nstreams = nstreams - 1
endif

enddo ! nstreams

!$OMP PARALLEL DO PRIVATE(iblk,i,j,ilo,ihi,jlo,jhi,this_block)
Expand Down
16 changes: 13 additions & 3 deletions cicecore/cicedyn/analysis/ice_history_shared.F90
Original file line number Diff line number Diff line change
Expand Up @@ -822,12 +822,22 @@ subroutine construct_filename(ncfile,suffix,ns)
write(ncfile,'(a,a,i4.4,a,a)') &
history_file(1:lenstr(history_file))//trim(cstream),'.', &
iyear,'.',trim(suffix)
elseif (histfreq(ns) == 'g') then
write(ncfile,'(a,a,a,a)') &
history_file(1:lenstr(history_file))//trim(cstream),'_grid', &
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't see how cstream in this case would be anything other than empty ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In theory, a user could set the 6th element of hist_suffix in namelist and it would be used here, but that feature is certainly not advertised nor expected to be used. I will remove the "cstream" string from the grid history file so there is no chance of something odd happening here. Good catch.

'.',trim(suffix)
endif

else ! instantaneous
write(ncfile,'(a,a,i4.4,a,i2.2,a,i2.2,a,i5.5,a,a)') &
history_file(1:lenstr(history_file))//trim(cstream),'_inst.', &
iyear,'-',imonth,'-',iday,'-',msec,'.',trim(suffix)
if (histfreq(ns) == 'g') then
write(ncfile,'(a,a,a,a)') &
history_file(1:lenstr(history_file))//trim(cstream),'_grid', &
'.',trim(suffix)
else
write(ncfile,'(a,a,i4.4,a,i2.2,a,i2.2,a,i5.5,a,a)') &
history_file(1:lenstr(history_file))//trim(cstream),'_inst.', &
iyear,'-',imonth,'-',iday,'-',msec,'.',trim(suffix)
endif
endif

endif
Expand Down
26 changes: 16 additions & 10 deletions cicecore/cicedyn/general/ice_init.F90
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ subroutine input_data
grid_file, gridcpl_file, kmt_file, &
bathymetry_file, use_bathymetry, &
bathymetry_format, kmt_type, &
grid_type, grid_format, &
grid_type, grid_format, grid_outfile, &
grid_ice, grid_ice_thrm, grid_ice_dynu, grid_ice_dynv, &
grid_ocn, grid_ocn_thrm, grid_ocn_dynu, grid_ocn_dynv, &
grid_atm, grid_atm_thrm, grid_atm_dynu, grid_atm_dynv, &
Expand Down Expand Up @@ -217,7 +217,7 @@ subroutine input_data
ncat, nilyr, nslyr, nblyr, &
kcatbound, gridcpl_file, dxrect, dyrect, &
dxscale, dyscale, lonrefrect, latrefrect, &
scale_dxdy, &
scale_dxdy, grid_outfile, &
close_boundaries, orca_halogrid, grid_ice, kmt_type, &
grid_atm, grid_ocn

Expand Down Expand Up @@ -332,6 +332,7 @@ subroutine input_data
bfbflag = 'off' ! off = optimized
diag_type = 'stdout'
diag_file = 'ice_diag.d'
histfreq(:) = 'x'
histfreq(1) = '1' ! output frequency option for different streams
histfreq(2) = 'h' ! output frequency option for different streams
histfreq(3) = 'd' ! output frequency option for different streams
Expand Down Expand Up @@ -383,6 +384,7 @@ subroutine input_data
grid_atm = 'A' ! underlying atm forcing/coupling grid
grid_ocn = 'A' ! underlying atm forcing/coupling grid
gridcpl_file = 'unknown_gridcpl_file'
grid_outfile = .false. ! write out one-time grid history file
orca_halogrid = .false. ! orca haloed grid - deprecated
bathymetry_file = 'unknown_bathymetry_file'
bathymetry_format = 'default'
Expand Down Expand Up @@ -960,6 +962,7 @@ subroutine input_data
call broadcast_scalar(cpl_bgc, master_task)
call broadcast_scalar(incond_dir, master_task)
call broadcast_scalar(incond_file, master_task)
call broadcast_scalar(version_name, master_task)
call broadcast_scalar(dump_last, master_task)
call broadcast_scalar(restart_file, master_task)
call broadcast_scalar(restart, master_task)
Expand Down Expand Up @@ -992,6 +995,7 @@ subroutine input_data
call broadcast_scalar(grid_atm, master_task)
call broadcast_scalar(grid_file, master_task)
call broadcast_scalar(gridcpl_file, master_task)
call broadcast_scalar(grid_outfile, master_task)
call broadcast_scalar(orca_halogrid, master_task)
call broadcast_scalar(bathymetry_file, master_task)
call broadcast_scalar(bathymetry_format, master_task)
Expand Down Expand Up @@ -2524,6 +2528,7 @@ subroutine input_data
write(nu_diag,*) '===================================== '
if (trim(runid) /= 'unknown') &
write(nu_diag,1031) ' runid = ', trim(runid)
write(nu_diag,1031) ' version_name = ', trim(version_name)
write(nu_diag,1031) ' runtype = ', trim(runtype)
write(nu_diag,1021) ' year_init = ', year_init
write(nu_diag,1021) ' month_init = ', month_init
Expand All @@ -2546,11 +2551,12 @@ subroutine input_data
write(nu_diag,1031) ' bfbflag = ', trim(bfbflag)
write(nu_diag,1021) ' numin = ', numin
write(nu_diag,1021) ' numax = ', numax
write(nu_diag,1033) ' histfreq = ', histfreq(:)
write(nu_diag,1023) ' histfreq_n = ', histfreq_n(:)
write(nu_diag,1033) ' histfreq_base = ', histfreq_base(:)
write(nu_diag,1013) ' hist_avg = ', hist_avg(:)
write(nu_diag,1033) ' hist_suffix = ', hist_suffix(:)
write(nu_diag,1011) ' grid_outfile = ', grid_outfile
write(nu_diag,1033) ' histfreq = ', histfreq(1:max_nstrm-1)
write(nu_diag,1023) ' histfreq_n = ', histfreq_n(1:max_nstrm-1)
write(nu_diag,1033) ' histfreq_base = ', histfreq_base(1:max_nstrm-1)
write(nu_diag,1013) ' hist_avg = ', hist_avg(1:max_nstrm-1)
write(nu_diag,1033) ' hist_suffix = ', hist_suffix(1:max_nstrm-1)
write(nu_diag,1031) ' history_dir = ', trim(history_dir)
write(nu_diag,1031) ' history_file = ', trim(history_file)
write(nu_diag,1021) ' history_precision= ', history_precision
Expand All @@ -2566,9 +2572,9 @@ subroutine input_data
write(nu_diag,1039) ' Initial condition will be written in ', &
trim(incond_dir)
endif
write(nu_diag,1033) ' dumpfreq = ', dumpfreq(:)
write(nu_diag,1023) ' dumpfreq_n = ', dumpfreq_n(:)
write(nu_diag,1033) ' dumpfreq_base = ', dumpfreq_base(:)
write(nu_diag,1033) ' dumpfreq = ', dumpfreq(1:max_nstrm-1)
write(nu_diag,1023) ' dumpfreq_n = ', dumpfreq_n(1:max_nstrm-1)
write(nu_diag,1033) ' dumpfreq_base = ', dumpfreq_base(1:max_nstrm-1)
write(nu_diag,1011) ' dump_last = ', dump_last
write(nu_diag,1011) ' restart = ', restart
write(nu_diag,1031) ' restart_dir = ', trim(restart_dir)
Expand Down
1 change: 1 addition & 0 deletions cicecore/cicedyn/infrastructure/ice_grid.F90
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ module ice_grid
kmt ! ocean topography mask for bathymetry (T-cell)

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