Skip to content

Commit

Permalink
Bring NUOPC_CompSpecialize() through the NUOPC C API.
Browse files Browse the repository at this point in the history
  • Loading branch information
theurich committed Jan 11, 2024
1 parent e0f7f37 commit 2e2903f
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 3 deletions.
24 changes: 23 additions & 1 deletion src/addon/NUOPC/include/NUOPC.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,33 @@
#ifndef NUOPC_H
#define NUOPC_H

// TODO: access these string constants via ISO_C interop. from Fortran definition
const char *label_InternalState = "ModelBase_InternalState";
const char *label_Advance = "ModelBase_Advance";
const char *label_AdvanceClock = "ModelBase_AdvanceClock";
const char *label_CheckImport = "ModelBase_CheckImport";
const char *label_SetRunClock = "ModelBase_SetRunClock";
const char *label_TimestampExport = "ModelBase_TimestampExport";
const char *label_Finalize = "ModelBase_Finalize";
const char *label_Advertise = "ModelBase_Advertise";
const char *label_ModifyAdvertised = "ModelBase_ModifyAdvertised";
const char *label_RealizeProvided = "ModelBase_RealizeProvided";
const char *label_AcceptTransfer = "ModelBase_AcceptTransfer";
const char *label_RealizeAccepted = "ModelBase_RealizeAccepted";
const char *label_SetClock = "ModelBase_SetClock";
const char *label_DataInitialize = "ModelBase_DataInitialize";

int NUOPC_CompDerive(
ESMC_GridComp comp, // in
ESMC_GridComp , // in
void (*userRoutine)(ESMC_GridComp, int *) // in
);

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

void NUOPC_ModelSetServices(ESMC_GridComp, int *);

#endif // NUOPC_H
22 changes: 21 additions & 1 deletion src/addon/NUOPC/interface/NUOPC_F.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ int NUOPC_CompDerive(
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);
Expand All @@ -32,6 +31,27 @@ int NUOPC_CompDerive(
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!!!
int NUOPC_CompSpecialize(
ESMC_GridComp comp, // in
char *specLabel, // in
void (*specRoutine)(ESMC_GridComp, int *) // in
){
int rc = ESMC_RC_NOT_IMPL; // final return code

FTN_X(f_nuopc_compspecialize)((void*)comp.ptr, specLabel, specRoutine, &rc,
strlen(specLabel));

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

void FTN_X(f_nuopc_modelsetservices)(void* gcomp, int* rc);
void NUOPC_ModelSetServices(ESMC_GridComp comp, int *rc){
FTN_X(f_nuopc_modelsetservices)((void*)comp.ptr, rc);
Expand Down
37 changes: 36 additions & 1 deletion src/addon/NUOPC/interface/NUOPC_c.F90
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
! $Id$
!
! Earth System Modeling Framework
! Copyright (c) 2002-2023, University Corporation for Atmospheric Research,
! Copyright (c) 2002-2024, University Corporation for Atmospheric Research,
! Massachusetts Institute of Technology, Geophysical Fluid Dynamics
! Laboratory, University of Michigan, National Centers for Environmental
! Prediction, Los Alamos National Laboratory, Argonne National Laboratory,
Expand Down Expand Up @@ -39,3 +39,38 @@ subroutine f_nuopc_modelsetservices(gcomp, rc)
rc = localrc

end subroutine f_nuopc_modelsetservices


subroutine f_nuopc_compspecialize(gcomp, specLabel, specRoutine, rc)
#undef ESMF_METHOD
#define ESMF_METHOD "f_nuopc_compspecialize"

use ESMF
use NUOPC
implicit none

type(ESMF_GridComp) :: gcomp !in
character(len=*), intent(in) :: specLabel
interface
subroutine specRoutine(gridcomp, rc)
use ESMF
implicit none
type(ESMF_GridComp) :: gridcomp ! must not be optional
integer, intent(out) :: rc ! must not be optional
end subroutine
end interface
integer, intent(out) :: rc !out

integer :: localrc

! Initialize return code; assume routine not implemented
rc = ESMF_RC_NOT_IMPL

call NUOPC_CompSpecialize(gcomp, specLabel, specRoutine=specRoutine, &
rc=localrc)
if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) return

rc = localrc

end subroutine f_nuopc_compspecialize

0 comments on commit 2e2903f

Please sign in to comment.