-
Notifications
You must be signed in to change notification settings - Fork 3
/
HMC_Module_Data_Restart_Gridded.f90
1853 lines (1622 loc) · 106 KB
/
HMC_Module_Data_Restart_Gridded.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
!------------------------------------------------------------------------------------------
! File: HMC_Module_Data_Restart_Gridded.f90
! Author(s): Fabio Delogu, Francesco Silvestro, Simone Gabellani
!
! Created on May 7, 2015, 1:27 PM
!------------------------------------------------------------------------------------------
!------------------------------------------------------------------------------------------
! Module Header
module HMC_Module_Data_Restart_Gridded
!------------------------------------------------------------------------------------------
! External module(s) for all subroutine in this module
#ifdef LIB_NC
use netcdf
#endif
use HMC_Module_Namelist, only: oHMC_Namelist
use HMC_Module_Vars_Loader, only: oHMC_Vars
use HMC_Module_Tools_Debug
#ifdef LIB_NC
use HMC_Module_Tools_IO, only: HMC_Tools_IO_Get2d_Binary_INT, &
HMC_Tools_IO_Get2d_Binary_DBL, &
HMC_Tools_IO_Get3d_Binary, &
HMC_Tools_IO_Get2d_NC, &
HMC_Tools_IO_Get3d_NC, &
check
#else
use HMC_Module_Tools_IO, only: HMC_Tools_IO_Get2d_Binary_INT, &
HMC_Tools_IO_Get2d_Binary_DBL, &
HMC_Tools_IO_Get3d_Binary
#endif
use HMC_Module_Tools_Generic, only: HMC_Tools_Generic_ReplaceText, &
HMC_Tools_Generic_CreateFolder, &
HMC_Tools_Generic_ZipFile, &
HMC_Tools_Generic_UnzipFile, &
HMC_Tools_Generic_RemoveFile, &
transpose3Dvar, &
checkdomainvar, getProcessID
! Implicit none for all subroutines in this module
implicit none
!------------------------------------------------------------------------------------------
contains
!------------------------------------------------------------------------------------------
! Subroutine to manage restart gridded data
subroutine HMC_Data_Restart_Gridded_Cpl( iID, sTime, &
iRowsStart, iRowsEnd, &
iColsStart, iColsEnd, &
iDaySteps, iTMarkedSteps)
!------------------------------------------------------------------------------------------
! Variable(s)
integer(kind = 4) :: iID
integer(kind = 4) :: iFlagRestart, iFlagSnow, iFlagCType
integer(kind = 4) :: iRows, iCols
integer(kind = 4) :: iRowsStart, iColsStart, iRowsEnd, iColsEnd
integer(kind = 4) :: iDaySteps, iTMarkedSteps
integer(kind = 4) :: iDtIntegr
integer(kind = 4) :: iFlagTypeData_Restart
integer(kind = 4) :: iScaleFactor
character(len = 19) :: sTime
character(len = 700) :: sPathData_Restart
character(len = 700) :: sFileNameData_Restart, sFileNameData_Restart_Zip
character(len = 700) :: sCommandUnzipFile
real(kind = 4), dimension(iRowsEnd - iRowsStart + 1, iColsEnd - iColsStart + 1) :: a2dVarDEM
real(kind = 4), dimension(iRowsEnd - iRowsStart + 1, iColsEnd - iColsStart + 1) :: a2dVarVTot, a2dVarVRet, &
a2dVarHydro, a2dVarRouting, &
a2dVarFlowDeep, &
a2dVarWTable, a2dVarLST, &
a2dVarLat, a2dVarLon
real(kind = 4), dimension(iRowsEnd - iRowsStart + 1, iColsEnd - iColsStart + 1) :: a2dVarHydroC, a2dVarHydroH, &
a2dVarQup
integer(kind = 4), dimension(iRowsEnd - iRowsStart + 1, iColsEnd - iColsStart + 1) :: a2iVarAgeS
real(kind = 4), dimension(iRowsEnd - iRowsStart + 1, iColsEnd - iColsStart + 1) :: a2dVarSWE, a2dVarAlbedoS
real(kind = 4), dimension(iRowsEnd - iRowsStart + 1, iColsEnd - iColsStart + 1) :: a2dVarRhoS, a2dVarRhoS0
real(kind = 4), dimension(iRowsEnd - iRowsStart + 1, iColsEnd - iColsStart + 1, iDaySteps) :: a3dVarTaC_1Days
real(kind = 4), dimension(iRowsEnd - iRowsStart + 1, iColsEnd - iColsStart + 1, iDaySteps*5) :: a3dVarTaC_5Days
real(kind = 4), dimension(iRowsEnd - iRowsStart + 1, iColsEnd - iColsStart + 1) :: a2dVarWSRunoff
real(kind = 4), dimension(iRowsEnd - iRowsStart + 1, iColsEnd - iColsStart + 1) :: a2dVarWTableUpd
real(kind = 4), dimension(iRowsEnd - iRowsStart + 1, iColsEnd - iColsStart + 1, iTMarkedSteps) :: a3dVarTaKMarked
real(kind = 4), dimension(iRowsEnd - iRowsStart + 1, iColsEnd - iColsStart + 1, iDaySteps) :: a3dVarTaK24
logical :: bFileExist, bCheckRestart, bCheckRestartS
!------------------------------------------------------------------------------------------
!------------------------------------------------------------------------------------------
! Initialize variable(s)
a2dVarVTot = 0.0; a2dVarVRet = 0.0; a2dVarHydro = 0.0; a2dVarRouting = 0.0; a2dVarFlowDeep = 0.0;
a2dVarLST = 0.0; a2dVarWTable = 0.0; a3dVarTaKMarked = 0.0; a3dVarTaK24 = 0.0;
a2dVarLat = 0.0; a2dVarLon = 0.0
a2dVarHydroC = 0.0; a2dVarHydroH = 0.0; a2dVarQup = 0.0;
a2iVarAgeS = 0; a2dVarSWE = 0.0; a2dVarAlbedoS = 0.0; a2dVarRhoS = 0.0; a2dVarRhoS0 = 0.0
a3dVarTaC_1Days = 0.0; a3dVarTaC_5Days = 0.0;
a2dVarWTableUpd = 0.0;
a2dVarWSRunoff = 0.0;
!------------------------------------------------------------------------------------------
!------------------------------------------------------------------------------------------
! Defining iRows and iCols (output data)
iRows = iRowsEnd - iRowsStart + 1
iCols = iColsEnd - iColsStart + 1
!------------------------------------------------------------------------------------------
!------------------------------------------------------------------------------------------
! Get global information
iFlagRestart = oHMC_Namelist(iID)%iFlagRestart
iFlagSnow = oHMC_Namelist(iID)%iFlagSnow
iFlagCType = oHMC_Namelist(iID)%iFlagCType
sPathData_Restart = oHMC_Namelist(iID)%sPathData_Restart_Gridded
iFlagTypeData_Restart = oHMC_Namelist(iID)%iFlagTypeData_Restart_Gridded
iScaleFactor = oHMC_Namelist(iID)%iScaleFactor
sCommandUnzipFile = oHMC_Namelist(iID)%sCommandUnzipFile
! Get glabal variable(s)
a2dVarDem = oHMC_Vars(iID)%a2dDem
! Info start
call mprintf(.true., iINFO_Extra, ' Data :: Restart gridded ... ' )
!------------------------------------------------------------------------------------------
!------------------------------------------------------------------------------------------
! Debug
if (iDEBUG.gt.0) then
call mprintf(.true., iINFO_Extra, ' ========= RESTART GRIDDED START =========== ')
call mprintf(.true., iINFO_Extra, checkvar(oHMC_Vars(iID)%a2dVTot, oHMC_Vars(iID)%a2iMask, 'VTOT START') )
call mprintf(.true., iINFO_Extra, checkvar(oHMC_Vars(iID)%a2dVRet, oHMC_Vars(iID)%a2iMask, 'VRET START') )
call mprintf(.true., iINFO_Extra, checkvar(oHMC_Vars(iID)%a2dHydro, oHMC_Vars(iID)%a2iMask, 'HYDRO START') )
call mprintf(.true., iINFO_Extra, checkvar(oHMC_Vars(iID)%a2dHydroC, oHMC_Vars(iID)%a2iMask, 'HYDROC START') )
call mprintf(.true., iINFO_Extra, checkvar(oHMC_Vars(iID)%a2dHydroH, oHMC_Vars(iID)%a2iMask, 'HYDROH START') )
call mprintf(.true., iINFO_Extra, checkvar(oHMC_Vars(iID)%a2dQup, oHMC_Vars(iID)%a2iMask, 'QUP START') )
call mprintf(.true., iINFO_Extra, checkvar(oHMC_Vars(iID)%a2dRouting, oHMC_Vars(iID)%a2iMask, 'ROUTING START') )
call mprintf(.true., iINFO_Extra, checkvar(oHMC_Vars(iID)%a2dWTable, oHMC_Vars(iID)%a2iMask, 'WTABLE START') )
call mprintf(.true., iINFO_Extra, checkvar(oHMC_Vars(iID)%a2dLST, oHMC_Vars(iID)%a2iMask, 'LST START') )
call mprintf(.true., iINFO_Extra, checkvar(oHMC_Vars(iID)%a3dTaKMarked(:,:,1), oHMC_Vars(iID)%a2iMask, 'TAMk START') )
call mprintf(.true., iINFO_Extra, checkvar(oHMC_Vars(iID)%a3dTaK24(:,:,1), oHMC_Vars(iID)%a2iMask, 'TA24 END') )
call mprintf(.true., iINFO_Extra, checkvar(oHMC_Vars(iID)%a2dFlowDeep, oHMC_Vars(iID)%a2iMask, 'FLOWDEEP START') )
call mprintf(.true., iINFO_Extra, checkvar(real(oHMC_Vars(iID)%a2iAge), oHMC_Vars(iID)%a2iMask, 'AGES START') )
call mprintf(.true., iINFO_Extra, checkvar(oHMC_Vars(iID)%a2dSWE, oHMC_Vars(iID)%a2iMask, 'SWE START') )
call mprintf(.true., iINFO_Extra, checkvar(oHMC_Vars(iID)%a2dRhoS, oHMC_Vars(iID)%a2iMask, 'RHOS START') )
call mprintf(.true., iINFO_Extra, checkvar(oHMC_Vars(iID)%a2dAlbedo_Snow, oHMC_Vars(iID)%a2iMask, 'ALBEDOS START') )
call mprintf(.true., iINFO_Extra, &
checkvar(oHMC_Vars(iID)%a3dTaC_Days1(:,:,1), oHMC_Vars(iID)%a2iMask, 'TA 1DAYS START') )
call mprintf(.true., iINFO_Extra, &
checkvar(oHMC_Vars(iID)%a3dTaC_Days5(:,:,1), oHMC_Vars(iID)%a2iMask, 'TA 5DAYS START') )
call mprintf(.true., iINFO_Extra, '')
endif
!------------------------------------------------------------------------------------------
!------------------------------------------------------------------------------------------
! Check restart flag value
if (iFlagRestart == 1) then
!------------------------------------------------------------------------------------------
! Replace general path with specific time feature(s)
call HMC_Tools_Generic_ReplaceText(sPathData_Restart, '$yyyy', sTime(1:4))
call HMC_Tools_Generic_ReplaceText(sPathData_Restart, '$mm', sTime(6:7))
call HMC_Tools_Generic_ReplaceText(sPathData_Restart, '$dd', sTime(9:10))
call HMC_Tools_Generic_ReplaceText(sPathData_Restart, '$HH', sTime(12:13))
call HMC_Tools_Generic_ReplaceText(sPathData_Restart, '$MM', sTime(15:16))
!------------------------------------------------------------------------------------------
!------------------------------------------------------------------------------------------
! Subroutine for reading netCDF restart data
if (iFlagTypeData_Restart == 2) then
!------------------------------------------------------------------------------------------
! Call subroutine to read data in netCDF format
#ifdef LIB_NC
call HMC_Data_Restart_Gridded_NC(iID, &
sPathData_Restart, &
iRows, iCols, iDtIntegr, &
iDaySteps, iTMarkedSteps, &
sTime, iFlagSnow, iFlagCType, &
a2dVarVTot, a2dVarVRet, &
a2dVarHydro, a2dVarRouting, &
a2dVarHydroC, a2dVarHydroH, a2dVarQup, &
a2dVarFlowDeep, &
a2dVarWTable, &
a2dVarLST, a3dVarTaKMarked, a3dVarTaK24, &
a2iVarAgeS, a2dVarSWE, a2dVarAlbedoS, a2dVarRhoS, &
a3dVarTaC_1Days, a3dVarTaC_5Days, &
a2dVarWSRunoff, &
a2dVarLat, a2dVarLon, &
bCheckRestart, bCheckRestartS)
#else
! Redefinition of forcing data flag (if netCDF library is not linked)
iFlagTypeData_Restart = 1
call mprintf(.true., iWARN, ' '// &
'restart gridded data type selected was netCDF but library is not linked! '// &
'Will be used data in binary format!')
#endif
!------------------------------------------------------------------------------------------
endif
!------------------------------------------------------------------------------------------
!------------------------------------------------------------------------------------------
! Subroutine for reading restart data in binary format
if (iFlagTypeData_Restart == 1) then
!------------------------------------------------------------------------------------------
! Call subroutine to read data in binary format
call HMC_Data_Restart_Gridded_Binary(iID, &
sPathData_Restart, &
iRows, iCols, iDtIntegr, &
iDaySteps, iTMarkedSteps, &
sTime, iFlagSnow, iFlagCType, &
a2dVarVTot, a2dVarVRet, &
a2dVarHydro, a2dVarRouting, &
a2dVarHydroC, a2dVarHydroH, a2dVarQup, &
a2dVarFlowDeep, &
a2dVarWTable, &
a2dVarLST, a3dVarTaKMarked, a3dVarTaK24, &
a2iVarAgeS, a2dVarSWE, a2dVarAlbedoS, a2dVarRhoS, &
a3dVarTaC_1Days, a3dVarTaC_5Days, &
a2dVarWSRunoff, &
bCheckRestart, bCheckRestartS)
!------------------------------------------------------------------------------------------
endif
!------------------------------------------------------------------------------------------
!------------------------------------------------------------------------------------------
! Check restart flag on data availability
call mprintf(.true., iINFO_Extra, ' Data :: Restart gridded for generic physics ... ' )
if (bCheckRestart .eqv. .true.) then
!------------------------------------------------------------------------------------------
! Parameter(s) Integration Step
if (iDtIntegr .gt. 0) then
oHMC_Vars(iID)%iDtIntegrPStep = iDtIntegr
else
call mprintf(.true., iWARN, ' The integration step is less then 0; '// &
'the parameter will be set by the namelist default value.')
endif
!------------------------------------------------------------------------------------------
!------------------------------------------------------------------------------------------
! Variable(s) conversion (Watertable)
where(a2dVarDem.gt.0.0)
a2dVarWTableUpd = a2dVarDem - a2dVarWTable/1000
endwhere
! Check limit(s)
where(a2dVarWTableUpd.gt.a2dVarDem)
a2dVarWTableUpd = a2dVarDem
endwhere
where(a2dVarWTableUpd.lt.oHMC_Vars(iID)%a2dWTableMax)
a2dVarWTableUpd = oHMC_Vars(iID)%a2dWTableMax
endwhere
! Initialize hydro variable(s) according with channel type
if (iFlagCType.eq.2) then
! Check hydro c initialization
where (a2dVarHydroC .lt. 0.0000001)
a2dVarHydroC = 0.0000001
endwhere
where (a2dVarHydroC .gt. 100000.0)
a2dVarHydroC = 0.0000001
endwhere
! Check hydro h initialization
where (a2dVarHydroH .lt. 0.0000001)
a2dVarHydroH = 0.0000001
endwhere
where (a2dVarHydroH .gt. 100000.0)
a2dVarHydroH = 0.0000001
endwhere
else
! Check hydro initialization
where (a2dVarHydro .lt. 0.0000001)
a2dVarHydro = 0.0000001
endwhere
where (a2dVarHydro .gt. 100000.0)
a2dVarHydro = 0.0000001
endwhere
endif
!------------------------------------------------------------------------------------------
!------------------------------------------------------------------------------------------
! Check variable(s) domain
a2dVarVTot = checkdomainvar(a2dVarVTot, oHMC_Vars(iID)%a2iMask, -9999.0 )
a2dVarVRet = checkdomainvar(a2dVarVRet, oHMC_Vars(iID)%a2iMask, 0.001 )
if (iFlagCType.eq.2) then
a2dVarHydroC = checkdomainvar(a2dVarHydroC, oHMC_Vars(iID)%a2iMask, 0.0 )
a2dVarHydroH = checkdomainvar(a2dVarHydroH, oHMC_Vars(iID)%a2iMask, 0.0 )
a2dVarQup = checkdomainvar(a2dVarQup, oHMC_Vars(iID)%a2iMask, 0.0 )
else
a2dVarHydro = checkdomainvar(a2dVarHydro, oHMC_Vars(iID)%a2iMask, 0.0 )
endif
a2dVarRouting = checkdomainvar(a2dVarRouting, oHMC_Vars(iID)%a2iMask, 0.0 )
a2dVarWTableUpd = checkdomainvar(a2dVarWTableUpd, oHMC_Vars(iID)%a2iMask, -9999.0 )
a2dVarLST = checkdomainvar(a2dVarLST, oHMC_Vars(iID)%a2iMask, -9999.0 )
a2dVarFlowDeep = checkdomainvar(a2dVarFlowDeep, oHMC_Vars(iID)%a2iMask, 0.0 )
a2dVarWSRunoff = checkdomainvar(a2dVarWSRunoff, oHMC_Vars(iID)%a2iMask, 0.0 )
!------------------------------------------------------------------------------------------
!------------------------------------------------------------------------------------------
! Pass variable(s) to global workspace
oHMC_Vars(iID)%a2dVTot = a2dVarVTot;
oHMC_Vars(iID)%a2dVRet = a2dVarVRet;
oHMC_Vars(iID)%a2dHydro = a2dVarHydro;
oHMC_Vars(iID)%a2dHydroC = a2dVarHydroC;
oHMC_Vars(iID)%a2dHydroH = a2dVarHydroH;
oHMC_Vars(iID)%a2dQup = a2dVarQup;
oHMC_Vars(iID)%a2dRouting = a2dVarRouting;
oHMC_Vars(iID)%a2dWTable = a2dVarWTableUpd;
oHMC_Vars(iID)%a2dLST = a2dVarLST;
oHMC_Vars(iID)%a2dFlowDeep = a2dVarFlowDeep;
oHMC_Vars(iID)%a3dTaKMarked = a3dVarTaKMarked;
oHMC_Vars(iID)%a3dTaK24 = a3dVarTaK24
oHMC_Vars(iID)%a2dWSRunoff = a2dVarWSRunoff
! Info end
call mprintf(.true., iINFO_Extra, ' Data :: Restart gridded for generic physics ... OK' )
!------------------------------------------------------------------------------------------
else
!------------------------------------------------------------------------------------------
! Exit message for not using restart data
call mprintf(.true., iINFO_Verbose, ' Restart flag selected but data are N/A (gridded data)')
! Info end
call mprintf(.true., iINFO_Extra, ' Data :: Restart gridded for generic physics ... SKIPPED ' )
!------------------------------------------------------------------------------------------
endif
!------------------------------------------------------------------------------------------
!------------------------------------------------------------------------------------------
! Check restart flag on snow data availability
call mprintf(.true., iINFO_Extra, ' Data :: Restart gridded for snow physics ... ' )
if (bCheckRestartS .eqv. .true.) then
!------------------------------------------------------------------------------------------
! Definition of snow density where SWE equal to 0.0 in restart condition
where(a2dVarSWE.eq.0.0) a2dVarRhoS = oHMC_Namelist(iID)%dRhoSnowFresh
where(a2dVarSWE.eq.0.0) a2dVarRhoS0 = oHMC_Namelist(iID)%dRhoSnowFresh
!------------------------------------------------------------------------------------------
!------------------------------------------------------------------------------------------
! Pass variable(s) to global workspace
oHMC_Vars(iID)%a2iAge = a2iVarAgeS
oHMC_Vars(iID)%a2dSWE = a2dVarSWE
oHMC_Vars(iID)%a2dRhoS = a2dVarRhoS
oHMC_Vars(iID)%a2dRhoS0 = a2dVarRhoS0
oHMC_Vars(iID)%a2dAlbedo_Snow = a2dVarAlbedoS
oHMC_Vars(iID)%a3dTaC_Days1 = a3dVarTaC_1Days
oHMC_Vars(iID)%a3dTaC_Days5 = a3dVarTaC_5Days
! Info end
call mprintf(.true., iINFO_Extra, ' Data :: Restart gridded for snow physics ... OK' )
!------------------------------------------------------------------------------------------
else
!------------------------------------------------------------------------------------------
! Exit message for not using restart data
call mprintf(.true., iINFO_Verbose, ' Restart flag selected but snow data are N/A (gridded data)')
! Info end
call mprintf(.true., iINFO_Extra, ' Data :: Restart gridded for snow physics ... SKIPPED' )
!------------------------------------------------------------------------------------------
endif
!------------------------------------------------------------------------------------------
else
!------------------------------------------------------------------------------------------
! Exit message for not using restart data
call mprintf(.true., iINFO_Verbose, ' No restart run selected (gridded data)')
! Info end
call mprintf(.true., iINFO_Extra, ' Data :: Restart gridded ... SKIPPED ' )
!------------------------------------------------------------------------------------------
endif
!------------------------------------------------------------------------------------------
!------------------------------------------------------------------------------------------
! Debug
if (iDEBUG.gt.0) then
call mprintf(.true., iINFO_Extra, '')
call mprintf(.true., iINFO_Extra, checkvar(oHMC_Vars(iID)%a2dVTot, oHMC_Vars(iID)%a2iMask, 'VTOT END') )
call mprintf(.true., iINFO_Extra, checkvar(oHMC_Vars(iID)%a2dVRet, oHMC_Vars(iID)%a2iMask, 'VRET END') )
call mprintf(.true., iINFO_Extra, checkvar(oHMC_Vars(iID)%a2dHydro, oHMC_Vars(iID)%a2iMask, 'HYDRO END') )
call mprintf(.true., iINFO_Extra, checkvar(oHMC_Vars(iID)%a2dHydroC, oHMC_Vars(iID)%a2iMask, 'HYDROC END') )
call mprintf(.true., iINFO_Extra, checkvar(oHMC_Vars(iID)%a2dHydroH, oHMC_Vars(iID)%a2iMask, 'HYDROH END') )
call mprintf(.true., iINFO_Extra, checkvar(oHMC_Vars(iID)%a2dQup, oHMC_Vars(iID)%a2iMask, 'QUP END') )
call mprintf(.true., iINFO_Extra, checkvar(oHMC_Vars(iID)%a2dRouting, oHMC_Vars(iID)%a2iMask, 'ROUTING END') )
call mprintf(.true., iINFO_Extra, checkvar(oHMC_Vars(iID)%a2dWTable, oHMC_Vars(iID)%a2iMask, 'WTABLE END') )
call mprintf(.true., iINFO_Extra, checkvar(oHMC_Vars(iID)%a2dLST, oHMC_Vars(iID)%a2iMask, 'LST END') )
call mprintf(.true., iINFO_Extra, checkvar(oHMC_Vars(iID)%a3dTaKMarked(:,:,1), oHMC_Vars(iID)%a2iMask, 'TAMk END') )
call mprintf(.true., iINFO_Extra, checkvar(oHMC_Vars(iID)%a3dTaK24(:,:,1), oHMC_Vars(iID)%a2iMask, 'TA24 END') )
call mprintf(.true., iINFO_Extra, checkvar(oHMC_Vars(iID)%a2dFlowDeep, oHMC_Vars(iID)%a2iMask, 'FLOWDEEP END') )
call mprintf(.true., iINFO_Extra, checkvar(real(oHMC_Vars(iID)%a2iAge), oHMC_Vars(iID)%a2iMask, 'AGES END') )
call mprintf(.true., iINFO_Extra, checkvar(oHMC_Vars(iID)%a2dSWE, oHMC_Vars(iID)%a2iMask, 'SWE END') )
call mprintf(.true., iINFO_Extra, checkvar(oHMC_Vars(iID)%a2dRhoS, oHMC_Vars(iID)%a2iMask, 'RHOS END') )
call mprintf(.true., iINFO_Extra, checkvar(oHMC_Vars(iID)%a2dAlbedo_Snow, oHMC_Vars(iID)%a2iMask, 'ALBEDOS END') )
call mprintf(.true., iINFO_Extra, &
checkvar(oHMC_Vars(iID)%a3dTaC_Days1(:,:,1), oHMC_Vars(iID)%a2iMask, 'TA 1DAYS END') )
call mprintf(.true., iINFO_Extra, &
checkvar(oHMC_Vars(iID)%a3dTaC_Days5(:,:,1), oHMC_Vars(iID)%a2iMask, 'TA 5DAYS END') )
call mprintf(.true., iINFO_Extra, '')
call mprintf(.true., iINFO_Extra, ' ========= RESTART GRIDDED END =========== ')
endif
!------------------------------------------------------------------------------------------
end subroutine HMC_Data_Restart_Gridded_Cpl
!------------------------------------------------------------------------------------------
!------------------------------------------------------------------------------------------
! Subroutine to read netCDF data restart
#ifdef LIB_NC
subroutine HMC_Data_Restart_Gridded_NC(iID, &
sPathData_Restart, &
iRows, iCols, iDtIntegr, &
iDaySteps, iTMarkedSteps, &
sTime, iFlagSnow, iFlagCType, &
a2dVarVTot, a2dVarVRet, &
a2dVarHydro, a2dVarRouting, &
a2dVarHydroC, a2dVarHydroH, a2dVarQup, &
a2dVarFlowDeep, &
a2dVarWTable, &
a2dVarLST, a3dVarTaKMarked, a3dVarTaK24, &
a2iVarAgeS, a2dVarSWE, a2dVarAlbedoS, a2dVarRhoS, &
a3dVarTaC_1Days, a3dVarTaC_5Days, &
a2dVarWSRunoff, &
a2dVarLat, a2dVarLon, &
bCheckRestart, bCheckRestartS)
!------------------------------------------------------------------------------------------
! Variable(s)
integer(kind = 4) :: iID
character(len = 256), intent(in) :: sPathData_Restart
character(len = 700) :: sFileNameData_Restart, sFileNameData_Restart_Zip, sFileNameData_Temp
character(len = 700) :: sCommandUnzipFile
character(len = 256) :: sVarName
integer(kind = 4), intent(in) :: iRows, iCols
integer(kind = 4), intent(in) :: iDaySteps, iTMarkedSteps
integer(kind = 4), intent(in) :: iFlagSnow, iFlagCType
integer(kind = 4) :: iDtIntegr
character(len = 19), intent(in) :: sTime
real(kind = 4), dimension(iCols, iRows) :: a2dVar
real(kind = 4), dimension(iCols, iRows, iTMarkedSteps) :: a3dVar1
real(kind = 4), dimension(iCols, iRows, iDaySteps) :: a3dVar2
real(kind = 4), dimension(iCols, iRows, iDaySteps) :: a3dVar3
real(kind = 4), dimension(iCols, iRows, iDaySteps*5) :: a3dVar4
real(kind = 4), dimension(iRows, iCols), intent(out) :: a2dVarVTot
real(kind = 4), dimension(iRows, iCols), intent(out) :: a2dVarVRet
real(kind = 4), dimension(iRows, iCols), intent(out) :: a2dVarHydro
real(kind = 4), dimension(iRows, iCols), intent(out) :: a2dVarRouting
real(kind = 4), dimension(iRows, iCols), intent(out) :: a2dVarHydroC
real(kind = 4), dimension(iRows, iCols), intent(out) :: a2dVarHydroH
real(kind = 4), dimension(iRows, iCols), intent(out) :: a2dVarQup
real(kind = 4), dimension(iRows, iCols), intent(out) :: a2dVarFlowDeep
real(kind = 4), dimension(iRows, iCols), intent(out) :: a2dVarWTable
real(kind = 4), dimension(iRows, iCols), intent(out) :: a2dVarLST
real(kind = 4), dimension(iRows, iCols, iTMarkedSteps), intent(out) :: a3dVarTaKMarked
real(kind = 4), dimension(iRows, iCols, iDaySteps), intent(out) :: a3dVarTaK24
integer(kind = 4), dimension(iRows, iCols), intent(out) :: a2iVarAgeS
real(kind = 4), dimension(iRows, iCols), intent(out) :: a2dVarSWE
real(kind = 4), dimension(iRows, iCols), intent(out) :: a2dVarAlbedoS
real(kind = 4), dimension(iRows, iCols), intent(out) :: a2dVarRhoS
real(kind = 4), dimension(iRows, iCols, iDaySteps), intent(out) :: a3dVarTaC_1Days
real(kind = 4), dimension(iRows, iCols, iDaySteps*5), intent(out) :: a3dVarTaC_5Days
real(kind = 4), dimension(iRows, iCols), intent(out) :: a2dVarWSRunoff
real(kind = 4), dimension(iRows, iCols), intent(out) :: a2dVarLat
real(kind = 4), dimension(iRows, iCols), intent(out) :: a2dVarLon
character(len = 256) :: sVarUnits, sPID
integer(kind = 4) :: iErr
integer(kind = 4) :: iFileID
real(kind = 4) :: dScaleFactor
logical :: bFileExist
logical :: bCheckRestart, bCheckRestartS
logical :: bCheckVar, bCheckVarS
!------------------------------------------------------------------------------------------
!------------------------------------------------------------------------------------------
! Initialize variable(s)
a2dVarVTot = -9999.0; a2dVarVRet = -9999.0;
a2dVarHydro = -9999.0; a2dVarRouting = -9999.0;
a2dVarHydroC = -9999.0; a2dVarHydroH = -9999.0; a2dVarQup = -9999.0;
a2dVarFlowDeep = -9999.0; a2dVarWTable = -9999.0;
a2dVarLST = -9999.0; a3dVarTaKMarked = -9999.0; a3dVarTaK24 = -9999.0;
a2iVarAgeS = -9999; a2dVarSWE = -9999.0; a2dVarAlbedoS = -9999.0; a2dVarRhoS = -9999.0;
a3dVarTaC_1Days = -9999.0; a3dVarTaC_5Days = -9999.0;
a2dVarWSRunoff = -9999.0
a2dVarLat = -9999.0; a2dVarLon = -9999.0;
dScaleFactor = 0.0; iDtIntegr = -9999;
bCheckRestart = .false.; sPID = '';
bCheckVar = .true.; bCheckVarS = .true.
!------------------------------------------------------------------------------------------
!------------------------------------------------------------------------------------------
! Get global information
sCommandUnzipFile = oHMC_Namelist(iID)%sCommandUnzipFile
! Info start
call mprintf(.true., iINFO_Extra, ' Data :: Restart gridded :: NetCDF ... ' )
! Get unique process ID
sPID = adjustl(getProcessID())
!------------------------------------------------------------------------------------------
!------------------------------------------------------------------------------------------
! Filename restart (example: hmc.state.201404300000.nc)
sFileNameData_Restart = trim(sPathData_Restart)//"hmc.state-grid."// &
sTime(1:4)//sTime(6:7)//sTime(9:10)// &
sTime(12:13)//sTime(15:16)// &
".nc"
! Create Filename with unique PID number to avoid simultaneously access to the same Forcing file
sFileNameData_Temp = trim(sPathData_Restart)//"hmc.state-grid."// &
sTime(1:4)//sTime(6:7)//sTime(9:10)// &
sTime(12:13)//sTime(15:16)//'_'//trim(sPID)// &
".nc"
! Info netCDF filename
call mprintf(.true., iINFO_Basic, ' Get filename (restart gridded): '//trim(sFileNameData_Restart)//' ... ' )
!------------------------------------------------------------------------------------------
!------------------------------------------------------------------------------------------
! Checking file input availability
sFileNameData_Restart_Zip = trim(sFileNameData_Restart)//'.gz'
inquire (file = trim(sFileNameData_Restart)//'.gz', exist = bFileExist)
if ( .not. bFileExist ) then
!------------------------------------------------------------------------------------------
! Warning message
call mprintf(.true., iWARN, ' No compressed restart netCDF data found: '//trim(sFileNameData_Restart_Zip) )
call mprintf(.true., iINFO_Verbose, &
' Get filename (restart gridded): '//trim(sFileNameData_Restart)//' ... FAILED' )
bCheckVar = .false.
!------------------------------------------------------------------------------------------
else
!------------------------------------------------------------------------------------------
! Unzip file
call HMC_Tools_Generic_UnzipFile(sCommandUnzipFile, &
sFileNameData_Restart_Zip, &
sFileNameData_Temp, .true.)
!------------------------------------------------------------------------------------------
!------------------------------------------------------------------------------------------
! Opening netCDF file
iErr = nf90_open(trim(sFileNameData_Temp), NF90_NOWRITE, iFileID)
if (iErr /= 0) then
!------------------------------------------------------------------------------------------
! Condition for no file restart found
call mprintf(.true., iWARN, ' Problem opening uncompressed netCDF file: '// &
trim(sFileNameData_Restart)//' --> Undefined restart data values' )
call mprintf(.true., iINFO_Verbose, &
' Get filename (restart gridded): '//trim(sFileNameData_Restart)//' ... FAILED' )
! Flag check restart
bCheckVar = .false.
!------------------------------------------------------------------------------------------
else
!------------------------------------------------------------------------------------------
! Attributes found for the restart conditions
iErr = nf90_inquire_attribute(iFileID, NF90_GLOBAL, "integration_step")
if (iErr /= 0) then
call mprintf(.true., iWARN, ' The attributes integration_step is not available in the restart gridded file' )
iDtIntegr = -9999
else
call check( nf90_get_att(iFileID, NF90_GLOBAL, "integration_step", iDtIntegr) )
endif
! Datasets found for the restart conditions
! VTot
sVarName = 'VTot';
call HMC_Tools_IO_Get2d_NC((sVarName), iFileID, a2dVar, sVarUnits, iCols, iRows, .true., iErr)
if(iErr /= 0) then
call mprintf(.true., iWARN, ' Get restart gridded data FAILED! Check restart data for '//sVarName//'!')
a2dVarVTot = -9999.0;
bCheckVar = bCheckVar .and. .false.
else
a2dVarVTot = transpose(a2dVar)
bCheckVar = bCheckVar .and. .true.
endif
! VRet
sVarName = 'VRet';
call HMC_Tools_IO_Get2d_NC((sVarName), iFileID, a2dVar, sVarUnits, iCols, iRows, .true., iErr)
if(iErr /= 0) then
call mprintf(.true., iWARN, ' Get restart gridded data FAILED! Check restart data for '//sVarName//'!')
a2dVarVRet = -9999.0;
bCheckVar = bCheckVar .and. .false.
else
a2dVarVRet = transpose(a2dVar)
bCheckVar = bCheckVar .and. .true.
endif
! Check channel type
if (iFlagCType.eq.2) then
! HydroLevel C
sVarName = 'HydroLevelC';
call HMC_Tools_IO_Get2d_NC((sVarName), iFileID, a2dVar, sVarUnits, iCols, iRows, .true., iErr)
if(iErr /= 0) then
call mprintf(.true., iWARN, ' Get restart gridded data FAILED! Check restart data for '//sVarName//'!')
a2dVarHydroC = -9999.0;
bCheckVar = bCheckVar .and. .false.
else
a2dVarHydroC = transpose(a2dVar)
bCheckVar = bCheckVar .and. .true.
endif
! HydroLevel H
sVarName = 'HydroLevelH';
call HMC_Tools_IO_Get2d_NC((sVarName), iFileID, a2dVar, sVarUnits, iCols, iRows, .true., iErr)
if(iErr /= 0) then
call mprintf(.true., iWARN, ' Get restart gridded data FAILED! Check restart data for '//sVarName//'!')
a2dVarHydroH = -9999.0;
bCheckVar = bCheckVar .and. .false.
else
a2dVarHydroH = transpose(a2dVar)
bCheckVar = bCheckVar .and. .true.
endif
! Q upstream
sVarName = 'Qup';
call HMC_Tools_IO_Get2d_NC((sVarName), iFileID, a2dVar, sVarUnits, iCols, iRows, .true., iErr)
if(iErr /= 0) then
call mprintf(.true., iWARN, ' Get restart gridded data FAILED! Check restart data for '//sVarName//'!')
a2dVarQup = -9999.0;
bCheckVar = bCheckVar .and. .false.
else
a2dVarQup = transpose(a2dVar)
bCheckVar = bCheckVar .and. .true.
endif
else
! HydroLevel
sVarName = 'HydroLevel';
call HMC_Tools_IO_Get2d_NC((sVarName), iFileID, a2dVar, sVarUnits, iCols, iRows, .true., iErr)
if(iErr /= 0) then
call mprintf(.true., iWARN, ' Get restart gridded data FAILED! Check restart data for '//sVarName//'!')
a2dVarHydro = -9999.0;
bCheckVar = bCheckVar .and. .false.
else
a2dVarHydro = transpose(a2dVar)
bCheckVar = bCheckVar .and. .true.
endif
endif
! Routing
sVarName = 'Routing';
call HMC_Tools_IO_Get2d_NC((sVarName), iFileID, a2dVar, sVarUnits, iCols, iRows, .true., iErr)
if(iErr /= 0) then
call mprintf(.true., iWARN, ' Get restart gridded data FAILED! Check restart data for '//sVarName//'!')
a2dVarRouting = -9999.0;
bCheckVar = bCheckVar .and. .false.
else
a2dVarRouting = transpose(a2dVar)
bCheckVar = bCheckVar .and. .true.
endif
! DFE
sVarName = 'DFE';
call HMC_Tools_IO_Get2d_NC((sVarName), iFileID, a2dVar, sVarUnits, iCols, iRows, .true., iErr)
if(iErr /= 0) then
call mprintf(.true., iWARN, ' Get restart gridded data FAILED! Check restart data for '//sVarName//'!')
a2dVarFlowDeep = -9999.0;
bCheckVar = bCheckVar .and. .false.
else
a2dVarFlowDeep = transpose(a2dVar)
bCheckVar = bCheckVar .and. .true.
endif
! WTLevel
sVarName = 'WTLevel';
call HMC_Tools_IO_Get2d_NC((sVarName), iFileID, a2dVar, sVarUnits, iCols, iRows, .true., iErr)
if(iErr /= 0) then
call mprintf(.true., iWARN, ' Get restart gridded data FAILED! Check restart data for '//sVarName//'!')
a2dVarWTable = -9999.0;
bCheckVar = bCheckVar .and. .false.
else
a2dVarWTable = transpose(a2dVar)
bCheckVar = bCheckVar .and. .true.
endif
! LST
sVarName = 'LST';
call HMC_Tools_IO_Get2d_NC((sVarName), iFileID, a2dVar, sVarUnits, iCols, iRows, .true., iErr)
if(iErr /= 0) then
call mprintf(.true., iWARN, ' Get restart gridded data FAILED! Check restart data for '//sVarName//'!')
a2dVarLST = -9999.0;
bCheckVar = bCheckVar .and. .false.
else
a2dVarLST = transpose(a2dVar)
bCheckVar = bCheckVar .and. .true.
endif
! Tmk
sVarName = 'Tmk';
call HMC_Tools_IO_Get3d_NC((sVarName), iFileID, a3dVar1, sVarUnits, dScaleFactor, &
iTMarkedSteps, iCols, iRows, .true., iErr)
! call HMC_Tools_IO_Get3d_NC((sVarName), iFileID, a3dVar1, sVarUnits, iTMarkedSteps, iCols, iRows, .true., iErr)
if(iErr /= 0) then
call mprintf(.true., iWARN, ' Get restart gridded data FAILED! Check restart data for '//sVarName//'!')
a3dVarTaKMarked = -9999.0;
bCheckVar = bCheckVar .and. .false.
else
a3dVarTaKMarked = transpose3Dvar(a3dVar1 * dScaleFactor)
bCheckVar = bCheckVar .and. .true.
endif
! T24
sVarName = 'T24';
call HMC_Tools_IO_Get3d_NC((sVarName), iFileID, a3dVar2, sVarUnits, dScaleFactor, &
iDaySteps, iCols, iRows, .true., iErr)
! call HMC_Tools_IO_Get3d_NC((sVarName), iFileID, a3dVar2, sVarUnits, iDaySteps, iCols, iRows, .true., iErr)
if(iErr /= 0) then
call mprintf(.true., iWARN, ' Get restart gridded data FAILED! Check restart data for '//sVarName//'!')
a3dVarTaK24 = -9999.0;
bCheckVar = bCheckVar .and. .false.
else
a3dVarTaK24 = transpose3Dvar(a3dVar2 * dScaleFactor)
bCheckVar = bCheckVar .and. .true.
endif
! WS
sVarName = 'WS';
call HMC_Tools_IO_Get2d_NC((sVarName), iFileID, a2dVar, sVarUnits, iCols, iRows, .false., iErr)
if(iErr /= 0) then
call mprintf(.true., iWARN, ' Get restart gridded data FAILED! '// &
'Not in mandatory restart variables! If needed check restart data for '//sVarName//'!')
a2dVarWSRunoff = 0.0
bCheckVar = bCheckVar .and. .true.
else
a2dVarWSRunoff = transpose(a2dVar)
bCheckVar = bCheckVar .and. .true.
endif
! Snow variable(s)
if (iFlagSnow.eq.1) then
! SWE
sVarName = 'SWE'
call HMC_Tools_IO_Get2d_NC((sVarName), iFileID, a2dVar, sVarUnits, iCols, iRows, .false., iErr)
if(iErr /= 0) then
call mprintf(.true., iWARN, ' Get restart gridded data FAILED! '// &
'Snow physics is activated! If needed check restart data for '//sVarName//'!')
a2dVarSWE = -9999.0;
bCheckVarS = bCheckVarS .and. .false.
else
a2dVarSWE = transpose(a2dVar)
bCheckVarS = bCheckVarS .and. .true.
endif
! Snow density
sVarName = 'RhoS';
call HMC_Tools_IO_Get2d_NC((sVarName), iFileID, a2dVar, sVarUnits, iCols, iRows, .false., iErr)
if(iErr /= 0) then
call mprintf(.true., iWARN, ' Get restart gridded data FAILED! '// &
'Snow physics is activated! If needed check restart data for '//sVarName//'!')
a2dVarRhoS = -9999.0;
bCheckVarS = bCheckVarS .and. .false.
else
a2dVarRhoS = transpose(a2dVar)
bCheckVarS = bCheckVarS .and. .true.
endif
! Snow albedo
sVarName = 'AlbedoS';
call HMC_Tools_IO_Get2d_NC((sVarName), iFileID, a2dVar, sVarUnits, iCols, iRows, .false., iErr)
if(iErr /= 0) then
call mprintf(.true., iWARN, ' Get restart gridded data FAILED! '// &
'Snow physics is activated! If needed check restart data for '//sVarName//'!')
a2dVarAlbedoS = -9999.0;
bCheckVarS = bCheckVarS .and. .false.
else
a2dVarAlbedoS = transpose(a2dVar)
bCheckVarS = bCheckVarS .and. .true.
endif
! Snow age
sVarName = 'AgeS';
call HMC_Tools_IO_Get2d_NC((sVarName), iFileID, a2dVar, sVarUnits, iCols, iRows, .false., iErr)
if(iErr /= 0) then
call mprintf(.true., iWARN, ' Get restart gridded data FAILED! '// &
'Snow physics is activated! If needed check restart data for '//sVarName//'!')
a2iVarAgeS = -9999;
bCheckVarS = bCheckVarS .and. .false.
else
a2iVarAgeS = int(transpose(a2dVar))
bCheckVarS = bCheckVarS .and. .true.
endif
! Air temperature last 1 day(s)
sVarName = 'T_1Days';
call HMC_Tools_IO_Get3d_NC((sVarName), iFileID, a3dVar3, sVarUnits, dScaleFactor, &
iDaySteps, iCols, iRows, .false., iErr)
! call HMC_Tools_IO_Get3d_NC((sVarName), iFileID, a3dVar3, sVarUnits, iDaySteps, iCols, iRows, .true., iErr)
if(iErr /= 0) then
call mprintf(.true., iWARN, ' Get restart gridded data FAILED! '// &
'Snow physics is activated! If needed check restart data for '//sVarName//'!')
a3dVarTaC_1Days = -9999.0;
bCheckVarS = bCheckVarS .and. .false.
else
a3dVarTaC_1Days = transpose3Dvar(a3dVar3 * dScaleFactor)
bCheckVarS = bCheckVarS .and. .true.
endif
! Air temperature last 5 day(s)
sVarName = 'T_5Days';
call HMC_Tools_IO_Get3d_NC((sVarName), iFileID, a3dVar4, sVarUnits, dScaleFactor, &
iDaySteps*5, iCols, iRows, .false., iErr)
! call HMC_Tools_IO_Get3d_NC((sVarName), iFileID, a3dVar4, sVarUnits, iDaySteps*5, iCols, iRows, .true., iErr)
if(iErr /= 0) then
call mprintf(.true., iWARN, ' Get restart gridded data FAILED! '// &
'Snow physics is activated! If needed check restart data for '//sVarName//'!')
a3dVarTaC_5Days = -9999.0;
bCheckVarS = bCheckVarS .and. .false.
else
a3dVarTaC_5Days = transpose3Dvar(a3dVar4 * dScaleFactor)
bCheckVarS = bCheckVarS .and. .true.
endif
else
! Condition snow not activated
a2dVarSWE = -9999.0;
a2dVarRhoS = -9999.0;
a2dVarAlbedoS = -9999.0;
a2iVarAgeS = -9999;
a3dVarTaC_1Days = -9999;
a3dVarTaC_5Days = -9999;
bCheckVarS = .true.
endif
! Closing netcdf file (drops db)
iErr = nf90_close(iFileID)
! Remove uncompressed file (to save space on disk)
call HMC_Tools_Generic_RemoveFile(oHMC_Namelist(iID)%sCommandRemoveFile, sFileNameData_Temp, .false.)
!------------------------------------------------------------------------------------------
!------------------------------------------------------------------------------------------
! Info filename
call mprintf(.true., iINFO_Basic, ' Get filename (restart gridded): '//trim(sFileNameData_Restart)//' ... OK' )
! Info end
call mprintf(.true., iINFO_Extra, ' Data :: Restart gridded :: NetCDF ... OK' )
!------------------------------------------------------------------------------------------
endif
!------------------------------------------------------------------------------------------
endif
!------------------------------------------------------------------------------------------
!------------------------------------------------------------------------------------------
! Check restart
if (bCheckVar .eqv. .true.) then
call mprintf(.true., iINFO_Basic, ' Data :: Restart gridded :: NetCDF :: All variable(s) are loaded! ' )
bCheckRestart = .true.
else
call mprintf(.true., iINFO_Basic, ' Data :: Restart gridded :: NetCDF :: Some/All variable(s) are N/A! ' )
call mprintf(.true., iWARN, ' Restart flag activated but some data restart are not available! ')
call mprintf(.true., iWARN, ' Restart gridded conditions are null! ')
bCheckRestart = .false.
endif
! Check restart snow
if (bCheckVarS .eqv. .true.) then
call mprintf(.true., iINFO_Verbose, ' Data :: Restart gridded :: NetCDF :: All snow variable(s) are loaded! ' )
bCheckRestartS = .true.
else
call mprintf(.true., iINFO_Verbose, ' Data :: Restart gridded :: NetCDF :: Some/All snow variable(s) are N/A! ' )
call mprintf(.true., iWARN, ' Restart flag activated but some data snow restart are not available! ')
call mprintf(.true., iWARN, ' Restart snow conditions are null! ')
bCheckRestartS = .false.
endif
!------------------------------------------------------------------------------------------
!------------------------------------------------------------------------------------------
! Debug
if (iDEBUG.gt.0) then
call mprintf(.true., iINFO_Extra, ' ========= CHECK RESTART GRIDDED NC =========== ')
call mprintf(.true., iINFO_Extra, checkvar(a2dVarVTot, int(oHMC_Vars(iID)%a2dDEM), 'VTOT NC') )
call mprintf(.true., iINFO_Extra, checkvar(a2dVarVRet, oHMC_Vars(iID)%a2iMask, 'VRET NC') )
call mprintf(.true., iINFO_Extra, checkvar(a2dVarHydro, oHMC_Vars(iID)%a2iMask, 'HYDRO NC') )
call mprintf(.true., iINFO_Extra, checkvar(a2dVarRouting, oHMC_Vars(iID)%a2iMask, 'ROUTING NC') )
call mprintf(.true., iINFO_Extra, checkvar(a2dVarWTable, oHMC_Vars(iID)%a2iMask, 'WTABLE NC') )
call mprintf(.true., iINFO_Extra, checkvar(a2dVarLST, oHMC_Vars(iID)%a2iMask, 'LST NC') )
call mprintf(.true., iINFO_Extra, checkvar(a2dVarFlowDeep, oHMC_Vars(iID)%a2iMask, 'FLOWDEEP NC') )
call mprintf(.true., iINFO_Extra, checkvar(real(a2iVarAgeS), oHMC_Vars(iID)%a2iMask, 'AGES NC') )
call mprintf(.true., iINFO_Extra, checkvar(a2dVarSWE, oHMC_Vars(iID)%a2iMask, 'SWE NC') )
call mprintf(.true., iINFO_Extra, checkvar(a2dVarRhoS, oHMC_Vars(iID)%a2iMask, 'RHOS NC') )
call mprintf(.true., iINFO_Extra, checkvar(a2dVarAlbedoS, oHMC_Vars(iID)%a2iMask, 'ALBEDOS NC') )
call mprintf(.true., iINFO_Extra, ' ========= CHECK RESTART GRIDDED NC =========== ')
endif
!------------------------------------------------------------------------------------------
end subroutine HMC_Data_Restart_Gridded_NC
#endif
!------------------------------------------------------------------------------------------
!------------------------------------------------------------------------------------------
! Subroutine to read binary data restart
subroutine HMC_Data_Restart_Gridded_Binary(iID, &
sPathData_Restart, &
iRows, iCols, iDtIntegr, &
iDaySteps, iTMarkedSteps, &
sTime, iFlagSnow, iFlagCType, &
a2dVarVTot, a2dVarVRet, &
a2dVarHydro, a2dVarRouting, &
a2dVarHydroC, a2dVarHydroH, a2dVarQup, &
a2dVarFlowDeep, &
a2dVarWTable, &
a2dVarLST, a3dVarTaKMarked, a3dVarTaK24, &
a2iVarAgeS, a2dVarSWE, a2dVarAlbedoS, a2dVarRhoS, &
a3dVarTaC_1Days, a3dVarTaC_5Days, &
a2dVarWSRunoff, &
bCheckRestart, bCheckRestartS)
!------------------------------------------------------------------------------------------
! Variable(s)
integer(kind = 4) :: iID
character(len = 700), intent(in) :: sPathData_Restart
character(len = 700) :: sFileNameData_Restart, sFileNameData_Restart_Zip, sFileNameData_Temp
character(len = 700) :: sCommandUnzipFile
character(len = 256) :: sVarName
integer(kind = 4), intent(in) :: iRows, iCols
integer(kind = 4), intent(in) :: iDaySteps, iTMarkedSteps
integer(kind = 4), intent(in) :: iFlagSnow, iFlagCType
integer(kind = 4) :: iDtIntegr
integer(kind = 4) :: iScaleFactor
character(len = 19), intent(in) :: sTime
real(kind = 4), dimension(iRows, iCols) :: a2dVar
real(kind = 4), dimension(iRows, iCols, iTMarkedSteps) :: a3dVar1
real(kind = 4), dimension(iRows, iCols, iDaySteps) :: a3dVar2
real(kind = 4), dimension(iRows, iCols, iDaySteps) :: a3dVar3
real(kind = 4), dimension(iRows, iCols, iDaySteps*5) :: a3dVar4
real(kind = 4), dimension(iRows, iCols), intent(out) :: a2dVarVTot
real(kind = 4), dimension(iRows, iCols), intent(out) :: a2dVarVRet
real(kind = 4), dimension(iRows, iCols), intent(out) :: a2dVarHydro
real(kind = 4), dimension(iRows, iCols), intent(out) :: a2dVarRouting
real(kind = 4), dimension(iRows, iCols), intent(out) :: a2dVarHydroC
real(kind = 4), dimension(iRows, iCols), intent(out) :: a2dVarHydroH
real(kind = 4), dimension(iRows, iCols), intent(out) :: a2dVarQup
real(kind = 4), dimension(iRows, iCols), intent(out) :: a2dVarFlowDeep
real(kind = 4), dimension(iRows, iCols), intent(out) :: a2dVarWTable
real(kind = 4), dimension(iRows, iCols), intent(out) :: a2dVarLST
real(kind = 4), dimension(iRows, iCols, iTMarkedSteps), intent(out) :: a3dVarTaKMarked
real(kind = 4), dimension(iRows, iCols, iDaySteps), intent(out) :: a3dVarTaK24
integer(kind = 4), dimension(iRows, iCols), intent(out) :: a2iVarAgeS
real(kind = 4), dimension(iRows, iCols), intent(out) :: a2dVarSWE
real(kind = 4), dimension(iRows, iCols), intent(out) :: a2dVarAlbedoS
real(kind = 4), dimension(iRows, iCols), intent(out) :: a2dVarRhoS
real(kind = 4), dimension(iRows, iCols, iDaySteps), intent(out) :: a3dVarTaC_1Days
real(kind = 4), dimension(iRows, iCols, iDaySteps*5), intent(out) :: a3dVarTaC_5Days
real(kind = 4), dimension(iRows, iCols), intent(out) :: a2dVarWSRunoff
character(len = 256) :: sVarUnits, sPID
integer(kind = 4) :: iErr
integer(kind = 4) :: iFileID