ROMS
Loading...
Searching...
No Matches
esmf_driver.h
Go to the documentation of this file.
1 PROGRAM esmf_driver
2!
3!git $Id$
4!=======================================================================
5! Copyright (c) 2002-2025 The ROMS Group !
6! Licensed under a MIT/X style license Hernan G. Arango !
7! See License_ROMS.md Ufuk Utku Turuncoglu !
8!=======================================================================
9! !
10! Master program to couple ROMS to other Earth System Models !
11! (ESM) using the ESMF library with the NUOPC layer. !
12! !
13! ESMF: Earth System Modeling Framework (Version 7 or higher) !
14! NUOPC: National Unified Operational Prediction Capability !
15! !
16!=======================================================================
17!
18 USE esmf
19!
20 USE mod_esmf_esm ! ESM coupling structures and variables
21!
23!
24 implicit none
25!
26! Local variable declarations.
27!
28 integer :: rc, urc
29!
30 character (len=*), parameter :: myfile = &
31 & __FILE__
32!
33 TYPE (esmf_gridcomp) :: driver
34 TYPE (esmf_logkind_flag) :: logkindflag
35!
36!-----------------------------------------------------------------------
37! Initialize ESMF coupling.
38!-----------------------------------------------------------------------
39!
40! It is optimal to have a single log file using ESMF_LOGKIND_SINGLE
41! combining messages from all PETs. However, it is not supported on
42! some platforms. If this is the case, use ESMF_LOGKIND_MULTI to
43! create one log file per PET. This is kind of annoying. In
44! applications using s large number of processors, opening a large
45! number of log files and writing messages can be a bottleneck.
46!
47 logkindflag=esmf_logkind_single
48!! LogKindFlag=ESMF_LOGKIND_MULTI
49!
50! Initialize ESMF.
51!
52 CALL esmf_initialize (defaultlogfilename=trim(esmnamelog), &
53 & logappendflag=.false., &
54 & logkindflag=logkindflag, &
55 & vm=vmdriver, &
56 & rc=rc)
57 IF (esmf_logfounderror(rctocheck=rc, &
58 & msg=esmf_logerr_passthru, &
59 & line=__line__, &
60 & file=myfile)) THEN
61 CALL esmf_finalize (endflag=esmf_end_abort)
62 END IF
63!
64!-----------------------------------------------------------------------
65! Create ESM component.
66!-----------------------------------------------------------------------
67!
68 driver=esmf_gridcompcreate(name="roms_esm", &
69 & rc=rc)
70 IF (esmf_logfounderror(rctocheck=rc, &
71 & msg=esmf_logerr_passthru, &
72 & line=__line__, &
73 & file=myfile)) THEN
74 CALL esmf_finalize (endflag=esmf_end_abort)
75 END IF
76!
77!-----------------------------------------------------------------------
78! Coupling ESM configuration.
79!-----------------------------------------------------------------------
80!
81! Read in coupling ESM configuration parameters from standard input.
82! (See "ROMS/External/coupling_esmf.in").
83!
84 CALL read_esmconfig (vmdriver, rc)
85 IF (esmf_logfounderror(rctocheck=rc, &
86 & msg=esmf_logerr_passthru, &
87 & line=__line__, &
88 & file=myfile)) THEN
89 CALL esmf_finalize (endflag=esmf_end_abort)
90 END IF
91!
92! Set user defined ESM log.
93!
94 IF (tracelevel.ge.2) THEN
95 CALL esmf_logset (flush=.true., &
96 & logmsglist=(/ esmf_logmsg_all /), &
97 & trace=.true., &
98 & rc=rc)
99 IF (esmf_logfounderror(rctocheck=rc, &
100 & msg=esmf_logerr_passthru, &
101 & line=__line__, &
102 & file=myfile)) THEN
103 CALL esmf_finalize (endflag=esmf_end_abort)
104 END IF
105 ELSE
106 CALL esmf_logset (flush=.true., &
107 & logmsglist=(/ esmf_logmsg_notrace /), &
108 & trace=.false., &
109 & rc=rc)
110 IF (esmf_logfounderror(rctocheck=rc, &
111 & msg=esmf_logerr_passthru, &
112 & line=__line__, &
113 & file=myfile)) THEN
114 CALL esmf_finalize (endflag=esmf_end_abort)
115 END IF
116 END IF
117!
118! Read in and set import and export fields metadata. Add additional
119! fields to NOUPC dictionary.
120!
121 CALL set_metadata (vmdriver, rc)
122 IF (esmf_logfounderror(rctocheck=rc, &
123 & msg=esmf_logerr_passthru, &
124 & line=__line__, &
125 & file=myfile)) THEN
126 CALL esmf_finalize (endflag=esmf_end_abort)
127 END IF
128!
129!-----------------------------------------------------------------------
130! Register ESM components.
131!-----------------------------------------------------------------------
132!
133 CALL esmf_gridcompsetservices (driver, &
134 & esm_setservices, &
135 & userrc=urc, &
136 & rc=rc)
137 IF (esmf_logfounderror(rctocheck=rc, &
138 & msg=esmf_logerr_passthru, &
139 & line=__line__, &
140 & file=myfile)) THEN
141 CALL esmf_finalize (endflag=esmf_end_abort)
142 END IF
143 IF (esmf_logfounderror(rctocheck=urc, &
144 & msg=esmf_logerr_passthru, &
145 & line=__line__, &
146 & file=myfile)) THEN
147 CALL esmf_finalize (endflag=esmf_end_abort)
148 END IF
149!
150!-----------------------------------------------------------------------
151! Initialize ESM component.
152!-----------------------------------------------------------------------
153!
154 CALL esmf_gridcompinitialize (driver, &
155 & userrc=urc, &
156 & rc=rc)
157 IF (esmf_logfounderror(rctocheck=rc, &
158 & msg=esmf_logerr_passthru, &
159 & line=__line__, &
160 & file=myfile)) THEN
161 CALL esmf_finalize (endflag=esmf_end_abort)
162 END IF
163 IF (esmf_logfounderror(rctocheck=urc, &
164 & msg=esmf_logerr_passthru, &
165 & line=__line__, &
166 & file=myfile)) THEN
167 CALL esmf_finalize (endflag=esmf_end_abort)
168 END IF
169!
170! Wait for the initialization phase to finish.
171!
172 CALL esmf_vmbarrier (vmdriver, rc=rc)
173 IF (esmf_logfounderror(rctocheck=rc, &
174 & msg=esmf_logerr_passthru, &
175 & line=__line__, &
176 & file=myfile)) THEN
177 CALL esmf_finalize (endflag=esmf_end_abort)
178 END IF
179!
180!-----------------------------------------------------------------------
181! Run ESM components.
182!-----------------------------------------------------------------------
183!
184 CALL esmf_gridcomprun (driver, &
185 & userrc=urc, &
186 & rc=rc)
187 IF (esmf_logfounderror(rctocheck=rc, &
188 & msg=esmf_logerr_passthru, &
189 & line=__line__, &
190 & file=myfile)) THEN
191 CALL esmf_finalize (endflag=esmf_end_abort)
192 END IF
193 IF (esmf_logfounderror(rctocheck=urc, &
194 & msg=esmf_logerr_passthru, &
195 & line=__line__, &
196 & file=myfile)) THEN
197 CALL esmf_finalize (endflag=esmf_end_abort)
198 END IF
199!
200!-----------------------------------------------------------------------
201! Finalize ESM components.
202!-----------------------------------------------------------------------
203!
204 CALL esmf_gridcompfinalize (driver, &
205 & userrc=urc, &
206 & rc=rc)
207 IF (esmf_logfounderror(rctocheck=rc, &
208 & msg=esmf_logerr_passthru, &
209 & line=__line__, &
210 & file=myfile)) THEN
211 CALL esmf_finalize (endflag=esmf_end_abort)
212 END IF
213 IF (esmf_logfounderror(rctocheck=urc, &
214 & msg=esmf_logerr_passthru, &
215 & line=__line__, &
216 & file=myfile)) THEN
217 CALL esmf_finalize (endflag=esmf_end_abort)
218 END IF
219!
220!-----------------------------------------------------------------------
221! Destroy ESM components.
222!-----------------------------------------------------------------------
223!
224 CALL esmf_gridcompdestroy (driver, &
225 & rc=rc)
226 IF (esmf_logfounderror(rctocheck=rc, &
227 & msg=esmf_logerr_passthru, &
228 & line=__line__, &
229 & file=myfile)) THEN
230 CALL esmf_finalize (endflag=esmf_end_abort)
231 END IF
232!
233!-----------------------------------------------------------------------
234! Finalize ESMF coupling.
235!-----------------------------------------------------------------------
236!
237 CALL esmf_finalize (rc=rc)
238!
239! Flush and lose coupling standard out unit.
240!
241 FLUSH (cplout)
242 CLOSE (cplout)
243!
244 stop
245 END PROGRAM esmf_driver
program esmf_driver
Definition esmf_driver.h:1
subroutine, public esm_setservices(driver, rc)
Definition esmf_esm.F:89
subroutine, public set_metadata(vm, rc)
type(esmf_vm) vmdriver
integer tracelevel
character(len=8), parameter esmnamelog
subroutine, public read_esmconfig(vm, rc)