Reading Config Files - GEOS-ESM/MAPL GitHub Wiki
Overview
MAPL currently uses the ESMF config format to specify external RC files to provide input to source code at runtime. There are two ways to access this, one is directly through the ESMF API's the other is the wrappers provided by MAPL to use the config associated with a gridded component (if applicable).
VIA ESMF API
If you want to directly access a config file on disk (let's call it myfile.rc) in any Fortran application using ESMF here is the method. Note that all ESMF calls have an optional return code (rc=) that you can obtain when calling and then checking. Note that ESMF (and the wrapper) support retrieving integers, reals, and logicals.
# must declare a config object
type(ESMF_Config) :: config
# the rest are for the example code below
logical :: isPresent
integer :: myval
# create the config (this is necessary unfortunately) then load the file
config = ESMF_ConfigCreate()
call ESMF_ConfigLoadFile(config,"myfile.rc")
# Now you can do a few things. All further interactions are with the config object
# You can check if the file has a particular key, lets call it mykey, with the isPresent option
# Note this is not strictly necessary but if you don't and the key is not present the ESMF log file
# will fill with warnings
call ESMF_ConfigFindLabel(config,"mykey",isPresent=isPresent)
# Now retrieve a value, you can pass a default
call ESMF_ConfigGetAttribute(config,myval,label="mykey",default=11)
VIA MAPL_GetResource
If you are in a gridded component in the GEOS (or another model using MAPL for the hierarchy) each gridded component has an ESMF_Config that is internally stored in the gridded component. Generally if running the GEOSgcm.x this is the AGCM.rc. If you are in a gridded component the component will have an ESMF_GridComp as the first argument in the init/run/finalize. Values from this can be obtained via the MAPL_GetResource wrapper that pulls from the internally stored ESMF_Config. In the code example below I will demonstrate.
# First if your component has not already declare an MAPL_MetaComp object
type(MAPL_MetaComp), pointer :: MAPL
integer :: myval
# Now retrieve it from the gridded component passed in which I will assume is named GC
call MAPL_GetObjectFromGC(GC,MAPL)
# Now you can get a value like this
call MAPL_GetResource(MAPL,myval,"mykey:",default=11)
Reading tables
Other Notes
If you see code with i90_label, i90_loadfile do not follow that example. That is a very old library called INPAK that became the basis for the ESMF_Config. Do not use in new code.