Skip to content

Commit 7b22a6d

Browse files
committed
Support 'hconfig' object in ESMF_Initialize() for easy access.
1 parent 53fb3ac commit 7b22a6d

File tree

1 file changed

+50
-23
lines changed

1 file changed

+50
-23
lines changed

src/Superstructure/ESMFMod/src/ESMF_Init.F90

Lines changed: 50 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ module ESMF_InitMod
6969
public ESMF_IsInitialized, ESMF_IsFinalized
7070

7171
! should be private to framework - needed by other modules
72-
public ESMF_FrameworkInternalInit
72+
public ESMF_FrameworkInternalInit
7373

7474
!EOPI
7575

@@ -98,7 +98,8 @@ subroutine ESMF_Initialize(keywordEnforcer, configFilenameFromArgNum, &
9898
defaultDefaultLogFilename, defaultLogFilename, &
9999
defaultLogAppendFlag, logAppendFlag, defaultLogKindFlag, logKindFlag, &
100100
mpiCommunicator, ioUnitLBound, ioUnitUBound, &
101-
defaultGlobalResourceControl, globalResourceControl, config, vm, rc)
101+
defaultGlobalResourceControl, globalResourceControl, config, hconfig, &
102+
vm, rc)
102103
!
103104
! !ARGUMENTS:
104105
type(ESMF_KeywordEnforcer), optional:: keywordEnforcer ! must use keywords below
@@ -119,6 +120,7 @@ subroutine ESMF_Initialize(keywordEnforcer, configFilenameFromArgNum, &
119120
logical, intent(in), optional :: defaultGlobalResourceControl
120121
logical, intent(in), optional :: globalResourceControl
121122
type(ESMF_Config), intent(out), optional :: config
123+
type(ESMF_HConfig), intent(out), optional :: hconfig
122124
type(ESMF_VM), intent(out), optional :: vm
123125
integer, intent(out), optional :: rc
124126

@@ -153,6 +155,8 @@ subroutine ESMF_Initialize(keywordEnforcer, configFilenameFromArgNum, &
153155
! file specification via the command line.
154156
! \item[8.6.0] Added {\tt defaultDefaultCalKind} argument to allow specifiation
155157
! of a default for {\tt defaultCalKind}.
158+
! \item[8.7.0] Added argument {\tt hconfig} to simplify direct access to the
159+
! default {\tt ESMF\_HConfig} object.
156160
! \end{description}
157161
! \end{itemize}
158162
!
@@ -383,8 +387,12 @@ subroutine ESMF_Initialize(keywordEnforcer, configFilenameFromArgNum, &
383387
! Returns the default {\tt ESMF\_Config} if the
384388
! {\tt configFilename} argument was provided. Otherwise the
385389
! presence of this argument triggers an error.
390+
! \item [{[hconfig]}]
391+
! Returns the default {\tt ESMF\_HConfig} if the
392+
! {\tt configFilename} argument was provided. Otherwise the
393+
! presence of this argument triggers an error.
386394
! \item [{[vm]}]
387-
! Returns the global {\tt ESMF\_VM} that was created
395+
! Returns the global {\tt ESMF\_VM} that was created
388396
! during initialization.
389397
! \item [{[rc]}]
390398
! Return code; equals {\tt ESMF\_SUCCESS} if there are no errors.
@@ -412,13 +420,13 @@ subroutine ESMF_Initialize(keywordEnforcer, configFilenameFromArgNum, &
412420
ioUnitLBound=ioUnitLBound, ioUnitUBound=ioUnitUBound, &
413421
defaultGlobalResourceControl=defaultGlobalResourceControl, &
414422
globalResourceControl=globalResourceControl, &
415-
config=config, rc=localrc)
416-
423+
config=config, hconfig=hconfig, rc=localrc)
424+
417425
! on failure LogErr is not initialized -> explicit print on error
418426
if (localrc .ne. ESMF_SUCCESS) then
419427
write (ESMF_UtilIOStderr,*) ESMF_METHOD, ": Error initializing framework"
420-
return
421-
endif
428+
return
429+
endif
422430
! on success LogErr is assumed to be functioning
423431

424432
! obtain global VM
@@ -490,14 +498,14 @@ subroutine ESMF_InitializePreMPI(keywordEnforcer, rc)
490498

491499
! initialize pre MPI parts of global VM
492500
call ESMF_VMInitializePreMPI(rc=localrc)
493-
501+
494502
! on failure LogErr is not initialized -> explicit print on error
495503
if (localrc .ne. ESMF_SUCCESS) then
496504
write (ESMF_UtilIOStderr,*) ESMF_METHOD, ": Error initializing framework"
497-
return
498-
endif
505+
return
506+
endif
499507
! on success LogErr is assumed to be functioning
500-
508+
501509
if (present(rc)) rc = ESMF_SUCCESS
502510
end subroutine ESMF_InitializePreMPI
503511
!------------------------------------------------------------------------------
@@ -515,7 +523,7 @@ subroutine ESMF_FrameworkInternalInit(lang, configFilenameFromArgNum, &
515523
defaultDefaultLogFilename, defaultLogFilename, &
516524
defaultLogAppendFlag, logAppendFlag, defaultLogKindFlag, logKindFlag, &
517525
mpiCommunicator, ioUnitLBound, ioUnitUBound, &
518-
defaultGlobalResourceControl, globalResourceControl, config, rc)
526+
defaultGlobalResourceControl, globalResourceControl, config, hconfig, rc)
519527
!
520528
! !ARGUMENTS:
521529
integer, intent(in) :: lang
@@ -536,6 +544,7 @@ subroutine ESMF_FrameworkInternalInit(lang, configFilenameFromArgNum, &
536544
logical, intent(in), optional :: defaultGlobalResourceControl
537545
logical, intent(in), optional :: globalResourceControl
538546
type(ESMF_Config), intent(out), optional :: config
547+
type(ESMF_HConfig), intent(out), optional :: hconfig
539548
integer, intent(out), optional :: rc
540549

541550
!
@@ -597,13 +606,17 @@ subroutine ESMF_FrameworkInternalInit(lang, configFilenameFromArgNum, &
597606
! Returns the default {\tt ESMF\_Config} if the
598607
! {\tt configFilename} argument was provided. Otherwise the
599608
! presence of this argument triggers an error.
609+
! \item [{[hconfig]}]
610+
! Returns the default {\tt ESMF\_HConfig} if the
611+
! {\tt configFilename} argument was provided. Otherwise the
612+
! presence of this argument triggers an error.
600613
! \item [{[rc]}]
601614
! Return code; equals {\tt ESMF\_SUCCESS} if there are no errors.
602615
! \end{description}
603616
!
604617
!EOPI
605618

606-
logical :: rcpresent ! Return code present
619+
logical :: rcpresent ! Return code present
607620
integer :: localrc
608621
logical, save :: already_init = .false. ! Static, maintains state.
609622
logical :: openflag, isPresent
@@ -619,7 +632,7 @@ subroutine ESMF_FrameworkInternalInit(lang, configFilenameFromArgNum, &
619632
character(ESMF_MAXSTR) :: errmsg
620633
integer :: errmsg_l
621634
type(ESMF_Config) :: configInternal
622-
type(ESMF_HConfig) :: hconfig, hconfigNode, hconfigNodePrev
635+
type(ESMF_HConfig) :: hconfigInternal, hconfigNode, hconfigNodePrev
623636

624637
logical :: globalResourceControlSet, logAppendFlagSet
625638
character(160) :: defaultLogFilenameSet, defaultLogFilenameS
@@ -809,10 +822,10 @@ subroutine ESMF_FrameworkInternalInit(lang, configFilenameFromArgNum, &
809822
ESMF_CONTEXT, rcToReturn=rc)) return
810823

811824
! access hconfig
812-
call ESMF_ConfigGet(configInternal, hconfig=hconfig, rc=localrc)
825+
call ESMF_ConfigGet(configInternal, hconfig=hconfigInternal, rc=localrc)
813826
if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
814827
ESMF_CONTEXT, rcToReturn=rc)) return
815-
isFlag = ESMF_HConfigIsNull(hconfig, rc=localrc)
828+
isFlag = ESMF_HConfigIsNull(hconfigInternal, rc=localrc)
816829
if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
817830
ESMF_CONTEXT, rcToReturn=rc)) return
818831
validHConfigNode = .false. ! not until found
@@ -827,7 +840,7 @@ subroutine ESMF_FrameworkInternalInit(lang, configFilenameFromArgNum, &
827840
return ! bail out
828841
endif
829842
! find the hconfigNode holding predefined label map
830-
hconfigNode = ESMF_HConfigCreate(hconfig, rc=localrc)
843+
hconfigNode = ESMF_HConfigCreate(hconfigInternal, rc=localrc)
831844
if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
832845
ESMF_CONTEXT, rcToReturn=rc)) return
833846
validHConfigNode = .true.
@@ -1319,12 +1332,17 @@ subroutine ESMF_FrameworkInternalInit(lang, configFilenameFromArgNum, &
13191332
ESMF_CONTEXT, rcToReturn=rc)) return
13201333
endif
13211334
! optionally destroy the Config
1322-
if (.not.present(config)) then
1335+
if (.not.(present(config).or.present(hconfig))) then
13231336
call ESMF_ConfigDestroy(configInternal, rc=localrc)
13241337
if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
13251338
ESMF_CONTEXT, rcToReturn=rc)) return
13261339
else
1327-
config = configInternal ! return back to user
1340+
if (present(config)) then
1341+
config = configInternal ! return back to user
1342+
endif
1343+
if (present(hconfig)) then
1344+
hconfig = hconfigInternal ! return back to user
1345+
endif
13281346
endif
13291347
endif
13301348

@@ -1381,12 +1399,21 @@ subroutine ESMF_FrameworkInternalInit(lang, configFilenameFromArgNum, &
13811399

13821400
already_init = .true.
13831401

1384-
if (.not.haveConfig.and.present(config)) then
1385-
call ESMF_LogSetError(ESMF_RC_ARG_INCOMP, &
1386-
msg="Cannot request 'config' without identifying "// &
1402+
if (.not.haveConfig) then
1403+
if (present(config)) then
1404+
call ESMF_LogSetError(ESMF_RC_ARG_INCOMP, &
1405+
msg="Cannot request 'config' without identifying "// &
13871406
"a valid config file", &
13881407
ESMF_CONTEXT, rcToReturn=rc)
1389-
return ! bail out
1408+
return ! bail out
1409+
endif
1410+
if (present(hconfig)) then
1411+
call ESMF_LogSetError(ESMF_RC_ARG_INCOMP, &
1412+
msg="Cannot request 'hconfig' without identifying "// &
1413+
"a valid config file", &
1414+
ESMF_CONTEXT, rcToReturn=rc)
1415+
return ! bail out
1416+
endif
13901417
endif
13911418

13921419
if (rcpresent) rc = ESMF_SUCCESS

0 commit comments

Comments
 (0)