forked from NOAA-EMC/fv3atm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
module_fcst_grid_comp.F90
1307 lines (1119 loc) · 58.4 KB
/
module_fcst_grid_comp.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
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#define ESMF_ERR_ABORT(rc) \
if (rc /= ESMF_SUCCESS) write(0,*) 'rc=',rc,__FILE__,__LINE__; if(ESMF_LogFoundError(rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) call ESMF_Finalize(endflag=ESMF_END_ABORT)
!-----------------------------------------------------------------------
!
module module_fcst_grid_comp
!
!-----------------------------------------------------------------------
!*** Forecast gridded component.
!-----------------------------------------------------------------------
!***
!*** HISTORY
!***
! Apr 2017: J. Wang - initial code for forecast grid component
!
!---------------------------------------------------------------------------------
!
use mpi
use esmf
use time_manager_mod, only: time_type, set_calendar_type, set_time, &
set_date, month_name, &
operator(+), operator(-), operator (<), &
operator (>), operator (/=), operator (/), &
operator (==), operator (*), &
THIRTY_DAY_MONTHS, JULIAN, GREGORIAN, &
NOLEAP, NO_CALENDAR, &
date_to_string, get_date, get_time
use atmos_model_mod, only: atmos_model_init, atmos_model_end, &
get_atmos_model_ungridded_dim, &
update_atmos_model_dynamics, &
update_atmos_radiation_physics, &
update_atmos_model_state, &
atmos_data_type, atmos_model_restart, &
atmos_model_exchange_phase_1, &
atmos_model_exchange_phase_2, &
addLsmask2grid, atmos_model_get_nth_domain_info
use constants_mod, only: constants_init
use fms_mod, only: error_mesg, fms_init, fms_end, &
write_version_number, uppercase
use mpp_mod, only: mpp_init, mpp_pe, mpp_npes, mpp_root_pe, &
mpp_error, FATAL, WARNING, NOTE
use mpp_mod, only: mpp_clock_id, mpp_clock_begin
use mpp_io_mod, only: mpp_open, mpp_close, MPP_DELETE
use mpp_domains_mod, only: mpp_get_compute_domains, domain2D
use sat_vapor_pres_mod, only: sat_vapor_pres_init
use diag_manager_mod, only: diag_manager_init, diag_manager_end, &
diag_manager_set_time_end
use data_override_mod, only: data_override_init
use fv_nggps_diags_mod, only: fv_dyn_bundle_setup
use fv3gfs_io_mod, only: fv_phys_bundle_setup
use fms_io_mod, only: field_exist, read_data
use atmosphere_mod, only: atmosphere_control_data
use module_fv3_io_def, only: num_pes_fcst, num_files, filename_base, &
nbdlphys, iau_offset
use module_fv3_config, only: dt_atmos, fcst_mpi_comm, fcst_ntasks, &
quilting, calendar, &
cplprint_flag, restart_endfcst
use get_stochy_pattern_mod, only: write_stoch_restart_atm
!
!-----------------------------------------------------------------------
!
implicit none
!
!-----------------------------------------------------------------------
!
private
!
!---- model defined-types ----
type(atmos_data_type), save :: Atmos
type(ESMF_GridComp),dimension(:),allocatable :: fcstGridComp
type(ESMF_Grid), dimension(:),allocatable :: fcstGrid
integer :: ngrids, mygrid
integer,dimension(:),allocatable :: grid_number_on_all_pets(:)
integer :: intrm_rst, n_atmsteps
!----- coupled model data -----
integer :: calendar_type = -99
integer :: date_init(6)
integer :: numLevels = 0
integer :: numSoilLayers = 0
integer :: numTracers = 0
integer :: frestart(999)
!
!-----------------------------------------------------------------------
!
public SetServices, fcstGrid, ngrids, mygrid, grid_number_on_all_pets
public numLevels, numSoilLayers, numTracers
!
contains
!
!-----------------------------------------------------------------------
!#######################################################################
!-----------------------------------------------------------------------
!
subroutine SetServices(fcst_comp, rc)
!
type(ESMF_GridComp) :: fcst_comp
integer, intent(out) :: rc
rc = ESMF_SUCCESS
call ESMF_GridCompSetEntryPoint(fcst_comp, ESMF_METHOD_INITIALIZE, &
userRoutine=fcst_initialize, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
!
call ESMF_GridCompSetEntryPoint(fcst_comp, ESMF_METHOD_RUN, &
userRoutine=fcst_run_phase_1, phase=1, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
call ESMF_GridCompSetEntryPoint(fcst_comp, ESMF_METHOD_RUN, &
userRoutine=fcst_run_phase_2, phase=2, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
!
call ESMF_GridCompSetEntryPoint(fcst_comp, ESMF_METHOD_FINALIZE, &
userRoutine=fcst_finalize, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
end subroutine SetServices
!
!-----------------------------------------------------------------------
!#######################################################################
!-----------------------------------------------------------------------
!
subroutine SetServicesNest(nest, rc)
!
type(ESMF_GridComp) :: nest
integer, intent(out) :: rc
character(len=80) :: name
type(ESMF_Grid) :: grid
type(ESMF_Info) :: info
integer :: layout(2), tilesize
integer :: tl, nx, ny
integer,dimension(2,6):: decomptile !define delayout for the 6 cubed-sphere tiles
integer,dimension(2) :: regdecomp !define delayout for the nest grid
type(ESMF_Decomp_Flag):: decompflagPTile(2,6)
rc = ESMF_SUCCESS
call ESMF_GridCompSetEntryPoint(nest, ESMF_METHOD_INITIALIZE, userRoutine=init_dyn_fb, phase=1, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
call ESMF_GridCompSetEntryPoint(nest, ESMF_METHOD_INITIALIZE, userRoutine=init_phys_fb, phase=2, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
call ESMF_GridCompGet(nest, name=name, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
call ESMF_InfoGetFromHost(nest, info=info, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
call ESMF_InfoGet(info, key="layout", values=layout, rc=rc); ESMF_ERR_ABORT(rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
if (trim(name)=="global") then
! global domain
call ESMF_InfoGet(info, key="tilesize", value=tilesize, rc=rc); ESMF_ERR_ABORT(rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
do tl=1,6
decomptile(1,tl) = layout(1)
decomptile(2,tl) = layout(2)
decompflagPTile(:,tl) = (/ESMF_DECOMP_SYMMEDGEMAX,ESMF_DECOMP_SYMMEDGEMAX/)
enddo
grid = ESMF_GridCreateCubedSphere(tileSize=tilesize, &
coordSys=ESMF_COORDSYS_SPH_RAD, &
regDecompPTile=decomptile, &
decompflagPTile=decompflagPTile, &
name="fcst_grid", rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
else
! nest domain
call ESMF_InfoGet(info, key="nx", value=nx, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
call ESMF_InfoGet(info, key="ny", value=ny, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
grid = ESMF_GridCreateNoPeriDim(regDecomp=(/layout(1),layout(2)/), &
minIndex=(/1,1/), &
maxIndex=(/nx,ny/), &
gridAlign=(/-1,-1/), &
coordSys=ESMF_COORDSYS_SPH_RAD, &
decompflag=(/ESMF_DECOMP_SYMMEDGEMAX,ESMF_DECOMP_SYMMEDGEMAX/), &
name="fcst_grid", &
indexflag=ESMF_INDEX_DELOCAL, &
rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
endif
call ESMF_GridCompSet(nest, grid=grid, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
end subroutine SetServicesNest
!
!-----------------------------------------------------------------------
!#######################################################################
!-----------------------------------------------------------------------
!
subroutine init_dyn_fb(nest, importState, exportState, clock, rc)
!
type(ESMF_GridComp) :: nest
type(ESMF_State) :: importState, exportState
type(ESMF_Clock) :: clock
integer,intent(out) :: rc
type(ESMF_Grid) :: grid
integer :: itemCount
character(len=ESMF_MAXSTR) :: itemNameList(1)
type(ESMF_FieldBundle) :: fb, fcstFB
call ESMF_GridCompGet(nest, grid=grid, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
call ESMF_StateGet(importState, itemCount=itemCount, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
if (itemCount /= 1) then
! error condition, expect exactly one dynamics field bundle
call ESMF_LogSetError(ESMF_RC_ARG_BAD, &
msg="Expecting exactly one dynamics field bundle.", line=__LINE__, file=__FILE__)
endif
call ESMF_StateGet(importState, itemNameList=itemNameList, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
call ESMF_StateGet(importState, itemName=itemNameList(1), fieldbundle=fcstFB, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
fb = ESMF_FieldBundleCreate(name=itemNameList(1), rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
call ESMF_AttributeCopy(fcstFB, fb, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
call ESMF_StateAdd(exportState,(/fb/), rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
call fv_dyn_bundle_setup(Atmos%axes, fb, grid, quilting=.true., rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
end subroutine init_dyn_fb
!
!-----------------------------------------------------------------------
!#######################################################################
!-----------------------------------------------------------------------
!
subroutine init_phys_fb(nest, importState, exportState, clock, rc)
!
type(ESMF_GridComp) :: nest
type(ESMF_State) :: importState, exportState
type(ESMF_Clock) :: clock
integer,intent(out) :: rc
type(ESMF_Grid) :: grid
integer :: itemCount, i
character(len=ESMF_MAXSTR), allocatable :: itemNameList(:)
type(ESMF_FieldBundle), allocatable :: fbList(:)
type(ESMF_FieldBundle) :: fcstFB
call ESMF_GridCompGet(nest, grid=grid, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
call ESMF_StateGet(importState, itemCount=itemCount, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
allocate(itemNameList(itemCount), fbList(itemCount))
call ESMF_StateGet(importState, itemNameList=itemNameList, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
do i=1, itemCount
call ESMF_StateGet(importState, itemName=itemNameList(i), fieldbundle=fcstFB, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
fbList(i) = ESMF_FieldBundleCreate(name=itemNameList(i), rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
call ESMF_AttributeCopy(fcstFB, fbList(i), rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
call ESMF_StateAdd(exportState, (/fbList(i)/), rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
enddo
call fv_phys_bundle_setup(Atmos%diag, Atmos%axes, fbList, grid, quilting=.true., nbdlphys=itemCount, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
end subroutine init_phys_fb
!
!-----------------------------------------------------------------------
!#######################################################################
!-----------------------------------------------------------------------
!
subroutine fcst_initialize(fcst_comp, importState, exportState, clock, rc)
!
!-----------------------------------------------------------------------
!*** INITIALIZE THE FORECAST GRIDDED COMPONENT.
!-----------------------------------------------------------------------
!
type(esmf_GridComp) :: fcst_comp
type(ESMF_State) :: importState, exportState
type(esmf_Clock) :: clock
integer,intent(out) :: rc
!
!*** local variables
!
integer :: i, j
!
type(ESMF_VM) :: VM
type(ESMF_Time) :: CurrTime, StartTime, StopTime
type(ESMF_Config) :: cf
integer,dimension(6) :: date, date_end
!
character(len=9) :: month
integer :: initClock, unit, total_inttime
integer :: mype
character(4) dateSY
character(2) dateSM,dateSD,dateSH,dateSN,dateSS
character(len=esmf_maxstr) name_FB, name_FB1
character(len=80) :: dateS
character(256) :: gridfile
character(8) :: bundle_grid
type(ESMF_FieldBundle),dimension(:), allocatable :: fieldbundle ! dynamics bundles
type(ESMF_FieldBundle),dimension(:,:), allocatable :: fieldbundlephys ! physics bundles
real(kind=8) :: mpi_wtime, timeis
type(ESMF_DELayout) :: delayout
type(ESMF_DistGrid) :: distgrid
real(ESMF_KIND_R8),dimension(:,:), pointer :: glatPtr, glonPtr
integer :: jsc, jec, isc, iec, nlev
type(domain2D) :: domain
integer :: n, fcstNpes, tmpvar, k
logical :: freq_restart, fexist
integer, allocatable, dimension(:) :: isl, iel, jsl, jel
integer, allocatable, dimension(:,:,:) :: deBlockList
integer, allocatable, dimension(:) :: petListNest
integer :: tlb(2), tub(2)
integer :: globalTileLayout(2)
integer :: nestRootPet, peListSize(1)
integer, allocatable :: petMap(:)
integer :: layout(2), nx, ny
integer, pointer :: pelist(:) => null()
logical :: top_parent_is_global
integer :: num_restart_interval, restart_starttime
real,dimension(:),allocatable :: restart_interval
integer :: urc
type(ESMF_State) :: tempState
type(ESMF_Info) :: info
type(time_type) :: Time_init, Time, Time_step, Time_end, &
Time_restart, Time_step_restart
type(time_type) :: iautime
integer :: io_unit, calendar_type_res, date_res(6), date_init_res(6)
!
!-----------------------------------------------------------------------
!***********************************************************************
!-----------------------------------------------------------------------
!
timeis = mpi_wtime()
rc = ESMF_SUCCESS
!
call ESMF_VMGetCurrent(vm=vm,rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
call ESMF_VMGet(vm=vm, localPet=mype, mpiCommunicator=fcst_mpi_comm, &
petCount=fcst_ntasks, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
if (mype == 0) write(*,*)'in fcst comp init, fcst_ntasks=',fcst_ntasks
CF = ESMF_ConfigCreate(rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
call ESMF_ConfigLoadFile(config=CF ,filename='model_configure' ,rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
num_restart_interval = ESMF_ConfigGetLen(config=CF, label ='restart_interval:',rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
if (mype == 0) print *,'af nems config,num_restart_interval=',num_restart_interval
if (num_restart_interval<=0) num_restart_interval = 1
allocate(restart_interval(num_restart_interval))
restart_interval = 0
call ESMF_ConfigGetAttribute(CF,valueList=restart_interval,label='restart_interval:', &
count=num_restart_interval, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
if (mype == 0) print *,'af nems config,restart_interval=',restart_interval
!
call fms_init(fcst_mpi_comm)
call mpp_init()
initClock = mpp_clock_id( 'Initialization' )
call mpp_clock_begin (initClock) !nesting problem
call constants_init
call sat_vapor_pres_init
select case( uppercase(trim(calendar)) )
case( 'JULIAN' )
calendar_type = JULIAN
case( 'GREGORIAN' )
calendar_type = GREGORIAN
case( 'NOLEAP' )
calendar_type = NOLEAP
case( 'THIRTY_DAY' )
calendar_type = THIRTY_DAY_MONTHS
case( 'NO_CALENDAR' )
calendar_type = NO_CALENDAR
case default
call mpp_error ( FATAL, 'fcst_initialize: calendar must be one of '// &
'JULIAN|GREGORIAN|NOLEAP|THIRTY_DAY|NO_CALENDAR.' )
end select
call set_calendar_type (calendar_type)
!
!-----------------------------------------------------------------------
!*** set atmos time
!-----------------------------------------------------------------------
!
call ESMF_ClockGet(clock, CurrTime=CurrTime, StartTime=StartTime, &
StopTime=StopTime, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
date_init = 0
call ESMF_TimeGet (StartTime, &
YY=date_init(1), MM=date_init(2), DD=date_init(3), &
H=date_init(4), M =date_init(5), S =date_init(6), rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
Time_init = set_date (date_init(1), date_init(2), date_init(3), &
date_init(4), date_init(5), date_init(6))
if (mype == 0) write(*,'(A,6I5)') 'StartTime=',date_init
date=0
call ESMF_TimeGet (CurrTime, &
YY=date(1), MM=date(2), DD=date(3), &
H=date(4), M =date(5), S =date(6), rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
Time = set_date (date(1), date(2), date(3), &
date(4), date(5), date(6))
if (mype == 0) write(*,'(A,6I5)') 'CurrTime =',date
date_end=0
call ESMF_TimeGet (StopTime, &
YY=date_end(1), MM=date_end(2), DD=date_end(3), &
H=date_end(4), M =date_end(5), S =date_end(6), rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
Time_end = set_date (date_end(1), date_end(2), date_end(3), &
date_end(4), date_end(5), date_end(6))
if (mype == 0) write(*,'(A,6I5)') 'StopTime =',date_end
!------------------------------------------------------------------------
! If this is a restarted run ('INPUT/coupler.res' file exists),
! compare date and date_init to the values in 'coupler.res'
if (mype == 0) then
inquire(FILE='INPUT/coupler.res', EXIST=fexist)
if (fexist) then ! file exists, this is a restart run
call ESMF_UtilIOUnitGet(unit=io_unit, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
open(unit=io_unit, file='INPUT/coupler.res', status='old', action='read', err=998)
read (io_unit,*,err=999) calendar_type_res
read (io_unit,*) date_init_res
read (io_unit,*) date_res
close(io_unit)
if(date_res(1) == 0 .and. date_init_res(1) /= 0) date_res = date_init_res
if(mype == 0) write(*,'(A,6(I4))') 'INPUT/coupler.res: date_init=',date_init_res
if(mype == 0) write(*,'(A,6(I4))') 'INPUT/coupler.res: date =',date_res
if (calendar_type /= calendar_type_res) then
write(0,'(A)') 'fcst_initialize ERROR: calendar_type /= calendar_type_res'
write(0,'(A,6(I4))')' calendar_type = ', calendar_type
write(0,'(A,6(I4))')' calendar_type_res = ', calendar_type_res
call ESMF_Finalize(endflag=ESMF_END_ABORT)
endif
if (.not. ALL(date_init.EQ.date_init_res)) then
write(0,'(A)') 'fcst_initialize ERROR: date_init /= date_init_res'
write(0,'(A,6(I4))')' date_init = ', date_init
write(0,'(A,6(I4))')' date_init_res = ', date_init_res
call ESMF_Finalize(endflag=ESMF_END_ABORT)
endif
if (.not. ALL(date.EQ.date_res)) then
write(0,'(A)') 'fcst_initialize ERROR: date /= date_res'
write(0,'(A,6(I4))')' date = ', date
write(0,'(A,6(I4))')' date_res = ', date_res
call ESMF_Finalize(endflag=ESMF_END_ABORT)
endif
999 continue
998 continue
endif ! fexist
endif ! mype == 0
call diag_manager_init (TIME_INIT=date)
call diag_manager_set_time_end(Time_end)
!
Time_step = set_time (dt_atmos,0)
if (mype == 0) write(*,*)'time_init=', date_init,'time=',date,'time_end=',date_end,'dt_atmos=',dt_atmos
! set up forecast time array that controls when to write out restart files
frestart = 0
call get_time(Time_end - Time_init, total_inttime)
! set iau offset time
Atmos%iau_offset = iau_offset
if(iau_offset > 0 ) then
iautime = set_time(iau_offset * 3600, 0)
endif
! if the second item is -1, the first number is frequency
freq_restart = .false.
if(num_restart_interval == 2) then
if(restart_interval(2)== -1) freq_restart = .true.
endif
if(freq_restart) then
if(restart_interval(1) >= 0) then
tmpvar = restart_interval(1) * 3600
Time_step_restart = set_time (tmpvar, 0)
if(iau_offset > 0 ) then
Time_restart = Time_init + iautime + Time_step_restart
frestart(1) = tmpvar + iau_offset *3600
else
Time_restart = Time_init + Time_step_restart
frestart(1) = tmpvar
endif
if(restart_interval(1) > 0) then
i = 2
do while ( Time_restart < Time_end )
frestart(i) = frestart(i-1) + tmpvar
Time_restart = Time_restart + Time_step_restart
i = i + 1
enddo
endif
endif
! otherwise it is an array with forecast time at which the restart files will be written out
else if(num_restart_interval >= 1) then
if(num_restart_interval == 1 .and. restart_interval(1) == 0 ) then
frestart(1) = total_inttime
else
if(iau_offset > 0 ) then
restart_starttime = iau_offset *3600
else
restart_starttime = 0
endif
do i=1,num_restart_interval
frestart(i) = restart_interval(i) * 3600. + restart_starttime
enddo
endif
endif
! if to write out restart at the end of forecast
restart_endfcst = .false.
if ( ANY(frestart(:) == total_inttime) ) restart_endfcst = .true.
! frestart only contains intermediate restart
do i=1,size(frestart)
if(frestart(i) == total_inttime) then
frestart(i) = 0
exit
endif
enddo
if (mype == 0) print *,'frestart=',frestart(1:10)/3600, 'restart_endfcst=',restart_endfcst, &
'total_inttime=',total_inttime
! if there is restart writing during integration
intrm_rst = 0
if (frestart(1)>0) intrm_rst = 1
!
!----- write time stamps (for start time and end time) ------
call mpp_open( unit, 'time_stamp.out', nohdrs=.TRUE. )
month = month_name(date(2))
if ( mpp_pe() == mpp_root_pe() ) write (unit,20) date, month(1:3)
month = month_name(date_end(2))
if ( mpp_pe() == mpp_root_pe() ) write (unit,20) date_end, month(1:3)
call mpp_close (unit)
20 format (6i4,2x,a3)
!
!------ initialize component models ------
call atmos_model_init (Atmos, Time_init, Time, Time_step)
!
inquire(FILE='data_table', EXIST=fexist)
if (fexist) then
call data_override_init()
endif
!-----------------------------------------------------------------------
!---- open and close dummy file in restart dir to check if dir exists --
if (mpp_pe() == 0 ) then
call mpp_open( unit, 'RESTART/file' )
call mpp_close(unit, MPP_DELETE)
endif
!
!-----------------------------------------------------------------------
!*** create grid for output fields, using FV3 parameters
!-----------------------------------------------------------------------
!
call mpp_error(NOTE, 'before create fcst grid')
gridfile = "grid_spec.nc" ! default
if (field_exist("INPUT/grid_spec.nc", "atm_mosaic_file")) then
call read_data("INPUT/grid_spec.nc", "atm_mosaic_file", gridfile)
endif
ngrids = Atmos%ngrids
mygrid = Atmos%mygrid
allocate(grid_number_on_all_pets(fcst_ntasks))
call mpi_allgather(mygrid, 1, MPI_INTEGER, &
grid_number_on_all_pets, 1, MPI_INTEGER, &
fcst_mpi_comm, rc)
allocate (fcstGrid(ngrids),fcstGridComp(ngrids))
do n=1,ngrids
pelist => null()
call atmos_model_get_nth_domain_info(n, layout, nx, ny, pelist)
call ESMF_VMBroadcast(vm, bcstData=layout, count=2, rootPet=pelist(1), rc=rc); ESMF_ERR_ABORT(rc)
if (n==1) then
! on grid==1 (top level parent) determine if the domain is global or regional
top_parent_is_global = .true.
if(mygrid==1) then
if (Atmos%regional) top_parent_is_global = .false.
endif
call mpi_bcast(top_parent_is_global, 1, MPI_LOGICAL, 0, fcst_mpi_comm, rc)
endif
if (n==1 .and. top_parent_is_global) then
fcstGridComp(n) = ESMF_GridCompCreate(name="global", petList=pelist, rc=rc); ESMF_ERR_ABORT(rc)
call ESMF_InfoGetFromHost(fcstGridComp(n), info=info, rc=rc); ESMF_ERR_ABORT(rc)
call ESMF_InfoSet(info, key="layout", values=layout, rc=rc); ESMF_ERR_ABORT(rc)
call ESMF_InfoSet(info, key="tilesize", value=Atmos%mlon, rc=rc); ESMF_ERR_ABORT(rc)
call ESMF_GridCompSetServices(fcstGridComp(n), SetServicesNest, userrc=urc, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
if (ESMF_LogFoundError(rcToCheck=urc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__, rcToReturn=rc)) return
else
allocate(petListNest(layout(1)*layout(2)))
k=pelist(1)
do j=1,layout(2)
do i=1,layout(1)
petListNest(k-pelist(1)+1) = k
k = k + 1
end do
end do
fcstGridComp(n) = ESMF_GridCompCreate(name="nest", petList=petListNest, rc=rc); ESMF_ERR_ABORT(rc)
call ESMF_InfoGetFromHost(fcstGridComp(n), info=info, rc=rc); ESMF_ERR_ABORT(rc)
call ESMF_InfoSet(info, key="layout", values=layout, rc=rc); ESMF_ERR_ABORT(rc)
call ESMF_InfoSet(info, key="nx", value=nx, rc=rc); ESMF_ERR_ABORT(rc)
call ESMF_InfoSet(info, key="ny", value=ny, rc=rc); ESMF_ERR_ABORT(rc)
call ESMF_GridCompSetServices(fcstGridComp(n), SetServicesNest, userrc=urc, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
if (ESMF_LogFoundError(rcToCheck=urc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__, rcToReturn=rc)) return
deallocate(petListNest)
end if
if (ESMF_GridCompIsPetLocal(fcstGridComp(n), rc=rc)) then
call ESMF_GridCompGet(fcstGridComp(n), grid=fcstGrid(n), rc=rc); ESMF_ERR_ABORT(rc)
call ESMF_GridAddCoord(fcstGrid(n), staggerLoc=ESMF_STAGGERLOC_CENTER, rc=rc); ESMF_ERR_ABORT(rc)
call ESMF_GridAddCoord(fcstGrid(n), staggerLoc=ESMF_STAGGERLOC_CORNER, rc=rc); ESMF_ERR_ABORT(rc)
! define "center" coordinate values
call ESMF_GridGetCoord(fcstGrid(n), coordDim=1, staggerLoc=ESMF_STAGGERLOC_CENTER, &
totalLBound=tlb, totalUBound=tub, &
farrayPtr=glonPtr, rc=rc); ESMF_ERR_ABORT(rc)
glonPtr(tlb(1):tub(1),tlb(2):tub(2)) = Atmos%lon(tlb(1):tub(1),tlb(2):tub(2))
call ESMF_GridGetCoord(fcstGrid(n), coordDim=2, staggerLoc=ESMF_STAGGERLOC_CENTER, &
totalLBound=tlb, totalUBound=tub, &
farrayPtr=glatPtr, rc=rc); ESMF_ERR_ABORT(rc)
glatPtr(tlb(1):tub(1),tlb(2):tub(2)) = Atmos%lat(tlb(1):tub(1),tlb(2):tub(2))
! define "corner" coordinate values
call ESMF_GridGetCoord(fcstGrid(n), coordDim=1, staggerLoc=ESMF_STAGGERLOC_CORNER, &
totalLBound=tlb, totalUBound=tub, &
farrayPtr=glonPtr, rc=rc); ESMF_ERR_ABORT(rc)
glonPtr(tlb(1):tub(1),tlb(2):tub(2)) = Atmos%lon_bnd(tlb(1):tub(1),tlb(2):tub(2))
call ESMF_GridGetCoord(fcstGrid(n), coordDim=2, staggerLoc=ESMF_STAGGERLOC_CORNER, &
totalLBound=tlb, totalUBound=tub, &
farrayPtr=glatPtr, rc=rc); ESMF_ERR_ABORT(rc)
glatPtr(tlb(1):tub(1),tlb(2):tub(2)) = Atmos%lat_bnd(tlb(1):tub(1),tlb(2):tub(2))
end if ! IsPetLocal
end do
!
!! FIXME
if ( .not. Atmos%nested ) then !! global only
call addLsmask2grid(fcstGrid(mygrid), rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
! print *,'call addLsmask2grid after fcstGrid, rc=',rc
endif
!test to write out vtk file:
! if( cplprint_flag ) then
! call ESMF_GridWriteVTK(fcstGrid, staggerloc=ESMF_STAGGERLOC_CENTER, &
! filename='fv3cap_fv3Grid', rc=rc)
! if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
! endif
!
! Write grid to netcdf file
if( cplprint_flag ) then
call wrt_fcst_grid(fcstGrid(mygrid), "diagnostic_FV3_fcstGrid.nc", &
regridArea=.TRUE., rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
endif
! Add gridfile Attribute to the exportState
call ESMF_AttributeAdd(exportState, convention="NetCDF", purpose="FV3", &
attrList=(/"gridfile"/), rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
call ESMF_AttributeSet(exportState, convention="NetCDF", purpose="FV3", &
name="gridfile", value=trim(gridfile), rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
! Add total number of domains(grids) Attribute to the exportState
call ESMF_AttributeAdd(exportState, convention="NetCDF", purpose="FV3", &
attrList=(/"ngrids"/), rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
call ESMF_AttributeSet(exportState, convention="NetCDF", purpose="FV3", &
name="ngrids", value=ngrids, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
! Add top_parent_is_global Attribute to the exportState
call ESMF_AttributeAdd(exportState, convention="NetCDF", purpose="FV3", &
attrList=(/"top_parent_is_global"/), rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
call ESMF_AttributeSet(exportState, convention="NetCDF", purpose="FV3", &
name="top_parent_is_global", value=top_parent_is_global, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
! Add dimension Attributes to Grid
do n=1,ngrids
if (ESMF_GridCompIsPetLocal(fcstGridComp(n), rc=rc)) then
call ESMF_AttributeAdd(fcstGrid(n), convention="NetCDF", purpose="FV3", &
attrList=(/"ESMF:gridded_dim_labels"/), rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
call ESMF_AttributeSet(fcstGrid(n), convention="NetCDF", purpose="FV3", &
name="ESMF:gridded_dim_labels", valueList=(/"grid_xt", "grid_yt"/), rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
endif
end do
! Add time Attribute to the exportState
call ESMF_AttributeAdd(exportState, convention="NetCDF", purpose="FV3", &
attrList=(/ "time ", &
"time:long_name ", &
"time:units ", &
"time:cartesian_axis", &
"time:calendar_type ", &
"time:calendar " /), rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
call ESMF_AttributeSet(exportState, convention="NetCDF", purpose="FV3", &
name="time", value=real(0,ESMF_KIND_R8), rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
write(dateSY,'(I4.4)')date_init(1)
write(dateSM,'(I2.2)')date_init(2)
write(dateSD,'(I2.2)')date_init(3)
write(dateSH,'(I2.2)')date_init(4)
write(dateSN,'(I2.2)')date_init(5)
write(dateSS,'(I2.2)')date_init(6)
dateS="hours since "//dateSY//'-'//dateSM//'-'//dateSD//' '//dateSH//':'// &
dateSN//":"//dateSS
if (mype == 0) write(*,*)'dateS=',trim(dateS),'date_init=',date_init
call ESMF_AttributeSet(exportState, convention="NetCDF", purpose="FV3", &
name="time:units", value=trim(dateS), rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
call ESMF_AttributeSet(exportState, convention="NetCDF", purpose="FV3", &
name="time:long_name", value="time", rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
call ESMF_AttributeSet(exportState, convention="NetCDF", purpose="FV3", &
name="time:cartesian_axis", value="T", rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
call ESMF_AttributeSet(exportState, convention="NetCDF", purpose="FV3", &
name="time:calendar_type", value=uppercase(trim(calendar)), rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
call ESMF_AttributeSet(exportState, convention="NetCDF", purpose="FV3", &
name="time:calendar", value=uppercase(trim(calendar)), rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
!
! Create FieldBundle for Fields that need to be regridded bilinear
if( quilting ) then
allocate(fieldbundle(ngrids))
nbdlphys = 2
allocate(fieldbundlephys(nbdlphys,ngrids))
do n=1,ngrids
bundle_grid=''
if (ngrids > 1 .and. n >= 2) then
write(bundle_grid,'(A5,I2.2,A1)') '.nest', n, '.'
endif
do i=1,num_files
!
tempState = ESMF_StateCreate(rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
name_FB = trim(filename_base(i)) // trim(bundle_grid)
!
if( i==1 ) then
! for dyn
name_FB1 = trim(name_FB)//'_bilinear'
fieldbundle(n) = ESMF_FieldBundleCreate(name=trim(name_FB1),rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
call ESMF_AttributeAdd(fieldbundle(n), convention="NetCDF", purpose="FV3", &
attrList=(/"grid_id"/), rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
call ESMF_AttributeSet(fieldbundle(n), convention="NetCDF", purpose="FV3", &
name="grid_id", value=n, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
call ESMF_StateAdd(tempState, (/fieldbundle(n)/), rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
call ESMF_GridCompInitialize(fcstGridComp(n), importState=tempState,&
exportState=exportState, phase=1, userrc=urc, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
if (ESMF_LogFoundError(rcToCheck=urc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__, rcToReturn=rc)) return
else if( i==2 ) then
! for phys
do j=1, nbdlphys
if( j==1 ) then
name_FB1 = trim(name_FB)//'_nearest_stod'
else
name_FB1 = trim(name_FB)//'_bilinear'
endif
fieldbundlephys(j,n) = ESMF_FieldBundleCreate(name=trim(name_FB1),rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
call ESMF_AttributeAdd(fieldbundlephys(j,n), convention="NetCDF", purpose="FV3", &
attrList=(/"grid_id"/), rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
call ESMF_AttributeSet(fieldbundlephys(j,n), convention="NetCDF", purpose="FV3", &
name="grid_id", value=n, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
call ESMF_StateAdd(tempState, (/fieldbundlephys(j,n)/), rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
enddo
call ESMF_GridCompInitialize(fcstGridComp(n), importState=tempState,&
exportState=exportState, phase=2, userrc=urc, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
if (ESMF_LogFoundError(rcToCheck=urc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__, rcToReturn=rc)) return
else
write(0,*)' unknown name_FB ', trim(name_FB)
ESMF_ERR_ABORT(101)
endif
!
call ESMF_StateDestroy(tempState, noGarbage=.true., rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
enddo ! num_files
enddo ! ngrids
!end qulting
endif
call get_atmos_model_ungridded_dim(nlev=numLevels, &
nsoillev=numSoilLayers, &
ntracers=numTracers)
if (mype == 0) write(*,*)'fcst_initialize total time: ', mpi_wtime() - timeis
!
!-----------------------------------------------------------------------
!
end subroutine fcst_initialize
!
!-----------------------------------------------------------------------
!#######################################################################
!-----------------------------------------------------------------------
!
subroutine fcst_run_phase_1(fcst_comp, importState, exportState,clock,rc)
!
!-----------------------------------------------------------------------
!*** the run step for the fcst gridded component.
!-----------------------------------------------------------------------
!
type(ESMF_GridComp) :: fcst_comp
type(ESMF_State) :: importState, exportState
type(ESMF_Clock) :: clock
integer,intent(out) :: rc
!
!*** local variables
!
integer :: mype, seconds
real(kind=8) :: mpi_wtime, tbeg1
!
!-----------------------------------------------------------------------
!***********************************************************************
!-----------------------------------------------------------------------
!
tbeg1 = mpi_wtime()
rc = ESMF_SUCCESS
!
!-----------------------------------------------------------------------
!
call ESMF_GridCompGet(fcst_comp, localpet=mype, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
call get_time(Atmos%Time - Atmos%Time_init, seconds)
n_atmsteps = seconds/dt_atmos
!
!-----------------------------------------------------------------------
! *** call fcst integration subroutines
call update_atmos_model_dynamics (Atmos)
call update_atmos_radiation_physics (Atmos)
call atmos_model_exchange_phase_1 (Atmos, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
if (mype == 0) write(*,*)"PASS: fcstRUN phase 1, n_atmsteps = ",n_atmsteps, ' time is ', mpi_wtime()-tbeg1
!
!-----------------------------------------------------------------------
!
end subroutine fcst_run_phase_1
!
!-----------------------------------------------------------------------
!#######################################################################
!-----------------------------------------------------------------------
!
subroutine fcst_run_phase_2(fcst_comp, importState, exportState,clock,rc)
!
!-----------------------------------------------------------------------
!*** the run step for the fcst gridded component.
!-----------------------------------------------------------------------
!
type(ESMF_GridComp) :: fcst_comp
type(ESMF_State) :: importState, exportState
type(ESMF_Clock) :: clock
integer,intent(out) :: rc
!
!*** local variables
!
integer :: mype, date(6), seconds
character(len=64) :: timestamp
integer :: unit
real(kind=8) :: mpi_wtime, tbeg1