unit Unit1;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ValEdit,
  ExtCtrls, Menus, ComCtrls, StdCtrls,
  gnuplot, AccPampa, Unit2, Unit4, Unit5, Unit7, Unit8, Unit6;

type

  { TForm1 }

  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    ImageList1: TImageList;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    Label6: TLabel;
    MainMenu1: TMainMenu;
    MenuItem1: TMenuItem;
    MenuItem12: TMenuItem;
    MenuItem13: TMenuItem;
    MenuItem14: TMenuItem;
    MenuItem2: TMenuItem;
    MenuItem3: TMenuItem;
    MenuItem4: TMenuItem;
    MenuItem5: TMenuItem;
    MenuItem6: TMenuItem;
    MenuItem7: TMenuItem;
    MenuItem8: TMenuItem;
    MenuItem9: TMenuItem;
    OpenDialog1: TOpenDialog;
    Panel1: TPanel;
    SaveDialog1: TSaveDialog;
    ToolBar1: TToolBar;
    ToolButton1: TToolButton;
    ToolButton3: TToolButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Form1Crate(Sender: TObject);
    procedure Label5Click(Sender: TObject);
    procedure MenuItem10Click(Sender: TObject);
    procedure MenuItem12Click(Sender: TObject);
    procedure MenuItem13Click(Sender: TObject);
    procedure MenuItem14Click(Sender: TObject);
    procedure MenuItem2Click(Sender: TObject);
    procedure MenuItem3Click(Sender: TObject);
    procedure MenuItem4Click(Sender: TObject);
    procedure MenuItem5Click(Sender: TObject);
    procedure MenuItem6Click(Sender: TObject);
    procedure MenuItem7Click(Sender: TObject);
    procedure MenuItem9Click(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure ToolButton2Click(Sender: TObject);
    procedure ToolButton3Click(Sender: TObject);
    procedure ToolButton4Click(Sender: TObject);
  private
    { private declarations }
  public
    { public declarations }
  end;

var
  Form1: TForm1;

implementation

uses Refinar;

{$R *.lfm}

{ TForm1 }

procedure TForm1.Form1Crate(Sender: TObject);
   Var i,j,tam:Integer;
begin
  SistOp:=1;
  Case SistOp of
    1: DiUser := '/home/tabatha/PAMPA/';
    2: DiUser := 'c:\PAMPA\';
  End;

  For i:=1 To 30 Do For j:=1 To 30 Do Borde[i,j]:='  ';
  C1:=False;
  C2:=False;
  label2.Caption:=FloatToStr(Iter);
  label4.Caption:=FloatToStr(Chi2);
  label6.Caption := FloatToStr(NPR);
  Ndet:=0;
  Nnodet:=0;
  Nfdet:=0;
  Nfnodet:=0;
  NG:=0;
  Espesor:=0;
  EspesorFilm:=0;
  Nzonas:=0;
  For i:=1 To np Do Lam[i]:=0.01;
  Archivos;
end;

procedure TForm1.Label5Click(Sender: TObject);
begin

end;

procedure TForm1.MenuItem10Click(Sender: TObject);
begin

end;

procedure TForm1.MenuItem4Click(Sender: TObject);     {Archivo:Abrir}
Var i,tam:Integer;
begin
  if OpenDialog1.Execute then begin
      DiDat := OpenDialog1.Filename;
      {ShowMessage(DiDat);}
  end;
  tam:=Length(DiDat);
  DiSal:=Copy(DiDat, 0, tam-4);
  Form2.Form2new();
  Form4.Form4new();
  c1:=False;
  c2:=False;
  Form5.Form5new();
  Form6.Form6new();
  Form7.Form7new();
  Leer;
  Leer_esp;
  If(Espesor<>0) Then C1:=True;
  If(EspesorFilm<>0) Then C2:=True;
  For i:=0 To 30 Do Zd1[i].Visible:=False;
  For i:=0 To 30 Do Znd1[i].Visible:=False;
  For i:=0 To 30 Do Zd2[i].Visible:=False;
  For i:=0 To 30 Do Znd2[i].Visible:=False;
end;

procedure TForm1.MenuItem5Click(Sender: TObject);     {Archivo:Guardar}
  Var tam,i:Integer;
begin
  if SaveDialog1.Execute then
    begin
      DiDat2 := SaveDialog1.Filename;
    end;
  tam:=Length(DiDat2);
  DiSal:=Copy(DiDat2, 0, tam-4);{toma el string DiDat2 y le quita los ultimos 4 caracteres}
  {ShowMessage(DiSal);}
  Escribir;
  EscribirSal;
end;

procedure TForm1.MenuItem6Click(Sender: TObject);     {Archivo:Nuevo}
begin
  {Parametros de Form2 'Blanco'}
  Form2.Form2new();
  Form4.Form4new();
  c1:=False;
  c2:=False;
  Form5.Form5new();
  Form6.Form6new();
  Form7.Form7new();
end;


procedure TForm1.MenuItem7Click(Sender: TObject);     {Archivo:Cerrar}
begin
  Close();
end;

procedure TForm1.MenuItem3Click(Sender: TObject);     {Editar}
begin
  If(c1) Then MenuItem12.Visible:=True
  Else  MenuItem12.Visible:=False;
  If(c2) Then MenuItem13.Visible:=True
  Else  MenuItem13.Visible:=False;
end;

procedure TForm1.MenuItem9Click(Sender: TObject);     {Editar:Blanco}
begin
  Form2.show;
end;

procedure TForm1.ToolButton1Click(Sender: TObject);
begin
 Form1.MenuItem4Click(Form1);
end;

procedure TForm1.ToolButton2Click(Sender: TObject);
begin
  Form1.MenuItem6Click(Form1);
end;

procedure TForm1.ToolButton3Click(Sender: TObject);
begin
   Form1.MenuItem5Click(Form1);
end;

procedure TForm1.ToolButton4Click(Sender: TObject);
begin

end;

procedure TForm1.MenuItem2Click(Sender: TObject);     {Editar:Parametros globales}
begin
  Form4.show;
end;


procedure TForm1.MenuItem12Click(Sender: TObject);    {Editar:Parametros capa1}
begin
  Form5.show;
end;

procedure TForm1.MenuItem13Click(Sender: TObject);    {Editar:Parametros capa 2}
begin
  Form6.show;
end;

procedure TForm1.MenuItem14Click(Sender: TObject);     {Editar:Espectro}
begin
  Form7.show;
end;

procedure TForm1.Button1Click(Sender: TObject);        {Boton Refinar}
begin
    Refina;
    {    ShowmessagePos('Iteraciones='+FloatToStr(iter)+'   '+'Chi²='+FloatToStr(chi2),100,100);}
    EscribirSal;
    Graficar;
    Application.ProcessMessages;
    label2.Refresh;
    label4.Refresh;
end;

procedure TForm1.Button2Click(Sender: TObject);     {Boton: Limpiar. Para cambiar el numero de parametros a refinar a 0}
  Var i:Integer;
begin
   For i:=1 To NPG+4*NL+NG+Nel+4*NLF+Nfilm Do Cod[i]:=0;
   ContNPR();

end;


end.

