From 2f90341ce064eda8d65bd904228fd408eea80200 Mon Sep 17 00:00:00 2001
From: Zaher Salman <zaher.salman@psi.ch>
Date: Wed, 26 Aug 2009 15:09:09 +0000
Subject: [PATCH] First implementation of single histogram fit. This going to
 be hard.

---
 src/external/MuSRFitGUI/MSR.pm       | 543 ++++++++++++++---
 src/external/MuSRFitGUI/MuSRFit.pl   | 260 +++++---
 src/external/MuSRFitGUI/MuSRFit.ui   | 880 +++++++++++++++++----------
 src/external/MuSRFitGUI/MuSRFit.ui.h |  26 +-
 4 files changed, 1221 insertions(+), 488 deletions(-)

diff --git a/src/external/MuSRFitGUI/MSR.pm b/src/external/MuSRFitGUI/MSR.pm
index 416f7a4a..704fec18 100755
--- a/src/external/MuSRFitGUI/MSR.pm
+++ b/src/external/MuSRFitGUI/MSR.pm
@@ -161,14 +161,7 @@ FITPARAMETER
     else {
         if ( $All{"Sh_Alpha"} == 1 ) {
             my $shcount = 1;
-        }
-        elsif ( $All{"Sh_N0"} == 1 ) {
-            my $shcount = 1;
-        }
-        elsif ( $All{"Sh_NBg"} == 1 ) {
-            my $shcount = 1;
-        }
-        else {
+        } else {
             my $shcount = 0;
         }
     }
@@ -191,7 +184,7 @@ FITPARAMETER
         # How many non-shared parameter for this RUN?
         my $nonsh = 0;
 
-        # Prepeare Alpha/N0/NBg line for the RUN block. Empty initially.
+        # Prepeare Alpha line for the RUN block. Empty initially.
         my $Alpha_Line = $EMPTY;
 
         # Loop over all components in the fit
@@ -201,17 +194,11 @@ FITPARAMETER
             my @Params = split( /\s+/, $Parameters );
 
             # For the first component we need Alpha for Asymmetry fits
-            if ( $component == 1 && $All{"FitAsyType"} eq "Asymmetry" ) {
-                unshift( @Params, "Alpha" );
-	    }
-	    # For the first component we need No and NBg for SingleHist fits
-	    elsif ( $component == 1 && $All{"FitAsyType"} eq "SingleHist" ) {
-                unshift( @Params, ( "N0", "NBg" ) );
-            }
-
+	    unshift( @Params, "Alpha" );
+	    
             foreach $Param (@Params) {
                 $Param_ORG = $Param;
-                if ( ($#FitTypes != 0) && ($Param ne "Alpha" && $Param ne "N0" && $Param ne "NBg" ) ) {
+                if ( ($#FitTypes != 0) && ($Param ne "Alpha") ) {
                     $Param = join( $EMPTY, $Param, "_", "$component" );
                 }
 
@@ -224,7 +211,7 @@ FITPARAMETER
                     $Shared = $All{"Sh_$Param"};
                 }
 
-                # Alpha, N0 and NBg Lines
+                # Alpha Line
                 #
                 # If you encounter alpha in the parameters list make sure
                 # to fill this line for the RUN block.
@@ -238,34 +225,8 @@ FITPARAMETER
                         $Alpha_Line = "alpha           $j\n";
                     }
                 }
-		# If you encounter N0 in the parameters list make sure
-		# to fill this line for the RUN block.
-                elsif ( $Param_ORG eq "N0" ) {
-                    if ($Shared) {
-                        $Alpha_Line = "norm            1\n";
-                    }
-                    else {
-                        $Alpha_Line = "norm            $j\n";
-                    }
 
-                    # Optional - add lifetime correction for SingleHist fits
-                    if ( $All{"ltc"} eq "y" ) {
-                        $Alpha_Line = $Alpha_Line . "lifetimecorrection\n";
-                    }
-
-                    # If you encounter NBg in the parameters list make sure
-                    # to fill this line for the RUN block.
-                }
-                elsif ( $Param_ORG eq "NBg" ) {
-                    if ($Shared) {
-                        $Alpha_Line = $Alpha_Line . "backgr.fit      2\n";
-                    }
-                    else {
-                        $Alpha_Line = $Alpha_Line . "backgr.fit      $j\n";
-                    }
-                }
-
-                # End of Alpha, N0 and NBg Lines
+                # End of Alpha Line
 ####################################################################################################
 
 ####################################################################################################
@@ -307,10 +268,7 @@ FITPARAMETER
       $j      $Name    $value     $error    $error    $minvalue    $maxvalue";
 
                     # Skip adding to map line in these cases
-                    if (   $Param ne "Alpha"
-			   && $Param ne "N0"
-			   && $Param ne "NBg"
-			   && $#RUNS != 0 )
+                    if ( $Param ne "Alpha" && $#RUNS != 0 )
                     {
                         ++$nonsh;
                         $Full_T_Block =~ s/$Param_ORG/map$nonsh/;
@@ -396,26 +354,13 @@ FITPARAMETER
                 $Def_Format{$BeamLine} );
         }
 
-        # What kind of fit? 0 - Single Histogram, 2 - Asymmetry, 4 - RRF
-        if ( $All{"FitAsyType"} eq "Asymmetry" ) {
-            $Type_Line = "fittype         2";
-            $PLT       = 2;
-            $Hist_Lines =
-              "forward         $Hists[0]\nbackward        $Hists[1]";
-            $Bg_Line   = "background      66000   66500   66000   66500";
-            $Data_Line = "data            3419    63000   3419    63000";
-        }
-        elsif ( $All{"FitAsyType"} eq "SingleHist" ) {
-            $Type_Line  = "fittype         0";
-            $PLT        = 0;
-            $Hist_Lines = "forward         HIST";
-            $Bg_Line    = $EMPTY;
-            $Data_Line  = "data            3419    63000";
-        }
-        elsif ( $All{"FitAsyType"} eq "RotRF" ) {
-            $Type_Line = "fittype         4";
-        }
-
+	$Type_Line = "fittype         2";
+	$PLT       = 2;
+	$Hist_Lines =
+	    "forward         $Hists[0]\nbackward        $Hists[1]";
+	$Bg_Line   = "background      66000   66500   66000   66500";
+	$Data_Line = "data            3419    63000   3419    63000";
+        
         # Omit background and data lines for LTG,GPS and Dolly
         if ( $BeamLine ne "LEM" ) {
             $Bg_Line = "background 50 250 50 250";
@@ -423,24 +368,12 @@ FITPARAMETER
 "t0              287     284\ndata            297     8000    294     8000";
         }
 
- #	$MAP_Line = "map             0    0    0    0    0    0    0    0    0    0";
         $FRANGE_Line = "fit             TINI    TFIN";
         $PAC_Line    = "packing         BINNING";
 
-        if ( $All{"FitAsyType"} eq "Asymmetry" ) {
-            $Single_RUN =
+	$Single_RUN =
 "$RUN_Line\n$Type_Line\n$Alpha_Line$Hist_Lines\n$Bg_Line\n$Data_Line\n$MAP_Line\n$FRANGE_Line\n$PAC_Line\n\n";
-        }
-        elsif ( $All{"FitAsyType"} eq "SingleHist" ) {
-            $Single_RUN = $EMPTY;
-            foreach my $Hist (@Hists) {
-                $Tmp_Hist_Line = $Hist_Lines;
-                $Tmp_Hist_Line =~ s/HIST/$Hist/g;
-                $Single_RUN = $Single_RUN
-                  . "$RUN_Line\n$Type_Line\n$Alpha_Line$Tmp_Hist_Line\n$Data_Line\n$MAP_Line\n$FRANGE_Line\n$PAC_Line\n\n";
-            }
-        }
-
+        
         # Now add the appropriate values of fit range and packing
         my $Range_Min = 8;
         my $Range_Max = 0;
@@ -456,17 +389,11 @@ FITPARAMETER
             # For multiple ranges use this
             if ( $Ti < $Range_Min ) { $Range_Min = $Ti; }
             if ( $Tf > $Range_Max ) { $Range_Max = $Tf; }
-            if ( $All{"FitAsyType"} eq "Asymmetry" ) {
-                $RUNS_Line = "$RUNS_Line " . $Range_Order;
-            }
-            elsif ( $All{"FitAsyType"} eq "SingleHist" ) {
-                $RUNS_Line = "$RUNS_Line " . $Range_Order;
-            }
-            ++$k;
+
+	    $RUNS_Line = "$RUNS_Line " . $Range_Order;
+	    ++$k;
             ++$Range_Order;
         }
-
-        #	if ($FitAsyType eq "Asymmetry") {$RUNS_Line="$RUNS_Line ".$iRun*$k;}
         ++$iRun;
     }
 
@@ -532,6 +459,436 @@ STATISTIC --- 0000-00-00 00:00:00
     return($Full_T_Block,\@Paramcomp);
 }
 
+########################
+# CreateMSRSingleHist
+########################
+sub CreateMSRSingleHist {
+    my %All = %{$_[0]};
+
+# "Smart" default value of the fit parameters.
+    my %Defaults = (
+		    "Asy",           "0.15",  "dAsy",          "0.01",
+		    "Asy_min",       "0",     "Asy_max",       "0",
+		    "Alpha",         "1.0",   "dAlpha",        "0.01",
+		    "Alpha_min",     "0",     "Alpha_max",     "0",
+		    "N0",            "300.0", "dN0",           "0.01",
+		    "N0_min",        "0",     "N0_max",        "0",
+		    "NBg",           "30.0",  "dNBg",          "0.01",
+		    "NBg_min",       "0",     "NBg_max",       "0",
+		    "Lam",           "1.0",   "dLam",          "0.01",
+		    "Lam_min",       "0",     "Lam_max",       "0",
+		    "Gam",           "1.0",   "dGam",          "0.01",
+		    "Gam_min",       "0",     "Gam_max",       "0",
+		    "Bet",           "0.5",   "dBet",          "0.01",
+		    "Bet_min",       "0",     "Bet_max",       "0",
+		    "Two",           "2.0",   "dTwo",          "0.0",
+		    "Two_min",       "0",     "Two_max",       "0",
+		    "Del",           "0.1",   "dDel",          "0.01",
+		    "Del_min",       "0",     "Del_max",       "0",
+		    "Sgm",           "0.1",   "dSgm",          "0.01",
+		    "Sgm_min",       "0",     "Sgm_max",       "0",
+		    "Aa",            "0.1",   "dAa",           "0.01",
+		    "Aa_min",        "0",     "Aa_max",        "0",
+		    "q",             "0.1",   "dq",            "0.01",
+		    "q_min",         "0",     "q_max",         "0",
+		    "Bg",            "0.036", "dBg",           "0.01",
+		    "Bg_min",        "0",     "Bg_max",        "0",
+		    "bgrlx",         "0.",    "dbgrlx",        "0.0",
+		    "bgrlx_min",     "0",     "bgrlx_max",     "0",
+		    "Frq",           "1.0",   "dFrq",          "1.",
+		    "Frq_min",       "0",     "Frq_max",       "0",
+		    "Field",         "100.0", "dField",        "1.",
+		    "Field_min",     "0",     "Field_max",     "0",
+		    "Energy",        "14.1",  "dEnergy",       "0.",
+		    "Energy_min",    "0",     "Energy_max",    "0",
+		    "DeadLayer",     "10.",   "dDeadLayer",    "0.1",
+		    "DeadLayer_min", "0",     "DeadLayer_max", "0",
+		    "Lambda",        "128.1", "dLambda",       "0.1",
+		    "Lambda_min",    "0",     "Lambda_max",    "0",
+		    "Phi",           "1.",    "dPhi",          "0.01",
+		    "Phi_min",       "0",     "Phi_max",       "0"
+		    );
+    # Start with empty array
+    my @FitTypes = ();
+
+    foreach ($All{"FitType1"},$All{"FitType2"},$All{"FitType3"}) {
+	if ($_ ne "None") {
+	    @FitTypes=(@FitTypes,$_);
+	}
+    }
+
+    my @Hists = split( /,/, $All{"LRBF"} );
+    my @TiVals = split( /,/, $All{"Tis"} );
+    my @TfVals = split( /,/, $All{"Tfs"} );
+    my @BINVals = split( /,/, $All{"BINS"} );
+    my $FILENAME = $All{"FILENAME"};
+    my $BeamLine = $All{"BeamLine"};
+    my $YEAR = $All{"YEAR"};
+    my $DATADIR = $DATADIRS{$BeamLine};
+
+    my $Step = $All{"go"};
+    if ( $Step eq "PLOT" ) {
+	$FITMINTYPE = $EMPTY;
+    } elsif ( $Step eq "MIGRAD" ) {
+	$FITMINTYPE = "MINIMIZE\nMIGRAD\nHESSE";
+    } elsif ( $Step eq "MINOS" ) {
+	$FITMINTYPE = "MIGRAD\nMINOS";
+    } elsif ( $Step eq "SIMPLEX" ) {
+	$FITMINTYPE = "SCAN\nSIMPLEX";
+    }
+
+    # First create the THEORY Block
+    my ($Full_T_Block,$Paramcomp_ref)=MSR::CreateTheory(@FitTypes);
+
+    my @Paramcomp = @$Paramcomp_ref;
+
+    my $TitleLine = $All{"TITLE"}."\n# Run Numbers: ".$All{"RunNumbers"};
+    $TitleLine =~ s/,/:/g;
+
+    # Fit parameters block
+    my $FitParaBlk = "
+###################################################################
+FITPARAMETER
+###################################################################
+#     No     Name       Value    Err     Min  Max                  ";
+
+    # Counter for RUNS
+    my $iRun = 1;
+
+    # Counter of Params
+    my $j = 1;
+
+    my @RUNS=split( /,/, $All{"RunNumbers"});
+    # $shcount is a counter for shared parameters
+    if ( $#RUNS == 0 && $#Hists == 0) {
+        my $shcount = 1;
+    } else {
+        if ( $All{"Sh_N0"} == 1 ) {
+            my $shcount = 1;
+        } elsif ( $All{"Sh_NBg"} == 1 ) {
+            my $shcount = 1;
+        } else {
+            my $shcount = 0;
+        }
+    }
+
+    $shcount   = 1;
+    my $RUN_Block = $EMPTY;
+    my $RUNS_Line = $EMPTY;
+
+    # range order
+    my $Range_Order = 1;
+    foreach my $RUN (@RUNS) {
+#######################################################################
+# For a single histogram fit we basically need to repeat this for each hist
+	foreach my $Hist (@Hists) {
+
+	    # Prepare the Parameters and initial values block
+	    my $component  = 0;
+	    my $Single_RUN = $EMPTY;
+
+	    # Prepare map line for each run
+	    my $MAP_Line = "map            ";
+	    
+	    # How many non-shared parameter for this RUN?
+	    my $nonsh = 0;
+	    
+	    # Prepeare N0/NBg line for the RUN block. Empty initially.
+	    my $N0Bg_Line = $EMPTY;
+	    
+	    # Loop over all components in the fit
+	    foreach my $FitType (@FitTypes) {
+		++$component;
+		my $Parameters = $Paramcomp[ $component - 1 ];
+		my @Params = split( /\s+/, $Parameters );
+		
+		# For the first component we need N0 and NBg for SingleHist fits
+		if ( $component == 1 && $All{"FitAsyType"} eq "SingleHist" ) {
+		    unshift( @Params, ( "N0", "NBg" ) );
+		}
+
+		foreach $Param (@Params) {
+		    $Param_ORG = $Param;
+		    $Param=$Param.$Hist;
+		    if ( ($#FitTypes != 0) && ( $Param ne "N0" && $Param ne "NBg" ) ) {
+			$Param = join( $EMPTY, $Param, "_", "$component" );
+		    }
+		    
+		    # If we have only one RUN with one Histogram then everything is shared
+		    if ( $#RUNS == 0 && $#Hists == 0 ) {
+			$Shared = 1;
+		    }
+		    # Otherwise check input if it was marked as shared
+		    else {
+			$Shared = $All{"Sh_$Param"};
+			print "Shared=$Shared\n";
+		    }
+		    
+		    # N0 and NBg Lines
+		    #
+		    # If you encounter N0 in the parameters list make sure
+		    # to fill this line for the RUN block.
+		    if ( $Param_ORG eq "N0" ) {
+			if ($Shared) {
+			    $N0Bg_Line = "norm            1\n";
+			}
+			else {
+			    $N0Bg_Line = "norm            $j\n";
+			}
+			
+			# Optional - add lifetime correction for SingleHist fits
+			if ( $All{"ltc"} eq "y" ) {
+			    $N0Bg_Line = $N0Bg_Line . "lifetimecorrection\n";
+			}
+		    }
+		    # If you encounter NBg in the parameters list make sure
+		    # to fill this line for the RUN block.
+		    elsif ( $Param_ORG eq "NBg" ) {
+			if ($Shared) {
+			    $N0Bg_Line = $N0Bg_Line . "backgr.fit      2\n";
+			}
+			else {
+			    $N0Bg_Line = $N0Bg_Line . "backgr.fit      $j\n";
+			}
+		    }
+
+		    # End of N0 and NBg Lines
+####################################################################################################
+		    
+####################################################################################################
+		    # Extract initial values, error and max/min from input
+		    $Name     = $Param . "_" . $iRun;
+		    $value    = $All{"$Name"};
+		    $error    = $All{"$erradd$Name"};
+		    $minvalue = $All{"$Name$minadd"};
+		    $maxvalue = $All{"$Name$maxadd"};
+# If these values are not in the input then take the defaulst
+# I think that this can go at the end if we use a separate initialization routine
+		    if ($value eq $EMPTY) {
+			$value = $Defaults{"$Param_ORG"};
+			$error = $Defaults{"$erradd$Param_ORG"};
+			$minvalue = $Defaults{"$Param_ORG$minadd"};
+			$maxvalue = $Defaults{"$Param_ORG$maxadd"};
+		    }
+		    if ( $minvalue == $maxvalue ) {
+			$minvalue = $EMPTY;
+			$maxvalue = $EMPTY;
+		    }
+####################################################################################################
+
+		    # Start preparing the parameters block
+		    print "Param=$Param_ORG is Shared=$Shared\n";
+		    if ($Shared) {
+			
+			# Parameter is shared enough to keep order from first run
+			if ( $iRun == 1 ) {
+			    $FitParaBlk = $FitParaBlk . "
+      $j      $Name    $value     $error    $error    $minvalue    $maxvalue";
+			    $Full_T_Block =~ s/$Param_ORG/$j/;
+			    ++$shcount;
+			    ++$j;
+			}
+		    } else {
+
+			# Parameter is not shared, use map unless it is a single RUN fit
+			$FitParaBlk = $FitParaBlk . "
+      $j      $Name    $value     $error    $error    $minvalue    $maxvalue";
+			
+			# Skip adding to map line in these cases
+			if ( $Param ne "N0" && $Param ne "NBg" && ($#RUNS != 0 || $#Hist != 0)) {
+			    ++$nonsh;
+			    $Full_T_Block =~ s/$Param_ORG/map$nonsh/;
+			    $MAP_Line = join( ' ', $MAP_Line, $j );
+			}
+			++$j;
+		    }
+		    $NtotPar = $j;
+		}
+	    }
+
+	    # Finished preparing the FITPARAMETERS block
+#######################################################################
+
+	    # For each defined range we need a block in the RUN-Block
+	    # Also for each histogram in Single Histograms fits
+	    # Also for Imaginaryand and Real for RRF fits
+	    
+	    $RUN = $RUNS[ $iRun - 1 ];
+	    if    ( $RUN < 10 )   { $RUNtmp = "000" . $RUN; }
+	    elsif ( $RUN < 100 )  { $RUNtmp = "00" . $RUN; }
+	    elsif ( $RUN < 1000 ) { $RUNtmp = "0" . $RUN; }
+	    
+	    # Get current year
+	    ( $sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst ) =
+		localtime( time() );
+	    my $current_year = $year + 1900;
+	    
+	    if ( $BeamLine eq "LEM" ) {
+		$RUN_File_Name = "lem" . substr( $YEAR, 2 ) . "_his_" . $RUNtmp;
+		$RUNFILE       = "$DATADIR/$YEAR/$RUN_File_Name";
+		$RUN_Line      = join( $SPACE,
+				       "RUN", $RUNFILE, $BeamLines{$BeamLine}, "PSI",
+				       $Def_Format{$BeamLine} );
+	    }
+	    elsif ( $BeamLine eq "GPS" ) {
+		$RUN_File_Name = "deltat_pta_gps_" . $RUNtmp;
+		if ( $YEAR == $current_year ) {
+		    $RUNFILE = "$DATADIR/$RUN_File_Name";
+		}
+		else {
+		    $RUNFILE = "$DATADIR/d$YEAR/pta/$RUN_File_Name";
+		}
+		$RUN_Line = join( $SPACE,
+				  "RUN", $RUNFILE, $BeamLines{$BeamLine}, "PSI",
+				  $Def_Format{$BeamLine} );
+	    }
+	    elsif ( $BeamLine eq "LTF" ) {
+		$RUN_File_Name = "deltat_pta_ltf_" . $RUNtmp;
+		if ( $YEAR == $current_year ) {
+		    $RUNFILE = "$DATADIR/$RUN_File_Name";
+		}
+		else {
+		    $RUNFILE = "$DATADIR/d$YEAR/pta/$RUN_File_Name";
+		}
+		$RUN_Line = join( $SPACE,
+				  "RUN", $RUNFILE, $BeamLines{$BeamLine}, "PSI",
+				  $Def_Format{$BeamLine} );
+	    }
+	    elsif ( $BeamLine eq "Dolly" ) {
+		$RUN_File_Name = "deltat_pta_dolly_" . $RUNtmp;
+		if ( $YEAR == $current_year ) {
+		    $RUNFILE = "$DATADIR/$RUN_File_Name";
+		}
+		else {
+		    $RUNFILE = "$DATADIR/d$YEAR/pta/$RUN_File_Name";
+		}
+		$RUN_Line = join( $SPACE,
+				  "RUN", $RUNFILE, $BeamLines{$BeamLine}, "PSI",
+				  $Def_Format{$BeamLine} );
+	    }
+	    elsif ( $BeamLine eq "GPD" ) {
+		$RUN_File_Name = "deltat_pta_gpd_" . $RUNtmp;
+		if ( $YEAR == $current_year ) {
+		    $RUNFILE = "$DATADIR/$RUN_File_Name";
+		}
+		else {
+		    $RUNFILE = "$DATADIR/d$YEAR/pta/$RUN_File_Name";
+		}
+		$RUN_Line = join( $SPACE,
+				  "RUN", $RUNFILE, $BeamLines{$BeamLine}, "PSI",
+				  $Def_Format{$BeamLine} );
+	    }
+	    
+	    # What kind of fit? 0 - Single Histogram, 2 - Asymmetry, 4 - RRF
+	    $Type_Line  = "fittype         0";
+	    $PLT        = 0;
+	    $Hist_Lines = "forward         HIST";
+	    $Bg_Line    = $EMPTY;
+	    $Data_Line  = "data            3419    63000";
+	    
+	    # Omit background and data lines for LTG,GPS and Dolly
+	    if ( $BeamLine ne "LEM" ) {
+		$Bg_Line = "background 50 250 50 250";
+		$Data_Line =
+		    "t0              287     284\ndata            297     8000    294     8000";
+	    }
+	    
+	    #	$MAP_Line = "map             0    0    0    0    0    0    0    0    0    0";
+	    $FRANGE_Line = "fit             TINI    TFIN";
+	    $PAC_Line    = "packing         BINNING";
+	    
+	    $Single_RUN = $EMPTY;
+	    $Tmp_Hist_Line = $Hist_Lines;
+	    $Tmp_Hist_Line =~ s/HIST/$Hist/g;
+	    $Single_RUN = $Single_RUN
+		. "$RUN_Line\n$Type_Line\n$N0Bg_Line$Tmp_Hist_Line\n$Data_Line\n$MAP_Line\n$FRANGE_Line\n$PAC_Line\n\n";
+	    
+	    # Now add the appropriate values of fit range and packing
+	    my $Range_Min = 8;
+	    my $Range_Max = 0;
+	    my $k         = 0;
+	    foreach my $Ti (@TiVals) {
+		my $Tf        = $TfVals[$k];
+		my $BIN       = $BINVals[$k];
+		$RUN_Block = $RUN_Block . $Single_RUN;
+		$RUN_Block =~ s/TINI/$Ti/g;
+		$RUN_Block =~ s/TFIN/$Tf/g;
+		$RUN_Block =~ s/BINNING/$BIN/g;
+		
+		# For multiple ranges use this
+		if ( $Ti < $Range_Min ) { $Range_Min = $Ti; }
+		if ( $Tf > $Range_Max ) { $Range_Max = $Tf; }
+		$RUNS_Line = "$RUNS_Line " . $Range_Order;
+		++$k;
+		++$Range_Order;
+	    }
+	}
+	++$iRun;
+    }
+
+    # The number of runs is
+    $NRUNS = $iRun - 1;
+
+    $Full_T_Block = "
+###################################################################
+THEORY
+###################################################################
+$Full_T_Block
+";
+
+    $RUN_Block =
+      "###################################################################
+$RUN_Block";
+
+    $COMMANDS_Block =
+      "###################################################################
+COMMANDS
+FITMINTYPE
+SAVE
+";
+    $COMMANDS_Block =~ s/FITMINTYPE/$FITMINTYPE/g;
+
+    # Check if log x and log y are selected
+    my $logxy = $EMPTY;
+    if ( $All{"logx"} eq "y" ) { $logxy = $logxy . "logx\n"; }
+    if ( $All{"logy"} eq "y" ) { $logxy = $logxy . "logy\n"; }
+
+    # Check if a plot range is defined (i.e. different from fit)
+    $PRANGE_Line = "use_fit_ranges";
+    if ( $All{"Xi"} != $All{"Xf"} ) {
+
+        #	if ($Yi != $Yf) {
+        $PRANGE_Line = "range  ".$All{"Xi"}."  ".$All{"Xf"}."  ".$All{"Yi"}."  ".$All{"Yf"};
+
+        #	} else {
+        #	    $PRANGE_Line = "range  $Xi  $Xf";
+        #	}
+    }
+
+    $PLOT_Block =
+      "###################################################################
+PLOT $PLT
+runs     $RUNS_Line
+$PRANGE_Line
+$logxy";
+
+    # Don't know why but it is needed initially
+    $STAT_Block =
+      "###############################################################
+STATISTIC --- 0000-00-00 00:00:00
+*** FIT DID NOT CONVERGE ***";
+
+    # Empty line at the end of each block
+    my $FullMSRFile = "$TitleLine$FitParaBlk\n$Full_T_Block\n$RUN_Block\n$COMMANDS_Block\n$PLOT_Block\n$STAT_Block\n";
+
+# Open output file FILENAME.msr
+    open( OUTF,q{>},"$FILENAME.msr" );
+    print OUTF ("$FullMSRFile");
+    close(OUTF);
+    return($Full_T_Block,\@Paramcomp);
+}
+
+
 ########################
 # Createheory
 ########################
diff --git a/src/external/MuSRFitGUI/MuSRFit.pl b/src/external/MuSRFitGUI/MuSRFit.pl
index fb79bb7b..a5f2c81d 100755
--- a/src/external/MuSRFitGUI/MuSRFit.pl
+++ b/src/external/MuSRFitGUI/MuSRFit.pl
@@ -1,6 +1,6 @@
 # Form implementation generated from reading ui file 'MuSRFit.ui'
 #
-# Created: Tue Aug 25 16:34:16 2009
+# Created: Wed Aug 26 17:07:14 2009
 #      by: The PerlQt User Interface Compiler (puic)
 #
 # WARNING! All changes made in this file will be lost!
@@ -14,7 +14,6 @@ package MuSRFitform;
 use Qt;
 use Qt::isa qw(Qt::MainWindow);
 use Qt::slots
-    fileNew => [],
     fileOpen => [],
     fileSave => [],
     fileChangeDir => [],
@@ -69,12 +68,16 @@ use Qt::attributes qw(
     SharingPahe
     buttonGroupSharing
     SharingComp1
+    Comp1ShLabel
     ShParam_1_1
     ShParam_1_2
     ShParam_1_3
     ShParam_1_4
     ShParam_1_5
-    Comp1ShLabel
+    ShParam_1_6
+    ShParam_1_7
+    ShParam_1_8
+    ShParam_1_9
     SharingComp2
     Comp2ShLabel
     ShParam_2_1
@@ -82,6 +85,10 @@ use Qt::attributes qw(
     ShParam_2_3
     ShParam_2_4
     ShParam_2_5
+    ShParam_2_6
+    ShParam_2_7
+    ShParam_2_8
+    ShParam_2_9
     SharingComp3
     Comp3ShLabel
     ShParam_3_1
@@ -89,6 +96,10 @@ use Qt::attributes qw(
     ShParam_3_3
     ShParam_3_4
     ShParam_3_5
+    ShParam_3_6
+    ShParam_3_7
+    ShParam_3_8
+    ShParam_3_9
     InitializationPage
     InitParamTable
     FittingPage
@@ -646,72 +657,117 @@ sub NEW
     buttonGroupSharing->setAlignment( int(&Qt::ButtonGroup::AlignLeft) );
     buttonGroupSharing->setCheckable( 0 );
 
-    my $LayoutWidget_2 = Qt::Widget(buttonGroupSharing, '$LayoutWidget_2');
-    $LayoutWidget_2->setGeometry( Qt::Rect(30, 50, 500, 311) );
-    my $layoutShComp = Qt::HBoxLayout($LayoutWidget_2, 11, 6, '$layoutShComp');
-
-    SharingComp1 = Qt::ButtonGroup($LayoutWidget_2, "SharingComp1");
+    SharingComp1 = Qt::ButtonGroup(buttonGroupSharing, "SharingComp1");
     SharingComp1->setEnabled( 0 );
+    SharingComp1->setGeometry( Qt::Rect(31, 25, 162, 335) );
     SharingComp1->setSizePolicy( Qt::SizePolicy(5, 3, 0, 0, SharingComp1->sizePolicy()->hasHeightForWidth()) );
     SharingComp1->setAlignment( int(&Qt::ButtonGroup::AlignLeft) );
 
-    my $LayoutWidget_3 = Qt::Widget(SharingComp1, '$LayoutWidget_3');
-    $LayoutWidget_3->setGeometry( Qt::Rect(30, 70, 81, 190) );
-    my $layoutComp1 = Qt::VBoxLayout($LayoutWidget_3, 11, 6, '$layoutComp1');
-
-    ShParam_1_1 = Qt::CheckBox($LayoutWidget_3, "ShParam_1_1");
-    $layoutComp1->addWidget(ShParam_1_1);
-
-    ShParam_1_2 = Qt::CheckBox($LayoutWidget_3, "ShParam_1_2");
-    $layoutComp1->addWidget(ShParam_1_2);
-
-    ShParam_1_3 = Qt::CheckBox($LayoutWidget_3, "ShParam_1_3");
-    $layoutComp1->addWidget(ShParam_1_3);
-
-    ShParam_1_4 = Qt::CheckBox($LayoutWidget_3, "ShParam_1_4");
-    $layoutComp1->addWidget(ShParam_1_4);
-
-    ShParam_1_5 = Qt::CheckBox($LayoutWidget_3, "ShParam_1_5");
-    ShParam_1_5->setEnabled( 0 );
-    ShParam_1_5->setPaletteBackgroundColor( Qt::Color(234, 233, 232) );
-    ShParam_1_5->setTristate( 0 );
-    $layoutComp1->addWidget(ShParam_1_5);
-
     Comp1ShLabel = Qt::Label(SharingComp1, "Comp1ShLabel");
     Comp1ShLabel->setGeometry( Qt::Rect(2, 30, 185, 20) );
     Comp1ShLabel->setPaletteBackgroundColor( Qt::Color(255, 255, 127) );
-    $layoutShComp->addWidget(SharingComp1);
 
-    SharingComp2 = Qt::ButtonGroup($LayoutWidget_2, "SharingComp2");
+    my $LayoutWidget_2 = Qt::Widget(SharingComp1, '$LayoutWidget_2');
+    $LayoutWidget_2->setGeometry( Qt::Rect(40, 60, 81, 266) );
+    my $layout14 = Qt::VBoxLayout($LayoutWidget_2, 0, 0, '$layout14');
+
+    ShParam_1_1 = Qt::CheckBox($LayoutWidget_2, "ShParam_1_1");
+    $layout14->addWidget(ShParam_1_1);
+
+    ShParam_1_2 = Qt::CheckBox($LayoutWidget_2, "ShParam_1_2");
+    $layout14->addWidget(ShParam_1_2);
+
+    ShParam_1_3 = Qt::CheckBox($LayoutWidget_2, "ShParam_1_3");
+    $layout14->addWidget(ShParam_1_3);
+
+    ShParam_1_4 = Qt::CheckBox($LayoutWidget_2, "ShParam_1_4");
+    $layout14->addWidget(ShParam_1_4);
+
+    ShParam_1_5 = Qt::CheckBox($LayoutWidget_2, "ShParam_1_5");
+    ShParam_1_5->setEnabled( 0 );
+    ShParam_1_5->setPaletteBackgroundColor( Qt::Color(234, 233, 232) );
+    ShParam_1_5->setTristate( 0 );
+    $layout14->addWidget(ShParam_1_5);
+
+    ShParam_1_6 = Qt::CheckBox($LayoutWidget_2, "ShParam_1_6");
+    ShParam_1_6->setEnabled( 0 );
+    ShParam_1_6->setPaletteBackgroundColor( Qt::Color(234, 233, 232) );
+    ShParam_1_6->setTristate( 0 );
+    $layout14->addWidget(ShParam_1_6);
+
+    ShParam_1_7 = Qt::CheckBox($LayoutWidget_2, "ShParam_1_7");
+    ShParam_1_7->setEnabled( 0 );
+    ShParam_1_7->setPaletteBackgroundColor( Qt::Color(234, 233, 232) );
+    ShParam_1_7->setTristate( 0 );
+    $layout14->addWidget(ShParam_1_7);
+
+    ShParam_1_8 = Qt::CheckBox($LayoutWidget_2, "ShParam_1_8");
+    ShParam_1_8->setEnabled( 0 );
+    ShParam_1_8->setPaletteBackgroundColor( Qt::Color(234, 233, 232) );
+    ShParam_1_8->setTristate( 0 );
+    $layout14->addWidget(ShParam_1_8);
+
+    ShParam_1_9 = Qt::CheckBox($LayoutWidget_2, "ShParam_1_9");
+    ShParam_1_9->setEnabled( 0 );
+    ShParam_1_9->setPaletteBackgroundColor( Qt::Color(234, 233, 232) );
+    ShParam_1_9->setTristate( 0 );
+    $layout14->addWidget(ShParam_1_9);
+
+    SharingComp2 = Qt::ButtonGroup(buttonGroupSharing, "SharingComp2");
     SharingComp2->setEnabled( 0 );
+    SharingComp2->setGeometry( Qt::Rect(199, 25, 162, 335) );
     SharingComp2->setSizePolicy( Qt::SizePolicy(5, 3, 0, 0, SharingComp2->sizePolicy()->hasHeightForWidth()) );
 
     Comp2ShLabel = Qt::Label(SharingComp2, "Comp2ShLabel");
     Comp2ShLabel->setGeometry( Qt::Rect(2, 30, 185, 20) );
     Comp2ShLabel->setPaletteBackgroundColor( Qt::Color(255, 255, 127) );
 
-    my $LayoutWidget_4 = Qt::Widget(SharingComp2, '$LayoutWidget_4');
-    $LayoutWidget_4->setGeometry( Qt::Rect(20, 70, 81, 190) );
-    my $layoutComp2 = Qt::VBoxLayout($LayoutWidget_4, 11, 6, '$layoutComp2');
+    my $LayoutWidget_3 = Qt::Widget(SharingComp2, '$LayoutWidget_3');
+    $LayoutWidget_3->setGeometry( Qt::Rect(40, 60, 81, 266) );
+    my $layout13 = Qt::VBoxLayout($LayoutWidget_3, 0, 0, '$layout13');
 
-    ShParam_2_1 = Qt::CheckBox($LayoutWidget_4, "ShParam_2_1");
-    $layoutComp2->addWidget(ShParam_2_1);
+    ShParam_2_1 = Qt::CheckBox($LayoutWidget_3, "ShParam_2_1");
+    $layout13->addWidget(ShParam_2_1);
 
-    ShParam_2_2 = Qt::CheckBox($LayoutWidget_4, "ShParam_2_2");
-    $layoutComp2->addWidget(ShParam_2_2);
+    ShParam_2_2 = Qt::CheckBox($LayoutWidget_3, "ShParam_2_2");
+    $layout13->addWidget(ShParam_2_2);
 
-    ShParam_2_3 = Qt::CheckBox($LayoutWidget_4, "ShParam_2_3");
-    $layoutComp2->addWidget(ShParam_2_3);
+    ShParam_2_3 = Qt::CheckBox($LayoutWidget_3, "ShParam_2_3");
+    $layout13->addWidget(ShParam_2_3);
 
-    ShParam_2_4 = Qt::CheckBox($LayoutWidget_4, "ShParam_2_4");
-    $layoutComp2->addWidget(ShParam_2_4);
+    ShParam_2_4 = Qt::CheckBox($LayoutWidget_3, "ShParam_2_4");
+    $layout13->addWidget(ShParam_2_4);
 
-    ShParam_2_5 = Qt::CheckBox($LayoutWidget_4, "ShParam_2_5");
-    $layoutComp2->addWidget(ShParam_2_5);
-    $layoutShComp->addWidget(SharingComp2);
+    ShParam_2_5 = Qt::CheckBox($LayoutWidget_3, "ShParam_2_5");
+    $layout13->addWidget(ShParam_2_5);
 
-    SharingComp3 = Qt::ButtonGroup($LayoutWidget_2, "SharingComp3");
+    ShParam_2_6 = Qt::CheckBox($LayoutWidget_3, "ShParam_2_6");
+    ShParam_2_6->setEnabled( 0 );
+    ShParam_2_6->setPaletteBackgroundColor( Qt::Color(234, 233, 232) );
+    ShParam_2_6->setTristate( 0 );
+    $layout13->addWidget(ShParam_2_6);
+
+    ShParam_2_7 = Qt::CheckBox($LayoutWidget_3, "ShParam_2_7");
+    ShParam_2_7->setEnabled( 0 );
+    ShParam_2_7->setPaletteBackgroundColor( Qt::Color(234, 233, 232) );
+    ShParam_2_7->setTristate( 0 );
+    $layout13->addWidget(ShParam_2_7);
+
+    ShParam_2_8 = Qt::CheckBox($LayoutWidget_3, "ShParam_2_8");
+    ShParam_2_8->setEnabled( 0 );
+    ShParam_2_8->setPaletteBackgroundColor( Qt::Color(234, 233, 232) );
+    ShParam_2_8->setTristate( 0 );
+    $layout13->addWidget(ShParam_2_8);
+
+    ShParam_2_9 = Qt::CheckBox($LayoutWidget_3, "ShParam_2_9");
+    ShParam_2_9->setEnabled( 0 );
+    ShParam_2_9->setPaletteBackgroundColor( Qt::Color(234, 233, 232) );
+    ShParam_2_9->setTristate( 0 );
+    $layout13->addWidget(ShParam_2_9);
+
+    SharingComp3 = Qt::ButtonGroup(buttonGroupSharing, "SharingComp3");
     SharingComp3->setEnabled( 0 );
+    SharingComp3->setGeometry( Qt::Rect(367, 25, 162, 335) );
     SharingComp3->setSizePolicy( Qt::SizePolicy(5, 3, 0, 0, SharingComp3->sizePolicy()->hasHeightForWidth()) );
     SharingComp3->setAlignment( int(&Qt::ButtonGroup::AlignJustify | &Qt::ButtonGroup::AlignVCenter) );
 
@@ -719,25 +775,48 @@ sub NEW
     Comp3ShLabel->setGeometry( Qt::Rect(2, 30, 185, 20) );
     Comp3ShLabel->setPaletteBackgroundColor( Qt::Color(255, 255, 127) );
 
-    my $LayoutWidget_5 = Qt::Widget(SharingComp3, '$LayoutWidget_5');
-    $LayoutWidget_5->setGeometry( Qt::Rect(30, 70, 81, 190) );
-    my $layoutComp3 = Qt::VBoxLayout($LayoutWidget_5, 11, 6, '$layoutComp3');
+    my $LayoutWidget_4 = Qt::Widget(SharingComp3, '$LayoutWidget_4');
+    $LayoutWidget_4->setGeometry( Qt::Rect(41, 58, 81, 266) );
+    my $layout15 = Qt::VBoxLayout($LayoutWidget_4, 11, 6, '$layout15');
 
-    ShParam_3_1 = Qt::CheckBox($LayoutWidget_5, "ShParam_3_1");
-    $layoutComp3->addWidget(ShParam_3_1);
+    ShParam_3_1 = Qt::CheckBox($LayoutWidget_4, "ShParam_3_1");
+    $layout15->addWidget(ShParam_3_1);
 
-    ShParam_3_2 = Qt::CheckBox($LayoutWidget_5, "ShParam_3_2");
-    $layoutComp3->addWidget(ShParam_3_2);
+    ShParam_3_2 = Qt::CheckBox($LayoutWidget_4, "ShParam_3_2");
+    $layout15->addWidget(ShParam_3_2);
 
-    ShParam_3_3 = Qt::CheckBox($LayoutWidget_5, "ShParam_3_3");
-    $layoutComp3->addWidget(ShParam_3_3);
+    ShParam_3_3 = Qt::CheckBox($LayoutWidget_4, "ShParam_3_3");
+    $layout15->addWidget(ShParam_3_3);
 
-    ShParam_3_4 = Qt::CheckBox($LayoutWidget_5, "ShParam_3_4");
-    $layoutComp3->addWidget(ShParam_3_4);
+    ShParam_3_4 = Qt::CheckBox($LayoutWidget_4, "ShParam_3_4");
+    $layout15->addWidget(ShParam_3_4);
 
-    ShParam_3_5 = Qt::CheckBox($LayoutWidget_5, "ShParam_3_5");
-    $layoutComp3->addWidget(ShParam_3_5);
-    $layoutShComp->addWidget(SharingComp3);
+    ShParam_3_5 = Qt::CheckBox($LayoutWidget_4, "ShParam_3_5");
+    $layout15->addWidget(ShParam_3_5);
+
+    ShParam_3_6 = Qt::CheckBox($LayoutWidget_4, "ShParam_3_6");
+    ShParam_3_6->setEnabled( 0 );
+    ShParam_3_6->setPaletteBackgroundColor( Qt::Color(234, 233, 232) );
+    ShParam_3_6->setTristate( 0 );
+    $layout15->addWidget(ShParam_3_6);
+
+    ShParam_3_7 = Qt::CheckBox($LayoutWidget_4, "ShParam_3_7");
+    ShParam_3_7->setEnabled( 0 );
+    ShParam_3_7->setPaletteBackgroundColor( Qt::Color(234, 233, 232) );
+    ShParam_3_7->setTristate( 0 );
+    $layout15->addWidget(ShParam_3_7);
+
+    ShParam_3_8 = Qt::CheckBox($LayoutWidget_4, "ShParam_3_8");
+    ShParam_3_8->setEnabled( 0 );
+    ShParam_3_8->setPaletteBackgroundColor( Qt::Color(234, 233, 232) );
+    ShParam_3_8->setTristate( 0 );
+    $layout15->addWidget(ShParam_3_8);
+
+    ShParam_3_9 = Qt::CheckBox($LayoutWidget_4, "ShParam_3_9");
+    ShParam_3_9->setEnabled( 0 );
+    ShParam_3_9->setPaletteBackgroundColor( Qt::Color(234, 233, 232) );
+    ShParam_3_9->setTristate( 0 );
+    $layout15->addWidget(ShParam_3_9);
     musrfit_tabs->insertTab( SharingPahe, "" );
 
     InitializationPage = Qt::Widget(musrfit_tabs, "InitializationPage");
@@ -874,7 +953,7 @@ sub NEW
     MenuBar= Qt::MenuBar( this, "MenuBar");
 
     MenuBar->setEnabled( 1 );
-    MenuBar->setGeometry( Qt::Rect(0, 0, 567, 27) );
+    MenuBar->setGeometry( Qt::Rect(0, 0, 570, 27) );
 
     fileMenu = Qt::PopupMenu( this );
     fileOpenAction->addTo( fileMenu );
@@ -910,12 +989,11 @@ sub NEW
     MenuBar->insertSeparator( 7 );
 
     languageChange();
-    my $resize = Qt::Size(567, 490);
+    my $resize = Qt::Size(570, 490);
     $resize = $resize->expandedTo(minimumSizeHint());
     resize( $resize );
     clearWState( &Qt::WState_Polished );
 
-    Qt::Object::connect(musrfit_tabs, SIGNAL "selected(const QString&)", this, SLOT "TabChanged()");
     Qt::Object::connect(helpAboutAction, SIGNAL "activated()", this, SLOT "helpAbout()");
     Qt::Object::connect(helpContentsAction, SIGNAL "activated()", this, SLOT "helpContents()");
     Qt::Object::connect(helpIndexAction, SIGNAL "activated()", this, SLOT "helpIndex()");
@@ -928,10 +1006,10 @@ sub NEW
     Qt::Object::connect(filePrintAction, SIGNAL "activated()", this, SLOT "filePrint()");
     Qt::Object::connect(fileSaveAction, SIGNAL "activated()", this, SLOT "fileSave()");
     Qt::Object::connect(fileOpenAction, SIGNAL "activated()", this, SLOT "fileOpen()");
-    Qt::Object::connect(fileNewAction, SIGNAL "activated()", this, SLOT "fileNew()");
+    Qt::Object::connect(fileChangeDirAction, SIGNAL "activated()", this, SLOT "fileChangeDir()");
+    Qt::Object::connect(musrfit_tabs, SIGNAL "selected(const QString&)", this, SLOT "TabChanged()");
     Qt::Object::connect(go, SIGNAL "clicked()", this, SLOT "GoFit()");
     Qt::Object::connect(InitParamTable, SIGNAL "valueChanged(int,int)", this, SLOT "UpdeateTable()");
-    Qt::Object::connect(fileChangeDirAction, SIGNAL "activated()", this, SLOT "fileChangeDir()");
 
     setTabOrder(musrfit_tabs, TITLE);
     setTabOrder(TITLE, FILENAME);
@@ -1063,18 +1141,22 @@ sub languageChange
     FitAsyTypeLabel->setText( trUtf8("Fit type") );
     FitAsyType->clear();
     FitAsyType->insertItem( trUtf8("Asymmetry") );
-    FitAsyType->insertItem( trUtf8("Single Histogram") );
+    FitAsyType->insertItem( trUtf8("SingleHist") );
     LRBFLabel->setText( trUtf8("Histograms list") );
     LRBF->setText( trUtf8("1,3") );
     musrfit_tabs->changeTab( RUNSPage, trUtf8("RUNS") );
     buttonGroupSharing->setTitle( trUtf8("Shared Parameters") );
     SharingComp1->setTitle( trUtf8("1st Component") );
+    Comp1ShLabel->setText( trUtf8("FitType1") );
     ShParam_1_1->setText( trUtf8("Param1") );
     ShParam_1_2->setText( trUtf8("Param2") );
     ShParam_1_3->setText( trUtf8("Param3") );
     ShParam_1_4->setText( trUtf8("Param4") );
     ShParam_1_5->setText( trUtf8("Param5") );
-    Comp1ShLabel->setText( trUtf8("FitType1") );
+    ShParam_1_6->setText( trUtf8("Param6") );
+    ShParam_1_7->setText( trUtf8("Param7") );
+    ShParam_1_8->setText( trUtf8("Param8") );
+    ShParam_1_9->setText( trUtf8("Param9") );
     SharingComp2->setTitle( trUtf8("2nd Component") );
     Comp2ShLabel->setText( trUtf8("FitType2") );
     ShParam_2_1->setText( trUtf8("Param1") );
@@ -1082,6 +1164,10 @@ sub languageChange
     ShParam_2_3->setText( trUtf8("Param3") );
     ShParam_2_4->setText( trUtf8("Param4") );
     ShParam_2_5->setText( trUtf8("Param5") );
+    ShParam_2_6->setText( trUtf8("Param6") );
+    ShParam_2_7->setText( trUtf8("Param7") );
+    ShParam_2_8->setText( trUtf8("Param8") );
+    ShParam_2_9->setText( trUtf8("Param9") );
     SharingComp3->setTitle( trUtf8("3rd Component") );
     Comp3ShLabel->setText( trUtf8("FitType3") );
     ShParam_3_1->setText( trUtf8("Param1") );
@@ -1089,6 +1175,10 @@ sub languageChange
     ShParam_3_3->setText( trUtf8("Param3") );
     ShParam_3_4->setText( trUtf8("Param4") );
     ShParam_3_5->setText( trUtf8("Param5") );
+    ShParam_3_6->setText( trUtf8("Param6") );
+    ShParam_3_7->setText( trUtf8("Param7") );
+    ShParam_3_8->setText( trUtf8("Param8") );
+    ShParam_3_9->setText( trUtf8("Param9") );
     musrfit_tabs->changeTab( SharingPahe, trUtf8("Sharing") );
     InitParamTable->horizontalHeader()->setLabel( 0, trUtf8("Value") );
     InitParamTable->horizontalHeader()->setLabel( 1, trUtf8("Error") );
@@ -1113,7 +1203,7 @@ sub languageChange
     fileOpenAction->setAccel( Qt::KeySequence( trUtf8("Ctrl+O") ) );
     fileSaveAction->setText( trUtf8("&Save MSR") );
     fileSaveAction->setMenuText( trUtf8("&Save MSR") );
-    fileSaveAction->setStatusTip( trUtf8("&Save MSRave") );
+    fileSaveAction->setStatusTip( trUtf8("&Save MSR") );
     fileSaveAction->setAccel( Qt::KeySequence( trUtf8("Ctrl+S") ) );
     fileSaveAsAction->setText( trUtf8("Save MSR &As...") );
     fileSaveAsAction->setMenuText( trUtf8("Save MSR &As...") );
@@ -1160,8 +1250,9 @@ sub languageChange
     FileExistCheck->setWhatsThis( trUtf8("Enable/Disable checking for MSR files.") );
     MaualFile->setText( trUtf8("Maual file selection") );
     MaualFile->setMenuText( trUtf8("Maual file selection") );
-    fileChangeDirAction->setText( trUtf8("Change dir") );
-    fileChangeDirAction->setMenuText( trUtf8("Change dir") );
+    fileChangeDirAction->setText( trUtf8("&Change dir") );
+    fileChangeDirAction->setMenuText( trUtf8("&Change dir") );
+    fileChangeDirAction->setAccel( Qt::KeySequence( trUtf8("Ctrl+C") ) );
     toolBar->setLabel( trUtf8("Tools") );
     MenuBar->findItem( 3 )->setText( trUtf8("&File") );
     MenuBar->findItem( 4 )->setText( trUtf8("&Edit") );
@@ -1170,11 +1261,6 @@ sub languageChange
 }
 
 
-sub fileNew
-{
-    print "MuSRFitform->fileNew(): Not implemented yet.\n";
-}
-
 sub fileOpen
 {
 
@@ -1321,6 +1407,7 @@ sub CreateAllInput
     $All{"LRBF"} = LRBF->text;
     $All{"RunNumbers"} =~ s/[\ \.\~\/\&\*\[\;\>\<\^\$\(\)\`\|\]\'\@]/,/g;
     my @RUNS = split( /,/, $All{"RunNumbers"} );
+    my @Hists = split(/,/, $All{"LRBF"} );
     
 # Construct fittypes that can be understood by MSR.pm
     my %FTs=(0,"Exponential",
@@ -1400,12 +1487,17 @@ sub CreateAllInput
 # Change state/label of parameters
 	foreach my $Param (@Params) {
 	    my $Param_ORG = $Param;
+# TODO: I need to take care of single hist fits here
+	    if ( $All{"FitAsyType"} eq "SingleHist" ) {		$Param=$Param.$Hists[0];	    }
 	    if ( $#FitTypes != 0 && (   $Param ne "Alpha" && $Param ne "N0" && $Param ne "NBg" ) ){
 		$Param = join( "", $Param, "_", $Component);
 	    }
 		
 # Is there any point of sharing, multiple runs?
-	    if ( $#RUNS == 0 ) {
+	    if ( $#RUNS == 0 && $All{"FitAsyType"} eq "Asymmetry") {
+		$Shared = 1;
+	    }
+	    elsif ( $#RUNS == 0 && $#Hists == 0 &&  $All{"FitAsyType"} eq "SingleHist" )  {
 		$Shared = 1;
 	    } else {	
 # Check if shared or not, construct name of checkbox, find its handle and then 
@@ -1467,7 +1559,12 @@ sub CallMSRCreate
     use MSR;
     my %All=CreateAllInput();
     if ($All{"RunNumbers"} ne "") {
-	my ($Full_T_Block,$Paramcomp_ref)= MSR::CreateMSR(\%All);
+	if ( $All{"FitAsyType"} eq "Asymmetry" ) {
+	    my ($Full_T_Block,$Paramcomp_ref)= MSR::CreateMSR(\%All);
+	}
+	elsif ( $All{"FitAsyType"} eq "SingleHist" ) {
+	    my ($Full_T_Block,$Paramcomp_ref)= MSR::CreateMSRSingleHist(\%All);
+	}
 	UpdateMSRFileInitTable();
     }
 
@@ -1557,7 +1654,7 @@ sub ActivateShComp
 	$CompShL->setText($All{"FitType$Component"});
 	
 # Change state/label of parameters
-	for (my $i=1; $i<=5;$i++) {		
+	for (my $i=1; $i<=9;$i++) {		
 	    my $ParamChkBx="ShParam_".$Component."_".$i;
 	    my $ChkBx = child($ParamChkBx);
 	    if ($Params[$i-1] ne "") {
@@ -1741,8 +1838,11 @@ sub TabChanged
     if ($All{"RunNumbers"} ne "" && $SlectedTab==4 && $FileExistCheck==1) {
 	if (-e $FILENAME) {
 # Warning: MSR file exists
-	    my $Warning = "Warning: MSR file $FILENAME Already exists!\nChange name or backup file if you do not want to loose it.";
+	    my $Warning = "Warning: MSR file $FILENAME Already exists!\nIf you continue it will overwriten.";
 	    my $WarningWindow = Qt::MessageBox::information( this, "Warning",$Warning);
+#	    my $Answer= Qt::MessageBox::warning( this, "Warning",$Warning, "&No", "&Yes", undef, 1,1);
+# $Answer =1,0 for yes and no
+#	    print "Answer=$Answer\n";
 	}
     }
  
diff --git a/src/external/MuSRFitGUI/MuSRFit.ui b/src/external/MuSRFitGUI/MuSRFit.ui
index a7c78a51..104a328c 100755
--- a/src/external/MuSRFitGUI/MuSRFit.ui
+++ b/src/external/MuSRFitGUI/MuSRFit.ui
@@ -8,7 +8,7 @@
         <rect>
             <x>0</x>
             <y>0</y>
-            <width>567</width>
+            <width>570</width>
             <height>490</height>
         </rect>
     </property>
@@ -731,7 +731,7 @@
                                 </item>
                                 <item>
                                     <property name="text">
-                                        <string>Single Histogram</string>
+                                        <string>SingleHist</string>
                                     </property>
                                 </item>
                                 <property name="name">
@@ -803,342 +803,612 @@
                 <property name="checkable">
                     <bool>false</bool>
                 </property>
-                <widget class="QLayoutWidget">
+                <widget class="QButtonGroup">
                     <property name="name">
-                        <cstring>layoutShComp</cstring>
+                        <cstring>SharingComp1</cstring>
+                    </property>
+                    <property name="enabled">
+                        <bool>false</bool>
                     </property>
                     <property name="geometry">
                         <rect>
-                            <x>30</x>
-                            <y>50</y>
-                            <width>500</width>
-                            <height>311</height>
+                            <x>31</x>
+                            <y>25</y>
+                            <width>162</width>
+                            <height>335</height>
                         </rect>
                     </property>
-                    <hbox>
+                    <property name="sizePolicy">
+                        <sizepolicy>
+                            <hsizetype>5</hsizetype>
+                            <vsizetype>3</vsizetype>
+                            <horstretch>0</horstretch>
+                            <verstretch>0</verstretch>
+                        </sizepolicy>
+                    </property>
+                    <property name="title">
+                        <string>1st Component</string>
+                    </property>
+                    <property name="alignment">
+                        <set>AlignLeft</set>
+                    </property>
+                    <widget class="QLabel">
                         <property name="name">
-                            <cstring>unnamed</cstring>
+                            <cstring>Comp1ShLabel</cstring>
                         </property>
-                        <widget class="QButtonGroup">
+                        <property name="geometry">
+                            <rect>
+                                <x>2</x>
+                                <y>30</y>
+                                <width>185</width>
+                                <height>20</height>
+                            </rect>
+                        </property>
+                        <property name="paletteBackgroundColor">
+                            <color>
+                                <red>255</red>
+                                <green>255</green>
+                                <blue>127</blue>
+                            </color>
+                        </property>
+                        <property name="text">
+                            <string>FitType1</string>
+                        </property>
+                    </widget>
+                    <widget class="QLayoutWidget">
+                        <property name="name">
+                            <cstring>layout14</cstring>
+                        </property>
+                        <property name="geometry">
+                            <rect>
+                                <x>40</x>
+                                <y>60</y>
+                                <width>81</width>
+                                <height>266</height>
+                            </rect>
+                        </property>
+                        <vbox>
                             <property name="name">
-                                <cstring>SharingComp1</cstring>
+                                <cstring>unnamed</cstring>
                             </property>
-                            <property name="enabled">
-                                <bool>false</bool>
+                            <property name="margin">
+                                <number>0</number>
                             </property>
-                            <property name="sizePolicy">
-                                <sizepolicy>
-                                    <hsizetype>5</hsizetype>
-                                    <vsizetype>3</vsizetype>
-                                    <horstretch>0</horstretch>
-                                    <verstretch>0</verstretch>
-                                </sizepolicy>
+                            <property name="spacing">
+                                <number>0</number>
                             </property>
-                            <property name="title">
-                                <string>1st Component</string>
-                            </property>
-                            <property name="alignment">
-                                <set>AlignLeft</set>
-                            </property>
-                            <widget class="QLayoutWidget">
+                            <widget class="QCheckBox">
                                 <property name="name">
-                                    <cstring>layoutComp1</cstring>
+                                    <cstring>ShParam_1_1</cstring>
                                 </property>
-                                <property name="geometry">
-                                    <rect>
-                                        <x>30</x>
-                                        <y>70</y>
-                                        <width>81</width>
-                                        <height>190</height>
-                                    </rect>
+                                <property name="text">
+                                    <string>Param1</string>
                                 </property>
-                                <vbox>
-                                    <property name="name">
-                                        <cstring>unnamed</cstring>
-                                    </property>
-                                    <widget class="QCheckBox">
-                                        <property name="name">
-                                            <cstring>ShParam_1_1</cstring>
-                                        </property>
-                                        <property name="text">
-                                            <string>Param1</string>
-                                        </property>
-                                    </widget>
-                                    <widget class="QCheckBox">
-                                        <property name="name">
-                                            <cstring>ShParam_1_2</cstring>
-                                        </property>
-                                        <property name="text">
-                                            <string>Param2</string>
-                                        </property>
-                                    </widget>
-                                    <widget class="QCheckBox">
-                                        <property name="name">
-                                            <cstring>ShParam_1_3</cstring>
-                                        </property>
-                                        <property name="text">
-                                            <string>Param3</string>
-                                        </property>
-                                    </widget>
-                                    <widget class="QCheckBox">
-                                        <property name="name">
-                                            <cstring>ShParam_1_4</cstring>
-                                        </property>
-                                        <property name="text">
-                                            <string>Param4</string>
-                                        </property>
-                                    </widget>
-                                    <widget class="QCheckBox">
-                                        <property name="name">
-                                            <cstring>ShParam_1_5</cstring>
-                                        </property>
-                                        <property name="enabled">
-                                            <bool>false</bool>
-                                        </property>
-                                        <property name="paletteBackgroundColor">
-                                            <color>
-                                                <red>234</red>
-                                                <green>233</green>
-                                                <blue>232</blue>
-                                            </color>
-                                        </property>
-                                        <property name="text">
-                                            <string>Param5</string>
-                                        </property>
-                                        <property name="tristate">
-                                            <bool>false</bool>
-                                        </property>
-                                    </widget>
-                                </vbox>
                             </widget>
-                            <widget class="QLabel">
+                            <widget class="QCheckBox">
                                 <property name="name">
-                                    <cstring>Comp1ShLabel</cstring>
+                                    <cstring>ShParam_1_2</cstring>
                                 </property>
-                                <property name="geometry">
-                                    <rect>
-                                        <x>2</x>
-                                        <y>30</y>
-                                        <width>185</width>
-                                        <height>20</height>
-                                    </rect>
+                                <property name="text">
+                                    <string>Param2</string>
+                                </property>
+                            </widget>
+                            <widget class="QCheckBox">
+                                <property name="name">
+                                    <cstring>ShParam_1_3</cstring>
+                                </property>
+                                <property name="text">
+                                    <string>Param3</string>
+                                </property>
+                            </widget>
+                            <widget class="QCheckBox">
+                                <property name="name">
+                                    <cstring>ShParam_1_4</cstring>
+                                </property>
+                                <property name="text">
+                                    <string>Param4</string>
+                                </property>
+                            </widget>
+                            <widget class="QCheckBox">
+                                <property name="name">
+                                    <cstring>ShParam_1_5</cstring>
+                                </property>
+                                <property name="enabled">
+                                    <bool>false</bool>
                                 </property>
                                 <property name="paletteBackgroundColor">
                                     <color>
-                                        <red>255</red>
-                                        <green>255</green>
-                                        <blue>127</blue>
+                                        <red>234</red>
+                                        <green>233</green>
+                                        <blue>232</blue>
                                     </color>
                                 </property>
                                 <property name="text">
-                                    <string>FitType1</string>
+                                    <string>Param5</string>
+                                </property>
+                                <property name="tristate">
+                                    <bool>false</bool>
                                 </property>
                             </widget>
-                        </widget>
-                        <widget class="QButtonGroup">
-                            <property name="name">
-                                <cstring>SharingComp2</cstring>
-                            </property>
-                            <property name="enabled">
-                                <bool>false</bool>
-                            </property>
-                            <property name="sizePolicy">
-                                <sizepolicy>
-                                    <hsizetype>5</hsizetype>
-                                    <vsizetype>3</vsizetype>
-                                    <horstretch>0</horstretch>
-                                    <verstretch>0</verstretch>
-                                </sizepolicy>
-                            </property>
-                            <property name="title">
-                                <string>2nd Component</string>
-                            </property>
-                            <widget class="QLabel">
+                            <widget class="QCheckBox">
                                 <property name="name">
-                                    <cstring>Comp2ShLabel</cstring>
+                                    <cstring>ShParam_1_6</cstring>
                                 </property>
-                                <property name="geometry">
-                                    <rect>
-                                        <x>2</x>
-                                        <y>30</y>
-                                        <width>185</width>
-                                        <height>20</height>
-                                    </rect>
+                                <property name="enabled">
+                                    <bool>false</bool>
                                 </property>
                                 <property name="paletteBackgroundColor">
                                     <color>
-                                        <red>255</red>
-                                        <green>255</green>
-                                        <blue>127</blue>
+                                        <red>234</red>
+                                        <green>233</green>
+                                        <blue>232</blue>
                                     </color>
                                 </property>
                                 <property name="text">
-                                    <string>FitType2</string>
+                                    <string>Param6</string>
+                                </property>
+                                <property name="tristate">
+                                    <bool>false</bool>
                                 </property>
                             </widget>
-                            <widget class="QLayoutWidget">
+                            <widget class="QCheckBox">
                                 <property name="name">
-                                    <cstring>layoutComp2</cstring>
+                                    <cstring>ShParam_1_7</cstring>
                                 </property>
-                                <property name="geometry">
-                                    <rect>
-                                        <x>20</x>
-                                        <y>70</y>
-                                        <width>81</width>
-                                        <height>190</height>
-                                    </rect>
-                                </property>
-                                <vbox>
-                                    <property name="name">
-                                        <cstring>unnamed</cstring>
-                                    </property>
-                                    <widget class="QCheckBox">
-                                        <property name="name">
-                                            <cstring>ShParam_2_1</cstring>
-                                        </property>
-                                        <property name="text">
-                                            <string>Param1</string>
-                                        </property>
-                                    </widget>
-                                    <widget class="QCheckBox">
-                                        <property name="name">
-                                            <cstring>ShParam_2_2</cstring>
-                                        </property>
-                                        <property name="text">
-                                            <string>Param2</string>
-                                        </property>
-                                    </widget>
-                                    <widget class="QCheckBox">
-                                        <property name="name">
-                                            <cstring>ShParam_2_3</cstring>
-                                        </property>
-                                        <property name="text">
-                                            <string>Param3</string>
-                                        </property>
-                                    </widget>
-                                    <widget class="QCheckBox">
-                                        <property name="name">
-                                            <cstring>ShParam_2_4</cstring>
-                                        </property>
-                                        <property name="text">
-                                            <string>Param4</string>
-                                        </property>
-                                    </widget>
-                                    <widget class="QCheckBox">
-                                        <property name="name">
-                                            <cstring>ShParam_2_5</cstring>
-                                        </property>
-                                        <property name="text">
-                                            <string>Param5</string>
-                                        </property>
-                                    </widget>
-                                </vbox>
-                            </widget>
-                        </widget>
-                        <widget class="QButtonGroup">
-                            <property name="name">
-                                <cstring>SharingComp3</cstring>
-                            </property>
-                            <property name="enabled">
-                                <bool>false</bool>
-                            </property>
-                            <property name="sizePolicy">
-                                <sizepolicy>
-                                    <hsizetype>5</hsizetype>
-                                    <vsizetype>3</vsizetype>
-                                    <horstretch>0</horstretch>
-                                    <verstretch>0</verstretch>
-                                </sizepolicy>
-                            </property>
-                            <property name="title">
-                                <string>3rd Component</string>
-                            </property>
-                            <property name="alignment">
-                                <set>AlignJustify|AlignVCenter</set>
-                            </property>
-                            <widget class="QLabel">
-                                <property name="name">
-                                    <cstring>Comp3ShLabel</cstring>
-                                </property>
-                                <property name="geometry">
-                                    <rect>
-                                        <x>2</x>
-                                        <y>30</y>
-                                        <width>185</width>
-                                        <height>20</height>
-                                    </rect>
+                                <property name="enabled">
+                                    <bool>false</bool>
                                 </property>
                                 <property name="paletteBackgroundColor">
                                     <color>
-                                        <red>255</red>
-                                        <green>255</green>
-                                        <blue>127</blue>
+                                        <red>234</red>
+                                        <green>233</green>
+                                        <blue>232</blue>
                                     </color>
                                 </property>
                                 <property name="text">
-                                    <string>FitType3</string>
+                                    <string>Param7</string>
+                                </property>
+                                <property name="tristate">
+                                    <bool>false</bool>
                                 </property>
                             </widget>
-                            <widget class="QLayoutWidget">
+                            <widget class="QCheckBox">
                                 <property name="name">
-                                    <cstring>layoutComp3</cstring>
+                                    <cstring>ShParam_1_8</cstring>
                                 </property>
-                                <property name="geometry">
-                                    <rect>
-                                        <x>30</x>
-                                        <y>70</y>
-                                        <width>81</width>
-                                        <height>190</height>
-                                    </rect>
+                                <property name="enabled">
+                                    <bool>false</bool>
+                                </property>
+                                <property name="paletteBackgroundColor">
+                                    <color>
+                                        <red>234</red>
+                                        <green>233</green>
+                                        <blue>232</blue>
+                                    </color>
+                                </property>
+                                <property name="text">
+                                    <string>Param8</string>
+                                </property>
+                                <property name="tristate">
+                                    <bool>false</bool>
                                 </property>
-                                <vbox>
-                                    <property name="name">
-                                        <cstring>unnamed</cstring>
-                                    </property>
-                                    <widget class="QCheckBox">
-                                        <property name="name">
-                                            <cstring>ShParam_3_1</cstring>
-                                        </property>
-                                        <property name="text">
-                                            <string>Param1</string>
-                                        </property>
-                                    </widget>
-                                    <widget class="QCheckBox">
-                                        <property name="name">
-                                            <cstring>ShParam_3_2</cstring>
-                                        </property>
-                                        <property name="text">
-                                            <string>Param2</string>
-                                        </property>
-                                    </widget>
-                                    <widget class="QCheckBox">
-                                        <property name="name">
-                                            <cstring>ShParam_3_3</cstring>
-                                        </property>
-                                        <property name="text">
-                                            <string>Param3</string>
-                                        </property>
-                                    </widget>
-                                    <widget class="QCheckBox">
-                                        <property name="name">
-                                            <cstring>ShParam_3_4</cstring>
-                                        </property>
-                                        <property name="text">
-                                            <string>Param4</string>
-                                        </property>
-                                    </widget>
-                                    <widget class="QCheckBox">
-                                        <property name="name">
-                                            <cstring>ShParam_3_5</cstring>
-                                        </property>
-                                        <property name="text">
-                                            <string>Param5</string>
-                                        </property>
-                                    </widget>
-                                </vbox>
                             </widget>
-                        </widget>
-                    </hbox>
+                            <widget class="QCheckBox">
+                                <property name="name">
+                                    <cstring>ShParam_1_9</cstring>
+                                </property>
+                                <property name="enabled">
+                                    <bool>false</bool>
+                                </property>
+                                <property name="paletteBackgroundColor">
+                                    <color>
+                                        <red>234</red>
+                                        <green>233</green>
+                                        <blue>232</blue>
+                                    </color>
+                                </property>
+                                <property name="text">
+                                    <string>Param9</string>
+                                </property>
+                                <property name="tristate">
+                                    <bool>false</bool>
+                                </property>
+                            </widget>
+                        </vbox>
+                    </widget>
+                </widget>
+                <widget class="QButtonGroup">
+                    <property name="name">
+                        <cstring>SharingComp2</cstring>
+                    </property>
+                    <property name="enabled">
+                        <bool>false</bool>
+                    </property>
+                    <property name="geometry">
+                        <rect>
+                            <x>199</x>
+                            <y>25</y>
+                            <width>162</width>
+                            <height>335</height>
+                        </rect>
+                    </property>
+                    <property name="sizePolicy">
+                        <sizepolicy>
+                            <hsizetype>5</hsizetype>
+                            <vsizetype>3</vsizetype>
+                            <horstretch>0</horstretch>
+                            <verstretch>0</verstretch>
+                        </sizepolicy>
+                    </property>
+                    <property name="title">
+                        <string>2nd Component</string>
+                    </property>
+                    <widget class="QLabel">
+                        <property name="name">
+                            <cstring>Comp2ShLabel</cstring>
+                        </property>
+                        <property name="geometry">
+                            <rect>
+                                <x>2</x>
+                                <y>30</y>
+                                <width>185</width>
+                                <height>20</height>
+                            </rect>
+                        </property>
+                        <property name="paletteBackgroundColor">
+                            <color>
+                                <red>255</red>
+                                <green>255</green>
+                                <blue>127</blue>
+                            </color>
+                        </property>
+                        <property name="text">
+                            <string>FitType2</string>
+                        </property>
+                    </widget>
+                    <widget class="QLayoutWidget">
+                        <property name="name">
+                            <cstring>layout13</cstring>
+                        </property>
+                        <property name="geometry">
+                            <rect>
+                                <x>40</x>
+                                <y>60</y>
+                                <width>81</width>
+                                <height>266</height>
+                            </rect>
+                        </property>
+                        <vbox>
+                            <property name="name">
+                                <cstring>unnamed</cstring>
+                            </property>
+                            <property name="margin">
+                                <number>0</number>
+                            </property>
+                            <property name="spacing">
+                                <number>0</number>
+                            </property>
+                            <widget class="QCheckBox">
+                                <property name="name">
+                                    <cstring>ShParam_2_1</cstring>
+                                </property>
+                                <property name="text">
+                                    <string>Param1</string>
+                                </property>
+                            </widget>
+                            <widget class="QCheckBox">
+                                <property name="name">
+                                    <cstring>ShParam_2_2</cstring>
+                                </property>
+                                <property name="text">
+                                    <string>Param2</string>
+                                </property>
+                            </widget>
+                            <widget class="QCheckBox">
+                                <property name="name">
+                                    <cstring>ShParam_2_3</cstring>
+                                </property>
+                                <property name="text">
+                                    <string>Param3</string>
+                                </property>
+                            </widget>
+                            <widget class="QCheckBox">
+                                <property name="name">
+                                    <cstring>ShParam_2_4</cstring>
+                                </property>
+                                <property name="text">
+                                    <string>Param4</string>
+                                </property>
+                            </widget>
+                            <widget class="QCheckBox">
+                                <property name="name">
+                                    <cstring>ShParam_2_5</cstring>
+                                </property>
+                                <property name="text">
+                                    <string>Param5</string>
+                                </property>
+                            </widget>
+                            <widget class="QCheckBox">
+                                <property name="name">
+                                    <cstring>ShParam_2_6</cstring>
+                                </property>
+                                <property name="enabled">
+                                    <bool>false</bool>
+                                </property>
+                                <property name="paletteBackgroundColor">
+                                    <color>
+                                        <red>234</red>
+                                        <green>233</green>
+                                        <blue>232</blue>
+                                    </color>
+                                </property>
+                                <property name="text">
+                                    <string>Param6</string>
+                                </property>
+                                <property name="tristate">
+                                    <bool>false</bool>
+                                </property>
+                            </widget>
+                            <widget class="QCheckBox">
+                                <property name="name">
+                                    <cstring>ShParam_2_7</cstring>
+                                </property>
+                                <property name="enabled">
+                                    <bool>false</bool>
+                                </property>
+                                <property name="paletteBackgroundColor">
+                                    <color>
+                                        <red>234</red>
+                                        <green>233</green>
+                                        <blue>232</blue>
+                                    </color>
+                                </property>
+                                <property name="text">
+                                    <string>Param7</string>
+                                </property>
+                                <property name="tristate">
+                                    <bool>false</bool>
+                                </property>
+                            </widget>
+                            <widget class="QCheckBox">
+                                <property name="name">
+                                    <cstring>ShParam_2_8</cstring>
+                                </property>
+                                <property name="enabled">
+                                    <bool>false</bool>
+                                </property>
+                                <property name="paletteBackgroundColor">
+                                    <color>
+                                        <red>234</red>
+                                        <green>233</green>
+                                        <blue>232</blue>
+                                    </color>
+                                </property>
+                                <property name="text">
+                                    <string>Param8</string>
+                                </property>
+                                <property name="tristate">
+                                    <bool>false</bool>
+                                </property>
+                            </widget>
+                            <widget class="QCheckBox">
+                                <property name="name">
+                                    <cstring>ShParam_2_9</cstring>
+                                </property>
+                                <property name="enabled">
+                                    <bool>false</bool>
+                                </property>
+                                <property name="paletteBackgroundColor">
+                                    <color>
+                                        <red>234</red>
+                                        <green>233</green>
+                                        <blue>232</blue>
+                                    </color>
+                                </property>
+                                <property name="text">
+                                    <string>Param9</string>
+                                </property>
+                                <property name="tristate">
+                                    <bool>false</bool>
+                                </property>
+                            </widget>
+                        </vbox>
+                    </widget>
+                </widget>
+                <widget class="QButtonGroup">
+                    <property name="name">
+                        <cstring>SharingComp3</cstring>
+                    </property>
+                    <property name="enabled">
+                        <bool>false</bool>
+                    </property>
+                    <property name="geometry">
+                        <rect>
+                            <x>367</x>
+                            <y>25</y>
+                            <width>162</width>
+                            <height>335</height>
+                        </rect>
+                    </property>
+                    <property name="sizePolicy">
+                        <sizepolicy>
+                            <hsizetype>5</hsizetype>
+                            <vsizetype>3</vsizetype>
+                            <horstretch>0</horstretch>
+                            <verstretch>0</verstretch>
+                        </sizepolicy>
+                    </property>
+                    <property name="title">
+                        <string>3rd Component</string>
+                    </property>
+                    <property name="alignment">
+                        <set>AlignJustify|AlignVCenter</set>
+                    </property>
+                    <widget class="QLabel">
+                        <property name="name">
+                            <cstring>Comp3ShLabel</cstring>
+                        </property>
+                        <property name="geometry">
+                            <rect>
+                                <x>2</x>
+                                <y>30</y>
+                                <width>185</width>
+                                <height>20</height>
+                            </rect>
+                        </property>
+                        <property name="paletteBackgroundColor">
+                            <color>
+                                <red>255</red>
+                                <green>255</green>
+                                <blue>127</blue>
+                            </color>
+                        </property>
+                        <property name="text">
+                            <string>FitType3</string>
+                        </property>
+                    </widget>
+                    <widget class="QLayoutWidget">
+                        <property name="name">
+                            <cstring>layout15</cstring>
+                        </property>
+                        <property name="geometry">
+                            <rect>
+                                <x>41</x>
+                                <y>58</y>
+                                <width>81</width>
+                                <height>266</height>
+                            </rect>
+                        </property>
+                        <vbox>
+                            <property name="name">
+                                <cstring>unnamed</cstring>
+                            </property>
+                            <widget class="QCheckBox">
+                                <property name="name">
+                                    <cstring>ShParam_3_1</cstring>
+                                </property>
+                                <property name="text">
+                                    <string>Param1</string>
+                                </property>
+                            </widget>
+                            <widget class="QCheckBox">
+                                <property name="name">
+                                    <cstring>ShParam_3_2</cstring>
+                                </property>
+                                <property name="text">
+                                    <string>Param2</string>
+                                </property>
+                            </widget>
+                            <widget class="QCheckBox">
+                                <property name="name">
+                                    <cstring>ShParam_3_3</cstring>
+                                </property>
+                                <property name="text">
+                                    <string>Param3</string>
+                                </property>
+                            </widget>
+                            <widget class="QCheckBox">
+                                <property name="name">
+                                    <cstring>ShParam_3_4</cstring>
+                                </property>
+                                <property name="text">
+                                    <string>Param4</string>
+                                </property>
+                            </widget>
+                            <widget class="QCheckBox">
+                                <property name="name">
+                                    <cstring>ShParam_3_5</cstring>
+                                </property>
+                                <property name="text">
+                                    <string>Param5</string>
+                                </property>
+                            </widget>
+                            <widget class="QCheckBox">
+                                <property name="name">
+                                    <cstring>ShParam_3_6</cstring>
+                                </property>
+                                <property name="enabled">
+                                    <bool>false</bool>
+                                </property>
+                                <property name="paletteBackgroundColor">
+                                    <color>
+                                        <red>234</red>
+                                        <green>233</green>
+                                        <blue>232</blue>
+                                    </color>
+                                </property>
+                                <property name="text">
+                                    <string>Param6</string>
+                                </property>
+                                <property name="tristate">
+                                    <bool>false</bool>
+                                </property>
+                            </widget>
+                            <widget class="QCheckBox">
+                                <property name="name">
+                                    <cstring>ShParam_3_7</cstring>
+                                </property>
+                                <property name="enabled">
+                                    <bool>false</bool>
+                                </property>
+                                <property name="paletteBackgroundColor">
+                                    <color>
+                                        <red>234</red>
+                                        <green>233</green>
+                                        <blue>232</blue>
+                                    </color>
+                                </property>
+                                <property name="text">
+                                    <string>Param7</string>
+                                </property>
+                                <property name="tristate">
+                                    <bool>false</bool>
+                                </property>
+                            </widget>
+                            <widget class="QCheckBox">
+                                <property name="name">
+                                    <cstring>ShParam_3_8</cstring>
+                                </property>
+                                <property name="enabled">
+                                    <bool>false</bool>
+                                </property>
+                                <property name="paletteBackgroundColor">
+                                    <color>
+                                        <red>234</red>
+                                        <green>233</green>
+                                        <blue>232</blue>
+                                    </color>
+                                </property>
+                                <property name="text">
+                                    <string>Param8</string>
+                                </property>
+                                <property name="tristate">
+                                    <bool>false</bool>
+                                </property>
+                            </widget>
+                            <widget class="QCheckBox">
+                                <property name="name">
+                                    <cstring>ShParam_3_9</cstring>
+                                </property>
+                                <property name="enabled">
+                                    <bool>false</bool>
+                                </property>
+                                <property name="paletteBackgroundColor">
+                                    <color>
+                                        <red>234</red>
+                                        <green>233</green>
+                                        <blue>232</blue>
+                                    </color>
+                                </property>
+                                <property name="text">
+                                    <string>Param9</string>
+                                </property>
+                                <property name="tristate">
+                                    <bool>false</bool>
+                                </property>
+                            </widget>
+                        </vbox>
+                    </widget>
                 </widget>
             </widget>
         </widget>
@@ -1458,7 +1728,7 @@
         <rect>
             <x>0</x>
             <y>0</y>
-            <width>567</width>
+            <width>570</width>
             <height>27</height>
         </rect>
     </property>
@@ -1558,7 +1828,7 @@
             <string>&amp;Save MSR</string>
         </property>
         <property name="statusTip">
-            <string>&amp;Save MSRave</string>
+            <string>&amp;Save MSR</string>
         </property>
         <property name="accel">
             <string>Ctrl+S</string>
@@ -1838,10 +2108,13 @@
             <cstring>fileChangeDirAction</cstring>
         </property>
         <property name="text">
-            <string>Change dir</string>
+            <string>&amp;Change dir</string>
         </property>
         <property name="menuText">
-            <string>Change dir</string>
+            <string>&amp;Change dir</string>
+        </property>
+        <property name="accel">
+            <string>Ctrl+C</string>
         </property>
     </action>
 </actions>
@@ -1881,12 +2154,6 @@
     </image>
 </images>
 <connections>
-    <connection>
-        <sender>musrfit_tabs</sender>
-        <signal>selected(const QString&amp;)</signal>
-        <receiver>MuSRFitform</receiver>
-        <slot>TabChanged()</slot>
-    </connection>
     <connection>
         <sender>helpAboutAction</sender>
         <signal>activated()</signal>
@@ -1960,10 +2227,16 @@
         <slot>fileOpen()</slot>
     </connection>
     <connection>
-        <sender>fileNewAction</sender>
+        <sender>fileChangeDirAction</sender>
         <signal>activated()</signal>
         <receiver>MuSRFitform</receiver>
-        <slot>fileNew()</slot>
+        <slot>fileChangeDir()</slot>
+    </connection>
+    <connection>
+        <sender>musrfit_tabs</sender>
+        <signal>selected(const QString&amp;)</signal>
+        <receiver>MuSRFitform</receiver>
+        <slot>TabChanged()</slot>
     </connection>
     <connection>
         <sender>go</sender>
@@ -1977,12 +2250,6 @@
         <receiver>MuSRFitform</receiver>
         <slot>UpdeateTable()</slot>
     </connection>
-    <connection>
-        <sender>fileChangeDirAction</sender>
-        <signal>activated()</signal>
-        <receiver>MuSRFitform</receiver>
-        <slot>fileChangeDir()</slot>
-    </connection>
 </connections>
 <tabstops>
     <tabstop>musrfit_tabs</tabstop>
@@ -2021,7 +2288,6 @@
     <include location="local" impldecl="in implementation">MuSRFit.ui.h</include>
 </includes>
 <slots>
-    <slot>fileNew()</slot>
     <slot>fileOpen()</slot>
     <slot>fileSave()</slot>
     <slot>fileChangeDir()</slot>
diff --git a/src/external/MuSRFitGUI/MuSRFit.ui.h b/src/external/MuSRFitGUI/MuSRFit.ui.h
index 6a6e0ef8..d35d095e 100755
--- a/src/external/MuSRFitGUI/MuSRFit.ui.h
+++ b/src/external/MuSRFitGUI/MuSRFit.ui.h
@@ -28,10 +28,6 @@
 # Copyright 2009 by Zaher Salman and the LEM Group.
 # <zaher.salman@psi.ch>
 
-void Form1::fileNew()
-{
-}
-
 void Form1::fileOpen()
 {
     my $file=Qt::FileDialog::getOpenFileName(
@@ -177,6 +173,7 @@ void MuSRFitform::CreateAllInput()
     $All{"LRBF"} = LRBF->text;
     $All{"RunNumbers"} =~ s/[\ \.\~\/\&\*\[\;\>\<\^\$\(\)\`\|\]\'\@]/,/g;
     my @RUNS = split( /,/, $All{"RunNumbers"} );
+    my @Hists = split(/,/, $All{"LRBF"} );
     
 # Construct fittypes that can be understood by MSR.pm
     my %FTs=(0,"Exponential",
@@ -256,12 +253,17 @@ void MuSRFitform::CreateAllInput()
 # Change state/label of parameters
 	foreach my $Param (@Params) {
 	    my $Param_ORG = $Param;
+# TODO: I need to take care of single hist fits here
+	    if ( $All{"FitAsyType"} eq "SingleHist" ) {		$Param=$Param.$Hists[0];	    }
 	    if ( $#FitTypes != 0 && (   $Param ne "Alpha" && $Param ne "N0" && $Param ne "NBg" ) ){
 		$Param = join( "", $Param, "_", $Component);
 	    }
 		
 # Is there any point of sharing, multiple runs?
-	    if ( $#RUNS == 0 ) {
+	    if ( $#RUNS == 0 && $All{"FitAsyType"} eq "Asymmetry") {
+		$Shared = 1;
+	    }
+	    elsif ( $#RUNS == 0 && $#Hists == 0 &&  $All{"FitAsyType"} eq "SingleHist" )  {
 		$Shared = 1;
 	    } else {	
 # Check if shared or not, construct name of checkbox, find its handle and then 
@@ -321,7 +323,12 @@ void MuSRFitform::CallMSRCreate()
     use MSR;
     my %All=CreateAllInput();
     if ($All{"RunNumbers"} ne "") {
-	my ($Full_T_Block,$Paramcomp_ref)= MSR::CreateMSR(\%All);
+	if ( $All{"FitAsyType"} eq "Asymmetry" ) {
+	    my ($Full_T_Block,$Paramcomp_ref)= MSR::CreateMSR(\%All);
+	}
+	elsif ( $All{"FitAsyType"} eq "SingleHist" ) {
+	    my ($Full_T_Block,$Paramcomp_ref)= MSR::CreateMSRSingleHist(\%All);
+	}
 	UpdateMSRFileInitTable();
     }
 }
@@ -407,7 +414,7 @@ void MuSRFitform::ActivateShComp()
 	$CompShL->setText($All{"FitType$Component"});
 	
 # Change state/label of parameters
-	for (my $i=1; $i<=5;$i++) {		
+	for (my $i=1; $i<=9;$i++) {		
 	    my $ParamChkBx="ShParam_".$Component."_".$i;
 	    my $ChkBx = child($ParamChkBx);
 	    if ($Params[$i-1] ne "") {
@@ -587,8 +594,11 @@ void MuSRFitform::TabChanged()
     if ($All{"RunNumbers"} ne "" && $SlectedTab==4 && $FileExistCheck==1) {
 	if (-e $FILENAME) {
 # Warning: MSR file exists
-	    my $Warning = "Warning: MSR file $FILENAME Already exists!\nChange name or backup file if you do not want to loose it.";
+	    my $Warning = "Warning: MSR file $FILENAME Already exists!\nIf you continue it will overwriten.";
 	    my $WarningWindow = Qt::MessageBox::information( this, "Warning",$Warning);
+#	    my $Answer= Qt::MessageBox::warning( this, "Warning",$Warning, "&No", "&Yes", undef, 1,1);
+# $Answer =1,0 for yes and no
+#	    print "Answer=$Answer\n";
 	}
     }