/// /// Get Crop object from IOCrop object. /// public static Crop ConvertFrom(IOCrop ioCrp) { if (Equals(ioCrp, null)) { return(null); } Crop newCrop = new Crop(); try { newCrop.Name = ioCrp.Name; newCrop.FileSource = ioCrp.FileSource; newCrop.FileFormat = ioCrp.FileFormat; newCrop.InitialStage = ioCrp.InitialStage; newCrop.DevelopmentStage = ioCrp.DevelopmentStage; newCrop.MidSeasonStage = ioCrp.MidSeasonStage; newCrop.LateSeasonStage = ioCrp.LateSeasonStage; newCrop.Kc1 = ioCrp.Kc1; newCrop.Kc2 = ioCrp.Kc2; newCrop.Kc3 = ioCrp.Kc3; newCrop.RoutingDepth1 = ioCrp.RoutingDepth1; newCrop.RoutingDepth2 = ioCrp.RoutingDepth2; newCrop.CriticalDepletion1 = ioCrp.CriticalDepletion1; newCrop.CriticalDepletion2 = ioCrp.CriticalDepletion2; newCrop.CriticalDepletion3 = ioCrp.CriticalDepletion3; newCrop.YieldResponse1 = ioCrp.YieldResponse1; newCrop.YieldResponse2 = ioCrp.YieldResponse2; newCrop.YieldResponse3 = ioCrp.YieldResponse3; newCrop.YieldResponse4 = ioCrp.YieldResponse4; newCrop.YieldResponse5 = ioCrp.YieldResponse5; newCrop.CropHeight = ioCrp.CropHeight; } catch (Exception ex) { //newCrop= null; throw ex; } return(newCrop); }
static void Main(string[] args) { string cropfile = string.Format(@"{0}\Data\crops\FAO\TOMATO.CRO", AppDomain.CurrentDomain.BaseDirectory); Console.WriteLine("The directory is :"); Console.WriteLine(cropfile); //crop data: IOCrop ioCrop = IOCrop.Load(cropfile); Crop crp = Crop.ConvertFrom(ioCrop); Console.WriteLine("Crop = {0}.", crp.Name); Console.WriteLine("Planting Date = {0}.", crp.PlantingDate); Console.WriteLine("Life = {0} days.", crp.LifeInDays); Console.WriteLine("Harvest Date = {0}.", crp.HarvestDate); //soil data: string soilFile = string.Format(@"{0}\Data\soils\FAO\LIGHT.SOI", AppDomain.CurrentDomain.BaseDirectory); IOSoil sol = IOSoil.Load(soilFile); Console.WriteLine(sol.TotalAvailableMoisture); }