LCOV - code coverage report
Current view: | top level - control - cam_snapshot_common.F90 (source / functions) |  |  | Hit | Total | Coverage
Test: | coverage.info |  | Lines: | 2 | 419 | 0.5 %
Date: | 2024-12-17 22:39:59 |  | Functions: | 1 | 22 | 4.5 %

              Line data    Source code
           1             : module cam_snapshot_common
           2             : !--------------------------------------------------------
           3             : ! The purpose of this module is to handle taking the "snapshot" of CAM data.
           4             : !
           5             : ! This module writes out ALL the state, tend and pbuf fields.  It also includes the cam_in and cam_out
           6             : ! fields which are used within CAM
           7             : !--------------------------------------------------------
           8             :
           9             : use shr_kind_mod,   only: r8 => shr_kind_r8
          10             : use cam_history,    only: addfld, add_default, outfld
          11             : use cam_history,    only: cam_history_snapshot_deactivate, cam_history_snapshot_activate
          12             : use cam_history_support, only: horiz_only
          13             : use cam_abortutils, only: endrun
          14             : use physics_buffer, only: physics_buffer_desc, pbuf_get_index, pbuf_get_field, pbuf_get_field_name
          15             : use physics_types,  only: physics_state, physics_tend, physics_ptend
          16             : use camsrfexch,     only: cam_out_t, cam_in_t
          17             : use ppgrid,         only: pcols, begchunk, endchunk
          18             : use constituents,   only: pcnst
          19             : use phys_control,   only: phys_getopts
          20             : use cam_logfile,    only: iulog
          21             :
          22             : implicit  none
          23             :
          24             : private
          25             :
          26             : public :: cam_snapshot_deactivate
          27             : public :: cam_snapshot_all_outfld
          28             : public :: cam_snapshot_ptend_outfld
          29             : public :: snapshot_type
          30             : public :: cam_state_snapshot_init
          31             : public :: cam_cnst_snapshot_init
          32             : public :: cam_tend_snapshot_init
          33             : public :: cam_ptend_snapshot_init
          34             : public :: cam_in_snapshot_init
          35             : public :: cam_out_snapshot_init
          36             : public :: cam_pbuf_snapshot_init
          37             : public :: snapshot_addfld
          38             :
          39             : private :: snapshot_addfld_nd
          40             : private :: state_snapshot_all_outfld
          41             : private :: cnst_snapshot_all_outfld
          42             : private :: tend_snapshot_all_outfld
          43             : private :: cam_in_snapshot_all_outfld
          44             : private :: cam_out_snapshot_all_outfld
          45             : private :: cam_pbuf_snapshot_all_outfld
          46             : private :: fill_pbuf_info
          47             :
          48             :
          49             :
          50             : ! This is the number of pbuf fields in the CAM code that are declared with the fieldname as opposed to being data driven.
          51             : integer, parameter :: npbuf_all = 310
          52             :
          53             : type snapshot_type
          54             :   character(len=40)  :: ddt_string
          55             :   character(len=256) :: standard_name
          56             :   character(len=20)  :: dim_name
          57             :   character(len=8)   :: units
          58             : end type snapshot_type
          59             :
          60             : type snapshot_type_nd
          61             :   character(len=40)  :: ddt_string
          62             :   character(len=256) :: standard_name
          63             :   character(len=20)  :: dim_name(6) ! hardwired 6 potential dimensions in pbuf
          64             :   character(len=8)   :: units
          65             : end type snapshot_type_nd
          66             :
          67             : type pbuf_info_type
          68             :   character(len=40)  :: name
          69             :   character(len=256) :: standard_name
          70             :   character(len=8)   :: units
          71             :   character(len=100) :: dim_string(6) ! hardwired 6 potential dimensions in pbuf
          72             : end type pbuf_info_type
          73             :
          74             : integer :: nstate_var
          75             : integer :: ncnst_var
          76             : integer :: ntend_var
          77             : integer :: ncam_in_var
          78             : integer :: ncam_out_var
          79             : integer :: npbuf_var
          80             :
          81             : integer :: cam_snapshot_before_num, cam_snapshot_after_num
          82             :
          83             : ! Note the maximum number of variables for each type
          84             : type (snapshot_type)    ::  state_snapshot(29)
          85             : type (snapshot_type)    ::  cnst_snapshot(pcnst)
          86             : type (snapshot_type)    ::  tend_snapshot(6)
          87             : type (snapshot_type)    ::  cam_in_snapshot(30)
          88             : type (snapshot_type)    ::  cam_out_snapshot(30)
          89             : type (snapshot_type_nd) ::  pbuf_snapshot(300)
          90             :
          91             : contains
          92             :
          93           0 : subroutine cam_snapshot_all_outfld(file_num, state, tend, cam_in, cam_out, pbuf)
          94             :
          95             : use time_manager,   only: is_first_step
          96             :
          97             : !--------------------------------------------------------
          98             : ! This subroutine does the outfld calls for ALL state, tend and pbuf fields.  It also includes the cam_in and cam_out
          99             : ! elements which are used within CAM
         100             : !--------------------------------------------------------
         101             :
         102             :    integer,                            intent(in) :: file_num
         103             :    type(physics_state), intent(in) :: state
         104             :    type(physics_tend),  intent(in) :: tend
         105             :    type(cam_in_t),      intent(in) :: cam_in
         106             :    type(cam_out_t),     intent(in) :: cam_out
         107             :    type(physics_buffer_desc), pointer, intent(in) :: pbuf(:)
         108             :
         109             :
         110             :    integer :: lchnk
         111             :
         112             :    ! Return if the first timestep as not all fields may be filled in and this will cause a core dump
         113           0 :    if (is_first_step()) return
         114             :
         115             :    ! Return if not turned on
         116           0 :    if (cam_snapshot_before_num <= 0 .and. cam_snapshot_after_num <= 0) return ! No snapshot files are being requested
         117             :
         118           0 :    lchnk = state%lchnk
         119             :
         120             :    ! Write out all the state fields
         121           0 :    call state_snapshot_all_outfld(lchnk, file_num, state)
         122             :
         123             :    ! Write out all the constituent fields
         124           0 :    call cnst_snapshot_all_outfld(lchnk, file_num, state%q)
         125             :
         126             :    ! Write out all the tendency fields
         127           0 :    call tend_snapshot_all_outfld(lchnk, file_num, tend)
         128             :
         129             :    ! Write out all the cam_in fields
         130           0 :    call cam_in_snapshot_all_outfld(lchnk, file_num, cam_in)
         131             :
         132             :    ! Write out all the cam_out fields
         133           0 :    call cam_out_snapshot_all_outfld(lchnk, file_num, cam_out)
         134             :
         135             :    ! Write out all the pbuf fields
         136           0 :    call cam_pbuf_snapshot_all_outfld(lchnk, file_num, pbuf)
         137             :
         138           0 : end subroutine cam_snapshot_all_outfld
         139             :
         140        1536 : subroutine cam_snapshot_deactivate()
         141             :
         142             : !--------------------------------------------------------
         143             : ! This subroutine deactivates the printing of the snapshot before and after files
         144             : ! Note - this needs to be done as add_default has been called to setup the proper
         145             : !        outputting of the requested fields. The outfld calls will only write
         146             : !        one file at a time (using the same name in both files), hence the writing
         147             : !        needs to be turned off for all fields, and will be turned on individaully
         148             : !        when needed.
         149             : !--------------------------------------------------------
         150             :    integer :: i
         151             :
         152             :    ! Return if not turned on
         153        1536 :    if (cam_snapshot_before_num <= 0 .and. cam_snapshot_after_num <= 0) return ! No snapshot files are being requested
         154             :
         155           0 :    do i=1,nstate_var
         156           0 :       call cam_history_snapshot_deactivate(state_snapshot(i)%standard_name)
         157             :    end do
         158             :
         159           0 :    do i=1,ncnst_var
         160           0 :       call cam_history_snapshot_deactivate(cnst_snapshot(i)%standard_name)
         161             :    end do
         162             :
         163           0 :    do i=1,ntend_var
         164           0 :       call cam_history_snapshot_deactivate(tend_snapshot(i)%standard_name)
         165             :    end do
         166             :
         167           0 :    do i=1,ncam_in_var
         168           0 :       call cam_history_snapshot_deactivate(cam_in_snapshot(i)%standard_name)
         169             :    end do
         170             :
         171           0 :    do i=1,ncam_out_var
         172           0 :       call cam_history_snapshot_deactivate(cam_out_snapshot(i)%standard_name)
         173             :    end do
         174             :
         175           0 :    do i=1,npbuf_var
         176           0 :       call cam_history_snapshot_deactivate(pbuf_snapshot(i)%standard_name)
         177             :    end do
         178             :
         179           0 : end subroutine cam_snapshot_deactivate
         180             :
         181             :
         182           0 : subroutine cam_state_snapshot_init(cam_snapshot_before_num_in, cam_snapshot_after_num_in)
         183             :
         184             : !--------------------------------------------------------
         185             : ! This subroutine does the addfld calls for state
         186             : !--------------------------------------------------------
         187             :
         188             :    integer,intent(in) :: cam_snapshot_before_num_in, cam_snapshot_after_num_in
         189             :
         190           0 :    nstate_var = 0
         191             :
         192           0 :    cam_snapshot_before_num = cam_snapshot_before_num_in
         193           0 :    cam_snapshot_after_num  = cam_snapshot_after_num_in
         194             :
         195             :    !--------------------------------------------------------
         196             :    ! Add the state variables to the output
         197             :    !--------------------------------------------------------
         198             :
         199             :    call snapshot_addfld( nstate_var, state_snapshot,  cam_snapshot_before_num, cam_snapshot_after_num, &
         200           0 :      'state%ps',        'state_ps',         'Pa',              horiz_only)
         201             :
         202             :    call snapshot_addfld( nstate_var, state_snapshot,  cam_snapshot_before_num, cam_snapshot_after_num, &
         203           0 :      'state%psdry',     'state_psdry',      'Pa',              horiz_only)
         204             :
         205             :    call snapshot_addfld( nstate_var, state_snapshot,  cam_snapshot_before_num, cam_snapshot_after_num, &
         206           0 :      'state%phis',      'state_phis',       'm2/m2',           horiz_only)
         207             :
         208             :    call snapshot_addfld( nstate_var, state_snapshot,  cam_snapshot_before_num, cam_snapshot_after_num, &
         209           0 :      'state%t',         'state_t',          'K',               'lev')
         210             :
         211             :    call snapshot_addfld( nstate_var, state_snapshot,  cam_snapshot_before_num, cam_snapshot_after_num, &
         212           0 :      'state%u',         'state_u',          'm s-1',           'lev')
         213             :
         214             :    call snapshot_addfld( nstate_var, state_snapshot,  cam_snapshot_before_num, cam_snapshot_after_num, &
         215           0 :      'state%v',         'state_v',          'm s-1',           'lev')
         216             :
         217             :    call snapshot_addfld( nstate_var, state_snapshot,  cam_snapshot_before_num, cam_snapshot_after_num, &
         218           0 :      'state%s',         'state_s',          ' ',               'lev')
         219             :
         220             :    call snapshot_addfld( nstate_var, state_snapshot,  cam_snapshot_before_num, cam_snapshot_after_num, &
         221           0 :      'state%omega',     'state_omega',      'Pa s-1',           'lev')
         222             :
         223             :    call snapshot_addfld( nstate_var, state_snapshot,  cam_snapshot_before_num, cam_snapshot_after_num, &
         224           0 :      'state%pmid',      'state_pmid',       'Pa',               'lev')
         225             :
         226             :    call snapshot_addfld( nstate_var, state_snapshot,  cam_snapshot_before_num, cam_snapshot_after_num, &
         227           0 :      'state%pmiddry',   'state_pmiddry',    'Pa',               'lev')
         228             :
         229             :    call snapshot_addfld( nstate_var, state_snapshot,  cam_snapshot_before_num, cam_snapshot_after_num, &
         230           0 :      'state%pdel',      'state_pdel',       'Pa',               'lev')
         231             :
         232             :    call snapshot_addfld( nstate_var, state_snapshot,  cam_snapshot_before_num, cam_snapshot_after_num, &
         233           0 :      'state%pdeldry',   'state_pdeldry',    'Pa',               'lev')
         234             :
         235             :    call snapshot_addfld( nstate_var, state_snapshot,  cam_snapshot_before_num, cam_snapshot_after_num, &
         236           0 :      'state%rpdel',     'state_rpdel',      'Pa',               'lev')
         237             :
         238             :    call snapshot_addfld( nstate_var, state_snapshot,  cam_snapshot_before_num, cam_snapshot_after_num, &
         239           0 :      'state%rpdeldry',  'state_rpdeldry',   'Pa',              'lev')
         240             :
         241             :    call snapshot_addfld( nstate_var, state_snapshot,  cam_snapshot_before_num, cam_snapshot_after_num, &
         242           0 :      'state%lnpmid',    'state_lnpmid',     'unset',           'lev')
         243             :
         244             :    call snapshot_addfld( nstate_var, state_snapshot,  cam_snapshot_before_num, cam_snapshot_after_num, &
         245           0 :      'state%lnpmiddry', 'state_lnpmiddry',  'unset',           'lev')
         246             :
         247             :    call snapshot_addfld( nstate_var, state_snapshot,  cam_snapshot_before_num, cam_snapshot_after_num, &
         248           0 :      'state%exner',     'state_exner',      'unset',            'lev')
         249             :
         250             :    call snapshot_addfld( nstate_var, state_snapshot,  cam_snapshot_before_num, cam_snapshot_after_num, &
         251           0 :      'state%zm',        'state_zm',         'm',                'lev')
         252             :
         253             :    call snapshot_addfld( nstate_var, state_snapshot,  cam_snapshot_before_num, cam_snapshot_after_num, &
         254           0 :      'state%pint',      'state_pint',       'Pa',               'ilev')
         255             :
         256             :    call snapshot_addfld( nstate_var, state_snapshot,  cam_snapshot_before_num, cam_snapshot_after_num, &
         257           0 :      'state%pintdry',   'state_pintdry',    'Pa',               'ilev')
         258             :
         259             :    call snapshot_addfld( nstate_var, state_snapshot,  cam_snapshot_before_num, cam_snapshot_after_num, &
         260           0 :      'state%lnpint',    'state_lnpint',     'unset',            'ilev')
         261             :
         262             :    call snapshot_addfld( nstate_var, state_snapshot,  cam_snapshot_before_num, cam_snapshot_after_num, &
         263           0 :      'state%lnpintdry', 'state_lnpintdry',  'unset',            'ilev')
         264             :
         265             :    call snapshot_addfld( nstate_var, state_snapshot,  cam_snapshot_before_num, cam_snapshot_after_num, &
         266           0 :      'state%zi',        'state_zi',         'm',                'ilev')
         267             :
         268             :    call snapshot_addfld( nstate_var, state_snapshot,  cam_snapshot_before_num, cam_snapshot_after_num, &
         269           0 :      'state%te_ini_phys', 'state_te_ini_phys',  'unset',            horiz_only)
         270             :
         271             :    call snapshot_addfld( nstate_var, state_snapshot,  cam_snapshot_before_num, cam_snapshot_after_num, &
         272           0 :      'state%te_cur_phys', 'state_te_cur_phys',  'unset',            horiz_only)
         273             :
         274             :    call snapshot_addfld( nstate_var, state_snapshot,  cam_snapshot_before_num, cam_snapshot_after_num, &
         275           0 :      'state%tw_ini', 'state_tw_ini',  'unset',                      horiz_only)
         276             :
         277             :    call snapshot_addfld( nstate_var, state_snapshot,  cam_snapshot_before_num, cam_snapshot_after_num, &
         278           0 :      'state%tw_cur', 'state_tw_cur',  'unset',                      horiz_only)
         279             :
         280             :    call snapshot_addfld( nstate_var, state_snapshot,  cam_snapshot_before_num, cam_snapshot_after_num, &
         281           0 :      'state%te_ini_dyn',  'state_te_ini_dyn',   'unset',            horiz_only)
         282             :
         283             :    call snapshot_addfld( nstate_var, state_snapshot,  cam_snapshot_before_num, cam_snapshot_after_num, &
         284           0 :      'state%te_cur_dyn',  'state_te_cur_dyn',   'unset',            horiz_only)
         285             :
         286           0 : end subroutine cam_state_snapshot_init
         287             :
         288           0 : subroutine cam_cnst_snapshot_init(cam_snapshot_before_num, cam_snapshot_after_num)
         289             :
         290             : !--------------------------------------------------------
         291             : ! This subroutine does the addfld calls for state constituent (q) fields
         292             : !--------------------------------------------------------
         293             :
         294             :    use constituents, only: cnst_name, cnst_longname
         295             :
         296             :    integer, intent(in) :: cam_snapshot_before_num, cam_snapshot_after_num
         297             :
         298             :    !--------------------------------------------------------
         299             :    ! Add the cnst variables to the output
         300             :    !--------------------------------------------------------
         301             :
         302           0 :    ncnst_var = 0 ! Updated inside snapshot_addfld
         303             :
         304           0 :    do while (ncnst_var < pcnst)
         305             :       call snapshot_addfld(ncnst_var, cnst_snapshot, cam_snapshot_before_num, &
         306           0 :            cam_snapshot_after_num, cnst_name(ncnst_var+1),                    &
         307           0 :            trim('cnst_'//cnst_name(ncnst_var+1)), 'kg kg-1', 'lev')
         308             :    end do
         309             :
         310           0 : end subroutine cam_cnst_snapshot_init
         311             :
         312           0 : subroutine cam_tend_snapshot_init(cam_snapshot_before_num, cam_snapshot_after_num)
         313             :
         314             : !--------------------------------------------------------
         315             : ! This subroutine does the addfld calls for tend fields.
         316             : !--------------------------------------------------------
         317             :
         318             :    integer,intent(in) :: cam_snapshot_before_num, cam_snapshot_after_num
         319             :
         320           0 :    ntend_var = 0
         321             :
         322             :    !--------------------------------------------------------
         323             :    ! Add the physics_tend variables to the output
         324             :    !--------------------------------------------------------
         325             :
         326             :    call snapshot_addfld( ntend_var, tend_snapshot,  cam_snapshot_before_num, cam_snapshot_after_num, &
         327           0 :      'tend%dtdt',        'tend_dtdt',         'K s-1',    'lev')
         328             :
         329             :    call snapshot_addfld( ntend_var, tend_snapshot,  cam_snapshot_before_num, cam_snapshot_after_num, &
         330           0 :      'tend%dudt',        'tend_dudt',         '',    'lev')
         331             :
         332             :    call snapshot_addfld( ntend_var, tend_snapshot,  cam_snapshot_before_num, cam_snapshot_after_num, &
         333           0 :      'tend%dvdt',        'tend_dvdt',         '',    'lev')
         334             :
         335             :    call snapshot_addfld( ntend_var, tend_snapshot,  cam_snapshot_before_num, cam_snapshot_after_num, &
         336           0 :      'tend%flx_net',        'tend_flx_net',   '',    horiz_only)
         337             :
         338             :    call snapshot_addfld( ntend_var, tend_snapshot,  cam_snapshot_before_num, cam_snapshot_after_num, &
         339           0 :      'tend%te_tnd',        'tend_te_tnd',   '',    horiz_only)
         340             :
         341             :    call snapshot_addfld( ntend_var, tend_snapshot,  cam_snapshot_before_num, cam_snapshot_after_num, &
         342           0 :      'tend%tw_tnd',        'tend_tw_tnd',   '',    horiz_only)
         343             :
         344           0 : end subroutine cam_tend_snapshot_init
         345             :
         346           0 : subroutine cam_ptend_snapshot_init(cam_snapshot_after_num)
         347             :    use constituents, only: cnst_name, cnst_longname
         348             :
         349             :    !--------------------------------------------------------
         350             :    ! This subroutine does the addfld calls for ptend fields.
         351             :    !--------------------------------------------------------
         352             :
         353             :    integer,intent(in) :: cam_snapshot_after_num
         354             :
         355             :    integer            :: mcnst
         356             :    character(len=64)  :: fname
         357             :    character(len=128) :: lname
         358             :    character(len=32)  :: cam_take_snapshot_before
         359             :    character(len=32)  :: cam_take_snapshot_after
         360             :
         361             :    call phys_getopts(cam_take_snapshot_before_out = cam_take_snapshot_before, &
         362           0 :         cam_take_snapshot_after_out = cam_take_snapshot_after)
         363             :
         364           0 :    if (trim(cam_take_snapshot_before) == trim(cam_take_snapshot_after)) then
         365             :
         366             :       !--------------------------------------------------------
         367             :       ! Add the physics_ptend variables to the output
         368             :       !--------------------------------------------------------
         369             :
         370             :       call addfld('ptend_s', (/ 'lev' /), 'I', 'J kg-1 s-1',         &
         371           0 :            'heating rate snapshot')
         372           0 :       call add_default('ptend_s', cam_snapshot_after_num, ' ')
         373             :
         374             :       call addfld('ptend_u', (/ 'lev' /), 'I', 'm s-1 s-1',          &
         375           0 :            'momentum tendency snapshot')
         376           0 :       call add_default('ptend_u', cam_snapshot_after_num, ' ')
         377             :
         378             :       call addfld('ptend_v', (/ 'lev' /), 'I', 'm s-1 s-1',          &
         379           0 :            'momentum tendency snapshot')
         380           0 :       call add_default('ptend_v', cam_snapshot_after_num, ' ')
         381             :
         382             :       call addfld('ptend_hflux_srf', horiz_only, 'I', 'W m-2',       &
         383           0 :            'net zonal stress at surface snapshot')
         384           0 :       call add_default('ptend_hflux_srf', cam_snapshot_after_num, ' ')
         385             :
         386             :       call addfld('ptend_hflux_top', horiz_only, 'I', 'W m-2',       &
         387           0 :            'net zonal stress at top of model snapshot')
         388           0 :       call add_default('ptend_hflux_top', cam_snapshot_after_num, ' ')
         389             :
         390             :       call addfld('ptend_taux_srf', horiz_only, 'I', 'Pa',           &
         391           0 :            'net meridional stress at surface snapshot')
         392           0 :       call add_default('ptend_taux_srf', cam_snapshot_after_num, ' ')
         393             :
         394             :       call addfld('ptend_taux_top', horiz_only, 'I', 'Pa',           &
         395           0 :            'net zonal stress at top of model snapshot')
         396           0 :       call add_default('ptend_taux_top', cam_snapshot_after_num, ' ')
         397             :
         398             :       call addfld('ptend_tauy_srf', horiz_only, 'I', 'Pa',           &
         399           0 :            'net meridional stress at surface snapshot')
         400           0 :       call add_default('ptend_tauy_srf', cam_snapshot_after_num, ' ')
         401             :
         402             :       call addfld('ptend_tauy_top', horiz_only, 'I', 'Pa',           &
         403           0 :            'net meridional stress at top of model snapshot')
         404           0 :       call add_default('ptend_tauy_top', cam_snapshot_after_num, ' ')
         405             :
         406           0 :       do mcnst = 1, pcnst
         407           0 :          fname = 'ptend_'//trim(cnst_name(mcnst))
         408           0 :          lname = 'tendency of '//trim(cnst_longname(mcnst))
         409           0 :          call addfld(trim(fname), (/ 'lev' /), 'I', 'kg kg-1 s-1', trim(lname))
         410           0 :          call add_default(trim(fname), cam_snapshot_after_num, ' ')
         411             :
         412           0 :          fname = 'ptend_cflx_srf_'//trim(cnst_name(mcnst))
         413           0 :          lname = 'flux of '//trim(cnst_longname(mcnst))//' at surface snapshot'
         414           0 :          call addfld(trim(fname), horiz_only, 'I', 'kg m-2 s-1', trim(lname))
         415           0 :          call add_default(trim(fname), cam_snapshot_after_num, ' ')
         416             :
         417           0 :          fname = 'ptend_cflx_top_'//trim(cnst_name(mcnst))
         418           0 :          lname = 'flux of '//trim(cnst_longname(mcnst))//' at top of model snapshot'
         419           0 :          call addfld(trim(fname), horiz_only, 'I', 'kg m-2 s-1', trim(lname))
         420           0 :          call add_default(trim(fname), cam_snapshot_after_num, ' ')
         421             :       end do
         422             :
         423             :    end if
         424             :
         425           0 : end subroutine cam_ptend_snapshot_init
         426             :
         427           0 : subroutine cam_in_snapshot_init(cam_snapshot_before_num, cam_snapshot_after_num, cam_in)
         428             :
         429             : !--------------------------------------------------------
         430             : ! This subroutine does the addfld calls for cam_in fields
         431             : !--------------------------------------------------------
         432             :
         433             :    type(cam_in_t), intent(in) :: cam_in
         434             :
         435             :    integer,intent(in) :: cam_snapshot_before_num, cam_snapshot_after_num
         436             :
         437           0 :    ncam_in_var = 0
         438             :
         439             :    !--------------------------------------------------------
         440             :    ! Add the state variables to the output
         441             :    !--------------------------------------------------------
         442             :
         443             :    call snapshot_addfld( ncam_in_var, cam_in_snapshot,  cam_snapshot_before_num, cam_snapshot_after_num, &
         444           0 :      'cam_in%landfrac',        'cam_in_landfrac',          'unset',          horiz_only)
         445             :
         446             :    call snapshot_addfld( ncam_in_var, cam_in_snapshot,  cam_snapshot_before_num, cam_snapshot_after_num, &
         447           0 :      'cam_in%ocnfrac',         'cam_in_ocnfrac',           'unset',          horiz_only)
         448             :
         449             :    call snapshot_addfld( ncam_in_var, cam_in_snapshot,  cam_snapshot_before_num, cam_snapshot_after_num, &
         450           0 :      'cam_in%snowhland',       'cam_in_snowhland',         'unset',          horiz_only)
         451             :
         452             :    call snapshot_addfld( ncam_in_var, cam_in_snapshot,  cam_snapshot_before_num, cam_snapshot_after_num, &
         453           0 :      'cam_in%ts',              'cam_in_ts',                'unset',          horiz_only)
         454             :
         455             :    call snapshot_addfld( ncam_in_var, cam_in_snapshot,  cam_snapshot_before_num, cam_snapshot_after_num, &
         456           0 :      'cam_in%sst',             'cam_in_sst',               'unset',          horiz_only)
         457             :
         458             :    call snapshot_addfld( ncam_in_var, cam_in_snapshot,  cam_snapshot_before_num, cam_snapshot_after_num, &
         459           0 :      'cam_in%icefrac',         'cam_in_icefrac',           'unset',          horiz_only)
         460             :
         461             :    call snapshot_addfld( ncam_in_var, cam_in_snapshot,  cam_snapshot_before_num, cam_snapshot_after_num, &
         462           0 :      'cam_in%shf',             'cam_in_shf',               'unset',          horiz_only)
         463             :
         464             :    call snapshot_addfld( ncam_in_var, cam_in_snapshot,  cam_snapshot_before_num, cam_snapshot_after_num, &
         465           0 :      'cam_in%cflx',            'cam_in_cflx',              'unset',          horiz_only)
         466             :
         467             :    call snapshot_addfld( ncam_in_var, cam_in_snapshot,  cam_snapshot_before_num, cam_snapshot_after_num, &
         468           0 :      'cam_in%wsx',             'cam_in_wsx',               'unset',          horiz_only)
         469             :
         470             :    call snapshot_addfld( ncam_in_var, cam_in_snapshot,  cam_snapshot_before_num, cam_snapshot_after_num, &
         471           0 :      'cam_in%wsy',             'cam_in_wsy',               'unset',          horiz_only)
         472             :
         473             :    call snapshot_addfld( ncam_in_var, cam_in_snapshot,  cam_snapshot_before_num, cam_snapshot_after_num, &
         474           0 :      'cam_in%asdif',           'cam_in_asdif',             'unset',          horiz_only)
         475             :
         476             :    call snapshot_addfld( ncam_in_var, cam_in_snapshot,  cam_snapshot_before_num, cam_snapshot_after_num, &
         477           0 :      'cam_in%aldif',           'cam_in_aldif',             'unset',          horiz_only)
         478             :
         479             :    call snapshot_addfld( ncam_in_var, cam_in_snapshot,  cam_snapshot_before_num, cam_snapshot_after_num, &
         480           0 :      'cam_in%lwup',            'cam_in_lwup',              'unset',          horiz_only)
         481             :
         482             :    call snapshot_addfld( ncam_in_var, cam_in_snapshot,  cam_snapshot_before_num, cam_snapshot_after_num, &
         483           0 :      'cam_in%asdir',           'cam_in_asdir',             'unset',          horiz_only)
         484             :
         485             :    call snapshot_addfld( ncam_in_var, cam_in_snapshot,  cam_snapshot_before_num, cam_snapshot_after_num, &
         486           0 :      'cam_in%aldir',           'cam_in_aldir',             'unset',          horiz_only)
         487             :
         488           0 :     if (associated (cam_in%meganflx)) &
         489             :     call snapshot_addfld( ncam_in_var, cam_in_snapshot,  cam_snapshot_before_num, cam_snapshot_after_num, &
         490           0 :       'cam_in%meganflx',        'cam_in_meganflx',          'unset',          horiz_only)
         491             :
         492           0 :     if (associated (cam_in%fireflx)) &
         493             :     call snapshot_addfld( ncam_in_var, cam_in_snapshot,  cam_snapshot_before_num, cam_snapshot_after_num, &
         494           0 :       'cam_in%fireflx',         'cam_in_fireflx',           'unset',          horiz_only)
         495             :
         496           0 :     if (associated (cam_in%fireztop)) &
         497             :     call snapshot_addfld( ncam_in_var, cam_in_snapshot,  cam_snapshot_before_num, cam_snapshot_after_num, &
         498           0 :       'cam_in%fireztop',        'cam_in_fireztop',          'unset',          horiz_only)
         499             :
         500           0 :     if (associated (cam_in%depvel)) &
         501             :     call snapshot_addfld( ncam_in_var, cam_in_snapshot,  cam_snapshot_before_num, cam_snapshot_after_num, &
         502           0 :       'cam_in%depvel',          'cam_in_depvel',            'unset',          horiz_only)
         503             :
         504             :    call snapshot_addfld( ncam_in_var, cam_in_snapshot,  cam_snapshot_before_num, cam_snapshot_after_num, &
         505           0 :      'cam_in%lhf',             'cam_in_lhf',               'unset',          horiz_only)
         506             :
         507           0 :     if (associated (cam_in%fv)) &
         508             :     call snapshot_addfld( ncam_in_var, cam_in_snapshot,  cam_snapshot_before_num, cam_snapshot_after_num, &
         509           0 :       'cam_in%fv',              'cam_in_fv',                'unset',          horiz_only)
         510             :
         511           0 :     if (associated (cam_in%ram1)) &
         512             :     call snapshot_addfld( ncam_in_var, cam_in_snapshot,  cam_snapshot_before_num, cam_snapshot_after_num, &
         513           0 :       'cam_in%ram1',            'cam_in_ram1',              'unset',          horiz_only)
         514             :
         515           0 :     if (associated (cam_in%dstflx)) &
         516             :     call snapshot_addfld( ncam_in_var, cam_in_snapshot,  cam_snapshot_before_num, cam_snapshot_after_num, &
         517           0 :       'cam_in%dstflx',          'cam_in_dstflx',            'unset',          horiz_only)
         518             :
         519           0 : end subroutine cam_in_snapshot_init
         520             :
         521           0 : subroutine cam_out_snapshot_init(cam_snapshot_before_num, cam_snapshot_after_num, cam_out)
         522             :
         523             : !--------------------------------------------------------
         524             : ! This subroutine does the addfld calls for cam_out fields
         525             : !--------------------------------------------------------
         526             :
         527             :    type(cam_out_t),  intent(in) :: cam_out
         528             :
         529             :    integer,          intent(in) :: cam_snapshot_before_num, cam_snapshot_after_num
         530             :
         531           0 :    ncam_out_var = 0
         532             :
         533             :    !--------------------------------------------------------
         534             :    ! Add the state variables to the output
         535             :    !--------------------------------------------------------
         536             :
         537             :    call snapshot_addfld( ncam_out_var, cam_out_snapshot,  cam_snapshot_before_num, cam_snapshot_after_num, &
         538           0 :      'cam_out%precc',               'cam_out_precc',           'm s-1',          horiz_only)
         539             :
         540             :    call snapshot_addfld( ncam_out_var, cam_out_snapshot,  cam_snapshot_before_num, cam_snapshot_after_num, &
         541           0 :      'cam_out%precl',               'cam_out_precl',           'm s-1',          horiz_only)
         542             :
         543             :    call snapshot_addfld( ncam_out_var, cam_out_snapshot,  cam_snapshot_before_num, cam_snapshot_after_num, &
         544           0 :      'cam_out%precsc',               'cam_out_precsc',         'm s-1',          horiz_only)
         545             :
         546             :    call snapshot_addfld( ncam_out_var, cam_out_snapshot,  cam_snapshot_before_num, cam_snapshot_after_num, &
         547           0 :      'cam_out%precsl',               'cam_out_precsl',         'm s-1',          horiz_only)
         548             :
         549           0 :    if (associated(cam_out%nhx_nitrogen_flx)) &
         550             :    call snapshot_addfld( ncam_out_var, cam_out_snapshot,  cam_snapshot_before_num, cam_snapshot_after_num, &
         551           0 :      'cam_out%nhx_nitrogen_flx',     'cam_out_nhx_nitrogen_flx',  'kgN m2-1 sec-1', horiz_only)
         552             :
         553           0 :    if (associated(cam_out%noy_nitrogen_flx)) &
         554             :    call snapshot_addfld( ncam_out_var, cam_out_snapshot,  cam_snapshot_before_num, cam_snapshot_after_num, &
         555           0 :      'cam_out%noy_nitrogen_flx',     'cam_out_noy_nitrogen_flx',  'kgN m2-1 sec-1', horiz_only)
         556             :
         557             :    call snapshot_addfld( ncam_out_var, cam_out_snapshot,  cam_snapshot_before_num, cam_snapshot_after_num, &
         558           0 :      'cam_out%bcphodry',             'cam_out_bcphodry',       'kg m-2 s-1',     horiz_only)
         559             :
         560             :    call snapshot_addfld( ncam_out_var, cam_out_snapshot,  cam_snapshot_before_num, cam_snapshot_after_num, &
         561           0 :      'cam_out%bcphidry',             'cam_out_bcphidry',       'kg m-2 s-1',     horiz_only)
         562             :
         563             :    call snapshot_addfld( ncam_out_var, cam_out_snapshot,  cam_snapshot_before_num, cam_snapshot_after_num, &
         564           0 :      'cam_out%ocphodry',             'cam_out_ocphodry',       'kg m-2 s-1',     horiz_only)
         565             :
         566             :    call snapshot_addfld( ncam_out_var, cam_out_snapshot,  cam_snapshot_before_num, cam_snapshot_after_num, &
         567           0 :      'cam_out%ocphidry',             'cam_out_ocphidry',       'kg m-2 s-1',     horiz_only)
         568             :
         569             :    call snapshot_addfld( ncam_out_var, cam_out_snapshot,  cam_snapshot_before_num, cam_snapshot_after_num, &
         570           0 :      'cam_out%bcphiwet',             'cam_out_bcphiwet',       'kg m-2 s-1',     horiz_only)
         571             :
         572             :    call snapshot_addfld( ncam_out_var, cam_out_snapshot,  cam_snapshot_before_num, cam_snapshot_after_num, &
         573           0 :      'cam_out%ocphiwet',             'cam_out_ocphiwet',       'kg m-2 s-1',     horiz_only)
         574             :
         575             :    call snapshot_addfld( ncam_out_var, cam_out_snapshot,  cam_snapshot_before_num, cam_snapshot_after_num, &
         576           0 :      'cam_out%dstwet1',             'cam_out_dstwet1',         'kg m-2 s-1',     horiz_only)
         577             :
         578             :    call snapshot_addfld( ncam_out_var, cam_out_snapshot,  cam_snapshot_before_num, cam_snapshot_after_num, &
         579           0 :      'cam_out%dstwet2',             'cam_out_dstwet2',         'kg m-2 s-1',     horiz_only)
         580             :
         581             :    call snapshot_addfld( ncam_out_var, cam_out_snapshot,  cam_snapshot_before_num, cam_snapshot_after_num, &
         582           0 :      'cam_out%dstwet3',             'cam_out_dstwet3',         'kg m-2 s-1',     horiz_only)
         583             :
         584             :    call snapshot_addfld( ncam_out_var, cam_out_snapshot,  cam_snapshot_before_num, cam_snapshot_after_num, &
         585           0 :      'cam_out%dstwet4',             'cam_out_dstwet4',         'kg m-2 s-1',     horiz_only)
         586             :
         587             :    call snapshot_addfld( ncam_out_var, cam_out_snapshot,  cam_snapshot_before_num, cam_snapshot_after_num, &
         588           0 :      'cam_out%dstdry1',             'cam_out_dstdry1',         'kg m-2 s-1',     horiz_only)
         589             :
         590             :    call snapshot_addfld( ncam_out_var, cam_out_snapshot,  cam_snapshot_before_num, cam_snapshot_after_num, &
         591           0 :      'cam_out%dstdry2',             'cam_out_dstdry2',         'kg m-2 s-1',     horiz_only)
         592             :
         593             :    call snapshot_addfld( ncam_out_var, cam_out_snapshot,  cam_snapshot_before_num, cam_snapshot_after_num, &
         594           0 :      'cam_out%dstdry3',             'cam_out_dstdry3',         'kg m-2 s-1',     horiz_only)
         595             :
         596             :    call snapshot_addfld( ncam_out_var, cam_out_snapshot,  cam_snapshot_before_num, cam_snapshot_after_num, &
         597           0 :      'cam_out%dstdry4',             'cam_out_dstdry4',         'kg m-2 s-1',     horiz_only)
         598             :
         599             :    call snapshot_addfld( ncam_out_var, cam_out_snapshot,  cam_snapshot_before_num, cam_snapshot_after_num, &
         600           0 :      'cam_out%sols',                'cam_out_sols',            'W m-2',          horiz_only)
         601             :
         602             :    call snapshot_addfld( ncam_out_var, cam_out_snapshot,  cam_snapshot_before_num, cam_snapshot_after_num, &
         603           0 :      'cam_out%soll',                'cam_out_soll',            'W m-2',          horiz_only)
         604             :
         605             :    call snapshot_addfld( ncam_out_var, cam_out_snapshot,  cam_snapshot_before_num, cam_snapshot_after_num, &
         606           0 :      'cam_out%solsd',               'cam_out_solsd',           'W m-2',          horiz_only)
         607             :
         608             :    call snapshot_addfld( ncam_out_var, cam_out_snapshot,  cam_snapshot_before_num, cam_snapshot_after_num, &
         609           0 :      'cam_out%solld',               'cam_out_solld',           'W m-2',          horiz_only)
         610             :
         611             :    call snapshot_addfld( ncam_out_var, cam_out_snapshot,  cam_snapshot_before_num, cam_snapshot_after_num, &
         612           0 :      'cam_out%netsw',               'cam_out_netsw',           'unset',          horiz_only)
         613             :
         614           0 : end subroutine cam_out_snapshot_init
         615             :
         616           0 : subroutine cam_pbuf_snapshot_init(cam_snapshot_before_num, cam_snapshot_after_num, pbuf)
         617             :
         618             : !--------------------------------------------------------
         619             : ! This subroutine does the addfld calls for pbuf fields.
         620             : !--------------------------------------------------------
         621             :
         622             :    use physics_buffer, only: pbuf_get_dim_strings
         623             :
         624             :    integer,                   intent(in) :: cam_snapshot_before_num, cam_snapshot_after_num
         625             :    type(physics_buffer_desc), intent(in) :: pbuf(:)
         626             :
         627             :    integer :: i, j, npbuf
         628           0 :    type(pbuf_info_type) :: pbuf_info(size(pbuf))
         629           0 :    character(len=40) :: const_cname(ncnst_var)
         630           0 :    character(len=40) :: dim_strings(size(pbuf),6) ! Hardwired 6 potential dimensions in pbuf
         631             :
         632           0 :    npbuf = size(pbuf(:))
         633             :
         634             :    !--------------------------------------------------------
         635             :    ! fill the name, standard name and units for pbuf_info
         636             :    !--------------------------------------------------------
         637             :
         638           0 :    call fill_pbuf_info(pbuf_info, pbuf, const_cname)
         639             :
         640             :    !--------------------------------------------------------
         641             :    ! Determine the indices for the addfld call based on the dimensions in the pbuf
         642             :    !--------------------------------------------------------
         643             :
         644           0 :    call pbuf_get_dim_strings(pbuf, dim_strings)
         645           0 :    do i=1, npbuf
         646             :       ! If the second dimension is empty, then this is a horiz_only field
         647           0 :       if (trim(dim_strings(i,2)) == '') then
         648           0 :          pbuf_info(i)%dim_string(1) = horiz_only
         649             :       else
         650             :          ! The first dimension is the horizontal dimension and should not be used in the addfld call
         651           0 :          do j=2,6
         652           0 :             pbuf_info(i)%dim_string(j-1) = dim_strings(i,j)
         653             :          end do
         654             :       end if
         655             :    end do
         656             :
         657             :    !--------------------------------------------------------
         658             :    ! Now that all of the information for the pbufs is stored, call the addfld
         659             :    !--------------------------------------------------------
         660           0 :    npbuf_var = 0 ! Updated inside snapshot_addfld
         661             :
         662           0 :    do while (npbuf_var < npbuf)
         663             :       call snapshot_addfld_nd( npbuf_var, pbuf_snapshot,  cam_snapshot_before_num, cam_snapshot_after_num, &
         664           0 :         pbuf_info(npbuf_var+1)%name,   pbuf_info(npbuf_var+1)%standard_name,   pbuf_info(npbuf_var+1)%units,&
         665           0 :         pbuf_info(npbuf_var+1)%dim_string)
         666             :    end do
         667             :
         668           0 : end subroutine cam_pbuf_snapshot_init
         669             :
         670           0 : subroutine snapshot_addfld_nd(nddt_var, ddt_snapshot, cam_snapshot_before_num, cam_snapshot_after_num,&
         671           0 :     ddt_string, standard_name, units, dimension_string)
         672             :
         673             :    integer,                 intent(inout)  :: nddt_var
         674             :    type (snapshot_type_nd), intent(inout) ::  ddt_snapshot(:)
         675             :
         676             :
         677             :    integer,          intent(in) :: cam_snapshot_before_num
         678             :    integer,          intent(in) :: cam_snapshot_after_num
         679             :    character(len=*), intent(in) :: ddt_string
         680             :    character(len=*), intent(in) :: standard_name
         681             :    character(len=*), intent(in) :: units
         682             :    character(len=*), intent(in) :: dimension_string(:)
         683             :
         684             :    integer :: ndims
         685             :
         686           0 :    nddt_var=nddt_var+1
         687             :
         688           0 :    if (nddt_var > size(ddt_snapshot)) &
         689           0 :       call endrun(' ERROR in snapshot_addfld: ddt_snapshot array not allocated large enough')
         690             :
         691           0 :    ndims = count(dimension_string /= '')
         692             :
         693           0 :    if (trim(dimension_string(1)) == horiz_only) then
         694           0 :       call addfld(standard_name, horiz_only, 'I', units, standard_name)
         695             :    else
         696           0 :       call addfld(standard_name, dimension_string(1:ndims), 'I', units, standard_name)
         697             :    end if
         698           0 :    if (cam_snapshot_before_num > 0) call add_default(standard_name, cam_snapshot_before_num, ' ')
         699           0 :    if (cam_snapshot_after_num > 0)  call add_default(standard_name, cam_snapshot_after_num, ' ')
         700             :
         701           0 :    ddt_snapshot(nddt_var)%ddt_string    = ddt_string
         702           0 :    ddt_snapshot(nddt_var)%standard_name = standard_name
         703           0 :    ddt_snapshot(nddt_var)%dim_name(:)   = dimension_string(:)
         704           0 :    ddt_snapshot(nddt_var)%units         = units
         705             :
         706             :
         707           0 : end subroutine snapshot_addfld_nd
         708             :
         709           0 : subroutine snapshot_addfld(nddt_var, ddt_snapshot, cam_snapshot_before_num, cam_snapshot_after_num,&
         710             :     ddt_string, standard_name, units, dimension_string)
         711             :
         712             :    integer,              intent(inout)  :: nddt_var
         713             :    type (snapshot_type), intent(inout) ::  ddt_snapshot(:)
         714             :
         715             :
         716             :    integer,          intent(in) :: cam_snapshot_before_num
         717             :    integer,          intent(in) :: cam_snapshot_after_num
         718             :    character(len=*), intent(in) :: ddt_string
         719             :    character(len=*), intent(in) :: standard_name
         720             :    character(len=*), intent(in) :: units
         721             :    character(len=*), intent(in) :: dimension_string
         722             :
         723             :
         724           0 :    nddt_var=nddt_var+1
         725             :
         726           0 :    if (nddt_var > size(ddt_snapshot)) &
         727           0 :       call endrun(' ERROR in snapshot_addfld: ddt_snapshot array not allocated large enough')
         728             :
         729           0 :    call addfld(standard_name, dimension_string, 'I', units, standard_name)
         730           0 :    if (cam_snapshot_before_num > 0) call add_default(standard_name, cam_snapshot_before_num, ' ')
         731           0 :    if (cam_snapshot_after_num > 0)  call add_default(standard_name, cam_snapshot_after_num, ' ')
         732             :
         733           0 :    ddt_snapshot(nddt_var)%ddt_string    = ddt_string
         734           0 :    ddt_snapshot(nddt_var)%standard_name = standard_name
         735           0 :    ddt_snapshot(nddt_var)%dim_name      = dimension_string
         736           0 :    ddt_snapshot(nddt_var)%units         = units
         737             :
         738             :
         739           0 : end subroutine snapshot_addfld
         740             :
         741           0 : subroutine state_snapshot_all_outfld(lchnk, file_num, state)
         742             :
         743             :    use physics_types,    only: phys_te_idx, dyn_te_idx
         744             :
         745             :    integer,              intent(in)  :: lchnk
         746             :    integer,              intent(in)  :: file_num
         747             :    type(physics_state),  intent(in)  :: state
         748             :
         749             :    integer :: i
         750             :
         751           0 :    do i=1, nstate_var
         752             :
         753             :       ! Turn on the writing for only the requested tape (file_num)
         754           0 :       call cam_history_snapshot_activate(trim(state_snapshot(i)%standard_name), file_num)
         755             :
         756             :       ! Select the state field which is being written
         757             :       select case(state_snapshot(i)%ddt_string)
         758             :
         759             :       case ('state%ps')
         760           0 :          call outfld(state_snapshot(i)%standard_name, state%ps, pcols, lchnk)
         761             :
         762             :       case ('state%psdry')
         763           0 :          call outfld(state_snapshot(i)%standard_name, state%psdry, pcols, lchnk)
         764             :
         765             :       case ('state%phis')
         766           0 :          call outfld(state_snapshot(i)%standard_name, state%phis, pcols, lchnk)
         767             :
         768             :       case ('state%t')
         769           0 :          call outfld(state_snapshot(i)%standard_name, state%t, pcols, lchnk)
         770             :
         771             :       case ('state%u')
         772           0 :          call outfld(state_snapshot(i)%standard_name, state%u, pcols, lchnk)
         773             :
         774             :       case ('state%v')
         775           0 :          call outfld(state_snapshot(i)%standard_name, state%v, pcols, lchnk)
         776             :
         777             :       case ('state%s')
         778           0 :          call outfld(state_snapshot(i)%standard_name, state%s, pcols, lchnk)
         779             :
         780             :       case ('state%omega')
         781           0 :          call outfld(state_snapshot(i)%standard_name, state%omega, pcols, lchnk)
         782             :
         783             :       case ('state%pmid')
         784           0 :          call outfld(state_snapshot(i)%standard_name, state%pmid, pcols, lchnk)
         785             :
         786             :       case ('state%pmiddry')
         787           0 :          call outfld(state_snapshot(i)%standard_name, state%pmiddry, pcols, lchnk)
         788             :
         789             :       case ('state%pdel')
         790           0 :          call outfld(state_snapshot(i)%standard_name, state%pdel, pcols, lchnk)
         791             :
         792             :       case ('state%pdeldry')
         793           0 :          call outfld(state_snapshot(i)%standard_name, state%pdeldry, pcols, lchnk)
         794             :
         795             :       case ('state%rpdel')
         796           0 :          call outfld(state_snapshot(i)%standard_name, state%rpdel, pcols, lchnk)
         797             :
         798             :       case ('state%rpdeldry')
         799           0 :          call outfld(state_snapshot(i)%standard_name, state%rpdeldry, pcols, lchnk)
         800             :
         801             :       case ('state%lnpmid')
         802           0 :          call outfld(state_snapshot(i)%standard_name, state%lnpmid, pcols, lchnk)
         803             :
         804             :       case ('state%lnpmiddry')
         805           0 :          call outfld(state_snapshot(i)%standard_name, state%lnpmiddry, pcols, lchnk)
         806             :
         807             :       case ('state%exner')
         808           0 :          call outfld(state_snapshot(i)%standard_name, state%exner, pcols, lchnk)
         809             :
         810             :       case ('state%zm')
         811           0 :          call outfld(state_snapshot(i)%standard_name, state%zm, pcols, lchnk)
         812             :
         813             :       case ('state%pint')
         814           0 :          call outfld(state_snapshot(i)%standard_name, state%pint, pcols, lchnk)
         815             :
         816             :       case ('state%pintdry')
         817           0 :          call outfld(state_snapshot(i)%standard_name, state%pintdry, pcols, lchnk)
         818             :
         819             :       case ('state%lnpint')
         820           0 :          call outfld(state_snapshot(i)%standard_name, state%lnpint, pcols, lchnk)
         821             :
         822             :       case ('state%lnpintdry')
         823           0 :          call outfld(state_snapshot(i)%standard_name, state%lnpintdry, pcols, lchnk)
         824             :
         825             :       case ('state%zi')
         826           0 :          call outfld(state_snapshot(i)%standard_name, state%zi, pcols, lchnk)
         827             :
         828             :       case ('state%te_ini_phys')
         829           0 :          call outfld(state_snapshot(i)%standard_name, state%te_ini(:, phys_te_idx), pcols, lchnk)
         830             :
         831             :       case ('state%te_cur_phys')
         832           0 :          call outfld(state_snapshot(i)%standard_name, state%te_cur(:, phys_te_idx), pcols, lchnk)
         833             :
         834             :       case ('state%tw_ini')
         835           0 :          call outfld(state_snapshot(i)%standard_name, state%tw_ini, pcols, lchnk)
         836             :
         837             :       case ('state%tw_cur')
         838           0 :          call outfld(state_snapshot(i)%standard_name, state%tw_cur, pcols, lchnk)
         839             :
         840             :       case ('state%te_ini_dyn')
         841           0 :          call outfld(state_snapshot(i)%standard_name, state%te_ini(:, dyn_te_idx), pcols, lchnk)
         842             :
         843             :       case ('state%te_cur_dyn')
         844           0 :          call outfld(state_snapshot(i)%standard_name, state%te_cur(:, dyn_te_idx), pcols, lchnk)
         845             :
         846             :       case default
         847           0 :          call endrun('ERROR in state_snapshot_all_outfld: no match found for '//trim(state_snapshot(i)%ddt_string))
         848             :
         849             :       end select
         850             :
         851           0 :       call cam_history_snapshot_deactivate(trim(state_snapshot(i)%standard_name))
         852             :
         853             :    end do
         854             :
         855           0 : end subroutine state_snapshot_all_outfld
         856             :
         857           0 : subroutine cam_snapshot_ptend_outfld(ptend, lchnk)
         858             :
         859           0 :    use constituents, only: cnst_name, cnst_longname
         860             :    !--------------------------------------------------------
         861             :    ! This subroutine does the outfld calls for ptend fields.
         862             :    !--------------------------------------------------------
         863             :
         864             :    type(physics_ptend), intent(in) :: ptend
         865             :    integer,             intent(in) :: lchnk
         866             :
         867             :    integer                         :: mcnst
         868             :    character(len=128)              :: fname
         869             :
         870             :    !--------------------------------------------------------
         871             :    ! Add the physics_ptend variables to the output
         872             :    !--------------------------------------------------------
         873             :
         874           0 :    if (ptend%ls) then
         875           0 :       call outfld('ptend_s', ptend%s, pcols, lchnk)
         876             :
         877           0 :       call outfld('ptend_hflux_srf', ptend%hflux_srf, pcols, lchnk)
         878             :
         879           0 :       call outfld('ptend_hflux_top', ptend%hflux_top, pcols, lchnk)
         880             :    end if
         881             :
         882           0 :    if (ptend%lu) then
         883           0 :       call outfld('ptend_u', ptend%u, pcols, lchnk)
         884             :
         885           0 :       call outfld('ptend_taux_srf', ptend%taux_srf, pcols, lchnk)
         886             :
         887           0 :       call outfld('ptend_taux_top', ptend%taux_top, pcols, lchnk)
         888             :    end if
         889             :
         890           0 :    if (ptend%lv) then
         891           0 :       call outfld('ptend_v', ptend%v, pcols, lchnk)
         892             :
         893           0 :       call outfld('ptend_tauy_srf', ptend%tauy_srf, pcols, lchnk)
         894             :
         895           0 :       call outfld('ptend_tauy_top', ptend%tauy_top, pcols, lchnk)
         896             :    end if
         897             :
         898           0 :    do mcnst = 1, pcnst
         899           0 :       if (ptend%lq(mcnst)) then
         900           0 :          fname = 'ptend_'//trim(cnst_name(mcnst))
         901           0 :          call outfld(trim(fname), ptend%q(:,:,mcnst), pcols, lchnk)
         902             :
         903           0 :          fname = 'ptend_cflx_srf_'//trim(cnst_name(mcnst))
         904           0 :          call outfld(trim(fname), ptend%cflx_srf(:,mcnst), pcols, lchnk)
         905             :
         906           0 :          fname = 'ptend_cflx_top_'//trim(cnst_name(mcnst))
         907           0 :          call outfld(trim(fname), ptend%cflx_top(:,mcnst), pcols, lchnk)
         908             :       end if
         909             :    end do
         910             :
         911             :
         912           0 : end subroutine cam_snapshot_ptend_outfld
         913             :
         914           0 : subroutine cnst_snapshot_all_outfld(lchnk, file_num, cnst)
         915             :
         916             :    integer,             intent(in)  :: lchnk
         917             :    integer,             intent(in)  :: file_num
         918             :    real(r8),            intent(in)  :: cnst(:,:,:)
         919             :
         920             :    integer :: i
         921             :
         922           0 :    do i=1, ncnst_var
         923             :
         924             :       ! Turn on the writing for only the requested tape (file_num)
         925           0 :       call cam_history_snapshot_activate(trim(cnst_snapshot(i)%standard_name), file_num)
         926           0 :       call outfld(cnst_snapshot(i)%standard_name, cnst(:,:,i), pcols, lchnk)
         927             :
         928             :       ! Now that the field has been written, turn off the writing for field
         929           0 :       call cam_history_snapshot_deactivate(trim(cnst_snapshot(i)%standard_name))
         930             :
         931             :    end do
         932             :
         933           0 : end subroutine cnst_snapshot_all_outfld
         934             :
         935           0 : subroutine tend_snapshot_all_outfld(lchnk, file_num, tend)
         936             :
         937             :    integer,             intent(in)  :: lchnk
         938             :    integer,             intent(in)  :: file_num
         939             :    type(physics_tend),  intent(in)  :: tend
         940             :
         941             :    integer :: i
         942             :
         943           0 :    do i=1, ntend_var
         944             :
         945             :       ! Turn on the writing for only the requested tape (file_num)
         946           0 :       call cam_history_snapshot_activate(trim(tend_snapshot(i)%standard_name), file_num)
         947             :
         948             :       ! Select the tend field which is being written
         949             :       select case(tend_snapshot(i)%ddt_string)
         950             :
         951             :       case ('tend%dtdt')
         952           0 :          call outfld(tend_snapshot(i)%standard_name, tend%dtdt, pcols, lchnk)
         953             :
         954             :       case ('tend%dudt')
         955           0 :          call outfld(tend_snapshot(i)%standard_name, tend%dudt, pcols, lchnk)
         956             :
         957             :       case ('tend%dvdt')
         958           0 :          call outfld(tend_snapshot(i)%standard_name, tend%dvdt, pcols, lchnk)
         959             :
         960             :       case ('tend%flx_net')
         961           0 :          call outfld(tend_snapshot(i)%standard_name, tend%flx_net, pcols, lchnk)
         962             :
         963             :       case ('tend%te_tnd')
         964           0 :          call outfld(tend_snapshot(i)%standard_name, tend%te_tnd, pcols, lchnk)
         965             :
         966             :       case ('tend%tw_tnd')
         967           0 :          call outfld(tend_snapshot(i)%standard_name, tend%tw_tnd, pcols, lchnk)
         968             :
         969             :       case default
         970           0 :          call endrun('ERROR in tend_snapshot_all_outfld: no match found for '//trim(tend_snapshot(i)%ddt_string))
         971             :
         972             :       end select
         973             :
         974           0 :       call cam_history_snapshot_deactivate(trim(tend_snapshot(i)%standard_name))
         975             :
         976             :    end do
         977             :
         978           0 : end subroutine tend_snapshot_all_outfld
         979             :
         980           0 : subroutine cam_in_snapshot_all_outfld(lchnk, file_num, cam_in)
         981             :
         982             :    integer,         intent(in)  :: lchnk
         983             :    integer,         intent(in)  :: file_num
         984             :    type(cam_in_t),  intent(in)  :: cam_in
         985             :
         986             :    integer :: i
         987             :
         988           0 :    do i=1, ncam_in_var
         989             :
         990             :       ! Turn on the writing for only the requested tape (file_num)
         991           0 :       call cam_history_snapshot_activate(trim(cam_in_snapshot(i)%standard_name), file_num)
         992             :
         993             :       ! Select the cam_in field which is being written
         994             :       select case(cam_in_snapshot(i)%ddt_string)
         995             :
         996             :       case ('cam_in%landfrac')
         997           0 :          call outfld(cam_in_snapshot(i)%standard_name, cam_in%landfrac, pcols, lchnk)
         998             :       case ('cam_in%ocnfrac')
         999           0 :          call outfld(cam_in_snapshot(i)%standard_name, cam_in%ocnfrac, pcols, lchnk)
        1000             :       case ('cam_in%snowhland')
        1001           0 :          call outfld(cam_in_snapshot(i)%standard_name, cam_in%snowhland, pcols, lchnk)
        1002             :       case ('cam_in%ts')
        1003           0 :          call outfld(cam_in_snapshot(i)%standard_name, cam_in%ts, pcols, lchnk)
        1004             :       case ('cam_in%sst')
        1005           0 :          call outfld(cam_in_snapshot(i)%standard_name, cam_in%sst, pcols, lchnk)
        1006             :       case ('cam_in%icefrac')
        1007           0 :          call outfld(cam_in_snapshot(i)%standard_name, cam_in%icefrac, pcols, lchnk)
        1008             :       case ('cam_in%shf')
        1009           0 :          call outfld(cam_in_snapshot(i)%standard_name, cam_in%shf, pcols, lchnk)
        1010             :       case ('cam_in%cflx')
        1011           0 :          call outfld(cam_in_snapshot(i)%standard_name, cam_in%cflx, pcols, lchnk)
        1012             :       case ('cam_in%wsx')
        1013           0 :          call outfld(cam_in_snapshot(i)%standard_name, cam_in%wsx, pcols, lchnk)
        1014             :       case ('cam_in%wsy')
        1015           0 :          call outfld(cam_in_snapshot(i)%standard_name, cam_in%wsy, pcols, lchnk)
        1016             :       case ('cam_in%asdif')
        1017           0 :          call outfld(cam_in_snapshot(i)%standard_name, cam_in%asdif, pcols, lchnk)
        1018             :       case ('cam_in%aldif')
        1019           0 :          call outfld(cam_in_snapshot(i)%standard_name, cam_in%aldif, pcols, lchnk)
        1020             :       case ('cam_in%lwup')
        1021           0 :          call outfld(cam_in_snapshot(i)%standard_name, cam_in%lwup, pcols, lchnk)
        1022             :       case ('cam_in%asdir')
        1023           0 :          call outfld(cam_in_snapshot(i)%standard_name, cam_in%asdir, pcols, lchnk)
        1024             :       case ('cam_in%aldir')
        1025           0 :          call outfld(cam_in_snapshot(i)%standard_name, cam_in%aldir, pcols, lchnk)
        1026             :       case ('cam_in%meganflx')
        1027           0 :          if (associated (cam_in%meganflx)) &
        1028           0 :          call outfld(cam_in_snapshot(i)%standard_name, cam_in%meganflx, pcols, lchnk)
        1029             :       case ('cam_in%fireflx')
        1030           0 :          if (associated (cam_in%fireflx)) &
        1031           0 :          call outfld(cam_in_snapshot(i)%standard_name, cam_in%fireflx, pcols, lchnk)
        1032             :       case ('cam_in%fireztop')
        1033           0 :          if (associated (cam_in%fireztop)) &
        1034           0 :          call outfld(cam_in_snapshot(i)%standard_name, cam_in%fireztop, pcols, lchnk)
        1035             :       case ('cam_in%depvel')
        1036           0 :          if (associated (cam_in%depvel)) &
        1037           0 :          call outfld(cam_in_snapshot(i)%standard_name, cam_in%depvel, pcols, lchnk)
        1038             :       case ('cam_in%lhf')
        1039           0 :          call outfld(cam_in_snapshot(i)%standard_name, cam_in%lhf, pcols, lchnk)
        1040             :       case ('cam_in%fv')
        1041           0 :          if (associated (cam_in%fv)) &
        1042           0 :          call outfld(cam_in_snapshot(i)%standard_name, cam_in%fv, pcols, lchnk)
        1043             :       case ('cam_in%ram1')
        1044           0 :          if (associated (cam_in%ram1)) &
        1045           0 :          call outfld(cam_in_snapshot(i)%standard_name, cam_in%ram1, pcols, lchnk)
        1046             :       case ('cam_in%dstflx')
        1047           0 :          if (associated (cam_in%dstflx)) &
        1048           0 :          call outfld(cam_in_snapshot(i)%standard_name, cam_in%dstflx, pcols, lchnk)
        1049             :
        1050             :       case default
        1051           0 :          call endrun('ERROR in cam_in_snapshot_all_outfld: no match found for '//trim(cam_in_snapshot(i)%ddt_string))
        1052             :
        1053             :       end select
        1054             :
        1055           0 :       call cam_history_snapshot_deactivate(trim(cam_in_snapshot(i)%standard_name))
        1056             :
        1057             :    end do
        1058             :
        1059           0 : end subroutine cam_in_snapshot_all_outfld
        1060             :
        1061           0 : subroutine cam_out_snapshot_all_outfld(lchnk, file_num, cam_out)
        1062             :
        1063             :    integer,         intent(in)  :: lchnk
        1064             :    integer,         intent(in)  :: file_num
        1065             :    type(cam_out_t), intent(in)  :: cam_out
        1066             :
        1067             :    integer :: i
        1068             :
        1069           0 :    do i=1, ncam_out_var
        1070             :
        1071             :       ! Turn on the writing for only the requested tape (file_num)
        1072           0 :       call cam_history_snapshot_activate(trim(cam_out_snapshot(i)%standard_name), file_num)
        1073             :
        1074             :       ! Select the cam_out field which is being written
        1075             :       select case(cam_out_snapshot(i)%ddt_string)
        1076             :
        1077             :       case ('cam_out%precc')
        1078           0 :          call outfld(cam_out_snapshot(i)%standard_name, cam_out%precc, pcols, lchnk)
        1079             :
        1080             :       case ('cam_out%precl')
        1081           0 :          call outfld(cam_out_snapshot(i)%standard_name, cam_out%precl, pcols, lchnk)
        1082             :
        1083             :       case ('cam_out%precsc')
        1084           0 :          call outfld(cam_out_snapshot(i)%standard_name, cam_out%precsc, pcols, lchnk)
        1085             :
        1086             :       case ('cam_out%precsl')
        1087           0 :          call outfld(cam_out_snapshot(i)%standard_name, cam_out%precsl, pcols, lchnk)
        1088             :
        1089             :       case ('cam_out%nhx_nitrogen_flx')
        1090           0 :          if (associated(cam_out%nhx_nitrogen_flx)) &
        1091           0 :             call outfld(cam_out_snapshot(i)%standard_name, cam_out%nhx_nitrogen_flx, pcols, lchnk)
        1092             :
        1093             :       case ('cam_out%noy_nitrogen_flx')
        1094           0 :          if (associated(cam_out%noy_nitrogen_flx)) &
        1095           0 :             call outfld(cam_out_snapshot(i)%standard_name, cam_out%noy_nitrogen_flx, pcols, lchnk)
        1096             :
        1097             :       case ('cam_out%bcphodry')
        1098           0 :          call outfld(cam_out_snapshot(i)%standard_name, cam_out%bcphodry, pcols, lchnk)
        1099             :
        1100             :       case ('cam_out%bcphidry')
        1101           0 :          call outfld(cam_out_snapshot(i)%standard_name, cam_out%bcphidry, pcols, lchnk)
        1102             :
        1103             :       case ('cam_out%ocphodry')
        1104           0 :          call outfld(cam_out_snapshot(i)%standard_name, cam_out%ocphodry, pcols, lchnk)
        1105             :
        1106             :       case ('cam_out%ocphidry')
        1107           0 :          call outfld(cam_out_snapshot(i)%standard_name, cam_out%ocphidry, pcols, lchnk)
        1108             :
        1109             :       case ('cam_out%bcphiwet')
        1110           0 :          call outfld(cam_out_snapshot(i)%standard_name, cam_out%bcphiwet, pcols, lchnk)
        1111             :
        1112             :       case ('cam_out%ocphiwet')
        1113           0 :          call outfld(cam_out_snapshot(i)%standard_name, cam_out%ocphiwet, pcols, lchnk)
        1114             :
        1115             :       case ('cam_out%dstwet1')
        1116           0 :          call outfld(cam_out_snapshot(i)%standard_name, cam_out%dstwet1, pcols, lchnk)
        1117             :
        1118             :       case ('cam_out%dstwet2')
        1119           0 :          call outfld(cam_out_snapshot(i)%standard_name, cam_out%dstwet2, pcols, lchnk)
        1120             :
        1121             :       case ('cam_out%dstwet3')
        1122           0 :          call outfld(cam_out_snapshot(i)%standard_name, cam_out%dstwet3, pcols, lchnk)
        1123             :
        1124             :       case ('cam_out%dstwet4')
        1125           0 :          call outfld(cam_out_snapshot(i)%standard_name, cam_out%dstwet4, pcols, lchnk)
        1126             :
        1127             :       case ('cam_out%dstdry1')
        1128           0 :          call outfld(cam_out_snapshot(i)%standard_name, cam_out%dstdry1, pcols, lchnk)
        1129             :
        1130             :       case ('cam_out%dstdry2')
        1131           0 :          call outfld(cam_out_snapshot(i)%standard_name, cam_out%dstdry2, pcols, lchnk)
        1132             :
        1133             :       case ('cam_out%dstdry3')
        1134           0 :          call outfld(cam_out_snapshot(i)%standard_name, cam_out%dstdry3, pcols, lchnk)
        1135             :
        1136             :       case ('cam_out%dstdry4')
        1137           0 :          call outfld(cam_out_snapshot(i)%standard_name, cam_out%dstdry4, pcols, lchnk)
        1138             :
        1139             :       case ('cam_out%sols')
        1140           0 :          call outfld(cam_out_snapshot(i)%standard_name, cam_out%sols, pcols, lchnk)
        1141             :
        1142             :       case ('cam_out%soll')
        1143           0 :          call outfld(cam_out_snapshot(i)%standard_name, cam_out%soll, pcols, lchnk)
        1144             :
        1145             :       case ('cam_out%solsd')
        1146           0 :          call outfld(cam_out_snapshot(i)%standard_name, cam_out%solsd, pcols, lchnk)
        1147             :
        1148             :       case ('cam_out%solld')
        1149           0 :          call outfld(cam_out_snapshot(i)%standard_name, cam_out%solld, pcols, lchnk)
        1150             :
        1151             :       case ('cam_out%flwds')
        1152           0 :          call outfld(cam_out_snapshot(i)%standard_name, cam_out%flwds, pcols, lchnk)
        1153             :
        1154             :       case ('cam_out%netsw')
        1155           0 :          call outfld(cam_out_snapshot(i)%standard_name, cam_out%netsw, pcols, lchnk)
        1156             :
        1157             :       case default
        1158           0 :          call endrun('ERROR in cam_out_snapshot_all_outfld: no match found for '//trim(cam_out_snapshot(i)%ddt_string))
        1159             :
        1160             :       end select
        1161             :
        1162           0 :       call cam_history_snapshot_deactivate(trim(cam_out_snapshot(i)%standard_name))
        1163             :
        1164             :    end do
        1165             :
        1166           0 : end subroutine cam_out_snapshot_all_outfld
        1167             :
        1168           0 : subroutine cam_pbuf_snapshot_all_outfld(lchnk, file_num, pbuf)
        1169             :    use physics_buffer, only: pbuf_is_used
        1170             :
        1171             :    integer,                   intent(in) :: lchnk
        1172             :    integer,                            intent(in) :: file_num
        1173             :    type(physics_buffer_desc), pointer, intent(in) :: pbuf(:)
        1174             :
        1175             :    integer :: i, pbuf_idx, ndims
        1176           0 :    real(r8), pointer, dimension(:,:)           :: tmpptr2d
        1177           0 :    real(r8), pointer, dimension(:,:,:)         :: tmpptr3d
        1178           0 :    real(r8), pointer, dimension(:,:,:,:)       :: tmpptr4d
        1179           0 :    real(r8), pointer, dimension(:,:,:,:,:)     :: tmpptr5d
        1180             :
        1181             :
        1182           0 :    do i=1, npbuf_var
        1183             :
        1184           0 :       pbuf_idx= pbuf_get_index(pbuf_snapshot(i)%ddt_string)
        1185             :
        1186           0 :       if (pbuf_is_used(pbuf(pbuf_idx))) then
        1187             :          ! Turn on the writing for only the requested tape (file_num)
        1188           0 :          call cam_history_snapshot_activate(trim(pbuf_snapshot(i)%standard_name), file_num)
        1189             :
        1190             :          ! Retrieve the pbuf data (dependent on the number of dimensions)
        1191           0 :          ndims = count(pbuf_snapshot(i)%dim_name(:) /= '')
        1192             :
        1193           0 :          select case (ndims)  ! Note that dimension 5 and 6 do not work with pbuf_get_field, so these are not used here
        1194             :
        1195             :          case (1)
        1196           0 :             call pbuf_get_field(pbuf, pbuf_idx, tmpptr2d)
        1197           0 :             call outfld(pbuf_snapshot(i)%standard_name, tmpptr2d, pcols, lchnk)
        1198             :
        1199             :          case (2)
        1200           0 :             call pbuf_get_field(pbuf, pbuf_idx, tmpptr3d)
        1201           0 :             call outfld(pbuf_snapshot(i)%standard_name, tmpptr3d, pcols, lchnk)
        1202             :
        1203             :          case (3)
        1204           0 :             call pbuf_get_field(pbuf, pbuf_idx, tmpptr3d)
        1205           0 :             call outfld(pbuf_snapshot(i)%standard_name, tmpptr4d, pcols, lchnk)
        1206             :
        1207             :          case (4)
        1208           0 :             call pbuf_get_field(pbuf, pbuf_idx, tmpptr5d)
        1209           0 :             call outfld(pbuf_snapshot(i)%standard_name, tmpptr5d, pcols, lchnk)
        1210             :
        1211             :          end select
        1212             :
        1213             :          ! Now that the field has been written, turn off the writing for field
        1214           0 :          call cam_history_snapshot_deactivate(trim(pbuf_snapshot(i)%standard_name))
        1215             :
        1216             :
        1217             :       end if
        1218             :
        1219             :    end do
        1220             :
        1221           0 : end subroutine cam_pbuf_snapshot_all_outfld
        1222             :
        1223           0 : subroutine fill_pbuf_info(pbuf_info, pbuf, const_cname)
        1224             :
        1225             : !---------------------------------------------------
        1226             : ! This subroutine exists to link the pbuf name with units.  It can be expanded to include standard_names
        1227             : ! at a later date if needed.  It is a list of all the pbuf fields that are called within CAM with actual
        1228             : ! names.
        1229             : !---------------------------------------------------
        1230             :
        1231             :      type(pbuf_info_type),   intent(inout) :: pbuf_info(:)
        1232             :      type(physics_buffer_desc), intent(in) :: pbuf(:)
        1233             :      character(len=*),          intent(in) :: const_cname(:)
        1234             :
        1235           0 :      logical, dimension(size(pbuf)) ::  found
        1236             :      character(len=24), dimension(2,npbuf_all) :: pbuf_all
        1237             :      character(len=24) :: pbuf_name
        1238             :      integer  :: i, ipbuf
        1239             :
        1240           0 :      found(:) = .false.
        1241             :
        1242             :      pbuf_all(1:2,1:100) = reshape ( (/  &
        1243             :           'ACCRE_ENHAN            ','unset                  ',&
        1244             :           'ACGCME                 ','unset                  ',&
        1245             :           'ACLDY_CEN              ','unset                  ',&
        1246             :           'ACNUM                  ','unset                  ',&
        1247             :           'ACPRECL                ','unset                  ',&
        1248             :           'AIST                   ','unset                  ',&
        1249             :           'ALST                   ','unset                  ',&
        1250             :           'am_evp_st              ','unset                  ',&
        1251             :           'AMIE_efxg              ','mW/m2                  ',&
        1252             :           'AMIE_kevg              ','keV                    ',&
        1253             :           'AST                    ','1                      ',&
        1254             :           'AurIPRateSum           ','unset                  ',&
        1255             :           'awk_PBL                ','unset                  ',&
        1256             :           'bprod                  ','unset                  ',&
        1257             :           'CC_ni                  ','unset                  ',&
        1258             :           'CC_nl                  ','unset                  ',&
        1259             :           'CC_qi                  ','unset                  ',&
        1260             :           'CC_ql                  ','unset                  ',&
        1261             :           'CC_qlst                ','unset                  ',&
        1262             :           'CC_qv                  ','unset                  ',&
        1263             :           'CC_T                   ','unset                  ',&
        1264             :           'CICEWP                 ','unset                  ',&
        1265             :           'CLDBOT                 ','1                      ',&
        1266             :           'CLDEMIS                ','unset                  ',&
        1267             :           'CLDFGRAU               ','1                      ',&
        1268             :           'CLDFSNOW               ','1                      ',&
        1269             :           'CLD                    ','unset                  ',&
        1270             :           'CLDICEINI              ','unset                  ',&
        1271             :           'CLDLIQINI              ','unset                  ',&
        1272             :           'CLDO                   ','unset                  ',&
        1273             :           'CLDTAU                 ','unset                  ',&
        1274             :           'CLDTOP                 ','1                      ',&
        1275             :           'CLIQWP                 ','unset                  ',&
        1276             :           'CLOUD_FRAC             ','unset                  ',&
        1277             :           'CLUBB_BUFFER           ','unset                  ',&
        1278             :           'CMELIQ                 ','kg/kg/s                ',&
        1279             :           'CMFMC_SH               ','unset                  ',&
        1280             :           'cmfr_det               ','kg/m2/s                ',&
        1281             :           'CONCLD                 ','fraction               ',&
        1282             :           'CRM_CLD_RAD            ','unset                  ',&
        1283             :           'CRM_DGNUMWET           ','unset                  ',&
        1284             :           'CRM_NC                 ','/kg                    ',&
        1285             :           'CRM_NC_RAD             ','unset                  ',&
        1286             :           'CRM_NG                 ','/kg                    ',&
        1287             :           'CRM_NI                 ','/kg                    ',&
        1288             :           'CRM_NI_RAD             ','unset                  ',&
        1289             :           'CRM_NR                 ','/kg                    ',&
        1290             :           'CRM_NS                 ','/kg                    ',&
        1291             :           'CRM_NS_RAD             ','unset                  ',&
        1292             :           'CRM_QAERWAT            ','unset                  ',&
        1293             :           'CRM_QC                 ','kg/kg                  ',&
        1294             :           'CRM_QC_RAD             ','unset                  ',&
        1295             :           'CRM_QG                 ','kg/kg                  ',&
        1296             :           'CRM_QI                 ','kg/kg                  ',&
        1297             :           'CRM_QI_RAD             ','unset                  ',&
        1298             :           'CRM_QN                 ','unset                  ',&
        1299             :           'CRM_QP                 ','kg/kg                  ',&
        1300             :           'CRM_QRAD               ','unset                  ',&
        1301             :           'CRM_QR                 ','kg/kg                  ',&
        1302             :           'CRM_QS                 ','kg/kg                  ',&
        1303             :           'CRM_QS_RAD             ','unset                  ',&
        1304             :           'CRM_QT                 ','unset                  ',&
        1305             :           'CRM_QV_RAD             ','unset                  ',&
        1306             :           'CRM_T                  ',' K                     ',&
        1307             :           'CRM_T_RAD              ','unset                  ',&
        1308             :           'CRM_U                  ','m/s                    ',&
        1309             :           'CRM_V                  ','m/s                    ',&
        1310             :           'CRM_W                  ','m/s                    ',&
        1311             :           'CT                     ','unset                  ',&
        1312             :           'cu_cmfr                ','kg/m2/s                ',&
        1313             :           'cuorg                  ','unset                  ',&
        1314             :           'cu_qir                 ','kg/kg                  ',&
        1315             :           'cu_qlr                 ','kg/kg                  ',&
        1316             :           'cu_qtr                 ','kg/kg                  ',&
        1317             :           'cushavg                ','m                      ',&
        1318             :           'cush                   ','m                      ',&
        1319             :           'cu_thlr                ','K                      ',&
        1320             :           'cu_trr                 ','unset                  ',&
        1321             :           'cu_ur                  ','m/s                    ',&
        1322             :           'cu_vr                  ','m/s                    ',&
        1323             :           'CV_REFFICE             ','micron                 ',&
        1324             :           'CV_REFFLIQ             ','micron                 ',&
        1325             :           'DEGRAU                 ','unset                  ',&
        1326             :           'DEI                    ','unset                  ',&
        1327             :           'delta_qt_PBL           ','unset                  ',&
        1328             :           'delta_thl_PBL          ','unset                  ',&
        1329             :           'delta_tr_PBL           ','unset                  ',&
        1330             :           'delta_u_PBL            ','unset                  ',&
        1331             :           'delta_v_PBL            ','unset                  ',&
        1332             :           'DES                    ','unset                  ',&
        1333             :           'DGNUM                  ','unset                  ',&
        1334             :           'DGNUMWET               ','unset                  ',&
        1335             :           'DIFZM                  ','kg/kg/s                ',&
        1336             :           'DLFZM                  ','kg/kg/s                ',&
        1337             :           'DNIFZM                 ','1/kg/s                 ',&
        1338             :           'DNLFZM                 ','1/kg/s                 ',&
        1339             :           'DP_FLXPRC              ','unset                  ',&
        1340             :           'DP_FLXSNW              ','unset                  ',&
        1341             :           'DP_FRAC                ','unset                  ',&
        1342           0 :           'dragblj                ','1/s                    '  /),  (/2,100/))
        1343             :
        1344             :      pbuf_all(1:2,101:200) = reshape ( (/  &
        1345             :           'DRYMASS                ','unset                  ',&
        1346             :           'DRYRAD                 ','unset                  ',&
        1347             :           'DRYVOL                 ','unset                  ',&
        1348             :           'DTCORE                 ','K/s                    ',&
        1349             :           'evprain_st             ','unset                  ',&
        1350             :           'evpsnow_st             ','unset                  ',&
        1351             :           'FICE                   ','fraction               ',&
        1352             :           'FLNS                   ','W/m2                   ',&
        1353             :           'FLNT                   ','W/m2                   ',&
        1354             :           'FRACIS                 ','unset                  ',&
        1355             :           'FRACSOA                ','unset                  ',&
        1356             :           'FRACSOG                ','unset                  ',&
        1357             :           'FRONTGA                ','unset                  ',&
        1358             :           'FRONTGF                ','K^2/M^2/S              ',&
        1359             :           'FRZCNT                 ','unset                  ',&
        1360             :           'FRZDEP                 ','unset                  ',&
        1361             :           'FRZIMM                 ','unset                  ',&
        1362             :           'FSDS                   ','W/m2                   ',&
        1363             :           'FSNS                   ','W/m2                   ',&
        1364             :           'FSNT                   ','W/m2                   ',&
        1365             :           'HallConduct            ','unset                  ',&
        1366             :           'HYGRO                  ','unset                  ',&
        1367             :           'ICCWAT                 ','unset                  ',&
        1368             :           'ICGRAUWP               ','unset                  ',&
        1369             :           'ICIWP                  ','unset                  ',&
        1370             :           'ICIWPST                ','unset                  ',&
        1371             :           'ICLWP                  ','unset                  ',&
        1372             :           'ICLWPST                ','unset                  ',&
        1373             :           'ICSWP                  ','unset                  ',&
        1374             :           'ICWMRDP                ','kg/kg                  ',&
        1375             :           'ICWMRSH                ','kg/kg                  ',&
        1376             :           'IonRates               ','unset                  ',&
        1377             :           'ipbl                   ','unset                  ',&
        1378             :           'ISS_FRAC               ','unset                  ',&
        1379             :           'kpblh                  ','unset                  ',&
        1380             :           'ksrftms                ','unset                  ',&
        1381             :           'kvh                    ','m2/s                   ',&
        1382             :           'kvm                    ','m2/s                   ',&
        1383             :           'kvt                    ','m2/s                   ',&
        1384             :           'LAMBDAC                ','unset                  ',&
        1385             :           'LANDM                  ','unset                  ',&
        1386             :           'LCWAT                  ','unset                  ',&
        1387             :           'LD                     ','unset                  ',&
        1388             :           'LHFLX                  ','W/m2                   ',&
        1389             :           'LHFLX_RES              ','unset                  ',&
        1390             :           'LS_FLXPRC              ','kg/m2/s                ',&
        1391             :           'LS_FLXSNW              ','kg/m2/s                ',&
        1392             :           'LS_MRPRC               ','unset                  ',&
        1393             :           'LS_MRSNW               ','unset                  ',&
        1394             :           'LS_REFFRAIN            ','micron                 ',&
        1395             :           'LS_REFFSNOW            ','micron                 ',&
        1396             :           'LU                     ','unset                  ',&
        1397             :           'MAMH2SO4EQ             ','unset                  ',&
        1398             :           'MU                     ','Pa/s                   ',&
        1399             :           'NAAI_HOM               ','unset                  ',&
        1400             :           'NAAI                   ','unset                  ',&
        1401             :           'NACON                  ','unset                  ',&
        1402             :           'NAER                   ','unset                  ',&
        1403             :           'NEVAPR_DPCU            ','unset                  ',&
        1404             :           'NEVAPR                 ','unset                  ',&
        1405             :           'NEVAPR_SHCU            ','unset                  ',&
        1406             :           'NIWAT                  ','unset                  ',&
        1407             :           'NLWAT                  ','unset                  ',&
        1408             :           'NMXRGN                 ','unset                  ',&
        1409             :           'NPCCN                  ','unset                  ',&
        1410             :           'NRAIN                  ','m-3                    ',&
        1411             :           'NSNOW                  ','m-3                    ',&
        1412             :           'O3                     ','unset                  ',&
        1413             :           'pblh                   ','m                      ',&
        1414             :           'PDF_PARAMS             ','unset                  ',&
        1415             :           'PDF_PARAMS_ZM          ','unset                  ',&
        1416             :           'PedConduct             ','unset                  ',&
        1417             :           'PMXRGN                 ','unset                  ',&
        1418             :           'PRAIN                  ','unset                  ',&
        1419             :           'PREC_DP                ','unset                  ',&
        1420             :           'PREC_PCW               ','m/s                    ',&
        1421             :           'PREC_SED               ','unset                  ',&
        1422             :           'PREC_SH                ','unset                  ',&
        1423             :           'PREC_SH                ','unset                  ',&
        1424             :           'PREC_STR               ','unset                  ',&
        1425             :           'PRER_EVAP              ','unset                  ',&
        1426             :           'PSL                    ','Pa                     ',&
        1427             :           'QAERWAT                ','unset                  ',&
        1428             :           'QCWAT                  ','unset                  ',&
        1429             :           'QFLX                   ','kg/m2/s                ',&
        1430             :           'QFLX_RES               ','unset                  ',&
        1431             :           'QINI                   ','unset                  ',&
        1432             :           'qir_det                ','kg/kg                  ',&
        1433             :           'QIST                   ','unset                  ',&
        1434             :           'qlr_det                ','kg/kg                  ',&
        1435             :           'QLST                   ','unset                  ',&
        1436             :           'QME                    ','unset                  ',&
        1437             :           'qpert                  ','kg/kg                  ',&
        1438             :           'QRAIN                  ','kg/kg                  ',&
        1439             :           'QRL                    ','K/s                    ',&
        1440             :           'qrlin                  ','unset                  ',&
        1441             :           'QRS                    ','K/s                    ',&
        1442             :           'qrsin                  ','unset                  ',&
        1443             :           'QSATFAC                ','-                      ',&
        1444           0 :           'QSNOW                  ','kg/kg                  '  /),    (/2,100/))
        1445             :
        1446             :      pbuf_all(1:2,201:300) = reshape ( (/  &
        1447             :           'QTeAur                 ','unset                  ',&
        1448             :           'qti_flx                ','unset                  ',&
        1449             :           'qtl_flx                ','unset                  ',&
        1450             :           'RAD_CLUBB              ','unset                  ',&
        1451             :           'RATE1_CW2PR_ST         ','unset                  ',&
        1452             :           'RCM                    ','unset                  ',&
        1453             :           'RE_ICE                 ','unset                  ',&
        1454             :           'REI                    ','micron                 ',&
        1455             :           'RELHUM                 ','percent                ',&
        1456             :           'REL                    ','micron                 ',&
        1457             :           'RELVAR                 ','-                      ',&
        1458             :           'RNDST                  ','unset                  ',&
        1459             :           'RPRDDP                 ','unset                  ',&
        1460             :           'RPRDSH                 ','unset                  ',&
        1461             :           'RPRDTOT                ','unset                  ',&
        1462             :           'RTM                    ','unset                  ',&
        1463             :           'rtp2_mc_zt             ','unset                  ',&
        1464             :           'RTP2_nadv              ','unset                  ',&
        1465             :           'rtpthlp_mc_zt          ','unset                  ',&
        1466             :           'RTPTHLP_nadv           ','unset                  ',&
        1467             :           'RTPTHVP                ','unset                  ',&
        1468             :           'SADICE                 ','cm2/cm3                ',&
        1469             :           'SADSNOW                ','cm2/cm3                ',&
        1470             :           'SADSULF                ','unset                  ',&
        1471             :           'SD                     ','unset                  ',&
        1472             :           'SGH30                  ','unset                  ',&
        1473             :           'SGH                    ','unset                  ',&
        1474             :           'SH_CLDICE              ','unset                  ',&
        1475             :           'SH_CLDLIQ              ','unset                  ',&
        1476             :           'SH_E_ED_RATIO          ','unset                  ',&
        1477             :           'SHFLX                  ','W/m2                   ',&
        1478             :           'SH_FLXPRC              ','unset                  ',&
        1479             :           'SHFLX_RES              ','unset                  ',&
        1480             :           'SH_FLXSNW              ','unset                  ',&
        1481             :           'SH_FRAC                ','unset                  ',&
        1482             :           'shfrc                  ','unset                  ',&
        1483             :           'SNOW_DP                ','unset                  ',&
        1484             :           'SNOW_PCW               ','unset                  ',&
        1485             :           'SNOW_SED               ','unset                  ',&
        1486             :           'SNOW_SH                ','unset                  ',&
        1487             :           'SNOW_STR               ','unset                  ',&
        1488             :           'SO4DRYVOL              ','unset                  ',&
        1489             :           'SSLTA                  ','kg/kg                  ',&
        1490             :           'SSLTC                  ','kg/kg                  ',&
        1491             :           'SU                     ','unset                  ',&
        1492             :           "taubljx                ",'N/m2                   ',&
        1493             :           "taubljy                ",'N/m2                   ',&
        1494             :           'tauresx                ','unset                  ',&
        1495             :           'tauresy                ','unset                  ',&
        1496             :           "tautmsx                ",'N/m2                   ',&
        1497             :           "tautmsy                ",'N/m2                   ',&
        1498             :           'TAUX                   ','N/m2                   ',&
        1499             :           'TAUX_RES               ','unset                  ',&
        1500             :           'TAUY                   ','N/m2                   ',&
        1501             :           'TAUY_RES               ','unset                  ',&
        1502             :           'tcorr                  ','unset                  ',&
        1503             :           'TCWAT                  ','unset                  ',&
        1504             :           'TElec                  ','K                      ',&
        1505             :           'TEOUT                  ','J/m2                   ',&
        1506             :           'THLM                   ','unset                  ',&
        1507             :           'thlp2_mc_zt            ','unset                  ',&
        1508             :           'THLP2_nadv             ','unset                  ',&
        1509             :           'THLPTHVP               ','unset                  ',&
        1510             :           'TIon                   ','K                      ',&
        1511             :           'TK_CRM                 ','unset                  ',&
        1512             :           'tke                    ','m2/s2                  ',&
        1513             :           'tkes                   ','m2/s2                  ',&
        1514             :           'TND_NSNOW              ','unset                  ',&
        1515             :           'TND_QSNOW              ','unset                  ',&
        1516             :           'tpert                  ','K                      ',&
        1517             :           'TREFMNAV               ','K                      ',&
        1518             :           'TREFMXAV               ','K                      ',&
        1519             :           'tropp                  ','unset                  ',&
        1520             :           'TSTCPY_SCOL            ','unset                  ',&
        1521             :           'TTEND_DP               ','unset                  ',&
        1522             :           'TTEND_SH               ','unset                  ',&
        1523             :           'T_TTEND                ','unset                  ',&
        1524             :           "UI                     ",'m/s                    ',&
        1525             :           'UM                     ','unset                  ',&
        1526             :           'UP2_nadv               ','unset                  ',&
        1527             :           'UPWP                   ','m^2/s^2                ',&
        1528             :           'UZM                    ','M/S                    ',&
        1529             :           'VI                     ','m/s                    ',&
        1530             :           'VM                     ','m/s                    ',&
        1531             :           'VOLC_MMR               ','unset                  ',&
        1532             :           'VOLC_RAD_GEOM          ','unset                  ',&
        1533             :           'VP2_nadv               ','unset                  ',&
        1534             :           'VPWP                   ','m^2/s^2                ',&
        1535             :           'went                   ','m/s                    ',&
        1536             :           'WETDENS_AP             ','unset                  ',&
        1537             :           "WI                     ",'m/s                    ',&
        1538             :           'WP3_nadv               ','unset                  ',&
        1539             :           'wprtp_mc_zt            ','unset                  ',&
        1540             :           'WPRTP_nadv             ','unset                  ',&
        1541             :           'wpthlp_mc_zt           ','unset                  ',&
        1542             :           'WPTHLP_nadv            ','unset                  ',&
        1543             :           'WPTHVP                 ','unset                  ',&
        1544             :           'WSEDL                  ','unset                  ',&
        1545             :           'wstarPBL               ','unset                  ',&
        1546           0 :           'ZM_DP                  ','unset                  '  /),                  (/2,100/))
        1547             :
        1548             :      pbuf_all(1:2,301:npbuf_all) = reshape ( (/  &
        1549             :           'ZM_DSUBCLD             ','unset                  ',&
        1550             :           'ZM_DU                  ','unset                  ',&
        1551             :           'ZM_ED                  ','unset                  ',&
        1552             :           'ZM_EU                  ','unset                  ',&
        1553             :           'ZM_IDEEP               ','unset                  ',&
        1554             :           'ZM_JT                  ','unset                  ',&
        1555             :           'ZM_MAXG                ','unset                  ',&
        1556             :           'ZM_MD                  ','unset                  ',&
        1557             :           'ZM_MU                  ','unset                  ',&
        1558           0 :           'ZTODT                  ','unset                  '  /),                     (/2,10/))
        1559             :
        1560             : ! Fields which are added with pbuf_add_field calls, but are data driven.  These are not
        1561             : ! included in the above list.  This means that these fields will not have proper units
        1562             : ! set for them
        1563             : !          'CG' // shortname,        'unset',        &
        1564             : !          'CI' // shortname,        'unset',        &
        1565             : !          'CL' // shortname,        'unset',        &
        1566             : !          ghg_names(i),             'unset',        &
        1567             : !          mmr_name1,                'unset',        &
        1568             : !          mmr_name2,                'unset',        &
        1569             : !          mmr_name3,                'unset',        &
        1570             : !          mmr_name,                 'unset',        &
        1571             : !          ozone_name,               'unset',        &
        1572             : !          pbufname,                 'unset',        &
        1573             : !          pbufname,                 'unset',        &
        1574             : !          pbuf_names(i),            'unset',        &
        1575             : !          rad_name1,                'unset',        &
        1576             : !          rad_name2,                'unset',        &
        1577             : !          rad_name3,                'unset',        &
        1578             : !          rad_name,                 'unset',        &
        1579             : !          sad_name,                 'cm2/cm3',      &
        1580             : !          volcaero_name,            'kg/kg',        &
        1581             : !          volcrad_name,             'm',            &
        1582             : !          xname_massptrcw(l,        'unset',        &
        1583             : !          xname_numptrcw,           'unset',        &
        1584             : !          aero_names(mm)
        1585             : !          cnst_names(iconst)
        1586             :
        1587           0 :    do ipbuf = 1, size(pbuf)
        1588           0 :      pbuf_name = pbuf_get_field_name(ipbuf)
        1589           0 :      i = 1
        1590           0 :      do while ((i <= npbuf_all) .and. .not. found(ipbuf))
        1591           0 :         if (trim(pbuf_all(1,i)) == trim(pbuf_name)) then
        1592           0 :            pbuf_info(ipbuf)%name          = trim(pbuf_all(1,i))
        1593           0 :            pbuf_info(ipbuf)%standard_name = 'pbuf_'//trim(pbuf_all(1,i))
        1594           0 :            pbuf_info(ipbuf)%units         = trim(pbuf_all(2,i))
        1595           0 :            pbuf_info(ipbuf)%dim_string(:) = ' '
        1596           0 :            found(ipbuf) = .true.
        1597             :        end if
        1598           0 :         i = i+1
        1599             :       end do
        1600           0 :       if (.not. found(ipbuf)) then
        1601             :
        1602             :          i = 1
        1603             :          ! Check if variable is a variation of constituent - then use the same units
        1604           0 :          do while ((i <= ncnst_var) .and. .not. found(ipbuf))
        1605           0 :             if (trim(const_cname(i)) == trim(pbuf_name)) then
        1606           0 :                pbuf_info(ipbuf) = pbuf_info_type(trim(const_cname(i)),trim('pbuf_'//const_cname(i)),&
        1607           0 :                                                  trim(cnst_snapshot(i)%units),      ' ')
        1608           0 :                found(ipbuf) = .true.
        1609             :             end if
        1610           0 :             i = i+1
        1611             :          end do
        1612             :       end if
        1613             :
        1614             :         ! Found a pbuf that has not been added to this routine
        1615           0 :       if (.not. found(ipbuf)) then
        1616           0 :          write(iulog,*) 'WARNING - no units information for: '//trim(pbuf_name)
        1617             :
        1618           0 :          pbuf_info(ipbuf)%name          = trim(pbuf_name)
        1619           0 :          pbuf_info(ipbuf)%standard_name = 'pbuf_'//trim(pbuf_name)
        1620           0 :          pbuf_info(ipbuf)%units         = 'unset'
        1621           0 :          pbuf_info(ipbuf)%dim_string(:) = ' '
        1622           0 :          found(ipbuf) = .true.
        1623             :       end if
        1624             :
        1625             :    end do
        1626             :
        1627           0 : end subroutine fill_pbuf_info
        1628             :
        1629           0 : end module cam_snapshot_common

Generated by: LCOV version 1.14