/
SoilN.f90
5674 lines (4198 loc) · 207 KB
/
SoilN.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
module Soiln2Module
use DataTypes
use infrastructure
! ====================================================================
! SoilN variables
! ====================================================================
! Short description:
! globals, parameters and constants
! Notes:
! none
! ----------------------- Declaration section ------------------------
Use ConstantsModule
integer max_wf_values ! maximum no. of index/values pairs for
parameter (max_wf_values = 10) ! specifying water factor on
! mineralization
integer max_pHf_values ! maximum no. of index/values pairs for
parameter (max_pHf_values = 10) ! specifying pH factor on
! nitrification
integer max_layer ! Maximum number of layers
parameter (max_layer = 100)
integer max_residues ! Maximum number of residues
parameter (max_residues = 100)
integer max_fom_type ! Maximum number of fom types
parameter (max_fom_type = 10)
integer residue_dim ! dimension number of residues
parameter (residue_dim = 2)
integer layer_dim ! dimension number of layers
parameter (layer_dim = 1)
integer nfract ! number of fractions of fresh organic
parameter (nfract = 3) ! matter
integer days_in_year_max ! Maximum number of days in a g_year
parameter (days_in_year_max = 366)
real C_in_fom ! fraction weight of C in carbohydrate
parameter (C_in_fom = 0.4)
real g_urea_min ! minimum urea allowed (kg/ha)
parameter (g_urea_min = 0.0)
integer on
parameter (on = 1)
integer off
parameter (off = 0)
! ====================================================================
type Soiln2Globals
sequence
! COEFFICIENTS
integer num_fom_types ! number of fom types read
integer fom_type ! integer representing type of fom
! CLIMATE
real amp ! annual amplitude in mean monthly
! temperature (oC)
real latitude ! latitude (degrees, negative for
! southern hemisphere)
real maxt ! maximum air temperature (oC)
real mint ! minimum air temperature (oC)
real radn ! solar radiation (MJ/m^2/day)
real salb ! bare soil albedo (unitless)
real surf_temp(days_in_year_max)
! actual soil surface temperatures (oC)
real ave_temp ! annual average ambient temperature(oC)
real dlt_soil_loss ! todays soil loss (t/ha)
! DATE
integer day_of_year ! day of year
integer year ! year
! INITIAL
real root_CN ! initial C:N ratio of roots ()
real root_CN_pool(nfract) ! initial C:N ratio of each of the three root composition pools (carbohydrate, cellulose, and lignin)
real root_wt ! initial root weight
real root_depth ! initial depth over which roots are distributed (mm)
real soil_CN ! soil C:N ratio ()
! POOLS
real biom_C(max_layer) ! biomass carbon (kg/ha)
real biom_N(max_layer) ! biomass nitrogen (kg/ha)
real fom_N(max_layer) ! nitrogen in FOM (kg/ha)
real fom_c_pool(nfract, max_layer)
! FOM C in each fraction (kg/ha)
real dlt_fom_c_pool1(max_layer) ! delta fom C pool in fraction 1 (kg/ha)
real dlt_fom_c_pool2(max_layer) ! delta fom C pool in fraction 2 (kg/ha)
real dlt_fom_c_pool3(max_layer) ! delta fom C pool in fraction 3 (kg/ha)
real fom_n_pool(nfract, max_layer)
! FOM N in each fraction (kg/ha)
real hum_C(max_layer) ! Humic C (kg/ha)
real hum_N(max_layer) ! Humic N (kg/ha)
real inert_C(max_layer) ! humic C that is not subject to
real biochar_c(max_layer) ! Ammount of biochar C that is in soil
! mineralization (kg/ha)
real NH4(max_layer) ! ammonium nitrogen(kg/ha)
real NO3(max_layer) ! nitrate nitrogen (kg/ha)
real NH4_yesterday(max_layer) ! yesterday's ammonium nitrogen(kg/ha)
real NO3_yesterday(max_layer) ! yesterday's nitrate nitrogen (kg/ha)
real urea(max_layer) ! Urea nitrogen (kg/ha)
integer num_residues ! number of residues decomposing (0-100)
! TRANSFORMATIONS
real dlt_biom_C_atm(max_layer)
! biomass C lost to atmosphere
! (kg/ha)
real dlt_biom_C_hum(max_layer)
! biomass C converted to humic
! (kg/ha)
real dlt_biom_N_min(max_layer)
! net biomass N mineralized (kg/ha)
real dlt_C_decomp(max_layer,max_residues)
! Residue C decomposed (kg/ha)
real dlt_C_incorp(max_layer)! Residue C incorporated into FOM
! (kg/ha)
real dlt_NO3_dnit(max_layer)! NO3 N denitrified (kg/ha)
real dlt_NH4_dnit(max_layer)! NH4 N denitrified
real n2o_atm (max_layer) ! amount of N20 produced
real dlt_fom_C_atm(nfract,max_layer)
! fom C lost to atmosphere
! (kg/ha)
real dlt_fom_C_biom(nfract,max_layer)
! fom C converted to biomass
! (kg/ha)
real dlt_fom_C_hum(nfract,max_layer)
! fom C converted to humic
! (kg/ha)
real dlt_fom_n(nfract,max_layer)
! fom N mineralised in each fraction
! (kg/ha)
real dlt_fom_N_min(max_layer)
! net fom N mineralized (kg/ha)
! (negative for immobilization)
real dlt_hum_C_atm(max_layer)
! humic C lost to atmosphere (kg/ha)
real dlt_hum_C_biom(max_layer)
! humic C converted to biomass
! (kg/ha)
real dlt_hum_N_min(max_layer)
! net humic N mineralized (kg/ha)
real dlt_N_decomp(max_residues)
! Residue N decomposed (kg/ha)
real dlt_fom_N_incorp(max_layer)
! Residue N incorporated into FOM
real dlt_res_c_atm(max_layer, max_residues)
! carbon from residues lost
! to atmosphere (kg/ha)
real dlt_res_c_biom(max_layer, max_residues)
! carbon from residues to biomass
real dlt_res_c_hum(max_layer, max_residues)
! carbon from residues to humic
real soilp_dlt_res_c_atm(max_layer) ! carbon from all residues to atmosphere in each layer (kg/ha) for 'get' by soilp
real soilp_dlt_res_c_hum(max_layer) ! carbon from all residues to humic in each layer (kg/ha) for 'get' by soilp
real soilp_dlt_res_c_biom(max_layer)! carbon from all residues to biom in each layer (kg/ha) for 'get' by soilp
real soilp_dlt_org_p(max_layer) ! variable needed by soilp in its calculations
real pot_C_decomp(max_residues)
! Potential residue C decomposition (kg/ha)
real pot_N_decomp(max_residues)
! Potential residue N decomposition (kg/ha)
real pot_P_decomp(max_residues)
! Potential residue P decomposition (kg/ha)
real dlt_res_C_decomp(max_layer, max_residues)
! residue C decomposition (kg/ha)
real dlt_res_N_decomp(max_layer, max_residues)
! residue N decomposition (kg/ha)
real dlt_res_nh4_min (max_layer)
! Net Residue NH4 mineralisation (kg/ha)
real dlt_res_no3_min (max_layer)
! Net Residue NO3 mineralisation (kg/ha)
real NO3_transform_net(max_layer)
! net NO3 transformation today
real NH4_transform_net(max_layer)
! net NH4 transformation today
real dlt_NO3_net(max_layer) ! net NO3 change today
real dlt_NH4_net(max_layer) ! net NH4 change today
! PROFILE
real sw_lim_dep(max_layer) !sv- denitrifcation variable added for henrike
real bd(max_layer) ! moist bulk density of soil (g/cm^3)
real dlayer(max_layer) ! thickness of soil layer (mm)
real dul_dep(max_layer) ! drained upper limit soil water content
! (mm)
real fr_biom_C(max_layer) ! initial ratio of biomass-C to
! mineralizable humic-C (0-1)
real fr_inert_C(max_layer) ! initial proportion of total soil C
! that is not subject to mineralization
! (0-1)
real ll15_dep(max_layer) ! lower limit (@15bar) of soil water
! content (mm)
real oc(max_layer) ! organic carbon concentration (%)
real ph(max_layer) ! pH of soil in a 1:1 soil-water slurry
real sat_dep(max_layer) ! saturated water content (mm)
real NH4_min(max_layer) ! minimum allowable NH4 (kg/ha)
real NO3_min(max_layer) ! minimum allowable NO3 (kg/ha)
real soil_temp(max_layer) ! soil temperature (oC)
real sw_dep(max_layer) ! soil water content (mm)
real dlt_N_sed ! total N / C losses
real dlt_C_loss_sed
integer p_N_reduction ! (on or off)
real dlt_rntrf(max_layer) ! nitrogen moved by nitrification
! (kg/ha)
real dlt_rntrf_eff(max_layer) ! effective nitrogen moved by nitrification
! (kg/ha)
real dlt_urea_hydrol(max_layer) ! nitrogen moved by hydrolysis (kg/ha)
real excess_nh4(max_layer) ! excess N required above NH4 supply
real DailyInitialC
real DailyInitialN
real oldC
real oldN
! CHARACTER
character soiltype*120 ! soil type spec used to determine mineralisation parameters.
character pond_active*10 ! parameter to indicate whether the soil is under flooded & ponded conditions
character residue_module*(Max_module_name_size)
! list of modules replying
character residue_name(max_residues)*(Max_module_name_size)
character residue_type(max_residues)*(Max_module_name_size)
! list of module types
character fom_types(max_fom_type)*32
! list of fom types
! LOGICAL
logical use_external_st ! flag for soil temperature
logical use_external_tav_amp ! flag for soil ph
logical use_external_ph ! flag for soil ph
logical use_organic_solutes ! flag for FOM leaching
real nitrification_inhibition(max_layer) ! nitrification inhibition -VOS added 13 Dec 09
real NH4_absorbed(max_layer) ! biochar related
real dlt_biochar_c_co2(max_layer)
real dlt_n_min_bc_tot(max_layer)
real dlt_bc_hum(max_layer)
real dlt_bc_biom(max_layer)
real bc_wfps_factor(max_layer)
end type Soiln2Globals
! ====================================================================
! type Soiln2Parameters
! end type Soiln2Parameters
! ====================================================================
type Soiln2Constants
sequence
real fbiom_lb ! lower bound for FBIOM
real fbiom_ub ! upper bound for FBIOM
real finert_lb ! lower bound for FINERT
real finert_ub ! upper bound for FINERT
real CNrf_coeff ! coeff. to determine the magnitude
! of C:N effects on decomposition of
! FOM ()
real CNrf_optCN ! C:N above which decomposition rate
! of FOM declines ()
real fom_min ! minimum allowable FOM (kg/ha)
real fr_fom(nfract,max_fom_type)
! carbohydrate, cellulose & lignin
! fractions of FOM (0-1)
real OC2OM_factor ! conversion from OC to OM
real opt_temp(2) ! Soil temperature above which there
! is no further effect on mineralisation
! and nitrification (oC)
real temp_exponent ! Exponent for power function used to
! calculate temperature factor (default 2.0)
real tfactor_zero ! Value for the temperature factor at 0 degreees
real NH4ppm_min ! minimum allowable NH4 (ppm)
real no3ppm_min ! minimum allowable NO3 (ppm)
real wf_min_index(max_wf_values)
! index specifying water content
! for water factor for mineralization
real wf_min_values(max_wf_values)
! value of water factor(mineralization)
! function at given index values
real wf_nit_index(max_wf_values)
! index specifying water content
! for water factor for nitrification
real wf_nit_values(max_wf_values)
! value of water factor(nitrification)
! function at given index values
real enr_a_coeff ! enrichment equation coefficients
real enr_b_coeff
real nitrification_pot ! Potential nitrification by soil (ppm)
real nh4_at_half_pot ! nh4 conc at half potential (ppm)
real pHf_nit_pH(max_pHf_values)
! pH values for specifying
! pH factor for nitrification
real pHf_nit_values(max_pHf_values)
! value of pH factor(nitrification)
! function for given pH values
real dnit_rate_coeff ! denitrification rate coefficient (kg/mg)
real dnit_wf_power ! denitrification water factor power term
real dnit_k1 ! k1 parameter from Thorburn et al (2010)
real dnit_wfps(max_wf_values) ! WFPS factor for n2o fraction of denitrification
real dnit_n2o_factor(max_wf_values) !Thorburn et al (2010)
integer num_dnit_wfps
real dnit_nitrf_loss ! fraction of nitrification lost as denitrification (0-1)
real wfps_lim !sv- added for henrike.
logical wfps_lim_exists
! MINERALISATION CONSTANTS
real ef_biom ! fraction of biomass C mineralized
! retained in system (0-1)
real ef_fom ! fraction of FOM C mineralized
! retained in system (0-1)
real ef_hum ! fraction of humic C mineralized
! retained in system (0-1)
real ef_res ! fraction of residue C mineralized
! retained in system (0-1)
real fr_biom_biom ! fraction of retained biomass C
! returned to biomass (0-1)
real fr_fom_biom ! fraction of retained FOM C
! transferred to biomass (0-1)
real fr_res_biom ! fraction of retained residue C
! transferred to biomass (0-1)
real mCN ! C:N ratio of microbes ()
real min_depth ! depth from which mineral N can be
! immobilized by decomposing residues
! (mm)
real rd_biom(2) ! potential rate of soil biomass
! mineralization (per day)
real rd_fom(nfract,2) ! maximum rate constants for
! decomposition of FOM pools (0-1)
real rd_hum(2) ! potential rate of humus
! mineralization (per day)
real fraction_urine_added
real rd_biom_old(2) !store the old decomposition rates
real rd_hum_old(2)
real rd_fom_old(nfract,2)
real ef_biom_old
real fr_biom_biom_old
real ef_fom_old
real fr_fom_biom_old
end type Soiln2Constants
! ====================================================================
type IDsType
sequence
integer :: ExternalMassFlow
integer :: new_solute
integer :: actualresiduedecompositioncalculated
integer :: reset
integer :: sum_report
integer :: IncorpFOM
integer :: tick
integer :: newmet
integer :: potentialresiduedecompositioncalculated
integer :: IncorpFOMPool
integer :: new_profile
integer :: process
integer :: NitrogenChanged
integer :: AddUrine
integer :: BiocharDecomposed
integer :: BiocharApplied
integer :: BulkDensityChangeTillage
end type IDsType
! instance variables.
common /InstancePointers/ ID,g,p,c
save InstancePointers
type (Soiln2Globals),pointer :: g
type (Soiln2Constants),pointer :: c
type (IDsType), pointer :: id
contains
! ===========================================================
subroutine soiln2_reset ()
! ===========================================================
implicit none
!+ Purpose
! Initialise SoilN module
!+ Mission Statement
! (Re)Initialise SoilN module
!+ Constant Values
character my_name*(*)
parameter (my_name='soiln2_reset')
!- Implementation Section ----------------------------------
call push_routine (my_name)
! Save State
call soiln2_save_state ()
! Zero internal State Variables
call soiln2_zero_variables ()
! Check data dependencies with other modules
call soiln2_check_data_supply ()
! Get information specific to the site
call soiln2_get_site_variables()
! Get information which may vary through time
call soiln2_get_other_variables ()
! Get all parameters from parameter file
call soiln2_read_param ()
! Get all coefficients from parameter file
call soiln2_read_constants ()
! Perform initial calculations from inputs
call soiln2_init_calc()
! Change of State
call soiln2_delta_state ()
call pop_routine (my_name)
return
end subroutine
! ===========================================================
subroutine soiln2_save_state ()
! ===========================================================
implicit none
!+ Sub-Program Arguments
!+ Purpose
! Calculate Organic Carbon Percentage
!+ Mission Statement
! Calculate Organic Carbon Percentage
!+ Calls
!+ Local Variables
!+ Constant Values
character*(*) myname ! name of current procedure
parameter (myname = 'soiln2_save_state')
!- Implementation Section ----------------------------------
call push_routine (myname)
! Calculations for OLD sysbal component
g%oldN = soiln2_total_n()
g%oldC = soiln2_total_c()
! Calculations for NEW sysbal component
g%DailyInitialC = soiln2_total_c()
g%DailyInitialN = soiln2_total_n()
call pop_routine (myname)
return
end subroutine
! ===========================================================
subroutine soiln2_delta_state ()
! ===========================================================
implicit none
!+ Sub-Program Arguments
!+ Purpose
! Calculate Organic Carbon Percentage
!+ Mission Statement
! Calculate Organic Carbon Percentage
!+ Calls
!+ Local Variables
real dltN
real newN
real dltC
real newC
!+ Constant Values
character*(*) myname ! name of current procedure
parameter (myname = 'soiln2_delta_state')
!- Implementation Section ----------------------------------
call push_routine (myname)
newN = soiln2_total_n()
newC = soiln2_total_c()
dltN = newN - g%oldN
dltC = newC - g%oldC
call soilN2_ExternalMassFlow (dltN)
call soilN2_ExternalMassFlowC (dltC)
call pop_routine (myname)
return
end subroutine
! ===========================================================
real function soiln2_total_c ()
! ===========================================================
implicit none
integer num_layers
integer layer ! layer number
real fom_c (max_layer) ! fresh organic C (kg/ha)
real carbon_tot ! total carbon in soil(kg/ha)
!- Implementation Section ----------------------------------
num_layers = count_of_real_vals (g%dlayer, max_layer)
call fill_real_array (fom_c, 0.0, max_layer)
do layer = 1, num_layers
fom_c(layer) = sum_real_array (g%fom_c_pool(1,layer), nfract)
end do
carbon_tot = 0.0
do layer = 1, num_layers
carbon_tot = carbon_tot + fom_c(layer)+ g%hum_c(layer)+ g%biom_c(layer)
end do
soiln2_total_c = carbon_tot
return
end function
! ===========================================================
real function soiln2_total_n ()
! ===========================================================
implicit none
integer num_layers
!- Implementation Section ----------------------------------
num_layers = count_of_real_vals (g%dlayer, max_layer)
soiln2_total_n = sum(g%fom_n(1:num_layers)) + sum(g%hum_n(1:num_layers)) + sum(g%biom_n(1:num_layers)) &
+ sum(g%no3(1:num_layers)) + sum(g%nh4(1:num_layers)) + sum(g%urea(1:num_layers))
return
end function
! ===========================================================
subroutine soiln2_read_param ()
! ===========================================================
implicit none
!+ Purpose
! Read in all parameters from parameter file.
!+ Mission Statement
! Read Parameters from par file
!+ Calls
!+ Constant Values
character*(*) section_name !
parameter (section_name = 'parameters')
!
character*(*) my_name
parameter (my_name='soiln2_read_param')
!+ Local Variables
integer i ! counter
integer layer ! Soil layer number
real no3(max_layer) ! soil nitrate(ppm)
real nh4(max_layer) ! soil ammonium(ppm)
integer numvals ! number of values read from file
real ureappm(max_layer) ! soil g_urea(ppm)
character string*80
!+ Initial Data Values
call fill_real_array (no3, 0.0, max_layer)
call fill_real_array (nh4, 0.0, max_layer)
call fill_real_array (ureappm,0.0, max_layer)
!- Implementation Section ----------------------------------
call push_routine (my_name)
call write_string ( new_line//' - Reading Parameters')
call read_real_var ('standard', 'fbiom_lb', '()', c%fbiom_lb, numvals, 0.0, 1.0)
call read_real_var ('standard', 'fbiom_ub', '()', c%fbiom_ub, numvals, 0.0, 1.0)
call read_real_var ('standard', 'finert_lb', '()', c%finert_lb, numvals, 0.0, 1.0)
call read_real_var ('standard', 'finert_ub', '()', c%finert_ub, numvals, 0.0, 1.0)
! read in setting for soil type which is used to determine the mineralisation
! model parameters section from the ini file.
g%soiltype = ' '
call read_char_var_optional (section_name, 'soiltype', '()', g%soiltype, numvals)
if (numvals.le.0) g%soiltype = 'standard'
! Get parameter file name from control file and open it
if (.not. g%use_external_st) then
! only need to read these if soil temp is not external
call get_real_var_optional ( unknown_module, 'amp','(oC)',g%amp,numvals,0.0,50.0)
if (numvals .ne.1) then
g%use_external_tav_amp = .false.
call read_real_var (section_name, 'amp', '(oC)', g%amp, numvals, 0.0, 50.0)
else
! got amp from system ok
g%use_external_tav_amp = .true.
endif
call get_real_var_optional (unknown_module,'tav','(oC)',g%ave_temp,numvals,0.0,50.0)
if (numvals .ne.1) then
if (g%use_external_tav_amp) then
call fatal_error (err_internal, 'Default AMP with external TAV not permitted.')
else
endif
call read_real_var (section_name, 'tav', '(oC)', g%ave_temp, numvals, 0.0, 50.0)
else
! got tav from system ok
if (g%use_external_tav_amp) then
else
call fatal_error (err_internal, 'External AMP with default TAV not permitted.')
endif
endif
endif
call read_real_var (section_name, 'root_cn', '()', g%root_cn, numvals, 0.0, 500.0)
call lbound_check_real_var_error(g%root_cn, 0.0, 'root_cn')
!dsg Optionally read in CN ratio in each of the fractions
call read_real_array_optional (section_name, 'root_cn_pool', 3, '()', g%root_cn_pool, numvals, 0.0, 1000.0)
!dsg Check if all values supplied. If not use average C:N ratio in all pools
if (numvals.lt.3) then
do i = 1,3
g%root_cn_pool(i)=g%root_cn
end do
endif
call read_real_var (section_name, 'root_wt', '(kg/ha)', g%root_wt, numvals, 0.0, 100000.0)
call lbound_check_real_var_error(g%root_wt, 0.0, 'root_wt')
call read_real_var_optional (section_name, 'root_depth', '(kg/ha)', g%root_depth, numvals, 0.0, 10000.0)
! dsg 180604 if 'root_depth' not provided, assume that 'root_wt' is distributed over whole profile
if (numvals.eq.0) then
g%root_depth = sum_real_array (g%dlayer, max_layer)
endif
call read_real_var (section_name, 'soil_cn', '()', g%soil_cn, numvals, 5.0, 30.0)
call lbound_check_real_var_error(g%soil_cn, 0.0, 'soil_cn')
call read_real_array (section_name, 'oc', max_layer, '(%)', g%oc, numvals, 0.01, 10.0)
call lbound_check_real_array_error(g%oc, 0.0, 'oc', numvals)
if (.not. g%use_external_ph) then
call read_real_array (section_name, 'ph', max_layer, '()', g%ph, numvals, 3.5, 11.0)
call lbound_check_real_array_error(g%ph, 0.0, 'ph', numvals)
endif
call read_real_array_error (section_name, 'fbiom', max_layer, '()', g%fr_biom_c, numvals, c%fbiom_lb, c%fbiom_ub)
call read_real_array_error ( &
section_name, 'finert', max_layer, '()', g%fr_inert_c, numvals, c%finert_lb, c%finert_ub)
call read_real_array (section_name, 'no3ppm', max_layer, '(ppm)', no3, numvals, 0.0, 300.0)
call lbound_check_real_array_error(no3, 0.0, 'no3', numvals)
call read_real_array (section_name, 'nh4ppm', max_layer, '(ppm)', nh4, numvals, 0.0, 300.0)
call lbound_check_real_array_error(g%nh4, 0.0, 'nh4', numvals)
call read_real_array_optional (section_name, 'ureappm', max_layer, '(ppm)', ureappm, numvals, 0.0, 600.0)
call read_real_var (section_name, 'enr_a_coeff', '()', c%enr_a_coeff, numvals, 1.0, 20.0)
call lbound_check_real_var_error(c%enr_a_coeff, 0.0, 'enr_a_coeff')
call read_real_var (section_name, 'enr_b_coeff', '()', c%enr_b_coeff, numvals, 0.0, 20.0)
call lbound_check_real_var_error(c%enr_b_coeff, 0.0, 'enr_b_coeff')
string = ' '
call read_char_var (section_name, 'profile_reduction', '()', string, numvals)
if (string(1:2) .eq. 'on') then
g%p_n_reduction = on
else
g%p_n_reduction = off
endif
call read_real_var_optional (section_name, 'fraction_urine_added', '(0-1)', c%fraction_urine_added, numvals, 0.0, 1.0)
if (numvals.le.0) c%fraction_urine_added = 0.75
string = ' '
call read_char_var_optional (section_name, 'use_organic_solutes', '()', string, numvals)
if (string(1:2) .eq. 'on') then
g%use_organic_solutes = .true.
else
g%use_organic_solutes = .false.
endif
do layer=1,max_layer
g%nh4(layer) = divide (nh4(layer), soiln2_fac (layer), 0.0)
g%no3(layer) = divide (no3(layer), soiln2_fac (layer), 0.0)
g%urea(layer) = divide (ureappm(layer), soiln2_fac (layer), 0.0)
end do
call read_real_var_optional (section_name, 'WFPS_lim', '(0-1)', c%wfps_lim, numvals, 0.0, 1.0)
if (numvals .eq. 0) then
c%wfps_lim_exists = .false.
else
c%wfps_lim_exists = .true.
write(*,*) 'WFPS_lim :', c%wfps_lim
endif
call pop_routine (my_name)
return
end subroutine
! ===========================================================
subroutine soiln2_zero_all_globals ()
! ===========================================================
implicit none
!+ Purpose
! Zero all global variables & arrays
!+ Mission statement
! Zero all global variables and arrays
!+ Constant Values
character my_name*(*) ! name of procedure
parameter (my_name = 'soiln2_zero_all_globals')
!- Implementation Section ----------------------------------
call push_routine (my_name)
! Globals
g%num_fom_types = 0
g%fom_type = 0
g%amp = 0.0
g%latitude = 0.0
g%maxt = 0.0
g%mint = 0.0
g%radn = 0.0
g%salb = 0.0
g%surf_temp(:) = 0.0
g%ave_temp = 0.0
g%dlt_soil_loss = 0.0
g%day_of_year = 0
g%year = 0
g%root_CN = 0.0
g%root_CN_pool(:) = 0.0
g%root_wt = 0.0
g%root_depth = 0.0
g%soil_CN = 0.0
g%biom_C(:) = 0.0
g%biom_N(:) = 0.0
g%fom_N(:) = 0.0
g%biochar_c(:) = 0.0
g%dlt_biochar_c_co2(:) = 0.0
g%dlt_n_min_bc_tot(:) = 0.0
g%dlt_bc_hum(:) = 0.0
g%dlt_bc_biom(:) = 0.0
g%bc_wfps_factor(:) = 0.0
g%fom_c_pool(:, :) = 0.0
g%dlt_fom_c_pool1(:) = 0.0
g%dlt_fom_c_pool2(:) = 0.0
g%dlt_fom_c_pool3(:) = 0.0
g%fom_n_pool(:, :) = 0.0
g%hum_C(:) = 0.0
g%hum_N(:) = 0.0
g%inert_C(:) = 0.0
g%NH4(:) = 0.0
g%NO3(:) = 0.0
g%NH4_yesterday(:) = 0.0
g%NO3_yesterday(:) = 0.0
g%urea(:) = 0.0
g%num_residues = 0
g%dlt_biom_C_atm(:)= 0.0
g%dlt_biom_C_hum(:) = 0.0
g%dlt_biom_N_min(:) = 0.0
g%dlt_C_decomp(:,:) = 0.0
g%dlt_C_incorp(:) = 0.0
g%dlt_NO3_dnit(:) = 0.0
g%dlt_NH4_dnit(:) = 0.0
g%N2O_atm(:) = 0.0
g%dlt_fom_C_atm(:,:) = 0.0
g%dlt_fom_C_biom(:,:) = 0.0
g%dlt_fom_C_hum(:,:) = 0.0
g%dlt_fom_n(:, :) = 0.0
g%dlt_fom_N_min(:) = 0.0
g%dlt_hum_C_atm(:) = 0.0
g%dlt_hum_C_biom(:) = 0.0
g%dlt_hum_N_min(:) = 0.0
g%dlt_N_decomp(:) = 0.0
g%dlt_fom_N_incorp(:) = 0.0
g%dlt_res_c_atm(:, :) = 0.0
g%dlt_res_c_biom(:, :) = 0.0
g%dlt_res_c_hum(:, :) = 0.0
g%soilp_dlt_res_c_atm(:) = 0.0
g%soilp_dlt_res_c_hum(:) = 0.0
g%soilp_dlt_res_c_biom(:)= 0.0
g%soilp_dlt_org_p(:) = 0.0
g%pot_C_decomp(:) = 0.0
g%pot_N_decomp(:) = 0.0
g%pot_P_decomp(:) = 0.0
g%dlt_res_C_decomp(:, :) = 0.0
g%dlt_res_N_decomp(:, :) = 0.0
g%dlt_res_nh4_min (:) = 0.0
g%dlt_res_no3_min (:) = 0.0
g%NO3_transform_net(:) = 0.0
g%NH4_transform_net(:) = 0.0
g%dlt_NO3_net(:) = 0.0
g%dlt_NH4_net(:) = 0.0
g%bd(:) = 0.0
g%dlayer(:) = 0.0
g%dul_dep(:) = 0.0
g%fr_biom_C(:) = 0.0
g%fr_inert_C(:) = 0.0
g%ll15_dep(:) = 0.0
g%oc(:) = 0.0
g%ph(:) = 0.0
g%sat_dep(:) = 0.0
g%NH4_min(:) = 0.0
g%NO3_min(:) = 0.0
g%soil_temp(:) = 0.0
g%sw_dep(:) = 0.0
g%dlt_N_sed = 0.0
g%dlt_C_loss_sed = 0.0
g%p_N_reduction = 0
g%dlt_rntrf(:) = 0.0
g%dlt_rntrf_eff(:) = 0.0
g%dlt_urea_hydrol(:) = 0.0
g%excess_nh4(:) = 0.0
g%DailyInitialC = 0.0
g%DailyInitialN = 0.0
g%oldC = 0.0
g%oldN = 0.0
g%soiltype = blank
g%pond_active = 'no'
g%residue_module = blank
g%residue_name(:) = blank
g%residue_type(:) = blank
g%fom_types(:) = blank
! I think that this needs to be true by default
! for comms to work - NIH
g%use_external_st = .true.
! Not sure about these - NIH
g%use_external_tav_amp = .false.
g%use_external_ph = .false.
g%use_organic_solutes = .false.
g%dlt_rntrf(:) = 0.0
g%dlt_rntrf_eff(:) = 0.0
g%dlt_urea_hydrol(:) = 0.0
g%excess_nh4(:) = 0.0
g%nitrification_inhibition(:) = 0.0 ! nitrification inhibition - default to no effect - VOS added 13 Dec 09, reviewed by RCichota (9/feb/2010)
g%NH4_absorbed(:) = 0.0
! Constants
c%CNrf_coeff = 0.0
c%CNrf_optCN = 0.0
c%fom_min = 0.0
c%fr_fom(:,:) = 0.0
c%OC2OM_factor = 0.0
c%opt_temp(:) = 0.0
c%temp_exponent = 0.0
c%tfactor_zero = 0.0
c%NH4ppm_min = 0.0
c%no3ppm_min = 0.0
c%wf_min_index(:) = 0.0
c%wf_min_values(:) = 0.0
c%wf_nit_index(:) = 0.0
c%wf_nit_values(:) = 0.0
c%enr_a_coeff = 0.0
c%enr_b_coeff = 0.0
c%nitrification_pot = 0.0
c%nh4_at_half_pot = 0.0
c%pHf_nit_pH(:) = 0.0
c%pHf_nit_values(:) = 0.0
c%dnit_rate_coeff = 0.0
c%dnit_wf_power = 0.0
c%dnit_k1 = 0.0
c%dnit_wfps(:) = 0.0
c%dnit_n2o_factor(:) = 0.0
c%num_dnit_wfps = 0
c%dnit_nitrf_loss = 0.0
c%ef_biom = 0.0
c%ef_fom = 0.0
c%ef_hum = 0.0
c%ef_res = 0.0
c%fr_biom_biom = 0.0
c%fr_fom_biom = 0.0
c%fr_res_biom = 0.0
c%mCN = 0.0
c%min_depth = 0.0
c%rd_biom(:) = 0.0
c%rd_fom(:,:) = 0.0
c%rd_hum(:) = 0.0
c%rd_hum_old(:) = 0.0
c%rd_biom_old(:) = 0.0
c%rd_fom_old(:,:) = 0.0
c%ef_biom_old = 0.0
c%fr_biom_biom_old = 0.0
c%ef_fom_old = 0.0
c%fr_fom_biom_old = 0.0
call pop_routine (my_name)
return
end subroutine
! ===========================================================
subroutine soiln2_zero_variables ()
! ===========================================================
implicit none
!+ Purpose
! Zero soil nitrogen variables
!+ Mission Statement
! Zero variables
!+ Constant Values
character my_name*(*) ! subroutine name
parameter (my_name = 'soiln2_zero_variables')
!- Implementation Section ----------------------------------
call push_routine (my_name)
g%amp = 0.0
g%latitude = 0.0
g%salb = 0.0
g%surf_temp = 0.0
g%ave_temp = 0.0
g%dlt_soil_loss = 0.0
g%root_CN = 0.0
g%root_wt = 0.0
g%soil_CN = 0.0
g%root_CN_pool(:) = 0.0
g%dlt_biom_C_atm = 0.0
g%dlt_biom_C_hum = 0.0
g%dlt_biom_N_min = 0.0
g%dlt_C_decomp = 0.0
g%dlt_C_incorp = 0.0
g%dlt_NO3_dnit = 0.0
g%dlt_NH4_dnit = 0.0
g%N2O_atm(:) =0.0
g%dlt_fom_C_atm = 0.0
g%dlt_fom_C_biom = 0.0
g%dlt_fom_C_hum = 0.0
g%dlt_fom_N_min = 0.0
g%dlt_hum_C_atm = 0.0
g%dlt_hum_C_biom = 0.0
g%dlt_hum_N_min = 0.0