Skip to content

Cm3 update cice#20

Draft
blimlim wants to merge 35 commits intomainfrom
cm3-update-cice
Draft

Cm3 update cice#20
blimlim wants to merge 35 commits intomainfrom
cm3-update-cice

Conversation

@blimlim
Copy link
Collaborator

@blimlim blimlim commented Apr 17, 2025

Not to be merged

This PR describes the changes made when updating the CICE version used by CM3 from 8e2aab2 to 2025.01.0, the version used in OM3 0.4.0. If the changes are approved, I'll change the branch name from cm3-update-cice to cm3-coupling-0.4.0 (or another name if we decide on a different naming scheme).

This branch was created by rebasing cm3-coupling onto e68e05b (i.e. 2025.01.0). This update should be done in parallel to the icepack update at ACCESS-NRI/Icepack#7.

Water balance

The following plots compare the water balance before any of the version updates (i.e. before any of the MOM, CMEPS, CICE updates), and after the latest CICE and ICEPACK updates. (I accidentally deleted my intermediate run which had the MOM+CMEPS changes, but not the CICE+ICEPACK uptdates). Note that there were other changes to the suite including the swap to the time travelling ice scheme between these two simulations.

water balance pre

water balance post

The water balance looks quite similar. By the end of the year, the updated code does show a bigger change in equivalent sea level: ~ 0.00075873 m difference:
water_balance diff

Fluxes:

The following show the errors in the fluxes for each of the two runs:

Water balance

Details
Run: update-versions_control-20250220-2
----------------------------------------------------------------------------------
Runoff : 124.21205549751689 mm/yr
Runoff water mass error (ocn_med - atm_med): -0.01775217009401331 mm/yr
Runoff water mass error (mom - ocn_med): 0.2787084969021123 mm/yr
Runoff water mass rel error (mom - ocn_med): 0.0022438119696657297

Rain : 1128.2264074974714 mm/yr
Rain water mass error (ocn_med - atm_med): -1.9443744854627312 mm/yr
Rain water mass error (mom - ocn_med): 2.50265739467568 mm/yr
Rain water mass rel error (mom - ocn_med): 0.002222052133765145

Snow : 80.56790584464103 mm/yr
Snow water mass error (ocn_med - atm_med): -19.79297964299043 mm/yr
Snow water mass rel error (ocn_med - atm_med): -0.3256767367732792
Snow water mass error (mom - ocn_med): 0.13371840003152613 mm/yr
Snow water mass rel error (mom - ocn_med): 0.002200223157620131


Run: 20250414-update-cice-icepack
----------------------------------------------------------------------------------
Runoff : 123.17690203740416 mm/yr
Runoff water mass error (ocn_med - atm_med): -0.019479010166151056 mm/yr
Runoff water mass error (mom - ocn_med): 0.27658106491480794 mm/yr
Runoff water mass rel error (mom - ocn_med): 0.0022453971510894206

Rain : 1132.1616016931832 mm/yr
Rain water mass error (ocn_med - atm_med): -1.925099926122357 mm/yr
Rain water mass error (mom - ocn_med): 2.5112933019954653 mm/yr
Rain water mass rel error (mom - ocn_med): 0.0022219184197901946

Snow : 78.71917962261716 mm/yr
Snow water mass error (ocn_med - atm_med): -18.948685597410766 mm/yr
Snow water mass rel error (ocn_med - atm_med): -0.317024075280685
Snow water mass error (mom - ocn_med): 0.13154538971448915 mm/yr
Snow water mass rel error (mom - ocn_med): 0.002200841600188445

The water flux errors are very comparable between the two runs.

Energy balance

Details
Run: update-versions_control-20250220-2
----------------------------------------------------------------------------------
SW:  176.9223 W/m^2
SW error (ocn_med - atm_med): -0.009616996488432505 W/m^2
SW rel error (atm_med - ocn_med): 5.435716115628626e-05
SW error (mom - ocn_med): 0.3991145969796719  W/m^2
SW rel error (mom - ocn_med): 0.0022559970592001223


LW:  -50.6349 W/m^2
LW error (ocn_med - atm_med): 0.002034111254040738 W/m^2
LW rel error (atm_med - ocn_med): -4.0172127908438995e-05
LW error (mom - ocn_med): -0.11364662305107487  W/m^2
LW rel error (mom - ocn_med): 0.0022445232918174114


SH:  -13.6040 W/m^2
SH error (ocn_med - atm_med): 0.0005019944459245806 W/m^2
SH rel error (atm_med - ocn_med): -3.690044358610117e-05
SH error (mom - ocn_med): -0.030503672494248235  W/m^2
SH rel error (mom - ocn_med): 0.002242336726667386


LH:  -107.0276 W/m^2
LH error (ocn_med - atm_med): 0.004621604924267331 W/m^2
LH rel error (atm_med - ocn_med): -4.318144254251409e-05
LH error (mom - ocn_med): -0.885024462135874  W/m^2
LH rel error (mom - ocn_med): 0.008269482984225885


Run: 20250414-update-cice-icepack
----------------------------------------------------------------------------------
SW:  177.5914 W/m^2
SW error (ocn_med - atm_med): -0.009491450224402342 W/m^2
SW rel error (atm_med - ocn_med): 5.3445450897494276e-05
SW error (mom - ocn_med): 0.4005701986857275  W/m^2
SW rel error (mom - ocn_med): 0.0022556931380393387


LW:  -50.9079 W/m^2
LW error (ocn_med - atm_med): 0.0020636242036715657 W/m^2
LW rel error (atm_med - ocn_med): -4.0536435065966305e-05
LW error (mom - ocn_med): -0.11423558644364107  W/m^2
LW rel error (mom - ocn_med): 0.002244057393625501


SH:  -13.4145 W/m^2
SH error (ocn_med - atm_med): 0.0005281212089283116 W/m^2
SH rel error (atm_med - ocn_med): -3.9369361530750556e-05
SH error (mom - ocn_med): -0.0300787175303725  W/m^2
SH rel error (mom - ocn_med): 0.0022423385144480874


LH:  -107.0081 W/m^2
LH error (ocn_med - atm_med): 0.00468215710442621 W/m^2
LH rel error (atm_med - ocn_med): -4.375516145733127e-05
LH error (mom - ocn_med): -0.8743345891156764  W/m^2
LH rel error (mom - ocn_med): 0.008171089576962571

Energy flux errors also are comparable.

Ice to ocean fluxes

Details
Run: update-versions_control-20250220-2
----------------------------------------------------------------------------------
iceImp_Fioi_melth
ice avg:  -0.6822172429407599
ocn avg:  -0.6821748665795724
error (ice_med - ocn_med): -4.237636118753496e-05
relative diff: 6.211564076696123e-05

iceImp_Fioi_meltw
ice avg:  2.7088748125090586e-07
ocn avg:  2.708230324942679e-07
error (ice_med - ocn_med): 6.444875663796532e-11
relative diff: 0.00023791707294982205

iceImp_Fioi_salt
ice avg:  -6.57522329534317e-10
ocn avg:  -6.577957816203805e-10
error (ice_med - ocn_med): 2.734520860634819e-13
relative diff: 0.00041570969851748523

Run: 20250414-update-cice-icepack
----------------------------------------------------------------------------------
iceImp_Fioi_melth
ice avg:  -0.6662568523970653
ocn avg:  -0.6662187816747793
error (ice_med - ocn_med): -3.807072228600994e-05
relative diff: 5.714120935347791e-05

iceImp_Fioi_meltw
ice avg:  3.7297616837774977e-07
ocn avg:  3.729115405177214e-07
error (ice_med - ocn_med): 6.462786002835616e-11
relative diff: 0.00017327611120424496

iceImp_Fioi_salt
ice avg:  -9.22887453290373e-11
ocn avg:  -9.257894911745888e-11
error (ice_med - ocn_med): 2.9020378842157925e-13
relative diff: 0.0031346628060487623

Here is the main cause for concern: the relative error for the ice-ocean salt flux increased from 0.00041570969851748523 to `0.00313466280604876231. I.e. ~7.5 times. The absolute error is similar between the two runs, while the average salt flux decreased greatly for the new versions.

While the jump in error is large, I think it may not actually be a cause for concern. It's an error between the mediator import and mediator export, which shouldn't be influenced by changes in the CICE and Icepack code. The intermediate update, where CMEPS and MOM were updated without CICE, showed a much smaller salt error.

I think the errors in mediator imports and exports could be due to their data being offset by one timestep.This seems consistent with the error pattern in the meltwater flux imports and exports in January and June:

jan melt flux error

jun melt flux error

I'm less sure about the very large decline in the salt flux magnitude between the two runs. A significant part of the difference appears to be in the Arctic in June:

Salt flux difference

EDIT: @MartinDix points out that the global year average salt flux ends up being a cancellation of different signed fluxes from different seasons, and in equilibrium should sum up to zero. This looks like it's the case in these two simulations, where the resulting in a global average is much smaller than the typical values during the year.

global_average_salt_flux
NH salt flux
SH salt flux

I think this suggests the change in yearly average salt flux is likely not a big cause for concern!

Atmosphere to ice fluxes

Details
Run: update-versions_control-20250220-2
----------------------------------------------------------------------------------
botmelt
atm avg:  -3.0092539206620588
ice avg:  -3.009461404262054
error (atm_med - ice_med): 0.00020748359999522847
relative diff: 6.89437650542341e-05

topmelt
atm avg:  1.837449871815238
ice avg:  1.837542519364736
error (atm_med - ice_med): -9.264754949800391e-05
relative diff: 5.041926840965479e-05

sublim
atm avg:  3.3988371068446785e-07
ice avg:  3.3991721033724313e-07
error (atm_med - ice_med): -3.349965277527929e-11
relative diff: 9.855238792423359e-05

Run: 20250414-update-cice-icepack
----------------------------------------------------------------------------------
botmelt
atm avg:  -2.828731165293191
ice avg:  -2.8289209649521774
error (atm_med - ice_med): 0.00018979965898635598
relative diff: 6.709259867553936e-05

topmelt
atm avg:  1.9745121492260116
ice avg:  1.9745976874996722
error (atm_med - ice_med): -8.553827366064581e-05
relative diff: 4.3319342568945456e-05

sublim
atm avg:  3.1304336252107373e-07
ice avg:  3.1308086653162743e-07
error (atm_med - ice_med): -3.750401055370374e-11
relative diff: 0.00011979017104807676

The errors look largely similar for these fluxes.

blimlim and others added 30 commits April 1, 2025 16:37
… by ice concentration before coupling (unscale in UM)
…m in the cap from local fluxes (#11)

Co-authored-by: Kieran Ricardo <kieran.ricardo@anu.edu.au>
blimlim and others added 5 commits April 9, 2025 15:31
@blimlim
Copy link
Collaborator Author

blimlim commented Apr 17, 2025

Merge conflicts while updating CICE drivers

We had no conflicts in the core CICE code. I rebased our

Several conflicts came up in the merge. I'll record each of the conflicts here for the purpose of documentation. For review, I've separated them into more substantial conflicts, and much more straightforward ones where I'm more confident in my choice for resolution. Where relevant, I've tried to include some background on the upstream or local changes that caused the conflicts.

The main branch's nuopc drivers in drivers/nuopc/cmeps include several updates. I've rebased our drivers/access/cmeps drivers onto the 2025.01.0 versions from drivers/nuopc/cmeps to bring the latest updates into our branch.

Changes more likely to need review

New icepack_init_radiation routine

In CICE_InitMod.F90/cice_init2(), a call to the new icepack_init_radiation was added:

<<<<<<< HEAD
    call icepack_init_radiation ! initialize icepack shortwave tables
=======
>>>>>>> 55bb543 (access driver)

The icepack_init_radiation subroutine initialises several data variables used in the radiation calculations. For the default setting of shortwave == 'dEdd', these variables are

rsnw_datatype, rsnw_tab, Qs_tab, ws_tab, gs_tab, ki_ssl_mn_3bd, wi_ssl_mn_3bd, gi_ssl_mn_3bd, ki_dl_mn_3bd, wi_dl_mn_3bd, gi_dl_mn_3bd, ki_int_mn_3bd, wi_int_mn_3bd, gi_int_mn_3bd, ki_p_ssl_mn, wi_p_ssl_mn, gi_p_ssl_mn, ki_p_int_mn, wi_p_int_mn, gi_p_int_mn, kw, ww, gw

gaer_bc_3bd, kaer_bc_3bd, waer_bc_3bd, kaer_3bd, waer_3bd, gaer_3bd, bcenh_3bd

The variables in the first paragraph were previously initialised in compute_dEdd. However this routine was only called when calc_Tsfc=.true and so these variables would not have been initialised in CM3.

Prior to the big E3SM merge, the data variables after gw mostly seem to have been initialised in faero_optics in CICE rather than icepack, and this routine was called separately in ice_InitMod.F90

Following discussion with @kieranricardo, it sounds harmless to keep the call to call icepack_init_radiation in our driver. It initialises variables that (presumably) have no effect when calc_Tsfc=.False., and leaves open the option to switch on some radiation settings in the future.

The following small clashes were related to this change:

Details
<<<<<<< HEAD
=======
    if (tr_aero .or. tr_zaero) then
       call faero_optics !initialize aerosol optical property tables
    end if

>>>>>>> 55bb543 (access driver)

Based on the above, it looks like faero_optics was incorporated into the new icepack_init_radiation routine, so accept changes from main.

<<<<<<< HEAD
  use icepack_intfc, only: icepack_init_snow, icepack_init_radiation
=======
  use icepack_intfc, only: icepack_init_snow
>>>>>>> 55bb543 (access driver)

As above, accept changes from main

Stub ufs logging routines

e8a69ab adds several stub logging routines to cice_wrapper_mod.F90. Routines with the same names are presumably used by the ufs model. As per the comments: Define stub routines that do nothing - they are just here to avoid having cppdefs in the main program. These shouldn't have any impact on CM3, and so I've kept the changes from main in each case.

Details
module cice_wrapper_mod

#ifdef CESMCOUPLED
<<<<<<< HEAD
  use perf_mod      , only : t_startf, t_stopf, t_barrierf
  use shr_log_mod  , only : shr_log_getlogunit, shr_log_setlogunit

  use ice_kinds_mod , only : dbl_kind, int_kind, char_len, char_len_long

  implicit none

  real(dbl_kind) :: wtime = 0.0
contains
  ! Define stub routines that do nothing - they are just here to avoid
  ! having cppdefs in the main program
  subroutine ufs_settimer(timevalue)
    real(dbl_kind),    intent(inout) :: timevalue
  end subroutine ufs_settimer
  subroutine ufs_logtimer(nunit,elapsedsecs,string,runtimelog,time0)
    integer,           intent(in)  :: nunit
    integer(int_kind), intent(in)  :: elapsedsecs
    character(len=*),  intent(in)  :: string
    logical,           intent(in)  :: runtimelog
    real(dbl_kind),    intent(in)  :: time0
  end subroutine ufs_logtimer
  subroutine ufs_file_setLogUnit(filename,nunit,runtimelog)
    character(len=*),  intent(in)  :: filename
    logical,           intent(in)  :: runtimelog
    integer,           intent(out) :: nunit
  end subroutine ufs_file_setLogUnit
  subroutine ufs_logfhour(msg,hour)
    character(len=*),  intent(in)  :: msg
    real(dbl_kind),    intent(in)  :: hour
  end subroutine ufs_logfhour
#else

  use ice_kinds_mod , only : dbl_kind, int_kind, char_len, char_len_long

  implicit none

  real(dbl_kind) :: wtime = 0.0
contains
  subroutine ufs_settimer(timevalue)
    real(dbl_kind),    intent(inout) :: timevalue
    real(dbl_kind)                   :: MPI_Wtime
    timevalue = MPI_Wtime()
  end subroutine ufs_settimer

  subroutine ufs_logtimer(nunit,elapsedsecs,string,runtimelog,time0)
    integer,           intent(in)    :: nunit
    integer(int_kind), intent(in)    :: elapsedsecs
    character(len=*),  intent(in)    :: string
    logical,           intent(in)    :: runtimelog
    real(dbl_kind),    intent(in)    :: time0
    real(dbl_kind)                   :: MPI_Wtime, timevalue
    if (.not. runtimelog) return
    if (time0 > 0.) then
       timevalue = MPI_Wtime()-time0
       write(nunit,*)elapsedsecs,' CICE '//trim(string),timevalue
    end if
  end subroutine ufs_logtimer

  subroutine ufs_file_setLogUnit(filename,nunit,runtimelog)
    character(len=*),  intent(in)    :: filename
    logical,           intent(in)    :: runtimelog
    integer,           intent(out)   :: nunit
    if (.not. runtimelog) return
    open (newunit=nunit, file=trim(filename))
  end subroutine ufs_file_setLogUnit

  subroutine ufs_logfhour(msg,hour)
    character(len=*),  intent(in)    :: msg
    real(dbl_kind),    intent(in)    :: hour
    character(len=char_len)          :: filename
    integer(int_kind)                :: nunit
    write(filename,'(a,i4.4)')'log.ice.f',int(hour)
    open(newunit=nunit,file=trim(filename))
    write(nunit,'(a)')'completed: cice'
    write(nunit,'(a,f10.3)')'forecast hour:',hour
    write(nunit,'(a)')'valid time: '//trim(msg)
    close(nunit)
  end subroutine ufs_logfhour

  ! Define stub routines that do nothing - they are just here to avoid
  ! having cppdefs in the main program
  subroutine shr_log_setLogUnit(nunit)
    integer, intent(in) :: nunit
  end subroutine shr_log_setLogUnit
  subroutine shr_log_getLogUnit(nunit)
    integer, intent(in) :: nunit
  end subroutine shr_log_getLogUnit
=======
  use perf_mod     , only : t_startf, t_stopf, t_barrierf
  use shr_file_mod , only : shr_file_getlogunit, shr_file_setlogunit

#else
contains

  ! These are just stub routines put in place to remove

  subroutine shr_file_setLogUnit(nunit)
    integer, intent(in) :: nunit
    ! do nothing for this stub - its just here to replace
    ! having cppdefs in the main program
  end subroutine shr_file_setLogUnit
  subroutine shr_file_getLogUnit(nunit)
    integer, intent(in) :: nunit
    ! do nothing for this stub - its just here to replace
    ! having cppdefs in the main program
  end subroutine shr_file_getLogUnit

>>>>>>> 55bb543 (access driver)

Related changes in CICE_RunMod.F90

<<<<<<< HEAD
      use cice_wrapper_mod, only : ufs_logfhour
=======
>>>>>>> 55bb543 (access driver)
<<<<<<< HEAD
         if (my_task == master_task) then
            do ns = 1,nstreams
               if (write_history(ns) .and. histfreq(ns) .eq. 'h') then
                  call calendar_sec2hms(msec,hh,mm,ss)
                  write(logmsg,'(6(i4,2x))')myear,mmonth,mday,hh,mm,ss
                  call ufs_logfhour(trim(logmsg),timesecs/c3600)
               end if
            end do
         end if
=======

>>>>>>> 55bb543 (access driver)

And in ice_comp_nuopc.F90:

<<<<<<< HEAD
    call NUOPC_CompAttributeGet(gcomp, name="RunTimeLog", value=cvalue, isPresent=isPresent, isSet=isSet, rc=rc)
    if (ChkErr(rc,__LINE__,u_FILE_u)) return
    if (isPresent .and. isSet) runtimelog=(trim(cvalue)=="true")
    write(logmsg,*) runtimelog
    call ESMF_LogWrite('CICE_cap:RunTimeLog = '//trim(logmsg), ESMF_LOGMSG_INFO)

    call NUOPC_CompAttributeGet(gcomp, name="write_restart_at_endofrun", value=cvalue, isPresent=isPresent, isSet=isSet, rc=rc)
    if (ChkErr(rc,__LINE__,u_FILE_u)) return
    if (isPresent .and. isSet) then
       if (trim(cvalue) .eq. '.true.') restart_eor = .true.
    endif

#ifdef CESMCOUPLED
    pointer_date = .true.
#endif

    ! set CICE internal pointer_date variable based on nuopc settings
    ! this appends a datestamp to the "rpointer" file
    call NUOPC_CompAttributeGet(gcomp, name="restart_pointer_append_date", value=cvalue, isPresent=isPresent, isSet=isSet, rc=rc)
    if (ChkErr(rc,__LINE__,u_FILE_u)) return
    if (isPresent .and. isSet) pointer_date = (trim(cvalue) .eq. ".true.")
=======
>>>>>>> 55bb543 (access driver)

Accept changes from main. runtimelog has no effect when #CESM_COUPLED is defined, as it appears to only be used as an argument in the stub ufs logging routines. Pointer date options also worth including.

<<<<<<< HEAD
    call ufs_settimer(wtime)

=======
>>>>>>> 55bb543 (access driver)
<<<<<<< HEAD
    call shr_log_setLogUnit (shrlogunit)
    call ufs_file_setLogUnit('./log.ice.timer',nu_timer,runtimelog)
=======
    call shr_file_setLogUnit (shrlogunit)
>>>>>>> 55bb543 (access driver)

<<<<<<< HEAD
    if (mastertask) call ufs_logtimer(nu_timer,msec,'InitializeRealize time: ',runtimelog,wtime)
=======
>>>>>>> 55bb543 (access driver)

...
<<<<<<< HEAD
    if (mastertask) call ufs_logtimer(nu_timer,msec,'ModelAdvance time since last step: ',runtimelog,wtime)
    call ufs_settimer(wtime)
=======
>>>>>>> 55bb543 (access driver)
<<<<<<< HEAD
    if (mastertask) call ufs_logtimer(nu_timer,msec,'ModelAdvance time: ',runtimelog,wtime)
    call ufs_settimer(wtime)

=======
>>>>>>> 55bb543 (access driver)
<<<<<<< HEAD
    call ufs_settimer(wtime)
=======
>>>>>>> 55bb543 (access driver)
...
<<<<<<< HEAD
    if(mastertask) call ufs_logtimer(nu_timer,msec,'ModelFinalize time: ',runtimelog,wtime)

=======
>>>>>>> 55bb543 (access driver)

Coupling field name changes in ice_import_export.F90

a5bb4f9 switched to using "CESM-style" field names for imports/exports in CICE. We already use the CESM-style names in the mediator. I think the mediator matches the differing field names using the field dictionary. To me it makes sense for us to swap over to the CESM-style names for consistency with the mediator, and also to make our code as close to the main branch as possible.

For each variable which had a name change, I've double checked the field dictionary to make sure the old names in our branch refer to the same variables as the new names in main. The only one without a match is Faii_evap_wiso which doesn't seem to have the expected alias of mean_evap_rate_atm_into_ice_wiso based on the code. In any case, we run with flds_wiso=.false, so I think the changes from main will be safe.

The main question for review: are we happy to swap over to the CESM-style names?

There's a large number of sections where these changes apply:

Details
<<<<<<< HEAD
    call fldlist_add(fldsToIce_num, fldsToIce, 'So_dhdx' )
    call fldlist_add(fldsToIce_num, fldsToIce, 'So_dhdy' )
    call fldlist_add(fldsToIce_num, fldsToIce, 'So_t'    )
    call fldlist_add(fldsToIce_num, fldsToIce, 'So_s'    )
    call fldlist_add(fldsToIce_num, fldsToIce, 'So_u'    )
    call fldlist_add(fldsToIce_num, fldsToIce, 'So_v'    )
    call fldlist_add(fldsToIce_num, fldsToIce, 'Fioo_q'  )
=======
    call fldlist_add(fldsToIce_num, fldsToIce, 'sea_surface_slope_zonal' )
    call fldlist_add(fldsToIce_num, fldsToIce, 'sea_surface_slope_merid' )
    call fldlist_add(fldsToIce_num, fldsToIce, 'sea_surface_temperature' )
    call fldlist_add(fldsToIce_num, fldsToIce, 's_surf'                  )
    call fldlist_add(fldsToIce_num, fldsToIce, 'ocn_current_zonal'       )
    call fldlist_add(fldsToIce_num, fldsToIce, 'ocn_current_merid'       )
    call fldlist_add(fldsToIce_num, fldsToIce, 'freezing_melting_potential')
>>>>>>> 55bb543 (access driver)

Accepted changes from main.


<<<<<<< HEAD
    call fldlist_add(fldsToIce_num, fldsToIce, 'Sa_z'       )
    call fldlist_add(fldsToIce_num, fldsToIce, 'Sa_u'       )
    call fldlist_add(fldsToIce_num, fldsToIce, 'Sa_v'       )
    call fldlist_add(fldsToIce_num, fldsToIce, 'Sa_shum'    )
    call fldlist_add(fldsToIce_num, fldsToIce, 'Sa_tbot'    )
    call fldlist_add(fldsToIce_num, fldsToIce, 'Sa_pbot'    )
    call fldlist_add(fldsToIce_num, fldsToIce, 'Faxa_swvdr' )
    call fldlist_add(fldsToIce_num, fldsToIce, 'Faxa_swvdf' )
    call fldlist_add(fldsToIce_num, fldsToIce, 'Faxa_swndr' )
    call fldlist_add(fldsToIce_num, fldsToIce, 'Faxa_swndf' )
    call fldlist_add(fldsToIce_num, fldsToIce, 'Faxa_lwdn'  )
    call fldlist_add(fldsToIce_num, fldsToIce, 'Faxa_rain'  )
    call fldlist_add(fldsToIce_num, fldsToIce, 'Faxa_snow'  )
    call fldlist_add(fldsToIce_num, fldsToIce, 'Sa_ptem'    ) !cesm
    call fldlist_add(fldsToIce_num, fldsToIce, 'Sa_dens'    ) !cesm

    ! the following are advertised but might not be connected if they are not present
    ! in the cmeps esmFldsExchange_xxx_mod.F90 that is model specific
    ! from atm - black carbon deposition fluxes (3)
    call fldlist_add(fldsToIce_num, fldsToIce, 'Faxa_bcph',  ungridded_lbound=1, ungridded_ubound=3)
    ! from atm - wet dust deposition fluxes (4 sizes)
    call fldlist_add(fldsToIce_num, fldsToIce, 'Faxa_dstwet', ungridded_lbound=1, ungridded_ubound=4)
    ! from atm - dry dust deposition fluxes (4 sizes)
    call fldlist_add(fldsToIce_num, fldsToIce, 'Faxa_dstdry', ungridded_lbound=1, ungridded_ubound=4)

    ! the following are advertised but might not be connected if they are not advertised in the
    ! in the cmeps esmFldsExchange_xxx_mod.F90 that is model specific
    ! from wave
    if (flds_wave) then
       call fldlist_add(fldsToIce_num, fldsToIce, 'Sw_elevation_spectrum', ungridded_lbound=1, &
            ungridded_ubound=25)
    end if
=======
    call fldlist_add(fldsToIce_num, fldsToIce, 'inst_height_lowest'            )
    call fldlist_add(fldsToIce_num, fldsToIce, 'inst_zonal_wind_height_lowest' )
    call fldlist_add(fldsToIce_num, fldsToIce, 'inst_merid_wind_height_lowest' )
    call fldlist_add(fldsToIce_num, fldsToIce, 'inst_spec_humid_height_lowest' )
    call fldlist_add(fldsToIce_num, fldsToIce, 'inst_temp_height_lowest'       )
    call fldlist_add(fldsToIce_num, fldsToIce, 'inst_pres_height_lowest'       )
    call fldlist_add(fldsToIce_num, fldsToIce, 'mean_down_sw_vis_dir_flx'      )
    call fldlist_add(fldsToIce_num, fldsToIce, 'mean_down_sw_ir_dir_flx'       )
    call fldlist_add(fldsToIce_num, fldsToIce, 'mean_down_sw_vis_dif_flx'      )
    call fldlist_add(fldsToIce_num, fldsToIce, 'mean_down_sw_ir_dif_flx'       )
    call fldlist_add(fldsToIce_num, fldsToIce, 'mean_down_lw_flx'              )
    call fldlist_add(fldsToIce_num, fldsToIce, 'mean_prec_rate'                )
    call fldlist_add(fldsToIce_num, fldsToIce, 'mean_fprec_rate'               )
    call fldlist_add(fldsToIce_num, fldsToIce, 'Sa_ptem'                       ) !cesm
    call fldlist_add(fldsToIce_num, fldsToIce, 'air_density_height_lowest'     ) !cesm

    call ice_advertise_fields_access_import(gcomp, importState, exportState, flds_scalar_name, rc)
>>>>>>> 55bb543 (access driver)

The first section up to call fldlist_add(fldsToIce_num, fldsToIce, 'Sa_dens' ) !cesm swaps over to CESM-style variable names. Include these changes from main.

For the section added to main:

 ! the following are advertised but might not be connected if they are not present
    ! in the cmeps esmFldsExchange_xxx_mod.F90 that is model specific
    ! from atm - black carbon deposition fluxes (3)
    call fldlist_add(fldsToIce_num, fldsToIce, 'Faxa_bcph',  ungridded_lbound=1, ungridded_ubound=3)
    ! from atm - wet dust deposition fluxes (4 sizes)
    call fldlist_add(fldsToIce_num, fldsToIce, 'Faxa_dstwet', ungridded_lbound=1, ungridded_ubound=4)
    ! from atm - dry dust deposition fluxes (4 sizes)
    call fldlist_add(fldsToIce_num, fldsToIce, 'Faxa_dstdry', ungridded_lbound=1, ungridded_ubound=4)

    ! the following are advertised but might not be connected if they are not advertised in the
    ! in the cmeps esmFldsExchange_xxx_mod.F90 that is model specific
    ! from wave
    if (flds_wave) then
       call fldlist_add(fldsToIce_num, fldsToIce, 'Sw_elevation_spectrum', ungridded_lbound=1, &
            ungridded_ubound=25)

based on the comments, this addition shouldn't have any effect as these fields are not connected in the mediator for CM3. I'll include these changes to keep our code as close as possible to main.

Lastly we want to keep the call to the custom ice_advertise_fields_access_import from our branch.

<<<<<<< HEAD
    call fldlist_add(fldsFrIce_num, fldsFrIce, 'Si_imask' )
    call fldlist_add(fldsFrIce_num, fldsFrIce, 'Si_ifrac' )
    call fldlist_add(fldsFrIce_num, fldsFrIce, 'Si_t'     )
    call fldlist_add(fldsFrIce_num, fldsFrIce, 'Si_vice'  )
    call fldlist_add(fldsFrIce_num, fldsFrIce, 'Si_vsno'  )
    call fldlist_add(fldsFrIce_num, fldsFrIce, 'Si_tref'  )
    call fldlist_add(fldsFrIce_num, fldsFrIce, 'Si_qref'  )
    call fldlist_add(fldsFrIce_num, fldsFrIce, 'Si_snowh' )
    call fldlist_add(fldsFrIce_num, fldsFrIce, 'Si_u10'   )
    call fldlist_add(fldsFrIce_num, fldsFrIce, 'Si_avsdr' )
    call fldlist_add(fldsFrIce_num, fldsFrIce, 'Si_avsdf' )
    call fldlist_add(fldsFrIce_num, fldsFrIce, 'Si_anidr' )
    call fldlist_add(fldsFrIce_num, fldsFrIce, 'Si_anidf' )
=======
    call fldlist_add(fldsFrIce_num, fldsFrIce, 'ice_mask'                    )
    call fldlist_add(fldsFrIce_num, fldsFrIce, 'ice_fraction'                )
    call fldlist_add(fldsFrIce_num, fldsFrIce, 'sea_ice_surface_temperature' )
    call fldlist_add(fldsFrIce_num, fldsFrIce, 'mean_ice_volume'             )
    call fldlist_add(fldsFrIce_num, fldsFrIce, 'mean_snow_volume'            )
    call fldlist_add(fldsFrIce_num, fldsFrIce, 'Si_tref'                     )
    call fldlist_add(fldsFrIce_num, fldsFrIce, 'Si_qref'                     )
    call fldlist_add(fldsFrIce_num, fldsFrIce, 'Si_snowh'                    )
    call fldlist_add(fldsFrIce_num, fldsFrIce, 'Si_u10'                      )
    call fldlist_add(fldsFrIce_num, fldsFrIce, 'inst_ice_vis_dir_albedo'     )
    call fldlist_add(fldsFrIce_num, fldsFrIce, 'inst_ice_ir_dir_albedo'      )
    call fldlist_add(fldsFrIce_num, fldsFrIce, 'inst_ice_vis_dif_albedo'     )
    call fldlist_add(fldsFrIce_num, fldsFrIce, 'inst_ice_ir_dif_albedo'      )
>>>>>>> 55bb543 (access driver)

Swap over to the CESM style names.

<<<<<<< HEAD
       call fldlist_add(fldsFrIce_num, fldsFrIce, 'Si_ifrac_n', &
            ungridded_lbound=1, ungridded_ubound=ncat)
    end if
    if (flds_wave) then
       call fldlist_add(fldsFrIce_num, fldsFrIce, 'Si_thick'    )
       call fldlist_add(fldsFrIce_num, fldsFrIce, 'Si_floediam' )
    end if

    ! ice/atm fluxes computed by ice
    call fldlist_add(fldsFrIce_num, fldsFrIce, 'Faii_taux'      )
    call fldlist_add(fldsFrIce_num, fldsFrIce, 'Faii_tauy'      )
    call fldlist_add(fldsFrIce_num, fldsFrIce, 'Faii_lat'       )
    call fldlist_add(fldsFrIce_num, fldsFrIce, 'Faii_sen'       )
    call fldlist_add(fldsFrIce_num, fldsFrIce, 'Faii_lwup'      )
    call fldlist_add(fldsFrIce_num, fldsFrIce, 'Faii_evap'      )
    call fldlist_add(fldsFrIce_num, fldsFrIce, 'Faii_swnet'     )

    ! ice/ocn fluxes computed by ice
    call fldlist_add(fldsFrIce_num, fldsFrIce, 'Fioi_melth'     )
    call fldlist_add(fldsFrIce_num, fldsFrIce, 'Fioi_swpen'     )
    call fldlist_add(fldsFrIce_num, fldsFrIce, 'Fioi_swpen_vdr' )
    call fldlist_add(fldsFrIce_num, fldsFrIce, 'Fioi_swpen_vdf' )
    call fldlist_add(fldsFrIce_num, fldsFrIce, 'Fioi_swpen_idr' )
    call fldlist_add(fldsFrIce_num, fldsFrIce, 'Fioi_swpen_idf' )

    if (send_i2x_per_cat) then
       call fldlist_add(fldsFrIce_num, fldsFrIce, 'Fioi_swpen_ifrac_n', &
            ungridded_lbound=1, ungridded_ubound=ncat)
    end if
    call fldlist_add(fldsFrIce_num , fldsFrIce, 'Fioi_meltw' )
    call fldlist_add(fldsFrIce_num , fldsFrIce, 'Fioi_salt'  )
    call fldlist_add(fldsFrIce_num , fldsFrIce, 'Fioi_taux'  )
    call fldlist_add(fldsFrIce_num , fldsFrIce, 'Fioi_tauy'  )

    ! the following are advertised but might not be connected if they are not present
    ! in the cmeps esmFldsExchange_xxx_mod.F90 that is model specific
    call fldlist_add(fldsFrIce_num , fldsFrIce, 'Fioi_bcpho'  )
    call fldlist_add(fldsFrIce_num , fldsFrIce, 'Fioi_bcphi'  )
    call fldlist_add(fldsFrIce_num , fldsFrIce, 'Fioi_flxdst' )

    if (flds_wiso) then
       call fldlist_add(fldsFrIce_num, fldsFrIce, 'Fioi_meltw_wiso', &
            ungridded_lbound=1, ungridded_ubound=3)
       call fldlist_add(fldsFrIce_num, fldsFrIce, 'Faii_evap_wiso', &
=======
       call fldlist_add(fldsFrIce_num, fldsFrIce, 'ice_fraction_n', &
            ungridded_lbound=1, ungridded_ubound=ncat)
    end if
    if (flds_wave) then
       call fldlist_add(fldsFrIce_num, fldsFrIce, 'Si_thick'                 )
       call fldlist_add(fldsFrIce_num, fldsFrIce, 'Si_floediam'              )
    end if

    ! ice/atm fluxes computed by ice
    call fldlist_add(fldsFrIce_num, fldsFrIce, 'stress_on_air_ice_zonal'          )
    call fldlist_add(fldsFrIce_num, fldsFrIce, 'stress_on_air_ice_merid'          )
    call fldlist_add(fldsFrIce_num, fldsFrIce, 'mean_laten_heat_flx_atm_into_ice' )
    call fldlist_add(fldsFrIce_num, fldsFrIce, 'mean_sensi_heat_flx_atm_into_ice' )
    call fldlist_add(fldsFrIce_num, fldsFrIce, 'mean_up_lw_flx_ice'               )
    call fldlist_add(fldsFrIce_num, fldsFrIce, 'mean_evap_rate_atm_into_ice'      )
    call fldlist_add(fldsFrIce_num, fldsFrIce, 'Faii_swnet'                       )

    ! ice/ocn fluxes computed by ice
    call fldlist_add(fldsFrIce_num, fldsFrIce, 'net_heat_flx_to_ocn'     )
    call fldlist_add(fldsFrIce_num, fldsFrIce, 'mean_sw_pen_to_ocn'      )
    call fldlist_add(fldsFrIce_num, fldsFrIce, 'mean_sw_pen_to_ocn_vis_dir_flx' )
    call fldlist_add(fldsFrIce_num, fldsFrIce, 'mean_sw_pen_to_ocn_vis_dif_flx' )
    call fldlist_add(fldsFrIce_num, fldsFrIce, 'mean_sw_pen_to_ocn_ir_dir_flx'  )
    call fldlist_add(fldsFrIce_num, fldsFrIce, 'mean_sw_pen_to_ocn_ir_dif_flx'  )

    if (send_i2x_per_cat) then
       call fldlist_add(fldsFrIce_num, fldsFrIce, 'mean_sw_pen_to_ocn_ifrac_n', &
            ungridded_lbound=1, ungridded_ubound=ncat)
    end if
    call fldlist_add(fldsFrIce_num , fldsFrIce, 'mean_fresh_water_to_ocean_rate' )
    call fldlist_add(fldsFrIce_num , fldsFrIce, 'mean_salt_rate'                 )
    call fldlist_add(fldsFrIce_num , fldsFrIce, 'stress_on_ocn_ice_zonal'        )
    call fldlist_add(fldsFrIce_num , fldsFrIce, 'stress_on_ocn_ice_merid'        )

    ! the following are advertised but might not be connected if they are not present
    ! in the cmeps esmFldsExchange_xxx_mod.F90 that is model specific
    call fldlist_add(fldsFrIce_num , fldsFrIce, 'Fioi_bcpho'                     )
    call fldlist_add(fldsFrIce_num , fldsFrIce, 'Fioi_bcphi'                     )
    call fldlist_add(fldsFrIce_num , fldsFrIce, 'Fioi_flxdst'                    )

    if (flds_wiso) then
       call fldlist_add(fldsFrIce_num, fldsFrIce, 'mean_fresh_water_to_ocean_rate_wiso', &
            ungridded_lbound=1, ungridded_ubound=3)
       call fldlist_add(fldsFrIce_num, fldsFrIce, 'mean_evap_rate_atm_into_ice_wiso', &
>>>>>>> 55bb543 (access driver)

<<<<<<< HEAD
call state_getimport(importState, 'So_t', output=aflds, index=1, rc=rc)
if (ChkErr(rc,LINE,u_FILE_u)) return

call state_getimport(importState, 'So_s', output=aflds, index=2, rc=rc)

=======
call state_getimport(importState, 'sea_surface_temperature', output=aflds, index=1, rc=rc)
if (ChkErr(rc,LINE,u_FILE_u)) return

call state_getimport(importState, 's_surf', output=aflds, index=2, rc=rc)

55bb543 (access driver)

Accept CESM-style names from `main`.



<<<<<<< HEAD
call state_getimport(importState, 'Sa_z', output=aflds, index=3, rc=rc)
if (ChkErr(rc,LINE,u_FILE_u)) return

if (State_FldChk(importState, 'Sa_ptem') .and. State_fldchk(importState, 'Sa_dens')) then
   call state_getimport(importState, 'Sa_ptem', output=aflds, index=4, rc=rc)
   if (ChkErr(rc,__LINE__,u_FILE_u)) return
   call state_getimport(importState, 'Sa_dens', output=aflds, index=5, rc=rc)
   if (ChkErr(rc,__LINE__,u_FILE_u)) return
else if (State_FldChk(importState, 'Sa_pbot')) then
   call state_getimport(importState, 'Sa_pbot', output=aflds, index=6, rc=rc)
   if (ChkErr(rc,__LINE__,u_FILE_u)) return
else
   call abort_ice(trim(subname)//&
        ": ERROR either Sa_ptem and Sa_dens OR Sa_pbot must be in import state")
end if

call state_getimport(importState, 'Sa_tbot', output=aflds, index=7, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return

call state_getimport(importState, 'Sa_shum', output=aflds, index=8, rc=rc)

=======
call state_getimport(importState, 'inst_height_lowest', output=aflds, index=3, rc=rc)
if (ChkErr(rc,LINE,u_FILE_u)) return

if (State_FldChk(importState, 'Sa_ptem') .and. State_fldchk(importState, 'air_density_height_lowest')) then
   call state_getimport(importState, 'Sa_ptem', output=aflds, index=4, rc=rc)
   if (ChkErr(rc,__LINE__,u_FILE_u)) return
   call state_getimport(importState, 'air_density_height_lowest', output=aflds, index=5, rc=rc)
   if (ChkErr(rc,__LINE__,u_FILE_u)) return
else if (State_FldChk(importState, 'inst_pres_height_lowest')) then
   call state_getimport(importState, 'inst_pres_height_lowest', output=aflds, index=6, rc=rc)
   if (ChkErr(rc,__LINE__,u_FILE_u)) return
else
   call abort_ice(trim(subname)//&
        ": ERROR either Sa_ptem and air_density_height_lowest OR inst_pres_height_lowest must be in import state")
end if

call state_getimport(importState, 'inst_temp_height_lowest', output=aflds, index=7, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return

call state_getimport(importState, 'inst_spec_humid_height_lowest', output=aflds, index=8, rc=rc)

55bb543 (access driver)

Accept name changes from `main`.

<<<<<<< HEAD
call state_getimport(importState, 'Fioo_q', output=aflds, index=9, &

call state_getimport(importState, 'freezing_melting_potential', output=aflds, index=9, &

55bb543 (access driver)

Accept name changes from `main`.

<<<<<<< HEAD
call state_getimport(importState, 'Faxa_swvdr', output=aflds, index=10, &
areacor=med2mod_areacor, rc=rc)
if (ChkErr(rc,LINE,u_FILE_u)) return

call state_getimport(importState, 'Faxa_swndr', output=aflds, index=11, &
     areacor=med2mod_areacor, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return

call state_getimport(importState, 'Faxa_swvdf', output=aflds, index=12, &
     areacor=med2mod_areacor, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return

call state_getimport(importState, 'Faxa_swndf', output=aflds, index=13, &
     areacor=med2mod_areacor, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return

call state_getimport(importState, 'Faxa_lwdn', output=aflds, index=14, &
     areacor=med2mod_areacor, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return

call state_getimport(importState, 'Faxa_rain', output=aflds, index=15, &
     areacor=med2mod_areacor, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return

call state_getimport(importState, 'Faxa_snow', output=aflds, index=16, &

=======
call state_getimport(importState, 'mean_down_sw_vis_dir_flx', output=aflds, index=10, &
areacor=med2mod_areacor, rc=rc)
if (ChkErr(rc,LINE,u_FILE_u)) return

call state_getimport(importState, 'mean_down_sw_ir_dir_flx', output=aflds, index=11, &
     areacor=med2mod_areacor, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return

call state_getimport(importState, 'mean_down_sw_vis_dif_flx', output=aflds, index=12, &
     areacor=med2mod_areacor, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return

call state_getimport(importState, 'mean_down_sw_ir_dif_flx', output=aflds, index=13, &
     areacor=med2mod_areacor, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return

call state_getimport(importState, 'mean_down_lw_flx', output=aflds, index=14, &
     areacor=med2mod_areacor, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return

call state_getimport(importState, 'mean_prec_rate', output=aflds, index=15, &
     areacor=med2mod_areacor, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return

call state_getimport(importState, 'mean_fprec_rate', output=aflds, index=16, &

55bb543 (access driver)

Accept name changes from `main`.
<<<<<<< HEAD
    if ( State_fldChk(importState, 'Sa_ptem') .and. State_fldchk(importState,'Sa_dens')) then
       !$OMP PARALLEL DO PRIVATE(iblk,i,j)
       do iblk = 1, nblocks
          do j = 1,ny_block
             do i = 1,nx_block
                potT (i,j,iblk) = aflds(i,j, 4,iblk)
                rhoa (i,j,iblk) = aflds(i,j, 5,iblk)
             end do
          end do
       end do
       !$OMP END PARALLEL DO
    else if (State_fldChk(importState, 'Sa_pbot')) then
       !$OMP PARALLEL DO PRIVATE(iblk,i,j)
       do iblk = 1, nblocks
          do j = 1,ny_block
             do i = 1,nx_block
                inst_pres_height_lowest = aflds(i,j,6,iblk)
                if (inst_pres_height_lowest > 0.0_ESMF_KIND_R8) then
                   potT (i,j,iblk) = Tair(i,j,iblk) * (100000._ESMF_KIND_R8/inst_pres_height_lowest)**0.286_ESMF_KIND_R8
                else
                   potT (i,j,iblk) = 0.0_ESMF_KIND_R8
                end if
                if (Tair(i,j,iblk) /= 0._ESMF_KIND_R8) then
                   rhoa(i,j,iblk) = inst_pres_height_lowest / &
                        (287.058_ESMF_KIND_R8*(1._ESMF_KIND_R8+0.608_ESMF_KIND_R8*Qa(i,j,iblk))*Tair(i,j,iblk))
                else
                   rhoa(i,j,iblk) = 1.2_ESMF_KIND_R8
                endif
             end do !i
          end do !j
       end do !iblk
       !$OMP END PARALLEL DO
    end if
=======
    if ( State_fldChk(importState, 'Sa_ptem') .and. State_fldchk(importState,'air_density_height_lowest')) then
      !$OMP PARALLEL DO PRIVATE(iblk,i,j)
      do iblk = 1, nblocks
         do j = 1,ny_block
            do i = 1,nx_block
               potT (i,j,iblk) = aflds(i,j, 4,iblk)
               rhoa (i,j,iblk) = aflds(i,j, 5,iblk)
            end do
         end do
      end do
      !$OMP END PARALLEL DO
   else if (State_fldChk(importState, 'inst_pres_height_lowest')) then
      !$OMP PARALLEL DO PRIVATE(iblk,i,j)
      do iblk = 1, nblocks
         do j = 1,ny_block
            do i = 1,nx_block
               inst_pres_height_lowest = aflds(i,j,6,iblk)
               if (inst_pres_height_lowest > 0.0_ESMF_KIND_R8) then
                  potT (i,j,iblk) = Tair(i,j,iblk) * (100000._ESMF_KIND_R8/inst_pres_height_lowest)**0.286_ESMF_KIND_R8
               else
                  potT (i,j,iblk) = 0.0_ESMF_KIND_R8
               end if
               if (Tair(i,j,iblk) /= 0._ESMF_KIND_R8) then
                  rhoa(i,j,iblk) = inst_pres_height_lowest / &
                       (287.058_ESMF_KIND_R8*(1._ESMF_KIND_R8+0.608_ESMF_KIND_R8*Qa(i,j,iblk))*Tair(i,j,iblk))
               else
                  rhoa(i,j,iblk) = 1.2_ESMF_KIND_R8
               endif
            end do !i
         end do !j
      end do !iblk
      !$OMP END PARALLEL DO
   end if

>>>>>>> 55bb543 (access driver)

Just more name changes, accept changes from main.

<<<<<<< HEAD
    call state_getimport(importState, 'So_u', output=aflds, index=1, rc=rc)
    if (ChkErr(rc,__LINE__,u_FILE_u)) return
    call state_getimport(importState, 'So_v', output=aflds, index=2, rc=rc)
    if (ChkErr(rc,__LINE__,u_FILE_u)) return

    call state_getimport(importState, 'Sa_u', output=aflds, index=3, rc=rc)
    if (ChkErr(rc,__LINE__,u_FILE_u)) return
    call state_getimport(importState, 'Sa_v', output=aflds, index=4, rc=rc)
    if (ChkErr(rc,__LINE__,u_FILE_u)) return

    call state_getimport(importState, 'So_dhdx', output=aflds, index=5, rc=rc)
    if (ChkErr(rc,__LINE__,u_FILE_u)) return
    call state_getimport(importState, 'So_dhdy', output=aflds, index=6, rc=rc)
=======
    call state_getimport(importState, 'ocn_current_zonal', output=aflds, index=1, rc=rc)
    if (ChkErr(rc,__LINE__,u_FILE_u)) return
    call state_getimport(importState, 'ocn_current_merid', output=aflds, index=2, rc=rc)
    if (ChkErr(rc,__LINE__,u_FILE_u)) return

    call state_getimport(importState, 'inst_zonal_wind_height_lowest', output=aflds, index=3, rc=rc)
    if (ChkErr(rc,__LINE__,u_FILE_u)) return
    call state_getimport(importState, 'inst_merid_wind_height_lowest', output=aflds, index=4, rc=rc)
    if (ChkErr(rc,__LINE__,u_FILE_u)) return

    call state_getimport(importState, 'sea_surface_slope_zonal', output=aflds, index=5, rc=rc)
    if (ChkErr(rc,__LINE__,u_FILE_u)) return
    call state_getimport(importState, 'sea_surface_slope_merid', output=aflds, index=6, rc=rc)
>>>>>>> 55bb543 (access driver)

Accept name changes from main.

<<<<<<< HEAD
    call state_setexport(exportState, 'Si_ifrac', input=ailohi, rc=rc)
    if (ChkErr(rc,__LINE__,u_FILE_u)) return

    if (trim(grid_format) == 'meshnc') then
       call state_setexport(exportState, 'Si_imask', input=ocn_gridcell_frac, rc=rc)
=======
    call state_setexport(exportState, 'ice_fraction', input=ailohi, rc=rc)
    if (ChkErr(rc,__LINE__,u_FILE_u)) return

    if (trim(grid_format) == 'meshnc') then
       call state_setexport(exportState, 'ice_mask', input=ocn_gridcell_frac, rc=rc)
>>>>>>> 55bb543 (access driver)


...


<<<<<<< HEAD
       call state_setexport(exportState, 'Si_imask', input=tempfld, rc=rc)
=======
       call state_setexport(exportState, 'ice_mask', input=tempfld, rc=rc)
>>>>>>> 55bb543 (access driver)

Use name changes from main.

<<<<<<< HEAD
    call state_setexport(exportState, 'Si_t', input=Tsrf , lmask=tmask, ifrac=ailohi, rc=rc)
    if (ChkErr(rc,__LINE__,u_FILE_u)) return

    ! albedo vis dir
    call state_setexport(exportState, 'Si_avsdr', input=alvdr, lmask=tmask, ifrac=ailohi, rc=rc)
    if (ChkErr(rc,__LINE__,u_FILE_u)) return

    ! albedo nir dir
    call state_setexport(exportState, 'Si_anidr', input=alidr, lmask=tmask, ifrac=ailohi, rc=rc)
    if (ChkErr(rc,__LINE__,u_FILE_u)) return

    ! albedo vis dif
    call state_setexport(exportState, 'Si_avsdf', input=alvdf, lmask=tmask, ifrac=ailohi, rc=rc)
    if (ChkErr(rc,__LINE__,u_FILE_u)) return

    ! albedo nir dif
    call state_setexport(exportState, 'Si_anidf', input=alidf, lmask=tmask, ifrac=ailohi, rc=rc)
=======
    call state_setexport(exportState, 'sea_ice_surface_temperature', input=Tsrf , lmask=tmask, ifrac=ailohi, rc=rc)
    if (ChkErr(rc,__LINE__,u_FILE_u)) return

    ! albedo vis dir
    call state_setexport(exportState, 'inst_ice_vis_dir_albedo', input=alvdr, lmask=tmask, ifrac=ailohi, rc=rc)
    if (ChkErr(rc,__LINE__,u_FILE_u)) return

    ! albedo nir dir
    call state_setexport(exportState, 'inst_ice_ir_dir_albedo', input=alidr, lmask=tmask, ifrac=ailohi, rc=rc)
    if (ChkErr(rc,__LINE__,u_FILE_u)) return

    ! albedo vis dif
    call state_setexport(exportState, 'inst_ice_vis_dif_albedo', input=alvdf, lmask=tmask, ifrac=ailohi, rc=rc)
    if (ChkErr(rc,__LINE__,u_FILE_u)) return

    ! albedo nir dif
    call state_setexport(exportState, 'inst_ice_ir_dif_albedo', input=alidf, lmask=tmask, ifrac=ailohi, rc=rc)
>>>>>>> 55bb543 (access driver)

Use name changes from main.

<<<<<<< HEAD
    call state_setexport(exportState, 'Si_vsno' , input=vsno , lmask=tmask, ifrac=ailohi, rc=rc)
    if (ChkErr(rc,__LINE__,u_FILE_u)) return

    ! Ice volume
    call state_setexport(exportState, 'Si_vice' , input=vice , lmask=tmask, ifrac=ailohi, rc=rc)
=======
    call state_setexport(exportState, 'mean_snow_volume' , input=vsno , lmask=tmask, ifrac=ailohi, rc=rc)
    if (ChkErr(rc,__LINE__,u_FILE_u)) return

    ! Ice volume
    call state_setexport(exportState, 'mean_ice_volume' , input=vice , lmask=tmask, ifrac=ailohi, rc=rc)
>>>>>>> 55bb543 (access driver)

Use name changes from main.

<<<<<<< HEAD
    call state_setexport(exportState, 'Faii_taux' , input=tauxa, lmask=tmask, ifrac=ailohi, &
=======
    call state_setexport(exportState, 'stress_on_air_ice_zonal' , input=tauxa, lmask=tmask, ifrac=ailohi, &
>>>>>>> 55bb543 (access driver)

...
<<<<<<< HEAD
    call state_setexport(exportState, 'Faii_tauy' , input=tauya, lmask=tmask, ifrac=ailohi, &
=======
    call state_setexport(exportState, 'stress_on_air_ice_merid' , input=tauya, lmask=tmask, ifrac=ailohi, &
>>>>>>> 55bb543 (access driver)
...

<<<<<<< HEAD
    call state_setexport(exportState, 'Faii_lat' , input=flat, lmask=tmask, ifrac=ailohi, &
=======
    call state_setexport(exportState, 'mean_laten_heat_flx_atm_into_ice' , input=flat, lmask=tmask, ifrac=ailohi, &
>>>>>>> 55bb543 (access driver)
...

<<<<<<< HEAD
    call state_setexport(exportState, 'Faii_sen' , input=fsens, lmask=tmask, ifrac=ailohi, &
=======
    call state_setexport(exportState, 'mean_sensi_heat_flx_atm_into_ice' , input=fsens, lmask=tmask, ifrac=ailohi, &
>>>>>>> 55bb543 (access driver)
...

<<<<<<< HEAD
    call state_setexport(exportState, 'Faii_lwup' , input=flwout, lmask=tmask, ifrac=ailohi, &
=======
    call state_setexport(exportState, 'mean_up_lw_flx_ice' , input=flwout, lmask=tmask, ifrac=ailohi, &
>>>>>>> 55bb543 (access driver)
...

<<<<<<< HEAD
    call state_setexport(exportState, 'Faii_evap' , input=evap, lmask=tmask, ifrac=ailohi, &
=======
    call state_setexport(exportState, 'mean_evap_rate_atm_into_ice' , input=evap, lmask=tmask, ifrac=ailohi, &
>>>>>>> 55bb543 (access driver)
...

<<<<<<< HEAD
    call state_setexport(exportState, 'Fioi_swpen' , input=fswthru, lmask=tmask, ifrac=ailohi, &
=======
    call state_setexport(exportState, 'mean_sw_pen_to_ocn' , input=fswthru, lmask=tmask, ifrac=ailohi, &
>>>>>>> 55bb543 (access driver)
...
<<<<<<< HEAD
    call state_setexport(exportState, 'Fioi_swpen_vdr' , input=fswthru_vdr, lmask=tmask, ifrac=ailohi, &
=======
    call state_setexport(exportState, 'mean_sw_pen_to_ocn_vis_dir_flx' , input=fswthru_vdr, lmask=tmask, ifrac=ailohi, &
>>>>>>> 55bb543 (access driver)
...

<<<<<<< HEAD
    call state_setexport(exportState, 'Fioi_swpen_vdf' , input=fswthru_vdf, lmask=tmask, ifrac=ailohi, &
=======
    call state_setexport(exportState, 'mean_sw_pen_to_ocn_vis_dif_flx' , input=fswthru_vdf, lmask=tmask, ifrac=ailohi, &
>>>>>>> 55bb543 (access driver)
...

<<<<<<< HEAD
    call state_setexport(exportState, 'Fioi_swpen_idr' , input=fswthru_idr, lmask=tmask, ifrac=ailohi, &
=======
    call state_setexport(exportState, 'mean_sw_pen_to_ocn_ir_dir_flx' , input=fswthru_idr, lmask=tmask, ifrac=ailohi, &
>>>>>>> 55bb543 (access driver)
...

<<<<<<< HEAD
    call state_setexport(exportState, 'Fioi_swpen_idf' , input=fswthru_idf, lmask=tmask, ifrac=ailohi, &
=======
    call state_setexport(exportState, 'mean_sw_pen_to_ocn_ir_dif_flx' , input=fswthru_idf, lmask=tmask, ifrac=ailohi, &
>>>>>>> 55bb543 (access driver)
...

<<<<<<< HEAD
    call state_setexport(exportState, 'Fioi_melth' , input=fhocn, lmask=tmask, ifrac=ailohi, &
=======
    call state_setexport(exportState, 'net_heat_flx_to_ocn' , input=fhocn, lmask=tmask, ifrac=ailohi, &
>>>>>>> 55bb543 (access driver)
...
<<<<<<< HEAD
    call state_setexport(exportState, 'Fioi_meltw' , input=fresh, lmask=tmask, ifrac=ailohi, &
=======
    call state_setexport(exportState, 'mean_fresh_water_to_ocean_rate' , input=fresh, lmask=tmask, ifrac=ailohi, &
>>>>>>> 55bb543 (access driver)
...
<<<<<<< HEAD
    call state_setexport(exportState, 'Fioi_salt' , input=fsalt, lmask=tmask, ifrac=ailohi, &
=======
    call state_setexport(exportState, 'mean_salt_rate' , input=fsalt, lmask=tmask, ifrac=ailohi, &
>>>>>>> 55bb543 (access driver)
...
<<<<<<< HEAD
    call state_setexport(exportState, 'Fioi_taux' , input=tauxo, lmask=tmask, ifrac=ailohi, &
=======
    call state_setexport(exportState, 'stress_on_ocn_ice_zonal' , input=tauxo, lmask=tmask, ifrac=ailohi, &
>>>>>>> 55bb543 (access driver)
...
<<<<<<< HEAD
    call state_setexport(exportState, 'Fioi_tauy' , input=tauyo, lmask=tmask, ifrac=ailohi, &
=======
    call state_setexport(exportState, 'stress_on_ocn_ice_merid' , input=tauyo, lmask=tmask, ifrac=ailohi, &
>>>>>>> 55bb543 (access driver)
...

<<<<<<< HEAD
    if (State_FldChk(exportState, 'Fioi_meltw_wiso')) then
=======
    if (State_FldChk(exportState, 'mean_fresh_water_to_ocean_rate_wiso')) then
>>>>>>> 55bb543 (access driver)
...

<<<<<<< HEAD
       call state_setexport(exportState, 'Fioi_meltw_wiso' , input=fiso_ocn, index=1, &
            lmask=tmask, ifrac=ailohi, ungridded_index=3, areacor=mod2med_areacor, rc=rc)
       if (ChkErr(rc,__LINE__,u_FILE_u)) return
       call state_setexport(exportState, 'Fioi_meltw_wiso' , input=fiso_ocn, index=2, &
            lmask=tmask, ifrac=ailohi, ungridded_index=1, areacor=mod2med_areacor, rc=rc)
       if (ChkErr(rc,__LINE__,u_FILE_u)) return
       call state_setexport(exportState, 'Fioi_meltw_wiso' , input=fiso_ocn, index=3, &
=======
       call state_setexport(exportState, 'mean_fresh_water_to_ocean_rate_wiso' , input=fiso_ocn, index=1, &
            lmask=tmask, ifrac=ailohi, ungridded_index=3, areacor=mod2med_areacor, rc=rc)
       if (ChkErr(rc,__LINE__,u_FILE_u)) return
       call state_setexport(exportState, 'mean_fresh_water_to_ocean_rate_wiso' , input=fiso_ocn, index=2, &
            lmask=tmask, ifrac=ailohi, ungridded_index=1, areacor=mod2med_areacor, rc=rc)
       if (ChkErr(rc,__LINE__,u_FILE_u)) return
       call state_setexport(exportState, 'mean_fresh_water_to_ocean_rate_wiso' , input=fiso_ocn, index=3, &
>>>>>>> 55bb543 (access driver)
...

<<<<<<< HEAD
    if (State_FldChk(exportState, 'Faii_evap_wiso')) then
       !  Isotope evap to atm
       call state_setexport(exportState, 'Faii_evap_wiso' , input=fiso_evap, index=1, &
            lmask=tmask, ifrac=ailohi, ungridded_index=3, areacor=mod2med_areacor, rc=rc)
       if (ChkErr(rc,__LINE__,u_FILE_u)) return
       call state_setexport(exportState, 'Faii_evap_wiso' , input=fiso_evap, index=2, &
            lmask=tmask, ifrac=ailohi, ungridded_index=1, areacor=mod2med_areacor, rc=rc)
       if (ChkErr(rc,__LINE__,u_FILE_u)) return
       call state_setexport(exportState, 'Faii_evap_wiso' , input=fiso_evap, index=3, &
=======
    if (State_FldChk(exportState, 'mean_evap_rate_atm_into_ice_wiso')) then
       !  Isotope evap to atm
       call state_setexport(exportState, 'mean_evap_rate_atm_into_ice_wiso' , input=fiso_evap, index=1, &
            lmask=tmask, ifrac=ailohi, ungridded_index=3, areacor=mod2med_areacor, rc=rc)
       if (ChkErr(rc,__LINE__,u_FILE_u)) return
       call state_setexport(exportState, 'mean_evap_rate_atm_into_ice_wiso' , input=fiso_evap, index=2, &
            lmask=tmask, ifrac=ailohi, ungridded_index=1, areacor=mod2med_areacor, rc=rc)
       if (ChkErr(rc,__LINE__,u_FILE_u)) return
       call state_setexport(exportState, 'mean_evap_rate_atm_into_ice_wiso' , input=fiso_evap, index=3, &
>>>>>>> 55bb543 (access driver)
...
<<<<<<< HEAD
    if ( State_FldChk(exportState, 'Si_ifrac_n') .and. &
         State_FldChk(exportState, 'Fioi_swpen_ifrac_n')) then
       do n = 1,ncat
          call state_setexport(exportState, 'Si_ifrac_n', input=aicen_init, index=n, &
=======
    if ( State_FldChk(exportState, 'ice_fraction_n') .and. &
         State_FldChk(exportState, 'mean_sw_pen_to_ocn_ifrac_n')) then
       do n = 1,ncat
          call state_setexport(exportState, 'ice_fraction_n', input=aicen_init, index=n, &
>>>>>>> 55bb543 (access driver)
...

<<<<<<< HEAD
          call state_setexport(exportState, 'Fioi_swpen_ifrac_n', input=fswthrun_ai, index=n, &
=======
          call state_setexport(exportState, 'mean_sw_pen_to_ocn_ifrac_n', input=fswthrun_ai, index=n, &
>>>>>>> 55bb543 (access driver)


Accept name changes from main.

Later during the rebase, the following clash came up:

<<<<<<< HEAD
    ! flux of heat exchange with ocean
    call state_setexport(exportState, 'Fioi_melth' , input=fhocn, lmask=tmask, ifrac=ailohi, &
         areacor=mod2med_areacor, rc=rc)
    if (ChkErr(rc,__LINE__,u_FILE_u)) return

    ! flux fresh water to ocean (h2o flux from melting)
    call state_setexport(exportState, 'Fioi_meltw' , input=fresh, lmask=tmask, ifrac=ailohi, &
         areacor=mod2med_areacor, rc=rc)
    if (ChkErr(rc,__LINE__,u_FILE_u)) return

    ! flux of salt to ocean (salt flux from melting)
    call state_setexport(exportState, 'Fioi_salt' , input=fsalt, lmask=tmask, ifrac=ailohi, &
         areacor=mod2med_areacor, rc=rc)
    if (ChkErr(rc,__LINE__,u_FILE_u)) return
=======
   !  ! flux of heat exchange with ocean
   !  call state_setexport(exportState, 'net_heat_flx_to_ocn' , input=fhocn, lmask=tmask, ifrac=ailohi, &
   !       areacor=mod2med_areacor, rc=rc)
   !  if (ChkErr(rc,__LINE__,u_FILE_u)) return

   !  ! flux fresh water to ocean (h2o flux from melting)
   !  call state_setexport(exportState, 'mean_fresh_water_to_ocean_rate' , input=fresh, lmask=tmask, ifrac=ailohi, &
   !       areacor=mod2med_areacor, rc=rc)
   !  if (ChkErr(rc,__LINE__,u_FILE_u)) return

   !  ! flux of salt to ocean (salt flux from melting)
   !  call state_setexport(exportState, 'mean_salt_rate' , input=fsalt, lmask=tmask, ifrac=ailohi, &
   !       areacor=mod2med_areacor, rc=rc)
   !  if (ChkErr(rc,__LINE__,u_FILE_u)) return
>>>>>>> 85f6fe0 (time average ice->ocn fluxes)

These state_setexport calls were commented out when time averaging of the fluxes was implemented. Keep them commented out, however swap to the new naming scheme.

We also need to change the names in the custom access routines ice_increment_fluxes and ice_export_access:

   call state_getfldptr(state, 'net_heat_flx_to_ocn', fhocn_ptr, rc)
   call state_getfldptr(state, 'mean_fresh_water_to_ocean_rate', fresh_ptr, rc)
   call state_getfldptr(state, 'mean_salt_rate', fsalt_ptr, rc)
  call state_getfldptr(exportState, 'net_heat_flx_to_ocn', fhocn_ptr, rc)
   call state_getfldptr(exportState, 'mean_fresh_water_to_ocean_rate', fresh_ptr, rc)

Adding back unused aerosol and water isotope fields

The section below was removed from the access driver somewhere between the time where the nuopc/cmeps driver was still used, and when it became a standalone access/cmeps driver

From what I can tell, Faxa_bcp, Faxa_dstwet, and shum_wiso are not present in esmFldsExchange_access_advt.F90. I'm opting to keep what's in main in order to keep our code as similar as possible, though am not 100% sure whether this is the right approach.

<<<<<<< HEAD
    !-------------------------------------------------------
    ! Get aerosols from mediator
    !-------------------------------------------------------

    if (State_FldChk(importState, 'Faxa_bcph')) then
       ! the following indices are based on what the atmosphere is sending
       ! bcphidry  ungridded_index=1
       ! bcphodry  ungridded_index=2
       ! bcphiwet  ungridded_index=3

       call state_getfldptr(importState, 'Faxa_bcph', fldptr=dataPtr2d, rc=rc)
       if (ChkErr(rc,__LINE__,u_FILE_u)) return
       n = 0
       do iblk = 1, nblocks
          this_block = get_block(blocks_ice(iblk),iblk)
          ilo = this_block%ilo; ihi = this_block%ihi
          jlo = this_block%jlo; jhi = this_block%jhi
          do j = jlo, jhi
             do i = ilo, ihi
                n = n+1
                faero_atm(i,j,1,iblk)  = dataPtr2d(2,n) * med2mod_areacor(n) ! bcphodry
                faero_atm(i,j,2,iblk)  = (dataptr2d(1,n) + dataPtr2d(3,n)) * med2mod_areacor(n) ! bcphidry + bcphiwet
             end do
          end do
       end do
    end if

    ! Sum over all dry and wet dust fluxes from ath atmosphere
    if (State_FldChk(importState, 'Faxa_dstwet') .and. State_FldChk(importState, 'Faxa_dstdry')) then
       call state_getfldptr(importState, 'Faxa_dstwet', fldptr=dataPtr2d_dstwet, rc=rc)
       if (ChkErr(rc,__LINE__,u_FILE_u)) return
       call state_getfldptr(importState, 'Faxa_dstdry', fldptr=dataPtr2d_dstdry, rc=rc)
       if (ChkErr(rc,__LINE__,u_FILE_u)) return
       n = 0
       do iblk = 1, nblocks
          this_block = get_block(blocks_ice(iblk),iblk)
          ilo = this_block%ilo; ihi = this_block%ihi
          jlo = this_block%jlo; jhi = this_block%jhi
          do j = jlo, jhi
             do i = ilo, ihi
                n = n+1
                faero_atm(i,j,3,iblk)  = dataPtr2d_dstwet(1,n) + dataptr2d_dstdry(1,n) + &
                                         dataPtr2d_dstwet(2,n) + dataptr2d_dstdry(2,n) + &
                                         dataPtr2d_dstwet(3,n) + dataptr2d_dstdry(3,n) + &
                                         dataPtr2d_dstwet(4,n) + dataptr2d_dstdry(4,n)
                faero_atm(i,j,3,iblk) = faero_atm(i,j,3,iblk) * med2mod_areacor(n)
             end do
          end do
       end do
    end if

    !-------------------------------------------------------
    ! Water isotopes from the mediator
    !-------------------------------------------------------

    ! 16O => ungridded_index=1
    ! 18O => ungridded_index=2
    ! HDO => ungridded_index=3

    if (State_FldChk(importState, 'shum_wiso')) then
       call state_getimport(importState, 'Sa_shum_wiso', output=Qa_iso, index=1, ungridded_index=3, rc=rc)
       if (ChkErr(rc,__LINE__,u_FILE_u)) return
       call state_getimport(importState, 'Sa_shum_wiso', output=Qa_iso, index=2, ungridded_index=1, rc=rc)
       if (ChkErr(rc,__LINE__,u_FILE_u)) return
       call state_getimport(importState, 'Sa_shum_wiso', output=Qa_iso, index=3, ungridded_index=2, rc=rc)
       if (ChkErr(rc,__LINE__,u_FILE_u)) return

       ! call state_getimport(importState, 'mean_prec_rate_wiso', output=fiso_rain, index=1, ungridded_index=3, &
       !      areacor=med2mod_areacor, rc=rc)
       ! if (ChkErr(rc,__LINE__,u_FILE_u)) return
       ! call state_getimport(importState, 'mean_prec_rate_wiso', output=fiso_rain, index=2, ungridded_index=1, &
       !      areacor=med2mod_areacor, rc=rc)
       ! if (ChkErr(rc,__LINE__,u_FILE_u)) return
       ! call state_getimport(importState, 'mean_prec_rate_wiso', output=fiso_rain, index=3, ungridded_index=2, &
       !      areacor=med2mod_areacor, rc=rc)
       ! if (ChkErr(rc,__LINE__,u_FILE_u)) return

       call state_getimport(importState, 'Faxa_snow_wiso', output=fiso_atm, index=1, ungridded_index=3, rc=rc)
       if (ChkErr(rc,__LINE__,u_FILE_u)) return
       call state_getimport(importState, 'Faxa_snow_wiso', output=fiso_atm, index=2, ungridded_index=1, rc=rc)
       if (ChkErr(rc,__LINE__,u_FILE_u)) return
       call state_getimport(importState, 'Faxa_snow_wiso', output=fiso_atm, index=3, ungridded_index=2, rc=rc)
       if (ChkErr(rc,__LINE__,u_FILE_u)) return

       call state_getimport(importState, 'So_roce_wiso', output=HDO_ocn   , ungridded_index=3, &
            areacor=med2mod_areacor, rc=rc)
       if (ChkErr(rc,__LINE__,u_FILE_u)) return
       call state_getimport(importState, 'So_roce_wiso', output=H2_16O_ocn, ungridded_index=1, &
            areacor=med2mod_areacor, rc=rc)
       if (ChkErr(rc,__LINE__,u_FILE_u)) return
       call state_getimport(importState, 'So_roce_wiso', output=H2_18O_ocn, ungridded_index=2, &
            areacor=med2mod_areacor, rc=rc)
       if (ChkErr(rc,__LINE__,u_FILE_u)) return
    end if

=======
>>>>>>> 55bb543 (access driver)

New restart options

In ice_comp_nuopc.F90:

<<<<<<< HEAD
  use ice_calendar       , only : force_restart_now, write_ic
  use ice_calendar       , only : idate, idate0,  mday, mmonth, myear, year_init, month_init, day_init
  use ice_calendar       , only : msec, dt, calendar, calendar_type, nextsw_cday, istep
  use ice_calendar       , only : ice_calendar_noleap, ice_calendar_gregorian, use_leap_years
  use ice_kinds_mod      , only : dbl_kind, int_kind, char_len, char_len_long
  use ice_fileunits      , only : nu_diag, nu_diag_set, inst_index, inst_name
  use ice_fileunits      , only : inst_suffix, release_all_fileunits, flush_fileunit
  use ice_restart_shared , only : runid, runtype, restart, use_restart_time, restart_dir, restart_file, &
                                  restart_format, restart_chunksize, pointer_date
  use ice_history        , only : accum_hist
  use ice_history_shared , only : history_format, history_chunksize
=======
  use ice_calendar       , only : force_restart_now, write_ic, init_calendar
  use ice_calendar       , only : idate, mday, mmonth, myear, year_init
  use ice_calendar       , only : msec, dt, calendar, calendar_type, nextsw_cday, istep
  use ice_calendar       , only : ice_calendar_noleap, ice_calendar_gregorian
  use ice_kinds_mod      , only : dbl_kind, int_kind, char_len, char_len_long
  use ice_fileunits      , only : nu_diag, nu_diag_set, inst_index, inst_name
  use ice_fileunits      , only : inst_suffix, release_all_fileunits, flush_fileunit
  use ice_restart_shared , only : runid, runtype, restart, use_restart_time, restart_dir, restart_file
  use ice_history        , only : accum_hist
>>>>>>> 55bb543 (access driver)

Calendar variables month_init, day_init, use_leap_years added. Restart and history settings restart_format, restart_chunksize, pointer_date added.

Restart formatting namelist options were added in aca8357. I'll accept the changes from main but we may need to check our cice namelist settings in the suite – I think we're currently setting it via the nuopc.runconfig

<<<<<<< HEAD
  integer                      :: nthrds       ! Number of threads to use in this component
  integer                      :: nu_timer = 6 ! Simple timer log, unused except by UFS
  integer                      :: dbug = 0
  logical                      :: profile_memory = .false.
  logical                      :: mastertask
  logical                      :: runtimelog = .false.
  logical                      :: restart_eor = .false. !End of run restart flag
=======
  integer                      :: nthrds   ! Number of threads to use in this component

  integer                      :: dbug = 0
  logical                      :: profile_memory = .false.
  logical                      :: mastertask
>>>>>>> 55bb543 (access driver)

9c4334a adds option to write restart at end of run. Seems ok to include, so accept changes from main.

<<<<<<< HEAD
    force_restart_now = .false.

=======
>>>>>>> 55bb543 (access driver)
    if (ESMF_AlarmIsRinging(alarm, rc=rc)) then
       if (ChkErr(rc,__LINE__,u_FILE_u)) return
       force_restart_now = .true.
       call ESMF_AlarmRingerOff( alarm, rc=rc )
       if (ChkErr(rc,__LINE__,u_FILE_u)) return

       call ESMF_ClockGetNextTime(clock, nextTime=nextTime, rc=rc)
       if (ChkErr(rc,__LINE__,u_FILE_u)) return
       call ESMF_TimeGet(nexttime, yy=yy, mm=mm, dd=dd, s=tod, rc=rc)
       if (ChkErr(rc,__LINE__,u_FILE_u)) return

       write(restart_date,"(i4.4,a,i2.2,a,i2.2,a,i5.5)") yy, '-', mm, '-',dd,'-',tod
       write(restart_filename,'(4a)') trim(restart_dir), trim(restart_file), '.', trim(restart_date)
<<<<<<< HEAD
    endif

    ! Handle end of run restart
    if (restart_eor) then
       call ESMF_ClockGetAlarm(clock, alarmname='alarm_stop', alarm=alarm, rc=rc)
       if (ChkErr(rc,__LINE__,u_FILE_u)) return
       if (ESMF_AlarmIsRinging(alarm, rc=rc)) then
          if (ChkErr(rc,__LINE__,u_FILE_u)) return
          force_restart_now = .true.
          call ESMF_AlarmRingerOff( alarm, rc=rc )
          if (ChkErr(rc,__LINE__,u_FILE_u)) return
       endif
=======
    else
       force_restart_now = .false.
>>>>>>> 55bb543 (access driver)

Accept changes for end of run restart option.

Removing extra print of ungriddedUbound

In subroutine ice_realize_fields(gcomp, mesh, flds_scalar_name, flds_scalar_num, rc):

    real(dbl_kind)              :: min_med2mod_areacor_glob
    character(len=*), parameter :: subname='(ice_import_export:realize_fields)'
<<<<<<< HEAD
=======
    character(len=100) :: tmpString
    integer            :: ungriddedUbound(1)

>>>>>>> 55bb543 (access driver)

...

<<<<<<< HEAD
=======
   call ESMF_StateGet(exportState, itemName='ia_aicen', field=lfield, rc=rc)
   call ESMF_FieldGet(lfield, ungriddedUBound=ungriddedUbound, rc=rc)
   write (tmpString, *) ungriddedUbound(1)
   call ESMF_LogWrite('CICE ungridded ubound: ' // trim(tmpString), ESMF_LogMsg_Info, rc=rc)
     
>>>>>>> 55bb543 (access driver)

From what I can tell, the addition in our branch of the ungriddedUbound print has no impact and can be removed.

Simpler changes

Details

CICE_InitMod.F90:

<<<<<<< HEAD
    use ice_forcing_bgc      , only: faero_default, alloc_forcing_bgc, fiso_default
    use ice_grid             , only: dealloc_grid
=======
    use ice_forcing_bgc      , only: faero_default, faero_optics, alloc_forcing_bgc, fiso_default
>>>>>>> 55bb543 (access driver)

Accept changes from main

<<<<<<< HEAD
    call icepack_init_itd(hin_max=hin_max)  ! ice thickness distribution
    if (my_task == master_task) then
       call icepack_init_itd_hist(hin_max=hin_max, c_hi_range=c_hi_range) ! output
=======
    call icepack_init_itd(ncat=ncat, hin_max=hin_max)  ! ice thickness distribution
    if (my_task == master_task) then
       call icepack_init_itd_hist(ncat=ncat, hin_max=hin_max, c_hi_range=c_hi_range) ! output
>>>>>>> 55bb543 (access driver)

Redundant arguments removed. Accept changes from main.

<<<<<<< HEAD
    if (tr_fsd) call icepack_init_fsd_bounds ( &
         floe_rad_l_out = floe_rad_l,    &  ! fsd size lower bound in m (radius)
         floe_rad_c_out = floe_rad_c,    &  ! fsd size bin centre in m (radius)
         floe_binwidth_out = floe_binwidth, &  ! fsd size bin width in m (radius)
         c_fsd_range_out = c_fsd_range,   &  ! string for history output
         write_diags=(my_task == master_task))  ! write diag on master only
=======
    if (tr_fsd) call icepack_init_fsd_bounds (nfsd, & ! floe size distribution
         floe_rad_l,    &  ! fsd size lower bound in m (radius)
         floe_rad_c,    &  ! fsd size bin centre in m (radius)
         floe_binwidth, &  ! fsd size bin width in m (radius)
         c_fsd_range,   &  ! string for history output
         write_diags=(my_task == master_task))  ! write diag on master only

>>>>>>> 55bb543 (access driver)

Redundant arguments removed. Accept changes from main.

<<<<<<< HEAD
    call dealloc_grid         ! deallocate temporary grid arrays

=======
>>>>>>> 55bb543 (access driver)

Accept changes from main

<<<<<<< HEAD
    use ice_flux, only: Tf
=======
>>>>>>> 55bb543 (access driver)

As mentioned earlier, Tf is now provided as an input from CICE into several icepack routines. Likely related, so accept changes from main.

<<<<<<< HEAD
         restart_bgc
=======
         restart_zsal, restart_bgc
>>>>>>> 55bb543 (access driver)

Related to deprecation of zsalinity in icepack. Accept changes from main.

<<<<<<< HEAD
         skl_bgc, z_tracers
=======
         skl_bgc, z_tracers, solve_zsal
>>>>>>> 55bb543 (access driver)

Related to z_salinity deprecation in icepack. Accept changes from main

<<<<<<< HEAD
    call icepack_query_parameters(skl_bgc_out=skl_bgc, z_tracers_out=z_tracers)
=======
    call icepack_query_parameters(skl_bgc_out=skl_bgc, &
         z_tracers_out=z_tracers, solve_zsal_out=solve_zsal)
>>>>>>> 55bb543 (access driver)

Related to z_salinity deprecation in icepack. Accept changes from main

<<<<<<< HEAD
=======
       if (solve_zsal) &
            restart_zsal = .true.
>>>>>>> 55bb543 (access driver)

Related to z_salinity deprecation in icepack. Accept changes from main

<<<<<<< HEAD
    if (skl_bgc .or. z_tracers) then ! biogeochemistry
=======
    if (solve_zsal .or. skl_bgc .or. z_tracers) then ! biogeochemistry
>>>>>>> 55bb543 (access driver)

Related to z_salinity deprecation in icepack. Accept changes from main

<<<<<<< HEAD
                call icepack_aggregate(             &
=======
                call icepack_aggregate(ncat  = ncat,                  &
>>>>>>> 55bb543 (access driver)
                     aicen = aicen(i,j,:,iblk),     &
                     trcrn = trcrn(i,j,:,:,iblk),   &
                     vicen = vicen(i,j,:,iblk),     &
                     vsnon = vsnon(i,j,:,iblk),     &
                     aice  = aice (i,j,  iblk),     &
                     trcr  = trcr (i,j,:,iblk),     &
                     vice  = vice (i,j,  iblk),     &
                     vsno  = vsno (i,j,  iblk),     &
                     aice0 = aice0(i,j,  iblk),     &
<<<<<<< HEAD
                     trcr_depend   = trcr_depend,   &
                     trcr_base     = trcr_base,     &
                     n_trcr_strata = n_trcr_strata, &
                     nt_strata     = nt_strata,     &
                     Tf            = Tf(i,j,iblk))
=======
                     ntrcr = ntrcr,                 &
                     trcr_depend   = trcr_depend,   &
                     trcr_base     = trcr_base,     &
                     n_trcr_strata = n_trcr_strata, &
                     nt_strata     = nt_strata)
>>>>>>> 55bb543 (access driver)

Icepack interface updates: removing redundant parameters and feeding Tf from CICE to icepack. Accept changes from main.

CICE_RunMod.F90

<<<<<<< HEAD
      use ice_constants, only: c3600
      use ice_boundary, only: ice_HaloUpdate
      use ice_calendar, only: dt, dt_dyn, ndtd, diagfreq, write_restart, istep
      use ice_calendar, only: idate, myear, mmonth, mday, msec, timesecs
      use ice_calendar, only: calendar_sec2hms, write_history, nstreams, histfreq
      use ice_diagnostics, only: init_mass_diags, runtime_diags, debug_model, debug_ice
      use ice_diagnostics_bgc, only: hbrine_diags, bgc_diags
=======
      use ice_boundary, only: ice_HaloUpdate
      use ice_calendar, only: dt, dt_dyn, ndtd, diagfreq, write_restart, istep
      use ice_calendar, only: idate, msec
      use ice_diagnostics, only: init_mass_diags, runtime_diags, debug_model, debug_ice
      use ice_diagnostics_bgc, only: hbrine_diags, zsal_diags, bgc_diags
>>>>>>> 55bb543 (access driver)

Accept changes from main.

<<<<<<< HEAD
          daidtt, daidtd, dvidtt, dvidtd, dvsdtt, dvsdtd, dagedtt, dagedtd
=======
          daidtt, daidtd, dvidtt, dvidtd, dagedtt, dagedtd
>>>>>>> 55bb543 (access driver)

New diagnostic added in 2209749. Accept changes from main.

<<<<<<< HEAD
      use ice_communicate, only: MPI_COMM_ICE, my_task, master_task
=======
      use ice_communicate, only: MPI_COMM_ICE
>>>>>>> 55bb543 (access driver)

Accept changes from main

<<<<<<< HEAD
          calc_Tsfc, skl_bgc, z_tracers, wave_spec
=======
          calc_Tsfc, skl_bgc, solve_zsal, z_tracers, wave_spec
>>>>>>> 55bb543 (access driver)

Zsalinity deprecation. Accept changes from main

<<<<<<< HEAD
      integer (kind=int_kind)  :: hh,mm,ss,ns
      character (len=char_len) :: logmsg
=======
>>>>>>> 55bb543 (access driver)

New logging features, accept changes from main.

<<<<<<< HEAD
           z_tracers_out=z_tracers, ktherm_out=ktherm, wave_spec_out=wave_spec)
=======
           solve_zsal_out=solve_zsal, z_tracers_out=z_tracers, ktherm_out=ktherm, &
           wave_spec_out=wave_spec)
>>>>>>> 55bb543 (access driver)

Related to z_salinity deprecation in icepack. Accept changes from main.

<<<<<<< HEAD
=======
#ifdef CESMCOUPLED
>>>>>>> 55bb543 (access driver)
         if (prescribed_ice) then  ! read prescribed ice
            call t_barrierf('cice_run_presc_BARRIER',MPI_COMM_ICE)
            call t_startf ('cice_run_presc')
            call ice_prescribed_run(idate, msec)
            call t_stopf ('cice_run_presc')
         endif
<<<<<<< HEAD
=======
#endif
>>>>>>> 55bb543 (access driver)

We don't run with prescribed ice anyway, so should be safe to accept changes from main.

<<<<<<< HEAD
         call update_state (dt=dt, daidt=daidtt, dvidt=dvidtt, dvsdt=dvsdtt, &
                            dagedt=dagedtt, offset=offset)
=======
         call update_state (dt, daidtt, dvidtt, dagedtt, offset)
>>>>>>> 55bb543 (access driver)

Accept changes from main.

<<<<<<< HEAD
=======
            if (solve_zsal) call zsal_diags
>>>>>>> 55bb543 (access driver)

...

<<<<<<< HEAD
            if (skl_bgc .or. z_tracers) &
=======
            if (solve_zsal .or. skl_bgc .or. z_tracers) &
>>>>>>> 55bb543 (access driver)

Zsal deprecation, accept changes from main.

<<<<<<< HEAD
          albicen, albsnon, albpndn, apeffn, snowfracn
=======
          albicen, albsnon, albpndn, apeffn, fzsal_g, fzsal, snowfracn
>>>>>>> 55bb543 (access driver)

...

<<<<<<< HEAD
          flux_bio, flux_bio_ai, fnit, fsil, famm, fdmsp, fdms, fhum, &
          fdust, falgalN, fdoc, fdic, fdon, ffep, ffed, bgcflux_ice_to_ocn
=======
          fzsal_ai, fzsal_g_ai, flux_bio, flux_bio_ai, &
          fnit, fsil, famm, fdmsp, fdms, fhum, fdust, falgalN, &
          fdoc, fdic, fdon, ffep, ffed, bgcflux_ice_to_ocn
>>>>>>> 55bb543 (access driver)

Zsal deprecation. Accept changes from main.

<<<<<<< HEAD
=======
            fzsal_ai  (i,j,iblk) = fzsal  (i,j,iblk)
            fzsal_g_ai(i,j,iblk) = fzsal_g(i,j,iblk)
>>>>>>> 55bb543 (access driver)

Zsal deprecation. Accept changes from main.

<<<<<<< HEAD
=======
                            fzsal    (:,:,iblk), fzsal_g (:,:,iblk), &
>>>>>>> 55bb543 (access driver)

Zsal deprecation. Accept changes from main.

ice_mesh_mod.F90

<<<<<<< HEAD
    use ice_grid      , only : dxT, dyT, dxU, dyU
=======
    use ice_grid      , only : dxT, dyT, dxU, dyU, dyhx, dxhy, cyp, cxp, cym, cxm
>>>>>>> 55bb543 (access driver)

...

<<<<<<< HEAD
=======
             dxhy  (i,j,iblk) = 1.e36_dbl_kind
             dyhx  (i,j,iblk) = 1.e36_dbl_kind
             cyp   (i,j,iblk) = 1.e36_dbl_kind
             cxp   (i,j,iblk) = 1.e36_dbl_kind
             cym   (i,j,iblk) = 1.e36_dbl_kind
             cxm   (i,j,iblk) = 1.e36_dbl_kind
>>>>>>> 55bb543 (access driver)

These grid variables were removed from this module, accept changes from main.

<<<<<<< HEAD
       ilo = this_block%ilo
       ihi = this_block%ihi
       jlo = this_block%jlo
       jhi = this_block%jhi
       do j = jlo, jhi
          do i = ilo, ihi
             n = n + 1
=======
       do j = jlo, jhi
          jlo = this_block%jlo
          jhi = this_block%jhi
          do i = ilo, ihi
             ilo = this_block%ilo
             ihi = this_block%ihi
             n = n+1
>>>>>>> 55bb543 (access driver)

Accept change from main. This also lets us stop using this patch

ice_prescribed_mod.F90

We don't use this module, and so I just used the changes from main for all clashes.

ice_shr_methods.F90

Just logging changes. Accepted all changes from main

ice_comp_nuopc.F90

<<<<<<< HEAD
  use cice_wrapper_mod   , only : shr_log_getlogunit, shr_log_setlogunit
  use cice_wrapper_mod   , only : ufs_settimer, ufs_logtimer, ufs_file_setlogunit, wtime
=======
  use cice_wrapper_mod   , only : shr_file_getlogunit, shr_file_setlogunit
>>>>>>> 55bb543 (access driver)

Accept changes from main. Related to new stub logging routines.

<<<<<<< HEAD
       if (mastertask) write(nu_diag,*) trim(errmsg)
=======
       write(nu_diag,*) trim(errmsg)
>>>>>>> 55bb543 (access driver)

Accept changes from main.

<<<<<<< HEAD
    ! Netcdf output created by PIO
    call NUOPC_CompAttributeGet(gcomp, name="pio_typename", value=cvalue, &
         isPresent=isPresent, isSet=isSet, rc=rc)
    if (chkerr(rc,__LINE__,u_FILE_u)) return
    if (isPresent .and. isSet) then
      if (trim(history_format)/='cdf1' .and. mastertask) then
         write(nu_diag,*) trim(subname)//history_format//'WARNING: history_format from cice_namelist ignored'
         write(nu_diag,*) trim(subname)//'WARNING: using '//trim(cvalue)//' from ICE_modelio'
      endif
      if (trim(restart_format)/='cdf1' .and. mastertask) then
         write(nu_diag,*) trim(subname)//restart_format//'WARNING: restart_format from cice_namelist ignored'
         write(nu_diag,*) trim(subname)//'WARNING: using '//trim(cvalue)//' from ICE_modelio'
      endif

      ! The only reason to set these is to detect in ice_history_write if the chunk/deflate settings are ok.
      select case (trim(cvalue))
      case ('netcdf4p')
         history_format='hdf5'
         restart_format='hdf5'
      case ('netcdf4c')
         if (mastertask) write(nu_diag,*) trim(subname)//'WARNING: pio_typename = netcdf4c is superseded, use netcdf4p'
         history_format='hdf5'
         restart_format='hdf5'
      case default !pio_typename=netcdf or pnetcdf
         ! do nothing
      end select
    else
      if(mastertask) write(nu_diag,*) trim(subname)//'WARNING: pio_typename from driver needs to be set for netcdf output to work'
    end if

=======
>>>>>>> 55bb543 (access driver)

Include new output options from main.

<<<<<<< HEAD
       msec  = start_tod                         ! start from basedate
=======
>>>>>>> 55bb543 (access driver)

Change added here to allow different start times.

<<<<<<< HEAD
    !  - start time from ESMF clock. Used to set history time units
    idate0    = start_ymd
    year_init = (idate0/10000)
    month_init= (idate0-year_init*10000)/100           ! integer month of basedate
    day_init  = idate0-year_init*10000-month_init*100

    !  - Set use_leap_years based on calendar (as some CICE calls use this instead of the calendar type)
    if (calendar_type == ice_calendar_gregorian) then
      use_leap_years = .true.
    else
      use_leap_years = .false. ! no_leap calendars
    endif

=======
>>>>>>> 55bb543 (access driver)

9f30120
adds changes to correct the time units for model output. Accept changes from main.

<<<<<<< HEAD
    call ice_prescribed_init(gcomp, clock, ice_mesh, rc)
=======
    call ice_prescribed_init(clock, ice_mesh, rc)
>>>>>>> 55bb543 (access driver)

Accept changes from main.

<<<<<<< HEAD
       call State_SetScalar(dble(0), flds_scalar_index_nx, exportState, &
            flds_scalar_name, flds_scalar_num, rc)
       if (ChkErr(rc,__LINE__,u_FILE_u)) return
       call State_SetScalar(dble(0), flds_scalar_index_ny, exportState, &
            flds_scalar_name, flds_scalar_num, rc)
       if (ChkErr(rc,__LINE__,u_FILE_u)) return
=======
>>>>>>> 55bb543 (access driver)

Change supossedly only affects CAM single column runs, so include it.

<<<<<<< HEAD
=======
    integer                    :: nsteps     ! Number of model timeteps per coupling timestep
    integer                    :: cpl_dt     ! Coupling timestep in seconds
>>>>>>> 55bb543 (access driver)


<<<<<<< HEAD
    call CICE_Run()
=======
    call ESMF_TimeIntervalGet(timeStep, s=cpl_dt)
    nsteps = INT(cpl_dt / dt) 
    do k=1, nsteps
      call CICE_Run()
    end do
    
>>>>>>> 55bb543 (access driver)

We run multiple timesteps per ModelAdvance call, so keep the changes from our branch.

<<<<<<< HEAD
    call shr_log_getLogUnit (shrlogunit)
    call shr_log_setLogUnit (nu_diag)
=======
    call shr_file_getLogUnit (shrlogunit)
    call shr_file_setLogUnit (nu_diag)
>>>>>>> 55bb543 (access driver)

Accept changes from main.

<<<<<<< HEAD
    call shr_log_setLogUnit (shrlogunit)
=======
    call shr_file_setLogUnit (shrlogunit)
>>>>>>> 55bb543 (access driver)

Accept changes from main.

<<<<<<< HEAD
    integer, save                :: prev_orb_year=0 ! orbital year for previous orbital computation
    logical                      :: lprint
    logical, save                :: first_time = .true.
=======
    logical                      :: lprint
    logical                      :: first_time = .true.
>>>>>>> 55bb543 (access driver)

...

<<<<<<< HEAD
    else
       orb_year = orb_iyear
    end if

    if (orb_year .ne. prev_orb_year) then
       lprint = mastertask
       ! this prevents the orbital print happening before the log file is opened.
       if (.not. first_time) prev_orb_year = orb_year
    endif
    eccen = orb_eccen

=======
       lprint = mastertask
    else
       orb_year = orb_iyear
       if (first_time) then
          lprint = mastertask
       else
          lprint = .false.
       end if
    end if

    eccen = orb_eccen
>>>>>>> 55bb543 (access driver)

Just related to logging changes. Accept changes from main.

ice_import_export.F90

<<<<<<< HEAD
=======
  use ice_flux           , only : flatn_f, fcondtopn_f, fsurfn_f
>>>>>>> 55bb543 (access driver)

These fields are added for CM3 coupling. Keep changes from our branch.

<<<<<<< HEAD
=======
    call ice_advertise_fields_access_export(gcomp, importState, exportState, flds_scalar_name, rc)

>>>>>>> 55bb543 (access driver)

Make sure to keep our custom routine.


<<<<<<< HEAD

    ! allocate area correction factors
    call ESMF_MeshGet(mesh, numOwnedElements=numOwnedElements, rc=rc)
    if (chkerr(rc,__LINE__,u_FILE_u)) return
    allocate (mod2med_areacor(numOwnedElements))
    allocate (med2mod_areacor(numOwnedElements))

    if (single_column) then

       mod2med_areacor(:) = 1._dbl_kind
       med2mod_areacor(:) = 1._dbl_kind

    else

       ! Get mesh areas from second field - using second field since the
       ! first field is the scalar field

       call ESMF_StateGet(exportState, itemName=trim(fldsFrIce(2)%stdname), field=lfield, rc=rc)
       if (ChkErr(rc,__LINE__,u_FILE_u)) return
       call ESMF_FieldRegridGetArea(lfield, rc=rc)
       if (chkerr(rc,__LINE__,u_FILE_u)) return
       call ESMF_FieldGet(lfield, farrayPtr=dataptr, rc=rc)
       if (chkerr(rc,__LINE__,u_FILE_u)) return
       allocate(mesh_areas(numOwnedElements))
       mesh_areas(:) = dataptr(:)

       ! Determine flux correction factors (module variables)
       allocate(model_areas(numOwnedElements))
       mod2med_areacor(:) = 1._dbl_kind
       med2mod_areacor(:) = 1._dbl_kind
       n = 0
       do iblk = 1, nblocks
          this_block = get_block(blocks_ice(iblk),iblk)
          ilo = this_block%ilo
          ihi = this_block%ihi
          jlo = this_block%jlo
          jhi = this_block%jhi
          do j = jlo, jhi
             do i = ilo, ihi
                n = n+1
                model_areas(n) = tarea(i,j,iblk)/(radius*radius)
                mod2med_areacor(n) = model_areas(n) / mesh_areas(n)
                med2mod_areacor(n) = mesh_areas(n) / model_areas(n)
             enddo
          enddo
       enddo
       deallocate(model_areas)
       deallocate(mesh_areas)
    end if
=======
    ! Get mesh areas from second field - using second field since the
    ! first field is the scalar field
    if (single_column) return

    call ESMF_MeshGet(mesh, numOwnedElements=numOwnedElements, rc=rc)
    if (chkerr(rc,__LINE__,u_FILE_u)) return
    call ESMF_StateGet(exportState, itemName=trim(fldsFrIce(2)%stdname), field=lfield, rc=rc)
    if (ChkErr(rc,__LINE__,u_FILE_u)) return
    call ESMF_FieldRegridGetArea(lfield, rc=rc)
    if (chkerr(rc,__LINE__,u_FILE_u)) return
    call ESMF_FieldGet(lfield, farrayPtr=dataptr, rc=rc)
    if (chkerr(rc,__LINE__,u_FILE_u)) return
    allocate(mesh_areas(numOwnedElements))
    mesh_areas(:) = dataptr(:)

    ! Determine flux correction factors (module variables)
    allocate(model_areas(numOwnedElements))
    allocate(mod2med_areacor(numOwnedElements))
    allocate(med2mod_areacor(numOwnedElements))
    mod2med_areacor(:) = 1._dbl_kind
    med2mod_areacor(:) = 1._dbl_kind
    n = 0
    do iblk = 1, nblocks
       this_block = get_block(blocks_ice(iblk),iblk)
       ilo = this_block%ilo
       ihi = this_block%ihi
       jlo = this_block%jlo
       jhi = this_block%jhi
       do j = jlo, jhi
          do i = ilo, ihi
             n = n+1
             model_areas(n) = tarea(i,j,iblk)/(radius*radius)
             mod2med_areacor(n) = model_areas(n) / mesh_areas(n)
             med2mod_areacor(n) = mesh_areas(n) / model_areas(n)
          enddo
       enddo
    enddo
    deallocate(model_areas)
    deallocate(mesh_areas)
>>>>>>> 55bb543 (access driver)

Keep the changes from main as they are related to a bugfix.

In subroutine ice_import( importState, rc ):

<<<<<<< HEAD
=======
    use icepack_tracers, only: nt_Tsfc
    use icepack_parameters, only: Lsub

>>>>>>> 55bb543 (access driver)

Keep the changes from our branch, which were added specifically for CM3, in order to process fluxes imported to CICE. See here.

<<<<<<< HEAD
=======
    do i=1,ncat
      call state_getimport(importState, 'sublim', output=flatn_f, index=i, ungridded_index=i, rc=rc)
      call state_getimport(importState, 'botmelt', output=fcondtopn_f, index=i, ungridded_index=i, rc=rc)
      call state_getimport(importState, 'topmelt', output=fsurfn_f, index=i, ungridded_index=i, rc=rc)
      call state_getimport(importState, 'tstar_sice', output=trcrn(:,:,nt_Tsfc,:,:), index=i, ungridded_index=i, rc=rc)
    end do

    !$OMP PARALLEL DO PRIVATE(iblk,i,j)
    do iblk = 1, nblocks
      do j = 1,ny_block
         do i = 1,nx_block
            do k=1,ncat
               flatn_f(i,j,k,iblk) = -flatn_f(i,j,k,iblk) * Lsub ! convert to W m-2
               fsurfn_f(i,j,k,iblk) = fsurfn_f(i,j,k,iblk) +  fcondtopn_f(i,j,k,iblk)

               if (trcrn(i,j,nt_Tsfc,k,iblk) > 200.0) then
                  trcrn(i,j,nt_Tsfc,k,iblk) = trcrn(i,j,nt_Tsfc,k,iblk) - Tffresh
               end if
               trcrn(i,j,nt_Tsfc,k,iblk) = max(trcrn(i,j,nt_Tsfc,k,iblk), -60.0)
               trcrn(i,j,nt_Tsfc,k,iblk) = min(trcrn(i,j,nt_Tsfc,k,iblk), 0.0)
            end do
         end do
      end do
   end do
   !$OMP END PARALLEL DO

    ! flatn_f = - Foxx_evap(i,j,cat,k) * Lsub !! latent heat - 
    ! fcondtopn_f = botmelt 
    ! fsurfn_f   (:,:,cat,:) = topmelt(:,:,cat,:) + botmelt(:,:,cat,:)
      ! if (um_tsfice(i,j,cat,k) > 0.0) then
   !  trcrn(i,j,nt_Tsfc,cat,k) = 0.0 
   ! else if (um_tsfice(i,j,cat,k) < -60.0) then
   !   trcrn(i,j,nt_Tsfc,cat,k) = -60.0 
   ! else
   !   trcrn(i,j,nt_Tsfc,cat,k) = um_tsfice(i,j,cat,k)
   ! endif
>>>>>>> 55bb543 (access driver)

Keep the custom flux processing added for CM3.

<<<<<<< HEAD
=======
             ! strax !! windstress - already handled, come back to this
             ! stray !! windstress
             
>>>>>>> 55bb543 (access driver)

Not sure if the added comments are still relevant – I'll keep them in.


In ice_export:

<<<<<<< HEAD
  end subroutine ice_export

=======
    call ice_export_access(exportState, ailohi, rc)
    call log_state_info(exportState, fldsFrIce, fldsFrIce_num, exportState)

  end subroutine ice_export

  subroutine log_state_info(state, field_list, field_num, exportState)
   type(ESMF_State)            :: state, exportState
   type(fld_list_type)         :: field_list(:)
   integer                     :: field_num
   
   ! local variables
   type(ESMF_Field)            :: field
   character(len=320)          :: msgString, tmpString
   character(len=20)           :: fld_name
   integer                     :: i, rc, j, k, n
   real(ESMF_KIND_R8), pointer :: fld_ptr1(:), fld_ptr2(:, :), sea_ice_mask(:)
   real :: lo, hi
   real(ESMF_KIND_R8), pointer :: esmf_arr(:)

   call ESMF_StateGet(exportState, itemName='ice_mask', field=field)
   call ESMF_FieldGet(field, farrayptr=sea_ice_mask)
   
   do i = 1,field_num
     
      if (field_list(i)%stdname == 'cpl_scalars') cycle

      if (State_FldChk(state, trim(field_list(i)%stdname))) then

         write (tmpString, *) i
         call ESMF_LogWrite('i: ' // trim(tmpString) // ' - ' // trim(field_list(i)%stdname), ESMF_LOGMSG_DEBUG, rc=rc)    

         call ESMF_StateGet(state, itemName=trim(field_list(i)%stdname), field=field)

         if (field_list(i)%ungridded_lbound > 0 .and. field_list(i)%ungridded_ubound > 0) then 
            call ESMF_FieldGet(field, farrayptr=fld_ptr2)
            lo = minval(fld_ptr2)
            hi = maxval(fld_ptr2)
            write (tmpString, *) nan_check(pack(fld_ptr2, .true.))
            call ESMF_LogWrite(trim(field_list(i)%stdname) // ' any nans: ' // trim(tmpString), ESMF_LOGMSG_DEBUG, rc=rc)

         else
            call ESMF_FieldGet(field, farrayptr=fld_ptr1)
            lo = minval(fld_ptr1, sea_ice_mask==1.0)
            hi = maxval(fld_ptr1, sea_ice_mask==1.0)
            write (tmpString, *) nan_check(fld_ptr1)
            call ESMF_LogWrite(trim(field_list(i)%stdname) // ' any nans: ' // trim(tmpString), ESMF_LOGMSG_DEBUG, rc=rc)

         end if

         write (tmpString, *) lo
         call ESMF_LogWrite(trim(field_list(i)%stdname) // ' min: ' // trim(tmpString), ESMF_LOGMSG_DEBUG, rc=rc)
         write (tmpString, *) hi
         call ESMF_LogWrite(trim(field_list(i)%stdname) // ' max: ' // trim(tmpString), ESMF_LOGMSG_DEBUG, rc=rc)
   
      end if
   
   end do

 end subroutine log_state_info

 logical function nan_check(arr)
    use, intrinsic :: ieee_arithmetic
    real(ESMF_KIND_R8), intent(in)    :: arr(:)

    integer :: i

    nan_check = .false.

    do i=1,size(arr)
        nan_check = nan_check .or. ieee_is_nan(arr(i)) !.not.(arr(i) == arr(i))
    end do
    return

  end function nan_check

>>>>>>> 55bb543 (access driver)

Keep the CM3 custom export routine and logging routine.


In SetScalarField:

     character(len=*) , intent(in)    :: flds_scalar_name
      integer          , intent(in)    :: flds_scalar_num
      integer          , intent(inout) :: rc

      ! local variables
      type(ESMF_Distgrid) :: distgrid
      type(ESMF_Grid)     :: grid
<<<<<<< HEAD
      real(ESMF_KIND_R8), pointer :: fldptr2d(:,:)
=======
>>>>>>> 55bb543 (access driver)
      character(len=*), parameter :: subname='(ice_import_export:SetScalarField)'
      ! ----------------------------------------------

      rc = ESMF_SUCCESS

      ! create a DistGrid with a single index space element, which gets mapped onto DE 0.
      distgrid = ESMF_DistGridCreate(minIndex=(/1/), maxIndex=(/1/), rc=rc)
      if (ChkErr(rc,__LINE__,u_FILE_u)) return

      grid = ESMF_GridCreate(distgrid, rc=rc)
      if (ChkErr(rc,__LINE__,u_FILE_u)) return

      field = ESMF_FieldCreate(name=trim(flds_scalar_name), grid=grid, typekind=ESMF_TYPEKIND_R8, &
           ungriddedLBound=(/1/), ungriddedUBound=(/flds_scalar_num/), gridToFieldMap=(/2/), rc=rc)
      if (ChkErr(rc,__LINE__,u_FILE_u)) return

<<<<<<< HEAD
      ! initialize fldptr to zero
      call ESMF_FieldGet(field, farrayPtr=fldptr2d, rc=rc)
      if (ChkErr(rc,__LINE__,u_FILE_u)) return
      fldptr2d(:,:) = 0.0

=======
>>>>>>> 55bb543 (access driver)
    end subroutine SetScalarField

Accept the changes from main which appear to fix a potential uninitialized variable


In state_setexport_4d:

do iblk = 1, nblocks
          this_block = get_block(blocks_ice(iblk),iblk)
          ilo = this_block%ilo; ihi = this_block%ihi
          jlo = this_block%jlo; jhi = this_block%jhi
          if (present(lmask) .and. present(ifrac)) then
             do j = jlo, jhi
                do i = ilo, ihi
                   n = n+1
                   if ( lmask(i,j,iblk) .and. ifrac(i,j,iblk) > c0 ) then
                      dataPtr1d(n) = input(i,j,index,iblk)
                   end if
                end do
             end do
          else
<<<<<<< HEAD
             do j = jlo, jhi
                do i = ilo, ihi
                   n = n+1
                   dataPtr1d(n) = input(i,j,index,iblk)
                end do
=======
             do i = ilo, ihi
                n = n+1
                dataPtr1d(n) = input(i,j,index,iblk)
>>>>>>> 55bb543 (access driver)
             end do
          end if
       end do

Change relates to a bugfix, however probably doesn't affect us as it sounds like this section of the code is rarely used. Accept changes from main.


<<<<<<< HEAD
=======

  subroutine ice_advertise_fields_access_import(gcomp, importState, exportState, flds_scalar_name, rc)

   ! input/output variables
   type(ESMF_GridComp)            :: gcomp
   type(ESMF_State)               :: importState
   type(ESMF_State)               :: exportState
   character(len=*) , intent(in)  :: flds_scalar_name
   integer          , intent(out) :: rc
   
   character(len=100) :: tmpString

   call fldlist_add(fldsToIce_num, fldsToIce, 'pen_rad', ungridded_lbound=1, ungridded_ubound=ncat)   
   call fldlist_add(fldsToIce_num, fldsToIce, 'topmelt', ungridded_lbound=1, ungridded_ubound=ncat)   
   call fldlist_add(fldsToIce_num, fldsToIce, 'botmelt', ungridded_lbound=1, ungridded_ubound=ncat)   
   call fldlist_add(fldsToIce_num, fldsToIce, 'tstar_sice', ungridded_lbound=1, ungridded_ubound=ncat)   
   call fldlist_add(fldsToIce_num, fldsToIce, 'sublim', ungridded_lbound=1, ungridded_ubound=ncat)          
   
   write (tmpString, *) ncat
   call ESMF_LogWrite("CICE number of ice categories: " // trim(tmpString))
  end subroutine ice_advertise_fields_access_import


  subroutine ice_advertise_fields_access_export(gcomp, importState, exportState, flds_scalar_name, rc)

   ! input/output variables
   type(ESMF_GridComp)            :: gcomp
   type(ESMF_State)               :: importState
   type(ESMF_State)               :: exportState
   character(len=*) , intent(in)  :: flds_scalar_name
   integer          , intent(out) :: rc
   
   character(len=100) :: tmpString

   call fldlist_add(fldsFrIce_num , fldsFrIce, 'ia_aicen', ungridded_lbound=1, ungridded_ubound=ncat) ! from ice_state field: aicen
   call fldlist_add(fldsFrIce_num , fldsFrIce, 'ia_snown', ungridded_lbound=1, ungridded_ubound=ncat) ! from ice_state field: vsnon
   call fldlist_add(fldsFrIce_num , fldsFrIce, 'ia_thikn', ungridded_lbound=1, ungridded_ubound=ncat) ! from ice_state field: vicen

   call fldlist_add(fldsFrIce_num , fldsFrIce, 'ia_itopt', ungridded_lbound=1, ungridded_ubound=ncat) ! from ice flux: Tn_top
   call fldlist_add(fldsFrIce_num , fldsFrIce, 'ia_itopk', ungridded_lbound=1, ungridded_ubound=ncat) ! from ice flux: keffn_top
   call fldlist_add(fldsFrIce_num , fldsFrIce, 'ia_pndfn', ungridded_lbound=1, ungridded_ubound=ncat) ! from icepack_shorwave: apeffn
   call fldlist_add(fldsFrIce_num , fldsFrIce, 'ia_pndtn', ungridded_lbound=1, ungridded_ubound=ncat) ! from ice state field: trcrn

   write (tmpString, *) ncat
   call ESMF_LogWrite("CICE number of ice categories: " // trim(tmpString))
  end subroutine ice_advertise_fields_access_export


  subroutine ice_export_access(exportState, ailohi, rc)

   use ice_scam, only : single_column
   use ice_domain_size, only: nslyr, nilyr
   use icepack_parameters, only: hs_min, Lfresh, rhos, ksno, cp_ice, depressT, ktherm, rhoi
   use icepack_mushy_physics, only: liquidus_temperature_mush
   use icepack_therm_shared, only: calculate_Tin_from_qin
   use ice_state, only: aicen, vsnon, vicen, trcrn
   ! use icepack_therm_itd, only: nt_hpnd, 
   use icepack_tracers, only: nt_qsno, nt_hpnd, nt_sice, nt_qice
   use ice_arrays_column, only: apeffn

   ! input/output variables
   type(ESMF_State), intent(inout) :: exportState
   integer         , intent(out)   :: rc

   real    (kind=dbl_kind) :: ailohi(nx_block,ny_block,max_blocks)

   ! local variables
   type(block)             :: this_block                           ! block information for current block
   integer                 :: i, j, iblk, n, k                     ! indices
   integer                 :: ilo, ihi, jlo, jhi                   ! beginning and end of physical domain
   logical                 :: flag
   real    (kind=dbl_kind), allocatable :: tempfld(:,:,:), tempfld1(:,:,:), ki_fld(:,:,:,:), hi1_fld(:,:,:,:)
   real    (kind=dbl_kind) :: hs1, hi1, Tmlt1, ki, rnslyr, rnilyr
   logical (kind=log_kind), save :: first_call = .true.
   character(len=*),parameter :: subname = 'ice_export_access'
   character(len=200) :: tmpString
   !-----------------------------------------------------

   rc = ESMF_SUCCESS
   if (io_dbug > 5) call ESMF_LogWrite(subname//' called', ESMF_LOGMSG_INFO)

   call icepack_warnings_flush(nu_diag)
   if (icepack_warnings_aborted()) call abort_ice(error_message=subname, &
       file=u_FILE_u, line=__LINE__)

   ! Create a temporary field
   allocate(tempfld(nx_block,ny_block,nblocks))
   allocate(tempfld1(nx_block,ny_block,nblocks))
   allocate(ki_fld(nx_block,ny_block,ncat,nblocks))
   allocate(hi1_fld(nx_block,ny_block,ncat,nblocks))
   
   do n = 1, ncat
      call state_setexport(exportState, 'ia_aicen', input=aicen , lmask=tmask, ifrac=ailohi, rc=rc, index=n, ungridded_index=n)
      call state_setexport(exportState, 'ia_snown', input=vsnon , lmask=tmask, ifrac=ailohi, rc=rc, index=n, ungridded_index=n)
      call state_setexport(exportState, 'ia_thikn', input=vicen , lmask=tmask, ifrac=ailohi, rc=rc, index=n, ungridded_index=n)
      ! call state_setexport(exportState, 'ia_pndfn', input=apeffn, lmask=tmask, ifrac=ailohi, rc=rc, index=n, ungridded_index=n)
      ! call state_setexport(exportState, 'ia_pndtn', input=trcrn(:,:,nt_hpnd,:,:), lmask=tmask, ifrac=ailohi, rc=rc, index=n, ungridded_index=n)
   end do

   rnslyr = real(nslyr,kind=dbl_kind)      
   rnilyr = real(nilyr,kind=dbl_kind)  

   do n = 1, ncat
   do iblk = 1, nblocks
      this_block = get_block(blocks_ice(iblk),iblk)
      ilo = this_block%ilo
      ihi = this_block%ihi
      jlo = this_block%jlo
      jhi = this_block%jhi
      do j = jlo, jhi
         do i = ilo, ihi
            if (aicen(i,j,n,iblk) > puny) then
               hs1 = vsnon(i,j,n,iblk)/(aicen(i,j,n,iblk)*rnslyr)
               if (hs1 > hs_min/rnslyr) then
                  !snow is top layer
                  tempfld(i,j,iblk) = (Lfresh + trcrn(i,j,nt_qsno,n,iblk) / rhos)/cp_ice
                  tempfld1(i,j,iblk) = c2 * ksno / hs1   
               else
                  !ice is top layer
                  hi1 = vicen(i,j,n,iblk)/(aicen(i,j,n,iblk)*rnilyr)
                  if (ktherm == 2) then
                     Tmlt1 = liquidus_temperature_mush(trcrn(i,j,nt_sice,n,iblk))
                  else
                     Tmlt1 = - trcrn(i,j,nt_sice,n,iblk) * depressT
                  endif
                  
                  tempfld(i,j,iblk) = calculate_Tin_from_qin(trcrn(i,j,nt_qice,n,iblk),Tmlt1)
                  ki = calculate_ki_from_Tin(tempfld(i,j,iblk), trcrn(i,j,nt_sice,n,iblk))
                  tempfld1(i,j,iblk) = (c2 * ki / hi1) 
                  ki_fld(i,j,n,iblk) = tempfld(i,j,iblk) 
                  hi1_fld(i,j,n,iblk) = Tmlt1
               end if
            endif
         end do
      end do
   end do
   call state_setexport(exportState, 'ia_itopt', input=tempfld, lmask=tmask, ifrac=ailohi, rc=rc, ungridded_index=n)
   call state_setexport(exportState, 'ia_itopk', input=tempfld1, lmask=tmask, ifrac=ailohi, rc=rc, ungridded_index=n)
   end do
   
  end subroutine ice_export_access

  function calculate_ki_from_Tin (Tink, salink) &
   result(ki)

   use icepack_parameters, only: kice, conduct, rhoi
   ! use icepack_therm_bl99, only: kimin, betak
   !
   ! !USES:
   !
   ! !INPUT PARAMETERS:
   !
   real (kind=dbl_kind), intent(in) :: &
   Tink   , &             ! ice layer temperature
   salink                 ! salinity at one level
   !
   ! !OUTPUT PARAMETERS
   !
   real (kind=dbl_kind) :: &
   ki                     ! ice conductivity


   real (kind=dbl_kind), parameter :: &
         betak   = 0.13_dbl_kind, & ! constant in formula for k (W m-1 ppt-1)
         kimin   = 0.10_dbl_kind 
   !
   !EOP
   !
   if (conduct == 'MU71') then
   ! Maykut and Untersteiner 1971 form (with Wettlaufer 1991 constants)
      ki = kice + betak*salink/min(-puny,Tink)
   else
   ! Pringle et al JGR 2007 'bubbly brine'
   ki = (2.11_dbl_kind - 0.011_dbl_kind*Tink &
   + 0.09_dbl_kind*salink/min(-puny,Tink)) &
   * rhoi / 917._dbl_kind
   endif

   ki = max (ki, kimin) 

   end function calculate_ki_from_Tin

>>>>>>> 55bb543 (access driver)

Keep the custom access routines.

@blimlim blimlim requested a review from kieranricardo April 22, 2025 01:44
Copy link

@kieranricardo kieranricardo left a comment

Choose a reason for hiding this comment

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

Great work @blimlim!!

  • I suspect the water balance error increase is unrelated to your changes, and probably caused by TTI/coupling time stepping changes. Either way I think the increase is negligible, but I'll check whether it's caused by the time offset
  • the salt flux errors look fine to me, the absolute values are so small that I think you're right that the time step offset is causing this
  • swapping to the CESM names seems like the right approach to me, it's more readable and consistent with main
  • keeping the aerosols seems reasonable

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants