Ejemplo n.º 1
0
        // ------------------------------------------------------------
        // Read in all crop parameters from all crop sections in
        // specified file
        // ------------------------------------------------------------
        static private void ReadCropSections(string SectionBit, string FileName, Soil NewSoil)
        {
            string[] Sections = ApsimFile.IniFile.INIReadAllSections(FileName);
            foreach (string Section in Sections)
            {
                if (ApsimFile.IniFile.INIRead(FileName, Section, "ll") != "")
                {
                    // get the crop name
                    StringCollection SectionBits = StringManip.SplitStringHonouringQuotes(Section, ".");
                    if (SectionBits.Count == 3 && SectionBits[0].ToLower() == SectionBit.ToLower())
                    {
                        string CropName = SectionBits[1];
                        NewSoil.AddCrop(CropName);

                        double[] ll;
                        string   LLValue = GetStringValue(FileName, Section, "ll");
                        if (LLValue.ToLower() == "#ll")
                        {
                            ll = NewSoil.LL15;
                        }
                        else
                        {
                            ll = GetDoubleValues(FileName, Section, "ll");
                        }

                        NewSoil.SetCrop(CropName,
                                        ll,
                                        GetDoubleValues(FileName, Section, "kl"),
                                        GetDoubleValues(FileName, Section, "xf"));
                    }
                }
            }
        }
Ejemplo n.º 2
0
        static private string CreateSoilXmlFromSpreadsheet(DataTable Table, ref int Row)
        {
            // Create a new soil from the the specified table.
            // At end of this method, row will be pointing to the next
            // soil.
            string name = GetStringValue(Table, "Name", Row);

            if (name == "")
            {
                throw new Exception("Cannot find a soil name");
            }

            XmlDocument Doc      = new XmlDocument();
            XmlNode     SoilNode = Doc.CreateElement("Soil");

            XmlHelper.SetName(SoilNode, name);
            Soil NewSoil = new Soil(SoilNode);

            NewSoil.State             = GetStringValue(Table, "State", Row);
            NewSoil.Region            = GetStringValue(Table, "Region", Row);
            NewSoil.NearestTown       = GetStringValue(Table, "NearestTown", Row);
            NewSoil.Site              = GetStringValue(Table, "Site", Row);
            NewSoil.ApsoilNumber      = GetStringValue(Table, "APSoilNumber", Row);
            NewSoil.Classification    = GetStringValue(Table, "Classification", Row);
            NewSoil.Latitude          = MathUtility.Round(GetDoubleValue(Table, "Latitude(WGS84)", Row), 3);
            NewSoil.Longitude         = MathUtility.Round(GetDoubleValue(Table, "Longitude(WGS84)", Row), 3);
            NewSoil.LocationAccuracy  = GetStringValue(Table, "LocationAccuracy", Row);
            NewSoil.DataSource        = GetStringValue(Table, "DataSource", Row);
            NewSoil.Comment           = GetStringValue(Table, "Comments", Row);
            NewSoil.NaturalVegetation = GetStringValue(Table, "NaturalVegetation", Row);

            double SummerU = GetDoubleValue(Table, "SummerU", Row);

            if (SummerU != MathUtility.MissingValue)
            {
                NewSoil.SetSummerWinterUCona(GetDoubleValue(Table, "SummerU", Row), GetDoubleValue(Table, "WinterU", Row),
                                             GetDoubleValue(Table, "SummerCona", Row), GetDoubleValue(Table, "WinterCona", Row),
                                             GetStringValue(Table, "SummerDate", Row), GetStringValue(Table, "WinterDate", Row));
            }
            else
            {
                NewSoil.SetUCona(GetDoubleValue(Table, "U", Row), GetDoubleValue(Table, "Cona", Row));
            }

            NewSoil.Salb        = GetDoubleValue(Table, "Salb", Row);
            NewSoil.DiffusConst = GetDoubleValue(Table, "DiffusConst", Row);
            NewSoil.DiffusSlope = GetDoubleValue(Table, "DiffusSlope", Row);
            NewSoil.CN2Bare     = GetDoubleValue(Table, "CN2Bare", Row);
            NewSoil.CNRed       = GetDoubleValue(Table, "CNRed", Row);
            NewSoil.CNCov       = GetDoubleValue(Table, "CNCov", Row);
            NewSoil.RootCN      = GetDoubleValue(Table, "RootCN", Row);
            NewSoil.RootWT      = GetDoubleValue(Table, "RootWT", Row);
            NewSoil.SoilCN      = GetDoubleValue(Table, "SoilCN", Row);
            NewSoil.EnrACoeff   = GetDoubleValue(Table, "EnrACoeff", Row);
            NewSoil.EnrBCoeff   = GetDoubleValue(Table, "EnrBCoeff", Row);

            // Work out how many layers we're dealing with.
            int NumLayers = 0;

            while (Row + NumLayers < Table.Rows.Count &&
                   name.ToLower() == Table.Rows[Row + NumLayers]["Name"].ToString().ToLower())
            {
                NumLayers++;
            }

            // Store thickness.
            NewSoil.Thickness = GetDoubleValues(Table, "Thickness", NumLayers, Row, 0);

            // Store rest of soil layered variables.
            NewSoil.BD               = GetDoubleValues(Table, "bd", NumLayers, Row, 3);
            NewSoil.Rocks            = GetDoubleValues(Table, "Rocks", NumLayers, Row, 0);
            NewSoil.LL15             = GetDoubleValues(Table, "LL15", NumLayers, Row, 3);
            NewSoil.Airdry           = GetDoubleValues(Table, "Airdry", NumLayers, Row, 3);
            NewSoil.DUL              = GetDoubleValues(Table, "DUL", NumLayers, Row, 3);
            NewSoil.SAT              = GetDoubleValues(Table, "SAT", NumLayers, Row, 3);
            NewSoil.Texture          = GetStringValues(Table, "Texture", NumLayers, Row);
            NewSoil.SWCON            = GetDoubleValues(Table, "SWCON", NumLayers, Row, 2);
            NewSoil.MWCON            = GetDoubleValues(Table, "MWCON", NumLayers, Row, 2);
            NewSoil.FBIOM            = GetDoubleValues(Table, "FBIOM", NumLayers, Row, 2);
            NewSoil.FINERT           = GetDoubleValues(Table, "FINERT", NumLayers, Row, 1);
            NewSoil.KS               = GetDoubleValues(Table, "KS", NumLayers, Row, 2);
            NewSoil.OC               = GetDoubleValues(Table, "OC", NumLayers, Row, 2);
            NewSoil.EC               = GetDoubleValues(Table, "EC", NumLayers, Row, 1);
            NewSoil.PH               = GetDoubleValues(Table, "PH", NumLayers, Row, 1);
            NewSoil.CL               = GetDoubleValues(Table, "CL", NumLayers, Row, 1);
            NewSoil.Boron            = GetDoubleValues(Table, "Boron", NumLayers, Row, 1);
            NewSoil.CEC              = GetDoubleValues(Table, "CEC", NumLayers, Row, 1);
            NewSoil.Ca               = GetDoubleValues(Table, "Ca", NumLayers, Row, 1);
            NewSoil.Mg               = GetDoubleValues(Table, "Mg", NumLayers, Row, 1);
            NewSoil.Na               = GetDoubleValues(Table, "Na", NumLayers, Row, 1);
            NewSoil.K                = GetDoubleValues(Table, "K", NumLayers, Row, 1);
            NewSoil.ESP              = GetDoubleValues(Table, "ESP", NumLayers, Row, 1);
            NewSoil.Mn               = GetDoubleValues(Table, "Mn", NumLayers, Row, 1);
            NewSoil.Al               = GetDoubleValues(Table, "Al", NumLayers, Row, 1);
            NewSoil.ParticleSizeSand = GetDoubleValues(Table, "ParticleSizeSand", NumLayers, Row, 1);
            NewSoil.ParticleSizeSilt = GetDoubleValues(Table, "ParticleSizeSilt", NumLayers, Row, 1);
            NewSoil.ParticleSizeClay = GetDoubleValues(Table, "ParticleSizeClay", NumLayers, Row, 1);
            //dph NewSoil.InitialNitrogen.NO3 = GetDoubleValues(Table, "NO3", NumLayers, Row, 3);
            //dph NewSoil.InitialNitrogen.NH4 = GetDoubleValues(Table, "NH4", NumLayers, Row, 3);

            // Now get a list of all crop names.
            StringCollection Crops = new StringCollection();

            for (int i = 0; i != Table.Columns.Count; i++)
            {
                string ColumnName = Table.Columns[i].ColumnName;
                if (ColumnName.Length > 2 && ColumnName.Substring(0, 3).ToLower() == "ll(")
                {
                    Crops.Add(StringManip.SplitOffBracketedValue(ref ColumnName, '(', ')'));
                }
            }

            // Now import all crop stuff.
            for (int i = 0; i != Crops.Count; i++)
            {
                double[] ll = GetDoubleValues(Table, "LL(" + Crops[i] + ")", NumLayers, Row, 3);
                double[] kl = GetDoubleValues(Table, "KL(" + Crops[i] + ")", NumLayers, Row, 3);
                double[] xf = GetDoubleValues(Table, "XF(" + Crops[i] + ")", NumLayers, Row, 2);

                bool AllMissingValues = true;
                for (int j = 0; j != ll.Length && AllMissingValues; j++)
                {
                    AllMissingValues = (AllMissingValues && ll[j] == MathUtility.MissingValue &&
                                        kl[j] == MathUtility.MissingValue && xf[j] == MathUtility.MissingValue);
                }

                if (!AllMissingValues)
                {
                    NewSoil.AddCrop(Crops[i]);
                    NewSoil.SetCrop(Crops[i], ll, kl, xf);
                }
            }

            Row += NumLayers;
            return(NewSoil.Data.OuterXml);
        }