LCOV - code coverage report
Current view: top level - configuration/driver - icedrv_step.F90 (source / functions) Coverage Total Hit
Test: 250115-224328:3d8b76b919:4:base,io,travis,quick Lines: 88.36 % 318 281
Test Date: 2025-01-15 16:24:29 Functions: 100.00 % 11 11

            Line data    Source code
       1              : !=======================================================================
       2              : !
       3              : !  Contains Icepack component driver routines common to all drivers.
       4              : !
       5              : !  authors Elizabeth C. Hunke, LANL
       6              : 
       7              :       module icedrv_step
       8              : 
       9              :       use icedrv_constants, only: c0, nu_diag, c4, c1
      10              :       use icedrv_kinds
      11              : !      use icedrv_calendar, only: istep1
      12              :       use icedrv_forcing, only: ocn_data_type
      13              :       use icedrv_forcing, only: lateral_flux_type
      14              :       use icedrv_system, only: icedrv_system_abort
      15              :       use icepack_intfc, only: icepack_warnings_flush
      16              :       use icepack_intfc, only: icepack_warnings_aborted
      17              :       use icepack_intfc, only: icepack_query_tracer_flags
      18              :       use icepack_intfc, only: icepack_query_tracer_indices
      19              :       use icepack_intfc, only: icepack_query_tracer_sizes
      20              :       use icepack_intfc, only: icepack_query_parameters
      21              : 
      22              :       implicit none
      23              :       private
      24              : 
      25              :       public :: step_therm1, step_therm2, step_dyn_ridge, &
      26              :                 prep_radiation, step_radiation, ocean_mixed_layer, &
      27              :                 update_state, biogeochemistry, step_dyn_wave, step_snow, &
      28              :                 step_lateral_flux_scm
      29              : 
      30              : !=======================================================================
      31              : 
      32              :       contains
      33              : 
      34              : !=======================================================================
      35              : !
      36              : ! Scales radiation fields computed on the previous time step.
      37              : !
      38              : ! authors: Elizabeth Hunke, LANL
      39              : 
      40       657372 :       subroutine prep_radiation ()
      41              : 
      42              :       use icedrv_domain_size, only: ncat, nilyr, nslyr, nx
      43              :       use icedrv_flux, only: scale_factor, swvdr, swvdf, swidr, swidf
      44              :       use icedrv_flux, only: alvdr_ai, alvdf_ai, alidr_ai, alidf_ai
      45              :       use icedrv_flux, only: alvdr_init, alvdf_init, alidr_init, alidf_init
      46              :       use icedrv_arrays_column, only: fswsfcn, fswintn
      47              :       use icedrv_arrays_column, only: fswthrun, fswthrun_vdr, fswthrun_vdf, fswthrun_idr, fswthrun_idf
      48              :       use icedrv_arrays_column, only: fswpenln, Sswabsn, Iswabsn
      49              :       use icedrv_state, only: aice, aicen
      50              : 
      51              :       ! column package includes
      52              :       use icepack_intfc, only: icepack_prep_radiation
      53              : 
      54              :       ! local variables
      55              : 
      56              :       integer (kind=int_kind) :: &
      57              :          i               ! horizontal indices
      58              : 
      59              :       character(len=*), parameter :: subname='(prep_radiation)'
      60              : 
      61              :       !-----------------------------------------------------------------
      62              :       ! Compute netsw scaling factor (new netsw / old netsw)
      63              :       !-----------------------------------------------------------------
      64              : 
      65      3286860 :          do i = 1, nx
      66              : 
      67      2629488 :             alvdr_init(i) = alvdr_ai(i)
      68      2629488 :             alvdf_init(i) = alvdf_ai(i)
      69      2629488 :             alidr_init(i) = alidr_ai(i)
      70      2629488 :             alidf_init(i) = alidf_ai(i)
      71              : 
      72              :             call icepack_prep_radiation( &
      73              :                          aice=aice(i),   aicen=aicen(i,:), &
      74              :                          swvdr=swvdr(i), swvdf=swvdf(i),   &
      75              :                          swidr=swidr(i), swidf=swidf(i),   &
      76              :                          alvdr_ai=alvdr_ai(i), alvdf_ai=alvdf_ai(i), &
      77              :                          alidr_ai=alidr_ai(i), alidf_ai=alidf_ai(i), &
      78              :                          scale_factor=scale_factor(i),     &
      79              :                          fswsfcn=fswsfcn(i,:),   fswintn=fswintn(i,:),     &
      80              :                          fswthrun=fswthrun(i,:),           &
      81              :                          fswthrun_vdr=fswthrun_vdr(i,:),     &
      82              :                          fswthrun_vdf=fswthrun_vdf(i,:),     &
      83              :                          fswthrun_idr=fswthrun_idr(i,:),     &
      84              :                          fswthrun_idf=fswthrun_idf(i,:),     &
      85              :                          fswpenln=fswpenln(i,:,:),         &
      86      3286860 :                          Sswabsn=Sswabsn(i,:,:), Iswabsn=Iswabsn(i,:,:))
      87              : 
      88              :          enddo               ! i
      89       657372 :          call icepack_warnings_flush(nu_diag)
      90       657372 :          if (icepack_warnings_aborted()) call icedrv_system_abort(string=subname, &
      91            0 :              file=__FILE__, line=__LINE__)
      92              : 
      93       657372 :       end subroutine prep_radiation
      94              : 
      95              : !=======================================================================
      96              : !
      97              : ! Driver for updating ice and snow internal temperatures and
      98              : ! computing thermodynamic growth rates and coupler fluxes.
      99              : !
     100              : ! authors: William H. Lipscomb, LANL
     101              : 
     102      3944232 :       subroutine step_therm1 (dt)
     103              : 
     104              :       use icedrv_arrays_column, only: ffracn, dhsn
     105              :       use icedrv_arrays_column, only: Cdn_ocn, Cdn_ocn_skin, Cdn_ocn_floe
     106              :       use icedrv_arrays_column, only: Cdn_ocn_keel, Cdn_atm_ratio
     107              :       use icedrv_arrays_column, only: Cdn_atm, Cdn_atm_skin, Cdn_atm_floe
     108              :       use icedrv_arrays_column, only: Cdn_atm_rdg, Cdn_atm_pond
     109              :       use icedrv_arrays_column, only: hfreebd, hdraft, hridge, distrdg
     110              :       use icedrv_arrays_column, only: hkeel, dkeel, lfloe, dfloe
     111              :       use icedrv_arrays_column, only: fswsfcn, fswintn, Sswabsn, Iswabsn
     112              :       use icedrv_arrays_column, only: fswthrun, fswthrun_vdr, fswthrun_vdf, fswthrun_idr, fswthrun_idf
     113              :       use icedrv_arrays_column, only: meltsliqn, meltsliq
     114              :       use icedrv_calendar, only: yday
     115              :       use icedrv_domain_size, only: ncat, nilyr, nslyr, n_aero, n_iso, nfsd, nx
     116              :       use icedrv_flux, only: frzmlt, sst, Tf, strocnxT, strocnyT, rsiden, wlat, &
     117              :                              fbot, Tbot, Tsnice
     118              :       use icedrv_flux, only: meltsn, melttn, meltbn, congeln, snoicen, uatm, vatm
     119              :       use icedrv_flux, only: wind, rhoa, potT, Qa, Qa_iso, zlvl, strax, stray, flatn
     120              :       use icedrv_flux, only: fsensn, fsurfn, fcondtopn, fcondbotn
     121              :       use icedrv_flux, only: flw, fsnow, fpond, sss, mlt_onset, frz_onset, fsloss
     122              :       use icedrv_flux, only: frain, Tair, strairxT, strairyT, fsurf
     123              :       use icedrv_flux, only: fcondtop, fcondbot, fsens, fresh, fsalt, fhocn
     124              :       use icedrv_flux, only: flat, fswabs, flwout, evap, evaps, evapi
     125              :       use icedrv_flux, only: Tref, Qref, Qref_iso, Uref
     126              :       use icedrv_flux, only: meltt, melts, meltb, congel, snoice
     127              :       use icedrv_flux, only: fswthru, fswthru_vdr, fswthru_vdf, fswthru_idr, fswthru_idf
     128              :       use icedrv_flux, only: flatn_f, fsensn_f, fsurfn_f, fcondtopn_f
     129              :       use icedrv_flux, only: dsnow, dsnown, faero_atm, faero_ocn
     130              :       use icedrv_flux, only: fiso_atm, fiso_ocn, fiso_evap
     131              :       use icedrv_flux, only: HDO_ocn, H2_16O_ocn, H2_18O_ocn
     132              :       use icedrv_init, only: lmask_n, lmask_s
     133              :       use icedrv_state, only: aice, aicen, aice_init, aicen_init, vicen_init
     134              :       use icedrv_state, only: vice, vicen, vsno, vsnon, trcrn, uvel, vvel, vsnon_init
     135              : 
     136              :       ! column packge includes
     137              :       use icepack_intfc, only: icepack_step_therm1
     138              : 
     139              :       logical (kind=log_kind) :: &
     140              :          prescribed_ice ! if .true., use prescribed ice instead of computed
     141              : 
     142              :       real (kind=dbl_kind), intent(in) :: &
     143              :          dt      ! time step
     144              : 
     145              :       ! local variables
     146              : 
     147              :       integer (kind=int_kind) :: &
     148              :          i           , & ! horizontal indices
     149              :          n              , & ! thickness category index
     150              :          k, kk              ! indices for aerosols
     151              : 
     152              :       integer (kind=int_kind) :: &
     153              :          ntrcr, nt_apnd, nt_hpnd, nt_ipnd, nt_alvl, nt_vlvl, nt_Tsfc, &
     154              :          nt_iage, nt_FY, nt_qice, nt_sice, nt_qsno, nt_fsd, &
     155              :          nt_aero, nt_isosno, nt_isoice, nt_rsnw, nt_smice, nt_smliq
     156              : 
     157              :       logical (kind=log_kind) :: &
     158              :          tr_iage, tr_FY, tr_aero, tr_iso, calc_Tsfc, snwgrain
     159              : 
     160              :       real (kind=dbl_kind), dimension(n_aero,2,ncat) :: &
     161              :          aerosno,  aeroice    ! kg/m^2
     162              : 
     163              :       real (kind=dbl_kind), dimension(n_iso,ncat) :: &
     164              :          isosno,  isoice    ! kg/m^2
     165              : 
     166              :       real (kind=dbl_kind), dimension(nslyr,ncat) :: &
     167              :          rsnwn, smicen, smliqn
     168              : 
     169              :       real (kind=dbl_kind) :: &
     170              :          puny
     171              : 
     172              :       character(len=*), parameter :: subname='(step_therm1)'
     173              : 
     174              :       !-----------------------------------------------------------------
     175              :       ! query icepack values
     176              :       !-----------------------------------------------------------------
     177              : 
     178       657372 :       call icepack_query_parameters(puny_out=puny)
     179       657372 :       call icepack_query_parameters(calc_Tsfc_out=calc_Tsfc)
     180       657372 :       call icepack_query_parameters(snwgrain_out=snwgrain)
     181       657372 :       call icepack_warnings_flush(nu_diag)
     182       657372 :       if (icepack_warnings_aborted()) call icedrv_system_abort(string=subname, &
     183            0 :           file=__FILE__,line= __LINE__)
     184              : 
     185              :       call icepack_query_tracer_sizes( &
     186       657372 :            ntrcr_out=ntrcr)
     187       657372 :       call icepack_warnings_flush(nu_diag)
     188       657372 :       if (icepack_warnings_aborted()) call icedrv_system_abort(string=subname, &
     189            0 :           file=__FILE__,line= __LINE__)
     190              : 
     191              :       call icepack_query_tracer_flags( &
     192              :          tr_iage_out=tr_iage, tr_FY_out=tr_FY, &
     193       657372 :          tr_aero_out=tr_aero, tr_iso_out=tr_iso)
     194       657372 :       call icepack_warnings_flush(nu_diag)
     195       657372 :       if (icepack_warnings_aborted()) call icedrv_system_abort(string=subname, &
     196            0 :           file=__FILE__,line= __LINE__)
     197              : 
     198              :       call icepack_query_tracer_indices( &
     199              :          nt_apnd_out=nt_apnd, nt_hpnd_out=nt_hpnd, nt_ipnd_out=nt_ipnd, &
     200              :          nt_alvl_out=nt_alvl, nt_vlvl_out=nt_vlvl, nt_Tsfc_out=nt_Tsfc, &
     201              :          nt_iage_out=nt_iage, nt_FY_out=nt_FY, &
     202              :          nt_qice_out=nt_qice, nt_sice_out=nt_sice, &
     203              :          nt_aero_out=nt_aero, nt_qsno_out=nt_qsno, &
     204              :          nt_rsnw_out=nt_rsnw, nt_smice_out=nt_smice, nt_smliq_out=nt_smliq, &
     205       657372 :          nt_isosno_out=nt_isosno, nt_isoice_out=nt_isoice, nt_fsd_out=nt_fsd)
     206       657372 :       call icepack_warnings_flush(nu_diag)
     207       657372 :       if (icepack_warnings_aborted()) call icedrv_system_abort(string=subname, &
     208            0 :           file=__FILE__,line= __LINE__)
     209              : 
     210              :       !-----------------------------------------------------------------
     211              : 
     212       657372 :       prescribed_ice = .false.
     213       657372 :       aerosno(:,:,:) = c0
     214       657372 :       aeroice(:,:,:) = c0
     215       657372 :       isosno (:,:)   = c0
     216       657372 :       isoice (:,:)   = c0
     217       657372 :       rsnwn  (:,:)   = c0
     218       657372 :       smicen (:,:)   = c0
     219       657372 :       smliqn (:,:)   = c0
     220              : 
     221      3286860 :       do i = 1, nx
     222              : 
     223              :       !-----------------------------------------------------------------
     224              :       ! Save the ice area passed to the coupler (so that history fields
     225              :       !  can be made consistent with coupler fields).
     226              :       ! Save the initial ice area and volume in each category.
     227              :       !-----------------------------------------------------------------
     228              : 
     229      2629488 :          aice_init (i) = aice (i)
     230              : 
     231     16048188 :          do n = 1, ncat
     232     12761328 :             aicen_init(i,n) = aicen(i,n)
     233     12761328 :             vicen_init(i,n) = vicen(i,n)
     234     15390816 :             vsnon_init(i,n) = vsnon(i,n)
     235              :          enddo
     236              : 
     237              :       enddo ! i
     238              : 
     239      3286860 :       do i = 1, nx
     240      2629488 :         if (tr_aero) then
     241              :           ! trcrn(nt_aero) has units kg/m^3
     242       579168 :           do n = 1, ncat
     243      1061808 :             do k = 1, n_aero
     244              :               aerosno (k,:,n) = &
     245              :                   trcrn(i,nt_aero+(k-1)*4  :nt_aero+(k-1)*4+1,n) &
     246      1447920 :                   * vsnon_init(i,n)
     247              :               aeroice (k,:,n) = &
     248              :                   trcrn(i,nt_aero+(k-1)*4+2:nt_aero+(k-1)*4+3,n) &
     249      1930560 :                   * vicen_init(i,n)
     250              :             enddo
     251              :           enddo
     252              :         endif ! tr_aero
     253              : 
     254      2629488 :         if (tr_iso) then
     255              :           ! trcrn(nt_isosno/ice) has units kg/m^3
     256       368928 :           do n = 1, ncat
     257      1291248 :             do k = 1, n_iso
     258       922320 :               isosno(k,n) = trcrn(i,nt_isosno+k-1,n) * vsnon_init(i,n)
     259      1229760 :               isoice(k,n) = trcrn(i,nt_isoice+k-1,n) * vicen_init(i,n)
     260              :             enddo
     261              :           enddo
     262              :         endif ! tr_iso
     263              : 
     264      2629488 :         if (snwgrain) then
     265      1825344 :           do n = 1, ncat
     266      9430944 :             do k = 1, nslyr
     267      7605600 :                rsnwn (k,n) = trcrn(i,nt_rsnw +k-1,n)
     268      7605600 :                smicen(k,n) = trcrn(i,nt_smice+k-1,n)
     269      9126720 :                smliqn(k,n) = trcrn(i,nt_smliq+k-1,n)
     270              :             enddo
     271              :           enddo
     272              :         endif ! snwgrain
     273              : 
     274              :         call icepack_step_therm1(dt=dt, &
     275              :             aicen_init = aicen_init(i,:), &
     276              :             vicen_init = vicen_init(i,:), &
     277              :             vsnon_init = vsnon_init(i,:), &
     278              :             aice = aice(i),   aicen = aicen(i,:), &
     279              :             vice = vice(i),   vicen = vicen(i,:), &
     280              :             vsno = vsno(i),   vsnon = vsnon(i,:), &
     281              :             uvel = uvel(i),   vvel  = vvel(i),    &
     282              :             Tsfc = trcrn(i,nt_Tsfc,:),                 &
     283              :             zqsn = trcrn(i,nt_qsno:nt_qsno+nslyr-1,:), &
     284              :             zqin = trcrn(i,nt_qice:nt_qice+nilyr-1,:), &
     285              :             zSin = trcrn(i,nt_sice:nt_sice+nilyr-1,:), &
     286              :             alvl = trcrn(i,nt_alvl,:),                 &
     287              :             vlvl = trcrn(i,nt_vlvl,:),                 &
     288              :             apnd = trcrn(i,nt_apnd,:),                 &
     289              :             hpnd = trcrn(i,nt_hpnd,:),                 &
     290              :             ipnd = trcrn(i,nt_ipnd,:),                 &
     291              :             iage = trcrn(i,nt_iage,:),                 &
     292              :             FY   = trcrn(i,nt_FY,:),                   &
     293              :             rsnwn  = rsnwn (:,:),            &
     294              :             smicen = smicen(:,:),            &
     295              :             smliqn = smliqn(:,:),            &
     296              :             aerosno = aerosno(:,:,:),        &
     297              :             aeroice = aeroice(:,:,:),        &
     298              :             isosno  = isosno(:,:),           &
     299              :             isoice  = isoice(:,:),           &
     300              :             uatm = uatm(i), vatm = vatm(i),  &
     301              :             wind = wind(i), zlvl = zlvl(i),  &
     302              :             Qa   = Qa(i),   rhoa = rhoa(i),  &
     303              :             Qa_iso = Qa_iso(i,:),            &
     304              :             Tair = Tair(i), Tref = Tref(i),  &
     305              :             Qref = Qref(i), Uref = Uref(i),  &
     306              :             Qref_iso = Qref_iso(i,:),        &
     307              :             Cdn_atm_ratio = Cdn_atm_ratio(i),&
     308              :             Cdn_ocn       = Cdn_ocn(i),      &
     309              :             Cdn_ocn_skin  = Cdn_ocn_skin(i), &
     310              :             Cdn_ocn_floe  = Cdn_ocn_floe(i), &
     311              :             Cdn_ocn_keel  = Cdn_ocn_keel(i), &
     312              :             Cdn_atm       = Cdn_atm(i),      &
     313              :             Cdn_atm_skin  = Cdn_atm_skin(i), &
     314              :             Cdn_atm_floe  = Cdn_atm_floe(i), &
     315              :             Cdn_atm_pond  = Cdn_atm_pond(i), &
     316              :             Cdn_atm_rdg   = Cdn_atm_rdg(i),  &
     317              :             hfreebd  = hfreebd(i),    hkeel     = hkeel(i),       &
     318              :             hdraft   = hdraft(i),     hridge    = hridge(i),      &
     319              :             distrdg  = distrdg(i),    dkeel     = dkeel(i),       &
     320              :             lfloe    = lfloe(i),      dfloe     = dfloe(i),       &
     321              :             strax    = strax(i),      stray     = stray(i),       &
     322              :             strairxT = strairxT(i),   strairyT  = strairyT(i),    &
     323              :             potT     = potT(i),       sst       = sst(i),         &
     324              :             sss      = sss(i),        Tf        = Tf(i),          &
     325              :             strocnxT = strocnxT(i),   strocnyT  = strocnyT(i),    &
     326              :             fbot     = fbot(i),       frzmlt    = frzmlt(i),      &
     327              :             Tbot     = Tbot(i),       Tsnice    = Tsnice(i),      &
     328              :             rsiden   = rsiden(i,:),                               &
     329              :             wlat     = wlat(i),                                   &
     330              :             fsnow    = fsnow(i),      frain     = frain(i),       &
     331              :             fpond    = fpond(i),      fsloss    = fsloss(i),      &
     332              :             fsurf    = fsurf(i),      fsurfn    = fsurfn(i,:),    &
     333              :             fcondtop = fcondtop(i),   fcondtopn = fcondtopn(i,:), &
     334              :             fcondbot = fcondbot(i),   fcondbotn = fcondbotn(i,:), &
     335              :             fswsfcn  = fswsfcn(i,:),  fswintn   = fswintn(i,:),   &
     336              :             fswthrun = fswthrun(i,:),                             &
     337              :             fswthrun_vdr = fswthrun_vdr(i,:),                       &
     338              :             fswthrun_vdf = fswthrun_vdf(i,:),                       &
     339              :             fswthrun_idr = fswthrun_idr(i,:),                       &
     340              :             fswthrun_idf = fswthrun_idf(i,:),                       &
     341              :             fswabs    = fswabs(i),                                &
     342              :             flwout   = flwout(i),     flw       = flw(i),         &
     343              :             fsens    = fsens(i),      fsensn    = fsensn(i,:),    &
     344              :             flat     = flat(i),       flatn     = flatn(i,:),     &
     345              :             fresh    = fresh(i),      fsalt     = fsalt(i),       &
     346              :             fhocn    = fhocn(i),                                  &
     347              :             fswthru   = fswthru(i),                               &
     348              :             fswthru_vdr= fswthru_vdr(i),                          &
     349              :             fswthru_vdf= fswthru_vdf(i),                          &
     350              :             fswthru_idr= fswthru_idr(i),                          &
     351              :             fswthru_idf= fswthru_idf(i),                          &
     352              :             flatn_f  = flatn_f(i,:),  fsensn_f  = fsensn_f(i,:),  &
     353              :             fsurfn_f = fsurfn_f(i,:),                             &
     354              :             fcondtopn_f = fcondtopn_f(i,:),                       &
     355              :             faero_atm   = faero_atm(i,1:n_aero),                  &
     356              :             faero_ocn   = faero_ocn(i,1:n_aero),                  &
     357              :             fiso_atm    = fiso_atm   (i,:),                       &
     358              :             fiso_ocn    = fiso_ocn   (i,:),                       &
     359              :             fiso_evap   = fiso_evap  (i,:),                       &
     360              :             HDO_ocn     = HDO_ocn (i),                            &
     361              :             H2_16O_ocn  = H2_16O_ocn (i),                         &
     362              :             H2_18O_ocn  = H2_18O_ocn (i),                         &
     363              :             Sswabsn  = Sswabsn(i,:,:),Iswabsn   = Iswabsn(i,:,:), &
     364              :             evap = evap(i), evaps = evaps(i), evapi = evapi(i),   &
     365              :             dhsn     = dhsn(i,:),     ffracn    = ffracn(i,:),    &
     366              :             meltt    = meltt(i),      melttn    = melttn(i,:),    &
     367              :             meltb    = meltb(i),      meltbn    = meltbn(i,:),    &
     368              :             melts    = melts(i),      meltsn    = meltsn(i,:),    &
     369              :             congel   = congel(i),     congeln   = congeln(i,:),   &
     370              :             snoice   = snoice(i),     snoicen   = snoicen(i,:),   &
     371              :             dsnow    = dsnow(i),      dsnown    = dsnown(i,:),    &
     372              :             meltsliqn= meltsliqn(i,:), &
     373              :             afsdn         = trcrn       (i,nt_fsd:nt_fsd+nfsd-1,:), &
     374              :             lmask_n  = lmask_n(i),    lmask_s   = lmask_s(i),     &
     375              :             mlt_onset=mlt_onset(i),   frz_onset = frz_onset(i),   &
     376      2629488 :             yday = yday,  prescribed_ice = prescribed_ice)
     377              : 
     378      2629488 :         if (tr_aero) then
     379       579168 :           do n = 1, ncat
     380       482640 :             if (vicen(i,n) > puny) &
     381      1758360 :                 aeroice(:,:,n) = aeroice(:,:,n)/vicen(i,n)
     382       482640 :             if (vsnon(i,n) > puny) &
     383      1707760 :                 aerosno(:,:,n) = aerosno(:,:,n)/vsnon(i,n)
     384      1061808 :             do k = 1, n_aero
     385      1930560 :               do kk = 1, 2
     386       965280 :                 trcrn(i,nt_aero+(k-1)*4+kk-1,n)=aerosno(k,kk,n)
     387      1447920 :                 trcrn(i,nt_aero+(k-1)*4+kk+1,n)=aeroice(k,kk,n)
     388              :               enddo
     389              :             enddo
     390              :           enddo
     391              :         endif ! tr_aero
     392              : 
     393      2629488 :         if (tr_iso) then
     394       368928 :           do n = 1, ncat
     395       983796 :             if (vicen(i,n) > puny) isoice(:,n) = isoice(:,n)/vicen(i,n)
     396       977226 :             if (vsnon(i,n) > puny) isosno(:,n) = isosno(:,n)/vsnon(i,n)
     397      1291248 :             do k = 1, n_iso
     398       922320 :                trcrn(i,nt_isosno+k-1,n) = isosno(k,n)
     399      1229760 :                trcrn(i,nt_isoice+k-1,n) = isoice(k,n)
     400              :             enddo
     401              :           enddo
     402              :         endif ! tr_iso
     403              : 
     404      3286860 :         if (snwgrain) then
     405      1825344 :           do n = 1, ncat
     406      9430944 :             do k = 1, nslyr
     407      7605600 :                trcrn(i,nt_rsnw +k-1,n) = rsnwn (k,n)
     408      7605600 :                trcrn(i,nt_smice+k-1,n) = smicen(k,n)
     409      9126720 :                trcrn(i,nt_smliq+k-1,n) = smliqn(k,n)
     410              :             enddo
     411              :           enddo
     412              :         endif ! snwgrain
     413              : 
     414              :       enddo ! i
     415       657372 :       call icepack_warnings_flush(nu_diag)
     416       657372 :       if (icepack_warnings_aborted()) call icedrv_system_abort(string=subname, &
     417            0 :           file=__FILE__, line=__LINE__)
     418              : 
     419       657372 :     end subroutine step_therm1
     420              : 
     421              : !=======================================================================
     422              : ! Driver for thermodynamic changes not needed for coupling:
     423              : ! transport in thickness space, lateral growth and melting.
     424              : !
     425              : ! authors: William H. Lipscomb, LANL
     426              : !          Elizabeth C. Hunke, LANL
     427              : 
     428      1314744 :       subroutine step_therm2 (dt)
     429              : 
     430              :       use icedrv_arrays_column, only: hin_max, ocean_bio, &
     431              :                                       wave_sig_ht, wave_spectrum, &
     432              :                                       wavefreq, dwavefreq,        &
     433              :                                d_afsd_latg, d_afsd_newi, d_afsd_latm, d_afsd_weld
     434              :       use icedrv_arrays_column, only: first_ice
     435              :       use icedrv_calendar, only: yday
     436              :       use icedrv_domain_size, only: ncat, nilyr, nslyr, n_aero, nblyr, &
     437              :                                     nx
     438              :       use icedrv_flux, only: fresh, frain, fpond, frzmlt, frazil, frz_onset
     439              :       use icedrv_flux, only: fsalt, Tf, sss, salinz, fhocn, rsiden, wlat
     440              :       use icedrv_flux, only: meltl, frazil_diag, flux_bio, faero_ocn, fiso_ocn
     441              :       use icedrv_flux, only: HDO_ocn, H2_16O_ocn, H2_18O_ocn
     442              :       use icedrv_init, only: tmask
     443              :       use icedrv_state, only: aice, aicen, aice0, trcr_depend
     444              :       use icedrv_state, only: aicen_init, vicen_init, trcrn, vicen, vsnon
     445              :       use icedrv_state, only: trcr_base, n_trcr_strata, nt_strata
     446              : 
     447              :       ! column package_includes
     448              :       use icepack_intfc, only: icepack_step_therm2
     449              : 
     450              :       real (kind=dbl_kind), intent(in) :: &
     451              :          dt      ! time step
     452              : 
     453              :       ! local variables
     454              : 
     455              :       integer (kind=int_kind) :: &
     456              :          i       ! horizontal index
     457              : 
     458              :       integer (kind=int_kind) :: &
     459              :          ntrcr, nbtrcr
     460              : 
     461              :       logical (kind=log_kind) :: &
     462              :          tr_fsd  ! floe size distribution tracers
     463              : 
     464              :       character(len=*), parameter :: subname='(step_therm2)'
     465              : 
     466              :       !-----------------------------------------------------------------
     467              :       ! query icepack values
     468              :       !-----------------------------------------------------------------
     469              : 
     470       657372 :       call icepack_query_tracer_sizes(ntrcr_out=ntrcr, nbtrcr_out=nbtrcr)
     471       657372 :       call icepack_query_tracer_flags(tr_fsd_out=tr_fsd)
     472       657372 :       call icepack_warnings_flush(nu_diag)
     473       657372 :       if (icepack_warnings_aborted()) call icedrv_system_abort(string=subname, &
     474            0 :           file=__FILE__,line= __LINE__)
     475              : 
     476              :       !-----------------------------------------------------------------
     477              : 
     478      3286860 :       do i = 1, nx
     479              : 
     480      3286860 :          if (tmask(i)) then
     481              :             ! wave_sig_ht - compute here to pass to add new ice
     482      1972116 :             if (tr_fsd) &
     483      2565576 :             wave_sig_ht(i) = c4*SQRT(SUM(wave_spectrum(i,:)*dwavefreq(:)))
     484              : 
     485              :             call icepack_step_therm2(dt=dt,                           &
     486              :                          hin_max=hin_max(:),                          &
     487              :                          aicen=aicen(i,:),                            &
     488              :                          vicen=vicen(i,:),                            &
     489              :                          vsnon=vsnon(i,:),                            &
     490              :                          aicen_init=aicen_init(i,:),                  &
     491              :                          vicen_init=vicen_init(i,:),                  &
     492              :                          trcrn=trcrn(i,1:ntrcr,:),                    &
     493              :                          aice0=aice0(i),                              &
     494              :                          aice =aice(i),                               &
     495              :                          trcr_depend=trcr_depend(1:ntrcr),            &
     496              :                          trcr_base=trcr_base(1:ntrcr,:),              &
     497              :                          n_trcr_strata=n_trcr_strata(1:ntrcr),        &
     498              :                          nt_strata=nt_strata(1:ntrcr,:),              &
     499              :                          Tf=Tf(i), sss=sss(i),                        &
     500              :                          salinz=salinz(i,:),                          &
     501              :                          wlat=wlat(i),                                &
     502              :                          rsiden=rsiden(i,:), meltl=meltl(i),          &
     503              :                          frzmlt=frzmlt(i), frazil=frazil(i),          &
     504              :                          frain=frain(i),   fpond=fpond(i),            &
     505              :                          fresh=fresh(i),   fsalt=fsalt(i),            &
     506              :                          fhocn=fhocn(i),                              &
     507              :                          faero_ocn=faero_ocn(i,:),                    &
     508              :                          first_ice=first_ice(i,:),                    &
     509              :                          flux_bio=flux_bio(i,1:nbtrcr),               &
     510              :                          ocean_bio=ocean_bio(i,1:nbtrcr),             &
     511              :                          frazil_diag=frazil_diag(i),                  &
     512              :                          frz_onset=frz_onset(i),                      &
     513              :                          yday=yday,                                   &
     514              :                          fiso_ocn=fiso_ocn(i,:),                      &
     515              :                          HDO_ocn=HDO_ocn(i),                          &
     516              :                          H2_16O_ocn=H2_16O_ocn(i),                    &
     517              :                          H2_18O_ocn=H2_18O_ocn(i),                    &
     518              :                          wave_sig_ht=wave_sig_ht(i),                  &
     519              :                          wave_spectrum=wave_spectrum(i,:),            &
     520              :                          wavefreq=wavefreq(:),                        &
     521              :                          dwavefreq=dwavefreq(:),                      &
     522              :                          d_afsd_latg=d_afsd_latg(i,:),                &
     523              :                          d_afsd_newi=d_afsd_newi(i,:),                &
     524              :                          d_afsd_latm=d_afsd_latm(i,:),                &
     525      1972116 :                          d_afsd_weld=d_afsd_weld(i,:))
     526              : 
     527              :          endif ! tmask
     528              : 
     529              :       enddo                     ! i
     530       657372 :       call icepack_warnings_flush(nu_diag)
     531       657372 :       if (icepack_warnings_aborted()) call icedrv_system_abort(string=subname, &
     532            0 :           file=__FILE__, line=__LINE__)
     533              : 
     534       657372 :       end subroutine step_therm2
     535              : 
     536              : !=======================================================================
     537              : !
     538              : ! finalize thermo updates
     539              : !
     540              : ! authors: Elizabeth Hunke, LANL
     541              : 
     542      1432452 :       subroutine update_state (dt, daidt, dvidt, dagedt, offset)
     543              : 
     544              :       use icedrv_domain_size, only: ncat, nx
     545              :       use icedrv_init, only: tmask
     546              :       use icedrv_flux, only: Tf
     547              :       use icedrv_state, only: aicen, trcrn, vicen, vsnon
     548              :       use icedrv_state, only: aice,  trcr,  vice,  vsno, aice0, trcr_depend
     549              :       use icedrv_state, only: trcr_base, nt_strata, n_trcr_strata
     550              : 
     551              :       ! column package includes
     552              :       use icepack_intfc, only: icepack_aggregate
     553              : 
     554              :       real (kind=dbl_kind), intent(in) :: &
     555              :          dt       ! time step
     556              : 
     557              :       real (kind=dbl_kind), dimension(:), intent(inout), optional :: &
     558              :          daidt, & ! change in ice area per time step
     559              :          dvidt, & ! change in ice volume per time step
     560              :          dagedt   ! change in ice age per time step
     561              : 
     562              :       real (kind=dbl_kind), intent(in), optional :: &
     563              :          offset    ! d(age)/dt time offset = dt for thermo, 0 for dyn
     564              : 
     565              :       integer (kind=int_kind) :: &
     566              :          i,     & ! horizontal indices
     567              :          ntrcr, & !
     568              :          nt_iage  !
     569              : 
     570              :       logical (kind=log_kind) :: &
     571              :          tr_iage  ! ice age tracer
     572              : 
     573              :       character(len=*), parameter :: subname='(update_state)'
     574              : 
     575              :       !-----------------------------------------------------------------
     576              :       ! query icepack values
     577              :       !-----------------------------------------------------------------
     578              : 
     579      1432452 :       call icepack_query_tracer_sizes(ntrcr_out=ntrcr)
     580      1432452 :       call icepack_warnings_flush(nu_diag)
     581      1432452 :       if (icepack_warnings_aborted()) call icedrv_system_abort(string=subname, &
     582            0 :           file=__FILE__,line= __LINE__)
     583              : 
     584      1432452 :       call icepack_query_tracer_indices(nt_iage_out=nt_iage)
     585      1432452 :       call icepack_warnings_flush(nu_diag)
     586      1432452 :       if (icepack_warnings_aborted()) call icedrv_system_abort(string=subname, &
     587            0 :           file=__FILE__,line= __LINE__)
     588              : 
     589      1432452 :       call icepack_query_tracer_flags(tr_iage_out=tr_iage)
     590      1432452 :       call icepack_warnings_flush(nu_diag)
     591      1432452 :       if (icepack_warnings_aborted()) call icedrv_system_abort(string=subname, &
     592            0 :           file=__FILE__,line= __LINE__)
     593              : 
     594              :       !$OMP PARALLEL DO PRIVATE(i)
     595      7162260 :       do i = 1, nx
     596              : 
     597              :       !-----------------------------------------------------------------
     598              :       ! Aggregate the updated state variables (includes ghost cells).
     599              :       !-----------------------------------------------------------------
     600              : 
     601      5729808 :          if (tmask(i)) &
     602              :          call icepack_aggregate(trcrn=trcrn(i,1:ntrcr,:),     &
     603              :                                 aicen=aicen(i,:),             &
     604              :                                 vicen=vicen(i,:),             &
     605              :                                 vsnon=vsnon(i,:),             &
     606              :                                 trcr=trcr (i,1:ntrcr),        &
     607              :                                 aice=aice (i),                &
     608              :                                 vice=vice (i),                &
     609              :                                 vsno=vsno (i),                &
     610              :                                 aice0=aice0(i),               &
     611              :                                 trcr_depend=trcr_depend(1:ntrcr),     &
     612              :                                 trcr_base=trcr_base    (1:ntrcr,:),   &
     613              :                                 n_trcr_strata=n_trcr_strata(1:ntrcr), &
     614              :                                 nt_strata=nt_strata    (1:ntrcr,:), &
     615      4297356 :                                 Tf = Tf(i))
     616              : 
     617      7162260 :          if (present(offset)) then
     618              : 
     619              :       !-----------------------------------------------------------------
     620              :       ! Compute thermodynamic area and volume tendencies.
     621              :       !-----------------------------------------------------------------
     622              : 
     623      5390544 :          daidt(i) = (aice(i) - daidt(i)) / dt
     624      5390544 :          dvidt(i) = (vice(i) - dvidt(i)) / dt
     625      5390544 :          if (tr_iage) then
     626       122976 :             if (offset > c0) then                 ! thermo
     627        61488 :                if (trcr(i,nt_iage) > c0) &
     628              :                dagedt(i) = (trcr(i,nt_iage) &
     629        46111 :                                 - dagedt(i) - offset) / dt
     630              :             else                                  ! dynamics
     631              :                dagedt(i) = (trcr(i,nt_iage) &
     632        61488 :                                 - dagedt(i)) / dt
     633              :             endif
     634              :          endif ! tr_iage
     635              :          endif ! present(offset)
     636              : 
     637              :       enddo ! i
     638              :       !$OMP END PARALLEL DO
     639      1432452 :       call icepack_warnings_flush(nu_diag)
     640      1432452 :       if (icepack_warnings_aborted()) call icedrv_system_abort(string=subname, &
     641            0 :           file=__FILE__, line=__LINE__)
     642              : 
     643      1432452 :       end subroutine update_state
     644              : 
     645              : !=======================================================================
     646              : !
     647              : ! Run one time step of wave-fracturing the floe size distribution
     648              : !
     649              : ! authors: Lettie Roach, NIWA
     650              : !          Elizabeth C. Hunke, LANL
     651              : 
     652        24132 :       subroutine step_dyn_wave (dt)
     653              : 
     654              :       use icedrv_arrays_column, only: wave_spectrum, wave_sig_ht, &
     655              :           d_afsd_wave, wavefreq, dwavefreq
     656              :       use icedrv_domain_size, only: ncat, nfreq, nx
     657              :       use icedrv_state, only: trcrn, aicen, aice, vice
     658              :       use icepack_intfc, only: icepack_step_wavefracture
     659              : 
     660              :       real (kind=dbl_kind), intent(in) :: &
     661              :          dt      ! time step
     662              : 
     663              :       ! local variables
     664              : 
     665              :       integer (kind=int_kind) :: &
     666              :          i, j,            & ! horizontal indices
     667              :          ntrcr,           & !
     668              :          nbtrcr             !
     669              : 
     670              :       character (len=char_len) :: wave_spec_type
     671              : 
     672              :       character(len=*), parameter :: subname = '(step_dyn_wave)'
     673              : 
     674        24132 :       call icepack_query_parameters(wave_spec_type_out=wave_spec_type)
     675        24132 :       call icepack_warnings_flush(nu_diag)
     676        24132 :       if (icepack_warnings_aborted()) call icedrv_system_abort(string=subname, &
     677            0 :              file=__FILE__,line= __LINE__)
     678              : 
     679       120660 :       do i = 1, nx
     680      1254864 :            d_afsd_wave(i,:) = c0
     681              :            call icepack_step_wavefracture (wave_spec_type=wave_spec_type, &
     682              :                         dt=dt, nfreq=nfreq,                    &
     683              :                         aice          = aice         (i),      &
     684              :                         vice          = vice         (i),      &
     685              :                         aicen         = aicen        (i,:),    &
     686              :                         wave_spectrum = wave_spectrum(i,:),    &
     687              :                         wavefreq      = wavefreq     (:),      &
     688              :                         dwavefreq     = dwavefreq    (:),      &
     689              :                         trcrn         = trcrn        (i,:,:),  &
     690       120660 :                         d_afsd_wave   = d_afsd_wave  (i,:))
     691              :       end do ! i
     692              : 
     693        24132 :       call icepack_warnings_flush(nu_diag)
     694        24132 :       if (icepack_warnings_aborted()) call icedrv_system_abort(string=subname, &
     695            0 :              file=__FILE__,line= __LINE__)
     696              : 
     697        24132 :       end subroutine step_dyn_wave
     698              : 
     699              : 
     700              : !=======================================================================
     701              : !
     702              : ! Run one time step of horizontal advection (if there is closing)
     703              : !
     704              : ! authors: David Clemens-Sewall, NCAR
     705              : 
     706       690264 :       subroutine step_lateral_flux_scm (dt)
     707              : 
     708              :          use icedrv_domain_size, only: ncat, nx
     709              :          use icedrv_flux, only: closing, opening
     710              :          use icedrv_init, only: tmask
     711              :          use icedrv_state, only: vsnon, aicen, vicen, aice0
     712              : 
     713              :          real (kind=dbl_kind), intent(in) :: &
     714              :             dt      ! time step
     715              : 
     716              :          ! local variables
     717              : 
     718              :          integer (kind=int_kind) :: &
     719              :             i,            & ! horizontal indices
     720              :             n               ! ice thickness category index         !
     721              : 
     722              :          real (kind=dbl_kind) :: &
     723              :             expansion_ratio  ! how much the ice area will change
     724              : 
     725              :          character(len=*), parameter :: subname='(step_lateral_flux_scm)'
     726              : 
     727              :          !-----------------------------------------------------------------
     728              :          ! query icepack values
     729              :          !-----------------------------------------------------------------
     730       690264 :             call icepack_warnings_flush(nu_diag)
     731       690264 :             if (icepack_warnings_aborted()) call icedrv_system_abort(string=subname, &
     732            0 :                 file=__FILE__,line= __LINE__)
     733              : 
     734              :          !-----------------------------------------------------------------
     735              :          ! Ice advection
     736              :          !-----------------------------------------------------------------
     737              :             ! Currently we only do ridging for the SHEBA ocean data type (in step_dyn_ridge)
     738       690264 :             if (trim(ocn_data_type) == "SHEBA") then
     739              :                ! Currently only uniform_ice (and none) advection is implemented
     740       629580 :                if (trim(lateral_flux_type) == "uniform_ice") then
     741              : 
     742      2939640 :                   do i = 1, nx
     743              : 
     744      2939640 :                   if (tmask(i)) then
     745              :                      ! We assume that this single column grid cell is surrounded by
     746              :                      ! identical ice. If so, ice closing implies the flux of
     747              :                      ! this surrounding ice into the single column grid cell.
     748              :                      ! Equivalently, one can think of this step as expanding the
     749              :                      ! domain of the grid cell before the ridging step will
     750              :                      ! contract the domain.
     751      1763784 :                      expansion_ratio = c1 + (closing(i) - opening(i)) * dt
     752      1763784 :                      aice0(i) = aice0(i) * expansion_ratio
     753     10293120 :                      do n = 1, ncat
     754              :                         ! Scale up state variables
     755      8529336 :                         aicen(i,n) = aicen(i,n) * expansion_ratio
     756      8529336 :                         vicen(i,n) = vicen(i,n) * expansion_ratio
     757     10293120 :                         vsnon(i,n) = vsnon(i,n) * expansion_ratio
     758              :                      enddo ! n
     759              :                   endif ! tmask
     760              : 
     761              :                   enddo ! i
     762        41652 :                elseif (trim(lateral_flux_type) == "open_water") then
     763       208260 :                   do i = 1, nx
     764              : 
     765       208260 :                      if (tmask(i)) then
     766              :                         ! We assume that this single column grid cell is surrounded by
     767              :                         ! open water. If so, net ice closing implies the flux of
     768              :                         ! this surrounding open water into the single column grid cell.
     769              :                         ! To accomplish this without modifying the icepack
     770              :                         ! columnphysics code, we do nothing at this step. Within the
     771              :                         ! ridge_ice subroutine, icepack will ridge ice by the amount
     772              :                         ! given in the forcing. This will drop the cell area (asum)
     773              :                         ! below 1 and then in the second ridging iteration loop
     774              :                         ! 'opning' will be set such that it adds enough open water
     775              :                         ! to return the cell area to 1.
     776              :                         ! If the forcing is net opening, we still need to flux
     777              :                         ! ice out of the grid cell as above.
     778       124956 :                         expansion_ratio = c1 + (closing(i) - opening(i)) * dt
     779       124956 :                         if (expansion_ratio < 1) then ! net opening
     780        57477 :                            aice0(i) = aice0(i) * expansion_ratio
     781       344862 :                            do n = 1, ncat
     782              :                               ! Remove ice from cell
     783       287385 :                               aicen(i,n) = aicen(i,n) * expansion_ratio
     784       287385 :                               vicen(i,n) = vicen(i,n) * expansion_ratio
     785       344862 :                               vsnon(i,n) = vsnon(i,n) * expansion_ratio
     786              :                            enddo ! n
     787              :                         endif ! expansion ratio < 1
     788              :                      endif ! tmask
     789              : 
     790              :                      enddo ! i
     791              :                else
     792              :                   call icedrv_system_abort(string=subname//' ERROR: unknown lateral_flux_type: '&
     793            0 :                   //trim(lateral_flux_type),file=__FILE__,line=__LINE__)
     794              :                endif
     795              :             endif
     796              : 
     797       690264 :             call icepack_warnings_flush(nu_diag)
     798       690264 :             if (icepack_warnings_aborted()) call icedrv_system_abort(string=subname, &
     799            0 :                 file=__FILE__, line=__LINE__)
     800              : 
     801       690264 :          end subroutine step_lateral_flux_scm
     802              : 
     803              : !=======================================================================
     804              : !
     805              : ! Run one time step of ridging.
     806              : !
     807              : ! authors: William H. Lipscomb, LANL
     808              : !          Elizabeth C. Hunke, LANL
     809              : 
     810       690264 :       subroutine step_dyn_ridge (dt, ndtd)
     811              : 
     812              :       use icedrv_arrays_column, only: hin_max, first_ice
     813              :       use icedrv_domain_size, only: ncat, nilyr, nslyr, n_aero, nblyr, nx
     814              :       use icedrv_flux, only: rdg_conv, rdg_shear, dardg1dt, dardg2dt, Tf
     815              :       use icedrv_flux, only: dvirdgdt, opening, closing, fpond, fresh, fhocn
     816              :       use icedrv_flux, only: aparticn, krdgn, aredistn, vredistn, dardg1ndt, dardg2ndt
     817              :       use icedrv_flux, only: dvirdgndt, araftn, vraftn, fsalt, flux_bio, faero_ocn, fiso_ocn
     818              :       use icedrv_init, only: tmask
     819              :       use icedrv_state, only: trcrn, vsnon, aicen, vicen
     820              :       use icedrv_state, only: aice, aice0, trcr_depend, n_trcr_strata
     821              :       use icedrv_state, only: trcr_base, nt_strata
     822              : 
     823              :       ! column package includes
     824              :       use icepack_intfc, only: icepack_step_ridge
     825              : 
     826              :       real (kind=dbl_kind), intent(in) :: &
     827              :          dt      ! time step
     828              : 
     829              :       integer (kind=int_kind), intent(in) :: &
     830              :          ndtd    ! number of dynamics subcycles
     831              : 
     832              :       ! local variables
     833              : 
     834              :       integer (kind=int_kind) :: &
     835              :          i,            & ! horizontal indices
     836              :          ntrcr,        & !
     837              :          nbtrcr
     838              : 
     839              :       character(len=*), parameter :: subname='(step_dyn_ridge)'
     840              : 
     841              :       !-----------------------------------------------------------------
     842              :       ! query icepack values
     843              :       !-----------------------------------------------------------------
     844              : 
     845       690264 :          call icepack_query_tracer_sizes(ntrcr_out=ntrcr, nbtrcr_out=nbtrcr)
     846       690264 :          call icepack_warnings_flush(nu_diag)
     847       690264 :          if (icepack_warnings_aborted()) call icedrv_system_abort(string=subname, &
     848            0 :              file=__FILE__,line= __LINE__)
     849              : 
     850              :       !-----------------------------------------------------------------
     851              :       ! Ridging
     852              :       !-----------------------------------------------------------------
     853              : 
     854       690264 :          if (trim(ocn_data_type) == "SHEBA") then
     855              : 
     856      3147900 :          do i = 1, nx
     857              : 
     858              : !echmod: this changes the answers, continue using tmask for now
     859              : !      call aggregate_area (ncat, aicen(:), atmp, atmp0)
     860              : !      if (atmp > c0) then
     861              : 
     862      3147900 :          if (tmask(i)) then
     863              : 
     864              :             call icepack_step_ridge(dt=dt,         ndtd=ndtd,                &
     865              :                          hin_max=hin_max(:),                                 &
     866              :                          rdg_conv=rdg_conv(i),     rdg_shear=rdg_shear(i),   &
     867              :                          aicen=aicen(i,:),                                   &
     868              :                          trcrn=trcrn(i,1:ntrcr,:),                           &
     869              :                          vicen=vicen(i,:),         vsnon=vsnon(i,:),         &
     870              :                          aice0=aice0(i),                                     &
     871              :                          trcr_depend=trcr_depend(1:ntrcr),                   &
     872              :                          trcr_base=trcr_base(1:ntrcr,:),                     &
     873              :                          n_trcr_strata=n_trcr_strata(1:ntrcr),               &
     874              :                          nt_strata=nt_strata(1:ntrcr,:),                     &
     875              :                          dardg1dt=dardg1dt(i),     dardg2dt=dardg2dt(i),     &
     876              :                          dvirdgdt=dvirdgdt(i),     opening=opening(i),       &
     877              :                          fpond=fpond(i),                                     &
     878              :                          fresh=fresh(i),           fhocn=fhocn(i),           &
     879              :                          faero_ocn=faero_ocn(i,:), fiso_ocn=fiso_ocn(i,:),   &
     880              :                          aparticn=aparticn(i,:),   krdgn=krdgn(i,:),         &
     881              :                          aredistn=aredistn(i,:),   vredistn=vredistn(i,:),   &
     882              :                          dardg1ndt=dardg1ndt(i,:), dardg2ndt=dardg2ndt(i,:), &
     883              :                          dvirdgndt=dvirdgndt(i,:),                           &
     884              :                          araftn=araftn(i,:),       vraftn=vraftn(i,:),       &
     885              :                          aice=aice(i),             fsalt=fsalt(i),           &
     886              :                          first_ice=first_ice(i,:),                           &
     887              :                          flux_bio=flux_bio(i,1:nbtrcr),                      &
     888      1888740 :                          closing=closing(i),       Tf=Tf(i) )
     889              : 
     890              :          endif ! tmask
     891              : 
     892              :          enddo ! i
     893              : 
     894              :          else ! closing not read in
     895              : 
     896       303420 :          do i = 1, nx
     897              : 
     898              : !echmod: this changes the answers, continue using tmask for now
     899              : !      call aggregate_area (ncat, aicen(:), atmp, atmp0)
     900              : !      if (atmp > c0) then
     901              : 
     902       303420 :          if (tmask(i)) then
     903              : 
     904              :             call icepack_step_ridge (dt=dt,        ndtd=ndtd,                &
     905              :                          hin_max=hin_max(:),                                 &
     906              :                          rdg_conv=rdg_conv(i),     rdg_shear=rdg_shear(i),   &
     907              :                          aicen=aicen(i,:),                                   &
     908              :                          trcrn=trcrn(i,1:ntrcr,:),                           &
     909              :                          vicen=vicen(i,:),         vsnon=vsnon(i,:),         &
     910              :                          aice0=aice0(i),                                     &
     911              :                          trcr_depend=trcr_depend(1:ntrcr),                   &
     912              :                          trcr_base=trcr_base(1:ntrcr,:),                     &
     913              :                          n_trcr_strata=n_trcr_strata(1:ntrcr),               &
     914              :                          nt_strata=nt_strata(1:ntrcr,:),                     &
     915              :                          dardg1dt=dardg1dt(i),     dardg2dt=dardg2dt(i),     &
     916              :                          dvirdgdt=dvirdgdt(i),     opening=opening(i),       &
     917              :                          fpond=fpond(i),                                     &
     918              :                          fresh=fresh(i),           fhocn=fhocn(i),           &
     919              :                          faero_ocn=faero_ocn(i,:), fiso_ocn=fiso_ocn(i,:),   &
     920              :                          aparticn=aparticn(i,:),   krdgn=krdgn(i,:),         &
     921              :                          aredistn=aredistn(i,:),   vredistn=vredistn(i,:),   &
     922              :                          dardg1ndt=dardg1ndt(i,:), dardg2ndt=dardg2ndt(i,:), &
     923              :                          dvirdgndt=dvirdgndt(i,:),                           &
     924              :                          araftn=araftn(i,:),       vraftn=vraftn(i,:),       &
     925              :                          aice=aice(i),             fsalt=fsalt(i),           &
     926              :                          first_ice=first_ice(i,:),                           &
     927       182052 :                          flux_bio=flux_bio(i,1:nbtrcr), Tf = Tf(i))
     928              : 
     929              :          endif ! tmask
     930              : 
     931              :          enddo ! i
     932              : 
     933              :          endif
     934       690264 :          call icepack_warnings_flush(nu_diag)
     935       690264 :          if (icepack_warnings_aborted()) call icedrv_system_abort(string=subname, &
     936            0 :              file=__FILE__, line=__LINE__)
     937              : 
     938       690264 :       end subroutine step_dyn_ridge
     939              : 
     940              : !=======================================================================
     941              : !
     942              : ! Updates snow tracers
     943              : !
     944              : ! authors: Elizabeth C. Hunke, LANL
     945              : !          Nicole Jeffery, LANL
     946              : 
     947        84816 :       subroutine step_snow (dt)
     948              : 
     949              :       use icedrv_domain_size, only: ncat, nslyr, nilyr, nx
     950              :       use icedrv_flux, only: wind, fresh, fhocn, fsloss, fsnow
     951              :       use icedrv_state, only: trcrn, vsno, vsnon, vicen, aicen, aice
     952              :       use icepack_intfc, only: icepack_step_snow
     953              : 
     954              :       real (kind=dbl_kind), intent(in) :: &
     955              :          dt                 ! time step
     956              : 
     957              :       ! local variables
     958              : 
     959              :       integer (kind=int_kind) :: &
     960              :          nt_smice, nt_smliq, nt_rsnw, &
     961              :          nt_Tsfc, nt_qice, nt_sice, nt_qsno, &
     962              :          nt_alvl, nt_vlvl, nt_rhos
     963              : 
     964              :       integer (kind=int_kind) :: &
     965              :          i,               & ! horizontal index
     966              :          n                  ! category index
     967              : 
     968              :       character(len=*), parameter :: subname='(step_snow)'
     969              : 
     970              :       !-----------------------------------------------------------------
     971              :       ! query icepack values
     972              :       !-----------------------------------------------------------------
     973              : 
     974              :       call icepack_query_tracer_indices( &
     975              :          nt_smice_out=nt_smice, nt_smliq_out=nt_smliq, &
     976              :          nt_rsnw_out=nt_rsnw, nt_Tsfc_out=nt_Tsfc, &
     977              :          nt_qice_out=nt_qice, nt_sice_out=nt_sice, nt_qsno_out=nt_qsno, &
     978        84816 :          nt_alvl_out=nt_alvl, nt_vlvl_out=nt_vlvl, nt_rhos_out=nt_rhos)
     979        84816 :       call icepack_warnings_flush(nu_diag)
     980        84816 :          if (icepack_warnings_aborted()) call icedrv_system_abort(string=subname, &
     981            0 :              file=__FILE__,line= __LINE__)
     982              : 
     983              :       !-----------------------------------------------------------------
     984              :       ! Snow redistribution and metamorphosis
     985              :       !-----------------------------------------------------------------
     986              : 
     987       424080 :       do i = 1, nx
     988              : 
     989              :          call icepack_step_snow (dt,                         &
     990              :                      wind (i),           aice  (i),          &
     991              :                      aicen(i,:),         vicen (i,:),        &
     992              :                      vsnon(i,:),         trcrn(i,nt_Tsfc,:), &
     993              :                      trcrn(i,nt_qice,:),    & ! top layer only
     994              :                      trcrn(i,nt_sice,:),    & ! top layer only
     995              :                      trcrn(i,nt_qsno:nt_qsno+nslyr-1,:),     &
     996              :                      trcrn(i,nt_alvl,:), trcrn(i,nt_vlvl,:), &
     997              :                      trcrn(i,nt_smice:nt_smice+nslyr-1,:),   &
     998              :                      trcrn(i,nt_smliq:nt_smliq+nslyr-1,:),   &
     999              :                      trcrn(i,nt_rsnw:nt_rsnw+nslyr-1,:),     &
    1000              :                      trcrn(i,nt_rhos:nt_rhos+nslyr-1,:),     &
    1001              :                      fresh    (i),       fhocn (i),          &
    1002       424080 :                      fsloss   (i),       fsnow (i))
    1003              :       enddo
    1004              : 
    1005        84816 :       end subroutine step_snow
    1006              : 
    1007              : !=======================================================================
    1008              : !
    1009              : ! Computes radiation fields
    1010              : !
    1011              : ! authors: William H. Lipscomb, LANL
    1012              : !          David Bailey, NCAR
    1013              : !          Elizabeth C. Hunke, LANL
    1014              : 
    1015       657372 :       subroutine step_radiation (dt)
    1016              : 
    1017              :       use icedrv_arrays_column, only: ffracn, dhsn
    1018              :       use icedrv_arrays_column, only: fswsfcn, fswintn, fswpenln, Sswabsn, Iswabsn
    1019              :       use icedrv_arrays_column, only: fswthrun, fswthrun_vdr, fswthrun_vdf, fswthrun_idr, fswthrun_idf
    1020              :       use icedrv_arrays_column, only: albicen, albsnon, albpndn
    1021              :       use icedrv_arrays_column, only: alvdrn, alidrn, alvdfn, alidfn, apeffn, trcrn_sw, snowfracn
    1022              :       use icedrv_calendar, only: yday, sec
    1023              :       use icedrv_domain_size, only: ncat, n_aero, nilyr, nslyr, n_zaero, n_algae, nblyr, nx
    1024              :       use icedrv_flux, only: swvdr, swvdf, swidr, swidf, coszen, fsnow
    1025              :       use icedrv_init, only: TLAT, TLON, tmask
    1026              :       use icedrv_state, only: aicen, vicen, vsnon, trcrn
    1027              : 
    1028              :       ! column package includes
    1029              :       use icepack_intfc, only: icepack_step_radiation
    1030              : 
    1031              :       real (kind=dbl_kind), intent(in) :: &
    1032              :          dt                 ! time step
    1033              : 
    1034              :       ! local variables
    1035              : 
    1036              :       integer (kind=int_kind) :: &
    1037              :          i, n,   k ! horizontal indices
    1038              : 
    1039              :       integer (kind=int_kind) :: &
    1040              :          max_aero, max_algae, nt_Tsfc, nt_alvl, &
    1041              :          nt_apnd, nt_hpnd, nt_ipnd, nt_aero, nlt_chl_sw, &
    1042              :          ntrcr, nbtrcr_sw, nt_fbri, nt_rsnw
    1043              : 
    1044              :       integer (kind=int_kind), dimension(:), allocatable :: &
    1045       657372 :          nlt_zaero_sw, nt_zaero, nt_bgc_N
    1046              : 
    1047              :       logical (kind=log_kind) :: &
    1048              :          tr_bgc_N, tr_zaero, tr_brine, dEdd_algae, snwgrain
    1049              : 
    1050              :       real (kind=dbl_kind), dimension(ncat) :: &
    1051              :          fbri               ! brine height to ice thickness
    1052              : 
    1053              :       real(kind= dbl_kind), dimension(:,:), allocatable :: &
    1054       657372 :          rsnow          , & ! snow grain radius
    1055       657372 :          ztrcr_sw           ! BGC tracers affecting radiation
    1056              : 
    1057              :       logical (kind=log_kind) :: &
    1058              :          l_print_point      ! flag for printing debugging information
    1059              : 
    1060              :       character(len=*), parameter :: subname='(step_radiation)'
    1061              : 
    1062              :       !-----------------------------------------------------------------
    1063              :       ! query icepack values
    1064              :       !-----------------------------------------------------------------
    1065              : 
    1066              :       call icepack_query_tracer_sizes( &
    1067       657372 :            max_aero_out=max_aero, max_algae_out=max_algae)
    1068       657372 :       call icepack_warnings_flush(nu_diag)
    1069       657372 :       if (icepack_warnings_aborted()) call icedrv_system_abort(string=subname, &
    1070            0 :           file=__FILE__,line= __LINE__)
    1071       657372 :       allocate(nlt_zaero_sw(max_aero))
    1072       657372 :       allocate(nt_zaero(max_aero))
    1073       657372 :       allocate(nt_bgc_N(max_algae))
    1074              : 
    1075       657372 :       call icepack_query_tracer_sizes(ntrcr_out=ntrcr, nbtrcr_sw_out=nbtrcr_sw)
    1076       657372 :       call icepack_warnings_flush(nu_diag)
    1077       657372 :       if (icepack_warnings_aborted()) call icedrv_system_abort(string=subname, &
    1078            0 :           file=__FILE__,line= __LINE__)
    1079              : 
    1080              :       call icepack_query_tracer_flags( &
    1081       657372 :            tr_brine_out=tr_brine, tr_bgc_N_out=tr_bgc_N, tr_zaero_out=tr_zaero)
    1082       657372 :       call icepack_warnings_flush(nu_diag)
    1083       657372 :       if (icepack_warnings_aborted()) call icedrv_system_abort(string=subname, &
    1084            0 :           file=__FILE__,line= __LINE__)
    1085              : 
    1086              :       call icepack_query_tracer_indices( &
    1087              :            nt_Tsfc_out=nt_Tsfc, nt_alvl_out=nt_alvl, nt_apnd_out=nt_apnd, &
    1088              :            nt_hpnd_out=nt_hpnd, nt_ipnd_out=nt_ipnd, nt_aero_out=nt_aero, &
    1089              :            nlt_chl_sw_out=nlt_chl_sw, nlt_zaero_sw_out=nlt_zaero_sw, &
    1090              :            nt_rsnw_out=nt_rsnw, &
    1091       657372 :            nt_fbri_out=nt_fbri, nt_zaero_out=nt_zaero, nt_bgc_N_out=nt_bgc_N)
    1092       657372 :       call icepack_warnings_flush(nu_diag)
    1093       657372 :       if (icepack_warnings_aborted()) call icedrv_system_abort(string=subname, &
    1094            0 :           file=__FILE__,line= __LINE__)
    1095              : 
    1096       657372 :       call icepack_query_parameters(dEdd_algae_out=dEdd_algae, snwgrain_out=snwgrain)
    1097       657372 :       call icepack_warnings_flush(nu_diag)
    1098       657372 :       if (icepack_warnings_aborted()) call icedrv_system_abort(string=subname, &
    1099            0 :           file=__FILE__,line= __LINE__)
    1100              : 
    1101              :       !-----------------------------------------------------------------
    1102              : 
    1103       657372 :       allocate(rsnow(nslyr,ncat))
    1104       657372 :       allocate(ztrcr_sw(nbtrcr_sw,ncat))
    1105              : 
    1106       657372 :       l_print_point = .false.
    1107              : 
    1108      3286860 :       do i = 1, nx
    1109              : 
    1110      2629488 :          fbri       (:) = c0
    1111     36867984 :          rsnow    (:,:) = c0
    1112     15390816 :          ztrcr_sw (:,:) = c0
    1113     15390816 :          do n = 1, ncat
    1114     12761328 :            if (tr_brine) fbri    (n) = trcrn(i,nt_fbri,n)
    1115     22996416 :            if (snwgrain) rsnow (:,n) = trcrn(i,nt_rsnw:nt_rsnw+nslyr-1,n)
    1116              :          enddo
    1117              : 
    1118      2629488 :          if (tmask(i)) then
    1119              : 
    1120              :             call icepack_step_radiation(dt=dt,                          &
    1121              :                          fbri=fbri(:),                                  &
    1122              :                          aicen=aicen(i,:),          vicen=vicen(i,:),   &
    1123              :                          vsnon=vsnon(i,:),                              &
    1124              :                          Tsfcn=trcrn(i,nt_Tsfc,:),                      &
    1125              :                          alvln=trcrn(i,nt_alvl,:),                      &
    1126              :                          apndn=trcrn(i,nt_apnd,:),                      &
    1127              :                          hpndn=trcrn(i,nt_hpnd,:),                      &
    1128              :                          ipndn=trcrn(i,nt_ipnd,:),                      &
    1129              :                          aeron=trcrn(i,nt_aero:nt_aero+4*n_aero-1,:),   &
    1130              :                          bgcNn=trcrn(i,nt_bgc_N(1):nt_bgc_N(1)+n_algae*(nblyr+3)-1,:), &
    1131              :                          zaeron=trcrn(i,nt_zaero(1):nt_zaero(1)+n_zaero*(nblyr+3)-1,:), &
    1132              :                          trcrn_bgcsw=ztrcr_sw,                          &
    1133              :                          TLAT=TLAT(i),              TLON=TLON(i),       &
    1134              :                          sec=sec,                   yday=yday,          &
    1135              :                          swvdr=swvdr(i),            swvdf=swvdf(i),           &
    1136              :                          swidr=swidr(i),            swidf=swidf(i),           &
    1137              :                          coszen=coszen(i),          fsnow=fsnow(i),           &
    1138              :                          alvdrn=alvdrn(i,:),        alvdfn=alvdfn(i,:),       &
    1139              :                          alidrn=alidrn(i,:),        alidfn=alidfn(i,:),       &
    1140              :                          fswsfcn=fswsfcn(i,:),      fswintn=fswintn(i,:),     &
    1141              :                          fswthrun=fswthrun(i,:),                              &
    1142              :                          fswthrun_vdr=fswthrun_vdr(i,:),                      &
    1143              :                          fswthrun_vdf=fswthrun_vdf(i,:),                      &
    1144              :                          fswthrun_idr=fswthrun_idr(i,:),                      &
    1145              :                          fswthrun_idf=fswthrun_idf(i,:),                      &
    1146              :                          fswpenln=fswpenln(i,:,:),                            &
    1147              :                          Sswabsn=Sswabsn(i,:,:),    Iswabsn=Iswabsn(i,:,:),   &
    1148              :                          albicen=albicen(i,:),      albsnon=albsnon(i,:),     &
    1149              :                          albpndn=albpndn(i,:),      apeffn=apeffn(i,:),       &
    1150              :                          snowfracn=snowfracn(i,:),                            &
    1151              :                          dhsn=dhsn(i,:),            ffracn=ffracn(i,:),       &
    1152              :                          rsnow=rsnow(:,:),                                    &
    1153      1972116 :                          l_print_point=l_print_point)
    1154              : 
    1155              :          endif ! tmask
    1156              : 
    1157      3286860 :       if (dEdd_algae .and. (tr_zaero .or. tr_bgc_N)) then
    1158            0 :         do n = 1, ncat
    1159            0 :            do k = 1, nbtrcr_sw
    1160            0 :               trcrn_sw(i,k,n) = ztrcr_sw(k,n)
    1161              :            enddo
    1162              :         enddo
    1163              :       endif
    1164              : 
    1165              :       enddo ! i
    1166       657372 :       call icepack_warnings_flush(nu_diag)
    1167       657372 :       if (icepack_warnings_aborted()) call icedrv_system_abort(string=subname, &
    1168            0 :           file=__FILE__, line=__LINE__)
    1169              : 
    1170       657372 :       deallocate(rsnow)
    1171       657372 :       deallocate(ztrcr_sw)
    1172       657372 :       deallocate(nlt_zaero_sw)
    1173       657372 :       deallocate(nt_zaero)
    1174       657372 :       deallocate(nt_bgc_N)
    1175              : 
    1176      3944232 :       end subroutine step_radiation
    1177              : 
    1178              : !=======================================================================
    1179              : ! Ocean mixed layer calculation (internal to sea ice model).
    1180              : ! Allows heat storage in ocean for uncoupled runs.
    1181              : !
    1182              : ! authors:   John Weatherly, CRREL
    1183              : !            C.M. Bitz, UW
    1184              : !            Elizabeth C. Hunke, LANL
    1185              : !            Bruce P. Briegleb, NCAR
    1186              : !            William H. Lipscomb, LANL
    1187              : 
    1188       657372 :       subroutine ocean_mixed_layer (dt)
    1189              : 
    1190              :       use icedrv_arrays_column, only: Cdn_atm, Cdn_atm_ratio
    1191              :       use icepack_intfc, only: icepack_ocn_mixed_layer, icepack_atm_boundary
    1192              :       use icedrv_init, only: tmask
    1193              :       use icedrv_domain_size, only: nx
    1194              :       use icedrv_flux, only: sst, Tf, Qa, uatm, vatm, wind, potT, rhoa, zlvl
    1195              :       use icedrv_flux, only: frzmlt, fhocn, fswthru, flw, flwout_ocn, fsens_ocn, flat_ocn, evap_ocn
    1196              :       use icedrv_flux, only: alvdr_ocn, alidr_ocn, alvdf_ocn, alidf_ocn, swidf, swvdf, swidr, swvdr
    1197              :       use icedrv_flux, only: qdp, hmix, strairx_ocn, strairy_ocn, Tref_ocn, Qref_ocn
    1198              :       use icedrv_state, only: aice
    1199              : 
    1200              :       real (kind=dbl_kind), intent(in) :: &
    1201              :          dt      ! time step
    1202              : 
    1203              :       ! local variables
    1204              : 
    1205              :       integer (kind=int_kind) :: &
    1206              :          i           ! horizontal indices
    1207              : 
    1208              :       real (kind=dbl_kind) :: &
    1209              :          albocn
    1210              : 
    1211              :       real (kind=dbl_kind), dimension(nx) :: &
    1212              :          delt  , & ! potential temperature difference   (K)
    1213              :          delq  , & ! specific humidity difference   (kg/kg)
    1214              :          shcoef, & ! transfer coefficient for sensible heat
    1215              :          lhcoef    ! transfer coefficient for latent heat
    1216              : 
    1217              :       character(len=*), parameter :: subname='(ocean_mixed_layer)'
    1218              : 
    1219              :       !-----------------------------------------------------------------
    1220              :       ! query icepack values
    1221              :       !-----------------------------------------------------------------
    1222              : 
    1223       657372 :          call icepack_query_parameters(albocn_out=albocn)
    1224       657372 :          call icepack_warnings_flush(nu_diag)
    1225       657372 :          if (icepack_warnings_aborted()) call icedrv_system_abort(string=subname, &
    1226            0 :              file=__FILE__, line=__LINE__)
    1227              : 
    1228              :       !-----------------------------------------------------------------
    1229              :       ! Identify ocean cells.
    1230              :       ! Set fluxes to zero in land cells.
    1231              :       !-----------------------------------------------------------------
    1232              : 
    1233      3286860 :          do i = 1, nx
    1234      3286860 :             if (.not.tmask(i)) then
    1235       657372 :                sst       (i) = c0
    1236       657372 :                frzmlt    (i) = c0
    1237       657372 :                flwout_ocn(i) = c0
    1238       657372 :                fsens_ocn (i) = c0
    1239       657372 :                flat_ocn  (i) = c0
    1240       657372 :                evap_ocn  (i) = c0
    1241              :              endif
    1242              :          enddo                  ! i
    1243              : 
    1244              :       !-----------------------------------------------------------------
    1245              :       ! Compute boundary layer quantities
    1246              :       !-----------------------------------------------------------------
    1247              : 
    1248      3286860 :             do i = 1, nx
    1249      3286860 :                if (tmask(i)) then
    1250              :                   call icepack_atm_boundary(sfctype = 'ocn',          &
    1251              :                                             Tsf     = sst(i),         &
    1252              :                                             potT    = potT(i),        &
    1253              :                                             uatm    = uatm(i),        &
    1254              :                                             vatm    = vatm(i),        &
    1255              :                                             wind    = wind(i),        &
    1256              :                                             zlvl    = zlvl(i),        &
    1257              :                                             Qa      = Qa(i),          &
    1258              :                                             rhoa    = rhoa(i),        &
    1259              :                                             strx    = strairx_ocn(i), &
    1260              :                                             stry    = strairy_ocn(i), &
    1261              :                                             Tref    = Tref_ocn(i),    &
    1262              :                                             Qref    = Qref_ocn(i),    &
    1263              :                                             delt    = delt(i),        &
    1264              :                                             delq    = delq(i),        &
    1265              :                                             lhcoef  = lhcoef(i),      &
    1266              :                                             shcoef  = shcoef(i),      &
    1267              :                                             Cdn_atm = Cdn_atm(i),     &
    1268      1972116 :                                             Cdn_atm_ratio_n = Cdn_atm_ratio(i))
    1269              :                endif
    1270              :             enddo ! i
    1271       657372 :             call icepack_warnings_flush(nu_diag)
    1272       657372 :             if (icepack_warnings_aborted()) call icedrv_system_abort(string=subname, &
    1273            0 :                 file=__FILE__, line=__LINE__)
    1274              : 
    1275              :       !-----------------------------------------------------------------
    1276              :       ! Ocean albedo
    1277              :       ! For now, assume albedo = albocn in each spectral band.
    1278              :       !-----------------------------------------------------------------
    1279              : 
    1280      3286860 :          alvdr_ocn(:) = albocn
    1281      3286860 :          alidr_ocn(:) = albocn
    1282      3286860 :          alvdf_ocn(:) = albocn
    1283      3286860 :          alidf_ocn(:) = albocn
    1284              : 
    1285              :       !-----------------------------------------------------------------
    1286              :       ! Compute ocean fluxes and update SST
    1287              :       !-----------------------------------------------------------------
    1288      3286860 :       do i = 1, nx
    1289      3286860 :          if (tmask(i)) then
    1290              :             call icepack_ocn_mixed_layer(alvdr_ocn=alvdr_ocn(i),  swvdr=swvdr(i),   &
    1291              :                                          alidr_ocn=alidr_ocn(i),  swidr=swidr(i),   &
    1292              :                                          alvdf_ocn=alvdf_ocn(i),  swvdf=swvdf(i),   &
    1293              :                                          alidf_ocn=alidf_ocn(i),  swidf=swidf(i),   &
    1294              :                                          flwout_ocn=flwout_ocn(i),sst=sst(i),       &
    1295              :                                          fsens_ocn=fsens_ocn(i),  shcoef=shcoef(i), &
    1296              :                                          flat_ocn=flat_ocn(i),    lhcoef=lhcoef(i), &
    1297              :                                          evap_ocn=evap_ocn(i),    flw=flw(i),       &
    1298              :                                          delt=delt(i),            delq=delq(i),     &
    1299              :                                          aice=aice(i),            fhocn=fhocn(i),   &
    1300              :                                          fswthru=fswthru(i),      hmix=hmix(i),     &
    1301              :                                          Tf=Tf(i),                qdp=qdp(i),       &
    1302      1972116 :                                          frzmlt=frzmlt(i),        dt=dt)
    1303              :          endif
    1304              :       enddo                    ! i
    1305       657372 :       call icepack_warnings_flush(nu_diag)
    1306       657372 :       if (icepack_warnings_aborted()) call icedrv_system_abort(string=subname, &
    1307            0 :           file=__FILE__, line=__LINE__)
    1308              : 
    1309       657372 :       end subroutine ocean_mixed_layer
    1310              : 
    1311              : !=======================================================================
    1312              : 
    1313       657372 :       subroutine biogeochemistry (dt)
    1314              : 
    1315              :       use icedrv_arrays_column, only: upNO, upNH, iDi, iki, zfswin
    1316              :       use icedrv_arrays_column, only: darcy_V, grow_net
    1317              :       use icedrv_arrays_column, only: PP_net, hbri,dhbr_bot, dhbr_top, Zoo
    1318              :       use icedrv_arrays_column, only: fbio_snoice, fbio_atmice, ocean_bio
    1319              :       use icedrv_arrays_column, only: first_ice, fswpenln, bphi, bTiz, ice_bio_net
    1320              :       use icedrv_arrays_column, only: snow_bio_net, fswthrun
    1321              :       use icedrv_arrays_column, only: ocean_bio_all
    1322              :       use icepack_intfc, only: icepack_biogeochemistry, icepack_load_ocean_bio_array
    1323              :       use icedrv_domain_size, only: nblyr, nilyr, nslyr, n_algae, n_zaero, ncat
    1324              :       use icedrv_domain_size, only: n_doc, n_dic,  n_don, n_fed, n_fep, nx
    1325              :       use icedrv_flux, only: meltbn, melttn, congeln, snoicen
    1326              :       use icedrv_flux, only: sst, sss, Tf, fsnow, meltsn
    1327              :       use icedrv_flux, only: hin_old, flux_bio, flux_bio_atm, faero_atm
    1328              :       use icedrv_flux, only: nit, amm, sil, dmsp, dms, algalN, doc, don, dic, fed, fep, zaeros, hum
    1329              :       use icedrv_state, only: aicen_init, vicen_init, aicen, vicen, vsnon
    1330              :       use icedrv_state, only: trcrn, vsnon_init, aice0
    1331              : 
    1332              :       real (kind=dbl_kind), intent(in) :: &
    1333              :          dt      ! time step
    1334              : 
    1335              :       ! local variables
    1336              : 
    1337              :       integer (kind=int_kind) :: &
    1338              :          i           , & ! horizontal indices
    1339              :          mm              ! tracer index
    1340              : 
    1341              :       integer (kind=int_kind) :: &
    1342              :          max_algae, max_nbtrcr, max_don, &
    1343              :          max_doc, max_dic, max_aero, max_fe, &
    1344              :          nbtrcr, ntrcr
    1345              : 
    1346              :       integer (kind=int_kind), dimension(:), allocatable :: &
    1347       657372 :          nlt_zaero
    1348              : 
    1349              :       integer (kind=int_kind), allocatable :: &
    1350       657372 :          bio_index_o(:)
    1351              : 
    1352              :       logical (kind=log_kind) :: &
    1353              :          skl_bgc, tr_brine, tr_zaero
    1354              : 
    1355              :       character(len=*), parameter :: subname='(biogeochemistry)'
    1356              : 
    1357              :       !-----------------------------------------------------------------
    1358              :       ! query icepack values
    1359              :       !-----------------------------------------------------------------
    1360              : 
    1361       657372 :       call icepack_query_tracer_flags(tr_brine_out=tr_brine)
    1362       657372 :       call icepack_warnings_flush(nu_diag)
    1363       657372 :       if (icepack_warnings_aborted()) call icedrv_system_abort(string=subname, &
    1364            0 :           file=__FILE__,line= __LINE__)
    1365              : 
    1366       657372 :       call icepack_query_parameters(skl_bgc_out=skl_bgc)
    1367       657372 :       call icepack_warnings_flush(nu_diag)
    1368       657372 :       if (icepack_warnings_aborted()) call icedrv_system_abort(string=subname, &
    1369            0 :           file=__FILE__,line= __LINE__)
    1370              : 
    1371              :       !-----------------------------------------------------------------
    1372              : 
    1373       657372 :       if (tr_brine .or. skl_bgc) then
    1374              : 
    1375              :       !-----------------------------------------------------------------
    1376              : 
    1377              :       call icepack_query_tracer_sizes( &
    1378              :            max_algae_out=max_algae, max_nbtrcr_out=max_nbtrcr, max_don_out=max_don, &
    1379        60684 :            max_doc_out=max_doc, max_dic_out=max_dic, max_aero_out=max_aero, max_fe_out=max_fe)
    1380        60684 :       call icepack_warnings_flush(nu_diag)
    1381        60684 :       if (icepack_warnings_aborted()) call icedrv_system_abort(string=subname, &
    1382            0 :           file=__FILE__,line= __LINE__)
    1383              : 
    1384              :       !-----------------------------------------------------------------
    1385              : 
    1386        60684 :       allocate(bio_index_o(max_nbtrcr))
    1387        60684 :       allocate(nlt_zaero(max_aero))
    1388              : 
    1389              :       !-----------------------------------------------------------------
    1390              : 
    1391        60684 :       call icepack_query_tracer_sizes(ntrcr_out=ntrcr, nbtrcr_out=nbtrcr)
    1392        60684 :       call icepack_query_tracer_flags(tr_zaero_out=tr_zaero)
    1393        60684 :       call icepack_query_tracer_indices(nlt_zaero_out=nlt_zaero)
    1394        60684 :       call icepack_query_tracer_indices(bio_index_o_out=bio_index_o)
    1395        60684 :       call icepack_warnings_flush(nu_diag)
    1396        60684 :       if (icepack_warnings_aborted()) call icedrv_system_abort(string=subname, &
    1397            0 :           file=__FILE__,line= __LINE__)
    1398              : 
    1399              :       !-----------------------------------------------------------------
    1400              : 
    1401              :       ! Define ocean concentrations for tracers used in simulation
    1402       303420 :       do i = 1, nx
    1403              : 
    1404              :          call icepack_load_ocean_bio_array(                 &
    1405              :                       nit = nit(i),   amm    = amm(i),      &
    1406              :                       sil = sil(i),   dmsp   = dmsp(i),     &
    1407              :                       dms = dms(i),   algalN = algalN(i,:), &
    1408              :                       doc = doc(i,:), don    = don(i,:),    &
    1409              :                       dic = dic(i,:), fed    = fed(i,:),    &
    1410              :                       fep = fep(i,:), zaeros = zaeros(i,:), &
    1411              :                       ocean_bio_all=ocean_bio_all(i,:),     &
    1412       242736 :                       hum=hum(i))
    1413              : ! handled below
    1414              : !         call icepack_warnings_flush(nu_diag)
    1415              : !         if (icepack_warnings_aborted()) call icedrv_system_abort(i, istep1, subname, &
    1416              : !             file=__FILE__,line= __LINE__)
    1417              : 
    1418      3698256 :          do mm = 1,nbtrcr
    1419      3698256 :             ocean_bio(i,mm) = ocean_bio_all(i,bio_index_o(mm))
    1420              :          enddo  ! mm
    1421       242736 :          if (tr_zaero) then
    1422      1212720 :             do mm = 1, n_zaero  ! update aerosols
    1423      1212720 :                flux_bio_atm(i,nlt_zaero(mm)) = faero_atm(i,mm)
    1424              :             enddo  ! mm
    1425              :          endif
    1426              : 
    1427              :          call icepack_biogeochemistry(dt=dt,                    &
    1428              :                       upNO         = upNO(i),                   &
    1429              :                       upNH         = upNH(i),                   &
    1430              :                       iDi          = iDi(i,:,:),                &
    1431              :                       iki          = iki(i,:,:),                &
    1432              :                       zfswin       = zfswin(i,:,:),             &
    1433              :                       darcy_V      = darcy_V(i,:),              &
    1434              :                       grow_net     = grow_net(i),               &
    1435              :                       PP_net       = PP_net(i),                 &
    1436              :                       hbri         = hbri(i),                   &
    1437              :                       dhbr_bot     = dhbr_bot(i,:),             &
    1438              :                       dhbr_top     = dhbr_top(i,:),             &
    1439              :                       Zoo          = Zoo(i,:,:),                &
    1440              :                       fbio_snoice  = fbio_snoice(i,:),          &
    1441              :                       fbio_atmice  = fbio_atmice(i,:),          &
    1442              :                       ocean_bio    = ocean_bio(i,1:nbtrcr),     &
    1443              :                       first_ice    = first_ice(i,:),            &
    1444              :                       fswpenln     = fswpenln(i,:,:),           &
    1445              :                       bphi         = bphi(i,:,:),               &
    1446              :                       bTiz         = bTiz(i,:,:),               &
    1447              :                       ice_bio_net  = ice_bio_net(i,1:nbtrcr),   &
    1448              :                       snow_bio_net = snow_bio_net(i,1:nbtrcr),  &
    1449              :                       fswthrun     = fswthrun(i,:),             &
    1450              :                       meltbn       = meltbn(i,:),               &
    1451              :                       melttn       = melttn(i,:),               &
    1452              :                       congeln      = congeln(i,:),              &
    1453              :                       snoicen      = snoicen(i,:),              &
    1454              :                       sst          = sst(i),                    &
    1455              :                       sss          = sss(i),                    &
    1456              :                       Tf           = Tf(i),                     &
    1457              :                       fsnow        = fsnow(i),                  &
    1458              :                       meltsn       = meltsn(i,:),               &
    1459              :                       hin_old      = hin_old(i,:),              &
    1460              :                       flux_bio     = flux_bio(i,1:nbtrcr),      &
    1461              :                       flux_bio_atm = flux_bio_atm(i,1:nbtrcr),  &
    1462              :                       aicen_init   = aicen_init(i,:),           &
    1463              :                       vicen_init   = vicen_init(i,:),           &
    1464              :                       aicen        = aicen(i,:),                &
    1465              :                       vicen        = vicen(i,:),                &
    1466              :                       vsnon        = vsnon(i,:),                &
    1467              :                       aice0        = aice0(i),                  &
    1468              :                       trcrn        = trcrn(i,1:ntrcr,:),        &
    1469       303420 :                       vsnon_init   = vsnon_init(i,:))
    1470              : ! handled below
    1471              : !         call icepack_warnings_flush(nu_diag)
    1472              : !         if (icepack_warnings_aborted()) call icedrv_system_abort(i, istep1, subname, &
    1473              : !             __FILE__, __LINE__)
    1474              : 
    1475              :       enddo               ! i
    1476        60684 :       call icepack_warnings_flush(nu_diag)
    1477        60684 :       if (icepack_warnings_aborted()) call icedrv_system_abort(string=subname, &
    1478            0 :           file=__FILE__, line=__LINE__)
    1479              : 
    1480        60684 :       deallocate(nlt_zaero)
    1481       182052 :       deallocate(bio_index_o)
    1482              : 
    1483              :       endif  ! tr_brine .or. skl_bgc
    1484              : 
    1485       657372 :       end subroutine biogeochemistry
    1486              : 
    1487              : !=======================================================================
    1488              : 
    1489              :       end module icedrv_step
    1490              : 
    1491              : !=======================================================================
        

Generated by: LCOV version 2.0-1