forked from wrf-model/WRF
-
Notifications
You must be signed in to change notification settings - Fork 0
/
module_soil_pre.F
3110 lines (2617 loc) · 137 KB
/
module_soil_pre.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
MODULE module_soil_pre
USE module_date_time
USE module_state_description
CHARACTER (LEN=3) :: num_cat_count
INTEGER , PARAMETER , DIMENSION(0:300) :: ints = &
(/ 0, 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 /)
! Excluded middle processing
LOGICAL , SAVE :: hold_ups
INTEGER , SAVE :: em_width
LOGICAL , EXTERNAL :: skip_middle_points_t
CONTAINS
SUBROUTINE adjust_for_seaice_pre ( xice , landmask , tsk , ivgtyp , vegcat , lu_index , &
xland , landusef , isltyp , soilcat , soilctop , &
soilcbot , tmn , &
seaice_threshold , &
fractional_seaice, &
num_veg_cat , num_soil_top_cat , num_soil_bot_cat , &
iswater , isice , &
scheme , &
ids , ide , jds , jde , kds , kde , &
ims , ime , jms , jme , kms , kme , &
its , ite , jts , jte , kts , kte )
IMPLICIT NONE
INTEGER , INTENT(IN) :: ids , ide , jds , jde , kds , kde , &
ims , ime , jms , jme , kms , kme , &
its , ite , jts , jte , kts , kte , &
iswater , isice
INTEGER , INTENT(IN) :: num_veg_cat , num_soil_top_cat , num_soil_bot_cat , scheme
REAL , DIMENSION(ims:ime,1:num_veg_cat,jms:jme) , INTENT(INOUT):: landusef
REAL , DIMENSION(ims:ime,1:num_soil_top_cat,jms:jme) , INTENT(INOUT):: soilctop
REAL , DIMENSION(ims:ime,1:num_soil_bot_cat,jms:jme) , INTENT(INOUT):: soilcbot
INTEGER , DIMENSION(ims:ime,jms:jme), INTENT(OUT) :: isltyp , ivgtyp
REAL , DIMENSION(ims:ime,jms:jme) , INTENT(INOUT) :: landmask , xice , tsk , lu_index , &
vegcat, xland , soilcat , tmn
REAL , INTENT(IN) :: seaice_threshold
INTEGER :: i , j , num_seaice_changes , loop
CHARACTER (LEN=132) :: message
INTEGER, INTENT(IN) :: fractional_seaice
REAL :: XICE_THRESHOLD
IF ( FRACTIONAL_SEAICE == 0 ) THEN
xice_threshold = 0.5
ELSEIF ( FRACTIONAL_SEAICE == 1 ) THEN
xice_threshold = 0.02
ENDIF
num_seaice_changes = 0
fix_seaice : SELECT CASE ( scheme )
CASE ( SLABSCHEME )
DO j = jts , MIN(jde-1,jte)
DO i = its , MIN(ide-1,ite)
IF ( skip_middle_points_t ( ids , ide , jds , jde , i , j , em_width , hold_ups ) ) CYCLE
IF ( xice(i,j) .GT. 200.0 ) THEN
xice(i,j) = 0.
num_seaice_changes = num_seaice_changes + 1
END IF
END DO
END DO
IF ( num_seaice_changes .GT. 0 ) THEN
WRITE ( message , FMT='(A,I6)' ) &
'Total pre number of sea ice locations removed (due to FLAG values) = ', &
num_seaice_changes
CALL wrf_debug ( 0 , message )
END IF
num_seaice_changes = 0
DO j = jts , MIN(jde-1,jte)
DO i = its , MIN(ide-1,ite)
IF ( skip_middle_points_t ( ids , ide , jds , jde , i , j , em_width , hold_ups ) ) CYCLE
IF ( ( xice(i,j) .GE. xice_threshold ) .OR. &
( ( landmask(i,j) .LT. 0.5 ) .AND. ( tsk(i,j) .LT. seaice_threshold ) ) ) THEN
IF ( FRACTIONAL_SEAICE == 0 ) THEN
xice(i,j) = 1.0
ENDIF
num_seaice_changes = num_seaice_changes + 1
if(landmask(i,j) .LT. 0.5 )tmn(i,j) = 271.4
vegcat(i,j)=isice
ivgtyp(i,j)=isice
lu_index(i,j)=isice
landmask(i,j)=1.
xland(i,j)=1.
DO loop=1,num_veg_cat
landusef(i,loop,j)=0.
END DO
landusef(i,ivgtyp(i,j),j)=1.
isltyp(i,j) = 16
soilcat(i,j)=isltyp(i,j)
DO loop=1,num_soil_top_cat
soilctop(i,loop,j)=0
END DO
DO loop=1,num_soil_bot_cat
soilcbot(i,loop,j)=0
END DO
soilctop(i,isltyp(i,j),j)=1.
soilcbot(i,isltyp(i,j),j)=1.
ELSE
xice(i,j) = 0.0
END IF
END DO
END DO
IF ( num_seaice_changes .GT. 0 ) THEN
WRITE ( message , FMT='(A,I6)' ) &
'Total pre number of sea ice location changes (water to land) = ', num_seaice_changes
CALL wrf_debug ( 0 , message )
END IF
CASE ( LSMSCHEME , NOAHMPSCHEME , RUCLSMSCHEME ,CLMSCHEME,SSIBSCHEME) !mchen add for ssib
num_seaice_changes = 0
DO j = jts , MIN(jde-1,jte)
DO i = its , MIN(ide-1,ite)
IF ( skip_middle_points_t ( ids , ide , jds , jde , i , j , em_width , hold_ups ) ) CYCLE
IF ( landmask(i,j) .GT. 0.5 ) THEN
if (xice(i,j).gt.0) num_seaice_changes = num_seaice_changes + 1
xice(i,j) = 0.
END IF
END DO
END DO
IF ( num_seaice_changes .GT. 0 ) THEN
WRITE ( message , FMT='(A,I6)' ) &
'Total pre number of land location changes (seaice set to zero) = ', num_seaice_changes
CALL wrf_debug ( 0 , message )
END IF
END SELECT fix_seaice
END SUBROUTINE adjust_for_seaice_pre
SUBROUTINE adjust_for_seaice_post ( xice , landmask , tsk_old , tsk , ivgtyp , vegcat , lu_index , &
xland , landusef , isltyp , soilcat , soilctop , &
soilcbot , tmn , vegfra , &
tslb , smois , sh2o , &
seaice_threshold , &
sst , flag_sst , &
fractional_seaice, &
num_veg_cat , num_soil_top_cat , num_soil_bot_cat , &
num_soil_layers , &
iswater , isice , &
scheme , &
ids , ide , jds , jde , kds , kde , &
ims , ime , jms , jme , kms , kme , &
its , ite , jts , jte , kts , kte )
IMPLICIT NONE
INTEGER , INTENT(IN) :: ids , ide , jds , jde , kds , kde , &
ims , ime , jms , jme , kms , kme , &
its , ite , jts , jte , kts , kte , &
iswater , isice
INTEGER , INTENT(IN) :: num_veg_cat , num_soil_top_cat , num_soil_bot_cat , scheme
INTEGER , INTENT(IN) :: num_soil_layers
REAL , DIMENSION(ims:ime,1:num_veg_cat,jms:jme) , INTENT(INOUT):: landusef
REAL , DIMENSION(ims:ime,1:num_soil_top_cat,jms:jme) , INTENT(INOUT):: soilctop
REAL , DIMENSION(ims:ime,1:num_soil_bot_cat,jms:jme) , INTENT(INOUT):: soilcbot
REAL , DIMENSION(ims:ime,1:num_soil_layers,jms:jme) , INTENT(INOUT):: tslb , smois , sh2o
REAL , DIMENSION(ims:ime,jms:jme) , INTENT(IN):: sst
INTEGER , DIMENSION(ims:ime,jms:jme), INTENT(OUT) :: isltyp , ivgtyp
REAL , DIMENSION(ims:ime,jms:jme) , INTENT(INOUT) :: landmask , xice , tsk , lu_index , &
vegcat, xland , soilcat , tmn , &
tsk_old , vegfra
INTEGER , INTENT(IN) :: flag_sst
REAL , INTENT(IN) :: seaice_threshold
REAL :: total_depth , mid_point_depth
INTEGER :: i , j , num_seaice_changes , loop
CHARACTER (LEN=132) :: message
INTEGER, INTENT(IN) :: fractional_seaice
real :: xice_threshold
IF ( FRACTIONAL_SEAICE == 0 ) THEN
xice_threshold = 0.5
ELSEIF ( FRACTIONAL_SEAICE == 1 ) THEN
xice_threshold = 0.02
ENDIF
num_seaice_changes = 0
fix_seaice : SELECT CASE ( scheme )
CASE ( SLABSCHEME )
#ifdef WRF_USE_CTSM
CASE ( LSMSCHEME , NOAHMPSCHEME , CLMSCHEME, CTSMSCHEME, SSIBSCHEME ) !mchen add for ssib
#else
CASE ( LSMSCHEME , NOAHMPSCHEME , CLMSCHEME, SSIBSCHEME ) !mchen add for ssib
#endif
DO j = jts , MIN(jde-1,jte)
DO i = its , MIN(ide-1,ite)
IF ( skip_middle_points_t ( ids , ide , jds , jde , i , j , em_width , hold_ups ) ) CYCLE
IF ( xice(i,j) .GT. 200.0 ) THEN
xice(i,j) = 0.
num_seaice_changes = num_seaice_changes + 1
END IF
END DO
END DO
IF ( num_seaice_changes .GT. 0 ) THEN
WRITE ( message , FMT='(A,I6)' ) &
'Total post number of sea ice locations removed (due to FLAG values) = ', &
num_seaice_changes
CALL wrf_debug ( 0 , message )
END IF
num_seaice_changes = 0
DO j = jts , MIN(jde-1,jte)
DO i = its , MIN(ide-1,ite)
IF ( skip_middle_points_t ( ids , ide , jds , jde , i , j , em_width , hold_ups ) ) CYCLE
IF ( ( ( tsk(i,j) .LT. 170 ) .OR. ( tsk(i,j) .GT. 400 ) ) .AND. &
( ( tsk_old(i,j) .GT. 170 ) .AND. ( tsk_old(i,j) .LT. 400 ) ) )THEN
tsk(i,j) = tsk_old(i,j)
END IF
IF ( ( ( tsk(i,j) .LT. 170 ) .OR. ( tsk(i,j) .GT. 400 ) ) .AND. &
( ( tsk_old(i,j) .LT. 170 ) .OR. ( tsk_old(i,j) .GT. 400 ) ) )THEN
print *,'TSK woes in seaice post, i,j=',i,j,' tsk = ',tsk(i,j), tsk_old(i,j)
CALL wrf_error_fatal ( 'TSK is unrealistic, problems for seaice post')
ELSE IF ( ( xice(i,j) .GE. xice_threshold ) .OR. &
( ( landmask(i,j) .LT. 0.5 ) .AND. ( tsk(i,j) .LT. seaice_threshold ) ) ) THEN
IF ( FRACTIONAL_SEAICE == 0 ) THEN
xice(i,j) = 1.0
ENDIF
num_seaice_changes = num_seaice_changes + 1
if(landmask(i,j) .LT. 0.5 )tmn(i,j) = 271.4
vegcat(i,j)=isice
ivgtyp(i,j)=isice
lu_index(i,j)=isice
landmask(i,j)=1.
xland(i,j)=1.
vegfra(i,j)=0.
DO loop=1,num_veg_cat
landusef(i,loop,j)=0.
END DO
landusef(i,ivgtyp(i,j),j)=1.
tsk_old(i,j) = tsk(i,j)
isltyp(i,j) = 16
soilcat(i,j)=isltyp(i,j)
DO loop=1,num_soil_top_cat
soilctop(i,loop,j)=0
END DO
DO loop=1,num_soil_bot_cat
soilcbot(i,loop,j)=0
END DO
soilctop(i,isltyp(i,j),j)=1.
soilcbot(i,isltyp(i,j),j)=1.
total_depth = 3. ! ice is 3 m deep, num_soil_layers equispaced layers
DO loop = 1,num_soil_layers
mid_point_depth=(total_depth/num_soil_layers)/2. + &
(loop-1)*(total_depth/num_soil_layers)
tslb(i,loop,j) = ( (total_depth-mid_point_depth)*tsk(i,j) + &
mid_point_depth*tmn(i,j) ) / total_depth
END DO
DO loop=1,num_soil_layers
smois(i,loop,j) = 1.0
sh2o(i,loop,j) = 0.0
END DO
ELSE IF ( xice(i,j) .LT. xice_threshold ) THEN
xice(i,j) = 0.
END IF
END DO
END DO
IF ( num_seaice_changes .GT. 0 ) THEN
WRITE ( message , FMT='(A,I6)' ) &
'Total post number of sea ice location changes (water to land) = ', num_seaice_changes
CALL wrf_debug ( 0 , message )
END IF
CASE ( RUCLSMSCHEME )
DO j = jts , MIN(jde-1,jte)
DO i = its , MIN(ide-1,ite)
IF ( skip_middle_points_t ( ids , ide , jds , jde , i , j , em_width , hold_ups ) ) CYCLE
IF ( xice(i,j) .GT. 200.0 ) THEN
xice(i,j) = 0.
num_seaice_changes = num_seaice_changes + 1
END IF
END DO
END DO
IF ( num_seaice_changes .GT. 0 ) THEN
WRITE ( message , FMT='(A,I6)' ) &
'Total post number of sea ice locations removed (due to FLAG values) = ', &
num_seaice_changes
CALL wrf_debug ( 0 , message )
END IF
num_seaice_changes = 0
DO j = jts , MIN(jde-1,jte)
DO i = its , MIN(ide-1,ite)
IF ( skip_middle_points_t ( ids , ide , jds , jde , i , j , em_width , hold_ups ) ) CYCLE
IF ( ( ( tsk(i,j) .LT. 170 ) .OR. ( tsk(i,j) .GT. 400 ) ) .AND. &
( ( tsk_old(i,j) .GT. 170 ) .AND. ( tsk_old(i,j) .LT. 400 ) ) )THEN
tsk(i,j) = tsk_old(i,j)
END IF
IF ( ( ( tsk(i,j) .LT. 170 ) .OR. ( tsk(i,j) .GT. 400 ) ) .AND. &
( ( tsk_old(i,j) .LT. 170 ) .OR. ( tsk_old(i,j) .GT. 400 ) ) )THEN
print *,'TSK woes in seaice post, i,j=',i,j,' tsk = ',tsk(i,j), tsk_old(i,j)
CALL wrf_error_fatal ( 'TSK is unrealistic, problems for seaice post')
ELSE IF ( ( xice(i,j) .GE. xice_threshold ) .OR. &
( ( landmask(i,j) .LT. 0.5 ) .AND. ( tsk(i,j) .LT. seaice_threshold ) ) ) THEN
IF ( FRACTIONAL_SEAICE == 0 ) THEN
xice(i,j) = 1.0
ELSE
xice(i,j)=max(0.25,xice(i,j))
ENDIF
num_seaice_changes = num_seaice_changes + 1
if(landmask(i,j) .LT. 0.5 )tmn(i,j) = 271.4
vegcat(i,j)=isice
ivgtyp(i,j)=isice
lu_index(i,j)=isice
landmask(i,j)=1.
xland(i,j)=1.
vegfra(i,j)=0.
DO loop=1,num_veg_cat
landusef(i,loop,j)=0.
END DO
landusef(i,ivgtyp(i,j),j)=1.
!tgs - compute blended sea ice/water skin temperature
if(flag_sst.eq.1) then
tsk(i,j) = xice(i,j)*(min(271.4,tsk(i,j))) &
+(1-xice(i,j))*sst(i,j)
else
tsk(i,j) = xice(i,j)*(min(271.4,tsk(i,j))) &
+(1-xice(i,j))*tsk(i,j)
endif
tsk_old(i,j) = tsk(i,j)
isltyp(i,j) = 16
soilcat(i,j)=isltyp(i,j)
DO loop=1,num_soil_top_cat
soilctop(i,loop,j)=0
END DO
DO loop=1,num_soil_bot_cat
soilcbot(i,loop,j)=0
END DO
soilctop(i,isltyp(i,j),j)=1.
soilcbot(i,isltyp(i,j),j)=1.
total_depth = 3. ! ice is 3 m deep, num_soil_layers equispaced layers
tslb(i,1,j) = tsk(i,j)
tslb(i,num_soil_layers,j) = tmn(i,j)
DO loop = 2,num_soil_layers-1
mid_point_depth=(total_depth/num_soil_layers)/4. + &
(loop-2)*(total_depth/num_soil_layers)
tslb(i,loop,j) = ( (total_depth-mid_point_depth)*tsk(i,j) + &
mid_point_depth*tmn(i,j) ) / total_depth
END DO
DO loop=1,num_soil_layers
smois(i,loop,j) = 1.0
sh2o(i,loop,j) = 0.0
END DO
ELSE IF ( xice(i,j) .LT. xice_threshold ) THEN
xice(i,j) = 0.
END IF
END DO
END DO
IF ( num_seaice_changes .GT. 0 ) THEN
WRITE ( message , FMT='(A,I6)' ) &
'Total post number of sea ice location changes (water to land) = ', num_seaice_changes
CALL wrf_debug ( 0 , message )
END IF
END SELECT fix_seaice
END SUBROUTINE adjust_for_seaice_post
SUBROUTINE process_percent_cat_new ( landmask , &
landuse_frac , soil_top_cat , soil_bot_cat , &
isltyp , ivgtyp , &
num_veg_cat , num_soil_top_cat , num_soil_bot_cat , &
ids , ide , jds , jde , kds , kde , &
ims , ime , jms , jme , kms , kme , &
its , ite , jts , jte , kts , kte , &
iswater )
IMPLICIT NONE
INTEGER , INTENT(IN) :: ids , ide , jds , jde , kds , kde , &
ims , ime , jms , jme , kms , kme , &
its , ite , jts , jte , kts , kte , &
iswater
INTEGER , INTENT(IN) :: num_veg_cat , num_soil_top_cat , num_soil_bot_cat
REAL , DIMENSION(ims:ime,1:num_veg_cat,jms:jme) , INTENT(INOUT):: landuse_frac
REAL , DIMENSION(ims:ime,1:num_soil_top_cat,jms:jme) , INTENT(IN):: soil_top_cat
REAL , DIMENSION(ims:ime,1:num_soil_bot_cat,jms:jme) , INTENT(IN):: soil_bot_cat
INTEGER , DIMENSION(ims:ime,jms:jme), INTENT(OUT) :: isltyp , ivgtyp
REAL , DIMENSION(ims:ime,jms:jme) , INTENT(INOUT) :: landmask
INTEGER :: i , j , l , ll, dominant_index
REAL :: dominant_value
#if ( WRF_CHEM == 1 )
! REAL :: lwthresh = .99
REAL :: lwthresh = .50
#else
REAL :: lwthresh = .50
#endif
INTEGER , PARAMETER :: iswater_soil = 14
INTEGER :: iforce
CHARACTER (LEN=132) :: message
CHARACTER(LEN=256) :: mminlu
LOGICAL :: aggregate_lu
integer :: change_water , change_land
change_water = 0
change_land = 0
! Sanity check on the 50/50 points
DO j = jts , MIN(jde-1,jte)
DO i = its , MIN(ide-1,ite)
IF ( skip_middle_points_t ( ids , ide , jds , jde , i , j , em_width , hold_ups ) ) CYCLE
dominant_value = landuse_frac(i,iswater,j)
IF ( dominant_value .EQ. lwthresh ) THEN
DO l = 1 , num_veg_cat
IF ( l .EQ. iswater ) CYCLE
IF ( ( landuse_frac(i,l,j) .EQ. lwthresh ) .AND. ( landmask(i,j) .LT. 0.5 ) ) THEN
PRINT *,i,j,' water and category ',l,' both at 50%, landmask is ',landmask(i,j)
landuse_frac(i,l,j) = lwthresh - .01
landuse_frac(i,iswater,j) = lwthresh + 0.01
ELSE IF ( ( landuse_frac(i,l,j) .EQ. lwthresh ) .AND. ( landmask(i,j) .GT. 0.5 ) ) THEN
PRINT *,i,j,' water and category ',l,' both at 50%, landmask is ',landmask(i,j)
landuse_frac(i,l,j) = lwthresh + .01
landuse_frac(i,iswater,j) = lwthresh - 0.01
END IF
END DO
END IF
END DO
END DO
! Compute the aggregate of the vegetation/land use categories. Lump all of the grasses together,
! all of the shrubs, all of the trees, etc. Choose the correct set of available land use
! categories. Also, make sure that the user wants to actually avail themselves of aforementioned
! opportunity, as mayhaps they don't.
CALL nl_get_mminlu ( 1 , mminlu )
CALL nl_get_aggregate_lu ( 1 , aggregate_lu )
IF ( aggregate_lu ) THEN
DO j = jts , MIN(jde-1,jte)
DO i = its , MIN(ide-1,ite)
IF ( skip_middle_points_t ( ids , ide , jds , jde , i , j , em_width , hold_ups ) ) CYCLE
CALL aggregate_categories_part1 ( landuse_frac , iswater , num_veg_cat , mminlu(1:4) )
END DO
END DO
END IF
! Compute the dominant VEGETATION INDEX.
DO j = jts , MIN(jde-1,jte)
DO i = its , MIN(ide-1,ite)
IF ( skip_middle_points_t ( ids , ide , jds , jde , i , j , em_width , hold_ups ) ) CYCLE
dominant_value = landuse_frac(i,1,j)
dominant_index = 1
DO l = 2 , num_veg_cat
IF ( l .EQ. iswater ) THEN
! wait a bit
ELSE IF ( ( l .NE. iswater ) .AND. ( landuse_frac(i,l,j) .GT. dominant_value ) ) THEN
dominant_value = landuse_frac(i,l,j)
dominant_index = l
END IF
END DO
IF ( landuse_frac(i,iswater,j) .GT. lwthresh ) THEN
dominant_value = landuse_frac(i,iswater,j)
dominant_index = iswater
ELSE IF ( ( landuse_frac(i,iswater,j) .EQ. lwthresh) .AND. &
( landmask(i,j) .LT. 0.5) .AND. &
( dominant_value .EQ. lwthresh) ) THEN
dominant_value = landuse_frac(i,iswater,j)
dominant_index = iswater
ELSE IF ( ( landuse_frac(i,iswater,j) .EQ. lwthresh) .AND. &
( landmask(i,j) .GT. 0.5) .AND. &
( dominant_value .EQ. lwthresh) ) THEN
!no op
ELSE IF ( ( landuse_frac(i,iswater,j) .EQ. lwthresh ) .AND. &
( dominant_value .LT. lwthresh ) ) THEN
dominant_value = landuse_frac(i,iswater,j)
dominant_index = iswater
END IF
IF ( dominant_index .EQ. iswater ) THEN
if(landmask(i,j).gt.lwthresh) then
!print *,'changing to water at point ',i,j
!WRITE ( num_cat_count , FMT = '(I3)' ) num_veg_cat
!WRITE ( message , FMT = '('//num_cat_count//'(i3,1x))' ) ints(1:num_veg_cat)
!CALL wrf_debug(1,message)
!WRITE ( message , FMT = '('//num_cat_count//'(i3,1x))' ) nint(landuse_frac(i,:,j)*100)
!CALL wrf_debug(1,message)
change_water=change_water+1
endif
landmask(i,j) = 0
ELSE IF ( dominant_index .NE. iswater ) THEN
if(landmask(i,j).lt.lwthresh) then
!print *,'changing to land at point ',i,j
!WRITE ( num_cat_count , FMT = '(I3)' ) num_veg_cat
!WRITE ( message , FMT = '('//num_cat_count//'(i3,1x))' ) ints(1:num_veg_cat)
!CALL wrf_debug(1,message)
!WRITE ( message , FMT = '('//num_cat_count//'(i3,1x))' ) nint(landuse_frac(i,:,j)*100)
!CALL wrf_debug(1,message)
change_land=change_land+1
endif
landmask(i,j) = 1
END IF
ivgtyp(i,j) = dominant_index
END DO
END DO
! Compute the dominant SOIL TEXTURE INDEX, TOP.
iforce = 0
DO i = its , MIN(ide-1,ite)
DO j = jts , MIN(jde-1,jte)
IF ( skip_middle_points_t ( ids , ide , jds , jde , i , j , em_width , hold_ups ) ) CYCLE
dominant_value = soil_top_cat(i,1,j)
dominant_index = 1
IF ( landmask(i,j) .GT. lwthresh ) THEN
DO l = 2 , num_soil_top_cat
IF ( ( l .NE. iswater_soil ) .AND. ( soil_top_cat(i,l,j) .GT. dominant_value ) ) THEN
dominant_value = soil_top_cat(i,l,j)
dominant_index = l
END IF
END DO
IF ( dominant_value .LT. 0.01 ) THEN
iforce = iforce + 1
WRITE ( message , FMT = '(A,I4,I4)' ) &
'based on landuse, changing soil to land at point ',i,j
CALL wrf_debug(1,message)
WRITE ( num_cat_count , FMT = '(I3)' ) num_soil_top_cat
WRITE ( message , FMT = '('//num_cat_count//'(i3,1x))' ) (ints(l),l=1,num_soil_top_cat)
CALL wrf_debug(1,message)
WRITE ( message , FMT = '('//num_cat_count//'(i3,1x))' ) &
((nint(soil_top_cat(i,ints(l),j)*100)), l=1,num_soil_top_cat)
CALL wrf_debug(1,message)
dominant_index = 8
END IF
ELSE
dominant_index = iswater_soil
END IF
isltyp(i,j) = dominant_index
END DO
END DO
if(iforce.ne.0)then
WRITE(message,FMT='(A,I4,A,I6)' ) &
'forcing artificial silty clay loam at ',iforce,' points, out of ',&
(MIN(ide-1,ite)-its+1)*(MIN(jde-1,jte)-jts+1)
CALL wrf_debug(0,message)
endif
print *,'LAND CHANGE = ',change_land
print *,'WATER CHANGE = ',change_water
END SUBROUTINE process_percent_cat_new
SUBROUTINE process_soil_real ( tsk , tmn , tavgsfc, &
landmask , sst , ht, toposoil, &
st_input , sm_input , sw_input , &
st_levels_input , sm_levels_input , sw_levels_input , &
zs , dzs , flag_sm_adj, tslb , smois , sh2o , &
flag_sst , flag_tavgsfc, flag_soilhgt, &
flag_soil_layers, flag_soil_levels, &
ids , ide , jds , jde , kds , kde , &
ims , ime , jms , jme , kms , kme , &
its , ite , jts , jte , kts , kte , &
sf_surface_physics , num_soil_layers , real_data_init_type , &
num_st_levels_input , num_sm_levels_input , num_sw_levels_input , &
num_st_levels_alloc , num_sm_levels_alloc , num_sw_levels_alloc )
IMPLICIT NONE
INTEGER , INTENT(IN) :: ids , ide , jds , jde , kds , kde , &
ims , ime , jms , jme , kms , kme , &
its , ite , jts , jte , kts , kte , &
sf_surface_physics , num_soil_layers , real_data_init_type , &
num_st_levels_input , num_sm_levels_input , num_sw_levels_input , &
num_st_levels_alloc , num_sm_levels_alloc , num_sw_levels_alloc
INTEGER , INTENT(IN) :: flag_sst, flag_tavgsfc, flag_sm_adj
INTEGER , INTENT(IN) :: flag_soil_layers, flag_soil_levels, flag_soilhgt
REAL , DIMENSION(ims:ime,jms:jme) , INTENT(IN) :: landmask , sst
INTEGER , DIMENSION(1:num_st_levels_input) , INTENT(INOUT) :: st_levels_input
INTEGER , DIMENSION(1:num_sm_levels_input) , INTENT(INOUT) :: sm_levels_input
INTEGER , DIMENSION(1:num_sw_levels_input) , INTENT(INOUT) :: sw_levels_input
REAL , DIMENSION(ims:ime,1:num_st_levels_alloc,jms:jme) , INTENT(INOUT) :: st_input
REAL , DIMENSION(ims:ime,1:num_sm_levels_alloc,jms:jme) , INTENT(INOUT) :: sm_input
REAL , DIMENSION(ims:ime,1:num_sw_levels_alloc,jms:jme) , INTENT(INOUT) :: sw_input
REAL, DIMENSION(1:num_soil_layers), INTENT(OUT) :: zs,dzs
REAL , DIMENSION(ims:ime,num_soil_layers,jms:jme) , INTENT(OUT) :: tslb , smois , sh2o
REAL , DIMENSION(ims:ime,jms:jme) , INTENT(IN) :: tavgsfc, ht, toposoil
REAL , DIMENSION(ims:ime,jms:jme) , INTENT(INOUT) :: tsk, tmn
INTEGER :: i , j , k, l , dominant_index , num_soil_cat , num_veg_cat, closest_layer
REAL :: dominant_value, closest_depth, diff_cm
REAL , ALLOCATABLE , DIMENSION(:) :: depth ! Soil layer thicknesses (cm)
REAL, PARAMETER :: get_temp_closest_to = 30. ! use soil temperature closest to this depth (cm)
REAL, PARAMETER :: something_big = 1.e6 ! Initialize closest depth as something big (cm)
INTEGER :: something_far = 1000 ! Soil array index far away
CHARACTER (LEN=132) :: message
! Case statement for tmn initialization
! Need to have a reasonable default value for annual mean deeeeep soil temperature
! For sf_surface_physics = 1, we want to use close to a 30 cm value
! for the bottom level of the soil temps.
! NOTE: We are assuming that soil_layers are the same for each grid point
fix_bottom_level_for_temp : SELECT CASE ( sf_surface_physics )
CASE (SLABSCHEME)
IF ( flag_tavgsfc .EQ. 1 ) THEN
CALL wrf_debug ( 0 , 'Using average surface temperature for tmn')
DO j = jts , MIN(jde-1,jte)
DO i = its , MIN(ide-1,ite)
IF ( skip_middle_points_t ( ids , ide , jds , jde , i , j , em_width , hold_ups ) ) CYCLE
tmn(i,j) = tavgsfc(i,j)
END DO
END DO
ELSE
! Look for soil temp close to 30 cm
closest_layer = something_far
closest_depth = something_big
DO k = 1, num_st_levels_input
diff_cm = abs( st_levels_input(k) - get_temp_closest_to )
IF ( diff_cm < closest_depth ) THEN
closest_depth = diff_cm
closest_layer = k
END IF
END DO
IF ( closest_layer == something_far ) THEN
CALL wrf_debug ( 0 , 'No soil temperature data for grid%tmn near 30 cm')
CALL wrf_debug ( 0 , 'Using 1 degree static annual mean temps' )
ELSE
write(message, FMT='(A,F7.2,A,I3)')&
'Soil temperature closest to ',get_temp_closest_to, &
' at level ',st_levels_input(closest_layer)
CALL wrf_debug ( 0 , message )
DO j = jts , MIN(jde-1,jte)
DO i = its , MIN(ide-1,ite)
IF ( skip_middle_points_t ( ids , ide , jds , jde , i , j , em_width , hold_ups ) ) CYCLE
tmn(i,j) = st_input(i,closest_layer+1,j)
END DO
END DO
END IF
END IF
CASE (LSMSCHEME)
CASE (NOAHMPSCHEME)
CASE (CLMSCHEME)
CASE (RUCLSMSCHEME)
CASE (PXLSMSCHEME)
! When the input data from met_em is in layers, there is an additional level added to the beginning
! of the array to define the surface, which is why we add the extra value (closest_layer+1)
IF ( flag_tavgsfc .EQ. 1 ) THEN
CALL wrf_debug ( 0 , 'Using average surface temperature for tmn')
DO j = jts , MIN(jde-1,jte)
DO i = its , MIN(ide-1,ite)
IF ( skip_middle_points_t ( ids , ide , jds , jde , i , j , em_width , hold_ups ) ) CYCLE
tmn(i,j) = tavgsfc(i,j)
END DO
END DO
ELSE
! Look for soil temp close to 30 cm
closest_layer = num_st_levels_input+1
closest_depth = something_big
DO k = 1, num_st_levels_input
diff_cm = abs( st_levels_input(k) - get_temp_closest_to )
IF ( diff_cm < closest_depth ) THEN
closest_depth = diff_cm
closest_layer = k
END IF
END DO
IF ( closest_layer == num_st_levels_input + 1 ) THEN
CALL wrf_debug ( 0 , 'No soil temperature data for grid%tmn near 30 cm')
CALL wrf_debug ( 0 , 'Using 1 degree static annual mean temps' )
ELSE
write(message, FMT='(A,F7.2,A,I3)')&
'Soil temperature closest to ',get_temp_closest_to, &
' at level ',st_levels_input(closest_layer)
CALL wrf_debug ( 0 , message )
DO j = jts , MIN(jde-1,jte)
DO i = its , MIN(ide-1,ite)
IF ( skip_middle_points_t ( ids , ide , jds , jde , i , j , em_width , hold_ups ) ) CYCLE
tmn(i,j) = st_input(i,closest_layer+1,j)
END DO
END DO
END IF
END IF
#if 0
! Loop over layers and do a weighted mean
IF ( ALLOCATED ( depth ) ) DEALLOCATE ( depth )
ALLOCATE ( depth(num_st_levels_input) )
IF ( flag_soil_layers == 1 ) THEN
DO k = num_st_levels_input, 2, -1
depth(k) = st_levels_input(k) - st_levels_input(k-1)
END DO
depth(1) = st_levels_input(1)
ELSE IF ( flag_soil_levels == 1 ) THEN
DO k = 2, num_st_levels_input
depth(k) = st_levels_input(k) - st_levels_input(k-1)
END DO
depth(1) = 0.
END IF
DO j = jts , MIN(jde-1,jte)
DO i = its , MIN(ide-1,ite)
IF ( skip_middle_points_t ( ids , ide , jds , jde , i , j , em_width , hold_ups ) ) CYCLE
tmn(i,j) = 0.
DO k = 1, num_st_levels_input
tmn(i,j) = tmn(i,j) + depth(k) * st_input(i,k,j)
END DO
END DO
END DO
DEALLOCATE ( depth )
#endif
END SELECT fix_bottom_level_for_temp
! Adjust the various soil temperature values depending on the difference in
! elevation between the current model's elevation and the incoming data's
! orography.
adjust_soil : SELECT CASE ( sf_surface_physics )
CASE ( SLABSCHEME,LSMSCHEME,NOAHMPSCHEME,RUCLSMSCHEME,PXLSMSCHEME,CLMSCHEME,SSIBSCHEME )
CALL adjust_soil_temp_new ( tmn , sf_surface_physics , tsk , ht , &
toposoil , landmask , st_input, st_levels_input, &
flag_soilhgt , flag_tavgsfc , &
flag_soil_layers , flag_soil_levels, &
num_st_levels_input, num_st_levels_alloc, &
ids , ide , jds , jde , kds , kde , &
ims , ime , jms , jme , kms , kme , &
its , ite , jts , jte , kts , kte )
END SELECT adjust_soil
! Initialize the soil depth, and the soil temperature and moisture.
IF ( ( sf_surface_physics .EQ. SLABSCHEME ) .AND. ( num_soil_layers .GT. 1 ) ) THEN
CALL init_soil_depth_1 ( zs , dzs , num_soil_layers )
CALL init_soil_1_real ( tsk , tmn , tslb , zs , dzs , num_soil_layers , real_data_init_type , &
landmask , sst , flag_sst , &
ids , ide , jds , jde , kds , kde , &
ims , ime , jms , jme , kms , kme , &
its , ite , jts , jte , kts , kte )
ELSE IF ( ( sf_surface_physics .EQ. LSMSCHEME ) .AND. ( num_soil_layers .GT. 1 ) ) THEN
CALL init_soil_depth_2 ( zs , dzs , num_soil_layers )
CALL init_soil_2_real ( tsk , tmn , smois , sh2o , tslb , &
st_input , sm_input , sw_input , landmask , sst , &
zs , dzs , &
st_levels_input , sm_levels_input , sw_levels_input , &
num_soil_layers , num_st_levels_input , num_sm_levels_input , num_sw_levels_input , &
num_st_levels_alloc , num_sm_levels_alloc , num_sw_levels_alloc , &
flag_sst , flag_soil_layers , flag_soil_levels , &
ids , ide , jds , jde , kds , kde , &
ims , ime , jms , jme , kms , kme , &
its , ite , jts , jte , kts , kte )
ELSE IF ( ( sf_surface_physics .EQ. NOAHMPSCHEME ) .AND. ( num_soil_layers .GT. 1 ) ) THEN
CALL init_soil_depth_2 ( zs , dzs , num_soil_layers )
CALL init_soil_2_real ( tsk , tmn , smois , sh2o , tslb , &
st_input , sm_input , sw_input , landmask , sst , &
zs , dzs , &
st_levels_input , sm_levels_input , sw_levels_input , &
num_soil_layers , num_st_levels_input , num_sm_levels_input , num_sw_levels_input , &
num_st_levels_alloc , num_sm_levels_alloc , num_sw_levels_alloc , &
flag_sst , flag_soil_layers , flag_soil_levels , &
ids , ide , jds , jde , kds , kde , &
ims , ime , jms , jme , kms , kme , &
its , ite , jts , jte , kts , kte )
ELSE IF ( ( sf_surface_physics .EQ. RUCLSMSCHEME ) .AND. ( num_soil_layers .GT. 1 ) ) THEN
CALL init_soil_depth_3 ( zs , dzs , num_soil_layers )
CALL init_soil_3_real ( tsk , tmn , smois , tslb , &
st_input , sm_input , landmask , sst , &
zs , dzs , flag_sm_adj, &
st_levels_input , sm_levels_input , &
num_soil_layers , num_st_levels_input , num_sm_levels_input , &
num_st_levels_alloc , num_sm_levels_alloc , &
flag_sst , flag_soil_layers , flag_soil_levels , &
ids , ide , jds , jde , kds , kde , &
ims , ime , jms , jme , kms , kme , &
its , ite , jts , jte , kts , kte )
!CLM -- Jiming Jin 10/17/2012
ELSE IF ( ( sf_surface_physics .EQ. CLMSCHEME ) .AND. ( num_soil_layers .GT. 1 ) ) THEN
CALL init_soil_depth_4 ( zs , dzs , num_soil_layers )
CALL init_soil_4_real ( tsk , tmn , smois , sh2o , tslb , &
st_input , sm_input , sw_input , landmask , sst , &
zs , dzs , &
st_levels_input , sm_levels_input , sw_levels_input , &
num_soil_layers , num_st_levels_input , num_sm_levels_input , num_sw_levels_input , &
num_st_levels_alloc , num_sm_levels_alloc , num_sw_levels_alloc , &
flag_sst , flag_soil_layers , flag_soil_levels , &
ids , ide , jds , jde , kds , kde , &
ims , ime , jms , jme , kms , kme , &
its , ite , jts , jte , kts , kte )
ELSE IF ( ( sf_surface_physics .EQ. PXLSMSCHEME ) .AND. ( num_soil_layers .GT. 1 ) ) THEN
CALL init_soil_depth_7 ( zs , dzs , num_soil_layers )
CALL init_soil_7_real ( tsk , tmn , smois , sh2o, tslb , &
st_input , sm_input , sw_input, landmask , sst , &
zs , dzs , &
st_levels_input , sm_levels_input , sw_levels_input, &
num_soil_layers , num_st_levels_input , num_sm_levels_input , num_sw_levels_input , &
num_st_levels_alloc , num_sm_levels_alloc , num_sw_levels_alloc , &
flag_sst , flag_soil_layers , flag_soil_levels , &
ids , ide , jds , jde , kds , kde , &
ims , ime , jms , jme , kms , kme , &
its , ite , jts , jte , kts , kte )
ELSE IF ( ( sf_surface_physics .EQ. SSIBSCHEME ) .AND. ( num_soil_layers .GT. 1 ) ) THEN
CALL init_soil_depth_8 ( zs , dzs , num_soil_layers )
CALL init_soil_2_real ( tsk , tmn , smois , sh2o , tslb , &
st_input , sm_input , sw_input , landmask , sst , &
zs , dzs , &
st_levels_input , sm_levels_input , sw_levels_input , &
num_soil_layers , num_st_levels_input , num_sm_levels_input , num_sw_levels_input , &
num_st_levels_alloc , num_sm_levels_alloc , num_sw_levels_alloc , &
flag_sst , flag_soil_layers , flag_soil_levels , &
ids , ide , jds , jde , kds , kde , &
ims , ime , jms , jme , kms , kme , &
its , ite , jts , jte , kts , kte )
END IF
END SUBROUTINE process_soil_real
SUBROUTINE process_soil_ideal ( xland,xice,vegfra,snow,canwat, &
ivgtyp,isltyp,tslb,smois, &
tsk,tmn,zs,dzs, &
num_soil_layers, &
sf_surface_physics , &
ids,ide, jds,jde, kds,kde,&
ims,ime, jms,jme, kms,kme,&
its,ite, jts,jte, kts,kte )
IMPLICIT NONE
INTEGER, INTENT(IN) ::ids,ide, jds,jde, kds,kde, &
ims,ime, jms,jme, kms,kme, &
its,ite, jts,jte, kts,kte
INTEGER, INTENT(IN) :: num_soil_layers , sf_surface_physics
REAL, DIMENSION( ims:ime, num_soil_layers, jms:jme ) , INTENT(INOUT) :: smois, tslb
REAL, DIMENSION(num_soil_layers), INTENT(OUT) :: dzs,zs
REAL, DIMENSION( ims:ime, jms:jme ) , INTENT(INOUT) :: tsk, tmn
REAL, DIMENSION( ims:ime, jms:jme ) , INTENT(OUT) :: xland, snow, canwat, xice, vegfra
INTEGER, DIMENSION( ims:ime, jms:jme ) , INTENT(OUT) :: ivgtyp, isltyp
! Local variables.
INTEGER :: itf,jtf
itf=MIN(ite,ide-1)
jtf=MIN(jte,jde-1)
IF ( ( sf_surface_physics .EQ. SLABSCHEME ) .AND. ( num_soil_layers .GT. 1 ) ) THEN
CALL init_soil_depth_1 ( zs , dzs , num_soil_layers )
CALL init_soil_1_ideal(tsk,tmn,tslb,xland, &
ivgtyp,zs,dzs,num_soil_layers, &
ids,ide, jds,jde, kds,kde, &
ims,ime, jms,jme, kms,kme, &
its,ite, jts,jte, kts,kte )
ELSE IF ( ( sf_surface_physics .EQ. LSMSCHEME ) .AND. ( num_soil_layers .GT. 1 ) ) THEN
CALL init_soil_depth_2 ( zs , dzs , num_soil_layers )
CALL init_soil_2_ideal ( xland,xice,vegfra,snow,canwat, &
ivgtyp,isltyp,tslb,smois,tmn, &
num_soil_layers, &
ids,ide, jds,jde, kds,kde, &
ims,ime, jms,jme, kms,kme, &
its,ite, jts,jte, kts,kte )
ELSE IF ( ( sf_surface_physics .EQ. NOAHMPSCHEME ) .AND. ( num_soil_layers .GT. 1 ) ) THEN
CALL init_soil_depth_2 ( zs , dzs , num_soil_layers )
CALL init_soil_2_ideal ( xland,xice,vegfra,snow,canwat, &
ivgtyp,isltyp,tslb,smois,tmn, &
num_soil_layers, &
ids,ide, jds,jde, kds,kde, &
ims,ime, jms,jme, kms,kme, &
its,ite, jts,jte, kts,kte )
ELSE IF ( ( sf_surface_physics .EQ. RUCLSMSCHEME ) .AND. ( num_soil_layers .GT. 1 ) ) THEN
CALL init_soil_depth_3 ( zs , dzs , num_soil_layers )
END IF
END SUBROUTINE process_soil_ideal
SUBROUTINE adjust_soil_temp_new ( tmn , sf_surface_physics , tsk , ter , &
toposoil , landmask , st_input , st_levels_input, &
flag_toposoil , flag_tavgsfc , &
flag_soil_layers , flag_soil_levels, &
num_st_levels_input, num_st_levels_alloc, &
ids , ide , jds , jde , kds , kde , &
ims , ime , jms , jme , kms , kme , &
its , ite , jts , jte , kts , kte )
IMPLICIT NONE
INTEGER , INTENT(IN) :: ids , ide , jds , jde , kds , kde , &
ims , ime , jms , jme , kms , kme , &
its , ite , jts , jte , kts , kte
INTEGER , INTENT(IN) :: num_st_levels_input, num_st_levels_alloc
REAL , DIMENSION(ims:ime,jms:jme) , INTENT(IN) :: ter , toposoil , landmask
REAL , DIMENSION(ims:ime,jms:jme) , INTENT(INOUT) :: tmn , tsk
REAL , DIMENSION(ims:ime,1:num_st_levels_alloc,jms:jme) , INTENT(INOUT) :: st_input
INTEGER , DIMENSION(1:num_st_levels_input) , INTENT(IN) :: st_levels_input
INTEGER , INTENT(IN) :: sf_surface_physics , flag_toposoil , flag_tavgsfc
INTEGER , INTENT(IN) :: flag_soil_layers , flag_soil_levels
INTEGER :: i , j, k , st_near_sfc
REAL :: soil_elev_min_val , soil_elev_max_val , soil_elev_min_dif , soil_elev_max_dif
! Adjust the annual mean temperature as if it is based on from a sea-level elevation
! if the value used is from the actual annula mean data set. If the input field to
! be used for tmn is one of the first-guess input temp fields, need to do an adjustment
! only on the diff in topo from the model terrain and the first-guess terrain.
SELECT CASE ( sf_surface_physics )
CASE ( LSMSCHEME , NOAHMPSCHEME,CLMSCHEME )
DO j = jts , MIN(jde-1,jte)
DO i = its , MIN(ide-1,ite)
IF ( skip_middle_points_t ( ids , ide , jds , jde , i , j , em_width , hold_ups ) ) CYCLE
IF (landmask(i,j) .GT. 0.5 ) THEN
tmn(i,j) = tmn(i,j) - 0.0065 * ter(i,j)
END IF
END DO
END DO
CASE (RUCLSMSCHEME)
DO j = jts , MIN(jde-1,jte)
DO i = its , MIN(ide-1,ite)
IF ( skip_middle_points_t ( ids , ide , jds , jde , i , j , em_width , hold_ups ) ) CYCLE
IF (landmask(i,j) .GT. 0.5 ) THEN
tmn(i,j) = tmn(i,j) - 0.0065 * ter(i,j)
END IF
END DO
END DO
END SELECT
! Do we have a soil field with which to modify soil temperatures?
IF ( flag_toposoil .EQ. 1 ) THEN
DO j = jts , MIN(jde-1,jte)
DO i = its , MIN(ide-1,ite)
IF ( skip_middle_points_t ( ids , ide , jds , jde , i , j , em_width , hold_ups ) ) CYCLE
! Is the toposoil field OK, or is it a subversive soil elevation field. We can tell
! usually by looking at values. Anything less than -1000 m (lower than the Dead Sea) is