Skip to content

Commit

Permalink
Leverage access to ESMCI for error handling, etc. inside of NUOPC_F.C
Browse files Browse the repository at this point in the history
implementation.
  • Loading branch information
theurich committed Jan 16, 2024
1 parent 1f6359c commit a6ee783
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/addon/NUOPC/include/NUOPC.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ int NUOPC_CompDerive(

int NUOPC_CompSpecialize(
ESMC_GridComp, // in
char *, // in
const char *, // in
void (*specLabel)(ESMC_GridComp, int *) // in
);

Expand Down
47 changes: 36 additions & 11 deletions src/addon/NUOPC/interface/NUOPC_F.C
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "NUOPC.h"

// include ESMF headers
#include "ESMCI_Base.h"
#include "ESMCI_Arg.h"
#include "ESMCI_LogErr.h"
#include "ESMC_Interface.h"
Expand All @@ -27,44 +28,68 @@

extern "C" {

//-----------------------------------------------------------------------------
#undef ESMC_METHOD
#define ESMC_METHOD "NUOPC_CompDerive()"
int NUOPC_CompDerive(
ESMC_GridComp comp, // in
void (*userRoutine)(ESMC_GridComp, int *) // in
){
// initialize return code; assume routine not implemented
int localrc = ESMC_RC_NOT_IMPL; // local return code
int rc = ESMC_RC_NOT_IMPL; // final return code

(*userRoutine)(comp, &rc);
(*userRoutine)(comp, &localrc);
if (ESMC_LogDefault.MsgFoundError(localrc, ESMCI_ERR_PASSTHRU, ESMC_CONTEXT,
&rc)) return rc; // bail out

// return successfully
rc = ESMF_SUCCESS;
return rc;
}
//-----------------------------------------------------------------------------


void FTN_X(f_nuopc_compspecialize)(void* gcomp, char *specLabel,
void (*specRoutine)(ESMC_GridComp, int *), int *rc, int);
//TODO: the last argument should actually be of type ESMCI_FortranStrLenArg
//TODO: for this to be included this file here needs to change to be .C, i.e C++
//TODO: That'd be better anyway, because it allows standard error checking with
//TODO: backtrace generation in the calls below!!!
//-----------------------------------------------------------------------------
void FTN_X(f_nuopc_compspecialize)(void* gcomp, const char *specLabel,
void (*specRoutine)(ESMC_GridComp, int *), int *rc, ESMCI_FortranStrLenArg);
#undef ESMC_METHOD
#define ESMC_METHOD "NUOPC_CompSpecialize()"
int NUOPC_CompSpecialize(
ESMC_GridComp comp, // in
char *specLabel, // in
const char *specLabel, // in
void (*specRoutine)(ESMC_GridComp, int *) // in
){
// initialize return code; assume routine not implemented
int localrc = ESMC_RC_NOT_IMPL; // local return code
int rc = ESMC_RC_NOT_IMPL; // final return code

FTN_X(f_nuopc_compspecialize)((void*)comp.ptr, specLabel, specRoutine, &rc,
strlen(specLabel));
FTN_X(f_nuopc_compspecialize)((void*)comp.ptr, specLabel, specRoutine,
&localrc, (ESMCI_FortranStrLenArg)strlen(specLabel));
if (ESMC_LogDefault.MsgFoundError(localrc, ESMCI_ERR_PASSTHRU, ESMC_CONTEXT,
&rc)) return rc; // bail out

// return successfully
rc = ESMF_SUCCESS;
return rc;
}
//-----------------------------------------------------------------------------


//-----------------------------------------------------------------------------
void FTN_X(f_nuopc_modelsetservices)(void* gcomp, int* rc);
#undef ESMC_METHOD
#define ESMC_METHOD "NUOPC_ModelSetServices()"
void NUOPC_ModelSetServices(ESMC_GridComp comp, int *rc){
FTN_X(f_nuopc_modelsetservices)((void*)comp.ptr, rc);
// initialize return code; assume routine not implemented
int localrc = ESMC_RC_NOT_IMPL; // local return code
FTN_X(f_nuopc_modelsetservices)((void*)comp.ptr, &localrc);
if (ESMC_LogDefault.MsgFoundError(localrc, ESMCI_ERR_PASSTHRU, ESMC_CONTEXT,
rc)) return; // bail out

// return successfully
if (rc!=NULL) *rc = ESMF_SUCCESS;
}
//-----------------------------------------------------------------------------

}; // extern "C"

0 comments on commit a6ee783

Please sign in to comment.