/// <summary> /// Copy the supplement eaten into a TSupplementEaten[] /// </summary> /// <param name="Model"></param> /// <param name="aValue"></param> public static void MakeSuppEaten(TStockList Model, ref TSupplementEaten[] aValue) { int iCount; int iPadd; uint Idx; iCount = 0; for (iPadd = 0; iPadd <= Model.Paddocks.Count() - 1; iPadd++) { if (Model.Paddocks.byIndex(iPadd).SuppRemovalKG > 0.0) { iCount++; } } aValue = new TSupplementEaten[iCount]; Idx = 0; for (iPadd = 0; iPadd <= Model.Paddocks.Count() - 1; iPadd++) { if (Model.Paddocks.byIndex(iPadd).SuppRemovalKG > 0.0) { aValue[Idx] = new TSupplementEaten(); aValue[Idx].paddock = Model.Paddocks.byIndex(iPadd).sName; aValue[Idx].eaten = Model.Paddocks.byIndex(iPadd).SuppRemovalKG; Idx++; } } }
/// <summary> /// Rank the paddocks /// </summary> /// <param name="Model"></param> /// <param name="aValue"></param> public static void MakePaddockRank(TStockList Model, ref string[] aValue) { List <string> sList = new List <string>(); Model.rankPaddocks(sList); aValue = sList.ToArray(); /*Array.Resize(ref aValue, sList.Count); * for (int Idx = 0; Idx < aValue.Length; Idx++) * aValue[Idx] = sList[Idx];*/ }
/// <summary> /// Populate metabolizable energy use array /// Note: these are an* ME* partition /// </summary> /// <param name="Model"></param> /// <param name="aValue"></param> public static void MakeEnergyUse(TStockList Model, ref TEnergyUse[] aValue) { double dME_Metab; double dME_MoveGraze; int Idx; for (Idx = 1; Idx <= Model.Count(); Idx++) { TAnimalGroup group = Model.At(Idx); dME_Metab = group.AnimalState.EnergyUse.Metab / group.AnimalState.Efficiency.Maint; dME_MoveGraze = group.AnimalState.EnergyUse.Maint - dME_Metab - group.AnimalState.EnergyUse.Cold; aValue[Idx].maint_base = dME_Metab; aValue[Idx].maint_move_graze = dME_MoveGraze; // Separating E(graze) and E(move) requires work in AnimGRP.pas... aValue[Idx].maint_cold = group.AnimalState.EnergyUse.Cold; aValue[Idx].conceptus = group.AnimalState.EnergyUse.Preg; aValue[Idx].lactation = group.AnimalState.EnergyUse.Lact; aValue[Idx].fleece = group.AnimalState.EnergyUse.Wool / group.AnimalState.Efficiency.Gain; aValue[Idx].gain = group.AnimalState.EnergyUse.Gain / group.AnimalState.Efficiency.Gain; } }
/// <summary> /// /// </summary> /// <param name="Model"></param> /// <param name="aValue"></param> public static void MakePaddockList(TStockList Model, ref TPaddInit[] aValue) { TPaddockInfo aPadd; int Idx, Jdx; Array.Resize(ref aValue, Model.Paddocks.Count()); for (Idx = 0; Idx < aValue.Length; Idx++) { aPadd = Model.Paddocks.byIndex(Idx); aValue[Idx] = new TPaddInit(); aValue[Idx].name = aPadd.sName; // "name" aValue[Idx].area = aPadd.fArea; // "area" aValue[Idx].slope = aPadd.Slope; // "slope" Array.Resize(ref aValue[Idx].forages, aPadd.Forages.Count()); for (Jdx = 0; Jdx < aPadd.Forages.Count(); Jdx++) { aValue[Idx].forages[Jdx] = aPadd.Forages.byIndex(Jdx).sName; } aValue[Idx].excretion = aPadd.sExcretionDest; // "excretion" } }
/// <summary> /// Fill the double[] with values from the model. /// </summary> /// <param name="Model"></param> /// <param name="varCode"></param> /// <param name="bUseYoung"></param> /// <param name="bUseAll"></param> /// <param name="bUseTag"></param> /// <param name="aValue"></param> /// <returns></returns> public static bool PopulateRealValue(TStockList Model, int varCode, bool bUseYoung, bool bUseAll, bool bUseTag, ref double[] aValue) { int iNoPasses; TAnimalGroup aGroup; double dValue; double dTotal; int iDenom; int iPass, Idx; bool Result = true; Array.Clear(aValue, 0, aValue.Length); if (bUseTag) { iNoPasses = aValue.Length; } else { iNoPasses = 1; } for (iPass = 1; iPass <= iNoPasses; iPass++) { dTotal = 0.0; iDenom = 0; for (Idx = 1; Idx <= Model.Count(); Idx++) { if (!bUseTag || (Model.getTag(Idx) == iPass)) { if (!bUseYoung) { aGroup = Model.At(Idx); } else { aGroup = Model.At(Idx).Young; } dValue = 0.0; if (aGroup != null) { int N = (int)GrazType.TOMElement.N; int P = (int)GrazType.TOMElement.P; int S = (int)GrazType.TOMElement.S; switch (varCode) { case StockProps.prpAGE: dValue = aGroup.AgeDays; break; case StockProps.prpAGE_MONTHS: dValue = aGroup.AgeDays / MONTH2DAY; break; case StockProps.prpLIVE_WT: dValue = aGroup.LiveWeight; break; case StockProps.prpBASE_WT: dValue = aGroup.BaseWeight; break; case StockProps.prpCOND_SCORE: dValue = aGroup.fConditionScore(TAnimalParamSet.TCond_System.csSYSTEM1_5); break; case StockProps.prpMAX_PREV_WT: dValue = aGroup.MaxPrevWeight; break; case StockProps.prpFLEECE_WT: dValue = aGroup.FleeceCutWeight; break; case StockProps.prpCFLEECE_WT: dValue = aGroup.CleanFleeceWeight; break; case StockProps.prpFIBRE_DIAM: dValue = aGroup.FibreDiam; break; case StockProps.prpPREGNANT: dValue = aGroup.Pregnancy; break; case StockProps.prpLACTATING: dValue = aGroup.Lactation; break; case StockProps.prpNO_FOETUSES: dValue = aGroup.NoFoetuses; break; case StockProps.prpNO_SUCKLING: dValue = aGroup.NoOffspring; break; case StockProps.prpBIRTH_CS: dValue = aGroup.BirthCondition; break; case StockProps.prpDSE: dValue = aGroup.DrySheepEquivs; break; case StockProps.prpWT_CHANGE: dValue = aGroup.WeightChange; break; case StockProps.prpME_INTAKE: dValue = aGroup.AnimalState.ME_Intake.Total; break; case StockProps.prpCPI_INTAKE: dValue = aGroup.AnimalState.CP_Intake.Total; break; case StockProps.prpCFLEECE_GROWTH: dValue = aGroup.CleanFleeceGrowth; break; case StockProps.prpDAY_FIBRE_DIAM: dValue = aGroup.DayFibreDiam; break; case StockProps.prpMILK_WT: dValue = aGroup.MilkYield; break; case StockProps.prpMILK_ME: dValue = aGroup.MilkEnergy; break; case StockProps.prpRETAINED_N: dValue = aGroup.AnimalState.CP_Intake.Total / GrazType.N2Protein - (aGroup.AnimalState.InOrgFaeces.Nu[N] + aGroup.AnimalState.OrgFaeces.Nu[N] + aGroup.AnimalState.Urine.Nu[N]); break; case StockProps.prpRETAINED_P: dValue = aGroup.AnimalState.Phos_Intake.Total - (aGroup.AnimalState.InOrgFaeces.Nu[P] + aGroup.AnimalState.OrgFaeces.Nu[P] + aGroup.AnimalState.Urine.Nu[P]); break; case StockProps.prpRETAINED_S: dValue = aGroup.AnimalState.Sulf_Intake.Total - (aGroup.AnimalState.InOrgFaeces.Nu[S] + aGroup.AnimalState.OrgFaeces.Nu[S] + aGroup.AnimalState.Urine.Nu[S]); break; case StockProps.prpURINE_N: dValue = aGroup.AnimalState.Urine.Nu[N]; break; case StockProps.prpURINE_P: dValue = aGroup.AnimalState.Urine.Nu[P]; break; case StockProps.prpURINE_S: dValue = aGroup.AnimalState.Urine.Nu[S]; break; case StockProps.prpCH4_OUTPUT: dValue = 0.001 * aGroup.MethaneWeight; // Convert g/d to kg/d break; case StockProps.prpRDPI: dValue = aGroup.AnimalState.RDP_Intake; break; case StockProps.prpRDPR: dValue = aGroup.AnimalState.RDP_Reqd; break; case StockProps.prpRDP_EFFECT: dValue = aGroup.AnimalState.RDP_IntakeEffect; break; case StockProps.prpINTAKE_MOD: dValue = aGroup.IntakeModifier; break; default: Result = false; break; } } if (!bUseTag && !bUseAll) { aValue[Idx - 1] = dValue; } else if (varCode == StockProps.prpDSE) // Sum DSE's; take a weighted average of { dTotal = dTotal + dValue; // all other values } else if (aGroup != null) { dTotal = dTotal + aGroup.NoAnimals * dValue; iDenom = iDenom + aGroup.NoAnimals; } } //_ loop over animal groups _ } if ((varCode != StockProps.prpDSE) && (iDenom > 0)) { dTotal = dTotal / iDenom; } if (bUseAll) { aValue[0] = dTotal; } else if (bUseTag) { aValue[iPass - 1] = dTotal; } } //_ loop over passes _ return(Result); }
/// <summary> /// Populate the numbers array for the type of output required /// </summary> /// <param name="Model"></param> /// <param name="code"></param> /// <param name="bUseYoung"></param> /// <param name="bUseAll"></param> /// <param name="bUseTag"></param> /// <param name="numbers"></param> /// <returns></returns> public static bool PopulateNumberValue(TStockList Model, CountType code, bool bUseYoung, bool bUseAll, bool bUseTag, ref int[] numbers) { int iNoPasses; TAnimalGroup aGroup; int iValue; int iTotal; int iPass, Idx; bool Result = true; Array.Clear(numbers, 0, numbers.Length); if (bUseTag) { iNoPasses = numbers.Length; } else { iNoPasses = 1; } for (iPass = 1; iPass <= iNoPasses; iPass++) { iTotal = 0; for (Idx = 1; Idx <= Model.Count(); Idx++) { if (!bUseTag || (Model.getTag(Idx) == iPass)) { if (!bUseYoung) { aGroup = Model.At(Idx); } else { aGroup = Model.At(Idx).Young; } iValue = 0; if (aGroup != null) { switch (code) { case CountType.eBoth: iValue = aGroup.NoAnimals; break; case CountType.eFemale: iValue = aGroup.FemaleNo; break; case CountType.eMale: iValue = aGroup.MaleNo; break; default: Result = false; break; } } if (!bUseTag && !bUseAll) { numbers[Idx - 1] = iValue; } else { iTotal = iTotal + iValue; } } // _ loop over animal groups } if (bUseAll) { numbers[0] = iTotal; } else if (bUseTag) { numbers[iPass - 1] = iTotal; } } //_ loop over passes _ return(Result); }
/// <summary> /// /// </summary> /// <param name="Model"></param> /// <param name="Animal"></param> /// <param name="aValue"></param> public static void MakeCattleValue(TStockList Model, GrazType.AnimalType Animal, ref TCattleInit[] aValue) { TAnimalGroup aGroup; int iCount; int Idx, Jdx; iCount = 0; for (Idx = 1; Idx <= Model.Count(); Idx++) { if (Model.At(Idx).Genotype.Animal == Animal) { iCount++; } } Array.Resize(ref aValue, iCount); Jdx = 0; for (Idx = 1; Idx <= Model.Count(); Idx++) { if (Model.At(Idx).Genotype.Animal == Animal) { aGroup = Model.At(Idx); aValue[Jdx] = new TCattleInit(); aValue[Jdx].genotype = aGroup.Genotype.sName; aValue[Jdx].number = aGroup.NoAnimals; aValue[Jdx].sex = Model.SexString(Idx, false); aValue[Jdx].age = aGroup.AgeDays; aValue[Jdx].weight = aGroup.LiveWeight; aValue[Jdx].max_prev_wt = aGroup.MaxPrevWeight; aValue[Jdx].pregnant = aGroup.Pregnancy; aValue[Jdx].lactating = aGroup.Lactation; /*if (Animal == GrazType.AnimalType.Sheep) * { * aValue[Jdx].fleece_wt = aGroup.FleeceCutWeight; * aValue[Jdx].fibre_diam = aGroup.FibreDiam; * aValue[Jdx].no_young = Math.Max(aGroup.NoFoetuses, aGroup.NoOffspring); * } * else*/ if (Animal == GrazType.AnimalType.Cattle) { aValue[Jdx].no_foetuses = aGroup.NoFoetuses; aValue[Jdx].no_suckling = aGroup.NoOffspring; } if (aGroup.Lactation > 0) { aValue[Jdx].birth_cs = aGroup.BirthCondition; } if ((aGroup.Pregnancy > 0) || (aGroup.Young != null)) { if (aGroup.MatedTo != null) { aValue[Jdx].mated_to = aGroup.MatedTo.sName; } else { aValue[Jdx].mated_to = ""; } } else { aValue[Jdx].mated_to = ""; } if (aGroup.Young != null) { /*if (Animal == GrazType.AnimalType.Sheep) * { * aValue[Jdx].lamb_wt = aGroup.Young.LiveWeight; * aValue[Jdx].lamb_fleece_wt = aGroup.Young.FleeceCutWeight; * } * else*/ if (Animal == GrazType.AnimalType.Cattle) { aValue[Jdx].calf_wt = aGroup.Young.LiveWeight; } aValue[Jdx].paddock = Model.getInPadd(Idx); aValue[Jdx].tag = Model.getTag(Idx); aValue[Jdx].priority = Model.getPriority(Idx); } } Jdx++; } // next animal }
/// <summary> /// Copies the parameters into an array of genotype structures /// </summary> /// <param name="Model"></param> /// <param name="aValue"></param> public static void MakeGenotypesValue(TStockList Model, ref TStockGeno[] aValue) { TAnimalParamSet Params; string sDamBreed = ""; string sSireBreed = ""; int iGeneration = 0; int Idx, Jdx; Array.Resize(ref aValue, Model.iGenotypeCount()); for (Idx = 0; Idx <= Model.iGenotypeCount() - 1; Idx++) { Params = Model.getGenotype(Idx); if (Params.iParentageCount() == 1) { sDamBreed = Params.sParentageBreed(0); sSireBreed = sDamBreed; iGeneration = 0; } else if ((Params.iParentageCount() == 2) && (Params.fParentagePropn(0) > 0)) { sDamBreed = Params.sParentageBreed(0); sSireBreed = Params.sParentageBreed(1); iGeneration = Convert.ToInt32(Math.Max(0, Math.Round(Math.Log(Params.fParentagePropn(0)) / Math.Log(0.5)))); //TODO: may need checking } else if (Params.iParentageCount() == 2) { sSireBreed = Params.sParentageBreed(1); sDamBreed = sSireBreed; iGeneration = 0; } else { sDamBreed = Params.sParentageBreed(0); sSireBreed = Params.sParentageBreed(1); iGeneration = 0; } aValue[Idx].name = Params.sName; aValue[Idx].dam_breed = sDamBreed; aValue[Idx].sire_breed = sSireBreed; aValue[Idx].generation = iGeneration; aValue[Idx].srw = Params.BreedSRW; aValue[Idx].death_rate = Params.AnnualDeaths(false); aValue[Idx].wnr_death_rate = Params.AnnualDeaths(true); aValue[Idx].ref_fleece_wt = Params.PotentialGFW; aValue[Idx].max_fibre_diam = Params.MaxMicrons; aValue[Idx].fleece_yield = Params.FleeceYield; aValue[Idx].peak_milk = Params.PotMilkYield; if (Params.Animal == GrazType.AnimalType.Sheep) { Array.Resize(ref aValue[Idx].conception, 3); } else { Array.Resize(ref aValue[Idx].conception, 2); } for (Jdx = 0; Jdx < aValue[Idx].conception.Length; Jdx++) { aValue[Idx].conception[Jdx] = Params.Conceptions[Jdx]; } } }
/// <summary> /// Populate the dry matter pool /// </summary> /// <param name="Model"></param> /// <param name="iCode"></param> /// <param name="bUseYoung"></param> /// <param name="bUseAll"></param> /// <param name="bUseTag"></param> /// <param name="aValue"></param> /// <returns></returns> public static bool PopulateDMPoolValue(TStockList Model, int iCode, bool bUseYoung, bool bUseAll, bool bUseTag, ref TDMPoolHead[] aValue) { int iNoPasses; TAnimalGroup aGroup; GrazType.DM_Pool Pool = new GrazType.DM_Pool(); GrazType.DM_Pool TotalPool = new GrazType.DM_Pool(); int iDenom; int iPass, Idx; bool Result = true; for (int i = 0; i < aValue.Length; i++) { aValue[i] = new TDMPoolHead(); } if (bUseTag) { iNoPasses = aValue.Length; } else { iNoPasses = 1; } for (iPass = 1; iPass <= iNoPasses; iPass++) { GrazType.ZeroDMPool(ref TotalPool); iDenom = 0; for (Idx = 1; Idx <= Model.Count(); Idx++) { if (!bUseTag || (Model.getTag(Idx) == iPass)) { if (!bUseYoung) { aGroup = Model.At(Idx); } else { aGroup = Model.At(Idx).Young; } GrazType.ZeroDMPool(ref Pool); if (aGroup != null) { int N = (int)GrazType.TOMElement.N; int P = (int)GrazType.TOMElement.P; int S = (int)GrazType.TOMElement.S; switch (iCode) { case StockProps.prpINTAKE: Pool.DM = aGroup.AnimalState.DM_Intake.Total; Pool.Nu[N] = aGroup.AnimalState.CP_Intake.Total / GrazType.N2Protein; Pool.Nu[P] = aGroup.AnimalState.Phos_Intake.Total; Pool.Nu[S] = aGroup.AnimalState.Sulf_Intake.Total; Pool.AshAlk = aGroup.AnimalState.PaddockIntake.AshAlkalinity * aGroup.AnimalState.PaddockIntake.Biomass + aGroup.AnimalState.SuppIntake.AshAlkalinity * aGroup.AnimalState.SuppIntake.Biomass; break; case StockProps.prpINTAKE_PAST: Pool.DM = aGroup.AnimalState.DM_Intake.Herbage; Pool.Nu[N] = aGroup.AnimalState.CP_Intake.Herbage / GrazType.N2Protein; Pool.Nu[P] = aGroup.AnimalState.Phos_Intake.Herbage; Pool.Nu[S] = aGroup.AnimalState.Sulf_Intake.Herbage; Pool.AshAlk = aGroup.AnimalState.PaddockIntake.AshAlkalinity * aGroup.AnimalState.PaddockIntake.Biomass; break; case StockProps.prpINTAKE_SUPP: Pool.DM = aGroup.AnimalState.DM_Intake.Supp; Pool.Nu[N] = aGroup.AnimalState.CP_Intake.Supp / GrazType.N2Protein; Pool.Nu[P] = aGroup.AnimalState.Phos_Intake.Supp; Pool.Nu[S] = aGroup.AnimalState.Sulf_Intake.Supp; Pool.AshAlk = aGroup.AnimalState.SuppIntake.AshAlkalinity * aGroup.AnimalState.SuppIntake.Biomass; break; case StockProps.prpFAECES: GrazType.AddDMPool(aGroup.AnimalState.OrgFaeces, Pool); GrazType.AddDMPool(aGroup.AnimalState.InOrgFaeces, Pool); break; case StockProps.prpINORG_FAECES: GrazType.AddDMPool(aGroup.AnimalState.InOrgFaeces, Pool); break; default: Result = false; break; } } if (!bUseTag && !bUseAll) { DMPool2Value(Pool, aValue[Idx - 1], (iCode == StockProps.prpINORG_FAECES)); } else if (aGroup != null) { GrazType.AddDMPool(GrazType.MultiplyDMPool(Pool, aGroup.NoAnimals), TotalPool); iDenom = iDenom + aGroup.NoAnimals; } } } //_ loop over animal groups _ if (bUseTag || bUseAll) { if (iDenom > 0) { TotalPool = GrazType.PoolFraction(TotalPool, 1.0 / iDenom); } if (bUseAll) { DMPool2Value(TotalPool, aValue[0], (iCode == StockProps.prpINORG_FAECES)); } else { DMPool2Value(TotalPool, aValue[iPass - 1], (iCode == StockProps.prpINORG_FAECES)); } } } return(Result); }