/// <summary> /// Return the specified crop to caller. Will return null if not found. /// </summary> public SoilCrop Crop(string CropName) { SoilCrop C = FindCrop(CropName); if (C == null) { return(null); } else { return(C); } }
/// <summary> /// Read in all crop parameters from all crop sections. /// </summary> static private void ReadCropSections(string SectionBit, string FileName, Soil NewSoil, double[] Thickness) { string[] Sections = IniFile.INIReadAllSections(FileName); foreach (string Section in Sections) { if (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]; double[] ll; string LLValue = GetStringValue(FileName, Section, "ll"); if (LLValue.ToLower() == "#ll") { ll = NewSoil.Water.LL15; } else { ll = GetDoubleValues(FileName, Section, "ll"); } CropName = CropName.Replace(" ", ""); SoilCrop NewCrop = new SoilCrop(); NewCrop.Name = CropName; NewCrop.Thickness = NewSoil.Water.Thickness; NewCrop.LL = ll; NewCrop.KL = GetDoubleValues(FileName, Section, "kl"); NewCrop.XF = GetDoubleValues(FileName, Section, "xf"); NewSoil.Water.Crops.Add(NewCrop); } } } }
/// <summary> /// Fill the specified SoilNode with data from the specified table. /// </summary> public static Soil[] TableToSoils(DataTable Table, ProgressNotifier Notifier = null) { List <Soil> Soils = new List <Soil>(); string[] Names = DataTableUtility.GetColumnAsStrings(Table, "Name"); if (Names.Length == 0) { throw new Exception("Cannot find a name column in spreadsheet"); } // Loop through all blocks of rows in datatable from XLS, create a // soil and store soil in correct location in the AllSoils XML. int StartRow = 0; int counter = 0; while (StartRow < Table.Rows.Count) { // Calculate how many rows for this soil int NumRows = 1; for (int i = StartRow + 1; i < Names.Length; i++) { if (Names[i] == Names[StartRow]) { NumRows++; } else { break; } } Soil NewSoil = new Soil(); Soils.Add(NewSoil); NewSoil.Name = Names[StartRow]; NewSoil.Country = GetStringValue(Table, StartRow, "Country"); NewSoil.State = GetStringValue(Table, StartRow, "State"); NewSoil.Region = GetStringValue(Table, StartRow, "Region"); NewSoil.NearestTown = GetStringValue(Table, StartRow, "NearestTown"); NewSoil.Site = GetStringValue(Table, StartRow, "Site"); NewSoil.ApsoilNumber = GetStringValue(Table, StartRow, "APSoilNumber"); NewSoil.SoilType = GetStringValue(Table, StartRow, "Soil type texture or other descriptor"); NewSoil.LocalName = GetStringValue(Table, StartRow, "LocalName"); NewSoil.ASCOrder = GetStringValue(Table, StartRow, "ASC_Order"); NewSoil.ASCSubOrder = GetStringValue(Table, StartRow, "ASC_Sub-order"); NewSoil.Latitude = GetDoubleValue(Table, StartRow, "Latitude"); NewSoil.Longitude = GetDoubleValue(Table, StartRow, "Longitude"); NewSoil.LocationAccuracy = GetStringValue(Table, StartRow, "LocationAccuracy"); NewSoil.YearOfSampling = GetIntegerValue(Table, StartRow, "YearOfSampling"); NewSoil.DataSource = GetStringValue(Table, StartRow, "DataSource"); NewSoil.Comments = GetStringValue(Table, StartRow, "Comments"); NewSoil.NaturalVegetation = GetStringValue(Table, StartRow, "NaturalVegetation"); NewSoil.RecordNumber = GetIntegerValue(Table, StartRow, "RecordNo"); NewSoil.Analysis.MunsellColour = GetStringValues(Table, "MunsellColour", NumRows, StartRow); NewSoil.Analysis.MunsellMetadata = GetCodeValues(Table, "MunsellColourCode", NumRows, StartRow); NewSoil.Water.Thickness = MathUtility.RemoveMissingValuesFromBottom(GetDoubleValues(Table, "Thickness (mm)", NumRows, StartRow)); int NumLayers = NewSoil.Water.Thickness.Length; NewSoil.Water.BD = GetDoubleValues(Table, "BD (g/cc)", NumLayers, StartRow); NewSoil.Water.BDMetadata = GetCodeValues(Table, "BDCode", NumLayers, StartRow); NewSoil.Analysis.Rocks = GetDoubleValues(Table, "Rocks (%)", NumRows, StartRow); NewSoil.Analysis.RocksMetadata = GetCodeValues(Table, "RocksCode", NumRows, StartRow); NewSoil.Analysis.Texture = GetStringValues(Table, "Texture", NumRows, StartRow); NewSoil.Analysis.TextureMetadata = GetCodeValues(Table, "TextureCode", NumRows, StartRow); NewSoil.Water.SAT = GetDoubleValues(Table, "SAT (mm/mm)", NumLayers, StartRow); NewSoil.Water.SATMetadata = GetCodeValues(Table, "SATCode", NumLayers, StartRow); NewSoil.Water.DUL = GetDoubleValues(Table, "DUL (mm/mm)", NumLayers, StartRow); NewSoil.Water.DULMetadata = GetCodeValues(Table, "DULCode", NumLayers, StartRow); NewSoil.Water.LL15 = GetDoubleValues(Table, "LL15 (mm/mm)", NumLayers, StartRow); NewSoil.Water.LL15Metadata = GetCodeValues(Table, "LL15Code", NumLayers, StartRow); NewSoil.Water.AirDry = GetDoubleValues(Table, "Airdry (mm/mm)", NumLayers, StartRow); NewSoil.Water.AirDryMetadata = GetCodeValues(Table, "AirdryCode", NumLayers, StartRow); NewSoil.SoilWater = new SoilWater(); NewSoil.SoilWater.Thickness = NewSoil.Water.Thickness; NewSoil.SoilWater.SummerU = GetDoubleValue(Table, StartRow, "SummerU"); NewSoil.SoilWater.SummerCona = GetDoubleValue(Table, StartRow, "SummerCona"); NewSoil.SoilWater.WinterU = GetDoubleValue(Table, StartRow, "WinterU"); NewSoil.SoilWater.WinterCona = GetDoubleValue(Table, StartRow, "WinterCona"); NewSoil.SoilWater.SummerDate = GetStringValue(Table, StartRow, "SummerDate"); NewSoil.SoilWater.WinterDate = GetStringValue(Table, StartRow, "WinterDate"); NewSoil.SoilWater.Salb = GetDoubleValue(Table, StartRow, "Salb"); NewSoil.SoilWater.DiffusConst = GetDoubleValue(Table, StartRow, "DiffusConst"); NewSoil.SoilWater.DiffusSlope = GetDoubleValue(Table, StartRow, "DiffusSlope"); NewSoil.SoilWater.CN2Bare = GetDoubleValue(Table, StartRow, "Cn2Bare"); NewSoil.SoilWater.CNRed = GetDoubleValue(Table, StartRow, "CnRed"); NewSoil.SoilWater.CNCov = GetDoubleValue(Table, StartRow, "CnCov"); if (Table.Columns.Contains("ThicknessChem (mm)")) { NewSoil.SoilOrganicMatter.Thickness = MathUtility.RemoveMissingValuesFromBottom(GetDoubleValues(Table, "ThicknessChem (mm)", NumRows, StartRow)); } else { NewSoil.SoilOrganicMatter.Thickness = NewSoil.Water.Thickness; } int NumChemLayers = NewSoil.SoilOrganicMatter.Thickness.Length; NewSoil.SoilOrganicMatter.RootCN = GetDoubleValue(Table, StartRow, "RootCn"); NewSoil.SoilOrganicMatter.RootWt = GetDoubleValue(Table, StartRow, "RootWt"); NewSoil.SoilOrganicMatter.SoilCN = GetDoubleValue(Table, StartRow, "SoilCN"); NewSoil.SoilOrganicMatter.EnrACoeff = GetDoubleValue(Table, StartRow, "EnrACoeff"); NewSoil.SoilOrganicMatter.EnrBCoeff = GetDoubleValue(Table, StartRow, "EnrBCoeff"); NewSoil.SoilWater.SWCON = GetDoubleValues(Table, "SWCON (0-1)", NumLayers, StartRow); NewSoil.SoilWater.MWCON = GetDoubleValues(Table, "MWCON (0-1)", NumLayers, StartRow); NewSoil.SoilOrganicMatter.FBiom = GetDoubleValues(Table, "FBIOM (0-1)", NumChemLayers, StartRow); NewSoil.SoilOrganicMatter.FInert = GetDoubleValues(Table, "FINERT (0-1)", NumChemLayers, StartRow); NewSoil.Water.KS = GetDoubleValues(Table, "KS (mm/day)", NumLayers, StartRow); NewSoil.SoilOrganicMatter.OC = GetDoubleValues(Table, "OC", NumChemLayers, StartRow); NewSoil.SoilOrganicMatter.OCMetadata = GetCodeValues(Table, "OCCode", NumChemLayers, StartRow); NewSoil.SoilOrganicMatter.OCUnits = GetOCUnits(Table, StartRow); NewSoil.Analysis.Thickness = NewSoil.SoilOrganicMatter.Thickness; NewSoil.Analysis.EC = GetDoubleValues(Table, "EC (1:5 dS/m)", NumChemLayers, StartRow); NewSoil.Analysis.ECMetadata = GetCodeValues(Table, "ECCode", NumChemLayers, StartRow); NewSoil.Analysis.PH = GetDoubleValues(Table, "PH", NumChemLayers, StartRow); NewSoil.Analysis.PHMetadata = GetCodeValues(Table, "PHCode", NumChemLayers, StartRow); NewSoil.Analysis.PHUnits = GetPHUnits(Table, StartRow); NewSoil.Analysis.CL = GetDoubleValues(Table, "CL (mg/kg)", NumChemLayers, StartRow); NewSoil.Analysis.CLMetadata = GetCodeValues(Table, "CLCode", NumChemLayers, StartRow); NewSoil.Analysis.Boron = GetDoubleValues(Table, "Boron (Hot water mg/kg)", NumChemLayers, StartRow); NewSoil.Analysis.BoronMetadata = GetCodeValues(Table, "BoronCode", NumChemLayers, StartRow); NewSoil.Analysis.CEC = GetDoubleValues(Table, "CEC (cmol+/kg)", NumChemLayers, StartRow); NewSoil.Analysis.CECMetadata = GetCodeValues(Table, "CECCode", NumChemLayers, StartRow); NewSoil.Analysis.Ca = GetDoubleValues(Table, "Ca (cmol+/kg)", NumChemLayers, StartRow); NewSoil.Analysis.CaMetadata = GetCodeValues(Table, "CaCode", NumChemLayers, StartRow); NewSoil.Analysis.Mg = GetDoubleValues(Table, "Mg (cmol+/kg)", NumChemLayers, StartRow); NewSoil.Analysis.MgMetadata = GetCodeValues(Table, "MgCode", NumChemLayers, StartRow); NewSoil.Analysis.Na = GetDoubleValues(Table, "Na (cmol+/kg)", NumChemLayers, StartRow); NewSoil.Analysis.NaMetadata = GetCodeValues(Table, "NaCode", NumChemLayers, StartRow); NewSoil.Analysis.K = GetDoubleValues(Table, "K (cmol+/kg)", NumChemLayers, StartRow); NewSoil.Analysis.KMetadata = GetCodeValues(Table, "KCode", NumChemLayers, StartRow); NewSoil.Analysis.ESP = GetDoubleValues(Table, "ESP (%)", NumChemLayers, StartRow); NewSoil.Analysis.ESPMetadata = GetCodeValues(Table, "ESPCode", NumChemLayers, StartRow); NewSoil.Analysis.Mn = GetDoubleValues(Table, "Mn (mg/kg)", NumChemLayers, StartRow); NewSoil.Analysis.MnMetadata = GetCodeValues(Table, "MnCode", NumChemLayers, StartRow); NewSoil.Analysis.Al = GetDoubleValues(Table, "Al (cmol+/kg)", NumChemLayers, StartRow); NewSoil.Analysis.AlMetadata = GetCodeValues(Table, "AlCode", NumChemLayers, StartRow); NewSoil.Analysis.ParticleSizeSand = GetDoubleValues(Table, "ParticleSizeSand (%)", NumChemLayers, StartRow); NewSoil.Analysis.ParticleSizeSandMetadata = GetCodeValues(Table, "ParticleSizeSandCode", NumChemLayers, StartRow); NewSoil.Analysis.ParticleSizeSilt = GetDoubleValues(Table, "ParticleSizeSilt (%)", NumChemLayers, StartRow); NewSoil.Analysis.ParticleSizeSiltMetadata = GetCodeValues(Table, "ParticleSizeSiltCode", NumChemLayers, StartRow); NewSoil.Analysis.ParticleSizeClay = GetDoubleValues(Table, "ParticleSizeClay (%)", NumChemLayers, StartRow); NewSoil.Analysis.ParticleSizeClayMetadata = GetCodeValues(Table, "ParticleSizeClayCode", NumChemLayers, StartRow); // crops foreach (DataColumn Col in Table.Columns) { if (Col.ColumnName.ToLower().Contains(" ll")) { string[] NameBits = Col.ColumnName.Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); if (NameBits.Length == 3) { string CropName = NameBits[0]; SoilCrop NewCrop = new SoilCrop(); NewCrop.Name = CropName; NewCrop.Thickness = NewSoil.Water.Thickness; NewCrop.LL = GetDoubleValues(Table, CropName + " ll (mm/mm)", NumLayers, StartRow); NewCrop.LLMetadata = GetCodeValues(Table, CropName + " llCode", NumLayers, StartRow); NewCrop.KL = GetDoubleValues(Table, CropName + " kl (/day)", NumLayers, StartRow); NewCrop.XF = GetDoubleValues(Table, CropName + " xf (0-1)", NumLayers, StartRow); if (MathUtility.ValuesInArray(NewCrop.LL) || MathUtility.ValuesInArray(NewCrop.KL)) { NewSoil.Water.Crops.Add(NewCrop); } } } } StartRow += NumRows; if (Notifier != null) { Notifier.Invoke(Convert.ToInt32(StartRow * 100.0 / Table.Rows.Count)); } counter++; if (counter == 50) { GC.Collect(); counter = 0; } } return(Soils.ToArray()); }