-
Notifications
You must be signed in to change notification settings - Fork 7
/
mod_process_hres_data.F90
6646 lines (5533 loc) · 264 KB
/
mod_process_hres_data.F90
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#define VERIFY_(A) IF(A/=0)THEN;PRINT *,'ERROR AT LINE ', __LINE__;STOP;ENDIF
#define ASSERT_(A) if(.not.A)then;print *,'Error:',__FILE__,__LINE__;stop;endif
!
! A Collection subroutine that helps process MODIS Albedo, GEOLAND2 LAI, and
! NGDC-HWSD-STATSGO merged soil data on their native grids 3-23-2012
! Contact: Sarith Mahanama sarith.p.mahanama@nasa.gov
! Email : sarith.p.mahanama@nasa.gov
!
! CHANGE LOG:
!
! jkolassa, reichle, May 2022:
! The bcs file "CLM4.5_veg_typs_fracs" was not used in CatchmentCNCLM45 and is no longer
! produced by make_bcs.
! Separate mappings from ESA GlobCover to CatchmentCNCLM40 and CatchmentCNCLM45 PFTs
! were initially implemented because the underlying CLM4.0 and CLM4.5 models have different
! plant functional types and distributions. Ultimately, the decision was made to use the same
! (CLM4.0-based) PFT distribution for both CatchmentCNCLM40 and CatchmentCNCLM45, and the
! obsolete mapping of ESA GlobCover data to CLM4.5 PFTs (subroutine ESA2CLM_45) was removed.
MODULE process_hres_data
use rmTinyCatchParaMod
use MAPL_SortMod
use date_time_util
use leap_year
use MAPL_ConstantsMod
use lsm_routines, ONLY: sibalb
#if defined USE_EXTERNAL_FINDLOC
use findloc_mod, only: findloc
#endif
implicit none
include 'netcdf.inc'
private
public :: soil_para_hwsd,hres_lai,hres_gswp2, merge_lai_data, grid2tile_modis6
public :: modis_alb_on_tiles_high,modis_scale_para_high,hres_lai_no_gswp
public :: histogram, create_mapping, esa2mosaic , esa2clm
public :: grid2tile_ndep_t2m_alb, CREATE_ROUT_PARA_FILE, map_country_codes, get_country_codes
public :: CLM45_fixed_parameters, CLM45_clim_parameters, gimms_clim_ndvi, grid2tile_glass, open_landparam_nc4_files
! Below structure is used to regrid high resolution data to high resolution tile raster
integer, parameter :: N_tiles_per_cell = 9
integer , parameter :: nc_esa = 129600, nr_esa = 64800
real, parameter :: pi= MAPL_PI,RADIUS=MAPL_RADIUS
integer, parameter :: N_GADM = 256 + 1, N_STATES = 50
real, parameter :: SOILDEPTH_MIN_HWSD = 1334. ! minimum soil depth for HWSD soil parameters
type :: do_regrid
integer :: NT
integer, dimension (N_tiles_per_cell) :: TID
integer, dimension (N_tiles_per_cell) :: count
end type do_regrid
type, public :: regrid_map
integer :: nc_data = 1
integer :: nr_data = 1
integer, allocatable, dimension (:,:) :: ij_index
type(do_regrid), pointer, dimension (:) :: map
end type regrid_map
contains
!
! ---------------------------------------------------------------------
!
SUBROUTINE ESA2CLM (nc, nr, gfile)
implicit none
integer , intent (in) :: nc, nr
character (*) :: gfile
integer , parameter :: N_lon_clm = 1152, N_lat_clm = 768, lsmpft = 17
integer*2, allocatable, target, dimension (:,:) :: esa_veg
integer*2, pointer , dimension (:,:) :: subset
integer , allocatable, dimension (:) :: tile_id, i_esa2clm, j_esa2clm
integer :: i,j, k,n, status, ncid, varid, maxcat, dx,dy, esa_type, tid, cid, ii, jj
real :: dx_clm, dy_clm, x_min_clm (N_lon_clm), y_min_clm (N_lat_clm), clm_fracs(lsmpft)
real :: minlon,maxlon,minlat,maxlat,tile_lat, scale, ftot
integer :: cpt1, cpt2, cst1, cst2 ! CLM-carbon types
real :: cpf1, cpf2, csf1, csf2 ! CLM-carbon fractions
DOUBLE PRECISION, allocatable, dimension (:) :: lon_esa, lat_esa
DOUBLE PRECISION :: EDGEN, EDGEE, EDGES, EDGEW
DOUBLE PRECISION, ALLOCATABLE, DIMENSION (:,:,:) :: PCT_PFT_DBL
REAL, ALLOCATABLE, DIMENSION (:,:,:) :: PCTPFT
integer, allocatable, dimension (:) :: density, loc_int
real , allocatable, dimension (:) :: loc_val
logical, allocatable, dimension (:) :: unq_mask
integer :: NBINS, NPLUS
integer, allocatable, dimension (:,:) :: clm_veg
integer :: esa_clm_veg (2)
real :: esa_clm_frac(2)
logical :: file_exists
REAL, ALLOCATABLE, DIMENSION (:,:) :: NITYP,NFVEG
! Reading CLM pft data file
!--------------------------
ALLOCATE (PCTPFT (1:N_lon_clm, 1:N_lat_clm, 1:lsmpft))
ALLOCATE (PCT_PFT_DBL (1:N_lon_clm, 1:N_lat_clm, 1:lsmpft))
status = NF_OPEN ('data/CATCH/surfdata_0.23x0.31_simyr2000_c100406.nc', NF_NOWRITE, ncid)
status = NF_GET_VARA_DOUBLE (ncid,1,(/1/),(/1/),EDGEN) ; VERIFY_(STATUS)
status = NF_GET_VARA_DOUBLE (ncid,2,(/1/),(/1/),EDGEE) ; VERIFY_(STATUS)
status = NF_GET_VARA_DOUBLE (ncid,3,(/1/),(/1/),EDGES) ; VERIFY_(STATUS)
status = NF_GET_VARA_DOUBLE (ncid,4,(/1/),(/1/),EDGEW) ; VERIFY_(STATUS)
status = NF_INQ_VARID (ncid,'PCT_PFT',VarID) ; VERIFY_(STATUS)
do k = 1, lsmpft
status = NF_GET_VARA_DOUBLE (ncid,VarID,(/1,1,k/),(/N_lon_clm, N_lat_clm, 1/),PCT_PFT_DBL(:,:,k)) ; VERIFY_(STATUS)
end do
status = NF_CLOSE(ncid)
! change type 6 to 10 for Australia only gkw: to remove CLM artificial tree line, and stay true to ESA
! ----------------------------------------------------------------------------------------------------
PCT_PFT_DBL(360:494,215:341,11) = PCT_PFT_DBL(360:494,215:341,11) + PCT_PFT_DBL(360:494,215:341, 7)
PCT_PFT_DBL(360:494,215:341, 7) = 0.
! CLM description (17) CatchmentCNCLM description (19)
! -------------------- ------------------------------
! 'BARE' 1 bare (does not have bare soil)
! 'NLEt' 2 needleleaf evergreen temperate tree 1
! 'NLEB' 3 needleleaf evergreen boreal tree 2
! 'NLDB' 4 needleleaf deciduous boreal tree 3
! 'BLET' 5 broadleaf evergreen tropical tree 4
! 'BLEt' 6 broadleaf evergreen temperate tree 5
! 'BLDT' 7 broadleaf deciduous tropical tree 6
! 'BLDt' 8 broadleaf deciduous temperate tree 7
! 'BLDB' 9 broadleaf deciduous boreal tree 8
! 'BLEtS' 10 broadleaf evergreen temperate shrub 9
! 'BLDtS' 11 broadleaf deciduous temperate shrub 10 broadleaf deciduous temperate shrub [moisture + deciduous]
! 'BLDtSm' broadleaf deciduous temperate shrub 11 broadleaf deciduous temperate shrub [moisture stress only]
! 'BLDBS' 12 broadleaf deciduous boreal shrub 12
! 'AC3G' 13 arctic c3 grass 13
! 'CC3G' 14 cool c3 grass 14 cool c3 grass [moisture + deciduous]
! 'CC3Gm' cool c3 grass 15 cool c3 grass [moisture stress only]
! 'WC4G' 15 warm c4 grass 16
! 'WC4Gm' warm c4 grass 17
! 'CROP' 16 crop 18 crop [moisture + deciduous]
! 'CROPm' crop 19 crop [moisture stress only]
! 17 water
dx_clm = 360./N_lon_clm
dy_clm = 180./N_lat_clm
do i = 1, N_lon_clm
x_min_clm (i) = (i-1)*dx_clm + EDGEW - 180.
end do
do i = 1, N_lat_clm
y_min_clm (i) = (i-1)*dy_clm + EDGES
end do
PCTPFT (1:N_lon_clm/2 ,:,:) = REAL (PCT_PFT_DBL(N_lon_clm/2 + 1: N_lon_clm,:,:))
PCTPFT (N_lon_clm/2 + 1: N_lon_clm,:,:) = REAL (PCT_PFT_DBL(1:N_lon_clm/2 ,:,:))
DEALLOCATE (PCT_PFT_DBL)
! Find primary and secondary types in the CLM data file
! -----------------------------------------------------
! allocate (clm_veg (1:N_lon_clm,1:N_lat_clm,1:2))
!
! do j = 1, N_lat_clm
! do i = 1, N_lon_clm
! if(maxval(PCT_PFT(i,j,:)) > 0.) then
! clm_fracs = PCT_PFT(i,j,:)
! if (maxval (clm_fracs) == 100.) then
! clm_veg(i,j,:) = maxloc (clm_fracs)
! else
! clm_veg(i,j,0) = maxloc (clm_fracs)
! clm_fracs (clm_veg(i,j,0)) = 0.
! clm_veg(i,j,1) = maxloc (clm_fracs)
! endif
! else
! clm_veg(i,j,:) = 17
! endif
! end do
! end do
! Reading ESA vegetation types
!-----------------------------
allocate (esa_veg (1:nc_esa, 1: nr_esa))
allocate (lon_esa (1:nc_esa))
allocate (lat_esa (1:nr_esa))
status = NF_OPEN ('data/CATCH/ESA_GlobalCover.nc', NF_NOWRITE, ncid)
if(status /=0) then
PRINT *, NF_STRERROR(STATUS)
print *, 'Problem with NF_OPEN','ESA_GlobalCover.nc'
stop
endif
status = NF_GET_VARA_DOUBLE (ncid,1,(/1/),(/nr_esa/),lat_esa)
status = NF_GET_VARA_DOUBLE (ncid,2,(/1/),(/nc_esa/),lon_esa)
do j = 1,nr_esa
status = NF_GET_VARA_INT2 (ncid,3,(/1,j/),(/nc_esa,1/),esa_veg(:,j))
if(status /=0) then
PRINT *, NF_STRERROR(STATUS)
print *, 'Problem with NF_GET ESA_GlobalCover.nc : ', STATUS
stop
endif
end do
status = NF_CLOSE(ncid)
! Find I,J of overlying CLM grid cells for each ESA pixel
!--------------------------------------------------------
allocate (i_esa2clm (1:nc_esa))
allocate (j_esa2clm (1:nr_esa))
do i = 1, N_lon_clm
where ((real(lon_esa) >= x_min_clm(i)).and.(real(lon_esa) < (x_min_clm(i) + dx_clm))) i_esa2clm= i
end do
i_esa2clm(129545:nc_esa) = 1
do j = 1, N_lat_clm
where ((real(lat_esa) >= y_min_clm(j)).and.(real(lat_esa) < (y_min_clm(j) + dy_clm))) j_esa2clm= j
end do
!
! Reading number of tiles
! -----------------------
open (10, file = 'clsm/catchment.def', form = 'formatted', status = 'old', &
action = 'read')
read (10, *) maxcat
close (10, status = 'keep')
!
! Loop through tile_id raster
! ___________________________
allocate (tile_id (1:nc ))
allocate (clm_veg (1:maxcat,1:lsmpft))
clm_veg = 0.
dx = nc_esa / nc
dy = nr_esa / nr
open (10,file=trim(gfile)//'.rst',status='old',action='read', &
form='unformatted',convert='little_endian')
do j=1,nr
! read a row
read(10)tile_id(:)
do i = 1,nc
ii = i_esa2clm ((i-1)*dx + dx/2)
jj = j_esa2clm ((j-1)*dy + dy/2)
if((tile_id (i) >= 1).and.(tile_id(i) <= maxcat)) then
if (associated (subset)) NULLIFY (subset)
subset => esa_veg((i-1)*dx +1 :i*dx, (j-1)*dy +1:j*dy)
NPLUS = count(subset >= 1 .and. subset <= 230)
if(NPLUS > 0) then
allocate (loc_int (1:NPLUS))
allocate (unq_mask(1:NPLUS))
loc_int = pack(subset,mask = (subset >= 1 .and. subset <= 230))
call MAPL_Sort (loc_int)
unq_mask = .true.
do n = 2,NPLUS
unq_mask(n) = .not.(loc_int(n) == loc_int(n-1))
end do
NBINS = count(unq_mask)
allocate(loc_val (1:NBINS))
allocate(density (1:NBINS))
loc_val = 1.*pack(loc_int,mask =unq_mask)
call histogram (size(subset,1)*size(subset,2), NBINS, density, loc_val, real(subset))
do k = 1, nbins
if (density (k) > 0) then
esa_type = int (loc_val(k))
! if (esa_type == 10) clm_veg (tile_id(i), 17) = 1.* density(k) ! lakes inland water
if (esa_type == 11) clm_veg (tile_id(i), 16) = clm_veg (tile_id(i), 16) + 1.* density(k) ! ESA type 11: Post-flooding or irrigated croplands
if (esa_type == 14) clm_veg (tile_id(i), 16) = clm_veg (tile_id(i), 16) + 1.* density(k) ! ESA type 14: Rainfed croplands
if (esa_type == 20) clm_veg (tile_id(i), 16) = clm_veg (tile_id(i), 16) + 1.* density(k) ! ESA type 20: Mosaic Cropland (50-70%) / Vegetation (grassland, shrubland, forest) (20-50%)
if (esa_type == 190) clm_veg (tile_id(i), 16) = clm_veg (tile_id(i), 16) + 1.* density(k) ! ESA type 190: Artificial surfaces and associated areas (urban areas >50%)
! if (esa_type == 200) clm_veg (tile_id(i), 11) = clm_veg (tile_id(i), 11) + 1.* density(k) ! ESA type 200: Bare areas
! if (esa_type == 210) clm_veg (tile_id(i), 17) = clm_veg (tile_id(i), 17) + 1.* density(k) ! ocean
! if (esa_type == 220) clm_veg (tile_id(i), 17) = clm_veg (tile_id(i), 17) + 1.* density(k) ! ice
! gkw: bare soil excluded! only considering vegetated land
! -----------------------------------------------------------------------------------------------------------------------------------------
if (esa_type == 30) then
! ESA type 30: Mosaic Vegetation (grassland, shrubland, forest) (50-70%) / Cropland (20-50%)
clm_veg (tile_id(i), 16) = clm_veg (tile_id(i), 16) + 0.5* density(k)
if(sum(PCTPFT(ii,jj,2:15)) > 0.) then
do n = 2, 15
clm_veg (tile_id(i), n) = clm_veg (tile_id(i), n) + 0.5* density(k)*(PCTPFT(ii,jj,n))/sum(PCTPFT(ii,jj,2:15))
enddo
else
clm_veg (tile_id(i), 16) = clm_veg (tile_id(i), 16) + 1.0* density(k)
endif
endif
! -----------------------------------------------------------------------------------------------------------------------------------------
if (esa_type == 40) then
! ESA type 40: Closed to open (>15%) broadleaved evergreen and/or semi-deciduous forest (>5m)
if(sum(PCTPFT(ii,jj,5:6)) > 0.) then
do n = 5, 6
clm_veg (tile_id(i), n) = clm_veg (tile_id(i), n) + 1.*density(k)*(PCTPFT(ii,jj,n))/sum(PCTPFT(ii,jj,5:6))
enddo
else
if(abs(y_min_clm(jj) + 0.5*dy_clm) < 23.5) then
clm_veg (tile_id(i), 5) = clm_veg (tile_id(i), 5) + 1.0* density(k)
else
clm_veg (tile_id(i), 6) = clm_veg (tile_id(i), 6) + 1.0* density(k)
endif
endif
endif
! -----------------------------------------------------------------------------------------------------------------------------------------
if ((esa_type == 50) .or. (esa_type == 60)) then
! ESA type 50: Closed (>40%) broadleaved deciduous forest (>5m)
! ESA type 60: Open (15-40%) broadleaved deciduous forest (>5m)
if(sum(PCTPFT(ii,jj,7:9)) > 0.) then
do n = 7, 9
clm_veg (tile_id(i), n) = clm_veg (tile_id(i), n) + density(k)*(PCTPFT(ii,jj,n))/sum(PCTPFT(ii,jj,7:9))
enddo
else
if(abs(y_min_clm(jj) + 0.5*dy_clm) < 23.5) then
clm_veg (tile_id(i), 7) = clm_veg (tile_id(i), 7) + 1.0* density(k)
else
if(abs(y_min_clm(jj) + 0.5*dy_clm) < 60.) clm_veg (tile_id(i), 8) = clm_veg (tile_id(i), 8) + 1.0* density(k)
if(abs(y_min_clm(jj) + 0.5*dy_clm) >= 60.) clm_veg (tile_id(i), 9) = clm_veg (tile_id(i), 9) + 1.0* density(k)
end if
end if
endif
! -----------------------------------------------------------------------------------------------------------------------------------------
if (esa_type == 70) then
! ESA type 70: Closed (>40%) needleleaved evergreen forest (>5m)
if(sum(PCTPFT(ii,jj,2:3)) > 0.) then
do n = 2, 3
clm_veg (tile_id(i), n) = clm_veg (tile_id(i), n) + density(k)*(PCTPFT(ii,jj,n))/sum(PCTPFT(ii,jj,2:3))
enddo
else
if(abs(y_min_clm(jj) + 0.5*dy_clm) < 60.) then
clm_veg (tile_id(i), 2) = clm_veg (tile_id(i), 2) + 1.0* density(k)
else
clm_veg (tile_id(i), 3) = clm_veg (tile_id(i), 3) + 1.0* density(k)
end if
end if
endif
! -----------------------------------------------------------------------------------------------------------------------------------------
if (esa_type == 90) then
!ESA type 90: Open (15-40%) needleleaved deciduous or evergreen forest (>5m)
if(sum(PCTPFT(ii,jj,2:4)) > 0.) then
do n = 2, 4
clm_veg (tile_id(i), n) = clm_veg (tile_id(i), n) + 1.*density(k)*(PCTPFT(ii,jj,n))/sum(PCTPFT(ii,jj,2:4))
enddo
else
if(abs(y_min_clm(jj) + 0.5*dy_clm) < 60.) then
clm_veg (tile_id(i), 2) = clm_veg (tile_id(i), 2) + 1.0* density(k)
else
clm_veg (tile_id(i), 3) = clm_veg (tile_id(i), 3) + 1.0* density(k)
end if
end if
endif
! -----------------------------------------------------------------------------------------------------------------------------------------
if (esa_type == 100) then
! ESA type 100: Closed to open (>15%) mixed broadleaved and needleleaved forest (>5m)
if((sum(PCTPFT(ii,jj,2:4)) + sum(PCTPFT(ii,jj,7:9))) > 0.) then
do n = 2, 9
if((n /= 5) .and. (n /= 6)) clm_veg (tile_id(i), n) = clm_veg (tile_id(i), n) + density(k)*(PCTPFT(ii,jj,n))/(sum(PCTPFT(ii,jj,2:4)) + sum(PCTPFT(ii,jj,7:9)))
enddo
else
if(abs(y_min_clm(jj) + 0.5*dy_clm) < 23.5) then
clm_veg (tile_id(i), 7) = clm_veg (tile_id(i), 7) + 0.5* density(k)
clm_veg (tile_id(i), 2) = clm_veg (tile_id(i), 2) + 0.5* density(k)
elseif (abs(y_min_clm(jj) + 0.5*dy_clm) < 60.) then
clm_veg (tile_id(i), 8) = clm_veg (tile_id(i), 8) + 0.5* density(k)
clm_veg (tile_id(i), 2) = clm_veg (tile_id(i), 2) + 0.5* density(k)
else
clm_veg (tile_id(i), 9) = clm_veg (tile_id(i), 9) + 0.5* density(k)
clm_veg (tile_id(i), 3) = clm_veg (tile_id(i), 3) + 0.5* density(k)
end if
end if
endif
! -----------------------------------------------------------------------------------------------------------------------------------------
if (esa_type == 110) then
! ESA type 110: Mosaic Forest/Shrubland (50-70%) / Grassland (20-50%)
if(sum(PCTPFT(ii,jj,7:12)) > 0.) then
do n = 7, 12
clm_veg (tile_id(i), n) = clm_veg (tile_id(i), n) + 0.6*density(k)*(PCTPFT(ii,jj,n))/sum(PCTPFT(ii,jj,7:12))
enddo
else
if(abs(y_min_clm(jj) + 0.5*dy_clm) < 23.5) then
clm_veg (tile_id(i), 7) = clm_veg (tile_id(i), 7) + 0.3* density(k)
clm_veg (tile_id(i), 11) = clm_veg (tile_id(i), 11) + 0.3* density(k)
else if (abs(y_min_clm(jj) + 0.5*dy_clm) < 60.) then
clm_veg (tile_id(i), 8) = clm_veg (tile_id(i), 8) + 0.3* density(k)
clm_veg (tile_id(i), 11) = clm_veg (tile_id(i), 11) + 0.3* density(k)
else
clm_veg (tile_id(i), 9) = clm_veg (tile_id(i), 9) + 0.3* density(k)
clm_veg (tile_id(i), 12) = clm_veg (tile_id(i), 12) + 0.3* density(k)
end if
end if
if(sum(PCTPFT(ii,jj,13:15)) > 0.) then
do n =13, 15
clm_veg (tile_id(i), n) = clm_veg (tile_id(i), n) + 0.4*density(k)*(PCTPFT(ii,jj,n))/sum(PCTPFT(ii,jj,13:15))
enddo
else
if(abs(y_min_clm(jj) + 0.5*dy_clm) < 30.) then
clm_veg (tile_id(i), 15) = clm_veg (tile_id(i), 15) + 0.4* density(k)
else if (abs(y_min_clm(jj) + 0.5*dy_clm) < 55.) then
clm_veg (tile_id(i), 14) = clm_veg (tile_id(i), 14) + 0.4* density(k)
else
clm_veg (tile_id(i), 13) = clm_veg (tile_id(i), 13) + 0.4* density(k)
end if
end if
endif
! -----------------------------------------------------------------------------------------------------------------------------------------
if (esa_type == 120) then
! ESA type 120: Mosaic Grassland (50-70%) / Forest/Shrubland (20-50%)
if(sum(PCTPFT(ii,jj,7:12)) > 0.) then
do n = 7, 12
clm_veg (tile_id(i), n) = clm_veg (tile_id(i), n) + 0.4*density(k)*(PCTPFT(ii,jj,n))/sum(PCTPFT(ii,jj,7:12))
enddo
else
if(abs(y_min_clm(jj) + 0.5*dy_clm) < 23.5) then
clm_veg (tile_id(i), 7) = clm_veg (tile_id(i), 7) + 0.2* density(k)
clm_veg (tile_id(i), 11) = clm_veg (tile_id(i), 11) + 0.2* density(k)
else if (abs(y_min_clm(jj) + 0.5*dy_clm) < 60.) then
clm_veg (tile_id(i), 8) = clm_veg (tile_id(i), 8) + 0.2* density(k)
clm_veg (tile_id(i), 11) = clm_veg (tile_id(i), 11) + 0.2* density(k)
else
clm_veg (tile_id(i), 9) = clm_veg (tile_id(i), 9) + 0.2* density(k)
clm_veg (tile_id(i), 12) = clm_veg (tile_id(i), 12) + 0.2* density(k)
end if
end if
if(sum(PCTPFT(ii,jj,13:15)) > 0.) then
do n =13, 15
clm_veg (tile_id(i), n) = clm_veg (tile_id(i), n) + 0.6*density(k)*(PCTPFT(ii,jj,n))/sum(PCTPFT(ii,jj,13:15))
enddo
else
if(abs(y_min_clm(jj) + 0.5*dy_clm) < 30.) then
clm_veg (tile_id(i), 15) = clm_veg (tile_id(i), 15) + 0.6* density(k)
else if (abs(y_min_clm(jj) + 0.5*dy_clm) < 55.) then
clm_veg (tile_id(i), 14) = clm_veg (tile_id(i), 14) + 0.6* density(k)
else
clm_veg (tile_id(i), 13) = clm_veg (tile_id(i), 13) + 0.6* density(k)
end if
end if
endif
! -----------------------------------------------------------------------------------------------------------------------------------------
if (esa_type == 130) then
! Closed to open (>15%) shrubland (<5m)
if(sum(PCTPFT(ii,jj,10:12)) > 0.) then
do n = 10,12
clm_veg (tile_id(i), n) = clm_veg (tile_id(i), n) + 1.*density(k)*(PCTPFT(ii,jj,n))/sum(PCTPFT(ii,jj,10:12))
enddo
else
if(abs(y_min_clm(jj) + 0.5*dy_clm) < 60.) then
clm_veg (tile_id(i), 11) = clm_veg (tile_id(i), 11) + 1.0* density(k)
else
clm_veg (tile_id(i), 12) = clm_veg (tile_id(i), 12) + 1.0* density(k)
end if
end if
endif
! -----------------------------------------------------------------------------------------------------------------------------------------
if (esa_type == 140) then
! ESA type 140: Closed to open (>15%) grassland
if(sum(PCTPFT(ii,jj,13:15)) > 0.) then
do n = 13,15
clm_veg (tile_id(i), n) = clm_veg (tile_id(i), n) + 1.*density(k)*(PCTPFT(ii,jj,n))/sum(PCTPFT(ii,jj,13:15))
enddo
else
if(abs(y_min_clm(jj) + 0.5*dy_clm) < 30.) then
clm_veg (tile_id(i), 15) = clm_veg (tile_id(i), 15) + 1.0* density(k)
else if (abs(y_min_clm(jj) + 0.5*dy_clm) < 55.) then
clm_veg (tile_id(i), 14) = clm_veg (tile_id(i), 14) + 1.0* density(k)
else
clm_veg (tile_id(i), 13) = clm_veg (tile_id(i), 13) + 1.0* density(k)
end if
end if
end if
! -----------------------------------------------------------------------------------------------------------------------------------------
if (esa_type == 150) then
! ESA type 150: Sparse (<15%) vegetation (woody vegetation, shrubs, grassland)
if(sum(PCTPFT(ii,jj,10:15)) > 0.) then
do n = 10, 15
clm_veg (tile_id(i), n) = clm_veg (tile_id(i), n) + 1.0*density(k)*(PCTPFT(ii,jj,n))/sum(PCTPFT(ii,jj,10:15))
enddo
else
if(abs(y_min_clm(jj) + 0.5*dy_clm) < 30.) then
clm_veg (tile_id(i), 14) = clm_veg (tile_id(i), 14) + 0.5* density(k)
clm_veg (tile_id(i), 11) = clm_veg (tile_id(i), 11) + 0.5* density(k)
else if (abs(y_min_clm(jj) + 0.5*dy_clm) < 55.) then
clm_veg (tile_id(i), 14) = clm_veg (tile_id(i), 14) + 0.5* density(k)
clm_veg (tile_id(i), 11) = clm_veg (tile_id(i), 11) + 0.5* density(k)
else
clm_veg (tile_id(i), 13) = clm_veg (tile_id(i), 13) + 0.5* density(k)
clm_veg (tile_id(i), 12) = clm_veg (tile_id(i), 12) + 0.5* density(k)
end if
end if
endif
! -----------------------------------------------------------------------------------------------------------------------------------------
if((esa_type == 160) .or. (esa_type == 170)) then
! ESA type 160: Closed (>40%) broadleaved forest regularly flooded - Fresh water ! ESA type 170: Closed (>40%) broadleaved semi-deciduous and/or evergreen forest regularly flooded
if(sum(PCTPFT(ii,jj,5:9)) > 0.) then
do n = 5,9
clm_veg (tile_id(i), n) = clm_veg (tile_id(i), n) + 1.*density(k)*(PCTPFT(ii,jj,n))/sum(PCTPFT(ii,jj,5:9))
enddo
else
if(abs(y_min_clm(jj) + 0.5*dy_clm) < 23.5) then
clm_veg (tile_id(i), 5) = clm_veg (tile_id(i), 5) + 1.0* density(k)
else if (abs(y_min_clm(jj) + 0.5*dy_clm) < 60.) then
clm_veg (tile_id(i), 8) = clm_veg (tile_id(i), 8) + 1.0* density(k)
else
clm_veg (tile_id(i), 9) = clm_veg (tile_id(i), 9) + 1.0* density(k)
end if
end if
endif
! -----------------------------------------------------------------------------------------------------------------------------------------
if (esa_type == 180) then
! ESA type 180: Closed to open (>15%) vegetation (grassland, shrubland, woody vegetation) on regularly flooded or waterlogged soil - Fresh, brackish or saline water
if(sum(PCTPFT(ii,jj,10:15)) > 0.) then
do n = 10,15
clm_veg (tile_id(i), n) = clm_veg (tile_id(i), n) + 1.*density(k)*(PCTPFT(ii,jj,n))/sum(PCTPFT(ii,jj,10:15))
enddo
else
if(abs(y_min_clm(jj) + 0.5*dy_clm) < 30.) then
clm_veg (tile_id(i), 15) = clm_veg (tile_id(i), 15) + 1.0* density(k)
else if (abs(y_min_clm(jj) + 0.5*dy_clm) < 55.) then
clm_veg (tile_id(i), 14) = clm_veg (tile_id(i), 14) + 1.0* density(k)
else
clm_veg (tile_id(i), 13) = clm_veg (tile_id(i), 13) + 1.0* density(k)
end if
end if
endif
endif
enddo
deallocate (loc_int,unq_mask,loc_val,density)
endif
end if
enddo
end do
deallocate (tile_id, PCTPFT,esa_veg,lon_esa,lat_esa,i_esa2clm,j_esa2clm)
close (10,status='keep')
!
! Now create CLM-carbon_veg_fracs file
! ------------------------------------
open (10,file='clsm/CLM_veg_typs_fracs', &
form='formatted',status='unknown')
open (11, file = 'clsm/catchment.def', form = 'formatted', status = 'old', &
action = 'read')
read (11, *) maxcat
inquire(file='clsm/catchcn_params.nc4', exist=file_exists)
if(file_exists) then
status = NF_OPEN ('clsm/catchcn_params.nc4', NF_WRITE, ncid) ; VERIFY_(STATUS)
allocate (NITYP (1:MAXCAT, 1:4))
allocate (NFVEG (1:MAXCAT, 1:4))
endif
do k = 1, maxcat
read (11,'(i10,i8,5(2x,f9.4))') tid,cid,minlon,maxlon,minlat,maxlat
tile_lat = (minlat + maxlat)/2.
scale = (ABS (tile_lat) - 32.)/10.
scale = min (max(scale,0.),1.)
esa_clm_veg = 0
esa_clm_frac= 0.
clm_fracs = clm_veg (k,:)
if (sum (clm_fracs) == 0.) then ! gkw: no vegetated land found; set to BLDtS
esa_clm_veg (1) = 11 ! broadleaf deciduous shrub
esa_clm_frac(1) = 100.
else
esa_clm_veg (1) = maxloc(clm_fracs,1)
esa_clm_frac(1) = maxval(clm_fracs)
endif
clm_fracs (esa_clm_veg (1)) = 0.
if (sum (clm_fracs) == 0.) then ! gkw: no vegetated secondary type found, set to primary with zero fraction
esa_clm_veg (2) = esa_clm_veg (1)
esa_clm_frac(1) = 100.
esa_clm_frac(2) = 0.
else
esa_clm_veg (2) = maxloc(clm_fracs,1)
esa_clm_frac(1) = 100.*clm_veg (k,esa_clm_veg (1))/(clm_veg (k,esa_clm_veg (1)) + clm_veg (k,esa_clm_veg (2)))
esa_clm_frac(2) = 100. - esa_clm_frac(1)
end if
! Now splitting CLM types for CNCLM model
! --------------------------------------------
! CLM types 2- 10,12,13 are not being split.
! .............................................
if ((esa_clm_veg (1) >= 2).and.(esa_clm_veg (1) <= 10)) then
CPT1 = esa_clm_veg (1) - 1
CPT2 = esa_clm_veg (1) - 1
CPF1 = esa_clm_frac(1)
CPF2 = 0.
endif
if ((esa_clm_veg (2) >= 2).and.(esa_clm_veg (2) <= 10)) then
CST1 = esa_clm_veg (2) - 1
CST2 = esa_clm_veg (2) - 1
CSF1 = esa_clm_frac(2)
CSF2 = 0.
endif
! .............................................
if ((esa_clm_veg (1) >= 12).and.(esa_clm_veg (1) <= 13)) then
CPT1 = esa_clm_veg (1)
CPT2 = esa_clm_veg (1)
CPF1 = esa_clm_frac(1)
CPF2 = 0.
endif
if ((esa_clm_veg (2) >= 12).and.(esa_clm_veg (2) <= 13)) then
CST1 = esa_clm_veg (2)
CST2 = esa_clm_veg (2)
CSF1 = esa_clm_frac(2)
CSF2 = 0.
endif
! Now splitting
! .............
if (esa_clm_veg (1) == 11) then
CPT1 = 10
CPT2 = 11
CPF1 = esa_clm_frac(1) * scale
CPF2 = esa_clm_frac(1) * (1. - scale)
endif
if (esa_clm_veg (2) == 11) then
CST1 = 10
CST2 = 11
CSF1 = esa_clm_frac(2) * scale
CSF2 = esa_clm_frac(2) * (1. - scale)
endif
! .............
if (esa_clm_veg (1) == 14) then
CPT1 = 14
CPT2 = 15
CPF1 = esa_clm_frac(1) * scale
CPF2 = esa_clm_frac(1) * (1. - scale)
endif
if (esa_clm_veg (2) == 14) then
CST1 = 14
CST2 = 15
CSF1 = esa_clm_frac(2) * scale
CSF2 = esa_clm_frac(2) * (1. - scale)
endif
! .............
if (esa_clm_veg (1) == 15) then
CPT1 = 16
CPT2 = 17
CPF1 = esa_clm_frac(1) * scale
CPF2 = esa_clm_frac(1) * (1. - scale)
endif
if (esa_clm_veg (2) == 15) then
CST1 = 16
CST2 = 17
CSF1 = esa_clm_frac(2) * scale
CSF2 = esa_clm_frac(2) * (1. - scale)
endif
! .............
if (esa_clm_veg (1) == 16) then
CPT1 = 18
CPT2 = 19
CPF1 = esa_clm_frac(1) * scale
CPF2 = esa_clm_frac(1) * (1. - scale)
endif
if (esa_clm_veg (2) == 16) then
CST1 = 18
CST2 = 19
CSF1 = esa_clm_frac(2) * scale
CSF2 = esa_clm_frac(2) * (1. - scale)
endif
! fractions must sum to 1
! -----------------------
ftot = cpf1 + cpf2 + csf1 + csf2
if(ftot /= 100.) then
cpf1 = 100. * cpf1 / ftot
cpf2 = 100. * cpf2 / ftot
csf1 = 100. * csf1 / ftot
csf2 = 100. * csf2 / ftot
endif
write (10,'(2I10,4I3,4f7.2,2I3,2f7.2)') &
tid,cid,cpt1, cpt2, cst1, cst2, cpf1, cpf2, csf1, csf2, &
esa_clm_veg (1), esa_clm_veg (2), esa_clm_frac(1), esa_clm_frac(2)
if (allocated (NITYP)) NITYP (k, :) = (/REAL(cpt1), REAL(cpt2), REAL(cst1), REAL(cst2)/)
if (allocated (NFVEG)) NFVEG (k, :) = (/cpf1, cpf2, csf1, csf2/)
end do
if(file_exists) then
status = NF_PUT_VARA_REAL(NCID,NC_VarID(NCID,'ITY' ) ,(/1,1/),(/maxcat,1/), NITYP (:, 1)) ; VERIFY_(STATUS)
status = NF_PUT_VARA_REAL(NCID,NC_VarID(NCID,'ITY' ) ,(/1,2/),(/maxcat,1/), NITYP (:, 2)) ; VERIFY_(STATUS)
status = NF_PUT_VARA_REAL(NCID,NC_VarID(NCID,'ITY' ) ,(/1,3/),(/maxcat,1/), NITYP (:, 3)) ; VERIFY_(STATUS)
status = NF_PUT_VARA_REAL(NCID,NC_VarID(NCID,'ITY' ) ,(/1,4/),(/maxcat,1/), NITYP (:, 4)) ; VERIFY_(STATUS)
status = NF_PUT_VARA_REAL(NCID,NC_VarID(NCID,'FVG' ) ,(/1,1/),(/maxcat,1/), NFVEG (:, 1)) ; VERIFY_(STATUS)
status = NF_PUT_VARA_REAL(NCID,NC_VarID(NCID,'FVG' ) ,(/1,2/),(/maxcat,1/), NFVEG (:, 2)) ; VERIFY_(STATUS)
status = NF_PUT_VARA_REAL(NCID,NC_VarID(NCID,'FVG' ) ,(/1,3/),(/maxcat,1/), NFVEG (:, 3)) ; VERIFY_(STATUS)
status = NF_PUT_VARA_REAL(NCID,NC_VarID(NCID,'FVG' ) ,(/1,4/),(/maxcat,1/), NFVEG (:, 4)) ; VERIFY_(STATUS)
DEALLOCATE (NITYP, NFVEG)
STATUS = NF_CLOSE (NCID) ; VERIFY_(STATUS)
endif
close (10, status = 'keep')
close (11, status = 'keep')
END SUBROUTINE ESA2CLM
!
! ---------------------------------------------------------------------
!
SUBROUTINE ESA2MOSAIC (nc, nr, gfile)
implicit none
integer , intent (in) :: nc, nr
character (*) :: gfile
integer , parameter :: nc_esa = 129600, nr_esa = 64800
integer*2, allocatable, target, dimension (:,:) :: esa_veg
integer*2, pointer , dimension (:,:) :: subset
integer , allocatable, dimension (:) :: tile_id, ityp
integer :: i,j, k, status, ncid, maxcat, dx,dy, esa_type, tid, cid
integer :: mos1, mos2
real :: mfrac, sfrac, tfrac, tem (6)
integer, allocatable, dimension (:) :: density, loc_int
real , allocatable, dimension (:) :: loc_val
logical, allocatable, dimension (:) :: unq_mask
real , allocatable :: veg (:,:)
integer :: NBINS, NPLUS
real, pointer, dimension (:) :: z2, z0
real, dimension (6) :: VGZ2 = (/35.0, 20.0, 17.0, 0.6, 0.5, 0.6/) ! Dorman and Sellers (1989)
logical :: file_exists
! Reading ESA vegetation types
!-----------------------------
allocate (esa_veg (1:nc_esa, 1: nr_esa))
status = NF_OPEN ('data/CATCH/ESA_GlobalCover.nc', NF_NOWRITE, ncid)
if(status /=0) then
PRINT *, NF_STRERROR(STATUS)
print *, 'Problem with NF_OPEN','ESA_GlobalCover.nc'
stop
endif
do j = 1,nr_esa
status = NF_GET_VARA_INT2 (ncid,3,(/1,j/),(/nc_esa,1/),esa_veg(:,j))
if(status /=0) then
PRINT *, NF_STRERROR(STATUS)
print *, 'Problem with NF_GET ESA_GlobalCover.nc : ', STATUS
stop
endif
end do
status = NF_CLOSE(ncid)
!
! Reading number of tiles
! -----------------------
open (10, file = 'clsm/catchment.def', form = 'formatted', status = 'old', &
action = 'read')
read (10, *) maxcat
close (10, status = 'keep')
!
! Loop through tile_id raster
! ___________________________
allocate (tile_id (1:nc))
allocate(veg(1:maxcat,1:6))
veg = 0.
dx = nc_esa / nc
dy = nr_esa / nr
open (10,file=trim(gfile)//'.rst',status='old',action='read', &
form='unformatted',convert='little_endian')
do j=1,nr
! read a row
read(10)tile_id(:)
do i = 1,nc
if((tile_id (i) >= 1).and.(tile_id(i) <= maxcat)) then
if (associated (subset)) NULLIFY (subset)
subset => esa_veg((i-1)*dx +1 :i*dx, (j-1)*dy +1:j*dy)
NPLUS = count(subset >= 1 .and. subset <= 230)
if(NPLUS > 0) then
allocate (loc_int (1:NPLUS))
allocate (unq_mask(1:NPLUS))
loc_int = pack(subset,mask = (subset >= 1 .and. subset <= 230))
call MAPL_Sort (loc_int)
unq_mask = .true.
do k = 2,NPLUS
unq_mask(k) = .not.(loc_int(k) == loc_int(k-1))
end do
NBINS = count(unq_mask)
allocate(loc_val (1:NBINS))
allocate(density (1:NBINS))
loc_val = 1.*pack(loc_int,mask =unq_mask)
call histogram (size(subset,1)*size(subset,2), NBINS, density, loc_val, real(subset))
do k = 1, nbins
if (density (k) > 0) then
esa_type = int (loc_val(k))
! if (esa_type == 10) veg (tile_id(i),10) = 1.* density (k) ; lakes inland water
if (esa_type == 10) veg (tile_id(i), 4) = veg (tile_id(i), 4) + 1.* density (k) ! inconsistent mask/veg
if (esa_type == 11) veg (tile_id(i), 4) = veg (tile_id(i), 4) + 1.* density (k)
if (esa_type == 14) veg (tile_id(i), 4) = veg (tile_id(i), 4) + 1.* density (k)
if (esa_type == 20) veg (tile_id(i), 4) = veg (tile_id(i), 4) + 1.* density (k)
if (esa_type == 30) veg (tile_id(i), 4) = veg (tile_id(i), 4) + 1.* density (k)
if (esa_type == 40) veg (tile_id(i), 1) = veg (tile_id(i), 1) + 1.* density (k)
if (esa_type == 50) veg (tile_id(i), 2) = veg (tile_id(i), 2) + 1.* density (k)
if (esa_type == 60) veg (tile_id(i), 2) = veg (tile_id(i), 2) + 1.* density (k)
if (esa_type == 70) veg (tile_id(i), 3) = veg (tile_id(i), 3) + 1.* density (k)
if (esa_type == 90) veg (tile_id(i), 3) = veg (tile_id(i), 3) + 1.* density (k)
if (esa_type == 100) veg (tile_id(i), 2) = veg (tile_id(i), 2) + 0.5* density (k)
if (esa_type == 100) veg (tile_id(i), 3) = veg (tile_id(i), 3) + 0.5* density (k)
if (esa_type == 110) veg (tile_id(i), 2) = veg (tile_id(i), 2) + 0.3* density (k)
if (esa_type == 110) veg (tile_id(i), 5) = veg (tile_id(i), 5) + 0.3* density (k)
if (esa_type == 110) veg (tile_id(i), 4) = veg (tile_id(i), 4) + 0.4* density (k)
if (esa_type == 120) veg (tile_id(i), 2) = veg (tile_id(i), 2) + 0.2* density (k)
if (esa_type == 120) veg (tile_id(i), 5) = veg (tile_id(i), 5) + 0.2* density (k)
if (esa_type == 120) veg (tile_id(i), 4) = veg (tile_id(i), 4) + 0.6* density (k)
if (esa_type == 130) veg (tile_id(i), 5) = veg (tile_id(i), 5) + 1.* density (k)
if (esa_type == 140) veg (tile_id(i), 4) = veg (tile_id(i), 4) + 1.* density (k)
if((j > NINT(real(nr)*(40./180.))).and.(j < NINT(real(nr)*(140./180.)))) then
if (esa_type == 150) veg (tile_id(i),5) = veg (tile_id(i),5) + 0.5* density (k)
if (esa_type == 150) veg (tile_id(i),4) = veg (tile_id(i),4) + 0.5* density (k)
else
if (esa_type == 150) veg (tile_id(i),6) = veg (tile_id(i),6) + 0.5* density (k)
if (esa_type == 150) veg (tile_id(i),4) = veg (tile_id(i),4) + 0.5* density (k)
end if
if((j > NINT(real(nr)*(70./180.))).and.(j < NINT(real(nr)*(110./180.)))) then
if (esa_type == 160) veg (tile_id(i), 1) = veg (tile_id(i), 1) + 1.* density (k)
else
if (esa_type == 160) veg (tile_id(i), 2) = veg (tile_id(i), 2) + 1.* density (k)
end if
if (esa_type == 170) veg (tile_id(i), 1) = veg (tile_id(i), 1) + 1.* density (k)
if (esa_type == 180) veg (tile_id(i), 4) = veg (tile_id(i), 4) + 1.* density (k)
if (esa_type == 190) veg (tile_id(i), 4) = veg (tile_id(i), 4) + 1.* density (k)
if (esa_type == 200) veg (tile_id(i), 5) = veg (tile_id(i), 5) + 1.* density (k)
if (esa_type == 210) veg (tile_id(i), 4) = veg (tile_id(i), 4) + 1.* density (k) ! inconsistent mask/veg
if (esa_type == 220) veg (tile_id(i), 4) = veg (tile_id(i), 4) + 1.* density (k) ! inconsistent mask/veg
! if (esa_type == 210) veg (tile_id(i),11) = 1.* density (k) ; ocean
! if (esa_type == 220) veg (tile_id(i), 9) = 1.* density (k) ; ice
endif
enddo
deallocate (loc_int,unq_mask,loc_val,density)
endif
endif
end do
end do
deallocate (tile_id)
close (10,status='keep')
! Canopy height and ASCAT roughness length
call ascat_r0 (nc,nr,gfile, z0)
if(jpl_height) then
call jpl_canoph (nc,nr,gfile, z2)
else
allocate (z2(1:maxcat))
endif
!
! Now create mosaic_veg_fracs file
! --------------------------------
allocate (ityp (1:maxcat))
open (10,file='clsm/mosaic_veg_typs_fracs', &
form='formatted',status='unknown')
open (11, file = 'clsm/catchment.def', form = 'formatted', status = 'old', &
action = 'read')
read (11, *) maxcat
do k = 1, maxcat
read (11,'(i10,i8,5(2x,f9.4))') tid,cid
tem = 0.
tem(1:6)=veg (k,1:6)
if(sum(tem).gt.0)then
mfrac = -10.
sfrac = -10.
mos1 = 100
mos2 = 100
do i = 1,6
if(mfrac.le.tem(i))then
sfrac = mfrac
mos2 = mos1
mfrac = tem(i)
mos1 = i
elseif(sfrac.le.tem(i)) then
if(tem(i).lt.mfrac)then