-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdiff_clm5.patch
2710 lines (2706 loc) · 146 KB
/
diff_clm5.patch
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
diff -ruN clm5.0_control/src/biogeochem/CNFUNMod.F90 clm5.0_perecm/src/biogeochem/CNFUNMod.F90
--- clm5.0_control/src/biogeochem/CNFUNMod.F90 2019-06-04 17:18:45.898704700 -0600
+++ clm5.0_perecm/src/biogeochem/CNFUNMod.F90 2019-06-05 15:07:26.687850360 -0600
@@ -24,6 +24,9 @@
use PatchType , only : patch
use ColumnType , only : col
use pftconMod , only : pftcon, npcropmin
+!RKB added
+ use surfrdMod , only : surfrd_cftformat, surfrd_pftformat
+!RKB end
use decompMod , only : bounds_type
use clm_varctl , only : use_nitrif_denitrif,use_flexiblecn
use abortutils , only : endrun
@@ -217,6 +220,9 @@
use PatchType , only : patch
use subgridAveMod , only : p2c
use pftconMod , only : npcropmin
+!RKB added
+ use surfrdMod , only : surfrd_cftformat, surfrd_pftformat
+!RKB end
!
! !ARGUMENTS:
type(bounds_type) , intent(in) :: bounds
@@ -527,6 +533,9 @@
kn_nonmyc => pftcon%kn_nonmyc , & ! Input: A non-mycorrhizal uptake
! parameter
perecm => pftcon%perecm , & ! Input: The fraction of ECM
+!RKB added
+ perecm_pft => surfrd%perecm_pft , & ! Input: The fraction of ECM
+!RKB end
! -associated PFT
grperc => pftcon%grperc , & ! Input: growth percentage
fun_cn_flex_a => pftcon%fun_cn_flex_a , & ! Parameter a of FUN-flexcn link code (def 5)
diff -ruN clm5.0_control/src/biogeochem/CNFUNMod.F90~ clm5.0_perecm/src/biogeochem/CNFUNMod.F90~
--- clm5.0_control/src/biogeochem/CNFUNMod.F90~ 1969-12-31 17:00:00.000000000 -0700
+++ clm5.0_perecm/src/biogeochem/CNFUNMod.F90~ 2019-06-05 15:03:36.819900572 -0600
@@ -0,0 +1,1807 @@
+module CNFUNMod
+!--------------------------------------------------------------------
+ !---
+! ! DESCRIPTION
+! ! The FUN model developed by Fisher et al. 2010 and
+! ! end Brzostek et al. 2014. Coded by Mingjie Shi 2015.
+! ! Coding logic and structure altered by Rosie Fisher. October 2015.
+! ! Critically, this removes the 'FUN-resistors' idea of Brzostek et
+ ! al. 2014
+! ! and replaces it with uptake that is proportional to the N/C
+ ! exchange rate.
+! ! and adjusts the logic so that FUN does not depends upon the
+ ! CLM4.0 'FPG' downregulation idea
+! ! and instead it takes C spent on N uptake away from growth.
+! ! The critical output so fthis code are sminn_to_plant_fun and
+ ! npp_Nuptake, which are the N
+! ! available to the plant for grwoth, and the C spent on obtaining
+ ! it.
+
+! !USES:
+ use shr_kind_mod , only : r8 => shr_kind_r8
+ use shr_log_mod , only : errMsg => shr_log_errMsg
+ use clm_varctl , only : iulog
+ use PatchType , only : patch
+ use ColumnType , only : col
+ use pftconMod , only : pftcon, npcropmin
+!RKB added
+ use surfrdMod , only : surfrd_cftformat, surfrd_pftformat
+!RKB end
+ use decompMod , only : bounds_type
+ use clm_varctl , only : use_nitrif_denitrif,use_flexiblecn
+ use abortutils , only : endrun
+ use CNVegstateType , only : cnveg_state_type
+ use CNVegCarbonStateType , only : cnveg_carbonstate_type
+ use CNVegCarbonFluxType , only : cnveg_carbonflux_type
+ use CNVegnitrogenstateType , only : cnveg_nitrogenstate_type
+ use CNVegnitrogenfluxType , only : cnveg_nitrogenflux_type
+ use SoilBiogeochemNitrogenFluxType , only : soilbiogeochem_nitrogenflux_type
+ use SoilBiogeochemNitrogenStateType , only : soilbiogeochem_nitrogenstate_type
+
+ use SoilBiogeochemCarbonFluxType , only : soilbiogeochem_carbonflux_type
+ use WaterStateType , only : waterstate_type
+ use WaterfluxType , only : waterflux_type
+ use TemperatureType , only : temperature_type
+ use SoilStateType , only : soilstate_type
+ use CanopyStateType , only : canopystate_type
+ use perf_mod , only : t_startf, t_stopf
+
+ implicit none
+ private
+!
+! !PUBLIC MEMBER FUNCTIONS:
+ public:: readParams ! Read in parameters needed for FUN
+ public:: CNFUNInit ! FUN calculation initialization
+ public:: CNFUN ! Run FUN
+
+ type, private :: params_type
+ real(r8) :: ndays_on ! number of days to complete leaf onset
+ real(r8) :: ndays_off ! number of days to complete leaf offset
+ end type params_type
+
+ !
+ type(params_type), private :: params_inst ! params_inst is
+ ! populated in readParamsMod
+ !
+ !
+ ! !PRIVATE DATA MEMBERS:
+ real(r8) :: dt ! decomp timestep (seconds)
+ real(r8) :: ndays_on ! number of days to complete onset
+ real(r8) :: ndays_off ! number of days to complete offset
+
+ integer, private, parameter :: COST_METHOD = 2 !new way of doing the N uptake
+ ! resistances. see teamwork thread on over-cheap uptake in N
+ ! resistors.
+ integer, private, parameter :: nstp = 2 ! Number of
+ ! calculation part
+ integer, private, parameter :: ncost6 = 6 ! Number of
+ ! N transport pathways
+
+ character(len=*), parameter, private :: sourcefile = &
+ __FILE__
+
+!
+!--------------------------------------------------------------------
+ !---
+ contains
+!--------------------------------------------------------------------
+ !---
+ subroutine readParams ( ncid )
+ !
+ ! !USES:
+ use ncdio_pio , only : file_desc_t,ncd_io
+
+ ! !ARGUMENTS:
+ implicit none
+ type(file_desc_t),intent(inout) :: ncid ! pio netCDF file id
+ !
+ ! !LOCAL VARIABLES:
+ character(len=32) :: subname = 'CNFUNParamsType'
+ character(len=100) :: errCode = '-Error reading in parameters file:'
+ logical :: readv ! has variable been read in or not
+ real(r8) :: tempr ! temporary to read in parameter
+ character(len=100) :: tString ! temp. var for reading
+!--------------------------------------------------------------------
+ !---
+
+ ! read in parameters
+
+ tString='ndays_on'
+ call ncd_io(varname=trim(tString),data=tempr, flag='read', ncid=ncid, readvar=readv)
+ if ( .not. readv ) call endrun( msg=trim(errCode)//trim(tString)//errMsg(sourcefile, __LINE__))
+ params_inst%ndays_on=tempr
+
+ tString='ndays_off'
+ call ncd_io(varname=trim(tString),data=tempr, flag='read', ncid=ncid, readvar=readv)
+ if ( .not. readv ) call endrun( msg=trim(errCode)//trim(tString)//errMsg(sourcefile, __LINE__))
+ params_inst%ndays_off=tempr
+
+
+ end subroutine readParams
+
+!--------------------------------------------------------------------
+ !---
+ subroutine CNFUNInit (bounds,cnveg_state_inst,cnveg_carbonstate_inst,cnveg_nitrogenstate_inst)
+ !
+ ! !DESCRIPTION:
+ !
+ ! !USES:
+ use clm_varcon , only: secspday, fun_period
+ use clm_time_manager, only: get_step_size,get_nstep,get_curr_date,get_days_per_year
+ !
+ ! !ARGUMENTS:
+ type(bounds_type) , intent(in) :: bounds
+ type(cnveg_state_type) , intent(inout) :: cnveg_state_inst
+ type(cnveg_carbonstate_type) , intent(inout) :: cnveg_carbonstate_inst
+ type(cnveg_nitrogenstate_type), intent(inout) :: cnveg_nitrogenstate_inst
+ !
+ ! !LOCAL VARIABLES:
+ real(r8) :: dayspyr ! days per year (days)
+ real(r8) :: timestep_fun ! Timestep length for
+ ! FUN (s)
+ real(r8) :: numofyear ! number of days per
+ ! year
+ integer :: nstep ! time step number
+ integer :: nstep_fun ! Number of
+ ! atmospheric timesteps between calls to FUN
+ character(len=32) :: subname = 'CNFUNInit'
+!--------------------------------------------------------------------
+ !---
+
+! Set local pointers
+ associate(ivt => patch%itype , & ! Input: [integer (:) ] p
+ leafcn => pftcon%leafcn , & ! Input: leaf C:N (gC/gN)
+ leafcn_offset => cnveg_state_inst%leafcn_offset_patch , & ! Output:
+ ! [real(r8) (:) ] Leaf C:N used by FUN
+ leafc_storage_xfer_acc => cnveg_carbonstate_inst%leafc_storage_xfer_acc_patch , & ! Output: [real(r8) (:)
+ ! ] Accmulated leaf C transfer (gC/m2)
+ storage_cdemand => cnveg_carbonstate_inst%storage_cdemand_patch , & ! Output: [real(r8) (:)
+ ! ] C use from the C storage pool
+ leafn_storage_xfer_acc => cnveg_nitrogenstate_inst%leafn_storage_xfer_acc_patch, & ! Output: [real(r8) (:)
+ ! ] Accmulated leaf N transfer (gC/m2)
+ storage_ndemand => cnveg_nitrogenstate_inst%storage_ndemand_patch & ! Output: [real(r8) (:)
+ ! ] N demand during the offset period
+ )
+ !--------------------------------------------------------------------
+ !---
+ ! Calculate some timestep-related values.
+ !--------------------------------------------------------------------
+ !---
+ ! set time steps
+ dt = real(get_step_size(), r8)
+ dayspyr = get_days_per_year()
+ nstep = get_nstep()
+ timestep_fun = real(secspday * fun_period)
+ nstep_fun = int(secspday * dayspyr / dt)
+
+ ndays_on = params_inst%ndays_on
+ ndays_off = params_inst%ndays_off
+
+ !--------------------------------------------------------------------
+ !---
+ ! Decide if FUN will be called on this timestep.
+ !--------------------------------------------------------------------
+ !---
+ numofyear = nstep/nstep_fun
+ if (mod(nstep,nstep_fun) == 0) then
+ leafcn_offset(bounds%begp:bounds%endp) = leafcn(ivt(bounds%begp:bounds%endp))
+ storage_cdemand(bounds%begp:bounds%endp) = 0._r8
+ storage_ndemand(bounds%begp:bounds%endp) = 0._r8
+ leafn_storage_xfer_acc(bounds%begp:bounds%endp) = 0._r8
+ leafc_storage_xfer_acc(bounds%begp:bounds%endp) = 0._r8
+ end if
+!--------------------------------------------------------------------
+ !---
+ end associate
+ end subroutine CNFUNInit
+!--------------------------------------------------------------------
+ !---
+
+ !--------------------------------------------------------------------
+ !---
+ ! Start the CNFUN subroutine
+ !--------------------------------------------------------------------
+ !---
+ subroutine CNFUN(bounds,num_soilc, filter_soilc,num_soilp&
+ &,filter_soilp,waterstate_inst ,&
+ & waterflux_inst,temperature_inst,soilstate_inst&
+ &,cnveg_state_inst,cnveg_carbonstate_inst,&
+ & cnveg_carbonflux_inst,cnveg_nitrogenstate_inst&
+ &,cnveg_nitrogenflux_inst ,&
+ & soilbiogeochem_nitrogenflux_inst&
+ &,soilbiogeochem_carbonflux_inst,canopystate_inst,&
+ & soilbiogeochem_nitrogenstate_inst)
+
+! !USES:
+ use clm_time_manager, only : get_step_size, get_curr_date, get_days_per_year
+ use clm_varpar , only : nlevdecomp
+ use clm_varcon , only : secspday, smallValue, fun_period, tfrz, dzsoi_decomp, spval
+ use clm_varctl , only : use_nitrif_denitrif
+ use PatchType , only : patch
+ use subgridAveMod , only : p2c
+ use pftconMod , only : npcropmin
+!RKB added
+ use surfrdMod , only : surfrd_cftformat, surfrd_pftformat
+!RKB end
+!
+! !ARGUMENTS:
+ type(bounds_type) , intent(in) :: bounds
+ integer , intent(in) :: num_soilc ! number of soil columns in filter
+ integer , intent(in) :: filter_soilc(:) ! filter for soil columns
+ integer , intent(in) :: num_soilp ! number of soil patches in filter
+ integer , intent(in) :: filter_soilp(:) ! filter for soil patches
+ type(waterstate_type) , intent(in) :: waterstate_inst
+ type(waterflux_type) , intent(in) :: waterflux_inst
+ type(temperature_type) , intent(in) :: temperature_inst
+ type(soilstate_type) , intent(in) :: soilstate_inst
+ type(cnveg_state_type) , intent(inout) :: cnveg_state_inst
+ type(cnveg_carbonstate_type) , intent(inout) :: cnveg_carbonstate_inst
+ type(cnveg_carbonflux_type) , intent(inout) :: cnveg_carbonflux_inst
+ type(cnveg_nitrogenstate_type) , intent(inout) :: cnveg_nitrogenstate_inst
+ type(cnveg_nitrogenflux_type) , intent(inout) :: cnveg_nitrogenflux_inst
+ type(soilbiogeochem_nitrogenflux_type) , intent(inout) :: soilbiogeochem_nitrogenflux_inst
+ type(soilbiogeochem_carbonflux_type) , intent(inout) :: soilbiogeochem_carbonflux_inst
+ type(canopystate_type) , intent(inout) :: canopystate_inst
+ type(soilbiogeochem_nitrogenstate_type) , intent(inout) :: soilbiogeochem_nitrogenstate_inst
+ !
+ ! !LOCAL VARIABLES:
+ ! local pointers to implicit in arrays
+ !
+ !--------------------------------------------------------------------
+ ! ------------
+ ! Integer parameters
+ !--------------------------------------------------------------------
+ !-----------
+ integer, parameter :: icostFix = 1 ! Process
+ ! number for fixing.
+ integer, parameter :: icostRetrans = 2 ! Process
+ ! number for retranslocation.
+ integer, parameter :: icostActiveNO3 = 3 ! Process
+ ! number for mycorrhizal uptake of NO3.
+ integer, parameter :: icostActiveNH4 = 4 ! Process
+ ! number for mycorrhizal uptake of NH4
+ integer, parameter :: icostnonmyc_no3 = 5 ! Process
+ ! number for nonmyc uptake of NO3.
+ integer, parameter :: icostnonmyc_nh4 = 6 ! Process
+ ! number for nonmyc uptake of NH4.
+ real(r8), parameter :: big_cost = 1000000000._r8! An arbitrarily large cost
+
+ ! array index when plant is fixing
+ integer, parameter :: plants_are_fixing = 1
+ integer, parameter :: plants_not_fixing = 2
+
+ ! array index for ECM step versus AM step
+ integer, parameter :: ecm_step = 1
+ integer, parameter :: am_step = 2
+ ! arbitrary large cost (gC/gN).
+ !--------------------------------------------------------------------
+ !-----------------------------------------------
+ ! Local Real variables.
+ !--------------------------------------------------------------------
+ !-----------------------------------------------
+ real(r8) :: excess ! excess N taken up by transpiration (gN/m2)
+ real(r8) :: steppday ! model time steps in each day (-)
+ real(r8) :: rootc_dens_step ! root C for each PFT in each soil layer(gC/m2)
+ real(r8) :: retrans_limit1 ! a temporary variable for leafn (gN/m2)
+ real(r8) :: qflx_tran_veg_layer ! transpiration in each soil layer (mm H2O/S)
+ real(r8) :: dn ! Increment of N (gN/m2)
+ real(r8) :: dn_retrans ! Increment of N (gN/m2)
+ real(r8) :: dnpp ! Increment of NPP (gC/m2)
+ real(r8) :: dnpp_retrans ! Increment of NPP (gC/m2)
+ real(r8) :: rootc_dens(bounds%begp:bounds%endp,1:nlevdecomp) ! the root carbon density (gC/m2)
+ real(r8) :: rootC(bounds%begp:bounds%endp) ! root biomass (gC/m2)
+ real(r8) :: permyc(bounds%begp:bounds%endp,1:nstp) ! the arrary for the ECM and AM ratio (-)
+ real(r8) :: kc_active(bounds%begp:bounds%endp,1:nstp) ! the kc_active parameter (gC/m2)
+ real(r8) :: kn_active(bounds%begp:bounds%endp,1:nstp) ! the kn_active parameter (gC/m2)
+ real(r8) :: availc_pool(bounds%begp:bounds%endp) ! The avaible C pool for allocation (gC/m2)
+ real(r8) :: plantN(bounds%begp:bounds%endp) ! Plant N (gN/m2)
+ real(r8) :: plant_ndemand_pool(bounds%begp:bounds%endp) ! The N demand pool (gN/m2)
+ real(r8) :: plant_ndemand_pool_step(bounds%begp:bounds%endp,1:nstp) ! the N demand pool (gN/m2)
+ real(r8) :: leafn_step(bounds%begp:bounds%endp,1:nstp) ! N loss based for deciduous trees (gN/m2)
+ real(r8) :: leafn_retrans_step(bounds%begp:bounds%endp,1:nstp) ! N loss based for deciduous trees (gN/m2)
+ real(r8) :: litterfall_n(bounds%begp:bounds%endp) ! N loss based on the leafc to litter (gN/m2)
+ real(r8) :: litterfall_n_step(bounds%begp:bounds%endp,1:nstp) ! N loss based on the leafc to litter (gN/m2)
+ real(r8) :: litterfall_c_step(bounds%begp:bounds%endp,1:nstp) ! N loss based on the leafc to litter (gN/m2)
+ real(r8) :: tc_soisno(bounds%begc:bounds%endc,1:nlevdecomp) ! Soil temperature (degrees Celsius)
+ real(r8) :: npp_remaining(bounds%begp:bounds%endp,1:nstp) ! A temporary variable for npp_remaining(gC/m2)
+ real(r8) :: n_passive_step(bounds%begp:bounds%endp,1:nstp) ! N taken up by transpiration at substep(gN/m2)
+ real(r8) :: n_passive_acc(bounds%begp:bounds%endp) ! N acquired by passive uptake (gN/m2)
+ real(r8) :: cost_retran(bounds%begp:bounds%endp,1:nlevdecomp) ! cost of retran (gC/gN)
+ real(r8) :: cost_fix(bounds%begp:bounds%endp,1:nlevdecomp) ! cost of fixation (gC/gN)
+ real(r8) :: cost_resis(bounds%begp:bounds%endp,1:nlevdecomp) ! cost of resis (gC/gN)
+ real(r8) :: cost_res_resis(bounds%begp:bounds%endp,1:nlevdecomp) ! The cost of resis (gN/gC)
+ real(r8) :: n_fix_acc(bounds%begp:bounds%endp,1:nstp) ! N acquired by fixation (gN/m2)
+ real(r8) :: n_fix_acc_total(bounds%begp:bounds%endp) ! N acquired by fixation (gN/m2)
+ real(r8) :: npp_fix_acc(bounds%begp:bounds%endp,1:nstp) ! Amount of NPP used by fixation (gC/m2)
+ real(r8) :: npp_fix_acc_total(bounds%begp:bounds%endp) ! Amount of NPP used by fixation (gC/m2)
+ real(r8) :: n_retrans_acc(bounds%begp:bounds%endp,1:nstp) ! N acquired by retranslocation (gN/m2)
+ real(r8) :: n_retrans_acc_total(bounds%begp:bounds%endp) ! N acquired by retranslocation (gN/m2)
+ real(r8) :: free_nretrans_acc(bounds%begp:bounds%endp,1:nstp) ! N acquired by retranslocation (gN/m2)
+ real(r8) :: npp_retrans_acc(bounds%begp:bounds%endp,1:nstp) ! NPP used for the extraction (gC/m2)
+ real(r8) :: npp_retrans_acc_total(bounds%begp:bounds%endp) ! NPP used for the extraction (gC/m2)
+ real(r8) :: nt_uptake(bounds%begp:bounds%endp,1:nstp) ! N uptake from retrans, active, and fix(gN/m2)
+ real(r8) :: npp_uptake(bounds%begp:bounds%endp,1:nstp) ! NPP used by the uptakes (gC/m2)
+
+ !----------NITRIF_DENITRIF-------------!
+
+ real(r8) :: sminn_no3_diff ! A temporary limit for N uptake (gN/m2)
+ real(r8) :: sminn_nh4_diff ! A temporary limit for N uptake (gN/m2)
+ real(r8) :: active_no3_limit1 ! A temporary limit for N uptake (gN/m2)
+ real(r8) :: active_nh4_limit1 ! A temporary limit for N uptake (gN/m2)
+ real(r8) :: cost_active_no3(bounds%begp:bounds%endp,1:nlevdecomp) ! cost of mycorrhizal (gC/gN)
+ real(r8) :: cost_active_nh4(bounds%begp:bounds%endp,1:nlevdecomp) ! cost of mycorrhizal (gC/gN)
+ real(r8) :: cost_nonmyc_no3(bounds%begp:bounds%endp,1:nlevdecomp) ! cost of nonmyc (gC/gN)
+ real(r8) :: cost_nonmyc_nh4(bounds%begp:bounds%endp,1:nlevdecomp) ! cost of nonmyc (gC/gN)
+
+ real(r8) :: sminn_no3_conc(bounds%begc:bounds%endc,1:nlevdecomp) ! Concentration of no3 in soil water (gN/gH2O)
+ real(r8) :: sminn_no3_conc_step(bounds%begp:bounds%endp,1:nlevdecomp,1:nstp) ! A temporary variable for soil mineral N (gN/gH2O)
+ real(r8) :: sminn_no3_layer(bounds%begc:bounds%endc,1:nlevdecomp) ! Available no3 in each soil layer (gN/m2)
+ real(r8) :: sminn_no3_layer_step(bounds%begp:bounds%endp,1:nlevdecomp,1:nstp)! A temporary variable for soil no3 (gN/m2)
+ real(r8) :: sminn_no3_uptake(bounds%begp:bounds%endp,1:nlevdecomp,1:nstp) ! A temporary variable for soil mineral N (gN/m2/s)
+ real(r8) :: sminn_nh4_conc(bounds%begc:bounds%endc,1:nlevdecomp) ! Concentration of nh4 in soil water (gN/gH2O)
+ real(r8) :: sminn_nh4_conc_step(bounds%begp:bounds%endp,1:nlevdecomp,1:nstp) ! A temporary variable for soil mineral N (gN/gH2O)
+ real(r8) :: sminn_nh4_layer(bounds%begc:bounds%endc,1:nlevdecomp) ! Available nh4 in each soil layer (gN/m2)
+ real(r8) :: sminn_nh4_layer_step(bounds%begp:bounds%endp,1:nlevdecomp,1:nstp)! A temporary variable for soil mineral N (gN/m2)
+ real(r8) :: sminn_nh4_uptake(bounds%begp:bounds%endp,1:nlevdecomp,1:nstp) ! A temporary variable for soil mineral N (gN/m2/s)
+
+ real(r8) :: active_no3_uptake1(bounds%begp:bounds%endp,1:nlevdecomp) ! no3 mycorrhizal uptake (gN/m2)
+ real(r8) :: active_nh4_uptake1(bounds%begp:bounds%endp,1:nlevdecomp) ! nh4 mycorrhizal uptake (gN/m2)
+ real(r8) :: nonmyc_no3_uptake1(bounds%begp:bounds%endp,1:nlevdecomp) ! no3 non-mycorrhizal uptake (gN/m2)
+ real(r8) :: nonmyc_nh4_uptake1(bounds%begp:bounds%endp,1:nlevdecomp) ! nh4 non-mycorrhizal uptake (gN/m2)
+ real(r8) :: active_no3_uptake2(bounds%begp:bounds%endp,1:nlevdecomp) ! no3 mycorrhizal uptake (gN/m2)
+ real(r8) :: active_nh4_uptake2(bounds%begp:bounds%endp,1:nlevdecomp) ! nh4 mycorrhizal uptake (gN/m2)
+ real(r8) :: nonmyc_no3_uptake2(bounds%begp:bounds%endp,1:nlevdecomp) ! no3 non-mycorrhizal uptake (gN/m2)
+ real(r8) :: nonmyc_nh4_uptake2(bounds%begp:bounds%endp,1:nlevdecomp) ! nh4 non-mycorrhizal uptake (gN/m2)
+ real(r8) :: n_am_no3_acc(bounds%begp:bounds%endp) ! AM no3 uptake (gN/m2)
+ real(r8) :: n_am_nh4_acc(bounds%begp:bounds%endp) ! AM nh4 uptake (gN/m2)
+ real(r8) :: n_ecm_no3_acc(bounds%begp:bounds%endp) ! ECM no3 uptake (gN/m2)
+ real(r8) :: n_ecm_nh4_acc(bounds%begp:bounds%endp) ! ECM nh4 uptake (gN/m2)
+ real(r8) :: n_active_no3_acc(bounds%begp:bounds%endp,1:nstp) ! Mycorrhizal no3 uptake (gN/m2)
+ real(r8) :: n_active_nh4_acc(bounds%begp:bounds%endp,1:nstp) ! Mycorrhizal nh4 uptake (gN/m2)
+ real(r8) :: n_nonmyc_no3_acc(bounds%begp:bounds%endp,1:nstp) ! Non-myc no3 uptake (gN/m2)
+ real(r8) :: n_nonmyc_nh4_acc(bounds%begp:bounds%endp,1:nstp) ! Non-myc nh4 uptake (gN/m2)
+ real(r8) :: n_active_no3_acc_total(bounds%begp:bounds%endp) ! Mycorrhizal no3 uptake (gN/m2)
+ real(r8) :: n_active_nh4_acc_total(bounds%begp:bounds%endp) ! Mycorrhizal no3 uptake (gN/m2)
+
+ real(r8) :: n_nonmyc_no3_acc_total(bounds%begp:bounds%endp) ! Non-myc no3 uptake (gN/m2)
+ real(r8) :: n_nonmyc_nh4_acc_total(bounds%begp:bounds%endp) ! Non-myc no3 uptake (gN/m2)
+ real(r8) :: npp_active_no3_acc(bounds%begp:bounds%endp,1:nstp) ! Mycorrhizal no3 uptake used C (gC/m2)
+ real(r8) :: npp_active_nh4_acc(bounds%begp:bounds%endp,1:nstp) ! Mycorrhizal nh4 uptake used C (gC/m2)
+ real(r8) :: npp_nonmyc_no3_acc(bounds%begp:bounds%endp,1:nstp) ! Non-myc no3 uptake used C (gC/m2)
+ real(r8) :: npp_nonmyc_nh4_acc(bounds%begp:bounds%endp,1:nstp) ! Non-myc nh4 uptake used C (gC/m2)
+ real(r8) :: npp_active_no3_acc_total(bounds%begp:bounds%endp) ! Mycorrhizal no3 uptake used C (gC/m2)
+ real(r8) :: npp_active_nh4_acc_total(bounds%begp:bounds%endp) ! Mycorrhizal nh4 uptake used C (gC/m2)
+ real(r8) :: npp_nonmyc_no3_acc_total(bounds%begp:bounds%endp) ! Non-myc no3 uptake used C (gC/m2)
+ real(r8) :: npp_nonmyc_nh4_acc_total(bounds%begp:bounds%endp) ! Non-myc nh4 uptake used C (gC/m2)
+ real(r8) :: n_am_no3_retrans(bounds%begp:bounds%endp) ! AM no3 uptake for offset (gN/m2)
+ real(r8) :: n_am_nh4_retrans(bounds%begp:bounds%endp) ! AM nh4 uptake for offset (gN/m2)
+ real(r8) :: n_ecm_no3_retrans(bounds%begp:bounds%endp) ! ECM no3 uptake for offset (gN/m2)
+ real(r8) :: n_ecm_nh4_retrans(bounds%begp:bounds%endp) ! ECM nh4 uptake for offset (gN/m2)
+ real(r8) :: n_active_no3_retrans(bounds%begp:bounds%endp,1:nstp) ! Mycorrhizal no3 for offset (gN/m2)
+ real(r8) :: n_active_nh4_retrans(bounds%begp:bounds%endp,1:nstp) ! Mycorrhizal nh4 for offset (gN/m2)
+ real(r8) :: n_nonmyc_no3_retrans(bounds%begp:bounds%endp,1:nstp) ! Non-myc no3 for offset (gN/m2)
+ real(r8) :: n_nonmyc_nh4_retrans(bounds%begp:bounds%endp,1:nstp) ! Non-myc nh4 for offset (gN/m2)
+ real(r8) :: n_active_no3_retrans_total(bounds%begp:bounds%endp) ! Mycorrhizal no3 for offset (gN/m2)
+ real(r8) :: n_active_nh4_retrans_total(bounds%begp:bounds%endp) ! Mycorrhizal nh4 for offset (gN/m2)
+ real(r8) :: n_nonmyc_no3_retrans_total(bounds%begp:bounds%endp) ! Non-myc no3 for offset (gN/m2)
+ real(r8) :: n_nonmyc_nh4_retrans_total(bounds%begp:bounds%endp) ! Non-myc nh4 for offset (gN/m2)
+ real(r8) :: n_passive_no3_vr(bounds%begp:bounds%endp,1:nlevdecomp) ! Layer passive no3 uptake (gN/m2)
+ real(r8) :: n_passive_nh4_vr(bounds%begp:bounds%endp,1:nlevdecomp) ! Layer passive nh4 uptake (gN/m2)
+ real(r8) :: n_fix_no3_vr(bounds%begp:bounds%endp,1:nlevdecomp) ! Layer fixation no3 uptake (gN/m2)
+ real(r8) :: n_fix_nh4_vr(bounds%begp:bounds%endp,1:nlevdecomp) ! Layer fixation nh4 uptake (gN/m2)
+ real(r8) :: n_active_no3_vr(bounds%begp:bounds%endp,1:nlevdecomp) ! Layer mycorrhizal no3 uptake (gN/m2)
+ real(r8) :: n_nonmyc_no3_vr(bounds%begp:bounds%endp,1:nlevdecomp) ! Layer non-myc no3 uptake (gN/m2)
+ real(r8) :: n_active_nh4_vr(bounds%begp:bounds%endp,1:nlevdecomp) ! Layer mycorrhizal nh4 uptake (gN/m2)
+ real(r8) :: n_nonmyc_nh4_vr(bounds%begp:bounds%endp,1:nlevdecomp) ! Layer non-myc nh4 uptake (gN/m2)
+ real(r8) :: npp_active_no3_retrans(bounds%begp:bounds%endp,1:nstp) ! Mycorrhizal no3 uptake used C for offset (gN/m2)
+ real(r8) :: npp_active_nh4_retrans(bounds%begp:bounds%endp,1:nstp) ! Mycorrhizal nh4 uptake used C for offset (gN/m2)
+ real(r8) :: npp_nonmyc_no3_retrans(bounds%begp:bounds%endp,1:nstp) ! Non-myc no3 uptake used C for offset (gN/m2)
+ real(r8) :: npp_nonmyc_nh4_retrans(bounds%begp:bounds%endp,1:nstp) ! Non-myc nh4 uptake used C for offset (gN/m2)
+ real(r8) :: npp_active_no3_retrans_total(bounds%begp:bounds%endp) ! Mycorrhizal no3 uptake used C for offset (gN/m2)
+ real(r8) :: npp_active_nh4_retrans_total(bounds%begp:bounds%endp) ! Mycorrhizal nh4 uptake used C for offset (gN/m2)
+ real(r8) :: npp_nonmyc_no3_retrans_total(bounds%begp:bounds%endp) ! Non-myc no3 uptake used C for offset (gN/m2)
+ real(r8) :: npp_nonmyc_nh4_retrans_total(bounds%begp:bounds%endp) ! Non-myc nh4 uptake used C for offset (gN/m2)
+
+
+ real(r8) :: costNit(1:nlevdecomp,ncost6) ! Cost of N via each process (gC/gN)
+
+ ! Uptake fluxes for COST_METHOD=2
+ ! actual npp to each layer for each uptake process
+ real(r8) :: npp_to_fixation(1:nlevdecomp)
+ real(r8) :: npp_to_retrans(1:nlevdecomp)
+ real(r8) :: npp_to_active_nh4(1:nlevdecomp)
+ real(r8) :: npp_to_nonmyc_nh4(1:nlevdecomp)
+ real(r8) :: npp_to_active_no3(1:nlevdecomp)
+ real(r8) :: npp_to_nonmyc_no3 (1:nlevdecomp)
+
+ ! fraction of carbon to each uptake process
+ real(r8) :: npp_frac_to_fixation(1:nlevdecomp)
+ real(r8) :: npp_frac_to_retrans(1:nlevdecomp)
+ real(r8) :: npp_frac_to_active_nh4(1:nlevdecomp)
+ real(r8) :: npp_frac_to_nonmyc_nh4(1:nlevdecomp)
+ real(r8) :: npp_frac_to_active_no3(1:nlevdecomp)
+ real(r8) :: npp_frac_to_nonmyc_no3 (1:nlevdecomp)
+
+ ! hypothetical fluxes on N in each layer
+ real(r8) :: n_exch_fixation(1:nlevdecomp) ! N aquired from one unit of C for fixation (unitless)
+ real(r8) :: n_exch_retrans(1:nlevdecomp) ! N aquired from one unit of C for retrans (unitless)
+ real(r8) :: n_exch_active_nh4(1:nlevdecomp) ! N aquired from one unit of C for act nh4(unitless)
+ real(r8) :: n_exch_nonmyc_nh4(1:nlevdecomp) ! N aquired from one unit of C for nonmy nh4 (unitless)
+ real(r8) :: n_exch_active_no3(1:nlevdecomp) ! N aquired from one unit of C for act no3 (unitless)
+ real(r8) :: n_exch_nonmyc_no3(1:nlevdecomp) ! N aquired from one unit of C for nonmyc no3 (unitless)
+
+ !actual fluxes of N in each layer
+ real(r8) :: n_from_fixation(1:nlevdecomp) ! N aquired in each layer for fixation (gN m-2 s-1)
+ real(r8) :: n_from_retrans(1:nlevdecomp) ! N aquired in each layer of C for retrans (gN m-2 s-1)
+ real(r8) :: n_from_active_nh4(1:nlevdecomp) ! N aquired in each layer of C for act nh4 (gN m-2 s-1)
+ real(r8) :: n_from_nonmyc_nh4(1:nlevdecomp) ! N aquired in each layer of C for nonmy nh4 (gN m-2 s-1)
+ real(r8) :: n_from_active_no3(1:nlevdecomp) ! N aquired in each layer of C for act no3 (gN m-2 s-1)
+ real(r8) :: n_from_nonmyc_no3(1:nlevdecomp) ! N aquired in each layer of C for nonmyc no3 (gN m-2 s-1)
+
+ real(r8) :: free_Nretrans(bounds%begp:bounds%endp) ! the total amount of NO3 and NH4 (gN/m3/s)
+
+ ! Uptake fluxes for COST_METHOD=2
+ !actual fluxes of N in each layer
+ real(r8) :: frac_ideal_C_use ! How much less C do we use for 'buying' N than that
+ ! needed to get to the ideal ratio? fraction.
+
+ real(r8) :: N_acquired
+ real(r8) :: C_spent
+ real(r8) :: leaf_narea ! leaf n per unit leaf
+ ! area in gN/m2 (averaged across canopy, which is OK for the cost
+ ! calculation)
+
+
+ real(r8) :: sum_n_acquired ! Sum N aquired from one unit of C (unitless)
+ real(r8) :: burned_off_carbon ! carbon wasted by poor allocation algorithm. If
+ ! this is too big, we need a better iteration.
+ real(r8) :: temp_n_flux
+ real(r8) :: delta_cn ! difference between 'ideal' leaf CN ration and
+ ! actual leaf C:N ratio. C/N
+ real(r8) :: excess_carbon ! how much carbon goes into the leaf C
+ ! pool on account of the flexibleCN modifications.
+ real(r8) :: excess_carbon_acc ! excess accumulated over layers.
+ ! WITHOUT GROWTH RESP
+ real(r8) :: fixerfrac ! what fraction of plants can fix?
+ real(r8) :: npp_to_spend ! how much carbon do we need to get
+ ! rid of?
+ real(r8) :: soil_n_extraction ! calculates total N pullled from
+ ! soil
+ real(r8) :: total_N_conductance !inverse of C to of N for whole soil
+ ! -leaf pathway
+ real(r8) :: total_N_resistance ! C to of N for whole soil -leaf
+ ! pathway
+ real(r8) :: free_RT_frac=0.0_r8 !fraction of N retranslocation which is automatic/free.
+ ! SHould be made into a PFT parameter.
+
+ real(r8) :: paid_for_n_retrans
+ real(r8) :: free_n_retrans
+ real(r8) :: total_c_spent_retrans
+ real(r8) :: total_c_accounted_retrans
+
+
+ !------end of not_use_nitrif_denitrif------!
+ !--------------------------------------------------------------------
+ !------------
+ ! Local Integer variables
+ !--------------------------------------------------------------------
+ !------------
+ integer :: fn ! number of values
+ ! in pft filter
+ integer :: fp ! lake filter pft
+ ! index
+ integer :: fc ! lake filter column
+ ! index
+ integer :: p, c ! pft index
+ integer :: g, l ! indices
+ integer :: j, i, k ! soil/snow level
+ ! index
+ integer :: istp ! Loop counters/work
+ integer :: icost ! a local index
+ integer :: fixer ! 0 = non-fixer, 1
+ ! =fixer
+ logical :: unmetDemand ! True while there
+ ! is still demand for N
+ logical :: local_use_flexibleCN ! local version of use_flexCN
+ integer :: FIX ! for loop. 1 for
+ ! fixers, 2 for non fixers. This will become redundant with the
+ ! 'fixer' parameter if it works.
+
+ !--------------------------------------------------------------------
+ !---------------------------------
+ associate(ivt => patch%itype , & ! Input: [integer (:) ] p
+ leafcn => pftcon%leafcn , & ! Input: leaf C:N (gC/gN)
+ lflitcn => pftcon%lflitcn , & ! Input: leaf litter C:N (gC/gN)
+ season_decid => pftcon%season_decid , & ! Input: binary flag for seasonal
+ ! -deciduous leaf habit (0 or 1)
+ stress_decid => pftcon%stress_decid , & ! Input: binary flag for stress
+ ! -deciduous leaf habit (0 or 1)
+ a_fix => pftcon%a_fix , & ! Input: A BNF parameter
+ b_fix => pftcon%b_fix , & ! Input: A BNF parameter
+ c_fix => pftcon%c_fix , & ! Input: A BNF parameter
+ s_fix => pftcon%s_fix , & ! Input: A BNF parameter
+ akc_active => pftcon%akc_active , & ! Input: A mycorrhizal uptake
+ ! parameter
+ akn_active => pftcon%akn_active , & ! Input: A mycorrhizal uptake
+ ! parameter
+ ekc_active => pftcon%ekc_active , & ! Input: A mycorrhizal uptake
+ ! parameter
+ ekn_active => pftcon%ekn_active , & ! Input: A mycorrhizal upatke
+ ! parameter
+ kc_nonmyc => pftcon%kc_nonmyc , & ! Input: A non-mycorrhizal uptake
+ ! parameter
+ kn_nonmyc => pftcon%kn_nonmyc , & ! Input: A non-mycorrhizal uptake
+ ! parameter
+ perecm => pftcon%perecm , & ! Input: The fraction of ECM
+ ! -associated PFT
+ grperc => pftcon%grperc , & ! Input: growth percentage
+ fun_cn_flex_a => pftcon%fun_cn_flex_a , & ! Parameter a of FUN-flexcn link code (def 5)
+ fun_cn_flex_b => pftcon%fun_cn_flex_b , & ! Parameter b of FUN-flexcn link code (def 200)
+ fun_cn_flex_c => pftcon%fun_cn_flex_c , & ! Parameter b of FUN-flexcn link code (def 80)
+ FUN_fracfixers => pftcon%FUN_fracfixers , & ! Fraction of C that can be used for fixation.
+ leafcn_offset => cnveg_state_inst%leafcn_offset_patch , & ! Output:
+ ! [real(r8) (:)] Leaf C:N used by FUN
+ plantCN => cnveg_state_inst%plantCN_patch , & ! Output: [real(r8) (:)] Plant
+ ! C:N used by FUN
+ onset_flag => cnveg_state_inst%onset_flag_patch , & ! Output: [real(r8) (:)] onset
+ ! flag
+ offset_flag => cnveg_state_inst%offset_flag_patch , & ! Output: [real(r8) (:)] offset
+ ! flag
+ availc => cnveg_carbonflux_inst%availc_patch , & ! Iutput: [real(r8) (:)] C flux
+ ! available for allocation (gC/m2/s)
+ leafc => cnveg_carbonstate_inst%leafc_patch , & ! Input: [real(r8) (:)] (gC/m2)
+ ! leaf C
+ leafc_storage => cnveg_carbonstate_inst%leafc_storage_patch , & ! Input: [real(r8)
+ ! (:)] (gC/m2) leaf C storage
+ frootc => cnveg_carbonstate_inst%frootc_patch , & ! Input: [real(r8)
+ ! (:)] (gC/m2) fine root C
+ frootc_storage => cnveg_carbonstate_inst%frootc_storage_patch , & ! Input: [real(r8)
+ ! (:)] (gC/m2) fine root C storage
+ livestemc => cnveg_carbonstate_inst%livestemc_patch , & ! Input: [real(r8)
+ ! (:)] (gC/m2) live stem C
+ livecrootc => cnveg_carbonstate_inst%livecrootc_patch , & ! Input: [real(r8)
+ ! (:)] (gC/m2) live coarse root C
+ leafc_storage_xfer_acc => cnveg_carbonstate_inst%leafc_storage_xfer_acc_patch , & ! uutput: [real(r8)
+ ! (:)] Accmulated leaf C transfer (gC/m2)
+ storage_cdemand => cnveg_carbonstate_inst%storage_cdemand_patch , & ! Output: [real(r8)
+ ! (:)] C use f rom the C storage pool
+ tlai => canopystate_inst%tlai_patch , & ! Input: [real(r8) (:) ] one
+ ! -sided leaf area index
+ leafn => cnveg_nitrogenstate_inst%leafn_patch , & ! Input: [real(r8) (:)]
+ ! (gN/m2) leaf N
+ frootn => cnveg_nitrogenstate_inst%frootn_patch , & ! Input: [real(r8) (:)]
+ ! (gN/m2) fine root N
+ livestemn => cnveg_nitrogenstate_inst%livestemn_patch , & ! Input: [real(r8) (:)]
+ ! (gN/m2) live stem N
+ livecrootn => cnveg_nitrogenstate_inst%livecrootn_patch , & ! Input: [real(r8) (:)]
+ ! (gN/m2) live coarse root N
+ leafn_storage_xfer_acc => cnveg_nitrogenstate_inst%leafn_storage_xfer_acc_patch, & ! Output: [real(r8) (:)]
+ ! Accmulated leaf N transfer (gC/m2)
+ storage_ndemand => cnveg_nitrogenstate_inst%storage_ndemand_patch , & ! Output: [real(r8) (:)]
+ ! N demand during the offset period
+ leafc_to_litter => cnveg_carbonflux_inst%leafc_to_litter_patch , & ! Output: [real(r8)
+ ! (:) ] leaf C litterfall (gC/m2/s)
+ leafc_to_litter_fun => cnveg_carbonflux_inst%leafc_to_litter_fun_patch , & ! Output: [real(r8)
+ ! (:) ] leaf C litterfall used by FUN (gC/m2/s)
+ prev_leafc_to_litter => cnveg_carbonflux_inst%prev_leafc_to_litter_patch , & ! Output: [real(r8) (:)
+ ! ] previous timestep leaf C litterfall flux (gC/m2/s)
+ leafc_storage_to_xfer => cnveg_carbonflux_inst%leafc_storage_to_xfer_patch , & ! Output: [real(r8)
+ ! (:) ]
+ npp_Nactive => cnveg_carbonflux_inst%npp_Nactive_patch , & ! Output: [real(r8)
+ ! (:) ] Mycorrhizal N uptake used C (gC/m2/s)
+ npp_Nnonmyc => cnveg_carbonflux_inst%npp_Nnonmyc_patch , & ! Output: [real(r8)
+ ! (:) ] Non-mycorrhizal N uptake use C (gC/m2/s)
+ npp_Nam => cnveg_carbonflux_inst%npp_Nam_patch , & ! Output: [real(r8)
+ ! (:) ] AM uptake use C (gC/m2/s)
+ npp_Necm => cnveg_carbonflux_inst%npp_Necm_patch , & ! Output: [real(r8)
+ ! (:) ] ECM uptake use C (gC/m2/s)
+ npp_Nactive_no3 => cnveg_carbonflux_inst%npp_Nactive_no3_patch , & ! Output: [real(r8)
+ ! (:) ] Mycorrhizal N uptake used C (gC/m2/s)
+ npp_Nnonmyc_no3 => cnveg_carbonflux_inst%npp_Nnonmyc_no3_patch , & ! Output: [real(r8)
+ ! (:) ] Non-myco uptake use C (gC/m2/s) rrhizal N uptake
+ ! (gN/m2/s)
+ npp_Nam_no3 => cnveg_carbonflux_inst%npp_Nam_no3_patch , & ! Output: [real(r8)
+ ! (:) ] AM uptake use C (gC/m2/s)
+ npp_Necm_no3 => cnveg_carbonflux_inst%npp_Necm_no3_patch , & ! Output: [real(r8)
+ ! (:) ] ECM uptake use C (gC/m2/s)
+ npp_Nactive_nh4 => cnveg_carbonflux_inst%npp_Nactive_nh4_patch , & ! Output: [real(r8)
+ ! (:) ] Mycorrhizal N uptake used C (gC/m2/s)
+ npp_Nnonmyc_nh4 => cnveg_carbonflux_inst%npp_Nnonmyc_nh4_patch , & ! Output: [real(r8)
+ ! (:) ] Non-mycorrhizal N uptake used C (gC/m2/s)
+ npp_Nam_nh4 => cnveg_carbonflux_inst%npp_Nam_nh4_patch , & ! Output: [real(r8)
+ ! (:) ] AM uptake used C(gC/m2/s)
+ npp_Necm_nh4 => cnveg_carbonflux_inst%npp_Necm_nh4_patch , & ! Output: [real(r8)
+ ! (:) ] ECM uptake used C (gC/m2/s)
+ npp_Nfix => cnveg_carbonflux_inst%npp_Nfix_patch , & ! Output: [real(r8)
+ ! (:) ] Symbiotic BNF used C (gC/m2/s)
+ npp_Nretrans => cnveg_carbonflux_inst%npp_Nretrans_patch , & ! Output: [real(r8)
+ ! (:) ] Retranslocation N uptake used C (gC/m2/s)
+ npp_Nuptake => cnveg_carbonflux_inst%npp_Nuptake_patch , & ! Output: [real(r8)
+ ! (:) ] Total N uptake of FUN used C (gC/m2/s)
+ npp_growth => cnveg_carbonflux_inst%npp_growth_patch , & ! Output: [real(r8)
+ ! (:) ] Total N uptake of FUN used C (gC/m2/s)
+ burnedoff_carbon => cnveg_carbonflux_inst%npp_burnedoff_patch , & ! Output: [real(r8)
+ ! (:) ] C that cannot be used for N uptake(gC/m2/s)
+ leafc_change => cnveg_carbonflux_inst%leafc_change_patch , & ! Output: [real(r8)
+ ! (:) ] Used C from the leaf (gC/m2/s)
+ leafn_storage_to_xfer => cnveg_nitrogenflux_inst%leafn_storage_to_xfer_patch , & ! Output: [real(r8) (:) ]
+ plant_ndemand => cnveg_nitrogenflux_inst%plant_ndemand_patch , & ! Iutput: [real(r8) (:)
+ ! ] N flux required to support initial GPP (gN/m2/s)
+ plant_ndemand_retrans => cnveg_nitrogenflux_inst%plant_ndemand_retrans_patch , & ! Output: [real(r8) (:)
+ ! ] N demand generated for FUN (gN/m2/s)
+ plant_ndemand_season => cnveg_nitrogenflux_inst%plant_ndemand_season_patch , & ! Output: [real(r8) (:)
+ ! ] N demand for seasonal deciduous forest (gN/m2/s)
+ plant_ndemand_stress => cnveg_nitrogenflux_inst%plant_ndemand_stress_patch , & ! Output: [real(r8) (:)
+ ! ] N demand for stress deciduous forest (gN/m2/s)
+ Nactive => cnveg_nitrogenflux_inst%Nactive_patch , & ! Output: [real(r8) (:)
+ ! ] Mycorrhizal N uptake (gN/m2/s)
+ Nnonmyc => cnveg_nitrogenflux_inst%Nnonmyc_patch , & ! Output: [real(r8) (:)
+ ! ] Non-mycorrhizal N uptake (gN/m2/s)
+ Nam => cnveg_nitrogenflux_inst%Nam_patch , & ! Output: [real(r8) (:) ] AM
+ ! uptake (gN/m2/s)
+ Necm => cnveg_nitrogenflux_inst%Necm_patch , & ! Output: [real(r8) (:) ] ECM
+ ! uptake (gN/m2/s)
+ Nactive_no3 => cnveg_nitrogenflux_inst%Nactive_no3_patch , & ! Output: [real(r8) (:)
+ ! ] Mycorrhizal N uptake (gN/m2/s)
+ Nnonmyc_no3 => cnveg_nitrogenflux_inst%Nnonmyc_no3_patch , & ! Output: [real(r8) (:)
+ ! ] Non-mycorrhizal N uptake (gN/m2/s)
+ Nam_no3 => cnveg_nitrogenflux_inst%Nam_no3_patch , & ! Output: [real(r8) (:)
+ ! ] AM uptake (gN/m2/s)
+ Necm_no3 => cnveg_nitrogenflux_inst%Necm_no3_patch , & ! Output: [real(r8) (:)
+ ! ] ECM uptake (gN/m2/s)
+ Nactive_nh4 => cnveg_nitrogenflux_inst%Nactive_nh4_patch , & ! Output: [real(r8) (:)
+ ! ] Mycorrhizal N uptake (gN/m2/s)
+ Nnonmyc_nh4 => cnveg_nitrogenflux_inst%Nnonmyc_nh4_patch , & ! Output: [real(r8) (:)
+ ! ] Non-mycorrhizal N uptake (gN/m2/s)
+ Nam_nh4 => cnveg_nitrogenflux_inst%Nam_nh4_patch , & ! Output: [real(r8) (:)
+ ! ] AM uptake (gN/m2/s)
+ Necm_nh4 => cnveg_nitrogenflux_inst%Necm_nh4_patch , & ! Output: [real(r8) (:)
+ ! ] ECM uptake (gN/m2/s)
+ Npassive => cnveg_nitrogenflux_inst%Npassive_patch , & ! Output: [real(r8) (:)
+ ! ] Passive N uptake (gN/m2/s)
+ Nfix => cnveg_nitrogenflux_inst%Nfix_patch , & ! Output: [real(r8) (:) ]
+ ! Symbiotic BNF (gN/m2/s)
+ cost_nfix => cnveg_nitrogenflux_inst%cost_Nfix_patch , & ! Output: [real(r8) (:)
+ ! ] Cost of fixation gC:gN
+ cost_nactive => cnveg_nitrogenflux_inst%cost_Nactive_patch , & ! Output: [real(r8) (:) ]
+ ! Cost of active uptake gC:gN
+ cost_nretrans => cnveg_nitrogenflux_inst%cost_Nretrans_patch , & ! Output: [real(r8) (:) ]
+ ! Cost of retranslocation gC:gN
+ nuptake_npp_fraction_patch => cnveg_nitrogenflux_inst%nuptake_npp_fraction_patch , & ! Output: [real(r8) (:)
+ ! ] frac of NPP in NUPTAKE
+
+ c_allometry => cnveg_state_inst%c_allometry_patch , & ! Output: [real(r8) (:) ] C
+ ! allocation index (DIM)
+ n_allometry => cnveg_state_inst%n_allometry_patch , & ! Output: [real(r8) (:) ] N
+ ! allocation index (DIM)
+ leafn_storage => cnveg_nitrogenstate_inst%leafn_storage_patch , & ! Input: [real(r8) (:)
+ ! ] (gN/m2) leaf N store
+ nfix_to_sminn => soilbiogeochem_nitrogenflux_inst%nfix_to_sminn_col , & ! Output: [real(r8) (:)]
+ ! symbiotic/asymbiotic N fixation to soil mineral N (gN/m2
+ ! /s)
+ Nretrans => cnveg_nitrogenflux_inst%Nretrans_patch , & ! Output: [real(r8) (:)
+ ! ] Retranslocation N uptake (gN/m2/s)
+ Nretrans_season => cnveg_nitrogenflux_inst%Nretrans_season_patch , & ! Output: [real(r8) (:)
+ ! ] Retranslocation N uptake (gN/m2/s)
+ Nretrans_stress => cnveg_nitrogenflux_inst%Nretrans_stress_patch , & ! Output: [real(r8) (:)
+ ! ] Retranslocation N uptake (gN/m2/s)
+ Nuptake => cnveg_nitrogenflux_inst%Nuptake_patch , & ! Output: [real(r8) (:)
+ ! ] Total N uptake of FUN (gN/m2/s)
+ retransn_to_npool => cnveg_nitrogenflux_inst%retransn_to_npool_patch , & ! Output: [real(r8)
+ ! (:) ] deployment of retranslocated N (gN/m2/s)
+ free_retransn_to_npool => cnveg_nitrogenflux_inst%free_retransn_to_npool_patch , & ! Output: [real(r8)
+ ! uptake of free N from leaves (needed to allow RT during the night with no NPP
+ sminn_to_plant_fun => cnveg_nitrogenflux_inst%sminn_to_plant_fun_patch , & ! Output:
+ ! [real(r8) (:) ] Total soil N uptake of FUN (gN/m2/s)
+ sminn_to_plant_fun_vr => cnveg_nitrogenflux_inst%sminn_to_plant_fun_vr_patch , & ! Output:
+ ! [real(r8) (:) ] Total layer soil N uptake of FUN (gN/m2
+ ! /s)
+ sminn_to_plant_fun_no3_vr => cnveg_nitrogenflux_inst%sminn_to_plant_fun_no3_vr_patch , & ! Output: [real(r8)
+ ! (:) ] Total layer no3 uptake of FUN (gN/m2/s)
+ sminn_to_plant_fun_nh4_vr => cnveg_nitrogenflux_inst%sminn_to_plant_fun_nh4_vr_patch , & ! Output: [real(r8)
+ ! (:) ] Total layer nh4 uptake of FUN (gN/m2/s)
+ sminn_to_plant_vr => soilbiogeochem_nitrogenflux_inst%sminn_to_plant_vr_col , & ! Output: [real(r8) (:
+ ! ,:) ]
+ smin_no3_to_plant_vr => soilbiogeochem_nitrogenflux_inst%smin_no3_to_plant_vr_col , & ! Output: [real(r8) (:
+ ! ,:) ]
+ smin_nh4_to_plant_vr => soilbiogeochem_nitrogenflux_inst%smin_nh4_to_plant_vr_col , & ! Output: [real(r8) (:
+ ! ,:) ]
+ smin_vr_nh4 => soilbiogeochem_nitrogenstate_inst%smin_nh4_vr_col , & ! Input: [real(r8) (:,:) ] (gN/m3) soil mineral
+ ! NH4
+ smin_vr_no3 => soilbiogeochem_nitrogenstate_inst%smin_no3_vr_col , & ! Input: [real(r8) (:,:) ] (gN/m3) soil mineral
+ ! NO3
+ soilc_change => cnveg_carbonflux_inst%soilc_change_patch , & ! Output: [real(r8)
+ ! (:) ] Used C from the soil (gC/m2/s)
+ h2osoi_liq => waterstate_inst%h2osoi_liq_col , & ! Input: [real(r8) (:,:)]
+ ! liquid water (kg/m2) (new) (-nlevsno+1:nlevgrnd)
+ qflx_tran_veg => waterflux_inst%qflx_tran_veg_patch , & ! Input: [real(r8) (:) ]
+ ! vegetation transpiration (mm H2O/s) (+ = to atm)
+ t_soisno => temperature_inst%t_soisno_col , & ! Input: [real(r8) (:,:)]
+ ! soil temperature (Kelvin) (-nlevsno+1:nlevgrnd)
+ crootfr => soilstate_inst%crootfr_patch & ! Input: [real(r8) (:,:)]
+ ! fraction of roots for carbon in each soil layer (nlevgrnd)
+ )
+ !--------------------------------------------------------------------
+ !-----------
+ ! Initialize output fluxes, which were also initialized in CNFUNMod.
+ !--------------------------------------------------------------------
+ !-----------
+ local_use_flexibleCN = use_flexibleCN
+ steppday = 48._r8
+ qflx_tran_veg_layer = 0._r8
+ rootc_dens_step = 0._r8
+ plant_ndemand_pool = 0._r8
+
+ call t_startf('CNFUNzeroarrays')
+ do fp = 1,num_soilp ! PFT Starts
+ p = filter_soilp(fp)
+ availc_pool(p) = 0._r8
+ rootC(p) = 0._r8
+ litterfall_n(p) = 0._r8
+ burnedoff_carbon(p) = 0._r8
+ end do
+
+
+ do j = 1, nlevdecomp
+ do fp = 1,num_soilp ! PFT Starts
+ p = filter_soilp(fp)
+ c = patch%column(p)
+ rootc_dens(p,j) = 0._r8
+ cost_retran(p,j) = 0._r8
+ cost_fix(p,j) = 0._r8
+ cost_resis(p,j) = 0._r8
+ cost_res_resis(p,j) = 0._r8
+ cost_active_no3(p,j) = 0._r8
+ cost_active_nh4(p,j) = 0._r8
+ cost_nonmyc_no3(p,j) = 0._r8
+ cost_nonmyc_nh4(p,j) = 0._r8
+
+ sminn_no3_conc(c,j) = 0._r8
+ sminn_no3_layer(c,j) = 0._r8
+ sminn_nh4_conc(c,j) = 0._r8
+ sminn_nh4_layer(c,j) = 0._r8
+ end do
+ end do
+
+ do istp = 1, nstp
+ do fp = 1,num_soilp ! PFT Starts
+ p = filter_soilp(fp)
+ npp_remaining(p,istp) = 0._r8
+ permyc(p,istp) = 0._r8
+ plant_ndemand_pool_step(p,istp) = 0._r8
+ nt_uptake(p,istp) = 0._r8
+ npp_uptake(p,istp) = 0._r8
+ leafn_step(p,istp) = 0._r8
+ leafn_retrans_step(p,istp) = 0._r8
+ litterfall_n_step(p,istp) = 0._r8
+ litterfall_c_step(p,istp) = 0._r8
+ end do
+ do j = 1, nlevdecomp
+ do fp = 1,num_soilp ! PFT Starts
+ p = filter_soilp(fp)
+ sminn_no3_conc_step(p,j,istp) = 0._r8
+ sminn_no3_layer_step(p,j,istp) = 0._r8
+ sminn_no3_uptake(p,j,istp) = 0._r8
+ sminn_nh4_conc_step(p,j,istp) = 0._r8
+ sminn_nh4_layer_step(p,j,istp) = 0._r8
+ sminn_nh4_uptake(p,j,istp) = 0._r8
+ end do
+ end do
+ end do
+
+ do icost = 1, ncost6
+ do j = 1, nlevdecomp
+ costNit(j,icost) = big_cost
+ end do
+ end do
+
+ ! Time step of FUN
+ dt = real(get_step_size(), r8)
+ call t_stopf('CNFUNzeroarrays')
+ !--------------------------------------------------------------------
+ !----------------------------
+ ! Calculation starts
+ !--------------------------------------------------------------------
+ call t_startf('CNFUNcalcs1')
+ !----------------------------
+ do fp = 1,num_soilp ! PFT Starts
+ p = filter_soilp(fp)
+
+ litterfall_n(p) = (leafc_to_litter_fun(p) / leafcn_offset(p)) * dt
+ rootC(p) = frootc(p)
+
+ plantN(p) = leafn(p) + frootn(p) + livestemn(p) + livecrootn(p)
+ if (n_allometry(p).gt.0._r8) then
+ plantCN(p) = c_allometry(p)/n_allometry(p) !changed RF.
+ ! above code gives CN ratio too low.
+ else
+ plantCN(p) = 0._r8
+ end if
+ end do ! PFT ends
+ do istp = 1, nstp
+ do fp = 1,num_soilp ! PFT Starts
+ p = filter_soilp(fp)
+
+ if (istp.eq.ecm_step) then
+ permyc(p,istp) = perecm(ivt(p))
+ kc_active(p,istp) = ekc_active(ivt(p))
+ kn_active(p,istp) = ekn_active(ivt(p))
+ else
+ permyc(p,istp) = 1._r8 - perecm(ivt(p))
+ kc_active(p,istp) = akc_active(ivt(p))
+ kn_active(p,istp) = akn_active(ivt(p))
+ end if
+
+ if(leafc(p)>0.0_r8)then
+ ! N available in leaf which fell off in this timestep. Same fraction loss as C.
+ litterfall_c_step(p,istp) = dt * permyc(p,istp) * leafc_to_litter_fun(p)
+ litterfall_n_step(p,istp) = dt * permyc(p,istp) * leafn(p) * leafc_to_litter_fun(p)/leafc(p)
+ endif
+
+ if (season_decid(ivt(p)) == 1._r8.or.stress_decid(ivt(p)) == 1._r8) then
+ if (offset_flag(p) .ne. 1._r8) then
+ litterfall_n_step(p,istp) = 0.0_r8
+ litterfall_c_step(p,istp) = 0.0_r8
+ endif
+ endif
+
+ end do
+ end do
+
+ do j = 1, nlevdecomp
+ do fp = 1,num_soilp ! PFT Starts
+ p = filter_soilp(fp)
+ c = patch%column(p)
+ sminn_no3_layer(c,j)= smin_no3_to_plant_vr(c,j) * dzsoi_decomp(j) * dt
+ sminn_nh4_layer(c,j)= smin_nh4_to_plant_vr(c,j) * dzsoi_decomp(j) * dt
+ if (h2osoi_liq(c,j) < smallValue) then
+ sminn_no3_layer(c,j) = 0._r8
+ sminn_nh4_layer(c,j) = 0._r8
+ end if
+ sminn_no3_layer(c,j) = max(sminn_no3_layer(c,j),0._r8)
+ sminn_nh4_layer(c,j) = max(sminn_nh4_layer(c,j),0._r8)
+ if (h2osoi_liq(c,j) > smallValue) then
+ sminn_no3_conc(c,j) = sminn_no3_layer(c,j) / (h2osoi_liq(c,j) * 1000._r8) ! (gN/m2)/(gH2O/m2) (coverted from
+ ! kg2g)
+ sminn_nh4_conc(c,j) = sminn_nh4_layer(c,j) / (h2osoi_liq(c,j) * 1000._r8) ! (gN/m2)/(gH2O/m2) (coverted from
+ ! kg2g)
+ else
+ sminn_no3_conc(c,j) = 0._r8
+ sminn_nh4_conc(c,j) = 0._r8
+ end if
+ end do
+ end do
+
+ do istp = 1, nstp
+ do j = 1, nlevdecomp
+ do fp = 1,num_soilp ! PFT Starts
+ p = filter_soilp(fp)
+ c = patch%column(p)
+
+ sminn_no3_layer_step(p,j,istp) = sminn_no3_layer(c,j) * permyc(p,istp)
+ sminn_nh4_layer_step(p,j,istp) = sminn_nh4_layer(c,j) * permyc(p,istp)
+ sminn_no3_conc_step(p,j,istp) = sminn_no3_conc(c,j) * permyc(p,istp)
+ sminn_nh4_conc_step(p,j,istp) = sminn_nh4_conc(c,j) * permyc(p,istp)
+ end do
+ end do
+ end do
+ call t_stopf('CNFUNcalcs1')
+
+ call t_startf('CNFUNzeroarrays2')
+ do fp = 1,num_soilp ! PFT Starts
+ p = filter_soilp(fp)
+ n_passive_acc(p) = 0._r8
+ n_fix_acc_total(p) = 0._r8
+ n_retrans_acc_total(p) = 0._r8
+ npp_fix_acc_total(p) = 0._r8
+ n_nonmyc_no3_retrans_total(p) = 0._r8
+ n_nonmyc_nh4_retrans_total(p) = 0._r8
+ npp_retrans_acc_total(p) = 0._r8
+ n_am_no3_acc(p) = 0._r8
+ n_am_nh4_acc(p) = 0._r8
+ n_am_no3_retrans(p) = 0._r8
+ n_am_nh4_retrans(p) = 0._r8
+ n_ecm_no3_acc(p) = 0._r8
+ n_ecm_nh4_acc(p) = 0._r8
+ n_ecm_no3_retrans(p) = 0._r8
+ n_ecm_nh4_retrans(p) = 0._r8
+ n_active_no3_acc_total(p) = 0._r8
+ n_active_nh4_acc_total(p) = 0._r8
+ n_active_no3_retrans_total(p) = 0._r8
+ n_active_nh4_retrans_total(p) = 0._r8
+ n_nonmyc_no3_acc_total(p) = 0._r8
+ n_nonmyc_nh4_acc_total(p) = 0._r8
+ npp_active_no3_acc_total(p) = 0._r8
+ npp_active_nh4_acc_total(p) = 0._r8
+ npp_active_no3_retrans_total(p) = 0._r8
+ npp_active_nh4_retrans_total(p) = 0._r8
+ npp_nonmyc_no3_acc_total(p) = 0._r8
+ npp_nonmyc_nh4_acc_total(p) = 0._r8
+ npp_nonmyc_no3_retrans_total(p) = 0._r8
+ npp_nonmyc_nh4_retrans_total(p) = 0._r8
+ free_Nretrans(p) = 0._r8
+ end do
+
+ do j = 1, nlevdecomp
+ do fp = 1,num_soilp ! PFT Starts
+ p = filter_soilp(fp)
+ n_passive_no3_vr(p,j) = 0._r8
+ n_passive_nh4_vr(p,j) = 0._r8
+ n_active_no3_vr(p,j) = 0._r8
+ n_nonmyc_no3_vr(p,j) = 0._r8
+ n_active_nh4_vr(p,j) = 0._r8
+ n_nonmyc_nh4_vr(p,j) = 0._r8
+ end do
+ end do
+ do istp = 1, nstp
+ do fp = 1,num_soilp ! PFT Starts
+ p = filter_soilp(fp)
+ n_passive_step(p,istp) = 0._r8
+ n_fix_acc(p,istp) = 0._r8
+ n_retrans_acc(p,istp) = 0._r8
+ npp_fix_acc(p,istp) = 0._r8
+ npp_retrans_acc(p,istp) = 0._r8
+ n_active_no3_acc(p,istp) = 0._r8
+ n_active_nh4_acc(p,istp) = 0._r8
+ n_active_no3_retrans(p,istp) = 0._r8
+ n_active_nh4_retrans(p,istp) = 0._r8
+ n_nonmyc_no3_acc(p,istp) = 0._r8
+ n_nonmyc_nh4_acc(p,istp) = 0._r8
+ n_nonmyc_no3_retrans(p,istp) = 0._r8
+ n_nonmyc_nh4_retrans(p,istp) = 0._r8
+ npp_active_no3_acc(p,istp) = 0._r8
+ npp_active_nh4_acc(p,istp) = 0._r8
+ npp_active_no3_retrans(p,istp) = 0._r8
+ npp_active_nh4_retrans(p,istp) = 0._r8
+ npp_nonmyc_no3_acc(p,istp) = 0._r8
+ npp_nonmyc_nh4_acc(p,istp) = 0._r8
+ npp_nonmyc_no3_retrans(p,istp) = 0._r8
+ npp_nonmyc_nh4_retrans(p,istp) = 0._r8
+ end do
+ end do
+
+ burned_off_carbon = 0._r8