Skip to content

Commit

Permalink
Merge branch 'feature/more-init-opts' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
theurich committed Aug 8, 2023
2 parents 3a48da4 + 6b24de6 commit affb98a
Show file tree
Hide file tree
Showing 7 changed files with 336 additions and 47 deletions.
1 change: 1 addition & 0 deletions src/Infrastructure/VM/include/ESMCI_VM.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ class VM : public VMK { // inherits from ESMCI::VMK class
static void rmFObject(void **fobject);
static bool validObject(ESMC_Base *);
static char const *getenv(char const *name);
static void setenv(char const *name, char const *value);
// misc.
int print() const;
int validate() const;
Expand Down
27 changes: 27 additions & 0 deletions src/Infrastructure/VM/interface/ESMCI_VM_F.C
Original file line number Diff line number Diff line change
Expand Up @@ -1170,6 +1170,33 @@ extern "C" {
if (rc!=NULL) *rc = ESMF_SUCCESS;
}

void FTN_X(c_esmc_vmsetenv)(char *name, char *value, int *rc,
ESMCI_FortranStrLenArg name_l, ESMCI_FortranStrLenArg value_l){
#undef ESMC_METHOD
#define ESMC_METHOD "c_esmc_vmsetenv()"
// Initialize return code; assume routine not implemented
if (rc!=NULL) *rc = ESMC_RC_NOT_IMPL;
try{
std::string nameStr(name, name_l);
std::string valueStr(value, value_l);
ESMCI::VM::setenv(nameStr.c_str(), valueStr.c_str());
}catch(int localrc){
if (ESMC_LogDefault.MsgFoundError(localrc, ESMCI_ERR_PASSTHRU,
ESMC_CONTEXT, rc))
return; // bail out
}catch(std::exception &x){
ESMC_LogDefault.MsgFoundError(ESMC_RC_INTNRL_BAD, x.what(), ESMC_CONTEXT,
rc);
return; // bail out
}catch(...){
ESMC_LogDefault.MsgFoundError(ESMC_RC_INTNRL_BAD, "- Caught exception",
ESMC_CONTEXT, rc);
return;
}
// return successfully
if (rc!=NULL) *rc = ESMF_SUCCESS;
}

void FTN_X(c_esmc_vmfinalize)(ESMC_Logical *keepMpiFlag, int *rc){
#undef ESMC_METHOD
#define ESMC_METHOD "c_esmc_vmfinalize()"
Expand Down
45 changes: 45 additions & 0 deletions src/Infrastructure/VM/interface/ESMF_VM.F90
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,7 @@ subroutine c_ESMC_VMSendRecvNB(vm, sendData, sendSize, dst, recvData, &
public ESMF_VMInitializePreMPI
public ESMF_VMInitialize
public ESMF_VMSet
public ESMF_VMSetEnv
public ESMF_VMFinalize
public ESMF_VMAbort
public ESMF_VMShutdown
Expand Down Expand Up @@ -9348,6 +9349,50 @@ end subroutine ESMF_VMSet
!------------------------------------------------------------------------------


! -------------------------- ESMF-internal method -----------------------------
#undef ESMF_METHOD
#define ESMF_METHOD "ESMF_VMSetEnv()"
!BOPI
! !IROUTINE: ESMF_VMSetEnv - Set environment variable cached in the Global VM

! !INTERFACE:
subroutine ESMF_VMSetEnv(name, value, rc)
!
! !ARGUMENTS:
character(*), intent(in) :: name
character(*), intent(in) :: value
integer, intent(out), optional :: rc
!
! !DESCRIPTION:
! Set environment variable cached in the Global VM. Potentially override what
! came from the shell environment.
!
! The arguments are:
! \begin{description}
! \item [name]
! The name of the environment variable.
! \item [value]
! The value of the environment variable.
! \item[{[rc]}]
! Return code; equals {\tt ESMF\_SUCCESS} if there are no errors.
! \end{description}
!
!EOPI
!------------------------------------------------------------------------------
integer :: localrc ! local return code

! Call into the C++ interface.
call c_ESMC_VMSetEnv(name, value, localrc)
if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) return

! return successfully
if (present(rc)) rc = ESMF_SUCCESS

end subroutine ESMF_VMSetEnv
!------------------------------------------------------------------------------


! -------------------------- ESMF-internal method -----------------------------
#undef ESMF_METHOD
#define ESMF_METHOD "ESMF_VMFinalize()"
Expand Down
39 changes: 38 additions & 1 deletion src/Infrastructure/VM/src/ESMCI_VM.C
Original file line number Diff line number Diff line change
Expand Up @@ -3108,7 +3108,7 @@ char const *VM::getenv(
char const *name){
//
// !DESCRIPTION:
// Access environment variables in the global VM object
// Access environment variable cached within the global VM object
//
//EOPI
//-----------------------------------------------------------------------------
Expand All @@ -3125,6 +3125,43 @@ char const *VM::getenv(
//-----------------------------------------------------------------------------


//-----------------------------------------------------------------------------
#undef ESMC_METHOD
#define ESMC_METHOD "ESMCI::VM::setenv()"
//BOPI
// !IROUTINE: ESMCI::VM::setenv - set environment variable
// !INTERFACE:
void VM::setenv(
//
// !RETURN VALUE:
// pointer to value or NULL
//
// !ARGUMENTS:
//
char const *name,
char const *value){
//
// !DESCRIPTION:
// Set environment variable cached within the global VM object
//
//EOPI
//-----------------------------------------------------------------------------
int count = esmfRuntimeEnv.size();
int i;
for (i=0; i<count; i++)
if (!esmfRuntimeEnv[i].compare(name)) break;
if (i == count){
// no match found -> add new variable
esmfRuntimeEnv.push_back(name);
esmfRuntimeEnvValue.push_back(value);
}else{
// match found -> update the value
esmfRuntimeEnvValue[i] = std::string(value);
}
}
//-----------------------------------------------------------------------------


//-----------------------------------------------------------------------------
#undef ESMC_METHOD
#define ESMC_METHOD "ESMCI::VM::initialize()"
Expand Down
Loading

0 comments on commit affb98a

Please sign in to comment.