/// <summary> /// Changes initial Root Wt to an array. /// </summary> /// <param name="root">The root JSON token.</param> /// <param name="fileName">The name of the apsimx file.</param> private static void UpgradeToVersion55(JObject root, string fileName) { foreach (var SOM in JsonUtilities.ChildrenOfType(root, "SoilOrganicMatter")) { double soilcnr; if (SOM["SoilCN"] is JArray) { soilcnr = Convert.ToDouble(SOM["SoilCN"][0], CultureInfo.InvariantCulture); // This can happen when importing old APSIM file. } else { soilcnr = Convert.ToDouble(SOM["SoilCN"], CultureInfo.InvariantCulture); } SOM.Remove("SoilCN"); double[] thickness = MathUtilities.StringsToDoubles(JsonUtilities.Values(SOM, "Thickness")); double[] SoilCNVector = new double[thickness.Length]; for (int layer = 0; layer < thickness.Length; layer++) { SoilCNVector[layer] = soilcnr; } JsonUtilities.SetValues(SOM, "SoilCN", SoilCNVector); } }
/// <summary> /// </summary> /// <param name="root">The root JSON token.</param> /// <param name="fileName">The name of the apsimx file.</param> private static void UpgradeToVersion52(JObject root, string fileName) { foreach (var SOM in JsonUtilities.ChildrenOfType(root, "SoilOrganicMatter")) { double rootWt = Convert.ToDouble(SOM["RootWt"]); SOM.Remove("RootWt"); double[] thickness = MathUtilities.StringsToDoubles(JsonUtilities.Values(SOM, "Thickness")); double profileDepth = MathUtilities.Sum(thickness); double cumDepth = 0; double[] rootWtFraction = new double[thickness.Length]; for (int layer = 0; layer < thickness.Length; layer++) { double fracLayer = Math.Min(1.0, MathUtilities.Divide(profileDepth - cumDepth, thickness[layer], 0.0)); cumDepth += thickness[layer]; rootWtFraction[layer] = fracLayer * Math.Exp(-3.0 * Math.Min(1.0, MathUtilities.Divide(cumDepth, profileDepth, 0.0))); } // get the actuall FOM distribution through layers (adds up to one) double totFOMfraction = MathUtilities.Sum(rootWtFraction); for (int layer = 0; layer < thickness.Length; layer++) { rootWtFraction[layer] /= totFOMfraction; } double[] rootWtVector = MathUtilities.Multiply_Value(rootWtFraction, rootWt); JsonUtilities.SetValues(SOM, "RootWt", rootWtVector); } }
/// <summary> /// Changes initial Root Wt to an array. /// </summary> /// <param name="root">The root JSON token.</param> /// <param name="fileName">The name of the apsimx file.</param> private static void UpgradeToVersion55(JObject root, string fileName) { foreach (var SOM in JsonUtilities.ChildrenOfType(root, "SoilOrganicMatter")) { double soilcnr = Convert.ToDouble(SOM["SoilCN"]); SOM.Remove("SoilCN"); double[] thickness = MathUtilities.StringsToDoubles(JsonUtilities.Values(SOM, "Thickness")); double[] SoilCNVector = new double[thickness.Length]; for (int layer = 0; layer < thickness.Length; layer++) { SoilCNVector[layer] = soilcnr; } JsonUtilities.SetValues(SOM, "SoilCN", SoilCNVector); } }