unit ArrTools;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  G32_WConvolution;

  procedure SaveArr( var ms: TMemoryStream; var Arr: T2DPoint2fArr);overload;
  procedure LoadArr( var ms: TMemoryStream; var Arr: T2DPoint2fArr);overload;

  procedure SaveArr( filename : string; var Arr: T2DPoint2fArr);overload;
  procedure LoadArr( filename : string; var Arr: T2DPoint2fArr);overload;

  
  function Print2DArr( Arr : T2DPoint1fArr): String;

implementation


function Print2DArr( Arr : T2DPoint1fArr): String;
Var
 i,j  : integer;
 S_   : String;
 CR   : String;
begin
 CR:='';
 for i:=0 to High(Arr) do begin
     for j:=0 to High(Arr[i]) do begin
         S_:=format('[%d,%d]=%.6f ;',[i,j,Arr[i,j]]);
         Result:=Result+CR+S_;
         CR:='';
     end;
     CR:=#13#10;
 end;
end;


procedure SaveArr( var ms: TMemoryStream; var Arr: T2DPoint2fArr);
Var
 Point2f         : TPoint2f;
 CurveID,PointID : integer;
 DimH,DimW       : integer;
begin
//ms.Position:=0;

DimH:=Length(Arr);
ms.Write(DimH,sizeof(DimH));

For CurveID:=0 to DimH-1 do
begin
 DimW:=Length(Arr[CurveID]);
 ms.Write(DimW,sizeof(DimW));
 For PointID:=0 to DimW-1 do
  begin
   Point2f:=Arr[CurveID,PointID];
   ms.Write(Point2f,sizeof(Point2f));
  end;
end;

end;

procedure LoadArr( var ms: TMemoryStream; var Arr: T2DPoint2fArr);
Var
 Point2f         : TPoint2f;
 CurveID,PointID : integer;
 DimH,DimW       : integer;
begin
//ms.Position:=0;

ms.Read(DimH,sizeof(DimH));
Arr:=nil;
SetLength(Arr,DimH);

For CurveID:=0 to DimH-1 do
begin
 ms.Read(DimW,sizeof(DimW));
 SetLength(Arr[CurveID],DimW);
 For PointID:=0 to DimW-1 do
  begin
   ms.Read(Point2f,sizeof(Point2f));
   Arr[CurveID,PointID]:=Point2f;
  end;
end;

end;

procedure SaveArr( filename : string; var Arr: T2DPoint2fArr);
Var
 ms : TMemoryStream;
begin
 ms:=TMemoryStream.Create;
 try
  SaveArr(ms,Arr);
  ms.SaveToFile(filename);
 finally
  ms.Free;
 end;
  
end;
 
procedure LoadArr( filename : string; var Arr: T2DPoint2fArr);
Var
 ms : TMemoryStream;
begin
 ms:=TMemoryStream.Create;
 try
   ms.LoadFromFile(filename);
   LoadArr(ms,Arr);
 finally
  ms.Free;
 end;
 
end;


end.
