unit imain;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls,math;

type
  TfmIMain = class(TForm)
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    Button4: TButton;
    Button5: TButton;
    BtnDevices: TButton;
    Button6: TButton;
    Button7: TButton;
    Button8: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure Button5Click(Sender: TObject);
    procedure BtnDevicesClick(Sender: TObject);
    procedure Button6Click(Sender: TObject);
    procedure Button7Click(Sender: TObject);
    procedure Button8Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  fmIMain: TfmIMain;

implementation

uses Series,PwrCurveGr, Data, WVelPeriodGr, GraphBase, PwrProductGr,
  WDataEd, RootsEqu, DeviceSel, LoadConst, phDataEd, FormHolder;

{$R *.DFM}

procedure TfmIMain.Button1Click(Sender: TObject);
begin
{
  with TFmPwrCurveGr.Create('C:\Program Files\Wasp6\Power curves\Nordex N27 (150 kW).pow') do
  try
    ShowModal;
  finally
    Free;
  end
}  
end;

procedure TfmIMain.Button2Click(Sender: TObject);
var
 meas : TMeasurments;
begin
  Meas := TMeasurments.Create;
  Meas.LoadFromAsciiFile('C:\windsum\diasdata.exp');
  with TFmWVelPeriodGr.Create(Application) do
  try
    AssignWindData(Meas);
    ShowModal;
  finally
    Free;
  end;
end;

procedure TfmIMain.Button3Click(Sender: TObject);
var
 Meas : TMeasurments;
 PwrC : TWindPwrCurve;
 i       : integer;
 p,pttl       : float;
 dtBase       : TDateTime;
begin
  Meas := TMeasurments.Create;
  Meas.LoadFromAsciiFile('C:\windsum\diasdata.exp');
  PwrC := TWindPwrCurve.Create;
  PwrC.LoadFromWaspPow('C:\Program Files\Wasp6\Power curves\Vestas V20 (100 kW).pow');
  dtBase := EncodeDate(1991,1,1);
  with TFmPwrProductGr.Create(Application) do
  try
    pttl := 0;
    for i:=0 to Meas.Count-1 do
    begin
      p := PwrC.PwrAt(Meas.WindVelocity[i]);
      Series1.AddXY(dtBase+i/24,p);
      pttl := pttl + p;
    end;
    Chart1.Title.Text.Add(Format('ttl %8.0n kWh',[pttl/1000]));
    ShowModal;
  finally
    Free;
  end;
end;

procedure TfmIMain.Button4Click(Sender: TObject);
var
 Meas : TMeasurments;
begin
  Meas := TMeasurments.Create;
  Meas.LoadFromAsciiFile('C:\windsum\diasdata.exp');
  with TFmWDataEd.Create(Meas) do
  try
    ShowModal;
  finally
    Free;
  end;
end;

procedure TfmIMain.Button5Click(Sender: TObject);
const
  k = 1.62;
  C = 6.0;
  iMax = 8;

  function iwbp(x : float) : float;
  begin
    result := wbp(c,k,x);
  end;

  function iwb(x : float) : float;
  begin
    result := wb(c,k,x);
  end;

  function dwb(x : float) : float;
  var
   h,f : float;
   ff  : float;
  begin
    h := 0.1;
    f := (iwb(x+h)-iwb(x))/h;
    h := 0.01;
    ff := (iwb(x+h)-iwb(x))/h;
    while abs(f-ff)>1e-4 do
    begin
      f := ff;
      h := h/10;
      ff:= (iwb(x+h)-iwb(x))/h;
    end;
    result := ff;
  end;


var
  x     : float;
  iter  : integer;
  Series,
  pSeries ,
  p2Series : TFastLineSeries;
begin

  with TfmGraphBase.Create(Application) do
  try
    Series:=TFastLineSeries.Create(Chart1);
    Series.ParentChart := Chart1;
    pSeries:=TFastLineSeries.Create(Chart1);
    pSeries.ParentChart := Chart1;
    p2Series:=TFastLineSeries.Create(Chart1);
    p2Series.ParentChart := Chart1;
    for iter:=1 to 40 do
    begin
      x :=iter/40*imax;
      Series.addXY(x,iwb(x));
      pSeries.AddXY(x,iwbp(x));
    end;
    ShowModal
  finally
    Free;
  end;
end;

procedure TfmIMain.BtnDevicesClick(Sender: TObject);
begin
  with TfmDevSel.Create(Application) do
  try
   ShowModal;
  finally
   Free;
  end;
end;

procedure TfmIMain.Button6Click(Sender: TObject);
begin
  with TfmLoadConstr.Create(Application) do
  try
    ShowModal;
  finally
    Free; 
  end;
end;

procedure TfmIMain.Button7Click(Sender: TObject);
begin
  with TFmPhDataEd.Create(application) do
  try
    ShowModal;
  finally
    Free;
  end;
end;

procedure TfmIMain.Button8Click(Sender: TObject);
begin
  with TfmHolder.Create(application) do
  try
   ShowModal;
  finally
   free;
  end;
end;

end.
