diff --git a/cicecore/cicedyn/analysis/ice_history_shared.F90 b/cicecore/cicedyn/analysis/ice_history_shared.F90 index 197ed4f66..ac2cf8afb 100644 --- a/cicecore/cicedyn/analysis/ice_history_shared.F90 +++ b/cicecore/cicedyn/analysis/ice_history_shared.F90 @@ -62,11 +62,9 @@ module ice_history_shared integer (kind=int_kind), public :: & history_iotasks , & ! iotasks, root, stride defines io pes for pio history_root , & ! iotasks, root, stride defines io pes for pio - history_stride ! iotasks, root, stride defines io pes for pio - - integer (kind=int_kind), public :: history_deflate ! compression level for netcdf4 - - integer (kind=int_kind), dimension(2), public :: history_chunksize ! chunksize for netcdf4 + history_stride , & ! iotasks, root, stride defines io pes for pio + history_deflate , & ! compression level for hdf5/netcdf4 + history_chunksize(2) ! chunksize for hdf5/netcdf4 !--------------------------------------------------------------- ! Instructions for adding a field: (search for 'example') diff --git a/cicecore/cicedyn/general/ice_init.F90 b/cicecore/cicedyn/general/ice_init.F90 index 7f84ac636..73980683c 100644 --- a/cicecore/cicedyn/general/ice_init.F90 +++ b/cicecore/cicedyn/general/ice_init.F90 @@ -350,7 +350,7 @@ subroutine input_data history_file = 'iceh' ! history file name prefix history_precision = 4 ! precision of history files history_deflate = 0 ! compression level for netcdf4 - history_chunksize = (/0,0/) ! chunksize for netcdf4 + history_chunksize(:) = 0 ! chunksize for netcdf4 write_ic = .false. ! write out initial condition cpl_bgc = .false. ! couple bgc thru driver incond_dir = history_dir ! write to history dir for default @@ -372,7 +372,7 @@ subroutine input_data restart_iotasks = -99 ! restart iotasks, root, stride sets pes for pio restart_rearranger = 'default' ! restart rearranger for pio restart_deflate = 0 ! compression level for netcdf4 - restart_chunksize = (/0,0/) ! chunksize for netcdf4 + restart_chunksize(:) = 0 ! chunksize for netcdf4 lcdf64 = .false. ! 64 bit offset for netCDF ice_ic = 'default' ! latitude and sst-dependent grid_format = 'bin' ! file format ('bin'=binary or 'nc'=netcdf) @@ -953,8 +953,7 @@ subroutine input_data call broadcast_scalar(history_rearranger, master_task) call broadcast_scalar(hist_time_axis, master_task) call broadcast_scalar(history_deflate, master_task) - call broadcast_scalar(history_chunksize(1), master_task) - call broadcast_scalar(history_chunksize(2), master_task) + call broadcast_array(history_chunksize, master_task) call broadcast_scalar(write_ic, master_task) call broadcast_scalar(cpl_bgc, master_task) call broadcast_scalar(incond_dir, master_task) @@ -972,8 +971,7 @@ subroutine input_data call broadcast_scalar(restart_stride, master_task) call broadcast_scalar(restart_rearranger, master_task) call broadcast_scalar(restart_deflate, master_task) - call broadcast_scalar(restart_chunksize(1), master_task) - call broadcast_scalar(restart_chunksize(2), master_task) + call broadcast_array(restart_chunksize, master_task) call broadcast_scalar(lcdf64, master_task) call broadcast_scalar(pointer_file, master_task) call broadcast_scalar(ice_ic, master_task) @@ -1769,26 +1767,10 @@ subroutine input_data if (history_deflate/=0 .or. restart_deflate/=0 & .or. history_chunksize(1)/=0 .or. history_chunksize(2)/=0 & .or. restart_chunksize(1)/=0 .or. restart_chunksize(2)/=0) then - if (my_task == master_task) then - write (nu_diag,*) subname//' WARNING: _deflate and _chunksize not compatible with PIO1, will be ignored' - endif -#else - if(history_deflate<0 .or. history_deflate>9) then - if (my_task == master_task) then - write (nu_diag,*) subname//' WARNING: history_deflate value not valid, setting to 0 ' - write (nu_diag,*) subname//' WARNING: Allowed range: integers from 0 to 9 ' - endif - history_deflate=0 - endif - - if(restart_deflate<0 .or. restart_deflate>9) then - if (my_task == master_task) then - write (nu_diag,*) subname//' WARNING: restart_deflate value not valid, setting to 0 ' - write (nu_diag,*) subname//' WARNING: Allowed range: integers from 0 to 9 ' - endif - restart_deflate=0 + if (my_task == master_task) write (nu_diag,*) subname//' ERROR: _deflate and _chunksize not compatible with PIO1' + abort_list = trim(abort_list)//":54" endif - +#else #ifndef CESMCOUPLED ! history_format not used by nuopc driver if (history_format/='hdf5' .and. history_deflate/=0) then @@ -1796,7 +1778,6 @@ subroutine input_data write (nu_diag,*) subname//' WARNING: history_deflate not compatible with '//history_format write (nu_diag,*) subname//' WARNING: netcdf compression only possible with history_type="hdf5" ' endif - history_deflate=0 endif if (history_format/='hdf5' .and. (history_chunksize(1)/=0 .or. history_chunksize(2)/=0)) then @@ -1811,7 +1792,6 @@ subroutine input_data write (nu_diag,*) subname//' WARNING: restart_deflate not compatible with '//restart_format write (nu_diag,*) subname//' WARNING: netcdf compression only possible with restart_type="hdf5" ' endif - restart_deflate=0 endif if (restart_format/='hdf5' .and. (restart_chunksize(1)/=0 .or. restart_chunksize(2)/=0)) then @@ -1820,8 +1800,19 @@ subroutine input_data write (nu_diag,*) subname//' WARNING: netcdf chunking only possible with restart_type="hdf5" ' endif endif - #endif + + if(history_deflate<0 .or. history_deflate>9) then + if (my_task == master_task) write (nu_diag,*) subname//& + ' ERROR: history_deflate value not valid. Allowed range: integers from 0 to 9 ' + abort_list = trim(abort_list)//":55" + endif + + if(restart_deflate<0 .or. restart_deflate>9) then + if (my_task == master_task) write (nu_diag,*) subname//& + ' ERROR: restart_deflate value not valid. Allowed range: integers from 0 to 9 ' + abort_list = trim(abort_list)//":56" + endif #endif ! Implicit solver input validation diff --git a/cicecore/cicedyn/infrastructure/io/io_netcdf/ice_history_write.F90 b/cicecore/cicedyn/infrastructure/io/io_netcdf/ice_history_write.F90 index 1dcee39ac..4827a8f8f 100644 --- a/cicecore/cicedyn/infrastructure/io/io_netcdf/ice_history_write.F90 +++ b/cicecore/cicedyn/infrastructure/io/io_netcdf/ice_history_write.F90 @@ -45,6 +45,8 @@ module ice_history_write public :: ice_write_hist + integer (kind=int_kind) :: imtid,jmtid + !======================================================================= contains @@ -90,7 +92,7 @@ subroutine ice_write_hist (ns) real (kind=dbl_kind), dimension(nx_block,ny_block,max_blocks) :: work1 integer (kind=int_kind) :: i,k,ic,n,nn, & - ncid,status,imtid,jmtid,kmtidi,kmtids,kmtidb, cmtid,timid,varid, & + ncid,status,kmtidi,kmtids,kmtidb, cmtid,timid,varid, & nvertexid,ivertex,kmtida,iflag, fmtid integer (kind=int_kind), dimension(3) :: dimid integer (kind=int_kind), dimension(4) :: dimidz @@ -454,9 +456,9 @@ subroutine ice_write_hist (ns) endif enddo - !----------------------------------------------------------------- - ! define attributes for time-variant variables - !----------------------------------------------------------------- + !----------------------------------------------------------------- + ! define attributes for time-variant variables + !----------------------------------------------------------------- do n=1,num_avail_hist_fields_2D if (avail_hist_fields(n)%vhistfreq == histfreq(ns) .or. write_ic) then @@ -475,7 +477,10 @@ subroutine ice_write_hist (ns) endif enddo ! num_avail_hist_fields_3Dc + dimidz(1) = imtid + dimidz(2) = jmtid dimidz(3) = kmtidi + dimidz(4) = timid do n = n3Dccum + 1, n3Dzcum if (avail_hist_fields(n)%vhistfreq == histfreq(ns) .or. write_ic) then @@ -483,7 +488,10 @@ subroutine ice_write_hist (ns) endif enddo ! num_avail_hist_fields_3Dz + dimidz(1) = imtid + dimidz(2) = jmtid dimidz(3) = kmtidb + dimidz(4) = timid do n = n3Dzcum + 1, n3Dbcum if (avail_hist_fields(n)%vhistfreq == histfreq(ns) .or. write_ic) then @@ -491,7 +499,10 @@ subroutine ice_write_hist (ns) endif enddo ! num_avail_hist_fields_3Db + dimidz(1) = imtid + dimidz(2) = jmtid dimidz(3) = kmtida + dimidz(4) = timid do n = n3Dbcum + 1, n3Dacum if (avail_hist_fields(n)%vhistfreq == histfreq(ns) .or. write_ic) then @@ -499,7 +510,10 @@ subroutine ice_write_hist (ns) endif enddo ! num_avail_hist_fields_3Da + dimidz(1) = imtid + dimidz(2) = jmtid dimidz(3) = fmtid + dimidz(4) = timid do n = n3Dacum + 1, n3Dfcum if (avail_hist_fields(n)%vhistfreq == histfreq(ns) .or. write_ic) then @@ -519,7 +533,11 @@ subroutine ice_write_hist (ns) endif enddo ! num_avail_hist_fields_4Di + dimidcz(1) = imtid + dimidcz(2) = jmtid dimidcz(3) = kmtids + dimidcz(4) = cmtid + dimidcz(5) = timid do n = n4Dicum + 1, n4Dscum if (avail_hist_fields(n)%vhistfreq == histfreq(ns) .or. write_ic) then @@ -527,7 +545,11 @@ subroutine ice_write_hist (ns) endif enddo ! num_avail_hist_fields_4Ds + dimidcz(1) = imtid + dimidcz(2) = jmtid dimidcz(3) = fmtid + dimidcz(4) = cmtid + dimidcz(5) = timid do n = n4Dscum + 1, n4Dfcum if (avail_hist_fields(n)%vhistfreq == histfreq(ns) .or. write_ic) then @@ -1155,7 +1177,7 @@ subroutine ice_hist_field_def(ncid, hfield, lprecision, dimids, ns) history_precision, hist_avg use ice_calendar, only: histfreq, histfreq_n, write_ic #ifdef USE_NETCDF - use netcdf, only: NF90_CHUNKED, nf90_def_var, nf90_put_att + use netcdf, only: NF90_CHUNKED, nf90_def_var, nf90_put_att, nf90_def_var_chunking, nf90_def_var_deflate integer(kind=int_kind), intent(in) :: ncid, dimids(:), lprecision, ns type(ice_hist_field), intent(in) :: hfield @@ -1164,24 +1186,25 @@ subroutine ice_hist_field_def(ncid, hfield, lprecision, dimids, ns) integer(kind=int_kind) :: chunks(size(dimids)), i, status, varid character(len=*), parameter :: subname = '(ice_hist_field_def)' - - if (history_format=='hdf5') then - chunks(1)=history_chunksize(1) - chunks(2)=history_chunksize(2) - do i = 3, size(dimids) - chunks(i) = 0 - enddo - status = nf90_def_var(ncid, hfield%vname, & - lprecision, dimids, varid, & - chunksizes=chunks, deflate_level=history_deflate) - call ice_check_nc(status, & - subname//' ERROR: defining var '//hfield%vname,file=__FILE__,line=__LINE__) - else - ! no chunk and compress - status = nf90_def_var(ncid, hfield%vname, & - lprecision, dimids, varid) - call ice_check_nc(status, & - subname//' ERROR: defining var '//hfield%vname,file=__FILE__,line=__LINE__) + + status = nf90_def_var(ncid, hfield%vname, lprecision, dimids, varid) + call ice_check_nc(status, subname//' ERROR: defining var '//trim(hfield%vname),file=__FILE__,line=__LINE__) + + if (history_format=='hdf5' .and. size(dimids)>1) then + if (dimids(1)==imtid .and. dimids(2)==jmtid) then + chunks(1)=history_chunksize(1) + chunks(2)=history_chunksize(2) + do i = 3, size(dimids) + chunks(i) = 0 + enddo + status = nf90_def_var_chunking(ncid,varid, NF90_CHUNKED, chunksizes=chunks) + call ice_check_nc(status, subname//' ERROR chunking var '//trim(hfield%vname), file=__FILE__, line=__LINE__) + endif + endif + + if (history_format=='hdf5' .and. history_deflate/=0) then + status=nf90_def_var_deflate(ncid, varid, shuffle=0, deflate=1, deflate_level=history_deflate) + call ice_check_nc(status, subname//' ERROR deflating var '//trim(hfield%vname), file=__FILE__, line=__LINE__) endif ! add attributes @@ -1300,32 +1323,39 @@ end subroutine ice_write_hist_fill subroutine ice_hist_coord_def(ncid, coord, lprecision, dimids, varid) - use ice_history_shared, only: history_deflate, history_format + use ice_history_shared, only: history_deflate, history_format, history_chunksize #ifdef USE_NETCDF - use netcdf, only: nf90_def_var, nf90_put_att + use netcdf, only: nf90_def_var, nf90_put_att, nf90_def_var_chunking, nf90_def_var_deflate, NF90_CHUNKED integer(kind=int_kind), intent(in) :: ncid, dimids(:), lprecision type(coord_attributes), intent(in) :: coord integer(kind=int_kind), intent(inout) :: varid !local vars - integer(kind=int_kind) :: status + integer(kind=int_kind) ::chunks(size(dimids)), i, status character(len=*), parameter :: subname = '(ice_hist_coord_def)' + + status = nf90_def_var(ncid, coord%short_name, lprecision, dimids, varid) + call ice_check_nc(status, subname//' ERROR: defining coord '//coord%short_name,file=__FILE__,line=__LINE__) - !define var, set deflate, long_name and units - if (history_format=='hdf5' .and. size(dimids)>1 ) then - status = nf90_def_var(ncid, trim(coord%short_name), & - lprecision, dimids, varid, deflate_level=history_deflate) - call ice_check_nc(status, & - subname//' ERROR: defining coord '//coord%short_name,file=__FILE__,line=__LINE__) - else - ! no compress - status = nf90_def_var(ncid, coord%short_name, & - lprecision, dimids, varid) - call ice_check_nc(status, & - subname//' ERROR: defining coord '//coord%short_name,file=__FILE__,line=__LINE__) + if (history_format=='hdf5' .and. size(dimids)>1) then + if (dimids(1)==imtid .and. dimids(2)==jmtid) then + chunks(1)=history_chunksize(1) + chunks(2)=history_chunksize(2) + do i = 3, size(dimids) + chunks(i) = 0 + enddo + status = nf90_def_var_chunking(ncid,varid, NF90_CHUNKED, chunksizes=chunks) + call ice_check_nc(status, subname//' ERROR chunking var '//trim(coord%short_name), file=__FILE__, line=__LINE__) + endif + endif + + if (history_format=='hdf5' .and. history_deflate/=0) then + status=nf90_def_var_deflate(ncid, varid, shuffle=0, deflate=1, deflate_level=history_deflate) + call ice_check_nc(status, subname//' ERROR deflating var '//trim(coord%short_name), file=__FILE__, line=__LINE__) endif + status = nf90_put_att(ncid,varid,'long_name',trim(coord%long_name)) call ice_check_nc(status, subname// ' ERROR: defining long_name for '//coord%short_name, & file=__FILE__, line=__LINE__) diff --git a/cicecore/cicedyn/infrastructure/io/io_netcdf/ice_restart.F90 b/cicecore/cicedyn/infrastructure/io/io_netcdf/ice_restart.F90 index 3059ac359..ebc05dedc 100644 --- a/cicecore/cicedyn/infrastructure/io/io_netcdf/ice_restart.F90 +++ b/cicecore/cicedyn/infrastructure/io/io_netcdf/ice_restart.F90 @@ -30,10 +30,12 @@ module ice_restart implicit none private public :: init_restart_write, init_restart_read, & - read_restart_field, write_restart_field, final_restart, & - query_field + read_restart_field, write_restart_field, final_restart, & + query_field - integer (kind=int_kind) :: ncid + integer (kind=int_kind) :: ncid , & + dimid_ni, & ! netCDF identifiers + dimid_nj !======================================================================= @@ -170,8 +172,7 @@ subroutine init_restart_write(filename_spec) integer (kind=int_kind), allocatable :: dims(:) integer (kind=int_kind) :: & - dimid_ni, & ! netCDF identifiers - dimid_nj, & ! + dimid_ncat, & ! iflag, & ! netCDF creation flag status ! status variable from netCDF routine @@ -890,18 +891,26 @@ subroutine define_rest_field(ncid, vname, dims) #ifdef USE_NETCDF - if (restart_format=='hdf5') then - chunks(1)=restart_chunksize(1) - chunks(2)=restart_chunksize(2) - do i = 3, size(dims) - chunks(i) = 0 - enddo - status = nf90_def_var(ncid,trim(vname),nf90_double,dims,varid, & - chunksizes=chunks, deflate_level=restart_deflate) - else - status = nf90_def_var(ncid,trim(vname),nf90_double,dims,varid) - end if + status = nf90_def_var(ncid,trim(vname),nf90_double,dims,varid) call ice_check_nc(status, subname//' ERROR: def var '//trim(vname), file=__FILE__, line=__LINE__) + + if (restart_format=='hdf5' .and. size(dims)>1) then + if (dims(1)==dimid_ni .and. dims(2)==dimid_nj) then + chunks(1)=restart_chunksize(1) + chunks(2)=restart_chunksize(2) + do i = 3, size(dims) + chunks(i) = 0 + enddo + status = nf90_def_var_chunking(ncid,varid, NF90_CHUNKED, chunksizes=chunks) + call ice_check_nc(status, subname//' ERROR: chunking var '//trim(vname), file=__FILE__, line=__LINE__) + endif + endif + + if (restart_format=='hdf5' .and. restart_deflate/=0) then + status=nf90_def_var_deflate(ncid, varid, shuffle=0, deflate=1, deflate_level=restart_deflate) + call ice_check_nc(status, subname//' ERROR deflating var '//trim(vname), file=__FILE__, line=__LINE__) + endif + #else call abort_ice(subname//' ERROR: USE_NETCDF cpp not defined', & file=__FILE__, line=__LINE__) diff --git a/cicecore/cicedyn/infrastructure/io/io_pio2/ice_history_write.F90 b/cicecore/cicedyn/infrastructure/io/io_pio2/ice_history_write.F90 index f03844d0a..1c9650b57 100644 --- a/cicecore/cicedyn/infrastructure/io/io_pio2/ice_history_write.F90 +++ b/cicecore/cicedyn/infrastructure/io/io_pio2/ice_history_write.F90 @@ -42,7 +42,6 @@ module ice_history_write public :: ice_write_hist - integer (kind=int_kind) :: deflate , shuffle = 0 integer (kind=int_kind) :: imtid,jmtid !======================================================================= @@ -193,13 +192,6 @@ subroutine ice_write_hist (ns) ! option of turning on double precision history files lprecision = pio_real if (history_precision == 8) lprecision = pio_double - - ! option to deflate netcdf4 iotypes - if (history_deflate/=0 .and. history_format=='hdf5') then - deflate = 1 - else - deflate = 0 - endif !----------------------------------------------------------------- ! define dimensions @@ -479,95 +471,114 @@ subroutine ice_write_hist (ns) !----------------------------------------------------------------- ! 2D - dimid3(1) = imtid - dimid3(2) = jmtid - dimid3(3) = timid + dimid3(1) = imtid + dimid3(2) = jmtid + dimid3(3) = timid - do n=1,num_avail_hist_fields_2D - if (avail_hist_fields(n)%vhistfreq == histfreq(ns) .or. write_ic) then - call ice_hist_field_def(File, avail_hist_fields(n),lprecision, dimid3, ns) - endif - enddo + do n=1,num_avail_hist_fields_2D + if (avail_hist_fields(n)%vhistfreq == histfreq(ns) .or. write_ic) then + call ice_hist_field_def(File, avail_hist_fields(n),lprecision, dimid3, ns) + endif + enddo - ! 3D (category) - dimidz(1) = imtid - dimidz(2) = jmtid - dimidz(3) = cmtid - dimidz(4) = timid + ! 3D (category) + dimidz(1) = imtid + dimidz(2) = jmtid + dimidz(3) = cmtid + dimidz(4) = timid - do n = n2D + 1, n3Dccum - if (avail_hist_fields(n)%vhistfreq == histfreq(ns) .or. write_ic) then - call ice_hist_field_def(File, avail_hist_fields(n),lprecision, dimidz,ns) - endif - enddo ! num_avail_hist_fields_3Dc + do n = n2D + 1, n3Dccum + if (avail_hist_fields(n)%vhistfreq == histfreq(ns) .or. write_ic) then + call ice_hist_field_def(File, avail_hist_fields(n),lprecision, dimidz,ns) + endif + enddo ! num_avail_hist_fields_3Dc - ! 3D (ice layers) - dimidz(3) = kmtidi - - do n = n3Dccum + 1, n3Dzcum - if (avail_hist_fields(n)%vhistfreq == histfreq(ns) .or. write_ic) then - call ice_hist_field_def(File, avail_hist_fields(n),lprecision, dimidz,ns) - endif - enddo ! num_avail_hist_fields_3Dz + ! 3D (ice layers) + dimidz(1) = imtid + dimidz(2) = jmtid + dimidz(3) = kmtidi + dimidz(4) = timid + + do n = n3Dccum + 1, n3Dzcum + if (avail_hist_fields(n)%vhistfreq == histfreq(ns) .or. write_ic) then + call ice_hist_field_def(File, avail_hist_fields(n),lprecision, dimidz,ns) + endif + enddo ! num_avail_hist_fields_3Dz - ! 3D (biology ice layers) - dimidz(3) = kmtidb - - do n = n3Dzcum + 1, n3Dbcum - if (avail_hist_fields(n)%vhistfreq == histfreq(ns) .or. write_ic) then - call ice_hist_field_def(File, avail_hist_fields(n),lprecision, dimidz,ns) - endif - enddo ! num_avail_hist_fields_3Db + ! 3D (biology ice layers) + dimidz(1) = imtid + dimidz(2) = jmtid + dimidz(3) = kmtidb + dimidz(4) = timid + + do n = n3Dzcum + 1, n3Dbcum + if (avail_hist_fields(n)%vhistfreq == histfreq(ns) .or. write_ic) then + call ice_hist_field_def(File, avail_hist_fields(n),lprecision, dimidz,ns) + endif + enddo ! num_avail_hist_fields_3Db - ! 3D (biology snow layers) - dimidz(3) = kmtida - - do n = n3Dbcum + 1, n3Dacum - if (avail_hist_fields(n)%vhistfreq == histfreq(ns) .or. write_ic) then - call ice_hist_field_def(File, avail_hist_fields(n),lprecision, dimidz,ns) - endif - enddo ! num_avail_hist_fields_3Da + ! 3D (biology snow layers) + dimidz(1) = imtid + dimidz(2) = jmtid + dimidz(3) = kmtida + dimidz(4) = timid + + do n = n3Dbcum + 1, n3Dacum + if (avail_hist_fields(n)%vhistfreq == histfreq(ns) .or. write_ic) then + call ice_hist_field_def(File, avail_hist_fields(n),lprecision, dimidz,ns) + endif + enddo ! num_avail_hist_fields_3Da - ! 3D (fsd) - dimidz(3) = fmtid - - do n = n3Dacum + 1, n3Dfcum - if (avail_hist_fields(n)%vhistfreq == histfreq(ns) .or. write_ic) then - call ice_hist_field_def(File, avail_hist_fields(n),lprecision, dimidz,ns) - endif - enddo ! num_avail_hist_fields_3Df + ! 3D (fsd) + dimidz(1) = imtid + dimidz(2) = jmtid + dimidz(3) = fmtid + dimidz(4) = timid + + do n = n3Dacum + 1, n3Dfcum + if (avail_hist_fields(n)%vhistfreq == histfreq(ns) .or. write_ic) then + call ice_hist_field_def(File, avail_hist_fields(n),lprecision, dimidz,ns) + endif + enddo ! num_avail_hist_fields_3Df ! 4D (ice categories) - - dimidcz(1) = imtid - dimidcz(2) = jmtid - dimidcz(3) = kmtidi - dimidcz(4) = cmtid - dimidcz(5) = timid - - do n = n3Dfcum + 1, n4Dicum - if (avail_hist_fields(n)%vhistfreq == histfreq(ns) .or. write_ic) then - call ice_hist_field_def(File, avail_hist_fields(n),lprecision, dimidcz,ns) - endif - enddo ! num_avail_hist_fields_4Di + dimidcz(1) = imtid + dimidcz(2) = jmtid + dimidcz(3) = kmtidi + dimidcz(4) = cmtid + dimidcz(5) = timid - ! 4D (snow layers) - dimidcz(3) = kmtids - - do n = n4Dicum + 1, n4Dscum - if (avail_hist_fields(n)%vhistfreq == histfreq(ns) .or. write_ic) then - call ice_hist_field_def(File, avail_hist_fields(n),lprecision, dimidcz,ns) - endif - enddo ! num_avail_hist_fields_4Ds + do n = n3Dfcum + 1, n4Dicum + if (avail_hist_fields(n)%vhistfreq == histfreq(ns) .or. write_ic) then + call ice_hist_field_def(File, avail_hist_fields(n),lprecision, dimidcz,ns) + endif + enddo ! num_avail_hist_fields_4Di + + ! 4D (snow layers) + dimidcz(1) = imtid + dimidcz(2) = jmtid + dimidcz(3) = kmtids + dimidcz(4) = cmtid + dimidcz(5) = timid + + do n = n4Dicum + 1, n4Dscum + if (avail_hist_fields(n)%vhistfreq == histfreq(ns) .or. write_ic) then + call ice_hist_field_def(File, avail_hist_fields(n),lprecision, dimidcz,ns) + endif + enddo ! num_avail_hist_fields_4Ds ! 4D (fsd layers) - dimidcz(3) = fmtid + dimidcz(1) = imtid + dimidcz(2) = jmtid + dimidcz(3) = fmtid + dimidcz(4) = cmtid + dimidcz(5) = timid - do n = n4Dscum + 1, n4Dfcum - if (avail_hist_fields(n)%vhistfreq == histfreq(ns) .or. write_ic) then - call ice_hist_field_def(File, avail_hist_fields(n),lprecision, dimidcz,ns) - endif - enddo ! num_avail_hist_fields_4Df + do n = n4Dscum + 1, n4Dfcum + if (avail_hist_fields(n)%vhistfreq == histfreq(ns) .or. write_ic) then + call ice_hist_field_def(File, avail_hist_fields(n),lprecision, dimidcz,ns) + endif + enddo ! num_avail_hist_fields_4Df !----------------------------------------------------------------- ! global attributes @@ -1269,21 +1280,23 @@ subroutine ice_hist_coord_def(File, coord,lprecision, dimids,varid) call ice_pio_check(status, & subname//' ERROR: defining coord '//coord%short_name,file=__FILE__,line=__LINE__) #ifndef USE_PIO1 - if (deflate==1 .and. size(dimids)>1 ) then - status = pio_def_var_deflate(File, varid, shuffle, deflate ,history_deflate) + if (history_deflate/=0 .and. history_format=='hdf5') then + status = pio_def_var_deflate(File, varid, shuffle=0, deflate=1, deflate_level=history_deflate) call ice_pio_check(status, & subname//' ERROR: deflating coord '//coord%short_name,file=__FILE__,line=__LINE__) endif - if (history_format=='hdf5' .and. dimids(1)==imtid .and. dimids(2)==jmtid) then - chunks(1)=history_chunksize(1) - chunks(2)=history_chunksize(2) - do i = 3, size(dimids) - chunks(i) = 0 - enddo - status = pio_def_var_chunking(File, varid, NF90_CHUNKED, chunks) - call ice_pio_check(status, & - subname//' ERROR: chunking coord '//coord%short_name,file=__FILE__,line=__LINE__) + if (history_format=='hdf5' .and. size(dimids)>1) then + if (dimids(1)==imtid .and. dimids(2)==jmtid) then + chunks(1)=history_chunksize(1) + chunks(2)=history_chunksize(2) + do i = 3, size(dimids) + chunks(i) = 0 + enddo + status = pio_def_var_chunking(File, varid, NF90_CHUNKED, chunks) + call ice_pio_check(status, & + subname//' ERROR: chunking coord '//coord%short_name,file=__FILE__,line=__LINE__) + endif endif #endif call ice_pio_check(pio_put_att(File,varid,'long_name',trim(coord%long_name)), & @@ -1323,23 +1336,26 @@ subroutine ice_hist_field_def(File, hfield,lprecision, dimids, ns) subname//' ERROR: defining var '//hfield%vname,file=__FILE__,line=__LINE__) #ifndef USE_PIO1 - if (deflate==1) then - status = pio_def_var_deflate(File, varid, shuffle, deflate ,history_deflate) + if (history_deflate/=0 .and. history_format=='hdf5') then + status = pio_def_var_deflate(File, varid, shuffle=0, deflate=1, deflate_level=history_deflate) call ice_pio_check(status, & subname//' ERROR: deflating var '//hfield%vname,file=__FILE__,line=__LINE__) endif - if (history_format=='hdf5' .and. dimids(1)==imtid .and. dimids(2)==jmtid) then - chunks(1)=history_chunksize(1) - chunks(2)=history_chunksize(2) - do i = 1, size(dimids) - chunks(i) = 0 - enddo - status = pio_def_var_chunking(File, varid, NF90_CHUNKED, chunks) - call ice_pio_check(status, & - subname//' ERROR: chunking var '//hfield%vname,file=__FILE__,line=__LINE__) + if (history_format=='hdf5' .and. size(dimids)>1) then + if (dimids(1)==imtid .and. dimids(2)==jmtid) then + chunks(1)=history_chunksize(1) + chunks(2)=history_chunksize(2) + do i = 1, size(dimids) + chunks(i) = 0 + enddo + status = pio_def_var_chunking(File, varid, NF90_CHUNKED, chunks) + call ice_pio_check(status, & + subname//' ERROR: chunking var '//hfield%vname,file=__FILE__,line=__LINE__) + endif endif #endif + !var attributes call ice_pio_check(pio_put_att(File,varid,'units', trim(hfield%vunit)), & diff --git a/cicecore/cicedyn/infrastructure/io/io_pio2/ice_restart.F90 b/cicecore/cicedyn/infrastructure/io/io_pio2/ice_restart.F90 index 17a702e37..a646cac36 100644 --- a/cicecore/cicedyn/infrastructure/io/io_pio2/ice_restart.F90 +++ b/cicecore/cicedyn/infrastructure/io/io_pio2/ice_restart.F90 @@ -29,7 +29,7 @@ module ice_restart type(io_desc_t) :: iodesc2d type(io_desc_t) :: iodesc3d_ncat - integer (kind=int_kind) :: deflate + integer (kind=int_kind) :: dimid_ni, dimid_nj !======================================================================= @@ -176,8 +176,7 @@ subroutine init_restart_write(filename_spec) character(len=char_len_long) :: filename integer (kind=int_kind) :: & - dimid_ni, dimid_nj, dimid_ncat, & - dimid_nilyr, dimid_nslyr, dimid_naero + dimid_ncat, dimid_nilyr, dimid_nslyr, dimid_naero integer (kind=int_kind), allocatable :: dims(:) @@ -225,12 +224,6 @@ subroutine init_restart_write(filename_spec) write(nu_rst_pointer,'(a)') filename close(nu_rst_pointer) endif - - if (restart_deflate/=0 .and. restart_format=='hdf5') then - deflate = 1 - else - deflate = 0 - endif File%fh=-1 call ice_pio_init(mode='write',filename=trim(filename), File=File, & @@ -241,22 +234,22 @@ subroutine init_restart_write(filename_spec) call pio_seterrorhandling(File, PIO_RETURN_ERROR) call ice_pio_check(pio_put_att(File,pio_global,'istep1',istep1), & - subname//' ERROR: writing restart step',file=__FILE__,line=__LINE__) + subname//' ERROR: writing restart step',file=__FILE__,line=__LINE__) call ice_pio_check(pio_put_att(File,pio_global,'myear',myear), & - subname//' ERROR: writing restart year',file=__FILE__,line=__LINE__) + subname//' ERROR: writing restart year',file=__FILE__,line=__LINE__) call ice_pio_check(pio_put_att(File,pio_global,'mmonth',mmonth), & - subname//' ERROR: writing restart month',file=__FILE__,line=__LINE__) + subname//' ERROR: writing restart month',file=__FILE__,line=__LINE__) call ice_pio_check(pio_put_att(File,pio_global,'mday',mday), & - subname//' ERROR: writing restart day',file=__FILE__,line=__LINE__) + subname//' ERROR: writing restart day',file=__FILE__,line=__LINE__) call ice_pio_check(pio_put_att(File,pio_global,'msec',msec), & - subname//' ERROR: writing restart sec',file=__FILE__,line=__LINE__) + subname//' ERROR: writing restart sec',file=__FILE__,line=__LINE__) call ice_pio_check(pio_def_dim(File,'ni',nx_global,dimid_ni), & - subname//' ERROR: defining restart dim ni',file=__FILE__,line=__LINE__) + subname//' ERROR: defining restart dim ni',file=__FILE__,line=__LINE__) call ice_pio_check(pio_def_dim(File,'nj',ny_global,dimid_nj), & - subname//' ERROR: defining restart dim nj',file=__FILE__,line=__LINE__) + subname//' ERROR: defining restart dim nj',file=__FILE__,line=__LINE__) call ice_pio_check(pio_def_dim(File,'ncat',ncat,dimid_ncat), & - subname//' ERROR: defining restart dim ncat',file=__FILE__,line=__LINE__) + subname//' ERROR: defining restart dim ncat',file=__FILE__,line=__LINE__) !----------------------------------------------------------------- ! 2D restart fields @@ -937,22 +930,24 @@ subroutine define_rest_field(File, vname, dims) subname//' ERROR defining restart field '//trim(vname)) #ifndef USE_PIO1 - if (deflate==1) then - status = pio_def_var_deflate(File, vardesc, 0, deflate,restart_deflate) + if (restart_format=='hdf5' .and. restart_deflate/=0) then + status = pio_def_var_deflate(File, vardesc, shuffle=0, deflate=0,deflate_level=restart_deflate) call ice_pio_check(status, & subname//' ERROR: deflating restart field '//trim(vname),file=__FILE__,line=__LINE__) endif if (restart_format=='hdf5' .and. size(dims)>1) then - chunks(1)=restart_chunksize(1) - chunks(2)=restart_chunksize(2) - do i = 3, size(dims) - chunks(i) = 0 - enddo - - status = pio_def_var_chunking(File, vardesc, NF90_CHUNKED, chunks) - call ice_pio_check(status, subname//' ERROR: chunking restart field '//trim(vname),& - file=__FILE__,line=__LINE__) + if (dims(1)==dimid_ni .and. dims(2)==dimid_nj) then + chunks(1)=restart_chunksize(1) + chunks(2)=restart_chunksize(2) + do i = 3, size(dims) + chunks(i) = 0 + enddo + + status = pio_def_var_chunking(File, vardesc, NF90_CHUNKED, chunks) + call ice_pio_check(status, subname//' ERROR: chunking restart field '//trim(vname),& + file=__FILE__,line=__LINE__) + endif endif #endif diff --git a/cicecore/shared/ice_restart_shared.F90 b/cicecore/shared/ice_restart_shared.F90 index 87d6b7763..8452dac7c 100644 --- a/cicecore/shared/ice_restart_shared.F90 +++ b/cicecore/shared/ice_restart_shared.F90 @@ -33,8 +33,8 @@ module ice_restart_shared restart_iotasks , & ! iotasks, root, stride defines io pes for pio restart_root , & ! iotasks, root, stride defines io pes for pio restart_stride , & ! iotasks, root, stride defines io pes for pio - restart_deflate , & ! compression level for netcdf4 - restart_chunksize(2) ! chunksize for netcdf4 + restart_deflate , & ! compression level for hdf5/netcdf4 + restart_chunksize(2) ! chunksize for hdf5/netcdf4 !=======================================================================