-
Notifications
You must be signed in to change notification settings - Fork 7
/
mimics_inout_CN.f90
2740 lines (2140 loc) · 123 KB
/
mimics_inout_CN.f90
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
!--------------------------------------------------------------------------------
! FILE: mimics_inout_CN.f90
!
! Purpose:
! Input/Output subroutines for the MIMICS model
!
! SUBROUTINE mimics_readbiome - read pftlookup_mimics.csv (mimics parameters)
! SUBROUTINE mimics_init - initialize mimics pools. If initcasa >= 1, read .csv file
! SUBROUTINE mimics_poolfluxout - write mimics C pools to restart .csv output file
! SUBROUTINE mimics_poolfluxout_CN - write mimics C&N pools to restart .csv output file
! SUBROUTINE WritePoolFluxNcFile_mimics_annual - write annual mimics pools and fluxes to netCDF file
! SUBROUTINE WritePoolFluxNcFile_mimics_daily - write daily mimics pools and fluxes to netCDF file
! SUBROUTINE WritePointMIMICS - write daily mimics pools and other quantities to a .csv file daily
!
! Contact: Melannie Hartman
! melannie@ucar.edu
!
! History:
! 1/5/2015 - Created
! 11/7/2017 - Echo contents of parameter and restart files
! 12/3/2018 - Add inputs to SOMp to daily and annual NetCDF files,
! and to daily point output file
! 6/23/2019 - Add subroutine mimics_poolfluxout_CN
! 11/30/2019 - Add MIMICS N variables to netCDF output
!--------------------------------------------------------------------------------
SUBROUTINE mimics_readbiome(fname_mimicsbiome, mp, mvtype)
use casadimension
use define_types
use casavariable
use mimicsdimension
use mimicsparam
use mimicsvariable
implicit none
! Function arguments
character(len=100), INTENT(IN) :: fname_mimicsbiome
integer, INTENT(IN) :: mp ! number of grid points
integer, INTENT(IN) :: mvtype ! number of vegetation (biome) types
! Local variables
integer :: ioErr
integer :: npt, nP, nv, nv1
real(r_2) :: Pscalar, kmod_val(6)
character(len=200) :: buffer
open(101,file=fname_mimicsbiome)
!Skip past vegetation descriptions
read(101,*)
do nv=1,mvtype
read(101,*)
end do
! Fixed parameters
! TO DO - check input file variable name to assure corrert placement of parameter values
write(*,*)
write(*,*) "Reading MIMICS parameters from file ", trim(fname_mimicsbiome), "..."
read(101,*) buffer
write(*,*) trim(buffer)
read(101,*) mimicsbiome%Vslope(R1)
read(101,*) mimicsbiome%Vslope(R2)
read(101,*) mimicsbiome%Vslope(R3)
read(101,*) mimicsbiome%Vslope(K1)
read(101,*) mimicsbiome%Vslope(K2)
read(101,*) mimicsbiome%Vslope(K3)
write(*,'(2x,a13,2x,f10.6)') 'Vslope(R1)=', mimicsbiome%Vslope(R1)
write(*,'(2x,a13,2x,f10.6)') 'Vslope(R2)=', mimicsbiome%Vslope(R2)
write(*,'(2x,a13,2x,f10.6)') 'Vslope(R3)=', mimicsbiome%Vslope(R3)
write(*,'(2x,a13,2x,f10.6)') 'Vslope(K1)=', mimicsbiome%Vslope(K1)
write(*,'(2x,a13,2x,f10.6)') 'Vslope(K2)=', mimicsbiome%Vslope(K2)
write(*,'(2x,a13,2x,f10.6)') 'Vslope(K3)=', mimicsbiome%Vslope(K3)
read(101,*) mimicsbiome%Vint(R1)
read(101,*) mimicsbiome%Vint(R2)
read(101,*) mimicsbiome%Vint(R3)
read(101,*) mimicsbiome%Vint(K1)
read(101,*) mimicsbiome%Vint(K2)
read(101,*) mimicsbiome%Vint(K3)
write(*,'(2x,a13,2x,f10.6)') 'Vint(R1)=', mimicsbiome%Vint(R1)
write(*,'(2x,a13,2x,f10.6)') 'Vint(R2)=', mimicsbiome%Vint(R2)
write(*,'(2x,a13,2x,f10.6)') 'Vint(R3)=', mimicsbiome%Vint(R3)
write(*,'(2x,a13,2x,f10.6)') 'Vint(K1)=', mimicsbiome%Vint(K1)
write(*,'(2x,a13,2x,f10.6)') 'Vint(K2)=', mimicsbiome%Vint(K2)
write(*,'(2x,a13,2x,f10.6)') 'Vint(K3)=', mimicsbiome%Vint(K3)
read(101,*) mimicsbiome%av(R1)
read(101,*) mimicsbiome%av(R2)
read(101,*) mimicsbiome%av(R3)
read(101,*) mimicsbiome%av(K1)
read(101,*) mimicsbiome%av(K2)
read(101,*) mimicsbiome%av(K3)
write(*,'(2x,a13,2x,f12.8)') 'av(R1)=', mimicsbiome%av(R1)
write(*,'(2x,a13,2x,f12.8)') 'av(R2)=', mimicsbiome%av(R2)
write(*,'(2x,a13,2x,f12.8)') 'av(R3)=', mimicsbiome%av(R3)
write(*,'(2x,a13,2x,f12.8)') 'av(K1)=', mimicsbiome%av(K1)
write(*,'(2x,a13,2x,f12.8)') 'av(K2)=', mimicsbiome%av(K2)
write(*,'(2x,a13,2x,f12.8)') 'av(K3)=', mimicsbiome%av(K3)
read(101,*) mimicsbiome%Kslope(R1)
read(101,*) mimicsbiome%Kslope(R2)
read(101,*) mimicsbiome%Kslope(R3)
read(101,*) mimicsbiome%Kslope(K1)
read(101,*) mimicsbiome%Kslope(K2)
read(101,*) mimicsbiome%Kslope(K3)
write(*,'(2x,a13,2x,f10.6)') 'Kslope(R1)=', mimicsbiome%Kslope(R1)
write(*,'(2x,a13,2x,f10.6)') 'Kslope(R2)=', mimicsbiome%Kslope(R2)
write(*,'(2x,a13,2x,f10.6)') 'Kslope(R3)=', mimicsbiome%Kslope(R3)
write(*,'(2x,a13,2x,f10.6)') 'Kslope(K1)=', mimicsbiome%Kslope(K1)
write(*,'(2x,a13,2x,f10.6)') 'Kslope(K2)=', mimicsbiome%Kslope(K2)
write(*,'(2x,a13,2x,f10.6)') 'Kslope(K3)=', mimicsbiome%Kslope(K3)
read(101,*) mimicsbiome%Kint(R1)
read(101,*) mimicsbiome%Kint(R2)
read(101,*) mimicsbiome%Kint(R3)
read(101,*) mimicsbiome%Kint(K1)
read(101,*) mimicsbiome%Kint(K2)
read(101,*) mimicsbiome%Kint(K3)
write(*,'(2x,a13,2x,f10.6)') 'Kint(R1)=', mimicsbiome%Kint(R1)
write(*,'(2x,a13,2x,f10.6)') 'Kint(R2)=', mimicsbiome%Kint(R2)
write(*,'(2x,a13,2x,f10.6)') 'Kint(R3)=', mimicsbiome%Kint(R3)
write(*,'(2x,a13,2x,f10.6)') 'Kint(K1)=', mimicsbiome%Kint(K1)
write(*,'(2x,a13,2x,f10.6)') 'Kint(K2)=', mimicsbiome%Kint(K2)
write(*,'(2x,a13,2x,f10.6)') 'Kint(K3)=', mimicsbiome%Kint(K3)
read(101,*) mimicsbiome%ak(R1)
read(101,*) mimicsbiome%ak(R2)
read(101,*) mimicsbiome%ak(R3)
read(101,*) mimicsbiome%ak(K1)
read(101,*) mimicsbiome%ak(K2)
read(101,*) mimicsbiome%ak(K3)
write(*,'(2x,a13,2x,f10.6)') 'ak(R1)=', mimicsbiome%ak(R1)
write(*,'(2x,a13,2x,f10.6)') 'ak(R2)=', mimicsbiome%ak(R2)
write(*,'(2x,a13,2x,f10.6)') 'ak(R3)=', mimicsbiome%ak(R3)
write(*,'(2x,a13,2x,f10.6)') 'ak(K1)=', mimicsbiome%ak(K1)
write(*,'(2x,a13,2x,f10.6)') 'ak(K2)=', mimicsbiome%ak(K2)
write(*,'(2x,a13,2x,f10.6)') 'ak(K3)=', mimicsbiome%ak(K3)
read(101,*) mimicsbiome%Vmod(R1)
read(101,*) mimicsbiome%Vmod(R2)
read(101,*) mimicsbiome%Vmod(R3)
read(101,*) mimicsbiome%Vmod(K1)
read(101,*) mimicsbiome%Vmod(K2)
read(101,*) mimicsbiome%Vmod(K3)
write(*,'(2x,a13,2x,f10.6)') 'Vmod(R1)=', mimicsbiome%Vmod(R1)
write(*,'(2x,a13,2x,f10.6)') 'Vmod(R2)=', mimicsbiome%Vmod(R2)
write(*,'(2x,a13,2x,f10.6)') 'Vmod(R3)=', mimicsbiome%Vmod(R3)
write(*,'(2x,a13,2x,f10.6)') 'Vmod(K1)=', mimicsbiome%Vmod(K1)
write(*,'(2x,a13,2x,f10.6)') 'Vmod(K2)=', mimicsbiome%Vmod(K2)
write(*,'(2x,a13,2x,f10.6)') 'Vmod(K3)=', mimicsbiome%Vmod(K3)
read(101,*) kmod_val(R1)
read(101,*) kmod_val(R2)
read(101,*) kmod_val(R3)
read(101,*) kmod_val(K1)
read(101,*) kmod_val(K2)
read(101,*) kmod_val(K3)
write(*,'(2x,a13,2x,f10.6)') 'kmod_val(R1)=', kmod_val(R1)
write(*,'(2x,a13,2x,f10.6)') 'kmod_val(R2)=', kmod_val(R2)
write(*,'(2x,a13,2x,f10.6)') 'kmod_val(R3)=', kmod_val(R3)
write(*,'(2x,a13,2x,f10.6)') 'kmod_val(K1)=', kmod_val(K1)
write(*,'(2x,a13,2x,f10.6)') 'kmod_val(K2)=', kmod_val(K2)
write(*,'(2x,a13,2x,f10.6)') 'kmod_val(K3)=', kmod_val(K3)
read(101,*) mimicsbiome%KO(1)
read(101,*) mimicsbiome%KO(2)
write(*,'(2x,a13,2x,f10.6)') 'KO(1)=', mimicsbiome%KO(1)
write(*,'(2x,a13,2x,f10.6)') 'KO(2)=', mimicsbiome%KO(2)
read(101,*) mimicsbiome%MGE(1)
read(101,*) mimicsbiome%MGE(2)
read(101,*) mimicsbiome%MGE(3)
read(101,*) mimicsbiome%MGE(4)
write(*,'(2x,a13,2x,f10.6)') 'MGE(1)=', mimicsbiome%MGE(1)
write(*,'(2x,a13,2x,f10.6)') 'MGE(2)=', mimicsbiome%MGE(2)
write(*,'(2x,a13,2x,f10.6)') 'MGE(3)=', mimicsbiome%MGE(3)
write(*,'(2x,a13,2x,f10.6)') 'MGE(4)=', mimicsbiome%MGE(4)
read(101,*) mimicsbiome%tau_r(1)
read(101,*) mimicsbiome%tau_r(2)
write(*,'(2x,a13,2x,f10.6)') 'tau_r(1)=', mimicsbiome%tau_r(1)
write(*,'(2x,a13,2x,f10.6)') 'tau_r(2)=', mimicsbiome%tau_r(2)
read(101,*) mimicsbiome%tau_k(1)
read(101,*) mimicsbiome%tau_k(2)
write(*,'(2x,a13,2x,f10.6)') 'tau_k(1)=', mimicsbiome%tau_k(1)
write(*,'(2x,a13,2x,f10.6)') 'tau_k(2)=', mimicsbiome%tau_k(2)
read(101,*) mimicsbiome%tauModDenom
read(101,*) mimicsbiome%tauMod_MIN
read(101,*) mimicsbiome%tauMod_MAX
write(*,'(2x,a13,2x,f10.6)') 'tauModDenom=', mimicsbiome%tauModDenom
write(*,'(2x,a13,2x,f10.6)') 'tauMod_MIN=', mimicsbiome%tauMod_MIN
write(*,'(2x,a13,2x,f10.6)') 'tauMod_MAX=', mimicsbiome%tauMod_MAX
read(101,*) mimicsbiome%fPHYS_r(1)
read(101,*) mimicsbiome%fPHYS_r(2)
write(*,'(2x,a13,2x,f10.6)') 'fPHYS_r(1)=', mimicsbiome%fPHYS_r(1)
write(*,'(2x,a13,2x,f10.6)') 'fPHYS_r(2)=', mimicsbiome%fPHYS_r(2)
read(101,*) mimicsbiome%fPHYS_K(1)
read(101,*) mimicsbiome%fPHYS_K(2)
write(*,'(2x,a13,2x,f10.6)') 'fPHYS_K(1)=', mimicsbiome%fPHYS_K(1)
write(*,'(2x,a13,2x,f10.6)') 'fPHYS_K(2)=', mimicsbiome%fPHYS_K(2)
read(101,*) mimicsbiome%fCHEM_r(1)
read(101,*) mimicsbiome%fCHEM_r(2)
read(101,*) mimicsbiome%fCHEM_r(3)
write(*,'(2x,a13,2x,f10.6)') 'fCHEM_r(1)=', mimicsbiome%fCHEM_r(1)
write(*,'(2x,a13,2x,f10.6)') 'fCHEM_r(2)=', mimicsbiome%fCHEM_r(2)
write(*,'(2x,a13,2x,f10.6)') 'fCHEM_r(3)=', mimicsbiome%fCHEM_r(3)
read(101,*) mimicsbiome%fCHEM_K(1)
read(101,*) mimicsbiome%fCHEM_K(2)
read(101,*) mimicsbiome%fCHEM_K(3)
write(*,'(2x,a13,2x,f10.6)') 'fCHEM_K(1)=', mimicsbiome%fCHEM_K(1)
write(*,'(2x,a13,2x,f10.6)') 'fCHEM_K(2)=', mimicsbiome%fCHEM_K(2)
write(*,'(2x,a13,2x,f10.6)') 'fCHEM_K(3)=', mimicsbiome%fCHEM_K(3)
read(101,*) mimicsbiome%fSOM_p(1)
read(101,*) mimicsbiome%fSOM_p(2)
write(*,'(2x,a13,2x,f10.6)') 'fSOM_p(1)=', mimicsbiome%fSOM_p(1)
write(*,'(2x,a13,2x,f10.6)') 'fSOM_p(2)=', mimicsbiome%fSOM_p(2)
read(101,*) mimicsbiome%phys_scalar(1)
read(101,*) mimicsbiome%phys_scalar(2)
write(*,'(2x,a15,2x,f10.6)') 'phys_scalar(1)=', mimicsbiome%phys_scalar(1)
write(*,'(2x,a15,2x,f10.6)') 'phys_scalar(2)=', mimicsbiome%phys_scalar(2)
read(101,*) mimicsbiome%Fi(metbc)
read(101,*) mimicsbiome%Fi(struc)
write(*,'(2x,a13,2x,f10.6)') 'Fi(metbc)=', mimicsbiome%Fi(metbc)
write(*,'(2x,a13,2x,f10.6)') 'Fi(struc)=',mimicsbiome%Fi(struc)
read(101,*) mimicsbiome%fmet_p(1)
read(101,*) mimicsbiome%fmet_p(2)
read(101,*) mimicsbiome%fmet_p(3)
write(*,'(2x,a13,2x,f10.6)') 'fmet_p(1)=', mimicsbiome%fmet_p(1)
write(*,'(2x,a13,2x,f10.6)') 'fmet_p(2)=', mimicsbiome%fmet_p(2)
write(*,'(2x,a13,2x,f10.6)') 'fmet_p(3)=', mimicsbiome%fmet_p(3)
!! ----------------------------------------------------------------------
!! Additional N-related parameters for MIMICS-CN. -mdh 6/21/2019
read(101,*) mimicsbiome%densDep
read(101,*)
read(101,*)
!read(101,*) mimicsbiome%fracNimport_r
!read(101,*) mimicsbiome%fracNimport_k
write(*,'(2x,a8,2x,f10.6)') 'densDep=', mimicsbiome%densDep
!write(*,'(2x,a14,2x,f10.6)') 'fracNimport_r=', mimicsbiome%fracNimport_r
!write(*,'(2x,a14,2x,f10.6)') 'fracNimport_k=', mimicsbiome%fracNimport_k
read(101,*) mimicsbiome%NUE(1)
read(101,*) mimicsbiome%NUE(2)
read(101,*) mimicsbiome%NUE(3)
read(101,*) mimicsbiome%NUE(4)
write(*,'(2x,a7,2x,f10.6)') 'NUE(1)=', mimicsbiome%NUE(1)
write(*,'(2x,a7,2x,f10.6)') 'NUE(2)=', mimicsbiome%NUE(2)
write(*,'(2x,a7,2x,f10.6)') 'NUE(3)=', mimicsbiome%NUE(3)
write(*,'(2x,a7,2x,f10.6)') 'NUE(4)=', mimicsbiome%NUE(4)
read(101,*) mimicsbiome%CNr
read(101,*) mimicsbiome%CNk
read(101,*) mimicsbiome%fracDINavailMIC
read(101,*) mimicsbiome%cnModNum
write(*,'(2x,a5,2x,f10.6)') 'CNr=', mimicsbiome%CNr
write(*,'(2x,a5,2x,f10.6)') 'CNk=', mimicsbiome%CNk
write(*,'(2x,a16,2x,f10.6)') 'fracDINavailMIC=', mimicsbiome%fracDINavailMIC
write(*,'(2x,a13,2x,f10.6)') 'cnModNum=', mimicsbiome%cnModNum
!! ----------------------------------------------------------------------
!Biome-specific parameters
read(101,*) buffer
write(*,*) trim(buffer)
read(101,*) buffer
write(*,*) trim(buffer)
do nv=1,mvtype
read(101,*) nv1,mimicsbiome%depth(nv)
write(*,'(2x,i2,2x,f7.2)') nv1,mimicsbiome%depth(nv)
if (mimicsbiome%depth(nv) <= 0.0) then
write(*,*) 'Error in ', trim(filename_mimicsbiome),' (depth <= 0): depth(',nv,')=',mimicsbiome%depth(nv)
STOP
endif
end do
! The fWFunction switch determines what water function to use (CASACNP=1,MIMICS=2,CORPSE=3)
! If this parameter was not inserted (unexpected EOF), then default to MIMICS f(W)=1.0
read(101,*,IOSTAT=ioErr) mimicsbiome%fWFunction
if (ioErr .eq. 0) THEN
write(*,'(2x,a11,2x,i2)') 'fWFunction=', mimicsbiome%fWFunction
if (mimicsbiome%fWFunction .eq. CASACNP) then
write(*,*) ' Using f(W) function from CASACNP...'
elseif (mimicsbiome%fWFunction .eq. CORPSE) then
write(*,*) ' Using f(W) function from CORPSE...'
else
write(*,*) ' Using f(W)=1.0 from MIMICS...'
mimicsbiome%fWFunction = MIMICS
endif
else
! Error or EOF. Default to MIMICS f(W)=1.0
write(*,*) ' Using f(W)=1.0 from MIMICS...'
mimicsbiome%fWFunction = MIMICS
endif
close(101)
write(*,*) "Done reading MIMICS parameters from file ", trim(fname_mimicsbiome), "..."
! Calculate cell-specific parameters
do npt=1,mp
! Use site-level value for Pscalar (-mdh 4/20/2015)
! Pscalar = 1.0 / (2.0 * exp(-2.0*SQRT(soil%clay(npt))))
! Use global value for Pscalar (-mdh 4/6/2015)
! Pscalar = 1.0 / (0.8 * exp(-3.0*SQRT(soil%clay(npt))))
! Updated based on Will's (-mdh 6/1/2015)
! Pscalar = 1.0 / (2.0 * exp(-3.0*SQRT(soil%clay(npt))))
Pscalar = mimicsbiome%phys_scalar(1) * exp(mimicsbiome%phys_scalar(2)*SQRT(soil%clay(npt)))
mimicsbiome%Kmod(npt,R1) = kmod_val(R1) ! modifies Km[r1] for fluxes from LITm to MICr
mimicsbiome%Kmod(npt,R2) = kmod_val(R2) ! modifies Km[r2] for fluxes from LITs to MICr
mimicsbiome%Kmod(npt,R3) = kmod_val(R3) * Pscalar ! modifies Km[r3] for fluxes from SOMa to MICr
mimicsbiome%Kmod(npt,K1) = kmod_val(K1) ! modifies Km[k1] for fluxes from LITm to MICk
mimicsbiome%Kmod(npt,K2) = kmod_val(K2) ! modifies Km[k2] for fluxes from LITs MICk
mimicsbiome%Kmod(npt,K3) = kmod_val(K3) * Pscalar ! modifies Km[k3] for fluxes from SOMa to MICk
do nP=1,mplant
! fmet = fraction of plant residue transferred to metabolic litter (0.0 - 1.0)
! It is computed from the biome-specific lignin:N ratio for plant pool nP
! (g lignin / g N) = (g lignin / g C) / (g N / g C)
! When icycle > 1, mimicsbiome%ligninNratio will be reset in mimics_coeffplant.
! The value of mimicsbiome%ligninNratio below is used for C-only simulations. -mdh 1/20/2020
mimicsbiome%ligninNratio(npt,nP) = casabiome%fracLigninPlant(veg%iveg(npt), nP) &
/ max(0.001,casapool%ratioNCplant(npt,nP))
! write(*,*) 'lignin:N = ', mimicsbiome%ligninNratio(npt,nP)
end do
! mimicsbiome%desorb(npt) - desorbsion rate from SOMp to SOMa (hr-1)
! mimicsbiome%desorb(npt) = 1.5 * 0.00001 * exp(-1.5 * soil%clay(npt))
mimicsbiome%desorb(npt) = mimicsbiome%fSOM_p(1) * exp(mimicsbiome%fSOM_p(2) * soil%clay(npt))
end do
END SUBROUTINE mimics_readbiome
!--------------------------------------------------------------------------------
SUBROUTINE mimics_init(filename_mimicsipool,mp,ms,mst)
! Initialize mimics litter, microbe, and SOM pools
! This subroutine should be called after subroutine init_casa (not in place of)
! and after subroutine mimics_readbiome.
use casadimension
use casaparm
use casavariable
use mimicsdimension
use mimicsparam
use mimicsvariable
implicit none
!Subroutine arguments
character(len=100), INTENT(IN) :: filename_mimicsipool
integer, INTENT(IN) :: mp, ms, mst
!integer, INTENT(IN) :: icycle ! 1 = C only, 2 = C+N
!Local Variables
integer :: np,npt,npz,nl,ns,nland,nlandz
real(r_2) :: nyearz,ivtz,latz,lonz,areacellz
character(len=200) :: buffer
mimicspool%LITm(:) = 0.0
mimicspool%LITs(:) = 0.0
mimicspool%MICr(:) = 0.0
mimicspool%MICk(:) = 0.0
mimicspool%SOMa(:) = 0.0
mimicspool%SOMc(:) = 0.0
mimicspool%SOMp(:) = 0.0
mimicspool%LITmN(:) = 0.0
mimicspool%LITsN(:) = 0.0
mimicspool%MICrN(:) = 0.0
mimicspool%MICkN(:) = 0.0
mimicspool%SOMaN(:) = 0.0
mimicspool%SOMcN(:) = 0.0
mimicspool%SOMpN(:) = 0.0
mimicsflux%ClitInput(:,:) = 0.0
mimicsflux%Chresp(:) = 0.0
mimicsflux%CSOMpInput(:) = 0.0
mimicsflux%Overflow_r(:) = 0.0
mimicsflux%Overflow_k(:) = 0.0
mimicsflux%NlitInput(:,:) = 0.0
WHERE(casamet%iveg2 /= icewater)
mimicspool%LITm(:) = 1.0
mimicspool%LITs(:) = 1.0
mimicspool%MICr(:) = 0.015
mimicspool%MICk(:) = 0.025
mimicspool%SOMa(:) = 1.0
mimicspool%SOMc(:) = 1.0
mimicspool%SOMp(:) = 1.0
mimicspool%LITmN(:) = mimicspool%LITm(:)/10.0
mimicspool%LITsN(:) = mimicspool%LITs(:)/10.0
mimicspool%MICrN(:) = mimicspool%MICr(:)/mimicsbiome%CNr
mimicspool%MICkN(:) = mimicspool%MICk(:)/mimicsbiome%CNk
mimicspool%SOMaN(:) = mimicspool%SOMa(:)/10.0
mimicspool%SOMcN(:) = mimicspool%SOMc(:)/10.0
mimicspool%SOMpN(:) = mimicspool%SOMp(:)/10.0
END WHERE
!If not a spinup run (initcasa .ne. 0) read initial pool values from file,
!overwriting the C&N pool assignments above.
if (initcasa >= 1) then
write(*,*)
write(*,*) "Reading initial MIMICS pool file: ", trim(filename_mimicsipool), "..."
open(105,file=filename_mimicsipool)
read(105,*) buffer ! Skip past header line
!write(*,*) trim(buffer)
do npt =1, mp
if (icycle == 1) then
read(105,*) nyearz,npz,ivtz,latz,lonz,areacellz, &
mimicspool%LITm(npt), mimicspool%LITs(npt), &
mimicspool%MICr(npt), mimicspool%MICk(npt), &
mimicspool%SOMa(npt), mimicspool%SOMc(npt), mimicspool%SOMp(npt)
else
read(105,*) nyearz,npz,ivtz,latz,lonz,areacellz, &
mimicspool%LITm(npt), mimicspool%LITs(npt), &
mimicspool%MICr(npt), mimicspool%MICk(npt), &
mimicspool%SOMa(npt), mimicspool%SOMc(npt), mimicspool%SOMp(npt), &
mimicspool%LITmN(npt), mimicspool%LITsN(npt), &
mimicspool%MICrN(npt), mimicspool%MICkN(npt), &
mimicspool%SOMaN(npt), mimicspool%SOMcN(npt), mimicspool%SOMpN(npt)
endif
! write(*,123) nyearz,npz,ivtz,latz,lonz,areacellz, &
! mimicspool%LITm(npt), mimicspool%LITs(npt), &
! mimicspool%MICr(npt), mimicspool%MICk(npt), &
! mimicspool%SOMa(npt), mimicspool%SOMc(npt), mimicspool%SOMp(npt), &
! mimicspool%LITmN(npt), mimicspool%LITsN(npt), &
! mimicspool%MICrN(npt), mimicspool%MICkN(npt), &
! mimicspool%SOMaN(npt), mimicspool%SOMcN(npt), mimicspool%SOMpN(npt)
!
! 123 format(f4.0,',',i4,',',f4.0,',',17(f8.4,','))
!ATTENTION: Check npz, ivtz, latz, lonz, areacellz against values read by casa_init
!TO DO
end do
close(105)
print *, "Done reading initial MIMICS pool file: ", filename_mimicsipool, "..."
endif
! check for negative pool sizes
mimicspool%LITm = max(0.0, mimicspool%LITm)
mimicspool%LITs = max(0.0, mimicspool%LITs)
mimicspool%MICr = max(0.0, mimicspool%MICr)
mimicspool%MICk = max(0.0, mimicspool%MICk)
mimicspool%SOMa = max(0.0, mimicspool%SOMa)
mimicspool%SOMc = max(0.0, mimicspool%SOMc)
mimicspool%SOMp = max(0.0, mimicspool%SOMp)
mimicspool%LITmN = max(0.0, mimicspool%LITmN)
mimicspool%LITsN = max(0.0, mimicspool%LITsN)
mimicspool%MICrN = max(0.0, mimicspool%MICrN)
mimicspool%MICkN = max(0.0, mimicspool%MICkN)
mimicspool%SOMaN = max(0.0, mimicspool%SOMaN)
mimicspool%SOMcN = max(0.0, mimicspool%SOMcN)
mimicspool%SOMpN = max(0.0, mimicspool%SOMpN)
! ATTENTION: need corresponding assignments for MIMICS?
! casabal%clitterlast = casapool%clitter
! casabal%csoillast = casapool%csoil
! casabal%sumcbal = 0.0
! ATTENTION: check if these assignments will create divide by zero errors
! I commented these assignments out to see if it makes a difference in
! the output. (-MDH 2/16/2015)
! casapool%Csoil(:,:) = 0.0
! casapool%Clitter(:,:) = 0.0
! casapool%Nsoil(:,:) = 0.0
! casapool%Nlitter(:,:) = 0.0
! casapool%Nsoilmin(:) = 0.0
! casapool%Psoil(:,:) = 0.0
! casapool%Plitter(:,:) = 0.0
END SUBROUTINE mimics_init
!--------------------------------------------------------------------------------
SUBROUTINE mimics_poolfluxout(filename_mimicsepool,mp,iYrCnt,myear,writeToRestartCSVfile)
use define_types
! use casadimension
use casaparm
use casavariable
use mimicsdimension
use mimicsparam
use mimicsvariable
implicit none
!Subroutine arguments
character(len=100), INTENT(IN) :: filename_mimicsepool
integer, INTENT(IN) :: mp, iYrCnt, myear
logical, INTENT(IN) :: writeToRestartCSVfile
!Local Variables
integer :: npt,nout,nso
real(r_2) :: xyear, xyear2
!--------------------------------------------------------------------------
! Calculate average daily pool over the years and average annual fluxes
! These pools and fluxes were accumulated each day of the simulation.
! See subroutine mimics_caccum in mimics_cycle.f90.
! xyear=1.0/(real(myear)*365)
! xyear2 = 1.0/(real(myear))
! Output is every year now, not every myear years. -mdh 10/17/2016
xyear=1.0/365.0
xyear2 = 1.0
!Divide by number of simulation days to get average daily pool value
mimicspoolAn%ClitterAn(:,:) = mimicspoolAn%ClitterAn(:,:) * xyear
mimicspoolAn%CmicrobeAn(:,:) = mimicspoolAn%CmicrobeAn(:,:) * xyear
mimicspoolAn%CsoilAn(:,:) = mimicspoolAn%CsoilAn(:,:) * xyear
mimicspoolAn%thetaLiqAn(:) = mimicspoolAn%thetaLiqAn(:) * xyear
mimicspoolAn%thetaFrznAn(:) = mimicspoolAn%thetaFrznAn(:) * xyear
mimicspoolAn%fTAn(:) = mimicspoolAn%fTAn(:) * xyear
mimicspoolAn%fWAn(:) = mimicspoolAn%fWAn(:) * xyear
!Divide by number of simulation years to get average annual flux
mimicsfluxAn%ChrespAn(:) = mimicsfluxAn%ChrespAn(:) * xyear2
mimicsfluxAn%CLitInputAn(:,:) = mimicsfluxAn%CLitInputAn(:,:) * xyear2
mimicsfluxAn%CSOMpInputAn(:) = mimicsfluxAn%CSOMpInputAn(:) * xyear2
!--------------------------------------------------------------------------
if (writeToRestartCSVfile) then
nout=106
open(nout,file=filename_mimicsepool)
! mimicsbal%sumcbal=min(9999.0,max(-9999.0,mimicsbal%sumcbal))
!Write header line
write(nout,91) "iYrCnt,npt,veg%iveg,", &
"casamet%lat,casamet%lon,", &
"casamet%areacell,", &
"mimicspool%LITm,mimicspool%LITs,", &
"mimicspool%MICr,mimicspool%MICk,", &
"mimicspool%SOMa,mimicspool%SOMc,", &
"mimicspool%SOMp"
91 format(a20,a24,a17,a32,a32,a32,a15)
do npt =1, mp
! Attention...If initial pool values for MIMICS transient run are not set to 0.0 for icewater,
! daily global mean output drops at the end of the first year when these pools are set to 0.0 below.
! Rely on initialization to set icewater cells correctly since MIMICS does not simulate them. -mdh 7/11/2016
! if (casamet%iveg2(npt) == icewater) then
! mimicspool%LITm(npt) = 0.0
! mimicspool%LITs(npt) = 0.0
! mimicspool%MICr(npt) = 0.0
! mimicspool%MICk(npt) = 0.0
! mimicspool%SOMa(npt) = 0.0
! mimicspool%SOMc(npt) = 0.0
! mimicspool%SOMp(npt) = 0.0
!! mimicsbal%sumcbal(npt) = 0.0
! endif
write(nout,92) iYrCnt,npt,veg%iveg(npt), &
casamet%lat(npt),casamet%lon(npt), &
casamet%areacell(npt)*(1.0e-9), &
mimicspool%LITm(npt), mimicspool%LITs(npt), &
mimicspool%MICr(npt), mimicspool%MICk(npt), &
mimicspool%SOMa(npt), mimicspool%SOMc(npt), mimicspool%SOMp(npt)
end do
CLOSE(nout)
endif
92 format(3(i6,',',2x),10(f18.10,',',2x))
!--------------------------------------------------------------------------
nout=107
open(nout,file="mimics_diagnostic.csv")
!Write header line
write(nout,93) "iYrCnt,npt,veg%iveg,", &
"casamet%lat,casamet%lon,", &
"casamet%areacell,", &
"lignin:N,fmet,"
93 format(a20,a24,a17,a13)
do npt =1, mp
write(nout,94) iYrCnt,npt,veg%iveg(npt), &
casamet%lat(npt),casamet%lon(npt), &
casamet%areacell(npt)*(1.0e-9), &
mimicsbiome%ligninNratioAvg(npt), mimicsbiome%fmet(npt)
end do
CLOSE(nout)
94 format(3(i6,',',2x),5(f18.10,',',2x))
END SUBROUTINE mimics_poolfluxout
!--------------------------------------------------------------------------------
SUBROUTINE mimics_poolfluxout_CN(filename_mimicsepool,mp,iYrCnt,myear,writeToRestartCSVfile)
use define_types
! use casadimension
use casaparm
use casavariable
use mimicsdimension
use mimicsparam
use mimicsvariable
implicit none
!Subroutine arguments
character(len=100), INTENT(IN) :: filename_mimicsepool
integer, INTENT(IN) :: mp, iYrCnt, myear
logical, INTENT(IN) :: writeToRestartCSVfile
!Local Variables
integer :: npt,nout,nso
real(r_2) :: xyear, xyear2
!--------------------------------------------------------------------------
! Calculate average daily pool over the years and average annual fluxes
! These pools and fluxes were accumulated each day of the simulation.
! See subroutine mimics_caccum in mimics_cycle.f90.
! xyear=1.0/(real(myear)*365)
! xyear2 = 1.0/(real(myear))
! Output is every year now, not every myear years. -mdh 10/17/2016
xyear=1.0/365.0
xyear2 = 1.0
!Divide by number of simulation days to get average daily pool value
mimicspoolAn%ClitterAn(:,:) = mimicspoolAn%ClitterAn(:,:) * xyear
mimicspoolAn%CmicrobeAn(:,:) = mimicspoolAn%CmicrobeAn(:,:) * xyear
mimicspoolAn%CsoilAn(:,:) = mimicspoolAn%CsoilAn(:,:) * xyear
mimicspoolAn%NlitterAn(:,:) = mimicspoolAn%NlitterAn(:,:) * xyear
mimicspoolAn%NmicrobeAn(:,:) = mimicspoolAn%NmicrobeAn(:,:) * xyear
mimicspoolAn%NsoilAn(:,:) = mimicspoolAn%NsoilAn(:,:) * xyear
mimicspoolAn%DINAn(:) = mimicspoolAn%DINAn(:) * xyear
mimicspoolAn%thetaLiqAn(:) = mimicspoolAn%thetaLiqAn(:) * xyear
mimicspoolAn%thetaFrznAn(:) = mimicspoolAn%thetaFrznAn(:) * xyear
mimicspoolAn%fTAn(:) = mimicspoolAn%fTAn(:) * xyear
mimicspoolAn%fWAn(:) = mimicspoolAn%fWAn(:) * xyear
!Divide by number of simulation years to get average annual flux
mimicsfluxAn%ChrespAn(:) = mimicsfluxAn%ChrespAn(:) * xyear2
mimicsfluxAn%CLitInputAn(:,:) = mimicsfluxAn%CLitInputAn(:,:) * xyear2
mimicsfluxAn%CSOMpInputAn(:) = mimicsfluxAn%CSOMpInputAn(:) * xyear2
mimicsfluxAn%NLitInputAn(:,:) = mimicsfluxAn%NLitInputAn(:,:) * xyear2
! Overflow_r and Overflow_k added to NetCDF output file. -mdh 10/12/2020
mimicsfluxAn%Overflow_rAn(:) = mimicsfluxAn%Overflow_rAn(:) * xyear2
mimicsfluxAn%Overflow_kAn(:) = mimicsfluxAn%Overflow_kAn(:) * xyear2
!--------------------------------------------------------------------------
if (writeToRestartCSVfile) then
nout=106
open(nout,file=filename_mimicsepool)
! mimicsbal%sumcbal=min(9999.0,max(-9999.0,mimicsbal%sumcbal))
!Write header line
write(nout,91) "iYrCnt,npt,veg%iveg,", &
"casamet%lat,casamet%lon,", &
"casamet%areacell,", &
"mimicspool%LITm,mimicspool%LITs,", &
"mimicspool%MICr,mimicspool%MICk,", &
"mimicspool%SOMa,mimicspool%SOMc,", &
"mimicspool%SOMp,", &
"mimicspool%LITmN,mimicspool%LITsN,", &
"mimicspool%MICrN,mimicspool%MICkN,", &
"mimicspool%SOMaN,mimicspool%SOMcN,", &
"mimicspool%SOMpN"
91 format(a20,a24,a17,a32,a32,a32,a16,a34,a34,a34,a16)
do npt =1, mp
! Attention...If initial pool values for MIMICS transient run are not set to 0.0 for icewater,
! daily global mean output drops at the end of the first year when these pools are set to 0.0 below.
! Rely on initialization to set icewater cells correctly since MIMICS does not simulate them. -mdh 7/11/2016
! if (casamet%iveg2(npt) == icewater) then
! mimicspool%LITm(npt) = 0.0
! mimicspool%LITs(npt) = 0.0
! mimicspool%MICr(npt) = 0.0
! mimicspool%MICk(npt) = 0.0
! mimicspool%SOMa(npt) = 0.0
! mimicspool%SOMc(npt) = 0.0
! mimicspool%SOMp(npt) = 0.0
!! mimicsbal%sumcbal(npt) = 0.0
! endif
write(nout,92) iYrCnt,npt,veg%iveg(npt), &
casamet%lat(npt),casamet%lon(npt), &
casamet%areacell(npt)*(1.0e-9), &
mimicspool%LITm(npt), mimicspool%LITs(npt), &
mimicspool%MICr(npt), mimicspool%MICk(npt), &
mimicspool%SOMa(npt), mimicspool%SOMc(npt), mimicspool%SOMp(npt), &
mimicspool%LITmN(npt), mimicspool%LITsN(npt), &
mimicspool%MICrN(npt), mimicspool%MICkN(npt), &
mimicspool%SOMaN(npt), mimicspool%SOMcN(npt), mimicspool%SOMpN(npt)
end do
CLOSE(nout)
endif
92 format(3(i6,',',1x),17(f18.10,',',1x))
!--------------------------------------------------------------------------
nout=107
open(nout,file="mimics_diagnostic.csv")
!Write header line
write(nout,93) "iYrCnt,npt,veg%iveg,", &
"casamet%lat,casamet%lon,", &
"casamet%areacell,", &
"lignin:N,fmet,"
93 format(a20,a24,a17,a13)
do npt =1, mp
write(nout,94) iYrCnt,npt,veg%iveg(npt), &
casamet%lat(npt),casamet%lon(npt), &
casamet%areacell(npt)*(1.0e-9), &
mimicsbiome%ligninNratioAvg(npt), mimicsbiome%fmet(npt)
end do
CLOSE(nout)
94 format(3(i6,',',2x),5(f18.10,',',2x))
END SUBROUTINE mimics_poolfluxout_CN
!----------------------------------------------------------------------------------------------------
SUBROUTINE WritePoolFluxNcFile_mimics_annual(filename_ncOut, mp, year)
! DESCRIPTION
! Define and write average annual output variables from MIMICS model to netcdf file filename_ncOut.
! Called by casacnpdriver once a year and again at the end of the simulation.
! The file will contain values for a single year.
!
! Melannie Hartman. January 26, 2015
USE define_types
USE casaparm
USE casavariable
USE clmgridvariable
USE mimicsdimension
USE mimicsparam
USE mimicsvariable
implicit none
include 'netcdf.inc'
real(4), parameter :: MISSING_VALUE = 1.e+36
integer, parameter :: MISSING_INT = -9999
! ARGUMENTS
character(len=*), intent(in) :: filename_ncOut ! NetCDF output file name
integer, intent(in) :: mp ! number of points with valid data
integer, intent(in) :: year ! output year
! LOCAL VARIABLES
integer :: i
integer :: ncid ! netcdf file ID
integer :: status ! function return status
! integer :: dimid_mp ! netcdf dimension id
integer :: dimid_lat ! netcdf dimension id
integer :: dimid_lon ! netcdf dimension id
integer :: dimid_time ! netcdf dimension id
integer :: nlon, nlat, ntimes ! Dimension sizes for NetCDf file
integer :: dims(3) ! Array of NetCDF dimension IDs for defining variables
integer :: start1(1), count1(1) ! start and count arrays for writing 1-D data from netcdf files
integer :: start2(2), count2(2) ! start and count arrays for writing 2-D data from netcdf files
integer :: start3(3), count3(3) ! start and count arrays for writing 3-D data from netcdf files
integer :: varid_lon, varid_lat ! NetCDF variable ID for latitude and longitude
integer :: varid_time ! NetCDF variable ID for time
! integer :: varid_year ! NetCDF variable ID for year
integer :: varid_mask ! NetCDF variable ID for cellMissing(nlon,nlat)
integer :: varid_cellid ! NetCDF variable ID for cellid(nlon,nlat)
integer :: varid_igbp ! NetCDF variable ID for IGBP_PFT(nlon,nlat)
integer :: varid_landarea ! NetCDF variable ID for land area
integer :: varid_cLITm ! NetCDF variable ID for metablic litter C
integer :: varid_cLITs ! NetCDF variable ID for structural litter C
integer :: varid_cMICr ! NetCDF variable ID for microbe r-selected pool C
integer :: varid_cMICk ! NetCDF variable ID for microbe K-selected pool C
integer :: varid_cSOMa ! NetCDF variable ID for available soil C
integer :: varid_cSOMc ! NetCDF variable ID for chemically protected soil C
integer :: varid_cSOMp ! NetCDF variable ID for physically protected soil C
integer :: varid_cHresp ! NetCDF variable ID for soil heterotrophic respiration C
integer :: varid_cSOMpIn ! NetCDF variable ID for physically protected soil C inputs
integer :: varid_cLitIn_m ! NetCDF variable ID for metabolic litter Input C
integer :: varid_cLitIn_s ! NetCDF variable ID for structural litter Input C
integer :: varid_of_r ! NetCDF variable ID for Overflow_r respiration
integer :: varid_of_k ! NetCDF variable ID for Overflow_k respiration
integer :: varid_nLITm ! NetCDF variable ID for metablic litter N
integer :: varid_nLITs ! NetCDF variable ID for structural litter N
integer :: varid_nMICr ! NetCDF variable ID for microbe r-selected pool N
integer :: varid_nMICk ! NetCDF variable ID for microbe K-selected pool N
integer :: varid_nSOMa ! NetCDF variable ID for available soil N
integer :: varid_nSOMc ! NetCDF variable ID for chemically protected soil N
integer :: varid_nSOMp ! NetCDF variable ID for physically protected soil N
integer :: varid_DIN ! NetCDF variable ID for dissolved inorganic N
integer :: varid_nLitIn_m ! NetCDF variable ID for metabolic litter Input N
integer :: varid_nLitIn_s ! NetCDF variable ID for structural litter Input N
integer :: varid_thetaLiq ! NetCDF variable ID for fraction of liquid soil water saturation
integer :: varid_thetaFrzn ! NetCDF variable ID for fraction of frozen soil water saturation
! integer :: varid_fT ! NetCDF variable ID for soil temperature amultiplier on decompostion
integer :: varid_fW ! NetCDF variable ID for soil moisture multiplier on decompostion
character*100 :: attr_name ! String for assigning global and variable attributes
character*100 :: attr_units ! String for assigning global and variable attributes
character*10 :: date_string ! String for assigning date to global attributes
character*8 :: time_string ! String for assigning time to global attributes
integer :: verbose=0
integer :: npt, ilon, ilat, itime
integer, allocatable :: IGBP_PFT(:,:) ! IGBP_PFT(nlon,nlat) IGBP PFT classification (1-18)
real(4), allocatable :: landarea(:,:) ! landarea(nlon,nlat) km^2
real(4), allocatable :: var1(:,:,:) ! gridded output variable
real(4), allocatable :: var2(:,:,:) ! gridded output variable
real(4), allocatable :: var3(:,:,:) ! gridded output variable
real(4), allocatable :: var4(:,:,:) ! gridded output variable
real(4), allocatable :: var5(:,:,:) ! gridded output variable
real(4), allocatable :: var6(:,:,:) ! gridded output variable
real(4), allocatable :: var7(:,:,:) ! gridded output variable
real(4), allocatable :: var8(:,:,:) ! gridded output variable
real(4), allocatable :: var9(:,:,:) ! gridded output variable
real(4), allocatable :: var10(:,:,:) ! gridded output variable
real(4) :: time ! time in years (1..ntimes)
if (verbose .ge. 0) print *, "Writing output to file ", trim(filename_ncOut), "..."
! Output these variables in NetCDF file:
! veg%iveg(npt) - IGBP PFTs
! casamet%lat(npt) - latitudes
! casamet%lon(npt) - longitudes
! casamet%areacell(npt)*(1.0e-6) - landarea (km^2)
! Average annual values for fluxes and pools
! mimicsfluxAn%CLitInputAn(npt,METBC) - metabolic litter inputs (gC/m2/yr)
! mimicsfluxAn%CLitInputAn(npt,STRUC) - structural litter inputs (gC/m2/yr)
! mimicsfluxAn%ChrespAn(npt) - heterotrphic respiration flux (gC/m2/yr)
! mimicsfluxAn%CSOMpInputAn(npt) - inputs to SOMp (gC/m2/yr)
! mimicspoolAn%ClitterAn(npt,METBC) - metabolic litter pool (gC/m2)
! mimicspoolAn%ClitterAn(npt,STRUC) - structural litter pool (gC/m2)
! mimicspoolAn%CmicrobeAn(npt,RSEL) - r-selected microbe pool (gC/m2)
! mimicspoolAn%CmicrobeAn(npt,KSEL) - K-selected microbe pool (gC/m2)
! mimicspoolAn%CsoilAn(npt,AVAL) - available SOM pool (gC/m2)
! mimicspoolAn%CsoilAn(npt,CHEM) - chemically protected SOM pool (gC/m2)
! mimicspoolAn%CsoilAn(npt,PHYS) - physically protected SOM pool (gC/m2)
dims(1) = 0
dims(2) = 0
ntimes = 1
nlat = clmgrid%nlat
nlon = clmgrid%nlon
! Create the netcdf file
status = nf_create(filename_ncOut, NF_CLOBBER, ncid)
if (status /= nf_noerr) call handle_err(status, trim(filename_ncOut))
! Define file dimensions
status = nf_def_dim(ncid, 'lon', nlon, dimid_lon)
if (status /= nf_noerr) call handle_err(status, "lon")
status = nf_def_dim(ncid, 'lat', nlat, dimid_lat)
if (status /= nf_noerr) call handle_err(status, "lat")
! status = nf_def_dim(ncid, 'time', ntimes, dimid_time)
status = nf_def_dim(ncid, 'time', nf_unlimited, dimid_time)
if (status /= nf_noerr) call handle_err(status, "time")
! status = nf_def_dim(ncid, 'mp', mp, dimid_mp)
! if (status /= nf_noerr) call handle_err(status, "mp")
! Define variables
dims(1) = dimid_lon
status = nf_def_var(ncid, 'lon', NF_REAL, 1, dims, varid_lon)
if (status /= nf_noerr) call handle_err(status, "def_var(lon)")
dims(1) = dimid_lat
status = nf_def_var(ncid, 'lat', NF_REAL, 1, dims, varid_lat)
if (status /= nf_noerr) call handle_err(status, "def_var(lat)")
dims(1) = dimid_time
status = nf_def_var(ncid, 'time', NF_FLOAT, 1, dims, varid_time)
if (status /= nf_noerr) call handle_err(status, "def_var(time)")
! dims(1) = dimid_time
! status = nf_def_var(ncid, 'year', NF_INT, 1, dims, varid_year)
! if (status /= nf_noerr) call handle_err(status, "def_var(year)")
! Because dimensions in FORTRAN are in Column Major Order (the first
! array index varies the most rapidly) dimensions of FORTRAN arrays
! are in the opposite order that they appear in the NetCDF file with ncdump.
dims(1) = dimid_lon
dims(2) = dimid_lat
status = nf_def_var(ncid, 'IGBP_PFT', NF_INT, 2, dims, varid_igbp)
if (status /= nf_noerr) call handle_err(status, "IGBP_PFT")
status = nf_def_var(ncid, 'landarea', NF_REAL, 2, dims, varid_landarea)
if (status /= nf_noerr) call handle_err(status, "landarea")
status = nf_def_var(ncid, 'cellMissing', NF_INT, 2, dims, varid_mask)
if (status /= nf_noerr) call handle_err(status, "cellMissing")
status = nf_def_var(ncid, 'cellid', NF_INT, 2, dims, varid_cellid)
if (status /= nf_noerr) call handle_err(status, "cellid")
! Because dimensions in FORTRAN are in Column Major Order (the first
! array index varies the most rapidly) dimensions of FORTRAN arrays
! are in the opposite order that they appear in the NetCDF file with ncdump.
dims(1) = dimid_lon
dims(2) = dimid_lat
dims(3) = dimid_time
status = nf_def_var(ncid, 'cLITm', NF_REAL, 3, dims, varid_cLITm)
if (status /= nf_noerr) call handle_err(status, "cLITm")
status = nf_def_var(ncid, 'cLITs', NF_REAL, 3, dims, varid_cLITs)
if (status /= nf_noerr) call handle_err(status, "cLITs")
status = nf_def_var(ncid, 'cMICr', NF_REAL, 3, dims, varid_cMICr)
if (status /= nf_noerr) call handle_err(status, "cMICr")
status = nf_def_var(ncid, 'cMICk', NF_REAL, 3, dims, varid_cMICk)
if (status /= nf_noerr) call handle_err(status, "cMICk")
status = nf_def_var(ncid, 'cSOMa', NF_REAL, 3, dims, varid_cSOMa)
if (status /= nf_noerr) call handle_err(status, "cSOMa")
status = nf_def_var(ncid, 'cSOMc', NF_REAL, 3, dims, varid_cSOMc)
if (status /= nf_noerr) call handle_err(status, "cSOMc")