// unit UANOVARep;     (*  ÚFJԂPv    *)
// 
// interface
// 
// uses
//   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
//   Grids, StdCtrls;
// 
// type
//   TForm1 = class(TForm)
//     StringGrid1: TStringGrid;
//     AddButton: TButton;
//     ExitButton: TButton;
//     DelButton: TButton;
//     CalcButton: TButton;
//     SaveButton: TButton;
//     LoadButton: TButton;
//     SaveDialog1: TSaveDialog;
//     OpenDialog1: TOpenDialog;
//     PButton: TButton;
//     AddColButton: TButton;
//     DelColButton: TButton;
//     procedure ExitButtonClick(Sender: TObject);
//     procedure FormCreate(Sender: TObject);
//     procedure AddButtonClick(Sender: TObject);
//     procedure DelButtonClick(Sender: TObject);
//     procedure CalcButtonClick(Sender: TObject);
//     procedure SaveButtonClick(Sender: TObject);
//     procedure LoadButtonClick(Sender: TObject);
//     procedure PButtonClick(Sender: TObject);
//     procedure AddColButtonClick(Sender: TObject);
//     procedure DelColButtonClick(Sender: TObject);
//   private
//     { Private 錾 }
//   public
//     { Public 錾 }
//   end;
// 
// var
//   Form1: TForm1;
// 
// implementation
// 
// {$R *.DFM}
// 
// uses  Printers;
// 
// procedure TForm1.ExitButtonClick(Sender: TObject);
// begin
//            Close;
// end;
// 
// 
// procedure TForm1.FormCreate(Sender: TObject);
// var sel : TGridRect;      //  IZ̈ʒu\킷߂̌^
// begin
//     with StringGrid1 do
//       begin
//           ColCount:=2;                  //  ̐
//           RowCount:=3;                  //  ̃f[^̐
//           Font.Height:=16;
//           Cells[0,1]:='x';
//           Cells[0,2]:='1Ԗ';
//           Cells[1,0]:=' P';
//           Cells[1,1]:='xP';
//           Options:=Options-[goRangeSelect];  //  PZ̑I
//           with sel do                        //  Z̈ʒu
//             begin  Left:=1; Top:=1; Right:=1; Bottom:=1;  end;
//           Selection:=sel;                    //  IZ̐ݒ
//           Options:=[goEditing]+Options;      //  ZҏW
//           EditorMode:=true;                  //  ZҏW
//       end;
// end;
// 
// 
// (*           s̒ǉ          *)
// procedure TForm1.AddButtonClick(Sender: TObject);
// var   i, j, pos : Longint;
// begin
//       with StringGrid1 do
//         begin
//             pos:=Selection.top;
//             RowCount:=RowCount+1;
//             Cells[0,RowCount-1]:=IntToStr(RowCount-2)+'Ԗ';
//             for j:=1 to ColCount-1 do
//               Cells[j,RowCount-1]:=' ';
//             if (1 < pos) and (pos < RowCount-2) then
//               begin
//                 for i:=RowCount-1 downto pos+2 do
//                   for j:=1 to ColCount-1 do
//                     begin
//                       Cells[j,i]:=Cells[j,i-1];
//                     end;
// 
//                 for j:=1 to ColCount-1 do
//                   Cells[j,pos+1]:=' ';
//               end;
//         end;
// end;
// 
// (*         ̒ǉ        *)
// procedure TForm1.AddColButtonClick(Sender: TObject);
// var   i, j, pos : Longint;
// begin
//       with StringGrid1 do
//         begin
//             pos:=Selection.Left;
//             ColCount:=ColCount+1;
//             for j:=1 to ColCount-1 do
//               Cells[j,0]:=' '+IntToStr(j);
//             for i:=1 to RowCount-1 do
//               Cells[ColCount-1,i]:=' ';
//             if (0 < pos) and (pos < ColCount-2) then
//               begin
//                 for i:=ColCount-1 downto pos+2 do
//                   for j:=1 to RowCount-1 do
//                     Cells[i,j]:=Cells[i-1,j];
// 
//                 for j:=1 to RowCount-1 do
//                   Cells[pos+1,j]:=' ';
//               end;
//         end;
// end;
// 
// (*          s̍폜           *)
// procedure TForm1.DelButtonClick(Sender: TObject);
// var pos, i, j : Longint;
// begin
//     with StringGrid1 do
//       begin
//         pos:= Selection.top;     //  Is̐ݒ
// 
//         //   Z̒l̈ړ
//         if (1 < pos) and (pos < RowCount-1) then
//             for i:=pos to RowCount-2 do
//               for j:=1 to ColCount-1 do
//                 Cells[j,i]:=Cells[j,i+1];
// 
//            //   Ō̍s폜
//         if 1 < pos then
//           if RowCount > 2 then RowCount:=RowCount-1;
//         for i:=2 to RowCount-1 do
//           Cells[0,i]:=IntToStr(i-1)+'Ԗ';  
//       end;
// end;
// 
// (*      ̍폜      *)
// procedure TForm1.DelColButtonClick(Sender: TObject);
// var pos, i, j : Longint;
// begin
//     with StringGrid1 do
//       begin
//         pos:= Selection.Left;     //  I̐ݒ
// 
//         //   Z̒l̈ړ
//         if (0 < pos) and (pos < ColCount-1) then
//             for i:=pos to ColCount-2 do
//               for j:=1 to RowCount-1 do
//                 Cells[i,j]:=Cells[i+1,j];
// 
//         //   Ō̗폜
//         if 0 < pos then
//           if ColCount > 2 then ColCount:=ColCount-1;
//         for i:=1 to ColCount-1 do
//           Cells[i,0]:=' '+IntToStr(i);  
//       end;
// end;
// 
// procedure TForm1.CalcButtonClick(Sender: TObject);
// var      outf        : TextFile;
//          nm          : string;
//          y           : array of array of Extended;
//          my_i        : array of Extended;
//          my_j        : array of Extended;
//          a, n, i, j  : Longint;
//          g_my, ss, ss_s, ss_a, ss_sa, ms_s, ms_a, ms_sa, f : Extended;
// begin
//     with StringGrid1 do
//       begin
//         n:=RowCount-2;   //   f[^̐ݒ
//         a:=Colcount-1;   //   ̐
//         SetLength(y,n+1,a+1);
//         SetLength(my_i, n+1);
//         SetLength(my_j, a+1);
//         try
//           for i := 1 to n do      //  f[^̓ǂݍ
//               for j := 1 to a do
//                 y[i, j]:=StrToFloat(Cells[j,i+1]);
//         except                             //   sȃf[^
//           ShowMessage('Error ===>  Cells[1,'+IntToStr(i)+'] = '
//                        +Cells[1,i]);
//           Exit;   //   ̎葱̏I
//         end;
//       end;
// 
//     with OpenDialog1 do
//       begin
//         Title:='vZʂ̏o͗pt@C';
//         FileName:='';
//         Execute;
//         AssignFile(outf,FileName);
//         Rewrite(outf);
//       end;
// 
//      writeln(outf, 'f[^ =');
//      for i := 1 to n do
//        begin
//          for j := 1 to a do write(outf, y[i, j]:10:2);
//          writeln(outf);
//        end;
// 
//      g_my:=0.0;
//      for i:=1 to n do
//        begin
//          my_i[i]:=0.0;
//          for j:=1 to a do my_i[i]:=my_i[i]+y[i,j];
//          my_i[i]:=my_i[i]/a;       //  팱i̕
//          g_my:=g_my+my_i[i];
//        end;
//      g_my:=g_my/n;        //  Ŝ̕
// 
//      for j:=1 to a do
//        begin
//          my_j[j]:=0.0;
//          for i:=1 to n do my_j[j]:=my_j[j]+y[i,j];
//          my_j[j]:=my_j[j]/n;       //  j̕
//        end;
// 
//      writeln(outf);
//      writeln(outf, 'ϒl');
//      for j:=1 to a do write(outf, my_j[j]:10:2);
// 
//      ss:=0.0; ss_a:=0.0; ss_s:=0.0;
//      for i:=1 to n do
//        for j:=1 to a do
//          begin
//            ss  :=ss+sqr(y[i,j]-g_my);     //  Ŝ̕ϓ
//            ss_a:=ss_a+sqr(my_j[j]-g_my);  //  Ԃ̕ϓiʁj
//            ss_s:=ss_s+sqr(my_i[i]-g_my);  //  팱ҊԂ̕ϓ
//          end;
//      ss_sa:=ss-ss_a-ss_s;             //  ݍp
// 
//      (*   ϕǎvZ   *)
// 
//      ms_s  := ss_s/(n - 1);
//      ms_a  := ss_a/(a - 1);
//      ms_sa := ss_sa/((n - 1) * (a - 1));
// 
//      f     := ms_a/ms_sa;             //  el
// 
//      writeln(outf); writeln(outf);
//      writeln(outf, '                 ',
//                     '       a@@Rx@@ϕa@  @    e');
//      writeln(outf, '팱Ҋ        ',
//                      ss_s:15:3, (n-1):7, ms_s:15:3);
//      writeln(outf, 'viʁj  ',
//                      ss_a:15:3, (a-1):7, ms_a:15:3, f:15:3);
//      writeln(outf, 'ciݍpj',
//                      ss_sa:15:3, (n-1)*(a-1):7, ms_sa:15:3);
// 
//      Closefile(outf);
// 
//      Finalize(y);
//      Finalize(my_i);
//      Finalize(my_j);
// 
//      ExitButton.SetFocus;
// end;
// 
// (*    Obhɐݒ肳Ăf[^̕ۑ    *)
// procedure TForm1.SaveButtonClick(Sender: TObject);
// var outf : TextFile;
//     h, i : Longint;
// begin
//     with SaveDialog1 do        //   ۑpt@C̖O̐ݒ
//       begin
//           Title:='t@C';
//           Execute;
//           AssignFile(outf,FileName);
//       end;
// 
//     Rewrite(outf);            //  t@Copɐݒ
// 
//     with StringGrid1 do
//       begin
//         writeln(outf,ColCount-2);
//         writeln(outf,RowCount-2);
//         for h:=1 to ColCount-1 do
//           begin
//             writeln(outf,Cells[h,1]);
//             for i:=2 to RowCount-1 do
//               writeln(outf, Trim(Cells[h,i])); //  f[^̏o
//           end;
//       end;
// 
//     CloseFile(outf);
// end;
// 
// (*    t@CObhփf[^ǂݍ    *)
// procedure TForm1.LoadButtonClick(Sender: TObject);
// var inf : TextFile;
//     v, h, i   : Longint;
//     s      : string;
// begin
//     with OpenDialog1 do           //  t@C̐ݒ
//       begin
//           Title:='t@C';
//           Execute;
//           AssignFile(inf,FileName);
//       end;
// 
//     Reset(inf);                  //   t@Cǂݏopɐݒ
// 
//     with StringGrid1 do
//       begin
//         readln(inf,v);          //   f[^̓ǂݍ
//         ColCount:=v+2;
//         readln(inf,v);
//         RowCount:=v+2;
//         for h:=1 to ColCount-1 do
//           for i:=1 to RowCount-1 do
//             begin
//               readln(inf,s);     //    f[^̓ǂݍ
//               Cells[h,i]:=s;
//             end;
// 
//         for i:=2 to RowCount-1 do
//           Cells[0,i]:=IntToStr(i-1)+'Ԗ';
//         for h:=1 to ColCount-1 do
//           Cells[h,0]:=' '+IntToStr(h);
//       end;
// 
//     CloseFile(inf);
// end;
// 
// procedure TForm1.PButtonClick(Sender: TObject);
// var   pout : TextFile;
//       h, i    : Longint;
// begin
//       with printer do
//         begin
//           AssignPrn(pout);
//           Rewrite(pout);
// 
//           with Canvas.Font do
//             begin
//                 Name:='lr ';
//                 size:=16;
//             end;
// 
//           writeln(pout);
//           writeln(pout);
//           writeln(pout,'Data =');
// 
//           with StringGrid1 do
//             for h:=1 to ColCount-1 do
//               begin
//                 writeln(pout,'',h,' ==> ',Cells[h,1]);
//             for i:=2 to RowCount-1 do
//               writeln(pout,i:5,'   ',Cells[h,i]);
//               end;
//           CloseFile(pout);
//         end;
// end;
// 
// end.
