From 6d1bdcefe4a432748a7548392a438efd6a33270b Mon Sep 17 00:00:00 2001 From: David Bailey Date: Wed, 14 Dec 2022 11:15:37 -0700 Subject: [PATCH 1/7] Fix OMP setup --- cicecore/cicedyn/infrastructure/ice_grid.F90 | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/cicecore/cicedyn/infrastructure/ice_grid.F90 b/cicecore/cicedyn/infrastructure/ice_grid.F90 index d6c612f00..b775c21f2 100644 --- a/cicecore/cicedyn/infrastructure/ice_grid.F90 +++ b/cicecore/cicedyn/infrastructure/ice_grid.F90 @@ -508,7 +508,6 @@ subroutine init_grid2 !----------------------------------------------------------------- ! This code does not work in CESM. Needs to be investigated further. -#ifndef CESMCOUPLED #if defined (_OPENMP) !$OMP PARALLEL DO ORDERED PRIVATE(iblk) SCHEDULE(runtime) do iblk = 1, nblocks @@ -521,12 +520,11 @@ subroutine init_grid2 write(nu_diag,*) subname,' omp schedule = ',ompsk,ompcs endif write(nu_diag,*) subname,' block, thread = ',iblk,OMP_GET_THREAD_NUM() - call flush_fileunit(nu_diag) !$OMP END ORDERED endif enddo !$OMP END PARALLEL DO -#endif + call flush_fileunit(nu_diag) #endif !----------------------------------------------------------------- From d7988c940a8e2dad95f7b743c521558bba39ef2b Mon Sep 17 00:00:00 2001 From: David Bailey Date: Thu, 15 Dec 2022 14:49:00 -0700 Subject: [PATCH 2/7] Update meshgrid --- cicecore/cicedyn/general/ice_init.F90 | 3 +-- cicecore/drivers/nuopc/cmeps/ice_comp_nuopc.F90 | 4 ++-- cicecore/drivers/nuopc/cmeps/ice_import_export.F90 | 4 ++-- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/cicecore/cicedyn/general/ice_init.F90 b/cicecore/cicedyn/general/ice_init.F90 index 03ebc0174..fa040414a 100644 --- a/cicecore/cicedyn/general/ice_init.F90 +++ b/cicecore/cicedyn/general/ice_init.F90 @@ -2330,8 +2330,7 @@ subroutine input_data grid_type /= 'rectangular' .and. & grid_type /= 'cpom_grid' .and. & grid_type /= 'regional' .and. & - grid_type /= 'latlon' .and. & - grid_type /= 'setmask' ) then + grid_type /= 'latlon') then if (my_task == master_task) write(nu_diag,*) subname//' ERROR: unknown grid_type=',trim(grid_type) abort_list = trim(abort_list)//":20" endif diff --git a/cicecore/drivers/nuopc/cmeps/ice_comp_nuopc.F90 b/cicecore/drivers/nuopc/cmeps/ice_comp_nuopc.F90 index 5f2995132..b94fcff05 100644 --- a/cicecore/drivers/nuopc/cmeps/ice_comp_nuopc.F90 +++ b/cicecore/drivers/nuopc/cmeps/ice_comp_nuopc.F90 @@ -21,7 +21,7 @@ module ice_comp_nuopc use ice_import_export , only : ice_import, ice_export, ice_advertise_fields, ice_realize_fields use ice_domain_size , only : nx_global, ny_global - use ice_grid , only : grid_type, init_grid2 + use ice_grid , only : grid_format, init_grid2 use ice_communicate , only : init_communicate, my_task, master_task, mpi_comm_ice use ice_calendar , only : force_restart_now, write_ic, init_calendar use ice_calendar , only : idate, mday, mmonth, myear, year_init @@ -684,7 +684,7 @@ subroutine InitializeAdvertise(gcomp, importState, exportState, clock, rc) if (ChkErr(rc,__LINE__,u_FILE_u)) return ! Initialize the cice mesh and the cice mask - if (trim(grid_type) == 'setmask') then + if (trim(grid_format) == 'meshnc') then ! In this case cap code determines the mask file call ice_mesh_setmask_from_maskfile(ice_maskfile, ice_mesh, rc=rc) if (ChkErr(rc,__LINE__,u_FILE_u)) return diff --git a/cicecore/drivers/nuopc/cmeps/ice_import_export.F90 b/cicecore/drivers/nuopc/cmeps/ice_import_export.F90 index e4db010de..60059e39a 100644 --- a/cicecore/drivers/nuopc/cmeps/ice_import_export.F90 +++ b/cicecore/drivers/nuopc/cmeps/ice_import_export.F90 @@ -27,7 +27,7 @@ module ice_import_export use ice_arrays_column , only : floe_rad_c, wave_spectrum use ice_state , only : vice, vsno, aice, aicen_init, trcr, trcrn use ice_grid , only : tlon, tlat, tarea, tmask, anglet, hm - use ice_grid , only : grid_type + use ice_grid , only : grid_format use ice_mesh_mod , only : ocn_gridcell_frac use ice_boundary , only : ice_HaloUpdate use ice_fileunits , only : nu_diag, flush_fileunit @@ -1059,7 +1059,7 @@ subroutine ice_export( exportState, rc ) call state_setexport(exportState, 'ice_fraction', input=ailohi, rc=rc) if (ChkErr(rc,__LINE__,u_FILE_u)) return - if (trim(grid_type) == 'setmask') then + if (trim(grid_format) == 'meshnc') then call state_setexport(exportState, 'ice_mask', input=ocn_gridcell_frac, rc=rc) if (ChkErr(rc,__LINE__,u_FILE_u)) return else From 8afd0be23357b7160e1c9fb5a228c7a0b60c78e4 Mon Sep 17 00:00:00 2001 From: David Bailey Date: Thu, 26 Jan 2023 11:38:19 -0700 Subject: [PATCH 3/7] Small updates for CESM --- cicecore/cicedyn/infrastructure/ice_grid.F90 | 1 - cicecore/cicedyn/infrastructure/io/io_pio2/ice_restart.F90 | 6 ++++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/cicecore/cicedyn/infrastructure/ice_grid.F90 b/cicecore/cicedyn/infrastructure/ice_grid.F90 index b775c21f2..0d56d3400 100644 --- a/cicecore/cicedyn/infrastructure/ice_grid.F90 +++ b/cicecore/cicedyn/infrastructure/ice_grid.F90 @@ -507,7 +507,6 @@ subroutine init_grid2 ! Diagnose OpenMP thread schedule, force order in output !----------------------------------------------------------------- -! This code does not work in CESM. Needs to be investigated further. #if defined (_OPENMP) !$OMP PARALLEL DO ORDERED PRIVATE(iblk) SCHEDULE(runtime) do iblk = 1, nblocks diff --git a/cicecore/cicedyn/infrastructure/io/io_pio2/ice_restart.F90 b/cicecore/cicedyn/infrastructure/io/io_pio2/ice_restart.F90 index 7019f7128..cdfbac87a 100644 --- a/cicecore/cicedyn/infrastructure/io/io_pio2/ice_restart.F90 +++ b/cicecore/cicedyn/infrastructure/io/io_pio2/ice_restart.F90 @@ -749,6 +749,9 @@ subroutine read_restart_field(nu,nrec,work,atype,vname,ndim3,diag, & ! if (ndim3 == ncat .and. ncat>1) then if (ndim3 == ncat .and. ndims == 3) then call pio_read_darray(File, vardesc, iodesc3d_ncat, work, status) +#ifdef CESMCOUPLED + where (work == PIO_FILL_DOUBLE) work = c0 +#endif if (present(field_loc)) then do n=1,ndim3 call ice_HaloUpdate (work(:,:,n,:), halo_info, & @@ -758,6 +761,9 @@ subroutine read_restart_field(nu,nrec,work,atype,vname,ndim3,diag, & ! elseif (ndim3 == 1) then elseif (ndim3 == 1 .and. ndims == 2) then call pio_read_darray(File, vardesc, iodesc2d, work, status) +#ifdef CESMCOUPLED + where (work == PIO_FILL_DOUBLE) work = c0 +#endif if (present(field_loc)) then call ice_HaloUpdate (work(:,:,1,:), halo_info, & field_loc, field_type) From 14e0b919e55416f30e0cbc2f4f58b3859c591e47 Mon Sep 17 00:00:00 2001 From: David Bailey Date: Thu, 26 Jan 2023 15:20:49 -0700 Subject: [PATCH 4/7] Add change for UFS --- cicecore/shared/ice_fileunits.F90 | 2 -- 1 file changed, 2 deletions(-) diff --git a/cicecore/shared/ice_fileunits.F90 b/cicecore/shared/ice_fileunits.F90 index 7e425e5e7..72a40f513 100644 --- a/cicecore/shared/ice_fileunits.F90 +++ b/cicecore/shared/ice_fileunits.F90 @@ -81,10 +81,8 @@ module ice_fileunits integer (kind=int_kind), public :: & nu_diag = ice_stdout ! diagnostics output file, unit number may be overwritten -#ifdef CESMCOUPLED logical (kind=log_kind), public :: & nu_diag_set = .false. ! flag to indicate whether nu_diag is already set -#endif integer (kind=int_kind), public :: & ice_IOUnitsMinUnit = 11, & ! do not use unit numbers below From 957ce31398e11dd7539b594a340aef3fffce8ae3 Mon Sep 17 00:00:00 2001 From: David Bailey Date: Tue, 28 Feb 2023 12:44:35 -0700 Subject: [PATCH 5/7] Add time_period_freq to history file metadata --- .../io/io_pio2/ice_history_write.F90 | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) 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 6407d8c76..33d839e53 100644 --- a/cicecore/cicedyn/infrastructure/io/io_pio2/ice_history_write.F90 +++ b/cicecore/cicedyn/infrastructure/io/io_pio2/ice_history_write.F90 @@ -76,6 +76,9 @@ subroutine ice_write_hist (ns) integer (kind=int_kind), dimension(6) :: dimidex real (kind= dbl_kind) :: ltime2 character (char_len) :: title +#ifdef CESMCOUPLED + character (char_len) :: time_period_freq +#endif character (char_len_long) :: ncfile(max_nstrm) integer (kind=int_kind) :: iotype @@ -626,6 +629,21 @@ subroutine ice_write_hist (ns) !----------------------------------------------------------------- #ifdef CESMCOUPLED status = pio_put_att(File,pio_global,'title',runid) + + select case (histfreq(ns)) + case ("y", "Y") + write(time_period_freq,'(a,i0)') 'year_',histfreq_n(ns) + case ("m", "M") + write(time_period_freq,'(a,i0)') 'month_',histfreq_n(ns) + case ("d", "D") + write(time_period_freq,'(a,i0)') 'day_',histfreq_n(ns) + case ("h", "H") + write(time_period_freq,'(a,i0)') 'hour_',histfreq_n(ns) + case ("1") + write(time_period_freq,'(a,i0)') 'step_',histfreq_n(ns) + end select + + status = pio_put_att(File,pio_global,'time_period_freq',trim(time_period_freq)) #else title = 'sea ice model output for CICE' status = pio_put_att(File,pio_global,'title',trim(title)) From 5ed7993d9943f2b7e1a613e93354360a3c487934 Mon Sep 17 00:00:00 2001 From: David Bailey Date: Wed, 1 Mar 2023 16:34:34 -0700 Subject: [PATCH 6/7] Add time_period_freq to io_netcdf and remove ifdef --- .../io/io_netcdf/ice_history_write.F90 | 22 +++++++++++- .../io/io_pio2/ice_history_write.F90 | 34 +++++++++---------- 2 files changed, 38 insertions(+), 18 deletions(-) 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 019ab8ce9..85a8e710e 100644 --- a/cicecore/cicedyn/infrastructure/io/io_netcdf/ice_history_write.F90 +++ b/cicecore/cicedyn/infrastructure/io/io_netcdf/ice_history_write.F90 @@ -48,7 +48,7 @@ subroutine ice_write_hist (ns) use ice_blocks, only: nx_block, ny_block use ice_broadcast, only: broadcast_scalar use ice_calendar, only: msec, timesecs, idate, idate0, write_ic, & - histfreq, days_per_year, use_leap_years, dayyr, & + histfreq, histfreq_n, days_per_year, use_leap_years, dayyr, & hh_init, mm_init, ss_init use ice_communicate, only: my_task, master_task use ice_domain, only: distrb_info @@ -86,6 +86,7 @@ subroutine ice_write_hist (ns) integer (kind=int_kind), dimension(6) :: dimidex real (kind=dbl_kind) :: ltime2 character (char_len) :: title + character (char_len) :: time_period_freq character (char_len_long) :: ncfile(max_nstrm) real (kind=dbl_kind) :: secday, rad_to_deg @@ -682,6 +683,25 @@ subroutine ice_write_hist (ns) if (status /= nf90_noerr) call abort_ice(subname// & 'ERROR: global attribute date2') + select case (histfreq(ns)) + case ("y", "Y") + write(time_period_freq,'(a,i0)') 'year_',histfreq_n(ns) + case ("m", "M") + write(time_period_freq,'(a,i0)') 'month_',histfreq_n(ns) + case ("d", "D") + write(time_period_freq,'(a,i0)') 'day_',histfreq_n(ns) + case ("h", "H") + write(time_period_freq,'(a,i0)') 'hour_',histfreq_n(ns) + case ("1") + write(time_period_freq,'(a,i0)') 'step_',histfreq_n(ns) + end select + + if (.not.write_ic) then + status = nf90_put_att(ncid,nf90_global,'time_period_freq',trim(time_period_freq)) + if (status /= nf90_noerr) call abort_ice(subname// & + 'ERROR: global attribute time_period_freq') + endif + title = 'CF-1.0' status = & nf90_put_att(ncid,nf90_global,'conventions',title) 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 33d839e53..5647f66fb 100644 --- a/cicecore/cicedyn/infrastructure/io/io_pio2/ice_history_write.F90 +++ b/cicecore/cicedyn/infrastructure/io/io_pio2/ice_history_write.F90 @@ -76,9 +76,7 @@ subroutine ice_write_hist (ns) integer (kind=int_kind), dimension(6) :: dimidex real (kind= dbl_kind) :: ltime2 character (char_len) :: title -#ifdef CESMCOUPLED character (char_len) :: time_period_freq -#endif character (char_len_long) :: ncfile(max_nstrm) integer (kind=int_kind) :: iotype @@ -629,21 +627,6 @@ subroutine ice_write_hist (ns) !----------------------------------------------------------------- #ifdef CESMCOUPLED status = pio_put_att(File,pio_global,'title',runid) - - select case (histfreq(ns)) - case ("y", "Y") - write(time_period_freq,'(a,i0)') 'year_',histfreq_n(ns) - case ("m", "M") - write(time_period_freq,'(a,i0)') 'month_',histfreq_n(ns) - case ("d", "D") - write(time_period_freq,'(a,i0)') 'day_',histfreq_n(ns) - case ("h", "H") - write(time_period_freq,'(a,i0)') 'hour_',histfreq_n(ns) - case ("1") - write(time_period_freq,'(a,i0)') 'step_',histfreq_n(ns) - end select - - status = pio_put_att(File,pio_global,'time_period_freq',trim(time_period_freq)) #else title = 'sea ice model output for CICE' status = pio_put_att(File,pio_global,'title',trim(title)) @@ -667,6 +650,23 @@ subroutine ice_write_hist (ns) write(title,'(a,i6)') 'seconds elapsed into model date: ',msec status = pio_put_att(File,pio_global,'comment3',trim(title)) + select case (histfreq(ns)) + case ("y", "Y") + write(time_period_freq,'(a,i0)') 'year_',histfreq_n(ns) + case ("m", "M") + write(time_period_freq,'(a,i0)') 'month_',histfreq_n(ns) + case ("d", "D") + write(time_period_freq,'(a,i0)') 'day_',histfreq_n(ns) + case ("h", "H") + write(time_period_freq,'(a,i0)') 'hour_',histfreq_n(ns) + case ("1") + write(time_period_freq,'(a,i0)') 'step_',histfreq_n(ns) + end select + + if (.not.write_ic) then + status = pio_put_att(File,pio_global,'time_period_freq',trim(time_period_freq)) + endif + title = 'CF-1.0' status = & pio_put_att(File,pio_global,'conventions',trim(title)) From f6fe43656bec25aa65bd44cd02e44a85d3915844 Mon Sep 17 00:00:00 2001 From: David Bailey Date: Thu, 2 Mar 2023 13:32:30 -0700 Subject: [PATCH 7/7] Initialize time_period_freq --- .../cicedyn/infrastructure/io/io_netcdf/ice_history_write.F90 | 4 ++-- .../cicedyn/infrastructure/io/io_pio2/ice_history_write.F90 | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) 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 85a8e710e..d85ec5e3c 100644 --- a/cicecore/cicedyn/infrastructure/io/io_netcdf/ice_history_write.F90 +++ b/cicecore/cicedyn/infrastructure/io/io_netcdf/ice_history_write.F90 @@ -86,7 +86,7 @@ subroutine ice_write_hist (ns) integer (kind=int_kind), dimension(6) :: dimidex real (kind=dbl_kind) :: ltime2 character (char_len) :: title - character (char_len) :: time_period_freq + character (char_len) :: time_period_freq = 'none' character (char_len_long) :: ncfile(max_nstrm) real (kind=dbl_kind) :: secday, rad_to_deg @@ -696,7 +696,7 @@ subroutine ice_write_hist (ns) write(time_period_freq,'(a,i0)') 'step_',histfreq_n(ns) end select - if (.not.write_ic) then + if (.not.write_ic .and. trim(time_period_freq) /= 'none') then status = nf90_put_att(ncid,nf90_global,'time_period_freq',trim(time_period_freq)) if (status /= nf90_noerr) call abort_ice(subname// & 'ERROR: global attribute time_period_freq') 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 5647f66fb..a697a98d5 100644 --- a/cicecore/cicedyn/infrastructure/io/io_pio2/ice_history_write.F90 +++ b/cicecore/cicedyn/infrastructure/io/io_pio2/ice_history_write.F90 @@ -76,7 +76,7 @@ subroutine ice_write_hist (ns) integer (kind=int_kind), dimension(6) :: dimidex real (kind= dbl_kind) :: ltime2 character (char_len) :: title - character (char_len) :: time_period_freq + character (char_len) :: time_period_freq = 'none' character (char_len_long) :: ncfile(max_nstrm) integer (kind=int_kind) :: iotype @@ -663,7 +663,7 @@ subroutine ice_write_hist (ns) write(time_period_freq,'(a,i0)') 'step_',histfreq_n(ns) end select - if (.not.write_ic) then + if (.not.write_ic .and. trim(time_period_freq) /= 'none') then status = pio_put_att(File,pio_global,'time_period_freq',trim(time_period_freq)) endif