/// <summary> /// Add a component to the xml tree. Customised for each component type /// found in the source. /// </summary> /// <param name="compNode">The source component node in the .apsim file</param> /// <param name="destParent">The parent of the new component in the .apsimx file</param> /// <returns>The new component xml node</returns> private XmlNode AddComponent(XmlNode compNode, ref XmlNode destParent) { XmlNode newNode = null; try { if (compNode.Name == "simulation") { XmlNode newSim = this.AddCompNode(destParent, "Simulation", XmlUtilities.NameAttr(compNode)); this.AddChildComponents(compNode, newSim); } else if (compNode.Name == "folder") { XmlNode newFolder = this.AddCompNode(destParent, "Folder", XmlUtilities.NameAttr(compNode)); this.AddChildComponents(compNode, newFolder); } else if (compNode.Name == "clock") { newNode = this.ImportClock(compNode, destParent, newNode); } else if (compNode.Name == "metfile") { newNode = this.ImportMetFile(compNode, destParent, newNode); } else if (compNode.Name == "micromet") { newNode = this.ImportMicromet(compNode, destParent, newNode); } else if (compNode.Name == "manager") { newNode = this.ImportManager(compNode, destParent, newNode); } else if (compNode.Name == "manager2") { newNode = this.ImportManager2(compNode, destParent, newNode); } else if (compNode.Name == "outputfile") { newNode = this.ImportOutputFile(compNode, destParent, newNode); } else if (compNode.Name == "operations") { newNode = this.ImportOperations(compNode, destParent, newNode); } else if (compNode.Name == "summaryfile") { newNode = this.AddCompNode(destParent, "Summary", XmlUtilities.NameAttr(compNode)); XmlNode childNode = newNode.AppendChild(destParent.OwnerDocument.CreateElement("html")); childNode.InnerText = "true"; } else if (compNode.Name.ToLower() == "soil") { newNode = this.ImportSoil(compNode, destParent, newNode); } else if (compNode.Name.ToLower() == "sample") { newNode = this.ImportSample(compNode, destParent, newNode); } else if (compNode.Name.ToLower() == "water") { newNode = this.ImportWater(compNode, destParent, newNode); } else if (compNode.Name.ToLower() == "soilwater") { newNode = this.ImportSoilWater(compNode, destParent, newNode); this.soilWaterExists = newNode != null; this.AddCompNode(destParent, "SoilNitrogen", "SoilNitrogen"); // may need to copy more details for SoilNitrogen } else if (compNode.Name == "InitialWater") { newNode = this.ImportInitialWater(compNode, destParent, newNode); } else if (compNode.Name == "SoilOrganicMatter") { newNode = this.ImportSOM(compNode, destParent, newNode); } else if (compNode.Name == "Analysis") { newNode = this.ImportAnalysis(compNode, destParent, newNode); } else if (compNode.Name == "SoilCrop") { newNode = this.ImportSoilCrop(compNode, destParent, newNode); } else if (compNode.Name == "area") { newNode = this.AddCompNode(destParent, "Zone", XmlUtilities.NameAttr(compNode)); XmlNode newPaddockNode = newNode; string area = this.GetInnerText(compNode, "paddock_area"); if (area == string.Empty) { XmlUtilities.SetValue(compNode, "paddock_area", "1.0"); } this.CopyNodeAndValue(compNode, newPaddockNode, "paddock_area", "Area", true); this.surfOMExists = false; this.soilWaterExists = false; this.microClimateExists = false; // copy all the children in this paddock this.AddChildComponents(compNode, newPaddockNode); // if it contains a soilwater then if (this.soilWaterExists && !this.surfOMExists) { Console.WriteLine("Added SurfaceOM to " + XmlUtilities.FullPathUsingName(newPaddockNode)); Models.SurfaceOM.SurfaceOrganicMatter mysom = new Models.SurfaceOM.SurfaceOrganicMatter(); mysom.PoolName = "wheat_stubble"; mysom.type = "wheat"; mysom.mass = "0"; mysom.cnr = "80"; mysom.cpr = "0"; mysom.standing_fraction = "0.0"; newNode = ImportObject(newPaddockNode, newNode, mysom, "SurfaceOrganicMatter"); } // alway ensure that MicroClimate exists in this paddock if (!this.microClimateExists) { newNode = this.ImportMicromet(null, newPaddockNode, newNode); // create a new node from no source } } else if (compNode.Name == "surfaceom") { newNode = this.ImportSurfaceOM(compNode, destParent, newNode); this.surfOMExists = newNode != null; } else if (compNode.Name == "memo") { newNode = this.AddCompNode(destParent, "Memo", XmlUtilities.NameAttr(compNode)); XmlNode memoTextNode = newNode.AppendChild(destParent.OwnerDocument.CreateElement("MemoText")); memoTextNode.InnerText = compNode.InnerText; } else if (compNode.Name == "Graph") { newNode = this.ImportGraph(compNode, destParent, newNode); } else if (StringUtilities.IndexOfCaseInsensitive(cropNames, compNode.Name) != -1) { this.ImportPlant(compNode, destParent, newNode); } else { // Do nothing. } } catch (Exception exp) { throw new Exception("Cannot import " + compNode.Name + " :Error - " + exp.Message + "\n"); } return newNode; }
/// <summary> /// Import surfaceom /// </summary> /// <param name="compNode">The node being imported from the apsim file xml</param> /// <param name="destParent">Destination parent node that the new child is added to</param> /// <param name="newNode">The new surfaceom node</param> /// <returns>The new node</returns> private XmlNode ImportSurfaceOM(XmlNode compNode, XmlNode destParent, XmlNode newNode) { Models.SurfaceOM.SurfaceOrganicMatter mysom = new Models.SurfaceOM.SurfaceOrganicMatter(); mysom.PoolName = this.GetInnerText(compNode, "PoolName"); mysom.type = this.GetInnerText(compNode, "type"); mysom.mass = this.GetInnerText(compNode, "mass"); mysom.cnr = this.GetInnerText(compNode, "cnr"); mysom.cpr = this.GetInnerText(compNode, "cpr"); mysom.standing_fraction = this.GetInnerText(compNode, "standing_fraction"); newNode = ImportObject(destParent, newNode, mysom, XmlUtilities.NameAttr(compNode)); return newNode; }