-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2420 from GEOS-ESM/feature/jk/doc/code_generator
Automatic Code Generator Sample Code (0 diff)
- Loading branch information
Showing
7 changed files
with
217 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
113 changes: 113 additions & 0 deletions
113
docs/tutorial/grid_comps/automatic_code_generator_example/ACG_GridComp.F90
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
#include "MAPL_Generic.h" | ||
#include "MAPL_Exceptions.h" | ||
!------------------------------------------------------------------------------ | ||
!> | ||
!### MODULE: `ACG_GridComp` | ||
! | ||
! This module is created to show how to automatically regenerate code segments | ||
! for the registration and access of ESMF states member variables. | ||
! It is not meant to be executed in an application but only to be compiled. | ||
! | ||
module ACG_GridComp | ||
|
||
use ESMF | ||
use MAPL | ||
|
||
implicit none | ||
private | ||
|
||
public SetServices | ||
|
||
!------------------------------------------------------------------------------ | ||
contains | ||
!------------------------------------------------------------------------------ | ||
!> | ||
! `SetServices` uses MAPL_GenericSetServices, which sets | ||
! the Initialize and Finalize services to generic versions. | ||
! It also allocates our instance of a generic state and puts it in the | ||
! gridded component (GC). Here we only set the run method and | ||
! declare the data services. | ||
! | ||
subroutine SetServices(GC,rc) | ||
|
||
type(ESMF_GridComp), intent(inout) :: GC !! gridded component | ||
integer, optional :: rc !! return code | ||
|
||
integer :: status | ||
|
||
call MAPL_GridCompSetEntryPoint ( gc, ESMF_METHOD_INITIALIZE, initialize, _RC) | ||
call MAPL_GridCompSetEntryPoint ( gc, ESMF_METHOD_RUN, run, _RC) | ||
|
||
#include "ACG_Export___.h" | ||
#include "ACG_Import___.h" | ||
|
||
! Set generic services | ||
! ---------------------------------- | ||
call MAPL_GenericSetServices(GC, _RC) | ||
|
||
_RETURN(_SUCCESS) | ||
|
||
end subroutine SetServices | ||
|
||
!------------------------------------------------------------------------------ | ||
!> | ||
! `initialize` is meant to initialize the `ACG` gridded component. | ||
! It primarily creates its exports. | ||
! | ||
subroutine initialize(GC, import, export, clock, rc) | ||
|
||
type (ESMF_GridComp), intent(inout) :: GC !! Gridded component | ||
type (ESMF_State), intent(inout) :: import !! Import state | ||
type (ESMF_State), intent(inout) :: export !! Export state | ||
type (ESMF_Clock), intent(inout) :: clock !! The clock | ||
integer, optional, intent( out) :: RC !! Error code | ||
! | ||
! Locals | ||
integer :: status | ||
|
||
call MAPL_GridCreate(GC, _RC) | ||
|
||
! Call Generic Initialize | ||
! ---------------------------------------- | ||
call MAPL_GenericInitialize(GC, import, export, clock, _RC) | ||
|
||
_RETURN(_SUCCESS) | ||
|
||
end subroutine initialize | ||
|
||
!------------------------------------------------------------------------------ | ||
!> | ||
! `run` is the Run method for `ACG`. | ||
! | ||
subroutine run(GC, import, export, clock, rc) | ||
|
||
type (ESMF_GridComp), intent(inout) :: GC !! Gridded component | ||
type (ESMF_State), intent(inout) :: import !! Import state | ||
type (ESMF_State), intent(inout) :: export !! Export state | ||
type (ESMF_Clock), intent(inout) :: clock !! The clock | ||
integer, optional, intent( out) :: RC !! Error code | ||
! | ||
! Locals | ||
type (MAPL_MetaComp), pointer :: MAPL | ||
integer :: status | ||
|
||
#include "ACG_DeclarePointer___.h" | ||
|
||
!**************************************************************************** | ||
! Begin... | ||
|
||
! Get my internal MAPL_Generic state | ||
! ----------------------------------- | ||
call MAPL_GetObjectFromGC ( GC, MAPL, _RC) | ||
|
||
#include "ACG_GetPointer___.h" | ||
|
||
|
||
_RETURN(_SUCCESS) | ||
|
||
_UNUSED_DUMMY(import) | ||
_UNUSED_DUMMY(clock) | ||
|
||
end subroutine run | ||
|
||
end module ACG_GridComp |
57 changes: 57 additions & 0 deletions
57
docs/tutorial/grid_comps/automatic_code_generator_example/ACG_StateSpecs.rc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
schema_version: 2.0.0 | ||
component: ACG | ||
|
||
category: IMPORT | ||
#---------------------------------------------------------------------------- | ||
# VARIABLE | DIMENSIONS | Additional Metadata | ||
#---------------------------------------------------------------------------- | ||
NAME | UNITS | DIMS | VLOC | RESTART | LONG NAME | ||
#---------------------------------------------------------------------------- | ||
ZLE | m | xyz | E | | geopotential_height | ||
T | K | xyz | C | OPT | air_temperature | ||
PLE | Pa | xyz | E | OPT | air_pressure | ||
|
||
category: EXPORT | ||
#--------------------------------------------------------------------------- | ||
# VARIABLE | DIMENSIONS | Additional Metadata | ||
#--------------------------------------------------------------------------- | ||
NAME | UNITS | DIMS | VLOC | LONG NAME | ||
#--------------------------------------------------------------------------- | ||
ZPBLCN | m | xy | N | boundary_layer_depth | ||
CNV_FRC | 1 | xy | N | convective_fraction | ||
|
||
category: INTERNAL | ||
#--------------------------------------------------------------------------- | ||
# VARIABLE | DIMENSION | Additional Metadata | ||
#--------------------------------------------------------------------------- | ||
NAME | UNITS | DIMS | VLOC | ADD2EXPORT | FRIENDLYTO | LONG NAME | ||
#--------------------------------------------------------------------------- | ||
|
||
|
||
#******************************************************** | ||
# | ||
# Legend | ||
# | ||
#------------------------------------------------------------------ | ||
# Column label | MAPL keyword/interpretation | Default | ||
#--------------|--------------------------------------------------- | ||
# NAME | short_name | | ||
# UNITS | units | | ||
# DIMS | dims | | ||
# VLOC | VLocation | MAPL_VLocationNone | ||
# LONG NAME | long_name | | ||
# COND | if (<logical-expr>) then | .FALSE. | ||
# NUM_SUBTILES | num_subtiles | ||
# ... | ||
#------------------------------------------------------------------ | ||
# | ||
#-------------------------------------------- | ||
# Entry alias | Column | MAPL keyword/interpretation | ||
#--------------|----------------------------- | ||
# xyz | DIMS | MAPL_HorzVert | ||
# xy | DIMS | MAPL_HorzOnly | ||
# z | DIMS | MAPL_VertOnly (plus ungridded) | ||
# C | VLOC | MAPL_VlocationCenter | ||
# E | VLOC | MAPL_VlocationEdge | ||
# N | VLOC | MAPL_VlocationNone | ||
#-------------------------------------------- |
21 changes: 21 additions & 0 deletions
21
docs/tutorial/grid_comps/automatic_code_generator_example/CMakeLists.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
esma_set_this (OVERRIDE MAPL.acg) | ||
|
||
set (srcs | ||
ACG_GridComp.F90 | ||
) | ||
|
||
esma_add_library (${this} SRCS ${srcs} DEPENDENCIES MAPL.shared MAPL TYPE ${MAPL_LIBRARY_TYPE}) | ||
|
||
target_link_libraries(${this} PRIVATE esmf) | ||
|
||
target_include_directories (${this} PUBLIC $<BUILD_INTERFACE:${MAPL_SOURCE_DIR}/include>) | ||
|
||
set_target_properties (${this} PROPERTIES Fortran_MODULE_DIRECTORY ${include_${this}}) | ||
|
||
mapl_acg (${this} ACG_StateSpecs.rc | ||
IMPORT_SPECS EXPORT_SPECS | ||
GET_POINTERS DECLARE_POINTERS) | ||
|
||
if (NOT CMAKE_Fortran_COMPILER_ID MATCHES "NAG") | ||
target_link_libraries(${this} PRIVATE OpenMP::OpenMP_Fortran) | ||
endif () |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters