forked from ESCOMP/CDEPS
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathdshr_stream_mod.F90
2067 lines (1784 loc) · 87.7 KB
/
dshr_stream_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_stream_mod
! -------------------------------------------------------------------------------
! Data type and methods to manage input data streams.
! A "data stream" is a sequence of input files where each file contains the
! same set of data fields and all the data fields are on the same grid.
! The sequence of input data files provides an uninterupted time series of
! data.
!
! A stream data type stores information about one data stream, including the
! range of data date years to use and how data dates align with model dates.
!
! Given a model date, this module can return data dates that are upper and
! lower time bounds around the given model date and the names of the files
! containing those dates.
! -------------------------------------------------------------------------------
use shr_kind_mod , only : r8=>shr_kind_r8, cs=>shr_kind_cs, cl=>shr_kind_cl, cxx=>shr_kind_cxx, cx=>shr_kind_cx
use shr_sys_mod , only : shr_sys_abort
use shr_const_mod , only : shr_const_cday
use shr_string_mod , only : shr_string_leftalign_and_convert_tabs, shr_string_parseCFtunit
use shr_cal_mod , only : shr_cal_noleap
use shr_cal_mod , only : shr_cal_date2ymd
use shr_cal_mod , only : shr_cal_ymd2date
use shr_cal_mod , only : shr_cal_calendarName
use shr_cal_mod , only : shr_cal_advDate
use shr_cal_mod , only : shr_cal_advdateint
use shr_cal_mod , only : shr_cal_leapyear
use dshr_methods_mod , only : chkerr
use pio , only : pio_noerr, pio_seterrorhandling, pio_inq_att, pio_openfile, pio_closefile
use pio , only : file_desc_t, pio_inq_varid, iosystem_desc_t, pio_file_is_open
use pio , only : pio_nowrite, pio_inquire_dimension, pio_inquire_variable, pio_bcast_error
use pio , only : pio_get_att, pio_get_var
#ifdef CESMCOUPLED
use shr_pio_mod , only : shr_pio_getiosys, shr_pio_getiotype, shr_pio_getioformat
#endif
implicit none
private ! default private
! !PUBLIC TYPES:
public :: shr_stream_streamType ! stream data type with private components
! !PUBLIC MEMBER FUNCTIONS:
public :: shr_stream_init_from_esmfconfig
#ifndef DISABLE_FoX
public :: shr_stream_init_from_xml
#endif
public :: shr_stream_init_from_inline ! initial stream type
public :: shr_stream_findBounds ! return lower/upper bounding date info
public :: shr_stream_getMeshFileName ! return stream filename
public :: shr_stream_getModelFieldList ! return model field name list
public :: shr_stream_getStreamFieldList! return stream file field name list
public :: shr_stream_getPrevFileName ! return previous file in sequence
public :: shr_stream_getNextFileName ! return next file in sequence
public :: shr_stream_getNFiles ! get the number of files in a stream
public :: shr_stream_getCalendar ! get the stream calendar
public :: shr_stream_getCurrFile ! get the currfile, fileopen, and currpioid
public :: shr_stream_getData ! get stream data from target file
public :: shr_stream_setCurrFile ! set the currfile, fileopen, and currpioid
public :: shr_stream_dataDump ! internal stream data for debugging
public :: shr_stream_restIO ! read or write to netcdf restart file
character(CS),parameter,public :: shr_stream_file_null = 'not_set'
! valid values for time extrapoloation
character(CS),parameter,public :: shr_stream_taxis_cycle = 'cycle'
character(CS),parameter,public :: shr_stream_taxis_extend = 'extend'
character(CS),parameter,public :: shr_stream_taxis_limit = 'limit'
! valid values for time interpolation
character(CS),parameter,public :: shr_stream_tinterp_lower = 'lower'
character(CS),parameter,public :: shr_stream_tinterp_upper = 'upper'
character(CS),parameter,public :: shr_stream_tinterp_nearest = 'nearest'
character(CS),parameter,public :: shr_stream_tinterp_linear = 'linear'
character(CS),parameter,public :: shr_stream_tinterp_coszen = 'coszen'
! valid values for mapping interpolation
character(CS),parameter,public :: shr_stream_mapalgo_bilinear = 'bilinear'
character(CS),parameter,public :: shr_stream_mapalgo_redist = 'redist'
character(CS),parameter,public :: shr_stream_mapalgo_nn = 'nn'
character(CS),parameter,public :: shr_stream_mapalgo_consf = 'consf'
character(CS),parameter,public :: shr_stream_mapalgo_consd = 'consd'
character(CS),parameter,public :: shr_stream_mapalgo_none = 'none'
! a useful derived type to use inside shr_streamType ---
type shr_stream_file_type
character(CX) :: name = shr_stream_file_null ! the file name (full pathname)
logical :: haveData = .false. ! has t-coord data been read in?
integer :: nt = 0 ! size of time dimension
integer ,allocatable :: date(:) ! t-coord date: yyyymmdd
integer ,allocatable :: secs(:) ! t-coord secs: elapsed on date
type(file_desc_t) :: fileid
end type shr_stream_file_type
type shr_stream_data_variable
character(CS) :: nameinfile
character(CS) :: nameinmodel
end type shr_stream_data_variable
type shr_stream_streamType
!private ! no public access to internal components
type(iosystem_desc_t), pointer :: pio_subsystem
integer :: pio_iotype
integer :: pio_ioformat
integer :: logunit ! stdout log unit
logical :: init = .false. ! has stream been initialized
integer :: nFiles = 0 ! number of data files
integer :: yearFirst = -1 ! first year to use in t-axis (yyyymmdd)
integer :: yearLast = -1 ! last year to use in t-axis (yyyymmdd)
integer :: yearAlign = -1 ! align yearFirst with this model year
character(CS) :: lev_dimname = 'null' ! name of vertical dimension if any
character(CS) :: taxMode = shr_stream_taxis_cycle ! cycling option for time axis
character(CS) :: tInterpAlgo = 'linear' ! algorithm to use for time interpolation
character(CS) :: mapalgo = 'bilinear' ! type of mapping - default is 'bilinear'
character(CS) :: readMode = 'single' ! stream read model - 'single' or 'full_file'
real(r8) :: dtlimit = 1.5_r8 ! delta time ratio limits for time interpolation
integer :: offset = 0 ! offset in seconds of stream data
character(CS) :: calendar = shr_cal_noleap ! stream calendar (obtained from first stream data file)
character(CL) :: meshFile = ' ' ! filename for mesh for all fields on stream (full pathname)
integer :: k_lvd = -1 ! file/sample of least valid date
integer :: n_lvd = -1 ! file/sample of least valid date
logical :: found_lvd = .false. ! T <=> k_lvd,n_lvd have been set
integer :: k_gvd = -1 ! file/sample of greatest valid date
integer :: n_gvd = -1 ! file/sample of greatest valid date
logical :: found_gvd = .false. ! T <=> k_gvd,n_gvd have been set
logical :: fileopen = .false. ! is current file open
character(CX) :: currfile = ' ' ! current filename
integer :: nvars ! number of stream variables
character(CL) :: stream_vectors = 'null' ! stream vectors names
type(file_desc_t) :: currpioid ! current pio file desc
type(shr_stream_file_type) , allocatable :: file(:) ! filenames of stream data files (full pathname)
type(shr_stream_data_variable), allocatable :: varlist(:) ! stream variable names (on file and in model)
integer :: src_mask_val = 0 ! mask value for src mesh
integer :: dst_mask_val = 0 ! mask value for dst mesh
end type shr_stream_streamType
!----- parameters -----
integer :: debug = 0 ! edit/turn-on for debug write statements
real(R8) , parameter :: spd = shr_const_cday ! seconds per day
character(*) , parameter :: u_FILE_u = &
__FILE__
!===============================================================================
contains
!===============================================================================
#ifndef DISABLE_FoX
subroutine shr_stream_init_from_xml(streamfilename, streamdat, isroot_task, logunit, &
pio_subsystem, io_type, io_format, compname, rc)
use FoX_DOM, only : extractDataContent, destroy, Node, NodeList, parseFile, getElementsByTagname
use FoX_DOM, only : getLength, item
use ESMF, only : ESMF_VM, ESMF_VMGetCurrent, ESMF_VMBroadCast, ESMF_SUCCESS
! ---------------------------------------------------------------------
! The xml format of a stream txt file will look like the following
! <?xml version="1.0"?>
! <file id="stream" version="1.0">
! <stream_info>
! <taxmode></taxmode>
! <tintalgo></tintalgo>
! <mapalgo></mapalgo>
! <readmode></readmode>
! <dtlimit></dtlimit>
! <year_first></year_first>
! <year_last></year_last>
! <year_align></year_align>
! <vectors></vectors>
! <meshfile></meshfile>
! <lev_dimname></lev_dimname>
! <data_files>
! <file></file>
! </data_files>
! <data_variables>
! <var></var>
! </data_variables>
! <offset></offset>
! </stream_info>
! </file>
! ---------------------------------------------------------------------
! input/output variables
character(len=*), optional , intent(in) :: streamfilename
type(shr_stream_streamType) , intent(inout), pointer :: streamdat(:)
logical , intent(in) :: isroot_task
integer , intent(in) :: logunit
type(iosystem_desc_t) , intent(in), pointer :: pio_subsystem
integer , intent(in) :: io_type
integer , intent(in) :: io_format
character(len=*) , intent(in) :: compname
integer , intent(out) :: rc
! local variables
type(ESMF_VM) :: vm
type(Node) , pointer :: Sdoc, p, streamnode
type(NodeList) , pointer :: streamlist, filelist, varlist
character(len=CL) :: tmpstr
integer :: i, n, nstrms
integer :: status
integer :: tmp(6)
real(r8) :: rtmp(1)
character(*),parameter :: subName = '(shr_stream_init_from_xml) '
! --------------------------------------------------------
rc = ESMF_SUCCESS
nstrms = 0
if (isroot_task) then
Sdoc => parseFile(streamfilename, iostat=status)
if (status /= 0) then
call shr_sys_abort("Could not parse file "//trim(streamfilename))
endif
streamlist => getElementsByTagname(Sdoc, "stream_info")
nstrms = getLength(streamlist)
! allocate an array of shr_streamtype objects on just isroot_task
allocate(streamdat(nstrms))
! fill in non-default values for the streamdat attributes
do i= 1, nstrms
streamnode => item(streamlist, i-1)
p => item(getElementsByTagname(streamnode, "taxmode"), 0)
if (associated(p)) then
call extractDataContent(p, streamdat(i)%taxmode)
if (streamdat(i)%taxmode /= shr_stream_taxis_cycle .and. &
streamdat(i)%taxmode /= shr_stream_taxis_extend .and. &
streamdat(i)%taxmode /= shr_stream_taxis_limit) then
call shr_sys_abort("tintalgo must have a value of either cycle, extend or limit")
end if
endif
p => item(getElementsByTagname(streamnode, "mapalgo"), 0)
if (associated(p)) then
call extractDataContent(p, streamdat(i)%mapalgo)
if (streamdat(i)%mapalgo /= shr_stream_mapalgo_bilinear .and. &
streamdat(i)%mapalgo /= shr_stream_mapalgo_redist .and. &
streamdat(i)%mapalgo /= shr_stream_mapalgo_nn .and. &
streamdat(i)%mapalgo /= shr_stream_mapalgo_consf .and. &
streamdat(i)%mapalgo /= shr_stream_mapalgo_consd .and. &
streamdat(i)%mapalgo /= shr_stream_mapalgo_none) then
call shr_sys_abort("mapaglo must have a value of either bilinear, redist, nn, consf or consd")
end if
endif
p => item(getElementsByTagname(streamnode, "tintalgo"), 0)
if (associated(p)) then
call extractDataContent(p, streamdat(i)%tInterpAlgo)
if (streamdat(i)%tInterpAlgo /= shr_stream_tinterp_lower .and. &
streamdat(i)%tInterpAlgo /= shr_stream_tinterp_upper .and. &
streamdat(i)%tInterpAlgo /= shr_stream_tinterp_nearest .and. &
streamdat(i)%tInterpAlgo /= shr_stream_tinterp_linear .and. &
streamdat(i)%tInterpAlgo /= shr_stream_tinterp_coszen) then
call shr_sys_abort("tintalgo must have a value of either lower, upper, nearest, linear or coszen")
end if
endif
p => item(getElementsByTagname(streamnode, "readmode"), 0)
if (associated(p)) then
call extractDataContent(p, streamdat(i)%readMode)
endif
p=> item(getElementsByTagname(streamnode, "year_first"), 0)
if(associated(p)) then
call extractDataContent(p, streamdat(i)%yearFirst)
else
call shr_sys_abort("yearFirst must be provided")
endif
p=> item(getElementsByTagname(streamnode, "year_last"), 0)
if(associated(p)) then
call extractDataContent(p, streamdat(i)%yearLast)
else
call shr_sys_abort("yearLast must be provided")
endif
p=> item(getElementsByTagname(streamnode, "year_align"), 0)
if(associated(p)) then
call extractDataContent(p, streamdat(i)%yearAlign)
else
call shr_sys_abort("yearAlign must be provided")
endif
p=> item(getElementsByTagname(streamnode, "dtlimit"), 0)
if(associated(p)) then
call extractDataContent(p, streamdat(i)%dtlimit)
endif
p=> item(getElementsByTagname(streamnode, "offset"), 0)
if(associated(p)) then
call extractDataContent(p, streamdat(i)%offset)
endif
p=> item(getElementsByTagname(streamnode, "meshfile"), 0)
if (associated(p)) then
call extractDataContent(p, streamdat(i)%meshfile)
else
call shr_sys_abort("mesh file name must be provided")
endif
p => item(getElementsByTagname(streamnode, "vectors"), 0)
if (associated(p)) then
call extractDataContent(p, streamdat(i)%stream_vectors)
else
call shr_sys_abort("stream vectors must be provided")
endif
! Determine name of vertical dimension
p => item(getElementsByTagname(streamnode, "lev_dimname"), 0)
if (associated(p)) then
call extractDataContent(p, streamdat(i)%lev_dimname)
else
call shr_sys_abort("stream vertical level dimension name must be provided")
endif
! Determine input data files
p => item(getElementsByTagname(streamnode, "datafiles"), 0)
if (.not. associated(p)) then
call shr_sys_abort("stream data files must be provided")
endif
filelist => getElementsByTagname(p,"file")
streamdat(i)%nfiles = getLength(filelist)
allocate(streamdat(i)%file( streamdat(i)%nfiles))
do n=1, streamdat(i)%nfiles
p => item(filelist, n-1)
call extractDataContent(p, streamdat(i)%file(n)%name)
enddo
! Determine name(s) of stream variable(s) in file and model
p => item(getElementsByTagname(streamnode, "datavars"), 0)
varlist => getElementsByTagname(p, "var")
streamdat(i)%nvars = getLength(varlist)
allocate(streamdat(i)%varlist(streamdat(i)%nvars))
do n = 1, streamdat(i)%nvars
p => item(varlist, n-1)
call extractDataContent(p, tmpstr)
streamdat(i)%varlist(n)%nameinfile = tmpstr(1:index(tmpstr, " "))
streamdat(i)%varlist(n)%nameinmodel = tmpstr(index(trim(tmpstr), " ", .true.)+1:)
enddo
enddo
#ifndef CPRPGI
! PGI compiler has an issue with this call (empty procedure)
call destroy(Sdoc)
#endif
endif
! allocate streamdat instance on all tasks
call ESMF_VMGetCurrent(vm, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
tmp(1) = nstrms
call ESMF_VMBroadCast(vm, tmp, 1, 0, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
nstrms = tmp(1)
if (.not. isroot_task) then
allocate(streamdat(nstrms))
endif
! broadcast the contents of streamdat from the main task to all tasks
do i=1,nstrms
tmp(1) = streamdat(i)%nfiles
tmp(2) = streamdat(i)%nvars
tmp(3) = streamdat(i)%yearFirst
tmp(4) = streamdat(i)%yearLast
tmp(5) = streamdat(i)%yearAlign
tmp(6) = streamdat(i)%offset
call ESMF_VMBroadCast(vm, tmp, 6, 0, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
streamdat(i)%nfiles = tmp(1)
streamdat(i)%nvars = tmp(2)
streamdat(i)%yearFirst = tmp(3)
streamdat(i)%yearLast = tmp(4)
streamdat(i)%yearAlign = tmp(5)
streamdat(i)%offset = tmp(6)
if(.not. isroot_task) then
allocate(streamdat(i)%file(streamdat(i)%nfiles))
allocate(streamdat(i)%varlist(streamdat(i)%nvars))
endif
do n=1,streamdat(i)%nfiles
call ESMF_VMBroadCast(vm, streamdat(i)%file(n)%name, CX, 0, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
enddo
do n=1,streamdat(i)%nvars
call ESMF_VMBroadCast(vm, streamdat(i)%varlist(n)%nameinfile, CS, 0, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call ESMF_VMBroadCast(vm, streamdat(i)%varlist(n)%nameinmodel, CS, 0, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
enddo
call ESMF_VMBroadCast(vm, streamdat(i)%meshfile, CL, 0, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call ESMF_VMBroadCast(vm, streamdat(i)%lev_dimname, CS, 0, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call ESMF_VMBroadCast(vm, streamdat(i)%taxmode, CS, 0, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call ESMF_VMBroadCast(vm, streamdat(i)%readmode, CS, 0, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call ESMF_VMBroadCast(vm, streamdat(i)%tinterpAlgo, CS, 0, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call ESMF_VMBroadCast(vm, streamdat(i)%stream_vectors, CL, 0, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call ESMF_VMBroadCast(vm, streamdat(i)%mapalgo, CS, 0, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
rtmp(1) = streamdat(i)%dtlimit
call ESMF_VMBroadCast(vm, rtmp, 1, 0, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
streamdat(i)%dtlimit = rtmp(1)
#ifdef CESMCOUPLED
! Initialize stream pio
streamdat(i)%pio_subsystem => shr_pio_getiosys(trim(compname))
streamdat(i)%pio_iotype = shr_pio_getiotype(trim(compname))
streamdat(i)%pio_ioformat = shr_pio_getioformat(trim(compname))
! This is to avoid an unused dummy argument warning
if(.false.) then
if(associated(pio_subsystem)) print *, io_type, io_format
endif
#else
streamdat(i)%pio_subsystem => pio_subsystem
streamdat(i)%pio_iotype = io_type
streamdat(i)%pio_ioformat = io_format
#endif
! Set logunit
streamdat(i)%logunit = logunit
call shr_stream_getCalendar(streamdat(i), 1, streamdat(i)%calendar)
! Error check
if (trim(streamdat(i)%taxmode) == shr_stream_taxis_extend .and. streamdat(i)%dtlimit < 1.e10) then
call shr_sys_abort(trim(subName)//" ERROR: if taxmode value is extend set dtlimit to 1.e30")
end if
! initialize flag that stream has been set
streamdat(i)%init = .true.
enddo
end subroutine shr_stream_init_from_xml
#endif
!===============================================================================
subroutine shr_stream_init_from_inline(streamdat, &
pio_subsystem, io_type, io_format, &
stream_meshfile, stream_lev_dimname, stream_mapalgo, &
stream_yearFirst, stream_yearLast, stream_yearAlign, &
stream_offset, stream_taxmode, stream_tintalgo, stream_dtlimit, &
stream_fldlistFile, stream_fldListModel, stream_fileNames, &
logunit, compname, stream_src_mask_val, stream_dst_mask_val)
! --------------------------------------------------------
! set values of stream datatype independent of a reading in a stream text file
! this is used to initialize a stream directly from fortran interface
! --------------------------------------------------------
! input/output variables
type(shr_stream_streamType) ,pointer, intent(inout) :: streamdat(:) ! data streams (assume 1 below)
type(iosystem_desc_t) ,pointer, intent(in) :: pio_subsystem ! data structure required for pio operations
integer ,intent(in) :: io_type ! data format
integer ,intent(in) :: io_format ! netcdf format
character(*) ,intent(in) :: stream_meshFile ! full pathname to stream mesh file
character(*) ,intent(in) :: stream_lev_dimname ! name of vertical dimension in stream
character(*) ,intent(in) :: stream_mapalgo ! stream mesh -> model mesh mapping type
integer ,intent(in) :: stream_yearFirst ! first year to use
integer ,intent(in) :: stream_yearLast ! last year to use
integer ,intent(in) :: stream_yearAlign ! align yearFirst with this model year
character(*) ,intent(in) :: stream_tintalgo ! time interpolation algorithm
integer ,intent(in) :: stream_offset ! offset in seconds of stream data
character(*) ,intent(in) :: stream_taxMode ! time axis mode
real(r8) ,intent(in) :: stream_dtlimit ! ratio of max/min stream delta times
character(*) ,intent(in) :: stream_fldListFile(:) ! file field names, colon delim list
character(*) ,intent(in) :: stream_fldListModel(:) ! model field names, colon delim list
character(*) ,intent(in) :: stream_filenames(:) ! stream data filenames (full pathnamesa)
integer ,intent(in) :: logunit ! stdout unit
character(len=*) ,intent(in) :: compname ! component name (e.g. ATM, OCN...)
integer ,optional, intent(in) :: stream_src_mask_val ! source mask value
integer ,optional, intent(in) :: stream_dst_mask_val ! destination mask value
! local variables
integer :: n
integer :: nfiles
integer :: nvars
character(CS) :: calendar ! stream calendar
character(*),parameter :: subName = '(shr_stream_init_from_inline) '
! --------------------------------------------------------
! Assume only 1 stream
allocate(streamdat(1))
! overwrite default values
streamdat(1)%meshFile = trim(stream_meshFile)
streamdat(1)%lev_dimname = trim(stream_lev_dimname)
streamdat(1)%mapalgo = trim(stream_mapalgo)
streamdat(1)%yearFirst = stream_yearFirst
streamdat(1)%yearLast = stream_yearLast
streamdat(1)%yearAlign = stream_yearAlign
streamdat(1)%tinterpAlgo = trim(stream_tintalgo)
streamdat(1)%offset = stream_offset
streamdat(1)%taxMode = trim(stream_taxMode)
streamdat(1)%dtlimit = stream_dtlimit
#ifdef CESMCOUPLED
! Initialize stream pio
streamdat(1)%pio_subsystem => shr_pio_getiosys(trim(compname))
streamdat(1)%pio_iotype = shr_pio_getiotype(trim(compname))
streamdat(1)%pio_ioformat = shr_pio_getioformat(trim(compname))
! This is to avoid an unused dummy argument warning
if(.false.) then
if(associated(pio_subsystem)) print *, io_type, io_format
endif
#else
streamdat(1)%pio_subsystem => pio_subsystem
streamdat(1)%pio_iotype = io_type
streamdat(1)%pio_ioformat = io_format
#endif
! initialize stream filenames
if (allocated(streamdat(1)%file)) then
deallocate(streamdat(1)%file)
end if
nfiles = size(stream_filenames)
streamdat(1)%nfiles = nfiles
allocate(streamdat(1)%file(nfiles))
do n = 1, nfiles
streamdat(1)%file(n)%name = trim(stream_filenames(n))
enddo
! Determine name of stream variables in file and model
nvars = size(stream_fldlistFile)
streamdat(1)%nvars = nvars
allocate(streamdat(1)%varlist(nvars))
do n = 1, nvars
streamdat(1)%varlist(n)%nameinfile = trim(stream_fldlistFile(n))
streamdat(1)%varlist(n)%nameinmodel = trim(stream_fldlistModel(n))
end do
! Initialize logunit
streamdat(:)%logunit = logunit
! Get stream calendar
call shr_stream_getCalendar(streamdat(1), 1, calendar)
streamdat(1)%calendar = trim(calendar)
! Set source and destination mask
if (present(stream_src_mask_val)) streamdat(1)%src_mask_val = stream_src_mask_val
if (present(stream_dst_mask_val)) streamdat(1)%dst_mask_val = stream_dst_mask_val
! Initialize flag that stream has been set
streamdat(1)%init = .true.
end subroutine shr_stream_init_from_inline
!===============================================================================
subroutine shr_stream_init_from_esmfconfig(streamfilename, streamdat, logunit, &
pio_subsystem, io_type, io_format, rc)
use esmf , only : ESMF_VM, ESMF_VMGetCurrent, ESMF_VMBroadCast
use esmf , only : ESMF_SUCCESS, ESMF_ConfigCreate, ESMF_ConfigLoadFile
use esmf , only : ESMF_ConfigGetLen, ESMF_ConfigGetAttribute
use esmf , only : ESMF_Config, ESMF_MAXSTR
!!---------------------------------------------------------------------
!! The configuration file is a text file that can have following entries
!! file_id: "stream"
!! file_version: 1.0
!! stream_info: 1
!! taxmode:
!! tInterpAlgo:
!! readMode:
!! mapalgo:
!! dtlimit:
!! yearFirst:
!! yearLast:
!! yearAlign:
!! stream_vectors:
!! stream_mesh_file:
!! stream_lev_dimname:
!! stream_data_files:
!! stream_data_variables:
!! stream_offset:
!! stream_src_mask:
!! stream_dst_mask:
!!---------------------------------------------------------------------
! input/output variables
character(len=*), optional , intent(in) :: streamfilename
type(shr_stream_streamType) , intent(inout), pointer :: streamdat(:)
integer , intent(in) :: logunit
type(iosystem_desc_t) , intent(in), pointer :: pio_subsystem
integer , intent(in) :: io_type
integer , intent(in) :: io_format
integer , intent(out) :: rc
! local variables
type(ESMF_VM) :: vm
type(ESMF_Config) :: cf
integer :: i, n, nstrms
character(2) :: mystrm
character(*),parameter :: subName = '(shr_stream_init_from_esmfconfig)'
character(len=ESMF_MAXSTR), allocatable :: strm_tmpstrings(:)
character(*) , parameter :: u_FILE_u = __FILE__
! ---------------------------------------------------------------------
rc = ESMF_SUCCESS
nstrms = 0
! allocate streamdat instance on all tasks
call ESMF_VMGetCurrent(vm, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
! set ESMF config
cf = ESMF_ConfigCreate(rc=RC)
call ESMF_ConfigLoadFile(config=CF ,filename=trim(streamfilename), rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
! get number of streams
nstrms = ESMF_ConfigGetLen(config=CF, label='stream_info:', rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
! allocate an array of shr_stream_streamtype objects on just isroot_task
if( nstrms > 0 ) then
allocate(streamdat(nstrms))
else
call shr_sys_abort("no stream_info in config file "//trim(streamfilename))
endif
! fill in non-default values for the streamdat attributes
do i=1, nstrms
write(mystrm,"(I2.2)") i
call ESMF_ConfigGetAttribute(CF,value=streamdat(i)%taxmode,label="taxmode"//mystrm//':', rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call ESMF_ConfigGetAttribute(CF,value=streamdat(i)%mapalgo,label="mapalgo"//mystrm//':', rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call ESMF_ConfigGetAttribute(CF,value=streamdat(i)%tInterpAlgo,label="tInterpAlgo"//mystrm//':', rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call ESMF_ConfigGetAttribute(CF,value=streamdat(i)%readMode,label="readMode"//mystrm//':', rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
if( ESMF_ConfigGetLen(config=CF, label="yearFirst"//mystrm//':', rc=rc) > 0 ) then
call ESMF_ConfigGetAttribute(CF,value=streamdat(i)%yearFirst,label="yearFirst"//mystrm//':', rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
else
call shr_sys_abort("yearFirst must be provided")
endif
if( ESMF_ConfigGetLen(config=CF, label="yearLast"//mystrm//':', rc=rc) > 0 ) then
call ESMF_ConfigGetAttribute(CF,value=streamdat(i)%yearLast,label="yearLast"//mystrm//':', rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
else
call shr_sys_abort("yearLast must be provided")
endif
if( ESMF_ConfigGetLen(config=CF, label="yearAlign"//mystrm//':', rc=rc) > 0 ) then
call ESMF_ConfigGetAttribute(CF,value=streamdat(i)%yearAlign,label="yearAlign"//mystrm//':', rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
else
call shr_sys_abort("yearAlign must be provided")
endif
call ESMF_ConfigGetAttribute(CF,value=streamdat(i)%dtlimit,label="dtlimit"//mystrm//':', rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call ESMF_ConfigGetAttribute(CF,value=streamdat(i)%offset,label="stream_offset"//mystrm//':', rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
if( ESMF_ConfigGetLen(config=CF, label="stream_mesh_file"//mystrm//':', rc=rc) > 0 ) then
call ESMF_ConfigGetAttribute(CF,value=streamdat(i)%meshfile,label="stream_mesh_file"//mystrm//':', rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
else
call shr_sys_abort("stream_mesh_file must be provided")
endif
if( ESMF_ConfigGetLen(config=CF, label="stream_vectors"//mystrm//':', rc=rc) > 0 ) then
call ESMF_ConfigGetAttribute(CF,value=streamdat(i)%stream_vectors,label="stream_vectors"//mystrm//':', rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
endif
if( ESMF_ConfigGetLen(config=CF, label="stream_lev_dimname"//mystrm//':', rc=rc) > 0 ) then
call ESMF_ConfigGetAttribute(CF,value=streamdat(i)%lev_dimname,label="stream_lev_dimname"//mystrm//':', rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
else
call shr_sys_abort("stream_lev_dimname must be provided")
endif
! Get a list of stream file names
streamdat(i)%nfiles = ESMF_ConfigGetLen(config=CF, label="stream_data_files"//mystrm//':', rc=rc)
if( streamdat(i)%nfiles > 0) then
allocate(streamdat(i)%file( streamdat(i)%nfiles))
allocate(strm_tmpstrings(streamdat(i)%nfiles))
call ESMF_ConfigGetAttribute(CF,valueList=strm_tmpstrings, label="stream_data_files"//mystrm//':', rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
do n=1,streamdat(i)%nfiles
streamdat(i)%file(n)%name = trim(strm_tmpstrings(n))
enddo
deallocate(strm_tmpstrings)
else
call shr_sys_abort("stream data files must be provided")
endif
! Get name of stream variables in file and model
streamdat(i)%nvars = ESMF_ConfigGetLen(config=CF, label="stream_data_variables"//mystrm//':', rc=rc)
if( streamdat(i)%nvars > 0) then
allocate(streamdat(i)%varlist(streamdat(i)%nvars))
allocate(strm_tmpstrings(streamdat(i)%nvars))
call ESMF_ConfigGetAttribute(CF,valueList=strm_tmpstrings,label="stream_data_variables"//mystrm//':', rc=rc)
do n=1, streamdat(i)%nvars
streamdat(i)%varlist(n)%nameinfile = strm_tmpstrings(n)(1:index(trim(strm_tmpstrings(n)), " "))
streamdat(i)%varlist(n)%nameinmodel = strm_tmpstrings(n)(index(trim(strm_tmpstrings(n)), " ", .true.)+1:)
enddo
deallocate(strm_tmpstrings)
else
call shr_sys_abort("stream data variables must be provided")
endif
! Initialize stream pio
streamdat(i)%pio_subsystem => pio_subsystem
streamdat(i)%pio_iotype = io_type
streamdat(i)%pio_ioformat = io_format
! Set logunit
streamdat(i)%logunit = logunit
call shr_stream_getCalendar(streamdat(i), 1, streamdat(i)%calendar)
! Get source and destination mask, 0 by default
call ESMF_ConfigGetAttribute(CF,value=streamdat(i)%src_mask_val,label="stream_src_mask"//mystrm//':', default=0, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call ESMF_ConfigGetAttribute(CF,value=streamdat(i)%dst_mask_val,label="stream_dst_mask"//mystrm//':', default=0, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
! Error check
if (trim(streamdat(i)%taxmode) == shr_stream_taxis_extend .and. streamdat(i)%dtlimit < 1.e10) then
call shr_sys_abort(trim(subName)//" ERROR: if taxmode value is extend set dtlimit to 1.e30")
end if
enddo ! end loop nstrm
! initialize flag that stream has been set
streamdat(:)%init = .true.
end subroutine shr_stream_init_from_esmfconfig
!===============================================================================
subroutine shr_stream_findBounds(strm, mDateIn, secIn, isroot_task, &
mDateLB, dDateLB, secLB, n_lb, fileLB, mDateUB, dDateUB, secUB, n_ub, fileUB)
!-------------------------------------------------------------------------------
! Given a stream and a model date, find time coordinates of the upper and
! lower time bounds surrounding the models date. Returns the model date,
! data date, elasped seconds, time index, and file names associated with
! these upper and lower time bounds.
! 1) take the model date, map it into the data date range
! 2) find the upper and lower bounding data dates
! 3) return the bounding data and model dates, file names, & t-coord indicies
!-------------------------------------------------------------------------------
! input/output parameters:
type(shr_stream_streamType) ,intent(inout):: strm ! data stream to query
integer ,intent(in) :: mDateIn ! model date (yyyymmdd)
integer ,intent(in) :: secIn ! elapsed sec on model date
logical ,intent(in) :: isroot_task ! is mpi task root communicator task
integer ,intent(out) :: mDateLB ! model date of LB
integer ,intent(out) :: dDateLB ! data date of LB
integer ,intent(out) :: secLB ! elap sec of LB
integer ,intent(out) :: n_lb ! t-coord index of LB
character(*) ,intent(out) :: fileLB ! file containing LB
integer ,intent(out) :: mDateUB ! model date of UB
integer ,intent(out) :: dDateUB ! data date of UB
integer ,intent(out) :: secUB ! elap sec of UB
integer ,intent(out) :: n_ub ! t-coord index of UB
character(*) ,intent(out) :: fileUB ! file containing UB
! local variables
integer :: dDateIn ! model date mapped onto a data date
integer :: dDateF ! first date
integer :: dDateL ! last date
integer :: n,nf ! loop index wrt t-coord array within one file
integer :: k,kf ! loop index wrt list of files
integer :: k_ub,k_lb ! file index of U/L bounds
integer :: rCode ! return code
integer :: mYear ! year of model date
integer :: yrFirst ! first year of data loop
integer :: yrLast ! last year of data loop
integer :: yrAlign ! model year that aligns with yearFirst
integer :: nYears ! number of years in data loop
integer :: dYear ! data year corresponding to model year
integer :: yy,mm,dd ! year,month,day
real(R8) :: rDateIn ! model dDateIn + secs/(secs per day)
real(R8) :: rDate1 ! stream dDateIn + secs/(secs per day)
real(R8) :: rDate2 ! stream dDateIn + secs/(secs per day)
real(R8) :: rDatelvd ! lvd dDate + secs/(secs per day)
real(R8) :: rDategvd ! gvd dDate + secs/(secs per day)
logical :: cycle ! is cycling on or off
logical :: limit ! is limiting on or off
character(*),parameter :: subName = '(shr_stream_findBounds) '
character(*),parameter :: F00 = "('(shr_stream_findBounds) ',8a)"
character(*),parameter :: F01 = "('(shr_stream_findBounds) ',a,i9.8,a)"
character(*),parameter :: F02 = "('(shr_stream_findBounds) ',a,2i9.8,i6,i5,1x,a)"
character(*),parameter :: F03 = "('(shr_stream_findBounds) ',a,i4)"
character(*),parameter :: F04 = "('(shr_stream_findBounds) ',2a,i4)"
!-------------------------------------------------------------------------------
if (debug>0 .and. isroot_task) then
write(strm%logunit,F02) "DEBUG: ---------- enter ------------------"
end if
if ( .not. strm%init ) then
call shr_sys_abort(trim(subName)//" ERROR: trying to find bounds of uninitialized stream")
end if
if (trim(strm%taxMode) == trim(shr_stream_taxis_cycle)) then
cycle = .true.
limit = .false.
elseif (trim(strm%taxMode) == trim(shr_stream_taxis_extend)) then
cycle = .false.
limit = .false.
elseif (trim(strm%taxMode) == trim(shr_stream_taxis_limit)) then
cycle = .false.
limit = .true.
else
write(strm%logunit,*) trim(subName),' ERROR: illegal taxMode = ',trim(strm%taxMode)
call shr_sys_abort(trim(subName)//' ERROR: illegal taxMode = '//trim(strm%taxMode))
endif
!----------------------------------------------------------------------------
! convert/map the model year/date into a data year/date
! note: these values will be needed later to convert data year to model year
!----------------------------------------------------------------------------
mYear = mDateIn/10000 ! assumes/require F90 truncation
yrFirst = strm%yearFirst ! first year in data sequence
yrLast = strm%yearLast ! last year in data sequence
yrAlign = strm%yearAlign ! model year corresponding to yearFirst
nYears = yrLast - yrFirst + 1 ! number of years in data sequence
dDateF = yrFirst * 10000 + 101 ! first date in valid range
dDateL = (yrLast+1) * 10000 + 101 ! last date in valid range
n = 0
if (cycle) then
dYear = yrFirst + modulo(mYear-yrAlign+(2*nYears),nYears) ! current data year
if(debug>0 .and. isroot_task) then
write(strm%logunit, *) trim(subname), ' dyear, yrfirst, myear, yralign, nyears =', dyear, yrfirst, myear, yralign, nyears
endif
else
dYear = yrFirst + mYear - yrAlign
endif
if (dYear < 0) then
write(strm%logunit,*) trim(subName),' ERROR: dyear lt zero = ',dYear
call shr_sys_abort(trim(subName)//' ERROR: dyear lt zero')
endif
dDateIn = dYear*10000 + modulo(mDateIn,10000) ! mDateIn mapped to range of data years
rDateIn = dDateIn + secIn/spd ! dDateIn + fraction of a day
if (debug>0 .and. isroot_task) then
write(strm%logunit,'(a,2(i8,2x),2(f20.4,2x))') 'mYear,dYear,dDateIn,rDateIn = ',mYear,dYear,dDateIn,rDateIn
write(strm%logunit,'(a,2(i8,2x),2(f20.4,2x))') 'yrFirst,yrLast,yrAlign,nYears= ',yrFirst,yrLast,yrAlign,nYears
endif
!----------------------------------------------------------------------------
! find least valid date (lvd)
!----------------------------------------------------------------------------
if (.not. strm%found_lvd) then
A: do k=1,strm%nFiles
if (.not. strm%file(k)%haveData) then
call shr_stream_readtCoord(strm, k, isroot_task, rCode)
if ( rCode /= 0 )then
call shr_sys_abort(trim(subName)//" ERROR: readtCoord1")
end if
end if
do n=1,strm%file(k)%nt
if ( dDateF <= strm%file(k)%date(n) ) then
!--- found a date in or beyond yearFirst ---
strm%k_lvd = k
strm%n_lvd = n
strm%found_lvd = .true.
exit A
end if
end do
end do A
if (.not. strm%found_lvd) then
write(strm%logunit,F00) "ERROR: LVD not found, all data is before yearFirst"
call shr_sys_abort(trim(subName)//" ERROR: LVD not found, all data is before yearFirst")
else
!--- LVD is in or beyond yearFirst, verify it is not beyond yearLast ---
if ( dDateL <= strm%file(strm%k_lvd)%date(strm%n_lvd) ) then
write(strm%logunit,F00) "ERROR: LVD not found, all data is after yearLast"
call shr_sys_abort(trim(subName)//" ERROR: LVD not found, all data is after yearLast")
end if
end if
if (debug>1 .and. isroot_task ) then
if (strm%found_lvd) write(strm%logunit,F01) " found LVD = ",strm%file(k)%date(n)
end if
end if
if (strm%found_lvd) then
k = strm%k_lvd
n = strm%n_lvd
rDatelvd = strm%file(k)%date(n) + strm%file(k)%secs(n)/spd ! LVD date + frac day
else
write(strm%logunit,F00) "ERROR: LVD not found yet"
call shr_sys_abort(trim(subName)//" ERROR: LVD not found yet")
endif
if (strm%found_gvd) then
k = strm%k_gvd
n = strm%n_gvd
rDategvd = strm%file(k)%date(n) + strm%file(k)%secs(n)/spd ! GVD date + frac day
else
rDategvd = 99991231.0
endif
if (debug>0 .and. isroot_task) then
write(strm%logunit,'(a,3(f20.4,2x))') 'rDateIn,rDatelvd,rDategvd = ',rDateIn,rDatelvd,rDategvd
endif
!-----------------------------------------------------------
! dateIn < rDatelvd
! limit -> abort
! extend -> use lvd value, set LB to 00000101
! cycle -> lvd is UB, gvd is LB, shift mDateLB by -nYears
!-----------------------------------------------------------
if (rDateIn < rDatelvd) then
if (limit) then
write(strm%logunit,*) trim(subName)," ERROR: limit on and rDateIn lt rDatelvd",rDateIn,rDatelvd
call shr_sys_abort(trim(subName)//" ERROR: rDateIn lt rDatelvd limit true")
endif
if (.not.cycle) then
k_lb = strm%k_lvd
n_lb = strm%n_lvd
dDateLB = 00000101
mDateLB = 00000101
secLB = 0
fileLB = strm%file(k_lb)%name
k_ub = strm%k_lvd
n_ub = strm%n_lvd
dDateUB = strm%file(k_ub)%date(n_ub)
call shr_cal_date2ymd(dDateUB,yy,mm,dd)
yy = yy + (mYear-dYear)
call shr_cal_ymd2date(yy,mm,dd,mDateUB)
secUB = strm%file(k_ub)%secs(n_ub)
fileUB = strm%file(k_ub)%name
return
endif
if (cycle) then
!--- find greatest valid date (GVD) ---
if (.not. strm%found_gvd) then
!--- start search at last file & move toward first file ---
B: do k=strm%nFiles,1,-1
!--- read data for file number k ---
if (.not. strm%file(k)%haveData) then
call shr_stream_readtCoord(strm, k, isroot_task, rCode)
if ( rCode /= 0 )then
call shr_sys_abort(trim(subName)//" ERROR: readtCoord2")
end if
end if
!--- start search at greatest date & move toward least date ---
do n=strm%file(k)%nt,1,-1
if ( strm%file(k)%date(n) < dDateL ) then
strm%k_gvd = k
strm%n_gvd = n
strm%found_gvd = .true.
rDategvd = strm%file(k)%date(n) + strm%file(k)%secs(n)/spd ! GVD date + frac day
if (debug>1 .and. isroot_task) then
write(strm%logunit,F01) " found GVD ",strm%file(k)%date(n)
end if
exit B
end if
end do
end do B
end if
if (.not. strm%found_gvd) then
write(strm%logunit,F00) "ERROR: GVD not found1"
call shr_sys_abort(trim(subName)//" ERROR: GVD not found1")
endif
k_lb = strm%k_gvd
n_lb = strm%n_gvd
dDateLB = strm%file(k_lb)%date(n_lb)
call shr_cal_date2ymd(dDateLB,yy,mm,dd)
yy = yy + (mYear-dYear-nYears)
call shr_cal_ymd2date(yy,mm,dd,mDateLB)
secLB = strm%file(k_lb)%secs(n_lb)
fileLB = strm%file(k_lb)%name
k_ub = strm%k_lvd
n_ub = strm%n_lvd
dDateUB = strm%file(k_ub)%date(n_ub)
call shr_cal_date2ymd(dDateUB,yy,mm,dd)
yy = yy + (mYear-dYear)
call shr_cal_ymd2date(yy,mm,dd,mDateUB)