diff --git a/src/external/MuSRFitGUI/musrfit.cgi b/src/external/MuSRFitGUI/musrfit.cgi
new file mode 100755
index 00000000..6014502e
--- /dev/null
+++ b/src/external/MuSRFitGUI/musrfit.cgi
@@ -0,0 +1,1282 @@
+#!/usr/bin/perl
+#
+# Copyright Zaher Salman and PSI LEM Group 2009.
+# zaher.salman@psi.ch
+
+######## Relevant subdirectories and urls ########
+# May need modification on different servers
+$WEBDIR = "/~l_salman";
+$REALDIR = "/home/l_salman/public_html";
+$BINDIR = "/usr/local/bin";
+$MAINPAGE = "/cgi-bin/musrfit.cgi";
+
+$OUTPUT = $WEBDIR . "/msrfit_out";
+$OUTPUT_REAL = $REALDIR . "/msrfit_out";
+
+$SUMM_DIR = "/mnt/data/nemu/summ";
+
+# Programs used
+if ( $TITLE eq $EMPTY || $TITLE eq "TITLE" ) {
+ $MUSRFIT = $BINDIR . "/musrfit -t";
+}
+else {
+ $MUSRFIT = $BINDIR . "/musrfit";
+}
+$MUSRVIEW = $BINDIR . "/musrview --png";
+$DUMPASCII = "$MUSRFIT --dump ascii";
+$MSR2DAT = $BINDIR . "/msr2dat";
+#######################################################################
+
+# Nothing need to be changed from here on
+$EMPTY=q{};
+$SPACE=q{ };
+$COMMA=q{,};
+
+# Additions to paremeters' names
+$erradd = "d";
+$minadd = "_min";
+$maxadd = "_max";
+
+%BeamLines = ( "LEM", "MUE4", "GPS", "PIM3", "LTF", "PIM3", "Dolly", "PIE1" , "GPD", "PIE1");
+
+# Commands used often
+$cln_out = "rm -f $OUTPUT_REAL/FILENAME*";
+$cln = "rm -f MINUIT2.* $OUTPUT_REAL/FILENAME* FILENAME.*";
+$plotonly =
+"$MUSRVIEW FILENAME.msr >> $OUTPUT_REAL/FILENAME.out; convert FILENAME\_0.png -crop 590x460+1+50 $OUTPUT_REAL/FILENAME.png; rm -f FILENAME\_0.png";
+$fitplot =
+"$MUSRFIT FILENAME.msr > $OUTPUT_REAL/FILENAME.out; $MUSRVIEW FILENAME.msr >> $OUTPUT_REAL/FILENAME.out; convert FILENAME\_0.png -crop 590x460+1+50 $OUTPUT_REAL/FILENAME.png; rm -f FILENAME\_0.png";
+$dumpascii =
+"$DUMPASCII FILENAME.msr > $OUTPUT_REAL/FILENAME_ascii.out; /bin/tar -cvzf $OUTPUT_REAL/FILENAME.tgz FILENAME*.dat >> $OUTPUT_REAL/FILENAME_ascii.out; rm -f FILENAME*.dat";
+$msr2dat = "$MSR2DAT < FILENAME.msr > $OUTPUT_REAL/FILENAME_par.dat";
+
+# "Smart" default value of the fit parameters.
+%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"
+);
+
+#######################################################################
+######## Main body of code ########
+use CGI;
+use MSR;
+
+my $in = new CGI;
+
+
+
+# See which step or command we are coming from
+# Step Value Command
+#
+# -1 CLEAR/START NEW
+# 1 Defin Shared
+# 2 Initialize parameters
+# 3 PLOT
+# 4 MIGRAD
+# 5 MINOS
+# 6 SIMPLEX
+#######################################################################
+$Step = $in->param("go");
+$FITMINTTYPE = "PLOT";
+if ( $Step eq "PLOT" ) {
+ $Step = 3;
+ $FITMINTYPE = $EMPTY;
+}
+elsif ( $Step eq "MIGRAD" ) {
+ $Step = 4;
+ $FITMINTYPE = "MINIMIZE\nMIGRAD\nHESSE";
+}
+elsif ( $Step eq "MINOS" ) {
+ $Step = 5;
+ $FITMINTYPE = "MIGRAD\nMINOS";
+}
+elsif ( $Step eq "SIMPLEX" ) {
+ $Step = 6;
+ $FITMINTYPE = "SCAN\nSIMPLEX";
+}
+elsif ( $Step eq "Go Back" ) {
+ $Step = -1;
+}
+
+#######################################################################
+# Common to all steps
+# If you are coming from a previous round pass in various parameters
+PassIn();
+
+# This is the content of the html page..
+$Content = $EMPTY;
+
+# This is just for temporary debugging html text
+$TC = $EMPTY;
+
+# Put all input values in a hash
+@All = $in->param();
+$N = $#All;
+$i = 0;
+while ( $i <= $N ) {
+ $One = $All[$i];
+ $AllParameters{ $One } = $in->param($One);
+# $TC=$TC."$One=".$AllParameters{ $One }." ";
+ ++$i;
+}
+
+#$TC=$TC."OUT: ".MSR::Test(\%AllParameters);
+#$tmp="Frq";
+#$TC=$TC."Sh_Frq= ".$AllParameters{"Sh_$tmp"}." ";
+
+# Skip the shared parameters step if you have only one
+if ( $Step == 1 && $#RUNS == 0 ) { $Step = 2; }
+
+#######################################################################
+# Choose shared parameters if you have multiple runs
+#######################################################################
+if ( $Step == 1 ) {
+
+ # First create the THEORY block to get a parameters list
+ ($Full_T_Block,$Paramcomp_ref)=MSR::CreateTheory(@FitTypes);
+ @Paramcomp = @$Paramcomp_ref;
+ StepShared();
+}
+#######################################################################
+
+#######################################################################
+# Initialize/Fix parameters values
+#######################################################################
+elsif ( $Step == 2 ) {
+ $RUN = $RUNS[0];
+ if ( $RUN < 10 ) { $RUN = "000" . $RUN; }
+ elsif ( $RUN < 100 ) { $RUN = "00" . $RUN; }
+ elsif ( $RUN < 1000 ) { $RUN = "0" . $RUN; }
+
+ # First create the THEORY block to get a parameters list
+ ($Full_T_Block,$Paramcomp_ref)=MSR::CreateTheory(@FitTypes);
+ @Paramcomp = @$Paramcomp_ref;
+ if ( $BeamLine eq "LEM" ) {
+
+ # Take the temperature from data file if you can
+ ExtractInfo( $RUN, $YEAR, "Temp" );
+ $TEMPERATURE = $RTRN_Val;
+ }
+
+ # If TITLE is empty or eq TITLE get it from the first run if you can
+ if ( $TITLE eq $EMPTY || $TITLE eq "TITLE" ) {
+
+ # This is a flag to keep setting TITLE to default
+ $T_Keep = 1;
+ }
+ else {
+ $T_Keep = 0;
+ }
+
+ # If the filename is empty or eq RUN put default
+ if ( $FILENAME eq $EMPTY || $FILENAME eq "RUN" || $FILENAME eq "0" ) {
+
+ # Flag to keep default filename
+ $FN_Keep = 1;
+ if ( $RUNS[0] ne $EMPTY ) {
+ ( $TMP1, $TMP2, $BLine ) = split( /\//, $BeamLine );
+ $FILENAME = $RUNS[0] . "_" . $BeamLine . "_" . $YEAR;
+ }
+ }
+ else {
+ $FN_Keep = 0;
+ }
+
+# If the file already exists do not continue running. The file may be
+# used by someone else.
+# TODO: Maybe create a different name and not die.
+# if (-e "$FILENAME.msr") {
+# $Content = $Content."The file name \"$FILENAME\" is being used, choose another name or delete it!";
+# &SpitHTML;
+# die;
+# }
+ InitFixStep();
+}
+#######################################################################
+
+#######################################################################
+# Create musrfit .msr file and fit/plot the result
+#######################################################################
+elsif ( $Step <= 6 && $Step >= 3 ) {
+
+ # Then create appropriate file
+ ($Full_T_Block,$Paramcomp_ref)= MSR::CreateMSR(\%AllParameters);
+ @Paramcomp = @$Paramcomp_ref;
+
+ if ( $Step == 3 ) {
+ $ops = "plot";
+ $cmd = $plotonly;
+ }
+ elsif ( $Step == 4 ) {
+ $cmd = $fitplot;
+ $ops = "migrad";
+ }
+ elsif ( $Step == 5 ) {
+ $cmd = $fitplot;
+ $ops = "minos";
+ }
+ elsif ( $Step == 6 ) {
+ $cmd = $fitplot;
+ $ops = "simplex";
+ }
+
+ # Fit and plot results
+ $cmd =~ s/FILENAME/$FILENAME/g;
+ $tmp = system("$cmd");
+
+ # Generate ascii data and fit
+ $cmd = $dumpascii;
+ $cmd =~ s/FILENAME/$FILENAME/g;
+ $tmp = system("$cmd");
+
+ # Generate parameters table
+ $cmd = $msr2dat;
+ $cmd =~ s/FILENAME/$FILENAME/g;
+ $tmp = system("$cmd");
+
+ $Spectra = ( $#RUNS + 1 ) * ( $#TiVals + 1 );
+ if ( $RRF != 0 && $Spectra == 1 ) { $Spectra = 2; }
+
+ PrintOut();
+}
+else {
+ if ( $Step == -1 ) {
+
+ # Clean up
+ $cmd = $cln;
+ $cmd =~ s/FILENAME/$FILENAME/g;
+ $tmp = system("$cmd");
+
+ # Check flag for default
+ $T_Keep = $in->param("T_Keep");
+ if ( $T_Keep == 1 ) {
+ $TITLE = "TITLE";
+ }
+
+ # Check flag for default
+ $FN_Keep = $in->param("FN_Keep");
+ if ( $FN_Keep == 1 ) { $FILENAME = "RUN"; }
+ $Step = 0;
+ $Content = $EMPTY;
+ }
+
+ # Take title, runnumber, ti, tf, bin ...
+ Step0();
+}
+
+# Insert passed on variables into the HTML code
+PassOn();
+SpitHTML();
+exit(0);
+
+######## Split functions and subroutines ########
+
+########################
+#sub SpitHTML
+#
+#This function prints the start of the feedback form web page.
+########################
+sub SpitHTML {
+ print("Content-type: text/html; charset=iso-8859-1 \n\n");
+ print(
+ "
+
+$TITLE
+
+
+
+$TC
+$Content
+
+If you have any problems please send me an email about it
+
+
+"
+ );
+ return;
+}
+########################
+
+########################
+# Step 0
+#
+# Is the begining of the fitting pocess
+# Take title and run numbers and the type of fitting function
+########################
+sub Step0 {
+
+ # Prepare body of the HTML code
+ $Content = $Content . "
+Enter the label (default is run title)
+
+
+";
+
+ # Get current year
+ ( $sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst ) =
+ localtime( time() );
+ $year = $year + 1900;
+ $Years = $EMPTY;
+
+ # Creat a drop down menu for years from 1994 until current
+ for ( $i = $year ; $i >= 1994 ; $i-- ) {
+# for ($i=1994..$year) {
+ $Years =
+ $Years . " ";
+ }
+
+ for my $BeamLine ( keys %BeamLines ) {
+ $BeamLineDDM = $BeamLineDDM
+ . "\n";
+ }
+
+ # Insert the years into the HTML code
+ $Content =~ s/INSERT_YEARS_HERE/$Years/g;
+
+ # Insert the beamlines into the HTML code
+ $Content =~ s/INSERT_BEAMLINES_HERE/$BeamLineDDM/g;
+ return;
+}
+########################
+
+########################
+# StepShared
+#
+# Choose shared parameters if applicable
+#
+########################
+sub StepShared {
+
+ # Here we need first a list of parameters which depends
+ # on the functions chosen and number of components
+
+ $Content = $Content . "
+Choose the shared parameters
+
+";
+
+ # Prepare table of parameters
+ $component = 0;
+ $Param_Table = $EMPTY;
+ foreach my $FitType (@FitTypes) {
+ ++$component;
+ $Parameters = $Paramcomp[ $component - 1 ];
+ $Param_Table = $Param_Table . "
+Component $component: $FitType
+