next up previous contents
Next: hist_printflds Up: Routine/Function Prologues Previous: getdatetime (Source File: getdatetime.F90)   Contents

Fortran: Module Interface histFileMod (Source File: histFileMod.F90)

Module containing methods to for CLM history file handling.


USES:

   use shr_kind_mod, only : r8 => shr_kind_r8
   use spmdMod     , only : masterproc
   use shr_sys_mod , only : shr_sys_flush
   use abortutils  , only : endrun
   use clm_varcon  , only : spval,ispval
   use clm_varctl  , only : iulog
   use clmtype     , only : gratm, grlnd, nameg, namel, namec, namep, allrof
   use decompMod   , only : get_proc_bounds, get_proc_global
   use decompMod   , only : get_proc_bounds_atm, get_proc_global_atm
 #if (defined RTM)
   use RunoffMod   , only : get_proc_rof_bounds, get_proc_rof_global
 #endif
   use ncdio_pio
   implicit none
   save
   private
PUBLIC TYPES:
   Constants
   integer , public, parameter :: max_tapes = 6          ! max number of history tapes
   integer , public, parameter :: max_flds = 1500        ! max number of history fields
   integer , public, parameter :: max_namlen = 32        ! maximum number of characters for field name
   Counters
   integer , public :: ntapes = 0         ! index of max history file requested
   Namelist
   integer :: ni                          ! implicit index below
   logical, public :: &
        hist_empty_htapes  = .false.      ! namelist: flag indicates no default history fields
   integer, public :: &
        hist_ndens(max_tapes) = 2         ! namelist: output density of netcdf history files
   integer, public :: &
        hist_mfilt(max_tapes) = 30        ! namelist: number of time samples per tape
   logical, public :: &
        hist_dov2xy(max_tapes) = (/.true.,(.true.,ni=2,max_tapes)/) ! namelist: true=> do grid averaging
   integer, public :: &
        hist_nhtfrq(max_tapes) = (/0, (-24, ni=2,max_tapes)/)        ! namelist: history write freq(0=monthly)
   character(len=1), public :: &
        hist_avgflag_pertape(max_tapes) = (/(' ',ni=1,max_tapes)/)   ! namelist: per tape averaging flag
   character(len=max_namlen), public :: &
        hist_type1d_pertape(max_tapes)  = (/(' ',ni=1,max_tapes)/)   ! namelist: per tape type1d
 
   character(len=max_namlen+2), public :: &
        fincl(max_flds,max_tapes)         ! namelist-equivalence list of fields to add
 
   character(len=max_namlen+2), public :: &
        hist_fincl1(max_flds) = ' '       ! namelist: list of fields to add
   character(len=max_namlen+2), public :: &
        hist_fincl2(max_flds) = ' '       ! namelist: list of fields to add
   character(len=max_namlen+2), public :: &
        hist_fincl3(max_flds) = ' '       ! namelist: list of fields to add
   character(len=max_namlen+2), public :: &
        hist_fincl4(max_flds) = ' '       ! namelist: list of fields to add
   character(len=max_namlen+2), public :: &
        hist_fincl5(max_flds) = ' '       ! namelist: list of fields to add
   character(len=max_namlen+2), public :: &
        hist_fincl6(max_flds) = ' '       ! namelist: list of fields to add
 
   character(len=max_namlen), public :: &
        fexcl(max_flds,max_tapes)         ! namelist-equivalence list of fields to remove
 
   character(len=max_namlen), public :: &
        hist_fexcl1(max_flds) = ' ' ! namelist: list of fields to remove
   character(len=max_namlen), public :: &
        hist_fexcl2(max_flds) = ' ' ! namelist: list of fields to remove
   character(len=max_namlen), public :: &
        hist_fexcl3(max_flds) = ' ' ! namelist: list of fields to remove
   character(len=max_namlen), public :: &
        hist_fexcl4(max_flds) = ' ' ! namelist: list of fields to remove
   character(len=max_namlen), public :: &
        hist_fexcl5(max_flds) = ' ' ! namelist: list of fields to remove
   character(len=max_namlen), public :: &
        hist_fexcl6(max_flds) = ' ' ! namelist: list of fields to remove
   Restart
   logical, private :: if_disphist(max_tapes)   ! true => save history file
PUBLIC MEMBER FUNCTIONS:
   public :: hist_addfld1d        ! Add a 1d single-level field to the master field list
   public :: hist_addfld2d        ! Add a 2d multi-level field to the master field list
   public :: hist_add_subscript   ! Add a 2d subscript dimension
   public :: hist_printflds       ! Print summary of master field list
   public :: hist_htapes_build    ! Initialize history file handler for initial or continue run
   public :: hist_update_hbuf     ! Updates history buffer for all fields and tapes
   public :: hist_htapes_wrapup   ! Write history tape(s)
   public :: hist_restart_ncd     ! Read/write history file restart data
REVISION HISTORY:
   Created by Mariana Vertenstein
PRIVATE MEMBER FUNCTIONS:
   private :: masterlist_make_active    ! Add a field to a history file default "on" list
   private :: masterlist_addfld         ! Add a field to the master field list
   private :: masterlist_change_timeavg ! Override default history tape contents for specific tape
   private :: htapes_fieldlist          ! Define the contents of each history file based on namelist
   private :: htape_addfld              ! Add a field to the active list for a history tape
   private :: htape_create              ! Define contents of history file t
   private :: htape_timeconst           ! Write time constant values to history tape
   private :: htape_timeconst3D         ! Write time constant 3D values to primary history tape
   private :: hfields_normalize         ! Normalize history file fields by number of accumulations
   private :: hfields_zero              ! Zero out accumulation and hsitory buffers for a tape
   private :: hfields_write             ! Write a variable to a history tape
   private :: hfields_1dinfo            ! Define/output 1d subgrid info if appropriate
   private :: hist_update_hbuf_field_1d ! Updates history buffer for specific field and tape
   private :: hist_update_hbuf_field_2d ! Updates history buffer for specific field and tape 
   private :: list_index                ! Find index of field in exclude list
   private :: set_hist_filename         ! Determine history dataset filenames
   private :: getname                   ! Retrieve name portion of input "inname"
   private :: getflag                   ! Retrieve flag
   private :: pointer_index             ! Track data pointer indices
   private :: max_nFields               ! The max number of fields on any tape
PRIVATE TYPES:
   Constants
   integer, parameter :: max_chars = 128        ! max chars for char variables
   Subscript dimensions
   integer, parameter :: max_subs = 100         ! max number of subscripts
   integer            :: num_subs = 0           ! actual number of subscripts
   character(len=32)  :: subs_name(max_subs)    ! name of subscript
   integer            :: subs_dim(max_subs)     ! dimension of subscript
   Derived types
   type field_info
      character(len=max_namlen) :: name         ! field name
      character(len=max_chars)  :: long_name    ! long name
      character(len=max_chars)  :: units        ! units
      character(len=8) :: type1d                ! clm pointer first dimension type
                                                ! from clmtype (nameg, etc)
      character(len=8) :: type1d_out            ! hbuf first dimension type
                                                ! from clmtype (nameg, etc)
      character(len=8) :: type2d                ! hbuf second dimension type 
                                                ! ["levgrnd","levlak","numrad","subname(n)"]
      integer :: beg1d                          ! on-node 1d clm pointer start index
      integer :: end1d                          ! on-node 1d clm pointer end index
      integer :: num1d                          ! size of clm pointer first dimension (all nodes)
      integer :: beg1d_out                      ! on-node 1d hbuf pointer start index
      integer :: end1d_out                      ! on-node 1d hbuf pointer end index
      integer :: num1d_out                      ! size of hbuf first dimension (all nodes)
      integer :: num2d                          ! size of hbuf second dimension (e.g. number of vertical levels)
      integer :: hpindex                        ! history pointer index 
      character(len=8) :: p2c_scale_type        ! scale factor when averaging pft to column
      character(len=8) :: c2l_scale_type        ! scale factor when averaging column to landunit
      character(len=8) :: l2g_scale_type        ! scale factor when averaging landunit to gridcell
   end type field_info
 
   type master_entry
      type (field_info)  :: field               ! field information
      logical            :: actflag(max_tapes)  ! active/inactive flag
      character(len=1)   :: avgflag(max_tapes)  ! time averaging flag ("X","A","M" or "I",)
   end type master_entry
 
   type history_entry
      type (field_info) :: field                ! field information
      character(len=1)  :: avgflag              ! time averaging flag
      real(r8), pointer :: hbuf(:,:)            ! history buffer (dimensions: dim1d x num2d)
      integer , pointer :: nacs(:,:)            ! accumulation counter (dimensions: dim1d x num2d)
   end type history_entry
 
   type history_tape
      integer  :: nflds                         ! number of active fields on tape
      integer  :: ntimes                        ! current number of time samples on tape
      integer  :: mfilt                         ! maximum number of time samples per tape
      integer  :: nhtfrq                        ! number of time samples per tape
      integer  :: ncprec                        ! netcdf output precision
      logical  :: dov2xy                        ! true => do xy average for all fields
      logical  :: is_endhist                    ! true => current time step is end of history interval
      real(r8) :: begtime                       ! time at beginning of history averaging interval
      type (history_entry) :: hlist(max_flds)   ! array of active history tape entries
   end type history_tape
 
   type clmpoint_rs                             ! Pointer to real scalar data (1D)
      real(r8), pointer :: ptr(:)
   end type clmpoint_rs
   type clmpoint_ra                             ! Pointer to real array data (2D)
      real(r8), pointer :: ptr(:,:)
   end type clmpoint_ra



Subsections

Erik Kluzek 2011-06-15