Fixed bug when handling a wrong chemical formula (issue MUSR-303).

This commit is contained in:
salman 2015-08-25 15:01:17 +02:00
parent 9609ebe149
commit efd0f35f54
4 changed files with 77 additions and 26 deletions

View File

@ -83,19 +83,19 @@ sub internal_formula_parser {
sub add_formula_strings {
my ($formula, $coef, %elements) = @_;
# print "Getting Formula of $formula\n";
$formula =~ /^(?:([A-Z][a-z]*)(\d+\.?\d*)?)+$/o # XXX new
or die "Invalid Portion of Formula $formula";
while ($formula =~ m/([A-Z][a-z]*)(\d+\.?\d*)?/go) { # XXX new
my ($elm, $count) = ($1, $2);
$count = 1 unless defined $count;
if (defined $elements{$elm}) {
$elements{$elm} += $count * $coef;
} else {
$elements{$elm} = $count * $coef;
}
if ($formula =~ /^(?:([A-Z][a-z]*)(\d+\.?\d*)?)+$/o) {
# or die "Invalid Portion of Formula $formula";
while ($formula =~ m/([A-Z][a-z]*)(\d+\.?\d*)?/go) { # XXX new
my ($elm, $count) = ($1, $2);
$count = 1 unless defined $count;
if (defined $elements{$elm}) {
$elements{$elm} += $count * $coef;
} else {
$elements{$elm} = $count * $coef;
}
}
return %elements;
}
return %elements;
}
sub ParensBalanced {

View File

@ -31,7 +31,6 @@ use QtCore4::slots
SaveFileAs => [];
use Ui_TrimSPGUI4;
sub NEW {
my ( $class, $parent ) = @_;
$class->SUPER::NEW($parent);
@ -52,7 +51,7 @@ sub child {
sub CollectValues
{
my %All=();
$All{"numLayer"}=this->{ui}->numLayer->value();
$All{"numLayer"}= this->{ui}->numLayer->value();
# Collect layers parameters
for (my $i=1;$i<=$All{"numLayer"};$i++) {
my $LComp = "L".$i."Comp";
@ -353,7 +352,9 @@ sub CreateInpFile
my $Comp = this->{ui}->layerTable->item($i-1,0)->text();
$All{$LComp} = $Comp;
my %LElComp=Chem::parse_formula($Comp);
foreach my $key (keys %LElComp) {if ($key eq "") {$Check++;}}
if ($Comp eq "") {$Check++;}
# Write composition to results file header
# Densities of layers
my $Lrho="L".$i."rho";
@ -369,7 +370,7 @@ sub CreateInpFile
# Sanity check, is the layer supposed to have value? are they all there?
if ($Check!=0) {
my $ErrMsg="Error: Layer $i is empty. Expecting it to be defined!\n";
my $ErrMsg="Error: Layer $i is empty or bad chemical formula.\nPleach check!\n";
print STDERR $ErrMsg;
my $HelpWindow = Qt::MessageBox::information( this, "Error!",$ErrMsg);
return("ERROR");
@ -417,10 +418,9 @@ sub CreateInpFile
}
foreach my $key (keys %All) {
# print $key,$All{$key},"\n";
if ($All{$key} ne ""){
$TemplateFile =~ s/$key/$All{$key}/;
# Seed repeats three times
# Seed repeats three times
if ($key eq "ranSeed") { $TemplateFile =~ s/$key/$All{$key}/g;}
}
}
@ -477,6 +477,8 @@ sub StartSequenceOne
my @SdzValues=();
my $cmd="";
my @called = caller;
print "pck=".$called[0]." fln=".$called[1]." line=".$called[2];
if (!$ENV{'TRIMBIN'}) {
# If trim.sp binary is not defined give warning and return
my $Warning = Qt::MessageBox::information( this, "Warning!",
@ -492,7 +494,9 @@ sub StartSequenceOne
}
my $Progress=0;
$All{"SdzFlag"}=0;
if ($All{"scanSeq"}) {
# For multiple runs or a scan
if ($All{"radioList"}) {
@SValues=split(/,/,$All{"scanList"});
@SdzValues=split(/,/,$All{"scanListdz"});
@ -522,7 +526,7 @@ sub StartSequenceOne
$ScanAttrib = child("Qt::LineEdit","numberProj");
} elsif ($All{"comboScan"}==5) {
$ScanName = "Ld".$All{"scandL"};
$ScanAttrib = this->{ui}->layerTable->item($All{"ScandL"}-1,2);
$ScanAttrib = this->{ui}->layerTable->item($All{"scandL"}-1,2);
}
my $iScan=0;
@ -541,17 +545,26 @@ sub StartSequenceOne
open (INPF,q{>}, "$FILENAME.inp" );
print INPF $eingabe1;
close(INPF);
# Use Linux version
# Use Linux version
$Progress=$Progress+90/$#SValues;
this->{ui}->progress->setValue($Progress);
this->{ui}->progress->update();
$cmd = "cp $FILENAME.inp eingabe1.inp; ".$ENV{'TRIMBIN'};
system($cmd);
my $pid = fork();
die "Unable to fork: $!" unless defined($pid);
if (!$pid) { # child
exec($cmd);
die "Unable to exec: $!";
}
while (wait () != -1){}
#system($cmd);
foreach ("err","out","rge") {
system("mv -f ausgabe1.$_ $FILENAME.$_");
}
$iScan++;
print "iScan=".$iScan."\n";
}
} else {
# For a single run
@ -563,25 +576,38 @@ sub StartSequenceOne
close(INPF);
$Progress=20;
this->{ui}->progress->setValue($Progress);
this->{ui}->progress->update();
# Use Linux version
$cmd = "cp $FILENAME.inp eingabe1.inp; ".$ENV{'TRIMBIN'};
system($cmd);
my $pid = fork();
die "Unable to fork: $!" unless defined($pid);
if (!$pid) { # child
exec($cmd);
die "Unable to exec: $!";
}
while (wait () != -1){}
#system($cmd);
foreach ("err","out","rge") {
system("mv -f ausgabe1.$_ $FILENAME.$_");
}
$Progress=90;
this->{ui}->progress->setValue($Progress);
this->{ui}->progress->update();
sleep(10);
}
# Move the fort.33 file into the subdirectory and change its name
$cmd="rm -f eingabe1.inp; mv -f fort.33 ".$All{"workPath"}."/".$All{"fileNamePrefix"}."_Seq_Results.dat";
system($cmd);
$Progress=100;
this->{ui}->progress->setValue($Progress);
this->{ui}->progress->update();
undef %All;
undef $cmd;
print "at end\n";
return(1);
sleep(10);
return(0);
}
@ -790,7 +816,13 @@ sub PlotProfiles
my $TrimPath = $ENV{'PERLLIB'};
# Now that we have the file list send it to root macro for plotting.
my $cmd='root -n -l "'.$TrimPath.'/../plotRge.C(\"'.$filenames.'\")"&';
my $pid=system($cmd);
my $pid = fork();
die "Unable to fork: $!" unless defined($pid);
if (!$pid) { # child
exec($cmd);
die "Unable to exec: $!";
}
# my $pid=system($cmd);
}
}
@ -809,7 +841,13 @@ sub PlotFraction
my $TrimPath = $ENV{'PERLLIB'};
# Now that we have the file name send it to root macro for plotting.
my $cmd='root -n -l "'.$TrimPath.'/../plotFrc.C(\"'.$file.'\")"&';
my $pid=system($cmd);
my $pid = fork();
die "Unable to fork: $!" unless defined($pid);
if (!$pid) { # child
exec($cmd);
die "Unable to exec: $!";
}
# my $pid=system($cmd);
}
}
@ -827,7 +865,13 @@ sub PlotMean
my $TrimPath = $ENV{'PERLLIB'};
# Now that we have the file name send it to root macro for plotting.
my $cmd='root -n -l "'.$TrimPath.'/../plotMean.C(\"'.$file.'\")"&';
my $pid=system($cmd);
my $pid = fork();
die "Unable to fork: $!" unless defined($pid);
if (!$pid) { # child
exec($cmd);
die "Unable to exec: $!";
}
# my $pid=system($cmd);
}
}

View File

@ -1531,4 +1531,4 @@ sub retranslate_ui {
retranslateUi( $trimSPGUI4 );
}
1;
1;

View File

@ -154,6 +154,7 @@ void plotFrc(char *FileName)
gr1->SetMarkerStyle(20);
gr1->SetMarkerColor(TColor::kRed);
gr1->SetLineColor(TColor::kRed);
// Preferably get the chemical formula from header
legend->AddEntry(gr1,"Layer 1");
mg->Add(gr1);
}
@ -164,6 +165,7 @@ void plotFrc(char *FileName)
gr2->SetMarkerColor(TColor::kGreen);
gr2->SetLineColor(TColor::kGreen);
// gr2->Draw("PC");
// Preferably get the chemical formula from header
legend->AddEntry(gr2,"Layer 2");
mg->Add(gr2);
}
@ -174,6 +176,7 @@ void plotFrc(char *FileName)
gr3->SetMarkerColor(TColor::kBlue);
gr3->SetLineColor(TColor::kBlue);
// gr3->Draw("PC");
// Preferably get the chemical formula from header
legend->AddEntry(gr3,"Layer 3");
mg->Add(gr3);
}
@ -184,6 +187,7 @@ void plotFrc(char *FileName)
gr4->SetMarkerColor(TColor::kMagenta);
gr4->SetLineColor(TColor::kMagenta);
// gr4->Draw("PC");
// Preferably get the chemical formula from header
legend->AddEntry(gr4,"Layer 4");
mg->Add(gr4);
}
@ -194,6 +198,7 @@ void plotFrc(char *FileName)
gr5->SetMarkerColor(TColor::kOrange);
gr5->SetLineColor(TColor::kOrange);
// gr5->Draw("PC");
// Preferably get the chemical formula from header
legend->AddEntry(gr5,"Layer 5");
mg->Add(gr5);
}
@ -204,6 +209,7 @@ void plotFrc(char *FileName)
gr6->SetMarkerColor(TColor::kViolet);
gr6->SetLineColor(TColor::kViolet);
// gr6->Draw("PC");
// Preferably get the chemical formula from header
legend->AddEntry(gr6,"Layer 6");
mg->Add(gr6);
}
@ -214,6 +220,7 @@ void plotFrc(char *FileName)
gr7->SetMarkerColor(TColor::kAzure+7);
gr7->SetLineColor(TColor::kAzure+7);
// gr7->Draw("PC");
// Preferably get the chemical formula from header
legend->AddEntry(gr7,"Layer 7");
mg->Add(gr7);
}