Skip to content

Commit

Permalink
Merge pull request #1325 from GEOS-ESM/feature/mathomp4/#1282-configu…
Browse files Browse the repository at this point in the history
…rable-metadata

Fixes #1282. Make History metadata configurable
  • Loading branch information
tclune authored Feb 1, 2022
2 parents ccccd31 + d15555f commit 62621e3
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 28 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed

- A small performance improvement. cycle => exit in MAPL_Generic.F90
- Made history global metadata configurable. This can be done in two ways
1. Globally for all collections by setting `COMMENT:`, `CONTACT:`, `CONVENTION:`, `INSTITUTION:`, `REFERENCES:`, and `SOURCE:` at the top of `HISTORY.rc` like `EXPDSC:`
2. On a per-collection bases by setting `collection.comment:`, `collection.contact:`, `collection.convention:`, `collection.institution:`, `collection.references:`, and `collection.source:`
- The default settings for these are to match that of MAPL 2.17.0

### Removed

Expand Down
58 changes: 35 additions & 23 deletions gridcomps/History/MAPL_HistoryCollection.F90
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,33 @@ module MAPL_HistoryCollectionMod
use HistoryTrajectoryMod
use gFTL_StringStringMap
implicit none

private

type, public :: FieldSet
character(len=ESMF_MAXSTR), pointer :: fields(:,:) => null()
integer :: nfields = 0
end type FieldSet

type, public :: HistoryCollectionGlobalAttributes
character(len=ESMF_MAXSTR) :: filename
character(len=ESMF_MAXSTR) :: descr
character(len=ESMF_MAXSTR) :: comment
character(len=ESMF_MAXSTR) :: contact
character(len=ESMF_MAXSTR) :: convention
character(len=ESMF_MAXSTR) :: institution
character(len=ESMF_MAXSTR) :: references
character(len=ESMF_MAXSTR) :: source
contains
procedure :: define_collection_attributes
end type HistoryCollectionGlobalAttributes

type, public :: HistoryCollection
character(len=ESMF_MAXSTR) :: collection
character(len=ESMF_MAXSTR) :: filename
character(len=ESMF_MAXSTR) :: template
character(len=ESMF_MAXSTR) :: format
character(len=ESMF_MAXSTR) :: mode
character(len=ESMF_MAXSTR) :: descr
integer :: frequency
integer :: acc_interval
integer :: ref_date
Expand All @@ -41,7 +53,7 @@ module MAPL_HistoryCollectionMod
integer :: unit
type(ESMF_FieldBundle) :: bundle
type(MAPL_CFIO) :: MCFIO
type(MAPL_GriddedIO) :: mGriddedIO
type(MAPL_GriddedIO) :: mGriddedIO
type(VerticalData) :: vdata
type(TimeData) :: timeInfo
real , pointer :: levels(:) => null()
Expand All @@ -61,7 +73,7 @@ module MAPL_HistoryCollectionMod
integer :: conservative
integer :: voting
integer :: nbits
integer :: deflate
integer :: deflate
integer :: slices
integer :: Root
integer :: Psize
Expand All @@ -81,43 +93,43 @@ module MAPL_HistoryCollectionMod
type(ESMF_FIELD), pointer :: r8(:) => null()
type(ESMF_FIELD), pointer :: r4(:) => null()
character(len=ESMF_MAXSTR) :: output_grid_label
type(GriddedIOItemVector) :: items
type(GriddedIOItemVector) :: items
character(len=ESMF_MAXSTR) :: currentFile
character(len=ESMF_MAXPATHLEN) :: trackFile
logical :: splitField
logical :: regex
logical :: timeseries_output = .false.
logical :: recycle_track = .false.
type(HistoryTrajectory) :: trajectory
character(len=ESMF_MAXSTR) :: positive
character(len=ESMF_MAXSTR) :: positive
type(HistoryCollectionGlobalAttributes) :: global_atts
contains
procedure :: AddGrid
procedure :: define_collection_attributes
end type HistoryCollection

contains

function define_collection_attributes(this,rc) result(global_attributes)
class(HistoryCollection), intent(inout) :: this
class(HistoryCollectionGlobalAttributes), intent(inout) :: this
integer, optional, intent(out) :: rc

type(StringStringMap) :: global_attributes
integer :: status

call global_attributes%insert("Title",trim(this%descr))
call global_attributes%insert("History","File written by MAPL_PFIO")
call global_attributes%insert("Source","unknown")
call global_attributes%insert("Contact","http://gmao.gsfc.nasa.gov")
call global_attributes%insert("Convention","CF")
call global_attributes%insert("Institution","NASA Global Modeling and Assimilation Office")
call global_attributes%insert("References","see MAPL documentation")
call global_attributes%insert("Source",trim(this%source))
call global_attributes%insert("Contact",trim(this%contact))
call global_attributes%insert("Convention",trim(this%convention))
call global_attributes%insert("Institution",trim(this%institution))
call global_attributes%insert("References",trim(this%references))
call global_attributes%insert("Filename",trim(this%filename))
call global_attributes%insert("Comment","NetCDF-4")
call global_attributes%insert("Comment",trim(this%comment))

_RETURN(_SUCCESS)
end function define_collection_attributes

subroutine AddGrid(this,output_grids,resolution,rc)
subroutine AddGrid(this,output_grids,resolution,rc)
use MAPL_GridManagerMod
use MAPL_AbstractGridFactoryMod
use MAPL_ConfigMod
Expand All @@ -130,7 +142,7 @@ subroutine AddGrid(this,output_grids,resolution,rc)
integer, intent(inout), optional :: rc

integer :: status
character(len=ESMF_MAXSTR), parameter :: Iam = "AddGrid"
character(len=*), parameter :: Iam = "AddGrid"
type(ESMF_Config) :: cfg
integer :: nx,ny,im_world,jm_world
character(len=ESMF_MAXSTR) :: tlabel
Expand All @@ -155,7 +167,7 @@ subroutine AddGrid(this,output_grids,resolution,rc)
_VERIFY(status)
call MAPL_ConfigSetAttribute(cfg,value=ny, label=trim(tlabel)//".NY:",rc=status)
_VERIFY(status)

if (resolution(2)==resolution(1)*6) then
call MAPL_ConfigSetAttribute(cfg,value="Cubed-Sphere", label=trim(tlabel)//".GRID_TYPE:",rc=status)
_VERIFY(status)
Expand All @@ -177,20 +189,20 @@ subroutine AddGrid(this,output_grids,resolution,rc)
end if
output_grid = grid_manager%make_grid(cfg,prefix=trim(tlabel)//'.',rc=status)
_VERIFY(status)

factory => grid_manager%get_factory(output_grid,rc=status)
_VERIFY(status)
this%output_grid_label = factory%generate_grid_name()
lgrid => output_grids%at(trim(this%output_grid_label))
if (.not.associated(lgrid)) call output_grids%insert(this%output_grid_label,output_grid)
if (.not.associated(lgrid)) call output_grids%insert(this%output_grid_label,output_grid)

end subroutine AddGrid

end module MAPL_HistoryCollectionMod

module MAPL_HistoryCollectionVectorMod
use MAPL_HistoryCollectionMod

#define _type type (HistoryCollection)
#define _vector HistoryCollectionVector
#define _iterator HistoryCollectionVectorIterator
Expand All @@ -200,7 +212,7 @@ module MAPL_HistoryCollectionVectorMod
#undef _iterator
#undef _vector
#undef _type

end module MAPL_HistoryCollectionVectorMod

module MAPL_StringFieldSetMapMod
Expand All @@ -218,5 +230,5 @@ module MAPL_StringFieldSetMapMod
#undef _map
#undef _value
#undef _key

end module MAPL_StringFieldSetMapMod
59 changes: 54 additions & 5 deletions gridcomps/History/MAPL_HistoryGridComp.F90
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ module MAPL_HistoryGridCompMod
use MAPL_ConfigMod
use, intrinsic :: iso_fortran_env, only: INT64
use, intrinsic :: iso_fortran_env, only: REAL32, REAL64
use MAPL_HistoryCollectionMod, only: HistoryCollection, FieldSet
use MAPL_HistoryCollectionMod, only: HistoryCollection, FieldSet, HistoryCollectionGlobalAttributes
use MAPL_HistoryCollectionVectorMod, only: HistoryCollectionVector
use MAPL_StringFieldSetMapMod, only: StringFieldSetMap
use MAPL_StringFieldSetMapMod, only: StringFieldSetMapIterator
Expand Down Expand Up @@ -101,10 +101,11 @@ module MAPL_HistoryGridCompMod
type (SpecWrapper), pointer :: SRCS(:) => null()
type (SpecWrapper), pointer :: DSTS(:) => null()
type (StringGridMap) :: output_grids
type (StringFieldSetMap) :: field_sets
type (StringFieldSetMap) :: field_sets
character(len=ESMF_MAXSTR) :: expsrc
character(len=ESMF_MAXSTR) :: expid
character(len=ESMF_MAXSTR) :: expdsc
type(HistoryCollectionGlobalAttributes) :: global_atts
integer :: CoresPerNode, mype, npes
integer :: AvoidRootNodeThreshold
integer :: blocksize
Expand Down Expand Up @@ -227,6 +228,18 @@ subroutine Initialize ( gc, import, dumexport, clock, rc )
! \item[format] Character string defining file format ("flat" or "CFIO"). Default = "flat".
! \item[mode] Character string equal to "instantaneous" or "time-averaged". Default = "instantaneous".
! \item[descr] Character string equal to the list description. Defaults to "expdsc".
! \item[commment] Character string defining a comment.
! Defaults to "NetCDF-4". Can be globally set for all collections with "COMMENT:"
! \item[contact] Character string defining a contact.
! Defaults to "http://gmao.gsfc.nasa.gov". Can be globally set for all collections with "CONTACT:"
! \item[convention] Character string defining the convention.
! Defaults to "CF". Can be globally set for all collections with "CONVENTION:"
! \item[institution] Character string defining an institution.
! Defaults to "NASA Global Modeling and Assimilation Office". Can be globally set for all collections with "INSTITUTION:"
! \item[references] Character string defining references.
! Defaults to "see MAPL documentation". Can be globally set for all collections with "REFERENCES:"
! \item[source] Character string defining source.
! Defaults to "unknown". Can be globally set for all collections with "SOURCE:"
! \item[frequency] Integer (HHMMSS) for the frequency of output. Default = 060000.
! \item[acc_interval] Integer (HHMMSS) for the acculation interval (<= frequency) for time-averaged diagnostics.
! Default = Diagnostic Frequency.
Expand Down Expand Up @@ -490,6 +503,18 @@ subroutine Initialize ( gc, import, dumexport, clock, rc )
call ESMF_ConfigGetAttribute ( config, value=INTSTATE%expdsc, &
label ='EXPDSC:', default='', rc=status )
_VERIFY(STATUS)
call ESMF_ConfigGetAttribute ( config, value=INTSTATE%global_atts%institution, &
label ='INSTITUTION:', default='NASA Global Modeling and Assimilation Office', _RC)
call ESMF_ConfigGetAttribute ( config, value=INTSTATE%global_atts%references, &
label ='REFERENCES:', default='see MAPL documentation', _RC)
call ESMF_ConfigGetAttribute ( config, value=INTSTATE%global_atts%contact, &
label ='CONTACT:', default='http://gmao.gsfc.nasa.gov', _RC)
call ESMF_ConfigGetAttribute ( config, value=INTSTATE%global_atts%comment, &
label ='COMMENT:', default='NetCDF-4', _RC)
call ESMF_ConfigGetAttribute ( config, value=INTSTATE%global_atts%convention, &
label ='CONVENTION:', default='CF', _RC)
call ESMF_ConfigGetAttribute ( config, value=INTSTATE%global_atts%source, &
label ='SOURCE:', default='unknown', _RC)
call ESMF_ConfigGetAttribute ( config, value=INTSTATE%CoresPerNode, &
label ='CoresPerNode:', default=min(npes,8), rc=status )
_VERIFY(STATUS)
Expand Down Expand Up @@ -755,10 +780,34 @@ subroutine Initialize ( gc, import, dumexport, clock, rc )
call ESMF_ConfigGetAttribute ( cfg, value=list(n)%mode,default='instantaneous', &
label=trim(string) // 'mode:' ,rc=status )
_VERIFY(STATUS)
call ESMF_ConfigGetAttribute ( cfg, value=list(n)%descr, &

! Fill the global attributes

! filename is special as it does double duty, so we fill directly
! from HistoryCollection object
list(n)%global_atts%filename = list(n)%filename
call ESMF_ConfigGetAttribute ( cfg, value=list(n)%global_atts%descr, &
default=INTSTATE%expdsc, &
label=trim(string) // 'descr:' ,rc=status )
_VERIFY(STATUS)
call ESMF_ConfigGetAttribute ( cfg, value=list(n)%global_atts%comment, &
default=INTSTATE%global_atts%comment, &
label=trim(string) // 'comment:' ,_RC)
call ESMF_ConfigGetAttribute ( cfg, value=list(n)%global_atts%contact, &
default=INTSTATE%global_atts%contact, &
label=trim(string) // 'contact:' ,_RC)
call ESMF_ConfigGetAttribute ( cfg, value=list(n)%global_atts%convention, &
default=INTSTATE%global_atts%convention, &
label=trim(string) // 'convention:' ,_RC)
call ESMF_ConfigGetAttribute ( cfg, value=list(n)%global_atts%institution, &
default=INTSTATE%global_atts%institution, &
label=trim(string) // 'institution:' ,_RC)
call ESMF_ConfigGetAttribute ( cfg, value=list(n)%global_atts%references, &
default=INTSTATE%global_atts%references, &
label=trim(string) // 'references:' ,_RC)
call ESMF_ConfigGetAttribute ( cfg, value=list(n)%global_atts%source, &
default=INTSTATE%global_atts%source, &
label=trim(string) // 'source:' ,_RC)

call ESMF_ConfigGetAttribute ( cfg, mntly, default=0, &
label=trim(string) // 'monthly:',rc=status )
Expand Down Expand Up @@ -2434,7 +2483,7 @@ subroutine Initialize ( gc, import, dumexport, clock, rc )
call list(n)%trajectory%initialize(list(n)%items,list(n)%bundle,list(n)%timeInfo,vdata=list(n)%vdata,recycle_track=list(n)%recycle_track,rc=status)
_VERIFY(status)
else
global_attributes = list(n)%define_collection_attributes(_RC)
global_attributes = list(n)%global_atts%define_collection_attributes(_RC)
if (trim(list(n)%output_grid_label)/='') then
pgrid => IntState%output_grids%at(trim(list(n)%output_grid_label))
call list(n)%mGriddedIO%CreateFileMetaData(list(n)%items,list(n)%bundle,list(n)%timeInfo,ogrid=pgrid,vdata=list(n)%vdata,global_attributes=global_attributes,rc=status)
Expand Down Expand Up @@ -3604,7 +3653,7 @@ subroutine Run ( gc, import, export, clock, rc )
if( INTSTATE%LCTL(n) ) then
call MAPL_GradsCtlWrite ( clock, state_out, list(n), &
filename(n), INTSTATE%expid, &
list(n)%descr, intstate%output_grids,rc )
list(n)%global_atts%descr, intstate%output_grids,rc )
INTSTATE%LCTL(n) = .false.
endif

Expand Down

0 comments on commit 62621e3

Please sign in to comment.