OSDN Git Service

[modified] u_feedingcalc2.pasのStandardDailyWeightGainを訂正
[feedingorigin2/HikakuBunseki.git] / u_datagenerator1.pas
1 unit u_DataGenerator1;
2
3 {
4   Feeding Origin 2 is software that supports calculation of nutrient requirement of livestock
5   and feed design based on Japanese feeding standard.
6   Copyright (C) 2017,  Syuichiro Fukagawa.
7
8   This program is free software; you can redistribute it and/or modify it under the terms of
9   the GNU General Public License as published by the Free Software Foundation; either version 3
10   of the License, or (at your option) any later version.
11   This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
12   without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13   See the GNU General Public License for more details.
14   You should have received a copy of the GNU General Public License along with this program.
15   If not, see <http://www.gnu.org/licenses/>.
16
17
18   Feeding Origin 2は、日本飼養標準に基づいた家畜の養分要求量の計算および飼料設計を支援するソフ
19   トウェアです.
20   Copyright (C) 2017, 深川修一郎.
21
22    このプログラムはフリーソフトウェアです。あなたはこれを、フリーソフトウェア財団によって
23   発行されたGNU一般公衆利用許諾書(バージョン3か、それ以降のバージョンのうちどれか)が定める
24   条件の下で再頒布または改変することができます。
25   このプログラムは有用であることを願って頒布されますが、*全くの無保証* です。商業可能性の保証
26   や特定目的への適合性は、言外に示されたものも含め、全く存在しません。詳しくはGNU一般公衆利用
27   許諾書をご覧ください。
28    あなたはこのプログラムと共に、GNU一般公衆利用許諾書のコピーを一部 受け取っているはずです。
29   もし受け取っていなければ、<http://www.gnu.org/licenses/> をご覧ください。
30   
31   *本日本語訳は、FSFより2007年6月29日に発行されたGNU GPL v3の原文から、八田真行氏が翻訳した
32    ものを基にしています。 < https://mag.osdn.jp/07/09/02/130237 >
33 }
34
35 {$mode objfpc}{$H+}
36
37 interface
38
39 uses
40   Classes, SysUtils, FileUtil, TAGraph, TASeries, Forms, Controls, Graphics,
41   Dialogs, ExtCtrls, math, StrUtils, StdCtrls, Grids, ComCtrls, u_feedingcalc2,
42   u_CommonModule, u_Marker, TACustomSeries, u_regWorkData, u_splash;
43
44 type
45   astG = Array[0..72065] of reGROW ;
46   TreGrowOrign = array[0..72577] of reGROW;
47
48   { TForm1 }
49
50   TForm1 = class(TForm)
51     Button1: TButton;
52     Button2: TButton;
53     Button3: TButton;
54     Button4: TButton;
55     Button5: TButton;
56     RegressionCurveOriginAfter: TLineSeries;
57     RegressionCurveOriginBefore: TLineSeries;
58     CheckBox4: TCheckBox;
59     Image1: TImage;
60     Image2: TImage;
61     Image3: TImage;
62     Label7: TLabel;
63     Label8: TLabel;
64     Label9: TLabel;
65     RegressionCurveJFS: TLineSeries;
66     CheckBox2: TCheckBox;
67     CheckBox3: TCheckBox;
68     Label4: TLabel;
69     Label5: TLabel;
70     Label6: TLabel;
71     Origin2BeforeWeaning: TLineSeries;
72     Origin2AfterWeaning: TLineSeries;
73     JapaneseFeedingStandard: TLineSeries;
74     Chart1: TChart;
75     CheckBox1: TCheckBox;
76     ComboBox1: TComboBox;
77     ComboBox2: TComboBox;
78     ComboBox3: TComboBox;
79     Label1: TLabel;
80     Label2: TLabel;
81     Label3: TLabel;
82     LabeledEdit1: TLabeledEdit;
83     LabeledEdit2: TLabeledEdit;
84     PageControl1: TPageControl;
85     Panel1: TPanel;
86     Panel3: TPanel;
87     StringGrid1: TStringGrid;
88     StringGrid2: TStringGrid;
89     TabSheet1: TTabSheet;
90     TabSheet2: TTabSheet;
91     TabSheet3: TTabSheet;
92     procedure Button1Click(Sender: TObject);
93     procedure Button2Click(Sender: TObject);
94     procedure Button3Click(Sender: TObject);
95     procedure Button4Click(Sender: TObject);
96     procedure Button5Click(Sender: TObject);
97     procedure CheckBox1Change(Sender: TObject);
98     procedure CheckBox2Change(Sender: TObject);
99     procedure CheckBox3Change(Sender: TObject);
100     procedure CheckBox4Change(Sender: TObject);
101     procedure ComboBox1Change(Sender: TObject);
102     procedure ComboBox2Change(Sender: TObject);
103     procedure ComboBox3Change(Sender: TObject);
104     procedure Check_of_Weight(Sender: TObject);
105     procedure FormShow(Sender: TObject);
106     procedure LabeledEdit1KeyDown(Sender: TObject; var Key: Word;
107       Shift: TShiftState);
108     procedure LabeledEdit2KeyDown(Sender: TObject; var Key: Word;
109       Shift: TShiftState);
110     procedure GeneralKeyPress(Sender: TObject; var Key: char);
111   private
112     { private declarations }
113   public
114     gstG   : astG;
115     gOrign : TreGrowOrign;
116     giRow4JFS    : Integer;
117     giRow4Orign  : Integer;
118
119     procedure ReadData();
120     procedure Spread_JFS_Data();
121     procedure Spread_Origin2_Data();
122     procedure DispHeader_1();
123     procedure DispHeader_2();
124     procedure SelectData();
125     procedure Class_JFS();
126     procedure Class_Origin2();
127     procedure GraphOutPut();
128     procedure GraphDraw4JFS();
129     procedure GraphDraw4Origin2(var iKbn : Integer);
130     function  NichZotaijuAnbaichi(var dWt : Double) : Double;
131   end;
132
133 var
134   Form1: TForm1;
135   gstR  : reNUTRIENT ;
136   giSNo, giRow, giOrgSrc  : Integer;
137
138 implementation
139
140 {$R *.lfm}
141
142 procedure TForm1.Check_of_Weight(Sender: TObject);
143 var
144   TE  :  TLabeledEdit ;
145   iEN   : Integer;
146   dWt, dWrk1   : Double;
147 begin
148   TE  := Sender as TLabeledEdit ;
149   iEN := StrToInt(RightStr(TE.Name, 1));
150   dWt := StrToFloat(TE.Text);
151   if (dWt < 40) or (dWt > 707) then
152     begin
153       ShowMessage('体重は40kg以上707kg以下を入力します。');
154       TE.SetFocus;
155       exit;
156     end;
157
158   case  iEN  of
159     1 :
160       begin
161         dWrk1 := StrToFloat(LabeledEdit2.Text);
162         if dWrk1 <= dWt then
163           begin
164             ShowMessage('体重(最大)より小さい値を入力してください。');
165             TE.SetFocus;
166             exit;
167           end;
168       end;
169     2 :
170       begin
171         dWrk1 := StrToFloat(LabeledEdit1.Text);
172         if dWrk1 >= dWt then
173           begin
174             ShowMessage('体重(最小)より大きい値を入力してください。');
175             TE.SetFocus;
176             exit;
177           end;
178       end;
179   end;
180
181   SelectData();
182   GraphOutPut();
183 end;
184
185 procedure TForm1.FormShow(Sender: TObject);
186 begin
187   u_splash.fSplash.Show ;
188
189   if not FileExists('IkuseiData.dat') then
190   begin
191     ShowMessage('データ・ファイルの「IkuseiData.dat」が見つかりません。'+#$0D+#$0A+'プログラムを終了します。');
192     close();
193   end;
194
195   Application.ProcessMessages;
196   ReadData();
197   Application.ProcessMessages;
198   Spread_JFS_Data();
199   Application.ProcessMessages;
200   Spread_Origin2_Data();
201   Application.ProcessMessages;
202
203   Form1.Cursor:=crDefault;
204   Form1.Panel1.Cursor:=crDefault;
205   Form1.PageControl1.Cursor:=crDefault;
206   Form1.TabSheet3.Cursor:=crDefault;
207
208   Form1.Panel3.Cursor:=crDefault;
209   Form1.Chart1.Cursor:=crDefault;
210
211   Form1.Panel1.Enabled:=true;
212   Form1.TabSheet3.Enabled:=true ;
213
214   Application.ProcessMessages;
215
216   SelectData();
217   GraphOutPut();
218
219   u_splash.fSplash.Close;
220 end;
221
222 procedure TForm1.LabeledEdit1KeyDown(Sender: TObject; var Key: Word;
223   Shift: TShiftState);
224 begin
225     ComEditKeyDown(Form1, Sender, Key, Shift);
226 end;
227
228 procedure TForm1.GeneralKeyPress(Sender: TObject; var Key: char);
229 begin
230     ComEditKeyPress(Form1, Sender, Key);
231 end;
232
233 procedure TForm1.LabeledEdit2KeyDown(Sender: TObject; var Key: Word;
234   Shift: TShiftState);
235 begin
236     ComEditKeyDown(Form1, Sender, Key, Shift);
237 end;
238
239 procedure TForm1.Button2Click(Sender: TObject);
240 begin
241    SelectData();
242    GraphOutPut();
243 end;
244
245 procedure TForm1.Button3Click(Sender: TObject);
246 var
247   m, n, i, iK  :  Integer;
248   X, Yxm, Yxn, Yx_1, YxYx_1, Yx2 : Double;
249   SigmaYxm, SigmaYxn, SigmaYx_1, SigmaYxYx_1, SigmaYx2 : Double;
250   a, b, c : Double;
251   Cx, CxYx, C2x : Double;
252   SigmaCx, SigmaCxYx, SigmaC2x : Double;
253   dWt, dRg : Double;
254   dMeanY, SgmaYiFi2, SgmaYiMY2, dR2 : Double;
255   sMb : String;
256 begin
257   if giRow4JFS > 0 then
258     begin
259       n := giRow4JFS ;
260       m := n - 1;
261       iK := ComboBox2.ItemIndex + 7;
262       SigmaYxn    := 0;
263       SigmaYxm    := 0;
264       SigmaYx_1   := 0;
265       SigmaYxYx_1 := 0;
266       SigmaYx2    := 0;
267       SigmaCx     := 0;
268       SigmaCxYx   := 0;
269       SigmaC2x    := 0;
270       dMeanY      := 0;
271       SgmaYiFi2   := 0;
272       SgmaYiMY2   := 0;
273       for i:=1 to m do
274         begin
275           Yxm         := StrToFloat(StringGrid1.Cells[iK, i]);
276           SigmaYxm    += Yxm;
277           Yx_1        := StrToFloat(StringGrid1.Cells[iK, i+1]);
278           SigmaYx_1   += Yx_1;
279           YxYx_1      := Yxm * Yx_1;
280           SigmaYxYx_1 += YxYx_1;
281           Yx2         := Power(Yxm, 2);
282           SigmaYx2    += Yx2;
283         end;
284       c := (n*SigmaYxYx_1-SigmaYxm*SigmaYx_1)/(n*SigmaYx2-Power(SigmaYxm,2));
285       for i:=1 to n do
286         begin
287           X   := StrToFloat(StringGrid1.Cells[1, i]);
288           Yxn := StrToFloat(StringGrid1.Cells[iK, i]);
289           SigmaYxn += Yxn ;
290           Cx        := Power(c, X) ;
291           SigmaCx   += Cx ;
292           CxYx      := Cx * Yxn;
293           SigmaCxYx += CxYx;
294           C2x       := Power(Cx, 2);
295           SigmaC2x  += C2x ;
296         end;
297
298       dMeanY := SigmaYxn / n;
299
300       b := (n*SigmaCxYx-SigmaCx*SigmaYxn)/(n*SigmaC2x-Power(SigmaCx,2));
301       a := (SigmaYxn/n)-b*(SigmaCx/n);
302       if b < 0 then
303           sMb := ' - ' + FloatToStrF(abs(b), ffGeneral, 8, 4 ) + ' * '
304       else
305           sMb := ' + ' + FloatToStrF(b, ffGeneral, 8, 4 ) + ' * ';
306       Label7.Caption := 'Y= '+FloatToStrF(a, ffGeneral, 8, 4 )+sMb+FloatToStrF(c, ffGeneral, 8, 4 )+' ^ X ';
307
308       RegressionCurveJFS.Clear;
309       for i:=1 to n do
310         begin
311           dWt := StrToFloat(StringGrid1.Cells[1, i]);
312           dRg := a + b * Power(c, dWt);
313           RegressionCurveJFS.AddXY(dWt, dRg);
314           Yxn := StrToFloat(StringGrid1.Cells[iK, i]);
315           SgmaYiFi2 += Power((Yxn - dRg), 2);
316           SgmaYiMY2 += Power((Yxn - dMeanY), 2);
317         end;
318       dR2 := 1.0 - ( SgmaYiFi2 / SgmaYiMY2 );
319       Label7.Caption := Label7.Caption + ' ; R2= ' + FloatToStr(dR2);
320     end;
321 end;
322
323 procedure TForm1.Button4Click(Sender: TObject);
324 var
325   NofArticles : Integer;
326   n, i, j, iK  :  Integer;
327   X, Yxm, Yxn, Yx_1, YxYx_1, Yx2 : Double;
328   SigmaYxm, SigmaYxn, SigmaYx_1, SigmaYxYx_1, SigmaYx2 : Double;
329   a, b, c : Double;
330   Cx, CxYx, C2x : Double;
331   SigmaCx, SigmaCxYx, SigmaC2x : Double;
332   dWt, dRg : Double;
333   dMeanY, SgmaYiFi2, SgmaYiMY2, dR2 : Double;
334   sMb : String;
335 begin
336   if giRow4JFS > 0 then
337     begin
338       n := giRow4Orign ;
339       iK := ComboBox2.ItemIndex + 7;
340       NofArticles := 0;
341       SigmaYxn    := 0;
342       SigmaYxm    := 0;
343       SigmaYx_1   := 0;
344       SigmaYxYx_1 := 0;
345       SigmaYx2    := 0;
346       SigmaCx     := 0;
347       SigmaCxYx   := 0;
348       SigmaC2x    := 0;
349       dMeanY      := 0;
350       SgmaYiFi2   := 0;
351       SgmaYiMY2   := 0;
352       for i:=1 to 72599 do
353         begin
354           for j:=0 to 17 do
355             begin
356                  RegWorkForm.StringGrid3.Cells[ j, i] := '';
357             end;
358         end;
359       for i:=1 to n do
360         begin
361           if Trim(StringGrid2.Cells[5, i]) = '離乳前' then
362             begin
363               NofArticles += 1;
364               RegWorkForm.StringGrid3.Cells[ 0, NofArticles] := StringGrid2.Cells[ 0, i] ;
365               RegWorkForm.StringGrid3.Cells[ 1, NofArticles] := StringGrid2.Cells[ 1, i] ;
366               RegWorkForm.StringGrid3.Cells[ 2, NofArticles] := StringGrid2.Cells[ 2, i] ;
367               RegWorkForm.StringGrid3.Cells[ 3, NofArticles] := StringGrid2.Cells[ 3, i] ;
368               RegWorkForm.StringGrid3.Cells[ 4, NofArticles] := StringGrid2.Cells[ 4, i] ;
369               RegWorkForm.StringGrid3.Cells[ 5, NofArticles] := StringGrid2.Cells[ 5, i] ;
370               RegWorkForm.StringGrid3.Cells[ 6, NofArticles] := StringGrid2.Cells[ 6, i] ;
371               RegWorkForm.StringGrid3.Cells[ 7, NofArticles] := StringGrid2.Cells[ 7, i] ;
372               RegWorkForm.StringGrid3.Cells[ 8, NofArticles] := StringGrid2.Cells[ 8, i] ;
373               RegWorkForm.StringGrid3.Cells[ 9, NofArticles] := StringGrid2.Cells[ 9, i] ;
374               RegWorkForm.StringGrid3.Cells[10, NofArticles] := StringGrid2.Cells[10, i] ;
375               RegWorkForm.StringGrid3.Cells[11, NofArticles] := StringGrid2.Cells[11, i] ;
376               RegWorkForm.StringGrid3.Cells[12, NofArticles] := StringGrid2.Cells[12, i] ;
377               RegWorkForm.StringGrid3.Cells[13, NofArticles] := StringGrid2.Cells[13, i] ;
378               RegWorkForm.StringGrid3.Cells[14, NofArticles] := StringGrid2.Cells[14, i] ;
379               RegWorkForm.StringGrid3.Cells[15, NofArticles] := StringGrid2.Cells[15, i] ;
380               RegWorkForm.StringGrid3.Cells[16, NofArticles] := StringGrid2.Cells[16, i] ;
381               RegWorkForm.StringGrid3.Cells[17, NofArticles] := StringGrid2.Cells[17, i] ;
382             end;
383         end;
384       if NofArticles = 0 then exit;
385       for i:=1 to (NofArticles-1) do
386         begin
387               Yxm         := StrToFloat(RegWorkForm.StringGrid3.Cells[iK, i]);
388               SigmaYxm    += Yxm;
389               Yx_1        := StrToFloat(RegWorkForm.StringGrid3.Cells[iK, i+1]);
390               SigmaYx_1   += Yx_1;
391               YxYx_1      := Yxm * Yx_1;
392               SigmaYxYx_1 += YxYx_1;
393               Yx2         := Power(Yxm, 2);
394               SigmaYx2    += Yx2;
395         end;
396       c := (NofArticles*SigmaYxYx_1-SigmaYxm*SigmaYx_1)/(NofArticles*SigmaYx2-Power(SigmaYxm,2));
397       for i:=1 to NofArticles do
398         begin
399               X   := StrToFloat(RegWorkForm.StringGrid3.Cells[1, i]);
400               Yxn := StrToFloat(RegWorkForm.StringGrid3.Cells[iK, i]);
401               SigmaYxn  += Yxn ;
402               Cx        := Power(c, X) ;
403               SigmaCx   += Cx ;
404               CxYx      := Cx * Yxn;
405               SigmaCxYx += CxYx;
406               C2x       := Power(Cx, 2);
407               SigmaC2x  += C2x ;
408         end;
409
410       dMeanY := SigmaYxn / NofArticles;
411
412       b := (NofArticles*SigmaCxYx-SigmaCx*SigmaYxn)/(NofArticles*SigmaC2x-Power(SigmaCx,2));
413       a := (SigmaYxn/NofArticles)-b*(SigmaCx/NofArticles);
414       if b < 0 then
415           sMb := ' - ' + FloatToStrF(abs(b), ffGeneral, 8, 4 ) + ' * '
416       else
417           sMb := ' + ' + FloatToStrF(b, ffGeneral, 8, 4 ) + ' * ';
418       Label8.Caption := 'Y= '+FloatToStrF(a, ffGeneral, 8, 4 )+sMb+FloatToStrF(c, ffGeneral, 8, 4 )+' ^ X ';
419       RegressionCurveOriginBefore.Clear;
420       for i:=1 to NofArticles do
421         begin
422               dWt := StrToFloat(RegWorkForm.StringGrid3.Cells[1, i]);
423               dRg := a + b * Power(c, dWt);
424               RegressionCurveOriginBefore.AddXY(dWt, dRg);
425               Yxn := StrToFloat(StringGrid1.Cells[iK, i]);
426               SgmaYiFi2 += Power((Yxn - dRg), 2);
427               SgmaYiMY2 += Power((Yxn - dMeanY), 2);
428         end;
429       dR2 := 1.0 - ( SgmaYiFi2 / SgmaYiMY2 );
430       Label8.Caption := Label8.Caption + ' ; R2= ' + FloatToStr(dR2);
431     end;
432 end;
433
434 procedure TForm1.Button5Click(Sender: TObject);
435 var
436   NofArticles : Integer;
437   n, i, j, iK  :  Integer;
438   X, Yxm, Yxn, Yx_1, YxYx_1, Yx2 : Double;
439   SigmaYxm, SigmaYxn, SigmaYx_1, SigmaYxYx_1, SigmaYx2 : Double;
440   a, b, c : Double;
441   Cx, CxYx, C2x : Double;
442   SigmaCx, SigmaCxYx, SigmaC2x : Double;
443   dWt, dRg : Double;
444   dMeanY, SgmaYiFi2, SgmaYiMY2, dR2 : Double;
445   sMb : String;
446 begin
447   if giRow4JFS > 0 then
448     begin
449       n := giRow4Orign ;
450       iK := ComboBox2.ItemIndex + 7;
451       NofArticles := 0;
452       SigmaYxn    := 0;
453       SigmaYxm    := 0;
454       SigmaYx_1   := 0;
455       SigmaYxYx_1 := 0;
456       SigmaYx2    := 0;
457       SigmaCx     := 0;
458       SigmaCxYx   := 0;
459       SigmaC2x    := 0;
460       dMeanY      := 0;
461       SgmaYiFi2   := 0;
462       SgmaYiMY2   := 0;
463       for i:=1 to 72599 do
464         begin
465           for j:=0 to 17 do
466             begin
467                  RegWorkForm.StringGrid3.Cells[ j, i] := '';
468             end;
469         end;
470       for i:=1 to n do
471         begin
472           if Trim(StringGrid2.Cells[5, i]) = '離乳後' then
473             begin
474               NofArticles += 1;
475               RegWorkForm.StringGrid3.Cells[ 0, NofArticles] := StringGrid2.Cells[ 0, i] ;
476               RegWorkForm.StringGrid3.Cells[ 1, NofArticles] := StringGrid2.Cells[ 1, i] ;
477               RegWorkForm.StringGrid3.Cells[ 2, NofArticles] := StringGrid2.Cells[ 2, i] ;
478               RegWorkForm.StringGrid3.Cells[ 3, NofArticles] := StringGrid2.Cells[ 3, i] ;
479               RegWorkForm.StringGrid3.Cells[ 4, NofArticles] := StringGrid2.Cells[ 4, i] ;
480               RegWorkForm.StringGrid3.Cells[ 5, NofArticles] := StringGrid2.Cells[ 5, i] ;
481               RegWorkForm.StringGrid3.Cells[ 6, NofArticles] := StringGrid2.Cells[ 6, i] ;
482               RegWorkForm.StringGrid3.Cells[ 7, NofArticles] := StringGrid2.Cells[19, i] ;
483               RegWorkForm.StringGrid3.Cells[ 8, NofArticles] := StringGrid2.Cells[20, i] ;
484               RegWorkForm.StringGrid3.Cells[ 9, NofArticles] := StringGrid2.Cells[21, i] ;
485               RegWorkForm.StringGrid3.Cells[10, NofArticles] := StringGrid2.Cells[22, i] ;
486               RegWorkForm.StringGrid3.Cells[11, NofArticles] := StringGrid2.Cells[23, i] ;
487               RegWorkForm.StringGrid3.Cells[12, NofArticles] := StringGrid2.Cells[24, i] ;
488               RegWorkForm.StringGrid3.Cells[13, NofArticles] := StringGrid2.Cells[25, i] ;
489               RegWorkForm.StringGrid3.Cells[14, NofArticles] := StringGrid2.Cells[26, i] ;
490               RegWorkForm.StringGrid3.Cells[15, NofArticles] := StringGrid2.Cells[27, i] ;
491               RegWorkForm.StringGrid3.Cells[16, NofArticles] := StringGrid2.Cells[28, i] ;
492               RegWorkForm.StringGrid3.Cells[17, NofArticles] := StringGrid2.Cells[29, i] ;
493             end;
494         end;
495       for i:=1 to (NofArticles-1) do
496         begin
497               Yxm         := StrToFloat(RegWorkForm.StringGrid3.Cells[iK, i]);
498               SigmaYxm    += Yxm;
499               Yx_1        := StrToFloat(RegWorkForm.StringGrid3.Cells[iK, i+1]);
500               SigmaYx_1   += Yx_1;
501               YxYx_1      := Yxm * Yx_1;
502               SigmaYxYx_1 += YxYx_1;
503               Yx2         := Power(Yxm, 2);
504               SigmaYx2    += Yx2;
505         end;
506       c := (NofArticles*SigmaYxYx_1-SigmaYxm*SigmaYx_1)/(NofArticles*SigmaYx2-Power(SigmaYxm,2));
507       for i:=1 to NofArticles do
508         begin
509               X   := StrToFloat(RegWorkForm.StringGrid3.Cells[1, i]);
510               Yxn := StrToFloat(RegWorkForm.StringGrid3.Cells[iK, i]);
511               SigmaYxn += Yxn ;
512               Cx        := Power(c, X) ;
513               SigmaCx   += Cx ;
514               CxYx      := Cx * Yxn;
515               SigmaCxYx += CxYx;
516               C2x       := Power(Cx, 2);
517               SigmaC2x  += C2x ;
518         end;
519
520       dMeanY := SigmaYxn / NofArticles;
521
522       b := (NofArticles*SigmaCxYx-SigmaCx*SigmaYxn)/(NofArticles*SigmaC2x-Power(SigmaCx,2));
523       a := (SigmaYxn/NofArticles)-b*(SigmaCx/NofArticles);
524       if b < 0 then
525           sMb := ' - ' + FloatToStrF(abs(b), ffGeneral, 8, 4 ) + ' * '
526       else
527           sMb := ' + ' + FloatToStrF(b, ffGeneral, 8, 4 ) + ' * ';
528       Label9.Caption := 'Y= '+FloatToStrF(a, ffGeneral, 8, 4 )+sMb+FloatToStrF(c, ffGeneral, 8, 4 )+' ^ X ';
529       RegressionCurveOriginAfter.Clear;
530       for i:=1 to NofArticles do
531         begin
532               dWt := StrToFloat(RegWorkForm.StringGrid3.Cells[1, i]);
533               dRg := a + b * Power(c, dWt);
534               RegressionCurveOriginAfter.AddXY(dWt, dRg);
535               Yxn := StrToFloat(StringGrid1.Cells[iK, i]);
536               SgmaYiFi2 += Power((Yxn - dRg), 2);
537               SgmaYiMY2 += Power((Yxn - dMeanY), 2);
538         end;
539       dR2 := 1.0 - ( SgmaYiFi2 / SgmaYiMY2 );
540       Label9.Caption := Label9.Caption + ' ; R2= ' + FloatToStr(dR2);
541     end;
542 end;
543
544 procedure TForm1.Button1Click(Sender: TObject);
545 begin
546   fMarker.Show;
547 end;
548
549 procedure TForm1.CheckBox1Change(Sender: TObject);
550 begin
551     SelectData();
552     GraphOutPut();
553 end;
554
555 procedure TForm1.CheckBox2Change(Sender: TObject);
556 begin
557   SelectData();
558   GraphOutPut();
559 end;
560
561 procedure TForm1.CheckBox3Change(Sender: TObject);
562 begin
563     SelectData();
564     GraphOutPut();
565 end;
566
567 procedure TForm1.CheckBox4Change(Sender: TObject);
568 begin
569     SelectData();
570     GraphOutPut();
571 end;
572
573 procedure TForm1.ComboBox1Change(Sender: TObject);
574 begin
575     SelectData();
576     GraphOutPut();
577 end;
578
579 procedure TForm1.ComboBox2Change(Sender: TObject);
580 begin
581     SelectData();
582     GraphOutPut();
583 end;
584
585 procedure TForm1.ComboBox3Change(Sender: TObject);
586 begin
587     SelectData();
588     GraphOutPut();
589 end;
590
591 procedure TForm1.Spread_Origin2_Data();
592 var
593   i, iSN, iPN : Integer ;
594   dWeight, dGain : Double;
595   sLowest, sSeason  : String;
596   stG  : reGROW ;
597
598 begin
599   DispHeader_2();
600   iSN := giSNo;
601   iPN := 0;
602   for i:=1 to iSN do
603     begin
604       dWeight := gstG[i].dWt1;
605       dGain   := gstG[i].dInWt1;
606       sLowest := gstG[i].cLVCP;
607       sSeason := gstG[i].cKset;
608       Inc(iPN);
609       if (dWeight <= 66.00) then
610         begin
611           StringGrid2.Cells[0, iPN] := IntToStr(iPN);
612           StringGrid2.Cells[1, iPN] := FloatToStr(dWeight);
613           StringGrid2.Cells[2, iPN] := FloatToStr(dGain);
614           StringGrid2.Cells[3, iPN] := sLowest;
615           StringGrid2.Cells[4, iPN] := sSeason;
616           StringGrid2.Cells[5, iPN] := '離乳前';
617           gOrign[iPN].dWt1   := dWeight;
618           gOrign[iPN].dInWt1 := dGain;
619           gOrign[iPN].cLVCP  := sLowest;
620           gOrign[iPN].cKset  := sSeason;
621           gOrign[iPN].cWean  := '離乳前';
622           stG := gOrign[iPN];
623           gOrign[iPN].Nutrient := GrowingCow_A( stG );
624           StringGrid2.Cells[ 6, iPN] := FloatToStr(gOrign[iPN].Nutrient.dFCM);
625           StringGrid2.Cells[ 7, iPN] := FloatToStr(gOrign[iPN].Nutrient.dDMI);
626           StringGrid2.Cells[ 8, iPN] := FloatToStr(gOrign[iPN].Nutrient.dCP);
627           StringGrid2.Cells[ 9, iPN] := FloatToStr(gOrign[iPN].Nutrient.dDCP);
628           StringGrid2.Cells[10, iPN] := FloatToStr(gOrign[iPN].Nutrient.dTDN);
629           StringGrid2.Cells[11, iPN] := FloatToStr(gOrign[iPN].Nutrient.dDE);
630           StringGrid2.Cells[12, iPN] := FloatToStr(gOrign[iPN].Nutrient.dMEC);
631           StringGrid2.Cells[13, iPN] := FloatToStr(gOrign[iPN].Nutrient.dMEJ);
632           StringGrid2.Cells[14, iPN] := FloatToStr(gOrign[iPN].Nutrient.dCa);
633           StringGrid2.Cells[15, iPN] := FloatToStr(gOrign[iPN].Nutrient.dP);
634           StringGrid2.Cells[16, iPN] := FloatToStr(gOrign[iPN].Nutrient.dVA);
635           StringGrid2.Cells[17, iPN] := FloatToStr(gOrign[iPN].Nutrient.dVD);
636         end
637       else if (dWeight > 66.00) and (dWeight < 75.00) then
638         begin
639           StringGrid2.Cells[0, iPN] := IntToStr(iPN);
640           StringGrid2.Cells[1, iPN] := FloatToStr(dWeight);
641           StringGrid2.Cells[2, iPN] := FloatToStr(dGain);
642           StringGrid2.Cells[3, iPN] := sLowest;
643           StringGrid2.Cells[4, iPN] := sSeason;
644           StringGrid2.Cells[5, iPN] := '離乳前';
645           gOrign[iPN].dWt1   := dWeight;
646           gOrign[iPN].dInWt1 := dGain;
647           gOrign[iPN].cLVCP  := sLowest;
648           gOrign[iPN].cKset  := sSeason;
649           gOrign[iPN].cWean  := '離乳前';
650           stG := gOrign[iPN];
651           gOrign[iPN].Nutrient := GrowingCow_A( stG );
652           StringGrid2.Cells[ 6, iPN] := FloatToStr(gOrign[iPN].Nutrient.dFCM);
653           StringGrid2.Cells[ 7, iPN] := FloatToStr(gOrign[iPN].Nutrient.dDMI);
654           StringGrid2.Cells[ 8, iPN] := FloatToStr(gOrign[iPN].Nutrient.dCP);
655           StringGrid2.Cells[ 9, iPN] := FloatToStr(gOrign[iPN].Nutrient.dDCP);
656           StringGrid2.Cells[10, iPN] := FloatToStr(gOrign[iPN].Nutrient.dTDN);
657           StringGrid2.Cells[11, iPN] := FloatToStr(gOrign[iPN].Nutrient.dDE);
658           StringGrid2.Cells[12, iPN] := FloatToStr(gOrign[iPN].Nutrient.dMEC);
659           StringGrid2.Cells[13, iPN] := FloatToStr(gOrign[iPN].Nutrient.dMEJ);
660           StringGrid2.Cells[14, iPN] := FloatToStr(gOrign[iPN].Nutrient.dCa);
661           StringGrid2.Cells[15, iPN] := FloatToStr(gOrign[iPN].Nutrient.dP);
662           StringGrid2.Cells[16, iPN] := FloatToStr(gOrign[iPN].Nutrient.dVA);
663           StringGrid2.Cells[17, iPN] := FloatToStr(gOrign[iPN].Nutrient.dVD);
664           Inc(iPN);
665           StringGrid2.Cells[0, iPN] := IntToStr(iPN);
666           StringGrid2.Cells[1, iPN] := FloatToStr(dWeight);
667           StringGrid2.Cells[2, iPN] := FloatToStr(dGain);
668           StringGrid2.Cells[3, iPN] := sLowest;
669           StringGrid2.Cells[4, iPN] := sSeason;
670           StringGrid2.Cells[5, iPN] := '離乳後';
671           gOrign[iPN].dWt1   := dWeight;
672           gOrign[iPN].dInWt1 := dGain;
673           gOrign[iPN].cLVCP  := sLowest;
674           gOrign[iPN].cKset  := sSeason;
675           gOrign[iPN].cWean  := '離乳後';
676           stG := gOrign[iPN];
677           gOrign[iPN].Nutrient := GrowingCow_A( stG );
678           StringGrid2.Cells[ 6, iPN] := FloatToStr(gOrign[iPN].Nutrient.dFCM);
679           StringGrid2.Cells[ 7, iPN] := FloatToStr(gOrign[iPN].Nutrient.dDMI);
680           StringGrid2.Cells[ 8, iPN] := FloatToStr(gOrign[iPN].Nutrient.dCP);
681           StringGrid2.Cells[ 9, iPN] := FloatToStr(gOrign[iPN].Nutrient.dDCP);
682           StringGrid2.Cells[10, iPN] := FloatToStr(gOrign[iPN].Nutrient.dTDN);
683           StringGrid2.Cells[11, iPN] := FloatToStr(gOrign[iPN].Nutrient.dDE);
684           StringGrid2.Cells[12, iPN] := FloatToStr(gOrign[iPN].Nutrient.dMEC);
685           StringGrid2.Cells[13, iPN] := FloatToStr(gOrign[iPN].Nutrient.dMEJ);
686           StringGrid2.Cells[14, iPN] := FloatToStr(gOrign[iPN].Nutrient.dCa);
687           StringGrid2.Cells[15, iPN] := FloatToStr(gOrign[iPN].Nutrient.dP);
688           StringGrid2.Cells[16, iPN] := FloatToStr(gOrign[iPN].Nutrient.dVA);
689           StringGrid2.Cells[17, iPN] := FloatToStr(gOrign[iPN].Nutrient.dVD);
690         end
691       else
692         begin
693           StringGrid2.Cells[0, iPN] := IntToStr(iPN);
694           StringGrid2.Cells[1, iPN] := FloatToStr(dWeight);
695           StringGrid2.Cells[2, iPN] := FloatToStr(dGain);
696           StringGrid2.Cells[3, iPN] := sLowest;
697           StringGrid2.Cells[4, iPN] := sSeason;
698           StringGrid2.Cells[5, iPN] := '離乳後';
699           gOrign[iPN].dWt1   := dWeight;
700           gOrign[iPN].dInWt1 := dGain;
701           gOrign[iPN].cLVCP  := sLowest;
702           gOrign[iPN].cKset  := sSeason;
703           gOrign[iPN].cWean  := '離乳後';
704           stG := gOrign[iPN];
705           gOrign[iPN].Nutrient := GrowingCow_A( stG );
706           StringGrid2.Cells[ 6, iPN] := FloatToStr(gOrign[iPN].Nutrient.dFCM);
707           StringGrid2.Cells[ 7, iPN] := FloatToStr(gOrign[iPN].Nutrient.dDMI);
708           StringGrid2.Cells[ 8, iPN] := FloatToStr(gOrign[iPN].Nutrient.dCP);
709           StringGrid2.Cells[ 9, iPN] := FloatToStr(gOrign[iPN].Nutrient.dDCP);
710           StringGrid2.Cells[10, iPN] := FloatToStr(gOrign[iPN].Nutrient.dTDN);
711           StringGrid2.Cells[11, iPN] := FloatToStr(gOrign[iPN].Nutrient.dDE);
712           StringGrid2.Cells[12, iPN] := FloatToStr(gOrign[iPN].Nutrient.dMEC);
713           StringGrid2.Cells[13, iPN] := FloatToStr(gOrign[iPN].Nutrient.dMEJ);
714           StringGrid2.Cells[14, iPN] := FloatToStr(gOrign[iPN].Nutrient.dCa);
715           StringGrid2.Cells[15, iPN] := FloatToStr(gOrign[iPN].Nutrient.dP);
716           StringGrid2.Cells[16, iPN] := FloatToStr(gOrign[iPN].Nutrient.dVA);
717           StringGrid2.Cells[17, iPN] := FloatToStr(gOrign[iPN].Nutrient.dVD);
718         end;
719     end;
720     giOrgSrc := iPN;
721 end;
722
723 procedure TForm1.ReadData();
724 var
725     inf      : TextFile;
726     u_String, sWrk, sDat : string;
727     iRow, iNo, iP, iL, iT  : Integer ;
728     bKomk    : Boolean;
729 begin
730     iRow := 1 ;
731     AssignFile(inf,'IkuseiData.dat');
732     Reset( inf ) ;
733     if IOResult <> 0  then
734         begin
735           ShowMessage('ファイルアクセスエラー');
736           exit;
737         end;
738     bKomk := False;
739     while not Eof( inf ) do
740       begin
741         ReadLn( inf, u_String );
742         if bKomk then
743           begin
744             iNo := 1 ;
745             iP  := 1 ;
746             iL  := Length(u_String);
747             Repeat
748               iT   := PosEx( '  ', u_String, iP ) ;
749               sWrk := MidStr(u_String, iP , (iT-iP) );
750               iP   := iT + 1 ;
751               sDat := UTF8Encode( sWrk ) ;
752               case  iNo  of
753                  1 : gstG[iRow].dWt1     := StrToFloat( sDat ) ;
754                    2 : gstG[iRow].dInWt1         := StrToFloat( sDat ) ;
755                    3 : gstG[iRow].cLVCP  := sDat  ;
756                    4 : gstG[iRow].cKset  := sDat  ;
757                  5 : gstG[iRow].Nutrient.dFCM := StrToFloat( sDat ) ;
758                  6 : gstG[iRow].Nutrient.dDMI := StrToFloat( sDat ) ;
759                  7 : gstG[iRow].Nutrient.dCP  := StrToFloat( sDat ) ;
760                  8 : gstG[iRow].Nutrient.dDCP := StrToFloat( sDat ) ;
761                  9 : gstG[iRow].Nutrient.dTDN := StrToFloat( sDat ) ;
762                 10 : gstG[iRow].Nutrient.dDE  := StrToFloat( sDat ) ;
763                 11 : gstG[iRow].Nutrient.dMEC := StrToFloat( sDat ) ;
764                 12 : gstG[iRow].Nutrient.dMEJ := StrToFloat( sDat ) ;
765                 13 : gstG[iRow].Nutrient.dCa  := StrToFloat( sDat ) ;
766                 14 : gstG[iRow].Nutrient.dP   := StrToFloat( sDat ) ;
767                 15 : gstG[iRow].Nutrient.dVA  := StrToFloat( sDat ) ;
768                 16 : gstG[iRow].Nutrient.dVD  := StrToFloat( sDat ) ;
769               end;
770               Inc(iNo);
771             until iT = iL ;
772           Inc( iRow ) ;
773           Application.ProcessMessages;
774         end;
775         bKomk := True;
776       end;
777     giSNo := iRow - 1;
778     CloseFile( inf ) ;
779 end;
780
781 procedure TForm1.Spread_JFS_Data();
782 var
783   i, j, iR         : Integer;
784 begin
785   StringGrid1.Clean;
786   DispHeader_1();
787   iR := 1;
788   for j:=1 to giSNo do
789     begin
790       for i:=0 to 17 do
791         begin
792           case  i  of
793              0 : StringGrid1.Cells[i, iR] := IntToStr(j) ;
794              1 : StringGrid1.Cells[i, iR] := FloatToStr(gstG[j].dWt1)   ;
795              2 : StringGrid1.Cells[i, iR] := FloatToStr(gstG[j].dInWt1) ;
796              3 : StringGrid1.Cells[i, iR] := gstG[j].cLVCP  ;
797              4 : StringGrid1.Cells[i, iR] := gstG[j].cKset  ;
798              5 : StringGrid1.Cells[i, iR] := gstG[j].cWean  ;
799              6 : StringGrid1.Cells[i, iR] := FloatToStr(gstG[j].Nutrient.dFCM) ;
800              7 : StringGrid1.Cells[i, iR] := FloatToStr(gstG[j].Nutrient.dDMI) ;
801              8 : StringGrid1.Cells[i, iR] := FloatToStr(gstG[j].Nutrient.dCP)  ;
802              9 : StringGrid1.Cells[i, iR] := FloatToStr(gstG[j].Nutrient.dDCP) ;
803             10 : StringGrid1.Cells[i, iR] := FloatToStr(gstG[j].Nutrient.dTDN) ;
804             11 : StringGrid1.Cells[i, iR] := FloatToStr(gstG[j].Nutrient.dDE)  ;
805             12 : StringGrid1.Cells[i, iR] := FloatToStr(gstG[j].Nutrient.dMEC) ;
806             13 : StringGrid1.Cells[i, iR] := FloatToStr(gstG[j].Nutrient.dMEJ) ;
807             14 : StringGrid1.Cells[i, iR] := FloatToStr(gstG[j].Nutrient.dCa)  ;
808             15 : StringGrid1.Cells[i, iR] := FloatToStr(gstG[j].Nutrient.dP)   ;
809             16 : StringGrid1.Cells[i, iR] := FloatToStr(gstG[j].Nutrient.dVA)  ;
810             17 : StringGrid1.Cells[i, iR] := FloatToStr(gstG[j].Nutrient.dVD)  ;
811           end;
812         end;
813         Inc( iR );
814         Application.ProcessMessages;
815     end;
816 end;
817
818 procedure TForm1.DispHeader_1();
819 var
820     iNO  :  Integer;
821 begin
822     iNO := 0 ;
823     StringGrid1.Clean;
824     StringGrid1.Cols[iNO].Text := 'No.';
825     for iNO := 0 to 4 do
826       begin
827                 case iNo of
828                   0 :
829                     begin
830                       StringGrid1.Columns[iNo].Title.Caption := '体重' ;
831                       StringGrid1.Columns[iNo].Alignment := taRightJustify ;
832                     end;
833                   1 :
834                     begin
835                       StringGrid1.Columns[iNo].Title.Caption := '日増体重' ;
836                       StringGrid1.Columns[iNo].Alignment := taRightJustify ;
837                     end;
838                   2 :
839                     begin
840                       StringGrid1.Columns[iNo].Title.Caption := 'CPの最低値' ;
841                       StringGrid1.Columns[iNo].Alignment := taCenter ;
842                     end;
843                   3 :
844                     begin
845                       StringGrid1.Columns[iNo].Title.Caption := '季節の考慮';
846                       StringGrid1.Columns[iNo].Alignment := taLeftJustify ;
847                     end;
848                   4 :
849                     begin
850                       StringGrid1.Columns[iNo].Title.Caption := '育成牛の離乳' ;
851                       StringGrid1.Columns[iNo].Alignment := taLeftJustify ;
852                     end;
853                 end;
854       end;
855     Inc( iNO ) ;
856     StringGrid1.Columns[iNo].Title.Caption := 'FCM' ;
857     StringGrid1.Columns[iNo].Alignment := taRightJustify ;
858     Inc( iNO ) ;
859     StringGrid1.Columns[iNo].Title.Caption := 'DMI' ;
860     StringGrid1.Columns[iNo].Alignment := taRightJustify ;
861     Inc( iNO ) ;
862     StringGrid1.Columns[iNo].Title.Caption := 'CP' ;
863     StringGrid1.Columns[iNo].Alignment := taRightJustify ;
864     Inc( iNO ) ;
865     StringGrid1.Columns[iNo].Title.Caption := 'DCP' ;
866     StringGrid1.Columns[iNo].Alignment := taRightJustify ;
867     Inc( iNO ) ;
868     StringGrid1.Columns[iNo].Title.Caption := 'TDN' ;
869     StringGrid1.Columns[iNo].Alignment := taRightJustify ;
870     Inc( iNO ) ;
871     StringGrid1.Columns[iNo].Title.Caption := 'DE' ;
872     StringGrid1.Columns[iNo].Alignment := taRightJustify ;
873     Inc( iNO ) ;
874     StringGrid1.Columns[iNo].Title.Caption := 'ME(Mcal)' ;
875     StringGrid1.Columns[iNo].Alignment := taRightJustify ;
876     Inc( iNO ) ;
877     StringGrid1.Columns[iNo].Title.Caption := 'ME(MJ)' ;
878     StringGrid1.Columns[iNo].Alignment := taRightJustify ;
879     Inc( iNO ) ;
880     StringGrid1.Columns[iNo].Title.Caption := 'Ca' ;
881     StringGrid1.Columns[iNo].Alignment := taRightJustify ;
882     Inc( iNO ) ;
883     StringGrid1.Columns[iNo].Title.Caption := 'P' ;
884     StringGrid1.Columns[iNo].Alignment := taRightJustify ;
885     Inc( iNO ) ;
886     StringGrid1.Columns[iNo].Title.Caption := 'VA' ;
887     StringGrid1.Columns[iNo].Alignment := taRightJustify ;
888     Inc( iNO ) ;
889     StringGrid1.Columns[iNo].Title.Caption := 'VD' ;
890     StringGrid1.Columns[iNo].Alignment := taRightJustify ;
891     Inc( iNO ) ;
892     StringGrid1.Columns[iNo].Title.Caption := ' ' ;
893     StringGrid1.Columns[iNo].Alignment := taRightJustify ;
894     Application.ProcessMessages;
895 end;
896
897 procedure TForm1.DispHeader_2();
898 var
899     iNO  :  Integer;
900 begin
901     iNO := 0 ;
902     StringGrid2.Clean;
903     StringGrid2.Cols[iNO].Text := 'No.';
904     for iNO := 0 to 4 do
905       begin
906                 case iNo of
907                   0 :
908                     begin
909                       StringGrid2.Columns[iNo].Title.Caption := '体重' ;
910                       StringGrid2.Columns[iNo].Alignment := taRightJustify ;
911                     end;
912                   1 :
913                     begin
914                       StringGrid2.Columns[iNo].Title.Caption := '日増体重' ;
915                       StringGrid2.Columns[iNo].Alignment := taRightJustify ;
916                     end;
917                   2 :
918                     begin
919                       StringGrid2.Columns[iNo].Title.Caption := 'CPの最低値' ;
920                       StringGrid2.Columns[iNo].Alignment := taCenter ;
921                     end;
922                   3 :
923                     begin
924                       StringGrid2.Columns[iNo].Title.Caption := '季節の考慮';
925                       StringGrid2.Columns[iNo].Alignment := taLeftJustify ;
926                     end;
927                   4 :
928                     begin
929                       StringGrid2.Columns[iNo].Title.Caption := '育成牛の離乳' ;
930                       StringGrid2.Columns[iNo].Alignment := taLeftJustify ;
931                     end;
932                 end;
933       end;
934     Inc( iNO ) ;
935     StringGrid2.Columns[iNo].Title.Caption := 'FCM' ;
936     StringGrid2.Columns[iNo].Alignment := taRightJustify ;
937     Inc( iNO ) ;
938     StringGrid2.Columns[iNo].Title.Caption := 'DMI' ;
939     StringGrid2.Columns[iNo].Alignment := taRightJustify ;
940     Inc( iNO ) ;
941     StringGrid2.Columns[iNo].Title.Caption := 'CP' ;
942     StringGrid2.Columns[iNo].Alignment := taRightJustify ;
943     Inc( iNO ) ;
944     StringGrid2.Columns[iNo].Title.Caption := 'DCP' ;
945     StringGrid2.Columns[iNo].Alignment := taRightJustify ;
946     Inc( iNO ) ;
947     StringGrid2.Columns[iNo].Title.Caption := 'TDN' ;
948     StringGrid2.Columns[iNo].Alignment := taRightJustify ;
949     Inc( iNO ) ;
950     StringGrid2.Columns[iNo].Title.Caption := 'DE' ;
951     StringGrid2.Columns[iNo].Alignment := taRightJustify ;
952     Inc( iNO ) ;
953     StringGrid2.Columns[iNo].Title.Caption := 'ME(Mcal)' ;
954     StringGrid2.Columns[iNo].Alignment := taRightJustify ;
955     Inc( iNO ) ;
956     StringGrid2.Columns[iNo].Title.Caption := 'ME(MJ)' ;
957     StringGrid2.Columns[iNo].Alignment := taRightJustify ;
958     Inc( iNO ) ;
959     StringGrid2.Columns[iNo].Title.Caption := 'Ca' ;
960     StringGrid2.Columns[iNo].Alignment := taRightJustify ;
961     Inc( iNO ) ;
962     StringGrid2.Columns[iNo].Title.Caption := 'P' ;
963     StringGrid2.Columns[iNo].Alignment := taRightJustify ;
964     Inc( iNO ) ;
965     StringGrid2.Columns[iNo].Title.Caption := 'VA' ;
966     StringGrid2.Columns[iNo].Alignment := taRightJustify ;
967     Inc( iNO ) ;
968     StringGrid2.Columns[iNo].Title.Caption := 'VD' ;
969     StringGrid2.Columns[iNo].Alignment := taRightJustify ;
970     Inc( iNO ) ;
971     StringGrid2.Columns[iNo].Title.Caption := ' ' ;
972     StringGrid2.Columns[iNo].Alignment := taRightJustify ;
973     Inc( iNO ) ;
974     StringGrid2.Columns[iNo].Title.Caption := '<DMI>' ;
975     StringGrid2.Columns[iNo].Alignment := taRightJustify ;
976     Inc( iNO ) ;
977     StringGrid2.Columns[iNo].Title.Caption := '<CP>' ;
978     StringGrid2.Columns[iNo].Alignment := taRightJustify ;
979     Inc( iNO ) ;
980     StringGrid2.Columns[iNo].Title.Caption := '<DCP>' ;
981     StringGrid2.Columns[iNo].Alignment := taRightJustify ;
982     Inc( iNO ) ;
983     StringGrid2.Columns[iNo].Title.Caption := '<TDN>' ;
984     StringGrid2.Columns[iNo].Alignment := taRightJustify ;
985     Inc( iNO ) ;
986     StringGrid2.Columns[iNo].Title.Caption := '<DE>' ;
987     StringGrid2.Columns[iNo].Alignment := taRightJustify ;
988     Inc( iNO ) ;
989     StringGrid2.Columns[iNo].Title.Caption := '<ME(Mcal)>' ;
990     StringGrid2.Columns[iNo].Alignment := taRightJustify ;
991     Inc( iNO ) ;
992     StringGrid2.Columns[iNo].Title.Caption := '<ME(MJ)>' ;
993     StringGrid2.Columns[iNo].Alignment := taRightJustify ;
994     Inc( iNO ) ;
995     StringGrid2.Columns[iNo].Title.Caption := '<Ca>' ;
996     StringGrid2.Columns[iNo].Alignment := taRightJustify ;
997     Inc( iNO ) ;
998     StringGrid2.Columns[iNo].Title.Caption := '<P>' ;
999     StringGrid2.Columns[iNo].Alignment := taRightJustify ;
1000     Inc( iNO ) ;
1001     StringGrid2.Columns[iNo].Title.Caption := '<VA>' ;
1002     StringGrid2.Columns[iNo].Alignment := taRightJustify ;
1003     Inc( iNO ) ;
1004     StringGrid2.Columns[iNo].Title.Caption := '<VD>' ;
1005     StringGrid2.Columns[iNo].Alignment := taRightJustify ;
1006     Inc( iNO ) ;
1007     StringGrid2.Columns[iNo].Title.Caption := ' ' ;
1008     StringGrid2.Columns[iNo].Alignment := taRightJustify ;
1009     Inc( iNO ) ;
1010     StringGrid2.Columns[iNo].Title.Caption := ' ' ;
1011     StringGrid2.Columns[iNo].Alignment := taRightJustify ;
1012     Application.ProcessMessages;
1013 end;
1014
1015 procedure TForm1.SelectData();
1016 begin
1017   Class_JFS();
1018   Class_Origin2();
1019 end;
1020
1021 procedure TForm1.Class_JFS();
1022 var
1023   dBW, dLW, dZoTj  : Double;
1024   sKset, sCP12     : String;
1025   i, j, iR         : Integer;
1026   sZotj            : String;
1027   bC12Flg          : Boolean;
1028 begin
1029   dLW := StrToFloat(LabeledEdit1.Text);
1030   dBW := StrToFloat(LabeledEdit2.Text);
1031   sZotj := ComboBox3.Caption;
1032   if (sZotj <> '標準値') then dZoTj := StrToFloat(sZotj);
1033   sKset := ComboBox1.Caption;
1034   if CheckBox1.Checked then sCP12 := 'ON' else sCP12 := 'OFF';
1035   StringGrid1.Clean;
1036   iR := 1;
1037   for j:=1 to giSNo do
1038   begin
1039       if (gstG[j].dWt1 >= dLW) and (gstG[j].dWt1 <= dBW) then
1040       begin
1041           if (sZotj = '標準値') then dZoTj := NichZotaijuAnbaichi(gstG[j].dWt1);
1042           if gstG[j].dInWt1 = dZoTj then
1043           begin
1044               if gstG[j].cKset = sKset then
1045               begin
1046                   bC12Flg := False;
1047                   if  gstG[j].dWt1 < 250 then
1048                     bC12Flg := True
1049                   else
1050                     if gstG[j].cLVCP = sCP12 then  bC12Flg := True;
1051                   if bC12Flg then
1052                    begin
1053                      for i:=0 to 17 do
1054                      begin
1055                          case  i  of
1056                             0 : StringGrid1.Cells[i, iR] := IntToStr(j) ;
1057                             1 : StringGrid1.Cells[i, iR] := FloatToStr(gstG[j].dWt1)   ;
1058                             2 : StringGrid1.Cells[i, iR] := FloatToStr(gstG[j].dInWt1) ;
1059                             3 : StringGrid1.Cells[i, iR] := gstG[j].cLVCP  ;
1060                             4 : StringGrid1.Cells[i, iR] := gstG[j].cKset  ;
1061                             5 : StringGrid1.Cells[i, iR] := gstG[j].cWean  ;
1062                             6 : StringGrid1.Cells[i, iR] := FloatToStr(gstG[j].Nutrient.dFCM) ;
1063                             7 : StringGrid1.Cells[i, iR] := FloatToStr(gstG[j].Nutrient.dDMI) ;
1064                             8 : StringGrid1.Cells[i, iR] := FloatToStr(gstG[j].Nutrient.dCP)  ;
1065                             9 : StringGrid1.Cells[i, iR] := FloatToStr(gstG[j].Nutrient.dDCP) ;
1066                            10 : StringGrid1.Cells[i, iR] := FloatToStr(gstG[j].Nutrient.dTDN) ;
1067                            11 : StringGrid1.Cells[i, iR] := FloatToStr(gstG[j].Nutrient.dDE)  ;
1068                            12 : StringGrid1.Cells[i, iR] := FloatToStr(gstG[j].Nutrient.dMEC) ;
1069                            13 : StringGrid1.Cells[i, iR] := FloatToStr(gstG[j].Nutrient.dMEJ) ;
1070                            14 : StringGrid1.Cells[i, iR] := FloatToStr(gstG[j].Nutrient.dCa)  ;
1071                            15 : StringGrid1.Cells[i, iR] := FloatToStr(gstG[j].Nutrient.dP)   ;
1072                            16 : StringGrid1.Cells[i, iR] := FloatToStr(gstG[j].Nutrient.dVA)  ;
1073                            17 : StringGrid1.Cells[i, iR] := FloatToStr(gstG[j].Nutrient.dVD)  ;
1074                          end;
1075                      end;
1076                      Inc( iR );
1077                      Application.ProcessMessages;
1078                    end;
1079               end;
1080           end;
1081       end;
1082   end;
1083   giRow4JFS := iR - 1 ;
1084 end;
1085
1086 procedure TForm1.Class_Origin2();
1087 var
1088   dBW, dLW, dZoTj  : Double;
1089   sKset, sCP12     : String;
1090   i, j, iR         : Integer;
1091   sZotj            : String;
1092   bC12Flg          : Boolean;
1093 begin
1094   dLW := StrToFloat(LabeledEdit1.Text);
1095   dBW := StrToFloat(LabeledEdit2.Text);
1096   sZotj := ComboBox3.Caption;
1097   if (sZotj <> '標準値') then dZoTj := StrToFloat(sZotj);
1098   sKset := ComboBox1.Caption;
1099   if CheckBox1.Checked then sCP12 := 'ON' else sCP12 := 'OFF';
1100   StringGrid2.Clean;
1101   iR := 1;
1102   for j:=1 to giOrgSrc do
1103   begin
1104       if (gOrign[j].dWt1 >= dLW) and (gOrign[j].dWt1 <= dBW) then
1105       begin
1106           if (sZotj = '標準値') then dZoTj := NichZotaijuAnbaichi(gOrign[j].dWt1);
1107           if gOrign[j].dInWt1 = dZoTj then
1108           begin
1109               if gOrign[j].cKset = sKset then
1110               begin
1111                   bC12Flg := False;
1112                   if gOrign[j].dWt1 < 250 then
1113                     bC12Flg := True
1114                   else
1115                     if gOrign[j].cLVCP = sCP12 then  bC12Flg := True;
1116                   if bC12Flg then
1117                   begin
1118                       if gOrign[j].cWean = '離乳前' then
1119                       begin
1120                           for i:=0 to 17 do
1121                           begin
1122                               case  i  of
1123                                  0 : StringGrid2.Cells[i, iR] := IntToStr(j) ;
1124                                  1 : StringGrid2.Cells[i, iR] := FloatToStr(gOrign[j].dWt1)   ;
1125                                  2 : StringGrid2.Cells[i, iR] := FloatToStr(gOrign[j].dInWt1) ;
1126                                  3 : StringGrid2.Cells[i, iR] := gOrign[j].cLVCP  ;
1127                                  4 : StringGrid2.Cells[i, iR] := gOrign[j].cKset  ;
1128                                  5 : StringGrid2.Cells[i, iR] := gOrign[j].cWean  ;
1129                                  6 : StringGrid2.Cells[i, iR] := FloatToStr(gOrign[j].Nutrient.dFCM) ;
1130                                  7 : StringGrid2.Cells[i, iR] := FloatToStr(gOrign[j].Nutrient.dDMI) ;
1131                                  8 : StringGrid2.Cells[i, iR] := FloatToStr(gOrign[j].Nutrient.dCP)  ;
1132                                  9 : StringGrid2.Cells[i, iR] := FloatToStr(gOrign[j].Nutrient.dDCP) ;
1133                                 10 : StringGrid2.Cells[i, iR] := FloatToStr(gOrign[j].Nutrient.dTDN) ;
1134                                 11 : StringGrid2.Cells[i, iR] := FloatToStr(gOrign[j].Nutrient.dDE)  ;
1135                                 12 : StringGrid2.Cells[i, iR] := FloatToStr(gOrign[j].Nutrient.dMEC) ;
1136                                 13 : StringGrid2.Cells[i, iR] := FloatToStr(gOrign[j].Nutrient.dMEJ) ;
1137                                 14 : StringGrid2.Cells[i, iR] := FloatToStr(gOrign[j].Nutrient.dCa)  ;
1138                                 15 : StringGrid2.Cells[i, iR] := FloatToStr(gOrign[j].Nutrient.dP)   ;
1139                                 16 : StringGrid2.Cells[i, iR] := FloatToStr(gOrign[j].Nutrient.dVA)  ;
1140                                 17 : StringGrid2.Cells[i, iR] := FloatToStr(gOrign[j].Nutrient.dVD)  ;
1141                               end;
1142                           end;
1143                       end
1144                       else
1145                       begin
1146                           for i:=0 to 17 do
1147                           begin
1148                               case  i  of
1149                                  0 : StringGrid2.Cells[i, iR] := IntToStr(j) ;
1150                                  1 : StringGrid2.Cells[i, iR] := FloatToStr(gOrign[j].dWt1)   ;
1151                                  2 : StringGrid2.Cells[i, iR] := FloatToStr(gOrign[j].dInWt1) ;
1152                                  3 : StringGrid2.Cells[i, iR] := gOrign[j].cLVCP  ;
1153                                  4 : StringGrid2.Cells[i, iR] := gOrign[j].cKset  ;
1154                                  5 : StringGrid2.Cells[i, iR] := gOrign[j].cWean  ;
1155                                  6 : StringGrid2.Cells[i, iR] := FloatToStr(gOrign[j].Nutrient.dFCM) ;
1156                                  7 : StringGrid2.Cells[i+12, iR] := FloatToStr(gOrign[j].Nutrient.dDMI) ;
1157                                  8 : StringGrid2.Cells[i+12, iR] := FloatToStr(gOrign[j].Nutrient.dCP)  ;
1158                                  9 : StringGrid2.Cells[i+12, iR] := FloatToStr(gOrign[j].Nutrient.dDCP) ;
1159                                 10 : StringGrid2.Cells[i+12, iR] := FloatToStr(gOrign[j].Nutrient.dTDN) ;
1160                                 11 : StringGrid2.Cells[i+12, iR] := FloatToStr(gOrign[j].Nutrient.dDE)  ;
1161                                 12 : StringGrid2.Cells[i+12, iR] := FloatToStr(gOrign[j].Nutrient.dMEC) ;
1162                                 13 : StringGrid2.Cells[i+12, iR] := FloatToStr(gOrign[j].Nutrient.dMEJ) ;
1163                                 14 : StringGrid2.Cells[i+12, iR] := FloatToStr(gOrign[j].Nutrient.dCa)  ;
1164                                 15 : StringGrid2.Cells[i+12, iR] := FloatToStr(gOrign[j].Nutrient.dP)   ;
1165                                 16 : StringGrid2.Cells[i+12, iR] := FloatToStr(gOrign[j].Nutrient.dVA)  ;
1166                                 17 : StringGrid2.Cells[i+12, iR] := FloatToStr(gOrign[j].Nutrient.dVD)  ;
1167                               end;
1168                           end;
1169                       end;
1170                       Inc( iR );
1171                       Application.ProcessMessages;
1172                   end;
1173               end;
1174           end;
1175       end;
1176   end;
1177   giRow4Orign := iR - 1 ;
1178 end;
1179
1180 procedure TForm1.GraphOutPut();
1181   var iKbn : Integer;
1182 begin
1183   JapaneseFeedingStandard.Clear;
1184   Origin2BeforeWeaning.Clear;
1185   Origin2AfterWeaning.Clear;
1186   RegressionCurveJFS.Clear;
1187   RegressionCurveOriginBefore.Clear;
1188   RegressionCurveOriginAfter.Clear;
1189   Label7.Caption := '';
1190   Label8.Caption := '';
1191   Label9.Caption := '';
1192   JapaneseFeedingStandard.LinePen.Color:=clRed;
1193   Origin2BeforeWeaning.LinePen.Color:=clGreen;
1194   Origin2AfterWeaning.LinePen.Color:=clBlue;
1195   JapaneseFeedingStandard.Pointer.HorizSize := fMarker.gMrkSze[1];
1196   JapaneseFeedingStandard.Pointer.VertSize  := fMarker.gMrkSze[1];
1197   Origin2BeforeWeaning.Pointer.HorizSize := fMarker.gMrkSze[2];
1198   Origin2BeforeWeaning.Pointer.VertSize  := fMarker.gMrkSze[2];
1199   Origin2AfterWeaning.Pointer.HorizSize := fMarker.gMrkSze[3];
1200   Origin2AfterWeaning.Pointer.VertSize  := fMarker.gMrkSze[3];
1201   if ComboBox2.Text = 'DMI' then
1202       Chart1.AxisList.Axes[0].Title.Caption := 'DMI (kg)'
1203   else if ComboBox2.Text = 'CP'  then
1204       Chart1.AxisList.Axes[0].Title.Caption := 'CP (g)'
1205   else if ComboBox2.Text = 'DCP' then
1206       Chart1.AxisList.Axes[0].Title.Caption := 'DCP (g)'
1207   else if ComboBox2.Text = 'TDN' then
1208       Chart1.AxisList.Axes[0].Title.Caption := 'TDN (kg)'
1209   else if ComboBox2.Text = 'DE' then
1210       Chart1.AxisList.Axes[0].Title.Caption := 'DE (Mcal)'
1211   else if ComboBox2.Text = 'ME(Mcal)' then
1212       Chart1.AxisList.Axes[0].Title.Caption := 'ME (Mcal)'
1213   else if ComboBox2.Text = 'ME(MJ)' then
1214       Chart1.AxisList.Axes[0].Title.Caption := 'ME (MJ)'
1215   else if ComboBox2.Text = 'Ca' then
1216       Chart1.AxisList.Axes[0].Title.Caption := 'Ca (g)'
1217   else if ComboBox2.Text = 'P' then
1218       Chart1.AxisList.Axes[0].Title.Caption := 'P (g)'
1219   else if ComboBox2.Text = 'VA' then
1220       Chart1.AxisList.Axes[0].Title.Caption := 'VA (1000IU)'
1221   else if ComboBox2.Text = 'VD' then
1222       Chart1.AxisList.Axes[0].Title.Caption := 'VD (1000IU)';
1223   if CheckBox2.Checked then  GraphDraw4JFS();
1224   iKbn := 0;
1225   if CheckBox3.Checked then  iKbn := iKbn +  1;
1226   if CheckBox4.Checked then  iKbn := iKbn + 10;
1227   if iKbn > 0 then  GraphDraw4Origin2( iKbn );
1228 end;
1229
1230 procedure TForm1.GraphDraw4JFS();
1231 var
1232   i, iB : Integer;
1233   dWt, dWrk : Double;
1234   sWrk : String;
1235 begin
1236   if ComboBox2.Text = 'DMI' then
1237       iB := 7
1238   else if ComboBox2.Text = 'CP'  then
1239       iB := 8
1240   else if ComboBox2.Text = 'DCP' then
1241       iB := 9
1242    else if ComboBox2.Text = 'TDN' then
1243       iB := 10
1244    else if ComboBox2.Text = 'DE' then
1245       iB := 11
1246    else if ComboBox2.Text = 'ME(Mcal)' then
1247       iB := 12
1248    else if ComboBox2.Text = 'ME(MJ)' then
1249       iB := 13
1250    else if ComboBox2.Text = 'Ca' then
1251       iB := 14
1252    else if ComboBox2.Text = 'P' then
1253       iB := 15
1254    else if ComboBox2.Text = 'VA' then
1255       iB := 16
1256    else if ComboBox2.Text = 'VD' then
1257       iB := 17;
1258   for i:=1 to giRow4JFS do
1259     begin
1260       dWt  := StrToFloat(StringGrid1.Cells[1,i]);
1261       sWrk := StringGrid1.Cells[iB,i];
1262       if Trim(sWrk) <> '' then
1263         begin
1264           dWrk := StrToFloat(StringGrid1.Cells[iB,i]);
1265           JapaneseFeedingStandard.AddXY(dWt, dWrk);
1266         end;
1267     end;
1268 end;
1269
1270 procedure TForm1.GraphDraw4Origin2(var iKbn : Integer);
1271 var
1272   i, iA, iB : Integer;
1273   dWt, dWrk : Double;
1274   sWrk : String;
1275 begin
1276   if ComboBox2.Text = 'DMI' then
1277     begin
1278       iB := 7;
1279       iA := 19;
1280     end
1281   else if ComboBox2.Text = 'CP'  then
1282     begin
1283       iB := 8;
1284       iA := 20;
1285     end
1286   else if ComboBox2.Text = 'DCP' then
1287     begin
1288       iB := 9;
1289       iA := 21;
1290     end
1291    else if ComboBox2.Text = 'TDN' then
1292     begin
1293       iB := 10;
1294       iA := 22;
1295     end
1296    else if ComboBox2.Text = 'DE' then
1297      begin
1298        iB := 11;
1299        iA := 23;
1300      end
1301    else if ComboBox2.Text = 'ME(Mcal)' then
1302      begin
1303        iB := 12;
1304        iA := 24;
1305      end
1306    else if ComboBox2.Text = 'ME(MJ)' then
1307      begin
1308        iB := 13;
1309        iA := 25;
1310      end
1311    else if ComboBox2.Text = 'Ca' then
1312      begin
1313        iB := 14;
1314        iA := 26;
1315      end
1316    else if ComboBox2.Text = 'P' then
1317      begin
1318        iB := 15;
1319        iA := 27;
1320      end
1321    else if ComboBox2.Text = 'VA' then
1322      begin
1323        iB := 16;
1324        iA := 28;
1325      end
1326    else if ComboBox2.Text = 'VD' then
1327      begin
1328        iB := 17;
1329        iA := 29;
1330      end;
1331   for i:=1 to giRow4Orign do
1332     begin
1333       if (iKbn = 1) or (iKbn = 11) then
1334       begin
1335         dWt  := StrToFloat(StringGrid2.Cells[1,i]);
1336         sWrk := StringGrid2.Cells[iB,i];
1337         if Trim(sWrk) <> '' then
1338           begin
1339             dWrk := StrToFloat(StringGrid2.Cells[iB,i]);
1340             Origin2BeforeWeaning.AddXY(dWt, dWrk);
1341           end;
1342       end;
1343       if (iKbn = 10) or (iKbn = 11) then
1344       begin
1345         dWt  := StrToFloat(StringGrid2.Cells[1,i]);
1346         sWrk := StringGrid2.Cells[iA,i];
1347         if Trim(sWrk) <> '' then
1348           begin
1349             dWrk := StrToFloat(StringGrid2.Cells[iA,i]);
1350             Origin2AfterWeaning.AddXY(dWt, dWrk);
1351           end;
1352       end;
1353     end;
1354 end;
1355
1356 function TForm1.NichZotaijuAnbaichi(var dWt : Double) : Double;
1357 begin
1358   if( dWt >=  40 ) then NichZotaijuAnbaichi := 0.0 ;
1359   if( dWt >=  43 ) then NichZotaijuAnbaichi := 0.1 ;
1360   if( dWt >=  44 ) then NichZotaijuAnbaichi := 0.2 ;
1361   if( dWt >=  45 ) then NichZotaijuAnbaichi := 0.3 ;
1362   if( dWt >=  46 ) then NichZotaijuAnbaichi := 0.4 ;
1363   if( dWt >=  48 ) then NichZotaijuAnbaichi := 0.5 ;
1364   if( dWt >=  51 ) then NichZotaijuAnbaichi := 0.6 ;
1365   if( dWt >=  55 ) then NichZotaijuAnbaichi := 0.7 ;
1366   if( dWt >=  60 ) then NichZotaijuAnbaichi := 0.8 ;
1367   if( dWt >=  69 ) then NichZotaijuAnbaichi := 0.9 ;
1368   if( dWt >=  73 ) then NichZotaijuAnbaichi := 1.0 ;
1369   if( dWt >= 130 ) then NichZotaijuAnbaichi := 0.9 ;
1370   if( dWt >= 214 ) then NichZotaijuAnbaichi := 0.8 ;
1371   if( dWt >= 282 ) then NichZotaijuAnbaichi := 0.7 ;
1372   if( dWt >= 345 ) then NichZotaijuAnbaichi := 0.6 ;
1373   if( dWt >= 404 ) then NichZotaijuAnbaichi := 0.5 ;
1374   if( dWt >= 462 ) then NichZotaijuAnbaichi := 0.4 ;
1375   if( dWt >= 518 ) then NichZotaijuAnbaichi := 0.3 ;
1376   if( dWt >= 573 ) then NichZotaijuAnbaichi := 0.2 ;
1377   if( dWt >= 627 ) then NichZotaijuAnbaichi := 0.1 ;
1378   if( dWt >= 681 ) then NichZotaijuAnbaichi := 0.0 ;
1379 end;
1380
1381
1382 end.
1383