package TkFittingAppFlexible; use clib::TkFittingAppBase; @ISA = qw(TkFittingAppBase); use strict; use Sci qw($pi $kB $c $e $e0 $me $mp $mn $h $hbar $torad $todeg); use MyTk::MyDragDrop; sub CreateWidgets { my ($this, $DoSuperOnly) = @_; $this->{ProgramName} = "FittingTest2008"; $this->{EntryWidth} = 12; $this->{nVarColumn} = 3; $this->{pNoteBookTabs} = [qw(Main ViewRange LSQ Common Setup)], $this->{pFooterButtonsArray} = ["RePlot", "RestoreScale", "Re&calc", "&Fit"]; $this->{pChooseFileArray} = [ # $VarName, $Label, $FileName, $FrameName, # $FileMask, $pButtons, $pAxes, $pDataLabels ["Param", "Param:", "ParameterFile", "ParameterFileFrame", "*.prm", ["save", "edit"], [], [], ], ["Sample1CSV", "Sample1:", "Sample1CSVFile", "Sample1FileFrame", '*.csv;*.spe;*.jel;*.asp;*.smo;*isa;*.ref;*.pal;*.bef;*.aft', ["edit"], ['X1', 'Y1'], [['E.*', '.*eV.*'], ['T.*', 'R.*', '.*signal.*', '.*']], ], ["Sample2CSV", "Sample2:", "Sample2CSVFile", "Sample2FileFrame", '*.csv;*.spe;*.jel;*.asp;*.smo;*isa;*.ref;*.pal;*.bef;*.aft', ["edit"], ['X1', 'Y1'], [['E.*', '.*eV.*'], ['T.*', 'R.*', '.*signal.*', '.*']], ], ]; $this->{pPlotTypeArray} = [ [ ['x', 'log(|x|)'], ['x', 'log(|x|)'] ], # [ # ['x', '-x'], ['x', '-x'] # ], ]; $this->{ParameterFrameLabel} = 'Common parameters'; $this->{pParameterConfigArray} = [ # VarName VarLabel Value Format Unit ForOptimize Check Scale Min Max ['c0', 'c0', 1.0, '%12.6g', 'A', 1, 1, 1.0, '', '' ], ['c1', 'c1', 0.0, '%12.6g', 'A', 1, 1, 1.0, '', '' ], ['c2', 'c2', 0.5, '%12.6g', 'A', 1, 1, 1.0, '', '' ], ['c3', 'c3', 1.0, '%12.6g', 'A', 1, 1, 1.0, '', '' ], ['c4', 'c4', 1.0, '%12.6g', 'A', 1, 1, 1.0, '', '' ], ]; $this->SUPER::CreateWidgets(); #$this->{Optimize}->PrintParameters(1, undef, 1); my $DragDrop = new MyDragDrop(); $DragDrop->ConfigureDrop( $this->mw(), [ "\\.prm\$", $this->{ParameterFileFrame}->{PathEntry}, sub { $this->ReadParameterFile($_[0]); }, ], [ ".*", $this->{Sample1FileFrame}->{PathEntry}, sub { $this->{Sample1FileFrame}->{PathEntry}->SetText($_[0]); $this->ReadSampleDataFile($_[0], 1, $this->{Sample1FileFrame}, 1, 1); }, ], ); } no strict; sub CalY { my ($this, $x) = @_; my $ini = $this->{ini}; # Assign $ini hash variables (var_name) to scalar variabls $var_name. foreach my $key (keys %$ini) { $$key = $ini->{$key}; } return $ini->{c0} + $ini->{c1} * $x + $ini->{c2} * $x * $x + $ini->{c3} * $x * $x * $x + $ini->{c4} * $x * $x * $x * $x;; # The following lines are just for samples. # Variables can be accessed in two formats: $ini->{var_name} or $var_name. return 1e10 if($ini->{w} <= 0.0); my $div = ($x - $x0) / $w; return 1e10 if(abs(1.0+$div) <= 1.0e-10); my $ret = $c0 + $c1 / ( 1.0 + $div*$div ); return $ret; # return $ini->{c0} + $ini->{c1} * $x + $ini->{c2} * $x * $x; } use strict; 1;