-
Notifications
You must be signed in to change notification settings - Fork 4
/
preprocess_code.f
1435 lines (1204 loc) · 48.2 KB
/
preprocess_code.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 preprocess_code.f
c Perform a variety of preprocessing steps, like read in topography
c and vegetation arrays, open input and output files, etc.
ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
SUBROUTINE PREPROCESS_CODE(topoveg_fname,const_veg_flag,
& vegtype,veg_z0,vegsnowdepth,fetch,xmu,C_z,h_const,
& wind_min,Up_const,dz_susp,ztop_susp,fall_vel,Ur_const,
& ro_water,ro_air,gravity,vonKarman,pi,twopio360,snow_z0,
& nx,ny,sum_sprec,sum_qsubl,sum_trans,sum_unload,topo,
& topo_land,snow_d,topoflag,snow_d_init,snow_d_init_const,
& soft_snow_d,met_input_fname,igrads_metfile,deltax,deltay,
& snowtran_output_fname,micromet_output_fname,
& enbal_output_fname,snowpack_output_fname,print_micromet,
& print_enbal,print_snowpack,print_snowtran,run_micromet,
& run_enbal,run_snowpack,run_snowtran,ro_snow_grid,swe_depth,
& sum_runoff,sum_prec,ro_snow,twolayer_flag,sum_Qcs,
& canopy_int,ascii_topoveg,topo_ascii_fname,icorr_factor_loop,
& veg_ascii_fname,undef,isingle_stn_flag,max_iter,
& i_tair_flag,i_rh_flag,i_wind_flag,i_prec_flag,sum_glacmelt,
& snow_depth,sum_d_canopy_int,corr_factor,icorr_factor_index,
& sum_sfcsublim,barnes_lg_domain,n_stns_used,k_stn,xmn,ymn,
& ro_soft_snow_old,sum_swemelt,xlat,lat_solar_flag,xlat_grid,
& xlon_grid,UTC_flag,dt,swe_depth_old,canopy_int_old,
& vegsnowd_xy,iveg_ht_flag,ihrestart_flag,i_dataassim_loop,
& multilayer_snowpack,max_layers,multilayer_output_fname,
& print_multilayer,JJ,tslsnowfall,tsls_threshold,
& irun_data_assim,izero_snow_date,iclear_mn,iclear_dy,
& xclear_hr,dy_snow,swe_lyr,ro_layer,T_old,gamma,icond_flag,
& curve_lg_scale_flag,curve_wt_lg,check_met_data,seaice_run,
& snowmodel_line_flag,xg_line,yg_line,print_user,albedo_flag)
implicit none
include 'snowmodel.inc'
integer i,j,k,nx,ny,igrads_metfile,n_recs_out,iheader,
& isingle_stn_flag,max_iter,i_tair_flag,i_rh_flag,i_wind_flag,
& i_prec_flag,iter,iobs_num,n_stns_used,nveg,iveg_ht_flag,
& lat_solar_flag,ihrestart_flag,nstns_orig,i_dataassim_loop,
& multilayer_snowpack,max_layers,irun_data_assim,
& izero_snow_date,iclear_mn,iclear_dy,icond_flag,albedo_flag
real ro_water,ro_air,gravity,vonKarman,snow_z0,
& fetch,xmu,C_z,h_const,wind_min,Up_const,check_met_data,
& dz_susp,ztop_susp,fall_vel,Ur_const,pi,twopio360,topoflag,
& snow_d_init_const,const_veg_flag,ro_snow,twolayer_flag,
& ascii_topoveg,undef,barnes_lg_domain,xlat,UTC_flag,dt,
& print_multilayer,xclear_hr,curve_lg_scale_flag,seaice_run,
& snowmodel_line_flag,print_user
real topo_land(nx_max,ny_max)
real topo(nx_max,ny_max)
real vegtype(nx_max,ny_max)
real xlat_grid(nx_max,ny_max)
real xlon_grid(nx_max,ny_max)
real snow_d(nx_max,ny_max)
real snow_depth(nx_max,ny_max)
real snow_d_init(nx_max,ny_max)
real canopy_int(nx_max,ny_max)
real swe_depth_old(nx_max,ny_max)
real canopy_int_old(nx_max,ny_max)
real sum_sprec(nx_max,ny_max)
real sum_qsubl(nx_max,ny_max)
real sum_trans(nx_max,ny_max)
real sum_unload(nx_max,ny_max)
real soft_snow_d(nx_max,ny_max)
real ro_soft_snow_old(nx_max,ny_max)
real ro_snow_grid(nx_max,ny_max)
real swe_depth(nx_max,ny_max)
real sum_prec(nx_max,ny_max)
real sum_runoff(nx_max,ny_max)
real sum_Qcs(nx_max,ny_max)
real sum_glacmelt(nx_max,ny_max)
real sum_swemelt(nx_max,ny_max)
real sum_d_canopy_int(nx_max,ny_max)
real sum_sfcsublim(nx_max,ny_max)
real vegsnowdepth(nvegtypes)
real veg_z0(nx_max,ny_max)
real vegsnowd_xy(nx_max,ny_max)
real curve_wt_lg(nx_max,ny_max)
real corr_factor(nx_max,ny_max,max_obs_dates+1)
integer icorr_factor_index(max_time_steps)
integer icorr_factor_loop
integer k_stn(nx_max,ny_max,5)
double precision xmn,ymn
real deltax,deltay
integer icount,iii,jjj
double precision xg_line(nx_max,ny_max),yg_line(nx_max,ny_max)
real run_micromet,run_enbal,run_snowpack,run_snowtran
real print_micromet,print_enbal,print_snowpack,print_snowtran
character*80 topoveg_fname,met_input_fname,topo_ascii_fname,
& veg_ascii_fname
character*80 snowtran_output_fname,micromet_output_fname,
& enbal_output_fname,snowpack_output_fname,
& multilayer_output_fname
integer JJ(nx_max,ny_max)
real tslsnowfall(nx_max,ny_max)
real tsls_threshold
real dy_snow(nx_max,ny_max,nz_max)
real swe_lyr(nx_max,ny_max,nz_max)
real ro_layer(nx_max,ny_max,nz_max)
real T_old(nx_max,ny_max,nz_max)
real gamma(nx_max,ny_max,nz_max)
ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
c Check to see whether the maximum array dimensions defined in
c snowmodel.inc are adequate for the simulation domain defined
c in snowmodel.par.
if (snowmodel_line_flag.eq.0.0) then
if (nx+1.gt.nx_max .or. ny+1.gt.ny_max) then
print *, 'Must increase the value of nx_max or ny_max'
print *, ' in snowmodel.inc to be greater than nx+1'
print *, ' and/or ny+1.'
print *, 'nx_max = ',nx_max,' ny_max = ',ny_max
print *, 'nx = ',nx,' ny = ',ny
stop
endif
else
if (nx.ge.nx_max .or. ny.ne.1 .or. ny_max.ne.2) then
print *, 'For snowmodel_line_flag = 1.0, we suggest setting'
print *, 'nx = number of grid cells, ny = 1, nx_max = nx+1,'
print *, 'and ny_max = ny+1 = 2 in snowmodel.inc.'
print *, ' The current values are:'
print *, ' nx_max = ',nx_max,' ny_max = ',ny_max
print *, ' nx = ',nx,' ny = ',ny
stop
endif
endif
if (multilayer_snowpack.eq.1) then
if (max_layers+1.gt.nz_max) then
print *, 'nz_max in snowmodel.inc must be at least 1 greater'
print *, ' than max_layers in the snowmodel.inc file. So,'
print *, ' if you want to run the multi-layer snowpack model'
print *, ' with a single snow layer, set nz_max=2. If you'
print *, ' want to run the original single-layer snowpack'
print *, ' model, you can set nz_max=1 in snowmodel.inc.'
print *, 'nz_max = ',nz_max
print *, 'max_layers = ',max_layers
stop
endif
endif
if (max_iter.gt.max_time_steps) then
print *, 'Must increase the value of max_time_steps'
print *, ' in snowmodel.inc to be greater than max_iter.'
print *, 'max_time_steps = ',max_time_steps
print *, 'max_iter = ',max_iter
stop
endif
c If running the concatenated configuration of the model, check to
c make sure the rest of the model is configured correctly.
if (snowmodel_line_flag.eq.1.0) then
if (run_snowtran.eq.1.0) then
print *, 'You cannot run snowmodel_line_flag = 1.0 with'
print *, 'run_snowtran = 1.0'
stop
endif
if (barnes_lg_domain.eq.0.0) then
print *, 'If snowmodel_line_flag = 1.0, then you must run'
print *, 'the model with barnes_lg_domain = 1.0'
stop
endif
endif
c Make sure the time since last snowfall treshold is not less
c than the model time step.
if (multilayer_snowpack.eq.1) then
if (tsls_threshold.lt.dt/3600.0) then
print *,'Need to correct tsls_threshold to'
print *,' be >= dt (in hours).'
stop
endif
endif
c Check the model dt value, and send an error message if dt < 3600.
if (dt.lt.3600.0) then
print *, 'You must modify the hour fraction calculation'
print *, ' in get_model_time subroutine to handle'
print *, ' dt values less that 3600.0 seconds.'
print *, 'dt = ',dt
stop
endif
c Define the date on which the snow arrays will be zeroed out.
iclear_mn = izero_snow_date / 10000
iclear_dy = (izero_snow_date - iclear_mn * 10000) / 100
xclear_hr =
& real((izero_snow_date - iclear_mn * 10000) - iclear_dy * 100)
c Check to see whether there is enough snow layers to calculate
c conductive surface fluxes.
if (icond_flag.eq.1) then
if (multilayer_snowpack.eq.0 .or. max_layers.lt.2) then
print *,'If icond_flag = 1, then multilayer_snowpack = 1'
print *,' and max_layers >= 2.'
stop
endif
endif
c Read in the topography array.
if (ascii_topoveg.eq.0.0) then
open (unit=37,file=topoveg_fname,
& form='unformatted',access='direct',recl=4*nx*ny)
read (37,rec=1) ((topo_land(i,j),i=1,nx),j=1,ny)
elseif (ascii_topoveg.eq.1.0) then
c Read off the header lines. I will assume that all of this
c information was input in the .par file correctly.
open (37,file=topo_ascii_fname,form='formatted')
iheader = 6
do k=1,iheader
read (37,*)
enddo
c Read the data in as real numbers, and do the yrev.
do j=ny,1,-1
read (37,*) (topo_land(i,j),i=1,nx)
enddo
endif
c If vegetation data is not available on the topography grid,
c define the vegetation to be constant.
if (const_veg_flag.ne.0.0) then
do i=1,nx
do j=1,ny
vegtype(i,j) = const_veg_flag
enddo
enddo
c Read in the vegetation array.
else
if (ascii_topoveg.eq.0.0) then
read (37,rec=2) ((vegtype(i,j),i=1,nx),j=1,ny)
elseif (ascii_topoveg.eq.1.0) then
c Read off the header lines. I will assume that all of this
c information was input in the .par file correctly.
open (38,file=veg_ascii_fname,form='formatted')
do k=1,iheader
read (38,*)
enddo
c Read the data in as real numbers, and do the yrev.
do j=ny,1,-1
read (38,*) (vegtype(i,j),i=1,nx)
enddo
endif
endif
c Now that we have read in the topo and veg data arrays, check
c whether all of the values look like valid numbers.
do i=1,nx
do j=1,ny
if (vegtype(i,j).lt.1.0 .or. vegtype(i,j).gt.30.0) then
print *, 'Found Invalid Vegetation-Type Value'
print *, ' Value =',vegtype(i,j),' at ',i,j
stop
endif
if (topo_land(i,j).lt.0.0 .or. topo_land(i,j).gt.9000.0) then
print *, 'Found Invalid Topography Value'
print *, ' Value =',topo_land(i,j),' at ',i,j
stop
endif
enddo
enddo
c J.PFLUG
c provide the opportunity to read in snow and rain precipitation data
if (i_prec_flag.eq.-1.0) then
open (99,file='met/TUO_elev_fp.txt',
& form='formatted')
rewind(99)
endif
if (albedo_flag.eq.1.0) then
open (98,file='extra_met/albedo.dat',
& form='formatted')
rewind (98)
endif
c END J.PFLUG
c Fill the the vegetation snow-holding depth array for vegetation
c types 1 through 24 (types 25 through 30 were filled from the
c .par file.
call fill_veg_shd(nvegtypes,vegsnowdepth)
c Use vegsnowdepth to fill the 2D spatial array, or read in the
c user-provided file of the vegetation heights (in cm).
if (iveg_ht_flag.eq.-1) then
open (191,file='topo_veg/veg_ht.gdat',
& form='unformatted',access='direct',recl=4*nx*ny)
read (191,rec=1) ((vegsnowd_xy(i,j),i=1,nx),j=1,ny)
close(191)
c Convert from cm to m.
do i=1,nx
do j=1,ny
vegsnowd_xy(i,j) = vegsnowd_xy(i,j) / 100.0
enddo
enddo
elseif (iveg_ht_flag.eq.1) then
open (191,file='topo_veg/veg_ht.asc',form='formatted')
iheader = 6
do k=1,iheader
read (191,*)
enddo
c Read the data in as real numbers, and do the yrev.
do j=ny,1,-1
read (191,*) (vegsnowd_xy(i,j),i=1,nx)
enddo
close(191)
c Convert from cm to m.
do i=1,nx
do j=1,ny
vegsnowd_xy(i,j) = vegsnowd_xy(i,j) / 100.0
enddo
enddo
elseif (iveg_ht_flag.eq.0) then
do i=1,nx
do j=1,ny
nveg = nint(vegtype(i,j))
vegsnowd_xy(i,j) = vegsnowdepth(nveg)
enddo
enddo
endif
c Define the roughness lengths for each of the vegetation types.
c Note that this is pretty arbitrary, because these values are
c really only used when there is no blowing snow, and thus have
c no impact on the simulation except to provide a non-zero value
c for any such parts of the domain.
do i=1,nx
do j=1,ny
veg_z0(i,j) = 0.25 * vegsnowd_xy(i,j)
enddo
enddo
c Read in the large-scale curvature weighting array, if the run
c requires it.
if (curve_lg_scale_flag.eq.1.0) then
open (444,file='extra_met/large_curvature_wt.gdat',
& form='unformatted',access='direct',recl=4*nx*ny)
read (444,rec=1) ((curve_wt_lg(i,j),i=1,nx),j=1,ny)
close (444)
endif
c If this is a sea ice run, open the sea ice concentration file.
if (seaice_run.ne.0.0) then
open (445,file='seaice/ice_conc.gdat',
& form='unformatted',access='direct',recl=4*nx*ny)
endif
c Check to make sure that if you are running SnowTran-3D and the
c EnBal and SnowPack models, you have also set the flag to run
c the SnowTran-3D two-layer submodel.
if (run_enbal.eq.1.0 .and. run_snowpack.eq.1.0 .and.
& run_snowtran.eq.1.0) then
if (twolayer_flag.ne.1.0) then
print *, 'For SnowTran-3D with EnBal and SnowPack,'
print *, ' twolayer_flag must equal 1.0'
stop
endif
endif
c Check to see that the defined domain is large enough to be
c running SnowTran-3D.
if (run_snowtran.eq.1.0) then
if (nx.lt.3 .or. ny.lt.3) then
print *, 'To run SnowTran-3D, nx and ny must both be 3'
print *, ' or greater (see SnowTran-3D code/notes)'
stop
endif
endif
c Check to see whether the model is configured correctly to be
c running the multi-layer snow model.
if (multilayer_snowpack.eq.1) then
if (irun_data_assim.eq.1 .or. ihrestart_flag.ne.-2 .or.
& snow_d_init_const.ne.0.0) then
print *, 'The multi-layer snowpack model requires:'
print *, ' irun_data_assim = 0'
print *, ' ihrestart_flag = -2'
print *, ' snow_d_init_const = 0.0'
c stop
endif
endif
c Get a collection of constants that are not generally modified.
call constants(fetch,xmu,C_z,h_const,wind_min,Up_const,
& dz_susp,ztop_susp,fall_vel,Ur_const,ro_water,ro_air,
& gravity,vonKarman,pi,twopio360,snow_z0)
c Run a check to see if SnowTran-3D is being run with grid
c increments that are too large.
if (deltax.gt.500.0 .or. deltay.gt.500.0) then
if (run_snowtran.eq.1.0) then
print *
print *, '!!! deltax,y should not be greater than 500 m'
print *, '!!! if you are also running SnowTran-3D'
print *
stop
endif
endif
c Initialize the summing arrays, and define the initial snow-depth
c distributions.
call initialize(nx,ny,sum_sprec,sum_qsubl,sum_trans,
& sum_unload,topo,topo_land,snow_d,topoflag,snow_d_init,
& snow_d_init_const,soft_snow_d,ro_water,sum_sfcsublim,
& ro_snow_grid,swe_depth,sum_runoff,sum_prec,ro_snow,
& sum_Qcs,canopy_int,sum_glacmelt,snow_depth,sum_d_canopy_int,
& ro_soft_snow_old,sum_swemelt,swe_depth_old,canopy_int_old,
& ihrestart_flag,i_dataassim_loop,max_iter,corr_factor,
& icorr_factor_index,JJ,tslsnowfall,tsls_threshold,dy_snow,
& swe_lyr,ro_layer,T_old,gamma)
c Check to see whether the data assimilation has been configured
c correctly.
if (irun_data_assim.eq.1) then
c Check to see whether the required output files will be created.
if (print_user.ne.1.0) then
print *, 'For a data assimilation run print_user must = 1.0'
stop
endif
c Check to see whether the corr_factor array is defined to be large
c enough to do the assimilation. It looks like I can't do that
c here because I don't know the name of the swe-obs input file yet.
c Therefore I will do a check when dataassim_user.f is called. So
c in the mean time I will just print a message to the screen telling
c the user to check this.
print *
print *, 'For a DATA ASSIMILATION RUN, MAX_OBS_DATES must be'
print *, 'defined in SNOWMODEL.INC to be greater than the'
print *, 'number of observation dates in the entire simulation'
print *, '+ (plus) the number of years in the simulation. For'
print *, 'example, for a 6-year simulation with two observation'
print *, 'dates in each year, you would set max_obs_dates to be'
print *, 'at least = 18.'
print *
endif
c Initialize the precipitation factor for the first iteration to
c equal 1.0.
if (icorr_factor_loop.eq.1) then
do iobs_num=1,max_obs_dates+1
do j=1,ny
do i=1,nx
corr_factor(i,j,iobs_num) = 1.0
enddo
enddo
enddo
do iter=1,max_iter
icorr_factor_index(iter) = 1
enddo
endif
c Read or build the latitude array that will be used to do the
c latitude weighting when calculating incoming solar radiation.
if (lat_solar_flag.eq.-1) then
open (91,file='extra_met/grid_lat.gdat',
& form='unformatted',access='direct',recl=4*nx*ny)
read (91,rec=1) ((xlat_grid(i,j),i=1,nx),j=1,ny)
close(91)
elseif (lat_solar_flag.eq.1) then
open (91,file='extra_met/grid_lat.asc',form='formatted')
iheader = 6
do k=1,iheader
read (91,*)
enddo
c Read the data in as real numbers, and do the yrev.
do j=ny,1,-1
read (91,*) (xlat_grid(i,j),i=1,nx)
enddo
close(91)
elseif (lat_solar_flag.eq.0) then
c Print an error if the y-domain is big enough to have important
c solar radiation differences from south to north.
if (ny*deltay.gt.500000.0) then
print *
print *,'YOUR DOMAIN IS PRETTY BIG TO NOT ACCOUNT FOR'
print *,' SOLAR RADIATION VARIATIONS WITH LATITUDE'
print *,' see the "lat_solar_flag" in snowmodel.par'
print *
stop
endif
do i=1,nx
do j=1,ny
xlat_grid(i,j) = xlat
enddo
enddo
endif
c Read or build the lonitude array that will be used to do the
c lonitude influence when calculating incoming solar radiation.
if (UTC_flag.eq.-1.0) then
open (91,file='extra_met/grid_lon.gdat',
& form='unformatted',access='direct',recl=4*nx*ny)
read (91,rec=1) ((xlon_grid(i,j),i=1,nx),j=1,ny)
close(91)
elseif (UTC_flag.eq.1.0) then
open (91,file='extra_met/grid_lon.asc',form='formatted')
iheader = 6
do k=1,iheader
read (91,*)
enddo
c Read the data in as real numbers, and do the yrev.
do j=ny,1,-1
read (91,*) (xlon_grid(i,j),i=1,nx)
enddo
close(91)
elseif (UTC_flag.eq.0.0) then
c Print an error if the x-domain is big enough to have important
c solar radiation differences from east to west.
if (nx*deltax.gt.500000.0) then
print *
print *,'YOUR DOMAIN IS PRETTY BIG TO NOT ACCOUNT FOR'
print *,' SOLAR RADIATION VARIATIONS WITH LONITUDE'
print *,' see the "UTC_flag" in snowmodel.par'
print *
stop
endif
endif
c Open the MicroMet station data input file.
if (igrads_metfile.eq.1) then
open(20,file=met_input_fname,form='unformatted',
& access='direct',recl=4*13)
else
open (20,file=met_input_fname,form='formatted')
endif
c Run a check to see whether there are any time slices with no
c valid data.
if (check_met_data.eq.1.0) then
print *
print *,'Checking for sufficient met forcing data to'
print *,' complete the model simulation. This may'
print *,' take a while, depending on how big your met'
print *,' input file is.'
print *
call met_data_check(undef,isingle_stn_flag,igrads_metfile,
& max_iter,i_tair_flag,i_rh_flag,i_wind_flag,i_prec_flag)
endif
c If the concatenated configuration of the model is used, read
c in the x and y coordinates for the concatenated grid cells.
if (snowmodel_line_flag.eq.1.0) then
open (1331,file='extra_met/snowmodel_line_pts.dat')
do j=1,ny
do i=1,nx
read (1331,*) icount,iii,jjj,xg_line(i,j),yg_line(i,j)
enddo
enddo
close (1331)
endif
c If the large-domain barnes oi scheme is used, generate the
c nearest-station indexing array.
if (barnes_lg_domain.eq.1.0) then
print *
print *,'You are running the large-domain Barnes oi scheme'
print *,' This requires:'
print *,' 1) no missing data for the fields of interest'
print *,' 2) no missing stations during the simulation'
print *,' 3) met file must list stations in the same order'
print *,' 4) the number of nearest stations used is 5 or less'
print *,' 5) **** no error checking for this is done ****'
print *
print *,'Generating nearest-station index. Be patient.'
print *
if (n_stns_used.gt.5 .or. n_stns_used.lt.1) then
print *,'invalid n_stns_used value'
stop
endif
call get_nearest_stns_1(nx,ny,xmn,ymn,deltax,deltay,
& n_stns_used,k_stn,snowmodel_line_flag,xg_line,yg_line)
endif
c If this is a history restart run, advance the micromet input
c file to the restart time.
if (ihrestart_flag.ge.0) then
if (igrads_metfile.eq.0) then
do iter=1,ihrestart_flag
if (isingle_stn_flag.eq.1) then
nstns_orig = 1
else
read(20,*) nstns_orig
endif
do k=1,nstns_orig
read(20,*)
enddo
enddo
endif
endif
c Open the files to be used to store model output.
c For MicroMet.
if (run_micromet.eq.1.0 .and. print_micromet.eq.1.0) then
n_recs_out = 8
open (81,file=micromet_output_fname,
& form='unformatted',access='direct',recl=4*n_recs_out*nx*ny)
endif
c For EnBal.
if (run_enbal.eq.1.0 .and. print_enbal.eq.1.0) then
n_recs_out = 10
open (82,file=enbal_output_fname,
& form='unformatted',access='direct',recl=4*n_recs_out*nx*ny)
endif
c For SnowPack.
if (run_snowpack.eq.1.0 .and. print_snowpack.eq.1.0) then
n_recs_out = 16
open (83,file=snowpack_output_fname,
& form='unformatted',access='direct',recl=4*n_recs_out*nx*ny)
endif
c For SnowTran-3D.
if (run_snowtran.eq.1.0 .and. print_snowtran.eq.1.0) then
n_recs_out = 7
open (84,file=snowtran_output_fname,
& form='unformatted',access='direct',recl=4*n_recs_out*nx*ny)
endif
c For Multi-Layer SnowPack.
if (run_snowpack.eq.1.0 .and. multilayer_snowpack.eq.1 .and.
& print_multilayer.eq.1.0) then
open (85,file=multilayer_output_fname,
& form='unformatted',access='direct',
& recl=4*(4*nx*ny+6*nx*ny*nz_max))
endif
c For random precipitation error
if (irun_data_assim.eq.1.and.icorr_factor_loop.eq.1) then
open(11,file='data/randomError.txt')
endif
return
end
ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
subroutine initialize(nx,ny,sum_sprec,sum_qsubl,sum_trans,
& sum_unload,topo,topo_land,snow_d,topoflag,snow_d_init,
& snow_d_init_const,soft_snow_d,ro_water,sum_sfcsublim,
& ro_snow_grid,swe_depth,sum_runoff,sum_prec,ro_snow,
& sum_Qcs,canopy_int,sum_glacmelt,snow_depth,sum_d_canopy_int,
& ro_soft_snow_old,sum_swemelt,swe_depth_old,canopy_int_old,
& ihrestart_flag,i_dataassim_loop,max_iter,corr_factor,
& icorr_factor_index,JJ,tslsnowfall,tsls_threshold,dy_snow,
& swe_lyr,ro_layer,T_old,gamma)
implicit none
include 'snowmodel.inc'
integer i,j,nx,ny,ihrestart_flag,i_dataassim_loop,max_iter,k
real topoflag,snow_d_init_const,ro_water,ro_snow
real sum_sprec(nx_max,ny_max)
real sum_qsubl(nx_max,ny_max)
real sum_trans(nx_max,ny_max)
real sum_unload(nx_max,ny_max)
real topo(nx_max,ny_max)
real topo_land(nx_max,ny_max)
real snow_d(nx_max,ny_max)
real snow_depth(nx_max,ny_max)
real soft_snow_d(nx_max,ny_max)
real ro_soft_snow_old(nx_max,ny_max)
real ro_snow_grid(nx_max,ny_max)
real swe_depth(nx_max,ny_max)
real sum_prec(nx_max,ny_max)
real sum_runoff(nx_max,ny_max)
real sum_Qcs(nx_max,ny_max)
real canopy_int(nx_max,ny_max)
real sum_glacmelt(nx_max,ny_max)
real sum_swemelt(nx_max,ny_max)
real sum_d_canopy_int(nx_max,ny_max)
real sum_sfcsublim(nx_max,ny_max)
real snow_d_init(nx_max,ny_max)
real swe_depth_old(nx_max,ny_max)
real canopy_int_old(nx_max,ny_max)
integer JJ(nx_max,ny_max)
real tslsnowfall(nx_max,ny_max)
real tsls_threshold
real dy_snow(nx_max,ny_max,nz_max)
real swe_lyr(nx_max,ny_max,nz_max)
real ro_layer(nx_max,ny_max,nz_max)
real T_old(nx_max,ny_max,nz_max)
real gamma(nx_max,ny_max,nz_max)
integer icorr_factor_index(max_time_steps)
real corr_factor(nx_max,ny_max,max_obs_dates+1)
if (ihrestart_flag.ge.0) then
c Read in the saved data.
CALL HRESTART_READ(nx,ny,snow_d,snow_depth,
& canopy_int,soft_snow_d,ro_snow_grid,swe_depth,
& ro_soft_snow_old,snow_d_init,swe_depth_old,
& canopy_int_old,topo,sum_sprec,ihrestart_flag,
& i_dataassim_loop)
if (i_dataassim_loop.lt.0.0) then
CALL HRESTART_READ_DA(nx,ny,max_iter,corr_factor,
& icorr_factor_index,i_dataassim_loop)
endif
do i=1,nx
do j=1,ny
c Fill the summing arrays.
sum_runoff(i,j) = 0.0
sum_prec(i,j) = 0.0
c sum_sprec(i,j) = 0.0
sum_qsubl(i,j) = 0.0
sum_trans(i,j) = 0.0
sum_unload(i,j) = 0.0
sum_Qcs(i,j) = 0.0
sum_glacmelt(i,j) = 0.0
sum_swemelt(i,j) = 0.0
sum_d_canopy_int(i,j) = 0.0
sum_sfcsublim(i,j) = 0.0
c Define the initial snow-depth distributions.
c snow_d_init(i,j) = snow_d_init_const
c snow_d(i,j) = snow_d_init(i,j)
c snow_depth(i,j) = snow_d_init(i,j)
c canopy_int(i,j) = 0.0
c soft_snow_d(i,j) = snow_d(i,j)
c ro_snow_grid(i,j) = ro_snow
c swe_depth(i,j) = snow_d(i,j) * ro_snow_grid(i,j) / ro_water
c ro_soft_snow_old(i,j) = 50.0
c swe_depth_old(i,j) = swe_depth(i,j)
c canopy_int_old(i,j) = canopy_int(i,j)
enddo
enddo
else
do i=1,nx
do j=1,ny
c Fill the summing arrays.
sum_runoff(i,j) = 0.0
sum_prec(i,j) = 0.0
sum_sprec(i,j) = 0.0
sum_qsubl(i,j) = 0.0
sum_trans(i,j) = 0.0
sum_unload(i,j) = 0.0
sum_Qcs(i,j) = 0.0
sum_glacmelt(i,j) = 0.0
sum_swemelt(i,j) = 0.0
sum_d_canopy_int(i,j) = 0.0
sum_sfcsublim(i,j) = 0.0
c Define the initial snow-depth distributions.
snow_d_init(i,j) = snow_d_init_const
snow_d(i,j) = snow_d_init(i,j)
snow_depth(i,j) = snow_d_init(i,j)
canopy_int(i,j) = 0.0
soft_snow_d(i,j) = snow_d(i,j)
ro_snow_grid(i,j) = ro_snow
swe_depth(i,j) = snow_d(i,j) * ro_snow_grid(i,j) / ro_water
ro_soft_snow_old(i,j) = 50.0
swe_depth_old(i,j) = swe_depth(i,j)
canopy_int_old(i,j) = canopy_int(i,j)
c Initialize the multi-layer snowpack arrays.
JJ(i,j) = 0
tslsnowfall(i,j) = tsls_threshold
enddo
enddo
do i=1,nx
do j=1,ny
do k=1,nz_max
dy_snow(i,j,k) = 0.0
swe_lyr(i,j,k) = 0.0
ro_layer(i,j,k) = ro_snow
T_old(i,j,k) = 273.16
gamma(i,j,k) = 0.138 - 1.01 * (ro_layer(i,j,k)/1000.0) +
& 3.233 * (ro_layer(i,j,k)/1000.0)**2
enddo
enddo
enddo
if (topoflag.eq.1.0) then
do i=1,nx
do j=1,ny
topo(i,j) = topo_land(i,j) + snow_d(i,j)
enddo
enddo
elseif (topoflag.eq.0.0) then
do i=1,nx
do j=1,ny
topo(i,j) = topo_land(i,j)
enddo
enddo
endif
endif
return
end
ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
subroutine constants(fetch,xmu,C_z,h_const,wind_min,Up_const,
& dz_susp,ztop_susp,fall_vel,Ur_const,ro_water,ro_air,
& gravity,vonKarman,pi,twopio360,snow_z0)
implicit none
real fetch,xmu,C_z,h_const,wind_min,Up_const,
& dz_susp,ztop_susp,fall_vel,Ur_const,ro_water,ro_air,
& gravity,vonKarman,pi,twopio360,snow_z0
c These constants are not generally modified for a particular model
c run.
c Snow surface roughness length.
snow_z0 = 0.001
c Constants related to surface shear stress and saltation
c transport.
fetch = 500.0
xmu = 3.0
C_z = 0.12
h_const = 1.6
wind_min = 4.0
c Constants related to suspended snow profile.
Up_const = 2.8
dz_susp = 0.20
ztop_susp = 2.0
fall_vel = 0.3
Ur_const = 0.5
c General constants.
ro_water = 1000.0
ro_air = 1.275
gravity = 9.81
vonKarman = 0.4
pi = 2.0 * acos(0.0)
twopio360 = 2.0 * pi / 360.0
return
end
cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
subroutine fill_veg_shd(nvegtypes,vegsnowdepth)
implicit none
integer k,nvegtypes,nvegtypes_fixed
parameter (nvegtypes_fixed=24)
real vegsnowdepth(nvegtypes),vegsnowdepth_fixed(nvegtypes_fixed)
c Fill the the vegetation snow-holding depth array for
c vegetation types 1 through 24 (types 25 through 30 were filled
c from the .par file.
c
c The following summary was taken from the .par file.
c
c The vegetation types are assumed to range from 1 through 30. The
c last 6 types are available to be user-defined vegetation types
c and vegetation snow-holding depth. The first 24 vegetation
c types, and the associated vegetation snow-holding depth
c (meters), are hard-coded to be:
c
c code description veg_shd example class
c
c 1 coniferous forest 15.00 spruce-fir/taiga/lodgepole forest
c 2 deciduous forest 12.00 aspen forest forest
c 3 mixed forest 14.00 aspen/spruce-fir/low taiga forest
c 4 scattered short-conifer 8.00 pinyon-juniper forest
c 5 clearcut conifer 4.00 stumps and regenerating forest
c
c 6 mesic upland shrub 0.50 deeper soils, less rocky shrub
c 7 xeric upland shrub 0.25 rocky, windblown soils shrub
c 8 playa shrubland 1.00 greasewood, saltbush shrub
c 9 shrub wetland/riparian 1.75 willow along streams shrub
c 10 erect shrub tundra 0.65 arctic shrubland shrub
c 11 low shrub tundra 0.30 low to medium arctic shrubs shrub
c
c 12 grassland rangeland 0.15 graminoids and forbs grass
c 13 subalpine meadow 0.25 meadows below treeline grass
c 14 tundra (non-tussock) 0.15 alpine, high arctic grass
c 15 tundra (tussock) 0.20 graminoid and dwarf shrubs grass
c 16 prostrate shrub tundra 0.10 graminoid dominated grass
c 17 arctic gram. wetland 0.20 grassy wetlands, wet tundra grass
c
c 18 bare 0.01 bare
c
c 19 water/possibly frozen 0.01 water
c 20 permanent snow/glacier 0.01 water
c
c 21 residential/urban 0.01 human
c 22 tall crops 0.40 e.g., corn stubble human
c 23 short crops 0.25 e.g., wheat stubble human
c 24 ocean 0.01 water
c
c 25 user defined (see below)
c 26 user defined (see below)
c 27 user defined (see below)
c 28 user defined (see below)
c 29 user defined (see below)
c 30 user defined (see below)
c
c Define the vegetation snow-holding depth (meters) for each
c of the user-defined vegetation types. The numbers in the
c list below correspond to the vegetation-type numbers in the
c vegetation-type data array (veg type 25.0 -> veg_shd_25). Note
c that even if these are not used, they cannot be commented out
c or you will get an error message.
c veg_shd_25 = 0.10
c veg_shd_26 = 0.10
c veg_shd_27 = 0.10
c veg_shd_28 = 0.10
c veg_shd_29 = 0.10
c veg_shd_30 = 0.10
data vegsnowdepth_fixed/15.00, 12.00, 14.00, 8.00, 4.00,
& 0.50, 0.25, 1.00, 1.75, 0.65, 0.30,
& 0.15, 0.25, 0.15, 0.20, 0.10, 0.20,
& 0.01, 0.01, 0.01, 0.01, 0.40, 0.25,
& 0.01/
do k=1,nvegtypes_fixed
vegsnowdepth(k) = vegsnowdepth_fixed(k)
enddo
return
end
cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
subroutine met_data_check(undef,isingle_stn_flag,igrads_metfile,
& max_iter,i_tair_flag,i_rh_flag,i_wind_flag,i_prec_flag)
implicit none
include 'snowmodel.inc'
integer iyr,imo,idy ! year, month, and day of data