Advertisement
algodritmo

rumengut

Dec 15th, 2021 (edited)
299
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 167.41 KB | None | 0 0
  1. unit RumenGut;
  2.  
  3. interface
  4. uses Global;
  5.  
  6. procedure NutrientSupply(ptrFeedDescriptions:PFeedsRecord;ptrAmount:PTAmount;
  7.                          ptrNutAbsorbed:PNutAbsorbedRecord);stdcall;
  8. procedure blood(ac, prop, but, pH, vol, RSA: Single; tslp: Integer;
  9.                 var Aac, Aprop, Abut: Single);
  10. //procedure fNDFandpH(pH,pHLast,FeedfNDFRate: Single;HourlyLoop: Integer;var fNDFRate: Single);
  11. function CalcLig(Diet: Integer;DMITMR: Single): Single;
  12.  
  13.  
  14. implementation
  15.  
  16. uses
  17. Microbes, SysUtils, Windows, Math, SingleForm;
  18.  
  19. //const
  20. //Microbes on solids have maintenance which goes up as pH goes down from 6.8
  21. //log106_8=0.000000158;
  22. //Microbes on liquids have maintenance which goes up as pH goes down from 6
  23. //log106_0=0.000001;
  24. //log105_2=0.0000063;
  25.  
  26. {procedure fNDFandpH(pH,pHLast,FeedfNDFRate: Single;HourlyLoop: Integer;var fNDFRate: Single);
  27. const
  28. IncreasedRate=1.15;
  29.  
  30. begin
  31. if pH<5.2 then
  32.  fNDFRate:=0.0005
  33. else if pH<5.7 then
  34.  begin
  35.  if fNDFRate<(FeedfNDFRate*(1-(Power(10,-pH)-log106_8)/(log105_2-log106_8))) then
  36.   begin
  37.   fNDFRate:=(FeedfNDFRate*(1-(Power(10,-pH)-log106_8)/(log105_2-log106_8)));
  38.   if fNDFRate=0 then fNDFRate:=(FeedfNDFRate*(1-(Power(10,-pH)-log106_8)/(log105_2-log106_8)));//(1-(6.2-pH)*1.1))
  39.   end
  40.  else
  41.   begin
  42.   fNDFRate:=(FeedfNDFRate*(1-(Power(10,-pH)-log106_8)/(log105_2-log106_8)));//; (1-(Power(10,-pH)-log106_2)/0.00000614))
  43.   fNDFRateOutFor:=HourlyLoop;
  44.   end;
  45.  end
  46. else if pH>=5.7 then
  47.  begin
  48.  if fNDFRate=0 then fNDFRate:=0.0005;
  49. // if HourlyLoop>fNDFRateOutFor+4 then
  50.   fNDFRate:=FNDFRate*IncreasedRate;
  51.  if fNDFRate>FeedfNDFRate then fNDFRate:=FeedfNDFRate;
  52.  end;
  53. // fNDFRate:=0;
  54. if fNDFRate<0.0005 then fNDFRate:=0.0005;
  55.  
  56. end;}
  57. function CalcLig(Diet: Integer;DMITMR: Single): Single;
  58. var
  59. n: Integer;
  60. SDM,LIG,ForageDM,TMRForageDM,DMForage: Single;
  61.  
  62. begin
  63. SDM:=0;
  64. LIG:=0;
  65. ForageDM:=0;TMRForageDM:=0;DMForage:=0;
  66. if not FSGrazingAll[rFeedInfo.Diet] then
  67.  for n:=1 to rFeedInfo.iNoFeeds do
  68.   if rFeedInfo.TMRFeed[n-1].pemNDF>3.5 then
  69.    begin
  70.    SDM:=SDM+StrToFloat(FeedOrder[n-1,7+Diet]);
  71.    end;
  72. //Robotics
  73. if ChopLength then
  74.  begin
  75.  if FSGrazingAll[rFeedInfo.Diet] then DMITMR:=1;
  76.  SDM:=DMITMR;
  77.  if TMRRobotic then
  78.   begin
  79.   SDM:=SDM+rFeedInfo.RoboticPerMeal1*RoboticFeeds[rFeedInfo.Parlour]
  80.       +rFeedInfo.RoboticPerMeal2*RoboticFeeds[rFeedInfo.Parlour];
  81.   end
  82.  else if FSParlour[rFeedInfo.Diet] then
  83.   begin
  84.   SDM:=SDM+rFeedInfo.ParlourPerMeal*ParlourFeeds[rFeedInfo.Parlour];
  85.   end;
  86.  SDM:=SDM/DMITMR*Thousand;
  87.  end;
  88. {//Parlour
  89.  if not rFeedInfo.ParlourFeed.GroundOrLong then
  90.   begin
  91.   SDM:=SDM+StrToFloat(FeedOrder[13,7+Diet]);
  92.   end;}
  93. //Grazing
  94.  if rFeedInfo.GrazingFeed.pemNDF>3.5 then
  95.   begin
  96.   SDM:=SDM+rFeedInfo.GrazingFeed.DM;
  97.   end;
  98. if not FSGrazingAll[rFeedInfo.Diet] then
  99.  for n:=1 to rFeedInfo.iNoFeeds do
  100.   if rFeedInfo.TMRFeed[n-1].pemNDF>3.5 then
  101.    begin
  102.    LIG:=LIG+rFeedInfo.TMRFeed[n-1].unfermNDF*StrToFloat(FeedOrder[n-1,7+Diet])/SDM;
  103.    ForageDM:=ForageDM+rFeedInfo.TMRFeed[n-1].DM
  104.                        *StrToFloat(FeedOrder[n-1,7+Diet])/SDM;
  105.    end;
  106. {//Parlour
  107.  if not rFeedInfo.ParlourFeed.GroundOrLong then
  108.   begin
  109.   LIG:=LIG+rFeedInfo.ParlourFeed.C3*StrToFloat(FeedOrder[13,7+Diet])/SDM;
  110.   end; }
  111. //Grazing
  112.  if rFeedInfo.GrazingFeed.pemNDF>3.5 then
  113.   begin
  114.   LIG:=LIG+rFeedInfo.GrazingFeed.unfermNDF*rFeedInfo.GrazingFeed.DM/SDM;
  115.   ForageDM:=ForageDM+rFeedInfo.GrazingFeed.DM;
  116.   end;
  117. for n := 0 to rFeedInfo.iNoFeeds-1 do
  118.  if rFeedInfo.TMRFeed[n].pemNDF>3.5 then
  119.   begin
  120.   TMRForageDM:=TMRForageDM+rFeedInfo.TMRFeed[n].DM
  121.                        *StrToFloat(FeedOrder[n,7+Diet]);
  122.   DMForage:=DMForage+StrToFloat(FeedOrder[n,7+Diet]);
  123.   end;
  124. if DMForage>0 then TMRForageDM:=TMRForageDM/DMForage;
  125. if version1_01_16 then
  126.  begin
  127.  if TMRForageDM>30 then ForageDMBelow30Ppn:=1 else ForageDMBelow30Ppn:=34-TMRForageDM/0.88;
  128.  if TMRForageDM<23 then ForageDMBelow30Ppn:=34-23/0.88;
  129.  end
  130. else
  131.  begin
  132.  ForageDMBelow30Ppn:=1;
  133.  end;
  134. CalcLig:=LIG/Thousand;
  135. end;
  136.  
  137. procedure blood(ac, prop, but, pH, vol, RSA: Single; tslp: Integer;
  138.                 var Aac, Aprop, Abut: Single);
  139. //take concs (M) of ac, prop and but and calculate molar quantities absorbed
  140. const
  141. pKac=4.76;
  142. pKpr=4.87;
  143. pKbu=4.81;
  144. Kacu=0.48;
  145. Kacd=0.12;
  146. Kpru=0.67;
  147. Kprd=0.21;
  148. Kbuu=1.43;
  149. Kbud=0.15;
  150.  
  151. var
  152. Facu,Fpru,Fbuu,Factor: Single;
  153.  
  154. begin
  155. Factor:=RSA/100/tslp;//vary 400 - 1000 250
  156. if ph < 5 then ph := 5;
  157. Facu:=1/(1+power(10,pH-pKac));
  158. Fpru:=1/(1+power(10,pH-pKpr));
  159. Fbuu:=1/(1+power(10,pH-pKbu));
  160. Aac:=Factor*ac*(Kacu*Facu+Kacd*(1-Facu));{mol/tstep}
  161. Aprop:=Factor*prop*(Kpru*Fpru+Kprd*(1-Fpru));
  162. Abut:=Factor*but*(Kbuu*Fbuu+Kbud*(1-Fbuu));
  163. if Aac>ac*vol*0.4 then Aac:=ac*vol*0.4;//0.95
  164. if Aprop>prop*vol*0.4 then Aprop := prop*vol*0.4; {aac,aprop,abut mmol/h, ac,prop,but moles}
  165. if Abut>but*vol*0.4 then Abut := but*vol*0.4;
  166. if Aac<0 then Aac:=0;
  167. if Aprop<0 then Aprop:=0;
  168. if Abut<0 then Abut:=0;
  169. end;
  170.  
  171. procedure NutrientSupply(ptrFeedDescriptions:PFeedsRecord;ptrAmount:PTAmount;
  172.                          ptrNutAbsorbed:PNutAbsorbedRecord);
  173. const
  174. StepsPerHour=10;
  175. MicMaint=1.63; //mmoles/g/hr
  176. BloodOsmol=280;
  177. CPToTP=1;//microbes don't produce any CP, just TP! 0.75;
  178. DigestibilityOfTP=0.8;//0.85;
  179. DigestibilityOfDUP=0.6;
  180. LPMult=0.11;
  181. SStarchToQStarchBR=0;//0.004411; //O.045 scaled down
  182. MicPassRate=2*0.00958; //0.1 scaled down 1.1^0.1-1
  183. RNH3=0.025;//0.07 //0.02   0.025      very sensitive to this
  184. SlowProteinToQuickProtein=0;//0.00489; //0.05 scaled down
  185. BicarbonateContentSaliva={0.75*}130+13.8; //meq 130 from bicarbonate, 13.8 equivalent from phosphate
  186. //FeedSaliva=0.25;
  187. LacticToGlucose=1;
  188. USPass=2;
  189. MicrobialProteinRate=0.5;
  190. MicNonCHO=0.8;
  191. MWN=14;
  192. ClearanceRatio=1.3;//1.3;
  193. //RatioLongtoTotal=0.5;
  194. pKCO2=7.74; pCO2=0.7;
  195. AvpH=10;//average out pH to 1 per hour
  196. PassageRateFactor=1.15; //to speed up flow of uNDF 11022013 Andy's comment was
  197. //that on high intakes they weren't getting enough milk
  198. MaxRuminationTime=780;  //minutes of rumination per day
  199.  
  200. var
  201. ParlourRobot: Boolean;
  202. Days1toEnd,Hours1to24,StepHours1toEnd,loopi,loopm,NumFoods,Line,n1,IndexPosn1,NH3Lim,
  203. FinalCount,count,iNoFeeds1,s,EatingStepsPerHour,counter: Integer;
  204. fNDF, iNDF, QStarch, DegCP, iDegCp,HourlyActualIntake,DailyIntake,
  205. SIfNDF, SIiNDF, SIStarch, SIDegCP, SIiDegCP, HGfNDF, HGiNDF,
  206. RNDF, RQStarch,RSStarch, RDegCP, PassfNDFtoSI, PassiNDFtoSI, PassQStarchtoSI,
  207. PassDegCPtoSI, PassiDegCPtoSI, PassfNDFOut, PassiNDFOut,FermfNDFinHG,
  208. TotalAmount,FermfNDFinRum, FermStarchinRum, FermDegCPinRum,LagCP,
  209. SupplementRatio,SupplementToEat,SolCP,FermSolCPinRum,RaCP,PassSolCPtoSI,
  210. LagNDF,fNDFLong,iNDFLong,DegCPLong,iDegCPLong,PassfNDFLongtoSI,PassiNDFLongtoSI,
  211. PassDegCPLongtoSI,PassiDegCPLongtoSI,FermfNDFLonginRum,FermDegCPLonginRum,
  212. fNDFLongBreakdown,iNDFLongBreakdown,DegCPLongBreakdown,iDegCPLongBreakdown,
  213. PassLagfNDFtoSI,PassLagiNDFtoSI,PassLagDegCPtoSI,PassLagiDegCPtoSI,
  214. PassLagSStarchtoSI,PassLagUSStarchtoSI,LagSStarch,PectinPS,PectinRate,
  215. SStarch,SStarchLong,USStarch,USStarchLong,UQStarch,PassUQStarchtoSI,
  216. PassSStarchLongtoSI,PassUSStarchLongtoSI,PassSStarchtoSI,PassUSStarchtoSI,
  217. SStarchLongBreakdown,USStarchLongBreakdown,SStarchToQStarchBreakdown,
  218. FermSStarchinRum,FermSStarchLonginRum,SProteinToQProteinSolubilisation,
  219. PassPectintoSI,FermPectininRum,HGPectinPS,PassPectinOut,FermPectininHG,
  220. LagSGlycerol,RSGlycerol,LagUrea,SlowReleaseNH3Rate: array of Single;
  221. SolCHO,SolsNDF,NH3Rum,Ash,H2O,Oil,AcLRum,AcSRum,PropLRum,PropSRum,ButLRum,ButSRum,
  222. CH4LRum,CH4SRum,MicRumLiquid,MicRumSolids,Lactate,MPOutOfRumen,
  223. RSolCHO,RSolCP,FermNDFRum,FermQStarchRum,FermSStarchRum,FermDegCPRum,FermNDFHG,FermLacticinRum,
  224. RLPass,RPPass,PassSolCHOtoSI,PassAshtoSI,SumPassDigCPtoSI,PassLactictoSI,
  225. PassOiltoSI,FermSolCHOinRum,HourlyPotentialIntake,SIMic,HGPPass,
  226. SISolCHO,SISolCP,SIOil,RumDM,QMicLiquidR,QMicSolidsR,QMicLaR,QAcR,QPrR,QBuR,QLaR,
  227. QCH4R,PassNH3toSI,BicarbonateFromSaliva,PAcR,PPrR,PBuR,PLaR,UnFermNDFRL,
  228. AcHG,PropHG,ButHG,CH4HG,MicHG,NH3HG,QMicHG,QAcHG,QPrHG,QBuHG,FermNH3inRum,
  229. QCH4HG,SIDigCHO,UnFermSolCHOL,UnFermSolCHOS,UnFermNDFRS,UnFermSolCHOHG,UnFermNDFHG,
  230. UnFermLacticAcidL,UnFermLacticAcidS,UnFermLacticAcidHG,PpnHexUsedL,PpnHexUsedS,PpnHexUsed,
  231. PpnHexFerm,pH,CAcR,CPrR,CBuR,CLaR,Protons,{NaHCO3,}DailyFlowSaliva,BicarbonateEaten,
  232. AbsAc,AbsPr,AbsBu,FreeWater,BoundWater,LiquidVolume,RestSaliva,LacLRum,LacSRum,
  233. ConcPPass,RConcPPass,FL,PassMultiplier,RumenOsmol,OsFlux,EatingSaliva,
  234. TotalRumenVol,OutFlow,Value,MaxDailyLoad,SumHourlyActualIntake,MTP,DUP,
  235. NonForageIntake,TotalSupplementToEat,FDM,DMI,MP,Ac,Pr,Bu,CH4,AbsOil,CHO,
  236. FaecalfNDF,FaecaliNDF,FaecalN,avDMI,avDMIGrazing,PpnForagePolySacFerm,UrinaryN,
  237. BloodUreaConc,UreaPoolSize,BodyWater,SumUndigestedProtein,
  238. SIUndigestedCP,FermProteinHG,QProteinHG,ConsumedVFA,ConsumedLactate,{HProduced,}dH,
  239. ConsumedNH3,EEsoFar,QAc,QPr,QBu,ProteinGrowth,PassLagSGlyceroltoSI,
  240. QCHO,QMTP,QDUP,QMP,Scalar,dQAcR,dQAcHG,dQPrR,dQPrHG,dQBuR,dQBuHG,dQLaR,HFSSiR,
  241. dSIDigCHO,dSIMic,dMP,dAbsOil,FeedWater,FermSolCPRum,SumPassSolCPtoSI,SolubleCP,
  242. HFSCiR,HFNiR,HFSiR,HSCPiR,HDCPiR,{HSCiR,HPSCiR,}HFNH3QiR,HFNH3SiR,HI,MicLacRum,MicLacHG,LacHG,
  243. PassSolsNDFtoSI,FermSolsNDFinRum,HGsNDF,FermsNDFHG,PasssNDFOut,AcidEaten,VolBlood,
  244. ElapsedTime,LPBR,AbsNH3,sss,EMNS,hEMNSh,dEMNS,MicGrowthLacRum,PassQMicLiquidR,
  245. PassQMicSolidsR,PassageFree,PassageBound,DM,RuminationSaliva,{dpH,}Acid,ProdLacAc,
  246. FNH3RumFree,FNH3RumSolid,FermNH3inRumFree,FermNH3inRumSolid,FreeProteinRatio,
  247. SolidProteinRatio,NH3UsedSolid,NH3UsedFree,StarchUsedFree,StarchUsedSolids,
  248. StarchUsedHG,pHLim,pHLast,DeathOfQMicLiquidR,DeathOfQMicSolidsR,DeathOfQMicHG,
  249. QDeadSolidMicrobes,QDeadLiquidMicrobes,FermDSMCHO,FermDLMCHO,FermDLMLip,FermDSMLip,
  250. FermDLMProt,FermDSMProt,RMicProt,SalivaFlow,UrineWater,WaterDrunk,PpnLaUttoRest,
  251. dUrineWater,dWaterDrunk,PassSIWater,PassWater,QMicLaUtR,MicLacUtRum,
  252. FermPectinRum,FermPectinHG,FaecalPectin,MonoPG_Glycerol,PassMPGtoSI,
  253. PassLagUreatoSI,RoboticPerMealPerFood,XSProtein,TMRDailyIntake,
  254. GrassDailyIntake,AlkabupHaAcidConsumed,AlkabupHaAcidConsumedPpn: Single;
  255. x,AcLaRum,PropLaRum,ButLaRum,CH4LaRum,FermNH3inRumFreeLa,DeathOfQMicLiquidRLa,
  256. QDeadLiquidMicrobesLa,FermDLaMCHO,FermDLaMProt,FermDLaMLip,PpnNH3,pnLaR,dUrinaryN,
  257. dAcid,dNaHCO3,SIMicCHO,SIMicLip,dSIMicCHO,dSIMicLip,Neutralised,CO2Produced,
  258. ppnNeutralised,DegradableTrueP,ProteinMilk,EnergyMilk,ParlourPerMealPerFood,
  259. LPBreakdownR,LongParticles,ShortParticles,ProtFromBody,MaxProtFromBody,
  260. SumProteinFromBody,MinimumUrineWater,DaysIntake,deNaHCO3,deHProduced,
  261. MolarNaHCO3,DissociatedAcidRatioVFA,DissociatedAcidRatioLactic,LipidGrowth,
  262. PassUnfermentedGlyceroltoSI,Glycerol,PassGlyceroltoSI,FermGlycerolinRumen,
  263. EnergyFromKetogenic,EnergyFromGlucogenic,RatioKetogenic:Single;
  264. FixedIntake,CanEatForage,IncreaseRumenFillUpper,Weeks1_12,MaxRum,MaxLPBR: Boolean;
  265. LagfNDFToEnter,LagiNDFToEnter,LagNDFEntryTime,
  266. LagSStarchEntryTime,LagSStarchToEnter,LagUSStarchToEnter,
  267. LagDegCPToEnter,LagiDegCPToEnter,LagCPEntryTime,
  268. LagSGlycerolToEnter,LagSGlycerolEntryTime,LagUreaEntryTime,
  269. LagUreaToEnter: array of array[1..24] of Single;
  270. pHOverTime: array[1..10] of Single;
  271. OxygenLevel,OxygenUsed,QYeast,YeastMaint,AcY,PropY,ButY,CH4Y,DeathYeast,
  272. deltaYeast,FermMonoPG_GlycerolinRum,TimeSpentEating,UnfermentedGlycerolSmall,
  273. {LongNDF,TotalNDF,}SlowReleaseNH3,LagParlourFeed,HalfRoboticDMI,LiqPerMeal,
  274. MaxLongParticles,TotalLongParticles,DMRatio,TotalRumDM: Single;
  275. ParlourCountLow,ParlourCountHigh,RoboticCountLow,RoboticCountHigh,
  276. LiquidCount: Integer;
  277. LPMultiplier: array of Single;
  278.  
  279. begin
  280. WhyWontItWork:=0;WWIW:=0;
  281. MinimumUrineWater:=LactationDay1/StepsPerHour/HoursInDay;
  282. MicLacHG:=0;LacHG:=0;pHLast:=6.2;Weeks1_12:=False;ProportionNH3Free:=0.5;
  283. for n1:=1 to 24 do
  284.  begin
  285.  TLongNDFForage[n1]:=0;
  286.  TNDFForage[n1]:=0;
  287.  ULongNDFForage[n1]:=0;
  288.  UNDFForage[n1]:=0;
  289.  end;
  290. VolBlood:=Animal.LFEB*0.1;
  291. BodyWater:=Animal.Water;//kg
  292. //put NH3 from g/day to moles of urea per tstep
  293. ptrNutAbsorbed^.NH3:=ptrNutAbsorbed^.NH3/HoursInDay/StepsPerHour/(2*MWNH3);
  294. UreaPoolSize:=1;
  295. ptrNutAbsorbed^.RuminationTime:=1;
  296. BloodUreaConc:=0.005;//initial value of 5mM
  297. iNoFeeds1:=ptrFeedDescriptions^.iNoFeeds;
  298. NumFoods:=iNoFeeds1+ptrFeedDescriptions^.iParlour
  299.           +ptrFeedDescriptions^.iGrazing
  300.           +ptrFeedDescriptions^.iRobotic
  301.           +ptrFeedDescriptions^.iLiquid;  //length of array determines how many foods being fed
  302. //iRobotic sometimes set to 1 which means there is no Robotic!
  303. if ptrFeedDescriptions^.iRobotic=1 then NumFoods:=NumFoods-1;
  304. //iLiquid should be zero if not TMRRobotics otherwise NumFoods too high
  305. //if not TMRRobotic then
  306. // if ptrFeedDescriptions^.iLiquid=1 then NumFoods:=NumFoods-1;
  307. //NumFoods-counter = count for grazing
  308. if ptrFeedDescriptions^.iParlour>0 then
  309.  counter:=PreMixParlourNo+ptrFeedDescriptions^.iRobotic+ptrFeedDescriptions^.iLiquid+1
  310. else counter:=1;
  311. //NumFoods has a number equivalent to iNoFeeds, and one for iGrazing and
  312. //one equivalent to iParlour. All arrays start at zero! So NumFoods-1 to give arrays
  313. //So for one tmr, one grazing and one parlour 1st is tmr, 2nd is grazing, 3rd is parlour
  314. ParlourCountHigh:=0;
  315. RoboticCountHigh:=0;
  316. if ptrFeedDescriptions^.iParlour>0 then
  317.  begin
  318.  ParlourCountLow:=iNoFeeds1+ptrFeedDescriptions^.iGrazing;
  319.  ParlourCountHigh:=ParlourCountLow+ptrFeedDescriptions^.iParlour-1;
  320.  end;
  321. if ptrFeedDescriptions^.iRobotic>0 then
  322.  begin
  323.  RoboticCountLow:=ParlourCountHigh+1;
  324.  RoboticCountHigh:=RoboticCountLow+ptrFeedDescriptions^.iRobotic-1;
  325.  end;
  326. if ptrFeedDescriptions^.iLiquid>0 then
  327.  begin
  328.  LiquidCount:=RoboticCountHigh+1;
  329.  end;
  330.  
  331.  
  332. if TMRRobotic then
  333.  ParlourHour[1]:=RoboticHour[1];
  334.  
  335. SetLength(SlowReleaseNH3Rate,NumFoods);
  336. SetLength(LagUrea,NumFoods);
  337. SetLength(LagUreaToEnter,NumFoods);
  338. SetLength(LagUreaEntryTime,NumFoods);
  339. SetLength(RSGlycerol,NumFoods);
  340. SetLength(LagSGlycerol,NumFoods);
  341. SetLength(LagSGlycerolToEnter,NumFoods);
  342. SetLength(LagSGlycerolEntryTime,NumFoods);
  343. SetLength(LagfNDFToEnter,NumFoods);
  344. SetLength(LagiNDFToEnter,NumFoods);
  345. SetLength(LagNDFEntryTime,NumFoods);
  346. SetLength(LagSStarchToEnter,NumFoods);
  347. SetLength(LagUSStarchToEnter,NumFoods);
  348. SetLength(LagSStarchEntryTime,NumFoods);
  349. SetLength(LagDegCPToEnter,NumFoods);
  350. SetLength(LagiDegCPToEnter,NumFoods);
  351. SetLength(LagCPEntryTime,NumFoods);
  352. SetLength(PassLagfNDFtoSI,NumFoods);
  353. SetLength(PassLagSStarchtoSI,NumFoods);
  354. SetLength(PassLagUSStarchtoSI,NumFoods);
  355. SetLength(LagSStarch,NumFoods);
  356. SetLength(PassLagDegCPtoSI,NumFoods);
  357. SetLength(PassLagiNDFtoSI,NumFoods);
  358. SetLength(PassLagiDegCPtoSI,NumFoods);
  359. SetLength(fNDF,NumFoods);  //use this to set up size of internal arrays
  360. SetLength(iNDF,NumFoods);
  361. SetLength(fNDFLong,NumFoods);
  362. SetLength(iNDFLong,NumFoods);
  363. SetLength(SStarch,NumFoods);  //use this to set up size of internal arrays
  364. SetLength(USStarch,NumFoods);
  365. SetLength(SStarchLong,NumFoods);
  366. SetLength(USStarchLong,NumFoods);
  367. SetLength(UQStarch,NumFoods);  //use this to set up size of internal arrays
  368. SetLength(LagNDF,NumFoods);
  369. SetLength(LagCP,NumFoods);
  370. SetLength(QStarch,NumFoods);
  371. SetLength(SolCP,NumFoods);
  372. SetLength(DegCP,NumFoods);
  373. SetLength(iDegCP,NumFoods);
  374. SetLength(DegCPLong,NumFoods);
  375. SetLength(iDegCPLong,NumFoods);
  376. SetLength(RNDF,NumFoods);
  377. SetLength(RQStarch,NumFoods);
  378. SetLength(RSStarch,NumFoods);
  379. SetLength(PectinPS,NumFoods);
  380. SetLength(PectinRate,NumFoods);
  381. SetLength(RDegCP,NumFoods);
  382. SetLength(RaCP,NumFoods);
  383. SetLength(SIfNDF,NumFoods);
  384. SetLength(SIiNDF,NumFoods);
  385. SetLength(SIStarch,NumFoods);
  386. SetLength(SIDegCP,NumFoods);
  387. SetLength(SIiDegCP,NumFoods);
  388. SetLength(PassPectintoSI,NumFoods);
  389. SetLength(PassfNDFtoSI,NumFoods);
  390. SetLength(PassiNDFtoSI,NumFoods);
  391. SetLength(PassfNDFLongtoSI,NumFoods);
  392. SetLength(PassiNDFLongtoSI,NumFoods);
  393. SetLength(PassQStarchtoSI,NumFoods);
  394. SetLength(PassSolCPtoSI,NumFoods);
  395. SetLength(PassDegCPtoSI,NumFoods);
  396. SetLength(PassiDegCPtoSI,NumFoods);
  397. SetLength(PassDegCPLongtoSI,NumFoods);
  398. SetLength(PassiDegCPLongtoSI,NumFoods);
  399. SetLength(FermfNDFinRum,NumFoods);
  400. SetLength(FermfNDFLonginRum,NumFoods);
  401. SetLength(FermStarchinRum,NumFoods);
  402. SetLength(FermSolCPinRum,NumFoods);
  403. SetLength(FermDegCPinRum,NumFoods);
  404. SetLength(FermDegCPLonginRum,NumFoods);
  405. SetLength(PassPectinOut,NumFoods);
  406. SetLength(PassfNDFOut,NumFoods);
  407. SetLength(PassiNDFOut,NumFoods);
  408. SetLength(HGPectinPS,NumFoods);
  409. SetLength(HGfNDF,NumFoods);
  410. SetLength(HGiNDF,NumFoods);
  411. SetLength(FermPectininHG,NumFoods);
  412. SetLength(FermfNDFinHG,NumFoods);
  413. SetLength(TotalAmount,iNoFeeds1);
  414. SetLength(HourlyActualIntake,NumFoods);
  415. SetLength(DailyIntake,NumFoods);
  416. SetLength(SupplementRatio,NumFoods);
  417. SetLength(SupplementToEat,NumFoods);
  418. SetLength(fNDFLongBreakdown,NumFoods);
  419. SetLength(iNDFLongBreakdown,NumFoods);
  420. SetLength(DegCPLongBreakdown,NumFoods);
  421. SetLength(iDegCPLongBreakdown,NumFoods);
  422. SetLength(PassSStarchLongtoSI,NumFoods);
  423. SetLength(PassUSStarchLongtoSI,NumFoods);
  424. SetLength(PassSStarchtoSI,NumFoods);
  425. SetLength(PassUSStarchtoSI,NumFoods);
  426. SetLength(PassUQStarchtoSI,NumFoods);
  427. SetLength(SStarchLongBreakdown,NumFoods);
  428. SetLength(USStarchLongBreakdown,NumFoods);
  429. SetLength(SStarchToQStarchBreakdown,NumFoods);
  430. SetLength(FermSStarchinRum,NumFoods);
  431. SetLength(FermSStarchLonginRum,NumFoods);
  432. SetLength(SProteinToQProteinSolubilisation,NumFoods);
  433. SetLength(FermPectininRum,NumFoods);
  434. SetLength(LPMultiplier,iNoFeeds1);
  435. LongForage:=False;
  436. for n1 := 0 to iNoFeeds1-1 do
  437.  begin
  438.  LPMultiplier[n1]:=1;
  439.  if rFeedInfo.TMRFeed[n1].LongForage then
  440.   begin
  441.   LongForage:=True;
  442.   LPMultiplier[n1]:=1.1;
  443.   end;
  444.  end;
  445.  
  446.  
  447.  
  448. DrinkingTime:=[1,6,9,14,18,21];
  449. //if ptrFeedDescriptions^.Week=0 then
  450. // Animal.ProteinLoss:=Animal.PMat*0.2/Animal.Tstar*1.35
  451. //else
  452. // Animal.ProteinLoss:=Animal.ProteinLoss*0.8+Animal.PMat*0.2/Animal.Tstar*1.35*0.025;
  453. MaxProtFromBody:=Animal.PMat*0.2/Animal.Teestar;//Animal.ProteinLoss;
  454. ProtFromBody:=0;
  455. //SumProteinFromBody:=0;
  456. //for loopi:=0 to UpperLimit do
  457. // SumProteinFromBody:=SumProteinFromBody
  458. //                  +ptrNutAbsorbed^.ProteinFromBody[loopi];
  459. for loopi:=0 to NumFoods-1 do
  460.  for loopm:=1 to HoursInDay do
  461.   begin
  462.   LagSGlycerolEntryTime[loopi,loopm]:=-1;
  463.   LagNDFEntryTime[loopi,loopm]:=-1;
  464.   LagSStarchEntryTime[loopi,loopm]:=-1;
  465.   LagCPEntryTime[loopi,loopm]:=-1;
  466.   end;
  467. fNDFRateOutFor:=0;FixedIntake:=True;// else FixedIntake:=False; //predicting intake - if true using predetermined intake
  468. SolCHO:=0;  SolsNDF:=0;  Ash:=0;  Oil:=0;MaxDailyLoad:=0; MonoPG_Glycerol:=0;
  469. SISolCHO:=0;  SISolCP:=0;  SIOil:=0; AcLRum:=0; PropLRum:=0; Lactate:=0;
  470. ButLRum:=0; CH4LRum:=0; MicRumLiquid:=0; BoundWater:=0; SlowReleaseNH3:=0;
  471. AcSRum:=0;PropSRum:=0;ButSRum:=0;CH4SRum:=0;MicRumSolids:=0;LacLRum:=0;LacSRum:=0;
  472. AcLaRum:=0;PropLaRum:=0;ButLaRum:=0;CH4LaRum:=0;PassUnfermentedGlyceroltoSI:=0;
  473. SIMic:=0; FDM:=0; NH3HG:=0; MicHG:=0; CH4HG:=0; AcHG:=0; PropHG:=0;
  474. ButHG:=0; SIDigCHO:=0; pH:=7.2; CAcR:=0.1; CPrR:=0.035; CBuR:=0.02;
  475. OutFlow:=0;NonForageIntake:=0;DUP:=0;MTP:=0;FaecalN:=0;FaecalfNDF:=0;
  476. FaecaliNDF:=0;NH3Lim:=0;pHLim:=0;PpnForagePolySacFerm:=0;QAc:=0;QPr:=0;
  477. QBu:=0;QCHO:=0;QMTP:=0;QMP:=0;QDUP:=0; HGsNDF:=0;avDMIGrazing:=0;
  478. RuminationSaliva:=0;Protons:=0;{NaHCO3:=0.13*15*ptrFeedDescriptions^.RVol/10025;}DailyFlowSaliva:=0;
  479. QMicSolidsR:=10*ptrFeedDescriptions^.RVol;QMicLiquidR:=10*ptrFeedDescriptions^.RVol;
  480. QDeadSolidMicrobes:=0;LiquidCHO:=0;LiquidProt:=0;LiquidLip:=0;QMicHG:=0.1*ptrFeedDescriptions^.RVol;
  481. QDeadLiquidMicrobes:=0;QDeadLiquidMicrobesLa:=0;SIMicCHO:=0;SIMicLip:=0;
  482. ppnNeutralised:=1;LaUtCHO:=0;LaUtProt:=0;LaUtLip:=0;LaUtAsh:=0;TimeSpentEating:=0;
  483. MolarNaHCO3:=0.04;UnfermentedGlycerolSmall:=0;Glycerol:=0; HalfRoboticDMI:=1;
  484. MaxLongParticles:=0; MaxLPBR:=False;TotalLongParticles:=0; DMRatio:=0.5;
  485. //dPassGlycerol:=0;dGlycerol:=0;
  486. for loopi:=1 to 10 do pHOverTime[loopi]:=6.8;
  487.  QMicLaUtR:=100*ptrFeedDescriptions^.RVol/100;
  488.  QMicLaR:=30*ptrFeedDescriptions^.RVol/100;
  489. if ptrFeedDescriptions^.TMR then
  490.  begin
  491.  ptrFeedDescriptions^.RumSA:=251360*power(ptrFeedDescriptions^.RumFillUpper
  492.                              *ptrFeedDescriptions^.RVol/4189.333,0.667);// 'cm2
  493.  end
  494. else
  495.  begin
  496. // ptrFeedDescriptions^.RumFillUpper:=1.2;
  497.  end;
  498. //initialise compartments by assuming first meal fills rumen, unless DMI has been
  499. //set - in which case use value from DMI that is passed in - it will be > 0
  500. if not FSGrazingAll[ptrFeedDescriptions^.Diet] then
  501.  begin
  502.  for loopi:=0 to iNoFeeds1-1 do  //calculate total of amount array
  503.    TotalAmount[loopi]:=TotalAmount[loopi]+
  504.     ptrAmount^[loopi+(ptrFeedDescriptions^.Diet-1)*iNoFeeds1];
  505.  end;
  506. if not FSGrazingAll[ptrFeedDescriptions^.Diet] then
  507.  begin
  508.  for loopi:=0 to iNoFeeds1-1 do MaxDailyLoad:=MaxDailyLoad+TotalAmount[loopi];
  509.  for loopi:=0 to ptrFeedDescriptions^.iNoFeeds-1 do
  510.  //Rumen Pools
  511.  begin
  512.   if FixedIntake then
  513.    begin
  514.    if ptrFeedDescriptions^.TMR then Scalar:=ptrFeedDescriptions^.RVol*0.15*0.4 else Scalar:=1;    //0.5 to 10
  515.    sss:=Scalar*TotalAmount[loopi]/MaxDailyLoad;
  516.    if ptrFeedDescriptions^.Long then
  517.     begin
  518.     fNDF[loopi]:=(1-ptrFeedDescriptions^.TMRFeed[loopi].LargePartLag)*sss
  519.                   *ptrFeedDescriptions^.TMRFeed[loopi].fermNDF;
  520.     iNDF[loopi]:=(1-ptrFeedDescriptions^.TMRFeed[loopi].LargePartLag)*sss
  521.                   *ptrFeedDescriptions^.TMRFeed[loopi].unfermNDF;
  522.     fNDFLong[loopi]:=ptrFeedDescriptions^.TMRFeed[loopi].LargePartLag*sss
  523.                   *ptrFeedDescriptions^.TMRFeed[loopi].fermNDF;
  524.     iNDFLong[loopi]:=ptrFeedDescriptions^.TMRFeed[loopi].LargePartLag*sss
  525.                   *ptrFeedDescriptions^.TMRFeed[loopi].unfermNDF;
  526.     SStarch[loopi]:=(1-ptrFeedDescriptions^.TMRFeed[loopi].LargePartLag)*sss
  527.                   *ptrFeedDescriptions^.TMRFeed[loopi].SlowStarch;
  528.     USStarch[loopi]:=(1-ptrFeedDescriptions^.TMRFeed[loopi].LargePartLag)*sss
  529.                   *ptrFeedDescriptions^.TMRFeed[loopi].UndegSStarch;
  530.     SStarchLong[loopi]:=ptrFeedDescriptions^.TMRFeed[loopi].LargePartLag*sss
  531.                   *ptrFeedDescriptions^.TMRFeed[loopi].SlowStarch;
  532.     USStarchLong[loopi]:=ptrFeedDescriptions^.TMRFeed[loopi].LargePartLag*sss
  533.                   *ptrFeedDescriptions^.TMRFeed[loopi].UndegSStarch;
  534.     end
  535.    else
  536.     begin
  537.     fNDF[loopi]:=sss*ptrFeedDescriptions^.TMRFeed[loopi].fermNDF;
  538.     iNDF[loopi]:=sss*ptrFeedDescriptions^.TMRFeed[loopi].unfermNDF;
  539.     SStarch[loopi]:=sss*ptrFeedDescriptions^.TMRFeed[loopi].SlowStarch;
  540.     USStarch[loopi]:=sss*ptrFeedDescriptions^.TMRFeed[loopi].UndegSStarch;
  541.     end;
  542.    QStarch[loopi]:=sss*ptrFeedDescriptions^.TMRFeed[loopi].QuickStarch;
  543.    UQStarch[loopi]:=sss*ptrFeedDescriptions^.TMRFeed[loopi].UndegQStarch;
  544.    DegCP[loopi]:=sss*ptrFeedDescriptions^.TMRFeed[loopi].P2;
  545.    iDegCP[loopi]:=sss*ptrFeedDescriptions^.TMRFeed[loopi].P3;
  546.    SolCHO:=SolCHO+sss*ptrFeedDescriptions^.TMRFeed[loopi].C1;
  547.    if ptrFeedDescriptions^.Pectins then
  548.     begin
  549.     SolsNDF:=0;
  550.     PectinPS[loopi]:=sss*ptrFeedDescriptions^.TMRFeed[loopi].C1sNDF;
  551.     end
  552.    else
  553.     begin
  554.     if ptrFeedDescriptions^.ACHOintoWSCsNDF then
  555.      SolsNDF:=SolsNDF+sss*ptrFeedDescriptions^.TMRFeed[loopi].C1sNDF
  556.     else SolsNDF:=0;
  557.     end;
  558.    SolCP[loopi]:=sss*ptrFeedDescriptions^.TMRFeed[loopi].P1;
  559.    Ash:=Ash+sss*ptrFeedDescriptions^.TMRFeed[loopi].Mins;
  560.    Oil:=Oil+sss*ptrFeedDescriptions^.TMRFeed[loopi].EE;
  561.    BoundWater:=BoundWater+fNDF[loopi]+iNDF[loopi]+QStarch[loopi];
  562.    end;
  563.   //SI Pools
  564.   SIfNDF[loopi]:=0;
  565.   SIiNDF[loopi]:=0;
  566.   SIStarch[loopi]:=0;
  567.   SIDegCP[loopi]:=0;
  568.   SIiDegCP[loopi]:=0;
  569.   end;
  570.  end
  571. else
  572.  begin
  573.    Scalar:=ptrFeedDescriptions^.RVol*0.15*0.5;
  574. //Grazing is NumFoods-1 - PreMixParlourNo when iParlour is on.
  575.    count:=NumFoods-counter;
  576.    if ptrFeedDescriptions^.Long then
  577.     begin
  578.     fNDF[count]:=(1-ptrFeedDescriptions^.GrazingFeed.LargePartLag)*Scalar
  579.          *ptrFeedDescriptions^.GrazingFeed.fermNDF;
  580.     iNDF[count]:=(1-ptrFeedDescriptions^.GrazingFeed.LargePartLag)*Scalar
  581.          *ptrFeedDescriptions^.GrazingFeed.unfermNDF;
  582.     fNDFLong[count]:=ptrFeedDescriptions^.GrazingFeed.LargePartLag*Scalar
  583.          *ptrFeedDescriptions^.GrazingFeed.fermNDF;
  584.     iNDFLong[count]:=ptrFeedDescriptions^.GrazingFeed.LargePartLag*Scalar
  585.          *ptrFeedDescriptions^.GrazingFeed.unfermNDF;
  586.     SStarch[count]:=(1-ptrFeedDescriptions^.GrazingFeed.LargePartLag)*Scalar
  587.          *ptrFeedDescriptions^.GrazingFeed.SlowStarch;
  588.     USStarch[count]:=(1-ptrFeedDescriptions^.GrazingFeed.LargePartLag)*Scalar
  589.          *ptrFeedDescriptions^.GrazingFeed.UndegSStarch;
  590.     SStarchLong[count]:=ptrFeedDescriptions^.GrazingFeed.LargePartLag*Scalar
  591.          *ptrFeedDescriptions^.GrazingFeed.SlowStarch;
  592.     USStarchLong[count]:=ptrFeedDescriptions^.GrazingFeed.LargePartLag*Scalar
  593.          *ptrFeedDescriptions^.GrazingFeed.UndegSStarch;
  594.     end
  595.    else
  596.     begin
  597.     fNDF[count]:=Scalar*ptrFeedDescriptions^.GrazingFeed.fermNDF;
  598.     iNDF[count]:=Scalar*ptrFeedDescriptions^.GrazingFeed.unfermNDF;
  599.     SStarch[count]:=Scalar*ptrFeedDescriptions^.GrazingFeed.SlowStarch;
  600.     USStarch[count]:=Scalar*ptrFeedDescriptions^.GrazingFeed.UndegSStarch;
  601.     end;
  602.    QStarch[count]:=Scalar*ptrFeedDescriptions^.GrazingFeed.QuickStarch;
  603.    UQStarch[count]:=Scalar*ptrFeedDescriptions^.GrazingFeed.UndegQStarch;
  604.    DegCP[count]:=Scalar*ptrFeedDescriptions^.GrazingFeed.P2;
  605.    iDegCP[count]:=Scalar*ptrFeedDescriptions^.GrazingFeed.P3;
  606.    SolCHO:=SolCHO+Scalar*ptrFeedDescriptions^.GrazingFeed.C1;
  607.    if ptrFeedDescriptions^.Pectins then
  608.     begin
  609.     SolsNDF:=0;
  610.     PectinPS[count]:=Scalar*ptrFeedDescriptions^.GrazingFeed.C1sNDF;
  611.     end
  612.    else
  613.     begin
  614.     if ptrFeedDescriptions^.ACHOintoWSCsNDF then
  615.      SolsNDF:=SolsNDF+Scalar*ptrFeedDescriptions^.GrazingFeed.C1sNDF
  616.     else SolsNDF:=0;
  617.     end;
  618.    SolCP[count]:=Scalar*ptrFeedDescriptions^.GrazingFeed.P1;
  619.    Ash:=Ash+Scalar*ptrFeedDescriptions^.GrazingFeed.Mins;
  620.    Oil:=Oil+Scalar*ptrFeedDescriptions^.GrazingFeed.EE;
  621.    BoundWater:=BoundWater+fNDF[count]+iNDF[count]+QStarch[count];
  622.   //SI Pools
  623.   SIfNDF[count]:=0;
  624.   SIiNDF[count]:=0;
  625.   SIStarch[count]:=0;
  626.   SIDegCP[count]:=0;
  627.   SIiDegCP[count]:=0;
  628.  end;
  629. NH3Rum:=0.005*17*ptrFeedDescriptions^.RVol; //g - assume initial conc of 5mM
  630. //calculate rates per tslp
  631. HGPPass := (0.8/0.2)*ptrFeedDescriptions^.PPass;//foregut ppn/HGppn
  632. if not FSGrazingAll[ptrFeedDescriptions^.Diet] then
  633.  for loopi:=0 to ptrFeedDescriptions^.iNoFeeds-1 do
  634.   begin
  635.   RSGlycerol[loopi]:=Power(1+ptrFeedDescriptions^.TMRFeed[loopi].SlowGlycerolRate,1/StepsPerHour)-1;
  636.   RNDF[loopi]:=(Power(1+ptrFeedDescriptions^.TMRFeed[loopi].RC2,1/StepsPerHour)-1){*0.5};
  637.   RQStarch[loopi]:=Power(1+ptrFeedDescriptions^.TMRFeed[loopi].RC3,1/StepsPerHour)-1;
  638.   RSStarch[loopi]:=(Power(1+ptrFeedDescriptions^.TMRFeed[loopi].RSStarch,1/StepsPerHour)-1){*0.5};
  639.   RDegCP[loopi]:=Power(1+ptrFeedDescriptions^.TMRFeed[loopi].RP2,1/StepsPerHour)-1;
  640.   RaCP[loopi]:=Power(1+ptrFeedDescriptions^.TMRFeed[loopi].RP1,1/StepsPerHour)-1;
  641.   PectinRate[loopi]:=Power(1+ptrFeedDescriptions^.TMRFeed[loopi].PectinRate,1/StepsPerHour)-1;
  642.   SlowReleaseNH3Rate[loopi]:=Power(1+ptrFeedDescriptions^.TMRFeed[loopi].SRNH3Rate,1/StepsPerHour)-1;
  643.   end;
  644. if ptrFeedDescriptions^.iGrazing>0 then
  645. //Grazing is NumFoods-1 - PreMixParlourNo when iParlour is on.
  646.  begin
  647.  count:=ptrFeedDescriptions^.iNoFeeds;
  648.  RSGlycerol[count]:=Power(1+ptrFeedDescriptions^.GrazingFeed.SlowGlycerolRate,1/StepsPerHour)-1;
  649.  RNDF[count]:=Power(1+ptrFeedDescriptions^.GrazingFeed.RC2,1/StepsPerHour)-1;
  650.  RQStarch[count]:=Power(1+ptrFeedDescriptions^.GrazingFeed.RC3,1/StepsPerHour)-1;
  651.  RSStarch[count]:=Power(1+ptrFeedDescriptions^.GrazingFeed.RSStarch,1/StepsPerHour)-1;
  652.  RDegCP[count]:=Power(1+ptrFeedDescriptions^.GrazingFeed.RP2,1/StepsPerHour)-1;
  653.  RaCP[count]:=Power(1+ptrFeedDescriptions^.GrazingFeed.RP1,1/StepsPerHour)-1;
  654.  PectinRate[count]:=Power(1+ptrFeedDescriptions^.GrazingFeed.PectinRate,1/StepsPerHour)-1;
  655.  end;
  656. if ptrFeedDescriptions^.iParlour>0 then
  657.  begin
  658.  n1:=0;
  659.  for count:=ParlourCountLow to ParlourCountHigh do
  660.   begin
  661.   RSGlycerol[count]:=Power(1+ptrFeedDescriptions^.ParlourFeed[n1].SlowGlycerolRate,1/StepsPerHour)-1;
  662.   RNDF[count]:=Power(1+ptrFeedDescriptions^.ParlourFeed[n1].RC2,1/StepsPerHour)-1;
  663.   RQStarch[count]:=Power(1+ptrFeedDescriptions^.ParlourFeed[n1].RC3,1/StepsPerHour)-1;
  664.   RSStarch[count]:=Power(1+ptrFeedDescriptions^.ParlourFeed[n1].RSStarch,1/StepsPerHour)-1;
  665.   RDegCP[count]:=Power(1+ptrFeedDescriptions^.ParlourFeed[n1].RP2,1/StepsPerHour)-1;
  666.   RaCP[count]:=Power(1+ptrFeedDescriptions^.ParlourFeed[n1].RP1,1/StepsPerHour)-1;
  667.   PectinRate[count]:=Power(1+ptrFeedDescriptions^.ParlourFeed[n1].PectinRate,1/StepsPerHour)-1;
  668.   SlowReleaseNH3Rate[count]:=Power(1+ptrFeedDescriptions^.ParlourFeed[n1].SRNH3Rate,1/StepsPerHour)-1;
  669.   inc(n1);
  670.   end;
  671.  end;
  672. if ptrFeedDescriptions^.iRobotic>1 then
  673.  begin
  674.  n1:=0;
  675.  for count:=RoboticCountLow to RoboticCountHigh do
  676.   begin
  677.   RSGlycerol[count]:=Power(1+ptrFeedDescriptions^.RoboticFeed[n1].SlowGlycerolRate,1/StepsPerHour)-1;
  678.   RNDF[count]:=Power(1+ptrFeedDescriptions^.RoboticFeed[n1].RC2,1/StepsPerHour)-1;
  679.   RQStarch[count]:=Power(1+ptrFeedDescriptions^.RoboticFeed[n1].RC3,1/StepsPerHour)-1;
  680.   RSStarch[count]:=Power(1+ptrFeedDescriptions^.RoboticFeed[n1].RSStarch,1/StepsPerHour)-1;
  681.   RDegCP[count]:=Power(1+ptrFeedDescriptions^.RoboticFeed[n1].RP2,1/StepsPerHour)-1;
  682.   RaCP[count]:=Power(1+ptrFeedDescriptions^.RoboticFeed[n1].RP1,1/StepsPerHour)-1;
  683.   PectinRate[count]:=Power(1+ptrFeedDescriptions^.RoboticFeed[n1].PectinRate,1/StepsPerHour)-1;
  684.   SlowReleaseNH3Rate[count]:=Power(1+ptrFeedDescriptions^.RoboticFeed[n1].SRNH3Rate,1/StepsPerHour)-1;
  685.   inc(n1);
  686.   end;
  687.  end;
  688. if ptrFeedDescriptions^.iLiquid>0 then
  689.  begin
  690.  count:=LiquidCount;
  691.   begin
  692.   RSGlycerol[count]:=Power(1+ptrFeedDescriptions^.LiquidFeed.SlowGlycerolRate,1/StepsPerHour)-1;
  693.   RNDF[count]:=Power(1+ptrFeedDescriptions^.LiquidFeed.RC2,1/StepsPerHour)-1;
  694.   RQStarch[count]:=Power(1+ptrFeedDescriptions^.LiquidFeed.RC3,1/StepsPerHour)-1;
  695.   RSStarch[count]:=Power(1+ptrFeedDescriptions^.LiquidFeed.RSStarch,1/StepsPerHour)-1;
  696.   RDegCP[count]:=Power(1+ptrFeedDescriptions^.LiquidFeed.RP2,1/StepsPerHour)-1;
  697.   RaCP[count]:=Power(1+ptrFeedDescriptions^.LiquidFeed.RP1,1/StepsPerHour)-1;
  698.   PectinRate[count]:=Power(1+ptrFeedDescriptions^.LiquidFeed.PectinRate,1/StepsPerHour)-1;
  699.   SlowReleaseNH3Rate[count]:=Power(1+ptrFeedDescriptions^.LiquidFeed.SRNH3Rate,1/StepsPerHour)-1;
  700.   end;
  701.  end;
  702.  
  703. RMicProt:=Power(1+MicrobialProteinRate,1/StepsPerHour)-1;
  704. RSolCHO:=Power(1+ptrFeedDescriptions^.RC1,1/StepsPerHour)-1;
  705. RLPass:=Power(1+ptrFeedDescriptions^.LPass,1/StepsPerHour)-1;
  706. RPPass:=Power(1+ptrFeedDescriptions^.PPass,1/StepsPerHour)-1;
  707. HGPPass:=Power(1+HGPPass,1/StepsPerHour)-1;
  708. ConcPPass:=(-0.424+1.45*ptrFeedDescriptions^.PPass*100)/100;
  709. RConcPPass:=Power(1+ConcPPass,1/StepsPerHour)-1;
  710. //if ptrFeedDescriptions^.Long then
  711. // if not ptrFeedDescriptions^.LPBRwithRumination then
  712. //  LPBR:=Power(1+ptrFeedDescriptions^.LongParticleBR,1/StepsPerHour)-1
  713. // else
  714. LPBreakdownR:=Power(1+2*ptrFeedDescriptions^.LongParticleBR,1/StepsPerHour)-1;
  715. //Andy on Pickervance diet led to the following 0.1. That agrees with what they were eating
  716. //if Beef then
  717. // LPBreakdownR:=LPBreakdownR*0.8
  718. //else
  719. //  if LeftStr(Instant.Edit66.Text,1)='-' then
  720. if ChopLength then
  721.  if version1_01_16 then
  722.   begin
  723.   LPBreakdownR:=LPBreakdownR*0.45*LargeParticleBR;
  724.   end
  725.  else
  726.   begin
  727.   LPBreakdownR:=LPBreakdownR*0.45*LargeParticleBR
  728.   end
  729. else
  730.  LPBreakdownR:=LPBreakdownR*0.5*LargeParticleBR;
  731. //Rumen water
  732. FreeWater:=ptrFeedDescriptions^.RVol*0.75;
  733. //ptrFeedDescriptions^.RumFillUpper:=1;
  734. LiquidVolume:=FreeWater*1.2;
  735. OxygenLevel:=1*LiquidVolume;  //umole/litre
  736. Neutralised:=0.155*LiquidVolume;
  737. RestSaliva:=RestSalivaPpn*21.25*ptrFeedDescriptions^.ActualWeight*0.375/Thousand/StepsPerHour;//kg/tstep
  738. ElapsedTime:=0;
  739. PassageFree:=RLPass*FreeWater/LiquidVolume;
  740. PassageBound:=RConcPPass*(1-FreeWater/LiquidVolume);
  741. //Start main loops
  742. for Days1toEnd:=1 to ptrFeedDescriptions^.iDaysToRun do //daily loop
  743.  begin
  744.   ptrNutAbsorbed^.RuminationTime:=1;
  745.   EEsoFar:=0; DaysIntake:=0;
  746.   dQAcR:=0; dQAcHG:=0; dQPrR:=0; dQPrHG:=0; dQBuR:=0; dQBuHG:=0;
  747.   dSIDigCHO:=0; dSIMic:=0; dMP:=0; dAbsOil:=0; dQLaR:=0; dSIMicCHO:=0;dSIMicLip:=0;
  748.   UrineWater:=0;WaterDrunk:=0; UrinaryN:=0;GrassDailyIntake:=0;TMRDailyIntake:=0;
  749.   for loopi:=0 to NumFoods-1 do SupplementToEat[loopi]:=0;//initialise
  750.   for Hours1to24:=1 to HoursInDay do //hourly loop
  751.    begin
  752.    HFSCiR:=0;
  753.    HFNiR:=0;
  754.    HFSiR:=0; HFSSiR:=0;
  755.    HSCPiR:=0;
  756.    HDCPiR:=0;
  757. //   HSCiR:=0;
  758. //   HPSCiR:=0;
  759.    HFNH3QiR:=0;
  760.    HFNH3SiR:=0;
  761.    hEMNSh:=0;
  762.    PAcR:=0; PPrR:=0; PBuR:=0; PLaR:=0; //dpH:=0;
  763.    FreeProteinRatio:=0; SolidProteinRatio:=0;
  764.    dAcid:=0; dNaHCO3:=0;
  765. //put eating grazing vs tmr here
  766.    if FSGrazingpemNDF then
  767.     begin
  768.     if (Hours1to24 in GrazingHour[ptrFeedDescriptions^.Diet]) then
  769.      begin
  770. //     EatingTime:=[3,8,12,14,17,19,23];
  771. //     EatingTime:=[3,8,10,12,14,16,18,20,23];
  772.      EatingTime:=[2,6,9,12,15,18,20,23];
  773. //     if ActiveFibreGrazing<27.5 then
  774. //      RuminatingTime:=0.0054*ActiveFibreGrazing+0.4531
  775. //     else
  776. //      RuminatingTime:=0.6;
  777. //     Available2Eat:=WakingTime*(1-RuminatingTime);
  778. //     if Available2Eat<9.5 then EatingTime:=[4,7,9,12,15,18,21,24]
  779. //     else if Available2Eat<10.5 then EatingTime:=[3,6,9,12,14,16,18,21,24]
  780. //     else if Available2Eat<11.5 then EatingTime:=[2,4,6,9,12,14,16,18,21,23]
  781. //     else EatingTime:=[2,4,6,8,10,12,14,16,18,21,23];
  782.      end;
  783.     end
  784.    else
  785.     begin
  786. //    if ActiveFibreTMR<27.5 then
  787. //      RuminatingTime:=0.0054*ActiveFibreTMR+0.4531
  788. //    else
  789. //      RuminatingTime:=0.6;
  790. //    Available2Eat:=WakingTime*(1-RuminatingTime);
  791.     if Virgilio then
  792.      begin
  793.  
  794.      end
  795.     else if TMRRobotic then
  796.      begin
  797.  
  798.      end
  799.     else if NoOfMeals=11 then
  800.      begin
  801. //10 to 7 meals per day
  802.      if StrToInt(Instant.Edit63.Text)<=39 then
  803.       if version1_01_16 then
  804.        begin
  805.        if Beef then
  806.         EatingTime:=[3,7,11,15,19,23]
  807.        else
  808.         EatingTime:=[3,7,9,12,15,18,20,23];
  809.        end
  810.       else
  811.        begin
  812.        EatingTime:=[2,6,9,12,16,19,22];
  813.        end
  814.      else if StrToInt(Instant.Edit63.Text)<=49 then
  815.       EatingTime:=[3,7,9,12,15,18,20,23]
  816.      else
  817.       EatingTime:=[2,4,6,8,10,12,14,17,19,22];//[2,6,9,12,16,19,22];//[3,8,12,14,17,19,23];//[3,8,11,14,18,21,24]; //[3,8,12,14,16,19,23]
  818. //     if Available2Eat<9.5 then EatingTime:=[4,7,9,12,15,18,21,24] [2,4,7,9,12,15,18,20,23];//
  819. //     else if Available2Eat<10.5 then EatingTime:=[3,6,9,12,14,16,18,21,24]
  820. //     else if Available2Eat<11.0 then EatingTime:=[2,4,6,9,12,14,16,18,20,23]
  821. //     else EatingTime:=[2,4,6,8,10,12,14,16,18,21,23];
  822.      end
  823.     else if NoOfMeals=8 then
  824.      begin
  825. {88}     EatingTime:=[2,6,9,11,14,18,20,23];//[3,8,12,14,16,18,20,23];
  826.      end
  827.     else if NoOfMeals=6 then
  828.      begin
  829.      EatingTime:=[8,12,16,18,21,24];
  830.      end
  831.     else if NoOfMeals=4 then
  832.      begin
  833.      EatingTime:=[1,8,14,20];
  834.      end;
  835.     end;
  836.     for StepHours1toEnd:=1 to StepsPerHour do //within hour loop
  837.      begin
  838.  
  839.      if (LagTimeParlour) and (LagParlourFeed>0) then
  840.       begin
  841.       n1:=0;
  842.  
  843.       for count:=NumFoods-counter+1 to NumFoods-1-ptrFeedDescriptions^.iRobotic do
  844.        begin
  845.        ParlourPerMealPerFood:=LagParlourFeed/StepsPerHour
  846.                                      *PMParlourAmount[n1]/100;
  847.        QStarch[count]:=QStarch[count]+ParlourPerMealPerFood
  848.                       *ptrFeedDescriptions^.ParlourFeed[n1].QuickStarch;
  849.        UQStarch[count]:=UQStarch[count]+ParlourPerMealPerFood
  850.                       *ptrFeedDescriptions^.ParlourFeed[n1].UndegQStarch;
  851.        SolCHO:=SolCHO+ParlourPerMealPerFood
  852.                       *ptrFeedDescriptions^.ParlourFeed[n1].C1;
  853.        MonoPG_Glycerol:=MonoPG_Glycerol+ParlourPerMealPerFood
  854.                       *ptrFeedDescriptions^.ParlourFeed[n1].MPG;
  855.        Glycerol:=Glycerol+ParlourPerMealPerFood
  856.                       *ptrFeedDescriptions^.ParlourFeed[n1].Glycerol;
  857.        UnfermentedGlycerolSmall:=UnfermentedGlycerolSmall+ParlourPerMealPerFood
  858.                       *ptrFeedDescriptions^.ParlourFeed[n1].UnfermentedGlycerol;
  859.        SolCP[count]:=SolCP[count]+ParlourPerMealPerFood
  860.                       *ptrFeedDescriptions^.ParlourFeed[n1].P1;
  861.        if ptrFeedDescriptions^.Pectins then
  862.         begin
  863.         SolsNDF:=0;
  864.         PectinPS[count]:=PectinPS[count]+ParlourPerMealPerFood
  865.                       *ptrFeedDescriptions^.ParlourFeed[n1].C1sNDF;
  866.         end
  867.        else
  868.         begin
  869.         if ptrFeedDescriptions^.ACHOintoWSCsNDF then
  870.          SolsNDF:=SolsNDF+ParlourPerMealPerFood
  871.                *ptrFeedDescriptions^.ParlourFeed[n1].C1sNDF
  872.         else SolsNDF:=0;
  873.         end;
  874.        Ash:=Ash+ParlourPerMealPerFood
  875.           *ptrFeedDescriptions^.ParlourFeed[n1].Mins;
  876.        Oil:=Oil+ParlourPerMealPerFood
  877.           *ptrFeedDescriptions^.ParlourFeed[n1].EE;
  878.        ConsumedVFA:=ConsumedVFA+ParlourPerMealPerFood
  879.                   *ptrFeedDescriptions^.ParlourFeed[n1].fVFA;
  880.        Lactate:=Lactate+ParlourPerMealPerFood
  881.               *ptrFeedDescriptions^.ParlourFeed[n1].fLactic;
  882.        ConsumedNH3:=ConsumedNH3+ParlourPerMealPerFood
  883.                   *ptrFeedDescriptions^.ParlourFeed[n1].fNH3;
  884.        AcidEaten:=AcidEaten+ParlourPerMealPerFood
  885.                  *ptrFeedDescriptions^.ParlourFeed[n1].PpnAcid;
  886.        BicarbonateEaten:=BicarbonateEaten+ParlourPerMealPerFood
  887.                         *ptrFeedDescriptions^.ParlourFeed[n1].HCO3*Thousand/MWNaHCO3;
  888.        FeedWater:=FeedWater+ParlourPerMealPerFood*10
  889.                 *(100-ptrFeedDescriptions^.ParlourFeed[n1].DM);
  890.        inc(n1);
  891.        end;
  892.       end;
  893.  
  894.      if (Hours1to24 in AwakeTime) and (not (Hours1to24+1 in EatingTime)) then
  895.       begin
  896.       if (FSParlour[ptrFeedDescriptions^.Diet]) and
  897.        (Hours1to24 in ParlourHour[ptrFeedDescriptions^.Diet]) then
  898.        begin
  899.        if ptrFeedDescriptions^.LPBRwithRumination then LPBR:=0;
  900.        RuminationSaliva:=0;
  901.        end
  902.       else
  903.        begin
  904. // ruminating saliva needs to be fixed to large part vs small part
  905.        if ptrFeedDescriptions^.LPBRwithRumination then LPBR:=LPBreakdownR;
  906.        LongParticles:=0; ShortParticles:=0;
  907.        if ChopLength then
  908.         begin
  909.         for loopi:=0 to NumFoods-1 do
  910.          begin
  911.          LongParticles:=LongParticles+fNDFLong[loopi]+iNDFLong[loopi]
  912.                         +SStarchLong[loopi]+USStarchLong[loopi]
  913.                         +DegCPLong[loopi]+iDegCPLong[loopi];
  914.          ShortParticles:=ShortParticles+fNDF[loopi]+iNDF[loopi]
  915.                          +SStarch[loopi]+USStarch[loopi]
  916.                          +DegCP[loopi]+iDegCP[loopi];
  917.          end;
  918.         if (Days1toEnd=4) and (Hours1to24=HoursinDay)
  919.          and (StepHours1toEnd=StepsPerHour) then
  920.          begin
  921.          MaxLongParticles:=LongParticles/(ptrNutAbsorbed^.RuminationTime
  922.                            *60/StepsPerHour)*MaxRuminationTime;
  923.          TotalLongParticles:=LongParticles;
  924.          MaxLPBR:=True;
  925.          end;
  926.         if MaxLPBR then
  927.          LPBR:=TotalLongParticles*LPBR/LongParticles
  928.         else
  929.          LPBR:=LPBR;
  930.         end
  931.        else
  932.         begin
  933.         for loopi:=0 to NumFoods-1 do
  934.          begin
  935.          LongParticles:=LongParticles+fNDFLong[loopi]+iNDFLong[loopi];
  936.          ShortParticles:=ShortParticles+fNDF[loopi]+iNDF[loopi];
  937.          end;
  938.         end;
  939. //if (Days1toEnd=20)  then
  940. //     QMP:=QMP;
  941.        if LongParticles/(LongParticles+ShortParticles)>ptrFeedDescriptions^.RatioLongtoTotal then
  942.         begin
  943.         if pH<7 then
  944.          RuminationSaliva:=1.17*27.1*0.375/Thousand/StepsPerHour
  945.                            *ptrFeedDescriptions^.ActualWeight
  946.         else
  947.          RuminationSaliva:=0.5*27.1*0.375/Thousand/StepsPerHour*ptrFeedDescriptions^.ActualWeight;
  948.         inc(ptrNutAbsorbed^.RuminationTime);
  949.         end
  950.        else
  951.         begin
  952.         if ptrFeedDescriptions^.LPBRwithRumination then
  953.          if version1_01_16 then
  954.           begin
  955.           LPBR:=LPBreakdownR*0.15*ForageDMBelow30Ppn;
  956.           end
  957.          else
  958.           begin
  959.           LPBR:=0;
  960.           end;
  961.         RuminationSaliva:=0;
  962.         end;
  963.        end;
  964.       end
  965.      else
  966.       begin
  967.       if ptrFeedDescriptions^.LPBRwithRumination then
  968.          if version1_01_16 then
  969.           begin
  970.           LPBR:=LPBreakdownR*0.15*ForageDMBelow30Ppn;
  971.           end
  972.          else
  973.           begin
  974.           LPBR:=0;
  975.           end;
  976.       RuminationSaliva:=0;
  977.       end;
  978. //TimeSpentEating flows in here from way down below to put on or off the EatingSaliva
  979. //(line 2052)
  980.      if StepHours1toEnd*60/StepsPerHour<TimeSpentEating then
  981. //Eating time increased to 10 per day. Have to decrease the amount of eating saliva produced each meal hence 0.54
  982.       SalivaFlow:=EatingSaliva+RestSaliva+{1.5*}RuminationSaliva
  983.      else SalivaFlow:=RestSaliva+RuminationSaliva ;
  984. //if (Days1toEnd=20){ and (Hours1to24>7)} and (StepHours1toEnd=1) then
  985. //      QMP:=QMP;
  986.      try
  987.      if ptrFeedDescriptions^.LagTime then
  988.       begin
  989.       PassLagSGlyceroltoSI:=0;
  990.       PassLagUreatoSI:=0;
  991.       for loopi:=0 to NumFoods-1 do
  992.        begin
  993.        PassLagfNDFtoSI[loopi]:=0;
  994.        PassLagiNDFtoSI[loopi]:=0;
  995.        PassLagSStarchtoSI[loopi]:=0;
  996.        PassLagUSStarchtoSI[loopi]:=0;
  997.        PassLagDegCPtoSI[loopi]:=0;
  998.        PassLagiDegCPtoSI[loopi]:=0;
  999.        LagSGlycerol[loopi]:=0;
  1000.        LagNDF[loopi]:=0;
  1001.        LagSStarch[loopi]:=0;
  1002.        LagCP[loopi]:=0;
  1003.        LagUrea[loopi]:=0;
  1004.        end;
  1005.       ElapsedTime:=HoursInDay*(Days1toEnd-1)+Hours1to24-1+StepHours1toEnd/StepsPerHour;
  1006.       for loopi:=0 to NumFoods-1 do
  1007.        for loopm:=1 to HoursInDay do
  1008.         begin
  1009.         if (LagNDFEntryTime[loopi,loopm]>0) then
  1010.          begin
  1011.          if (LagNDFEntryTime[loopi,loopm]<ElapsedTime) then
  1012.           begin
  1013.           if not (FSGrazingAll[ptrFeedDescriptions^.Diet]) and
  1014.            (loopi<ptrFeedDescriptions^.iNoFeeds) then
  1015.            begin
  1016.            fNDF[loopi]:=fNDF[loopi]+LagfNDFToEnter[loopi,loopm]
  1017.                          *(1-ptrFeedDescriptions^.TMRFeed[loopi].LargePartLag*LPMultiplier[loopi]);
  1018.            iNDF[loopi]:=iNDF[loopi]+LagiNDFToEnter[loopi,loopm]
  1019.                          *(1-ptrFeedDescriptions^.TMRFeed[loopi].LargePartLag*LPMultiplier[loopi]);
  1020.            fNDFLong[loopi]:=fNDFLong[loopi]+LagfNDFToEnter[loopi,loopm]
  1021.                              *ptrFeedDescriptions^.TMRFeed[loopi].LargePartLag*LPMultiplier[loopi];
  1022.            iNDFLong[loopi]:=iNDFLong[loopi]+LagiNDFToEnter[loopi,loopm]
  1023.                              *ptrFeedDescriptions^.TMRFeed[loopi].LargePartLag*LPMultiplier[loopi];
  1024.            end
  1025.           else if loopi=ptrFeedDescriptions^.iNoFeeds-1+ptrFeedDescriptions^.iGrazing then
  1026.            begin
  1027.            fNDF[loopi]:=fNDF[loopi]+LagfNDFToEnter[loopi,loopm]
  1028.                          *(1-ptrFeedDescriptions^.GrazingFeed.LargePartLag);
  1029.            iNDF[loopi]:=iNDF[loopi]+LagiNDFToEnter[loopi,loopm]
  1030.                          *(1-ptrFeedDescriptions^.GrazingFeed.LargePartLag);
  1031.            fNDFLong[loopi]:=fNDFLong[loopi]+LagfNDFToEnter[loopi,loopm]
  1032.                              *ptrFeedDescriptions^.GrazingFeed.LargePartLag;
  1033.            iNDFLong[loopi]:=iNDFLong[loopi]+LagiNDFToEnter[loopi,loopm]
  1034.                              *ptrFeedDescriptions^.GrazingFeed.LargePartLag;
  1035.            end
  1036.           else if loopi>ptrFeedDescriptions^.iNoFeeds-1+ptrFeedDescriptions^.iGrazing
  1037.                           then
  1038. //if loopi >, there is a Parlour Feed and maybe a Robotic Feed. ParlourFeed[numbers]
  1039. //and RoboticFeed[numbers] start from zero and go up
  1040. //to the total number of ingredients in a parlour feed -1. So loopi needs to be corrected
  1041. //to make it zero and upwards. It is corrected by -1 -(ptrFeedDescriptions^.iNoFeeds-1
  1042. // +ptrFeedDescriptions^.iGrazing).
  1043. //The LargePartLag is set in SingleForm and is a proportion (0-1). It says how much
  1044. //is Long particles. If LargePartLag is zero, all of the LagfNDFToEnter goes to
  1045. //fNDF and if it is 1, all goes to fNDFLong.
  1046.            begin
  1047.            if loopi<=ParlourCountHigh then
  1048.             begin
  1049.             fNDF[loopi]:=fNDF[loopi]+LagfNDFToEnter[loopi,loopm]
  1050.                          *(1-ptrFeedDescriptions^.ParlourFeed[loopi-1
  1051.                          -(ptrFeedDescriptions^.iNoFeeds-1
  1052.                             +ptrFeedDescriptions^.iGrazing)].LargePartLag);
  1053.             iNDF[loopi]:=iNDF[loopi]+LagiNDFToEnter[loopi,loopm]
  1054.                          *(1-ptrFeedDescriptions^.ParlourFeed[loopi-1
  1055.                          -(ptrFeedDescriptions^.iNoFeeds-1
  1056.                             +ptrFeedDescriptions^.iGrazing)].LargePartLag);
  1057.             fNDFLong[loopi]:=fNDFLong[loopi]+LagfNDFToEnter[loopi,loopm]
  1058.                              *ptrFeedDescriptions^.ParlourFeed[loopi-1
  1059.                              -(ptrFeedDescriptions^.iNoFeeds-1
  1060.                             +ptrFeedDescriptions^.iGrazing)].LargePartLag;
  1061.             iNDFLong[loopi]:=iNDFLong[loopi]+LagiNDFToEnter[loopi,loopm]
  1062.                              *ptrFeedDescriptions^.ParlourFeed[loopi-1
  1063.                              -(ptrFeedDescriptions^.iNoFeeds-1
  1064.                             +ptrFeedDescriptions^.iGrazing)].LargePartLag;
  1065.             end
  1066.            else if loopi<=RoboticCountHigh then
  1067.             begin
  1068.             fNDF[loopi]:=fNDF[loopi]+LagfNDFToEnter[loopi,loopm]
  1069.                          *(1-ptrFeedDescriptions^.RoboticFeed[loopi-1
  1070.                          -(ptrFeedDescriptions^.iNoFeeds-1
  1071.                             +ptrFeedDescriptions^.iGrazing
  1072.                             +ptrFeedDescriptions^.iParlour)].LargePartLag);
  1073.             iNDF[loopi]:=iNDF[loopi]+LagiNDFToEnter[loopi,loopm]
  1074.                          *(1-ptrFeedDescriptions^.RoboticFeed[loopi-1
  1075.                          -(ptrFeedDescriptions^.iNoFeeds-1
  1076.                             +ptrFeedDescriptions^.iGrazing
  1077.                             +ptrFeedDescriptions^.iParlour)].LargePartLag);
  1078.             fNDFLong[loopi]:=fNDFLong[loopi]+LagfNDFToEnter[loopi,loopm]
  1079.                              *ptrFeedDescriptions^.RoboticFeed[loopi-1
  1080.                              -(ptrFeedDescriptions^.iNoFeeds-1
  1081.                             +ptrFeedDescriptions^.iGrazing
  1082.                             +ptrFeedDescriptions^.iParlour)].LargePartLag;
  1083.             iNDFLong[loopi]:=iNDFLong[loopi]+LagiNDFToEnter[loopi,loopm]
  1084.                              *ptrFeedDescriptions^.RoboticFeed[loopi-1
  1085.                              -(ptrFeedDescriptions^.iNoFeeds-1
  1086.                             +ptrFeedDescriptions^.iGrazing
  1087.                             +ptrFeedDescriptions^.iParlour)].LargePartLag;
  1088.             end
  1089.            else
  1090.             begin
  1091.             fNDF[loopi]:=fNDF[loopi]+LagfNDFToEnter[loopi,loopm]
  1092.                          *(1-ptrFeedDescriptions^.LiquidFeed.LargePartLag);
  1093.             iNDF[loopi]:=iNDF[loopi]+LagiNDFToEnter[loopi,loopm]
  1094.                          *(1-ptrFeedDescriptions^.LiquidFeed.LargePartLag);
  1095.             fNDFLong[loopi]:=fNDFLong[loopi]+LagfNDFToEnter[loopi,loopm]
  1096.                              *ptrFeedDescriptions^.LiquidFeed.LargePartLag;
  1097.             iNDFLong[loopi]:=iNDFLong[loopi]+LagiNDFToEnter[loopi,loopm]
  1098.                              *ptrFeedDescriptions^.LiquidFeed.LargePartLag;
  1099.             end;
  1100.            end;
  1101.           LagNDFEntryTime[loopi,loopm]:=-1;
  1102.           LagfNDFToEnter[loopi,loopm]:=0;
  1103.           LagiNDFToEnter[loopi,loopm]:=0;
  1104.           end
  1105.          else
  1106.           begin
  1107.           if not (FSGrazingAll[ptrFeedDescriptions^.Diet]) and
  1108.            (loopi<ptrFeedDescriptions^.iNoFeeds) then
  1109.            begin
  1110.            if not ptrFeedDescriptions^.TMRFeed[loopi].ForOrConc then
  1111.             begin
  1112. {**}            PassLagfNDFtoSI[loopi]:=PassLagfNDFtoSI[loopi]
  1113.                                     +LagfNDFToEnter[loopi,loopm]*RConcPPass;//Days1toEnd
  1114.             PassLagiNDFtoSI[loopi]:=PassLagiNDFtoSI[loopi]
  1115.                                     +LagiNDFToEnter[loopi,loopm]*RConcPPass;//Days1toEnd
  1116.             LagfNDFToEnter[loopi,loopm]:=LagfNDFToEnter[loopi,loopm]*(1-RConcPPass);
  1117.             LagiNDFToEnter[loopi,loopm]:=LagiNDFToEnter[loopi,loopm]*(1-RConcPPass);
  1118.             end;
  1119.            end
  1120.           else if loopi>ptrFeedDescriptions^.iNoFeeds-1+ptrFeedDescriptions^.iGrazing
  1121.                          {+ptrFeedDescriptions^.iParlour} then
  1122.            begin
  1123.            if loopi<=ParlourCountHigh then
  1124.             begin
  1125.             if ptrFeedDescriptions^.iParlour>0 then
  1126.              begin
  1127.               if not ptrFeedDescriptions^.ParlourFeed[loopi-1
  1128.                              -(ptrFeedDescriptions^.iNoFeeds-1
  1129.                             +ptrFeedDescriptions^.iGrazing)].ForOrConc then
  1130.                begin
  1131.                PassLagfNDFtoSI[loopi]:=PassLagfNDFtoSI[loopi]
  1132.                                     +LagfNDFToEnter[loopi,loopm]*RConcPPass;//Days1toEnd
  1133.                PassLagiNDFtoSI[loopi]:=PassLagiNDFtoSI[loopi]
  1134.                                     +LagiNDFToEnter[loopi,loopm]*RConcPPass;//Days1toEnd
  1135.                LagfNDFToEnter[loopi,loopm]:=LagfNDFToEnter[loopi,loopm]*(1-RConcPPass);
  1136.                LagiNDFToEnter[loopi,loopm]:=LagiNDFToEnter[loopi,loopm]*(1-RConcPPass);
  1137.                end;
  1138.              end;
  1139.             end
  1140.            else if loopi<=RoboticCountHigh then
  1141.             begin
  1142.             if ptrFeedDescriptions^.iRobotic>0 then
  1143.              begin
  1144.               if not ptrFeedDescriptions^.RoboticFeed[loopi-1
  1145.                              -(ptrFeedDescriptions^.iNoFeeds-1
  1146.                             +ptrFeedDescriptions^.iGrazing
  1147.                             +ptrFeedDescriptions^.iParlour)].ForOrConc then
  1148.                begin
  1149.                PassLagfNDFtoSI[loopi]:=PassLagfNDFtoSI[loopi]
  1150.                                     +LagfNDFToEnter[loopi,loopm]*RConcPPass;//Days1toEnd
  1151.                PassLagiNDFtoSI[loopi]:=PassLagiNDFtoSI[loopi]
  1152.                                     +LagiNDFToEnter[loopi,loopm]*RConcPPass;//Days1toEnd
  1153.                LagfNDFToEnter[loopi,loopm]:=LagfNDFToEnter[loopi,loopm]*(1-RConcPPass);
  1154.                LagiNDFToEnter[loopi,loopm]:=LagiNDFToEnter[loopi,loopm]*(1-RConcPPass);
  1155.                end;
  1156.              end;
  1157.             end
  1158.            else
  1159.             begin
  1160.             if ptrFeedDescriptions^.iRobotic>0 then
  1161.              begin
  1162.               if not ptrFeedDescriptions^.LiquidFeed.ForOrConc then
  1163.                begin
  1164.                PassLagfNDFtoSI[loopi]:=PassLagfNDFtoSI[loopi]
  1165.                                     +LagfNDFToEnter[loopi,loopm]*RConcPPass;//Days1toEnd
  1166.                PassLagiNDFtoSI[loopi]:=PassLagiNDFtoSI[loopi]
  1167.                                     +LagiNDFToEnter[loopi,loopm]*RConcPPass;//Days1toEnd
  1168.                LagfNDFToEnter[loopi,loopm]:=LagfNDFToEnter[loopi,loopm]*(1-RConcPPass);
  1169.                LagiNDFToEnter[loopi,loopm]:=LagiNDFToEnter[loopi,loopm]*(1-RConcPPass);
  1170.                end;
  1171.              end;
  1172.             end;
  1173.            end;
  1174.           LagNDF[loopi]:=LagNDF[loopi]+LagfNDFToEnter[loopi,loopm]
  1175.                          +LagiNDFToEnter[loopi,loopm];
  1176.           end; //EntryTime<ElapsedTime
  1177.          end; //EntryTime>0
  1178.         if (LagSGlycerolEntryTime[loopi,loopm]>0) then
  1179.          begin
  1180.          if (LagSGlycerolEntryTime[loopi,loopm]<ElapsedTime) then
  1181.           begin
  1182.           Glycerol:=Glycerol+LagSGlycerolToEnter[loopi,loopm];
  1183.           LagSGlycerolEntryTime[loopi,loopm]:=-1;
  1184.           LagSGlycerolToEnter[loopi,loopm]:=0;
  1185.           end
  1186.          else
  1187.           begin
  1188.           PassLagSGlycerolToSI:=PassLagSGlyceroltoSI+
  1189.                                        LagSGlycerolToEnter[loopi,loopm]*RConcPPass;
  1190.           LagSGlycerolToEnter[loopi,loopm]:=LagSGlycerolToEnter[loopi,loopm]*
  1191.                                              (1-RConcPPass);
  1192.           LagSGlycerol[loopi]:=LagSGlycerol[loopi]+LagSGlycerolToEnter[loopi,loopm];
  1193.           end; //EntryTime<ElapsedTime
  1194.          end; //EntryTime>0
  1195.  
  1196.         if (LagUreaEntryTime[loopi,loopm]>0) then
  1197.          begin
  1198.          if (LagUreaEntryTime[loopi,loopm]<ElapsedTime) then
  1199.           begin
  1200.           SlowReleaseNH3:=SlowReleaseNH3+LagUreaToEnter[loopi,loopm];
  1201.           LagUreaEntryTime[loopi,loopm]:=-1;
  1202.           LagUreaToEnter[loopi,loopm]:=0;
  1203.           end
  1204.          else
  1205.           begin
  1206.           PassLagUreaToSI:=PassLagUreatoSI+
  1207.                                        LagUreaToEnter[loopi,loopm]*RConcPPass;
  1208.           LagUreaToEnter[loopi,loopm]:=LagUreaToEnter[loopi,loopm]*
  1209.                                              (1-RConcPPass);
  1210.           LagUrea[loopi]:=LagUrea[loopi]+LagUreaToEnter[loopi,loopm];
  1211.           end; //EntryTime<ElapsedTime
  1212.          end; //EntryTime>0
  1213.  
  1214.         if (LagSStarchEntryTime[loopi,loopm]>0) then
  1215.          begin
  1216.          if (LagSStarchEntryTime[loopi,loopm]<ElapsedTime) then
  1217.           begin
  1218.           if not (FSGrazingAll[ptrFeedDescriptions^.Diet]) and (loopi<ptrFeedDescriptions^.iNoFeeds) then
  1219.            begin
  1220.            SStarch[loopi]:=SStarch[loopi]+LagSStarchToEnter[loopi,loopm]
  1221.                          *(1-ptrFeedDescriptions^.TMRFeed[loopi].LargePartLag*LPMultiplier[loopi]);
  1222.            USStarch[loopi]:=USStarch[loopi]+LagUSStarchToEnter[loopi,loopm]
  1223.                          *(1-ptrFeedDescriptions^.TMRFeed[loopi].LargePartLag*LPMultiplier[loopi]);
  1224.            SStarchLong[loopi]:=SStarchLong[loopi]+LagSStarchToEnter[loopi,loopm]
  1225.                              *ptrFeedDescriptions^.TMRFeed[loopi].LargePartLag*LPMultiplier[loopi];
  1226.            USStarchLong[loopi]:=USStarchLong[loopi]+LagUSStarchToEnter[loopi,loopm]
  1227.                              *ptrFeedDescriptions^.TMRFeed[loopi].LargePartLag*LPMultiplier[loopi];
  1228.            end
  1229.           else if loopi=ptrFeedDescriptions^.iNoFeeds-1+ptrFeedDescriptions^.iGrazing then
  1230.            begin
  1231.            SStarch[loopi]:=SStarch[loopi]+LagSStarchToEnter[loopi,loopm]
  1232.                          *(1-ptrFeedDescriptions^.GrazingFeed.LargePartLag);
  1233.            USStarch[loopi]:=USStarch[loopi]+LagUSStarchToEnter[loopi,loopm]
  1234.                          *(1-ptrFeedDescriptions^.GrazingFeed.LargePartLag);
  1235.            SStarchLong[loopi]:=SStarchLong[loopi]+LagSStarchToEnter[loopi,loopm]
  1236.                              *ptrFeedDescriptions^.GrazingFeed.LargePartLag;
  1237.            USStarchLong[loopi]:=USStarchLong[loopi]+LagUSStarchToEnter[loopi,loopm]
  1238.                              *ptrFeedDescriptions^.GrazingFeed.LargePartLag;
  1239.            end
  1240.           else if loopi>ptrFeedDescriptions^.iNoFeeds-1
  1241.                             +ptrFeedDescriptions^.iGrazing then
  1242.            begin
  1243.            if loopi<=ParlourCountHigh then
  1244.             begin
  1245.             SStarch[loopi]:=SStarch[loopi]+LagSStarchToEnter[loopi,loopm]
  1246.                          *(1-ptrFeedDescriptions^.ParlourFeed[loopi-1
  1247.                          -(ptrFeedDescriptions^.iNoFeeds-1
  1248.                             +ptrFeedDescriptions^.iGrazing)].LargePartLag);
  1249.             USStarch[loopi]:=USStarch[loopi]+LagUSStarchToEnter[loopi,loopm]
  1250.                          *(1-ptrFeedDescriptions^.ParlourFeed[loopi-1
  1251.                          -(ptrFeedDescriptions^.iNoFeeds-1
  1252.                             +ptrFeedDescriptions^.iGrazing)].LargePartLag);
  1253.             SStarchLong[loopi]:=SStarchLong[loopi]+LagSStarchToEnter[loopi,loopm]
  1254.                              *ptrFeedDescriptions^.ParlourFeed[loopi-1
  1255.                              -(ptrFeedDescriptions^.iNoFeeds-1
  1256.                             +ptrFeedDescriptions^.iGrazing)].LargePartLag;
  1257.             USStarchLong[loopi]:=USStarchLong[loopi]+LagUSStarchToEnter[loopi,loopm]
  1258.                              *ptrFeedDescriptions^.ParlourFeed[loopi-1
  1259.                              -(ptrFeedDescriptions^.iNoFeeds-1
  1260.                             +ptrFeedDescriptions^.iGrazing)].LargePartLag;
  1261.             end
  1262.            else if loopi<=RoboticCountHigh then
  1263.             begin
  1264.             SStarch[loopi]:=SStarch[loopi]+LagSStarchToEnter[loopi,loopm]
  1265.                          *(1-ptrFeedDescriptions^.RoboticFeed[loopi-1
  1266.                          -(ptrFeedDescriptions^.iNoFeeds-1
  1267.                             +ptrFeedDescriptions^.iGrazing
  1268.                             +ptrFeedDescriptions^.iParlour)].LargePartLag);
  1269.             USStarch[loopi]:=USStarch[loopi]+LagUSStarchToEnter[loopi,loopm]
  1270.                          *(1-ptrFeedDescriptions^.RoboticFeed[loopi-1
  1271.                          -(ptrFeedDescriptions^.iNoFeeds-1
  1272.                             +ptrFeedDescriptions^.iGrazing
  1273.                             +ptrFeedDescriptions^.iParlour)].LargePartLag);
  1274.             SStarchLong[loopi]:=SStarchLong[loopi]+LagSStarchToEnter[loopi,loopm]
  1275.                              *ptrFeedDescriptions^.RoboticFeed[loopi-1
  1276.                              -(ptrFeedDescriptions^.iNoFeeds-1
  1277.                             +ptrFeedDescriptions^.iGrazing
  1278.                             +ptrFeedDescriptions^.iParlour)].LargePartLag;
  1279.             USStarchLong[loopi]:=USStarchLong[loopi]+LagUSStarchToEnter[loopi,loopm]
  1280.                              *ptrFeedDescriptions^.RoboticFeed[loopi-1
  1281.                              -(ptrFeedDescriptions^.iNoFeeds-1
  1282.                             +ptrFeedDescriptions^.iGrazing
  1283.                             +ptrFeedDescriptions^.iParlour)].LargePartLag;
  1284.             end
  1285.            else
  1286.             begin
  1287.             SStarch[loopi]:=SStarch[loopi]+LagSStarchToEnter[loopi,loopm]
  1288.                          *(1-ptrFeedDescriptions^.LiquidFeed.LargePartLag);
  1289.             USStarch[loopi]:=USStarch[loopi]+LagUSStarchToEnter[loopi,loopm]
  1290.                          *(1-ptrFeedDescriptions^.LiquidFeed.LargePartLag);
  1291.             SStarchLong[loopi]:=SStarchLong[loopi]+LagSStarchToEnter[loopi,loopm]
  1292.                              *ptrFeedDescriptions^.LiquidFeed.LargePartLag;
  1293.             USStarchLong[loopi]:=USStarchLong[loopi]+LagUSStarchToEnter[loopi,loopm]
  1294.                              *ptrFeedDescriptions^.LiquidFeed.LargePartLag;
  1295.             end;
  1296.            end;
  1297.           LagSStarchEntryTime[loopi,loopm]:=-1;
  1298.           LagSStarchToEnter[loopi,loopm]:=0;
  1299.           LagUSStarchToEnter[loopi,loopm]:=0;
  1300.           end
  1301.          else
  1302.           begin
  1303.           if not (FSGrazingAll[ptrFeedDescriptions^.Diet]) and (loopi<ptrFeedDescriptions^.iNoFeeds) then
  1304.            begin
  1305.            if not ptrFeedDescriptions^.TMRFeed[loopi].ForOrConc then
  1306.             begin
  1307. {**}            PassLagSStarchtoSI[loopi]:=PassLagSStarchtoSI[loopi]
  1308.                                     +LagSStarchToEnter[loopi,loopm]*RConcPPass;//Days1toEnd
  1309.             PassLagUSStarchtoSI[loopi]:=PassLagUSStarchtoSI[loopi]
  1310.                                     +LagUSStarchToEnter[loopi,loopm]*RConcPPass;//Days1toEnd
  1311.             LagSStarchToEnter[loopi,loopm]:=LagSStarchToEnter[loopi,loopm]*(1-RConcPPass);
  1312.             LagUSStarchToEnter[loopi,loopm]:=LagUSStarchToEnter[loopi,loopm]*(1-RConcPPass);
  1313.             end;
  1314.            end
  1315.           else if loopi>ptrFeedDescriptions^.iNoFeeds-1+ptrFeedDescriptions^.iGrazing
  1316.                          {+ptrFeedDescriptions^.iParlour} then
  1317.            begin
  1318.            if loopi<=ParlourCountHigh then
  1319.             begin
  1320.             if ptrFeedDescriptions^.iParlour>0 then
  1321.              begin
  1322.               if not ptrFeedDescriptions^.ParlourFeed[loopi-1
  1323.                              -(ptrFeedDescriptions^.iNoFeeds-1
  1324.                             +ptrFeedDescriptions^.iGrazing)].ForOrConc then
  1325.                begin
  1326.                PassLagSStarchtoSI[loopi]:=PassLagSStarchtoSI[loopi]
  1327.                                     +LagSStarchToEnter[loopi,loopm]*RConcPPass;//Days1toEnd
  1328.                PassLagUSStarchtoSI[loopi]:=PassLagUSStarchtoSI[loopi]
  1329.                                     +LagUSStarchToEnter[loopi,loopm]*RConcPPass;//Days1toEnd
  1330.                LagSStarchToEnter[loopi,loopm]:=LagSStarchToEnter[loopi,loopm]*(1-RConcPPass);
  1331.                LagUSStarchToEnter[loopi,loopm]:=LagUSStarchToEnter[loopi,loopm]*(1-RConcPPass);
  1332.                end;
  1333.              end
  1334.            else if loopi<=RoboticCountHigh then
  1335.              begin
  1336.              if ptrFeedDescriptions^.iRobotic>0 then
  1337.               begin
  1338.               if not ptrFeedDescriptions^.RoboticFeed[loopi-1
  1339.                              -(ptrFeedDescriptions^.iNoFeeds-1
  1340.                             +ptrFeedDescriptions^.iGrazing
  1341.                             +ptrFeedDescriptions^.iParlour)].ForOrConc then
  1342.                begin
  1343.                PassLagSStarchtoSI[loopi]:=PassLagSStarchtoSI[loopi]
  1344.                                     +LagSStarchToEnter[loopi,loopm]*RConcPPass;//Days1toEnd
  1345.                PassLagUSStarchtoSI[loopi]:=PassLagUSStarchtoSI[loopi]
  1346.                                     +LagUSStarchToEnter[loopi,loopm]*RConcPPass;//Days1toEnd
  1347.                LagSStarchToEnter[loopi,loopm]:=LagSStarchToEnter[loopi,loopm]*(1-RConcPPass);
  1348.                LagUSStarchToEnter[loopi,loopm]:=LagUSStarchToEnter[loopi,loopm]*(1-RConcPPass);
  1349.                end;
  1350.               end;
  1351.              end
  1352.             else
  1353.              begin
  1354.              if ptrFeedDescriptions^.iRobotic>0 then
  1355.               begin
  1356.               if not ptrFeedDescriptions^.LiquidFeed.ForOrConc then
  1357.                begin
  1358.                PassLagSStarchtoSI[loopi]:=PassLagSStarchtoSI[loopi]
  1359.                                     +LagSStarchToEnter[loopi,loopm]*RConcPPass;//Days1toEnd
  1360.                PassLagUSStarchtoSI[loopi]:=PassLagUSStarchtoSI[loopi]
  1361.                                     +LagUSStarchToEnter[loopi,loopm]*RConcPPass;//Days1toEnd
  1362.                LagSStarchToEnter[loopi,loopm]:=LagSStarchToEnter[loopi,loopm]*(1-RConcPPass);
  1363.                LagUSStarchToEnter[loopi,loopm]:=LagUSStarchToEnter[loopi,loopm]*(1-RConcPPass);
  1364.                end;
  1365.               end;
  1366.              end;
  1367.             end;
  1368.            end;
  1369.           LagSStarch[loopi]:=LagSStarch[loopi]+LagSStarchToEnter[loopi,loopm]
  1370.                          +LagUSStarchToEnter[loopi,loopm];
  1371.           end; //EntryTime<ElapsedTime
  1372.          end; //EntryTime>0
  1373.  
  1374.         if (LagCPEntryTime[loopi,loopm]>0) then
  1375.          begin
  1376.          if (LagCPEntryTime[loopi,loopm]<ElapsedTime) then
  1377.           begin
  1378.           if not (FSGrazingAll[ptrFeedDescriptions^.Diet]) and (loopi<ptrFeedDescriptions^.iNoFeeds) then
  1379.            begin
  1380.            DegCP[loopi]:=DegCP[loopi]+LagDegCPToEnter[loopi,loopm]
  1381.                          *(1-ptrFeedDescriptions^.TMRFeed[loopi].LargePartLag*LPMultiplier[loopi]);
  1382.            iDegCP[loopi]:=iDegCP[loopi]+LagiDegCPToEnter[loopi,loopm]
  1383.                           *(1-ptrFeedDescriptions^.TMRFeed[loopi].LargePartLag*LPMultiplier[loopi]);
  1384.            DegCPLong[loopi]:=DegCPLong[loopi]+LagDegCPToEnter[loopi,loopm]
  1385.                              *ptrFeedDescriptions^.TMRFeed[loopi].LargePartLag*LPMultiplier[loopi];
  1386.            iDegCPLong[loopi]:=iDegCPLong[loopi]+LagiDegCPToEnter[loopi,loopm]
  1387.                               *ptrFeedDescriptions^.TMRFeed[loopi].LargePartLag*LPMultiplier[loopi];
  1388.            end
  1389.           else if loopi=ptrFeedDescriptions^.iNoFeeds-1+ptrFeedDescriptions^.iGrazing then
  1390.            begin
  1391.            DegCP[loopi]:=DegCP[loopi]+LagDegCPToEnter[loopi,loopm]
  1392.                          *(1-ptrFeedDescriptions^.GrazingFeed.LargePartLag);
  1393.            iDegCP[loopi]:=iDegCP[loopi]+LagiDegCPToEnter[loopi,loopm]
  1394.                          *(1-ptrFeedDescriptions^.GrazingFeed.LargePartLag);
  1395.            DegCPLong[loopi]:=DegCPLong[loopi]+LagDegCPToEnter[loopi,loopm]
  1396.                              *ptrFeedDescriptions^.GrazingFeed.LargePartLag;
  1397.            iDegCPLong[loopi]:=iDegCPLong[loopi]+LagiDegCPToEnter[loopi,loopm]
  1398.                              *ptrFeedDescriptions^.GrazingFeed.LargePartLag;
  1399.            end
  1400.           else if loopi>ptrFeedDescriptions^.iNoFeeds-1+ptrFeedDescriptions^.iGrazing
  1401.                          {+ptrFeedDescriptions^.iParlour} then
  1402.            begin
  1403.            if loopi<=ParlourCountHigh then
  1404.             begin
  1405.             DegCP[loopi]:=DegCP[loopi]+LagDegCPToEnter[loopi,loopm]
  1406.                          *(1-ptrFeedDescriptions^.ParlourFeed[loopi-1
  1407.                          -(ptrFeedDescriptions^.iNoFeeds-1
  1408.                             +ptrFeedDescriptions^.iGrazing)].LargePartLag);
  1409.             iDegCP[loopi]:=iDegCP[loopi]+LagiDegCPToEnter[loopi,loopm]
  1410.                          *(1-ptrFeedDescriptions^.ParlourFeed[loopi-1
  1411.                          -(ptrFeedDescriptions^.iNoFeeds-1
  1412.                             +ptrFeedDescriptions^.iGrazing)].LargePartLag);
  1413.             DegCPLong[loopi]:=DegCPLong[loopi]+LagDegCPToEnter[loopi,loopm]
  1414.                              *ptrFeedDescriptions^.ParlourFeed[loopi-1
  1415.                              -(ptrFeedDescriptions^.iNoFeeds-1
  1416.                             +ptrFeedDescriptions^.iGrazing)].LargePartLag;
  1417.             iDegCPLong[loopi]:=iDegCPLong[loopi]+LagiDegCPToEnter[loopi,loopm]
  1418.                              *ptrFeedDescriptions^.ParlourFeed[loopi-1
  1419.                              -(ptrFeedDescriptions^.iNoFeeds-1
  1420.                              +ptrFeedDescriptions^.iGrazing)].LargePartLag;
  1421.             end
  1422.            else if loopi<=RoboticCountHigh then
  1423.             begin
  1424.             DegCP[loopi]:=DegCP[loopi]+LagDegCPToEnter[loopi,loopm]
  1425.                          *(1-ptrFeedDescriptions^.RoboticFeed[loopi-1
  1426.                          -(ptrFeedDescriptions^.iNoFeeds-1
  1427.                             +ptrFeedDescriptions^.iGrazing
  1428.                             +ptrFeedDescriptions^.iParlour)].LargePartLag);
  1429.             iDegCP[loopi]:=iDegCP[loopi]+LagiDegCPToEnter[loopi,loopm]
  1430.                          *(1-ptrFeedDescriptions^.RoboticFeed[loopi-1
  1431.                          -(ptrFeedDescriptions^.iNoFeeds-1
  1432.                             +ptrFeedDescriptions^.iGrazing
  1433.                             +ptrFeedDescriptions^.iParlour)].LargePartLag);
  1434.             DegCPLong[loopi]:=DegCPLong[loopi]+LagDegCPToEnter[loopi,loopm]
  1435.                              *ptrFeedDescriptions^.RoboticFeed[loopi-1
  1436.                              -(ptrFeedDescriptions^.iNoFeeds-1
  1437.                             +ptrFeedDescriptions^.iGrazing
  1438.                             +ptrFeedDescriptions^.iParlour)].LargePartLag;
  1439.             iDegCPLong[loopi]:=iDegCPLong[loopi]+LagiDegCPToEnter[loopi,loopm]
  1440.                              *ptrFeedDescriptions^.RoboticFeed[loopi-1
  1441.                              -(ptrFeedDescriptions^.iNoFeeds-1
  1442.                             +ptrFeedDescriptions^.iGrazing
  1443.                             +ptrFeedDescriptions^.iParlour)].LargePartLag;
  1444.             end
  1445.            else
  1446.             begin
  1447.             DegCP[loopi]:=DegCP[loopi]+LagDegCPToEnter[loopi,loopm]
  1448.                          *(1-ptrFeedDescriptions^.LiquidFeed.LargePartLag);
  1449.             iDegCP[loopi]:=iDegCP[loopi]+LagiDegCPToEnter[loopi,loopm]
  1450.                          *(1-ptrFeedDescriptions^.LiquidFeed.LargePartLag);
  1451.             DegCPLong[loopi]:=DegCPLong[loopi]+LagDegCPToEnter[loopi,loopm]
  1452.                              *ptrFeedDescriptions^.LiquidFeed.LargePartLag;
  1453.             iDegCPLong[loopi]:=iDegCPLong[loopi]+LagiDegCPToEnter[loopi,loopm]
  1454.                              *ptrFeedDescriptions^.LiquidFeed.LargePartLag;
  1455.             end;
  1456.            end;
  1457.           LagCPEntryTime[loopi,loopm]:=-1;
  1458.           LagDegCPToEnter[loopi,loopm]:=0;
  1459.           LagiDegCPToEnter[loopi,loopm]:=0;
  1460.           end
  1461.          else //if CPEntryTime<Elapsedtime
  1462.           begin
  1463.           if not (FSGrazingAll[ptrFeedDescriptions^.Diet]) and (loopi<ptrFeedDescriptions^.iNoFeeds) then
  1464.            begin
  1465.            if not ptrFeedDescriptions^.TMRFeed[loopi].ForOrConc then
  1466.             begin
  1467.             PassLagDegCPtoSI[loopi]:=PassLagDegCPtoSI[loopi]
  1468.                                     +LagDegCPToEnter[loopi,loopm]*RConcPPass;
  1469.             PassLagiDegCPtoSI[loopi]:=PassLagiDegCPtoSI[loopi]
  1470.                                     +LagiDegCPToEnter[loopi,loopm]*RConcPPass;
  1471.             LagDegCPToEnter[loopi,loopm]:=LagDegCPToEnter[loopi,loopm]*(1-RConcPPass);
  1472.             LagiDegCPToEnter[loopi,loopm]:=LagiDegCPToEnter[loopi,loopm]*(1-RConcPPass);
  1473.             end;
  1474.            end
  1475.           else if loopi>ptrFeedDescriptions^.iNoFeeds-1+ptrFeedDescriptions^.iGrazing
  1476.                          {+ptrFeedDescriptions^.iParlour} then
  1477.            begin
  1478.            if loopi<=ParlourCountHigh then
  1479.             begin
  1480.             if ptrFeedDescriptions^.iParlour>0 then
  1481.              begin
  1482.              if not ptrFeedDescriptions^.ParlourFeed[loopi-1
  1483.                              -(ptrFeedDescriptions^.iNoFeeds-1
  1484.                             +ptrFeedDescriptions^.iGrazing)].ForOrConc then
  1485.               begin
  1486.               PassLagDegCPtoSI[loopi]:=PassLagDegCPtoSI[loopi]
  1487.                                     +LagDegCPToEnter[loopi,loopm]*RConcPPass;//Days1toEnd
  1488.               PassLagiDegCPtoSI[loopi]:=PassLagiDegCPtoSI[loopi]
  1489.                                     +LagiDegCPToEnter[loopi,loopm]*RConcPPass;//Days1toEnd
  1490.               LagDegCPToEnter[loopi,loopm]:=LagDegCPToEnter[loopi,loopm]*(1-RConcPPass);
  1491.               LagiDegCPToEnter[loopi,loopm]:=LagiDegCPToEnter[loopi,loopm]*(1-RConcPPass);
  1492.               end;
  1493.              end
  1494.            else if loopi<=RoboticCountHigh then
  1495.              begin
  1496.              if ptrFeedDescriptions^.iRobotic>0 then
  1497.               begin
  1498.               if not ptrFeedDescriptions^.RoboticFeed[loopi-1
  1499.                              -(ptrFeedDescriptions^.iNoFeeds-1
  1500.                             +ptrFeedDescriptions^.iGrazing
  1501.                             +ptrFeedDescriptions^.iParlour)].ForOrConc then
  1502.                begin
  1503.                PassLagDegCPtoSI[loopi]:=PassLagDegCPtoSI[loopi]
  1504.                                     +LagDegCPToEnter[loopi,loopm]*RConcPPass;//Days1toEnd
  1505.                PassLagiDegCPtoSI[loopi]:=PassLagiDegCPtoSI[loopi]
  1506.                                     +LagiDegCPToEnter[loopi,loopm]*RConcPPass;//Days1toEnd
  1507.                LagDegCPToEnter[loopi,loopm]:=LagDegCPToEnter[loopi,loopm]*(1-RConcPPass);
  1508.                LagiDegCPToEnter[loopi,loopm]:=LagiDegCPToEnter[loopi,loopm]*(1-RConcPPass);
  1509.                end;
  1510.               end;
  1511.              end
  1512.             else
  1513.              begin
  1514.              if ptrFeedDescriptions^.iRobotic>0 then
  1515.               begin
  1516.               if not ptrFeedDescriptions^.LiquidFeed.ForOrConc then
  1517.                begin
  1518.                PassLagDegCPtoSI[loopi]:=PassLagDegCPtoSI[loopi]
  1519.                                     +LagDegCPToEnter[loopi,loopm]*RConcPPass;//Days1toEnd
  1520.                PassLagiDegCPtoSI[loopi]:=PassLagiDegCPtoSI[loopi]
  1521.                                     +LagiDegCPToEnter[loopi,loopm]*RConcPPass;//Days1toEnd
  1522.                LagDegCPToEnter[loopi,loopm]:=LagDegCPToEnter[loopi,loopm]*(1-RConcPPass);
  1523.                LagiDegCPToEnter[loopi,loopm]:=LagiDegCPToEnter[loopi,loopm]*(1-RConcPPass);
  1524.                end;
  1525.               end;
  1526.              end;
  1527.             end;
  1528.            end;
  1529.           LagCP[loopi]:=LagCP[loopi]+LagDegCPToEnter[loopi,loopm]
  1530.                         +LagiDegCPToEnter[loopi,loopm];
  1531.           end;
  1532.          end;
  1533.         end;
  1534.        end;
  1535.      except
  1536.       on Exception do MessageBeep(0);
  1537.      end;
  1538.      RumDM:=0;TotalRumDM:=0;
  1539.       for loopi:=0 to NumFoods-1 do
  1540.        begin
  1541.        RumDM:=RumDM+fNDF[loopi]+iNDF[loopi]+fNDFLong[loopi]+iNDFLong[loopi]
  1542.              +LagNDF[loopi]+LagCP[loopi]+DegCP[loopi]+iDegCP[loopi]
  1543.              +DegCPLong[loopi]+iDegCPLong[loopi]{+QStarch[loopi]+UQStarch[loopi]}{+SolCP[loopi]}
  1544.              {+SStarch[loopi]+USStarch[loopi]+LagSStarch[loopi]
  1545.              +SStarchLong[loopi]+USStarchLong[loopi]};
  1546.        TotalRumDM:=TotalRumDM+fNDF[loopi]+iNDF[loopi]+fNDFLong[loopi]+iNDFLong[loopi]
  1547.              +LagNDF[loopi]+LagCP[loopi]+DegCP[loopi]+iDegCP[loopi]
  1548.              +DegCPLong[loopi]+iDegCPLong[loopi]+QStarch[loopi]+UQStarch[loopi]+SolCP[loopi]
  1549.              +SStarch[loopi]+USStarch[loopi]+LagSStarch[loopi]
  1550.              +SStarchLong[loopi]+USStarchLong[loopi]+PectinPS[loopi];
  1551.        end;
  1552.      TotalRumDM:=TotalRumDM+SolCHO;
  1553. //if (Days1toEnd=20){ and (Hours1to24>7)} and (StepHours1toEnd=1) then
  1554. //      QMP:=QMP;
  1555.      FermQStarchRum:=0; FermSStarchRum:=0;
  1556.      FermNDFRum:=0;
  1557.      FermDegCPRum:=0;
  1558.      FermNDFHG:=0; FermPectinHG:=0;
  1559.      FermSolCPRum:=0; FermPectinRum:=0;
  1560.      SumPassDigCPtoSI:=0;
  1561.      BoundWater:=0;
  1562.      PassSIWater:=0;
  1563.      //Calculate Flows
  1564.      //Passage
  1565.      PassSolCHOtoSI:=SolCHO*(PassageFree+PassageBound);//RLPass
  1566.      PassLactictoSI:=Lactate*(PassageFree+PassageBound);//RLPass
  1567.      PassSolsNDFtoSI:=SolsNDF*(PassageFree+PassageBound);//RLPass
  1568.      SumPassSolCPtoSI:=0;
  1569.      PassMPGtoSI:=MonoPG_Glycerol*(PassageFree+PassageBound);
  1570.      PassGlyceroltoSI:=Glycerol*(PassageFree+PassageBound)+PassLagSGlyceroltoSI;
  1571.      PassUnfermentedGlyceroltoSI:=UnfermentedGlycerolSmall*(PassageFree+PassageBound);
  1572.      for loopi:=0 to NumFoods-1 do
  1573.       begin
  1574.       PassSolCPtoSI[loopi]:=SolCP[loopi]*(PassageFree+PassageBound);//RLPass
  1575.       SumPassSolCPtoSI:=SumPassSolCPtoSI+PassSolCPtoSI[loopi];
  1576.       end;
  1577.      PassAshtoSI:=Ash*(PassageFree+PassageBound);//RLPass
  1578.      PassOiltoSI:=Oil*(PassageFree+PassageBound);//RLPass
  1579.      PassNH3toSI:=NH3Rum*(PassageFree+PassageBound)+PassLagUreatoSI;//RLPass
  1580.      if Beef then
  1581.       begin
  1582.       PassQMicLiquidR:=QMicLiquidR*MicPassRate*0.075; //Liquid to Solid transfer rate
  1583.       PassQMicSolidsR:=QMicSolidsR*MicPassRate*0.05; //Solid to Liquid transfer rate
  1584.       end
  1585.      else
  1586.       begin
  1587.       PassQMicLiquidR:=QMicLiquidR*MicPassRate*0.5; //Liquid to Solid transfer rate
  1588.       PassQMicSolidsR:=QMicSolidsR*MicPassRate*0.4; //Solid to Liquid transfer rate
  1589.       end;
  1590.      //Check whether forage or concentrate and use appropriate passage rate
  1591.      //FororConc true if forage
  1592.      for loopi:=0 to ptrFeedDescriptions^.iNoFeeds-1 do
  1593.       begin
  1594.       if not ptrFeedDescriptions^.TMRFeed[loopi].FororConc then
  1595.        begin
  1596.        PassfNDFLongtoSI[loopi]:=fNDFLong[loopi]*RConcPPass*LPMult;
  1597.        PassiNDFLongtoSI[loopi]:=iNDFLong[loopi]*RConcPPass*LPMult*PassageRateFactor;
  1598.        PassSStarchLongtoSI[loopi]:=SStarchLong[loopi]*RConcPPass*LPMult;
  1599.        PassUSStarchLongtoSI[loopi]:=USStarchLong[loopi]*(RConcPPass*USPass)*LPMult;
  1600.        PassDegCPLongtoSI[loopi]:=DegCPLong[loopi]*RConcPPass*LPMult;
  1601.        PassiDegCPLongtoSI[loopi]:=iDegCPLong[loopi]*RConcPPass*LPMult;
  1602.        PassfNDFtoSI[loopi]:=fNDF[loopi]*RConcPPass;
  1603.        PassiNDFtoSI[loopi]:=iNDF[loopi]*RConcPPass*PassageRateFactor;
  1604.        PassSStarchtoSI[loopi]:=SStarch[loopi]*RConcPPass;
  1605.        PassUSStarchtoSI[loopi]:=USStarch[loopi]*(RConcPPass*USPass);
  1606.        PassDegCPtoSI[loopi]:=DegCP[loopi]*RConcPPass;
  1607.        PassiDegCPtoSI[loopi]:=iDegCP[loopi]*RConcPPass;
  1608.        end
  1609.       else
  1610.        begin
  1611.        PassfNDFLongtoSI[loopi]:=fNDFLong[loopi]*RPPass*LPMult;
  1612.        PassiNDFLongtoSI[loopi]:=iNDFLong[loopi]*RPPass*LPMult*PassageRateFactor;
  1613.        PassSStarchLongtoSI[loopi]:=SStarchLong[loopi]*RConcPPass*LPMult;
  1614.        PassUSStarchLongtoSI[loopi]:=USStarchLong[loopi]*(RConcPPass)*LPMult*USPass;
  1615.        PassDegCPLongtoSI[loopi]:=DegCPLong[loopi]*RPPass*LPMult;
  1616.        PassiDegCPLongtoSI[loopi]:=iDegCPLong[loopi]*RPPass*LPMult;
  1617.        PassfNDFtoSI[loopi]:=fNDF[loopi]*RPPass;
  1618.        PassiNDFtoSI[loopi]:=iNDF[loopi]*RPPass*PassageRateFactor;
  1619.        PassSStarchtoSI[loopi]:=SStarch[loopi]*RConcPPass;
  1620.        PassUSStarchtoSI[loopi]:=USStarch[loopi]*(RConcPPass*USPass);
  1621.        PassDegCPtoSI[loopi]:=DegCP[loopi]*RPPass;
  1622.        PassiDegCPtoSI[loopi]:=iDegCP[loopi]*RPPass;
  1623.        end;
  1624.       PassPectintoSI[loopi]:=PectinPS[loopi]*(PassageFree+PassageBound);
  1625.       PassQStarchtoSI[loopi]:=QStarch[loopi]*(PassageFree+PassageBound);//RLPass
  1626.       PassUQStarchtoSI[loopi]:=UQStarch[loopi]*(PassageFree+PassageBound);//RLPass
  1627.       SumPassDigCPtoSI:=SumPassDigCPtoSI+PassDegCPtoSI[loopi]+PassiDegCPtoSI[loopi]
  1628.                          +PassDegCPLongtoSI[loopi]+PassiDegCPLongtoSI[loopi]
  1629.       end;
  1630.       if ptrFeedDescriptions^.iGrazing>0 then
  1631.        begin
  1632.        count:=ptrFeedDescriptions^.iNoFeeds;
  1633.        if not ptrFeedDescriptions^.GrazingFeed.FororConc then
  1634.         begin
  1635.         PassfNDFLongtoSI[count]:=fNDFLong[count]*RConcPPass*LPMult;
  1636.         PassiNDFLongtoSI[count]:=iNDFLong[count]*RConcPPass*LPMult;
  1637.         PassSStarchLongtoSI[count]:=SStarchLong[count]*RConcPPass*LPMult;
  1638.         PassUSStarchLongtoSI[count]:=USStarchLong[count]*(RConcPPass*USPass)*LPMult;
  1639.         PassDegCPLongtoSI[count]:=DegCPLong[count]*RConcPPass*LPMult;
  1640.         PassiDegCPLongtoSI[count]:=iDegCPLong[count]*RConcPPass*LPMult;
  1641.         PassfNDFtoSI[count]:=fNDF[count]*RConcPPass;
  1642.         PassiNDFtoSI[count]:=iNDF[count]*RConcPPass;
  1643.         PassSStarchtoSI[count]:=SStarch[count]*RConcPPass;
  1644.         PassUSStarchtoSI[count]:=USStarch[count]*(RConcPPass*USPass);
  1645.         PassDegCPtoSI[count]:=DegCP[count]*RConcPPass;
  1646.         PassiDegCPtoSI[count]:=iDegCP[count]*RConcPPass;
  1647.         end
  1648.        else
  1649.         begin
  1650.         PassfNDFLongtoSI[count]:=fNDFLong[count]*RPPass*LPMult;
  1651.         PassiNDFLongtoSI[count]:=iNDFLong[count]*RPPass*LPMult;
  1652.         PassSStarchLongtoSI[count]:=SStarchLong[count]*RConcPPass*LPMult;
  1653.         PassUSStarchLongtoSI[count]:=USStarchLong[count]*(RConcPPass*USPass)*LPMult;
  1654.         PassDegCPLongtoSI[count]:=DegCPLong[count]*RPPass*LPMult;
  1655.         PassiDegCPLongtoSI[count]:=iDegCPLong[count]*RPPass*LPMult;
  1656.         PassfNDFtoSI[count]:=fNDF[count]*RPPass;
  1657.         PassiNDFtoSI[count]:=iNDF[count]*RPPass;
  1658.         PassSStarchtoSI[count]:=SStarch[count]*RConcPPass;
  1659.         PassUSStarchtoSI[count]:=USStarch[count]*(RConcPPass*USPass);
  1660.         PassDegCPtoSI[count]:=DegCP[count]*RPPass;
  1661.         PassiDegCPtoSI[count]:=iDegCP[count]*RPPass;
  1662.         end;
  1663.        PassPectintoSI[count]:=PectinPS[count]*(PassageFree+PassageBound);
  1664.        PassQStarchtoSI[count]:=QStarch[count]*(PassageFree+PassageBound);//RLPass
  1665.        PassUQStarchtoSI[count]:=UQStarch[count]*(PassageFree+PassageBound);//RLPass
  1666.        SumPassDigCPtoSI:=SumPassDigCPtoSI+PassDegCPtoSI[count]+PassiDegCPtoSI[count]
  1667.                          +PassDegCPLongtoSI[count]+PassiDegCPLongtoSI[count]
  1668.        end;
  1669.       if ptrFeedDescriptions^.iParlour>0 then
  1670.        begin
  1671.        n1:=0;
  1672.        for count:=NumFoods-counter+1 to NumFoods-1 do
  1673.         begin
  1674.         if not ptrFeedDescriptions^.ParlourFeed[n1].FororConc then
  1675.          begin
  1676.          PassfNDFLongtoSI[count]:=fNDFLong[count]*RConcPPass*LPMult;
  1677.          PassiNDFLongtoSI[count]:=iNDFLong[count]*RConcPPass*LPMult;
  1678.          PassSStarchLongtoSI[count]:=SStarchLong[count]*RConcPPass*LPMult;
  1679.          PassUSStarchLongtoSI[count]:=USStarchLong[count]*(RConcPPass*USPass)*LPMult;
  1680.          PassDegCPLongtoSI[count]:=DegCPLong[count]*RConcPPass*LPMult;
  1681.          PassiDegCPLongtoSI[count]:=iDegCPLong[count]*RConcPPass*LPMult;
  1682.          PassfNDFtoSI[count]:=fNDF[count]*RConcPPass;
  1683.          PassiNDFtoSI[count]:=iNDF[count]*RConcPPass;
  1684.          PassSStarchtoSI[count]:=SStarch[count]*RConcPPass;
  1685.          PassUSStarchtoSI[count]:=USStarch[count]*(RConcPPass*USPass);
  1686.          PassDegCPtoSI[count]:=DegCP[count]*RConcPPass;
  1687.          PassiDegCPtoSI[count]:=iDegCP[count]*RConcPPass;
  1688.          end
  1689.         else
  1690.          begin
  1691.          PassfNDFLongtoSI[count]:=fNDFLong[count]*RPPass*LPMult;
  1692.          PassiNDFLongtoSI[count]:=iNDFLong[count]*RPPass*LPMult;
  1693.          PassSStarchLongtoSI[count]:=SStarchLong[count]*RConcPPass*LPMult;
  1694.          PassUSStarchLongtoSI[count]:=USStarchLong[count]*(RConcPPass*USPass)*LPMult;
  1695.          PassDegCPLongtoSI[count]:=DegCPLong[count]*RPPass*LPMult;
  1696.          PassiDegCPLongtoSI[count]:=iDegCPLong[count]*RPPass*LPMult;
  1697.          PassfNDFtoSI[count]:=fNDF[count]*RPPass;
  1698.          PassiNDFtoSI[count]:=iNDF[count]*RPPass;
  1699.          PassSStarchtoSI[count]:=SStarch[count]*RConcPPass;
  1700.          PassUSStarchtoSI[count]:=USStarch[count]*(RConcPPass*USPass);
  1701.          PassDegCPtoSI[count]:=DegCP[count]*RPPass;
  1702.          PassiDegCPtoSI[count]:=iDegCP[count]*RPPass;
  1703.          end;
  1704.         PassPectintoSI[count]:=PectinPS[count]*(PassageFree+PassageBound);
  1705.         PassQStarchtoSI[count]:=QStarch[count]*(PassageFree+PassageBound);//RLPass
  1706.         PassUQStarchtoSI[count]:=UQStarch[count]*(PassageFree+PassageBound);//RLPass
  1707.         SumPassDigCPtoSI:=SumPassDigCPtoSI+PassDegCPtoSI[count]
  1708.          +PassiDegCPtoSI[count]+PassDegCPLongtoSI[count]
  1709.          +PassiDegCPLongtoSI[count];
  1710.         inc(n1);
  1711.         end;
  1712.        end;
  1713.      //Breakdown
  1714.       if ChopLength then
  1715.        begin
  1716.        for loopi:=0 to NumFoods-1 do
  1717.         begin
  1718.         fNDFLongBreakdown[loopi]:=fNDFLong[loopi]*LPBR;
  1719.         iNDFLongBreakdown[loopi]:=iNDFLong[loopi]*LPBR;
  1720.         SStarchLongBreakdown[loopi]:=SStarchLong[loopi]*LPBR;
  1721.         USStarchLongBreakdown[loopi]:=USStarchLong[loopi]*LPBR;
  1722.         DegCPLongBreakdown[loopi]:=DegCPLong[loopi]*LPBR;
  1723.         iDegCPLongBreakdown[loopi]:=iDegCPLong[loopi]*LPBR;
  1724.         SProteinToQProteinSolubilisation[loopi]:=DegCP[loopi]*SlowProteinToQuickProtein;
  1725.         SStarchToQStarchBreakdown[loopi]:=SStarch[loopi]*SStarchToQStarchBR;
  1726.         end;
  1727.        end
  1728.       else
  1729.        begin
  1730.        for loopi:=0 to NumFoods-1 do
  1731.         begin
  1732.         fNDFLongBreakdown[loopi]:=fNDFLong[loopi]*LPBR;
  1733.         iNDFLongBreakdown[loopi]:=iNDFLong[loopi]*LPBR;
  1734.         SStarchLongBreakdown[loopi]:=SStarchLong[loopi]*LPBR;
  1735.         USStarchLongBreakdown[loopi]:=USStarchLong[loopi]*LPBR;
  1736.         DegCPLongBreakdown[loopi]:=DegCPLong[loopi]*LPBR;
  1737.         iDegCPLongBreakdown[loopi]:=iDegCPLong[loopi]*LPBR;
  1738.         SProteinToQProteinSolubilisation[loopi]:=DegCP[loopi]*SlowProteinToQuickProtein;
  1739.         SStarchToQStarchBreakdown[loopi]:=SStarch[loopi]*SStarchToQStarchBR;
  1740. //       USStarchToUQStarchBreakdown[loopi]:=USStarch[loopi]*SStarchToQStarchBR;
  1741.         end;
  1742.        end;
  1743. //      if Days1toEnd=5 then
  1744. //      if StepHours1toEnd=1 then
  1745. //       QMP:=QMP;
  1746.      //Fermentation
  1747.      FermSolCHOinRum:=SolCHO*RSolCHO;
  1748.      FermMonoPG_GlycerolinRum:=MonoPG_Glycerol*RSolCHO;
  1749.      FermGlycerolinRumen:=Glycerol*RSolCHO;
  1750. //     if Days1toEnd=ptrFeedDescriptions.iDaysToRun then
  1751. //      dGlycerol:=dGlycerol+FermMonoPG_GlycerolinRum;
  1752.      FermSolsNDFinRum:=SolsNDF*RSolCHO;
  1753.      FermLacticinRum:=Lactate*RSolCHO*10; //2.5
  1754.      if NH3Rum>20 then
  1755.       FermNH3inRum:=15*RNH3
  1756.      else
  1757.       FermNH3inRum:=NH3Rum*RNH3;//RSolCHO*10;//only allow 75% NH3 to be fermented per iteration
  1758.      FermDLMCHO:=QDeadLiquidMicrobes*RSolCHO;
  1759.      FermDSMCHO:=QDeadSolidMicrobes*RSolCHO;
  1760.      FermDLMLip:=QDeadLiquidMicrobes*RSolCHO;
  1761.      FermDSMLip:=QDeadSolidMicrobes*RSolCHO;
  1762.      FermDLMProt:=QDeadLiquidMicrobes*RMicProt;
  1763.      FermDSMProt:=QDeadSolidMicrobes*RMicProt;
  1764.      FermDLaMCHO:=QDeadLiquidMicrobesLa*RSolCHO;
  1765.      FermDLaMLip:=QDeadLiquidMicrobesLa*RSolCHO;
  1766.      FermDLaMProt:=QDeadLiquidMicrobesLa*RMicProt;
  1767.      for loopi:=0 to NumFoods-1 do
  1768.       begin
  1769.       FermfNDFinRum[loopi]:=fNDF[loopi]*RNDF[loopi];
  1770.       FermfNDFLonginRum[loopi]:=fNDFLong[loopi]*RNDF[loopi];
  1771.       FermNDFRum:=FermNDFRum+FermfNDFinRum[loopi]+FermfNDFLonginRum[loopi];
  1772.       FermSStarchinRum[loopi]:=SStarch[loopi]*RSStarch[loopi];
  1773.       FermSStarchLonginRum[loopi]:=SStarchLong[loopi]*RSStarch[loopi];
  1774.       FermSStarchRum:=FermSStarchRum+FermSStarchinRum[loopi]+FermSStarchLonginRum[loopi];
  1775.       FermDegCPinRum[loopi]:=DegCP[loopi]*RDegCP[loopi];
  1776.       FermDegCPLonginRum[loopi]:=DegCPLong[loopi]*RDegCP[loopi];
  1777.       FermDegCPRum:=FermDegCPRum+FermDegCPinRum[loopi]+FermDegCPLonginRum[loopi];
  1778.       FermStarchinRum[loopi]:=QStarch[loopi]*RQStarch[loopi];
  1779.       FermQStarchRum:=FermQStarchRum+FermStarchinRum[loopi];
  1780.       FermSolCPinRum[loopi]:=SolCP[loopi]*RaCP[loopi];
  1781.       FermSolCPRum:=FermSolCPRum+FermSolCPinRum[loopi];
  1782.       FermPectininRum[loopi]:=PectinPS[loopi]*PectinRate[loopi];
  1783.       FermPectinRum:=FermPectinRum+FermPectininRum[loopi];
  1784.       end;
  1785. //     pH:=5;
  1786. //     MicLacRum:=MicMaint*0.45+1000000*Power(10,-pH)/1.4;
  1787. //     MicRumLiquid:=MicMaint*0.45+1000000*Power(10,-pH)/1.4;
  1788. //     MicLacUtRum:=MicMaint*0.45+1000000*Power(10,-pH)/1.2;
  1789. //     MicRumSolids:=MicMaint*0.8+1000000*Power(10,-pH)/1;
  1790. //     MicLacRum:=MicMaint*0.5+1000000*Power(10,-pH)/1.2;
  1791.       MicLacRum:=(MicMaint*0.45+1000000*Power(10,-pH)/1.4)/StepsPerHour*QMicLaR
  1792.                   *FreeWater/LiquidVolume;
  1793.       MicRumLiquid:=(MicMaint*0.45+1000000*Power(10,-pH)/1.4)/StepsPerHour*QMicLiquidR; //0.65 1.25
  1794.       MicLacUtRum:=(MicMaint*0.45+1000000*Power(10,-pH)/1.2)/StepsPerHour*QMicLaUtR;
  1795.  
  1796.      if (FNH3RumFree*(1-PpnLaUttoRest)-FermNH3inRumFree)>(FNH3RumSolid-FermNH3inRumSolid) then
  1797.       ProportionNH3Free:=ProportionNH3Free+0.01
  1798.      else ProportionNH3Free:=ProportionNH3Free-0.01;
  1799.      if ProportionNH3Free>0.8 then ProportionNH3Free:=0.8;
  1800.      if ProportionNH3Free<0.2 then ProportionNH3Free:=0.2;
  1801. //      if Days1toEnd=3 then
  1802. //       if Hours1to24=24 then
  1803. //        if StepHours1toEnd=10 then
  1804. //         QMP:=QMP;
  1805.  
  1806. //     Quick:=(FermSolCHOinRum+FermSolsNDFinRum
  1807. //                  +FermDLMCHO+FermDLaMCHO+FermPectinRum+
  1808. //                  FermQStarchRum)/(FermSolCPRum+FermDLMProt+FermDLaMProt+FNH3RumFree*6.25);
  1809. //     Slow:=(FermDSMCHO+FermNDFRum+FermSStarchRum)/(FermDegCPRum+FermDSMProt+FNH3RumSolid*6.25);
  1810.  
  1811.      FNH3RumFree:=FermNH3inRum*ProportionNH3Free;//0.5;//(QMicLaR+QMicLiquidR+QMicLaUtR)/(QMicLaR+QMicLiquidR+QMicSolidsR+QMicLaUtR);
  1812.      FNH3RumSolid:=FermNH3inRum*(1-ProportionNH3Free);//0.5;//QMicSolidsR/(QMicLaR+QMicLiquidR+QMicSolidsR);
  1813.      if Yeast then
  1814.       begin
  1815.       YeastMaint:=(MicMaint*0.45+1000000*Power(10,-pH)/1.2)/StepsPerHour*QYeast;
  1816.       YeastOxFe(FermSolCHOinRum,FermLacticinRum,FermQStarchRum,FermSolCPRum,
  1817.                 FNH3RumFree,OxygenLevel,Oil*RSolCHO,YeastMaint,QYeast,deltaYeast,AcY,
  1818.                 PropY,ButY,CH4Y,DeathYeast,OxygenUsed);
  1819.  
  1820.       end;
  1821.       PpnLaUttoRest:=QMicLaUtR/(QMicLaR+QMicLiquidR+QMicLaUtR);
  1822.       fermentation(FermSolCHOinRum+FermSolsNDFinRum
  1823.                   +FermDLMCHO+FermDLaMCHO,FermPectinRum,
  1824.                   FermQStarchRum,(FermSolCPRum+FermDLMProt+FermDLaMProt)
  1825.                   *(1-PpnLaUttoRest),(Oil*RSolCHO+FermDLMLip+FermDLaMLip)
  1826.                   *(1-PpnLaUttoRest),0,FNH3RumFree*(1-PpnLaUttoRest),QMicLiquidR,
  1827.                   QMicLaR,StepsPerHour,AcLRum,PropLRum,ButLRum,LacLRum,CH4LRum,
  1828.                   FermNH3inRumFree,MicRumLiquid,MicLacRum,UnFermSolCHOL,
  1829.                   UnfermNDFRL,x,StarchUsedFree,PpnHexUsedL,PpnHexFerm,
  1830.                   DeathOfQMicLiquidR,1);
  1831.       if LacLRum<0 then LacLRum:=0;
  1832.       if FermNH3inRumFree>FNH3RumFree*(1-PpnLaUttoRest) then
  1833.        PpnNH3:=1
  1834.       else
  1835.        PpnNH3:=FNH3RumFree*PpnLaUttoRest;
  1836.  
  1837.       fermentation(0,0,0,(FermSolCPRum+FermDLMProt+FermDLaMProt)*PpnLaUttoRest,
  1838.                   (Oil*RSolCHO+FermDLMLip+FermDLaMLip)*PpnLaUttoRest,
  1839.                   FermLacticinRum+FermMonoPG_GlycerolinRum+FermGlycerolinRumen,
  1840.                   FNH3RumFree*PpnNH3,QMicLaUtR,0,StepsPerHour,
  1841.                   AcLaRum,PropLaRum,ButLaRum,x,CH4LaRum,FermNH3inRumFreeLa,
  1842.                   MicLacUtRum,x,x,x,UnFermLacticAcidL,x,x,x,DeathOfQMicLiquidRLa,1);
  1843.      MicGrowthLacRum:=MicLacRum;
  1844.       MicRumSolids:=(MicMaint*0.8+1000000*Power(10,-pH)/1)/StepsPerHour*QMicSolidsR;
  1845.       MicLacRum:=(MicMaint*0.5+1000000*Power(10,-pH)/1.2)/StepsPerHour*QMicLaR
  1846.                  *(1-FreeWater/LiquidVolume);
  1847.      fermentation(FermDSMCHO,FermNDFRum,FermSStarchRum,
  1848.                   FermDegCPRum+FermDSMProt,Oil*RSolCHO+FermDSMLip,0,
  1849.                   FNH3RumSolid,QMicSolidsR,QMicLaR,StepsPerHour,AcSRum,PropSRum,ButSRum,
  1850.                   LacSRum,CH4SRum,FermNH3inRumSolid,MicRumSolids,MicLacRum,UnFermSolCHOS,
  1851.                   UnfermNDFRS,UnFermLacticAcidS,StarchUsedSolids,PpnHexUsedS,PpnHexFerm,
  1852.                   DeathOfQMicSolidsR,2);
  1853. //      if Days1toEnd={ptrFeedDescriptions.iDaysToRun}1 then
  1854. //      if StepHours1toEnd=1 then
  1855. //       QMP:=QMP;
  1856.  
  1857.      MicGrowthLacRum:=MicGrowthLacRum+MicLacRum;
  1858.      HFSCiR:=HFSCiR+FermSolCHOinRum+FermSolsNDFinRum+FermPectinRum;//+FermLacticinRum;
  1859.      HFNiR:=HFNiR+FermNDFRum;
  1860.      HFSiR:=HFSiR+FermQStarchRum*StarchUsedFree;
  1861.      HFSSiR:=HFSSiR+FermSStarchRum*StarchUsedSolids;
  1862.      HSCPiR:=HSCPiR+FermSolCPRum;
  1863.      HDCPiR:=HDCPiR+FermDegCPRum;
  1864. //     HSCiR:=HSCiR+SolCHO*UnFermSolCHOL;
  1865. //     HPSCiR:=HPSCiR+PassSolCHOtoSI;
  1866.      //Update Compartments
  1867.      //Rumen
  1868.      SolCHO:=SolCHO-PassSolCHOtoSI-FermSolCHOinRum*UnFermSolCHOL;
  1869.      SolsNDF:=SolsNDF-PassSolsNDFtoSI-FermSolsNDFinRum;
  1870.      Lactate:=Lactate-PassLactictoSI-FermLacticinRum*UnFermLacticAcidL
  1871.               +(LacLRum+LacSRum)*MWLacticAcid;//LacRum in moles
  1872.      Ash:=Ash-PassAshtoSI+SalivaFlow*7.5-(MicRumLiquid+MicRumSolids
  1873.           +MicGrowthLacRum)*Thousand*MicAsh;//g;
  1874. //     BicarbonateFromSaliva:=SalivaFlow*BicarbonateContentSaliva/1000*1.0; //eq or moles
  1875.      Oil:=Oil-PassOiltoSI-Oil*RSolCHO*2;//*(PpnHexUsedL+PpnHexUsedS);
  1876. //In MonoPG_Glycerol, 2*ferm because fermentation + absorption put at equivalent rates
  1877. // 489 Ruminal and physiological metabolism of glycerin. C. R.Krehbiel*,J. Anim. Sci. Vol. 86, E-Suppl. 2/J. Dairy Sci. Vol. 91, E-Suppl. 1 p392
  1878.      MonoPG_Glycerol:=MonoPG_Glycerol-PassMPGtoSI-2*FermMonoPG_GlycerolinRum;
  1879.      Glycerol:=Glycerol-PassGlyceroltoSI-2*FermGlycerolinRumen;
  1880.      UnfermentedGlycerolSmall:=UnfermentedGlycerolSmall-PassUnfermentedGlyceroltoSI;
  1881. // divided by 4 as Bodeker et al used rumen sacks to estimate uptake. Sacks
  1882. //would not have whole rumen volume!
  1883.      AbsNH3:=(NH3Rum/LiquidVolume/MWNH3*Thousand*0.5)*3/StepsPerHour/5
  1884.               *ptrFeedDescriptions^.RVol/100;//mmoles per time step Bodeker et al 1990
  1885. //20*blood to rumen a guess. In 10 min could estimate blood flow by using
  1886. //scaled blood flow
  1887. //NH3Rum should be around 18 to give 10mM (/LiquidVolume/MWNH3)
  1888. //      if Days1toEnd=ptrFeedDescriptions.iDaysToRun then
  1889. //       if Hours1to24=4 then
  1890. //        if StepHours1toEnd=4 then
  1891. //         QMP:=QMP;
  1892.       NH3Rum:=NH3Rum+ConsumedNH3/StepsPerHour-(FNH3RumFree*(1-PpnLaUttoRest)-FermNH3inRumFree)
  1893.              -(FNH3RumFree*PpnNH3-FermNH3inRumFreeLa)-(FNH3RumSolid-FermNH3inRumSolid)
  1894.              -PassNH3toSI+(SalivaFlow+0.5*VolBlood/BodyWater)*BloodUreaConc*2*MWNH3;//FermNH3Rum is value passed back of NH3 from fermentation
  1895.      NH3Rum:=NH3Rum-AbsNH3*LiquidVolume*MWNH3/Thousand;
  1896.      for loopi:=0 to NumFoods-1 do
  1897.       begin
  1898.       NH3Rum:=NH3Rum+SlowReleaseNH3*SlowReleaseNH3Rate[loopi];
  1899.       SlowReleaseNH3:=(1-SlowReleaseNH3Rate[loopi])*SlowReleaseNH3;
  1900.       end;
  1901. //milk from protein divided by no of hours and tstep then multiplied by BloodUreaConc
  1902. //gives the no of moles of urea in milk
  1903.      if ptrFeedDescriptions^.Week>0 then
  1904.       ptrNutAbsorbed^.MilkUrea:=ptrNutAbsorbed^.MilkFromP[CowParity,
  1905.              ptrFeedDescriptions^.Week-1]/HoursInDay/StepsPerHour*BloodUreaConc
  1906.      else ptrNutAbsorbed^.MilkUrea:=LactationDay1/HoursInDay/StepsPerHour*BloodUreaConc;
  1907. //dUrinaryN is gN/tstep and UrinaryN are gN/d
  1908.      dUrinaryN:=BloodUreaConc*2*MWN*Animal.Weight
  1909.                 *ClearanceRatio/HoursInDay/StepsPerHour;
  1910.      UrinaryN:=UrinaryN+dUrinaryN;
  1911.  
  1912. //1g of NH3 gives rise to 1/(2MWNH3) of urea moles
  1913. //1g of N gives rise to 1/(2MWN) of urea moles
  1914. //1 mmole of NH3 gives rise to 1/(2Thousand) of urea moles
  1915. //20*blood flow a guess. Could use scaled blood flow as better estimate
  1916.      UreaPoolSize:=BloodUreaConc*BodyWater
  1917.                    +PassNH3toSI/(2*MWNH3)*0.5+AbsNH3/2/Thousand
  1918.                    +ptrNutAbsorbed^.NH3-dUrinaryN/MWN/2-ptrNutAbsorbed^.MilkUrea
  1919.                    -SalivaFlow*BloodUreaConc-0.5*VolBlood/BodyWater*BloodUreaConc;
  1920.      BloodUreaConc:=UreaPoolSize/BodyWater;
  1921. //      if Days1toEnd=ptrFeedDescriptions.iDaysToRun then
  1922. //       if Hours1to24=4 then
  1923. //        if StepHours1toEnd=4 then
  1924. //         QMP:=QMP;
  1925.      if Days1toEnd>ptrFeedDescriptions.iDaysToRun-4 then//for last 4 days accumulate iterations where NH3 limiting
  1926.       begin
  1927.       if UnfermNDFRS>0 then
  1928.        inc(NH3Lim)
  1929.       else if (UnFermLacticAcidL>0) or (UnFermLacticAcidS>0) then
  1930.        inc(NH3Lim)
  1931.       else if (UnFermSolCHOL>0) or (UnFermSolCHOS>0) then
  1932.        inc(NH3Lim);
  1933.       end;
  1934.      for loopi:=0 to NumFoods-1 do
  1935.       begin
  1936.       fNDFLong[loopi]:=fNDFLong[loopi]-FermfNDFLonginRum[loopi]*UnfermNDFRS
  1937.                         -PassfNDFLongtoSI[loopi]-fNDFLongBreakdown[loopi];
  1938.       iNDFLong[loopi]:=iNDFLong[loopi]-PassiNDFLongtoSI[loopi]-iNDFLongBreakdown[loopi];
  1939.       fNDF[loopi]:=fNDF[loopi]-FermfNDFinRum[loopi]*UnfermNDFRS-PassfNDFtoSI[loopi]
  1940.                         +fNDFLongBreakdown[loopi];
  1941.       iNDF[loopi]:=iNDF[loopi]-PassiNDFtoSI[loopi]+iNDFLongBreakdown[loopi];
  1942.       SStarchLong[loopi]:=SStarchLong[loopi]-FermSStarchLonginRum[loopi]*StarchUsedSolids
  1943.                            -PassSStarchLongtoSI[loopi]-SStarchLongBreakdown[loopi];
  1944.       USStarchLong[loopi]:=USStarchLong[loopi]-PassUSStarchLongtoSI[loopi]
  1945.                             -USStarchLongBreakdown[loopi];
  1946.       SStarch[loopi]:=SStarch[loopi]-FermSStarchinRum[loopi]*StarchUsedSolids-PassSStarchtoSI[loopi]
  1947.                         +SStarchLongBreakdown[loopi]-SStarchToQStarchBreakdown[loopi];
  1948.       USStarch[loopi]:=USStarch[loopi]-PassUSStarchtoSI[loopi]+USStarchLongBreakdown[loopi];
  1949.       DegCPLong[loopi]:=DegCPLong[loopi]-FermDegCPLonginRum[loopi]-PassDegCPLongtoSI[loopi]
  1950.                          -DegCPLongBreakdown[loopi];
  1951.       iDegCPLong[loopi]:=iDegCPLong[loopi]-PassiDegCPLongtoSI[loopi]-iDegCPLongBreakdown[loopi];
  1952.       DegCP[loopi]:=DegCP[loopi]-FermDegCPinRum[loopi]-PassDegCPtoSI[loopi]
  1953.                          +DegCPLongBreakdown[loopi]-SProteinToQProteinSolubilisation[loopi];
  1954.       iDegCP[loopi]:=iDegCP[loopi]-PassiDegCPtoSI[loopi]+iDegCPLongBreakdown[loopi];
  1955.       QStarch[loopi]:=QStarch[loopi]-FermStarchinRum[loopi]*StarchUsedFree-PassQStarchtoSI[loopi]
  1956.                       +SStarchToQStarchBreakdown[loopi];
  1957.       UQStarch[loopi]:=UQStarch[loopi]-PassUQStarchtoSI[loopi];
  1958.       SolCP[loopi]:=SolCP[loopi]-FermSolCPinRum[loopi]-PassSolCPtoSI[loopi]
  1959.                     +SProteinToQProteinSolubilisation[loopi];
  1960.       PectinPS[loopi]:=PectinPS[loopi]-FermPectininRum[loopi]*UnfermNDFRL
  1961.                        -PassPectintoSI[loopi];
  1962.       DM:=fNDF[loopi]+iNDF[loopi]+fNDFLong[loopi]+iNDFLong[loopi]
  1963.              +LagNDF[loopi]+SolCP[loopi]+DegCP[loopi]+iDegCP[loopi]
  1964.              +DegCPLong[loopi]+iDegCPLong[loopi]+QStarch[loopi]+LagCP[loopi]
  1965.              +SStarch[loopi]+UQStarch[loopi]+USStarch[loopi]+LagSStarch[loopi]
  1966.              +SStarchLong[loopi]+USStarchLong[loopi];
  1967.       PassWater:=PassfNDFtoSI[loopi]+PassiNDFtoSI[loopi]
  1968.                  +PassfNDFLongtoSI[loopi]+PassiNDFLongtoSI[loopi]
  1969.                  +PassSolCPtoSI[loopi]+PassDegCPLongtoSI[loopi]
  1970.                  +PassiDegCPLongtoSI[loopi]+PassDegCPtoSI[loopi]
  1971.                  +PassiDegCPtoSI[loopi]+PassQStarchtoSI[loopi]
  1972.                  +PassSStarchtoSI[loopi]+PassUQStarchtoSI[loopi]
  1973.                  +PassUSStarchtoSI[loopi]+PassSStarchLongtoSI[loopi]
  1974.                  +PassUSStarchLongtoSI[loopi];
  1975.       if DM>0 then PassSIWater:=PassSIWater+((PassfNDFtoSI[loopi]+PassiNDFtoSI[loopi])/(PassWater{*Thousand
  1976.               /(Thousand-ptrFeedDescriptions^.TMRFeed[loopi].C1
  1977.                    -ptrFeedDescriptions^.TMRFeed[loopi].C1sNDF)})*7+1.08)
  1978.              *(PassWater-PassSolCPtoSI[loopi]-PassQStarchtoSI[loopi]-PassUQStarchtoSI[loopi]);
  1979.       if DM>0 then BoundWater:=BoundWater+((fNDF[loopi]+iNDF[loopi])/(DM{*Thousand
  1980.               /(Thousand-ptrFeedDescriptions^.TMRFeed[loopi].C1
  1981.                    -ptrFeedDescriptions^.TMRFeed[loopi].C1sNDF)})*7+1.08)
  1982.              *(DM-SolCP[loopi]-QStarch[loopi]-UQStarch[loopi]);
  1983.       end;
  1984.      SolubleCP:=0; DegradableTrueP:=0;
  1985.      for loopi:=0 to NumFoods-1 do
  1986.       begin
  1987.       SolubleCP:=SolubleCP+SolCP[loopi];
  1988.       DegradableTrueP:=DegradableTrueP+DegCP[loopi];
  1989.       end;
  1990.      QAcR:=QAcR+AcLRum+AcSRum+AcLaRum+ConsumedVFA/MWAceticAcid/StepsPerHour;//Q and dQ for Ac, Pr, Bu are in moles!
  1991.      dQAcR:=dQAcR+AcLRum+AcSRum+AcLaRum+ConsumedVFA/MWAceticAcid/StepsPerHour;
  1992.      QPrR:=QPrR+PropLRum+PropSRum+PropLaRum;
  1993.      dQPrR:=dQPrR+PropLRum+PropSRum+PropLaRum;
  1994.      QBuR:=QBuR+ButLRum+ButSRum+ButLaRum;
  1995.      dQBuR:=dQBuR+ButLRum+ButSRum+ButLaRum;
  1996.      //Put in +ConsumedLactate/MWLacticAcid/StepsPerHour to QLaR and dQLaR
  1997.      QLaR:=QLaR+LacLRum+LacSRum+ConsumedLactate/MWLacticAcid/StepsPerHour
  1998.            -FermLacticinRum/MWLacticAcid*UnFermLacticAcidL;
  1999.      dQLaR:=dQLaR+LacLRum+LacSRum+ConsumedLactate/MWLacticAcid/StepsPerHour
  2000.             -FermLacticinRum/MWLacticAcid*UnFermLacticAcidL;
  2001.       if Days1toEnd=ptrFeedDescriptions.iDaysToRun then
  2002.        begin
  2003.        SIMicCHO:=SIMicCHO+((QMicLiquidR+QDeadLiquidMicrobes)*LiquidCHO+(QMicLaUtR
  2004.                    +QDeadLiquidMicrobesLa)*LaUtCHO+QMicLaR*MicCHO)*PassageFree
  2005.                    +((QMicLiquidR+QDeadLiquidMicrobes)*LiquidCHO+(QDeadSolidMicrobes
  2006.                    +QMicSolidsR+QMicLaR)*MicCHO+(QMicLaUtR
  2007.                    +QDeadLiquidMicrobesLa)*LaUtCHO)*PassageBound;
  2008.        SIMicLip:=SIMicLip+((QMicLiquidR+QDeadLiquidMicrobes)*LiquidLip+(QMicLaUtR
  2009.                    +QDeadLiquidMicrobesLa)*LaUtLip+QMicLaR*MicLip)*PassageFree
  2010.                    +((QMicLiquidR+QDeadLiquidMicrobes)*LiquidLip+(QDeadSolidMicrobes
  2011.                    +QMicSolidsR+QMicLaR)*MicLip+(QMicLaUtR
  2012.                    +QDeadLiquidMicrobesLa)*LaUtLip)*PassageBound;
  2013.        end;
  2014.       dSIMicCHO:=dSIMicCHO+((QMicLiquidR+QDeadLiquidMicrobes)*LiquidCHO+(QMicLaUtR
  2015.                    +QDeadLiquidMicrobesLa)*LaUtCHO+QMicLaR*MicCHO)*PassageFree
  2016.                    +((QMicLiquidR+QDeadLiquidMicrobes)*LiquidCHO+(QDeadSolidMicrobes
  2017.                    +QMicSolidsR+QMicLaR)*MicCHO+(QMicLaUtR
  2018.                    +QDeadLiquidMicrobesLa)*LaUtCHO)*PassageBound;
  2019.       dSIMicLip:=dSIMicLip+((QMicLiquidR+QDeadLiquidMicrobes)*LiquidLip+(QMicLaUtR
  2020.                    +QDeadLiquidMicrobesLa)*LaUtLip+QMicLaR*MicLip)*PassageFree
  2021.                    +((QMicLiquidR+QDeadLiquidMicrobes)*LiquidLip+(QDeadSolidMicrobes
  2022.                    +QMicSolidsR+QMicLaR)*MicLip+(QMicLaUtR
  2023.                    +QDeadLiquidMicrobesLa)*LaUtLip)*PassageBound;
  2024.       MPOutOfRumen:=((QMicLiquidR+QDeadLiquidMicrobes)*LiquidProt+(QMicLaUtR
  2025.                    +QDeadLiquidMicrobesLa)*LaUtProt+QMicLaR*MicrobialCrudeProtein)*PassageFree
  2026.                    +((QMicLiquidR+QDeadLiquidMicrobes)*LiquidProt+(QDeadSolidMicrobes
  2027.                    +QMicSolidsR+QMicLaR)*MicrobialCrudeProtein+(QMicLaUtR
  2028.                    +QDeadLiquidMicrobesLa)*LaUtProt)*PassageBound;
  2029.       QDeadLiquidMicrobes:=QDeadLiquidMicrobes+QMicLiquidR*DeathOfQMicLiquidR
  2030.                           -QDeadLiquidMicrobes*(PassageFree+PassageBound)
  2031.                           -FermDLMCHO-FermDLMProt-FermDLMLip;
  2032.       QDeadSolidMicrobes:=QDeadSolidMicrobes+QMicSolidsR*DeathOfQMicSolidsR
  2033.                          -QDeadSolidMicrobes*RConcPPass-FermDSMCHO-FermDSMProt
  2034.                          -FermDSMLip;
  2035.       QDeadLiquidMicrobesLa:=QDeadLiquidMicrobesLa+QMicLaUtR*DeathOfQMicLiquidRLa
  2036.                          -QDeadLiquidMicrobesLa*(PassageFree+PassageBound)
  2037.                          -FermDLaMCHO-FermDLaMProt-FermDLaMLip;
  2038.       QMicLiquidR:=QMicLiquidR-PassQMicLiquidR+PassQMicSolidsR
  2039.                   -QMicLiquidR*(PassageFree+PassageBound)-QMicLiquidR*DeathOfQMicLiquidR;
  2040.       LiquidCHO:=(QMicLiquidR*LiquidCHO+MicRumLiquid*Thousand*MicCHO)/(QMicLiquidR
  2041.                +MicRumLiquid*Thousand);
  2042.       LiquidProt:=MicrobialCrudeProtein/MicNonCHO*(1-LiquidCHO);
  2043.       LiquidLip:=MicLip/MicNonCHO*(1-LiquidCHO);
  2044.       QMicLiquidR:=QMicLiquidR+MicRumLiquid*Thousand;
  2045.       QMicSolidsR:=QMicSolidsR+MicRumSolids*Thousand+PassQMicLiquidR-PassQMicSolidsR
  2046.                   -QMicSolidsR*RConcPPass-QMicSolidsR*DeathOfQMicSolidsR;
  2047.       QMicLaUtR:=QMicLaUtR
  2048.                   -QMicLaUtR*(PassageFree+PassageBound)-QMicLaUtR*DeathOfQMicLiquidRLa;
  2049.       LaUtCHO:=(QMicLaUtR*LaUtCHO+MicLacUtRum*Thousand*MicCHO)/(QMicLaUtR
  2050.                +MicLacUtRum*Thousand);
  2051.       LaUtProt:=MicrobialCrudeProtein/MicNonCHO*(1-LaUtCHO);
  2052.       LaUtLip:=MicLip/MicNonCHO*(1-LaUtCHO);
  2053.       QMicLaUtR:=QMicLaUtR+MicLacUtRum*Thousand;
  2054.      QMicLaR:=QMicLaR+MicGrowthLacRum*Thousand-QMicLaR*(PassageFree+PassageBound);
  2055.      Blood(CAcR,CPrR,CBuR,pH,ptrFeedDescriptions^.RVol,ptrFeedDescriptions^.RumSA{*RumFillUpper},
  2056.             StepsPerHour,AbsAc,AbsPr,AbsBu);
  2057. //Production of H+ - total
  2058.      ProdLacAc:=0.05*(LacLRum+LacSRum)/(AcLRum+AcSRum); //*tslp/2;//
  2059.      Acid:=(CAcR+CPrR+CBuR+CLaR*(1.2+ProdLacAc))*LiquidVolume-ConsumedVFA/MWAceticAcid/StepsPerHour //moles
  2060.                 -ConsumedLactate/MWLacticAcid/StepsPerHour+AcidEaten/StepsPerHour/Thousand
  2061.                 +AcLRum+AcSRum+PropLRum+PropSRum+ButLRum+ButSRum+LacLRum+LacSRum
  2062.                 +AcLaRum+PropLaRum+ButLaRum; //*1.2 to give lactic more umphh
  2063. //CAcR, CPrR, CBuR, CLaR are moles/litre
  2064.      pnLaR:=CLaR/(CAcr+CPrR+CBuR+CLaR);
  2065.      CAcR:=CAcR+(AcLRum+AcSRum+AcLaRum+ConsumedVFA/MWAceticAcid/StepsPerHour)/LiquidVolume
  2066.            -AbsAc/LiquidVolume-CAcR*PassageFree-CAcR*PassageBound;
  2067.      CPrR:=CPrR+(PropLRum+PropSRum+PropLaRum)/LiquidVolume-AbsPr/LiquidVolume
  2068.            -CPrR*PassageFree-CPrR*PassageBound;
  2069.      CBuR:=CBuR+(ButLRum+ButSRum+ButLaRum)/LiquidVolume-AbsBu/LiquidVolume
  2070.            -CBuR*PassageFree-CBuR*PassageBound;
  2071.      CLaR:=Lactate/MWLacticAcid/LiquidVolume; //Lactate (g/kg) /90 (-> moles)
  2072.      BicarbonateFromSaliva:=SalivaFlow*BicarbonateContentSaliva/Thousand; //eq or moles
  2073.      if Days1toEnd=ptrFeedDescriptions.iDaysToRun then
  2074.       begin
  2075.       PAcR:=PAcR+AcLRum+AcSRum+AcLaRum;
  2076.       PPrR:=PPrR+PropLRum+PropSRum+PropLaRum;
  2077.       PBuR:=PBuR+ButLRum+ButSRum+ButLaRum;
  2078.       PLaR:=PLaR+LacLRum+LacSRum;
  2079.       if FNH3RumSolid-FermNH3inRumSolid<0 then
  2080.        NH3UsedSolid:=0
  2081.       else
  2082.        NH3UsedSolid:=FNH3RumSolid-FermNH3inRumSolid;
  2083.       if FNH3RumFree-FermNH3inRumFree<0 then
  2084.        NH3UsedFree:=0
  2085.       else
  2086.        NH3UsedFree:=FNH3RumFree-FermNH3inRumFree;
  2087.       HFNH3QiR:=HFNH3QiR+NH3UsedFree;
  2088.       HFNH3SiR:=HFNH3SiR+NH3UsedSolid;
  2089.       FreeProteinRatio:=FreeProteinRatio+FermNH3inRumFree-FNH3RumFree-FermSolCPRum*0.36/6.25*17/14;
  2090.       SolidProteinRatio:=SolidProteinRatio+FermNH3inRumSolid-FNH3RumSolid-FermDegCPRum*0.36/6.25*17/14;
  2091.       end;
  2092.      if Days1toEnd>4 then       //3 to 4
  2093.       begin
  2094. //     if Bicarbonate7_74 then
  2095. //      begin
  2096.       //Paper in J Anim Sci 1998 Kohn and Dunlap on calculation of buffering capacity of
  2097.       //bicarbonate rumen 76, 1702-1709. Says pKa 7.74 and pCO2 0.7.
  2098.       //put in a pH factor which says how much acetate is dissociated at pH
  2099.       //So all VFA and lactic produced as acid but at pH how much is dissociated?
  2100.       DissociatedAcidRatioVFA:=exp(pH-pKVFA)/(exp(pH-pKVFA)+1);
  2101.       DissociatedAcidRatioLactic:=exp(pH-pKLA)/(exp(pH-pKLA)+1);
  2102.       deNaHCO3:=(BicarbonateFromSaliva+BicarbonateEaten/StepsPerHour
  2103.              +FermLacticinRum/MWLacticAcid*UnFermLacticAcidL*DissociatedAcidRatioLactic
  2104.                 +(AbsAc+AbsPr+AbsBu)*DissociatedAcidRatioVFA)
  2105.                 /(FreeWater+BoundWater/Thousand); //moles/l
  2106.       deHProduced:=((AcLRum+AcSRum+PropLRum+PropSRum+ButLRum+ButSRum
  2107.                 +AcLaRum+PropLaRum+ButLaRum)*DissociatedAcidRatioVFA+(LacLRum
  2108.                 +LacSRum)*DissociatedAcidRatioLactic+AcidEaten*AcidNeutralised/StepsPerHour)
  2109.                 /(FreeWater+BoundWater/Thousand); //moles/l
  2110.       MolarNaHCO3:=MolarNaHCO3+deNaHCO3-deHProduced;
  2111.       if MolarNaHCO3<0.00127 then MolarNaHCO3:=0.00127;
  2112.       pHOverTime[StepHours1toEnd]:=pKCO2+log10(MolarNaHCO3/pCO2);
  2113.       MolarNaHCO3:=MolarNaHCO3*(1-PassageFree-PassageBound);
  2114.       dAcid:=dAcid+Acid;
  2115.       end;
  2116.      pH:=0;
  2117.      for loopi:=0 to AvpH-1 do
  2118.       begin
  2119.       if StepHours1toEnd-loopi=0 then
  2120.        pH:=pH+pHOverTime[10]
  2121.       else if StepHours1toEnd-loopi=-1 then
  2122.        pH:=pH+pHOverTime[9]
  2123.       else if StepHours1toEnd-loopi=-2 then
  2124.        pH:=pH+pHoverTime[8]
  2125.       else if StepHours1toEnd-loopi=-3 then
  2126.        pH:=pH+pHoverTime[7]
  2127.       else if StepHours1toEnd-loopi=-4 then
  2128.        pH:=pH+pHoverTime[6]
  2129.       else if StepHours1toEnd-loopi=-5 then
  2130.        pH:=pH+pHoverTime[5]
  2131.       else if StepHours1toEnd-loopi=-6 then
  2132.        pH:=pH+pHoverTime[4]
  2133.       else if StepHours1toEnd-loopi=-7 then
  2134.        pH:=pH+pHoverTime[3]
  2135.       else if StepHours1toEnd-loopi=-8 then
  2136.        pH:=pH+pHoverTime[2]
  2137.       else if StepHours1toEnd-loopi=-9 then
  2138.        pH:=pH+pHoverTime[1]
  2139.       else pH:=pH+pHOverTime[loopi+1];
  2140.       end;
  2141.      pH:=pH/AvpH;
  2142.      if (Days1toEnd=ptrFeedDescriptions.iDaysToRun-1) and (pH<6.25) then
  2143.       begin
  2144.       pHLim:=pHLim+(6.25-pH);
  2145.       end;
  2146.      if Days1toEnd=ptrFeedDescriptions^.iDaysToRun then
  2147.       DailyFlowSaliva:=DailyFlowSaliva+SalivaFlow;
  2148.      pHLast:=pHOverTime[StepHours1toEnd];
  2149.      if pH>6.75 then pH:=6.75;
  2150. //Water dynamics
  2151.      RumenOsmol:=(CAcR+CPrR+CBuR+CLaR+(Ash/MWIons+SolCHO/MWGlucose
  2152.                   +SolubleCP/MWProtein+MonoPG_Glycerol/MWMPG
  2153.                   +NH3Rum/MWNH3)/LiquidVolume)*Thousand;
  2154.      OsFlux:=10*(0.0001*ptrFeedDescriptions^.RumSA*(RumenOsmol-BloodOsmol-55))
  2155.              /StepsPerHour/HoursInDay; //g/tstep Argylle and Baldwin 1988. .00003*RumSA my bit. 10* to give a tstep rate from a day rate!
  2156. //      if Days1toEnd=ptrFeedDescriptions.iDaysToRun then
  2157. //      if StepHours1toEnd=4 then
  2158. //       QMP:=QMP;
  2159.      if MicrobesAcidosis then
  2160.       begin
  2161.       BodyWater:=BodyWater-OsFlux-ptrFeedDescriptions^.MilkWater/StepsPerHour+OutFlow
  2162.                  -MinimumUrineWater-SalivaFlow+PassSIWater/Thousand;
  2163.       if BodyWater>Animal.Water then
  2164.        begin
  2165.        dUrineWater:=BodyWater-Animal.Water;
  2166.        dWaterDrunk:=0;
  2167.        end
  2168.       else
  2169.        begin
  2170.        dUrineWater:=0;
  2171.        end;
  2172.       dUrineWater:=dUrineWater+MinimumUrineWater;
  2173.       UrineWater:=UrineWater+dUrineWater;
  2174.       BodyWater:=BodyWater-dUrineWater;
  2175.       end;
  2176.      FreeWater:=FreeWater+OsFlux+SalivaFlow+FeedWater/Thousand/StepsPerHour+dWaterDrunk;
  2177.      dWaterDrunk:=0;
  2178.      LiquidVolume:=FreeWater+BoundWater/Thousand;
  2179.      PassageFree:=RLPass*FreeWater/LiquidVolume;
  2180.      if PassageFree>0.5 then PassageFree:=0.5;
  2181.      PassageBound:=RConcPPass*(1-FreeWater/LiquidVolume);
  2182.      TotalRumenVol:=RumDM/Thousand+FreeWater+BoundWater/Thousand;
  2183.      if TotalRumenVol>ptrFeedDescriptions^.RVol then
  2184.       begin
  2185.       OutFlow:=TotalRumenVol-ptrFeedDescriptions^.RVol;
  2186.       TotalRumenVol:=ptrFeedDescriptions^.RVol;
  2187.       FreeWater:=FreeWater-Outflow;
  2188.       end
  2189.      else OutFlow:=0;
  2190.      RLPass:=OutFlow/LiquidVolume;
  2191.      if FreeWater<0.05 then FreeWater:=0.5;
  2192.      if Yeast then
  2193.       OxygenLevel:=OxygenLevel*(1-OxygenUsed)+(dWaterDrunk+SalivaFlow)*200
  2194.                    -OutFlow;
  2195.      //SI
  2196.      dSIMic:=dSIMic+MPOutOfRumen/MicrobialCrudeProtein;
  2197.      MTP:=MTP+MPOutOfRumen*CPToTP*DigestibilityofTP;
  2198.      DUP:=DUP+(SumPassSolCPtoSI+SumPassDigCPtoSI)*DigestibilityOfDUP;
  2199.      MP:=MTP+DUP;//cumulative
  2200.      dMP:=dMP+MPOutOfRumen*CPToTP*DigestibilityofTP
  2201.           +(SumPassSolCPtoSI+SumPassDigCPtoSI)*DigestibilityOfDUP;
  2202.      SumUndigestedProtein:=0;
  2203.      for loopi:=0 to NumFoods-1 do
  2204.       begin
  2205.       SIfNDF[loopi]:=SIfNDF[loopi]+PassfNDFtoSI[loopi]+PassfNDFLongtoSI[loopi]
  2206.                       +PassLagfNDFtoSI[loopi];
  2207.       SIiNDF[loopi]:=SIiNDF[loopi]+PassiNDFtoSI[loopi]+PassiNDFLongtoSI[loopi]
  2208.                       +PassLagiNDFtoSI[loopi];
  2209.       SIDegCP[loopi]:=SIDegCP[loopi]+PassDegCPtoSI[loopi]+PassDegCPLongtoSI[loopi]
  2210.                        +PassLagDegCPtoSI[loopi];
  2211.       SIiDegCP[loopi]:=SIiDegCP[loopi]+PassiDegCPtoSI[loopi]+PassiDegCPLongtoSI[loopi]
  2212.                        +PassLagiDegCPtoSI[loopi];
  2213.       SIStarch[loopi]:=SIStarch[loopi]+(PassQStarchtoSI[loopi]+PassUQStarchtoSI[loopi]
  2214.              +PassSStarchToSI[loopi]+PassUSStarchToSI[loopi]
  2215.              +PassSStarchLongToSI[loopi]+PassUSStarchLongToSI[loopi])*LacticToGlucose;
  2216.       SIDigCHO:=SIDigCHO+(PassQStarchtoSI[loopi]+PassUQStarchtoSI[loopi]
  2217.              +PassSStarchToSI[loopi]+PassUSStarchToSI[loopi]
  2218.              +PassSStarchLongToSI[loopi]+PassUSStarchLongToSI[loopi])*LacticToGlucose;
  2219.       if Days1toEnd=(ptrFeedDescriptions^.iDaysToRun) then
  2220.        begin
  2221.        QCHO:=QCHO+(PassQStarchtoSI[loopi]+PassUQStarchtoSI[loopi]
  2222.              +PassSStarchToSI[loopi]+PassUSStarchToSI[loopi]
  2223.              +PassSStarchLongToSI[loopi]+PassUSStarchLongToSI[loopi])*LacticToGlucose;
  2224.        end;
  2225.       dSIDigCHO:=dSIDigCHO+(PassQStarchtoSI[loopi]+PassUQStarchtoSI[loopi]
  2226.              +PassSStarchToSI[loopi]+PassUSStarchToSI[loopi]
  2227.              +PassSStarchLongToSI[loopi]+PassUSStarchLongToSI[loopi])*LacticToGlucose;
  2228.       SumUndigestedProtein:=SumUndigestedProtein+PassDegCPtoSI[loopi]+PassiDegCPtoSI[loopi];
  2229.       end;
  2230. //     if Days1toEnd=(ptrFeedDescriptions^.iDaysToRun) then
  2231.       SIUndigestedCP:=(SumPassSolCPtoSI+SumUndigestedProtein)*(1-DigestibilityOfDUP)
  2232.                      +MPOutOfRumen*CPToTP*(1-DigestibilityofTP);//FoodCP that is not absorbed
  2233.      SIDigCHO:=SIDigCHO+PassSolCHOtoSI+PassLactictoSI*LacticToGlucose
  2234.                 +PassMPGtoSI/MWMPG/2*MWGlucose
  2235.                 +(PassUnfermentedGlyceroltoSI+PassGlyceroltoSI)/MWGlycerol/2*MWGlucose;
  2236.      dSIDigCHO:=dSIDigCHO+PassSolCHOtoSI+PassLactictoSI*LacticToGlucose
  2237.                 +PassMPGtoSI/MWMPG/2*MWGlucose
  2238.                 +(PassUnfermentedGlyceroltoSI+PassGlyceroltoSI)/MWGlycerol/2*MWGlucose;
  2239.      AbsOil:=AbsOil+PassOiltoSI;
  2240.      dAbsOil:=dAbsOil+PassOiltoSI;
  2241.      //HG
  2242.      for loopi:=0 to NumFoods-1 do
  2243.       begin
  2244.       PassPectinOut[loopi]:=HGPectinPS[loopi]*HGPPass;
  2245.       PassfNDFOut[loopi]:=HGfNDF[loopi]*HGPPass;
  2246.       PassiNDFOut[loopi]:=HGiNDF[loopi]*HGPPass;
  2247.       FaecalPectin:=FaecalPectin+PassPectinOut[loopi];
  2248.       FaecaliNDF:=FaecaliNDF+PassiNDFOut[loopi];
  2249.       FaecalfNDF:=FaecalfNDF+PassfNDFOut[loopi];
  2250.       FDM:=FDM+PassfNDFOut[loopi]+PassiNDFOut[loopi]+PassPectinOut[loopi];//cumulative
  2251.       FermPectininHG[loopi]:=HGPectinPS[loopi]*PectinRate[loopi];
  2252.       FermPectinHG:=FermPectinHG+FermPectininHG[loopi];
  2253.       FermfNDFinHG[loopi]:=HGfNDF[loopi]*RNDF[loopi];
  2254.       FermNDFHG:=FermNDFHG+FermfNDFinHG[loopi];
  2255.       HGPectinPS[loopi]:=HGPectinPS[loopi]+PassPectintoSI[loopi]
  2256.                          -PassPectinOut[loopi]-FermPectininHG[loopi];
  2257.       HGfNDF[loopi]:=HGfNDF[loopi]+PassfNDFtoSI[loopi]+PassfNDFLongtoSI[loopi]
  2258.                       +PassLagfNDFtoSI[loopi]-PassfNDFOut[loopi]-FermfNDFinHG[loopi];
  2259.       HGiNDF[loopi]:=HGiNDF[loopi]+PassiNDFtoSI[loopi]+PassiNDFLongtoSI[loopi]
  2260.                      +PassLagiNDFtoSI[loopi]-PassiNDFOut[loopi];
  2261.       end;
  2262.      FermNDFHG:=FermNDFHG;//+FermsNDFHG;
  2263.      FermProteinHG:=QProteinHG*0.1/StepsPerHour;
  2264.      MicHG:=MicMaint/StepsPerHour*QMicHG;
  2265.      if (Days1toEnd<3) and (Hours1to24<4) then    //2 to 3
  2266.      else
  2267.       begin
  2268.       fermentation(FermsNDFHG,FermNDFHG+FermPectinHG,0,FermProteinHG,0,0,0,QMicHG,0,StepsPerHour,
  2269.                   AcHG, PropHG, ButHG,LacHG, CH4HG, NH3HG, MicHG,MicLacHG,
  2270.                   UnFermSolCHOHG, UnFermNDFHG,UnFermLacticAcidHG,StarchUsedHG,
  2271.                   PpnHexUsed,PpnHexFerm,DeathOfQMicHG, 3);
  2272.       QMicHG:=QMicHG+MicHG*Thousand-QMicHG*HGPPass;
  2273.       end;
  2274.      QAcHG:=QAcHG+AcHG;
  2275.      dQAcHG:=dQAcHG+AcHG;
  2276.      QPrHG:=QPrHG+PropHG;
  2277.      dQPrHG:=dQPrHG+PropHG;
  2278.      QBuHG:=QBuHG+ButHG;
  2279.      dQBuHG:=dQBuHG+ButHG;
  2280.      QProteinHG:=QProteinHG-QProteinHG*HGPPass-FermProteinHG+SIUndigestedCP;
  2281.      FDM:=FDM+QMicHG*HGPPass+QProteinHG*HGPPass;
  2282.      if Days1toEnd=ptrFeedDescriptions^.iDaysToRun then
  2283.       begin
  2284.       QAc:=QAc+AcLRum+AcSRum+AcLaRum+ConsumedVFA/MWAceticAcid/StepsPerHour+AcHG;
  2285.       QPr:=QPr+PropLRum+PropSRum+PropLaRum+PropHG;
  2286.       QBu:=QBu+ButLRum+ButSRum+ButLaRum+ButHG;
  2287.       //Absorption of MonoPG_Glycerol equivalent to Fermentation
  2288.       QCHO:=QCHO+PassSolCHOtoSI+PassLactictoSI+(PassMPGtoSI
  2289.              +FermMonoPG_GlycerolinRum+PassUnfermentedGlyceroltoSI)/MWMPG/2*MWGlucose;
  2290.       QCH4R:=QCH4R+CH4LRum+CH4SRum+CH4LaRum;//moles
  2291.       QCH4HG:=QCH4HG+CH4HG;
  2292.       FaecalN:=FaecalN+QMicHG*HGPPass*0.5/6.25+QProteinHG*HGPPass/6.25;//assumes microbial CP is 50% of microbialDM
  2293.       QMTP:=QMTP+MPOutOfRumen*CPToTP*DigestibilityofTP;
  2294.       QDUP:=QDUP+(SumPassSolCPtoSI+SumPassDigCPtoSI)*DigestibilityOfDUP;
  2295.       QMP:=QMTP+QDUP;//cumulative
  2296.       SIMic:=SIMic+MPOutOfRumen/MicrobialCrudeProtein;
  2297.       //efficiency of microbial N synthesis (EMNS) 25gN/kgOM or 32gN/kgcarbohydrate
  2298.       dEMNS:=(MicRumLiquid+MicRumSolids+MicLacRum)*Thousand*Thousand*0.45/6.25
  2299.              /(FermSolCHOinRum+FermSolsNDFinRum+FermNDFRum+FermQStarchRum+FermSStarchRum
  2300.            {+FermSolCPRum+FermDegCPRum+Oil}-UnFermSolCHOL-UnFermSolCHOS
  2301.              -UnfermNDFRS-UnFermLacticAcidL-UnFermLacticAcidS);
  2302.       hEMNSh:=hEMNSh+dEMNS;
  2303.       EMNS:=EMNS+dEMNS;
  2304.       for loopi:=0 to NumFoods-1 do
  2305.        begin
  2306.        TLongNDFForage[Hours1To24]:=TLongNDFForage[Hours1To24]+(iNDFLong[loopi]
  2307.                                    +fNDFLong[loopi])/StepsPerHour/RumDM;
  2308.        ULongNDFForage[Hours1To24]:=ULongNDFForage[Hours1To24]+iNDFLong[loopi]
  2309.                                    /StepsPerHour/RumDM;
  2310.        if loopi<ptrFeedDescriptions^.iNoFeeds then
  2311.         begin
  2312.         if (ptrFeedDescriptions^.TMRFeed[loopi].ForOrConc) or (ptrFeedDescriptions^.TMRFeed[loopi].GroundOrLong=False) then
  2313.          begin
  2314.          UNDFForage[Hours1To24]:=UNDFForage[Hours1To24]+(iNDFLong[loopi]
  2315.                                  +iNDF[loopi])/StepsPerHour/TotalRumDM;
  2316.          TNDFForage[Hours1To24]:=TNDFForage[Hours1To24]+(iNDFLong[loopi]
  2317.                                    +iNDF[loopi]+fNDFLong[loopi]+fNDF[loopi])
  2318.                                    /StepsPerHour/TotalRumDM;
  2319.          end;
  2320.         end
  2321.        else if loopi=ptrFeedDescriptions^.iNoFeeds-1+ptrFeedDescriptions^.iGrazing then
  2322.         begin
  2323.         if ptrFeedDescriptions^.GrazingFeed.ForOrConc then
  2324.          begin
  2325.          UNDFForage[Hours1To24]:=UNDFForage[Hours1To24]+(iNDFLong[loopi]
  2326.                                  +iNDF[loopi])/StepsPerHour/TotalRumDM;
  2327.          TNDFForage[Hours1To24]:=TNDFForage[Hours1To24]+(iNDFLong[loopi]
  2328.                                    +iNDF[loopi]+fNDFLong[loopi]+fNDF[loopi])
  2329.                                    /StepsPerHour/TotalRumDM;
  2330.          end;
  2331.         end
  2332.        else if loopi>ptrFeedDescriptions^.iNoFeeds-1+ptrFeedDescriptions^.iGrazing then
  2333.         begin
  2334. //        if ptrFeedDescriptions^.ParlourFeed[loopi-1-(ptrFeedDescriptions^.iNoFeeds-1+ptrFeedDescriptions^.iGrazing)].ForOrConc then
  2335. //         begin
  2336. //         UNDFForage[Hours1To24]:=UNDFForage[Hours1To24]+(iNDFLong[loopi]
  2337. //                                 +iNDF[loopi])/StepsPerHour/TotalRumDM;
  2338. //         TNDFForage[Hours1To24]:=TNDFForage[Hours1To24]+(iNDFLong[loopi]
  2339. //                                   +iNDF[loopi]+fNDFLong[loopi]+fNDF[loopi])
  2340. //                                   /StepsPerHour/TotalRumDM;
  2341. //         end;
  2342.         end;
  2343.        end;
  2344.       end;
  2345.      end;//end of within hour loop
  2346.      LagParlourFeed:=0;
  2347. //add in intake
  2348.    if (Hours1to24 in EatingTime) then
  2349.     begin
  2350. //   if Days1toEnd=ptrFeedDescriptions^.iDaysToRun then
  2351. //            QMP:=QMP;
  2352.     HourlyPotentialIntake:=(ptrFeedDescriptions^.RumFillUpper
  2353.                             *ptrFeedDescriptions^.RVol*Thousand*0.15
  2354.                            -RumDM)/Thousand;
  2355.     if (Hours1to24 in GrazingHour[ptrFeedDescriptions^.Diet]) then
  2356.      begin
  2357.      if HourlyPotentialIntake>ptrFeedDescriptions^.MaxIntakePerHourPGrazing then
  2358.       HourlyPotentialIntake:=ptrFeedDescriptions^.MaxIntakePerHourPGrazing;
  2359.      end
  2360.     else {if not Beef then}
  2361.  
  2362.      begin
  2363.      if HourlyPotentialIntake>ptrFeedDescriptions^.MaxIntakePerHour then
  2364.       begin
  2365.       HourlyPotentialIntake:=ptrFeedDescriptions^.MaxIntakePerHour;
  2366.       EatingStepsPerHour:=StepsPerHour;
  2367.       end
  2368.      else
  2369.       begin
  2370.       EatingStepsPerHour:=Round(StepsPerHour*HourlyPotentialIntake
  2371.                            /ptrFeedDescriptions^.MaxIntakePerHour);
  2372.       end;
  2373.      end;
  2374.     end
  2375.    else
  2376.     HourlyPotentialIntake:=0;
  2377.    if HourlyPotentialIntake<0 then HourlyPotentialIntake:=0;
  2378.    ConsumedVFA:=0;
  2379.    ConsumedNH3:=0;
  2380.    ConsumedLactate:=0;
  2381.    FeedWater:=0;
  2382.    AcidEaten:=0; BicarbonateEaten:=0; AlkabupHaAcidConsumed:=0; AlkabupHaAcidConsumedPpn:=0;
  2383.   if (Hours1to24 in AwakeTime) then
  2384.    begin
  2385.    if (FSParlour[ptrFeedDescriptions^.Diet]) and
  2386.     (Hours1to24 in ParlourHour[ptrFeedDescriptions^.Diet])
  2387.      then
  2388.     begin
  2389.     n1:=0;
  2390.     ParlourRobot:=True;
  2391.     if LagTimeParlour then
  2392.      begin
  2393.      LagParlourFeed:=ptrFeedDescriptions^.ParlourPerMeal;
  2394.      end
  2395.     else
  2396.      begin
  2397.      LagParlourFeed:=0;
  2398.      end;
  2399.     for count:=ParlourCountLow to ParlourCountHigh do
  2400.      begin
  2401.      if TMRRobotic then
  2402.       begin
  2403.       if (HalfRobotic) and (Hours1to24=1) then
  2404.        begin
  2405.        HalfRoboticDMI:=0.5;
  2406.        end
  2407.       else
  2408.        begin
  2409.        HalfRoboticDMI:=1;
  2410.        end;
  2411.       ParlourPerMealPerFood:=ptrFeedDescriptions^.RoboticPerMeal1
  2412.                                      *PMParlourAmount[n1]/100*HalfRoboticDMI;
  2413.       end
  2414.      else
  2415.       ParlourPerMealPerFood:=ptrFeedDescriptions^.ParlourPerMeal
  2416.                                      *PMParlourAmount[n1]/100*HalfRoboticDMI;
  2417.      LagUrea[count]:=LagUrea[count]+ParlourPerMealPerFood
  2418.                       *ptrFeedDescriptions^.ParlourFeed[n1].UreaProtected;
  2419.      LagUreaToEnter[count,Hours1to24]:=ParlourPerMealPerFood
  2420.                       *ptrFeedDescriptions^.ParlourFeed[n1].UreaProtected;
  2421.      LagUreaEntryTime[count,Hours1to24]:=ElapsedTime
  2422.                      +ptrFeedDescriptions^.ParlourFeed[n1].UreaTimeLag;
  2423.      LagNDF[count]:=LagNDF[count]+ParlourPerMealPerFood
  2424.                       *ptrFeedDescriptions^.ParlourFeed[n1].fermNDF
  2425.                       +ParlourPerMealPerFood
  2426.                       *ptrFeedDescriptions^.ParlourFeed[n1].unfermNDF;
  2427.      LagfNDFToEnter[count,Hours1to24]:=ParlourPerMealPerFood
  2428.                       *ptrFeedDescriptions^.ParlourFeed[n1].fermNDF;
  2429.      LagiNDFToEnter[count,Hours1to24]:=ParlourPerMealPerFood
  2430.                       *ptrFeedDescriptions^.ParlourFeed[n1].unfermNDF;
  2431.      LagNDFEntryTime[count,Hours1to24]:=ElapsedTime
  2432.                       +ptrFeedDescriptions^.ParlourFeed[n1].Lag;
  2433.      LagSStarch[count]:=LagSStarch[count]+ParlourPerMealPerFood
  2434.                       *ptrFeedDescriptions^.ParlourFeed[n1].SlowStarch
  2435.                       +ParlourPerMealPerFood
  2436.                       *ptrFeedDescriptions^.ParlourFeed[n1].UndegSStarch;
  2437.      LagSStarchToEnter[count,Hours1to24]:=ParlourPerMealPerFood
  2438.                       *ptrFeedDescriptions^.ParlourFeed[n1].SlowStarch;
  2439.      LagUSStarchToEnter[count,Hours1to24]:=ParlourPerMealPerFood
  2440.                       *ptrFeedDescriptions^.ParlourFeed[n1].UndegSStarch;
  2441.      LagSStarchEntryTime[count,Hours1to24]:=ElapsedTime
  2442.                       +ptrFeedDescriptions^.ParlourFeed[n1].StarchLag;
  2443.      LagCP[count]:=LagCP[count]+ParlourPerMealPerFood
  2444.                       *ptrFeedDescriptions^.ParlourFeed[n1].P2
  2445.                       +ParlourPerMealPerFood
  2446.                       *ptrFeedDescriptions^.ParlourFeed[n1].P3;
  2447.      LagDegCPToEnter[count,Hours1to24]:=ParlourPerMealPerFood
  2448.                       *ptrFeedDescriptions^.ParlourFeed[n1].P2;
  2449.      LagiDegCPToEnter[count,Hours1to24]:=ParlourPerMealPerFood
  2450.                       *ptrFeedDescriptions^.ParlourFeed[n1].P3;
  2451.      LagCPEntryTime[count,Hours1to24]:=ElapsedTime
  2452.                       +ptrFeedDescriptions^.ParlourFeed[n1].NLag;
  2453.      if LagTimeParlour then
  2454.       begin
  2455. //      LagParlourFeed:=ptrFeedDescriptions^.ParlourPerMeal;
  2456.       end
  2457.      else
  2458.       begin
  2459.       QStarch[count]:=QStarch[count]+ParlourPerMealPerFood
  2460.                       *ptrFeedDescriptions^.ParlourFeed[n1].QuickStarch;
  2461.       UQStarch[count]:=UQStarch[count]+ParlourPerMealPerFood
  2462.                       *ptrFeedDescriptions^.ParlourFeed[n1].UndegQStarch;
  2463.       SolCHO:=SolCHO+ParlourPerMealPerFood
  2464.                       *ptrFeedDescriptions^.ParlourFeed[n1].C1;
  2465.       MonoPG_Glycerol:=MonoPG_Glycerol+ParlourPerMealPerFood
  2466.                       *ptrFeedDescriptions^.ParlourFeed[n1].MPG;
  2467.       Glycerol:=Glycerol+ParlourPerMealPerFood
  2468.                       *ptrFeedDescriptions^.ParlourFeed[n1].Glycerol;
  2469.       UnfermentedGlycerolSmall:=UnfermentedGlycerolSmall+ParlourPerMealPerFood
  2470.                       *ptrFeedDescriptions^.ParlourFeed[n1].UnfermentedGlycerol;
  2471.       SolCP[count]:=SolCP[count]+ParlourPerMealPerFood
  2472.                       *ptrFeedDescriptions^.ParlourFeed[n1].P1;
  2473.       if ptrFeedDescriptions^.Pectins then
  2474.        begin
  2475.        SolsNDF:=0;
  2476.        PectinPS[count]:=PectinPS[count]+ParlourPerMealPerFood
  2477.                       *ptrFeedDescriptions^.ParlourFeed[n1].C1sNDF;
  2478.        end
  2479.       else
  2480.        begin
  2481.        if ptrFeedDescriptions^.ACHOintoWSCsNDF then
  2482.         SolsNDF:=SolsNDF+ParlourPerMealPerFood
  2483.                *ptrFeedDescriptions^.ParlourFeed[n1].C1sNDF
  2484.        else SolsNDF:=0;
  2485.        end;
  2486.       Ash:=Ash+ParlourPerMealPerFood
  2487.           *ptrFeedDescriptions^.ParlourFeed[n1].Mins;
  2488.       Oil:=Oil+ParlourPerMealPerFood
  2489.           *ptrFeedDescriptions^.ParlourFeed[n1].EE;
  2490.       ConsumedVFA:=ConsumedVFA+ParlourPerMealPerFood
  2491.                   *ptrFeedDescriptions^.ParlourFeed[n1].fVFA;
  2492.       Lactate:=Lactate+ParlourPerMealPerFood
  2493.               *ptrFeedDescriptions^.ParlourFeed[n1].fLactic;
  2494.       ConsumedNH3:=ConsumedNH3+ParlourPerMealPerFood
  2495.                   *ptrFeedDescriptions^.ParlourFeed[n1].fNH3;
  2496.       AcidEaten:=AcidEaten+ParlourPerMealPerFood
  2497.                  *ptrFeedDescriptions^.ParlourFeed[n1].PpnAcid;
  2498.       BicarbonateEaten:=BicarbonateEaten+ParlourPerMealPerFood
  2499.                         *ptrFeedDescriptions^.ParlourFeed[n1].HCO3*Thousand/MWNaHCO3;
  2500.       FeedWater:=FeedWater+ParlourPerMealPerFood*10
  2501.                 *(100-ptrFeedDescriptions^.ParlourFeed[n1].DM);
  2502.       end;
  2503.      HourlyActualIntake[count]:=ParlourPerMealPerFood;
  2504.      inc(n1);
  2505.      end;
  2506.     if ParlourTMR then
  2507.      begin
  2508.      for loopi:=0 to ptrFeedDescriptions^.iNoFeeds-1 do   //
  2509.       begin
  2510.       //Rob reckoned that TMR eaten should be around 7 - 8 kg DM. 1.25 that I did have was lower than that at 2.5 so it was multiplied by 3.1!
  2511.       HI:=3.875*ptrAmount^[ptrFeedDescriptions^.iNoFeeds*(ptrFeedDescriptions^.Diet-1)+loopi];  //1.25
  2512.       LagUrea[loopi]:=LagUrea[loopi]+HI
  2513.                             *ptrFeedDescriptions^.TMRFeed[loopi].UreaProtected;
  2514.       LagUreaToEnter[loopi,Hours1to24]:=HI*ptrFeedDescriptions^.TMRFeed[loopi].UreaProtected;
  2515.       if LagUreaToEnter[loopi,Hours1to24]>0 then
  2516.        LagUreaEntryTime[loopi,Hours1to24]:=ElapsedTime
  2517.                                                 +ptrFeedDescriptions^.TMRFeed[loopi].UreaTimeLag;
  2518.       LagSGlycerol[loopi]:=LagSGlycerol[loopi]+HI
  2519.                             *ptrFeedDescriptions^.TMRFeed[loopi].SlowGlycerol;
  2520.       LagSGlycerolToEnter[loopi,Hours1to24]:=HI*ptrFeedDescriptions^.TMRFeed[loopi].SlowGlycerol;
  2521.       if LagSGlycerolToEnter[loopi,Hours1to24]>0 then
  2522.        LagSGlycerolEntryTime[loopi,Hours1to24]:=ElapsedTime
  2523.                                                 +ptrFeedDescriptions^.TMRFeed[loopi].SlowGlycerolLag;
  2524.       LagNDF[loopi]:=LagNDF[loopi]+HI*ptrFeedDescriptions^.TMRFeed[loopi].fermNDF
  2525.                           +HI*ptrFeedDescriptions^.TMRFeed[loopi].unfermNDF;
  2526.       LagfNDFToEnter[loopi,Hours1to24]:=HI*ptrFeedDescriptions^.TMRFeed[loopi].fermNDF;
  2527.       LagiNDFToEnter[loopi,Hours1to24]:=HI*ptrFeedDescriptions^.TMRFeed[loopi].unfermNDF;
  2528.       if (LagfNDFToEnter[loopi,Hours1to24]>0) or (LagiNDFToEnter[loopi,Hours1to24]>0) then
  2529.         LagNDFEntryTime[loopi,Hours1to24]:=ElapsedTime+ptrFeedDescriptions^.TMRFeed[loopi].Lag{+4};
  2530.       LagSStarch[loopi]:=LagSStarch[loopi]+HI*ptrFeedDescriptions^.TMRFeed[loopi].SlowStarch
  2531.                           +HI*ptrFeedDescriptions^.TMRFeed[loopi].UndegSStarch;
  2532.       LagSStarchToEnter[loopi,Hours1to24]:=HI*ptrFeedDescriptions^.TMRFeed[loopi].SlowStarch;
  2533.       LagUSStarchToEnter[loopi,Hours1to24]:=HI*ptrFeedDescriptions^.TMRFeed[loopi].UndegSStarch;
  2534.       if (LagSStarchToEnter[loopi,Hours1to24]>0) or (LagUSStarchToEnter[loopi,Hours1to24]>0) then
  2535.         LagSStarchEntryTime[loopi,Hours1to24]:=ElapsedTime+ptrFeedDescriptions^.TMRFeed[loopi].StarchLag{+4};
  2536.       QStarch[loopi]:=QStarch[loopi]+HI*ptrFeedDescriptions^.TMRFeed[loopi].QuickStarch;
  2537.       UQStarch[loopi]:=UQStarch[loopi]+HI*ptrFeedDescriptions^.TMRFeed[loopi].UndegQStarch;
  2538.       LagCP[loopi]:=LagCP[loopi]+HI*ptrFeedDescriptions^.TMRFeed[loopi].P2
  2539.                           +HI*ptrFeedDescriptions^.TMRFeed[loopi].P3;
  2540.       LagDegCPToEnter[loopi,Hours1to24]:=HI*ptrFeedDescriptions^.TMRFeed[loopi].P2;
  2541.       LagiDegCPToEnter[loopi,Hours1to24]:=HI*ptrFeedDescriptions^.TMRFeed[loopi].P3;
  2542.       if (LagDegCPToEnter[loopi,Hours1to24]>0) or (LagiDegCPToEnter[loopi,Hours1to24]>0) then
  2543.         LagCPEntryTime[loopi,Hours1to24]:=ElapsedTime+ptrFeedDescriptions^.TMRFeed[loopi].NLag;
  2544.       SolCHO:=SolCHO+HI*ptrFeedDescriptions^.TMRFeed[loopi].C1;
  2545.       MonoPG_Glycerol:=MonoPG_Glycerol+HI*ptrFeedDescriptions^.TMRFeed[loopi].MPG;
  2546.       Glycerol:=Glycerol+HI*ptrFeedDescriptions^.TMRFeed[loopi].Glycerol;
  2547.       UnfermentedGlycerolSmall:=UnfermentedGlycerolSmall
  2548.                     +HI*ptrFeedDescriptions^.TMRFeed[loopi].UnfermentedGlycerol;
  2549.       if ptrFeedDescriptions^.Pectins then
  2550.        begin
  2551.        SolsNDF:=0;
  2552.        PectinPS[loopi]:=PectinPS[loopi]+HI
  2553.                        *ptrFeedDescriptions^.TMRFeed[loopi].C1sNDF
  2554.        end
  2555.       else
  2556.        begin
  2557.        if ptrFeedDescriptions^.ACHOintoWSCsNDF then
  2558.        SolsNDF:=SolsNDF+HI*ptrFeedDescriptions^.TMRFeed[loopi].C1sNDF
  2559.        else SolsNDF:=0;
  2560.        end;
  2561.       SolCP[loopi]:=SolCP[loopi]+HI*ptrFeedDescriptions^.TMRFeed[loopi].P1;
  2562.       Ash:=Ash+HI*ptrFeedDescriptions^.TMRFeed[loopi].Mins;
  2563.       Oil:=Oil+HI*ptrFeedDescriptions^.TMRFeed[loopi].EE;
  2564.       ConsumedVFA:=ConsumedVFA+HI*ptrFeedDescriptions^.TMRFeed[loopi].fVFA;
  2565.       Lactate:=Lactate+HI*ptrFeedDescriptions^.TMRFeed[loopi].fLactic;
  2566.       ConsumedLactate:=ConsumedLactate+HI*ptrFeedDescriptions^.TMRFeed[loopi].fLactic;
  2567.       ConsumedNH3:=ConsumedNH3+HI*ptrFeedDescriptions^.TMRFeed[loopi].fNH3;
  2568.       AcidEaten:=AcidEaten+HI*ptrFeedDescriptions^.TMRFeed[loopi].PpnAcid;
  2569.       if not NotAlkapHer then
  2570.        begin
  2571.        AlkabupHaAcidConsumed:=AlkabupHaAcidConsumed
  2572.                               +HI*(ptrFeedDescriptions^.TMRFeed[loopi].fLactic
  2573.                               +ptrFeedDescriptions^.TMRFeed[loopi].fVFA*1.25);
  2574.        end;
  2575.       BicarbonateEaten:=BicarbonateEaten+HI
  2576.                         *ptrFeedDescriptions^.TMRFeed[loopi].HCO3*Thousand/MWNaHCO3;
  2577.       HourlyActualIntake[loopi]:=HI;
  2578.       FeedWater:=FeedWater+HI*10*(100-ptrFeedDescriptions^.TMRFeed[loopi].DM);
  2579. //      if Days1toEnd=ptrFeedDescriptions^.iDaysToRun then
  2580. //       if Hours1to24=3 then
  2581.  
  2582. //             QMP:=QMP;
  2583.       end;
  2584.  
  2585.      end;
  2586.  
  2587.     if (TMRRobotic) and (RoboticCountHigh>RoboticCountLow) then
  2588.      begin
  2589.      n1:=0;
  2590.      ParlourRobot:=True;
  2591.      for count:=RoboticCountLow to RoboticCountHigh do
  2592.       begin
  2593.       RoboticPerMealPerFood:=ptrFeedDescriptions^.RoboticPerMeal2
  2594.                                      *PMRoboticAmount[n1]/100*HalfRoboticDMI;
  2595.       if RoboticPerMealPerFood>0 then
  2596.        begin
  2597.       LagUrea[count]:=LagUrea[count]+RoboticPerMealPerFood
  2598.                       *ptrFeedDescriptions^.RoboticFeed[n1].UreaProtected;
  2599.       LagUreaToEnter[count,Hours1to24]:=RoboticPerMealPerFood
  2600.                       *ptrFeedDescriptions^.RoboticFeed[n1].UreaProtected;
  2601.       LagUreaEntryTime[count,Hours1to24]:=ElapsedTime
  2602.                      +ptrFeedDescriptions^.RoboticFeed[n1].UreaTimeLag;
  2603.       LagNDF[count]:=LagNDF[count]+RoboticPerMealPerFood
  2604.                       *ptrFeedDescriptions^.RoboticFeed[n1].fermNDF
  2605.                       +RoboticPerMealPerFood
  2606.                       *ptrFeedDescriptions^.RoboticFeed[n1].unfermNDF;
  2607.       LagfNDFToEnter[count,Hours1to24]:=RoboticPerMealPerFood
  2608.                       *ptrFeedDescriptions^.RoboticFeed[n1].fermNDF;
  2609.       LagiNDFToEnter[count,Hours1to24]:=RoboticPerMealPerFood
  2610.                       *ptrFeedDescriptions^.RoboticFeed[n1].unfermNDF;
  2611.       LagNDFEntryTime[count,Hours1to24]:=ElapsedTime
  2612.                       +ptrFeedDescriptions^.RoboticFeed[n1].Lag;
  2613.       LagSStarch[count]:=LagSStarch[count]+RoboticPerMealPerFood
  2614.                       *ptrFeedDescriptions^.RoboticFeed[n1].SlowStarch
  2615.                       +RoboticPerMealPerFood
  2616.                       *ptrFeedDescriptions^.RoboticFeed[n1].UndegSStarch;
  2617.       LagSStarchToEnter[count,Hours1to24]:=RoboticPerMealPerFood
  2618.                       *ptrFeedDescriptions^.RoboticFeed[n1].SlowStarch;
  2619.       LagUSStarchToEnter[count,Hours1to24]:=RoboticPerMealPerFood
  2620.                       *ptrFeedDescriptions^.RoboticFeed[n1].UndegSStarch;
  2621.       LagSStarchEntryTime[count,Hours1to24]:=ElapsedTime
  2622.                       +ptrFeedDescriptions^.RoboticFeed[n1].StarchLag;
  2623.       LagCP[count]:=LagCP[count]+ParlourPerMealPerFood
  2624.                       *ptrFeedDescriptions^.RoboticFeed[n1].P2
  2625.                       +RoboticPerMealPerFood
  2626.                       *ptrFeedDescriptions^.RoboticFeed[n1].P3;
  2627.       LagDegCPToEnter[count,Hours1to24]:=RoboticPerMealPerFood
  2628.                       *ptrFeedDescriptions^.RoboticFeed[n1].P2;
  2629.       LagiDegCPToEnter[count,Hours1to24]:=RoboticPerMealPerFood
  2630.                       *ptrFeedDescriptions^.RoboticFeed[n1].P3;
  2631.       LagCPEntryTime[count,Hours1to24]:=ElapsedTime
  2632.                       +ptrFeedDescriptions^.RoboticFeed[n1].NLag;
  2633.       if LagTimeParlour then
  2634.        begin
  2635. //      LagParlourFeed:=ptrFeedDescriptions^.ParlourPerMeal;
  2636.        end
  2637.       else
  2638.        begin
  2639.        QStarch[count]:=QStarch[count]+RoboticPerMealPerFood
  2640.                       *ptrFeedDescriptions^.RoboticFeed[n1].QuickStarch;
  2641.        UQStarch[count]:=UQStarch[count]+RoboticPerMealPerFood
  2642.                       *ptrFeedDescriptions^.RoboticFeed[n1].UndegQStarch;
  2643.        SolCHO:=SolCHO+RoboticPerMealPerFood
  2644.                       *ptrFeedDescriptions^.RoboticFeed[n1].C1;
  2645.        MonoPG_Glycerol:=MonoPG_Glycerol+RoboticPerMealPerFood
  2646.                       *ptrFeedDescriptions^.RoboticFeed[n1].MPG;
  2647.        Glycerol:=Glycerol+RoboticPerMealPerFood
  2648.                       *ptrFeedDescriptions^.RoboticFeed[n1].Glycerol;
  2649.        UnfermentedGlycerolSmall:=UnfermentedGlycerolSmall+RoboticPerMealPerFood
  2650.                       *ptrFeedDescriptions^.RoboticFeed[n1].UnfermentedGlycerol;
  2651.        SolCP[count]:=SolCP[count]+RoboticPerMealPerFood
  2652.                       *ptrFeedDescriptions^.RoboticFeed[n1].P1;
  2653.        if ptrFeedDescriptions^.Pectins then
  2654.         begin
  2655.         SolsNDF:=0;
  2656.         PectinPS[count]:=PectinPS[count]+RoboticPerMealPerFood
  2657.                       *ptrFeedDescriptions^.RoboticFeed[n1].C1sNDF;
  2658.         end
  2659.        else
  2660.         begin
  2661.         if ptrFeedDescriptions^.ACHOintoWSCsNDF then
  2662.          SolsNDF:=SolsNDF+RoboticPerMealPerFood
  2663.                *ptrFeedDescriptions^.RoboticFeed[n1].C1sNDF
  2664.         else SolsNDF:=0;
  2665.         end;
  2666.        Ash:=Ash+RoboticPerMealPerFood
  2667.           *ptrFeedDescriptions^.RoboticFeed[n1].Mins;
  2668.        Oil:=Oil+RoboticPerMealPerFood
  2669.           *ptrFeedDescriptions^.RoboticFeed[n1].EE;
  2670.        ConsumedVFA:=ConsumedVFA+RoboticPerMealPerFood
  2671.                   *ptrFeedDescriptions^.RoboticFeed[n1].fVFA;
  2672.        Lactate:=Lactate+RoboticPerMealPerFood
  2673.               *ptrFeedDescriptions^.RoboticFeed[n1].fLactic;
  2674.        ConsumedNH3:=ConsumedNH3+RoboticPerMealPerFood
  2675.                   *ptrFeedDescriptions^.RoboticFeed[n1].fNH3;
  2676.        AcidEaten:=AcidEaten+RoboticPerMealPerFood
  2677.                  *ptrFeedDescriptions^.RoboticFeed[n1].PpnAcid;
  2678.        BicarbonateEaten:=BicarbonateEaten+RoboticPerMealPerFood
  2679.                         *ptrFeedDescriptions^.RoboticFeed[n1].HCO3*Thousand/MWNaHCO3;
  2680.        FeedWater:=FeedWater+RoboticPerMealPerFood*10
  2681.                 *(100-ptrFeedDescriptions^.RoboticFeed[n1].DM);
  2682.        end;
  2683.       HourlyActualIntake[count]:=RoboticPerMealPerFood;
  2684.       inc(n1);
  2685.        end;
  2686.       end;
  2687.      if ptrFeedDescriptions^.iLiquid>0 then
  2688.       begin
  2689.       count:=LiquidCount;
  2690.       LiqPerMeal:=rFeedInfo.LiquidPerMeal*HalfRoboticDMI;
  2691.       begin
  2692.       LagUrea[count]:=LagUrea[count]+LiqPerMeal
  2693.                       *ptrFeedDescriptions^.LiquidFeed.UreaProtected;
  2694.       LagUreaToEnter[count,Hours1to24]:=LiqPerMeal
  2695.                       *ptrFeedDescriptions^.LiquidFeed.UreaProtected;
  2696.       LagUreaEntryTime[count,Hours1to24]:=ElapsedTime
  2697.                      +ptrFeedDescriptions^.LiquidFeed.UreaTimeLag;
  2698.       LagNDF[count]:=LagNDF[count]+LiqPerMeal
  2699.                       *ptrFeedDescriptions^.LiquidFeed.fermNDF
  2700.                       +LiqPerMeal
  2701.                       *ptrFeedDescriptions^.LiquidFeed.unfermNDF;
  2702.       LagfNDFToEnter[count,Hours1to24]:=LiqPerMeal
  2703.                       *ptrFeedDescriptions^.LiquidFeed.fermNDF;
  2704.       LagiNDFToEnter[count,Hours1to24]:=LiqPerMeal
  2705.                       *ptrFeedDescriptions^.LiquidFeed.unfermNDF;
  2706.       LagNDFEntryTime[count,Hours1to24]:=ElapsedTime
  2707.                       +ptrFeedDescriptions^.LiquidFeed.Lag;
  2708.       LagSStarch[count]:=LagSStarch[count]+LiqPerMeal
  2709.                       *ptrFeedDescriptions^.LiquidFeed.SlowStarch
  2710.                       +LiqPerMeal
  2711.                       *ptrFeedDescriptions^.LiquidFeed.UndegSStarch;
  2712.       LagSStarchToEnter[count,Hours1to24]:=LiqPerMeal
  2713.                       *ptrFeedDescriptions^.LiquidFeed.SlowStarch;
  2714.       LagUSStarchToEnter[count,Hours1to24]:=LiqPerMeal
  2715.                       *ptrFeedDescriptions^.LiquidFeed.UndegSStarch;
  2716.       LagSStarchEntryTime[count,Hours1to24]:=ElapsedTime
  2717.                       +ptrFeedDescriptions^.LiquidFeed.StarchLag;
  2718.       LagCP[count]:=LagCP[count]+LiqPerMeal
  2719.                       *ptrFeedDescriptions^.LiquidFeed.P2
  2720.                       +LiqPerMeal
  2721.                       *ptrFeedDescriptions^.LiquidFeed.P3;
  2722.       LagDegCPToEnter[count,Hours1to24]:=LiqPerMeal
  2723.                       *ptrFeedDescriptions^.LiquidFeed.P2;
  2724.       LagiDegCPToEnter[count,Hours1to24]:=LiqPerMeal
  2725.                       *ptrFeedDescriptions^.LiquidFeed.P3;
  2726.       LagCPEntryTime[count,Hours1to24]:=ElapsedTime
  2727.                       +ptrFeedDescriptions^.LiquidFeed.NLag;
  2728.       if LagTimeParlour then
  2729.        begin
  2730. //      LagParlourFeed:=ptrFeedDescriptions^.ParlourPerMeal;
  2731.        end
  2732.       else
  2733.        begin
  2734.        QStarch[count]:=QStarch[count]+LiqPerMeal
  2735.                       *ptrFeedDescriptions^.LiquidFeed.QuickStarch;
  2736.        UQStarch[count]:=UQStarch[count]+LiqPerMeal
  2737.                       *ptrFeedDescriptions^.LiquidFeed.UndegQStarch;
  2738.        SolCHO:=SolCHO+LiqPerMeal
  2739.                       *ptrFeedDescriptions^.LiquidFeed.C1;
  2740.        MonoPG_Glycerol:=MonoPG_Glycerol+LiqPerMeal
  2741.                       *ptrFeedDescriptions^.LiquidFeed.MPG;
  2742.        Glycerol:=Glycerol+LiqPerMeal
  2743.                       *ptrFeedDescriptions^.LiquidFeed.Glycerol;
  2744.        UnfermentedGlycerolSmall:=UnfermentedGlycerolSmall+LiqPerMeal
  2745.                       *ptrFeedDescriptions^.LiquidFeed.UnfermentedGlycerol;
  2746.        SolCP[count]:=SolCP[count]+LiqPerMeal
  2747.                       *ptrFeedDescriptions^.LiquidFeed.P1;
  2748.        if ptrFeedDescriptions^.Pectins then
  2749.         begin
  2750.         SolsNDF:=0;
  2751.         PectinPS[count]:=PectinPS[count]+LiqPerMeal
  2752.                       *ptrFeedDescriptions^.LiquidFeed.C1sNDF;
  2753.         end
  2754.        else
  2755.         begin
  2756.         if ptrFeedDescriptions^.ACHOintoWSCsNDF then
  2757.          SolsNDF:=SolsNDF+LiqPerMeal
  2758.                *ptrFeedDescriptions^.LiquidFeed.C1sNDF
  2759.         else SolsNDF:=0;
  2760.         end;
  2761.        Ash:=Ash+LiqPerMeal
  2762.           *ptrFeedDescriptions^.LiquidFeed.Mins;
  2763.        Oil:=Oil+LiqPerMeal
  2764.           *ptrFeedDescriptions^.LiquidFeed.EE;
  2765.        ConsumedVFA:=ConsumedVFA+LiqPerMeal
  2766.                   *ptrFeedDescriptions^.LiquidFeed.fVFA;
  2767.        Lactate:=Lactate+LiqPerMeal
  2768.               *ptrFeedDescriptions^.LiquidFeed.fLactic;
  2769.        ConsumedNH3:=ConsumedNH3+LiqPerMeal
  2770.                   *ptrFeedDescriptions^.LiquidFeed.fNH3;
  2771.        AcidEaten:=AcidEaten+LiqPerMeal
  2772.                  *ptrFeedDescriptions^.LiquidFeed.PpnAcid;
  2773.        BicarbonateEaten:=BicarbonateEaten+LiqPerMeal
  2774.                         *ptrFeedDescriptions^.LiquidFeed.HCO3*Thousand/MWNaHCO3;
  2775.        FeedWater:=FeedWater+LiqPerMeal*10
  2776.                 *(100-ptrFeedDescriptions^.LiquidFeed.DM);
  2777.        end;
  2778.       HourlyActualIntake[count]:=LiqPerMeal;
  2779.       end;
  2780.      end;
  2781.      end;
  2782.      //      if Days1toEnd=ptrFeedDescriptions^.iDaysToRun then
  2783. //             QMP:=QMP;
  2784.     CanEatForage:=False;
  2785.     end;
  2786.    if (Hours1to24 in EatingTime) then
  2787.     begin
  2788.     if (Hours1to24 in GrazingHour[ptrFeedDescriptions^.Diet]) then
  2789.      begin
  2790.      ParlourRobot:=False;
  2791.      if HourlyPotentialIntake>ptrFeedDescriptions^.SwardLength/4 then
  2792.       HourlyPotentialIntake:=ptrFeedDescriptions^.SwardLength/4;
  2793.      count:=ptrFeedDescriptions^.iNoFeeds;
  2794.      LagNDF[count]:=LagNDF[count]+HourlyPotentialIntake*ptrFeedDescriptions^.GrazingFeed.fermNDF
  2795.                       +HourlyPotentialIntake*ptrFeedDescriptions^.GrazingFeed.unfermNDF;
  2796.      LagfNDFToEnter[count,Hours1to24]:=HourlyPotentialIntake*ptrFeedDescriptions^.GrazingFeed.fermNDF;
  2797.      LagiNDFToEnter[count,Hours1to24]:=HourlyPotentialIntake*ptrFeedDescriptions^.GrazingFeed.unfermNDF;
  2798.      LagNDFEntryTime[count,Hours1to24]:=ElapsedTime+ptrFeedDescriptions^.GrazingFeed.Lag;
  2799.      LagSStarch[count]:=LagSStarch[count]+HourlyPotentialIntake*ptrFeedDescriptions^.GrazingFeed.SlowStarch
  2800.                       +HourlyPotentialIntake*ptrFeedDescriptions^.GrazingFeed.UndegSStarch;
  2801.      LagSStarchToEnter[count,Hours1to24]:=HourlyPotentialIntake*ptrFeedDescriptions^.GrazingFeed.SlowStarch;
  2802.      LagUSStarchToEnter[count,Hours1to24]:=HourlyPotentialIntake*ptrFeedDescriptions^.GrazingFeed.UndegSStarch;
  2803.      LagSStarchEntryTime[count,Hours1to24]:=ElapsedTime+ptrFeedDescriptions^.GrazingFeed.StarchLag;
  2804.      QStarch[count]:=QStarch[count]+HourlyPotentialIntake*ptrFeedDescriptions^.GrazingFeed.QuickStarch;
  2805.      UQStarch[count]:=UQStarch[count]+HourlyPotentialIntake*ptrFeedDescriptions^.GrazingFeed.UndegQStarch;
  2806.      LagCP[count]:=LagCP[count]+HourlyPotentialIntake*ptrFeedDescriptions^.GrazingFeed.P2
  2807.                       +HourlyPotentialIntake*ptrFeedDescriptions^.GrazingFeed.P3;
  2808.      LagDegCPToEnter[count,Hours1to24]:=HourlyPotentialIntake*ptrFeedDescriptions^.GrazingFeed.P2;
  2809.      LagiDegCPToEnter[count,Hours1to24]:=HourlyPotentialIntake*ptrFeedDescriptions^.GrazingFeed.P3;
  2810.      LagCPEntryTime[count,Hours1to24]:=ElapsedTime+ptrFeedDescriptions^.GrazingFeed.NLag;
  2811.      SolCHO:=SolCHO+HourlyPotentialIntake*ptrFeedDescriptions^.GrazingFeed.C1;
  2812.      MonoPG_Glycerol:=MonoPG_Glycerol+HourlyPotentialIntake*ptrFeedDescriptions^.GrazingFeed.MPG;
  2813.      Glycerol:=Glycerol+HourlyPotentialIntake*ptrFeedDescriptions^.GrazingFeed.Glycerol;
  2814.      UnfermentedGlycerolSmall:=UnfermentedGlycerolSmall+HourlyPotentialIntake
  2815.                           *ptrFeedDescriptions^.GrazingFeed.UnfermentedGlycerol;
  2816.      if ptrFeedDescriptions^.Pectins then
  2817.       begin
  2818.       SolsNDF:=0;
  2819.       PectinPS[count]:=PectinPS[count]+HourlyPotentialIntake
  2820.                        *ptrFeedDescriptions^.GrazingFeed.C1sNDF
  2821.       end
  2822.      else
  2823.       begin
  2824.       if ptrFeedDescriptions^.ACHOintoWSCsNDF then
  2825.        SolsNDF:=SolsNDF+HourlyPotentialIntake*ptrFeedDescriptions^.GrazingFeed.C1sNDF
  2826.       else SolsNDF:=0;
  2827.       end;
  2828.      SolCP[count]:=SolCP[count]+HourlyPotentialIntake*ptrFeedDescriptions^.GrazingFeed.P1;
  2829.      Ash:=Ash+HourlyPotentialIntake*ptrFeedDescriptions^.GrazingFeed.Mins;
  2830.      Oil:=Oil+HourlyPotentialIntake*ptrFeedDescriptions^.GrazingFeed.EE;
  2831.      ConsumedVFA:=ConsumedVFA+HourlyPotentialIntake*ptrFeedDescriptions^.GrazingFeed.fVFA;
  2832.      Lactate:=Lactate+HourlyPotentialIntake*ptrFeedDescriptions^.GrazingFeed.fLactic;
  2833.      ConsumedLactate:=ConsumedLactate+HI*ptrFeedDescriptions^.GrazingFeed.fLactic;
  2834.      ConsumedNH3:=ConsumedNH3+HourlyPotentialIntake*ptrFeedDescriptions^.GrazingFeed.fNH3;
  2835.      AcidEaten:=AcidEaten+HourlyPotentialIntake*ptrFeedDescriptions^.GrazingFeed.PpnAcid;
  2836.      BicarbonateEaten:=BicarbonateEaten+HourlyPotentialIntake
  2837.                         *ptrFeedDescriptions^.GrazingFeed.HCO3*Thousand/MWNaHCO3;
  2838.      HourlyActualIntake[count]:=HourlyPotentialIntake;
  2839.      GrassDailyIntake:=GrassDailyIntake+HourlyPotentialIntake;
  2840.      FeedWater:=FeedWater+HourlyPotentialIntake*10*(100-ptrFeedDescriptions^.GrazingFeed.DM);
  2841.      end
  2842.     else if not ParlourTMR then//if (ptrFeedDescriptions^.TMR) then
  2843.      begin
  2844.      if (ptrFeedDescriptions^.cFix) and (Days1toEnd>4) then
  2845.       begin
  2846.       DaysIntake:=DaysIntake+HourlyPotentialIntake;
  2847.       if DaysIntake>ptrFeedDescriptions^.Fixed then
  2848.        if DaysIntake-ptrFeedDescriptions^.Fixed<HourlyPotentialIntake then
  2849.         begin
  2850.         HourlyPotentialIntake:=ptrFeedDescriptions^.Fixed-(DaysIntake-HourlyPotentialIntake);
  2851.         end
  2852.        else
  2853.         begin
  2854.         HourlyPotentialIntake:=0;
  2855.         end;
  2856.       end;
  2857.      ParlourRobot:=False;
  2858.      for loopi:=0 to ptrFeedDescriptions^.iNoFeeds-1 do   //
  2859.       begin
  2860.       HI:=HourlyPotentialIntake*ptrAmount^[ptrFeedDescriptions^.iNoFeeds*(ptrFeedDescriptions^.Diet-1)+loopi];
  2861.       LagUrea[loopi]:=LagUrea[loopi]+HI
  2862.                             *ptrFeedDescriptions^.TMRFeed[loopi].UreaProtected;
  2863.       LagUreaToEnter[loopi,Hours1to24]:=HI*ptrFeedDescriptions^.TMRFeed[loopi].UreaProtected;
  2864.       if LagUreaToEnter[loopi,Hours1to24]>0 then
  2865.        LagUreaEntryTime[loopi,Hours1to24]:=ElapsedTime
  2866.                                                 +ptrFeedDescriptions^.TMRFeed[loopi].UreaTimeLag;
  2867.       LagSGlycerol[loopi]:=LagSGlycerol[loopi]+HI
  2868.                             *ptrFeedDescriptions^.TMRFeed[loopi].SlowGlycerol;
  2869.       LagSGlycerolToEnter[loopi,Hours1to24]:=HI*ptrFeedDescriptions^.TMRFeed[loopi].SlowGlycerol;
  2870.       if LagSGlycerolToEnter[loopi,Hours1to24]>0 then
  2871.        LagSGlycerolEntryTime[loopi,Hours1to24]:=ElapsedTime
  2872.                                                 +ptrFeedDescriptions^.TMRFeed[loopi].SlowGlycerolLag;
  2873.       LagNDF[loopi]:=LagNDF[loopi]+HI*ptrFeedDescriptions^.TMRFeed[loopi].fermNDF
  2874.                           +HI*ptrFeedDescriptions^.TMRFeed[loopi].unfermNDF;
  2875.       LagfNDFToEnter[loopi,Hours1to24]:=HI*ptrFeedDescriptions^.TMRFeed[loopi].fermNDF;
  2876.       LagiNDFToEnter[loopi,Hours1to24]:=HI*ptrFeedDescriptions^.TMRFeed[loopi].unfermNDF;
  2877.       if (LagfNDFToEnter[loopi,Hours1to24]>0) or (LagiNDFToEnter[loopi,Hours1to24]>0) then
  2878.         LagNDFEntryTime[loopi,Hours1to24]:=ElapsedTime+ptrFeedDescriptions^.TMRFeed[loopi].Lag{+4};
  2879.       LagSStarch[loopi]:=LagSStarch[loopi]+HI*ptrFeedDescriptions^.TMRFeed[loopi].SlowStarch
  2880.                           +HI*ptrFeedDescriptions^.TMRFeed[loopi].UndegSStarch;
  2881.       LagSStarchToEnter[loopi,Hours1to24]:=HI*ptrFeedDescriptions^.TMRFeed[loopi].SlowStarch;
  2882.       LagUSStarchToEnter[loopi,Hours1to24]:=HI*ptrFeedDescriptions^.TMRFeed[loopi].UndegSStarch;
  2883.       if (LagSStarchToEnter[loopi,Hours1to24]>0) or (LagUSStarchToEnter[loopi,Hours1to24]>0) then
  2884.         LagSStarchEntryTime[loopi,Hours1to24]:=ElapsedTime+ptrFeedDescriptions^.TMRFeed[loopi].StarchLag{+4};
  2885.       QStarch[loopi]:=QStarch[loopi]+HI*ptrFeedDescriptions^.TMRFeed[loopi].QuickStarch;
  2886.       UQStarch[loopi]:=UQStarch[loopi]+HI*ptrFeedDescriptions^.TMRFeed[loopi].UndegQStarch;
  2887.       LagCP[loopi]:=LagCP[loopi]+HI*ptrFeedDescriptions^.TMRFeed[loopi].P2
  2888.                           +HI*ptrFeedDescriptions^.TMRFeed[loopi].P3;
  2889.       LagDegCPToEnter[loopi,Hours1to24]:=HI*ptrFeedDescriptions^.TMRFeed[loopi].P2;
  2890.       LagiDegCPToEnter[loopi,Hours1to24]:=HI*ptrFeedDescriptions^.TMRFeed[loopi].P3;
  2891.       if (LagDegCPToEnter[loopi,Hours1to24]>0) or (LagiDegCPToEnter[loopi,Hours1to24]>0) then
  2892.         LagCPEntryTime[loopi,Hours1to24]:=ElapsedTime+ptrFeedDescriptions^.TMRFeed[loopi].NLag;
  2893.       SolCHO:=SolCHO+HI*ptrFeedDescriptions^.TMRFeed[loopi].C1;
  2894.       MonoPG_Glycerol:=MonoPG_Glycerol+HI*ptrFeedDescriptions^.TMRFeed[loopi].MPG;
  2895.       Glycerol:=Glycerol+HI*ptrFeedDescriptions^.TMRFeed[loopi].Glycerol;
  2896.       UnfermentedGlycerolSmall:=UnfermentedGlycerolSmall
  2897.                     +HI*ptrFeedDescriptions^.TMRFeed[loopi].UnfermentedGlycerol;
  2898.       if ptrFeedDescriptions^.Pectins then
  2899.        begin
  2900.        SolsNDF:=0;
  2901.        PectinPS[loopi]:=PectinPS[loopi]+HI
  2902.                        *ptrFeedDescriptions^.TMRFeed[loopi].C1sNDF
  2903.        end
  2904.       else
  2905.        begin
  2906.        if ptrFeedDescriptions^.ACHOintoWSCsNDF then
  2907.        SolsNDF:=SolsNDF+HI*ptrFeedDescriptions^.TMRFeed[loopi].C1sNDF
  2908.        else SolsNDF:=0;
  2909.        end;
  2910.       SolCP[loopi]:=SolCP[loopi]+HI*ptrFeedDescriptions^.TMRFeed[loopi].P1;
  2911.       Ash:=Ash+HI*ptrFeedDescriptions^.TMRFeed[loopi].Mins;
  2912.       Oil:=Oil+HI*ptrFeedDescriptions^.TMRFeed[loopi].EE;
  2913.       ConsumedVFA:=ConsumedVFA+HI*ptrFeedDescriptions^.TMRFeed[loopi].fVFA;
  2914.       Lactate:=Lactate+HI*ptrFeedDescriptions^.TMRFeed[loopi].fLactic;
  2915.       ConsumedLactate:=ConsumedLactate+HI*ptrFeedDescriptions^.TMRFeed[loopi].fLactic;
  2916.       ConsumedNH3:=ConsumedNH3+HI*ptrFeedDescriptions^.TMRFeed[loopi].fNH3;
  2917.       AcidEaten:=AcidEaten+HI*ptrFeedDescriptions^.TMRFeed[loopi].PpnAcid;
  2918.       if not NotAlkapHer then
  2919.        begin
  2920.        AlkabupHaAcidConsumed:=AlkabupHaAcidConsumed
  2921.                               +HI*(ptrFeedDescriptions^.TMRFeed[loopi].fLactic
  2922.                               +ptrFeedDescriptions^.TMRFeed[loopi].fVFA*1.25);
  2923.        end;
  2924.       BicarbonateEaten:=BicarbonateEaten+HI
  2925.                         *ptrFeedDescriptions^.TMRFeed[loopi].HCO3*Thousand/MWNaHCO3;
  2926.       HourlyActualIntake[loopi]:=HI;
  2927.       FeedWater:=FeedWater+HI*10*(100-ptrFeedDescriptions^.TMRFeed[loopi].DM);
  2928. //      if Days1toEnd=ptrFeedDescriptions^.iDaysToRun then
  2929. //       if Hours1to24=3 then
  2930.  
  2931. //             QMP:=QMP;
  2932.       end;
  2933.      end;
  2934.     end;
  2935.    end
  2936.    else
  2937.     begin
  2938.     for loopi:=0 to NumFoods-1 do HourlyActualIntake[loopi]:=0;
  2939.     HourlyPotentialIntake:=0;
  2940.     end;
  2941.  
  2942.  
  2943.    //Drinking water here
  2944.     if BodyWater<Animal.Water then
  2945.      if Hours1to24 in DrinkingTime then
  2946.      begin
  2947.      dWaterDrunk:=Animal.Water-BodyWater;
  2948.      WaterDrunk:=WaterDrunk+dWaterDrunk;
  2949.      end;
  2950.  
  2951.    if not NotAlkapHer then
  2952.     begin
  2953.     if AlkabupHaAcidConsumed>0 then
  2954.      AlkabupHaAcidConsumedPpn:=(AlkabupHaAcidConsumed
  2955.                       -HourlyPotentialIntake*ptrAmount^[ptrFeedDescriptions^.iNoFeeds
  2956.                       *(ptrFeedDescriptions^.Diet-1)+AlkabupHaCounter]*1000)
  2957.                       /AlkabupHaAcidConsumed;
  2958.     if AlkabupHaAcidConsumedPpn<0 then AlkabupHaAcidConsumedPpn:=0;
  2959.     AcidEaten:=AcidEaten*AlkabupHaAcidConsumedPpn;
  2960.     end;
  2961. SumHourlyActualIntake:=0;
  2962.    for loopi:=0 to NumFoods-1 do
  2963.      SumHourlyActualIntake:=SumHourlyActualIntake+HourlyActualIntake[loopi];
  2964.    DMI:=DMI+SumHourlyActualIntake;
  2965.    WWIW:=DMI;
  2966.    TMRDailyIntake:=TMRDailyIntake+SumHourlyActualIntake;
  2967. //      if Days1toEnd>ptrFeedDescriptions^.iDaysToRun-4 then
  2968. //             QMP:=QMP;
  2969. //Saliva is resting, eating and ruminating. If intake is zero, no eating!
  2970.    if SumHourlyActualIntake=0 then
  2971.     EatingSaliva:=0
  2972.    else
  2973.     begin
  2974.     if FSGrazingAll[ptrFeedDescriptions^.Diet] then
  2975.      DMRatio:=0.51 //ptrFeedDescriptions^.GrazingFeed.DM/100
  2976.     else
  2977.      DMRatio:=ptrFeedDescriptions^.TMRDM[ptrFeedDescriptions^.Diet]/
  2978.       ptrFeedDescriptions^.TMRFM[ptrFeedDescriptions^.Diet];
  2979.     if DMRatio<0.2 then
  2980.        EatingSaliva:=0
  2981.     else if DMRatio>0.5 then
  2982.        EatingSaliva:=RestSaliva
  2983.     else
  2984.      begin
  2985.      if TMROnlyGS then
  2986.       begin
  2987.       EatingSaliva:=RestSaliva*(DMRatio-0.2)/0.3;
  2988.       end
  2989.      else
  2990.       begin
  2991.       EatingSaliva:=RestSaliva;
  2992.       end;
  2993.      end;
  2994.     end;
  2995.     if ParlourRobot then
  2996.      EatingSaliva:=RestSaliva;
  2997.     ParlourRobot:=False;
  2998. {//if eating, saliva is zero if active fibre is zero. Otherwise depends on active fibre
  2999.     if ActiveFibreTMR*SumHourlyActualIntake/ptrFeedDescriptions^.MaxIntakePerHour
  3000.      >RestSaliva*StepsPerHour then
  3001.      begin
  3002.      EatingSaliva:=ActiveFibreTMR*SumHourlyActualIntake
  3003.                    /ptrFeedDescriptions^.MaxIntakePerHour/StepsPerHour
  3004.                    *ptrFeedDescriptions^.RVol/100*ForageDMBelow30Ppn-RestSaliva ;
  3005.      if EatingSaliva<RestSaliva then EatingSaliva:=0;  }
  3006.  
  3007. //Anim Sci 2002, 74, 369-382 and Can J Anim Sci 2002, 82, 215-223 say eating time
  3008. //is approx 35 min but I think is linked to AF. Below is a modification that puts the
  3009. //eating time to 25 to 50 minutes depending on AF. This is used in determining
  3010. //the EatingSaliva secretion way up above (line 636). So whereas it was set to 1 hour, it now
  3011. //is set to a time above which it is zero.
  3012.     if SumHourlyActualIntake>0 then
  3013.      begin
  3014.      if LongForage then
  3015.       begin
  3016.       TimeSpentEating:=61;
  3017.       end
  3018.      else
  3019.       begin
  3020.       TimeSpentEating:=8+15+60*(1-SumHourlyActualIntake
  3021.                              /ptrFeedDescriptions^.MaxIntakePerHourAF10);
  3022.       if TimeSpentEating<0 then TimeSpentEating:=60;
  3023.       if TimeSpentEating>60 then TimeSpentEating:=60;
  3024.       end;
  3025.      end
  3026.     else
  3027.      TimeSpentEating:=0;
  3028. //     if Days1toEnd=ptrFeedDescriptions^.iDaysToRun then
  3029. //            QMP:=QMP;
  3030.  {    end
  3031.     else EatingSaliva:=0;   }
  3032.    if (Days1toEnd>(ptrFeedDescriptions^.iDaysToRun-4)) then
  3033.     avDMI:=avDMI+SumHourlyActualIntake;
  3034.    if Days1toEnd>(ptrFeedDescriptions^.iDaysToRun-1) then
  3035.     begin
  3036.     if ptrFeedDescriptions^.iGrazing=1 then avDMIGrazing:=avDMIGrazing
  3037.                              +HourlyActualIntake[ptrFeedDescriptions^.iNoFeeds];
  3038.     for loopi:=0 to NumFoods-1 do
  3039.      DailyIntake[loopi]:=DailyIntake[loopi]+HourlyActualIntake[loopi];
  3040.     end;
  3041.    if Days1toEnd=ptrFeedDescriptions^.iDaysToRun then
  3042.     begin
  3043.      ptrNutAbsorbed^.aNutAbsorbedElement[CowParity,ptrFeedDescriptions^.Week,Hours1to24-1].ThroughTheDaypH:=pH;
  3044.      if UNDFForage[Hours1To24]<0.2 then
  3045.       hourlypH[Hours1to24-1]:=pH-1.6
  3046.      else if UNDFForage[Hours1To24]<0.28 then
  3047.       hourlypH[Hours1to24-1]:=pH+(20*UNDFForage[Hours1To24]-5.6)
  3048.      else
  3049.       begin
  3050.       if Consultant=41 then
  3051.        hourlypH[Hours1to24-1]:=pH+0.1
  3052.       else
  3053.        hourlypH[Hours1to24-1]:=pH;
  3054.       end;
  3055.      hourlyNH3[Hours1to24-1]:=NH3Rum*RNH3*StepsPerHour; //g NH3/total liquid * rate of use for fermentation/h
  3056.      hourlyNH3Total[Hours1to24-1]:=NH3Rum/LiquidVolume/MWNH3*Thousand;
  3057.      hourlyQMicLiquidR[Hours1to24-1]:=QMicLiquidR/TotalRumenVol;
  3058.      hourlyQMicSolidsR[Hours1to24-1]:=QMicSolidsR/TotalRumenVol;
  3059.      hourlyQMicLaUtR[Hours1to24-1]:=QMicLaUtR/TotalRumenVol;
  3060.      hourlyQMicLaR[Hours1to24-1]:=QMicLaR/TotalRumenVol;
  3061.     ptrNutAbsorbed^.aNutAbsorbedElement[CowParity,ptrFeedDescriptions^.Week,Hours1to24-1].
  3062.                  iHr:=Hours1to24;
  3063.     ptrNutAbsorbed^.aNutAbsorbedElement[CowParity,ptrFeedDescriptions^.Week,Hours1to24-1].
  3064.                  TotIntake:=SumHourlyActualIntake;
  3065.     ptrNutAbsorbed^.aNutAbsorbedElement[CowParity,ptrFeedDescriptions^.Week,Hours1to24-1].
  3066.                  CAcR:=CAcR*Thousand;
  3067.     ptrNutAbsorbed^.aNutAbsorbedElement[CowParity,ptrFeedDescriptions^.Week,Hours1to24-1].
  3068.                  CPrR:=CPrR*Thousand;
  3069.     ptrNutAbsorbed^.aNutAbsorbedElement[CowParity,ptrFeedDescriptions^.Week,Hours1to24-1].
  3070.                  CBuR:=CBuR*Thousand;
  3071.     ptrNutAbsorbed^.aNutAbsorbedElement[CowParity,ptrFeedDescriptions^.Week,Hours1to24-1].
  3072.                  CLaR:=CLaR*Thousand;
  3073.     ptrNutAbsorbed^.aNutAbsorbedElement[CowParity,ptrFeedDescriptions^.Week,Hours1to24-1].
  3074.                  QMicR:=QMicLiquidR+QMicSolidsR+QMicLaR+QMicLaUtR;
  3075.     ptrNutAbsorbed^.aNutAbsorbedElement[CowParity,ptrFeedDescriptions^.Week,Hours1to24-1].
  3076.                  RumDM:=RumDM;
  3077.     ptrNutAbsorbed^.aNutAbsorbedElement[CowParity,ptrFeedDescriptions^.Week,Hours1to24-1].
  3078.                  QCHOFerm:=HFSCiR;
  3079.     ptrNutAbsorbed^.aNutAbsorbedElement[CowParity,ptrFeedDescriptions^.Week,Hours1to24-1].
  3080.                  NDFFerm:=HFNiR;
  3081.     ptrNutAbsorbed^.aNutAbsorbedElement[CowParity,ptrFeedDescriptions^.Week,Hours1to24-1].
  3082.                  StarchFerm:=HFSiR;
  3083.     ptrNutAbsorbed^.aNutAbsorbedElement[CowParity,ptrFeedDescriptions^.Week,Hours1to24-1].
  3084.                  SStarchFerm:=HFSSiR;
  3085.     ptrNutAbsorbed^.aNutAbsorbedElement[CowParity,ptrFeedDescriptions^.Week,Hours1to24-1].
  3086.                  QPFerm:=HSCPiR;
  3087.     ptrNutAbsorbed^.aNutAbsorbedElement[CowParity,ptrFeedDescriptions^.Week,Hours1to24-1].
  3088.                  SPFerm:=HDCPiR;
  3089.     ptrNutAbsorbed^.aNutAbsorbedElement[CowParity,ptrFeedDescriptions^.Week,Hours1to24-1].
  3090.                  NH3QFerm:=HFNH3QiR/6.25*MWNH3/MWN;//FreeProteinRatio/tslp;//
  3091.     ptrNutAbsorbed^.aNutAbsorbedElement[CowParity,ptrFeedDescriptions^.Week,Hours1to24-1].
  3092.                  NH3SFerm:=HFNH3SiR/6.25*MWNH3/MWN; //SolidProteinRatio/tslp;//
  3093.     ptrNutAbsorbed^.aNutAbsorbedElement[CowParity,ptrFeedDescriptions^.Week,Hours1to24-1].
  3094.                  hEMNS:=hEMNSh/StepsPerHour;
  3095.     ptrNutAbsorbed^.aNutAbsorbedElement[CowParity,ptrFeedDescriptions^.Week,Hours1to24-1].
  3096.                  PAcR:=PAcR;
  3097.     ptrNutAbsorbed^.aNutAbsorbedElement[CowParity,ptrFeedDescriptions^.Week,Hours1to24-1].
  3098.                  PPrR:=PPrR;
  3099.     ptrNutAbsorbed^.aNutAbsorbedElement[CowParity,ptrFeedDescriptions^.Week,Hours1to24-1].
  3100.                  PBuR:=PBuR;
  3101.     ptrNutAbsorbed^.aNutAbsorbedElement[CowParity,ptrFeedDescriptions^.Week,Hours1to24-1].
  3102.                  PLaR:=PLaR;
  3103.     ptrNutAbsorbed^.aNutAbsorbedElement[CowParity,ptrFeedDescriptions^.Week,Hours1to24-1].
  3104.                   ThroughTheDayAcid:=dAcid/StepsPerHour;
  3105.     ptrNutAbsorbed^.aNutAbsorbedElement[CowParity,ptrFeedDescriptions^.Week,Hours1to24-1].
  3106.                   ThroughTheDayAlkali:=dNaHCO3/StepsPerHour;
  3107.     end;
  3108.    for loopi:=0 to NumFoods-1 do
  3109.     HourlyActualIntake[loopi]:=0;
  3110.    end;//end hourly loop
  3111. //At end of each day calculate TMR intake and adjust long particle breakdown rate
  3112. //accordingly.
  3113.    TMRDailyIntake:=TMRDailyIntake
  3114.                    -rFeedInfo.ParlourPerMeal*ParlourFeeds[rFeedInfo.Parlour]
  3115.                    -rFeedInfo.RoboticPerMeal1*RoboticFeeds[rFeedInfo.Parlour]
  3116.                    -rFeedInfo.RoboticPerMeal2*RoboticFeeds[rFeedInfo.Parlour]
  3117.                    -rFeedInfo.LiquidPerMeal*RoboticFeeds[rFeedInfo.Parlour]
  3118.                    -GrassDailyIntake;
  3119.    if TMRDailyIntake<1 then TMRDailyIntake:=1;
  3120.  
  3121. {   ptrFeedDescriptions^.LongParticleBR:=0.1436*power(CalcLig(rFeedInfo.Diet,TMRDailyIntake),-0.4572)
  3122.                              *power(rFeedInfo.ActualWeight,-0.27)*ForageDMBelow30Ppn;
  3123.    LPBreakdownR:=Power(1+2*ptrFeedDescriptions^.LongParticleBR,1/StepsPerHour)-1;
  3124.    if ChopLength then
  3125.     LPBreakdownR:=LPBreakdownR*0.45*LargeParticleBR  //Langhill rumination time ~570 min=0.3
  3126.    else
  3127.     LPBreakdownR:=LPBreakdownR*0.5*LargeParticleBR;
  3128.  }
  3129.    EEsoFar:=(dQAcR+dQAcHG)*EnergyOfAcetate+(dQPrR+dQPrHG)*EnergyOfPropionate+
  3130.       (dQBuR+dQBuHG)*EnergyOfButyrate{+dQLaR*EnergyOfLacticAcid}+
  3131.       (dSIDigCHO+dSIMicCHO)*EnergyOfCHO+(dAbsOil+dSIMicLip)*EnergyOfOil;
  3132.    EnergyFromKetogenic:=(dQAcR+dQAcHG)*EnergyOfAcetate+(dQBuR+dQBuHG)*EnergyOfButyrate
  3133.                             +(dAbsOil+dSIMicLip)*EnergyOfOil;
  3134.    EnergyFromGlucogenic:=(dQPrR+dQPrHG)*EnergyOfPropionate+
  3135.                              (dSIDigCHO+dSIMicCHO)*EnergyOfCHO;
  3136.    RatioKetogenic:=EnergyFromKetogenic/(EnergyFromKetogenic+EnergyFromGlucogenic);
  3137. //if Days1toEnd=20 then
  3138. //  QMP:=QMP;
  3139.  
  3140.    if Days1toEnd>4 then
  3141.     if MicrobesAcidosis then
  3142.      begin
  3143.      if ChopLength then
  3144.       begin
  3145.       if ptrNutAbsorbed^.RuminationTime*60/StepsPerHour>MaxRuminationTime*MaxRuminationFactor then
  3146.        MaxRum:=True
  3147.       else
  3148.        MaxRum:=False;
  3149.       end
  3150.      else MaxRum:=False;
  3151.      if (MaxRum) and (not DryCow) then
  3152.       begin
  3153.       IncreaseRumenFillUpper:=False;
  3154.       end
  3155.     else if ptrNutAbsorbed^.ProteinPerKG>0 then
  3156.       begin
  3157.       ProteinMilk:=(dMP-ptrNutAbsorbed^.MPReqNotMilk
  3158.                     +ProtFromBody*Thousand)/ptrNutAbsorbed^.ProteinPerKG;
  3159.       if ProteinMilk>ptrNutAbsorbed^.PotentialMilk[CowParity,
  3160.             ptrFeedDescriptions^.Week] then
  3161.        begin
  3162.        XSProtein:=ProteinMilk-ptrNutAbsorbed^.PotentialMilk[CowParity,
  3163.                   ptrFeedDescriptions^.Week];
  3164.        ProteinMilk:=ptrNutAbsorbed^.PotentialMilk[CowParity,
  3165.                   ptrFeedDescriptions^.Week]*1.01;
  3166.        end
  3167.       else
  3168.        begin
  3169.        XSProtein:=0;
  3170.        end;
  3171.       XSProtein:=XSProtein*ptrNutAbsorbed^.ProteinPerKG;
  3172.       ProteinReqMilk:=ProteinMilk;
  3173. //EEsoFar has to include all protein not used for milk * protein to energy
  3174.       EEsoFar:=EEsoFar+(ptrNutAbsorbed^.MPReqNotMilk+XSProtein)*(1/(EfficiencyMPtoAA
  3175.                *EfficiencyAAtoMilkP)-1)*(EnergyOfProtein-EnergyToMakeUrea);
  3176.       EnergyMilk:=(EEsoFar-ptrNutAbsorbed^.EReqNotMilk)/ptrNutAbsorbed^.EnergyPerKG;
  3177.       EnergyReqMilk:=EnergyMilk;
  3178.  
  3179.       if ptrFeedDescriptions^.Week<=Animal.TStar/DaysInWeek then
  3180.        begin
  3181.        Weeks1_12:=True;
  3182.        if ProteinMilk<EnergyMilk then
  3183.         begin
  3184.         ptrNutAbsorbed^.ProteinToEnergy[CowParity,ptrFeedDescriptions^.Week]:=0;
  3185.         if CowParity=2 then  //only 3rd lactation
  3186.          begin
  3187.          if not SingleRun then
  3188.           begin
  3189.           ProtFromBody:=(EnergyMilk-ProteinMilk)*ptrNutAbsorbed^.ProteinPerKG/Thousand;
  3190.           end
  3191.          else
  3192.           begin
  3193.           if ProtFromBody<=0 then
  3194.            begin
  3195.            ProtFromBody:=MaxProtFromBody*0.2;
  3196.            end
  3197.           else
  3198.            begin
  3199.            ProtFromBody:=ProtFromBody*1.15;
  3200.            end;
  3201. {**}      ProtFromBody:=0;
  3202.           end;
  3203.          if ProtFromBody>MaxProtFromBody/2 then
  3204.           begin
  3205.           ProtFromBody:=MaxProtFromBody/2;
  3206.           end;
  3207.          ptrNutAbsorbed^.ProteinFromBody[ptrFeedDescriptions^.Week]:=
  3208.                                                                ProtFromBody;
  3209.          IncreaseRumenFillUpper:=False;
  3210.          end
  3211.         else
  3212.          begin
  3213.          ptrNutAbsorbed^.ProteinFromBody[ptrFeedDescriptions^.Week]:=0;
  3214.          IncreaseRumenFillUpper:=False;
  3215.          end;
  3216.         end
  3217.        else //if ProteinMilk>=EnergyMilk
  3218.         begin
  3219.         ProtFromBody:=ProtFromBody*0.85;
  3220.         ptrNutAbsorbed^.ProteinFromBody[ptrFeedDescriptions^.Week]:=ProtFromBody;
  3221.         if ProteinMilk>=ptrNutAbsorbed^.PotentialMilk[CowParity,
  3222.             ptrFeedDescriptions^.Week] then
  3223.          begin
  3224.          if EnergyMilk<ptrNutAbsorbed^.PotentialMilk[CowParity,
  3225.             ptrFeedDescriptions^.Week] then
  3226.           begin
  3227.           IncreaseRumenFillUpper:=True;
  3228.           end
  3229.          else
  3230.           begin
  3231.           IncreaseRumenFillUpper:=False;
  3232.           end;
  3233.          end
  3234.         else
  3235.          begin
  3236.          IncreaseRumenFillUpper:=True;
  3237.          end;
  3238.         end;
  3239.        end
  3240.       else //if ptrFeedDescriptions^.Week>Animal.TStar/DaysInWeek then
  3241.        begin
  3242.        if ProteinMilk<EnergyMilk then
  3243.         begin
  3244.         ptrNutAbsorbed^.ProteinToEnergy[CowParity,ptrFeedDescriptions^.Week]:=0;
  3245.         //put on body fat here
  3246.         ptrNutAbsorbed^.ProteinFromBody[ptrFeedDescriptions^.Week]:=0;
  3247.         if ProteinMilk>=ptrNutAbsorbed^.PotentialMilk[CowParity,
  3248.             ptrFeedDescriptions^.Week] then
  3249.          IncreaseRumenFillUpper:=False
  3250.         else
  3251.          IncreaseRumenFillUpper:=True;
  3252.         end
  3253.        else //if ProteinMilk>=EnergyMilk
  3254.         begin
  3255.         //put here xsprotein to energy
  3256.         ptrNutAbsorbed^.ProteinFromBody[ptrFeedDescriptions^.Week]:=0;
  3257.         if ProteinMilk>ptrNutAbsorbed^.PotentialMilk[CowParity,
  3258.             ptrFeedDescriptions^.Week] then
  3259.          begin
  3260.          //calculate PotentialMilk-EnergyMilk and work out what protein to energy needed
  3261.          if EnergyMilk<ptrNutAbsorbed^.PotentialMilk[CowParity,
  3262.             ptrFeedDescriptions^.Week] then
  3263.           begin
  3264.           IncreaseRumenFillUpper:=True;
  3265.           end
  3266.          else
  3267.           begin
  3268.           IncreaseRumenFillUpper:=False;
  3269.           end;
  3270.          end
  3271.         else
  3272.          begin
  3273.          IncreaseRumenFillUpper:=True;
  3274.          end;
  3275.         end;
  3276.        end;
  3277.       end
  3278.      else//ptrNutAbsorbed^.ProteinPerKG<=0
  3279.       begin
  3280.       if (Beef) then
  3281.        begin
  3282. //     if Days1toEnd>ptrFeedDescriptions^.iDaysToRun-4 then
  3283. //            QMP:=QMP;
  3284.        ProteinGrowth:=(dMP-ptrNutAbsorbed^.MPReqNotMilk)*RV/Thousand*0.9;
  3285. //       EnergyForProtein:=ProteinGrowth*Thousand*Animal.EEP;
  3286.        if ((dQAcR+dQAcHG)*EnergyOfAcetate+(dQBuR+dQBuHG)*EnergyOfButyrate
  3287.             -MaintenanceEnergy*RatioKetogenic)>0 then
  3288.         LipidGrowth:=(((dQAcR+dQAcHG)*EnergyOfAcetate+
  3289.                     (dQBuR+dQBuHG)*EnergyOfButyrate-MaintenanceEnergy
  3290.                     *RatioKetogenic)/Animal.EELplus+(dAbsOil+dSIMicLip)/Thousand)
  3291.                     +(EnergyFromGlucogenic-MaintenanceEnergy*(1-RatioKetogenic))
  3292.                     /Animal.EELplus
  3293.                     //*Animal.MatureLFEB/Animal.LipidFreeEmptyBody
  3294.        else
  3295.         LipidGrowth:=0;
  3296.        if (ProteinGrowth>Animal.MaxProtein) and (LipidGrowth>Animal.MaxLipid*1.0) then
  3297.         IncreaseRumenFillUpper:=False //True//
  3298.        else if LipidGrowth>Animal.MaxLipid*1.1 then
  3299.         IncreaseRumenFillUpper:=False
  3300.        else
  3301.         IncreaseRumenFillUpper:=True;
  3302.        end
  3303.       else
  3304.        begin
  3305.        if DryCow then
  3306.         begin
  3307.         if dMP>ptrNutAbsorbed^.MPReqNotMilk*1.5 then
  3308.          IncreaseRumenFillUpper:=False
  3309.         else
  3310.          IncreaseRumenFillUpper:=True;
  3311.         end
  3312.        else
  3313.         IncreaseRumenFillUpper:=True;
  3314.        end;
  3315.       end;
  3316.     if (not IncreaseRumenFillUpper) or (pH<5.5) then
  3317.       begin
  3318.       if (MaxRum) and (not DryCow) then
  3319.         ptrFeedDescriptions^.RumFillUpper:=ptrFeedDescriptions^.RumFillUpper*MaxRuminationTime/(ptrNutAbsorbed^.RuminationTime*60/StepsPerHour) //MaxLongParticles?LongParticles
  3320.       else      if (SingleRun) and (ptrNutAbsorbed^.PotentialMilk[CowParity,
  3321.             ptrFeedDescriptions^.Week]>0) then
  3322.        begin
  3323.        if (EnergyMilk/ptrNutAbsorbed^.PotentialMilk[CowParity,
  3324.             ptrFeedDescriptions^.Week]>1.15) and (not Weeks1_12) then
  3325.         ptrFeedDescriptions^.RumFillUpper:=ptrFeedDescriptions^.RumFillUpper*0.9
  3326.        else if (SingleRun) and (Weeks1_12) then
  3327.         ptrFeedDescriptions^.RumFillUpper:=ptrFeedDescriptions^.RumFillUpper*0.97
  3328.        else
  3329.         ptrFeedDescriptions^.RumFillUpper:=ptrFeedDescriptions^.RumFillUpper*0.98;
  3330.        end
  3331.       else
  3332.        begin
  3333.        if Beef then
  3334.         begin
  3335.         if ProteinGrowth/Animal.MaxProtein>1.15 then
  3336.          begin
  3337.          ptrFeedDescriptions^.RumFillUpper:=ptrFeedDescriptions^.RumFillUpper*0.96;
  3338.          end
  3339.         else
  3340.          begin
  3341.          ptrFeedDescriptions^.RumFillUpper:=ptrFeedDescriptions^.RumFillUpper*0.99;
  3342.          end;
  3343.         end
  3344.        else
  3345.         begin
  3346.         if DryCow then
  3347.          ptrFeedDescriptions^.RumFillUpper:=ptrFeedDescriptions^.RumFillUpper*0.975
  3348.         else
  3349.          ptrFeedDescriptions^.RumFillUpper:=ptrFeedDescriptions^.RumFillUpper*0.99;//0.975
  3350.         end;
  3351.        end;
  3352.       ptrFeedDescriptions^.RumSA:=251360*power(ptrFeedDescriptions^.RumFillUpper*ptrFeedDescriptions^.RVol/4189.333,0.667);// 'cm2
  3353.       end
  3354.      else {if EEsoFar<ptrFeedDescriptions.EReq then}
  3355.       begin
  3356.       if (Beef) and (ptrFeedDescriptions^.RumFillUpper<1.15) then
  3357.        begin
  3358.        ptrFeedDescriptions^.RumFillUpper:=ptrFeedDescriptions^.RumFillUpper*1.02;
  3359.        ptrFeedDescriptions^.RumSA:=251360*power(ptrFeedDescriptions^.RumFillUpper*ptrFeedDescriptions^.RVol/4189.333,0.667);// 'cm2
  3360.        end
  3361.       else if (ptrFeedDescriptions^.RumFillUpper<1.15) and
  3362.          (not ptrFeedDescriptions^.FourOrFive) then
  3363.        begin
  3364.        if (EEsoFar/ptrFeedDescriptions.EReq<0.85) and (ptrFeedDescriptions^.RumFillUpper<0.92)
  3365.         and (not ChopLength) then
  3366.         ptrFeedDescriptions^.RumFillUpper:=ptrFeedDescriptions^.RumFillUpper*1.1
  3367.        else ptrFeedDescriptions^.RumFillUpper:=ptrFeedDescriptions^.RumFillUpper*1.01;
  3368.        ptrFeedDescriptions^.RumSA:=251360*power(ptrFeedDescriptions^.RumFillUpper*ptrFeedDescriptions^.RVol/4189.333,0.667);// 'cm2
  3369.        end
  3370.       else if (ptrFeedDescriptions^.RumFillUpper<1.15) then
  3371.        begin
  3372.        ptrFeedDescriptions^.RumFillUpper:=ptrFeedDescriptions^.RumFillUpper*1.02;
  3373.        end;
  3374.       end;
  3375.      end
  3376.     else
  3377.      begin
  3378.      end;  //if MicrobesAcidosis
  3379.  inc(WhyWontItWork);
  3380.  end;//end daily loop
  3381. ptrNutAbsorbed^.TotalLongNDF:=0;ptrNutAbsorbed^.TotalNDF:=0;
  3382. ptrNutAbsorbed^.uLongNDF:=0;ptrNutAbsorbed^.TotaluNDF:=0;ptrNutAbsorbed^.iNDFForage:=0;
  3383. ptrNutAbsorbed^.TotalNDFForage:=0;
  3384. {for loopi:=0 to NumFoods-1 do
  3385.  begin
  3386.  ptrNutAbsorbed^.TotalLongNDF:=ptrNutAbsorbed^.TotalLongNDF+iNDFLong[loopi]+fNDFLong[loopi];
  3387.  ptrNutAbsorbed^.TotalNDF:=ptrNutAbsorbed^.TotalNDF+iNDFLong[loopi]+fNDFLong[loopi]+iNDF[loopi]+fNDF[loopi];
  3388.  ptrNutAbsorbed^.uLongNDF:=ptrNutAbsorbed^.uLongNDF+iNDFLong[loopi];
  3389.  ptrNutAbsorbed^.TotaluNDF:=ptrNutAbsorbed^.TotaluNDF+iNDFLong[loopi]+iNDF[loopi];
  3390.  if loopi<ptrFeedDescriptions^.iNoFeeds then
  3391.   begin
  3392.   if ptrFeedDescriptions^.TMRFeed[loopi].ForOrConc then
  3393.    begin
  3394.    ptrNutAbsorbed^.iNDFForage:=ptrNutAbsorbed^.iNDFForage+iNDFLong[loopi]+iNDF[loopi];
  3395.    ptrNutAbsorbed^.TotalNDFForage:=ptrNutAbsorbed^.TotalNDFForage+iNDFLong[loopi]
  3396.                                    +iNDF[loopi]+fNDFLong[loopi]+fNDF[loopi];
  3397.    end;
  3398.   end
  3399.  else if loopi=ptrFeedDescriptions^.iNoFeeds-1+ptrFeedDescriptions^.iGrazing then
  3400.   begin
  3401.   if ptrFeedDescriptions^.GrazingFeed.ForOrConc then
  3402.    begin
  3403.    ptrNutAbsorbed^.iNDFForage:=ptrNutAbsorbed^.iNDFForage+iNDFLong[loopi]+iNDF[loopi];
  3404.    ptrNutAbsorbed^.TotalNDFForage:=ptrNutAbsorbed^.TotalNDFForage+iNDFLong[loopi]
  3405.                                    +iNDF[loopi]+fNDFLong[loopi]+fNDF[loopi];
  3406.    end;
  3407.   end
  3408.  else if loopi>ptrFeedDescriptions^.iNoFeeds-1+ptrFeedDescriptions^.iGrazing then
  3409.   begin
  3410.    if ptrFeedDescriptions^.ParlourFeed[loopi-1-(ptrFeedDescriptions^.iNoFeeds-1+ptrFeedDescriptions^.iGrazing)].ForOrConc then
  3411.    begin
  3412.    ptrNutAbsorbed^.iNDFForage:=ptrNutAbsorbed^.iNDFForage+iNDFLong[loopi]+iNDF[loopi];
  3413.    ptrNutAbsorbed^.TotalNDFForage:=ptrNutAbsorbed^.TotalNDFForage+iNDFLong[loopi]
  3414.                                    +iNDF[loopi]+fNDFLong[loopi]+fNDF[loopi];
  3415.    end;
  3416.   end;
  3417.  end; }
  3418. for loopi := 1 to 24 do
  3419.  begin
  3420.  ptrNutAbsorbed^.uLongNDF:=ptrNutAbsorbed^.uLongNDF+ULongNDFForage[loopi];
  3421.  ptrNutAbsorbed^.TotalLongNDF:=ptrNutAbsorbed^.TotalLongNDF+TLongNDFForage[loopi];
  3422.  ptrNutAbsorbed^.iNDFForage:=ptrNutAbsorbed^.iNDFForage+UNDFForage[loopi];
  3423.  ptrNutAbsorbed^.TotalNDFForage:=ptrNutAbsorbed^.TotalNDFForage+TNDFForage[loopi]
  3424.  end;
  3425. ptrNutAbsorbed^.RuminationTime:=Round(60/StepsPerHour*ptrNutAbsorbed^.RuminationTime);
  3426. ptrNutAbsorbed^.uLongNDF:=ptrNutAbsorbed^.uLongNDF/24;
  3427. ptrNutAbsorbed^.iNDFForage:=ptrNutAbsorbed^.iNDFForage/24;
  3428. ptrNutAbsorbed^.TotalLongNDF:=ptrNutAbsorbed^.TotalLongNDF/24;
  3429. //ptrNutAbsorbed^.TotalNDF:=ptrNutAbsorbed^.TotalNDF/RumDM;
  3430. ptrNutAbsorbed^.TotalNDFForage:=ptrNutAbsorbed^.TotalNDFForage/24;
  3431. //ptrNutAbsorbed^.LongNDFtoTotalNDF:=ptrNutAbsorbed^.TotalLongNDF/ptrNutAbsorbed^.TotalNDF;
  3432. //if ptrFeedDescriptions^.CFix then
  3433. AvDMI:=AvDMI/4;
  3434. ptrNutAbsorbed^.DMI[CowParity,ptrFeedDescriptions^.Week]:=AvDMI;
  3435. TMRIntakeZaoying:=AvDMI;
  3436. ptrNutAbsorbed^.GrazingDMI[CowParity,ptrFeedDescriptions^.Week]:=AvDMIGrazing;
  3437. for loopi:=0 to NumFoods-1 do
  3438.  DailyIntake[loopi]:=DailyIntake[loopi];
  3439. ptrNutAbsorbed^.MP[CowParity,ptrFeedDescriptions^.Week]:=QMP;
  3440. ptrNutAbsorbed^.MTP[CowParity,ptrFeedDescriptions^.Week]:=QMTP;
  3441. ptrNutAbsorbed^.DUP[CowParity,ptrFeedDescriptions^.Week]:=QDUP;
  3442. ptrNutAbsorbed^.Ac[CowParity,ptrFeedDescriptions^.Week]:=QAc;
  3443. ptrNutAbsorbed^.Pr[CowParity,ptrFeedDescriptions^.Week]:=QPr;
  3444. ptrNutAbsorbed^.Bu[CowParity,ptrFeedDescriptions^.Week]:=QBu;
  3445. ptrNutAbsorbed^.FDM[CowParity,ptrFeedDescriptions^.Week]:=FDM/ptrFeedDescriptions^.iDaysToRun/1000;
  3446. ptrNutAbsorbed^.CHO[CowParity,ptrFeedDescriptions^.Week]:=QCHO;
  3447. ptrNutAbsorbed^.AbsOil[CowParity,ptrFeedDescriptions^.Week]:=AbsOil/ptrFeedDescriptions^.iDaysToRun;
  3448. ptrNutAbsorbed^.CH4[CowParity,ptrFeedDescriptions^.Week]:=QCH4R+QCH4HG;
  3449. ptrNutAbsorbed^.FaecalN[CowParity,ptrFeedDescriptions^.Week]:=FaecalN;
  3450. ptrNutAbsorbed^.FaecalfNDF[CowParity,ptrFeedDescriptions^.Week]:=FaecalfNDF/ptrFeedDescriptions^.iDaysToRun;
  3451. ptrNutAbsorbed^.FaecaliNDF[CowParity,ptrFeedDescriptions^.Week]:=FaecaliNDF/ptrFeedDescriptions^.iDaysToRun;
  3452. ptrNutAbsorbed^.UrinaryN[CowParity,ptrFeedDescriptions^.Week]:=UrinaryN;
  3453. ptrNutAbsorbed^.TotMicLip[CowParity,ptrFeedDescriptions^.Week]:=SIMicCHO;
  3454. ptrNutAbsorbed^.TotMicCHO[CowParity,ptrFeedDescriptions^.Week]:=SIMicLip;
  3455. ptrNutAbsorbed^.pHLim[CowParity,ptrFeedDescriptions^.Week]:=Round(pHLim*100/(HoursInDay*StepsPerHour));
  3456. ptrNutAbsorbed^.EMNS[CowParity,ptrFeedDescriptions^.Week]:=EMNS/(HoursInDay*StepsPerHour);
  3457. ptrNutAbsorbed^.Saliva[CowParity,ptrFeedDescriptions^.Week]:=DailyFlowSaliva;
  3458. Animal.PredictedGutFill:=TotalRumenVol/(rFeedInfo.ActualWeight*JerseyOpt);
  3459. end;
  3460.  
  3461. end.
  3462.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement