-
Notifications
You must be signed in to change notification settings - Fork 47
/
Copy pathMAIN_NEMS.F90
556 lines (540 loc) · 27 KB
/
MAIN_NEMS.F90
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
#define ESMF_ERR_ABORT(rc) if (ESMF_LogFoundError(rc, msg="Aborting NEMS", line=__LINE__, file=__FILE__)) call ESMF_Finalize(endflag=ESMF_END_ABORT)
!-----------------------------------------------------------------------
!
PROGRAM MAIN_NEMS
!
!-----------------------------------------------------------------------
!*** Main Program for NEMS.
!*** Define ESMF data types and procedures.
!-----------------------------------------------------------------------
!
!-----------------------------------------------------------------------
!
! PROGRAM HISTORY LOG:
! 2007- Black - Modified from Wei-yu's version
! 2007-09 Black - Create the Clock here.
! 2009-08 Colon - Unified NEM-NMM & NEMS-GFS
! 2009-06-29 Black - Modified for addition of NMM nesting;
! added new ATM Driver Component.
! 2009-09 Lu - Add w3tage calls for resource statistics
! 2009-08 W. Yang - Ensemble GEFS Concurrency Code.
! 2010-03 Jovic/Black - Revised to create NEMS gridded component
! for new structure.
! 2010-04 Yang - Add GEFS and GFS for the revised NEMS.
! 2010-11 Yang - Add the "Generic Core" to NEMS
! 2011-02 Yang - Updated to use both the ESMF 4.0.0rp2 library,
! ESMF 5 series library and the the
! ESMF 3.1.0rp2 library.
! 2011-05 Theurich & Yang - Modified for using the ESMF 5.2.0r_beta_snapshot_07.
! 2011-10 Yang - Modified for using the ESMF 5.2.0r library.
! 2013-07 Theurich - Macro based ESMF error handling
! 2016-11 Trahan - Resource usage reporting
!
!-----------------------------------------------------------------------
!
USE MPI
USE ESMF
!
!-----------------------------------------------------------------------
!*** USE the EARTH gridded component module. Although it
!*** contains the calls to Register and the top level Initialize,
!*** Run, and Finalize, only the Register routine is public.
!-----------------------------------------------------------------------
!
USE module_EARTH_GRID_COMP
!
!-----------------------------------------------------------------------
!*** The following module contains error-checking, and other utilities
!-----------------------------------------------------------------------
!
! USE module_NEMS_UTILS, ONLY: check_esmf_pet, message_check
!
!-----------------------------------------------------------------------
!*** This module calculates resource usage across all ranks.
!-----------------------------------------------------------------------
!
USE module_NEMS_Rusage,ONLY: NEMS_Rusage
!
!-----------------------------------------------------------------------
!
IMPLICIT NONE
!
!-----------------------------------------------------------------------
!*** Local Variables.
!-----------------------------------------------------------------------
!
INTEGER :: MYPE & !<-- The MPI task ID
,NSECONDS_FCST & !<-- Length of forecast in seconds
,YY,MM,DD & !<-- Time variables for date
,HH,MNS,SEC & !<-- Time variables for time of day
,fhrot
!
REAL :: NHOURS_FCST !<-- Length of forecast in hours
TYPE(NEMS_Rusage) :: rusage !<-- Resource usage tracking object
TYPE(ESMF_TimeInterval) :: RUNDURATION & !<-- The ESMF time. The total forecast hours.
,TIMESTEP & !<-- The ESMF timestep length (we only need a dummy here)
,restartOffset
!
TYPE(ESMF_Time) :: CURRTIME & !<-- The ESMF current time.
,STARTTIME !<-- The ESMF start time.
!
TYPE(ESMF_VM) :: VM !<-- The ESMF virtual machine,
! which contains and manages
! the computer CPU resource
! for the ESMF grid components.
!
TYPE(ESMF_GridComp) :: EARTH_GRID_COMP !<-- The EARTH gridded component.
!
TYPE(ESMF_Clock) :: CLOCK_MAIN !<-- The ESMF time management clock
!
TYPE(ESMF_Config) :: CF_MAIN !<-- The Configure object
!
LOGICAL :: PRINT_ESMF !<-- Flag for ESMF PET files
!
CHARACTER(ESMF_MAXSTR) :: MESSAGE_CHECK
!
INTEGER :: RC, RC_USER !<-- The running error signal
!
CHARACTER(LEN=MPI_MAX_PROCESSOR_NAME) :: PROCNAME !<-- The processor(host) name
INTEGER :: PROCNAME_LEN !<-- Actual PROCRNAME string length
!
!-----------------------------------------------------------------------
!***********************************************************************
!-----------------------------------------------------------------------
!
!-----------------------------------------------------------------------
!*** Check if we want ESMF PET files or not
!-----------------------------------------------------------------------
!
CALL CHECK_ESMF_PET(PRINT_ESMF)
!
!-----------------------------------------------------------------------
!*** Initialize the ESMF framework.
!-----------------------------------------------------------------------
!
IF(PRINT_ESMF) THEN
CALL ESMF_Initialize(VM =VM & !<-- The ESMF Virtual Machine
,defaultCalKind =ESMF_CALKIND_GREGORIAN & !<-- Set up the default calendar.
,logkindflag =ESMF_LOGKIND_MULTI & !<-- Define multiple log error output files;
,rc =RC)
ESMF_ERR_ABORT(RC)
ELSE
CALL ESMF_Initialize(VM =VM & !<-- The ESMF Virtual Machine
,defaultCalKind =ESMF_CALKIND_GREGORIAN & !<-- Set up the default calendar.
,logkindflag =ESMF_LOGKIND_NONE & !<-- Define no log error output files;
,rc =RC)
ESMF_ERR_ABORT(RC)
ENDIF
!
!-----------------------------------------------------------------------
!*** Get the processor(host) name
!-----------------------------------------------------------------------
!
CALL MPI_Get_processor_name(PROCNAME,PROCNAME_LEN,RC)
! write(0,*)'processor_name =',trim(PROCNAME)
!
!-----------------------------------------------------------------------
!*** Extract the MPI task ID.
!-----------------------------------------------------------------------
!
! ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
MESSAGE_CHECK="MAIN: Obtain the local task ID"
! CALL ESMF_LogWrite(MESSAGE_CHECK,ESMF_LOGMSG_INFO,rc=RC)
! ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
!
CALL ESMF_VMGet(vm =VM & !<-- The ESMF Virtual Machine
,localpet=MYPE & !<-- The local MPI task ID
,rc =RC)
ESMF_ERR_ABORT(RC)
! ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
!
!-----------------------------------------------------------------------
!*** Print subversion version and other status information.
!-----------------------------------------------------------------------
!
if (mype==0) call w3tagb('nems ',0000,0000,0000,'np23 ')
!
!-----------------------------------------------------------------------
!*** Start gathering resource usage information.
!-----------------------------------------------------------------------
!
! Note intentional use of MPI_COMM_WORLD since we are getting
! resource usage for ALL ranks on ALL machines.
call rusage%start(MPI_COMM_WORLD,PROCNAME,PROCNAME_LEN,RC)
! It is safe to ignore RC since rusage%is_valid will tell us if
! the start succeeded.
!
!-----------------------------------------------------------------------
!*** Set up the default log.
!-----------------------------------------------------------------------
!
! ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
MESSAGE_CHECK="Set Up ESMF Log"
! CALL ESMF_LogWrite(MESSAGE_CHECK,ESMF_LOGMSG_INFO,rc=RC)
! ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
!
IF(PRINT_ESMF) THEN
CALL ESMF_LogSet(flush =.false. &
,trace =.false. &
,rc =RC)
ESMF_ERR_ABORT(RC)
ENDIF
! ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
!
!-----------------------------------------------------------------------
!*** Create and load the Configure object which will hold the contents
!*** of the Main configure file.
!-----------------------------------------------------------------------
!
! ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
MESSAGE_CHECK="Create/Load the Main Configure Object"
! CALL ESMF_LogWrite(MESSAGE_CHECK,ESMF_LOGMSG_INFO,rc=RC)
! ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
!
CF_MAIN=ESMF_ConfigCreate(rc=RC)
!
CALL ESMF_ConfigLoadFile(config =CF_MAIN & !<-- The Configure object
,filename='model_configure' & !<-- The name of the configure file
,rc =RC)
ESMF_ERR_ABORT(RC)
! ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
!
!-----------------------------------------------------------------------
!*** Create the EARTH gridded component which will create and
!*** control the ATM (atmoshpere), OCN (ocean), ICE (sea ice), etc.
!*** gridded components.
!-----------------------------------------------------------------------
!
! ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
MESSAGE_CHECK="Create the EARTH Gridded Component"
! CALL ESMF_LogWrite(MESSAGE_CHECK,ESMF_LOGMSG_INFO,rc=RC)
! ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
!
EARTH_GRID_COMP=ESMF_GridCompCreate(name ='EARTH Grid Comp' & !<-- EARTH component name
,rc = RC)
ESMF_ERR_ABORT(RC)
! ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
!
!-----------------------------------------------------------------------
!*** Register the EARTH gridded component's Initialize, Run and
!*** Finalize routines.
!-----------------------------------------------------------------------
!
! ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
MESSAGE_CHECK="Register EARTH Gridded Component Init, Run, Finalize"
! CALL ESMF_LogWrite(MESSAGE_CHECK,ESMF_LOGMSG_INFO,rc=RC)
! ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
!
CALL ESMF_GridCompSetServices(EARTH_GRID_COMP & !<-- The EARTH component
,EARTH_REGISTER & !<-- User's subroutineName
,rc=RC)
ESMF_ERR_ABORT(RC)
! ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
!
!-----------------------------------------------------------------------
!*** Create the main ESMF Clock.
!*** The Clock is needed for all calls to Init, Run, and Finalize.
!
! ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
!
!-----------------------------------------------------------------------
!*** Set the start time in the Main Clock.
!-----------------------------------------------------------------------
!
! ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
MESSAGE_CHECK="MAIN: Extract Starting Year from Config File"
! CALL ESMF_LogWrite(MESSAGE_CHECK,ESMF_LOGMSG_INFO,rc=RC)
! ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
!
CALL ESMF_ConfigGetAttribute(config=CF_MAIN &
,value =YY &
,label ='start_year:' &
,rc =RC)
ESMF_ERR_ABORT(RC)
! ~ ~ ~ ~ ~ ~ ~ ~ ~ ~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 ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
MESSAGE_CHECK="MAIN: Extract Starting Second from Config File"
! CALL ESMF_LogWrite(MESSAGE_CHECK,ESMF_LOGMSG_INFO,rc=RC)
! ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
!
CALL ESMF_ConfigGetAttribute(config=CF_MAIN &
,value =SEC &
,label ='start_second:' &
,rc =RC)
ESMF_ERR_ABORT(RC)
! ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
!
! ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
MESSAGE_CHECK="MAIN: Set the Forecast Start Time"
! CALL ESMF_LogWrite(MESSAGE_CHECK,ESMF_LOGMSG_INFO,rc=RC)
! ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
!
CALL ESMF_TimeSet(time=STARTTIME & !<-- The start time of the forecast (ESMF)
,yy =YY & !<-- Year from config file
,mm =MM & !<-- Month from config file
,dd =DD & !<-- Day from config file
,h =HH & !<-- Hour from config file
,m =MNS & !<-- Minute from config file
,s =SEC & !<-- Second from config file
,rc =RC)
ESMF_ERR_ABORT(RC)
! ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
!
!-----------------------------------------------------------------------
!*** Set the run duration in the Main Clock.
!-----------------------------------------------------------------------
!
! ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
MESSAGE_CHECK="MAIN: Extract Forecast Length from Config File"
! CALL ESMF_LogWrite(MESSAGE_CHECK,ESMF_LOGMSG_INFO,rc=RC)
! ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
!
CALL ESMF_ConfigGetAttribute(config=CF_MAIN &
,value =NHOURS_FCST &
,label ='nhours_fcst:' &
,rc =RC)
ESMF_ERR_ABORT(RC)
! ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
!
NSECONDS_FCST=nint(NHOURS_FCST*3600.) !<-- The forecast length (sec) (REAL)
!
!-----------------------------------------------------------------------
!
! ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
MESSAGE_CHECK="MAIN: Set the Forecast Length"
! CALL ESMF_LogWrite(MESSAGE_CHECK,ESMF_LOGMSG_INFO,rc=RC)
! ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
!
CALL ESMF_TimeIntervalSet(timeinterval=RUNDURATION & !<-- The forecast length (s) (ESMF)
,s =NSECONDS_FCST &
,rc =RC)
ESMF_ERR_ABORT(RC)
! ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
!
!-----------------------------------------------------------------------
!*** Now the Main Clock can be created.
!-----------------------------------------------------------------------
!
! ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
MESSAGE_CHECK="Create the Main Clock"
! CALL ESMF_LogWrite(MESSAGE_CHECK,ESMF_LOGMSG_INFO,rc=RC)
! ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
!
! NUOPC requires a correct timeStep to function. Here TIMESTEP was just created
! pro forma, but now is replaced with RUNDURATION to become meaningful.
TIMESTEP = RUNDURATION
CLOCK_MAIN=ESMF_ClockCreate(name ='CLOCK_MAIN' & !<-- The top-level ESMF Clock
,timeStep =TIMESTEP & !<-- Timestep needed by the Clock (ESMF)
,startTime =STARTTIME & !<-- The integration start time (ESMF)
,runDuration=RUNDURATION & !<-- The integration duration (ESMF)
,rc =RC)
ESMF_ERR_ABORT(RC)
! ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
!
!-----------------------------------------------------------------------
!*** Adjust the currTime of the main clock: CLOCK_MAIN
!*** if the fhrot is > 0
!*** This will correctly set the EARTH clocks in case of
!*** Restart-From-History.
!-----------------------------------------------------------------------
CALL ESMF_ConfigGetAttribute(config = CF_MAIN &
,value = fhrot &
,label = 'fhrot:' &
,default = 0 &
,rc = RC)
ESMF_ERR_ABORT(RC)
if (fhrot > 0) then
CALL ESMF_TimeIntervalSet(restartOffset, h=fhrot, rc=RC)
ESMF_ERR_ABORT(RC)
CURRTIME = STARTTIME + restartOffset
call ESMF_ClockSet(CLOCK_MAIN, currTime=CURRTIME, rc=RC)
ESMF_ERR_ABORT(RC)
endif
! ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
!
!-----------------------------------------------------------------------
!*** Execute the INITIALIZE step for the EARTH component.
!*** The Initialize routine that is called here as well as the
!*** Run and Finalize routines invoked below are those specified
!*** in the Register routine called in ESMF_GridCompSetServices above.
!-----------------------------------------------------------------------
!
! ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
MESSAGE_CHECK="Execute the EARTH Component Initialize Step"
! CALL ESMF_LogWrite(MESSAGE_CHECK,ESMF_LOGMSG_INFO,rc=RC)
! ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
!
CALL ESMF_GridCompInitialize(gridcomp =EARTH_GRID_COMP & !<-- The EARTH component
,clock =CLOCK_MAIN & !<-- The ESMF clock
,userRc =RC_USER &
,rc =RC)
ESMF_ERR_ABORT(RC)
ESMF_ERR_ABORT(RC_USER)
! ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
!
!-----------------------------------------------------------------------
!*** Execute the RUN step for the EARTH component.
!-----------------------------------------------------------------------
!
! ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
MESSAGE_CHECK="Execute the EARTH Component Run Step"
! CALL ESMF_LogWrite(MESSAGE_CHECK,ESMF_LOGMSG_INFO,rc=RC)
! ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
!
CALL ESMF_GridCompRun(gridcomp =EARTH_GRID_COMP & !<-- The EARTH component
,clock =CLOCK_MAIN & !<-- The ESMF clock
,userRc =RC_USER &
,rc =RC)
ESMF_ERR_ABORT(RC)
ESMF_ERR_ABORT(RC_USER)
! ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
!
!-----------------------------------------------------------------------
!*** Execute the FINALIZE step for the EARTH component.
!-----------------------------------------------------------------------
!
! ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
MESSAGE_CHECK="Execute the EARTH Component Finalize Step"
! CALL ESMF_LogWrite(MESSAGE_CHECK,ESMF_LOGMSG_INFO,rc=RC)
! ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
!
CALL ESMF_GridCompFinalize(gridcomp =EARTH_GRID_COMP & !<-- The EARTH component
,clock =CLOCK_MAIN & !<-- The Main ESMF clock
,userRc =RC_USER &
,rc =RC)
ESMF_ERR_ABORT(RC)
ESMF_ERR_ABORT(RC_USER)
! ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
!
!-----------------------------------------------------------------------
!*** Destroy the Main Clock.
!-----------------------------------------------------------------------
!
! ~ ~ ~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= RC)
! ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
!
CALL ESMF_GridCompDestroy(gridcomp=EARTH_GRID_COMP &
,rc =RC)
ESMF_ERR_ABORT(RC)
! ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
! Resource usage reporting. We only do this if the rusage%start was
! successful.
if(rusage%is_valid()) then
call rusage%stop(rc)
if(rc==0) call rusage%report(rc)
endif
!-----------------------------------------------------------------------
!*** Shut down the ESMF system.
!-----------------------------------------------------------------------
!
CALL ESMF_Finalize()
!
!-----------------------------------------------------------------------
!
if(mype==0)call w3tage('nems ')
!
!-----------------------------------------------------------------------
!
contains
subroutine check_esmf_pet(print_esmf)
implicit none
integer :: i,n
character *256 :: c1,c2
logical :: opened,print_esmf
do n=101,201
inquire(n,opened=opened)
if(.not.opened)then
open(n,file='model_configure',status='old') !<-- Open configure file
exit
endif
enddo
print_esmf=.false.
do i=1,10000
read(n,*,end=22)c1,c2
if(c1(1:10) == 'print_esmf') then !<-- Search for print_esmf flag
if( c2 == 'true' .or. & !<-- Check if print_esmf is true or false
c2 == '.true.' .or. &
c2 == 'TRUE' .or. &
c2 == '.TRUE.' ) print_esmf=.true.
exit
endif
enddo
22 close(n)
return
end subroutine check_esmf_pet
END PROGRAM MAIN_NEMS
!
!-----------------------------------------------------------------------