-
Notifications
You must be signed in to change notification settings - Fork 2
/
ssib3.f
6002 lines (5609 loc) · 285 KB
/
ssib3.f
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
C=======================================================================
C THIS IS A SIMPLIFIED SIB MODEL
C=======================================================================
CM THIS CODE OF YONGKANG XUES HAS BEEN MODIFIED TO RUN AS A SUBROUTINE
CM INSIDE AN ENKF RADIOMETRIC DATA ASSIMILATION FOR ESTIMATION OF SWE.
CM THE VEGIN1, VEGIN2 AND CNTROLS SUBROUTINES NO LONGER READ DATA FROM
CM FILES, BUT EXTRACT IT FROM THESE ARRAYS; SOME VALUES THAT ARE
CM STATIC HAVE BEEN HARDCODED INTO THESE SUBROUTINES. THEREFORE, THE
CM run.ctl FILE WHICH USED TO CONTAIN THE NAMES OF ALL OF THESE FILES
CM IS NOW OBSELETE. FURTHERMORE, THE ALBEDO ADJUSTMENT BASED ON THE
CM xadj VARIABLE IS ALSO OBSELETE AND NOT IMPLEMENTED HERE. THE CODE
CM TO COMPUTE rnoffs AND rnoffb WAS ALSO REMOVED, AS IT WAS NOT BEING
CM USED IN THE PRESENT APPLICATION.
CM CONSTANT VEGETATION DATA IS CONTAINED IN THE VEGIN1ARG VARIABLE,
CM VEGETATION DATA WHICH CHANGES EACH MONTH IN THE VEGIN2ARG VARIABLE.
CM N_U - NUMBER OF FORCING DATA AT EACH TIMESTEP
CM N_STEPS - NUMBER OF STEPS AT WHICH TO RUN THE MODEL
CM UARG - FORCING DATA
CM ALPHA - PARAMETERS DICTATING THE GROWTH OF THE SNOW GRAINS
CM T0 - INITIAL TIME DATA
CM X0 - INITIAL AUXILIARY DATA NEEDED TO INITIALIZE THE MODEL
CM Y0 - INITIAL SNOW STATE VARIABLES
CM Z - THE LATITUDE AND LONGITUDE OF THIS RUN
CM YOUT - THE OUTPUT ARRAY CONTAINING THE SNOW DATA
subroutine ssib3(IVEG_TYPE,n_u,n_steps,uarg,alpha,t0,
& x0,y0,z_in,yout,PIXEL,n_y,n_x,xout,zout,tend,replicate,rank,
& meas,n_a,f_veg,vcov_dat) ! ZenithAngle,Energy_out,Effective_PPT)
COMMON /XRIB/RIB,temprib
character*7 run
INCLUDE 'comsib.in'
include 'snow4.in'
cm these lines to define sizes for arrays now used to initialize
cm ssib and call it as a subroutine
integer n_u,n_steps,PIXEL,n_y,n_x,replicate,rank,meas,counter
real uarg(n_u,n_steps)
real alpha(n_a),t0(5),x0(12),y0(n_y),z_in(2),tend(5)
real vcov_dat
cm the dimension of f_veg is consistent with mvnrnd
real yout(n_y,n_steps),xout(n_x,n_steps),zout(n_steps)
real sweold,swenew,sag1,sag2
real ALBEDOOUT(n_steps,2,2)
real ZenithAngle(n_steps)
real Energy_out(8,n_steps)
real Effective_PPT(1,n_steps)
real f_veg(1,1)
c real swenew_Vec(n_steps)
c real sweold_Vec(n_steps)
c real sag1_Vec(n_steps)
c real sag2_Vec(n_steps)
cl ================ declaration of MEMLS parameters ====================
cl declaration for parameters in MEMLS3 and MEMLS4, NOV 16 2012
cl 4-layer memls parameters
integer :: n_rlz4,n_rz4,n_yz4,n_ypz4,n_yrz4,n_zz4,n_zpz4,
& n_zrz4,n_cz4,n_xz4,n_az4,n_uz4,meas_switch4,n_bdrf4
integer :: ierr4
integer, dimension(1) :: iveg_type4
integer, dimension(:), allocatable :: ctrl4
real, dimension(1) :: tbs,tbs4
real, dimension(:),allocatable :: freq4,theta_m4
real, dimension(:,:),allocatable :: y4memls,xz4
real, dimension(:,:,:),allocatable :: uz4
real, dimension(1,1) :: f_veg_m4,albedo_m4
real, dimension(1,2) :: bdrf4
real, dimension(2,1) :: zz4,tbraw,tbraw4
integer :: month_m4
cl 3-layer memls parameters
integer :: n_rlz3,n_rz3,n_yz3,n_ypz3,n_yrz3,n_zz3,n_zpz3,
& n_zrz3,n_cz3,n_xz3,n_az3,n_uz3,meas_switch3,n_bdrf3
integer :: ierr3
integer, dimension(1) :: iveg_type3
integer, dimension(:), allocatable :: ctrl3
real, dimension(1) :: tbs3,CPEX
real, dimension(:),allocatable :: freq3,theta_m3
real, dimension(:,:),allocatable :: y3memls,xz3
real, dimension(:,:,:),allocatable :: uz3
real, dimension(1,1) :: f_veg_m3,albedo_m3
real, dimension(1,2) :: bdrf3
real, dimension(2,1) :: zz3,tbraw3
integer :: month_m3
cl ================ MEMLS declaration done ====================
CM THE ctlpa AND nroot VARIABLE WILL BE HARDCODED IN (read from file before)
c control stomatal resistance;
c final stomatal resistance=ctlpa * stomatal resistance
ctlpa=1.0
c control root depth, nroot=1: root depth has no control: nroot not
c =1: root depth is controled by rootp, which are read in vegin2.
nroot=1
f_veg(1,1)=0.0
cm print out all inputs...
c print *, iveg_type,n_u,n_steps,alpha,t0,x0,y0,z_in,PIXEL,
c & n_y,n_x,tend,replicate,rank,meas,n_a,f_veg,vcov_dat
CM SOME OF THESE FORMAT STATEMENTS WERE OBSELTE AND SO DELETED
2 format(a12)
3 format(a40)
CM INITIALIZE SOME VARIABLES
cm put in a check that n_x is 13, not 12, since i used 12 for so long...
if(n_x.ne.13)then
print *, 'error! n_x=',n_x,'; n_x should be 13...'
end if
CALL CNTROLS(MDAY,alpha,t0,x0,y0,z_in,pixel,n_a)
CALL CONSTS
CUMERROR = 0
ERRORCUM = 0
xqlast1 = 0.
xqlast2 = 0.
xqlast3 = 0.
xlastwet =0.
xlastswe = 0.
xlastcap1 = 0.
sweold = 0.0
swenew = 0.0
c four lines changed by mike to allow time to be read in and used
c iyr=1979
iyr=YEAR
mthst = MONTH
ndyst = MDAY
nhrst = TIME
mthend = 240
ndyend = 31
nhrend = 24
nobs = 0
XPG1 = 0.
XPG2 = 0.
c these are for my own time keeping which replaces time in forcing file
nyy=iyr
nmm=mthst
ndd=ndyst
nhh=nhrst
c
C ** ASSIGN VEGETATION PARAMETERS FROM INPUT ARRAYS
call vegin
CALL VEGIN1(IVEG_TYPE)
CALL VEGIN2(IVEG_TYPE,nmm,f_veg,vcov_dat)
c
cjyj--control parameter of snow model
MDLSNO=0
SD_CR=0.05
cm this part is changed by mike to allow snow density to be read in
cm snden=3.75
isnow=1
cm this park changed by mike
SDEP=CAPAC(2)*snden
call getinput
swe=CAPAC(2)
cm this part is changed by mike, to allow dz(nd) to be read in
snowdepth=dz(1)+dz(2)+dz(3)
if(mdlsno.eq.0.and.snowdepth.gt.sd_cr) then
isnow=0
call layern(tgs,0,nmm,ndd,nhh)
endif
CS 10/13/98
C ** CREATE THE COEFFICIENTS FOR SURFACE ALBEDO
XHC = 0.
XHG = 0.
XCI = 0.
XCT = 0.
XGI = 0.
XGT = 0.
XGS = 0.
NNX = 0
isnowhr=0
iday=0
cm ********************************************
cm START OF TIME LOOP
cm ********************************************
DO ICTRL=1,N_STEPS
cm extract forcing data from uarg array
! print *, ictrl
icrash=1
swdown=uarg(1,ICTRL)
rainf=uarg(2,ICTRL)
obsnow=uarg(3,ICTRL)
dirdown=uarg(4,ICTRL)
psur=uarg(5,ICTRL)
tm=uarg(6,ICTRL)
qair=uarg(7,ICTRL)
windn=uarg(8,ICTRL)
winde=uarg(9,ICTRL)
afac=1.0
cl dongyue constrain the soil tempc
if(tgs.lt.273.16)then
tgs=273.16
end if
c if(ictrl.eq.icrash) print *, 'U=',uarg(1:9,ictrl)
cm check on whether it should be rain or snow...
if(tm.gt.273.16.and.obsnow.gt.0.0)then
rainf=obsnow
obsnow=0.0
end if
if(tm.le.273.16.and.rainf.gt.0.0)then
obsnow=rainf
rainf=0.0
end if
if(obsnow.gt.0.0)then
isnowhr=isnowhr+1
end if
cm conversions of forcing data
UM=(windn**2+winde**2)**0.5
TPREC=(rainf+obsnow)*3600
cm here surface pressure is converted from Pa to mbar
psur = psur / 100.0
EM = (psur*qair)/0.6220
cm update of time variables
idkmax = 31
lstmth = nmm
do 3456, ikahan=0,19
if ((nmm.eq.(4+12*ikahan)).or.
& (nmm.eq.(9+12*ikahan)).or.
& (nmm.eq.(11+12*ikahan)).or.
& (nmm.eq.(6+12*ikahan))) then
idkmax = 30
endif
3456 continue
do 3457, ikahan=0,19
if (nmm.eq.(2+12*ikahan)) then
idkmax=28
if ((nyy.eq.1980).or.(nyy.eq.1984).or.(nyy.eq.1988).
& or.(nyy.eq.1992).or.(nyy.eq.1996).or.
& (nyy.eq.2000).or.(nyy.eq.2004)) then
idkmax = 29
endif
endif
3457 continue
if (nhh.eq.24) then
nhh = 0
ndd = ndd + 1
if (ndd.eq.(idkmax+1)) then
ndd = 1
nmm = nmm + 1
do 3458, ikahan=1,20
if (nmm.eq.(1+12*ikahan)) then
nmm = 1
nyy = nyy + 1
endif
3458 continue
endif
endif
nhh=nhh+1
qsoil=0.
wfsoil=0.
solsoil=0.
snroff=0.
if (swdown.lt.0) swdown = 0.0
if (tprec.le.0.) tprec = 0.0
ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
if (lstmth.ne.nmm) then
if ((nmm.eq.13).or.(nmm.eq.25).or.(nmm.eq.37).or.
& (nmm.eq.49).or.(nmm.eq.61).or.(nmm.eq.73).or.
& (nmm.eq.85).or.(nmm.eq.97).or.(nmm.eq.109).or.
& (nmm.eq.121).or.(nmm.eq.133).or.(nmm.eq.145).or.
& (nmm.eq.157).or.(nmm.eq.169).or.(nmm.eq.181).or.
& (nmm.eq.193).or.(nmm.eq.205).or.(nmm.eq.217).or.
& (nmm.eq.229)) rewind(2)
CALL VEGIN2(IVEG_TYPE,nmm,f_veg,vcov_dat)
endif
c if (ictrl.eq.icrash) print *, 'ictrl=',ictrl,'after timekeeping'
cm observation counter updated
nobs = nobs + 1
IF (MDLSNO.eq.0) THEN
iptype=2
cm Mike is changing this to the SNTHERM cutoff temperature for snow
If (TM.ge.273.16) iptype=1
If (TPREC.le.0.) iptype=0
END IF
c
C ** START THE MAIN PROGRAM
c
c if (ictrl.eq.icrash) print *, 'ictrl=',ictrl,'before main prog.'
RADN(3,2) = dirdown
UM = AMAX1(UM,0.25)
SWDOWN = AMAX1(SWDOWN,0.1)
IHOUR = NHH
c ** calculate solar zenith angle
CALL RADC2(SUNANG)
! Manu - is changing this so that the Zentih Angle is the same computed
! as a fucntion of slope and aspect from the disaggregation file
SUNANG = ZenithAngle(ICTRL)
SUNANG = AMAX1(0.01,SUNANG)
c
C ** CALCULATE THE CLOUD COVER USING AN EMPIRICAL EQUATION
CLOUD = (1160.*SUNANG - SWDOWN) / (963. * SUNANG)
CLOUD = AMAX1(CLOUD,0.)
CLOUD = AMIN1(CLOUD,1.)
CLOUD = AMAX1(0.58,CLOUD)
C ** SEPERATE THE SHORT WAVE RADIATION INTO DIFFERENT SPECTRUM
DIFRAT = 0.0604 / ( SUNANG-0.0223 ) + 0.0683
IF ( DIFRAT .LT. 0. ) DIFRAT = 0.
IF ( DIFRAT .GT. 1. ) DIFRAT = 1.
DIFRAT = DIFRAT + ( 1. - DIFRAT ) * CLOUD
VNRAT = ( 580. - CLOUD*464. ) / ( ( 580. - CLOUD*499. )
& + ( 580. - CLOUD*464. ) )
C
FRAC(1,1) = (1.-DIFRAT)*VNRAT
FRAC(1,2) = DIFRAT*VNRAT
FRAC(2,1) = (1.-DIFRAT)*(1.-VNRAT)
FRAC(2,2) = DIFRAT*(1.-VNRAT)
RADN(1,1) = FRAC(1,1)*SWDOWN
RADN(1,2) = FRAC(1,2)*SWDOWN
RADN(2,1) = FRAC(2,1)*SWDOWN
RADN(2,2) = FRAC(2,2)*SWDOWN
Cm initialize snow vars -mike
IF (MDLSNO.eq.0.and.ISNOW.EQ.0) THEN
tsoil=TGS
TGS=tssno(n)
CAPAC(2)=swe
SDEP=snowdepth
ssss=sdep
else
ssss=capac(2)*snden
END IF
c if (ictrl.eq.icrash) print *, 'before radab call'
cm MAIN RADIATION CALLS
CALL RADAB (ISNOW,MDLSNO,afac,ictrl,PIXEL,swenew,sweold,
& sag1,sag2)
c Manu set sweold = swe, this is needed in CLM albedo model
sweold = swe
c if (ictrl.eq.icrash) print *, 'after radab call'
CALL ROOT1
CALL STOMA1
RSTUN = RST(1)
C
c PPC = TPREC
c PPL = TPREC-PPC
PPL = TPREC
PPC = TPREC-PPL
C
C ** WATER BALANCE CHES.
c
TOTWB = WWW(1) * POROS * ZDEPTH(1)
& + WWW(2) * POROS * ZDEPTH(2)
& + WWW(3) * POROS * ZDEPTH(3)
& + CAPAC(1) + CAPAC(2)
thelastmoist = www(1)*poros*zdepth(1) + www(2)*poros*zdepth(2)
& + www(3)*poros*zdepth(3)
thelastcapac1 = CAPAC(1)
thelastcapac2 = CAPAC(2)
cm if(meas.eq.2) then
cm print *, 'www=',www,'capac=',capac,'totwb=',totwb
cm end if
C
c ** interception and runoff calculations
CS Chanfe INTERC to INTERCS (****,***) ON 10/13/98
c if (ictrl.eq.icrash) print *, 'before intercs calls'
CALL INTERCS (ISNOW,p0,CSOIL,dzsoil,CHISL)
c if (ictrl.eq.icrash) print *, 'after intercs calls; ',
c & 'isnow=',isnow
IF (MDLSNO.eq.0.and.ISNOW.EQ.0) THEN
prcp=p0
tkair=TM
c if (ictrl.eq.icrash) print *, 'before getmet calls'
CALL getmet (iptype,UM,nmm,nhh,ndd,ictrl,pixel)
c ** aerodynamic resistance and flux calculations
solar=0.
DO 1100 IVEG = 2, 2
DO 1100 IWAVE = 1, 2
DO 1100 IRAD = 1, 2
solar=solar+RADFAC(IVEG,IWAVE,IRAD)*RADN(IWAVE,IRAD)
1100 CONTINUE
CALL snow1st (dtt,TM,solsoil,ISNOW,nmm,ndd,nhh,ictrl,pixel,imike)
c if (ictrl.eq.icrash) print *, 'before temrs2 calls'
c if ( (ictrl.ge.5500).and.(ictrl.lt.5502) ) then
c if (ictrl.eq.5500) then
c print*,ictrl,'SW1=',swe,'c(2)',capac(2),'SD',snowdepth,'DENS',snden
c endif
CALL TEMRS2 (MDLSNO,ISNOW,CHISL,tsoil,solsoil,meas,
& CSOIL,dzsoil,wfsoil,ictrl,pixel,y0,n_y,replicate,rank)
call old
c if ( (ictrl.ge.5500).and.(ictrl.lt.5502) ) then
c if (ictrl.eq.5500) then
c print*,ictrl,'SW2=',swe,'c(2)',capac(2),'SD',snowdepth,'DENS',snden
c endif
ELSE
cm if there is snowfall, find snowfall density (get_met)and
cm incorporate snowfall in the rest of the snowpack (newsnow)
c if (ictrl.eq.icrash) print *, 'top of if-structure, isnow=1',
c & 'tprec=',tprec,'iptype=',iptype,'gsize=',gsize
if(TPREC.gt.0.and.iptype.ne.1)then
prcp=TPREC/1000.
tkair=TM
c if (ictrl.eq.icrash) print *, 'before getmet'
call getmet(iptype,UM,nmm,ndd,nhh,ictrl,pixel)
c if (ictrl.eq.icrash) print *, 'before newsnow'
cm The 'getmet' subroutine sets 'iptype' to 0 if the depth of
cm newsnowfall is less than some critical value.
if(iptype.ne.0) call newsnow(ISNOW,nmm,ndd,nhh,ictrl,pixel)
c if (ictrl.eq.icrash) print *, 'after getmet, newsnow calls'
endif
if(gsize>0.) call graingrowth(ISNOW)
c if (ictrl.eq.icrash) print *, 'before temrs1 calls'
CALL TEMRS1 (MDLSNO,ISNOW,rank,replicate,pixel,ictrl,icrash)
c if (ictrl.eq.icrash) print *, 'after temrs1 calls'
END IF
cm UPDATE STATE VARIABLES AFTER N-R TEMPERATURE SOLUTION
CALL UPDAT1 (MDLSNO,ISNOW,wfsoil,swe,snroff)
c if (ictrl.eq.icrash) print *, 'after updat1 calls'
cm RELAYER SNOWPACK DEPENDING ON CHANGE IN DEPTH
IF (MDLSNO.eq.0.and.ISNOW.EQ.0) THEN
CAPAC(2)=swe
swenew = swe
cm mike is adding this on jan 31 05 to solve an issue
cm that comes up when the snow melts completely away from a
cm pack with snowdepth > 0.05 m
snowdepth=dzo(1)+dzo(2)+dzo(3)
If (snowdepth.lt.SD_CR) Then
ISNOW=1
call LAYER1 (CSOIL,TGS,dzsoil,h,w,snowdepth,
& swe,stemp,nd,gsize,gdia)
Else
c if (ictrl.le.5469) then
ISNOW=0
call modnodenew
c if (ictrl.eq.5500) print*,'1.MODcalled'
c endif
End if
ELSE IF(MDLSNO.eq.0.and.ISNOW.GT.0) THEN
If (capac(2)*snden.gt.SD_CR) Then
swe=CAPAC(2)
snowdepth=capac(2)*snden
ISNOW=0
CALL LAYERN (TGS,1,nmm,nhh,ndd)
Else
ISNOW=1
cm in order to output the snow, update snowdepth variable
snowdepth = capac(2)*snden
swe = capac(2)
cm end of mikes changes
End if
END IF
c if (ictrl.eq.icrash) print *, 'after layer calls'
call set0
c if (ictrl.eq.icrash) print *, 'before water balance checks'
ROFF=ROFF+snroff
c this next line was added by dr xue
c rnoffs(nobs) = rnoffs(nobs) + snroff
C
cm WATER AND ENERGY BALANCE CHECKS
ENDWB = WWW(1) * POROS * ZDEPTH(1)
& + WWW(2) * POROS * ZDEPTH(2)
& + WWW(3) * POROS * ZDEPTH(3)
& + CAPAC(1) + CAPAC(2) - PPL/1000. + ETMASS/1000. + ROFF
ERROR = TOTWB - ENDWB
cm if(meas.eq.2) then
cm print *, 'www=',www,'capac=',capac,'ppl=',ppl,'etmass=',etmass,
cm & 'roff=',roff,'endwb=',endwb,'poros=',poros,'zdepth=',zdepth
cm end if
CUMERROR = CUMERROR + ERROR
if ((nmm.eq.240).and.(ndd.eq.31).and.(nhh.eq.24))
& write(6,*) 'CUMULATIVE ERROR = ',CUMERROR
c if (ictrl.eq.49) print *, 'before energy balance checks, dtt=',
c & dtt
CBAL = RADT(1) - CHF - (ECT+HC+ECI)/DTT
GBAL = RADT(2) - SHF - (EGT+EGI+HG+EGS)/DTT
ZLHS = RADT(1) + RADT(2) - CHF - SHF
ZRHS = HFLUX + (ECT + ECI + EGT + EGI + EGS)/DTT
RORRE = ZLHS-ZRHS
ERRORCUM = ERRORCUM + RORRE
c Manu Extract the energy balance at the ground [snow level]
Energy_out(1,ictrl)=GBAL
Energy_out(2,ictrl)=RADT(2)
Energy_out(3,ictrl)=SHF
Energy_out(4,ictrl)=EGT
Energy_out(5,ictrl)=EGI
Energy_out(6,ictrl)=HG
Energy_out(7,ictrl)=EGS
Energy_out(8,ictrl)=ZLWU
c Extract the throughfall precipitation [with units = meters/hr]
Effective_PPT(1,ictrl)=p0
c if (ictrl.eq.49) print *, 'after energy balance calcs'
IF(ABS (ZLHS - ZRHS) .GT. 0.010) THEN
print *, 'warning: energy balance error greater than 0.01'
IF(ABS (ZLHS - ZRHS) .GT. 4.000) THEN
XPG1 = XPG1 + ZLHS
XPG2 = XPG2 + ZRHS
ectw=ect/dtt
eciw=eci/dtt
egtw=egt/dtt
egiw=egi/dtt
egsw=egs/dtt
print *, ictrl,nmm,ndd,nhh,swdown,radn(3,2),zlwup,
+ HFLUX,CHF,SHF,ectw,eciw,egtw,egiw,egsw,temprib,
+ zlhs,zrhs
print *, 'ssib3: energy balance error. snowdepth=',snowdepth,
& 'bwo=',bwo,'tssno=',tssno,'tgs=',tgs,'gdia=',gdia,'capac(2)=',
& capac(2),'flo=',flo,'pixel=',pixel,'replicate=',replicate,
& 'rank=',rank,'y0=',y0,'obsnow=',obsnow,'egi_old=',x0(9),
& 'Tair=',uarg(6,ictrl),'ictrl=',ictrl,'Tair(i-1)=',
& uarg(6,ictrl-1),'x0=',x0,'zlat=',zlat,'zlong=',zlong,
& 'LWDOWN=',uarg(4,ictrl),'radt(1)=',radt(1),'radt(2)=',radt(2)
STOP
END IF
END IF
c if (ictrl.eq.49) print *, 'after balance checks'
c ** prepare for post-processing
c
c
wav = sqrt(www(1)*www(2))
tenest = phsat * wav ** ( - bee)
tenes1 = phsat * (www(1) ** ( - bee) )
tenes2 = phsat * (www(2) ** ( - bee) )
c
c ** store the output data for post-processing
c
c if (ictrl.eq.49) print *, 'before x* calcs, hlat=',
c & hlat
xhc = hc / dtt + xhc
xhg = hg / dtt + xhg
xci = eci /hlat + xci
xct = ect /hlat + xct
xgi = egi /hlat + xgi
xgt = egt /hlat + xgt
xgs = egs /hlat + xgs
cm CALCULATE OVERALL LATENT HEAT
siblh = (((ECT + ECI + EGT + EGI + EGS)/HLAT
& *(3150.19 - 2.378 * tm)) /3.6)
cs for france data albm=0.7, so Sun add folowing statement albm=0.4
cs on 03/29/99
c albm=0.7
cs sun add above statement on 03/29/99
xmustar=0.7
qmsensh=0.7
albm=0.7
cs sun add above statement on 03/29/99
c if (ictrl.eq.49) print *, 'before output1 call...'
!cl ======================= DONGYUE ADD ITERATION ======================
!
!cl ------------ initialization -----------------
!! for 4 layer memls
! n_rlz4=1
! n_rz4=1
! n_yz4=n_y_ssib !should be 14...
! n_ypz4=1
! n_yrz4=14
! n_zz4=2 !number of observations
! n_zpz4=2
! n_zrz4=1
! n_cz4=9
! n_az4=8 !unused, actually...
! n_xz4=13
! n_uz4=9
! !allocate & define ctrl
! allocate(ctrl4(n_cz4))
! ctrl4=0
! ctrl4(1)=0 !number of calculations to do, set in interfacez
! ctrl4(2)=0 !number of snow layers, set in interfacez
! ctrl4(3)=1 !atm_switch
! ctrl4(4)=0 !veg_switch, set in interfacez
! !these next numbers all pulled from old sizes.in file... careful!
! ctrl4(5)=5 !number of auxiliary inputs for snow rtm... need to check!
! ctrl4(6)=5 !number of snow inputs for snow rtm
! ctrl4(7)=5 !number of inputs for canopy rtm
! ctrl4(8)=4 !number inputs for atmospheric rtm
! ctrl4(9)=1 !number of passive microwave channels
! !allocate & set frequency and angle arrays
! !allocate(freq(ctrl(9)),theta(ctrl(9)))
! allocate(freq4(1),theta_m4(1))
! freq4(1)=37.
! theta_m4(1)=55.
! month_m4=12 !hard-code to december
! !note: just use local meas,rank as input to interfacez for debugging
! ierr4=0 !dummy
! meas_switch4=1 !determines which measurements are used
! iveg_type4(1)=veg_map
! f_veg_m4(1,1)=0.
! albedo_m4(1,1)=0. !dummy variable; not used in interfacez
! n_bdrf4=1 !dummy variable to size bdrf dummy variable in interfacez
! bdrf4=0. !dummy variable; not used in interfacez
!
!
!! for 3 layer memls
! n_rlz3=1
! n_rz3=1
! n_yz3=n_y_ssib !should be 14...
! n_ypz3=1
! n_yrz3=14
! n_zz3=2 !number of observations
! n_zpz3=2
! n_zrz3=1
! n_cz3=9
! n_az3=8 !unused, actually...
! n_xz3=13
! n_uz3=9
! !allocate & define ctrl
! allocate(ctrl3(n_cz3))
! ctrl3=0
! ctrl3(1)=0 !number of calculations to do, set in interfacez
! ctrl3(2)=0 !number of snow layers, set in interfacez
! ctrl3(3)=1 !atm_switch
! ctrl3(4)=0 !veg_switch, set in interfacez
! !these next numbers all pulled from old sizes.in file... careful!
! ctrl3(5)=5 !number of auxiliary inputs for snow rtm... need to check!
! ctrl3(6)=5 !number of snow inputs for snow rtm
! ctrl3(7)=5 !number of inputs for canopy rtm
! ctrl3(8)=4 !number inputs for atmospheric rtm
! ctrl3(9)=1 !number of passive microwave channels
! !allocate & set frequency and angle arrays
! !allocate(freq(ctrl(9)),theta(ctrl(9)))
! allocate(freq3(1),theta_m3(1))
! freq3(1)=37.
! theta_m3(1)=55.
! month_m3=12 !hard-code to december
! !note: just use local meas,rank as input to interfacez for debugging
! ierr3=0 !dummy
! meas_switch3=1 !determines which measurements are used
! iveg_type3(1)=veg_map
! f_veg_m3(1,1)=0.
! albedo_m3(1,1)=0. !dummy variable; not used in interfacez
! n_bdrf3=1 !dummy variable to size bdrf dummy variable in interfacez
! bdrf3=0. !dummy variable; not used in interfacez
!cl ---------------- initialization done --------------------
!! determine whether go into the iteration
! call ssib_layer(yout(1,ictrl-1),dz)
! IF((ictrl.ne.1).and.((3600*obsnow).gt.2).and.
! & ((yout(1,ictrl-1).ne.0.)))then
!
!! 4 layer memls
! allocate(y4memls(21,1),xz4(13,1),uz4(9,1,1))
! y4memls=0.0
! tbs4=0.0
! xz4=0.0
! uz4=0.0
!
! y4memls(1:3,1)=dz(1:3)
! y4memls(4,1)=3.6*obsnow
! y4memls(5:7,1)=yout(2:4,ictrl-1)
! y4memls(8,1)=yout(4,ictrl-1)
! y4memls(9:11,1)=yout(5:7,ictrl-1)
! y4memls(12,1)=yout(7,ictrl-1)
! y4memls(13:15,1)=yout(8:10,ictrl-1)
! y4memls(16,1)=yout(10,ictrl-1)
! y4memls(17:19,1)=yout(11:13,ictrl-1)
! y4memls(20,1)=yout(13,ictrl-1)
! y4memls(21,1)=yout(14,ictrl-1)
!
! xz4(:,1)=xout(:,ictrl-1)
! uz4(:,1,1)=uarg(:,ictrl-1)
!
!! set water content to be 0
! y4memls(13:16,1)=0.0
!
!
!! call interfacez4
! call interfacez4(y4memls,zz4,n_rlz4,n_rz4,n_yz4,n_ypz4,n_yrz4,
! & n_zz4,n_zpz4,n_zrz4,n_cz4,n_xz4,ctrl4,freq4,theta_m4,xz4,n_az4,
! & n_u,uz4,month_m4,tbraw4,albedo_m4,ictrl,rank,iveg_type4,ierr4,
! & f_veg_m4,bdrf4,n_bdrf4,meas_switch4,vcov_dat)
!
! tbs4=tbs4+tbraw4(2,1)
!
! !print*,'4 LAYER TB IS=====', TBS4
! deallocate(y4memls,xz4,uz4)
!
!! 4 layer memls done
!
!! =========== begin run 3 layer memls ============
! allocate(y3memls(14,1),xz3(13,1),uz3(9,1,1))
! y3memls=0.0
! xz3=0.0
! uz3=0.0
! tbs3=0.0
!
!
! if(isnow.eq.0)then
! y3memls(1,1)=sum(dzo)
! y3memls(2,1)=bwo(1)
! y3memls(3,1)=bwo(2)
! y3memls(4,1)=bwo(3)
! y3memls(5,1)=tssno(1)
! y3memls(6,1)=tssno(2)
! y3memls(7,1)=tssno(3)
! y3memls(8,1)= flo(1)*bwo(1)/1000
! y3memls(9,1)= flo(2)*bwo(2)/1000
! y3memls(10,1)=flo(3)*bwo(3)/1000
! y3memls(11,1)=gdia(1)
! y3memls(12,1)=gdia(2)
! y3memls(13,1)=gdia(3)
! y3memls(14,1)=TGS
! elseif(snowdepth.gt.0)then
! y3memls(1,1)=snowdepth
! y3memls(2,1)=capac(2)*1000/snowdepth
! y3memls(3,1)=capac(2)*1000/snowdepth
! y3memls(4,1)=capac(2)*1000/snowdepth
! y3memls(5,1)=TGS
! y3memls(6,1)=TGS
! y3memls(7,1)=TGS
! y3memls(8,1)=0.
! y3memls(9,1)=0.
! y3memls(10,1)=0.
! y3memls(11,1)=gsize
! y3memls(12,1)=gsize
! y3memls(13,1)=gsize
! y3memls(14,1)=TGS
! else
! y3memls(1:14,1)=0.0
! y3memls(14,1)=TGS
! endif
!
!! set water content to be 0
! y3memls(8:10,1)=0.0
!
!
!
! xz3(1 ,1)=TD
! xz3(2 ,1)=TC
! xz3(3 ,1)=TA
! xz3(4 ,1)=TM
! xz3(5 ,1)=www(1)
! xz3(6 ,1)=www(2)
! xz3(7 ,1)=www(3)
! xz3(8 ,1)=capac(1)
! xz3(9 ,1)=egi
! xz3(10,1)=gsize
! xz3(11,1)=snden
! xz3(12,1)=capac(2)
! xz3(13,1)=roff
!
! uz3(:,1,1)=uarg(:,ictrl)
!
!! call interfacez3
! call interfacez3(y3memls,zz3,n_rlz3,n_rz3,n_yz3,n_ypz3,n_yrz3,
! & n_zz3,n_zpz3,n_zrz3,n_cz3,n_xz3,ctrl3,freq3,theta_m3,xz3,n_az3,
! & n_u,uz3,month_m3,tbraw3,albedo_m3,ictrl,rank,iveg_type3,ierr3,
! & f_veg_m3,bdrf3,n_bdrf3,meas_switch3,vcov_dat)
!
! tbs3=tbs3+tbraw3(2,1)
!
! !print*,'3 LAYER TB IS=====', TBS3
! !print*, tbs3(1)-tbs4(1)
! !print*,'ICTRL is', ictrl
!
!! iteration begins
! counter=0
! do while((tbs3(1)-tbs4(1)).gt.(0.005))
! y3memls(11,1)=y3memls(11,1)+0.00001
! call interfacez3(y3memls,zz3,n_rlz3,n_rz3,n_yz3,n_ypz3,n_yrz3,
! & n_zz3,n_zpz3,n_zrz3,n_cz3,n_xz3,ctrl3,freq3,theta_m3,xz3,n_az3,
! & n_u,uz3,month_m3,tbraw3,albedo_m3,ictrl,rank,iveg_type3,ierr3,
! & f_veg_m3,bdrf3,n_bdrf3,meas_switch3,vcov_dat)
! tbs3=0.0
! tbs3=tbs3+tbraw3(2,1)
! counter=counter+1
! enddo
!
! !print*,'itration times: ',counter
!! iteration ends
!
! if(isnow.eq.0)then
! gdia(1)=y3memls(11,1)
! elseif(snowdepth.gt.0)then
! gsize=y3memls(11,1)
! endif
!
! !print*,'================================'
!
! deallocate(y3memls,xz3,uz3)
!
! ENDIF
!
! deallocate(freq4,theta_m4,ctrl4,freq3,theta_m3,ctrl3)
!
!cl ======================= ITERATION DONE ==========================
call output1(sunang,siblh,isnow,iday,n_steps,yout,n_y,xout,n_x,
& zout,tend,pixel)
c if (ictrl.eq.49) print *, 'after output1 call...'
END DO
return
end
cm **************************************************************
cm END OF TIME LOOP
cm **************************************************************
C=======================================================================
C
SUBROUTINE CNTROLS(MDAY,alpha,t0,x0,y0,z_in,ipixel,n_a)
C 1 AUGUST 1988
C=======================================================================
C
C INITIALISATION AND SWITCHES.
C
C-----------------------------------------------------------------------
include 'comsib.in'
include 'snow4.in'
dimension alpha(n_a),t0(5),x0(12),y0(14),z_in(2)
C
cm READ(4,*)
cm READ(4,*) DTT, ITRUNK, ILW
cm READ(4,*) ZLAT, ZLONG, TIME,MONTH,MDAY,DAY,YEAR, NITER
cm READ(4,*) ssisnow, snden
cm READ(4,*) TC, TGS, TD, TA, TM, HT, QA
cm READ(4,*) WWW(1),WWW(2),WWW(3),CAPAC(1),CAPAC(2)
cm READ(4,*) DZ(1), DZ(2), DZ(3)
cm READ(4,*) tssn(1),tssn(2),tssn(3)
cm READ(4,*) bw(1), bw(2), bw(3)
cm READ(4,*) fl(1), fl(2), fl(3)
cm READ(4,*) gsize,gdia(1),gdia(2),gdia(3)
cm READ(4,*) sg1,sg2,egi
CM INSTEAD OF READING THESE DATA FROM FILE, THEY ARE PASSED TO SSIB
CM IN THE ALPHA,T0,X0,Y0,Z ARRAYS OR HARDCODED IN
CM FIRST EXTRACT ABOVE ARRAYS TO COMMON VARS
do i=1,3
sg1(i)=alpha(i)
end do
sg2=alpha(4)
sg3=alpha(5)
sg4=alpha(6)
time=t0(1)
month=int(t0(2))
mday=int(t0(3))
day=t0(4)
year=t0(5)
TD=x0(1)
TC=x0(2)
TA=x0(3)
TM=x0(4)
WWW(1)=x0(5)
WWW(2)=x0(6)
WWW(3)=x0(7)
CAPAC(1)=x0(8)
egi=x0(9)
gsize=x0(10)
snden=x0(11)
capac(2)=x0(12)
cm note! there is no need to set roff to x0(13)...
snowdepth=y0(1)
bw(1)=y0(2)
bw(2)=y0(3)
bw(3)=y0(4)
tssn(1)=y0(5)
tssn(2)=y0(6)
tssn(3)=y0(7)
cm initialize fl as 0, then set only if bw>0
fl(1)=0.
fl(2)=0.
fl(3)=0.
if(bw(1).gt.0.) fl(1)=y0(8)/bw(1)*1000
if(bw(2).gt.0.) fl(2)=y0(9)/bw(2)*1000
if(bw(3).gt.0.) fl(3)=y0(10)/bw(3)*1000
gdia(1)=y0(11)
gdia(2)=y0(12)
gdia(3)=y0(13)
tgs=y0(14)
zlat=z_in(1)
zlong=z_in(2)
tssno=0.
flo=0.
bwo=0.
CM DETERMINE DZ(1,2,3) FROM SNOWDEPTH USING LAYERING RULE
IF (snowdepth.le.0.05) THEN
dz=0.0
ELSE IF (snowdepth.gt.0.05.and.snowdepth.le.0.06) THEN
dz(1)=0.02
dz(2)=0.02
dz(3)=snowdepth- dz(1)- dz(2)
ELSE IF ( snowdepth.gt.0.06.and.snowdepth.le.0.08) then
dz(3)=0.02
dz(2)=0.02
dz(1)=snowdepth- dz(3)- dz(2)
ELSE IF ( snowdepth.gt.0.08.and.snowdepth.le.0.62) then
dz(3)=0.02
dz(2)=(snowdepth- dz(3))*0.33333333
dz(1)=(snowdepth- dz(3))*0.66666667
ELSE IF ( snowdepth.gt.0.62) then