LCOV - code coverage report
Current view: top level - configuration/driver - icedrv_diagnostics.F90 (source / functions) Coverage Total Hit
Test: 250115-224328:3d8b76b919:4:base,io,travis,quick Lines: 57.75 % 258 149
Test Date: 2025-01-15 16:24:29 Functions: 66.67 % 6 4

            Line data    Source code
       1              : !=======================================================================
       2              : 
       3              : ! Diagnostic information output during run
       4              : !
       5              : ! authors: Elizabeth C. Hunke, LANL
       6              : 
       7              :       module icedrv_diagnostics
       8              : 
       9              :       use icedrv_kinds
      10              :       use icedrv_constants, only: nu_diag, nu_diag_out
      11              :       use icedrv_domain_size, only: nx
      12              :       use icedrv_domain_size, only: ncat, nfsd, n_iso, nilyr, nslyr
      13              :       use icepack_intfc, only: c0
      14              :       use icepack_intfc, only: icepack_warnings_flush, icepack_warnings_aborted
      15              :       use icepack_intfc, only: icepack_query_parameters
      16              :       use icepack_intfc, only: icepack_query_tracer_flags, icepack_query_tracer_indices
      17              :       use icedrv_system, only: icedrv_system_abort, icedrv_system_flush
      18              : 
      19              :       implicit none
      20              :       private
      21              :       public :: runtime_diags, &
      22              :                 init_mass_diags, &
      23              :                 icedrv_diagnostics_debug, &
      24              :                 print_state
      25              : 
      26              :       ! diagnostic output file
      27              :       character (len=char_len), public :: diag_file
      28              : 
      29              :       ! point print data
      30              : 
      31              :       logical (kind=log_kind), public :: &
      32              :          print_points         ! if true, print point data
      33              : 
      34              :       integer (kind=int_kind), parameter, public :: &
      35              :          npnt = 2             ! total number of points to be printed
      36              : 
      37              :       character (len=char_len), dimension(nx), public :: nx_names
      38              : 
      39              :       ! for water and heat budgets
      40              :       real (kind=dbl_kind), dimension(nx) :: &
      41              :          pdhi             , & ! change in mean ice thickness (m)
      42              :          pdhs             , & ! change in mean snow thickness (m)
      43              :          pde                  ! change in ice and snow energy (W m-2)
      44              : 
      45              :       real (kind=dbl_kind), dimension(nx,n_iso) :: &
      46              :          pdiso                ! change in mean isotope concentration
      47              : 
      48              : !=======================================================================
      49              : 
      50              :       contains
      51              : 
      52              : !=======================================================================
      53              : 
      54              : ! Writes diagnostic info (max, min, global sums, etc) to standard out
      55              : !
      56              : ! authors: Elizabeth C. Hunke, LANL
      57              : !          Bruce P. Briegleb, NCAR
      58              : !          Cecilia M. Bitz, UW
      59              : 
      60       336336 :       subroutine runtime_diags (dt)
      61              : 
      62              :       use icedrv_arrays_column, only: floe_rad_c
      63              :       use icedrv_flux, only: evap, fsnow, frazil
      64              :       use icedrv_flux, only: fswabs, flw, flwout, fsens, fsurf, flat
      65              :       use icedrv_flux, only: frain, fiso_evap, fiso_ocn, fiso_atm
      66              :       use icedrv_flux, only: Tair, Qa, fsw, fcondtop
      67              :       use icedrv_flux, only: meltt, meltb, meltl, snoice
      68              :       use icedrv_flux, only: dsnow, congel, sst, sss, Tf, fhocn
      69              :       use icedrv_state, only: aice, vice, vsno, trcr, trcrn, aicen, vsnon
      70              : 
      71              :       real (kind=dbl_kind), intent(in) :: &
      72              :          dt      ! time step
      73              : 
      74              :       ! local variables
      75              : 
      76              :       integer (kind=int_kind) :: &
      77              :          n, nc, k
      78              : 
      79              :       logical (kind=log_kind) :: &
      80              :          calc_Tsfc, snwgrain
      81              : 
      82              :       character (len=char_len) :: &
      83              :          snwredist
      84              : 
      85              :       ! fields at diagnostic points
      86              :       real (kind=dbl_kind) :: &
      87              :          pTair, pfsnow, pfrain, &
      88              :          paice, hiavg, hsavg, hbravg, psalt, pTsfc, &
      89              :          pevap, pfhocn, fsdavg, &
      90              :          rsnwavg, rhosavg, smicetot, smliqtot, smtot
      91              : 
      92              :       real (kind=dbl_kind), dimension (nx) :: &
      93              :          work1, work2, work3
      94              : 
      95              :       real (kind=dbl_kind) :: &
      96              :          Tffresh, rhos, rhow, rhoi
      97              : 
      98              :       logical (kind=log_kind) :: tr_brine, tr_fsd, tr_iso, tr_snow
      99              :       integer (kind=int_kind) :: nt_fbri, nt_Tsfc, nt_fsd, nt_isosno, nt_isoice
     100              :       integer (kind=int_kind) :: nt_rsnw, nt_rhos, nt_smice, nt_smliq
     101              : 
     102              :       character(len=*), parameter :: subname='(runtime_diags)'
     103              : 
     104              :       !-----------------------------------------------------------------
     105              :       ! query Icepack values
     106              :       !-----------------------------------------------------------------
     107              : 
     108              :       call icepack_query_parameters(calc_Tsfc_out=calc_Tsfc, &
     109        84084 :            snwredist_out=snwredist, snwgrain_out=snwgrain)
     110              :       call icepack_query_tracer_flags(tr_brine_out=tr_brine, &
     111        84084 :            tr_fsd_out=tr_fsd,tr_iso_out=tr_iso,tr_snow_out=tr_snow)
     112              :       call icepack_query_tracer_indices(nt_fbri_out=nt_fbri, nt_Tsfc_out=nt_Tsfc,&
     113              :            nt_fsd_out=nt_fsd, nt_isosno_out=nt_isosno, nt_isoice_out=nt_isoice, &
     114              :            nt_rsnw_out=nt_rsnw, nt_rhos_out=nt_rhos, &
     115        84084 :            nt_smice_out=nt_smice, nt_smliq_out=nt_smliq)
     116              :       call icepack_query_parameters(Tffresh_out=Tffresh, rhos_out=rhos, &
     117        84084 :            rhow_out=rhow, rhoi_out=rhoi)
     118        84084 :       call icepack_warnings_flush(nu_diag)
     119        84084 :       if (icepack_warnings_aborted()) call icedrv_system_abort(string=subname, &
     120            0 :           file=__FILE__,line= __LINE__)
     121              : 
     122              :       !-----------------------------------------------------------------
     123              :       ! NOTE these are computed for the last timestep only (not avg)
     124              :       !-----------------------------------------------------------------
     125              : 
     126        84084 :       call total_energy (work1)
     127        84084 :       call total_salt   (work2)
     128              : 
     129       420420 :       do n = 1, nx
     130       336336 :         pTair = Tair(n) - Tffresh ! air temperature
     131       336336 :         pfsnow = fsnow(n)*dt/rhos ! snowfall
     132       336336 :         pfrain = frain(n)*dt/rhow ! rainfall
     133              : 
     134       336336 :         paice = aice(n)           ! ice area
     135       336336 :         hiavg = c0                ! avg ice thickness
     136       336336 :         hsavg = c0                ! avg snow thickness
     137       336336 :         fsdavg = c0               ! FSD rep radius
     138       336336 :         hbravg = c0               ! avg brine thickness
     139       336336 :         rsnwavg = c0              ! avg snow grain radius
     140       336336 :         rhosavg = c0              ! avg snow density
     141       336336 :         smicetot = c0             ! total mass of ice in snow (kg/m2)
     142       336336 :         smliqtot = c0             ! total mass of liquid in snow (kg/m2)
     143       336336 :         smtot = c0                ! total mass of snow volume (kg/m2)
     144       336336 :         psalt = c0
     145       336336 :         if (paice /= c0) then
     146       250705 :            hiavg = vice(n)/paice
     147       250705 :            hsavg = vsno(n)/paice
     148       250705 :            if (tr_brine) hbravg = trcr(n,nt_fbri) * hiavg
     149       250705 :            if (tr_fsd) then        ! avg floe size distribution
     150        24660 :               do nc = 1, ncat
     151       211035 :               do k = 1, nfsd
     152              :                   fsdavg  = fsdavg &
     153              :                           + trcrn(n,nt_fsd+k-1,nc) * floe_rad_c(k) &
     154       206925 :                           * aicen(n,nc) / paice
     155              :               end do
     156              :               end do
     157              :            end if
     158       250705 :            if (tr_snow) then      ! snow tracer quantities
     159        60816 :               do nc = 1, ncat
     160        50680 :                  if (vsnon(n,nc) > c0) then
     161       246426 :                     do k = 1, nslyr
     162       205355 :                        rsnwavg  = rsnwavg  + trcrn(n,nt_rsnw +k-1,nc) ! snow grain radius
     163       205355 :                        rhosavg  = rhosavg  + trcrn(n,nt_rhos +k-1,nc) ! compacted snow density
     164       205355 :                        smicetot = smicetot + trcrn(n,nt_smice+k-1,nc) * vsnon(n,nc)
     165       246426 :                        smliqtot = smliqtot + trcrn(n,nt_smliq+k-1,nc) * vsnon(n,nc)
     166              :                     end do
     167              :                  endif
     168        60816 :                  smtot = smtot + rhos * vsnon(n,nc) ! mass of ice in standard density snow
     169              :               end do
     170        10136 :               rsnwavg  = rsnwavg  / real(nslyr*ncat,kind=dbl_kind) ! snow grain radius
     171        10136 :               rhosavg  = rhosavg  / real(nslyr*ncat,kind=dbl_kind) ! compacted snow density
     172        10136 :               smicetot = smicetot / real(nslyr,kind=dbl_kind) ! mass of ice in snow
     173        10136 :               smliqtot = smliqtot / real(nslyr,kind=dbl_kind) ! mass of liquid in snow
     174              :            end if
     175              : 
     176              :         endif
     177       336336 :         if (vice(n) /= c0) psalt = work2(n)/vice(n)
     178       336336 :         pTsfc = trcr(n,nt_Tsfc)   ! ice/snow sfc temperature
     179       336336 :         pevap = evap(n)*dt/rhoi   ! sublimation/condensation
     180       336336 :         pdhi(n) = vice(n) - pdhi(n)  ! ice thickness change
     181       336336 :         pdhs(n) = vsno(n) - pdhs(n)  ! snow thickness change
     182       336336 :         pde(n) =-(work1(n)- pde(n))/dt ! ice/snow energy change
     183       336336 :         pfhocn = -fhocn(n)        ! ocean heat used by ice
     184              : 
     185       336336 :         work3(:) = c0
     186              : 
     187       344016 :         do k = 1, n_iso
     188              :            work3 (n)  =  (trcr(n,nt_isosno+k-1)*vsno(n) &
     189         7680 :                          +trcr(n,nt_isoice+k-1)*vice(n))
     190        10240 :            pdiso(n,k) = work3(n) - pdiso(n,k)
     191              :         enddo
     192              : 
     193              :         !-----------------------------------------------------------------
     194              :         ! start spewing
     195              :         !-----------------------------------------------------------------
     196              : 
     197       336336 :         write(nu_diag_out+n-1,899) nx_names(n)
     198              : 
     199       336336 :         write(nu_diag_out+n-1,*) '                         '
     200       336336 :         write(nu_diag_out+n-1,*) '----------atm----------'
     201       336336 :         write(nu_diag_out+n-1,900) 'air temperature (C)    = ',pTair
     202       336336 :         write(nu_diag_out+n-1,900) 'specific humidity      = ',Qa(n)
     203       336336 :         write(nu_diag_out+n-1,900) 'snowfall (m)           = ',pfsnow
     204       336336 :         write(nu_diag_out+n-1,900) 'rainfall (m)           = ',pfrain
     205       336336 :         if (.not.calc_Tsfc) then
     206            0 :           write(nu_diag_out+n-1,900) 'total surface heat flux= ', fsurf(n)
     207            0 :           write(nu_diag_out+n-1,900) 'top sfc conductive flux= ',fcondtop(n)
     208            0 :           write(nu_diag_out+n-1,900) 'latent heat flux       = ',flat(n)
     209              :         else
     210       336336 :           write(nu_diag_out+n-1,900) 'shortwave radiation sum= ',fsw(n)
     211       336336 :           write(nu_diag_out+n-1,900) 'longwave radiation     = ',flw(n)
     212              :         endif
     213       336336 :         write(nu_diag_out+n-1,*) '----------ice----------'
     214       336336 :         write(nu_diag_out+n-1,900) 'area fraction          = ',aice(n)! ice area
     215       336336 :         write(nu_diag_out+n-1,900) 'avg ice thickness (m)  = ',hiavg
     216       336336 :         write(nu_diag_out+n-1,900) 'avg snow depth (m)     = ',hsavg
     217       336336 :         write(nu_diag_out+n-1,900) 'avg salinity (ppt)     = ',psalt
     218       336336 :         write(nu_diag_out+n-1,900) 'avg brine thickness (m)= ',hbravg
     219       336336 :         if (tr_fsd) &
     220         5480 :         write(nu_diag_out+n-1,900) 'avg fsd rep radius (m) = ',fsdavg
     221              : 
     222       336336 :         if (calc_Tsfc) then
     223       336336 :           write(nu_diag_out+n-1,900) 'surface temperature(C) = ',pTsfc ! ice/snow
     224       336336 :           write(nu_diag_out+n-1,900) 'absorbed shortwave flx = ',fswabs(n)
     225       336336 :           write(nu_diag_out+n-1,900) 'outward longwave flx   = ',flwout(n)
     226       336336 :           write(nu_diag_out+n-1,900) 'sensible heat flx      = ',fsens(n)
     227       336336 :           write(nu_diag_out+n-1,900) 'latent heat flx        = ',flat(n)
     228              :         endif
     229       336336 :         write(nu_diag_out+n-1,900) 'subl/cond (m ice)      = ',pevap   ! sublimation/condensation
     230       336336 :         write(nu_diag_out+n-1,900) 'top melt (m)           = ',meltt(n)
     231       336336 :         write(nu_diag_out+n-1,900) 'bottom melt (m)        = ',meltb(n)
     232       336336 :         write(nu_diag_out+n-1,900) 'lateral melt (m)       = ',meltl(n)
     233       336336 :         write(nu_diag_out+n-1,900) 'new ice (m)            = ',frazil(n) ! frazil
     234       336336 :         write(nu_diag_out+n-1,900) 'congelation (m)        = ',congel(n)
     235       336336 :         write(nu_diag_out+n-1,900) 'snow-ice (m)           = ',snoice(n)
     236       336336 :         write(nu_diag_out+n-1,900) 'snow change (m)        = ',dsnow(n)
     237       336336 :         write(nu_diag_out+n-1,900) 'effective dhi (m)      = ',pdhi(n)   ! ice thickness change
     238       336336 :         write(nu_diag_out+n-1,900) 'effective dhs (m)      = ',pdhs(n)   ! snow thickness change
     239       336336 :         write(nu_diag_out+n-1,900) 'intnl enrgy chng(W/m^2)= ',pde (n)   ! ice/snow energy change
     240              : 
     241       336336 :         if (tr_snow) then
     242        14128 :            if (trim(snwredist) /= 'none') then
     243        14128 :               write(nu_diag_out+n-1,900) 'avg snow density(kg/m3)= ',rhosavg
     244              :            endif
     245        14128 :            if (snwgrain) then
     246        12668 :               write(nu_diag_out+n-1,900) 'avg snow grain radius  = ',rsnwavg
     247        12668 :               write(nu_diag_out+n-1,900) 'mass ice in snow(kg/m2)= ',smicetot
     248        12668 :               write(nu_diag_out+n-1,900) 'mass liq in snow(kg/m2)= ',smliqtot
     249        12668 :               write(nu_diag_out+n-1,900) 'mass ice+liq    (kg/m2)= ',smicetot+smliqtot
     250        12668 :               write(nu_diag_out+n-1,900) 'mass std snow   (kg/m2)= ',smtot
     251        12668 :               write(nu_diag_out+n-1,900) 'max  ice+liq    (kg/m2)= ',rhow * hsavg
     252              :            endif
     253              :         endif
     254              : 
     255       336336 :         write(nu_diag_out+n-1,*) '----------ocn----------'
     256       336336 :         write(nu_diag_out+n-1,900) 'sst (C)                = ',sst(n)  ! sea surface temperature
     257       336336 :         write(nu_diag_out+n-1,900) 'sss (ppt)              = ',sss(n)  ! sea surface salinity
     258       336336 :         write(nu_diag_out+n-1,900) 'freezing temp (C)      = ',Tf(n)   ! freezing temperature
     259       336336 :         write(nu_diag_out+n-1,900) 'heat used (W/m^2)      = ',pfhocn  ! ocean heat used by ice
     260              : 
     261       336336 :         if (tr_iso) then
     262        10240 :           do k = 1, n_iso
     263         7680 :              write(nu_diag_out+n-1,901) 'isotopic precip      = ',fiso_atm(n,k)*dt,k
     264         7680 :              write(nu_diag_out+n-1,901) 'isotopic evap/cond   = ',fiso_evap(n,k)*dt,k
     265         7680 :              write(nu_diag_out+n-1,901) 'isotopic loss to ocn = ',fiso_ocn(n,k)*dt,k
     266         7680 :              write(nu_diag_out+n-1,901) 'isotopic gain/loss   = ',(fiso_atm(n,k)-fiso_ocn(n,k)+fiso_evap(n,k))*dt,k
     267        10240 :              write(nu_diag_out+n-1,901) 'isotopic conc chg    = ',pdiso(n,k),k
     268              :           enddo
     269              :         endif
     270       420420 :         call icedrv_system_flush(nu_diag_out+n-1)
     271              :       end do
     272              : 899   format (43x,a24)
     273              : 900   format (a25,2x,f24.17)
     274              : 901   format (a25,2x,f24.17,i6)
     275              : 
     276        84084 :       end subroutine runtime_diags
     277              : 
     278              : !=======================================================================
     279              : 
     280              : ! Computes global combined ice and snow mass sum
     281              : !
     282              : ! author: Elizabeth C. Hunke, LANL
     283              : 
     284      1314744 :       subroutine init_mass_diags
     285              : 
     286              :       use icedrv_state, only: vice, vsno, trcr
     287              : 
     288              :       integer (kind=int_kind) :: i, k, nt_isosno, nt_isoice
     289              : 
     290              :       real (kind=dbl_kind), dimension (nx) :: work1
     291              : 
     292              :       character(len=*), parameter :: subname='(init_mass_diags)'
     293              : 
     294       657372 :       call icepack_query_tracer_indices(nt_isosno_out=nt_isosno)
     295       657372 :       call icepack_query_tracer_indices(nt_isoice_out=nt_isoice)
     296              : 
     297       657372 :       call total_energy (work1)
     298      3286860 :       do i = 1, nx
     299      2629488 :          pdhi(i) = vice (i)
     300      2629488 :          pdhs(i) = vsno (i)
     301      2629488 :          pde (i) = work1(i)
     302      3471324 :          do k = 1, n_iso
     303              :             pdiso(i,k) = (trcr(i,nt_isosno+k-1)*vsno(i) &
     304       245952 :                          +trcr(i,nt_isoice+k-1)*vice(i))
     305              :          enddo
     306              :       enddo
     307              : 
     308       657372 :       end subroutine init_mass_diags
     309              : 
     310              : !=======================================================================
     311              : 
     312              : ! Computes total energy of ice and snow in a grid cell.
     313              : !
     314              : ! authors: E. C. Hunke, LANL
     315              : 
     316       741456 :       subroutine total_energy (work)
     317              : 
     318              :       use icedrv_state, only: vicen, vsnon, trcrn
     319              : 
     320              :       real (kind=dbl_kind), dimension (nx), intent(out) :: &
     321              :          work      ! total energy
     322              : 
     323              :       ! local variables
     324              : 
     325              :       integer (kind=int_kind) :: &
     326              :         i, k, n
     327              : 
     328              :       integer (kind=int_kind) :: nt_qice, nt_qsno
     329              : 
     330              :       character(len=*), parameter :: subname='(total_energy)'
     331              : 
     332              :       !-----------------------------------------------------------------
     333              :       ! query Icepack values
     334              :       !-----------------------------------------------------------------
     335              : 
     336       741456 :          call icepack_query_tracer_indices(nt_qice_out=nt_qice, nt_qsno_out=nt_qsno)
     337       741456 :          call icepack_warnings_flush(nu_diag)
     338       741456 :          if (icepack_warnings_aborted()) call icedrv_system_abort(string=subname, &
     339            0 :              file=__FILE__,line= __LINE__)
     340              : 
     341              :       !-----------------------------------------------------------------
     342              :       ! Initialize
     343              :       !-----------------------------------------------------------------
     344              : 
     345       741456 :          work(:) = c0
     346              : 
     347              :       !-----------------------------------------------------------------
     348              :       ! Aggregate
     349              :       !-----------------------------------------------------------------
     350              : 
     351      4348188 :          do n = 1, ncat
     352     27948924 :             do k = 1, nilyr
     353    125317692 :                do i = 1, nx
     354              :                   work(i) = work(i) &
     355              :                           + trcrn(i,nt_qice+k-1,n) &
     356    121710960 :                           * vicen(i,n) / real(nilyr,kind=dbl_kind)
     357              :                enddo            ! i
     358              :             enddo               ! k
     359              : 
     360     10224620 :             do k = 1, nslyr
     361     32988892 :                do i = 1, nx
     362              :                   work(i) = work(i) &
     363              :                           + trcrn(i,nt_qsno+k-1,n) &
     364     29382160 :                           * vsnon(i,n) / real(nslyr,kind=dbl_kind)
     365              :                enddo            ! i
     366              :             enddo               ! k
     367              :          enddo                  ! n
     368              : 
     369       741456 :       end subroutine total_energy
     370              : 
     371              : !=======================================================================
     372              : 
     373              : ! Computes bulk salinity of ice and snow in a grid cell.
     374              : ! author: E. C. Hunke, LANL
     375              : 
     376        84084 :       subroutine total_salt (work)
     377              : 
     378              :       use icedrv_state, only: vicen, trcrn
     379              : 
     380              :       real (kind=dbl_kind), dimension (nx),  &
     381              :          intent(out) :: &
     382              :          work      ! total salt
     383              : 
     384              :       ! local variables
     385              : 
     386              :       integer (kind=int_kind) :: &
     387              :         i, k, n
     388              : 
     389              :       integer (kind=int_kind) :: nt_sice
     390              : 
     391              :       character(len=*), parameter :: subname='(total_salt)'
     392              : 
     393              :       !-----------------------------------------------------------------
     394              :       ! query Icepack values
     395              :       !-----------------------------------------------------------------
     396              : 
     397        84084 :          call icepack_query_tracer_indices(nt_sice_out=nt_sice)
     398        84084 :          call icepack_warnings_flush(nu_diag)
     399        84084 :          if (icepack_warnings_aborted()) call icedrv_system_abort(string=subname, &
     400            0 :              file=__FILE__,line= __LINE__)
     401              : 
     402              :       !-----------------------------------------------------------------
     403              :       ! Initialize
     404              :       !-----------------------------------------------------------------
     405              : 
     406        84084 :          work(:) = c0
     407              : 
     408              :       !-----------------------------------------------------------------
     409              :       ! Aggregate
     410              :       !-----------------------------------------------------------------
     411              : 
     412       500484 :          do n = 1, ncat
     413      3379104 :             do k = 1, nilyr
     414     14809500 :                do i = 1, nx
     415              :                   work(i) = work(i) &
     416              :                           + trcrn(i,nt_sice+k-1,n) &
     417     14393100 :                           * vicen(i,n) / real(nilyr,kind=dbl_kind)
     418              :                enddo            ! i
     419              :             enddo               ! k
     420              :          enddo                  ! n
     421              : 
     422        84084 :       end subroutine total_salt
     423              : 
     424              : !=======================================================================
     425              : !
     426              : ! Wrapper for the print_state debugging routine.
     427              : ! Useful for debugging in the main driver (see ice.F_debug)
     428              : !
     429              : ! author Elizabeth C. Hunke, LANL
     430              : !
     431            0 :       subroutine icedrv_diagnostics_debug (plabeld)
     432              : 
     433              :       use icedrv_calendar, only: istep1
     434              : 
     435              :       character (*), intent(in) :: plabeld
     436              : 
     437              :       character(len=*), parameter :: &
     438              :          subname='(icedrv_diagnostics_debug)'
     439              : 
     440              :       ! printing info for routine print_state
     441              : 
     442              :       integer (kind=int_kind), parameter :: &
     443              :          check_step = 1, & ! begin printing at istep1=check_step
     444              :          ip = 3               ! i index
     445              : 
     446            0 :       if (istep1 >= check_step) then
     447            0 :          call print_state(plabeld,ip)
     448              :       endif
     449              : 
     450            0 :       end subroutine icedrv_diagnostics_debug
     451              : 
     452              : !=======================================================================
     453              : 
     454              : ! This routine is useful for debugging.
     455              : ! Calls to it should be inserted in the form (after thermo, for example)
     456              : !     plabel = 'post thermo'
     457              : !     if (istep1 >= check_step) call print_state(plabel,ip)
     458              : ! 'use ice_diagnostics' may need to be inserted also
     459              : ! author: Elizabeth C. Hunke, LANL
     460              : 
     461            0 :       subroutine print_state(plabel,i)
     462              : 
     463              :       use icedrv_calendar,  only: istep1, time
     464              :       use icedrv_state, only: aice0, aicen, vicen, vsnon, uvel, vvel, trcrn
     465              :       use icedrv_flux, only: uatm, vatm, potT, Tair, Qa, flw, frain, fsnow
     466              :       use icedrv_flux, only: fsens, flat, evap, flwout
     467              :       use icedrv_flux, only: swvdr, swvdf, swidr, swidf, rhoa
     468              :       use icedrv_flux, only: frzmlt, sst, sss, Tf, Tref, Qref, Uref
     469              :       use icedrv_flux, only: uocn, vocn
     470              :       use icedrv_flux, only: fsw, fswabs, fswint_ai, fswthru, scale_factor
     471              :       use icedrv_flux, only: alvdr_ai, alvdf_ai, alidf_ai, alidr_ai
     472              : 
     473              :       character (*), intent(in) :: plabel
     474              : 
     475              :       integer (kind=int_kind), intent(in) :: &
     476              :           i              ! horizontal index
     477              : 
     478              :       ! local variables
     479              : 
     480              :       real (kind=dbl_kind) :: &
     481              :           eidebug, esdebug, &
     482              :           qi, qs, Tsnow, &
     483              :           puny, Lfresh, cp_ice, &
     484              :           rhoi, rhos
     485              : 
     486              :       integer (kind=int_kind) :: n, k
     487              : 
     488              :       integer (kind=int_kind) :: nt_Tsfc, nt_qice, nt_qsno, nt_fsd
     489              :       integer (kind=int_kind) :: nt_smice, nt_smliq
     490              : 
     491              :       logical (kind=log_kind) :: tr_fsd, tr_snow
     492              : 
     493              :       character(len=*), parameter :: subname='(print_state)'
     494              : 
     495              :       !-----------------------------------------------------------------
     496              :       ! query Icepack values
     497              :       !-----------------------------------------------------------------
     498              : 
     499            0 :       call icepack_query_tracer_flags(tr_fsd_out=tr_fsd, tr_snow_out=tr_snow)
     500              :       call icepack_query_tracer_indices(nt_Tsfc_out=nt_Tsfc, nt_qice_out=nt_qice, &
     501              :            nt_qsno_out=nt_qsno,nt_fsd_out=nt_fsd, nt_smice_out=nt_smice, &
     502            0 :            nt_smliq_out=nt_smliq)
     503              :       call icepack_query_parameters(puny_out=puny, Lfresh_out=Lfresh, cp_ice_out=cp_ice, &
     504            0 :            rhoi_out=rhoi, rhos_out=rhos)
     505            0 :       call icepack_warnings_flush(nu_diag)
     506            0 :       if (icepack_warnings_aborted()) call icedrv_system_abort(string=subname, &
     507            0 :           file=__FILE__,line= __LINE__)
     508              : 
     509              :       !-----------------------------------------------------------------
     510              :       ! write diagnostics
     511              :       !-----------------------------------------------------------------
     512              : 
     513            0 :       write(nu_diag,*) trim(plabel)
     514            0 :       write(nu_diag,*) 'istep1, i, time', &
     515            0 :                         istep1, i, time
     516            0 :       write(nu_diag,*) ' '
     517            0 :       write(nu_diag,*) 'aice0', aice0(i)
     518            0 :       do n = 1, ncat
     519            0 :          write(nu_diag,*) ' '
     520            0 :          write(nu_diag,*) 'n =',n
     521            0 :          write(nu_diag,*) 'aicen', aicen(i,n)
     522            0 :          write(nu_diag,*) 'vicen', vicen(i,n)
     523            0 :          write(nu_diag,*) 'vsnon', vsnon(i,n)
     524            0 :          if (aicen(i,n) > puny) then
     525            0 :             write(nu_diag,*) 'hin', vicen(i,n)/aicen(i,n)
     526            0 :             write(nu_diag,*) 'hsn', vsnon(i,n)/aicen(i,n)
     527              :          endif
     528            0 :          write(nu_diag,*) 'Tsfcn',trcrn(i,nt_Tsfc,n)
     529            0 :          if (tr_fsd ) write(nu_diag,*) 'afsdn',trcrn(i,nt_fsd,n)   ! fsd cat 1
     530            0 :          if (tr_snow) write(nu_diag,*) 'smice',trcrn(i,nt_smice:nt_smice+nslyr-1,n)
     531            0 :          if (tr_snow) write(nu_diag,*) 'smliq',trcrn(i,nt_smliq:nt_smliq+nslyr-1,n)
     532            0 :          write(nu_diag,*) ' '
     533              :       enddo                     ! n
     534              : 
     535            0 :       eidebug = c0
     536            0 :       do n = 1,ncat
     537            0 :          do k = 1,nilyr
     538            0 :             qi = trcrn(i,nt_qice+k-1,n)
     539            0 :             write(nu_diag,*) 'qice, cat ',n,' layer ',k, qi
     540            0 :             eidebug = eidebug + qi
     541            0 :             if (aicen(i,n) > puny) then
     542            0 :                write(nu_diag,*)  'qi/rhoi', qi/rhoi
     543              :             endif
     544              :          enddo
     545            0 :          write(nu_diag,*) ' '
     546              :       enddo
     547            0 :       write(nu_diag,*) 'qice(i)',eidebug
     548            0 :       write(nu_diag,*) ' '
     549              : 
     550            0 :       esdebug = c0
     551            0 :       do n = 1,ncat
     552            0 :          if (vsnon(i,n) > puny) then
     553            0 :             do k = 1,nslyr
     554            0 :                qs = trcrn(i,nt_qsno+k-1,n)
     555            0 :                write(nu_diag,*) 'qsnow, cat ',n,' layer ',k, qs
     556            0 :                esdebug = esdebug + qs
     557            0 :                Tsnow = (Lfresh + qs/rhos) / cp_ice
     558            0 :                write(nu_diag,*) 'qs/rhos', qs/rhos
     559            0 :                write(nu_diag,*) 'Tsnow', Tsnow
     560              :             enddo
     561            0 :             write(nu_diag,*) ' '
     562              :          endif
     563              :       enddo
     564            0 :       write(nu_diag,*) 'qsnow(i)',esdebug
     565            0 :       write(nu_diag,*) ' '
     566              : 
     567            0 :       write(nu_diag,*) 'uvel(i)',uvel(i)
     568            0 :       write(nu_diag,*) 'vvel(i)',vvel(i)
     569              : 
     570            0 :       write(nu_diag,*) ' '
     571            0 :       write(nu_diag,*) 'atm states and fluxes'
     572            0 :       write(nu_diag,*) '            uatm    = ',uatm (i)
     573            0 :       write(nu_diag,*) '            vatm    = ',vatm (i)
     574            0 :       write(nu_diag,*) '            potT    = ',potT (i)
     575            0 :       write(nu_diag,*) '            Tair    = ',Tair (i)
     576            0 :       write(nu_diag,*) '            Qa      = ',Qa   (i)
     577            0 :       write(nu_diag,*) '            rhoa    = ',rhoa (i)
     578            0 :       write(nu_diag,*) '            swvdr   = ',swvdr(i)
     579            0 :       write(nu_diag,*) '            swvdf   = ',swvdf(i)
     580            0 :       write(nu_diag,*) '            swidr   = ',swidr(i)
     581            0 :       write(nu_diag,*) '            swidf   = ',swidf(i)
     582            0 :       write(nu_diag,*) '            flw     = ',flw  (i)
     583            0 :       write(nu_diag,*) '            frain   = ',frain(i)
     584            0 :       write(nu_diag,*) '            fsnow   = ',fsnow(i)
     585            0 :       write(nu_diag,*) ' '
     586            0 :       write(nu_diag,*) 'ocn states and fluxes'
     587            0 :       write(nu_diag,*) '            frzmlt  = ',frzmlt (i)
     588            0 :       write(nu_diag,*) '            sst     = ',sst    (i)
     589            0 :       write(nu_diag,*) '            sss     = ',sss    (i)
     590            0 :       write(nu_diag,*) '            Tf      = ',Tf     (i)
     591            0 :       write(nu_diag,*) '            uocn    = ',uocn   (i)
     592            0 :       write(nu_diag,*) '            vocn    = ',vocn   (i)
     593            0 :       write(nu_diag,*) ' '
     594            0 :       write(nu_diag,*) 'srf states and fluxes'
     595            0 :       write(nu_diag,*) '            Tref    = ',Tref  (i)
     596            0 :       write(nu_diag,*) '            Qref    = ',Qref  (i)
     597            0 :       write(nu_diag,*) '            Uref    = ',Uref  (i)
     598            0 :       write(nu_diag,*) '            fsens   = ',fsens (i)
     599            0 :       write(nu_diag,*) '            flat    = ',flat  (i)
     600            0 :       write(nu_diag,*) '            evap    = ',evap  (i)
     601            0 :       write(nu_diag,*) '            flwout  = ',flwout(i)
     602            0 :       write(nu_diag,*) ' '
     603            0 :       write(nu_diag,*) 'shortwave'
     604            0 :       write(nu_diag,*) '            fsw          = ',fsw         (i)
     605            0 :       write(nu_diag,*) '            fswabs       = ',fswabs      (i)
     606            0 :       write(nu_diag,*) '            fswint_ai    = ',fswint_ai   (i)
     607            0 :       write(nu_diag,*) '            fswthru      = ',fswthru     (i)
     608            0 :       write(nu_diag,*) '            scale_factor = ',scale_factor(i)
     609            0 :       write(nu_diag,*) '            alvdr        = ',alvdr_ai    (i)
     610            0 :       write(nu_diag,*) '            alvdf        = ',alvdf_ai    (i)
     611            0 :       write(nu_diag,*) '            alidr        = ',alidr_ai    (i)
     612            0 :       write(nu_diag,*) '            alidf        = ',alidf_ai    (i)
     613            0 :       write(nu_diag,*) ' '
     614              : 
     615            0 :       call icepack_warnings_flush(nu_diag)
     616            0 :       call icedrv_system_flush(nu_diag)
     617              : 
     618            0 :       end subroutine print_state
     619              : 
     620              : !=======================================================================
     621              : 
     622              :       end module icedrv_diagnostics
     623              : 
     624              : !=======================================================================
        

Generated by: LCOV version 2.0-1