unit LBRMTypes;

interface

uses  SysUtils, Classes, StdCtrls, Arrays;

type
   TParmArray  = array[1..9] of single;
   TDigitArray = array[1..9] of integer;
   TCondArray  = array[1..5] of single;   // USZM, LSZM, GZM, SurfZM, SnowZM
   TMetData    = array[1..3] of TMyArrayOfInt;     // Tmax, Tmin, Prec

   TEditPtr    = ^TEdit;

   TConfigInfo = record
      WorkDir   : string;     // working directory
      ParmFile  : string;     // parameters
      BoundFile : string;     // boundary conditions
      MetFile   : string;     // met data
      FlowFile  : string;     // measured flow
      LBRMFile  : string;     // model output
   end;

   TParameterInfo = record
      SDate, EDate, CDate, CurrentParm : longint;
      Area, USZC    : single;
      KCons, B1, B2 : single;
      RMSE, Correlation : single;
      IDString      : string;
      Insolation    : array [1..12] of single;
      Comments      : array [1..50] of string;
      ParmNow, ParmMin, ParmMax, ParmOpt : TParmArray;
      DigitNow, DigitMax                 : TDigitArray;
   end;

   TBoundInfo = record
      SeqNum : longint;                      // date as a sequence number
      USZM, LSZM, GZM, SURF, SNOW : single;  // storages
   end;

   TBoundaryInfo = class
   private
      fCount  : integer;
      TheList : TList;
      Missing : TBoundInfo;
      function Get(Indeks : longint) : TBoundInfo;
      procedure Put(Indeks : longint; Value : TBoundInfo);
   public
      HeaderLine1, HeaderLine2 : string;

      constructor Create;
      destructor  Destroy; override;
      property    TheValue [N : longint] : TBoundInfo
                  read Get  write Put;  default;
      property    Count : integer
                  read fCount write fCount;
      procedure   Add(BI : TBoundInfo);
      procedure   Clear;
   end;


   procedure ClearConfigInfo(CI : TConfigInfo);
   procedure ClearParmInfo(PI : TParameterInfo);

implementation

{$RANGECHECKS OFF}

//------------------------
procedure ClearConfigInfo(CI : TConfigInfo);
begin
   with CI do begin
      WorkDir   := '';
      ParmFile  := '';
      BoundFile := '';
      MetFile   := '';
      FlowFile  := '';
      LBRMFile  := '';
   end;
end;

//------------------------
procedure ClearParmInfo(PI : TParameterInfo);
var
   I : integer;
begin
   with PI do begin
      SDate := 0;
      EDate := 0;
      CDate := 0;
      CurrentParm := 0;
      Area := 0.0;
      USZC := 0.0;
      RMSE := 0.0;
      Correlation := 0.0;
      IDString := '';
   end;

   for I:=1 to 12 do PI.Insolation[I] := 0.0;
   for I:=1 to 50 do PI.Comments[I] := '';
   for I:=1 to 9 do begin
      PI.ParmNow[I] := 0.0;
      PI.ParmMin[I] := 0.0;
      PI.ParmMax[I] := 0.0;
      PI.ParmOpt[I] := 0.0;
      PI.DigitNow[I] := 1;
      PI.DigitMax[I] := 1;
   end;
end;

//------------------------
constructor TBoundaryInfo.Create;
begin
   fCount := 0;
   TheList := TList.Create;
   TheList.Capacity := 25;     // allocate 25 pointers
   Missing.SeqNum := -9999;
   Missing.USZM   := -9999.999;
   Missing.LSZM   := -9999.999;
   Missing.GZM    := -9999.999;
   Missing.SURF   := -9999.999;
   Missing.SNOW   := -9999.999;
end;

//------------------------
destructor TBoundaryInfo.Destroy;
begin
   if (TheList <> nil) then begin
      TheList.Clear;
      TheList.Free;
   end;
   inherited Destroy;
end;

//------------------------
//
//  Item index is 0..n-1
//
function TBoundaryInfo.Get(Indeks : longint) : TBoundInfo;
begin
   Result := Missing;           // default if index out of range
   if (Indeks < 0) then exit;
   if (Indeks > TheList.Count-1) then exit;
   Result := TBoundInfo((TheList[Indeks])^);
end;

//----------------------------------
//
//  Item index is 0..n-1
//
procedure TBoundaryInfo.Put(Indeks : longint; Value : TBoundInfo);
begin
   if (Indeks < 0) then exit;
   if (Indeks > TheList.Count-1) then exit;
   TBoundInfo(TheList[Indeks]^) := Value;
end;

//----------------------------------
procedure TBoundaryInfo.Add(BI : TBoundInfo);
var
   B2 : ^TBoundInfo;
begin
   if (Count = TheList.Capacity) then
      TheList.Capacity := TheList.Capacity + 25;
   new(B2);
   B2^ := BI;
   TheList.Add(B2);
   fCount := TheList.Count;
end;

//------------------------
procedure TBoundaryInfo.Clear;
begin
   TheList.Clear;
   TheList.Capacity := 25;
end;



end.
