root / UFBesLactE.pas
Historique | Voir | Annoter | Télécharger (12,246 ko)
1 |
unit UFBesLactE ;
|
---|---|
2 |
|
3 |
interface
|
4 |
|
5 |
uses
|
6 |
Windows, Forms, Classes, Controls, StdCtrls, Buttons, UVariables; |
7 |
|
8 |
type
|
9 |
TFBesLactE = class(TForm)
|
10 |
GBProfil: TGroupBox; |
11 |
CBProfil: TComboBox; |
12 |
GBResult: TGroupBox; |
13 |
BBRapLact: TBitBtn; |
14 |
BBResLact: TBitBtn; |
15 |
procedure FormClose(Sender: TObject; var Action: TCloseAction); |
16 |
procedure FormActivate(Sender: TObject);
|
17 |
procedure CBProfilChange(Sender: TObject);
|
18 |
procedure BBResLactClick(Sender: TObject);
|
19 |
procedure BBRapLactClick(Sender: TObject);
|
20 |
procedure FormCreate(Sender: TObject);
|
21 |
procedure FormShow(Sender: TObject);
|
22 |
private
|
23 |
{ D?clarations priv?es }
|
24 |
Update, Modal: boolean; |
25 |
procedure CalcApport;
|
26 |
procedure CalcResult;
|
27 |
public
|
28 |
{ D?clarations publiques }
|
29 |
AppAliTot, AppEDTot, AppEMTot, AppENTot: array[1..NB_CYCLES] of double; |
30 |
BesEMTot, BesEMEntTot, BesEMLaitTot: array[1..NB_CYCLES] of double; |
31 |
AppAli, AppED, AppEM, AppEN: array[1..NB_CYCLES, 1..28] of double; |
32 |
BesEMEnt, BesEMLait, BesP, BesCa: array[1..NB_CYCLES, 1..28] of double; |
33 |
AppAA, BesAA, BesAAEnt, BesAALait: array[1..NB_CYCLES, 1..14, 1..28] of double; |
34 |
end;
|
35 |
|
36 |
var
|
37 |
FBesLactE: TFBesLactE; |
38 |
|
39 |
implementation
|
40 |
|
41 |
uses
|
42 |
Math, gnugettext, UInit, UFindRec, UCalcul, UFResBesLactE, UFRapBesLactE; |
43 |
|
44 |
{$R *.dfm}
|
45 |
|
46 |
{ TFBesLactE }
|
47 |
|
48 |
procedure TFBesLactE.FormCreate(Sender: TObject);
|
49 |
begin
|
50 |
if Screen.Fonts.IndexOf('Arial Unicode MS') <> -1 |
51 |
then
|
52 |
Font.Name := 'Arial Unicode MS';
|
53 |
TranslateComponent(Self); |
54 |
Constraints.MinWidth := 296 + (Width - ClientWidth);
|
55 |
Width := Constraints.MinWidth; |
56 |
Constraints.MaxWidth := Constraints.MinWidth; |
57 |
Constraints.MinHeight := 112 + (Height - ClientHeight);
|
58 |
Height := Constraints.MinHeight; |
59 |
Constraints.MaxHeight := Constraints.MinHeight; |
60 |
end;
|
61 |
|
62 |
procedure TFBesLactE.FormShow(Sender: TObject);
|
63 |
begin
|
64 |
Modal := False; |
65 |
end;
|
66 |
|
67 |
procedure TFBesLactE.FormClose(Sender: TObject; var Action: TCloseAction); |
68 |
begin
|
69 |
Action := caFree; |
70 |
NumWinBesLactE := -1;
|
71 |
end;
|
72 |
|
73 |
procedure TFBesLactE.FormActivate(Sender: TObject);
|
74 |
begin
|
75 |
if not Modal |
76 |
then
|
77 |
StringsProfilT(CBProfil.Items, False); |
78 |
end;
|
79 |
|
80 |
procedure TFBesLactE.CBProfilChange(Sender: TObject);
|
81 |
begin
|
82 |
if CBProfil.ItemIndex = -1 |
83 |
then
|
84 |
CBProfil.Hint := ''
|
85 |
else
|
86 |
begin
|
87 |
PProfilT := ListProfilT[FindIdxProfilT (CBProfil.Text)] ; |
88 |
CBProfil.Hint := PProfilT.Memo ; |
89 |
Update := TRUE ; |
90 |
CalcApport ; |
91 |
CalcResult ; |
92 |
Update := FALSE ; |
93 |
BBResLact.Enabled := TRUE ; |
94 |
BBRapLact.Enabled := TRUE ; |
95 |
end ;
|
96 |
end;
|
97 |
|
98 |
procedure TFBesLactE.CalcApport ;
|
99 |
var
|
100 |
i, Cycle, Jour, AA, Unite : integer ; |
101 |
PctAli1, PctAli2, Quantite, Ingere, IngSec1, IngSec2 : double ; |
102 |
NumRuleSeqAli, NumRuleRation : integer ; |
103 |
RuleSeqAli : array[1..MAX_RULE] of RecRuleSeqAliT ; |
104 |
RuleRation : array[1..MAX_RULE] of RecRuleRationT ; |
105 |
RuleSeqAliInit, RuleRationInit, Ecart : integer ; |
106 |
RecCC1, RecCC2 : CompositionChimique ; |
107 |
TabAAtotal1, TabAAtotal2, TabCUDAA1, TabCUDAA2 : array[0..12] of double ; |
108 |
ok : boolean ; |
109 |
begin
|
110 |
for Cycle := 1 to NB_CYCLES do |
111 |
begin
|
112 |
PSeqAliT := ListSeqAliT[FindIdxSeqAliT (FindNomSeqAliT (PProfilT.SeqAli))] ; |
113 |
for i := 1 to PSeqAliT.NbRuleLact do |
114 |
RuleSeqAli[i] := PSeqAliT.RuleLact[i] ; |
115 |
NumRuleSeqAli := 1 ;
|
116 |
RuleSeqAliInit := 1 ;
|
117 |
with RuleRation[1] do |
118 |
begin
|
119 |
ModeFin := -1 ;
|
120 |
Equation := 3 ; // Curvilin?aire |
121 |
a := PProfilT.Lact[Cycle] / 2 ; // Initial |
122 |
c := PProfilT.Lact[Cycle] ; // Moyenne
|
123 |
d := PProfilT.DureeLact ; // Dur?e
|
124 |
end ;
|
125 |
Unite := PProfilT.Unite ; |
126 |
NumRuleRation := 1 ;
|
127 |
RuleRationInit := 1 ;
|
128 |
// Boucle des jours
|
129 |
for Jour := 1 to PProfilT.DureeLact do |
130 |
begin
|
131 |
// Aliment(s) distribu?(s)
|
132 |
repeat
|
133 |
ok := TRUE ; |
134 |
with RuleSeqAli[NumRuleSeqAli] do |
135 |
if ModeFin = 0 |
136 |
then // Dur?e |
137 |
if (Jour - RuleSeqAliInit + 1 > ValFin) then ok := FALSE ; |
138 |
if not (ok) |
139 |
then // Changement de r?gle |
140 |
begin
|
141 |
Inc (NumRuleSeqAli) ; |
142 |
RuleSeqAliInit := Jour ; |
143 |
end ;
|
144 |
until ok ;
|
145 |
with RuleSeqAli[NumRuleSeqAli] do |
146 |
begin
|
147 |
// Composition aliment 1
|
148 |
if NumAli1 = -1 |
149 |
then
|
150 |
begin
|
151 |
RecCC1 := CCVide ; |
152 |
for i := 0 to 12 do |
153 |
TabAAtotal1[i] := 0 ;
|
154 |
for i := 0 to 12 do |
155 |
TabCUDAA1[i] := 0 ;
|
156 |
end
|
157 |
else
|
158 |
begin
|
159 |
PAliment := ListAliment[FindIdxAliment (FindNomAliment (NumAli1))] ; |
160 |
RecCC1 := PAliment.CC ; |
161 |
for i := 0 to 12 do |
162 |
TabAAtotal1[i] := PAliment.AAtotal[i] ; |
163 |
for i := 0 to 12 do |
164 |
TabCUDAA1[i] := PAliment.CUDAA[i] ; |
165 |
end ;
|
166 |
// Composition aliment 2
|
167 |
if NumAli2 = -1 |
168 |
then
|
169 |
begin
|
170 |
RecCC2 := CCVide ; |
171 |
for i := 0 to 12 do |
172 |
TabAAtotal2[i] := 0 ;
|
173 |
for i := 0 to 12 do |
174 |
TabCUDAA2[i] := 0 ;
|
175 |
end
|
176 |
else
|
177 |
begin
|
178 |
PAliment := ListAliment[FindIdxAliment (FindNomAliment (NumAli2))] ; |
179 |
RecCC2 := PAliment.CC ; |
180 |
for i := 0 to 12 do |
181 |
TabAAtotal2[i] := PAliment.AAtotal[i] ; |
182 |
for i := 0 to 12 do |
183 |
TabCUDAA2[i] := PAliment.CUDAA[i] ; |
184 |
end ;
|
185 |
// Calcul des % aliments
|
186 |
if PctAli1Init = PctAli1Fin
|
187 |
then
|
188 |
PctAli1 := PctAli1Init |
189 |
else // Transition |
190 |
begin
|
191 |
Ecart := PctAli1Fin - PctAli1Init ; |
192 |
if ModeFin = 0 |
193 |
then // Dur?e |
194 |
PctAli1 := PctAli1Init + (Jour - RuleSeqAliInit) * Ecart / ValFin |
195 |
else // Fin |
196 |
PctAli1 := PctAli1Init + (Jour - RuleSeqAliInit) * Ecart / (PProfilT.DureeLact - RuleSeqAliInit) ; |
197 |
end ;
|
198 |
end ;
|
199 |
PctAli2 := 100 - PctAli1 ;
|
200 |
// Quantit?(s) distribu?e(s)
|
201 |
repeat
|
202 |
ok := TRUE ; |
203 |
with RuleRation[NumRuleRation] do |
204 |
if ModeFin = 0 |
205 |
then // Dur?e |
206 |
if Jour - RuleRationInit + 1 > ValFin then ok := FALSE ; |
207 |
if not (ok) |
208 |
then // Changement de r?gle |
209 |
begin
|
210 |
Inc (NumRuleRation) ; |
211 |
RuleRationInit := Jour ; |
212 |
end ;
|
213 |
until ok ;
|
214 |
with RuleRation[NumRuleRation] do |
215 |
begin
|
216 |
// Calcul des quantit?s
|
217 |
case Equation of |
218 |
0 : // Constant |
219 |
Quantite := a ; |
220 |
1 : // Lin?aire |
221 |
Quantite := a + b * (Jour - RuleRationInit) ; |
222 |
2 : // Lin?aire-plateau |
223 |
Quantite := LPvaleur (a, b, c, Jour - RuleRationInit + 1, d) ;
|
224 |
3 : // Curvilin?aire |
225 |
Quantite := CLvaleur (a, c, Jour - RuleRationInit + 1, d) ;
|
226 |
else
|
227 |
Quantite := 0 ;
|
228 |
end ;
|
229 |
// Convertion de ED, EM, EN en quantit? si besoin
|
230 |
case Unite of |
231 |
1 : // ED (MJ/j) |
232 |
Ingere := Quantite |
233 |
/ (PctAli1 / 100 * RecCC1.ED_T * RecCC1.MS / 1000 |
234 |
+ PctAli2 / 100 * RecCC2.ED_T * RecCC2.MS / 1000) ; |
235 |
2 : // EM (MJ/j) |
236 |
Ingere := Quantite |
237 |
/ (PctAli1 / 100 * RecCC1.EM_T * RecCC1.MS / 1000 |
238 |
+ PctAli2 / 100 * RecCC2.EM_T * RecCC2.MS / 1000) ; |
239 |
3 : // EN (MJ/j) |
240 |
Ingere := Quantite |
241 |
/ (PctAli1 / 100 * RecCC1.EN_T * RecCC1.MS / 1000 |
242 |
+ PctAli2 / 100 * RecCC2.EN_T * RecCC2.MS / 1000) ; |
243 |
4 : // MS (kg/j) |
244 |
Ingere := Quantite |
245 |
/ (PctAli1 / 100 * RecCC1.MS / 1000 |
246 |
+ PctAli2 / 100 * RecCC2.MS / 1000) ; |
247 |
else // QI (kg/j) |
248 |
Ingere := Quantite ; |
249 |
end ;
|
250 |
end ;
|
251 |
// Aliment ing?r?
|
252 |
AppAli[Cycle, Jour] := Ingere ; |
253 |
IngSec1 := Ingere * PctAli1 / 100 * RecCC1.MS / 1000 ; |
254 |
IngSec2 := Ingere * PctAli2 / 100 * RecCC2.MS / 1000 ; |
255 |
// Energie ing?r?e
|
256 |
AppED[Cycle, Jour] := IngSec1 * RecCC1.ED_T + IngSec2 * RecCC2.ED_T ; |
257 |
AppEM[Cycle, Jour] := IngSec1 * RecCC1.EM_T + IngSec2 * RecCC2.EM_T ; |
258 |
AppEN[Cycle, Jour] := IngSec1 * RecCC1.EN_T + IngSec2 * RecCC2.EN_T ; |
259 |
// Acides amin?s digestibles
|
260 |
for AA := 1 to 12 do |
261 |
AppAA[Cycle, AA, Jour] := IngSec1 * TabAAtotal1[AA] * TabCUDAA1[AA] / 100
|
262 |
+ IngSec2 * TabAAtotal2[AA] * TabCUDAA2[AA] / 100 ;
|
263 |
// met+cys
|
264 |
AppAA[Cycle, 13, Jour] := AppAA[Cycle, 2, Jour] + AppAA[Cycle, 3, Jour] ; |
265 |
// phe+tyr
|
266 |
AppAA[Cycle, 14, Jour] := AppAA[Cycle, 6, Jour] + AppAA[Cycle, 7, Jour] ; |
267 |
end ;
|
268 |
// Totaux
|
269 |
AppAliTot[Cycle] := Sum (Slice (AppAli[Cycle], PProfilT.DureeLact)) ; |
270 |
AppEDTot[Cycle] := Sum (Slice (AppED[Cycle], PProfilT.DureeLact)) ; |
271 |
AppEMTot[Cycle] := Sum (Slice (AppEM[Cycle], PProfilT.DureeLact)) ; |
272 |
AppENTot[Cycle] := Sum (Slice (AppEN[Cycle], PProfilT.DureeLact)) ; |
273 |
end ;
|
274 |
end;
|
275 |
|
276 |
procedure TFBesLactE.CalcResult ;
|
277 |
var
|
278 |
Cycle, Jour, AA : integer ; |
279 |
GMQPort, RA, NRLait : double ; |
280 |
begin
|
281 |
for Cycle := 1 to NB_CYCLES do |
282 |
begin
|
283 |
// GMQ port?e
|
284 |
GMQPort := (PProfilT.Porcelets[Cycle].PdsSev - PProfilT.Porcelets[Cycle].PdsNais) * PProfilT.Porcelets[Cycle].Sevres / PProfilT.DureeLact ; |
285 |
//
|
286 |
// Besoins ?n?rg?tiques
|
287 |
//
|
288 |
// Energie pour l'entretien
|
289 |
BesEMEntTot[Cycle] := Power (PProfilT.Truies[Cycle].PdsApMB, 0.75) * EELact ;
|
290 |
for Jour := 1 to PProfilT.DureeLact do |
291 |
BesEMEnt[Cycle, Jour] := BesEMEntTot[Cycle] ; |
292 |
// Energie pour la production de lait
|
293 |
RA := 0.0000023096 * Power (PProfilT.DureeLact, 4) - 0.00027619 * Power (PProfilT.DureeLact, 3) + 0.012889 * Power (PProfilT.DureeLact, 2) - 0.28116 * PProfilT.DureeLact + 4.799 ; |
294 |
for Jour := 1 to PProfilT.DureeLact do |
295 |
BesEMLait[Cycle, Jour] := (20.6 * GMQPort * 1000 - 376 * PProfilT.Porcelets[Cycle].Sevres) * RA * Exp (-0.025 * Jour) * Exp (-Exp (0.5 - 0.1 * Jour)) / 1000 / KL ; |
296 |
BesEMLaitTot[Cycle] := Mean (Slice (BesEMLait[Cycle], PProfilT.DureeLact)) ; |
297 |
// Besoin total en ?nergie
|
298 |
BesEMTot[Cycle] := BesEMEntTot[Cycle] + BesEMLaitTot[Cycle] ; |
299 |
//
|
300 |
// Besoins en acides amin?s
|
301 |
//
|
302 |
for Jour := 1 to PProfilT.DureeLact do |
303 |
begin
|
304 |
// Production d'azote dans le lait
|
305 |
NRLait := (0.0257 * GMQPort * 1000 + 0.42 * PProfilT.Porcelets[Cycle].Sevres) * RA * Exp (-0.025 * Jour) * Exp (- Exp (0.5 - 0.1 * Jour)) ; |
306 |
// 1) Besoin total
|
307 |
BesAA[Cycle, 1, Jour] := (14.2 + 0.629 * NRLait) / 1.335 ; |
308 |
for AA := 2 to 12 do |
309 |
BesAA[Cycle, AA, Jour] := BesAA[Cycle, 1, Jour] * ProtIdLact[AA] / 100 ; |
310 |
// met+cys
|
311 |
BesAA[Cycle, 13, Jour] := BesAA[Cycle, 1, Jour] * (ProtIdLact[2] + ProtIdLact[3]) / 100 ; |
312 |
// phe+tyr
|
313 |
BesAA[Cycle, 14, Jour] := BesAA[Cycle, 1, Jour] * (ProtIdLact[6] + ProtIdLact[7]) / 100 ; |
314 |
// 2) Besoin d'entretien
|
315 |
BesAAEnt[Cycle, 1, Jour] := Power (PProfilT.Truies[Cycle].PdsApMB, 0.75) * 0.036 ; |
316 |
for AA := 2 to 12 do |
317 |
BesAAEnt[Cycle, AA, Jour] := BesAAEnt[Cycle, 1, Jour] * ProtIdEnt[AA] / 100 ; |
318 |
// met+cys
|
319 |
BesAAEnt[Cycle, 13, Jour] := BesAAEnt[Cycle, 1, Jour] * (ProtIdEnt[2] + ProtIdEnt[3]) / 100 ; |
320 |
// phe+tyr
|
321 |
BesAAEnt[Cycle, 14, Jour] := BesAAEnt[Cycle, 1, Jour] * (ProtIdEnt[6] + ProtIdEnt[7]) / 100 ; |
322 |
// 3) Besoin pour la port?e
|
323 |
for AA := 1 to 14 do |
324 |
BesAALait[Cycle, AA, Jour] := BesAA[Cycle, AA, Jour] - BesAAEnt[Cycle, AA, Jour] ; |
325 |
end ;
|
326 |
//
|
327 |
// Besoins en min?raux
|
328 |
//
|
329 |
for Jour := 1 to PProfilT.DureeLact do |
330 |
begin
|
331 |
// Production d'azote dans le lait
|
332 |
NRLait := (0.0257 * GMQPort * 1000 + 0.42 * PProfilT.Porcelets[Cycle].Sevres) * RA * Exp (-0.025 * Jour) * Exp (- Exp (0.5 - 0.1 * Jour)) ; |
333 |
// Phosphore digestible
|
334 |
BesP[Cycle, Jour] := 10 * PProfilT.Truies[Cycle].PdsApMB / 1000 |
335 |
+ NRLait * 6.38 / 0.050 / 1000 * 1.55 ; |
336 |
// Calcium total
|
337 |
BesCa[Cycle, Jour] := BesP[Cycle, Jour] * 3.2 ;
|
338 |
end ;
|
339 |
end ;
|
340 |
end;
|
341 |
|
342 |
procedure TFBesLactE.BBResLactClick(Sender: TObject);
|
343 |
begin
|
344 |
Modal := True; |
345 |
FResBesLactE := TFResBesLactE.Create (Self) ; |
346 |
FResBesLactE.ShowModal ; |
347 |
FResBesLactE.Release ; |
348 |
Modal := False; |
349 |
end;
|
350 |
|
351 |
procedure TFBesLactE.BBRapLactClick(Sender: TObject);
|
352 |
begin
|
353 |
Modal := True; |
354 |
FRapBesLactE := TFRapBesLactE.Create(Self); |
355 |
FRapBesLactE.QRRapport.PreviewModal ; |
356 |
FRapBesLactE.Release; |
357 |
Modal := False; |
358 |
end;
|
359 |
|
360 |
end.
|