type
InputArr = array of array of real;
SplitArr = array of array of real;
OutputArr = array of array of real;
{ TForm1 }
TForm1 = class(TForm)
// ...
private
public
Ni, rsplit : integer;
inter1 : array of array of real;
inttemp : array of array of real;
inter2 : array of array of real;
procedure Splitting(var Iarray : InputArr; Sarray : SplitArr; rinput : integer);
procedure Outputs(Arr : OutputArr; ncol : integer);
end;
var
Form1: TForm1;
implementation
{$R *.lfm}
{ TForm1 }
{0a - number of input rows}
procedure TForm1.Edit1Exit(Sender: TObject);
begin
Ni:=StrToInt(Edit1.Text);
StringGrid1.RowCount:=Ni+1;
end;
procedure TForm1.Splitting(var Iarray : InputArr; Sarray : SplitArr; rinput : integer);
var m, n : integer;
begin
rsplit:=2*rinput-1;
Edit2.Text:=IntToStr(rsplit);
//SetLength(Sarray, rsplit, 2);
m:=0;
while m <= rinput-1 do
begin
n:=2*m;
Sarray[n,0]:=Iarray[m,0];
Sarray[n,1]:=Iarray[m,1];
if m = rinput-1 then
m:=m+1
else
begin
n:=n+1;
Sarray[n,0]:=(Iarray[m,0]+Iarray[m+1,0])/2;
Sarray[n,1]:= Iarray[m,1]+((Iarray[m+1,1]-Iarray[m,1])/(Iarray[m+1,0]-Iarray[m,0]))*(Sarray[n,0]-Sarray[n-1,0]);
m:=m+1;
end;
end;
end;
procedure TForm1.Outputs(Arr : OutputArr; ncol : integer);
var rout, cout : integer;
begin
//Processed Array -> StringGrid2
for cout:=0 to 1 do
begin
for rout:=0 to StringGrid2.RowCount-2 do
begin
if cout = 0 then StringGrid2.Cells[cout,rout+1]:=FloatToStr(Arr[rout,cout])
else StringGrid2.Cells[ncol,rout+1]:=FloatToStr(Arr[rout,cout]);
end;
end;
end;
{1 - interpolation}
procedure TForm1.Button1Click(Sender: TObject);
var
i, j, k, ncycle, acol, qnt, No : integer;
begin
Chart1LineSeries1.Clear;
Chart1LineSeries2.Clear;
//No:=StrToInt(Edit2.Text);
//StringGrid2.RowCount:=No+1;
SetLength(inter1, StringGrid1.RowCount-1, 2);
//SetLength(inter2, StringGrid2.RowCount-1, 2);
acol:=1;
//checking the elements
for k:=1 to StringGrid1.RowCount-1 do
begin
if (StringGrid1.Cells[0, k]='') or (StringGrid1.Cells[1, k]='')
then
begin
ShowMessage('Check your input data');
Exit;
end;
end;
//StringGrid1 -> Input Array
for i:=0 to StringGrid1.RowCount-2 do
begin
for j:=0 to 1 do
begin
inter1[i,j]:= StrToFloat(StringGrid1.Cells[j,i+1]);
end;
end;
ncycle:=StrToInt(Edit2.Text) Div StrToInt(Edit1.Text);
if ncycle > 0 then
if ncycle*StrToInt(Edit1.Text)/StrToInt(Edit2.Text) <= 0.80
then ncycle:=ncycle+1 else ncycle:=ncycle+0;
if ncycle <= 0 then begin
ShowMessage('Check the number of output data points');
Exit;
end;
//Input Array -> Interpolated Array
for qnt:= 0 to ncycle-1 do
begin
if qnt = 0 then
begin
SetLength(inter2, 2*Ni-1, 2);
Splitting(inter1, inter2, Ni);
end
else
begin
SetLength(inter2, rsplit, 2);
Splitting(inter2, inter2, rsplit);
end;
end;
StringGrid2.RowCount:=rsplit+1;
//Interpolated Array -> SringGrid2
Outputs(inter2, acol);
end;