Example #1
0
        /// <summary>
        /// Publishes uptake values
        /// </summary>
        private void PublishUptakes()
        {
            CohortWaterSupplyType Supply = new CohortWaterSupplyType();
            PMF.WaterUptakesCalculatedType Water = new PMF.WaterUptakesCalculatedType();
            Water.Uptakes = new PMF.WaterUptakesCalculatedUptakesType[num_crops];

            for (int counter = 0; counter < num_crops; counter++)
            {
                Water.Uptakes[counter] = new PMF.WaterUptakesCalculatedUptakesType();
                if (supply_event_id[counter] != 0)
                {
                    Supply.CohortID = crop_names[counter];
                    Supply.RootSystemLayer = new CohortWaterSupplyRootSystemLayerType[n + 1];
                    double bottom = 0.0;
                    for (int node = 0; node <= n; node++)
                    {
                        // This uses "bottom", not "dlayer", so we need to convert
                        bottom += _dlayer[node];
                        Supply.RootSystemLayer[node].Bottom = bottom;

                        // uptake may be very small -ve - assume error small
                        Supply.RootSystemLayer[node].Supply = Math.Max(pwuptake[counter][node], 0.0);
                    }
                    CohortWaterSupply.Invoke(Supply);
                }

                string cropname;
                if (supply_event_id[counter] == 0)
                    cropname = crop_owners[counter];
                else
                    cropname = crop_owners[counter] + "_" + crop_names[counter];

                Water.Uptakes[counter].Name = cropname;
                Water.Uptakes[counter].Amount = new double[n + 1];

                for (int node = 0; node <= n; node++)
                {
                    // uptake may be very small -ve - assume error small
                    Water.Uptakes[counter].Amount[node] = Math.Max(pwuptake[counter][node], 0.0);
                }
            }

            WaterUptakesCalculated.Invoke(Water);
        }
 private void OnWaterUptakesCalculated(WaterUptakesCalculatedType SoilWater)
 {
     foreach (WaterUptakesCalculatedUptakesType cropUptake in SoilWater.Uptakes)
     {
         if (cropUptake.Name == Name)
         {
             for (int layer = 0; layer < cropUptake.Amount.Length; layer++)
                 mySoilWaterUptake[layer] = cropUptake.Amount[layer];
         }
     }
 }