Skip to content

Commit

Permalink
Precision (#446)
Browse files Browse the repository at this point in the history
* Add history_precision option for history files.

* Update to work with pio2

* Precision updates

* Fix missing value precision

* Add documentation

* revert the Macros and env

* revert cice.build

* Move abort statement for history_precision
  • Loading branch information
dabail10 authored May 20, 2020
1 parent bce31c2 commit 9ead578
Show file tree
Hide file tree
Showing 14 changed files with 437 additions and 150 deletions.
2 changes: 2 additions & 0 deletions cicecore/cicedynB/analysis/ice_history_shared.F90
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ module ice_history_shared
private
public :: define_hist_field, accum_hist_field, icefields_nml, construct_filename

integer (kind=int_kind), public :: history_precision

logical (kind=log_kind), public :: &
hist_avg ! if true, write averaged data instead of snapshots

Expand Down
13 changes: 11 additions & 2 deletions cicecore/cicedynB/general/ice_init.F90
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ subroutine input_data
restart, restart_ext, restart_dir, restart_file, pointer_file, &
runid, runtype, use_restart_time, restart_format, lcdf64
use ice_history_shared, only: hist_avg, history_dir, history_file, &
incond_dir, incond_file, version_name
incond_dir, incond_file, version_name, &
history_precision
use ice_flux, only: update_ocn_f, l_mpond_fresh
use ice_flux, only: default_season
use ice_flux_bgc, only: cpl_bgc
Expand Down Expand Up @@ -152,7 +153,7 @@ subroutine input_data
diagfreq, diag_type, diag_file, &
print_global, print_points, latpnt, lonpnt, &
dbug, histfreq, histfreq_n, hist_avg, &
history_dir, history_file, cpl_bgc, &
history_dir, history_file, history_precision, cpl_bgc, &
write_ic, incond_dir, incond_file, version_name

namelist /grid_nml/ &
Expand Down Expand Up @@ -251,6 +252,7 @@ subroutine input_data
hist_avg = .true. ! if true, write time-averages (not snapshots)
history_dir = './' ! write to executable dir for default
history_file = 'iceh' ! history file name prefix
history_precision = 4 ! precision of history files
write_ic = .false. ! write out initial condition
cpl_bgc = .false. ! history file name prefix
incond_dir = history_dir ! write to history dir for default
Expand Down Expand Up @@ -536,6 +538,7 @@ subroutine input_data
call broadcast_scalar(hist_avg, master_task)
call broadcast_scalar(history_dir, master_task)
call broadcast_scalar(history_file, master_task)
call broadcast_scalar(history_precision, master_task)
call broadcast_scalar(write_ic, master_task)
call broadcast_scalar(cpl_bgc, master_task)
call broadcast_scalar(incond_dir, master_task)
Expand Down Expand Up @@ -935,6 +938,11 @@ subroutine input_data
abort_flag = 19
endif

if(history_precision .ne. 4 .and. history_precision .ne. 8) then
write (nu_diag,*) 'ERROR: bad value for history_precision, allowed values: 4, 8'
abort_flag = 22
endif

if (.not.(trim(dumpfreq) == 'y' .or. trim(dumpfreq) == 'Y' .or. &
trim(dumpfreq) == 'm' .or. trim(dumpfreq) == 'M' .or. &
trim(dumpfreq) == 'd' .or. trim(dumpfreq) == 'D' .or. &
Expand Down Expand Up @@ -993,6 +1001,7 @@ subroutine input_data
trim(history_dir)
write(nu_diag,*) ' history_file = ', &
trim(history_file)
write(nu_diag,1020) ' history_precision = ', history_precision
if (write_ic) then
write(nu_diag,*) 'Initial condition will be written in ', &
trim(incond_dir)
Expand Down
27 changes: 17 additions & 10 deletions cicecore/cicedynB/infrastructure/io/io_binary/ice_history_write.F90
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ subroutine ice_write_hist(ns)

integer (kind=int_kind) :: icategory,i_aice

character (len=4) :: &
atype ! format for output array
! (real/integer, 4-byte/8-byte)

character (char_len) :: current_date,current_time
character (len=16) :: c_aice
logical (kind=log_kind) :: diag
Expand All @@ -70,6 +74,9 @@ subroutine ice_write_hist(ns)

diag = .false.

atype = 'rda4'
if (history_precision == 8) atype = 'rda8'

if (my_task == master_task) then

call construct_filename(ncfile(ns),'da',ns)
Expand Down Expand Up @@ -124,7 +131,7 @@ subroutine ice_write_hist(ns)
write (nu_hdr, 996) nrec,'tarea','area of T grid cells','m^2'
write (nu_hdr, * ) 'History variables: (left column = nrec)'
endif ! my_task = master_task
call ice_write(nu_history, nrec, tarea, 'rda4', diag)
call ice_write(nu_history, nrec, tarea, atype, diag)

do n=1,num_avail_hist_fields_2D
if (avail_hist_fields(n)%vhistfreq == histfreq(ns)) then
Expand Down Expand Up @@ -160,7 +167,7 @@ subroutine ice_write_hist(ns)
endif
endif

call ice_write(nu_history, nrec, a2D(:,:,n,:), 'rda4', diag)
call ice_write(nu_history, nrec, a2D(:,:,n,:), atype, diag)

endif
enddo ! num_avail_hist_fields_2D
Expand All @@ -183,7 +190,7 @@ subroutine ice_write_hist(ns)
endif
endif

call ice_write(nu_history, nrec, a3Dc(:,:,nn,n-n2D,:), 'rda4', diag)
call ice_write(nu_history, nrec, a3Dc(:,:,nn,n-n2D,:), atype, diag)
enddo ! ncat

endif
Expand All @@ -207,7 +214,7 @@ subroutine ice_write_hist(ns)
endif
endif

call ice_write(nu_history, nrec, a3Dz(:,:,k,n-n3Dccum,:), 'rda4', diag)
call ice_write(nu_history, nrec, a3Dz(:,:,k,n-n3Dccum,:), atype, diag)
enddo ! nzilyr

endif
Expand All @@ -231,7 +238,7 @@ subroutine ice_write_hist(ns)
endif
endif

call ice_write(nu_history, nrec, a3Db(:,:,k,n-n3Dzcum,:), 'rda4', diag)
call ice_write(nu_history, nrec, a3Db(:,:,k,n-n3Dzcum,:), atype, diag)
enddo ! nzilyr

endif
Expand All @@ -255,7 +262,7 @@ subroutine ice_write_hist(ns)
endif
endif

call ice_write(nu_history, nrec, a3Da(:,:,k,n-n3Dbcum,:), 'rda4', diag)
call ice_write(nu_history, nrec, a3Da(:,:,k,n-n3Dbcum,:), atype, diag)
enddo ! nzilyr

endif
Expand All @@ -279,7 +286,7 @@ subroutine ice_write_hist(ns)
endif
endif

call ice_write(nu_history, nrec, a3Df(:,:,k,n-n3Dacum,:), 'rda4', diag)
call ice_write(nu_history, nrec, a3Df(:,:,k,n-n3Dacum,:), atype, diag)
enddo ! nfsd_hist

endif
Expand All @@ -304,7 +311,7 @@ subroutine ice_write_hist(ns)
endif
endif

call ice_write(nu_history, nrec, a4Di(:,:,k,nn,n-n3Dfcum,:), 'rda4', diag)
call ice_write(nu_history, nrec, a4Di(:,:,k,nn,n-n3Dfcum,:), atype, diag)
enddo ! nzilyr
enddo ! ncat_hist

Expand All @@ -330,7 +337,7 @@ subroutine ice_write_hist(ns)
endif
endif

call ice_write(nu_history, nrec, a4Ds(:,:,k,nn,n-n4Dicum,:), 'rda4', diag)
call ice_write(nu_history, nrec, a4Ds(:,:,k,nn,n-n4Dicum,:), atype, diag)
enddo ! nzilyr
enddo ! ncat_hist

Expand All @@ -356,7 +363,7 @@ subroutine ice_write_hist(ns)
endif
endif

call ice_write(nu_history, nrec, a4Df(:,:,k,nn,n-n4Dscum,:), 'rda4', diag)
call ice_write(nu_history, nrec, a4Df(:,:,k,nn,n-n4Dscum,:), atype, diag)
enddo ! nfsd_hist
enddo ! ncat_hist

Expand Down
Loading

0 comments on commit 9ead578

Please sign in to comment.