Skip to content

Commit

Permalink
Merge pull request #3174 from GEOS-ESM/feature/mathomp4/2845-esmf-env…
Browse files Browse the repository at this point in the history
…-var

Fixes #2845. Allow ESMF_CONFIG_FILE to specify ESMF control file
  • Loading branch information
tclune authored Dec 5, 2024
2 parents 194323c + e9b9476 commit f9b8421
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 9 deletions.
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

- Added macro _RETURN(_SUCCESS) to fetch_data
- Added macro `_RETURN(_SUCCESS)` to fetch_data
- Allow update offsets of ±timestep in ExtData2G
- Minor revision (and generalization) of grid-def for GSI purposes
- Trajectory sampler: fix a bug when group_name does not exist in netCDF file and a bug that omitted the first time point
- Add ability to use an `ESMF_CONFIG_FILE` environment variable to specify name of file to pass in pre-`ESMF_Initialize` options to ESMF (see [ESMF Docs](https://earthsystemmodeling.org/docs/release/latest/ESMF_refdoc/node4.html#SECTION04024000000000000000) for allowed flags.
- Allow lat-lon grid factory to detect and use CF compliant lat-lon bounds in a file when making a grid
- PFIO/Variable class, new procedures to retrieve string/reals/int attributes from a variable

Expand Down Expand Up @@ -50,6 +50,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed

- Fixed issue of some Baselibs builds appearing to support zstandard. This is not possible due to Baselibs building HDF5 and netCDF as static libraries
- Trajectory sampler: fix a bug when group_name does not exist in netCDF file and a bug that omitted the first time point
- Fixed a bug where the periodicity around the earth of the lat-lon grid was not being set properly when grid did not span from pole to pole

### Removed
Expand Down
39 changes: 32 additions & 7 deletions gridcomps/Cap/MAPL_Cap.F90
Original file line number Diff line number Diff line change
Expand Up @@ -274,9 +274,10 @@ subroutine run_model(this, comm, unusable, rc)
integer :: rank, ierror
integer :: status
class(Logger), pointer :: lgr
logical :: file_exists
logical :: esmfConfigFileExists
type (ESMF_VM) :: vm
character(len=:), allocatable :: esmfComm
character(len=:), allocatable :: esmfComm, esmfConfigFile
integer :: esmfConfigFileLen

_UNUSED_DUMMY(unusable)

Expand All @@ -288,16 +289,41 @@ subroutine run_model(this, comm, unusable, rc)
call MPI_COMM_RANK(comm, rank, status)
_VERIFY(status)

! We look to see if the user has set an environment variable for the
! name of the ESMF configuration file. If they have, we use that. If not,
! we use the default of "ESMF.rc" for backward compatibility

! Step one: default to ESMF.rc

esmfConfigFile = 'ESMF.rc'
esmfConfigFileLen = len(esmfConfigFile)

! Step two: get the length of the environment variable
call get_environment_variable('ESMF_CONFIG_FILE', length=esmfConfigFileLen, status=status)
! Step three: if the environment variable exists, get the value of the environment variable
if (status == 0) then ! variable exists
! We need to deallocate so we can reallocate
deallocate(esmfConfigFile)
allocate(character(len = esmfConfigFileLen) :: esmfConfigFile)
call get_environment_variable('ESMF_CONFIG_FILE', value=esmfConfigFile, status=status)
_VERIFY(status)
end if

if (rank == 0) then
inquire(file='ESMF.rc', exist=file_exists)
inquire(file=esmfConfigFile, exist=esmfConfigFileExists)
end if
call MPI_BCAST(file_exists, 1, MPI_LOGICAL, 0, comm, status)
call MPI_BCAST(esmfConfigFileExists, 1, MPI_LOGICAL, 0, comm, status)
_VERIFY(status)
call MPI_BCAST(esmfConfigFile, esmfConfigFileLen, MPI_CHARACTER, 0, comm, status)
_VERIFY(status)

lgr => logging%get_logger('MAPL')

! If the file exists, we pass it into ESMF_Initialize, else, we
! use the one from the command line arguments
if (file_exists) then
call ESMF_Initialize (configFileName='ESMF.rc', mpiCommunicator=comm, vm=vm, _RC)
if (esmfConfigFileExists) then
call lgr%info("Using ESMF configuration file: %a", esmfConfigFile)
call ESMF_Initialize (configFileName=esmfConfigFile, mpiCommunicator=comm, vm=vm, _RC)
else
call ESMF_Initialize (logKindFlag=this%cap_options%esmf_logging_mode, mpiCommunicator=comm, vm=vm, _RC)
end if
Expand All @@ -312,7 +338,6 @@ subroutine run_model(this, comm, unusable, rc)
call ESMF_MeshSetMOAB(this%cap_options%with_esmf_moab, rc=status)
_VERIFY(status)

lgr => logging%get_logger('MAPL')
call lgr%info("Running with MOAB library for ESMF Mesh: %l1", this%cap_options%with_esmf_moab)

call this%initialize_cap_gc(rc=status)
Expand Down

0 comments on commit f9b8421

Please sign in to comment.