CMEPS icon indicating copy to clipboard operation
CMEPS copied to clipboard

use ESMF_Version_* to get version dependent differences in CMEPS

Open mvertens opened this issue 5 years ago • 2 comments

All of the ESMF_VERSION_* symbols are available as parameters via "use ESMF" in Fortran code. This is documented under https://esmf-org.github.io/dev_docs/ESMF_refdoc/node9.html#SECTION090161000000000000000.

Using the above Fortran named constants is the most portable way to code version dependent differences in code because it does not require the build system to get involved. I think this approach should be used inside the CMEPS code for (ESMF_VERSION_MAJOR==8 .and. ESMF_VERSION_MINOR>0), and it should replace the CPP #if based code.

There are cases where the CPP based #if approach is necessary - basically for when API changes between ESMF versions will not allow compilation under different versions. This is not the case here, and therefore it will be much simpler to just use Fortran level logic based on the named constants. The problem with the CPP macro based approach is that it requires that the build system gets the variables from the esmf.mk and then pass them in via -D option to the compiler. The NEMS build system does this e.g. for module_EARTH_GRID_COMP.F90 and module_MEDIATOR.F90, but not for CMEPS, which would need a change in the CMEPS Makefile.

Again, my recommendation is to change the CMEPS version logic code to using the ESMF_VERSION_* named constants defined by "use ESMF".

mvertens avatar Jul 02 '20 17:07 mvertens

I think that there must be some confusion here.

jedwards4b avatar Jul 06 '20 14:07 jedwards4b

The suggestion from Gerhard cannot be used since the ESMF_VERSION macro is being used to determine if elements of the ESMF module itself exist. Therefore I think that this code needs to remain as is.

#if ESMF_VERSION_MINOR > 0                                                                           
    use ESMF , only : ESMF_StateSet, ESMF_StateIntent_Import, ESMF_StateIntent_Export                
    use ESMF , only : ESMF_StateIntent_Flag                                                          
#endif

jedwards4b avatar Jul 06 '20 15:07 jedwards4b