Skip to content

Commit

Permalink
Minor code simplification (ESMF logical -> Fortran logical), formatting
Browse files Browse the repository at this point in the history
(mostly white space), and a few typos (in comments).
  • Loading branch information
theurich committed Jan 4, 2024
1 parent cb589e1 commit a0cf089
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 77 deletions.
23 changes: 10 additions & 13 deletions src/Infrastructure/HConfig/interface/ESMCI_HConfig_F.C
Original file line number Diff line number Diff line change
Expand Up @@ -173,28 +173,25 @@ extern "C" {
}

// Check for equality
// Since this is used as equality operator above there isn't a place to pass a return code, so just
// pass false for an error instead (as done with equality operators elsewhere in ESMF)
void FTN_X(c_esmc_hconfigequal)(ESMCI::HConfig *hconfig1, ESMCI::HConfig *hconfig2, ESMC_Logical *isEqual){
// Since this is used as equality operator above, there isn't a place to pass
// a return code, so just pass false for an error instead (as done with
// equality operators elsewhere in ESMF).
void FTN_X(c_esmc_hconfigequal)(ESMCI::HConfig *hconfig1,
ESMCI::HConfig *hconfig2, ESMC_Logical *isEqual){
#undef ESMC_METHOD
#define ESMC_METHOD "c_esmc_hconfigequal()"

// Init return
// Init return
*isEqual = ESMF_FALSE;

// Test for NULL pointers
if (hconfig1 == NULL) return;
if (hconfig2 == NULL) return;

// call into C++
bool equal=ESMCI::HConfig::equal(hconfig1, hconfig2);

// Comnvert to ESMF Logical
// call into C++
bool equal = ESMCI::HConfig::equal(hconfig1, hconfig2);
// Convert to ESMF Logical
if (equal) *isEqual=ESMF_TRUE;
else *isEqual = ESMF_FALSE;
else *isEqual = ESMF_FALSE;
}


void FTN_X(c_esmc_hconfigdestroy)(ESMCI::HConfig *ptr, int *rc){
#undef ESMC_METHOD
#define ESMC_METHOD "c_esmc_hconfigdestroy()"
Expand Down
24 changes: 10 additions & 14 deletions src/Infrastructure/HConfig/interface/ESMF_HConfig.F90
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,7 @@ function ESMF_HConfigEQ(HConfig1, HConfig2)

ESMF_INIT_TYPE init1, init2
type(ESMF_Logical) :: isEqual

! Use the following logic, rather than "ESMF-INIT-CHECK-DEEP", to gain
! init checks on both args, and in the case where both are uninitialized,
! to distinguish equality based on uninitialized type (uncreated,
Expand All @@ -625,6 +625,9 @@ function ESMF_HConfigEQ(HConfig1, HConfig2)
init1 = ESMF_HConfigGetInit(HConfig1)
init2 = ESMF_HConfigGetInit(HConfig2)

! initialize return value
ESMF_HConfigEQ = .false.

! TODO: this line must remain split in two for SunOS f90 8.3 127000-03
if (init1 .eq. ESMF_INIT_CREATED .and. &
init2 .eq. ESMF_INIT_CREATED) then
Expand All @@ -633,13 +636,8 @@ function ESMF_HConfigEQ(HConfig1, HConfig2)
call c_ESMC_HConfigEqual(HConfig1, HConfig2, isEqual)

! Translate from ESMF logical to Fortran logical
ESMF_HConfigEQ= .false.
if (isEqual == ESMF_TRUE) then
ESMF_HConfigEQ= .true.
endif
ESMF_HConfigEQ = isEqual

else
ESMF_HConfigEQ = .false.
endif

end function ESMF_HConfigEQ
Expand Down Expand Up @@ -681,6 +679,9 @@ function ESMF_HConfigIterEQ(HConfig1, HConfig2)
init1 = ESMF_HConfigIterGetInit(HConfig1)
init2 = ESMF_HConfigIterGetInit(HConfig2)

! initialize return value
ESMF_HConfigIterEQ = .false.

! TODO: this line must remain split in two for SunOS f90 8.3 127000-03
if (init1 .eq. ESMF_INIT_CREATED .and. &
init2 .eq. ESMF_INIT_CREATED) then
Expand All @@ -691,13 +692,8 @@ function ESMF_HConfigIterEQ(HConfig1, HConfig2)
call c_ESMC_HConfigEqual(HConfig1, HConfig2, isEqual)

! Translate from ESMF logical to Fortran logical
ESMF_HConfigIterEQ= .false.
if (isEqual == ESMF_TRUE) then
ESMF_HConfigIterEQ= .true.
endif

else
ESMF_HConfigIterEQ = .false.
ESMF_HConfigIterEQ = isEqual

endif

end function ESMF_HConfigIterEQ
Expand Down
103 changes: 53 additions & 50 deletions src/Infrastructure/HConfig/src/ESMCI_HConfig.C
Original file line number Diff line number Diff line change
Expand Up @@ -246,69 +246,72 @@ HConfig HConfig::create(
//-----------------------------------------------------------------------------


//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
#undef ESMC_METHOD
#define ESMC_METHOD "ESMCI::HConfig::equal()"
//BOP
//BOP
// !IROUTINE: ESMCI::HConfig::equal - check if two hconfigs are equal
//
//
// !INTERFACE:
bool HConfig::equal(
//
// !RETURN VALUE:
// bool
//
// !ARGUMENTS:
HConfig *hconfig1,
HConfig *hconfig2) {
//
//
// !DESCRIPTION:
//
//EOP
//-----------------------------------------------------------------------------
bool HConfig::equal(
//
// !RETURN VALUE:
// bool
//
// !ARGUMENTS:
HConfig *hconfig1,
HConfig *hconfig2) {
//
//
// !DESCRIPTION:
//
//EOP
//-----------------------------------------------------------------------------

#ifdef ESMF_YAMLCPP

// Check for error condiiton of NULL inputs, since this is used as an equality operator above there isn't
// really a route to pass an error code, so return false instead (which seems to be the way this is handled
// in other equality operators in the framework).
if (hconfig1 == NULL) return false;
if (hconfig2 == NULL) return false;

// TODO: Move this into an equality operator for HConfig and call that here instead

// See if the docs are equal
if (hconfig1->doc == hconfig2->doc) {

// They are both NULL, so this is an iterator
if (hconfig1->doc == NULL) {

// See if they are the same type
if (hconfig1->type == hconfig2->type) {

// Compare iterators to determine final equality
if (hconfig1->iter == hconfig2->iter) return true;
else return false;

} else {
return false; // Not the same type so not the same
}

} else { // Not NULL, so they aren't iterators, but have the same docs, so the same
return true;
// Check for error condition of NULL inputs, since this is used as an equality
// operator above, there isn't really a way to pass an error code, so return
// false instead (which seems to be the way this is handled in other equality
// operators in the framework).
if (hconfig1 == NULL) return false;
if (hconfig2 == NULL) return false;

// TODO: Move this into an equality operator for HConfig and call that instead

// See if the docs are equal
if (hconfig1->doc == hconfig2->doc) {

// They are both NULL, so this is an iterator
if (hconfig1->doc == NULL) {

// See if they are the same type
if (hconfig1->type == hconfig2->type) {

// Compare iterators to determine final equality
if (hconfig1->iter == hconfig2->iter) return true;
else return false;

} else {
return false; // Not the same type so not the same
}
} else { // Not the same docs, so not the same
return false;

} else { // Not NULL -> aren't iterators, but have the same docs -> equal
return true;
}


} else { // Not the same docs -> not equal
return false;
}

#else
return false;
#endif

}
//-----------------------------------------------------------------------------


//-----------------------------------------------------------------------------
#undef ESMC_METHOD
#define ESMC_METHOD "ESMCI::HConfig::destroy()"
Expand Down

0 comments on commit a0cf089

Please sign in to comment.