Skip to content

Commit 5c16b7f

Browse files
committed
Required changes to enable IPD-only, CCPP-only and CCPP-IPD builds using CPP
preprocessor directives. Preparation for future metadata parsing by defining cap source files as separate objects in the makefile. Ignore auto-generated .inc files in git.
1 parent 082d747 commit 5c16b7f

File tree

3 files changed

+128
-6
lines changed

3 files changed

+128
-6
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Auto-generated include files in Fortran code
2+
*.inc

IPD_layer/IPD_driver.F90

+103
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,27 @@ module IPD_driver
1212

1313
use physics_restart_layer, only: restart_populate
1414

15+
#ifdef CCPP_IPD
16+
use fms_mod, only: error_mesg
17+
use ccpp_types, only: ccpp_t
18+
use ccpp, only: ccpp_init
19+
use ccpp_fcall, only: ccpp_run
20+
use ccpp_fields, only: ccpp_fields_add
21+
! Begin include auto-generated list of modules for ccpp
22+
! DH* #include "ccpp_modules.inc"
23+
! End include auto-generated list of modules for ccpp
24+
use iso_c_binding, only: c_loc
25+
#endif
26+
1527
implicit none
1628

29+
#ifdef CCPP_IPD
30+
!------------------------------------------------------!
31+
! CCPP container !
32+
!------------------------------------------------------!
33+
type(ccpp_t), save, target :: cdata
34+
#endif
35+
1736
!------------------------------------------------------!
1837
! IPD containers !
1938
!------------------------------------------------------!
@@ -32,6 +51,9 @@ module IPD_driver
3251
public IPD_radiation_step
3352
public IPD_physics_step1
3453
public IPD_physics_step2
54+
#ifdef CCPP_IPD
55+
public IPD_step
56+
#endif
3557

3658
CONTAINS
3759
!*******************************************************************************************
@@ -138,4 +160,85 @@ subroutine IPD_physics_step2 (IPD_Control, IPD_Data, IPD_Diag, IPD_Restart)
138160

139161
end subroutine IPD_physics_step2
140162

163+
164+
#ifdef CCPP_IPD
165+
!----------------------
166+
! IPD step generalized
167+
!----------------------
168+
subroutine IPD_step (IPD_Control, IPD_Data, IPD_Diag, IPD_Restart, Atm_block, Init_parm, l_salp_data, l_snupx, ccpp_suite, step)
169+
170+
use namelist_soilveg, only: salp_data, snupx, max_vegtyp
171+
use block_control_mod, only: block_control_type
172+
use IPD_typedefs, only: kind_phys
173+
174+
implicit none
175+
176+
type(IPD_control_type), intent(inout) :: IPD_Control
177+
type(IPD_data_type), intent(inout) :: IPD_Data(:)
178+
type(IPD_diag_type), intent(inout) :: IPD_Diag(:)
179+
type(IPD_restart_type), intent(inout) :: IPD_Restart
180+
type (block_control_type), intent(in) , optional :: Atm_block
181+
type(IPD_init_type), intent(in) , optional :: Init_parm
182+
real(kind=kind_phys), intent(inout), optional :: l_salp_data
183+
real(kind=kind_phys), intent(inout), optional :: l_snupx(max_vegtyp)
184+
character(len=256), intent(in), optional :: ccpp_suite
185+
integer, intent(in) :: step
186+
! Local variables
187+
integer :: ierr
188+
189+
if (step==0) then
190+
if (.not. present(Atm_block)) then
191+
! DH* TODO - NEED PROPER ERROR HANDLING HERE
192+
print *, "IPD init step called without mandatory Atm_block argument"
193+
stop
194+
else if (.not. present(Init_parm)) then
195+
! DH* TODO - NEED PROPER ERROR HANDLING HERE
196+
print *, "IPD init step called without mandatory Init_parm argument"
197+
stop
198+
else if (.not. present(l_salp_data)) then
199+
! DH* TODO - NEED PROPER ERROR HANDLING HERE
200+
print *, "IPD init step called without mandatory l_salp_data argument"
201+
stop
202+
else if (.not. present(l_snupx)) then
203+
! DH* TODO - NEED PROPER ERROR HANDLING HERE
204+
print *, "IPD init step called without mandatory l_snupx argument"
205+
stop
206+
else if (.not. present(ccpp_suite)) then
207+
! DH* TODO - NEED PROPER ERROR HANDLING HERE
208+
print *, "IPD init step called without mandatory ccpp_suite argument"
209+
stop
210+
end if
211+
212+
!--- Initialize CCPP
213+
call ccpp_init(ccpp_suite, cdata, ierr)
214+
215+
! Begin include auto-generated list of calls to ccpp_fields_add
216+
! DH* #include "ccpp_fields.inc"
217+
! End include auto-generated list of calls to ccpp_fields_add
218+
219+
!--- Add the DDTs to the CCPP data structure
220+
call ccpp_fields_add(cdata, 'IPD_Control', '', c_loc(IPD_Control), &
221+
ierr=ierr)
222+
call ccpp_fields_add(cdata, 'IPD_Data', '', c_loc(IPD_Data), &
223+
size(IPD_Data), shape(IPD_Data), ierr)
224+
call ccpp_fields_add(cdata, 'IPD_Diag', '', c_loc(IPD_Diag), &
225+
size(IPD_Diag), shape(IPD_Diag), ierr)
226+
call ccpp_fields_add(cdata, 'IPD_Restart', '', c_loc(IPD_Restart), ierr=ierr)
227+
call ccpp_fields_add(cdata, 'Atm_block', '', c_loc(Atm_block), ierr=ierr)
228+
call ccpp_fields_add(cdata, 'Init_parm', '', c_loc(Init_parm), ierr=ierr)
229+
call ccpp_fields_add(cdata, 'nblks', Atm_block%nblks, ierr, '')
230+
call ccpp_fields_add(cdata, 'salp_data', l_salp_data, ierr)
231+
call ccpp_fields_add(cdata, 'snupx', l_snupx, ierr)
232+
233+
call ccpp_run(cdata%suite%init, cdata, ierr)
234+
!else if (step==X) then
235+
! !--- Finalize CCPP
236+
! call ccpp_init(ccpp_suite, cdata, ierr)
237+
else
238+
call ccpp_run(cdata%suite%ipds(1)%subcycles(1)%schemes(step), cdata, ierr)
239+
end if
240+
end subroutine IPD_step
241+
#endif
242+
243+
141244
end module IPD_driver

makefile

+23-6
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,20 @@ VER_PATCH = 0
2222

2323
FFLAGS += -I../fms -I../fms/include -fPIC
2424

25-
CPPDEFS = -DNEW_TAUCTMAX -DSMALL_PE -DNEMS_GSM
25+
CPPDEFS += -DNEW_TAUCTMAX -DSMALL_PE -DNEMS_GSM
26+
27+
28+
ifneq (,$(findstring CCPP_DIRECT,$(CPPDEFS)))
29+
# CCPP without IPD
30+
IPD_DRIVER_CAP = ./IPD_layer/IPD_driver_cap.F90
31+
else ifneq (,$(findstring CCPP_IPD,$(CPPDEFS)))
32+
# IPD with CCPP
33+
IPD_DRIVER_CAP = ./IPD_layer/IPD_driver_cap.F90
34+
else
35+
# IPD without CCPP
36+
IPD_DRIVER_CAP =
37+
endif
38+
2639

2740
SRCS_f = \
2841
./physics/cnvc90.f \
@@ -144,14 +157,15 @@ SRCS_F90 = \
144157
./GFS_layer/GFS_radiation_driver.F90 \
145158
./GFS_layer/GFS_restart.F90 \
146159
./GFS_layer/GFS_typedefs.F90 \
147-
./IPD_layer/IPD_driver_cap.F90 \
148160
./IPD_layer/IPD_driver.F90 \
149161
./IPD_layer/IPD_typedefs.F90
150162

151-
152163
SRCS_c =
153164

154-
DEPEND_FILES = $(SRCS_f) $(SRCS_f90) $(SRCS_F) $(SRCS_F90)
165+
CAPS_F90 = \
166+
$(IPD_DRIVER_CAP)
167+
168+
DEPEND_FILES = $(SRCS_f) $(SRCS_f90) $(SRCS_F) $(SRCS_F90) $(CAPS_F90)
155169

156170
OBJS_f = $(SRCS_f:.f=.o)
157171
OBJS_f90 = $(SRCS_f90:.f90=.o)
@@ -161,10 +175,13 @@ OBJS_c = $(SRCS_c:.c=.o)
161175

162176
OBJS = $(OBJS_f) $(OBJS_f90) $(OBJS_F) $(OBJS_F90) $(OBJS_c)
163177

178+
CAPS = $(CAPS_F90:.F90=.o)
179+
164180
all default: depend $(LIBRARY)
165181

166-
$(LIBRARY): $(OBJS)
167-
$(FC) -shared -Wl,-soname,$(LIBRARY).$(VER_MAJOR) $(OBJS) $(LDFLAGS) $(NCEPLIBS) -o $(LIBRARY).$(VER_MAJOR).$(VER_MINOR).$(VER_PATCH)
182+
$(LIBRARY): $(OBJS) $(CAPS)
183+
$(FC) -shared -Wl,-soname,$(LIBRARY).$(VER_MAJOR) $(OBJS) $(CAPS) $(LDFLAGS) $(NCEPLIBS) -o $(LIBRARY).$(VER_MAJOR).$(VER_MINOR).$(VER_PATCH)
184+
# DH* placeholder for PGI fix of cap object names in shared library
168185
ln -sf $(LIBRARY).$(VER_MAJOR).$(VER_MINOR).$(VER_PATCH) $(LIBRARY)
169186
ln -sf $(LIBRARY).$(VER_MAJOR).$(VER_MINOR).$(VER_PATCH) $(LIBRARY).$(VER_MAJOR)
170187

0 commit comments

Comments
 (0)