-
Notifications
You must be signed in to change notification settings - Fork 45
/
dshr_mod.F90
1967 lines (1707 loc) · 81.5 KB
/
dshr_mod.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
module dshr_mod
use NUOPC , only : NUOPC_CompAttributeGet, NUOPC_CompFilterPhaseMap
use NUOPC_Model , only : NUOPC_ModelGet
use ESMF , only : operator(<), operator(/=), operator(+)
use ESMF , only : operator(-), operator(*) , operator(>=)
use ESMF , only : operator(<=), operator(>), operator(==)
use ESMF , only : ESMF_METHOD_INITIALIZE
use ESMF , only : ESMF_LOGERR_PASSTHRU, ESMF_LogFoundError, ESMF_LOGMSG_ERROR, ESMF_MAXSTR
use ESMF , only : ESMF_SUCCESS, ESMF_LogWrite, ESMF_LOGMSG_INFO, ESMF_FAILURE, ESMF_LogSetError
use ESMF , only : ESMF_State, ESMF_StateGet
use ESMF , only : ESMF_Field, ESMF_FieldGet
use ESMF , only : ESMF_FieldBundle, ESMF_FieldBundleGet, ESMF_FieldBundleIsCreated
use ESMF , only : ESMF_DistGrid, ESMF_DistGridGet, ESMF_Array, ESMF_ArrayCreate, ESMF_ArrayDestroy
use ESMF , only : ESMF_GridComp, ESMF_GridCompGet, ESMF_GridCompSet
use ESMF , only : ESMF_GeomType_Flag, ESMF_FieldStatus_Flag
use ESMF , only : ESMF_Mesh, ESMF_MeshGet, ESMF_MeshSet, ESMF_MeshCreate, ESMF_MeshDestroy
use ESMF , only : ESMF_STAGGERLOC_CENTER, ESMF_STAGGERLOC_CORNER, ESMF_GRIDCREATENOPERIDIMUFRM
use ESMF , only : ESMF_FILEFORMAT_ESMFMESH, ESMF_Grid
use ESMF , only : ESMF_GEOMTYPE_MESH, ESMF_GEOMTYPE_GRID, ESMF_FIELDSTATUS_COMPLETE
use ESMF , only : ESMF_Clock, ESMF_ClockCreate, ESMF_ClockGet, ESMF_ClockSet
use ESMF , only : ESMF_ClockPrint, ESMF_ClockAdvance, ESMF_ClockGetAlarmList
use ESMF , only : ESMF_Alarm, ESMF_AlarmCreate, ESMF_AlarmGet, ESMF_AlarmSet
use ESMF , only : ESMF_ALARMLIST_ALL
use ESMF , only : ESMF_Calendar
use ESMF , only : ESMF_CALKIND_NOLEAP, ESMF_CALKIND_GREGORIAN, ESMF_CALKIND_FLAG
use ESMF , only : ESMF_Time, ESMF_TimeGet, ESMF_TimeSet
use ESMF , only : ESMF_TimeInterval, ESMF_TimeIntervalSet, ESMF_TimeIntervalGet
use ESMF , only : ESMF_VM, ESMF_VMGet, ESMF_VMBroadcast, ESMF_VMGetCurrent
use ESMF , only : ESMF_RouteHandle, ESMF_FieldRegrid
use ESMF , only : ESMF_TERMORDER_SRCSEQ, ESMF_FieldRegridStore, ESMF_SparseMatrixWrite
use ESMF , only : ESMF_Region_Flag, ESMF_REGION_TOTAL, ESMF_MAXSTR, ESMF_RC_NOT_VALID
use ESMF , only : ESMF_UtilStringUpperCase
use shr_kind_mod , only : r8=>shr_kind_r8, cs=>shr_kind_cs, cl=>shr_kind_cl, cx=>shr_kind_cx, cxx=>shr_kind_cxx, i8=>shr_kind_i8
use shr_sys_mod , only : shr_sys_abort
use shr_log_mod , only : shr_log_setLogUnit
use shr_cal_mod , only : shr_cal_noleap, shr_cal_gregorian, shr_cal_calendarname
use shr_cal_mod , only : shr_cal_datetod2string, shr_cal_date2julian
use shr_const_mod , only : shr_const_spval, shr_const_cday
use shr_orb_mod , only : shr_orb_params, SHR_ORB_UNDEF_INT, SHR_ORB_UNDEF_REAL
#ifdef CESMCOUPLED
use shr_pio_mod , only : shr_pio_getiosys, shr_pio_getiotype, shr_pio_getioformat
#endif
use dshr_strdata_mod , only : shr_strdata_type, SHR_STRDATA_GET_STREAM_COUNT
use shr_string_mod , only : shr_string_toLower
use dshr_methods_mod , only : chkerr
use pio
implicit none
public
public :: dshr_model_initphase
public :: dshr_init
public :: dshr_mesh_init
public :: dshr_set_runclock
public :: dshr_restart_read
public :: dshr_restart_write
public :: dshr_log_clock_advance
public :: dshr_state_getscalar
public :: dshr_state_setscalar
public :: dshr_orbital_update
public :: dshr_orbital_init
private :: dshr_mesh_create_scol ! create mesh for single column mode
private :: dshr_alarm_init ! initialize alarms
private :: dshr_time_init ! initialize time
! Note that gridTofieldMap = 2, therefore the ungridded dimension is innermost
! orbital settings
character(len=CL) :: orb_mode ! attribute - orbital mode (nuopc attribute)
integer :: orb_iyear ! attribute - orbital year (nuopc attribute)
integer :: orb_iyear_align ! attribute - associated with model year (nuopc attribute)
real(R8) :: orb_obliq ! attribute - obliquity in degrees (nuopc attribute)
real(R8) :: orb_mvelp ! attribute - moving vernal equinox longitude (nuopc attribute)
real(R8) :: orb_eccen ! attribute and update- orbital eccentricity (nuopc attribute)
character(len=*) , parameter :: orb_fixed_year = 'fixed_year'
character(len=*) , parameter :: orb_variable_year = 'variable_year'
character(len=*) , parameter :: orb_fixed_parameters = 'fixed_parameters'
logical :: write_restart_at_endofrun
integer , parameter :: main_task = 0
character(*), parameter :: u_FILE_u = &
__FILE__
!===============================================================================
contains
!===============================================================================
subroutine dshr_model_initphase(gcomp, importState, exportState, clock, rc)
use ESMF, only : ESMF_ClockIsCreated, ESMF_StateIsCreated
! input/output variables
type(ESMF_GridComp) :: gcomp
type(ESMF_State) :: importState, exportState
type(ESMF_Clock) :: clock
integer, intent(out) :: rc
character(len=*), parameter :: subname ='dshr_model_initphase'
!-------------------------------------------------------------------------------
rc = ESMF_SUCCESS
! To prevent an unused variable warning
if(.not. (ESMF_StateIsCreated(importState) .or. ESMF_StateIsCreated(exportState) .or. ESMF_ClockIsCreated(clock))) then
call ESMF_LogWrite(trim(subname)//' state or clock not created', ESMF_LOGMSG_ERROR)
endif
! Switch to IPDv01 by filtering all other phaseMap entries
call NUOPC_CompFilterPhaseMap(gcomp, ESMF_METHOD_INITIALIZE, acceptStringList=(/"IPDv01p"/), rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
end subroutine dshr_model_initphase
!===============================================================================
subroutine dshr_init(gcomp, compname, sdat, mpicom, my_task, inst_index, inst_suffix, &
flds_scalar_name, flds_scalar_num, flds_scalar_index_nx, flds_scalar_index_ny, logunit, rc)
#ifdef CESMCOUPLED
use nuopc_shr_methods, only : set_component_logging
#endif
! input/output variables
type(ESMF_GridComp) :: gcomp
type(shr_strdata_type), intent(in) :: sdat ! No longer used
character(len=*) , intent(in) :: compname !e.g. ATM, OCN, ...
integer , intent(inout) :: mpicom
integer , intent(out) :: my_task
integer , intent(out) :: inst_index
character(len=*) , intent(out) :: inst_suffix
character(len=*) , intent(out) :: flds_scalar_name
integer , intent(out) :: flds_scalar_num
integer , intent(out) :: flds_scalar_index_nx
integer , intent(out) :: flds_scalar_index_ny
integer , intent(out) :: logunit
integer , intent(out) :: rc
! local variables
type(ESMF_VM) :: vm
logical :: isPresent, isSet
#ifdef CESMCOUPLED
integer :: slogunit
#endif
character(len=CX) :: cvalue
character(len=CX) :: logmsg
character(len=CX) :: diro
character(len=CX) :: logfile
character(len=*),parameter :: subname='(dshr_advertise)'
! ----------------------------------------------
rc = ESMF_SUCCESS
! generate local mpi comm
call ESMF_GridCompGet(gcomp, vm=vm, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call ESMF_VMGet(vm, mpiCommunicator=mpicom, localPet=my_task, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
! get scalar attributes
call NUOPC_CompAttributeGet(gcomp, name="ScalarFieldName", value=cvalue, isPresent=isPresent, isSet=isSet, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
if (isPresent .and. isSet) then
flds_scalar_name = trim(cvalue)
call ESMF_LogWrite(trim(subname)//' flds_scalar_name = '//trim(flds_scalar_name), ESMF_LOGMSG_INFO)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
endif
call NUOPC_CompAttributeGet(gcomp, name="ScalarFieldCount", value=cvalue, isPresent=isPresent, isSet=isSet, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
if (isPresent .and. isSet) then
read(cvalue, *) flds_scalar_num
write(logmsg,*) flds_scalar_num
call ESMF_LogWrite(trim(subname)//' flds_scalar_num = '//trim(logmsg), ESMF_LOGMSG_INFO)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
endif
call NUOPC_CompAttributeGet(gcomp, name="ScalarFieldIdxGridNX", value=cvalue, isPresent=isPresent, isSet=isSet, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
if (isPresent .and. isSet) then
read(cvalue,*) flds_scalar_index_nx
write(logmsg,*) flds_scalar_index_nx
call ESMF_LogWrite(trim(subname)//' : flds_scalar_index_nx = '//trim(logmsg), ESMF_LOGMSG_INFO)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
endif
call NUOPC_CompAttributeGet(gcomp, name="ScalarFieldIdxGridNY", value=cvalue, isPresent=isPresent, isSet=isSet, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
if (isPresent .and. isSet) then
read(cvalue,*) flds_scalar_index_ny
write(logmsg,*) flds_scalar_index_ny
call ESMF_LogWrite(trim(subname)//' : flds_scalar_index_ny = '//trim(logmsg), ESMF_LOGMSG_INFO)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
endif
! set output logging
call NUOPC_CompAttributeGet(gcomp, name="diro", value=diro, isPresent=isPresent, isSet=isSet, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
if (.not. (isPresent .and. isSet)) then
diro = "."
endif
call NUOPC_CompAttributeGet(gcomp, name="logfile", value=cvalue, isPresent=isPresent, isSet=isSet, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
if (isPresent .and. isSet) then
read(cvalue,*) logfile
else
logfile = "d"//shr_string_toLower(compname)//".log"
endif
#ifdef CESMCOUPLED
call set_component_logging(gcomp, my_task == main_task, logunit, slogunit, rc=rc)
#else
if (my_task == main_task) then
call ESMF_LogWrite(trim(subname)//' : output logging is written to '//trim(diro)//"/"//trim(logfile), ESMF_LOGMSG_INFO)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
open(newunit=logunit, file=trim(diro)//"/"//trim(logfile))
else
logUnit = 6
endif
#endif
call shr_log_setLogUnit(logunit)
! set component instance and suffix
call NUOPC_CompAttributeGet(gcomp, name="inst_suffix", isPresent=isPresent, rc=rc)
if (chkerr(rc,__LINE__,u_FILE_u)) return
if (isPresent) then
call NUOPC_CompAttributeGet(gcomp, name="inst_suffix", value=inst_suffix, rc=rc)
if (chkerr(rc,__LINE__,u_FILE_u)) return
cvalue = inst_suffix(2:)
read(cvalue, *) inst_index
else
inst_suffix = ""
inst_index=1
endif
call NUOPC_CompAttributeGet(gcomp, name="write_restart_at_endofrun", value=cvalue, isPresent=isPresent, isSet=isSet, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
if (isPresent .and. isSet) then
if (trim(cvalue) .eq. '.true.') write_restart_at_endofrun = .true.
end if
end subroutine dshr_init
!===============================================================================
subroutine dshr_mesh_init(gcomp, sdat, nullstr, logunit, compname, model_nxg, model_nyg, &
model_meshfile, model_maskfile, model_mesh, model_mask, model_frac, read_restart, rc)
! ----------------------------------------------
! Initialize model mesh
! ----------------------------------------------
! input/output variables
type(ESMF_GridComp) , intent(inout) :: gcomp
type(shr_strdata_type) , intent(inout) :: sdat
integer , intent(in) :: logunit
character(len=*) , intent(in) :: compname !e.g. ATM, OCN, ...
character(len=*) , intent(in) :: nullstr
integer , intent(in) :: model_nxg
integer , intent(in) :: model_nyg
character(len=*) , intent(in) :: model_meshfile
character(len=*) , intent(in) :: model_maskfile
type(ESMF_Mesh) , intent(out) :: model_mesh
integer , pointer , intent(out) :: model_mask(:)
real(r8), pointer , intent(out) :: model_frac(:)
logical , intent(out) :: read_restart
integer , intent(out) :: rc
! local variables
type(ESMF_VM) :: vm
logical :: mainproc
type(ESMF_DistGrid) :: distGrid
integer :: my_task
real(r8) :: scol_lon
real(r8) :: scol_lat
character(CL) :: cvalue
integer :: lsize ! local size of mesh
type(ESMF_Array) :: elemMaskArray
logical :: isPresent, isSet
logical :: exists ! check for file existence
real(r8) :: scol_spval = -999._r8
character(*) , parameter :: F00 ="('(dshr_mesh_init) ',a)"
character(len=*), parameter :: subname='(dshr_mod:dshr_mesh_init)'
! ----------------------------------------------
rc = ESMF_SUCCESS
! generate local mpi comm
call ESMF_GridCompGet(gcomp, vm=vm, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call ESMF_VMGet(vm, localPet=my_task, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
mainproc = (my_task == main_task)
call shr_log_setLogUnit(logunit)
! Initialize pio subsystem
#ifdef CESMCOUPLED
sdat%pio_subsystem => shr_pio_getiosys(trim(compname))
sdat%io_type = shr_pio_getiotype(trim(compname))
sdat%io_format = shr_pio_getioformat(trim(compname))
#else
call dshr_pio_init(gcomp, sdat, logunit, rc)
#endif
! Set restart flag
call NUOPC_CompAttributeGet(gcomp, name='read_restart', value=cvalue, isPresent=isPresent, isSet=isSet, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
if (isPresent .and. isSet) then
read(cvalue,*) read_restart
else
call shr_sys_abort(subname//' ERROR: read restart flag must be present')
end if
! obtain the single column lon and lat
call NUOPC_CompAttributeGet(gcomp, name='scol_lon', value=cvalue, isPresent=isPresent, isSet=isSet, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
if (isPresent .and. isSet) then
read(cvalue,*) scol_lon
else
scol_lon = scol_spval
end if
call NUOPC_CompAttributeGet(gcomp, name='scol_lat', value=cvalue, isPresent=isPresent, isSet=isSet, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
if (isPresent .and. isSet) then
read(cvalue,*) scol_lat
else
scol_lat = scol_spval
end if
if (scol_lon > scol_spval .and. scol_lat > scol_spval) then
! This is simply a single point run
call dshr_mesh_create_scol(gcomp, compname, scol_lon, scol_lat, model_mesh, model_mask, model_frac, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
else
! check that model_meshfile and model_maskfile exists
if (my_task == main_task) then
inquire(file=trim(model_meshfile), exist=exists)
if (.not.exists) then
write(logunit, *)' ERROR: model_meshfile '//trim(model_meshfile)//' does not exist'
call shr_sys_abort(trim(subname)//' ERROR: model_meshfile '//trim(model_meshfile)//' does not exist')
end if
inquire(file=trim(model_maskfile), exist=exists)
if (.not.exists) then
write(logunit, *)' ERROR: model_maskfile '//trim(model_maskfile)//' does not exist'
call shr_sys_abort(trim(subname)//' ERROR: model_maskfile '//trim(model_maskfile)//' does not exist')
end if
endif
! Read in the input model mesh
model_mesh = ESMF_MeshCreate(trim(model_meshfile), fileformat=ESMF_FILEFORMAT_ESMFMESH, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
! Reset the model mesh mask if the mask file is different from the mesh file
if (trim(model_meshfile) /= trim(model_maskfile)) then
! obtain the model mask by mapping the mesh created by reading in the model_maskfile to the
! model mesh and then reset the model mesh mask
call dshr_set_modelmask(model_mesh, model_maskfile, compname, model_mask, model_frac, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
if (mainproc) then
write(logunit,F00) trim(subname)// " obtained "//trim(compname)//" mesh from "// &
trim(model_meshfile)
write(logunit,F00) trim(subname)// " obtained "//trim(compname)//" mask from "// &
trim(model_maskfile)
end if
else ! model_meshfile and model_maskfile are the same
! obtain the mask and fraction from the mesh file
call ESMF_MeshGet(model_mesh, numOwnedElements=lsize, elementdistGrid=distGrid, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
! allocate memory for model_mask and model frac
allocate(model_mask(lsize))
allocate(model_frac(lsize))
! Get the values of model_mask
elemMaskArray = ESMF_ArrayCreate(distGrid, model_mask, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call ESMF_MeshGet(model_mesh, elemMaskArray=elemMaskArray, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
! Now set the fraction as just the real mask
model_frac(:) = real(model_mask(:), kind=r8)
call ESMF_ArrayDestroy(elemMaskArray, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
if (mainproc) then
write(logunit,F00) trim(subname)// " obtained "//trim(compname)//" mesh and mask from "// &
trim(model_meshfile)
end if
end if
end if
end subroutine dshr_mesh_init
!===============================================================================
subroutine dshr_mesh_create_scol(gcomp, compname, scol_lon, scol_lat, &
model_mesh, model_mask, model_frac, rc)
! Create a single column mesh - the area is arbitrary
! input/output variables
type(ESMF_GridComp) , intent(inout) :: gcomp
character(len=*) , intent(in) :: compname
real(r8) , intent(inout) :: scol_lon
real(r8) , intent(inout) :: scol_lat
type(ESMF_Mesh) , intent(out) :: model_mesh
integer , pointer , intent(inout) :: model_mask(:)
real(r8), pointer , intent(inout) :: model_frac(:)
integer , intent(out) :: rc
! local variables
type(ESMF_Grid) :: lgrid
character(CL) :: cvalue
integer :: maxIndex(2)
real(r8) :: mincornerCoord(2)
real(r8) :: maxcornerCoord(2)
character(len=*), parameter :: subname='(dshr_mesh_create_single_column)'
! ----------------------------------------------
rc = ESMF_SUCCESS
allocate(model_mask(1))
allocate(model_frac(1))
if (compname == 'ATM') then
model_frac(1) = 1._r8
model_mask(1) = 1
else if (compname == 'LND') then
call NUOPC_CompAttributeGet(gcomp, name='scol_lndmask', value=cvalue, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
read(cvalue,*) model_mask(1)
call NUOPC_CompAttributeGet(gcomp, name='scol_lndfrac', value=cvalue, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
read(cvalue,*) model_frac(1)
else if (compname == 'OCN' .or. compname == 'ICE') then
call NUOPC_CompAttributeGet(gcomp, name='scol_ocnmask', value=cvalue, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
read(cvalue,*) model_mask(1)
call NUOPC_CompAttributeGet(gcomp, name='scol_ocnfrac', value=cvalue, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
read(cvalue,*) model_frac(1)
else
call shr_sys_abort('ERROR: currently component '//trim(compname)//' is not supported for single column')
end if
! Use center and come up with arbitrary area delta lon and lat = .1 degree
maxIndex(1) = 1 ! number of lons
maxIndex(2) = 1 ! number of lats
mincornerCoord(1) = scol_lon - .1_r8 ! min lon
mincornerCoord(2) = scol_lat - .1_r8 ! min lat
maxcornerCoord(1) = scol_lon + .1_r8 ! max lon
maxcornerCoord(2) = scol_lat + .1_r8 ! max lat
! create the model grid
lgrid = ESMF_GridCreateNoPeriDimUfrm (maxindex=maxindex, &
mincornercoord=mincornercoord, maxcornercoord= maxcornercoord, &
staggerloclist=(/ESMF_STAGGERLOC_CENTER, ESMF_STAGGERLOC_CORNER/), rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
! create the mesh from the grid
model_mesh = ESMF_MeshCreate(lgrid, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
end subroutine dshr_mesh_create_scol
!===============================================================================
subroutine dshr_set_runclock(gcomp, rc)
! input/output variables
type(ESMF_GridComp) :: gcomp
integer, intent(out) :: rc
! local variables
type(ESMF_Clock) :: mclock, dclock
type(ESMF_Time) :: mcurrtime, dcurrtime
type(ESMF_Time) :: mstoptime
type(ESMF_TimeInterval) :: mtimestep, dtimestep
character(len=256) :: cvalue
character(len=256) :: restart_option ! Restart option units
integer :: restart_n ! Number until restart interval
integer :: restart_ymd ! Restart date (YYYYMMDD)
type(ESMF_ALARM) :: restart_alarm
character(len=256) :: stop_option ! Stop option units
integer :: stop_n ! Number until stop interval
integer :: stop_ymd ! Stop date (YYYYMMDD)
type(ESMF_ALARM) :: stop_alarm
character(len=128) :: name
integer :: alarmcount
character(len=*),parameter :: subname='dshr_mod:(ModelSetRunClock) '
!-------------------------------------------------------------------------------
rc = ESMF_SUCCESS
! query the Component for its clocks
call NUOPC_ModelGet(gcomp, driverClock=dclock, modelClock=mclock, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call ESMF_ClockGet(dclock, currTime=dcurrtime, timeStep=dtimestep, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call ESMF_ClockGet(mclock, currTime=mcurrtime, timeStep=mtimestep, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
! force model clock currtime and timestep to match driver and set stoptime
mstoptime = mcurrtime + dtimestep
call ESMF_ClockSet(mclock, currTime=dcurrtime, timeStep=dtimestep, stopTime=mstoptime, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
! set restart alarm
call ESMF_ClockGetAlarmList(mclock, alarmlistflag=ESMF_ALARMLIST_ALL, alarmCount=alarmCount, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
if (alarmCount == 0) then
call ESMF_GridCompGet(gcomp, name=name, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call ESMF_LogWrite(subname//'setting alarms for' // trim(name), ESMF_LOGMSG_INFO)
call NUOPC_CompAttributeGet(gcomp, name="restart_option", value=restart_option, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call NUOPC_CompAttributeGet(gcomp, name="restart_n", value=cvalue, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
read(cvalue,*) restart_n
call NUOPC_CompAttributeGet(gcomp, name="restart_ymd", value=cvalue, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
read(cvalue,*) restart_ymd
call dshr_alarm_init(mclock, restart_alarm, restart_option, &
opt_n = restart_n, &
opt_ymd = restart_ymd, &
RefTime = mcurrTime, &
alarmname = 'alarm_restart', rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call ESMF_AlarmSet(restart_alarm, clock=mclock, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
!----------------
! Stop alarm
!----------------
call NUOPC_CompAttributeGet(gcomp, name="stop_option", value=stop_option, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call NUOPC_CompAttributeGet(gcomp, name="stop_n", value=cvalue, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
read(cvalue,*) stop_n
call NUOPC_CompAttributeGet(gcomp, name="stop_ymd", value=cvalue, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
read(cvalue,*) stop_ymd
call dshr_alarm_init(mclock, stop_alarm, stop_option, &
opt_n = stop_n, &
opt_ymd = stop_ymd, &
RefTime = mcurrTime, &
alarmname = 'alarm_stop', rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call ESMF_AlarmSet(stop_alarm, clock=mclock, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
end if
! Advance model clock to trigger alarms then reset model clock back to currtime
call ESMF_ClockAdvance(mclock,rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call ESMF_ClockSet(mclock, currTime=dcurrtime, timeStep=dtimestep, stopTime=mstoptime, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
end subroutine dshr_set_runclock
!===============================================================================
subroutine dshr_alarm_init( clock, alarm, option, &
opt_n, opt_ymd, opt_tod, RefTime, alarmname, rc)
! Setup an alarm in a clock
! Notes: The ringtime sent to AlarmCreate MUST be the next alarm
! time. If you send an arbitrary but proper ringtime from the
! past and the ring interval, the alarm will always go off on the
! next clock advance and this will cause serious problems. Even
! if it makes sense to initialize an alarm with some reference
! time and the alarm interval, that reference time has to be
! advance forward to be >= the current time. In the logic below
! we set an appropriate "NextAlarm" and then we make sure to
! advance it properly based on the ring interval.
! input/output variables
type(ESMF_Clock) , intent(inout) :: clock ! clock
type(ESMF_Alarm) , intent(inout) :: alarm ! alarm
character(len=*) , intent(in) :: option ! alarm option
integer , optional , intent(in) :: opt_n ! alarm freq
integer , optional , intent(in) :: opt_ymd ! alarm ymd
integer , optional , intent(in) :: opt_tod ! alarm tod (sec)
type(ESMF_Time) , optional , intent(in) :: RefTime ! ref time
character(len=*) , optional , intent(in) :: alarmname ! alarm name
integer , intent(inout) :: rc ! Return code
! local variables
type(ESMF_Calendar) :: cal ! calendar
integer :: lymd ! local ymd
integer :: ltod ! local tod
integer :: cyy,cmm,cdd,csec ! time info
character(len=64) :: lalarmname ! local alarm name
logical :: update_nextalarm ! update next alarm
type(ESMF_Time) :: CurrTime ! Current Time
type(ESMF_Time) :: NextAlarm ! Next restart alarm time
type(ESMF_TimeInterval) :: AlarmInterval ! Alarm interval
character(len=*), parameter :: & ! Clock and alarm options
optNONE = "none" , &
optNever = "never" , &
optNSteps = "nsteps" , &
optNStep = "nstep" , &
optNSeconds = "nseconds" , &
optNSecond = "nsecond" , &
optNMinutes = "nminutes" , &
optNMinute = "nminute" , &
optNHours = "nhours" , &
optNHour = "nhour" , &
optNDays = "ndays" , &
optNDay = "nday" , &
optNMonths = "nmonths" , &
optNMonth = "nmonth" , &
optNYears = "nyears" , &
optNYear = "nyear" , &
optMonthly = "monthly" , &
optYearly = "yearly" , &
optDate = "date" , &
optEnd = "end" , &
optIfdays0 = "ifdays0"
character(len=*), parameter :: subname = '(dshr_alarm_init): '
!-------------------------------------------------------------------------------
rc = ESMF_SUCCESS
update_nextalarm = .false.
lalarmname = 'alarm_unknown'
if (present(alarmname)) lalarmname = trim(alarmname)
ltod = 0
if (present(opt_tod)) ltod = opt_tod
lymd = -1
if (present(opt_ymd)) lymd = opt_ymd
call ESMF_ClockGet(clock, CurrTime=CurrTime, rc=rc)
if (chkerr(rc,__LINE__,u_FILE_u)) return
call ESMF_TimeGet(CurrTime, yy=cyy, mm=cmm, dd=cdd, s=csec, rc=rc )
if (chkerr(rc,__LINE__,u_FILE_u)) return
! initial guess of next alarm, this will be updated below
if (present(RefTime)) then
NextAlarm = RefTime
else
NextAlarm = CurrTime
endif
! Determine calendar
call ESMF_ClockGet(clock, calendar=cal)
! Determine inputs for call to create alarm
selectcase (trim(option))
case (optNONE)
call ESMF_TimeIntervalSet(AlarmInterval, yy=9999, rc=rc)
if (chkerr(rc,__LINE__,u_FILE_u)) return
call ESMF_TimeSet( NextAlarm, yy=9999, mm=12, dd=1, s=0, calendar=cal, rc=rc )
if (chkerr(rc,__LINE__,u_FILE_u)) return
update_nextalarm = .false.
case (optNever)
call ESMF_TimeIntervalSet(AlarmInterval, yy=9999, rc=rc)
if (chkerr(rc,__LINE__,u_FILE_u)) return
call ESMF_TimeSet( NextAlarm, yy=9999, mm=12, dd=1, s=0, calendar=cal, rc=rc )
if (chkerr(rc,__LINE__,u_FILE_u)) return
update_nextalarm = .false.
case (optEnd)
call ESMF_TimeIntervalSet(AlarmInterval, yy=9999, rc=rc)
if (chkerr(rc,__LINE__,u_FILE_u)) return
call ESMF_TimeSet( NextAlarm, yy=9999, mm=12, dd=1, s=0, calendar=cal, rc=rc )
if (chkerr(rc,__LINE__,u_FILE_u)) return
update_nextalarm = .false.
case (optDate)
if (.not. present(opt_ymd)) then
call shr_sys_abort(subname//trim(option)//' requires opt_ymd')
end if
if (lymd < 0 .or. ltod < 0) then
call shr_sys_abort(subname//trim(option)//'opt_ymd, opt_tod invalid')
end if
call ESMF_TimeIntervalSet(AlarmInterval, yy=9999, rc=rc)
if (chkerr(rc,__LINE__,u_FILE_u)) return
call dshr_time_init(NextAlarm, lymd, cal, ltod, rc)
if (chkerr(rc,__LINE__,u_FILE_u)) return
update_nextalarm = .false.
case (optIfdays0)
if (.not. present(opt_ymd)) then
call shr_sys_abort(subname//trim(option)//' requires opt_ymd')
end if
if (.not.present(opt_n)) then
call shr_sys_abort(subname//trim(option)//' requires opt_n')
end if
if (opt_n <= 0) then
call shr_sys_abort(subname//trim(option)//' invalid opt_n')
end if
call ESMF_TimeIntervalSet(AlarmInterval, mm=1, rc=rc)
if (chkerr(rc,__LINE__,u_FILE_u)) return
call ESMF_TimeSet( NextAlarm, yy=cyy, mm=cmm, dd=opt_n, s=0, calendar=cal, rc=rc )
if (chkerr(rc,__LINE__,u_FILE_u)) return
update_nextalarm = .true.
case (optNSteps)
if (.not.present(opt_n)) then
call shr_sys_abort(subname//trim(option)//' requires opt_n')
end if
if (opt_n <= 0) then
call shr_sys_abort(subname//trim(option)//' invalid opt_n')
end if
call ESMF_ClockGet(clock, TimeStep=AlarmInterval, rc=rc)
if (chkerr(rc,__LINE__,u_FILE_u)) return
AlarmInterval = AlarmInterval * opt_n
update_nextalarm = .true.
case (optNStep)
if (.not.present(opt_n)) call shr_sys_abort(subname//trim(option)//' requires opt_n')
if (opt_n <= 0) call shr_sys_abort(subname//trim(option)//' invalid opt_n')
call ESMF_ClockGet(clock, TimeStep=AlarmInterval, rc=rc)
if (chkerr(rc,__LINE__,u_FILE_u)) return
AlarmInterval = AlarmInterval * opt_n
update_nextalarm = .true.
case (optNSeconds)
if (.not.present(opt_n)) then
call shr_sys_abort(subname//trim(option)//' requires opt_n')
end if
if (opt_n <= 0) then
call shr_sys_abort(subname//trim(option)//' invalid opt_n')
end if
call ESMF_TimeIntervalSet(AlarmInterval, s=1, rc=rc)
if (chkerr(rc,__LINE__,u_FILE_u)) return
AlarmInterval = AlarmInterval * opt_n
update_nextalarm = .true.
case (optNSecond)
if (.not.present(opt_n)) then
call shr_sys_abort(subname//trim(option)//' requires opt_n')
end if
if (opt_n <= 0) then
call shr_sys_abort(subname//trim(option)//' invalid opt_n')
end if
call ESMF_TimeIntervalSet(AlarmInterval, s=1, rc=rc)
if (chkerr(rc,__LINE__,u_FILE_u)) return
AlarmInterval = AlarmInterval * opt_n
update_nextalarm = .true.
case (optNMinutes)
call ESMF_TimeIntervalSet(AlarmInterval, s=60, rc=rc)
if (.not.present(opt_n)) then
call shr_sys_abort(subname//trim(option)//' requires opt_n')
end if
if (opt_n <= 0) then
call shr_sys_abort(subname//trim(option)//' invalid opt_n')
end if
AlarmInterval = AlarmInterval * opt_n
update_nextalarm = .true.
case (optNMinute)
if (.not.present(opt_n)) then
call shr_sys_abort(subname//trim(option)//' requires opt_n')
end if
if (opt_n <= 0) then
call shr_sys_abort(subname//trim(option)//' invalid opt_n')
end if
call ESMF_TimeIntervalSet(AlarmInterval, s=60, rc=rc)
if (chkerr(rc,__LINE__,u_FILE_u)) return
AlarmInterval = AlarmInterval * opt_n
update_nextalarm = .true.
case (optNHours)
if (.not.present(opt_n)) then
call shr_sys_abort(subname//trim(option)//' requires opt_n')
end if
if (opt_n <= 0) then
call shr_sys_abort(subname//trim(option)//' invalid opt_n')
end if
call ESMF_TimeIntervalSet(AlarmInterval, s=3600, rc=rc)
if (chkerr(rc,__LINE__,u_FILE_u)) return
AlarmInterval = AlarmInterval * opt_n
update_nextalarm = .true.
case (optNHour)
if (.not.present(opt_n)) then
call shr_sys_abort(subname//trim(option)//' requires opt_n')
end if
if (opt_n <= 0) then
call shr_sys_abort(subname//trim(option)//' invalid opt_n')
end if
call ESMF_TimeIntervalSet(AlarmInterval, s=3600, rc=rc)
if (chkerr(rc,__LINE__,u_FILE_u)) return
AlarmInterval = AlarmInterval * opt_n
update_nextalarm = .true.
case (optNDays)
if (.not.present(opt_n)) then
call shr_sys_abort(subname//trim(option)//' requires opt_n')
end if
if (opt_n <= 0) then
call shr_sys_abort(subname//trim(option)//' invalid opt_n')
end if
call ESMF_TimeIntervalSet(AlarmInterval, d=1, rc=rc)
if (chkerr(rc,__LINE__,u_FILE_u)) return
AlarmInterval = AlarmInterval * opt_n
update_nextalarm = .true.
case (optNDay)
if (.not.present(opt_n)) then
call shr_sys_abort(subname//trim(option)//' requires opt_n')
end if
if (opt_n <= 0) then
call shr_sys_abort(subname//trim(option)//' invalid opt_n')
end if
call ESMF_TimeIntervalSet(AlarmInterval, d=1, rc=rc)
if (chkerr(rc,__LINE__,u_FILE_u)) return
AlarmInterval = AlarmInterval * opt_n
update_nextalarm = .true.
case (optNMonths)
if (.not.present(opt_n)) then
call shr_sys_abort(subname//trim(option)//' requires opt_n')
end if
if (opt_n <= 0) then
call shr_sys_abort(subname//trim(option)//' invalid opt_n')
end if
call ESMF_TimeIntervalSet(AlarmInterval, mm=1, rc=rc)
if (chkerr(rc,__LINE__,u_FILE_u)) return
AlarmInterval = AlarmInterval * opt_n
update_nextalarm = .true.
case (optNMonth)
if (.not.present(opt_n)) then
call shr_sys_abort(subname//trim(option)//' requires opt_n')
end if
if (opt_n <= 0) then
call shr_sys_abort(subname//trim(option)//' invalid opt_n')
end if
call ESMF_TimeIntervalSet(AlarmInterval, mm=1, rc=rc)
if (chkerr(rc,__LINE__,u_FILE_u)) return
AlarmInterval = AlarmInterval * opt_n
update_nextalarm = .true.
case (optMonthly)
call ESMF_TimeIntervalSet(AlarmInterval, mm=1, rc=rc)
if (chkerr(rc,__LINE__,u_FILE_u)) return
call ESMF_TimeSet( NextAlarm, yy=cyy, mm=cmm, dd=1, s=0, calendar=cal, rc=rc )
if (chkerr(rc,__LINE__,u_FILE_u)) return
update_nextalarm = .true.
case (optNYears)
if (.not.present(opt_n)) then
call shr_sys_abort(subname//trim(option)//' requires opt_n')
end if
if (opt_n <= 0) then
call shr_sys_abort(subname//trim(option)//' invalid opt_n')
end if
call ESMF_TimeIntervalSet(AlarmInterval, yy=1, rc=rc)
if (chkerr(rc,__LINE__,u_FILE_u)) return
AlarmInterval = AlarmInterval * opt_n
update_nextalarm = .true.
case (optNYear)
if (.not.present(opt_n)) then
call shr_sys_abort(subname//trim(option)//' requires opt_n')
end if
if (opt_n <= 0) then
call shr_sys_abort(subname//trim(option)//' invalid opt_n')
end if
call ESMF_TimeIntervalSet(AlarmInterval, yy=1, rc=rc)
if (chkerr(rc,__LINE__,u_FILE_u)) return
AlarmInterval = AlarmInterval * opt_n
update_nextalarm = .true.
case (optYearly)
call ESMF_TimeIntervalSet(AlarmInterval, yy=1, rc=rc)
if (chkerr(rc,__LINE__,u_FILE_u)) return
call ESMF_TimeSet( NextAlarm, yy=cyy, mm=1, dd=1, s=0, calendar=cal, rc=rc )
if (chkerr(rc,__LINE__,u_FILE_u)) return
update_nextalarm = .true.
case default
call shr_sys_abort(subname//'unknown option '//trim(option))
end select
! --------------------------------------------------------------------------------
! --- AlarmInterval and NextAlarm should be set ---
! --------------------------------------------------------------------------------
! --- advance Next Alarm so it won't ring on first timestep for
! --- most options above. go back one alarminterval just to be careful
if (update_nextalarm) then
NextAlarm = NextAlarm - AlarmInterval
do while (NextAlarm <= CurrTime)
NextAlarm = NextAlarm + AlarmInterval
enddo
endif
alarm = ESMF_AlarmCreate( name=lalarmname, clock=clock, ringTime=NextAlarm, &
ringInterval=AlarmInterval, rc=rc)
if (chkerr(rc,__LINE__,u_FILE_u)) return
end subroutine dshr_alarm_init
!===============================================================================
subroutine dshr_time_init( Time, ymd, cal, tod, rc)
! Create the ESMF_Time object corresponding to the given input time,
! given in YMD (Year Month Day) and TOD (Time-of-day) format.
! Set the time by an integer as YYYYMMDD and integer seconds in the day
! input/output parameters:
type(ESMF_Time) , intent(inout) :: Time ! ESMF time
integer , intent(in) :: ymd ! year, month, day YYYYMMDD
type(ESMF_Calendar) , intent(in) :: cal ! ESMF calendar
integer , intent(in) :: tod ! time of day in seconds
integer , intent(out) :: rc
! local variables
integer :: year, mon, day ! year, month, day as integers
integer :: tdate
integer , parameter :: SecPerDay = 86400 ! Seconds per day
character(len=*), parameter :: subname='(dshr_time_init)'
!-------------------------------------------------------------------------------
rc = ESMF_SUCCESS
if ( (ymd < 0) .or. (tod < 0) .or. (tod > SecPerDay) )then
call shr_sys_abort( subname//'ERROR yymmdd is a negative number or time-of-day out of bounds' )
end if
tdate = abs(ymd)
year = int(tdate/10000)
if (ymd < 0) year = -year
mon = int( mod(tdate,10000)/ 100)
day = mod(tdate, 100)
call ESMF_TimeSet( Time, yy=year, mm=mon, dd=day, s=tod, calendar=cal, rc=rc )
if (chkerr(rc,__LINE__,u_FILE_u)) return
end subroutine dshr_time_init
!===============================================================================
subroutine dshr_restart_read(rest_filem, rpfile, inst_suffix, nullstr, &
logunit, my_task, mpicom, sdat, fld, fldname)
! Read restart file
use dshr_stream_mod, only : shr_stream_restIO
use ESMF, only : ESMF_VMGetCurrent
! input/output arguments
character(len=*) , intent(inout) :: rest_filem
character(len=*) , intent(in) :: rpfile
character(len=*) , intent(in) :: inst_suffix
character(len=*) , intent(in) :: nullstr
integer , intent(in) :: logunit
integer , intent(in) :: my_task
integer , intent(in) :: mpicom
type(shr_strdata_type) , intent(inout) :: sdat
real(r8) , optional , pointer :: fld(:)
character(len=*) , optional , intent(in) :: fldname
! local variables
type(ESMF_VM) :: vm
integer :: nu
logical :: exists ! file existance
type(file_desc_t) :: pioid
type(var_desc_t) :: varid
type(io_desc_t) :: pio_iodesc
integer :: rcode
integer :: rc
integer :: tmp(1)
character(*), parameter :: F00 = "('(dshr_restart_read) ',8a)"
character(*), parameter :: subName = "(dshr_restart_read) "
!-------------------------------------------------------------------------------
! no streams means no restart file is read.
if(shr_strdata_get_stream_count(sdat) <= 0) return
call ESMF_VMGetCurrent(vm, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
exists = .false.
if (trim(rest_filem) == trim(nullstr)) then
if (my_task == main_task) then
write(logunit,F00) ' restart filename from rpointer'
inquire(file=trim(rpfile)//trim(inst_suffix), exist=exists)
if (.not.exists) then
write(logunit, F00) ' ERROR: rpointer file does not exist'
call shr_sys_abort(trim(subname)//' ERROR: rpointer file missing')
endif
open(newunit=nu, file=trim(rpfile)//trim(inst_suffix), form='formatted')