160 double grams_soil[
MAXLYR];
161 double nitratePPM[
MAXLYR];
164 double co2_correction[
MAXLYR];
166 double n2ofrac, n2frac;
169 double min_nitrate_end;
176 double WFPS_threshold;
188 min_nitrate_end = 0.05;
191 grams_per_ug = 1.0E-6;
192 CM_per_METER = 100.0;
193 for (ilyr=0; ilyr <
MAXLYR; ilyr++) {
203 for (ilyr=0; ilyr < layers->
numlyrs; ilyr++) {
207 k[ilyr] =
max(layers->
tcoeff[ilyr], 0.001);
209 ntotflux[ilyr] = 0.0;
212 for (ilyr=0; ilyr < layers->
numlyrs; ilyr++) {
214 nitrate[ilyr] += k[ilyr] * (*newNO3);
223 leachdly(wfluxout, layers->
numlyrs, nitrate, *critflow, frlechd, stream,
224 *basef, *stormf, inorglch);
226 for (ilyr=0; ilyr < layers->
numlyrs; ilyr++) {
230 grams_soil[ilyr] = layers->
bulkd[ilyr] * layers->
width[ilyr] *
231 CM_per_METER * CM_per_METER;
232 nitratePPM[ilyr] = nitrate[ilyr] / grams_soil[ilyr] * ug_per_gram;
233 if (nitratePPM[ilyr] < min_nitrate) {
235 fprintf(stdout,
"CANNOT DENITRIFY layer %1d, nitrate[%1d] = %f\n",
236 ilyr, ilyr, nitrate[ilyr]);
240 co2PPM[ilyr] = k[ilyr] * (*newCO2) / grams_soil[ilyr] *
243 wfps_fc[ilyr] = layers->
fieldc[ilyr] /
249 WFPS_threshold = (dD0_fc >= 0.15) ? 0.80 : (dD0_fc*250 + 43)/100;
250 if (layers->
wfps[ilyr] <= WFPS_threshold) {
251 co2_correction[ilyr] = co2PPM[ilyr];
253 a = (dD0_fc >= 0.15) ? 0.004 : (-0.1 * dD0_fc + 0.019);
254 co2_correction[ilyr] = co2PPM[ilyr] * (1.0 + a *
255 (layers->
wfps[ilyr] - WFPS_threshold)*100);
271 fDno3 =
max(0.0, fDno3);
285 ((0.1 * pow(co2_correction[ilyr], 1.3)) - min_nitrate));
293 M =
min(0.113, dD0_fc) * (-1.25) + 0.145;
297 x_inflection = (9.0 - M * co2_correction[ilyr]);
304 (atan(0.6*
M_PI*(10.0*layers->
wfps[ilyr]-
305 x_inflection))) /
M_PI);
306 fDwfps =
max(0.0, fDwfps);
309 fprintf(stdout,
"\n%6s %6s %6s\n",
"fDwfps",
"fDno3",
"fDco2");
310 fprintf(stdout,
"%6.4lf %6.4lf %6.4lf\n", fDwfps,fDno3,fDco2);
316 if (*jday >= sitepar->
jdayStart && *jday <= sitepar->jdayEnd) {
319 Dtotflux = (fDno3 < fDco2) ? fDno3 : fDco2;
325 Dtotflux =
max(0.066, Dtotflux);
330 fprintf(stdout,
"Dtotflux = %8.4lf\n", Dtotflux);
342 k1 =
max(1.5, 38.4 - 350 * dD0_fc);
343 fRno3_co2 =
max(0.16 * k1, k1 * exp(-0.8 * nitratePPM[ilyr]/co2PPM[ilyr]));
351 fRwfps =
max(0.1, 0.015 * layers->
wfps[ilyr]*100 - 0.32);
355 Rn2n2o = fRno3_co2 * fRwfps;
361 fprintf(stdout,
"\n%6s %8s %8s %9s %2s %3s\n",
"fRwfps",
362 "nitratePPM",
"co2PPM",
"fRno3_co2",
"k1",
"dD0");
363 fprintf(stdout,
"%6.4lf %6.4lf %6.4lf %6.4lf %6.4lf %6.4lf\n",
364 fRwfps,nitratePPM[ilyr],co2PPM[ilyr],fRno3_co2,k1,dD0_fc);
365 fprintf(stdout,
"Ratio N2:N2O = %12.10lf\n", Rn2n2o);
371 ntotflux[ilyr] = Dtotflux * grams_soil[ilyr] * grams_per_ug;
372 n2oflux = ntotflux[ilyr] / (Rn2n2o + 1.0);
373 *Dn2oflux += n2oflux;
374 dN2Olyr[ilyr] = n2oflux;
375 *Dn2flux += ntotflux[ilyr] - n2oflux;
376 dN2lyr[ilyr] = ntotflux[ilyr] - n2oflux;
378 fprintf(stdout,
"\n%3s %6s %6s %6s %6s\n",
"lyr",
"n2o",
"n2",
380 fprintf(stdout,
"%3d %6.4lf %6.4lf %6.4lf\n", ilyr,
381 n2oflux, co2PPM[ilyr], nitratePPM[ilyr]);
386 fprintf(stdout,
"\nIn denitrify, Dn2oflux (gN/m2/day) = %12.10lf\n",
388 fprintf(stdout,
"In denitrify, Dn2flux (gN/m2/day) = %12.10lf\n",
392 if (*Dn2oflux < 1.0E-25) {
395 if (*Dn2flux < 1.0E-25) {
400 fprintf(stdout,
"In denitrify(1), Dn2oflux = %12.10lf\n", *Dn2oflux);
401 fprintf(stdout,
"In denitrify(1), Dn2flux = %12.10lf\n", *Dn2flux);
407 if (*Dn2oflux + *Dn2flux > 1.0E-30) {
408 n2ofrac = *Dn2oflux/(*Dn2oflux + *Dn2flux);
409 n2frac = *Dn2flux/(*Dn2oflux + *Dn2flux);
412 for (ilyr=0; ilyr < layers->
numlyrs; ilyr++) {
413 if (nitratePPM[ilyr] < min_nitrate) {
415 excess += ntotflux[ilyr];
417 printf(
"First IF check in loop, excess = %12.10lf\n", excess);
419 }
else if ((nitrate[ilyr] - ntotflux[ilyr]) >
420 (min_nitrate_end * grams_soil[ilyr] * grams_per_ug)) {
422 nitrate[ilyr] -= ntotflux[ilyr];
424 printf(
"Second IF check in loop, nitrate[%1d] = %12.10lf", ilyr,
426 printf(
" nitratePPM[%1d] = %12.10lf\n", ilyr, nitratePPM[ilyr]);
431 fluxout = (nitratePPM[ilyr] - min_nitrate_end) *
432 grams_soil[ilyr] * grams_per_ug;
433 excess += (ntotflux[ilyr] - fluxout);
434 nitrate[ilyr] = min_nitrate_end * grams_soil[ilyr] * grams_per_ug;
436 printf(
"Third IF check in loop, excess = %12.10lf\n",excess);
437 printf(
"nitrate[%1d] = %12.10lf", ilyr, nitrate[ilyr]);
438 printf(
" nitratePPM[%1d] = %12.10lf\n", ilyr, nitratePPM[ilyr]);
443 *Dn2oflux -= n2ofrac * excess;
444 *Dn2flux -= n2frac * excess;
447 printf(
" n2ofrac = %12f\n", n2ofrac);
448 printf(
" n2frac = %12f\n", n2frac);
449 fprintf(stdout,
" n2o_excess = %12.10lf\n", n2ofrac * excess);
450 fprintf(stdout,
" n2_excess = %12.10lf\n", n2frac * excess);
458 fprintf(stdout,
"In denitrify(2), Dn2oflux = %12.10lf\n", *Dn2oflux);
459 fprintf(stdout,
"In denitrify(2), Dn2flux = %12.10lf\n", *Dn2flux);
double f_arctangent(double x, double A[])
Definition: pi_funcs.c:71
double fieldc[MAXLYR]
Definition: soilwater.h:76
void leachdly(double wfluxout[], int numlyrs, double nitrate[], double critflow, double frlechd[], double stream[], double basef, double stormf, double *inorglch)
Definition: leachdly.c:58
int jdayStart
Definition: soilwater.h:126
int numlyrs
Definition: soilwater.h:86
#define min(a, b)
Definition: diffusiv.c:66
double bulkd[MAXLYR]
Definition: soilwater.h:75
void wfps(LAYERPAR_SPT layers)
Definition: wfps.c:50
double width[MAXLYR]
Definition: soilwater.h:71
#define max(a, b)
Definition: diffusiv.c:67
double diffusiv(double *A, double *bulkden, double *wfps)
Definition: diffusiv.c:69
double tcoeff[MAXLYR]
Definition: soilwater.h:79
double wfps[MAXLYR]
Definition: soilwater.h:92
#define PARTDENS
Definition: diffusiv.c:65
#define M_PI
Definition: denitrify.c:139
#define MAXLYR
Definition: swconst.h:8