Implimentation of msr2dat in the MSR module.

This commit is contained in:
2009-10-08 15:40:45 +00:00
parent fcdc91996e
commit aa8b0953d0
3 changed files with 99 additions and 7 deletions

View File

@ -985,9 +985,9 @@ sub CreateTheory {
} # End CreateTheory } # End CreateTheory
######################## ########################
# ExtractParamBlk # ExtractBlks
######################## ########################
sub ExtractParamBlk { sub ExtractBlk {
# This subroutine takes the MSR file as input and extracts the parameters # This subroutine takes the MSR file as input and extracts the parameters
# with the corresponding values, errors etc... # with the corresponding values, errors etc...
@ -1021,7 +1021,7 @@ sub ExtractParamBlk {
my @Param=split(/\s+/,$line); my @Param=split(/\s+/,$line);
} }
return(\@FPBlock) return(\@TBlock,\@FPBlock)
} }
@ -1310,7 +1310,7 @@ sub ExportParams {
# open (MSRF,q{<},"$FILENAME.msr" ); # open (MSRF,q{<},"$FILENAME.msr" );
# my @lines = <MSRF>; # my @lines = <MSRF>;
# close(IFILE); # close(IFILE);
# my $FPBlock_ref=MSR::ExtractParamBlk(@lines); # my $FPBlock_ref=MSR::ExtractBlk(@lines);
# my @FPBloc = @$FPBlock_ref; # my @FPBloc = @$FPBlock_ref;
# Then loop over expected parameters and extract their values and error bar # Then loop over expected parameters and extract their values and error bar
@ -1422,6 +1422,98 @@ sub ExportParams {
return $TABLE; return $TABLE;
} }
########################
# MSR2Dat
# Function return a tab separated table of parameters from an MSR file
# input should be
# @msrfile
########################
sub MSR2Dat {
# Take the msr file as input array of lines
my @file=@_;
# Extract PRAMETERS and THEORY Blocks
(my $TBlock_ref, my $FPBlock_ref)=MSR::ExtractBlks(@file);
my @FPBlock = @$FPBlock_ref;
my @TBlock = @$TBlock_ref;
# Get shared parameters
foreach $TLine (@TBlock) {
# Then split it to find numbers of shared parameters
@tmp=split(/\s+/,$TLine);
foreach (@tmp) {
if ($_ eq $_+0 ) {
# This is a number, keep it in the Shared arry
@Shared=(@Shared,$_);
}
}
}
# Nice trick, make a hash for unique RUN lines
# Find spectrum lines
my @MAPS = grep {/map /} @file;
my @RUNS = grep {/RUN/} @file;
my $counter=0;
foreach $key (@RUNS){
# This gets rid of duplicates
$RUN{$key}=$counter;
$MAP{$key}=$MAPS[$counter];
$counter++;
}
# Number of runs (or independent sets of parameters) in this file
my $NRuns=1;
foreach (sort { $RUN{$a} <=> $RUN{$b}} keys %RUN ) {
@RunParams=();
$NP=0;
# print $_."=".$MAP{$_}."\n";
@tmp=split(/\s+/,$MAP{$_});
# Remove first element (map)
shift(@tmp);
foreach (@tmp) {
if ($_ ne "" && $_>0 ) {
@RunParams=(@RunParams,$_);
$NP++;
}
}
if ($NP>0) {
$orders=join(",",@RunParams);
$RUNParams[$NRuns]=$orders;
$NRuns++;
}
}
# Split parameter's line to extract values and errors
foreach $line (@FPBlock) {
@Param=split(/\s+/,$line);
# Create a hash with the parameter order as a key
# and the value and error as value
$P{$Param[1]}=$Param[3].",".$Param[4];
$PName{$Param[1]}=$Param[2];
}
# Now we have everything. Lets start ordering
# First lines is names
@Pnum=split(/,/,$RUNParams[1]);
foreach (@Pnum,@Shared) {
$DatFile=join("\t",$DatFile,$PName{$_},"d".$PName{$_});
}
$DatFile=$DatFile."\n";
# For the values from all the files.
# I am not checking if all the files have the same theory function
for ($i=1;$i<=$NRuns-1;$i++) {
@Pnum=split(/,/,$RUNParams[$i]);
# First go for the shared parameters
foreach (@Pnum,@Shared) {
($value,$err)=split(/,/,$P{$_});
$DatFile=join("\t",$DatFile,$value,$err);
}
$DatFile=$DatFile."\n";
}
return $DatFile;
}
######################## ########################
# RUNFileNameAuto # RUNFileNameAuto

View File

@ -1,6 +1,6 @@
# Form implementation generated from reading ui file 'MuSRFit.ui' # Form implementation generated from reading ui file 'MuSRFit.ui'
# #
# Created: Wed Sep 23 18:24:32 2009 # Created: Thu Oct 8 17:22:34 2009
# by: The PerlQt User Interface Compiler (puic) # by: The PerlQt User Interface Compiler (puic)
# #
# WARNING! All changes made in this file will be lost! # WARNING! All changes made in this file will be lost!
@ -3419,7 +3419,7 @@ sub UpdateMSRFileInitTable
textMSROutput->append("$line"); textMSROutput->append("$line");
} }
my $FPBlock_ref=MSR::ExtractParamBlk(@lines); (my $TBlock_ref, my $FPBlock_ref)=MSR::ExtractParamBlk(@lines);
my @FPBloc = @$FPBlock_ref; my @FPBloc = @$FPBlock_ref;
my $PCount=0; my $PCount=0;

View File

@ -469,7 +469,7 @@ void MuSRFitform::UpdateMSRFileInitTable()
textMSROutput->append("$line"); textMSROutput->append("$line");
} }
my $FPBlock_ref=MSR::ExtractParamBlk(@lines); (my $TBlock_ref, my $FPBlock_ref)=MSR::ExtractBlks(@lines);
my @FPBloc = @$FPBlock_ref; my @FPBloc = @$FPBlock_ref;
my $PCount=0; my $PCount=0;