GEOS-ESM / MAPL

MAPL is a foundation layer of the GEOS architecture, whose original purpose is to supplement the Earth System Modeling Framework (ESMF)
https://geos-esm.github.io/MAPL/
Apache License 2.0
26 stars 18 forks source link

Specify ESMF Config File via environment variable? #2845

Open mathomp4 opened 1 month ago

mathomp4 commented 1 month ago

In talking with @darianboggs about some ESMF stuff I was reminded of https://github.com/GEOS-ESM/MAPL/pull/2233 which fixed #2133, a request from @lizziel to allow the ability to set the ESMF logging level via a file rather than via command line option.

But, it is hardcoded that the file name is ESMF.rc and nothing else. Now, in MAPL3 land, this will need to be (or should be) a YAML file. So that means ESMF.yml or ESMF.yaml.

But but, @darianboggs reminded me that get_environment_variable does exist in Fortran.

So my thinking is maybe we should do something like:

  1. Look for environment variable ESMF_CONTROL_FILE or whatever (@tclune will have good opinions on this). If found, check if the file ends in .rc, .yml or .yaml. If so, feed that in. (Note: I believe ESMF depends on a file ending in .yml or .yaml to trigger hconfig, so we would want to enforce that and then it makes our life easy if we say ESMF_Config files end in .rc.)
  2. If no environment variable, look for ESMF.rc, ESMF.yml or ESMF.yaml, and use that
  3. Check for command line argument.

Now, I suppose, the command line argument should maybe "win" this battle, but I also know the arguments might be going away in favor of yamls so... 🤷🏼

I suppose the question is: would this be useful? I can sort of see maybe having a set of control files for scripting purposes with different names and then using the environment variable to select?

tclune commented 1 month ago

~ESMF logging can be controlled with the config file passed to ESMF_Init. No need for get_environment_variable. MAPL3 is already doing it this way.~

tclune commented 1 month ago

Sorry - I think my previous answer misunderstood where the question was going.

This should be an issue for main.F90. MAPL3 will use a command line option (but a very simple one) to determine the top config file. GCHP can readily have their own main.F90 that uses get_environment_variable for the same purpose.

We could then consider somehow maintaining both variants inside MAPL for simplicity so that if things change we correct both. (Ideally these top files do very very little though.)

lizziel commented 1 month ago

Using get_environment_variable in the main driver fortran file works for us. And I support moving to yml too. I can make the updates in GCHP when we update to MAPL3.