Beispiel #1
0
        /// <summary>Calculates volumetric soil water for the given sample.</summary>
        /// <param name="sample">The sample.</param>
        /// <param name="soil">The soil.</param>
        /// <returns>Volumetric water (mm/mm)</returns>
        private static double[] SWVolumetric(Sample sample, Soil soil)
        {
            if (sample.SWUnits == Sample.SWUnitsEnum.Volumetric || sample.SW == null)
            {
                return(sample.SW);
            }
            else
            {
                // convert the numbers
                if (sample.SWUnits == Sample.SWUnitsEnum.Gravimetric)
                {
                    double[] bd = LayerStructure.BDMapped(soil, sample.Thickness);

                    return(MathUtilities.Multiply(sample.SW, bd));
                }
                else
                {
                    return(MathUtilities.Divide(sample.SW, sample.Thickness)); // from mm to mm/mm
                }
            }
        }
Beispiel #2
0
        /// <summary>Convert soil units to APSIM standard.</summary>
        /// <param name="soil">The soil.</param>
        public static void Convert(Soil soil)
        {
            // Convert soil organic matter OC to total %
            if (soil.SoilOrganicMatter != null)
            {
                soil.SoilOrganicMatter.OC      = OCTotalPercent(soil.SoilOrganicMatter.OC, soil.SoilOrganicMatter.OCUnits);
                soil.SoilOrganicMatter.OCUnits = SoilOrganicMatter.OCUnitsEnum.Total;
            }

            // Convert nitrogen to ppm.
            if (soil.Nitrogen != null)
            {
                double[] bd = LayerStructure.BDMapped(soil, soil.Nitrogen.Thickness);
                soil.Nitrogen.NO3      = Nppm(soil.Nitrogen.NO3, soil.Nitrogen.Thickness, soil.Nitrogen.NO3Units, bd);
                soil.Nitrogen.NO3Units = Nitrogen.NUnitsEnum.ppm;

                soil.Nitrogen.NH4      = Nppm(soil.Nitrogen.NH4, soil.Nitrogen.Thickness, soil.Nitrogen.NH4Units, bd);
                soil.Nitrogen.NH4Units = Nitrogen.NUnitsEnum.ppm;
            }

            // Convert analysis.
            if (soil.Analysis != null)
            {
                soil.Analysis.PH      = PHWater(soil.Analysis.PH, soil.Analysis.PHUnits);
                soil.Analysis.PHUnits = Analysis.PHUnitsEnum.Water;
            }

            // Convert all samples.
            if (soil.Samples != null)
            {
                foreach (Sample sample in soil.Samples)
                {
                    // Convert sw units to volumetric.
                    if (sample.SW != null)
                    {
                        sample.SW = SWVolumetric(sample, soil);
                    }
                    sample.SWUnits = Sample.SWUnitsEnum.Volumetric;

                    // Convert no3 units to ppm.
                    if (sample.NO3 != null)
                    {
                        double[] bd = LayerStructure.BDMapped(soil, sample.Thickness);
                        sample.NO3 = Nppm(sample.NO3, sample.Thickness, sample.NO3Units, bd);
                    }
                    sample.NO3Units = Nitrogen.NUnitsEnum.ppm;

                    // Convert nh4 units to ppm.
                    if (sample.NH4 != null)
                    {
                        double[] bd = LayerStructure.BDMapped(soil, sample.Thickness);
                        sample.NH4 = Nppm(sample.NH4, sample.Thickness, sample.NH4Units, bd);
                    }
                    sample.NH4Units = Nitrogen.NUnitsEnum.ppm;

                    // Convert OC to total (%)
                    if (sample.OC != null)
                    {
                        sample.OC = OCTotalPercent(sample.OC, sample.OCUnits);
                    }
                    sample.OCUnits = SoilOrganicMatter.OCUnitsEnum.Total;

                    // Convert PH to water.
                    if (sample.PH != null)
                    {
                        sample.PH = PHWater(sample.PH, sample.PHUnits);
                    }
                    sample.PHUnits = Analysis.PHUnitsEnum.Water;
                }
            }
        }