diff --git a/Code/Mantid/Build/CMake/CommonSetup.cmake b/Code/Mantid/Build/CMake/CommonSetup.cmake
index 7238d80002059f20920cc4fdfb1d04224a883990..1693e45d196646d76c1554c573e4c5d69f668808 100644
--- a/Code/Mantid/Build/CMake/CommonSetup.cmake
+++ b/Code/Mantid/Build/CMake/CommonSetup.cmake
@@ -242,6 +242,11 @@ endif ()
 ###########################################################################
 include ( CppCheckSetup )
 
+###########################################################################
+# Setup pylint
+###########################################################################
+include ( PylintSetup )
+
 ###########################################################################
 # Set up the unit tests target
 ###########################################################################
diff --git a/Code/Mantid/Build/CMake/FindPylint.cmake b/Code/Mantid/Build/CMake/FindPylint.cmake
new file mode 100644
index 0000000000000000000000000000000000000000..666800d2da40dafac850a6ec17f232c00a937c19
--- /dev/null
+++ b/Code/Mantid/Build/CMake/FindPylint.cmake
@@ -0,0 +1,40 @@
+# - Find Pylint
+# Find the Pylint executable and extract the version number
+#
+# OUTPUT Variables
+#
+#   PYLINT_FOUND
+#       True if the pylint package was found
+#   PYLINT_EXECUTABLE
+#       The pylint executable location
+#   PYLINT_VERSION
+#       A string denoting the version of pylint that has been found
+#   PYLINT_RUNNER_SCRIPT
+#       Location of python script that will actually run pylint
+#   PYLINT_CFG_FILE
+#       Location of configuration file
+#
+
+#=============================================================
+# main()
+#=============================================================
+
+find_program ( PYLINT_EXECUTABLE pylint PATHS /usr/bin )
+
+if ( PYLINT_EXECUTABLE )
+  execute_process ( COMMAND ${PYLINT_EXECUTABLE} --version OUTPUT_VARIABLE PYLINT_VERSION_RAW ERROR_QUIET )
+  if (PYLINT_VERSION_RAW)
+    string ( REGEX REPLACE "^pylint ([0-9]+.[0-9]+.[0-9]+),.*" "\\1" PYLINT_VERSION ${PYLINT_VERSION_RAW})
+  else ()
+    set ( PYLINT_VERSION "unknown" )
+  endif()
+  # Script to find all .py files and execute pylint
+  set ( PYLINT_RUNNER_SCRIPT ${CMAKE_SOURCE_DIR}/../Tools/Pylint/run_pylint.py )
+  # Configuration file
+  set ( PYLINT_CFG_FILE ${CMAKE_SOURCE_DIR}/../Tools/Pylint/pylint.cfg )
+endif ()
+
+include(FindPackageHandleStandardArgs)
+FIND_PACKAGE_HANDLE_STANDARD_ARGS ( Pylint DEFAULT_MSG PYLINT_EXECUTABLE )
+
+mark_as_advanced ( PYLINT_EXECUTABLE PYLINT_VERSION )
diff --git a/Code/Mantid/Build/CMake/PylintSetup.cmake b/Code/Mantid/Build/CMake/PylintSetup.cmake
new file mode 100644
index 0000000000000000000000000000000000000000..3de3811641d5794de4c8fd467a4813aaa83e0ac9
--- /dev/null
+++ b/Code/Mantid/Build/CMake/PylintSetup.cmake
@@ -0,0 +1,50 @@
+########################################################
+# Setup target to run pylint checking if it is available
+########################################################
+find_package ( Pylint )
+
+if ( PYLINT_FOUND AND PYLINT_VERSION VERSION_LESS "1.0.0" )
+  message ( STATUS "pylint found but version is < 1.0.0 (${PYLINT_VERSION}): no target generated." )
+  set ( PYLINT_FOUND FALSE )
+endif()
+
+if ( PYLINT_FOUND )
+  message ( STATUS "pylint version: ${PYLINT_VERSION}" )
+
+  # Output format options
+  if ( NOT  PYLINT_OUTPUT_FORMAT )
+    # Use msvs for MSVC generator, colorized for everything else. The buildservers can
+    # set it to parseable for Jenkins
+    if ( MSVC )
+      set ( DEFAULT_FORMAT "msvs" )
+    else ()
+      set ( DEFAULT_FORMAT "colorized" )
+    endif ()
+    set ( PYLINT_OUTPUT_FORMAT ${DEFAULT_FORMAT} CACHE STRING "Desired pylint output format" )
+
+    # There are a limited set of allowed options
+    set_property( CACHE PYLINT_OUTPUT_FORMAT PROPERTY STRINGS "text" "html" "msvs" "parseable" "colorized" )
+  endif()
+
+  # add a pylint-check target to run pylint on the required files and directories
+  # relative to the root source directory
+  set ( BASE_DIR ${CMAKE_SOURCE_DIR} )
+  set ( PYLINT_INCLUDES
+        Framework/PythonInterface/plugins
+        scripts
+  )
+  set ( PYLINT_EXCLUDES
+        scripts/lib1to2
+        scripts/test
+  )
+  add_custom_target ( pylintcheck
+                      COMMAND ${PYTHON_EXECUTABLE} ${PYLINT_RUNNER_SCRIPT} --format=${PYLINT_OUTPUT_FORMAT}
+                              --rcfile=${PYLINT_CFG_FILE}
+                              --mantidpath=${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${CMAKE_CFG_INTDIR}
+                              --basedir=${BASE_DIR} --nofail
+                              --exclude="${PYLINT_EXCLUDES}"
+                              ${PYLINT_INCLUDES}
+                      COMMENT "Running pylint on selected python files"
+                    )
+  set_target_properties ( pylintcheck PROPERTIES EXCLUDE_FROM_ALL TRUE )
+endif ()
diff --git a/Code/Mantid/Build/Jenkins/buildscript b/Code/Mantid/Build/Jenkins/buildscript
index 088dce7f0317cbfade0e23ae8780bd4e17711e3c..57312f0339b05bf199e8c77b6082b56b90d0b78a 100755
--- a/Code/Mantid/Build/Jenkins/buildscript
+++ b/Code/Mantid/Build/Jenkins/buildscript
@@ -45,7 +45,7 @@ if [[ ${JOB_NAME} == *clean* ]]; then
     elif [[ ${JOB_NAME} == *develop* ]]; then
       PACKAGINGVARS="-DENVVARS_ON_INSTALL=False -DCMAKE_INSTALL_PREFIX=/opt/mantidunstable -DCPACK_PACKAGE_SUFFIX=unstable -DCPACK_SET_DESTDIR=OFF -DPACKAGE_DOCS=ON"
     elif [[ ${JOB_NAME} == *release* ]]; then
-      PACKAGINGVARS="-DCPACK_SET_DESTDIR=ON -DPACKAGE_DOCS=ON"
+      PACKAGINGVARS="-DENVVARS_ON_INSTALL=True -DCPACK_SET_DESTDIR=ON -DPACKAGE_DOCS=ON"
     fi
   else
     # Mac packaging
@@ -69,10 +69,21 @@ fi
 [ -d $WORKSPACE/build ] || mkdir $WORKSPACE/build
 cd $WORKSPACE/build
 
+###############################################################################
+## Check the required build configuration
+###############################################################################
+if [[ ${JOB_NAME} == *debug* ]]; then
+  BUILD_CONFIG="Debug"
+elif [[ ${JOB_NAME} == *relwithdbg* ]]; then
+  BUILD_CONFIG="RelWithDbg"
+else
+  BUILD_CONFIG="Release"
+fi
+
 ###############################################################################
 # CMake configuration
 ###############################################################################
-$SCL_ON_RHEL6 "cmake -DCMAKE_BUILD_TYPE=Release -DENABLE_CPACK=ON -DMAKE_VATES=ON -DParaView_DIR=${PARAVIEW_DIR} -DDOCS_HTML=ON ${PACKAGINGVARS} ../Code/Mantid"
+$SCL_ON_RHEL6 "cmake -DCMAKE_BUILD_TYPE=${BUILD_CONFIG} -DENABLE_CPACK=ON -DMAKE_VATES=ON -DParaView_DIR=${PARAVIEW_DIR} -DDOCS_HTML=ON ${PACKAGINGVARS} ../Code/Mantid"
 
 ###############################################################################
 # Build step
diff --git a/Code/Mantid/Build/Jenkins/buildscript.bat b/Code/Mantid/Build/Jenkins/buildscript.bat
index 974828f3a5707664015c44a4f7a2f984e2aa78f8..e63a5a20289f2e6249c9b64a3630c814a9227d1a 100755
--- a/Code/Mantid/Build/Jenkins/buildscript.bat
+++ b/Code/Mantid/Build/Jenkins/buildscript.bat
@@ -9,6 +9,19 @@
 
 "C:\Program Files (x86)\CMake 2.8\bin\cmake.exe" --version 
 
+:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
+:: Check the required build configuration
+:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
+set BUILD_CONFIG=
+if not "%JOB_NAME%"=="%JOB_NAME:debug=%" (
+    set BUILD_CONFIG=Debug
+) else (
+if not "%JOB_NAME%"=="%JOB_NAME:relwithdbg=%" (
+    set BUILD_CONFIG=RelWithDbg
+) else (
+    set BUILD_CONFIG=Release
+    ))
+
 :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
 :: Get or update the third party dependencies
 :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
@@ -16,7 +29,7 @@ cd %WORKSPACE%\Code
 call fetch_Third_Party win64
 cd %WORKSPACE%
 
-set PATH=%WORKSPACE%\Code\Third_Party\lib\win64;%WORKSPACE%\Code\Third_Party\lib\win64\Python27;%PARAVIEW_DIR%\bin\Release;%PATH%
+set PATH=%WORKSPACE%\Code\Third_Party\lib\win64;%WORKSPACE%\Code\Third_Party\lib\win64\Python27;%PARAVIEW_DIR%\bin\%BUILD_CONFIG%;%PATH%
 
 :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
 :: Check whether this is a clean build (must have 'clean' in the job name)
@@ -45,16 +58,17 @@ if ERRORLEVEL 1 exit /B %ERRORLEVEL%
 :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
 :: Build step
 :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
-msbuild /nologo /m:%BUILD_THREADS% /nr:false /p:Configuration=Release Mantid.sln
+
+msbuild /nologo /m:%BUILD_THREADS% /nr:false /p:Configuration=%BUILD_CONFIG% Mantid.sln
 if ERRORLEVEL 1 exit /B %ERRORLEVEL%
 
 :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
 :: Run the tests
 :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
-"C:\Program Files (x86)\CMake 2.8\bin\ctest.exe" -C Release -j%BUILD_THREADS% --schedule-random --output-on-failure -E MantidPlot
+"C:\Program Files (x86)\CMake 2.8\bin\ctest.exe" -C %BUILD_CONFIG% -j%BUILD_THREADS% --schedule-random --output-on-failure -E MantidPlot
 if ERRORLEVEL 1 exit /B %ERRORLEVEL%
 :: Run GUI tests serially
-ctest -C Release --output-on-failure -R MantidPlot
+ctest -C %BUILD_CONFIG% --output-on-failure -R MantidPlot
 if ERRORLEVEL 1 exit /B %ERRORLEVEL%
 
 :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
@@ -62,9 +76,9 @@ if ERRORLEVEL 1 exit /B %ERRORLEVEL%
 :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
 if "%CLEANBUILD%" EQU "yes" (
     :: Build offline documentation
-    msbuild /nologo /nr:false /p:Configuration=Release docs/docs-qthelp.vcxproj
+    msbuild /nologo /nr:false /p:Configuration=%BUILD_CONFIG% docs/docs-qthelp.vcxproj
 
     :: ignore errors as the exit code of the build isn't correct
     ::if ERRORLEVEL 1 exit /B %ERRORLEVEL%
-    cpack -C Release --config CPackConfig.cmake
+    cpack -C %BUILD_CONFIG% --config CPackConfig.cmake
 )
diff --git a/Code/Mantid/Framework/API/CMakeLists.txt b/Code/Mantid/Framework/API/CMakeLists.txt
index 837224c908a70230871c8c41052aa2dfd96498f3..ae0dfd6951d527c813eed3cca0a74918de30fe9d 100644
--- a/Code/Mantid/Framework/API/CMakeLists.txt
+++ b/Code/Mantid/Framework/API/CMakeLists.txt
@@ -362,7 +362,8 @@ set ( TEST_FILES
 	VectorParameterTest.h
 	WorkspaceFactoryTest.h
 	WorkspaceGroupTest.h
-	WorkspaceHistoryTest.h
+  WorkspaceHistoryTest.h
+	WorkspaceHistoryIOTest.h
 	WorkspaceOpOverloadsTest.h
 	WorkspacePropertyTest.h
 )
diff --git a/Code/Mantid/Framework/API/inc/MantidAPI/FrameworkManager.h b/Code/Mantid/Framework/API/inc/MantidAPI/FrameworkManager.h
index 7fa8996f8e11709571e395d370913df830b8ad7f..70310150409926cf311fee4f0ac47413ac8a7a6f 100644
--- a/Code/Mantid/Framework/API/inc/MantidAPI/FrameworkManager.h
+++ b/Code/Mantid/Framework/API/inc/MantidAPI/FrameworkManager.h
@@ -54,6 +54,9 @@ namespace Mantid
     class MANTID_API_DLL FrameworkManagerImpl
     {
     public:
+      /// Load a set of plugins using a key from the ConfigService
+      void loadPluginsUsingKey(const std::string & key);
+
       /// Set the number of OpenMP threads to use based on the config value
       void setNumOMPThreadsToConfigValue();
       /// Set the number of OpenMP threads to the given value
@@ -108,10 +111,6 @@ namespace Mantid
       
       /// Set up the global locale
       void setGlobalLocaleToAscii();
-      /// Load the plugins
-      void loadAllPlugins();
-      /// Load a set of plugins
-      void loadPluginsUsingKey(const std::string & key);
       /// Silence NeXus output
       void disableNexusOutput();
 
diff --git a/Code/Mantid/Framework/API/inc/MantidAPI/IFuncMinimizer.h b/Code/Mantid/Framework/API/inc/MantidAPI/IFuncMinimizer.h
index bb93e1dc19d41ed42fc0568239a39071d72883a3..d2c05bb1b268ea9830c4b3b2c7083aee25475987 100644
--- a/Code/Mantid/Framework/API/inc/MantidAPI/IFuncMinimizer.h
+++ b/Code/Mantid/Framework/API/inc/MantidAPI/IFuncMinimizer.h
@@ -46,17 +46,21 @@ public:
   /// Virtual destructor
   virtual ~IFuncMinimizer() {}
 
-  /// Initialize minimizer, i.e. pass costFunction
-  virtual void initialize(API::ICostFunction_sptr function) = 0;
+  /// Initialize minimizer.
+  /// @param function :: Function to minimize
+  /// @param maxIterations :: Maximum number of iterations.
+  virtual void initialize(API::ICostFunction_sptr function, size_t maxIterations = 1000) = 0;
 
   /// Get name of minimizer
   virtual std::string name() const = 0;
 
   /// Do one iteration
+  /// @param iteration :: Current iteration number. 0 <= iteration < maxIterations
   /// @return :: true if iterations should be continued or false to stop
-  virtual bool iterate() = 0;
+  virtual bool iterate(size_t iteration) = 0;
 
   /// Perform iteration with minimizer and return true if successful.
+  /// @param maxIterations :: Maximum number of iterations.
   virtual bool minimize(size_t maxIterations = 1000);
 
   /// Get the error string
diff --git a/Code/Mantid/Framework/API/inc/MantidAPI/MultipleFileProperty.h b/Code/Mantid/Framework/API/inc/MantidAPI/MultipleFileProperty.h
index f34f61754b5dc76e7fdb5b683d6350393e2dc757..2735f4cc62a74e0954a1e845f8067c2491ce9772 100644
--- a/Code/Mantid/Framework/API/inc/MantidAPI/MultipleFileProperty.h
+++ b/Code/Mantid/Framework/API/inc/MantidAPI/MultipleFileProperty.h
@@ -112,8 +112,7 @@ namespace API
     virtual std::string getDefault() const;
 
     /// @return the vector of suggested extensions. For use in GUIs showing files.
-    std::set<std::string> getExts() const
-    { return std::set<std::string>(m_exts.begin(), m_exts.end()); }
+    std::vector<std::string> getExts() const { return m_exts; }
     
     /// Returns the main file extension that's used 
     std::string getDefaultExt() const {return m_defaultExt;}
diff --git a/Code/Mantid/Framework/API/inc/MantidAPI/ScriptBuilder.h b/Code/Mantid/Framework/API/inc/MantidAPI/ScriptBuilder.h
index 9c647e1b0461b620f31767c22ed01f4a7d7322ed..b9303bcc1991516c98e00c3e637194c032476b4d 100644
--- a/Code/Mantid/Framework/API/inc/MantidAPI/ScriptBuilder.h
+++ b/Code/Mantid/Framework/API/inc/MantidAPI/ScriptBuilder.h
@@ -49,7 +49,7 @@ namespace API
 class MANTID_API_DLL ScriptBuilder
 {
 public:
-  ScriptBuilder(boost::shared_ptr<HistoryView> view);
+  ScriptBuilder(boost::shared_ptr<HistoryView> view, std::string versionSpecificity = "old");
   virtual ~ScriptBuilder() {};
 
   /// build a python script from the history view
@@ -63,6 +63,7 @@ private:
 
   const std::vector<HistoryItem> m_historyItems;
   std::string m_output;
+  std::string m_versionSpecificity;
 };
 
 } // namespace API
diff --git a/Code/Mantid/Framework/API/inc/MantidAPI/WorkspaceProperty.h b/Code/Mantid/Framework/API/inc/MantidAPI/WorkspaceProperty.h
index c4e56872e2d6e7704d6ec743510982f878b82d41..496a71cc0efe7b87b2fa10c56d4e3c8283a480f3 100644
--- a/Code/Mantid/Framework/API/inc/MantidAPI/WorkspaceProperty.h
+++ b/Code/Mantid/Framework/API/inc/MantidAPI/WorkspaceProperty.h
@@ -309,7 +309,7 @@ namespace Mantid
        *  For output workspaces, an empty set is returned
        *  @return set of objects in AnalysisDataService
        */
-      virtual std::set<std::string> allowedValues() const
+      virtual std::vector<std::string> allowedValues() const
       {
         if ( this->direction() == Kernel::Direction::Input || this->direction() == Kernel::Direction::InOut )
         {
@@ -331,12 +331,12 @@ namespace Mantid
             }
             else ++it;
           }
-          return vals;
+          return std::vector<std::string>(vals.begin(), vals.end());
         }
         else
         {
           // For output workspaces, just return an empty set
-          return std::set<std::string>();
+          return std::vector<std::string>();
         }
       }
 
diff --git a/Code/Mantid/Framework/API/src/Algorithm.cpp b/Code/Mantid/Framework/API/src/Algorithm.cpp
index 7b01faddd820443e3d86eaf0a8626a32ac7cb6ec..195941bfa7c771b6021eb148607ebe5289781662 100644
--- a/Code/Mantid/Framework/API/src/Algorithm.cpp
+++ b/Code/Mantid/Framework/API/src/Algorithm.cpp
@@ -899,7 +899,18 @@ namespace Mantid
         if( i < numProps - 1 ) stream << ",";
       }
       stream << ")";
-      return Algorithm::fromString(stream.str());
+      IAlgorithm_sptr alg;
+      
+      try
+      {
+        alg = Algorithm::fromString(stream.str());
+      }
+      catch(std::invalid_argument&)
+      {
+        throw std::runtime_error("Could not create algorithm from history. "
+                                 "Is this a child algorithm whose workspaces are not in the ADS?");
+      }
+      return alg;
     }
 
 
diff --git a/Code/Mantid/Framework/API/src/AlgorithmFactory.cpp b/Code/Mantid/Framework/API/src/AlgorithmFactory.cpp
index 79b39269797f1e9143f974e115d1245056a9ee18..2fcb3c6b7c41766ac63293c0331e25e806400758 100644
--- a/Code/Mantid/Framework/API/src/AlgorithmFactory.cpp
+++ b/Code/Mantid/Framework/API/src/AlgorithmFactory.cpp
@@ -354,18 +354,42 @@ namespace Mantid
       }
       else
         continue;
+
       boost::shared_ptr<IAlgorithm> alg = create(desc.name,desc.version);
       std::vector<std::string> categories = alg->categories();
-      //for each category
-      std::vector<std::string>::const_iterator itCategoriesEnd = categories.end();
-      for(std::vector<std::string>::const_iterator itCategories = categories.begin(); itCategories!=itCategoriesEnd; ++itCategories)
+
+      //For each category
+      auto itCategoriesEnd = categories.end();
+      for(auto itCategories = categories.begin(); itCategories != itCategoriesEnd; ++itCategories)
       {
         desc.category = *itCategories;
-        //if the entry is not in the set of hidden categories
-        if (hiddenCategories.find(desc.category) == hiddenCategories.end())
+
+        //Let's check if this category or any of its parents are hidden.
+        bool categoryIsHidden = false;
+
+        //Split the category into its components.
+        std::vector<std::string> categoryLayers;
+        boost::split(categoryLayers, desc.category, boost::is_any_of("\\"));
+
+        //Traverse each parent category, working our way from the top down.
+        std::string currentLayer = "";
+        for(auto layerIt = categoryLayers.begin(); layerIt != categoryLayers.end(); ++layerIt)
         {
-          res.push_back(desc);
+          currentLayer.append(*layerIt);
+
+          if(hiddenCategories.find(currentLayer) != hiddenCategories.end())
+          {
+            //Category is hidden, no need to check any others.
+            categoryIsHidden = true;
+            break;
+          }
+
+          //Add a separator in case we're going down another layer.
+          currentLayer.append("\\");
         }
+
+        if(!categoryIsHidden)
+          res.push_back(desc);
       }
     }
     return res;
diff --git a/Code/Mantid/Framework/API/src/FileProperty.cpp b/Code/Mantid/Framework/API/src/FileProperty.cpp
index 8a76e4065d4dd18c74adc78357a366e4a77c1a7b..dfa8da1a787d889d6b895a0834c1a8be21a09bea 100644
--- a/Code/Mantid/Framework/API/src/FileProperty.cpp
+++ b/Code/Mantid/Framework/API/src/FileProperty.cpp
@@ -224,10 +224,10 @@ bool FileProperty::extsMatchRunFiles()
   const std::vector<std::string>  facilityExts = facilityInfo.extensions();
   std::vector<std::string>::const_iterator facilityExtsBegin = facilityExts.begin();
   std::vector<std::string>::const_iterator facilityExtsEnd = facilityExts.end();
-  const std::set<std::string> allowedExts = this->allowedValues();
+  const std::vector<std::string> allowedExts = this->allowedValues();
 
   bool match(false);
-  for( std::set<std::string>::const_iterator it = allowedExts.begin(); it != allowedExts.end(); ++it )
+  for( auto it = allowedExts.begin(); it != allowedExts.end(); ++it )
   {
     if( std::find(facilityExtsBegin, facilityExtsEnd, *it) != facilityExtsEnd )
     {
@@ -271,7 +271,7 @@ std::string FileProperty::setLoadProperty(const std::string & propValue)
   {
     if( m_runFileProp ) // runfiles go through FileFinder::findRun
     {
-      std::set<std::string> allowedExts(allowedValues());
+      std::vector<std::string> allowedExts(allowedValues());
       std::vector<std::string> exts;
       if (!m_defaultExt.empty())
       {
@@ -285,7 +285,7 @@ std::string FileProperty::setLoadProperty(const std::string & propValue)
         std::transform(m_defaultExt.begin(), m_defaultExt.end(), upper.begin(), toupper);
         addExtension(upper, exts);
       }
-      for(std::set<std::string>::iterator it = allowedExts.begin();it!=allowedExts.end();++it)
+      for(auto it = allowedExts.begin();it!=allowedExts.end();++it)
       {
         std::string lower(*it);
         std::string upper(*it);
diff --git a/Code/Mantid/Framework/API/src/FrameworkManager.cpp b/Code/Mantid/Framework/API/src/FrameworkManager.cpp
index 90acdd0d7538c59ac4f2fe14e734e56d3807a6b0..f1c21e59405ab9a62ef568f60183fff7917aa52a 100644
--- a/Code/Mantid/Framework/API/src/FrameworkManager.cpp
+++ b/Code/Mantid/Framework/API/src/FrameworkManager.cpp
@@ -31,6 +31,8 @@ namespace API
   {
     /// static logger
     Kernel::Logger g_log("FrameworkManager");
+    /// Key that that defines the location of the framework plugins
+    const char * PLUGINS_DIR_KEY = "plugins.directory";
   }
 
   /** This is a function called every time NeXuS raises an error.
@@ -69,7 +71,7 @@ FrameworkManagerImpl::FrameworkManagerImpl()
 #endif
 
   g_log.notice() << Mantid::welcomeMessage() << std::endl;
-  loadAllPlugins();
+  loadPluginsUsingKey(PLUGINS_DIR_KEY);
   disableNexusOutput();
   setNumOMPThreadsToConfigValue();
 
@@ -85,39 +87,6 @@ FrameworkManagerImpl::~FrameworkManagerImpl()
 {
 }
 
-
-/**
- * Set the global locale for all C++ stream operations to use simple ASCII characters.
- * If the system supports it UTF-8 encoding will be used, otherwise the 
- * classic C locale is used
- */
-void FrameworkManagerImpl::setGlobalLocaleToAscii()
-{
-  // This ensures that all subsequent stream operations interpret everything as simple
-  // ASCII. On systems in the UK and US having this as the system default is not an issue.
-  // However, systems that have their encoding set differently can see unexpected behavour when
-  // translating from string->numeral values. One example is floating-point interpretation in 
-  // German where a comma is used instead of a period.
-  std::locale::global(std::locale::classic());
-}
-
-/**
- * Attempts to load the dynamic library plugins
- */
-void FrameworkManagerImpl::loadAllPlugins()
-{
-  loadPluginsUsingKey("plugins.directory");
-  // Load Paraview plugin libraries if possible
-  if(Kernel::ConfigService::Instance().quickParaViewCheck())
-  {
-    loadPluginsUsingKey("pvplugins.directory");
-  }
-  else
-  {
-    g_log.debug("Cannot load ParaView libraries");
-  }
-}
-
 /**
  * Load a set of plugins from the path pointed to by the given config key
  * @param key :: A string containing a key to lookup in the ConfigService
@@ -137,6 +106,21 @@ void FrameworkManagerImpl::loadPluginsUsingKey(const std::string & key)
   }
 }
 
+/**
+ * Set the global locale for all C++ stream operations to use simple ASCII characters.
+ * If the system supports it UTF-8 encoding will be used, otherwise the 
+ * classic C locale is used
+ */
+void FrameworkManagerImpl::setGlobalLocaleToAscii()
+{
+  // This ensures that all subsequent stream operations interpret everything as simple
+  // ASCII. On systems in the UK and US having this as the system default is not an issue.
+  // However, systems that have their encoding set differently can see unexpected behavour when
+  // translating from string->numeral values. One example is floating-point interpretation in 
+  // German where a comma is used instead of a period.
+  std::locale::global(std::locale::classic());
+}
+
 /// Silence NeXus output
 void FrameworkManagerImpl::disableNexusOutput()
 {
diff --git a/Code/Mantid/Framework/API/src/IFuncMinimizer.cpp b/Code/Mantid/Framework/API/src/IFuncMinimizer.cpp
index 8790275cb07c354c2c8a1b607783089257aacc31..a808d413e3e30c892c067a519370ae92aae0109d 100644
--- a/Code/Mantid/Framework/API/src/IFuncMinimizer.cpp
+++ b/Code/Mantid/Framework/API/src/IFuncMinimizer.cpp
@@ -22,13 +22,13 @@ bool IFuncMinimizer::minimize(size_t maxIterations)
   bool success = false;
   do
   {
-    iter++;
-    if ( !iterate() )
+    if ( !iterate(iter) )
     {
       success = m_errorString.empty() || m_errorString == "success";
       m_errorString = "success";
       break;
     }
+    iter++;
   }
   while (iter < maxIterations);
 
diff --git a/Code/Mantid/Framework/API/src/IFunction.cpp b/Code/Mantid/Framework/API/src/IFunction.cpp
index b2c8d73c58d4556a199a304fb4bd326865adbe12..353d9648855ef4a5f31573f0df376c9b19620261 100644
--- a/Code/Mantid/Framework/API/src/IFunction.cpp
+++ b/Code/Mantid/Framework/API/src/IFunction.cpp
@@ -53,6 +53,7 @@ namespace API
     if (m_handler)
     {
       delete m_handler;
+      m_handler=NULL;
     }
   }
 
diff --git a/Code/Mantid/Framework/API/src/Sample.cpp b/Code/Mantid/Framework/API/src/Sample.cpp
index 36bce6d0ff0461111730302cc4f8b2c04c5244b2..bfa6c6028ebf95c9342373b1bdcd36ca49fb43f3 100644
--- a/Code/Mantid/Framework/API/src/Sample.cpp
+++ b/Code/Mantid/Framework/API/src/Sample.cpp
@@ -71,7 +71,8 @@ namespace Mantid
       m_thick = rhs.m_thick;
       m_height = rhs.m_height;
       m_width = rhs.m_width;
-      if (rhs.m_lattice)
+      if (m_lattice!=NULL) delete m_lattice;
+      if (rhs.m_lattice)       
         m_lattice = new OrientedLattice(rhs.getOrientedLattice());
       else
         m_lattice = NULL;
@@ -198,7 +199,14 @@ namespace Mantid
      */
     void Sample::setOrientedLattice(OrientedLattice * latt)
     {
-      m_lattice = latt;
+      if (m_lattice!=NULL)
+      {
+          delete m_lattice;
+      }
+      if (latt!=NULL)
+        m_lattice = new OrientedLattice(*latt);
+      else
+        m_lattice=NULL;
     }
 
     /** @return true if the sample has an OrientedLattice  */
diff --git a/Code/Mantid/Framework/API/src/ScriptBuilder.cpp b/Code/Mantid/Framework/API/src/ScriptBuilder.cpp
index f21dc4a6733b0e66b85e7f57d198858b23e07f8b..5bcad6e097a924ba17053f5bd4c97564da547f0f 100644
--- a/Code/Mantid/Framework/API/src/ScriptBuilder.cpp
+++ b/Code/Mantid/Framework/API/src/ScriptBuilder.cpp
@@ -1,6 +1,7 @@
 //----------------------------------------------------------------------
 // Includes
 //----------------------------------------------------------------------
+#include "MantidAPI/AlgorithmFactory.h"
 #include "MantidAPI/HistoryItem.h"
 #include "MantidAPI/ScriptBuilder.h"
 
@@ -14,8 +15,8 @@ namespace API
 using Mantid::Kernel::PropertyHistory_sptr;
 using Mantid::Kernel::PropertyHistory_const_sptr;
 
-ScriptBuilder::ScriptBuilder(boost::shared_ptr<HistoryView> view)
-  : m_historyItems(view->getAlgorithmsList()), m_output()
+ScriptBuilder::ScriptBuilder(boost::shared_ptr<HistoryView> view, std::string versionSpecificity)
+  : m_historyItems(view->getAlgorithmsList()), m_output(), m_versionSpecificity(versionSpecificity)
 {
 }
 
@@ -116,6 +117,35 @@ const std::string ScriptBuilder::buildAlgorithmString(AlgorithmHistory_const_spt
     }
   }
 
+  //Three cases, we can either specify the version of every algorithm...
+  if(m_versionSpecificity == "all")
+  {
+    properties << "Version=" << algHistory->version() << ", ";
+  }
+  else if(m_versionSpecificity == "old")
+  {
+    //...or only specify algorithm versions when they're not the newest version
+    bool oldVersion = false;
+
+    std::vector<Algorithm_descriptor> descriptors = AlgorithmFactory::Instance().getDescriptors();
+    for(auto dit = descriptors.begin(); dit != descriptors.end(); ++dit)
+    {
+      //If a newer version of this algorithm exists, then this must be an old version.
+      if((*dit).name == algHistory->name() && (*dit).version > algHistory->version())
+      {
+        oldVersion = true;
+        break;
+      }
+    }
+
+    if(oldVersion)
+    {
+      properties << "Version=" << algHistory->version() << ", ";
+    }
+  }
+  //Third case is we never specify the version, so do nothing.
+
+
   std::string propStr = properties.str();
   if (propStr.length() > 0)
   {  
diff --git a/Code/Mantid/Framework/API/src/WorkspaceGroup.cpp b/Code/Mantid/Framework/API/src/WorkspaceGroup.cpp
index 7993cae37d78c7349ccc517aa0e2a64b41c88812..233b3ce2ad41d52fc90c0638ca75f04240fb974b 100644
--- a/Code/Mantid/Framework/API/src/WorkspaceGroup.cpp
+++ b/Code/Mantid/Framework/API/src/WorkspaceGroup.cpp
@@ -268,7 +268,7 @@ void WorkspaceGroup::removeItem(const size_t index)
 void WorkspaceGroup::workspaceDeleteHandle(Mantid::API::WorkspacePostDeleteNotification_ptr notice)
 {
   Poco::Mutex::ScopedLock _lock(m_mutex);
-  const std::string deletedName = notice->object_name();
+  const std::string deletedName = notice->objectName();
   if( !this->contains(deletedName)) return;
 
   if( deletedName != this->getName() )
@@ -292,12 +292,12 @@ void WorkspaceGroup::workspaceReplaceHandle(Mantid::API::WorkspaceBeforeReplaceN
 {
   Poco::Mutex::ScopedLock _lock(m_mutex);
 
-  const std::string replacedName = notice->object_name();
+  const std::string replacedName = notice->objectName();
   for(auto citr=m_workspaces.begin(); citr!=m_workspaces.end(); ++citr)
   {
     if ( (**citr).name() == replacedName )
     {
-      *citr = notice->new_object();
+      *citr = notice->newObject();
       break;
     }
   }
diff --git a/Code/Mantid/Framework/API/test/ExperimentInfoTest.h b/Code/Mantid/Framework/API/test/ExperimentInfoTest.h
index 61ba1e7b687d92fd28d6307cd377cb312fb953f6..80592866959a9ed7142e8d5f8469e93453cbae2d 100644
--- a/Code/Mantid/Framework/API/test/ExperimentInfoTest.h
+++ b/Code/Mantid/Framework/API/test/ExperimentInfoTest.h
@@ -289,7 +289,8 @@ public:
     ExperimentInfo ws;
     ws.mutableRun().setProtonCharge(1.234);
     ws.mutableSample().setName("test");
-    ws.mutableSample().setOrientedLattice( new OrientedLattice(1,2,3,90,90,90) );
+    OrientedLattice latt(1,2,3,90,90,90);
+    ws.mutableSample().setOrientedLattice( &latt  );
     boost::shared_ptr<Instrument> inst1(new Instrument());
     inst1->setName("MyTestInst");
     ws.setInstrument(inst1);
@@ -306,7 +307,8 @@ public:
     ExperimentInfo ws;
     ws.mutableRun().setProtonCharge(1.234);
     ws.mutableSample().setName("test");
-    ws.mutableSample().setOrientedLattice( new OrientedLattice(1,2,3,90,90,90) );
+    OrientedLattice latt(1,2,3,90,90,90);
+    ws.mutableSample().setOrientedLattice( &latt  );
     boost::shared_ptr<Instrument> inst1(new Instrument());
     inst1->setName("MyTestInst");
     ws.setInstrument(inst1);
@@ -323,7 +325,8 @@ public:
     ExperimentInfo ws;
     ws.mutableRun().setProtonCharge(1.234);
     ws.mutableSample().setName("test");
-    ws.mutableSample().setOrientedLattice( new OrientedLattice(1,2,3,90,90,90) );
+    OrientedLattice latt(1,2,3,90,90,90);
+    ws.mutableSample().setOrientedLattice( &latt  );
     boost::shared_ptr<Instrument> inst1(new Instrument());
     inst1->setName("MyTestInst");
     ws.setInstrument(inst1);
diff --git a/Code/Mantid/Framework/API/test/FuncMinimizerFactoryTest.h b/Code/Mantid/Framework/API/test/FuncMinimizerFactoryTest.h
index 35b286c84f817d1b54d42517e3fe838f64dc2661..014d4609906263f4bac153bd574b0ee84b02e60e 100644
--- a/Code/Mantid/Framework/API/test/FuncMinimizerFactoryTest.h
+++ b/Code/Mantid/Framework/API/test/FuncMinimizerFactoryTest.h
@@ -26,10 +26,10 @@ public:
 
   /// Overloading base class methods
   std::string name()const {return "Boevs";}
-  bool iterate() {return true;}
+  bool iterate(size_t) {return true;}
   int hasConverged() {return 101;}
   double costFunctionVal() {return 5.0;}
-  void initialize(API::ICostFunction_sptr)
+  void initialize(API::ICostFunction_sptr,size_t)
   {
   }
 };
diff --git a/Code/Mantid/Framework/API/test/SampleTest.h b/Code/Mantid/Framework/API/test/SampleTest.h
index c9a0b886b706ed8e2e34e2385532cc6dd7e4246e..ea38133089d0e578c48f0c54957a9b342c480df4 100644
--- a/Code/Mantid/Framework/API/test/SampleTest.h
+++ b/Code/Mantid/Framework/API/test/SampleTest.h
@@ -89,24 +89,24 @@ public:
   void test_OrientedLattice()
   {
     Sample sample;
-    const std::string envName("TestKit");
     OrientedLattice *latt = new OrientedLattice(1.0,2.0,3.0, 90, 90, 90);
 
     TS_ASSERT_THROWS_NOTHING(sample.setOrientedLattice(latt));
 
     const OrientedLattice & retLatt = sample.getOrientedLattice();
     // Test that this references the correct object
-    TS_ASSERT_EQUALS(&retLatt, latt);
+    //TS_ASSERT_EQUALS(&retLatt, latt);//This is no longer correct. setOrientedLattice makes a copy of the OrientedLattice object
     TS_ASSERT_EQUALS(retLatt.a(), 1.0);
     TS_ASSERT_EQUALS(retLatt.b(), 2.0);
     TS_ASSERT_EQUALS(retLatt.c(), 3.0);
+    delete latt;
   }
 
 
   void test_OrientedLattice_and_theCopyconstructor()
   {
     Sample sample;
-    const std::string envName("TestKit");
+    //const std::string envName("TestKit");
     OrientedLattice *latt = new OrientedLattice(1.0,2.0,3.0, 90, 90, 90);
 
     TS_ASSERT_THROWS_NOTHING(sample.setOrientedLattice(latt));
@@ -129,7 +129,7 @@ public:
     TS_ASSERT_EQUALS(retLatt.a(), 1.0);
     TS_ASSERT_EQUALS(retLatt.b(), 2.0);
     TS_ASSERT_EQUALS(retLatt.c(), 3.0);
-
+    delete latt;
   }
 
   void test_clearOrientedLattice()
@@ -146,6 +146,7 @@ public:
 
     TS_ASSERT(!sample.hasOrientedLattice())
     TS_ASSERT_THROWS(sample.getOrientedLattice(), std::runtime_error&)
+    delete latt;
   }
 
   void test_clearOrientedLattice_and_the_copy_constructor()
@@ -182,7 +183,7 @@ public:
     TS_ASSERT_THROWS(sampleA.getOrientedLattice(), std::runtime_error&)
     TS_ASSERT(!sampleB.hasOrientedLattice())
     TS_ASSERT_THROWS(sampleB.getOrientedLattice(), std::runtime_error&)
-
+    delete latticeA;
   }
 
   void test_clearOrientedLattice_and_assignment()
@@ -220,7 +221,7 @@ public:
     TS_ASSERT_THROWS(sampleA.getOrientedLattice(), std::runtime_error&)
     TS_ASSERT(!sampleB.hasOrientedLattice())
     TS_ASSERT_THROWS(sampleB.getOrientedLattice(), std::runtime_error&)
-
+    delete latticeA;
   }
 
 
@@ -287,7 +288,8 @@ public:
     sample.setShape(*shape_sptr);
     sample.setName("NameOfASample");
     sample.setWidth(1.234);
-    sample.setOrientedLattice( new OrientedLattice(4,5,6,90,91,92) );
+    OrientedLattice latt(4,5,6,90,91,92);
+    sample.setOrientedLattice( &latt );
     boost::shared_ptr<Sample> sample2 = boost::shared_ptr<Sample>(new Sample());
     sample2->setName("test name for test_Multiple_Sample - 2");
     sample.addSample(sample2);
diff --git a/Code/Mantid/Framework/API/test/WorkspaceHistoryIOTest.h b/Code/Mantid/Framework/API/test/WorkspaceHistoryIOTest.h
new file mode 100644
index 0000000000000000000000000000000000000000..e62fa4a2278c526bf5a37de602627c2fd88f52d5
--- /dev/null
+++ b/Code/Mantid/Framework/API/test/WorkspaceHistoryIOTest.h
@@ -0,0 +1,371 @@
+#ifndef WORKSPACEHISTORYIOTEST_H_
+#define WORKSPACEHISTORYIOTEST_H_
+
+#include <cxxtest/TestSuite.h>
+#include "MantidAPI/WorkspaceHistory.h"
+#include "MantidAPI/AlgorithmHistory.h"
+#include "MantidAPI/Algorithm.h"
+#include "MantidAPI/AlgorithmFactory.h"
+#include "MantidAPI/FileFinder.h"
+#include "MantidKernel/Property.h"
+#include "MantidTestHelpers/NexusTestHelper.h"
+#include "Poco/File.h"
+
+using namespace Mantid::API;
+using namespace Mantid::Kernel;
+
+class WorkspaceHistoryIOTest : public CxxTest::TestSuite
+{
+private:
+
+ void failiure_testfile_setup(int testno, NexusTestHelper &testfile)
+  {
+    //dummy file info
+    std::stringstream output;
+
+    // Environment history
+    EnvironmentHistory envHist;
+    output << envHist;
+    char buffer [25];
+    time_t now;
+    time(&now);
+    strftime (buffer,25,"%Y-%b-%d %H:%M:%S",localtime(&now));
+
+    //common start
+    testfile.createFile("LoadNexusTest.nxs");
+
+    testfile.file->makeGroup("process", "NXprocess", true);
+
+      testfile.file->makeGroup("MantidEnvironment", "NXnote", true);
+        testfile.file->writeData("author", "mantid");
+        testfile.file->openData("author");
+          testfile.file->putAttr("date", std::string(buffer));
+        testfile.file->closeData();
+        testfile.file->writeData("description", "Mantid Environment data");
+        testfile.file->writeData("data", output.str());
+      testfile.file->closeGroup();
+      //commonend
+
+      if (testno != 6)
+      {
+        //first algorithm
+        testfile.file->makeGroup("MantidAlgorithm_0", "NXnote", true);
+          testfile.file->writeData("author", std::string("mantid"));
+          testfile.file->writeData("description", std::string("Mantid Algorithm data"));
+          testfile.file->writeData("data", "Algorithm: LoadRaw v1\nExecution Date: 2009-Oct-09 16:56:54\nExecution Duration: 2.3 seconds\nParameters:\n  Name: Filename, Value: /home/dmn58364/Mantid/trunk/Test/Data/GEM38370.raw, Default?: No, Direction: Input\n  Name: OutputWorkspace, Value: GEM38370, Default?: No, Direction: Output\n  Name: SpectrumMin, Value: 1, Default?: Yes, Direction: Input\n  Name: SpectrumMax, Value: 2147483632, Default?: Yes, Direction: Input\n  Name: SpectrumList, Value: , Default?: Yes, Direction: Input\n  Name: Cache, Value: If Slow, Default?: Yes, Direction: Input\n  Name: LoadLogFiles, Value: 1, Default?: Yes, Direction: Input");
+        testfile.file->closeGroup();
+        //second algorithm is different each test
+        switch(testno)
+        {
+        case 2:
+          {
+            testfile.file->makeGroup("MantidAlgorithm_1", "NXnote", true);
+              //missing author
+              testfile.file->writeData("description", std::string("Mantid Algorithm data"));
+              testfile.file->writeData("data", "Algorithm: LoadRaw v2\nExecution Date: 2009-Oct-09 16:56:54\nExecution Duration: 2.3 seconds\nParameters:\n  Name: Filename, Value: /home/dmn58364/Mantid/trunk/Test/Data/GEM38370.raw, Default?: No, Direction: Input\n  Name: OutputWorkspace, Value: GEM38370, Default?: No, Direction: Output\n  Name: SpectrumMin, Value: 1, Default?: Yes, Direction: Input\n  Name: SpectrumMax, Value: 2147483632, Default?: Yes, Direction: Input\n  Name: SpectrumList, Value: , Default?: Yes, Direction: Input\n  Name: Cache, Value: If Slow, Default?: Yes, Direction: Input\n  Name: LoadLogFiles, Value: 1, Default?: Yes, Direction: Input");
+            testfile.file->closeGroup();
+            break;
+          }
+        case 3:
+          {
+            testfile.file->makeGroup("MantidAlgorithm_1", "NXnote", true);
+              testfile.file->writeData("author", std::string("mantid"));
+              //missing description
+              testfile.file->writeData("data", "Algorithm: LoadRaw v2\nExecution Date: 2009-Oct-09 16:56:54\nExecution Duration: 2.3 seconds\nParameters:\n  Name: Filename, Value: /home/dmn58364/Mantid/trunk/Test/Data/GEM38370.raw, Default?: No, Direction: Input\n  Name: OutputWorkspace, Value: GEM38370, Default?: No, Direction: Output\n  Name: SpectrumMin, Value: 1, Default?: Yes, Direction: Input\n  Name: SpectrumMax, Value: 2147483632, Default?: Yes, Direction: Input\n  Name: SpectrumList, Value: , Default?: Yes, Direction: Input\n  Name: Cache, Value: If Slow, Default?: Yes, Direction: Input\n  Name: LoadLogFiles, Value: 1, Default?: Yes, Direction: Input");
+            testfile.file->closeGroup();
+            break;
+          }
+        case 4:
+          {
+            testfile.file->makeGroup("MantidAlgorithm_1", "NXnote", true);
+              testfile.file->writeData("author", std::string("mantid"));
+              testfile.file->writeData("description", std::string("Mantid Algorithm data"));
+              //missing data
+            testfile.file->closeGroup();
+            break;
+          }
+        case 5:
+          {
+            testfile.file->makeGroup("MantidAlgorithm_1", "NXnote", true);
+              testfile.file->writeData("author", std::string("mantid"));
+              testfile.file->writeData("description", std::string("Mantid Algorithm data"));
+              testfile.file->writeData("data", "some data");
+            testfile.file->closeGroup();
+            break;
+          }
+        case 7:
+          {
+            testfile.file->makeGroup("MantidAlgorithm_1", "NXnote", true);
+              testfile.file->writeData("author", std::string("mantid"));
+              testfile.file->writeData("description", std::string("Mantid Algorithm data"));
+              testfile.file->writeData("data", "some data\nsome data\nsome data\nsome data\nsome data");
+            testfile.file->closeGroup();
+            break;
+          }
+        default:
+          {
+            testfile.file->makeGroup("MantidAlgorithm_1", "NXnote", true);
+              testfile.file->writeData("author", std::string("mantid"));
+              testfile.file->writeData("description", std::string("Mantid Algorithm data"));
+              testfile.file->writeData("data", "Algorithm: LoadRaw v2\nExecution Date: 2009-Oct-09 16:56:54\nExecution Duration: 2.3 seconds\nParameters:\n  Name: Filename, Value: /home/dmn58364/Mantid/trunk/Test/Data/GEM38370.raw, Default?: No, Direction: Input\n  Name: OutputWorkspace, Value: GEM38370, Default?: No, Direction: Output\n  Name: SpectrumMin, Value: 1, Default?: Yes, Direction: Input\n  Name: SpectrumMax, Value: 2147483632, Default?: Yes, Direction: Input\n  Name: SpectrumList, Value: , Default?: Yes, Direction: Input\n  Name: Cache, Value: If Slow, Default?: Yes, Direction: Input\n  Name: LoadLogFiles, Value: 1, Default?: Yes, Direction: Input");
+            testfile.file->closeGroup();
+            break;
+          }
+        }
+        testfile.file->makeGroup("MantidAlgorithm_2", "NXnote", true);
+          testfile.file->writeData("author", std::string("mantid"));
+          testfile.file->writeData("description", std::string("Mantid Algorithm data"));
+          testfile.file->writeData("data", "Algorithm: LoadRaw v3\nExecution Date: 2009-Oct-09 16:56:54\nExecution Duration: 2.3 seconds\nParameters:\n  Name: Filename, Value: /home/dmn58364/Mantid/trunk/Test/Data/GEM38370.raw, Default?: No, Direction: Input\n  Name: OutputWorkspace, Value: GEM38370, Default?: No, Direction: Output\n  Name: SpectrumMin, Value: 1, Default?: Yes, Direction: Input\n  Name: SpectrumMax, Value: 2147483632, Default?: Yes, Direction: Input\n  Name: SpectrumList, Value: , Default?: Yes, Direction: Input\n  Name: Cache, Value: If Slow, Default?: Yes, Direction: Input\n  Name: LoadLogFiles, Value: 1, Default?: Yes, Direction: Input");
+        testfile.file->closeGroup();
+      }
+      else
+      {
+        testfile.file->makeGroup("MantidAlgorithm_0", "NXnote", true);
+          testfile.file->writeData("author", std::string("mantid"));
+          testfile.file->writeData("description", std::string("Mantid Algorithm data"));
+          testfile.file->writeData("data", "some data");
+        testfile.file->closeGroup();
+
+        testfile.file->makeGroup("MantidAlgorithm_1", "NXnote", true);
+          testfile.file->writeData("author", std::string("mantid"));
+          testfile.file->writeData("description", std::string("Mantid Algorithm data"));
+          testfile.file->writeData("data", "some data");
+        testfile.file->closeGroup();
+
+        testfile.file->makeGroup("MantidAlgorithm_2", "NXnote", true);
+          testfile.file->writeData("author", std::string("mantid"));
+          testfile.file->writeData("description", std::string("Mantid Algorithm data"));
+          testfile.file->writeData("data", "some data");
+        testfile.file->closeGroup();
+      }
+    //common end
+    testfile.file->closeGroup();
+  }
+
+public:
+  void test_SaveNexus()
+  {
+    WorkspaceHistory testHistory;
+    for (int i = 1; i < 5; i++)
+    {
+      AlgorithmHistory algHist("History" + boost::lexical_cast<std::string>(i), 1,DateAndTime::defaultTime(),-1.0,i);
+      testHistory.addHistory(boost::make_shared<AlgorithmHistory>(algHist));
+    }
+
+    auto savehandle = boost::make_shared< ::NeXus::File >("WorkspaceHistoryTest_test_SaveNexus.nxs",NXACC_CREATE5);
+    TS_ASSERT_THROWS_NOTHING(testHistory.saveNexus(savehandle.get()));
+    savehandle->close();
+
+    auto loadhandle = boost::make_shared< ::NeXus::File >("WorkspaceHistoryTest_test_SaveNexus.nxs");
+    std::string rootstring = "/process/";
+    for (int i = 1; i < 5; i++)
+    {
+      TS_ASSERT_THROWS_NOTHING(loadhandle->openPath(rootstring + "MantidAlgorithm_" + boost::lexical_cast<std::string>(i)));
+    }
+    TS_ASSERT_THROWS_NOTHING(loadhandle->openPath(rootstring + "MantidEnvironment"));
+    TS_ASSERT_THROWS_NOTHING(loadhandle->openPath(rootstring + "MantidAlgorithm_4/author"));
+    TS_ASSERT_THROWS_NOTHING(loadhandle->openPath(rootstring + "MantidAlgorithm_4/data"));
+    TS_ASSERT_THROWS_NOTHING(loadhandle->openPath(rootstring + "MantidAlgorithm_4/description"));
+    TS_ASSERT_THROWS_ANYTHING(loadhandle->openPath(rootstring + "MantidAlgorithm_5"));
+
+    loadhandle->close();
+    Poco::File("WorkspaceHistoryTest_test_SaveNexus.nxs").remove();
+  }
+
+  void test_SaveNexus_NestedHistory()
+  {
+    WorkspaceHistory testHistory;
+    AlgorithmHistory algHist("ParentHistory", 1,DateAndTime::defaultTime(),-1.0, 0);
+    AlgorithmHistory childHist("ChildHistory", 1,DateAndTime::defaultTime(),-1.0, 1);
+
+    algHist.addChildHistory(boost::make_shared<AlgorithmHistory>(childHist));
+    testHistory.addHistory(boost::make_shared<AlgorithmHistory>(algHist));
+
+    auto savehandle = boost::make_shared< ::NeXus::File >("WorkspaceHistoryTest_test_SaveNexus.nxs",NXACC_CREATE5);
+    TS_ASSERT_THROWS_NOTHING(testHistory.saveNexus(savehandle.get()));
+    savehandle->close();
+
+    auto loadhandle = boost::make_shared< ::NeXus::File >("WorkspaceHistoryTest_test_SaveNexus.nxs");
+    std::string rootstring = "/process/";
+    TS_ASSERT_THROWS_NOTHING(loadhandle->openPath(rootstring + "MantidAlgorithm_1/"));
+    TS_ASSERT_THROWS_NOTHING(loadhandle->openPath(rootstring + "MantidAlgorithm_1/author"));
+    TS_ASSERT_THROWS_NOTHING(loadhandle->openPath(rootstring + "MantidAlgorithm_1/data"));
+    TS_ASSERT_THROWS_NOTHING(loadhandle->openPath(rootstring + "MantidAlgorithm_1/description"));
+
+    TS_ASSERT_THROWS_NOTHING(loadhandle->openPath(rootstring + "MantidAlgorithm_1/MantidAlgorithm_2"));
+    TS_ASSERT_THROWS_NOTHING(loadhandle->openPath(rootstring + "MantidAlgorithm_1/MantidAlgorithm_2/author"));
+    TS_ASSERT_THROWS_NOTHING(loadhandle->openPath(rootstring + "MantidAlgorithm_1/MantidAlgorithm_2/data"));
+    TS_ASSERT_THROWS_NOTHING(loadhandle->openPath(rootstring + "MantidAlgorithm_1/MantidAlgorithm_2/description"));
+
+    loadhandle->close();
+    Poco::File("WorkspaceHistoryTest_test_SaveNexus.nxs").remove();
+  }
+
+  void test_SaveNexus_Empty()
+  {
+    WorkspaceHistory testHistory;
+
+    auto savehandle = boost::make_shared< ::NeXus::File >("WorkspaceHistoryTest_test_SaveNexus.nxs",NXACC_CREATE5);
+    TS_ASSERT_THROWS_NOTHING(testHistory.saveNexus(savehandle.get()));
+    savehandle->close();
+
+    auto loadhandle = boost::make_shared< ::NeXus::File >("WorkspaceHistoryTest_test_SaveNexus.nxs");
+    std::string rootstring = "/process/";
+    TS_ASSERT_THROWS_NOTHING(loadhandle->openPath(rootstring));
+    TS_ASSERT_THROWS_NOTHING(loadhandle->openPath(rootstring + "MantidEnvironment"));
+    TS_ASSERT_THROWS_ANYTHING(loadhandle->openPath(rootstring + "MantidAlgorithm_1"));
+    
+    loadhandle->close();
+    Poco::File("WorkspaceHistoryTest_test_SaveNexus.nxs").remove();
+  }
+
+  void test_LoadNexus()
+  {
+    std::string filename = FileFinder::Instance().getFullPath("GEM38370_Focussed_Legacy.nxs");
+    auto loadhandle = boost::make_shared< ::NeXus::File >(filename);
+    loadhandle->openPath("/mantid_workspace_1");
+
+    WorkspaceHistory emptyHistory;
+    TS_ASSERT_THROWS_NOTHING(emptyHistory.loadNexus(loadhandle.get()));
+
+    const auto & histories = emptyHistory.getAlgorithmHistories();
+    TS_ASSERT_EQUALS(3,histories.size());
+    
+    const auto history = emptyHistory.getAlgorithmHistory(0);
+
+    TS_ASSERT_EQUALS("LoadRaw", history->name());
+    TS_ASSERT_EQUALS(3, history->version());
+    TS_ASSERT_EQUALS(DateAndTime("2009-10-09T16:56:54"), history->executionDate());
+    TS_ASSERT_EQUALS(2.3, history->executionDuration());
+    loadhandle->close();
+  }
+
+  void test_LoadNexus_NestedHistory()
+  {
+    std::string filename = FileFinder::Instance().getFullPath("HistoryTest_CreateTransmissionAuto.nxs");
+    auto loadhandle = boost::make_shared< ::NeXus::File >(filename);
+    loadhandle->openPath("/mantid_workspace_1");
+
+    WorkspaceHistory wsHistory;
+    TS_ASSERT_THROWS_NOTHING(wsHistory.loadNexus(loadhandle.get()));
+
+    const auto & histories = wsHistory.getAlgorithmHistories();
+    TS_ASSERT_EQUALS(3,histories.size());
+
+    auto history = wsHistory.getAlgorithmHistory(1);
+
+    TS_ASSERT_EQUALS("CreateTransmissionWorkspaceAuto", history->name());
+    TS_ASSERT_EQUALS(1, history->version());
+
+    const auto childHistory = history->getChildAlgorithmHistory(0);
+
+    TS_ASSERT_EQUALS("CreateTransmissionWorkspace", childHistory->name());
+    TS_ASSERT_EQUALS(1, childHistory->version());
+
+    history = wsHistory.getAlgorithmHistory(2);
+
+    TS_ASSERT_EQUALS("SaveNexusProcessed", history->name());
+    TS_ASSERT_EQUALS(1, history->version());
+    
+    loadhandle->close();
+  }
+
+  void test_LoadNexus_Blank_File()
+  {
+    std::string rootstring = "/process/";
+    //first file - clean - contains nothing
+    NexusTestHelper testfile(true);
+    testfile.createFile("LoadNexusTest.nxs");
+
+    WorkspaceHistory history;
+    //will throw nothing as it will return with only a warning, no exception
+    TS_ASSERT_THROWS_NOTHING(history.loadNexus(testfile.file));
+    const auto & histories = history.getAlgorithmHistories();
+    
+    TS_ASSERT_EQUALS(0,histories.size());
+    TS_ASSERT_THROWS_ANYTHING(testfile.file->openPath(rootstring));
+    TS_ASSERT_THROWS_ANYTHING(testfile.file->openPath(rootstring + "MantidEnvironment"));
+    TS_ASSERT_THROWS_ANYTHING(testfile.file->openPath(rootstring + "MantidAlgorithm_1"));
+
+  }
+
+  void test_LoadNexus_Missing_Author()
+  {
+    //second file - 3 algorithms one missing an author
+    NexusTestHelper testfile(true);
+    failiure_testfile_setup(2, testfile);
+    WorkspaceHistory history;
+    TS_ASSERT_THROWS_NOTHING(history.loadNexus(testfile.file));
+    const auto & histories = history.getAlgorithmHistories();
+    //three will still exist as it doesn't really care about the author
+    TS_ASSERT_EQUALS(3,histories.size());
+  }
+
+  void test_LoadNexus_Missing_Description()
+  {
+    //third file - 3 algorithms one missing a description
+    NexusTestHelper testfile(true);
+    failiure_testfile_setup(3, testfile);
+    WorkspaceHistory history;
+    TS_ASSERT_THROWS_NOTHING(history.loadNexus(testfile.file));
+    const auto & histories = history.getAlgorithmHistories();
+    
+    //three will still exist as it doesn't really care about the author
+    TS_ASSERT_EQUALS(3,histories.size());
+  }
+
+  void test_LoadNexus_Missing_Data()
+  {
+    //fourth file - 3 algorithms one missing data
+    NexusTestHelper testfile(true);
+    failiure_testfile_setup(4, testfile);
+    WorkspaceHistory history;
+    //this WILL throw as it looks for a data field using ::NeXus::File::readData() and it won't be found
+    TS_ASSERT_THROWS_ANYTHING(history.loadNexus(testfile.file));
+    const auto & histories = history.getAlgorithmHistories();
+    //only one will exist as it will throw on the second (wihtout the data) and skip the rest
+    TS_ASSERT_EQUALS(1,histories.size());
+  }
+
+  void test_LoadNexus_Short_Data()
+  {
+    //fifth file - 3 algorithms one wiht only one line of data
+    NexusTestHelper testfile(true);
+    failiure_testfile_setup(5, testfile);
+    WorkspaceHistory history;
+    //won't throw as it'll simply ignore the bad data
+    TS_ASSERT_THROWS_NOTHING(history.loadNexus(testfile.file));
+    const auto & histories = history.getAlgorithmHistories();
+    
+    //only two will exist as it will ignore the second (with only the single line) and continue as normal
+    TS_ASSERT_EQUALS(2,histories.size());
+  }
+
+  void test_LoadNexus_All_Short_Data()
+  {
+    //sixth file - 3 algorithms all with only one line of data
+    NexusTestHelper testfile(true);
+    failiure_testfile_setup(6, testfile);
+    WorkspaceHistory history;
+    //nothign will throw but nothing will be loaded either as the data is invalid
+    TS_ASSERT_THROWS_NOTHING(history.loadNexus(testfile.file));
+    const auto & histories = history.getAlgorithmHistories();
+    //size should be zero as nothing went in the file
+    TS_ASSERT_EQUALS(0,histories.size());
+  }
+
+  void test_LoadNexus_Bad_Formatting()
+  {
+    //seventh file - 3 algorithms, one with bad formatting
+    NexusTestHelper testfile(true);
+    failiure_testfile_setup(7, testfile);
+    WorkspaceHistory history;
+    //this will throw on the second due to the unformatted data - the function expects well formatted data
+    TS_ASSERT_THROWS_ANYTHING(history.loadNexus(testfile.file));
+    const auto & histories = history.getAlgorithmHistories();
+    //only one will exist as it will throw on the second (with the bad data) and skip the rest
+    TS_ASSERT_EQUALS(1,histories.size());
+  }
+};
+
+#endif
\ No newline at end of file
diff --git a/Code/Mantid/Framework/API/test/WorkspaceHistoryTest.h b/Code/Mantid/Framework/API/test/WorkspaceHistoryTest.h
index 14b5d5a5380609aa678462498e432d11990676c9..1886d59e934507271152fde1fcdbb1db02c90868 100644
--- a/Code/Mantid/Framework/API/test/WorkspaceHistoryTest.h
+++ b/Code/Mantid/Framework/API/test/WorkspaceHistoryTest.h
@@ -66,130 +66,7 @@ private:
     }
   };
 
-  void failiure_testfile_setup(int testno, NexusTestHelper &testfile)
-  {
-    //dummy file info
-    std::stringstream output;
-
-    // Environment history
-    EnvironmentHistory envHist;
-    output << envHist;
-    char buffer [25];
-    time_t now;
-    time(&now);
-    strftime (buffer,25,"%Y-%b-%d %H:%M:%S",localtime(&now));
-
-    //common start
-    testfile.createFile("LoadNexusTest.nxs");
-
-    testfile.file->makeGroup("process", "NXprocess", true);
-
-      testfile.file->makeGroup("MantidEnvironment", "NXnote", true);
-        testfile.file->writeData("author", "mantid");
-        testfile.file->openData("author");
-          testfile.file->putAttr("date", std::string(buffer));
-        testfile.file->closeData();
-        testfile.file->writeData("description", "Mantid Environment data");
-        testfile.file->writeData("data", output.str());
-      testfile.file->closeGroup();
-      //commonend
-
-      if (testno != 6)
-      {
-        //first algorithm
-        testfile.file->makeGroup("MantidAlgorithm_0", "NXnote", true);
-          testfile.file->writeData("author", std::string("mantid"));
-          testfile.file->writeData("description", std::string("Mantid Algorithm data"));
-          testfile.file->writeData("data", "Algorithm: LoadRaw v1\nExecution Date: 2009-Oct-09 16:56:54\nExecution Duration: 2.3 seconds\nParameters:\n  Name: Filename, Value: /home/dmn58364/Mantid/trunk/Test/Data/GEM38370.raw, Default?: No, Direction: Input\n  Name: OutputWorkspace, Value: GEM38370, Default?: No, Direction: Output\n  Name: SpectrumMin, Value: 1, Default?: Yes, Direction: Input\n  Name: SpectrumMax, Value: 2147483632, Default?: Yes, Direction: Input\n  Name: SpectrumList, Value: , Default?: Yes, Direction: Input\n  Name: Cache, Value: If Slow, Default?: Yes, Direction: Input\n  Name: LoadLogFiles, Value: 1, Default?: Yes, Direction: Input");
-        testfile.file->closeGroup();
-        //second algorithm is different each test
-        switch(testno)
-        {
-        case 2:
-          {
-            testfile.file->makeGroup("MantidAlgorithm_1", "NXnote", true);
-              //missing author
-              testfile.file->writeData("description", std::string("Mantid Algorithm data"));
-              testfile.file->writeData("data", "Algorithm: LoadRaw v2\nExecution Date: 2009-Oct-09 16:56:54\nExecution Duration: 2.3 seconds\nParameters:\n  Name: Filename, Value: /home/dmn58364/Mantid/trunk/Test/Data/GEM38370.raw, Default?: No, Direction: Input\n  Name: OutputWorkspace, Value: GEM38370, Default?: No, Direction: Output\n  Name: SpectrumMin, Value: 1, Default?: Yes, Direction: Input\n  Name: SpectrumMax, Value: 2147483632, Default?: Yes, Direction: Input\n  Name: SpectrumList, Value: , Default?: Yes, Direction: Input\n  Name: Cache, Value: If Slow, Default?: Yes, Direction: Input\n  Name: LoadLogFiles, Value: 1, Default?: Yes, Direction: Input");
-            testfile.file->closeGroup();
-            break;
-          }
-        case 3:
-          {
-            testfile.file->makeGroup("MantidAlgorithm_1", "NXnote", true);
-              testfile.file->writeData("author", std::string("mantid"));
-              //missing description
-              testfile.file->writeData("data", "Algorithm: LoadRaw v2\nExecution Date: 2009-Oct-09 16:56:54\nExecution Duration: 2.3 seconds\nParameters:\n  Name: Filename, Value: /home/dmn58364/Mantid/trunk/Test/Data/GEM38370.raw, Default?: No, Direction: Input\n  Name: OutputWorkspace, Value: GEM38370, Default?: No, Direction: Output\n  Name: SpectrumMin, Value: 1, Default?: Yes, Direction: Input\n  Name: SpectrumMax, Value: 2147483632, Default?: Yes, Direction: Input\n  Name: SpectrumList, Value: , Default?: Yes, Direction: Input\n  Name: Cache, Value: If Slow, Default?: Yes, Direction: Input\n  Name: LoadLogFiles, Value: 1, Default?: Yes, Direction: Input");
-            testfile.file->closeGroup();
-            break;
-          }
-        case 4:
-          {
-            testfile.file->makeGroup("MantidAlgorithm_1", "NXnote", true);
-              testfile.file->writeData("author", std::string("mantid"));
-              testfile.file->writeData("description", std::string("Mantid Algorithm data"));
-              //missing data
-            testfile.file->closeGroup();
-            break;
-          }
-        case 5:
-          {
-            testfile.file->makeGroup("MantidAlgorithm_1", "NXnote", true);
-              testfile.file->writeData("author", std::string("mantid"));
-              testfile.file->writeData("description", std::string("Mantid Algorithm data"));
-              testfile.file->writeData("data", "some data");
-            testfile.file->closeGroup();
-            break;
-          }
-        case 7:
-          {
-            testfile.file->makeGroup("MantidAlgorithm_1", "NXnote", true);
-              testfile.file->writeData("author", std::string("mantid"));
-              testfile.file->writeData("description", std::string("Mantid Algorithm data"));
-              testfile.file->writeData("data", "some data\nsome data\nsome data\nsome data\nsome data");
-            testfile.file->closeGroup();
-            break;
-          }
-        default:
-          {
-            testfile.file->makeGroup("MantidAlgorithm_1", "NXnote", true);
-              testfile.file->writeData("author", std::string("mantid"));
-              testfile.file->writeData("description", std::string("Mantid Algorithm data"));
-              testfile.file->writeData("data", "Algorithm: LoadRaw v2\nExecution Date: 2009-Oct-09 16:56:54\nExecution Duration: 2.3 seconds\nParameters:\n  Name: Filename, Value: /home/dmn58364/Mantid/trunk/Test/Data/GEM38370.raw, Default?: No, Direction: Input\n  Name: OutputWorkspace, Value: GEM38370, Default?: No, Direction: Output\n  Name: SpectrumMin, Value: 1, Default?: Yes, Direction: Input\n  Name: SpectrumMax, Value: 2147483632, Default?: Yes, Direction: Input\n  Name: SpectrumList, Value: , Default?: Yes, Direction: Input\n  Name: Cache, Value: If Slow, Default?: Yes, Direction: Input\n  Name: LoadLogFiles, Value: 1, Default?: Yes, Direction: Input");
-            testfile.file->closeGroup();
-            break;
-          }
-        }
-        testfile.file->makeGroup("MantidAlgorithm_2", "NXnote", true);
-          testfile.file->writeData("author", std::string("mantid"));
-          testfile.file->writeData("description", std::string("Mantid Algorithm data"));
-          testfile.file->writeData("data", "Algorithm: LoadRaw v3\nExecution Date: 2009-Oct-09 16:56:54\nExecution Duration: 2.3 seconds\nParameters:\n  Name: Filename, Value: /home/dmn58364/Mantid/trunk/Test/Data/GEM38370.raw, Default?: No, Direction: Input\n  Name: OutputWorkspace, Value: GEM38370, Default?: No, Direction: Output\n  Name: SpectrumMin, Value: 1, Default?: Yes, Direction: Input\n  Name: SpectrumMax, Value: 2147483632, Default?: Yes, Direction: Input\n  Name: SpectrumList, Value: , Default?: Yes, Direction: Input\n  Name: Cache, Value: If Slow, Default?: Yes, Direction: Input\n  Name: LoadLogFiles, Value: 1, Default?: Yes, Direction: Input");
-        testfile.file->closeGroup();
-      }
-      else
-      {
-        testfile.file->makeGroup("MantidAlgorithm_0", "NXnote", true);
-          testfile.file->writeData("author", std::string("mantid"));
-          testfile.file->writeData("description", std::string("Mantid Algorithm data"));
-          testfile.file->writeData("data", "some data");
-        testfile.file->closeGroup();
-
-        testfile.file->makeGroup("MantidAlgorithm_1", "NXnote", true);
-          testfile.file->writeData("author", std::string("mantid"));
-          testfile.file->writeData("description", std::string("Mantid Algorithm data"));
-          testfile.file->writeData("data", "some data");
-        testfile.file->closeGroup();
-
-        testfile.file->makeGroup("MantidAlgorithm_2", "NXnote", true);
-          testfile.file->writeData("author", std::string("mantid"));
-          testfile.file->writeData("description", std::string("Mantid Algorithm data"));
-          testfile.file->writeData("data", "some data");
-        testfile.file->closeGroup();
-      }
-    //common end
-    testfile.file->closeGroup();
-  }
-
+ 
 public:
 
   void test_New_History_Is_Empty()
@@ -263,230 +140,6 @@ public:
     TS_ASSERT_THROWS(emptyHistory.lastAlgorithm(), std::out_of_range);
     TS_ASSERT_THROWS(emptyHistory.getAlgorithm(1), std::out_of_range);
   }
-
-  void test_SaveNexus()
-  {
-    WorkspaceHistory testHistory;
-    for (int i = 1; i < 5; i++)
-    {
-      AlgorithmHistory algHist("History" + boost::lexical_cast<std::string>(i), 1,DateAndTime::defaultTime(),-1.0,i);
-      testHistory.addHistory(boost::make_shared<AlgorithmHistory>(algHist));
-    }
-
-    auto savehandle = boost::make_shared< ::NeXus::File >("WorkspaceHistoryTest_test_SaveNexus.nxs",NXACC_CREATE5);
-    TS_ASSERT_THROWS_NOTHING(testHistory.saveNexus(savehandle.get()));
-    savehandle->close();
-
-    auto loadhandle = boost::make_shared< ::NeXus::File >("WorkspaceHistoryTest_test_SaveNexus.nxs");
-    std::string rootstring = "/process/";
-    for (int i = 1; i < 5; i++)
-    {
-      TS_ASSERT_THROWS_NOTHING(loadhandle->openPath(rootstring + "MantidAlgorithm_" + boost::lexical_cast<std::string>(i)));
-    }
-    TS_ASSERT_THROWS_NOTHING(loadhandle->openPath(rootstring + "MantidEnvironment"));
-    TS_ASSERT_THROWS_NOTHING(loadhandle->openPath(rootstring + "MantidAlgorithm_4/author"));
-    TS_ASSERT_THROWS_NOTHING(loadhandle->openPath(rootstring + "MantidAlgorithm_4/data"));
-    TS_ASSERT_THROWS_NOTHING(loadhandle->openPath(rootstring + "MantidAlgorithm_4/description"));
-    TS_ASSERT_THROWS_ANYTHING(loadhandle->openPath(rootstring + "MantidAlgorithm_5"));
-
-    loadhandle->close();
-    Poco::File("WorkspaceHistoryTest_test_SaveNexus.nxs").remove();
-  }
-
-  void test_SaveNexus_NestedHistory()
-  {
-    WorkspaceHistory testHistory;
-    AlgorithmHistory algHist("ParentHistory", 1,DateAndTime::defaultTime(),-1.0, 0);
-    AlgorithmHistory childHist("ChildHistory", 1,DateAndTime::defaultTime(),-1.0, 1);
-
-    algHist.addChildHistory(boost::make_shared<AlgorithmHistory>(childHist));
-    testHistory.addHistory(boost::make_shared<AlgorithmHistory>(algHist));
-
-    auto savehandle = boost::make_shared< ::NeXus::File >("WorkspaceHistoryTest_test_SaveNexus.nxs",NXACC_CREATE5);
-    TS_ASSERT_THROWS_NOTHING(testHistory.saveNexus(savehandle.get()));
-    savehandle->close();
-
-    auto loadhandle = boost::make_shared< ::NeXus::File >("WorkspaceHistoryTest_test_SaveNexus.nxs");
-    std::string rootstring = "/process/";
-    TS_ASSERT_THROWS_NOTHING(loadhandle->openPath(rootstring + "MantidAlgorithm_1/"));
-    TS_ASSERT_THROWS_NOTHING(loadhandle->openPath(rootstring + "MantidAlgorithm_1/author"));
-    TS_ASSERT_THROWS_NOTHING(loadhandle->openPath(rootstring + "MantidAlgorithm_1/data"));
-    TS_ASSERT_THROWS_NOTHING(loadhandle->openPath(rootstring + "MantidAlgorithm_1/description"));
-
-    TS_ASSERT_THROWS_NOTHING(loadhandle->openPath(rootstring + "MantidAlgorithm_1/MantidAlgorithm_2"));
-    TS_ASSERT_THROWS_NOTHING(loadhandle->openPath(rootstring + "MantidAlgorithm_1/MantidAlgorithm_2/author"));
-    TS_ASSERT_THROWS_NOTHING(loadhandle->openPath(rootstring + "MantidAlgorithm_1/MantidAlgorithm_2/data"));
-    TS_ASSERT_THROWS_NOTHING(loadhandle->openPath(rootstring + "MantidAlgorithm_1/MantidAlgorithm_2/description"));
-
-    loadhandle->close();
-    Poco::File("WorkspaceHistoryTest_test_SaveNexus.nxs").remove();
-  }
-
-  void test_SaveNexus_Empty()
-  {
-    WorkspaceHistory testHistory;
-
-    auto savehandle = boost::make_shared< ::NeXus::File >("WorkspaceHistoryTest_test_SaveNexus.nxs",NXACC_CREATE5);
-    TS_ASSERT_THROWS_NOTHING(testHistory.saveNexus(savehandle.get()));
-    savehandle->close();
-
-    auto loadhandle = boost::make_shared< ::NeXus::File >("WorkspaceHistoryTest_test_SaveNexus.nxs");
-    std::string rootstring = "/process/";
-    TS_ASSERT_THROWS_NOTHING(loadhandle->openPath(rootstring));
-    TS_ASSERT_THROWS_NOTHING(loadhandle->openPath(rootstring + "MantidEnvironment"));
-    TS_ASSERT_THROWS_ANYTHING(loadhandle->openPath(rootstring + "MantidAlgorithm_1"));
-    
-    loadhandle->close();
-    Poco::File("WorkspaceHistoryTest_test_SaveNexus.nxs").remove();
-  }
-
-  void test_LoadNexus()
-  {
-    std::string filename = FileFinder::Instance().getFullPath("GEM38370_Focussed_Legacy.nxs");
-    auto loadhandle = boost::make_shared< ::NeXus::File >(filename);
-    loadhandle->openPath("/mantid_workspace_1");
-
-    WorkspaceHistory emptyHistory;
-    TS_ASSERT_THROWS_NOTHING(emptyHistory.loadNexus(loadhandle.get()));
-
-    const auto & histories = emptyHistory.getAlgorithmHistories();
-    TS_ASSERT_EQUALS(3,histories.size());
-    
-    const auto history = emptyHistory.getAlgorithmHistory(0);
-
-    TS_ASSERT_EQUALS("LoadRaw", history->name());
-    TS_ASSERT_EQUALS(3, history->version());
-    TS_ASSERT_EQUALS(DateAndTime("2009-10-09T16:56:54"), history->executionDate());
-    TS_ASSERT_EQUALS(2.3, history->executionDuration());
-    loadhandle->close();
-  }
-
-  void test_LoadNexus_NestedHistory()
-  {
-    std::string filename = FileFinder::Instance().getFullPath("HistoryTest_CreateTransmissionAuto.nxs");
-    auto loadhandle = boost::make_shared< ::NeXus::File >(filename);
-    loadhandle->openPath("/mantid_workspace_1");
-
-    WorkspaceHistory wsHistory;
-    TS_ASSERT_THROWS_NOTHING(wsHistory.loadNexus(loadhandle.get()));
-
-    const auto & histories = wsHistory.getAlgorithmHistories();
-    TS_ASSERT_EQUALS(3,histories.size());
-
-    auto history = wsHistory.getAlgorithmHistory(1);
-
-    TS_ASSERT_EQUALS("CreateTransmissionWorkspaceAuto", history->name());
-    TS_ASSERT_EQUALS(1, history->version());
-
-    const auto childHistory = history->getChildAlgorithmHistory(0);
-
-    TS_ASSERT_EQUALS("CreateTransmissionWorkspace", childHistory->name());
-    TS_ASSERT_EQUALS(1, childHistory->version());
-
-    history = wsHistory.getAlgorithmHistory(2);
-
-    TS_ASSERT_EQUALS("SaveNexusProcessed", history->name());
-    TS_ASSERT_EQUALS(1, history->version());
-    
-    loadhandle->close();
-  }
-
-  void test_LoadNexus_Blank_File()
-  {
-    std::string rootstring = "/process/";
-    //first file - clean - contains nothing
-    NexusTestHelper testfile(true);
-    testfile.createFile("LoadNexusTest.nxs");
-
-    WorkspaceHistory history;
-    //will throw nothing as it will return with only a warning, no exception
-    TS_ASSERT_THROWS_NOTHING(history.loadNexus(testfile.file));
-    const auto & histories = history.getAlgorithmHistories();
-    
-    TS_ASSERT_EQUALS(0,histories.size());
-    TS_ASSERT_THROWS_ANYTHING(testfile.file->openPath(rootstring));
-    TS_ASSERT_THROWS_ANYTHING(testfile.file->openPath(rootstring + "MantidEnvironment"));
-    TS_ASSERT_THROWS_ANYTHING(testfile.file->openPath(rootstring + "MantidAlgorithm_1"));
-
-  }
-
-  void test_LoadNexus_Missing_Author()
-  {
-    //second file - 3 algorithms one missing an author
-    NexusTestHelper testfile(true);
-    failiure_testfile_setup(2, testfile);
-    WorkspaceHistory history;
-    TS_ASSERT_THROWS_NOTHING(history.loadNexus(testfile.file));
-    const auto & histories = history.getAlgorithmHistories();
-    //three will still exist as it doesn't really care about the author
-    TS_ASSERT_EQUALS(3,histories.size());
-  }
-
-  void test_LoadNexus_Missing_Description()
-  {
-    //third file - 3 algorithms one missing a description
-    NexusTestHelper testfile(true);
-    failiure_testfile_setup(3, testfile);
-    WorkspaceHistory history;
-    TS_ASSERT_THROWS_NOTHING(history.loadNexus(testfile.file));
-    const auto & histories = history.getAlgorithmHistories();
-    
-    //three will still exist as it doesn't really care about the author
-    TS_ASSERT_EQUALS(3,histories.size());
-  }
-
-  void test_LoadNexus_Missing_Data()
-  {
-    //fourth file - 3 algorithms one missing data
-    NexusTestHelper testfile(true);
-    failiure_testfile_setup(4, testfile);
-    WorkspaceHistory history;
-    //this WILL throw as it looks for a data field using ::NeXus::File::readData() and it won't be found
-    TS_ASSERT_THROWS_ANYTHING(history.loadNexus(testfile.file));
-    const auto & histories = history.getAlgorithmHistories();
-    //only one will exist as it will throw on the second (wihtout the data) and skip the rest
-    TS_ASSERT_EQUALS(1,histories.size());
-  }
-
-  void test_LoadNexus_Short_Data()
-  {
-    //fifth file - 3 algorithms one wiht only one line of data
-    NexusTestHelper testfile(true);
-    failiure_testfile_setup(5, testfile);
-    WorkspaceHistory history;
-    //won't throw as it'll simply ignore the bad data
-    TS_ASSERT_THROWS_NOTHING(history.loadNexus(testfile.file));
-    const auto & histories = history.getAlgorithmHistories();
-    
-    //only two will exist as it will ignore the second (with only the single line) and continue as normal
-    TS_ASSERT_EQUALS(2,histories.size());
-  }
-
-  void test_LoadNexus_All_Short_Data()
-  {
-    //sixth file - 3 algorithms all with only one line of data
-    NexusTestHelper testfile(true);
-    failiure_testfile_setup(6, testfile);
-    WorkspaceHistory history;
-    //nothign will throw but nothing will be loaded either as the data is invalid
-    TS_ASSERT_THROWS_NOTHING(history.loadNexus(testfile.file));
-    const auto & histories = history.getAlgorithmHistories();
-    //size should be zero as nothing went in the file
-    TS_ASSERT_EQUALS(0,histories.size());
-  }
-
-  void test_LoadNexus_Bad_Formatting()
-  {
-    //seventh file - 3 algorithms, one with bad formatting
-    NexusTestHelper testfile(true);
-    failiure_testfile_setup(7, testfile);
-    WorkspaceHistory history;
-    //this will throw on the second due to the unformatted data - the function expects well formatted data
-    TS_ASSERT_THROWS_ANYTHING(history.loadNexus(testfile.file));
-    const auto & histories = history.getAlgorithmHistories();
-    //only one will exist as it will throw on the second (with the bad data) and skip the rest
-    TS_ASSERT_EQUALS(1,histories.size());
-  }
 };
 
 class WorkspaceHistoryTestPerformance : public CxxTest::TestSuite
@@ -531,5 +184,4 @@ private:
   Mantid::API::WorkspaceHistory m_wsHist;
 };
 
-
 #endif
diff --git a/Code/Mantid/Framework/API/test/WorkspacePropertyTest.h b/Code/Mantid/Framework/API/test/WorkspacePropertyTest.h
index b45fb6e5b8e2a402a25bcbc2c0e5942f95b69975..d9663ac0227fe9d1f46aa8468cee4e7515e430c6 100644
--- a/Code/Mantid/Framework/API/test/WorkspacePropertyTest.h
+++ b/Code/Mantid/Framework/API/test/WorkspacePropertyTest.h
@@ -162,11 +162,11 @@ public:
 
   void testAllowedValues()
   {
-    std::set<std::string> vals;
+    std::vector<std::string> vals;
     TS_ASSERT_THROWS_NOTHING( vals = wsp1->allowedValues() )
     TS_ASSERT_EQUALS( vals.size(), 2 )
-    TS_ASSERT( vals.count("ws1") )
-    TS_ASSERT( vals.count("ws3") )
+    TS_ASSERT( std::find( vals.begin(), vals.end(), "ws1") != vals.end() )
+    TS_ASSERT( std::find( vals.begin(), vals.end(), "ws3") != vals.end() )
 
     TS_ASSERT( wsp2->allowedValues().empty() )
 
diff --git a/Code/Mantid/Framework/Algorithms/CMakeLists.txt b/Code/Mantid/Framework/Algorithms/CMakeLists.txt
index 131135ff25e32b7a1e432b3272ed90260722dfdb..b05af4d8b211ade97f9e24d7012b2be2e325cfec 100644
--- a/Code/Mantid/Framework/Algorithms/CMakeLists.txt
+++ b/Code/Mantid/Framework/Algorithms/CMakeLists.txt
@@ -30,6 +30,7 @@ set ( SRC_FILES
 	src/ChangePulsetime.cpp
 	src/CheckWorkspacesMatch.cpp
 	src/ChopData.cpp
+	src/ClearInstrumentParameters.cpp
 	src/ClearMaskFlag.cpp
 	src/CloneWorkspace.cpp
 	src/CommutativeBinaryOperation.cpp
@@ -269,6 +270,7 @@ set ( INC_FILES
 	inc/MantidAlgorithms/ChangePulsetime.h
 	inc/MantidAlgorithms/CheckWorkspacesMatch.h
 	inc/MantidAlgorithms/ChopData.h
+	inc/MantidAlgorithms/ClearInstrumentParameters.h
 	inc/MantidAlgorithms/ClearMaskFlag.h
 	inc/MantidAlgorithms/CloneWorkspace.h
 	inc/MantidAlgorithms/CommutativeBinaryOperation.h
@@ -520,6 +522,7 @@ set ( TEST_FILES
 	ChangePulsetimeTest.h
 	CheckWorkspacesMatchTest.h
 	ChopDataTest.h
+	ClearInstrumentParametersTest.h
 	ClearMaskFlagTest.h
 	CloneWorkspaceTest.h
 	CommutativeBinaryOperationTest.h
@@ -553,6 +556,7 @@ set ( TEST_FILES
 	CreatePeaksWorkspaceTest.h
 	CreateSampleWorkspaceTest.h
 	CreateSingleValuedWorkspaceTest.h
+	CreateTransmissionWorkspaceTest.h
 	CreateTransmissionWorkspaceAutoTest.h
 	CreateWorkspaceTest.h
 	CropWorkspaceTest.h
diff --git a/Code/Mantid/Framework/Algorithms/inc/MantidAlgorithms/ClearInstrumentParameters.h b/Code/Mantid/Framework/Algorithms/inc/MantidAlgorithms/ClearInstrumentParameters.h
new file mode 100644
index 0000000000000000000000000000000000000000..d1509fe4f12fa027f492a217ebc357d7bb005c71
--- /dev/null
+++ b/Code/Mantid/Framework/Algorithms/inc/MantidAlgorithms/ClearInstrumentParameters.h
@@ -0,0 +1,57 @@
+#ifndef MANTID_ALGORITHMS_CLEARINSTRUMENTPARAMETERS_H_
+#define MANTID_ALGORITHMS_CLEARINSTRUMENTPARAMETERS_H_
+
+#include "MantidKernel/System.h"
+#include "MantidAPI/Algorithm.h"
+
+namespace Mantid
+{
+
+namespace Algorithms
+{
+
+  /** ClearInstrumentParameters : Clear out an instrument's parameters.
+
+    @author Harry Jeffery, ISIS, RAL
+    @date 30/7/2014
+
+    Copyright &copy; 2014 ISIS Rutherford Appleton Laboratory & NScD Oak Ridge National Laboratory
+
+    This file is part of Mantid.
+
+    Mantid is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 3 of the License, or
+    (at your option) any later version.
+
+    Mantid is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+    File change history is stored at: <https://github.com/mantidproject/mantid>
+    Code Documentation is available at: <http://doxygen.mantidproject.org>
+  */
+  class DLLExport ClearInstrumentParameters : public API::Algorithm
+  {
+  public:
+    ClearInstrumentParameters();
+    virtual ~ClearInstrumentParameters();
+    virtual const std::string name() const;
+    virtual const std::string summary() const;
+    virtual const std::string category() const;
+    virtual int version() const;
+
+  private:
+    void init();
+    void exec();
+  };
+
+
+} // namespace Algorithms
+} // namespace Mantid
+
+#endif  /* MANTID_ALGORITHMS_CLEARINSTRUMENTPARAMETERS_H_ */
diff --git a/Code/Mantid/Framework/Algorithms/inc/MantidAlgorithms/FilterEvents.h b/Code/Mantid/Framework/Algorithms/inc/MantidAlgorithms/FilterEvents.h
index da237d409572d4ebc2697f93e1d6df6be92ad471..528442714f74f9e3887188278701238f9c18c696 100644
--- a/Code/Mantid/Framework/Algorithms/inc/MantidAlgorithms/FilterEvents.h
+++ b/Code/Mantid/Framework/Algorithms/inc/MantidAlgorithms/FilterEvents.h
@@ -45,13 +45,14 @@ namespace Algorithms
 
     enum TOFCorrectionType {NoneCorrect, CustomizedCorrect, DirectCorrect, ElasticCorrect, IndirectCorrect};
     enum TOFCorrectionOp {MultiplyOp, ShiftOp};
+    enum EVENTFILTERSKIP {EventFilterSkipNoDet, EventFilterSkipNoDetTOFCorr};
 
   public:
     FilterEvents();
     virtual ~FilterEvents();
     
     /// Algorithm's name for identification overriding a virtual method
-    virtual const std::string name() const { return "FilterEvents";};
+    virtual const std::string name() const { return "FilterEvents";}
     ///Summary of algorithms purpose
     virtual const std::string summary() const {return "Filter events from an EventWorkspace to one or multiple EventWorkspaces according to a series of splitters.";}
 
@@ -100,6 +101,9 @@ namespace Algorithms
     /// Filter events by splitters in format of vector
     void filterEventsByVectorSplitters(double progressamount);
 
+    /// Examine workspace
+    void examineEventWS();
+
     DataObjects::EventWorkspace_sptr m_eventWS;
     DataObjects::SplittersWorkspace_sptr m_splittersWorkspace;
     API::MatrixWorkspace_const_sptr m_matrixSplitterWS;
@@ -132,12 +136,12 @@ namespace Algorithms
     /// Base of output workspace's name
     std::string m_outputWSNameBase;
 
-    ///
+    /// Flag to group workspace
     bool m_toGroupWS;
 
-    ///
+    /// Vector for splitting time
     std::vector<int64_t> m_vecSplitterTime;
-    ///
+    /// Vector for splitting grouip
     std::vector<int> m_vecSplitterGroup;
 
     /// Flag to split sample logs
@@ -150,6 +154,11 @@ namespace Algorithms
     /// TOF detector/sample correction type
     TOFCorrectionType m_tofCorrType;
 
+    /// Spectrum skip type
+    EVENTFILTERSKIP m_specSkipType;
+    /// Vector for skip information
+    std::vector<bool> m_vecSkip;
+
   };
 
 
diff --git a/Code/Mantid/Framework/Algorithms/inc/MantidAlgorithms/GenerateEventsFilter.h b/Code/Mantid/Framework/Algorithms/inc/MantidAlgorithms/GenerateEventsFilter.h
index dcd8861aa81d9b8fded5001476fb96d5cc0f096f..24cae04d16567c5531b8bf4d524ffc57cb10fc38 100644
--- a/Code/Mantid/Framework/Algorithms/inc/MantidAlgorithms/GenerateEventsFilter.h
+++ b/Code/Mantid/Framework/Algorithms/inc/MantidAlgorithms/GenerateEventsFilter.h
@@ -94,9 +94,9 @@ namespace Algorithms
     void processMultipleValueFilters(double minvalue, double valueinterval, double maxvalue,
                                      bool filterincrease, bool filterdecrease);
 
-    void makeFilterByValue(Kernel::TimeSplitterType& split, double min, double max, double TimeTolerance, bool centre,
-        bool filterIncrease, bool filterDecrease, Kernel::DateAndTime startTime, Kernel::DateAndTime stopTime,
-        int wsindex);
+    void makeFilterBySingleValue(double min, double max, double TimeTolerance, bool centre,
+                                 bool filterIncrease, bool filterDecrease, Kernel::DateAndTime startTime, Kernel::DateAndTime stopTime,
+                                 int wsindex);
 
     /// Make multiple-log-value filters in serial
     void makeMultipleFiltersByValues(std::map<size_t, int> indexwsindexmap, std::vector<double> logvalueranges, bool centre,
@@ -142,6 +142,14 @@ namespace Algorithms
     /// Generate a SplittersWorkspace for filtering by log values
     void generateSplittersInSplitterWS();
 
+    /// Identify the a sample log entry is within intended value and time region
+    bool identifyLogEntry(const int &index, const Kernel::DateAndTime &currT, const bool &lastgood,
+                          const double &minvalue, const double &maxvalue,
+                          const Kernel::DateAndTime &startT, const Kernel::DateAndTime &stopT, const bool &filterIncrease, const bool &filterDecrease);
+
+    /// ??
+    int determineChangingDirection(int startindex);
+
     DataObjects::EventWorkspace_const_sptr m_dataWS;
 
     /// SplitterWorkspace
diff --git a/Code/Mantid/Framework/Algorithms/inc/MantidAlgorithms/GeneratePythonScript.h b/Code/Mantid/Framework/Algorithms/inc/MantidAlgorithms/GeneratePythonScript.h
index c65dc26a1460335d431f7ea7ed7721ad28dd01a5..e09530b338ee589e7654c3cd9a3c8a64d465c008 100644
--- a/Code/Mantid/Framework/Algorithms/inc/MantidAlgorithms/GeneratePythonScript.h
+++ b/Code/Mantid/Framework/Algorithms/inc/MantidAlgorithms/GeneratePythonScript.h
@@ -64,12 +64,6 @@ protected:
   void init();
   /// Run the algorithm
   void exec();
-  /// Generate the line of script corresponding to the given AlgorithmHistory
-  std::string genAlgString(const API::AlgorithmHistory&);
-  /// Generate the parameter string (of format "[name]='[value]'") for the given PropertyHistory.
-  std::string genParamString(Mantid::Kernel::PropertyHistory_const_sptr, const API::IAlgorithm_sptr, const std::string algHistName);
-  // "Sanitize" property name.
-  std::string sanitizePropertyName(const std::string&);
 };
 
 
diff --git a/Code/Mantid/Framework/Algorithms/inc/MantidAlgorithms/ScaleX.h b/Code/Mantid/Framework/Algorithms/inc/MantidAlgorithms/ScaleX.h
index 39ff6e03f0a5d61d586a68ff691ba0782393c25e..f44110f3ceff43050cbe4a012efd330f98a39bb0 100644
--- a/Code/Mantid/Framework/Algorithms/inc/MantidAlgorithms/ScaleX.h
+++ b/Code/Mantid/Framework/Algorithms/inc/MantidAlgorithms/ScaleX.h
@@ -55,7 +55,7 @@ namespace Mantid
       /// Algorithm's name for identification overriding a virtual method
       virtual const std::string name() const { return "ScaleX";}
     ///Summary of algorithms purpose
-    virtual const std::string summary() const {return "Scales an input workspace by the given factor, which can be either multiplicative or additive.";}
+    virtual const std::string summary() const {return "Scales the X-axis of an input workspace by the given factor, which can be either multiplicative or additive.";}
 
       /// Algorithm's version for identification overriding a virtual method
       virtual int version() const { return 1;}
diff --git a/Code/Mantid/Framework/Algorithms/inc/MantidAlgorithms/Stitch1D.h b/Code/Mantid/Framework/Algorithms/inc/MantidAlgorithms/Stitch1D.h
index 26366341f99cf259b0d2119440f3ac7730ba935b..52a4044d88424f0f64c095d43c4fb49840e800e3 100644
--- a/Code/Mantid/Framework/Algorithms/inc/MantidAlgorithms/Stitch1D.h
+++ b/Code/Mantid/Framework/Algorithms/inc/MantidAlgorithms/Stitch1D.h
@@ -12,44 +12,64 @@ namespace Mantid
 
     /** Stitch1D : Stitches two Matrix Workspaces together into a single output.
 
-    Copyright &copy; 2014 ISIS Rutherford Appleton Laboratory & NScD Oak Ridge National Laboratory
+     Copyright &copy; 2014 ISIS Rutherford Appleton Laboratory & NScD Oak Ridge National Laboratory
 
-    This file is part of Mantid.
+     This file is part of Mantid.
 
-    Mantid is free software; you can redistribute it and/or modify
-    it under the terms of the GNU General Public License as published by
-    the Free Software Foundation; either version 3 of the License, or
-    (at your option) any later version.
+     Mantid is free software; you can redistribute it and/or modify
+     it under the terms of the GNU General Public License as published by
+     the Free Software Foundation; either version 3 of the License, or
+     (at your option) any later version.
 
-    Mantid is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU General Public License for more details.
+     Mantid is distributed in the hope that it will be useful,
+     but WITHOUT ANY WARRANTY; without even the implied warranty of
+     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+     GNU General Public License for more details.
 
-    You should have received a copy of the GNU General Public License
-    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+     You should have received a copy of the GNU General Public License
+     along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-    File change history is stored at: <https://github.com/mantidproject/mantid>
-    Code Documentation is available at: <http://doxygen.mantidproject.org>
-    */
-    class DLLExport Stitch1D  : public API::Algorithm
+     File change history is stored at: <https://github.com/mantidproject/mantid>
+     Code Documentation is available at: <http://doxygen.mantidproject.org>
+     */
+    class DLLExport Stitch1D: public API::Algorithm
     {
     public:
       /// Default constructor
-      Stitch1D(){};
+      Stitch1D()
+      {
+      }
+      ;
       /// Destructor
-      virtual ~Stitch1D(){};
+      virtual ~Stitch1D()
+      {
+      }
+      ;
       /// Algorithm's name for identification. @see Algorithm::name
-      virtual const std::string name() const {return "Stitch1D";}
+      virtual const std::string name() const
+      {
+        return "Stitch1D";
+      }
       /// Algorithm's version for identification. @see Algorithm::version
-      virtual int version() const {return 3;}
+      virtual int version() const
+      {
+        return 3;
+      }
       /// Algorithm's category for identification. @see Algorithm::category
-      virtual const std::string category() const {return "Reflectometry";}
+      virtual const std::string category() const
+      {
+        return "Reflectometry";
+      }
       ///Summary of algorithm's purpose
-      virtual const std::string summary() const {return "Stitches single histogram matrix workspaces together";}
+      virtual const std::string summary() const
+      {
+        return "Stitches single histogram matrix workspaces together";
+      }
       /// Does the x-axis have non-zero errors
       bool hasNonzeroErrors(Mantid::API::MatrixWorkspace_sptr ws);
     private:
+      /// Helper typedef. For storing indexes of special values per spectra per workspace.
+      typedef std::vector<std::vector<size_t> > SpecialTypeIndexes;
       /// Overwrites Algorithm method.
       void init();
       /// Overwrites Algorithm method.
@@ -60,27 +80,48 @@ namespace Mantid
       double getEndOverlap(const double& intesectionMin, const double& intesectionMax) const;
 
       /// Get the rebin parameters
-      Mantid::MantidVec getRebinParams(Mantid::API::MatrixWorkspace_sptr& lhsWS, Mantid::API::MatrixWorkspace_sptr& rhsWS, const bool scaleRHSWS) const;
+      Mantid::MantidVec getRebinParams(Mantid::API::MatrixWorkspace_sptr& lhsWS,
+          Mantid::API::MatrixWorkspace_sptr& rhsWS, const bool scaleRHSWS) const;
       /// Perform rebin
-      Mantid::API::MatrixWorkspace_sptr rebin(Mantid::API::MatrixWorkspace_sptr& input, const Mantid::MantidVec& params);
+      Mantid::API::MatrixWorkspace_sptr rebin(Mantid::API::MatrixWorkspace_sptr& input,
+          const Mantid::MantidVec& params);
       /// Perform integration
-      Mantid::API::MatrixWorkspace_sptr specialIntegration(Mantid::API::MatrixWorkspace_sptr& input, const double& start, const double& stop);
+      Mantid::API::MatrixWorkspace_sptr integration(Mantid::API::MatrixWorkspace_sptr& input,
+          const double& start, const double& stop);
       /// Perform multiplication over a range
-      Mantid::API::MatrixWorkspace_sptr multiplyRange(Mantid::API::MatrixWorkspace_sptr& input, const int& startBin, const int& endBin, const double& factor);
+      Mantid::API::MatrixWorkspace_sptr multiplyRange(Mantid::API::MatrixWorkspace_sptr& input,
+          const int& startBin, const int& endBin, const double& factor);
       /// Perform multiplication over a range
-      Mantid::API::MatrixWorkspace_sptr multiplyRange(Mantid::API::MatrixWorkspace_sptr& input, const int& startBin, const double& factor);
+      Mantid::API::MatrixWorkspace_sptr multiplyRange(Mantid::API::MatrixWorkspace_sptr& input,
+          const int& startBin, const double& factor);
       /// Create a single valued workspace
       Mantid::API::MatrixWorkspace_sptr singleValueWS(double val);
       /// Calclate the weighted mean
-      Mantid::API::MatrixWorkspace_sptr weightedMean(Mantid::API::MatrixWorkspace_sptr& inOne, Mantid::API::MatrixWorkspace_sptr& inTwo);
+      Mantid::API::MatrixWorkspace_sptr weightedMean(Mantid::API::MatrixWorkspace_sptr& inOne,
+          Mantid::API::MatrixWorkspace_sptr& inTwo);
       /// Find the start and end indexes
-      boost::tuple<int,int> findStartEndIndexes(double startOverlap, double endOverlap, Mantid::API::MatrixWorkspace_sptr& workspace);
+      boost::tuple<int, int> findStartEndIndexes(double startOverlap, double endOverlap,
+          Mantid::API::MatrixWorkspace_sptr& workspace);
+      /// Mask out everything but the data in the ranges
+      Mantid::API::MatrixWorkspace_sptr maskAllBut(int a1, int a2,
+          Mantid::API::MatrixWorkspace_sptr & source);
+      /// Mask out everything but the data in the ranges, but do it inplace.
+      void maskInPlace(int a1, int a2, Mantid::API::MatrixWorkspace_sptr source);
+      /// Add back in any special values
+      void reinsertSpecialValues(Mantid::API::MatrixWorkspace_sptr ws);
       /// Range tolerance
       static const double range_tolerance;
+      /// Index per workspace spectra of Nans
+      SpecialTypeIndexes m_nanYIndexes;
+      /// Index per workspace spectra of Infs
+      SpecialTypeIndexes m_infYIndexes;
+      /// Index per workspace spectra of Nans
+      SpecialTypeIndexes m_nanEIndexes;
+      /// Index per workspace spectra of Infs
+      SpecialTypeIndexes m_infEIndexes;
 
     };
 
-
   } // namespace Algorithms
 } // namespace Mantid
 
diff --git a/Code/Mantid/Framework/Algorithms/src/CheckWorkspacesMatch.cpp b/Code/Mantid/Framework/Algorithms/src/CheckWorkspacesMatch.cpp
index 7a9f50f24910f8d44ddade8294e61619612d22a9..e8267d6f02eaf765c60bd3258bed246e0d494b72 100644
--- a/Code/Mantid/Framework/Algorithms/src/CheckWorkspacesMatch.cpp
+++ b/Code/Mantid/Framework/Algorithms/src/CheckWorkspacesMatch.cpp
@@ -729,9 +729,8 @@ bool CheckWorkspacesMatch::checkInstrument(API::MatrixWorkspace_const_sptr ws1,
 
   if ( ws1_parmap != ws2_parmap )
   {
-    g_log.debug() << "Parameter maps...\n";
-    g_log.debug() << "WS1: " << ws1_parmap.asString() << "\n";
-    g_log.debug() << "WS2: " << ws2_parmap.asString() << "\n";
+    g_log.debug() << "Here information to help understand parameter map differences:\n";
+    g_log.debug() << ws1_parmap.diff(ws2_parmap);
     result = "Instrument ParameterMap mismatch (differences in ordering ignored)";
     return false;
   }
diff --git a/Code/Mantid/Framework/Algorithms/src/ClearInstrumentParameters.cpp b/Code/Mantid/Framework/Algorithms/src/ClearInstrumentParameters.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..9c071335a3706747b74369452a266cd780a02469
--- /dev/null
+++ b/Code/Mantid/Framework/Algorithms/src/ClearInstrumentParameters.cpp
@@ -0,0 +1,99 @@
+#include "MantidAlgorithms/ClearInstrumentParameters.h"
+#include "MantidAPI/FileProperty.h"
+#include "MantidAPI/WorkspaceValidators.h"
+#include "MantidGeometry/IComponent.h"
+#include "MantidGeometry/Instrument.h"
+#include "MantidGeometry/Instrument/ParameterMap.h"
+
+namespace Mantid
+{
+namespace Algorithms
+{
+
+  // Register the algorithm into the AlgorithmFactory
+  DECLARE_ALGORITHM(ClearInstrumentParameters)
+
+  using namespace Kernel;
+  using namespace API;
+  using namespace Geometry;
+
+  //----------------------------------------------------------------------------------------------
+  /** Constructor
+   */
+  ClearInstrumentParameters::ClearInstrumentParameters()
+  {
+  }
+
+  //----------------------------------------------------------------------------------------------
+  /** Destructor
+   */
+  ClearInstrumentParameters::~ClearInstrumentParameters()
+  {
+  }
+
+  //----------------------------------------------------------------------------------------------
+  /// Algorithm's name for identification. @see Algorithm::name
+  const std::string ClearInstrumentParameters::name() const { return "ClearInstrumentParameters";};
+
+  /// Summary of the algorithm's purpose. @see Algorithm::summary
+  const std::string ClearInstrumentParameters::summary() const { return "Clears all the parameters associated with a workspace's instrument.";}
+
+  /// Algorithm's version for identification. @see Algorithm::version
+  int ClearInstrumentParameters::version() const { return 1;};
+
+  /// Algorithm's category for identification. @see Algorithm::category
+  const std::string ClearInstrumentParameters::category() const { return "DataHandling\\Instrument";}
+
+  //----------------------------------------------------------------------------------------------
+
+  //----------------------------------------------------------------------------------------------
+  /** Initialize the algorithm's properties.
+   */
+  void ClearInstrumentParameters::init()
+  {
+    declareProperty(new WorkspaceProperty<>("Workspace","",Direction::InOut,boost::make_shared<InstrumentValidator>()),
+    "Workspace whose instrument parameters are to be cleared.");
+
+    declareProperty("LocationParameters", true, "Clear the location parameters used to calibrate the instrument.", Direction::Input);
+  }
+
+  //----------------------------------------------------------------------------------------------
+  /** Execute the algorithm.
+   */
+  void ClearInstrumentParameters::exec()
+  {
+    const MatrixWorkspace_const_sptr ws = getProperty("Workspace");
+    const bool clearLocationParams = getProperty("LocationParameters");
+
+    const Instrument_const_sptr instrument = ws->getInstrument();
+    const ParameterMap_sptr params = instrument->getParameterMap();
+
+    ParameterMap::pmap paramsToKeep;
+
+    //Go through all the parameters, keep a hold of any we don't want to clear.
+    for(auto paramIt = params->begin(); paramIt != params->end(); ++paramIt)
+    {
+      //Are we keeping the location parameters?
+      const std::string pName = (*paramIt).second->name();
+      if(!clearLocationParams &&
+        (pName == "x"          || pName == "y"          || pName == "z" ||
+         pName == "r-position" || pName == "t-position" || pName == "p-position" ||
+         pName == "rotx"       || pName == "roty"       || pName == "rotz"))
+      {
+        paramsToKeep.insert(*paramIt);
+      }
+    }
+
+    //Clear out the parameter map
+    params->clear();
+
+    //Add any parameters we're keeping back into the parameter map.
+    for(auto paramIt = paramsToKeep.begin(); paramIt != paramsToKeep.end(); ++paramIt)
+    {
+      params->add((*paramIt).first, (*paramIt).second);
+    }
+
+  }
+
+} // namespace Algorithms
+} // namespace Mantid
diff --git a/Code/Mantid/Framework/Algorithms/src/ConvertUnits.cpp b/Code/Mantid/Framework/Algorithms/src/ConvertUnits.cpp
index a961eae8459640770eb5f301d39d5836025df264..0b3f28e2b4061e201d92d832c33f01b5bb760aa1 100644
--- a/Code/Mantid/Framework/Algorithms/src/ConvertUnits.cpp
+++ b/Code/Mantid/Framework/Algorithms/src/ConvertUnits.cpp
@@ -370,7 +370,7 @@ void ConvertUnits::convertViaTOF(Kernel::Unit_const_sptr fromUnit, API::MatrixWo
   IComponent_const_sptr sample = instrument->getSample();
   if ( source == NULL || sample == NULL )
   {
-    throw Exception::InstrumentDefinitionError("Instrubment not sufficiently defined: failed to get source and/or sample");
+    throw Exception::InstrumentDefinitionError("Instrument not sufficiently defined: failed to get source and/or sample");
   }
   double l1;
   try
diff --git a/Code/Mantid/Framework/Algorithms/src/CopySample.cpp b/Code/Mantid/Framework/Algorithms/src/CopySample.cpp
index 9a9c40a7d68e809f449aea411d335601c2389870..e7ee71c3b16b481fe81da2fc4ff6b5d3c588d790 100644
--- a/Code/Mantid/Framework/Algorithms/src/CopySample.cpp
+++ b/Code/Mantid/Framework/Algorithms/src/CopySample.cpp
@@ -155,7 +155,7 @@ namespace Algorithms
         }
         else
         {
-            to.setOrientedLattice(new Geometry::OrientedLattice(from.getOrientedLattice()));
+            to.setOrientedLattice(&from.getOrientedLattice());
         }
     }
 
diff --git a/Code/Mantid/Framework/Algorithms/src/CreateCalFileByNames.cpp b/Code/Mantid/Framework/Algorithms/src/CreateCalFileByNames.cpp
index 568f90689643237091f54a47b772110da3c26b8f..576e138f382843c13efc755836b44ce4dbcff460 100644
--- a/Code/Mantid/Framework/Algorithms/src/CreateCalFileByNames.cpp
+++ b/Code/Mantid/Framework/Algorithms/src/CreateCalFileByNames.cpp
@@ -211,7 +211,6 @@ namespace Mantid
         int number, udet, select, group;
         double offset;
 
-        instrcalmap::const_iterator it;
         std::string str;
         while(getline(infile,str))
         {
@@ -219,10 +218,12 @@ namespace Mantid
             continue;
           std::istringstream istr(str);
           istr >> number >> udet >> offset >> select >> group;
-          it=instrcalib.find(udet);
-          if (it==instrcalib.end()) // Not found, don't assign a group
-            group=0;
-          group=((*it).second).second; // If found then assign new group
+          instrcalmap::const_iterator it = instrcalib.find(udet);
+          if (it == instrcalib.end()) // Not found, don't assign a group
+            group = 0;
+          else
+            group=((*it).second).second; // If found then assign new group
+          // write out
           writeCalEntry(outfile,number,udet,offset,select,group);
         }
       }
diff --git a/Code/Mantid/Framework/Algorithms/src/CreateDummyCalFile.cpp b/Code/Mantid/Framework/Algorithms/src/CreateDummyCalFile.cpp
index fc259f00766994ab37f443ac67a18cadf21e25dc..48dd491f3983b8b26ac581d2e9d84f640b3374fa 100644
--- a/Code/Mantid/Framework/Algorithms/src/CreateDummyCalFile.cpp
+++ b/Code/Mantid/Framework/Algorithms/src/CreateDummyCalFile.cpp
@@ -264,7 +264,6 @@ namespace Mantid
         int number, udet, select, group;
         double offset;
 
-        instrcalmap::const_iterator it;
         std::string str;
         while(getline(infile,str))
         {
@@ -272,10 +271,12 @@ namespace Mantid
             continue;
           std::istringstream istr(str);
           istr >> number >> udet >> offset >> select >> group;
-          it=instrcalib.find(udet);
-          if (it==instrcalib.end()) // Not found, don't assign a group
-            group=0;
-          group=((*it).second).second; // If found then assign new group
+          instrcalmap::const_iterator it = instrcalib.find(udet);
+          if (it == instrcalib.end()) // Not found, don't assign a group
+            group = 0;
+          else
+            group=((*it).second).second; // If found then assign new group
+          // write to file
           writeCalEntry(outfile,number,udet,offset,select,group);
         }
       }
diff --git a/Code/Mantid/Framework/Algorithms/src/CreateTransmissionWorkspaceAuto.cpp b/Code/Mantid/Framework/Algorithms/src/CreateTransmissionWorkspaceAuto.cpp
index fdad0ff0ea7c9e50822064429e47fdf0c6f0a09d..9672f3c701ca8a9098da95d55e7b27c142adfbf5 100644
--- a/Code/Mantid/Framework/Algorithms/src/CreateTransmissionWorkspaceAuto.cpp
+++ b/Code/Mantid/Framework/Algorithms/src/CreateTransmissionWorkspaceAuto.cpp
@@ -120,7 +120,7 @@ namespace Mantid
       std::string outputWorkspaceName = this->getPropertyValue("OutputWorkspace");
       std::string analysis_mode = this->getPropertyValue("AnalysisMode");
 
-      auto second_ws_property = this->getPointerToProperty("SecondTransmissionRun");
+      MatrixWorkspace_sptr secondWS = this->getProperty("SecondTransmissionRun");
 
       auto start_overlap = isSet<double>("StartOverlap");
       auto end_overlap = isSet<double>("EndOverlap");
@@ -173,6 +173,7 @@ namespace Mantid
       //construct the algorithm
 
       IAlgorithm_sptr algCreateTransWS = createChildAlgorithm("CreateTransmissionWorkspace");
+      algCreateTransWS->setRethrows(true);
       algCreateTransWS->initialize();
 
       if (algCreateTransWS->isInitialized())
@@ -180,9 +181,9 @@ namespace Mantid
 
         algCreateTransWS->setProperty("FirstTransmissionRun", firstWS);
 
-        if (!second_ws_property->isDefault())
+        if (secondWS)
         {
-          algCreateTransWS->setProperty("SecondTransmissionRun", second_ws_property->value());
+          algCreateTransWS->setProperty("SecondTransmissionRun", secondWS);
         }
 
         algCreateTransWS->setProperty("OutputWorkspace", outputWorkspaceName);
diff --git a/Code/Mantid/Framework/Algorithms/src/DiffractionFocussing2.cpp b/Code/Mantid/Framework/Algorithms/src/DiffractionFocussing2.cpp
index 4ced3516bfb161c87778d1c462a3e2f1caee44a3..7714e23d3facff7fca59e2f9615b0867fffe509a 100644
--- a/Code/Mantid/Framework/Algorithms/src/DiffractionFocussing2.cpp
+++ b/Code/Mantid/Framework/Algorithms/src/DiffractionFocussing2.cpp
@@ -493,6 +493,7 @@ void DiffractionFocussing2::execEvent()
   }
   out->clearMRU();
   setProperty("OutputWorkspace", boost::dynamic_pointer_cast<MatrixWorkspace>(out));
+  delete prog;
   return;
 }
 
diff --git a/Code/Mantid/Framework/Algorithms/src/FilterEvents.cpp b/Code/Mantid/Framework/Algorithms/src/FilterEvents.cpp
index 6831e95a7b17b0375ead586c27e9fdb138127996..4ba24686e209d459b2dbe7fa19a87869af14e36a 100644
--- a/Code/Mantid/Framework/Algorithms/src/FilterEvents.cpp
+++ b/Code/Mantid/Framework/Algorithms/src/FilterEvents.cpp
@@ -101,6 +101,13 @@ namespace Algorithms
     setPropertySettings("IncidentEnergy",
                         new VisibleWhenProperty("CorrectionToSample", IS_EQUAL_TO, "Direct"));
 
+    // Algorithm to spectra without detectors
+    vector<string> spec_no_det;
+    spec_no_det.push_back("Skip");
+    spec_no_det.push_back("Skip only if TOF correction");
+    declareProperty("SpectrumWithoutDetector", "Skip", boost::make_shared<StringListValidator>(spec_no_det),
+                    "Approach to deal with spectrum without detectors. ");
+
     declareProperty("SplitSampleLogs", true, "If selected, all sample logs will be splitted by the  "
                     "event splitters.  It is not recommended for fast event log splitters. ");
 
@@ -122,6 +129,9 @@ namespace Algorithms
     // Process algorithm properties
     processProperties();
 
+    // Examine workspace for detectors
+    examineEventWS();
+
     // Parse splitters
     mProgress = 0.0;
     progress(mProgress, "Processing SplittersWorkspace.");
@@ -187,7 +197,6 @@ namespace Algorithms
     return;
   }
 
-
   //----------------------------------------------------------------------------------------------
   /** Process input properties
    */
@@ -264,6 +273,14 @@ namespace Algorithms
         throw runtime_error("In case of customized TOF correction, correction workspace must be given!");
     }
 
+    // Spectrum skip
+    string skipappr = getPropertyValue("SpectrumWithoutDetector");
+    if (skipappr.compare("Skip") == 0)
+      m_specSkipType = EventFilterSkipNoDet;
+    else if (skipappr.compare("Skip only if TOF correction") == 0)
+      m_specSkipType = EventFilterSkipNoDetTOFCorr;
+    else
+      throw runtime_error("An unrecognized option for SpectrumWithoutDetector");
     m_splitSampleLogs = getProperty("SplitSampleLogs");
 
     // Debug spectrum
@@ -272,8 +289,82 @@ namespace Algorithms
       m_useDBSpectrum = false;
     else
       m_useDBSpectrum = true;
+
+    return;
+  }
+
+
+  //----------------------------------------------------------------------------------------------
+  /** Examine whether any spectrum does not have detector
+    */
+  void FilterEvents::examineEventWS()
+  {
+    size_t numhist = m_eventWS->getNumberHistograms();
+    m_vecSkip.resize(numhist, false);
+
+    if (m_specSkipType == EventFilterSkipNoDetTOFCorr && m_tofCorrType == NoneCorrect)
+    {
+      // No TOF correction and skip spectrum only if TOF correction is required
+      g_log.notice("By user's choice, No spectrum will be skipped even if it has no detector.");
+    }
+    else
+    {
+      stringstream msgss;
+      size_t numskipspec = 0;
+      size_t numeventsskip = 0;
+
+      for (size_t i = 0; i < numhist; ++i)
+      {
+        bool skip = false;
+
+        // Access detector of the spectrum
+        try
+        {
+          IDetector_const_sptr tempdet = m_eventWS->getDetector(i);
+          if (!tempdet)
+            skip = true;
+        }
+        catch (const Kernel::Exception::NotFoundError&)
+        {
+          // No detector found
+          skip = true;
+        }
+
+        // Output
+        if (skip)
+        {
+          m_vecSkip[i] = true;
+
+          ++ numskipspec;
+          const EventList& elist = m_eventWS->getEventList(i);
+          numeventsskip += elist.getNumberEvents();
+          msgss << i;
+          if (numskipspec % 10 == 0)
+            msgss << "\n";
+          else
+            msgss << ",";
+        }
+
+      } // ENDFOR
+
+      if (numskipspec > 0)
+      {
+        g_log.warning() << "There are " << numskipspec << " spectra that do not have detectors. "
+                        << "They will be skipped during filtering. There are total " << numeventsskip
+                        << " events in those spectra. \nList of these specta is as below:\n"
+                        << msgss.str() << "\n";
+      }
+      else
+      {
+        g_log.notice("There is no spectrum that does not have detectors.");
+      }
+
+    } // END-IF-ELSE
+
+    return;
   }
 
+
   //----------------------------------------------------------------------------------------------
   /** Convert SplitterWorkspace object to TimeSplitterType (sorted vector)
    *  and create a map for all workspace group number
@@ -456,11 +547,11 @@ namespace Algorithms
         declareProperty(new API::WorkspaceProperty<DataObjects::EventWorkspace>(
                           propertynamess.str(), wsname.str(), Direction::Output), "Output");
         setProperty(propertynamess.str(), optws);
-	AnalysisDataService::Instance().addOrReplace(wsname.str(), optws);
+        AnalysisDataService::Instance().addOrReplace(wsname.str(), optws);
 
         ++ numoutputws;
 
-        g_log.debug() << "[DB9141] Created output Workspace of group = " << wsgroup << "  Property Name = "
+        g_log.debug() << "Created output Workspace of group = " << wsgroup << "  Property Name = "
                       << propertynamess.str() << " Workspace name = " << wsname.str()
                       << " with Number of events = " << optws->getNumberEvents() << "\n";
 
@@ -538,20 +629,23 @@ namespace Algorithms
     size_t numhist = m_eventWS->getNumberHistograms();
     for (size_t i = 0; i < numhist; ++i)
     {
-      IComponent_const_sptr tmpdet = boost::dynamic_pointer_cast<const IComponent>(m_eventWS->getDetector(i));
-      double l2 = instrument->getDistance(*tmpdet);
+      if (!m_vecSkip[i])
+      {
+        IComponent_const_sptr tmpdet = boost::dynamic_pointer_cast<const IComponent>(m_eventWS->getDetector(i));
+        double l2 = instrument->getDistance(*tmpdet);
 
-      double corrfactor = (l1)/(l1+l2);
+        double corrfactor = (l1)/(l1+l2);
 
-      m_detTofOffsets[i] = corrfactor;
-      corrws->dataY(i)[0] = corrfactor;
+        m_detTofOffsets[i] = corrfactor;
+        corrws->dataY(i)[0] = corrfactor;
+      }
     }
 
     return;
   }
 
   //----------------------------------------------------------------------------------------------
-  /**
+  /** Calculate TOF correction for direct geometry inelastic instrument
     * Time = T_pulse + TOF*0 + L1/sqrt(E*2/m)
     */
   void FilterEvents::setupDirectTOFCorrection(API::MatrixWorkspace_sptr corrws)
@@ -599,7 +693,7 @@ namespace Algorithms
   }
 
   //----------------------------------------------------------------------------------------------
-  /**
+  /** Calculate TOF correction for indirect geometry inelastic instrument
     * Time = T_pulse + TOF - L2/sqrt(E_fix * 2 * meV / mass)
     */
   void FilterEvents::setupIndirectTOFCorrection(API::MatrixWorkspace_sptr corrws)
@@ -620,58 +714,61 @@ namespace Algorithms
 
     for (size_t i = 0; i < numhist; ++i)
     {
-      double shift;
-
-      IDetector_const_sptr det = m_eventWS->getDetector(i);
-      if (!det->isMonitor())
+      if (!m_vecSkip[i])
       {
-        // Get E_fix
-        double efix = 0.;
-        try
+        double shift;
+        IDetector_const_sptr det = m_eventWS->getDetector(i);
+        if (!det->isMonitor())
         {
-          Parameter_sptr par = pmap.getRecursive(det.get(),"Efixed");
-          if (par)
+          // Get E_fix
+          double efix = 0.;
+          try
           {
-            efix = par->value<double>();
-            g_log.debug() << "Detector: " << det->getID() << " of spectrum " << i << " EFixed: " << efix << "\n";
+            Parameter_sptr par = pmap.getRecursive(det.get(),"Efixed");
+            if (par)
+            {
+              efix = par->value<double>();
+              g_log.debug() << "Detector: " << det->getID() << " of spectrum " << i << " EFixed: " << efix << "\n";
+            }
+            else
+            {
+              g_log.warning() << "Detector: " << det->getID() << " of spectrum " << i << " does not have EFixed set up."
+                              << "\n";
+            }
           }
-          else
+          catch (std::runtime_error&)
           {
-            g_log.warning() << "Detector: " << det->getID() << " of spectrum " << i << " does not have EFixed set up."
-                            << "\n";
+            // Throws if a DetectorGroup, use single provided value
+            stringstream errmsg;
+            errmsg << "Inelastic instrument detector " << det->getID() << " of spectrum " << i
+                   << " does not have EFixed ";
+            throw runtime_error(errmsg.str());
           }
+
+          // Get L2
+          double l2 = det->getPos().distance(samplepos);
+
+          // Calculate shift
+          shift = -1. * l2 / sqrt(efix * twomev_d_mass);
+
+          g_log.notice() << "Detector " << i << ": " << "L2 = " << l2 << ", EFix = " << efix << ", Shift = " << shift << "\n";
         }
-        catch (std::runtime_error&)
+        else
         {
-          // Throws if a DetectorGroup, use single provided value
-          stringstream errmsg;
-          errmsg << "Inelastic instrument detector " << det->getID() << " of spectrum " << i
-                 << " does not have EFixed ";
-          throw runtime_error(errmsg.str());
-        }
+          // Monitor:
+          g_log.warning() << "Spectrum " << i << " contains detector " << det->getID() << " is a monitor. " << "\n";
 
-        // Get L2
-        double l2 = det->getPos().distance(samplepos);
+          shift = 0.;
+        }
 
-        // Calculate shift
-        shift = -1. * l2 / sqrt(efix * twomev_d_mass);
+        // Set up the shifts
+        m_detTofOffsets[i] = 1.0;
+        m_detTofShifts[i] = shift;
 
-        g_log.notice() << "Detector " << i << ": " << "L2 = " << l2 << ", EFix = " << efix << ", Shift = " << shift << "\n";
-      }
-      else
-      {
-        // Monitor:
-        g_log.warning() << "Spectrum " << i << " contains detector " << det->getID() << " is a monitor. " << "\n";
+        corrws->dataY(i)[0] = 1.0;
+        corrws->dataY(i)[1] = shift;
 
-        shift = 0.;
       }
-
-      // Set up the shifts
-      m_detTofOffsets[i] = 1.0;
-      m_detTofShifts[i] = shift;
-
-      corrws->dataY(i)[0] = 1.0;
-      corrws->dataY(i)[1] = shift;
     } // ENDOF (all spectra)
 
     return;
@@ -857,33 +954,37 @@ namespace Algorithms
     {
       PARALLEL_START_INTERUPT_REGION
 
-      // Get the output event lists (should be empty) to be a map
-      std::map<int, DataObjects::EventList* > outputs;
-      PARALLEL_CRITICAL(build_elist)
+      // Filter the non-skipped
+      if (!m_vecSkip[iws])
       {
-        for (wsiter = m_outputWS.begin(); wsiter != m_outputWS.end(); ++ wsiter)
+        // Get the output event lists (should be empty) to be a map
+        std::map<int, DataObjects::EventList* > outputs;
+        PARALLEL_CRITICAL(build_elist)
         {
-          int index = wsiter->first;
-          DataObjects::EventList* output_el = wsiter->second->getEventListPtr(iws);
-          outputs.insert(std::make_pair(index, output_el));
+          for (wsiter = m_outputWS.begin(); wsiter != m_outputWS.end(); ++ wsiter)
+          {
+            int index = wsiter->first;
+            DataObjects::EventList* output_el = wsiter->second->getEventListPtr(iws);
+            outputs.insert(std::make_pair(index, output_el));
+          }
         }
-      }
 
-      // Get a holder on input workspace's event list of this spectrum
-      const DataObjects::EventList& input_el = m_eventWS->getEventList(iws);
+        // Get a holder on input workspace's event list of this spectrum
+        const DataObjects::EventList& input_el = m_eventWS->getEventList(iws);
 
-      // Perform the filtering (using the splitting function and just one output)
-      if (mFilterByPulseTime)
-      {
-        input_el.splitByPulseTime(m_splitters, outputs);
-      }
-      else if (m_tofCorrType != NoneCorrect)
-      {
-        input_el.splitByFullTime(m_splitters, outputs, true, m_detTofOffsets[iws], m_detTofShifts[iws]);
-      }
-      else
-      {
-        input_el.splitByFullTime(m_splitters, outputs, false, 1.0, 0.0);
+        // Perform the filtering (using the splitting function and just one output)
+        if (mFilterByPulseTime)
+        {
+          input_el.splitByPulseTime(m_splitters, outputs);
+        }
+        else if (m_tofCorrType != NoneCorrect)
+        {
+          input_el.splitByFullTime(m_splitters, outputs, true, m_detTofOffsets[iws], m_detTofShifts[iws]);
+        }
+        else
+        {
+          input_el.splitByFullTime(m_splitters, outputs, false, 1.0, 0.0);
+        }
       }
 
       PARALLEL_END_INTERUPT_REGION
@@ -961,44 +1062,48 @@ namespace Algorithms
     {
       PARALLEL_START_INTERUPT_REGION
 
-      // Get the output event lists (should be empty) to be a map
-      map<int, DataObjects::EventList* > outputs;
-      PARALLEL_CRITICAL(build_elist)
+      // Filter the non-skipped spectrum
+      if (!m_vecSkip[iws])
       {
-        for (wsiter = m_outputWS.begin(); wsiter != m_outputWS.end(); ++ wsiter)
+        // Get the output event lists (should be empty) to be a map
+        map<int, DataObjects::EventList* > outputs;
+        PARALLEL_CRITICAL(build_elist)
         {
-          int index = wsiter->first;
-          DataObjects::EventList* output_el = wsiter->second->getEventListPtr(iws);
-          outputs.insert(std::make_pair(index, output_el));
+          for (wsiter = m_outputWS.begin(); wsiter != m_outputWS.end(); ++ wsiter)
+          {
+            int index = wsiter->first;
+            DataObjects::EventList* output_el = wsiter->second->getEventListPtr(iws);
+            outputs.insert(std::make_pair(index, output_el));
+          }
         }
-      }
 
-      // Get a holder on input workspace's event list of this spectrum
-      const DataObjects::EventList& input_el = m_eventWS->getEventList(iws);
+        // Get a holder on input workspace's event list of this spectrum
+        const DataObjects::EventList& input_el = m_eventWS->getEventList(iws);
 
-      bool printdetail = false;
-      if (m_useDBSpectrum)
-          printdetail = (iws == static_cast<int64_t>(m_dbWSIndex));
+        bool printdetail = false;
+        if (m_useDBSpectrum)
+            printdetail = (iws == static_cast<int64_t>(m_dbWSIndex));
 
-      // Perform the filtering (using the splitting function and just one output)
-      std::string logmessage("");
-      if (mFilterByPulseTime)
-      {
-        throw runtime_error("It is not a good practice to split fast event by pulse time. ");
-      }
-      else if (m_tofCorrType != NoneCorrect)
-      {
-        logmessage = input_el.splitByFullTimeMatrixSplitter(m_vecSplitterTime, m_vecSplitterGroup, outputs,
-                                                            true, m_detTofOffsets[iws], m_detTofShifts[iws]);
-      }
-      else
-      {
-        logmessage = input_el.splitByFullTimeMatrixSplitter(m_vecSplitterTime, m_vecSplitterGroup, outputs,
-                                                            false, 1.0, 0.0);
-      }
+        // Perform the filtering (using the splitting function and just one output)
+        std::string logmessage("");
+        if (mFilterByPulseTime)
+        {
+          throw runtime_error("It is not a good practice to split fast event by pulse time. ");
+        }
+        else if (m_tofCorrType != NoneCorrect)
+        {
+          logmessage = input_el.splitByFullTimeMatrixSplitter(m_vecSplitterTime, m_vecSplitterGroup, outputs,
+                                                              true, m_detTofOffsets[iws], m_detTofShifts[iws]);
+        }
+        else
+        {
+          logmessage = input_el.splitByFullTimeMatrixSplitter(m_vecSplitterTime, m_vecSplitterGroup, outputs,
+                                                              false, 1.0, 0.0);
+        }
 
-      if (printdetail)
-        g_log.notice(logmessage);
+        if (printdetail)
+          g_log.notice(logmessage);
+      }
 
       PARALLEL_END_INTERUPT_REGION
     } // END FOR i = 0
diff --git a/Code/Mantid/Framework/Algorithms/src/GenerateEventsFilter.cpp b/Code/Mantid/Framework/Algorithms/src/GenerateEventsFilter.cpp
index 79687460dd53731e965f680f2bfec5e5f52c580e..68c05a55e76e8872bd17b26d22882fb7e45bf586 100644
--- a/Code/Mantid/Framework/Algorithms/src/GenerateEventsFilter.cpp
+++ b/Code/Mantid/Framework/Algorithms/src/GenerateEventsFilter.cpp
@@ -454,9 +454,15 @@ namespace Algorithms
 
     //  Clear duplicate value
     if (m_dblLog)
+    {
+      g_log.debug("Attempting to remove duplicates in double series log.");
       m_dblLog->eliminateDuplicates();
+    }
     else
+    {
+      g_log.debug("Attempting to remove duplicates in integer series log.");
       m_intLog->eliminateDuplicates();
+    }
 
     // Process input properties related to filter with log value
     double minvalue = this->getProperty("MinimumLogValue");
@@ -523,6 +529,12 @@ namespace Algorithms
                << " is larger than maximum log value " << maxvalue;
         throw runtime_error(errmsg.str());
       }
+      else
+      {
+        g_log.debug() << "Filter by log value: min = " << minvalue << ", max = " << maxvalue
+                      << ", process single value? = " << toProcessSingleValueFilter
+                      << ", delta value = " << deltaValue << "\n";
+      }
 
       // Filter double value log
       if (toProcessSingleValueFilter)
@@ -564,18 +576,16 @@ namespace Algorithms
                << " is larger than maximum log value " << maxvalue;
         throw runtime_error(errmsg.str());
       }
+      else
+      {
+        g_log.information() << "Generate event-filter for integer log: min = " << minvaluei << ", "
+                            << "max = " << maxvaluei << "\n";
+      }
 
       // Split along log
       DateAndTime runendtime = m_dataWS->run().endTime();
+      processIntegerValueFilter(minvaluei, maxvaluei, filterIncrease, filterDecrease, runendtime);
 
-      if (m_forFastLog)
-      {
-        throw runtime_error("It is supported to generate FastLog for integer timeseries log yet. ");
-      }
-      else
-      {
-        processIntegerValueFilter(minvaluei, maxvaluei, filterIncrease, filterDecrease, runendtime);
-      }
     } // ENDIFELSE: Double/Integer Log
 
     g_log.information() << "Minimum value = " << minvalue <<  ", " << "maximum value = "
@@ -594,27 +604,24 @@ namespace Algorithms
   void GenerateEventsFilter::processSingleValueFilter(double minvalue, double maxvalue,
                                                       bool filterincrease, bool filterdecrease)
   {
-    // 1. Validity & value
+    // Get parameters time-tolerance and log-boundary
     double timetolerance = this->getProperty("TimeTolerance");
     int64_t timetolerance_ns = static_cast<int64_t>(timetolerance*m_timeUnitConvertFactorToNS);
 
     std::string logboundary = this->getProperty("LogBoundary");
     transform(logboundary.begin(), logboundary.end(), logboundary.begin(), ::tolower);
 
-    // 2. Generate filter
-    std::vector<Kernel::SplittingInterval> splitters;
+    // Generate filter
+    // std::vector<Kernel::SplittingInterval> splitters;
     int wsindex = 0;
-    makeFilterByValue(splitters, minvalue, maxvalue, static_cast<double>(timetolerance_ns)*1.0E-9,
-        logboundary.compare("centre")==0,
-        filterincrease, filterdecrease, m_startTime, m_stopTime, wsindex);
+    makeFilterBySingleValue(minvalue, maxvalue, static_cast<double>(timetolerance_ns)*1.0E-9,
+                            logboundary.compare("centre")==0,
+                            filterincrease, filterdecrease, m_startTime, m_stopTime, wsindex);
 
-    // 3. Add to output
-    for (size_t isp = 0; isp < splitters.size(); isp ++)
-    {
-      m_splitWS->addSplitter(splitters[isp]);
-    }
+    // Create information table workspace
+    if (!m_filterInfoWS)
+      throw runtime_error("m_filterInfoWS has not been initialized.");
 
-    // 4. Add information
     API::TableRow row = m_filterInfoWS->appendRow();
     std::stringstream ss;
     ss << "Log " << m_dblLog->name() << " From " << minvalue << " To " << maxvalue << "  Value-change-direction ";
@@ -704,10 +711,10 @@ namespace Algorithms
          mit != indexwsindexmap.end(); ++mit)
     {
       dbsplitss << "Index " << mit->first << ":  WS-group = " << mit->second
-              << ". Log value range: " << logvalueranges[mit->first*2] << ", "
-              << logvalueranges[mit->first*2+1] << ".\n";
+              << ". Log value range: [" << logvalueranges[mit->first*2] << ", "
+              << logvalueranges[mit->first*2+1] << ").\n";
     }
-    g_log.debug(dbsplitss.str());
+    g_log.information(dbsplitss.str());
 
     // Check split interval obtained wehther is with valid size
     if (logvalueranges.size() < 2)
@@ -760,7 +767,7 @@ namespace Algorithms
    * SINGLE log values >= min and < max. Creates SplittingInterval's where
    * times match the log values, and going to index==0.
    *
-   * @param split :: Splitter that will be filled.
+   *(removed) split :: Splitter that will be filled.
    * @param min :: Min value.
    * @param max :: Max value.
    * @param TimeTolerance :: Offset added to times in seconds.
@@ -771,86 +778,69 @@ namespace Algorithms
    * @param stopTime :: Stop time.
    * @param wsindex :: Workspace index.
    */
-  void GenerateEventsFilter::makeFilterByValue(TimeSplitterType &split, double min, double max, double TimeTolerance,
-                                               bool centre, bool filterIncrease, bool filterDecrease,
-                                               DateAndTime startTime, Kernel::DateAndTime stopTime, int wsindex)
+  void GenerateEventsFilter::makeFilterBySingleValue(double min, double max, double TimeTolerance,
+                                                     bool centre, bool filterIncrease, bool filterDecrease,
+                                                     DateAndTime startTime, Kernel::DateAndTime stopTime, int wsindex)
   {
-    // 1. Do nothing if the log is empty.
+    // Do nothing if the log is empty.
     if (m_dblLog->size() == 0)
     {
       g_log.warning() << "There is no entry in this property " << this->name() << "\n";
       return;
     }
 
-    // 2. Do the rest
+    // Clear splitters in vector format
+    m_vecSplitterGroup.clear();
+    m_vecSplitterTime.clear();
+
+    // Initialize control parameters
     bool lastGood = false;
     bool isGood = false;;
     time_duration tol = DateAndTime::durationFromSeconds( TimeTolerance );
     int numgood = 0;
-    DateAndTime lastTime, t;
+    DateAndTime lastTime, currT;
     DateAndTime start, stop;
 
     size_t progslot = 0;
+    string info("");
 
     for (int i = 0; i < m_dblLog->size(); i ++)
     {
-      lastTime = t;
+      lastTime = currT;
       //The new entry
-      t = m_dblLog->nthTime(i);
-      double val = m_dblLog->nthValue(i);
+      currT = m_dblLog->nthTime(i);
 
-      // A good value?
-      if (filterIncrease && filterDecrease)
-      {
-        // a) Including both sides
-        isGood = ((val >= min) && (val < max)) && t >= startTime && t <= stopTime;
-      }
-      else if (filterIncrease)
-      {
-        if (i == 0)
-          isGood = false;
-        else
-          isGood = ((val >= min) && (val < max)) && t >= startTime && t <= stopTime && val-m_dblLog->nthValue(i-1) > 0;
-      }
-      else if (filterDecrease)
-      {
-        if (i == 0)
-          isGood = false;
-        else
-          isGood = ((val >= min) && (val < max)) && t >= startTime && t <= stopTime && val-m_dblLog->nthValue(i-1) < 0;
-      }
-      else
-      {
-        g_log.error("Neither increasing nor decreasing is selected.  It is empty!");
-      }
 
+      // A good value?
+      isGood = identifyLogEntry(i, currT, lastGood, min, max, startTime, stopTime, filterIncrease, filterDecrease);
       if (isGood)
         numgood++;
 
+      // Log status (time/value/value changing direciton) is changed
       if (isGood != lastGood)
       {
         //We switched from bad to good or good to bad
-
         if (isGood)
         {
           //Start of a good section
           if (centre)
-            start = t - tol;
+            start = currT - tol;
           else
-            start = t;
+            start = currT;
         }
         else
         {
           //End of the good section
           if (centre)
           {
-            stop = t - tol;
+            stop = currT - tol;
           }
           else
           {
-            stop = t;
+            stop = currT;
           }
-          split.push_back( SplittingInterval(start, stop, wsindex) );
+
+          addNewTimeFilterSplitter(start, stop, wsindex, info);
 
           //Reset the number of good ones, for next time
           numgood = 0;
@@ -873,16 +863,61 @@ namespace Algorithms
     {
       //The log ended on "good" so we need to close it using the last time we found
       if (centre)
-        stop = t - tol;
+        stop = currT - tol;
       else
-        stop = t;
-      split.push_back( SplittingInterval(start, stop, wsindex) );
+        stop = currT;
+      addNewTimeFilterSplitter(start, stop, wsindex, info);
       numgood = 0;
     }
 
     return;
   }
 
+  //----------------------------------------------------------------------------------------------
+  /** Identify a log entry whether it can be included in the splitter for filtering by single log value
+    * - Direction: direction of changing value will be determined by the current log entry and next entry
+    *              because the boundary should be set at the first value with new direction (as well as last value
+    *              with the old direction)
+    */
+  bool GenerateEventsFilter::identifyLogEntry(const int& index, const Kernel::DateAndTime& currT, const bool& lastgood,
+                                              const double& minvalue, const double& maxvalue,
+                                              const Kernel::DateAndTime& startT, const Kernel::DateAndTime& stopT,
+                                              const bool& filterIncrease, const bool& filterDecrease)
+  {
+    double val = m_dblLog->nthValue(index);
+
+    // Identify by time and value
+    bool isgood =(val >= minvalue && val < maxvalue) && (currT >= startT && currT < stopT);
+
+    // Consider direction: not both (i.e., not increase or not decrease)
+    if ( isgood && (!filterIncrease || !filterDecrease) )
+    {
+      int numlogentries = m_dblLog->size();
+      double diff;
+      if (index < numlogentries-1)
+      {
+        // For a non-last log entry
+        diff = m_dblLog->nthValue(index+1) - val;
+      }
+      else
+      {
+        // Last log entry: follow the last direction
+        diff = val - m_dblLog->nthValue(index-1);
+      }
+
+      if (diff > 0 && filterIncrease)
+        isgood = true;
+      else if (diff < 0 && filterDecrease)
+        isgood = true;
+      else if (diff == 0)
+        isgood = lastgood;
+      else
+        isgood = false;
+    }
+
+    return isgood;
+  }
+
   //-----------------------------------------------------------------------------------------------
   /** Fill a TimeSplitterType that will filter the events by matching
    * SINGLE log values >= min and < max. Creates SplittingInterval's where
@@ -1148,6 +1183,10 @@ namespace Algorithms
                         << m_dblLog->nthTime(istart) << ", " << m_dblLog->nthTime(iend) << "\n";
 
     DateAndTime laststoptime(0);
+    int lastlogindex = m_dblLog->size()-1;
+
+    int prevDirection = determineChangingDirection(istart);
+
     for (int i = istart; i <= iend; i ++)
     {
       // Initialize status flags and new entry
@@ -1159,7 +1198,7 @@ namespace Algorithms
       double currValue = m_dblLog->nthValue(i);
 
       // Filter out by time and direction (optional)
-      bool intime = false;
+      bool intime = true;
       if (currTime < startTime)
       {
         // case i.  Too early, do nothing
@@ -1175,18 +1214,34 @@ namespace Algorithms
           createsplitter = true;
         }
       }
-      else
-      {
-        // case iii. In the range to generate filters
-        intime = true;
-      }
 
       // Check log within given time range
       bool newsplitter = false; // Flag to start a new split in this loop
 
+      // Determine direction
+      int direction = 0;
+      if (i < lastlogindex)
+      {
+        // Not the last log entry
+        double diff = m_dblLog->nthValue(i+1)-m_dblLog->nthValue(i);
+        if (diff > 0)
+          direction = 1;
+        else if (diff < 0)
+          direction = -1;
+        else
+          direction = prevDirection;
+      }
+      else
+      {
+        // Last log entry: use the previous direction
+        direction = prevDirection;
+      }
+      prevDirection = direction;
+
+      // Examine log value for filter
       if (intime)
       {
-        // Determine direction
+        // Determine whether direction is fine
         bool correctdir = true;
         if (filterIncrease && filterDecrease)
         {
@@ -1196,36 +1251,35 @@ namespace Algorithms
         else
         {
           // Filter out one direction
-          int direction = 0;
-          if ( m_dblLog->nthValue(i)-m_dblLog->nthValue(i-1) > 0)
-            direction = 1;
-          else
-            direction = -1;
           if (filterIncrease && direction > 0)
             correctdir = true;
           else if (filterDecrease && direction < 0)
             correctdir = true;
+          else if (direction == 0)
+            throw runtime_error("Direction is not determined.");
           else
             correctdir = false;
-
-          // Condition to generate a Splitter (close parenthesis)
-          if (!correctdir && start.totalNanoseconds() > 0)
-          {
-            stop = currTime;
-            createsplitter = true;
-          }
         } // END-IF-ELSE: Direction
 
-        // Check this value whether it falls into any range
+        // Treat the log entry based on: changing direction (+ time range)
         if (correctdir)
         {
+          // Check this value whether it falls into any range
           size_t index = searchValue(logvalueranges, currValue);
+
+          if (g_log.is(Logger::Priority::PRIO_DEBUG))
           {
             stringstream dbss;
-            dbss << "DBx257 Examine Log Index " << i << ", Value = " << currValue
+            dbss << "[DBx257] Examine Log Index " << i << ", Value = " << currValue
                  << ", Data Range Index = " << index << "; "
                  << "Group Index = " << indexwsindexmap[index/2]
-                 << " (log value range vector size = " << logvalueranges.size() << ").";
+                 << " (log value range vector size = " << logvalueranges.size() << "): ";
+			if( index == 0 )
+              dbss << logvalueranges[index] << ", " << logvalueranges[index+1];
+			else if( index == logvalueranges.size() )
+              dbss << logvalueranges[index-1] << ", " << logvalueranges[index];
+			else
+              dbss << logvalueranges[index-1] << ", " << logvalueranges[index] << ", " << logvalueranges[index+1];
             g_log.debug(dbss.str());
           }
 
@@ -1245,19 +1299,19 @@ namespace Algorithms
 
               if (currindex != lastindex && start.totalNanoseconds() == 0)
               {
-                // i.   A new region!
+                // Group index is different from last and start is not set up: new a region!
                 newsplitter = true;
               }
               else if (currindex != lastindex && start.totalNanoseconds() > 0)
               {
-                // ii.  Time to close a region and new a region
+                // Group index is different from last and start is set up:  close a region and new a region
                 stop = currTime;
                 createsplitter = true;
                 newsplitter = true;
               }
               else if (currindex == lastindex && start.totalNanoseconds() > 0)
               {
-                // iii. Still in the same zone
+                // Still of the group index
                 if (i == iend)
                 {
                   // Last entry in this section of log.  Need to flag to close the pair
@@ -1273,7 +1327,7 @@ namespace Algorithms
               }
               else
               {
-                // iv.  It is impossible
+                // An impossible situation
                 std::stringstream errmsg;
                 double lastvalue =  m_dblLog->nthValue(i-1);
                 errmsg << "Impossible to have currindex == lastindex == " << currindex
@@ -1281,8 +1335,6 @@ namespace Algorithms
                        << currValue << "\t, Index = " << index
                        << " in range " << logvalueranges[index] << ", " << logvalueranges[index+1]
                        << "; Last value = " << lastvalue;
-
-                g_log.error(errmsg.str());
                 throw std::runtime_error(errmsg.str());
               }
             } // [In-bound: Inside interval]
@@ -1290,11 +1342,14 @@ namespace Algorithms
             {
               // [Situation] Fall between interval (which is not likley happen)
               currindex = -1;
+              g_log.warning() << "Not likely to happen! Current value = " << currValue
+                              << " is  within value range but its index = " << index
+                              << " has no map to group index. " << "\n";
               if (start.totalNanoseconds() > 0)
               {
                 // Close the interval pair if it has been started.
                 stop = currTime;
-                createsplitter = true;
+                createsplitter = true;                
               }
             } // [In-bound: Between interval]
           }
@@ -1315,8 +1370,16 @@ namespace Algorithms
         {
           // Log Index i falls out b/c out of wrong direction
           currindex = -1;
+
+          // Condition to generate a Splitter (close parenthesis)
+          if (!correctdir && start.totalNanoseconds() > 0)
+          {
+            stop = currTime;
+            createsplitter = true;
+          }
+
         }
-      }
+      } // ENDIF (log entry in specified time)
       else
       {
         // Log Index i falls out b/c out of time range...
@@ -1334,10 +1397,7 @@ namespace Algorithms
       }
 
       // e) Start new splitter: have to be here due to start cannot be updated before a possible splitter generated
-      if (newsplitter)
-      {
-        start = currTime;
-      }
+      if (newsplitter) start = currTime;
 
       // f) Break
       if (breakloop)
@@ -1384,14 +1444,9 @@ namespace Algorithms
       singlevaluemode = false;
 
       double deltadbl = getProperty("LogValueInterval");
-      if (isEmpty(deltadbl))
-      {
-        delta = maxvalue-minvalue;
-      }
-      else
-      {
-        delta = static_cast<int>(deltadbl+0.5);
-      }
+      if (isEmpty(deltadbl)) delta = maxvalue-minvalue+1;
+      else delta = static_cast<int>(deltadbl+0.5);
+
       if (delta <= 0)
       {
         stringstream errss;
@@ -1399,12 +1454,14 @@ namespace Algorithms
               << "Current input is " << deltadbl << ".";
         throw runtime_error(errss.str());
       }
+      else
+        g_log.information() << "Generate event-filter by integer log: step = " << delta << "\n";
     }
 
     // Search along log to generate splitters
     size_t numlogentries = m_intLog->size();
-    vector<DateAndTime> times = m_intLog->timesAsVector();
-    vector<int> values = m_intLog->valuesAsVector();
+    vector<DateAndTime> vecTimes = m_intLog->timesAsVector();
+    vector<int> vecValue = m_intLog->valuesAsVector();
 
     time_duration timetol = DateAndTime::durationFromSeconds( m_logTimeTolerance*m_timeUnitConvertFactorToNS*1.0E-9);
     int64_t timetolns = timetol.total_nanoseconds();
@@ -1417,15 +1474,15 @@ namespace Algorithms
 
     for (size_t i = 0; i < numlogentries; ++i)
     {
-      int currvalue = values[i];
+      int currvalue = vecValue[i];
       int currgroup = -1;
 
       // Determine whether this log value is allowed and then the ws group it belonged to.
       if (currvalue >= minvalue && currvalue <= maxvalue )
       {
         // Log value is in specified range
-        if ((i == 0) || (i >= 1 && ((filterIncrease && values[i] >= values[i-1]) ||
-                                    (filterDecrease && values[i] <= values[i-1]))))
+        if ((i == 0) || (i >= 1 && ((filterIncrease && vecValue[i] >= vecValue[i-1]) ||
+                                    (filterDecrease && vecValue[i] <= vecValue[i-1]))))
         {
           // First entry (regardless direction) and other entries considering change of value
           if (singlevaluemode)
@@ -1446,9 +1503,9 @@ namespace Algorithms
         // previous log is in allowed region.  but this one is not.  create a splitter
         if (splitstarttime.totalNanoseconds() == 0) throw runtime_error("Programming logic error.");
 
-        makeSplitterInVector(m_vecSplitterTime, m_vecSplitterGroup, splitstarttime, times[i], pregroup,
+        makeSplitterInVector(m_vecSplitterTime, m_vecSplitterGroup, splitstarttime, vecTimes[i], pregroup,
                              timetolns, laststoptime);
-        laststoptime = times[i];
+        laststoptime = vecTimes[i];
 
         splitstarttime = DateAndTime(0);
         statuschanged = true;
@@ -1456,7 +1513,7 @@ namespace Algorithms
       else if (pregroup < 0 && currgroup >= 0)
       {
         // previous log is not allowed, but this one is.  this is the start of a new splitter
-        splitstarttime = times[i];
+        splitstarttime = vecTimes[i];
         statuschanged = true;
       }
       else if (currgroup >= 0 && pregroup != currgroup)
@@ -1464,11 +1521,11 @@ namespace Algorithms
         // migrated to a new region
         if (splitstarttime.totalNanoseconds() == 0)
           throw runtime_error("Programming logic error (1).");
-        makeSplitterInVector(m_vecSplitterTime, m_vecSplitterGroup, splitstarttime, times[i], pregroup,
+        makeSplitterInVector(m_vecSplitterTime, m_vecSplitterGroup, splitstarttime, vecTimes[i], pregroup,
                              timetolns, laststoptime);
-        laststoptime = times[i];
+        laststoptime = vecTimes[i];
 
-        splitstarttime = times[i];
+        splitstarttime = vecTimes[i];
         statuschanged = true;
       }
       else
@@ -1528,8 +1585,8 @@ namespace Algorithms
       }
     }
 
-    g_log.notice() << "Integer log " << m_intLog->name() << ": Number of splitters = " << m_splitters.size()
-                   << ", Number of split info = " << m_filterInfoWS->rowCount() << ".\n";
+    g_log.information() << "Integer log " << m_intLog->name() << ": Number of splitters = " << m_vecSplitterGroup.size()
+                        << ", Number of split info = " << m_filterInfoWS->rowCount() << ".\n";
 
     return;
   }
@@ -1556,12 +1613,67 @@ namespace Algorithms
     // Binary search
     size_t index = static_cast<size_t>(std::lower_bound(sorteddata.begin(), sorteddata.end(), value)
                                        - sorteddata.begin());
-    if (index >= 1)
+
+    if (value < sorteddata[index] && index%2 == 1)
+    {
+      // value to search is less than the boundary: use the index of the one just smaller to the value to search
       -- index;
+    }
+    else if (value == sorteddata[index] && index%2 == 1)
+    {
+      // value to search is on the boudary, i..e, a,b,b,c,c,....,x,x,y
+      ++ index;
+
+      // return if out of range
+      if (index == sorteddata.size()) return outrange;
+    }
 
     return index;
   }
 
+  //----------------------------------------------------------------------------------------------
+  /** Determine starting value changing direction
+    */
+  int  GenerateEventsFilter::determineChangingDirection(int startindex)
+  {
+    int direction = 0;
+
+    // Search to earlier entries
+    int index = startindex;
+    while (direction == 0 && index > 0)
+    {
+      double diff = m_dblLog->nthValue(index) - m_dblLog->nthValue(index-1);
+      if (diff > 0)
+        direction = 1;
+      else if (diff < 0)
+        direction = -1;
+
+      -- index;
+    }
+
+    if (direction != 0)
+      return direction;
+
+    // Search to later entries
+    index = startindex;
+    int maxindex = m_dblLog->size()-1;
+    while (direction == 0 && index < maxindex)
+    {
+      double diff = m_dblLog->nthValue(index+1) - m_dblLog->nthValue(index);
+      if (diff > 0)
+        direction = 1;
+      else if (diff < 0)
+        direction = -1;
+
+      ++ index;
+    }
+
+    if (direction == 0)
+      throw runtime_error("Sample log is flat.  Use option 'Both' instead! ");
+
+    return direction;
+  }
+
   //----------------------------------------------------------------------------------------------
   /** Add a new splitter to vector of splitters.  It is used by FilterByTime only.
     */
@@ -1606,8 +1718,11 @@ namespace Algorithms
     }
 
     // Information
-    API::TableRow row = m_filterInfoWS->appendRow();
-    row << wsindex << info;
+    if (info.size() > 0)
+    {
+      API::TableRow row = m_filterInfoWS->appendRow();
+      row << wsindex << info;
+    }
 
     return;
   }
diff --git a/Code/Mantid/Framework/Algorithms/src/GeneratePythonScript.cpp b/Code/Mantid/Framework/Algorithms/src/GeneratePythonScript.cpp
index d1f2cf7dacbafde1491ab7091323a19fc0a9d5cd..475f479792d49dc587ef313c4b4d7655035e259d 100644
--- a/Code/Mantid/Framework/Algorithms/src/GeneratePythonScript.cpp
+++ b/Code/Mantid/Framework/Algorithms/src/GeneratePythonScript.cpp
@@ -1,4 +1,5 @@
 #include "MantidAlgorithms/GeneratePythonScript.h"
+#include "MantidKernel/ListValidator.h"
 #include "MantidKernel/System.h"
 #include "MantidAPI/FileProperty.h"
 #include "MantidAPI/AlgorithmManager.h"
@@ -34,7 +35,14 @@ void GeneratePythonScript::init()
   "The name of the file into which the workspace history will be generated.");
   declareProperty("ScriptText", std::string(""), "Saves the history of the workspace to a variable.", Direction::Output);
 
-  declareProperty("UnrollAll", false, "Unroll all algorithms to show just there child algorithms.", Direction::Input);
+  declareProperty("UnrollAll", false, "Unroll all algorithms to show just their child algorithms.", Direction::Input);
+
+  std::vector<std::string> saveVersions;
+  saveVersions.push_back("Specify Old");
+  saveVersions.push_back("Specify All");
+  saveVersions.push_back("Specify None");
+  declareProperty("SpecifyAlgorithmVersions","Specify Old",boost::make_shared<StringListValidator>(saveVersions),
+      "When to specify which algorithm version was used by Mantid.");
 }
 
 //----------------------------------------------------------------------------------------------
@@ -44,6 +52,7 @@ void GeneratePythonScript::exec()
 {
   const Workspace_const_sptr ws = getProperty("InputWorkspace");
   const bool unrollAll = getProperty("UnrollAll");
+  const std::string saveVersions = getProperty("SpecifyAlgorithmVersions");
 
   // Get the algorithm histories of the workspace.
   const WorkspaceHistory wsHistory = ws->getHistory();
@@ -55,7 +64,15 @@ void GeneratePythonScript::exec()
     view->unrollAll();
   }
 
-  ScriptBuilder builder(view);
+  std::string versionSpecificity;
+  if(saveVersions == "Specify Old")
+    versionSpecificity = "old";
+  else if(saveVersions == "Specify None")
+    versionSpecificity = "none";
+  else
+    versionSpecificity = "all";
+
+  ScriptBuilder builder(view, versionSpecificity);
   std::string generatedScript = "";
   generatedScript += "######################################################################\n";
   generatedScript += "#Python Script Generated by GeneratePythonScript Algorithm\n";
diff --git a/Code/Mantid/Framework/Algorithms/src/GetDetOffsetsMultiPeaks.cpp b/Code/Mantid/Framework/Algorithms/src/GetDetOffsetsMultiPeaks.cpp
index a69c5dfde6e629966234e923bee51d297dcd80e9..879070165dd0f43068cc784c06feddc18a6c4d23 100644
--- a/Code/Mantid/Framework/Algorithms/src/GetDetOffsetsMultiPeaks.cpp
+++ b/Code/Mantid/Framework/Algorithms/src/GetDetOffsetsMultiPeaks.cpp
@@ -495,7 +495,7 @@ namespace Algorithms
     fr.chi2 = -1;
 
     fr.fitSum = 0.0;
-    // fr.chisqSum = 0.0;
+    fr.chisqSum = 0.0;
 
     fr.peakPosFittedSize = 0.0;
 
diff --git a/Code/Mantid/Framework/Algorithms/src/MaxMin.cpp b/Code/Mantid/Framework/Algorithms/src/MaxMin.cpp
index a89b169f73e9d7b0e7ee655d37c777c693f2f7c1..329fe76a946268fe9efde307352bfb1785e7472c 100644
--- a/Code/Mantid/Framework/Algorithms/src/MaxMin.cpp
+++ b/Code/Mantid/Framework/Algorithms/src/MaxMin.cpp
@@ -104,7 +104,7 @@ void MaxMin::exec()
     else highit=std::find_if(lowit,X.end(),std::bind2nd(std::greater<double>(),m_MaxRange));
 
     // If range specified doesn't overlap with this spectrum then bail out
-    if ( lowit == X.end() || highit == X.begin() ) continue;
+    if ( lowit == X.end() || highit == X.begin() || lowit == highit ) continue;
 
     --highit; // Upper limit is the bin before, i.e. the last value smaller than MaxRange
 
diff --git a/Code/Mantid/Framework/Algorithms/src/PolarizationCorrection.cpp b/Code/Mantid/Framework/Algorithms/src/PolarizationCorrection.cpp
index 07da031bd8461013c8f7903b348d1535df3a5c39..7bdf7f89e56c7383a22675af3deb27090f17ff02 100644
--- a/Code/Mantid/Framework/Algorithms/src/PolarizationCorrection.cpp
+++ b/Code/Mantid/Framework/Algorithms/src/PolarizationCorrection.cpp
@@ -295,23 +295,28 @@ namespace Mantid
       const auto alpha = this->execPolynomialCorrection(ones, c_alpha); // Execute polynomial expression
       const auto ap = this->execPolynomialCorrection(ones, c_ap); // Execute polynomial expression
 
-      const auto A0 = Iaa * pp + ap * Ipa * rho * pp + ap * Iap * pp * alpha
-          + Ipp * ap * alpha * rho * pp;
+      const auto A0 = (Iaa + ap * Ipa * rho + ap * Iap * alpha + Ipp * ap * alpha * rho) * pp;
       const auto A1 = pp * Iaa;
       const auto A2 = pp * Iap;
       const auto A3 = ap * Iaa;
       const auto A4 = ap * Ipa;
-      const auto A5 = ap * alpha * Ipp;
-      const auto A6 = ap * alpha * Iap;
-      const auto A7 = pp * rho * Ipp;
-      const auto A8 = pp * rho * Ipa;
+      const auto apAlpha = ap * alpha;
+      const auto A5 = apAlpha * Ipp;
+      const auto A6 = apAlpha * Iap;
+      const auto ppRho = pp * rho;
+      const auto A7 = ppRho * Ipp;
+      const auto A8 = ppRho * Ipa;
 
       const auto D = pp * ap * (rho + alpha + 1.0 + rho * alpha);
-
-      const auto nIpp = (A0 - A1 + A2 - A3 + A4 + A5 - A6 + A7 - A8 + Ipp + Iaa - Ipa - Iap) / D;
-      const auto nIaa = (A0 + A1 - A2 + A3 - A4 - A5 + A6 - A7 + A8 + Ipp + Iaa - Ipa - Iap) / D;
-      const auto nIpa = (A0 - A1 + A2 + A3 - A4 - A5 + A6 + A7 - A8 - Ipp - Iaa + Ipa + Iap) / D;
-      const auto nIap = (A0 + A1 - A2 - A3 + A4 + A5 - A6 - A7 + A8 - Ipp - Iaa + Ipa + Iap) / D;
+      const auto IppPlusIaaMinusIpaMinusIap = Ipp + Iaa - Ipa - Iap;
+      const auto IpaPlusIapMinusIppMinusIaa =  Ipa + Iap - Ipp - Iaa;
+      const auto AOperations = A0 - A1 + A2 - A3 + A4 + A5 - A6 + A7 - A8;
+      const auto negateAOperations = A0 + A1 - A2 - A3 + A4 + A5 - A6 - A7 + A8;
+
+      const auto nIpp = (AOperations + IppPlusIaaMinusIpaMinusIap) / D;
+      const auto nIaa = (negateAOperations + IppPlusIaaMinusIpaMinusIap) / D;
+      const auto nIpa = (AOperations + IpaPlusIapMinusIppMinusIaa) / D;
+      const auto nIap = (negateAOperations + IpaPlusIapMinusIppMinusIaa) / D;
 
       WorkspaceGroup_sptr dataOut = boost::make_shared<WorkspaceGroup>();
       dataOut->addWorkspace(nIpp);
diff --git a/Code/Mantid/Framework/Algorithms/src/ReflectometryReductionOneAuto.cpp b/Code/Mantid/Framework/Algorithms/src/ReflectometryReductionOneAuto.cpp
index ea1054ad443098a08f4fe68726929056e9313536..ab6f1b2b0c30b59c6470e506b5ca2b21408449e8 100644
--- a/Code/Mantid/Framework/Algorithms/src/ReflectometryReductionOneAuto.cpp
+++ b/Code/Mantid/Framework/Algorithms/src/ReflectometryReductionOneAuto.cpp
@@ -126,13 +126,24 @@ namespace Mantid
       {
         if (analysis_mode == "PointDetectorAnalysis")
         {
-          processing_commands = boost::lexical_cast<std::string>(static_cast<int>(instrument->getNumberParameter("PointDetectorStart")[0]))
-            + "," + boost::lexical_cast<std::string>(static_cast<int>(instrument->getNumberParameter("PointDetectorStop")[0]));
+          const int detStart = static_cast<int>(instrument->getNumberParameter("PointDetectorStart")[0]);
+          const int detStop  = static_cast<int>(instrument->getNumberParameter("PointDetectorStop")[0]);
+
+          if(detStart == detStop)
+          {
+            //If the range given only specifies one detector, we pass along just that one detector
+            processing_commands = boost::lexical_cast<std::string>(detStart);
+          }
+          else
+          {
+            //Otherwise, we create a range.
+            processing_commands = boost::lexical_cast<std::string>(detStart) + ":" + boost::lexical_cast<std::string>(detStop);
+          }
         }
         else
         {
           processing_commands = boost::lexical_cast<std::string>(static_cast<int>(instrument->getNumberParameter("MultiDetectorStart")[0]))
-            + "," + boost::lexical_cast<std::string>(in_ws->getNumberHistograms() - 1);
+            + ":" + boost::lexical_cast<std::string>(in_ws->getNumberHistograms() - 1);
         }
       }
       else
diff --git a/Code/Mantid/Framework/Algorithms/src/ReflectometryWorkflowBase.cpp b/Code/Mantid/Framework/Algorithms/src/ReflectometryWorkflowBase.cpp
index 7e46b248f7781c623681ae62c0d6d83e732542e9..4c9a45acd7a230dec51d2b73de497b926043eda6 100644
--- a/Code/Mantid/Framework/Algorithms/src/ReflectometryWorkflowBase.cpp
+++ b/Code/Mantid/Framework/Algorithms/src/ReflectometryWorkflowBase.cpp
@@ -219,7 +219,8 @@ namespace Mantid
         throw std::invalid_argument("FirstTransmissionRun must be either in TOF or Wavelength");
       }
 
-      const bool bInWavelength = (!wavelengthValidator.isValid(firstTransmissionRun).empty());
+      const auto message = wavelengthValidator.isValid(firstTransmissionRun);
+      const bool bInWavelength = message.empty();
       return bInWavelength;
     }
 
@@ -384,6 +385,7 @@ namespace Mantid
           boost::assign::list_of(0).convert_to_container<std::vector<int> >());
       correctMonitorsAlg->setProperty("StartX", backgroundMinMax.get<0>());
       correctMonitorsAlg->setProperty("EndX", backgroundMinMax.get<1>());
+      correctMonitorsAlg->setProperty("SkipMonitors",false);
       correctMonitorsAlg->execute();
       monitorWS = correctMonitorsAlg->getProperty("OutputWorkspace");
 
diff --git a/Code/Mantid/Framework/Algorithms/src/ScaleX.cpp b/Code/Mantid/Framework/Algorithms/src/ScaleX.cpp
index e95a0f3d6709c9b81e0a60de8bfb94345e714435..537550f15d99671de8757db9ea1e969a24b2c2df 100644
--- a/Code/Mantid/Framework/Algorithms/src/ScaleX.cpp
+++ b/Code/Mantid/Framework/Algorithms/src/ScaleX.cpp
@@ -44,7 +44,7 @@ void ScaleX::init()
   declareProperty(new WorkspaceProperty<MatrixWorkspace>("OutputWorkspace","",Direction::Output),
     "Name of the output workspace");
   auto isDouble = boost::make_shared<BoundedValidator<double> >();
-  declareProperty("Factor", m_algFactor, isDouble, "The value by which to scale the input workspace. Default is 1.0");
+  declareProperty("Factor", m_algFactor, isDouble, "The value by which to scale the X-axis of the input workspace. Default is 1.0");
   std::vector<std::string> op(2);
   op[0] = "Multiply";
   op[1] = "Add";
diff --git a/Code/Mantid/Framework/Algorithms/src/Stitch1D.cpp b/Code/Mantid/Framework/Algorithms/src/Stitch1D.cpp
index 6cb8e14c76ded914c8da9729d518d101d860a7fd..ba4f981b3674d2afd487609c51edb3abb7c392a4 100644
--- a/Code/Mantid/Framework/Algorithms/src/Stitch1D.cpp
+++ b/Code/Mantid/Framework/Algorithms/src/Stitch1D.cpp
@@ -16,7 +16,6 @@
 #include <vector>
 #include <algorithm>
 
-
 using namespace Mantid::Kernel;
 using namespace Mantid::API;
 using Mantid::MantidVec;
@@ -36,6 +35,17 @@ namespace
   {
     return (0 != i);
   }
+
+  bool isNan(const double& value)
+  {
+    return boost::math::isnan(value);
+  }
+
+  bool isInf(const double& value)
+  {
+    return std::abs(value) == std::numeric_limits<double>::infinity();
+  }
+
 }
 
 namespace Mantid
@@ -50,10 +60,77 @@ namespace Mantid
      * inclusive of bin boundaries if they are sitting ontop of the bin boundaries.
      */
     const double Stitch1D::range_tolerance = 1e-9;
-    // Register the algorithm into the AlgorithmFactory
+// Register the algorithm into the AlgorithmFactory
     DECLARE_ALGORITHM(Stitch1D)
 
-    //----------------------------------------------------------------------------------------------
+    /**
+     * Zero out all y and e data that is not in the region a1 to a2.
+     * @param a1 : Zero based bin index (first one)
+     * @param a2 : Zero based bin index (last one inclusive)
+     * @param source : Workspace providing the source data.
+     * @return Masked workspace.
+     */
+    MatrixWorkspace_sptr Stitch1D::maskAllBut(int a1, int a2, MatrixWorkspace_sptr & source)
+    {
+      MatrixWorkspace_sptr product = WorkspaceFactory::Instance().create(source);
+      const int histogramCount = static_cast<int>(source->getNumberHistograms());
+      PARALLEL_FOR2(source,product)
+      for (int i = 0; i < histogramCount; ++i)
+      {
+        PARALLEL_START_INTERUPT_REGION
+        // Copy over the bin boundaries
+        product->setX(i, source->refX(i));
+        // Copy over the data
+        const MantidVec& sourceY = source->readY(i);
+        const MantidVec& sourceE = source->readE(i);
+
+        // initially zero - out the data.
+        product->dataY(i) = MantidVec(sourceY.size(), 0);
+        product->dataE(i) = MantidVec(sourceE.size(), 0);
+
+        MantidVec& newY = product->dataY(i);
+        MantidVec& newE = product->dataE(i);
+
+        // Copy over the non-zero stuff
+        std::copy(sourceY.begin() + a1 + 1, sourceY.begin() + a2, newY.begin() + a1 + 1);
+        std::copy(sourceE.begin() + a1 + 1, sourceE.begin() + a2, newE.begin() + a1 + 1);
+
+        PARALLEL_END_INTERUPT_REGION
+      }
+      PARALLEL_CHECK_INTERUPT_REGION
+      return product;
+    }
+
+    /**
+     * Mask out data in the region between a1 and a2 with zeros. Operation performed on the original workspace
+     * @param a1 : start position in X
+     * @param a2 : end position in X
+     * @param source : Workspace to mask.
+     */
+    void Stitch1D::maskInPlace(int a1, int a2, MatrixWorkspace_sptr source)
+    {
+      MatrixWorkspace_sptr product = WorkspaceFactory::Instance().create(source);
+      const int histogramCount = static_cast<int>(source->getNumberHistograms());
+      PARALLEL_FOR2(source,product)
+      for (int i = 0; i < histogramCount; ++i)
+      {
+        PARALLEL_START_INTERUPT_REGION
+        // Copy over the data
+        MantidVec& sourceY = source->dataY(i);
+        MantidVec& sourceE = source->dataE(i);
+
+        for (int i = a1; i < a2; ++i)
+        {
+          sourceY[i] = 0;
+          sourceE[i] = 0;
+        }
+
+        PARALLEL_END_INTERUPT_REGION
+      }
+      PARALLEL_CHECK_INTERUPT_REGION
+    }
+
+//----------------------------------------------------------------------------------------------
     /** Initialize the algorithm's properties.
      */
     void Stitch1D::init()
@@ -83,8 +160,9 @@ namespace Mantid
       auto manualScaleFactorValidator = boost::make_shared<BoundedValidator<double> >();
       manualScaleFactorValidator->setLower(0);
       manualScaleFactorValidator->setExclusive(true);
-      declareProperty(new PropertyWithValue<double>("ManualScaleFactor", 1.0, manualScaleFactorValidator, Direction::Input),
-          "Provided value for the scale factor. Optional.");
+      declareProperty(
+          new PropertyWithValue<double>("ManualScaleFactor", 1.0, manualScaleFactorValidator,
+              Direction::Input), "Provided value for the scale factor. Optional.");
       declareProperty(
           new PropertyWithValue<double>("OutScaleFactor", Mantid::EMPTY_DBL(), Direction::Output),
           "The actual used value for the scaling factor.");
@@ -156,7 +234,8 @@ namespace Mantid
      @param scaleRHS :: Scale the right hand side workspace
      @return a vector<double> contianing the rebinning parameters
      */
-    MantidVec Stitch1D::getRebinParams(MatrixWorkspace_sptr& lhsWS, MatrixWorkspace_sptr& rhsWS, const bool scaleRHS) const
+    MantidVec Stitch1D::getRebinParams(MatrixWorkspace_sptr& lhsWS, MatrixWorkspace_sptr& rhsWS,
+        const bool scaleRHS) const
     {
       MantidVec inputParams = this->getProperty("Params");
       Property* prop = this->getProperty("Params");
@@ -176,8 +255,8 @@ namespace Mantid
         MantidVec calculatedParams;
 
         // Calculate the step size based on the existing step size of the LHS workspace. That way scale factors should be reasonably maintained.
-        double calculatedStep =0;
-        if(scaleRHS)
+        double calculatedStep = 0;
+        if (scaleRHS)
         {
           // Calculate the step from the workspace that will not be scaled. The LHS workspace.
           calculatedStep = lhsX[1] - lhsX[0];
@@ -223,30 +302,68 @@ namespace Mantid
       rebin->setProperty("Params", params);
       rebin->execute();
       MatrixWorkspace_sptr outWS = rebin->getProperty("OutputWorkspace");
+
+      const int histogramCount = static_cast<int>(outWS->getNumberHistograms());
+
+      // Record special values and then mask them out as zeros. Special values are remembered and then replaced post processing.
+      PARALLEL_FOR1(outWS)
+      for (int i = 0; i < histogramCount; ++i)
+      {
+        PARALLEL_START_INTERUPT_REGION
+        std::vector<size_t>& nanYIndexes = m_nanYIndexes[i];
+        std::vector<size_t>& nanEIndexes = m_nanEIndexes[i];
+        std::vector<size_t>& infYIndexes = m_infYIndexes[i];
+        std::vector<size_t>& infEIndexes = m_infEIndexes[i];
+        // Copy over the data
+        MantidVec& sourceY = outWS->dataY(i);
+        MantidVec& sourceE = outWS->dataE(i);
+
+        for (size_t j = 0; j < sourceY.size(); ++j)
+        {
+          const double& value = sourceY[j];
+          const double& eValue = sourceE[j];
+          if (isNan(value))
+          {
+            nanYIndexes.push_back(j);
+            sourceY[j] = 0;
+          }
+          else if (isInf(value))
+          {
+            infYIndexes.push_back(j);
+            sourceY[j] = 0;
+          }
+
+          if (isNan(eValue))
+          {
+            nanEIndexes.push_back(j);
+            sourceE[j] = 0;
+          }
+          else if (isInf(eValue))
+          {
+            infEIndexes.push_back(j);
+            sourceE[j] = 0;
+          }
+
+        }
+
+      PARALLEL_END_INTERUPT_REGION
+      }
+      PARALLEL_CHECK_INTERUPT_REGION
+
       return outWS;
     }
 
-    /**Runs the Integration Algorithm as a child after replacing special values.
+    /**Runs the Integration Algorithm as a child.
      @param input :: The input workspace
      @param start :: a double defining the start of the region to integrate
      @param stop :: a double defining the end of the region to integrate
      @return A shared pointer to the resulting MatrixWorkspace
      */
-    MatrixWorkspace_sptr Stitch1D::specialIntegration(MatrixWorkspace_sptr& input, const double& start,
+    MatrixWorkspace_sptr Stitch1D::integration(MatrixWorkspace_sptr& input, const double& start,
         const double& stop)
     {
-      // Effectively ignore values that will trip the integration.
-      auto replace = this->createChildAlgorithm("ReplaceSpecialValues");
-      replace->setProperty("InputWorkspace", input);
-      replace->setProperty("NaNValue", 0.0);
-      replace->setProperty("NaNError", 0.0);
-      replace->setProperty("InfinityValue", 0.0);
-      replace->setProperty("InfinityError", 0.0);
-      replace->execute();
-      MatrixWorkspace_sptr patchedWS = replace->getProperty("OutputWorkspace");
-
       auto integration = this->createChildAlgorithm("Integration");
-      integration->setProperty("InputWorkspace", patchedWS);
+      integration->setProperty("InputWorkspace", input);
       integration->setProperty("RangeLower", start);
       integration->setProperty("RangeUpper", stop);
       integration->execute();
@@ -355,7 +472,7 @@ namespace Mantid
         if (!hasNonZeroErrors) // Keep checking
         {
           auto e = ws->readE(i);
-          auto it = std::find_if(e.begin(), e.end(),isNonzero);
+          auto it = std::find_if(e.begin(), e.end(), isNonzero);
           if (it != e.end())
           {
             PARALLEL_CRITICAL(has_non_zero)
@@ -371,7 +488,7 @@ namespace Mantid
     return hasNonZeroErrors;
   }
 
-  //----------------------------------------------------------------------------------------------
+//----------------------------------------------------------------------------------------------
   /** Execute the algorithm.
    */
   void Stitch1D::exec()
@@ -422,6 +539,11 @@ namespace Mantid
       throw std::runtime_error(message);
     }
 
+    const size_t histogramCount = rhsWS->getNumberHistograms();
+    m_nanYIndexes.resize(histogramCount);
+    m_infYIndexes.resize(histogramCount);
+    m_nanEIndexes.resize(histogramCount);
+    m_infEIndexes.resize(histogramCount);
     auto rebinnedLHS = rebin(lhsWS, params);
     auto rebinnedRHS = rebin(rhsWS, params);
 
@@ -449,8 +571,8 @@ namespace Mantid
     }
     else
     {
-      auto rhsOverlapIntegrated = specialIntegration(rebinnedRHS, startOverlap, endOverlap);
-      auto lhsOverlapIntegrated = specialIntegration(rebinnedLHS, startOverlap, endOverlap);
+      auto rhsOverlapIntegrated = integration(rebinnedRHS, startOverlap, endOverlap);
+      auto lhsOverlapIntegrated = integration(rebinnedLHS, startOverlap, endOverlap);
 
       MatrixWorkspace_sptr ratio;
       if (scaleRHS)
@@ -465,10 +587,11 @@ namespace Mantid
       }
       scaleFactor = ratio->readY(0).front();
       errorScaleFactor = ratio->readE(0).front();
-      if(scaleFactor < 1e-2 || scaleFactor > 1e2  || boost::math::isnan(scaleFactor))
+      if (scaleFactor < 1e-2 || scaleFactor > 1e2 || boost::math::isnan(scaleFactor))
       {
         std::stringstream messageBuffer;
-        messageBuffer << "Stitch1D calculated scale factor is: " << scaleFactor << ". Check that in both input workspaces the integrated overlap region is non-zero.";
+        messageBuffer << "Stitch1D calculated scale factor is: " << scaleFactor
+            << ". Check that in both input workspaces the integrated overlap region is non-zero.";
         g_log.warning(messageBuffer.str());
       }
 
@@ -478,20 +601,13 @@ namespace Mantid
     int a2 = boost::tuples::get<1>(startEnd);
 
     // Mask out everything BUT the overlap region as a new workspace.
-    MatrixWorkspace_sptr overlap1 = multiplyRange(rebinnedLHS, 0, a1, 0);
-    overlap1 = multiplyRange(overlap1, a2, 0);
-
+    MatrixWorkspace_sptr overlap1 = maskAllBut(a1, a2, rebinnedLHS);
     // Mask out everything BUT the overlap region as a new workspace.
-    MatrixWorkspace_sptr overlap2 = multiplyRange(rebinnedRHS, 0, a1, 0);
-    overlap2 = multiplyRange(overlap2, a2, 0);
-
-    // Mask out everything AFTER the start of the overlap region
-    rebinnedLHS = multiplyRange(rebinnedLHS, a1 + 1, 0);
-
-    // Mask out everything BEFORE the end of the overlap region
-    rebinnedRHS = multiplyRange(rebinnedRHS, 0, a2 - 1, 0);
-
-    // Calculate a weighted mean for the overlap region
+    MatrixWorkspace_sptr overlap2 = maskAllBut(a1, a2, rebinnedRHS);
+    // Mask out everything AFTER the overlap region as a new workspace.
+    maskInPlace(a1 + 1, static_cast<int>(rebinnedLHS->blocksize()), rebinnedLHS);
+    // Mask out everything BEFORE the overlap region as a new workspace.
+    maskInPlace(0, a2, rebinnedRHS);
 
     MatrixWorkspace_sptr overlapave;
     if (hasNonzeroErrors(overlap1) && hasNonzeroErrors(overlap2))
@@ -507,6 +623,7 @@ namespace Mantid
     }
 
     MatrixWorkspace_sptr result = rebinnedLHS + overlapave + rebinnedRHS;
+    reinsertSpecialValues(result);
 
     // Provide log information about the scale factors used in the calculations.
     std::stringstream messageBuffer;
@@ -518,5 +635,44 @@ namespace Mantid
 
   }
 
+  /**
+   * Put special values back.
+   * @param ws : MatrixWorkspace to resinsert special values into.
+   */
+  void Stitch1D::reinsertSpecialValues(MatrixWorkspace_sptr ws)
+  {
+    int histogramCount = static_cast<int>(ws->getNumberHistograms());
+    PARALLEL_FOR1(ws)
+    for (int i = 0; i < histogramCount; ++i)
+    {
+      PARALLEL_START_INTERUPT_REGION
+      // Copy over the data
+      MantidVec& sourceY = ws->dataY(i);
+
+      for (size_t j = 0; j < m_nanYIndexes[i].size(); ++j)
+      {
+        sourceY[m_nanYIndexes[i][j]] = std::numeric_limits<double>::quiet_NaN();
+      }
+
+      for (size_t j = 0; j < m_infYIndexes[i].size(); ++j)
+      {
+        sourceY[m_infYIndexes[i][j]] = std::numeric_limits<double>::infinity();
+      }
+
+      for (size_t j = 0; j < m_nanEIndexes[i].size(); ++j)
+      {
+        sourceY[m_nanEIndexes[i][j]] = std::numeric_limits<double>::quiet_NaN();
+      }
+
+      for (size_t j = 0; j < m_infEIndexes[i].size(); ++j)
+      {
+        sourceY[m_infEIndexes[i][j]] = std::numeric_limits<double>::infinity();
+      }
+
+    PARALLEL_END_INTERUPT_REGION
+  }
+PARALLEL_CHECK_INTERUPT_REGION
+}
+
 } // namespace Algorithms
 } // namespace Mantid
diff --git a/Code/Mantid/Framework/Algorithms/test/AddTimeSeriesLogTest.h b/Code/Mantid/Framework/Algorithms/test/AddTimeSeriesLogTest.h
index 5f9c9e94146c80666a76f4e90d4ece39b676b658..2b14bb34f75a0a0aa5788c20baa726080f7c2ce6 100644
--- a/Code/Mantid/Framework/Algorithms/test/AddTimeSeriesLogTest.h
+++ b/Code/Mantid/Framework/Algorithms/test/AddTimeSeriesLogTest.h
@@ -47,8 +47,8 @@ public:
     const auto allowedValues = prop->allowedValues();
 
     TS_ASSERT_EQUALS(2, allowedValues.size());
-    TS_ASSERT_EQUALS(1, allowedValues.count("int"));
-    TS_ASSERT_EQUALS(1, allowedValues.count("double"));
+    TS_ASSERT( std::find( allowedValues.begin(), allowedValues.end(), "int") != allowedValues.end() );
+    TS_ASSERT( std::find( allowedValues.begin(), allowedValues.end(), "double") != allowedValues.end() );
   }
 
   void test_delete_existing_removes_complete_log_first()
diff --git a/Code/Mantid/Framework/Algorithms/test/AlignDetectorsTest.h b/Code/Mantid/Framework/Algorithms/test/AlignDetectorsTest.h
index 5ba80f7fa53ad7cb05d164cd5409781dd2d9aaac..3f7d4983e3b34580b2e36383df5e8f8e1beea69d 100644
--- a/Code/Mantid/Framework/Algorithms/test/AlignDetectorsTest.h
+++ b/Code/Mantid/Framework/Algorithms/test/AlignDetectorsTest.h
@@ -2,6 +2,7 @@
 #define ALIGNDETECTORSTEST_H_
 
 #include <cxxtest/TestSuite.h>
+#include "MantidTestHelpers/WorkspaceCreationHelper.h"
 
 #include "MantidAlgorithms/AlignDetectors.h"
 #include "MantidDataHandling/LoadNexus.h"
@@ -87,23 +88,13 @@ public:
   }
 
 
-
-
   /** Setup for loading raw data */
   void setUp_Event()
   {
     inputWS = "eventWS";
-    LoadEventPreNexus loader;
-    loader.initialize();
-    std::string eventfile( "CNCS_7860_neutron_event.dat" );
-    std::string pulsefile( "CNCS_7860_pulseid.dat" );
-    loader.setPropertyValue("EventFilename", eventfile);
-    loader.setPropertyValue("PulseidFilename", pulsefile);
-    loader.setPropertyValue("MappingFilename", "CNCS_TS_2008_08_18.dat");
-    loader.setPropertyValue("SpectrumList","1,2,3,4,5,6,7,8,9,10");
-    loader.setPropertyValue("OutputWorkspace", inputWS);
-    loader.execute();
-    TS_ASSERT (loader.isExecuted() );
+    EventWorkspace_sptr ws = WorkspaceCreationHelper::createEventWorkspaceWithFullInstrument(1, 10,false);
+    ws->getAxis(0)->setUnit("TOF");
+    AnalysisDataService::Instance().addOrReplace(inputWS, ws);
   }
 
 
diff --git a/Code/Mantid/Framework/Algorithms/test/ClearInstrumentParametersTest.h b/Code/Mantid/Framework/Algorithms/test/ClearInstrumentParametersTest.h
new file mode 100644
index 0000000000000000000000000000000000000000..53a99f77ea2e65b60a2ffaa00f7342910cd3d6e9
--- /dev/null
+++ b/Code/Mantid/Framework/Algorithms/test/ClearInstrumentParametersTest.h
@@ -0,0 +1,97 @@
+#ifndef CLEARINSTRUMENTPARAMETERSTEST_H
+#define CLEARINSTRUMENTPARAMETERSTEST_H
+
+#include <cxxtest/TestSuite.h>
+
+#include "MantidAlgorithms/ClearInstrumentParameters.h"
+#include "MantidAPI/AnalysisDataService.h"
+#include "MantidDataHandling/LoadInstrument.h"
+#include "MantidDataObjects/Workspace2D.h"
+
+using namespace Mantid::Algorithms;
+using namespace Mantid::API;
+using namespace Mantid::Kernel;
+using namespace Mantid::Geometry;
+using namespace Mantid::DataHandling;
+using namespace Mantid::DataObjects;
+
+class ClearInstrumentParametersTest : public CxxTest::TestSuite
+{
+public:
+
+  void testClearInstrumentParameters()
+  {
+    //Load a workspace
+    prepareWorkspace();
+
+    //Set some parameters
+    setParam("nickel-holder", "testDouble", 1.23);
+    setParam("nickel-holder", "testString", "hello world");
+
+    //Clear the parameters
+    clearParameters();
+
+    //Check the parameters
+    checkEmpty("nickel-holder", "testDouble");
+    checkEmpty("nickel-holder", "testString");
+  }
+
+  void setParam(std::string cName, std::string pName, std::string value)
+  {
+    Instrument_const_sptr inst = m_ws->getInstrument();
+    ParameterMap& paramMap = m_ws->instrumentParameters();
+    boost::shared_ptr<const IComponent> comp = inst->getComponentByName(cName);
+    paramMap.addString(comp->getComponentID(), pName, value);
+  }
+
+  void setParam(std::string cName, std::string pName, double value)
+  {
+    Instrument_const_sptr inst = m_ws->getInstrument();
+    ParameterMap& paramMap = m_ws->instrumentParameters();
+    boost::shared_ptr<const IComponent> comp = inst->getComponentByName(cName);
+    paramMap.addDouble(comp->getComponentID(), pName, value);
+  }
+
+  void checkEmpty(std::string cName, std::string pName)
+  {
+    Instrument_const_sptr inst = m_ws->getInstrument();
+    ParameterMap& paramMap = m_ws->instrumentParameters();
+    boost::shared_ptr<const IComponent> comp = inst->getComponentByName(cName);
+    bool exists = paramMap.contains(comp.get(), pName);
+    TS_ASSERT_EQUALS(exists, false);
+  }
+
+  void clearParameters()
+  {
+    ClearInstrumentParameters clearer;
+    TS_ASSERT_THROWS_NOTHING(clearer.initialize());
+    clearer.setPropertyValue("Workspace", m_ws->name());
+    TS_ASSERT_THROWS_NOTHING(clearer.execute());
+    TS_ASSERT(clearer.isExecuted());
+  }
+
+  void prepareWorkspace()
+  {
+    LoadInstrument loaderIDF2;
+
+    TS_ASSERT_THROWS_NOTHING(loaderIDF2.initialize());
+
+    std::string wsName = "SaveParameterFileTestIDF2";
+    Workspace_sptr ws = WorkspaceFactory::Instance().create("Workspace2D",1,1,1);
+    Workspace2D_sptr ws2D = boost::dynamic_pointer_cast<Workspace2D>(ws);
+
+    TS_ASSERT_THROWS_NOTHING(AnalysisDataService::Instance().add(wsName, ws2D));
+
+    loaderIDF2.setPropertyValue("Filename", "IDFs_for_UNIT_TESTING/IDF_for_UNIT_TESTING2.xml");
+    loaderIDF2.setPropertyValue("Workspace", wsName);
+    TS_ASSERT_THROWS_NOTHING(loaderIDF2.execute());
+    TS_ASSERT( loaderIDF2.isExecuted() );
+
+    m_ws = boost::dynamic_pointer_cast<MatrixWorkspace>(ws2D);
+  }
+
+private:
+  MatrixWorkspace_sptr m_ws;
+};
+
+#endif /* CLEARINSTRUMENTPARAMETERSTEST_H */
diff --git a/Code/Mantid/Framework/Algorithms/test/ConvertUnitsTest.h b/Code/Mantid/Framework/Algorithms/test/ConvertUnitsTest.h
index f7c7556ee1f4b3d4606a23187c05f83ea5a51697..9aeb70f2f2ee00a43a763950d0690cb218491717 100644
--- a/Code/Mantid/Framework/Algorithms/test/ConvertUnitsTest.h
+++ b/Code/Mantid/Framework/Algorithms/test/ConvertUnitsTest.h
@@ -293,24 +293,13 @@ public:
   void setup_Event()
   {
     this->inputSpace = "eventWS";
-    Mantid::DataHandling::LoadEventPreNexus loader;
-    loader.initialize();
-    std::string eventfile( "CNCS_7860_neutron_event.dat" );
-    std::string pulsefile( "CNCS_7860_pulseid.dat" );
-    pulsefile = "";
-    loader.setPropertyValue("EventFilename", eventfile);
-    loader.setPropertyValue("PulseidFilename", pulsefile);
-    loader.setPropertyValue("MappingFilename", "CNCS_TS_2008_08_18.dat");
-    loader.setPropertyValue("OutputWorkspace", this->inputSpace);
-    loader.setPropertyValue("ChunkNumber", "1");
-    loader.setPropertyValue("TotalChunks", "10");
-    loader.execute();
-    TS_ASSERT (loader.isExecuted() );
+    EventWorkspace_sptr ws = WorkspaceCreationHelper::createEventWorkspaceWithFullInstrument(1, 10,false);
+    AnalysisDataService::Instance().addOrReplace(inputSpace, ws);
   }
 
   void testExecEvent_sameOutputWS()
   {
-    std::size_t wkspIndex = 4348; // a good workspace index (with events)
+    std::size_t wkspIndex = 0;
     this->setup_Event();
 
     //Retrieve Workspace
@@ -318,8 +307,9 @@ public:
     TS_ASSERT( WS ); //workspace is loaded
     size_t start_blocksize = WS->blocksize();
     size_t num_events = WS->getNumberEvents();
-    double a_tof = WS->getEventList(wkspIndex).getEvents()[0].tof();
-    double a_x = WS->getEventList(wkspIndex).dataX()[1];
+    EventList el = WS->getEventList(wkspIndex);
+    double a_tof = el.getEvents()[0].tof();
+    double a_x = el.dataX()[1];
 
     if ( !alg.isInitialized() ) alg.initialize();
     TS_ASSERT( alg.isInitialized() );
diff --git a/Code/Mantid/Framework/Algorithms/test/CopySampleTest.h b/Code/Mantid/Framework/Algorithms/test/CopySampleTest.h
index 3732f6e47d1e909e379db0f941977e9751a7e462..d3a0aad1fe26696ffa6e090a0908b371d6291ab1 100644
--- a/Code/Mantid/Framework/Algorithms/test/CopySampleTest.h
+++ b/Code/Mantid/Framework/Algorithms/test/CopySampleTest.h
@@ -68,6 +68,7 @@ public:
     sample.setEnvironment(kit);
     OrientedLattice *latt = new OrientedLattice(1.0,2.0,3.0, 90, 90, 90);
     sample.setOrientedLattice(latt);
+    delete latt;
     Material vanBlock("vanBlock", Mantid::PhysicalConstants::getNeutronAtom(23, 0), 0.072);
     sample.setMaterial(vanBlock);
     Object_sptr shape_sptr =
@@ -241,7 +242,9 @@ public:
     ExperimentInfo_sptr ei1(new ExperimentInfo);
     Sample s=createsample();
     Sample s1;
-    s1.setOrientedLattice(new OrientedLattice(6.0,7.0,8.0, 90, 90, 90));
+    OrientedLattice *latt=new OrientedLattice(6.0,7.0,8.0, 90, 90, 90);
+    s1.setOrientedLattice(latt);
+    delete latt;
     s1.setName("newsample");
     ei->mutableSample()=s;
     TS_ASSERT_EQUALS( ew->addExperimentInfo(ei), 0);
diff --git a/Code/Mantid/Framework/Algorithms/test/CreateSampleWorkspaceTest.h b/Code/Mantid/Framework/Algorithms/test/CreateSampleWorkspaceTest.h
index b0cb8a89fc0546f8754caf82bb55856470e3fe83..517aea13cd7d675125121e4714553d193cd1d1f4 100644
--- a/Code/Mantid/Framework/Algorithms/test/CreateSampleWorkspaceTest.h
+++ b/Code/Mantid/Framework/Algorithms/test/CreateSampleWorkspaceTest.h
@@ -231,6 +231,38 @@ public:
     // Remove workspace from the data service.
     AnalysisDataService::Instance().remove(outWSName);
   }
+
+  void test_units()
+  {
+    // Name of the output workspace.
+    std::string outWSName("CreateSampleWorkspaceTest_units");
+  
+    /* Equivalent of this python command:
+      ws=CreateSampleWorkspace(WorkspaceType="Event",Function="One Peak",
+      NumBanks=1,BankPixelWidth=2,NumEvents=50,Random=True,
+      XUnit="dSpacing",XMin=0, XMax=8, BinWidth=0.1)
+    */
+    MatrixWorkspace_sptr ws = createSampleWorkspace(outWSName,"Event","One Peak","",1,2,50,true,"dSpacing",0,8,0.1);
+    if (!ws) return;
+    // Remove workspace from the data service.
+    AnalysisDataService::Instance().remove(outWSName);
+
+    ws = createSampleWorkspace(outWSName,"Event","One Peak","",1,2,50,true,"Wavelength",0,8,0.1);
+    if (!ws) return;
+    // Remove workspace from the data service.
+    AnalysisDataService::Instance().remove(outWSName);
+
+    ws = createSampleWorkspace(outWSName,"Event","One Peak","",1,2,50,true,"Energy",100,1000,10);
+    if (!ws) return;
+    // Remove workspace from the data service.
+    AnalysisDataService::Instance().remove(outWSName);
+
+    ws = createSampleWorkspace(outWSName,"Event","One Peak","",1,2,50,true,"QSquared",0,800,10);
+    if (!ws) return;
+    // Remove workspace from the data service.
+    AnalysisDataService::Instance().remove(outWSName);
+  }
+  
 };
 
 
diff --git a/Code/Mantid/Framework/Algorithms/test/CreateTransmissionWorkspaceAutoTest.h b/Code/Mantid/Framework/Algorithms/test/CreateTransmissionWorkspaceAutoTest.h
index aaa125be0c92675160d2efd9cbbbc32110086e61..e58ede051c1cb4fab18b8e9031014bb86ed40177 100644
--- a/Code/Mantid/Framework/Algorithms/test/CreateTransmissionWorkspaceAutoTest.h
+++ b/Code/Mantid/Framework/Algorithms/test/CreateTransmissionWorkspaceAutoTest.h
@@ -7,402 +7,136 @@
 #include "MantidAPI/FrameworkManager.h"
 #include "MantidAPI/AlgorithmManager.h"
 #include <boost/assign/list_of.hpp>
+#include <boost/lexical_cast.hpp>
 
 using Mantid::Algorithms::CreateTransmissionWorkspaceAuto;
 using namespace Mantid::API;
+using namespace Mantid::Kernel;
 using namespace boost::assign;
 using Mantid::MantidVec;
 
-class CreateTransmissionWorkspaceAutoTest : public CxxTest::TestSuite
+namespace
+{
+  class PropertyFinder
+  {
+  private:
+    const std::string m_propertyName;
+  public:
+    PropertyFinder(const std::string& propertyName) :
+        m_propertyName(propertyName)
+    {
+    }
+    bool operator()(const PropertyHistories::value_type& candidate) const
+    {
+      return candidate->name() == m_propertyName;
+    }
+  };
+
+  template<typename T>
+  T findPropertyValue(PropertyHistories& histories, const std::string& propertyName)
+  {
+    PropertyFinder finder(propertyName);
+    auto it = std::find_if(histories.begin(), histories.end(), finder);
+    return boost::lexical_cast<T>((*it)->value());
+  }
+}
+
+class CreateTransmissionWorkspaceAutoTest: public CxxTest::TestSuite
 {
 public:
   // This pair of boilerplate methods prevent the suite being created statically
   // This means the constructor isn't called when running other tests
-  static CreateTransmissionWorkspaceAutoTest *createSuite() { return new CreateTransmissionWorkspaceAutoTest(); }
-  static void destroySuite( CreateTransmissionWorkspaceAutoTest *suite ) { delete suite; }
+  static CreateTransmissionWorkspaceAutoTest *createSuite()
+  {
+    return new CreateTransmissionWorkspaceAutoTest();
+  }
+  static void destroySuite(CreateTransmissionWorkspaceAutoTest *suite)
+  {
+    delete suite;
+  }
+
 
-  MatrixWorkspace_sptr m_TOF;
-  MatrixWorkspace_sptr m_NotTOF;
-  const std::string outWSName;
-  const std::string inWSName;
-  const std::string transWSName;
+  MatrixWorkspace_sptr m_dataWS;
 
-  CreateTransmissionWorkspaceAutoTest(): outWSName("CreateTransmissionWorkspaceAutoTest_OutputWS_Q"),
-    inWSName("CreateTransmissionWorkspaceAutoTest_InputWS"),
-    transWSName("CreateTransmissionWorkspaceAutoTest_TransWS")
+  CreateTransmissionWorkspaceAutoTest()
   {
     FrameworkManager::Instance();
-    MantidVec xData = boost::assign::list_of(0)(0)(0)(0).convert_to_container<MantidVec>();
-    MantidVec yData = boost::assign::list_of(0)(0)(0).convert_to_container<MantidVec>();
 
-    auto createWorkspace = AlgorithmManager::Instance().create("CreateWorkspace");
-    createWorkspace->initialize();
-    createWorkspace->setProperty("UnitX", "1/q");
-    createWorkspace->setProperty("DataX", xData);
-    createWorkspace->setProperty("DataY", yData);
-    createWorkspace->setProperty("NSpec", 1);
-    createWorkspace->setPropertyValue("OutputWorkspace", "NotTOF");
-    createWorkspace->execute();
-    m_NotTOF = AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>("NotTOF");
+    IAlgorithm_sptr lAlg = AlgorithmManager::Instance().create("Load");
+    lAlg->setChild(true);
+    lAlg->initialize();
+    lAlg->setProperty("Filename", "INTER00013460.nxs");
+    lAlg->setPropertyValue("OutputWorkspace", "demo_ws");
+    lAlg->execute();
+    Workspace_sptr temp = lAlg->getProperty("OutputWorkspace");
+    m_dataWS = boost::dynamic_pointer_cast<MatrixWorkspace>(temp);
 
-    createWorkspace->setProperty("UnitX", "TOF");
-    createWorkspace->setProperty("DataX", xData);
-    createWorkspace->setProperty("DataY", yData);
-    createWorkspace->setProperty("NSpec", 1);
-    createWorkspace->setPropertyValue("OutputWorkspace", "TOF");
-    createWorkspace->execute();
-    m_TOF = AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>("TOF");
   }
 
   ~CreateTransmissionWorkspaceAutoTest()
   {
-    AnalysisDataService::Instance().remove("TOF");
-    AnalysisDataService::Instance().remove("NotTOF");
   }
 
-  IAlgorithm_sptr construct_standard_algorithm()
-  {
-    auto alg = AlgorithmManager::Instance().create("CreateTransmissionWorkspaceAuto");
-    alg->initialize();
-    alg->setProperty("FirstTransmissionRun", m_TOF);
-    alg->setProperty("WavelengthMin", 0.0);
-    alg->setProperty("WavelengthMax", 1.0);
-    alg->setProperty("I0MonitorIndex", 0);
-    alg->setPropertyValue("ProcessingInstructions", "0, 1");
-    alg->setProperty("MonitorBackgroundWavelengthMin", 0.0);
-    alg->setProperty("MonitorBackgroundWavelengthMax", 1.0);
-    alg->setProperty("MonitorIntegrationWavelengthMin", 0.0);
-    alg->setProperty("MonitorIntegrationWavelengthMax", 1.0);
-    alg->setPropertyValue("OutputWorkspace", outWSName);
-    alg->setRethrows(true);
-    return alg;
-  }
 
   void test_Init()
   {
     CreateTransmissionWorkspaceAuto alg;
-    TS_ASSERT_THROWS_NOTHING( alg.initialize() )
-      TS_ASSERT( alg.isInitialized() )
+    TS_ASSERT_THROWS_NOTHING( alg.initialize())
+    TS_ASSERT( alg.isInitialized())
   }
 
   void test_exec()
   {
-    IAlgorithm_sptr lAlg = AlgorithmManager::Instance().create("Load");
-    lAlg->initialize();
-    lAlg->setPropertyValue("Filename", "INTER00013463.nxs");
-    lAlg->setPropertyValue("OutputWorkspace", inWSName);
-    lAlg->execute(); 
-    MatrixWorkspace_sptr ws = AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>(inWSName);
-
     IAlgorithm_sptr alg = AlgorithmManager::Instance().create("CreateTransmissionWorkspaceAuto");
-    TS_ASSERT_THROWS_NOTHING( alg->initialize() );
-    TS_ASSERT( alg->isInitialized() );
-    TS_ASSERT_THROWS_NOTHING( alg->setProperty("FirstTransmissionRun", ws); );
-    TS_ASSERT_THROWS_NOTHING( alg->setPropertyValue("OutputWorkspace", outWSName); );
-    TS_ASSERT_THROWS_NOTHING( alg->execute(); );
-    TS_ASSERT( alg->isExecuted() );
-
-    MatrixWorkspace_sptr outWS;
-    TS_ASSERT_THROWS_NOTHING( outWS = AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>(outWSName); );
-
-    auto inst = ws->getInstrument();
-    auto history = outWS->getHistory();
-    auto algHist = history.getAlgorithmHistory(history.size()-1);
-    auto historyAlg = algHist->getChildAlgorithm(0);
-
-    double wavelengthMin = historyAlg->getProperty("WavelengthMin");
-    double wavelengthMax = historyAlg->getProperty("WavelengthMax");
-    double monitorBackgroundWavelengthMin = historyAlg->getProperty("MonitorBackgroundWavelengthMin");
-    double monitorBackgroundWavelengthMax = historyAlg->getProperty("MonitorBackgroundWavelengthMax");
-    double monitorIntegrationWavelengthMin = historyAlg->getProperty("MonitorIntegrationWavelengthMin");
-    double monitorIntegrationWavelengthMax = historyAlg->getProperty("MonitorIntegrationWavelengthMax");
-    int i0MonitorIndex = historyAlg->getProperty("I0MonitorIndex");
-    std::string processingInstructions = historyAlg->getProperty("ProcessingInstructions");
+    alg->setRethrows(true);
+    TS_ASSERT_THROWS_NOTHING( alg->initialize());
+    TS_ASSERT_THROWS_NOTHING( alg->setProperty("FirstTransmissionRun", m_dataWS));
+    TS_ASSERT_THROWS_NOTHING( alg->setPropertyValue("OutputWorkspace", "outWS"));
+    alg->execute();
+    TS_ASSERT( alg->isExecuted());
+
+    MatrixWorkspace_sptr outWS = AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>("outWS");
+
+    auto inst = m_dataWS->getInstrument();
+    auto workspaceHistory = outWS->getHistory();
+    AlgorithmHistory_const_sptr workerAlgHistory =
+        workspaceHistory.getAlgorithmHistory(0)->getChildAlgorithmHistory(0);
+    auto vecPropertyHistories = workerAlgHistory->getProperties();
+
+    const double wavelengthMin = findPropertyValue<double>(vecPropertyHistories, "WavelengthMin");
+    double wavelengthMax = findPropertyValue<double>(vecPropertyHistories, "WavelengthMax");
+    double monitorBackgroundWavelengthMin = findPropertyValue<double>(vecPropertyHistories,
+        "MonitorBackgroundWavelengthMin");
+    double monitorBackgroundWavelengthMax = findPropertyValue<double>(vecPropertyHistories,
+        "MonitorBackgroundWavelengthMax");
+    double monitorIntegrationWavelengthMin = findPropertyValue<double>(vecPropertyHistories,
+        "MonitorIntegrationWavelengthMin");
+    double monitorIntegrationWavelengthMax = findPropertyValue<double>(vecPropertyHistories,
+        "MonitorIntegrationWavelengthMax");
+    int i0MonitorIndex = findPropertyValue<int>(vecPropertyHistories, "I0MonitorIndex");
+    std::string processingInstructions = findPropertyValue<std::string>(vecPropertyHistories,
+        "ProcessingInstructions");
     std::vector<std::string> pointDetectorStartStop;
-    boost::split(pointDetectorStartStop,processingInstructions,boost::is_any_of(","));
+    boost::split(pointDetectorStartStop, processingInstructions, boost::is_any_of(","));
 
     TS_ASSERT_EQUALS(inst->getNumberParameter("LambdaMin").at(0), wavelengthMin);
     TS_ASSERT_EQUALS(inst->getNumberParameter("LambdaMax").at(0), wavelengthMax);
-    TS_ASSERT_EQUALS(inst->getNumberParameter("MonitorBackgroundMin").at(0), monitorBackgroundWavelengthMin);
-    TS_ASSERT_EQUALS(inst->getNumberParameter("MonitorBackgroundMax").at(0), monitorBackgroundWavelengthMax);
-    TS_ASSERT_EQUALS(inst->getNumberParameter("MonitorIntegralMin").at(0), monitorIntegrationWavelengthMin);
-    TS_ASSERT_EQUALS(inst->getNumberParameter("MonitorIntegralMax").at(0), monitorIntegrationWavelengthMax);
+    TS_ASSERT_EQUALS(inst->getNumberParameter("MonitorBackgroundMin").at(0),
+        monitorBackgroundWavelengthMin);
+    TS_ASSERT_EQUALS(inst->getNumberParameter("MonitorBackgroundMax").at(0),
+        monitorBackgroundWavelengthMax);
+    TS_ASSERT_EQUALS(inst->getNumberParameter("MonitorIntegralMin").at(0),
+        monitorIntegrationWavelengthMin);
+    TS_ASSERT_EQUALS(inst->getNumberParameter("MonitorIntegralMax").at(0),
+        monitorIntegrationWavelengthMax);
     TS_ASSERT_EQUALS(inst->getNumberParameter("I0MonitorIndex").at(0), i0MonitorIndex);
-    TS_ASSERT_EQUALS(inst->getNumberParameter("PointDetectorStart").at(0), boost::lexical_cast<double>(pointDetectorStartStop.at(0)));
-    TS_ASSERT_EQUALS(inst->getNumberParameter("PointDetectorStop").at(0), boost::lexical_cast<double>(pointDetectorStartStop.at(1)));
-
-    // Remove workspace from the data service.
-    AnalysisDataService::Instance().remove(outWSName);
-    AnalysisDataService::Instance().remove(inWSName);
-
-  }
-
-  void test_check_first_transmission_workspace_not_tof_or_wavelength_throws()
-  {
-    auto alg = construct_standard_algorithm();
-    TS_ASSERT_THROWS(alg->setProperty("FirstTransmissionRun", m_NotTOF), std::invalid_argument);
-  }
+    TS_ASSERT_EQUALS(inst->getNumberParameter("PointDetectorStart").at(0),
+        boost::lexical_cast<double>(pointDetectorStartStop.at(0)));
+    TS_ASSERT_EQUALS(inst->getNumberParameter("PointDetectorStop").at(0),
+        boost::lexical_cast<double>(pointDetectorStartStop.at(1)));
 
-  void test_check_second_transmission_workspace_not_tof_throws()
-  {
-    auto alg = construct_standard_algorithm();
-    TS_ASSERT_THROWS(alg->setProperty("SecondTransmissionRun", m_NotTOF), std::invalid_argument);
-  }
-
-  void test_end_overlap_must_be_greater_than_start_overlap_or_throw()
-  {
-    auto alg = construct_standard_algorithm();
-    alg->setProperty("FirstTransmissionRun", m_TOF);
-    alg->setProperty("SecondTransmissionRun", m_TOF);
-    MantidVec params = boost::assign::list_of(0.0)(0.1)(1.0).convert_to_container<MantidVec>();
-    alg->setProperty("Params", params);
-    alg->setProperty("StartOverlap", 0.6);
-    alg->setProperty("EndOverlap", 0.4);
-    TS_ASSERT_THROWS(alg->execute(), std::invalid_argument);
-  }
-
-  void test_must_provide_wavelengths()
-  {
-    auto alg = AlgorithmManager::Instance().create("CreateTransmissionWorkspaceAuto");
-    alg->initialize();
-    alg->setProperty("FirstTransmissionRun", m_TOF);
-    alg->setProperty("SecondTransmissionRun", m_TOF);
-    alg->setProperty("WavelengthMax", 1.0);
-    alg->setPropertyValue("OutputWorkspace", outWSName);
-    alg->setRethrows(true);
-    TS_ASSERT_THROWS(alg->execute(), std::runtime_error);
-
-    alg->setProperty("FirstTransmissionRun", m_TOF);
-    alg->setProperty("SecondTransmissionRun", m_TOF);
-    alg->setProperty("WavelengthMin", 1.0);
-    alg->setPropertyValue("OutputWorkspace", outWSName);
-    alg->setRethrows(true);
-    TS_ASSERT_THROWS(alg->execute(), std::runtime_error);
-  }
-
-  void test_wavelength_min_greater_wavelength_max_throws()
-  {
-    auto alg = construct_standard_algorithm();
-    alg->setProperty("WavelengthMin", 1.0);
-    alg->setProperty("WavelengthMax", 0.0);
-    TS_ASSERT_THROWS(alg->execute(), std::invalid_argument);
-  }
-
-  void test_monitor_background_wavelength_min_greater_monitor_background_wavelength_max_throws()
-  {
-    auto alg = construct_standard_algorithm();
-    alg->setProperty("MonitorBackgroundWavelengthMin", 1.0);
-    alg->setProperty("MonitorBackgroundWavelengthMax", 0.0);
-    TS_ASSERT_THROWS(alg->execute(), std::invalid_argument);
-  }
-
-  void test_monitor_integration_wavelength_min_greater_monitor_integration_wavelength_max_throws()
-  {
-    auto alg = construct_standard_algorithm();
-    alg->setProperty("MonitorIntegrationWavelengthMin", 1.0);
-    alg->setProperty("MonitorIntegrationWavelengthMax", 0.0);
-    TS_ASSERT_THROWS(alg->execute(), std::invalid_argument);
-  }
-
-  void test_monitor_index_positive()
-  {
-    auto alg = construct_standard_algorithm();
-    TS_ASSERT_THROWS(alg->setProperty("I0MonitorIndex", -1), std::invalid_argument);
-  }
-
-  void test_workspace_index_list_throw_if_not_pairs()
-  {
-    auto alg = construct_standard_algorithm();
-    alg->setProperty("ProcessingInstructions", "0");
-    TS_ASSERT_THROWS(alg->execute(), std::runtime_error);
   }
 
-  void test_workspace_index_list_values_not_positive_throws()
-  {
-    auto alg = construct_standard_algorithm();
-    alg->setProperty("ProcessingInstructions", "-1, 0"); //-1 is not acceptable.
-    TS_ASSERT_THROWS(alg->execute(), std::invalid_argument);
-  }
-
-  void test_workspace_index_list_min_max_pairs_throw_if_min_greater_than_max()
-  {
-    auto alg = construct_standard_algorithm();
-    alg->setProperty("ProcessingInstructions", "1, 0"); //1 > 0.
-    TS_ASSERT_THROWS(alg->execute(), std::out_of_range);
-  }
-
-  void test_spectrum_map_mismatch_throws()
-  {
-    // Name of the output workspace.
-    IAlgorithm_sptr lAlg = AlgorithmManager::Instance().create("Load");
-    lAlg->initialize();
-    lAlg->setPropertyValue("Filename", "INTER00013463.nxs");
-    lAlg->setPropertyValue("OutputWorkspace", inWSName);
-    lAlg->execute(); 
-    MatrixWorkspace_sptr trans1 = AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>(inWSName);
-
-    IAlgorithm_sptr alg = AlgorithmManager::Instance().create("CreateTransmissionWorkspaceAuto");
-    TS_ASSERT_THROWS_NOTHING( alg->initialize() );
-    TS_ASSERT( alg->isInitialized() );
-    alg->setRethrows(true);
-    TS_ASSERT_THROWS_NOTHING( alg->setProperty("FirstTransmissionRun", trans1); );
-    TS_ASSERT_THROWS_NOTHING( alg->setProperty("SecondTransmissionRun", m_TOF); );
-    TS_ASSERT_THROWS_NOTHING( alg->setProperty("ProcessingInstructions", "3,4"); );
-    MantidVec params = boost::assign::list_of(0.0)(0.1)(1.0).convert_to_container<MantidVec>();
-    TS_ASSERT_THROWS_NOTHING( alg->setProperty("Params", params); );
-    TS_ASSERT_THROWS_NOTHING( alg->setProperty("StartOverlap", 1.0); );
-    TS_ASSERT_THROWS_NOTHING( alg->setProperty("EndOverlap", 2.0); );
-    TS_ASSERT_THROWS_NOTHING( alg->setPropertyValue("OutputWorkspace", outWSName); );
-    TS_ASSERT_THROWS(alg->execute(), std::invalid_argument);
-
-    // Remove workspace from the data service.
-    AnalysisDataService::Instance().remove(outWSName);
-  }
-
-  void test_execute_one_tranmission()
-  {
-    // Name of the output workspace.
-    IAlgorithm_sptr lAlg = AlgorithmManager::Instance().create("Load");
-    lAlg->initialize();
-    lAlg->setPropertyValue("Filename", "INTER00013463.nxs");
-    lAlg->setPropertyValue("OutputWorkspace", inWSName);
-    lAlg->execute(); 
-    MatrixWorkspace_sptr trans1 = AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>(inWSName);
-
-    IAlgorithm_sptr alg = AlgorithmManager::Instance().create("CreateTransmissionWorkspaceAuto");
-    TS_ASSERT_THROWS_NOTHING( alg->initialize() );
-    TS_ASSERT( alg->isInitialized() );
-    TS_ASSERT_THROWS_NOTHING( alg->setProperty("FirstTransmissionRun", trans1); );
-    TS_ASSERT_THROWS_NOTHING( alg->setProperty("ProcessingInstructions", "3,4"); );
-    TS_ASSERT_THROWS_NOTHING( alg->setProperty("I0MonitorIndex",0 ); );
-    TS_ASSERT_THROWS_NOTHING( alg->setProperty("WavelengthMin", 0.0); );
-    TS_ASSERT_THROWS_NOTHING( alg->setProperty("WavelengthMax", 17.9); );
-    TS_ASSERT_THROWS_NOTHING( alg->setProperty("WavelengthStep", 0.5); );
-    TS_ASSERT_THROWS_NOTHING( alg->setProperty("MonitorBackgroundWavelengthMin", 15.0); );
-    TS_ASSERT_THROWS_NOTHING( alg->setProperty("MonitorBackgroundWavelengthMax", 17.0); );
-    TS_ASSERT_THROWS_NOTHING( alg->setProperty("MonitorIntegrationWavelengthMin", 4.0); );
-    TS_ASSERT_THROWS_NOTHING( alg->setProperty("MonitorIntegrationWavelengthMax", 10.0); );
-    TS_ASSERT_THROWS_NOTHING( alg->setPropertyValue("OutputWorkspace", outWSName); );
-    TS_ASSERT_THROWS_NOTHING( alg->execute(); );
-    TS_ASSERT( alg->isExecuted() );
-
-    MatrixWorkspace_sptr outWS;
-    TS_ASSERT_THROWS_NOTHING( outWS = AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>(outWSName); );
-
-    TS_ASSERT_EQUALS("Wavelength", outWS->getAxis(0)->unit()->unitID());
-
-    //Because we have one transmission workspace, binning should come from the WavelengthStep.
-    auto x = outWS->readX(0);
-    auto actual_binning = x[1] - x[0];
-    double step = alg->getProperty("WavelengthStep");
-    TS_ASSERT_DELTA(step, actual_binning, 0.0000001);
-
-    // Remove workspace from the data service.
-    AnalysisDataService::Instance().remove(outWSName);
-    AnalysisDataService::Instance().remove(inWSName);
-  }
-
-  void test_execute_two_tranmissions()
-  {
-    // Name of the output workspace.
-    IAlgorithm_sptr lAlg = AlgorithmManager::Instance().create("Load");
-    lAlg->initialize();
-    lAlg->setPropertyValue("Filename", "INTER00013463.nxs");
-    lAlg->setPropertyValue("OutputWorkspace", inWSName + "1");
-    lAlg->execute(); 
-    MatrixWorkspace_sptr trans1 = AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>(inWSName + "1");
-    lAlg->setPropertyValue("Filename", "INTER00013464.nxs");
-    lAlg->setPropertyValue("OutputWorkspace", inWSName + "2");
-    lAlg->execute();
-    MatrixWorkspace_sptr trans2 = AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>(inWSName + "2");
-
-    IAlgorithm_sptr alg = AlgorithmManager::Instance().create("CreateTransmissionWorkspaceAuto");
-    TS_ASSERT_THROWS_NOTHING( alg->initialize() );
-    TS_ASSERT( alg->isInitialized() );
-    TS_ASSERT_THROWS_NOTHING( alg->setProperty("ProcessingInstructions", "3,4"); );
-    TS_ASSERT_THROWS_NOTHING( alg->setProperty("FirstTransmissionRun", trans1); );
-    TS_ASSERT_THROWS_NOTHING( alg->setProperty("SecondTransmissionRun", trans2); );
-    TS_ASSERT_THROWS_NOTHING( alg->setProperty("I0MonitorIndex", 0); );
-    TS_ASSERT_THROWS_NOTHING( alg->setProperty("WavelengthMin", 0.0); );
-    TS_ASSERT_THROWS_NOTHING( alg->setProperty("WavelengthMax", 17.9); );
-    TS_ASSERT_THROWS_NOTHING( alg->setProperty("WavelengthStep", 0.5); );
-    TS_ASSERT_THROWS_NOTHING( alg->setProperty("MonitorBackgroundWavelengthMin", 15.0); );
-    TS_ASSERT_THROWS_NOTHING( alg->setProperty("MonitorBackgroundWavelengthMax", 17.0); );
-    TS_ASSERT_THROWS_NOTHING( alg->setProperty("MonitorIntegrationWavelengthMin", 4.0); );
-    TS_ASSERT_THROWS_NOTHING( alg->setProperty("MonitorIntegrationWavelengthMax", 10.0); );
-    MantidVec params = boost::assign::list_of(1.5)(0.02)(17).convert_to_container<MantidVec>();
-    TS_ASSERT_THROWS_NOTHING( alg->setProperty("Params", params); );
-    TS_ASSERT_THROWS_NOTHING( alg->setProperty("StartOverlap", 10.0); );
-    TS_ASSERT_THROWS_NOTHING( alg->setProperty("EndOverlap", 12.0); );
-    TS_ASSERT_THROWS_NOTHING( alg->setPropertyValue("OutputWorkspace", outWSName); );
-    TS_ASSERT_THROWS_NOTHING( alg->execute(); );
-    TS_ASSERT( alg->isExecuted() );
-
-    MatrixWorkspace_sptr outWS;
-    TS_ASSERT_THROWS_NOTHING( outWS = AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>(outWSName); );
-
-    TS_ASSERT_EQUALS("Wavelength", outWS->getAxis(0)->unit()->unitID());
-
-    //Because we have two transmission workspaces, binning should come from the Params for stitching.
-    auto x = outWS->readX(0);
-    auto actual_binning = x[1] - x[0];
-    MantidVec outparams = alg->getProperty("Params");
-    TS_ASSERT_DELTA(actual_binning, params[1], 0.0000001);
-    TS_ASSERT_DELTA(1.5, params[0], 0.0000001);
-    TS_ASSERT_DELTA(17, params[2], 0.0000001);
-
-    // Remove workspace from the data service.
-    AnalysisDataService::Instance().remove(outWSName);
-    AnalysisDataService::Instance().remove(inWSName + "1");
-    AnalysisDataService::Instance().remove(inWSName + "2");
-  }
-
-  void test_execute_two_tranmissions_with_minimal_property()
-  {
-    // Name of the output workspace.
-    IAlgorithm_sptr lAlg = AlgorithmManager::Instance().create("Load");
-    lAlg->initialize();
-    lAlg->setPropertyValue("Filename", "INTER00013463.nxs");
-    lAlg->setPropertyValue("OutputWorkspace", inWSName + "1");
-    lAlg->execute();
-    MatrixWorkspace_sptr trans1 = AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>(inWSName + "1");
-    lAlg->setPropertyValue("Filename", "INTER00013464.nxs");
-    lAlg->setPropertyValue("OutputWorkspace", inWSName + "2");
-    lAlg->execute();
-    MatrixWorkspace_sptr trans2 = AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>(inWSName + "2");
-
-    IAlgorithm_sptr alg = AlgorithmManager::Instance().create("CreateTransmissionWorkspaceAuto");
-    TS_ASSERT_THROWS_NOTHING( alg->initialize() );
-    TS_ASSERT( alg->isInitialized() );
-    TS_ASSERT_THROWS_NOTHING( alg->setProperty("ProcessingInstructions", "3,4"); );
-    TS_ASSERT_THROWS_NOTHING( alg->setProperty("FirstTransmissionRun", trans1); );
-    TS_ASSERT_THROWS_NOTHING( alg->setProperty("SecondTransmissionRun", trans2); );
-    TS_ASSERT_THROWS_NOTHING( alg->setProperty("I0MonitorIndex", 0); );
-    TS_ASSERT_THROWS_NOTHING( alg->setProperty("WavelengthMin", 0.0); );
-    TS_ASSERT_THROWS_NOTHING( alg->setProperty("WavelengthMax", 17.9); );
-    TS_ASSERT_THROWS_NOTHING( alg->setProperty("WavelengthStep", 0.5); );
-    TS_ASSERT_THROWS_NOTHING( alg->setProperty("MonitorBackgroundWavelengthMin", 15.0); );
-    TS_ASSERT_THROWS_NOTHING( alg->setProperty("MonitorBackgroundWavelengthMax", 17.0); );
-    TS_ASSERT_THROWS_NOTHING( alg->setProperty("MonitorIntegrationWavelengthMin", 4.0); );
-    TS_ASSERT_THROWS_NOTHING( alg->setProperty("MonitorIntegrationWavelengthMax", 10.0); );
-    MantidVec params = boost::assign::list_of(1.5)(0.02)(17).convert_to_container<MantidVec>();
-    // TS_ASSERT_THROWS_NOTHING( alg->setProperty("Params", params); ); // DO NOT SPECIFY PARAMS
-    //TS_ASSERT_THROWS_NOTHING( alg->setProperty("StartOverlap", 10.0); ); // DO NOT SPECIFY STARTOVERLAP
-    //TS_ASSERT_THROWS_NOTHING( alg->setProperty("EndOverlap", 12.0); ); // DO NOT SPECIFY END OVERLAP
-    TS_ASSERT_THROWS_NOTHING( alg->setPropertyValue("OutputWorkspace", outWSName); );
-    TS_ASSERT_THROWS_NOTHING( alg->execute(); );
-    TS_ASSERT( alg->isExecuted() );
-
-    MatrixWorkspace_sptr outWS;
-    TS_ASSERT_THROWS_NOTHING( outWS = AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>(outWSName); );
-
-    TS_ASSERT_EQUALS("Wavelength", outWS->getAxis(0)->unit()->unitID());
-
-    // Remove workspace from the data service.
-    AnalysisDataService::Instance().remove(outWSName);
-    AnalysisDataService::Instance().remove(inWSName + "1");
-    AnalysisDataService::Instance().remove(inWSName + "2");
-  }
 
 };
 
diff --git a/Code/Mantid/Framework/Algorithms/test/CreateTransmissionWorkspaceTest.h b/Code/Mantid/Framework/Algorithms/test/CreateTransmissionWorkspaceTest.h
new file mode 100644
index 0000000000000000000000000000000000000000..556bf9c3795aa82014460388cee65ce01b1b1e8a
--- /dev/null
+++ b/Code/Mantid/Framework/Algorithms/test/CreateTransmissionWorkspaceTest.h
@@ -0,0 +1,223 @@
+/*
+ * CreateTransmissionWorkspaceTest.h
+ *
+ *  Created on: Jul 29, 2014
+ *      Author: spu92482
+ */
+
+#ifndef ALGORITHMS_TEST_CREATETRANSMISSIONWORKSPACETEST_H_
+#define ALGORITHMS_TEST_CREATETRANSMISSIONWORKSPACETEST_H_
+
+#include <cxxtest/TestSuite.h>
+#include <algorithm>
+#include <boost/assign.hpp>
+#include "MantidAlgorithms/ReflectometryReductionOne.h"
+#include "MantidAPI/AlgorithmManager.h"
+#include "MantidAPI/FrameworkManager.h"
+#include "MantidAPI/MatrixWorkspace.h"
+#include "MantidTestHelpers/WorkspaceCreationHelper.h"
+#include "MantidGeometry/Instrument/ReferenceFrame.h"
+
+using namespace Mantid;
+using namespace Mantid::Kernel;
+using namespace Mantid::API;
+using namespace Mantid::Algorithms;
+using namespace WorkspaceCreationHelper;
+
+class CreateTransmissionWorkspaceTest: public CxxTest::TestSuite
+{
+private:
+
+  MatrixWorkspace_sptr m_tinyReflWS;
+  MatrixWorkspace_sptr m_TOF;
+  MatrixWorkspace_sptr m_NotTOF;
+
+private:
+
+  IAlgorithm_sptr construct_standard_algorithm()
+  {
+    auto alg = AlgorithmManager::Instance().create("CreateTransmissionWorkspaceAuto");
+    alg->initialize();
+    alg->setChild(true);
+    alg->setProperty("FirstTransmissionRun", m_TOF);
+    alg->setProperty("WavelengthMin", 0.0);
+    alg->setProperty("WavelengthMax", 1.0);
+    alg->setProperty("I0MonitorIndex", 0);
+    alg->setPropertyValue("ProcessingInstructions", "0, 1");
+    alg->setProperty("MonitorBackgroundWavelengthMin", 0.0);
+    alg->setProperty("MonitorBackgroundWavelengthMax", 1.0);
+    alg->setProperty("MonitorIntegrationWavelengthMin", 0.0);
+    alg->setProperty("MonitorIntegrationWavelengthMax", 1.0);
+    alg->setPropertyValue("OutputWorkspace", "demo_ws");
+    alg->setRethrows(true);
+    return alg;
+  }
+
+public:
+
+  // This pair of boilerplate methods prevent the suite being created statically
+  // This means the constructor isn't called when running other tests
+  static CreateTransmissionWorkspaceTest *createSuite()
+  {
+    return new CreateTransmissionWorkspaceTest();
+  }
+  static void destroySuite(CreateTransmissionWorkspaceTest *suite)
+  {
+    delete suite;
+  }
+
+  CreateTransmissionWorkspaceTest()
+  {
+    m_tinyReflWS = create2DWorkspaceWithReflectometryInstrument();
+
+    FrameworkManager::Instance();
+    MantidVec xData = boost::assign::list_of(0)(0)(0)(0).convert_to_container<MantidVec>();
+    MantidVec yData = boost::assign::list_of(0)(0)(0).convert_to_container<MantidVec>();
+
+    auto createWorkspace = AlgorithmManager::Instance().createUnmanaged("CreateWorkspace");
+    createWorkspace->setChild(true);
+    createWorkspace->initialize();
+    createWorkspace->setProperty("UnitX", "1/q");
+    createWorkspace->setProperty("DataX", xData);
+    createWorkspace->setProperty("DataY", yData);
+    createWorkspace->setProperty("NSpec", 1);
+    createWorkspace->setPropertyValue("OutputWorkspace", "UnitWS");
+    createWorkspace->execute();
+    m_NotTOF = createWorkspace->getProperty("OutputWorkspace");
+
+    createWorkspace->setProperty("UnitX", "TOF");
+    createWorkspace->setProperty("DataX", xData);
+    createWorkspace->setProperty("DataY", yData);
+    createWorkspace->setProperty("NSpec", 1);
+    createWorkspace->execute();
+    m_TOF = createWorkspace->getProperty("OutputWorkspace");
+
+  }
+
+  void test_check_first_transmission_workspace_not_tof_or_wavelength_throws()
+  {
+    auto alg = construct_standard_algorithm();
+    TS_ASSERT_THROWS(alg->setProperty("FirstTransmissionRun", m_NotTOF), std::invalid_argument);
+  }
+
+  void test_check_second_transmission_workspace_not_tof_throws()
+  {
+    auto alg = construct_standard_algorithm();
+    TS_ASSERT_THROWS(alg->setProperty("SecondTransmissionRun", m_NotTOF), std::invalid_argument);
+  }
+
+  void test_end_overlap_must_be_greater_than_start_overlap_or_throw()
+  {
+    auto alg = construct_standard_algorithm();
+    alg->setProperty("FirstTransmissionRun", m_TOF);
+    alg->setProperty("SecondTransmissionRun", m_TOF);
+    MantidVec params = boost::assign::list_of(0.0)(0.1)(1.0).convert_to_container<MantidVec>();
+    alg->setProperty("Params", params);
+    alg->setProperty("StartOverlap", 0.6);
+    alg->setProperty("EndOverlap", 0.4);
+    TS_ASSERT_THROWS(alg->execute(), std::invalid_argument);
+  }
+
+  void test_must_provide_wavelengths()
+  {
+    auto alg = AlgorithmManager::Instance().create("CreateTransmissionWorkspace");
+    alg->initialize();
+    alg->setChild(true);
+    alg->setProperty("FirstTransmissionRun", m_TOF);
+    alg->setProperty("SecondTransmissionRun", m_TOF);
+    alg->setPropertyValue("OutputWorkspace", "demo_ws");
+    alg->setRethrows(true);
+    TS_ASSERT_THROWS(alg->execute(), std::runtime_error);
+
+    alg->setProperty("FirstTransmissionRun", m_TOF);
+    alg->setProperty("SecondTransmissionRun", m_TOF);
+    alg->setProperty("WavelengthMin", 1.0);
+    alg->setRethrows(true);
+    TS_ASSERT_THROWS(alg->execute(), std::runtime_error);
+  }
+
+  void test_wavelength_min_greater_wavelength_max_throws()
+  {
+    auto alg = construct_standard_algorithm();
+    alg->setProperty("WavelengthMin", 1.0);
+    alg->setProperty("WavelengthMax", 0.0);
+    TS_ASSERT_THROWS(alg->execute(), std::invalid_argument);
+  }
+
+  void test_monitor_background_wavelength_min_greater_monitor_background_wavelength_max_throws()
+  {
+    auto alg = construct_standard_algorithm();
+    alg->setProperty("MonitorBackgroundWavelengthMin", 1.0);
+    alg->setProperty("MonitorBackgroundWavelengthMax", 0.0);
+    TS_ASSERT_THROWS(alg->execute(), std::invalid_argument);
+  }
+
+  void test_monitor_integration_wavelength_min_greater_monitor_integration_wavelength_max_throws()
+  {
+    auto alg = construct_standard_algorithm();
+    alg->setProperty("MonitorIntegrationWavelengthMin", 1.0);
+    alg->setProperty("MonitorIntegrationWavelengthMax", 0.0);
+    TS_ASSERT_THROWS(alg->execute(), std::invalid_argument);
+  }
+
+  void test_monitor_index_positive()
+  {
+    auto alg = construct_standard_algorithm();
+    TS_ASSERT_THROWS(alg->setProperty("I0MonitorIndex", -1), std::invalid_argument);
+  }
+
+  void test_workspace_index_list_throw_if_not_pairs()
+  {
+    auto alg = construct_standard_algorithm();
+    alg->setProperty("ProcessingInstructions", "0");
+    TS_ASSERT_THROWS(alg->execute(), std::runtime_error);
+  }
+
+  void test_workspace_index_list_values_not_positive_throws()
+  {
+    auto alg = construct_standard_algorithm();
+    alg->setProperty("ProcessingInstructions", "-1, 0"); //-1 is not acceptable.
+    TS_ASSERT_THROWS(alg->execute(), std::invalid_argument);
+  }
+
+  void test_workspace_index_list_min_max_pairs_throw_if_min_greater_than_max()
+  {
+    auto alg = construct_standard_algorithm();
+    alg->setProperty("ProcessingInstructions", "1, 0"); //1 > 0.
+    TS_ASSERT_THROWS(alg->execute(), std::out_of_range);
+  }
+
+  void test_execute_one_tranmission()
+  {
+
+    IAlgorithm_sptr alg = AlgorithmManager::Instance().create("CreateTransmissionWorkspace");
+
+    alg->setChild(true);
+    alg->initialize();
+
+    alg->setProperty("FirstTransmissionRun", m_tinyReflWS);
+    alg->setProperty("WavelengthMin", 1.0);
+    alg->setProperty("WavelengthMax", 15.0);
+    alg->setProperty("WavelengthStep", 0.05);
+    alg->setProperty("I0MonitorIndex", 0);
+    alg->setProperty("MonitorBackgroundWavelengthMin", 14.0);
+    alg->setProperty("MonitorBackgroundWavelengthMax", 15.0);
+    alg->setProperty("MonitorIntegrationWavelengthMin", 4.0);
+    alg->setProperty("MonitorIntegrationWavelengthMax", 10.0);
+    alg->setPropertyValue("ProcessingInstructions", "1");
+    alg->setPropertyValue("OutputWorkspace", "demo_ws");
+    alg->execute();
+
+    MatrixWorkspace_sptr outWS = alg->getProperty("OutputWorkspace");
+    TS_ASSERT_EQUALS("Wavelength", outWS->getAxis(0)->unit()->unitID());
+
+    //Because we have one transmission workspace, binning should come from the WavelengthStep.
+    auto x = outWS->readX(0);
+    auto actual_binning = x[1] - x[0];
+    double step = alg->getProperty("WavelengthStep");
+    TS_ASSERT_DELTA(step, actual_binning, 0.0001);
+  }
+};
+
+
+#endif /* ALGORITHMS_TEST_CREATETRANSMISSIONWORKSPACETEST_H_ */
diff --git a/Code/Mantid/Framework/Algorithms/test/GenerateEventsFilterTest.h b/Code/Mantid/Framework/Algorithms/test/GenerateEventsFilterTest.h
index 01be5e3f1c54acd86fcf13f30216f3237e5b928d..7fd57ca80ac5ae540a80f1a34ca31045c1e7f3c8 100644
--- a/Code/Mantid/Framework/Algorithms/test/GenerateEventsFilterTest.h
+++ b/Code/Mantid/Framework/Algorithms/test/GenerateEventsFilterTest.h
@@ -173,14 +173,14 @@ public:
   //----------------------------------------------------------------------------------------------
   /** Generate filter by log value in simple way
    * (1) No time tolerance
-   * (2) Just one
+   * (2) Just one region
    */
   void test_genSimpleLogValueFilter()
   {
-    // 1. Create input
+    // Create input
     DataObjects::EventWorkspace_sptr eventWS = createEventWorkspace();
 
-    // 2. Init and set property
+    // Init and set property
     GenerateEventsFilter alg;
     alg.initialize();
 
@@ -212,7 +212,7 @@ public:
      TS_ASSERT_EQUALS(splittersws->getNumberSplitters(), numsplitters);
 
      Kernel::SplittingInterval s0 = splittersws->getSplitter(0);
-     TS_ASSERT_EQUALS(s0.start().totalNanoseconds(), 3000025000-static_cast<int64_t>(1.0E-8*1.0E9));
+     TS_ASSERT_EQUALS(s0.start().totalNanoseconds(), 3000000000-static_cast<int64_t>(1.0E-8*1.0E9));
      TS_ASSERT_EQUALS(s0.stop().totalNanoseconds(), 3000050000-static_cast<int64_t>(1.0E-8*1.0E9));
 
      Kernel::SplittingInterval s1 = splittersws->getSplitter(1);
@@ -235,12 +235,10 @@ public:
    */
   void test_genMultipleLogValuesFilter()
   {
-    std::cout << "\n==== Test Multiple Log Value Filter ====\n" << std::endl;
-
-    // 1. Create input
+    // Create input
     DataObjects::EventWorkspace_sptr eventWS = createEventWorkspace();
 
-    // 2. Init and set property
+    // Init and set property
     GenerateEventsFilter alg;
     alg.initialize();
 
@@ -256,11 +254,11 @@ public:
     TS_ASSERT_THROWS_NOTHING(alg.setProperty("TimeTolerance", 1.0E-8));
     TS_ASSERT_THROWS_NOTHING(alg.setProperty("LogBoundary",  "Centre"));
 
-    // 3. Running and get result
+    // Running and get result
     TS_ASSERT_THROWS_NOTHING(alg.execute());
     TS_ASSERT(alg.isExecuted());
 
-    // 4. Check output
+    // Check output
      DataObjects::SplittersWorkspace_sptr splittersws =
          boost::dynamic_pointer_cast<DataObjects::SplittersWorkspace>(AnalysisDataService::Instance().retrieve("Splitters04"));
      TS_ASSERT(splittersws);
@@ -269,20 +267,20 @@ public:
          boost::dynamic_pointer_cast<DataObjects::TableWorkspace>(AnalysisDataService::Instance().retrieve("Information"));
      TS_ASSERT(infows);
 
-     // 5. Check
-     size_t numsplitters = 15;
+     // Check
+     size_t numsplitters = 16;
      TS_ASSERT_EQUALS(splittersws->getNumberSplitters(), numsplitters);
      size_t numoutputs = 11;
      TS_ASSERT_EQUALS(infows->rowCount(), numoutputs);
 
      Kernel::SplittingInterval s0 = splittersws->getSplitter(0);
-     TS_ASSERT_EQUALS(s0.start(), 3000024990);
-     TS_ASSERT_EQUALS(s0.index(), 6);
+     TS_ASSERT_EQUALS(s0.start(), 3000000000-static_cast<int>(1.0E-8*1.0E9));
+     TS_ASSERT_EQUALS(s0.index(), 5);
 
-     Kernel::SplittingInterval s14 = splittersws->getSplitter(14);
-     TS_ASSERT_EQUALS(s14.start(), 3000924990);
-     TS_ASSERT_EQUALS(s14.stop(),  3000974990);
-     TS_ASSERT_EQUALS(s14.index(), 9);
+     Kernel::SplittingInterval s15 = splittersws->getSplitter(15);
+     TS_ASSERT_EQUALS(s15.start(), 3000924990);
+     TS_ASSERT_EQUALS(s15.stop(),  3000974990);
+     TS_ASSERT_EQUALS(s15.index(), 9);
 
   }
 
@@ -347,6 +345,61 @@ public:
      AnalysisDataService::Instance().remove("IntLogInformation");
   }
 
+  //----------------------------------------------------------------------------------------------
+  /** Test to generate a set of filters against an integer log by using the single value mode
+    */
+  void test_genFilterByIntegerLog2()
+  {
+    // Create input
+    DataObjects::EventWorkspace_sptr eventWS = createEventWorkspaceIntLog();
+    AnalysisDataService::Instance().addOrReplace("TestEventData2", eventWS);
+
+    // Initialize and set property
+    GenerateEventsFilter alg;
+    alg.initialize();
+
+    TS_ASSERT_THROWS_NOTHING(alg.setProperty("InputWorkspace", "TestEventData2"));
+    TS_ASSERT_THROWS_NOTHING(alg.setProperty("OutputWorkspace", "IntLogSplitter"));
+    TS_ASSERT_THROWS_NOTHING(alg.setProperty("InformationWorkspace", "IntLogInformation"));
+    TS_ASSERT_THROWS_NOTHING(alg.setProperty("LogName", "DummyIntLog"));
+    TS_ASSERT_THROWS_NOTHING(alg.setProperty("MinimumLogValue", static_cast<double>(1)));
+    TS_ASSERT_THROWS_NOTHING(alg.setProperty("MaximumLogValue", static_cast<double>(2)));
+    TS_ASSERT_THROWS_NOTHING(alg.setProperty("UnitOfTime", "Seconds"));
+    TS_ASSERT_THROWS_NOTHING(alg.setProperty("FilterLogValueByChangingDirection", "Both"));
+    TS_ASSERT_THROWS_NOTHING(alg.setProperty("TimeTolerance", 0.05));
+    TS_ASSERT_THROWS_NOTHING(alg.setProperty("LogBoundary",  "Centre"));
+
+    // Running and get result
+    TS_ASSERT_THROWS_NOTHING(alg.execute());
+    TS_ASSERT(alg.isExecuted());
+
+    // Retrieve output workspaces
+    SplittersWorkspace_sptr splittersws = boost::dynamic_pointer_cast<SplittersWorkspace>(
+          AnalysisDataService::Instance().retrieve("IntLogSplitter"));
+    TS_ASSERT(splittersws);
+
+    TableWorkspace_const_sptr infows = boost::dynamic_pointer_cast<TableWorkspace>(
+          AnalysisDataService::Instance().retrieve("IntLogInformation"));
+    TS_ASSERT(infows);
+
+     // Check output workspace
+     size_t numsplitters = 1;
+     TS_ASSERT_EQUALS(splittersws->getNumberSplitters(), numsplitters);
+     size_t numoutputs = 1;
+     TS_ASSERT_EQUALS(infows->rowCount(), numoutputs);
+
+     int64_t factor = static_cast<int64_t>(1.0E9+0.5);
+
+     Kernel::SplittingInterval s0 = splittersws->getSplitter(0);
+     TS_ASSERT_EQUALS(s0.start().totalNanoseconds(), 11*factor-5*factor/100);
+     TS_ASSERT_EQUALS(s0.index(), 0);
+
+     // Clean
+     AnalysisDataService::Instance().remove("TestEventData2");
+     AnalysisDataService::Instance().remove("IntLogSplitter");
+     AnalysisDataService::Instance().remove("IntLogInformation");
+  }
+
 
   //----------------------------------------------------------------------------------------------
   /** Create an EventWorkspace including
@@ -683,10 +736,9 @@ public:
     AnalysisDataService::Instance().remove("InfoWS04B");
     AnalysisDataService::Instance().remove("Splitters04C");
     AnalysisDataService::Instance().remove("InfoWS04C");
+  }
 
-    // TS_ASSERT_EQUALS(1, 100);
 
-  }
 
   //----------------------------------------------------------------------------------------------
   /** Generate filter by log values in increasing
@@ -695,8 +747,6 @@ public:
    */
   void test_genMultipleLogValuesFilterMatrixSplitterParallel()
   {
-    std::cout << "\n==== Test Multiple Log Value Filter (Matrix Splitter Parallel) ====\n" << std::endl;
-
     // Create input
     DataObjects::EventWorkspace_sptr eventWS = createEventWorkspace();
     AnalysisDataService::Instance().addOrReplace("TestEventWS04B", eventWS);
@@ -783,6 +833,112 @@ public:
 
   }
 
+  //----------------------------------------------------------------------------------------------
+  /** Generate filter by log values in 'FastLog' mode only 1 interval
+   */
+  void test_genSingleleLogValuesFilterMatrixSplitter()
+  {
+    std::cout << "\n==== Test Single Log Value Filter (Matrix Splitter) ====\n" << "\n";
+
+    // Create input
+    DataObjects::EventWorkspace_sptr eventWS = createEventWorkspace();
+    AnalysisDataService::Instance().addOrReplace("TestEventWS09", eventWS);
+
+    // Init and set property
+    GenerateEventsFilter alg;
+    alg.initialize();
+
+    TS_ASSERT_THROWS_NOTHING(alg.setProperty("InputWorkspace", "TestEventWS09"));
+    TS_ASSERT_THROWS_NOTHING(alg.setProperty("OutputWorkspace", "Splitters09"));
+    TS_ASSERT_THROWS_NOTHING(alg.setProperty("InformationWorkspace", "InfoWS09"));
+    TS_ASSERT_THROWS_NOTHING(alg.setProperty("FastLog", true));
+    TS_ASSERT_THROWS_NOTHING(alg.setProperty("LogName", "FastSineLog"));
+    TS_ASSERT_THROWS_NOTHING(alg.setProperty("MinimumLogValue", "-1.0"));
+    TS_ASSERT_THROWS_NOTHING(alg.setProperty("MaximumLogValue",  "1.0"));
+    TS_ASSERT_THROWS_NOTHING(alg.setProperty("LogValueTolerance", 0.05));
+    TS_ASSERT_THROWS_NOTHING(alg.setProperty("FilterLogValueByChangingDirection", "Both"));
+    TS_ASSERT_THROWS_NOTHING(alg.setProperty("TimeTolerance", 1.0E-8));
+    TS_ASSERT_THROWS_NOTHING(alg.setProperty("LogBoundary",  "Centre"));
+
+    // Running and get result
+    TS_ASSERT_THROWS_NOTHING(alg.execute());
+    TS_ASSERT(alg.isExecuted());
+
+    // Check output workspace
+    MatrixWorkspace_sptr splittersws =
+        boost::dynamic_pointer_cast<MatrixWorkspace>(AnalysisDataService::Instance().retrieve("Splitters09"));
+    TS_ASSERT(splittersws);
+    if (splittersws)
+      TS_ASSERT(splittersws->readX(0).size() >= 2);
+
+    DataObjects::TableWorkspace_const_sptr infows =
+        boost::dynamic_pointer_cast<DataObjects::TableWorkspace>(AnalysisDataService::Instance().retrieve("InfoWS09"));
+    TS_ASSERT(infows);
+
+
+    // Clean
+    AnalysisDataService::Instance().remove("TestEventWS09");
+    AnalysisDataService::Instance().remove("Splitters09");
+    AnalysisDataService::Instance().remove("InfoWS09");
+  }
+
+
+  //----------------------------------------------------------------------------------------------
+  /** Generate filter by integer log values in increasing in matrix workspace
+   * (1) No time tolerance
+   * (2) Just one
+   */
+  void test_genMultipleIntLogValuesFilterMatrixSplitter()
+  {
+    std::cout << "\n==== Test Multiple Integer Log Value Filter (Matrix Splitter) ====\n" << std::endl;
+
+    // Create input
+    DataObjects::EventWorkspace_sptr eventWS = createEventWorkspaceIntLog();
+    AnalysisDataService::Instance().addOrReplace("TestEventWS09", eventWS);
+
+    // Init and set property
+    GenerateEventsFilter alg;
+    alg.initialize();
+
+    TS_ASSERT_THROWS_NOTHING(alg.setProperty("InputWorkspace", "TestEventWS09"));
+    TS_ASSERT_THROWS_NOTHING(alg.setProperty("OutputWorkspace", "Splitters09"));
+    TS_ASSERT_THROWS_NOTHING(alg.setProperty("InformationWorkspace", "InfoWS09"));
+    TS_ASSERT_THROWS_NOTHING(alg.setProperty("FastLog", true));
+    TS_ASSERT_THROWS_NOTHING(alg.setProperty("LogName", "DummyIntLog"));
+    TS_ASSERT_THROWS_NOTHING(alg.setProperty("MinimumLogValue", static_cast<double>(1)));
+    TS_ASSERT_THROWS_NOTHING(alg.setProperty("MaximumLogValue", static_cast<double>(10)));
+    TS_ASSERT_THROWS_NOTHING(alg.setProperty("LogValueInterval", static_cast<double>(1)));
+    TS_ASSERT_THROWS_NOTHING(alg.setProperty("UnitOfTime", "Seconds"));
+    TS_ASSERT_THROWS_NOTHING(alg.setProperty("FilterLogValueByChangingDirection", "Both"));
+    TS_ASSERT_THROWS_NOTHING(alg.setProperty("TimeTolerance", 0.05));
+    TS_ASSERT_THROWS_NOTHING(alg.setProperty("LogBoundary",  "Centre"));
+
+    // Running and get result
+    TS_ASSERT_THROWS_NOTHING(alg.execute());
+    TS_ASSERT(alg.isExecuted());
+
+    // Check output workspace
+    MatrixWorkspace_sptr splittersws =
+        boost::dynamic_pointer_cast<MatrixWorkspace>(AnalysisDataService::Instance().retrieve("Splitters09"));
+    TS_ASSERT(splittersws);
+
+    DataObjects::TableWorkspace_const_sptr infows =
+        boost::dynamic_pointer_cast<DataObjects::TableWorkspace>(AnalysisDataService::Instance().retrieve("InfoWS09"));
+    TS_ASSERT(infows);
+
+    if (!splittersws || !infows)
+      return;
+
+    TS_ASSERT_EQUALS(splittersws->readY(0).size(), 10);
+
+    int64_t factor = static_cast<int64_t>(1.0E9+0.5);
+    TS_ASSERT_DELTA(splittersws->readX(0)[0], static_cast<double>(11*factor-5*factor/100), 0.000001);
+
+    TS_ASSERT_DELTA(splittersws->readY(0)[0], 0.0, 0.00001);
+    TS_ASSERT_DELTA(splittersws->readY(0)[1], 1.0, 0.00001);
+  }
+
+
   //----------------------------------------------------------------------------------------------
   /** Convert the splitters stored in a matrix workspace to a vector of SplittingInterval objects
     */
diff --git a/Code/Mantid/Framework/Algorithms/test/NormaliseToMonitorTest.h b/Code/Mantid/Framework/Algorithms/test/NormaliseToMonitorTest.h
index d238a916a8f2df1d3fa65520ae7210870cc5da9d..9dea3ac2185021c77de0a758e61888704aa337c3 100644
--- a/Code/Mantid/Framework/Algorithms/test/NormaliseToMonitorTest.h
+++ b/Code/Mantid/Framework/Algorithms/test/NormaliseToMonitorTest.h
@@ -321,7 +321,7 @@ public:
         TS_ASSERT_THROWS_NOTHING(pSett= monSpec->getSettings());
         TS_ASSERT_THROWS_NOTHING(pSett->applyChanges(&norm6, monSpec));
         // it should return the list of allowed monitor ID-s
-        std::set<std::string> monitors = monSpec->allowedValues();
+        std::vector<std::string> monitors = monSpec->allowedValues();
         TS_ASSERT_EQUALS(1,monitors.size());
         TS_ASSERT_EQUALS("0",*(monitors.begin()));
 
diff --git a/Code/Mantid/Framework/Algorithms/test/Rebin2DTest.h b/Code/Mantid/Framework/Algorithms/test/Rebin2DTest.h
index e8eb7aeaa0acebebdf3167bffee23b6e9ef8a649..38b94cfc4cdc1a6c9a29f2825dfd9ea770cc8174 100644
--- a/Code/Mantid/Framework/Algorithms/test/Rebin2DTest.h
+++ b/Code/Mantid/Framework/Algorithms/test/Rebin2DTest.h
@@ -247,12 +247,18 @@ class Rebin2DTestPerformance : public CxxTest::TestSuite
   
 public:
   
+  Rebin2DTestPerformance()
+  {
+    m_inputWS = makeInputWS(false, true);
+  }
+
   void test_On_Large_Workspace()
   {
-    MatrixWorkspace_sptr inputWS = makeInputWS(false, true);
-    runAlgorithm(inputWS, "100,200,41000", "-0.5,2,499.5");
+    runAlgorithm(m_inputWS, "100,200,41000", "-0.5,2,499.5");
   }
-  
+
+private:
+  MatrixWorkspace_sptr m_inputWS;
 
 };
 
diff --git a/Code/Mantid/Framework/Algorithms/test/ReflectometryReductionOneAutoTest.h b/Code/Mantid/Framework/Algorithms/test/ReflectometryReductionOneAutoTest.h
index 2e588c01b3c3e028a14c51e8d278bfe1338801f0..aa26694475e43634fa8fcea583cd0202320e3e7b 100644
--- a/Code/Mantid/Framework/Algorithms/test/ReflectometryReductionOneAutoTest.h
+++ b/Code/Mantid/Framework/Algorithms/test/ReflectometryReductionOneAutoTest.h
@@ -9,29 +9,68 @@
 #include <boost/assign/list_of.hpp>
 
 using Mantid::Algorithms::ReflectometryReductionOneAuto;
+using namespace Mantid::Kernel;
 using namespace Mantid::API;
 using namespace boost::assign;
 using Mantid::MantidVec;
 
-class ReflectometryReductionOneAutoTest : public CxxTest::TestSuite
+namespace
+{
+  class PropertyFinder
+  {
+  private:
+    const std::string m_propertyName;
+  public:
+    PropertyFinder(const std::string& propertyName) :
+        m_propertyName(propertyName)
+    {
+    }
+    bool operator()(const PropertyHistories::value_type& candidate) const
+    {
+      return candidate->name() == m_propertyName;
+    }
+  };
+
+  template<typename T>
+  T findPropertyValue(PropertyHistories& histories, const std::string& propertyName)
+  {
+    PropertyFinder finder(propertyName);
+    auto it = std::find_if(histories.begin(), histories.end(), finder);
+    return boost::lexical_cast<T>((*it)->value());
+  }
+
+}
+
+class ReflectometryReductionOneAutoTest: public CxxTest::TestSuite
 {
 public:
   // This pair of boilerplate methods prevent the suite being created statically
   // This means the constructor isn't called when running other tests
-  static ReflectometryReductionOneAutoTest *createSuite() { return new ReflectometryReductionOneAutoTest(); }
-  static void destroySuite( ReflectometryReductionOneAutoTest *suite ) { delete suite; }
+  static ReflectometryReductionOneAutoTest *createSuite()
+  {
+    return new ReflectometryReductionOneAutoTest();
+  }
+  static void destroySuite(ReflectometryReductionOneAutoTest *suite)
+  {
+    delete suite;
+  }
 
   MatrixWorkspace_sptr m_TOF;
   MatrixWorkspace_sptr m_NotTOF;
+  MatrixWorkspace_sptr m_dataWorkspace;
+  MatrixWorkspace_sptr m_transWorkspace1;
+  MatrixWorkspace_sptr m_transWorkspace2;
+  WorkspaceGroup_sptr m_multiDetectorWorkspace;
   const std::string outWSQName;
   const std::string outWSLamName;
   const std::string inWSName;
   const std::string transWSName;
 
-  ReflectometryReductionOneAutoTest(): outWSQName("ReflectometryReductionOneAutoTest_OutputWS_Q"),
-    outWSLamName("ReflectometryReductionOneAutoTest_OutputWS_Lam"),
-    inWSName("ReflectometryReductionOneAutoTest_InputWS"),
-    transWSName("ReflectometryReductionOneAutoTest_TransWS")
+  ReflectometryReductionOneAutoTest() :
+      outWSQName("ReflectometryReductionOneAutoTest_OutputWS_Q"), outWSLamName(
+          "ReflectometryReductionOneAutoTest_OutputWS_Lam"), inWSName(
+          "ReflectometryReductionOneAutoTest_InputWS"), transWSName(
+          "ReflectometryReductionOneAutoTest_TransWS")
   {
     MantidVec xData = boost::assign::list_of(0)(0)(0)(0).convert_to_container<MantidVec>();
     MantidVec yData = boost::assign::list_of(0)(0)(0).convert_to_container<MantidVec>();
@@ -53,8 +92,38 @@ public:
     createWorkspace->setPropertyValue("OutputWorkspace", "TOF");
     createWorkspace->execute();
     m_TOF = AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>("TOF");
-  }
 
+    IAlgorithm_sptr lAlg = AlgorithmManager::Instance().create("Load");
+    lAlg->setChild(true);
+    lAlg->initialize();
+    lAlg->setProperty("Filename", "INTER00013460.nxs");
+    lAlg->setPropertyValue("OutputWorkspace", "demo_ws");
+    lAlg->execute();
+    Workspace_sptr temp = lAlg->getProperty("OutputWorkspace");
+    m_dataWorkspace = boost::dynamic_pointer_cast<MatrixWorkspace>(temp);
+    //m_dataWorkspace = AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>("data_ws");
+
+    lAlg->setProperty("Filename", "INTER00013463.nxs");
+    lAlg->setPropertyValue("OutputWorkspace", "trans_ws_1");
+    lAlg->execute();
+    temp = lAlg->getProperty("OutputWorkspace");
+    m_transWorkspace1 = boost::dynamic_pointer_cast<MatrixWorkspace>(temp);
+    //m_transWorkspace1 = AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>("trans_ws_1");
+
+    lAlg->setProperty("Filename", "INTER00013464.nxs");
+    lAlg->setPropertyValue("OutputWorkspace", "trans_ws_2");
+    lAlg->execute();
+    temp = lAlg->getProperty("OutputWorkspace");
+    m_transWorkspace2 = boost::dynamic_pointer_cast<MatrixWorkspace>(temp);
+    //m_transWorkspace2 = AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>("trans_ws_2");
+
+    lAlg->setPropertyValue("Filename", "POLREF00004699.nxs");
+    lAlg->setPropertyValue("OutputWorkspace", "multidetector_ws_1");
+    lAlg->execute();
+    temp = lAlg->getProperty("OutputWorkspace");
+    m_multiDetectorWorkspace = boost::dynamic_pointer_cast<WorkspaceGroup>(temp);
+    //m_multiDetectorWorkspace = AnalysisDataService::Instance().retrieveWS<WorkspaceGroup>( "multidetector_ws_1");
+  }
   ~ReflectometryReductionOneAutoTest()
   {
     AnalysisDataService::Instance().remove("TOF");
@@ -83,72 +152,8 @@ public:
   void test_Init()
   {
     ReflectometryReductionOneAuto alg;
-    TS_ASSERT_THROWS_NOTHING( alg.initialize() );
-    TS_ASSERT( alg.isInitialized() );
-  }
-
-  void test_exec()
-  {
-    // Name of the output workspace.
-
-    IAlgorithm_sptr lAlg = AlgorithmManager::Instance().create("Load");
-    lAlg->setRethrows(true);
-    lAlg->initialize();
-    lAlg->setPropertyValue("Filename", "INTER00013463.nxs");
-    lAlg->setPropertyValue("OutputWorkspace", transWSName);
-    lAlg->execute();
-    lAlg->setPropertyValue("Filename", "INTER00013460.nxs");
-    lAlg->setPropertyValue("OutputWorkspace", inWSName);
-    lAlg->execute();
-    MatrixWorkspace_sptr ws = AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>(inWSName);
-    MatrixWorkspace_sptr tws = AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>(transWSName);
-
-    IAlgorithm_sptr alg = AlgorithmManager::Instance().create("ReflectometryReductionOneAuto");
-    alg->setRethrows(true);
-    TS_ASSERT_THROWS_NOTHING( alg->initialize() );
-    TS_ASSERT( alg->isInitialized() );
-    TS_ASSERT_THROWS_NOTHING( alg->setProperty("InputWorkspace", ws); );
-    TS_ASSERT_THROWS_NOTHING( alg->setProperty("AnalysisMode", "PointDetectorAnalysis"); );
-    TS_ASSERT_THROWS_NOTHING( alg->setPropertyValue("OutputWorkspace", outWSQName); );
-    TS_ASSERT_THROWS_NOTHING( alg->setPropertyValue("OutputWorkspaceWavelength", outWSLamName); );
-    TS_ASSERT_THROWS_NOTHING( alg->execute(); );
-    TS_ASSERT( alg->isExecuted() );
-
-    MatrixWorkspace_sptr outWS;
-    TS_ASSERT_THROWS_NOTHING( outWS = AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>(outWSQName); );
-
-    auto inst = tws->getInstrument();
-    auto history = outWS->getHistory();
-    auto algHist = history.getAlgorithmHistory(history.size()-1);
-    auto historyAlg = algHist->getChildAlgorithm(0);
-
-    double wavelengthMin = historyAlg->getProperty("WavelengthMin");
-    double wavelengthMax = historyAlg->getProperty("WavelengthMax");
-    double monitorBackgroundWavelengthMin = historyAlg->getProperty("MonitorBackgroundWavelengthMin");
-    double monitorBackgroundWavelengthMax = historyAlg->getProperty("MonitorBackgroundWavelengthMax");
-    double monitorIntegrationWavelengthMin = historyAlg->getProperty("MonitorIntegrationWavelengthMin");
-    double monitorIntegrationWavelengthMax = historyAlg->getProperty("MonitorIntegrationWavelengthMax");
-    int i0MonitorIndex = historyAlg->getProperty("I0MonitorIndex");
-    std::string processingInstructions = historyAlg->getProperty("ProcessingInstructions");
-    std::vector<std::string> pointDetectorStartStop;
-    boost::split(pointDetectorStartStop,processingInstructions,boost::is_any_of(","));
-
-    TS_ASSERT_EQUALS(inst->getNumberParameter("LambdaMin")[0], wavelengthMin);
-    TS_ASSERT_EQUALS(inst->getNumberParameter("LambdaMax")[0], wavelengthMax);
-    TS_ASSERT_EQUALS(inst->getNumberParameter("MonitorBackgroundMin")[0], monitorBackgroundWavelengthMin);
-    TS_ASSERT_EQUALS(inst->getNumberParameter("MonitorBackgroundMax")[0], monitorBackgroundWavelengthMax);
-    TS_ASSERT_EQUALS(inst->getNumberParameter("MonitorIntegralMin")[0], monitorIntegrationWavelengthMin);
-    TS_ASSERT_EQUALS(inst->getNumberParameter("MonitorIntegralMax")[0], monitorIntegrationWavelengthMax);
-    TS_ASSERT_EQUALS(inst->getNumberParameter("I0MonitorIndex")[0], i0MonitorIndex);
-    TS_ASSERT_EQUALS(inst->getNumberParameter("PointDetectorStart")[0], boost::lexical_cast<double>(pointDetectorStartStop[0]));
-    TS_ASSERT_EQUALS(inst->getNumberParameter("PointDetectorStop")[0], boost::lexical_cast<double>(pointDetectorStartStop.at(1)));
-
-    // Remove workspace from the data service.
-    AnalysisDataService::Instance().remove(outWSQName);
-    AnalysisDataService::Instance().remove(outWSLamName);
-    AnalysisDataService::Instance().remove(inWSName);
-    AnalysisDataService::Instance().remove(transWSName);
-
+    TS_ASSERT_THROWS_NOTHING( alg.initialize());
+    TS_ASSERT( alg.isInitialized());
   }
 
   void test_check_input_workpace_not_tof_throws()
@@ -267,7 +272,8 @@ public:
   {
     auto alg = construct_standard_algorithm();
     alg->setProperty("AnalysisMode", "PointDetectorAnalysis");
-    std::vector<int> RegionOfDirectBeam = boost::assign::list_of(1)(2).convert_to_container< std::vector<int> >();
+    std::vector<int> RegionOfDirectBeam = boost::assign::list_of(1)(2).convert_to_container<
+        std::vector<int> >();
     alg->setProperty("RegionOfDirectBeam", RegionOfDirectBeam);
     TS_ASSERT_THROWS(alg->execute(), std::invalid_argument);
   }
@@ -276,7 +282,8 @@ public:
   {
     auto alg = construct_standard_algorithm();
     alg->setProperty("AnalysisMode", "MultiDetectorAnalysis");
-    std::vector<int> RegionOfDirectBeam = boost::assign::list_of(0)(-1).convert_to_container< std::vector<int> >();
+    std::vector<int> RegionOfDirectBeam = boost::assign::list_of(0)(-1).convert_to_container<
+        std::vector<int> >();
     alg->setProperty("RegionOfDirectBeam", RegionOfDirectBeam);
     TS_ASSERT_THROWS(alg->execute(), std::invalid_argument);
   }
@@ -285,7 +292,8 @@ public:
   {
     auto alg = construct_standard_algorithm();
     alg->setProperty("AnalysisMode", "MultiDetectorAnalysis");
-    std::vector<int> RegionOfDirectBeam = boost::assign::list_of(1)(0).convert_to_container< std::vector<int> >();
+    std::vector<int> RegionOfDirectBeam = boost::assign::list_of(1)(0).convert_to_container<
+        std::vector<int> >();
     alg->setProperty("RegionOfDirectBeam", RegionOfDirectBeam);
     TS_ASSERT_THROWS(alg->execute(), std::invalid_argument);
   }
@@ -304,333 +312,65 @@ public:
     TS_ASSERT_THROWS(alg->execute(), std::out_of_range);
   }
 
-  void test_point_detector_run_with_single_transmission_workspace()
-  {
-    IAlgorithm_sptr lAlg = AlgorithmManager::Instance().create("Load");
-    lAlg->setRethrows(true);
-    lAlg->initialize();
-    lAlg->isInitialized();
-    lAlg->setPropertyValue("Filename", "INTER00013460.nxs");
-    lAlg->setPropertyValue("OutputWorkspace", inWSName);
-    lAlg->execute();
-    lAlg->isExecuted();
-    MatrixWorkspace_sptr ws = AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>(inWSName);
-
-    auto alg = construct_standard_algorithm();
-    alg->setProperty("InputWorkspace", ws);
-    alg->setProperty("ProcessingInstructions", "3,4");
-    alg->setProperty("FirstTransmissionRun", ws);
-    alg->setProperty("ThetaIn", 0.2); // Currently a requirement that one transmisson correction is provided.
-    TS_ASSERT_THROWS_NOTHING(alg->execute(); );
-
-    MatrixWorkspace_sptr outWSlam;
-    MatrixWorkspace_sptr outWSq;
-    double outTheta = 0;
-    TS_ASSERT_THROWS_NOTHING( outWSlam = AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>(outWSLamName); );
-    TS_ASSERT_THROWS_NOTHING( outWSq = AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>(outWSQName); );
-    TS_ASSERT_THROWS_NOTHING( outTheta = alg->getProperty("ThetaOut"); );
-    TSM_ASSERT_EQUALS("Theta in and out should be the same", 0.2, outTheta);
-    TS_ASSERT_EQUALS("Wavelength", outWSlam->getAxis(0)->unit()->unitID());
-    TS_ASSERT_EQUALS("MomentumTransfer", outWSq->getAxis(0)->unit()->unitID());
-
-    TS_ASSERT_EQUALS(2, outWSlam->getNumberHistograms());
-    // Remove workspace from the data service.
-    AnalysisDataService::Instance().remove(outWSQName);
-    AnalysisDataService::Instance().remove(outWSLamName);
-    AnalysisDataService::Instance().remove(inWSName);
-    AnalysisDataService::Instance().remove(transWSName);
-  }
-
-  void test_point_detector_run_with_two_transmission_workspaces()
-  {
-    IAlgorithm_sptr lAlg = AlgorithmManager::Instance().create("Load");
-    lAlg->setRethrows(true);
-    lAlg->initialize();
-    lAlg->setPropertyValue("Filename", "INTER00013460.nxs");
-    lAlg->setPropertyValue("OutputWorkspace", inWSName);
-    lAlg->execute();
-    lAlg->setPropertyValue("Filename", "INTER00013463.nxs");
-    lAlg->setPropertyValue("OutputWorkspace", transWSName);
-    lAlg->execute();
-    lAlg->setPropertyValue("Filename", "INTER00013464.nxs");
-    lAlg->setPropertyValue("OutputWorkspace", transWSName + "2");
-    lAlg->execute();
-    MatrixWorkspace_sptr ws = AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>(inWSName);
-    MatrixWorkspace_sptr trans_run1 = AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>(transWSName);
-    MatrixWorkspace_sptr trans_run2 = AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>(transWSName + "2");
-
-    auto alg = construct_standard_algorithm();
-
-    alg->setProperty("InputWorkspace", ws);
-    alg->setProperty("ProcessingInstructions", "3,4");
-    alg->setProperty("FirstTransmissionRun", trans_run1);
-    alg->setProperty("SecondTransmissionRun", trans_run2);
-    alg->setProperty("ThetaIn", 0.2); // Currently a requirement that one transmisson correction is provided.
-    MantidVec params = boost::assign::list_of(0.0)(0.02)(5).convert_to_container<MantidVec>();
-    TS_ASSERT_THROWS_NOTHING(alg->execute(); );
-
-    MatrixWorkspace_sptr outWSlam;
-    MatrixWorkspace_sptr outWSq;
-    double outTheta = 0;
-    TS_ASSERT_THROWS_NOTHING( outWSlam = AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>(outWSLamName); );
-    TS_ASSERT_THROWS_NOTHING( outWSq = AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>(outWSQName); );
-    TS_ASSERT_THROWS_NOTHING( outTheta = alg->getProperty("ThetaOut"); );
-    TS_ASSERT_DELTA(outTheta, 0.2, 0.0000001);
-
-    // Remove workspace from the data service.
-    AnalysisDataService::Instance().remove(outWSQName);
-    AnalysisDataService::Instance().remove(outWSLamName);
-    AnalysisDataService::Instance().remove(inWSName);
-    AnalysisDataService::Instance().remove(transWSName);
-    AnalysisDataService::Instance().remove(transWSName + "2");
-  }
 
-  void test_spectrum_map_mismatch_throws_when_strict()
-  {
-    IAlgorithm_sptr lAlg = AlgorithmManager::Instance().create("Load");
-    lAlg->setRethrows(true);
-    lAlg->initialize();
-    lAlg->setPropertyValue("Filename", "INTER00013460.nxs");
-    lAlg->setPropertyValue("OutputWorkspace", inWSName);
-    lAlg->execute();
-    lAlg->setPropertyValue("Filename", "INTER00013463.nxs");
-    lAlg->setPropertyValue("OutputWorkspace", transWSName);
-    lAlg->execute();
-    MatrixWorkspace_sptr ws = AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>(inWSName);
-    MatrixWorkspace_sptr trans_run1_tof = AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>(transWSName);
-
-    /*
-    Here we convert the transmission run to Lam. The workspace will NOT have the same spectra map as the input workspace,
-    and strict checking is turned on, so this will throw upon execution.
-    */
-    IAlgorithm_sptr convAlg = AlgorithmManager::Instance().create("ConvertUnits");
-    convAlg->setProperty("InputWorkspace", trans_run1_tof);
-    convAlg->setProperty("Target","Wavelength");
-    convAlg->setProperty("OutputWorkspace", transWSName + "Lam");
-    convAlg->execute();
-    MatrixWorkspace_sptr trans_run1_lam = AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>(transWSName + "Lam");
-
-    IAlgorithm_sptr cropAlg = AlgorithmManager::Instance().create("CropWorkspace");
-    cropAlg->setProperty("InputWorkspace", trans_run1_lam);
-    cropAlg->setProperty("EndWorkspaceIndex", 1);
-    cropAlg->setProperty("OutputWorkspace", transWSName + "Lam");
-    cropAlg->execute();
-    trans_run1_lam = AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>(transWSName + "Lam");
-
-    auto alg = construct_standard_algorithm();
-    alg->setProperty("InputWorkspace", ws);
-    alg->setProperty("ProcessingInstructions", "3,4"); // This will make spectrum numbers in input workspace different from denominator
-    alg->setProperty("FirstTransmissionRun", trans_run1_lam);
-    alg->setProperty("StrictSpectrumChecking", true);
-
-    TS_ASSERT_THROWS(alg->execute(), std::invalid_argument); // Should throw due to spectrum missmatch.
-
-    // Remove workspace from the data service.
-    AnalysisDataService::Instance().remove(inWSName);
-    AnalysisDataService::Instance().remove(transWSName);
-    AnalysisDataService::Instance().remove(transWSName + "Lam");
-  }
-
-  void test_spectrum_map_mismatch_doesnt_throw_when_not_strict()
-  {
-    IAlgorithm_sptr lAlg = AlgorithmManager::Instance().create("Load");
-    lAlg->setRethrows(true);
-    lAlg->initialize();
-    lAlg->setPropertyValue("Filename", "INTER00013460.nxs");
-    lAlg->setPropertyValue("OutputWorkspace", inWSName);
-    lAlg->execute();
-    lAlg->setPropertyValue("Filename", "INTER00013463.nxs");
-    lAlg->setPropertyValue("OutputWorkspace", transWSName);
-    lAlg->execute();
-    MatrixWorkspace_sptr ws = AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>(inWSName);
-    MatrixWorkspace_sptr trans_run1_tof = AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>(transWSName);
-
-    /*
-    Here we convert the transmission run to Lam. The workspace will NOT have the same spectra map as the input workspace,
-    and strict checking is turned on, so this will throw upon execution.
-    */
-    IAlgorithm_sptr convAlg = AlgorithmManager::Instance().create("ConvertUnits");
-    convAlg->setProperty("InputWorkspace", trans_run1_tof);
-    convAlg->setProperty("Target","Wavelength");
-    convAlg->setProperty("OutputWorkspace", transWSName + "Lam");
-    convAlg->execute();
-    MatrixWorkspace_sptr trans_run1_lam = AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>(transWSName + "Lam");
-
-    IAlgorithm_sptr cropAlg = AlgorithmManager::Instance().create("CropWorkspace");
-    cropAlg->setProperty("InputWorkspace", trans_run1_lam);
-    cropAlg->setProperty("EndWorkspaceIndex", 1);
-    cropAlg->setProperty("OutputWorkspace", transWSName + "Lam");
-    cropAlg->execute();
-    trans_run1_lam = AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>(transWSName + "Lam");
-
-    auto alg = construct_standard_algorithm();
-    alg->setProperty("InputWorkspace", ws);
-    alg->setProperty("ProcessingInstructions", "3,4"); // This will make spectrum numbers in input workspace different from denominator
-    alg->setProperty("FirstTransmissionRun", trans_run1_lam);
-    alg->setProperty("StrictSpectrumChecking", false); //Will not crash-out on spectrum checking.
-
-    TS_ASSERT_THROWS_NOTHING(alg->execute()); // Should not throw
-
-    // Remove workspace from the data service.
-    AnalysisDataService::Instance().remove(inWSName);
-    AnalysisDataService::Instance().remove(transWSName);
-    AnalysisDataService::Instance().remove(transWSName + "Lam");
-    AnalysisDataService::Instance().remove(outWSQName);
-    AnalysisDataService::Instance().remove(outWSLamName);
-  }
-
-  void test_calculate_theta()
+  void test_exec()
   {
-    IAlgorithm_sptr lAlg = AlgorithmManager::Instance().create("Load");
-    lAlg->setRethrows(true);
-    lAlg->initialize();
-    lAlg->setPropertyValue("Filename", "INTER00013460.nxs");
-    lAlg->setPropertyValue("OutputWorkspace", inWSName);
-    lAlg->execute();
-    MatrixWorkspace_sptr ws = AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>(inWSName);
-
-    auto alg = construct_standard_algorithm();
-    alg->setProperty("InputWorkspace", ws);
-    alg->setProperty("ProcessingInstructions", "3,4");
-    alg->setProperty("FirstTransmissionRun", ws); // Currently a requirement that one transmisson correction is provided.
-
-    TS_ASSERT_THROWS_NOTHING(alg->execute()); // Should not throw
-
-    MatrixWorkspace_sptr outWSlam;
-    MatrixWorkspace_sptr outWSq;
-    double outTheta = 0;
-    TS_ASSERT_THROWS_NOTHING( outWSlam = AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>(outWSLamName); );
-    TS_ASSERT_THROWS_NOTHING( outWSq = AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>(outWSQName); );
-    TS_ASSERT_THROWS_NOTHING( outTheta = alg->getProperty("ThetaOut"); );
+    IAlgorithm_sptr alg = AlgorithmManager::Instance().create("ReflectometryReductionOneAuto");
+    alg->setRethrows(true);
+    TS_ASSERT_THROWS_NOTHING( alg->initialize());
+    TS_ASSERT_THROWS_NOTHING( alg->setProperty("InputWorkspace", m_dataWorkspace));
+    TS_ASSERT_THROWS_NOTHING( alg->setProperty("AnalysisMode", "PointDetectorAnalysis"));
+    TS_ASSERT_THROWS_NOTHING( alg->setPropertyValue("OutputWorkspace", outWSQName));
+    TS_ASSERT_THROWS_NOTHING( alg->setPropertyValue("OutputWorkspaceWavelength", outWSLamName));
+    alg->execute();
+    TS_ASSERT( alg->isExecuted());
+
+    MatrixWorkspace_sptr outWS = AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>(outWSQName);
+
+    auto inst = m_dataWorkspace->getInstrument();
+    auto workspaceHistory = outWS->getHistory();
+    AlgorithmHistory_const_sptr workerAlgHistory =
+        workspaceHistory.getAlgorithmHistory(0)->getChildAlgorithmHistory(0);
+    auto vecPropertyHistories = workerAlgHistory->getProperties();
+
+    const double wavelengthMin = findPropertyValue<double>(vecPropertyHistories, "WavelengthMin");
+    const double wavelengthMax = findPropertyValue<double>(vecPropertyHistories, "WavelengthMax");
+    const double monitorBackgroundWavelengthMin = findPropertyValue<double>(vecPropertyHistories,
+        "MonitorBackgroundWavelengthMin");
+    const double monitorBackgroundWavelengthMax = findPropertyValue<double>(vecPropertyHistories,
+        "MonitorBackgroundWavelengthMax");
+    const double monitorIntegrationWavelengthMin = findPropertyValue<double>(vecPropertyHistories,
+        "MonitorIntegrationWavelengthMin");
+    const double monitorIntegrationWavelengthMax = findPropertyValue<double>(vecPropertyHistories,
+        "MonitorIntegrationWavelengthMax");
+    const int i0MonitorIndex = findPropertyValue<int>(vecPropertyHistories, "I0MonitorIndex");
+    std::string processingInstructions = findPropertyValue<std::string>(vecPropertyHistories,
+        "ProcessingInstructions");
+    std::vector<std::string> pointDetectorStartStop;
+    boost::split(pointDetectorStartStop, processingInstructions, boost::is_any_of(":"));
 
-    TS_ASSERT_DELTA(0.70969419, outTheta, 0.00001);
+    TS_ASSERT_EQUALS(inst->getNumberParameter("LambdaMin")[0], wavelengthMin);
+    TS_ASSERT_EQUALS(inst->getNumberParameter("LambdaMax")[0], wavelengthMax);
+    TS_ASSERT_EQUALS(inst->getNumberParameter("MonitorBackgroundMin")[0],
+        monitorBackgroundWavelengthMin);
+    TS_ASSERT_EQUALS(inst->getNumberParameter("MonitorBackgroundMax")[0],
+        monitorBackgroundWavelengthMax);
+    TS_ASSERT_EQUALS(inst->getNumberParameter("MonitorIntegralMin")[0], monitorIntegrationWavelengthMin);
+    TS_ASSERT_EQUALS(inst->getNumberParameter("MonitorIntegralMax")[0], monitorIntegrationWavelengthMax);
+    TS_ASSERT_EQUALS(inst->getNumberParameter("I0MonitorIndex")[0], i0MonitorIndex);
+    TS_ASSERT_EQUALS(inst->getNumberParameter("PointDetectorStart")[0],
+        boost::lexical_cast<double>(pointDetectorStartStop[0]));
+    TS_ASSERT_EQUALS(inst->getNumberParameter("PointDetectorStop")[0],
+        boost::lexical_cast<double>(pointDetectorStartStop[1]));
 
     // Remove workspace from the data service.
     AnalysisDataService::Instance().remove(outWSQName);
     AnalysisDataService::Instance().remove(outWSLamName);
-    AnalysisDataService::Instance().remove(inWSName);
-  }
-
-  void  test_correct_positions_point_detector()
-  {
-    IAlgorithm_sptr lAlg = AlgorithmManager::Instance().create("Load");
-    lAlg->setRethrows(true);
-    lAlg->initialize();
-    lAlg->setPropertyValue("Filename", "INTER00013460.nxs");
-    lAlg->setPropertyValue("OutputWorkspace", inWSName);
-    lAlg->execute();
-    MatrixWorkspace_sptr ws = AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>(inWSName);
 
-    auto alg = construct_standard_algorithm();
-    alg->setProperty("InputWorkspace", ws);
-    alg->setProperty("ProcessingInstructions", "3,4");
-    alg->setProperty("ThetaIn", 0.4); //Low angle
-    alg->setProperty("CorrectDetectorPositions", true);
-    alg->setProperty("FirstTransmissionRun", ws); // Currently a requirement that one transmisson correction is provided.
-
-    TS_ASSERT_THROWS_NOTHING(alg->execute()); // Should not throw
-    
-    MatrixWorkspace_sptr outWSlam1;
-    MatrixWorkspace_sptr outWSq1;
-    double outTheta1 = 0;
-    TS_ASSERT_THROWS_NOTHING( outWSlam1 = AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>(outWSQName); );
-    TS_ASSERT_THROWS_NOTHING( outWSq1 = AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>(outWSQName); );
-    TS_ASSERT_THROWS_NOTHING( outTheta1 = alg->getProperty("ThetaOut"); );
-    TS_ASSERT_DELTA(outTheta1, 0.4, 0.0000001);
-
-    auto pos1 = outWSlam1->getInstrument()->getComponentByName("point-detector")->getPos();
-    
-    alg->setProperty("ThetaIn", 0.8); // Repeat with greater incident angle
-    alg->setPropertyValue("OutputWorkspace", outWSQName + "2");
-    alg->setPropertyValue("OutputWorkspaceWavelength", outWSLamName + "2");
-    TS_ASSERT_THROWS_NOTHING(alg->execute()); // Should not throw
-    MatrixWorkspace_sptr outWSlam2;
-    MatrixWorkspace_sptr outWSq2;
-    double outTheta2 = 0;
-    TS_ASSERT_THROWS_NOTHING( outWSlam2 = AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>(outWSQName + "2"); );
-    TS_ASSERT_THROWS_NOTHING( outWSq2 = AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>(outWSQName + "2"); );
-    TS_ASSERT_THROWS_NOTHING( outTheta2 = alg->getProperty("ThetaOut"); );
-    TS_ASSERT_DELTA(outTheta2, 0.8, 0.0000001);
-
-    auto pos2 = outWSlam2->getInstrument()->getComponentByName("point-detector")->getPos();
-
-    TSM_ASSERT_LESS_THAN("Greater incident angle so greater height.",pos1.Y(),pos2.Y());
-    TS_ASSERT_EQUALS(pos2.X(), pos1.X());
-    TS_ASSERT_EQUALS(pos2.Z(), pos1.Z());
-    
-    // Remove workspace from the data service.
-    AnalysisDataService::Instance().remove(outWSQName);
-    AnalysisDataService::Instance().remove(outWSLamName);
-    AnalysisDataService::Instance().remove(outWSQName + "2");
-    AnalysisDataService::Instance().remove(outWSLamName + "2");
-    AnalysisDataService::Instance().remove(inWSName);
   }
 
-  void  test_multidetector_run()
-  {
-    IAlgorithm_sptr lAlg = AlgorithmManager::Instance().create("Load");
-    lAlg->setRethrows(true);
-    lAlg->initialize();
-    lAlg->setPropertyValue("Filename", "POLREF00004699.nxs");
-    lAlg->setPropertyValue("OutputWorkspace", inWSName);
-    lAlg->execute();
-    MatrixWorkspace_sptr ws = boost::dynamic_pointer_cast<MatrixWorkspace>(AnalysisDataService::Instance().retrieveWS<WorkspaceGroup>(inWSName)->getItem(0));
 
-    auto alg = construct_standard_algorithm();
-    alg->setProperty("InputWorkspace", ws);
-    alg->setProperty("ProcessingInstructions", "3,10"); //Fictional values
-    alg->setProperty("RegionOfDirectBeam", "20, 30"); //Fictional values
-    alg->setProperty("ThetaIn", 0.1); //Fictional values
-    alg->setProperty("CorrectDetectorPositions", false);
-    alg->setProperty("AnalysisMode", "MultiDetectorAnalysis");
-    
-    TS_ASSERT_THROWS_NOTHING(alg->execute()); // Should not throw
-
-    MatrixWorkspace_sptr outWSlam;
-    MatrixWorkspace_sptr outWSq;
-    double outTheta = 0;
-    TS_ASSERT_THROWS_NOTHING( outWSlam = AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>(outWSLamName); );
-    TS_ASSERT_THROWS_NOTHING( outWSq = AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>(outWSQName); );
-    TS_ASSERT_THROWS_NOTHING( outTheta = alg->getProperty("ThetaOut"); );
-    TS_ASSERT_DELTA(outTheta, 0.1, 0.0000001);
-
-    TS_ASSERT_EQUALS("Wavelength", outWSlam->getAxis(0)->unit()->unitID());
-    TS_ASSERT_EQUALS("MomentumTransfer", outWSq->getAxis(0)->unit()->unitID());
-  }
 
-  void  Xtest_correct_positions_multi_detector()
-  {
-    IAlgorithm_sptr lAlg = AlgorithmManager::Instance().create("Load");
-    lAlg->setRethrows(true);
-    lAlg->initialize();
-    lAlg->setPropertyValue("Filename", "POLREF00004699.nxs");
-    lAlg->setPropertyValue("OutputWorkspace", inWSName);
-    lAlg->execute();
-    MatrixWorkspace_sptr ws = boost::dynamic_pointer_cast<MatrixWorkspace>(AnalysisDataService::Instance().retrieveWS<WorkspaceGroup>(inWSName)->getItem(0));
-
-    auto alg = construct_standard_algorithm();
-    alg->setProperty("InputWorkspace", ws);
-    alg->setProperty("ProcessingInstructions", "73"); //Fictional values
-    alg->setProperty("RegionOfDirectBeam", "28, 29"); //Fictional values
-    alg->setProperty("ThetaIn", 0.49/2); //Fictional values
-    alg->setProperty("CorrectDetectorPositions", true);
-    alg->setProperty("AnalysisMode", "MultiDetectorAnalysis");
-    
-    TS_ASSERT_THROWS_NOTHING(alg->execute()); // Should not throw
-
-    MatrixWorkspace_sptr outWSlam;
-    MatrixWorkspace_sptr outWSq;
-    double outTheta = 0;
-    TS_ASSERT_THROWS_NOTHING( outWSlam = AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>(outWSLamName); );
-    TS_ASSERT_THROWS_NOTHING( outWSq = AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>(outWSQName); );
-    TS_ASSERT_THROWS_NOTHING( outTheta = alg->getProperty("ThetaOut"); );
-    TS_ASSERT_DELTA(outTheta, 0.49/2, 0.0000001);
-    
-    auto pos = outWSlam->getInstrument()->getComponentByName("lineardetector")->getPos();
-
-    TS_ASSERT_DELTA(-0.05714, pos.Z(), 0.0001);
-  }
 };
 
-
 #endif /* MANTID_ALGORITHMS_REFLECTOMETRYREDUCTIONONEAUTOTEST_H_ */
diff --git a/Code/Mantid/Framework/Algorithms/test/ReflectometryReductionOneTest.h b/Code/Mantid/Framework/Algorithms/test/ReflectometryReductionOneTest.h
index 83c9f6e4c995ff1f4f2c9b72d8885914dd102c3f..2d76b3f7150bebb86cef84edd73e0015791ddce0 100644
--- a/Code/Mantid/Framework/Algorithms/test/ReflectometryReductionOneTest.h
+++ b/Code/Mantid/Framework/Algorithms/test/ReflectometryReductionOneTest.h
@@ -1,44 +1,58 @@
-#ifndef REFLECTOMETRYREDUCTIONONETEST_H_
-#define REFLECTOMETRYREDUCTIONONETEST_H_
+#ifndef ALGORITHMS_TEST_REFLECTOMETRYREDUCTIONONETEST_H_
+#define ALGORITHMS_TEST_REFLECTOMETRYREDUCTIONONETEST_H_
 
 #include <cxxtest/TestSuite.h>
 #include <algorithm>
 #include "MantidAlgorithms/ReflectometryReductionOne.h"
 #include "MantidAPI/AlgorithmManager.h"
+#include "MantidAPI/MatrixWorkspace.h"
+#include "MantidTestHelpers/WorkspaceCreationHelper.h"
+#include "MantidGeometry/Instrument/ReferenceFrame.h"
 
 using namespace Mantid;
 using namespace Mantid::Kernel;
 using namespace Mantid::API;
 using namespace Mantid::Algorithms;
+using namespace WorkspaceCreationHelper;
 
 class ReflectometryReductionOneTest: public CxxTest::TestSuite
 {
+private:
+
+  MatrixWorkspace_sptr m_tinyReflWS;
+
 public:
 
-  void test_tolam()
+  // This pair of boilerplate methods prevent the suite being created statically
+  // This means the constructor isn't called when running other tests
+  static ReflectometryReductionOneTest *createSuite()
+  {
+    return new ReflectometryReductionOneTest();
+  }
+  static void destroySuite(ReflectometryReductionOneTest *suite)
+  {
+    delete suite;
+  }
+
+  ReflectometryReductionOneTest()
   {
-    auto loadAlg = AlgorithmManager::Instance().create("Load");
-    loadAlg->initialize();
-    loadAlg->setProperty("Filename", "INTER00013460.nxs");
-    loadAlg->setPropertyValue("OutputWorkspace", "demo");
-    loadAlg->execute();
+    m_tinyReflWS = create2DWorkspaceWithReflectometryInstrument();
+  }
 
-    MatrixWorkspace_sptr toConvert = AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>("demo");
+  void test_tolam()
+  {
+    MatrixWorkspace_sptr toConvert = m_tinyReflWS;
     std::vector<int> detectorIndexRange;
-    size_t workspaceIndexToKeep1 = 3;
-    size_t workspaceIndexToKeep2 = 4;
-    const int monitorIndex = 2;
+    size_t workspaceIndexToKeep1 = 1;
+    const int monitorIndex = 0;
 
     specid_t specId1 = toConvert->getSpectrum(workspaceIndexToKeep1)->getSpectrumNo();
-    specid_t specId2 = toConvert->getSpectrum(workspaceIndexToKeep2)->getSpectrumNo();
     specid_t monitorSpecId = toConvert->getSpectrum(monitorIndex)->getSpectrumNo();
 
     // Define one spectra to keep
     detectorIndexRange.push_back(static_cast<int>(workspaceIndexToKeep1));
-    // Define another spectra to keep
-    detectorIndexRange.push_back(static_cast<int>(workspaceIndexToKeep2));
     std::stringstream buffer;
-    buffer << workspaceIndexToKeep1 << "," << workspaceIndexToKeep2;
+    buffer << workspaceIndexToKeep1;
     const std::string detectorIndexRangesStr = buffer.str();
 
     // Define a wavelength range for the detector workspace
@@ -65,12 +79,11 @@ public:
     TS_ASSERT_EQUALS("Wavelength", detectorWS->getAxis(0)->unit()->unitID());
 
     // Check the number of spectrum kept.
-    TS_ASSERT_EQUALS(2, detectorWS->getNumberHistograms());
+    TS_ASSERT_EQUALS(1, detectorWS->getNumberHistograms());
 
     auto map = detectorWS->getSpectrumToWorkspaceIndexMap();
     // Check the spectrum ids retained.
     TS_ASSERT_EQUALS(map[specId1], 0);
-    TS_ASSERT_EQUALS(map[specId2], 1);
 
     // Check the cropped x range
     Mantid::MantidVec copyX = detectorWS->readX(0);
@@ -89,10 +102,54 @@ public:
     // Check the spectrum ids retained.
     TS_ASSERT_EQUALS(map[monitorSpecId], 0);
 
-    AnalysisDataService::Instance().remove(toConvert->getName());
   }
 
+  IAlgorithm_sptr construct_standard_algorithm()
+  {
+    auto alg = AlgorithmManager::Instance().create("ReflectometryReductionOne");
+    alg->setRethrows(true);
+    alg->setChild(true);
+    alg->initialize();
+    alg->setProperty("InputWorkspace", m_tinyReflWS);
+    alg->setProperty("WavelengthMin", 1.0);
+    alg->setProperty("WavelengthMax", 15.0);
+    alg->setProperty("I0MonitorIndex", 0);
+    alg->setProperty("MonitorBackgroundWavelengthMin", 14.0);
+    alg->setProperty("MonitorBackgroundWavelengthMax", 15.0);
+    alg->setProperty("MonitorIntegrationWavelengthMin", 4.0);
+    alg->setProperty("MonitorIntegrationWavelengthMax", 10.0);
+    alg->setPropertyValue("ProcessingInstructions", "1");
+    alg->setPropertyValue("OutputWorkspace", "x");
+    alg->setPropertyValue("OutputWorkspaceWavelength", "y");
+    alg->setRethrows(true);
+    return alg;
+  }
+
+  void test_execute()
+  {
+    auto alg = construct_standard_algorithm();
+    TS_ASSERT_THROWS_NOTHING(alg->execute());
+    MatrixWorkspace_sptr workspaceInQ = alg->getProperty("OutputWorkspace");
+    MatrixWorkspace_sptr workspaceInLam = alg->getProperty("OutputWorkspaceWavelength");
+    const double theta = alg->getProperty("ThetaOut");
+    UNUSED_ARG(theta)
+    UNUSED_ARG(workspaceInQ)
+    UNUSED_ARG(workspaceInLam)
+  }
+
+  void test_calculate_theta()
+  {
+
+    auto alg = construct_standard_algorithm();
+
+    alg->execute();
+    // Should not throw
+
+    const double outTheta = alg->getProperty("ThetaOut");
+
+    TS_ASSERT_DELTA(45.0/2, outTheta, 0.00001);
+  }
 
 };
 
-#endif /* REFLECTOMETRYREDUCTIONONETEST_H_ */
+#endif /* ALGORITHMS_TEST_REFLECTOMETRYREDUCTIONONETEST_H_ */
diff --git a/Code/Mantid/Framework/Algorithms/test/Stitch1DTest.h b/Code/Mantid/Framework/Algorithms/test/Stitch1DTest.h
index 7533e5e095e7b0cf2d645e5a42e2c6fcc8619a9b..71b1ae004ca8dad776c8c214f170f19a2065c3de 100644
--- a/Code/Mantid/Framework/Algorithms/test/Stitch1DTest.h
+++ b/Code/Mantid/Framework/Algorithms/test/Stitch1DTest.h
@@ -4,18 +4,21 @@
 #include <cxxtest/TestSuite.h>
 
 #include "MantidAlgorithms/Stitch1D.h"
-#include "MantidAPI/FrameworkManager.h"
-#include "MantidAPI/AlgorithmManager.h"
+#include "MantidKernel/UnitFactory.h"
+#include "MantidDataObjects/Workspace2D.h"
 #include <algorithm>
 #include <math.h>
 #include <boost/assign/list_of.hpp>
 #include <boost/tuple/tuple.hpp>
 #include <boost/math/special_functions.hpp>
+#include <boost/make_shared.hpp>
 
 using namespace Mantid::API;
+using namespace Mantid::Kernel;
 using namespace boost::assign;
 using Mantid::Algorithms::Stitch1D;
 using Mantid::MantidVec;
+using namespace Mantid::DataObjects;
 
 double roundSix(double i)
 {
@@ -51,32 +54,30 @@ private:
   MatrixWorkspace_sptr createWorkspace(MantidVec& xData, MantidVec& yData, MantidVec& eData,
       const int nSpec = 1)
   {
-    auto createWorkspace = AlgorithmManager::Instance().create("CreateWorkspace");
-    createWorkspace->setChild(true);
-    createWorkspace->initialize();
-    createWorkspace->setProperty("UnitX", "1/q");
-    createWorkspace->setProperty("DataX", xData);
-    createWorkspace->setProperty("DataY", yData);
-    createWorkspace->setProperty("NSpec", nSpec);
-    createWorkspace->setProperty("DataE", eData);
-    createWorkspace->setPropertyValue("OutputWorkspace", "dummy");
-    createWorkspace->execute();
-    MatrixWorkspace_sptr outWS = createWorkspace->getProperty("OutputWorkspace");
+
+    Workspace2D_sptr outWS = boost::make_shared<Workspace2D>();
+    outWS->initialize(nSpec, xData.size(), yData.size());
+    for (int i = 0; i < nSpec; ++i)
+    {
+      outWS->dataY(i) = yData;
+      outWS->dataE(i) = eData;
+      outWS->dataX(i) = xData;
+    }
+
+    outWS->getAxis(0)->unit() = UnitFactory::Instance().create("Wavelength");
+
     return outWS;
   }
 
   MatrixWorkspace_sptr create1DWorkspace(MantidVec& xData, MantidVec& yData)
   {
-    auto createWorkspace = AlgorithmManager::Instance().create("CreateWorkspace");
-    createWorkspace->setChild(true);
-    createWorkspace->initialize();
-    createWorkspace->setProperty("UnitX", "1/q");
-    createWorkspace->setProperty("DataX", xData);
-    createWorkspace->setProperty("DataY", yData);
-    createWorkspace->setProperty("NSpec", 1);
-    createWorkspace->setPropertyValue("OutputWorkspace", "dummy");
-    createWorkspace->execute();
-    MatrixWorkspace_sptr outWS = createWorkspace->getProperty("OutputWorkspace");
+    Workspace2D_sptr outWS = boost::make_shared<Workspace2D>();
+    outWS->initialize(1, xData.size(), yData.size());
+    outWS->dataY(0) = yData;
+    outWS->dataX(0) = xData;
+
+    outWS->getAxis(0)->unit() = UnitFactory::Instance().create("Wavelength");
+
     return outWS;
   }
 
@@ -136,16 +137,7 @@ private:
     }
     yValues.pop_back();
 
-    auto createWorkspace = AlgorithmManager::Instance().create("CreateWorkspace");
-    createWorkspace->setChild(true);
-    createWorkspace->initialize();
-    createWorkspace->setProperty("UnitX", "x");
-    createWorkspace->setProperty("DataX", xValues);
-    createWorkspace->setProperty("DataY", yValues);
-    createWorkspace->setProperty("NSpec", 1);
-    createWorkspace->setPropertyValue("OutputWorkspace", "dummy");
-    createWorkspace->execute();
-    MatrixWorkspace_sptr outWS = createWorkspace->getProperty("OutputWorkspace");
+    MatrixWorkspace_sptr outWS = create1DWorkspace(xValues, yValues);
 
     return outWS;
   }
@@ -164,7 +156,6 @@ public:
 
   Stitch1DTest()
   {
-    FrameworkManager::Instance();
 
     e = MantidVec(10, 0);
     x = MantidVec(11);
@@ -345,8 +336,8 @@ public:
 
     //Check the ranges on the output workspace against the param inputs.
     MantidVec out_x_values = ret.get<0>()->readX(0);
-    double x_min = *std::min_element(out_x_values.begin(), out_x_values.end());
-    double x_max = *std::max_element(out_x_values.begin(), out_x_values.end());
+    double x_min = out_x_values.front();
+    double x_max = out_x_values.back();
     double step_size = out_x_values[1] - out_x_values[0];
 
     TS_ASSERT_EQUALS(x_min, -1);
@@ -653,7 +644,7 @@ public:
     TSM_ASSERT("NOT all error values are non-zero", alg.hasNonzeroErrors(ws));
   }
 
-  void test_patch_nan_y_value()
+  void test_patch_nan_y_value_for_scaling()
   {
     const size_t nspectrum = 1;
 
@@ -681,7 +672,7 @@ public:
     TSM_ASSERT("ScaleFactor should not be NAN", !boost::math::isnan(scaleFactor));
   }
 
-  void test_patch_inf_y_value()
+  void test_patch_inf_y_value_for_scaling()
   {
     const size_t nspectrum = 1;
 
@@ -709,6 +700,40 @@ public:
     TSM_ASSERT("ScaleFactor should not be Infinity", !boost::math::isinf(scaleFactor));
   }
 
+
+  void test_reset_nans()
+  {
+    const size_t nspectrum = 1;
+
+    auto x = MantidVec(10);
+    const double xstart = 0;
+    const double xstep = 1;
+    LinearSequence<MantidVec::value_type> sequenceX(xstart, xstep);
+    std::generate(x.begin(), x.end(), sequenceX);
+
+    auto y = MantidVec(nspectrum * (x.size() - 1), 1);
+    auto e = MantidVec(nspectrum * (x.size() - 1), 1);
+
+    double nan = std::numeric_limits<double>::quiet_NaN();
+    y[0] = nan; // Add a Infinity
+    MatrixWorkspace_sptr lhsWS = createWorkspace(x, y, e, static_cast<int>(nspectrum));
+
+    y[0] = y[1];
+    // Remove infinity
+    MatrixWorkspace_sptr rhsWS = createWorkspace(x, y, e, static_cast<int>(nspectrum));
+
+    auto ret = do_stitch1D(lhsWS, rhsWS);
+
+    MatrixWorkspace_sptr outWs = ret.get<0>();
+    double scaleFactor = ret.get<1>();
+
+    TSM_ASSERT("ScaleFactor should not be Infinity", !boost::math::isinf(scaleFactor));
+
+    auto outY = outWs->readY(0);
+    TSM_ASSERT("Nans should be put back", boost::math::isnan(outY[0]));
+  }
+
+
 };
 
 #endif /* MANTID_ALGORITHMS_STITCH1DTEST_H_ */
diff --git a/Code/Mantid/Framework/Crystal/CMakeLists.txt b/Code/Mantid/Framework/Crystal/CMakeLists.txt
index 7f8a69bad62e2ac5d1fd49bd0550f1401a34a3df..fbec38fe0f62a583a7321749890fc385c86f470e 100644
--- a/Code/Mantid/Framework/Crystal/CMakeLists.txt
+++ b/Code/Mantid/Framework/Crystal/CMakeLists.txt
@@ -52,6 +52,7 @@ set ( SRC_FILES
 	src/SaveHKL.cpp
 	src/SaveIsawPeaks.cpp
 	src/SaveIsawUB.cpp
+	src/SaveLauenorm.cpp
 	src/SavePeaksFile.cpp
 	src/SelectCellOfType.cpp
 	src/SelectCellWithForm.cpp
@@ -123,6 +124,7 @@ set ( INC_FILES
 	inc/MantidCrystal/SaveHKL.h
 	inc/MantidCrystal/SaveIsawPeaks.h
 	inc/MantidCrystal/SaveIsawUB.h
+	inc/MantidCrystal/SaveLauenorm.h
 	inc/MantidCrystal/SavePeaksFile.h
 	inc/MantidCrystal/SelectCellOfType.h
 	inc/MantidCrystal/SelectCellWithForm.h
@@ -187,6 +189,7 @@ set ( TEST_FILES
 	SaveHKLTest.h
 	SaveIsawPeaksTest.h
 	SaveIsawUBTest.h
+	SaveLauenormTest.h
 	SavePeaksFileTest.h
 	SelectCellOfTypeTest.h
 	SelectCellWithFormTest.h
diff --git a/Code/Mantid/Framework/Crystal/inc/MantidCrystal/SaveLauenorm.h b/Code/Mantid/Framework/Crystal/inc/MantidCrystal/SaveLauenorm.h
new file mode 100644
index 0000000000000000000000000000000000000000..ae629f7dfbfcea53ad34277939c0ae64eaea8bc8
--- /dev/null
+++ b/Code/Mantid/Framework/Crystal/inc/MantidCrystal/SaveLauenorm.h
@@ -0,0 +1,51 @@
+#ifndef MANTID_CRYSTAL_SAVELauenorm_H_
+#define MANTID_CRYSTAL_SAVELauenorm_H_
+    
+#include "MantidKernel/System.h"
+#include "MantidAPI/Algorithm.h" 
+#include "MantidDataObjects/PeaksWorkspace.h"
+
+namespace Mantid
+{
+namespace Crystal
+{
+
+  /** Save a PeaksWorkspace to a lauenorm format
+   * http://www.ccp4.ac.uk/cvs/viewvc.cgi/laue/doc/lauenorm.ptx?diff_format=s&revision=1.1.1.1&view=markup
+   * 
+   * @author Vickie Lynch, SNS
+   * @date 2014-07-24
+   */
+
+  class DLLExport SaveLauenorm  : public API::Algorithm
+  {
+  public:
+    SaveLauenorm();
+    ~SaveLauenorm();
+    
+    /// Algorithm's name for identification 
+    virtual const std::string name() const { return "SaveLauenorm";};
+    ///Summary of algorithms purpose
+    virtual const std::string summary() const {return "Save a PeaksWorkspace to a ASCII .hkl file.";}
+
+    /// Algorithm's version for identification 
+    virtual int version() const { return 1;};
+    /// Algorithm's category for identification
+    virtual const std::string category() const { return "Crystal;DataHandling\\Text";}
+    
+  private:
+    
+    /// Initialise the properties
+    void init();
+    /// Run the algorithm
+    void exec();
+
+    DataObjects::PeaksWorkspace_sptr ws;
+    void sizeBanks(std::string bankName, int& nCols, int& nRows);
+  };
+
+
+} // namespace Mantid
+} // namespace Crystal
+
+#endif  /* MANTID_CRYSTAL_SAVELauenorm_H_ */
diff --git a/Code/Mantid/Framework/Crystal/src/CalculateUMatrix.cpp b/Code/Mantid/Framework/Crystal/src/CalculateUMatrix.cpp
index d57ac39b22dc1fd1dc242056004167330591322f..7ffb3c20afeced276566936c5f31b06d3a17c3e3 100644
--- a/Code/Mantid/Framework/Crystal/src/CalculateUMatrix.cpp
+++ b/Code/Mantid/Framework/Crystal/src/CalculateUMatrix.cpp
@@ -123,7 +123,7 @@ namespace Crystal
     DblMatrix U(qR.getRotation());
     o.setU(U);
 
-    ws->mutableSample().setOrientedLattice(new OrientedLattice(o));
+    ws->mutableSample().setOrientedLattice(&o);
 
   }
 
diff --git a/Code/Mantid/Framework/Crystal/src/FindUBUsingFFT.cpp b/Code/Mantid/Framework/Crystal/src/FindUBUsingFFT.cpp
index 6a6666406185820052b16a590dc7ac1647acbed4..5b2926bf2d0f18bdf4b10b1b5914e590a479e230 100644
--- a/Code/Mantid/Framework/Crystal/src/FindUBUsingFFT.cpp
+++ b/Code/Mantid/Framework/Crystal/src/FindUBUsingFFT.cpp
@@ -130,7 +130,7 @@ namespace Crystal
       g_log.notice() << o_lattice << "\n";
 
 
-      ws->mutableSample().setOrientedLattice( new OrientedLattice(o_lattice) );
+      ws->mutableSample().setOrientedLattice( &o_lattice );
     }
   }
 
diff --git a/Code/Mantid/Framework/Crystal/src/FindUBUsingIndexedPeaks.cpp b/Code/Mantid/Framework/Crystal/src/FindUBUsingIndexedPeaks.cpp
index acfa60d4864ec9b373547dbe41669ff5ec5e99b3..e14b75b7066dfe7a18f5c61160a6016ad5367628 100644
--- a/Code/Mantid/Framework/Crystal/src/FindUBUsingIndexedPeaks.cpp
+++ b/Code/Mantid/Framework/Crystal/src/FindUBUsingIndexedPeaks.cpp
@@ -139,7 +139,7 @@ namespace Crystal
                                             <<std::fixed<<std::setprecision(3)<<std::setw(9)<<sigabc[5]
                                             <<std::endl;
       o_lattice.setError(sigabc[0],sigabc[1],sigabc[2],sigabc[3],sigabc[4],sigabc[5]);
-      ws->mutableSample().setOrientedLattice( new OrientedLattice(o_lattice) );
+      ws->mutableSample().setOrientedLattice( &o_lattice );
     }
   }
 
diff --git a/Code/Mantid/Framework/Crystal/src/FindUBUsingLatticeParameters.cpp b/Code/Mantid/Framework/Crystal/src/FindUBUsingLatticeParameters.cpp
index f2f25e1232bf601eda4877479bc00a09acdfaa50..046809572a13aa5b2e8dd2907904eac5c1dd7d64 100644
--- a/Code/Mantid/Framework/Crystal/src/FindUBUsingLatticeParameters.cpp
+++ b/Code/Mantid/Framework/Crystal/src/FindUBUsingLatticeParameters.cpp
@@ -160,7 +160,7 @@ namespace Crystal
             calc_a - a, calc_b - b, calc_c - c, calc_alpha - alpha, calc_beta - beta,
             calc_gamma - gamma);
         g_log.notice(std::string(logInfo));
-        ws->mutableSample().setOrientedLattice(new OrientedLattice(o_lattice));
+        ws->mutableSample().setOrientedLattice(&o_lattice);
       }
   }
 
diff --git a/Code/Mantid/Framework/Crystal/src/FindUBUsingMinMaxD.cpp b/Code/Mantid/Framework/Crystal/src/FindUBUsingMinMaxD.cpp
index 00922e79d4fb4381484684610e39b3ced0fd8ec8..51656c6d9edf013e5b73ef0dd9cc0bb493d29435 100644
--- a/Code/Mantid/Framework/Crystal/src/FindUBUsingMinMaxD.cpp
+++ b/Code/Mantid/Framework/Crystal/src/FindUBUsingMinMaxD.cpp
@@ -166,7 +166,7 @@ namespace Crystal
                                               <<std::fixed<<std::setprecision(3)<<std::setw(9)<<sigabc[4]
                                               <<std::fixed<<std::setprecision(3)<<std::setw(9)<<sigabc[5]
                                               <<std::endl;
-        ws->mutableSample().setOrientedLattice(new OrientedLattice(o_lattice));
+        ws->mutableSample().setOrientedLattice(&o_lattice);
       }
   }
 
diff --git a/Code/Mantid/Framework/Crystal/src/GoniometerAnglesFromPhiRotation.cpp b/Code/Mantid/Framework/Crystal/src/GoniometerAnglesFromPhiRotation.cpp
index 8faa4dd50e01958f1cac961473c5058ce006153e..8064e81f89d8152718b0ea082ff77b46a6b38e52 100644
--- a/Code/Mantid/Framework/Crystal/src/GoniometerAnglesFromPhiRotation.cpp
+++ b/Code/Mantid/Framework/Crystal/src/GoniometerAnglesFromPhiRotation.cpp
@@ -213,7 +213,7 @@ namespace Mantid
       Geometry::OrientedLattice lat2 = PeaksRun1->sample().getOrientedLattice();
 
       lat2.setUB(UB1);
-      PeaksRun2->mutableSample().setOrientedLattice(new OrientedLattice(lat2));
+      PeaksRun2->mutableSample().setOrientedLattice(&lat2);
 
       PeaksWorkspace_sptr Peakss = getProperty("PeaksWorkspace2");
 
@@ -400,13 +400,13 @@ namespace Mantid
         PeaksRun2->getPeak(i).setGoniometerMatrix(Gon2a);
       }
 
-      OrientedLattice & latt2(PeaksRun2->mutableSample().getOrientedLattice());
-      Kernel::Matrix<double> UB = latt2.getUB();
+      OrientedLattice latt2(PeaksRun2->mutableSample().getOrientedLattice());
+      //Kernel::Matrix<double> UB = latt2.getUB();
       Rot.Invert();
       Gon2a.Invert();
       latt2.setUB(Gon2a * Mk * UB1);
 
-      PeaksRun2->mutableSample().setOrientedLattice(new OrientedLattice(latt2));
+      PeaksRun2->mutableSample().setOrientedLattice(&latt2);
     }
 
     /**
diff --git a/Code/Mantid/Framework/Crystal/src/LoadIsawUB.cpp b/Code/Mantid/Framework/Crystal/src/LoadIsawUB.cpp
index 867c3e32833ea1ebba277336cec9c26683dffd59..c58c1c3d773a0a2382b2d3432157f9bab449f1be 100644
--- a/Code/Mantid/Framework/Crystal/src/LoadIsawUB.cpp
+++ b/Code/Mantid/Framework/Crystal/src/LoadIsawUB.cpp
@@ -152,6 +152,7 @@ namespace Crystal
         }
     }
 
+    delete latt;
     this->setProperty("InputWorkspace", ws1);
 
   }
diff --git a/Code/Mantid/Framework/Crystal/src/OptimizeLatticeForCellType.cpp b/Code/Mantid/Framework/Crystal/src/OptimizeLatticeForCellType.cpp
index baf4ba6183d63c8b51ba6bdb895e01d3517036e4..31c1cdd06440b9cb9be1aa6036081e02dc78afef 100644
--- a/Code/Mantid/Framework/Crystal/src/OptimizeLatticeForCellType.cpp
+++ b/Code/Mantid/Framework/Crystal/src/OptimizeLatticeForCellType.cpp
@@ -282,7 +282,7 @@ namespace Mantid
 		  // Show the modified lattice parameters
 		  g_log.notice() << runWS[i_run]->getName() <<"  " << o_lattice << "\n";
 
-		  runWS[i_run]->mutableSample().setOrientedLattice( new OrientedLattice(o_lattice) );
+          runWS[i_run]->mutableSample().setOrientedLattice( &o_lattice);
 
 		  setProperty("OutputChi2", chisq);
 
diff --git a/Code/Mantid/Framework/Crystal/src/PredictFractionalPeaks.cpp b/Code/Mantid/Framework/Crystal/src/PredictFractionalPeaks.cpp
index d330bcd872cb0ae616c3cea36d695b4f321a071c..b2bcae9a18bba3a1ec5300878412c9b4b61c01ff 100644
--- a/Code/Mantid/Framework/Crystal/src/PredictFractionalPeaks.cpp
+++ b/Code/Mantid/Framework/Crystal/src/PredictFractionalPeaks.cpp
@@ -44,10 +44,10 @@ namespace Mantid
     /// Initialise the properties
     void PredictFractionalPeaks::init()
     {
-      declareProperty(new WorkspaceProperty<PeaksWorkspace> ("Peaks", "", Direction::Input),
+      declareProperty(new WorkspaceProperty<IPeaksWorkspace> ("Peaks", "", Direction::Input),
         "Workspace of Peaks with orientation matrix that indexed the peaks and instrument loaded");
 
-      declareProperty(new WorkspaceProperty<PeaksWorkspace> ("FracPeaks", "", Direction::Output),
+      declareProperty(new WorkspaceProperty<IPeaksWorkspace> ("FracPeaks", "", Direction::Output),
         "Workspace of Peaks with peaks with fractional h,k, and/or l values");
 
       declareProperty(new Kernel::ArrayProperty<double>(string("HOffset"),string("-.5,0, .5")),"Offset in the h direction");
@@ -90,7 +90,9 @@ namespace Mantid
     /// Run the algorithm
     void PredictFractionalPeaks::exec()
     {
-      PeaksWorkspace_sptr Peaks=getProperty("Peaks");
+      IPeaksWorkspace_sptr ipeaks = getProperty("Peaks");
+      auto Peaks = boost::dynamic_pointer_cast<PeaksWorkspace>(ipeaks);
+      if(!Peaks) throw std::invalid_argument("Input workspace is not a PeaksWorkspace. Type=" + ipeaks->id());
 
       vector<double> hOffsets = getProperty("HOffset");
       vector<double> kOffsets = getProperty("KOffset");
@@ -99,7 +101,6 @@ namespace Mantid
       if ( kOffsets.empty())kOffsets.push_back(0.0);
       if ( lOffsets.empty())lOffsets.push_back(0.0);
 
-      ;
       bool includePeaksInRange= getProperty("IncludeAllPeaksInRange");
 
       if(  Peaks->getNumberPeaks()<=0)
diff --git a/Code/Mantid/Framework/Crystal/src/SaveLauenorm.cpp b/Code/Mantid/Framework/Crystal/src/SaveLauenorm.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..e0fcf85f79e5680df9b5d63ac03d11fadb900e72
--- /dev/null
+++ b/Code/Mantid/Framework/Crystal/src/SaveLauenorm.cpp
@@ -0,0 +1,236 @@
+#include "MantidAPI/FileProperty.h"
+#include "MantidAPI/WorkspaceValidators.h"
+#include "MantidCrystal/SaveLauenorm.h"
+#include "MantidDataObjects/Peak.h"
+#include "MantidDataObjects/PeaksWorkspace.h"
+#include "MantidGeometry/Instrument/RectangularDetector.h"
+#include "MantidKernel/Strings.h"
+#include "MantidKernel/System.h"
+#include "MantidKernel/Utils.h"
+#include "MantidKernel/V3D.h"
+#include "MantidKernel/BoundedValidator.h"
+#include "MantidKernel/UnitFactory.h"
+#include "MantidKernel/ListValidator.h"
+#include "MantidCrystal/AnvredCorrection.h"
+#include <boost/math/special_functions/fpclassify.hpp>
+#include <fstream>
+#include <Poco/File.h>
+#include <Poco/Path.h>
+#include "boost/assign.hpp"
+
+using namespace Mantid::Geometry;
+using namespace Mantid::DataObjects;
+using namespace Mantid::Kernel;
+using namespace Mantid::API;
+using namespace Mantid::PhysicalConstants;
+using namespace boost::assign;
+
+namespace Mantid
+{
+namespace Crystal
+{
+
+  // Register the algorithm into the AlgorithmFactory
+  DECLARE_ALGORITHM(SaveLauenorm)
+
+
+  //----------------------------------------------------------------------------------------------
+  /** Constructor
+   */
+  SaveLauenorm::SaveLauenorm()
+  {
+  }
+    
+  //----------------------------------------------------------------------------------------------
+  /** Destructor
+   */
+  SaveLauenorm::~SaveLauenorm()
+  {
+  }
+  
+
+  //----------------------------------------------------------------------------------------------
+
+  //----------------------------------------------------------------------------------------------
+  /** Initialize the algorithm's properties.
+   */
+  void SaveLauenorm::init()
+  {
+    declareProperty(new WorkspaceProperty<PeaksWorkspace>("InputWorkspace","",Direction::Input),
+        "An input PeaksWorkspace.");
+    declareProperty(new API::FileProperty("Filename", "", API::FileProperty::Save),
+        "The filename to use for the saved data");
+    auto mustBePositive = boost::make_shared<BoundedValidator<double> >();
+    mustBePositive->setLower(0.0);
+    declareProperty("ScalePeaks", 1.0, mustBePositive,
+      "Multiply FSQ and sig(FSQ) by scaleFactor");
+    declareProperty("MinDSpacing", 0.0, "Minimum d-spacing (Angstroms)");
+    declareProperty("MinWavelength", 0.0, "Minimum wavelength (Angstroms)");
+    declareProperty("MaxWavelength", EMPTY_DBL(), "Maximum wavelength (Angstroms)");
+    std::vector<std::string> histoTypes;
+    histoTypes.push_back("Bank" );
+    histoTypes.push_back("RunNumber" );
+    histoTypes.push_back("Both Bank and RunNumber");
+    declareProperty("SortFilesBy", histoTypes[0],boost::make_shared<StringListValidator>(histoTypes),
+      "Sort into files by bank(default), run number or both.");
+    declareProperty("MinIsigI", EMPTY_DBL(), mustBePositive,
+       "The minimum I/sig(I) ratio");
+    declareProperty("WidthBorder", EMPTY_INT(), "Width of border of detectors");
+    declareProperty("MinIntensity", EMPTY_DBL(), mustBePositive,
+       "The minimum Intensity");
+  }
+
+  //----------------------------------------------------------------------------------------------
+  /** Execute the algorithm.
+   */
+  void SaveLauenorm::exec()
+  {
+
+	std::string filename = getProperty("Filename");
+    ws = getProperty("InputWorkspace");
+    double scaleFactor = getProperty("ScalePeaks"); 
+    double dMin = getProperty("MinDSpacing");
+    double wlMin = getProperty("MinWavelength");
+    double wlMax = getProperty("MaxWavelength");
+    std::string type = getProperty("SortFilesBy");
+    double minIsigI = getProperty("MinIsigI");
+    double minIntensity = getProperty("MinIntensity");
+    int widthBorder = getProperty("WidthBorder");
+
+    // sequenceNo and run number
+    int sequenceNo = 0;
+    int oldSequence = -1;
+
+    std::fstream out;
+    std::ostringstream ss;
+
+
+    // We must sort the peaks
+    std::vector< std::pair<std::string, bool> > criteria;
+    if(type.compare(0,2,"Ba")==0) criteria.push_back( std::pair<std::string, bool>("BankName", true) );
+    else if(type.compare(0,2,"Ru")==0) criteria.push_back( std::pair<std::string, bool>("RunNumber", true) );
+    else
+    {
+    	criteria.push_back( std::pair<std::string, bool>("RunNumber", true) );
+    	criteria.push_back( std::pair<std::string, bool>("BankName", true) );
+    }
+    criteria.push_back( std::pair<std::string, bool>("h", true) );
+    criteria.push_back( std::pair<std::string, bool>("k", true) );
+    criteria.push_back( std::pair<std::string, bool>("l", true) );
+    ws->sort(criteria);
+
+    std::vector<Peak> peaks= ws->getPeaks();
+
+    // ============================== Save all Peaks =========================================
+
+    // Go through each peak at this run / bank
+    for (int wi=0; wi < ws->getNumberPeaks(); wi++)
+    {
+
+      Peak & p = peaks[wi];
+      if (p.getIntensity() == 0.0 || boost::math::isnan(p.getIntensity()) || 
+        boost::math::isnan(p.getSigmaIntensity())) continue;
+      if (minIsigI != EMPTY_DBL() && p.getIntensity() < std::abs(minIsigI * p.getSigmaIntensity())) continue;
+      if (minIntensity != EMPTY_DBL() && p.getIntensity() < minIntensity) continue;
+      int sequence = p.getRunNumber();
+	  std::string bankName = p.getBankName();
+	  int nCols, nRows;
+	  sizeBanks(bankName, nCols, nRows);
+	  if (widthBorder != EMPTY_INT() && (p.getCol() < widthBorder || p.getRow() < widthBorder || p.getCol() > (nCols - widthBorder) ||
+			  p.getRow() > (nRows -widthBorder))) continue;
+      if(type.compare(0,2,"Ru")!=0)
+      {
+		  // Take out the "bank" part of the bank name and convert to an int
+		  bankName.erase(remove_if(bankName.begin(), bankName.end(), not1(std::ptr_fun (::isdigit))), bankName.end());
+		  Strings::convert(bankName, sequence);
+      }
+
+
+      // Two-theta = polar angle = scattering angle = between +Z vector and the scattered beam
+      double scattering = p.getScattering();
+      double lambda =  p.getWavelength();
+      double dsp = p.getDSpacing();
+      if(dsp < dMin || lambda < wlMin || (minIsigI != EMPTY_DBL() && lambda > wlMax)) continue;
+      // This can be bank number of run number depending on
+      if (sequence != oldSequence)
+      {
+    	  oldSequence = sequence;
+    	  out.flush();
+    	  out.close();
+    	  sequenceNo++;
+    	  ss.str("");
+    	  ss.clear();
+    	  ss << std::setw(3) << std::setfill('0') << sequenceNo;
+
+          Poco::Path path(filename);
+          std::string basename = path.getBaseName(); // Filename minus extension
+          // Chop off filename
+          path.makeParent();
+          path.append(basename + ss.str() );
+          Poco::File fileobj(path);
+          out.open(path.toString().c_str(), std::ios::out);
+      }
+      // h k l lambda theta intensity and  sig(intensity)  in format (3I5,2F10.5,2I10)
+      // HKL is flipped by -1 due to different q convention in ISAW vs mantid.
+      if (p.getH() == 0 && p.getK() == 0 && p.getL() == 0) continue;
+      out <<  std::setw( 5 ) << Utils::round(-p.getH())
+          <<  std::setw( 5 ) << Utils::round(-p.getK())
+          <<  std::setw( 5 ) << Utils::round(-p.getL());
+      out << std::setw( 10 ) << std::fixed << std::setprecision( 5 ) << lambda;
+      // Assume that want theta not two-theta
+      out << std::setw( 10 ) << std::fixed << std::setprecision( 5 ) << 0.5 * scattering;
+
+      // SHELX can read data without the space between the l and intensity
+      if(p.getDetectorID() != -1)
+      {
+		  double ckIntensity = scaleFactor*p.getIntensity();
+		  if (ckIntensity > 999999999.985) g_log.warning() << "Scaled intensity, " << ckIntensity << " is too large for format.  Decrease ScalePeaks.\n";
+		  out << std::setw( 10 ) << Utils::round(ckIntensity);
+
+		  out << std::setw( 10 ) << Utils::round(scaleFactor*p.getSigmaIntensity());
+      }
+      else
+      {
+    	  // This is data from LoadLauenorm which is already corrected
+          out << std::setw( 10 ) << Utils::round(p.getIntensity());
+
+          out << std::setw( 10 ) << Utils::round(p.getSigmaIntensity());
+      }
+
+      out << std::endl;
+    }
+
+    out.flush();
+    out.close();
+
+
+  }
+  void SaveLauenorm::sizeBanks(std::string bankName, int& nCols, int& nRows)
+  {
+         if (bankName.compare("None") == 0) return;
+         boost::shared_ptr<const IComponent> parent = ws->getInstrument()->getComponentByName(bankName);
+         if(!parent) return;
+         if (parent->type().compare("RectangularDetector") == 0)
+         {
+                        boost::shared_ptr<const RectangularDetector> RDet = boost::dynamic_pointer_cast<
+                                                                const RectangularDetector>(parent);
+
+                        nCols = RDet->xpixels();
+                        nRows = RDet->ypixels();
+         }
+         else
+         {
+                        std::vector<Geometry::IComponent_const_sptr> children;
+                        boost::shared_ptr<const Geometry::ICompAssembly> asmb = boost::dynamic_pointer_cast<const Geometry::ICompAssembly>(parent);
+                        asmb->getChildren(children, false);
+                        boost::shared_ptr<const Geometry::ICompAssembly> asmb2 = boost::dynamic_pointer_cast<const Geometry::ICompAssembly>(children[0]);
+                        std::vector<Geometry::IComponent_const_sptr> grandchildren;
+                        asmb2->getChildren(grandchildren,false);
+                        nRows = static_cast<int>(grandchildren.size());
+                        nCols = static_cast<int>(children.size());
+         }
+  }
+
+
+} // namespace Mantid
+} // namespace Crystal
diff --git a/Code/Mantid/Framework/Crystal/src/SelectCellOfType.cpp b/Code/Mantid/Framework/Crystal/src/SelectCellOfType.cpp
index 0b03b860bae2f3938d7c0bbbd237f9c724b9b560..35d895922958daebeee7a69b6e627b14cd1a06e7 100644
--- a/Code/Mantid/Framework/Crystal/src/SelectCellOfType.cpp
+++ b/Code/Mantid/Framework/Crystal/src/SelectCellOfType.cpp
@@ -137,7 +137,7 @@ namespace Crystal
 
       o_lattice.setError( sigabc[0],sigabc[1],sigabc[2],sigabc[3],sigabc[4],sigabc[5]);
 
-      ws->mutableSample().setOrientedLattice( new OrientedLattice(o_lattice) ); 
+      ws->mutableSample().setOrientedLattice( &o_lattice );
 
       std::vector<Peak> &peaks = ws->getPeaks();
       size_t n_peaks = ws->getNumberPeaks();
diff --git a/Code/Mantid/Framework/Crystal/src/SelectCellWithForm.cpp b/Code/Mantid/Framework/Crystal/src/SelectCellWithForm.cpp
index 8ee891db6cf9601f4676b25360c4596976e59863..713af5a866a9ea1943a86287bf7614be1432bb8a 100644
--- a/Code/Mantid/Framework/Crystal/src/SelectCellWithForm.cpp
+++ b/Code/Mantid/Framework/Crystal/src/SelectCellWithForm.cpp
@@ -172,7 +172,7 @@ namespace Crystal
 
     o_lattice.setError( sigabc[0],sigabc[1],sigabc[2],sigabc[3],sigabc[4],sigabc[5]);
 
-    ws->mutableSample().setOrientedLattice( new OrientedLattice(o_lattice) );
+    ws->mutableSample().setOrientedLattice( &o_lattice );
 
     std::vector<Peak> &peaks = ws->getPeaks();
     size_t n_peaks = ws->getNumberPeaks();
diff --git a/Code/Mantid/Framework/Crystal/src/SetUB.cpp b/Code/Mantid/Framework/Crystal/src/SetUB.cpp
index 9e862a781f16dc103e34d9ae61db02bcc32c015a..f47ec4aac81157ea2cf4f7677ca6bcfc55eec253 100644
--- a/Code/Mantid/Framework/Crystal/src/SetUB.cpp
+++ b/Code/Mantid/Framework/Crystal/src/SetUB.cpp
@@ -126,7 +126,7 @@ namespace Crystal
       if ((sampleNumber==EMPTY_INT()) || (sampleNumber<0)) //copy to all samples
       {
         for(uint16_t i=0;i<mdws->getNumExperimentInfo();i++)
-          mdws->getExperimentInfo(i)->mutableSample().setOrientedLattice(new OrientedLattice(o));
+          mdws->getExperimentInfo(i)->mutableSample().setOrientedLattice(&o);
       }
       else //copy to a single sample
       {
@@ -135,14 +135,14 @@ namespace Crystal
           g_log.warning()<<"Number greater than the number of last sample in the workspace ("<<(mdws->getNumExperimentInfo()-1)<<"). Will use sample number 0 instead\n";
           sampleNumber=0;
         }
-        mdws->getExperimentInfo(static_cast<uint16_t>(sampleNumber))->mutableSample().setOrientedLattice(new OrientedLattice(o));
+        mdws->getExperimentInfo(static_cast<uint16_t>(sampleNumber))->mutableSample().setOrientedLattice(&o);
       }
     }
     else //peaks workspace or matrix workspace
     {
       ExperimentInfo_sptr ei=boost::dynamic_pointer_cast<ExperimentInfo>(ws);
       if (!ei) throw std::invalid_argument("Wrong type of workspace");
-      ei->mutableSample().setOrientedLattice(new OrientedLattice(o));
+      ei->mutableSample().setOrientedLattice(&o);
     }
     this->setProperty("Workspace",ws);
   }
diff --git a/Code/Mantid/Framework/Crystal/src/ShowPossibleCells.cpp b/Code/Mantid/Framework/Crystal/src/ShowPossibleCells.cpp
index 66da33061d6df6e432293d81eb5cf58e6c9848f3..3df918a6c14b240105fec2bba36cb61bc5c091ad 100644
--- a/Code/Mantid/Framework/Crystal/src/ShowPossibleCells.cpp
+++ b/Code/Mantid/Framework/Crystal/src/ShowPossibleCells.cpp
@@ -40,7 +40,7 @@ namespace Crystal
   void ShowPossibleCells::init()
   {
     this->declareProperty(new WorkspaceProperty<PeaksWorkspace>(
-          "PeaksWorkspace","",Direction::Input), "Input Peaks Workspace");
+          "PeaksWorkspace","",Direction::InOut), "Input Peaks Workspace");
 
     auto mustBePositive = boost::make_shared<BoundedValidator<double> >();
     mustBePositive->setLower(0.0);
diff --git a/Code/Mantid/Framework/Crystal/src/TransformHKL.cpp b/Code/Mantid/Framework/Crystal/src/TransformHKL.cpp
index 97fc22064ede1194081baf97161b0fd54c287815..f239e6ceb01d02aae4a6c002e3b0c7d009744659 100644
--- a/Code/Mantid/Framework/Crystal/src/TransformHKL.cpp
+++ b/Code/Mantid/Framework/Crystal/src/TransformHKL.cpp
@@ -148,7 +148,7 @@ namespace Crystal
     std::vector<double> sigabc(6);
     SelectCellWithForm::DetermineErrors(sigabc,UB,ws, tolerance);
     o_lattice.setError( sigabc[0],sigabc[1],sigabc[2],sigabc[3],sigabc[4],sigabc[5]);
-    ws->mutableSample().setOrientedLattice( new OrientedLattice(o_lattice) );
+    ws->mutableSample().setOrientedLattice( &o_lattice );
 
     std::vector<Peak> &peaks = ws->getPeaks();
     size_t n_peaks = ws->getNumberPeaks();
diff --git a/Code/Mantid/Framework/Crystal/test/AnvredCorrectionTest.h b/Code/Mantid/Framework/Crystal/test/AnvredCorrectionTest.h
index 7d28aafa97a69136e9c99d9c1ec32596fcffea30..475b214b1901b57300c011740143c4c4debd7f20 100644
--- a/Code/Mantid/Framework/Crystal/test/AnvredCorrectionTest.h
+++ b/Code/Mantid/Framework/Crystal/test/AnvredCorrectionTest.h
@@ -9,6 +9,8 @@
 #include "MantidTestHelpers/ComponentCreationHelper.h"
 #include "MantidTestHelpers/FacilityHelper.h"
 #include "MantidTestHelpers/WorkspaceCreationHelper.h"
+#include "MantidDataHandling/RotateInstrumentComponent.h"
+#include "MantidDataHandling/MoveInstrumentComponent.h"
 #include <boost/random/linear_congruential.hpp>
 #include <boost/random/mersenne_twister.hpp>
 #include <boost/random/uniform_int.hpp>
@@ -37,93 +39,34 @@ public:
    *
    * @return EventWorkspace_sptr
    */
-  EventWorkspace_sptr createDiffractionEventWorkspace(int numEvents)
+  EventWorkspace_sptr createDiffractionEventWorkspace()
   {
-    FacilityHelper::ScopedFacilities loadTESTFacility("IDFs_for_UNIT_TESTING/UnitTestFacilities.xml", "TEST");
-
-    int numPixels = 10000;
-    int numBins = 16;
-    double binDelta = 0.10;
-    boost::mt19937 rng;
-    boost::uniform_real<double> u2(0, 1.0); // Random from 0 to 1.0
-    boost::variate_generator<boost::mt19937&, boost::uniform_real<double> > genUnit(rng, u2);
-    int randomSeed = 1;
-    rng.seed((unsigned int)(randomSeed));
-    size_t nd = 1;
-    // Make a random generator for each dimensions
-    typedef boost::variate_generator<boost::mt19937&, boost::uniform_real<double> >   gen_t;
-    gen_t * gens[1];
-    for (size_t d=0; d<nd; ++d)
-    {
-      double min = -1.;
-      double max = 1.;
-      if (max <= min) throw std::invalid_argument("UniformParams: min must be < max for all dimensions.");
-      boost::uniform_real<double> u(min,max); // Range
-      gen_t * gen = new gen_t(rng, u);
-      gens[d] = gen;
-    }
-
-
-
-    EventWorkspace_sptr retVal(new EventWorkspace);
-    retVal->initialize(numPixels,1,1);
-
-    // --------- Load the instrument -----------
-    LoadInstrument * loadInst = new LoadInstrument();
-    loadInst->initialize();
-    loadInst->setPropertyValue("Filename", "IDFs_for_UNIT_TESTING/MINITOPAZ_Definition.xml");
-    loadInst->setProperty<MatrixWorkspace_sptr> ("Workspace", retVal);
-    loadInst->execute();
-    delete loadInst;
-    // Populate the instrument parameters in this workspace - this works around a bug
-    retVal->populateInstrumentParameters();
-
-    DateAndTime run_start("2010-01-01T00:00:00");
-
-    for (int pix = 0; pix < numPixels; pix++)
-    {
-      EventList & el = retVal->getEventList(pix);
-      el.setSpectrumNo(pix);
-      el.addDetectorID(pix);
-      //Background
-      for (int i=0; i<numBins; i++)
-      {
-        //Two events per bin
-        el += TofEvent((i+0.5)*binDelta, run_start+double(i));
-        el += TofEvent((i+0.5)*binDelta, run_start+double(i));
-      }
-
-      //Peak
-      int r = static_cast<int>(numEvents/std::sqrt((pix/100-50.5)*(pix/100-50.5) + (pix%100-50.5)*(pix%100-50.5)));
-      for (int i=0; i<r; i++)
-      {
-        el += TofEvent(0.75+binDelta*(((*gens[0])()+(*gens[0])()+(*gens[0])())*2.-3.), run_start+double(i));
-      }
-
-    }
-
-    /// Clean up the generators
-    for (size_t d=0; d<nd; ++d)
-      delete gens[d];
-
-
-    //Create the x-axis for histogramming.
-    MantidVecPtr x1;
-    MantidVec& xRef = x1.access();
-    xRef.resize(numBins);
-    for (int i = 0; i < numBins; ++i)
-    {
-      xRef[i] = i*binDelta;
-    }
-
-    //Set all the histograms at once.
-    retVal->setAllX(x1);
-
-    // Some sanity checks
-    TS_ASSERT_EQUALS( retVal->getInstrument()->getName(), "MINITOPAZ");
-    std::map<int, Geometry::IDetector_const_sptr> dets;
-    retVal->getInstrument()->getDetectors(dets);
-    TS_ASSERT_EQUALS( dets.size(), 100*100);
+	// setup the test workspace
+	EventWorkspace_sptr retVal = WorkspaceCreationHelper::createEventWorkspaceWithFullInstrument(1,1,false);
+
+    MoveInstrumentComponent mover;
+    mover.initialize();
+    mover.setProperty("Workspace", retVal);
+    mover.setPropertyValue("ComponentName","bank1(x=0)");
+    mover.setPropertyValue("X","0.5");
+    mover.setPropertyValue("Y","0.");
+    mover.setPropertyValue("Z","-5");
+    mover.setPropertyValue("RelativePosition","1");
+    mover.execute();
+    double angle = -90.0;
+    Mantid::Kernel::V3D axis(0.,1.,0.);
+	RotateInstrumentComponent alg;
+	alg.initialize();
+	alg.setChild(true);
+	TS_ASSERT_THROWS_NOTHING(alg.setProperty("Workspace", retVal));
+	TS_ASSERT_THROWS_NOTHING(alg.setPropertyValue("ComponentName", "bank1(x=0)") );
+	TS_ASSERT_THROWS_NOTHING(alg.setProperty("X", axis.X()) );
+	TS_ASSERT_THROWS_NOTHING(alg.setProperty("Y", axis.Y()) );
+	TS_ASSERT_THROWS_NOTHING(alg.setProperty("Z", axis.Z()) );
+	TS_ASSERT_THROWS_NOTHING(alg.setProperty("Angle", angle) );
+	TS_ASSERT_THROWS_NOTHING(alg.setProperty("RelativeRotation", false) );
+	TS_ASSERT_THROWS_NOTHING( alg.execute(); );
+	TS_ASSERT( alg.isExecuted() );
 
     return retVal;
   }
@@ -137,12 +80,10 @@ public:
   
 
 
-  void do_test_MINITOPAZ(bool ev)
+  void do_test_events(bool ev)
   {
 
-    int numEventsPer = 100;
-    MatrixWorkspace_sptr inputW = createDiffractionEventWorkspace(numEventsPer);
-    EventWorkspace_sptr in_ws = boost::dynamic_pointer_cast<EventWorkspace>( inputW );
+    MatrixWorkspace_sptr inputW = createDiffractionEventWorkspace();
     inputW->getAxis(0)->setUnit("Wavelength");
 
     AnvredCorrection alg;
@@ -152,9 +93,9 @@ public:
     alg.setProperty("OutputWorkspace", "TOPAZ");
     alg.setProperty("PreserveEvents", ev);
     alg.setProperty("OnlySphericalAbsorption", false);
-    alg.setProperty("LinearScatteringCoef", 1.302);
-    alg.setProperty("LinearAbsorptionCoef", 1.686);
-    alg.setProperty("Radius", 0.17);
+    alg.setProperty("LinearScatteringCoef", 0.369);
+    alg.setProperty("LinearAbsorptionCoef", 0.011);
+    alg.setProperty("Radius", 0.05);
     alg.setProperty("PowerLambda", 3.0);
     TS_ASSERT_THROWS_NOTHING( alg.execute(); )
     TS_ASSERT( alg.isExecuted() )
@@ -164,14 +105,19 @@ public:
         ws = AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>("TOPAZ") );
     TS_ASSERT(ws);
     if (!ws) return;
-    TS_ASSERT_DELTA( ws->readY(5050)[5], 130.0, 6.0);
+    // do the final comparison
+    const MantidVec & y_actual = ws->readY(0);
+    TS_ASSERT_DELTA(y_actual[0], 8.2052, 0.0001);
+    TS_ASSERT_DELTA(y_actual[1], 0.3040, 0.0001);
+    TS_ASSERT_DELTA(y_actual[2], 0.0656, 0.0001);
+
     AnalysisDataService::Instance().remove("TOPAZ");
   }
 
-  void test_MINITOPAZ()
+  void test_events()
   {
-    do_test_MINITOPAZ(true);
-    do_test_MINITOPAZ(false);
+    do_test_events(true);
+    do_test_events(false);
   }
 
 
diff --git a/Code/Mantid/Framework/Crystal/test/CalculatePeaksHKLTest.h b/Code/Mantid/Framework/Crystal/test/CalculatePeaksHKLTest.h
index 84bed6966764c0d3653b596eaf40c8fd8230c66c..f239ec794cf1473dd93401bf38a8d1697d626416 100644
--- a/Code/Mantid/Framework/Crystal/test/CalculatePeaksHKLTest.h
+++ b/Code/Mantid/Framework/Crystal/test/CalculatePeaksHKLTest.h
@@ -56,6 +56,7 @@ public:
     auto ws = WorkspaceCreationHelper::createPeaksWorkspace(10);
     ws->mutableSample().setOrientedLattice(lattice);
 
+    delete lattice;
     Mantid::API::AnalysisDataService::Instance().addOrReplace("ws", ws);
 
     CalculatePeaksHKL alg;
@@ -87,6 +88,8 @@ public:
     ws->mutableSample().setOrientedLattice(lattice);
     ws->getPeak(0).setHKL(1, 1, 1);// First peak is already indexed now.
 
+    delete lattice;
+
     Mantid::API::AnalysisDataService::Instance().addOrReplace("ws", ws);
 
     CalculatePeaksHKL alg;
@@ -112,6 +115,8 @@ public:
     ws->mutableSample().setOrientedLattice(lattice);
     ws->getPeak(0).setHKL(1, 1, 1);// First peak is already indexed now.
 
+    delete lattice;
+
     Mantid::API::AnalysisDataService::Instance().addOrReplace("ws", ws);
 
     CalculatePeaksHKL alg;
diff --git a/Code/Mantid/Framework/Crystal/test/CalculateUMatrixTest.h b/Code/Mantid/Framework/Crystal/test/CalculateUMatrixTest.h
index 38cca516ead807e74b6085cdbee0b07d02feea10..60ca8c8eaffaeec215e7e4507e4b6bfe7f9054df 100644
--- a/Code/Mantid/Framework/Crystal/test/CalculateUMatrixTest.h
+++ b/Code/Mantid/Framework/Crystal/test/CalculateUMatrixTest.h
@@ -8,9 +8,7 @@
 #include <iomanip>
 
 #include "MantidCrystal/CalculateUMatrix.h"
-#include "MantidCrystal/LoadIsawPeaks.h"
 #include "MantidGeometry/Crystal/OrientedLattice.h"
-#include "MantidCrystal/LoadIsawUB.h"
 
 #include "MantidDataObjects/PeaksWorkspace.h"
 #include "MantidKernel/V3D.h"
@@ -37,15 +35,8 @@ public:
   void test_exec()
   {
     // Name of the output workspace.
-    std::string WSName("peaks");
-    LoadIsawPeaks loader;
-    TS_ASSERT_THROWS_NOTHING( loader.initialize() );
-    TS_ASSERT( loader.isInitialized() );
-    loader.setPropertyValue("Filename", "TOPAZ_3007.peaks");
-    loader.setPropertyValue("OutputWorkspace", WSName);
-
-    TS_ASSERT( loader.execute() );
-    TS_ASSERT( loader.isExecuted() );
+    std::string WSName("peaksCalculateUMatrix");
+    generatePeaks(WSName);
 
     PeaksWorkspace_sptr ws;
     TS_ASSERT_THROWS_NOTHING( ws = boost::dynamic_pointer_cast<PeaksWorkspace>(
@@ -55,11 +46,11 @@ public:
     CalculateUMatrix alg;
     TS_ASSERT_THROWS_NOTHING( alg.initialize() )
     TS_ASSERT( alg.isInitialized() )
-    TS_ASSERT_THROWS_NOTHING( alg.setPropertyValue("a", "14.1526") );
-    TS_ASSERT_THROWS_NOTHING( alg.setPropertyValue("b", "19.2903") );
-    TS_ASSERT_THROWS_NOTHING( alg.setPropertyValue("c", "8.5813") );
+    TS_ASSERT_THROWS_NOTHING( alg.setPropertyValue("a", "2.") );
+    TS_ASSERT_THROWS_NOTHING( alg.setPropertyValue("b", "3.") );
+    TS_ASSERT_THROWS_NOTHING( alg.setPropertyValue("c", "4.") );
     TS_ASSERT_THROWS_NOTHING( alg.setPropertyValue("alpha", "90") );
-    TS_ASSERT_THROWS_NOTHING( alg.setPropertyValue("beta", "105.0738") );
+    TS_ASSERT_THROWS_NOTHING( alg.setPropertyValue("beta",  "90") );
     TS_ASSERT_THROWS_NOTHING( alg.setPropertyValue("gamma", "90") );
     TS_ASSERT_THROWS_NOTHING( alg.setPropertyValue("PeaksWorkspace", WSName) );
     TS_ASSERT_THROWS_NOTHING( alg.execute(); );
@@ -69,17 +60,16 @@ public:
     TS_ASSERT(ws->mutableSample().hasOrientedLattice());
     // Check that the UB matrix is the same as in TOPAZ_3007.mat
     OrientedLattice latt=ws->mutableSample().getOrientedLattice();
+    DblMatrix U(3,3,false);
+    U[0][0]=sqrt(3.)*0.5;
+    U[2][2]=sqrt(3.)*0.5;
+    U[2][0]=0.5;
+    U[0][2]=-0.5;
+    U[1][1]=1.;
 
-    LoadIsawUB alg1;
-    TS_ASSERT_THROWS_NOTHING( alg1.initialize() )
-    TS_ASSERT( alg1.isInitialized() )
-    TS_ASSERT_THROWS_NOTHING( alg1.setPropertyValue("Filename", "TOPAZ_3007.mat") );
-    TS_ASSERT_THROWS_NOTHING( alg1.setPropertyValue("InputWorkspace", WSName) );
-    TS_ASSERT_THROWS_NOTHING( alg1.execute(); );
-    TS_ASSERT_THROWS_NOTHING( alg1.isExecuted(); );
-    OrientedLattice lattFromUB=ws->mutableSample().getOrientedLattice();
 
-    TS_ASSERT(latt.getUB().equals(lattFromUB.getUB(),2e-4)); //Some values differ by up to 1.7e-4
+    TS_ASSERT(latt.getU().equals(U,1e-10));
+
     // Remove workspace from the data service.
     AnalysisDataService::Instance().remove(WSName);
   }
@@ -145,6 +135,82 @@ public:
     TS_ASSERT( alg2.isExecuted() );
     AnalysisDataService::Instance().remove(WSName);
   }
+
+private:
+  DblMatrix UB;
+
+  void setupUB()
+  {
+      OrientedLattice ol;
+      DblMatrix U(3,3,false);
+      U[0][0]=sqrt(3.)*0.5;
+      U[2][2]=sqrt(3.)*0.5;
+      U[2][0]=0.5;
+      U[0][2]=-0.5;
+      U[1][1]=1.;
+      ol.set(2,3,4,90,90,90);
+      ol.setU(U);
+      UB=ol.getUB();
+  }
+
+  double QXUB(double H, double K, double L)
+  {
+     return (UB*V3D(H,K,L))[0]*2.*M_PI;
+  }
+
+  double QYUB(double H, double K, double L)
+  {
+     return (UB*V3D(H,K,L))[1]*2.*M_PI;
+  }
+
+  double QZUB(double H, double K, double L)
+  {
+     return (UB*V3D(H,K,L))[2]*2.*M_PI;
+  }
+
+  double lam(double H,double K,double L)
+  {
+      return 2.*QZUB(H,K,L)/(QXUB(H,K,L)*QXUB(H,K,L)+QYUB(H,K,L)*QYUB(H,K,L)+QZUB(H,K,L)*QZUB(H,K,L))*2.*M_PI;
+  }
+
+  double th(double H,double K,double L)
+  {
+      return acos(1.-QZUB(H,K,L)*lam(H,K,L)/2./M_PI);
+  }
+
+  double ph(double H,double K,double L)
+  {
+      return atan2(-QYUB(H,K,L),-QXUB(H,K,L));
+  }
+
+  void generatePeaks(std::string WSName)
+  {
+      setupUB();
+
+      double Hpeaks[9]={0,1,1,0,-1,-1,1,-3,-2};
+      double Kpeaks[9]={3,0,4,0,2,0,2,3,1};
+      double Lpeaks[9]={3,5,5,2,3,2,4,5,3};
+
+      std::vector<double> lambda(9),theta(9),phi(9),L2(9,1.);
+      for(int i=0;i<=8;i++)
+      {
+          lambda.at(i)=lam(Hpeaks[i],Kpeaks[i],Lpeaks[i]);
+          theta.at(i)=th(Hpeaks[i],Kpeaks[i],Lpeaks[i]);
+          phi.at(i)=ph(Hpeaks[i],Kpeaks[i],Lpeaks[i]);
+      }
+
+      Mantid::Geometry::Instrument_sptr inst = ComponentCreationHelper::createCylInstrumentWithDetInGivenPosisions(L2,theta, phi);
+      inst->setName("SillyInstrument");
+      auto pw = PeaksWorkspace_sptr(new PeaksWorkspace);
+      pw->setInstrument(inst);
+      for(int i=0;i<=8;i++)
+      {
+        Peak p(inst, i+1, lambda[i],V3D(Hpeaks[i],Kpeaks[i],Lpeaks[i]));
+        pw->addPeak(p);
+      }
+      AnalysisDataService::Instance().addOrReplace(WSName,pw);
+  }
+
 };
 
 
diff --git a/Code/Mantid/Framework/Crystal/test/ClearUBTest.h b/Code/Mantid/Framework/Crystal/test/ClearUBTest.h
index 33837904caffa2ef08bb3bd8e1713b09a9dd1952..ae1189b6a6125fdc7353fce75ffe3fa08f0b325c 100644
--- a/Code/Mantid/Framework/Crystal/test/ClearUBTest.h
+++ b/Code/Mantid/Framework/Crystal/test/ClearUBTest.h
@@ -39,8 +39,8 @@ private:
     auto ws = WorkspaceCreationHelper::Create2DWorkspace(1, 2);
     if(withOrientedLattice)
     {
-      OrientedLattice *latt = new OrientedLattice(1.0,2.0,3.0, 90, 90, 90);
-      ws->mutableSample().setOrientedLattice(latt);
+      OrientedLattice latt(1.0,2.0,3.0, 90, 90, 90);
+      ws->mutableSample().setOrientedLattice(&latt);
     }
     const std::string wsName = "TestWorkspace";
     AnalysisDataService::Instance().addOrReplace(wsName, ws);
@@ -53,13 +53,14 @@ private:
   {
     const std::string wsName = "TestWorkspace";
     auto ws = MDEventsTestHelper::makeFakeMDHistoWorkspace(1, 1, 10, 10, 1, wsName);
-    ws->getExperimentInfo(0)->mutableSample().setOrientedLattice(new OrientedLattice(1.0,2.0,3.0, 90, 90,90));
+    OrientedLattice latt(1.0,2.0,3.0, 90, 90,90);
+    ws->getExperimentInfo(0)->mutableSample().setOrientedLattice(&latt);
 
     for(uint16_t i = 1; i < nExperimentInfosToAdd; ++i)
     {
       ExperimentInfo_sptr experimentInfo = boost::make_shared<ExperimentInfo>();
       ws->addExperimentInfo(experimentInfo);
-      ws->getExperimentInfo(i)->mutableSample().setOrientedLattice(new OrientedLattice(1.0,2.0,3.0, 90, 90,90));
+      ws->getExperimentInfo(i)->mutableSample().setOrientedLattice(&latt);
     }
 
     AnalysisDataService::Instance().addOrReplace(wsName, ws);
diff --git a/Code/Mantid/Framework/Crystal/test/HasUBTest.h b/Code/Mantid/Framework/Crystal/test/HasUBTest.h
index 892f308fbbd6397f8d5daeec1aede37ec7c115d8..d5e6628792d36c8bc32307c090c56641a3687bf8 100644
--- a/Code/Mantid/Framework/Crystal/test/HasUBTest.h
+++ b/Code/Mantid/Framework/Crystal/test/HasUBTest.h
@@ -28,6 +28,7 @@ private:
     {
       OrientedLattice *latt = new OrientedLattice(1.0, 2.0, 3.0, 90, 90, 90);
       ws->mutableSample().setOrientedLattice(latt);
+      delete latt;
     }
     const std::string wsName = "TestWorkspace";
     AnalysisDataService::Instance().addOrReplace(wsName, ws);
@@ -40,17 +41,17 @@ private:
   {
     const std::string wsName = "TestWorkspace";
     auto ws = MDEventsTestHelper::makeFakeMDHistoWorkspace(1, 1, 10, 10, 1, wsName);
-    ws->getExperimentInfo(0)->mutableSample().setOrientedLattice(
-        new OrientedLattice(1.0, 2.0, 3.0, 90, 90, 90));
+    OrientedLattice *latt =new OrientedLattice(1.0, 2.0, 3.0, 90, 90, 90);
+    ws->getExperimentInfo(0)->mutableSample().setOrientedLattice(latt);
 
     for (uint16_t i = 1; i < nExperimentInfosToAdd; ++i)
     {
       ExperimentInfo_sptr experimentInfo = boost::make_shared<ExperimentInfo>();
       ws->addExperimentInfo(experimentInfo);
-      ws->getExperimentInfo(i)->mutableSample().setOrientedLattice(
-          new OrientedLattice(1.0, 2.0, 3.0, 90, 90, 90));
+      ws->getExperimentInfo(i)->mutableSample().setOrientedLattice(latt);
     }
 
+    delete latt;
     AnalysisDataService::Instance().addOrReplace(wsName, ws);
     return wsName;
   }
diff --git a/Code/Mantid/Framework/Crystal/test/IndexPeaksTest.h b/Code/Mantid/Framework/Crystal/test/IndexPeaksTest.h
index c021ef468b2a069e668d7b9c23a541f3f197b09b..717c7ce43b3620ec8010482f649387091a049a95 100644
--- a/Code/Mantid/Framework/Crystal/test/IndexPeaksTest.h
+++ b/Code/Mantid/Framework/Crystal/test/IndexPeaksTest.h
@@ -67,7 +67,7 @@ public:
 
     OrientedLattice o_lattice;
     o_lattice.setUB( UB );
-    ws->mutableSample().setOrientedLattice( new OrientedLattice(o_lattice) );
+    ws->mutableSample().setOrientedLattice( &o_lattice );
 
                                            // index the peaks with the new UB
     IndexPeaks alg;
diff --git a/Code/Mantid/Framework/Crystal/test/PredictFractionalPeaksTest.h b/Code/Mantid/Framework/Crystal/test/PredictFractionalPeaksTest.h
index 1a09f4ab84e161b443fcd55443cf4bc81849e8c8..9b1bf9f7c034d17f37a6283ff4ee8c6205d76b46 100644
--- a/Code/Mantid/Framework/Crystal/test/PredictFractionalPeaksTest.h
+++ b/Code/Mantid/Framework/Crystal/test/PredictFractionalPeaksTest.h
@@ -85,7 +85,7 @@ public:
     TS_ASSERT( alg.execute() );
     TS_ASSERT( alg.isExecuted() );
     alg.setPropertyValue("FracPeaks","FracPeaks");
-    PeaksWorkspace_sptr FracPeaks= alg.getProperty("FracPeaks");
+    IPeaksWorkspace_sptr FracPeaks = alg.getProperty("FracPeaks");
 
     TS_ASSERT_EQUALS(FracPeaks->getNumberPeaks(),117);
 
diff --git a/Code/Mantid/Framework/Crystal/test/SaveLauenormTest.h b/Code/Mantid/Framework/Crystal/test/SaveLauenormTest.h
new file mode 100644
index 0000000000000000000000000000000000000000..df692301366188829e8c50f13e89e6d2b98f6cf9
--- /dev/null
+++ b/Code/Mantid/Framework/Crystal/test/SaveLauenormTest.h
@@ -0,0 +1,104 @@
+#ifndef MANTID_CRYSTAL_SAVELauenormTEST_H_
+#define MANTID_CRYSTAL_SAVELauenormTEST_H_
+
+#include "MantidCrystal/SaveLauenorm.h"
+#include "MantidDataObjects/Peak.h"
+#include "MantidDataObjects/PeaksWorkspace.h"
+#include "MantidGeometry/IDTypes.h"
+#include "MantidKernel/System.h"
+#include "MantidKernel/Timer.h"
+#include "MantidTestHelpers/ComponentCreationHelper.h"
+#include <cxxtest/TestSuite.h>
+#include <iomanip>
+#include <iostream>
+#include <fstream>
+#include <Poco/File.h>
+
+using namespace Mantid;
+using namespace Mantid::Crystal;
+using namespace Mantid::API;
+using namespace Mantid::Geometry;
+using namespace Mantid::Kernel;
+using namespace Mantid::DataObjects;
+using namespace Mantid::PhysicalConstants;
+
+class SaveLauenormTest : public CxxTest::TestSuite
+{
+public:
+    
+  void test_Init()
+  {
+    SaveLauenorm alg;
+    TS_ASSERT_THROWS_NOTHING( alg.initialize() )
+    TS_ASSERT( alg.isInitialized() )
+  }
+  
+  void do_test(int numRuns, size_t numBanks, size_t numPeaksPerBank)
+  {
+    Instrument_sptr inst = ComponentCreationHelper::createTestInstrumentRectangular(4, 10, 1.0);
+    PeaksWorkspace_sptr ws(new PeaksWorkspace());
+    ws->setInstrument(inst);
+
+    for (int run=1000; run<numRuns+1000; run++)
+      for (size_t b=1; b<=numBanks; b++)
+      for (size_t i=0; i<numPeaksPerBank; i++)
+      {
+        V3D hkl(static_cast<double>(i), static_cast<double>(i), static_cast<double>(i));
+        DblMatrix gon(3,3, true);
+        Peak p(inst, static_cast<detid_t>(b*100 + i+1+i*10), static_cast<double>(i)*1.0+0.5, hkl, gon);
+        p.setRunNumber(run);
+        p.setBankName("bank1");
+        p.setIntensity( static_cast<double>(i)+0.1);
+        p.setSigmaIntensity( sqrt(static_cast<double>(i)));
+        p.setBinCount( static_cast<double>(i) );
+        ws->addPeak(p);
+      }
+
+    std::string outfile = "./LAUE";
+    SaveLauenorm alg;
+    TS_ASSERT_THROWS_NOTHING( alg.initialize() )
+    TS_ASSERT( alg.isInitialized() )
+    TS_ASSERT_THROWS_NOTHING( alg.setProperty("InputWorkspace", ws) );
+    TS_ASSERT_THROWS_NOTHING( alg.setPropertyValue("Filename", outfile) );
+    TS_ASSERT_THROWS_NOTHING( alg.execute(); );
+    TS_ASSERT( alg.isExecuted() );
+    
+    // Get the file
+    outfile = alg.getPropertyValue("Filename")+"001";
+    bool fileExists = false;
+    TS_ASSERT( fileExists = Poco::File(outfile).exists() );
+    if ( fileExists )
+    {
+
+      std::ifstream in(outfile.c_str());
+
+      double d1,d2,d3,d4,d5,d6,d7;
+      if(numPeaksPerBank > 0)
+      {
+        in >> d1 >> d2 >> d3 >> d4 >> d5 >>d6 >> d7;
+        TS_ASSERT_EQUALS(d1,-1 );
+        TS_ASSERT_EQUALS(d2,-1 );
+        TS_ASSERT_EQUALS(d3,-1 );
+        TS_ASSERT_EQUALS(d6,1 );
+        TS_ASSERT_EQUALS(d7,1 );
+        TS_ASSERT_EQUALS(d4,1.5 );
+        TS_ASSERT_DELTA(d5,0.21025 , 1e-4);
+      }
+    }
+
+    if (Poco::File(outfile).exists())
+      Poco::File(outfile).remove();
+  }
+
+  /// Test with a few peaks
+  void test_exec()
+  {
+    do_test(2, 4,4);
+  }
+
+
+};
+
+
+#endif /* MANTID_CRYSTAL_SAVELauenormTEST_H_ */
+
diff --git a/Code/Mantid/Framework/Crystal/test/SelectCellOfTypeTest.h b/Code/Mantid/Framework/Crystal/test/SelectCellOfTypeTest.h
index 1403096e4f0aa5466ab6fb1816e9cf404416cd0a..c671c150f18714177e1fb7364161287537a3a9f9 100644
--- a/Code/Mantid/Framework/Crystal/test/SelectCellOfTypeTest.h
+++ b/Code/Mantid/Framework/Crystal/test/SelectCellOfTypeTest.h
@@ -60,7 +60,7 @@ public:
 
     OrientedLattice o_lattice;
     o_lattice.setUB( UB );
-    ws->mutableSample().setOrientedLattice( new OrientedLattice(o_lattice) );
+    ws->mutableSample().setOrientedLattice( &o_lattice );
 
                                            // now get the UB back from the WS
     UB = o_lattice.getUB();
diff --git a/Code/Mantid/Framework/Crystal/test/SelectCellWithFormTest.h b/Code/Mantid/Framework/Crystal/test/SelectCellWithFormTest.h
index ab29a82fcb905aa470440c0fd7ba71ff7215839d..944258894d3fd8732d304893c78af84fe25ae9a4 100644
--- a/Code/Mantid/Framework/Crystal/test/SelectCellWithFormTest.h
+++ b/Code/Mantid/Framework/Crystal/test/SelectCellWithFormTest.h
@@ -60,7 +60,7 @@ public:
 
     OrientedLattice o_lattice;
     o_lattice.setUB( UB );
-    ws->mutableSample().setOrientedLattice( new OrientedLattice(o_lattice) );
+    ws->mutableSample().setOrientedLattice( &o_lattice );
 
                                            // now get the UB back from the WS
     UB = o_lattice.getUB();
diff --git a/Code/Mantid/Framework/Crystal/test/ShowPossibleCellsTest.h b/Code/Mantid/Framework/Crystal/test/ShowPossibleCellsTest.h
index 9578fa1acd13fc4a27053f214f868342e0f4e23c..4ff3c365a5cc558e4c14976c591b40b44d5db0cc 100644
--- a/Code/Mantid/Framework/Crystal/test/ShowPossibleCellsTest.h
+++ b/Code/Mantid/Framework/Crystal/test/ShowPossibleCellsTest.h
@@ -60,7 +60,7 @@ public:
 
     OrientedLattice o_lattice;
     o_lattice.setUB( UB );
-    ws->mutableSample().setOrientedLattice( new OrientedLattice(o_lattice) );
+    ws->mutableSample().setOrientedLattice( &o_lattice );
 
                                            // now get the UB back from the WS
     UB = o_lattice.getUB();
diff --git a/Code/Mantid/Framework/Crystal/test/TransformHKLTest.h b/Code/Mantid/Framework/Crystal/test/TransformHKLTest.h
index 70340bada9fc20a41390e315fb8fb59a4f274ca2..154b8dc03a6b870f5b7c0295937e3c485c428cba 100644
--- a/Code/Mantid/Framework/Crystal/test/TransformHKLTest.h
+++ b/Code/Mantid/Framework/Crystal/test/TransformHKLTest.h
@@ -60,7 +60,7 @@ public:
 
     OrientedLattice o_lattice;
     o_lattice.setUB( UB );
-    ws->mutableSample().setOrientedLattice( new OrientedLattice(o_lattice) );
+    ws->mutableSample().setOrientedLattice( &o_lattice );
 
     Matrix<double> UB_inverse(UB);
     UB_inverse.Invert();
diff --git a/Code/Mantid/Framework/CurveFitting/CMakeLists.txt b/Code/Mantid/Framework/CurveFitting/CMakeLists.txt
index 739905c09c96d30925d5fd0b031273a757b43c21..c0906757d86a153f51650c8a9ad346827c2c05fa 100644
--- a/Code/Mantid/Framework/CurveFitting/CMakeLists.txt
+++ b/Code/Mantid/Framework/CurveFitting/CMakeLists.txt
@@ -94,12 +94,16 @@ set ( SRC_FILES
 	src/ThermalNeutronDtoTOFFunction.cpp
 	src/UserFunction.cpp
 	src/UserFunction1D.cpp
+  src/VesuvioResolution.cpp
 	src/Voigt.cpp
+  src/FakeMinimizer.cpp
+
 )
                 
 set ( SRC_UNITY_IGNORE_FILES src/Fit1D.cpp src/GSLFunctions.cpp )
 
 set ( INC_FILES
+  inc/MantidCurveFitting/FakeMinimizer.h
 	#	inc/MantidCurveFitting/CostFuncIgnorePosPeaks.h
 	#	inc/MantidCurveFitting/SCDPanelErrors.h
 	# inc/MantidCurveFitting/ChebyshevPolynomialBackground.h
@@ -199,6 +203,7 @@ set ( INC_FILES
 	inc/MantidCurveFitting/ThermalNeutronDtoTOFFunction.h
 	inc/MantidCurveFitting/UserFunction.h
 	inc/MantidCurveFitting/UserFunction1D.h
+  inc/MantidCurveFitting/VesuvioResolution.h
 	inc/MantidCurveFitting/Voigt.h
 )
               
@@ -233,8 +238,9 @@ set ( TEST_FILES
 	ExpDecayOscTest.h
 	ExpDecayTest.h
 	FRConjugateGradientTest.h
-	FitMWTest.h
-	FitPowderDiffPeaksTest.h
+  FitMWTest.h
+  FitTest.h
+  FitPowderDiffPeaksTest.h
 	FlatBackgroundTest.h
 	FullprofPolynomialTest.h
 	FunctionDomain1DSpectrumCreatorTest.h
@@ -290,6 +296,7 @@ set ( TEST_FILES
 	ThermalNeutronDtoTOFFunctionTest.h
 	UserFunction1DTest.h
 	UserFunctionTest.h
+  VesuvioResolutionTest.h
 	VoigtTest.h
 )
 
diff --git a/Code/Mantid/Framework/CurveFitting/inc/MantidCurveFitting/ComptonProfile.h b/Code/Mantid/Framework/CurveFitting/inc/MantidCurveFitting/ComptonProfile.h
index 291c5af1866d3bbcf42b0f071190d0bb37f35b25..03df34e5a4832f7a6a211828943c6dc4a7c2a608 100644
--- a/Code/Mantid/Framework/CurveFitting/inc/MantidCurveFitting/ComptonProfile.h
+++ b/Code/Mantid/Framework/CurveFitting/inc/MantidCurveFitting/ComptonProfile.h
@@ -2,6 +2,7 @@
 #define MANTID_CURVEFITTING_COMPTONPROFILE_H_
 
 #include "MantidCurveFitting/DllConfig.h"
+#include "MantidCurveFitting/VesuvioResolution.h"
 #include "MantidAPI/IPeakFunction.h"
 #include "MantidAPI/MatrixWorkspace.h"
 #include "MantidAPI/ParamFunction.h"
@@ -15,18 +16,6 @@ namespace CurveFitting
   //---------------------------------------------------------------------------
   struct DetectorParams;
 
-  //---------------------------------------------------------------------------
-  /// Simple data structure to store resolution parameter values
-  /// It avoids some functions taking a huge number of arguments
-  struct ResolutionParams
-  {
-    double dl1; ///< spread in source-sample distance
-    double dl2; ///< spread in sample-detector distance
-    double dthe; ///< spread in scattering angle
-    double dEnLorentz; ///< lorentz width in energy
-    double dEnGauss; ///< gaussian width in energy
-  };
-
   /**
     This class serves as a base-class for ComptonProfile type functions. @see GaussianComptonProfile, GramCharlierComptonProfile
     
@@ -64,9 +53,14 @@ namespace CurveFitting
     void setUpForFit();
     /// Cache a copy of the workspace pointer and pull out the parameters
     void setMatrixWorkspace(boost::shared_ptr<const API::MatrixWorkspace> workspace,size_t wi,double startX, double endX);
+
+    /// Pre-calculate the Y-space values with specified resolution parameters
+    void cacheYSpaceValues(const std::vector<double> & tseconds, const bool isHistogram,
+                                         const DetectorParams & detpar, const ResolutionParams& respar);
+
     /// Pre-calculate the Y-space values
     virtual void cacheYSpaceValues(const std::vector<double> & tseconds, const bool isHistogram,
-                                   const DetectorParams & detpar,const ResolutionParams & respar);
+                                   const DetectorParams & detpar);
     /// Turn off logger
     void disableLogging() { m_log.setEnabled(false); }
     ///@}
@@ -95,11 +89,7 @@ namespace CurveFitting
     inline const std::vector<double> & e0() const { return m_e0; }
     /// Access the mass
     inline double mass() const { return m_mass; }
-    /// Access total resolution width
-    inline double resolutionFWHM() const { return m_resolutionSigma; }
-    /// Access lorentz FWHM
-    inline double lorentzFWHM() const { return m_lorentzFWHM; }
-
+    
     /// Compute Voigt function interpolated around the given values
     void voigtApproxDiff(std::vector<double> & voigtDiff, const std::vector<double> & yspace, const double lorentzPos, const double lorentzAmp,
                          const double lorentzWidth, const double gaussWidth) const;
@@ -118,6 +108,8 @@ namespace CurveFitting
 
     /// Voigt function
     boost::shared_ptr<API::IPeakFunction> m_voigt;
+    /// Vesuvio resolution function
+    boost::shared_ptr<VesuvioResolution> m_resolutionFunction;
 
     /** @name Caches for commonly used values*/
     ///@{
@@ -127,10 +119,6 @@ namespace CurveFitting
     std::vector<double> m_modQ;
     /// Incident energies
     std::vector<double> m_e0;
-    /// Total resolution width
-    double m_resolutionSigma;
-    /// Lorentz FWHM
-    double m_lorentzFWHM;
     ///@}
 
   };
diff --git a/Code/Mantid/Framework/CurveFitting/inc/MantidCurveFitting/DampingMinimizer.h b/Code/Mantid/Framework/CurveFitting/inc/MantidCurveFitting/DampingMinimizer.h
index e32af3fa59da007df07b37de1aec2885c3cb0ffb..76e49b1531486d440936b886b7b78f62e43af2e5 100644
--- a/Code/Mantid/Framework/CurveFitting/inc/MantidCurveFitting/DampingMinimizer.h
+++ b/Code/Mantid/Framework/CurveFitting/inc/MantidCurveFitting/DampingMinimizer.h
@@ -49,9 +49,9 @@ public:
   std::string name() const {return "DampingMinimizer";}
 
   /// Initialize minimizer, i.e. pass a function to minimize.
-  virtual void initialize(API::ICostFunction_sptr function);
+  virtual void initialize(API::ICostFunction_sptr function,size_t maxIterations = 0);
   /// Do one iteration.
-  virtual bool iterate();
+  virtual bool iterate(size_t);
   /// Return current value of the cost function
   virtual double costFunctionVal();
 
diff --git a/Code/Mantid/Framework/CurveFitting/inc/MantidCurveFitting/DerivMinimizer.h b/Code/Mantid/Framework/CurveFitting/inc/MantidCurveFitting/DerivMinimizer.h
index 7bb99eab54ab805398724902adb6df6d4db4becd..3f66f271a64cc21751b426ca8f0c7d3b0288ddf2 100644
--- a/Code/Mantid/Framework/CurveFitting/inc/MantidCurveFitting/DerivMinimizer.h
+++ b/Code/Mantid/Framework/CurveFitting/inc/MantidCurveFitting/DerivMinimizer.h
@@ -49,13 +49,13 @@ public:
   ~DerivMinimizer();
 
   /// Do one iteration.
-  bool iterate();
+  bool iterate(size_t);
   /// Return current value of the cost function
   double costFunctionVal();
   /// Calculate the covariance matrix.
   void calCovarianceMatrix(gsl_matrix * covar, double epsrel = 0.0001);
   /// Initialize minimizer, i.e. pass a function to minimize.
-  virtual void initialize(API::ICostFunction_sptr function);
+  virtual void initialize(API::ICostFunction_sptr function,size_t maxIterations = 0);
   /// Set maximum value of the gradient at which iterations can stop
   void setStopGradient(const double value);
 
diff --git a/Code/Mantid/Framework/CurveFitting/inc/MantidCurveFitting/FakeMinimizer.h b/Code/Mantid/Framework/CurveFitting/inc/MantidCurveFitting/FakeMinimizer.h
new file mode 100644
index 0000000000000000000000000000000000000000..65ed977845bbad47d6f2b4b994acdc8686772505
--- /dev/null
+++ b/Code/Mantid/Framework/CurveFitting/inc/MantidCurveFitting/FakeMinimizer.h
@@ -0,0 +1,65 @@
+#ifndef MANTID_CURVEFITTING_FAKEMINIMIZER_H_
+#define MANTID_CURVEFITTING_FAKEMINIMIZER_H_
+
+//----------------------------------------------------------------------
+// Includes
+//----------------------------------------------------------------------
+#include "MantidAPI/IFuncMinimizer.h"
+
+namespace Mantid
+{
+namespace CurveFitting
+{
+/** Fake minimizer for testing output workspace properties.
+    Must be deleted before closing ticket #10008.
+
+    Copyright &copy; 2009 ISIS Rutherford Appleton Laboratory & NScD Oak Ridge National Laboratory
+
+    This file is part of Mantid.
+
+    Mantid is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 3 of the License, or
+    (at your option) any later version.
+
+    Mantid is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+    File change history is stored at: <https://github.com/mantidproject/mantid>.
+    Code Documentation is available at: <http://doxygen.mantidproject.org>
+*/
+class DLLExport FakeMinimizer : public API::IFuncMinimizer
+{
+public:
+  /// Constructor setting a value for the relative error acceptance (default=0.01)
+  FakeMinimizer();
+  /// Destructor
+  ~FakeMinimizer();
+
+  /// Overloading base class methods
+  std::string name()const{return "Fake";}
+  /// Do one iteration
+  bool iterate(size_t);
+  /// Return current value of the cost function
+  double costFunctionVal();
+  /// Initialize minimizer, i.e. pass a function to minimize.
+  virtual void initialize(API::ICostFunction_sptr function, size_t maxIterations = 0);
+
+private:
+  size_t m_maxIters;
+  std::vector<double> m_data;
+  int m_someInt;
+  double m_someDouble;
+  std::string m_someString;
+};
+
+
+} // namespace CurveFitting
+} // namespace Mantid
+
+#endif /*MANTID_CURVEFITTING_FAKEMINIMIZER_H_*/
diff --git a/Code/Mantid/Framework/CurveFitting/inc/MantidCurveFitting/Fit.h b/Code/Mantid/Framework/CurveFitting/inc/MantidCurveFitting/Fit.h
index 6d293a8f4bb58c30b96aaf925df225c4f217e8fe..7cafa3622bda5a4dfaa3021d88ec4a6c94a29769 100644
--- a/Code/Mantid/Framework/CurveFitting/inc/MantidCurveFitting/Fit.h
+++ b/Code/Mantid/Framework/CurveFitting/inc/MantidCurveFitting/Fit.h
@@ -17,6 +17,7 @@ namespace Mantid
     class FunctionDomain;
     class FunctionValues;
     class Workspace;
+    class IFuncMinimizer;
   }
 
   namespace CurveFitting
@@ -111,6 +112,7 @@ namespace Mantid
       void addWorkspaces();
       /// Read domain type property and cache the value
       void setDomainType();
+      void copyMinimizerOutput(const API::IFuncMinimizer& minimizer);
 
       /// Pointer to the fitting function
       API::IFunction_sptr m_function;
diff --git a/Code/Mantid/Framework/CurveFitting/inc/MantidCurveFitting/FunctionDomain1DSpectrumCreator.h b/Code/Mantid/Framework/CurveFitting/inc/MantidCurveFitting/FunctionDomain1DSpectrumCreator.h
index 4ef25335ffac116f18cf242a028b31fb2b88a608..f1f0130f36dacdcd65c02721a68c95ba942dc832 100644
--- a/Code/Mantid/Framework/CurveFitting/inc/MantidCurveFitting/FunctionDomain1DSpectrumCreator.h
+++ b/Code/Mantid/Framework/CurveFitting/inc/MantidCurveFitting/FunctionDomain1DSpectrumCreator.h
@@ -42,19 +42,18 @@ namespace CurveFitting
     Code Documentation is available at: <http://doxygen.mantidproject.org>
 
   */
-using namespace API;
 
-class DLLExport FunctionDomain1DSpectrumCreator : public IDomainCreator
+class DLLExport FunctionDomain1DSpectrumCreator : public API::IDomainCreator
 {
 public:
     FunctionDomain1DSpectrumCreator();
     virtual ~FunctionDomain1DSpectrumCreator() { }
 
-    void setMatrixWorkspace(MatrixWorkspace_sptr matrixWorkspace);
+    void setMatrixWorkspace(API::MatrixWorkspace_sptr matrixWorkspace);
     void setWorkspaceIndex(size_t workspaceIndex);
 
-    virtual void createDomain(boost::shared_ptr<FunctionDomain> &domain,
-                         boost::shared_ptr<FunctionValues> &values,
+    virtual void createDomain(boost::shared_ptr<API::FunctionDomain> &domain,
+                         boost::shared_ptr<API::FunctionValues> &values,
                          size_t i0 = 0);
 
     virtual size_t getDomainSize() const;
@@ -65,7 +64,7 @@ protected:
     MantidVec getVectorHistogram() const;
     MantidVec getVectorNonHistogram() const;
 
-    MatrixWorkspace_sptr m_matrixWorkspace;
+    API::MatrixWorkspace_sptr m_matrixWorkspace;
     size_t m_workspaceIndex;
     bool m_workspaceIndexIsSet;
     
diff --git a/Code/Mantid/Framework/CurveFitting/inc/MantidCurveFitting/GramCharlierComptonProfile.h b/Code/Mantid/Framework/CurveFitting/inc/MantidCurveFitting/GramCharlierComptonProfile.h
index ca687eedfc64d06e1bd9e9dd7850ddae30f87812..2aff8dfc0f1e2c82d6dc9b1920fc2d81e62ec65c 100644
--- a/Code/Mantid/Framework/CurveFitting/inc/MantidCurveFitting/GramCharlierComptonProfile.h
+++ b/Code/Mantid/Framework/CurveFitting/inc/MantidCurveFitting/GramCharlierComptonProfile.h
@@ -71,7 +71,7 @@ namespace CurveFitting
     void setMatrixWorkspace(boost::shared_ptr<const API::MatrixWorkspace> workspace,size_t wi,double startX, double endX);
     /// Pre-calculate the Y-space values
     void cacheYSpaceValues(const std::vector<double> & tseconds, const bool isHistogram,
-                           const DetectorParams & detpar,const ResolutionParams & respar);
+                           const DetectorParams & detpar);
 
     /// The active hermite coefficents
     std::vector<short> m_hermite;
diff --git a/Code/Mantid/Framework/CurveFitting/inc/MantidCurveFitting/LevenbergMarquardtMDMinimizer.h b/Code/Mantid/Framework/CurveFitting/inc/MantidCurveFitting/LevenbergMarquardtMDMinimizer.h
index 14caf5e413d152fe28c40f0b321679f32a8f5f19..e0981cea84ee9ea87f641e3505e3b77cb85f315d 100644
--- a/Code/Mantid/Framework/CurveFitting/inc/MantidCurveFitting/LevenbergMarquardtMDMinimizer.h
+++ b/Code/Mantid/Framework/CurveFitting/inc/MantidCurveFitting/LevenbergMarquardtMDMinimizer.h
@@ -50,9 +50,9 @@ public:
   std::string name() const {return "Levenberg-MarquardtMD";}
 
   /// Initialize minimizer, i.e. pass a function to minimize.
-  virtual void initialize(API::ICostFunction_sptr function);
+  virtual void initialize(API::ICostFunction_sptr function, size_t  maxIterations = 0);
   /// Do one iteration.
-  virtual bool iterate();
+  virtual bool iterate(size_t iteration);
   /// Return current value of the cost function
   virtual double costFunctionVal();
 
diff --git a/Code/Mantid/Framework/CurveFitting/inc/MantidCurveFitting/LevenbergMarquardtMinimizer.h b/Code/Mantid/Framework/CurveFitting/inc/MantidCurveFitting/LevenbergMarquardtMinimizer.h
index c08c860b815bd1e1930870faa2fa2e651772bc27..7fbcd493a92a522f51872ec9d004388f9a3d5e86 100644
--- a/Code/Mantid/Framework/CurveFitting/inc/MantidCurveFitting/LevenbergMarquardtMinimizer.h
+++ b/Code/Mantid/Framework/CurveFitting/inc/MantidCurveFitting/LevenbergMarquardtMinimizer.h
@@ -51,9 +51,9 @@ public:
   std::string name() const {return "Levenberg-Marquardt";}
 
   /// Initialize minimizer, i.e. pass a function to minimize.
-  virtual void initialize(API::ICostFunction_sptr function);
+  virtual void initialize(API::ICostFunction_sptr function,size_t maxIterations = 0);
   /// Do one iteration.
-  virtual bool iterate();
+  virtual bool iterate(size_t);
   /// Return current value of the cost function
   virtual double costFunctionVal();
 
diff --git a/Code/Mantid/Framework/CurveFitting/inc/MantidCurveFitting/ProcessBackground.h b/Code/Mantid/Framework/CurveFitting/inc/MantidCurveFitting/ProcessBackground.h
index e263d2c8b07530f8d4740e8cffbcce916c762e24..b5ec291bfc4218b5c873745981e75326f3e6b533 100644
--- a/Code/Mantid/Framework/CurveFitting/inc/MantidCurveFitting/ProcessBackground.h
+++ b/Code/Mantid/Framework/CurveFitting/inc/MantidCurveFitting/ProcessBackground.h
@@ -86,19 +86,17 @@ private:
     /// Execution body
     virtual void exec();
 
-    /// Select background points (main)
-    void execSelectBkgdPoints();
+    /// Set up dummy output optional workspaces
+    void setupDummyOutputWSes();
 
-    /// Select background points (main)
-    void execSelectBkgdPoints2();
+    /// Select b...
+    void selectBkgdPoints();
 
-    /// Parse peak centre and FWHM from a table workspace
-    void parsePeakTableWorkspace(DataObjects::TableWorkspace_sptr peaktablews, std::vector<double>& vec_peakcentre,
-                                 std::vector<double>& vec_peakfwhm);
+    /// Select background points (main)
+    void selectFromGivenXValues();
 
-    /// Exclude peak regions
-    size_t excludePeaks(std::vector<double> v_inX, std::vector<bool>& v_useX, std::vector<double> v_centre,
-                        std::vector<double> v_fwhm);
+    /// Select background points (main)
+    void selectFromGivenFunction();
 
     /// Select background points automatically
     DataObjects::Workspace2D_sptr autoBackgroundSelection(DataObjects::Workspace2D_sptr bkgdWS);
@@ -119,7 +117,7 @@ private:
 
     std::string m_bkgdType;
 
-    bool m_doFitBackground;
+    // bool m_doFitBackground;
 
     // double mTolerance;
 
diff --git a/Code/Mantid/Framework/CurveFitting/inc/MantidCurveFitting/SeqDomainSpectrumCreator.h b/Code/Mantid/Framework/CurveFitting/inc/MantidCurveFitting/SeqDomainSpectrumCreator.h
index 8454aa1f530a146d5180dac747bc7ea3e4a9ce59..b719912e9604c6b3bcb72325dd18210928278cb4 100644
--- a/Code/Mantid/Framework/CurveFitting/inc/MantidCurveFitting/SeqDomainSpectrumCreator.h
+++ b/Code/Mantid/Framework/CurveFitting/inc/MantidCurveFitting/SeqDomainSpectrumCreator.h
@@ -42,9 +42,7 @@ namespace CurveFitting
     Code Documentation is available at: <http://doxygen.mantidproject.org>
   */
 
-using namespace API;
-
-class DLLExport SeqDomainSpectrumCreator : public IDomainCreator
+class DLLExport SeqDomainSpectrumCreator : public API::IDomainCreator
 {
 public:
     SeqDomainSpectrumCreator(Kernel::IPropertyManager* manager,
@@ -52,23 +50,23 @@ public:
 
     virtual ~SeqDomainSpectrumCreator() { }
 
-    virtual void createDomain(boost::shared_ptr<FunctionDomain> &domain,
-                              boost::shared_ptr<FunctionValues> &values,
+    virtual void createDomain(boost::shared_ptr<API::FunctionDomain> &domain,
+                              boost::shared_ptr<API::FunctionValues> &values,
                               size_t i0 = 0);
 
-    virtual Workspace_sptr createOutputWorkspace(const std::string &baseName,
-                                       IFunction_sptr function,
-                                       boost::shared_ptr<FunctionDomain> domain,
-                                       boost::shared_ptr<FunctionValues> values,
+    virtual API::Workspace_sptr createOutputWorkspace(const std::string &baseName,
+                                       API::IFunction_sptr function,
+                                       boost::shared_ptr<API::FunctionDomain> domain,
+                                       boost::shared_ptr<API::FunctionValues> values,
                                        const std::string &outputWorkspacePropertyName = "OutputWorkspace");
     virtual size_t getDomainSize() const;
 
 protected:
     void setParametersFromPropertyManager();
-    void setMatrixWorkspace(MatrixWorkspace_sptr matrixWorkspace);
+    void setMatrixWorkspace(API::MatrixWorkspace_sptr matrixWorkspace);
 
     std::string m_workspacePropertyName;
-    MatrixWorkspace_sptr m_matrixWorkspace;
+    API::MatrixWorkspace_sptr m_matrixWorkspace;
 };
 
 
diff --git a/Code/Mantid/Framework/CurveFitting/inc/MantidCurveFitting/SimplexMinimizer.h b/Code/Mantid/Framework/CurveFitting/inc/MantidCurveFitting/SimplexMinimizer.h
index 0146fe6e213827619a89e6202fb44e9edc866a52..24b008df82c0431608a8b8b7c6e3cfff2ab71bfb 100644
--- a/Code/Mantid/Framework/CurveFitting/inc/MantidCurveFitting/SimplexMinimizer.h
+++ b/Code/Mantid/Framework/CurveFitting/inc/MantidCurveFitting/SimplexMinimizer.h
@@ -49,11 +49,11 @@ public:
   /// Overloading base class methods
   std::string name()const{return "Simplex";}
   /// Do one iteration
-  bool iterate();
+  bool iterate(size_t);
   /// Return current value of the cost function
   double costFunctionVal();
   /// Initialize minimizer, i.e. pass a function to minimize.
-  virtual void initialize(API::ICostFunction_sptr function);
+  virtual void initialize(API::ICostFunction_sptr function, size_t maxIterations = 0);
 
 protected:
 
diff --git a/Code/Mantid/Framework/CurveFitting/inc/MantidCurveFitting/VesuvioResolution.h b/Code/Mantid/Framework/CurveFitting/inc/MantidCurveFitting/VesuvioResolution.h
new file mode 100644
index 0000000000000000000000000000000000000000..f03970f602238b8b5c0353dbbb76c0d96c004b0c
--- /dev/null
+++ b/Code/Mantid/Framework/CurveFitting/inc/MantidCurveFitting/VesuvioResolution.h
@@ -0,0 +1,113 @@
+#ifndef MANTID_CURVEFITTING_VESUVIORESOLUTION_H_
+#define MANTID_CURVEFITTING_VESUVIORESOLUTION_H_
+
+#include "MantidCurveFitting/DllConfig.h"
+#include "MantidAPI/IPeakFunction.h"
+#include "MantidAPI/MatrixWorkspace.h"
+#include "MantidAPI/ParamFunction.h"
+
+namespace Mantid
+{
+namespace CurveFitting
+{
+  //---------------------------------------------------------------------------
+  // Forward declarations
+  //---------------------------------------------------------------------------
+  struct DetectorParams;
+
+  //---------------------------------------------------------------------------
+  /// Simple data structure to store resolution parameter values
+  /// It avoids some functions taking a huge number of arguments
+  struct ResolutionParams
+  {
+    double dl1; ///< spread in source-sample distance
+    double dl2; ///< spread in sample-detector distance
+    double dthe; ///< spread in scattering angle
+    double dEnLorentz; ///< lorentz width in energy
+    double dEnGauss; ///< gaussian width in energy
+  };
+
+  /**
+
+    Calculate the resolution from a workspace of Vesuvio data using the mass & instrument definition.
+
+    Copyright &copy; 2013 ISIS Rutherford Appleton Laboratory & NScD Oak Ridge National Laboratory
+
+    This file is part of Mantid.
+
+    Mantid is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 3 of the License, or
+    (at your option) any later version.
+
+    Mantid is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+    File change history is stored at: <https://github.com/mantidproject/mantid>
+    Code Documentation is available at: <http://doxygen.mantidproject.org>
+  */
+  class MANTID_CURVEFITTING_DLL VesuvioResolution : public virtual API::ParamFunction, public virtual API::IFunction1D
+  {
+  public:
+    /// Default constructor required for factory
+    VesuvioResolution();
+
+    /** @name Function evaluation */
+    ///@{
+    /// A string identifier for this function
+    std::string name() const;
+    /// Access total resolution width
+    inline double resolutionFWHM() const { return m_resolutionSigma; }
+    /// Access lorentz FWHM
+    inline double lorentzFWHM() const { return m_lorentzFWHM; }
+    /// Calculate the function
+    void function1D(double* out, const double* xValues, const size_t nData) const;
+    /// Ensure the object is ready to be fitted
+    void setUpForFit();
+    /// Cache a copy of the workspace pointer and pull out the parameters
+    void setMatrixWorkspace(boost::shared_ptr<const API::MatrixWorkspace> workspace,size_t wi,double startX, double endX);
+    /// Pre-calculate the resolution components values
+    void cacheResolutionComponents(const DetectorParams & detpar,const ResolutionParams & respar);
+    /// Turn off logger
+    void disableLogging() { m_log.setEnabled(false); }
+    /// Compute Voigt function
+    void voigtApprox(std::vector<double> & voigt, const std::vector<double> & yspace, const double lorentzPos,
+                                 const double lorentzAmp, const double lorentzWidth, const double gaussWidth) const;
+    /// Compute Voigt function with cached values
+    void voigtApprox(std::vector<double> & voigt, const std::vector<double> & xValues, const double lorentzPos,
+                                 const double lorentzAmp) const;
+
+    ///@}
+
+  private:
+    /// Declare parameters that will never participate in the fit
+    void declareAttributes();
+    /// Set an attribute value (and possibly cache its value)
+    void setAttribute(const std::string& name,const Attribute& value);
+
+    /// Logger
+    mutable Kernel::Logger m_log;
+    /// Current workspace index, required to access instrument parameters
+    size_t m_wsIndex;
+    /// Store the mass values
+    double m_mass;
+    /// Voigt function
+    boost::shared_ptr<API::IPeakFunction> m_voigt;
+    /// Total resolution width
+    double m_resolutionSigma;
+    /// Lorentz FWHM
+    double m_lorentzFWHM;
+    ///@}
+
+  };
+
+
+} // namespace CurveFitting
+} // namespace Mantid
+
+#endif  /* MANTID_CURVEFITTING_VESUVIORESOLUTION_H_ */
diff --git a/Code/Mantid/Framework/CurveFitting/src/CalculateGammaBackground.cpp b/Code/Mantid/Framework/CurveFitting/src/CalculateGammaBackground.cpp
index aab2583f9caa974de5c7544fe77d0770f9be6523..e3027dc59b8979a892ba14c1d6d7b94d98adefbd 100644
--- a/Code/Mantid/Framework/CurveFitting/src/CalculateGammaBackground.cpp
+++ b/Code/Mantid/Framework/CurveFitting/src/CalculateGammaBackground.cpp
@@ -58,6 +58,7 @@ namespace Mantid
     CalculateGammaBackground::~CalculateGammaBackground()
     {
       delete m_progress;
+      m_indices.clear();
     }
 
     //--------------------------------------------------------------------------------------------------------
diff --git a/Code/Mantid/Framework/CurveFitting/src/ComptonProfile.cpp b/Code/Mantid/Framework/CurveFitting/src/ComptonProfile.cpp
index 4494090769a221ca4535f6649ce979a582bdc773..6d6ed53ef92f259cd70810e24711b777ad044903 100644
--- a/Code/Mantid/Framework/CurveFitting/src/ComptonProfile.cpp
+++ b/Code/Mantid/Framework/CurveFitting/src/ComptonProfile.cpp
@@ -25,9 +25,12 @@ namespace CurveFitting
    */
   ComptonProfile::ComptonProfile() : API::ParamFunction(), API::IFunction1D(),
       m_log("ComptonProfile"),
-      m_wsIndex(0), m_mass(0.0), m_voigt(),
-      m_yspace(), m_modQ(), m_e0(),m_resolutionSigma(0.0), m_lorentzFWHM(0.0)
-  {}
+      m_wsIndex(0), m_mass(0.0), m_voigt(), m_resolutionFunction(),
+      m_yspace(), m_modQ(), m_e0()
+  {
+    using namespace Mantid::API;
+    m_resolutionFunction = boost::dynamic_pointer_cast<VesuvioResolution>(FunctionFactory::Instance().createFunction("VesuvioResolution"));
+  }
 
   //-------------------------------------- Function evaluation -----------------------------------------
 
@@ -52,9 +55,9 @@ namespace CurveFitting
    */
   void ComptonProfile::setUpForFit()
   {
-    // Voigt
     using namespace Mantid::API;
     m_voigt = boost::dynamic_pointer_cast<IPeakFunction>(FunctionFactory::Instance().createFunction("Voigt"));
+    m_resolutionFunction->setUpForFit();
   }
 
   /**
@@ -87,93 +90,34 @@ namespace CurveFitting
       throw std::invalid_argument("ComptonProfile - Workspace has no detector attached to histogram at index " + boost::lexical_cast<std::string>(m_wsIndex));
     }
 
-    DetectorParams detpar = ConvertToYSpace::getDetectorParameters(workspace, m_wsIndex);
-    const auto & pmap = workspace->constInstrumentParameters();
+    m_resolutionFunction->setAttributeValue("Mass", m_mass);
+    m_resolutionFunction->setMatrixWorkspace(workspace, wsIndex, startX, endX);
 
-    ResolutionParams respar;
-    respar.dl1 = ConvertToYSpace::getComponentParameter(det, pmap, "sigma_l1");
-    respar.dl2 = ConvertToYSpace::getComponentParameter(det, pmap, "sigma_l2");
-    respar.dthe = ConvertToYSpace::getComponentParameter(det, pmap, "sigma_theta"); //radians
-    respar.dEnLorentz = ConvertToYSpace::getComponentParameter(det, pmap, "hwhm_lorentz");
-    respar.dEnGauss = ConvertToYSpace::getComponentParameter(det, pmap, "sigma_gauss");
+    DetectorParams detpar = ConvertToYSpace::getDetectorParameters(workspace, m_wsIndex);
+    this->cacheYSpaceValues(workspace->readX(m_wsIndex), workspace->isHistogramData(), detpar);
+  }
 
-    this->cacheYSpaceValues(workspace->readX(m_wsIndex), workspace->isHistogramData(), detpar, respar);
+  void ComptonProfile::cacheYSpaceValues(const std::vector<double> & tseconds, const bool isHistogram,
+                                         const DetectorParams & detpar, const ResolutionParams& respar)
+  {
+    m_resolutionFunction->cacheResolutionComponents(detpar, respar);
+    this->cacheYSpaceValues(tseconds, isHistogram, detpar);
   }
 
   /**
    * @param tseconds A vector containing the time-of-flight values in seconds
    * @param isHistogram True if histogram tof values have been passed in
    * @param detpar Structure containing detector parameters
-   * @param respar Structure containing resolution parameters
    */
   void ComptonProfile::cacheYSpaceValues(const std::vector<double> & tseconds, const bool isHistogram,
-                                         const DetectorParams & detpar, const ResolutionParams & respar)
+                                         const DetectorParams & detpar)
   {
-    // geometry
-    double theta = detpar.theta; //cache for frequent access
-    double hwhmLorentzE = respar.dEnLorentz;
-    double hwhmGaussE = STDDEV_TO_HWHM*respar.dEnGauss;
-
     // ------ Fixed coefficients related to resolution & Y-space transforms ------------------
-    const double mn = PhysicalConstants::NeutronMassAMU;
     const double mevToK = PhysicalConstants::E_mev_toNeutronWavenumberSq;
     const double massToMeV = 0.5*PhysicalConstants::NeutronMass/PhysicalConstants::meV; // Includes factor of 1/2
-
+    
     const double v1 = std::sqrt(detpar.efixed/massToMeV);
     const double k1 = std::sqrt(detpar.efixed/mevToK);
-    const double l2l1 = detpar.l2/detpar.l1;
-
-    // Resolution dependence
-
-    // Find K0/K1 at y=0 by taking the largest root of (M-1)s^2 + 2cos(theta)s - (M+1) = 0
-    // Quadratic if M != 1 but simple linear if it does
-    double k0k1(0.0);
-    if((m_mass-1.0) > DBL_EPSILON)
-    {
-      double x0(0.0),x1(0.0);
-      gsl_poly_solve_quadratic(m_mass-1.0, 2.0*std::cos(theta), -(m_mass+1.0), &x0, &x1);
-      k0k1 = std::max(x0,x1); // K0/K1 at y=0
-    }
-    else
-    {
-      // solution is simply s = 1/cos(theta)
-      k0k1 = 1.0/std::cos(theta);
-    }
-    double qy0(0.0), wgauss(0.0);
-
-    if(m_mass > 1.0)
-    {
-      qy0 = std::sqrt(k1*k1*m_mass*(k0k1*k0k1 - 1));
-      double k0k1p3 = std::pow(k0k1,3);
-      double r1 = -(1.0 + l2l1*k0k1p3);
-      double r2 = 1.0 - l2l1*k0k1p3 + l2l1*std::pow(k0k1,2)*std::cos(theta) - k0k1*std::cos(theta);
-
-      double factor = (0.2413/qy0)*((m_mass/mn)*r1 - r2);
-      m_lorentzFWHM = std::abs(factor*hwhmLorentzE*2);
-      wgauss = std::abs(factor*hwhmGaussE*2);
-    }
-    else
-    {
-      qy0 = k1*std::tan(theta);
-      double factor = (0.2413*2.0/k1)*std::abs((std::cos(theta) + l2l1)/std::sin(theta));
-      m_lorentzFWHM = hwhmLorentzE*factor;
-      wgauss = hwhmGaussE*factor;
-    }
-
-    double k0y0 = k1*k0k1;                     // k0_y0 =  k0 value at y=0
-    double wtheta = 2.0*STDDEV_TO_HWHM*std::abs(k0y0*k1*std::sin(theta)/qy0)*respar.dthe;
-    double common = (m_mass/mn) - 1 + k1*std::cos(theta)/k0y0;
-    double wl1 = 2.0*STDDEV_TO_HWHM*std::abs((std::pow(k0y0,2)/(qy0*detpar.l1))*common)*respar.dl1;
-    double wl2 = 2.0*STDDEV_TO_HWHM*std::abs((std::pow(k0y0,3)/(k1*qy0*detpar.l1))*common)*respar.dl2;
-
-    m_resolutionSigma = std::sqrt(std::pow(wgauss,2) + std::pow(wtheta,2) + std::pow(wl1,2) + std::pow(wl2,2));
-
-    m_log.notice() << "--------------------- Mass=" << m_mass << " -----------------------" << std::endl;
-    m_log.notice() << "w_l1 (FWHM)=" << wl2 << std::endl;
-    m_log.notice() << "w_l0 (FWHM)=" << wl1 << std::endl;
-    m_log.notice() << "w_theta (FWHM)=" << wtheta << std::endl;
-    m_log.notice() << "w_foil_lorentz (FWHM)=" << m_lorentzFWHM << std::endl;
-    m_log.notice() << "w_foil_gauss (FWHM)=" << wgauss << std::endl;
 
     // Calculate energy dependent factors and transform q to Y-space
     const size_t nData = (isHistogram) ? tseconds.size() - 1 : tseconds.size();
@@ -203,7 +147,11 @@ namespace CurveFitting
   void ComptonProfile::setAttribute(const std::string& name,const Attribute& value)
   {
     IFunction::setAttribute(name,value); // Make sure the base-class stores it
-    if(name == MASS_NAME) m_mass = value.asDouble();
+    if(name == MASS_NAME)
+    {
+      m_mass = value.asDouble();
+      m_resolutionFunction->setAttributeValue("Mass", m_mass);
+    }
   }
 
   /**
@@ -233,24 +181,24 @@ namespace CurveFitting
     std::vector<double> ypmEps(yspace.size());
     // y+2eps
     std::transform(yspace.begin(), yspace.end(), ypmEps.begin(), std::bind2nd(std::plus<double>(), 2.0*epsilon)); // Add 2 epsilon
-    voigtApprox(voigtDiff, ypmEps, lorentzPos, lorentzAmp, lorentzWidth, gaussWidth);
+    m_resolutionFunction->voigtApprox(voigtDiff, ypmEps, lorentzPos, lorentzAmp, lorentzWidth, gaussWidth);
     // y-2eps
     std::transform(yspace.begin(), yspace.end(), ypmEps.begin(), std::bind2nd(std::minus<double>(), 2.0*epsilon)); // Subtract 2 epsilon
     std::vector<double> tmpResult(yspace.size());
-    voigtApprox(tmpResult, ypmEps, lorentzPos, lorentzAmp, lorentzWidth, gaussWidth);
+    m_resolutionFunction->voigtApprox(tmpResult, ypmEps, lorentzPos, lorentzAmp, lorentzWidth, gaussWidth);
     // Difference of first two terms - result is put back in voigtDiff
     std::transform(voigtDiff.begin(), voigtDiff.end(), tmpResult.begin(), voigtDiff.begin(), std::minus<double>());
 
     // y+eps
     std::transform(yspace.begin(), yspace.end(), ypmEps.begin(), std::bind2nd(std::plus<double>(), epsilon)); // Add epsilon
-    voigtApprox(tmpResult, ypmEps, lorentzPos, lorentzAmp, lorentzWidth, gaussWidth);
+    m_resolutionFunction->voigtApprox(tmpResult, ypmEps, lorentzPos, lorentzAmp, lorentzWidth, gaussWidth);
     std::transform(tmpResult.begin(), tmpResult.end(), tmpResult.begin(), std::bind2nd(std::multiplies<double>(), 2.0)); // times 2
     // Difference with 3rd term - result is put back in voigtDiff
     std::transform(voigtDiff.begin(), voigtDiff.end(), tmpResult.begin(), voigtDiff.begin(), std::minus<double>());
 
     //y-eps
     std::transform(yspace.begin(), yspace.end(), ypmEps.begin(), std::bind2nd(std::minus<double>(), epsilon)); // Subtract epsilon
-    voigtApprox(tmpResult, ypmEps, lorentzPos, lorentzAmp, lorentzWidth, gaussWidth);
+    m_resolutionFunction->voigtApprox(tmpResult, ypmEps, lorentzPos, lorentzAmp, lorentzWidth, gaussWidth);
     std::transform(tmpResult.begin(), tmpResult.end(), tmpResult.begin(), std::bind2nd(std::multiplies<double>(), 2.0)); // times 2
     // Sum final term
     std::transform(voigtDiff.begin(), voigtDiff.end(), tmpResult.begin(), voigtDiff.begin(), std::plus<double>());
@@ -259,29 +207,5 @@ namespace CurveFitting
     std::transform(voigtDiff.begin(), voigtDiff.end(), voigtDiff.begin(), std::bind2nd(std::divides<double>(), 2.0*std::pow(epsilon,3))); // divided by (2eps^3)
   }
 
-  /**
-   * Transforms the input y coordinates using the Voigt function approximation. The area is normalized to lorentzAmp
-   * @param voigt [Out] Output values (vector is expected to be of the correct size
-   * @param yspace Input y coordinates
-   * @param lorentzPos LorentzPos parameter
-   * @param lorentzAmp LorentzAmp parameter
-   * @param lorentzWidth LorentzFWHM parameter
-   * @param gaussWidth GaussianFWHM parameter
-   */
-  void ComptonProfile::voigtApprox(std::vector<double> & voigt, const std::vector<double> & yspace, const double lorentzPos,
-                                 const double lorentzAmp, const double lorentzWidth, const double gaussWidth) const
-  {
-    m_voigt->setParameter(0,lorentzAmp);
-    m_voigt->setParameter(1,lorentzPos);
-    m_voigt->setParameter(2,lorentzWidth);
-    m_voigt->setParameter(3,gaussWidth);
-    assert(voigt.size() == yspace.size());
-    m_voigt->functionLocal(voigt.data(), yspace.data(), yspace.size());
-
-    // Normalize so that integral of V=lorentzAmp
-    const double norm = 1.0/(0.5*M_PI*lorentzWidth);
-    std::transform(voigt.begin(), voigt.end(), voigt.begin(), std::bind2nd(std::multiplies<double>(), norm));
-  }
-
 } // namespace CurveFitting
 } // namespace Mantid
diff --git a/Code/Mantid/Framework/CurveFitting/src/DampingMinimizer.cpp b/Code/Mantid/Framework/CurveFitting/src/DampingMinimizer.cpp
index 5f3ea2863fb40e983c0f1daf02d5ea2dc1286358..73b38d9f2fa6da43e75bf8a8533dd076dbc9eedd 100644
--- a/Code/Mantid/Framework/CurveFitting/src/DampingMinimizer.cpp
+++ b/Code/Mantid/Framework/CurveFitting/src/DampingMinimizer.cpp
@@ -37,7 +37,7 @@ m_relTol(1e-6)
 }
 
 /// Initialize minimizer, i.e. pass a function to minimize.
-void DampingMinimizer::initialize(API::ICostFunction_sptr function)
+void DampingMinimizer::initialize(API::ICostFunction_sptr function,size_t)
 {
   m_leastSquares = boost::dynamic_pointer_cast<CostFuncLeastSquares>(function);
   if ( !m_leastSquares )
@@ -47,7 +47,7 @@ void DampingMinimizer::initialize(API::ICostFunction_sptr function)
 }
 
 /// Do one iteration.
-bool DampingMinimizer::iterate()
+bool DampingMinimizer::iterate(size_t)
 {
   const bool debug = false;
 
diff --git a/Code/Mantid/Framework/CurveFitting/src/DerivMinimizer.cpp b/Code/Mantid/Framework/CurveFitting/src/DerivMinimizer.cpp
index 754aeb81bf87645931d6e82c58ba5c9a3d810eb0..011d79dccfdf65f1bb7644a36183eaffa278b40a 100644
--- a/Code/Mantid/Framework/CurveFitting/src/DerivMinimizer.cpp
+++ b/Code/Mantid/Framework/CurveFitting/src/DerivMinimizer.cpp
@@ -119,9 +119,11 @@ DerivMinimizer::~DerivMinimizer()
 /**
  * Initialize the minimizer.
  * @param function :: A cost function to minimize.
+ * @param maxIterations :: Maximum number of iterations.
  */
-void DerivMinimizer::initialize(API::ICostFunction_sptr function) 
+void DerivMinimizer::initialize(API::ICostFunction_sptr function, size_t maxIterations)
 {
+  UNUSED_ARG(maxIterations);
   m_costFunction = function;
   m_gslMultiminContainer.n = m_costFunction->nParams();
   m_gslMultiminContainer.f = &fun;
@@ -147,7 +149,7 @@ void DerivMinimizer::initialize(API::ICostFunction_sptr function)
  * Perform one iteration.
  * @return :: true to continue, false to stop.
  */
-bool DerivMinimizer::iterate() 
+bool DerivMinimizer::iterate(size_t)
 {
   if (m_gslSolver == NULL)
   {
diff --git a/Code/Mantid/Framework/CurveFitting/src/FakeMinimizer.cpp b/Code/Mantid/Framework/CurveFitting/src/FakeMinimizer.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..5bc52675633077289b89d798c40d93b9fd33d570
--- /dev/null
+++ b/Code/Mantid/Framework/CurveFitting/src/FakeMinimizer.cpp
@@ -0,0 +1,96 @@
+//----------------------------------------------------------------------
+// Includes
+//----------------------------------------------------------------------
+#include "MantidCurveFitting/FakeMinimizer.h"
+#include "MantidCurveFitting/CostFuncFitting.h"
+
+#include "MantidAPI/FuncMinimizerFactory.h"
+#include "MantidAPI/WorkspaceProperty.h"
+#include "MantidAPI/MatrixWorkspace.h"
+#include "MantidAPI/WorkspaceFactory.h"
+#include "MantidKernel/UnitFactory.h"
+#include "MantidKernel/Unit.h"
+
+#include "MantidKernel/Logger.h"
+
+namespace Mantid
+{
+namespace CurveFitting
+{
+  namespace
+  {
+    /// static logger
+    Kernel::Logger g_log("FakeMinimizer");
+  }
+
+DECLARE_FUNCMINIMIZER(FakeMinimizer,Fake)
+
+
+FakeMinimizer::FakeMinimizer()
+{
+    declareProperty(new API::WorkspaceProperty<API::MatrixWorkspace>("SomeOutput","abc",Kernel::Direction::Output),
+        "Name of the output Workspace holding some output.");
+    declareProperty("SomeInt",0,"Some integer value");
+    declareProperty("SomeDouble",0.0,"Some double value");
+    declareProperty("SomeString","Some units","Some string value");
+}
+
+FakeMinimizer::~FakeMinimizer()
+{
+}
+
+void FakeMinimizer::initialize(API::ICostFunction_sptr, size_t maxIters)
+{
+    m_maxIters = maxIters;
+    m_data.resize(m_maxIters);
+    m_someInt = getProperty("SomeInt");
+    m_someDouble = getProperty("SomeDouble");
+    m_someString = getPropertyValue("SomeString");
+}
+
+/**
+ * Do one iteration.
+ * @param iter :: Current iteration number.
+ * @return :: true if iterations to be continued, false if they can stop
+ */
+bool FakeMinimizer::iterate(size_t iter)
+{
+    m_data[iter] = static_cast<double>(iter) / static_cast<double>(m_maxIters - 1);
+
+    if ( iter >= m_maxIters - 1 )
+    {
+      API::MatrixWorkspace_sptr ws = API::WorkspaceFactory::Instance().create("Workspace2D",1,m_maxIters,m_maxIters);
+      auto & X = ws->dataX(0);
+      for(size_t i = 0; i < X.size(); ++i)
+      {
+          X[i] = static_cast<double>(i + 1);
+      }
+      auto & Y = ws->dataY(0);
+      Y.assign( m_data.begin(), m_data.end() );
+
+      auto &E = ws->dataE(0);
+      if ( m_maxIters > 0 )
+        E[0] = static_cast<double>( m_someInt );
+      if ( m_maxIters > 1 )
+        E[1] = m_someDouble;
+
+      auto ilabel = Kernel::UnitFactory::Instance().create("Label");
+      auto label = boost::dynamic_pointer_cast<Kernel::Units::Label>(ilabel);
+      label->setLabel( m_someString );
+      auto axis = ws->getAxis(0);
+      axis->unit() = ilabel;
+
+      setProperty("SomeOutput",ws);
+      return false;
+    }
+
+    return true;
+}
+
+double FakeMinimizer::costFunctionVal()
+{
+  return 0.0;
+}
+
+} // namespace CurveFitting
+} // namespace Mantid
diff --git a/Code/Mantid/Framework/CurveFitting/src/Fit.cpp b/Code/Mantid/Framework/CurveFitting/src/Fit.cpp
index 3efc28d95dba5ee41566930c3da6c8f2a329f1ad..63d424221d4542f09bed9e8261684ea51556cbd4 100644
--- a/Code/Mantid/Framework/CurveFitting/src/Fit.cpp
+++ b/Code/Mantid/Framework/CurveFitting/src/Fit.cpp
@@ -109,6 +109,23 @@ namespace CurveFitting
     minimizerProperty->replaceValidator( Kernel::IValidator_sptr(new Kernel::StartsWithValidator(minimizerOptions)) );
   }
 
+  /**
+    * Copy all output workspace properties from the minimizer to Fit algorithm.
+    * @param minimizer :: The minimizer to copy from.
+    */
+  void Fit::copyMinimizerOutput(const API::IFuncMinimizer &minimizer)
+  {
+      auto &properties = minimizer.getProperties();
+      for(auto prop = properties.begin(); prop != properties.end(); ++prop)
+      {
+          if ( (**prop).direction() == Kernel::Direction::Output )
+          {
+              Kernel::Property* property = (**prop).clone();
+              declareProperty( property );
+          }
+      }
+  }
+
   void Fit::setFunction()
   {
     // get the function
@@ -393,7 +410,8 @@ namespace CurveFitting
     API::IFuncMinimizer_sptr minimizer = API::FuncMinimizerFactory::Instance().createMinimizer(minimizerName);
 
     // Try to retrieve optional properties
-    const int maxIterations = getProperty("MaxIterations");
+    int intMaxIterations = getProperty("MaxIterations");
+    const size_t maxIterations = static_cast<size_t>( intMaxIterations );
 
     // get the cost function which must be a CostFuncFitting
     boost::shared_ptr<CostFuncFitting> costFunc = boost::dynamic_pointer_cast<CostFuncFitting>(
@@ -401,7 +419,7 @@ namespace CurveFitting
       );
 
     costFunc->setFittingFunction(m_function,domain,values);
-    minimizer->initialize(costFunc);
+    minimizer->initialize(costFunc,maxIterations);
 
     const int64_t nsteps = maxIterations*m_function->estimateNoProgressCalls();
     API::Progress prog(this,0.0,1.0,nsteps);
@@ -412,12 +430,11 @@ namespace CurveFitting
     bool success = false;
     std::string errorString;
     g_log.debug("Starting minimizer iteration\n");
-    while (static_cast<int>(iter) < maxIterations)
+    while ( iter < maxIterations )
     {
-      iter++;
       g_log.debug() << "Starting iteration " << iter << "\n";
       m_function->iterationStarting();
-      if ( !minimizer->iterate() )
+      if ( !minimizer->iterate(iter) )
       {
         errorString = minimizer->getError();
         g_log.debug() << "Iteration stopped. Minimizer status string=" << errorString << "\n";
@@ -435,10 +452,11 @@ namespace CurveFitting
       {
         g_log.debug() << "Iteration " << iter << ", cost function = " << minimizer->costFunctionVal() << "\n";
       }
+      ++iter;
     }
     g_log.debug() << "Number of minimizer iterations=" << iter << "\n";
 
-    if (static_cast<int>(iter) >= maxIterations)
+    if ( iter >= maxIterations)
     {
       if ( !errorString.empty() )
       {
@@ -489,6 +507,8 @@ namespace CurveFitting
 
     if (doCreateOutput)
     {
+      copyMinimizerOutput(*minimizer);
+
       if (baseName.empty())
       {
         baseName = ws->name();
diff --git a/Code/Mantid/Framework/CurveFitting/src/GaussianComptonProfile.cpp b/Code/Mantid/Framework/CurveFitting/src/GaussianComptonProfile.cpp
index a02791a74cd1e3f36b29141354d5ea8acadd48e1..1d80fe9a27ed5eff2216dcec95a9e0ce76108da4 100644
--- a/Code/Mantid/Framework/CurveFitting/src/GaussianComptonProfile.cpp
+++ b/Code/Mantid/Framework/CurveFitting/src/GaussianComptonProfile.cpp
@@ -89,13 +89,13 @@ namespace Mantid
     void GaussianComptonProfile::massProfile(double * result, const size_t nData, const double amplitude) const
     {
       double lorentzPos(0.0), gaussWidth(getParameter(0));
-      double gaussFWHM = std::sqrt(std::pow(resolutionFWHM(),2) + std::pow(2.0*STDDEV_TO_HWHM*gaussWidth,2));
+      double gaussFWHM = std::sqrt(std::pow(m_resolutionFunction->resolutionFWHM(),2) + std::pow(2.0*STDDEV_TO_HWHM*gaussWidth,2));
 
       const auto & yspace = ySpace();
       // Gaussian already folded into Voigt
       std::vector<double> voigt(yspace.size()), voigtDiffResult(yspace.size());
-      voigtApprox(voigt, yspace, lorentzPos, amplitude, lorentzFWHM(), gaussFWHM);
-      voigtApproxDiff(voigtDiffResult, yspace, lorentzPos, amplitude, lorentzFWHM(), gaussFWHM);
+      m_resolutionFunction->voigtApprox(voigt, yspace, lorentzPos, amplitude, m_resolutionFunction->lorentzFWHM(), gaussFWHM);
+      voigtApproxDiff(voigtDiffResult, yspace, lorentzPos, amplitude, m_resolutionFunction->lorentzFWHM(), gaussFWHM);
 
       const auto & modq = modQ();
       const auto & ei = e0();
diff --git a/Code/Mantid/Framework/CurveFitting/src/GramCharlierComptonProfile.cpp b/Code/Mantid/Framework/CurveFitting/src/GramCharlierComptonProfile.cpp
index 1ef4c72dec1db2e26a0fd644e7a7586f4a4ceba8..d1937170ba0fa5d8a362375ae08e8142b8a7ba83 100644
--- a/Code/Mantid/Framework/CurveFitting/src/GramCharlierComptonProfile.cpp
+++ b/Code/Mantid/Framework/CurveFitting/src/GramCharlierComptonProfile.cpp
@@ -352,12 +352,11 @@ namespace Mantid
      * @param tseconds A vector containing the time-of-flight values in seconds
      * @param isHistogram True if histogram tof values have been passed in
      * @param detpar Structure containing detector parameters
-     * @param respar Structure containing resolution parameters
      */
     void GramCharlierComptonProfile::cacheYSpaceValues(const std::vector<double> & tseconds, const bool isHistogram,
-                                                       const DetectorParams & detpar, const ResolutionParams & respar)
+                                                       const DetectorParams & detpar)
     {
-      ComptonProfile::cacheYSpaceValues(tseconds,isHistogram,detpar, respar); // base-class calculations
+      ComptonProfile::cacheYSpaceValues(tseconds,isHistogram,detpar); // base-class calculations
 
       // Is FSE fixed at the moment?
       // The ComptonScatteringCountRate fixes it but we still need to know if the user wanted it fixed
@@ -419,7 +418,7 @@ namespace Mantid
 
         const double yi = yspace[i];
         std::transform(minusYFine.begin(), minusYFine.end(), ym.begin(), std::bind2nd(std::plus<double>(), yi)); //yfine is actually -yfine
-        voigtApprox(voigt,ym,0,1.0,lorentzFWHM(),resolutionFWHM());
+        m_resolutionFunction->voigtApprox(voigt,ym,0,1.0);
       }
 
       m_voigtProfile.resize(NFINE_Y); // Value holder for later to avoid repeated memory allocations when creating a new vector
diff --git a/Code/Mantid/Framework/CurveFitting/src/IkedaCarpenterPV.cpp b/Code/Mantid/Framework/CurveFitting/src/IkedaCarpenterPV.cpp
index 7e20f7ee8669903572a8475fba73748ba352f932..ac730b246345176a2291563f5f841dd91ddccbb4 100644
--- a/Code/Mantid/Framework/CurveFitting/src/IkedaCarpenterPV.cpp
+++ b/Code/Mantid/Framework/CurveFitting/src/IkedaCarpenterPV.cpp
@@ -64,10 +64,12 @@ void IkedaCarpenterPV::setHeight(const double h)
 double IkedaCarpenterPV::height()const 
 {
   // return the function value at centre()
-  double h0;
-  double toCentre = centre();
-  constFunction(&h0, &toCentre, 1);
-  return h0;
+  //using arrays - otherwise coverity warning
+  double h0[1];
+  double toCentre[1];
+  toCentre[0]= centre();
+  constFunction(h0, toCentre, 1);
+  return h0[0];
 };
 
 double IkedaCarpenterPV::fwhm()const
diff --git a/Code/Mantid/Framework/CurveFitting/src/LeBailFit.cpp b/Code/Mantid/Framework/CurveFitting/src/LeBailFit.cpp
index daf084fcf81ecf3b59ec83f13ee728700bb929a0..a8eace0fb8dabd8d4272e249156316eeb28d71e3 100644
--- a/Code/Mantid/Framework/CurveFitting/src/LeBailFit.cpp
+++ b/Code/Mantid/Framework/CurveFitting/src/LeBailFit.cpp
@@ -856,7 +856,7 @@ namespace CurveFitting
     m_dampingFactor = getProperty("Damping");
 
     tempindex = getProperty("NumberMinimizeSteps");
-    if (tempindex >= 0)
+    if (tempindex > 0)
       m_numMinimizeSteps = static_cast<size_t>(tempindex);
     else
     {
@@ -2535,9 +2535,11 @@ namespace CurveFitting
 
     // 2. Set up peak density
     vector<double> peakdensity(vecRawX.size(), 1.0);
-    for (size_t ipk = 0; ipk < m_lebailFunction->getNumberOfPeaks(); ++ipk)
-    {
-      throw runtime_error("Need to figure out how to deal with this part!");
+    throw runtime_error("Need to figure out how to deal with this part!");
+
+  //  for (size_t ipk = 0; ipk < m_lebailFunction->getNumberOfPeaks(); ++ipk)
+  //  {
+
       /* Below are original code for modifying from
       ThermalNeutronBk2BkExpConvPVoigt_sptr thispeak = m_dspPeaks[ipk].second;
       double height = thispeak->height();
@@ -2562,10 +2564,10 @@ namespace CurveFitting
         for (int i = ileft; i <= iright; ++i)
         {
           peakdensity[i] += 1.0;
-        }
-      }
-      */
-    }
+        }*/
+ //     }
+
+    /*}
 
     // FIXME : What is bk_prm2???
     double bk_prm2 = 1.0;
@@ -2585,7 +2587,7 @@ namespace CurveFitting
         background[i] = 0.0;
     }
 
-    return;
+    return;*/
   }
 
   //----------------------------------------------------------------------------------------------
diff --git a/Code/Mantid/Framework/CurveFitting/src/LeBailFunction.cpp b/Code/Mantid/Framework/CurveFitting/src/LeBailFunction.cpp
index a40bdc5c908bc10e2f3447357653316191cf2adb..1aa29d6b92751479168c823576250474ce945a77 100644
--- a/Code/Mantid/Framework/CurveFitting/src/LeBailFunction.cpp
+++ b/Code/Mantid/Framework/CurveFitting/src/LeBailFunction.cpp
@@ -655,8 +655,9 @@ namespace CurveFitting
   void LeBailFunction::setPeakParameters(IPowderDiffPeakFunction_sptr peak, map<string, double > parammap,
                                          double peakheight, bool setpeakheight)
   {
+    UNUSED_ARG(peak); UNUSED_ARG(parammap); UNUSED_ARG(peakheight); UNUSED_ARG(setpeakheight);
     throw runtime_error("Requiring update flag: peak value changed and etc.");
-
+/*
     // FIXME - The best solution for speeding is to have a set of peak parameter listed in the order
     //         of peak function's parameters' indexed.  Then no need to do search anymore.
 
@@ -692,7 +693,7 @@ namespace CurveFitting
     if (setpeakheight)
       peak->setHeight(peakheight);
 
-    return;
+    return;*/
   }
 
   //----------------------------------------------------------------------------------------------
@@ -1047,8 +1048,9 @@ namespace CurveFitting
    */
   void LeBailFunction::setPeakHeights(std::vector<double> inheights)
   {
+    UNUSED_ARG(inheights);
     throw runtime_error("It is not implemented properly.");
-
+/*
     if (inheights.size() != heights.size())
     {
       g_log.error() << "Input number of peaks (height) is not same as peaks. " << std::endl;
@@ -1058,7 +1060,7 @@ namespace CurveFitting
     for (size_t ih = 0; ih < inheights.size(); ++ih)
       heights[ih] = inheights[ih];
 
-    return;
+    return;*/
   }
 
 
diff --git a/Code/Mantid/Framework/CurveFitting/src/LevenbergMarquardtMDMinimizer.cpp b/Code/Mantid/Framework/CurveFitting/src/LevenbergMarquardtMDMinimizer.cpp
index 6e6261b898c46a2e6fd283d9064df27c5d388482..d64f725b75b1bf3bb67664f2b4ddd34dd6021d3f 100644
--- a/Code/Mantid/Framework/CurveFitting/src/LevenbergMarquardtMDMinimizer.cpp
+++ b/Code/Mantid/Framework/CurveFitting/src/LevenbergMarquardtMDMinimizer.cpp
@@ -43,7 +43,7 @@ m_rho(1.0)
 }
 
 /// Initialize minimizer, i.e. pass a function to minimize.
-void LevenbergMarquardtMDMinimizer::initialize(API::ICostFunction_sptr function)
+void LevenbergMarquardtMDMinimizer::initialize(API::ICostFunction_sptr function, size_t)
 {
   m_leastSquares = boost::dynamic_pointer_cast<CostFuncLeastSquares>(function);
   if ( !m_leastSquares )
@@ -56,7 +56,7 @@ void LevenbergMarquardtMDMinimizer::initialize(API::ICostFunction_sptr function)
 }
 
 /// Do one iteration.
-bool LevenbergMarquardtMDMinimizer::iterate()
+bool LevenbergMarquardtMDMinimizer::iterate(size_t)
 {
   const bool debug = getProperty("Debug");
   const double muMax = getProperty("MuMax");
diff --git a/Code/Mantid/Framework/CurveFitting/src/LevenbergMarquardtMinimizer.cpp b/Code/Mantid/Framework/CurveFitting/src/LevenbergMarquardtMinimizer.cpp
index 0e22512a011f0c330a05fdc22a64a6e430083fe6..9f63f9a0b03d17773c4c408a9647b4ce1e4aad1c 100644
--- a/Code/Mantid/Framework/CurveFitting/src/LevenbergMarquardtMinimizer.cpp
+++ b/Code/Mantid/Framework/CurveFitting/src/LevenbergMarquardtMinimizer.cpp
@@ -35,7 +35,7 @@ LevenbergMarquardtMinimizer::LevenbergMarquardtMinimizer()
   declareProperty("RelError", m_relError, "Relative error allowed for parameters - a stopping parameter in success.");
 }
 
-void LevenbergMarquardtMinimizer::initialize(API::ICostFunction_sptr costFunction)
+void LevenbergMarquardtMinimizer::initialize(API::ICostFunction_sptr costFunction, size_t)
 {
   // set-up GSL container to be used with GSL simplex algorithm
   auto leastSquares = boost::dynamic_pointer_cast<CostFuncLeastSquares>(costFunction);
@@ -86,7 +86,7 @@ LevenbergMarquardtMinimizer::~LevenbergMarquardtMinimizer()
   }
 }
 
-bool LevenbergMarquardtMinimizer::iterate() 
+bool LevenbergMarquardtMinimizer::iterate(size_t)
 {
   m_absError = getProperty("AbsError");
   m_relError = getProperty("RelError");
diff --git a/Code/Mantid/Framework/CurveFitting/src/ProcessBackground.cpp b/Code/Mantid/Framework/CurveFitting/src/ProcessBackground.cpp
index fb6969d13c8843ddaee057ef9e06e9964465b15e..59d12fd76e78a4cfbf3bb50b444f62824a4b968a 100644
--- a/Code/Mantid/Framework/CurveFitting/src/ProcessBackground.cpp
+++ b/Code/Mantid/Framework/CurveFitting/src/ProcessBackground.cpp
@@ -150,14 +150,14 @@ DECLARE_ALGORITHM(ProcessBackground)
     // Optional output workspace
     declareProperty(new WorkspaceProperty<Workspace2D>("UserBackgroundWorkspace", "", Direction::Output,
                                                        PropertyMode::Optional),
-                            "Output workspace containing fitted background from points specified by users.");
+                    "Output workspace containing fitted background from points specified by users.");
     setPropertySettings("UserBackgroundWorkspace",
                         new VisibleWhenProperty("Options", IS_EQUAL_TO,  "SelectBackgroundPoints"));
 
     // Optional output workspace
     declareProperty(new WorkspaceProperty<TableWorkspace>("OutputBackgroundParameterWorkspace", "", Direction::Output,
                                                           PropertyMode::Optional),
-                            "Output parameter table workspace containing the background fitting result. ");
+                    "Output parameter table workspace containing the background fitting result. ");
     setPropertySettings("OutputBackgroundParameterWorkspace",
                         new VisibleWhenProperty("Options", IS_EQUAL_TO,  "SelectBackgroundPoints"));
 
@@ -237,38 +237,8 @@ DECLARE_ALGORITHM(ProcessBackground)
     }
     else if (option.compare("SelectBackgroundPoints") == 0)
     {
-      string outbkgdparwsname = getPropertyValue("OutputBackgroundParameterWorkspace");
-      if (outbkgdparwsname.size() > 0)
-      {
-        // Will fit the selected background
-        m_doFitBackground = true;
-      }
-      else
-      {
-        m_doFitBackground = false;
-      }
-
-      string smode = getProperty("SelectionMode");
-      if (smode == "FitGivenDataPoints")
-      {
-        execSelectBkgdPoints();
-      }
-      else if (smode == "UserFunction")
-      {
-        execSelectBkgdPoints2();
-      }
-      else
-      {
-        throw runtime_error("N/A is not supported.");
-      }
-
-      if (m_doFitBackground)
-      {
-        // Fit the selected background
-        string bkgdfunctype = getPropertyValue("OutputBackgroundType");
-        fitBackgroundFunction(bkgdfunctype);
-      }
 
+      selectBkgdPoints();
     }
     else
     {
@@ -283,294 +253,226 @@ DECLARE_ALGORITHM(ProcessBackground)
   }
 
   //----------------------------------------------------------------------------------------------
-  /** Remove peaks within a specified region
-   */
-  void ProcessBackground::removePeaks()
+  /** Set dummy output workspaces to avoid python error for optional workspaces
+    */
+  void ProcessBackground::setupDummyOutputWSes()
   {
-    // Get input
-    TableWorkspace_sptr peaktablews = getProperty("BraggPeakTableWorkspace");
-    if (!peaktablews)
-      throw runtime_error("Option RemovePeaks requires input to BgraggPeaTablekWorkspace.");
-
-    m_numFWHM = getProperty("NumberOfFWHM");
-    if (m_numFWHM <= 0.)
-      throw runtime_error("NumberOfFWHM must be larger than 0. ");
-
-    RemovePeaks remove;
-    remove.setup(peaktablews);
-    m_outputWS = remove.removePeaks(m_dataWS, m_wsIndex, m_numFWHM);
-
-    // Dummy
+    // Dummy outputs to make it work with python script
+    setPropertyValue("UserBackgroundWorkspace", "dummy0");
     Workspace2D_sptr dummyws = boost::dynamic_pointer_cast<Workspace2D>(
           WorkspaceFactory::Instance().create("Workspace2D", 1, 1, 1));
     setProperty("UserBackgroundWorkspace", dummyws);
 
+    setPropertyValue("OutputBackgroundParameterWorkspace", "dummy1");
+    TableWorkspace_sptr dummytbws = boost::make_shared<TableWorkspace>();
+    setProperty("OutputBackgroundParameterWorkspace", dummytbws);
+
     return;
   }
 
-
   //----------------------------------------------------------------------------------------------
-  /** Parse peak centre and FWHM from a table workspace
-    */
-  void ProcessBackground::parsePeakTableWorkspace(TableWorkspace_sptr peaktablews,
-                                                  vector<double>& vec_peakcentre,
-                                                  vector<double>& vec_peakfwhm)
+  /** Delete a certain region from input workspace
+   */
+  void ProcessBackground::deleteRegion()
   {
-    // Get peak table workspace information
-    vector<string> colnames = peaktablews->getColumnNames();
-    int index_centre = -1;
-    int index_fwhm = -1;
-    for (int i = 0; i < static_cast<int>(colnames.size()); ++i)
-    {
-      string colname = colnames[i];
-      if (colname.compare("TOF_h") == 0)
-        index_centre = i;
-      else if (colname.compare("FWHM") == 0)
-        index_fwhm = i;
-    }
-
-    if (index_centre < 0 || index_fwhm < 0)
+    // Check boundary
+    if (m_lowerBound == Mantid::EMPTY_DBL() || m_upperBound == Mantid::EMPTY_DBL())
     {
-      throw runtime_error("Input Bragg peak table workspace does not have TOF_h and/or FWHM");
+      throw std::invalid_argument("Using DeleteRegion.  Both LowerBound and UpperBound must be specified.");
     }
-
-    // Get values
-    size_t numrows = peaktablews->rowCount();
-    vec_peakcentre.resize(numrows, 0.);
-    vec_peakfwhm.resize(numrows, 0.);
-
-    for (size_t i = 0; i < numrows; ++i)
+    if (m_lowerBound >= m_upperBound)
     {
-      double centre = peaktablews->cell<double>(i, index_centre);
-      double fwhm = peaktablews->cell<double>(i, index_fwhm);
-      vec_peakcentre[i] = centre;
-      vec_peakfwhm[i] = fwhm;
+      throw std::invalid_argument("Lower boundary cannot be equal or larger than upper boundary.");
     }
 
-    return;
-  }
+    // Copy original data and exclude region defined by m_lowerBound and m_upperBound
+    const MantidVec& dataX = m_dataWS->readX(0);
+    const MantidVec& dataY = m_dataWS->readY(0);
+    const MantidVec& dataE = m_dataWS->readE(0);
 
-  //----------------------------------------------------------------------------------------------
-  /** Exclude peak regions
-    * @return :: numbkgdpoints
-    */
-  size_t ProcessBackground::excludePeaks(vector<double> v_inX, vector<bool>& v_useX,
-                                         vector<double> v_centre, vector<double> v_fwhm)
-  {
-    // Validate
-    if (v_centre.size() != v_fwhm.size())
-      throw runtime_error("Input different number of peak centres and fwhm.");
-    if (v_inX.size() != v_useX.size())
-      throw runtime_error("Input differetn number of vec X and flag X.");
+    std::vector<double> vx, vy, ve;
 
-    // Flag peak regions
-    size_t numpeaks = v_centre.size();
-    for (size_t i = 0; i < numpeaks; ++i)
+    for (size_t i = 0; i < dataY.size(); ++i)
     {
-      // Define boundary
-      double centre = v_centre[i];
-      double fwhm = v_fwhm[i];
-      double xmin = centre-m_numFWHM*fwhm;
-      double xmax = centre+m_numFWHM*fwhm;
-
-      vector<double>::iterator viter;
-      int i_min, i_max;
-
-      // Locate index in v_inX
-      if (xmin <= v_inX.front())
-        i_min = 0;
-      else if (xmin >= v_inX.back())
-        i_min = static_cast<int>(v_inX.size())-1;
-      else
+      double xtmp = dataX[i];
+      if (xtmp < m_lowerBound || xtmp > m_upperBound)
       {
-        viter = lower_bound(v_inX.begin(), v_inX.end(), xmin);
-        i_min = static_cast<int>(viter-v_inX.begin());
+        vx.push_back(dataX[i]);
+        vy.push_back(dataY[i]);
+        ve.push_back(dataE[i]);
       }
+    }
+    if (dataX.size() > dataY.size())
+    {
+      vx.push_back(dataX.back());
+    }
 
-      if (xmax <= v_inX.front())
-        i_max = 0;
-      else if (xmax >= v_inX.back())
-        i_max = static_cast<int>(v_inX.size())-1;
-      else
-      {
-        viter = lower_bound(v_inX.begin(), v_inX.end(), xmax);
-        i_max = static_cast<int>(viter-v_inX.begin());
-      }
+    // Create new workspace
+    size_t sizex = vx.size();
+    size_t sizey = vy.size();
+    API::MatrixWorkspace_sptr mws = API::WorkspaceFactory::Instance().create("Workspace2D", 1, sizex, sizey);
+    m_outputWS = boost::dynamic_pointer_cast<DataObjects::Workspace2D>(mws);
+    m_outputWS->getAxis(0)->setUnit(m_dataWS->getAxis(0)->unit()->unitID());
 
-      // Flag the excluded region
-      for (int i = i_min; i <= i_max; ++i)
-        v_useX[i] = false;
+    for (size_t i = 0; i < sizey; ++i)
+    {
+      m_outputWS->dataX(0)[i] = vx[i];
+      m_outputWS->dataY(0)[i] = vy[i];
+      m_outputWS->dataE(0)[i] = ve[i];
+    }
+    if (sizex > sizey)
+    {
+      m_outputWS->dataX(0)[sizex-1] = vx.back();
     }
 
-    // Count non-excluded region
-    size_t count = 0;
-    for (size_t i = 0; i < v_useX.size(); ++i)
-      if (v_useX[i])
-        ++ count;
+    // Set up dummies
+    setupDummyOutputWSes();
 
-    return count;
+    return;
   }
 
   //----------------------------------------------------------------------------------------------
-  /** Delete a certain region from input workspace
+  /** Add a certain region from reference workspace
    */
-  void ProcessBackground::deleteRegion()
+  void ProcessBackground::addRegion()
   {
-      // 1. Check boundary
-      if (m_lowerBound == Mantid::EMPTY_DBL() || m_upperBound == Mantid::EMPTY_DBL())
-      {
-          throw std::invalid_argument("Using DeleteRegion.  Both LowerBound and UpperBound must be specified.");
-      }
-      if (m_lowerBound >= m_upperBound)
-      {
-          throw std::invalid_argument("Lower boundary cannot be equal or larger than upper boundary.");
-      }
-
-      // 2. Copy data
-      const MantidVec& dataX = m_dataWS->readX(0);
-      const MantidVec& dataY = m_dataWS->readY(0);
-      const MantidVec& dataE = m_dataWS->readE(0);
+    // Check boundary, which are required
+    if (m_lowerBound == Mantid::EMPTY_DBL() || m_upperBound == Mantid::EMPTY_DBL())
+    {
+      throw std::invalid_argument("Using AddRegion.  Both LowerBound and UpperBound must be specified.");
+    }
+    if (m_lowerBound >= m_upperBound)
+    {
+      throw std::invalid_argument("Lower boundary cannot be equal or larger than upper boundary.");
+    }
 
-      std::vector<double> vx, vy, ve;
+    // Copy data to a set of vectors
+    const MantidVec& vecX = m_dataWS->readX(0);
+    const MantidVec& vecY = m_dataWS->readY(0);
+    const MantidVec& vecE = m_dataWS->readE(0);
 
-      for (size_t i = 0; i < dataY.size(); ++i)
-      {
-          double xtmp = dataX[i];
-          if (xtmp < m_lowerBound || xtmp > m_upperBound)
-          {
-              vx.push_back(dataX[i]);
-              vy.push_back(dataY[i]);
-              ve.push_back(dataE[i]);
-          }
-      }
-      if (dataX.size() > dataY.size())
+    std::vector<double> vx, vy, ve;
+    for (size_t i = 0; i < vecY.size(); ++i)
+    {
+      double xtmp = vecX[i];
+      if (xtmp < m_lowerBound || xtmp > m_upperBound)
       {
-          vx.push_back(dataX.back());
+        vx.push_back(vecX[i]);
+        vy.push_back(vecY[i]);
+        ve.push_back(vecE[i]);
       }
+    }
 
-      // 4. Create new workspace
-      size_t sizex = vx.size();
-      size_t sizey = vy.size();
-      API::MatrixWorkspace_sptr mws = API::WorkspaceFactory::Instance().create("Workspace2D", 1, sizex, sizey);
-      m_outputWS = boost::dynamic_pointer_cast<DataObjects::Workspace2D>(mws);
+    // Histogram
+    if (vecX.size() > vecY.size()) vx.push_back(vecX.back());
 
-      for (size_t i = 0; i < sizey; ++i)
-      {
-          m_outputWS->dataX(0)[i] = vx[i];
-          m_outputWS->dataY(0)[i] = vy[i];
-          m_outputWS->dataE(0)[i] = ve[i];
-      }
-      if (sizex > sizey)
-      {
-          m_outputWS->dataX(0)[sizex-1] = vx.back();
-      }
+    // Get access to reference workspace
+    DataObjects::Workspace2D_const_sptr refWS = getProperty("ReferenceWorkspace");
+    if (!refWS) throw std::invalid_argument("ReferenceWorkspace is not given. ");
 
-      return;
-  }
+    const MantidVec& refX = refWS->dataX(0);
+    const MantidVec& refY = refWS->dataY(0);
+    const MantidVec& refE = refWS->dataE(0);
 
-  /*
-   * Add a certain region from reference workspace
-   */
-  void ProcessBackground::addRegion()
-  {
-      // 1. Check boundary
-      if (m_lowerBound == Mantid::EMPTY_DBL() || m_upperBound == Mantid::EMPTY_DBL())
-      {
-          throw std::invalid_argument("Using AddRegion.  Both LowerBound and UpperBound must be specified.");
-      }
-      if (m_lowerBound >= m_upperBound)
-      {
-          throw std::invalid_argument("Lower boundary cannot be equal or larger than upper boundary.");
-      }
+    // 4. Insert the value of the reference workspace from lowerBoundary to upperBoundary
+    std::vector<double>::const_iterator refiter;
+    refiter = std::lower_bound(refX.begin(), refX.end(), m_lowerBound);
+    size_t sindex = size_t(refiter-refX.begin());
+    refiter = std::lower_bound(refX.begin(), refX.end(), m_upperBound);
+    size_t eindex = size_t(refiter-refX.begin());
 
-      // 2. Copy data
-      const MantidVec& dataX = m_dataWS->readX(0);
-      const MantidVec& dataY = m_dataWS->readY(0);
-      const MantidVec& dataE = m_dataWS->readE(0);
+    for (size_t i = sindex; i < eindex; ++i)
+    {
+      double tmpx = refX[i];
+      double tmpy = refY[i];
+      double tmpe = refE[i];
 
-      std::vector<double> vx, vy, ve;
-      for (size_t i = 0; i < dataY.size(); ++i)
-      {
-          double xtmp = dataX[i];
-          if (xtmp < m_lowerBound || xtmp > m_upperBound)
-          {
-              vx.push_back(dataX[i]);
-              vy.push_back(dataY[i]);
-              ve.push_back(dataE[i]);
-          }
-      }
-      if (dataX.size() > dataY.size())
-      {
-          vx.push_back(dataX.back());
-      }
+      // Locate the position of tmpx in the array to be inserted
+      std::vector<double>::iterator newit = std::lower_bound(vx.begin(), vx.end(), tmpx);
+      size_t newindex = size_t(newit-vx.begin());
 
-      // 3. Reference workspace
-      DataObjects::Workspace2D_const_sptr refWS = getProperty("ReferenceWorkspace");
-      if (!refWS)
-      {
-          throw std::invalid_argument("ReferenceWorkspace is not given. ");
-      }
+      // insert tmpx, tmpy, tmpe by iterator
+      vx.insert(newit, tmpx);
 
-      const MantidVec& refX = refWS->dataX(0);
-      const MantidVec& refY = refWS->dataY(0);
-      const MantidVec& refE = refWS->dataE(0);
+      newit = vy.begin()+newindex;
+      vy.insert(newit, tmpy);
 
-      // 4. Insert
-      std::vector<double>::const_iterator refiter;
-      refiter = std::lower_bound(refX.begin(), refX.end(), m_lowerBound);
-      size_t sindex = size_t(refiter-refX.begin());
-      refiter = std::lower_bound(refX.begin(), refX.end(), m_upperBound);
-      size_t eindex = size_t(refiter-refX.begin());
+      newit = ve.begin()+newindex;
+      ve.insert(newit, tmpe);
+    }
 
-      for (size_t i = sindex; i < eindex; ++i)
+    // Check
+    for (size_t i = 1; i < vx.size(); ++i)
+    {
+      if (vx[i] <= vx[i-1])
       {
-          double tmpx = refX[i];
-          double tmpy = refY[i];
-          double tmpe = refE[i];
+        g_log.error() << "The vector X with value inserted is not ordered incrementally" << std::endl;
+        throw std::runtime_error("Build new vector error!");
+      }
+    }
 
-          // Locate the position of tmpx in the array to be inserted
-          std::vector<double>::iterator newit = std::lower_bound(vx.begin(), vx.end(), tmpx);
-          size_t newindex = size_t(newit-vx.begin());
+    // Construct the new Workspace
+    m_outputWS = boost::dynamic_pointer_cast<DataObjects::Workspace2D>
+        (API::WorkspaceFactory::Instance().create("Workspace2D", 1, vx.size(), vy.size()));
+    m_outputWS->getAxis(0)->setUnit(m_dataWS->getAxis(0)->unit()->unitID());
+    for (size_t i = 0; i < vy.size(); ++i)
+    {
+      m_outputWS->dataX(0)[i] = vx[i];
+      m_outputWS->dataY(0)[i] = vy[i];
+      m_outputWS->dataE(0)[i] = ve[i];
+    }
+    if (vx.size() > vy.size())
+      m_outputWS->dataX(0)[vx.size()-1] = vx.back();
 
-          // insert tmpx, tmpy, tmpe by iterator
-          vx.insert(newit, tmpx);
+    // Write out dummy output workspaces
+    setupDummyOutputWSes();
 
-          newit = vy.begin()+newindex;
-          vy.insert(newit, tmpy);
+    return;
+  }
 
-          newit = ve.begin()+newindex;
-          ve.insert(newit, tmpe);
-      }
+  //----------------------------------------------------------------------------------------------
+  // Methods for selecting background points
+  //----------------------------------------------------------------------------------------------
 
-      // Check
-      for (size_t i = 1; i < vx.size(); ++i)
-      {
-          if (vx[i] <= vx[i-1])
-          {
-              g_log.error() << "The vector X with value inserted is not ordered incrementally" << std::endl;
-              throw std::runtime_error("Build new vector error!");
-          }
-      }
+  //----------------------------------------------------------------------------------------------
+  /** Main method to select background points
+    */
+  void ProcessBackground::selectBkgdPoints()
+  {
+    // Select background points
+    string smode = getProperty("SelectionMode");
+    if (smode == "FitGivenDataPoints")
+    {
+      selectFromGivenXValues();
+    }
+    else if (smode == "UserFunction")
+    {
+      selectFromGivenFunction();
+    }
+    else
+    {
+      throw runtime_error("N/A is not supported.");
+    }
 
-      // 5. Construct the new Workspace
-      m_outputWS = boost::dynamic_pointer_cast<DataObjects::Workspace2D>
-              (API::WorkspaceFactory::Instance().create("Workspace2D", 1, vx.size(), vy.size()));
-      for (size_t i = 0; i < vy.size(); ++i)
-      {
-          m_outputWS->dataX(0)[i] = vx[i];
-          m_outputWS->dataY(0)[i] = vy[i];
-          m_outputWS->dataE(0)[i] = ve[i];
-      }
-      if (vx.size() > vy.size())
-          m_outputWS->dataX(0)[vx.size()-1] = vx.back();
+    // Fit the background points
+    string outbkgdparwsname = getPropertyValue("OutputBackgroundParameterWorkspace");
+    if (outbkgdparwsname.size() > 0)
+    {
+      // Will fit the selected background
+      string bkgdfunctype = getPropertyValue("OutputBackgroundType");
+      fitBackgroundFunction(bkgdfunctype);
+    }
+
+    m_outputWS->getAxis(0)->setUnit(m_dataWS->getAxis(0)->unit()->unitID());
 
-      return;
+    return;
   }
 
+
   //----------------------------------------------------------------------------------------------
   /** Select background points
     */
-  void ProcessBackground::execSelectBkgdPoints()
+  void ProcessBackground::selectFromGivenXValues()
   {
     // Get special input properties
     std::vector<double> bkgdpoints = getProperty("BackgroundPoints");
@@ -649,7 +551,7 @@ DECLARE_ALGORITHM(ProcessBackground)
   //----------------------------------------------------------------------------------------------
   /** Select background points via a given background function
     */
-  void ProcessBackground::execSelectBkgdPoints2()
+  void ProcessBackground::selectFromGivenFunction()
   {
     // Process properties
     BackgroundFunction_sptr bkgdfunc = createBackgroundFunction(m_bkgdType);
@@ -693,10 +595,16 @@ DECLARE_ALGORITHM(ProcessBackground)
     BackgroundFunction_sptr bkgdfunction = createBackgroundFunction(m_bkgdType);
 
     int bkgdorder = getProperty("BackgroundOrder");
+    if (bkgdorder == 0)
+      g_log.warning("(Input) background function order is 0.  It might not be able to give a good estimation.");
+
     bkgdfunction->setAttributeValue("n", bkgdorder);
+    bkgdfunction->initialize();
 
-    g_log.debug() << "DBx622 Background Workspace has " << bkgdWS->readX(0).size()
-                  << " data points." << std::endl;
+    g_log.information() << "Input background points has " << bkgdWS->readX(0).size()
+                        << " data points for fit " << bkgdorder << "-th order " << bkgdfunction->name()
+                        << " (background) function" << bkgdfunction->asString()
+                        << "\n";
 
     // Fit input (a few) background pionts to get initial guess
     API::IAlgorithm_sptr fit;
@@ -740,19 +648,6 @@ DECLARE_ALGORITHM(ProcessBackground)
     g_log.information() << "Fit background: Fit Status = " << fitStatus << ", chi2 = "
                         << chi2 << "\n";
 
-    // c) get out the parameter names
-    API::IFunction_sptr func = fit->getProperty("Function");
-    /* Comment out as not being used
-    std::vector<std::string> parnames = func->getParameterNames();
-    std::map<std::string, double> parvalues;
-    for (size_t iname = 0; iname < parnames.size(); ++iname)
-    {
-      double value = func->getParameter(parnames[iname]);
-      parvalues.insert(std::make_pair(parnames[iname], value));
-    }
-    DataObject::Workspace2D_const_sptr theorybackground = AnalysisDataService::Instance().retrieve(wsname);
-    */
-
     // Filter and construct for the output workspace
     Workspace2D_sptr outws = filterForBackground(bkgdfunction);
 
@@ -802,9 +697,7 @@ DECLARE_ALGORITHM(ProcessBackground)
     double posnoisetolerance = getProperty("NoiseTolerance");
     double negnoisetolerance = getProperty("NegativeNoiseTolerance");
     if (isEmpty(negnoisetolerance))
-    {
       negnoisetolerance = posnoisetolerance;
-    }
 
     // Calcualte theoretical values
     const std::vector<double> x = m_dataWS->readX(m_wsIndex);
@@ -812,43 +705,45 @@ DECLARE_ALGORITHM(ProcessBackground)
     API::FunctionValues values(domain);
     bkgdfunction->function(domain, values);
 
-    g_log.information() << "Background function : " << bkgdfunction->asString() << "\n";
+    g_log.information() << "Function used to select background points : " << bkgdfunction->asString() << "\n";
 
     // Optional output
     string userbkgdwsname = getPropertyValue("UserBackgroundWorkspace");
-    if (userbkgdwsname.size() != 0)
+    if (userbkgdwsname.size() == 0)
+      throw runtime_error("In mode SelectBackgroundPoints, UserBackgroundWorkspace must be given!");
+
+    size_t sizex = domain.size();
+    size_t sizey = values.size();
+    MatrixWorkspace_sptr visualws = boost::dynamic_pointer_cast<MatrixWorkspace>(
+          WorkspaceFactory::Instance().create("Workspace2D", 4, sizex, sizey));
+    for (size_t i = 0; i < sizex; ++i)
     {
-      size_t sizex = domain.size();
-      size_t sizey = values.size();
-      MatrixWorkspace_sptr outws = boost::dynamic_pointer_cast<MatrixWorkspace>(
-            WorkspaceFactory::Instance().create("Workspace2D", 4, sizex, sizey));
-      for (size_t i = 0; i < sizex; ++i)
+      for (size_t j = 0; j < 4; ++j)
       {
-        for (size_t j = 0; j < 4; ++j)
-        {
-          outws->dataX(j)[i] = domain[i];
-        }
+        visualws->dataX(j)[i] = domain[i];
       }
-      for (size_t i = 0; i < sizey; ++i)
-      {
-        outws->dataY(0)[i] = values[i];
-        outws->dataY(1)[i] = m_dataWS->readY(m_wsIndex)[i] - values[i];
-        outws->dataY(2)[i] = posnoisetolerance;
-        outws->dataY(3)[i] = -negnoisetolerance;
-      }
-      setProperty("UserBackgroundWorkspace", outws);
     }
+    for (size_t i = 0; i < sizey; ++i)
+    {
+      visualws->dataY(0)[i] = values[i];
+      visualws->dataY(1)[i] = m_dataWS->readY(m_wsIndex)[i] - values[i];
+      visualws->dataY(2)[i] = posnoisetolerance;
+      visualws->dataY(3)[i] = -negnoisetolerance;
+    }
+    setProperty("UserBackgroundWorkspace", visualws);
 
     // Filter for background
     std::vector<double> vecx, vecy, vece;
     for (size_t i = 0; i < domain.size(); ++i)
     {
-      double y = m_dataWS->readY(m_wsIndex)[i];
-      double theoryy = values[i];
-      if (y-theoryy < posnoisetolerance && y-theoryy > -negnoisetolerance)
+      // double y = m_dataWS->readY(m_wsIndex)[i];
+      // double theoryy = values[i]; y-theoryy
+      double purey = visualws->readY(1)[i];
+      if (purey < posnoisetolerance &&  purey > -negnoisetolerance)
       {
         // Selected
         double x = domain[i];
+        double y = m_dataWS->readY(m_wsIndex)[i];
         double e = m_dataWS->readE(m_wsIndex)[i];
         vecx.push_back(x);
         vecy.push_back(y);
@@ -859,16 +754,10 @@ DECLARE_ALGORITHM(ProcessBackground)
                         << m_dataWS->readX(m_wsIndex).size()
                         << " total data points. " << "\n";
 
-    // Build new workspace
-    size_t nspec;
-    if (m_doFitBackground)
-      nspec = 3;
-    else
-      nspec = 1;
-
+    // Build new workspace for OutputWorkspace
+    size_t nspec = 3;
     Workspace2D_sptr outws = boost::dynamic_pointer_cast<DataObjects::Workspace2D>
         (API::WorkspaceFactory::Instance().create("Workspace2D", nspec, vecx.size(), vecy.size()));
-
     for (size_t i = 0; i < vecx.size(); ++i)
     {
       for(size_t j = 0; j < nspec; ++j)
@@ -880,6 +769,143 @@ DECLARE_ALGORITHM(ProcessBackground)
     return outws;
   }
 
+  //----------------------------------------------------------------------------------------------
+  /** Fit background function
+    */
+  void ProcessBackground::fitBackgroundFunction(std::string bkgdfunctiontype)
+  {
+    // Get background type and create bakground function
+    BackgroundFunction_sptr bkgdfunction = createBackgroundFunction(bkgdfunctiontype);
+
+    int bkgdorder = getProperty("OutputBackgroundOrder");
+    bkgdfunction->setAttributeValue("n", bkgdorder);
+
+    if (bkgdfunctiontype == "Chebyshev")
+    {
+      double xmin = m_outputWS->readX(0).front();
+      double xmax = m_outputWS->readX(0).back();
+      g_log.information() << "Chebyshev Fit range: " << xmin << ", " << xmax << "\n";
+      bkgdfunction->setAttributeValue("StartX", xmin);
+      bkgdfunction->setAttributeValue("EndX", xmax);
+    }
+
+    g_log.information() << "Fit selected background " << bkgdfunctiontype
+                        << " to data workspace with " << m_outputWS->getNumberHistograms() << " spectra."
+                        << "\n";
+
+    // Fit input (a few) background pionts to get initial guess
+    API::IAlgorithm_sptr fit;
+    try
+    {
+      fit = this->createChildAlgorithm("Fit", 0.9, 1.0, true);
+    }
+    catch (Exception::NotFoundError &)
+    {
+      g_log.error() << "Requires CurveFitting library." << std::endl;
+      throw;
+    }
+
+    g_log.information() << "Fitting background function: " << bkgdfunction->asString() << "\n";
+
+    double startx = m_lowerBound;
+    double endx = m_upperBound;
+    fit->setProperty("Function", boost::dynamic_pointer_cast<API::IFunction>(bkgdfunction));
+    fit->setProperty("InputWorkspace", m_outputWS);
+    fit->setProperty("WorkspaceIndex", 0);
+    fit->setProperty("MaxIterations", 500);
+    fit->setProperty("StartX", startx);
+    fit->setProperty("EndX", endx);
+    fit->setProperty("Minimizer", "Levenberg-MarquardtMD");
+    fit->setProperty("CostFunction", "Least squares");
+
+    fit->executeAsChildAlg();
+
+    // Get fit status and chi^2
+    std::string fitStatus = fit->getProperty("OutputStatus");
+    bool allowedfailure = (fitStatus.find("cannot") < fitStatus.size()) &&
+        (fitStatus.find("tolerance") < fitStatus.size());
+    if (fitStatus.compare("success") != 0 && !allowedfailure)
+    {
+      g_log.error() << "ProcessBackground: Fit Status = " << fitStatus
+                    << ".  Not to update fit result" << std::endl;
+      throw std::runtime_error("Bad Fit");
+    }
+
+    const double chi2 = fit->getProperty("OutputChi2overDoF");
+    g_log.information() << "Fit background: Fit Status = " << fitStatus << ", chi2 = "
+                        << chi2 << "\n";
+
+    // Get out the parameter names
+    API::IFunction_sptr funcout = fit->getProperty("Function");
+    TableWorkspace_sptr outbkgdparws = boost::make_shared<TableWorkspace>();
+    outbkgdparws->addColumn("str", "Name");
+    outbkgdparws->addColumn("double", "Value");
+
+    TableRow typerow = outbkgdparws->appendRow();
+    typerow << bkgdfunctiontype << 0.;
+
+    vector<string> parnames = funcout->getParameterNames();
+    size_t nparam = funcout->nParams();
+    for (size_t i = 0; i < nparam; ++i)
+    {
+      TableRow newrow = outbkgdparws->appendRow();
+      newrow << parnames[i] << funcout->getParameter(i);
+    }
+
+    TableRow chi2row = outbkgdparws->appendRow();
+    chi2row << "Chi-square" << chi2;
+
+    g_log.information() << "Set table workspace (#row = " << outbkgdparws->rowCount()
+                        << ") to OutputBackgroundParameterTable. " << "\n";
+    setProperty("OutputBackgroundParameterWorkspace", outbkgdparws);
+
+    // Set output workspace
+    const MantidVec& vecX = m_outputWS->readX(0);
+    const MantidVec& vecY = m_outputWS->readY(0);
+    FunctionDomain1DVector domain(vecX);
+    FunctionValues values(domain);
+
+    funcout->function(domain, values);
+
+    MantidVec& dataModel = m_outputWS->dataY(1);
+    MantidVec& dataDiff = m_outputWS->dataY(2);
+    for (size_t i = 0; i < dataModel.size(); ++i)
+    {
+      dataModel[i] = values[i];
+      dataDiff[i] = vecY[i] - dataModel[i];
+    }
+
+    return;
+  }
+
+  //----------------------------------------------------------------------------------------------
+  // Remove peaks
+  //----------------------------------------------------------------------------------------------
+
+  //----------------------------------------------------------------------------------------------
+  /** Remove peaks within a specified region
+   */
+  void ProcessBackground::removePeaks()
+  {
+    // Get input
+    TableWorkspace_sptr peaktablews = getProperty("BraggPeakTableWorkspace");
+    if (!peaktablews)
+      throw runtime_error("Option RemovePeaks requires input to BgraggPeaTablekWorkspace.");
+
+    m_numFWHM = getProperty("NumberOfFWHM");
+    if (m_numFWHM <= 0.)
+      throw runtime_error("NumberOfFWHM must be larger than 0. ");
+
+    // Remove peaks
+    RemovePeaks remove;
+    remove.setup(peaktablews);
+    m_outputWS = remove.removePeaks(m_dataWS, m_wsIndex, m_numFWHM);
+
+    // Dummy outputs
+    setupDummyOutputWSes();
+
+    return;
+  }
 
   //----------------------------------------------------------------------------------------------
   /** Constructor
@@ -941,6 +967,7 @@ DECLARE_ALGORITHM(ProcessBackground)
     // Construct output workspace
     Workspace2D_sptr outws = boost::dynamic_pointer_cast<Workspace2D>(
           WorkspaceFactory::Instance().create("Workspace2D", 1, numbkgdpoints, numbkgdpointsy));
+    outws->getAxis(0)->setUnit(dataws->getAxis(0)->unit()->unitID());
     MantidVec& outX = outws->dataX(0);
     MantidVec& outY = outws->dataY(0);
     MantidVec& outE = outws->dataE(0);
@@ -1069,115 +1096,6 @@ DECLARE_ALGORITHM(ProcessBackground)
     return count;
   }
 
-  //----------------------------------------------------------------------------------------------
-  /** Fit background function
-    */
-  void ProcessBackground::fitBackgroundFunction(std::string bkgdfunctiontype)
-  {
-    // Get background type and create bakground function
-    BackgroundFunction_sptr bkgdfunction = createBackgroundFunction(bkgdfunctiontype);
-
-    int bkgdorder = getProperty("OutputBackgroundOrder");
-    bkgdfunction->setAttributeValue("n", bkgdorder);
-
-    if (bkgdfunctiontype == "Chebyshev")
-    {
-      double xmin = m_outputWS->readX(0).front();
-      double xmax = m_outputWS->readX(0).back();
-      g_log.information() << "Chebyshev Fit range: " << xmin << ", " << xmax << "\n";
-      bkgdfunction->setAttributeValue("StartX", xmin);
-      bkgdfunction->setAttributeValue("EndX", xmax);
-    }
-
-    g_log.information() << "Fit selected background " << bkgdfunctiontype
-                        << " to data workspace with " << m_outputWS->getNumberHistograms() << " spectra."
-                        << "\n";
-
-    // Fit input (a few) background pionts to get initial guess
-    API::IAlgorithm_sptr fit;
-    try
-    {
-      fit = this->createChildAlgorithm("Fit", 0.9, 1.0, true);
-    }
-    catch (Exception::NotFoundError &)
-    {
-      g_log.error() << "Requires CurveFitting library." << std::endl;
-      throw;
-    }
-
-    g_log.information() << "Fitting background function: " << bkgdfunction->asString() << "\n";
-
-    double startx = m_lowerBound;
-    double endx = m_upperBound;
-    fit->setProperty("Function", boost::dynamic_pointer_cast<API::IFunction>(bkgdfunction));
-    fit->setProperty("InputWorkspace", m_outputWS);
-    fit->setProperty("WorkspaceIndex", 0);
-    fit->setProperty("MaxIterations", 500);
-    fit->setProperty("StartX", startx);
-    fit->setProperty("EndX", endx);
-    fit->setProperty("Minimizer", "Levenberg-MarquardtMD");
-    fit->setProperty("CostFunction", "Least squares");
-
-    fit->executeAsChildAlg();
-
-    // Get fit status and chi^2
-    std::string fitStatus = fit->getProperty("OutputStatus");
-    bool allowedfailure = (fitStatus.find("cannot") < fitStatus.size()) &&
-        (fitStatus.find("tolerance") < fitStatus.size());
-    if (fitStatus.compare("success") != 0 && !allowedfailure)
-    {
-      g_log.error() << "ProcessBackground: Fit Status = " << fitStatus
-                    << ".  Not to update fit result" << std::endl;
-      throw std::runtime_error("Bad Fit");
-    }
-
-    const double chi2 = fit->getProperty("OutputChi2overDoF");
-    g_log.information() << "Fit background: Fit Status = " << fitStatus << ", chi2 = "
-                        << chi2 << "\n";
-
-    // Get out the parameter names
-    API::IFunction_sptr funcout = fit->getProperty("Function");
-    TableWorkspace_sptr outbkgdparws = boost::make_shared<TableWorkspace>();
-    outbkgdparws->addColumn("str", "Name");
-    outbkgdparws->addColumn("double", "Value");
-
-    TableRow typerow = outbkgdparws->appendRow();
-    typerow << bkgdfunctiontype << 0.;
-
-    vector<string> parnames = funcout->getParameterNames();
-    size_t nparam = funcout->nParams();
-    for (size_t i = 0; i < nparam; ++i)
-    {
-      TableRow newrow = outbkgdparws->appendRow();
-      newrow << parnames[i] << funcout->getParameter(i);
-    }
-
-    TableRow chi2row = outbkgdparws->appendRow();
-    chi2row << "Chi-square" << chi2;
-
-    g_log.information() << "Set table workspace (#row = " << outbkgdparws->rowCount()
-                        << ") to OutputBackgroundParameterTable. " << "\n";
-    setProperty("OutputBackgroundParameterWorkspace", outbkgdparws);
-
-    // Set output workspace
-    const MantidVec& vecX = m_outputWS->readX(0);
-    const MantidVec& vecY = m_outputWS->readY(0);
-    FunctionDomain1DVector domain(vecX);
-    FunctionValues values(domain);
-
-    funcout->function(domain, values);
-
-    MantidVec& dataModel = m_outputWS->dataY(1);
-    MantidVec& dataDiff = m_outputWS->dataY(2);
-    for (size_t i = 0; i < dataModel.size(); ++i)
-    {
-      dataModel[i] = values[i];
-      dataDiff[i] = vecY[i] - dataModel[i];
-    }
-
-    return;
-  }
-
 
 } // namespace CurveFitting
 } // namespace Mantid
diff --git a/Code/Mantid/Framework/CurveFitting/src/SimplexMinimizer.cpp b/Code/Mantid/Framework/CurveFitting/src/SimplexMinimizer.cpp
index a021788054bf8208ae8412cc3456891271f76d4f..377d3527c9a9cb51ca779e86db4136760ce57b3e 100644
--- a/Code/Mantid/Framework/CurveFitting/src/SimplexMinimizer.cpp
+++ b/Code/Mantid/Framework/CurveFitting/src/SimplexMinimizer.cpp
@@ -57,7 +57,7 @@ m_gslSolver(NULL)
 {
 }
 
-void SimplexMinimizer::initialize(API::ICostFunction_sptr function) 
+void SimplexMinimizer::initialize(API::ICostFunction_sptr function, size_t)
 {
   m_costFunction = function;
 
@@ -90,7 +90,7 @@ void SimplexMinimizer::initialize(API::ICostFunction_sptr function)
  * Do one iteration.
  * @return :: true if iterations to be continued, false if they can stop
  */
-bool SimplexMinimizer::iterate() 
+bool SimplexMinimizer::iterate(size_t)
 {
   int status = gsl_multimin_fminimizer_iterate(m_gslSolver);
   if (status)
diff --git a/Code/Mantid/Framework/CurveFitting/src/VesuvioResolution.cpp b/Code/Mantid/Framework/CurveFitting/src/VesuvioResolution.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..c0adfc1b6a560949ac48e89b3c5f1c2fff540e91
--- /dev/null
+++ b/Code/Mantid/Framework/CurveFitting/src/VesuvioResolution.cpp
@@ -0,0 +1,232 @@
+//-----------------------------------------------------------------------------
+// Includes
+//-----------------------------------------------------------------------------
+#include "MantidCurveFitting/VesuvioResolution.h"
+#include "MantidCurveFitting/ConvertToYSpace.h"
+#include "MantidAPI/FunctionFactory.h"
+#include <gsl/gsl_poly.h>
+
+namespace Mantid
+{
+namespace CurveFitting
+{
+  namespace
+  {
+    ///@cond
+    const char * MASS_NAME = "Mass";
+
+    const double STDDEV_TO_HWHM = std::sqrt(std::log(4.0));
+    ///@endcond
+  }
+
+  // Register into factory
+  DECLARE_FUNCTION(VesuvioResolution);
+
+  /**
+   */
+  VesuvioResolution::VesuvioResolution() : API::ParamFunction(), API::IFunction1D(),
+      m_log("VesuvioResolution"),
+      m_wsIndex(0), m_mass(0.0), m_voigt(),
+      m_resolutionSigma(0.0), m_lorentzFWHM(0.0)
+  {}
+
+  /**
+   * @returns A string containing the name of the function
+   */
+  std::string VesuvioResolution::name() const
+  {
+    return "VesuvioResolution";
+  }
+
+
+  //-------------------------------------- Function evaluation -----------------------------------------
+
+  /*
+   * Creates the internal caches
+   */
+  void VesuvioResolution::setUpForFit()
+  {
+    // Voigt
+    using namespace Mantid::API;
+    m_voigt = boost::dynamic_pointer_cast<IPeakFunction>(FunctionFactory::Instance().createFunction("Voigt"));
+  }
+
+  /**
+   * Also caches parameters from the instrument
+   * @param workspace The workspace set as input
+   * @param wsIndex A workspace index
+   * @param startX Starting x-vaue (unused).
+   * @param endX Ending x-vaue (unused).
+   */
+  void VesuvioResolution::setMatrixWorkspace(boost::shared_ptr<const API::MatrixWorkspace> workspace,size_t wsIndex,double startX, double endX)
+  {
+    UNUSED_ARG(startX);
+    UNUSED_ARG(endX);
+
+    auto inst = workspace->getInstrument();
+    auto sample = inst->getSample();
+    auto source = inst->getSource();
+    if(!sample || !source)
+    {
+      throw std::invalid_argument("VesuvioResolution - Workspace has no source/sample.");
+    }
+    m_wsIndex = wsIndex;
+    Geometry::IDetector_const_sptr det;
+    try
+    {
+     det = workspace->getDetector(m_wsIndex);
+    }
+    catch (Kernel::Exception::NotFoundError &)
+    {
+      throw std::invalid_argument("VesuvioResolution - Workspace has no detector attached to histogram at index " + boost::lexical_cast<std::string>(m_wsIndex));
+    }
+
+    DetectorParams detpar = ConvertToYSpace::getDetectorParameters(workspace, m_wsIndex);
+    const auto & pmap = workspace->constInstrumentParameters();
+
+    ResolutionParams respar;
+    respar.dl1 = ConvertToYSpace::getComponentParameter(det, pmap, "sigma_l1");
+    respar.dl2 = ConvertToYSpace::getComponentParameter(det, pmap, "sigma_l2");
+    respar.dthe = ConvertToYSpace::getComponentParameter(det, pmap, "sigma_theta"); //radians
+    respar.dEnLorentz = ConvertToYSpace::getComponentParameter(det, pmap, "hwhm_lorentz");
+    respar.dEnGauss = ConvertToYSpace::getComponentParameter(det, pmap, "sigma_gauss");
+
+    this->cacheResolutionComponents(detpar, respar);
+  }
+
+  /**
+   * @param detpar Structure containing detector parameters
+   * @param respar Structure containing resolution parameters
+   */
+  void VesuvioResolution::cacheResolutionComponents(const DetectorParams & detpar, const ResolutionParams & respar)
+  {
+    // geometry
+    double theta = detpar.theta; //cache for frequent access
+    double hwhmLorentzE = respar.dEnLorentz;
+    double hwhmGaussE = STDDEV_TO_HWHM*respar.dEnGauss;
+
+    // ------ Fixed coefficients related to resolution & Y-space transforms ------------------
+    const double mn = PhysicalConstants::NeutronMassAMU;
+    const double mevToK = PhysicalConstants::E_mev_toNeutronWavenumberSq;
+
+    const double k1 = std::sqrt(detpar.efixed/mevToK);
+    const double l2l1 = detpar.l2/detpar.l1;
+
+    // Resolution dependence
+
+    // Find K0/K1 at y=0 by taking the largest root of (M-1)s^2 + 2cos(theta)s - (M+1) = 0
+    // Quadratic if M != 1 but simple linear if it does
+    double k0k1(0.0);
+    if((m_mass-1.0) > DBL_EPSILON)
+    {
+      double x0(0.0),x1(0.0);
+      gsl_poly_solve_quadratic(m_mass-1.0, 2.0*std::cos(theta), -(m_mass+1.0), &x0, &x1);
+      k0k1 = std::max(x0,x1); // K0/K1 at y=0
+    }
+    else
+    {
+      // solution is simply s = 1/cos(theta)
+      k0k1 = 1.0/std::cos(theta);
+    }
+    double qy0(0.0), wgauss(0.0);
+
+    if(m_mass > 1.0)
+    {
+      qy0 = std::sqrt(k1*k1*m_mass*(k0k1*k0k1 - 1));
+      double k0k1p3 = std::pow(k0k1,3);
+      double r1 = -(1.0 + l2l1*k0k1p3);
+      double r2 = 1.0 - l2l1*k0k1p3 + l2l1*std::pow(k0k1,2)*std::cos(theta) - k0k1*std::cos(theta);
+
+      double factor = (0.2413/qy0)*((m_mass/mn)*r1 - r2);
+      m_lorentzFWHM = std::abs(factor*hwhmLorentzE*2);
+      wgauss = std::abs(factor*hwhmGaussE*2);
+    }
+    else
+    {
+      qy0 = k1*std::tan(theta);
+      double factor = (0.2413*2.0/k1)*std::abs((std::cos(theta) + l2l1)/std::sin(theta));
+      m_lorentzFWHM = hwhmLorentzE*factor;
+      wgauss = hwhmGaussE*factor;
+    }
+
+    double k0y0 = k1*k0k1;                     // k0_y0 =  k0 value at y=0
+    double wtheta = 2.0*STDDEV_TO_HWHM*std::abs(k0y0*k1*std::sin(theta)/qy0)*respar.dthe;
+    double common = (m_mass/mn) - 1 + k1*std::cos(theta)/k0y0;
+    double wl1 = 2.0*STDDEV_TO_HWHM*std::abs((std::pow(k0y0,2)/(qy0*detpar.l1))*common)*respar.dl1;
+    double wl2 = 2.0*STDDEV_TO_HWHM*std::abs((std::pow(k0y0,3)/(k1*qy0*detpar.l1))*common)*respar.dl2;
+
+    m_resolutionSigma = std::sqrt(std::pow(wgauss,2) + std::pow(wtheta,2) + std::pow(wl1,2) + std::pow(wl2,2));
+    
+    m_log.notice() << "--------------------- Mass=" << m_mass << " -----------------------" << std::endl;
+    m_log.notice() << "w_l1 (FWHM)=" << wl2 << std::endl;
+    m_log.notice() << "w_l0 (FWHM)=" << wl1 << std::endl;
+    m_log.notice() << "w_theta (FWHM)=" << wtheta << std::endl;
+    m_log.notice() << "w_foil_lorentz (FWHM)=" << m_lorentzFWHM << std::endl;
+    m_log.notice() << "w_foil_gauss (FWHM)=" << wgauss << std::endl;
+
+  }
+
+  void VesuvioResolution::function1D(double* out, const double* xValues, const size_t nData) const
+  {
+    std::vector<double> outVec(static_cast<int>(nData),0);
+    const std::vector<double> xValuesVec(xValues, xValues + nData);
+    voigtApprox(outVec, xValuesVec, 0, 1, m_lorentzFWHM, m_resolutionSigma);
+    std::copy(outVec.begin(), outVec.end(), out);
+  }
+
+  /**
+   */
+  void VesuvioResolution::declareAttributes()
+  {
+    declareAttribute(MASS_NAME, IFunction::Attribute(m_mass));
+  }
+
+  /**
+   * @param name The name of the attribute
+   * @param value The attribute's value
+   */
+  void VesuvioResolution::setAttribute(const std::string& name,const Attribute& value)
+  {
+    IFunction::setAttribute(name,value); // Make sure the base-class stores it
+    if(name == MASS_NAME) m_mass = value.asDouble();
+  }
+
+  /**
+   * Convenience wrapper for voigtApprox. This version uses the cached values of the widths
+   * @param voigt [Out] Output values (vector is expected to be of the correct size
+   * @param xValues Input coordinates
+   * @param lorentzPos LorentzPos parameter
+   * @param lorentzAmp LorentzAmp parameter
+   */
+  void VesuvioResolution::voigtApprox(std::vector<double> & voigt, const std::vector<double> & xValues, const double lorentzPos,
+                                 const double lorentzAmp) const
+  {
+    voigtApprox(voigt, xValues, lorentzPos, lorentzAmp, m_lorentzFWHM, m_resolutionSigma);
+  }
+  
+  /**
+   * Transforms the input y coordinates using the Voigt function approximation. The area is normalized to lorentzAmp
+   * @param voigt [Out] Output values (vector is expected to be of the correct size
+   * @param xValues Input coordinates
+   * @param lorentzPos LorentzPos parameter
+   * @param lorentzAmp LorentzAmp parameter
+   * @param lorentzWidth LorentzFWHM parameter
+   * @param gaussWidth GaussianFWHM parameter
+   */
+  void VesuvioResolution::voigtApprox(std::vector<double> & voigt, const std::vector<double> & xValues, const double lorentzPos,
+                                 const double lorentzAmp, const double lorentzWidth, const double gaussWidth) const
+  {
+    m_voigt->setParameter(0,lorentzAmp);
+    m_voigt->setParameter(1,lorentzPos);
+    m_voigt->setParameter(2,lorentzWidth);
+    m_voigt->setParameter(3,gaussWidth);
+    assert(voigt.size() == xValues.size());
+    m_voigt->functionLocal(voigt.data(), xValues.data(), xValues.size());
+
+    // Normalize so that integral of V=lorentzAmp
+    const double norm = 1.0/(0.5*M_PI*lorentzWidth);
+    std::transform(voigt.begin(), voigt.end(), voigt.begin(), std::bind2nd(std::multiplies<double>(), norm));
+  }
+
+} // namespace CurveFitting
+} // namespace Mantid
diff --git a/Code/Mantid/Framework/CurveFitting/test/FitTest.h b/Code/Mantid/Framework/CurveFitting/test/FitTest.h
new file mode 100644
index 0000000000000000000000000000000000000000..bb395cbee3c01076cee4629ffc234ff7b38bff74
--- /dev/null
+++ b/Code/Mantid/Framework/CurveFitting/test/FitTest.h
@@ -0,0 +1,136 @@
+#ifndef CURVEFITTING_FITTEST_H_
+#define CURVEFITTING_FITTEST_H_
+
+#include <cxxtest/TestSuite.h>
+#include "MantidTestHelpers/FakeObjects.h"
+
+#include "MantidCurveFitting/Fit.h"
+
+#include "MantidAPI/FrameworkManager.h"
+#include "MantidAPI/WorkspaceProperty.h"
+#include "MantidAPI/AnalysisDataService.h"
+#include "MantidAPI/IFuncMinimizer.h"
+#include "MantidAPI/FuncMinimizerFactory.h"
+
+using namespace Mantid;
+using namespace Mantid::CurveFitting;
+using namespace Mantid::API;
+
+namespace
+{
+    class TestMinimizer : public API::IFuncMinimizer
+    {
+    public:
+      /// Constructor setting a value for the relative error acceptance (default=0.01)
+      TestMinimizer()
+      {
+          declareProperty(new API::WorkspaceProperty<API::MatrixWorkspace>("SomeOutput","abc",Kernel::Direction::Output),
+              "Name of the output Workspace holding some output.");
+      }
+
+      /// Overloading base class methods.
+      std::string name()const{return "TestMinimizer";}
+      /// Do one iteration.
+      bool iterate(size_t iter)
+      {
+          m_data[iter] = iter;
+
+          if ( iter >= m_data.size() - 1 )
+          {
+              API::MatrixWorkspace_sptr ws = API::WorkspaceFactory::Instance().create("Workspace2D",1,m_data.size(),m_data.size());
+              auto & Y = ws->dataY(0);
+              for(size_t i = 0; i < Y.size(); ++i)
+              {
+                Y[i] = static_cast<double>(m_data[i]);
+              }
+              setProperty("SomeOutput",ws);
+              return false;
+          }
+          return true;
+      }
+
+      /// Return current value of the cost function
+      double costFunctionVal() {return 0.0;}
+      /// Initialize minimizer.
+      virtual void initialize(API::ICostFunction_sptr, size_t maxIterations = 0)
+      {
+            m_data.resize(maxIterations);
+      }
+
+    private:
+      std::vector<size_t> m_data;
+    };
+
+    DECLARE_FUNCMINIMIZER(TestMinimizer,TestMinimizer)
+}
+
+class FitTest : public CxxTest::TestSuite
+{
+public:
+  // This pair of boilerplate methods prevent the suite being created statically
+  // This means the constructor isn't called when running other tests
+  static FitTest *createSuite() { return new FitTest(); }
+  static void destroySuite( FitTest *suite ) { delete suite; }
+  
+  FitTest()
+  {
+    // need to have DataObjects loaded
+    FrameworkManager::Instance();
+  }
+
+
+  // Test that Fit copies minimizer's output properties to Fit
+  // Test that minimizer's iterate(iter) method is called maxIteration times
+  //  and iter passed to iterate() has values within 0 <= iter < maxIterations
+  void test_minimizer_output()
+  {
+      API::MatrixWorkspace_sptr ws = API::WorkspaceFactory::Instance().create("Workspace2D",1,1,1);
+      Fit fit;
+      fit.initialize();
+
+      fit.setProperty("Function","name=LinearBackground");
+      fit.setProperty("InputWorkspace",ws);
+      fit.setProperty("MaxIterations",99);
+      fit.setProperty("Minimizer","TestMinimizer,SomeOutput=MinimizerOutput");
+      fit.setProperty("CreateOutput",true);
+
+      fit.execute();
+      TS_ASSERT( fit.existsProperty("SomeOutput") );
+      TS_ASSERT_EQUALS( fit.getPropertyValue("SomeOutput"), "MinimizerOutput");
+      TS_ASSERT( API::AnalysisDataService::Instance().doesExist("MinimizerOutput") );
+
+      API::MatrixWorkspace_sptr outWS = API::AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>("MinimizerOutput");
+      TS_ASSERT( outWS );
+      auto &y = outWS->readY(0);
+      TS_ASSERT_EQUALS( y.size(), 99 );
+      for(size_t iter = 0; iter < 99; ++iter)
+      {
+          TS_ASSERT_EQUALS( y[iter], static_cast<double>(iter) );
+      }
+
+      API::AnalysisDataService::Instance().clear();
+  }
+
+  // Test that minimizer's output is'n passed to Fit if no other output is created.
+  // Other output are: fitting parameters table, calculated values.
+  // To create output either CreateOutput must be set to true or Output be set to non-empty string
+  void test_minimizer_output_not_passed_to_Fit()
+  {
+      API::MatrixWorkspace_sptr ws = API::WorkspaceFactory::Instance().create("Workspace2D",1,1,1);
+      Fit fit;
+      fit.initialize();
+
+      fit.setProperty("Function","name=LinearBackground");
+      fit.setProperty("InputWorkspace",ws);
+      fit.setProperty("MaxIterations",99);
+      fit.setProperty("Minimizer","TestMinimizer,SomeOutput=MinimizerOutput");
+
+      fit.execute();
+      TS_ASSERT( !fit.existsProperty("SomeOutput") );
+      TS_ASSERT( !API::AnalysisDataService::Instance().doesExist("MinimizerOutput") );
+
+  }
+
+};
+
+#endif /*CURVEFITTING_FITMWTEST_H_*/
diff --git a/Code/Mantid/Framework/CurveFitting/test/ProcessBackgroundTest.h b/Code/Mantid/Framework/CurveFitting/test/ProcessBackgroundTest.h
index 94b58c3fd4b298127938b948b842243b5c6c11f1..7784a2d974524adcf2d4425810839155fdef739c 100644
--- a/Code/Mantid/Framework/CurveFitting/test/ProcessBackgroundTest.h
+++ b/Code/Mantid/Framework/CurveFitting/test/ProcessBackgroundTest.h
@@ -272,6 +272,7 @@ public:
     alg.setProperty("BackgroundTableWorkspace", functablews);
 
     alg.setProperty("OutputBackgroundParameterWorkspace", "OutBackgroundParameters");
+    alg.setProperty("UserBackgroundWorkspace", "VisualWS");
     alg.setProperty("OutputBackgroundType", "Chebyshev");
     alg.setProperty("OutputBackgroundOrder", 6);
 
diff --git a/Code/Mantid/Framework/CurveFitting/test/VesuvioResolutionTest.h b/Code/Mantid/Framework/CurveFitting/test/VesuvioResolutionTest.h
new file mode 100644
index 0000000000000000000000000000000000000000..99eb32e481cf056dbe926b4e2ae87cccba8e889e
--- /dev/null
+++ b/Code/Mantid/Framework/CurveFitting/test/VesuvioResolutionTest.h
@@ -0,0 +1,87 @@
+#ifndef MANTID_CURVEFITTING_VESUVIORESOLUTIONTEST_H_
+#define MANTID_CURVEFITTING_VESUVIORESOLUTIONTEST_H_
+
+#include <cxxtest/TestSuite.h>
+#include "MantidCurveFitting/VesuvioResolution.h"
+
+#include "ComptonProfileTestHelpers.h"
+
+using Mantid::CurveFitting::VesuvioResolution;
+
+class VesuvioResolutionTest : public CxxTest::TestSuite
+{
+public:
+  // This pair of boilerplate methods prevent the suite being created statically
+  // This means the constructor isn't called when running other tests
+  static VesuvioResolutionTest *createSuite() { return new VesuvioResolutionTest(); }
+  static void destroySuite( VesuvioResolutionTest *suite ) { delete suite; }
+
+  void test_Name_Is_As_Expected()
+  {
+    // These are used in scripts so should not change!
+    Mantid::API::IFunction_sptr func = createFunction();
+    TS_ASSERT_EQUALS("VesuvioResolution", func->name());
+  }
+
+  void test_initialized_object_has_expected_attributes()
+  {
+    Mantid::API::IFunction_sptr func = createFunction();
+    checkDefaultAttrsExist(*func);
+  }
+
+  void test_Expected_Results_Returned_Given_Data()
+  {
+    using namespace Mantid::API;
+
+     auto func = createFunction();
+     double x0(165.0),x1(166.0),dx(0.5); //chosen to give put us near the peak for this mass & spectrum
+     auto testWS = ComptonProfileTestHelpers::createTestWorkspace(1,x0,x1,dx);
+     auto & dataX = testWS->dataX(0);
+     std::transform(dataX.begin(), dataX.end(), dataX.begin(), std::bind2nd(std::multiplies<double>(),1e-06)); // to seconds
+     func->setMatrixWorkspace(testWS,0,dataX.front(),dataX.back());
+     FunctionDomain1DView domain(dataX.data(), dataX.size());
+     FunctionValues values(domain);
+
+     TS_ASSERT_THROWS_NOTHING(func->function(domain, values));
+
+     const double tol(1e-6);
+     TS_ASSERT_DELTA(0.279933, values.getCalculated(0), tol);
+     TS_ASSERT_DELTA(0.279933, values.getCalculated(1), tol);
+     TS_ASSERT_DELTA(0.279933, values.getCalculated(2), tol);
+  }
+
+private:
+
+  boost::shared_ptr<VesuvioResolution> createFunction()
+  {
+    auto func = boost::make_shared<VesuvioResolution>();
+    func->initialize();
+    func->setAttributeValue("Mass",1.0);
+    func->setUpForFit();
+    return func;
+  }
+
+  void checkDefaultAttrsExist(const Mantid::API::IFunction & func)
+  {
+    static const size_t nattrs = 1;
+    TS_ASSERT_LESS_THAN_EQUALS(nattrs, func.nAttributes()); //at least nattrs
+
+    // Test names as they are used in scripts
+    if(nattrs <= func.nAttributes())
+    {
+      const char * attrAarr[nattrs] = {"Mass"};
+      std::set<std::string> expectedAttrs(attrAarr, attrAarr + nattrs);
+      std::vector<std::string> actualNames = func.getAttributeNames();
+
+      for(size_t i = 0; i < nattrs; ++i)
+      {
+        const std::string & name = actualNames[i];
+        size_t keyCount = expectedAttrs.count(name);
+        TSM_ASSERT_EQUALS("Attribute" + name + " was found but not expected.", 1, keyCount);
+      }
+    }
+  }
+};
+
+
+#endif /* MANTID_CURVEFITTING_VESUVIORESOLUTIONTEST_H_ */
diff --git a/Code/Mantid/Framework/DataHandling/CMakeLists.txt b/Code/Mantid/Framework/DataHandling/CMakeLists.txt
index 6f6036c59aef5941eb8fde5d890af0c8c6910cd7..8edcfd12003d6ad5646db3a4dda02e2fdd38bd8a 100644
--- a/Code/Mantid/Framework/DataHandling/CMakeLists.txt
+++ b/Code/Mantid/Framework/DataHandling/CMakeLists.txt
@@ -126,6 +126,7 @@ set ( SRC_FILES
 	src/SaveNXSPE.cpp
 	src/SaveNexus.cpp
 	src/SaveNexusProcessed.cpp
+	src/SaveParameterFile.cpp
 	src/SavePAR.cpp
 	src/SavePHX.cpp
 	src/SaveRKH.cpp
@@ -261,6 +262,7 @@ set ( INC_FILES
 	inc/MantidDataHandling/SaveNXSPE.h
 	inc/MantidDataHandling/SaveNexus.h
 	inc/MantidDataHandling/SaveNexusProcessed.h
+	inc/MantidDataHandling/SaveParameterFile.h
 	inc/MantidDataHandling/SavePAR.h
 	inc/MantidDataHandling/SavePHX.h
 	inc/MantidDataHandling/SaveRKH.h
@@ -384,6 +386,7 @@ set ( TEST_FILES
 	SaveDspacemapTest.h
 	SaveFocussedXYETest.h
 	SaveFullprofResolutionTest.h
+	SaveGSSTest.h
 	SaveILLCosmosAsciiTest.h
 	SaveIsawDetCalTest.h
 	SaveMaskTest.h
@@ -391,6 +394,7 @@ set ( TEST_FILES
 	SaveNXSPETest.h
 	SaveNexusProcessedTest.h
 	SaveNexusTest.h
+	SaveParameterFileTest.h
 	SavePARTest.h
 	SavePHXTest.h
 	SaveRKHTest.h
diff --git a/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/LoadGSS.h b/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/LoadGSS.h
index 571b63ad479968033ac999761b34c6bb2bf269fb..99b797b95d3d3c510ff69ad755d7c6c4b580853a 100644
--- a/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/LoadGSS.h
+++ b/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/LoadGSS.h
@@ -41,15 +41,20 @@ class DLLExport LoadGSS : public  API::IFileLoader<Kernel::FileDescriptor>
 public:
   /// (Empty) Constructor
   LoadGSS() {}
+
   /// Virtual destructor
+
   virtual ~LoadGSS() {}
+
   /// Algorithm's name
   virtual const std::string name() const { return "LoadGSS"; }
-    ///Summary of algorithms purpose
-    virtual const std::string summary() const {return "Loads a GSS file such as that saved by SaveGSS. This is not a lossless process, as SaveGSS truncates some data. There is no instrument assosciated with the resulting workspace.  'Please Note': Due to limitations of the GSS file format, the process of going from Mantid to a GSS file and back is not perfect.";}
+
+  /// Summary of algorithms purpose
+  virtual const std::string summary() const {return "Loads a GSS file such as that saved by SaveGSS. This is not a lossless process, as SaveGSS truncates some data. There is no instrument assosciated with the resulting workspace.  'Please Note': Due to limitations of the GSS file format, the process of going from Mantid to a GSS file and back is not perfect.";}
 
   /// Algorithm's version
   virtual int version() const { return (1); }
+
   /// Algorithm's category for identification
   virtual const std::string category() const { return "Diffraction;DataHandling\\Text"; }
 
@@ -57,18 +62,25 @@ public:
   virtual int confidence(Kernel::FileDescriptor & descriptor) const;
 
 private:
-  
   /// Initialisation code
   void init();
-  ///Execution code
+
+  /// Execution code
   void exec();
-  // Convert a string (value+unit) to double (value)
+
+  /// Main method to load GSAS
+  API::MatrixWorkspace_sptr loadGSASFile(const std::string& filename, bool useBankAsSpectrum);
+
+  /// Convert a string (value+unit) to double (value)
   double convertToDouble(std::string inputstring);
-  // Create an instrument geometry.
-  void createInstrumentGeometry(API::MatrixWorkspace_sptr workspace, std::string instrumentname, double primaryflightpath,
-      std::vector<int> detectorids, std::vector<double> totalflightpaths, std::vector<double> twothetas);
+
+  /// Create an instrument geometry.
+  void createInstrumentGeometry(API::MatrixWorkspace_sptr workspace, const std::string& instrumentname,
+                                const double& primaryflightpath, const std::vector<int>& detectorids,
+                                const std::vector<double>& totalflightpaths, const std::vector<double>& twothetas);
 
 };
+
 }
 }
 #endif //DATAHANDING_LOADGSS_H_
diff --git a/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/LoadILL.h b/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/LoadILL.h
index 9a4c1596c0f89744fe86a786004bfa367d8838f7..a9cd9e06a90ea3e41944d6f1d6960df23a816e44 100644
--- a/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/LoadILL.h
+++ b/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/LoadILL.h
@@ -8,124 +8,124 @@
 #include "MantidNexus/NexusClasses.h"
 #include "MantidDataHandling/LoadHelper.h"
 
-namespace Mantid {
-namespace DataHandling {
-/**
- Loads an ILL nexus file into a Mantid workspace.
-
- Required properties:
- <UL>
- <LI> Filename - The ILL nexus file to be read </LI>
- <LI> Workspace - The name to give to the output workspace </LI>
- </UL>
-
- Copyright &copy; 2010 ISIS Rutherford Appleton Laboratory & NScD Oak Ridge National Laboratory
-
- This file is part of Mantid.
-
- Mantid is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- Mantid is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program.  If not, see <http://www.gnu.org/licenses/>.
-
- File change history is stored at: <https://github.com/mantidproject/mantid>
- Code Documentation is available at: <http://doxygen.mantidproject.org>
- */
-class DLLExport LoadILL: public API::IFileLoader<Kernel::NexusDescriptor> {
-public:
-  /// Constructor
-  LoadILL();	/// Virtual destructor
-  virtual ~LoadILL() {
-  }
-  /// Algorithm's name
-  virtual const std::string name() const {
-    return "LoadILL";
-  }
-  ///Summary of algorithms purpose
-  virtual const std::string summary() const {
-    return "Loads a ILL nexus file.";
-  }
-
-  /// Algorithm's version
-  virtual int version() const {
-    return (1);
-  }
-  /// Algorithm's category for identification
-  virtual const std::string category() const {
-    return "DataHandling";
-  }
-
-  /// Returns a confidence value that this algorithm can load a file
-  int confidence(Kernel::NexusDescriptor & descriptor) const;
-
-private:
-  // Initialisation code
-  void init();
-  // Execution code
-  void exec();
-
-  int getEPPFromVanadium(const std::string &,
-      Mantid::API::MatrixWorkspace_sptr);
-  void loadInstrumentDetails(NeXus::NXEntry&);
-  std::vector<std::vector<int> > getMonitorInfo(NeXus::NXEntry& firstEntry);
-  void initWorkSpace(NeXus::NXEntry& entry,
-      const std::vector<std::vector<int> >&);
-  void initInstrumentSpecific();
-  void addAllNexusFieldsAsProperties(std::string filename);
-  void addEnergyToRun();
-
-  void loadExperimentDetails(NeXus::NXEntry & entry);
-  int getDetectorElasticPeakPosition(const NeXus::NXInt &data);
-  void loadTimeDetails(NeXus::NXEntry& entry);
-  NeXus::NXData loadNexusFileData(NeXus::NXEntry& entry);
-  void loadDataIntoTheWorkSpace(NeXus::NXEntry& entry,
-      const std::vector<std::vector<int> >&,
-      int vanaCalculatedDetectorElasticPeakPosition = -1);
-
-  void runLoadInstrument();
-
-  /// Calculate error for y
-  static double calculateError(double in) {
-    return sqrt(in);
-  }
-  int validateVanadium(const std::string &);
-
-  API::MatrixWorkspace_sptr m_localWorkspace;
+namespace Mantid
+{
+  namespace DataHandling
+  {
+    /**
+     Loads an ILL nexus file into a Mantid workspace.
+
+     Copyright &copy; 2010 ISIS Rutherford Appleton Laboratory & NScD Oak Ridge National Laboratory
+
+     This file is part of Mantid.
+
+     Mantid is free software; you can redistribute it and/or modify
+     it under the terms of the GNU General Public License as published by
+     the Free Software Foundation; either version 3 of the License, or
+     (at your option) any later version.
+
+     Mantid is distributed in the hope that it will be useful,
+     but WITHOUT ANY WARRANTY; without even the implied warranty of
+     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+     GNU General Public License for more details.
+
+     You should have received a copy of the GNU General Public License
+     along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+     File change history is stored at: <https://github.com/mantidproject/mantid>
+     Code Documentation is available at: <http://doxygen.mantidproject.org>
+     */
+    class DLLExport LoadILL: public API::IFileLoader<Kernel::NexusDescriptor>
+    {
+    public:
+      /// Constructor
+      LoadILL();	/// Virtual destructor
+      virtual ~LoadILL()
+      {
+      }
+      /// Algorithm's name
+      virtual const std::string name() const
+      {
+        return "LoadILL";
+      }
+      ///Summary of algorithms purpose
+      virtual const std::string summary() const
+      {
+        return "Loads a ILL nexus file.";
+      }
+
+      /// Algorithm's version
+      virtual int version() const
+      {
+        return (1);
+      }
+      /// Algorithm's category for identification
+      virtual const std::string category() const
+      {
+        return "DataHandling";
+      }
+
+      /// Returns a confidence value that this algorithm can load a file
+      int confidence(Kernel::NexusDescriptor & descriptor) const;
+
+    private:
+      // Initialisation code
+      void init();
+      // Execution code
+      void exec();
+
+      int getEPPFromVanadium(const std::string &, Mantid::API::MatrixWorkspace_sptr);
+      void loadInstrumentDetails(NeXus::NXEntry&);
+      std::vector<std::vector<int> > getMonitorInfo(NeXus::NXEntry& firstEntry);
+      void initWorkSpace(NeXus::NXEntry& entry, const std::vector<std::vector<int> >&);
+      void initInstrumentSpecific();
+      void addAllNexusFieldsAsProperties(std::string filename);
+      void addEnergyToRun();
+
+      void loadExperimentDetails(NeXus::NXEntry & entry);
+      int getDetectorElasticPeakPosition(const NeXus::NXInt &data);
+      void loadTimeDetails(NeXus::NXEntry& entry);
+      NeXus::NXData loadNexusFileData(NeXus::NXEntry& entry);
+      void loadDataIntoTheWorkSpace(NeXus::NXEntry& entry, const std::vector<std::vector<int> >&,
+          int vanaCalculatedDetectorElasticPeakPosition = -1);
+
+      void runLoadInstrument();
+
+      /// Calculate error for y
+      static double calculateError(double in)
+      {
+        return sqrt(in);
+      }
+      int validateVanadium(const std::string &);
+
+      API::MatrixWorkspace_sptr m_localWorkspace;
 
 //	NeXus::NXRoot m_dataRoot;
 //	NeXus::NXRoot m_vanaRoot;
 
-  std::string m_instrumentName; ///< Name of the instrument
-  std::string m_instrumentPath; ///< Name of the instrument path
+      std::string m_instrumentName; ///< Name of the instrument
+      std::string m_instrumentPath; ///< Name of the instrument path
 
-  // Variables describing the data in the detector
-  size_t m_numberOfTubes; // number of tubes - X
-  size_t m_numberOfPixelsPerTube; //number of pixels per tube - Y
-  size_t m_numberOfChannels; // time channels - Z
-  size_t m_numberOfHistograms;
+      // Variables describing the data in the detector
+      size_t m_numberOfTubes; // number of tubes - X
+      size_t m_numberOfPixelsPerTube; //number of pixels per tube - Y
+      size_t m_numberOfChannels; // time channels - Z
+      size_t m_numberOfHistograms;
 
-  /* Values parsed from the nexus file */
-  int m_monitorElasticPeakPosition;
-  double m_wavelength;
-  double m_channelWidth;
+      /* Values parsed from the nexus file */
+      int m_monitorElasticPeakPosition;
+      double m_wavelength;
+      double m_channelWidth;
 
-  double m_l1; //=2.0;
-  double m_l2; //=4.0;
+      double m_l1; //=2.0;
+      double m_l2; //=4.0;
 
-  std::vector<std::string> m_supportedInstruments;
-  LoadHelper m_loader;
+      std::vector<std::string> m_supportedInstruments;
+      LoadHelper m_loader;
 
-};
+    };
 
-} // namespace DataHandling
+  } // namespace DataHandling
 } // namespace Mantid
 
 #endif /*MANTID_DATAHANDLING_LoadILL_H_*/
diff --git a/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/LoadILLReflectometry.h b/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/LoadILLReflectometry.h
index 5b01aa8089c116eda069db216b399451eca6d2d4..f808b32a77d76613ef37b913f54324ae25980ae7 100644
--- a/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/LoadILLReflectometry.h
+++ b/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/LoadILLReflectometry.h
@@ -13,7 +13,7 @@ namespace Mantid
   namespace DataHandling
   {
 
-    /** LoadILLReflectometry : TODO: DESCRIPTION
+    /** LoadILLReflectometry : Loads a ILL Reflectometry data file.
 
      Copyright &copy; 2014 ISIS Rutherford Appleton Laboratory & NScD Oak Ridge National Laboratory
 
@@ -80,7 +80,6 @@ namespace Mantid
       double m_wavelength;
       double m_channelWidth;
 
-
       std::vector<std::string> m_supportedInstruments;
       LoadHelper m_loader;
 
diff --git a/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/LoadInstrumentFromNexus.h b/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/LoadInstrumentFromNexus.h
index 6ef00628b8534d0cb97433e30f8df10a7df83f25..2d63bedc2979452c5c03823becdbf824aefeec16 100644
--- a/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/LoadInstrumentFromNexus.h
+++ b/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/LoadInstrumentFromNexus.h
@@ -73,8 +73,8 @@ namespace Mantid
 
       /// Algorithm's name for identification overriding a virtual method
       virtual const std::string name() const { return "LoadInstrumentFromNexus";};
-    ///Summary of algorithms purpose
-    virtual const std::string summary() const {return "Attempts to load some information about the instrument from a Nexus file. In particular attempt to read L2 and 2-theta detector position values and add detectors which are positioned relative to the sample in spherical coordinates as (r,theta,phi)=(L2,2-theta,phi). Also adds dummy source and samplepos components to instrument.  Later this will be extended to use any further available details about the instrument in the Nexus file.  If the L1 source - sample distance is not available in the file then it may be read from the mantid properties file using the key instrument.L1, as a final fallback a default distance of 10m will be used.";}
+      ///Summary of algorithms purpose
+      virtual const std::string summary() const {return "Attempts to load some information about the instrument from a Nexus file. It adds dummy source and samplepos components to instrument. If the L1 source - sample distance is not available in the file then it may be read from the mantid properties file using the key instrument.L1, as a final fallback a default distance of 10m will be used.";}
 
 
       /// Algorithm's version for identification overriding a virtual method
diff --git a/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/LoadMuonNexus1.h b/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/LoadMuonNexus1.h
index 37ab9e0a08762edc29204740b2df781ee186d05f..7b2c3f669bfca0d0390855a37dbea2b947603b5c 100644
--- a/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/LoadMuonNexus1.h
+++ b/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/LoadMuonNexus1.h
@@ -90,12 +90,8 @@ namespace Mantid
     protected:
       /// Overwrites Algorithm method
       void exec();
-      /// Implement the base class method
-      void runLoadInstrumentFromNexus(DataObjects::Workspace2D_sptr);
-      
-    private:
-      
       
+    private:   
       void loadData(const MantidVecPtr::ptr_type& tcbs,size_t hist, specid_t& i,
         MuonNexusReader& nxload, const int64_t lengthIn, DataObjects::Workspace2D_sptr localWorkspace);
       void runLoadMappingTable(DataObjects::Workspace2D_sptr);
diff --git a/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/ProcessDasNexusLog.h b/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/ProcessDasNexusLog.h
index dd077d8c664d3cabb1ee84d115fded9b896189e8..b15b129264fc681372e8637d9bfa6f24853e065a 100644
--- a/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/ProcessDasNexusLog.h
+++ b/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/ProcessDasNexusLog.h
@@ -3,6 +3,7 @@
 
 #include "MantidKernel/System.h"
 #include "MantidAPI/Algorithm.h"
+#include "MantidAPI/DeprecatedAlgorithm.h"
 
 namespace Mantid
 {
@@ -33,7 +34,7 @@ namespace DataHandling
     File change history is stored at: <https://github.com/mantidproject/mantid>
     Code Documentation is available at: <http://doxygen.mantidproject.org>
   */
-  class DLLExport ProcessDasNexusLog : public API::Algorithm
+  class DLLExport ProcessDasNexusLog : public API::Algorithm, public API::DeprecatedAlgorithm
   {
   public:
     ProcessDasNexusLog();
diff --git a/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/RawFileInfo.h b/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/RawFileInfo.h
index 775295ceebd470035013e8a833de15093140ed0a..7ef4d200c9680e32cf085db914a06e29770d8806 100644
--- a/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/RawFileInfo.h
+++ b/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/RawFileInfo.h
@@ -6,6 +6,11 @@
 //------------------------------------
 #include "MantidAPI/Algorithm.h"
 
+//------------------------------------
+// Forward declarations
+//------------------------------------
+class ISISRAW;
+
 namespace Mantid
 {
 namespace DataHandling
@@ -52,17 +57,21 @@ namespace DataHandling
    File change history is stored at: <https://github.com/mantidproject/mantid>. 
    Code Documentation is available at: <http://doxygen.mantidproject.org>
 */
-class DLLExport RawFileInfo : public Mantid::API::Algorithm
+class DLLExport RawFileInfo : public API::Algorithm
 {
 public:
+
+  static const std::string runTitle(const ISISRAW & isisRaw);
+  static const std::string runHeader(const ISISRAW & isisRaw);
+
   /// (Empty) Constructor
   RawFileInfo() : Mantid::API::Algorithm() {}
   /// Virtual destructor
   virtual ~RawFileInfo() {}
   /// Algorithm's name
   virtual const std::string name() const { return "RawFileInfo"; }
-    ///Summary of algorithms purpose
-    virtual const std::string summary() const {return "Extract run parameters from a  RAW file as output properties.";}
+  ///Summary of algorithms purpose
+  virtual const std::string summary() const {return "Extract run parameters from a  RAW file as output properties.";}
 
   /// Algorithm's version
   virtual int version() const { return (1); }
diff --git a/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/SaveGSS.h b/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/SaveGSS.h
index 3d9d0989d282f61b7a28118505d121b95fd70fd7..eab1f76db85c653eafee75eb0db661b55b8efacc 100644
--- a/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/SaveGSS.h
+++ b/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/SaveGSS.h
@@ -79,19 +79,27 @@ private:
   void init();
   ///Execution code
   void exec();
+
+  /// Write GSAS file
+  void writeGSASFile(const std::string& outfilename, bool append, int basebanknumber, bool multiplybybinwidth,  bool split,
+                     const std::string& outputFormat);
+
   ///Write the header information
-  void writeHeaders(const std::string &format, std::ostream& os,API::MatrixWorkspace_const_sptr& workspace, double primaryflightpath) const;
+  void writeHeaders(const std::string &format, std::stringstream &os,double primaryflightpath) const;
   ///Write out the data in RALF format
-  void writeRALFdata(const int bank, const bool MultiplyByBinWidth, std::ostream& out,
+  void writeRALFdata(const int bank, const bool MultiplyByBinWidth, std::stringstream &out,
                      const MantidVec& X, const MantidVec& Y, const MantidVec& E) const;
   ///Write out the data in SLOG format
-  void writeSLOGdata(const int bank, const bool MultiplyByBinWidth, std::ostream& out,
+  void writeSLOGdata(const int bank, const bool MultiplyByBinWidth, std::stringstream &out,
                      const MantidVec& X, const MantidVec& Y, const MantidVec& E) const;
   /// sets non workspace properties for the algorithm
   void setOtherProperties(IAlgorithm* alg,const std::string & propertyName,const std::string &propertyValue,int periodNum);
 
   bool m_useSpecAsBank;
 
+  /// Workspace
+  API::MatrixWorkspace_const_sptr inputWS;
+
 };
 
 }
diff --git a/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/SaveParameterFile.h b/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/SaveParameterFile.h
new file mode 100644
index 0000000000000000000000000000000000000000..fcf51fb54fc00f0f202b4eb3e11da7b8e34aad99
--- /dev/null
+++ b/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/SaveParameterFile.h
@@ -0,0 +1,62 @@
+#ifndef MANTID_ALGORITHMS_SAVEPARAMETERFILE_H_
+#define MANTID_ALGORITHMS_SAVEPARAMETERFILE_H_
+
+#include "MantidKernel/System.h"
+#include "MantidAPI/Algorithm.h"
+
+namespace Mantid
+{
+
+namespace DataHandling
+{
+
+  /** SaveParameterFile : Save a workspace's parameters to an instrument parameter file.
+
+    @author Harry Jeffery, ISIS, RAL
+    @date 17/7/2014
+
+    Copyright &copy; 2014 ISIS Rutherford Appleton Laboratory & NScD Oak Ridge National Laboratory
+
+    This file is part of Mantid.
+
+    Mantid is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 3 of the License, or
+    (at your option) any later version.
+
+    Mantid is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+    File change history is stored at: <https://github.com/mantidproject/mantid>
+    Code Documentation is available at: <http://doxygen.mantidproject.org>
+  */
+  class DLLExport SaveParameterFile  : public API::Algorithm
+  {
+  public:
+    SaveParameterFile();
+    virtual ~SaveParameterFile();
+
+    virtual const std::string name() const;
+    ///Summary of algorithms purpose
+    virtual const std::string summary() const {return "Save an instrument's parameters to an instrument parameter file.";}
+
+    virtual int version() const;
+    virtual const std::string category() const;
+
+  private:
+
+    void init();
+    void exec();
+
+  };
+
+
+} // namespace Algorithms
+} // namespace Mantid
+
+#endif  /* MANTID_ALGORITHMS_SAVEPARAMETERFILE_H_ */
diff --git a/Code/Mantid/Framework/DataHandling/src/FilterEventsByLogValuePreNexus.cpp b/Code/Mantid/Framework/DataHandling/src/FilterEventsByLogValuePreNexus.cpp
index f94b51755c9b7b066372b739fab595f5b56a94b4..55ddfcc3360c995198d5c3a1d15b4acdf9fa84c0 100644
--- a/Code/Mantid/Framework/DataHandling/src/FilterEventsByLogValuePreNexus.cpp
+++ b/Code/Mantid/Framework/DataHandling/src/FilterEventsByLogValuePreNexus.cpp
@@ -1849,7 +1849,7 @@ namespace DataHandling
     int filterstatus = -1;
     DateAndTime logpulsetime;
     // double logtof;
-    bool definedfilterstatus;
+    bool definedfilterstatus = false;
     if (fileOffset == 0)
     {
       // First file loading chunk
diff --git a/Code/Mantid/Framework/DataHandling/src/LoadDspacemap.cpp b/Code/Mantid/Framework/DataHandling/src/LoadDspacemap.cpp
index 53435dfa74e8c5deab32db4f45373d840745d561..b81e1a76f1227a5c45b8fc1fd0e6227d75e29caa 100644
--- a/Code/Mantid/Framework/DataHandling/src/LoadDspacemap.cpp
+++ b/Code/Mantid/Framework/DataHandling/src/LoadDspacemap.cpp
@@ -400,6 +400,8 @@ namespace DataHandling
         vulcan[static_cast<detid_t>(it->pixelID)] = it->factor;
       }
     }
+
+    delete results;
   }
 
 
diff --git a/Code/Mantid/Framework/DataHandling/src/LoadEventNexus.cpp b/Code/Mantid/Framework/DataHandling/src/LoadEventNexus.cpp
index dbdd0f6ef5ee36077a2ce633c3d3dc06784eafc6..d11a0d35dfaae23f169ce9b9ee438436c47dd941 100644
--- a/Code/Mantid/Framework/DataHandling/src/LoadEventNexus.cpp
+++ b/Code/Mantid/Framework/DataHandling/src/LoadEventNexus.cpp
@@ -2355,13 +2355,13 @@ void LoadEventNexus::setTimeFilters(const bool monitors)
 
   filter_tof_min = getProperty(prefix + "ByTofMin");
   filter_tof_max = getProperty(prefix + "ByTofMax");
-  if ( (filter_tof_min == EMPTY_DBL()) ||  (filter_tof_max == EMPTY_DBL()))
+  if ( (filter_tof_min == EMPTY_DBL()) &&  (filter_tof_max == EMPTY_DBL()))
   {
     //Nothing specified. Include everything
     filter_tof_min = -1e20;
     filter_tof_max = +1e20;
   }
-  else if ( (filter_tof_min != EMPTY_DBL()) ||  (filter_tof_max != EMPTY_DBL()))
+  else if ( (filter_tof_min != EMPTY_DBL()) &&  (filter_tof_max != EMPTY_DBL()))
   {
     //Both specified. Keep these values
   }
diff --git a/Code/Mantid/Framework/DataHandling/src/LoadGSS.cpp b/Code/Mantid/Framework/DataHandling/src/LoadGSS.cpp
index 967f362fdc28dd2765f64a3c07509f8f65b57070..9333163d053cc851ef0fa8bb5d1f587534d9424c 100644
--- a/Code/Mantid/Framework/DataHandling/src/LoadGSS.cpp
+++ b/Code/Mantid/Framework/DataHandling/src/LoadGSS.cpp
@@ -25,501 +25,531 @@ using namespace Mantid::Kernel;
 
 namespace Mantid
 {
-  namespace DataHandling
+namespace DataHandling
+{
+
+  DECLARE_FILELOADER_ALGORITHM(LoadGSS)
+
+  //----------------------------------------------------------------------------------------------
+  /** Return the confidence with with this algorithm can load the file
+    * @param descriptor A descriptor for the file
+    * @returns An integer specifying the confidence level. 0 indicates it will not be used
+    */
+  int LoadGSS::confidence(Kernel::FileDescriptor & descriptor) const
   {
-    DECLARE_FILELOADER_ALGORITHM(LoadGSS);
-
-    /**
-     * Return the confidence with with this algorithm can load the file
-     * @param descriptor A descriptor for the file
-     * @returns An integer specifying the confidence level. 0 indicates it will not be used
-     */
-    int LoadGSS::confidence(Kernel::FileDescriptor & descriptor) const
-    {
-      if(!descriptor.isAscii()) return 0;
+    if(!descriptor.isAscii()) return 0;
 
-      std::string str;
-      std::istream & file = descriptor.data();
-      std::getline(file, str);//workspace title first line
-      while (!file.eof())
+    std::string str;
+    std::istream & file = descriptor.data();
+    std::getline(file, str);//workspace title first line
+    while (!file.eof())
+    {
+      std::getline(file, str);
+      // Skip over empty and comment lines, as well as those coming from files saved with the 'ExtendedHeader' option
+      if (str.empty() || str[0] == '#' || str.compare(0, 8, "Monitor:") == 0)
       {
-        std::getline(file, str);
-        // Skip over empty and comment lines, as well as those coming from files saved with the 'ExtendedHeader' option
-        if (str.empty() || str[0] == '#' || str.compare(0, 8, "Monitor:") == 0)
-        {
-          continue;
-        }
-        if(str.compare(0, 4,"BANK") == 0 &&
-           (str.find("RALF") != std::string::npos || str.find("SLOG") != std::string::npos) &&
-           (str.find("FXYE") != std::string::npos))
-        {
-          return 80;
-        }
+        continue;
+      }
+      if(str.compare(0, 4,"BANK") == 0 &&
+         (str.find("RALF") != std::string::npos || str.find("SLOG") != std::string::npos) &&
+         (str.find("FXYE") != std::string::npos))
+      {
+        return 80;
       }
-      return 0;
     }
+    return 0;
+  }
 
-    /**
-     * Initialise the algorithm
-     */
-    void LoadGSS::init()
-    {
-      std::vector<std::string> exts;
-      exts.push_back(".gsa");
-      exts.push_back(".gss");
-      exts.push_back(".txt");
-      declareProperty(new API::FileProperty("Filename", "", API::FileProperty::Load, exts),
-          "The input filename of the stored data");
-      declareProperty(new API::WorkspaceProperty<>("OutputWorkspace", "", Kernel::Direction::Output),
-                      "Workspace name to load into.");
-
-      declareProperty("UseBankIDasSpectrumNumber", false, "If true, spectrum number corresponding to each bank is to be its bank ID. ");
-    }
+  //----------------------------------------------------------------------------------------------
+  /** Initialise the algorithm
+    */
+  void LoadGSS::init()
+  {
+    std::vector<std::string> exts;
+    exts.push_back(".gsa");
+    exts.push_back(".gss");
+    exts.push_back(".gda");
+    exts.push_back(".txt");
+    declareProperty(new API::FileProperty("Filename", "", API::FileProperty::Load, exts),
+                    "The input filename of the stored data");
+
+    declareProperty(new API::WorkspaceProperty<>("OutputWorkspace", "", Kernel::Direction::Output),
+                    "Workspace name to load into.");
+
+    declareProperty("UseBankIDasSpectrumNumber", false, "If true, spectrum number corresponding to each bank is to be its bank ID. ");
+  }
+
+  //----------------------------------------------------------------------------------------------
+  /** Execute the algorithm
+    */
+  void LoadGSS::exec()
+  {
+    // Process input parameters
+    std::string filename = getPropertyValue("Filename");
 
-    /**
-     * Execute the algorithm
-     */
-    void LoadGSS::exec()
-    {
-      using namespace Mantid::API;
-      std::string filename = getPropertyValue("Filename");
+    bool useBankAsSpectrum = getProperty("UseBankIDasSpectrumNumber");
 
-      bool m_useBankAsSpectrum = getProperty("UseBankIDasSpectrumNumber");
+    MatrixWorkspace_sptr outputWorkspace = loadGSASFile(filename, useBankAsSpectrum);
 
-      std::vector<MantidVec*> gsasDataX;
-      std::vector<MantidVec*> gsasDataY;
-      std::vector<MantidVec*> gsasDataE;
+    setProperty("OutputWorkspace", outputWorkspace);
 
-      double primaryflightpath = -1;
-      std::vector<double> twothetas;
-      std::vector<double> difcs;
-      std::vector<double> totalflightpaths;
-      std::vector<int> detectorIDs;
+    return;
+  }
 
-      MantidVec* X = new MantidVec();
-      MantidVec* Y = new MantidVec();
-      MantidVec* E = new MantidVec();
+  //----------------------------------------------------------------------------------------------
+  /** Main method to load GSAS file
+    */
+  API::MatrixWorkspace_sptr LoadGSS::loadGSASFile(const std::string& filename, bool useBankAsSpectrum)
+  {
+    // Vectors for detector information
+    double primaryflightpath = -1;
+    std::vector<double> twothetas;
+    std::vector<double> difcs;
+    std::vector<double> totalflightpaths;
+    std::vector<int> detectorIDs;
+
+    // Vectors to store data
+    std::vector<std::vector<double> > gsasDataX, gsasDataY, gsasDataE;
+    std::vector<double> vecX, vecY, vecE;
+
+    // progress
+    Progress* prog = NULL;
+
+    // Parameters for reading file
+    char currentLine[256];
+    std::string wsTitle;
+    std::string slogTitle;
+    std::string instrumentname = "Generic";
+    char filetype = 'x';
+
+    // Gather data
+    std::ifstream input(filename.c_str(), std::ios_base::in);
+    if (!input.is_open())
+    {
+      // throw exception if file cannot be opened
+      std::stringstream errss;
+      errss << "Unable to open GSAS file " << filename;
+      throw std::runtime_error(errss.str());
+    }
+
+    // First line: Title
+    if (!input.eof())
+    {
+      // Get workspace title (should be first line or 2nd line for SLOG)
+      input.getline(currentLine, 256);
+      wsTitle = currentLine;
+    }
+    else
+    {
+      throw std::runtime_error("File is empty");
+    }
 
-      Progress* prog = NULL;
+    // Loop all the lines
+    bool isOutOfHead = false;
+    bool slogtitleset = false;
+    bool multiplybybinwidth = false;
+    int nSpec = 0;
+    bool calslogx0 = true;
+    double bc4 = 0;
+    double bc3 = 0;
 
-      char currentLine[256];
-      std::string wsTitle;
-      std::string slogTitle;
-      std::string instrumentname = "Generic";
-      char filetype = 'x';
+    while (!input.eof() && input.getline(currentLine, 256))
+    {
+      // Initialize progress after NSpec is imported
+      if (nSpec != 0 && prog == NULL)
+      {
+        prog = new Progress(this, 0.0, 1.0, nSpec);
+      }
 
-      std::ifstream input(filename.c_str(), std::ios_base::in);
+      // Set flag to test SLOG
+      if (!slogtitleset)
+      {
+        slogTitle = currentLine;
+        slogtitleset = true;
+      }
 
-      // Gather data
-      if (input.is_open())
+      if (currentLine[0] == '\n' || currentLine[0] == '#')
       {
+        // Comment/information line
+        std::string key1, key2;
+        std::istringstream inputLine(currentLine, std::ios::in);
+        inputLine.ignore(256, ' ');
+        inputLine >> key1 >> key2;
 
-        // 1. First line: Title
-        if (!input.eof())
+        if (key2 == "Histograms")
         {
-          //    Get workspace title (should be first line or 2nd line for SLOG)
-          input.getline(currentLine, 256);
-          wsTitle = currentLine;
-        } // if
-
-        // 2. Loop all the lines
-        bool isOutOfHead = false;
-        bool slogtitleset = false;
-        bool multiplybybinwidth = false;
-        bool db1 = true;      
-        int nSpec = 0;
-        bool calslogx0 = true;
-        double bc4 = 0;
-        double bc3 = 0;
-
-        while (!input.eof() && input.getline(currentLine, 256))
+          // NSpec (Format: 'nspec HISTOGRAM')
+          nSpec = atoi(key1.c_str());
+          g_log.information() << "Histogram Line:  " << key1 << "  nSpec = " << nSpec << "\n";
+        }
+        else if (key1 == "Instrument:")
         {
-
-          if (nSpec != 0 && prog == NULL)
+          // Instrument (Format: 'Instrument XXXX')
+          instrumentname = key2;
+          g_log.information() << "Instrument    :  " << key2 << "\n";
+        }
+        else if (key1 == "with")
+        {
+          // Multiply by bin width: (Format: 'with multiplied')
+          std::string s1;
+          inputLine >> s1;
+          if (s1 == "multiplied")
           {
-            prog = new Progress(this, 0.0, 1.0, nSpec);
+            multiplybybinwidth = true;
+            g_log.information() << "Y is multiplied by bin width" << std::endl;
           }
-          if (!slogtitleset)
+          else
           {
-            slogTitle = currentLine;
-            slogtitleset = true;
+            g_log.warning() << "In line '" << currentLine << "', key word " << s1 << " is not allowed!\n";
           }
+        }
+        else if (key1 == "Primary")
+        {
+          // Primary flight path ...
+          std::string s1, s2;
+          inputLine >> s1 >> s2;
+          primaryflightpath = atof(s2.c_str()); // convertToDouble(s2);
+          g_log.information() << "L1 = " << primaryflightpath << std::endl;
+        }
+        else if (key1 == "Total")
+        {
+          // Total flight path .... .... including total flying path, difc and 2theta of 1 bank
+          std::string s1, s2, s3, s4, s5, s6;
+          inputLine >> s1 >> s2 >> s3 >> s4 >> s5 >> s6;
+#if 0
+          double totalpath = convertToDouble(s2);
+          double tth = convertToDouble(s4);
+          double difc = convertToDouble(s6);
+#else
+          double totalpath = atof(s2.c_str());
+          double tth = atof(s4.c_str());
+          double difc = atof(s6.c_str());
+#endif
+
+          totalflightpaths.push_back(totalpath);
+          twothetas.push_back(tth);
+          difcs.push_back(difc);
+
+          g_log.information() << "Bank " << difcs.size()-1 << ": Total flight path = " << totalpath
+                              << "  2Theta = " << tth << "  DIFC = " << difc << "\n";
+        } // if keys....
+
+      } // ENDIF for Line with #
+      else if (currentLine[0] == 'B')
+      {
+        // Line start with Bank including file format, X0 information and etc.
+        isOutOfHead = true;
 
+        // If there is, Save the previous to array and initialze new MantiVec for (X, Y, E)
+        if (vecX.size() != 0)
+        {
+          std::vector<double> storeX = vecX;
+          std::vector<double> storeY = vecY;
+          std::vector<double> storeE = vecE;
+
+          gsasDataX.push_back(storeX);
+          gsasDataY.push_back(storeY);
+          gsasDataE.push_back(storeE);
+          vecX.clear();
+          vecY.clear();
+          vecE.clear();
+
+          if (prog != NULL)
+            prog->report();
+        }
 
-          if (currentLine[0] == '\n' || currentLine[0] == '#')
-          {
-            // Comment/Information Line
-
-            std::string key1, key2;
-            std::istringstream inputLine(currentLine, std::ios::in);
-            inputLine.ignore(256, ' ');
-            inputLine >> key1 >> key2;
-
-            if (key2 == "Histograms")
-            {
-              // X Histograms
-              nSpec = atoi(key1.c_str());
-              g_log.debug() << "Histogram Line:  " << key1 << "  nSpec = " << nSpec << std::endl;
-            }
-            else if (key1 == "Instrument:")
-            {
-              // Instrument: XXXX
-              instrumentname = key2;
-              g_log.information() << "Instrument    :  " << key2 << std::endl;
-            }
-            else if (key1 == "with")
-            {
-              std::string s1;
-              inputLine >> s1;
-              if (s1 == "multiplied"){
-                multiplybybinwidth = true;
-                g_log.information() << "Y is multiplied by bin width" << std::endl;
-              } else {
-                g_log.debug() << "s1 = " << s1 << " is not allowed!\n";
-              }
-            }
-            else if (key1 == "Primary")
-            {
-              // Primary flight path ...
-              std::string s1, s2;
-              inputLine >> s1 >> s2;
-              primaryflightpath = convertToDouble(s2);
-              g_log.information() << "L1 = " << primaryflightpath << std::endl;
-            }
-            else if (key1 == "Total")
-            {
-              // Total flight path .... ....
-              std::string s1, s2, s3, s4, s5, s6;
-              inputLine >> s1 >> s2 >> s3 >> s4 >> s5 >> s6;
-              double totalpath = convertToDouble(s2);
-              double tth = convertToDouble(s4);
-              double difc = convertToDouble(s6);
-
-              totalflightpaths.push_back(totalpath);
-              twothetas.push_back(tth);
-              difcs.push_back(difc);
-
-              g_log.information() << "Total flight path = " << totalpath << "  2Theta = " << tth << "  DIFC = " << difc << std::endl;
-            } // if keys....
-
-          } // Line with #
-          else if (currentLine[0] == 'B')
+        // Parse the bank line in format
+        // RALF: BANK <SpectraNo> <NBins> <NBins> RALF <BC1> <BC2> <BC1> <BC4>
+        // SLOG: BANK <SpectraNo> <NBins> <NBins> SLOG <BC1> <BC2> <BC3> 0>
+        // where,
+        // BC1 = X[0] * 32
+        // BC2 = X[1] * 32 - BC1
+        // BC4 = ( X[1] - X[0] ) / X[0]
+
+        int specno, nbin1, nbin2;
+        std::istringstream inputLine(currentLine, std::ios::in);
+
+        double bc1 = 0;
+        double bc2 = 0;
+
+        inputLine.ignore(256, 'K');
+        std::string filetypestring;
+
+        inputLine >> specno >> nbin1 >> nbin2 >> filetypestring;
+        g_log.debug() << "Bank: " << specno << "  filetypestring = " << filetypestring << std::endl;
+
+        detectorIDs.push_back(specno);
+
+        if (filetypestring[0] == 'S')
+        {
+          // SLOG
+          filetype = 's';
+          inputLine >> bc1 >> bc2 >> bc3 >> bc4;
+        }
+        else if (filetypestring[0] == 'R')
+        {
+          // RALF
+          filetype = 'r';
+          inputLine >> bc1 >> bc2 >> bc1 >> bc4;
+        }
+        else
+        {
+          g_log.error() << "Unsupported GSAS File Type: " << filetypestring << "\n";
+          throw Exception::FileError("Not a GSAS file", filename);
+        }
+
+        // Determine x0
+        if (filetype == 'r')
+        {
+          double x0 = bc1 / 32;
+          g_log.debug() << "RALF: x0 = " << x0 << "  bc4 = " << bc4 << std::endl;
+          vecX.push_back(x0);
+        }
+        else
+        {
+          // Cannot calculate x0, turn on the flag
+          calslogx0 = true;
+        }
+      } // Line with B
+      else if (isOutOfHead)
+      {
+        // Parse data line
+        double xValue;
+        double yValue;
+        double eValue;
+
+        double xPrev;
+
+        // * Get previous X value
+        if (vecX.size() != 0)
+        {
+          xPrev = vecX.back();
+        }
+        else if (filetype == 'r')
+        {
+          // Except if RALF
+          throw Mantid::Kernel::Exception::NotImplementedError(
+                "LoadGSS: File was not in expected format.");
+        }
+        else
+        {
+          xPrev = -0.0;
+        }
+
+        std::istringstream inputLine(currentLine, std::ios::in);
+        inputLine >> xValue >> yValue >> eValue;
+
+        // It is different for the definition of X, Y, Z in SLOG and RALF format
+        if (filetype == 'r')
+        {
+          // RALF
+          xValue = (2 * xValue) - xPrev;
+          yValue = yValue / (xPrev * bc4);
+          eValue = eValue / (xPrev * bc4);
+
+        }
+        else if (filetype == 's')
+        {
+          // SLOG
+          if (calslogx0)
           {
-            // Line start with Bank including file format, X0 information and etc.
-
-            isOutOfHead = true;
-
-            // 1. Save the previous to array and initialze new MantiVec for (X, Y, E)
-            if (X->size() != 0)
-            {
-              gsasDataX.push_back(X);
-              gsasDataY.push_back(Y);
-              gsasDataE.push_back(E);
-              X = new MantidVec();
-              Y = new MantidVec();
-              E = new MantidVec();
-
-              if (prog != NULL)
-                prog->report();
-            }
-
-            // 2. Parse
-
-            /* BANK <SpectraNo> <NBins> <NBins> RALF <BC1> <BC2> <BC1> <BC4>
-             *    OR,
-             * BANK <SpectraNo> <NBins> <NBins> SLOG <BC1> <BC2> <BC3> 0>
-             *  BC1 = X[0] * 32
-             *  BC2 = X[1] * 32 - BC1
-             *  BC4 = ( X[1] - X[0] ) / X[0]
-             */
-
-            // Parse B-line
-            int specno, nbin1, nbin2;
-            std::istringstream inputLine(currentLine, std::ios::in);
-
-            double bc1 = 0;
-            double bc2 = 0;
-            /*
-             inputLine.ignore(256, 'F');
-             inputLine >> bc1 >> bc2 >> bc1 >> bc4;
-             */
-
-            inputLine.ignore(256, 'K');
-            std::string filetypestring;
-
-            inputLine >> specno >> nbin1 >> nbin2 >> filetypestring;
-            g_log.debug() << "Bank: " << specno << "  filetypestring = " << filetypestring << std::endl;
-
-            detectorIDs.push_back(specno);
-
-            if (filetypestring[0] == 'S')
-            {
-              // SLOG
-              filetype = 's';
-              inputLine >> bc1 >> bc2 >> bc3 >> bc4;
-            }
-            else if (filetypestring[0] == 'R')
-            {
-              // RALF
-              filetype = 'r';
-              inputLine >> bc1 >> bc2 >> bc1 >> bc4;
-            }
-            else
-            {
-              g_log.error() << "Unsupported File Type: " << filetypestring << std::endl;
-              throw Exception::FileError("Not a GSAS file", filename);
-            }
-
-            // Determine x0
-            if (filetype == 'r')
-            {
-              double x0 = bc1 / 32;
-              g_log.debug() << "RALF: x0 = " << x0 << "  bc4 = " << bc4 << std::endl;
-              X->push_back(x0);
-            }
-            else
-            {
-              // Cannot calculate x0, turn on the flag
-              calslogx0 = true;
-            }
-          } // Line with B
-          else if (isOutOfHead)
+            // calculation of x0 must use the x'[0]
+            g_log.debug() << "x'_0 = " << xValue << "  bc3 = " << bc3 << std::endl;
+
+            double x0 = 2 * xValue / (bc3 + 2.0);
+            vecX.push_back(x0);
+            xPrev = x0;
+            g_log.debug() << "SLOG: x0 = " << x0 << std::endl;
+            calslogx0 = false;
+          }
+
+          xValue = (2 * xValue) - xPrev;
+          if (multiplybybinwidth)
           {
-            double xValue;
-            double yValue;
-            double eValue;
-
-            double xPrev;
-
-            // * Get previous X value
-            if (X->size() != 0)
-            {
-              xPrev = X->back();
-            }
-            else if (filetype == 'r')
-            {
-              // Except if RALF
-              throw Mantid::Kernel::Exception::NotImplementedError(
-                  "LoadGSS: File was not in expected format.");
-            }
-            else
-            {
-              xPrev = -0.0;
-            }
-
-            std::istringstream inputLine(currentLine, std::ios::in);
-            inputLine >> xValue >> yValue >> eValue;
-
-            // It is different for the definition of X, Y, Z in SLOG and RALF format
-            if (filetype == 'r')
-            {
-              // RALF
-              double tempy = yValue;
-
-              xValue = (2 * xValue) - xPrev;
-              yValue = yValue / (xPrev * bc4);
-              eValue = eValue / (xPrev * bc4);
-
-              if (db1)
-              {
-                g_log.debug() << "Type: " << filetype << "  xPrev = " << xPrev << " bc4 =" << bc4
-                    << std::endl;
-                g_log.debug() << "yValue = " << yValue << tempy << std::endl;
-                db1 = false;
-              }
-
-            } // filetype == r
-            else if (filetype == 's')
-            {
-              // SLOG
-              if (calslogx0)
-              {
-                // calculation of x0 must use the x'[0]
-                g_log.debug() << "x'_0 = " << xValue << "  bc3 = " << bc3 << std::endl;
-
-                double x0 = 2 * xValue / (bc3 + 2.0);
-                X->push_back(x0);
-                xPrev = x0;
-                g_log.debug() << "SLOG: x0 = " << x0 << std::endl;
-                calslogx0 = false;
-              }
-
-              xValue = (2 * xValue) - xPrev;
-              if (multiplybybinwidth)
-              {
-                yValue = yValue / (xValue - xPrev);
-                eValue = eValue / (xValue - xPrev);
-              }
-            } // file type == s
-
-            // store read in data (x, y, e) to vector
-            X->push_back(xValue);
-            Y->push_back(yValue);
-            E->push_back(eValue);
-          } // Date Line
-          else{
-            g_log.debug() << "Line not defined: " << currentLine << std::endl;
+            yValue = yValue / (xValue - xPrev);
+            eValue = eValue / (xValue - xPrev);
           }
-        } // while
-
-        // Clean up after file is read through
-        if (X->size() != 0)
-        { // Put final spectra into data
-          gsasDataX.push_back(X);
-          gsasDataY.push_back(Y);
-          gsasDataE.push_back(E);
         }
-        input.close();
-      } // if input is_open
 
-      int nHist(static_cast<int> (gsasDataX.size()));
-      int xWidth(static_cast<int> (X->size()));
-      int yWidth(static_cast<int> (Y->size()));
+        // store read in data (x, y, e) to vector
+        vecX.push_back(xValue);
+        vecY.push_back(yValue);
+        vecE.push_back(eValue);
+      } // Date Line
+      else
+      {
+        g_log.warning() << "Line not defined: " << currentLine << std::endl;
+      }
+    } // ENDWHILE of readling all lines
+
+    // Push the vectors (X, Y, E) of the last bank to gsasData
+    if (vecX.size() != 0)
+    { // Put final spectra into data
+      gsasDataX.push_back(vecX);
+      gsasDataY.push_back(vecY);
+      gsasDataE.push_back(vecE);
+    }
+    input.close();
+
+
+    //********************************************************************************************
+    // Construct the workspace for GSS data
+    //********************************************************************************************
+
+    // Create workspace & GSS Files data is always in TOF
+    int nHist(static_cast<int> (gsasDataX.size()));
+    int xWidth(static_cast<int> (vecX.size()));
+    int yWidth(static_cast<int> (vecY.size()));
 
-      // 2. Create workspace & GSS Files data is always in TOF
-      MatrixWorkspace_sptr outputWorkspace = boost::dynamic_pointer_cast<MatrixWorkspace>(
+    MatrixWorkspace_sptr outputWorkspace = boost::dynamic_pointer_cast<MatrixWorkspace>(
           WorkspaceFactory::Instance().create("Workspace2D", nHist, xWidth, yWidth));
-      outputWorkspace->getAxis(0)->unit() = UnitFactory::Instance().create("TOF");
+    outputWorkspace->getAxis(0)->unit() = UnitFactory::Instance().create("TOF");
 
-      // 2.1 Set workspace title
-      if (filetype == 'r')
-      {
-        outputWorkspace->setTitle(wsTitle);
-      }
-      else
+    // set workspace title
+    if (filetype == 'r')
+      outputWorkspace->setTitle(wsTitle);
+    else
+      outputWorkspace->setTitle(slogTitle);
+
+    // put data from MatidVec's into outputWorkspace
+    if (detectorIDs.size() != static_cast<size_t>(nHist))
+    {
+      // File error is found
+      std::ostringstream mess("");
+      mess << "Number of spectra (" << detectorIDs.size() << ") is not equal to number of histograms (" << nHist << ").";
+      throw std::runtime_error(mess.str());
+    }
+
+    for (int i = 0; i < nHist; ++i)
+    {
+      // Move data across
+      outputWorkspace->dataX(i) = gsasDataX[i];
+      outputWorkspace->dataY(i) = gsasDataY[i];
+      outputWorkspace->dataE(i) = gsasDataE[i];
+
+      // Reset spectrum number if
+      if (useBankAsSpectrum)
       {
-        outputWorkspace->setTitle(slogTitle);
+        specid_t specno = static_cast<specid_t>(detectorIDs[i]);
+        outputWorkspace->getSpectrum(i)->setSpectrumNo(specno);
       }
+    }
+
+    // build instrument geometry
+    createInstrumentGeometry(outputWorkspace, instrumentname, primaryflightpath,
+                             detectorIDs, totalflightpaths, twothetas);
+
+    // Clean up
+    delete prog;
 
-      // 2.2 Put data from MatidVec's into outputWorkspace
-      if (detectorIDs.size() != static_cast<size_t>(nHist))
+    return outputWorkspace;
+  }
+
+
+  //----------------------------------------------------------------------------------------------
+  /** Convert a string containing number and unit to double
+    */
+  double LoadGSS::convertToDouble(std::string inputstring)
+  {
+    std::string temps = "";
+    int isize = (int)inputstring.size();
+    for (int i = 0; i < isize; i++)
+    {
+      char thechar = inputstring[i];
+      if ((thechar <= 'Z' && thechar >= 'A') || (thechar <= 'z' && thechar >= 'a'))
       {
-        std::ostringstream mess("");
-        mess << "Number of spectra (" << detectorIDs.size() << ") is not equal to number of histograms (" << nHist << ").";
-        throw std::runtime_error(mess.str());
+        break;
       }
-      for (int i = 0; i < nHist; ++i)
+      else
       {
-        // Move data across
-        outputWorkspace->dataX(i) = *gsasDataX[i];
-        outputWorkspace->dataY(i) = *gsasDataY[i];
-        outputWorkspace->dataE(i) = *gsasDataE[i];
-        // Clean up after copy
-        delete gsasDataX[i];
-        delete gsasDataY[i];
-        delete gsasDataE[i];
-
-        // Reset spectrum number if
-        if (m_useBankAsSpectrum)
-        {
-          specid_t specno = static_cast<specid_t>(detectorIDs[i]);
-          outputWorkspace->getSpectrum(i)->setSpectrumNo(specno);
-        }
+        temps += thechar;
       }
+    }
 
-      // 2.3 Build instrument geometry
-      createInstrumentGeometry(outputWorkspace, instrumentname, primaryflightpath,
-          detectorIDs, totalflightpaths, twothetas);
+    double rd = atof(temps.c_str());
 
-      // Clean up
-      delete prog;
+    return rd;
+  }
 
-      setProperty("OutputWorkspace", outputWorkspace);
+  //----------------------------------------------------------------------------------------------
+  /** Create the instrument geometry with Instrument
+    */
+  void LoadGSS::createInstrumentGeometry(MatrixWorkspace_sptr workspace, const std::string& instrumentname,
+                                         const double& primaryflightpath, const std::vector<int>& detectorids,
+                                         const std::vector<double>& totalflightpaths, const std::vector<double>& twothetas)
+  {
+    // Check Input
+    if (detectorids.size() != totalflightpaths.size() || totalflightpaths.size() != twothetas.size())
+    {
+      g_log.warning("Cannot create geometry, because the numbers of L2 and Polar are not equal.");
       return;
     }
 
-    // Convert a string containing number and unit to double
-    double LoadGSS::convertToDouble(std::string inputstring)
+    // Debug output
+    std::stringstream dbss;
+    dbss << "L1 = " << primaryflightpath << "\n";
+    for (size_t i = 0; i < detectorids.size(); i ++)
     {
+      dbss << "Detector " << detectorids[i] << "  L1+L2 = " << totalflightpaths[i] << "  2Theta = "
+           << twothetas[i] << "\n";
+    }
+    g_log.debug(dbss.str());
 
-      std::string temps = "";
-      int isize = (int)inputstring.size();
-      for (int i = 0; i < isize; i++)
-      {
-        char thechar = inputstring[i];
-        if ((thechar <= 'Z' && thechar >= 'A') || (thechar <= 'z' && thechar >= 'a'))
-        {
-          break;
-        }
-        else
-        {
-          temps += thechar;
-        }
-      }
-
-      double rd = atof(temps.c_str());
+    // Create a new instrument and set its name
+    Geometry::Instrument_sptr instrument(new Geometry::Instrument(instrumentname));
+    workspace->setInstrument(instrument);
 
-      return rd;
-    }
+    // Add dummy source and samplepos to instrument
+    Geometry::ObjComponent *samplepos = new Geometry::ObjComponent("Sample",instrument.get());
+    instrument->add(samplepos);
+    instrument->markAsSamplePos(samplepos);
+    samplepos->setPos(0.0,0.0,0.0);
 
-    /* Create the instrument geometry with Instrument
-     *
-     */
-    void LoadGSS::createInstrumentGeometry(MatrixWorkspace_sptr workspace, std::string instrumentname, double primaryflightpath,
-        std::vector<int> detectorids, std::vector<double> totalflightpaths, std::vector<double> twothetas){
-
-      // 0. Check Input
-      g_log.information() << "L1 = " << primaryflightpath << std::endl;
-      if (detectorids.size() != totalflightpaths.size() || totalflightpaths.size() != twothetas.size()){
-        g_log.warning() << "Cannot create geometry, because the numbers of L2 and Polar are not equal." << std::endl;
-        return;
-      }
-      for (size_t i = 0; i < detectorids.size(); i ++){
-        g_log.debug() << "Detector " << detectorids[i] << "  L1+L2 = " << totalflightpaths[i] << "  2Theta = " << twothetas[i] << std::endl;
-      }
+    Geometry::ObjComponent *source = new Geometry::ObjComponent("Source",instrument.get());
+    instrument->add(source);
+    instrument->markAsSource(source);
 
-      // 1. Create a new instrument and set its name
-      Geometry::Instrument_sptr instrument(new Geometry::Instrument(instrumentname));
-      workspace->setInstrument(instrument);
+    double l1 = primaryflightpath;
+    source->setPos(0.0,0.0,-1.0*l1);
 
-      // 3. Add dummy source and samplepos to instrument
-      Geometry::ObjComponent *samplepos = new Geometry::ObjComponent("Sample",instrument.get());
-      instrument->add(samplepos);
-      instrument->markAsSamplePos(samplepos);
-      samplepos->setPos(0.0,0.0,0.0);
+    // Add detectors
+    // The L2 and 2-theta values from Raw file assumed to be relative to sample position
+    const int numDetector = (int)detectorids.size();    // number of detectors
+    // std::vector<int> detID = detectorids;    // detector IDs
+    // std::vector<double> angle = twothetas;  // angle between indicent beam and direction from sample to detector (two-theta)
 
-      Geometry::ObjComponent *source = new Geometry::ObjComponent("Source",instrument.get());
-      instrument->add(source);
-      instrument->markAsSource(source);
+    // Assumption: detector IDs are in the same order of workspace index
+    for (int i = 0; i < numDetector; ++i)
+    {
+      // a) Create a new detector. Instrument will take ownership of pointer so no need to delete.
+      Geometry::Detector *detector = new Geometry::Detector("det", detectorids[i],samplepos);
+      Kernel::V3D pos;
 
-      double l1 = primaryflightpath;
-      source->setPos(0.0,0.0,-1.0*l1);
+      // r is L2
+      double r = totalflightpaths[i] - l1;
+      pos.spherical(r, twothetas[i], 0.0 );
 
-      // 4. add detectors
-      // The L2 and 2-theta values from Raw file assumed to be relative to sample position
-      const int numDetector = (int)detectorids.size();    // number of detectors
-      std::vector<int> detID = detectorids;    // detector IDs
-      std::vector<double> angle = twothetas;  // angle between indicent beam and direction from sample to detector (two-theta)
+      detector->setPos(pos);
 
-      // Assumption: detector IDs are in the same order of workspace index
-      for (int i = 0; i < numDetector; ++i)
+      // add copy to instrument, spectrum and mark it
+      API::ISpectrum *spec = workspace->getSpectrum(i);
+      if (spec)
       {
-        // a) Create a new detector. Instrument will take ownership of pointer so no need to delete.
-        Geometry::Detector *detector = new Geometry::Detector("det",detID[i],samplepos);
-        Kernel::V3D pos;
-
-        // r is L2
-        double r = totalflightpaths[i] - l1;
-        pos.spherical(r, angle[i], 0.0 );
-
-        detector->setPos(pos);
-
-        // add copy to instrument, spectrum and mark it
-        API::ISpectrum *spec = workspace->getSpectrum(i);
-        if (!spec){
-          g_log.error() << "Workspace " << i << " has no spectrum!" << std::endl;
-          continue;
-        } else {
-          spec->clearDetectorIDs();
-          spec->addDetectorID(detID[i]);
-        }
-
+        spec->clearDetectorIDs();
+        spec->addDetectorID(detectorids[i]);
         instrument->add(detector);
         instrument->markAsDetector(detector);
       }
+      else
+      {
+        g_log.error() << "Workspace " << i << " has no spectrum!" << std::endl;
+        continue;
+      }
 
-      return;
-    }
+    } // ENDFOR (i: spectrum)
 
-  }//namespace
+    return;
+  }
+
+}//namespace
 }//namespace
diff --git a/Code/Mantid/Framework/DataHandling/src/LoadILL.cpp b/Code/Mantid/Framework/DataHandling/src/LoadILL.cpp
index f83ee5d4c0b74e805105dec9f44da72ba818adc1..6d2ac53513f4240fef3cdf2bc9a304975e55d829 100644
--- a/Code/Mantid/Framework/DataHandling/src/LoadILL.cpp
+++ b/Code/Mantid/Framework/DataHandling/src/LoadILL.cpp
@@ -29,16 +29,6 @@ namespace Mantid
 
     DECLARE_NEXUS_FILELOADER_ALGORITHM(LoadILL);
 
-    /**
-     * tostring operator to print the contents of NXClassInfo
-     *
-     * TODO : This has to go somewhere else
-     */
-    std::ostream& operator<<(std::ostream &strm, const NXClassInfo &c)
-    {
-      return strm << "NXClassInfo :: nxname: " << c.nxname << " , nxclass: " << c.nxclass;
-    }
-
 //---------------------------------------------------
 // Private member functions
 //---------------------------------------------------
@@ -54,8 +44,7 @@ namespace Mantid
       // fields existent only at the ILL
       if (descriptor.pathExists("/entry0/wavelength")
           && descriptor.pathExists("/entry0/experiment_identifier")
-          && descriptor.pathExists("/entry0/mode") 
-          && !descriptor.pathExists("/entry0/dataSD") // This one is for LoadILLIndirect
+          && descriptor.pathExists("/entry0/mode") && !descriptor.pathExists("/entry0/dataSD") // This one is for LoadILLIndirect
           && !descriptor.pathExists("/entry0/instrument/VirtualChopper") // This one is for LoadILLReflectometry
               )
       {
@@ -373,25 +362,14 @@ namespace Mantid
 
     /*
      * Load data about the Experiment.
-     *
-     * TODO: This is very incomplete. We need input from scientists to complete the code below
+     * TODO: Scientists must provide information to complete the code below
      *
      * @param entry :: The Nexus entry
      */
     void LoadILL::loadExperimentDetails(NXEntry & entry)
     {
-
-      // TODO: Do the rest
-      // Pick out the geometry information
-
       std::string description = boost::lexical_cast<std::string>(entry.getFloat("sample/description"));
-
       m_localWorkspace->mutableSample().setName(description);
-
-      //  m_localWorkspace->mutableSample().setThickness(static_cast<double> (isis_raw->spb.e_thick));
-      //  m_localWorkspace->mutableSample().setHeight(static_cast<double> (isis_raw->spb.e_height));
-      //  m_localWorkspace->mutableSample().setWidth(static_cast<double> (isis_raw->spb.e_width));
-
     }
 
     /**
@@ -401,7 +379,6 @@ namespace Mantid
      * It gets a few spectra in the equatorial line of the detector,
      * sum them up and finds the maximum = the Elastic peak
      *
-     *
      * @param data :: spectra data
      * @return detector Elastic Peak Position
      */
@@ -437,7 +414,6 @@ namespace Mantid
       }
       else
       {
-        //calculatedDetectorElasticPeakPosition = *it;
         calculatedDetectorElasticPeakPosition = static_cast<int>(std::distance(
             cumulatedSumOfSpectras.begin(), it));
 
@@ -598,9 +574,6 @@ namespace Mantid
       // Now execute the Child Algorithm. Catch and log any error, but don't stop.
       try
       {
-
-        // TODO: depending on the m_numberOfPixelsPerTube we might need to load a different IDF
-
         loadInst->setPropertyValue("InstrumentName", m_instrumentName);
         loadInst->setProperty<MatrixWorkspace_sptr>("Workspace", m_localWorkspace);
         loadInst->execute();
diff --git a/Code/Mantid/Framework/DataHandling/src/LoadILLReflectometry.cpp b/Code/Mantid/Framework/DataHandling/src/LoadILLReflectometry.cpp
index 22df862fec0f6968f96012af7ebe07d46d7c7019..5c9bdea5f20542ce531e5f23f3b040a91700baee 100644
--- a/Code/Mantid/Framework/DataHandling/src/LoadILLReflectometry.cpp
+++ b/Code/Mantid/Framework/DataHandling/src/LoadILLReflectometry.cpp
@@ -33,6 +33,8 @@ namespace Mantid
      */
     LoadILLReflectometry::LoadILLReflectometry()
     {
+      m_wavelength = 0;
+      m_channelWidth = 0;
       m_numberOfTubes = 0; // number of tubes - X
       m_numberOfPixelsPerTube = 0; //number of pixels per tube - Y
       m_numberOfChannels = 0; // time channels - Z
@@ -229,7 +231,6 @@ namespace Mantid
       m_numberOfPixelsPerTube = static_cast<size_t>(data.dim1());
       m_numberOfChannels = static_cast<size_t>(data.dim2());
 
-
     }
 
     /**
@@ -315,7 +316,6 @@ namespace Mantid
       double open_offset = entry.getFloat("instrument/VirtualChopper/open_offset"); /* par1[56] */
       double chop1_speed = entry.getFloat("instrument/VirtualChopper/chopper1_speed_average"); /* PAR2[109] */
 
-
       g_log.debug() << "m_numberOfChannels: " << m_numberOfChannels << std::endl;
       g_log.debug() << "m_channelWidth: " << m_channelWidth << std::endl;
       g_log.debug() << "tof_delay: " << tof_delay << std::endl;
@@ -326,9 +326,8 @@ namespace Mantid
       g_log.debug() << "chop1_speed: " << chop1_speed << std::endl;
 
       // Thanks to Miguel Gonzales/ILL for this TOF formula
-      double t_TOF2 = - 1.e6 * 60.0 * (POFF - 45.0 + mean_chop_2_phase - mean_chop_1_phase + open_offset)
-                                /
-                                (2.0 * 360 * chop1_speed);
+      double t_TOF2 = -1.e6 * 60.0 * (POFF - 45.0 + mean_chop_2_phase - mean_chop_1_phase + open_offset)
+          / (2.0 * 360 * chop1_speed);
 
       g_log.debug() << "t_TOF2: " << t_TOF2 << std::endl;
 
@@ -340,11 +339,10 @@ namespace Mantid
 
         //g_log.debug() << "t_TOF1: " << t_TOF1 << std::endl;
 
-        m_localWorkspace->dataX(0)[timechannelnumber] = t_TOF1 + t_TOF2 ;
+        m_localWorkspace->dataX(0)[timechannelnumber] = t_TOF1 + t_TOF2;
 
       }
 
-
       // Load monitors
       for (size_t im = 0; im < nb_monitors; im++)
       {
@@ -389,8 +387,6 @@ namespace Mantid
 
     }  // LoadILLIndirect::loadDataIntoTheWorkSpace
 
-
-
     void LoadILLReflectometry::loadNexusEntriesIntoProperties(std::string nexusfilename)
     {
 
diff --git a/Code/Mantid/Framework/DataHandling/src/LoadISISNexus2.cpp b/Code/Mantid/Framework/DataHandling/src/LoadISISNexus2.cpp
index e6023d388d54855fa55b568368c888e74e65c0a8..2a353dc165b17bf8f5e06934d6b253aefbe0d8e9 100644
--- a/Code/Mantid/Framework/DataHandling/src/LoadISISNexus2.cpp
+++ b/Code/Mantid/Framework/DataHandling/src/LoadISISNexus2.cpp
@@ -718,7 +718,29 @@ namespace Mantid
       // Run header
       NXChar char_data = vms_compat.openNXChar("HDR");
       char_data.load();
-      runDetails.addProperty("run_header", std::string(char_data(),80));
+
+      // Space-separate the fields
+      char * nxsHdr = char_data();
+      char header[86] = {};
+      const size_t byte = sizeof(char);
+      const char fieldSep(' ');
+      size_t fieldWidths[7] = {3, 5, 20, 24, 12, 8, 8};
+
+      char * srcStart = nxsHdr;
+      char * destStart = header;
+      for(size_t i = 0; i < 7; ++i)
+      {
+        size_t width = fieldWidths[i];
+        memcpy(destStart, srcStart, width*byte);
+        if( i < 6 ) // no space after last field
+        {
+          srcStart += width;
+          destStart += width;
+          memset(destStart, fieldSep, byte); // insert separator
+          destStart += 1;
+        }
+      }
+      runDetails.addProperty("run_header", std::string(header, header + 86));
       
       // Data details on run not the workspace
       runDetails.addProperty("nspectra", static_cast<int>(m_numberOfSpectraInFile));
diff --git a/Code/Mantid/Framework/DataHandling/src/LoadInstrumentFromNexus.cpp b/Code/Mantid/Framework/DataHandling/src/LoadInstrumentFromNexus.cpp
index 232870a02c175c2fa20445834932c8312e63cedc..0c933cc17c06b76dc6f3fe8fe4505140b619bf74 100644
--- a/Code/Mantid/Framework/DataHandling/src/LoadInstrumentFromNexus.cpp
+++ b/Code/Mantid/Framework/DataHandling/src/LoadInstrumentFromNexus.cpp
@@ -75,7 +75,7 @@ void LoadInstrumentFromNexus::exec()
   Geometry::ObjComponent *source = new Geometry::ObjComponent("Unknown",instrument.get());
   instrument->add(source);
   instrument->markAsSource(source);
-  double l1;
+  double l1 = 0.0;
   // If user has provided an L1, use that
   if ( ! Kernel::ConfigService::Instance().getValue("instrument.L1", l1) )
   {
diff --git a/Code/Mantid/Framework/DataHandling/src/LoadLogsForSNSPulsedMagnet.cpp b/Code/Mantid/Framework/DataHandling/src/LoadLogsForSNSPulsedMagnet.cpp
index c7bf66e96e29cf425813c204be23cfe706c781cb..681070c76d27f54b38c1e5dd0846ed66628b7636 100644
--- a/Code/Mantid/Framework/DataHandling/src/LoadLogsForSNSPulsedMagnet.cpp
+++ b/Code/Mantid/Framework/DataHandling/src/LoadLogsForSNSPulsedMagnet.cpp
@@ -241,6 +241,9 @@ struct Pulse
 
     g_log.debug() << "Integration is Over!\n";
 
+    // Clean memory
+    delete[] property;
+
     return;
   }
 
diff --git a/Code/Mantid/Framework/DataHandling/src/LoadMuonNexus.cpp b/Code/Mantid/Framework/DataHandling/src/LoadMuonNexus.cpp
index d6120b4a6811ee144264ecce00dda8fc2a027661..74cbee90106384816bb6a69a9482d339e6f16bf1 100644
--- a/Code/Mantid/Framework/DataHandling/src/LoadMuonNexus.cpp
+++ b/Code/Mantid/Framework/DataHandling/src/LoadMuonNexus.cpp
@@ -124,7 +124,7 @@ namespace Mantid
       }
     }
 
-    /// Run the Child Algorithm LoadInstrument (or LoadInstrumentFromNexus)
+    /// Run the Child Algorithm LoadInstrument 
     void LoadMuonNexus::runLoadInstrument(DataObjects::Workspace2D_sptr localWorkspace)
     {
 
@@ -147,14 +147,12 @@ namespace Mantid
         g_log.information("Unable to successfully run LoadInstrument Child Algorithm");
       }
 
-      // If loading instrument definition file fails, run LoadInstrumentFromNexus instead
-      // This does not work at present as the example files do not hold the necessary data
-      // but is a place holder. Hopefully the new version of Nexus Muon files should be more
-      // complete.
-      if ( ! loadInst->isExecuted() )
-      {
-        runLoadInstrumentFromNexus(localWorkspace);
-      }
+      // If loading instrument definition file fails, 
+	  // we may get instrument by some other means yet to be decided upon
+	  // at present we do nothing.
+      //if ( ! loadInst->isExecuted() )
+      //{
+      //}
     }
 
     /**
diff --git a/Code/Mantid/Framework/DataHandling/src/LoadMuonNexus1.cpp b/Code/Mantid/Framework/DataHandling/src/LoadMuonNexus1.cpp
index 739067b2d1afbf4793e8facb5944ce78cf68c892..264c9437d2a97314103974c5e7c5e6728e999cf3 100644
--- a/Code/Mantid/Framework/DataHandling/src/LoadMuonNexus1.cpp
+++ b/Code/Mantid/Framework/DataHandling/src/LoadMuonNexus1.cpp
@@ -612,36 +612,6 @@ namespace Mantid
       }
     }
 
-    /// Run LoadInstrumentFromNexus as a Child Algorithm (only if loading from instrument definition file fails)
-    void LoadMuonNexus1::runLoadInstrumentFromNexus(DataObjects::Workspace2D_sptr localWorkspace)
-    {
-      g_log.information() << "Instrument definition file not found. Attempt to load information about \n"
-        << "the instrument from nexus data file.\n";
-
-      IAlgorithm_sptr loadInst = createChildAlgorithm("LoadInstrumentFromNexus");
-
-      // Now execute the Child Algorithm. Catch and log any error, but don't stop.
-      bool executionSuccessful(true);
-      try
-      {
-        loadInst->setPropertyValue("Filename", m_filename);
-        loadInst->setProperty<MatrixWorkspace_sptr> ("Workspace", localWorkspace);
-        loadInst->execute();
-      }
-      catch( std::invalid_argument&)
-      {
-        g_log.information("Invalid argument to LoadInstrument Child Algorithm");
-        executionSuccessful = false;
-      }
-      catch (std::runtime_error&)
-      {
-        g_log.information("Unable to successfully run LoadInstrument Child Algorithm");
-        executionSuccessful = false;
-      }
-
-      if ( !executionSuccessful ) g_log.error("No instrument definition loaded");      
-    }
-
     /// Run the LoadLog Child Algorithm
     void LoadMuonNexus1::runLoadLog(DataObjects::Workspace2D_sptr localWorkspace)
     {
diff --git a/Code/Mantid/Framework/DataHandling/src/LoadRaw3.cpp b/Code/Mantid/Framework/DataHandling/src/LoadRaw3.cpp
index cd33dc6131d7fdcc939d8add58d2d645be12dac6..a09ee07e3501459e3658c60b05f15a7f8218a358 100644
--- a/Code/Mantid/Framework/DataHandling/src/LoadRaw3.cpp
+++ b/Code/Mantid/Framework/DataHandling/src/LoadRaw3.cpp
@@ -67,16 +67,18 @@ namespace Mantid
       monitorOptions.push_back("Include");
       monitorOptions.push_back("Exclude");
       monitorOptions.push_back("Separate");
-      monitorOptions.push_back("1");
-      monitorOptions.push_back("0");
-      declareProperty("LoadMonitors","Include", boost::make_shared<StringListValidator>(monitorOptions),
+      std::map<std::string,std::string> monitorOptionsAliases;
+      monitorOptionsAliases["1"] = "Separate";
+      monitorOptionsAliases["0"] = "Exclude";
+      declareProperty("LoadMonitors","Include", boost::make_shared<StringListValidator>(monitorOptions,monitorOptionsAliases),
           "Option to control the loading of monitors.\n"
-      "Allowed options are Include,Exclude, Separate, 1, and 0.\n"
+      "Allowed options are Include,Exclude, Separate.\n"
       "Include:The default is Include option which loads the monitors into the output workspace.\n"
       "Exclude:The Exclude option excludes monitors from the output workspace.\n"
       "Separate:The Separate option loads monitors into a separate workspace called OutputWorkspace_Monitor.\n"
-      "1:  The option introduced to allow compatibility with LoadEventNexus in scripts. Equivalent to Separate.\n"
-      "0:  The option introduced to allow compatibility with LoadEventNexus in scripts. Equivalent to Exclude.\n");
+      "Defined aliases:\n"
+      "1:  Equivalent to Separate.\n"
+      "0:  Equivalent to Exclude.\n");
     }
 
 
diff --git a/Code/Mantid/Framework/DataHandling/src/LoadRawHelper.cpp b/Code/Mantid/Framework/DataHandling/src/LoadRawHelper.cpp
index 798e4cc6211d530ac447ad158ff34a3d872b1d15..eeb48a16931d6c6f3906baa37ed4f8c513354c77 100644
--- a/Code/Mantid/Framework/DataHandling/src/LoadRawHelper.cpp
+++ b/Code/Mantid/Framework/DataHandling/src/LoadRawHelper.cpp
@@ -17,6 +17,7 @@
 #include "LoadRaw/isisraw2.h"
 #include "MantidDataHandling/LoadLog.h"
 #include "MantidDataHandling/LoadAscii.h"
+#include "MantidDataHandling/RawFileInfo.h"
 
 #include <boost/algorithm/string/predicate.hpp>
 #include <boost/date_time/gregorian/gregorian.hpp>
@@ -773,11 +774,10 @@ namespace Mantid
       }      
 
       API::Run& runDetails = localWorkspace->mutableRun();
-      // Run header is stored as consecutive char arrays adding up to a total of 80 bytes in the HDR_STRUCT
-      const std::string run_header(localISISRaw->hdr.inst_abrv, 80);
-      runDetails.addProperty("run_header", run_header);
+
+      runDetails.addProperty("run_header", RawFileInfo::runHeader(*localISISRaw));
       // Run title is stored in a different attribute
-      runDetails.addProperty("run_title", std::string(localISISRaw->r_title,80), true);
+      runDetails.addProperty("run_title", RawFileInfo::runTitle(*localISISRaw), true);
 
       runDetails.addProperty("user_name", std::string(localISISRaw->hdr.hd_user, 20));
       runDetails.addProperty("inst_abrv", std::string(localISISRaw->hdr.inst_abrv, 3));
@@ -820,7 +820,7 @@ namespace Mantid
 
     /// To help transforming date stored in ISIS raw file into iso 8601
     /// @param month
-    ::     /// @return month as string integer e.g. 01
+    /// @return month as string integer e.g. 01
     std::string LoadRawHelper::convertMonthLabelToIntStr(std::string month) const
     {
       std::transform(month.begin(), month.end(), month.begin(), toupper);
diff --git a/Code/Mantid/Framework/DataHandling/src/NexusTester.cpp b/Code/Mantid/Framework/DataHandling/src/NexusTester.cpp
index dc3fc17a6c1c2f143249f30452907eb01bef11f0..64958df0fba5421c6e289c353b2d45b674f0e784 100644
--- a/Code/Mantid/Framework/DataHandling/src/NexusTester.cpp
+++ b/Code/Mantid/Framework/DataHandling/src/NexusTester.cpp
@@ -192,6 +192,7 @@ namespace DataHandling
       g_log.notice() << tim << " to load the file = " << MBperSec << " MB/sec (data), " << MBperSec*CompressionFactor << " MB/sec (file)" << std::endl;
     }
 
+    delete[] fakeData;
   }
 
 
diff --git a/Code/Mantid/Framework/DataHandling/src/ProcessDasNexusLog.cpp b/Code/Mantid/Framework/DataHandling/src/ProcessDasNexusLog.cpp
index da2aa1e73e2a566a63a90d5881ab0af94714cde2..74bc1e5beabbf44b6e4acde6447e9d2684f7b3a4 100644
--- a/Code/Mantid/Framework/DataHandling/src/ProcessDasNexusLog.cpp
+++ b/Code/Mantid/Framework/DataHandling/src/ProcessDasNexusLog.cpp
@@ -23,7 +23,7 @@ namespace DataHandling
   //----------------------------------------------------------------------------------------------
   /** Constructor
    */
-  ProcessDasNexusLog::ProcessDasNexusLog()
+  ProcessDasNexusLog::ProcessDasNexusLog() : Algorithm(), DeprecatedAlgorithm()
   {
   }
     
diff --git a/Code/Mantid/Framework/DataHandling/src/RawFileInfo.cpp b/Code/Mantid/Framework/DataHandling/src/RawFileInfo.cpp
index a2da3291cfaa235e7539be0a9acf392d85ffa53e..67113f58950d82376cd4e782ffc8ca8dae3d322e 100644
--- a/Code/Mantid/Framework/DataHandling/src/RawFileInfo.cpp
+++ b/Code/Mantid/Framework/DataHandling/src/RawFileInfo.cpp
@@ -20,7 +20,72 @@ using namespace Mantid::DataHandling;
 
 DECLARE_ALGORITHM(RawFileInfo)
 
-/// Initialise
+/**
+ * Return the run title from the raw data structure
+ * @param isisRaw A reference to the ISISRAW data structure
+ * @return A string containing the title
+ */
+const std::string RawFileInfo::runTitle(const ISISRAW &isisRaw)
+{
+  return std::string(isisRaw.r_title, 80);
+}
+
+/**
+ * Return the run header from the raw data structure
+ * @param isisRaw A reference to the ISISRAW data structure
+ * @return A string containing the header
+ */
+const std::string RawFileInfo::runHeader(const ISISRAW &isisRaw)
+{
+  // coverity doesn't like assuming that the whole hdr struct
+  // has each array of characters laid out consecutively in memory
+  // so we shouldn't just do:
+  // header(isis_raw.hdr.hd_run, 69) to pull out everything
+
+  // Separate each section with a character. 80 chars + 6 separators
+  const auto & rawHdr = isisRaw.hdr;
+  char header[86] = {};
+  const size_t byte = sizeof(char);
+  const char fieldSep(' ');
+  char * start = header;
+
+  memcpy(start, rawHdr.inst_abrv, 3*byte);
+  start += 3;
+  memset(start, fieldSep, byte); // insert separator
+  start += 1;
+
+  memcpy(start, rawHdr.hd_run, 5*byte);
+  start += 5;
+  memset(start, fieldSep, byte);
+  start += 1;
+
+  memcpy(start, rawHdr.hd_user, 20*byte);
+  start += 20;
+  memset(start, fieldSep, byte);
+  start += 1;
+
+  memcpy(start, rawHdr.hd_title, 24*byte);
+  start += 24;
+  memset(start, fieldSep, byte);
+  start += 1;
+
+  memcpy(start, rawHdr.hd_date, 12*byte);
+  start += 12;
+  memset(start, fieldSep, byte);
+  start += 1;
+
+  memcpy(start, rawHdr.hd_time, 8*byte);
+  start += 8;
+  memset(start, fieldSep, byte);
+  start += 1;
+
+  memcpy(start, rawHdr.hd_dur, 8*byte);
+  // final field so no space afterward
+
+  return std::string(header, header + 86);
+}
+
+/// Create properties
 void RawFileInfo::init()
 {
   std::vector<std::string> exts;
@@ -48,15 +113,9 @@ void RawFileInfo::exec()
     throw Exception::FileError("Unable to open File:", filename);
   }
   
-  const std::string title(isis_raw.r_title,80);
-
-  //  First get the general information about the run
-  std::string header(isis_raw.hdr.hd_run, 69);
-  // Insert some spaces to tidy the string up a bit
-  header.insert(5, " ");
-  header.insert(26, " ");
-  header.insert(51, " ");
-  
+  const std::string title = RawFileInfo::runTitle(isis_raw);
+  const std::string header = RawFileInfo::runHeader(isis_raw);
+
   g_log.debug() << "Properties retrieved from " << filename << "\n"
 		<< "\tRun title: " << title
 		<< "\n\tRun header: " << header << "\n";
diff --git a/Code/Mantid/Framework/DataHandling/src/SaveAscii.cpp b/Code/Mantid/Framework/DataHandling/src/SaveAscii.cpp
index 0874bac65b43b3431513bf00cc89dac945015688..de426569fb8d01fb055ba67df7f571a7c930e5d3 100644
--- a/Code/Mantid/Framework/DataHandling/src/SaveAscii.cpp
+++ b/Code/Mantid/Framework/DataHandling/src/SaveAscii.cpp
@@ -73,6 +73,8 @@ namespace Mantid
 
       declareProperty("ColumnHeader", true, "If true, put column headers into file. ");
 
+      declareProperty("ICEFormat", false, "If true, special column headers for ICE in file. ");
+
     }
 
     /** 
@@ -114,6 +116,20 @@ namespace Mantid
           sep = " , ";
         }
         std::string comment = getPropertyValue("CommentIndicator");
+        std::string errstr = "E";
+        std::string errstr2 = "";
+        std::string comstr = " , ";
+        bool ice = getProperty("ICEFormat");
+        if (ice)
+        {
+        	// overwrite properties so file can be read by ICE
+        	errstr = "Y";
+        	errstr2 = "_error";
+        	comstr = ", ";
+        	writeHeader = true;
+        	write_dx = false;
+        	comment = "#features:";
+        }
 
         // Create an spectra index list for output
         std::set<int> idx;
@@ -153,13 +169,13 @@ namespace Mantid
           if (idx.empty())
             for(int spec=0;spec<nSpectra;spec++)
             {
-              file << " , Y" << spec << " , E" << spec;
+              file << comstr << "Y" << spec << comstr << errstr << spec << errstr2;
               if (write_dx) file << " , DX" << spec;
             }
           else
             for(std::set<int>::const_iterator spec=idx.begin();spec!=idx.end();++spec)
             {
-              file << " , Y" << *spec << " , E" << *spec;
+              file << comstr << "Y" << *spec << comstr << errstr << *spec << errstr2;
               if (write_dx) file << " , DX" << *spec;
             }
             file << std::endl;
diff --git a/Code/Mantid/Framework/DataHandling/src/SaveAscii2.cpp b/Code/Mantid/Framework/DataHandling/src/SaveAscii2.cpp
index 9b87eda6bd39533da38e6b2e97c273fde60377c1..f5d2bb8ee328f577d926ceffb467834976012050 100644
--- a/Code/Mantid/Framework/DataHandling/src/SaveAscii2.cpp
+++ b/Code/Mantid/Framework/DataHandling/src/SaveAscii2.cpp
@@ -78,6 +78,8 @@ namespace Mantid
 
       declareProperty("ColumnHeader", true, "If true, put column headers into file. ");
 
+      declareProperty("AppendToFile", false, "If true, don't overwrite the file. Append to the end of it. ");
+
     }
 
     /** 
@@ -98,6 +100,7 @@ namespace Mantid
       int spec_min = getProperty("WorkspaceIndexMin");
       int spec_max = getProperty("WorkspaceIndexMax");
       bool writeHeader = getProperty("ColumnHeader");
+      bool appendToFile = getProperty("AppendToFile");
 
       // Check whether we need to write the fourth column
       m_writeDX = getProperty("WriteXError");
@@ -177,7 +180,7 @@ namespace Mantid
         throw std::runtime_error("Trying to save an empty workspace");
       }
       std::string filename = getProperty("Filename");
-      std::ofstream file(filename.c_str());
+      std::ofstream file(filename.c_str(), (appendToFile ? std::ios::app : std::ios::out));
 
       if (!file)
       {
@@ -250,7 +253,7 @@ namespace Mantid
           file << m_ws->readX(0)[bin];
         }
         file << m_sep;
-        file << m_ws->readY(*spectraItr)[bin];                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 
+        file << m_ws->readY(*spectraItr)[bin];
         file << m_sep;
         file << m_ws->readE(*spectraItr)[bin];
         if (m_writeDX)
diff --git a/Code/Mantid/Framework/DataHandling/src/SaveGSS.cpp b/Code/Mantid/Framework/DataHandling/src/SaveGSS.cpp
index ddc5f771c59729803dcc159f11f3ce773c33791d..9a10662a35d948e040fc11947214baa8b0ebc0b7 100644
--- a/Code/Mantid/Framework/DataHandling/src/SaveGSS.cpp
+++ b/Code/Mantid/Framework/DataHandling/src/SaveGSS.cpp
@@ -15,228 +15,312 @@
 
 namespace Mantid
 {
-  namespace DataHandling
+namespace DataHandling
+{
+
+  using namespace Mantid::API;
+
+  // Register the algorithm into the AlgorithmFactory
+  DECLARE_ALGORITHM(SaveGSS)
+
+  const std::string RALF("RALF");
+  const std::string SLOG("SLOG");
+
+  //---------------------------------------------------
+  // Private member functions
+  //---------------------------------------------------
+  /** Initialise the algorithm
+    */
+  void SaveGSS::init()
   {
+    // Data must be in TOF
+    declareProperty(new API::WorkspaceProperty<>("InputWorkspace", "", Kernel::Direction::Input,
+                                                 boost::make_shared<API::WorkspaceUnitValidator>("TOF")),
+                    "The input workspace, which must be in time-of-flight");
+    declareProperty(new API::FileProperty("Filename", "", API::FileProperty::Save),
+                    "The filename to use for the saved data");
+    declareProperty("SplitFiles", true,
+                    "Whether to save each spectrum into a separate file ('true') or not ('false'). "
+                    "Note that this is a string, not a boolean property.");
+    declareProperty("Append", true, "If true and Filename already exists, append, else overwrite ");
+    declareProperty("Bank", 1,
+                    "The bank number to include in the file header for the first spectrum, "
+                    "i.e., the starting bank number. "
+                    "This will increment for each spectrum or group member. ");
+    std::vector<std::string> formats;
+    formats.push_back(RALF);
+    formats.push_back(SLOG);
+    declareProperty("Format", RALF, boost::make_shared<Kernel::StringListValidator>(formats), "GSAS format to save as");
+    declareProperty("MultiplyByBinWidth", true,
+                    "Multiply the intensity (Y) by the bin width; default TRUE.");
+    declareProperty("ExtendedHeader", false, "Add information to the header about iparm file and normalization");
+
+    declareProperty("UseSpectrumNumberAsBankID", false, "If true, then each bank's bank ID is equal to the spectrum number; "
+                    "otherwise, the continous bank IDs are applied. ");
+  }
+
+  //----------------------------------------------------------------------------------------------
+  /** Determine the focused position for the supplied spectrum. The position
+   * (l1, l2, tth) is returned via the references passed in.
+   */
+  void getFocusedPos(MatrixWorkspace_const_sptr wksp, const int spectrum, double &l1, double &l2,
+                     double &tth, double& difc)
+  {
+    Geometry::Instrument_const_sptr instrument = wksp->getInstrument();
+    if (instrument == NULL)
+    {
+      l1 = 0.;
+      l2 = 0.;
+      tth = 0.;
+      return;
+    }
+    Geometry::IComponent_const_sptr source = instrument->getSource();
+    Geometry::IComponent_const_sptr sample = instrument->getSample();
+    if (source == NULL || sample == NULL)
+    {
+      l1 = 0.;
+      l2 = 0.;
+      tth = 0.;
+      return;
+    }
+    l1 = source->getDistance(*sample);
+    Geometry::IDetector_const_sptr det = wksp->getDetector(spectrum);
+    if (!det)
+    {
+      std::stringstream errss;
+      errss << "Workspace " << wksp->name() << " does not have detector with spectrum "
+            << spectrum;
+      throw std::runtime_error(errss.str());
+    }
+    l2 = det->getDistance(*sample);
+    tth = wksp->detectorTwoTheta(det);
 
-    using namespace API;
+    difc = ((2.0 * PhysicalConstants::NeutronMass * sin(tth / 2.0) * (l1 + l2))
+            / (PhysicalConstants::h * 1e4));
 
-    // Register the algorithm into the AlgorithmFactory
-    DECLARE_ALGORITHM(SaveGSS)
+    return;
+  }
 
-    const std::string RALF("RALF");
-    const std::string SLOG("SLOG");
+  //----------------------------------------------------------------------------------------------
+  /** Execute the algorithm
+    */
+  void SaveGSS::exec()
+  {
+    // Process properties
+    // Retrieve the input workspace
+    inputWS = getProperty("InputWorkspace");
 
-    //---------------------------------------------------
-    // Private member functions
-    //---------------------------------------------------
-    /**
-     * Initialise the algorithm
-     */
-    void SaveGSS::init()
+    // Check whether it is PointData or Histogram
+    if (!inputWS->isHistogramData())
+      g_log.warning("Input workspace is NOT histogram!  SaveGSS may not work well with PointData.");
+
+    // Check the number of histogram/spectra < 99
+    const int nHist = static_cast<int> (inputWS->getNumberHistograms());
+    if (nHist > 99)
     {
-      // Data must be in TOF
-      declareProperty(new API::WorkspaceProperty<>("InputWorkspace", "", Kernel::Direction::Input,
-                                                   boost::make_shared<API::WorkspaceUnitValidator>("TOF")),
-          "The input workspace, which must be in time-of-flight");
-      declareProperty(new API::FileProperty("Filename", "", API::FileProperty::Save),
-          "The filename to use for the saved data");
-      declareProperty("SplitFiles", true,
-          "Whether to save each spectrum into a separate file ('true') or not ('false'). Note that this is a string, not a boolean property.");
-      declareProperty("Append", true, "If true and Filename already exists, append, else overwrite ");
-      declareProperty(
-          "Bank",
-          1,
-          "The bank number to include in the file header for the first spectrum. This will increment for each spectrum or group member.");
-      std::vector<std::string> formats;
-      formats.push_back(RALF);
-      formats.push_back(SLOG);
-      declareProperty("Format", RALF, boost::make_shared<Kernel::StringListValidator>(formats), "GSAS format to save as");
-      declareProperty("MultiplyByBinWidth", true,
-          "Multiply the intensity (Y) by the bin width; default TRUE.");
-      declareProperty("ExtendedHeader", false, "Add information to the header about iparm file and normalization");
-
-      declareProperty("UseSpectrumNumberAsBankID", false, "If true, then each bank's bank ID is equal to the spectrum number; "
-                      "otherwise, the continous bank IDs are applied. ");
+      std::stringstream errss;
+      errss << "Number of Spectra ("<< nHist<<") cannot be larger than 99 for GSAS file";
+      g_log.error(errss.str());
+      throw new std::invalid_argument(errss.str());
     }
 
-    /**
-     * Determine the focused position for the supplied spectrum. The position
-     * (l1, l2, tth) is returned via the references passed in.
-     */
-    void getFocusedPos(MatrixWorkspace_const_sptr wksp, const int spectrum, double &l1, double &l2,
-        double &tth)
+    std::string filename = getProperty("Filename");
+
+    const int bank = getProperty("Bank");
+    const bool MultiplyByBinWidth = getProperty("MultiplyByBinWidth");
+    bool split = getProperty("SplitFiles");
+
+    std::string outputFormat = getProperty("Format");
+
+    m_useSpecAsBank = getProperty("UseSpectrumNumberAsBankID");
+
+    // Check whether to append to an already existing file or overwrite
+    bool append = getProperty("Append");
+
+    // Check whether append or not
+    if (!split)
     {
-      Geometry::Instrument_const_sptr instrument = wksp->getInstrument();
-      if (instrument == NULL)
+      const std::string file(filename);
+      Poco::File fileobj(file);
+      if (fileobj.exists() && !append)
       {
-        l1 = 0.;
-        l2 = 0.;
-        tth = 0.;
-        return;
+        // Non-append mode and will be overwritten
+        g_log.warning() << "Target GSAS file " << filename << " exists and will be overwritten. " << "\n";
       }
-      Geometry::IComponent_const_sptr source = instrument->getSource();
-      Geometry::IComponent_const_sptr sample = instrument->getSample();
-      if (source == NULL || sample == NULL)
+      else if (!fileobj.exists() && append)
       {
-        l1 = 0.;
-        l2 = 0.;
-        tth = 0.;
-        return;
+        // File does not exist but in append mode
+        g_log.warning() << "Target GSAS file " << filename << " does not exist.  Append mode is set to false "
+                        << "\n";
+        append = false;
       }
-      l1 = source->getDistance(*sample);
-      Geometry::IDetector_const_sptr det = wksp->getDetector(spectrum);
-      l2 = det->getDistance(*sample);
-      tth = wksp->detectorTwoTheta(det);
     }
 
-    /**
-     * Execute the algorithm
-     */
-    void SaveGSS::exec()
+    writeGSASFile(filename, append, bank, MultiplyByBinWidth, split, outputFormat);
+
+    return;
+  }
+
+  //----------------------------------------------------------------------------------------------
+  /** Write GSAS file based on user-specified request
+    */
+  void SaveGSS::writeGSASFile(const std::string& outfilename, bool append, int basebanknumber,
+                              bool multiplybybinwidth,  bool split, const std::string& outputFormat)
+  {
+    // Initialize the file stream
+    using std::ios_base;
+    ios_base::openmode mode = (append ? (ios_base::out | ios_base::app) : ios_base::out);
+
+    // Instrument related
+    Geometry::Instrument_const_sptr instrument = inputWS->getInstrument();
+    Geometry::IComponent_const_sptr source;
+    Geometry::IComponent_const_sptr sample;
+    bool has_instrument = false;
+    if (instrument != NULL)
     {
-      using namespace Mantid::API;
-      //Retrieve the input workspace
-      MatrixWorkspace_const_sptr inputWS = getProperty("InputWorkspace");
-      const int nHist = static_cast<int> (inputWS->getNumberHistograms());
+      source = instrument->getSource();
+      sample = instrument->getSample();
+      if (source && sample)
+        has_instrument = true;
+    }
+
+    // Write GSAS file for each histogram (spectrum)
+    std::stringstream outbuffer;
+
+    int nHist = static_cast<int>(inputWS->getNumberHistograms());
+    Progress p(this, 0.0, 1.0, nHist);
 
-      // Check the number of histogram/spectra < 99
-      if (nHist > 99)
+
+    for (int iws = 0; iws < nHist; iws++)
+    {
+      // Determine whether to skip the spectrum due to being masked
+      if (has_instrument)
       {
-        g_log.error() << "Number of Spectra ("<< nHist<<") cannot be larger than 99 for GSAS file" << std::endl;
-        throw new std::invalid_argument("Workspace has more than the 99 spectra, allowed by GSAS");
+        try
+        {
+          Geometry::IDetector_const_sptr det = inputWS->getDetector(static_cast<size_t> (iws));
+          if (det->isMasked())
+            continue;
+        }
+        catch(const Kernel::Exception::NotFoundError& )
+        {
+          has_instrument = false;
+          g_log.warning() << "There is no detector associated with spectrum " << iws
+                          << ". Workspace is treated as NO-INSTRUMENT case. \n";
+        }
       }
 
-      std::string filename = getProperty("Filename");
+      // Obtain detector information
+      double l1, l2, tth, difc;
+      if (has_instrument)
+        getFocusedPos(inputWS, iws, l1, l2, tth, difc);
+      else
+        l1 = l2 = tth = difc = 0;
+      g_log.debug() << "Spectrum " << iws << ": L1 = " << l1 << "  L2 = " << l2 << "  2theta = " << tth << "\n";
 
-      const int bank = getProperty("Bank");
-      const bool MultiplyByBinWidth = getProperty("MultiplyByBinWidth");
-      const bool split = getProperty("SplitFiles");
-      std::string outputFormat = getProperty("Format");
+      std::stringstream tmpbuffer;
 
-      m_useSpecAsBank = getProperty("UseSpectrumNumberAsBankID");
+      // Header: 2 cases requires header: (1) first bank in non-append mode and (2) split
+      g_log.notice() << "[DB9933] Append = " << append << ", split = " << split << "\n";
 
-      std::ostringstream number;
-      std::ofstream out;
-      // Check whether to append to an already existing file or overwrite
-      const bool append = getProperty("Append");
-      using std::ios_base;
-      ios_base::openmode mode = (append ? (ios_base::out | ios_base::app) : ios_base::out);
-      Progress p(this, 0.0, 1.0, nHist);
-      double l1, l2, tth;
-      Geometry::Instrument_const_sptr instrument = inputWS->getInstrument();
-      Geometry::IComponent_const_sptr source;
-      Geometry::IComponent_const_sptr sample;
-      if (instrument != NULL)
+      bool writeheader = false;
+      std::string splitfilename("");
+      if (!split && iws == 0 && !append)
       {
-        source = instrument->getSource();
-        sample = instrument->getSample();
+        // Non-split mode and first spectrum and in non-append mode
+        writeheader = true;
       }
-
-      // Write GSAS file for each histogram (spectrum)
-      for (int i = 0; i < nHist; i++)
+      else if (split)
       {
-        if (instrument != NULL)
-        {
-          if (source != NULL && sample != NULL)
-          {
-            Geometry::IDetector_const_sptr det = inputWS->getDetector(static_cast<size_t> (i));
-            if (det->isMasked())
-              continue;
-          }
-        }
-        getFocusedPos(inputWS, i, l1, l2, tth);
-        g_log.information() << "L1 = " << l1 << "  L2 = " << l2 << "  2theta = " << tth << std::endl;
+        std::stringstream number;
+        number << "-" << iws;
+
+        Poco::Path path(outfilename);
+        std::string basename = path.getBaseName(); // Filename minus extension
+        std::string ext = path.getExtension();
+        // Chop off filename
+        path.makeParent();
+        path.append(basename + number.str() + "." + ext);
+        Poco::File fileobj(path);
+        const bool exists = fileobj.exists();
+        if (!exists || !append)
+          writeheader = true;
+        if (fileobj.exists() && !append)
+          g_log.warning() << "File " << path.getFileName() << " exists and will be overwritten." << "\n";
+        splitfilename = path.toString();
+      }
 
-        // Write Header
-        // If NOT split, only write to first histogram
-        // If     split, write to each histogram
-        if (!split && i == 0) // Assign only one file
-        {
-          const std::string file(filename);
-          Poco::File fileobj(file);
-          const bool exists = fileobj.exists();
-          out.open(file.c_str(), mode);
-          if (!exists || !append)
-            writeHeaders(outputFormat, out, inputWS, l1);
+      // Create header
+      if ( writeheader )
+        writeHeaders(outputFormat, tmpbuffer, l1);
 
-        }
-        else if (split)//Several files will be created with names: filename-i.ext
-        {
-          // New number
-          number << "-" << i;
-
-          Poco::Path path(filename);
-          std::string basename = path.getBaseName(); // Filename minus extension
-          std::string ext = path.getExtension();
-          // Chop off filename
-          path.makeParent();
-          path.append(basename + number.str() + "." + ext);
-          Poco::File fileobj(path);
-          const bool exists = fileobj.exists();
-          out.open(path.toString().c_str(), mode);
-          number.str("");
-          if (!exists || !append)
-            writeHeaders(outputFormat, out, inputWS, l1);
-        }
+      // Write bank header
+      if (has_instrument)
+      {
+        tmpbuffer << "# Total flight path " << (l1 + l2) << "m, tth " << (tth * 180. / M_PI)
+                  << "deg, DIFC " << difc << "\n";
+      }
+      tmpbuffer << "# Data for spectrum :" << iws << "\n";
 
-        { // New scope
-          if (!out.is_open())
-          {
-            throw std::runtime_error("Could not open filename: " + filename);
-          }
-
-          if (l1 != 0. || l2 != 0. || tth != 0.)
-          {
-            out << "# Total flight path " << (l1 + l2) << "m, tth " << (tth * 180. / M_PI)
-                << "deg, DIFC " << ((2.0 * PhysicalConstants::NeutronMass * sin(tth / 2.0) * (l1 + l2))
-                / (PhysicalConstants::h * 1e4)) << "\n";
-          }
-          out << "# Data for spectrum :" << i << std::endl;
-
-          int bankid;
-          if (m_useSpecAsBank)
-          {
-            bankid = static_cast<int>(inputWS->getSpectrum(i)->getSpectrumNo());
-          }
-          else
-          {
-            bankid = bank + i;
-          }
-
-          if (RALF.compare(outputFormat) == 0)
-          {
-            this->writeRALFdata(bankid, MultiplyByBinWidth, out, inputWS->readX(i), inputWS->readY(i),
-                inputWS->readE(i));
-          }
-          else if (SLOG.compare(outputFormat) == 0)
-          {
-            this->writeSLOGdata(bankid, MultiplyByBinWidth, out, inputWS->readX(i), inputWS->readY(i),
-                inputWS->readE(i));
-          }
-          else
-          {
-            throw std::runtime_error("Cannot write to the unknown " +  outputFormat + "output format"); 
-          }
-
-        } // End separate scope
-
-        //Close at each iteration
-        if (split)
-        {
-          out.close();
-        }
-        p.report();
-      } // for nHist
+      // Determine bank number into GSAS file
+      int bankid;
+      if (m_useSpecAsBank)
+      {
+        bankid = static_cast<int>(inputWS->getSpectrum(iws)->getSpectrumNo());
+      }
+      else
+      {
+        bankid = basebanknumber + iws;
+      }
+
+      // Write data
+      if (RALF.compare(outputFormat) == 0)
+      {
+        this->writeRALFdata(bankid, multiplybybinwidth, tmpbuffer, inputWS->readX(iws), inputWS->readY(iws),
+                            inputWS->readE(iws));
+      }
+      else if (SLOG.compare(outputFormat) == 0)
+      {
+        this->writeSLOGdata(bankid, multiplybybinwidth, tmpbuffer, inputWS->readX(iws), inputWS->readY(iws),
+                            inputWS->readE(iws));
+      }
+      else
+      {
+        throw std::runtime_error("Cannot write to the unknown " +  outputFormat + "output format");
+      }
 
-      // Close if single file
-      if (!split)
+      // Write out to file if necessary
+      if (split)
       {
+        // Create a new file name and a new file with ofstream
+        std::ofstream out;
+        out.open(splitfilename.c_str(), mode);
+        out.write(tmpbuffer.str().c_str(), tmpbuffer.str().size());
         out.close();
       }
-      return;
+      else
+      {
+        outbuffer << tmpbuffer.str();
+      }
+
+      p.report();
+
+    } // ENDFOR (iws)
+
+    // Write file
+    if (!split)
+    {
+      std::ofstream out;
+      out.open(outfilename.c_str(), mode);
+      out.write(outbuffer.str().c_str(), outbuffer.str().length());
+      out.close();
     }
 
-    /** Ensures that when a workspace group is passed as output to this workspace
+    return;
+  }
+
+  //----------------------------------------------------------------------------------------------
+  /** Ensures that when a workspace group is passed as output to this workspace
      *  everything is saved to one file and the bank number increments for each
      *  group member.
      *  @param alg ::           Pointer to the algorithm
@@ -244,250 +328,281 @@ namespace Mantid
      *  @param propertyValue :: Value  of the property
      *  @param periodNum ::     Effectively a counter through the group members
      */
-    void SaveGSS::setOtherProperties(IAlgorithm* alg, const std::string& propertyName,
-        const std::string& propertyValue, int periodNum)
+  void SaveGSS::setOtherProperties(IAlgorithm* alg, const std::string& propertyName,
+                                   const std::string& propertyValue, int periodNum)
+  {
+    // We want to append subsequent group members to the first one
+    if (propertyName == "Append")
     {
-      // We want to append subsequent group members to the first one
-      if (propertyName == "Append")
+      if (periodNum != 1)
       {
-        if (periodNum != 1)
-        {
-          alg->setPropertyValue(propertyName, "1");
-        }
-        else
-          alg->setPropertyValue(propertyName, propertyValue);
-      }
-      // We want the bank number to increment for each member of the group
-      else if (propertyName == "Bank")
-      {
-        alg->setProperty("Bank", atoi(propertyValue.c_str()) + periodNum - 1);
+        alg->setPropertyValue(propertyName, "1");
       }
       else
-        Algorithm::setOtherProperties(alg, propertyName, propertyValue, periodNum);
+        alg->setPropertyValue(propertyName, propertyValue);
+    }
+    // We want the bank number to increment for each member of the group
+    else if (propertyName == "Bank")
+    {
+      alg->setProperty("Bank", atoi(propertyValue.c_str()) + periodNum - 1);
+    }
+    else
+      Algorithm::setOtherProperties(alg, propertyName, propertyValue, periodNum);
+  }
+
+  //----------------------------------------------------------------------------------------------
+  /** Write value from a RunInfo property (i.e., log) to a stream
+      */
+  void writeLogValue(std::ostream &os, const Run& runinfo, const std::string& name, const std::string& defValue="UNKNOWN")
+  {
+    // Return without property exists
+    if (!runinfo.hasProperty(name))
+    {
+      os << defValue;
+      return;
     }
 
-    void writeValue(std::ostream &os, const Run& runinfo, const std::string& name, const std::string& defValue="UNKNOWN")
+    // Get handler of property
+    Kernel::Property* prop = runinfo.getProperty(name);
+
+    // Return without a valid pointer to property
+    if (prop == NULL)
     {
-      if (!runinfo.hasProperty(name))
-      {
-        os << defValue;
-        return;
-      }
-      Kernel::Property* prop = runinfo.getProperty(name);
-      if (prop == NULL)
-      {
-        os << defValue;
-        return;
-      }
-      Kernel::TimeSeriesProperty<double> *log =
-          dynamic_cast<Kernel::TimeSeriesProperty<double> *> (prop);
-      if (log != NULL)
-      {
-        os << log->getStatistics().mean;
-      }
-      else
-      {
-        os << prop->value();
-      }
-      std::string units = prop->units();
-      if (!units.empty())
-        os << " " << units;
+      os << defValue;
+      return;
+    }
+
+    // Get value
+    Kernel::TimeSeriesProperty<double> *log =
+        dynamic_cast<Kernel::TimeSeriesProperty<double> *> (prop);
+    if (log)
+    {
+      // Time series to get mean
+      os << log->getStatistics().mean;
+    }
+    else
+    {
+      // None time series
+      os << prop->value();
     }
 
-    /**
-     * Write the header information for the given workspace
+    // Unit
+    std::string units = prop->units();
+    if (!units.empty())
+      os << " " << units;
+
+    return;
+  }
+
+  //--------------------------------------------------------------------------------------------
+  /** Write the header information, which is independent of bank, from the given workspace
      * @param format :: The string containing the header formatting
      * @param os :: The stream to use to write the information
-     * @param workspace :: A shared pointer to MatrixWorkspace
      * @param primaryflightpath :: Value for the moderator to sample distance
      */
-    void SaveGSS::writeHeaders(const std::string &format, std::ostream& os,
-        Mantid::API::MatrixWorkspace_const_sptr& workspace, double primaryflightpath) const
+  void SaveGSS::writeHeaders(const std::string &format, std::stringstream& os,
+                             double primaryflightpath) const
+  {
+    const Run& runinfo = inputWS->run();
+
+    // Run number
+    if (format.compare(SLOG) == 0)
     {
-      const Run& runinfo = workspace->run();
-      if (format.compare(SLOG) == 0)
-      {
-        os << "Sample Run: ";
-        writeValue(os, runinfo, "run_number");
-        os << " Vanadium Run: ";
-        writeValue(os, runinfo, "van_number");
-        os << " Wavelength: ";
-        writeValue(os, runinfo, "LambdaRequest");
-        os << "\n";
-      }
+      os << "Sample Run: ";
+      writeLogValue(os, runinfo, "run_number");
+      os << " Vanadium Run: ";
+      writeLogValue(os, runinfo, "van_number");
+      os << " Wavelength: ";
+      writeLogValue(os, runinfo, "LambdaRequest");
+      os << "\n";
+    }
 
-      if (this->getProperty("ExtendedHeader"))
+    if (this->getProperty("ExtendedHeader"))
+    {
+      // the instrument parameter file
+      if (runinfo.hasProperty("iparm_file"))
       {
-        // the instrument parameter file
-        if (runinfo.hasProperty("iparm_file"))
+        Kernel::Property* prop = runinfo.getProperty("iparm_file");
+        if (prop != NULL && (!prop->value().empty()))
         {
-          Kernel::Property* prop = runinfo.getProperty("iparm_file");
-          if (prop != NULL && (!prop->value().empty()))
-          {
-            std::stringstream line;
-            line << "#Instrument parameter file: "
-                 << prop->value();
-            os << std::setw(80) << std::left << line.str() << "\n";
-          }
+          std::stringstream line;
+          line << "#Instrument parameter file: "
+               << prop->value();
+          os << std::setw(80) << std::left << line.str() << "\n";
         }
-
-        // write out the gsas monitor counts
-        os << "Monitor: ";
-        if (runinfo.hasProperty("gsas_monitor"))
-        {
-          writeValue(os, runinfo, "gsas_monitor");
-        }
-        else
-        {
-          writeValue(os, runinfo, "gd_prtn_chrg", "1");
-        }
-        os << "\n";
       }
 
-      if (format.compare(SLOG) == 0)
+      // write out the gsas monitor counts
+      os << "Monitor: ";
+      if (runinfo.hasProperty("gsas_monitor"))
       {
-        os << "# "; // make the next line a comment
+        writeLogValue(os, runinfo, "gsas_monitor");
       }
-      os << workspace->getTitle() << "\n";
-      os << "# " << workspace->getNumberHistograms() << " Histograms\n";
-      os << "# File generated by Mantid:\n";
-      os << "# Instrument: " << workspace->getInstrument()->getName() << "\n";
-      os << "# From workspace named : " << workspace->getName() << "\n";
-      if (getProperty("MultiplyByBinWidth"))
-        os << "# with Y multiplied by the bin widths.\n";
-      os << "# Primary flight path " << primaryflightpath << "m \n";
-      if (format.compare(SLOG) == 0)
+      else
       {
-        os << "# Sample Temperature: ";
-        writeValue(os, runinfo, "SampleTemp");
-        os << " Freq: ";
-        writeValue(os, runinfo, "SpeedRequest1");
-        os << " Guide: ";
-        writeValue(os, runinfo, "guide");
-        os << "\n";
-
-        // print whether it is normalized by monitor or pcharge
-        bool norm_by_current = false;
-        bool norm_by_monitor = false;
-        const Mantid::API::AlgorithmHistories& algohist = workspace->getHistory().getAlgorithmHistories();
-        for (Mantid::API::AlgorithmHistories::const_iterator it = algohist.begin(); it != algohist.end(); ++it)
-        {
-          if ((*it)->name().compare("NormaliseByCurrent") == 0)
-            norm_by_current = true;
-          if ((*it)->name().compare("NormaliseToMonitor") == 0)
-            norm_by_monitor = true;
-        }
-        os << "#";
-        if (norm_by_current)
-          os << " Normalised to pCharge";
-        if (norm_by_monitor)
-          os << " Normalised to monitor";
-        os << "\n";
+        writeLogValue(os, runinfo, "gd_prtn_chrg", "1");
       }
-
-      return;
+      os << "\n";
     }
 
-    inline void writeBankLine(std::ostream& out, const std::string& bintype, const int banknum,
-        const size_t datasize)
+    if (format.compare(SLOG) == 0)
     {
-      out << "BANK " << std::fixed << std::setprecision(0) << banknum // First bank should be 1 for GSAS; this can be changed
-          << std::fixed << " " << datasize << std::fixed << " " << datasize << std::fixed << " "
-          << bintype;
+      os << "# "; // make the next line a comment
     }
-
-    inline double fixErrorValue(const double value)
+    os << inputWS->getTitle() << "\n";
+    os << "# " << inputWS->getNumberHistograms() << " Histograms\n";
+    os << "# File generated by Mantid:\n";
+    os << "# Instrument: " << inputWS->getInstrument()->getName() << "\n";
+    os << "# From workspace named : " << inputWS->getName() << "\n";
+    if (getProperty("MultiplyByBinWidth"))
+      os << "# with Y multiplied by the bin widths.\n";
+    os << "# Primary flight path " << primaryflightpath << "m \n";
+    if (format.compare(SLOG) == 0)
     {
-      if (value <= 0. || boost::math::isnan(value) || boost::math::isinf(value)) //Negative errors cannot be read by GSAS
-        return 0.;
-      else
-        return value;
-    }
-
-    void SaveGSS::writeRALFdata(const int bank, const bool MultiplyByBinWidth, std::ostream& out,
-        const MantidVec& X, const MantidVec& Y, const MantidVec& E) const
-    {
-      const size_t datasize = Y.size();
-      double bc1 = X[0] * 32;
-      double bc2 = (X[1] - X[0]) * 32;
-      // Logarithmic step
-      double bc4 = (X[1] - X[0]) / X[0];
-      if (boost::math::isnan(fabs(bc4)) || boost::math::isinf(bc4))
-        bc4 = 0; //If X is zero for BANK
-
-      //Write out the data header
-      writeBankLine(out, "RALF", bank, datasize);
-      out << std::fixed << " " << std::setprecision(0) << std::setw(8) << bc1 << std::fixed << " "
-          << std::setprecision(0) << std::setw(8) << bc2 << std::fixed << " " << std::setprecision(0)
-          << std::setw(8) << bc1 << std::fixed << " " << std::setprecision(5) << std::setw(7) << bc4
-          << " FXYE" << std::endl;
-
-      //Do each Y entry
-      for (size_t j = 0; j < datasize; j++)
+      os << "# Sample Temperature: ";
+      writeLogValue(os, runinfo, "SampleTemp");
+      os << " Freq: ";
+      writeLogValue(os, runinfo, "SpeedRequest1");
+      os << " Guide: ";
+      writeLogValue(os, runinfo, "guide");
+      os << "\n";
+
+      // print whether it is normalized by monitor or pcharge
+      bool norm_by_current = false;
+      bool norm_by_monitor = false;
+      const Mantid::API::AlgorithmHistories& algohist = inputWS->getHistory().getAlgorithmHistories();
+      for (Mantid::API::AlgorithmHistories::const_iterator it = algohist.begin(); it != algohist.end(); ++it)
       {
-        //Calculate the error
-        double Epos;
-        if (MultiplyByBinWidth)
-          Epos = E[j] * (X[j + 1] - X[j]); // E[j]*X[j]*bc4;
-        else
-          Epos = E[j];
-        Epos = fixErrorValue(Epos);
-
-        //The center of the X bin.
-        out << std::fixed << std::setprecision(5) << std::setw(15) << 0.5 * (X[j] + X[j + 1]);
-
-        // The Y value
-        if (MultiplyByBinWidth)
-          out << std::fixed << std::setprecision(8) << std::setw(18) << Y[j] * (X[j + 1] - X[j]);
-        else
-          out << std::fixed << std::setprecision(8) << std::setw(18) << Y[j];
-
-        //The error
-        out << std::fixed << std::setprecision(8) << std::setw(18) << Epos << "\n";
+        if ((*it)->name().compare("NormaliseByCurrent") == 0)
+          norm_by_current = true;
+        if ((*it)->name().compare("NormaliseToMonitor") == 0)
+          norm_by_monitor = true;
       }
+      os << "#";
+      if (norm_by_current)
+        os << " Normalised to pCharge";
+      if (norm_by_monitor)
+        os << " Normalised to monitor";
+      os << "\n";
     }
 
-    void SaveGSS::writeSLOGdata(const int bank, const bool MultiplyByBinWidth, std::ostream& out,
-        const MantidVec& X, const MantidVec& Y, const MantidVec& E) const
+    return;
+  }
+
+  //----------------------------------------------------------------------------------------------
+  /** Write a single line for bank
+    */
+  inline void writeBankLine(std::stringstream& out, const std::string& bintype, const int banknum,
+                            const size_t datasize)
+  {
+    out << "BANK " << std::fixed << std::setprecision(0) << banknum // First bank should be 1 for GSAS; this can be changed
+        << std::fixed << " " << datasize << std::fixed << " " << datasize << std::fixed << " "
+        << bintype;
+  }
+
+  //----------------------------------------------------------------------------------------------
+  /** Fix error if value is less than zero or infinity
+    */
+  inline double fixErrorValue(const double value)
+  {
+    if (value <= 0. || boost::math::isnan(value) || boost::math::isinf(value)) //Negative errors cannot be read by GSAS
+      return 0.;
+    else
+      return value;
+  }
+
+  //--------------------------------------------------------------------------------------------
+  /**
+    */
+  void SaveGSS::writeRALFdata(const int bank, const bool MultiplyByBinWidth, std::stringstream& out,
+                              const MantidVec& X, const MantidVec& Y, const MantidVec& E) const
+  {
+    const size_t datasize = Y.size();
+    double bc1 = X[0] * 32;
+    double bc2 = (X[1] - X[0]) * 32;
+    // Logarithmic step
+    double bc4 = (X[1] - X[0]) / X[0];
+    if (boost::math::isnan(fabs(bc4)) || boost::math::isinf(bc4))
+      bc4 = 0; //If X is zero for BANK
+
+
+    //Write out the data header
+    writeBankLine(out, "RALF", bank, datasize);
+    out << std::fixed << " " << std::setprecision(0) << std::setw(8) << bc1 << std::fixed << " "
+        << std::setprecision(0) << std::setw(8) << bc2 << std::fixed << " " << std::setprecision(0)
+        << std::setw(8) << bc1 << std::fixed << " " << std::setprecision(5) << std::setw(7) << bc4
+        << " FXYE" << std::endl;
+
+    //Do each Y entry
+    for (size_t j = 0; j < datasize; j++)
     {
+      //Calculate the error
+      double Epos;
+      if (MultiplyByBinWidth)
+        Epos = E[j] * (X[j + 1] - X[j]); // E[j]*X[j]*bc4;
+      else
+        Epos = E[j];
+      Epos = fixErrorValue(Epos);
 
-      g_log.debug() << "SaveGSS(): MultipyByBinwidth = " << MultiplyByBinWidth << std::endl;
+      //The center of the X bin.
+      out << std::fixed << std::setprecision(5) << std::setw(15) << 0.5 * (X[j] + X[j + 1]);
 
-      const size_t datasize = Y.size();
-      double bc1 = X.front(); // minimum TOF in microseconds
-      if (bc1 <= 0.)
-      {
-        throw std::runtime_error("Cannot write out logarithmic data starting at zero");
-      }
-      double bc2 = 0.5 * (*(X.rbegin()) + *(X.rbegin()+ 1)); // maximum TOF (in microseconds?)
-      double bc3 = (*(X.begin() + 1) - bc1) / bc1; // deltaT/T
+      // The Y value
+      if (MultiplyByBinWidth)
+        out << std::fixed << std::setprecision(8) << std::setw(18) << Y[j] * (X[j + 1] - X[j]);
+      else
+        out << std::fixed << std::setprecision(8) << std::setw(18) << Y[j];
 
-      g_log.debug() << "SaveGSS(): Min TOF = " << bc1 << std::endl;
+      //The error
+      out << std::fixed << std::setprecision(8) << std::setw(18) << Epos << "\n";
+    }
 
-      writeBankLine(out, "SLOG", bank, datasize);
-      out << std::fixed << " " << std::setprecision(0) << std::setw(10) << bc1 << std::fixed << " "
-          << std::setprecision(0) << std::setw(10) << bc2 << std::fixed << " " << std::setprecision(7)
-          << std::setw(10) << bc3 << std::fixed << " 0 FXYE" << std::endl;
+    return;
+  }
 
-      for (size_t i = 0; i < datasize; i++)
-      {
-        double y = Y[i];
-        double e = E[i];
-        if (MultiplyByBinWidth)
-        {
-          // Multiple by bin width as
-          double delta = X[i + 1] - X[i];
-          y *= delta;
-          e *= delta;
-        }
-        e = fixErrorValue(e);
+  //--------------------------------------------------------------------------------------------
+  /** Write data in SLOG format
+    */
+  void SaveGSS::writeSLOGdata(const int bank, const bool MultiplyByBinWidth, std::stringstream& out,
+                              const MantidVec& X, const MantidVec& Y, const MantidVec& E) const
+  {
+    const size_t datasize = Y.size();
+    double bc1 = X.front(); // minimum TOF in microseconds
+    if (bc1 <= 0.)
+    {
+      throw std::runtime_error("Cannot write out logarithmic data starting at zero");
+    }
+    double bc2 = 0.5 * (*(X.rbegin()) + *(X.rbegin()+ 1)); // maximum TOF (in microseconds?)
+    double bc3 = (*(X.begin() + 1) - bc1) / bc1; // deltaT/T
+
+    g_log.debug() << "SaveGSS(): Min TOF = " << bc1 << std::endl;
+
+    writeBankLine(out, "SLOG", bank, datasize);
+    out << std::fixed << " " << std::setprecision(0) << std::setw(10) << bc1 << std::fixed << " "
+        << std::setprecision(0) << std::setw(10) << bc2 << std::fixed << " " << std::setprecision(7)
+        << std::setw(10) << bc3 << std::fixed << " 0 FXYE" << std::endl;
 
-        out << "  " << std::fixed << std::setprecision(9) << std::setw(20) << 0.5 * (X[i] + X[i + 1])
-            << "  " << std::fixed << std::setprecision(9) << std::setw(20) << y << "  " << std::fixed
-            << std::setprecision(9) << std::setw(20) << e << std::setw(12) << " " << "\n"; // let it flush its own buffer
+    for (size_t i = 0; i < datasize; i++)
+    {
+      double y = Y[i];
+      double e = E[i];
+      if (MultiplyByBinWidth)
+      {
+        // Multiple by bin width as
+        double delta = X[i + 1] - X[i];
+        y *= delta;
+        e *= delta;
       }
-      out << std::flush;
+      e = fixErrorValue(e);
+
+      out << "  " << std::fixed << std::setprecision(9) << std::setw(20) << 0.5 * (X[i] + X[i + 1])
+          << "  " << std::fixed << std::setprecision(9) << std::setw(20) << y << "  " << std::fixed
+          << std::setprecision(9) << std::setw(20) << e << std::setw(12) << " " << "\n"; // let it flush its own buffer
     }
+    out << std::flush;
+
+    return;
+  }
 
-  } // namespace DataHandling
+} // namespace DataHandling
 } // namespace Mantid
diff --git a/Code/Mantid/Framework/DataHandling/src/SaveParameterFile.cpp b/Code/Mantid/Framework/DataHandling/src/SaveParameterFile.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..1f47ac4c05a03bd85456abadac162e9d4fca60bf
--- /dev/null
+++ b/Code/Mantid/Framework/DataHandling/src/SaveParameterFile.cpp
@@ -0,0 +1,198 @@
+#include "MantidAPI/FileProperty.h"
+#include "MantidAPI/WorkspaceValidators.h"
+#include "MantidDataHandling/SaveParameterFile.h"
+#include "MantidGeometry/IComponent.h"
+#include "MantidGeometry/Instrument.h"
+#include "MantidGeometry/Instrument/ParameterMap.h"
+
+#include <boost/lexical_cast.hpp>
+
+#include <Poco/DOM/AutoPtr.h>
+#include <Poco/DOM/Document.h>
+#include <Poco/DOM/DOMWriter.h>
+#include <Poco/DOM/Element.h>
+#include <Poco/XML/XMLWriter.h>
+
+#include <fstream>
+
+namespace Mantid
+{
+namespace DataHandling
+{
+
+  // Register the algorithm into the AlgorithmFactory
+  DECLARE_ALGORITHM(SaveParameterFile)
+
+  using namespace Kernel;
+  using namespace API;
+  using namespace Geometry;
+
+  using namespace Poco;
+
+  //----------------------------------------------------------------------------------------------
+  /** Constructor
+   */
+  SaveParameterFile::SaveParameterFile()
+  {
+  }
+
+  //----------------------------------------------------------------------------------------------
+  /** Destructor
+   */
+  SaveParameterFile::~SaveParameterFile()
+  { }
+
+  //----------------------------------------------------------------------------------------------
+  /// Algorithm's name for identification. @see Algorithm::name
+  const std::string SaveParameterFile::name() const { return "SaveParameterFile";};
+
+  /// Algorithm's version for identification. @see Algorithm::version
+  int SaveParameterFile::version() const { return 1;};
+
+  /// Algorithm's category for identification. @see Algorithm::category
+  const std::string SaveParameterFile::category() const { return "DataHandling\\Instrument";}
+
+  //----------------------------------------------------------------------------------------------
+
+  //----------------------------------------------------------------------------------------------
+  /** Initialize the algorithm's properties.
+   */
+  void SaveParameterFile::init()
+  {
+    declareProperty(new WorkspaceProperty<>("Workspace","",Direction::Input,boost::make_shared<InstrumentValidator>()),
+    "Workspace to save the instrument parameters from.");
+
+    std::vector<std::string> exts;
+    exts.push_back(".xml");
+
+    declareProperty(new API::FileProperty("Filename","", API::FileProperty::Save, exts),
+    "The name of the file into which the instrument parameters will be saved.");
+
+    declareProperty("SaveLocationParameters", false, "Save the location parameters used to calibrate the instrument.", Direction::Input);
+  }
+
+  //----------------------------------------------------------------------------------------------
+  /** Execute the algorithm.
+   */
+  void SaveParameterFile::exec()
+  {
+    const MatrixWorkspace_const_sptr ws = getProperty("Workspace");
+    const bool saveLocationParams = getProperty("SaveLocationParameters");
+    const std::string filename = getProperty("Filename");
+
+    const Instrument_const_sptr instrument = ws->getInstrument();
+    const ParameterMap_sptr params = instrument->getParameterMap();
+
+    //Map of component ids to their respective XML Elements
+    std::map<ComponentID,XML::AutoPtr<XML::Element> > compMap;
+
+    //Set up the XML document
+    XML::AutoPtr<XML::Document> xmlDoc = new XML::Document;
+    XML::AutoPtr<XML::Element> rootElem = xmlDoc->createElement("parameter-file");
+    rootElem->setAttribute("instrument", instrument->getName());
+    rootElem->setAttribute("valid-from", instrument->getValidFromDate().toISO8601String());
+    xmlDoc->appendChild(rootElem);
+
+    //Iterate through all the parameters set for the instrument and build an XML
+    //document out of it.
+    for(auto paramsIt = params->begin(); paramsIt != params->end(); ++paramsIt)
+    {
+      //Component data
+      const ComponentID cID = (*paramsIt).first;
+      const std::string cFullName = cID->getFullName();
+      const IDetector* cDet = dynamic_cast<IDetector*>(cID);
+      const detid_t cDetID = (cDet) ? cDet->getID() : 0;
+      const std::string cDetIDStr = boost::lexical_cast<std::string>(cDetID);
+
+      //Parameter data
+      const std::string pName = (*paramsIt).second->name();
+      const std::string pType = (*paramsIt).second->type();
+      const std::string pValue = (*paramsIt).second->asString();
+
+      //Skip rot and pos according to: http://www.mantidproject.org/IDF#Using_.3Cparameter.3E
+      if(pName == "pos" || pName == "rot")
+        continue;
+
+      //If save location parameters is not enabled, skip any location parameters
+      if(!saveLocationParams)
+      {
+        if( pName == "x"          || pName == "y"          || pName == "z" ||
+            pName == "r-position" || pName == "t-position" || pName == "p-position" ||
+            pName == "rotx"       || pName == "roty"       || pName == "rotz")
+        {
+          continue;
+        }
+      }
+
+      //A component-link element
+      XML::AutoPtr<XML::Element> compElem = 0;
+
+      /* If an element already exists for a component with this name, re-use it.
+       *
+       * Why are we using an std::map and not simply traversing the DOM? Because
+       * the interface for doing that is painful and horrible to use, and this is
+       * probably faster (but negligably so in this case).
+       *
+       * And lastly, because Poco::XML::NodeList::length() segfaults.
+       */
+      auto compIt = compMap.find(cID);
+      if(compIt != compMap.end())
+      {
+        compElem = (*compIt).second;
+      }
+
+      //One doesn't already exist? Make a new one.
+      if(!compElem)
+      {
+        compElem = xmlDoc->createElement("component-link");
+        rootElem->appendChild(compElem);
+        compMap[cID] = compElem;
+      }
+
+      //Create the parameter and value elements
+      XML::AutoPtr<XML::Element> paramElem = xmlDoc->createElement("parameter");
+      XML::AutoPtr<XML::Element> valueElem = xmlDoc->createElement("value");
+
+      //Set the attributes
+      compElem->setAttribute("name", cFullName);
+
+      //If there is a valid detector id, include it
+      if(cDetID > 0)
+      {
+        compElem->setAttribute("id", cDetIDStr);
+      }
+
+      paramElem->setAttribute("name", pName);
+
+      //For strings, we specify their type.
+      if(pType == "string")
+      {
+        paramElem->setAttribute("type", "string");
+      }
+
+      valueElem->setAttribute("val", pValue);
+
+      //Insert the elements into the document
+      compElem->appendChild(paramElem);
+      paramElem->appendChild(valueElem);
+    }
+
+    //Output the XMl document to the given file.
+    XML::DOMWriter writer;
+    writer.setOptions(XML::XMLWriter::PRETTY_PRINT | XML::XMLWriter::WRITE_XML_DECLARATION);
+    std::ofstream file(filename.c_str(), std::ofstream::trunc);
+    try
+    {
+      writer.writeNode(file, xmlDoc);
+    }
+    catch(Poco::Exception &e)
+    {
+      g_log.error() << "Error serializing XML for SaveParameterFile: " << e.displayText() << std::endl;
+    }
+    file.flush();
+    file.close();
+
+  }
+
+} // namespace Algorithms
+} // namespace Mantid
diff --git a/Code/Mantid/Framework/DataHandling/src/SaveToSNSHistogramNexus.cpp b/Code/Mantid/Framework/DataHandling/src/SaveToSNSHistogramNexus.cpp
index 2a98171185101c7d6871726139d3ccc802df558d..9d1d5644868abb05d756438fdb076d00fdb439e7 100644
--- a/Code/Mantid/Framework/DataHandling/src/SaveToSNSHistogramNexus.cpp
+++ b/Code/Mantid/Framework/DataHandling/src/SaveToSNSHistogramNexus.cpp
@@ -365,32 +365,57 @@ namespace DataHandling
 
     if (doBoth)
     {
+      bool returnerror = false;
+
       Timer tim2;
-      if (NXopendata (outId, field_name) != NX_OK) return NX_ERROR;
-      if (NXputdata (outId, data) != NX_OK) return NX_ERROR;
-      if (NXclosedata (outId) != NX_OK) return NX_ERROR;
-      this->prog->reportIncrement(det->xpixels()*det->ypixels()*1, det->getName() + " data");
+      if (NXopendata (outId, field_name) != NX_OK)
+        returnerror = true;
+      else if (NXputdata (outId, data) != NX_OK)
+        returnerror = true;
+      else if (NXclosedata (outId) != NX_OK)
+        returnerror = true;
+      else
+      {
+        this->prog->reportIncrement(det->xpixels()*det->ypixels()*1, det->getName() + " data");
+
+        if (NXopendata (outId, errors_field_name) != NX_OK)
+          returnerror = true;
+        else if (NXputdata (outId, errors) != NX_OK)
+          returnerror = true;
+        else if (NXclosedata (outId) != NX_OK)
+          returnerror = true;
+        else
+        {
+          this->prog->reportIncrement(det->xpixels()*det->ypixels()*1, det->getName() + " errors");
+          saveTime += tim2.elapsed();
+        }
+      }
+
+      if (returnerror)
+      {
+        delete [] data;
+        delete [] errors;
+
+        return NX_ERROR;
+      }
 
-      if (NXopendata (outId, errors_field_name) != NX_OK) return NX_ERROR;
-      if (NXputdata (outId, errors) != NX_OK) return NX_ERROR;
-      if (NXclosedata (outId) != NX_OK) return NX_ERROR;
-      this->prog->reportIncrement(det->xpixels()*det->ypixels()*1, det->getName() + " errors");
-      saveTime += tim2.elapsed();
     }
     else
     {
-      if (NXclosedata (outId) != NX_OK) return NX_ERROR;
+      if (NXclosedata (outId) != NX_OK)
+      {
+        delete[] data;
+        return NX_ERROR;
+      }
     }
 
     std::cout << "Filling out " << det->getName() << " took " << fillTime << " sec.\n";
     std::cout << "Saving      " << det->getName() << " took " << saveTime << " sec.\n";
 
-
     delete [] data;
     if (doBoth)
       delete [] errors;
 
-
     return NX_OK;
 
   }
diff --git a/Code/Mantid/Framework/DataHandling/src/SaveVTK.cpp b/Code/Mantid/Framework/DataHandling/src/SaveVTK.cpp
index ff4b8f91f451e1aa6455d7c7320481be82abe628..f385c2600664872db576d5e805ccd46b37bf44e1 100644
--- a/Code/Mantid/Framework/DataHandling/src/SaveVTK.cpp
+++ b/Code/Mantid/Framework/DataHandling/src/SaveVTK.cpp
@@ -46,7 +46,7 @@ namespace Mantid
         "0)" );
       declareProperty("Xmaximum", 0.0, mustBePositive,
         "No bin that contains x values higher than this will saved (default\n"
-        "the highest x value)" );
+        "0 signifies the highest x value)" );
     }
 
     /**
diff --git a/Code/Mantid/Framework/DataHandling/test/LoadISISNexusTest.h b/Code/Mantid/Framework/DataHandling/test/LoadISISNexusTest.h
index 49664a6fce97a913b0c227f9a1265599e9a85d54..a16b53f707507fd34b6a5e86aa36e67ac5b074ec 100644
--- a/Code/Mantid/Framework/DataHandling/test/LoadISISNexusTest.h
+++ b/Code/Mantid/Framework/DataHandling/test/LoadISISNexusTest.h
@@ -91,6 +91,10 @@ public:
         const std::vector< Property* >& logs = ws->run().getLogData();
         TS_ASSERT_EQUALS(logs.size(), 62);
 
+        std::string header = ws->run().getPropertyValueAsType<std::string>("run_header");
+        TS_ASSERT_EQUALS(86, header.size());
+        TS_ASSERT_EQUALS("LOQ 49886 Team LOQ             Quiet Count, ISIS Off, N 28-APR-2009  09:20:29     0.00", header);
+
         TimeSeriesProperty<std::string>* slog = dynamic_cast<TimeSeriesProperty<std::string>*>(ws->run().getLogData("icp_event"));
         TS_ASSERT(slog);
         std::string str = slog->value();
diff --git a/Code/Mantid/Framework/DataHandling/test/LoadParameterFileTest.h b/Code/Mantid/Framework/DataHandling/test/LoadParameterFileTest.h
index e6efa9b134b0f0a0d5c3790b6f25255a11df0e9a..7705eb7da7c096a4d1e2f8ac329819903f42fd34 100644
--- a/Code/Mantid/Framework/DataHandling/test/LoadParameterFileTest.h
+++ b/Code/Mantid/Framework/DataHandling/test/LoadParameterFileTest.h
@@ -59,6 +59,13 @@ public:
     param = paramMap.get(&(*ptrDet), "fjols-test-paramfile");
     TS_ASSERT_DELTA( param->value<double>(), 50.0, 0.0001);
 
+    ptrDet = i->getDetector(1301);
+    TS_ASSERT_EQUALS( ptrDet->getID(), 1301);
+    TS_ASSERT_EQUALS( ptrDet->getName(), "pixel");
+    param = paramMap.get(ptrDet.get(), "testDouble");
+    TS_ASSERT_DELTA( param->value<double>(), 25.0, 0.0001);
+    TS_ASSERT_EQUALS( paramMap.getString(ptrDet.get(), "testString"), "hello world");
+
     std::vector<double> dummy = paramMap.getDouble("nickel-holder", "klovn");
     TS_ASSERT_DELTA( dummy[0], 1.0, 0.0001);
     dummy = paramMap.getDouble("nickel-holder", "pos");
@@ -92,6 +99,10 @@ public:
       " <component-link name=\"IDF_for_UNIT_TESTING2.xml/combined translation6\" >"
       "  <parameter name=\"fjols-test-paramfile\"> <value val=\"52.0\" /> </parameter>"
       "	</component-link>"
+      " <component-link id=\"1301\" >"
+      "  <parameter name=\"testDouble\"> <value val=\"27.0\" /> </parameter>"
+      "  <parameter name=\"testString\" type=\"string\"> <value val=\"goodbye world\" /> </parameter>"
+      "	</component-link>"
       "</parameter-file>";
 
     // load in additional parameters
@@ -118,6 +129,13 @@ public:
     param = paramMap.get(&(*ptrDet), "fjols-test-paramfile");
     TS_ASSERT_DELTA( param->value<double>(), 52.0, 0.0001);
 
+    ptrDet = i->getDetector(1301);
+    TS_ASSERT_EQUALS( ptrDet->getID(), 1301);
+    TS_ASSERT_EQUALS( ptrDet->getName(), "pixel");
+    param = paramMap.get(ptrDet.get(), "testDouble");
+    TS_ASSERT_DELTA( param->value<double>(), 27.0, 0.0001);
+    TS_ASSERT_EQUALS( paramMap.getString(ptrDet.get(), "testString"), "goodbye world");
+
     std::vector<double> dummy = paramMap.getDouble("nickel-holder", "klovn");
     TS_ASSERT_DELTA( dummy[0], 1.0, 0.0001);
     dummy = paramMap.getDouble("nickel-holder", "pos");
diff --git a/Code/Mantid/Framework/DataHandling/test/LoadRaw3Test.h b/Code/Mantid/Framework/DataHandling/test/LoadRaw3Test.h
index e07e53026eba6bf765906a5250df8dec6ee6db25..6c97e94587a05e2a97f8e24a538dddf629a7a7b4 100644
--- a/Code/Mantid/Framework/DataHandling/test/LoadRaw3Test.h
+++ b/Code/Mantid/Framework/DataHandling/test/LoadRaw3Test.h
@@ -423,6 +423,12 @@ public:
     AnalysisDataService::Instance().remove("twoRegimes");
   }
   void testSeparateMonitors()
+  {
+    doTestSeparateMonitors("Separate");
+    doTestSeparateMonitors("1");
+  }
+
+  void doTestSeparateMonitors(const std::string& option)
   {
     LoadRaw3 loader6;
     if ( !loader6.isInitialized() ) loader6.initialize();
@@ -432,7 +438,7 @@ public:
 
     // Now set it...
     loader6.setPropertyValue("Filename", inputFile);
-    loader6.setPropertyValue("LoadMonitors", "Separate");
+    loader6.setPropertyValue("LoadMonitors", option);
 
     outputSpace = "outer1";
     loader6.setPropertyValue("OutputWorkspace", outputSpace);
@@ -835,15 +841,21 @@ public:
     AnalysisDataService::Instance().remove("outWS_monitors");
     AnalysisDataService::Instance().remove("outWS");
   }
-  //no monitors in the selected range
   void testExcludeMonitors()
+  {
+    doTestExcludeMonitors("Exclude");
+    doTestExcludeMonitors("0");
+  }
+
+  //no monitors in the selected range
+  void doTestExcludeMonitors(const std::string& option)
   {
     LoadRaw3 loader11;
     if ( !loader11.isInitialized() ) loader11.initialize();
 
     loader11.setPropertyValue("Filename", inputFile);
     loader11.setPropertyValue("OutputWorkspace", "outWS");
-    loader11.setPropertyValue("LoadMonitors", "Exclude");
+    loader11.setPropertyValue("LoadMonitors", option);
 
     TS_ASSERT_THROWS_NOTHING(loader11.execute());
     TS_ASSERT( loader11.isExecuted() );
diff --git a/Code/Mantid/Framework/DataHandling/test/RawFileInfoTest.h b/Code/Mantid/Framework/DataHandling/test/RawFileInfoTest.h
index e806ff2bc4bb0ede38b2f65fd1c73bb4770af0b8..481271e4593bd1dfc6259e04653133841b1f8672 100644
--- a/Code/Mantid/Framework/DataHandling/test/RawFileInfoTest.h
+++ b/Code/Mantid/Framework/DataHandling/test/RawFileInfoTest.h
@@ -57,7 +57,7 @@ private:
     std::string title = alg.getProperty("RunTitle");
     TS_ASSERT_EQUALS(title, std::string("direct beam                                                                     "));
     std::string header = alg.getProperty("RunHeader");
-    TS_ASSERT_EQUALS(header, std::string("48127 LOQ team & SANS Xpre direct beam              18-DEC-2008 17:58:38"));
+    TS_ASSERT_EQUALS(header, std::string("LOQ 48127 LOQ team & SANS Xpre direct beam              18-DEC-2008  17:58:38    10.04"));
     int spectra_count = alg.getProperty("SpectraCount"); //7290
     TS_ASSERT_EQUALS(spectra_count, 8);
       
diff --git a/Code/Mantid/Framework/DataHandling/test/SaveGSSTest.h b/Code/Mantid/Framework/DataHandling/test/SaveGSSTest.h
new file mode 100644
index 0000000000000000000000000000000000000000..8bc59d74668dc6bbce35c732091c534d23a94b17
--- /dev/null
+++ b/Code/Mantid/Framework/DataHandling/test/SaveGSSTest.h
@@ -0,0 +1,389 @@
+#ifndef SAVEGSSTEST_H_
+#define SAVEGSSTEST_H_
+
+#include "cxxtest/TestSuite.h"
+#include "MantidDataHandling/SaveGSS.h"
+#include "MantidAPI/AlgorithmManager.h"
+#include "MantidAPI/MatrixWorkspace.h"
+#include "MantidTestHelpers/WorkspaceCreationHelper.h"
+#include "MantidGeometry/Instrument.h"
+
+#include <Poco/File.h>
+#include <fstream>
+
+using namespace Mantid;
+using namespace Mantid::API;
+using namespace Mantid::DataObjects;
+using namespace Mantid::Geometry;
+using namespace Mantid::Kernel;
+using Mantid::DataHandling::SaveGSS;
+
+class SaveGSSTest : public CxxTest::TestSuite
+{
+public:
+
+  void test_TheBasics()
+  {
+    Mantid::DataHandling::SaveGSS saver;
+    TS_ASSERT_THROWS_NOTHING( saver.initialize() )
+    TS_ASSERT_EQUALS( saver.name(), "SaveGSS" )
+    TS_ASSERT_EQUALS( saver.category(), "Diffraction;DataHandling\\Text" )
+    TS_ASSERT_EQUALS( saver.version(), 1 )
+  }
+
+  //----------------------------------------------------------------------------------------------
+  /** Save a 2 banks diffraction data with instrument
+    */
+  void test_2BankInstrument()
+  {
+    // Create a workspace for writing out
+    MatrixWorkspace_sptr dataws = generateTestMatrixWorkspace();
+    AnalysisDataService::Instance().addOrReplace("Test2BankWS", dataws);
+
+    Mantid::DataHandling::SaveGSS saver;
+    saver.initialize();
+
+    // Set properties
+    TS_ASSERT_THROWS_NOTHING( saver.setPropertyValue("InputWorkspace", "Test2BankWS") );
+    TS_ASSERT_THROWS_NOTHING( saver.setProperty("Filename", "test1.gsa") );
+    TS_ASSERT_THROWS_NOTHING( saver.setProperty("Format", "SLOG") );
+    TS_ASSERT_THROWS_NOTHING( saver.setProperty("SplitFiles", false) );
+    TS_ASSERT_THROWS_NOTHING( saver.setProperty("MultiplyByBinWidth", false) );
+    TS_ASSERT_THROWS_NOTHING( saver.setProperty("Append", false) );
+
+    // Execute
+    saver.execute();
+    TS_ASSERT(saver.isExecuted());
+
+    // Check result
+    // locate output file
+    std::string outfilepath = saver.getPropertyValue("Filename");
+    std::cout << "Output file is located at " << outfilepath << "\n";
+
+    Poco::File gsasfile(outfilepath);
+    TS_ASSERT(gsasfile.exists());
+
+    // check file
+    if (gsasfile.exists())
+    {
+      size_t numlines = 0;
+      std::ifstream fs_gsas(outfilepath.c_str());
+      std::string line;
+      while (std::getline(fs_gsas, line))
+      {
+        size_t linenumber = numlines;
+        std::stringstream liness(line);
+        if (linenumber == 11)
+        {
+          std::string bank;
+          int banknumber;
+          liness >> bank >> banknumber;
+          TS_ASSERT_EQUALS(bank, "BANK");
+          TS_ASSERT_EQUALS(banknumber, 1);
+        }
+        else if (linenumber == 60)
+        {
+          double x, y, e;
+          liness >> x >> y >> e;
+          TS_ASSERT_DELTA(x, 8101.43, 0.01);
+          TS_ASSERT_DELTA(y, 688.18, 0.01);
+          TS_ASSERT_DELTA(e, 26.23, 0.01);
+        }
+        else if (linenumber == 114)
+        {
+          std::string bank;
+          int banknumber;
+          liness >> bank >> banknumber;
+          TS_ASSERT_EQUALS(bank, "BANK");
+          TS_ASSERT_EQUALS(banknumber, 2);
+        }
+        else if (linenumber == 173)
+        {
+          double x, y, e;
+          liness >> x >> y >> e;
+          TS_ASSERT_DELTA(x, 8949.02, 0.01);
+          TS_ASSERT_DELTA(y, 1592.26, 0.01);
+          TS_ASSERT_DELTA(e, 39.90, 0.01);
+        }
+
+        ++ numlines;
+      }
+
+      TS_ASSERT_EQUALS(numlines, 215);
+    }
+
+    // Clean
+    AnalysisDataService::Instance().remove("Test2BankWS");
+    if (gsasfile.exists())
+      gsasfile.remove();
+
+    return;
+  }
+
+  //----------------------------------------------------------------------------------------------
+  /** Save a 2 banks diffraction data with instrument
+    */
+  void test_2BankInstrumentRALF()
+  {
+    // Create a workspace for writing out
+    MatrixWorkspace_sptr dataws = generateTestMatrixWorkspace();
+    AnalysisDataService::Instance().addOrReplace("Test2BankWS", dataws);
+
+    Mantid::DataHandling::SaveGSS saver;
+    saver.initialize();
+
+    // Set properties
+    TS_ASSERT_THROWS_NOTHING( saver.setPropertyValue("InputWorkspace", "Test2BankWS") );
+    TS_ASSERT_THROWS_NOTHING( saver.setProperty("Filename", "test1r.gsa") );
+    TS_ASSERT_THROWS_NOTHING( saver.setProperty("Format", "RALF") );
+    TS_ASSERT_THROWS_NOTHING( saver.setProperty("SplitFiles", false) );
+    TS_ASSERT_THROWS_NOTHING( saver.setProperty("MultiplyByBinWidth", false) );
+    TS_ASSERT_THROWS_NOTHING( saver.setProperty("Append", false) );
+
+    // Execute
+    saver.execute();
+    TS_ASSERT(saver.isExecuted());
+
+    // Check result
+    // locate output file
+    std::string outfilepath = saver.getPropertyValue("Filename");
+    std::cout << "Output file is located at " << outfilepath << "\n";
+
+    Poco::File gsasfile(outfilepath);
+    TS_ASSERT(gsasfile.exists());
+
+    // check file
+    if (gsasfile.exists())
+    {
+      size_t numlines = 0;
+      std::ifstream fs_gsas(outfilepath.c_str());
+      std::string line;
+      while (std::getline(fs_gsas, line))
+      {
+        size_t linenumber = numlines;
+        std::stringstream liness(line);
+        if (linenumber == 8)
+        {
+          std::string bank;
+          int banknumber;
+          liness >> bank >> banknumber;
+          TS_ASSERT_EQUALS(bank, "BANK");
+          TS_ASSERT_EQUALS(banknumber, 1);
+        }
+        else if (linenumber == 57)
+        {
+          double x, y, e;
+          liness >> x >> y >> e;
+          TS_ASSERT_DELTA(x, 8101.43, 0.01);
+          TS_ASSERT_DELTA(y, 688.18, 0.01);
+          TS_ASSERT_DELTA(e, 26.23, 0.01);
+        }
+        else if (linenumber == 111)
+        {
+          std::string bank;
+          int banknumber;
+          liness >> bank >> banknumber;
+          TS_ASSERT_EQUALS(bank, "BANK");
+          TS_ASSERT_EQUALS(banknumber, 2);
+        }
+        else if (linenumber == 170)
+        {
+          double x, y, e;
+          liness >> x >> y >> e;
+          TS_ASSERT_DELTA(x, 8949.02, 0.01);
+          TS_ASSERT_DELTA(y, 1592.26, 0.01);
+          TS_ASSERT_DELTA(e, 39.90, 0.01);
+        }
+
+        ++ numlines;
+      }
+
+      TS_ASSERT_EQUALS(numlines, 212);
+    }
+
+    // Clean
+    AnalysisDataService::Instance().remove("Test2BankWS");
+    if (gsasfile.exists())
+      gsasfile.remove();
+
+    return;
+  }
+
+  //----------------------------------------------------------------------------------------------
+  /** Save a 2 bank workspace in point data format and without instrument
+    */
+  void test_2BankNoInstrumentData()
+  {
+    MatrixWorkspace_sptr dataws = generateNoInstrumentWorkspace();
+
+    AnalysisDataService::Instance().addOrReplace("TestNoInstWS", dataws);
+
+    Mantid::DataHandling::SaveGSS saver;
+    saver.initialize();
+
+    // Set properties
+    TS_ASSERT_THROWS_NOTHING( saver.setPropertyValue("InputWorkspace", "TestNoInstWS") );
+    TS_ASSERT_THROWS_NOTHING( saver.setProperty("Filename", "test2.gsa") );
+    TS_ASSERT_THROWS_NOTHING( saver.setProperty("Format", "SLOG") );
+    TS_ASSERT_THROWS_NOTHING( saver.setProperty("SplitFiles", false) );
+    TS_ASSERT_THROWS_NOTHING( saver.setProperty("MultiplyByBinWidth", false) );
+    TS_ASSERT_THROWS_NOTHING( saver.setProperty("Append", false) );
+
+    // Execute
+    saver.execute();
+    TS_ASSERT(saver.isExecuted());
+
+    // Check result
+    // locate output file
+    std::string outfilepath = saver.getPropertyValue("Filename");
+    std::cout << "Output file is located at " << outfilepath << "\n";
+
+    Poco::File gsasfile(outfilepath);
+    TS_ASSERT(gsasfile.exists());
+
+    // check file
+    if (gsasfile.exists())
+    {
+      size_t numlines = 0;
+      std::ifstream fs_gsas(outfilepath.c_str());
+      std::string line;
+      while (std::getline(fs_gsas, line))
+      {
+        size_t linenumber = numlines;
+        std::stringstream liness(line);
+        if (linenumber == 10)
+        {
+          std::string bank;
+          int banknumber;
+          liness >> bank >> banknumber;
+          TS_ASSERT_EQUALS(bank, "BANK");
+          TS_ASSERT_EQUALS(banknumber, 1);
+        }
+        else if (linenumber == 59)
+        {
+          double x, y, e;
+          liness >> x >> y >> e;
+          TS_ASSERT_DELTA(x, 8101.43, 0.01);
+          TS_ASSERT_DELTA(y, 688.18, 0.01);
+          TS_ASSERT_DELTA(e, 26.23, 0.01);
+        }
+        else if (linenumber == 112)
+        {
+          std::string bank;
+          int banknumber;
+          liness >> bank >> banknumber;
+          TS_ASSERT_EQUALS(bank, "BANK");
+          TS_ASSERT_EQUALS(banknumber, 2);
+        }
+        else if (linenumber == 171)
+        {
+          double x, y, e;
+          liness >> x >> y >> e;
+          TS_ASSERT_DELTA(x, 8949.02, 0.01);
+          TS_ASSERT_DELTA(y, 1592.26, 0.01);
+          TS_ASSERT_DELTA(e, 39.90, 0.01);
+        }
+
+        ++ numlines;
+      }
+
+      TS_ASSERT_EQUALS(numlines, 213);
+    }
+
+
+    // Clean
+    AnalysisDataService::Instance().remove("TestNoInstWS");
+    if (gsasfile.exists())
+      gsasfile.remove();
+
+    return;
+  }
+
+private:
+
+  //----------------------------------------------------------------------------------------------
+  /**
+    */
+  API::MatrixWorkspace_sptr generateNoInstrumentWorkspace()
+  {
+    MatrixWorkspace_sptr dataws = WorkspaceCreationHelper::Create2DWorkspace(2, 100);
+    dataws->getAxis(0)->setUnit("TOF");
+
+    // Set data with logarithm bin
+    double t0 = 5000.;
+    double dt = 0.01;
+    size_t numhist = dataws->getNumberHistograms();
+    for (size_t iws = 0; iws < numhist; ++iws)
+    {
+      MantidVec& dataX = dataws->dataX(iws);
+      dataX[0] = t0;
+      for (size_t i = 1; i < dataX.size(); ++i)
+        dataX[i] = (1+dt)*dataX[i-1];
+    }
+
+    // Set y and e
+    for (size_t iws = 0; iws < numhist; ++iws)
+    {
+      const MantidVec& vecX = dataws->readX(iws);
+      MantidVec& dataY = dataws->dataY(iws);
+      MantidVec& dataE = dataws->dataE(iws);
+      double factor = (static_cast<double>(iws)+1)*1000.;
+      for (size_t i = 0; i < dataY.size(); ++i)
+      {
+        dataY[i] = factor*std::exp(-(vecX[i] - 7000. - factor)*(vecX[i] - 7000. - factor)/(0.01*factor*factor));
+        if (dataY[i] < 0.01)
+          dataE[i] = 0.1;
+        else
+          dataE[i] = std::sqrt(dataY[i]);
+      }
+    }
+
+    return dataws;
+  }
+
+  //----------------------------------------------------------------------------------------------
+  /** Generate a matrix workspace for writing to gsas file
+    */
+  API::MatrixWorkspace_sptr generateTestMatrixWorkspace()
+  {
+    // Create workspace
+    MatrixWorkspace_sptr dataws = boost::dynamic_pointer_cast<MatrixWorkspace>(
+          WorkspaceCreationHelper::create2DWorkspaceWithFullInstrument(2, 100, false, false, true, "TestFake"));
+    dataws->getAxis(0)->setUnit("TOF");
+
+    // Set data with logarithm bin
+    double t0 = 5000.;
+    double dt = 0.01;
+    size_t numhist = dataws->getNumberHistograms();
+    for (size_t iws = 0; iws < numhist; ++iws)
+    {
+      MantidVec& dataX = dataws->dataX(iws);
+      dataX[0] = t0;
+      for (size_t i = 1; i < dataX.size(); ++i)
+        dataX[i] = (1+dt)*dataX[i-1];
+    }
+
+    // Set y and e
+    for (size_t iws = 0; iws < numhist; ++iws)
+    {
+      const MantidVec& vecX = dataws->readX(iws);
+      MantidVec& dataY = dataws->dataY(iws);
+      MantidVec& dataE = dataws->dataE(iws);
+      double factor = (static_cast<double>(iws)+1)*1000.;
+      for (size_t i = 0; i < dataY.size(); ++i)
+      {
+        dataY[i] = factor*std::exp(-(vecX[i] - 7000. - factor)*(vecX[i] - 7000. - factor)/(0.01*factor*factor));
+        if (dataY[i] < 0.01)
+          dataE[i] = 0.1;
+        else
+          dataE[i] = std::sqrt(dataY[i]);
+      }
+    }
+
+    return dataws;
+  }
+
+};
+
+
+#endif //SAVEGSSTEST_H_
diff --git a/Code/Mantid/Framework/DataHandling/test/SaveParameterFileTest.h b/Code/Mantid/Framework/DataHandling/test/SaveParameterFileTest.h
new file mode 100644
index 0000000000000000000000000000000000000000..4bd4a329164888fd8bf89214ddc57f6bf44a9bd7
--- /dev/null
+++ b/Code/Mantid/Framework/DataHandling/test/SaveParameterFileTest.h
@@ -0,0 +1,165 @@
+#ifndef SAVEPARAMETERFILETEST_H_
+#define SAVEPARAMETERFILETEST_H_
+
+#include <cxxtest/TestSuite.h>
+
+#include "MantidAPI/Algorithm.h"
+#include "MantidAPI/AnalysisDataService.h"
+#include "MantidAPI/FrameworkManager.h"
+#include "MantidAPI/Workspace.h"
+#include "MantidAPI/WorkspaceFactory.h"
+#include "MantidDataHandling/LoadInstrument.h"
+#include "MantidDataHandling/LoadParameterFile.h"
+#include "MantidDataHandling/SaveParameterFile.h"
+#include "MantidDataObjects/Workspace2D.h"
+#include "MantidGeometry/IDetector.h"
+#include "MantidGeometry/Instrument.h"
+#include "MantidGeometry/Instrument/Component.h"
+#include "MantidKernel/Exception.h"
+#include "MantidTestHelpers/ScopedFileHelper.h"
+
+using namespace Mantid::API;
+using namespace Mantid::Kernel;
+using namespace Mantid::Geometry;
+using namespace Mantid::DataHandling;
+using namespace Mantid::DataObjects;
+
+class SaveParameterFileTest : public CxxTest::TestSuite
+{
+public:
+
+  void testSavingParameters()
+  {
+    //First we want to load a workspace to work with.
+    prepareWorkspace();
+
+    //Now let's set some parameters
+    setParam("nickel-holder", "testDouble1", 1.23);
+    setParam("nickel-holder", "testDouble2", 1.00);
+    setParam("nickel-holder", "testString1", "hello world");
+    setParam("nickel-holder", "testString2", "unchanged");
+    setParamByDetID(1301, "testDouble", 2.17);
+
+    //Create a temporary blank file for us to test with
+    ScopedFileHelper::ScopedFile paramFile("", "__params.xml");
+
+    //Save the parameters out to disk
+    saveParams(paramFile.getFileName());
+
+    //Change some parameters - these changes should not have an effect
+    setParam("nickel-holder", "testDouble1", 3.14);
+    setParam("nickel-holder", "testString1", "broken");
+    setParamByDetID(1301, "testDouble", 7.89);
+
+    //Load the saved parameters back in
+    loadParams(paramFile.getFileName());
+
+    //Confirm all the parameters are as they should be
+    checkParam("nickel-holder", "testDouble1", 1.23);
+    checkParam("nickel-holder", "testDouble2", 1.00);
+    checkParam("nickel-holder", "testString1", "hello world");
+    checkParam("nickel-holder", "testString2", "unchanged");
+    checkParamByDetID(1301, "testDouble", 2.17);
+  }
+
+  void setParam(std::string cName, std::string pName, std::string value)
+  {
+    Instrument_const_sptr inst = m_ws->getInstrument();
+    ParameterMap& paramMap = m_ws->instrumentParameters();
+    boost::shared_ptr<const IComponent> comp = inst->getComponentByName(cName);
+    paramMap.addString(comp->getComponentID(), pName, value);
+  }
+
+  void setParam(std::string cName, std::string pName, double value)
+  {
+    Instrument_const_sptr inst = m_ws->getInstrument();
+    ParameterMap& paramMap = m_ws->instrumentParameters();
+    boost::shared_ptr<const IComponent> comp = inst->getComponentByName(cName);
+    paramMap.addDouble(comp->getComponentID(), pName, value);
+  }
+
+  void setParamByDetID(int id, std::string pName, double value)
+  {
+    Instrument_const_sptr inst = m_ws->getInstrument();
+    ParameterMap& paramMap = m_ws->instrumentParameters();
+    IDetector_const_sptr det = inst->getDetector(id);
+    IComponent_const_sptr comp = boost::dynamic_pointer_cast<const IComponent>(det);
+    paramMap.addDouble(comp->getComponentID(), pName, value);
+  }
+
+  void checkParam(std::string cName, std::string pName, std::string value)
+  {
+    Instrument_const_sptr inst = m_ws->getInstrument();
+    ParameterMap& paramMap = m_ws->instrumentParameters();
+    boost::shared_ptr<const IComponent> comp = inst->getComponentByName(cName);
+    std::string param = paramMap.getString(comp.get(), pName);
+    TS_ASSERT_EQUALS(value, param);
+  }
+
+  void checkParam(std::string cName, std::string pName, double value)
+  {
+    Instrument_const_sptr inst = m_ws->getInstrument();
+    ParameterMap& paramMap = m_ws->instrumentParameters();
+    boost::shared_ptr<const IComponent> comp = inst->getComponentByName(cName);
+    std::vector<double> values = paramMap.getDouble(cName, pName);
+    TS_ASSERT_DELTA(value, values.front(), 0.0001);
+  }
+
+  void checkParamByDetID(int id, std::string pName, double value)
+  {
+    Instrument_const_sptr inst = m_ws->getInstrument();
+    ParameterMap& paramMap = m_ws->instrumentParameters();
+    IDetector_const_sptr det = inst->getDetector(id);
+    IComponent_const_sptr comp = boost::dynamic_pointer_cast<const IComponent>(det);
+    Parameter_sptr param = paramMap.get(comp.get(), pName);
+    double pValue = param->value<double>();
+    TS_ASSERT_DELTA(value, pValue, 0.0001);
+  }
+
+
+  void loadParams(std::string filename)
+  {
+    LoadParameterFile loaderPF;
+    TS_ASSERT_THROWS_NOTHING(loaderPF.initialize());
+    loaderPF.setPropertyValue("Filename", filename);
+    loaderPF.setPropertyValue("Workspace", m_ws->name());
+    TS_ASSERT_THROWS_NOTHING(loaderPF.execute());
+    TS_ASSERT(loaderPF.isExecuted());
+  }
+
+  void saveParams(std::string filename)
+  {
+    SaveParameterFile saverPF;
+    TS_ASSERT_THROWS_NOTHING(saverPF.initialize());
+    saverPF.setPropertyValue("Filename", filename);
+    saverPF.setPropertyValue("Workspace", m_ws->name());
+    TS_ASSERT_THROWS_NOTHING(saverPF.execute());
+    TS_ASSERT(saverPF.isExecuted());
+  }
+
+  void prepareWorkspace()
+  {
+    LoadInstrument loaderIDF2;
+
+    TS_ASSERT_THROWS_NOTHING(loaderIDF2.initialize());
+
+    std::string wsName = "SaveParameterFileTestIDF2";
+    Workspace_sptr ws = WorkspaceFactory::Instance().create("Workspace2D",1,1,1);
+    Workspace2D_sptr ws2D = boost::dynamic_pointer_cast<Workspace2D>(ws);
+
+    TS_ASSERT_THROWS_NOTHING(AnalysisDataService::Instance().add(wsName, ws2D));
+
+    loaderIDF2.setPropertyValue("Filename", "IDFs_for_UNIT_TESTING/IDF_for_UNIT_TESTING2.xml");
+    loaderIDF2.setPropertyValue("Workspace", wsName);
+    TS_ASSERT_THROWS_NOTHING(loaderIDF2.execute());
+    TS_ASSERT( loaderIDF2.isExecuted() );
+
+    m_ws = boost::dynamic_pointer_cast<MatrixWorkspace>(ws2D);
+  }
+
+private:
+  MatrixWorkspace_sptr m_ws;
+
+};
+
+#endif /*SAVEPARAMETERFILETEST_H_*/
diff --git a/Code/Mantid/Framework/DataObjects/inc/MantidDataObjects/MaskWorkspace.h b/Code/Mantid/Framework/DataObjects/inc/MantidDataObjects/MaskWorkspace.h
index 100545dca0823b41cd1601027a68ed474ceca294..3bc4a32a0202b708a61654607c5e81453c10262d 100644
--- a/Code/Mantid/Framework/DataObjects/inc/MantidDataObjects/MaskWorkspace.h
+++ b/Code/Mantid/Framework/DataObjects/inc/MantidDataObjects/MaskWorkspace.h
@@ -52,10 +52,7 @@ namespace DataObjects
     void clearMask();
 
     /// Check whether any instrument associated
-    bool hasInstrument();
-
-    /// Flag for having a REAL intrument associated
-    mutable bool m_hasInstrument;
+    bool hasInstrument() const;
   };
 
   ///shared pointer to the MaskWorkspace class
diff --git a/Code/Mantid/Framework/DataObjects/src/MaskWorkspace.cpp b/Code/Mantid/Framework/DataObjects/src/MaskWorkspace.cpp
index 644f686d7aaa076706c47302fa37168b8e44653a..3633e3244d1d2e162bd530d59df5fb4b9b8ef83b 100644
--- a/Code/Mantid/Framework/DataObjects/src/MaskWorkspace.cpp
+++ b/Code/Mantid/Framework/DataObjects/src/MaskWorkspace.cpp
@@ -32,9 +32,8 @@ namespace DataObjects
      * Constructor - Default.
      * @return MaskWorkspace
      */
-    MaskWorkspace::MaskWorkspace()  : m_hasInstrument(false)
+    MaskWorkspace::MaskWorkspace()
     {
-      m_hasInstrument = hasInstrument();
     }
 
     /**
@@ -42,11 +41,10 @@ namespace DataObjects
      * @param[in] numvectors Number of vectors/histograms for this workspace.
      * @return MaskWorkspace
      */
-    MaskWorkspace::MaskWorkspace(std::size_t numvectors) : m_hasInstrument(false)
+    MaskWorkspace::MaskWorkspace(std::size_t numvectors)
     {
       this->init(numvectors, 1, 1);
       this->clearMask();
-      m_hasInstrument = hasInstrument();
     }
 
     /**
@@ -56,10 +54,9 @@ namespace DataObjects
      * @return MaskWorkspace
      */
     MaskWorkspace::MaskWorkspace(Mantid::Geometry::Instrument_const_sptr instrument, const bool includeMonitors)
-      : SpecialWorkspace2D(instrument, includeMonitors), m_hasInstrument(true)
+      : SpecialWorkspace2D(instrument, includeMonitors)
     {
       this->clearMask();
-      m_hasInstrument = hasInstrument();
     }
 
     /**
@@ -68,10 +65,9 @@ namespace DataObjects
      * @return MaskWorkspace
      */
     MaskWorkspace::MaskWorkspace(const API::MatrixWorkspace_const_sptr parent)
-        : SpecialWorkspace2D(parent), m_hasInstrument(true)
+        : SpecialWorkspace2D(parent)
     {
       this->clearMask();
-      m_hasInstrument = hasInstrument();
     }
 
     //--------------------------------------------------------------------------
@@ -107,14 +103,6 @@ namespace DataObjects
     {
       // Determine whether has instrument or not
       Geometry::Instrument_const_sptr inst = getInstrument();
-      if (inst)
-      {
-        if (inst->getNumberDetectors() > 0)
-          m_hasInstrument = true;
-        else
-          m_hasInstrument = false;
-      }
-      else m_hasInstrument = false;
 
       size_t numMasked(0);
       const size_t numWksp(this->getNumberHistograms());
@@ -124,7 +112,7 @@ namespace DataObjects
         {
           numMasked++;
         }
-        else if (m_hasInstrument)
+        else if (this->hasInstrument())
         {
           const set<detid_t> ids = this->getDetectorIDs(i);
           if (this->isMasked(ids)) // slow and correct check with the real method
@@ -149,9 +137,13 @@ namespace DataObjects
       set<detid_t> detIDs;
 
       Geometry::Instrument_const_sptr inst = this->getInstrument();
-      if (inst) m_hasInstrument = true;
 
-      if (m_hasInstrument)
+      /*
+       * Note
+       * This test originally just checked if there was an instument and ignored
+       * the number of detectors
+       */
+      if (this->hasInstrument())
       {
         size_t numHist(this->getNumberHistograms());
         for (size_t i = 0; i < numHist; i++)
@@ -194,7 +186,7 @@ namespace DataObjects
      */
     bool MaskWorkspace::isMasked(const detid_t detectorID) const
     {
-      if (!m_hasInstrument)
+      if (!this->hasInstrument())
       {
         std::stringstream msg;
         if (!this->getInstrument())
@@ -296,8 +288,6 @@ namespace DataObjects
     void MaskWorkspace::copyFrom(boost::shared_ptr<const SpecialWorkspace2D> sourcews)
     {
       SpecialWorkspace2D::copyFrom(sourcews);
-
-      m_hasInstrument = hasInstrument();
     }
 
     /**
@@ -316,7 +306,7 @@ namespace DataObjects
       * (1) There is an instrument associated with
       * (2) Number of detectors is larger than 0
       */
-    bool MaskWorkspace::hasInstrument()
+    bool MaskWorkspace::hasInstrument() const
     {
       bool hasinst;
       Geometry::Instrument_const_sptr inst = this->getInstrument();
diff --git a/Code/Mantid/Framework/Geometry/inc/MantidGeometry/Instrument/ParameterMap.h b/Code/Mantid/Framework/Geometry/inc/MantidGeometry/Instrument/ParameterMap.h
index 2c244db23ea2a229cc4add3da015043c14545c76..c1cba73d0b87e503a3addab81be4971e68c5919c 100644
--- a/Code/Mantid/Framework/Geometry/inc/MantidGeometry/Instrument/ParameterMap.h
+++ b/Code/Mantid/Framework/Geometry/inc/MantidGeometry/Instrument/ParameterMap.h
@@ -109,6 +109,8 @@ namespace Geometry
     static const std::string & pV3D();
     static const std::string & pQuat();
 
+    const std::string diff(const ParameterMap & rhs, const bool & firstDiffOnly = false) const;
+
     /// Inquality comparison operator
     bool operator!=(const ParameterMap & rhs) const;
     /// Equality comparison operator
diff --git a/Code/Mantid/Framework/Geometry/src/Instrument.cpp b/Code/Mantid/Framework/Geometry/src/Instrument.cpp
index 773ccf932719b419d4d3913d8cf3dec84ac988de..b2f7bfb8afea480ae4a3b7e2af8a22035635f4f6 100644
--- a/Code/Mantid/Framework/Geometry/src/Instrument.cpp
+++ b/Code/Mantid/Framework/Geometry/src/Instrument.cpp
@@ -511,8 +511,6 @@ namespace Mantid
         detid2det_map::const_iterator it = m_detectorCache.find(detector_id);
         if ( it == m_detectorCache.end() )
         {
-          //FIXME: When ticket #4544 is fixed, re-enable this debug print:
-          //g_log.debug() << "Detector with ID " << detector_id << " not found." << std::endl;
           std::stringstream readInt;
           readInt << detector_id;
           throw Kernel::Exception::NotFoundError("Instrument: Detector with ID " + readInt.str() + " not found.","");
diff --git a/Code/Mantid/Framework/Geometry/src/Instrument/Goniometer.cpp b/Code/Mantid/Framework/Geometry/src/Instrument/Goniometer.cpp
index b0e907793a72baf3b8d8fc69110b92ac7363b96c..7f3bd50d31081f7df0f3235740d8756f3d0805f9 100644
--- a/Code/Mantid/Framework/Geometry/src/Instrument/Goniometer.cpp
+++ b/Code/Mantid/Framework/Geometry/src/Instrument/Goniometer.cpp
@@ -246,41 +246,7 @@ void Goniometer::makeUniversalGoniometer()
 */
 std::vector<double> Goniometer::getEulerAngles(std::string convention)
 {
-
-  std::string conv(convention);
-  //translate convention to three integers X=0, Y=1, Z=2
-  if (conv.length()!=3) throw std::invalid_argument("Wrong convention name (string length not 3)");
-  boost::to_upper(conv);
-  if (conv.find_first_not_of("XYZ")!=std::string::npos) throw std::invalid_argument("Wrong convention name (characters other than XYZ)");
-  if ((conv[0]==conv[1]) || (conv[2]==conv[1])) throw std::invalid_argument("Wrong convention name (repeated indices)");
-  boost::replace_all(conv,"X","0");
-  boost::replace_all(conv,"Y","1");
-  boost::replace_all(conv,"Z","2");
-  int first, second, last, TB, par01,par12;
-  std::stringstream s;
-  s<<conv[0]<<" "<<conv[1]<<" "<<conv[2];
-  s>>first>>second>>last;
-  TB=(first+second+last+9==3)?1:0;
-  par01=((second-first+9)%3==1)?1:-1;
-  par12=((last-second+9)%3==1)?1:-1;
-  
-  std::vector<double> angles(3);
-  double s1,s2,s3,c1,c2,c3;
-  s3=(1.-TB-TB*par12)*R[(last+TB*par12+9)%3][(last-par12+9)%3];
-  c3=(TB-(1.-TB)*par12)*R[(last+TB*par12+9)%3][(last+par12+9)%3];
-  angles[2]=atan2(s3,c3)*rad2deg;
-  V3D axis3(0,0,0);
-  axis3[last]=1.;  
-  DblMatrix Rm3(Quat(-angles[2],axis3).getRotation()),Rp;
-  Rp=R*Rm3;
-  s1=par01*Rp[(first-par01+9)%3][(first+par01+9)%3];
-  c1=Rp[second][second];
-  s2=par01*Rp[first][3-first-second];
-  c2=Rp[first][first];  
-  angles[0]=atan2(s1,c1)*rad2deg;
-  angles[1]=atan2(s2,c2)*rad2deg;
-
-  return angles;
+  return Quat(getR()).getEulerAngles(convention);
 }
 
 /// Private function to recalculate the rotation matrix of the goniometer
diff --git a/Code/Mantid/Framework/Geometry/src/Instrument/InstrumentDefinitionParser.cpp b/Code/Mantid/Framework/Geometry/src/Instrument/InstrumentDefinitionParser.cpp
index fae53d070e5af57a3fc20489fbaf6874958d919a..5adefdf4e67e37ecdf2a187e10c141e3dbaa72b3 100644
--- a/Code/Mantid/Framework/Geometry/src/Instrument/InstrumentDefinitionParser.cpp
+++ b/Code/Mantid/Framework/Geometry/src/Instrument/InstrumentDefinitionParser.cpp
@@ -1946,18 +1946,56 @@ namespace Geometry
     for (unsigned long iLink = 0; iLink < numberLinks; iLink++)
     {
       Element* pLinkElem = static_cast<Element*>(pNL_link->item(iLink));
+      std::string id = pLinkElem->getAttribute("id");
       std::string name = pLinkElem->getAttribute("name");
       std::vector<boost::shared_ptr<const Geometry::IComponent> > sharedIComp;
-      if( name.find('/',0) == std::string::npos )
-      { // Simple name, look for all components of that name.
-          sharedIComp = instrument->getAllComponentsWithName(name);
-      } 
-      else
-      { // Pathname given. Assume it is unique.
-        boost::shared_ptr<const Geometry::IComponent> shared = instrument->getComponentByName(name);
-        sharedIComp.push_back( shared );
+
+      //If available, use the detector id as it's the most specific.
+      if(id.length() > 0)
+      {
+        int detid;
+        std::stringstream(id) >> detid;
+        boost::shared_ptr<const Geometry::IComponent> detector = instrument->getDetector((detid_t) detid);
+
+        //If we didn't find anything with the detector id, explain why to the user, and throw an exception.
+        if(!detector)
+        {
+          g_log.error() << "Error whilst loading parameters. No detector found with id '" << detid << "'" << std::endl;
+          g_log.error() << "Please check that your detectors' ids are correct." << std::endl;
+          throw Kernel::Exception::InstrumentDefinitionError("Invalid detector id in component-link tag.");
+        }
+
+        sharedIComp.push_back(detector);
+
+        //If the user also supplied a name, make sure it's consistent with the detector id.
+        if(name.length() > 0)
+        {
+          auto comp = boost::dynamic_pointer_cast<const IComponent>(detector);
+          if(comp)
+          {
+            bool consistent = (comp->getFullName() == name || comp->getName() == name);
+            if(!consistent)
+            {
+              g_log.warning() << "Error whilst loading parameters. Name '" << name << "' does not match id '" << detid << "'." << std::endl;
+              g_log.warning() << "Parameters have been applied to detector with id '" << detid << "'. Please check the name is correct." << std::endl;
+            }
+          }
+        }
       }
+      else
+      {
+        //No detector id given, fall back to using the name
 
+        if( name.find('/',0) == std::string::npos )
+        { // Simple name, look for all components of that name.
+            sharedIComp = instrument->getAllComponentsWithName(name);
+        }
+        else
+        { // Pathname given. Assume it is unique.
+          boost::shared_ptr<const Geometry::IComponent> shared = instrument->getComponentByName(name);
+          sharedIComp.push_back( shared );
+        }
+      }
 
       for (size_t i = 0; i < sharedIComp.size(); i++)
       {
diff --git a/Code/Mantid/Framework/Geometry/src/Instrument/ParameterMap.cpp b/Code/Mantid/Framework/Geometry/src/Instrument/ParameterMap.cpp
index 9e229fbf25b689d609e444e8447286857b2f8085..77fae890d1c82c714663f1b7e927f2d9e0d80a41 100644
--- a/Code/Mantid/Framework/Geometry/src/Instrument/ParameterMap.cpp
+++ b/Code/Mantid/Framework/Geometry/src/Instrument/ParameterMap.cpp
@@ -175,6 +175,88 @@ namespace Mantid
       return true;
     }
 
+     
+    /**
+     * Output information that helps understanding the mismatch between two parameter maps.
+     * To loop through the difference between two very large parameter map can take time, in which
+     * you can a hit to what causes the difference faster setting firstDiffOnly to true
+     * @param rhs A reference to a ParameterMap object to compare it to
+     * @param firstDiffOnly If true return only first difference found
+     * @return diff as a string
+     */
+    const std::string ParameterMap::diff(const ParameterMap & rhs, const bool & firstDiffOnly) const
+    {
+      if(this == &rhs) return std::string(""); // True for the same object
+      
+      // Quick size check
+      if(this->size() != rhs.size()) 
+      {
+          return std::string("Number of parameters does not match: ") + 
+            boost::lexical_cast<std::string>(this->size()) + " not equal to " +
+            boost::lexical_cast<std::string>(rhs.size());
+      }
+      
+      // Run this same loops as in operator==
+      // The map is unordered and the key is only valid at runtime. The
+      // asString method turns the ComponentIDs to full-qualified name identifiers
+      // so we will use the same approach to compare them
+
+      std::stringstream strOutput;
+      pmap_cit thisEnd = this->m_map.end();
+      pmap_cit rhsEnd = rhs.m_map.end();
+      for(pmap_cit thisIt = this->m_map.begin(); thisIt != thisEnd; ++thisIt)
+      {
+        const IComponent * comp = static_cast<IComponent*>(thisIt->first);
+        const std::string fullName = comp->getFullName();
+        const auto & param = thisIt->second;
+        bool match(false);
+        for(pmap_cit rhsIt = rhs.m_map.begin(); rhsIt != rhsEnd; ++rhsIt)
+        {
+          const IComponent * rhsComp = static_cast<IComponent*>(rhsIt->first);
+          const std::string rhsFullName = rhsComp->getFullName();
+          if(fullName == rhsFullName && (*param) == (*rhsIt->second))
+          {
+            match = true;
+            break;
+          }
+        }
+
+        if(!match) 
+        {
+          // output some information that helps with understanding the mismatch
+          strOutput << "Parameter mismatch LHS=RHS for LHS parameter in component with name: " << fullName
+            << ". Parameter name is: " << (*param).name() << " and value: " << (*param).asString() << std::endl;
+          bool componentWithSameNameRHS = false;
+          bool parameterWithSameNameRHS = false;
+          for(pmap_cit rhsIt = rhs.m_map.begin(); rhsIt != rhsEnd; ++rhsIt)
+          {
+            const IComponent * rhsComp = static_cast<IComponent*>(rhsIt->first);
+            const std::string rhsFullName = rhsComp->getFullName();
+            if(fullName == rhsFullName)
+            {
+              componentWithSameNameRHS = true;
+              if ((*param).name() == (*rhsIt->second).name())
+              {
+                parameterWithSameNameRHS = true;
+                strOutput << "RHS param with same name has value: " << (*rhsIt->second).asString() << std::endl;
+              }
+            }
+          }
+          if (!componentWithSameNameRHS)
+          {
+            strOutput << "No matching RHS component name" << std::endl;
+          }
+          if (componentWithSameNameRHS && !parameterWithSameNameRHS)
+          {
+            strOutput << "Found matching RHS component name but not parameter name" << std::endl;
+          }
+          if (firstDiffOnly)
+            return strOutput.str();
+        }
+      }
+      return strOutput.str();
+    }
+
     /**
      * Clear any parameters with the given name
      * @param name :: The name of the parameter
diff --git a/Code/Mantid/Framework/Geometry/test/ObjectTest.h b/Code/Mantid/Framework/Geometry/test/ObjectTest.h
index 91783e1a9dd3923f62ac4337ad2ea41494d52b48..f32e628f9fa4f44fa751a1bae1c82f8f993d0150 100644
--- a/Code/Mantid/Framework/Geometry/test/ObjectTest.h
+++ b/Code/Mantid/Framework/Geometry/test/ObjectTest.h
@@ -569,25 +569,10 @@ public:
     // where R is sphere radius and r is distance of observer from sphere centre
     // Intercept for track in reverse direction now worked round
     TS_ASSERT_DELTA(geom_obj->rayTraceSolidAngle(V3D(8.1,0,0)),0.864364,satol);
-    TS_ASSERT_DELTA(geom_obj->rayTraceSolidAngle(V3D(0,8.1,0)),0.864364,satol);
-    TS_ASSERT_DELTA(geom_obj->rayTraceSolidAngle(V3D(0,0,8.1)),0.864364,satol);
-    TS_ASSERT_DELTA(geom_obj->rayTraceSolidAngle(V3D(0,0,-8.1)),0.864364,satol);
     // internal point (should be 4pi)
     TS_ASSERT_DELTA(geom_obj->rayTraceSolidAngle(V3D(0,0,0)),4*M_PI,satol);
     // surface point
     TS_ASSERT_DELTA(geom_obj->rayTraceSolidAngle(V3D(4.1,0,0)),2*M_PI,satol);
-    // distant points
-    TS_ASSERT_DELTA(geom_obj->rayTraceSolidAngle(V3D(20,0,0)),0.133442,satol);
-    TS_ASSERT_DELTA(geom_obj->rayTraceSolidAngle(V3D(200,0,0)),0.0013204,satol);
-    TS_ASSERT_DELTA(geom_obj->rayTraceSolidAngle(V3D(2000,0,0)),1.32025e-5,satol);
-    //
-    // test solidAngle interface, which will be main method to solid angle
-    //
-    TS_ASSERT_DELTA(geom_obj->solidAngle(V3D(8.1,0,0)),0.864364,satol);
-    TS_ASSERT_DELTA(geom_obj->solidAngle(V3D(0,8.1,0)),0.864364,satol);
-    TS_ASSERT_DELTA(geom_obj->solidAngle(V3D(0,0,8.1)),0.864364,satol);
-    TS_ASSERT_DELTA(geom_obj->solidAngle(V3D(0,0,-8.1)),0.864364,satol);
-    //
   }
 
 
@@ -645,27 +630,6 @@ public:
     TS_ASSERT_DELTA(geom_obj->triangleSolidAngle(V3D(0,-1.0,0)),M_PI*2.0/3.0,satol);
     TS_ASSERT_DELTA(geom_obj->triangleSolidAngle(V3D(0,0,1.0)),M_PI*2.0/3.0,satol);
     TS_ASSERT_DELTA(geom_obj->triangleSolidAngle(V3D(0,0,-1.0)),M_PI*2.0/3.0,satol);
-
-//    if(timeTest)
-//    {
-//      // block to test time of solid angle methods
-//      // change false to true to include
-//      double saRay,saTri;
-//      V3D observer(1.0,0,0);
-//      int iter=4000;
-//      int starttime=clock();
-//      for (int i=0;i<iter;i++)
-//        saTri=geom_obj->triangleSolidAngle(observer);
-//      int endtime=clock();
-//      std::cout << std::endl << "Cube tri time=" << (endtime-starttime)/(static_cast<double>(CLOCKS_PER_SEC*iter)) << std::endl;
-//      iter=50;
-//      starttime=clock();
-//      for (int i=0;i<iter;i++)
-//        saRay=geom_obj->rayTraceSolidAngle(observer);
-//      endtime=clock();
-//      std::cout << "Cube ray time=" << (endtime-starttime)/(static_cast<double>(CLOCKS_PER_SEC*iter)) << std::endl;
-//    }
-
   }
 
 
@@ -796,38 +760,10 @@ public:
     // where R is sphere radius and r is distance of observer from sphere centre
     // Intercept for track in reverse direction now worked round
     TS_ASSERT_DELTA(geom_obj->triangleSolidAngle(V3D(8.1,0,0)),0.864364,satol);
-    TS_ASSERT_DELTA(geom_obj->triangleSolidAngle(V3D(0,8.1,0)),0.864364,satol);
-    TS_ASSERT_DELTA(geom_obj->triangleSolidAngle(V3D(0,0,8.1)),0.864364,satol);
-    TS_ASSERT_DELTA(geom_obj->triangleSolidAngle(V3D(0,0,-8.1)),0.864364,satol);
     // internal point (should be 4pi)
     TS_ASSERT_DELTA(geom_obj->triangleSolidAngle(V3D(0,0,0)),4*M_PI,satol);
     // surface point
     TS_ASSERT_DELTA(geom_obj->triangleSolidAngle(V3D(4.1,0,0)),2*M_PI,satol);
-    // distant points
-    TS_ASSERT_DELTA(geom_obj->triangleSolidAngle(V3D(20,0,0)),0.133442,satol*0.133);
-    TS_ASSERT_DELTA(geom_obj->triangleSolidAngle(V3D(200,0,0)),0.0013204,satol*0.00132);
-    TS_ASSERT_DELTA(geom_obj->triangleSolidAngle(V3D(2000,0,0)),1.32025e-5,satol*1.32e-5);
-
-//    if(timeTest)
-//    {
-//      // block to test time of solid angle methods
-//      // change false to true to include
-//      double saTri,saRay;
-//      int iter=400;
-//      V3D observer(8.1,0,0);
-//      int starttime=clock();
-//      for (int i=0;i<iter;i++)
-//        saTri=geom_obj->triangleSolidAngle(observer);
-//      int endtime=clock();
-//      std::cout << std::endl << "Sphere tri time =" << (endtime-starttime)/(static_cast<double>(CLOCKS_PER_SEC*iter)) << std::endl;
-//      iter=40;
-//      starttime=clock();
-//      for (int i=0;i<iter;i++)
-//        saRay=geom_obj->rayTraceSolidAngle(observer);
-//      endtime=clock();
-//      std::cout << "Sphere ray time =" << (endtime-starttime)/(static_cast<double>(CLOCKS_PER_SEC*iter)) << std::endl;
-//    }
-
   }
 
 private:
diff --git a/Code/Mantid/Framework/Geometry/test/ParameterMapTest.h b/Code/Mantid/Framework/Geometry/test/ParameterMapTest.h
index 6be82c348135aaf95e020053731c62447e3341cc..207c89741f8f961629482a3b6deb1c4d12247596 100644
--- a/Code/Mantid/Framework/Geometry/test/ParameterMapTest.h
+++ b/Code/Mantid/Framework/Geometry/test/ParameterMapTest.h
@@ -130,6 +130,31 @@ public:
 
   }
 
+  void test_Diff_Method()
+  {
+    const std::string name("TestName");
+    const double value(5.1);
+   
+    ParameterMap pmapA;
+    ParameterMap pmapB;
+    // Empty
+    TS_ASSERT_EQUALS(pmapA.diff(pmapB), "");
+    TS_ASSERT_EQUALS(pmapA.diff(pmapA), "");
+    
+    pmapA.addDouble(m_testInstrument.get(), name, value);
+    TS_ASSERT_DIFFERS(pmapA.diff(pmapB), "");
+
+    pmapB.addDouble(m_testInstrument.get(), name, value);
+    TS_ASSERT_EQUALS(pmapA.diff(pmapB), "");
+
+    pmapA.addDouble(m_testInstrument.get(), name, value);
+    pmapB.addDouble(m_testInstrument.get(), name, 5.2);
+    pmapA.addDouble(m_testInstrument.get(), name+"2", value);
+    pmapB.addDouble(m_testInstrument.get(), name+"2", 5.3);
+    TS_ASSERT_DIFFERS(pmapA.diff(pmapB), "");
+    TS_ASSERT_DIFFERS(pmapA.diff(pmapB), "");
+  }
+
   void testClone()
   {
     const double value(5.1);
diff --git a/Code/Mantid/Framework/ICat/src/ICat3/ICat3Catalog.cpp b/Code/Mantid/Framework/ICat/src/ICat3/ICat3Catalog.cpp
index 17ce2110e7006b3002f0609c161c42a0efbec1df..9843f9300da395ffea3df1eb208208f96212653c 100644
--- a/Code/Mantid/Framework/ICat/src/ICat3/ICat3Catalog.cpp
+++ b/Code/Mantid/Framework/ICat/src/ICat3/ICat3Catalog.cpp
@@ -14,7 +14,7 @@ namespace Mantid
     ICat3Catalog::ICat3Catalog() : m_helper(new CICatHelper()) {}
 
     /// destructor
-    ICat3Catalog::~ICat3Catalog() {}
+    ICat3Catalog::~ICat3Catalog() {delete m_helper;}
 
     /**
      * Authenticate the user against all catalogues in the container.
diff --git a/Code/Mantid/Framework/ICat/src/ICat3/ICat3Helper.cpp b/Code/Mantid/Framework/ICat/src/ICat3/ICat3Helper.cpp
index 6f9cc365d340c9b75f7b236e8007d114e6cb777e..6cbeebfb7e8e37f73fc1de52f23baf90d0263998 100644
--- a/Code/Mantid/Framework/ICat/src/ICat3/ICat3Helper.cpp
+++ b/Code/Mantid/Framework/ICat/src/ICat3/ICat3Helper.cpp
@@ -196,6 +196,8 @@ namespace Mantid
             creationtime->assign(ftime);
           }
           savetoTableWorkspace(creationtime,t);
+          if (creationtime)
+            delete creationtime;
 
 
           // 
diff --git a/Code/Mantid/Framework/Kernel/inc/MantidKernel/CompositeValidator.h b/Code/Mantid/Framework/Kernel/inc/MantidKernel/CompositeValidator.h
index 82186c0051bbd018b6b3a060f34455627c95dd14..36b57a0204b5f6edb5536133368c1e1e43d806b7 100644
--- a/Code/Mantid/Framework/Kernel/inc/MantidKernel/CompositeValidator.h
+++ b/Code/Mantid/Framework/Kernel/inc/MantidKernel/CompositeValidator.h
@@ -49,7 +49,7 @@ namespace Kernel
     ///Gets the type of the validator
     std::string getType() const { return "composite"; }
     /// Return the instersection of allowed values from children
-    std::set<std::string> allowedValues() const;
+    std::vector<std::string> allowedValues() const;
     /// Clones this and the children into a new Validator
     IValidator_sptr clone() const;
     /// Adds a validator to the group of validators to check
diff --git a/Code/Mantid/Framework/Kernel/inc/MantidKernel/DataService.h b/Code/Mantid/Framework/Kernel/inc/MantidKernel/DataService.h
index db8bd96fbd7f4888a3eb09ab11b43b5a9d9b2343..e911dd5de36ade06c7e2e28482bd88512a1b9d59 100644
--- a/Code/Mantid/Framework/Kernel/inc/MantidKernel/DataService.h
+++ b/Code/Mantid/Framework/Kernel/inc/MantidKernel/DataService.h
@@ -18,10 +18,10 @@ namespace Mantid
 {
 namespace Kernel
 {
-/** DataService is the base class for storing DataObjects. It stores instances of DataObjects
-    (Workspace, Instrument, MappingTables,...). This is a templated class, implemented as a
+/** DataService stores instances of a given type.
+    This is a templated class, designed to be implemented as a
     singleton. For simplicity and naming conventions, specialized classes must be constructed. The specialized
-    classes (see example MantidAPI/InstrumentDataService.h) must simply :
+    classes must simply:
     1) call the BaseClass constructor with the Name of the service
     2) Support the SingletonHolder templated class.
     This is the primary data service that  the users will interact with either through writing scripts or directly
@@ -68,7 +68,7 @@ public:
         Poco::Notification(), m_name(name) {}
 
       /// Returns the name of the object
-      std::string object_name()const{return m_name;}
+      std::string objectName()const {return m_name;}
     private:
       std::string m_name;///< object's name
     };
@@ -79,7 +79,7 @@ public:
     public:
         /// Constructor
         DataServiceNotification(const std::string& name, const boost::shared_ptr<T> obj)
-          : NamedObjectNotification(name), m_object(obj){}
+          : NamedObjectNotification(name), m_object(obj) {}
         /// Returns the const pointer to the object concerned or 0 if it is a general notification
         const boost::shared_ptr<T> object()const{return m_object;}
     private:
@@ -91,7 +91,8 @@ public:
     class AddNotification: public DataServiceNotification
     {
     public:
-        AddNotification(const std::string& name,const boost::shared_ptr<T> obj):DataServiceNotification(name,obj){}///< Constructor
+        AddNotification(const std::string& name,const boost::shared_ptr<T> obj) :
+          DataServiceNotification(name,obj) {}///< Constructor
     };
 
 
@@ -103,14 +104,15 @@ public:
 
             @param name :: The name of the replaced object
             @param obj ::  The pointer to the old object
-            @param new_obj :: The pointer to the new object
+            @param newObj :: The pointer to the new object
 
             Both old and new objects are guaranteed to exist when an observer receives the notification.
         */
-        BeforeReplaceNotification(const std::string& name, const boost::shared_ptr<T> obj,const boost::shared_ptr<T> new_obj):DataServiceNotification(name,obj),m_new_object(new_obj){}
-        const boost::shared_ptr<T> new_object()const{return m_new_object;}///< Returns the pointer to the new object.
+        BeforeReplaceNotification(const std::string& name, const boost::shared_ptr<T> obj,const boost::shared_ptr<T> newObj)
+          : DataServiceNotification(name,obj),m_newObject(newObj) {}
+        const boost::shared_ptr<T> newObject()const{return m_newObject;}///< Returns the pointer to the new object.
     private:
-        boost::shared_ptr<T> m_new_object;///< shared pointer to the object
+        boost::shared_ptr<T> m_newObject;///< shared pointer to the object
     };
 
     /// AfterReplaceNotification is sent after an object is replaced in the addOrReplace() function.
@@ -119,10 +121,11 @@ public:
     public:
         /** Constructor.
           * @param name :: The name of the replaced object
-          *  @param new_obj :: The pointer to the new object
+          *  @param newObj :: The pointer to the new object
           *  Only new objects are guaranteed to exist when an observer receives the notification.
         */
-        AfterReplaceNotification(const std::string& name, const boost::shared_ptr<T> new_obj):DataServiceNotification(name,new_obj) {}
+        AfterReplaceNotification(const std::string& name, const boost::shared_ptr<T> newObj)
+           : DataServiceNotification(name, newObj) {}
     };
 
     /// PreDeleteNotification is sent before an object is deleted from the data service.
@@ -132,7 +135,8 @@ public:
     {
     public:
       /// Constructor
-      PreDeleteNotification(const std::string& name,const boost::shared_ptr<T> obj):DataServiceNotification(name,obj){}
+      PreDeleteNotification(const std::string& name,const boost::shared_ptr<T> obj)
+        : DataServiceNotification(name, obj){}
     };
 
     /// PostDeleteNotification is sent after an object is deleted from the data service.
@@ -142,7 +146,8 @@ public:
     {
     public:
       /// Constructor
-      PostDeleteNotification(const std::string& name):NamedObjectNotification(name) {}
+      PostDeleteNotification(const std::string& name)
+        : NamedObjectNotification(name) {}
     };
 
     /// Clear notification is sent when the service is cleared
@@ -152,18 +157,18 @@ public:
       ///Constructor
       ClearNotification() :  NamedObjectNotification("") {}
     };
-    /// Rename notification is sent from Renameworkspaces algorithm after a workspace is renamed
+    /// Rename notification is sent when the rename method is called
     class RenameNotification: public NamedObjectNotification
     {
     public:
         /// Constructor
-      RenameNotification(const std::string& name,const std::string& newwsname) :
-        NamedObjectNotification(name), m_outwsname(newwsname){}
+      RenameNotification(const std::string& name,const std::string& newName) :
+        NamedObjectNotification(name), m_newName(newName){}
 
-      ///name of the new workspace
-      const std::string& new_objectname()const{return m_outwsname;}
+      /// New name for the object
+      const std::string& newObjectName()const{return m_newName;}
     private:
-      std::string m_outwsname; ///< output workspace name
+      std::string m_newName; ///< New object name
     };
 
   //--------------------------------------------------------------------------
@@ -182,9 +187,9 @@ public:
     // Make DataService access thread-safe
     m_mutex.lock();
 
-    // At the moment, you can't overwrite a workspace (i.e. pass in a name
-    // that's already in the map with a pointer to a different workspace).
-    // Also, there's nothing to stop the same workspace from being added
+    // At the moment, you can't overwrite an object (i.e. pass in a name
+    // that's already in the map with a pointer to a different object).
+    // Also, there's nothing to stop the same object from being added
     // more than once with different names.
     if ( ! datamap.insert(typename svcmap::value_type(name, Tobject)).second)
     {
@@ -259,12 +264,19 @@ public:
       m_mutex.unlock();
       return;
     }
+    // The map is shared across threads so the item is erased from the map before
+    // unlocking the mutex and is held in a local stack variable.
+    // This protects it from being modified by another thread.
+    auto data = it->second;
+    datamap.erase(it);
+
+    // Do NOT use "it" iterator after this point. Other threads may modify the map
     m_mutex.unlock();
-    notificationCenter.postNotification(new PreDeleteNotification(foundName,it->second));
+    notificationCenter.postNotification(new PreDeleteNotification(foundName, data));
     m_mutex.lock();
 
+    data.reset(); // DataService now has no references to the object
     g_log.information("Data Object '"+ foundName +"' deleted from data service.");
-    datamap.erase(it);
 
     m_mutex.unlock();
     notificationCenter.postNotification(new PostDeleteNotification(foundName));
@@ -466,7 +478,7 @@ public:
 
 protected:
   /// Protected constructor (singleton)
-  DataService(const std::string& name) : svc_name(name),g_log(svc_name) {}
+  DataService(const std::string& name) : svcName(name), g_log(svcName) {}
   virtual ~DataService(){}
 
 private:
@@ -534,7 +546,7 @@ private:
   }
 
   /// DataService name. This is set only at construction. DataService name should be provided when construction of derived classes
-  const std::string svc_name;
+  const std::string svcName;
   /// Map of objects in the data service
   svcmap datamap;
   /// Recursive mutex to avoid simultaneous access or notifications
diff --git a/Code/Mantid/Framework/Kernel/inc/MantidKernel/DirectoryValidator.h b/Code/Mantid/Framework/Kernel/inc/MantidKernel/DirectoryValidator.h
index d16ff94d82222aea032ed5378818500c08b7c176..9b19d4c9a3857d7beead50ad613a89bc2fb09db3 100644
--- a/Code/Mantid/Framework/Kernel/inc/MantidKernel/DirectoryValidator.h
+++ b/Code/Mantid/Framework/Kernel/inc/MantidKernel/DirectoryValidator.h
@@ -44,7 +44,7 @@ class MANTID_KERNEL_DLL DirectoryValidator : public FileValidator
 public:
   explicit DirectoryValidator(bool testDirectoryExists = true);
   virtual ~DirectoryValidator();
-  virtual std::set<std::string> allowedValues() const;
+  virtual std::vector<std::string> allowedValues() const;
   IValidator_sptr clone() const;
 
 private:
diff --git a/Code/Mantid/Framework/Kernel/inc/MantidKernel/DynamicFactory.h b/Code/Mantid/Framework/Kernel/inc/MantidKernel/DynamicFactory.h
index b74a1ed341cdf49d3cd389d677ef163abf74a850..cc1d8e6b6ecd04da3e24ea7e9146aa45806b2a92 100644
--- a/Code/Mantid/Framework/Kernel/inc/MantidKernel/DynamicFactory.h
+++ b/Code/Mantid/Framework/Kernel/inc/MantidKernel/DynamicFactory.h
@@ -20,6 +20,8 @@
 #include <Poco/AutoPtr.h>
 
 // std
+#include <cstring>
+#include <functional>
 #include <map>
 #include <vector>
 
@@ -32,6 +34,20 @@ namespace Kernel
   // Forward declarations
   //----------------------------------------------------------------------------
   class Logger; 
+  
+  typedef std::less<std::string> CaseSensitiveStringComparator;
+  struct CaseInsensitiveStringComparator
+  {
+    bool operator() (const std::string & s1, const std::string & s2) const
+    {
+#ifdef _MSC_VER
+	    return stricmp(s1.c_str(), s2.c_str()) < 0;
+#else
+	    return strcasecmp(s1.c_str(), s2.c_str()) < 0;
+#endif
+    }
+  };
+
     
 /** @class DynamicFactory DynamicFactory.h Kernel/DynamicFactory.h
 
@@ -61,7 +77,7 @@ namespace Kernel
     File change history is stored at: <https://github.com/mantidproject/mantid>.
     Code Documentation is available at: <http://doxygen.mantidproject.org>
 */
-template <class Base>
+template <class Base, class Comparator = CaseInsensitiveStringComparator >
 class DynamicFactory
 {
 
@@ -96,7 +112,7 @@ public:
   }
 
   /**
-   * Enable notifications
+   * Disable notifications
    */
   void disableNotifications()
   {
@@ -266,7 +282,7 @@ private:
   }
 
   /// A typedef for the map of registered classes
-  typedef std::map<std::string, AbstractFactory*> FactoryMap;
+  typedef std::map<std::string, AbstractFactory*,Comparator> FactoryMap;
   /// The map holding the registered class names and their instantiators
   FactoryMap _map;
   /// Flag marking whether we should dispatch notifications
diff --git a/Code/Mantid/Framework/Kernel/inc/MantidKernel/FileValidator.h b/Code/Mantid/Framework/Kernel/inc/MantidKernel/FileValidator.h
index f6d444dba8ba829759b51622c27f6ccc22885f5e..baf9f6607eb09e0cfcd89c0f5922379fae159e29 100644
--- a/Code/Mantid/Framework/Kernel/inc/MantidKernel/FileValidator.h
+++ b/Code/Mantid/Framework/Kernel/inc/MantidKernel/FileValidator.h
@@ -44,12 +44,12 @@ class MANTID_KERNEL_DLL FileValidator : public TypedValidator<std::string>
 public:
   explicit FileValidator(const std::vector<std::string>& extensions=std::vector<std::string>(), bool testFileExists = true, bool testCanWrite=false);
   virtual ~FileValidator();
-  virtual std::set<std::string> allowedValues() const;
+  virtual std::vector<std::string> allowedValues() const;
   IValidator_sptr clone() const;
 
 protected:
   /// The list of permitted extensions
-  const std::set<std::string> m_extensions;
+  std::vector<std::string> m_extensions;
   /// Flag indicating whether to test for existence of filename
   bool m_testExist;
   /// Flag indicating whether to test for the file being writable
diff --git a/Code/Mantid/Framework/Kernel/inc/MantidKernel/IValidator.h b/Code/Mantid/Framework/Kernel/inc/MantidKernel/IValidator.h
index 47bf2b7dcc950e7616420cb1941a568d0159d7df..a11813143626ee6300f057a3ff124adb9a637816 100644
--- a/Code/Mantid/Framework/Kernel/inc/MantidKernel/IValidator.h
+++ b/Code/Mantid/Framework/Kernel/inc/MantidKernel/IValidator.h
@@ -14,9 +14,10 @@
 # include <boost/type_traits/is_convertible.hpp>
 # include <boost/type_traits/is_pointer.hpp>
 #endif
-#include <set>
+#include <vector>
 #include <string>
 #include <sstream>
+#include <stdexcept>
 
 namespace Mantid
 {
@@ -106,7 +107,15 @@ public:
    *  Overridden in applicable concrete validators; the base class just returns an empty set.
    *  @return The set of allowed values that this validator may have or an empty set
    */
-  virtual std::set<std::string> allowedValues() const { return std::set<std::string>(); }
+  virtual std::vector<std::string> allowedValues() const { return std::vector<std::string>(); }
+
+  /**
+   * Implement this method for validators which wish to support aliasing for alloeed values.
+   * @param alias :: A string representation of an alias.
+   * @return :: A string representation of an aliased value. Should throw std::invalid_argument
+   *    is the given alias is invalid.
+   */
+  virtual std::string getValueForAlias(const std::string& alias) const { UNUSED_ARG(alias); throw std::invalid_argument("Validator does'n support value aliasing.") ;}
   
   /// Make a copy of the present type of validator
   virtual IValidator_sptr clone() const = 0;
diff --git a/Code/Mantid/Framework/Kernel/inc/MantidKernel/Interpolation.h b/Code/Mantid/Framework/Kernel/inc/MantidKernel/Interpolation.h
index 04185c419d4d1ec10c59155dbaa25caece63128e..417c166cf5424daf51e719fda4f22e419278d215 100644
--- a/Code/Mantid/Framework/Kernel/inc/MantidKernel/Interpolation.h
+++ b/Code/Mantid/Framework/Kernel/inc/MantidKernel/Interpolation.h
@@ -62,10 +62,14 @@ private:
   /// unit of y-axis
   Unit_sptr m_yUnit;
 
+protected:
+  size_t findIndexOfNextLargerValue(const std::vector<double> &data, double key, size_t range_start, size_t range_end) const;
+
 public:
 
   /// Constructor default to linear interpolation and x-unit set to TOF
   Interpolation();
+  virtual ~Interpolation() { }
 
   /// add data point
   void addPoint(const double& xx, const double& yy);
@@ -97,6 +101,8 @@ public:
   /// Prints object to stream
   void printSelf(std::ostream& os) const;
 
+  /// Clear interpolation values
+  void resetData();
 };
 
 // defining operator << and >>
diff --git a/Code/Mantid/Framework/Kernel/inc/MantidKernel/ListValidator.h b/Code/Mantid/Framework/Kernel/inc/MantidKernel/ListValidator.h
index 8fd5e39a274253041023bba14aced81713f25ac9..517b7441b2004417917e6db9ff969f902e5d1ae7 100644
--- a/Code/Mantid/Framework/Kernel/inc/MantidKernel/ListValidator.h
+++ b/Code/Mantid/Framework/Kernel/inc/MantidKernel/ListValidator.h
@@ -9,6 +9,7 @@
 # include <boost/lexical_cast.hpp>
 #endif
 #include <vector>
+#include <map>
 
 namespace Mantid
 {
@@ -56,10 +57,19 @@ public:
   }
 
   /** Constructor
-   *  @param values :: A vector of the valid values     */
-  explicit ListValidator(const std::vector<TYPE>& values):
-    TypedValidator<TYPE>(), m_allowedValues(values.begin(), values.end())
+   *  @param values :: A vector of the valid values     
+   *  @param aliases :: Optional aliases for the valid values.
+   */
+  explicit ListValidator(const std::vector<TYPE>& values, const std::map<std::string,std::string>& aliases = std::map<std::string,std::string>()):
+    TypedValidator<TYPE>(), m_allowedValues(values.begin(), values.end()), m_aliases(aliases.begin(),aliases.end())
   {
+    for(auto aliasIt = m_aliases.begin(); aliasIt != m_aliases.end(); ++aliasIt)
+    {
+      if ( values.end() == std::find( values.begin(), values.end(), boost::lexical_cast<TYPE>(aliasIt->second) ) )
+      {
+        throw std::invalid_argument("Alias " + aliasIt->first + " referes to invalid value " + aliasIt->second);
+      }
+    }
   }
   /// Destructor
   virtual ~ListValidator(){};
@@ -69,26 +79,47 @@ public:
    * Returns the set of allowed values currently defined
    * @returns A set of allowed values that this validator will currently allow
    */
-  std::set<std::string> allowedValues() const
+  std::vector<std::string> allowedValues() const
   {
     /// The interface requires strings
-    std::set<std::string> allowedStrings;
+    std::vector<std::string> allowedStrings;
+    allowedStrings.reserve(m_allowedValues.size());
     auto cend = m_allowedValues.end();
     for(auto cit = m_allowedValues.begin(); cit != cend; ++cit)
     {
-      allowedStrings.insert(boost::lexical_cast<std::string>(*cit));
+      allowedStrings.push_back(boost::lexical_cast<std::string>(*cit));
     }
     return allowedStrings;
   }
 
   /**
-   * Add value to the list of allowable values
+   * Add value to the list of allowable values if it's not already there
    * @param value :: A value of the templated type
    */
   void addAllowedValue(const TYPE &value)
   {
-    m_allowedValues.insert(value);
+    // add only new values
+    if ( std::find( m_allowedValues.begin(), m_allowedValues.end(), value ) == m_allowedValues.end() )
+    {
+      m_allowedValues.push_back(value);
+    }
+  }
+
+  /**
+   * Return an allowed value (as a string) given an alias.
+   * @param alias :: An alias string.
+   * @return :: Allowed value or throw if alias is unknown.
+   */
+  std::string getValueForAlias(const std::string& alias) const
+  {
+    auto aliasIt = m_aliases.find( alias );
+    if ( aliasIt == m_aliases.end() )
+    {
+      throw std::invalid_argument("Unknown alias found " + alias);
+    }
+    return aliasIt->second;
   }
+
 protected:
   /** Checks if the string passed is in the list
    *  @param value :: The value to test
@@ -96,13 +127,14 @@ protected:
    */
   std::string checkValidity(const TYPE & value) const
   {
-    if ( m_allowedValues.count(value) )
+    if ( m_allowedValues.end() != std::find( m_allowedValues.begin(), m_allowedValues.end(), value ) )
     {
       return "";
     }
     else
     {
       if ( isEmpty(value) ) return "Select a value";
+      if ( isAlias(value) ) return "_alias";
       std::ostringstream os;
       os << "The value \"" << value << "\" is not in the list of allowed values";
       return os.str();
@@ -123,8 +155,32 @@ protected:
    */
   bool isEmpty(const std::string & value) const { return value.empty(); }
 
+  /**
+   * Test if a value is an alias of an alowed value.
+   * @param value :: Value to test.
+   * @return :: True if it's an alias.
+   */
+  template<typename T>
+  bool isAlias(const T& value) const 
+  { 
+    std::string strValue = boost::lexical_cast<std::string>( value );
+    return m_aliases.find( strValue ) != m_aliases.end();
+  }
+
+  /**
+   * Test if a value is an alias of an alowed value.
+   * @param value :: Value to test.
+   * @return :: True if it's an alias.
+   */
+  bool isAlias(const std::string & value) const 
+  { 
+    return m_aliases.find( value ) != m_aliases.end();
+  }
+
   /// The set of valid values
-  std::set<TYPE> m_allowedValues;
+  std::vector<TYPE> m_allowedValues;
+  /// The optional aliases for the allowed values.
+  std::map<std::string,std::string> m_aliases;
 };
 
 /// ListValidator<std::string> is used heavily
diff --git a/Code/Mantid/Framework/Kernel/inc/MantidKernel/MultiFileValidator.h b/Code/Mantid/Framework/Kernel/inc/MantidKernel/MultiFileValidator.h
index b784cdd1b773786064595bbe0fd13f0ae5b07b2b..cec9ca9815a1cbefa24969c44eb5ab151282bf50 100644
--- a/Code/Mantid/Framework/Kernel/inc/MantidKernel/MultiFileValidator.h
+++ b/Code/Mantid/Framework/Kernel/inc/MantidKernel/MultiFileValidator.h
@@ -51,7 +51,7 @@ public:
   IValidator_sptr clone() const;
 
   /// Returns the set of allowed extensions.
-  virtual std::set<std::string> allowedValues() const;
+  virtual std::vector<std::string> allowedValues() const;
 
 protected:
   /// FileValidator instance used for validating multiple files.
diff --git a/Code/Mantid/Framework/Kernel/inc/MantidKernel/Property.h b/Code/Mantid/Framework/Kernel/inc/MantidKernel/Property.h
index 570ed6f9f3320581fda207f86ee5b4100cd4b613..f12efa4e601373d8e9729f98fb4a5dfc4d7af2a5 100644
--- a/Code/Mantid/Framework/Kernel/inc/MantidKernel/Property.h
+++ b/Code/Mantid/Framework/Kernel/inc/MantidKernel/Property.h
@@ -137,7 +137,7 @@ public:
   /// Get the default value for the property which is the value the property was initialised with
   virtual std::string getDefault() const = 0;
 
-  virtual std::set<std::string> allowedValues() const;
+  virtual std::vector<std::string> allowedValues() const;
 
   virtual const PropertyHistory createHistory() const;
 
diff --git a/Code/Mantid/Framework/Kernel/inc/MantidKernel/PropertyWithValue.h b/Code/Mantid/Framework/Kernel/inc/MantidKernel/PropertyWithValue.h
index 167cf066263e7c0243e8ae68cb75255b33c56962..35ad67d7241e832a2ad2114f29c5fbb6bee5ab88 100644
--- a/Code/Mantid/Framework/Kernel/inc/MantidKernel/PropertyWithValue.h
+++ b/Code/Mantid/Framework/Kernel/inc/MantidKernel/PropertyWithValue.h
@@ -439,6 +439,11 @@ public:
     {
       return m_value;
     }
+    else if ( problem == "_alias" )
+    {
+      m_value = getValueForAlias( value );
+      return m_value;
+    }
     else
     {
       m_value = oldValue;
@@ -486,7 +491,7 @@ public:
    *  If not, it returns an empty vector.
    *  @return Returns the set of valid values for this property, or it returns an empty vector.
    */
-  virtual std::set<std::string> allowedValues() const
+  virtual std::vector<std::string> allowedValues() const
   {
     return m_validator->allowedValues();
   }
@@ -565,6 +570,19 @@ private:
       return "Attempt to assign object of type DataItem to property (" + name() + ") of incorrect type";
     }
 
+  /** Return value for a given alias.
+   * @param alias :: An alias for a value. If a value cannot be found throw an invalid_argument exception.
+   * @return :: A value.
+   */
+  const TYPE getValueForAlias(const TYPE& alias) const
+  {
+    std::string strAlias = toString( alias );
+    std::string strValue = m_validator->getValueForAlias( strAlias );
+    TYPE value;
+    toValue( strValue, value );
+    return value;
+  }
+
   /// Visitor validator class
   IValidator_sptr m_validator;
 
diff --git a/Code/Mantid/Framework/Kernel/inc/MantidKernel/Quat.h b/Code/Mantid/Framework/Kernel/inc/MantidKernel/Quat.h
index 7fa9744e5dd3e765ca36967a7dabbaa76d4ba367..1ae1ba924d287dc854e8f64b10de6f21f27b39b2 100644
--- a/Code/Mantid/Framework/Kernel/inc/MantidKernel/Quat.h
+++ b/Code/Mantid/Framework/Kernel/inc/MantidKernel/Quat.h
@@ -76,6 +76,7 @@ namespace Mantid
       void set(const double ww, const double aa, const double bb, const double cc);
       void setAngleAxis(const double _deg, const V3D& _axis);
       void getAngleAxis(double& _deg,double& _axis1,double& _axis2,double& axis3) const;
+      std::vector<double> getEulerAngles(const std::string& convention) const;
       /// Set the rotation (both don't change rotation axis)
       void setRotation(const double deg);
       //! Norm of a quaternion
diff --git a/Code/Mantid/Framework/Kernel/inc/MantidKernel/Unit.h b/Code/Mantid/Framework/Kernel/inc/MantidKernel/Unit.h
index 3e3e42603a596303919a180585cd26af7ce2ead2..bff8349b08b69edc5ad88e1e66345caffb23665a 100644
--- a/Code/Mantid/Framework/Kernel/inc/MantidKernel/Unit.h
+++ b/Code/Mantid/Framework/Kernel/inc/MantidKernel/Unit.h
@@ -75,6 +75,10 @@ public:
   /// @return The unit label
   virtual const UnitLabel label() const = 0;
 
+  //Equality operators based on the value returned by unitID();
+  bool operator==(const Unit& u) const;
+  bool operator!=(const Unit& u) const;
+
   // Check whether the unit can be converted to another via a simple factor
   bool quickConversion(const Unit& destination, double& factor, double& power) const;
   bool quickConversion(std::string destUnitName, double& factor, double& power) const;
diff --git a/Code/Mantid/Framework/Kernel/inc/MantidKernel/V3D.h b/Code/Mantid/Framework/Kernel/inc/MantidKernel/V3D.h
index 75c2f53a9c769e7744a82e90a6affff8eef8d22f..6773bfbf3e465b4e1aa552139dd6993ccca9768c 100644
--- a/Code/Mantid/Framework/Kernel/inc/MantidKernel/V3D.h
+++ b/Code/Mantid/Framework/Kernel/inc/MantidKernel/V3D.h
@@ -109,16 +109,18 @@ namespace Mantid
       double norm2() const;
       /// transform vector into form, used to describe directions in crystallogaphical coodinate system
       double   toMillerIndexes(double eps=1.e-3);
-      // Scalar product
+      /// Scalar product
       double scalar_prod(const V3D&) const;
-      // Cross product
+      /// Cross product
       V3D cross_prod(const V3D&) const;
-      // Distance (R) between two points defined as vectors
+      /// Distance (R) between two points defined as vectors
       double distance(const V3D&) const;
-      // Zenith (theta) angle between this and another vector
+      /// Zenith (theta) angle between this and another vector
       double zenith(const V3D&) const;
-      // Angle between this and another vector
+      /// Angle between this and another vector
       double angle(const V3D&) const;
+      /// Direction angles
+      V3D directionAngles(bool inDegrees=true) const;
 
       // Make 2 vectors into 3 orthogonal vectors
       static std::vector<V3D> makeVectorsOrthogonal(std::vector<V3D> & vectors);
diff --git a/Code/Mantid/Framework/Kernel/src/CompositeValidator.cpp b/Code/Mantid/Framework/Kernel/src/CompositeValidator.cpp
index c708532a088a4f83656ba14369c7ce661f5150b3..e617ba961dac218e0596e21c5e9678761a83bfaa 100644
--- a/Code/Mantid/Framework/Kernel/src/CompositeValidator.cpp
+++ b/Code/Mantid/Framework/Kernel/src/CompositeValidator.cpp
@@ -23,7 +23,7 @@ namespace Mantid
      * the intersection of the allowedValues for the child validators
      * @return
      */
-    std::set<std::string> CompositeValidator::allowedValues() const
+    std::vector<std::string> CompositeValidator::allowedValues() const
     {
       std::set<std::string>      elem_unique;
       std::multiset<std::string> elem_all;
@@ -32,14 +32,14 @@ namespace Mantid
       std::list<IValidator_sptr>::const_iterator itrEnd = m_children.end();
       for( std::list<IValidator_sptr>::const_iterator itr = m_children.begin(); itr != itrEnd; ++itr)
       {
-        std::set<std::string> subs = (*itr)->allowedValues();
+        std::vector<std::string> subs = (*itr)->allowedValues();
         if ( subs.empty())continue;
         elem_unique.insert(subs.begin(),subs.end());
         elem_all.insert(subs.begin(),subs.end());
         n_combinations++;
       }
       // empty or single set of allowed values
-      if(n_combinations<2)return elem_unique;
+      if(n_combinations<2)return std::vector<std::string>( elem_unique.begin(), elem_unique.end() );
       // there is more then one combination and we have to identify its union;
       for(std::set<std::string>::const_iterator its=elem_unique.begin();its!=elem_unique.end();++its)
       {
@@ -51,7 +51,7 @@ namespace Mantid
       {
         rez.insert(*im);
       }
-      return rez;
+      return std::vector<std::string>( rez.begin(), rez.end() );
     }
 
     /**
diff --git a/Code/Mantid/Framework/Kernel/src/DateValidator.cpp b/Code/Mantid/Framework/Kernel/src/DateValidator.cpp
index db5f6fec763ff521a50efebd403f0082aa1e1cdd..4e8696761ecffbaca276267439ded07635fbd2ba 100644
--- a/Code/Mantid/Framework/Kernel/src/DateValidator.cpp
+++ b/Code/Mantid/Framework/Kernel/src/DateValidator.cpp
@@ -26,7 +26,7 @@ namespace Kernel
       // Zero it out
       timeinfo.tm_sec = 0; timeinfo.tm_min = 0; timeinfo.tm_hour = 0;
       timeinfo.tm_mday = 0; timeinfo.tm_mon = 0; timeinfo.tm_year = 0;
-      timeinfo.tm_isdst = -1;
+      timeinfo.tm_wday = 0; timeinfo.tm_isdst = -1;
 
       std::basic_string<char>::size_type index, off = 0;
       int day, month, year;
diff --git a/Code/Mantid/Framework/Kernel/src/DirectoryValidator.cpp b/Code/Mantid/Framework/Kernel/src/DirectoryValidator.cpp
index e2e6e775e55b9b884f070a10739e32f1cd517bd1..d0c2daa5b4c045cb45200dc849902e4ef9052a25 100644
--- a/Code/Mantid/Framework/Kernel/src/DirectoryValidator.cpp
+++ b/Code/Mantid/Framework/Kernel/src/DirectoryValidator.cpp
@@ -22,9 +22,9 @@ DirectoryValidator::DirectoryValidator(bool testDirectoryExists)
 DirectoryValidator::~DirectoryValidator() {}
 
 /// Returns the set of valid values
-std::set<std::string> DirectoryValidator::allowedValues() const
+std::vector<std::string> DirectoryValidator::allowedValues() const
 {
-  return std::set<std::string>();
+  return std::vector<std::string>();
 }
 
 /** 
diff --git a/Code/Mantid/Framework/Kernel/src/FacilityInfo.cpp b/Code/Mantid/Framework/Kernel/src/FacilityInfo.cpp
index 0924d0c77d4710657995f64dec85c7e57ad46135..3234e2e2c70b402099dc135dc53e882808beba71 100644
--- a/Code/Mantid/Framework/Kernel/src/FacilityInfo.cpp
+++ b/Code/Mantid/Framework/Kernel/src/FacilityInfo.cpp
@@ -12,9 +12,11 @@
 #include <Poco/StringTokenizer.h>
 #include <boost/algorithm/string.hpp>
 #include <boost/shared_ptr.hpp>
+
 #include <algorithm>
 #include <iostream>
 
+
 using Poco::XML::Element;
 
 namespace Mantid
diff --git a/Code/Mantid/Framework/Kernel/src/FileValidator.cpp b/Code/Mantid/Framework/Kernel/src/FileValidator.cpp
index 254444b8a284870cef95d725124ee259fe871084..caced6ba0947a447a2d1f176b8c2204ddf041213 100644
--- a/Code/Mantid/Framework/Kernel/src/FileValidator.cpp
+++ b/Code/Mantid/Framework/Kernel/src/FileValidator.cpp
@@ -1,23 +1,11 @@
 #include "MantidKernel/FileValidator.h"
 #include "MantidKernel/Logger.h"
 #include <algorithm>
+#include <boost/algorithm/string/case_conv.hpp>
 #include <Poco/File.h>
 #include <Poco/Path.h>
 #include <iostream>
 
-
-namespace
-{
-  /// Functor object to supply to for_each
-  struct lowercase
-  {
-    void operator()(std::string s)
-    {
-      std::transform(s.begin(), s.end(), s.begin(), tolower);
-    }
-  };
-}
-
 namespace Mantid
 {
 namespace Kernel
@@ -37,18 +25,24 @@ namespace
 FileValidator::FileValidator(const std::vector<std::string>& extensions, bool testFileExists,
                              bool testCanWrite) :
   TypedValidator<std::string>(),
-  m_extensions(extensions.begin(),extensions.end()),
   m_testExist(testFileExists),
   m_testCanWrite(testCanWrite)
 {
-  for_each(m_extensions.begin(), m_extensions.end(), lowercase());
+  for(auto it = extensions.begin(); it != extensions.end(); ++it)
+  {
+    const std::string ext = boost::to_lower_copy(*it);
+    if ( std::find(m_extensions.begin(), m_extensions.end(), ext) == m_extensions.end() )
+    {
+      m_extensions.push_back( ext );
+    }
+  }
 }
 
 /// Destructor
 FileValidator::~FileValidator() {}
 
 /// Returns the set of valid values
-std::set<std::string> FileValidator::allowedValues() const
+std::vector<std::string> FileValidator::allowedValues() const
 {
   return m_extensions;
 }
@@ -83,7 +77,7 @@ std::string FileValidator::checkValidity(const std::string &value) const
       g_log.debug() << "Unrecognised extension in file \"" << value << "\"";
       if (!this->m_extensions.empty()) {
         g_log.debug() << " [ ";
-        for (std::set<std::string>::const_iterator it = this->m_extensions.begin(); it != this->m_extensions.end(); ++it)
+        for (auto it = this->m_extensions.begin(); it != this->m_extensions.end(); ++it)
           g_log.debug() << *it << " ";
         g_log.debug() << "]";
       }
@@ -190,7 +184,7 @@ bool FileValidator::endswith(const std::string &value) const
   std::transform(value_copy.begin(), value_copy.end(), value_copy.begin(), tolower);
 
   // check for the ending
-  for (std::set<std::string>::const_iterator it = m_extensions.begin();
+  for (auto it = m_extensions.begin();
        it != m_extensions.end(); ++it) {
     if (has_ending(value, *it)) // original case
       return true;
diff --git a/Code/Mantid/Framework/Kernel/src/Interpolation.cpp b/Code/Mantid/Framework/Kernel/src/Interpolation.cpp
index c17f4d6ca6b5d730b7fadb4b03c0e2b0c12fb4bf..f7842d2f26abc88849d3820a1278b0ae030700c7 100644
--- a/Code/Mantid/Framework/Kernel/src/Interpolation.cpp
+++ b/Code/Mantid/Framework/Kernel/src/Interpolation.cpp
@@ -21,6 +21,26 @@ namespace Kernel
     m_yUnit = UnitFactory::Instance().create("TOF");
   }
 
+  size_t Interpolation::findIndexOfNextLargerValue(const std::vector<double> &data, double key, size_t range_start, size_t range_end) const
+  {
+      if(range_end < range_start)
+      {
+          throw std::range_error("Value is outside array range.");
+      }
+
+      size_t center = range_start + (range_end - range_start) / 2;
+
+      if(data[center] > key && data[center - 1] <= key) {
+          return center;
+      }
+
+      if(data[center] <= key) {
+          return findIndexOfNextLargerValue(data, key, center + 1, range_end);
+      } else {
+          return findIndexOfNextLargerValue(data, key, range_start, center - 1);
+      }
+  }
+
   void Interpolation::setXUnit(const std::string& unit) 
   { 
     m_xUnit = UnitFactory::Instance().create(unit);
@@ -42,13 +62,18 @@ namespace Kernel
 
     if ( N == 0 )
     {
-      g_log.error() << "No data in Interpolation. Return interpolation value zero.";
+      g_log.error() << "Need at least one value for interpolation. Return interpolation value zero.";
       return 0.0;
     }
+
+    if ( N == 1 )
+    {
+      return m_y[0];
+    }
     
     // check first if at is within the limits of interpolation interval
 
-    if ( at <= m_x[0] )
+    if ( at < m_x[0] )
     {
       return m_y[0]-(m_x[0]-at)*(m_y[1]-m_y[0])/(m_x[1]-m_x[0]);
     }
@@ -58,16 +83,14 @@ namespace Kernel
       return m_y[N-1]+(at-m_x[N-1])*(m_y[N-1]-m_y[N-2])/(m_x[N-1]-m_x[N-2]);
     }
 
-    // otherwise
-
-    for (unsigned int i = 1; i < N; i++)
-    {
-      if ( m_x[i] > at )
-      {
-        return m_y[i-1] + (at-m_x[i-1])*(m_y[i]-m_y[i-1])/(m_x[i]-m_x[i-1]);
-      }
+    try {
+        // otherwise
+        // General case. Find index of next largest value by binary search.
+        size_t idx = findIndexOfNextLargerValue(m_x, at, 1, N - 1);
+        return m_y[idx-1] + (at - m_x[idx-1])*(m_y[idx]-m_y[idx-1])/(m_x[idx]-m_x[idx-1]);
+    } catch(std::range_error) {
+        return 0.0;
     }
-    return 0.0;
   }
 
   /** Add point in the interpolation.
@@ -132,6 +155,15 @@ namespace Kernel
     }
   }
 
+  /**
+    Resets interpolation data by clearing the internal storage for x- and y-values
+  */
+  void Interpolation::resetData()
+  {
+      m_x.clear();
+      m_y.clear();
+  }
+
   /**
     Prints the value of parameter
     @param os :: the Stream to output to
@@ -161,6 +193,7 @@ namespace Kernel
     f.setMethod(values[0]);
     f.setXUnit(values[1]);
     f.setYUnit(values[2]);
+    f.resetData(); // Reset data, in case the interpolation table is not empty
 
     for ( unsigned int i = 3; i < values.count(); i++)
     {
diff --git a/Code/Mantid/Framework/Kernel/src/MultiFileValidator.cpp b/Code/Mantid/Framework/Kernel/src/MultiFileValidator.cpp
index d1edf007089f32fddde62d5bedc86b312f26139b..15090af71e078e9da0223b8ed9c09f5f3dd5a850 100644
--- a/Code/Mantid/Framework/Kernel/src/MultiFileValidator.cpp
+++ b/Code/Mantid/Framework/Kernel/src/MultiFileValidator.cpp
@@ -42,7 +42,7 @@ namespace Kernel
   MultiFileValidator::~MultiFileValidator() {}
 
   /// Returns the set of valid values
-  std::set<std::string> MultiFileValidator::allowedValues() const
+  std::vector<std::string> MultiFileValidator::allowedValues() const
   {
     return m_fileValidator.allowedValues();
   }
diff --git a/Code/Mantid/Framework/Kernel/src/Property.cpp b/Code/Mantid/Framework/Kernel/src/Property.cpp
index 90562b02d15d8ce4e0ab55b6a6475875752fa912..7adf842043f23592ce652b19450e92c8e0bd2d47 100644
--- a/Code/Mantid/Framework/Kernel/src/Property.cpp
+++ b/Code/Mantid/Framework/Kernel/src/Property.cpp
@@ -182,9 +182,9 @@ void Property::setBriefDocumentation( const std::string& documentation )
  *  If not, it returns an empty set.
  * @return the set of valid values for this property or an empty set
  */
-std::set<std::string> Property::allowedValues() const
+std::vector<std::string> Property::allowedValues() const
 {
-  return std::set<std::string>();
+  return std::vector<std::string>();
 }
 
 /// Create a PropertyHistory object representing the current state of the Property.
diff --git a/Code/Mantid/Framework/Kernel/src/Quat.cpp b/Code/Mantid/Framework/Kernel/src/Quat.cpp
index f82656e4f34222c5006d64c06e1560970b54c993..bf0a6f408f4084a72a7f1b921931b8fca00aac57 100644
--- a/Code/Mantid/Framework/Kernel/src/Quat.cpp
+++ b/Code/Mantid/Framework/Kernel/src/Quat.cpp
@@ -8,6 +8,8 @@
 #include <cstdlib>
 #include <float.h>
 
+#include <boost/algorithm/string.hpp>
+
 
 namespace Mantid
 {
@@ -776,6 +778,85 @@ void Quat::rotateBB(double& xmin, double& ymin, double& zmin, double& xmax, doub
 	return;
 }
 
+/** Calculate the Euler angles that are equivalent to this Quaternion.
+ *
+ * Euler angles are calculated intrinsically, i.e. the first rotation modifies the axis used for
+ * the second rotation, and the second rotation modifies the axis used for the third rotation.
+ *
+ * You can specify which axis the rotations should be applied around and the order in which they
+ * are to be applied with the convention parameter. For instance, for a rotation of Y and then
+ * the new Z axis, and then the new Y axis: pass "YZY" as the convention. Or for a rotation
+ * such as X, and then the new Y axis, and then the new Z axis: pass "XYZ" as the convention.
+ *
+ * @param convention :: The axes to apply the rotations to and the order in which to do so. Defaults to "XYZ".
+ * @returns A vector of the Euler angles in degrees. The order of the angles is the same as in the convention parameter.
+ */
+std::vector<double> Quat::getEulerAngles(const std::string& convention = "XYZ") const
+{
+  std::string conv(convention);
+
+  if(conv.length() != 3)
+    throw std::invalid_argument("Wrong convention name (string length not 3)");
+
+  boost::to_upper(conv);
+
+  //Check it's only XYZ in the string
+  if(conv.find_first_not_of("XYZ") != std::string::npos)
+    throw std::invalid_argument("Wrong convention name (characters other than XYZ)");
+
+  //Cannot be XXY, XYY, or similar. Only first and last may be the same: YXY
+  if((conv[0]==conv[1]) || (conv[2]==conv[1]))
+    throw std::invalid_argument("Wrong convention name (repeated indices)");
+
+  boost::replace_all(conv,"X","0");
+  boost::replace_all(conv,"Y","1");
+  boost::replace_all(conv,"Z","2");
+
+  std::stringstream s;
+  s << conv[0] << " " << conv[1] << " " << conv[2];
+
+  int first, second, last;
+  s >> first >> second >> last;
+
+  // Do we want Tait-Bryan angles, as opposed to 'classic' Euler angles?
+  const int TB = (first * second * last == 0 && first + second + last == 3) ? 1 : 0;
+
+  const int par01 = ( (second - first + 9) % 3 == 1) ? 1 : -1;
+  const int par12 = ( (last - second + 9)  % 3 == 1) ? 1 : -1;
+
+  std::vector<double> angles(3);
+
+  const DblMatrix R = DblMatrix(this->getRotation());
+
+  const int i = (last + TB * par12 + 9) % 3;
+  const int j1 = (last - par12 + 9) % 3;
+  const int j2 = (last + par12 + 9) % 3;
+
+  const double s3 = (1.0 -  TB - TB  * par12) * R[i][j1];
+  const double c3 = (TB - (1.0 - TB) * par12) * R[i][j2];
+
+  V3D axis3(0,0,0);
+  axis3[last] = 1.0;
+
+  const double rad2deg = 180.0 / M_PI;
+
+  angles[2] = atan2(s3,c3) * rad2deg;
+
+  DblMatrix Rm3(Quat(-angles[2], axis3).getRotation());
+  DblMatrix Rp = R * Rm3;
+
+  const double s1 = par01 * Rp[(first - par01 + 9) % 3][(first + par01 + 9) % 3];
+  const double c1 = Rp[second][second];
+  const double s2 = par01*Rp[first][3-first-second];
+  const double c2 = Rp[first][first];
+
+  angles[0] = atan2(s1,c1) * rad2deg;
+  angles[1] = atan2(s2,c2) * rad2deg;
+
+  return angles;
+}
+
+
 } // Namespace Kernel
 
 } // Namespce Mantid
diff --git a/Code/Mantid/Framework/Kernel/src/TimeSeriesProperty.cpp b/Code/Mantid/Framework/Kernel/src/TimeSeriesProperty.cpp
index 4203056b2ec7c76cdf7464e0ce40333f9bdee9ea..fd5486eac227bade03be9d568da0ca729d4d0a52 100644
--- a/Code/Mantid/Framework/Kernel/src/TimeSeriesProperty.cpp
+++ b/Code/Mantid/Framework/Kernel/src/TimeSeriesProperty.cpp
@@ -1786,6 +1786,9 @@ namespace Mantid
         ++ vit;
       }
 
+      // update m_size
+      countSize();
+
       // 3. Finish
       g_log.warning() << "Log " << this->name() << " has " << numremoved << " entries removed due to duplicated time. " << "\n";
 
diff --git a/Code/Mantid/Framework/Kernel/src/Unit.cpp b/Code/Mantid/Framework/Kernel/src/Unit.cpp
index 3e2fe4e1c89fae2b719ad2f822950fce05b4a552..6ee5c1939b40a12ccf7ad38cded8594567035d46 100644
--- a/Code/Mantid/Framework/Kernel/src/Unit.cpp
+++ b/Code/Mantid/Framework/Kernel/src/Unit.cpp
@@ -59,6 +59,17 @@ namespace Kernel
     return *this;
   }
 
+
+  bool Unit::operator==(const Unit& u) const
+  {
+    return unitID() == u.unitID();
+  }
+
+  bool Unit::operator!=(const Unit& u) const
+  {
+    return !(*this == u);
+  }
+
 /** Is conversion by constant multiplication possible?
  *
  *  Look to see if conversion from the unit upon which this method is called requires
diff --git a/Code/Mantid/Framework/Kernel/src/V3D.cpp b/Code/Mantid/Framework/Kernel/src/V3D.cpp
index d86f9d42c2c60bd03f065237e9765f4772587e32..8e06fb397002f4f228aeb5aa6cc3de72deb5d92d 100644
--- a/Code/Mantid/Framework/Kernel/src/V3D.cpp
+++ b/Code/Mantid/Framework/Kernel/src/V3D.cpp
@@ -877,6 +877,23 @@ bool V3D::CompareMagnitude( const V3D & v1, const V3D & v2 )
   return (mag_sq_1 < mag_sq_2);
 }
 
+/**
+ * Get direction angles from direction cosines.
+ * @param inDegrees : optional argument for specifying in radians (false). Defaults to true.
+ * @return V3D containing anlges.
+ */
+V3D V3D::directionAngles(bool inDegrees) const
+{
+  double conversionFactor = 1.0;
+  if(inDegrees)
+  {
+    conversionFactor = 180.0/M_PI;
+  }
+  const double divisor = this->norm();
+  return V3D(conversionFactor*acos(x/divisor), conversionFactor*acos(y/divisor), conversionFactor*acos(z/divisor));
+
+}
+
 
 } // Namespace Kernel
 } // Namespace Mantid
diff --git a/Code/Mantid/Framework/Kernel/test/CompositeValidatorTest.h b/Code/Mantid/Framework/Kernel/test/CompositeValidatorTest.h
index e6e36c5a62c92645945b67d1cd50cdbea596af1d..795420bd2d84f99b6ad140c44c525792a6526801 100644
--- a/Code/Mantid/Framework/Kernel/test/CompositeValidatorTest.h
+++ b/Code/Mantid/Framework/Kernel/test/CompositeValidatorTest.h
@@ -54,7 +54,7 @@ public:
     CompositeValidator comp;
     comp.add(IValidator_sptr(val1));
 
-    std::set<std::string> allowed=comp.allowedValues();
+    std::vector<std::string> allowed=comp.allowedValues();
     TS_ASSERT_EQUALS(allowed_val1.size(),allowed.size());
 
     std::vector<std::string> allowed_val2(3);
@@ -63,7 +63,7 @@ public:
     StringListValidator * val2 = new StringListValidator(allowed_val2);
     comp.add(IValidator_sptr(val2));
 
-    std::set<std::string> allowed2=comp.allowedValues();
+    std::vector<std::string> allowed2=comp.allowedValues();
     TS_ASSERT_EQUALS(1,allowed2.size());
     TS_ASSERT_EQUALS("b2",*(allowed2.begin()));
 
diff --git a/Code/Mantid/Framework/Kernel/test/DataServiceTest.h b/Code/Mantid/Framework/Kernel/test/DataServiceTest.h
index 28749c0f48fb48faca2a3fa766a098d775590ced..4230b2d1747967c8f4a3f1013802bf28da5a7ddd 100644
--- a/Code/Mantid/Framework/Kernel/test/DataServiceTest.h
+++ b/Code/Mantid/Framework/Kernel/test/DataServiceTest.h
@@ -81,14 +81,14 @@ public:
 
   void handlePreDeleteNotification(const Poco::AutoPtr<FakeDataService::PreDeleteNotification>& notification)
   {
-    TS_ASSERT_EQUALS( notification->object_name(), "one" );
+    TS_ASSERT_EQUALS( notification->objectName(), "one" );
     TS_ASSERT_EQUALS( *notification->object(), 1 );
     ++notificationFlag;
   }
 
   void handlePostDeleteNotification(const Poco::AutoPtr<FakeDataService::PostDeleteNotification>& notification)
   {
-    TS_ASSERT_EQUALS( notification->object_name(), "one" );
+    TS_ASSERT_EQUALS( notification->objectName(), "one" );
     ++notificationFlag;
   }
 
diff --git a/Code/Mantid/Framework/Kernel/test/DynamicFactoryTest.h b/Code/Mantid/Framework/Kernel/test/DynamicFactoryTest.h
index 79d29cac661167f9c7545171fb6284eee1aab805..3f1374633ad4a9a26d9d325d0eab99d66ba3f307 100644
--- a/Code/Mantid/Framework/Kernel/test/DynamicFactoryTest.h
+++ b/Code/Mantid/Framework/Kernel/test/DynamicFactoryTest.h
@@ -18,6 +18,11 @@ class IntFactory : public DynamicFactory<int>
 {
 };
 
+// Helper class
+class CaseSensitiveIntFactory : public DynamicFactory<int,CaseSensitiveStringComparator>
+{
+};
+
 class DynamicFactoryTest : public CxxTest::TestSuite
 {
   typedef boost::shared_ptr<int> int_ptr;
@@ -43,9 +48,20 @@ public:
     TS_ASSERT_THROWS( factory.create("testEntry"), std::runtime_error )
     factory.subscribe<int>("testEntry");
     TS_ASSERT_THROWS_NOTHING( int_ptr i = factory.create("testEntry") );
+    TS_ASSERT_THROWS_NOTHING( int_ptr i = factory.create("TESTENTRY") );
     factory.unsubscribe("testEntry");
   }
 
+  void testCreateCaseSensitive()
+  {
+    TS_ASSERT_THROWS( caseSensitiveFactory.create("testEntryCaseSensitive"), std::runtime_error )
+    caseSensitiveFactory.subscribe<int>("testEntryCaseSensitive");
+    TS_ASSERT_THROWS( int_ptr i = caseSensitiveFactory.create("testEntryCaseSENSITIVE") , std::runtime_error); //case error on a case sensitive dynamic factory
+    TS_ASSERT_THROWS_NOTHING( int_ptr i2 = caseSensitiveFactory.create("testEntryCaseSensitive") );
+    caseSensitiveFactory.unsubscribe("testEntryCaseSensitive");
+  }
+
+
   void testCreateUnwrapped()
   {
     TS_ASSERT_THROWS( factory.createUnwrapped("testUnrappedEntry"), std::runtime_error )
@@ -53,9 +69,24 @@ public:
     int *i = NULL;
     TS_ASSERT_THROWS_NOTHING( i = factory.createUnwrapped("testUnwrappedEntry") );
     delete i;
+
+    int *j = NULL;
+    TS_ASSERT_THROWS_NOTHING( j = factory.createUnwrapped("TESTUnwrappedEntry") );
+    delete j;
     factory.unsubscribe("testUnwrappedEntry");
   }
 
+  void testCreateUnwrappedCaseSensitive()
+  {
+    TS_ASSERT_THROWS( caseSensitiveFactory.create("testUnrappedEntryCaseSensitive"), std::runtime_error )
+    caseSensitiveFactory.subscribe<int>("testUnrappedEntryCaseSensitive");
+    int *i = NULL;
+    TS_ASSERT_THROWS( i = caseSensitiveFactory.createUnwrapped("testUnrappedentrycaseSENSITIVE") , std::runtime_error); //case error on a case sensitive dynamic factory
+    TS_ASSERT_THROWS_NOTHING( i = caseSensitiveFactory.createUnwrapped("testUnrappedEntryCaseSensitive") );
+    delete i;
+    caseSensitiveFactory.unsubscribe("testUnrappedEntryCaseSensitive");
+  }
+
   void testSubscribeWithEmptyNameThrowsInvalidArgument()
   {
     TS_ASSERT_THROWS( factory.subscribe<int>(""), std::invalid_argument);
@@ -121,12 +152,36 @@ public:
     TS_ASSERT( ! factory.exists("testing") );
     factory.subscribe<int>("testing");
     TS_ASSERT( factory.exists("testing") );
+    TS_ASSERT( factory.exists("TESTING") );
   }
 	
   void testGetKeys()
   {
+    std::string testKey = "testGetKeys";
+    //check it is not already present
+    TS_ASSERT_THROWS( factory.create(testKey), std::runtime_error )
+    factory.subscribe<int>(testKey);
+
     std::vector<std::string> keys = factory.getKeys();
+    
+    TSM_ASSERT("Could not find the test key in the returned vector.", std::find(keys.begin(), keys.end(), testKey)!=keys.end()) //check the case is correct
+
     TS_ASSERT(!keys.empty());
+
+    factory.unsubscribe(testKey);
+  }
+
+  void testGetKeysRetainsCase()
+  {
+    std::string testKey = "testGetKeysRetainsCase";
+    //check it is not already present
+    TS_ASSERT_THROWS( factory.create(testKey), std::runtime_error )
+    factory.subscribe<int>(testKey);
+
+    std::vector<std::string> keys = factory.getKeys();
+    
+    factory.unsubscribe(testKey);
+
   }
 
 private:
@@ -136,6 +191,7 @@ private:
   }
 
   IntFactory factory;
+  CaseSensitiveIntFactory caseSensitiveFactory;
   Poco::NObserver<DynamicFactoryTest, IntFactory::UpdateNotification> m_notificationObserver;
   bool m_updateNoticeReceived;
 };
diff --git a/Code/Mantid/Framework/Kernel/test/FileValidatorTest.h b/Code/Mantid/Framework/Kernel/test/FileValidatorTest.h
index b3d20aa48e8d31456765d98446019590cc687ab5..cc6c26293662902d8d680d606b247de0258e38db 100644
--- a/Code/Mantid/Framework/Kernel/test/FileValidatorTest.h
+++ b/Code/Mantid/Framework/Kernel/test/FileValidatorTest.h
@@ -23,7 +23,9 @@ void testConstructors()
   vec.push_back("raw");
   vec.push_back("RAW");
   FileValidator v2(vec);
-  TS_ASSERT_EQUALS  ( v2.allowedValues().size(), 2 );
+
+  //File extensions are converted to lowercase so should have one unique extension
+  TS_ASSERT_EQUALS  ( v2.allowedValues().size(), 1 );
 }
 
 void testPassesOnExistentFile()
diff --git a/Code/Mantid/Framework/Kernel/test/InterpolationTest.h b/Code/Mantid/Framework/Kernel/test/InterpolationTest.h
index b8e22fff1012140fb799d6f198d56702b07c04ce..d73e2ef030cf7751724f3b650414a6aed3aa4e72 100644
--- a/Code/Mantid/Framework/Kernel/test/InterpolationTest.h
+++ b/Code/Mantid/Framework/Kernel/test/InterpolationTest.h
@@ -10,66 +10,292 @@ using namespace Mantid::Kernel;
 class InterpolationTest : public CxxTest::TestSuite
 {
 public:
-  
-	void test1()
-	{
-    Interpolation interpolation;
+    /* In the constructor some vectors with values are setup,
+     * which make the tests easier later on.
+     *
+     * To check the interpolated values, call the method
+     *   checkInterpolationResults(const Interpolation &interpolation);
+     * and supply the interpolation object which is to be tested. The method will call
+     * further methods to cover all possible edge-cases. On failure, it will be visible
+     * which case caused the failure.
+     */
+    InterpolationTest()
+    {
+        // values for setting up the interpolation
+        m_tableXValues.push_back(200.0);
+        m_tableXValues.push_back(201.0);
+        m_tableXValues.push_back(202.0);
+        m_tableXValues.push_back(203.0);
+        m_tableXValues.push_back(204.0);
+
+        m_tableYValues.push_back(50);
+        m_tableYValues.push_back(60);
+        m_tableYValues.push_back(100);
+        m_tableYValues.push_back(300);
+        m_tableYValues.push_back(400);
+
+        // bulk values for interpolation test
+        m_interpolationXValues.push_back(200.5);
+        m_interpolationXValues.push_back(201.25);
+        m_interpolationXValues.push_back(203.5);
+
+        m_expectedYValues.push_back(55.0);
+        m_expectedYValues.push_back(70.0);
+        m_expectedYValues.push_back(350.0);
+
+        // values outside interpolation range
+        m_outsideXValues.push_back(100.0);
+        m_outsideXValues.push_back(3000.0);
+
+        m_outsideYValues.push_back(-950.0);
+        m_outsideYValues.push_back(280000.0);
+    }
+
+    void testCopyConstruction()
+    {
+        Interpolation interpolation;
+        interpolation.setMethod("linear");
+        interpolation.setXUnit("Wavelength");
+        interpolation.setYUnit("dSpacing");
+
+        interpolation.addPoint(200.0, 2.0);
+        interpolation.addPoint(202.0, 3.0);
+
+        Interpolation other = interpolation;
+
+        TS_ASSERT_EQUALS(other.getMethod(), "linear");
+        TS_ASSERT_EQUALS(other.getXUnit()->unitID(), "Wavelength");
+        TS_ASSERT_EQUALS(other.getYUnit()->unitID(), "dSpacing");
+        TS_ASSERT_EQUALS(other.value(200.0), 2.0);
+    }
+
+    void testContainData()
+    {
+        Interpolation interpolation;
+
+        TS_ASSERT ( interpolation.containData() == false );
+
+        interpolation.addPoint(200.0, 50);
+
+        TS_ASSERT ( interpolation.containData() == true );
+    }
+
+    void testResetData()
+    {
+        Interpolation interpolation = getInitializedInterpolation("Wavelength", "dSpacing");
+
+        TS_ASSERT(interpolation.containData());
+        interpolation.resetData();
+        TS_ASSERT(interpolation.containData() == false);
+    }
+
+    void testAddPointOrdered()
+    {
+        Interpolation interpolation;
+
+        // Add points from values in vectors in correct order.
+        for(size_t i = 0; i < m_tableXValues.size(); ++i) {
+            interpolation.addPoint(m_tableXValues[i], m_tableYValues[i]);
+        }
+
+        // Check correctness of interpolation for different cases
+        checkInterpolationResults(interpolation);
+    }
+
+    void testAddPointArbitrary()
+    {
+        Interpolation interpolation;
+
+        size_t insertionOrderRaw[] = {1, 0, 3, 4, 2};
+        std::vector<size_t> insertionOrder(insertionOrderRaw, insertionOrderRaw + 5);
+
+        for(std::vector<size_t>::const_iterator i = insertionOrder.begin(); i != insertionOrder.end(); ++i) {
+            interpolation.addPoint(m_tableXValues[*i], m_tableYValues[*i]);
+        }
+
+        checkInterpolationResults(interpolation);
+    }
+
+    void testEmpty()
+    {
+        Interpolation interpolation;
+
+        std::stringstream str;
+        str << interpolation;
+        TS_ASSERT( str.str().compare("linear ; TOF ; TOF") == 0 );
+
+        Interpolation readIn;
+        str >> readIn;
+
+        TS_ASSERT( readIn.containData() == false );
+    }
 
-    TS_ASSERT ( interpolation.containData() == false );
+    void testStreamOperators()
+    {
+        std::string xUnit = "Wavelength";
+        std::string yUnit = "dSpacing";
 
-    interpolation.addPoint(200.0, 50);
+        Interpolation interpolation = getInitializedInterpolation(xUnit, yUnit);
 
-    TS_ASSERT ( interpolation.containData() == true );
+        // Output stream
+        std::stringstream str;
+        str << interpolation;
+        TS_ASSERT( str.str().compare("linear ; Wavelength ; dSpacing ; 200 50 ; 201 60 ; 202 100 ; 203 300 ; 204 400") == 0 );
 
-    interpolation.addPoint(201.0, 60);
-    interpolation.addPoint(202.0, 100);
-    interpolation.addPoint(204.0, 400);
-    interpolation.addPoint(203.0, 300);
+        // Input stream for empty interpolation object
+        Interpolation readIn;
+        TS_ASSERT( readIn.getXUnit()->unitID() == "TOF" );
+        TS_ASSERT( readIn.getYUnit()->unitID() == "TOF" );
+        str >> readIn;
+        TS_ASSERT( readIn.getXUnit()->unitID() == xUnit );
+        TS_ASSERT( readIn.getYUnit()->unitID() == yUnit );
 
-    // Test that all the base class member variables are correctly assigned to
-    TS_ASSERT_DELTA( interpolation.value(100), -950.0 ,0.000000001); 
-    TS_ASSERT_DELTA( interpolation.value(3000), 280000.0 ,0.000000001);
-    TS_ASSERT_DELTA( interpolation.value(200.5), 55.0 ,0.000000001); 
-    TS_ASSERT_DELTA( interpolation.value(201.25), 70.0 ,0.000000001); 
-    TS_ASSERT_DELTA( interpolation.value(203.5), 350.0 ,0.000000001); 
+        checkInterpolationResults(readIn);
+    }
+
+    void testStreamOperatorsNonEmpty()
+    {
+        Interpolation interpolation = getInitializedInterpolation("Wavelength", "dSpacing");
+
+        std::stringstream str;
+        str << interpolation;
+
+        // Reconstruct on existing object.
+        str >> interpolation;
+
+        checkInterpolationResults(interpolation);
+    }
+
+    void testFindIndexOfNextLargerValue()
+    {
+        TestableInterpolation interpolation;
+
+        size_t N = m_tableXValues.size();
+
+        // lower limit - can be treated like general case
+        TS_ASSERT_EQUALS(interpolation.findIndexOfNextLargerValue(m_tableXValues, 200.0, 1, N - 1), 1);
+
+        // Exact interpolation points
+        TS_ASSERT_EQUALS(interpolation.findIndexOfNextLargerValue(m_tableXValues, 201.0, 1, N - 1), 2);
+        TS_ASSERT_EQUALS(interpolation.findIndexOfNextLargerValue(m_tableXValues, 202.0, 1, N - 1), 3);
+        TS_ASSERT_EQUALS(interpolation.findIndexOfNextLargerValue(m_tableXValues, 203.0, 1, N - 1), 4);
+
+        // Arbitrary interpolation points
+        TS_ASSERT_EQUALS(interpolation.findIndexOfNextLargerValue(m_tableXValues, 200.5, 1, N - 1), 1);
+        TS_ASSERT_EQUALS(interpolation.findIndexOfNextLargerValue(m_tableXValues, 201.25, 1, N - 1), 2);
+        TS_ASSERT_EQUALS(interpolation.findIndexOfNextLargerValue(m_tableXValues, 203.5, 1, N - 1), 4);
+
+
+        // upper limit - must be covered as edge case before this can ever be called.
+        TS_ASSERT_THROWS(interpolation.findIndexOfNextLargerValue(m_tableXValues, 204.0, 1, N - 1), std::range_error);
+
+        // outside interpolation limits - edge cases as well
+        TS_ASSERT_THROWS(interpolation.findIndexOfNextLargerValue(m_tableXValues, 199, 1, N - 1), std::range_error)
+        TS_ASSERT_THROWS(interpolation.findIndexOfNextLargerValue(m_tableXValues, 2000.0, 1, N - 1), std::range_error)
+    }
+
+    void testInterpolationWithTooFewValues()
+    {
+        Interpolation interpolationZero;
+        Interpolation interpolationOne;
+        interpolationOne.addPoint(200, 2.0);
+
+        for(size_t i = 0; i < m_tableXValues.size(); ++i) {
+            // When there are zero values in the interpolation, it returns 0.0
+            checkValue(interpolationZero, m_tableXValues[i], 0.0, "zero interpolation values");
 
-    TS_ASSERT_EQUALS(interpolation.value(204.0), 400.0);
+            // With one value, it returns this one value for any x.
+            checkValue(interpolationOne, m_tableXValues[i], 2.0, "one interpolation value");
+        }
+    }
+
+private:
+    Interpolation getInitializedInterpolation(std::string xUnit, std::string yUnit)
+    {
+        Interpolation interpolation;
 
-    interpolation.setXUnit("Wavelength");
-    interpolation.setYUnit("dSpacing");
-    std::stringstream str;
-    str << interpolation;
-    TS_ASSERT( str.str().compare("linear ; Wavelength ; dSpacing ; 200 50 ; 201 60 ; 202 100 ; 203 300 ; 204 400") == 0 );
+        // take values from constructor
+        for(size_t i = 0; i < m_tableXValues.size(); ++i) {
+            interpolation.addPoint(m_tableXValues[i], m_tableYValues[i]);
+        }
 
-    Interpolation readIn;
-    TS_ASSERT( readIn.getXUnit()->unitID() == "TOF" );
-    TS_ASSERT( readIn.getYUnit()->unitID() == "TOF" );
-    str >> readIn;
-    TS_ASSERT( readIn.getXUnit()->unitID() == "Wavelength" );
-    TS_ASSERT( readIn.getYUnit()->unitID() == "dSpacing" );
+        interpolation.setXUnit(xUnit);
+        interpolation.setYUnit(yUnit);
 
-    // Test that all the base class member variables are correctly assigned to
-    TS_ASSERT_DELTA( readIn.value(100), -950.0 ,0.000000001); 
-    TS_ASSERT_DELTA( readIn.value(3000), 280000.0 ,0.000000001);
-    TS_ASSERT_DELTA( readIn.value(200.5), 55.0 ,0.000000001); 
-    TS_ASSERT_DELTA( readIn.value(201.25), 70.0 ,0.000000001); 
-    TS_ASSERT_DELTA( readIn.value(203.5), 350.0 ,0.000000001);
+        return interpolation;
     }
 
-	void testEmpty()
-	{
-    Interpolation interpolation;
+    void checkInterpolationResults(const Interpolation &interpolation)
+    {
+        checkValueAtLowerLimit(interpolation);
+        checkValueAtUpperLimit(interpolation);
+        checkValuesAtExactBulkPoints(interpolation);
+        checkValuesInsideInterpolationRange(interpolation);
+        checkValuesOutsideInterpolationRange(interpolation);
+    }
 
-    std::stringstream str;
-    str << interpolation;
-    TS_ASSERT( str.str().compare("linear ; TOF ; TOF") == 0 );
+    void checkValueAtLowerLimit(const Interpolation &interpolation)
+    {
+        checkValue(interpolation, m_tableXValues.front(), m_tableYValues.front(), "at lower limit");
+    }
 
-    Interpolation readIn;
-    str >> readIn;
+    void checkValueAtUpperLimit(const Interpolation &interpolation)
+    {
+        checkValue(interpolation, m_tableXValues.back(), m_tableYValues.back(), "at upper limit");
+    }
+
+    void checkValuesAtExactBulkPoints(const Interpolation &interpolation)
+    {
+        for(size_t i = 1; i < m_tableXValues.size() - 1; ++i) {
+            checkValue(interpolation, m_tableXValues[i], m_tableYValues[i], "at interpolation point");
+        }
+    }
+
+    void checkValuesInsideInterpolationRange(const Interpolation &interpolation) {
+        for(size_t i = 0; i < m_interpolationXValues.size(); ++i) {
+            checkValue(interpolation, m_interpolationXValues[i], m_expectedYValues[i], "inside interpolation range");
+        }
+    }
 
-    TS_ASSERT( readIn.containData() == false );
-	}
+    void checkValuesOutsideInterpolationRange(const Interpolation &interpolation)
+    {
+        for(size_t i = 0; i < m_outsideXValues.size(); ++i) {
+            checkValue(interpolation, m_outsideXValues[i], m_outsideYValues[i], "outside interpolation range");
+        }
+    }
+
+    /* This function performs the actual check.
+     * It takes a string argument to make it more obvious where the problem is.
+     */
+    void checkValue(const Interpolation &interpolation, double x, double y, std::string testedRange)
+    {
+        std::ostringstream errorString;
+        errorString << "Interpolation error " << testedRange;
+
+        TSM_ASSERT_EQUALS(errorString.str().c_str(), interpolation.value(x), y);
+    }
+
+    // These two vectors contain the data points from which the interpolation is constructed
+    std::vector<double> m_tableXValues;
+    std::vector<double> m_tableYValues;
   
+    // Two vectors with test values for the "bulk", e.g. no values at the limits and
+    std::vector<double> m_interpolationXValues;
+    std::vector<double> m_expectedYValues;
+
+    // Values outside interpolation range
+    std::vector<double> m_outsideXValues;
+    std::vector<double> m_outsideYValues;
+
+    // For the test of findIndexOfNextLargerValue access to protected member is needed
+    class TestableInterpolation : public Interpolation {
+        friend class InterpolationTest;
+
+    public:
+        TestableInterpolation() : Interpolation()
+        { }
+        ~TestableInterpolation() { }
+    };
 };
 
 #endif /*INTERPOLATIONTEST_H_*/
diff --git a/Code/Mantid/Framework/Kernel/test/ListValidatorTest.h b/Code/Mantid/Framework/Kernel/test/ListValidatorTest.h
index 566f529f8181b581016d0668e58a33968a898cb5..4fcabd4f39562c2729b38cd3a8c1ea995a30b0e4 100644
--- a/Code/Mantid/Framework/Kernel/test/ListValidatorTest.h
+++ b/Code/Mantid/Framework/Kernel/test/ListValidatorTest.h
@@ -49,12 +49,12 @@ public:
     StringListValidator v;
     v.addAllowedValue("one");
     v.addAllowedValue("two");
-    std::set<std::string> s;
+    std::vector<std::string> s;
     TS_ASSERT_THROWS_NOTHING( s = v.allowedValues() )
     TS_ASSERT_EQUALS( s.size(), 2 )
-    TS_ASSERT( s.count("one") )
-    TS_ASSERT( s.count("two") )
-    TS_ASSERT( ! s.count("three") )
+    TS_ASSERT( std::find( s.begin(), s.end(), "one")  != s.end() )
+    TS_ASSERT( std::find( s.begin(), s.end(), "two")  != s.end() )
+    TS_ASSERT( std::find( s.begin(), s.end(), "three")  == s.end() )
   }
 
   void testAddAllowedValue()
@@ -77,6 +77,87 @@ public:
     TS_ASSERT_DIFFERS( v, vv );
     TS_ASSERT( boost::dynamic_pointer_cast<StringListValidator>(vv) );
   }
+
+  void testAliasString()
+  {
+    std::vector<std::string> values;
+    values.push_back("one");
+    values.push_back("three");
+    values.push_back("two");
+    std::map<std::string,std::string> aliases;
+    aliases["1"] = "one";
+    aliases["2"] = "two";
+    aliases["3"] = "three";
+    StringListValidator validator(values, aliases);
+    TS_ASSERT_EQUALS( validator.isValid("one"), "" )
+    TS_ASSERT_EQUALS( validator.isValid("two"), "" )
+    TS_ASSERT_EQUALS( validator.isValid("three"), "" )
+
+    TS_ASSERT_EQUALS( validator.isValid("1"), "_alias" )
+    TS_ASSERT_EQUALS( validator.isValid("2"), "_alias" )
+    TS_ASSERT_EQUALS( validator.isValid("3"), "_alias" )
+    TS_ASSERT_EQUALS( validator.isValid("4"), "The value \"4\" is not in the list of allowed values" )
+
+    TS_ASSERT_EQUALS( validator.getValueForAlias("1"), "one" )
+    TS_ASSERT_EQUALS( validator.getValueForAlias("2"), "two" )
+    TS_ASSERT_EQUALS( validator.getValueForAlias("3"), "three" )
+
+    TS_ASSERT_THROWS( validator.getValueForAlias("4"), std::invalid_argument )
+  }
+  
+  void testAliasInt()
+  {
+    std::vector<int> values;
+    values.push_back(1);
+    values.push_back(5);
+    values.push_back(3);
+    std::map<std::string,std::string> aliases;
+    aliases["11"] = "1";
+    aliases["33"] = "3";
+    aliases["55"] = "5";
+    ListValidator<int> validator(values, aliases);
+    TS_ASSERT_EQUALS( validator.isValid(1), "" )
+    TS_ASSERT_EQUALS( validator.isValid(3), "" )
+    TS_ASSERT_EQUALS( validator.isValid(5), "" )
+
+    TS_ASSERT_EQUALS( validator.isValid(11), "_alias" )
+    TS_ASSERT_EQUALS( validator.isValid(33), "_alias" )
+    TS_ASSERT_EQUALS( validator.isValid(55), "_alias" )
+    TS_ASSERT_EQUALS( validator.isValid(4), "The value \"4\" is not in the list of allowed values" )
+
+    TS_ASSERT_EQUALS( validator.getValueForAlias("11"), "1" )
+    TS_ASSERT_EQUALS( validator.getValueForAlias("33"), "3" )
+    TS_ASSERT_EQUALS( validator.getValueForAlias("55"), "5" )
+
+    TS_ASSERT_THROWS( validator.getValueForAlias("13"), std::invalid_argument )
+  }
+  
+  void test_wrong_alias()
+  {
+    std::vector<std::string> values;
+    values.push_back("one");
+    values.push_back("three");
+    std::map<std::string,std::string> aliases;
+    aliases["1"] = "one";
+    aliases["2"] = "two";
+    TS_ASSERT_THROWS( StringListValidator validator(values, aliases), std::invalid_argument );
+  }
+  
+  void test_self_alias()
+  {
+    std::vector<std::string> values;
+    values.push_back("one");
+    values.push_back("three");
+    std::map<std::string,std::string> aliases;
+    aliases["1"] = "one";
+    aliases["three"] = "three";
+    aliases["one"] = "three";
+    StringListValidator validator(values, aliases);
+
+    TS_ASSERT_EQUALS( validator.isValid("one"), "" )
+    TS_ASSERT_EQUALS( validator.isValid("three"), "" )
+    TS_ASSERT_EQUALS( validator.isValid("1"), "_alias" )
+  }
   
 };
 
diff --git a/Code/Mantid/Framework/Kernel/test/MatrixTest.h b/Code/Mantid/Framework/Kernel/test/MatrixTest.h
index 247f07ab6bdf7689788f047003207108c616d4ac..41334c83ca179e3a79506dc53fa2c7a56ea0db6b 100644
--- a/Code/Mantid/Framework/Kernel/test/MatrixTest.h
+++ b/Code/Mantid/Framework/Kernel/test/MatrixTest.h
@@ -162,6 +162,49 @@ public:
 	  TSM_ASSERT_THROWS("building matrix by this construcor and data with wrong number of elements should throw",(Matrix<double>(data)),std::invalid_argument);
   }
 
+  void test_Transpose_On_Square_Matrix_Matches_TPrime()
+  {
+    Matrix<double> A(2,2);
+    A[0][0]=1.0;
+    A[0][1]=2.0;
+    A[1][0]=3.0;
+    A[1][1]=4.0;
+
+    auto B = A.Tprime(); // new matrix
+    TS_ASSERT_EQUALS(1.0, B[0][0]);
+    TS_ASSERT_EQUALS(3.0, B[0][1]);
+    TS_ASSERT_EQUALS(2.0, B[1][0]);
+    TS_ASSERT_EQUALS(4.0, B[1][1]);
+
+    A.Transpose(); // in place
+    TS_ASSERT_EQUALS(1.0, A[0][0]);
+    TS_ASSERT_EQUALS(3.0, A[0][1]);
+    TS_ASSERT_EQUALS(2.0, A[1][0]);
+    TS_ASSERT_EQUALS(4.0, A[1][1]);
+
+  }
+
+  void test_Transpose_On_Irregular_Matrix_Matches_TPrime()
+  {
+    Matrix<double> A(2,3);
+    A[0][0]=1.0;
+    A[0][1]=2.0;
+    A[0][2]=3.0;
+    A[1][0]=4.0;
+    A[1][1]=5.0;
+    A[1][2]=6.0;
+
+    auto B = A.Tprime(); // new matrix
+    TS_ASSERT_EQUALS(2, B.numCols());
+    TS_ASSERT_EQUALS(3, B.numRows());
+    TS_ASSERT_EQUALS(1.0, B[0][0]);
+    TS_ASSERT_EQUALS(4.0, B[0][1]);
+    TS_ASSERT_EQUALS(2.0, B[1][0]);
+    TS_ASSERT_EQUALS(5.0, B[1][1]);
+    TS_ASSERT_EQUALS(3.0, B[2][0]);
+    TS_ASSERT_EQUALS(6.0, B[2][1]);
+  }
+
 
   void testFromVectorBuildCorrect()
   {
diff --git a/Code/Mantid/Framework/Kernel/test/MultiFileValidatorTest.h b/Code/Mantid/Framework/Kernel/test/MultiFileValidatorTest.h
index 18f9d6604f695f4dd3b0c5a3e3fdccc8c406e48e..1a2868e535c000127138b00ea0eae7985f8f22e2 100644
--- a/Code/Mantid/Framework/Kernel/test/MultiFileValidatorTest.h
+++ b/Code/Mantid/Framework/Kernel/test/MultiFileValidatorTest.h
@@ -30,7 +30,9 @@ void testVectorConstructor()
   vec.push_back("raw");
   vec.push_back("RAW");
   FileValidator v(vec);
-  TS_ASSERT_EQUALS  ( v.allowedValues().size(), 2 );
+
+  //File extensions are converted to lowercase so should have one unique extension
+  TS_ASSERT_EQUALS  ( v.allowedValues().size(), 1 );
 }
 
 void testCopyConstructor()
@@ -40,7 +42,9 @@ void testCopyConstructor()
   vec.push_back("RAW");
   FileValidator v(vec);
   FileValidator copy(v);
-  TS_ASSERT_EQUALS  ( copy.allowedValues().size(), 2 );
+
+  //File extensions are converted to lowercase so should have one unique extension
+  TS_ASSERT_EQUALS  ( copy.allowedValues().size(), 1 );
 }
 
 void testPassesOnExistentFiles()
diff --git a/Code/Mantid/Framework/Kernel/test/PropertyWithValueTest.h b/Code/Mantid/Framework/Kernel/test/PropertyWithValueTest.h
index 0ae11f4010097436ea041e1f1e21603c1d5cc8b9..4eb2853d5615b7858bccb32e2a0a2883e6ddef29 100644
--- a/Code/Mantid/Framework/Kernel/test/PropertyWithValueTest.h
+++ b/Code/Mantid/Framework/Kernel/test/PropertyWithValueTest.h
@@ -502,11 +502,11 @@ public:
     TS_ASSERT_EQUALS( p.setValue("three"), "The value \"three\" is not in the list of allowed values" );
     TS_ASSERT_EQUALS( p.value(), "two" );
     TS_ASSERT_EQUALS( p.isValid(), "" );
-    std::set<std::string> vals;
-    TS_ASSERT_THROWS_NOTHING( vals = p.allowedValues() );
-    TS_ASSERT_EQUALS( vals.size(), 2 );
-    TS_ASSERT( vals.count("one") );
-    TS_ASSERT( vals.count("two") );
+    std::vector<std::string> s;
+    TS_ASSERT_THROWS_NOTHING( s = p.allowedValues() );
+    TS_ASSERT_EQUALS( s.size(), 2 );
+    TS_ASSERT( std::find( s.begin(), s.end(), "one")  != s.end() )
+    TS_ASSERT( std::find( s.begin(), s.end(), "two")  != s.end() )
   }
   
   void testIsDefault()
@@ -603,6 +603,32 @@ public:
     delete p1;
     delete p2;
   }
+
+  void test_string_property_alias()
+  {
+    // system("pause");
+    std::vector<std::string> allowedValues;
+    allowedValues.push_back( "Hello");
+    allowedValues.push_back( "World");
+    std::map<std::string,std::string> alias;
+    alias["1"] = "Hello";
+    alias["0"] = "World";
+    auto validator = boost::make_shared<ListValidator<std::string>>(allowedValues,alias);
+    PropertyWithValue<std::string> prop("String","",validator);
+    TS_ASSERT_THROWS_NOTHING( prop = "Hello" );
+    std::string value = prop;
+    TS_ASSERT_EQUALS( value, "Hello" );
+    
+    TS_ASSERT_THROWS( prop = "Mantid", std::invalid_argument );
+    
+    TS_ASSERT_THROWS_NOTHING( prop = "1" );
+    value = prop;
+    TS_ASSERT_EQUALS( value, "Hello" );
+    
+    TS_ASSERT_THROWS_NOTHING( prop = "0" );
+    value = prop;
+    TS_ASSERT_EQUALS( value, "World" );
+  }
   
 private:
   PropertyWithValue<int> *iProp;
diff --git a/Code/Mantid/Framework/Kernel/test/QuatTest.h b/Code/Mantid/Framework/Kernel/test/QuatTest.h
index 4071965ad2f1108b47cd1fda20b595a7ea6208fb..cd3ab774e93a24ba9fec7707736afc26606db327 100644
--- a/Code/Mantid/Framework/Kernel/test/QuatTest.h
+++ b/Code/Mantid/Framework/Kernel/test/QuatTest.h
@@ -457,6 +457,55 @@ public:
     TS_ASSERT_DELTA(final.Z(), 1.0, 1e-5);
   }
 
+  void testGetEulerAngles1()
+  {
+    Quat X(120.0, V3D(1,0,0));
+    Quat Y(-60.0, V3D(0,1,0));
+    Quat Z(90.0, V3D(0,0,1));
+    Quat rot = X * Y * Z;
+
+    std::vector<double> angles = rot.getEulerAngles("XYZ");
+    TS_ASSERT_DELTA(angles[0], 120.0, 1e-5);
+    TS_ASSERT_DELTA(angles[1], -60.0, 1e-5);
+    TS_ASSERT_DELTA(angles[2], 90.0, 1e-5);
+  }
+
+  void testGetEulerAngles2()
+  {
+    //Test using a different convention
+    Quat X(0.0, V3D(1,0,0));
+    Quat Y(15.0, V3D(0,1,0));
+    Quat Z(75.0, V3D(0,0,1));
+    Quat rot = Z * X * Y;
+
+    std::vector<double> angles = rot.getEulerAngles("ZXY");
+    TS_ASSERT_DELTA(angles[0], 75.0, 1e-5);
+    TS_ASSERT_DELTA(angles[1], 0.0, 1e-5);
+    TS_ASSERT_DELTA(angles[2], 15.0, 1e-5);
+  }
+
+  void testGetEulerAngles3()
+  {
+    //In some cases we don't get the same angles out as we put in.
+    //That's okay though, so long as they represent the same rotation.
+    Quat X(68.0, V3D(1,0,0));
+    Quat Y(175.0, V3D(0,1,0));
+    Quat Z(20.0, V3D(0,0,1));
+    Quat rot = X * Y * Z;
+
+    Quat X2(-112.0, V3D(1,0,0));
+    Quat Y2(5.0, V3D(0,1,0));
+    Quat Z2(-160.0, V3D(0,0,1));
+    Quat rot2 = X * Y * Z;
+
+    TS_ASSERT(rot == rot2);
+
+    std::vector<double> angles = rot.getEulerAngles("XYZ");
+    TS_ASSERT_DELTA(angles[0], -112.0, 1e-5);
+    TS_ASSERT_DELTA(angles[1], 5.0, 1e-5);
+    TS_ASSERT_DELTA(angles[2], -160.0, 1e-5);
+  }
+
   void compareArbitrary(const Quat& rotQ)
   {
     V3D oX(1,0,0);
diff --git a/Code/Mantid/Framework/Kernel/test/StartsWithValidatorTest.h b/Code/Mantid/Framework/Kernel/test/StartsWithValidatorTest.h
index 7f53f9e44cfd2ee28f2eda5d67888de65b67cc5a..39a4f0a4bc79872053f679f1a2ae67548c053528 100644
--- a/Code/Mantid/Framework/Kernel/test/StartsWithValidatorTest.h
+++ b/Code/Mantid/Framework/Kernel/test/StartsWithValidatorTest.h
@@ -49,12 +49,12 @@ public:
     StartsWithValidator v;
     v.addAllowedValue("one");
     v.addAllowedValue("two");
-    std::set<std::string> s;
+    std::vector<std::string> s;
     TS_ASSERT_THROWS_NOTHING( s = v.allowedValues() )
     TS_ASSERT_EQUALS( s.size(), 2 )
-    TS_ASSERT( s.count("one") )
-    TS_ASSERT( s.count("two") )
-    TS_ASSERT( ! s.count("three") )
+    TS_ASSERT( std::find( s.begin(), s.end(), "one")  != s.end() )
+    TS_ASSERT( std::find( s.begin(), s.end(), "two")  != s.end() )
+    TS_ASSERT( std::find( s.begin(), s.end(), "three")  == s.end() )
   }
 
   void testLongValues()
diff --git a/Code/Mantid/Framework/Kernel/test/UnitTest.h b/Code/Mantid/Framework/Kernel/test/UnitTest.h
index 4042d190153a77df7f586b0328324d69b1b0c0c1..6439181b2c1e141354443e7179ffda7c5ee1e2b4 100644
--- a/Code/Mantid/Framework/Kernel/test/UnitTest.h
+++ b/Code/Mantid/Framework/Kernel/test/UnitTest.h
@@ -172,6 +172,26 @@ public:
     TS_ASSERT(lim_max!=label.conversionTOFMax());
   }
 
+  /**
+   * Tests the two equality operators == and !=
+   */
+  void testEqualityOperators()
+  {
+    //Get some units to test equality with
+    auto *e1 = Energy().clone();
+    auto *e2 = Energy().clone();
+    auto *wl = Wavelength().clone();
+
+    //Test equality operator
+    TS_ASSERT(*e1 == *e2);
+
+    //Test inequality oeprator
+    TS_ASSERT(*e1 != *wl);
+
+    delete e1;
+    delete e2;
+    delete wl;
+  }
 
   //----------------------------------------------------------------------
   // Base Unit class tests
diff --git a/Code/Mantid/Framework/Kernel/test/V3DTest.h b/Code/Mantid/Framework/Kernel/test/V3DTest.h
index 5f1262780a7c760cea13c4775798c9e1b669aa8c..98f6367c19481da8cf1d12c77a09f5950bfb348a 100644
--- a/Code/Mantid/Framework/Kernel/test/V3DTest.h
+++ b/Code/Mantid/Framework/Kernel/test/V3DTest.h
@@ -12,340 +12,340 @@
 
 using Mantid::Kernel::V3D;
 
-class V3DTest : public CxxTest::TestSuite
+class V3DTest: public CxxTest::TestSuite
 {
 private:
 
-  Mantid::Kernel::V3D a,b,c,d;
+  Mantid::Kernel::V3D a, b, c, d;
 
 public:
-    void testEmptyConstructor()
-    {
-        // very important as a MD geometry rely on it later
-        TS_ASSERT_EQUALS(a.X(),0.0);
-        TS_ASSERT_EQUALS(a.Y(),0.0);
-        TS_ASSERT_EQUALS(a.Z(),0.0);
-    }
-    void testDefaultConstructor()
-    {
-        Mantid::Kernel::V3D d(1.0,2.0,3.0);
-        TS_ASSERT_EQUALS(d.X(),1.0);
-        TS_ASSERT_EQUALS(d.Y(),2.0);
-        TS_ASSERT_EQUALS(d.Z(),3.0);
-    }
-    void testAssignment()
-    {
-        a(1.0,1.0,1.0);
-        TS_ASSERT_EQUALS(a.X(),1.0);
-        TS_ASSERT_EQUALS(a.Y(),1.0);
-        TS_ASSERT_EQUALS(a.Z(),1.0);
-    }
-    void testcopyConstructor()
-    {
-        a(2.0,2.0,2.0);
-        Mantid::Kernel::V3D d(a);
-        TS_ASSERT_EQUALS(d.X(),2.0);
-        TS_ASSERT_EQUALS(d.Y(),2.0);
-        TS_ASSERT_EQUALS(d.Z(),2.0);
-    }
-    void testOperatorEqual()
-    {
-        a(-1.0,-1.0,-1.0);
-        b=a;
-        TS_ASSERT_EQUALS(b.X(),-1.0);
-        TS_ASSERT_EQUALS(b.Y(),-1.0);
-        TS_ASSERT_EQUALS(b.Z(),-1.0);
-    }
-
-    void testPlusOperation()
-    {
-        a(1.0,1.0,1.0);
-        b(2.0,3.0,4.0);
-        c=a+b;
-        TS_ASSERT_EQUALS(c.X(),3.0);
-        TS_ASSERT_EQUALS(c.Y(),4.0);
-        TS_ASSERT_EQUALS(c.Z(),5.0);
-    }
-    void testMinusOperation()
-    {
-        a(1.0,2.0,3.0);
-        b(1.0,2.0,3.0);
-        c=a-b;
-        TS_ASSERT_EQUALS(c.X(),0.0);
-        TS_ASSERT_EQUALS(c.Y(),0.0);
-        TS_ASSERT_EQUALS(c.Z(),0.0);
-    }
-    void testMultipliesOperation()
-    {
-        a(1.0,2.0,3.0);
-        b(1.0,2.0,3.0);
-        c=a*b;
-        TS_ASSERT_EQUALS(c.X(),1.0);
-        TS_ASSERT_EQUALS(c.Y(),4.0);
-        TS_ASSERT_EQUALS(c.Z(),9.0);
-        a*=a;
-        // I want a TS_ASSERT here... a==c
-    }
-    void testDividesOperation()
-    {
-        a(1.0,2.0,3.0);
-        b(1.0,2.0,3.0);
-        c=a/b;
-        TS_ASSERT_EQUALS(c.X(),1.0);
-        TS_ASSERT_EQUALS(c.Y(),1.0);
-        TS_ASSERT_EQUALS(c.Z(),1.0);
-    }
-    void testPlusEqualOperation()
-    {
-        a(1.0,2.0,3.0);
-        b(0.0,0.0,0.0);
-        b+=a;
-        TS_ASSERT_EQUALS(b.X(),1.0);
-        TS_ASSERT_EQUALS(b.Y(),2.0);
-        TS_ASSERT_EQUALS(b.Z(),3.0);
-    }
-    void testMinusEqualOperation()
-    {
-        a(1.0,2.0,3.0);
-        b(0.0,0.0,0.0);
-        b-=a;
-        TS_ASSERT_EQUALS(b.X(),-1.0);
-        TS_ASSERT_EQUALS(b.Y(),-2.0);
-        TS_ASSERT_EQUALS(b.Z(),-3.0);
-    }
-    void testMultipliesEqualOperation()
-    {
-        a(1.0,2.0,3.0);
-        b(2.0,2.0,2.0);
-        b*=a;
-        TS_ASSERT_EQUALS(b.X(),2.0);
-        TS_ASSERT_EQUALS(b.Y(),4.0);
-        TS_ASSERT_EQUALS(b.Z(),6.0);
-    }
-    void testDividesEqualOperation()
-    {
-        a(1.0,2.0,3.0);
-        b(2.0,2.0,2.0);
-        b/=a;
-        TS_ASSERT_EQUALS(b.X(),2.0);
-        TS_ASSERT_EQUALS(b.Y(),1.0);
-        TS_ASSERT_EQUALS(b.Z(),2.0/3.0);
-    }
-    void testScaleMultiplies()
-    {
-        a(1.0,2.0,3.0);
-        b=a * -2.0;
-        TS_ASSERT_EQUALS(b.X(),-2.0);
-        TS_ASSERT_EQUALS(b.Y(),-4.0);
-        TS_ASSERT_EQUALS(b.Z(),-6.0);
-    }
-    void testScaleMultipliesEqual()
-    {
-        a(1.0,2.0,3.0);
-        a*=2.0;
-        TS_ASSERT_EQUALS(a.X(),2.0);
-        TS_ASSERT_EQUALS(a.Y(),4.0);
-        TS_ASSERT_EQUALS(a.Z(),6.0);
-    }
-    void testScaleDivides()
-    {
-        a(1.0,2.0,3.0);
-        b=a/2.0;
-        TS_ASSERT_EQUALS(b.X(),0.5);
-        TS_ASSERT_EQUALS(b.Y(),1.0);
-        TS_ASSERT_EQUALS(b.Z(),1.5);
-    }
-    void testScaleDividesEqual()
-    {
-        a(1.0,2.0,3.0);
-        a/=2.0;
-        TS_ASSERT_EQUALS(a.X(),0.5);
-        TS_ASSERT_EQUALS(a.Y(),1.0);
-        TS_ASSERT_EQUALS(a.Z(),1.5);
-    }
-    void testEqualEqualOperator()
-    {
-        a(1.0,1.0,1.0);
-        b=a;
-        TS_ASSERT(a==b);
-    }
-    void testLessStrictOperator()
-    {
-        a(1.0,1.0,1.0);
-        b(2.0,1.0,0.0);
-        TS_ASSERT(a<b);
-        a(1.0,1.0,1.0);
-        b(1.0,2.0,0.0);
-        TS_ASSERT(a<b);
-        a(1.0,1.0,1.0);
-        b(1.0,1.0,2.0);
-        TS_ASSERT(a<b);
-        b=a;
-        TS_ASSERT(!(a<b));
-    }
-    void testGetX()
-    {
-        a(1.0,0.0,0.0);
-        TS_ASSERT_EQUALS(a.X(),1.0);
-    }
-    void testGetY()
-    {
-        a(1.0,2.0,0.0);
-        TS_ASSERT_EQUALS(a.Y(),2.0);
-    }
-    void testGetZ()
-    {
-        a(1.0,0.0,3.0);
-        TS_ASSERT_EQUALS(a.Z(),3.0);
-    }
-    void testOperatorBracketNonConst()
-    {
-        a(1.0,2.0,3.0);
-        TS_ASSERT_EQUALS(a[0],1.0);
-        TS_ASSERT_EQUALS(a[1],2.0);
-        TS_ASSERT_EQUALS(a[2],3.0);
-        a[0]=-1.0;
-        a[1]=-2.0;
-        a[2]=-3.0;
-        TS_ASSERT_EQUALS(a[0],-1.0);
-        TS_ASSERT_EQUALS(a[1],-2.0);
-        TS_ASSERT_EQUALS(a[2],-3.0);
-    }
-    void testOperatorBracketConst()
-    {
-        const Mantid::Kernel::V3D d(1.0,2.0,3.0);
-        TS_ASSERT_EQUALS(d[0],1.0);
-        TS_ASSERT_EQUALS(d[1],2.0);
-        TS_ASSERT_EQUALS(d[2],3.0);
-    }
-    void testOperatorBracketNonConstThrows()
-    {
-        TS_ASSERT_THROWS(a[-1],std::runtime_error&);
-        TS_ASSERT_THROWS(a[3],std::runtime_error&);
-    }
-    void testOperatorBracketConstThrows()
-    {
-        const Mantid::Kernel::V3D d(1.0,2.0,3.0);
-        TS_ASSERT_THROWS(d[-1],std::runtime_error&);
-        TS_ASSERT_THROWS(d[3],std::runtime_error&);
-    }
-    void testNorm()
-    {
-        a(1.0,-5.0,8.0);
-        TS_ASSERT_EQUALS(a.norm(),sqrt(90.0));
-    }
-    void testNorm2()
-    {
-        a(1.0,-5.0,8.0);
-        TS_ASSERT_EQUALS(a.norm2(),90.0);
-    }
-    void testNormalize()
-    {
-        a(1.0,1.0,1.0);
-        b=a;
-        b.normalize();
-        TS_ASSERT_EQUALS(b[0],1.0/sqrt(3.0));
-        TS_ASSERT_EQUALS(b[1],1.0/sqrt(3.0));
-        TS_ASSERT_EQUALS(b[2],1.0/sqrt(3.0));
-    }
-    void testScalarProduct()
-    {
-        a(1.0,2.0,1.0);
-        b(1.0,-2.0,-1.0);
-        double sp=a.scalar_prod(b);
-        TS_ASSERT_EQUALS(sp,-4.0);
-    }
-    void testCrossProduct()
-    {
-        a(1.0,0.0,0.0);
-        b(0.0,1.0,0.0);
-        c=a.cross_prod(b);
-        TS_ASSERT_EQUALS(c[0],0.0);
-        TS_ASSERT_EQUALS(c[1],0.0);
-        TS_ASSERT_EQUALS(c[2],1.0);
-    }
-    void testDistance()
-    {
-        a(0.0,0.0,0.0);
-        b(2.0,2.0,2.0);
-        double d=a.distance(b);
-        TS_ASSERT_EQUALS(d,2.0*sqrt(3.0));
-    }
-
-    void testZenith()
-    {
-      b(0.0,0.0,0.0);
-      a(9.9,7.6,0.0);
-      TS_ASSERT_EQUALS( a.zenith(a), 0.0 );
-      TS_ASSERT_DELTA( a.zenith(b), M_PI/2.0, 0.0001 );
-      a(-1.1,0.0,0.0);
-    TS_ASSERT_DELTA( a.zenith(b), M_PI/2.0, 0.0001 );
-    a(0.0,0.0,1.0);
-    TS_ASSERT_EQUALS( a.zenith(b), 0.0 );
-    a(1.0,0.0,1.0);
-    TS_ASSERT_DELTA( a.zenith(b), M_PI/4.0, 0.0001 );
-    a(1.0,0.0,-1.0);
-    TS_ASSERT_DELTA( a.zenith(b), 3.0*M_PI/4.0, 0.0001 );
-    }
-
-    void testAngle()
-    {
-      a(2.0,0.0,0.0);
-      b(0.0,1.0,0.0);
-      c(1.0,1.0,0.0);
-      d(-1.0,0.0,0.0);
-      TS_ASSERT_DELTA( a.angle(a), 0.0, 0.0001 );
-      TS_ASSERT_DELTA( a.angle(b), M_PI/2.0, 0.0001 );
-    TS_ASSERT_DELTA( a.angle(c), M_PI/4.0, 0.0001 );
-    TS_ASSERT_DELTA( a.angle(d), M_PI, 0.0001 );
-    }
+  void testEmptyConstructor()
+  {
+    // very important as a MD geometry rely on it later
+    TS_ASSERT_EQUALS(a.X(), 0.0);
+    TS_ASSERT_EQUALS(a.Y(), 0.0);
+    TS_ASSERT_EQUALS(a.Z(), 0.0);
+  }
+  void testDefaultConstructor()
+  {
+    Mantid::Kernel::V3D d(1.0, 2.0, 3.0);
+    TS_ASSERT_EQUALS(d.X(), 1.0);
+    TS_ASSERT_EQUALS(d.Y(), 2.0);
+    TS_ASSERT_EQUALS(d.Z(), 3.0);
+  }
+  void testAssignment()
+  {
+    a(1.0, 1.0, 1.0);
+    TS_ASSERT_EQUALS(a.X(), 1.0);
+    TS_ASSERT_EQUALS(a.Y(), 1.0);
+    TS_ASSERT_EQUALS(a.Z(), 1.0);
+  }
+  void testcopyConstructor()
+  {
+    a(2.0, 2.0, 2.0);
+    Mantid::Kernel::V3D d(a);
+    TS_ASSERT_EQUALS(d.X(), 2.0);
+    TS_ASSERT_EQUALS(d.Y(), 2.0);
+    TS_ASSERT_EQUALS(d.Z(), 2.0);
+  }
+  void testOperatorEqual()
+  {
+    a(-1.0, -1.0, -1.0);
+    b = a;
+    TS_ASSERT_EQUALS(b.X(), -1.0);
+    TS_ASSERT_EQUALS(b.Y(), -1.0);
+    TS_ASSERT_EQUALS(b.Z(), -1.0);
+  }
+
+  void testPlusOperation()
+  {
+    a(1.0, 1.0, 1.0);
+    b(2.0, 3.0, 4.0);
+    c = a + b;
+    TS_ASSERT_EQUALS(c.X(), 3.0);
+    TS_ASSERT_EQUALS(c.Y(), 4.0);
+    TS_ASSERT_EQUALS(c.Z(), 5.0);
+  }
+  void testMinusOperation()
+  {
+    a(1.0, 2.0, 3.0);
+    b(1.0, 2.0, 3.0);
+    c = a - b;
+    TS_ASSERT_EQUALS(c.X(), 0.0);
+    TS_ASSERT_EQUALS(c.Y(), 0.0);
+    TS_ASSERT_EQUALS(c.Z(), 0.0);
+  }
+  void testMultipliesOperation()
+  {
+    a(1.0, 2.0, 3.0);
+    b(1.0, 2.0, 3.0);
+    c = a * b;
+    TS_ASSERT_EQUALS(c.X(), 1.0);
+    TS_ASSERT_EQUALS(c.Y(), 4.0);
+    TS_ASSERT_EQUALS(c.Z(), 9.0);
+    a *= a;
+    // I want a TS_ASSERT here... a==c
+  }
+  void testDividesOperation()
+  {
+    a(1.0, 2.0, 3.0);
+    b(1.0, 2.0, 3.0);
+    c = a / b;
+    TS_ASSERT_EQUALS(c.X(), 1.0);
+    TS_ASSERT_EQUALS(c.Y(), 1.0);
+    TS_ASSERT_EQUALS(c.Z(), 1.0);
+  }
+  void testPlusEqualOperation()
+  {
+    a(1.0, 2.0, 3.0);
+    b(0.0, 0.0, 0.0);
+    b += a;
+    TS_ASSERT_EQUALS(b.X(), 1.0);
+    TS_ASSERT_EQUALS(b.Y(), 2.0);
+    TS_ASSERT_EQUALS(b.Z(), 3.0);
+  }
+  void testMinusEqualOperation()
+  {
+    a(1.0, 2.0, 3.0);
+    b(0.0, 0.0, 0.0);
+    b -= a;
+    TS_ASSERT_EQUALS(b.X(), -1.0);
+    TS_ASSERT_EQUALS(b.Y(), -2.0);
+    TS_ASSERT_EQUALS(b.Z(), -3.0);
+  }
+  void testMultipliesEqualOperation()
+  {
+    a(1.0, 2.0, 3.0);
+    b(2.0, 2.0, 2.0);
+    b *= a;
+    TS_ASSERT_EQUALS(b.X(), 2.0);
+    TS_ASSERT_EQUALS(b.Y(), 4.0);
+    TS_ASSERT_EQUALS(b.Z(), 6.0);
+  }
+  void testDividesEqualOperation()
+  {
+    a(1.0, 2.0, 3.0);
+    b(2.0, 2.0, 2.0);
+    b /= a;
+    TS_ASSERT_EQUALS(b.X(), 2.0);
+    TS_ASSERT_EQUALS(b.Y(), 1.0);
+    TS_ASSERT_EQUALS(b.Z(), 2.0/3.0);
+  }
+  void testScaleMultiplies()
+  {
+    a(1.0, 2.0, 3.0);
+    b = a * -2.0;
+    TS_ASSERT_EQUALS(b.X(), -2.0);
+    TS_ASSERT_EQUALS(b.Y(), -4.0);
+    TS_ASSERT_EQUALS(b.Z(), -6.0);
+  }
+  void testScaleMultipliesEqual()
+  {
+    a(1.0, 2.0, 3.0);
+    a *= 2.0;
+    TS_ASSERT_EQUALS(a.X(), 2.0);
+    TS_ASSERT_EQUALS(a.Y(), 4.0);
+    TS_ASSERT_EQUALS(a.Z(), 6.0);
+  }
+  void testScaleDivides()
+  {
+    a(1.0, 2.0, 3.0);
+    b = a / 2.0;
+    TS_ASSERT_EQUALS(b.X(), 0.5);
+    TS_ASSERT_EQUALS(b.Y(), 1.0);
+    TS_ASSERT_EQUALS(b.Z(), 1.5);
+  }
+  void testScaleDividesEqual()
+  {
+    a(1.0, 2.0, 3.0);
+    a /= 2.0;
+    TS_ASSERT_EQUALS(a.X(), 0.5);
+    TS_ASSERT_EQUALS(a.Y(), 1.0);
+    TS_ASSERT_EQUALS(a.Z(), 1.5);
+  }
+  void testEqualEqualOperator()
+  {
+    a(1.0, 1.0, 1.0);
+    b = a;
+    TS_ASSERT(a==b);
+  }
+  void testLessStrictOperator()
+  {
+    a(1.0, 1.0, 1.0);
+    b(2.0, 1.0, 0.0);
+    TS_ASSERT(a<b);
+    a(1.0, 1.0, 1.0);
+    b(1.0, 2.0, 0.0);
+    TS_ASSERT(a<b);
+    a(1.0, 1.0, 1.0);
+    b(1.0, 1.0, 2.0);
+    TS_ASSERT(a<b);
+    b = a;
+    TS_ASSERT(!(a<b));
+  }
+  void testGetX()
+  {
+    a(1.0, 0.0, 0.0);
+    TS_ASSERT_EQUALS(a.X(), 1.0);
+  }
+  void testGetY()
+  {
+    a(1.0, 2.0, 0.0);
+    TS_ASSERT_EQUALS(a.Y(), 2.0);
+  }
+  void testGetZ()
+  {
+    a(1.0, 0.0, 3.0);
+    TS_ASSERT_EQUALS(a.Z(), 3.0);
+  }
+  void testOperatorBracketNonConst()
+  {
+    a(1.0, 2.0, 3.0);
+    TS_ASSERT_EQUALS(a[0], 1.0);
+    TS_ASSERT_EQUALS(a[1], 2.0);
+    TS_ASSERT_EQUALS(a[2], 3.0);
+    a[0] = -1.0;
+    a[1] = -2.0;
+    a[2] = -3.0;
+    TS_ASSERT_EQUALS(a[0], -1.0);
+    TS_ASSERT_EQUALS(a[1], -2.0);
+    TS_ASSERT_EQUALS(a[2], -3.0);
+  }
+  void testOperatorBracketConst()
+  {
+    const Mantid::Kernel::V3D d(1.0, 2.0, 3.0);
+    TS_ASSERT_EQUALS(d[0], 1.0);
+    TS_ASSERT_EQUALS(d[1], 2.0);
+    TS_ASSERT_EQUALS(d[2], 3.0);
+  }
+  void testOperatorBracketNonConstThrows()
+  {
+    TS_ASSERT_THROWS(a[-1], std::runtime_error&);
+    TS_ASSERT_THROWS(a[3], std::runtime_error&);
+  }
+  void testOperatorBracketConstThrows()
+  {
+    const Mantid::Kernel::V3D d(1.0, 2.0, 3.0);
+    TS_ASSERT_THROWS(d[-1], std::runtime_error&);
+    TS_ASSERT_THROWS(d[3], std::runtime_error&);
+  }
+  void testNorm()
+  {
+    a(1.0, -5.0, 8.0);
+    TS_ASSERT_EQUALS(a.norm(), sqrt(90.0));
+  }
+  void testNorm2()
+  {
+    a(1.0, -5.0, 8.0);
+    TS_ASSERT_EQUALS(a.norm2(), 90.0);
+  }
+  void testNormalize()
+  {
+    a(1.0, 1.0, 1.0);
+    b = a;
+    b.normalize();
+    TS_ASSERT_EQUALS(b[0], 1.0/sqrt(3.0));
+    TS_ASSERT_EQUALS(b[1], 1.0/sqrt(3.0));
+    TS_ASSERT_EQUALS(b[2], 1.0/sqrt(3.0));
+  }
+  void testScalarProduct()
+  {
+    a(1.0, 2.0, 1.0);
+    b(1.0, -2.0, -1.0);
+    double sp = a.scalar_prod(b);
+    TS_ASSERT_EQUALS(sp, -4.0);
+  }
+  void testCrossProduct()
+  {
+    a(1.0, 0.0, 0.0);
+    b(0.0, 1.0, 0.0);
+    c = a.cross_prod(b);
+    TS_ASSERT_EQUALS(c[0], 0.0);
+    TS_ASSERT_EQUALS(c[1], 0.0);
+    TS_ASSERT_EQUALS(c[2], 1.0);
+  }
+  void testDistance()
+  {
+    a(0.0, 0.0, 0.0);
+    b(2.0, 2.0, 2.0);
+    double d = a.distance(b);
+    TS_ASSERT_EQUALS(d, 2.0*sqrt(3.0));
+  }
+
+  void testZenith()
+  {
+    b(0.0, 0.0, 0.0);
+    a(9.9, 7.6, 0.0);
+    TS_ASSERT_EQUALS( a.zenith(a), 0.0);
+    TS_ASSERT_DELTA( a.zenith(b), M_PI/2.0, 0.0001);
+    a(-1.1, 0.0, 0.0);
+    TS_ASSERT_DELTA( a.zenith(b), M_PI/2.0, 0.0001);
+    a(0.0, 0.0, 1.0);
+    TS_ASSERT_EQUALS( a.zenith(b), 0.0);
+    a(1.0, 0.0, 1.0);
+    TS_ASSERT_DELTA( a.zenith(b), M_PI/4.0, 0.0001);
+    a(1.0, 0.0, -1.0);
+    TS_ASSERT_DELTA( a.zenith(b), 3.0*M_PI/4.0, 0.0001);
+  }
+
+  void testAngle()
+  {
+    a(2.0, 0.0, 0.0);
+    b(0.0, 1.0, 0.0);
+    c(1.0, 1.0, 0.0);
+    d(-1.0, 0.0, 0.0);
+    TS_ASSERT_DELTA( a.angle(a), 0.0, 0.0001);
+    TS_ASSERT_DELTA( a.angle(b), M_PI/2.0, 0.0001);
+    TS_ASSERT_DELTA( a.angle(c), M_PI/4.0, 0.0001);
+    TS_ASSERT_DELTA( a.angle(d), M_PI, 0.0001);
+  }
 
   void testSpherical()
   {
-    double r=3,theta=45.0,phi=45.0;
-    a(0.0,0.0,0.0);
-    b(0.0,0.0,0.0);
-    b.spherical(r,theta,phi);
-    double d=a.distance(b);
-    TS_ASSERT_DELTA(d,r,0.0001);
-    TS_ASSERT_DELTA(b.X(), 1.5, 0.0001 );
-    TS_ASSERT_DELTA(b.Y(), 1.5, 0.0001 );
-    TS_ASSERT_DELTA(b.Z(), 3.0/sqrt(2.0), 0.0001 );
+    double r = 3, theta = 45.0, phi = 45.0;
+    a(0.0, 0.0, 0.0);
+    b(0.0, 0.0, 0.0);
+    b.spherical(r, theta, phi);
+    double d = a.distance(b);
+    TS_ASSERT_DELTA(d, r, 0.0001);
+    TS_ASSERT_DELTA(b.X(), 1.5, 0.0001);
+    TS_ASSERT_DELTA(b.Y(), 1.5, 0.0001);
+    TS_ASSERT_DELTA(b.Z(), 3.0/sqrt(2.0), 0.0001);
     // Test getSpherical returns the original values
-    TS_ASSERT_THROWS_NOTHING( b.getSpherical(r,theta,phi) );
-    TS_ASSERT_EQUALS( r,     3.0 );
-    TS_ASSERT_EQUALS( theta, 45.0 );
-    TS_ASSERT_EQUALS( phi,   45.0 );
+    TS_ASSERT_THROWS_NOTHING( b.getSpherical(r,theta,phi));
+    TS_ASSERT_EQUALS( r, 3.0);
+    TS_ASSERT_EQUALS( theta, 45.0);
+    TS_ASSERT_EQUALS( phi, 45.0);
   }
 
   void test_spherical_rad()
   {
-    a(0.0,0.0,0.0);
+    a(0.0, 0.0, 0.0);
     a.spherical_rad(1, 0, 0);
-    TS_ASSERT(a == V3D(0, 0, 1) );
-    a.spherical_rad(1, M_PI/2, 0);
-    TS_ASSERT(a == V3D(1, 0, 0) );
-    a.spherical_rad(1, M_PI/2, M_PI/2);
-    TS_ASSERT(a == V3D(0, 1, 0) );
+    TS_ASSERT(a == V3D(0, 0, 1));
+    a.spherical_rad(1, M_PI / 2, 0);
+    TS_ASSERT(a == V3D(1, 0, 0));
+    a.spherical_rad(1, M_PI / 2, M_PI / 2);
+    TS_ASSERT(a == V3D(0, 1, 0));
     a.spherical_rad(1, M_PI, 0);
-    TS_ASSERT(a == V3D(0, 0, -1) );
-    a.spherical_rad(2, M_PI/4, 0);
-    TS_ASSERT(a == V3D(sqrt(2.0), 0, sqrt(2.0)) );
+    TS_ASSERT(a == V3D(0, 0, -1));
+    a.spherical_rad(2, M_PI / 4, 0);
+    TS_ASSERT(a == V3D(sqrt(2.0), 0, sqrt(2.0)));
   }
 
   void test_azimuth_polar_SNS()
   {
-    a(0.0,0.0,0.0);
-    a.azimuth_polar_SNS( 1.0, 0, M_PI/2);
-    TS_ASSERT(a == V3D(1.0, 0, 0) );
-    a.azimuth_polar_SNS( 1.0, M_PI/2, M_PI/2);
-    TS_ASSERT(a == V3D(0.0, 0, 1.0) );
-    a.azimuth_polar_SNS( 2, 0, 0);
-    TS_ASSERT(a == V3D(0, 2, 0) );
-    a.azimuth_polar_SNS( 2, 0, M_PI);
-    TS_ASSERT(a == V3D(0, -2, 0) );
-    a.azimuth_polar_SNS( 2, 0, M_PI/4);
-    TS_ASSERT(a == V3D(sqrt(2.0), sqrt(2.0), 0) );
+    a(0.0, 0.0, 0.0);
+    a.azimuth_polar_SNS(1.0, 0, M_PI / 2);
+    TS_ASSERT(a == V3D(1.0, 0, 0));
+    a.azimuth_polar_SNS(1.0, M_PI / 2, M_PI / 2);
+    TS_ASSERT(a == V3D(0.0, 0, 1.0));
+    a.azimuth_polar_SNS(2, 0, 0);
+    TS_ASSERT(a == V3D(0, 2, 0));
+    a.azimuth_polar_SNS(2, 0, M_PI);
+    TS_ASSERT(a == V3D(0, -2, 0));
+    a.azimuth_polar_SNS(2, 0, M_PI / 4);
+    TS_ASSERT(a == V3D(sqrt(2.0), sqrt(2.0), 0));
   }
 
   /** Round each component to the nearest integer */
@@ -353,27 +353,27 @@ public:
   {
     a(1.2, 0.9, 4.34);
     a.round();
-    TS_ASSERT(a == V3D(1.0, 1.0, 4.0) );
+    TS_ASSERT(a == V3D(1.0, 1.0, 4.0));
 
     a(-1.2, -1.9, -3.9);
     a.round();
-    TS_ASSERT(a == V3D(-1.0, -2.0, -4.0) );
+    TS_ASSERT(a == V3D(-1.0, -2.0, -4.0));
   }
 
   void test_toString()
   {
-    V3D a(1,2,3);
+    V3D a(1, 2, 3);
     TS_ASSERT_EQUALS( a.toString(), "1 2 3");
     V3D b;
     b.fromString("4 5 6");
-    TS_ASSERT_EQUALS( b, V3D(4,5,6) );
+    TS_ASSERT_EQUALS( b, V3D(4,5,6));
   }
 
   void test_nexus()
   {
     NexusTestHelper th(true);
     th.createFile("V3DTest.nxs");
-    V3D a(1,2,3);
+    V3D a(1, 2, 3);
     a.saveNexus(th.file, "vector");
     th.reopenFile();
     V3D b;
@@ -389,32 +389,32 @@ public:
     in.push_back(V3D(1, 0, 0));
     in.push_back(V3D(0, 1, 0));
     out = V3D::makeVectorsOrthogonal(in);
-    TS_ASSERT( out[0] == V3D(1,0,0) );
-    TS_ASSERT( out[1] == V3D(0,1,0) );
-    TS_ASSERT( out[2] == V3D(0,0,1) );
+    TS_ASSERT( out[0] == V3D(1,0,0));
+    TS_ASSERT( out[1] == V3D(0,1,0));
+    TS_ASSERT( out[2] == V3D(0,0,1));
 
     // Non-unit vectors
     in.clear();
     in.push_back(V3D(0.5, 0, 0));
     in.push_back(V3D(0.5, 1.23, 0));
     out = V3D::makeVectorsOrthogonal(in);
-    TS_ASSERT( out[0] == V3D(1,0,0) );
-    TS_ASSERT( out[1] == V3D(0,1,0) );
-    TS_ASSERT( out[2] == V3D(0,0,1) );
+    TS_ASSERT( out[0] == V3D(1,0,0));
+    TS_ASSERT( out[1] == V3D(0,1,0));
+    TS_ASSERT( out[2] == V3D(0,0,1));
 
     // Flip it over
     in.clear();
     in.push_back(V3D(0.5, 0, 0));
     in.push_back(V3D(0.5, -1.23, 0));
     out = V3D::makeVectorsOrthogonal(in);
-    TS_ASSERT( out[0] == V3D(1,0,0) );
-    TS_ASSERT( out[1] == V3D(0,-1,0) );
-    TS_ASSERT( out[2] == V3D(0,0,-1) );
+    TS_ASSERT( out[0] == V3D(1,0,0));
+    TS_ASSERT( out[1] == V3D(0,-1,0));
+    TS_ASSERT( out[2] == V3D(0,0,-1));
   }
 
   void test_to_ostream()
   {
-    V3D a(1,2,3);
+    V3D a(1, 2, 3);
     std::ostringstream ostr;
     ostr << a;
     TS_ASSERT_EQUALS( ostr.str(), "[1,2,3]");
@@ -425,72 +425,71 @@ public:
     V3D a;
     std::istringstream istr("[4,5,6]");
     istr >> a;
-    TS_ASSERT_EQUALS( a, V3D(4,5,6) );
+    TS_ASSERT_EQUALS( a, V3D(4,5,6));
   }
 
   void test_toCrystllographic()
   {
-     V3D a0;
-     TS_ASSERT_THROWS(a0.toMillerIndexes(),std::invalid_argument);
-
-     V3D a1(0.1,0.2,5);
-     TS_ASSERT_THROWS_NOTHING(a1.toMillerIndexes());
+    V3D a0;
+    TS_ASSERT_THROWS(a0.toMillerIndexes(), std::invalid_argument);
 
-     TS_ASSERT_DELTA(1,a1[0],1.e-3);
-     TS_ASSERT_DELTA(2,a1[1],1.e-3);
-     TS_ASSERT_DELTA(50,a1[2],1.e-3);
+    V3D a1(0.1, 0.2, 5);
+    TS_ASSERT_THROWS_NOTHING(a1.toMillerIndexes());
 
-     V3D a2(0.02,0,2);
-     TS_ASSERT_THROWS_NOTHING(a2.toMillerIndexes());
+    TS_ASSERT_DELTA(1, a1[0], 1.e-3);
+    TS_ASSERT_DELTA(2, a1[1], 1.e-3);
+    TS_ASSERT_DELTA(50, a1[2], 1.e-3);
 
-     TS_ASSERT_DELTA(1,a2[0],1.e-3);
-     TS_ASSERT_DELTA(0,a2[1],1.e-3);
-     TS_ASSERT_DELTA(100,a2[2],1.e-3);
+    V3D a2(0.02, 0, 2);
+    TS_ASSERT_THROWS_NOTHING(a2.toMillerIndexes());
 
-     V3D a3(0.2,1.54321,2);
-     TS_ASSERT_THROWS_NOTHING(a3.toMillerIndexes(0.1));
+    TS_ASSERT_DELTA(1, a2[0], 1.e-3);
+    TS_ASSERT_DELTA(0, a2[1], 1.e-3);
+    TS_ASSERT_DELTA(100, a2[2], 1.e-3);
 
-     TS_ASSERT_DELTA(5.18,a3[0],1.e-1);
-     TS_ASSERT_DELTA(40,a3[1],1.e-1);
-     TS_ASSERT_DELTA(51.84,a3[2],1.e-1);
+    V3D a3(0.2, 1.54321, 2);
+    TS_ASSERT_THROWS_NOTHING(a3.toMillerIndexes(0.1));
 
-     V3D a4(-0.6,-0.80321,-3);
-     TS_ASSERT_THROWS_NOTHING(a4.toMillerIndexes(0.001));
+    TS_ASSERT_DELTA(5.18, a3[0], 1.e-1);
+    TS_ASSERT_DELTA(40, a3[1], 1.e-1);
+    TS_ASSERT_DELTA(51.84, a3[2], 1.e-1);
 
-     TS_ASSERT_DELTA(-1245,a4[0],1.e-1);
-     TS_ASSERT_DELTA(-1666.6,a4[1],1.e-1);
-     TS_ASSERT_DELTA(-6225,a4[2],1.e-1);
+    V3D a4(-0.6, -0.80321, -3);
+    TS_ASSERT_THROWS_NOTHING(a4.toMillerIndexes(0.001));
 
-     V3D a5(-3,-0.80321,-0.6);
-     TS_ASSERT_THROWS_NOTHING(a5.toMillerIndexes(0.1));
+    TS_ASSERT_DELTA(-1245, a4[0], 1.e-1);
+    TS_ASSERT_DELTA(-1666.6, a4[1], 1.e-1);
+    TS_ASSERT_DELTA(-6225, a4[2], 1.e-1);
 
-     TS_ASSERT_DELTA(-62.25,a5[0],1.e-1);
-     TS_ASSERT_DELTA(-16.66,a5[1],1.e-1);
-     TS_ASSERT_DELTA(-12.45,a5[2],1.e-1);
+    V3D a5(-3, -0.80321, -0.6);
+    TS_ASSERT_THROWS_NOTHING(a5.toMillerIndexes(0.1));
 
-     V3D a6(-3,5,-6);
-     TS_ASSERT_THROWS_NOTHING(a6.toMillerIndexes(0.001));
+    TS_ASSERT_DELTA(-62.25, a5[0], 1.e-1);
+    TS_ASSERT_DELTA(-16.66, a5[1], 1.e-1);
+    TS_ASSERT_DELTA(-12.45, a5[2], 1.e-1);
 
-     TS_ASSERT_DELTA(-3,a6[0],1.e-3);
-     TS_ASSERT_DELTA( 5,a6[1],1.e-3);
-     TS_ASSERT_DELTA(-6,a6[2],1.e-3);
+    V3D a6(-3, 5, -6);
+    TS_ASSERT_THROWS_NOTHING(a6.toMillerIndexes(0.001));
 
-     V3D a7(-3,0.5,-6);
-     TS_ASSERT_THROWS_NOTHING(a7.toMillerIndexes(0.001));
+    TS_ASSERT_DELTA(-3, a6[0], 1.e-3);
+    TS_ASSERT_DELTA( 5, a6[1], 1.e-3);
+    TS_ASSERT_DELTA(-6, a6[2], 1.e-3);
 
-     TS_ASSERT_DELTA(-6, a7[0],1.e-3);
-     TS_ASSERT_DELTA( 1, a7[1],1.e-3);
-     TS_ASSERT_DELTA(-12,a7[2],1.e-3);
+    V3D a7(-3, 0.5, -6);
+    TS_ASSERT_THROWS_NOTHING(a7.toMillerIndexes(0.001));
 
+    TS_ASSERT_DELTA(-6, a7[0], 1.e-3);
+    TS_ASSERT_DELTA( 1, a7[1], 1.e-3);
+    TS_ASSERT_DELTA(-12, a7[2], 1.e-3);
 
-     V3D a8(-3,0.3333,-6);
-     TS_ASSERT_THROWS_NOTHING(a8.toMillerIndexes(0.1));
+    V3D a8(-3, 0.3333, -6);
+    TS_ASSERT_THROWS_NOTHING(a8.toMillerIndexes(0.1));
 
-     TS_ASSERT_DELTA(-9, a8[0],1.e-2);
-     TS_ASSERT_DELTA( 1, a8[1],1.e-2);
-     TS_ASSERT_DELTA(-18,a8[2],1.e-2);
+    TS_ASSERT_DELTA(-9, a8[0], 1.e-2);
+    TS_ASSERT_DELTA( 1, a8[1], 1.e-2);
+    TS_ASSERT_DELTA(-18, a8[2], 1.e-2);
 
- /*    V3D a9(-3,5,-6);
+    /*    V3D a9(-3,5,-6);
      a9.normalize();
      TS_ASSERT_THROWS_NOTHING(a9.toMillerIndexes(0.1));
 
@@ -498,7 +497,44 @@ public:
      TS_ASSERT_DELTA( 5,a9[1],1.e-3);
      TS_ASSERT_DELTA(-6,a9[2],1.e-3);*/
 
+  }
+
+  void test_directionAngles_cubic_default()
+  {
+    const V3D orthoNormal(1.0, 1.0, 1.0);
+    const V3D angles = orthoNormal.directionAngles();
+    const double expectedAngle = acos(1.0 / sqrt(3.0)) * 180 / M_PI;
+    TS_ASSERT_DELTA(expectedAngle, angles[0], 1e-6);
+    TS_ASSERT_DELTA(expectedAngle, angles[1], 1e-6);
+    TS_ASSERT_DELTA(expectedAngle, angles[2], 1e-6);
+  }
+
+  void test_directionAngles_cubic_radians()
+  {
+    const V3D orthoNormal(1.0, 1.0, 1.0);
+    const bool inDegrees = false;
+    const V3D angles = orthoNormal.directionAngles(inDegrees);
+    const double expectedAngle = acos(1.0 / sqrt(3.0));
+    TS_ASSERT_DELTA(expectedAngle, angles[0], 1e-6);
+    TS_ASSERT_DELTA(expectedAngle, angles[1], 1e-6);
+    TS_ASSERT_DELTA(expectedAngle, angles[2], 1e-6);
+  }
 
+  void test_directionAngles_orthorombic()
+  {
+    const V3D v1(1.0, 1.0, 2.0);
+    V3D angles = v1.directionAngles();
+    const double modv1 = v1.norm();
+    TS_ASSERT_DELTA(acos(1.0 / modv1) * 180 / M_PI, angles[0], 1e-6);
+    TS_ASSERT_DELTA(acos(1.0 / modv1) * 180 / M_PI, angles[1], 1e-6);
+    TS_ASSERT_DELTA(acos(2.0 / modv1) * 180 / M_PI, angles[2], 1e-6);
+
+    const V3D v2(2.0, 3.0, 4.0);
+    angles = v2.directionAngles();
+    const double modv2 = v2.norm();
+    TS_ASSERT_DELTA(acos(2.0 / modv2) * 180 / M_PI, angles[0], 1e-6);
+    TS_ASSERT_DELTA(acos(3.0 / modv2) * 180 / M_PI, angles[1], 1e-6);
+    TS_ASSERT_DELTA(acos(4.0 / modv2) * 180 / M_PI, angles[2], 1e-6);
   }
 
 };
diff --git a/Code/Mantid/Framework/MDAlgorithms/CMakeLists.txt b/Code/Mantid/Framework/MDAlgorithms/CMakeLists.txt
index 69a0ba944ac4c794d30cda7243e1ba0c6f85946a..d4952e2ba98ce353b8482e9c9582c96cbe6f367f 100644
--- a/Code/Mantid/Framework/MDAlgorithms/CMakeLists.txt
+++ b/Code/Mantid/Framework/MDAlgorithms/CMakeLists.txt
@@ -196,7 +196,6 @@ set ( TEST_FILES
 	LoadMDTest.h
 	LoadSQWTest.h
 	LogarithmMDTest.h
-	LoadILLAsciiTest.h
 	MDResolutionConvolutionFactoryTest.h
 	MaskMDTest.h
 	MergeMDFilesTest.h
diff --git a/Code/Mantid/Framework/MDAlgorithms/src/LoadSQW.cpp b/Code/Mantid/Framework/MDAlgorithms/src/LoadSQW.cpp
index 1879d759e5e848b7766f6eb94eeec3d54b56625a..508b3982d05b201844aab3d9473b68b6248d8b6a 100644
--- a/Code/Mantid/Framework/MDAlgorithms/src/LoadSQW.cpp
+++ b/Code/Mantid/Framework/MDAlgorithms/src/LoadSQW.cpp
@@ -379,7 +379,8 @@ namespace Mantid
       // Q units so general goniometer should provide unit rotation matrix
       info->mutableRun().mutableGoniometer().makeUniversalGoniometer();
       //
-      info->mutableSample().setOrientedLattice(new OrientedLattice(a,b,c,aa,bb,cc));
+      OrientedLattice latt(a,b,c,aa,bb,cc);
+      info->mutableSample().setOrientedLattice(&latt );
       ws->addExperimentInfo(info);
     }
 
diff --git a/Code/Mantid/Framework/MDAlgorithms/test/CachedExperimentInfoTest.h b/Code/Mantid/Framework/MDAlgorithms/test/CachedExperimentInfoTest.h
index 1701630807d0ca578661756528a3076a7b0ba5a0..3ffa9da205c0aa3e64984c34f84d907c0f592eef 100644
--- a/Code/Mantid/Framework/MDAlgorithms/test/CachedExperimentInfoTest.h
+++ b/Code/Mantid/Framework/MDAlgorithms/test/CachedExperimentInfoTest.h
@@ -229,7 +229,8 @@ private:
 
     m_expt->setInstrument(instrument);
     m_expt->mutableRun().addProperty("deltaE-mode", DeltaEMode::asString(emode));
-    m_expt->mutableSample().setOrientedLattice(new Mantid::Geometry::OrientedLattice(5.57,5.51,12.298));
+    Mantid::Geometry::OrientedLattice latt(5.57,5.51,12.298);
+    m_expt->mutableSample().setOrientedLattice(&latt);
 
     if(emode == DeltaEMode::Direct) // Direct
     {
diff --git a/Code/Mantid/Framework/MDAlgorithms/test/CentroidPeaksMD2Test.h b/Code/Mantid/Framework/MDAlgorithms/test/CentroidPeaksMD2Test.h
index 38146b7980e5d5eb21f8d971e0eb0eda0fb87f36..ada885d65317c365c15fa304425e537328fe78e0 100644
--- a/Code/Mantid/Framework/MDAlgorithms/test/CentroidPeaksMD2Test.h
+++ b/Code/Mantid/Framework/MDAlgorithms/test/CentroidPeaksMD2Test.h
@@ -4,13 +4,14 @@
 #include "MantidMDAlgorithms/CentroidPeaksMD2.h"
 #include "MantidAPI/AnalysisDataService.h"
 #include "MantidAPI/IMDEventWorkspace.h"
-#include "MantidAPI/FrameworkManager.h"
 #include "MantidDataObjects/PeaksWorkspace.h"
 #include "MantidGeometry/MDGeometry/MDHistoDimension.h"
 #include "MantidKernel/System.h"
 #include "MantidKernel/Timer.h"
 #include "MantidMDEvents/MDEventFactory.h"
 #include "MantidTestHelpers/ComponentCreationHelper.h"
+#include "MantidMDAlgorithms/CreateMDWorkspace.h"
+#include "MantidMDAlgorithms/FakeMDEventData.h"
 #include <boost/math/distributions/normal.hpp>
 #include <boost/math/special_functions/fpclassify.hpp>
 #include <boost/math/special_functions/pow.hpp>
@@ -51,14 +52,18 @@ public:
   static void createMDEW()
   {
     // ---- Start with empty MDEW ----
-    FrameworkManager::Instance().exec("CreateMDWorkspace", 14,
-        "Dimensions", "3",
-        "Extents", "-10,10,-10,10,-10,10",
-        "Names", "h,k,l",
-        "Units", "-,-,-",
-        "SplitInto", "5",
-        "MaxRecursionDepth", "2",
-        "OutputWorkspace", "CentroidPeaksMD2Test_MDEWS");
+    CreateMDWorkspace algC;
+    TS_ASSERT_THROWS_NOTHING( algC.initialize() )
+    TS_ASSERT( algC.isInitialized() )
+    TS_ASSERT_THROWS_NOTHING( algC.setProperty("Dimensions", "3") );
+    TS_ASSERT_THROWS_NOTHING( algC.setProperty("Extents", "-10,10,-10,10,-10,10") );
+    TS_ASSERT_THROWS_NOTHING( algC.setProperty("Names", "h,k,l") );
+    TS_ASSERT_THROWS_NOTHING( algC.setProperty("Units", "-,-,-") );
+    TS_ASSERT_THROWS_NOTHING( algC.setProperty("SplitInto", "5") );
+    TS_ASSERT_THROWS_NOTHING( algC.setProperty("MaxRecursionDepth", "2") );
+    TS_ASSERT_THROWS_NOTHING( algC.setPropertyValue("OutputWorkspace", "CentroidPeaksMD2Test_MDEWS" ) );
+    TS_ASSERT_THROWS_NOTHING( algC.execute() );
+    TS_ASSERT( algC.isExecuted() );
   }
 
 
@@ -68,10 +73,14 @@ public:
   {
     std::ostringstream mess;
     mess << num << ", " << x << ", " << y << ", " << z << ", " << radius;
-    FrameworkManager::Instance().exec("FakeMDEventData", 6,
-        "InputWorkspace", "CentroidPeaksMD2Test_MDEWS",
-        "PeakParams", mess.str().c_str(),
-        "RandomSeed", "1234");
+    FakeMDEventData algF;
+    TS_ASSERT_THROWS_NOTHING( algF.initialize() )
+    TS_ASSERT( algF.isInitialized() )
+    TS_ASSERT_THROWS_NOTHING( algF.setPropertyValue("InputWorkspace", "CentroidPeaksMD2Test_MDEWS" ) );
+    TS_ASSERT_THROWS_NOTHING( algF.setProperty("PeakParams",mess.str().c_str() ) );
+    TS_ASSERT_THROWS_NOTHING( algF.setProperty("RandomSeed", "1234" ) );
+    TS_ASSERT_THROWS_NOTHING( algF.execute() );
+    TS_ASSERT( algF.isExecuted() );
 
   }
 
diff --git a/Code/Mantid/Framework/MDAlgorithms/test/CentroidPeaksMDTest.h b/Code/Mantid/Framework/MDAlgorithms/test/CentroidPeaksMDTest.h
index 128cccfd7facf5549f27cceb73f1966df4ee2e10..44e18fd891199191b537c371267d120d52117823 100644
--- a/Code/Mantid/Framework/MDAlgorithms/test/CentroidPeaksMDTest.h
+++ b/Code/Mantid/Framework/MDAlgorithms/test/CentroidPeaksMDTest.h
@@ -4,13 +4,14 @@
 #include "MantidMDAlgorithms/CentroidPeaksMD.h"
 #include "MantidAPI/AnalysisDataService.h"
 #include "MantidAPI/IMDEventWorkspace.h"
-#include "MantidAPI/FrameworkManager.h"
 #include "MantidDataObjects/PeaksWorkspace.h"
 #include "MantidGeometry/MDGeometry/MDHistoDimension.h"
 #include "MantidKernel/System.h"
 #include "MantidKernel/Timer.h"
 #include "MantidMDEvents/MDEventFactory.h"
 #include "MantidTestHelpers/ComponentCreationHelper.h"
+#include "MantidMDAlgorithms/CreateMDWorkspace.h"
+#include "MantidMDAlgorithms/FakeMDEventData.h"
 #include <boost/math/distributions/normal.hpp>
 #include <boost/math/special_functions/fpclassify.hpp>
 #include <boost/math/special_functions/pow.hpp>
@@ -51,14 +52,18 @@ public:
   static void createMDEW()
   {
     // ---- Start with empty MDEW ----
-    FrameworkManager::Instance().exec("CreateMDWorkspace", 14,
-        "Dimensions", "3",
-        "Extents", "-10,10,-10,10,-10,10",
-        "Names", "h,k,l",
-        "Units", "-,-,-",
-        "SplitInto", "5",
-        "MaxRecursionDepth", "2",
-        "OutputWorkspace", "CentroidPeaksMDTest_MDEWS");
+    CreateMDWorkspace algC;
+    TS_ASSERT_THROWS_NOTHING( algC.initialize() )
+    TS_ASSERT( algC.isInitialized() )
+    TS_ASSERT_THROWS_NOTHING( algC.setProperty("Dimensions", "3") );
+    TS_ASSERT_THROWS_NOTHING( algC.setProperty("Extents", "-10,10,-10,10,-10,10") );
+    TS_ASSERT_THROWS_NOTHING( algC.setProperty("Names", "h,k,l") );
+    TS_ASSERT_THROWS_NOTHING( algC.setProperty("Units", "-,-,-") );
+    TS_ASSERT_THROWS_NOTHING( algC.setProperty("SplitInto", "5") );
+    TS_ASSERT_THROWS_NOTHING( algC.setProperty("MaxRecursionDepth", "2") );
+    TS_ASSERT_THROWS_NOTHING( algC.setPropertyValue("OutputWorkspace", "CentroidPeaksMDTest_MDEWS" ) );
+    TS_ASSERT_THROWS_NOTHING( algC.execute() );
+    TS_ASSERT( algC.isExecuted() );
   }
 
 
@@ -68,10 +73,14 @@ public:
   {
     std::ostringstream mess;
     mess << num << ", " << x << ", " << y << ", " << z << ", " << radius;
-    FrameworkManager::Instance().exec("FakeMDEventData", 6,
-        "InputWorkspace", "CentroidPeaksMDTest_MDEWS",
-        "PeakParams", mess.str().c_str(),
-        "RandomSeed", "1234");
+    FakeMDEventData algF;
+    TS_ASSERT_THROWS_NOTHING( algF.initialize() )
+    TS_ASSERT( algF.isInitialized() )
+    TS_ASSERT_THROWS_NOTHING( algF.setPropertyValue("InputWorkspace", "CentroidPeaksMDTest_MDEWS" ) );
+    TS_ASSERT_THROWS_NOTHING( algF.setProperty("PeakParams",mess.str().c_str() ) );
+    TS_ASSERT_THROWS_NOTHING( algF.setProperty("RandomSeed", "1234" ) );
+    TS_ASSERT_THROWS_NOTHING( algF.execute() );
+    TS_ASSERT( algF.isExecuted() );
 
   }
 
diff --git a/Code/Mantid/Framework/MDAlgorithms/test/ConvertToMDMinMaxGlobalTest.h b/Code/Mantid/Framework/MDAlgorithms/test/ConvertToMDMinMaxGlobalTest.h
index 60910604fa5a1aa97cff0e0867b829087968cc35..0981bc731c63c8bd64ec5a3a94f0faacccd52177 100644
--- a/Code/Mantid/Framework/MDAlgorithms/test/ConvertToMDMinMaxGlobalTest.h
+++ b/Code/Mantid/Framework/MDAlgorithms/test/ConvertToMDMinMaxGlobalTest.h
@@ -228,8 +228,8 @@ private:
           pmap.addDouble(physicalPixel,"Efixed",Ef);
           ws->replaceInstrumentParameters(pmap);
       }
-
-      ws->mutableSample().setOrientedLattice(new Mantid::Geometry::OrientedLattice(2,3,4,90,90,90));
+      Mantid::Geometry::OrientedLattice latt(2,3,4,90,90,90);
+      ws->mutableSample().setOrientedLattice(&latt);
 
       Mantid::Kernel::TimeSeriesProperty<double> * p = new Mantid::Kernel::TimeSeriesProperty<double>("doubleProp");
       TS_ASSERT_THROWS_NOTHING( p->addValue("2007-11-30T16:17:00",9.99) );
diff --git a/Code/Mantid/Framework/MDAlgorithms/test/ConvertToMDMinMaxLocalTest.h b/Code/Mantid/Framework/MDAlgorithms/test/ConvertToMDMinMaxLocalTest.h
index 6f77593a6236e095fc2971f457eb400f30240356..5ca43c8ba0ae23f9cdbaede1b68fa601da806a4e 100644
--- a/Code/Mantid/Framework/MDAlgorithms/test/ConvertToMDMinMaxLocalTest.h
+++ b/Code/Mantid/Framework/MDAlgorithms/test/ConvertToMDMinMaxLocalTest.h
@@ -253,8 +253,8 @@ private:
           pmap.addDouble(physicalPixel,"Efixed",Ef);
           ws->replaceInstrumentParameters(pmap);
       }
-
-      ws->mutableSample().setOrientedLattice(new Mantid::Geometry::OrientedLattice(2,3,4,90,90,90));
+      Mantid::Geometry::OrientedLattice latt(2,3,4,90,90,90);
+      ws->mutableSample().setOrientedLattice(&latt);
 
       Mantid::Kernel::TimeSeriesProperty<double> * p = new Mantid::Kernel::TimeSeriesProperty<double>("doubleProp");
       TS_ASSERT_THROWS_NOTHING( p->addValue("2007-11-30T16:17:00",9.99) );
diff --git a/Code/Mantid/Framework/MDAlgorithms/test/ConvertToMDTest.h b/Code/Mantid/Framework/MDAlgorithms/test/ConvertToMDTest.h
index 25ac7ac9eed1915a853d664f76fc4614172e2442..85a3fc70baeb73feb396d4f40ec2bbbbff595e39 100644
--- a/Code/Mantid/Framework/MDAlgorithms/test/ConvertToMDTest.h
+++ b/Code/Mantid/Framework/MDAlgorithms/test/ConvertToMDTest.h
@@ -55,6 +55,7 @@ public:
 static ConvertToMDTest *createSuite() { return new ConvertToMDTest(); }
 static void destroySuite(ConvertToMDTest * suite) { delete suite; }    
 
+typedef std::vector<std::string> PropertyAllowedValues;
 
 void testInit(){
 
@@ -193,21 +194,20 @@ void testAlgorithmProperties()
   TSM_ASSERT_THROWS_NOTHING("Property name has changed. This has broken Create MD Workspace GUI. Fix CreateMDWorkspaceGUI!", QDimProperty = alg.getProperty("MinValues"));
   TSM_ASSERT_THROWS_NOTHING("Property name has changed. This has broken Create MD Workspace GUI. Fix CreateMDWorkspaceGUI!", QDimProperty = alg.getProperty("MaxValues"));
 
-  typedef std::set<std::string> PropertyAllowedValues;
   QDimProperty =alg.getProperty("QDimensions");
   PropertyAllowedValues QDimValues = QDimProperty->allowedValues();
   TSM_ASSERT_EQUALS("QDimensions property values have changed. This has broken Create MD Workspace GUI. Fix CreateMDWorkspaceGUI!", 3, QDimValues.size());
-  TSM_ASSERT("QDimensions property values have changed. This has broken Create MD Workspace GUI. Fix CreateMDWorkspaceGUI!",  QDimValues.find("CopyToMD") != QDimValues.end());
-  TSM_ASSERT("QDimensions property values have changed. This has broken Create MD Workspace GUI. Fix CreateMDWorkspaceGUI!", QDimValues.find("|Q|") != QDimValues.end());
-  TSM_ASSERT("QDimensions property values have changed. This has broken Create MD Workspace GUI. Fix CreateMDWorkspaceGUI!", QDimValues.find("Q3D") != QDimValues.end());
+  TSM_ASSERT("QDimensions property values have changed. This has broken Create MD Workspace GUI. Fix CreateMDWorkspaceGUI!",  findValue( QDimValues,"CopyToMD") );
+  TSM_ASSERT("QDimensions property values have changed. This has broken Create MD Workspace GUI. Fix CreateMDWorkspaceGUI!", findValue( QDimValues, "|Q|") );
+  TSM_ASSERT("QDimensions property values have changed. This has broken Create MD Workspace GUI. Fix CreateMDWorkspaceGUI!", findValue( QDimValues, "Q3D") );
 
   Mantid::Kernel::Property *dEAnalysisMode =alg.getProperty("dEAnalysisMode");
   PropertyAllowedValues dEAnalysisModeValues = dEAnalysisMode->allowedValues();
   TSM_ASSERT_EQUALS("QDimensions property values have changed. This has broken Create MD Workspace GUI. Fix CreateMDWorkspaceGUI!", 3, dEAnalysisModeValues.size());
-//  TSM_ASSERT("dEAnalysisMode property values have changed. This has broken Create MD Workspace GUI. Fix CreateMDWorkspaceGUI!",  dEAnalysisModeValues.find("NoDE") != dEAnalysisModeValues.end());
-  TSM_ASSERT("dEAnalysisMode property values have changed. This has broken Create MD Workspace GUI. Fix CreateMDWorkspaceGUI!", dEAnalysisModeValues.find("Direct") != dEAnalysisModeValues.end());
-  TSM_ASSERT("dEAnalysisMode property values have changed. This has broken Create MD Workspace GUI. Fix CreateMDWorkspaceGUI!", dEAnalysisModeValues.find("Indirect") != dEAnalysisModeValues.end());
-  TSM_ASSERT("dEAnalysisMode property values have changed. This has broken Create MD Workspace GUI. Fix CreateMDWorkspaceGUI!", dEAnalysisModeValues.find("Elastic") != dEAnalysisModeValues.end());
+//  TSM_ASSERT("dEAnalysisMode property values have changed. This has broken Create MD Workspace GUI. Fix CreateMDWorkspaceGUI!",  findValue( dEAnalysisModeValues, "NoDE") );
+  TSM_ASSERT("dEAnalysisMode property values have changed. This has broken Create MD Workspace GUI. Fix CreateMDWorkspaceGUI!", findValue( dEAnalysisModeValues, "Direct") );
+  TSM_ASSERT("dEAnalysisMode property values have changed. This has broken Create MD Workspace GUI. Fix CreateMDWorkspaceGUI!", findValue( dEAnalysisModeValues, "Indirect") );
+  TSM_ASSERT("dEAnalysisMode property values have changed. This has broken Create MD Workspace GUI. Fix CreateMDWorkspaceGUI!", findValue( dEAnalysisModeValues, "Elastic") );
 }
 
 
@@ -239,6 +239,11 @@ private:
       TS_ASSERT_DELTA(bin.second, bin_max, 1e-8);
     }
   }
+
+  bool findValue(const PropertyAllowedValues& container, const std::string& value)
+  {
+    return std::find( container.begin(), container.end(), value) != container.end();
+  }
 };
 
 //-------------------------------------------------------------------------------------------------
diff --git a/Code/Mantid/Framework/MDAlgorithms/test/ConvertToQ3DdETest.h b/Code/Mantid/Framework/MDAlgorithms/test/ConvertToQ3DdETest.h
index 3f2f3364285d7da60b4e21063077fee5824e4623..b148da7fd1bec7ca7934d7a33b42c2ca06fd5ca2 100644
--- a/Code/Mantid/Framework/MDAlgorithms/test/ConvertToQ3DdETest.h
+++ b/Code/Mantid/Framework/MDAlgorithms/test/ConvertToQ3DdETest.h
@@ -284,6 +284,7 @@ void xtestTransfMat1()
      Mantid::API::MatrixWorkspace_sptr ws2D =WorkspaceCreationHelper::createProcessedWorkspaceWithCylComplexInstrument(16,10,true);
      OrientedLattice * latt = new OrientedLattice(1,2,3, 90., 90., 90.);
      ws2D->mutableSample().setOrientedLattice(latt);
+     delete latt;
      MDWSDescription TWS(4);
 
 
@@ -298,7 +299,7 @@ void xtestTransfMat2()
      Mantid::API::MatrixWorkspace_sptr ws2D =WorkspaceCreationHelper::createProcessedWorkspaceWithCylComplexInstrument(16,10,true);
      OrientedLattice * latt = new OrientedLattice(1,2,3, 75., 45., 35.);
      ws2D->mutableSample().setOrientedLattice(latt);
-
+     delete latt;
       std::vector<double> rot;
     //std::vector<double> rot=pAlg->get_transf_matrix(ws2D,Kernel::V3D(1,0,0),Kernel::V3D(0,1,0));
      Kernel::Matrix<double> unit = Kernel::Matrix<double>(3,3, true);
@@ -310,7 +311,7 @@ void xtestTransfMat3()
      Mantid::API::MatrixWorkspace_sptr ws2D =WorkspaceCreationHelper::createProcessedWorkspaceWithCylComplexInstrument(16,10,true);
      OrientedLattice * latt = new OrientedLattice(1,2,3, 75., 45., 35.);
      ws2D->mutableSample().setOrientedLattice(latt);
-
+     delete latt;
       std::vector<double> rot;
      //std::vector<double> rot=pAlg->get_transf_matrix(ws2D,Kernel::V3D(1,0,0),Kernel::V3D(0,-1,0));
      Kernel::Matrix<double> unit = Kernel::Matrix<double>(3,3, true);
@@ -324,6 +325,7 @@ void xtestTransfMat4()
      Mantid::API::MatrixWorkspace_sptr ws2D =WorkspaceCreationHelper::createProcessedWorkspaceWithCylComplexInstrument(16,10,true);
      OrientedLattice * latt = new OrientedLattice(1,1,3, 90., 90., 90.);
      ws2D->mutableSample().setOrientedLattice(latt);
+     delete latt;
      ws2D->mutableRun().mutableGoniometer().setRotationAngle(0,0);
      ws2D->mutableRun().mutableGoniometer().setRotationAngle(1,0);
      ws2D->mutableRun().mutableGoniometer().setRotationAngle(2,0);
@@ -344,6 +346,7 @@ void xtestTransfMat5()
      Mantid::API::MatrixWorkspace_sptr ws2D =WorkspaceCreationHelper::createProcessedWorkspaceWithCylComplexInstrument(16,10,true);
      OrientedLattice * latt = new OrientedLattice(1,2,3, 75., 45., 90.);
      ws2D->mutableSample().setOrientedLattice(latt);
+     delete latt;
      ws2D->mutableRun().mutableGoniometer().setRotationAngle(0,0);
      ws2D->mutableRun().mutableGoniometer().setRotationAngle(1,0);
      ws2D->mutableRun().mutableGoniometer().setRotationAngle(2,0);
@@ -365,6 +368,7 @@ void xtestTransf_PSI_DPSI()
      Mantid::API::MatrixWorkspace_sptr ws2D =WorkspaceCreationHelper::createProcessedWorkspaceWithCylComplexInstrument(16,10,true);
      OrientedLattice * latt = new OrientedLattice(1,1,1, 90., 90., 90.);
      ws2D->mutableSample().setOrientedLattice(latt);
+     delete latt;
      ws2D->mutableRun().mutableGoniometer().setRotationAngle(0,0);
      ws2D->mutableRun().mutableGoniometer().setRotationAngle(1,-20); // Psi, dPsi
      ws2D->mutableRun().mutableGoniometer().setRotationAngle(2,0);
@@ -385,6 +389,7 @@ void xtestTransf_GL()
      Mantid::API::MatrixWorkspace_sptr ws2D =WorkspaceCreationHelper::createProcessedWorkspaceWithCylComplexInstrument(16,10,true);
      OrientedLattice * latt = new OrientedLattice(1,1,1, 90., 90., 90.);
      ws2D->mutableSample().setOrientedLattice(latt);
+     delete latt;
      ws2D->mutableRun().mutableGoniometer().setRotationAngle(0,20);  //gl
      ws2D->mutableRun().mutableGoniometer().setRotationAngle(1,0);
      ws2D->mutableRun().mutableGoniometer().setRotationAngle(2,0);
diff --git a/Code/Mantid/Framework/MDAlgorithms/test/IntegratePeaksMD2Test.h b/Code/Mantid/Framework/MDAlgorithms/test/IntegratePeaksMD2Test.h
index 8da53122e016758f352edb63f9f32f7ee262e08d..d81184d312c9cbc0d0309fb7b03ff0e9ee78673c 100644
--- a/Code/Mantid/Framework/MDAlgorithms/test/IntegratePeaksMD2Test.h
+++ b/Code/Mantid/Framework/MDAlgorithms/test/IntegratePeaksMD2Test.h
@@ -10,6 +10,8 @@
 #include "MantidKernel/Timer.h"
 #include "MantidMDEvents/MDEventFactory.h"
 #include "MantidMDAlgorithms/IntegratePeaksMD2.h"
+#include "MantidMDAlgorithms/CreateMDWorkspace.h"
+#include "MantidMDAlgorithms/FakeMDEventData.h"
 #include "MantidTestHelpers/ComponentCreationHelper.h"
 #include <boost/math/distributions/normal.hpp>
 #include <boost/math/special_functions/fpclassify.hpp>
@@ -37,15 +39,22 @@ using Mantid::Kernel::V3D;
 class IntegratePeaksMD2Test : public CxxTest::TestSuite
 {
 public:
+  IntegratePeaksMD2Test()
+  {
+
+	Mantid::API::FrameworkManager::Instance();
+  }
+  ~IntegratePeaksMD2Test()
+  {
+
+  }
 
   void test_Init()
   {
-    FrameworkManager::Instance();
     IntegratePeaksMD2 alg;
     TS_ASSERT_THROWS_NOTHING( alg.initialize() )
     TS_ASSERT( alg.isInitialized() )
   }
-  
 
   //-------------------------------------------------------------------------------
   /** Run the IntegratePeaksMD2 with the given peak radius integration param */
@@ -78,14 +87,19 @@ public:
   static void createMDEW()
   {
     // ---- Start with empty MDEW ----
-    FrameworkManager::Instance().exec("CreateMDWorkspace", 14,
-        "Dimensions", "3",
-        "Extents", "-10,10,-10,10,-10,10",
-        "Names", "h,k,l",
-        "Units", "-,-,-",
-        "SplitInto", "5",
-        "MaxRecursionDepth", "2",
-        "OutputWorkspace", "IntegratePeaksMD2Test_MDEWS");
+
+    CreateMDWorkspace algC;
+    TS_ASSERT_THROWS_NOTHING( algC.initialize() )
+    TS_ASSERT( algC.isInitialized() )
+    TS_ASSERT_THROWS_NOTHING( algC.setProperty("Dimensions", "3") );
+    TS_ASSERT_THROWS_NOTHING( algC.setProperty("Extents", "-10,10,-10,10,-10,10") );
+    TS_ASSERT_THROWS_NOTHING( algC.setProperty("Names", "h,k,l") );
+    TS_ASSERT_THROWS_NOTHING( algC.setProperty("Units", "-,-,-") );
+    TS_ASSERT_THROWS_NOTHING( algC.setProperty("SplitInto", "5") );
+    TS_ASSERT_THROWS_NOTHING( algC.setProperty("MaxRecursionDepth", "2") );
+    TS_ASSERT_THROWS_NOTHING( algC.setPropertyValue("OutputWorkspace", "IntegratePeaksMD2Test_MDEWS" ) );
+    TS_ASSERT_THROWS_NOTHING( algC.execute() );
+    TS_ASSERT( algC.isExecuted() );
   }
 
 
@@ -95,8 +109,13 @@ public:
   {
     std::ostringstream mess;
     mess << num << ", " << x << ", " << y << ", " << z << ", " << radius;
-    FrameworkManager::Instance().exec("FakeMDEventData", 4,
-        "InputWorkspace", "IntegratePeaksMD2Test_MDEWS", "PeakParams", mess.str().c_str());
+    FakeMDEventData algF;
+    TS_ASSERT_THROWS_NOTHING( algF.initialize() )
+    TS_ASSERT( algF.isInitialized() )
+    TS_ASSERT_THROWS_NOTHING( algF.setPropertyValue("InputWorkspace", "IntegratePeaksMD2Test_MDEWS" ) );
+    TS_ASSERT_THROWS_NOTHING( algF.setProperty("PeakParams",mess.str().c_str() ) );
+    TS_ASSERT_THROWS_NOTHING( algF.execute() );
+    TS_ASSERT( algF.isExecuted() );
   }
 
 
@@ -142,7 +161,7 @@ public:
     TS_ASSERT_DELTA( peakWS0->getPeak(0).getIntensity(), 2.0, 1e-2);
     // Error is also calculated
     TS_ASSERT_DELTA( peakWS0->getPeak(0).getSigmaIntensity(), sqrt(2.0), 1e-2);
-    Poco::File("IntegratePeaksMD2Test_MDEWSGaussian.dat").remove();
+    Poco::File(Mantid::Kernel::ConfigService::Instance().getString("defaultsave.directory") + "IntegratePeaksMD2Test_MDEWSGaussian.dat").remove();
 
     // Test profile back to back exponential
     fnct = "BackToBackExponential";
@@ -151,7 +170,7 @@ public:
     // TS_ASSERT_DELTA( peakWS0->getPeak(0).getIntensity(), 2.0, 0.2);
     // Error is also calculated
     // TS_ASSERT_DELTA( peakWS0->getPeak(0).getSigmaIntensity(), sqrt(2.0), 0.2);
-    Poco::File("IntegratePeaksMD2Test_MDEWSBackToBackExponential.dat").remove();
+    Poco::File(Mantid::Kernel::ConfigService::Instance().getString("defaultsave.directory") + "IntegratePeaksMD2Test_MDEWSBackToBackExponential.dat").remove();
     /*fnct = "ConvolutionExpGaussian";
     doRun(0.1,0.0,"IntegratePeaksMD2Test_peaks",0.0,true,true,fnct);
 
@@ -360,8 +379,14 @@ public:
     IntegratePeaksMD2Test::createMDEW();
 
     // Add a uniform, random background.
-    FrameworkManager::Instance().exec("FakeMDEventData", 4,
-        "InputWorkspace", "IntegratePeaksMD2Test_MDEWS", "UniformParams", "100000");
+
+    FakeMDEventData algF2;
+    TS_ASSERT_THROWS_NOTHING( algF2.initialize() )
+    TS_ASSERT( algF2.isInitialized() )
+    TS_ASSERT_THROWS_NOTHING( algF2.setPropertyValue("InputWorkspace", "IntegratePeaksMD2Test_MDEWS" ) );
+    TS_ASSERT_THROWS_NOTHING( algF2.setProperty("UniformParams","100000" ) );
+    TS_ASSERT_THROWS_NOTHING( algF2.execute() );
+    TS_ASSERT( algF2.isExecuted() );
 
     MDEventWorkspace3Lean::sptr mdews =
         AnalysisDataService::Instance().retrieveWS<MDEventWorkspace3Lean>("IntegratePeaksMD2Test_MDEWS");
diff --git a/Code/Mantid/Framework/MDAlgorithms/test/IntegratePeaksMDTest.h b/Code/Mantid/Framework/MDAlgorithms/test/IntegratePeaksMDTest.h
index 617003290591093d54c228a9897170a9904ecf74..f398c08b9904480c5059d151d1b0aa0f3f66af29 100644
--- a/Code/Mantid/Framework/MDAlgorithms/test/IntegratePeaksMDTest.h
+++ b/Code/Mantid/Framework/MDAlgorithms/test/IntegratePeaksMDTest.h
@@ -10,6 +10,8 @@
 #include "MantidKernel/Timer.h"
 #include "MantidMDEvents/MDEventFactory.h"
 #include "MantidMDAlgorithms/IntegratePeaksMD.h"
+#include "MantidMDAlgorithms/CreateMDWorkspace.h"
+#include "MantidMDAlgorithms/FakeMDEventData.h"
 #include "MantidTestHelpers/ComponentCreationHelper.h"
 #include <boost/math/distributions/normal.hpp>
 #include <boost/math/special_functions/fpclassify.hpp>
@@ -37,15 +39,22 @@ using Mantid::Kernel::V3D;
 class IntegratePeaksMDTest : public CxxTest::TestSuite
 {
 public:
+  IntegratePeaksMDTest()
+  {
+
+	Mantid::API::FrameworkManager::Instance();
+  }
+  ~IntegratePeaksMDTest()
+  {
+
+  }
 
   void test_Init()
   {
-    FrameworkManager::Instance();
     IntegratePeaksMD alg;
     TS_ASSERT_THROWS_NOTHING( alg.initialize() )
     TS_ASSERT( alg.isInitialized() )
   }
-  
 
   //-------------------------------------------------------------------------------
   /** Run the IntegratePeaksMD with the given peak radius integration param */
@@ -78,14 +87,19 @@ public:
   static void createMDEW()
   {
     // ---- Start with empty MDEW ----
-    FrameworkManager::Instance().exec("CreateMDWorkspace", 14,
-        "Dimensions", "3",
-        "Extents", "-10,10,-10,10,-10,10",
-        "Names", "h,k,l",
-        "Units", "-,-,-",
-        "SplitInto", "5",
-        "MaxRecursionDepth", "2",
-        "OutputWorkspace", "IntegratePeaksMDTest_MDEWS");
+
+    CreateMDWorkspace algC;
+    TS_ASSERT_THROWS_NOTHING( algC.initialize() )
+    TS_ASSERT( algC.isInitialized() )
+    TS_ASSERT_THROWS_NOTHING( algC.setProperty("Dimensions", "3") );
+    TS_ASSERT_THROWS_NOTHING( algC.setProperty("Extents", "-10,10,-10,10,-10,10") );
+    TS_ASSERT_THROWS_NOTHING( algC.setProperty("Names", "h,k,l") );
+    TS_ASSERT_THROWS_NOTHING( algC.setProperty("Units", "-,-,-") );
+    TS_ASSERT_THROWS_NOTHING( algC.setProperty("SplitInto", "5") );
+    TS_ASSERT_THROWS_NOTHING( algC.setProperty("MaxRecursionDepth", "2") );
+    TS_ASSERT_THROWS_NOTHING( algC.setPropertyValue("OutputWorkspace", "IntegratePeaksMDTest_MDEWS" ) );
+    TS_ASSERT_THROWS_NOTHING( algC.execute() );
+    TS_ASSERT( algC.isExecuted() );
   }
 
 
@@ -95,8 +109,13 @@ public:
   {
     std::ostringstream mess;
     mess << num << ", " << x << ", " << y << ", " << z << ", " << radius;
-    FrameworkManager::Instance().exec("FakeMDEventData", 4,
-        "InputWorkspace", "IntegratePeaksMDTest_MDEWS", "PeakParams", mess.str().c_str());
+    FakeMDEventData algF;
+    TS_ASSERT_THROWS_NOTHING( algF.initialize() )
+    TS_ASSERT( algF.isInitialized() )
+    TS_ASSERT_THROWS_NOTHING( algF.setPropertyValue("InputWorkspace", "IntegratePeaksMDTest_MDEWS" ) );
+    TS_ASSERT_THROWS_NOTHING( algF.setProperty("PeakParams",mess.str().c_str() ) );
+    TS_ASSERT_THROWS_NOTHING( algF.execute() );
+    TS_ASSERT( algF.isExecuted() );
   }
 
 
@@ -134,22 +153,24 @@ public:
 
     // Error is also calculated
     TS_ASSERT_DELTA( peakWS0->getPeak(0).getSigmaIntensity(), sqrt(2.0), 1e-2);
+
+    // Test profile Gaussian
     std::string fnct = "Gaussian";
     doRun(0.1,0.0,"IntegratePeaksMDTest_peaks",0.0,true,true,fnct);
     // More accurate integration changed values
     TS_ASSERT_DELTA( peakWS0->getPeak(0).getIntensity(), 2.0, 1e-2);
-
     // Error is also calculated
     TS_ASSERT_DELTA( peakWS0->getPeak(0).getSigmaIntensity(), sqrt(2.0), 1e-2);
-    Poco::File("IntegratePeaksMDTest_MDEWSGaussian.dat").remove();
+    Poco::File(Mantid::Kernel::ConfigService::Instance().getString("defaultsave.directory") + "IntegratePeaksMDTest_MDEWSGaussian.dat").remove();
+
+    // Test profile back to back exponential
     fnct = "BackToBackExponential";
     doRun(0.1,0.0,"IntegratePeaksMDTest_peaks",0.0,true,true,fnct);
 
     // TS_ASSERT_DELTA( peakWS0->getPeak(0).getIntensity(), 2.0, 0.2);
-
     // Error is also calculated
     // TS_ASSERT_DELTA( peakWS0->getPeak(0).getSigmaIntensity(), sqrt(2.0), 0.2);
-    Poco::File("IntegratePeaksMDTest_MDEWSBackToBackExponential.dat").remove();
+    Poco::File(Mantid::Kernel::ConfigService::Instance().getString("defaultsave.directory") + "IntegratePeaksMDTest_MDEWSBackToBackExponential.dat").remove();
     /*fnct = "ConvolutionExpGaussian";
     doRun(0.1,0.0,"IntegratePeaksMDTest_peaks",0.0,true,true,fnct);
 
@@ -358,8 +379,14 @@ public:
     IntegratePeaksMDTest::createMDEW();
 
     // Add a uniform, random background.
-    FrameworkManager::Instance().exec("FakeMDEventData", 4,
-        "InputWorkspace", "IntegratePeaksMDTest_MDEWS", "UniformParams", "100000");
+
+    FakeMDEventData algF2;
+    TS_ASSERT_THROWS_NOTHING( algF2.initialize() )
+    TS_ASSERT( algF2.isInitialized() )
+    TS_ASSERT_THROWS_NOTHING( algF2.setPropertyValue("InputWorkspace", "IntegratePeaksMDTest_MDEWS" ) );
+    TS_ASSERT_THROWS_NOTHING( algF2.setProperty("UniformParams","100000" ) );
+    TS_ASSERT_THROWS_NOTHING( algF2.execute() );
+    TS_ASSERT( algF2.isExecuted() );
 
     MDEventWorkspace3Lean::sptr mdews =
         AnalysisDataService::Instance().retrieveWS<MDEventWorkspace3Lean>("IntegratePeaksMDTest_MDEWS");
diff --git a/Code/Mantid/Framework/MDAlgorithms/test/LoadILLAsciiTest.h b/Code/Mantid/Framework/MDAlgorithms/test/LoadILLAsciiTest.h
deleted file mode 100644
index 66eb2a14f3a3c27ff97b64d8efc8fb6657504a45..0000000000000000000000000000000000000000
--- a/Code/Mantid/Framework/MDAlgorithms/test/LoadILLAsciiTest.h
+++ /dev/null
@@ -1,83 +0,0 @@
-#ifndef MANTID_MDALGORITHMS_LOADILLASCIITEST_H_
-#define MANTID_MDALGORITHMS_LOADILLASCIITEST_H_
-
-#include <cxxtest/TestSuite.h>
-
-#include "MantidMDAlgorithms/LoadILLAscii.h"
-#include "MantidMDAlgorithms/LoadILLAsciiHelper.h"
-
-using Mantid::MDAlgorithms::LoadILLAscii;
-using namespace Mantid::API;
-
-class LoadILLAsciiTest: public CxxTest::TestSuite {
-public:
-	// This pair of boilerplate methods prevent the suite being created statically
-	// This means the constructor isn't called when running other tests
-	static LoadILLAsciiTest *createSuite() {
-		return new LoadILLAsciiTest();
-	}
-	static void destroySuite(LoadILLAsciiTest *suite) {
-		delete suite;
-	}
-
-	LoadILLAsciiTest() :
-			m_testFile("ILLD2B_123944") {
-	}
-
-	void test_Init() {
-		LoadILLAscii alg;
-		TS_ASSERT_THROWS_NOTHING(alg.initialize())
-		TS_ASSERT(alg.isInitialized())
-	}
-
-	void test_exec() {
-
-		LoadILLAscii loader;
-		loader.initialize();
-		loader.setPropertyValue("Filename", m_testFile);
-		std::string outputSpaceName = "LoadILLTest_out";
-		loader.setPropertyValue("OutputWorkspace", outputSpaceName);
-		TS_ASSERT_THROWS_NOTHING( loader.execute());
-
-		// Retrieve the workspace from data service.
-		IMDEventWorkspace_sptr ws;
-		TS_ASSERT_THROWS_NOTHING(
-				ws = AnalysisDataService::Instance().retrieveWS<IMDEventWorkspace>(outputSpaceName));
-		TS_ASSERT(ws);
-
-		//TS_ASSERT_EQUALS( ws->getNEvents(), 409600);
-		// Trimmed file to be submitted to github
-		TS_ASSERT_EQUALS( ws->getNEvents(), 114688);
-
-		// Remove workspace from the data service.
-		AnalysisDataService::Instance().remove(outputSpaceName);
-
-	}
-
-//	// DOES NOT WORK. Can't find input file
-//	void test_LoadILLHelper() {
-//
-//		using Mantid::MDAlgorithms::ILLParser;
-//
-//		// Parses ascii file and fills the data scructures
-//		ILLParser illAsciiParser("../Test/AutoTestData/" + m_testFile);
-//		illAsciiParser.parse();
-//
-//		double wavelength = illAsciiParser.getValueFromHeader<double>("wavelength");
-//		TS_ASSERT_EQUALS(wavelength,25)
-//
-//		// get local references to the parsed file
-//		const std::vector<std::vector<int> > &spectraList = illAsciiParser.getSpectraList();
-//		const std::vector<std::map<std::string, std::string> > &spectraHeaderList = illAsciiParser.getSpectraHeaderList();
-//
-//		TS_ASSERT_EQUALS(spectraList.size(),25)
-//		TS_ASSERT_EQUALS(spectraHeaderList.size(),25)
-//
-//	}
-
-private:
-	std::string m_testFile;
-
-};
-
-#endif /* MANTID_MDALGORITHMS_LOADILLASCIITEST_H_ */
diff --git a/Code/Mantid/Framework/MDAlgorithms/test/ModeratorChopperResolutionTest.h b/Code/Mantid/Framework/MDAlgorithms/test/ModeratorChopperResolutionTest.h
index 4f1733fa46fb97d5f15380294aa20ecc6a8dc9ff..5eefde2693b2fbe9e63c9fb84bc56ec90b26fe56 100644
--- a/Code/Mantid/Framework/MDAlgorithms/test/ModeratorChopperResolutionTest.h
+++ b/Code/Mantid/Framework/MDAlgorithms/test/ModeratorChopperResolutionTest.h
@@ -71,7 +71,8 @@ private:
 
     m_expt->setInstrument(instrument);
     m_expt->mutableRun().addProperty("deltaE-mode", DeltaEMode::asString(Mantid::Kernel::DeltaEMode::Direct));
-    m_expt->mutableSample().setOrientedLattice(new Mantid::Geometry::OrientedLattice(5.57,5.51,12.298));
+    Mantid::Geometry::OrientedLattice latt(5.57,5.51,12.298);
+    m_expt->mutableSample().setOrientedLattice(&latt);
 
 
     // Add log entry
diff --git a/Code/Mantid/Framework/MDAlgorithms/test/MullerAnsatzTest.h b/Code/Mantid/Framework/MDAlgorithms/test/MullerAnsatzTest.h
index 2d335a60ccdc5fdb3f770fb983eac35acf33e5e8..9a9b216d955237563fcbb490046fe9a5f869c605 100644
--- a/Code/Mantid/Framework/MDAlgorithms/test/MullerAnsatzTest.h
+++ b/Code/Mantid/Framework/MDAlgorithms/test/MullerAnsatzTest.h
@@ -105,6 +105,7 @@ private:
     lattice->setUFromVectors(uVec, vVec);
 
     experimentDescr.mutableSample().setOrientedLattice(lattice);
+    delete lattice;
     experimentDescr.mutableRun().addProperty("temperature_log", 6.0);
 
     double weight(-1.0);
diff --git a/Code/Mantid/Framework/MDAlgorithms/test/Strontium122Test.h b/Code/Mantid/Framework/MDAlgorithms/test/Strontium122Test.h
index 78ca2fe8b4a5059389ae67b3add807b2af72d332..9cd187cb8886fdfd57ee53b248726eda1e8cdf59 100644
--- a/Code/Mantid/Framework/MDAlgorithms/test/Strontium122Test.h
+++ b/Code/Mantid/Framework/MDAlgorithms/test/Strontium122Test.h
@@ -120,6 +120,7 @@ private:
     lattice->setUFromVectors(uVec, vVec);
 
     experimentDescr.mutableSample().setOrientedLattice(lattice);
+    delete lattice;
     experimentDescr.mutableRun().addProperty("temperature_log", 6.0);
 
     double weight(-1.0);
diff --git a/Code/Mantid/Framework/MDAlgorithms/test/TobyFitBMatrixTest.h b/Code/Mantid/Framework/MDAlgorithms/test/TobyFitBMatrixTest.h
index 1ce164f3d0c0af79f9c74bcc891c11bf64a2be8f..92d05049bf28e1158441252c3ce6f1d5d5afd1b0 100644
--- a/Code/Mantid/Framework/MDAlgorithms/test/TobyFitBMatrixTest.h
+++ b/Code/Mantid/Framework/MDAlgorithms/test/TobyFitBMatrixTest.h
@@ -131,7 +131,7 @@ private:
     // OrientedLattice
     OrientedLattice * latticeRotation = new OrientedLattice;
     expt->mutableSample().setOrientedLattice(latticeRotation);
-
+    delete latticeRotation;
     return expt;
   }
 
diff --git a/Code/Mantid/Framework/MDAlgorithms/test/TobyFitYVectorTest.h b/Code/Mantid/Framework/MDAlgorithms/test/TobyFitYVectorTest.h
index ed8c3d8ea6763e5d1818e048984db87074e7f987..948f5addc0b2e1cdc59aa3c96f088aea57be459e 100644
--- a/Code/Mantid/Framework/MDAlgorithms/test/TobyFitYVectorTest.h
+++ b/Code/Mantid/Framework/MDAlgorithms/test/TobyFitYVectorTest.h
@@ -117,7 +117,7 @@ private:
     // OrientedLattice
     OrientedLattice * latticeRotation = new OrientedLattice;
     expt->mutableSample().setOrientedLattice(latticeRotation);
-
+    delete latticeRotation;
     return expt;
   }
 
diff --git a/Code/Mantid/Framework/MDEvents/inc/MantidMDEvents/OneStepMDEW.h b/Code/Mantid/Framework/MDEvents/inc/MantidMDEvents/OneStepMDEW.h
index b6a7cacbdcda97c1fcd4c2b39f94e5e2049e728a..9b2b8515a4277ae202df46de1793116fadc1ed33 100644
--- a/Code/Mantid/Framework/MDEvents/inc/MantidMDEvents/OneStepMDEW.h
+++ b/Code/Mantid/Framework/MDEvents/inc/MantidMDEvents/OneStepMDEW.h
@@ -2,19 +2,19 @@
 #define MANTID_MDEVENTS_ONESTEPMDEW_H_
     
 #include "MantidKernel/System.h"
-#include "MantidAPI/Algorithm.h" 
+#include "MantidAPI/DeprecatedAlgorithm.h"
 
 namespace Mantid
 {
 namespace MDEvents
 {
 
-  /** OneStepMDEW : TODO: DESCRIPTION
+  /** OneStepMDEW : Assumes elastic diffration. Load Event data and immediately converts to MDEvent with Lorentz correction applied.
    * 
    * @author
    * @date 2011-04-06 10:19:10.284945
    */
-  class DLLExport OneStepMDEW  : public API::Algorithm
+  class DLLExport OneStepMDEW  : public API::Algorithm, API::DeprecatedAlgorithm
   {
   public:
     OneStepMDEW();
diff --git a/Code/Mantid/Framework/MDEvents/src/OneStepMDEW.cpp b/Code/Mantid/Framework/MDEvents/src/OneStepMDEW.cpp
index 1f6eab79cd1a730c35ba34289d437e5ae39d1a65..4685af9e53ac661b667e9767c185e4af333e30d1 100644
--- a/Code/Mantid/Framework/MDEvents/src/OneStepMDEW.cpp
+++ b/Code/Mantid/Framework/MDEvents/src/OneStepMDEW.cpp
@@ -1,6 +1,7 @@
 #include "MantidMDEvents/OneStepMDEW.h"
 #include "MantidKernel/System.h"
 #include "MantidAPI/FileProperty.h"
+#include "MantidAPI/FrameworkManager.h"
 #include "MantidDataObjects/EventWorkspace.h"
 #include "MantidAPI/IMDEventWorkspace.h"
 //#include "MantidNexus/LoadEventNexus.h"
@@ -24,6 +25,7 @@ namespace Mantid
     */
     OneStepMDEW::OneStepMDEW()
     {
+      this->useAlgorithm("ConvertToDiffractionMDWorkspace");
     }
 
     //----------------------------------------------------------------------------------------------
@@ -56,17 +58,19 @@ namespace Mantid
     {
       std::string tempWsName = getPropertyValue("OutputWorkspace") + "_nxs";
 
-      Algorithm_sptr childAlg;
+
       // -------- First we load the event nexus file -------------
-      childAlg = AlgorithmFactory::Instance().create("LoadEventNexus", 1);
-      childAlg->initialize();
-      childAlg->setPropertyValue("Filename", getPropertyValue("Filename"));
-      childAlg->setPropertyValue("OutputWorkspace", tempWsName);
-      childAlg->executeAsChildAlg();
+      Algorithm_sptr loadAlg = createChildAlgorithm("LoadEventNexus", 0, 2);
+      loadAlg->initialize();
+      loadAlg->setPropertyValue("Filename", getPropertyValue("Filename"));
+      loadAlg->setPropertyValue("OutputWorkspace", tempWsName);
+      loadAlg->executeAsChildAlg();
+      IEventWorkspace_sptr tempWS = loadAlg->getProperty("OutputWorkspace");
 
       // --------- Now Convert -------------------------------
-      childAlg = createChildAlgorithm("ConvertToDiffractionMDWorkspace");
-      childAlg->setPropertyValue("InputWorkspace", tempWsName);
+
+      Algorithm_sptr childAlg = createChildAlgorithm("ConvertToDiffractionMDWorkspace",2,4,true,1);
+      childAlg->setProperty("InputWorkspace", tempWS);
       childAlg->setProperty<bool>("ClearInputWorkspace", false);
       childAlg->setProperty<bool>("LorentzCorrection", true);
       childAlg->executeAsChildAlg();
diff --git a/Code/Mantid/Framework/MDEvents/test/MDEventInserterTest.h b/Code/Mantid/Framework/MDEvents/test/MDEventInserterTest.h
index 65e648eea7774482a9c8cc4b66dbfadc9581583a..b7edbd209ec130d20cdab8c99ef84b81e5d5d6fa 100644
--- a/Code/Mantid/Framework/MDEvents/test/MDEventInserterTest.h
+++ b/Code/Mantid/Framework/MDEvents/test/MDEventInserterTest.h
@@ -5,6 +5,7 @@
 #include "MantidKernel/Timer.h"
 #include "MantidKernel/System.h"
 #include "MantidAPI/FrameworkManager.h"
+#include "MantidAPI/AlgorithmManager.h"
 #include "MantidAPI/AnalysisDataService.h"
 #include "MantidAPI/IMDEventWorkspace.h"
 #include "MantidAPI/IAlgorithm.h"
@@ -28,26 +29,19 @@ private:
   /// Test helper method. Creates an empty 2D MDEventWorkspace, with the specified event type.
   IMDEventWorkspace_sptr createInputWorkspace(const std::string& eventType)
   {
-    const std::string outWSName = "inputWS";
-
-    AnalysisDataServiceImpl& ADS = AnalysisDataService::Instance();
-
-    if(ADS.doesExist(outWSName))
-    {
-      ADS.remove(outWSName);
-    }
-    
-    IAlgorithm* createAlg = FrameworkManager::Instance().createAlgorithm("CreateMDWorkspace");
+    IAlgorithm_sptr createAlg = AlgorithmManager::Instance().createUnmanaged("CreateMDWorkspace");
     createAlg->initialize();
+    createAlg->setChild(true);
     createAlg->setProperty("Dimensions", 2);
     createAlg->setPropertyValue("Extents", "-10,10,-10,10");
     createAlg->setPropertyValue("Names", "A, B");
     createAlg->setPropertyValue("Units", "m, m");
     createAlg->setPropertyValue("EventType", eventType);
-    createAlg->setPropertyValue("OutputWorkspace", outWSName);
+    createAlg->setPropertyValue("OutputWorkspace", "out_ws");
     createAlg->execute();
-
-    return ADS.retrieveWS<IMDEventWorkspace>(outWSName);
+    Workspace_sptr temp = createAlg->getProperty("OutputWorkspace");
+    IMDEventWorkspace_sptr outWS = boost::dynamic_pointer_cast<IMDEventWorkspace>(temp);
+    return outWS;
   }
 
 public:
@@ -56,6 +50,11 @@ public:
   static MDEventInserterTest *createSuite() { return new MDEventInserterTest(); }
   static void destroySuite( MDEventInserterTest *suite ) { delete suite; }
 
+  MDEventInserterTest()
+  {
+    FrameworkManager::Instance();
+  }
+
 
   void test_add_md_lean_events()
   {
@@ -126,4 +125,4 @@ public:
 };
 
 
-#endif /* MANTID_MDEVENTS_MDEVENTINSERTERTEST_H_ */
\ No newline at end of file
+#endif /* MANTID_MDEVENTS_MDEVENTINSERTERTEST_H_ */
diff --git a/Code/Mantid/Framework/MDEvents/test/MDWSTransfTest.h b/Code/Mantid/Framework/MDEvents/test/MDWSTransfTest.h
index 5c5647f46b60583d59ec037d426778620d526478..f449888ae5b7bff2473bfa0a6c9abf6db3cd1fb7 100644
--- a/Code/Mantid/Framework/MDEvents/test/MDWSTransfTest.h
+++ b/Code/Mantid/Framework/MDEvents/test/MDWSTransfTest.h
@@ -65,7 +65,7 @@ void testFindTargetFrame()
 
    TS_ASSERT_EQUALS(CnvrtToMD::SampleFrame,Transf.findTargetFrame(TargWSDescription));
 
-   spws->mutableSample().setOrientedLattice(new Geometry::OrientedLattice(*pLattice)); 
+   spws->mutableSample().setOrientedLattice(pLattice);
    TS_ASSERT_EQUALS(CnvrtToMD::HKLFrame,Transf.findTargetFrame(TargWSDescription));
 
 }
@@ -83,7 +83,7 @@ void testForceTargetFrame()
    MDWSTransformTestHelper Transf;
    TSM_ASSERT_THROWS("Forced HKL frame would not accept workspace without oriented lattice",Transf.getTransfMatrix(TargWSDescription,CnvrtToMD::HKLFrame,CnvrtToMD::HKLScale),std::invalid_argument);
    TSM_ASSERT_THROWS("Forced SampleFrame frame would not accept workspace without goniometer defined",Transf.getTransfMatrix(TargWSDescription,CnvrtToMD::SampleFrame,CnvrtToMD::HKLScale),std::invalid_argument);
-   spws->mutableSample().setOrientedLattice(new Geometry::OrientedLattice(*pLattice)); 
+   spws->mutableSample().setOrientedLattice(pLattice);
    
    WorkspaceCreationHelper::SetGoniometer(spws,20,0,0);
 
@@ -203,8 +203,9 @@ void testTransf2HoraceQinA()
      MDEvents::MDWSDescription TWS;
      std::vector<double> minVal(4,-3),maxVal(4,3);
      TWS.setMinMax(minVal,maxVal);
+     Geometry::OrientedLattice latt(5*M_PI,M_PI,2*M_PI, 90., 90., 90.);
 
-     ws2D->mutableSample().setOrientedLattice(new Geometry::OrientedLattice(5*M_PI,M_PI,2*M_PI, 90., 90., 90.));
+     ws2D->mutableSample().setOrientedLattice(&latt);
      TWS.buildFromMatrixWS(ws2D,"Q3D","Direct");
 
      std::vector<double> u(3,0);
@@ -304,7 +305,8 @@ void testTransf2HKL()
  
      ws2D->mutableRun().mutableGoniometer().setRotationAngle(0,0);
      // this is Wollastonite
-     ws2D->mutableSample().setOrientedLattice(new Geometry::OrientedLattice(7.9250,7.3200,7.0650,90.0550,95.2170,103.4200));
+     Geometry::OrientedLattice latt(7.9250,7.3200,7.0650,90.0550,95.2170,103.4200);
+     ws2D->mutableSample().setOrientedLattice(&latt);
      // 
      //[transf,u_to_rlu]=calc_proj_matrix([7.9250,7.3200,7.0650], 90.0550,95.2170,103.4200, u, v, 0, omega, dpsi, gl, gs)
      // u to rlu
diff --git a/Code/Mantid/Framework/MDEvents/test/OneStepMDEWTest.h b/Code/Mantid/Framework/MDEvents/test/OneStepMDEWTest.h
index f5b64f4343cc55f0d3b6bb0971c440b079489ae2..6f9c971be39ad357a07e140c14be63fd6b9c0686 100644
--- a/Code/Mantid/Framework/MDEvents/test/OneStepMDEWTest.h
+++ b/Code/Mantid/Framework/MDEvents/test/OneStepMDEWTest.h
@@ -34,9 +34,9 @@ public:
     OneStepMDEW alg;
     TS_ASSERT_THROWS_NOTHING( alg.initialize() )
     TS_ASSERT( alg.isInitialized() )
-    TS_ASSERT_THROWS_NOTHING( alg.setPropertyValue("Filename", "CNCS_7860_event.nxs") );
-    TS_ASSERT_THROWS_NOTHING( alg.setPropertyValue("OutputWorkspace", "OneStepMDEWTest") );
-    TS_ASSERT_THROWS_NOTHING( alg.execute() );
+    alg.setPropertyValue("Filename", "HYS_11092_event.nxs");
+    alg.setPropertyValue("OutputWorkspace", "OneStepMDEWTest");
+    alg.execute();
     TS_ASSERT( alg.isExecuted() );
 
     IMDEventWorkspace_sptr out;
@@ -44,7 +44,6 @@ public:
         AnalysisDataService::Instance().retrieve("OneStepMDEWTest")); );
     TS_ASSERT(out);
     if (!out) return;
-    TS_ASSERT_LESS_THAN( 1000, out->getNPoints());
   }
 
 
diff --git a/Code/Mantid/Framework/PythonInterface/inc/MantidPythonInterface/kernel/PythonObjectInstantiator.h b/Code/Mantid/Framework/PythonInterface/inc/MantidPythonInterface/kernel/PythonObjectInstantiator.h
index 41a12eb36828d0158e75c7f98f38bc6a0bb183e7..27d28c460a9808cbd2112c4aeab325eccb99d019 100644
--- a/Code/Mantid/Framework/PythonInterface/inc/MantidPythonInterface/kernel/PythonObjectInstantiator.h
+++ b/Code/Mantid/Framework/PythonInterface/inc/MantidPythonInterface/kernel/PythonObjectInstantiator.h
@@ -27,31 +27,44 @@
 // Includes
 //-----------------------------------------------------------------------------
 #include "MantidKernel/Instantiator.h"
-#include "MantidAPI/IAlgorithm.h"
 #include "MantidPythonInterface/kernel/Environment/Threading.h"
 
-#include <boost/python/object.hpp>
 #include <boost/python/extract.hpp>
+#include <boost/python/object.hpp>
+// older versions of boost::python seem to require this last, after the object include
+#include <boost/python/converter/shared_ptr_deleter.hpp>
 
 namespace Mantid
 {
   namespace PythonInterface
   {
-    ///@cond
     /**
-     * A custom deleter to be used with shared_ptr objects that wrap objects
-     * instantiated in Python
+     * Special shared_ptr::deleter object that locks the GIL while deleting
+     * the underlying Python object
      */
-    template<typename T>
-    struct NoDelete
+    struct GILSharedPtrDeleter
     {
-    public:
-      void operator()(T const *) // No-op as ptr was not created with new
-      {}
+      GILSharedPtrDeleter(const boost::python::converter::shared_ptr_deleter & deleter)
+        : m_deleter(boost::python::converter::shared_ptr_deleter(deleter.owner))
+      {
+      }
+      /**
+       * Called when the shared_ptr reference count is zero
+       * @param data A pointer to the data to be deleted
+       */
+      void operator()(void const* data)
+      {
+        Environment::GlobalInterpreterLock gil;
+        m_deleter(data);
+      }
+      /// Main deleter object
+      boost::python::converter::shared_ptr_deleter m_deleter;
     };
-    ///@endcond
-
 
+    /**
+     * @tparam Base A pointer to the C++ type that is stored in within the created
+     *              python object
+     */
     template<typename Base>
     class PythonObjectInstantiator : public Kernel::AbstractInstantiator<Base>
     {
@@ -78,43 +91,35 @@ namespace Mantid
     template<typename Base>
     boost::shared_ptr<Base> PythonObjectInstantiator<Base>::createInstance() const
     {
-      // A custom deleter is required since calling delete is not what we want
-      return boost::shared_ptr<Base>(createUnwrappedInstance());
+      using namespace boost::python;
+      Environment::GlobalInterpreterLock gil;
+      
+      object instance = m_classObject();
+      // The instantiator assumes that the exported type uses a HeldType=boost::shared_ptr<Adapter>,
+      // where Adapter inherits from Base,
+      // see http://www.boost.org/doc/libs/1_42_0/libs/python/doc/v2/class.html#class_-spec.
+      // The advantage is that the memory management is very simple as it is all handled within the
+      // boost layer.
+
+      // Swap the deleter for one that acquires the GIL before actually deallocating the
+      // Python object or we get a segfault when deleting the objects on later
+      // versions of Python 2.7
+      auto instancePtr = extract<boost::shared_ptr<Base>>(instance)();
+      auto * deleter = boost::get_deleter<converter::shared_ptr_deleter, Base>(instancePtr);
+      instancePtr.reset(instancePtr.get(), GILSharedPtrDeleter(*deleter));
+      return instancePtr;
     }
 
     /**
-     * Creates an instance of the object as raw ptr to the Base type
-     * @returns A raw ptr to Base.
+     * @throws std::runtime_error as we're unable to extract a non-shared ptr from the wrapped object
      */
     template<typename Base>
     Base * PythonObjectInstantiator<Base>::createUnwrappedInstance() const
     {
-      using namespace boost::python;
-      Environment::GlobalInterpreterLock gil;
-
-      PyObject *newObj = PyObject_CallObject(m_classObject.ptr(), NULL); // No args
-      // borrowed: Do not decrement reference count on destruction
-      // we are passing out a new reference for something else to manage
-      object wrap(handle<>(borrowed(newObj)));
-      try
-      {
-        // In Python the actual object type is different to that of the main exported
-        // type. This is required so that Python we can take over lifetime management of
-        // the object when we create it here
-        // See http://wiki.python.org/moin/boost.python/HowTo#ownership_of_C.2B-.2B-_object_extended_in_Python
-        boost::shared_ptr<Base> newObj = extract<boost::shared_ptr<Base>>(object(wrap));
-        Base *barePtr = newObj.get();
-        newObj.reset(); // We take ownership
-        return barePtr;
-      }
-      catch(boost::python::error_already_set&)
-      {
-        throw std::runtime_error("PythonObjectInstantiator::createUnwrapped - Could not extract boost::shared_ptr<> to base type. "
-                                 "Please make sure the HeldType in the Python wrapper is boost::shared_ptr<Base>.");
-      }
+      throw std::runtime_error("Unable to create unwrapped instance of Python object");
     }
 
   }
 }
 
-#endif /* MANTID_PythonInterface_PYTHONALGORITHMINSTANTIATOR_H_ */
+#endif /* MANTID_PYTHONINTERFACE_PYTHONALGORITHMINSTANTIATOR_H_ */
diff --git a/Code/Mantid/Framework/PythonInterface/mantid/api/CMakeLists.txt b/Code/Mantid/Framework/PythonInterface/mantid/api/CMakeLists.txt
index afd9afded103b19244e929e1bc299e30cdeb5e63..1ec1239798419506c1106abcc2a692932a544ebd 100644
--- a/Code/Mantid/Framework/PythonInterface/mantid/api/CMakeLists.txt
+++ b/Code/Mantid/Framework/PythonInterface/mantid/api/CMakeLists.txt
@@ -42,6 +42,7 @@ set ( EXPORT_FILES
   src/Exports/IEventWorkspace.cpp
   src/Exports/IEventWorkspaceProperty.cpp
   src/Exports/IPeaksWorkspace.cpp
+  src/Exports/IPeaksWorkspaceProperty.cpp
   src/Exports/BinaryOperations.cpp
   src/Exports/WorkspaceGroup.cpp
   src/Exports/WorkspaceGroupProperty.cpp
diff --git a/Code/Mantid/Framework/PythonInterface/mantid/api/src/Exports/IAlgorithm.cpp b/Code/Mantid/Framework/PythonInterface/mantid/api/src/Exports/IAlgorithm.cpp
index 0344859c63e1f4ceab3fcbc790fe5ca96e58ec32..7dd6d4ba2b73cc93bcdf791db1401a95f7b032ea 100644
--- a/Code/Mantid/Framework/PythonInterface/mantid/api/src/Exports/IAlgorithm.cpp
+++ b/Code/Mantid/Framework/PythonInterface/mantid/api/src/Exports/IAlgorithm.cpp
@@ -167,7 +167,7 @@ namespace
       if (!prop->isValid().empty())
         buffer << ":req";
       buffer << ") *" << prop->type() << "* ";
-      std::set<std::string> allowed = prop->allowedValues();
+      std::vector<std::string> allowed = prop->allowedValues();
       if (!prop->documentation().empty() || !allowed.empty())
       {
         buffer << "      " << prop->documentation();
diff --git a/Code/Mantid/Framework/PythonInterface/mantid/api/src/Exports/IPeaksWorkspaceProperty.cpp b/Code/Mantid/Framework/PythonInterface/mantid/api/src/Exports/IPeaksWorkspaceProperty.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..f98cc9dec625582b0b3f9fbd8271b26c113cd8ae
--- /dev/null
+++ b/Code/Mantid/Framework/PythonInterface/mantid/api/src/Exports/IPeaksWorkspaceProperty.cpp
@@ -0,0 +1,9 @@
+#include "MantidPythonInterface/api/WorkspacePropertyExporter.h"
+#include "MantidAPI/IPeaksWorkspace.h"
+
+void export_IPeaksWorkspaceProperty()
+{
+  using Mantid::API::IPeaksWorkspace;
+  using Mantid::PythonInterface::WorkspacePropertyExporter;
+  WorkspacePropertyExporter<IPeaksWorkspace>::define("IPeaksWorkspaceProperty");
+}
diff --git a/Code/Mantid/Framework/PythonInterface/mantid/api/src/FitFunctions/IFunction1DAdapter.cpp b/Code/Mantid/Framework/PythonInterface/mantid/api/src/FitFunctions/IFunction1DAdapter.cpp
index 4a7ff3b9e7c3949bb599769176366f4af9123cd6..f5b4ae3b422cb17a4824aaf34eb95b7056103ca0 100644
--- a/Code/Mantid/Framework/PythonInterface/mantid/api/src/FitFunctions/IFunction1DAdapter.cpp
+++ b/Code/Mantid/Framework/PythonInterface/mantid/api/src/FitFunctions/IFunction1DAdapter.cpp
@@ -53,7 +53,7 @@ namespace Mantid
       Py_DECREF(xvals);
       if(PyErr_Occurred())
       {
-        Py_DECREF(result);
+        Py_XDECREF(result);
         Environment::throwRuntimeError(true);
       }
 
diff --git a/Code/Mantid/Framework/PythonInterface/mantid/geometry/src/Exports/OrientedLattice.cpp b/Code/Mantid/Framework/PythonInterface/mantid/geometry/src/Exports/OrientedLattice.cpp
index 69b3b3c2e5fe589e8314f6afa735d056ac64cf5f..6204d5f4c8ec05ad0d65395f67605c0bf7f43930 100644
--- a/Code/Mantid/Framework/PythonInterface/mantid/geometry/src/Exports/OrientedLattice.cpp
+++ b/Code/Mantid/Framework/PythonInterface/mantid/geometry/src/Exports/OrientedLattice.cpp
@@ -16,24 +16,34 @@ namespace //<unnamed>
   using namespace Mantid::PythonInterface;
 
   /// Set the U vector via a numpy array
-  void setU(OrientedLattice & self, object data)
+  void setU(OrientedLattice & self, const object& data)
   {
     self.setU(Converters::PyObjectToMatrix(data)());
   }
 
   /// Set the U vector via a numpy array
-  void setUB(OrientedLattice & self, object data)
+  void setUB(OrientedLattice & self, const object& data)
   {
     self.setUB(Converters::PyObjectToMatrix(data)());
   }
 
   /// Set the U matrix from 2 Python objects representing a V3D type. This can be a V3D object, a list
   /// or a numpy array. If the arrays are used they must be of length 3
-  void setUFromVectors(OrientedLattice & self, object vec1, object vec2)
+  void setUFromVectors(OrientedLattice & self, const object& vec1, const object& vec2)
   {
     self.setUFromVectors(Converters::PyObjectToV3D(vec1)(), Converters::PyObjectToV3D(vec2)());
   }
 
+  Mantid::Kernel::V3D qFromHKL(OrientedLattice & self, const object& vec)
+  {
+    return self.qFromHKL(Converters::PyObjectToV3D(vec)());
+  }
+
+  Mantid::Kernel::V3D hklFromQ(OrientedLattice & self, const object& vec)
+  {
+    return self.hklFromQ(Converters::PyObjectToV3D(vec)());
+  }
+
 }
 
 void export_OrientedLattice()
@@ -41,20 +51,18 @@ void export_OrientedLattice()
   /// return_value_policy for read-only numpy array
   typedef return_value_policy<Policies::MatrixToNumpy<Converters::WrapReadOnly> > return_readonly_numpy;
 
-  class_<OrientedLattice, bases<UnitCell> >("OrientedLattice", init< >())
-    .def( init< OrientedLattice const & >(( arg("other") )) )
-    .def( init< double, double, double >(( arg("_a"), arg("_b"), arg("_c") )) )
-    .def( init< double, double, double, double, double, double,
-                optional< int > >(( arg("_a"), arg("_b"), arg("_c"), arg("_alpha"), arg("_beta"), arg("_gamma"), arg("Unit")=(int)(angDegrees) )) )
-    .def( init<UnitCell>( arg("uc") ) )
-    .def( "getuVector", (&OrientedLattice::getuVector))
-    .def( "getvVector", (&OrientedLattice::getvVector))
-    .def( "getU", &OrientedLattice::getU, return_readonly_numpy() )
-    .def( "setU", &setU )
-    .def( "getUB",&OrientedLattice::getUB, return_readonly_numpy() )
-    .def( "setUB",&setUB )
-    .def( "setUFromVectors", &setUFromVectors)
-
-    ;
+  class_<OrientedLattice, bases<UnitCell> >("OrientedLattice", init<>())
+      .def(init<OrientedLattice const &>((arg("other"))))
+      .def(init<double, double, double>((arg("_a"), arg("_b"), arg("_c"))))
+      .def(init<double, double, double, double, double, double, optional<int> >((arg("_a"), arg("_b"), arg("_c"), arg("_alpha"), arg("_beta"), arg("_gamma"), arg("Unit") =
+              (int) (angDegrees))))
+      .def(init<UnitCell>(arg("uc"))).def("getuVector",(&OrientedLattice::getuVector))
+      .def("getvVector", (&OrientedLattice::getvVector))
+      .def("getU",&OrientedLattice::getU, return_readonly_numpy()).def("setU", &setU).def("getUB",&OrientedLattice::getUB, return_readonly_numpy())
+      .def("setUB", &setUB)
+      .def("setUFromVectors",&setUFromVectors)
+      .def("qFromHKL", &qFromHKL, "Q vector from HKL vector")
+      .def("hklFromQ", &hklFromQ, "HKL value from Q vector")
+      ;
 }
 
diff --git a/Code/Mantid/Framework/PythonInterface/mantid/kernel/src/Exports/V3D.cpp b/Code/Mantid/Framework/PythonInterface/mantid/kernel/src/Exports/V3D.cpp
index 6d2bfbd30a54467be4549153a3826fab96cb8cae..88ff3bbe9f0855eac71bef86cd9813c619eae4c7 100644
--- a/Code/Mantid/Framework/PythonInterface/mantid/kernel/src/Exports/V3D.cpp
+++ b/Code/Mantid/Framework/PythonInterface/mantid/kernel/src/Exports/V3D.cpp
@@ -6,6 +6,22 @@
 using namespace boost::python;
 using Mantid::Kernel::V3D;
 
+namespace
+{
+
+  /**
+   * Helper forwarding method for directionAngles to allow default argument values.
+   * @param self
+   * @return
+   */
+  V3D directionAnglesDefault(V3D & self)
+  {
+    return self.directionAngles();
+  }
+
+}
+
+
 void export_V3D()
 {
   //V3D class
@@ -41,5 +57,7 @@ void export_V3D()
     .def(self == self)
     .def(self != self) // must define != as Python's default is to compare object address
     .def(self_ns::str(self))
+    .def("directionAngles", &V3D::directionAngles, "Calculate direction angles from direction cosines")
+    .def("directionAngles", &directionAnglesDefault, "Calculate direction angles from direction cosines")
     ;
 }
diff --git a/Code/Mantid/Framework/PythonInterface/plugins/algorithms/CreateLeBailFitInput.py b/Code/Mantid/Framework/PythonInterface/plugins/algorithms/CreateLeBailFitInput.py
index fb50454c149df5125d64354afcc433372e857d33..da5d0068f2f72f293ee7b66c13ecf9824df7faaf 100644
--- a/Code/Mantid/Framework/PythonInterface/plugins/algorithms/CreateLeBailFitInput.py
+++ b/Code/Mantid/Framework/PythonInterface/plugins/algorithms/CreateLeBailFitInput.py
@@ -4,6 +4,7 @@
 import mantid.simpleapi as api
 from mantid.api import *
 from mantid.kernel import *
+from mantid.api import AnalysisDataService
 
 _OUTPUTLEVEL = "NOOUTPUT"
 
@@ -63,8 +64,7 @@ class CreateLeBailFitInput(PythonAlgorithm):
         paramWS = self.createPeakParameterWorkspace(irffilename)
         self.setProperty("InstrumentParameterWorkspace", paramWS)
 
-        hklWS = WorkspaceFactory.createTable()
-        self.setProperty("BraggPeakParameterWorkspace", hklWS)
+        # hklWS = WorkspaceFactory.createTable()
 
         # 2. Get Other Properties
         # instrument = self.getPropertyValue("Instrument")
@@ -79,12 +79,13 @@ class CreateLeBailFitInput(PythonAlgorithm):
                 raise NotImplementedError("MaxHKL must have 3 integers")
             hklws = self.generateBraggReflections(hklmax)
         else: 
-            hklws = self.importFullProfHKLFile(reflectionfilename)
+            hklwsname = self.getProperty("BraggPeakParameterWorkspace").value
+            hklws = self.importFullProfHKLFile(reflectionfilename, hklwsname)
         self.setProperty("BraggPeakParameterWorkspace", hklws)
 
         return
 
-    def importFullProfHKLFile(self, hklfilename):
+    def importFullProfHKLFile(self, hklfilename, hklwsname):
         """ Import Fullprof's .hkl file
         """
         import math
@@ -93,17 +94,34 @@ class CreateLeBailFitInput(PythonAlgorithm):
         rand = random.randint(1, 100000)
         dummywsname = "Foo%d" % (rand)
         hklwsname = self.getPropertyValue("BraggPeakParameterWorkspace")
-        print hklwsname
-        tempX = api.LoadFullprofFile(
-                Filename=hklfilename, 
-                # PeakParameterWorkspace = hklwsname,
-                PeakParameterWorkspace = "TempXXX",
+
+        # print hklwsname
+        # tempX = api.LoadFullprofFile(
+        #         Filename=hklfilename,
+        #         PeakParameterWorkspace = "TempXXX",
+        #         OutputWorkspace = dummywsname)
+
+        # hklws2 = AnalysisDataService.retrieve("TempXXX")
+        # print "HKL WS 2 = ", hklws2
+
+        # hklws = tempX[0]
+        # dummyws = tempX[1]
+
+        # print "TempXXX: ", hklws
+
+        # api.DeleteWorkspace(Workspace=dummyws)
+        # api.DeleteWorkspace(Workspace="TempXXX")
+
+        api.LoadFullprofFile( 
+                Filename=hklfilename,
+                PeakParameterWorkspace = hklwsname,
                 OutputWorkspace = dummywsname)
-    
-        hklws = tempX[0]
-        dummyws = tempX[1]
+        
+        hklws = AnalysisDataService.retrieve(hklwsname)
+        if hklws is None:
+            raise NotImplementedError("Unable to retrieve LoadFullprofFile's output TempXXX from analysis data service.")
 
-        api.DeleteWorkspace(Workspace=dummyws)
+        api.DeleteWorkspace(Workspace=dummywsname)
 
         return hklws
 
diff --git a/Code/Mantid/Framework/PythonInterface/plugins/algorithms/EnginXCalibrateFull.py b/Code/Mantid/Framework/PythonInterface/plugins/algorithms/EnginXCalibrateFull.py
index c20df3a4d1c84beadaac33c5408373d0b3a02e72..3f3c15610fa4a9327f03e1d21ec593b3f56ba35d 100644
--- a/Code/Mantid/Framework/PythonInterface/plugins/algorithms/EnginXCalibrateFull.py
+++ b/Code/Mantid/Framework/PythonInterface/plugins/algorithms/EnginXCalibrateFull.py
@@ -69,9 +69,10 @@ class EnginXCalibrateFull(PythonAlgorithm):
 		rebinAlg.execute()
 		result = rebinAlg.getProperty('OutputWorkspace').value
 
-		convertAlg = self.createChildAlgorithm('ConvertToDistribution')
-		convertAlg.setProperty('Workspace', result)
-		convertAlg.execute()
+                if result.isDistribution()==False:
+			convertAlg = self.createChildAlgorithm('ConvertToDistribution')
+			convertAlg.setProperty('Workspace', result)
+			convertAlg.execute()
 
 		return result
 
diff --git a/Code/Mantid/Framework/PythonInterface/plugins/algorithms/SNSPowderReduction.py b/Code/Mantid/Framework/PythonInterface/plugins/algorithms/SNSPowderReduction.py
index 24d1021352186835b8d1573dce93ff7aee1cde28..50152c18b0d0a30fa32cb5d4b60058358ff9a4f6 100644
--- a/Code/Mantid/Framework/PythonInterface/plugins/algorithms/SNSPowderReduction.py
+++ b/Code/Mantid/Framework/PythonInterface/plugins/algorithms/SNSPowderReduction.py
@@ -95,6 +95,8 @@ class SNSPowderReduction(DataProcessorAlgorithm):
         self.declareProperty("LowResolutionSpectraOffset", -1,
                              "If larger and equal to 0, then process low resolution TOF and offset is the spectra number. Otherwise, ignored.")
 
+        self.declareProperty("NormalizeByCurrent", True, "Normalize by current")
+
         return
 
 
@@ -152,6 +154,8 @@ class SNSPowderReduction(DataProcessorAlgorithm):
 
         self._splitinfotablews = self.getProperty("SplitInformationWorkspace").value
 
+        self._normalisebycurrent = self.getProperty("NormalizeByCurrent").value
+
         # Process data
         workspacelist = [] # all data workspaces that will be converted to d-spacing in the end
         samwksplist = []
@@ -299,9 +303,10 @@ class SNSPowderReduction(DataProcessorAlgorithm):
                     name = "_".join(str(vanRun).split("_")[:-1])
                     vanRun = api.RenameWorkspace(InputWorkspace=vanRun, OutputWorkspace=name)
                     try:
-                        vanRun = api.NormaliseByCurrent(InputWorkspace=vanRun, 
-                                                        OutputWorkspace=vanRun)
-                        vanRun.getRun()['gsas_monitor'] = 1
+                        if self._normalisebycurrent is True:
+                            vanRun = api.NormaliseByCurrent(InputWorkspace=vanRun, 
+                                                            OutputWorkspace=vanRun)
+                            vanRun.getRun()['gsas_monitor'] = 1
                     except Exception, e:
                         self.log().warning(str(e))
 
@@ -311,9 +316,10 @@ class SNSPowderReduction(DataProcessorAlgorithm):
                     if vbackRun > 0:
                         vbackRun = self._loadData(vbackRun, SUFFIX, vanFilterWall, outname="vbackRun")
                         try:
-                            vbackRun = api.NormaliseByCurrent(InputWorkspace=vbackRun, 
-                                                              OutputWorkspace=vbackRun)
-                            vbackRun.getRun()['gsas_monitor'] = 1
+                            if self._normalisebycurrent is True:
+                                vbackRun = api.NormaliseByCurrent(InputWorkspace=vbackRun, 
+                                                                  OutputWorkspace=vbackRun)
+                                vbackRun.getRun()['gsas_monitor'] = 1
                         except Exception, e:
                             self.log().warning(str(e))
 
@@ -686,9 +692,10 @@ class SNSPowderReduction(DataProcessorAlgorithm):
                     OutputWorkspace=wksplist[itemp], Tolerance=COMPRESS_TOL_TOF) # 100ns
 
             try:
-                wksplist[itemp] = api.NormaliseByCurrent(InputWorkspace=wksplist[itemp], 
-                                                         OutputWorkspace=wksplist[itemp])
-                wksplist[itemp].getRun()['gsas_monitor'] = 1
+                if self._normalisebycurrent is True:
+                    wksplist[itemp] = api.NormaliseByCurrent(InputWorkspace=wksplist[itemp], 
+                                                             OutputWorkspace=wksplist[itemp])
+                    wksplist[itemp].getRun()['gsas_monitor'] = 1
             except Exception, e:
                 self.log().warning(str(e))
 
diff --git a/Code/Mantid/Framework/PythonInterface/plugins/algorithms/SortByQVectors.py b/Code/Mantid/Framework/PythonInterface/plugins/algorithms/SortByQVectors.py
index 491d91ce171abba24885ee9b5a1a0c16deb642a9..0bfa010d315415c56541a248c2256b2e6b20ebeb 100644
--- a/Code/Mantid/Framework/PythonInterface/plugins/algorithms/SortByQVectors.py
+++ b/Code/Mantid/Framework/PythonInterface/plugins/algorithms/SortByQVectors.py
@@ -73,7 +73,7 @@ class SortByQVectors(PythonAlgorithm):
             loopIndex = 0
             wsOut = mtd[wsOutput]
             for norm, spec in sortStat:
-                wsOut.getAxis(1).setValue(loopIndex, norm)
+                wsOut.getSpectrum(loopIndex).setSpectrumNo(int(norm*1000))
                 loopIndex = loopIndex + 1
             if len(yUnit) > 0:
                 wsOut.getAxis(1).setUnit(yUnit)
diff --git a/Code/Mantid/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/EQSANSDirectBeamTransmission.py b/Code/Mantid/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/EQSANSDirectBeamTransmission.py
index 424e7a883dbd66aaf24c4546750cd646a4c79c4a..c0485393154573ba327de2a0df23710f10ab8058 100644
--- a/Code/Mantid/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/EQSANSDirectBeamTransmission.py
+++ b/Code/Mantid/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/EQSANSDirectBeamTransmission.py
@@ -71,6 +71,9 @@ class EQSANSDirectBeamTransmission(PythonAlgorithm):
             if raw_ws is not None:
                 self.setPropertyValue("RawTransmissionWorkspace", raw_name)
                 self.setProperty("RawTransmissionWorkspace", raw_ws)
+            
+            # Save the transmission to disk
+            self._save_transmission(trans_ws, raw_ws)
         else:
             ws = self._with_frame_skipping(workspace)
             self.setProperty("OutputWorkspace", ws)
@@ -229,8 +232,53 @@ class EQSANSDirectBeamTransmission(PythonAlgorithm):
             self.setPropertyValue("RawTransmissionWorkspace", raw_ws_name)
             self.setProperty("RawTransmissionWorkspace", raw_ws)
             
+            # Save the transmission to disk
+            self._save_transmission(trans_ws, raw_ws)
+            
         # 2- Apply correction (Note: Apply2DTransCorr)
         #Apply angle-dependent transmission correction using the zero-angle transmission
         return TransmissionUtils.apply_transmission(self, workspace, trans_ws)
 
+    def _save_transmission(self, trans_ws, raw_ws):
+        """
+            Save the transmission data and fit to disk.
+            @param trans_ws: transmission workspace
+            @param raw_ws: transmission fit workspace
+        """
+        property_manager_name = self.getProperty("ReductionProperties").value
+        property_manager = PropertyManagerDataService.retrieve(property_manager_name)
+
+        output_ws_name = self.getPropertyValue('OutputWorkspace')
+        if property_manager.existsProperty("OutputDirectory"):
+            output_dir = property_manager.getProperty("OutputDirectory").value
+            if os.path.isdir(output_dir):
+                if raw_ws is not None:
+                    filename = os.path.join(output_dir, output_ws_name+'_transmission.txt')
+                    alg = AlgorithmManager.create("SaveAscii")
+                    alg.initialize()
+                    alg.setChild(True)
+                    alg.setProperty("Filename", filename)
+                    alg.setProperty("InputWorkspace", raw_ws)
+                    alg.setProperty("Separator", "Tab")
+                    alg.setProperty("CommentIndicator", "# ")
+                    alg.setProperty("WriteSpectrumID", False)
+                    alg.execute()
+
+                if trans_ws is not None:
+                    filename = os.path.join(output_dir, output_ws_name+'_transmission_fit.txt')
+                    alg = AlgorithmManager.create("SaveAscii")
+                    alg.initialize()
+                    alg.setChild(True)
+                    alg.setProperty("Filename", filename)
+                    alg.setProperty("InputWorkspace", trans_ws)
+                    alg.setProperty("Separator", "Tab")
+                    alg.setProperty("CommentIndicator", "# ")
+                    alg.setProperty("WriteSpectrumID", False)
+                    alg.execute()
+            else:
+                msg = "Output directory doesn't exist: %s\n" % output_dir
+                Logger(__file__).error(msg)
+        else:
+            Logger(__file__).error("Could not find output directory")
+
 AlgorithmFactory.subscribe(EQSANSDirectBeamTransmission)
diff --git a/Code/Mantid/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/HFIRSANSReduction.py b/Code/Mantid/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/HFIRSANSReduction.py
index 9f0e409cd7bed05d5954f374c1334e7d6d8e7b1e..0a573cbbe89189b79161e74c95775cf23fb6dbcf 100644
--- a/Code/Mantid/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/HFIRSANSReduction.py
+++ b/Code/Mantid/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/HFIRSANSReduction.py
@@ -403,8 +403,17 @@ class HFIRSANSReduction(PythonAlgorithm):
                         proc = open(process_file, 'r')
                         proc_xml = proc.read()
                     elif len(process_file)>0:
-                        Logger("HFIRSANSReduction").error("Could not read %s\n" % process_file)               
-                
+                        Logger("HFIRSANSReduction").error("Could not read %s\n" % process_file)
+                if property_manager.existsProperty("SetupAlgorithm"):
+                        setup_info = property_manager.getProperty("SetupAlgorithm").value
+                        proc_xml += "\n<Reduction>\n"
+                        # The instrument name refers to the UI, which is named BIOSANS for all HFIR SANS
+                        proc_xml += "  <instrument_name>BIOSANS</instrument_name>\n"
+                        proc_xml += "  <SetupInfo>%s</SetupInfo>\n" % setup_info
+                        filename = self.getProperty("Filename").value
+                        proc_xml += "  <Filename>%s</Filename>\n" % filename
+                        proc_xml += "</Reduction>\n"
+
                 filename = os.path.join(output_dir, iq_output+'.txt')
                 
                 alg = AlgorithmManager.create("SaveAscii")
diff --git a/Code/Mantid/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/IndirectILLReduction.py b/Code/Mantid/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/IndirectILLReduction.py
index f0def09da83ec9bfcdf9187a41a9df58a4d783a7..f1657980e43a1ff01c9e32c6407338558cde18ea 100644
--- a/Code/Mantid/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/IndirectILLReduction.py
+++ b/Code/Mantid/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/IndirectILLReduction.py
@@ -1,7 +1,3 @@
-"""*WIKI* 
-A workflow algorithm to perform a data reduction for Indirect ILL instruments. Note that currently only IN16B is supported. 
-*WIKI*"""
-
 from mantid.simpleapi import *
 from mantid.kernel import StringListValidator, Direction
 from mantid.api import DataProcessorAlgorithm, PropertyMode, AlgorithmFactory, FileProperty, FileAction, MatrixWorkspaceProperty
@@ -14,7 +10,7 @@ import os.path
 class IndirectILLReduction(DataProcessorAlgorithm):
 
     def category(self):
-        return "Workflow\\MIDAS;Inelastic;PythonAlgorithms" 
+        return "Workflow\\MIDAS;Inelastic;PythonAlgorithms"
 
     def PyInit(self):
         #input options
@@ -197,7 +193,6 @@ class IndirectILLReduction(DataProcessorAlgorithm):
         right_mon_ws = right_ws + '_mon'
         CropWorkspace(InputWorkspace=grouped_ws, OutputWorkspace=right_ws, Xmin=x[mid_point])
         CropWorkspace(InputWorkspace=monitor_ws, OutputWorkspace=right_mon_ws, Xmin=x[mid_point])
-        x = mtd[right_ws].readX(0)
 
         self._calculate_energy(right_mon_ws, right_ws, self._red_right_workspace)
         xr = mtd[self._red_right_workspace].readX(0)
diff --git a/Code/Mantid/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/SANSReduction.py b/Code/Mantid/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/SANSReduction.py
index b32bfb8a77a5cddde23cc1e4b9e5d871de614d72..afdb25da3b4182aef56cba2e022571907225e30d 100644
--- a/Code/Mantid/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/SANSReduction.py
+++ b/Code/Mantid/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/SANSReduction.py
@@ -400,8 +400,20 @@ class SANSReduction(PythonAlgorithm):
                         proc = open(process_file, 'r')
                         proc_xml = proc.read()
                     elif len(process_file)>0 and process_file.lower().find("none") != 0:
-                        Logger("SANSReduction").error("Could not read process info file %s\n" % process_file)               
-                
+                        Logger("SANSReduction").error("Could not read process info file %s\n" % process_file)
+                if property_manager.existsProperty("SetupAlgorithm"):
+                        if property_manager.existsProperty('InstrumentName'):
+                            instrument_name = property_manager.getProperty('InstrumentName').value
+                        else:
+                            instrument_name = 'EQSANS'
+                        setup_info = property_manager.getProperty("SetupAlgorithm").value
+                        proc_xml += "\n<Reduction>\n"
+                        proc_xml += "  <instrument_name>%s</instrument_name>\n" % instrument_name
+                        proc_xml += "  <SetupInfo>%s</SetupInfo>\n" % setup_info
+                        filename = self.getProperty("Filename").value
+                        proc_xml += "  <Filename>%s</Filename>\n" % filename
+                        proc_xml += "</Reduction>\n"
+                        
                 filename = os.path.join(output_dir, iq_output+'.txt')
                 
                 alg = AlgorithmManager.create("SaveAscii")
diff --git a/Code/Mantid/Framework/PythonInterface/plugins/functions/DSFinterp1DFit.py b/Code/Mantid/Framework/PythonInterface/plugins/functions/DSFinterp1DFit.py
index f7aa861c15dbf4702b5b947b417e9068ce4b087d..cb9c756c0c07c50a7882f53f3e33cd39a180e098 100644
--- a/Code/Mantid/Framework/PythonInterface/plugins/functions/DSFinterp1DFit.py
+++ b/Code/Mantid/Framework/PythonInterface/plugins/functions/DSFinterp1DFit.py
@@ -28,9 +28,6 @@ from mantid.simpleapi import mtd
 from mantid import logger
 import numpy
 from scipy.interpolate import interp1d
-from pdb import set_trace as tr
-
-#from pdb import set_trace as tr
 
 class DSFinterp1DFit(IFunction1D):
 
@@ -117,7 +114,7 @@ class DSFinterp1DFit(IFunction1D):
           raise IndexError(message)
       # check number of input workspaces and parameters is the same
       if len(self._ParameterValues) != len(self._InputWorkspaces):
-        message = 'Number of InputWorkspaces and ParameterValues should be the same. Found {0} and {1}, respectively'.format(len(self._ParameterValues), len(self._InputWorkspaces))
+        message = 'Number of InputWorkspaces and ParameterValues should be the same. Found {0} and {1}, respectively'.format(len(self._InputWorkspaces), len(self._ParameterValues))
         logger.error(message)
         raise ValueError(message)
       # check the regression type is valid
diff --git a/Code/Mantid/Framework/PythonInterface/test/python/mantid/api/PythonAlgorithmTraitsTest.py b/Code/Mantid/Framework/PythonInterface/test/python/mantid/api/PythonAlgorithmTraitsTest.py
index 9e349e538b0c0790e5fd79c7c5c1408729feb0c3..b30f74d9bfc5b21c148f5e24ab5ede0e8d8c3284 100644
--- a/Code/Mantid/Framework/PythonInterface/test/python/mantid/api/PythonAlgorithmTraitsTest.py
+++ b/Code/Mantid/Framework/PythonInterface/test/python/mantid/api/PythonAlgorithmTraitsTest.py
@@ -115,7 +115,12 @@ class PythonAlgorithmTest(unittest.TestCase):
     # --------------------------- Failure cases --------------------------------------------
     def test_isRunning_returning_non_bool_raises_error(self):
         alg = AlgorithmManager.createUnmanaged("TestPyAlgIsRunningReturnsNonBool")
-        self.assertRaises(RuntimeError, alg.isRunning)
+        # boost.python automatically downcasts to the most available type
+        # meaning that type(alg)=TestPyAlgIsRunningReturnsNonBool and not the interface
+        # so that any method lookup doesn't go through the base class automatically.
+        # Here we simulate how it would be called on C++ framework side
+        base_running_attr = getattr(IAlgorithm, "isRunning")
+        self.assertRaises(RuntimeError, base_running_attr, alg)
 
 if __name__ == '__main__':
     unittest.main()
diff --git a/Code/Mantid/Framework/PythonInterface/test/python/mantid/geometry/OrientedLatticeTest.py b/Code/Mantid/Framework/PythonInterface/test/python/mantid/geometry/OrientedLatticeTest.py
index 73a101edcc3e09d0c8c2d5c7b10be309a0c035a1..d3387d12f12f5409927df787ff941f8d38f9d5d0 100644
--- a/Code/Mantid/Framework/PythonInterface/test/python/mantid/geometry/OrientedLatticeTest.py
+++ b/Code/Mantid/Framework/PythonInterface/test/python/mantid/geometry/OrientedLatticeTest.py
@@ -36,7 +36,47 @@ class OrientedLatticeTest(unittest.TestCase):
         run_test([1,0,0],[0,1,0])
         # Set from numpy arrays
         run_test(np.array([1,0,0]),np.array([0,1,0]))
-
-
+        
+    def test_qFromHKL(self):
+        ol = OrientedLattice(1,1,1)
+        hkl = V3D(1,1,1)
+        qVec = ol.qFromHKL(hkl)
+        self.assertAlmostEqual(hkl.X() * 2 * np.pi, qVec.X(), 9)
+        self.assertAlmostEqual(hkl.Y() * 2 * np.pi, qVec.Y(), 9)
+        self.assertAlmostEqual(hkl.Z() * 2 * np.pi, qVec.Z(), 9)
+        
+        
+    def test_hklFromQ(self):
+        ol = OrientedLattice(1,1,1)
+        qVec = V3D(1,1,1)
+        hkl = ol.hklFromQ(qVec)
+        self.assertAlmostEqual(hkl.X() * 2 * np.pi, qVec.X(), 9)
+        self.assertAlmostEqual(hkl.Y() * 2 * np.pi, qVec.Y(), 9)
+        self.assertAlmostEqual(hkl.Z() * 2 * np.pi, qVec.Z(), 9)
+        
+    def test_qFromHLK_input_types(self):
+        '''
+        Test that you can provide input hkl values as different python types.
+        '''
+        ol = OrientedLattice(1,1,1)
+        
+        self.assertTrue(isinstance( ol.qFromHKL(V3D(1,1,1)), V3D), "Should work with V3D input")
+   
+        self.assertTrue(isinstance( ol.qFromHKL([1,1,1]), V3D), "Should work with python array input" )
+      
+        self.assertTrue(isinstance( ol.qFromHKL(np.array([1,1,1])), V3D), "Should work with numpy array input" )
+        
+    def test_hklFromQ_input_types(self):
+        '''
+        Test that you can provide input q values as different python types.
+        '''
+        ol = OrientedLattice(1,1,1)
+        
+        self.assertTrue(isinstance( ol.hklFromQ(V3D(1,1,1)), V3D), "Should work with V3D input")
+   
+        self.assertTrue(isinstance( ol.hklFromQ([1,1,1]), V3D), "Should work with python array input" )
+      
+        self.assertTrue(isinstance( ol.hklFromQ(np.array([1,1,1])), V3D), "Should work with numpy array input" )
+        
 if __name__ == '__main__':
     unittest.main()
\ No newline at end of file
diff --git a/Code/Mantid/Framework/PythonInterface/test/python/mantid/kernel/V3DTest.py b/Code/Mantid/Framework/PythonInterface/test/python/mantid/kernel/V3DTest.py
index 75f7c77fff6480991b521e1ecff0774221900dd4..312712e8fbc65b0149280d8d8a7e7fde7c4ab5c8 100644
--- a/Code/Mantid/Framework/PythonInterface/test/python/mantid/kernel/V3DTest.py
+++ b/Code/Mantid/Framework/PythonInterface/test/python/mantid/kernel/V3DTest.py
@@ -79,6 +79,24 @@ class V3DTest(unittest.TestCase):
         self.assertFalse(p1 != p2)
         p3 = V3D(1.0,-5.0,10.0)
         self.assertTrue(p1 != p3)
+        
+    def test_directionAngles_rads(self):
+        v = V3D(1, 1, 1)
+        inDegrees = False
+        angles = v.directionAngles(inDegrees)
+        self.assertAlmostEquals(math.acos(1.0/math.sqrt(3.0)), angles.X())
+        self.assertAlmostEquals(math.acos(1.0/math.sqrt(3.0)), angles.Y())
+        self.assertAlmostEquals(math.acos(1.0/math.sqrt(3.0)), angles.Z())
+        
+    def test_directionAngles(self):
+        v = V3D(1, 1, 1)
+        angles = v.directionAngles()
+        self.assertAlmostEquals(math.acos(1.0/math.sqrt(3.0)) * 180 / math.pi, angles.X())
+        self.assertAlmostEquals(math.acos(1.0/math.sqrt(3.0)) * 180 / math.pi, angles.Y())
+        self.assertAlmostEquals(math.acos(1.0/math.sqrt(3.0)) * 180 / math.pi, angles.Z())
+        
+        
+        
 
 if __name__ == '__main__':
     unittest.main()
diff --git a/Code/Mantid/Framework/PythonInterface/test/python/plugins/algorithms/CMakeLists.txt b/Code/Mantid/Framework/PythonInterface/test/python/plugins/algorithms/CMakeLists.txt
index 3a383b6a2f4a430aebf2c998ff2e485eae813afd..a49dab7bcbd502cb68c34b8b1b51a3a8cab1a7d6 100644
--- a/Code/Mantid/Framework/PythonInterface/test/python/plugins/algorithms/CMakeLists.txt
+++ b/Code/Mantid/Framework/PythonInterface/test/python/plugins/algorithms/CMakeLists.txt
@@ -27,6 +27,7 @@ set ( TEST_PY_FILES
   RetrieveRunInfoTest.py
   SANSWideAngleCorrectionTest.py
   SavePlot1DTest.py
+  SortByQVectorsTest.py
   SortDetectorsTest.py
   SortXAxisTest.py
   Stitch1DManyTest.py
diff --git a/Code/Mantid/Framework/PythonInterface/test/python/plugins/algorithms/SortByQVectorsTest.py b/Code/Mantid/Framework/PythonInterface/test/python/plugins/algorithms/SortByQVectorsTest.py
new file mode 100644
index 0000000000000000000000000000000000000000..935560c2969024b90d28472d0eea65351ca2f332
--- /dev/null
+++ b/Code/Mantid/Framework/PythonInterface/test/python/plugins/algorithms/SortByQVectorsTest.py
@@ -0,0 +1,20 @@
+import unittest,os
+import mantid
+
+
+class SortByQVectorsTest(unittest.TestCase):
+
+
+	def test_output(self):
+                ws = mantid.simpleapi.LoadSassena("outputSassena_1.4.1.h5", TimeUnit=1.0)
+		mantid.simpleapi.SortByQVectors('ws')
+		self.assertAlmostEqual(ws[0].getNumberHistograms(),5)
+		self.assertAlmostEqual(ws[0].dataY(0)[0],0.0)
+		self.assertAlmostEqual(ws[0].dataY(1)[0],0.00600600591861)
+		self.assertAlmostEqual(ws[0].dataY(2)[0],0.0120120118372)
+		self.assertAlmostEqual(ws[0].dataY(3)[0],0.0180180184543)
+		self.assertAlmostEqual(ws[0].dataY(4)[0],0.0240240236744)
+		mantid.api.AnalysisDataService.remove("ws")
+
+if __name__=="__main__":
+	unittest.main()
diff --git a/Code/Mantid/Framework/PythonInterface/test/python/plugins/functions/DSFinterp1DFitTest.py b/Code/Mantid/Framework/PythonInterface/test/python/plugins/functions/DSFinterp1DFitTest.py
index 3e06bdf02d93be97e13bad168763a1fa25ddd23f..7485f524476abf08e38c6831f4a42ba639743d63 100644
--- a/Code/Mantid/Framework/PythonInterface/test/python/plugins/functions/DSFinterp1DFitTest.py
+++ b/Code/Mantid/Framework/PythonInterface/test/python/plugins/functions/DSFinterp1DFitTest.py
@@ -1,9 +1,10 @@
 import unittest
 import numpy
-#from pdb import set_trace as tr
+
 from mantid.kernel import logger
 from mantid.simpleapi import CreateWorkspace, Fit, mtd, SaveNexus
 from mantid.api import AnalysisDataService
+import sys
 
 class DSFinterp1DTestTest(unittest.TestCase):
 
diff --git a/Code/Mantid/Framework/SINQ/CMakeLists.txt b/Code/Mantid/Framework/SINQ/CMakeLists.txt
index 2b7ff00a7a672c8a78d206f581a1d1774555c549..34ca043ba2286a9e4e35be03877a45c053f7dd14 100644
--- a/Code/Mantid/Framework/SINQ/CMakeLists.txt
+++ b/Code/Mantid/Framework/SINQ/CMakeLists.txt
@@ -3,16 +3,8 @@ set ( SRC_FILES
 	src/LoadFlexiNexus.cpp
 	src/MDHistoToWorkspace2D.cpp
 	src/PoldiAutoCorrelation5.cpp
+        src/PoldiCalculateSpectrum2D.cpp
 	src/PoldiFitPeaks1D.cpp
-        src/PoldiUtilities/PoldiAutoCorrelationCore.cpp
-        src/PoldiUtilities/PoldiBasicChopper.cpp
-        src/PoldiUtilities/PoldiChopperFactory.cpp
-        src/PoldiUtilities/PoldiDeadWireDecorator.cpp
-        src/PoldiUtilities/PoldiDetectorDecorator.cpp
-        src/PoldiUtilities/PoldiDetectorFactory.cpp
-        src/PoldiUtilities/PoldiHeliumDetector.cpp
-        src/PoldiUtilities/PoldiSourceSpectrum.cpp
-        src/PoldiUtilities/UncertainValue.cpp
 	src/PoldiLoadChopperSlits.cpp
 	src/PoldiLoadIPP.cpp
 	src/PoldiLoadLog.cpp
@@ -22,6 +14,8 @@ set ( SRC_FILES
 	src/PoldiRemoveDeadWires.cpp
 	src/PoldiTruncateData.cpp
 	src/PoldiUtilities/MillerIndices.cpp
+        src/PoldiUtilities/PeakFunctionIntegrator.cpp
+	src/PoldiUtilities/Poldi2DFunction.cpp
 	src/PoldiUtilities/PoldiAutoCorrelationCore.cpp
 	src/PoldiUtilities/PoldiBasicChopper.cpp
 	src/PoldiUtilities/PoldiChopperFactory.cpp
@@ -31,8 +25,12 @@ set ( SRC_FILES
 	src/PoldiUtilities/PoldiDetectorFactory.cpp
         src/PoldiUtilities/PoldiDGrid.cpp
 	src/PoldiUtilities/PoldiHeliumDetector.cpp
+        src/PoldiUtilities/PoldiInstrumentAdapter.cpp
 	src/PoldiUtilities/PoldiPeak.cpp
 	src/PoldiUtilities/PoldiPeakCollection.cpp
+        src/PoldiUtilities/PoldiSpectrumDomainFunction.cpp
+        src/PoldiUtilities/PoldiSourceSpectrum.cpp
+	src/PoldiUtilities/PoldiTimeTransformer.cpp
 	src/PoldiUtilities/UncertainValue.cpp
 	src/ProjectMD.cpp
 	src/SINQHMListener.cpp
@@ -46,19 +44,8 @@ set ( INC_FILES
 	inc/MantidSINQ/LoadFlexiNexus.h
 	inc/MantidSINQ/MDHistoToWorkspace2D.h
 	inc/MantidSINQ/PoldiAutoCorrelation5.h
+        inc/MantidSINQ/PoldiCalculateSpectrum2D.h
 	inc/MantidSINQ/PoldiFitPeaks1D.h
-        inc/MantidSINQ/PoldiUtilities/PoldiAbstractChopper.h
-        inc/MantidSINQ/PoldiUtilities/PoldiAbstractDetector.h
-        inc/MantidSINQ/PoldiAutoCorrelation5.h
-        inc/MantidSINQ/PoldiUtilities/PoldiAutoCorrelationCore.h
-        inc/MantidSINQ/PoldiUtilities/PoldiBasicChopper.h
-        inc/MantidSINQ/PoldiUtilities/PoldiChopperFactory.h
-        inc/MantidSINQ/PoldiUtilities/PoldiDeadWireDecorator.h
-        inc/MantidSINQ/PoldiUtilities/PoldiDetectorDecorator.h
-        inc/MantidSINQ/PoldiUtilities/PoldiDetectorFactory.h
-        inc/MantidSINQ/PoldiUtilities/PoldiHeliumDetector.h
-        inc/MantidSINQ/PoldiUtilities/PoldiSourceSpectrum.h
-        inc/MantidSINQ/PoldiUtilities/UncertainValue.h
 	inc/MantidSINQ/PoldiLoadChopperSlits.h
 	inc/MantidSINQ/PoldiLoadIPP.h
 	inc/MantidSINQ/PoldiLoadLog.h
@@ -69,6 +56,8 @@ set ( INC_FILES
 	inc/MantidSINQ/PoldiTruncateData.h
 	inc/MantidSINQ/PoldiUtilities/MillerIndices.h
 	inc/MantidSINQ/PoldiUtilities/MillerIndicesIO.h
+        inc/MantidSINQ/PoldiUtilities/PeakFunctionIntegrator.h
+	inc/MantidSINQ/PoldiUtilities/Poldi2DFunction.h
 	inc/MantidSINQ/PoldiUtilities/PoldiAbstractChopper.h
 	inc/MantidSINQ/PoldiUtilities/PoldiAbstractDetector.h
 	inc/MantidSINQ/PoldiUtilities/PoldiAutoCorrelationCore.h
@@ -80,9 +69,12 @@ set ( INC_FILES
 	inc/MantidSINQ/PoldiUtilities/PoldiDetectorFactory.h
         inc/MantidSINQ/PoldiUtilities/PoldiDGrid.h
 	inc/MantidSINQ/PoldiUtilities/PoldiHeliumDetector.h
+        inc/MantidSINQ/PoldiUtilities/PoldiInstrumentAdapter.h
 	inc/MantidSINQ/PoldiUtilities/PoldiMockInstrumentHelpers.h
 	inc/MantidSINQ/PoldiUtilities/PoldiPeak.h
 	inc/MantidSINQ/PoldiUtilities/PoldiPeakCollection.h
+        inc/MantidSINQ/PoldiUtilities/PoldiSpectrumDomainFunction.h
+	inc/MantidSINQ/PoldiUtilities/PoldiTimeTransformer.h
 	inc/MantidSINQ/PoldiUtilities/UncertainValue.h
 	inc/MantidSINQ/PoldiUtilities/UncertainValueIO.h
 	inc/MantidSINQ/ProjectMD.h
@@ -97,8 +89,11 @@ set ( TEST_FILES
 	MDHistoToWorkspace2DTest.h
 	MillerIndicesIOTest.h
 	MillerIndicesTest.h
+        PeakFunctionIntegratorTest.h
+	Poldi2DFunctionTest.h
 	PoldiAutoCorrelationCoreTest.h
 	PoldiBasicChopperTest.h
+        PoldiCalculateSpectrum2DTest.h
 	PoldiChopperFactoryTest.h
         PoldiConversionsTest.h
 	PoldiDeadWireDecoratorTest.h
@@ -107,10 +102,13 @@ set ( TEST_FILES
 	PoldiDetectorFactoryTest.h
 	PoldiDetectorTest.h
 	PoldiFitPeaks1DTest.h
+        PoldiInstrumentAdapterTest.h
         PoldiPeakCollectionTest.h
 	PoldiPeakSearchTest.h
 	PoldiPeakTest.h
         PoldiSourceSpectrumTest.h
+        PoldiSpectrumDomainFunctionTest.h
+	PoldiTimeTransformerTest.h
 	PoldiTruncateDataTest.h
 	ProjectMDTest.h
 	SliceMDHistoTest.h
diff --git a/Code/Mantid/Framework/SINQ/inc/MantidSINQ/PoldiAutoCorrelation5.h b/Code/Mantid/Framework/SINQ/inc/MantidSINQ/PoldiAutoCorrelation5.h
index 484385e256ad7d8987d8800947cba446ac2474d6..87cd373f02f190d4892f7af3aff2f9d6d159444f 100644
--- a/Code/Mantid/Framework/SINQ/inc/MantidSINQ/PoldiAutoCorrelation5.h
+++ b/Code/Mantid/Framework/SINQ/inc/MantidSINQ/PoldiAutoCorrelation5.h
@@ -12,6 +12,7 @@
 
 #include "MantidKernel/PhysicalConstants.h"
 #include "MantidSINQ/PoldiUtilities/PoldiAutoCorrelationCore.h"
+#include "MantidSINQ/PoldiUtilities/PoldiDeadWireDecorator.h"
 
 
 
@@ -76,15 +77,11 @@ public:
 	/// Algorithm's category for identification overriding a virtual method
     virtual const std::string category() const { return "SINQ\\Poldi"; }
 
-
-
 protected:
 	/// Overwrites Algorithm method
 	void exec();
 
-
-
-
+    void logConfigurationInformation(boost::shared_ptr<PoldiDeadWireDecorator> cleanDetector, PoldiAbstractChopper_sptr chopper);
 
 private:
 	/// Overwrites Algorithm method.
diff --git a/Code/Mantid/Framework/SINQ/inc/MantidSINQ/PoldiCalculateSpectrum2D.h b/Code/Mantid/Framework/SINQ/inc/MantidSINQ/PoldiCalculateSpectrum2D.h
new file mode 100644
index 0000000000000000000000000000000000000000..ac5a3f2869322d2d5164c7c6aab2ad8c65e90679
--- /dev/null
+++ b/Code/Mantid/Framework/SINQ/inc/MantidSINQ/PoldiCalculateSpectrum2D.h
@@ -0,0 +1,93 @@
+#ifndef MANTID_SINQ_POLDICALCULATESPECTRUM2D_H_
+#define MANTID_SINQ_POLDICALCULATESPECTRUM2D_H_
+
+#include "MantidKernel/System.h"
+#include "MantidSINQ/DllConfig.h"
+#include "MantidAPI/Algorithm.h"
+#include "MantidAPI/MultiDomainFunction.h"
+#include "MantidDataObjects/TableWorkspace.h"
+#include "MantidSINQ/PoldiUtilities/PoldiPeakCollection.h"
+#include "MantidSINQ/PoldiUtilities/PoldiTimeTransformer.h"
+#include "MantidSINQ/PoldiUtilities/Poldi2DFunction.h"
+
+
+namespace Mantid
+{
+namespace Poldi
+{
+
+/** PoldiCalculateSpectrum2D
+
+    An Algorithm to calculate a POLDI 2D-spectrum from a given table containing POLDI
+    peak data. A MatrixWorkspace containing a proper POLDI instrument definition is required
+    to determine output workspace dimensions etc.
+
+      @author Michael Wedel, Paul Scherrer Institut - SINQ
+      @date 16/05/2014
+
+      Copyright © 2014 PSI-MSS
+
+    This file is part of Mantid.
+
+    Mantid is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 3 of the License, or
+    (at your option) any later version.
+
+    Mantid is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+    File change history is stored at: <https://github.com/mantidproject/mantid>
+    Code Documentation is available at: <http://doxygen.mantidproject.org>
+  */
+
+class MANTID_SINQ_DLL PoldiCalculateSpectrum2D  : public API::Algorithm
+{
+public:
+    PoldiCalculateSpectrum2D();
+    virtual ~PoldiCalculateSpectrum2D();
+    
+    virtual const std::string name() const;
+    virtual int version() const;
+    virtual const std::string category() const;
+
+    virtual const std::string summary() const;
+
+protected:
+    PoldiPeakCollection_sptr getPeakCollection(const DataObjects::TableWorkspace_sptr &peakTable) const;
+    PoldiPeakCollection_sptr getIntegratedPeakCollection(const PoldiPeakCollection_sptr &rawPeakCollection) const;
+    PoldiPeakCollection_sptr getNormalizedPeakCollection(const PoldiPeakCollection_sptr &peakCollection) const;
+
+    boost::shared_ptr<Poldi2DFunction> getFunctionFromPeakCollection(const PoldiPeakCollection_sptr &peakCollection) const;
+
+    API::MatrixWorkspace_sptr calculateSpectrum(const PoldiPeakCollection_sptr &peakCollection, const API::MatrixWorkspace_sptr &matrixWorkspace);
+
+    void setTimeTransformerFromInstrument(const PoldiInstrumentAdapter_sptr &poldiInstrument);
+    void setTimeTransformer(const PoldiTimeTransformer_sptr &poldiTimeTransformer);
+
+    void setDeltaTFromWorkspace(const API::MatrixWorkspace_sptr &matrixWorkspace);
+    void setDeltaT(double newDeltaT);
+    bool isValidDeltaT(double deltaT) const;
+
+    void throwOnInsufficientState();
+
+
+    PoldiTimeTransformer_sptr m_timeTransformer;
+    double m_deltaT;
+
+private:
+    void init();
+    void exec();
+
+};
+
+
+} // namespace Poldi
+} // namespace Mantid
+
+#endif  /* MANTID_SINQ_POLDICALCULATESPECTRUM2D_H_ */
diff --git a/Code/Mantid/Framework/SINQ/inc/MantidSINQ/PoldiPeakSearch.h b/Code/Mantid/Framework/SINQ/inc/MantidSINQ/PoldiPeakSearch.h
index 98aba2536d61a3ae3fd5ece230980321cc0ee012..a8faeff25cd947ad6f99c864fc8cf97004c98cca 100644
--- a/Code/Mantid/Framework/SINQ/inc/MantidSINQ/PoldiPeakSearch.h
+++ b/Code/Mantid/Framework/SINQ/inc/MantidSINQ/PoldiPeakSearch.h
@@ -100,6 +100,7 @@ namespace Poldi
 
     MantidVec::const_iterator m_recursionAbsoluteBegin;
     MantidVec::const_iterator m_recursionAbsoluteEnd;
+    bool m_recursionBordersInitialized;
 
     PoldiPeakCollection_sptr m_peaks;
 
diff --git a/Code/Mantid/Framework/SINQ/inc/MantidSINQ/PoldiUtilities/MillerIndices.h b/Code/Mantid/Framework/SINQ/inc/MantidSINQ/PoldiUtilities/MillerIndices.h
index d3a34f91a74cdcc19237b4606e2af4bba1c6f3e1..440863048eada271dcd38ecb1d1654a93d0ec5b4 100644
--- a/Code/Mantid/Framework/SINQ/inc/MantidSINQ/PoldiUtilities/MillerIndices.h
+++ b/Code/Mantid/Framework/SINQ/inc/MantidSINQ/PoldiUtilities/MillerIndices.h
@@ -47,6 +47,7 @@ public:
     int l() const;
 
     int operator[](int index);
+    bool operator ==(MillerIndices &other) const;
 
     const std::vector<int>& asVector() const;
 
diff --git a/Code/Mantid/Framework/SINQ/inc/MantidSINQ/PoldiUtilities/PeakFunctionIntegrator.h b/Code/Mantid/Framework/SINQ/inc/MantidSINQ/PoldiUtilities/PeakFunctionIntegrator.h
new file mode 100644
index 0000000000000000000000000000000000000000..2617a3cf7909d2a7352ffcbc75d8628e3f5c398d
--- /dev/null
+++ b/Code/Mantid/Framework/SINQ/inc/MantidSINQ/PoldiUtilities/PeakFunctionIntegrator.h
@@ -0,0 +1,77 @@
+#ifndef PEAKFUNCTIONINTEGRATOR_H
+#define PEAKFUNCTIONINTEGRATOR_H
+
+#include "MantidSINQ/DllConfig.h"
+#include "MantidAPI/IPeakFunction.h"
+#include "gsl/gsl_integration.h"
+
+namespace Mantid {
+namespace Poldi {
+
+/** PeakFunctionIntegrator :
+ *
+  General integration of peaks (in the form of IPeakFunction) by wrapping the
+  corresponding GSL-functions. Integration with infinity limits is supported.
+
+    @author Michael Wedel, Paul Scherrer Institut - SINQ
+    @date 24/04/2014
+
+    Copyright © 2014 PSI-MSS
+
+  This file is part of Mantid.
+
+  Mantid is free software; you can redistribute it and/or modify
+  it under the terms of the GNU General Public License as published by
+  the Free Software Foundation; either version 3 of the License, or
+  (at your option) any later version.
+
+  Mantid is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  GNU General Public License for more details.
+
+  You should have received a copy of the GNU General Public License
+  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+  File change history is stored at: <https://github.com/mantidproject/mantid>
+  Code Documentation is available at: <http://doxygen.mantidproject.org>
+*/
+
+struct MANTID_SINQ_DLL IntegrationResult {
+    double result;
+    double error;
+    size_t intervals;
+
+    int errorCode;
+    bool success;
+};
+
+class MANTID_SINQ_DLL PeakFunctionIntegrator {
+public:
+    PeakFunctionIntegrator(double requiredRelativePrecision = 1e-8);
+    virtual ~PeakFunctionIntegrator();
+
+    void setRequiredRelativePrecision(double newPrecision);
+    double requiredRelativePrecision() const;
+
+    IntegrationResult integrateInfinity(API::IPeakFunction_const_sptr peakFunction) const;
+    IntegrationResult integratePositiveInfinity(API::IPeakFunction_const_sptr peakFunction, double lowerLimit) const;
+    IntegrationResult integrateNegativeInfinity(API::IPeakFunction_const_sptr peakFunction, double upperLimit) const;
+
+    IntegrationResult integrate(API::IPeakFunction_const_sptr peakFunction, double lowerLimit, double upperLimit) const;
+
+protected:
+    gsl_function getGSLFunction(API::IPeakFunction_const_sptr peakFunction) const;
+    void throwIfInvalid(API::IPeakFunction_const_sptr peakFunction) const;
+
+    gsl_integration_workspace *m_integrationWorkspace;
+
+    double m_relativePrecision;
+};
+
+double MANTID_SINQ_DLL gsl_peak_wrapper(double x, void *parameters);
+
+}
+}
+
+#endif // PEAKFUNCTIONINTEGRATOR_H
diff --git a/Code/Mantid/Framework/SINQ/inc/MantidSINQ/PoldiUtilities/Poldi2DFunction.h b/Code/Mantid/Framework/SINQ/inc/MantidSINQ/PoldiUtilities/Poldi2DFunction.h
new file mode 100644
index 0000000000000000000000000000000000000000..3c5b9dc6ed4ccd8362bff7d6d96ee8ebfc52e965
--- /dev/null
+++ b/Code/Mantid/Framework/SINQ/inc/MantidSINQ/PoldiUtilities/Poldi2DFunction.h
@@ -0,0 +1,59 @@
+#ifndef MANTID_SINQ_POLDI2DFUNCTION_H_
+#define MANTID_SINQ_POLDI2DFUNCTION_H_
+
+#include "MantidKernel/System.h"
+#include "MantidSINQ/DllConfig.h"
+#include "MantidAPI/CompositeFunction.h"
+#include "MantidAPI/IFunction1DSpectrum.h"
+
+namespace Mantid
+{
+namespace Poldi
+{
+
+/** Poldi2DFunction :
+
+    Function for POLDI 2D spectrum. It implements CompositeFunction in order to
+    combine functions for different peaks and IFunction1DSpectrum so that Fit
+    is able to choose the correct domain creator for it.
+
+      @author Michael Wedel, Paul Scherrer Institut - SINQ
+      @date 13/06/2014
+
+      Copyright © 2014 PSI-MSS
+
+    This file is part of Mantid.
+
+    Mantid is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 3 of the License, or
+    (at your option) any later version.
+
+    Mantid is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+    File change history is stored at: <https://github.com/mantidproject/mantid>
+    Code Documentation is available at: <http://doxygen.mantidproject.org>
+  */
+class MANTID_SINQ_DLL Poldi2DFunction : virtual public API::IFunction1DSpectrum, virtual public API::CompositeFunction
+{
+public:
+    Poldi2DFunction();
+    virtual ~Poldi2DFunction() {}
+
+    virtual void function(const API::FunctionDomain &domain, API::FunctionValues &values) const;
+    virtual void functionDeriv(const API::FunctionDomain &domain, API::Jacobian &jacobian);
+    
+    virtual void function1DSpectrum(const API::FunctionDomain1DSpectrum &domain, API::FunctionValues &values) const;
+};
+
+
+} // namespace SINQ
+} // namespace Mantid
+
+#endif  /* MANTID_SINQ_POLDI2DFUNCTION_H_ */
diff --git a/Code/Mantid/Framework/SINQ/inc/MantidSINQ/PoldiUtilities/PoldiAbstractDetector.h b/Code/Mantid/Framework/SINQ/inc/MantidSINQ/PoldiUtilities/PoldiAbstractDetector.h
index 6c5d9ce0a4a45f5545747975c984778568c77a72..f97e3465de1f446a825f91050317edf141a9a2ab 100644
--- a/Code/Mantid/Framework/SINQ/inc/MantidSINQ/PoldiUtilities/PoldiAbstractDetector.h
+++ b/Code/Mantid/Framework/SINQ/inc/MantidSINQ/PoldiUtilities/PoldiAbstractDetector.h
@@ -50,6 +50,8 @@ public:
 
     virtual void loadConfiguration(Geometry::Instrument_const_sptr poldiInstrument) = 0;
 
+    virtual double efficiency() = 0;
+
     virtual double twoTheta(int elementIndex) = 0;
     virtual double distanceFromSample(int elementIndex) = 0;
 
diff --git a/Code/Mantid/Framework/SINQ/inc/MantidSINQ/PoldiUtilities/PoldiDetectorDecorator.h b/Code/Mantid/Framework/SINQ/inc/MantidSINQ/PoldiUtilities/PoldiDetectorDecorator.h
index fcc920ad1c39d336e67afcc385ef513c04d5185f..7d8071ad75b5bd94137dadfa4e9eaa3f1364fed1 100644
--- a/Code/Mantid/Framework/SINQ/inc/MantidSINQ/PoldiUtilities/PoldiDetectorDecorator.h
+++ b/Code/Mantid/Framework/SINQ/inc/MantidSINQ/PoldiUtilities/PoldiDetectorDecorator.h
@@ -51,6 +51,8 @@ public:
 
     virtual void loadConfiguration(Geometry::Instrument_const_sptr poldiInstrument);
 
+    virtual double efficiency();
+
     virtual double twoTheta(int elementIndex);
     virtual double distanceFromSample(int elementIndex);
 
diff --git a/Code/Mantid/Framework/SINQ/inc/MantidSINQ/PoldiUtilities/PoldiHeliumDetector.h b/Code/Mantid/Framework/SINQ/inc/MantidSINQ/PoldiUtilities/PoldiHeliumDetector.h
index 896aa37d5b9c6f73977d4d62d9c34e93798d0af0..890599e9ce0a43fa556eecd91a1a72a648c0a702 100644
--- a/Code/Mantid/Framework/SINQ/inc/MantidSINQ/PoldiUtilities/PoldiHeliumDetector.h
+++ b/Code/Mantid/Framework/SINQ/inc/MantidSINQ/PoldiUtilities/PoldiHeliumDetector.h
@@ -47,6 +47,8 @@ public:
 
     void loadConfiguration(Geometry::Instrument_const_sptr poldiInstrument);
 
+    double efficiency();
+
     double twoTheta(int elementIndex);
     double distanceFromSample(int elementIndex);
 
@@ -61,10 +63,10 @@ protected:
     double phi(int elementIndex);
     double phi(double twoTheta);
 
-    void initializeFixedParameters(double radius, size_t elementCount, double elementWidth);
+    void initializeFixedParameters(double radius, size_t elementCount, double elementWidth, double newEfficiency);
     void initializeCalibratedParameters(Kernel::V2D position, double centerTwoTheta);
 
-    /* These detector parameters are fixed and specific to the geometry or result from it directly */
+    /* These detector parameters are fixed and specific to the geometry or result from it directly */    
     double m_radius;
     size_t m_elementCount;
     size_t m_centralElement;
@@ -72,6 +74,7 @@ protected:
     double m_angularResolution;
     double m_totalOpeningAngle;
     std::vector<int> m_availableElements;
+    double m_efficiency;
 
     /* Parameters that are calibrated or depend on calibrated parameters */
     V2D m_calibratedPosition;
diff --git a/Code/Mantid/Framework/SINQ/inc/MantidSINQ/PoldiUtilities/PoldiInstrumentAdapter.h b/Code/Mantid/Framework/SINQ/inc/MantidSINQ/PoldiUtilities/PoldiInstrumentAdapter.h
new file mode 100644
index 0000000000000000000000000000000000000000..ea9d164702361bc2f779f3f32d3a41b06e60c1ae
--- /dev/null
+++ b/Code/Mantid/Framework/SINQ/inc/MantidSINQ/PoldiUtilities/PoldiInstrumentAdapter.h
@@ -0,0 +1,121 @@
+#ifndef MANTID_SINQ_POLDIINSTRUMENTADAPTER_H_
+#define MANTID_SINQ_POLDIINSTRUMENTADAPTER_H_
+
+#include "MantidKernel/System.h"
+#include "MantidSINQ/DllConfig.h"
+#include "MantidGeometry/Instrument.h"
+#include "MantidAPI/ExperimentInfo.h"
+#include "MantidAPI/MatrixWorkspace.h"
+
+#include <map>
+
+#include "MantidSINQ/PoldiUtilities/PoldiAbstractDetector.h"
+#include "MantidSINQ/PoldiUtilities/PoldiAbstractChopper.h"
+#include "MantidSINQ/PoldiUtilities/PoldiSourceSpectrum.h"
+
+namespace Mantid
+{
+namespace Poldi
+{
+
+/** PoldiInstrumentAdapter :
+    Adapter for constructing POLDI objects on the basis
+    of Mantid's instrument-tools.
+
+    Mantid is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 3 of the License, or
+    (at your option) any later version.
+
+    Mantid is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+    File change history is stored at: <https://github.com/mantidproject/mantid>
+    Code Documentation is available at: <http://doxygen.mantidproject.org>
+  */
+
+class AbstractDoubleValueExtractor
+{
+public:
+    AbstractDoubleValueExtractor(std::string doubleValueKey) :
+        m_doubleValueKey(doubleValueKey)
+    { }
+
+    virtual ~AbstractDoubleValueExtractor() { }
+
+    virtual double operator()(const API::Run &runInformation) const = 0;
+
+protected:
+    std::string m_doubleValueKey;
+};
+
+typedef boost::shared_ptr<AbstractDoubleValueExtractor> AbstractDoubleValueExtractor_sptr;
+
+class NumberDoubleValueExtractor : public AbstractDoubleValueExtractor
+{
+public:
+    NumberDoubleValueExtractor(std::string doubleValueKey) :
+        AbstractDoubleValueExtractor(doubleValueKey)
+    { }
+    virtual ~NumberDoubleValueExtractor() { }
+
+    virtual double operator()(const API::Run &runInformation) const {
+        return runInformation.getPropertyValueAsType<double>(m_doubleValueKey);
+    }
+};
+
+class VectorDoubleValueExtractor : public AbstractDoubleValueExtractor
+{
+public:
+    VectorDoubleValueExtractor(std::string doubleValueKey) :
+        AbstractDoubleValueExtractor(doubleValueKey)
+    { }
+    virtual ~VectorDoubleValueExtractor() { }
+
+    virtual double operator()(const API::Run &runInformation) const {
+        return runInformation.getPropertyValueAsType<std::vector<double> >(m_doubleValueKey).front();
+    }
+};
+
+class MANTID_SINQ_DLL PoldiInstrumentAdapter
+{
+public:
+    PoldiInstrumentAdapter(const API::MatrixWorkspace_const_sptr &matrixWorkspace);
+    PoldiInstrumentAdapter(const Geometry::Instrument_const_sptr &mantidInstrument, const API::Run &runInformation);
+    virtual ~PoldiInstrumentAdapter();
+
+    PoldiAbstractChopper_sptr chopper() const;
+    PoldiAbstractDetector_sptr detector() const;
+    PoldiSourceSpectrum_sptr spectrum() const;
+
+protected:
+    PoldiInstrumentAdapter() { }
+
+    void initializeFromInstrumentAndRun(const Geometry::Instrument_const_sptr &mantidInstrument, const API::Run &runInformation);
+
+    void setDetector(const Geometry::Instrument_const_sptr &mantidInstrument);
+    void setChopper(const Geometry::Instrument_const_sptr &mantidInstrument, const API::Run &runInformation);
+    void setSpectrum(const Geometry::Instrument_const_sptr &mantidInstrument);
+
+    double getChopperSpeedFromRun(const API::Run &runInformation);
+    AbstractDoubleValueExtractor_sptr getExtractorForProperty(Kernel::Property *chopperSpeedProperty);
+
+    PoldiAbstractChopper_sptr m_chopper;
+    PoldiAbstractDetector_sptr m_detector;
+    PoldiSourceSpectrum_sptr m_spectrum;
+
+    static const std::string m_chopperSpeedPropertyName;
+    static std::map<std::string, AbstractDoubleValueExtractor_sptr> m_extractors;
+};
+
+typedef boost::shared_ptr<PoldiInstrumentAdapter> PoldiInstrumentAdapter_sptr;
+
+} // namespace Poldi
+} // namespace Mantid
+
+#endif  /* MANTID_SINQ_POLDIINSTRUMENTADAPTER_H_ */
diff --git a/Code/Mantid/Framework/SINQ/inc/MantidSINQ/PoldiUtilities/PoldiMockInstrumentHelpers.h b/Code/Mantid/Framework/SINQ/inc/MantidSINQ/PoldiUtilities/PoldiMockInstrumentHelpers.h
index b171b5ca8e93c50be42d475a5c41d3902350e38a..028e933041570ac359823e1d051811fd5395a19e 100644
--- a/Code/Mantid/Framework/SINQ/inc/MantidSINQ/PoldiUtilities/PoldiMockInstrumentHelpers.h
+++ b/Code/Mantid/Framework/SINQ/inc/MantidSINQ/PoldiUtilities/PoldiMockInstrumentHelpers.h
@@ -6,6 +6,9 @@
 #include <algorithm>
 #include "MantidSINQ/PoldiUtilities/PoldiAbstractDetector.h"
 #include "MantidSINQ/PoldiUtilities/PoldiAbstractChopper.h"
+#include "MantidSINQ/PoldiUtilities/PoldiSourceSpectrum.h"
+#include "MantidSINQ/PoldiUtilities/PoldiInstrumentAdapter.h"
+#include "MantidSINQ/PoldiUtilities/PoldiPeakCollection.h"
 
 #include "MantidSINQ/PoldiUtilities/PoldiHeliumDetector.h"
 #include "MantidSINQ/PoldiUtilities/PoldiConversions.h"
@@ -13,7 +16,12 @@
 #include "MantidGeometry/Instrument/FitParameter.h"
 #include "MantidKernel/Interpolation.h"
 
-using namespace Mantid::Geometry;
+#include "MantidAPI/WorkspaceFactory.h"
+#include "MantidDataObjects/TableWorkspace.h"
+#include "MantidAPI/TableRow.h"
+#include "MantidTestHelpers/WorkspaceCreationHelper.h"
+
+using ::testing::Return;
 
 namespace Mantid {
 namespace Poldi {
@@ -41,6 +49,7 @@ public:
         UNUSED_ARG(poldiInstrument);
     }
 
+    MOCK_METHOD0(efficiency, double());
     MOCK_METHOD1(twoTheta, double(int elementIndex));
     MOCK_METHOD1(distanceFromSample, double(int elementIndex));
     MOCK_METHOD0(elementCount, size_t());
@@ -66,7 +75,7 @@ public:
     {
         UNUSED_ARG(poldiInstrument);
 
-        initializeFixedParameters(3000.0, static_cast<size_t>(400), 2.5);
+        initializeFixedParameters(3000.0, static_cast<size_t>(400), 2.5, 0.88);
         initializeCalibratedParameters(Mantid::Kernel::V2D(-931.47, -860.0), Conversions::degToRad(90.41));
     }
 };
@@ -81,10 +90,10 @@ protected:
 public:
     MockChopper() : PoldiAbstractChopper()
     {
-        double slits [] = {0.000000, 0.162156};
+        double slits [] = {0.000000, 0.162156, 0.250867, 0.3704, 0.439811, 0.588455, 0.761389, 0.895667};
         m_slitPositions = std::vector<double>(slits, slits + sizeof(slits) / sizeof(slits[0]));
 
-        double times [] = {0.000000, 243.234};
+        double times [] = {0.000000, 243.234, 376.3, 555.6, 659.716, 882.682, 1142.08, 1343.5};
         m_slitTimes = std::vector<double>(times, times + sizeof(times) / sizeof(times[0]));
     }
 
@@ -110,26 +119,26 @@ public:
     }
 };
 
-class PoldiFakeSourceComponent : public ObjComponent
+class PoldiFakeSourceComponent : public Geometry::ObjComponent
 {
 public:
     PoldiFakeSourceComponent() :
         ObjComponent("FakePoldiSource", 0) {}
 };
 
-class PoldiAbstractFakeInstrument : public Instrument
+class PoldiAbstractFakeInstrument : public Geometry::Instrument
 {
 public:
     PoldiAbstractFakeInstrument() {}
 
-    virtual boost::shared_ptr<const IComponent> getComponentByName(const std::string &cname, int nlevels = 0) const {
+    virtual boost::shared_ptr<const Geometry::IComponent> getComponentByName(const std::string &cname, int nlevels = 0) const {
         UNUSED_ARG(cname);
         UNUSED_ARG(nlevels);
 
         return getComponentByNameFake();
     }
 
-    virtual boost::shared_ptr<const IComponent> getComponentByNameFake() const = 0;
+    virtual boost::shared_ptr<const Geometry::IComponent> getComponentByNameFake() const = 0;
 };
 
 class PoldiValidSourceFakeInstrument : public PoldiAbstractFakeInstrument
@@ -138,9 +147,9 @@ public:
     PoldiValidSourceFakeInstrument() :
         PoldiAbstractFakeInstrument() {}
 
-    boost::shared_ptr<const IComponent> getComponentByNameFake() const
+    boost::shared_ptr<const Geometry::IComponent> getComponentByNameFake() const
     {
-        return boost::shared_ptr<const IComponent>(new PoldiFakeSourceComponent);
+        return boost::shared_ptr<const Geometry::IComponent>(new PoldiFakeSourceComponent);
     }
 };
 
@@ -150,30 +159,364 @@ public:
     PoldiInvalidSourceFakeInstrument() :
         PoldiAbstractFakeInstrument() {}
 
-    boost::shared_ptr<const IComponent> getComponentByNameFake() const
+    boost::shared_ptr<const Geometry::IComponent> getComponentByNameFake() const
     {
-        return boost::shared_ptr<const IComponent>();
+        return boost::shared_ptr<const Geometry::IComponent>();
     }
 };
 
-class PoldiValidFakeParameterMap : public ParameterMap
+class PoldiValidFakeParameterMap : public Geometry::ParameterMap
 {
 public:
-    PoldiValidFakeParameterMap(const IComponent *component) :
-        ParameterMap()
+    PoldiValidFakeParameterMap(const Geometry::IComponent *component) :
+        Geometry::ParameterMap()
     {
         add("fitting", component, "WavelengthDistribution", Mantid::Geometry::FitParameter());
     }
 
 };
 
-class PoldiInvalidFakeParameterMap : public ParameterMap
+class PoldiInvalidFakeParameterMap : public Geometry::ParameterMap
 {
 public:
     PoldiInvalidFakeParameterMap() :
-        ParameterMap()
+        Geometry::ParameterMap()
+    {
+    }
+
+};
+
+class ConfiguredSpectrum : public PoldiSourceSpectrum
+{
+public:
+    ConfiguredSpectrum() :
+        PoldiSourceSpectrum(Kernel::Interpolation())
     {
+        m_spectrum.addPoint(0.986430049, 0.0379200461685);
+        m_spectrum.addPoint(1.01097, 0.0647900877564);
+        m_spectrum.addPoint(1.03552008, 0.158472779233);
+        m_spectrum.addPoint(1.06007004, 0.519912166374);
+        m_spectrum.addPoint(1.08460999, 1.61236820184);
+        m_spectrum.addPoint(1.10916007, 2.92556206166);
+        m_spectrum.addPoint(1.13371003, 3.01527151822);
+        m_spectrum.addPoint(1.15825999, 3.08617045167);
+        m_spectrum.addPoint(1.18280005, 3.3797870393);
+        m_spectrum.addPoint(1.20735002, 3.54669731732);
+        m_spectrum.addPoint(1.23189998, 3.6408488786);
+        m_spectrum.addPoint(1.25644004, 3.61670774172);
+        m_spectrum.addPoint(1.28099, 3.74104456034);
+        m_spectrum.addPoint(1.30553997, 3.85943944836);
+        m_spectrum.addPoint(1.33009005, 3.75758537926);
+        m_spectrum.addPoint(1.35462999, 3.72106056606);
+        m_spectrum.addPoint(1.37918007, 3.73501609979);
+        m_spectrum.addPoint(1.40373003, 3.80737158413);
+        m_spectrum.addPoint(1.42826998, 3.74757696126);
+        m_spectrum.addPoint(1.45282006, 3.79171629046);
+        m_spectrum.addPoint(1.47737002, 3.70519039935);
+        m_spectrum.addPoint(1.50190997, 3.64835854136);
+        m_spectrum.addPoint(1.52646005, 3.58509014427);
+        m_spectrum.addPoint(1.55101001, 3.52528432718);
+        m_spectrum.addPoint(1.57554996, 3.58574587753);
+        m_spectrum.addPoint(1.60010004, 3.52296612136);
+        m_spectrum.addPoint(1.62465, 3.48146692706);
+        m_spectrum.addPoint(1.64919996, 3.29247486904);
+        m_spectrum.addPoint(1.67374003, 3.18613505977);
+        m_spectrum.addPoint(1.69828999, 3.11493402243);
+        m_spectrum.addPoint(1.72284007, 3.019974154);
+        m_spectrum.addPoint(1.74738002, 2.95223419475);
+        m_spectrum.addPoint(1.77192998, 2.87013941439);
+        m_spectrum.addPoint(1.79648006, 2.8518896839);
+        m_spectrum.addPoint(1.82102001, 2.81334596521);
+        m_spectrum.addPoint(1.84556997, 2.79063867035);
+        m_spectrum.addPoint(1.87012005, 2.73278925933);
+        m_spectrum.addPoint(1.89467001, 2.70067519099);
+        m_spectrum.addPoint(1.91921008, 2.6032279618);
+        m_spectrum.addPoint(1.94376004, 2.49786056822);
+        m_spectrum.addPoint(1.96831, 2.3271600338);
+        m_spectrum.addPoint(1.99285007, 2.34552390934);
+        m_spectrum.addPoint(2.01740003, 2.22035491325);
+        m_spectrum.addPoint(2.04194999, 2.29464387452);
+        m_spectrum.addPoint(2.06648993, 2.20015866926);
+        m_spectrum.addPoint(2.09104013, 2.1126010471);
+        m_spectrum.addPoint(2.1155901, 2.03543605117);
+        m_spectrum.addPoint(2.14014006, 2.03696461356);
+        m_spectrum.addPoint(2.16468, 2.02314915783);
+        m_spectrum.addPoint(2.18922997, 1.92865797498);
+        m_spectrum.addPoint(2.21377993, 1.76339003593);
+        m_spectrum.addPoint(2.23832011, 1.70948140257);
+        m_spectrum.addPoint(2.26287007, 1.70655034399);
+        m_spectrum.addPoint(2.28742003, 1.63185257524);
+        m_spectrum.addPoint(2.31195998, 1.6101119067);
+        m_spectrum.addPoint(2.33650994, 1.52402877822);
+        m_spectrum.addPoint(2.3610599, 1.41765223428);
+        m_spectrum.addPoint(2.3856101, 1.41372656581);
+        m_spectrum.addPoint(2.41015005, 1.37861914774);
+        m_spectrum.addPoint(2.43470001, 1.39547907016);
+        m_spectrum.addPoint(2.45924997, 1.32522954793);
+        m_spectrum.addPoint(2.48378992, 1.3747536237);
+        m_spectrum.addPoint(2.50834012, 1.26342285426);
+        m_spectrum.addPoint(2.53289008, 1.1961405706);
+        m_spectrum.addPoint(2.55743003, 1.15607902115);
+        m_spectrum.addPoint(2.58197999, 1.09374471504);
+        m_spectrum.addPoint(2.60652995, 1.08882219384);
+        m_spectrum.addPoint(2.63107991, 1.08884830502);
+        m_spectrum.addPoint(2.6556201, 1.05670290487);
+        m_spectrum.addPoint(2.68017006, 1.02406197103);
+        m_spectrum.addPoint(2.70472002, 0.989440668677);
+        m_spectrum.addPoint(2.72925997, 1.00035277903);
+        m_spectrum.addPoint(2.75380993, 0.95038734642);
+        m_spectrum.addPoint(2.77836013, 0.869240260323);
+        m_spectrum.addPoint(2.80291009, 0.836101367713);
+        m_spectrum.addPoint(2.82745004, 0.832658084227);
+        m_spectrum.addPoint(2.852, 0.784670032334);
+        m_spectrum.addPoint(2.87654996, 0.789144670394);
+        m_spectrum.addPoint(2.90108991, 0.725317653441);
+        m_spectrum.addPoint(2.92564011, 0.737710213048);
+        m_spectrum.addPoint(2.95019007, 0.742183265093);
+        m_spectrum.addPoint(2.97473001, 0.692213030379);
+        m_spectrum.addPoint(2.99927998, 0.653130845445);
+        m_spectrum.addPoint(3.02382994, 0.658097474694);
+        m_spectrum.addPoint(3.04837012, 0.629903015127);
+        m_spectrum.addPoint(3.07292008, 0.620515648311);
+        m_spectrum.addPoint(3.09747005, 0.59182542276);
+        m_spectrum.addPoint(3.12202001, 0.596295491013);
+        m_spectrum.addPoint(3.14655995, 0.553251221336);
+        m_spectrum.addPoint(3.17110991, 0.561185043087);
+        m_spectrum.addPoint(3.19566011, 0.509726198752);
+        m_spectrum.addPoint(3.22020006, 0.497861766253);
+        m_spectrum.addPoint(3.24475002, 0.500350162334);
+        m_spectrum.addPoint(3.26929998, 0.462253499734);
+        m_spectrum.addPoint(3.29383993, 0.448903255167);
+        m_spectrum.addPoint(3.31839013, 0.442976704117);
+        m_spectrum.addPoint(3.34293699, 0.410906557596);
+        m_spectrum.addPoint(3.36748409, 0.400728656223);
+        m_spectrum.addPoint(3.39203095, 0.390802883239);
+        m_spectrum.addPoint(3.41657805, 0.381123104847);
+        m_spectrum.addPoint(3.44112492, 0.371682888874);
+        m_spectrum.addPoint(3.46567202, 0.362476568119);
+        m_spectrum.addPoint(3.49021912, 0.35349822306);
+        m_spectrum.addPoint(3.51476598, 0.34474241879);
+        m_spectrum.addPoint(3.53931308, 0.336203424027);
+        m_spectrum.addPoint(3.56385994, 0.327875851925);
+        m_spectrum.addPoint(3.58840704, 0.319754644057);
+        m_spectrum.addPoint(3.61295295, 0.311834601816);
+        m_spectrum.addPoint(3.637501, 0.304110594682);
+        m_spectrum.addPoint(3.66204691, 0.296578008794);
+        m_spectrum.addPoint(3.68659401, 0.289232018017);
+        m_spectrum.addPoint(3.71114111, 0.282067934396);
+        m_spectrum.addPoint(3.73568797, 0.275081354334);
+        m_spectrum.addPoint(3.76023507, 0.268267710027);
+        m_spectrum.addPoint(3.78478193, 0.261622986372);
+        m_spectrum.addPoint(3.80932903, 0.255142781777);
+        m_spectrum.addPoint(3.83387613, 0.248823039086);
+        m_spectrum.addPoint(3.85842299, 0.242659933438);
+        m_spectrum.addPoint(3.88297009, 0.236649455739);
+        m_spectrum.addPoint(3.90751696, 0.230787759101);
+        m_spectrum.addPoint(3.93206406, 0.225071303024);
+        m_spectrum.addPoint(3.95661092, 0.219496468911);
+        m_spectrum.addPoint(3.98115826, 0.214059716263);
+        m_spectrum.addPoint(4.0057044, 0.208757618724);
+        m_spectrum.addPoint(4.03025055, 0.203586864087);
+        m_spectrum.addPoint(4.0547986, 0.198544166977);
+        m_spectrum.addPoint(4.0793457, 0.193626378592);
+        m_spectrum.addPoint(4.10389137, 0.188830387379);
+        m_spectrum.addPoint(4.12843847, 0.184153209345);
+        m_spectrum.addPoint(4.15298653, 0.179591790409);
+        m_spectrum.addPoint(4.17753267, 0.17514353127);
+        m_spectrum.addPoint(4.20207977, 0.170805354615);
+        m_spectrum.addPoint(4.2266264, 0.166574544595);
+        m_spectrum.addPoint(4.2511735, 0.162448630069);
+        m_spectrum.addPoint(4.2757206, 0.158424976688);
+        m_spectrum.addPoint(4.3002677, 0.154500833359);
+        m_spectrum.addPoint(4.32481432, 0.150673962236);
+        m_spectrum.addPoint(4.34936142, 0.146941962269);
+        m_spectrum.addPoint(4.37390852, 0.143302256984);
+        m_spectrum.addPoint(4.39845562, 0.139752771944);
+        m_spectrum.addPoint(4.42300272, 0.136291257291);
+        m_spectrum.addPoint(4.44754934, 0.132915370247);
+        m_spectrum.addPoint(4.47209644, 0.129623152325);
+        m_spectrum.addPoint(4.49664354, 0.126412482228);
+        m_spectrum.addPoint(4.52119064, 0.123281343393);
+        m_spectrum.addPoint(4.54573774, 0.120227765918);
+        m_spectrum.addPoint(4.57028341, 0.11724980313);
+        m_spectrum.addPoint(4.59483051, 0.114345613286);
+        m_spectrum.addPoint(4.61937857, 0.111513366463);
+        m_spectrum.addPoint(4.64392471, 0.108751267379);
+        m_spectrum.addPoint(4.66847134, 0.106057579427);
+        m_spectrum.addPoint(4.69301844, 0.103430600844);
+        m_spectrum.addPoint(4.71756554, 0.100868711172);
+        m_spectrum.addPoint(4.74211264, 0.0983702671227);
+        m_spectrum.addPoint(4.76665974, 0.0959336772731);
+        m_spectrum.addPoint(4.79120636, 0.093557508202);
+        m_spectrum.addPoint(4.81575346, 0.0912401628801);
+        m_spectrum.addPoint(4.84030056, 0.0889801784484);
+        m_spectrum.addPoint(4.86484766, 0.0867762492478);
+        m_spectrum.addPoint(4.88939476, 0.084626860153);
+        m_spectrum.addPoint(4.91394138, 0.0825306822753);
+        m_spectrum.addPoint(4.93848753, 0.0804864976671);
+        m_spectrum.addPoint(4.96303558, 0.0784929071503);
+        m_spectrum.addPoint(4.98758268, 0.0765486581333);
+        m_spectrum.addPoint(5.01212931, 0.0746526079641);
+        m_spectrum.addPoint(5.03667545, 0.0728035212728);
+        m_spectrum.addPoint(5.06122255, 0.0710002323781);
+        m_spectrum.addPoint(5.08577061, 0.0692416164508);
+        m_spectrum.addPoint(5.11031771, 0.0675265194243);
+        m_spectrum.addPoint(5.13486338, 0.0658539680618);
+        m_spectrum.addPoint(5.15941048, 0.0642228143046);
+        m_spectrum.addPoint(5.18395853, 0.0626320322489);
+        m_spectrum.addPoint(5.20850468, 0.0610807125393);
+        m_spectrum.addPoint(5.23305178, 0.0595677948282);
+        m_spectrum.addPoint(5.2575984, 0.0580923114862);
+        m_spectrum.addPoint(5.2821455, 0.0566534406688);
+        m_spectrum.addPoint(5.3066926, 0.0552501801025);
+        m_spectrum.addPoint(5.3312397, 0.0538816494685);
+        m_spectrum.addPoint(5.35578632, 0.0525470679748);
+        m_spectrum.addPoint(5.38033342, 0.0512454914214);
+        m_spectrum.addPoint(5.40488052, 0.049976179668);
+        m_spectrum.addPoint(5.42942762, 0.0487383282922);
+        m_spectrum.addPoint(5.45397472, 0.0475310954243);
+        m_spectrum.addPoint(5.47852135, 0.0463537841787);
+        m_spectrum.addPoint(5.50306749, 0.0452056576189);
+        m_spectrum.addPoint(5.52761555, 0.044085928745);
+        m_spectrum.addPoint(5.55216265, 0.0429939565424);
+        m_spectrum.addPoint(5.60125542, 0.0408904789888);
+        m_spectrum.addPoint(5.62580252, 0.0398776505566);
+        m_spectrum.addPoint(5.65034962, 0.0388899122071);
+        m_spectrum.addPoint(5.69944334, 0.0369872268062);
+        m_spectrum.addPoint(5.72399044, 0.0360710788288);
+        m_spectrum.addPoint(5.77308464, 0.0343063026735);
+        m_spectrum.addPoint(5.79763174, 0.0334565608805);
+        m_spectrum.addPoint(5.82217836, 0.0326278676345);
+        m_spectrum.addPoint(5.87127256, 0.0310315517468);
+        m_spectrum.addPoint(5.89581966, 0.0302629090089);
+        m_spectrum.addPoint(5.94491243, 0.0287823115682);
+        m_spectrum.addPoint(5.96946049, 0.0280693832282);
+        m_spectrum.addPoint(5.99400759, 0.0273741231399);
     }
+};
+
+class FakePoldiInstrumentAdapter : public PoldiInstrumentAdapter
+{
+public:
+    FakePoldiInstrumentAdapter() :
+        PoldiInstrumentAdapter()
+    {
+        MockChopper *chopper = new MockChopper;
+        m_chopper = PoldiAbstractChopper_sptr(chopper);
+        m_detector = PoldiAbstractDetector_sptr(new ConfiguredHeliumDetector);
+        m_spectrum = PoldiSourceSpectrum_sptr(new ConfiguredSpectrum);
+
+        EXPECT_CALL(*chopper, distanceFromSample())
+                .WillRepeatedly(Return(11800.0));
+
+        EXPECT_CALL(*chopper, zeroOffset())
+                .WillRepeatedly(Return(0.15));
+    }
+};
+
+
+class PoldiPeakCollectionHelpers
+{
+/* This class contains some static helper function to create
+ * peak collections and related components for testing purposes.
+ */
+public:
+
+/**
+ * This function creates a TableWorkspace which can be used by PoldiPeakCollection
+ *
+ * A TableWorkspace with four peaks is generated. The data comes from a run of the
+ * original analysis software on poldi2013n006904 (available in system tests and
+ * usage tests). Only the first four peaks are considered and no errors are provided.
+ *
+ * @return TableWorkspace in the format PoldiPeakCollection requires
+ */
+static DataObjects::TableWorkspace_sptr createPoldiPeakTableWorkspace()
+{
+    DataObjects::TableWorkspace_sptr tableWs = boost::dynamic_pointer_cast<DataObjects::TableWorkspace>(API::WorkspaceFactory::Instance().createTable());
+    tableWs->addColumn("str", "HKL");
+    tableWs->addColumn("str", "d");
+    tableWs->addColumn("str", "Q");
+    tableWs->addColumn("str", "Intensity");
+    tableWs->addColumn("str", "FWHM (rel.)");
+
+    tableWs->logs()->addProperty<std::string>("IntensityType", "Maximum");
+    tableWs->logs()->addProperty<std::string>("ProfileFunctionName", "Gaussian");
+
+    API::TableRow newRow = tableWs->appendRow();
+    newRow << "0 0 0" << "1.108644" << "5.667449" << "3286.152" << "0.002475747";
+
+    newRow = tableWs->appendRow();
+    newRow << "0 0 0" << "1.637539" << "3.836968" << "2951.696" << "0.002516417";
+
+    newRow = tableWs->appendRow();
+    newRow << "0 0 0" << "1.920200" << "3.272152" << "3238.473" << "0.002444439";
+
+    newRow = tableWs->appendRow();
+    newRow << "0 0 0" << "1.245958" << "5.042856" << "2219.592" << "0.002696334";
+
+    return tableWs;
+}
+
+/**
+ * This function creates a PoldiPeakCollection
+ *
+ * A PoldiPeakCollection is created with the same information as in createPoldiPeakTableWorkspace().
+ *
+ * @return PoldiPeakCollection with four example peaks.
+ */
+static PoldiPeakCollection_sptr createPoldiPeakCollectionMaximum()
+{
+    PoldiPeakCollection_sptr peaks(new PoldiPeakCollection);
+    peaks->addPeak(PoldiPeak::create(MillerIndices(0, 0, 0), UncertainValue(1.108644), UncertainValue(3286.152), UncertainValue(0.002475747)));
+    peaks->addPeak(PoldiPeak::create(MillerIndices(0, 0, 0), UncertainValue(1.637539), UncertainValue(2951.696), UncertainValue(0.002516417)));
+    peaks->addPeak(PoldiPeak::create(MillerIndices(0, 0, 0), UncertainValue(1.920200), UncertainValue(3238.473), UncertainValue(0.002444439)));
+    peaks->addPeak(PoldiPeak::create(MillerIndices(0, 0, 0), UncertainValue(1.245958), UncertainValue(2219.592), UncertainValue(0.002696334)));
+
+    peaks->setProfileFunctionName("Gaussian");
+
+    return peaks;
+}
+
+/**
+ * This function creates a PoldiPeakCollection with integrated intensities
+ *
+ * The same peaks as above, with integrated intensities in "channel units".
+ *
+ * @return PoldiPeakCollection with four example peaks.
+ */
+static PoldiPeakCollection_sptr createPoldiPeakCollectionIntegral()
+{
+    PoldiPeakCollection_sptr peaks(new PoldiPeakCollection(PoldiPeakCollection::Integral));
+    peaks->addPeak(PoldiPeak::create(MillerIndices(0, 0, 0), UncertainValue(1.108644), UncertainValue(15835.28906), UncertainValue(0.002475747)));
+    peaks->addPeak(PoldiPeak::create(MillerIndices(0, 0, 0), UncertainValue(1.637539), UncertainValue(21354.32226), UncertainValue(0.002516417)));
+    peaks->addPeak(PoldiPeak::create(MillerIndices(0, 0, 0), UncertainValue(1.920200), UncertainValue(26687.36132), UncertainValue(0.002444439)));
+    peaks->addPeak(PoldiPeak::create(MillerIndices(0, 0, 0), UncertainValue(1.245958), UncertainValue(13091.51855), UncertainValue(0.002696334)));
+
+    peaks->setProfileFunctionName("Gaussian");
+
+    return peaks;
+}
+
+/**
+ * This function creates a PoldiPeakCollection with normalized intensities
+ *
+ * Again, the same peaks as above, but with normalized intensities (for 8 chopper slits)
+ *
+ * @return PoldiPeakCollection with four example peaks.
+ */
+static PoldiPeakCollection_sptr createPoldiPeakCollectionNormalized()
+{
+    PoldiPeakCollection_sptr peaks(new PoldiPeakCollection(PoldiPeakCollection::Integral));
+    peaks->addPeak(PoldiPeak::create(MillerIndices(0, 0, 0), UncertainValue(1.108644), UncertainValue(1.926395655), UncertainValue(0.002475747)));
+    peaks->addPeak(PoldiPeak::create(MillerIndices(0, 0, 0), UncertainValue(1.920200), UncertainValue(4.773980141), UncertainValue(0.002444439)));
+    peaks->addPeak(PoldiPeak::create(MillerIndices(0, 0, 0), UncertainValue(1.637539), UncertainValue(9.370919228), UncertainValue(0.002516417)));
+    peaks->addPeak(PoldiPeak::create(MillerIndices(0, 0, 0), UncertainValue(1.245958), UncertainValue(1.758037806), UncertainValue(0.002696334)));
+
+    peaks->setProfileFunctionName("Gaussian");
+
+    return peaks;
+}
 
 };
 
diff --git a/Code/Mantid/Framework/SINQ/inc/MantidSINQ/PoldiUtilities/PoldiPeak.h b/Code/Mantid/Framework/SINQ/inc/MantidSINQ/PoldiUtilities/PoldiPeak.h
index acf37b738c660f4e1ea20d08f4965f48d0a15990..f0ba9d7dd4598dabfb4310d1d189931e3014f658 100644
--- a/Code/Mantid/Framework/SINQ/inc/MantidSINQ/PoldiUtilities/PoldiPeak.h
+++ b/Code/Mantid/Framework/SINQ/inc/MantidSINQ/PoldiUtilities/PoldiPeak.h
@@ -53,6 +53,8 @@ public:
 
     ~PoldiPeak() {}
 
+    PoldiPeak_sptr clone() const;
+
     const MillerIndices& hkl() const;
     void setHKL(MillerIndices hkl);
 
diff --git a/Code/Mantid/Framework/SINQ/inc/MantidSINQ/PoldiUtilities/PoldiPeakCollection.h b/Code/Mantid/Framework/SINQ/inc/MantidSINQ/PoldiUtilities/PoldiPeakCollection.h
index bcceaf66f1719511d5637874bc0ef4ad9445f662..185d87ba49d719466b7d5717b1d6c48ff8f94ecb 100644
--- a/Code/Mantid/Framework/SINQ/inc/MantidSINQ/PoldiUtilities/PoldiPeakCollection.h
+++ b/Code/Mantid/Framework/SINQ/inc/MantidSINQ/PoldiUtilities/PoldiPeakCollection.h
@@ -38,32 +38,60 @@ namespace Poldi {
   Code Documentation is available at: <http://doxygen.mantidproject.org>
 */
 
+class PoldiPeakCollection;
+
+typedef boost::shared_ptr<PoldiPeakCollection> PoldiPeakCollection_sptr;
+
 class MANTID_SINQ_DLL PoldiPeakCollection
-{
+{    
 public:
-    PoldiPeakCollection();
-    PoldiPeakCollection(DataObjects::TableWorkspace_sptr workspace);
+    enum IntensityType {
+        Maximum,
+        Integral
+    };
+
+    PoldiPeakCollection(IntensityType intensityType = Maximum);
+    PoldiPeakCollection(const DataObjects::TableWorkspace_sptr &workspace);
     virtual ~PoldiPeakCollection() {}
 
+    PoldiPeakCollection_sptr clone();
+
     size_t peakCount() const;
 
-    void addPeak(PoldiPeak_sptr newPeak);
+    void addPeak(const PoldiPeak_sptr &newPeak);
     PoldiPeak_sptr peak(size_t index) const;
 
+    IntensityType intensityType() const;
+
+    void setProfileFunctionName(std::string newProfileFunction);
+    std::string getProfileFunctionName() const;
+    bool hasProfileFunctionName() const;
+
     DataObjects::TableWorkspace_sptr asTableWorkspace();
 
 protected:
-    void prepareTable(DataObjects::TableWorkspace_sptr table);
-    void peaksToTable(DataObjects::TableWorkspace_sptr table);
+    void prepareTable(const DataObjects::TableWorkspace_sptr &table);
+    void dataToTableLog(const DataObjects::TableWorkspace_sptr &table);
+    void peaksToTable(const DataObjects::TableWorkspace_sptr &table);
 
-    void constructFromTableWorkspace(DataObjects::TableWorkspace_sptr tableWorkspace);
-    bool checkColumns(DataObjects::TableWorkspace_sptr tableWorkspace);
+    void constructFromTableWorkspace(const DataObjects::TableWorkspace_sptr &tableWorkspace);
+    bool checkColumns(const DataObjects::TableWorkspace_sptr &tableWorkspace);
+
+    void recoverDataFromLog(const DataObjects::TableWorkspace_sptr &TableWorkspace);
+
+    std::string getIntensityTypeFromLog(const API::LogManager_sptr &tableLog);
+    std::string getProfileFunctionNameFromLog(const API::LogManager_sptr &tableLog);
+
+    std::string getStringValueFromLog(const API::LogManager_sptr &logManager, std::string valueName);
+
+    std::string intensityTypeToString(IntensityType type) const;
+    IntensityType intensityTypeFromString(std::string typeString) const;
 
     std::vector<PoldiPeak_sptr> m_peaks;
+    IntensityType m_intensityType;
+    std::string m_profileFunctionName;
 };
 
-typedef boost::shared_ptr<PoldiPeakCollection> PoldiPeakCollection_sptr;
-
 }
 }
 
diff --git a/Code/Mantid/Framework/SINQ/inc/MantidSINQ/PoldiUtilities/PoldiSourceSpectrum.h b/Code/Mantid/Framework/SINQ/inc/MantidSINQ/PoldiUtilities/PoldiSourceSpectrum.h
index 41e6b8b0bd25d132961a9fa19b9fb74e7e2c2c6c..5b418feeee8387f1afd9280e7b1645cabd454dd6 100644
--- a/Code/Mantid/Framework/SINQ/inc/MantidSINQ/PoldiUtilities/PoldiSourceSpectrum.h
+++ b/Code/Mantid/Framework/SINQ/inc/MantidSINQ/PoldiUtilities/PoldiSourceSpectrum.h
@@ -60,6 +60,8 @@ protected:
 };
 
 typedef boost::shared_ptr<PoldiSourceSpectrum> PoldiSourceSpectrum_sptr;
+typedef boost::shared_ptr<const PoldiSourceSpectrum> PoldiSourceSpectrum_const_sptr;
+
 
 }
 }
diff --git a/Code/Mantid/Framework/SINQ/inc/MantidSINQ/PoldiUtilities/PoldiSpectrumDomainFunction.h b/Code/Mantid/Framework/SINQ/inc/MantidSINQ/PoldiUtilities/PoldiSpectrumDomainFunction.h
new file mode 100644
index 0000000000000000000000000000000000000000..7b4910999925cc11b26c591b3944773d9dc324c5
--- /dev/null
+++ b/Code/Mantid/Framework/SINQ/inc/MantidSINQ/PoldiUtilities/PoldiSpectrumDomainFunction.h
@@ -0,0 +1,74 @@
+#ifndef MANTID_SINQ_POLDISPECTRUMDOMAINFUNCTION_H_
+#define MANTID_SINQ_POLDISPECTRUMDOMAINFUNCTION_H_
+
+#include "MantidSINQ/DllConfig.h"
+#include "MantidAPI/ParamFunction.h"
+#include "MantidAPI/IFunction1DSpectrum.h"
+#include "MantidAPI/FunctionDomain1D.h"
+#include <string>
+
+#include "MantidSINQ/PoldiUtilities/PoldiInstrumentAdapter.h"
+#include "MantidSINQ/PoldiUtilities/PoldiTimeTransformer.h"
+
+#include "MantidDataObjects/Workspace2D.h"
+#include "MantidSINQ/PoldiUtilities/PoldiConversions.h"
+
+namespace Mantid
+{
+namespace Poldi
+{
+
+/** PoldiSpectrumDomainFunction : TODO: DESCRIPTION
+
+    Copyright &copy; 2014 ISIS Rutherford Appleton Laboratory & NScD Oak Ridge National Laboratory
+
+    This file is part of Mantid.
+
+    Mantid is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 3 of the License, or
+    (at your option) any later version.
+
+    Mantid is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+    File change history is stored at: <https://github.com/mantidproject/mantid>
+    Code Documentation is available at: <http://doxygen.mantidproject.org>
+  */
+
+class MANTID_SINQ_DLL PoldiSpectrumDomainFunction : virtual public API::ParamFunction, virtual public API::IFunction1DSpectrum
+{
+public:
+    PoldiSpectrumDomainFunction();
+    virtual ~PoldiSpectrumDomainFunction()
+    {}
+    
+    virtual std::string name() const { return "PoldiSpectrumDomainFunction"; }
+
+    virtual void setWorkspace(boost::shared_ptr<const API::Workspace> ws);
+    virtual void function1DSpectrum(const API::FunctionDomain1DSpectrum &domain, API::FunctionValues &values) const;
+
+protected:
+    virtual void init();
+    void initializeParametersFromWorkspace(const DataObjects::Workspace2D_const_sptr &workspace2D);
+    void initializeInstrumentParameters(const PoldiInstrumentAdapter_sptr &poldiInstrument);
+    std::vector<double> getChopperSlitOffsets(const PoldiAbstractChopper_sptr &chopper);
+
+    double actualFunction(double x, double x0, double sigma, double area) const;
+
+    std::vector<double> m_chopperSlitOffsets;
+    double m_deltaT;
+
+    PoldiTimeTransformer_sptr m_timeTransformer;
+};
+
+
+} // namespace Poldi
+} // namespace Mantid
+
+#endif  /* MANTID_SINQ_POLDISPECTRUMDOMAINFUNCTION_H_ */
diff --git a/Code/Mantid/Framework/SINQ/inc/MantidSINQ/PoldiUtilities/PoldiTimeTransformer.h b/Code/Mantid/Framework/SINQ/inc/MantidSINQ/PoldiUtilities/PoldiTimeTransformer.h
new file mode 100644
index 0000000000000000000000000000000000000000..31b5442fd18eba0027e256ef66bd271f18a0c46a
--- /dev/null
+++ b/Code/Mantid/Framework/SINQ/inc/MantidSINQ/PoldiUtilities/PoldiTimeTransformer.h
@@ -0,0 +1,135 @@
+#ifndef MANTID_SINQ_POLDITIMETRANSFORMER_H_
+#define MANTID_SINQ_POLDITIMETRANSFORMER_H_
+
+#include "MantidKernel/System.h"
+#include "MantidSINQ/DllConfig.h"
+#include "MantidSINQ/PoldiUtilities/PoldiInstrumentAdapter.h"
+#include "MantidSINQ/PoldiUtilities/PoldiConversions.h"
+
+namespace Mantid
+{
+namespace Poldi
+{
+
+/** PoldiTimeTransformer
+
+    This helper class transforms peaks from "d" to "time", using
+    factors derived from POLDI detector configuration.
+
+      @author Michael Wedel, Paul Scherrer Institut - SINQ
+      @date 22/05/2014
+
+      Copyright © 2014 PSI-MSS
+
+    This file is part of Mantid.
+
+    Mantid is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 3 of the License, or
+    (at your option) any later version.
+
+    Mantid is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+    File change history is stored at: <https://github.com/mantidproject/mantid>
+    Code Documentation is available at: <http://doxygen.mantidproject.org>
+  */
+
+struct DetectorElementCharacteristics {
+    DetectorElementCharacteristics() :
+        distance(0.0),
+        totalDistance(0.0),
+        twoTheta(0.0),
+        sinTheta(0.0),
+        cosTheta(1.0),
+        tof1A(0.0)
+    { }
+
+    DetectorElementCharacteristics(int element, const PoldiAbstractDetector_sptr &detector, const PoldiAbstractChopper_sptr &chopper)
+    {
+        distance = detector->distanceFromSample(element);
+        totalDistance = detector->distanceFromSample(element) + chopper->distanceFromSample();
+        twoTheta = detector->twoTheta(element);
+        sinTheta = sin(twoTheta / 2.0);
+        cosTheta = cos(twoTheta / 2.0);
+        tof1A = Conversions::dtoTOF(1.0, totalDistance, sinTheta);
+    }
+
+    double distance;
+    double totalDistance;
+    double twoTheta;
+    double sinTheta;
+    double cosTheta;
+    double tof1A;
+};
+
+class DetectorElementData
+{
+public:
+    DetectorElementData(int element, const DetectorElementCharacteristics &center, const PoldiAbstractDetector_sptr &detector, const PoldiAbstractChopper_sptr &chopper)
+    {
+        DetectorElementCharacteristics current(element, detector, chopper);
+
+        m_intensityFactor = pow(center.distance / current.distance, 2.0) * current.sinTheta / center.sinTheta;
+        m_lambdaFactor = 2.0 * current.sinTheta / center.tof1A;
+        m_timeFactor = current.sinTheta / center.sinTheta * current.totalDistance / center.totalDistance;
+        m_widthFactor = current.cosTheta - center.cosTheta;
+    }
+
+    double intensityFactor() const { return m_intensityFactor; }
+    double lambdaFactor() const { return m_lambdaFactor; }
+    double timeFactor() const { return m_timeFactor; }
+    double widthFactor() const { return m_widthFactor; }
+
+protected:
+    double m_intensityFactor;
+    double m_lambdaFactor;
+    double m_timeFactor;
+    double m_widthFactor;
+};
+
+typedef boost::shared_ptr<const DetectorElementData> DetectorElementData_const_sptr;
+
+class MANTID_SINQ_DLL PoldiTimeTransformer
+{
+public:
+    PoldiTimeTransformer();
+    PoldiTimeTransformer(const PoldiInstrumentAdapter_sptr &poldiInstrument);
+    virtual ~PoldiTimeTransformer() { }
+
+    void initializeFromPoldiInstrument(const PoldiInstrumentAdapter_sptr &poldiInstrument);
+
+    size_t detectorElementCount() const;
+
+    double dToTOF(double d) const;
+    double timeTransformedWidth(double widthD, size_t detectorIndex) const;
+    double timeTransformedCentre(double centreD, size_t detectorIndex) const;
+    double timeTransformedIntensity(double areaD, double centreD, size_t detectorIndex) const;
+    double detectorElementIntensity(double centreD, size_t detectorIndex) const;
+
+    double calculatedTotalIntensity(double centreD) const;
+
+protected:
+    std::vector<DetectorElementData_const_sptr> getDetectorElementData(const PoldiAbstractDetector_sptr &detector, const PoldiAbstractChopper_sptr &chopper);
+    DetectorElementCharacteristics getDetectorCenterCharacteristics(const PoldiAbstractDetector_sptr &detector, const PoldiAbstractChopper_sptr &chopper);
+
+    DetectorElementCharacteristics m_detectorCenter;
+    std::vector<DetectorElementData_const_sptr> m_detectorElementData;
+    double m_detectorEfficiency;
+    size_t m_chopperSlits;
+
+    PoldiSourceSpectrum_const_sptr m_spectrum;
+    
+};
+
+typedef boost::shared_ptr<PoldiTimeTransformer> PoldiTimeTransformer_sptr;
+
+} // namespace Poldi
+} // namespace Mantid
+
+#endif  /* MANTID_SINQ_POLDITIMETRANSFORMER_H_ */
diff --git a/Code/Mantid/Framework/SINQ/src/LoadFlexiNexus.cpp b/Code/Mantid/Framework/SINQ/src/LoadFlexiNexus.cpp
index d43d385aa087b5a15e367184cd78191a27a96214..97c545c6e2d2f5359da4f938d5e3aac1432fa5e2 100644
--- a/Code/Mantid/Framework/SINQ/src/LoadFlexiNexus.cpp
+++ b/Code/Mantid/Framework/SINQ/src/LoadFlexiNexus.cpp
@@ -138,7 +138,7 @@ void LoadFlexiNexus::load2DWorkspace(NeXus::File *fin)
   std::map<std::string,std::string>::const_iterator it;
   std::vector<double> xData;
   if((it = dictionary.find("x-axis")) == dictionary.end()){
-    xData.reserve(spectraLength);
+    xData.resize(spectraLength);
     for(int i = 0; i < spectraLength; i++){
       xData[i] = (double)i;
     }
@@ -281,16 +281,16 @@ MDHistoDimension_sptr LoadFlexiNexus::makeDimension(NeXus::File *fin, int index,
   dataName += "-axis";
   std::vector<double> dData;
   if((it = dictionary.find(dataName)) == dictionary.end()){
+    dData.resize(length);
     for(int i = 0; i < length; i++){
-      dData.reserve(length);
       dData[i] = (double)i;
     }
   } else {
     if(safeOpenpath(fin,it->second)){
       fin->getDataCoerce(dData);
     } else {
+      dData.resize(length);
       for(int i = 0; i < length; i++){
-        dData.reserve(length);
         dData[i] = (double)i;
       }
     }
diff --git a/Code/Mantid/Framework/SINQ/src/PoldiAutoCorrelation5.cpp b/Code/Mantid/Framework/SINQ/src/PoldiAutoCorrelation5.cpp
index 3e2e71a53886e8b76798e991fe9a2722a6cf61e0..078e4663460b197bbc172009ce097b72ff9a2f74 100644
--- a/Code/Mantid/Framework/SINQ/src/PoldiAutoCorrelation5.cpp
+++ b/Code/Mantid/Framework/SINQ/src/PoldiAutoCorrelation5.cpp
@@ -7,15 +7,8 @@
 #include "MantidDataObjects/MaskWorkspace.h"
 #include "MantidDataObjects/TableWorkspace.h"
 
-#include "MantidSINQ/PoldiUtilities/PoldiDetectorFactory.h"
 #include "MantidSINQ/PoldiUtilities/PoldiDeadWireDecorator.h"
-#include "MantidSINQ/PoldiUtilities/PoldiAutoCorrelationCore.h"
-#include "MantidSINQ/PoldiUtilities/PoldiChopperFactory.h"
-
-#include "MantidGeometry/IComponent.h"
-#include "MantidGeometry/Instrument.h"
-#include "MantidGeometry/Instrument/FitParameter.h"
-#include "MantidGeometry/Instrument/DetectorGroup.h"
+#include "MantidSINQ/PoldiUtilities/PoldiInstrumentAdapter.h"
 
 #include <boost/shared_ptr.hpp>
 
@@ -84,60 +77,15 @@ void PoldiAutoCorrelation5::exec()
     double wlen_min = this->getProperty("wlenmin");
     double wlen_max = this->getProperty("wlenmax");
 
-    double chopperSpeed = 0.0;
-
-    try {
-        chopperSpeed = localWorkspace->run().getPropertyValueAsType<std::vector<double> >("chopperspeed").front();
-    } catch(std::invalid_argument&) {
-        throw(std::runtime_error("Chopper speed could not be extracted from Workspace '" + localWorkspace->name() + "'. Aborting."));
-    }
 
-    // Instrument definition
-    Instrument_const_sptr poldiInstrument = localWorkspace->getInstrument();
-
-	// Chopper configuration
-    PoldiChopperFactory chopperFactory;
-    boost::shared_ptr<PoldiAbstractChopper> chopper(chopperFactory.createChopper(std::string("default-chopper")));
-    chopper->loadConfiguration(poldiInstrument);
-    chopper->setRotationSpeed(chopperSpeed);
-
-	g_log.information() << "____________________________________________________ "  << std::endl;
-	g_log.information() << "_Poldi  chopper conf ------------------------------  "  << std::endl;
-    g_log.information() << "_Poldi -     Chopper speed:   " << chopper->rotationSpeed() << " rpm" << std::endl;
-    g_log.information() << "_Poldi -     Number of slits: " << chopper->slitPositions().size() << std::endl;
-    g_log.information() << "_Poldi -     Cycle time:      " << chopper->cycleTime() << " µs" << std::endl;
-    g_log.information() << "_Poldi -     Zero offset:     " << chopper->zeroOffset() << " µs" << std::endl;
-    g_log.information() << "_Poldi -     Distance:        " << chopper->distanceFromSample()  << " mm" << std::endl;
-
-    if(g_log.is(Poco::Message::PRIO_DEBUG)) {
-        for(size_t i = 0; i < chopper->slitPositions().size(); ++i) {
-            g_log.information()   << "_Poldi -     Slits: " << i
-                            << ": Position = " << chopper->slitPositions()[i]
-                               << "\t Time = " << chopper->slitTimes()[i] << " µs" << std::endl;
-        }
-    }
+    PoldiInstrumentAdapter instrumentAdapter(localWorkspace);
+    PoldiAbstractChopper_sptr chopper = instrumentAdapter.chopper();
 
-	// Detector configuration
-    PoldiDetectorFactory detectorFactory;
-    boost::shared_ptr<PoldiAbstractDetector> detector(detectorFactory.createDetector(std::string("helium3-detector")));
-    detector->loadConfiguration(poldiInstrument);
-
-    g_log.information() << "_Poldi  detector conf ------------------------------  "  << std::endl;
-    g_log.information() << "_Poldi -     Element count:     " << detector->elementCount() << std::endl;
-    g_log.information() << "_Poldi -     Central element:   " << detector->centralElement() << std::endl;
-    g_log.information() << "_Poldi -     2Theta(central):   " << detector->twoTheta(199) / M_PI * 180.0 << "°" << std::endl;
-    g_log.information() << "_Poldi -     Distance(central): " << detector->distanceFromSample(199) << " mm" << std::endl;
-
-    boost::shared_ptr<PoldiDeadWireDecorator> cleanDetector(new PoldiDeadWireDecorator(poldiInstrument, detector));
-
-    std::set<int> deadWires = cleanDetector->deadWires();
-    g_log.information() << "_Poldi -     Number of dead wires: " << deadWires.size() << std::endl;
-    g_log.information() << "_Poldi -     Wire indices: ";
-    for(std::set<int>::const_iterator dw = deadWires.begin(); dw != deadWires.end(); ++dw) {
-        g_log.information() << *dw << " ";
-    }
-    g_log.information() << std::endl;
+    PoldiAbstractDetector_sptr detector = instrumentAdapter.detector();
+    boost::shared_ptr<PoldiDeadWireDecorator> cleanDetector(new PoldiDeadWireDecorator(localWorkspace->getInstrument(), detector));
 
+    // log configuration information
+    logConfigurationInformation(cleanDetector, chopper);
 
     // putting together POLDI instrument for calculations
     m_core->setInstrument(cleanDetector, chopper);
@@ -160,5 +108,41 @@ void PoldiAutoCorrelation5::exec()
 	}
 }
 
+void PoldiAutoCorrelation5::logConfigurationInformation(boost::shared_ptr<PoldiDeadWireDecorator> cleanDetector, PoldiAbstractChopper_sptr chopper)
+{
+    if(cleanDetector && chopper) {
+        g_log.information() << "____________________________________________________ "  << std::endl;
+        g_log.information() << "_Poldi  chopper conf ------------------------------  "  << std::endl;
+        g_log.information() << "_Poldi -     Chopper speed:   " << chopper->rotationSpeed() << " rpm" << std::endl;
+        g_log.information() << "_Poldi -     Number of slits: " << chopper->slitPositions().size() << std::endl;
+        g_log.information() << "_Poldi -     Cycle time:      " << chopper->cycleTime() << " µs" << std::endl;
+        g_log.information() << "_Poldi -     Zero offset:     " << chopper->zeroOffset() << " µs" << std::endl;
+        g_log.information() << "_Poldi -     Distance:        " << chopper->distanceFromSample()  << " mm" << std::endl;
+
+        if(g_log.is(Poco::Message::PRIO_DEBUG)) {
+            for(size_t i = 0; i < chopper->slitPositions().size(); ++i) {
+                g_log.information()   << "_Poldi -     Slits: " << i
+                                      << ": Position = " << chopper->slitPositions()[i]
+                                         << "\t Time = " << chopper->slitTimes()[i] << " µs" << std::endl;
+            }
+        }
+
+        g_log.information() << "_Poldi  detector conf ------------------------------  "  << std::endl;
+        g_log.information() << "_Poldi -     Element count:     " << cleanDetector->elementCount() << std::endl;
+        g_log.information() << "_Poldi -     Central element:   " << cleanDetector->centralElement() << std::endl;
+        g_log.information() << "_Poldi -     2Theta(central):   " << cleanDetector->twoTheta(199) / M_PI * 180.0 << "°" << std::endl;
+        g_log.information() << "_Poldi -     Distance(central): " << cleanDetector->distanceFromSample(199) << " mm" << std::endl;
+
+
+        std::set<int> deadWires = cleanDetector->deadWires();
+        g_log.information() << "_Poldi -     Number of dead wires: " << deadWires.size() << std::endl;
+        g_log.information() << "_Poldi -     Wire indices: ";
+        for(std::set<int>::const_iterator dw = deadWires.begin(); dw != deadWires.end(); ++dw) {
+            g_log.information() << *dw << " ";
+        }
+        g_log.information() << std::endl;
+    }
+}
+
 } // namespace Poldi
 } // namespace Mantid
diff --git a/Code/Mantid/Framework/SINQ/src/PoldiCalculateSpectrum2D.cpp b/Code/Mantid/Framework/SINQ/src/PoldiCalculateSpectrum2D.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..529c9dc08757d2ed592dcfab97b396a2da9e05e8
--- /dev/null
+++ b/Code/Mantid/Framework/SINQ/src/PoldiCalculateSpectrum2D.cpp
@@ -0,0 +1,363 @@
+/*WIKI*
+TODO: Enter a full wiki-markup description of your algorithm here. You can then use the Build/wiki_maker.py script to generate your full wiki page.
+*WIKI*/
+
+#include "MantidSINQ/PoldiCalculateSpectrum2D.h"
+
+#include "MantidDataObjects/Workspace2D.h"
+#include "MantidDataObjects/TableWorkspace.h"
+#include "MantidAPI/TableRow.h"
+#include "MantidAPI/FunctionFactory.h"
+#include "MantidAPI/MultiDomainFunction.h"
+#include "MantidSINQ/PoldiUtilities/PoldiSpectrumDomainFunction.h"
+
+#include "MantidSINQ/PoldiUtilities/PoldiPeakCollection.h"
+#include "MantidSINQ/PoldiUtilities/PoldiInstrumentAdapter.h"
+#include "MantidSINQ/PoldiUtilities/PeakFunctionIntegrator.h"
+#include "MantidAPI/IPeakFunction.h"
+
+#include "MantidSINQ/PoldiUtilities/Poldi2DFunction.h"
+
+#include "boost/make_shared.hpp"
+
+namespace Mantid
+{
+namespace Poldi
+{
+  // Register the algorithm into the AlgorithmFactory
+  DECLARE_ALGORITHM(PoldiCalculateSpectrum2D)
+
+  using namespace API;
+  using namespace Kernel;
+  using namespace DataObjects;
+
+  /** Constructor
+   */
+  PoldiCalculateSpectrum2D::PoldiCalculateSpectrum2D():
+      Algorithm(),
+      m_timeTransformer(),
+      m_deltaT(0.0)
+  {
+  }
+
+  /** Destructor
+   */
+  PoldiCalculateSpectrum2D::~PoldiCalculateSpectrum2D()
+  {
+  }
+
+  /// Algorithm's name for identification. @see Algorithm::name
+  const std::string PoldiCalculateSpectrum2D::name() const { return "PoldiCalculateSpectrum2D";}
+
+  /// Algorithm's version for identification. @see Algorithm::version
+  int PoldiCalculateSpectrum2D::version() const { return 1;}
+
+  /// Algorithm's category for identification. @see Algorithm::category
+  const std::string PoldiCalculateSpectrum2D::category() const { return "SINQ\\Poldi\\PoldiSet";}
+
+  /// Very short algorithm summary. @see Algorith::summary
+  const std::string PoldiCalculateSpectrum2D::summary() const
+  {
+      return "Calculates a POLDI 2D-spectrum.";
+  }
+
+  /// Initialization of algorithm properties.
+  void PoldiCalculateSpectrum2D::init()
+  {
+    declareProperty(new WorkspaceProperty<MatrixWorkspace>("InputWorkspace","",Direction::Input), "Measured POLDI 2D-spectrum.");
+    declareProperty(new WorkspaceProperty<TableWorkspace>("PoldiPeakWorkspace", "", Direction::Input), "Table workspace with peak information.");
+    declareProperty("PeakProfileFunction", "", "Profile function to use for integrating the peak profiles before calculating the spectrum.");
+    declareProperty(new WorkspaceProperty<MatrixWorkspace>("OutputWorkspace","",Direction::Output), "Calculated POLDI 2D-spectrum");
+  }
+
+  /**
+   * Constructs a proper function from a peak collection
+   *
+   * This method constructs a Poldi2DFunction and assigns one PoldiSpectrumDomainFunction to it for
+   * each peak contained in the peak collection.
+   *
+   * @param peakCollection :: PoldiPeakCollection containing peaks with integral intensities
+   * @return Poldi2DFunction with one PoldiSpectrumDomainFunction per peak
+   */
+  boost::shared_ptr<Poldi2DFunction> PoldiCalculateSpectrum2D::getFunctionFromPeakCollection(const PoldiPeakCollection_sptr &peakCollection) const
+  {
+      boost::shared_ptr<Poldi2DFunction> mdFunction(new Poldi2DFunction);
+
+      for(size_t i = 0; i < peakCollection->peakCount(); ++i) {
+          PoldiPeak_sptr peak = peakCollection->peak(i);
+
+          IFunction_sptr peakFunction = FunctionFactory::Instance().createFunction("PoldiSpectrumDomainFunction");
+          peakFunction->setParameter("Area", peak->intensity());
+          peakFunction->setParameter("Fwhm", peak->fwhm(PoldiPeak::AbsoluteD));
+          peakFunction->setParameter("Centre", peak->d());
+
+          mdFunction->addFunction(peakFunction);
+      }
+
+      return mdFunction;
+  }
+
+  /// Executes the algorithm
+  void PoldiCalculateSpectrum2D::exec()
+  {
+      TableWorkspace_sptr peakTable = getProperty("PoldiPeakWorkspace");
+      if(!peakTable) {
+          throw std::runtime_error("Cannot proceed without peak workspace.");
+      }
+
+      MatrixWorkspace_sptr ws = getProperty("InputWorkspace");
+      setDeltaTFromWorkspace(ws);
+
+      setTimeTransformerFromInstrument(boost::make_shared<PoldiInstrumentAdapter>(ws));
+
+      PoldiPeakCollection_sptr peakCollection = getPeakCollection(peakTable);
+
+      Property *profileFunctionProperty = getPointerToProperty("PeakProfileFunction");
+      if(!profileFunctionProperty->isDefault()) {
+          peakCollection->setProfileFunctionName(profileFunctionProperty->value());
+      }
+
+      setProperty("OutputWorkspace", calculateSpectrum(peakCollection, ws));
+  }
+
+  /**
+   * Calculates the 2D spectrum in a MatrixWorkspace
+   *
+   * In this method the actual function calculation is performed using Fit.
+   *
+   * @param peakCollection :: PoldiPeakCollection
+   * @param matrixWorkspace :: MatrixWorkspace with POLDI instrument and correct dimensions
+   * @return MatrixWorkspace with the calculated data
+   */
+  MatrixWorkspace_sptr PoldiCalculateSpectrum2D::calculateSpectrum(const PoldiPeakCollection_sptr &peakCollection, const MatrixWorkspace_sptr &matrixWorkspace)
+  {
+      PoldiPeakCollection_sptr integratedPeaks = getIntegratedPeakCollection(peakCollection);
+      PoldiPeakCollection_sptr normalizedPeakCollection = getNormalizedPeakCollection(integratedPeaks);
+
+      boost::shared_ptr<IFunction> mdFunction = getFunctionFromPeakCollection(normalizedPeakCollection);
+      IAlgorithm_sptr fit = createChildAlgorithm("Fit", -1, -1, true);
+
+      if(!fit) {
+          throw std::runtime_error("Could not initialize 'Fit'-algorithm.");
+      }
+
+      fit->setProperty("Function", boost::dynamic_pointer_cast<IFunction>(mdFunction));
+      fit->setProperty("InputWorkspace", matrixWorkspace);
+      fit->setProperty("CreateOutput", true);
+      fit->setProperty("MaxIterations", 0);
+      fit->setProperty("Minimizer", "Levenberg-MarquardtMD");
+
+      fit->execute();
+
+      MatrixWorkspace_sptr outputWs = fit->getProperty("OutputWorkspace");
+
+      return outputWs;
+  }
+
+  /**
+   * Constructs a PoldiTimeTransformer from given instrument and calls setTimeTransformer.
+   *
+   * @param poldiInstrument :: PoldiInstrumentAdapter with valid components
+   */
+  void PoldiCalculateSpectrum2D::setTimeTransformerFromInstrument(const PoldiInstrumentAdapter_sptr &poldiInstrument)
+  {
+      setTimeTransformer(boost::make_shared<PoldiTimeTransformer>(poldiInstrument));
+  }
+
+  /**
+   * Sets the time transformer object that is used for all calculations.
+   *
+   * @param poldiTimeTransformer
+   */
+  void PoldiCalculateSpectrum2D::setTimeTransformer(const PoldiTimeTransformer_sptr &poldiTimeTransformer)
+  {
+      m_timeTransformer = poldiTimeTransformer;
+  }
+
+  /**
+   * Extracts time bin width from workspace parameter
+   *
+   * The method uses the difference between first and second x-value of the first spectrum as
+   * time bin width. If the workspace does not contain proper data (0 spectra or less than
+   * 2 x-values), the method throws an std::invalid_argument-exception. Otherwise it calls setDeltaT.
+   *
+   * @param matrixWorkspace :: MatrixWorkspace with at least one spectrum with at least two x-values.
+   */
+  void PoldiCalculateSpectrum2D::setDeltaTFromWorkspace(const MatrixWorkspace_sptr &matrixWorkspace)
+  {
+      if(matrixWorkspace->getNumberHistograms() < 1) {
+          throw std::invalid_argument("MatrixWorkspace does not contain any data.");
+      }
+
+      MantidVec xData = matrixWorkspace->readX(0);
+
+      if(xData.size() < 2) {
+          throw std::invalid_argument("Cannot process MatrixWorkspace with less than 2 x-values.");
+      }
+
+      // difference between first and second x-value is assumed to be the bin width.
+      setDeltaT(matrixWorkspace->readX(0)[1] - matrixWorkspace->readX(0)[0]);
+  }
+
+  /**
+   * Assigns delta t, throws std::invalid_argument on invalid value (determined by isValidDeltaT).
+   *
+   * @param newDeltaT :: Value to be used as delta t for calculations.
+   */
+  void PoldiCalculateSpectrum2D::setDeltaT(double newDeltaT)
+  {
+      if(!isValidDeltaT(newDeltaT)) {
+          throw std::invalid_argument("Time bin size must be larger than 0.");
+      }
+
+      m_deltaT = newDeltaT;
+  }
+
+  /**
+   * Checks whether delta t is larger than 0.
+   *
+   * @param deltaT :: Value to be checked for validity as a time difference.
+   * @return True if delta t is larger than 0, otherwise false.
+   */
+  bool PoldiCalculateSpectrum2D::isValidDeltaT(double deltaT) const
+  {
+      return deltaT > 0.0;
+  }
+
+  /**
+   * Tries to construct a PoldiPeakCollection from the supplied table.
+   *
+   * @param peakTable :: TableWorkspace with POLDI peak data.
+   * @return PoldiPeakCollection with the data from the table workspace.
+   */
+  PoldiPeakCollection_sptr PoldiCalculateSpectrum2D::getPeakCollection(const TableWorkspace_sptr &peakTable) const
+  {
+      try {
+          return boost::make_shared<PoldiPeakCollection>(peakTable);
+      } catch(...) {
+          throw std::runtime_error("Could not initialize peak collection.");
+      }
+  }
+
+  /**
+   * Return peak collection with integrated peaks
+   *
+   * This method takes a PoldiPeakCollection where the intensity is represented by the maximum. Then
+   * it takes the profile function stored in the peak collection, which must be the name of a registered
+   * IPeakFunction-implementation. The parameters height and fwhm are assigned, centre is set to 0 to
+   * avoid problems with the parameter transformation for the integration from -inf to inf. The profiles are
+   * integrated using a PeakFunctionIntegrator to the precision of 1e-10.
+   *
+   * The original peak collection is not modified, a new instance is created.
+   *
+   * @param rawPeakCollection :: PoldiPeakCollection
+   * @return PoldiPeakCollection with integrated intensities
+   */
+  PoldiPeakCollection_sptr PoldiCalculateSpectrum2D::getIntegratedPeakCollection(const PoldiPeakCollection_sptr &rawPeakCollection) const
+  {
+      if(!rawPeakCollection) {
+          throw std::invalid_argument("Cannot proceed with invalid PoldiPeakCollection.");
+      }
+
+      if(!isValidDeltaT(m_deltaT)) {
+          throw std::invalid_argument("Cannot proceed with invalid time bin size.");
+      }
+
+      if(!m_timeTransformer) {
+          throw std::invalid_argument("Cannot proceed with invalid PoldiTimeTransformer.");
+      }
+
+      if(rawPeakCollection->intensityType() == PoldiPeakCollection::Integral) {
+          /* Intensities are integral already - don't need to do anything,
+           * except cloning the collection, to make behavior consistent, since
+           * integrating also results in a new peak collection.
+           */
+          return rawPeakCollection->clone();
+      }
+
+      /* If no profile function is specified, it's not possible to get integrated
+       * intensities at all and we need to abort at this point.
+       */
+      if(!rawPeakCollection->hasProfileFunctionName()) {
+          throw std::runtime_error("Cannot integrate peak profiles without profile function.");
+      }
+
+      PeakFunctionIntegrator peakIntegrator(1e-10);
+
+      PoldiPeakCollection_sptr integratedPeakCollection = boost::make_shared<PoldiPeakCollection>(PoldiPeakCollection::Integral);
+      integratedPeakCollection->setProfileFunctionName(rawPeakCollection->getProfileFunctionName());
+
+      for(size_t i = 0; i < rawPeakCollection->peakCount(); ++i) {
+          PoldiPeak_sptr peak = rawPeakCollection->peak(i);
+
+          /* The integration is performed in time dimension,
+           * so the fwhm needs to be transformed.
+           */
+          double fwhmTime = m_timeTransformer->dToTOF(peak->fwhm(PoldiPeak::AbsoluteD));
+
+          IPeakFunction_sptr profileFunction = boost::dynamic_pointer_cast<IPeakFunction>(FunctionFactory::Instance().createFunction(rawPeakCollection->getProfileFunctionName()));
+          profileFunction->setHeight(peak->intensity());
+          profileFunction->setFwhm(fwhmTime);
+
+          /* Because the integration is running from -inf to inf, it is necessary
+           * to set the centre to 0. Otherwise the transformation performed by
+           * the integration routine will create problems.
+           */
+          profileFunction->setCentre(0.0);
+
+          IntegrationResult integration = peakIntegrator.integrateInfinity(profileFunction);
+
+          if(!integration.success) {
+              throw std::runtime_error("Problem during peak integration. Aborting.");
+          }
+
+          PoldiPeak_sptr integratedPeak = peak->clone();
+          /* Integration is performed in the time domain and later everything is normalized
+           * by deltaT. In the original code this is done at this point, so this behavior is kept
+           * for now.
+           */
+          integratedPeak->setIntensity(UncertainValue(integration.result / m_deltaT));
+          integratedPeakCollection->addPeak(integratedPeak);
+      }
+
+      return integratedPeakCollection;
+  }
+
+  /**
+   * Normalized the intensities of the given integrated peaks
+   *
+   * This function normalizes the peak intensities according to the source spectrum, the number of
+   * chopper slits and the number of detector elements.
+   *
+   * @param peakCollection :: PoldiPeakCollection with integrated intensities
+   * @return PoldiPeakCollection with normalized intensities
+   */
+  PoldiPeakCollection_sptr PoldiCalculateSpectrum2D::getNormalizedPeakCollection(const PoldiPeakCollection_sptr &peakCollection) const
+  {
+      if(!peakCollection) {
+          throw std::invalid_argument("Cannot proceed with invalid PoldiPeakCollection.");
+      }
+
+      if(!m_timeTransformer) {
+          throw std::invalid_argument("Cannot proceed without PoldiTimeTransformer.");
+      }
+
+      PoldiPeakCollection_sptr normalizedPeakCollection = boost::make_shared<PoldiPeakCollection>(PoldiPeakCollection::Integral);
+      normalizedPeakCollection->setProfileFunctionName(peakCollection->getProfileFunctionName());
+
+      for(size_t i = 0; i < peakCollection->peakCount(); ++i) {
+          PoldiPeak_sptr peak = peakCollection->peak(i);
+          double calculatedIntensity = m_timeTransformer->calculatedTotalIntensity(peak->d());
+
+          PoldiPeak_sptr normalizedPeak = peak->clone();
+          normalizedPeak->setIntensity(peak->intensity() / calculatedIntensity);
+
+          normalizedPeakCollection->addPeak(normalizedPeak);
+      }
+
+      return normalizedPeakCollection;
+  }
+
+
+} // namespace Poldi
+} // namespace Mantid
diff --git a/Code/Mantid/Framework/SINQ/src/PoldiFitPeaks1D.cpp b/Code/Mantid/Framework/SINQ/src/PoldiFitPeaks1D.cpp
index 88391cc32c0a59dd5a92df2f02c2dd2fe384b05b..cd8bf265e42ed67fe3464ca3af1f1913a39e767d 100644
--- a/Code/Mantid/Framework/SINQ/src/PoldiFitPeaks1D.cpp
+++ b/Code/Mantid/Framework/SINQ/src/PoldiFitPeaks1D.cpp
@@ -85,7 +85,10 @@ void PoldiFitPeaks1D::setPeakFunction(std::string peakFunction)
 
 PoldiPeakCollection_sptr PoldiFitPeaks1D::getInitializedPeakCollection(TableWorkspace_sptr peakTable)
 {
-    return PoldiPeakCollection_sptr(new PoldiPeakCollection(peakTable));
+    PoldiPeakCollection_sptr peakCollection(new PoldiPeakCollection(peakTable));
+    peakCollection->setProfileFunctionName(m_profileTemplate);
+
+    return peakCollection;
 }
 
 IFunction_sptr PoldiFitPeaks1D::getPeakProfile(PoldiPeak_sptr poldiPeak) {
diff --git a/Code/Mantid/Framework/SINQ/src/PoldiPeakSearch.cpp b/Code/Mantid/Framework/SINQ/src/PoldiPeakSearch.cpp
index 1999ec737e5b506834c685e98fefb3964eb6d351..c1056e460351cd02d1e6a7f922d929567b9e96b4 100644
--- a/Code/Mantid/Framework/SINQ/src/PoldiPeakSearch.cpp
+++ b/Code/Mantid/Framework/SINQ/src/PoldiPeakSearch.cpp
@@ -41,6 +41,7 @@ PoldiPeakSearch::PoldiPeakSearch() :
     m_maximumPeakNumber(0),
     m_recursionAbsoluteBegin(),
     m_recursionAbsoluteEnd(),
+    m_recursionBordersInitialized(false),
     m_peaks(new PoldiPeakCollection())
 {
 }
@@ -171,7 +172,7 @@ MantidVec::const_iterator PoldiPeakSearch::getLeftRangeBegin(MantidVec::const_it
      *
      * Exactly the same considerations are valid for the rightmost sublist.
      */
-    if(begin != m_recursionAbsoluteBegin) {
+    if(!m_recursionBordersInitialized || begin != m_recursionAbsoluteBegin) {
         return begin + m_minimumDistance;
     }
 
@@ -188,7 +189,7 @@ MantidVec::const_iterator PoldiPeakSearch::getLeftRangeBegin(MantidVec::const_it
   */
 MantidVec::const_iterator PoldiPeakSearch::getRightRangeEnd(MantidVec::const_iterator end) const
 {
-    if(end != m_recursionAbsoluteEnd) {
+    if(!m_recursionBordersInitialized || end != m_recursionAbsoluteEnd) {
         return end - m_minimumDistance;
     }
 
@@ -477,6 +478,8 @@ void PoldiPeakSearch::setRecursionAbsoluteBorders(MantidVec::const_iterator begi
 {
     m_recursionAbsoluteBegin = begin;
     m_recursionAbsoluteEnd = end;
+
+    m_recursionBordersInitialized = true;
 }
 
 bool PoldiPeakSearch::vectorElementGreaterThan(MantidVec::const_iterator first, MantidVec::const_iterator second)
diff --git a/Code/Mantid/Framework/SINQ/src/PoldiUtilities/MillerIndices.cpp b/Code/Mantid/Framework/SINQ/src/PoldiUtilities/MillerIndices.cpp
index 7e8249ea8f4a6db3080b34ee2ab6c24225e27905..bf9c92fac11dfcca5ad42e8293d216c876b24ae5 100644
--- a/Code/Mantid/Framework/SINQ/src/PoldiUtilities/MillerIndices.cpp
+++ b/Code/Mantid/Framework/SINQ/src/PoldiUtilities/MillerIndices.cpp
@@ -51,6 +51,11 @@ int MillerIndices::operator [](int index)
     return m_asVector[index];
 }
 
+bool MillerIndices::operator ==(MillerIndices &other) const
+{
+    return m_h == other.m_h && m_k == other.m_k && m_l == other.m_l;
+}
+
 const std::vector<int> &MillerIndices::asVector() const
 {
     return m_asVector;
diff --git a/Code/Mantid/Framework/SINQ/src/PoldiUtilities/PeakFunctionIntegrator.cpp b/Code/Mantid/Framework/SINQ/src/PoldiUtilities/PeakFunctionIntegrator.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..70d19838f4716e338c0bfdf59923ec54fed5aa3f
--- /dev/null
+++ b/Code/Mantid/Framework/SINQ/src/PoldiUtilities/PeakFunctionIntegrator.cpp
@@ -0,0 +1,175 @@
+#include "MantidSINQ/PoldiUtilities/PeakFunctionIntegrator.h"
+
+#include "MantidAPI/FunctionDomain1D.h"
+#include "gsl/gsl_errno.h"
+#include <iostream>
+#include <iomanip>
+
+namespace Mantid {
+namespace Poldi {
+
+using namespace API;
+
+/** Constructor with required relative precision argument. The default is 1e-8.
+ *  See also PeakFunctionIntegrator::setRequiredRelativePrecision.
+ *
+ * @param requiredRelativePrecision :: Desired relative precision of the integral estimations.
+ */
+PeakFunctionIntegrator::PeakFunctionIntegrator(double requiredRelativePrecision) :
+    m_integrationWorkspace(gsl_integration_workspace_alloc(1000)),
+    m_relativePrecision(requiredRelativePrecision)
+{
+    /* Error handling is disabled, so error-codes are associated to the integration result
+     * and have to be checked.
+     */
+    gsl_set_error_handler_off();
+}
+
+PeakFunctionIntegrator::~PeakFunctionIntegrator()
+{
+    gsl_integration_workspace_free(m_integrationWorkspace);
+}
+
+/** This method sets the desired numerical relative precision that's passed on to the
+ *  GSL integration-routines.
+ *
+ *  @param newPrecision :: Desired relative precision for integrations.
+ */
+void PeakFunctionIntegrator::setRequiredRelativePrecision(double newPrecision)
+{
+    m_relativePrecision = newPrecision;
+}
+
+/** Returns the currently set precision
+ */
+double PeakFunctionIntegrator::requiredRelativePrecision() const
+{
+    return m_relativePrecision;
+}
+
+/** Integration of peak function on the interval [-Inf, +Inf]. Internally, gsl_integration_qagi is used
+ *  for this. If a default constructed IPeakFunction_const_sptr is passed to the function, std::invalid_argument is thrown.
+ *  The results are returned as IntegrationResult-struct, which contains the approximation of the integral along
+ *  with other information such as an error estimate (absolute).
+ *
+ *  @param peakFunction :: Peak function to integrate.
+ */
+IntegrationResult PeakFunctionIntegrator::integrateInfinity(IPeakFunction_const_sptr peakFunction) const
+{
+    throwIfInvalid(peakFunction);
+
+    IntegrationResult result;
+
+    gsl_function f = getGSLFunction(peakFunction);
+
+    result.errorCode = gsl_integration_qagi(&f, 0, m_relativePrecision, 1000, m_integrationWorkspace, &result.result, &result.error);
+    result.success = (result.errorCode == GSL_SUCCESS);
+    result.intervals = m_integrationWorkspace->size;
+
+    return result;
+}
+
+/** Integration of peak function on the interval [a, +Inf]. Internally, gsl_integration_qagiu is used
+ *  for this. If a default constructed IPeakFunction_const_sptr is passed to the function, std::invalid_argument is thrown.
+ *
+ *  @param peakFunction :: Peak function to integrate.
+ */
+IntegrationResult PeakFunctionIntegrator::integratePositiveInfinity(IPeakFunction_const_sptr peakFunction, double lowerLimit) const
+{
+    throwIfInvalid(peakFunction);
+
+    IntegrationResult result;
+
+    gsl_function f = getGSLFunction(peakFunction);
+
+    result.errorCode = gsl_integration_qagiu(&f, lowerLimit, 0, m_relativePrecision, 1000, m_integrationWorkspace, &result.result, &result.error);
+    result.success = (result.errorCode == GSL_SUCCESS);
+    result.intervals = m_integrationWorkspace->size;
+
+    return result;
+}
+
+/** Integration of peak function on the interval [-Inf, b]. Internally, gsl_integration_qagil is used
+ *  for this. If a default constructed IPeakFunction_const_sptr is passed to the function, std::invalid_argument is thrown.
+ *
+ *  @param peakFunction :: Peak function to integrate.
+ */
+IntegrationResult PeakFunctionIntegrator::integrateNegativeInfinity(IPeakFunction_const_sptr peakFunction, double upperLimit) const
+{
+    throwIfInvalid(peakFunction);
+
+    IntegrationResult result;
+
+    gsl_function f = getGSLFunction(peakFunction);
+
+    result.errorCode = gsl_integration_qagil(&f, upperLimit, 0, m_relativePrecision, 1000, m_integrationWorkspace, &result.result, &result.error);
+    result.success = (result.errorCode == GSL_SUCCESS);
+    result.intervals = m_integrationWorkspace->size;
+
+    return result;
+}
+
+/** Integration of peak function on the interval [a, b]. Internally, gsl_integration_qags is used
+ *  for this. If a default constructed IPeakFunction_const_sptr is passed to the function, std::invalid_argument is thrown.
+ *
+ *  @param peakFunction :: Peak function to integrate.
+ */
+IntegrationResult PeakFunctionIntegrator::integrate(IPeakFunction_const_sptr peakFunction, double lowerLimit, double upperLimit) const
+{
+    throwIfInvalid(peakFunction);
+
+    IntegrationResult result;
+
+    gsl_function f = getGSLFunction(peakFunction);
+
+    result.errorCode = gsl_integration_qags(&f, lowerLimit, upperLimit, 0, m_relativePrecision, 1000, m_integrationWorkspace, &result.result, &result.error);
+    result.success = (result.errorCode == GSL_SUCCESS);
+    result.intervals = m_integrationWorkspace->size;
+
+    return result;
+}
+
+/** Method that wraps an IPeakFunction for use with GSL functions.
+ *
+ *  @param peakFunction :: Peak function to wrap.
+ */
+gsl_function PeakFunctionIntegrator::getGSLFunction(IPeakFunction_const_sptr peakFunction) const
+{
+    gsl_function f;
+    f.function = &Mantid::Poldi::gsl_peak_wrapper;
+    f.params = &peakFunction;
+
+    return f;
+}
+
+void PeakFunctionIntegrator::throwIfInvalid(IPeakFunction_const_sptr peakFunction) const
+{
+    if(!peakFunction) {
+        throw std::invalid_argument("Can not integrate NULL-function.");
+    }
+}
+
+double gsl_peak_wrapper(double x, void *parameters)
+{
+    IPeakFunction_const_sptr peakFunction = *(IPeakFunction_const_sptr *) parameters;
+
+    double y;
+
+    /* For the integration to work properly, functionLocal has to be used instead
+     * of the more general function-method due to the fact that the overriden function-method
+     * in IPeakFunction cuts off at some point. For slowly decaying peak functions
+     * such as Lorentzians, this is introduces large deviations for integrations
+     * from -Inf to +Inf.
+     */
+    peakFunction->functionLocal(&y, &x, 1);
+
+    return y;
+}
+
+
+
+}
+
+
+
+}
diff --git a/Code/Mantid/Framework/SINQ/src/PoldiUtilities/Poldi2DFunction.cpp b/Code/Mantid/Framework/SINQ/src/PoldiUtilities/Poldi2DFunction.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..8e88050e60fd7687683db89fd90968246540d7f7
--- /dev/null
+++ b/Code/Mantid/Framework/SINQ/src/PoldiUtilities/Poldi2DFunction.cpp
@@ -0,0 +1,61 @@
+#include "MantidSINQ/PoldiUtilities/Poldi2DFunction.h"
+
+namespace Mantid
+{
+namespace Poldi
+{
+using namespace API;
+
+Poldi2DFunction::Poldi2DFunction() :
+    IFunction1DSpectrum(),
+    CompositeFunction()
+{
+}
+
+/**
+ * Calculates function values for domain. In contrast to CompositeFunction, the summation
+ * of values is performed in a different way: The values are set to zero once at the beginning,
+ * then it is expected of the member functions to use FunctionValues::addToCalculated or add
+ * their values otherwise, without erasing the values.
+ *
+ * @param domain :: Function domain which is passed on to the member functions.
+ * @param values :: Function values.
+ */
+void Poldi2DFunction::function(const FunctionDomain &domain, FunctionValues &values) const
+{
+    values.zeroCalculated();
+
+    for(size_t i = 0; i < nFunctions(); ++i)
+    {
+      getFunction(i)->function(domain, values);
+    }
+}
+
+/**
+ * Calculates function derivatives. Simply calls CompositeFunction::functionDeriv
+ *
+ * @param domain :: Function domain which is passed on to the member functions.
+ * @param jacobian :: Jacobian.
+ */
+void Poldi2DFunction::functionDeriv(const FunctionDomain &domain, Jacobian &jacobian)
+{
+    CompositeFunction::functionDeriv(domain, jacobian);
+}
+
+/**
+ * Empty implementation of IFunction1DSpectrum::function1DSpectrum which must be present to
+ * completely implement the interface.
+ *
+ * @param domain :: Unused domain.
+ * @param values :: Unused function values.
+ */
+void Poldi2DFunction::function1DSpectrum(const FunctionDomain1DSpectrum &domain, FunctionValues &values) const
+{
+    UNUSED_ARG(domain);
+    UNUSED_ARG(values);
+}
+
+
+
+} // namespace Poldi
+} // namespace Mantid
diff --git a/Code/Mantid/Framework/SINQ/src/PoldiUtilities/PoldiAutoCorrelationCore.cpp b/Code/Mantid/Framework/SINQ/src/PoldiUtilities/PoldiAutoCorrelationCore.cpp
index dd7c0b464d210d8a33b75cab0ddebc6d397e949f..25a788f84cb7cdca31818b504bedceb513d1b0f1 100644
--- a/Code/Mantid/Framework/SINQ/src/PoldiUtilities/PoldiAutoCorrelationCore.cpp
+++ b/Code/Mantid/Framework/SINQ/src/PoldiUtilities/PoldiAutoCorrelationCore.cpp
@@ -23,6 +23,7 @@ PoldiAutoCorrelationCore::PoldiAutoCorrelationCore(Kernel::Logger &g_log) :
     m_chopper(),
     m_wavelengthRange(),
     m_deltaT(),
+    m_deltaD(),
     m_timeBinCount(),
     m_detectorElements(),
     m_weightsForD(),
diff --git a/Code/Mantid/Framework/SINQ/src/PoldiUtilities/PoldiDetectorDecorator.cpp b/Code/Mantid/Framework/SINQ/src/PoldiUtilities/PoldiDetectorDecorator.cpp
index 92240804c2904f19f369a4703baee48eb7bdd92f..1e34abb150429c0c7dd417416e5274f80f05f696 100644
--- a/Code/Mantid/Framework/SINQ/src/PoldiUtilities/PoldiDetectorDecorator.cpp
+++ b/Code/Mantid/Framework/SINQ/src/PoldiUtilities/PoldiDetectorDecorator.cpp
@@ -31,6 +31,15 @@ void PoldiDetectorDecorator::loadConfiguration(Instrument_const_sptr poldiInstru
     UNUSED_ARG(poldiInstrument)
 }
 
+double PoldiDetectorDecorator::efficiency()
+{
+    if(m_decoratedDetector) {
+        return m_decoratedDetector->efficiency();
+    } else {
+        throw std::runtime_error("No detector decorated!");
+    }
+}
+
 double PoldiDetectorDecorator::twoTheta(int elementIndex)
 {
     if(m_decoratedDetector) {
diff --git a/Code/Mantid/Framework/SINQ/src/PoldiUtilities/PoldiHeliumDetector.cpp b/Code/Mantid/Framework/SINQ/src/PoldiUtilities/PoldiHeliumDetector.cpp
index fc7a61fe8c0ff5450088a6920988a60a361af8db..473616a590ac2c63016d809116f4550793de41b6 100644
--- a/Code/Mantid/Framework/SINQ/src/PoldiUtilities/PoldiHeliumDetector.cpp
+++ b/Code/Mantid/Framework/SINQ/src/PoldiUtilities/PoldiHeliumDetector.cpp
@@ -19,6 +19,7 @@ PoldiHeliumDetector::PoldiHeliumDetector() :
     m_angularResolution(0.0),
     m_totalOpeningAngle(0.0),
     m_availableElements(),
+    m_efficiency(0.0),
     m_calibratedPosition(0.0, 0.0),
     m_vectorAngle(0.0),
     m_distanceFromSample(0.0),
@@ -33,13 +34,20 @@ void PoldiHeliumDetector::loadConfiguration(Instrument_const_sptr poldiInstrumen
     IComponent_const_sptr detector = poldiInstrument->getComponentByName("detector");
     double radius = detector->getNumberParameter("radius").front() * 1000.0;
     double elementWidth = detector->getNumberParameter("element_separation").front() * 1000.0;
-    initializeFixedParameters(radius, poldiInstrument->getNumberDetectors(), elementWidth);
+    double newEfficiency = detector->getNumberParameter("efficiency").front();
+
+    initializeFixedParameters(radius, poldiInstrument->getNumberDetectors(), elementWidth, newEfficiency);
 
     Kernel::V3D pos = detector->getPos() * 1000.0;
     double twoTheta = Conversions::degToRad(detector->getNumberParameter("two_theta").front());
     initializeCalibratedParameters(Kernel::V2D(pos.X(), pos.Y()), twoTheta);
 }
 
+double PoldiHeliumDetector::efficiency()
+{
+    return m_efficiency;
+}
+
 double PoldiHeliumDetector::twoTheta(int elementIndex)
 {
     double phiForElement = phi(elementIndex);
@@ -83,8 +91,9 @@ double PoldiHeliumDetector::phi(double twoTheta)
     return twoTheta - asin(m_distanceFromSample / m_radius * sin(M_PI + m_vectorAngle - twoTheta));
 }
 
-void PoldiHeliumDetector::initializeFixedParameters(double radius, size_t elementCount, double elementWidth)
+void PoldiHeliumDetector::initializeFixedParameters(double radius, size_t elementCount, double elementWidth, double newEfficiency)
 {
+    m_efficiency = newEfficiency;
     m_radius = radius;
     m_elementCount = elementCount;
     m_centralElement = (elementCount - 1) / 2;
diff --git a/Code/Mantid/Framework/SINQ/src/PoldiUtilities/PoldiInstrumentAdapter.cpp b/Code/Mantid/Framework/SINQ/src/PoldiUtilities/PoldiInstrumentAdapter.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..ed6c3234dbe58093201e288225adc4b32c36d575
--- /dev/null
+++ b/Code/Mantid/Framework/SINQ/src/PoldiUtilities/PoldiInstrumentAdapter.cpp
@@ -0,0 +1,192 @@
+#include "MantidSINQ/PoldiUtilities/PoldiInstrumentAdapter.h"
+
+#include "MantidSINQ/PoldiUtilities/PoldiDetectorFactory.h"
+#include "MantidSINQ/PoldiUtilities/PoldiChopperFactory.h"
+#include "MantidSINQ/PoldiUtilities/PoldiSourceSpectrum.h"
+
+#include "boost/assign.hpp"
+#include "boost/make_shared.hpp"
+
+namespace Mantid
+{
+namespace Poldi
+{
+using namespace Mantid::Geometry;
+using namespace Mantid::API;
+
+// Initializing static variables for DoubleValueExtractors
+const std::string PoldiInstrumentAdapter::m_chopperSpeedPropertyName = "chopperspeed";
+
+std::map<std::string, AbstractDoubleValueExtractor_sptr> PoldiInstrumentAdapter::m_extractors =
+        boost::assign::map_list_of
+        ("dbl list", boost::static_pointer_cast<AbstractDoubleValueExtractor>(boost::make_shared<VectorDoubleValueExtractor>(PoldiInstrumentAdapter::m_chopperSpeedPropertyName)))
+        ("number", boost::static_pointer_cast<AbstractDoubleValueExtractor>(boost::make_shared<NumberDoubleValueExtractor>(PoldiInstrumentAdapter::m_chopperSpeedPropertyName)));
+
+/** Constructor with workspace argument
+  *
+  * This constructor directly takes a matrix workspace and extracts instrument and run information.
+  *
+  * @param matrixWorkspace :: Workspace with a valid POLDI instrument and run information
+  */
+PoldiInstrumentAdapter::PoldiInstrumentAdapter(const MatrixWorkspace_const_sptr &matrixWorkspace)
+{
+    initializeFromInstrumentAndRun(matrixWorkspace->getInstrument(), matrixWorkspace->run());
+}
+
+/** Constructor with instrument and run information arguments
+  *
+  * This constructor internall calls PoldiInstrumentAdapter::initializeFromInstrumentAndRun.
+  *
+  * @param mantidInstrument :: Const shared pointer to Mantid::Geometry::Instrument
+  * @param runInformation :: Const Reference to Mantid::API::Run object
+  */
+PoldiInstrumentAdapter::PoldiInstrumentAdapter(const Instrument_const_sptr &mantidInstrument, const Run &runInformation)
+{
+    initializeFromInstrumentAndRun(mantidInstrument, runInformation);
+}
+
+PoldiInstrumentAdapter::~PoldiInstrumentAdapter()
+{
+}
+
+/** Returns the chopper stored in the adapter
+  *
+  * @return Abstract chopper, configured according to instrument and run (chopperspeed).
+  */
+PoldiAbstractChopper_sptr PoldiInstrumentAdapter::chopper() const
+{
+    return m_chopper;
+}
+
+/** Returns the detector stored in the adapter
+  *
+  * @return Abstract detector, configured with the data in instrument.
+  */
+PoldiAbstractDetector_sptr PoldiInstrumentAdapter::detector() const
+{
+    return m_detector;
+}
+
+/** Returns the spectrum stored in the adapter
+  *
+  * @return PoldiSourceSpectrum, as given in the insturment configuration.
+  */
+PoldiSourceSpectrum_sptr PoldiInstrumentAdapter::spectrum() const
+{
+    return m_spectrum;
+}
+
+/** Initializes object from POLDI instrument definition and run information
+  *
+  * With the Instrument and Run data provided in the arguments, the resulting POLDI utility objects are
+  * created. Currently this is a detector, a chopper and the neutron source spectrum.
+  * When a NULL-instrument pointer is passed in, or the chopperspeed-property is not present in the
+  * experiment log, std::runtime_error is thrown.
+  *
+  * @param mantidInstrument :: Const shared pointer to Mantid::Geometry::Instrument
+  * @param runInformation :: Const Reference to Mantid::API::Run object
+  */
+void PoldiInstrumentAdapter::initializeFromInstrumentAndRun(const Instrument_const_sptr &mantidInstrument, const Run &runInformation)
+{
+    if(!mantidInstrument) {
+        throw std::runtime_error("Can not construct POLDI classes from invalid instrument. Aborting.");
+    }
+
+    setDetector(mantidInstrument);
+    setChopper(mantidInstrument, runInformation);
+    setSpectrum(mantidInstrument);
+}
+
+/** Constructs a detector and stores it
+  *
+  * A PoldiAbstractDetector is constructed through PoldiDetectorFactory. Currently, the He3-detector
+  * is hard-coded at this place, but as soon as the new detector is available and tests
+  * have been performed, this will be changed.
+  *
+  * @param mantidInstrument :: Mantid instrument with POLDI detector setup data.
+  */
+void PoldiInstrumentAdapter::setDetector(const Instrument_const_sptr &mantidInstrument)
+{
+    PoldiDetectorFactory detectorFactory;
+    m_detector = PoldiAbstractDetector_sptr(detectorFactory.createDetector(std::string("helium3-detector")));
+    m_detector->loadConfiguration(mantidInstrument);
+}
+
+/** Constructs a chopper and stores it
+  *
+  * A PoldiAbstractChopper is constructed by PoldiChopperFactory. The configuration is taken
+  * from the passed instrument and the run information (for the chopper speed).
+  *
+  * @param mantidInstrument :: Mantid instrument with POLDI chopper information.
+  * @param runInformation :: Run information that contains a "chopperspeed" property.
+  */
+void PoldiInstrumentAdapter::setChopper(const Instrument_const_sptr &mantidInstrument, const Run &runInformation)
+{
+    double chopperSpeed = getChopperSpeedFromRun(runInformation);
+
+    PoldiChopperFactory chopperFactory;
+    m_chopper = PoldiAbstractChopper_sptr(chopperFactory.createChopper(std::string("default-chopper")));
+    m_chopper->loadConfiguration(mantidInstrument);
+    m_chopper->setRotationSpeed(chopperSpeed);
+}
+
+/**
+ * Extracts the chopper speed from run information
+ *
+ * This method tries to extract the chopper rotation speed from the run information, using
+ * an appropriate functor of type AbstractDoubleValueExtractor.
+ *
+ * @param runInformation :: Run information that contains a "chopperspeed" property
+ * @return Chopper speed as stored in run information
+ */
+double PoldiInstrumentAdapter::getChopperSpeedFromRun(const Run &runInformation)
+{
+    if(!runInformation.hasProperty(m_chopperSpeedPropertyName)) {
+        throw std::runtime_error("Cannot construct instrument without " + m_chopperSpeedPropertyName + "property in log. Aborting.");
+    }
+
+    Kernel::Property *chopperSpeedProperty = runInformation.getProperty(m_chopperSpeedPropertyName);
+
+    AbstractDoubleValueExtractor_sptr extractor = getExtractorForProperty(chopperSpeedProperty);
+
+    if(!extractor) {
+        throw std::invalid_argument("Cannot extract chopper speed from run information.");
+    }
+
+    return (*extractor)(runInformation);
+}
+
+/**
+ * Returns appropriate extractor for supplied property
+ *
+ * This method checks the property's type and gets the appropriate functor to extract the value.
+ * If a null pointer is supplied, the method throws an std::runtime_error exception.
+ *
+ * @param chopperSpeedProperty :: Property containing the chopper speed
+ * @return Functor of type AbstractDoubleValueExtractor
+ */
+AbstractDoubleValueExtractor_sptr PoldiInstrumentAdapter::getExtractorForProperty(Kernel::Property *chopperSpeedProperty)
+{
+    if(!chopperSpeedProperty) {
+        throw std::invalid_argument("Cannot process null-Property.");
+    }
+
+    std::string propertyType = chopperSpeedProperty->type();
+
+    return m_extractors[propertyType];
+}
+
+/** Constructs a spectrum and stores it
+  *
+  * This method constructs a PoldiSourceSpectrum object with the spectrum data provided
+  * by the instrument.
+  *
+  * @param mantidInstrument :: Mantid instrument containing a lookup table with a neutron wavelength spectrum.
+  */
+void PoldiInstrumentAdapter::setSpectrum(const Instrument_const_sptr &mantidInstrument)
+{
+    m_spectrum = boost::make_shared<PoldiSourceSpectrum>(mantidInstrument);
+}
+
+} // namespace Poldi
+} // namespace Mantid
diff --git a/Code/Mantid/Framework/SINQ/src/PoldiUtilities/PoldiPeak.cpp b/Code/Mantid/Framework/SINQ/src/PoldiUtilities/PoldiPeak.cpp
index 21aa31ea42ebfbb28cfa3f1babf36e21f0a03a38..0ddbd14d0fc09b13f08ff3d3cba66b9f55c496c6 100644
--- a/Code/Mantid/Framework/SINQ/src/PoldiUtilities/PoldiPeak.cpp
+++ b/Code/Mantid/Framework/SINQ/src/PoldiUtilities/PoldiPeak.cpp
@@ -7,6 +7,11 @@
 namespace Mantid {
 namespace Poldi {
 
+PoldiPeak_sptr PoldiPeak::clone() const
+{
+    return PoldiPeak_sptr(new PoldiPeak(*this));
+}
+
 const MillerIndices &PoldiPeak::hkl() const
 {
     return m_hkl;
diff --git a/Code/Mantid/Framework/SINQ/src/PoldiUtilities/PoldiPeakCollection.cpp b/Code/Mantid/Framework/SINQ/src/PoldiUtilities/PoldiPeakCollection.cpp
index c65b9ea413df5411d2d6eeb63c43e809b14bb69f..9b48113d823915ec448fab2912b590f5c19de87e 100644
--- a/Code/Mantid/Framework/SINQ/src/PoldiUtilities/PoldiPeakCollection.cpp
+++ b/Code/Mantid/Framework/SINQ/src/PoldiUtilities/PoldiPeakCollection.cpp
@@ -1,6 +1,7 @@
 #include "MantidSINQ/PoldiUtilities/PoldiPeakCollection.h"
 #include "MantidAPI/TableRow.h"
 #include "MantidAPI/WorkspaceFactory.h"
+#include "MantidAPI/LogManager.h"
 #include "boost/format.hpp"
 #include "boost/algorithm/string/join.hpp"
 
@@ -13,25 +14,41 @@ namespace Poldi {
 using namespace Mantid::API;
 using namespace Mantid::DataObjects;
 
-PoldiPeakCollection::PoldiPeakCollection() :
-    m_peaks()
+PoldiPeakCollection::PoldiPeakCollection(IntensityType intensityType) :
+    m_peaks(),
+    m_intensityType(intensityType),
+    m_profileFunctionName()
 {
 }
 
-PoldiPeakCollection::PoldiPeakCollection(TableWorkspace_sptr workspace) :
-    m_peaks()
+PoldiPeakCollection::PoldiPeakCollection(const TableWorkspace_sptr &workspace) :
+    m_peaks(),
+    m_intensityType(Maximum),
+    m_profileFunctionName()
 {
     if(workspace) {
         constructFromTableWorkspace(workspace);
     }
 }
 
+PoldiPeakCollection_sptr PoldiPeakCollection::clone()
+{
+    PoldiPeakCollection_sptr clone = boost::make_shared<PoldiPeakCollection>(m_intensityType);
+    clone->setProfileFunctionName(m_profileFunctionName);
+
+    for(size_t i = 0; i < m_peaks.size(); ++i) {
+        clone->addPeak(m_peaks[i]->clone());
+    }
+
+    return clone;
+}
+
 size_t PoldiPeakCollection::peakCount() const
 {
     return m_peaks.size();
 }
 
-void PoldiPeakCollection::addPeak(PoldiPeak_sptr newPeak)
+void PoldiPeakCollection::addPeak(const PoldiPeak_sptr &newPeak)
 {
     m_peaks.push_back(newPeak);
 }
@@ -45,17 +62,38 @@ PoldiPeak_sptr PoldiPeakCollection::peak(size_t index) const
     return m_peaks[index];
 }
 
+PoldiPeakCollection::IntensityType PoldiPeakCollection::intensityType() const
+{
+    return m_intensityType;
+}
+
+void PoldiPeakCollection::setProfileFunctionName(std::string newProfileFunction)
+{
+    m_profileFunctionName = newProfileFunction;
+}
+
+std::string PoldiPeakCollection::getProfileFunctionName() const
+{
+    return m_profileFunctionName;
+}
+
+bool PoldiPeakCollection::hasProfileFunctionName() const
+{
+    return !m_profileFunctionName.empty();
+}
+
 TableWorkspace_sptr PoldiPeakCollection::asTableWorkspace()
 {
     TableWorkspace_sptr peaks = boost::dynamic_pointer_cast<TableWorkspace>(WorkspaceFactory::Instance().createTable());
 
     prepareTable(peaks);
+    dataToTableLog(peaks);
     peaksToTable(peaks);
 
     return peaks;
 }
 
-void PoldiPeakCollection::prepareTable(TableWorkspace_sptr table)
+void PoldiPeakCollection::prepareTable(const TableWorkspace_sptr &table)
 {
     table->addColumn("str", "HKL");
     table->addColumn("str", "d");
@@ -64,7 +102,14 @@ void PoldiPeakCollection::prepareTable(TableWorkspace_sptr table)
     table->addColumn("str", "FWHM (rel.)");
 }
 
-void PoldiPeakCollection::peaksToTable(TableWorkspace_sptr table)
+void PoldiPeakCollection::dataToTableLog(const TableWorkspace_sptr &table)
+{
+    LogManager_sptr tableLog = table->logs();
+    tableLog->addProperty<std::string>("IntensityType", intensityTypeToString(m_intensityType));
+    tableLog->addProperty<std::string>("ProfileFunctionName", m_profileFunctionName);
+}
+
+void PoldiPeakCollection::peaksToTable(const TableWorkspace_sptr &table)
 {
     for(std::vector<PoldiPeak_sptr>::const_iterator peak = m_peaks.begin(); peak != m_peaks.end(); ++peak) {
         TableRow newRow = table->appendRow();
@@ -76,12 +121,14 @@ void PoldiPeakCollection::peaksToTable(TableWorkspace_sptr table)
     }
 }
 
-void PoldiPeakCollection::constructFromTableWorkspace(TableWorkspace_sptr tableWorkspace)
+void PoldiPeakCollection::constructFromTableWorkspace(const TableWorkspace_sptr &tableWorkspace)
 {
     if(checkColumns(tableWorkspace)) {
         size_t newPeakCount = tableWorkspace->rowCount();
         m_peaks.resize(newPeakCount);
 
+        recoverDataFromLog(tableWorkspace);
+
         for(size_t i = 0; i < newPeakCount; ++i) {
             TableRow nextRow = tableWorkspace->getRow(i);
             std::string hklString, dString, qString, intensityString, fwhmString;
@@ -96,7 +143,7 @@ void PoldiPeakCollection::constructFromTableWorkspace(TableWorkspace_sptr tableW
     }
 }
 
-bool PoldiPeakCollection::checkColumns(TableWorkspace_sptr tableWorkspace)
+bool PoldiPeakCollection::checkColumns(const TableWorkspace_sptr &tableWorkspace)
 {
     if(tableWorkspace->columnCount() != 5) {
         return false;
@@ -114,5 +161,56 @@ bool PoldiPeakCollection::checkColumns(TableWorkspace_sptr tableWorkspace)
     return columnNames == shouldNames;
 }
 
+void PoldiPeakCollection::recoverDataFromLog(const TableWorkspace_sptr &tableWorkspace)
+{
+    LogManager_sptr tableLog = tableWorkspace->logs();
+
+    m_intensityType = intensityTypeFromString(getIntensityTypeFromLog(tableLog));
+    m_profileFunctionName = getProfileFunctionNameFromLog(tableLog);
+}
+
+std::string PoldiPeakCollection::getIntensityTypeFromLog(const LogManager_sptr &tableLog)
+{
+    return getStringValueFromLog(tableLog, "IntensityType");
+}
+
+std::string PoldiPeakCollection::getProfileFunctionNameFromLog(const LogManager_sptr &tableLog)
+{
+    return getStringValueFromLog(tableLog, "ProfileFunctionName");
+}
+
+std::string PoldiPeakCollection::getStringValueFromLog(const LogManager_sptr &logManager, std::string valueName)
+{
+    if(logManager->hasProperty(valueName)) {
+        return logManager->getPropertyValueAsType<std::string>(valueName);
+    }
+
+    return "";
+}
+
+std::string PoldiPeakCollection::intensityTypeToString(PoldiPeakCollection::IntensityType type) const
+{
+    switch(type) {
+    case Maximum:
+        return "Maximum";
+    case Integral:
+        return "Integral";
+    }
+
+    throw std::runtime_error("Unkown intensity type can not be processed.");
+}
+
+PoldiPeakCollection::IntensityType PoldiPeakCollection::intensityTypeFromString(std::string typeString) const
+{
+    std::string lowerCaseType(typeString);
+    std::transform(lowerCaseType.begin(), lowerCaseType.end(), lowerCaseType.begin(), ::tolower);
+
+    if(lowerCaseType == "integral") {
+        return Integral;
+    }
+
+    return Maximum;
+}
+
 }
 }
diff --git a/Code/Mantid/Framework/SINQ/src/PoldiUtilities/PoldiSourceSpectrum.cpp b/Code/Mantid/Framework/SINQ/src/PoldiUtilities/PoldiSourceSpectrum.cpp
index 9bcbe63c1fa9ad3191725cf9a9cf60c7849034e3..fe8deb857789f62a848c2ce5077ab837e2b12132 100644
--- a/Code/Mantid/Framework/SINQ/src/PoldiUtilities/PoldiSourceSpectrum.cpp
+++ b/Code/Mantid/Framework/SINQ/src/PoldiUtilities/PoldiSourceSpectrum.cpp
@@ -26,7 +26,7 @@ PoldiSourceSpectrum::PoldiSourceSpectrum(Instrument_const_sptr poldiInstrument)
   */
 double PoldiSourceSpectrum::intensity(double wavelength) const
 {
-    return m_spectrum.value(wavelength);
+    return std::max(0.0, m_spectrum.value(wavelength));
 }
 
 /** Extracts the source spectrum from an Instrument
diff --git a/Code/Mantid/Framework/SINQ/src/PoldiUtilities/PoldiSpectrumDomainFunction.cpp b/Code/Mantid/Framework/SINQ/src/PoldiUtilities/PoldiSpectrumDomainFunction.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..20d433372a2407ccaad67f5146b29c2bec7ff02e
--- /dev/null
+++ b/Code/Mantid/Framework/SINQ/src/PoldiUtilities/PoldiSpectrumDomainFunction.cpp
@@ -0,0 +1,184 @@
+#include "MantidSINQ/PoldiUtilities/PoldiSpectrumDomainFunction.h"
+
+#include "MantidAPI/FunctionFactory.h"
+#include "MantidAPI/Workspace.h"
+#include "MantidDataObjects/Workspace2D.h"
+#include <stdexcept>
+
+#include "MantidAPI/FunctionDomain1D.h"
+
+namespace Mantid
+{
+namespace Poldi
+{
+
+using namespace DataObjects;
+using namespace API;
+
+DECLARE_FUNCTION(PoldiSpectrumDomainFunction)
+
+PoldiSpectrumDomainFunction::PoldiSpectrumDomainFunction() :
+    ParamFunction(),
+    m_chopperSlitOffsets(),
+    m_deltaT(0.0),
+    m_timeTransformer()
+{
+
+}
+
+/**
+ * Sets the workspace and initializes helper data
+ *
+ * This method calls PoldiSpectrumDomainFunction::initializeParametersFromWorkspace to
+ * setup the factors required for calculation of the spectrum with given index.
+ *
+ * @param ws :: Workspace with valid POLDI instrument and run information
+ */
+void PoldiSpectrumDomainFunction::setWorkspace(boost::shared_ptr<const Workspace> ws)
+{
+    Workspace2D_const_sptr workspace2D = boost::dynamic_pointer_cast<const Workspace2D>(ws);
+
+    if(!workspace2D) {
+        throw std::invalid_argument("PoldiSpectrumDomainFunction can only work with Workspace2D.");
+    }
+
+    initializeParametersFromWorkspace(workspace2D);
+}
+
+/**
+ * Performs the actual function calculation
+ *
+ * This method performs the necessary transformations for the parameters and calculates the function
+ * values for the spectrum with the index stored in domain.
+ *
+ * @param domain :: FunctionDomain1DSpectrum, containing a workspace index
+ * @param values :: Object to store the calculated function values
+ */
+void PoldiSpectrumDomainFunction::function1DSpectrum(const API::FunctionDomain1DSpectrum &domain, API::FunctionValues &values) const
+{
+    size_t index = domain.getWorkspaceIndex();
+    int domainSize = static_cast<int>(domain.size());
+
+    /* Parameters are given in d, but need to be processed in arrival time.
+     * This section performs the conversions. They depend on several factors
+     * terminated by the position in the detector, so the index is stored.
+     */
+    double fwhm = getParameter("Fwhm");
+    double fwhmT = m_timeTransformer->timeTransformedWidth(fwhm, index);
+    double fwhmChannel = fwhmT / m_deltaT;
+    double sigmaChannel = fwhmChannel / (2.0 * sqrt(2.0 * log(2.0)));
+
+    double centre = getParameter("Centre");
+    double centreT = m_timeTransformer->timeTransformedCentre(centre, index);
+
+    double area = getParameter("Area");
+    double areaT = m_timeTransformer->timeTransformedIntensity(area, centre, index);
+
+    /* Once all the factors are all there, the calculation needs to be
+     * performed with one offset per chopper slit.
+     */
+    for(size_t o = 0; o < m_chopperSlitOffsets.size(); ++o) {
+        double centreTOffset = centreT + m_chopperSlitOffsets[o];
+        double centreTOffsetChannel = centreTOffset / m_deltaT;
+
+        /* Calculations are performed in channel units
+         * Needs to be signed integer, because the profile can extend beyond the left edge,
+         * which results in negative indices. Since the spectrum "wraps around" the
+         * indices have to be transformed to the right edge.
+         */
+        int centreChannel = static_cast<int>(centreTOffsetChannel);
+        int widthChannels = std::max(2, static_cast<int>(fwhmChannel * 2.0));
+
+        for(int i = centreChannel - widthChannels; i <= centreChannel + widthChannels; ++i) {
+            /* Since the POLDI spectra "wrap around" on the time axis, the x-value of the
+             * domain can not be used, because if the profile extends to x < 0, it should appear
+             * at 500 - x. The same for the other side.
+             */
+            int cleanChannel = i % domainSize;
+            if(cleanChannel < 0) {
+                cleanChannel += domainSize;
+            }
+
+            double xValue = static_cast<double>(i) + 0.5;
+
+            /* This is a workaround for later, when "actualFunction" will be replaced with
+             * an arbitrary profile.
+             */
+            values.addToCalculated(cleanChannel, actualFunction(xValue, centreTOffsetChannel, sigmaChannel, areaT));
+        }
+    }
+}
+
+/**
+ * Initializes function parameters
+ */
+void PoldiSpectrumDomainFunction::init() {
+    declareParameter("Area", 1.0);
+    declareParameter("Fwhm", 1.0);
+    declareParameter("Centre", 0.0);
+}
+
+/**
+ * Extracts the time difference as well as instrument information
+ *
+ * @param workspace2D :: Workspace with valid POLDI instrument and required run information
+ */
+void PoldiSpectrumDomainFunction::initializeParametersFromWorkspace(const Workspace2D_const_sptr &workspace2D)
+{
+    m_deltaT = workspace2D->readX(0)[1] - workspace2D->readX(0)[0];
+
+    PoldiInstrumentAdapter_sptr adapter = boost::make_shared<PoldiInstrumentAdapter>(workspace2D->getInstrument(),  workspace2D->run());
+    initializeInstrumentParameters(adapter);
+ }
+
+/**
+ * Initializes chopper offsets and time transformer
+ *
+ * In this method, the instrument dependent parameter for the calculation are setup, so that a PoldiTimeTransformer is
+ * available to transfer parameters to the time domain using correct factors etc.
+ *
+ * @param poldiInstrument :: PoldiInstrumentAdapter that holds chopper, detector and spectrum
+ */
+void PoldiSpectrumDomainFunction::initializeInstrumentParameters(const PoldiInstrumentAdapter_sptr &poldiInstrument)
+{
+    m_timeTransformer = boost::make_shared<PoldiTimeTransformer>(poldiInstrument);
+    m_chopperSlitOffsets = getChopperSlitOffsets(poldiInstrument->chopper());
+
+}
+
+/**
+ * Adds the zero-offset of the chopper to the slit times
+ *
+ * @param chopper :: PoldiAbstractChopper with slit times, not corrected with zero-offset
+ * @return vector with zero-offset-corrected chopper slit times
+ */
+std::vector<double> PoldiSpectrumDomainFunction::getChopperSlitOffsets(const PoldiAbstractChopper_sptr &chopper)
+{
+    const std::vector<double> &chopperSlitTimes = chopper->slitTimes();
+    std::vector<double> offsets;
+    offsets.reserve(chopperSlitTimes.size());
+    for(std::vector<double>::const_iterator time = chopperSlitTimes.begin(); time != chopperSlitTimes.end(); ++time) {
+        offsets.push_back(*time + chopper->zeroOffset());
+    }
+
+    return offsets;
+}
+
+/**
+ * Profile function
+ *
+ * This is the actual profile function. Currently this is a Gaussian.
+ *
+ * @param x :: x-value for which y is to be calculated, in channel units
+ * @param x0 :: Centre of the peak, in channel units
+ * @param sigma :: Sigma-parameter of Gaussian distribution, in channel units
+ * @param area :: Area parameter
+ * @return Function value at position x
+ */
+double PoldiSpectrumDomainFunction::actualFunction(double x, double x0, double sigma, double area) const
+{
+    return area / (sqrt(2.0 * M_PI) * sigma) * exp(-0.5 * pow((x - x0) / sigma, 2.0));
+}
+
+} // namespace Poldi
+} // namespace Mantid
diff --git a/Code/Mantid/Framework/SINQ/src/PoldiUtilities/PoldiTimeTransformer.cpp b/Code/Mantid/Framework/SINQ/src/PoldiUtilities/PoldiTimeTransformer.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..37336fd2ceda1113a64dce057c1a3f6864a7dc5d
--- /dev/null
+++ b/Code/Mantid/Framework/SINQ/src/PoldiUtilities/PoldiTimeTransformer.cpp
@@ -0,0 +1,108 @@
+#include "MantidSINQ/PoldiUtilities/PoldiTimeTransformer.h"
+#include "boost/make_shared.hpp"
+
+namespace Mantid
+{
+namespace Poldi
+{
+
+PoldiTimeTransformer::PoldiTimeTransformer() :
+    m_detectorCenter(),
+    m_detectorElementData(),
+    m_detectorEfficiency(0.0),
+    m_chopperSlits(0),
+    m_spectrum()
+{
+}
+
+PoldiTimeTransformer::PoldiTimeTransformer(const PoldiInstrumentAdapter_sptr &poldiInstrument)
+{
+    initializeFromPoldiInstrument(poldiInstrument);
+}
+
+void PoldiTimeTransformer::initializeFromPoldiInstrument(const PoldiInstrumentAdapter_sptr &poldiInstrument)
+{
+    if(!poldiInstrument) {
+        throw std::invalid_argument("Cannot initialize PoldiTimeTransformer from null-instrument.");
+    }
+
+    PoldiAbstractDetector_sptr detector = poldiInstrument->detector();
+    PoldiAbstractChopper_sptr chopper = poldiInstrument->chopper();
+
+    m_spectrum = boost::const_pointer_cast<const PoldiSourceSpectrum>(poldiInstrument->spectrum());
+
+    m_detectorCenter = getDetectorCenterCharacteristics(detector, chopper);
+    m_detectorElementData = getDetectorElementData(detector, chopper);
+    m_detectorEfficiency = detector->efficiency();
+
+    m_chopperSlits = chopper->slitPositions().size();
+}
+
+double PoldiTimeTransformer::dToTOF(double d) const
+{
+    return m_detectorCenter.tof1A * d;
+}
+
+double PoldiTimeTransformer::timeTransformedWidth(double widthD, size_t detectorIndex) const
+{
+    UNUSED_ARG(detectorIndex);
+
+    return dToTOF(widthD);// + m_detectorElementData[detectorIndex]->widthFactor() * 0.0;
+}
+
+double PoldiTimeTransformer::timeTransformedCentre(double centreD, size_t detectorIndex) const
+{
+    return dToTOF(centreD) * m_detectorElementData[detectorIndex]->timeFactor();
+}
+
+double PoldiTimeTransformer::timeTransformedIntensity(double areaD, double centreD, size_t detectorIndex) const
+{
+    return areaD * detectorElementIntensity(centreD, detectorIndex);
+}
+
+double PoldiTimeTransformer::detectorElementIntensity(double centreD, size_t detectorIndex) const
+{
+    double lambda = dToTOF(centreD) * m_detectorElementData[detectorIndex]->lambdaFactor();
+    double intensity = m_spectrum->intensity(lambda) * m_detectorElementData[detectorIndex]->intensityFactor();
+
+    return intensity * (1.0 - exp(-m_detectorEfficiency * lambda));
+}
+
+double PoldiTimeTransformer::calculatedTotalIntensity(double centreD) const
+{
+    double sum = 0.0;
+    double chopperSlitFactor = static_cast<double>(m_chopperSlits);
+
+    for(size_t i = 0; i < m_detectorElementData.size(); ++i) {
+        sum += chopperSlitFactor * detectorElementIntensity(centreD, i);
+    }
+
+    return sum;
+}
+
+size_t PoldiTimeTransformer::detectorElementCount() const
+{
+    return m_detectorElementData.size();
+}
+
+std::vector<DetectorElementData_const_sptr> PoldiTimeTransformer::getDetectorElementData(const PoldiAbstractDetector_sptr &detector, const PoldiAbstractChopper_sptr &chopper)
+{
+    std::vector<DetectorElementData_const_sptr> data(detector->elementCount());
+
+    DetectorElementCharacteristics center = getDetectorCenterCharacteristics(detector, chopper);
+
+    for(int i = 0; i < static_cast<int>(detector->elementCount()); ++i) {
+        data[i] = boost::make_shared<DetectorElementData>(i, center, detector, chopper);
+    }
+
+    return data;
+}
+
+DetectorElementCharacteristics PoldiTimeTransformer::getDetectorCenterCharacteristics(const PoldiAbstractDetector_sptr &detector, const PoldiAbstractChopper_sptr &chopper)
+{
+    return DetectorElementCharacteristics(static_cast<int>(detector->centralElement()), detector, chopper);
+}
+
+
+} // namespace Poldi
+} // namespace Mantid
diff --git a/Code/Mantid/Framework/SINQ/test/MillerIndicesTest.h b/Code/Mantid/Framework/SINQ/test/MillerIndicesTest.h
index 1d5efd0ee07b436604d883b3f40032d0cb0116f8..8a581307a6b97c0628debdada99bb235d7b226b5 100644
--- a/Code/Mantid/Framework/SINQ/test/MillerIndicesTest.h
+++ b/Code/Mantid/Framework/SINQ/test/MillerIndicesTest.h
@@ -84,6 +84,16 @@ public:
         TS_ASSERT_EQUALS(copyVector.size(), 3);
         TS_ASSERT_EQUALS(copyVector[0], hkl[0]);
     }
+
+    void testEquality()
+    {
+        MillerIndices hklOne(1, 1, 0);
+        MillerIndices hklTwo(1, 1, 0);
+        MillerIndices hklThree(1, 2, 0);
+
+        TS_ASSERT_EQUALS(hklOne, hklTwo);
+        TS_ASSERT_DIFFERS(hklOne, hklThree);
+    }
 };
 
 #endif // MANTID_SINQ_MILLERINDICESTEST_H
diff --git a/Code/Mantid/Framework/SINQ/test/PeakFunctionIntegratorTest.h b/Code/Mantid/Framework/SINQ/test/PeakFunctionIntegratorTest.h
new file mode 100644
index 0000000000000000000000000000000000000000..59b641d58fb3d971ef227052a6e4d3b2282f836e
--- /dev/null
+++ b/Code/Mantid/Framework/SINQ/test/PeakFunctionIntegratorTest.h
@@ -0,0 +1,187 @@
+#ifndef PEAKFUNCTIONINTEGRATORTEST_H
+#define PEAKFUNCTIONINTEGRATORTEST_H
+
+#include <cxxtest/TestSuite.h>
+#include "MantidSINQ/PoldiUtilities/PeakFunctionIntegrator.h"
+
+#include "MantidCurveFitting/Gaussian.h"
+#include "MantidCurveFitting/Lorentzian.h"
+
+#include "gsl/gsl_errno.h"
+
+using namespace Mantid::Poldi;
+using namespace Mantid::API;
+using namespace Mantid::CurveFitting;
+
+class PeakFunctionIntegratorTest;
+
+class TestablePeakFunctionIntegrator : public PeakFunctionIntegrator
+{
+public:
+    TestablePeakFunctionIntegrator(double requiredRelativePrecision = 1e-8) :
+        PeakFunctionIntegrator(requiredRelativePrecision)
+    {
+
+    }
+
+    friend class PeakFunctionIntegratorTest;
+};
+
+class PeakFunctionIntegratorTest : public CxxTest::TestSuite
+{
+private:
+    IPeakFunction_sptr getGaussian(double center, double fwhm, double height)
+    {
+        IPeakFunction_sptr gaussian(new Gaussian);
+        gaussian->initialize();
+        gaussian->setCentre(center);
+        gaussian->setFwhm(fwhm);
+        gaussian->setHeight(height);
+
+        return gaussian;
+    }
+
+    double getGaussianAnalyticalInfiniteIntegral(IPeakFunction_sptr gaussian)
+    {
+        return gaussian->height() * gaussian->fwhm() / (2.0 * sqrt(2.0 * log(2.0))) * sqrt(2.0 * M_PI);
+    }
+
+    IPeakFunction_sptr getLorentzian(double center, double fwhm, double height)
+    {
+        IPeakFunction_sptr lorentzian(new Lorentzian);
+        lorentzian->initialize();
+        lorentzian->setCentre(center);
+        lorentzian->setFwhm(fwhm);
+        lorentzian->setHeight(height);
+
+        return lorentzian;
+    }
+
+    double getLorentzianAnalyticalInfiniteIntegral(IPeakFunction_sptr lorentzian)
+    {
+        return lorentzian->getParameter("Amplitude");
+    }
+
+public:
+    // This pair of boilerplate methods prevent the suite being created statically
+    // This means the constructor isn't called when running other tests
+    static PeakFunctionIntegratorTest *createSuite() { return new PeakFunctionIntegratorTest(); }
+    static void destroySuite( PeakFunctionIntegratorTest *suite ) { delete suite; }
+
+    void testDefaultConstruction()
+    {
+        TestablePeakFunctionIntegrator integrator;
+
+        TS_ASSERT(integrator.m_integrationWorkspace != 0);
+        TS_ASSERT_EQUALS(integrator.m_relativePrecision, 1e-8);
+    }
+
+    void testConstruction()
+    {
+        TestablePeakFunctionIntegrator integrator(1e-10);
+
+        TS_ASSERT(integrator.m_integrationWorkspace != 0);
+        TS_ASSERT_EQUALS(integrator.m_relativePrecision, 1e-10);
+    }
+
+    void testSetRequiredRelativePrecision()
+    {
+        PeakFunctionIntegrator integrator;
+        integrator.setRequiredRelativePrecision(1e-2);
+
+        TS_ASSERT_EQUALS(integrator.requiredRelativePrecision(), 1e-2);
+    }
+
+    void testgsl_peak_wrapper()
+    {
+        IPeakFunction_sptr gaussian = getGaussian(0.0, 1.0, 2.0);
+
+        TS_ASSERT_EQUALS(gsl_peak_wrapper(0.0, &gaussian), 2.0);
+    }
+
+    void testNullPointer()
+    {
+        PeakFunctionIntegrator integrator;
+
+        TS_ASSERT_THROWS(integrator.integrateInfinity(IPeakFunction_sptr()), std::invalid_argument);
+        TS_ASSERT_THROWS(integrator.integratePositiveInfinity(IPeakFunction_sptr(), 0.0), std::invalid_argument);
+        TS_ASSERT_THROWS(integrator.integrateNegativeInfinity(IPeakFunction_sptr(), 0.0), std::invalid_argument);
+        TS_ASSERT_THROWS(integrator.integrate(IPeakFunction_sptr(), 0.0, 0.0), std::invalid_argument);
+
+    }
+
+    void testIntegrateInfinityGaussian()
+    {
+        IPeakFunction_sptr gaussian = getGaussian(0.0, 1.0, 1.0);
+
+        PeakFunctionIntegrator integrator;
+        IntegrationResult result = integrator.integrateInfinity(gaussian);
+        TS_ASSERT_EQUALS(result.errorCode, static_cast<int>(GSL_SUCCESS));
+        TS_ASSERT_DELTA(result.result, getGaussianAnalyticalInfiniteIntegral(gaussian), integrator.requiredRelativePrecision());
+        TS_ASSERT_DELTA(result.error, 0.0, integrator.requiredRelativePrecision());
+
+        integrator.setRequiredRelativePrecision(1e-14);
+        IntegrationResult otherResult = integrator.integrateInfinity(gaussian);
+        TS_ASSERT_EQUALS(otherResult.errorCode, static_cast<int>(GSL_EBADTOL));
+        TS_ASSERT_EQUALS(otherResult.result, 0.0);
+        TS_ASSERT_EQUALS(otherResult.error, 0.0);
+    }
+
+    void testIntegratePositiveInfinityGaussian()
+    {
+        IPeakFunction_sptr gaussian = getGaussian(0.0, 1.0, 1.0);
+        PeakFunctionIntegrator integrator;
+        IntegrationResult result = integrator.integratePositiveInfinity(gaussian, 0.0);
+
+        TS_ASSERT_EQUALS(result.errorCode, static_cast<int>(GSL_SUCCESS));
+        TS_ASSERT_DELTA(result.result, getGaussianAnalyticalInfiniteIntegral(gaussian) / 2.0, integrator.requiredRelativePrecision());
+    }
+
+    void testIntegrateNegativeInfinityGaussian()
+    {
+        IPeakFunction_sptr gaussian = getGaussian(0.0, 1.0, 1.0);
+        PeakFunctionIntegrator integrator;
+        IntegrationResult result = integrator.integrateNegativeInfinity(gaussian, 0.0);
+
+        TS_ASSERT_EQUALS(result.errorCode, static_cast<int>(GSL_SUCCESS));
+        TS_ASSERT_DELTA(result.result, getGaussianAnalyticalInfiniteIntegral(gaussian) / 2.0, integrator.requiredRelativePrecision());
+    }
+
+    void testIntegrateGaussian()
+    {
+        /*
+         * Normal distribution with mu = 0, sigma = 1, height = 1/sqrt(2 * pi)
+         *  -integral from -1 to 1 should give approx. 0.682
+         *  -integral from -2 to 2 should give approx. 0.954
+         *  -integral from -3 to 3 should give approx. 0.997
+         */
+        IPeakFunction_sptr gaussian = getGaussian(0.0, 2.0 * sqrt(2.0 * log(2.0)), 1.0 / sqrt(2.0 * M_PI));
+        PeakFunctionIntegrator integrator(1e-10);
+
+        IntegrationResult rOneSigma = integrator.integrate(gaussian, -1.0, 1.0);
+        TS_ASSERT_EQUALS(rOneSigma.errorCode, static_cast<int>(GSL_SUCCESS));
+        TS_ASSERT_DELTA(rOneSigma.result, 0.682689492137086, integrator.requiredRelativePrecision());
+
+        IntegrationResult rTwoSigma = integrator.integrate(gaussian, -2.0, 2.0);
+        TS_ASSERT_EQUALS(rTwoSigma.errorCode, static_cast<int>(GSL_SUCCESS));
+        TS_ASSERT_DELTA(rTwoSigma.result, 0.954499736103642, integrator.requiredRelativePrecision());
+
+        IntegrationResult rThreeSigma = integrator.integrate(gaussian, -3.0, 3.0);
+        TS_ASSERT_EQUALS(rThreeSigma.errorCode, static_cast<int>(GSL_SUCCESS));
+        TS_ASSERT_DELTA(rThreeSigma.result, 0.997300203936740, integrator.requiredRelativePrecision());
+    }
+
+    void testIntegrateInfinityLorentzian()
+    {
+        IPeakFunction_sptr lorentzian = getLorentzian(0.0, 3.0, 8.0);
+        PeakFunctionIntegrator integrator(1e-8);
+
+        IntegrationResult result = integrator.integrateInfinity(lorentzian);
+        TS_ASSERT_EQUALS(result.errorCode, static_cast<int>(GSL_SUCCESS));
+        TS_ASSERT_DELTA(result.result, getLorentzianAnalyticalInfiniteIntegral(lorentzian), integrator.requiredRelativePrecision());
+        TS_ASSERT_LESS_THAN(result.intervals, 1000);
+    }
+
+};
+
+#endif // PEAKFUNCTIONINTEGRATORTEST_H
diff --git a/Code/Mantid/Framework/SINQ/test/Poldi2DFunctionTest.h b/Code/Mantid/Framework/SINQ/test/Poldi2DFunctionTest.h
new file mode 100644
index 0000000000000000000000000000000000000000..1e971ec312eb7e6a8df86c0cb2d00321aa8a9f0d
--- /dev/null
+++ b/Code/Mantid/Framework/SINQ/test/Poldi2DFunctionTest.h
@@ -0,0 +1,84 @@
+#ifndef MANTID_SINQ_POLDI2DFUNCTIONTEST_H_
+#define MANTID_SINQ_POLDI2DFUNCTIONTEST_H_
+
+#include <cxxtest/TestSuite.h>
+
+#include "MantidSINQ/PoldiUtilities/Poldi2DFunction.h"
+#include "MantidAPI/FunctionDomain1D.h"
+#include "MantidAPI/ParamFunction.h"
+
+using namespace Mantid::Poldi;
+using namespace Mantid::API;
+
+class Poldi2DFunctionTest : public CxxTest::TestSuite
+{
+public:
+    // This pair of boilerplate methods prevent the suite being created statically
+    // This means the constructor isn't called when running other tests
+    static Poldi2DFunctionTest *createSuite() { return new Poldi2DFunctionTest(); }
+    static void destroySuite( Poldi2DFunctionTest *suite ) { delete suite; }
+
+
+    void testTypes()
+    {
+        boost::shared_ptr<Poldi2DFunction> function2D(new Poldi2DFunction);
+
+        TS_ASSERT(boost::dynamic_pointer_cast<CompositeFunction>(function2D));
+        TS_ASSERT(boost::dynamic_pointer_cast<IFunction1DSpectrum>(function2D));
+    }
+
+    void testSummation()
+    {
+        boost::shared_ptr<Poldi2DFunction> function2D(new Poldi2DFunction);
+
+        IFunction_sptr first(new SummingFunction);
+        IFunction_sptr second(new SummingFunction);
+
+        function2D->addFunction(first);
+        function2D->addFunction(second);
+
+        // x doesn't matter for that function
+        std::vector<double> x(10, 1.0);
+
+        FunctionDomain1DSpectrum domain(0, x);
+        FunctionValues values(domain);
+
+        // check that functions are added properly
+        function2D->function(domain, values);
+        TS_ASSERT_EQUALS(values[0], 2.0);
+        TS_ASSERT_EQUALS(values[1], 2.0);
+        TS_ASSERT_EQUALS(values[9], 2.0);
+
+        // use same values object again, should give the same results
+        function2D->function(domain, values);
+        TS_ASSERT_EQUALS(values[0], 2.0);
+        TS_ASSERT_EQUALS(values[1], 2.0);
+        TS_ASSERT_EQUALS(values[9], 2.0);
+    }
+
+private:
+    /* small test function that behaves like PoldiSpectrumDomainFunction
+     * in that it uses FunctionValues::addToCalculated.
+     */
+    class SummingFunction : public IFunction1DSpectrum, public ParamFunction {
+    public:
+        std::string name() const { return "SummingFunction"; }
+
+        void function1DSpectrum(const FunctionDomain1DSpectrum &domain, FunctionValues &values) const
+        {
+            for(size_t i = 0; i < domain.size(); ++i) {
+                values.addToCalculated(i, 1.0);
+            }
+        }
+
+        void functionDeriv1DSpectrum(const FunctionDomain1DSpectrum &domain, Jacobian &jacobian) {
+            UNUSED_ARG(domain);
+            UNUSED_ARG(jacobian);
+        }
+
+    };
+
+};
+
+
+#endif /* MANTID_SINQ_POLDI2DFUNCTIONTEST_H_ */
diff --git a/Code/Mantid/Framework/SINQ/test/PoldiBasicChopperTest.h b/Code/Mantid/Framework/SINQ/test/PoldiBasicChopperTest.h
index 5ffc61cf3de8d4b0ace7b625900c7a6bb256c4b5..fe80941f549fa81c82c29d2cc44c91a21a4b8d07 100644
--- a/Code/Mantid/Framework/SINQ/test/PoldiBasicChopperTest.h
+++ b/Code/Mantid/Framework/SINQ/test/PoldiBasicChopperTest.h
@@ -9,6 +9,7 @@
 using namespace Mantid;
 using namespace Mantid::API;
 using namespace Mantid::Poldi;
+using namespace Mantid::Geometry;
 
 class TestablePoldiBasicChopper : public PoldiBasicChopper
 {
diff --git a/Code/Mantid/Framework/SINQ/test/PoldiCalculateSpectrum2DTest.h b/Code/Mantid/Framework/SINQ/test/PoldiCalculateSpectrum2DTest.h
new file mode 100644
index 0000000000000000000000000000000000000000..a7fc9bbaa223deb78196d34a8931310cc1c38ba7
--- /dev/null
+++ b/Code/Mantid/Framework/SINQ/test/PoldiCalculateSpectrum2DTest.h
@@ -0,0 +1,208 @@
+#ifndef MANTID_SINQ_POLDICALCULATESPECTRUM2DTEST_H_
+#define MANTID_SINQ_POLDICALCULATESPECTRUM2DTEST_H_
+
+#include <cxxtest/TestSuite.h>
+
+#include "MantidAPI/FrameworkManager.h"
+#include "MantidAPI/AlgorithmManager.h"
+
+#include "MantidSINQ/PoldiCalculateSpectrum2D.h"
+#include "MantidSINQ/PoldiUtilities/PoldiMockInstrumentHelpers.h"
+#include "MantidTestHelpers/WorkspaceCreationHelper.h"
+
+using namespace Mantid::Poldi;
+using namespace Mantid::API;
+using namespace Mantid::DataObjects;
+
+class PoldiCalculateSpectrum2DTest : public CxxTest::TestSuite
+{
+public:
+    // This pair of boilerplate methods prevent the suite being created statically
+    // This means the constructor isn't called when running other tests
+    static PoldiCalculateSpectrum2DTest *createSuite() { return new PoldiCalculateSpectrum2DTest(); }
+    static void destroySuite( PoldiCalculateSpectrum2DTest *suite ) { delete suite; }
+
+    PoldiCalculateSpectrum2DTest()
+    {
+        FrameworkManager::Instance();
+
+        m_instrument = PoldiInstrumentAdapter_sptr(new FakePoldiInstrumentAdapter);
+        m_timeTransformer = PoldiTimeTransformer_sptr(new PoldiTimeTransformer(m_instrument));
+    }
+
+    void testSetTimeTransformer()
+    {
+        TestablePoldiCalculateSpectrum2D spectrumCalculator;
+        spectrumCalculator.setTimeTransformer(m_timeTransformer);
+
+        TS_ASSERT_EQUALS(spectrumCalculator.m_timeTransformer, m_timeTransformer);
+    }
+
+    void testSetTimeTransformerFromInstrument()
+    {
+        TestablePoldiCalculateSpectrum2D spectrumCalculator;
+        spectrumCalculator.setTimeTransformerFromInstrument(m_instrument);
+
+        TS_ASSERT(spectrumCalculator.m_timeTransformer);
+    }
+
+    void testSetDeltaT()
+    {
+        TestablePoldiCalculateSpectrum2D spectrumCalculator;
+        TS_ASSERT_THROWS_NOTHING(spectrumCalculator.setDeltaT(2.0));
+        TS_ASSERT_EQUALS(spectrumCalculator.m_deltaT, 2.0);
+
+        TS_ASSERT_THROWS(spectrumCalculator.setDeltaT(0.0), std::invalid_argument);
+        TS_ASSERT_THROWS(spectrumCalculator.setDeltaT(-1.0), std::invalid_argument);
+    }
+
+    void testSetDeltaTFromWorkspace()
+    {
+        MatrixWorkspace_sptr ws = WorkspaceCreationHelper::Create2DWorkspace(1, 10);
+        for(size_t i = 0; i <= 10; ++i) {
+            ws->dataX(0)[i] = static_cast<double>(i);
+        }
+
+        TestablePoldiCalculateSpectrum2D spectrumCalculator;
+        spectrumCalculator.setDeltaTFromWorkspace(ws);
+        TS_ASSERT_EQUALS(spectrumCalculator.m_deltaT, 1.0);
+
+        MatrixWorkspace_sptr invalidWs = WorkspaceCreationHelper::Create2DWorkspace123(1, 1);
+        TS_ASSERT_THROWS(spectrumCalculator.setDeltaTFromWorkspace(invalidWs), std::invalid_argument);
+    }
+
+    void testIsValidDeltaT()
+    {
+        TestablePoldiCalculateSpectrum2D spectrumCalculator;
+        TS_ASSERT_EQUALS(spectrumCalculator.isValidDeltaT(1.0), true);
+        TS_ASSERT_EQUALS(spectrumCalculator.isValidDeltaT(0.0), false);
+        TS_ASSERT_EQUALS(spectrumCalculator.isValidDeltaT(-1.0), false);
+    }
+
+    void testGetPeakCollection()
+    {
+        TestablePoldiCalculateSpectrum2D spectrumCalculator;
+
+        TableWorkspace_sptr peakTable = PoldiPeakCollectionHelpers::createPoldiPeakTableWorkspace();
+        TS_ASSERT_THROWS_NOTHING(spectrumCalculator.getPeakCollection(peakTable));
+
+        PoldiPeakCollection_sptr collection = spectrumCalculator.getPeakCollection(peakTable);
+        TS_ASSERT_EQUALS(collection->peakCount(), peakTable->rowCount());
+    }
+
+    void testGetIntegratedPeakCollection()
+    {
+        PoldiPeakCollection_sptr testPeaks = PoldiPeakCollectionHelpers::createPoldiPeakCollectionMaximum();
+
+        TestablePoldiCalculateSpectrum2D spectrumCalculator;
+        // deltaT is not set, so this must fail
+        TS_ASSERT_THROWS(spectrumCalculator.getIntegratedPeakCollection(testPeaks), std::invalid_argument);
+        spectrumCalculator.setDeltaT(3.0);
+
+        // still fails, because time transformer is required.
+        TS_ASSERT_THROWS(spectrumCalculator.getIntegratedPeakCollection(testPeaks), std::invalid_argument);
+        spectrumCalculator.setTimeTransformer(m_timeTransformer);
+
+        // peak collection with some peaks, intensities are described by maximum,
+        // this is the "happy case".
+        TS_ASSERT_THROWS_NOTHING(spectrumCalculator.getIntegratedPeakCollection(testPeaks));
+
+        PoldiPeakCollection_sptr integratedTestPeaks = spectrumCalculator.getIntegratedPeakCollection(testPeaks);
+        // this should be a new peak collection
+        TS_ASSERT(integratedTestPeaks != testPeaks);
+        TS_ASSERT_EQUALS(integratedTestPeaks->peakCount(), testPeaks->peakCount());
+
+        // checking the actual integration result agains reference.
+        PoldiPeakCollection_sptr integratedReference = PoldiPeakCollectionHelpers::createPoldiPeakCollectionIntegral();
+
+        // compare result to relative error of 1e-6
+        compareIntensities(integratedTestPeaks, integratedReference, 1e-6);
+
+        // In case of integrated peaks nothing should happen
+        PoldiPeakCollection_sptr alreadyIntegratedPeaks(new PoldiPeakCollection(PoldiPeakCollection::Integral));
+        alreadyIntegratedPeaks->addPeak(PoldiPeak::create(2.0));
+
+        PoldiPeakCollection_sptr alreadyIntegratedResult = spectrumCalculator.getIntegratedPeakCollection(alreadyIntegratedPeaks);
+        TS_ASSERT(alreadyIntegratedResult != alreadyIntegratedPeaks);
+        TS_ASSERT_EQUALS(alreadyIntegratedResult->peakCount(), alreadyIntegratedPeaks->peakCount());
+        TS_ASSERT_EQUALS(alreadyIntegratedResult->peak(0)->d(), alreadyIntegratedPeaks->peak(0)->d());
+
+        // Where there's no profile function specified, the integration can not be performed.
+        PoldiPeakCollection_sptr noProfilePeaks(new PoldiPeakCollection);
+        TS_ASSERT_THROWS(spectrumCalculator.getIntegratedPeakCollection(noProfilePeaks), std::runtime_error);
+
+        // When there is no valid PoldiPeakCollection, the method also throws
+        PoldiPeakCollection_sptr invalidPeakCollection;
+        TS_ASSERT_THROWS(spectrumCalculator.getIntegratedPeakCollection(invalidPeakCollection), std::invalid_argument);
+    }
+
+    void testGetNormalizedPeakCollection()
+    {
+        TestablePoldiCalculateSpectrum2D spectrumCalculator;
+
+        // first, test the failing cases
+        PoldiPeakCollection_sptr invalidPeakCollection;
+        TS_ASSERT_THROWS(spectrumCalculator.getNormalizedPeakCollection(invalidPeakCollection), std::invalid_argument);
+
+        // m_timeTransformer has not been assigned, so even a "good" PeakCollection will throw
+        PoldiPeakCollection_sptr testPeaks = PoldiPeakCollectionHelpers::createPoldiPeakCollectionMaximum();
+        TS_ASSERT_THROWS(spectrumCalculator.getNormalizedPeakCollection(testPeaks), std::invalid_argument);
+
+        spectrumCalculator.setTimeTransformer(m_timeTransformer);
+
+        // to verify the results, use actual results from after integration step
+        PoldiPeakCollection_sptr integratedPeaks = PoldiPeakCollectionHelpers::createPoldiPeakCollectionIntegral();
+        TS_ASSERT_THROWS_NOTHING(spectrumCalculator.getNormalizedPeakCollection(integratedPeaks));
+
+        PoldiPeakCollection_sptr normalizedPeaks = spectrumCalculator.getNormalizedPeakCollection(integratedPeaks);
+        PoldiPeakCollection_sptr normalizedReferencePeaks = PoldiPeakCollectionHelpers::createPoldiPeakCollectionNormalized();
+
+        compareIntensities(normalizedPeaks, normalizedReferencePeaks, 1.5e-6);
+    }
+
+    void testGetFunctionFromPeakCollection()
+    {
+        TestablePoldiCalculateSpectrum2D spectrumCalculator;
+        PoldiPeakCollection_sptr peaks = PoldiPeakCollectionHelpers::createPoldiPeakCollectionNormalized();
+
+        boost::shared_ptr<Poldi2DFunction> poldi2DFunction = spectrumCalculator.getFunctionFromPeakCollection(peaks);
+
+        TS_ASSERT_EQUALS(poldi2DFunction->nFunctions(), peaks->peakCount());
+
+        for(size_t i = 0; i < poldi2DFunction->nFunctions(); ++i) {
+            IFunction_sptr rawFunction = poldi2DFunction->getFunction(i);
+            TS_ASSERT(boost::dynamic_pointer_cast<IFunction1DSpectrum>(rawFunction));
+            TS_ASSERT_EQUALS(rawFunction->parameterName(0), "Area");
+            TS_ASSERT_EQUALS(rawFunction->getParameter(0), peaks->peak(i)->intensity());
+        }
+    }
+
+private:
+    PoldiInstrumentAdapter_sptr m_instrument;
+    PoldiTimeTransformer_sptr m_timeTransformer;
+
+    void compareIntensities(PoldiPeakCollection_sptr first, PoldiPeakCollection_sptr second, double relativePrecision)
+    {
+        for(size_t i = 0; i < first->peakCount(); ++i) {
+            PoldiPeak_sptr peak = first->peak(i);
+            PoldiPeak_sptr referencePeak = second->peak(i);
+
+            std::stringstream strm;
+            strm << std::setprecision(15);
+            strm << "Error in Peak " << i << ": " << peak->intensity().value() << " != " << referencePeak->intensity().value();
+
+            TSM_ASSERT_DELTA(strm.str().c_str(), fabs(1.0 - peak->intensity().value()/referencePeak->intensity().value()), 0.0, relativePrecision);
+        }
+    }
+
+    class TestablePoldiCalculateSpectrum2D : public PoldiCalculateSpectrum2D
+    {
+        friend class PoldiCalculateSpectrum2DTest;
+    public:
+        TestablePoldiCalculateSpectrum2D() : PoldiCalculateSpectrum2D() { }
+        ~TestablePoldiCalculateSpectrum2D() { }
+    };
+
+};
+
+#endif // MANTID_SINQ_POLDICALCULATESPECTRUM2DTEST_H_
diff --git a/Code/Mantid/Framework/SINQ/test/PoldiDetectorTest.h b/Code/Mantid/Framework/SINQ/test/PoldiDetectorTest.h
index a4a50e9d47f13ca97423fce1e138c3b4a549fe6e..283ad94b9e138066357ca97723ea167c3d847106 100644
--- a/Code/Mantid/Framework/SINQ/test/PoldiDetectorTest.h
+++ b/Code/Mantid/Framework/SINQ/test/PoldiDetectorTest.h
@@ -14,6 +14,7 @@ using namespace Mantid::API;
 using namespace Mantid::Kernel;
 using namespace Mantid::Poldi;
 using namespace Mantid::DataObjects;
+using namespace Mantid::Geometry;
 
 class TestablePoldiHeliumDetector : public ConfiguredHeliumDetector
 {
diff --git a/Code/Mantid/Framework/SINQ/test/PoldiInstrumentAdapterTest.h b/Code/Mantid/Framework/SINQ/test/PoldiInstrumentAdapterTest.h
new file mode 100644
index 0000000000000000000000000000000000000000..ef9dbb5eafd796539cd5c08c900e64c891e17a6a
--- /dev/null
+++ b/Code/Mantid/Framework/SINQ/test/PoldiInstrumentAdapterTest.h
@@ -0,0 +1,126 @@
+#ifndef MANTID_SINQ_POLDIINSTRUMENTADAPTERTEST_H_
+#define MANTID_SINQ_POLDIINSTRUMENTADAPTERTEST_H_
+
+#include <cxxtest/TestSuite.h>
+#include <gtest/gtest.h>
+#include <gmock/gmock.h>
+
+#include "MantidSINQ/PoldiUtilities/PoldiInstrumentAdapter.h"
+#include "MantidSINQ/PoldiUtilities/PoldiMockInstrumentHelpers.h"
+
+#include "MantidAPI/Run.h"
+#include "MantidKernel/PropertyWithValue.h"
+
+using namespace Mantid::Poldi;
+using namespace Mantid::API;
+using namespace Mantid::Kernel;
+
+class PoldiInstrumentAdapterTest : public CxxTest::TestSuite
+{
+public:
+    // This pair of boilerplate methods prevent the suite being created statically
+    // This means the constructor isn't called when running other tests
+    static PoldiInstrumentAdapterTest *createSuite() { return new PoldiInstrumentAdapterTest(); }
+    static void destroySuite( PoldiInstrumentAdapterTest *suite ) { delete suite; }
+
+    PoldiInstrumentAdapterTest()
+    {
+        // special properties for testing AbstractDoubleValueExtractor
+        m_run.addProperty<double>("chopperspeed_double", 10000.0);
+
+        std::vector<double> chopperSpeed(1, 10000.0);
+        m_run.addProperty<std::vector<double> >("chopperspeed_vector", chopperSpeed);
+
+        // add string property, for which there is no extractor
+        m_stringRun.addProperty<std::string>(PoldiInstrumentAdapter::m_chopperSpeedPropertyName, "10000.0");
+
+        // run with correct chopperspeed property
+        m_correctRun.addProperty<double>(PoldiInstrumentAdapter::m_chopperSpeedPropertyName, 10000.0);
+    }
+
+    void testVectorDoubleValueExtractor()
+    {
+        // Extract vector value with vector value extractor - this should work.
+        AbstractDoubleValueExtractor_sptr extractorGood(new VectorDoubleValueExtractor("chopperspeed_vector"));
+        TS_ASSERT_THROWS_NOTHING((*extractorGood)(const_cast<const Run &>(m_run)));
+
+        // this should not work, because it's a "number" property (see constructor above)
+        AbstractDoubleValueExtractor_sptr extractorBad(new VectorDoubleValueExtractor("chopperspeed_double"));
+        TS_ASSERT_THROWS((*extractorBad)(const_cast<const Run &>(m_run)), std::invalid_argument);
+
+        // check that the value comes out correctly
+        TS_ASSERT_EQUALS((*extractorGood)(const_cast<const Run &>(m_run)), 10000.0);
+    }
+
+    void testNumberDoubleValueExtractor()
+    {
+        // Same as above test
+        AbstractDoubleValueExtractor_sptr extractorGood(new NumberDoubleValueExtractor("chopperspeed_double"));
+        TS_ASSERT_THROWS_NOTHING((*extractorGood)(const_cast<const Run &>(m_run)));
+
+        AbstractDoubleValueExtractor_sptr extractorBad(new NumberDoubleValueExtractor("chopperspeed_vector"));
+        TS_ASSERT_THROWS((*extractorBad)(const_cast<const Run &>(m_run)), std::invalid_argument);
+
+        // check that the value comes out correctly
+        TS_ASSERT_EQUALS((*extractorGood)(const_cast<const Run &>(m_run)), 10000.0);
+    }
+
+    void testGetChopperSpeedFromRun() {
+        TestablePoldiInstrumentAdapter instrumentAdapter;
+
+        // Throws, because "chopperspeed" is missing
+        TS_ASSERT_THROWS(instrumentAdapter.getChopperSpeedFromRun(m_run), std::runtime_error);
+
+        // Throws, because there is no extractor for supplied type
+        TS_ASSERT_THROWS(instrumentAdapter.getChopperSpeedFromRun(m_stringRun), std::invalid_argument);
+
+        // Should be ok.
+        TS_ASSERT_THROWS_NOTHING(instrumentAdapter.getChopperSpeedFromRun(m_correctRun));
+        TS_ASSERT_EQUALS(instrumentAdapter.getChopperSpeedFromRun(m_correctRun), 10000.0);
+    }
+
+    void testGetExtractorForProperty() {
+        TestablePoldiInstrumentAdapter instrumentAdapter;
+
+        // Throw on null-pointer
+        TS_ASSERT_THROWS(instrumentAdapter.getExtractorForProperty(0), std::invalid_argument);
+        TS_ASSERT_THROWS_NOTHING(instrumentAdapter.getExtractorForProperty(m_run.getProperty("chopperspeed_double")));
+
+        // Check that the correct extractor is retrieved
+        AbstractDoubleValueExtractor_sptr extractor = instrumentAdapter.getExtractorForProperty(m_run.getProperty("chopperspeed_double"));
+        TS_ASSERT(extractor);
+
+        TS_ASSERT(boost::dynamic_pointer_cast<NumberDoubleValueExtractor>(extractor));
+        TS_ASSERT(!boost::dynamic_pointer_cast<VectorDoubleValueExtractor>(extractor));
+
+        // Check that the correct extractor is retrieved
+        extractor = instrumentAdapter.getExtractorForProperty(m_run.getProperty("chopperspeed_vector"));
+        TS_ASSERT(extractor);
+
+        TS_ASSERT(boost::dynamic_pointer_cast<VectorDoubleValueExtractor>(extractor));
+        TS_ASSERT(!boost::dynamic_pointer_cast<NumberDoubleValueExtractor>(extractor));
+
+        // unregistered property type - invalid extractor
+        extractor = instrumentAdapter.getExtractorForProperty(m_stringRun.getProperty(PoldiInstrumentAdapter::m_chopperSpeedPropertyName));
+        TS_ASSERT(!extractor);
+    }
+
+private:
+    boost::shared_ptr<ConfiguredHeliumDetector> m_detector;
+    boost::shared_ptr<MockChopper> m_chopper;
+    PoldiSourceSpectrum_sptr m_spectrum;
+
+    Run m_run;
+    Run m_correctRun;
+    Run m_stringRun;
+
+    class TestablePoldiInstrumentAdapter : public PoldiInstrumentAdapter
+    {
+        friend class PoldiInstrumentAdapterTest;
+    public:
+        TestablePoldiInstrumentAdapter() : PoldiInstrumentAdapter() { }
+        ~TestablePoldiInstrumentAdapter() { }
+    };
+};
+
+#endif // MANTID_SINQ_POLDIINSTRUMENTADAPTERTEST_H_
diff --git a/Code/Mantid/Framework/SINQ/test/PoldiPeakCollectionTest.h b/Code/Mantid/Framework/SINQ/test/PoldiPeakCollectionTest.h
index 983010e3d7e69b8ab145c77e087430d2359f7fed..8dfb0be656e5b9f10cb3a97e735e6ebf41d68a37 100644
--- a/Code/Mantid/Framework/SINQ/test/PoldiPeakCollectionTest.h
+++ b/Code/Mantid/Framework/SINQ/test/PoldiPeakCollectionTest.h
@@ -92,6 +92,91 @@ public:
         }
     }
 
+    void testProfileFunctionName()
+    {
+        TestablePoldiPeakCollection collection;
+
+        TS_ASSERT(collection.m_profileFunctionName.empty());
+
+        collection.setProfileFunctionName("Gaussian");
+
+        TS_ASSERT_EQUALS(collection.m_profileFunctionName, "Gaussian");
+    }
+
+    void testProfileFunctionRevovery()
+    {
+        TestablePoldiPeakCollection collection;
+        collection.setProfileFunctionName("Gaussian");
+
+        TableWorkspace_sptr table = collection.asTableWorkspace();
+
+        TestablePoldiPeakCollection other(table);
+
+        TS_ASSERT_EQUALS(other.getProfileFunctionName(), "Gaussian");
+        TS_ASSERT(other.hasProfileFunctionName());
+    }
+
+    void testMissingProfileFunction()
+    {
+        TestablePoldiPeakCollection collection(m_dummyData);
+        TS_ASSERT(!collection.hasProfileFunctionName());
+        TS_ASSERT(collection.getProfileFunctionName().empty());
+    }
+
+
+    void testIntensityTypeFromString()
+    {
+        TestablePoldiPeakCollection collection;
+
+        TS_ASSERT_EQUALS(collection.intensityTypeFromString("Maximum"), PoldiPeakCollection::Maximum);
+        TS_ASSERT_EQUALS(collection.intensityTypeFromString("maximum"), PoldiPeakCollection::Maximum);
+        TS_ASSERT_EQUALS(collection.intensityTypeFromString("mAxIMuM"), PoldiPeakCollection::Maximum);
+
+        TS_ASSERT_EQUALS(collection.intensityTypeFromString("Integral"), PoldiPeakCollection::Integral);
+        TS_ASSERT_EQUALS(collection.intensityTypeFromString("integral"), PoldiPeakCollection::Integral);
+        TS_ASSERT_EQUALS(collection.intensityTypeFromString("InTEgrAl"), PoldiPeakCollection::Integral);
+
+        TS_ASSERT_EQUALS(collection.intensityTypeFromString("Garbage"), PoldiPeakCollection::Maximum);
+        TS_ASSERT_EQUALS(collection.intensityTypeFromString(""), PoldiPeakCollection::Maximum);
+    }
+
+    void testIntensityTypeToString()
+    {
+        TestablePoldiPeakCollection collection;
+        TS_ASSERT_EQUALS(collection.intensityTypeToString(PoldiPeakCollection::Maximum), "Maximum");
+        TS_ASSERT_EQUALS(collection.intensityTypeToString(PoldiPeakCollection::Integral), "Integral");
+    }
+
+    void testIntensityTypeRecovery()
+    {
+        PoldiPeakCollection collection(m_dummyData);
+
+        TS_ASSERT_EQUALS(collection.intensityType(), PoldiPeakCollection::Maximum);
+
+        TableWorkspace_sptr newDummy(m_dummyData->clone());
+        newDummy->logs()->addProperty<std::string>("IntensityType", "Integral");
+
+        PoldiPeakCollection otherCollection(newDummy);
+        TS_ASSERT_EQUALS(otherCollection.intensityType(), PoldiPeakCollection::Integral);
+    }
+
+    void testIntensityTypeRecoveryConversion()
+    {
+        TableWorkspace_sptr newDummy(m_dummyData->clone());
+        newDummy->logs()->addProperty<std::string>("IntensityType", "Integral");
+
+        PoldiPeakCollection collection(newDummy);
+
+        TableWorkspace_sptr compare = collection.asTableWorkspace();
+
+        TS_ASSERT(compare->logs()->hasProperty("IntensityType"));
+        TS_ASSERT_EQUALS(compare->logs()->getPropertyValueAsType<std::string>("IntensityType"), "Integral");
+
+        PoldiPeakCollection otherCollection(compare);
+
+        TS_ASSERT_EQUALS(otherCollection.intensityType(), PoldiPeakCollection::Integral);
+    }
+
     void testAddPeak()
     {
         PoldiPeakCollection peaks;
@@ -123,6 +208,32 @@ public:
         TS_ASSERT(peaks.checkColumns(newTable));
     }
 
+    void testClone()
+    {
+        PoldiPeakCollection_sptr peaks(new PoldiPeakCollection);
+        peaks->setProfileFunctionName("Test");
+        peaks->addPeak(PoldiPeak::create(2.0));
+        peaks->addPeak(PoldiPeak::create(3.0));
+
+        PoldiPeakCollection_sptr clone = peaks->clone();
+
+        // make sure those are different instances
+        TS_ASSERT(clone != peaks);
+
+        // everything else should be identical
+        TS_ASSERT_EQUALS(clone->getProfileFunctionName(), peaks->getProfileFunctionName());
+        TS_ASSERT_EQUALS(clone->intensityType(), peaks->intensityType());
+        TS_ASSERT_EQUALS(clone->peakCount(), peaks->peakCount());
+
+        for(size_t i = 0; i < clone->peakCount(); ++i) {
+            PoldiPeak_sptr clonePeak = clone->peak(i);
+            PoldiPeak_sptr peaksPeak = peaks->peak(i);
+
+            TS_ASSERT(clonePeak != peaksPeak);
+            TS_ASSERT_EQUALS(clonePeak->d(), peaksPeak->d());
+        }
+    }
+
 
 private:
     TableWorkspace_sptr m_dummyData;
diff --git a/Code/Mantid/Framework/SINQ/test/PoldiPeakSearchTest.h b/Code/Mantid/Framework/SINQ/test/PoldiPeakSearchTest.h
index 0ceff771a3ab4fb4962f8a9205d8b8b2ec15ceb3..3943c28988129fe5d2df1e3428e452c0543d2684 100644
--- a/Code/Mantid/Framework/SINQ/test/PoldiPeakSearchTest.h
+++ b/Code/Mantid/Framework/SINQ/test/PoldiPeakSearchTest.h
@@ -114,10 +114,14 @@ public:
         double testListRaw[] = {2.0, -3.0, -2.0, 12.0, 3.0 };
         std::vector<double> baseData(testListRaw, testListRaw + 5);
 
+        TS_ASSERT_EQUALS(poldiPeakSearch.m_recursionBordersInitialized, false);
+
         poldiPeakSearch.setRecursionAbsoluteBorders(baseData.begin(), baseData.end());
 
         TS_ASSERT_EQUALS(poldiPeakSearch.m_recursionAbsoluteBegin, baseData.begin());
         TS_ASSERT_EQUALS(poldiPeakSearch.m_recursionAbsoluteEnd, baseData.end());
+
+        TS_ASSERT_EQUALS(poldiPeakSearch.m_recursionBordersInitialized, true);
     }
 
     void testgetLeftRangeBegin()
diff --git a/Code/Mantid/Framework/SINQ/test/PoldiPeakTest.h b/Code/Mantid/Framework/SINQ/test/PoldiPeakTest.h
index 0856bba30026f3355d90f56f0f75c6fefd008a92..7ea4ebf8de7e97193384b0d108c65e1f6148a8d0 100644
--- a/Code/Mantid/Framework/SINQ/test/PoldiPeakTest.h
+++ b/Code/Mantid/Framework/SINQ/test/PoldiPeakTest.h
@@ -175,6 +175,17 @@ public:
         TS_ASSERT_EQUALS(peaks[1]->q(), 1.0);
         TS_ASSERT_EQUALS(peaks[2]->q(), 3.0);
     }
+
+    void testClone()
+    {
+        PoldiPeak_sptr peak = PoldiPeak::create(1.0, 200.00);
+        PoldiPeak_sptr clone = peak->clone();
+
+        TS_ASSERT_EQUALS(peak->d(), clone->d());
+        TS_ASSERT_EQUALS(peak->fwhm(), clone->fwhm());
+        TS_ASSERT_EQUALS(peak->intensity(), clone->intensity());
+        TS_ASSERT_EQUALS(peak->hkl(), clone->hkl());
+    }
 };
 
 #endif // MANTID_SINQ_POLDIPEAKTEST_H
diff --git a/Code/Mantid/Framework/SINQ/test/PoldiSpectrumDomainFunctionTest.h b/Code/Mantid/Framework/SINQ/test/PoldiSpectrumDomainFunctionTest.h
new file mode 100644
index 0000000000000000000000000000000000000000..3b6dbc2b42ce42756d26b7c84b73a350f19f2574
--- /dev/null
+++ b/Code/Mantid/Framework/SINQ/test/PoldiSpectrumDomainFunctionTest.h
@@ -0,0 +1,210 @@
+#ifndef MANTID_SINQ_POLDISPECTRUMDOMAINFUNCTIONTEST_H_
+#define MANTID_SINQ_POLDISPECTRUMDOMAINFUNCTIONTEST_H_
+
+#include <cxxtest/TestSuite.h>
+#include <gtest/gtest.h>
+#include <gmock/gmock.h>
+
+#include "MantidSINQ/PoldiUtilities/PoldiSpectrumDomainFunction.h"
+#include "MantidSINQ/PoldiUtilities/PoldiMockInstrumentHelpers.h"
+#include "MantidSINQ/PoldiUtilities/PoldiInstrumentAdapter.h"
+#include "MantidAPI/FunctionDomain1D.h"
+#include "MantidAPI/FunctionValues.h"
+#include "MantidAPI/MultiDomainFunction.h"
+#include "MantidCurveFitting/Gaussian.h"
+#include "MantidCurveFitting/FitMW.h"
+
+using ::testing::Return;
+
+using namespace Mantid::Poldi;
+using namespace Mantid::API;
+using namespace Mantid::CurveFitting;
+
+class PoldiSpectrumDomainFunctionTest : public CxxTest::TestSuite
+{
+public:
+    // This pair of boilerplate methods prevent the suite being created statically
+    // This means the constructor isn't called when running other tests
+    static PoldiSpectrumDomainFunctionTest *createSuite() { return new PoldiSpectrumDomainFunctionTest(); }
+    static void destroySuite( PoldiSpectrumDomainFunctionTest *suite ) { delete suite; }
+
+    PoldiSpectrumDomainFunctionTest()
+    {
+        m_detector = boost::shared_ptr<ConfiguredHeliumDetector>(new ConfiguredHeliumDetector);
+        m_chopper = boost::shared_ptr<MockChopper>(new MockChopper);
+
+        m_spectrum = PoldiSourceSpectrum_sptr(new ConfiguredSpectrum);
+
+        EXPECT_CALL(*m_chopper, distanceFromSample())
+                .WillRepeatedly(Return(11800.0));
+
+        EXPECT_CALL(*m_chopper, zeroOffset())
+                .WillRepeatedly(Return(0.15));
+
+        m_instrument = PoldiInstrumentAdapter_sptr(new FakePoldiInstrumentAdapter);
+    }
+
+
+    void testInit()
+    {
+        PoldiSpectrumDomainFunction function;
+        function.initialize();
+
+        std::vector<std::string> parameterNames = function.getParameterNames();
+
+        TS_ASSERT_EQUALS(parameterNames[0], "Area");
+        TS_ASSERT_EQUALS(parameterNames[1], "Fwhm");
+        TS_ASSERT_EQUALS(parameterNames[2], "Centre");
+    }
+
+    void testChopperSlitOffsets()
+    {
+        TestablePoldiSpectrumDomainFunction function;
+
+        std::vector<double> offsets = function.getChopperSlitOffsets(m_chopper);
+
+        for(size_t i = 0; i < offsets.size(); ++i) {
+            TS_ASSERT_EQUALS(offsets[i], m_chopper->slitTimes()[i] + m_chopper->zeroOffset());
+        }
+    }
+
+    void testInitializeFromInstrument()
+    {
+        TestablePoldiSpectrumDomainFunction function;
+        function.initializeInstrumentParameters(m_instrument);
+
+        TS_ASSERT_EQUALS(function.m_chopperSlitOffsets.size(), m_chopper->slitPositions().size());
+    }
+
+    void testActualFunction()
+    {
+        /* comparison with results from a math program */
+        double area = 1.0;
+        double sigma = 1.0;
+        double x0 = 0.0;
+
+        std::vector<double> reference;
+        reference.push_back(0.388349126567583);
+        reference.push_back(0.398942280401433);
+        reference.push_back(0.359646701831886);
+        reference.push_back(0.004431848411938);
+
+        TestablePoldiSpectrumDomainFunction function;
+
+        std::vector<double> x;
+        x.push_back(-0.232);
+        x.push_back(0.0);
+        x.push_back(0.4554);
+        x.push_back(3.0);
+
+        for(size_t i = 0; i < x.size(); ++i) {
+            TS_ASSERT_DELTA(function.actualFunction(x[i], x0, sigma, area), reference[i], 1e-15);
+        }
+    }
+
+    void testFunction()
+    {
+        TestablePoldiSpectrumDomainFunction function;
+        function.initialize();
+        function.setParameter("Area", 1.9854805);
+        function.setParameter("Fwhm", 0.0027446316797104233);
+        function.setParameter("Centre", 1.1086444);
+
+        function.initializeInstrumentParameters(m_instrument);
+        function.m_deltaT = 3.0;
+
+        std::vector<double> xvalues(500, 1.0);
+
+        FunctionDomain1DSpectrum domain(342, xvalues);
+        TS_ASSERT_EQUALS(domain.getWorkspaceIndex(), 342);
+        FunctionValues values(domain);
+        values.setCalculated(0.0);
+
+        function.function(domain, values);
+
+        std::vector<double> reference;
+        reference.push_back(2.5469337E-05);
+        reference.push_back(2.4222479E-04);
+        reference.push_back(1.7575109E-03);
+        reference.push_back(9.7287362E-03);
+        reference.push_back(4.1085955E-02);
+        reference.push_back(0.1323760);
+        reference.push_back(0.3253897);
+        reference.push_back(0.6102068);
+        reference.push_back(0.8730301);
+        reference.push_back(0.9529279);
+        reference.push_back(0.7935416);
+        reference.push_back(0.5041480);
+        reference.push_back(0.2443572);
+        reference.push_back(9.0358935E-02);
+        reference.push_back(2.5491528E-02);
+        reference.push_back(5.4865498E-03);
+        reference.push_back(9.0091029E-04);
+        reference.push_back(1.1286059E-04);
+        reference.push_back(1.0786535E-05);
+
+        for(size_t i = 0; i < reference.size(); ++i) {
+            TS_ASSERT_DELTA(values[479 + i], reference[i], 9e-5);
+        }
+    }
+
+    void testAccessThroughBasePointer()
+    {
+        TestablePoldiSpectrumDomainFunction *function = new TestablePoldiSpectrumDomainFunction();
+        function->initialize();
+        function->setParameter("Area", 1.9854805);
+        function->setParameter("Fwhm", 0.0027446316797104233);
+        function->setParameter("Centre", 1.1086444);
+
+        function->initializeInstrumentParameters(m_instrument);
+        function->m_deltaT = 3.0;
+
+        TS_ASSERT_EQUALS(function->getParameter(2), 1.1086444);
+
+        MultiDomainFunction *mdf = new MultiDomainFunction();
+        mdf->addFunction(IFunction_sptr(dynamic_cast<IFunction *>(function)));
+
+        TS_ASSERT_EQUALS(static_cast<IFunction*>(mdf)->getParameter(2), 1.1086444);
+    }
+
+   /*
+    * This test must be re-enabled, when #9497 is fixed, then it will pass.
+    *
+    void ___testCreateInitialized()
+    {
+        IFunction_sptr function(new Gaussian());
+        function->initialize();
+        function->setParameter(0, 1.23456);
+        function->setParameter(1, 1.234567);
+        function->setParameter(2, 0.01234567);
+
+        IFunction_sptr clone = function->clone();
+
+        // passes, Parameter 0 has less than 7 significant digits
+        TS_ASSERT_EQUALS(function->getParameter(0), clone->getParameter(0));
+
+        // fails, Parameter 1 has more than 7 significant digits
+        TS_ASSERT_EQUALS(function->getParameter(1), clone->getParameter(1));
+
+        // fails, Parameter 2 has more than 7 significant digits
+        TS_ASSERT_EQUALS(function->getParameter(2), clone->getParameter(2));
+    }
+    */
+
+private:
+    class TestablePoldiSpectrumDomainFunction : PoldiSpectrumDomainFunction
+    {
+        friend class PoldiSpectrumDomainFunctionTest;
+
+        TestablePoldiSpectrumDomainFunction() : PoldiSpectrumDomainFunction() {}
+    };
+
+    boost::shared_ptr<ConfiguredHeliumDetector> m_detector;
+    boost::shared_ptr<MockChopper> m_chopper;
+    PoldiSourceSpectrum_sptr m_spectrum;
+
+    PoldiInstrumentAdapter_sptr m_instrument;
+};
+
+
+#endif /* MANTID_SINQ_POLDISPECTRUMDOMAINFUNCTIONTEST_H_ */
diff --git a/Code/Mantid/Framework/SINQ/test/PoldiTimeTransformerTest.h b/Code/Mantid/Framework/SINQ/test/PoldiTimeTransformerTest.h
new file mode 100644
index 0000000000000000000000000000000000000000..1c238e4304fb5bdfcd1055b4666ceef3b6c2156f
--- /dev/null
+++ b/Code/Mantid/Framework/SINQ/test/PoldiTimeTransformerTest.h
@@ -0,0 +1,163 @@
+#ifndef MANTID_SINQ_POLDITIMETRANSFORMERTEST_H_
+#define MANTID_SINQ_POLDITIMETRANSFORMERTEST_H_
+
+#include <cxxtest/TestSuite.h>
+#include <gtest/gtest.h>
+#include <gmock/gmock.h>
+
+#include "MantidSINQ/PoldiUtilities/PoldiTimeTransformer.h"
+#include "MantidSINQ/PoldiUtilities/PoldiMockInstrumentHelpers.h"
+
+using namespace Mantid::Poldi;
+
+using ::testing::Return;
+
+class PoldiTimeTransformerTest : public CxxTest::TestSuite
+{
+public:
+  // This pair of boilerplate methods prevent the suite being created statically
+  // This means the constructor isn't called when running other tests
+  static PoldiTimeTransformerTest *createSuite() { return new PoldiTimeTransformerTest(); }
+  static void destroySuite( PoldiTimeTransformerTest *suite ) { delete suite; }
+
+  PoldiTimeTransformerTest()
+  {
+      m_detector = boost::shared_ptr<ConfiguredHeliumDetector>(new ConfiguredHeliumDetector);
+      m_chopper = boost::shared_ptr<MockChopper>(new MockChopper);
+
+      m_spectrum = PoldiSourceSpectrum_sptr(new ConfiguredSpectrum);
+
+      EXPECT_CALL(*m_chopper, distanceFromSample())
+              .WillRepeatedly(Return(11800.0));
+
+      EXPECT_CALL(*m_chopper, zeroOffset())
+              .WillRepeatedly(Return(0.15));
+
+      m_instrument = PoldiInstrumentAdapter_sptr(new FakePoldiInstrumentAdapter);
+  }
+
+  void testDetectorCharacteristics()
+  {
+      double distance = 1996.017;
+      double tof1A = 4947.990;
+      double twoTheta = 1.577358;
+
+      double sinTheta = 0.70942287322834615878;
+      double cosTheta = 0.70478307793280472246;
+
+      DetectorElementCharacteristics characteristics(static_cast<int>(m_detector->centralElement()), m_detector, m_chopper);
+
+      TS_ASSERT_DELTA(characteristics.twoTheta, twoTheta, 1e-6);
+      TS_ASSERT_DELTA(characteristics.distance, distance, 1e-3);
+      TS_ASSERT_DELTA(characteristics.totalDistance, distance + 11800.0, 1e-3);
+      TS_ASSERT_DELTA(characteristics.tof1A, tof1A, 1e-3);
+      TS_ASSERT_DELTA(characteristics.sinTheta, sinTheta, 1e-6);
+      TS_ASSERT_DELTA(characteristics.cosTheta, cosTheta, 1e-6);
+
+      TestablePoldiTimeTransformer transformer;
+      DetectorElementCharacteristics center = transformer.getDetectorCenterCharacteristics(m_detector, m_chopper);
+
+      TS_ASSERT_EQUALS(characteristics.twoTheta, center.twoTheta);
+      TS_ASSERT_EQUALS(characteristics.distance, center.distance);
+      TS_ASSERT_EQUALS(characteristics.totalDistance, center.totalDistance);
+      TS_ASSERT_EQUALS(characteristics.tof1A, center.tof1A);
+      TS_ASSERT_EQUALS(characteristics.sinTheta, center.sinTheta);
+      TS_ASSERT_EQUALS(characteristics.cosTheta, center.cosTheta);
+  }
+
+  void testDetectorFactors()
+  {
+      DetectorElementCharacteristics center(static_cast<int>(m_detector->centralElement()), m_detector, m_chopper);
+
+      DetectorElementData data(102, center, m_detector, m_chopper);
+
+      TS_ASSERT_DELTA(data.intensityFactor(), 1.010685, 1e-6);
+      TS_ASSERT_DELTA(data.lambdaFactor(), 2.6941614e-4, 1e-11);
+      TS_ASSERT_DELTA(data.timeFactor(), 0.9346730, 1e-7);
+  }
+
+  void testGetDetectorElementData()
+  {
+      TestablePoldiTimeTransformer transformer;
+      std::vector<DetectorElementData_const_sptr> elements = transformer.getDetectorElementData(m_detector, m_chopper);
+      DetectorElementCharacteristics center = transformer.getDetectorCenterCharacteristics(m_detector, m_chopper);
+
+      DetectorElementData data(102, center, m_detector, m_chopper);
+
+      TS_ASSERT_EQUALS(data.intensityFactor(), elements[102]->intensityFactor());
+      TS_ASSERT_DELTA(data.lambdaFactor(), 2.6941614e-4, 1e-11);
+      TS_ASSERT_DELTA(data.timeFactor(), 0.9346730, 1e-7);
+  }
+
+  void testInitializationFromInstrument()
+  {
+      TestablePoldiTimeTransformer transformer;
+
+      TS_ASSERT_THROWS_NOTHING(transformer.initializeFromPoldiInstrument(m_instrument));
+
+      PoldiInstrumentAdapter_sptr invalid;
+      TS_ASSERT_THROWS(transformer.initializeFromPoldiInstrument(invalid), std::invalid_argument);
+  }
+
+  void testTimeTransformedWidth()
+  {
+      /* Values from existing analysis software */
+      double fwhm = 0.0027446316797104233;
+      double deltaT = 3.0;
+
+      TestablePoldiTimeTransformer function;
+      function.initializeFromPoldiInstrument(m_instrument);
+
+      TS_ASSERT_DELTA(function.timeTransformedWidth(fwhm, 342) / deltaT, 4.526804, 1e-5);
+  }
+
+  void testTimeTransformedCentre()
+  {
+      double centre = 1.10864434901480127601;
+
+      TestablePoldiTimeTransformer function;
+      function.initializeFromPoldiInstrument(m_instrument);
+
+      TS_ASSERT_DELTA(function.timeTransformedCentre(centre, 342), 5964.820800781, 1e-3);
+  }
+
+  void testTimeTransformedIntensity()
+  {
+      double centre = 1.10864434901480127601;
+      double areaD = 1.985481;
+
+      TestablePoldiTimeTransformer function;
+      function.initializeFromPoldiInstrument(m_instrument);
+
+      TS_ASSERT_DELTA(function.timeTransformedIntensity(areaD, centre, 342), 4.611182, 1e-5);
+  }
+
+  void TestCalculatedTotalIntensity()
+  {
+      double centre = Conversions::qToD(5.667449);
+
+      TestablePoldiTimeTransformer function;
+      function.initializeFromPoldiInstrument(m_instrument);
+      function.m_chopperSlits = 8;
+
+      TS_ASSERT_DELTA(fabs(1.0 - function.calculatedTotalIntensity(centre)/8220.165039062), 0.0, 1e-7);
+  }
+
+
+private:
+  class TestablePoldiTimeTransformer : PoldiTimeTransformer
+  {
+      friend class PoldiTimeTransformerTest;
+
+      TestablePoldiTimeTransformer() : PoldiTimeTransformer() {}
+  };
+
+  boost::shared_ptr<ConfiguredHeliumDetector> m_detector;
+  boost::shared_ptr<MockChopper> m_chopper;
+  PoldiSourceSpectrum_sptr m_spectrum;
+
+  PoldiInstrumentAdapter_sptr m_instrument;
+};
+
+
+#endif /* MANTID_SINQ_POLDITIMETRANSFORMERTEST_H_ */
diff --git a/Code/Mantid/Framework/TestHelpers/inc/MantidTestHelpers/WorkspaceCreationHelper.h b/Code/Mantid/Framework/TestHelpers/inc/MantidTestHelpers/WorkspaceCreationHelper.h
index 175a8417954e4937a6f0ec7263bd584a569625b2..a764f7da0bf48d050a7b3e2008386ee11a8d8afe 100644
--- a/Code/Mantid/Framework/TestHelpers/inc/MantidTestHelpers/WorkspaceCreationHelper.h
+++ b/Code/Mantid/Framework/TestHelpers/inc/MantidTestHelpers/WorkspaceCreationHelper.h
@@ -251,6 +251,9 @@ namespace WorkspaceCreationHelper
   // create range of angular detectors positions
   void create2DAngles(std::vector<double> &L2,std::vector<double> &polar,std::vector<double> &azim,
                       size_t nPolar=10,size_t nAzim=10,double polStart=0,double polEnd=90,double azimStart=-30,double azimEnd=30);
+
+  /// Create a 2D workspace with one detector and one monitor based around a virtual reflectometry instrument.
+  Mantid::API::MatrixWorkspace_sptr create2DWorkspaceWithReflectometryInstrument(double startX=0);
 }
 
 #endif /*WORKSPACECREATIONHELPER_H_*/
diff --git a/Code/Mantid/Framework/TestHelpers/src/WorkspaceCreationHelper.cpp b/Code/Mantid/Framework/TestHelpers/src/WorkspaceCreationHelper.cpp
index 5a3c1b45bc8e0ea68a2c317018d5a89e8c75b1b7..b7c840e701730ad002b4a02da2797c79871e8753 100644
--- a/Code/Mantid/Framework/TestHelpers/src/WorkspaceCreationHelper.cpp
+++ b/Code/Mantid/Framework/TestHelpers/src/WorkspaceCreationHelper.cpp
@@ -471,6 +471,52 @@ namespace WorkspaceCreationHelper
     return ws;
   }
 
+  /**
+   * Create a very small 2D workspace for a virtual reflectometry instrument.
+   * @return workspace with instrument attached.
+   * @param startX : X Tof start value for the workspace.
+   */
+  MatrixWorkspace_sptr create2DWorkspaceWithReflectometryInstrument(double startX)
+  {
+    Instrument_sptr instrument = boost::make_shared<Instrument>();
+    instrument->setReferenceFrame(boost::make_shared<ReferenceFrame>(Y, X, Left, "0,0,0"));
+
+    ObjComponent *source = new ObjComponent("source");
+    source->setPos(V3D(0, 0, 0));
+    instrument->add(source);
+    instrument->markAsSource(source);
+
+    Detector* monitor = new Detector("Monitor", 1, NULL);
+    monitor->setPos(14, 0, 0);
+    instrument->add(monitor);
+    instrument->markAsMonitor(monitor);
+
+    ObjComponent *sample = new ObjComponent("some-surface-holder");
+    source->setPos(V3D(15, 0, 0));
+    instrument->add(sample);
+    instrument->markAsSamplePos(sample);
+
+    Detector* det = new Detector("point-detector", 2, NULL);
+    det->setPos(20, (20 - sample->getPos().X()), 0);
+    instrument->add(det);
+    instrument->markAsDetector(det);
+
+    const int nSpectra = 2;
+    const int nBins = 100;
+    const double deltaX = 2000; //TOF
+    auto workspace = Create2DWorkspaceBinned(nSpectra, nBins, startX, deltaX);
+
+    workspace->setTitle("Test histogram"); // actually adds a property call run_title to the logs
+    workspace->getAxis(0)->setUnit("TOF");
+    workspace->setYUnit("Counts");
+
+    workspace->setInstrument(instrument);
+
+    workspace->getSpectrum(0)->addDetectorID(det->getID());
+    workspace->getSpectrum(1)->addDetectorID(monitor->getID());
+    return workspace;
+  }
+
   //================================================================================================================
   WorkspaceSingleValue_sptr CreateWorkspaceSingleValue(double value)
   {
@@ -782,6 +828,7 @@ namespace WorkspaceCreationHelper
   {
     OrientedLattice * latt = new OrientedLattice(a,b,c, 90., 90., 90.);
     ws->mutableSample().setOrientedLattice(latt);
+    delete latt;
   }
 
   // =====================================================================================
@@ -819,6 +866,7 @@ namespace WorkspaceCreationHelper
     if(has_oriented_lattice){
         OrientedLattice * latt = new OrientedLattice(1,1,1, 90., 90., 90.);
         ws->mutableSample().setOrientedLattice(latt);
+        delete latt;
 
         AddTSPEntry( ws->mutableRun(), "phi", 0);
         AddTSPEntry( ws->mutableRun(), "chi", 0);
@@ -890,6 +938,7 @@ namespace WorkspaceCreationHelper
  // define oriented lattice which requested for processed ws   
     OrientedLattice * latt = new OrientedLattice(1,1,1, 90., 90., 90.);
     ws->mutableSample().setOrientedLattice(latt);
+    delete latt;
 
     //TODO: clarify if this property indeed goes there;
     ws->mutableRun().addProperty(new PropertyWithValue<double>("Ei", Ei),true);
diff --git a/Code/Mantid/Framework/WorkflowAlgorithms/src/SetupEQSANSReduction.cpp b/Code/Mantid/Framework/WorkflowAlgorithms/src/SetupEQSANSReduction.cpp
index 66853e3ac39262e6ef0910e5f2b1eee7a1824d82..d4b25fc062a5a92702b20b7b7ae4518c61d63e76 100644
--- a/Code/Mantid/Framework/WorkflowAlgorithms/src/SetupEQSANSReduction.cpp
+++ b/Code/Mantid/Framework/WorkflowAlgorithms/src/SetupEQSANSReduction.cpp
@@ -38,13 +38,13 @@ void SetupEQSANSReduction::init()
   declareProperty("UseConfig", true, "If true, the best configuration file found will be used");
   declareProperty("CorrectForFlightPath", false, "If true, the TOF will be modified for the true flight path from the sample to the detector pixel");
 
-  declareProperty("SkipTOFCorrection", false, "IF true, the EQSANS TOF correction will be skipped");
+  declareProperty("SkipTOFCorrection", false, "If true, the EQSANS TOF correction will be skipped");
   declareProperty("PreserveEvents", true, "If true, the output workspace will be an event workspace");
 
   declareProperty("SampleDetectorDistance", EMPTY_DBL(), "Sample to detector distance to use (overrides meta data), in mm");
   declareProperty("SampleDetectorDistanceOffset", EMPTY_DBL(), "Offset to the sample to detector distance (use only when using the distance found in the meta data), in mm");
 
-  declareProperty("SolidAngleCorrection", true, "If true, the solide angle correction will be applied to the data");
+  declareProperty("SolidAngleCorrection", true, "If true, the solid angle correction will be applied to the data");
   declareProperty("DetectorTubes", false, "If true, the solid angle correction for tube detectors will be applied");
 
   // -- Define group --
@@ -742,6 +742,11 @@ void SetupEQSANSReduction::exec()
     reductionManager->declareProperty(algProp);
   }
   setPropertyValue("OutputMessage", "EQSANS reduction options set");
+
+  // Save a string representation of this algorithm
+  algProp = new AlgorithmProperty("SetupAlgorithm");
+  algProp->setValue(toString());
+  reductionManager->declareProperty(algProp);
 }
 
 void SetupEQSANSReduction::setupSensitivity(boost::shared_ptr<PropertyManager> reductionManager)
@@ -789,7 +794,7 @@ void SetupEQSANSReduction::setupSensitivity(boost::shared_ptr<PropertyManager> r
          ctrAlg->setProperty("Filename", beamCenterFile);
          ctrAlg->setProperty("UseDirectBeamMethod", useDirectBeam);
          ctrAlg->setProperty("PersistentCorrection", false);
-         if (useDirectBeam && !isEmpty(sensitivityBeamRadius))
+         if (!isEmpty(sensitivityBeamRadius))
            ctrAlg->setProperty("BeamRadius", sensitivityBeamRadius);
          ctrAlg->setPropertyValue("ReductionProperties", reductionManagerName);
 
diff --git a/Code/Mantid/Framework/WorkflowAlgorithms/src/SetupHFIRReduction.cpp b/Code/Mantid/Framework/WorkflowAlgorithms/src/SetupHFIRReduction.cpp
index bd188967e515c46abc20777eecb7ecaeb3025106..322ed051d4cedafb3b12c41f5e06c239a8985568 100644
--- a/Code/Mantid/Framework/WorkflowAlgorithms/src/SetupHFIRReduction.cpp
+++ b/Code/Mantid/Framework/WorkflowAlgorithms/src/SetupHFIRReduction.cpp
@@ -717,6 +717,11 @@ void SetupHFIRReduction::exec()
   }
 
   setPropertyValue("OutputMessage", "HFIR reduction options set");
+
+  // Save a string representation of this algorithm
+  algProp = new AlgorithmProperty("SetupAlgorithm");
+  algProp->setValue(toString());
+  reductionManager->declareProperty(algProp);
 }
 
 void SetupHFIRReduction::setupSensitivity(boost::shared_ptr<PropertyManager> reductionManager)
diff --git a/Code/Mantid/MantidPlot/src/ApplicationWindow.cpp b/Code/Mantid/MantidPlot/src/ApplicationWindow.cpp
index 5d79814292d0d2284eb326223d03220f229590fa..c0314dd89cafee3da7a23556b34297b83e56fa66 100644
--- a/Code/Mantid/MantidPlot/src/ApplicationWindow.cpp
+++ b/Code/Mantid/MantidPlot/src/ApplicationWindow.cpp
@@ -201,6 +201,7 @@
 #include "MantidQtMantidWidgets/MuonFitPropertyBrowser.h"
 
 #include "MantidKernel/ConfigService.h"
+#include "MantidKernel/LibraryManager.h"
 #include "MantidKernel/Logger.h"
 #include "MantidKernel/MantidVersion.h"
 
@@ -219,6 +220,8 @@ namespace
 {
   /// static logger
   Mantid::Kernel::Logger g_log("ApplicationWindow");
+  /// ParaView plugins key
+  const char * PVPLUGINS_DIR_KEY = "pvplugins.directory";
 }
 
 extern "C"
@@ -355,10 +358,16 @@ void ApplicationWindow::init(bool factorySettings, const QStringList& args)
   trySetParaviewPath(args);
 
   using Mantid::Kernel::ConfigService;
-  ConfigService::Instance(); // Starts logging
+  auto & config = ConfigService::Instance(); // Starts logging
   resultsLog->attachLoggingChannel(); // Must be done after logging starts
   using Mantid::API::FrameworkManager;
-  FrameworkManager::Instance(); // Starts logging
+  auto & framework = FrameworkManager::Instance(); // Loads framework libraries
+  // Load Paraview plugin libraries if possible
+  if(config.quickParaViewCheck())
+  {
+    // load paraview plugins
+    framework.loadPluginsUsingKey(PVPLUGINS_DIR_KEY);
+  }
 
   // Create UI object
   mantidUI = new MantidUI(this);
@@ -574,8 +583,6 @@ void ApplicationWindow::init(bool factorySettings, const QStringList& args)
   }
 
   // Need to show first time setup dialog?
-  using Mantid::Kernel::ConfigServiceImpl;
-  ConfigServiceImpl& config = ConfigService::Instance();
   std::string facility = config.getString("default.facility");
   std::string instrument = config.getString("default.instrument");
   if ( facility.empty() || instrument.empty() )
@@ -879,15 +886,17 @@ void ApplicationWindow::initGlobalConstants()
   d_ASCII_import_read_only = false;
   d_ASCII_import_preview = true;
   d_preview_lines = 100;
+
 #ifdef Q_OS_MAC
-  d_ASCII_end_line = CR;
   d_eol = CR;
 #else
-  d_ASCII_end_line = LF;
+#ifdef _WIN32
+  d_eol = CRLF;
+#else
   d_eol = LF;
+#endif
 #endif
 
-  d_export_col_separator = "\t";
   d_export_col_names = false;
   d_export_col_comment = false;
   d_export_table_selection = false;
@@ -901,7 +910,6 @@ void ApplicationWindow::initGlobalConstants()
 
   //	QPrinterInfo::availablePrinters();
 
-
   //	d_export_resolution = QPrinter().resolution();
   d_export_color = true;
   d_export_vector_size = static_cast<int>(QPrinter::Custom);
@@ -931,7 +939,7 @@ void ApplicationWindow::initToolBars()
   addToolBar( Qt::TopToolBarArea, standardTools );
 
   standardTools->addAction(actionLoadFile);
-   standardTools->addSeparator ();
+  standardTools->addSeparator ();
   standardTools->addAction(actionNewProject);
   standardTools->addAction(actionOpenProj);
   standardTools->addAction(actionSaveProject);
@@ -4134,7 +4142,7 @@ ApplicationWindow * ApplicationWindow::plotFile(const QString& fn)
 
   t->importASCII(fn, app->columnSeparator, 0, app->renameColumns, app->strip_spaces, app->simplify_spaces,
       app->d_ASCII_import_comments, app->d_ASCII_comment_string,
-      app->d_ASCII_import_read_only, Table::Overwrite, app->d_ASCII_end_line);
+      app->d_ASCII_import_read_only, Table::Overwrite, app->d_eol);
   t->setCaptionPolicy(MdiSubWindow::Both);
   app->multilayerPlot(t, t->YColumns(),Graph::LineSymbols);
   QApplication::restoreOverrideCursor();
@@ -4160,7 +4168,7 @@ void ApplicationWindow::importASCII()
   d_ASCII_comment_string = import_dialog->commentString();
   d_ASCII_import_comments = import_dialog->importComments();
   d_ASCII_import_read_only = import_dialog->readOnly();
-  d_ASCII_end_line = (EndLineChar)import_dialog->endLineChar();
+  d_eol = (EndLineChar)import_dialog->endLineChar();
   saveSettings();
 
   importASCII(import_dialog->selectedFiles(),
@@ -5356,12 +5364,9 @@ void ApplicationWindow::readSettings()
   d_ASCII_import_read_only = settings.value("/ImportReadOnly", false).toBool();
   d_ASCII_import_preview = settings.value("/Preview", true).toBool();
   d_preview_lines = settings.value("/PreviewLines", 100).toInt();
-  d_ASCII_end_line = (EndLineChar)settings.value("/EndLineCharacter", d_ASCII_end_line).toInt();
   settings.endGroup(); // Import ASCII
 
   settings.beginGroup("/ExportASCII");
-  d_export_col_separator = settings.value("/ColumnSeparator", "\\t").toString();
-  d_export_col_separator.replace("\\t", "\t").replace("\\s", " ");
   d_export_col_names = settings.value("/ExportLabels", false).toBool();
   d_export_col_comment = settings.value("/ExportComments", false).toBool();
 
@@ -5744,12 +5749,9 @@ void ApplicationWindow::saveSettings()
   settings.setValue("/ImportReadOnly", d_ASCII_import_read_only);
   settings.setValue("/Preview", d_ASCII_import_preview);
   settings.setValue("/PreviewLines", d_preview_lines);
-  settings.setValue("/EndLineCharacter", (int)d_ASCII_end_line);
   settings.endGroup(); // ImportASCII
 
   settings.beginGroup("/ExportASCII");
-  sep = d_export_col_separator;
-  settings.setValue("/ColumnSeparator", sep.replace("\t", "\\t").replace(" ", "\\s"));
   settings.setValue("/ExportLabels", d_export_col_names);
   settings.setValue("/ExportComments", d_export_col_comment);
   settings.setValue("/ExportSelection", d_export_table_selection);
@@ -6563,6 +6565,7 @@ void ApplicationWindow::showExportASCIIDialog()
 
     ExportDialog* ed = new ExportDialog(tableName, this, Qt::WindowContextHelpButtonHint);
     ed->setAttribute(Qt::WA_DeleteOnClose);
+    ed->setColumnSeparator(columnSeparator);
     ed->exec();
   }
 }
diff --git a/Code/Mantid/MantidPlot/src/ApplicationWindow.h b/Code/Mantid/MantidPlot/src/ApplicationWindow.h
index 8efbb977b6b30d49e8185005dde47e6e85a97ad5..a4308ac508da80db50944e2fd1749ccd18eb4232 100644
--- a/Code/Mantid/MantidPlot/src/ApplicationWindow.h
+++ b/Code/Mantid/MantidPlot/src/ApplicationWindow.h
@@ -1322,7 +1322,7 @@ public:
   QFont appFont, plot3DTitleFont, plot3DNumbersFont, plot3DAxesFont;
   QFont tableTextFont, tableHeaderFont, plotAxesFont, plotLegendFont, plotNumbersFont, plotTitleFont;
   QColor tableBkgdColor, tableTextColor, tableHeaderColor;
-  QString projectname,columnSeparator, helpFilePath, appLanguage;
+  QString projectname, columnSeparator, helpFilePath, appLanguage;
   QString configFilePath, fitPluginsPath, fitModelsPath, asciiDirPath, imagesDirPath, scriptsDirPath;
   int ignoredLines, savingTimerId, plot3DResolution, recentMenuID;
   bool renameColumns, strip_spaces, simplify_spaces;
diff --git a/Code/Mantid/MantidPlot/src/ConfigDialog.cpp b/Code/Mantid/MantidPlot/src/ConfigDialog.cpp
index a58a58fb74e49610681e38177ad9ab8cde86f03b..1743a0b12c8e1068111a990fb59745a70a704b8f 100644
--- a/Code/Mantid/MantidPlot/src/ConfigDialog.cpp
+++ b/Code/Mantid/MantidPlot/src/ConfigDialog.cpp
@@ -1962,18 +1962,18 @@ void ConfigDialog::languageChange()
 
   //Fitting page
   cbEnableQtiPlotFitting->setText(tr("Enable QtiPlot fitting"));
+  cbEnableQtiPlotFitting->setToolTip(tr("Takes effect after reopening a plot window"));
   groupBoxFittingCurve->setTitle(tr("Generated Fit Curve"));
   generatePointsBtn->setText(tr("Uniform X Function"));
   lblPoints->setText( tr("Points") );
   samePointsBtn->setText( tr( "Same X as Fitting Data" ) );
   linearFit2PointsBox->setText( tr( "2 points for linear fits" ) );
-
   groupBoxMultiPeak->setTitle(tr("Display Peak Curves for Multi-peak Fits"));
-
   groupBoxFitParameters->setTitle(tr("Parameters Output"));
   lblPrecision->setText(tr("Significant Digits"));
   logBox->setText(tr("Write Parameters to Result Log"));
   plotLabelBox->setText(tr("Paste Parameters to Plot"));
+  plotLabelBox->setToolTip(tr("Adds a text box to the plot with details of fitting parameters"));
   scaleErrorsBox->setText(tr("Scale Errors with sqrt(Chi^2/doF)"));
   groupBoxMultiPeak->setTitle(tr("Display Peak Curves for Multi-peak Fits"));
   lblPeaksColor->setText(tr("Peaks Color"));
@@ -1998,7 +1998,6 @@ void ConfigDialog::apply()
   sep.replace(tr("SPACE"), " ");
   sep.replace("\\s", " ");
 
-
   if (sep.contains(QRegExp("[0-9.eE+-]"))!=0){
     QMessageBox::warning(0, tr("MantidPlot - Import options error"),
       tr("The separator must not contain the following characters: 0-9eE.+-"));
@@ -2048,8 +2047,6 @@ void ConfigDialog::apply()
     }
   }
 
-
-
   // 2D plots page: curves tab
   app->defaultCurveStyle = curveStyle();
   app->defaultCurveLineWidth = boxCurveLineWidth->value();
@@ -2265,7 +2262,6 @@ void ConfigDialog::updateCurveFitSettings()
   mantid_config.setString("curvefitting.peakRadius", setting);
 
   app->mantidUI->fitFunctionBrowser()->setDecimals(decimals->value());
-
 }
 
 void ConfigDialog::updateMantidOptionsTab()
diff --git a/Code/Mantid/MantidPlot/src/ExportDialog.cpp b/Code/Mantid/MantidPlot/src/ExportDialog.cpp
index 9a8a24c668c726a3de7978de3d7807db01cea54a..76c99f7df80dd4cae11733f176730619c8ab67cd 100644
--- a/Code/Mantid/MantidPlot/src/ExportDialog.cpp
+++ b/Code/Mantid/MantidPlot/src/ExportDialog.cpp
@@ -45,85 +45,86 @@ ExportDialog::ExportDialog(const QString& tableName, QWidget* parent, Qt::WFlags
 	ApplicationWindow *app = dynamic_cast<ApplicationWindow *>(parent);
 
 	QGridLayout *gl1 = new QGridLayout();
-    gl1->addWidget(new QLabel(tr("Export From")), 0, 0);
+  gl1->addWidget(new QLabel(tr("Export From")), 0, 0);
 	boxTable = new QComboBox();
 	QStringList tables = app->tableNames() + app->matrixNames() + app->mantidmatrixNames();
 	boxTable->addItems(tables);
 	boxTable->setCurrentIndex(0);
 
-	boxTable->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
-	gl1->addWidget(boxTable, 0, 1);
-
-	boxAllTables = new QCheckBox(tr( "&All" ));
-    boxAllTables->setChecked(false);
-	gl1->addWidget(boxAllTables, 0, 2);
-
-    sepText = new QLabel( tr( "Separator" ) );
-	gl1->addWidget(sepText, 1, 0);
-
-    boxSeparator = new QComboBox();
-	boxSeparator->addItem(tr("TAB"));
-    boxSeparator->addItem(tr("SPACE"));
-	boxSeparator->addItem(";" + tr("TAB"));
-	boxSeparator->addItem("," + tr("TAB"));
-	boxSeparator->addItem(";" + tr("SPACE"));
-	boxSeparator->addItem("," + tr("SPACE"));
-    boxSeparator->addItem(";");
-    boxSeparator->addItem(",");
-	boxSeparator->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
-	boxSeparator->setEditable( true );
-	gl1->addWidget(boxSeparator, 1, 1);
-	setColumnSeparator(app->d_export_col_separator);
+  boxTable->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
+  gl1->addWidget(boxTable, 0, 1);
+
+  boxAllTables = new QCheckBox(tr( "&All" ));
+  boxAllTables->setChecked(false);
+  gl1->addWidget(boxAllTables, 0, 2);
+
+  sepText = new QLabel( tr( "Separator" ) );
+  gl1->addWidget(sepText, 1, 0);
+
+  boxSeparator = new QComboBox();
+  boxSeparator->addItem(tr("TAB"));
+  boxSeparator->addItem(tr("SPACE"));
+  boxSeparator->addItem(";" + tr("TAB"));
+  boxSeparator->addItem("," + tr("TAB"));
+  boxSeparator->addItem(";" + tr("SPACE"));
+  boxSeparator->addItem("," + tr("SPACE"));
+  boxSeparator->addItem(";");
+  boxSeparator->addItem(",");
+  boxSeparator->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
+  boxSeparator->setEditable(true);
+
+  gl1->addWidget(boxSeparator, 1, 1);
+  setColumnSeparator(app->d_export_col_separator);
 
 	QString help = tr("The column separator can be customized. The following special codes can be used:\n\\t for a TAB character \n\\s for a SPACE");
 	help += "\n"+tr("The separator must not contain the following characters: 0-9eE.+-");
 
 	boxSeparator->setWhatsThis(help);
-	sepText->setWhatsThis(help);
-	boxSeparator->setToolTip(help);
-	sepText->setToolTip(help);
-
-	boxNames = new QCheckBox(tr( "Include Column &Names" ));
-    boxNames->setChecked( app->d_export_col_names );
-
-	boxComments = new QCheckBox(tr( "Include Column Co&mments" ));
-    boxComments->setChecked( app->d_export_col_comment );
-
-    boxSelection = new QCheckBox(tr( "Export &Selection" ));
-    boxSelection->setChecked( app->d_export_table_selection );
-
-	QVBoxLayout *vl1 = new QVBoxLayout();
-	vl1->addLayout( gl1 );
-	vl1->addWidget( boxNames );
-	vl1->addWidget( boxComments );
-	vl1->addWidget( boxSelection );
-
-	QHBoxLayout *hbox3 = new QHBoxLayout();
-	buttonOk = new QPushButton(tr( "&OK" ));
-    buttonOk->setDefault( true );
-	hbox3->addWidget( buttonOk );
-    buttonCancel = new QPushButton(tr( "&Cancel" ));
-	hbox3->addWidget( buttonCancel );
-	buttonHelp = new QPushButton(tr( "&Help" ));
-	hbox3->addWidget( buttonHelp );
-	hbox3->addStretch();
-
-	QVBoxLayout *vl = new QVBoxLayout( this );
-    vl->addLayout(vl1);
-	vl->addStretch();
-	vl->addLayout(hbox3);
-
-    // signals and slots connections
-    connect( boxTable, SIGNAL(activated(const QString &)), this, SLOT(updateOptions(const QString &)));
-    connect( buttonOk, SIGNAL( clicked() ), this, SLOT( accept() ) );
-	connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( close() ) );
-    connect( buttonHelp, SIGNAL( clicked() ), this, SLOT( help() ) );
-	connect( boxAllTables, SIGNAL( toggled(bool) ), this, SLOT( enableTableName(bool) ) );
-
-    if (tables.contains(tableName)){
-		boxTable->setCurrentIndex(boxTable->findText(tableName));
-		updateOptions(tableName);
-    }
+  sepText->setWhatsThis(help);
+  boxSeparator->setToolTip(help);
+  sepText->setToolTip(help);
+
+  boxNames = new QCheckBox(tr( "Include Column &Names" ));
+  boxNames->setChecked( app->d_export_col_names );
+
+  boxComments = new QCheckBox(tr( "Include Column Co&mments" ));
+  boxComments->setChecked( app->d_export_col_comment );
+
+  boxSelection = new QCheckBox(tr( "Export &Selection" ));
+  boxSelection->setChecked( app->d_export_table_selection );
+
+  QVBoxLayout *vl1 = new QVBoxLayout();
+  vl1->addLayout( gl1 );
+  vl1->addWidget( boxNames );
+  vl1->addWidget( boxComments );
+  vl1->addWidget( boxSelection );
+
+  QHBoxLayout *hbox3 = new QHBoxLayout();
+  buttonOk = new QPushButton(tr( "&OK" ));
+  buttonOk->setDefault( true );
+  hbox3->addWidget( buttonOk );
+  buttonCancel = new QPushButton(tr( "&Cancel" ));
+  hbox3->addWidget( buttonCancel );
+  buttonHelp = new QPushButton(tr( "&Help" ));
+  hbox3->addWidget( buttonHelp );
+  hbox3->addStretch();
+
+  QVBoxLayout *vl = new QVBoxLayout( this );
+  vl->addLayout(vl1);
+  vl->addStretch();
+  vl->addLayout(hbox3);
+
+  // signals and slots connections
+  connect( boxTable, SIGNAL(activated(const QString &)), this, SLOT(updateOptions(const QString &)));
+  connect( buttonOk, SIGNAL( clicked() ), this, SLOT( accept() ) );
+  connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( close() ) );
+  connect( buttonHelp, SIGNAL( clicked() ), this, SLOT( help() ) );
+  connect( boxAllTables, SIGNAL( toggled(bool) ), this, SLOT( enableTableName(bool) ) );
+
+  if (tables.contains(tableName)){
+    boxTable->setCurrentIndex(boxTable->findText(tableName));
+    updateOptions(tableName);
+  }
 }
 
 void ExportDialog::help()
diff --git a/Code/Mantid/MantidPlot/src/ExportDialog.h b/Code/Mantid/MantidPlot/src/ExportDialog.h
index ed20a812fc246000a30845601105245d319bfdfe..fd6959afe8bf6ce3133b425b23eb497f55f9e829 100644
--- a/Code/Mantid/MantidPlot/src/ExportDialog.h
+++ b/Code/Mantid/MantidPlot/src/ExportDialog.h
@@ -38,7 +38,7 @@ class QLabel;
 //! Export ASCII dialog
 class ExportDialog : public QDialog
 {
-    Q_OBJECT
+  Q_OBJECT
 
 public:
 	//! Constructor
@@ -47,21 +47,21 @@ public:
 	 * @param parent :: parent widget
 	 * @param fl :: window flags
 	 */
-    ExportDialog(const QString& tableName, QWidget* parent = 0, Qt::WFlags fl = 0 );
+  ExportDialog(const QString& tableName, QWidget* parent = 0, Qt::WFlags fl = 0 );
 
 private:
-	void closeEvent(QCloseEvent*);
+  void closeEvent(QCloseEvent*);
 
-    QPushButton* buttonOk;
-	QPushButton* buttonCancel;
-	QPushButton* buttonHelp;
-    QCheckBox* boxNames;
-    QCheckBox* boxComments;
-    QCheckBox* boxSelection;
-	QCheckBox* boxAllTables;
-    QComboBox* boxSeparator;
-	QComboBox* boxTable;
-	QLabel *sepText;
+  QPushButton* buttonOk;
+  QPushButton* buttonCancel;
+  QPushButton* buttonHelp;
+  QCheckBox* boxNames;
+  QCheckBox* boxComments;
+  QCheckBox* boxSelection;
+  QCheckBox* boxAllTables;
+  QComboBox* boxSeparator;
+  QComboBox* boxTable;
+  QLabel *sepText;
 
 public slots:
 	//! Set the column delimiter
diff --git a/Code/Mantid/MantidPlot/src/Graph.cpp b/Code/Mantid/MantidPlot/src/Graph.cpp
index 8780997cf7ca4208da9a35a579b4219ba704d76b..ca5427262b4671b14403c4098c44800cad3e18fe 100644
--- a/Code/Mantid/MantidPlot/src/Graph.cpp
+++ b/Code/Mantid/MantidPlot/src/Graph.cpp
@@ -3428,10 +3428,17 @@ PlotCurve* Graph::insertCurve(PlotCurve* c, int lineWidth, int curveType)
       m_yUnits = mc->yUnits();
       m_isDistribution = mc->isDistribution();
     }
+
+    //If we don't have any units, let's use the new curve's units.
+    if(!m_xUnits)
+      m_xUnits = mc->xUnits();
+    if(!m_yUnits)
+      m_yUnits = mc->yUnits();
+
     // Compare units. X units are compared by ID, Y units - by caption. That's because Y units will
     // always be of type Label, hence will always have ID "Label", and the caption is what we are
     // interested in.
-    if ( m_xUnits->unitID() != mc->xUnits()->unitID() || m_yUnits->caption() != mc->yUnits()->caption() )
+    if((m_xUnits && m_xUnits->unitID() != mc->xUnits()->unitID()) || (m_yUnits && m_yUnits->caption() != mc->yUnits()->caption()))
     {
       g_log.warning("You are overlaying plots from data having differing units!");
     }
diff --git a/Code/Mantid/MantidPlot/src/Mantid/AlgorithmHistoryWindow.cpp b/Code/Mantid/MantidPlot/src/Mantid/AlgorithmHistoryWindow.cpp
index db2a8d9300ff3083de1a06c8542082f92d533961..f23aeedd5936b06f06690a9aa0b965ed6999fa71 100644
--- a/Code/Mantid/MantidPlot/src/Mantid/AlgorithmHistoryWindow.cpp
+++ b/Code/Mantid/MantidPlot/src/Mantid/AlgorithmHistoryWindow.cpp
@@ -220,7 +220,15 @@ m_wsName(wsptr->getName().c_str()), m_view(wsptr->getHistory().createView())
   environmentLayout->addWidget(m_execSumGrpBox, 1);
   environmentLayout->addWidget(m_envHistGrpBox, 2);
 
-  // The button at the bottom
+  // The buttons at the bottom
+  m_scriptVersionLabel = new QLabel("Algorithm Versions:", this);
+  m_scriptComboMode = new QComboBox(this);
+  // N.B. The combobox item strings below are used in AlgorithmHistoryWindow::getScriptVersionMode()
+  // If you change them here, you MUST change them there too.
+  m_scriptComboMode->addItem("Only Specify Old Versions");
+  m_scriptComboMode->addItem("Never Specify Versions");
+  m_scriptComboMode->addItem("Always Specify Versions");
+  m_scriptComboMode->setToolTip("When to specify which version of an algorithm was used.");
   m_scriptButtonFile = new QPushButton("Script to File",this);
   m_scriptButtonClipboard = new QPushButton("Script to Clipboard",this);
   connect(m_scriptButtonFile,SIGNAL(clicked()), this, SLOT(writeToScriptFile()));
@@ -228,6 +236,8 @@ m_wsName(wsptr->getName().c_str()), m_view(wsptr->getHistory().createView())
 
   QHBoxLayout *buttonLayout = new QHBoxLayout;
   buttonLayout->addStretch(1); // Align the button to the right
+  buttonLayout->addWidget(m_scriptVersionLabel);
+  buttonLayout->addWidget(m_scriptComboMode);
   buttonLayout->addWidget(m_scriptButtonFile);
   buttonLayout->addWidget(m_scriptButtonClipboard);
 
@@ -305,6 +315,27 @@ AlgHistoryProperties* AlgorithmHistoryWindow::createAlgHistoryPropWindow()
   }
 }
 
+//! Used by the save script to clipboard/file buttons to select which versioning mode to use.
+std::string AlgorithmHistoryWindow::getScriptVersionMode()
+{
+  std::string curText = m_scriptComboMode->currentText().toStdString();
+
+  if(curText == "Only Specify Old Versions")
+  {
+    return "old";
+  }
+  else if(curText == "Always Specify Versions")
+  {
+    return "all";
+  }
+  else if(curText == "Never Specify Versions")
+  {
+    return "none";
+  }
+
+  throw std::runtime_error("AlgorithmHistoryWindow::getScriptVersionMode received unhandled version mode string");
+}
+
 void AlgorithmHistoryWindow::writeToScriptFile()
 {
   QString prevDir = MantidQt::API::AlgorithmInputHistory::Instance().getPreviousDirectory();
@@ -322,7 +353,7 @@ void AlgorithmHistoryWindow::writeToScriptFile()
   // An empty string indicates they clicked cancel
   if( filePath.isEmpty() ) return;
   
-  ScriptBuilder builder(m_view);
+  ScriptBuilder builder(m_view, getScriptVersionMode());
   std::ofstream file(filePath.toStdString().c_str(), std::ofstream::trunc);
   file << builder.build();
   file.flush();
@@ -374,7 +405,7 @@ void AlgorithmHistoryWindow::updateExecSummaryGrpBox(AlgorithmHistory_const_sptr
 
 void AlgorithmHistoryWindow::copytoClipboard()
 {	
-  ScriptBuilder builder(m_view);
+  ScriptBuilder builder(m_view, getScriptVersionMode());
   QString script;
   const std::string contents = builder.build();
   script.append(contents.c_str());
diff --git a/Code/Mantid/MantidPlot/src/Mantid/AlgorithmHistoryWindow.h b/Code/Mantid/MantidPlot/src/Mantid/AlgorithmHistoryWindow.h
index 95d380c7dfb1b077f06c914309c55c6edce83bb7..e172a33e64ec2d9d06c912d60533e388b60b85c1 100644
--- a/Code/Mantid/MantidPlot/src/Mantid/AlgorithmHistoryWindow.h
+++ b/Code/Mantid/MantidPlot/src/Mantid/AlgorithmHistoryWindow.h
@@ -13,6 +13,7 @@
 #include <QTreeWidget>
 #include <QStandardItemModel>
 #include <QAbstractListModel>
+#include <QComboBox>
 #include <QGroupBox>
 #include <QPushButton>
 
@@ -153,8 +154,12 @@ private:
   void updateExecSummaryGrpBox(Mantid::API::AlgorithmHistory_const_sptr algHistory);
   void updateAlgHistoryProperties(Mantid::API::AlgorithmHistory_const_sptr algHistory);
 
+  std::string getScriptVersionMode();
+
 private:
   const Mantid::API::WorkspaceHistory & m_algHist;
+  QLabel *m_scriptVersionLabel;
+  QComboBox *m_scriptComboMode;
   QPushButton *m_scriptButtonFile;
   QPushButton *m_scriptButtonClipboard;
   AlgHistoryTreeWidget *m_Historytree;
diff --git a/Code/Mantid/MantidPlot/src/Mantid/MantidMatrix.cpp b/Code/Mantid/MantidPlot/src/Mantid/MantidMatrix.cpp
index aa56b548b84f9412d41feee15f591846394d9477..5d17ab07e5811cc71f4b9ab099e5b0df08f855db 100644
--- a/Code/Mantid/MantidPlot/src/Mantid/MantidMatrix.cpp
+++ b/Code/Mantid/MantidPlot/src/Mantid/MantidMatrix.cpp
@@ -1,3 +1,4 @@
+#include "MantidKernel/Logger.h"
 #include "MantidMatrix.h"
 #include "MantidMatrixFunction.h"
 #include "MantidKernel/Timer.h"
@@ -52,6 +53,11 @@ using namespace Mantid::Kernel;
 using namespace MantidQt::API;
 using namespace Mantid::Geometry;
 
+namespace
+{
+  Logger g_log("MantidMatrix");
+}
+
 MantidMatrix::MantidMatrix(Mantid::API::MatrixWorkspace_const_sptr ws, ApplicationWindow* parent, const QString& label, const QString& name, int start, int end)
   : MdiSubWindow(parent, label, name, 0),
   WorkspaceObserver(),
@@ -893,9 +899,17 @@ void MantidMatrix::afterReplaceHandle(const std::string& wsName,const boost::sha
   }
 
   Mantid::API::MatrixWorkspace_sptr new_workspace = boost::dynamic_pointer_cast<MatrixWorkspace>(Mantid::API::AnalysisDataService::Instance().retrieve(m_strName));
-  emit needWorkspaceChange( new_workspace ); 
-
 
+  //If the cast failed (e.g. Matrix2D became a GroupWorkspace) do not try to change the matrix, just close it
+  if(new_workspace)
+  {
+    emit needWorkspaceChange( new_workspace );
+  }
+  else
+  {
+    g_log.warning("Workspace type changed. Closing matrix window.");
+    emit needToClose();
+  }
 }
 
 void MantidMatrix::changeWorkspace(Mantid::API::MatrixWorkspace_sptr ws)
diff --git a/Code/Mantid/MantidPlot/src/Mantid/MantidUI.cpp b/Code/Mantid/MantidPlot/src/Mantid/MantidUI.cpp
index 81ff739a70f0fe6ba704044fa3f7ee34e13e90f4..4fb90c695ab1460c1e98b8b3e7ee2bb99b541551 100644
--- a/Code/Mantid/MantidPlot/src/Mantid/MantidUI.cpp
+++ b/Code/Mantid/MantidPlot/src/Mantid/MantidUI.cpp
@@ -1811,7 +1811,7 @@ void MantidUI::handleClearADS(Mantid::API::ClearADSNotification_ptr)
 
 void MantidUI::handleRenameWorkspace(Mantid::API::WorkspaceRenameNotification_ptr msg)
 {
-  emit workspace_renamed(QString::fromStdString(msg->object_name()),QString::fromStdString(msg->new_objectname()));
+  emit workspace_renamed(QString::fromStdString(msg->objectName()),QString::fromStdString(msg->newObjectName()));
   emit ADS_updated();
 }
 void MantidUI::handleGroupWorkspaces(Mantid::API::WorkspacesGroupedNotification_ptr)
diff --git a/Code/Mantid/MantidPlot/src/Matrix.cpp b/Code/Mantid/MantidPlot/src/Matrix.cpp
index bb9c15e49b626cc28047be9777e64fad1c488318..92204ff0cd51c801ee3173be75f38d7e11d1aaa3 100644
--- a/Code/Mantid/MantidPlot/src/Matrix.cpp
+++ b/Code/Mantid/MantidPlot/src/Matrix.cpp
@@ -704,6 +704,8 @@ void Matrix::pasteSelection()
     d_matrix_model->pasteData(clipboardBuffer, topRow, leftCol, rows, cols);
     emit modifiedWindow(this);
   }
+
+  free(clipboardBuffer);
 }
 
 void Matrix::cutSelection()
diff --git a/Code/Mantid/MantidPlot/src/MultiLayer.cpp b/Code/Mantid/MantidPlot/src/MultiLayer.cpp
index 013e9401e714cbe804b3eee502b7530cfa4e67b3..2f2120a687276f992e75bd50c8d68745727d3415 100644
--- a/Code/Mantid/MantidPlot/src/MultiLayer.cpp
+++ b/Code/Mantid/MantidPlot/src/MultiLayer.cpp
@@ -1608,48 +1608,130 @@ void MultiLayer::showWaterfallFillDialog()
   if (active_graph->curvesList().isEmpty())
     return;
 
+  new WaterfallFillDialog(this, active_graph);  
+}
+
+
+void MultiLayer::setWaterfallFillColor(const QColor& c)
+{
+  d_waterfall_fill_color = c;
+  if (active_graph)
+    active_graph->setWaterfallFillColor(c);
+}
+
+
+WaterfallFillDialog::WaterfallFillDialog(MultiLayer *parent, Graph *active_graph) 
+{
+  this->setParent(parent);
+  this->m_active_graph = active_graph;
   QDialog *waterfallFillDialog = new QDialog(this);
   waterfallFillDialog->setWindowTitle(tr("Fill Curves"));
+  
+  QGroupBox *enableFillGroup = new QGroupBox(tr("Enable Fill"), waterfallFillDialog);
+  enableFillGroup->setCheckable(true);
+  
+  QGridLayout *enableFillLayout =  new QGridLayout(enableFillGroup);  
 
-  QGroupBox *gb1 = new QGroupBox(tr("Enable Fill"));
-  gb1->setCheckable(true);
+  // use line colour
+  QRadioButton *rLineC = new QRadioButton("Use Line Colour", enableFillGroup);
+  this->m_lineRadioButton = rLineC;
+  enableFillLayout->addWidget(rLineC,0,0);
+  
+  // use solid colour
+  QRadioButton *rSolidC = new QRadioButton("Use Solid Colour", enableFillGroup);
+  this->m_solidRadioButton = rSolidC;
+  enableFillLayout->addWidget(rSolidC, 1,0);
 
-  QGridLayout *hl1 = new QGridLayout(gb1);
-  hl1->addWidget(new QLabel(tr("Fill with Color")), 0, 0);
-  ColorButton *fillColorBox = new ColorButton();
-  hl1->addWidget(fillColorBox, 0, 1);
+  QGroupBox *colourModeGroup = new QGroupBox( tr("Fill with Colour"), enableFillGroup);  
+  
+  QGridLayout *hl1 = new QGridLayout(colourModeGroup);
+  hl1->addWidget(new QLabel(tr("Colour")), 0, 0);
+  ColorButton *fillColourBox = new ColorButton(colourModeGroup);
+  this->m_colourBox = fillColourBox;
+  fillColourBox->setColor(Qt::white); // Default colour
+  hl1->addWidget(fillColourBox, 0, 1);
+  enableFillLayout->addWidget(colourModeGroup,2,0);
 
-  QCheckBox *sideLinesBox = new QCheckBox(tr("Side Lines"));
-  //sideLinesBox->setChecked(active_graph->curve(0)->sideLinesEnabled());
-  hl1->addWidget(sideLinesBox, 1, 0);
-  hl1->setRowStretch(2, 1);
+  QCheckBox *sideLinesBox = new QCheckBox(tr("Side Lines"), enableFillGroup);
+  enableFillLayout->addWidget(sideLinesBox, 3, 0); 
 
   QBrush brush = active_graph->curve(0)->brush();
-  //fillColorBox->setColor(brush.style() != Qt::NoBrush ? brush.color() : d_waterfall_fill_color);
-  fillColorBox->setColor(Qt::white);
-  gb1->setChecked(brush.style() != Qt::NoBrush);
 
-  connect(gb1, SIGNAL(toggled(bool)), active_graph, SLOT(updateWaterfallFill(bool)));
-  connect(fillColorBox, SIGNAL(colorChanged(const QColor&)), this, SLOT(setWaterfallFillColor(const QColor&)));
-  connect(sideLinesBox, SIGNAL(toggled(bool)), active_graph, SLOT(setWaterfallSideLines(bool)));
+  // check if all curve colours are the same (= solid fill)
+  bool same = brush.style() != Qt::NoBrush; // check isn't first run against graph
+  
+  if(same)
+  {
+    int n = active_graph->curvesList().size();
+    for (int i = 0; i < n; i++)
+    {
+      same = same && (active_graph->curve(i)->brush().color() == brush.color());    
+    }
+  }
+  // set which is toggled
+  enableFillGroup->setChecked(brush.style() != Qt::NoBrush);
+
+  if(same)
+  {   
+    rSolidC->toggle();
+    if(enableFillGroup->isChecked())
+      fillColourBox->setColor(brush.color());
+  }
+  else
+  {
+    rLineC->toggle();
+    if(enableFillGroup->isChecked())
+      active_graph->updateWaterfallFill(true);  
+  }
 
-  QPushButton *closeBtn = new QPushButton(tr("&Close"));
+  // If sidelines previously enabled, check it.
+  PlotCurve *c = dynamic_cast<PlotCurve*>(active_graph->curve(0));
+  sideLinesBox->setChecked(c->sideLinesEnabled());   
+  
+  colourModeGroup->setEnabled(rSolidC->isChecked() && enableFillGroup->isChecked());  
+  
+  connect(enableFillGroup, SIGNAL(toggled(bool)), this, SLOT(enableFill(bool))); 
+  connect(fillColourBox, SIGNAL(colorChanged(const QColor&)), active_graph, SLOT(setWaterfallFillColor(const QColor&)));
+  connect(sideLinesBox, SIGNAL(toggled(bool)), active_graph, SLOT(setWaterfallSideLines(bool)));  
+  connect(rSolidC, SIGNAL(toggled(bool)), colourModeGroup, SLOT(setEnabled(bool)));  
+  connect(rSolidC, SIGNAL(toggled(bool)), this, SLOT(setFillMode())); 
+  connect(rLineC, SIGNAL(toggled(bool)), this, SLOT(setFillMode())); 
+  
+  QPushButton *closeBtn = new QPushButton(tr("&Close"),waterfallFillDialog);
   connect(closeBtn, SIGNAL(clicked()), waterfallFillDialog, SLOT(reject()));
 
-  QHBoxLayout *hl2 = new QHBoxLayout();
-  hl2->addStretch();
-  hl2->addWidget(closeBtn);
+  QHBoxLayout *hlClose = new QHBoxLayout();
+  hlClose->addStretch();
+  hlClose->addWidget(closeBtn);
 
   QVBoxLayout *vl = new QVBoxLayout(waterfallFillDialog);
-  vl->addWidget(gb1);
-  vl->addLayout(hl2);
+  vl->addWidget(enableFillGroup);
+  vl->addLayout(hlClose);
   waterfallFillDialog->exec();
 }
 
-void MultiLayer::setWaterfallFillColor(const QColor& c)
+void WaterfallFillDialog::enableFill(bool b)
 {
-  d_waterfall_fill_color = c;
-  if (active_graph)
-    active_graph->setWaterfallFillColor(c);
+  if(b)
+  {
+    WaterfallFillDialog::setFillMode();
+  }
+  else
+  {
+    m_active_graph->curve(0)->setBrush(Qt::BrushStyle::NoBrush);
+    m_active_graph->updateWaterfallFill(false);     
+  }
+}
+
+void WaterfallFillDialog::setFillMode()
+{
+  if( m_solidRadioButton->isChecked() ) 
+  {                  
+    m_active_graph->setWaterfallFillColor(this->m_colourBox->color());
+  }    
+  else if( m_lineRadioButton->isChecked() )
+  {       
+    m_active_graph->updateWaterfallFill(true); 
+  }
 }
 
diff --git a/Code/Mantid/MantidPlot/src/MultiLayer.h b/Code/Mantid/MantidPlot/src/MultiLayer.h
index f0bc64e70eba0da1da142355aae85612d06cf38a..c38e3817f0098b7a3ff4704114290c2267531654 100644
--- a/Code/Mantid/MantidPlot/src/MultiLayer.h
+++ b/Code/Mantid/MantidPlot/src/MultiLayer.h
@@ -46,6 +46,7 @@ class MantidTreeWidget;
 class MantidMDCurve;
 class MantidMatrixCurve;
 class QSize;
+class WaterfallFillDialog;
 
 /**
  * \brief An MDI window (MdiSubWindow) managing one or more Graph objects.
@@ -266,4 +267,24 @@ signals:
 
 Q_DECLARE_METATYPE(MultiLayer*);
 
+
+class WaterfallFillDialog : QDialog
+{
+    Q_OBJECT
+
+public:
+    WaterfallFillDialog(MultiLayer *parent, Graph *active_graph);
+
+public slots:    
+  void setFillMode();
+  void enableFill(bool b);
+
+private:
+    Graph *m_active_graph;
+    QRadioButton *m_solidRadioButton;
+    QRadioButton *m_lineRadioButton;
+    ColorButton *m_colourBox;
+};
+
+
 #endif
diff --git a/Code/Mantid/MantidPlot/src/PythonScript.cpp b/Code/Mantid/MantidPlot/src/PythonScript.cpp
index 750e0714b1f838be8ca3ac844e8cefd2a50f9c47..6657679ad72951026d45928a637e136502395cf4 100644
--- a/Code/Mantid/MantidPlot/src/PythonScript.cpp
+++ b/Code/Mantid/MantidPlot/src/PythonScript.cpp
@@ -418,16 +418,26 @@ void PythonScript::setContext(QObject *context)
 }
 
 /**
- * Clears the current set of local variables and resets
+ * Clears the current set of local variables, if they exist, and resets
  * the dictionary context back to the default set
  */
 void PythonScript::clearLocals()
 {
-  GlobalInterpreterLock pythonlock;
+  GlobalInterpreterLock pythonLock;
+
+  PyObject *mainModule = PyImport_AddModule("__main__");
+  PyObject *cleanLocals = PyDict_Copy(PyModule_GetDict(mainModule));
 
-  Py_XDECREF(localDict); //clear up any previous dictionary
-  PyObject *pymodule = PyImport_AddModule("__main__");
-  localDict = PyDict_Copy(PyModule_GetDict(pymodule));
+  if(localDict)
+  {
+    // Pull out variables that are not user-related
+    PyObject * value = PyDict_GetItemString(localDict, "__file__");
+    if(value) PyDict_SetItemString(cleanLocals, "__file__", value);
+    // reset locals
+    Py_DECREF(localDict);
+    localDict = NULL;
+  }
+  localDict = cleanLocals;
 }
 
 /**
diff --git a/Code/Mantid/MantidPlot/src/lib/include/PatternBox.h b/Code/Mantid/MantidPlot/src/lib/include/PatternBox.h
index 4ab5fb8f6ac5ce6642800119704e36cb35f921db..522e5fdb952854b4430a82bc555bf3d5223672ea 100644
--- a/Code/Mantid/MantidPlot/src/lib/include/PatternBox.h
+++ b/Code/Mantid/MantidPlot/src/lib/include/PatternBox.h
@@ -55,6 +55,7 @@ protected:
   void init();
 
 private:
+  static size_t numberOfPatterns();
   static const Qt::BrushStyle patterns[];
 };
 
diff --git a/Code/Mantid/MantidPlot/src/lib/include/PenStyleBox.h b/Code/Mantid/MantidPlot/src/lib/include/PenStyleBox.h
index 3190fd1d31eab381c0f5d98caf1acbf860c73976..e199edae8619e4db64418e8343197056fc8b5aa6 100644
--- a/Code/Mantid/MantidPlot/src/lib/include/PenStyleBox.h
+++ b/Code/Mantid/MantidPlot/src/lib/include/PenStyleBox.h
@@ -52,6 +52,7 @@ public:
   static Qt::PenStyle penStyle(int index);
 
 private:
+  static size_t numberOfPatterns();
   static const Qt::PenStyle patterns[];
 };
 
diff --git a/Code/Mantid/MantidPlot/src/lib/include/SymbolBox.h b/Code/Mantid/MantidPlot/src/lib/include/SymbolBox.h
index 27b30edcbc760e390d3979f76e2bd16f97ac4aa4..335ac6151b7713dae5f757cea7e8f9c69b3d7e3f 100644
--- a/Code/Mantid/MantidPlot/src/lib/include/SymbolBox.h
+++ b/Code/Mantid/MantidPlot/src/lib/include/SymbolBox.h
@@ -63,6 +63,8 @@ protected:
   void focusInEvent(QFocusEvent *);
 
 private:
+  static size_t numberOfSymbols();
+
   static const QwtSymbol::Style symbols[];
 };
 
diff --git a/Code/Mantid/MantidPlot/src/lib/src/ColorBox.cpp b/Code/Mantid/MantidPlot/src/lib/src/ColorBox.cpp
index ef5e361b2f8be258f34d7bcb432b7c8b2a7e4435..ce5ee091b17a1b496b0c41fed421028c94aed495 100644
--- a/Code/Mantid/MantidPlot/src/lib/src/ColorBox.cpp
+++ b/Code/Mantid/MantidPlot/src/lib/src/ColorBox.cpp
@@ -161,7 +161,7 @@ QStringList ColorBox::colorNames()
 
 QColor ColorBox::defaultColor(int colorIndex)
 {
-  if (colorIndex >= 0 && colorIndex < (int)sizeof(colors))
+  if (colorIndex >= 0 && colorIndex < colors_count)
     return colors[colorIndex];
 
   return Qt::black; // default color is black.
diff --git a/Code/Mantid/MantidPlot/src/lib/src/PatternBox.cpp b/Code/Mantid/MantidPlot/src/lib/src/PatternBox.cpp
index 9406cb405a45f50d0dbfb1d66db431f7f93c6aba..388c29fa77855a397dcad9de71b788f918ae6be2 100644
--- a/Code/Mantid/MantidPlot/src/lib/src/PatternBox.cpp
+++ b/Code/Mantid/MantidPlot/src/lib/src/PatternBox.cpp
@@ -149,7 +149,7 @@ void PatternBox::init()
 void PatternBox::setPattern(const Qt::BrushStyle& style)
 {
   // Avoid compiler warnings relating to patterns + sizeof(patterns) being out of range
-  size_t n = sizeof(patterns);
+  size_t n = numberOfPatterns();
   for(size_t i = 0; i < n; ++i)
   {
     if (patterns[i] == style)
@@ -163,7 +163,7 @@ void PatternBox::setPattern(const Qt::BrushStyle& style)
 
 Qt::BrushStyle PatternBox::brushStyle(int index)
 {
-  if (index < (int)sizeof(patterns))
+  if (index < (int)numberOfPatterns())
     return patterns[index];
   else
     return Qt::SolidPattern; // default patterns is solid.
@@ -172,7 +172,7 @@ Qt::BrushStyle PatternBox::brushStyle(int index)
 Qt::BrushStyle PatternBox::getSelectedPattern() const
 {
   size_t i = this->currentIndex();
-  if (i < sizeof(patterns))
+  if (i < numberOfPatterns())
     return patterns[i];
   else
     return Qt::SolidPattern; // default patterns is solid.
@@ -181,7 +181,7 @@ Qt::BrushStyle PatternBox::getSelectedPattern() const
 int PatternBox::patternIndex(const Qt::BrushStyle& style)
 {
   // Avoid compiler warnings relating to patterns + sizeof(patterns) being out of range
-  size_t n = sizeof(patterns);
+  size_t n = numberOfPatterns();
   for(size_t i = 0; i < n; ++i)
   {
     if (patterns[i] == style)
@@ -191,3 +191,8 @@ int PatternBox::patternIndex(const Qt::BrushStyle& style)
   }
   return 0; // default pattern is solid.
 }
+
+size_t PatternBox::numberOfPatterns()
+{
+  return sizeof(patterns) / sizeof(Qt::BrushStyle);
+}
diff --git a/Code/Mantid/MantidPlot/src/lib/src/PenStyleBox.cpp b/Code/Mantid/MantidPlot/src/lib/src/PenStyleBox.cpp
index c6235f00df6761b26ae18b698754f2882570f253..179541eebf96af77a5dca3652e3ad984569cee05 100644
--- a/Code/Mantid/MantidPlot/src/lib/src/PenStyleBox.cpp
+++ b/Code/Mantid/MantidPlot/src/lib/src/PenStyleBox.cpp
@@ -51,7 +51,7 @@ PenStyleBox::PenStyleBox(QWidget *parent) : QComboBox(parent)
 void PenStyleBox::setStyle(const Qt::PenStyle& style)
 {
   // Avoid compiler warnings relating to patterns + sizeof(patterns) being out of range
-  size_t n = sizeof(patterns);
+  size_t n = numberOfPatterns();
   for(size_t i = 0; i < n ; ++i)
   {
     if (patterns[i] == style)
@@ -70,7 +70,7 @@ void PenStyleBox::setStyle(const Qt::PenStyle& style)
 
 Qt::PenStyle PenStyleBox::penStyle(int index)
 {
-  if (index < (int)sizeof(patterns))
+  if (index < (int)numberOfPatterns())
     return patterns[index];
   else
     return Qt::SolidLine; // default style is solid. 
@@ -79,7 +79,7 @@ Qt::PenStyle PenStyleBox::penStyle(int index)
 Qt::PenStyle PenStyleBox::style() const
 {
   size_t i = this->currentIndex();
-  if (i < sizeof(patterns))
+  if (i < numberOfPatterns())
     return patterns[i];
   else
     return Qt::SolidLine; // default style is solid. 
@@ -88,7 +88,7 @@ Qt::PenStyle PenStyleBox::style() const
 int PenStyleBox::styleIndex(const Qt::PenStyle& style)
 {
   // Avoid compiler warnings relating to patterns + sizeof(patterns) being out of range
-  size_t n = sizeof(patterns);
+  size_t n = numberOfPatterns();
   for(size_t i = 0; i < n ; ++i)
   {
     if (patterns[i] == style) return int(i);
@@ -100,3 +100,8 @@ int PenStyleBox::styleIndex(const Qt::PenStyle& style)
 //  else
 //    return (int(ite - patterns));
 }
+
+size_t PenStyleBox::numberOfPatterns()
+{
+  return sizeof(patterns) / sizeof(Qt::PenStyle);
+}
\ No newline at end of file
diff --git a/Code/Mantid/MantidPlot/src/lib/src/SymbolBox.cpp b/Code/Mantid/MantidPlot/src/lib/src/SymbolBox.cpp
index d47e52037813cc22e5624a230ed488600ebdf33a..05b9728c499907c7e90ddcf967aa9eba50c76b63 100644
--- a/Code/Mantid/MantidPlot/src/lib/src/SymbolBox.cpp
+++ b/Code/Mantid/MantidPlot/src/lib/src/SymbolBox.cpp
@@ -150,7 +150,7 @@ void SymbolBox::init(bool showNoSymbol)
 void SymbolBox::setStyle(const QwtSymbol::Style& style)
 {
   // Avoid compiler warnings relating to symbols + sizeof(symbols) being out of range
-  size_t n = sizeof(symbols);
+  size_t n = numberOfSymbols();
   for(size_t i = 0; i < n; ++i)
   {
     if (symbols[i] == style)
@@ -179,7 +179,7 @@ QwtSymbol::Style SymbolBox::selectedSymbol() const
 int SymbolBox::symbolIndex(const QwtSymbol::Style& style)
 {
   // Avoid compiler warnings relating to symbols + sizeof(symbols) being out of range
-  size_t n = sizeof(symbols);
+  size_t n = numberOfSymbols();
   for(size_t i = 0; i < n; ++i)
   {
     if (symbols[i] == style)
@@ -197,7 +197,7 @@ int SymbolBox::symbolIndex(const QwtSymbol::Style& style)
 
 QwtSymbol::Style SymbolBox::style(int index)
 {
-  if (index >= 0 && index < (int)sizeof(symbols))
+  if (index >= 0 && index < (int)numberOfSymbols())
     return symbols[index];
 
   return QwtSymbol::NoSymbol;
@@ -217,3 +217,8 @@ void SymbolBox::focusInEvent(QFocusEvent * e)
   emit activated(this);
   return QComboBox::focusInEvent(e);
 }
+
+size_t SymbolBox::numberOfSymbols()
+{
+  return sizeof(symbols) / sizeof(QwtSymbol::Style);
+}
diff --git a/Code/Mantid/MantidPlot/src/origin/OPJFile.cpp b/Code/Mantid/MantidPlot/src/origin/OPJFile.cpp
index dc8d97fcf624a93d360fc8fd07e36a6e2c93f113..3af2f73e3cccdabe3db0d0f6f1e029e030c26821 100644
--- a/Code/Mantid/MantidPlot/src/origin/OPJFile.cpp
+++ b/Code/Mantid/MantidPlot/src/origin/OPJFile.cpp
@@ -2,7 +2,7 @@
     File                 : OPJFile.cpp
     --------------------------------------------------------------------
     Copyright            : (C) 2005-2007 Stefan Gerlach
-						   (C) 2007 by Alex Kargovsky, Ion Vasilief
+               (C) 2007 by Alex Kargovsky, Ion Vasilief
     Email (use @ for *)  : kargovsky*yumr.phys.msu.su, ion_vasilief*yahoo.fr
     Description          : Origin project import class
 
@@ -69,2974 +69,2980 @@ const char* colTypeNames[] = {"X", "Y", "Z", "XErr", "YErr", "Label", "None"};
 
 int strcmp_i(const char *s1, const char *s2) { //compare two strings ignoring case
 #ifdef _WINDOWS
-	return _stricmp(s1,s2);
+  return _stricmp(s1,s2);
 #else
-	return strcasecmp(s1,s2);
+  return strcasecmp(s1,s2);
 #endif
 }
 
 void OPJFile::ByteSwap(unsigned char * b, int n) {
-	register int i = 0;
-	register int j = n-1;
-	while (i<j) {
-		std::swap(b[i], b[j]);
-		i++, j--;
-	}
+  register int i = 0;
+  register int j = n-1;
+  while (i<j) {
+    std::swap(b[i], b[j]);
+    i++, j--;
+  }
 }
 
 OPJFile::OPJFile(const char *filename)
-	: filename(filename)
+  : filename(filename)
 {
-	version=0;
-	dataIndex=0;
-	objectIndex=0;
+  version=0;
+  dataIndex=0;
+  objectIndex=0;
 }
 
 int OPJFile::compareSpreadnames(char *sname) const {
-	for(unsigned int i=0;i<SPREADSHEET.size();i++)
-		if (0==strcmp_i(SPREADSHEET[i].name.c_str(),sname))
-			return i;
-	return -1;
+  for(unsigned int i=0;i<SPREADSHEET.size();i++)
+    if (0==strcmp_i(SPREADSHEET[i].name.c_str(),sname))
+      return i;
+  return -1;
 }
 
 int OPJFile::compareExcelnames(char *sname) const {
-	for(unsigned int i=0;i<EXCEL.size();i++)
-		if (0==strcmp_i(EXCEL[i].name.c_str(),sname))
-			return i;
-	return -1;
+  for(unsigned int i=0;i<EXCEL.size();i++)
+    if (0==strcmp_i(EXCEL[i].name.c_str(),sname))
+      return i;
+  return -1;
 }
 
 
 int OPJFile::compareColumnnames(int spread, char *sname) const {
-	for(unsigned int i=0;i<SPREADSHEET[spread].column.size();i++)
-		if (SPREADSHEET[spread].column[i].name == sname)
-			return i;
-	return -1;
+  for(unsigned int i=0;i<SPREADSHEET[spread].column.size();i++)
+    if (SPREADSHEET[spread].column[i].name == sname)
+      return i;
+  return -1;
 }
 int OPJFile::compareExcelColumnnames(int iexcel, int isheet, char *sname) const {
-	for(unsigned int i=0;i<EXCEL[iexcel].sheet[isheet].column.size();i++)
-		if (EXCEL[iexcel].sheet[isheet].column[i].name == sname)
-			return i;
-	return -1;
+  for(unsigned int i=0;i<EXCEL[iexcel].sheet[isheet].column.size();i++)
+    if (EXCEL[iexcel].sheet[isheet].column[i].name == sname)
+      return i;
+  return -1;
 }
 
 int OPJFile::compareMatrixnames(char *sname) const {
-	for(unsigned int i=0;i<MATRIX.size();i++)
-		if (0==strcmp_i(MATRIX[i].name.c_str(),sname))
-			return i;
-	return -1;
+  for(unsigned int i=0;i<MATRIX.size();i++)
+    if (0==strcmp_i(MATRIX[i].name.c_str(),sname))
+      return i;
+  return -1;
 }
 
 int OPJFile::compareFunctionnames(const char *sname) const {
-	for(unsigned int i=0;i<FUNCTION.size();i++)
-		if (0==strcmp_i(FUNCTION[i].name.c_str(),sname))
-			return i;
-	return -1;
+  for(unsigned int i=0;i<FUNCTION.size();i++)
+    if (0==strcmp_i(FUNCTION[i].name.c_str(),sname))
+      return i;
+  return -1;
 }
 
 vector<string> OPJFile::findDataByIndex(int index) const {
-	vector<string> str;
-	for(unsigned int spread=0;spread<SPREADSHEET.size();spread++)
-		for(unsigned int i=0;i<SPREADSHEET[spread].column.size();i++)
-			if (SPREADSHEET[spread].column[i].index == index)
-			{
-				str.push_back(SPREADSHEET[spread].column[i].name);
-				str.push_back("T_" + SPREADSHEET[spread].name);
-				return str;
-			}
-	for(unsigned int i=0;i<MATRIX.size();i++)
-		if (MATRIX[i].index == index)
-		{
-			str.push_back(MATRIX[i].name);
-			str.push_back("M_" + MATRIX[i].name);
-			return str;
-		}
-	for(unsigned int i=0;i<EXCEL.size();i++)
-		for(unsigned int j=0;j<EXCEL[i].sheet.size();j++)
-			for(unsigned int k=0;k<EXCEL[i].sheet[j].column.size();k++)
-				if (EXCEL[i].sheet[j].column[k].index == index)
-				{
-					str.push_back(EXCEL[i].sheet[j].column[k].name);
-					str.push_back("E_" + EXCEL[i].name);
-					return str;
-				}
-	for(unsigned int i=0;i<FUNCTION.size();i++)
-		if (FUNCTION[i].index == index)
-		{
-			str.push_back(FUNCTION[i].name);
-			str.push_back("F_" + FUNCTION[i].name);
-			return str;
-		}
-	return str;
+  vector<string> str;
+  for(unsigned int spread=0;spread<SPREADSHEET.size();spread++)
+    for(unsigned int i=0;i<SPREADSHEET[spread].column.size();i++)
+      if (SPREADSHEET[spread].column[i].index == index)
+      {
+        str.push_back(SPREADSHEET[spread].column[i].name);
+        str.push_back("T_" + SPREADSHEET[spread].name);
+        return str;
+      }
+  for(unsigned int i=0;i<MATRIX.size();i++)
+    if (MATRIX[i].index == index)
+    {
+      str.push_back(MATRIX[i].name);
+      str.push_back("M_" + MATRIX[i].name);
+      return str;
+    }
+  for(unsigned int i=0;i<EXCEL.size();i++)
+    for(unsigned int j=0;j<EXCEL[i].sheet.size();j++)
+      for(unsigned int k=0;k<EXCEL[i].sheet[j].column.size();k++)
+        if (EXCEL[i].sheet[j].column[k].index == index)
+        {
+          str.push_back(EXCEL[i].sheet[j].column[k].name);
+          str.push_back("E_" + EXCEL[i].name);
+          return str;
+        }
+  for(unsigned int i=0;i<FUNCTION.size();i++)
+    if (FUNCTION[i].index == index)
+    {
+      str.push_back(FUNCTION[i].name);
+      str.push_back("F_" + FUNCTION[i].name);
+      return str;
+    }
+  return str;
 }
 
 string OPJFile::findObjectByIndex(int index) {
-	for(unsigned int i=0;i<SPREADSHEET.size();i++)
-		if (SPREADSHEET[i].objectID == index)
-		{
-			return SPREADSHEET[i].name;
-		}
-
-	for(unsigned int i=0;i<MATRIX.size();i++)
-		if (MATRIX[i].objectID == index)
-		{
-			return MATRIX[i].name;
-		}
-
-	for(unsigned int i=0;i<EXCEL.size();i++)
-		if (EXCEL[i].objectID == index)
-		{
-			return EXCEL[i].name;
-		}
-
-	for(unsigned int i=0;i<GRAPH.size();i++)
-		if (GRAPH[i].objectID == index)
-		{
-			return GRAPH[i].name;
-		}
-
-	return "";
+  for(unsigned int i=0;i<SPREADSHEET.size();i++)
+    if (SPREADSHEET[i].objectID == index)
+    {
+      return SPREADSHEET[i].name;
+    }
+
+  for(unsigned int i=0;i<MATRIX.size();i++)
+    if (MATRIX[i].objectID == index)
+    {
+      return MATRIX[i].name;
+    }
+
+  for(unsigned int i=0;i<EXCEL.size();i++)
+    if (EXCEL[i].objectID == index)
+    {
+      return EXCEL[i].name;
+    }
+
+  for(unsigned int i=0;i<GRAPH.size();i++)
+    if (GRAPH[i].objectID == index)
+    {
+      return GRAPH[i].name;
+    }
+
+  return "";
 }
 
 void OPJFile::convertSpreadToExcel(int spread)
 {
-	//add new Excel sheet
-	EXCEL.push_back(excel(SPREADSHEET[spread].name, SPREADSHEET[spread].label, SPREADSHEET[spread].maxRows, SPREADSHEET[spread].bHidden, SPREADSHEET[spread].bLoose));
-	for (unsigned int i=0; i<SPREADSHEET[spread].column.size(); ++i)
-	{
-		string name=SPREADSHEET[spread].column[i].name;
-		int pos=static_cast<int>(name.find_last_of("@"));
-		string col=name;
-		unsigned int index=0;
-		if(pos!=-1)
-		{
-			col=name.substr(0, pos);
-			index=atoi(name.substr(pos+1).c_str())-1;
-		}
-
-		if(EXCEL.back().sheet.size()<=index)
-			EXCEL.back().sheet.resize(index+1);
-		SPREADSHEET[spread].column[i].name=col;
-		EXCEL.back().sheet[index].column.push_back(SPREADSHEET[spread].column[i]);
-	}
-	SPREADSHEET.erase(SPREADSHEET.begin()+spread);
+  //add new Excel sheet
+  EXCEL.push_back(excel(SPREADSHEET[spread].name, SPREADSHEET[spread].label, SPREADSHEET[spread].maxRows, SPREADSHEET[spread].bHidden, SPREADSHEET[spread].bLoose));
+  for (unsigned int i=0; i<SPREADSHEET[spread].column.size(); ++i)
+  {
+    string name=SPREADSHEET[spread].column[i].name;
+    int pos=static_cast<int>(name.find_last_of("@"));
+    string col=name;
+    unsigned int index=0;
+    if(pos!=-1)
+    {
+      col=name.substr(0, pos);
+      index=atoi(name.substr(pos+1).c_str())-1;
+    }
+
+    if(EXCEL.back().sheet.size()<=index)
+      EXCEL.back().sheet.resize(index+1);
+    SPREADSHEET[spread].column[i].name=col;
+    EXCEL.back().sheet[index].column.push_back(SPREADSHEET[spread].column[i]);
+  }
+  SPREADSHEET.erase(SPREADSHEET.begin()+spread);
 }
 // set default name for columns starting from spreadsheet spread
 void OPJFile::setColName(int spread) {
-	for(unsigned int j=spread;j<SPREADSHEET.size();j++) {
-		SPREADSHEET[j].column[0].type=X;
-		for (unsigned int k=1;k<SPREADSHEET[j].column.size();k++)
-			SPREADSHEET[j].column[k].type=Y;
-	}
+  for(unsigned int j=spread;j<SPREADSHEET.size();j++) {
+    SPREADSHEET[j].column[0].type=X;
+    for (unsigned int k=1;k<SPREADSHEET[j].column.size();k++)
+      SPREADSHEET[j].column[k].type=Y;
+  }
 }
 
 /* File Structure :
 filepre +
-	+ pre + head + data	col A
-	+ pre + head + data	col B
+  + pre + head + data col A
+  + pre + head + data col B
 */
 
 /* parse file "filename" completely and save values */
 int OPJFile::Parse() {
-	FILE *f;
-	if((f=fopen(filename,"rb")) == NULL ) {
-		printf("Could not open %s!\n",filename);
-		return -1;
-	}
-
-	char vers[5];
-	vers[4]=0;
-
-	// get version
-	fseek(f,0x7,SEEK_SET);
-	fread(&vers,4,1,f);
-	fclose(f);
-	version = atoi(vers);
-
-	if(version >= 2766 && version <= 2769) 	// 7.5
-		return ParseFormatNew();
-	else
-		return ParseFormatOld();
+  FILE *f;
+  if((f=fopen(filename,"rb")) == NULL ) {
+    printf("Could not open %s!\n",filename);
+    return -1;
+  }
+
+  char vers[5];
+  vers[4]=0;
+
+  // get version
+  fseek(f,0x7,SEEK_SET);
+  fread(&vers,4,1,f);
+  fclose(f);
+  version = atoi(vers);
+
+  if(version >= 2766 && version <= 2769)  // 7.5
+    return ParseFormatNew();
+  else
+    return ParseFormatOld();
 }
 
 
 int OPJFile::ParseFormatOld() {
-	int i;
-	FILE *f, *debug;
-	if((f=fopen(filename,"rb")) == NULL ) {
-		printf("Could not open %s!\n",filename);
-		return -1;
-	}
-
-	if((debug=fopen("opjfile.log","w")) == NULL ) {
-		printf("Could not open log file!\n");
-		return -1;
-	}
-
-	////////////////////////////// check version from header ///////////////////////////////
-	char vers[5];
-	vers[4]=0;
-
-	// get version
-	fseek(f,0x7,SEEK_SET);
-	fread(&vers,4,1,f);
-	version = atoi(vers);
-	fprintf(debug,"	[version = %d]\n",version);
-
-	// translate version
-	if(version >= 130 && version <= 140) 		// 4.1
-		version=410;
-	else if(version == 210) 	// 5.0
-		version=500;
-	else if(version == 2625) 	// 6.0
-		version=600;
-	else if(version == 2627) 	// 6.0 SR1
-		version=601;
-	else if(version == 2630 ) 	// 6.0 SR4
-		version=604;
-	else if(version == 2635 ) 	// 6.1
-		version=610;
-	else if(version == 2656) 	// 7.0
-		version=700;
-	else if(version == 2672) 	// 7.0 SR3
-		version=703;
-	else {
-		fprintf(debug,"Found unknown project version %d\n",version);
-		fprintf(debug,"Please contact the author of opj2dat\n");
-	}
-	fprintf(debug,"Found project version %.2f\n",version/100.0);
-
-	unsigned char c=0;	// tmp char
-
-	fprintf(debug,"HEADER :\n");
-	for(i=0;i<0x16;i++) {	// skip header + 5 Bytes ("27")
-		fread(&c,1,1,f);
-		fprintf(debug,"%.2X ",c);
-		if(!((i+1)%16)) fprintf(debug,"\n");
-	}
-	fprintf(debug,"\n");
-
-	do{
-		fread(&c,1,1,f);
-	} while (c != '\n');
-	fprintf(debug,"	[file header @ 0x%X]\n", (unsigned int) ftell(f));
-
-	/////////////////// find column ///////////////////////////////////////////////////////////
-	if(version>410)
-		for(i=0;i<5;i++)	// skip "0"
-			fread(&c,1,1,f);
-
-	int col_found;
-	fread(&col_found,4,1,f);
-	if(IsBigEndian()) SwapBytes(col_found);
-
-	fread(&c,1,1,f);	// skip '\n'
-	fprintf(debug,"	[column found = %d/0x%X @ 0x%X]\n",col_found,col_found,(unsigned int) ftell(f));
-
-	int current_col=1, nr=0, nbytes=0;
-	double a;
-	char name[25], valuesize;
-	while(col_found > 0 && col_found < 0x84) {	// should be 0x72, 0x73 or 0x83
-		//////////////////////////////// COLUMN HEADER /////////////////////////////////////////////
-		fprintf(debug,"COLUMN HEADER :\n");
-		for(i=0;i < 0x3D;i++) {	// skip 0x3C chars to value size
-			fread(&c,1,1,f);
-			//if(i>21 && i<27) {
-			fprintf(debug,"%.2X ",c);
-			if(!((i+1)%16)) fprintf(debug,"\n");
-			//}
-		}
-		fprintf(debug,"\n");
-
-		fread(&valuesize,1,1,f);
-		fprintf(debug,"	[valuesize = %d @ 0x%X]\n",valuesize,(unsigned int) ftell(f)-1);
-		if(valuesize <= 0) {
-			fprintf(debug,"	WARNING : found strange valuesize of %d\n",valuesize);
-			valuesize=10;
-		}
-
-		fprintf(debug,"SKIP :\n");
-		for(i=0;i<0x1A;i++) {	// skip to name
-			fread(&c,1,1,f);
-			fprintf(debug,"%.2X ",c);
-			if(!((i+1)%16)) fprintf(debug,"\n");
-		}
-		fprintf(debug,"\n");
-
-		// read name
-		fprintf(debug,"	[Spreadsheet @ 0x%X]\n",(unsigned int) ftell(f));
-		fflush(debug);
-		fread(&name,25,1,f);
-		//char* sname = new char[26];
-		char sname[26];
-		sprintf(sname,"%s",strtok(name,"_"));	// spreadsheet name
-		char* cname = strtok(NULL,"_");	// column name
-		while(char* tmpstr = strtok(NULL,"_")) {	// get multiple-"_" title correct
-			strcat(sname,"_");
-			strcat(sname,cname);
-			strcpy(cname,tmpstr);
-		}
-		int spread=0;
-		if(SPREADSHEET.size() == 0 || compareSpreadnames(sname) == -1) {
-			fprintf(debug,"NEW SPREADSHEET\n");
-			current_col=1;
-			SPREADSHEET.push_back(spreadSheet(sname));
-			spread=static_cast<int>(SPREADSHEET.size())-1;
-			SPREADSHEET.back().maxRows=0;
-		}
-		else {
-
-			spread=compareSpreadnames(sname);
-
-			current_col=static_cast<int>(SPREADSHEET[spread].column.size());
-
-			if(!current_col)
-				current_col=1;
-			current_col++;
-		}
-		fprintf(debug,"SPREADSHEET = %s COLUMN %d NAME = %s (@0x%X)\n",
-			sname, current_col, cname, (unsigned int) ftell(f));
-		fflush(debug);
-
-		if(cname == 0) {
-			fprintf(debug,"NO COLUMN NAME FOUND! Must be a matrix or function.\n");
-			////////////////////////////// READ MATRIX or FUNCTION ////////////////////////////////////
-			fprintf(debug,"Reading MATRIX.\n");
-			fflush(debug);
-
-			fprintf(debug,"	[position @ 0x%X]\n",(unsigned int) ftell(f));
-			// TODO
-			fprintf(debug,"	SIGNATURE : ");
-			for(i=0;i<2;i++) {	// skip header
-				fread(&c,1,1,f);
-				fprintf(debug,"%.2X ",c);
-			}
-			fflush(debug);
-
-			do{	// skip until '\n'
-				fread(&c,1,1,f);
-				// fprintf(debug,"%.2X ",c);
-			} while (c != '\n');
-			fprintf(debug,"\n");
-			fflush(debug);
-
-			// read size
-			int size;
-			fread(&size,4,1,f);
-			fread(&c,1,1,f);	// skip '\n'
-			// TODO : use entry size : double, float, ...
-			size /= 8;
-			fprintf(debug,"	SIZE = %d\n",size);
-			fflush(debug);
-
-			// catch exception
-			if(size>10000)
-				size=1000;
-
-			fprintf(debug,"VALUES :\n");
-			SPREADSHEET[SPREADSHEET.size()-1].maxRows=1;
-
-			double value=0;
-			for(i=0;i<size;i++) {	// read data
-				string stmp;
-				if(i<26)
-					stmp=char(i+0x41);
-				else if(i<26*26) {
-					stmp = char(0x40+i/26);
+  int i;
+  FILE *f, *debug;
+  if((f=fopen(filename,"rb")) == NULL ) {
+    printf("Could not open %s!\n",filename);
+    return -1;
+  }
+
+  if((debug=fopen("opjfile.log","w")) == NULL ) {
+    printf("Could not open log file!\n");
+    return -1;
+  }
+
+  ////////////////////////////// check version from header ///////////////////////////////
+  char vers[5];
+  vers[4]=0;
+
+  // get version
+  fseek(f,0x7,SEEK_SET);
+  fread(&vers,4,1,f);
+  version = atoi(vers);
+  fprintf(debug," [version = %d]\n",version);
+
+  // translate version
+  if(version >= 130 && version <= 140)    // 4.1
+    version=410;
+  else if(version == 210)   // 5.0
+    version=500;
+  else if(version == 2625)  // 6.0
+    version=600;
+  else if(version == 2627)  // 6.0 SR1
+    version=601;
+  else if(version == 2630 )   // 6.0 SR4
+    version=604;
+  else if(version == 2635 )   // 6.1
+    version=610;
+  else if(version == 2656)  // 7.0
+    version=700;
+  else if(version == 2672)  // 7.0 SR3
+    version=703;
+  else {
+    fprintf(debug,"Found unknown project version %d\n",version);
+    fprintf(debug,"Please contact the author of opj2dat\n");
+  }
+  fprintf(debug,"Found project version %.2f\n",version/100.0);
+
+  unsigned char c=0;  // tmp char
+
+  fprintf(debug,"HEADER :\n");
+  for(i=0;i<0x16;i++) { // skip header + 5 Bytes ("27")
+    fread(&c,1,1,f);
+    fprintf(debug,"%.2X ",c);
+    if(!((i+1)%16)) fprintf(debug,"\n");
+  }
+  fprintf(debug,"\n");
+
+  do{
+    fread(&c,1,1,f);
+  } while (c != '\n');
+  fprintf(debug," [file header @ 0x%X]\n", (unsigned int) ftell(f));
+
+  /////////////////// find column ///////////////////////////////////////////////////////////
+  if(version>410)
+    for(i=0;i<5;i++)  // skip "0"
+      fread(&c,1,1,f);
+
+  int col_found;
+  fread(&col_found,4,1,f);
+  if(IsBigEndian()) SwapBytes(col_found);
+
+  fread(&c,1,1,f);  // skip '\n'
+  fprintf(debug," [column found = %d/0x%X @ 0x%X]\n",col_found,col_found,(unsigned int) ftell(f));
+
+  int current_col=1, nr=0, nbytes=0;
+  double a;
+  char name[25], valuesize;
+  while(col_found > 0 && col_found < 0x84) {  // should be 0x72, 0x73 or 0x83
+    //////////////////////////////// COLUMN HEADER /////////////////////////////////////////////
+    fprintf(debug,"COLUMN HEADER :\n");
+    for(i=0;i < 0x3D;i++) { // skip 0x3C chars to value size
+      fread(&c,1,1,f);
+      //if(i>21 && i<27) {
+      fprintf(debug,"%.2X ",c);
+      if(!((i+1)%16)) fprintf(debug,"\n");
+      //}
+    }
+    fprintf(debug,"\n");
+
+    fread(&valuesize,1,1,f);
+    fprintf(debug," [valuesize = %d @ 0x%X]\n",valuesize,(unsigned int) ftell(f)-1);
+    if(valuesize <= 0) {
+      fprintf(debug," WARNING : found strange valuesize of %d\n",valuesize);
+      valuesize=10;
+    }
+
+    fprintf(debug,"SKIP :\n");
+    for(i=0;i<0x1A;i++) { // skip to name
+      fread(&c,1,1,f);
+      fprintf(debug,"%.2X ",c);
+      if(!((i+1)%16)) fprintf(debug,"\n");
+    }
+    fprintf(debug,"\n");
+
+    // read name
+    fprintf(debug," [Spreadsheet @ 0x%X]\n",(unsigned int) ftell(f));
+    fflush(debug);
+    fread(&name,25,1,f);
+    //char* sname = new char[26];
+    char sname[26];
+    sprintf(sname,"%s",strtok(name,"_")); // spreadsheet name
+    char* cname = strtok(NULL,"_"); // column name
+    while(char* tmpstr = strtok(NULL,"_")) {  // get multiple-"_" title correct
+      strcat(sname,"_");
+      strcat(sname,cname);
+      strcpy(cname,tmpstr);
+    }
+    int spread=0;
+    if(SPREADSHEET.size() == 0 || compareSpreadnames(sname) == -1) {
+      fprintf(debug,"NEW SPREADSHEET\n");
+      current_col=1;
+      SPREADSHEET.push_back(spreadSheet(sname));
+      spread=static_cast<int>(SPREADSHEET.size())-1;
+      SPREADSHEET.back().maxRows=0;
+    }
+    else {
+
+      spread=compareSpreadnames(sname);
+
+      current_col=static_cast<int>(SPREADSHEET[spread].column.size());
+
+      if(!current_col)
+        current_col=1;
+      current_col++;
+    }
+    fprintf(debug,"SPREADSHEET = %s COLUMN %d NAME = %s (@0x%X)\n",
+      sname, current_col, cname, (unsigned int) ftell(f));
+    fflush(debug);
+
+    if(cname == 0) {
+      fprintf(debug,"NO COLUMN NAME FOUND! Must be a matrix or function.\n");
+      ////////////////////////////// READ MATRIX or FUNCTION ////////////////////////////////////
+      fprintf(debug,"Reading MATRIX.\n");
+      fflush(debug);
+
+      fprintf(debug," [position @ 0x%X]\n",(unsigned int) ftell(f));
+      // TODO
+      fprintf(debug," SIGNATURE : ");
+      for(i=0;i<2;i++) {  // skip header
+        fread(&c,1,1,f);
+        fprintf(debug,"%.2X ",c);
+      }
+      fflush(debug);
+
+      do{ // skip until '\n'
+        fread(&c,1,1,f);
+        // fprintf(debug,"%.2X ",c);
+      } while (c != '\n');
+      fprintf(debug,"\n");
+      fflush(debug);
+
+      // read size
+      int size;
+      fread(&size,4,1,f);
+      fread(&c,1,1,f);  // skip '\n'
+      // TODO : use entry size : double, float, ...
+      size /= 8;
+      fprintf(debug," SIZE = %d\n",size);
+      fflush(debug);
+
+      // catch exception
+      if(size>10000)
+        size=1000;
+
+      fprintf(debug,"VALUES :\n");
+      SPREADSHEET[SPREADSHEET.size()-1].maxRows=1;
+
+      double value=0;
+      for(i=0;i<size;i++) { // read data
+        string stmp;
+        if(i<26)
+          stmp=char(i+0x41);
+        else if(i<26*26) {
+          stmp = char(0x40+i/26);
                                         stmp[1] = i%26+0x41;
-				}
-				else {
-					stmp = char(0x40+i/26/26);
-					stmp[1] = char(i/26%26+0x41);
-					stmp[2] = char(i%26+0x41);
-				}
-				SPREADSHEET[SPREADSHEET.size()-1].column.push_back(stmp);
-				fread(&value,8,1,f);
-				SPREADSHEET[SPREADSHEET.size()-1].column[i].odata.push_back(originData(value));
-
-				fprintf(debug,"%g ",value);
-			}
-			fprintf(debug,"\n");
-			fflush(debug);
-
-		}
-		else {	// worksheet
-			SPREADSHEET[spread].column.push_back(spreadColumn(cname));
-
-			////////////////////////////// SIZE of column /////////////////////////////////////////////
-			do{	// skip until '\n'
-				fread(&c,1,1,f);
-			} while (c != '\n');
-
-			fread(&nbytes,4,1,f);
-			if(IsBigEndian()) SwapBytes(nbytes);
-			if(fmod(nbytes,(double)valuesize)>0)
-				fprintf(debug,"WARNING: data section could not be read correct\n");
-			nr = nbytes / valuesize;
-			fprintf(debug,"	[number of rows = %d (%d Bytes) @ 0x%X]\n",nr,nbytes,(unsigned int) ftell(f));
-			fflush(debug);
-
-			SPREADSHEET[spread].maxRows<nr?SPREADSHEET[spread].maxRows=nr:0;
-
-			////////////////////////////////////// DATA ////////////////////////////////////////////////
-			fread(&c,1,1,f);	// skip '\n'
-			if(valuesize != 8 && valuesize <= 16) {	// skip 0 0
-				fread(&c,1,1,f);
-				fread(&c,1,1,f);
-			}
-			fprintf(debug,"	[data @ 0x%X]\n",(unsigned int) ftell(f));
-			fflush(debug);
-
-			for (i=0;i<nr;i++) {
-				if(valuesize <= 16) {	// value
-					fread(&a,valuesize,1,f);
-					if(IsBigEndian()) SwapBytes(a);
-					fprintf(debug,"%g ",a);
-					SPREADSHEET[spread].column[(current_col-1)].odata.push_back(originData(a));
-				}
-				else {			// label
-					char *stmp = new char[valuesize+1];
-					fread(stmp,valuesize,1,f);
-					fprintf(debug,"%s ",stmp);
-					SPREADSHEET[spread].column[(current_col-1)].odata.push_back(originData(stmp));
-					delete [] stmp;
-				}
-			}
-		}	// else
-		//		fprintf(debug,"	[now @ 0x%X]\n",ftell(f));
-		fprintf(debug,"\n");
-		fflush(debug);
-
-		for(i=0;i<4;i++)	// skip "0"
-			fread(&c,1,1,f);
-		if(valuesize == 8 || valuesize > 16) {	// skip 0 0
-			fread(&c,1,1,f);
-			fread(&c,1,1,f);
-		}
-		fread(&col_found,4,1,f);
-		if(IsBigEndian()) SwapBytes(col_found);
-		fread(&c,1,1,f);	// skip '\n'
-		fprintf(debug,"	[column found = %d/0x%X (@ 0x%X)]\n",col_found,col_found,(unsigned int) ftell(f)-5);
-		fflush(debug);
-	}
-
-	////////////////////// HEADER SECTION //////////////////////////////////////
-	// TODO : use new method ('\n')
-
-	int POS = int(ftell(f)-11);
-	fprintf(debug,"\nHEADER SECTION\n");
-	fprintf(debug,"	nr_spreads = %d\n",SPREADSHEET.size());
-	fprintf(debug,"	[position @ 0x%X]\n",POS);
-	fflush(debug);
+        }
+        else {
+          stmp = char(0x40+i/26/26);
+          stmp[1] = char(i/26%26+0x41);
+          stmp[2] = char(i%26+0x41);
+        }
+        SPREADSHEET[SPREADSHEET.size()-1].column.push_back(stmp);
+        fread(&value,8,1,f);
+        SPREADSHEET[SPREADSHEET.size()-1].column[i].odata.push_back(originData(value));
+
+        fprintf(debug,"%g ",value);
+      }
+      fprintf(debug,"\n");
+      fflush(debug);
+
+    }
+    else {  // worksheet
+      SPREADSHEET[spread].column.push_back(spreadColumn(cname));
+
+      ////////////////////////////// SIZE of column /////////////////////////////////////////////
+      do{ // skip until '\n'
+        fread(&c,1,1,f);
+      } while (c != '\n');
+
+      fread(&nbytes,4,1,f);
+      if(IsBigEndian()) SwapBytes(nbytes);
+      if(fmod(nbytes,(double)valuesize)>0)
+        fprintf(debug,"WARNING: data section could not be read correct\n");
+      nr = nbytes / valuesize;
+      fprintf(debug," [number of rows = %d (%d Bytes) @ 0x%X]\n",nr,nbytes,(unsigned int) ftell(f));
+      fflush(debug);
+
+      SPREADSHEET[spread].maxRows<nr?SPREADSHEET[spread].maxRows=nr:0;
+
+      ////////////////////////////////////// DATA ////////////////////////////////////////////////
+      fread(&c,1,1,f);  // skip '\n'
+      if(valuesize != 8 && valuesize <= 16) { // skip 0 0
+        fread(&c,1,1,f);
+        fread(&c,1,1,f);
+      }
+      fprintf(debug," [data @ 0x%X]\n",(unsigned int) ftell(f));
+      fflush(debug);
+
+      for (i=0;i<nr;i++) {
+        if(valuesize <= 16) { // value
+          fread(&a,valuesize,1,f);
+          if(IsBigEndian()) SwapBytes(a);
+          fprintf(debug,"%g ",a);
+          SPREADSHEET[spread].column[(current_col-1)].odata.push_back(originData(a));
+        }
+        else {      // label
+          char *stmp = new char[valuesize+1];
+          fread(stmp,valuesize,1,f);
+          fprintf(debug,"%s ",stmp);
+          SPREADSHEET[spread].column[(current_col-1)].odata.push_back(originData(stmp));
+          delete [] stmp;
+        }
+      }
+    } // else
+    //    fprintf(debug," [now @ 0x%X]\n",ftell(f));
+    fprintf(debug,"\n");
+    fflush(debug);
+
+    for(i=0;i<4;i++)  // skip "0"
+      fread(&c,1,1,f);
+    if(valuesize == 8 || valuesize > 16) {  // skip 0 0
+      fread(&c,1,1,f);
+      fread(&c,1,1,f);
+    }
+    fread(&col_found,4,1,f);
+    if(IsBigEndian()) SwapBytes(col_found);
+    fread(&c,1,1,f);  // skip '\n'
+    fprintf(debug," [column found = %d/0x%X (@ 0x%X)]\n",col_found,col_found,(unsigned int) ftell(f)-5);
+    fflush(debug);
+  }
+
+  ////////////////////// HEADER SECTION //////////////////////////////////////
+  // TODO : use new method ('\n')
+
+  int POS = int(ftell(f)-11);
+  fprintf(debug,"\nHEADER SECTION\n");
+  fprintf(debug," nr_spreads = %d\n",SPREADSHEET.size());
+  fprintf(debug," [position @ 0x%X]\n",POS);
+  fflush(debug);
 
 ///////////////////// SPREADSHEET INFOS ////////////////////////////////////
-	int LAYER=0;
-	int COL_JUMP = 0x1ED;
-	for(unsigned int i=0; i < SPREADSHEET.size(); i++) {
-	fprintf(debug,"		reading	Spreadsheet %d/%zd properties\n",i+1,SPREADSHEET.size());
-	fflush(debug);
-	if(i > 0) {
-		if (version == 700 )
-			POS += 0x2530 + static_cast<int>(SPREADSHEET[i-1].column.size())*COL_JUMP;
-		else if (version == 610 )
-			POS += 0x25A4 + static_cast<int>(SPREADSHEET[i-1].column.size())*COL_JUMP;
-		else if (version == 604 )
-			POS += 0x25A0 + static_cast<int>(SPREADSHEET[i-1].column.size())*COL_JUMP;
-		else if (version == 601 )
-			POS += 0x2560 + static_cast<int>(SPREADSHEET[i-1].column.size())*COL_JUMP;	// ?
-		else if (version == 600 )
-			POS += 0x2560 + static_cast<int>(SPREADSHEET[i-1].column.size())*COL_JUMP;
-		else if (version == 500 )
-			POS += 0x92C + static_cast<int>(SPREADSHEET[i-1].column.size())*COL_JUMP;
-		else if (version == 410 )
-			POS += 0x7FB + static_cast<int>(SPREADSHEET[i-1].column.size())*COL_JUMP;
-	}
-
-	fprintf(debug,"			reading	Header\n");
-	fflush(debug);
-	// HEADER
-	// check header
-	int ORIGIN = 0x55;
-	if(version == 500)
-		ORIGIN = 0x58;
-	fseek(f,POS + ORIGIN,SEEK_SET);	// check for 'O'RIGIN
-	char c;
-	fread(&c,1,1,f);
-	int jump=0;
-	if( c == 'O')
-		fprintf(debug,"			\"ORIGIN\" found ! (@ 0x%X)\n",POS+ORIGIN);
-	while( c != 'O' && jump < MAX_LEVEL) {	// no inf loop
-		fprintf(debug,"		TRY %d	\"O\"RIGIN not found ! : %c (@ 0x%X)",jump+1,c,POS+ORIGIN);
-		fprintf(debug,"			POS=0x%X | ORIGIN = 0x%X\n",POS,ORIGIN);
-		fflush(debug);
-		POS+=0x1F2;
-		fseek(f,POS + ORIGIN,SEEK_SET);
-		fread(&c,1,1,f);
-		jump++;
-	}
-
-	int spread=i;
-	if(jump == MAX_LEVEL){
-		fprintf(debug,"		Spreadsheet SECTION not found ! 	(@ 0x%X)\n",POS-10*0x1F2+0x55);
-		// setColName(spread);
-		return -5;
-	}
-
-	fprintf(debug,"			[Spreadsheet SECTION (@ 0x%X)]\n",POS);
-	fflush(debug);
-
-	// check spreadsheet name
-	fseek(f,POS + 0x12,SEEK_SET);
-	fread(&name,25,1,f);
-
-	spread=compareSpreadnames(name);
-	if(spread == -1)
-		spread=i;
-
-	fprintf(debug,"			SPREADSHEET %d NAME : %s	(@ 0x%X) has %d columns\n",
-		spread+1,name,POS + 0x12,SPREADSHEET[spread].column.size());
-	fflush(debug);
-
-	int ATYPE=0;
-	LAYER = POS;
-	if (version == 700)
-		ATYPE = 0x2E4;
-	else if (version == 610)
-		ATYPE = 0x358;
-	else if (version == 604)
-		ATYPE = 0x354;
-	else if (version == 601)
-		ATYPE = 0x500;	// ?
-	else if (version == 600)
-		ATYPE = 0x314;
-	else if (version == 500) {
-		COL_JUMP=0x5D;
-		ATYPE = 0x300;
-	}
-	else if (version == 410) {
-		COL_JUMP = 0x58;
-		ATYPE = 0x229;
-	}
-	fflush(debug);
-
-	/////////////// COLUMN Types ///////////////////////////////////////////
-	fprintf(debug,"			Spreadsheet has %d columns\n",SPREADSHEET[spread].column.size());
-	for (unsigned int j=0;j<SPREADSHEET[spread].column.size();j++) {
-		fprintf(debug,"			reading	COLUMN %d/%zd type\n",j+1,SPREADSHEET[spread].column.size());
-		fflush(debug);
-		fseek(f,LAYER+ATYPE+j*COL_JUMP, SEEK_SET);
-		fread(&name,25,1,f);
-
-		fseek(f,LAYER+ATYPE+j*COL_JUMP-1, SEEK_SET);
-		fread(&c,1,1,f);
-		ColumnType type;
-		switch(c) {
-			case 3:
-				type = X;
-				break;
-			case 0:
-				type = Y;
-				break;
-			case 5:
-				type = Z;
-				break;
-			case 6:
-				type = XErr;
-				break;
-			case 2:
-				type = YErr;
-				break;
-			case 4:
-				type = Label;
-				break;
-			default:
-				type = NONE;
-				break;
-		}
-
-		SPREADSHEET[spread].column[j].type=type;
-
-		fprintf(debug,"				COLUMN \"%s\" type = %s (@ 0x%X)\n",
-			SPREADSHEET[spread].column[j].name.c_str(),type,LAYER+ATYPE+j*COL_JUMP);
-		fflush(debug);
-
-		// check column name
-		int max_length=11;	// only first 11 chars are saved here !
-		int name_length = static_cast<int>(SPREADSHEET[spread].column[j].name.length());
+  int LAYER=0;
+  int COL_JUMP = 0x1ED;
+  for(unsigned int i=0; i < SPREADSHEET.size(); i++) {
+  fprintf(debug,"   reading Spreadsheet %d/%zd properties\n",i+1,SPREADSHEET.size());
+  fflush(debug);
+  if(i > 0) {
+    if (version == 700 )
+      POS += 0x2530 + static_cast<int>(SPREADSHEET[i-1].column.size())*COL_JUMP;
+    else if (version == 610 )
+      POS += 0x25A4 + static_cast<int>(SPREADSHEET[i-1].column.size())*COL_JUMP;
+    else if (version == 604 )
+      POS += 0x25A0 + static_cast<int>(SPREADSHEET[i-1].column.size())*COL_JUMP;
+    else if (version == 601 )
+      POS += 0x2560 + static_cast<int>(SPREADSHEET[i-1].column.size())*COL_JUMP;  // ?
+    else if (version == 600 )
+      POS += 0x2560 + static_cast<int>(SPREADSHEET[i-1].column.size())*COL_JUMP;
+    else if (version == 500 )
+      POS += 0x92C + static_cast<int>(SPREADSHEET[i-1].column.size())*COL_JUMP;
+    else if (version == 410 )
+      POS += 0x7FB + static_cast<int>(SPREADSHEET[i-1].column.size())*COL_JUMP;
+  }
+
+  fprintf(debug,"     reading Header\n");
+  fflush(debug);
+  // HEADER
+  // check header
+  int ORIGIN = 0x55;
+  if(version == 500)
+    ORIGIN = 0x58;
+  fseek(f,POS + ORIGIN,SEEK_SET); // check for 'O'RIGIN
+  char c;
+  fread(&c,1,1,f);
+  int jump=0;
+  if( c == 'O')
+    fprintf(debug,"     \"ORIGIN\" found ! (@ 0x%X)\n",POS+ORIGIN);
+  while( c != 'O' && jump < MAX_LEVEL) {  // no inf loop
+    fprintf(debug,"   TRY %d  \"O\"RIGIN not found ! : %c (@ 0x%X)",jump+1,c,POS+ORIGIN);
+    fprintf(debug,"     POS=0x%X | ORIGIN = 0x%X\n",POS,ORIGIN);
+    fflush(debug);
+    POS+=0x1F2;
+    fseek(f,POS + ORIGIN,SEEK_SET);
+    fread(&c,1,1,f);
+    jump++;
+  }
+
+  int spread=i;
+  if(jump == MAX_LEVEL){
+    fprintf(debug,"   Spreadsheet SECTION not found !   (@ 0x%X)\n",POS-10*0x1F2+0x55);
+    // setColName(spread);
+    fclose(f);
+    fclose(debug);
+    return -5;
+  }
+
+  fprintf(debug,"     [Spreadsheet SECTION (@ 0x%X)]\n",POS);
+  fflush(debug);
+
+  // check spreadsheet name
+  fseek(f,POS + 0x12,SEEK_SET);
+  fread(&name,25,1,f);
+
+  spread=compareSpreadnames(name);
+  if(spread == -1)
+    spread=i;
+
+  fprintf(debug,"     SPREADSHEET %d NAME : %s  (@ 0x%X) has %d columns\n",
+    spread+1,name,POS + 0x12,SPREADSHEET[spread].column.size());
+  fflush(debug);
+
+  int ATYPE=0;
+  LAYER = POS;
+  if (version == 700)
+    ATYPE = 0x2E4;
+  else if (version == 610)
+    ATYPE = 0x358;
+  else if (version == 604)
+    ATYPE = 0x354;
+  else if (version == 601)
+    ATYPE = 0x500;  // ?
+  else if (version == 600)
+    ATYPE = 0x314;
+  else if (version == 500) {
+    COL_JUMP=0x5D;
+    ATYPE = 0x300;
+  }
+  else if (version == 410) {
+    COL_JUMP = 0x58;
+    ATYPE = 0x229;
+  }
+  fflush(debug);
+
+  /////////////// COLUMN Types ///////////////////////////////////////////
+  fprintf(debug,"     Spreadsheet has %d columns\n",SPREADSHEET[spread].column.size());
+  for (unsigned int j=0;j<SPREADSHEET[spread].column.size();j++) {
+    fprintf(debug,"     reading COLUMN %d/%zd type\n",j+1,SPREADSHEET[spread].column.size());
+    fflush(debug);
+    fseek(f,LAYER+ATYPE+j*COL_JUMP, SEEK_SET);
+    fread(&name,25,1,f);
+
+    fseek(f,LAYER+ATYPE+j*COL_JUMP-1, SEEK_SET);
+    fread(&c,1,1,f);
+    ColumnType type;
+    switch(c) {
+      case 3:
+        type = X;
+        break;
+      case 0:
+        type = Y;
+        break;
+      case 5:
+        type = Z;
+        break;
+      case 6:
+        type = XErr;
+        break;
+      case 2:
+        type = YErr;
+        break;
+      case 4:
+        type = Label;
+        break;
+      default:
+        type = NONE;
+        break;
+    }
+
+    SPREADSHEET[spread].column[j].type=type;
+
+    fprintf(debug,"       COLUMN \"%s\" type = %s (@ 0x%X)\n",
+      SPREADSHEET[spread].column[j].name.c_str(),type,LAYER+ATYPE+j*COL_JUMP);
+    fflush(debug);
+
+    // check column name
+    int max_length=11;  // only first 11 chars are saved here !
+    int name_length = static_cast<int>(SPREADSHEET[spread].column[j].name.length());
                     int length = (name_length < max_length) ? name_length : max_length;
 
-		if(SPREADSHEET[spread].column[j].name.substr(0,length) == name) {
-			fprintf(debug,"				TEST : column name = \"%s\". OK!\n",
-				SPREADSHEET[spread].column[j].name.c_str());
-		}
-		else {
-			fprintf(debug,"				TEST : COLUMN %d name mismatch (\"%s\" != \"%s\")\n",
-				j+1,name,SPREADSHEET[spread].column[j].name.c_str());
-			//fprintf(debug,"ERROR : column name mismatch! Continue anyway.\n"ERROR_MSG);
-		}
-		fflush(debug);
-	}
-		fprintf(debug,"		Done with spreadsheet %d\n",spread);
-		fflush(debug);
-	}
+    if(SPREADSHEET[spread].column[j].name.substr(0,length) == name) {
+      fprintf(debug,"       TEST : column name = \"%s\". OK!\n",
+        SPREADSHEET[spread].column[j].name.c_str());
+    }
+    else {
+      fprintf(debug,"       TEST : COLUMN %d name mismatch (\"%s\" != \"%s\")\n",
+        j+1,name,SPREADSHEET[spread].column[j].name.c_str());
+      //fprintf(debug,"ERROR : column name mismatch! Continue anyway.\n"ERROR_MSG);
+    }
+    fflush(debug);
+  }
+    fprintf(debug,"   Done with spreadsheet %d\n",spread);
+    fflush(debug);
+  }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////////////
 
-	// TODO : GRAPHS
+  // TODO : GRAPHS
 
-	fprintf(debug,"Done parsing\n");
-	fclose(debug);
+  fprintf(debug,"Done parsing\n");
+  fclose(debug);
+  fclose(f);
 
-	return 0;
+  return 0;
 }
 
 
 int OPJFile::ParseFormatNew() {
-	int i;
-	FILE *f, *debug;
-	if((f=fopen(filename,"rb")) == NULL ) {
-		printf("Could not open %s!\n",filename);
-		return -1;
-	}
-
-	if((debug=fopen("opjfile.log","w")) == NULL ) {
-		printf("Could not open log file!\n");
-		return -1;
-	}
+  int i;
+  FILE *f, *debug;
+  if((f=fopen(filename,"rb")) == NULL ) {
+    printf("Could not open %s!\n",filename);
+    return -1;
+  }
+
+  if((debug=fopen("opjfile.log","w")) == NULL ) {
+    printf("Could not open log file!\n");
+    fclose(f);
+    return -1;
+  }
 
 ////////////////////////////// check version from header ///////////////////////////////
-	char vers[5];
-	vers[4]=0;
-
-	// get version
-	fseek(f,0x7,SEEK_SET);
-	fread(&vers,4,1,f);
-	version = atoi(vers);
-	fprintf(debug,"	[version = %d]\n",version);
-
-	// translate version
-	if(version >= 130 && version <= 140) 		// 4.1
-		version=410;
-	else if(version == 210) 	// 5.0
-		version=500;
-	else if(version == 2625) 	// 6.0
-		version=600;
-	else if(version == 2627) 	// 6.0 SR1
-		version=601;
-	else if(version == 2630 ) 	// 6.0 SR4
-		version=604;
-	else if(version == 2635 ) 	// 6.1
-		version=610;
-	else if(version == 2656) 	// 7.0
-		version=700;
-	else if(version == 2672) 	// 7.0 SR3
-		version=703;
-	else if(version >= 2766 && version <= 2769) 	// 7.5
-		version=750;
-	else {
-		fprintf(debug,"Found unknown project version %d\n",version);
-		fprintf(debug,"Please contact the author of opj2dat\n");
-	}
-	fprintf(debug,"Found project version %.2f\n",version/100.0);
-
-	unsigned char c=0;	// tmp char
-
-	fprintf(debug,"HEADER :\n");
-	for(i=0;i<0x16;i++) {	// skip header + 5 Bytes ("27")
-		fread(&c,1,1,f);
-		fprintf(debug,"%.2X ",c);
-		if(!((i+1)%16)) fprintf(debug,"\n");
-	}
-	fprintf(debug,"\n");
-
-	do{
-		fread(&c,1,1,f);
-	} while (c != '\n');
-	fprintf(debug,"	[file header @ 0x%X]\n", (unsigned int) ftell(f));
+  char vers[5];
+  vers[4]=0;
+
+  // get version
+  fseek(f,0x7,SEEK_SET);
+  fread(&vers,4,1,f);
+  version = atoi(vers);
+  fprintf(debug," [version = %d]\n",version);
+
+  // translate version
+  if(version >= 130 && version <= 140)    // 4.1
+    version=410;
+  else if(version == 210)   // 5.0
+    version=500;
+  else if(version == 2625)  // 6.0
+    version=600;
+  else if(version == 2627)  // 6.0 SR1
+    version=601;
+  else if(version == 2630 )   // 6.0 SR4
+    version=604;
+  else if(version == 2635 )   // 6.1
+    version=610;
+  else if(version == 2656)  // 7.0
+    version=700;
+  else if(version == 2672)  // 7.0 SR3
+    version=703;
+  else if(version >= 2766 && version <= 2769)   // 7.5
+    version=750;
+  else {
+    fprintf(debug,"Found unknown project version %d\n",version);
+    fprintf(debug,"Please contact the author of opj2dat\n");
+  }
+  fprintf(debug,"Found project version %.2f\n",version/100.0);
+
+  unsigned char c=0;  // tmp char
+
+  fprintf(debug,"HEADER :\n");
+  for(i=0;i<0x16;i++) { // skip header + 5 Bytes ("27")
+    fread(&c,1,1,f);
+    fprintf(debug,"%.2X ",c);
+    if(!((i+1)%16)) fprintf(debug,"\n");
+  }
+  fprintf(debug,"\n");
+
+  do{
+    fread(&c,1,1,f);
+  } while (c != '\n');
+  fprintf(debug," [file header @ 0x%X]\n", (unsigned int) ftell(f));
 
 /////////////////// find column ///////////////////////////////////////////////////////////
-	if(version>410)
-		for(i=0;i<5;i++)	// skip "0"
-			fread(&c,1,1,f);
-
-	int col_found;
-	fread(&col_found,4,1,f);
-	if(IsBigEndian()) SwapBytes(col_found);
-
-	fread(&c,1,1,f);	// skip '\n'
-	fprintf(debug,"	[column found = %d/0x%X @ 0x%X]\n",col_found,col_found,(unsigned int) ftell(f));
-	int colpos=int(ftell(f));
-
-	int current_col=1, nr=0, nbytes=0;
-	double a;
-	char name[25], valuesize;
-	while(col_found > 0 && col_found < 0x84) {	// should be 0x72, 0x73 or 0x83
+  if(version>410)
+    for(i=0;i<5;i++)  // skip "0"
+      fread(&c,1,1,f);
+
+  int col_found;
+  fread(&col_found,4,1,f);
+  if(IsBigEndian()) SwapBytes(col_found);
+
+  fread(&c,1,1,f);  // skip '\n'
+  fprintf(debug," [column found = %d/0x%X @ 0x%X]\n",col_found,col_found,(unsigned int) ftell(f));
+  int colpos=int(ftell(f));
+
+  int current_col=1, nr=0, nbytes=0;
+  double a;
+  char name[25], valuesize;
+  while(col_found > 0 && col_found < 0x84) {  // should be 0x72, 0x73 or 0x83
 //////////////////////////////// COLUMN HEADER /////////////////////////////////////////////
-		short data_type;
-		char data_type_u;
-		int oldpos=int(ftell(f));
-		fseek(f,oldpos+0x16,SEEK_SET);
-		fread(&data_type,2,1,f);
-		if(IsBigEndian()) SwapBytes(data_type);
-		fseek(f,oldpos+0x3F,SEEK_SET);
-		fread(&data_type_u,1,1,f);
-		fseek(f,oldpos,SEEK_SET);
-
-		fprintf(debug,"COLUMN HEADER :\n");
-		for(i=0;i < 0x3D;i++) {	// skip 0x3C chars to value size
-			fread(&c,1,1,f);
-			//if(i>21 && i<27) {
-				fprintf(debug,"%.2X ",c);
-				if(!((i+1)%16)) fprintf(debug,"\n");
-			//}
-		}
-		fprintf(debug,"\n");
-
-		fread(&valuesize,1,1,f);
-		fprintf(debug,"	[valuesize = %d @ 0x%X]\n",valuesize,(unsigned int) ftell(f)-1);
-		if(valuesize <= 0) {
-			fprintf(debug,"	WARNING : found strange valuesize of %d\n",valuesize);
-			valuesize=10;
-		}
-
-		fprintf(debug,"SKIP :\n");
-		for(i=0;i<0x1A;i++) {	// skip to name
-			fread(&c,1,1,f);
-			fprintf(debug,"%.2X ",c);
-			if(!((i+1)%16)) fprintf(debug,"\n");
-		}
-		fprintf(debug,"\n");
-
-		// read name
-		fprintf(debug,"	[Spreadsheet @ 0x%X]\n",(unsigned int) ftell(f));
-		fflush(debug);
-		fread(&name,25,1,f);
-		//char* sname = new char[26];
-		char sname[26];
-		sprintf(sname,"%s",strtok(name,"_"));	// spreadsheet name
-		char* cname = strtok(NULL,"_");	// column name
-		while(char* tmpstr = strtok(NULL,"_")) {	// get multiple-"_" title correct
-			strcat(sname,"_");
-			strcat(sname,cname);
-			strcpy(cname,tmpstr);
-		}
-		int spread=0;
-		if(cname == 0) {
-			fprintf(debug,"NO COLUMN NAME FOUND! Must be a matrix or function.\n");
+    short data_type;
+    char data_type_u;
+    int oldpos=int(ftell(f));
+    fseek(f,oldpos+0x16,SEEK_SET);
+    fread(&data_type,2,1,f);
+    if(IsBigEndian()) SwapBytes(data_type);
+    fseek(f,oldpos+0x3F,SEEK_SET);
+    fread(&data_type_u,1,1,f);
+    fseek(f,oldpos,SEEK_SET);
+
+    fprintf(debug,"COLUMN HEADER :\n");
+    for(i=0;i < 0x3D;i++) { // skip 0x3C chars to value size
+      fread(&c,1,1,f);
+      //if(i>21 && i<27) {
+        fprintf(debug,"%.2X ",c);
+        if(!((i+1)%16)) fprintf(debug,"\n");
+      //}
+    }
+    fprintf(debug,"\n");
+
+    fread(&valuesize,1,1,f);
+    fprintf(debug," [valuesize = %d @ 0x%X]\n",valuesize,(unsigned int) ftell(f)-1);
+    if(valuesize <= 0) {
+      fprintf(debug," WARNING : found strange valuesize of %d\n",valuesize);
+      valuesize=10;
+    }
+
+    fprintf(debug,"SKIP :\n");
+    for(i=0;i<0x1A;i++) { // skip to name
+      fread(&c,1,1,f);
+      fprintf(debug,"%.2X ",c);
+      if(!((i+1)%16)) fprintf(debug,"\n");
+    }
+    fprintf(debug,"\n");
+
+    // read name
+    fprintf(debug," [Spreadsheet @ 0x%X]\n",(unsigned int) ftell(f));
+    fflush(debug);
+    fread(&name,25,1,f);
+    //char* sname = new char[26];
+    char sname[26];
+    sprintf(sname,"%s",strtok(name,"_")); // spreadsheet name
+    char* cname = strtok(NULL,"_"); // column name
+    while(char* tmpstr = strtok(NULL,"_")) {  // get multiple-"_" title correct
+      strcat(sname,"_");
+      strcat(sname,cname);
+      strcpy(cname,tmpstr);
+    }
+    int spread=0;
+    if(cname == 0) {
+      fprintf(debug,"NO COLUMN NAME FOUND! Must be a matrix or function.\n");
 ////////////////////////////// READ MATRIX or FUNCTION ////////////////////////////////////
 
-			fprintf(debug,"	[position @ 0x%X]\n",(unsigned int) ftell(f));
-			// TODO
-			short signature;
-			fread(&signature,2,1,f);
-			if(IsBigEndian()) SwapBytes(signature);
-			fprintf(debug,"	SIGNATURE : ");
-			fprintf(debug,"%.2X ",signature);
-			fflush(debug);
-
-			do{	// skip until '\n'
-				fread(&c,1,1,f);
-				// fprintf(debug,"%.2X ",c);
-			} while (c != '\n');
-			fprintf(debug,"\n");
-			fflush(debug);
-
-			// read size
-			int size;
-			fread(&size,4,1,f);
-			if(IsBigEndian()) SwapBytes(size);
-			fread(&c,1,1,f);	// skip '\n'
-			// TODO : use entry size : double, float, ...
-			size /= valuesize;
-			fprintf(debug,"	SIZE = %d\n",size);
-			fflush(debug);
-
-			// catch exception
-			/*if(size>10000)
-				size=1000;*/
-			switch(signature)
-			{
-			case 0x50CA:
-			case 0x70CA:
-			case 0x50F2:
-			case 0x50E2:
-				fprintf(debug,"NEW MATRIX\n");
-				MATRIX.push_back(matrix(sname, dataIndex));
-				dataIndex++;
-
-				fprintf(debug,"VALUES :\n");
-
-				switch(data_type)
-				{
-				case 0x6001://double
-					for(i=0;i<size;i++) {
-						double value;
-						fread(&value,valuesize,1,f);
-						if(IsBigEndian()) SwapBytes(value);
-						MATRIX.back().data.push_back((double)value);
-						fprintf(debug,"%g ",MATRIX.back().data.back());
-					}
-					break;
-				case 0x6003://float
-					for(i=0;i<size;i++) {
-						float value;
-						fread(&value,valuesize,1,f);
-						if(IsBigEndian()) SwapBytes(value);
-						MATRIX.back().data.push_back((double)value);
-						fprintf(debug,"%g ",MATRIX.back().data.back());
-					}
-					break;
-				case 0x6801://int
-					if(data_type_u==8)//unsigned
-						for(i=0;i<size;i++) {
-							unsigned int value;
-							fread(&value,valuesize,1,f);
-							if(IsBigEndian()) SwapBytes(value);
-							MATRIX.back().data.push_back((double)value);
-							fprintf(debug,"%g ",MATRIX.back().data.back());
-						}
-					else
-						for(i=0;i<size;i++) {
-							int value;
-							fread(&value,valuesize,1,f);
-							if(IsBigEndian()) SwapBytes(value);
-							MATRIX.back().data.push_back((double)value);
-							fprintf(debug,"%g ",MATRIX.back().data.back());
-						}
-					break;
-				case 0x6803://short
-					if(data_type_u==8)//unsigned
-						for(i=0;i<size;i++) {
-							unsigned short value;
-							fread(&value,valuesize,1,f);
-							if(IsBigEndian()) SwapBytes(value);
-							MATRIX.back().data.push_back((double)value);
-							fprintf(debug,"%g ",MATRIX.back().data.back());
-						}
-					else
-						for(i=0;i<size;i++) {
-							short value;
-							fread(&value,valuesize,1,f);
-							if(IsBigEndian()) SwapBytes(value);
-							MATRIX.back().data.push_back((double)value);
-							fprintf(debug,"%g ",MATRIX.back().data.back());
-						}
-					break;
-				case 0x6821://char
-					if(data_type_u==8)//unsigned
-						for(i=0;i<size;i++) {
-							unsigned char value;
-							fread(&value,valuesize,1,f);
-							if(IsBigEndian()) SwapBytes(value);
-							MATRIX.back().data.push_back((double)value);
-							fprintf(debug,"%g ",MATRIX.back().data.back());
-						}
-					else
-						for(i=0;i<size;i++) {
-							char value;
-							fread(&value,valuesize,1,f);
-							if(IsBigEndian()) SwapBytes(value);
-							MATRIX.back().data.push_back((double)value);
-							fprintf(debug,"%g ",MATRIX.back().data.back());
-						}
-					break;
-				default:
-					fprintf(debug,"UNKNOWN MATRIX DATATYPE: %.2X SKIP DATA\n", data_type);
-					fseek(f, valuesize*size, SEEK_CUR);
-					MATRIX.pop_back();
-				}
-
-				break;
-			case 0x10C8:
-				fprintf(debug,"NEW FUNCTION\n");
-				FUNCTION.push_back(function(sname, dataIndex));
-				dataIndex++;
-
-				char *cmd;
-				cmd=new char[valuesize+1];
-				cmd[size_t(valuesize)]='\0';
-				fread(cmd,valuesize,1,f);
-				FUNCTION.back().formula=cmd;
-				int oldpos;
-				oldpos=int(ftell(f));
-				short t;
-				fseek(f,colpos+0xA,SEEK_SET);
-				fread(&t,2,1,f);
-				if(IsBigEndian()) SwapBytes(t);
-				if(t==0x1194)
-					FUNCTION.back().type=1;
-				int N;
-				fseek(f,colpos+0x21,SEEK_SET);
-				fread(&N,4,1,f);
-				if(IsBigEndian()) SwapBytes(N);
-				FUNCTION.back().points=N;
-				double d;
-				fread(&d,8,1,f);
-				if(IsBigEndian()) SwapBytes(d);
-				FUNCTION.back().begin=d;
-				fread(&d,8,1,f);
-				if(IsBigEndian()) SwapBytes(d);
-				FUNCTION.back().end=FUNCTION.back().begin+d*(FUNCTION.back().points-1);
-				fprintf(debug,"FUNCTION %s : %s \n", FUNCTION.back().name.c_str(), FUNCTION.back().formula.c_str());
-				fprintf(debug," interval %g : %g, number of points %d \n", FUNCTION.back().begin, FUNCTION.back().end, FUNCTION.back().points);
-				fseek(f,oldpos,SEEK_SET);
-
-				delete [] cmd;
-				break;
-			default:
-				fprintf(debug,"UNKNOWN SIGNATURE: %.2X SKIP DATA\n", signature);
-				fseek(f, valuesize*size, SEEK_CUR);
-				if(valuesize != 8 && valuesize <= 16)
-					fseek(f, 2, SEEK_CUR);
-			}
-
-			fprintf(debug,"\n");
-			fflush(debug);
-		}
-		else {	// worksheet
-			if(SPREADSHEET.size() == 0 || compareSpreadnames(sname) == -1) {
-				fprintf(debug,"NEW SPREADSHEET\n");
-				current_col=1;
-				SPREADSHEET.push_back(spreadSheet(sname));
-				spread=static_cast<int>(SPREADSHEET.size())-1;
-				SPREADSHEET.back().maxRows=0;
-			}
-			else {
-
-				spread=compareSpreadnames(sname);
-
-				current_col=static_cast<int>(SPREADSHEET[spread].column.size());
-
-				if(!current_col)
-					current_col=1;
-				current_col++;
-			}
-			fprintf(debug,"SPREADSHEET = %s COLUMN NAME = %s (%d) (@0x%X)\n",
-				sname, cname,current_col,(unsigned int) ftell(f));
-			fflush(debug);
-			SPREADSHEET[spread].column.push_back(spreadColumn(cname, dataIndex));
-			int sheetpos=static_cast<int>(SPREADSHEET[spread].column.back().name.find_last_of("@"));
-			if(!SPREADSHEET[spread].bMultisheet && sheetpos!=-1)
-				if(atoi(string(cname).substr(sheetpos+1).c_str())>1)
-				{
-					SPREADSHEET[spread].bMultisheet=true;
-					fprintf(debug,"SPREADSHEET \"%s\" IS MULTISHEET \n", sname);
-				}
-			dataIndex++;
+      fprintf(debug," [position @ 0x%X]\n",(unsigned int) ftell(f));
+      // TODO
+      short signature;
+      fread(&signature,2,1,f);
+      if(IsBigEndian()) SwapBytes(signature);
+      fprintf(debug," SIGNATURE : ");
+      fprintf(debug,"%.2X ",signature);
+      fflush(debug);
+
+      do{ // skip until '\n'
+        fread(&c,1,1,f);
+        // fprintf(debug,"%.2X ",c);
+      } while (c != '\n');
+      fprintf(debug,"\n");
+      fflush(debug);
+
+      // read size
+      int size;
+      fread(&size,4,1,f);
+      if(IsBigEndian()) SwapBytes(size);
+      fread(&c,1,1,f);  // skip '\n'
+      // TODO : use entry size : double, float, ...
+      size /= valuesize;
+      fprintf(debug," SIZE = %d\n",size);
+      fflush(debug);
+
+      // catch exception
+      /*if(size>10000)
+        size=1000;*/
+      switch(signature)
+      {
+      case 0x50CA:
+      case 0x70CA:
+      case 0x50F2:
+      case 0x50E2:
+        fprintf(debug,"NEW MATRIX\n");
+        MATRIX.push_back(matrix(sname, dataIndex));
+        dataIndex++;
+
+        fprintf(debug,"VALUES :\n");
+
+        switch(data_type)
+        {
+        case 0x6001://double
+          for(i=0;i<size;i++) {
+            double value;
+            fread(&value,valuesize,1,f);
+            if(IsBigEndian()) SwapBytes(value);
+            MATRIX.back().data.push_back((double)value);
+            fprintf(debug,"%g ",MATRIX.back().data.back());
+          }
+          break;
+        case 0x6003://float
+          for(i=0;i<size;i++) {
+            float value;
+            fread(&value,valuesize,1,f);
+            if(IsBigEndian()) SwapBytes(value);
+            MATRIX.back().data.push_back((double)value);
+            fprintf(debug,"%g ",MATRIX.back().data.back());
+          }
+          break;
+        case 0x6801://int
+          if(data_type_u==8)//unsigned
+            for(i=0;i<size;i++) {
+              unsigned int value;
+              fread(&value,valuesize,1,f);
+              if(IsBigEndian()) SwapBytes(value);
+              MATRIX.back().data.push_back((double)value);
+              fprintf(debug,"%g ",MATRIX.back().data.back());
+            }
+          else
+            for(i=0;i<size;i++) {
+              int value;
+              fread(&value,valuesize,1,f);
+              if(IsBigEndian()) SwapBytes(value);
+              MATRIX.back().data.push_back((double)value);
+              fprintf(debug,"%g ",MATRIX.back().data.back());
+            }
+          break;
+        case 0x6803://short
+          if(data_type_u==8)//unsigned
+            for(i=0;i<size;i++) {
+              unsigned short value;
+              fread(&value,valuesize,1,f);
+              if(IsBigEndian()) SwapBytes(value);
+              MATRIX.back().data.push_back((double)value);
+              fprintf(debug,"%g ",MATRIX.back().data.back());
+            }
+          else
+            for(i=0;i<size;i++) {
+              short value;
+              fread(&value,valuesize,1,f);
+              if(IsBigEndian()) SwapBytes(value);
+              MATRIX.back().data.push_back((double)value);
+              fprintf(debug,"%g ",MATRIX.back().data.back());
+            }
+          break;
+        case 0x6821://char
+          if(data_type_u==8)//unsigned
+            for(i=0;i<size;i++) {
+              unsigned char value;
+              fread(&value,valuesize,1,f);
+              if(IsBigEndian()) SwapBytes(value);
+              MATRIX.back().data.push_back((double)value);
+              fprintf(debug,"%g ",MATRIX.back().data.back());
+            }
+          else
+            for(i=0;i<size;i++) {
+              char value;
+              fread(&value,valuesize,1,f);
+              if(IsBigEndian()) SwapBytes(value);
+              MATRIX.back().data.push_back((double)value);
+              fprintf(debug,"%g ",MATRIX.back().data.back());
+            }
+          break;
+        default:
+          fprintf(debug,"UNKNOWN MATRIX DATATYPE: %.2X SKIP DATA\n", data_type);
+          fseek(f, valuesize*size, SEEK_CUR);
+          MATRIX.pop_back();
+        }
+
+        break;
+      case 0x10C8:
+        fprintf(debug,"NEW FUNCTION\n");
+        FUNCTION.push_back(function(sname, dataIndex));
+        dataIndex++;
+
+        char *cmd;
+        cmd=new char[valuesize+1];
+        cmd[size_t(valuesize)]='\0';
+        fread(cmd,valuesize,1,f);
+        FUNCTION.back().formula=cmd;
+        int oldpos;
+        oldpos=int(ftell(f));
+        short t;
+        fseek(f,colpos+0xA,SEEK_SET);
+        fread(&t,2,1,f);
+        if(IsBigEndian()) SwapBytes(t);
+        if(t==0x1194)
+          FUNCTION.back().type=1;
+        int N;
+        fseek(f,colpos+0x21,SEEK_SET);
+        fread(&N,4,1,f);
+        if(IsBigEndian()) SwapBytes(N);
+        FUNCTION.back().points=N;
+        double d;
+        fread(&d,8,1,f);
+        if(IsBigEndian()) SwapBytes(d);
+        FUNCTION.back().begin=d;
+        fread(&d,8,1,f);
+        if(IsBigEndian()) SwapBytes(d);
+        FUNCTION.back().end=FUNCTION.back().begin+d*(FUNCTION.back().points-1);
+        fprintf(debug,"FUNCTION %s : %s \n", FUNCTION.back().name.c_str(), FUNCTION.back().formula.c_str());
+        fprintf(debug," interval %g : %g, number of points %d \n", FUNCTION.back().begin, FUNCTION.back().end, FUNCTION.back().points);
+        fseek(f,oldpos,SEEK_SET);
+
+        delete [] cmd;
+        break;
+      default:
+        fprintf(debug,"UNKNOWN SIGNATURE: %.2X SKIP DATA\n", signature);
+        fseek(f, valuesize*size, SEEK_CUR);
+        if(valuesize != 8 && valuesize <= 16)
+          fseek(f, 2, SEEK_CUR);
+      }
+
+      fprintf(debug,"\n");
+      fflush(debug);
+    }
+    else {  // worksheet
+      if(SPREADSHEET.size() == 0 || compareSpreadnames(sname) == -1) {
+        fprintf(debug,"NEW SPREADSHEET\n");
+        current_col=1;
+        SPREADSHEET.push_back(spreadSheet(sname));
+        spread=static_cast<int>(SPREADSHEET.size())-1;
+        SPREADSHEET.back().maxRows=0;
+      }
+      else {
+
+        spread=compareSpreadnames(sname);
+
+        current_col=static_cast<int>(SPREADSHEET[spread].column.size());
+
+        if(!current_col)
+          current_col=1;
+        current_col++;
+      }
+      fprintf(debug,"SPREADSHEET = %s COLUMN NAME = %s (%d) (@0x%X)\n",
+        sname, cname,current_col,(unsigned int) ftell(f));
+      fflush(debug);
+      SPREADSHEET[spread].column.push_back(spreadColumn(cname, dataIndex));
+      int sheetpos=static_cast<int>(SPREADSHEET[spread].column.back().name.find_last_of("@"));
+      if(!SPREADSHEET[spread].bMultisheet && sheetpos!=-1)
+        if(atoi(string(cname).substr(sheetpos+1).c_str())>1)
+        {
+          SPREADSHEET[spread].bMultisheet=true;
+          fprintf(debug,"SPREADSHEET \"%s\" IS MULTISHEET \n", sname);
+        }
+      dataIndex++;
 
 ////////////////////////////// SIZE of column /////////////////////////////////////////////
-			do{	// skip until '\n'
-				fread(&c,1,1,f);
-			} while (c != '\n');
+      do{ // skip until '\n'
+        fread(&c,1,1,f);
+      } while (c != '\n');
 
-			fread(&nbytes,4,1,f);
-			if(IsBigEndian()) SwapBytes(nbytes);
-			if(fmod(nbytes,(double)valuesize)>0)
-				fprintf(debug,"WARNING: data section could not be read correct\n");
-			nr = nbytes / valuesize;
-			fprintf(debug,"	[number of rows = %d (%d Bytes) @ 0x%X]\n",nr,nbytes,(unsigned int) ftell(f));
-			fflush(debug);
+      fread(&nbytes,4,1,f);
+      if(IsBigEndian()) SwapBytes(nbytes);
+      if(fmod(nbytes,(double)valuesize)>0)
+        fprintf(debug,"WARNING: data section could not be read correct\n");
+      nr = nbytes / valuesize;
+      fprintf(debug," [number of rows = %d (%d Bytes) @ 0x%X]\n",nr,nbytes,(unsigned int) ftell(f));
+      fflush(debug);
 
-			SPREADSHEET[spread].maxRows<nr?SPREADSHEET[spread].maxRows=nr:0;
+      SPREADSHEET[spread].maxRows<nr?SPREADSHEET[spread].maxRows=nr:0;
 
 ////////////////////////////////////// DATA ////////////////////////////////////////////////
-			fread(&c,1,1,f);	// skip '\n'
-			/*if(valuesize != 8 && valuesize <= 16 && nbytes>0) {	// skip 0 0
-				fread(&c,1,1,f);
-				fread(&c,1,1,f);
-			}*/
-			fprintf(debug,"	[data @ 0x%X]\n",(unsigned int) ftell(f));
-			fflush(debug);
-
-			for (i=0;i<nr;i++) {
-				if(valuesize <= 8) {	// Numeric, Time, Date, Month, Day
-					fread(&a,valuesize,1,f);
-					if(IsBigEndian()) SwapBytes(a);
-					fprintf(debug,"%g ",a);
-					SPREADSHEET[spread].column[(current_col-1)].odata.push_back(originData(a));
-				}
-				else if((data_type&0x100)==0x100) // Text&Numeric
-				{
-					fread(&c,1,1,f);
-					fseek(f,1,SEEK_CUR);
-					if(c==0) //value
-					{
-						//fread(&a,valuesize-2,1,f);
-						fread(&a,8,1,f);
-						if(IsBigEndian()) SwapBytes(a);
-						fprintf(debug,"%g ",a);
-						SPREADSHEET[spread].column[(current_col-1)].odata.push_back(originData(a));
-						fseek(f,valuesize-10,SEEK_CUR);
-					}
-					else //text
-					{
-						char *stmp = new char[valuesize-1];
-						fread(stmp,valuesize-2,1,f);
-						if(strchr(stmp,0x0E)) // try find non-printable symbol - garbage test
-							stmp[0]='\0';
-						SPREADSHEET[spread].column[(current_col-1)].odata.push_back(originData(stmp));
-						fprintf(debug,"%s ",stmp);
-						delete [] stmp;
-					}
-				}
-				else //Text
-				{
-					char *stmp = new char[valuesize+1];
-					fread(stmp,valuesize,1,f);
-					if(strchr(stmp,0x0E)) // try find non-printable symbol - garbage test
-						stmp[0]='\0';
-					SPREADSHEET[spread].column[(current_col-1)].odata.push_back(originData(stmp));
-					fprintf(debug,"%s ",stmp);
-					delete [] stmp;
-				}
-			}
-
-		}	// else
-
-		fprintf(debug,"\n");
-		fflush(debug);
-
-		if(nbytes>0||cname==0)
-			fseek(f,1,SEEK_CUR);
-
-		int tailsize;
-		fread(&tailsize,4,1,f);
-		if(IsBigEndian()) SwapBytes(tailsize);
-		fseek(f,1+tailsize+(tailsize>0?1:0),SEEK_CUR); //skip tail
-		//fseek(f,5+((nbytes>0||cname==0)?1:0),SEEK_CUR);
-		fread(&col_found,4,1,f);
-		if(IsBigEndian()) SwapBytes(col_found);
-		fseek(f,1,SEEK_CUR);	// skip '\n'
-		fprintf(debug,"	[column found = %d/0x%X (@ 0x%X)]\n",col_found,col_found,(unsigned int) ftell(f)-5);
-		colpos=int(ftell(f));
-		fflush(debug);
-	}
+      fread(&c,1,1,f);  // skip '\n'
+      /*if(valuesize != 8 && valuesize <= 16 && nbytes>0) { // skip 0 0
+        fread(&c,1,1,f);
+        fread(&c,1,1,f);
+      }*/
+      fprintf(debug," [data @ 0x%X]\n",(unsigned int) ftell(f));
+      fflush(debug);
+
+      for (i=0;i<nr;i++) {
+        if(valuesize <= 8) {  // Numeric, Time, Date, Month, Day
+          fread(&a,valuesize,1,f);
+          if(IsBigEndian()) SwapBytes(a);
+          fprintf(debug,"%g ",a);
+          SPREADSHEET[spread].column[(current_col-1)].odata.push_back(originData(a));
+        }
+        else if((data_type&0x100)==0x100) // Text&Numeric
+        {
+          fread(&c,1,1,f);
+          fseek(f,1,SEEK_CUR);
+          if(c==0) //value
+          {
+            //fread(&a,valuesize-2,1,f);
+            fread(&a,8,1,f);
+            if(IsBigEndian()) SwapBytes(a);
+            fprintf(debug,"%g ",a);
+            SPREADSHEET[spread].column[(current_col-1)].odata.push_back(originData(a));
+            fseek(f,valuesize-10,SEEK_CUR);
+          }
+          else //text
+          {
+            char *stmp = new char[valuesize-1];
+            fread(stmp,valuesize-2,1,f);
+            if(strchr(stmp,0x0E)) // try find non-printable symbol - garbage test
+              stmp[0]='\0';
+            SPREADSHEET[spread].column[(current_col-1)].odata.push_back(originData(stmp));
+            fprintf(debug,"%s ",stmp);
+            delete [] stmp;
+          }
+        }
+        else //Text
+        {
+          char *stmp = new char[valuesize+1];
+          fread(stmp,valuesize,1,f);
+          if(strchr(stmp,0x0E)) // try find non-printable symbol - garbage test
+            stmp[0]='\0';
+          SPREADSHEET[spread].column[(current_col-1)].odata.push_back(originData(stmp));
+          fprintf(debug,"%s ",stmp);
+          delete [] stmp;
+        }
+      }
+
+    } // else
+
+    fprintf(debug,"\n");
+    fflush(debug);
+
+    if(nbytes>0||cname==0)
+      fseek(f,1,SEEK_CUR);
+
+    int tailsize;
+    fread(&tailsize,4,1,f);
+    if(IsBigEndian()) SwapBytes(tailsize);
+    fseek(f,1+tailsize+(tailsize>0?1:0),SEEK_CUR); //skip tail
+    //fseek(f,5+((nbytes>0||cname==0)?1:0),SEEK_CUR);
+    fread(&col_found,4,1,f);
+    if(IsBigEndian()) SwapBytes(col_found);
+    fseek(f,1,SEEK_CUR);  // skip '\n'
+    fprintf(debug," [column found = %d/0x%X (@ 0x%X)]\n",col_found,col_found,(unsigned int) ftell(f)-5);
+    colpos=int(ftell(f));
+    fflush(debug);
+  }
 
 ////////////////////////////////////////////////////////////////////////////
-	for(unsigned int i=0; i<SPREADSHEET.size(); ++i)
-		if(SPREADSHEET[i].bMultisheet)
-		{
-			fprintf(debug,"		CONVERT SPREADSHEET \"%s\" to EXCEL\n", SPREADSHEET[i].name.c_str());
-			fflush(debug);
-			convertSpreadToExcel(i);
-			i--;
-		}
+  for(unsigned int i=0; i<SPREADSHEET.size(); ++i)
+    if(SPREADSHEET[i].bMultisheet)
+    {
+      fprintf(debug,"   CONVERT SPREADSHEET \"%s\" to EXCEL\n", SPREADSHEET[i].name.c_str());
+      fflush(debug);
+      convertSpreadToExcel(i);
+      i--;
+    }
 ////////////////////////////////////////////////////////////////////////////
 ////////////////////// HEADER SECTION //////////////////////////////////////
 
-	int POS = int(ftell(f)-11);
-	fprintf(debug,"\nHEADER SECTION\n");
-	fprintf(debug,"	nr_spreads = %d\n",SPREADSHEET.size());
-	fprintf(debug,"	[position @ 0x%X]\n",POS);
-	fflush(debug);
+  int POS = int(ftell(f)-11);
+  fprintf(debug,"\nHEADER SECTION\n");
+  fprintf(debug," nr_spreads = %d\n",SPREADSHEET.size());
+  fprintf(debug," [position @ 0x%X]\n",POS);
+  fflush(debug);
 
 //////////////////////// OBJECT INFOS //////////////////////////////////////
-	POS+=0xB;
-	fseek(f,POS,SEEK_SET);
-	while(1) {
-
-		fprintf(debug,"			reading	Header\n");
-		fflush(debug);
-		// HEADER
-		// check header
-		POS=int(ftell(f));
-		int headersize;
-		fread(&headersize,4,1,f);
-		if(IsBigEndian()) SwapBytes(headersize);
-		if(headersize==0)
-			break;
-		char object_type[10];
-		char object_name[25];
-		fseek(f,POS + 0x7,SEEK_SET);
-		fread(&object_name,25,1,f);
-		fseek(f,POS + 0x4A,SEEK_SET);
-		fread(&object_type,10,1,f);
-
-		fseek(f,POS,SEEK_SET);
-
-		if(compareSpreadnames(object_name)!=-1)
-			readSpreadInfo(f, debug);
-		else if(compareMatrixnames(object_name)!=-1)
-			readMatrixInfo(f, debug);
-		else if(compareExcelnames(object_name)!=-1)
-			readExcelInfo(f, debug);
-		else
-			readGraphInfo(f, debug);
-	}
-
-
-
-	fseek(f,1,SEEK_CUR);
-	fprintf(debug,"Some Origin params @ 0x%X:\n", (unsigned int)ftell(f));
-	fread(&c,1,1,f);
-	while(c!=0)
-	{
-		fprintf(debug,"		");
-		while(c!='\n'){
-			fprintf(debug,"%c",c);
-			fread(&c,1,1,f);
-		}
-		double parvalue;
-		fread(&parvalue,8,1,f);
-		if(IsBigEndian()) SwapBytes(parvalue);
-		fprintf(debug,": %g\n", parvalue);
-		fseek(f,1,SEEK_CUR);
-		fread(&c,1,1,f);
-	}
-	fseek(f,1+5,SEEK_CUR);
-	while(1)
-	{
-		//fseek(f,5+0x40+1,SEEK_CUR);
-		int size;
-		fread(&size,4,1,f);
-		if(IsBigEndian()) SwapBytes(size);
-		if(size!=0x40)
-			break;
-
-		double creation_date, modification_date;
-
-		fseek(f,1+0x20,SEEK_CUR);
-		fread(&creation_date,8,1,f);
-		if(IsBigEndian()) SwapBytes(creation_date);
-
-		fread(&modification_date,8,1,f);
-		if(IsBigEndian()) SwapBytes(modification_date);
-
-		fseek(f,0x10-4,SEEK_CUR);
-		unsigned char labellen;
-		fread(&labellen,1,1,f);
-
-		fseek(f,4,SEEK_CUR);
-		fread(&size,4,1,f);
-		if(IsBigEndian()) SwapBytes(size);
-		fseek(f,1,SEEK_CUR);
-		char *stmp = new char[size+1];
-		fread(stmp,size,1,f);
-		if(0==strcmp(stmp,"ResultsLog"))
-		{
-			delete [] stmp;
-			fseek(f,1,SEEK_CUR);
-			fread(&size,4,1,f);
-			if(IsBigEndian()) SwapBytes(size);
-			fseek(f,1,SEEK_CUR);
-			stmp = new char[size+1];
-			fread(stmp,size,1,f);
-			resultsLog=stmp;
-			fprintf(debug,"Results Log: %s\n", resultsLog.c_str());
-			delete [] stmp;
-			break;
-		}
-		else
-		{
-			NOTE.push_back(note(stmp));
-			NOTE.back().objectID=objectIndex;
-			NOTE.back().creation_date=creation_date;
-			NOTE.back().modification_date=modification_date;
-			objectIndex++;
-			delete [] stmp;
-			fseek(f,1,SEEK_CUR);
-			fread(&size,4,1,f);
-			if(IsBigEndian()) SwapBytes(size);
-			fseek(f,1,SEEK_CUR);
-			if(labellen>1)
-			{
-				stmp = new char[labellen];
-				stmp[labellen-1]='\0';
-				fread(stmp,labellen-1,1,f);
-				NOTE.back().label=stmp;
-				delete [] stmp;
-				fseek(f,1,SEEK_CUR);
-			}
-			stmp = new char[size-labellen+1];
-			fread(stmp,size-labellen,1,f);
-			NOTE.back().text=stmp;
-			fprintf(debug,"NOTE %d NAME: %s\n", NOTE.size(), NOTE.back().name.c_str());
-			fprintf(debug,"NOTE %d LABEL: %s\n", NOTE.size(), NOTE.back().label.c_str());
-			fprintf(debug,"NOTE %d TEXT:\n%s\n", NOTE.size(), NOTE.back().text.c_str());
-			delete [] stmp;
-			fseek(f,1,SEEK_CUR);
-		}
-	}
-
-	fseek(f,1+4*5+0x10+1,SEEK_CUR);
-	try
-	{
-		readProjectTree(f, debug);
-	}
-	catch(...)
-	{}
-	fprintf(debug,"Done parsing\n");
-	fclose(debug);
-
-	return 0;
+  POS+=0xB;
+  fseek(f,POS,SEEK_SET);
+  while(1) {
+
+    fprintf(debug,"     reading Header\n");
+    fflush(debug);
+    // HEADER
+    // check header
+    POS=int(ftell(f));
+    int headersize;
+    fread(&headersize,4,1,f);
+    if(IsBigEndian()) SwapBytes(headersize);
+    if(headersize==0)
+      break;
+    char object_type[10];
+    char object_name[25];
+    fseek(f,POS + 0x7,SEEK_SET);
+    fread(&object_name,25,1,f);
+    fseek(f,POS + 0x4A,SEEK_SET);
+    fread(&object_type,10,1,f);
+
+    fseek(f,POS,SEEK_SET);
+
+    if(compareSpreadnames(object_name)!=-1)
+      readSpreadInfo(f, debug);
+    else if(compareMatrixnames(object_name)!=-1)
+      readMatrixInfo(f, debug);
+    else if(compareExcelnames(object_name)!=-1)
+      readExcelInfo(f, debug);
+    else
+      readGraphInfo(f, debug);
+  }
+
+
+
+  fseek(f,1,SEEK_CUR);
+  fprintf(debug,"Some Origin params @ 0x%X:\n", (unsigned int)ftell(f));
+  fread(&c,1,1,f);
+  while(c!=0)
+  {
+    fprintf(debug,"   ");
+    while(c!='\n'){
+      fprintf(debug,"%c",c);
+      fread(&c,1,1,f);
+    }
+    double parvalue;
+    fread(&parvalue,8,1,f);
+    if(IsBigEndian()) SwapBytes(parvalue);
+    fprintf(debug,": %g\n", parvalue);
+    fseek(f,1,SEEK_CUR);
+    fread(&c,1,1,f);
+  }
+  fseek(f,1+5,SEEK_CUR);
+  while(1)
+  {
+    //fseek(f,5+0x40+1,SEEK_CUR);
+    int size;
+    fread(&size,4,1,f);
+    if(IsBigEndian()) SwapBytes(size);
+    if(size!=0x40)
+      break;
+
+    double creation_date, modification_date;
+
+    fseek(f,1+0x20,SEEK_CUR);
+    fread(&creation_date,8,1,f);
+    if(IsBigEndian()) SwapBytes(creation_date);
+
+    fread(&modification_date,8,1,f);
+    if(IsBigEndian()) SwapBytes(modification_date);
+
+    fseek(f,0x10-4,SEEK_CUR);
+    unsigned char labellen;
+    fread(&labellen,1,1,f);
+
+    fseek(f,4,SEEK_CUR);
+    fread(&size,4,1,f);
+    if(IsBigEndian()) SwapBytes(size);
+    fseek(f,1,SEEK_CUR);
+    char *stmp = new char[size+1];
+    fread(stmp,size,1,f);
+    if(0==strcmp(stmp,"ResultsLog"))
+    {
+      delete [] stmp;
+      fseek(f,1,SEEK_CUR);
+      fread(&size,4,1,f);
+      if(IsBigEndian()) SwapBytes(size);
+      fseek(f,1,SEEK_CUR);
+      stmp = new char[size+1];
+      fread(stmp,size,1,f);
+      resultsLog=stmp;
+      fprintf(debug,"Results Log: %s\n", resultsLog.c_str());
+      delete [] stmp;
+      break;
+    }
+    else
+    {
+      NOTE.push_back(note(stmp));
+      NOTE.back().objectID=objectIndex;
+      NOTE.back().creation_date=creation_date;
+      NOTE.back().modification_date=modification_date;
+      objectIndex++;
+      delete [] stmp;
+      fseek(f,1,SEEK_CUR);
+      fread(&size,4,1,f);
+      if(IsBigEndian()) SwapBytes(size);
+      fseek(f,1,SEEK_CUR);
+      if(labellen>1)
+      {
+        stmp = new char[labellen];
+        stmp[labellen-1]='\0';
+        fread(stmp,labellen-1,1,f);
+        NOTE.back().label=stmp;
+        delete [] stmp;
+        fseek(f,1,SEEK_CUR);
+      }
+      stmp = new char[size-labellen+1];
+      fread(stmp,size-labellen,1,f);
+      NOTE.back().text=stmp;
+      fprintf(debug,"NOTE %d NAME: %s\n", NOTE.size(), NOTE.back().name.c_str());
+      fprintf(debug,"NOTE %d LABEL: %s\n", NOTE.size(), NOTE.back().label.c_str());
+      fprintf(debug,"NOTE %d TEXT:\n%s\n", NOTE.size(), NOTE.back().text.c_str());
+      delete [] stmp;
+      fseek(f,1,SEEK_CUR);
+    }
+  }
+
+  fseek(f,1+4*5+0x10+1,SEEK_CUR);
+  try
+  {
+    readProjectTree(f, debug);
+  }
+  catch(...)
+  {}
+  fprintf(debug,"Done parsing\n");
+  fclose(debug);
+
+  return 0;
 }
 
 void OPJFile::readSpreadInfo(FILE *f, FILE *debug)
 {
-	int POS=int(ftell(f));
-
-	int headersize;
-	fread(&headersize,4,1,f);
-	if(IsBigEndian()) SwapBytes(headersize);
-
-	POS+=5;
-
-	fprintf(debug,"			[Spreadsheet SECTION (@ 0x%X)]\n",POS);
-	fflush(debug);
-
-	// check spreadsheet name
-	char name[25];
-	fseek(f,POS + 0x2,SEEK_SET);
-	fread(&name,25,1,f);
-
-	int spread=compareSpreadnames(name);
-	SPREADSHEET[spread].name=name;
-	readWindowProperties(SPREADSHEET[spread], f, debug, POS, headersize);
-	SPREADSHEET[spread].bLoose=false;
-	char c = 0;
-
-	int LAYER = POS;
-	{
-		// LAYER section
-		LAYER += headersize + 0x1 + 0x5/* length of block = 0x12D + '\n'*/ + 0x12D + 0x1;
-		//now structure is next : section_header_size=0x6F(4 bytes) + '\n' + section_header(0x6F bytes) + section_body_1_size(4 bytes) + '\n' + section_body_1 + section_body_2_size(maybe=0)(4 bytes) + '\n' + section_body_2 + '\n'
-		//possible sections: column formulas, __WIPR, __WIOTN, __LayerInfoStorage etc
-		//section name(column name in formula case) starts with 0x46 position
-		while(1)
-		{
-			int sec_size;
-		//section_header_size=0x6F(4 bytes) + '\n'
-			LAYER+=0x5;
-
-		//section_header
-			fseek(f,LAYER+0x46,SEEK_SET);
-			char sec_name[42];
-			sec_name[41]='\0';
-			fread(&sec_name,41,1,f);
-
-			fprintf(debug,"				DEBUG SECTION NAME: %s (@ 0x%X)\n", sec_name, LAYER+0x46);
-			fflush(debug);
-
-		//section_body_1_size
-			LAYER+=0x6F+0x1;
-			fseek(f,LAYER,SEEK_SET);
-			fread(&sec_size,4,1,f);
-			if(IsBigEndian()) SwapBytes(sec_size);
-
-		//section_body_1
-			LAYER+=0x5;
-			fseek(f,LAYER,SEEK_SET);
-			//check if it is a formula
-			int col_index=compareColumnnames(spread,sec_name);
-			if(col_index!=-1)
-			{
-				char *stmp=new char[sec_size+1];
-				stmp[sec_size]='\0';
-				fread(stmp,sec_size,1,f);
-				SPREADSHEET[spread].column[col_index].command=stmp;
-				delete [] stmp;
-			}
-
-		//section_body_2_size
-			LAYER+=sec_size+0x1;
-			fseek(f,LAYER,SEEK_SET);
-			fread(&sec_size,4,1,f);
-			if(IsBigEndian()) SwapBytes(sec_size);
-
-		//section_body_2
-			LAYER+=0x5;
-
-		//close section 00 00 00 00 0A
-			LAYER+=sec_size+(sec_size>0?0x1:0)+0x5;
-
-			if(0==strcmp(sec_name,"__LayerInfoStorage"))
-				break;
-
-		}
-		LAYER+=0x5;
-
-	}
-
-	fflush(debug);
-
-	/////////////// COLUMN Types ///////////////////////////////////////////
-	fprintf(debug,"			Spreadsheet has %d columns\n",SPREADSHEET[spread].column.size());
-
-	while(1)
-	{
-		LAYER+=0x5;
-		fseek(f,LAYER+0x12, SEEK_SET);
-		fread(&name,12,1,f);
-
-		fseek(f,LAYER+0x11, SEEK_SET);
-		fread(&c,1,1,f);
-		short width=0;
-		fseek(f,LAYER+0x4A, SEEK_SET);
-		fread(&width,2,1,f);
-		if(IsBigEndian()) SwapBytes(width);
-		int col_index=compareColumnnames(spread,name);
-		if(col_index!=-1)
-		{
-			ColumnType type;
-			switch(c) {
-				case 3:
-					type = X;
-					break;
-				case 0:
-					type = Y;
-					break;
-				case 5:
-					type = Z;
-					break;
-				case 6:
-					type = XErr;
-					break;
-				case 2:
-					type = YErr;
-					break;
-				case 4:
-					type = Label;
-					break;
-				default:
-					type = NONE;
-					break;
-			}
-			SPREADSHEET[spread].column[col_index].type=type;
-			width/=0xA;
-			if(width==0)
-				width=8;
-			SPREADSHEET[spread].column[col_index].width=width;
-			fseek(f,LAYER+0x1E, SEEK_SET);
-			unsigned char c1,c2;
-			fread(&c1,1,1,f);
-			fread(&c2,1,1,f);
-			switch(c1)
-			{
-			case 0x00: // Numeric	   - Dec1000
-			case 0x09: // Text&Numeric - Dec1000
-			case 0x10: // Numeric	   - Scientific
-			case 0x19: // Text&Numeric - Scientific
-			case 0x20: // Numeric	   - Engeneering
-			case 0x29: // Text&Numeric - Engeneering
-			case 0x30: // Numeric	   - Dec1,000
-			case 0x39: // Text&Numeric - Dec1,000
-				SPREADSHEET[spread].column[col_index].value_type=(c1%0x10==0x9)?6:0;
-				SPREADSHEET[spread].column[col_index].value_type_specification=c1/0x10;
-				if(c2>=0x80)
-				{
-					SPREADSHEET[spread].column[col_index].significant_digits=c2-0x80;
-					SPREADSHEET[spread].column[col_index].numeric_display_type=2;
-				}
-				else if(c2>0)
-				{
-					SPREADSHEET[spread].column[col_index].decimal_places=c2-0x03;
-					SPREADSHEET[spread].column[col_index].numeric_display_type=1;
-				}
-				break;
-			case 0x02: // Time
-				SPREADSHEET[spread].column[col_index].value_type=3;
-				SPREADSHEET[spread].column[col_index].value_type_specification=c2-0x80;
-				break;
-			case 0x03: // Date
-				SPREADSHEET[spread].column[col_index].value_type=2;
-				SPREADSHEET[spread].column[col_index].value_type_specification=c2-0x80;
-				break;
-			case 0x31: // Text
-				SPREADSHEET[spread].column[col_index].value_type=1;
-				break;
-			case 0x4: // Month
-			case 0x34:
-				SPREADSHEET[spread].column[col_index].value_type=4;
-				SPREADSHEET[spread].column[col_index].value_type_specification=c2;
-				break;
-			case 0x5: // Day
-			case 0x35:
-				SPREADSHEET[spread].column[col_index].value_type=5;
-				SPREADSHEET[spread].column[col_index].value_type_specification=c2;
-				break;
-			default: // Text
-				SPREADSHEET[spread].column[col_index].value_type=1;
-				break;
-			}
-			fprintf(debug,"				COLUMN \"%s\" type = %s(%d) (@ 0x%X)\n",
-				SPREADSHEET[spread].column[col_index].name.c_str(),colTypeNames[type],c,LAYER+0x11);
-			fflush(debug);
-		}
-		LAYER+=0x1E7+0x1;
-		fseek(f,LAYER,SEEK_SET);
-		int comm_size=0;
-		fread(&comm_size,4,1,f);
-		if(IsBigEndian()) SwapBytes(comm_size);
-		LAYER+=0x5;
-		if(comm_size>0)
-		{
-			char* comment=new char[comm_size+1];
-			comment[comm_size]='\0';
-			fseek(f,LAYER,SEEK_SET);
-			fread(comment,comm_size,1,f);
-			if(col_index!=-1)
-				SPREADSHEET[spread].column[col_index].comment=comment;
-			LAYER+=comm_size+0x1;
-			delete [] comment;
-		}
-		fseek(f,LAYER,SEEK_SET);
-		int ntmp;
-		fread(&ntmp,4,1,f);
-		if(IsBigEndian()) SwapBytes(ntmp);
-		if(ntmp!=0x1E7)
-			break;
-	}
-	fprintf(debug,"		Done with spreadsheet %d\n",spread);
-	fflush(debug);
-
-	POS = LAYER+0x5*0x6+0x1ED*0x12;
-	fseek(f,POS,SEEK_SET);
+  int POS=int(ftell(f));
+
+  int headersize;
+  fread(&headersize,4,1,f);
+  if(IsBigEndian()) SwapBytes(headersize);
+
+  POS+=5;
+
+  fprintf(debug,"     [Spreadsheet SECTION (@ 0x%X)]\n",POS);
+  fflush(debug);
+
+  // check spreadsheet name
+  char name[25];
+  fseek(f,POS + 0x2,SEEK_SET);
+  fread(&name,25,1,f);
+
+  int spread=compareSpreadnames(name);
+  SPREADSHEET[spread].name=name;
+  readWindowProperties(SPREADSHEET[spread], f, debug, POS, headersize);
+  SPREADSHEET[spread].bLoose=false;
+  char c = 0;
+
+  int LAYER = POS;
+  {
+    // LAYER section
+    LAYER += headersize + 0x1 + 0x5/* length of block = 0x12D + '\n'*/ + 0x12D + 0x1;
+    //now structure is next : section_header_size=0x6F(4 bytes) + '\n' + section_header(0x6F bytes) + section_body_1_size(4 bytes) + '\n' + section_body_1 + section_body_2_size(maybe=0)(4 bytes) + '\n' + section_body_2 + '\n'
+    //possible sections: column formulas, __WIPR, __WIOTN, __LayerInfoStorage etc
+    //section name(column name in formula case) starts with 0x46 position
+    while(1)
+    {
+      int sec_size;
+    //section_header_size=0x6F(4 bytes) + '\n'
+      LAYER+=0x5;
+
+    //section_header
+      fseek(f,LAYER+0x46,SEEK_SET);
+      char sec_name[42];
+      fread(&sec_name,41,1,f);
+      sec_name[41]='\0';
+
+      fprintf(debug,"       DEBUG SECTION NAME: %s (@ 0x%X)\n", sec_name, LAYER+0x46);
+      fflush(debug);
+
+    //section_body_1_size
+      LAYER+=0x6F+0x1;
+      fseek(f,LAYER,SEEK_SET);
+      fread(&sec_size,4,1,f);
+      if(IsBigEndian()) SwapBytes(sec_size);
+
+    //section_body_1
+      LAYER+=0x5;
+      fseek(f,LAYER,SEEK_SET);
+      //check if it is a formula
+      int col_index=compareColumnnames(spread,sec_name);
+      if(col_index!=-1)
+      {
+        char *stmp=new char[sec_size+1];
+        stmp[sec_size]='\0';
+        fread(stmp,sec_size,1,f);
+        SPREADSHEET[spread].column[col_index].command=stmp;
+        delete [] stmp;
+      }
+
+    //section_body_2_size
+      LAYER+=sec_size+0x1;
+      fseek(f,LAYER,SEEK_SET);
+      fread(&sec_size,4,1,f);
+      if(IsBigEndian()) SwapBytes(sec_size);
+
+    //section_body_2
+      LAYER+=0x5;
+
+    //close section 00 00 00 00 0A
+      LAYER+=sec_size+(sec_size>0?0x1:0)+0x5;
+
+      if(0==strcmp(sec_name,"__LayerInfoStorage"))
+        break;
+
+    }
+    LAYER+=0x5;
+
+  }
+
+  fflush(debug);
+
+  /////////////// COLUMN Types ///////////////////////////////////////////
+  fprintf(debug,"     Spreadsheet has %d columns\n",SPREADSHEET[spread].column.size());
+
+  while(1)
+  {
+    LAYER+=0x5;
+    fseek(f,LAYER+0x12, SEEK_SET);
+    fread(&name,12,1,f);
+
+    fseek(f,LAYER+0x11, SEEK_SET);
+    fread(&c,1,1,f);
+    short width=0;
+    fseek(f,LAYER+0x4A, SEEK_SET);
+    fread(&width,2,1,f);
+    if(IsBigEndian()) SwapBytes(width);
+    int col_index=compareColumnnames(spread,name);
+    if(col_index!=-1)
+    {
+      ColumnType type;
+      switch(c) {
+        case 3:
+          type = X;
+          break;
+        case 0:
+          type = Y;
+          break;
+        case 5:
+          type = Z;
+          break;
+        case 6:
+          type = XErr;
+          break;
+        case 2:
+          type = YErr;
+          break;
+        case 4:
+          type = Label;
+          break;
+        default:
+          type = NONE;
+          break;
+      }
+      SPREADSHEET[spread].column[col_index].type=type;
+      width/=0xA;
+      if(width==0)
+        width=8;
+      SPREADSHEET[spread].column[col_index].width=width;
+      fseek(f,LAYER+0x1E, SEEK_SET);
+      unsigned char c1,c2;
+      fread(&c1,1,1,f);
+      fread(&c2,1,1,f);
+      switch(c1)
+      {
+      case 0x00: // Numeric    - Dec1000
+      case 0x09: // Text&Numeric - Dec1000
+      case 0x10: // Numeric    - Scientific
+      case 0x19: // Text&Numeric - Scientific
+      case 0x20: // Numeric    - Engeneering
+      case 0x29: // Text&Numeric - Engeneering
+      case 0x30: // Numeric    - Dec1,000
+      case 0x39: // Text&Numeric - Dec1,000
+        SPREADSHEET[spread].column[col_index].value_type=(c1%0x10==0x9)?6:0;
+        SPREADSHEET[spread].column[col_index].value_type_specification=c1/0x10;
+        if(c2>=0x80)
+        {
+          SPREADSHEET[spread].column[col_index].significant_digits=c2-0x80;
+          SPREADSHEET[spread].column[col_index].numeric_display_type=2;
+        }
+        else if(c2>0)
+        {
+          SPREADSHEET[spread].column[col_index].decimal_places=c2-0x03;
+          SPREADSHEET[spread].column[col_index].numeric_display_type=1;
+        }
+        break;
+      case 0x02: // Time
+        SPREADSHEET[spread].column[col_index].value_type=3;
+        SPREADSHEET[spread].column[col_index].value_type_specification=c2-0x80;
+        break;
+      case 0x03: // Date
+        SPREADSHEET[spread].column[col_index].value_type=2;
+        SPREADSHEET[spread].column[col_index].value_type_specification=c2-0x80;
+        break;
+      case 0x31: // Text
+        SPREADSHEET[spread].column[col_index].value_type=1;
+        break;
+      case 0x4: // Month
+      case 0x34:
+        SPREADSHEET[spread].column[col_index].value_type=4;
+        SPREADSHEET[spread].column[col_index].value_type_specification=c2;
+        break;
+      case 0x5: // Day
+      case 0x35:
+        SPREADSHEET[spread].column[col_index].value_type=5;
+        SPREADSHEET[spread].column[col_index].value_type_specification=c2;
+        break;
+      default: // Text
+        SPREADSHEET[spread].column[col_index].value_type=1;
+        break;
+      }
+      fprintf(debug,"       COLUMN \"%s\" type = %s(%d) (@ 0x%X)\n",
+        SPREADSHEET[spread].column[col_index].name.c_str(),colTypeNames[type],c,LAYER+0x11);
+      fflush(debug);
+    }
+    LAYER+=0x1E7+0x1;
+    fseek(f,LAYER,SEEK_SET);
+    int comm_size=0;
+    fread(&comm_size,4,1,f);
+    if(IsBigEndian()) SwapBytes(comm_size);
+    LAYER+=0x5;
+    if(comm_size>0)
+    {
+      char* comment=new char[comm_size+1];
+      comment[comm_size]='\0';
+      fseek(f,LAYER,SEEK_SET);
+      fread(comment,comm_size,1,f);
+      if(col_index!=-1)
+        SPREADSHEET[spread].column[col_index].comment=comment;
+      LAYER+=comm_size+0x1;
+      delete [] comment;
+    }
+    fseek(f,LAYER,SEEK_SET);
+    int ntmp;
+    fread(&ntmp,4,1,f);
+    if(IsBigEndian()) SwapBytes(ntmp);
+    if(ntmp!=0x1E7)
+      break;
+  }
+  fprintf(debug,"   Done with spreadsheet %d\n",spread);
+  fflush(debug);
+
+  POS = LAYER+0x5*0x6+0x1ED*0x12;
+  fseek(f,POS,SEEK_SET);
 }
 
 void OPJFile::readExcelInfo(FILE *f, FILE *debug)
 {
-	int POS=int(ftell(f));
-
-	int headersize;
-	fread(&headersize,4,1,f);
-	if(IsBigEndian()) SwapBytes(headersize);
-
-	POS+=5;
-
-	fprintf(debug,"			[EXCEL SECTION (@ 0x%X)]\n",POS);
-	fflush(debug);
-
-	// check spreadsheet name
-	char name[25];
-	fseek(f,POS + 0x2,SEEK_SET);
-	fread(&name,25,1,f);
-
-	int iexcel=compareExcelnames(name);
-	EXCEL[iexcel].name=name;
-	readWindowProperties(EXCEL[iexcel], f, debug, POS, headersize);
-	EXCEL[iexcel].bLoose=false;
-	char c = 0;
-
-	int LAYER = POS;
-	LAYER += headersize + 0x1;
-	int sec_size;
-	int isheet=0;
-	while(1)// multisheet loop
-	{
-		// LAYER section
-		LAYER += 0x5/* length of block = 0x12D + '\n'*/ + 0x12D + 0x1;
-		//now structure is next : section_header_size=0x6F(4 bytes) + '\n' + section_header(0x6F bytes) + section_body_1_size(4 bytes) + '\n' + section_body_1 + section_body_2_size(maybe=0)(4 bytes) + '\n' + section_body_2 + '\n'
-		//possible sections: column formulas, __WIPR, __WIOTN, __LayerInfoStorage etc
-		//section name(column name in formula case) starts with 0x46 position
-		while(1)
-		{
-		//section_header_size=0x6F(4 bytes) + '\n'
-			LAYER+=0x5;
-
-		//section_header
-			fseek(f,LAYER+0x46,SEEK_SET);
-			char sec_name[42];
-			sec_name[41]='\0';
-			fread(&sec_name,41,1,f);
-
-			fprintf(debug,"				DEBUG SECTION NAME: %s (@ 0x%X)\n", sec_name, LAYER+0x46);
-			fflush(debug);
-
-		//section_body_1_size
-			LAYER+=0x6F+0x1;
-			fseek(f,LAYER,SEEK_SET);
-			fread(&sec_size,4,1,f);
-			if(IsBigEndian()) SwapBytes(sec_size);
-
-		//section_body_1
-			LAYER+=0x5;
-			fseek(f,LAYER,SEEK_SET);
-			//check if it is a formula
-			int col_index=compareExcelColumnnames(iexcel, isheet, sec_name);
-			if(col_index!=-1)
-			{
-				char *stmp=new char[sec_size+1];
-				stmp[sec_size]='\0';
-				fread(stmp,sec_size,1,f);
-				EXCEL[iexcel].sheet[isheet].column[col_index].command=stmp;
-				delete [] stmp;
-			}
-
-		//section_body_2_size
-			LAYER+=sec_size+0x1;
-			fseek(f,LAYER,SEEK_SET);
-			fread(&sec_size,4,1,f);
-			if(IsBigEndian()) SwapBytes(sec_size);
-
-		//section_body_2
-			LAYER+=0x5;
-
-		//close section 00 00 00 00 0A
-			LAYER+=sec_size+(sec_size>0?0x1:0)+0x5;
-
-			if(0==strcmp(sec_name,"__LayerInfoStorage"))
-				break;
-
-		}
-		LAYER+=0x5;
-
-		fflush(debug);
-
-		/////////////// COLUMN Types ///////////////////////////////////////////
-		fprintf(debug,"			Excel sheet %d has %d columns\n",isheet,EXCEL[iexcel].sheet[isheet].column.size());
-
-		while(1)
-		{
-			LAYER+=0x5;
-			fseek(f,LAYER+0x12, SEEK_SET);
-			fread(&name,12,1,f);
-
-			fseek(f,LAYER+0x11, SEEK_SET);
-			fread(&c,1,1,f);
-			short width=0;
-			fseek(f,LAYER+0x4A, SEEK_SET);
-			fread(&width,2,1,f);
-			if(IsBigEndian()) SwapBytes(width);
-			//char col_name[30];
-			//sprintf(col_name, "%s@%d", name, isheet);
-			int col_index=compareExcelColumnnames(iexcel, isheet, name);
-			if(col_index!=-1)
-			{
-				ColumnType type;
-				switch(c) {
-					case 3:
-						type = X;
-						break;
-					case 0:
-						type = Y;
-						break;
-					case 5:
-						type = Z;
-						break;
-					case 6:
-						type = XErr;
-						break;
-					case 2:
-						type = YErr;
-						break;
-					case 4:
-						type = Label;
-						break;
-					default:
-						type = NONE;
-						break;
-				}
-				EXCEL[iexcel].sheet[isheet].column[col_index].type=type;
-				width/=0xA;
-				if(width==0)
-					width=8;
-				EXCEL[iexcel].sheet[isheet].column[col_index].width=width;
-				fseek(f,LAYER+0x1E, SEEK_SET);
-				unsigned char c1,c2;
-				fread(&c1,1,1,f);
-				fread(&c2,1,1,f);
-				switch(c1)
-				{
-				case 0x00: // Numeric	   - Dec1000
-				case 0x09: // Text&Numeric - Dec1000
-				case 0x10: // Numeric	   - Scientific
-				case 0x19: // Text&Numeric - Scientific
-				case 0x20: // Numeric	   - Engeneering
-				case 0x29: // Text&Numeric - Engeneering
-				case 0x30: // Numeric	   - Dec1,000
-				case 0x39: // Text&Numeric - Dec1,000
-					EXCEL[iexcel].sheet[isheet].column[col_index].value_type=(c1%0x10==0x9)?6:0;
-					EXCEL[iexcel].sheet[isheet].column[col_index].value_type_specification=c1/0x10;
-					if(c2>=0x80)
-					{
-						EXCEL[iexcel].sheet[isheet].column[col_index].significant_digits=c2-0x80;
-						EXCEL[iexcel].sheet[isheet].column[col_index].numeric_display_type=2;
-					}
-					else if(c2>0)
-					{
-						EXCEL[iexcel].sheet[isheet].column[col_index].decimal_places=c2-0x03;
-						EXCEL[iexcel].sheet[isheet].column[col_index].numeric_display_type=1;
-					}
-					break;
-				case 0x02: // Time
-					EXCEL[iexcel].sheet[isheet].column[col_index].value_type=3;
-					EXCEL[iexcel].sheet[isheet].column[col_index].value_type_specification=c2-0x80;
-					break;
-				case 0x03: // Date
-					EXCEL[iexcel].sheet[isheet].column[col_index].value_type=2;
-					EXCEL[iexcel].sheet[isheet].column[col_index].value_type_specification=c2-0x80;
-					break;
-				case 0x31: // Text
-					EXCEL[iexcel].sheet[isheet].column[col_index].value_type=1;
-					break;
-				case 0x4: // Month
-				case 0x34:
-					EXCEL[iexcel].sheet[isheet].column[col_index].value_type=4;
-					EXCEL[iexcel].sheet[isheet].column[col_index].value_type_specification=c2;
-					break;
-				case 0x5: // Day
-				case 0x35:
-					EXCEL[iexcel].sheet[isheet].column[col_index].value_type=5;
-					EXCEL[iexcel].sheet[isheet].column[col_index].value_type_specification=c2;
-					break;
-				default: // Text
-					EXCEL[iexcel].sheet[isheet].column[col_index].value_type=1;
-					break;
-				}
-				fprintf(debug,"				COLUMN \"%s\" type = %s(%d) (@ 0x%X)\n",
-					EXCEL[iexcel].sheet[isheet].column[col_index].name.c_str(),type,c,LAYER+0x11);
-				fflush(debug);
-			}
-			LAYER+=0x1E7+0x1;
-			fseek(f,LAYER,SEEK_SET);
-			int comm_size=0;
-			fread(&comm_size,4,1,f);
-			if(IsBigEndian()) SwapBytes(comm_size);
-			LAYER+=0x5;
-			if(comm_size>0)
-			{
-				char* comment=new char[comm_size+1];
-				comment[comm_size]='\0';
-				fseek(f,LAYER,SEEK_SET);
-				fread(comment,comm_size,1,f);
-				if(col_index!=-1)
-					EXCEL[iexcel].sheet[isheet].column[col_index].comment=comment;
-				LAYER+=comm_size+0x1;
-				delete [] comment;
-			}
-			fseek(f,LAYER,SEEK_SET);
-			int ntmp;
-			fread(&ntmp,4,1,f);
-			if(IsBigEndian()) SwapBytes(ntmp);
-			if(ntmp!=0x1E7)
-				break;
-		}
-		fprintf(debug,"		Done with excel %d\n", iexcel);
-		fflush(debug);
-
-		//POS = LAYER+0x5*0x6+0x1ED*0x12;
-		LAYER+=0x5*0x5+0x1ED*0x12;
-		fseek(f,LAYER,SEEK_SET);
-		fread(&sec_size,4,1,f);
-		if(IsBigEndian()) SwapBytes(sec_size);
-		if(sec_size==0)
-			break;
-		isheet++;
-	}
-	POS = LAYER+0x5;
-
-	fseek(f,POS,SEEK_SET);
+  int POS=int(ftell(f));
+
+  int headersize;
+  fread(&headersize,4,1,f);
+  if(IsBigEndian()) SwapBytes(headersize);
+
+  POS+=5;
+
+  fprintf(debug,"     [EXCEL SECTION (@ 0x%X)]\n",POS);
+  fflush(debug);
+
+  // check spreadsheet name
+  char name[25];
+  fseek(f,POS + 0x2,SEEK_SET);
+  fread(&name,25,1,f);
+
+  int iexcel=compareExcelnames(name);
+  EXCEL[iexcel].name=name;
+  readWindowProperties(EXCEL[iexcel], f, debug, POS, headersize);
+  EXCEL[iexcel].bLoose=false;
+  char c = 0;
+
+  int LAYER = POS;
+  LAYER += headersize + 0x1;
+  int sec_size;
+  int isheet=0;
+  while(1)// multisheet loop
+  {
+    // LAYER section
+    LAYER += 0x5/* length of block = 0x12D + '\n'*/ + 0x12D + 0x1;
+    //now structure is next : section_header_size=0x6F(4 bytes) + '\n' + section_header(0x6F bytes) + section_body_1_size(4 bytes) + '\n' + section_body_1 + section_body_2_size(maybe=0)(4 bytes) + '\n' + section_body_2 + '\n'
+    //possible sections: column formulas, __WIPR, __WIOTN, __LayerInfoStorage etc
+    //section name(column name in formula case) starts with 0x46 position
+    while(1)
+    {
+    //section_header_size=0x6F(4 bytes) + '\n'
+      LAYER+=0x5;
+
+    //section_header
+      fseek(f,LAYER+0x46,SEEK_SET);
+      char sec_name[42];
+      fread(&sec_name,41,1,f);
+      sec_name[41]='\0';
+
+      fprintf(debug,"       DEBUG SECTION NAME: %s (@ 0x%X)\n", sec_name, LAYER+0x46);
+      fflush(debug);
+
+    //section_body_1_size
+      LAYER+=0x6F+0x1;
+      fseek(f,LAYER,SEEK_SET);
+      fread(&sec_size,4,1,f);
+      if(IsBigEndian()) SwapBytes(sec_size);
+
+    //section_body_1
+      LAYER+=0x5;
+      fseek(f,LAYER,SEEK_SET);
+      //check if it is a formula
+      int col_index=compareExcelColumnnames(iexcel, isheet, sec_name);
+      if(col_index!=-1)
+      {
+        char *stmp=new char[sec_size+1];
+        stmp[sec_size]='\0';
+        fread(stmp,sec_size,1,f);
+        EXCEL[iexcel].sheet[isheet].column[col_index].command=stmp;
+        delete [] stmp;
+      }
+
+    //section_body_2_size
+      LAYER+=sec_size+0x1;
+      fseek(f,LAYER,SEEK_SET);
+      fread(&sec_size,4,1,f);
+      if(IsBigEndian()) SwapBytes(sec_size);
+
+    //section_body_2
+      LAYER+=0x5;
+
+    //close section 00 00 00 00 0A
+      LAYER+=sec_size+(sec_size>0?0x1:0)+0x5;
+
+      if(0==strcmp(sec_name,"__LayerInfoStorage"))
+        break;
+
+    }
+    LAYER+=0x5;
+
+    fflush(debug);
+
+    /////////////// COLUMN Types ///////////////////////////////////////////
+    fprintf(debug,"     Excel sheet %d has %d columns\n",isheet,EXCEL[iexcel].sheet[isheet].column.size());
+
+    while(1)
+    {
+      LAYER+=0x5;
+      fseek(f,LAYER+0x12, SEEK_SET);
+      fread(&name,12,1,f);
+
+      fseek(f,LAYER+0x11, SEEK_SET);
+      fread(&c,1,1,f);
+      short width=0;
+      fseek(f,LAYER+0x4A, SEEK_SET);
+      fread(&width,2,1,f);
+      if(IsBigEndian()) SwapBytes(width);
+      //char col_name[30];
+      //sprintf(col_name, "%s@%d", name, isheet);
+      int col_index=compareExcelColumnnames(iexcel, isheet, name);
+      if(col_index!=-1)
+      {
+        ColumnType type;
+        switch(c) {
+          case 3:
+            type = X;
+            break;
+          case 0:
+            type = Y;
+            break;
+          case 5:
+            type = Z;
+            break;
+          case 6:
+            type = XErr;
+            break;
+          case 2:
+            type = YErr;
+            break;
+          case 4:
+            type = Label;
+            break;
+          default:
+            type = NONE;
+            break;
+        }
+        EXCEL[iexcel].sheet[isheet].column[col_index].type=type;
+        width/=0xA;
+        if(width==0)
+          width=8;
+        EXCEL[iexcel].sheet[isheet].column[col_index].width=width;
+        fseek(f,LAYER+0x1E, SEEK_SET);
+        unsigned char c1,c2;
+        fread(&c1,1,1,f);
+        fread(&c2,1,1,f);
+        switch(c1)
+        {
+        case 0x00: // Numeric    - Dec1000
+        case 0x09: // Text&Numeric - Dec1000
+        case 0x10: // Numeric    - Scientific
+        case 0x19: // Text&Numeric - Scientific
+        case 0x20: // Numeric    - Engeneering
+        case 0x29: // Text&Numeric - Engeneering
+        case 0x30: // Numeric    - Dec1,000
+        case 0x39: // Text&Numeric - Dec1,000
+          EXCEL[iexcel].sheet[isheet].column[col_index].value_type=(c1%0x10==0x9)?6:0;
+          EXCEL[iexcel].sheet[isheet].column[col_index].value_type_specification=c1/0x10;
+          if(c2>=0x80)
+          {
+            EXCEL[iexcel].sheet[isheet].column[col_index].significant_digits=c2-0x80;
+            EXCEL[iexcel].sheet[isheet].column[col_index].numeric_display_type=2;
+          }
+          else if(c2>0)
+          {
+            EXCEL[iexcel].sheet[isheet].column[col_index].decimal_places=c2-0x03;
+            EXCEL[iexcel].sheet[isheet].column[col_index].numeric_display_type=1;
+          }
+          break;
+        case 0x02: // Time
+          EXCEL[iexcel].sheet[isheet].column[col_index].value_type=3;
+          EXCEL[iexcel].sheet[isheet].column[col_index].value_type_specification=c2-0x80;
+          break;
+        case 0x03: // Date
+          EXCEL[iexcel].sheet[isheet].column[col_index].value_type=2;
+          EXCEL[iexcel].sheet[isheet].column[col_index].value_type_specification=c2-0x80;
+          break;
+        case 0x31: // Text
+          EXCEL[iexcel].sheet[isheet].column[col_index].value_type=1;
+          break;
+        case 0x4: // Month
+        case 0x34:
+          EXCEL[iexcel].sheet[isheet].column[col_index].value_type=4;
+          EXCEL[iexcel].sheet[isheet].column[col_index].value_type_specification=c2;
+          break;
+        case 0x5: // Day
+        case 0x35:
+          EXCEL[iexcel].sheet[isheet].column[col_index].value_type=5;
+          EXCEL[iexcel].sheet[isheet].column[col_index].value_type_specification=c2;
+          break;
+        default: // Text
+          EXCEL[iexcel].sheet[isheet].column[col_index].value_type=1;
+          break;
+        }
+        fprintf(debug,"       COLUMN \"%s\" type = %s(%d) (@ 0x%X)\n",
+          EXCEL[iexcel].sheet[isheet].column[col_index].name.c_str(),type,c,LAYER+0x11);
+        fflush(debug);
+      }
+      LAYER+=0x1E7+0x1;
+      fseek(f,LAYER,SEEK_SET);
+      int comm_size=0;
+      fread(&comm_size,4,1,f);
+      if(IsBigEndian()) SwapBytes(comm_size);
+      LAYER+=0x5;
+      if(comm_size>0)
+      {
+        char* comment=new char[comm_size+1];
+        comment[comm_size]='\0';
+        fseek(f,LAYER,SEEK_SET);
+        fread(comment,comm_size,1,f);
+        if(col_index!=-1)
+          EXCEL[iexcel].sheet[isheet].column[col_index].comment=comment;
+        LAYER+=comm_size+0x1;
+        delete [] comment;
+      }
+      fseek(f,LAYER,SEEK_SET);
+      int ntmp;
+      fread(&ntmp,4,1,f);
+      if(IsBigEndian()) SwapBytes(ntmp);
+      if(ntmp!=0x1E7)
+        break;
+    }
+    fprintf(debug,"   Done with excel %d\n", iexcel);
+    fflush(debug);
+
+    //POS = LAYER+0x5*0x6+0x1ED*0x12;
+    LAYER+=0x5*0x5+0x1ED*0x12;
+    fseek(f,LAYER,SEEK_SET);
+    fread(&sec_size,4,1,f);
+    if(IsBigEndian()) SwapBytes(sec_size);
+    if(sec_size==0)
+      break;
+    isheet++;
+  }
+  POS = LAYER+0x5;
+
+  fseek(f,POS,SEEK_SET);
 }
 
 void OPJFile::readMatrixInfo(FILE *f, FILE *debug)
 {
-	int POS=int(ftell(f));
-
-	int headersize;
-	fread(&headersize,4,1,f);
-	if(IsBigEndian()) SwapBytes(headersize);
-	POS+=5;
-
-	fprintf(debug,"			[Matrix SECTION (@ 0x%X)]\n",POS);
-	fflush(debug);
-
-	// check spreadsheet name
-	char name[25];
-	fseek(f,POS + 0x2,SEEK_SET);
-	fread(&name,25,1,f);
-
-	int idx=compareMatrixnames(name);
-	MATRIX[idx].name=name;
-	readWindowProperties(MATRIX[idx], f, debug, POS, headersize);
-
-	unsigned char h = 0;
-	fseek(f,POS+0x87,SEEK_SET);
-	fread(&h,1,1,f);
-	switch(h)
-	{
-	case 1:
-		MATRIX[idx].view = matrix::ImageView;
-		break;
-	case 2:
-		MATRIX[idx].header = matrix::XY;
-		break;
-	}
-
-	int LAYER = POS;
-	LAYER += headersize + 0x1;
-	int sec_size;
-	// LAYER section
-	LAYER +=0x5;
-	fseek(f,LAYER+0x2B,SEEK_SET);
-	short w=0;
-	fread(&w,2,1,f);
-	if(IsBigEndian()) SwapBytes(w);
-	MATRIX[idx].nr_cols=w;
-	fseek(f,LAYER+0x52,SEEK_SET);
-	fread(&w,2,1,f);
-	if(IsBigEndian()) SwapBytes(w);
-	MATRIX[idx].nr_rows=w;
-
-	LAYER +=0x12D + 0x1;
-	//now structure is next : section_header_size=0x6F(4 bytes) + '\n' + section_header(0x6F bytes) + section_body_1_size(4 bytes) + '\n' + section_body_1 + section_body_2_size(maybe=0)(4 bytes) + '\n' + section_body_2 + '\n'
-	//possible sections: column formulas, __WIPR, __WIOTN, __LayerInfoStorage
-	//section name(column name in formula case) starts with 0x46 position
-	while(1)
-	{
-	//section_header_size=0x6F(4 bytes) + '\n'
-		LAYER+=0x5;
-
-	//section_header
-		fseek(f,LAYER+0x46,SEEK_SET);
-		char sec_name[42];
-		sec_name[41]='\0';
-		fread(&sec_name,41,1,f);
-
-	//section_body_1_size
-		LAYER+=0x6F+0x1;
-		fseek(f,LAYER,SEEK_SET);
-		fread(&sec_size,4,1,f);
-		if(IsBigEndian()) SwapBytes(sec_size);
-
-	//section_body_1
-		LAYER+=0x5;
-		//check if it is a formula
-		if(0==strcmp(sec_name,"MV"))
-		{
-			fseek(f,LAYER,SEEK_SET);
-			char *stmp=new char[sec_size+1];
-			stmp[sec_size]='\0';
-			fread(stmp,sec_size,1,f);
-			MATRIX[idx].command=stmp;
-			delete [] stmp;
-		}
-
-	//section_body_2_size
-		LAYER+=sec_size+0x1;
-		fseek(f,LAYER,SEEK_SET);
-		fread(&sec_size,4,1,f);
-		if(IsBigEndian()) SwapBytes(sec_size);
-
-	//section_body_2
-		LAYER+=0x5;
-
-	//close section 00 00 00 00 0A
-		LAYER+=sec_size+(sec_size>0?0x1:0)+0x5;
-
-		if(0==strcmp(sec_name,"__LayerInfoStorage"))
-			break;
-
-	}
-	LAYER+=0x5;
-
-	while(1)
-	{
-		LAYER+=0x5;
-
-		short width=0;
-		fseek(f,LAYER+0x2B, SEEK_SET);
-		fread(&width,2,1,f);
-		if(IsBigEndian()) SwapBytes(width);
-		width=short((width-55)/0xA);
-		if(width==0)
-			width=8;
-		MATRIX[idx].width=width;
-		fseek(f,LAYER+0x1E, SEEK_SET);
-		unsigned char c1,c2;
-		fread(&c1,1,1,f);
-		fread(&c2,1,1,f);
-
-		MATRIX[idx].value_type_specification=c1/0x10;
-		if(c2>=0x80)
-		{
-			MATRIX[idx].significant_digits=c2-0x80;
-			MATRIX[idx].numeric_display_type=2;
-		}
-		else if(c2>0)
-		{
-			MATRIX[idx].decimal_places=c2-0x03;
-			MATRIX[idx].numeric_display_type=1;
-		}
-
-		LAYER+=0x1E7+0x1;
-		fseek(f,LAYER,SEEK_SET);
-		int comm_size=0;
-		fread(&comm_size,4,1,f);
-		if(IsBigEndian()) SwapBytes(comm_size);
-		LAYER+=0x5;
-		if(comm_size>0)
-		{
-			LAYER+=comm_size+0x1;
-		}
-		fseek(f,LAYER,SEEK_SET);
-		int ntmp;
-		fread(&ntmp,4,1,f);
-		if(IsBigEndian()) SwapBytes(ntmp);
-		if(ntmp!=0x1E7)
-			break;
-	}
-
-	LAYER+=0x5*0x5+0x1ED*0x12;
-	POS = LAYER+0x5;
-
-	fseek(f,POS,SEEK_SET);
+  int POS=int(ftell(f));
+
+  int headersize;
+  fread(&headersize,4,1,f);
+  if(IsBigEndian()) SwapBytes(headersize);
+  POS+=5;
+
+  fprintf(debug,"     [Matrix SECTION (@ 0x%X)]\n",POS);
+  fflush(debug);
+
+  // check spreadsheet name
+  char name[25];
+  fseek(f,POS + 0x2,SEEK_SET);
+  fread(&name,25,1,f);
+
+  int idx=compareMatrixnames(name);
+  MATRIX[idx].name=name;
+  readWindowProperties(MATRIX[idx], f, debug, POS, headersize);
+
+  unsigned char h = 0;
+  fseek(f,POS+0x87,SEEK_SET);
+  fread(&h,1,1,f);
+  switch(h)
+  {
+  case 1:
+    MATRIX[idx].view = matrix::ImageView;
+    break;
+  case 2:
+    MATRIX[idx].header = matrix::XY;
+    break;
+  }
+
+  int LAYER = POS;
+  LAYER += headersize + 0x1;
+  int sec_size;
+  // LAYER section
+  LAYER +=0x5;
+  fseek(f,LAYER+0x2B,SEEK_SET);
+  short w=0;
+  fread(&w,2,1,f);
+  if(IsBigEndian()) SwapBytes(w);
+  MATRIX[idx].nr_cols=w;
+  fseek(f,LAYER+0x52,SEEK_SET);
+  fread(&w,2,1,f);
+  if(IsBigEndian()) SwapBytes(w);
+  MATRIX[idx].nr_rows=w;
+
+  LAYER +=0x12D + 0x1;
+  //now structure is next : section_header_size=0x6F(4 bytes) + '\n' + section_header(0x6F bytes) + section_body_1_size(4 bytes) + '\n' + section_body_1 + section_body_2_size(maybe=0)(4 bytes) + '\n' + section_body_2 + '\n'
+  //possible sections: column formulas, __WIPR, __WIOTN, __LayerInfoStorage
+  //section name(column name in formula case) starts with 0x46 position
+  while(1)
+  {
+  //section_header_size=0x6F(4 bytes) + '\n'
+    LAYER+=0x5;
+
+  //section_header
+    fseek(f,LAYER+0x46,SEEK_SET);
+    char sec_name[42];
+    sec_name[41]='\0';
+    fread(&sec_name,41,1,f);
+
+  //section_body_1_size
+    LAYER+=0x6F+0x1;
+    fseek(f,LAYER,SEEK_SET);
+    fread(&sec_size,4,1,f);
+    if(IsBigEndian()) SwapBytes(sec_size);
+
+  //section_body_1
+    LAYER+=0x5;
+    //check if it is a formula
+    if(0==strcmp(sec_name,"MV"))
+    {
+      fseek(f,LAYER,SEEK_SET);
+      char *stmp=new char[sec_size+1];
+      stmp[sec_size]='\0';
+      fread(stmp,sec_size,1,f);
+      MATRIX[idx].command=stmp;
+      delete [] stmp;
+    }
+
+  //section_body_2_size
+    LAYER+=sec_size+0x1;
+    fseek(f,LAYER,SEEK_SET);
+    fread(&sec_size,4,1,f);
+    if(IsBigEndian()) SwapBytes(sec_size);
+
+  //section_body_2
+    LAYER+=0x5;
+
+  //close section 00 00 00 00 0A
+    LAYER+=sec_size+(sec_size>0?0x1:0)+0x5;
+
+    if(0==strcmp(sec_name,"__LayerInfoStorage"))
+      break;
+
+  }
+  LAYER+=0x5;
+
+  while(1)
+  {
+    LAYER+=0x5;
+
+    short width=0;
+    fseek(f,LAYER+0x2B, SEEK_SET);
+    fread(&width,2,1,f);
+    if(IsBigEndian()) SwapBytes(width);
+    width=short((width-55)/0xA);
+    if(width==0)
+      width=8;
+    MATRIX[idx].width=width;
+    fseek(f,LAYER+0x1E, SEEK_SET);
+    unsigned char c1,c2;
+    fread(&c1,1,1,f);
+    fread(&c2,1,1,f);
+
+    MATRIX[idx].value_type_specification=c1/0x10;
+    if(c2>=0x80)
+    {
+      MATRIX[idx].significant_digits=c2-0x80;
+      MATRIX[idx].numeric_display_type=2;
+    }
+    else if(c2>0)
+    {
+      MATRIX[idx].decimal_places=c2-0x03;
+      MATRIX[idx].numeric_display_type=1;
+    }
+
+    LAYER+=0x1E7+0x1;
+    fseek(f,LAYER,SEEK_SET);
+    int comm_size=0;
+    fread(&comm_size,4,1,f);
+    if(IsBigEndian()) SwapBytes(comm_size);
+    LAYER+=0x5;
+    if(comm_size>0)
+    {
+      LAYER+=comm_size+0x1;
+    }
+    fseek(f,LAYER,SEEK_SET);
+    int ntmp;
+    fread(&ntmp,4,1,f);
+    if(IsBigEndian()) SwapBytes(ntmp);
+    if(ntmp!=0x1E7)
+      break;
+  }
+
+  LAYER+=0x5*0x5+0x1ED*0x12;
+  POS = LAYER+0x5;
+
+  fseek(f,POS,SEEK_SET);
 }
 
 
 void OPJFile::readGraphInfo(FILE *f, FILE *debug)
 {
-	int POS=int(ftell(f));
+  int POS=int(ftell(f));
 
-	int headersize;
-	fread(&headersize,4,1,f);
-	if(IsBigEndian()) SwapBytes(headersize);
-	POS+=5;
+  int headersize;
+  fread(&headersize,4,1,f);
+  if(IsBigEndian()) SwapBytes(headersize);
+  POS+=5;
 
-	fprintf(debug,"			[Graph SECTION (@ 0x%X)]\n",POS);
-	fflush(debug);
+  fprintf(debug,"     [Graph SECTION (@ 0x%X)]\n",POS);
+  fflush(debug);
 
-	char name[25];
-	fseek(f,POS + 0x2,SEEK_SET);
-	fread(&name,25,1,f);
+  char name[25];
+  fseek(f,POS + 0x2,SEEK_SET);
+  fread(&name,25,1,f);
 
-	GRAPH.push_back(graph(name));
-	readWindowProperties(GRAPH.back(), f, debug, POS, headersize);
+  GRAPH.push_back(graph(name));
+  readWindowProperties(GRAPH.back(), f, debug, POS, headersize);
         //char c = 0;
 
-	unsigned short graph_width;
-	fseek(f,POS + 0x23,SEEK_SET);
-	fread(&graph_width,2,1,f);
-	if(IsBigEndian()) SwapBytes(graph_width);
-	GRAPH.back().width = graph_width;
-
-	unsigned short graph_height;
-	fread(&graph_height,2,1,f);
-	if(IsBigEndian()) SwapBytes(graph_height);
-	GRAPH.back().height = graph_height;
-
-	int LAYER = POS;
-	LAYER += headersize + 0x1;
-	int sec_size;
-	while(1)// multilayer loop
-	{
-		GRAPH.back().layer.push_back(graphLayer());
-		// LAYER section
-		LAYER +=0x5;
-		double range=0.0;
-		unsigned char m=0;
-		fseek(f, LAYER+0xF, SEEK_SET);
-		fread(&range,8,1,f);
-		if(IsBigEndian()) SwapBytes(range);
-		GRAPH.back().layer.back().xAxis.min=range;
-		fread(&range,8,1,f);
-		if(IsBigEndian()) SwapBytes(range);
-		GRAPH.back().layer.back().xAxis.max=range;
-		fread(&range,8,1,f);
-		if(IsBigEndian()) SwapBytes(range);
-		GRAPH.back().layer.back().xAxis.step=range;
-		fseek(f, LAYER+0x2B, SEEK_SET);
-		fread(&m,1,1,f);
-		GRAPH.back().layer.back().xAxis.majorTicks=m;
-		fseek(f, LAYER+0x37, SEEK_SET);
-		fread(&m,1,1,f);
-		GRAPH.back().layer.back().xAxis.minorTicks=m;
-		fread(&m,1,1,f);
-		GRAPH.back().layer.back().xAxis.scale=m;
-
-		fseek(f, LAYER+0x3A, SEEK_SET);
-		fread(&range,8,1,f);
-		if(IsBigEndian()) SwapBytes(range);
-		GRAPH.back().layer.back().yAxis.min=range;
-		fread(&range,8,1,f);
-		if(IsBigEndian()) SwapBytes(range);
-		GRAPH.back().layer.back().yAxis.max=range;
-		fread(&range,8,1,f);
-		if(IsBigEndian()) SwapBytes(range);
-		GRAPH.back().layer.back().yAxis.step=range;
-		fseek(f, LAYER+0x56, SEEK_SET);
-		fread(&m,1,1,f);
-		GRAPH.back().layer.back().yAxis.majorTicks=m;
-		fseek(f, LAYER+0x62, SEEK_SET);
-		fread(&m,1,1,f);
-		GRAPH.back().layer.back().yAxis.minorTicks=m;
-		fread(&m,1,1,f);
-		GRAPH.back().layer.back().yAxis.scale=m;
-
-		rect r;
-		fseek(f, LAYER+0x71, SEEK_SET);
-		fread(&r,sizeof(rect),1,f);
-		if(IsBigEndian()) SwapBytes(r);
-		GRAPH.back().layer.back().clientRect=r;
-
-		LAYER += 0x12D + 0x1;
-		//now structure is next : section_header_size=0x6F(4 bytes) + '\n' + section_header(0x6F bytes) + section_body_1_size(4 bytes) + '\n' + section_body_1 + section_body_2_size(maybe=0)(4 bytes) + '\n' + section_body_2 + '\n'
-		//possible sections: axes, legend, __BC02, _202, _231, _232, __LayerInfoStorage etc
-		//section name starts with 0x46 position
-		while(1)
-		{
-		//section_header_size=0x6F(4 bytes) + '\n'
-			LAYER+=0x5;
-
-		//section_header
-			fseek(f,LAYER+0x46,SEEK_SET);
-			char sec_name[42];
-			sec_name[41]='\0';
-			fread(&sec_name,41,1,f);
-
-			fseek(f, LAYER+0x3, SEEK_SET);
-			fread(&r,sizeof(rect),1,f);
-			if(IsBigEndian()) SwapBytes(r);
-
-			unsigned char attach=0;
-			fseek(f,LAYER+0x28,SEEK_SET);
-			fread(&attach,1,1,f);
-
-			unsigned char border=0;
-			fseek(f, LAYER+0x29, SEEK_SET);
-			fread(&border,1,1,f);
-
-			unsigned char color=0;
-			fseek(f,LAYER+0x33,SEEK_SET);
-			fread(&color,1,1,f);
-
-		//section_body_1_size
-			LAYER+=0x6F+0x1;
-			fseek(f,LAYER,SEEK_SET);
-			fread(&sec_size,4,1,f);
-			if(IsBigEndian()) SwapBytes(sec_size);
-
-		//section_body_1
-			LAYER+=0x5;
-			int size=sec_size;
-
-			unsigned char type=0;
-			fseek(f,LAYER,SEEK_SET);
-			fread(&type,1,1,f);
-
-			//text properties
-			short rotation=0;
-			fseek(f,LAYER+2,SEEK_SET);
-			fread(&rotation,2,1,f);
-			if(IsBigEndian()) SwapBytes(rotation);
-
-			unsigned char fontsize=0;
-			fread(&fontsize,1,1,f);
-
-			unsigned char tab=0;
-			fseek(f,LAYER+0xA,SEEK_SET);
-			fread(&tab,1,1,f);
-
-			//line properties
-			unsigned char line_style = 0;
-			double width = 0.0;
-			lineVertex begin, end;
-			unsigned int w = 0;
-
-			fseek(f,LAYER+0x12,SEEK_SET);
-			fread(&line_style,1,1,f);
-
-			fseek(f,LAYER+0x13,SEEK_SET);
-			fread(&w,2,1,f);
-			if(IsBigEndian()) SwapBytes(w);
-			width = (double)w/500.0;
-
-			fseek(f,LAYER+0x20,SEEK_SET);
-			fread(&begin.x,8,1,f);
-			if(IsBigEndian()) SwapBytes(begin.x);
-
-			fread(&end.x,8,1,f);
-			if(IsBigEndian()) SwapBytes(end.x);
-
-			fseek(f,LAYER+0x40,SEEK_SET);
-			fread(&begin.y,8,1,f);
-			if(IsBigEndian()) SwapBytes(begin.y);
-
-			fread(&end.y,8,1,f);
-			if(IsBigEndian()) SwapBytes(end.y);
-
-			fseek(f,LAYER+0x60,SEEK_SET);
-			fread(&begin.shape_type,1,1,f);
-
-			fseek(f,LAYER+0x64,SEEK_SET);
-			fread(&w,4,1,f);
-			if(IsBigEndian()) SwapBytes(w);
-			begin.shape_width = (double)w/500.0;
-
-			fread(&w,4,1,f);
-			if(IsBigEndian()) SwapBytes(w);
-			begin.shape_length = (double)w/500.0;
-
-			fseek(f,LAYER+0x6C,SEEK_SET);
-			fread(&end.shape_type,1,1,f);
-
-			fseek(f,LAYER+0x70,SEEK_SET);
-			fread(&w,4,1,f);
-			if(IsBigEndian()) SwapBytes(w);
-			end.shape_width = (double)w/500.0;
-
-			fread(&w,4,1,f);
-			if(IsBigEndian()) SwapBytes(w);
-			end.shape_length = (double)w/500.0;
-
-			// bitmap properties
-			short bitmap_width = 0;
-			fseek(f,LAYER+0x1,SEEK_SET);
-			fread(&bitmap_width,2,1,f);
-			if(IsBigEndian()) SwapBytes(bitmap_width);
-
-			short bitmap_height = 0;
-			fread(&bitmap_height,2,1,f);
-			if(IsBigEndian()) SwapBytes(bitmap_height);
-
-			double bitmap_left = 0.0;
-			fseek(f,LAYER+0x13,SEEK_SET);
-			fread(&bitmap_left,8,1,f);
-			if(IsBigEndian()) SwapBytes(bitmap_left);
-
-			double bitmap_top = 0.0;
-			fseek(f,LAYER+0x1B,SEEK_SET);
-			fread(&bitmap_top,8,1,f);
-			if(IsBigEndian()) SwapBytes(bitmap_top);
-
-		//section_body_2_size
-			LAYER+=sec_size+0x1;
-			fseek(f,LAYER,SEEK_SET);
-			fread(&sec_size,4,1,f);
-			if(IsBigEndian()) SwapBytes(sec_size);
-
-		//section_body_2
-			LAYER+=0x5;
-			//check if it is a axis or legend
-			fseek(f,1,SEEK_CUR);
-			char stmp[255];
-			if(0==strcmp(sec_name,"XB"))
-			{
-				stmp[sec_size]='\0';
-				fread(&stmp,sec_size,1,f);
-				GRAPH.back().layer.back().xAxis.pos = Bottom;
-				GRAPH.back().layer.back().xAxis.label = text(stmp, r, color, fontsize, rotation/10, tab, (border >= 0x80 ? border-0x80 : None), attach);
-			}
-			else if(0==strcmp(sec_name,"XT"))
-			{
-				stmp[sec_size]='\0';
-				fread(&stmp,sec_size,1,f);
-				GRAPH.back().layer.back().xAxis.pos=Top;
-				GRAPH.back().layer.back().xAxis.label = text(stmp, r, color, fontsize, rotation/10, tab, (border >= 0x80 ? border-0x80 : None), attach);
-			}
-			else if(0==strcmp(sec_name,"YL"))
-			{
-				stmp[sec_size]='\0';
-				fread(&stmp,sec_size,1,f);
-				GRAPH.back().layer.back().yAxis.pos = Left;
-				GRAPH.back().layer.back().yAxis.label = text(stmp, r, color, fontsize, rotation/10, tab, (border >= 0x80 ? border-0x80 : None), attach);
-			}
-			else if(0==strcmp(sec_name,"YR"))
-			{
-				stmp[sec_size]='\0';
-				fread(&stmp,sec_size,1,f);
-				GRAPH.back().layer.back().yAxis.pos = Right;
-				GRAPH.back().layer.back().yAxis.label = text(stmp, r, color, fontsize, rotation/10, tab, (border >= 0x80 ? border-0x80 : None), attach);
-			}
-			else if(0==strcmp(sec_name,"Legend"))
-			{
-				stmp[sec_size]='\0';
-				fread(&stmp,sec_size,1,f);
-				GRAPH.back().layer.back().legend = text(stmp, r, color, fontsize, rotation/10, tab, (border >= 0x80 ? border-0x80 : None), attach);
-			}
-			else if(0==strcmp(sec_name,"__BCO2")) // histogram
-			{
-				double d;
-				fseek(f,LAYER+0x10,SEEK_SET);
-				fread(&d,8,1,f);
-				if(IsBigEndian()) SwapBytes(d);
-				GRAPH.back().layer.back().histogram_bin=d;
-				fseek(f,LAYER+0x20,SEEK_SET);
-				fread(&d,8,1,f);
-				if(IsBigEndian()) SwapBytes(d);
-				GRAPH.back().layer.back().histogram_end=d;
-				fseek(f,LAYER+0x28,SEEK_SET);
-				fread(&d,8,1,f);
-				if(IsBigEndian()) SwapBytes(d);
-				GRAPH.back().layer.back().histogram_begin=d;
-			}
-			else if(size==0x3E) // text
-			{
-				stmp[sec_size]='\0';
-				fread(&stmp,sec_size,1,f);
-				GRAPH.back().layer.back().texts.push_back(text(stmp));
-				GRAPH.back().layer.back().texts.back().color=color;
-				GRAPH.back().layer.back().texts.back().clientRect=r;
-				GRAPH.back().layer.back().texts.back().tab=tab;
-				GRAPH.back().layer.back().texts.back().fontsize=fontsize;
-				GRAPH.back().layer.back().texts.back().rotation=rotation/10;
-				GRAPH.back().layer.back().texts.back().attach=attach;
-				if(border>=0x80)
-					GRAPH.back().layer.back().texts.back().border_type=border-0x80;
-				else
-					GRAPH.back().layer.back().texts.back().border_type=None;
-			}
-			else if(size==0x78 && type==2) // line
-			{
-				GRAPH.back().layer.back().lines.push_back(line());
-				GRAPH.back().layer.back().lines.back().color=color;
-				GRAPH.back().layer.back().lines.back().clientRect=r;
-				GRAPH.back().layer.back().lines.back().attach=attach;
-				GRAPH.back().layer.back().lines.back().width=width;
-				GRAPH.back().layer.back().lines.back().line_style=line_style;
-				GRAPH.back().layer.back().lines.back().begin=begin;
-				GRAPH.back().layer.back().lines.back().end=end;
-			}
-			else if(size==0x28 && type==4) // bitmap
-			{
-				unsigned long filesize=sec_size+14;
-				GRAPH.back().layer.back().bitmaps.push_back(bitmap());
-				GRAPH.back().layer.back().bitmaps.back().left=bitmap_left;
-				GRAPH.back().layer.back().bitmaps.back().top=bitmap_top;
-				GRAPH.back().layer.back().bitmaps.back().width=
-					(GRAPH.back().layer.back().xAxis.max - GRAPH.back().layer.back().xAxis.min)*bitmap_width/10000;
-				GRAPH.back().layer.back().bitmaps.back().height=
-					(GRAPH.back().layer.back().yAxis.max - GRAPH.back().layer.back().yAxis.min)*bitmap_height/10000;
-				GRAPH.back().layer.back().bitmaps.back().attach=attach;
-				GRAPH.back().layer.back().bitmaps.back().size=filesize;
-				GRAPH.back().layer.back().bitmaps.back().data=new unsigned char[filesize];
-				unsigned char *data=GRAPH.back().layer.back().bitmaps.back().data;
-				//add Bitmap header
-				memcpy(data, "BM", 2);
-				data+=2;
-				memcpy(data, &filesize, 4);
-				data+=4;
-				unsigned int d=0;
-				memcpy(data, &d, 4);
-				data+=4;
-				d=0x36;
-				memcpy(data, &d, 4);
-				data+=4;
-				fread(data,sec_size,1,f);
-			}
-
-		//close section 00 00 00 00 0A
-			LAYER+=sec_size+(sec_size>0?0x1:0);
-
-		//section_body_3_size
-			fseek(f,LAYER,SEEK_SET);
-			fread(&sec_size,4,1,f);
-			if(IsBigEndian()) SwapBytes(sec_size);
-
-		//section_body_3
-			LAYER+=0x5;
-
-		//close section 00 00 00 00 0A
-			LAYER+=sec_size+(sec_size>0?0x1:0);
-
-			if(0==strcmp(sec_name,"__LayerInfoStorage"))
-				break;
-
-		}
-		LAYER+=0x5;
-		unsigned char h;
-		short w;
-
-		fseek(f,LAYER,SEEK_SET);
-		fread(&sec_size,4,1,f);
-		if(IsBigEndian()) SwapBytes(sec_size);
-		if(sec_size==0x1E7)//check layer is not empty
-		{
-			while(1)
-			{
-				LAYER+=0x5;
-
-				graphCurve curve;
-
-				vector<string> col;
-				fseek(f,LAYER+0x4,SEEK_SET);
-				fread(&w,2,1,f);
-				if(IsBigEndian()) SwapBytes(w);
-				col=findDataByIndex(w-1);
-				short nColY = w;
-				if(col.size()>0)
-				{
-					fprintf(debug,"			GRAPH %d layer %d curve %d Y : %s.%s\n",GRAPH.size(),GRAPH.back().layer.size(),GRAPH.back().layer.back().curve.size(),col[1].c_str(),col[0].c_str());
-					fflush(debug);
-					curve.yColName=col[0];
-					curve.dataName=col[1];
-				}
-
-				fseek(f,LAYER+0x23,SEEK_SET);
-				fread(&w,2,1,f);
-				if(IsBigEndian()) SwapBytes(w);
-				col=findDataByIndex(w-1);
-				if(col.size()>0)
-				{
-					fprintf(debug,"			GRAPH %d layer %d curve %d X : %s.%s\n",GRAPH.size(),GRAPH.back().layer.size(),GRAPH.back().layer.back().curve.size(),col[1].c_str(),col[0].c_str());
-					fflush(debug);
-					curve.xColName=col[0];
-					if(curve.dataName!=col[1])
-						fprintf(debug,"			GRAPH %d X and Y from different tables\n",GRAPH.size());
-				}
-
-				fseek(f,LAYER+0x4C,SEEK_SET);
-				fread(&h,1,1,f);
-				curve.type=h;
-
-				fseek(f,LAYER+0x11,SEEK_SET);
-				fread(&h,1,1,f);
-				curve.line_connect=h;
-
-				fseek(f,LAYER+0x12,SEEK_SET);
-				fread(&h,1,1,f);
-				curve.line_style=h;
-
-				fseek(f,LAYER+0x15,SEEK_SET);
-				fread(&w,2,1,f);
-				if(IsBigEndian()) SwapBytes(w);
-				curve.line_width=(double)w/500.0;
-
-				fseek(f,LAYER+0x19,SEEK_SET);
-				fread(&w,2,1,f);
-				if(IsBigEndian()) SwapBytes(w);
-				curve.symbol_size=(double)w/500.0;
-
-				fseek(f,LAYER+0x1C,SEEK_SET);
-				fread(&h,1,1,f);
-				curve.fillarea=(h==2?true:false);
-
-				fseek(f,LAYER+0x1E,SEEK_SET);
-				fread(&h,1,1,f);
-				curve.fillarea_type=h;
-
-				//vector
-				if(curve.type == FlowVector || curve.type == Vector)
-				{
-					fseek(f,LAYER+0x56,SEEK_SET);
-					fread(&curve.vector.multiplier,4,1,f);
-					if(IsBigEndian()) SwapBytes(curve.vector.multiplier);
-
-					fseek(f,LAYER+0x5E,SEEK_SET);
-					fread(&h,1,1,f);
-					col=findDataByIndex(nColY - 1 + h - 0x64);
-					if(col.size()>0)
-					{
-						curve.vector.endXColName = col[0];
-					}
-
-					fseek(f,LAYER+0x62,SEEK_SET);
-					fread(&h,1,1,f);
-					col=findDataByIndex(nColY - 1 + h - 0x64);
-					if(col.size()>0)
-					{
-						curve.vector.endYColName = col[0];
-					}
-
-					fseek(f,LAYER+0x18,SEEK_SET);
-					fread(&h,1,1,f);
-					if(h >= 0x64)
-					{
-						col=findDataByIndex(nColY - 1 + h - 0x64);
-						if(col.size()>0)
-							curve.vector.angleColName = col[0];
-					}
-					else if(h <= 0x08)
-					{
-						curve.vector.const_angle = 45*h;
-					}
-
-					fseek(f,LAYER+0x19,SEEK_SET);
-					fread(&h,1,1,f);
-					if(h >= 0x64 && h < 0x1F4)
-					{
-						col=findDataByIndex(nColY - 1 + h - 0x64);
-						if(col.size()>0)
-							curve.vector.magnitudeColName = col[0];
-					}
-					else
-					{
-						curve.vector.const_magnitude = static_cast<int>(curve.symbol_size);
-					}
-
-					fseek(f,LAYER+0x66,SEEK_SET);
-					fread(&curve.vector.arrow_lenght,2,1,f);
-					if(IsBigEndian()) SwapBytes(curve.vector.arrow_lenght);
-
-					fread(&curve.vector.arrow_angle,1,1,f);
-
-					fread(&h,1,1,f);
-					curve.vector.arrow_closed = !(h&0x1);
-
-					fread(&w,2,1,f);
-					if(IsBigEndian()) SwapBytes(w);
-					curve.vector.width=(double)w/500.0;
-
-					fseek(f,LAYER+0x142,SEEK_SET);
-					fread(&h,1,1,f);
-					switch(h)
-					{
-					case 2:
-						curve.vector.position = Midpoint;
-						break;
-					case 4:
-						curve.vector.position = Head;
-					    break;
-					default:
-						curve.vector.position = Tail;
-					    break;
-					}
-					
-				}
-
-				//pie
-				if(curve.type == Pie)
-				{
-					fseek(f,LAYER+0x92,SEEK_SET);
-					fread(&h,1,1,f);
-					curve.pie.format_percentages = (h&0x01);
-					curve.pie.format_values = (h&0x02);
-					curve.pie.position_associate = (h&0x08);
-					curve.pie.clockwise_rotation = (h&0x20);
-					curve.pie.format_categories = (h&0x80);
-
-					fread(&h,1,1,f);
-					curve.pie.format_automatic = h;
-
-					fread(&curve.pie.distance,2,1,f);
-					if(IsBigEndian()) SwapBytes(curve.pie.distance);
-
-					fread(&curve.pie.view_angle,1,1,f);
-
-					fseek(f,LAYER+0x98,SEEK_SET);
-					fread(&curve.pie.thickness,1,1,f);
-
-					fseek(f,LAYER+0x9A,SEEK_SET);
-					fread(&curve.pie.rotation,2,1,f);
-					if(IsBigEndian()) SwapBytes(curve.pie.rotation);
-
-					fseek(f,LAYER+0x9E,SEEK_SET);
-					fread(&curve.pie.displacement,2,1,f);
-					if(IsBigEndian()) SwapBytes(curve.pie.displacement);
-
-					fseek(f,LAYER+0xA0,SEEK_SET);
-					fread(&curve.pie.radius,2,1,f);
-					if(IsBigEndian()) SwapBytes(curve.pie.radius);
-
-					fseek(f,LAYER+0xA2,SEEK_SET);
-					fread(&curve.pie.horizontal_offset,2,1,f);
-					if(IsBigEndian()) SwapBytes(curve.pie.horizontal_offset);
-
-					fseek(f,LAYER+0xA6,SEEK_SET);
-					fread(&curve.pie.displaced_sections,4,1,f);
-					if(IsBigEndian()) SwapBytes(curve.pie.displaced_sections);
-				}
-				
-				fseek(f,LAYER+0xC2,SEEK_SET);
-				fread(&h,1,1,f);
-				curve.fillarea_color=h;
-
-				fseek(f,LAYER+0xC3,SEEK_SET);
-				fread(&h,1,1,f);
-				curve.fillarea_first_color=h;
-
-				fseek(f,LAYER+0xCE,SEEK_SET);
-				fread(&h,1,1,f);
-				curve.fillarea_pattern=h;
-
-				fseek(f,LAYER+0xCA,SEEK_SET);
-				fread(&h,1,1,f);
-				curve.fillarea_pattern_color=h;
-
-				fseek(f,LAYER+0xC6,SEEK_SET);
-				fread(&w,2,1,f);
-				if(IsBigEndian()) SwapBytes(w);
-				curve.fillarea_pattern_width=(double)w/500.0;
-
-				fseek(f,LAYER+0xCF,SEEK_SET);
-				fread(&h,1,1,f);
-				curve.fillarea_pattern_border_style=h;
-
-				fseek(f,LAYER+0xD2,SEEK_SET);
-				fread(&h,1,1,f);
-				curve.fillarea_pattern_border_color=h;
-
-				fseek(f,LAYER+0xD0,SEEK_SET);
-				fread(&w,2,1,f);
-				if(IsBigEndian()) SwapBytes(w);
-				curve.fillarea_pattern_border_width=(double)w/500.0;
-
-				fseek(f,LAYER+0x16A,SEEK_SET);
-				fread(&h,1,1,f);
-				curve.line_color=h;
-
-				fseek(f,LAYER+0x17,SEEK_SET);
-				fread(&w,2,1,f);
-				if(IsBigEndian()) SwapBytes(w);
-				curve.symbol_type=w;
-
-				fseek(f,LAYER+0x12E,SEEK_SET);
-				fread(&h,1,1,f);
-				curve.symbol_fill_color=h;
-
-				fseek(f,LAYER+0x132,SEEK_SET);
-				fread(&h,1,1,f);
-				curve.symbol_color=h;
-				curve.vector.color=h;
-
-				fseek(f,LAYER+0x136,SEEK_SET);
-				fread(&h,1,1,f);
-				curve.symbol_thickness=(h==255?1:h);
-
-				fseek(f,LAYER+0x137,SEEK_SET);
-				fread(&h,1,1,f);
-				curve.point_offset=h;
-
-				GRAPH.back().layer.back().curve.push_back(curve);
-
-				LAYER+=0x1E7+0x1;
-				fseek(f,LAYER,SEEK_SET);
-				int comm_size=0;
-				fread(&comm_size,4,1,f);
-				if(IsBigEndian()) SwapBytes(comm_size);
-				LAYER+=0x5;
-				if(comm_size>0)
-				{
-					LAYER+=comm_size+0x1;
-				}
-				fseek(f,LAYER,SEEK_SET);
-				int ntmp;
-				fread(&ntmp,4,1,f);
-				if(IsBigEndian()) SwapBytes(ntmp);
-				if(ntmp!=0x1E7)
-					break;
-			}
-
-		}
-		//LAYER+=0x5*0x5+0x1ED*0x12;
-		//LAYER+=2*0x5;
-
-		LAYER+=0x5;
-		//read axis breaks
-		while(1)
-		{
-			fseek(f,LAYER,SEEK_SET);
-			fread(&sec_size,4,1,f);
-			if(IsBigEndian()) SwapBytes(sec_size);
-			if(sec_size == 0x2D)
-			{
-				LAYER+=0x5;
-				fseek(f,LAYER+2,SEEK_SET);
-				fread(&h,1,1,f);
-				if(h==2)
-				{
-					GRAPH.back().layer.back().xAxisBreak.minor_ticks_before = (unsigned char)(GRAPH.back().layer.back().xAxis.minorTicks);
-					GRAPH.back().layer.back().xAxisBreak.scale_increment_before = GRAPH.back().layer.back().xAxis.step;
-					readGraphAxisBreakInfo(GRAPH.back().layer.back().xAxisBreak, f, LAYER);
-				}
-				else if(h==4)
-				{
-					GRAPH.back().layer.back().yAxisBreak.minor_ticks_before = (unsigned char)(GRAPH.back().layer.back().yAxis.minorTicks);
-					GRAPH.back().layer.back().yAxisBreak.scale_increment_before = GRAPH.back().layer.back().yAxis.step;
-					readGraphAxisBreakInfo(GRAPH.back().layer.back().yAxisBreak, f, LAYER);
-				}
-				LAYER+=0x2D + 0x1;
-			}
-			else
-				break;
-		}
-		LAYER+=0x5;
-		
-
-		LAYER+=0x5;
-		readGraphGridInfo(GRAPH.back().layer.back().xAxis.minorGrid, f, LAYER);
-		LAYER+=0x1E7+1;
-
-		LAYER+=0x5;
-		readGraphGridInfo(GRAPH.back().layer.back().xAxis.majorGrid, f, LAYER);
-		LAYER+=0x1E7+1;
-
-		LAYER+=0x5;
-		readGraphAxisTickLabelsInfo(GRAPH.back().layer.back().xAxis.tickAxis[0], f, LAYER);
-		LAYER+=0x1E7+1;
-
-		LAYER+=0x5;
-		readGraphAxisFormatInfo(GRAPH.back().layer.back().xAxis.formatAxis[0], f, LAYER);
-		LAYER+=0x1E7+1;
-
-		LAYER+=0x5;
-		readGraphAxisTickLabelsInfo(GRAPH.back().layer.back().xAxis.tickAxis[1], f, LAYER);
-		LAYER+=0x1E7+1;
-
-		LAYER+=0x5;
-		readGraphAxisFormatInfo(GRAPH.back().layer.back().xAxis.formatAxis[1], f, LAYER);
-		LAYER+=0x1E7+1;
-
-		LAYER+=0x5;
-
-
-		LAYER+=0x5;
-		readGraphGridInfo(GRAPH.back().layer.back().yAxis.minorGrid, f, LAYER);
-		LAYER+=0x1E7+1;
-
-		LAYER+=0x5;
-		readGraphGridInfo(GRAPH.back().layer.back().yAxis.majorGrid, f, LAYER);
-		LAYER+=0x1E7+1;
-
-		LAYER+=0x5;
-		readGraphAxisTickLabelsInfo(GRAPH.back().layer.back().yAxis.tickAxis[0], f, LAYER);
-		LAYER+=0x1E7+1;
-
-		LAYER+=0x5;
-		readGraphAxisFormatInfo(GRAPH.back().layer.back().yAxis.formatAxis[0], f, LAYER);
-		LAYER+=0x1E7+1;
-
-		LAYER+=0x5;
-		readGraphAxisTickLabelsInfo(GRAPH.back().layer.back().yAxis.tickAxis[1], f, LAYER);
-		LAYER+=0x1E7+1;
-
-		LAYER+=0x5;
-		readGraphAxisFormatInfo(GRAPH.back().layer.back().yAxis.formatAxis[1], f, LAYER);
-		LAYER+=0x1E7+1;
-
-		LAYER+=0x2*0x5+0x1ED*0x6;
-
-		fseek(f,LAYER,SEEK_SET);
-		fread(&sec_size,4,1,f);
-		if(IsBigEndian()) SwapBytes(sec_size);
-		if(sec_size==0)
-			break;
-	}
-	POS = LAYER+0x5;
-
-	fseek(f,POS,SEEK_SET);
+  unsigned short graph_width;
+  fseek(f,POS + 0x23,SEEK_SET);
+  fread(&graph_width,2,1,f);
+  if(IsBigEndian()) SwapBytes(graph_width);
+  GRAPH.back().width = graph_width;
+
+  unsigned short graph_height;
+  fread(&graph_height,2,1,f);
+  if(IsBigEndian()) SwapBytes(graph_height);
+  GRAPH.back().height = graph_height;
+
+  int LAYER = POS;
+  LAYER += headersize + 0x1;
+  int sec_size;
+  while(1)// multilayer loop
+  {
+    GRAPH.back().layer.push_back(graphLayer());
+    // LAYER section
+    LAYER +=0x5;
+    double range=0.0;
+    unsigned char m=0;
+    fseek(f, LAYER+0xF, SEEK_SET);
+    fread(&range,8,1,f);
+    if(IsBigEndian()) SwapBytes(range);
+    GRAPH.back().layer.back().xAxis.min=range;
+    fread(&range,8,1,f);
+    if(IsBigEndian()) SwapBytes(range);
+    GRAPH.back().layer.back().xAxis.max=range;
+    fread(&range,8,1,f);
+    if(IsBigEndian()) SwapBytes(range);
+    GRAPH.back().layer.back().xAxis.step=range;
+    fseek(f, LAYER+0x2B, SEEK_SET);
+    fread(&m,1,1,f);
+    GRAPH.back().layer.back().xAxis.majorTicks=m;
+    fseek(f, LAYER+0x37, SEEK_SET);
+    fread(&m,1,1,f);
+    GRAPH.back().layer.back().xAxis.minorTicks=m;
+    fread(&m,1,1,f);
+    GRAPH.back().layer.back().xAxis.scale=m;
+
+    fseek(f, LAYER+0x3A, SEEK_SET);
+    fread(&range,8,1,f);
+    if(IsBigEndian()) SwapBytes(range);
+    GRAPH.back().layer.back().yAxis.min=range;
+    fread(&range,8,1,f);
+    if(IsBigEndian()) SwapBytes(range);
+    GRAPH.back().layer.back().yAxis.max=range;
+    fread(&range,8,1,f);
+    if(IsBigEndian()) SwapBytes(range);
+    GRAPH.back().layer.back().yAxis.step=range;
+    fseek(f, LAYER+0x56, SEEK_SET);
+    fread(&m,1,1,f);
+    GRAPH.back().layer.back().yAxis.majorTicks=m;
+    fseek(f, LAYER+0x62, SEEK_SET);
+    fread(&m,1,1,f);
+    GRAPH.back().layer.back().yAxis.minorTicks=m;
+    fread(&m,1,1,f);
+    GRAPH.back().layer.back().yAxis.scale=m;
+
+    rect r;
+    fseek(f, LAYER+0x71, SEEK_SET);
+    fread(&r,sizeof(rect),1,f);
+    if(IsBigEndian()) SwapBytes(r);
+    GRAPH.back().layer.back().clientRect=r;
+
+    LAYER += 0x12D + 0x1;
+    //now structure is next : section_header_size=0x6F(4 bytes) + '\n' + section_header(0x6F bytes) + section_body_1_size(4 bytes) + '\n' + section_body_1 + section_body_2_size(maybe=0)(4 bytes) + '\n' + section_body_2 + '\n'
+    //possible sections: axes, legend, __BC02, _202, _231, _232, __LayerInfoStorage etc
+    //section name starts with 0x46 position
+    while(1)
+    {
+    //section_header_size=0x6F(4 bytes) + '\n'
+      LAYER+=0x5;
+
+    //section_header
+      fseek(f,LAYER+0x46,SEEK_SET);
+      char sec_name[42];
+      sec_name[41]='\0';
+      fread(&sec_name,41,1,f);
+
+      fseek(f, LAYER+0x3, SEEK_SET);
+      fread(&r,sizeof(rect),1,f);
+      if(IsBigEndian()) SwapBytes(r);
+
+      unsigned char attach=0;
+      fseek(f,LAYER+0x28,SEEK_SET);
+      fread(&attach,1,1,f);
+
+      unsigned char border=0;
+      fseek(f, LAYER+0x29, SEEK_SET);
+      fread(&border,1,1,f);
+
+      unsigned char color=0;
+      fseek(f,LAYER+0x33,SEEK_SET);
+      fread(&color,1,1,f);
+
+    //section_body_1_size
+      LAYER+=0x6F+0x1;
+      fseek(f,LAYER,SEEK_SET);
+      fread(&sec_size,4,1,f);
+      if(IsBigEndian()) SwapBytes(sec_size);
+
+    //section_body_1
+      LAYER+=0x5;
+      int size=sec_size;
+
+      unsigned char type=0;
+      fseek(f,LAYER,SEEK_SET);
+      fread(&type,1,1,f);
+
+      //text properties
+      short rotation=0;
+      fseek(f,LAYER+2,SEEK_SET);
+      fread(&rotation,2,1,f);
+      if(IsBigEndian()) SwapBytes(rotation);
+
+      unsigned char fontsize=0;
+      fread(&fontsize,1,1,f);
+
+      unsigned char tab=0;
+      fseek(f,LAYER+0xA,SEEK_SET);
+      fread(&tab,1,1,f);
+
+      //line properties
+      unsigned char line_style = 0;
+      double width = 0.0;
+      lineVertex begin, end;
+      unsigned int w = 0;
+
+      fseek(f,LAYER+0x12,SEEK_SET);
+      fread(&line_style,1,1,f);
+
+      fseek(f,LAYER+0x13,SEEK_SET);
+      fread(&w,2,1,f);
+      if(IsBigEndian()) SwapBytes(w);
+      width = (double)w/500.0;
+
+      fseek(f,LAYER+0x20,SEEK_SET);
+      fread(&begin.x,8,1,f);
+      if(IsBigEndian()) SwapBytes(begin.x);
+
+      fread(&end.x,8,1,f);
+      if(IsBigEndian()) SwapBytes(end.x);
+
+      fseek(f,LAYER+0x40,SEEK_SET);
+      fread(&begin.y,8,1,f);
+      if(IsBigEndian()) SwapBytes(begin.y);
+
+      fread(&end.y,8,1,f);
+      if(IsBigEndian()) SwapBytes(end.y);
+
+      fseek(f,LAYER+0x60,SEEK_SET);
+      fread(&begin.shape_type,1,1,f);
+
+      fseek(f,LAYER+0x64,SEEK_SET);
+      fread(&w,4,1,f);
+      if(IsBigEndian()) SwapBytes(w);
+      begin.shape_width = (double)w/500.0;
+
+      fread(&w,4,1,f);
+      if(IsBigEndian()) SwapBytes(w);
+      begin.shape_length = (double)w/500.0;
+
+      fseek(f,LAYER+0x6C,SEEK_SET);
+      fread(&end.shape_type,1,1,f);
+
+      fseek(f,LAYER+0x70,SEEK_SET);
+      fread(&w,4,1,f);
+      if(IsBigEndian()) SwapBytes(w);
+      end.shape_width = (double)w/500.0;
+
+      fread(&w,4,1,f);
+      if(IsBigEndian()) SwapBytes(w);
+      end.shape_length = (double)w/500.0;
+
+      // bitmap properties
+      short bitmap_width = 0;
+      fseek(f,LAYER+0x1,SEEK_SET);
+      fread(&bitmap_width,2,1,f);
+      if(IsBigEndian()) SwapBytes(bitmap_width);
+
+      short bitmap_height = 0;
+      fread(&bitmap_height,2,1,f);
+      if(IsBigEndian()) SwapBytes(bitmap_height);
+
+      double bitmap_left = 0.0;
+      fseek(f,LAYER+0x13,SEEK_SET);
+      fread(&bitmap_left,8,1,f);
+      if(IsBigEndian()) SwapBytes(bitmap_left);
+
+      double bitmap_top = 0.0;
+      fseek(f,LAYER+0x1B,SEEK_SET);
+      fread(&bitmap_top,8,1,f);
+      if(IsBigEndian()) SwapBytes(bitmap_top);
+
+    //section_body_2_size
+      LAYER+=sec_size+0x1;
+      fseek(f,LAYER,SEEK_SET);
+      fread(&sec_size,4,1,f);
+      if(IsBigEndian()) SwapBytes(sec_size);
+
+    //section_body_2
+      LAYER+=0x5;
+      //check if it is a axis or legend
+      fseek(f,1,SEEK_CUR);
+      char stmp[255];
+      if(0==strcmp(sec_name,"XB"))
+      {
+        stmp[sec_size]='\0';
+        fread(&stmp,sec_size,1,f);
+        GRAPH.back().layer.back().xAxis.pos = Bottom;
+        GRAPH.back().layer.back().xAxis.label = text(stmp, r, color, fontsize, rotation/10, tab, (border >= 0x80 ? border-0x80 : None), attach);
+      }
+      else if(0==strcmp(sec_name,"XT"))
+      {
+        stmp[sec_size]='\0';
+        fread(&stmp,sec_size,1,f);
+        GRAPH.back().layer.back().xAxis.pos=Top;
+        GRAPH.back().layer.back().xAxis.label = text(stmp, r, color, fontsize, rotation/10, tab, (border >= 0x80 ? border-0x80 : None), attach);
+      }
+      else if(0==strcmp(sec_name,"YL"))
+      {
+        stmp[sec_size]='\0';
+        fread(&stmp,sec_size,1,f);
+        GRAPH.back().layer.back().yAxis.pos = Left;
+        GRAPH.back().layer.back().yAxis.label = text(stmp, r, color, fontsize, rotation/10, tab, (border >= 0x80 ? border-0x80 : None), attach);
+      }
+      else if(0==strcmp(sec_name,"YR"))
+      {
+        stmp[sec_size]='\0';
+        fread(&stmp,sec_size,1,f);
+        GRAPH.back().layer.back().yAxis.pos = Right;
+        GRAPH.back().layer.back().yAxis.label = text(stmp, r, color, fontsize, rotation/10, tab, (border >= 0x80 ? border-0x80 : None), attach);
+      }
+      else if(0==strcmp(sec_name,"Legend"))
+      {
+        stmp[sec_size]='\0';
+        fread(&stmp,sec_size,1,f);
+        GRAPH.back().layer.back().legend = text(stmp, r, color, fontsize, rotation/10, tab, (border >= 0x80 ? border-0x80 : None), attach);
+      }
+      else if(0==strcmp(sec_name,"__BCO2")) // histogram
+      {
+        double d;
+        fseek(f,LAYER+0x10,SEEK_SET);
+        fread(&d,8,1,f);
+        if(IsBigEndian()) SwapBytes(d);
+        GRAPH.back().layer.back().histogram_bin=d;
+        fseek(f,LAYER+0x20,SEEK_SET);
+        fread(&d,8,1,f);
+        if(IsBigEndian()) SwapBytes(d);
+        GRAPH.back().layer.back().histogram_end=d;
+        fseek(f,LAYER+0x28,SEEK_SET);
+        fread(&d,8,1,f);
+        if(IsBigEndian()) SwapBytes(d);
+        GRAPH.back().layer.back().histogram_begin=d;
+      }
+      else if(size==0x3E) // text
+      {
+        stmp[sec_size]='\0';
+        fread(&stmp,sec_size,1,f);
+        GRAPH.back().layer.back().texts.push_back(text(stmp));
+        GRAPH.back().layer.back().texts.back().color=color;
+        GRAPH.back().layer.back().texts.back().clientRect=r;
+        GRAPH.back().layer.back().texts.back().tab=tab;
+        GRAPH.back().layer.back().texts.back().fontsize=fontsize;
+        GRAPH.back().layer.back().texts.back().rotation=rotation/10;
+        GRAPH.back().layer.back().texts.back().attach=attach;
+        if(border>=0x80)
+          GRAPH.back().layer.back().texts.back().border_type=border-0x80;
+        else
+          GRAPH.back().layer.back().texts.back().border_type=None;
+      }
+      else if(size==0x78 && type==2) // line
+      {
+        GRAPH.back().layer.back().lines.push_back(line());
+        GRAPH.back().layer.back().lines.back().color=color;
+        GRAPH.back().layer.back().lines.back().clientRect=r;
+        GRAPH.back().layer.back().lines.back().attach=attach;
+        GRAPH.back().layer.back().lines.back().width=width;
+        GRAPH.back().layer.back().lines.back().line_style=line_style;
+        GRAPH.back().layer.back().lines.back().begin=begin;
+        GRAPH.back().layer.back().lines.back().end=end;
+      }
+      else if(size==0x28 && type==4) // bitmap
+      {
+        unsigned long filesize=sec_size+14;
+        GRAPH.back().layer.back().bitmaps.push_back(bitmap());
+        GRAPH.back().layer.back().bitmaps.back().left=bitmap_left;
+        GRAPH.back().layer.back().bitmaps.back().top=bitmap_top;
+        GRAPH.back().layer.back().bitmaps.back().width=
+          (GRAPH.back().layer.back().xAxis.max - GRAPH.back().layer.back().xAxis.min)*bitmap_width/10000;
+        GRAPH.back().layer.back().bitmaps.back().height=
+          (GRAPH.back().layer.back().yAxis.max - GRAPH.back().layer.back().yAxis.min)*bitmap_height/10000;
+        GRAPH.back().layer.back().bitmaps.back().attach=attach;
+        GRAPH.back().layer.back().bitmaps.back().size=filesize;
+        GRAPH.back().layer.back().bitmaps.back().data=new unsigned char[filesize];
+        unsigned char *data=GRAPH.back().layer.back().bitmaps.back().data;
+        //add Bitmap header
+        memcpy(data, "BM", 2);
+        data+=2;
+        memcpy(data, &filesize, 4);
+        data+=4;
+        unsigned int d=0;
+        memcpy(data, &d, 4);
+        data+=4;
+        d=0x36;
+        memcpy(data, &d, 4);
+        data+=4;
+        fread(data,sec_size,1,f);
+      }
+
+    //close section 00 00 00 00 0A
+      LAYER+=sec_size+(sec_size>0?0x1:0);
+
+    //section_body_3_size
+      fseek(f,LAYER,SEEK_SET);
+      fread(&sec_size,4,1,f);
+      if(IsBigEndian()) SwapBytes(sec_size);
+
+    //section_body_3
+      LAYER+=0x5;
+
+    //close section 00 00 00 00 0A
+      LAYER+=sec_size+(sec_size>0?0x1:0);
+
+      if(0==strcmp(sec_name,"__LayerInfoStorage"))
+        break;
+
+    }
+    LAYER+=0x5;
+    unsigned char h;
+    short w;
+
+    fseek(f,LAYER,SEEK_SET);
+    fread(&sec_size,4,1,f);
+    if(IsBigEndian()) SwapBytes(sec_size);
+    if(sec_size==0x1E7)//check layer is not empty
+    {
+      while(1)
+      {
+        LAYER+=0x5;
+
+        graphCurve curve;
+
+        vector<string> col;
+        fseek(f,LAYER+0x4,SEEK_SET);
+        fread(&w,2,1,f);
+        if(IsBigEndian()) SwapBytes(w);
+        col=findDataByIndex(w-1);
+        short nColY = w;
+        if(col.size()>0)
+        {
+          fprintf(debug,"     GRAPH %d layer %d curve %d Y : %s.%s\n",GRAPH.size(),GRAPH.back().layer.size(),GRAPH.back().layer.back().curve.size(),col[1].c_str(),col[0].c_str());
+          fflush(debug);
+          curve.yColName=col[0];
+          curve.dataName=col[1];
+        }
+
+        fseek(f,LAYER+0x23,SEEK_SET);
+        fread(&w,2,1,f);
+        if(IsBigEndian()) SwapBytes(w);
+        col=findDataByIndex(w-1);
+        if(col.size()>0)
+        {
+          fprintf(debug,"     GRAPH %d layer %d curve %d X : %s.%s\n",GRAPH.size(),GRAPH.back().layer.size(),GRAPH.back().layer.back().curve.size(),col[1].c_str(),col[0].c_str());
+          fflush(debug);
+          curve.xColName=col[0];
+          if(curve.dataName!=col[1])
+            fprintf(debug,"     GRAPH %d X and Y from different tables\n",GRAPH.size());
+        }
+
+        fseek(f,LAYER+0x4C,SEEK_SET);
+        fread(&h,1,1,f);
+        curve.type=h;
+
+        fseek(f,LAYER+0x11,SEEK_SET);
+        fread(&h,1,1,f);
+        curve.line_connect=h;
+
+        fseek(f,LAYER+0x12,SEEK_SET);
+        fread(&h,1,1,f);
+        curve.line_style=h;
+
+        fseek(f,LAYER+0x15,SEEK_SET);
+        fread(&w,2,1,f);
+        if(IsBigEndian()) SwapBytes(w);
+        curve.line_width=(double)w/500.0;
+
+        fseek(f,LAYER+0x19,SEEK_SET);
+        fread(&w,2,1,f);
+        if(IsBigEndian()) SwapBytes(w);
+        curve.symbol_size=(double)w/500.0;
+
+        fseek(f,LAYER+0x1C,SEEK_SET);
+        fread(&h,1,1,f);
+        curve.fillarea=(h==2?true:false);
+
+        fseek(f,LAYER+0x1E,SEEK_SET);
+        fread(&h,1,1,f);
+        curve.fillarea_type=h;
+
+        //vector
+        if(curve.type == FlowVector || curve.type == Vector)
+        {
+          fseek(f,LAYER+0x56,SEEK_SET);
+          fread(&curve.vector.multiplier,4,1,f);
+          if(IsBigEndian()) SwapBytes(curve.vector.multiplier);
+
+          fseek(f,LAYER+0x5E,SEEK_SET);
+          fread(&h,1,1,f);
+          col=findDataByIndex(nColY - 1 + h - 0x64);
+          if(col.size()>0)
+          {
+            curve.vector.endXColName = col[0];
+          }
+
+          fseek(f,LAYER+0x62,SEEK_SET);
+          fread(&h,1,1,f);
+          col=findDataByIndex(nColY - 1 + h - 0x64);
+          if(col.size()>0)
+          {
+            curve.vector.endYColName = col[0];
+          }
+
+          fseek(f,LAYER+0x18,SEEK_SET);
+          fread(&h,1,1,f);
+          if(h >= 0x64)
+          {
+            col=findDataByIndex(nColY - 1 + h - 0x64);
+            if(col.size()>0)
+              curve.vector.angleColName = col[0];
+          }
+          else if(h <= 0x08)
+          {
+            curve.vector.const_angle = 45*h;
+          }
+
+          fseek(f,LAYER+0x19,SEEK_SET);
+          fread(&h,1,1,f);
+          if(h >= 0x64 && h < 0x1F4)
+          {
+            col=findDataByIndex(nColY - 1 + h - 0x64);
+            if(col.size()>0)
+              curve.vector.magnitudeColName = col[0];
+          }
+          else
+          {
+            curve.vector.const_magnitude = static_cast<int>(curve.symbol_size);
+          }
+
+          fseek(f,LAYER+0x66,SEEK_SET);
+          fread(&curve.vector.arrow_lenght,2,1,f);
+          if(IsBigEndian()) SwapBytes(curve.vector.arrow_lenght);
+
+          fread(&curve.vector.arrow_angle,1,1,f);
+
+          fread(&h,1,1,f);
+          curve.vector.arrow_closed = !(h&0x1);
+
+          fread(&w,2,1,f);
+          if(IsBigEndian()) SwapBytes(w);
+          curve.vector.width=(double)w/500.0;
+
+          fseek(f,LAYER+0x142,SEEK_SET);
+          fread(&h,1,1,f);
+          switch(h)
+          {
+          case 2:
+            curve.vector.position = Midpoint;
+            break;
+          case 4:
+            curve.vector.position = Head;
+              break;
+          default:
+            curve.vector.position = Tail;
+              break;
+          }
+          
+        }
+
+        //pie
+        if(curve.type == Pie)
+        {
+          fseek(f,LAYER+0x92,SEEK_SET);
+          fread(&h,1,1,f);
+          curve.pie.format_percentages = (h&0x01);
+          curve.pie.format_values = (h&0x02);
+          curve.pie.position_associate = (h&0x08);
+          curve.pie.clockwise_rotation = (h&0x20);
+          curve.pie.format_categories = (h&0x80);
+
+          fread(&h,1,1,f);
+          curve.pie.format_automatic = h;
+
+          fread(&curve.pie.distance,2,1,f);
+          if(IsBigEndian()) SwapBytes(curve.pie.distance);
+
+          fread(&curve.pie.view_angle,1,1,f);
+
+          fseek(f,LAYER+0x98,SEEK_SET);
+          fread(&curve.pie.thickness,1,1,f);
+
+          fseek(f,LAYER+0x9A,SEEK_SET);
+          fread(&curve.pie.rotation,2,1,f);
+          if(IsBigEndian()) SwapBytes(curve.pie.rotation);
+
+          fseek(f,LAYER+0x9E,SEEK_SET);
+          fread(&curve.pie.displacement,2,1,f);
+          if(IsBigEndian()) SwapBytes(curve.pie.displacement);
+
+          fseek(f,LAYER+0xA0,SEEK_SET);
+          fread(&curve.pie.radius,2,1,f);
+          if(IsBigEndian()) SwapBytes(curve.pie.radius);
+
+          fseek(f,LAYER+0xA2,SEEK_SET);
+          fread(&curve.pie.horizontal_offset,2,1,f);
+          if(IsBigEndian()) SwapBytes(curve.pie.horizontal_offset);
+
+          fseek(f,LAYER+0xA6,SEEK_SET);
+          fread(&curve.pie.displaced_sections,4,1,f);
+          if(IsBigEndian()) SwapBytes(curve.pie.displaced_sections);
+        }
+        
+        fseek(f,LAYER+0xC2,SEEK_SET);
+        fread(&h,1,1,f);
+        curve.fillarea_color=h;
+
+        fseek(f,LAYER+0xC3,SEEK_SET);
+        fread(&h,1,1,f);
+        curve.fillarea_first_color=h;
+
+        fseek(f,LAYER+0xCE,SEEK_SET);
+        fread(&h,1,1,f);
+        curve.fillarea_pattern=h;
+
+        fseek(f,LAYER+0xCA,SEEK_SET);
+        fread(&h,1,1,f);
+        curve.fillarea_pattern_color=h;
+
+        fseek(f,LAYER+0xC6,SEEK_SET);
+        fread(&w,2,1,f);
+        if(IsBigEndian()) SwapBytes(w);
+        curve.fillarea_pattern_width=(double)w/500.0;
+
+        fseek(f,LAYER+0xCF,SEEK_SET);
+        fread(&h,1,1,f);
+        curve.fillarea_pattern_border_style=h;
+
+        fseek(f,LAYER+0xD2,SEEK_SET);
+        fread(&h,1,1,f);
+        curve.fillarea_pattern_border_color=h;
+
+        fseek(f,LAYER+0xD0,SEEK_SET);
+        fread(&w,2,1,f);
+        if(IsBigEndian()) SwapBytes(w);
+        curve.fillarea_pattern_border_width=(double)w/500.0;
+
+        fseek(f,LAYER+0x16A,SEEK_SET);
+        fread(&h,1,1,f);
+        curve.line_color=h;
+
+        fseek(f,LAYER+0x17,SEEK_SET);
+        fread(&w,2,1,f);
+        if(IsBigEndian()) SwapBytes(w);
+        curve.symbol_type=w;
+
+        fseek(f,LAYER+0x12E,SEEK_SET);
+        fread(&h,1,1,f);
+        curve.symbol_fill_color=h;
+
+        fseek(f,LAYER+0x132,SEEK_SET);
+        fread(&h,1,1,f);
+        curve.symbol_color=h;
+        curve.vector.color=h;
+
+        fseek(f,LAYER+0x136,SEEK_SET);
+        fread(&h,1,1,f);
+        curve.symbol_thickness=(h==255?1:h);
+
+        fseek(f,LAYER+0x137,SEEK_SET);
+        fread(&h,1,1,f);
+        curve.point_offset=h;
+
+        GRAPH.back().layer.back().curve.push_back(curve);
+
+        LAYER+=0x1E7+0x1;
+        fseek(f,LAYER,SEEK_SET);
+        int comm_size=0;
+        fread(&comm_size,4,1,f);
+        if(IsBigEndian()) SwapBytes(comm_size);
+        LAYER+=0x5;
+        if(comm_size>0)
+        {
+          LAYER+=comm_size+0x1;
+        }
+        fseek(f,LAYER,SEEK_SET);
+        int ntmp;
+        fread(&ntmp,4,1,f);
+        if(IsBigEndian()) SwapBytes(ntmp);
+        if(ntmp!=0x1E7)
+          break;
+      }
+
+    }
+    //LAYER+=0x5*0x5+0x1ED*0x12;
+    //LAYER+=2*0x5;
+
+    LAYER+=0x5;
+    //read axis breaks
+    while(1)
+    {
+      fseek(f,LAYER,SEEK_SET);
+      fread(&sec_size,4,1,f);
+      if(IsBigEndian()) SwapBytes(sec_size);
+      if(sec_size == 0x2D)
+      {
+        LAYER+=0x5;
+        fseek(f,LAYER+2,SEEK_SET);
+        fread(&h,1,1,f);
+        if(h==2)
+        {
+          GRAPH.back().layer.back().xAxisBreak.minor_ticks_before = (unsigned char)(GRAPH.back().layer.back().xAxis.minorTicks);
+          GRAPH.back().layer.back().xAxisBreak.scale_increment_before = GRAPH.back().layer.back().xAxis.step;
+          readGraphAxisBreakInfo(GRAPH.back().layer.back().xAxisBreak, f, LAYER);
+        }
+        else if(h==4)
+        {
+          GRAPH.back().layer.back().yAxisBreak.minor_ticks_before = (unsigned char)(GRAPH.back().layer.back().yAxis.minorTicks);
+          GRAPH.back().layer.back().yAxisBreak.scale_increment_before = GRAPH.back().layer.back().yAxis.step;
+          readGraphAxisBreakInfo(GRAPH.back().layer.back().yAxisBreak, f, LAYER);
+        }
+        LAYER+=0x2D + 0x1;
+      }
+      else
+        break;
+    }
+    LAYER+=0x5;
+    
+
+    LAYER+=0x5;
+    readGraphGridInfo(GRAPH.back().layer.back().xAxis.minorGrid, f, LAYER);
+    LAYER+=0x1E7+1;
+
+    LAYER+=0x5;
+    readGraphGridInfo(GRAPH.back().layer.back().xAxis.majorGrid, f, LAYER);
+    LAYER+=0x1E7+1;
+
+    LAYER+=0x5;
+    readGraphAxisTickLabelsInfo(GRAPH.back().layer.back().xAxis.tickAxis[0], f, LAYER);
+    LAYER+=0x1E7+1;
+
+    LAYER+=0x5;
+    readGraphAxisFormatInfo(GRAPH.back().layer.back().xAxis.formatAxis[0], f, LAYER);
+    LAYER+=0x1E7+1;
+
+    LAYER+=0x5;
+    readGraphAxisTickLabelsInfo(GRAPH.back().layer.back().xAxis.tickAxis[1], f, LAYER);
+    LAYER+=0x1E7+1;
+
+    LAYER+=0x5;
+    readGraphAxisFormatInfo(GRAPH.back().layer.back().xAxis.formatAxis[1], f, LAYER);
+    LAYER+=0x1E7+1;
+
+    LAYER+=0x5;
+
+
+    LAYER+=0x5;
+    readGraphGridInfo(GRAPH.back().layer.back().yAxis.minorGrid, f, LAYER);
+    LAYER+=0x1E7+1;
+
+    LAYER+=0x5;
+    readGraphGridInfo(GRAPH.back().layer.back().yAxis.majorGrid, f, LAYER);
+    LAYER+=0x1E7+1;
+
+    LAYER+=0x5;
+    readGraphAxisTickLabelsInfo(GRAPH.back().layer.back().yAxis.tickAxis[0], f, LAYER);
+    LAYER+=0x1E7+1;
+
+    LAYER+=0x5;
+    readGraphAxisFormatInfo(GRAPH.back().layer.back().yAxis.formatAxis[0], f, LAYER);
+    LAYER+=0x1E7+1;
+
+    LAYER+=0x5;
+    readGraphAxisTickLabelsInfo(GRAPH.back().layer.back().yAxis.tickAxis[1], f, LAYER);
+    LAYER+=0x1E7+1;
+
+    LAYER+=0x5;
+    readGraphAxisFormatInfo(GRAPH.back().layer.back().yAxis.formatAxis[1], f, LAYER);
+    LAYER+=0x1E7+1;
+
+    LAYER+=0x2*0x5+0x1ED*0x6;
+
+    fseek(f,LAYER,SEEK_SET);
+    fread(&sec_size,4,1,f);
+    if(IsBigEndian()) SwapBytes(sec_size);
+    if(sec_size==0)
+      break;
+  }
+  POS = LAYER+0x5;
+
+  fseek(f,POS,SEEK_SET);
 }
 
 void OPJFile::skipObjectInfo(FILE *f, FILE *)
 {
-	int POS=int(ftell(f));
-
-	int headersize;
-	fread(&headersize,4,1,f);
-	if(IsBigEndian()) SwapBytes(headersize);
-	POS+=5;
-
-	int LAYER = POS;
-	LAYER += headersize + 0x1;
-	int sec_size;
-	while(1)// multilayer loop
-	{
-		// LAYER section
-		LAYER +=0x5/* length of block = 0x12D + '\n'*/ + 0x12D + 0x1;
-		//now structure is next : section_header_size=0x6F(4 bytes) + '\n' + section_header(0x6F bytes) + section_body_1_size(4 bytes) + '\n' + section_body_1 + section_body_2_size(maybe=0)(4 bytes) + '\n' + section_body_2 + '\n'
-		//possible sections: column formulas, __WIPR, __WIOTN, __LayerInfoStorage
-		//section name(column name in formula case) starts with 0x46 position
-		while(1)
-		{
-		//section_header_size=0x6F(4 bytes) + '\n'
-			LAYER+=0x5;
-
-		//section_header
-			fseek(f,LAYER+0x46,SEEK_SET);
-			char sec_name[42];
-			sec_name[41]='\0';
-			fread(&sec_name,41,1,f);
-
-		//section_body_1_size
-			LAYER+=0x6F+0x1;
-			fseek(f,LAYER,SEEK_SET);
-			fread(&sec_size,4,1,f);
-			if(IsBigEndian()) SwapBytes(sec_size);
-
-		//section_body_1
-			LAYER+=0x5;
-
-		//section_body_2_size
-			LAYER+=sec_size+0x1;
-			fseek(f,LAYER,SEEK_SET);
-			fread(&sec_size,4,1,f);
-			if(IsBigEndian()) SwapBytes(sec_size);
-
-		//section_body_2
-			LAYER+=0x5;
-
-		//close section 00 00 00 00 0A
-			LAYER+=sec_size+(sec_size>0?0x1:0);
-
-		//section_body_3_size
-			fseek(f,LAYER,SEEK_SET);
-			fread(&sec_size,4,1,f);
-			if(IsBigEndian()) SwapBytes(sec_size);
-
-		//section_body_3
-			LAYER+=0x5;
-
-		//close section 00 00 00 00 0A
-			LAYER+=sec_size+(sec_size>0?0x1:0);
-
-			if(0==strcmp(sec_name,"__LayerInfoStorage"))
-				break;
-
-		}
-		LAYER+=0x5;
-
-		while(1)
-		{
-			LAYER+=0x5;
-
-			LAYER+=0x1E7+0x1;
-			fseek(f,LAYER,SEEK_SET);
-			int comm_size=0;
-			fread(&comm_size,4,1,f);
-			if(IsBigEndian()) SwapBytes(comm_size);
-			LAYER+=0x5;
-			if(comm_size>0)
-			{
-				LAYER+=comm_size+0x1;
-			}
-			fseek(f,LAYER,SEEK_SET);
-			int ntmp;
-			fread(&ntmp,4,1,f);
-			if(IsBigEndian()) SwapBytes(ntmp);
-			if(ntmp!=0x1E7)
-				break;
-		}
-
-		LAYER+=0x5*0x5+0x1ED*0x12;
-		fseek(f,LAYER,SEEK_SET);
-		fread(&sec_size,4,1,f);
-		if(IsBigEndian()) SwapBytes(sec_size);
-		if(sec_size==0)
-			break;
-	}
-	POS = LAYER+0x5;
-
-	fseek(f,POS,SEEK_SET);
+  int POS=int(ftell(f));
+
+  int headersize;
+  fread(&headersize,4,1,f);
+  if(IsBigEndian()) SwapBytes(headersize);
+  POS+=5;
+
+  int LAYER = POS;
+  LAYER += headersize + 0x1;
+  int sec_size;
+  while(1)// multilayer loop
+  {
+    // LAYER section
+    LAYER +=0x5/* length of block = 0x12D + '\n'*/ + 0x12D + 0x1;
+    //now structure is next : section_header_size=0x6F(4 bytes) + '\n' + section_header(0x6F bytes) + section_body_1_size(4 bytes) + '\n' + section_body_1 + section_body_2_size(maybe=0)(4 bytes) + '\n' + section_body_2 + '\n'
+    //possible sections: column formulas, __WIPR, __WIOTN, __LayerInfoStorage
+    //section name(column name in formula case) starts with 0x46 position
+    while(1)
+    {
+    //section_header_size=0x6F(4 bytes) + '\n'
+      LAYER+=0x5;
+
+    //section_header
+      fseek(f,LAYER+0x46,SEEK_SET);
+      char sec_name[42];
+      sec_name[41]='\0';
+      fread(&sec_name,41,1,f);
+
+    //section_body_1_size
+      LAYER+=0x6F+0x1;
+      fseek(f,LAYER,SEEK_SET);
+      fread(&sec_size,4,1,f);
+      if(IsBigEndian()) SwapBytes(sec_size);
+
+    //section_body_1
+      LAYER+=0x5;
+
+    //section_body_2_size
+      LAYER+=sec_size+0x1;
+      fseek(f,LAYER,SEEK_SET);
+      fread(&sec_size,4,1,f);
+      if(IsBigEndian()) SwapBytes(sec_size);
+
+    //section_body_2
+      LAYER+=0x5;
+
+    //close section 00 00 00 00 0A
+      LAYER+=sec_size+(sec_size>0?0x1:0);
+
+    //section_body_3_size
+      fseek(f,LAYER,SEEK_SET);
+      fread(&sec_size,4,1,f);
+      if(IsBigEndian()) SwapBytes(sec_size);
+
+    //section_body_3
+      LAYER+=0x5;
+
+    //close section 00 00 00 00 0A
+      LAYER+=sec_size+(sec_size>0?0x1:0);
+
+      if(0==strcmp(sec_name,"__LayerInfoStorage"))
+        break;
+
+    }
+    LAYER+=0x5;
+
+    while(1)
+    {
+      LAYER+=0x5;
+
+      LAYER+=0x1E7+0x1;
+      fseek(f,LAYER,SEEK_SET);
+      int comm_size=0;
+      fread(&comm_size,4,1,f);
+      if(IsBigEndian()) SwapBytes(comm_size);
+      LAYER+=0x5;
+      if(comm_size>0)
+      {
+        LAYER+=comm_size+0x1;
+      }
+      fseek(f,LAYER,SEEK_SET);
+      int ntmp;
+      fread(&ntmp,4,1,f);
+      if(IsBigEndian()) SwapBytes(ntmp);
+      if(ntmp!=0x1E7)
+        break;
+    }
+
+    LAYER+=0x5*0x5+0x1ED*0x12;
+    fseek(f,LAYER,SEEK_SET);
+    fread(&sec_size,4,1,f);
+    if(IsBigEndian()) SwapBytes(sec_size);
+    if(sec_size==0)
+      break;
+  }
+  POS = LAYER+0x5;
+
+  fseek(f,POS,SEEK_SET);
 }
 
 void OPJFile::readGraphGridInfo(graphGrid &grid, FILE *f, int pos)
 {
-	unsigned char h;
-	short w;
-	fseek(f,pos+0x26,SEEK_SET);
-	fread(&h,1,1,f);
-	grid.hidden=(h==0);
+  unsigned char h;
+  short w;
+  fseek(f,pos+0x26,SEEK_SET);
+  fread(&h,1,1,f);
+  grid.hidden=(h==0);
 
-	fseek(f,pos+0xF,SEEK_SET);
-	fread(&h,1,1,f);
-	grid.color=h;
+  fseek(f,pos+0xF,SEEK_SET);
+  fread(&h,1,1,f);
+  grid.color=h;
 
 
-	fseek(f,pos+0x12,SEEK_SET);
-	fread(&h,1,1,f);
-	grid.style=h;
+  fseek(f,pos+0x12,SEEK_SET);
+  fread(&h,1,1,f);
+  grid.style=h;
 
-	fseek(f,pos+0x15,SEEK_SET);
-	fread(&w,2,1,f);
-	if(IsBigEndian()) SwapBytes(w);
-	grid.width=(double)w/500.0;
+  fseek(f,pos+0x15,SEEK_SET);
+  fread(&w,2,1,f);
+  if(IsBigEndian()) SwapBytes(w);
+  grid.width=(double)w/500.0;
 }
 
 void OPJFile::readGraphAxisBreakInfo(graphAxisBreak &axis_break, FILE *f, int pos)
 {
-	axis_break.show=true;
+  axis_break.show=true;
 
-	fseek(f,pos+0x0B,SEEK_SET);
-	fread(&axis_break.from,8,1,f);
-	if(IsBigEndian()) SwapBytes(axis_break.from);
-	
-	fread(&axis_break.to,8,1,f);
-	if(IsBigEndian()) SwapBytes(axis_break.to);
+  fseek(f,pos+0x0B,SEEK_SET);
+  fread(&axis_break.from,8,1,f);
+  if(IsBigEndian()) SwapBytes(axis_break.from);
+  
+  fread(&axis_break.to,8,1,f);
+  if(IsBigEndian()) SwapBytes(axis_break.to);
 
-	fread(&axis_break.scale_increment_after,8,1,f);
-	if(IsBigEndian()) SwapBytes(axis_break.scale_increment_after);
+  fread(&axis_break.scale_increment_after,8,1,f);
+  if(IsBigEndian()) SwapBytes(axis_break.scale_increment_after);
 
-	double position=0.0;
-	fread(&position,8,1,f);
-	if(IsBigEndian()) SwapBytes(position);
-	axis_break.position=(int)position;
+  double position=0.0;
+  fread(&position,8,1,f);
+  if(IsBigEndian()) SwapBytes(position);
+  axis_break.position=(int)position;
 
-	unsigned char h;
-	fread(&h,1,1,f);
-	axis_break.log10=(h==1);
+  unsigned char h;
+  fread(&h,1,1,f);
+  axis_break.log10=(h==1);
 
-	fread(&axis_break.minor_ticks_after,1,1,f);
+  fread(&axis_break.minor_ticks_after,1,1,f);
 }
 
 void OPJFile::readGraphAxisFormatInfo(graphAxisFormat &format, FILE *f, int pos)
 {
-	unsigned char h;
-	short w;
-	double p;
-	fseek(f,pos+0x26,SEEK_SET);
-	fread(&h,1,1,f);
-	format.hidden=(h==0);
-
-	fseek(f,pos+0xF,SEEK_SET);
-	fread(&h,1,1,f);
-	format.color=h;
-
-	fseek(f,pos+0x4A,SEEK_SET);
-	fread(&w,2,1,f);
-	if(IsBigEndian()) SwapBytes(w);
-	format.majorTickLength=(double)w/10.0;
-
-	fseek(f,pos+0x15,SEEK_SET);
-	fread(&w,2,1,f);
-	if(IsBigEndian()) SwapBytes(w);
-	format.thickness=(double)w/500.0;
-
-	fseek(f,pos+0x25,SEEK_SET);
-	fread(&h,1,1,f);
-	format.minorTicksType=(h>>6);
-	format.majorTicksType=((h>>4)&3);
-	format.axisPosition=(h&0xF);
-	switch(format.axisPosition)
-	{
-		case 1:
-			fseek(f,pos+0x37,SEEK_SET);
-			fread(&h,1,1,f);
-			format.axisPositionValue=(double)h;
-			break;
-		case 2:
-			fseek(f,pos+0x2F,SEEK_SET);
-			fread(&p,8,1,f);
-			if(IsBigEndian()) SwapBytes(p);
-			format.axisPositionValue=p;
-			break;
-	}
+  unsigned char h;
+  short w;
+  double p;
+  fseek(f,pos+0x26,SEEK_SET);
+  fread(&h,1,1,f);
+  format.hidden=(h==0);
+
+  fseek(f,pos+0xF,SEEK_SET);
+  fread(&h,1,1,f);
+  format.color=h;
+
+  fseek(f,pos+0x4A,SEEK_SET);
+  fread(&w,2,1,f);
+  if(IsBigEndian()) SwapBytes(w);
+  format.majorTickLength=(double)w/10.0;
+
+  fseek(f,pos+0x15,SEEK_SET);
+  fread(&w,2,1,f);
+  if(IsBigEndian()) SwapBytes(w);
+  format.thickness=(double)w/500.0;
+
+  fseek(f,pos+0x25,SEEK_SET);
+  fread(&h,1,1,f);
+  format.minorTicksType=(h>>6);
+  format.majorTicksType=((h>>4)&3);
+  format.axisPosition=(h&0xF);
+  switch(format.axisPosition)
+  {
+    case 1:
+      fseek(f,pos+0x37,SEEK_SET);
+      fread(&h,1,1,f);
+      format.axisPositionValue=(double)h;
+      break;
+    case 2:
+      fseek(f,pos+0x2F,SEEK_SET);
+      fread(&p,8,1,f);
+      if(IsBigEndian()) SwapBytes(p);
+      format.axisPositionValue=p;
+      break;
+  }
 }
 
 void OPJFile::readGraphAxisTickLabelsInfo(graphAxisTick &tick, FILE *f, int pos) {
-	unsigned char h;
-	unsigned char h1;
-	short w;
-	fseek(f,pos+0x26,SEEK_SET);
-	fread(&h,1,1,f);
-	tick.hidden=(h==0);
-
-	fseek(f,pos+0xF,SEEK_SET);
-	fread(&h,1,1,f);
-	tick.color=h;
-
-	fseek(f,pos+0x13,SEEK_SET);
-	fread(&w,2,1,f);
-	if(IsBigEndian()) SwapBytes(w);
-	tick.rotation=w/10;
-
-	fseek(f,pos+0x15,SEEK_SET);
-	fread(&w,2,1,f);
-	if(IsBigEndian()) SwapBytes(w);
-	tick.fontsize=w;
-
-	fseek(f,pos+0x1A,SEEK_SET);
-	fread(&h,1,1,f);
-	tick.fontbold=(h&0x8);
-
-	fseek(f,pos+0x23,SEEK_SET);
-	fread(&w,2,1,f);
-	if(IsBigEndian()) SwapBytes(w);
-
-	fseek(f,pos+0x25,SEEK_SET);
-	fread(&h,1,1,f);
-	fread(&h1,1,1,f);
-	tick.value_type=(h&0xF);
-
-	vector<string> col;
-	switch(tick.value_type)
-	{
-	case 0: //Numeric
-
-		/*switch((h>>4))
-		{
-			case 0x9:
-				tick.value_type_specification=1;
-				break;
-			case 0xA:
-				tick.value_type_specification=2;
-				break;
-			case 0xB:
-				tick.value_type_specification=3;
-				break;
-			default:
-				tick.value_type_specification=0;
-		}*/
-		if((h>>4)>7)
-		{
-			tick.value_type_specification=(h>>4)-8;
-			tick.decimal_places=h1-0x40;
-		}
-		else
-		{
-			tick.value_type_specification=(h>>4);
-			tick.decimal_places=-1;
-		}
-
-		break;
-	case 2: // Time
-	case 3: // Date
-	case 4: // Month
-	case 5: // Day
-	case 6: // Column heading
-		tick.value_type_specification=h1-0x40;
-		break;
-	case 1: // Text
-	case 7: // Tick-indexed dataset
-	case 10: // Categorical
-		col=findDataByIndex(w-1);
-		if(col.size()>0)
-		{
-			tick.colName=col[0];
-			tick.dataName=col[1];
-		}
-		break;
-	default: // Numeric Decimal 1.000
-		tick.value_type=Numeric;
-		tick.value_type_specification=0;
-		break;
-	}
+  unsigned char h;
+  unsigned char h1;
+  short w;
+  fseek(f,pos+0x26,SEEK_SET);
+  fread(&h,1,1,f);
+  tick.hidden=(h==0);
+
+  fseek(f,pos+0xF,SEEK_SET);
+  fread(&h,1,1,f);
+  tick.color=h;
+
+  fseek(f,pos+0x13,SEEK_SET);
+  fread(&w,2,1,f);
+  if(IsBigEndian()) SwapBytes(w);
+  tick.rotation=w/10;
+
+  fseek(f,pos+0x15,SEEK_SET);
+  fread(&w,2,1,f);
+  if(IsBigEndian()) SwapBytes(w);
+  tick.fontsize=w;
+
+  fseek(f,pos+0x1A,SEEK_SET);
+  fread(&h,1,1,f);
+  tick.fontbold=(h&0x8);
+
+  fseek(f,pos+0x23,SEEK_SET);
+  fread(&w,2,1,f);
+  if(IsBigEndian()) SwapBytes(w);
+
+  fseek(f,pos+0x25,SEEK_SET);
+  fread(&h,1,1,f);
+  fread(&h1,1,1,f);
+  tick.value_type=(h&0xF);
+
+  vector<string> col;
+  switch(tick.value_type)
+  {
+  case 0: //Numeric
+
+    /*switch((h>>4))
+    {
+      case 0x9:
+        tick.value_type_specification=1;
+        break;
+      case 0xA:
+        tick.value_type_specification=2;
+        break;
+      case 0xB:
+        tick.value_type_specification=3;
+        break;
+      default:
+        tick.value_type_specification=0;
+    }*/
+    if((h>>4)>7)
+    {
+      tick.value_type_specification=(h>>4)-8;
+      tick.decimal_places=h1-0x40;
+    }
+    else
+    {
+      tick.value_type_specification=(h>>4);
+      tick.decimal_places=-1;
+    }
+
+    break;
+  case 2: // Time
+  case 3: // Date
+  case 4: // Month
+  case 5: // Day
+  case 6: // Column heading
+    tick.value_type_specification=h1-0x40;
+    break;
+  case 1: // Text
+  case 7: // Tick-indexed dataset
+  case 10: // Categorical
+    col=findDataByIndex(w-1);
+    if(col.size()>0)
+    {
+      tick.colName=col[0];
+      tick.dataName=col[1];
+    }
+    break;
+  default: // Numeric Decimal 1.000
+    tick.value_type=Numeric;
+    tick.value_type_specification=0;
+    break;
+  }
 }
 
 void OPJFile::readProjectTree(FILE *f, FILE *debug)
 {
-	readProjectTreeFolder(f, debug, projectTree.begin());
+  readProjectTreeFolder(f, debug, projectTree.begin());
 
-	fprintf(debug,"Origin project Tree\n");
-	tree<projectNode>::iterator sib2=projectTree.begin(projectTree.begin());
+  fprintf(debug,"Origin project Tree\n");
+  tree<projectNode>::iterator sib2=projectTree.begin(projectTree.begin());
     tree<projectNode>::iterator end2=projectTree.end(projectTree.begin());
     while(sib2!=end2)
-	{
+  {
         for(int i=0; i<projectTree.depth(sib2)-1; ++i)
-			fprintf(debug," ");
-		fprintf(debug,"%s\n",(*sib2).name.c_str());
+      fprintf(debug," ");
+    fprintf(debug,"%s\n",(*sib2).name.c_str());
         ++sib2;
     }
-	fflush(debug);
+  fflush(debug);
 }
 
 void OPJFile::readProjectTreeFolder(FILE *f, FILE *debug, tree<projectNode>::iterator parent)
 {
-	int POS=int(ftell(f));
-
-	double creation_date, modification_date;
-
-	POS+=5;
-	fseek(f,POS+0x10,SEEK_SET);
-	fread(&creation_date,8,1,f);
-	if(IsBigEndian()) SwapBytes(creation_date);
-
-	fread(&modification_date,8,1,f);
-	if(IsBigEndian()) SwapBytes(modification_date);
-
-	POS+=0x20+1+5;
-	fseek(f,POS,SEEK_SET);
-
-	int namesize;
-	fread(&namesize,4,1,f);
-	if(IsBigEndian()) SwapBytes(namesize);
-
-	POS+=5;
-
-	// read folder name
-	char* name=new char[namesize+1];
-	name[namesize]='\0';
-	fseek(f,POS,SEEK_SET);
-	fread(name,namesize,1,f);
-	tree<projectNode>::iterator current_folder=projectTree.append_child(parent, projectNode(name, 1, creation_date, modification_date));
-	POS+=namesize+1+5+5;
-
-	int objectcount;
-	fseek(f,POS,SEEK_SET);
-	fread(&objectcount,4,1,f);
-	if(IsBigEndian()) SwapBytes(objectcount);
-	POS+=5+5;
-
-	for(int i=0; i<objectcount; ++i)
-	{
-		POS+=5;
-		char c;
-		fseek(f,POS+0x2,SEEK_SET);
-		fread(&c,1,1,f);
-		int objectID;
-		fseek(f,POS+0x4,SEEK_SET);
-		fread(&objectID,4,1,f);
-		if(IsBigEndian()) SwapBytes(objectID);
-		if(c==0x10)
-		{
-			projectTree.append_child(current_folder, projectNode(NOTE[objectID].name, 0));
-		}
-		else
-			projectTree.append_child(current_folder, projectNode(findObjectByIndex(objectID), 0));
-		POS+=8+1+5+5;
-	}
-	fseek(f,POS,SEEK_SET);
-	fread(&objectcount,4,1,f);
-	if(IsBigEndian()) SwapBytes(objectcount);
-	fseek(f,1,SEEK_CUR);
-	for(int i=0; i<objectcount; ++i)
-		readProjectTreeFolder(f, debug, current_folder);
+  int POS=int(ftell(f));
+
+  double creation_date, modification_date;
+
+  POS+=5;
+  fseek(f,POS+0x10,SEEK_SET);
+  fread(&creation_date,8,1,f);
+  if(IsBigEndian()) SwapBytes(creation_date);
+
+  fread(&modification_date,8,1,f);
+  if(IsBigEndian()) SwapBytes(modification_date);
+
+  POS+=0x20+1+5;
+  fseek(f,POS,SEEK_SET);
+
+  int namesize;
+  fread(&namesize,4,1,f);
+  if(IsBigEndian()) SwapBytes(namesize);
+
+  POS+=5;
+
+  // read folder name
+  char* name=new char[namesize+1];
+  name[namesize]='\0';
+  fseek(f,POS,SEEK_SET);
+  fread(name,namesize,1,f);
+  tree<projectNode>::iterator current_folder=projectTree.append_child(parent, projectNode(name, 1, creation_date, modification_date));
+  POS+=namesize+1+5+5;
+
+  int objectcount;
+  fseek(f,POS,SEEK_SET);
+  fread(&objectcount,4,1,f);
+  if(IsBigEndian()) SwapBytes(objectcount);
+  POS+=5+5;
+
+  for(int i=0; i<objectcount; ++i)
+  {
+    POS+=5;
+    char c;
+    fseek(f,POS+0x2,SEEK_SET);
+    fread(&c,1,1,f);
+    int objectID;
+    fseek(f,POS+0x4,SEEK_SET);
+    fread(&objectID,4,1,f);
+    if(IsBigEndian()) SwapBytes(objectID);
+    if(c==0x10)
+    {
+      projectTree.append_child(current_folder, projectNode(NOTE[objectID].name, 0));
+    }
+    else
+      projectTree.append_child(current_folder, projectNode(findObjectByIndex(objectID), 0));
+    POS+=8+1+5+5;
+  }
+  fseek(f,POS,SEEK_SET);
+  fread(&objectcount,4,1,f);
+  if(IsBigEndian()) SwapBytes(objectcount);
+  fseek(f,1,SEEK_CUR);
+  for(int i=0; i<objectcount; ++i)
+    readProjectTreeFolder(f, debug, current_folder);
+  
+  delete [] name;
 }
 
 void OPJFile::readWindowProperties(originWindow& window, FILE *f, FILE *debug, int POS, int headersize)
 {
-	window.objectID=objectIndex;
-	objectIndex++;
-
-	fseek(f,POS + 0x1B,SEEK_SET);
-	fread(&window.clientRect,8,1,f);
-	if(IsBigEndian()) SwapBytes(window.clientRect);
-
-	char c;
-	fseek(f,POS + 0x32,SEEK_SET);
-	fread(&c,1,1,f);
-
-	if(c&0x01)
-		window.state = originWindow::Minimized;
-	else if(c&0x02)
-		window.state = originWindow::Maximized;
-
-	fseek(f,POS + 0x69,SEEK_SET);
-	fread(&c,1,1,f);
-
-	if(c&0x01)
-		window.title = originWindow::Label;
-	else if(c&0x02)
-		window.title = originWindow::Name;
-	else
-		window.title = originWindow::Both;
-
-	window.bHidden = (c&0x08);
-	if(window.bHidden)
-	{
-		fprintf(debug,"			WINDOW %d NAME : %s	is hidden\n", objectIndex, window.name.c_str());
-		fflush(debug);
-	}
-
-	fseek(f,POS + 0x73,SEEK_SET);
-	fread(&window.creation_date,8,1,f);
-	if(IsBigEndian()) SwapBytes(window.creation_date);
-
-	fread(&window.modification_date,8,1,f);
-	if(IsBigEndian()) SwapBytes(window.modification_date);
-	
-	if(headersize > 0xC3)
-	{
-		int labellen = 0;
-		fseek(f,POS + 0xC3,SEEK_SET);
-		fread(&c,1,1,f);
-		while (c != '@')
-		{
-			fread(&c,1,1,f);
-			labellen++;
-		}
-		if(labellen > 0)
-		{
-			char *label=new char[labellen+1];
-			label[labellen]='\0';
-			fseek(f,POS + 0xC3,SEEK_SET);
-			fread(label,labellen,1,f);
-			window.label=label;
-			delete [] label;
-		}
-		else
-			window.label="";
-		fprintf(debug,"			WINDOW %d LABEL: %s\n", objectIndex, window.label.c_str());
-		fflush(debug);
-	}
+  window.objectID=objectIndex;
+  objectIndex++;
+
+  fseek(f,POS + 0x1B,SEEK_SET);
+  fread(&window.clientRect,8,1,f);
+  if(IsBigEndian()) SwapBytes(window.clientRect);
+
+  char c;
+  fseek(f,POS + 0x32,SEEK_SET);
+  fread(&c,1,1,f);
+
+  if(c&0x01)
+    window.state = originWindow::Minimized;
+  else if(c&0x02)
+    window.state = originWindow::Maximized;
+
+  fseek(f,POS + 0x69,SEEK_SET);
+  fread(&c,1,1,f);
+
+  if(c&0x01)
+    window.title = originWindow::Label;
+  else if(c&0x02)
+    window.title = originWindow::Name;
+  else
+    window.title = originWindow::Both;
+
+  window.bHidden = (c&0x08);
+  if(window.bHidden)
+  {
+    fprintf(debug,"     WINDOW %d NAME : %s is hidden\n", objectIndex, window.name.c_str());
+    fflush(debug);
+  }
+
+  fseek(f,POS + 0x73,SEEK_SET);
+  fread(&window.creation_date,8,1,f);
+  if(IsBigEndian()) SwapBytes(window.creation_date);
+
+  fread(&window.modification_date,8,1,f);
+  if(IsBigEndian()) SwapBytes(window.modification_date);
+  
+  if(headersize > 0xC3)
+  {
+    int labellen = 0;
+    fseek(f,POS + 0xC3,SEEK_SET);
+    fread(&c,1,1,f);
+    while (c != '@')
+    {
+      fread(&c,1,1,f);
+      labellen++;
+    }
+    if(labellen > 0)
+    {
+      char *label=new char[labellen+1];
+      label[labellen]='\0';
+      fseek(f,POS + 0xC3,SEEK_SET);
+      fread(label,labellen,1,f);
+      window.label=label;
+      delete [] label;
+    }
+    else
+      window.label="";
+    fprintf(debug,"     WINDOW %d LABEL: %s\n", objectIndex, window.label.c_str());
+    fflush(debug);
+  }
 }
 bool OPJFile::IsBigEndian()
 {
diff --git a/Code/Mantid/MantidQt/API/inc/MantidQtAPI/WorkspaceObserver.h b/Code/Mantid/MantidQt/API/inc/MantidQtAPI/WorkspaceObserver.h
index c6cb58ffcf4e1cea70de606a126c328e9947ab84..768c92ee2f5607e0bb350aaf10f13c5cea747b0c 100644
--- a/Code/Mantid/MantidQt/API/inc/MantidQtAPI/WorkspaceObserver.h
+++ b/Code/Mantid/MantidQt/API/inc/MantidQtAPI/WorkspaceObserver.h
@@ -186,7 +186,7 @@ namespace MantidQt
       */
       void _preDeleteHandle(Mantid::API::WorkspacePreDeleteNotification_ptr pNf)
       {
-        m_proxy->preDeleteRequested(pNf->object_name(), pNf->object());
+        m_proxy->preDeleteRequested(pNf->objectName(), pNf->object());
       }
       /// Poco::NObserver for DataServise::DeleteNotification.
       Poco::NObserver<WorkspaceObserver, Mantid::API::WorkspacePreDeleteNotification> m_preDeleteObserver;
@@ -196,7 +196,7 @@ namespace MantidQt
       */
       void _postDeleteHandle(Mantid::API::WorkspacePostDeleteNotification_ptr pNf)
       {
-        m_proxy->postDeleteRequested(pNf->object_name());
+        m_proxy->postDeleteRequested(pNf->objectName());
       }
       /// Poco::NObserver for DataServise::DeleteNotification.
       Poco::NObserver<WorkspaceObserver, Mantid::API::WorkspacePostDeleteNotification> m_postDeleteObserver;
@@ -206,7 +206,7 @@ namespace MantidQt
       */
       void _addHandle(Mantid::API::WorkspaceAddNotification_ptr pNf)
       {
-        m_proxy->addRequested(pNf->object_name(), pNf->object());
+        m_proxy->addRequested(pNf->objectName(), pNf->object());
       }
       /// Poco::NObserver for DataServise::AddNotification.
       Poco::NObserver<WorkspaceObserver, Mantid::API::WorkspaceAddNotification> m_addObserver;
@@ -216,7 +216,7 @@ namespace MantidQt
       */
       void _afterReplaceHandle(Mantid::API::WorkspaceAfterReplaceNotification_ptr pNf)
       {
-        m_proxy->afterReplaced(pNf->object_name(), pNf->object());
+        m_proxy->afterReplaced(pNf->objectName(), pNf->object());
       }
       /// Poco::NObserver for DataServise::AfterReplaceNotification.
       Poco::NObserver<WorkspaceObserver, Mantid::API::WorkspaceAfterReplaceNotification> m_afterReplaceObserver;
@@ -226,7 +226,7 @@ namespace MantidQt
       */
       void _renameHandle(Mantid::API::WorkspaceRenameNotification_ptr pNf)
       {
-        m_proxy->renamed(pNf->object_name(), pNf->new_objectname());
+        m_proxy->renamed(pNf->objectName(), pNf->newObjectName());
       }
       /// Poco::NObserver for DataServise::RenameNotification.
       Poco::NObserver<WorkspaceObserver, Mantid::API::WorkspaceRenameNotification> m_renameObserver;
diff --git a/Code/Mantid/MantidQt/API/src/AlgorithmDialog.cpp b/Code/Mantid/MantidQt/API/src/AlgorithmDialog.cpp
index 58104745db7e5438695e4147065d87c6b9fb8c15..21d06a50739dbfaeab580ec8f752431fa5a9e55d 100644
--- a/Code/Mantid/MantidQt/API/src/AlgorithmDialog.cpp
+++ b/Code/Mantid/MantidQt/API/src/AlgorithmDialog.cpp
@@ -610,9 +610,9 @@ void AlgorithmDialog::fillAndSetComboBox(const QString & propName, QComboBox* op
   Mantid::Kernel::Property *property = getAlgorithmProperty(propName);
   if( !property ) return;
 
-  std::set<std::string> items = property->allowedValues();
-  std::set<std::string>::const_iterator vend = items.end();
-  for(std::set<std::string>::const_iterator vitr = items.begin(); vitr != vend;
+  std::vector<std::string> items = property->allowedValues();
+  std::vector<std::string>::const_iterator vend = items.end();
+  for(std::vector<std::string>::const_iterator vitr = items.begin(); vitr != vend;
       ++vitr)
   {
     optionsBox->addItem(QString::fromStdString(*vitr));
diff --git a/Code/Mantid/MantidQt/API/src/FilePropertyWidget.cpp b/Code/Mantid/MantidQt/API/src/FilePropertyWidget.cpp
index 8cb24dd914ec7435cf1b57fa0d83d7dc965fa9d2..4ff4b79bbeb0e848084d4123265a3be3479466e2 100644
--- a/Code/Mantid/MantidQt/API/src/FilePropertyWidget.cpp
+++ b/Code/Mantid/MantidQt/API/src/FilePropertyWidget.cpp
@@ -98,7 +98,7 @@ namespace API
    * @param defaultExt :: default extension to use
    * @return a string that filters files by extenstions
    */
-  QString getFileDialogFilter(const std::set<std::string>& exts, const std::string& defaultExt)
+  QString getFileDialogFilter(const std::vector<std::string>& exts, const std::string& defaultExt)
   {
     QString filter("");
 
@@ -110,9 +110,9 @@ namespace API
     if( !exts.empty() )
     {
       // --------- Load a File -------------
-      std::set<std::string>::const_iterator iend = exts.end();
+      auto iend = exts.end();
       // Push a wild-card onto the front of each file suffix
-      for( std::set<std::string>::const_iterator itr = exts.begin(); itr != iend; ++itr)
+      for( auto itr = exts.begin(); itr != iend; ++itr)
       {
         if( (*itr) != defaultExt )
         {
@@ -138,7 +138,7 @@ namespace API
     if( !prop ) return "";
 
     //The allowed values in this context are file extensions
-    std::set<std::string> exts = prop->allowedValues();
+    std::vector<std::string> exts = prop->allowedValues();
     std::string defaultExt = prop->getDefaultExt();
 
     /* MG 20/07/09: Static functions such as these that use native Windows and MAC dialogs
@@ -160,8 +160,8 @@ namespace API
       {
         filter = "*" + QString::fromStdString(defaultExt) + ";;";
       }
-      std::set<std::string>::const_iterator iend = exts.end();
-      for( std::set<std::string>::const_iterator itr = exts.begin(); itr != iend; ++itr)
+      auto iend = exts.end();
+      for( auto itr = exts.begin(); itr != iend; ++itr)
       {
         if( (*itr) != defaultExt )
         {
diff --git a/Code/Mantid/MantidQt/API/src/OptionsPropertyWidget.cpp b/Code/Mantid/MantidQt/API/src/OptionsPropertyWidget.cpp
index d5f518f96db1e31e60843af6875b63aa0a68c238..f190d2600c1734af6bc346ad76e59bdbc0ae7bbe 100644
--- a/Code/Mantid/MantidQt/API/src/OptionsPropertyWidget.cpp
+++ b/Code/Mantid/MantidQt/API/src/OptionsPropertyWidget.cpp
@@ -41,8 +41,8 @@ namespace API
     m_combo->setToolTip(m_doc);
     m_widgets.push_back(m_combo);
 
-    std::set<std::string> items = prop->allowedValues();
-    for(std::set<std::string>::const_iterator vitr = items.begin(); vitr != items.end(); ++vitr)
+    std::vector<std::string> items = prop->allowedValues();
+    for(auto vitr = items.begin(); vitr != items.end(); ++vitr)
     {
       m_combo->addItem(QString::fromStdString(*vitr));
     }
diff --git a/Code/Mantid/MantidQt/CustomDialogs/src/CreateSampleShapeDialog.cpp b/Code/Mantid/MantidQt/CustomDialogs/src/CreateSampleShapeDialog.cpp
index 36b3c5ca6373bc1feb2a1002ed513b09e826aa66..54c9353030ea9b9012d9bc28308f83a291136f04 100644
--- a/Code/Mantid/MantidQt/CustomDialogs/src/CreateSampleShapeDialog.cpp
+++ b/Code/Mantid/MantidQt/CustomDialogs/src/CreateSampleShapeDialog.cpp
@@ -124,8 +124,8 @@ void CreateSampleShapeDialog::initLayout()
 
   // Check input workspace property. If there are available workspaces then
   // these have been set as allowed values
-  std::set<std::string> workspaces = getAlgorithmProperty("InputWorkspace")->allowedValues();
-  for( std::set<std::string>::const_iterator itr = workspaces.begin(); itr != workspaces.end(); ++itr )
+  std::vector<std::string> workspaces = getAlgorithmProperty("InputWorkspace")->allowedValues();
+  for( std::vector<std::string>::const_iterator itr = workspaces.begin(); itr != workspaces.end(); ++itr )
   {
     m_uiForm.wksp_opt->addItem(QString::fromStdString(*itr));
   }
diff --git a/Code/Mantid/MantidQt/CustomDialogs/src/FitDialog.cpp b/Code/Mantid/MantidQt/CustomDialogs/src/FitDialog.cpp
index 557acaf4f8ddd89ef82a9db0c1009dd793d8ff66..7b4217a2dc42a1c363509643b2f6cfe3c7849d7c 100644
--- a/Code/Mantid/MantidQt/CustomDialogs/src/FitDialog.cpp
+++ b/Code/Mantid/MantidQt/CustomDialogs/src/FitDialog.cpp
@@ -589,8 +589,8 @@ QString FitDialog::getStoredPropertyValue(const QString& propName) const
 QStringList FitDialog::getAllowedPropertyValues(const QString& propName) const
 {
   QStringList out;
-  std::set<std::string> workspaces = getAlgorithmProperty(propName)->allowedValues();
-  for( std::set<std::string>::const_iterator itr = workspaces.begin(); itr != workspaces.end(); ++itr )
+  std::vector<std::string> workspaces = getAlgorithmProperty(propName)->allowedValues();
+  for( std::vector<std::string>::const_iterator itr = workspaces.begin(); itr != workspaces.end(); ++itr )
   {
     out << QString::fromStdString(*itr);
   }
diff --git a/Code/Mantid/MantidQt/CustomDialogs/src/LoadDialog.cpp b/Code/Mantid/MantidQt/CustomDialogs/src/LoadDialog.cpp
index b7a7e950f1cdacb11d076205795199e962b4df12..6f92896ad552ee7673c5866b6dfd5f7b7a781a0d 100644
--- a/Code/Mantid/MantidQt/CustomDialogs/src/LoadDialog.cpp
+++ b/Code/Mantid/MantidQt/CustomDialogs/src/LoadDialog.cpp
@@ -338,9 +338,9 @@ namespace MantidQt
         {
           QComboBox *optionsBox = new QComboBox(parent);
           inputWidget = optionsBox;
-          std::set<std::string> items = prop->allowedValues();
-          std::set<std::string>::const_iterator vend = items.end();
-          for(std::set<std::string>::const_iterator vitr = items.begin(); vitr != vend;
+          std::vector<std::string> items = prop->allowedValues();
+          std::vector<std::string>::const_iterator vend = items.end();
+          for(std::vector<std::string>::const_iterator vitr = items.begin(); vitr != vend;
             ++vitr)
           {
             optionsBox->addItem(QString::fromStdString(*vitr));
diff --git a/Code/Mantid/MantidQt/CustomDialogs/src/LoadRawDialog.cpp b/Code/Mantid/MantidQt/CustomDialogs/src/LoadRawDialog.cpp
index ce126c57199aeb213c0aa3232e1763f531971744..4976b559a89ad3721308978e7dcbdd660ae23bfe 100644
--- a/Code/Mantid/MantidQt/CustomDialogs/src/LoadRawDialog.cpp
+++ b/Code/Mantid/MantidQt/CustomDialogs/src/LoadRawDialog.cpp
@@ -128,9 +128,9 @@ void LoadRawDialog::initLayout()
   if(cacheProp)
   {
     QComboBox *cacheBox = new QComboBox;
-    std::set<std::string> items =cacheProp->allowedValues();
-    std::set<std::string>::const_iterator vend = items.end();
-    for(std::set<std::string>::const_iterator vitr = items.begin(); vitr != vend; 
+    std::vector<std::string> items =cacheProp->allowedValues();
+    std::vector<std::string>::const_iterator vend = items.end();
+    for(std::vector<std::string>::const_iterator vitr = items.begin(); vitr != vend; 
         ++vitr)
     {
       cacheBox->addItem(QString::fromStdString(*vitr));
@@ -154,22 +154,14 @@ void LoadRawDialog::initLayout()
   //------------- If the algorithm version supports the LoadMonitors property add a check box for it ----
   Mantid::Kernel::Property* loadMonitors=getAlgorithmProperty("LoadMonitors");
   if(loadMonitors)
-  {  	  
-    // define property values which should not be shown
-    const char *excl[]={"0","1"};
-    std::vector<std::string> excluded_values(excl,excl+2);
-
-
+  {
     QComboBox *monitorsBox =new QComboBox;
-    std::set<std::string> monitoritems =loadMonitors->allowedValues();
-    std::set<std::string>::const_iterator mend = monitoritems.end();
-    for(std::set<std::string>::const_iterator mitr = monitoritems.begin(); mitr != mend; 
+    std::vector<std::string> monitoritems =loadMonitors->allowedValues();
+    std::vector<std::string>::const_iterator mend = monitoritems.end();
+    for(std::vector<std::string>::const_iterator mitr = monitoritems.begin(); mitr != mend; 
         ++mitr)
     {
-      if (std::find(excluded_values.begin(), excluded_values.end(), *mitr)==excluded_values.end())
-      {
-          monitorsBox->addItem(QString::fromStdString(*mitr));
-      }
+        monitorsBox->addItem(QString::fromStdString(*mitr));
     }
     prop_line->addWidget(new QLabel("LoadMonitors:"), 0, Qt::AlignRight);
     prop_line->addWidget(monitorsBox);
diff --git a/Code/Mantid/MantidQt/CustomInterfaces/CMakeLists.txt b/Code/Mantid/MantidQt/CustomInterfaces/CMakeLists.txt
index 65639c7d5a4dc73239e7bc1f22ea997532a213d1..8bfa3c243c24a1f12da261bdf67285543ba9641f 100644
--- a/Code/Mantid/MantidQt/CustomInterfaces/CMakeLists.txt
+++ b/Code/Mantid/MantidQt/CustomInterfaces/CMakeLists.txt
@@ -1,21 +1,24 @@
 set ( SRC_FILES
 	src/ApplyCorr.cpp
-	src/C2ETab.cpp
 	src/CalcCorr.cpp
 	src/ConvFit.cpp
-	src/ConvertToEnergy.cpp
 	src/CreateMDWorkspace.cpp
 	src/CreateMDWorkspaceAlgDialog.cpp
+  src/DirectConvertToEnergy.cpp
 	src/Elwin.cpp
 	src/EventNexusFileMemento.cpp
 	src/Fury.cpp
 	src/FuryFit.cpp
 	src/Homer.cpp
 	src/IDATab.cpp
-	src/Indirect.cpp
 	src/IndirectBayes.cpp
 	src/IndirectBayesTab.cpp
+  src/IndirectCalibration.cpp
+  src/IndirectConvertToEnergy.cpp
 	src/IndirectDataAnalysis.cpp
+  src/IndirectDataReduction.cpp
+  src/IndirectDataReductionTab.cpp
+  src/IndirectDiagnostics.cpp
 	src/IndirectDiffractionReduction.cpp
 	src/IndirectLoadAscii.cpp
 	src/IndirectLoadAsciiTab.cpp
@@ -24,6 +27,8 @@ set ( SRC_FILES
 	src/IndirectNeutron.cpp
 	src/IndirectSimulation.cpp
 	src/IndirectSimulationTab.cpp
+  src/IndirectSqw.cpp
+  src/IndirectTransmission.cpp
 	src/JumpFit.cpp
 	src/MSDFit.cpp
 	src/MantidEV.cpp
@@ -55,7 +60,6 @@ set ( SRC_FILES
 	src/SANSRunWindow.cpp
 	src/StepScan.cpp
 	src/Stretch.cpp
-	src/Transmission.cpp
 	src/UserInputValidator.cpp
 	src/WorkspaceInADS.cpp
 	src/WorkspaceMemento.cpp
@@ -67,12 +71,11 @@ set ( SRC_FILES
 set ( INC_FILES
 	inc/MantidQtCustomInterfaces/ApplyCorr.h
 	inc/MantidQtCustomInterfaces/Background.h
-	inc/MantidQtCustomInterfaces/C2ETab.h
 	inc/MantidQtCustomInterfaces/CalcCorr.h
 	inc/MantidQtCustomInterfaces/ConvFit.h
-	inc/MantidQtCustomInterfaces/ConvertToEnergy.h
 	inc/MantidQtCustomInterfaces/CreateMDWorkspace.h
 	inc/MantidQtCustomInterfaces/CreateMDWorkspaceAlgDialog.h
+  inc/MantidQtCustomInterfaces/DirectConvertToEnergy.h
 	inc/MantidQtCustomInterfaces/DllConfig.h
 	inc/MantidQtCustomInterfaces/Elwin.h
 	inc/MantidQtCustomInterfaces/EventNexusFileMemento.h
@@ -80,10 +83,14 @@ set ( INC_FILES
 	inc/MantidQtCustomInterfaces/FuryFit.h
 	inc/MantidQtCustomInterfaces/Homer.h
 	inc/MantidQtCustomInterfaces/IDATab.h
-	inc/MantidQtCustomInterfaces/Indirect.h
 	inc/MantidQtCustomInterfaces/IndirectBayes.h
 	inc/MantidQtCustomInterfaces/IndirectBayesTab.h
+  inc/MantidQtCustomInterfaces/IndirectCalibration.h
+  inc/MantidQtCustomInterfaces/IndirectConvertToEnergy.h
 	inc/MantidQtCustomInterfaces/IndirectDataAnalysis.h
+  inc/MantidQtCustomInterfaces/IndirectDataReduction.h
+  inc/MantidQtCustomInterfaces/IndirectDataReductionTab.h
+	inc/MantidQtCustomInterfaces/IndirectDiagnostics.h
 	inc/MantidQtCustomInterfaces/IndirectDiffractionReduction.h
 	inc/MantidQtCustomInterfaces/IndirectLoadAscii.h
 	inc/MantidQtCustomInterfaces/IndirectLoadAsciiTab.h
@@ -92,6 +99,8 @@ set ( INC_FILES
 	inc/MantidQtCustomInterfaces/IndirectNeutron.h
 	inc/MantidQtCustomInterfaces/IndirectSimulation.h
 	inc/MantidQtCustomInterfaces/IndirectSimulationTab.h
+	inc/MantidQtCustomInterfaces/IndirectSqw.h
+  inc/MantidQtCustomInterfaces/IndirectTransmission.h
 	inc/MantidQtCustomInterfaces/JumpFit.h
 	inc/MantidQtCustomInterfaces/MSDFit.h
 	inc/MantidQtCustomInterfaces/MantidEV.h
@@ -128,7 +137,6 @@ set ( INC_FILES
 	inc/MantidQtCustomInterfaces/SANSRunWindow.h
 	inc/MantidQtCustomInterfaces/StepScan.h
 	inc/MantidQtCustomInterfaces/Stretch.h
-	inc/MantidQtCustomInterfaces/Transmission.h
 	inc/MantidQtCustomInterfaces/Updateable.h
 	inc/MantidQtCustomInterfaces/UserInputValidator.h
 	inc/MantidQtCustomInterfaces/WorkspaceInADS.h
@@ -140,21 +148,24 @@ set ( SRC_UNITY_IGNORE_FILES )
 
 set ( MOC_FILES inc/MantidQtCustomInterfaces/Background.h
                 inc/MantidQtCustomInterfaces/ApplyCorr.h
-                inc/MantidQtCustomInterfaces/C2ETab.h
                 inc/MantidQtCustomInterfaces/CalcCorr.h
-                inc/MantidQtCustomInterfaces/ConvertToEnergy.h
                 inc/MantidQtCustomInterfaces/ConvFit.h
                 inc/MantidQtCustomInterfaces/CreateMDWorkspace.h
                 inc/MantidQtCustomInterfaces/CreateMDWorkspaceAlgDialog.h
+                inc/MantidQtCustomInterfaces/DirectConvertToEnergy.h
                 inc/MantidQtCustomInterfaces/Elwin.h
                 inc/MantidQtCustomInterfaces/Fury.h
                 inc/MantidQtCustomInterfaces/FuryFit.h
                 inc/MantidQtCustomInterfaces/Homer.h
                 inc/MantidQtCustomInterfaces/IDATab.h
-                inc/MantidQtCustomInterfaces/Indirect.h
                 inc/MantidQtCustomInterfaces/IndirectBayes.h
                 inc/MantidQtCustomInterfaces/IndirectBayesTab.h
+                inc/MantidQtCustomInterfaces/IndirectCalibration.h
+                inc/MantidQtCustomInterfaces/IndirectConvertToEnergy.h
                 inc/MantidQtCustomInterfaces/IndirectDataAnalysis.h
+                inc/MantidQtCustomInterfaces/IndirectDataReduction.h
+                inc/MantidQtCustomInterfaces/IndirectDataReductionTab.h
+                inc/MantidQtCustomInterfaces/IndirectDiagnostics.h
                 inc/MantidQtCustomInterfaces/IndirectDiffractionReduction.h
                 inc/MantidQtCustomInterfaces/IndirectLoadAscii.h
                 inc/MantidQtCustomInterfaces/IndirectLoadAsciiTab.h
@@ -163,6 +174,8 @@ set ( MOC_FILES inc/MantidQtCustomInterfaces/Background.h
                 inc/MantidQtCustomInterfaces/IndirectMoments.h
                 inc/MantidQtCustomInterfaces/IndirectSimulation.h
                 inc/MantidQtCustomInterfaces/IndirectSimulationTab.h
+                inc/MantidQtCustomInterfaces/IndirectSqw.h
+                inc/MantidQtCustomInterfaces/IndirectTransmission.h
                 inc/MantidQtCustomInterfaces/JumpFit.h
                 inc/MantidQtCustomInterfaces/MSDFit.h
                 inc/MantidQtCustomInterfaces/Muon/ALCBaselineModellingPresenter.h
@@ -188,16 +201,16 @@ set ( MOC_FILES inc/MantidQtCustomInterfaces/Background.h
                 inc/MantidQtCustomInterfaces/SANSEventSlicing.h              
                 inc/MantidQtCustomInterfaces/SANSDiagnostics.h
                 inc/MantidQtCustomInterfaces/Stretch.h
-                inc/MantidQtCustomInterfaces/Transmission.h
                 inc/MantidQtCustomInterfaces/MantidEV.h
                 inc/MantidQtCustomInterfaces/StepScan.h
 )
 
-set ( UI_FILES inc/MantidQtCustomInterfaces/ConvertToEnergy.ui
-               inc/MantidQtCustomInterfaces/CreateMDWorkspace.ui
+set ( UI_FILES inc/MantidQtCustomInterfaces/CreateMDWorkspace.ui
                inc/MantidQtCustomInterfaces/CreateMDWorkspaceAlgDialog.ui
+               inc/MantidQtCustomInterfaces/DirectConvertToEnergy.ui
                inc/MantidQtCustomInterfaces/IndirectBayes.ui
                inc/MantidQtCustomInterfaces/IndirectDataAnalysis.ui
+               inc/MantidQtCustomInterfaces/IndirectDataReduction.ui
                inc/MantidQtCustomInterfaces/IndirectDiffractionReduction.ui
                inc/MantidQtCustomInterfaces/IndirectLoadAscii.ui
                inc/MantidQtCustomInterfaces/IndirectNeutron.ui
diff --git a/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/ConvertToEnergy.h b/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/DirectConvertToEnergy.h
similarity index 83%
rename from Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/ConvertToEnergy.h
rename to Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/DirectConvertToEnergy.h
index b0073d103cbdc6d273dbbc6721ffc3d043812bec..cc00e906cdca2aa789c2526109d9ad5ade54bbd0 100644
--- a/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/ConvertToEnergy.h
+++ b/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/DirectConvertToEnergy.h
@@ -4,10 +4,10 @@
 //----------------------
 // Includes
 //----------------------
-#include "ui_ConvertToEnergy.h"
+#include "ui_DirectConvertToEnergy.h"
+#include "MantidQtAPI/AlgorithmRunner.h"
 #include "MantidQtAPI/UserSubWindow.h"
 
-
 namespace MantidQt
 {
   namespace CustomInterfaces
@@ -16,10 +16,9 @@ namespace MantidQt
     // Forward declarations
     //-------------------------------------------
     class Homer;
-    class Indirect;
 
     /** 
-    This class defines the ConvertToEnergy interface. It handles the overall instrument settings
+    This class defines the DirectConvertToEnergy interface. It handles the overall instrument settings
     and sets up the appropriate interface depending on the deltaE mode of the instrument. The deltaE
     mode is defined in the instrument definition file using the "deltaE-mode".    
 
@@ -47,7 +46,7 @@ namespace MantidQt
     Code Documentation is available at: <http://doxygen.mantidproject.org>    
     */
 
-    class ConvertToEnergy : public MantidQt::API::UserSubWindow
+    class DirectConvertToEnergy : public MantidQt::API::UserSubWindow
     {
       Q_OBJECT
 
@@ -56,11 +55,11 @@ namespace MantidQt
 
     public: // public constructor, destructor and functions
       /// Default Constructor
-      ConvertToEnergy(QWidget *parent = 0);
+      DirectConvertToEnergy(QWidget *parent = 0);
       ///Destructor
-      ~ConvertToEnergy();
+      ~DirectConvertToEnergy();
       /// Interface name
-      static std::string name() { return "Convert To Energy"; }
+      static std::string name() { return "Convert To Energy (Direct)"; }
       /// Aliases for this interface
       static std::set<std::string> aliases()
       { 
@@ -69,11 +68,12 @@ namespace MantidQt
         return aliasList;
       }
       // This interface's categories.
-      static QString categoryInfo() { return "Indirect;Direct"; }
+      static QString categoryInfo() { return "Direct"; }
 
     private slots:
       void helpClicked();
       void runClicked();
+      void instrumentLoadingDone(bool error);
 
     private: // private functions (and slots)
       /// Initialize the layout
@@ -87,26 +87,24 @@ namespace MantidQt
       //QString getIDFPath(const QString& prefix);
       /// Find the DeltaEMode (Direct or Indirect) of the instrument.
       DeltaEMode instrumentDeltaEMode(const QString& defFile);
-      /// Change the user interface to show the relevant sections for the instrument type.
-      void changeInterface(DeltaEMode desired);
+
     private slots:
       void userSelectInstrument(const QString& name);
       void openDirectoryDialog();
 
     private: // member variables
       /// The .ui form generated by Qt Designer
-      Ui::ConvertToEnergy m_uiForm;
+      Ui::DirectConvertToEnergy m_uiForm;
       /// Direct Instruments interface object
       Homer *m_directInstruments;
-      /// Indirect Instruments interface object
-      Indirect *m_indirectInstruments;
       /// Instrument the interface is currently set for.
       QString m_curInterfaceSetup;
       /// "DeltaE-mode" of the current instrument.
       DeltaEMode m_curEmodeType;
       /// The settings group
       QString m_settingsGroup;
-
+      /// Runner for insturment load algorithm
+      MantidQt::API::AlgorithmRunner* m_algRunner;
     };
 
   }
diff --git a/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/DirectConvertToEnergy.ui b/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/DirectConvertToEnergy.ui
new file mode 100644
index 0000000000000000000000000000000000000000..6d602fea19cd86b15593ced4809755b752c7fe90
--- /dev/null
+++ b/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/DirectConvertToEnergy.ui
@@ -0,0 +1,1360 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>DirectConvertToEnergy</class>
+ <widget class="QWidget" name="DirectConvertToEnergy">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>621</width>
+    <height>746</height>
+   </rect>
+  </property>
+  <property name="windowTitle">
+   <string>Convert To Energy Transfer (Direct)</string>
+  </property>
+  <layout class="QVBoxLayout" name="verticalLayout_20">
+   <property name="topMargin">
+    <number>9</number>
+   </property>
+   <item>
+    <widget class="QTabWidget" name="tabWidget">
+     <property name="sizePolicy">
+      <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
+       <horstretch>0</horstretch>
+       <verstretch>0</verstretch>
+      </sizepolicy>
+     </property>
+     <property name="styleSheet">
+      <string notr="true"/>
+     </property>
+     <property name="currentIndex">
+      <number>0</number>
+     </property>
+     <property name="iconSize">
+      <size>
+       <width>14</width>
+       <height>14</height>
+      </size>
+     </property>
+     <widget class="QWidget" name="tabEnergyTransfer">
+      <attribute name="title">
+       <string>Energy Transfer</string>
+      </attribute>
+      <layout class="QVBoxLayout" name="verticalLayout_2">
+       <item>
+        <layout class="QHBoxLayout" name="horizontalLayout_27">
+         <property name="topMargin">
+          <number>0</number>
+         </property>
+         <item>
+          <widget class="QLabel" name="label_2">
+           <property name="text">
+            <string>Instrument</string>
+           </property>
+          </widget>
+         </item>
+         <item>
+          <widget class="MantidQt::MantidWidgets::InstrumentSelector" name="cbInst">
+           <property name="techniques" stdset="0">
+            <stringlist>
+             <string>TOF Direct Geometry Spectroscopy</string>
+            </stringlist>
+           </property>
+          </widget>
+         </item>
+         <item>
+          <spacer name="horizontalSpacer">
+           <property name="orientation">
+            <enum>Qt::Horizontal</enum>
+           </property>
+           <property name="sizeHint" stdset="0">
+            <size>
+             <width>40</width>
+             <height>20</height>
+            </size>
+           </property>
+          </spacer>
+         </item>
+        </layout>
+       </item>
+       <item>
+        <widget class="QGroupBox" name="gbExperiment">
+         <property name="title">
+          <string>Input Files</string>
+         </property>
+         <layout class="QVBoxLayout" name="verticalLayout">
+          <property name="spacing">
+           <number>0</number>
+          </property>
+          <property name="margin">
+           <number>0</number>
+          </property>
+          <item>
+           <widget class="QStackedWidget" name="swInputFiles">
+            <property name="lineWidth">
+             <number>0</number>
+            </property>
+            <property name="currentIndex">
+             <number>0</number>
+            </property>
+            <widget class="QWidget" name="page_3">
+             <layout class="QVBoxLayout" name="verticalLayout_32">
+              <item>
+               <layout class="QHBoxLayout" name="runFilesLay">
+                <property name="spacing">
+                 <number>9</number>
+                </property>
+                <property name="topMargin">
+                 <number>9</number>
+                </property>
+                <property name="bottomMargin">
+                 <number>6</number>
+                </property>
+                <item>
+                 <widget class="MantidQt::MantidWidgets::MWRunFiles" name="runFiles" native="true">
+                  <property name="label" stdset="0">
+                   <string>Runs          </string>
+                  </property>
+                 </widget>
+                </item>
+                <item>
+                 <widget class="QCheckBox" name="ckSumSpecs">
+                  <property name="text">
+                   <string>Sum</string>
+                  </property>
+                 </widget>
+                </item>
+               </layout>
+              </item>
+              <item>
+               <widget class="MantidQt::MantidWidgets::MWRunFiles" name="mapFile" native="true">
+                <property name="findRunFiles" stdset="0">
+                 <bool>false</bool>
+                </property>
+                <property name="label" stdset="0">
+                 <string>Map File     </string>
+                </property>
+                <property name="multipleFiles" stdset="0">
+                 <bool>false</bool>
+                </property>
+                <property name="optional" stdset="0">
+                 <bool>true</bool>
+                </property>
+                <property name="algorithmAndProperty" stdset="0">
+                 <string>GroupDetectors|MapFile</string>
+                </property>
+               </widget>
+              </item>
+              <item>
+               <widget class="MantidQt::MantidWidgets::MWRunFiles" name="whiteBeamFile" native="true">
+                <property name="label" stdset="0">
+                 <string>Detector Vanadium</string>
+                </property>
+                <property name="multipleFiles" stdset="0">
+                 <bool>false</bool>
+                </property>
+                <property name="optional" stdset="0">
+                 <bool>true</bool>
+                </property>
+               </widget>
+              </item>
+             </layout>
+            </widget>
+           </widget>
+          </item>
+         </layout>
+        </widget>
+       </item>
+       <item>
+        <widget class="QGroupBox" name="gbAnalysis">
+         <property name="title">
+          <string>Analysis Options</string>
+         </property>
+         <layout class="QGridLayout" name="gridLayout_3">
+          <property name="sizeConstraint">
+           <enum>QLayout::SetDefaultConstraint</enum>
+          </property>
+          <property name="margin">
+           <number>0</number>
+          </property>
+          <property name="spacing">
+           <number>0</number>
+          </property>
+          <item row="0" column="0">
+           <widget class="QStackedWidget" name="swAnalysis">
+            <property name="lineWidth">
+             <number>0</number>
+            </property>
+            <property name="currentIndex">
+             <number>0</number>
+            </property>
+            <widget class="QWidget" name="page_5">
+             <layout class="QGridLayout" name="gridLayout_4">
+              <item row="1" column="1">
+               <widget class="QPushButton" name="pbBack">
+                <property name="text">
+                 <string>BG removal: none</string>
+                </property>
+               </widget>
+              </item>
+              <item row="1" column="2">
+               <spacer name="horizontalSpacer_9">
+                <property name="orientation">
+                 <enum>Qt::Horizontal</enum>
+                </property>
+                <property name="sizeHint" stdset="0">
+                 <size>
+                  <width>40</width>
+                  <height>20</height>
+                 </size>
+                </property>
+               </spacer>
+              </item>
+              <item row="1" column="5">
+               <spacer name="horizontalSpacer_6">
+                <property name="orientation">
+                 <enum>Qt::Horizontal</enum>
+                </property>
+                <property name="sizeHint" stdset="0">
+                 <size>
+                  <width>40</width>
+                  <height>20</height>
+                 </size>
+                </property>
+               </spacer>
+              </item>
+              <item row="1" column="0">
+               <spacer name="horizontalSpacer_22">
+                <property name="orientation">
+                 <enum>Qt::Horizontal</enum>
+                </property>
+                <property name="sizeHint" stdset="0">
+                 <size>
+                  <width>40</width>
+                  <height>20</height>
+                 </size>
+                </property>
+               </spacer>
+              </item>
+              <item row="1" column="3">
+               <widget class="QLabel" name="label">
+                <property name="text">
+                 <string>Normalise By</string>
+                </property>
+               </widget>
+              </item>
+              <item row="1" column="4">
+               <widget class="QComboBox" name="cbNormal">
+                <property name="currentIndex">
+                 <number>0</number>
+                </property>
+                <property name="frame">
+                 <bool>true</bool>
+                </property>
+                <item>
+                 <property name="text">
+                  <string>none</string>
+                 </property>
+                </item>
+                <item>
+                 <property name="text">
+                  <string>current</string>
+                 </property>
+                </item>
+                <item>
+                 <property name="text">
+                  <string>monitor-1</string>
+                 </property>
+                </item>
+               </widget>
+              </item>
+             </layout>
+            </widget>
+           </widget>
+          </item>
+         </layout>
+        </widget>
+       </item>
+       <item>
+        <widget class="QGroupBox" name="gbCtoE">
+         <property name="title">
+          <string>Conversion to Energy Transfer</string>
+         </property>
+         <layout class="QGridLayout" name="gridLayout_6">
+          <property name="margin">
+           <number>0</number>
+          </property>
+          <property name="spacing">
+           <number>0</number>
+          </property>
+          <item row="0" column="0">
+           <widget class="QStackedWidget" name="swConvertToEnergy">
+            <property name="currentIndex">
+             <number>0</number>
+            </property>
+            <widget class="QWidget" name="page_7">
+             <layout class="QHBoxLayout" name="horizontalLayout_3">
+              <item>
+               <widget class="QLabel" name="label_9">
+                <property name="text">
+                 <string>Incident Energy</string>
+                </property>
+               </widget>
+              </item>
+              <item>
+               <widget class="QLineEdit" name="leEGuess">
+                <property name="maximumSize">
+                 <size>
+                  <width>70</width>
+                  <height>16777215</height>
+                 </size>
+                </property>
+               </widget>
+              </item>
+              <item>
+               <widget class="QLabel" name="valGuess">
+                <property name="palette">
+                 <palette>
+                  <active>
+                   <colorrole role="WindowText">
+                    <brush brushstyle="SolidPattern">
+                     <color alpha="255">
+                      <red>170</red>
+                      <green>0</green>
+                      <blue>0</blue>
+                     </color>
+                    </brush>
+                   </colorrole>
+                  </active>
+                  <inactive>
+                   <colorrole role="WindowText">
+                    <brush brushstyle="SolidPattern">
+                     <color alpha="255">
+                      <red>170</red>
+                      <green>0</green>
+                      <blue>0</blue>
+                     </color>
+                    </brush>
+                   </colorrole>
+                  </inactive>
+                  <disabled>
+                   <colorrole role="WindowText">
+                    <brush brushstyle="SolidPattern">
+                     <color alpha="255">
+                      <red>118</red>
+                      <green>116</green>
+                      <blue>108</blue>
+                     </color>
+                    </brush>
+                   </colorrole>
+                  </disabled>
+                 </palette>
+                </property>
+                <property name="text">
+                 <string>*</string>
+                </property>
+                <property name="buddy">
+                 <cstring>leEGuess</cstring>
+                </property>
+               </widget>
+              </item>
+              <item>
+               <widget class="QLabel" name="label_10">
+                <property name="text">
+                 <string>meV</string>
+                </property>
+               </widget>
+              </item>
+              <item>
+               <spacer name="horizontalSpacer_8">
+                <property name="orientation">
+                 <enum>Qt::Horizontal</enum>
+                </property>
+                <property name="sizeHint" stdset="0">
+                 <size>
+                  <width>5</width>
+                  <height>20</height>
+                 </size>
+                </property>
+               </spacer>
+              </item>
+              <item>
+               <widget class="QCheckBox" name="ckFixEi">
+                <property name="text">
+                 <string>Fix Ei</string>
+                </property>
+               </widget>
+              </item>
+              <item>
+               <spacer name="horizontalSpacer_7">
+                <property name="orientation">
+                 <enum>Qt::Horizontal</enum>
+                </property>
+                <property name="sizeHint" stdset="0">
+                 <size>
+                  <width>40</width>
+                  <height>20</height>
+                 </size>
+                </property>
+               </spacer>
+              </item>
+             </layout>
+            </widget>
+           </widget>
+          </item>
+         </layout>
+        </widget>
+       </item>
+       <item>
+        <widget class="QStackedWidget" name="swRebin">
+         <property name="currentIndex">
+          <number>0</number>
+         </property>
+         <widget class="QWidget" name="page_9">
+          <layout class="QVBoxLayout" name="verticalLayout_15">
+           <property name="spacing">
+            <number>0</number>
+           </property>
+           <property name="margin">
+            <number>0</number>
+           </property>
+           <item>
+            <widget class="QGroupBox" name="gbRebin">
+             <property name="title">
+              <string>Energy Transfer Range (meV)</string>
+             </property>
+             <layout class="QVBoxLayout" name="verticalLayout_3">
+              <property name="spacing">
+               <number>0</number>
+              </property>
+              <property name="margin">
+               <number>0</number>
+              </property>
+              <item>
+               <layout class="QHBoxLayout" name="horizontalLayout_14">
+                <item>
+                 <spacer name="horizontalSpacer_28">
+                  <property name="orientation">
+                   <enum>Qt::Horizontal</enum>
+                  </property>
+                  <property name="sizeHint" stdset="0">
+                   <size>
+                    <width>40</width>
+                    <height>20</height>
+                   </size>
+                  </property>
+                 </spacer>
+                </item>
+                <item>
+                 <widget class="QLabel" name="label_19">
+                  <property name="text">
+                   <string>Low</string>
+                  </property>
+                 </widget>
+                </item>
+                <item>
+                 <widget class="QLineEdit" name="leELow">
+                  <property name="maximumSize">
+                   <size>
+                    <width>70</width>
+                    <height>16777215</height>
+                   </size>
+                  </property>
+                 </widget>
+                </item>
+                <item>
+                 <widget class="QLabel" name="validRebinLow">
+                  <property name="palette">
+                   <palette>
+                    <active>
+                     <colorrole role="WindowText">
+                      <brush brushstyle="SolidPattern">
+                       <color alpha="255">
+                        <red>170</red>
+                        <green>0</green>
+                        <blue>0</blue>
+                       </color>
+                      </brush>
+                     </colorrole>
+                    </active>
+                    <inactive>
+                     <colorrole role="WindowText">
+                      <brush brushstyle="SolidPattern">
+                       <color alpha="255">
+                        <red>170</red>
+                        <green>0</green>
+                        <blue>0</blue>
+                       </color>
+                      </brush>
+                     </colorrole>
+                    </inactive>
+                    <disabled>
+                     <colorrole role="WindowText">
+                      <brush brushstyle="SolidPattern">
+                       <color alpha="255">
+                        <red>118</red>
+                        <green>116</green>
+                        <blue>108</blue>
+                       </color>
+                      </brush>
+                     </colorrole>
+                    </disabled>
+                   </palette>
+                  </property>
+                  <property name="text">
+                   <string>*</string>
+                  </property>
+                  <property name="buddy">
+                   <cstring>leELow</cstring>
+                  </property>
+                 </widget>
+                </item>
+                <item>
+                 <widget class="QLabel" name="label_20">
+                  <property name="text">
+                   <string>Width</string>
+                  </property>
+                 </widget>
+                </item>
+                <item>
+                 <widget class="QLineEdit" name="leEWidth">
+                  <property name="maximumSize">
+                   <size>
+                    <width>70</width>
+                    <height>16777215</height>
+                   </size>
+                  </property>
+                 </widget>
+                </item>
+                <item>
+                 <widget class="QLabel" name="validRebinWidth">
+                  <property name="palette">
+                   <palette>
+                    <active>
+                     <colorrole role="WindowText">
+                      <brush brushstyle="SolidPattern">
+                       <color alpha="255">
+                        <red>170</red>
+                        <green>0</green>
+                        <blue>0</blue>
+                       </color>
+                      </brush>
+                     </colorrole>
+                    </active>
+                    <inactive>
+                     <colorrole role="WindowText">
+                      <brush brushstyle="SolidPattern">
+                       <color alpha="255">
+                        <red>170</red>
+                        <green>0</green>
+                        <blue>0</blue>
+                       </color>
+                      </brush>
+                     </colorrole>
+                    </inactive>
+                    <disabled>
+                     <colorrole role="WindowText">
+                      <brush brushstyle="SolidPattern">
+                       <color alpha="255">
+                        <red>118</red>
+                        <green>116</green>
+                        <blue>108</blue>
+                       </color>
+                      </brush>
+                     </colorrole>
+                    </disabled>
+                   </palette>
+                  </property>
+                  <property name="text">
+                   <string>*</string>
+                  </property>
+                  <property name="buddy">
+                   <cstring>leEWidth</cstring>
+                  </property>
+                 </widget>
+                </item>
+                <item>
+                 <widget class="QLabel" name="label_21">
+                  <property name="text">
+                   <string>High</string>
+                  </property>
+                 </widget>
+                </item>
+                <item>
+                 <widget class="QLineEdit" name="leEHigh">
+                  <property name="maximumSize">
+                   <size>
+                    <width>70</width>
+                    <height>16777215</height>
+                   </size>
+                  </property>
+                 </widget>
+                </item>
+                <item>
+                 <widget class="QLabel" name="validRebinHigh">
+                  <property name="palette">
+                   <palette>
+                    <active>
+                     <colorrole role="WindowText">
+                      <brush brushstyle="SolidPattern">
+                       <color alpha="255">
+                        <red>170</red>
+                        <green>0</green>
+                        <blue>0</blue>
+                       </color>
+                      </brush>
+                     </colorrole>
+                    </active>
+                    <inactive>
+                     <colorrole role="WindowText">
+                      <brush brushstyle="SolidPattern">
+                       <color alpha="255">
+                        <red>170</red>
+                        <green>0</green>
+                        <blue>0</blue>
+                       </color>
+                      </brush>
+                     </colorrole>
+                    </inactive>
+                    <disabled>
+                     <colorrole role="WindowText">
+                      <brush brushstyle="SolidPattern">
+                       <color alpha="255">
+                        <red>118</red>
+                        <green>116</green>
+                        <blue>108</blue>
+                       </color>
+                      </brush>
+                     </colorrole>
+                    </disabled>
+                   </palette>
+                  </property>
+                  <property name="text">
+                   <string>*</string>
+                  </property>
+                  <property name="buddy">
+                   <cstring>leEHigh</cstring>
+                  </property>
+                 </widget>
+                </item>
+                <item>
+                 <spacer name="horizontalSpacer_29">
+                  <property name="orientation">
+                   <enum>Qt::Horizontal</enum>
+                  </property>
+                  <property name="sizeHint" stdset="0">
+                   <size>
+                    <width>40</width>
+                    <height>20</height>
+                   </size>
+                  </property>
+                 </spacer>
+                </item>
+               </layout>
+              </item>
+             </layout>
+            </widget>
+           </item>
+           <item>
+            <widget class="QGroupBox" name="gbSampleEnv">
+             <property name="title">
+              <string>Sample Environment</string>
+             </property>
+             <layout class="QHBoxLayout" name="horizontalLayout_25">
+              <property name="margin">
+               <number>0</number>
+              </property>
+              <item>
+               <widget class="QLabel" name="label_5">
+                <property name="text">
+                 <string>SE Motor</string>
+                </property>
+               </widget>
+              </item>
+              <item>
+               <widget class="QLineEdit" name="motorNameEdit"/>
+              </item>
+              <item>
+               <widget class="QLabel" name="label_6">
+                <property name="text">
+                 <string>offset</string>
+                </property>
+               </widget>
+              </item>
+              <item>
+               <widget class="QLineEdit" name="seOffsetEdit">
+                <property name="toolTip">
+                 <string> Psi = Motor Value + Offset</string>
+                </property>
+               </widget>
+              </item>
+             </layout>
+            </widget>
+           </item>
+          </layout>
+         </widget>
+        </widget>
+       </item>
+       <item>
+        <widget class="QGroupBox" name="gbSave">
+         <property name="title">
+          <string>Output Options</string>
+         </property>
+         <layout class="QGridLayout" name="gridLayout_8">
+          <property name="topMargin">
+           <number>0</number>
+          </property>
+          <property name="bottomMargin">
+           <number>0</number>
+          </property>
+          <item row="1" column="0">
+           <layout class="QHBoxLayout" name="horizontalLayout_8">
+            <item>
+             <widget class="QLabel" name="save_lbFormats">
+              <property name="text">
+               <string>Select Save Formats:</string>
+              </property>
+             </widget>
+            </item>
+            <item>
+             <widget class="QCheckBox" name="save_ckSPE">
+              <property name="toolTip">
+               <string>Save file in SPE format.</string>
+              </property>
+              <property name="text">
+               <string>SPE</string>
+              </property>
+              <property name="checked">
+               <bool>false</bool>
+              </property>
+             </widget>
+            </item>
+            <item>
+             <widget class="QCheckBox" name="save_ckNexus">
+              <property name="toolTip">
+               <string>Save file in Nexus format.</string>
+              </property>
+              <property name="text">
+               <string>NeXus</string>
+              </property>
+             </widget>
+            </item>
+            <item>
+             <widget class="QCheckBox" name="save_ckNxSPE">
+              <property name="text">
+               <string>NXSPE</string>
+              </property>
+             </widget>
+            </item>
+            <item>
+             <widget class="QCheckBox" name="save_ckAscii">
+              <property name="text">
+               <string>ASCII</string>
+              </property>
+             </widget>
+            </item>
+            <item>
+             <widget class="QCheckBox" name="save_ckAclimax">
+              <property name="text">
+               <string>Aclimax</string>
+              </property>
+             </widget>
+            </item>
+            <item>
+             <spacer name="horizontalSpacer_15">
+              <property name="orientation">
+               <enum>Qt::Horizontal</enum>
+              </property>
+              <property name="sizeHint" stdset="0">
+               <size>
+                <width>40</width>
+                <height>20</height>
+               </size>
+              </property>
+             </spacer>
+            </item>
+           </layout>
+          </item>
+          <item row="0" column="0">
+           <widget class="QStackedWidget" name="swSave">
+            <property name="currentIndex">
+             <number>0</number>
+            </property>
+            <widget class="QWidget" name="page_15">
+             <layout class="QVBoxLayout" name="verticalLayout_13">
+              <item>
+               <layout class="QHBoxLayout" name="et_save">
+                <item>
+                 <widget class="QLabel" name="save_lbFile">
+                  <property name="text">
+                   <string>Filename</string>
+                  </property>
+                 </widget>
+                </item>
+                <item>
+                 <widget class="QLineEdit" name="leNameSPE">
+                  <property name="enabled">
+                   <bool>false</bool>
+                  </property>
+                  <property name="minimumSize">
+                   <size>
+                    <width>250</width>
+                    <height>0</height>
+                   </size>
+                  </property>
+                 </widget>
+                </item>
+                <item>
+                 <widget class="QPushButton" name="pbBrowseSPE">
+                  <property name="text">
+                   <string>Browse</string>
+                  </property>
+                 </widget>
+                </item>
+                <item>
+                 <spacer name="horizontalSpacer_2">
+                  <property name="orientation">
+                   <enum>Qt::Horizontal</enum>
+                  </property>
+                  <property name="sizeType">
+                   <enum>QSizePolicy::MinimumExpanding</enum>
+                  </property>
+                  <property name="sizeHint" stdset="0">
+                   <size>
+                    <width>40</width>
+                    <height>20</height>
+                   </size>
+                  </property>
+                 </spacer>
+                </item>
+               </layout>
+              </item>
+             </layout>
+            </widget>
+           </widget>
+          </item>
+         </layout>
+        </widget>
+       </item>
+      </layout>
+     </widget>
+     <widget class="QWidget" name="tabDiagnoseDetectors">
+      <attribute name="title">
+       <string>Diagnose Detectors</string>
+      </attribute>
+      <layout class="QVBoxLayout" name="verticalLayout_4">
+       <item>
+        <widget class="QCheckBox" name="ckRunDiag">
+         <property name="enabled">
+          <bool>true</bool>
+         </property>
+         <property name="text">
+          <string>Find Bad Detectors</string>
+         </property>
+         <property name="checked">
+          <bool>true</bool>
+         </property>
+        </widget>
+       </item>
+      </layout>
+     </widget>
+     <widget class="QWidget" name="tabAbsoluteUnits">
+      <attribute name="title">
+       <string>Absolute Units</string>
+      </attribute>
+      <layout class="QVBoxLayout" name="verticalLayout_11">
+       <item>
+        <widget class="QCheckBox" name="ckRunAbsol">
+         <property name="enabled">
+          <bool>true</bool>
+         </property>
+         <property name="text">
+          <string>Perform Absolute Normalisation</string>
+         </property>
+         <property name="checked">
+          <bool>false</bool>
+         </property>
+        </widget>
+       </item>
+       <item>
+        <widget class="QGroupBox" name="gbCalRuns">
+         <property name="enabled">
+          <bool>true</bool>
+         </property>
+         <property name="title">
+          <string>Run Files</string>
+         </property>
+         <layout class="QVBoxLayout" name="verticalLayout_31">
+          <item>
+           <widget class="MantidQt::MantidWidgets::MWRunFiles" name="absRunFiles" native="true">
+            <property name="label" stdset="0">
+             <string>Abs Units Vanadium</string>
+            </property>
+           </widget>
+          </item>
+          <item>
+           <widget class="MantidQt::MantidWidgets::MWRunFiles" name="absMapFile" native="true">
+            <property name="findRunFiles" stdset="0">
+             <bool>false</bool>
+            </property>
+            <property name="label" stdset="0">
+             <string>Map File  </string>
+            </property>
+            <property name="multipleFiles" stdset="0">
+             <bool>false</bool>
+            </property>
+            <property name="optional" stdset="0">
+             <bool>true</bool>
+            </property>
+            <property name="algorithmAndProperty" stdset="0">
+             <string>GroupDetectors|MapFile</string>
+            </property>
+           </widget>
+          </item>
+          <item>
+           <widget class="MantidQt::MantidWidgets::MWRunFiles" name="absWhiteFile" native="true">
+            <property name="label" stdset="0">
+             <string>Detector Vanadium (Abs Units)</string>
+            </property>
+            <property name="multipleFiles" stdset="0">
+             <bool>false</bool>
+            </property>
+            <property name="optional" stdset="0">
+             <bool>true</bool>
+            </property>
+           </widget>
+          </item>
+         </layout>
+        </widget>
+       </item>
+       <item>
+        <layout class="QHBoxLayout" name="horizontalLayout_17">
+         <item>
+          <widget class="QGroupBox" name="gbInteg">
+           <property name="styleSheet">
+            <string notr="true"/>
+           </property>
+           <property name="title">
+            <string>Integration (meV)</string>
+           </property>
+           <layout class="QGridLayout" name="gridLayout_17">
+            <item row="2" column="1">
+             <widget class="QLabel" name="label_29">
+              <property name="text">
+               <string>E Min</string>
+              </property>
+              <property name="alignment">
+               <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
+              </property>
+             </widget>
+            </item>
+            <item row="2" column="2">
+             <widget class="QLineEdit" name="leVanELow">
+              <property name="maximumSize">
+               <size>
+                <width>60</width>
+                <height>16777215</height>
+               </size>
+              </property>
+             </widget>
+            </item>
+            <item row="3" column="1">
+             <widget class="QLabel" name="label_30">
+              <property name="text">
+               <string>E Max</string>
+              </property>
+              <property name="alignment">
+               <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
+              </property>
+             </widget>
+            </item>
+            <item row="3" column="2">
+             <widget class="QLineEdit" name="leVanEHigh">
+              <property name="maximumSize">
+               <size>
+                <width>60</width>
+                <height>16777215</height>
+               </size>
+              </property>
+             </widget>
+            </item>
+            <item row="1" column="1">
+             <widget class="QLabel" name="label_31">
+              <property name="text">
+               <string>Incident Energy</string>
+              </property>
+              <property name="alignment">
+               <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
+              </property>
+             </widget>
+            </item>
+            <item row="1" column="2">
+             <widget class="QLineEdit" name="leVanEi">
+              <property name="minimumSize">
+               <size>
+                <width>0</width>
+                <height>0</height>
+               </size>
+              </property>
+              <property name="maximumSize">
+               <size>
+                <width>70</width>
+                <height>16777215</height>
+               </size>
+              </property>
+             </widget>
+            </item>
+            <item row="1" column="4">
+             <spacer name="horizontalSpacer_24">
+              <property name="orientation">
+               <enum>Qt::Horizontal</enum>
+              </property>
+              <property name="sizeHint" stdset="0">
+               <size>
+                <width>40</width>
+                <height>20</height>
+               </size>
+              </property>
+             </spacer>
+            </item>
+            <item row="1" column="0">
+             <spacer name="horizontalSpacer_25">
+              <property name="orientation">
+               <enum>Qt::Horizontal</enum>
+              </property>
+              <property name="sizeHint" stdset="0">
+               <size>
+                <width>40</width>
+                <height>20</height>
+               </size>
+              </property>
+             </spacer>
+            </item>
+            <item row="1" column="3">
+             <widget class="QLabel" name="lbValAbsEi">
+              <property name="palette">
+               <palette>
+                <active>
+                 <colorrole role="WindowText">
+                  <brush brushstyle="SolidPattern">
+                   <color alpha="255">
+                    <red>170</red>
+                    <green>0</green>
+                    <blue>0</blue>
+                   </color>
+                  </brush>
+                 </colorrole>
+                </active>
+                <inactive>
+                 <colorrole role="WindowText">
+                  <brush brushstyle="SolidPattern">
+                   <color alpha="255">
+                    <red>170</red>
+                    <green>0</green>
+                    <blue>0</blue>
+                   </color>
+                  </brush>
+                 </colorrole>
+                </inactive>
+                <disabled>
+                 <colorrole role="WindowText">
+                  <brush brushstyle="SolidPattern">
+                   <color alpha="255">
+                    <red>118</red>
+                    <green>116</green>
+                    <blue>108</blue>
+                   </color>
+                  </brush>
+                 </colorrole>
+                </disabled>
+               </palette>
+              </property>
+              <property name="styleSheet">
+               <string notr="true"/>
+              </property>
+              <property name="text">
+               <string>*</string>
+              </property>
+             </widget>
+            </item>
+           </layout>
+          </widget>
+         </item>
+         <item>
+          <widget class="QGroupBox" name="gbMasses">
+           <property name="sizePolicy">
+            <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
+             <horstretch>0</horstretch>
+             <verstretch>0</verstretch>
+            </sizepolicy>
+           </property>
+           <property name="title">
+            <string>Masses (for Absolute Units)</string>
+           </property>
+           <layout class="QGridLayout" name="gridLayout_18">
+            <item row="0" column="1">
+             <widget class="QLabel" name="label_32">
+              <property name="layoutDirection">
+               <enum>Qt::LeftToRight</enum>
+              </property>
+              <property name="text">
+               <string>Vanadium mass</string>
+              </property>
+              <property name="alignment">
+               <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
+              </property>
+             </widget>
+            </item>
+            <item row="1" column="1">
+             <widget class="QLabel" name="label_33">
+              <property name="layoutDirection">
+               <enum>Qt::LeftToRight</enum>
+              </property>
+              <property name="text">
+               <string>Sample mass</string>
+              </property>
+              <property name="alignment">
+               <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
+              </property>
+             </widget>
+            </item>
+            <item row="2" column="1">
+             <widget class="QLabel" name="label_34">
+              <property name="layoutDirection">
+               <enum>Qt::LeftToRight</enum>
+              </property>
+              <property name="text">
+               <string>Sample RMM</string>
+              </property>
+              <property name="alignment">
+               <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
+              </property>
+             </widget>
+            </item>
+            <item row="2" column="2">
+             <widget class="QLineEdit" name="leRMMMass">
+              <property name="sizePolicy">
+               <sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
+                <horstretch>0</horstretch>
+                <verstretch>0</verstretch>
+               </sizepolicy>
+              </property>
+              <property name="maximumSize">
+               <size>
+                <width>60</width>
+                <height>16777215</height>
+               </size>
+              </property>
+             </widget>
+            </item>
+            <item row="1" column="2">
+             <widget class="QLineEdit" name="leSamMass">
+              <property name="sizePolicy">
+               <sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
+                <horstretch>0</horstretch>
+                <verstretch>0</verstretch>
+               </sizepolicy>
+              </property>
+              <property name="maximumSize">
+               <size>
+                <width>60</width>
+                <height>16777215</height>
+               </size>
+              </property>
+             </widget>
+            </item>
+            <item row="0" column="2">
+             <widget class="QLineEdit" name="leVanMass">
+              <property name="sizePolicy">
+               <sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
+                <horstretch>0</horstretch>
+                <verstretch>0</verstretch>
+               </sizepolicy>
+              </property>
+              <property name="maximumSize">
+               <size>
+                <width>60</width>
+                <height>16777215</height>
+               </size>
+              </property>
+             </widget>
+            </item>
+            <item row="0" column="3">
+             <spacer name="horizontalSpacer_26">
+              <property name="orientation">
+               <enum>Qt::Horizontal</enum>
+              </property>
+              <property name="sizeHint" stdset="0">
+               <size>
+                <width>40</width>
+                <height>20</height>
+               </size>
+              </property>
+             </spacer>
+            </item>
+            <item row="0" column="0">
+             <spacer name="horizontalSpacer_27">
+              <property name="orientation">
+               <enum>Qt::Horizontal</enum>
+              </property>
+              <property name="sizeHint" stdset="0">
+               <size>
+                <width>40</width>
+                <height>20</height>
+               </size>
+              </property>
+             </spacer>
+            </item>
+           </layout>
+          </widget>
+         </item>
+        </layout>
+       </item>
+       <item>
+        <spacer name="verticalSpacer">
+         <property name="orientation">
+          <enum>Qt::Vertical</enum>
+         </property>
+         <property name="sizeHint" stdset="0">
+          <size>
+           <width>20</width>
+           <height>40</height>
+          </size>
+         </property>
+        </spacer>
+       </item>
+      </layout>
+     </widget>
+    </widget>
+   </item>
+   <item>
+    <layout class="QHBoxLayout" name="horizontalLayout_6">
+     <item>
+      <widget class="QPushButton" name="pbHelp">
+       <property name="maximumSize">
+        <size>
+         <width>25</width>
+         <height>25</height>
+        </size>
+       </property>
+       <property name="toolTip">
+        <string>Open interface help page in your web browser.</string>
+       </property>
+       <property name="text">
+        <string>?</string>
+       </property>
+      </widget>
+     </item>
+     <item>
+      <spacer name="horizontalSpacer_1">
+       <property name="orientation">
+        <enum>Qt::Horizontal</enum>
+       </property>
+       <property name="sizeHint" stdset="0">
+        <size>
+         <width>40</width>
+         <height>20</height>
+        </size>
+       </property>
+      </spacer>
+     </item>
+     <item>
+      <widget class="QPushButton" name="pbRun">
+       <property name="sizePolicy">
+        <sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
+         <horstretch>0</horstretch>
+         <verstretch>0</verstretch>
+        </sizepolicy>
+       </property>
+       <property name="maximumSize">
+        <size>
+         <width>180</width>
+         <height>16777215</height>
+        </size>
+       </property>
+       <property name="toolTip">
+        <string>Run conversion to energy process.</string>
+       </property>
+       <property name="text">
+        <string>Run</string>
+       </property>
+      </widget>
+     </item>
+     <item>
+      <spacer name="horizontalSpacer_5">
+       <property name="orientation">
+        <enum>Qt::Horizontal</enum>
+       </property>
+       <property name="sizeHint" stdset="0">
+        <size>
+         <width>40</width>
+         <height>20</height>
+        </size>
+       </property>
+      </spacer>
+     </item>
+     <item>
+      <widget class="QPushButton" name="pbManageDirectories">
+       <property name="text">
+        <string>Manage Directories</string>
+       </property>
+      </widget>
+     </item>
+    </layout>
+   </item>
+  </layout>
+ </widget>
+ <customwidgets>
+  <customwidget>
+   <class>MantidQt::MantidWidgets::MWRunFiles</class>
+   <extends>QWidget</extends>
+   <header>MantidQtMantidWidgets/MWRunFiles.h</header>
+  </customwidget>
+  <customwidget>
+   <class>MantidQt::MantidWidgets::InstrumentSelector</class>
+   <extends>QComboBox</extends>
+   <header>MantidQtMantidWidgets/InstrumentSelector.h</header>
+  </customwidget>
+ </customwidgets>
+ <tabstops>
+  <tabstop>tabWidget</tabstop>
+  <tabstop>ckSumSpecs</tabstop>
+  <tabstop>pbBack</tabstop>
+  <tabstop>cbNormal</tabstop>
+  <tabstop>leEGuess</tabstop>
+  <tabstop>ckFixEi</tabstop>
+  <tabstop>leELow</tabstop>
+  <tabstop>leEWidth</tabstop>
+  <tabstop>leEHigh</tabstop>
+  <tabstop>leNameSPE</tabstop>
+  <tabstop>pbBrowseSPE</tabstop>
+  <tabstop>save_ckSPE</tabstop>
+  <tabstop>save_ckNexus</tabstop>
+  <tabstop>pbRun</tabstop>
+  <tabstop>pbHelp</tabstop>
+  <tabstop>ckRunDiag</tabstop>
+  <tabstop>ckRunAbsol</tabstop>
+  <tabstop>leVanEi</tabstop>
+  <tabstop>leVanELow</tabstop>
+  <tabstop>leVanEHigh</tabstop>
+  <tabstop>leVanMass</tabstop>
+  <tabstop>leSamMass</tabstop>
+  <tabstop>leRMMMass</tabstop>
+  <tabstop>cbInst</tabstop>
+  <tabstop>runFiles</tabstop>
+  <tabstop>mapFile</tabstop>
+  <tabstop>whiteBeamFile</tabstop>
+  <tabstop>motorNameEdit</tabstop>
+  <tabstop>seOffsetEdit</tabstop>
+  <tabstop>save_ckNxSPE</tabstop>
+  <tabstop>save_ckAscii</tabstop>
+  <tabstop>save_ckAclimax</tabstop>
+  <tabstop>absRunFiles</tabstop>
+  <tabstop>absMapFile</tabstop>
+  <tabstop>absWhiteFile</tabstop>
+  <tabstop>pbManageDirectories</tabstop>
+ </tabstops>
+ <resources/>
+ <connections/>
+</ui>
diff --git a/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Homer.h b/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Homer.h
index 0c1dbc9ac56817c86dd1ddaf412b4ad661062a2c..a0abdbe9989dc8e5c3e8bd7350ab860c56e84f0d 100644
--- a/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Homer.h
+++ b/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Homer.h
@@ -1,7 +1,7 @@
 #ifndef MANTIDQTCUSTOMINTERFACES_HOMER_H_
 #define MANTIDQTCUSTOMINTERFACES_HOMER_H_
 
-#include "ui_ConvertToEnergy.h"
+#include "ui_DirectConvertToEnergy.h"
 #include "MantidQtAPI/UserSubWindow.h"
 #include "MantidAPI/IAlgorithm.h"
 #include <QString>
@@ -35,7 +35,7 @@ namespace MantidQt
     class Background;
 
     /** 
-    This class implements the ConvertToEnergy interface for the direct instruments
+    This class implements the DirectConvertToEnergy interface for the direct instruments
 
     @author Steve Williams, ISIS Computing Group, RAL
     @author Martyn Gigg, Tessella Support Services plc
@@ -66,7 +66,7 @@ namespace MantidQt
       Q_OBJECT
 
     public:
-      Homer(QWidget *parent, Ui::ConvertToEnergy & uiForm);
+      Homer(QWidget *parent, Ui::DirectConvertToEnergy & uiForm);
 
       // Initialize the layout
       virtual void initLayout();
@@ -129,7 +129,7 @@ namespace MantidQt
       void markAbsEiDirty(bool dirty = true);
 
     private:
-      Ui::ConvertToEnergy m_uiForm;
+      Ui::DirectConvertToEnergy m_uiForm;
       Background *m_backgroundDialog;
       /// A pointer to the widget with the user controls for finding bad detectors
       MantidWidgets::MWDiag *m_diagPage;
diff --git a/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Indirect.h b/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Indirect.h
deleted file mode 100644
index 925c535aff7ce6fc3bc333be75b747c097c1651f..0000000000000000000000000000000000000000
--- a/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Indirect.h
+++ /dev/null
@@ -1,195 +0,0 @@
-#ifndef MANTIDQTCUSTOMINTERFACES_INDIRECT_H_
-#define MANTIDQTCUSTOMINTERFACES_INDIRECT_H_
-
-#include "MantidQtAPI/UserSubWindow.h"
-#include "MantidQtCustomInterfaces/C2ETab.h"
-#include "ui_ConvertToEnergy.h"
-
-#include <qwt_plot.h>
-#include <qwt_plot_curve.h>
-
-#include "MantidQtMantidWidgets/RangeSelector.h"
-#include "MantidAPI/MatrixWorkspace.h"
-
-//----------------------------------------------------
-// Forward declarations
-//-----------------------------------------------------
-
-class QtProperty;
-class QtBoolPropertyManager;
-class QtDoublePropertyManager;
-class QtGroupPropertyManager;
-class QtTreePropertyBrowser;
-
-namespace MantidQt
-{
-  namespace CustomInterfaces
-  {
-    /// Forward Declarations
-    class Background;
-
-    /** 
-    This class defines handles the ConvertToEnergy interface for indirect instruments (IRIS/OSIRIS).    
-
-    @author Michael Whitty
-    @author Martyn Gigg
-
-    Copyright &copy; 2010 ISIS Rutherford Appleton Laboratory & NScD Oak Ridge National Laboratory
-
-    This file is part of Mantid.
-
-    Mantid is free software; you can redistribute it and/or modify
-    it under the terms of the GNU General Public License as published by
-    the Free Software Foundation; either version 3 of the License, or
-    (at your option) any later version.
-
-    Mantid is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU General Public License for more details.
-
-    You should have received a copy of the GNU General Public License
-    along with this program.  If not, see <http://www.gnu.org/licenses/>.
-
-    File change history is stored at: <https://github.com/mantidproject/mantid>
-    Code Documentation is available at: <http://doxygen.mantidproject.org>    
-    */
-
-    class Indirect : public MantidQt::API::UserSubWindow
-    {
-      Q_OBJECT
-
-    public:
-      /// explicit constructor, not to allow any implicit conversion of types
-      explicit Indirect(QWidget *parent, Ui::ConvertToEnergy & uiForm);
-      /// Initialize the layout
-      virtual void initLayout();
-      /// run Python-based initialisation commands
-      virtual void initLocalPython();
-      /// open the wiki page for this interface in a web browser
-      void helpClicked();
-      /// perform whatever operations needed for analysis
-      void runClicked();
-      void runConvertToEnergy();
-      /// gather necessary information from Instument Definition Files
-      virtual void setIDFValues(const QString & prefix);
-      /// perform any instrument-specific changes to layout
-      void performInstSpecific();
-
-    private:
-      virtual void closeEvent(QCloseEvent* close);
-      void handleDirectoryChange(Mantid::Kernel::ConfigValChangeNotification_ptr pNf); ///< handle POCO event
-      void clearReflectionInfo(); ///< clear various line edit boxes
-      QString createMapFile(const QString& groupType); ///< create the mapping file with which to group results
-      QString savePyCode(); ///< create python code as string to save files
-      void createRESfile(const QString& file); ///< create a RES file for use in Fury
-      bool validateInput(); ///< validate input of "Energy Transfer" tab
-      QString validateCalib(); ///< validate input of "Calibration" tab
-      bool validateSofQw(); ///< validate input of "S(Q, w)" tab
-      QString validateSlice(); ///< validate input of "Slice" tab
-      void loadSettings();
-      void saveSettings();
-
-      void setupCalibration(); ///< set up the miniplots on calibration tab
-      void setupSlice(); ///< setup the slice miniplot section
-
-    private slots:
-      void validateSofQ(int);
-      void pbRunEditing();  //< Called when a user starts to type / edit the runs to load.
-      void pbRunFinding();  //< Called when the FileFinder starts finding the files.
-      void pbRunFinished(); //< Called when the FileFinder has finished finding the files.
-      /// Slot showing a message box to the user
-      void showMessageBox(const QString& message);
-
-      void analyserSelected(int index); ///< set up cbReflection based on Analyser selection
-      void reflectionSelected(int index); ///< set up parameter file values based on reflection
-      void mappingOptionSelected(const QString& groupType); ///< change ui to display appropriate options
-      void tabChanged(int index); ///< handles enabling/disabling the "Run" button
-      void backgroundClicked(); ///< handles showing and hiding m_backgroundDialog
-      void backgroundRemoval(); ///< handles data from BG
-      void plotRaw(); ///< plot raw data from instrument
-      void rebinCheck(bool state); ///< handle checking/unchecking of "Do Not Rebin"
-      void detailedBalanceCheck(bool state); ///< handle checking/unchecking of "Detailed Balance"
-
-      void scaleMultiplierCheck(bool state); ///< handle checking/unchecking of "Scale: Multiply by"
-
-      void resCheck(bool state); ///< handles checking/unchecking of "Create RES File" checkbox
-      void useCalib(bool state); ///< whether to use calib file
-      void calibCreate(); ///< create calibration file
-      void calibFileChanged(const QString & calib); ///< sets m_uiForm.ckUseCalib to appropriate value
-      void intensityScaleMultiplierCheck(bool state); /// Toggle the intensity scale multiplier box
-      void calibValidateIntensity(const QString & text); /// Check that the scale multiplier is valid
-
-      void calPlotRaw();
-      void calPlotEnergy();
-      void calMinChanged(double);
-      void calMaxChanged(double);
-      void calUpdateRS(QtProperty*, double);
-      void calSetDefaultResolution(Mantid::API::MatrixWorkspace_const_sptr ws);
-
-      void sOfQwClicked(); ///< S(Q,w) tab run button clicked
-      void sOfQwRebinE(bool state);
-      void sOfQwPlotInput();
-
-      void sliceRun();
-      void slicePlotRaw();
-      void sliceTwoRanges(QtProperty*, bool);
-      void sliceCalib(bool state);
-      void sliceMinChanged(double val);
-      void sliceMaxChanged(double val);
-      void sliceUpdateRS(QtProperty*, double);
-
-    private:
-      /// set and show an instrument-specific widget
-      void setInstSpecificWidget(const std::string & parameterName, QCheckBox * checkBox, QCheckBox::ToggleState defaultState);
-      // set the upper and lower bounds of the plot range
-      void setPlotRange(MantidWidgets::RangeSelector* rangeSelector, QtDoublePropertyManager* dblManager, 
-        const std::pair<QtProperty*, QtProperty*> props, const std::pair<double, double>& bounds);
-
-      Ui::ConvertToEnergy m_uiForm; ///< user interface form object
-      Background *m_backgroundDialog; ///< background removal dialog
-      Poco::NObserver<Indirect, Mantid::Kernel::ConfigValChangeNotification> m_changeObserver; ///< Poco observer for changes in user directory settings
-      QString m_dataDir; ///< default data search directory
-      QString m_saveDir; ///< default data save directory
-      QString m_settingsGroup;
-      bool m_bgRemoval; ///< whether user has set values for BG removal
-
-      /* Validators */
-      QIntValidator *m_valInt; ///< validator for int inputs
-      QDoubleValidator *m_valDbl; ///< validator for double inputs
-      QDoubleValidator *m_valPosDbl; ///< validator for positive double inputs
-
-      // CALIBRATION MINIPLOTS (prefix: 'm_calCal' (calibration) and 'm_calRes' (resolution))
-      QwtPlot* m_calCalPlot;
-      QwtPlot* m_calResPlot;
-      MantidWidgets::RangeSelector* m_calCalR1;
-      MantidWidgets::RangeSelector* m_calCalR2;
-      MantidWidgets::RangeSelector* m_calResR1;
-      MantidWidgets::RangeSelector* m_calResR2;
-      QwtPlotCurve* m_calCalCurve;
-      QwtPlotCurve* m_calResCurve;
-      QtTreePropertyBrowser* m_calCalTree;
-      QtTreePropertyBrowser* m_calResTree;
-      QMap<QString, QtProperty*> m_calCalProp;
-      QMap<QString, QtProperty*> m_calResProp;
-      QtDoublePropertyManager* m_calDblMng;
-      QtGroupPropertyManager* m_calGrpMng;
-
-      // SLICE MINIPLOT (prefix: 'm_slt')
-      QwtPlot* m_sltPlot;
-      MantidWidgets::RangeSelector* m_sltR1;
-      MantidWidgets::RangeSelector* m_sltR2;
-      QwtPlotCurve* m_sltDataCurve;
-      QtTreePropertyBrowser* m_sltTree;
-      QMap<QString, QtProperty*> m_sltProp;
-      QtDoublePropertyManager* m_sltDblMng;
-      QtBoolPropertyManager* m_sltBlnMng;
-      QtGroupPropertyManager* m_sltGrpMng;
-
-      C2ETab* m_tab_trans;
-      C2ETab* m_tab_moments;
-    };
-  }
-}
-
-#endif // MANTIDQTCUSTOMINTERFACES_INDIRECT_H_
diff --git a/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/IndirectCalibration.h b/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/IndirectCalibration.h
new file mode 100644
index 0000000000000000000000000000000000000000..06d26db630bb99e5f736cd1a6c51d097e6c8737f
--- /dev/null
+++ b/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/IndirectCalibration.h
@@ -0,0 +1,69 @@
+#ifndef MANTIDQTCUSTOMINTERFACES_INDIRECTCALIBRATION_H_
+#define MANTIDQTCUSTOMINTERFACES_INDIRECTCALIBRATION_H_
+
+#include "MantidQtCustomInterfaces/IndirectDataReductionTab.h"
+
+#include "MantidKernel/System.h"
+#include "MantidQtCustomInterfaces/UserInputValidator.h"
+
+namespace MantidQt
+{
+namespace CustomInterfaces
+{
+  /** IndirectCalibration
+
+    @author Dan Nixon
+    @date 23/07/2014
+
+    Copyright &copy; 2013 ISIS Rutherford Appleton Laboratory & NScD Oak Ridge National Laboratory
+
+    This file is part of Mantid.
+
+    Mantid is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 3 of the License, or
+    (at your option) any later version.
+
+    Mantid is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+    File change history is stored at: <https://github.com/mantidproject/mantid>
+    Code Documentation is available at: <http://doxygen.mantidproject.org>
+  */
+  class DLLExport IndirectCalibration : public IndirectDataReductionTab
+  {
+    Q_OBJECT
+
+  public:
+    IndirectCalibration(Ui::IndirectDataReduction& uiForm, QWidget * parent = 0);
+    virtual ~IndirectCalibration();
+
+    virtual void setup();
+    virtual void run();
+    virtual bool validate();
+
+  private slots:
+    void calPlotRaw();
+    void calPlotEnergy();
+    void calMinChanged(double);
+    void calMaxChanged(double);
+    void calUpdateRS(QtProperty*, double);
+    void calSetDefaultResolution(Mantid::API::MatrixWorkspace_const_sptr ws);
+    void resCheck(bool state); ///< handles checking/unchecking of "Create RES File" checkbox
+    void intensityScaleMultiplierCheck(bool state); /// Toggle the intensity scale multiplier box
+    void calibValidateIntensity(const QString & text); /// Check that the scale multiplier is valid
+    void setDefaultInstDetails();
+
+  private:
+    void createRESfile(const QString& file);
+
+  };
+} // namespace CustomInterfaces
+} // namespace Mantid
+
+#endif //MANTIDQTCUSTOMINTERFACES_INDIRECTCALIBRATION_H_
diff --git a/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/IndirectConvertToEnergy.h b/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/IndirectConvertToEnergy.h
new file mode 100644
index 0000000000000000000000000000000000000000..b6f4119e651c07f3154c8faa92c2f03d7230e2b7
--- /dev/null
+++ b/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/IndirectConvertToEnergy.h
@@ -0,0 +1,80 @@
+#ifndef MANTIDQTCUSTOMINTERFACES_INDIRECTCONVERTTOENERGY_H_
+#define MANTIDQTCUSTOMINTERFACES_INDIRECTCONVERTTOENERGY_H_
+
+#include "MantidQtCustomInterfaces/IndirectDataReductionTab.h"
+
+#include "MantidKernel/System.h"
+#include "MantidQtCustomInterfaces/Background.h"
+
+namespace MantidQt
+{
+namespace CustomInterfaces
+{
+  /** IndirectConvertToEnergy
+
+    @author Dan Nixon
+    @date 23/07/2014
+
+    Copyright &copy; 2013 ISIS Rutherford Appleton Laboratory & NScD Oak Ridge National Laboratory
+
+    This file is part of Mantid.
+
+    Mantid is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 3 of the License, or
+    (at your option) any later version.
+
+    Mantid is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+    File change history is stored at: <https://github.com/mantidproject/mantid>
+    Code Documentation is available at: <http://doxygen.mantidproject.org>
+  */
+  class DLLExport IndirectConvertToEnergy : public IndirectDataReductionTab
+  {
+    Q_OBJECT
+
+  public:
+    IndirectConvertToEnergy(Ui::IndirectDataReduction& uiForm, QWidget * parent = 0);
+    virtual ~IndirectConvertToEnergy();
+
+    virtual void setup();
+    virtual void run();
+    virtual bool validate();
+
+    void setIDFValues(const QString & prefix);
+
+  private slots:
+    void clearReflectionInfo(); ///< clear various line edit boxes
+    void analyserSelected(int index); ///< set up cbReflection based on Analyser selection
+    void reflectionSelected(int index); ///< set up parameter file values based on reflection
+    void mappingOptionSelected(const QString& groupType); ///< change ui to display appropriate options
+    void backgroundClicked(); ///< handles showing and hiding m_backgroundDialog
+    void backgroundRemoval(); ///< handles data from BG
+    void rebinEntryToggle(bool state); ///< handle checking/unchecking of "Do Not Rebin"
+    void detailedBalanceCheck(bool state); ///< handle checking/unchecking of "Detailed Balance"
+    void scaleMultiplierCheck(bool state); ///< handle checking/unchecking of "Scale: Multiply by"
+    void plotRaw(); ///< plot raw data from instrument
+    void useCalib(bool state); ///< whether to use calib file
+    void calibFileChanged(const QString & calib); ///< sets m_uiForm.ckUseCalib to appropriate value
+    void pbRunEditing();  //< Called when a user starts to type / edit the runs to load.
+    void pbRunFinding();  //< Called when the FileFinder starts finding the files.
+    void pbRunFinished(); //< Called when the FileFinder has finished finding the files.
+
+  private:
+    Background *m_backgroundDialog; ///< background removal dialog
+    bool m_bgRemoval; ///< whether user has set values for BG removal
+
+    QString createMapFile(const QString& groupType); ///< create the mapping file with which to group results
+    QString savePyCode(); ///< create python code as string to save files
+
+  };
+} // namespace CustomInterfaces
+} // namespace Mantid
+
+#endif //MANTIDQTCUSTOMINTERFACES_INDIRECTCONVERTTOENERGY_H_
diff --git a/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/IndirectDataAnalysis.ui b/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/IndirectDataAnalysis.ui
index 6a04851d131e145514a72e22a49783802f96aa8f..71834c647f8f68543354bc0a77dee7728a4d6994 100644
--- a/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/IndirectDataAnalysis.ui
+++ b/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/IndirectDataAnalysis.ui
@@ -52,6 +52,7 @@
            <property name="fileExtensions">
             <stringlist>
              <string>_red.nxs</string>
+             <string>_sqw.nxs</string>
             </stringlist>
            </property>
           </widget>
@@ -1673,7 +1674,7 @@
                </layout>
               </widget>
               <widget class="QWidget" name="absp_pageCylinder">
-               <layout class="QVBoxLayout" name="verticalLayout_5">
+               <layout class="QVBoxLayout" name="absp_cylinder_layout">
                 <property name="margin">
                  <number>0</number>
                 </property>
diff --git a/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/IndirectDataReduction.h b/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/IndirectDataReduction.h
new file mode 100644
index 0000000000000000000000000000000000000000..3806e24b16f97464baa99ed4730e304bd9cec1f7
--- /dev/null
+++ b/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/IndirectDataReduction.h
@@ -0,0 +1,125 @@
+#ifndef MANTIDQTCUSTOMINTERFACES_INDIRECTDATAREDUCTION_H_
+#define MANTIDQTCUSTOMINTERFACES_INDIRECTDATAREDUCTION_H_
+
+//----------------------
+// Includes
+//----------------------
+#include "ui_IndirectDataReduction.h"
+
+#include "MantidQtAPI/AlgorithmRunner.h"
+#include "MantidQtAPI/UserSubWindow.h"
+#include "MantidQtCustomInterfaces/IndirectDataReductionTab.h"
+
+#include <qwt_plot.h>
+#include <qwt_plot_curve.h>
+
+namespace MantidQt
+{
+  namespace CustomInterfaces
+  {
+    //-------------------------------------------
+    // Forward declarations
+    //-------------------------------------------
+    class IndirectDataReductionTab;
+
+    /** 
+    This class defines the IndirectDataReduction interface. It handles the overall instrument settings
+    and sets up the appropriate interface depending on the deltaE mode of the instrument. The deltaE
+    mode is defined in the instrument definition file using the "deltaE-mode".    
+
+    @author Martyn Gigg, Tessella Support Services plc
+    @author Michael Whitty
+
+    Copyright &copy; 2010 ISIS Rutherford Appleton Laboratory & NScD Oak Ridge National Laboratory
+
+    This file is part of Mantid.
+
+    Mantid is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 3 of the License, or
+    (at your option) any later version.
+
+    Mantid is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+    File change history is stored at: <https://github.com/mantidproject/mantid>
+    Code Documentation is available at: <http://doxygen.mantidproject.org>    
+    */
+
+    class IndirectDataReduction : public MantidQt::API::UserSubWindow
+    {
+      Q_OBJECT
+
+    public:
+      /// Default Constructor
+      IndirectDataReduction(QWidget *parent = 0);
+      ///Destructor
+      ~IndirectDataReduction();
+      /// Interface name
+      static std::string name() { return "Indirect Data Reduction"; }
+      // This interface's categories.
+      static QString categoryInfo() { return "Indirect"; }
+
+      /// Initialize the layout
+      virtual void initLayout();
+      /// run Python-based initialisation commands
+      virtual void initLocalPython();
+      /// gather necessary information from Instument Definition Files
+      virtual void setIDFValues(const QString & prefix);
+      /// perform any instrument-specific changes to layout
+      void performInstSpecific();
+
+      void handleDirectoryChange(Mantid::Kernel::ConfigValChangeNotification_ptr pNf); ///< handle POCO event
+
+    private slots:
+      void helpClicked();
+      void runClicked();
+      void instrumentLoadingDone(bool error);
+
+      void userSelectInstrument(const QString& name);
+      void openDirectoryDialog();
+      void showMessageBox(const QString& message); /// Slot showing a message box to the user
+
+    private:
+      void loadSettings();
+      void readSettings();
+      void saveSettings();
+      void setDefaultInstrument(const QString & name);
+      void instrumentSelectChanged(const QString& name);
+      ///// Find path to instrument's _Definition.xml file (and check there is a parameter file).
+      //QString getIDFPath(const QString& prefix);
+      /// set and show an instrument-specific widget
+      void setInstSpecificWidget(const std::string & parameterName, QCheckBox * checkBox, QCheckBox::ToggleState defaultState);
+      virtual void closeEvent(QCloseEvent* close);
+
+      /// The .ui form generated by Qt Designer
+      Ui::IndirectDataReduction m_uiForm;
+      /// Instrument the interface is currently set for.
+      QString m_curInterfaceSetup;
+      /// The settings group
+      QString m_settingsGroup;
+      /// Runner for insturment load algorithm
+      MantidQt::API::AlgorithmRunner* m_algRunner;
+
+      //All indirect tabs
+      IndirectDataReductionTab* m_tab_convert_to_energy;
+      IndirectDataReductionTab* m_tab_sqw;
+      IndirectDataReductionTab* m_tab_diagnostics;
+      IndirectDataReductionTab* m_tab_calibration;
+      IndirectDataReductionTab* m_tab_trans;
+      IndirectDataReductionTab* m_tab_moments;
+
+      Poco::NObserver<IndirectDataReduction, Mantid::Kernel::ConfigValChangeNotification> m_changeObserver; ///< Poco observer for changes in user directory settings
+      QString m_dataDir; ///< default data search directory
+      QString m_saveDir; ///< default data save directory
+    };
+
+  }
+}
+
+#endif //MANTIDQTCUSTOMINTERFACES_INDIRECTDATAREDUCTION_H_
diff --git a/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/ConvertToEnergy.ui b/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/IndirectDataReduction.ui
similarity index 65%
rename from Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/ConvertToEnergy.ui
rename to Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/IndirectDataReduction.ui
index 87753a74cdf8423279774b97341e5323d33c56ff..2d4be200f5744ce799d886298c46dc71d9002e2f 100644
--- a/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/ConvertToEnergy.ui
+++ b/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/IndirectDataReduction.ui
@@ -1,17 +1,17 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <ui version="4.0">
- <class>ConvertToEnergy</class>
- <widget class="QWidget" name="ConvertToEnergy">
+ <class>IndirectDataReduction</class>
+ <widget class="QWidget" name="IndirectDataReduction">
   <property name="geometry">
    <rect>
     <x>0</x>
     <y>0</y>
     <width>621</width>
-    <height>746</height>
+    <height>761</height>
    </rect>
   </property>
   <property name="windowTitle">
-   <string>Convert To Energy Transfer</string>
+   <string>Indirect Data Reduction</string>
   </property>
   <layout class="QVBoxLayout" name="verticalLayout_20">
    <property name="topMargin">
@@ -43,105 +43,83 @@
       </attribute>
       <layout class="QVBoxLayout" name="verticalLayout_2">
        <item>
-        <layout class="QHBoxLayout" name="horizontalLayout_27">
-         <property name="topMargin">
-          <number>0</number>
+        <widget class="QGroupBox" name="gbC2EInstrument">
+         <property name="title">
+          <string>Instrument</string>
          </property>
-         <item>
-          <widget class="QLabel" name="label_2">
-           <property name="text">
-            <string>Instrument</string>
-           </property>
-          </widget>
-         </item>
-         <item>
-          <widget class="MantidQt::MantidWidgets::InstrumentSelector" name="cbInst">
-           <property name="techniques">
-            <stringlist>
-             <string>TOF Direct Geometry Spectroscopy</string>
-             <string>TOF Indirect Geometry Spectroscopy</string>
-            </stringlist>
-           </property>
-          </widget>
-         </item>
-         <item>
-          <widget class="QStackedWidget" name="swInstrument">
-           <property name="lineWidth">
-            <number>0</number>
-           </property>
-           <property name="currentIndex">
-            <number>1</number>
-           </property>
-           <widget class="QWidget" name="page">
-            <layout class="QHBoxLayout" name="horizontalLayout_16">
-             <item>
-              <spacer name="horizontalSpacer_3">
-               <property name="orientation">
-                <enum>Qt::Horizontal</enum>
-               </property>
-               <property name="sizeType">
-                <enum>QSizePolicy::Expanding</enum>
-               </property>
-               <property name="sizeHint" stdset="0">
-                <size>
-                 <width>40</width>
-                 <height>10</height>
-                </size>
-               </property>
-              </spacer>
-             </item>
-            </layout>
+         <layout class="QHBoxLayout" name="horizontalLayout_27">
+          <property name="topMargin">
+           <number>1</number>
+          </property>
+          <item>
+           <widget class="MantidQt::MantidWidgets::InstrumentSelector" name="cbInst">
+            <property name="techniques" stdset="0">
+             <stringlist>
+              <string>TOF Indirect Geometry Spectroscopy</string>
+             </stringlist>
+            </property>
            </widget>
-           <widget class="QWidget" name="page_2">
-            <layout class="QHBoxLayout" name="horizontalLayout">
-             <item>
-              <layout class="QHBoxLayout" name="horizontalLayout_2">
-               <property name="spacing">
-                <number>6</number>
-               </property>
-               <property name="sizeConstraint">
-                <enum>QLayout::SetDefaultConstraint</enum>
-               </property>
-               <item>
-                <widget class="QLabel" name="lbAnalyser">
-                 <property name="text">
-                  <string>Analyser</string>
-                 </property>
-                </widget>
-               </item>
-               <item>
-                <widget class="QComboBox" name="cbAnalyser">
-                 <property name="toolTip">
-                  <string>Select Analyser bank to use.</string>
-                 </property>
-                </widget>
-               </item>
-               <item>
-                <widget class="QLabel" name="lbReflection">
-                 <property name="text">
-                  <string>Reflection</string>
-                 </property>
-                </widget>
-               </item>
-               <item>
-                <widget class="QComboBox" name="cbReflection">
-                 <property name="toolTip">
-                  <string>Select Reflection used for experiment(s).</string>
-                 </property>
-                </widget>
-               </item>
-              </layout>
-             </item>
-            </layout>
+          </item>
+          <item>
+           <spacer name="horizontalSpacer_2">
+            <property name="orientation">
+             <enum>Qt::Horizontal</enum>
+            </property>
+            <property name="sizeHint" stdset="0">
+             <size>
+              <width>40</width>
+              <height>20</height>
+             </size>
+            </property>
+           </spacer>
+          </item>
+          <item>
+           <widget class="QLabel" name="lbAnalyser">
+            <property name="text">
+             <string>Analyser</string>
+            </property>
            </widget>
-          </widget>
-         </item>
-        </layout>
+          </item>
+          <item>
+           <widget class="QComboBox" name="cbAnalyser">
+            <property name="sizePolicy">
+             <sizepolicy hsizetype="Expanding" vsizetype="Fixed">
+              <horstretch>0</horstretch>
+              <verstretch>0</verstretch>
+             </sizepolicy>
+            </property>
+            <property name="toolTip">
+             <string>Select Analyser bank to use.</string>
+            </property>
+           </widget>
+          </item>
+          <item>
+           <widget class="QLabel" name="lbReflection">
+            <property name="text">
+             <string>Reflection</string>
+            </property>
+           </widget>
+          </item>
+          <item>
+           <widget class="QComboBox" name="cbReflection">
+            <property name="sizePolicy">
+             <sizepolicy hsizetype="Expanding" vsizetype="Fixed">
+              <horstretch>0</horstretch>
+              <verstretch>0</verstretch>
+             </sizepolicy>
+            </property>
+            <property name="toolTip">
+             <string>Select Reflection used for experiment(s).</string>
+            </property>
+           </widget>
+          </item>
+         </layout>
+        </widget>
        </item>
        <item>
-        <widget class="QGroupBox" name="gbExperiment">
+        <widget class="QGroupBox" name="gbConvertToEnergyInput">
          <property name="title">
-          <string>Input Files</string>
+          <string>Input</string>
          </property>
          <layout class="QVBoxLayout" name="verticalLayout">
           <property name="spacing">
@@ -156,71 +134,8 @@
              <number>0</number>
             </property>
             <property name="currentIndex">
-             <number>1</number>
+             <number>0</number>
             </property>
-            <widget class="QWidget" name="page_3">
-             <layout class="QVBoxLayout" name="verticalLayout_32">
-              <item>
-               <layout class="QHBoxLayout" name="runFilesLay">
-                <property name="spacing">
-                 <number>9</number>
-                </property>
-                <property name="topMargin">
-                 <number>9</number>
-                </property>
-                <property name="bottomMargin">
-                 <number>6</number>
-                </property>
-                <item>
-                 <widget class="MantidQt::MantidWidgets::MWRunFiles" name="runFiles">
-                  <property name="label" stdset="0">
-                   <string>Runs          </string>
-                  </property>
-                 </widget>
-                </item>
-                <item>
-                 <widget class="QCheckBox" name="ckSumSpecs">
-                  <property name="text">
-                   <string>Sum</string>
-                  </property>
-                 </widget>
-                </item>
-               </layout>
-              </item>
-              <item>
-               <widget class="MantidQt::MantidWidgets::MWRunFiles" name="mapFile">
-                <property name="findRunFiles" stdset="0">
-                 <bool>false</bool>
-                </property>
-                <property name="label" stdset="0">
-                 <string>Map File     </string>
-                </property>
-                <property name="multipleFiles" stdset="0">
-                 <bool>false</bool>
-                </property>
-                <property name="optional" stdset="0">
-                 <bool>true</bool>
-                </property>
-                <property name="algorithmAndProperty" stdset="0">
-                 <string>GroupDetectors|MapFile</string>
-                </property>
-               </widget>
-              </item>
-              <item>
-               <widget class="MantidQt::MantidWidgets::MWRunFiles" name="whiteBeamFile">
-                <property name="label" stdset="0">
-                 <string>Detector Vanadium</string>
-                </property>
-                <property name="multipleFiles" stdset="0">
-                 <bool>false</bool>
-                </property>
-                <property name="optional" stdset="0">
-                 <bool>true</bool>
-                </property>
-               </widget>
-              </item>
-             </layout>
-            </widget>
             <widget class="QWidget" name="page_4">
              <layout class="QVBoxLayout" name="verticalLayout_9">
               <item>
@@ -228,7 +143,7 @@
                 <item>
                  <layout class="QVBoxLayout" name="verticalLayout_6">
                   <item>
-                   <widget class="MantidQt::MantidWidgets::MWRunFiles" name="ind_runFiles">
+                   <widget class="MantidQt::MantidWidgets::MWRunFiles" name="ind_runFiles" native="true">
                     <property name="sizePolicy">
                      <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
                       <horstretch>0</horstretch>
@@ -244,7 +159,7 @@
                    </widget>
                   </item>
                   <item>
-                   <widget class="MantidQt::MantidWidgets::MWRunFiles" name="ind_calibFile">
+                   <widget class="MantidQt::MantidWidgets::MWRunFiles" name="ind_calibFile" native="true">
                     <property name="enabled">
                      <bool>false</bool>
                     </property>
@@ -266,7 +181,7 @@
                     <property name="optional" stdset="0">
                      <bool>true</bool>
                     </property>
-                    <property name="fileExtensions">
+                    <property name="fileExtensions" stdset="0">
                      <stringlist>
                       <string>_calib.nxs</string>
                      </stringlist>
@@ -370,12 +285,12 @@
                    <number>0</number>
                   </property>
                   <property name="currentIndex">
-                   <number>2</number>
+                   <number>0</number>
                   </property>
                   <widget class="QWidget" name="page_11">
                    <layout class="QHBoxLayout" name="horizontalLayout_5">
                     <item>
-                     <widget class="MantidQt::MantidWidgets::MWRunFiles" name="ind_mapFile">
+                     <widget class="MantidQt::MantidWidgets::MWRunFiles" name="ind_mapFile" native="true">
                       <property name="sizePolicy">
                        <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
                         <horstretch>0</horstretch>
@@ -394,7 +309,7 @@
                       <property name="algorithmAndProperty" stdset="0">
                        <string/>
                       </property>
-                      <property name="fileExtensions">
+                      <property name="fileExtensions" stdset="0">
                        <stringlist>
                         <string>.map</string>
                        </stringlist>
@@ -499,7 +414,7 @@
        <item>
         <widget class="QGroupBox" name="gbAnalysis">
          <property name="title">
-          <string>Analysis Options</string>
+          <string>Analysis</string>
          </property>
          <layout class="QGridLayout" name="gridLayout_3">
           <property name="sizeConstraint">
@@ -517,90 +432,8 @@
              <number>0</number>
             </property>
             <property name="currentIndex">
-             <number>1</number>
+             <number>0</number>
             </property>
-            <widget class="QWidget" name="page_5">
-             <layout class="QGridLayout" name="gridLayout_4">
-              <item row="1" column="1">
-               <widget class="QPushButton" name="pbBack">
-                <property name="text">
-                 <string>bg removal: none</string>
-                </property>
-               </widget>
-              </item>
-              <item row="1" column="2">
-               <spacer name="horizontalSpacer_9">
-                <property name="orientation">
-                 <enum>Qt::Horizontal</enum>
-                </property>
-                <property name="sizeHint" stdset="0">
-                 <size>
-                  <width>40</width>
-                  <height>20</height>
-                 </size>
-                </property>
-               </spacer>
-              </item>
-              <item row="1" column="5">
-               <spacer name="horizontalSpacer_6">
-                <property name="orientation">
-                 <enum>Qt::Horizontal</enum>
-                </property>
-                <property name="sizeHint" stdset="0">
-                 <size>
-                  <width>40</width>
-                  <height>20</height>
-                 </size>
-                </property>
-               </spacer>
-              </item>
-              <item row="1" column="0">
-               <spacer name="horizontalSpacer_22">
-                <property name="orientation">
-                 <enum>Qt::Horizontal</enum>
-                </property>
-                <property name="sizeHint" stdset="0">
-                 <size>
-                  <width>40</width>
-                  <height>20</height>
-                 </size>
-                </property>
-               </spacer>
-              </item>
-              <item row="1" column="3">
-               <widget class="QLabel" name="label">
-                <property name="text">
-                 <string>Normalise By</string>
-                </property>
-               </widget>
-              </item>
-              <item row="1" column="4">
-               <widget class="QComboBox" name="cbNormal">
-                <property name="currentIndex">
-                 <number>0</number>
-                </property>
-                <property name="frame">
-                 <bool>true</bool>
-                </property>
-                <item>
-                 <property name="text">
-                  <string>none</string>
-                 </property>
-                </item>
-                <item>
-                 <property name="text">
-                  <string>current</string>
-                 </property>
-                </item>
-                <item>
-                 <property name="text">
-                  <string>monitor-1</string>
-                 </property>
-                </item>
-               </widget>
-              </item>
-             </layout>
-            </widget>
             <widget class="QWidget" name="page_6">
              <layout class="QGridLayout" name="gridLayout_10">
               <item row="1" column="1">
@@ -736,114 +569,6 @@ p, li { white-space: pre-wrap; }
             <property name="currentIndex">
              <number>0</number>
             </property>
-            <widget class="QWidget" name="page_7">
-             <layout class="QHBoxLayout" name="horizontalLayout_3">
-              <item>
-               <widget class="QLabel" name="label_9">
-                <property name="text">
-                 <string>Incident Energy</string>
-                </property>
-               </widget>
-              </item>
-              <item>
-               <widget class="QLineEdit" name="leEGuess">
-                <property name="maximumSize">
-                 <size>
-                  <width>70</width>
-                  <height>16777215</height>
-                 </size>
-                </property>
-               </widget>
-              </item>
-              <item>
-               <widget class="QLabel" name="valGuess">
-                <property name="palette">
-                 <palette>
-                  <active>
-                   <colorrole role="WindowText">
-                    <brush brushstyle="SolidPattern">
-                     <color alpha="255">
-                      <red>170</red>
-                      <green>0</green>
-                      <blue>0</blue>
-                     </color>
-                    </brush>
-                   </colorrole>
-                  </active>
-                  <inactive>
-                   <colorrole role="WindowText">
-                    <brush brushstyle="SolidPattern">
-                     <color alpha="255">
-                      <red>170</red>
-                      <green>0</green>
-                      <blue>0</blue>
-                     </color>
-                    </brush>
-                   </colorrole>
-                  </inactive>
-                  <disabled>
-                   <colorrole role="WindowText">
-                    <brush brushstyle="SolidPattern">
-                     <color alpha="255">
-                      <red>118</red>
-                      <green>116</green>
-                      <blue>108</blue>
-                     </color>
-                    </brush>
-                   </colorrole>
-                  </disabled>
-                 </palette>
-                </property>
-                <property name="text">
-                 <string>*</string>
-                </property>
-                <property name="buddy">
-                 <cstring>leEGuess</cstring>
-                </property>
-               </widget>
-              </item>
-              <item>
-               <widget class="QLabel" name="label_10">
-                <property name="text">
-                 <string>meV</string>
-                </property>
-               </widget>
-              </item>
-              <item>
-               <spacer name="horizontalSpacer_8">
-                <property name="orientation">
-                 <enum>Qt::Horizontal</enum>
-                </property>
-                <property name="sizeHint" stdset="0">
-                 <size>
-                  <width>5</width>
-                  <height>20</height>
-                 </size>
-                </property>
-               </spacer>
-              </item>
-              <item>
-               <widget class="QCheckBox" name="ckFixEi">
-                <property name="text">
-                 <string>Fix Ei</string>
-                </property>
-               </widget>
-              </item>
-              <item>
-               <spacer name="horizontalSpacer_7">
-                <property name="orientation">
-                 <enum>Qt::Horizontal</enum>
-                </property>
-                <property name="sizeHint" stdset="0">
-                 <size>
-                  <width>40</width>
-                  <height>20</height>
-                 </size>
-                </property>
-               </spacer>
-              </item>
-             </layout>
-            </widget>
             <widget class="QWidget" name="page_8">
              <layout class="QHBoxLayout" name="horizontalLayout_4">
               <item>
@@ -930,322 +655,45 @@ p, li { white-space: pre-wrap; }
        <item>
         <widget class="QStackedWidget" name="swRebin">
          <property name="currentIndex">
-          <number>1</number>
+          <number>0</number>
          </property>
-         <widget class="QWidget" name="page_9">
-          <layout class="QVBoxLayout" name="verticalLayout_15">
-           <property name="spacing">
+         <widget class="QWidget" name="page_10">
+          <layout class="QGridLayout" name="gridLayout_7">
+           <property name="margin">
             <number>0</number>
            </property>
-           <property name="margin">
+           <property name="spacing">
             <number>0</number>
            </property>
-           <item>
-            <widget class="QGroupBox" name="gbRebin">
+           <item row="0" column="1">
+            <widget class="QGroupBox" name="gbIndRebin">
              <property name="title">
               <string>Energy Transfer Range (meV)</string>
              </property>
-             <layout class="QVBoxLayout" name="verticalLayout_3">
+             <layout class="QVBoxLayout" name="verticalLayout_14">
               <property name="spacing">
-               <number>0</number>
+               <number>6</number>
               </property>
               <property name="margin">
-               <number>0</number>
+               <number>6</number>
               </property>
               <item>
-               <layout class="QHBoxLayout" name="horizontalLayout_14">
-                <item>
-                 <spacer name="horizontalSpacer_28">
-                  <property name="orientation">
-                   <enum>Qt::Horizontal</enum>
-                  </property>
-                  <property name="sizeHint" stdset="0">
-                   <size>
-                    <width>40</width>
-                    <height>20</height>
-                   </size>
-                  </property>
-                 </spacer>
-                </item>
+               <layout class="QHBoxLayout" name="horizontalLayout_29">
                 <item>
-                 <widget class="QLabel" name="label_19">
+                 <widget class="QLabel" name="labelRebinSteps">
                   <property name="text">
-                   <string>Low</string>
+                   <string>Rebin Steps:</string>
                   </property>
                  </widget>
                 </item>
                 <item>
-                 <widget class="QLineEdit" name="leELow">
-                  <property name="maximumSize">
-                   <size>
-                    <width>70</width>
-                    <height>16777215</height>
-                   </size>
-                  </property>
-                 </widget>
-                </item>
-                <item>
-                 <widget class="QLabel" name="validRebinLow">
-                  <property name="palette">
-                   <palette>
-                    <active>
-                     <colorrole role="WindowText">
-                      <brush brushstyle="SolidPattern">
-                       <color alpha="255">
-                        <red>170</red>
-                        <green>0</green>
-                        <blue>0</blue>
-                       </color>
-                      </brush>
-                     </colorrole>
-                    </active>
-                    <inactive>
-                     <colorrole role="WindowText">
-                      <brush brushstyle="SolidPattern">
-                       <color alpha="255">
-                        <red>170</red>
-                        <green>0</green>
-                        <blue>0</blue>
-                       </color>
-                      </brush>
-                     </colorrole>
-                    </inactive>
-                    <disabled>
-                     <colorrole role="WindowText">
-                      <brush brushstyle="SolidPattern">
-                       <color alpha="255">
-                        <red>118</red>
-                        <green>116</green>
-                        <blue>108</blue>
-                       </color>
-                      </brush>
-                     </colorrole>
-                    </disabled>
-                   </palette>
-                  </property>
-                  <property name="text">
-                   <string>*</string>
-                  </property>
-                  <property name="buddy">
-                   <cstring>leELow</cstring>
-                  </property>
-                 </widget>
-                </item>
-                <item>
-                 <widget class="QLabel" name="label_20">
-                  <property name="text">
-                   <string>Width</string>
-                  </property>
-                 </widget>
-                </item>
-                <item>
-                 <widget class="QLineEdit" name="leEWidth">
-                  <property name="maximumSize">
-                   <size>
-                    <width>70</width>
-                    <height>16777215</height>
-                   </size>
-                  </property>
-                 </widget>
-                </item>
-                <item>
-                 <widget class="QLabel" name="validRebinWidth">
-                  <property name="palette">
-                   <palette>
-                    <active>
-                     <colorrole role="WindowText">
-                      <brush brushstyle="SolidPattern">
-                       <color alpha="255">
-                        <red>170</red>
-                        <green>0</green>
-                        <blue>0</blue>
-                       </color>
-                      </brush>
-                     </colorrole>
-                    </active>
-                    <inactive>
-                     <colorrole role="WindowText">
-                      <brush brushstyle="SolidPattern">
-                       <color alpha="255">
-                        <red>170</red>
-                        <green>0</green>
-                        <blue>0</blue>
-                       </color>
-                      </brush>
-                     </colorrole>
-                    </inactive>
-                    <disabled>
-                     <colorrole role="WindowText">
-                      <brush brushstyle="SolidPattern">
-                       <color alpha="255">
-                        <red>118</red>
-                        <green>116</green>
-                        <blue>108</blue>
-                       </color>
-                      </brush>
-                     </colorrole>
-                    </disabled>
-                   </palette>
-                  </property>
-                  <property name="text">
-                   <string>*</string>
-                  </property>
-                  <property name="buddy">
-                   <cstring>leEWidth</cstring>
-                  </property>
-                 </widget>
-                </item>
-                <item>
-                 <widget class="QLabel" name="label_21">
-                  <property name="text">
-                   <string>High</string>
-                  </property>
-                 </widget>
-                </item>
-                <item>
-                 <widget class="QLineEdit" name="leEHigh">
-                  <property name="maximumSize">
-                   <size>
-                    <width>70</width>
-                    <height>16777215</height>
-                   </size>
-                  </property>
-                 </widget>
-                </item>
-                <item>
-                 <widget class="QLabel" name="validRebinHigh">
-                  <property name="palette">
-                   <palette>
-                    <active>
-                     <colorrole role="WindowText">
-                      <brush brushstyle="SolidPattern">
-                       <color alpha="255">
-                        <red>170</red>
-                        <green>0</green>
-                        <blue>0</blue>
-                       </color>
-                      </brush>
-                     </colorrole>
-                    </active>
-                    <inactive>
-                     <colorrole role="WindowText">
-                      <brush brushstyle="SolidPattern">
-                       <color alpha="255">
-                        <red>170</red>
-                        <green>0</green>
-                        <blue>0</blue>
-                       </color>
-                      </brush>
-                     </colorrole>
-                    </inactive>
-                    <disabled>
-                     <colorrole role="WindowText">
-                      <brush brushstyle="SolidPattern">
-                       <color alpha="255">
-                        <red>118</red>
-                        <green>116</green>
-                        <blue>108</blue>
-                       </color>
-                      </brush>
-                     </colorrole>
-                    </disabled>
-                   </palette>
-                  </property>
-                  <property name="text">
-                   <string>*</string>
-                  </property>
-                  <property name="buddy">
-                   <cstring>leEHigh</cstring>
-                  </property>
-                 </widget>
-                </item>
-                <item>
-                 <spacer name="horizontalSpacer_29">
-                  <property name="orientation">
-                   <enum>Qt::Horizontal</enum>
-                  </property>
-                  <property name="sizeHint" stdset="0">
-                   <size>
-                    <width>40</width>
-                    <height>20</height>
-                   </size>
-                  </property>
-                 </spacer>
-                </item>
-               </layout>
-              </item>
-             </layout>
-            </widget>
-           </item>
-           <item>
-            <widget class="QGroupBox" name="gbSampleEnv">
-             <property name="title">
-              <string>Sample Environment</string>
-             </property>
-             <layout class="QHBoxLayout" name="horizontalLayout_25">
-              <property name="margin">
-               <number>0</number>
-              </property>
-              <item>
-               <widget class="QLabel" name="label_5">
-                <property name="text">
-                 <string>SE Motor</string>
-                </property>
-               </widget>
-              </item>
-              <item>
-               <widget class="QLineEdit" name="motorNameEdit"/>
-              </item>
-              <item>
-               <widget class="QLabel" name="label_6">
-                <property name="text">
-                 <string>offset</string>
-                </property>
-               </widget>
-              </item>
-              <item>
-               <widget class="QLineEdit" name="seOffsetEdit">
-                <property name="toolTip">
-                 <string> Psi = Motor Value + Offset</string>
-                </property>
-               </widget>
-              </item>
-             </layout>
-            </widget>
-           </item>
-          </layout>
-         </widget>
-         <widget class="QWidget" name="page_10">
-          <layout class="QGridLayout" name="gridLayout_7">
-           <property name="margin">
-            <number>0</number>
-           </property>
-           <property name="spacing">
-            <number>0</number>
-           </property>
-           <item row="0" column="1">
-            <widget class="QGroupBox" name="gbIndRebin">
-             <property name="title">
-              <string>Energy Transfer Range (meV)</string>
-             </property>
-             <layout class="QVBoxLayout" name="verticalLayout_14">
-              <property name="spacing">
-               <number>6</number>
-              </property>
-              <property name="margin">
-               <number>6</number>
-              </property>
-              <item>
-               <layout class="QHBoxLayout" name="horizontalLayout_29">
-                <item>
-                 <widget class="QLabel" name="label_7">
-                  <property name="text">
-                   <string>Rebin Steps:</string>
+                 <widget class="QComboBox" name="comboRebinType">
+                  <property name="sizePolicy">
+                   <sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
+                    <horstretch>0</horstretch>
+                    <verstretch>0</verstretch>
+                   </sizepolicy>
                   </property>
-                 </widget>
-                </item>
-                <item>
-                 <widget class="QComboBox" name="cbIndRebType">
                   <item>
                    <property name="text">
                     <string>Single</string>
@@ -1280,17 +728,17 @@ p, li { white-space: pre-wrap; }
                        <number>6</number>
                       </property>
                       <item>
-                       <widget class="QLabel" name="rebin_lbLow">
+                       <widget class="QLabel" name="labelRebinLow">
                         <property name="text">
                          <string>Low</string>
                         </property>
                         <property name="buddy">
-                         <cstring>rebin_leELow</cstring>
+                         <cstring>entryRebinLow</cstring>
                         </property>
                        </widget>
                       </item>
                       <item>
-                       <widget class="QLineEdit" name="rebin_leELow">
+                       <widget class="QLineEdit" name="entryRebinLow">
                         <property name="sizePolicy">
                          <sizepolicy hsizetype="Expanding" vsizetype="Fixed">
                           <horstretch>0</horstretch>
@@ -1330,17 +778,17 @@ p, li { white-space: pre-wrap; }
                        </spacer>
                       </item>
                       <item>
-                       <widget class="QLabel" name="rebin_lbWidth">
+                       <widget class="QLabel" name="labelRebinWidth">
                         <property name="text">
                          <string>Width</string>
                         </property>
                         <property name="buddy">
-                         <cstring>rebin_leEWidth</cstring>
+                         <cstring>entryRebinWidth</cstring>
                         </property>
                        </widget>
                       </item>
                       <item>
-                       <widget class="QLineEdit" name="rebin_leEWidth">
+                       <widget class="QLineEdit" name="entryRebinWidth">
                         <property name="toolTip">
                          <string>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
 &lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
@@ -1374,17 +822,17 @@ p, li { white-space: pre-wrap; }
                        </spacer>
                       </item>
                       <item>
-                       <widget class="QLabel" name="rebin_lbHigh">
+                       <widget class="QLabel" name="labelRebinHigh">
                         <property name="text">
                          <string>High</string>
                         </property>
                         <property name="buddy">
-                         <cstring>rebin_leEHigh</cstring>
+                         <cstring>entryRebinHigh</cstring>
                         </property>
                        </widget>
                       </item>
                       <item>
-                       <widget class="QLineEdit" name="rebin_leEHigh">
+                       <widget class="QLineEdit" name="entryRebinHigh">
                         <property name="toolTip">
                          <string>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
 &lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
@@ -1417,14 +865,14 @@ p, li { white-space: pre-wrap; }
                      <number>0</number>
                     </property>
                     <item>
-                     <widget class="QLabel" name="lbRebinString">
+                     <widget class="QLabel" name="labelRebinString">
                       <property name="text">
                        <string>Rebin String</string>
                       </property>
                      </widget>
                     </item>
                     <item>
-                     <widget class="QLineEdit" name="leRebinString"/>
+                     <widget class="QLineEdit" name="entryRebinString"/>
                     </item>
                    </layout>
                   </widget>
@@ -1475,7 +923,7 @@ p, li { white-space: pre-wrap; }
        <item>
         <widget class="QGroupBox" name="gbSave">
          <property name="title">
-          <string>Output Options</string>
+          <string>Output</string>
          </property>
          <layout class="QGridLayout" name="gridLayout_8">
           <property name="topMargin">
@@ -1557,57 +1005,6 @@ p, li { white-space: pre-wrap; }
             <property name="currentIndex">
              <number>0</number>
             </property>
-            <widget class="QWidget" name="page_15">
-             <layout class="QVBoxLayout" name="verticalLayout_13">
-              <item>
-               <layout class="QHBoxLayout" name="et_save">
-                <item>
-                 <widget class="QLabel" name="save_lbFile">
-                  <property name="text">
-                   <string>Filename</string>
-                  </property>
-                 </widget>
-                </item>
-                <item>
-                 <widget class="QLineEdit" name="leNameSPE">
-                  <property name="enabled">
-                   <bool>false</bool>
-                  </property>
-                  <property name="minimumSize">
-                   <size>
-                    <width>250</width>
-                    <height>0</height>
-                   </size>
-                  </property>
-                 </widget>
-                </item>
-                <item>
-                 <widget class="QPushButton" name="pbBrowseSPE">
-                  <property name="text">
-                   <string>Browse</string>
-                  </property>
-                 </widget>
-                </item>
-                <item>
-                 <spacer name="horizontalSpacer_2">
-                  <property name="orientation">
-                   <enum>Qt::Horizontal</enum>
-                  </property>
-                  <property name="sizeType">
-                   <enum>QSizePolicy::MinimumExpanding</enum>
-                  </property>
-                  <property name="sizeHint" stdset="0">
-                   <size>
-                    <width>40</width>
-                    <height>20</height>
-                   </size>
-                  </property>
-                 </spacer>
-                </item>
-               </layout>
-              </item>
-             </layout>
-            </widget>
             <widget class="QWidget" name="page_16">
              <layout class="QVBoxLayout" name="verticalLayout_18">
               <item>
@@ -1711,218 +1108,237 @@ Later steps in the process (saving, renaming) will not be done.</string>
          <item>
           <layout class="QGridLayout" name="gridLayout">
            <item row="0" column="0">
-            <layout class="QHBoxLayout" name="horizontalLayout_33">
-             <item>
-              <widget class="MantidQt::MantidWidgets::MWRunFiles" name="cal_leRunNo">
-               <property name="sizePolicy">
-                <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
-                 <horstretch>0</horstretch>
-                 <verstretch>41</verstretch>
-                </sizepolicy>
-               </property>
-               <property name="label" stdset="0">
-                <string>Run No</string>
-               </property>
-               <property name="multipleFiles" stdset="0">
-                <bool>true</bool>
-               </property>
-               <property name="algorithmAndProperty" stdset="0">
-                <string/>
-               </property>
-               <property name="fileExtensions">
-                <stringlist>
-                 <string>.raw</string>
-                </stringlist>
-               </property>
-              </widget>
-             </item>
-             <item>
-              <widget class="QPushButton" name="cal_pbPlot">
-               <property name="toolTip">
-                <string>Plot first detector spectra</string>
-               </property>
-               <property name="text">
-                <string>Plot Raw</string>
-               </property>
-              </widget>
-             </item>
-            </layout>
-           </item>
-           <item row="1" column="0">
-            <layout class="QHBoxLayout" name="horizontalLayout_18">
-             <item>
-              <widget class="QCheckBox" name="cal_ckIntensityScaleMultiplier">
-               <property name="text">
-                <string>Intensity Scale Factor</string>
-               </property>
-              </widget>
-             </item>
-             <item>
-              <widget class="QLineEdit" name="cal_leIntensityScaleMultiplier">
-               <property name="enabled">
-                <bool>false</bool>
-               </property>
-               <property name="sizePolicy">
-                <sizepolicy hsizetype="Minimum" vsizetype="Fixed">
-                 <horstretch>0</horstretch>
-                 <verstretch>0</verstretch>
-                </sizepolicy>
-               </property>
-               <property name="maximumSize">
-                <size>
-                 <width>50</width>
-                 <height>16777215</height>
-                </size>
-               </property>
-               <property name="text">
-                <string>1.0</string>
-               </property>
-               <property name="placeholderText">
-                <string/>
-               </property>
-              </widget>
-             </item>
-             <item>
-              <widget class="QLabel" name="cal_valIntensityScaleMultiplier">
-               <property name="sizePolicy">
-                <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
-                 <horstretch>10</horstretch>
-                 <verstretch>20</verstretch>
-                </sizepolicy>
-               </property>
-               <property name="minimumSize">
-                <size>
-                 <width>10</width>
-                 <height>0</height>
-                </size>
-               </property>
-               <property name="palette">
-                <palette>
-                 <active>
-                  <colorrole role="WindowText">
-                   <brush brushstyle="SolidPattern">
-                    <color alpha="255">
-                     <red>170</red>
-                     <green>0</green>
-                     <blue>0</blue>
-                    </color>
-                   </brush>
-                  </colorrole>
-                 </active>
-                 <inactive>
-                  <colorrole role="WindowText">
-                   <brush brushstyle="SolidPattern">
-                    <color alpha="255">
-                     <red>170</red>
-                     <green>0</green>
-                     <blue>0</blue>
-                    </color>
-                   </brush>
-                  </colorrole>
-                 </inactive>
-                 <disabled>
-                  <colorrole role="WindowText">
-                   <brush brushstyle="SolidPattern">
-                    <color alpha="255">
-                     <red>118</red>
-                     <green>116</green>
-                     <blue>108</blue>
-                    </color>
-                   </brush>
-                  </colorrole>
-                 </disabled>
-                </palette>
-               </property>
-               <property name="text">
-                <string>*</string>
-               </property>
-              </widget>
-             </item>
-             <item>
-              <spacer name="horizontalSpacer_23">
-               <property name="orientation">
-                <enum>Qt::Horizontal</enum>
-               </property>
-               <property name="sizeType">
-                <enum>QSizePolicy::Expanding</enum>
-               </property>
-               <property name="sizeHint" stdset="0">
-                <size>
-                 <width>40</width>
-                 <height>20</height>
-                </size>
-               </property>
-              </spacer>
-             </item>
-            </layout>
+            <widget class="QGroupBox" name="gbCalibrationInput">
+             <property name="title">
+              <string>Input</string>
+             </property>
+             <layout class="QVBoxLayout" name="verticalLayout_11">
+              <item>
+               <layout class="QHBoxLayout" name="loCalibInputFile">
+                <item>
+                 <widget class="MantidQt::MantidWidgets::MWRunFiles" name="cal_leRunNo" native="true">
+                  <property name="sizePolicy">
+                   <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
+                    <horstretch>0</horstretch>
+                    <verstretch>41</verstretch>
+                   </sizepolicy>
+                  </property>
+                  <property name="label" stdset="0">
+                   <string>Run No</string>
+                  </property>
+                  <property name="multipleFiles" stdset="0">
+                   <bool>true</bool>
+                  </property>
+                  <property name="algorithmAndProperty" stdset="0">
+                   <string/>
+                  </property>
+                  <property name="fileExtensions" stdset="0">
+                   <stringlist>
+                    <string>.raw</string>
+                   </stringlist>
+                  </property>
+                 </widget>
+                </item>
+                <item>
+                 <widget class="QPushButton" name="cal_pbPlot">
+                  <property name="toolTip">
+                   <string>Plot first detector spectra</string>
+                  </property>
+                  <property name="text">
+                   <string>Plot Raw</string>
+                  </property>
+                 </widget>
+                </item>
+               </layout>
+              </item>
+              <item>
+               <layout class="QHBoxLayout" name="loCalibScaleFactor">
+                <item>
+                 <widget class="QCheckBox" name="cal_ckIntensityScaleMultiplier">
+                  <property name="text">
+                   <string>Intensity Scale Factor</string>
+                  </property>
+                 </widget>
+                </item>
+                <item>
+                 <widget class="QLineEdit" name="cal_leIntensityScaleMultiplier">
+                  <property name="enabled">
+                   <bool>false</bool>
+                  </property>
+                  <property name="sizePolicy">
+                   <sizepolicy hsizetype="Minimum" vsizetype="Fixed">
+                    <horstretch>0</horstretch>
+                    <verstretch>0</verstretch>
+                   </sizepolicy>
+                  </property>
+                  <property name="maximumSize">
+                   <size>
+                    <width>50</width>
+                    <height>16777215</height>
+                   </size>
+                  </property>
+                  <property name="text">
+                   <string>1.0</string>
+                  </property>
+                  <property name="placeholderText">
+                   <string/>
+                  </property>
+                 </widget>
+                </item>
+                <item>
+                 <widget class="QLabel" name="cal_valIntensityScaleMultiplier">
+                  <property name="sizePolicy">
+                   <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
+                    <horstretch>10</horstretch>
+                    <verstretch>20</verstretch>
+                   </sizepolicy>
+                  </property>
+                  <property name="minimumSize">
+                   <size>
+                    <width>10</width>
+                    <height>0</height>
+                   </size>
+                  </property>
+                  <property name="palette">
+                   <palette>
+                    <active>
+                     <colorrole role="WindowText">
+                      <brush brushstyle="SolidPattern">
+                       <color alpha="255">
+                        <red>170</red>
+                        <green>0</green>
+                        <blue>0</blue>
+                       </color>
+                      </brush>
+                     </colorrole>
+                    </active>
+                    <inactive>
+                     <colorrole role="WindowText">
+                      <brush brushstyle="SolidPattern">
+                       <color alpha="255">
+                        <red>170</red>
+                        <green>0</green>
+                        <blue>0</blue>
+                       </color>
+                      </brush>
+                     </colorrole>
+                    </inactive>
+                    <disabled>
+                     <colorrole role="WindowText">
+                      <brush brushstyle="SolidPattern">
+                       <color alpha="255">
+                        <red>118</red>
+                        <green>116</green>
+                        <blue>108</blue>
+                       </color>
+                      </brush>
+                     </colorrole>
+                    </disabled>
+                   </palette>
+                  </property>
+                  <property name="text">
+                   <string>*</string>
+                  </property>
+                 </widget>
+                </item>
+                <item>
+                 <spacer name="horizontalSpacer_23">
+                  <property name="orientation">
+                   <enum>Qt::Horizontal</enum>
+                  </property>
+                  <property name="sizeType">
+                   <enum>QSizePolicy::Expanding</enum>
+                  </property>
+                  <property name="sizeHint" stdset="0">
+                   <size>
+                    <width>40</width>
+                    <height>20</height>
+                   </size>
+                  </property>
+                 </spacer>
+                </item>
+               </layout>
+              </item>
+             </layout>
+            </widget>
            </item>
           </layout>
          </item>
         </layout>
        </item>
        <item>
-        <layout class="QHBoxLayout" name="horizontalLayout_20">
-         <item>
-          <layout class="QVBoxLayout" name="cal_treeCal"/>
-         </item>
-         <item>
-          <layout class="QVBoxLayout" name="cal_plotCal"/>
-         </item>
-        </layout>
+        <widget class="QGroupBox" name="gbCalibration">
+         <property name="title">
+          <string>Calibration</string>
+         </property>
+         <layout class="QHBoxLayout" name="horizontalLayout_20">
+          <item>
+           <layout class="QVBoxLayout" name="cal_treeCal"/>
+          </item>
+          <item>
+           <layout class="QVBoxLayout" name="cal_plotCal"/>
+          </item>
+         </layout>
+        </widget>
        </item>
        <item>
-        <layout class="QHBoxLayout" name="cal_plots">
-         <item>
-          <layout class="QVBoxLayout" name="cal_treeRes">
-           <item>
-            <layout class="QGridLayout" name="gridLayout_5">
-             <item row="1" column="0">
-              <widget class="QCheckBox" name="cal_ckResScale">
-               <property name="enabled">
-                <bool>false</bool>
-               </property>
-               <property name="text">
-                <string>Scale RES:</string>
-               </property>
-              </widget>
-             </item>
-             <item row="1" column="1">
-              <widget class="QLineEdit" name="cal_leResScale">
-               <property name="enabled">
-                <bool>false</bool>
-               </property>
-               <property name="sizePolicy">
-                <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
-                 <horstretch>0</horstretch>
-                 <verstretch>0</verstretch>
-                </sizepolicy>
-               </property>
-               <property name="text">
-                <string>1.0</string>
-               </property>
-               <property name="placeholderText">
-                <string/>
-               </property>
-              </widget>
-             </item>
-             <item row="0" column="0" colspan="2">
-              <widget class="QCheckBox" name="cal_ckRES">
-               <property name="toolTip">
-                <string>Create RES file</string>
-               </property>
-               <property name="text">
-                <string>Create RES File</string>
-               </property>
-              </widget>
-             </item>
-            </layout>
-           </item>
-          </layout>
-         </item>
-         <item>
-          <layout class="QVBoxLayout" name="cal_plotRes"/>
-         </item>
-        </layout>
+        <widget class="QGroupBox" name="gbResolution">
+         <property name="title">
+          <string>Resolution</string>
+         </property>
+         <layout class="QHBoxLayout" name="cal_plots">
+          <item>
+           <layout class="QVBoxLayout" name="cal_treeRes">
+            <item>
+             <layout class="QGridLayout" name="gridLayout_5">
+              <item row="1" column="0">
+               <widget class="QCheckBox" name="cal_ckResScale">
+                <property name="enabled">
+                 <bool>false</bool>
+                </property>
+                <property name="text">
+                 <string>Scale RES:</string>
+                </property>
+               </widget>
+              </item>
+              <item row="1" column="1">
+               <widget class="QLineEdit" name="cal_leResScale">
+                <property name="enabled">
+                 <bool>false</bool>
+                </property>
+                <property name="sizePolicy">
+                 <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
+                  <horstretch>0</horstretch>
+                  <verstretch>0</verstretch>
+                 </sizepolicy>
+                </property>
+                <property name="text">
+                 <string>1.0</string>
+                </property>
+                <property name="placeholderText">
+                 <string/>
+                </property>
+               </widget>
+              </item>
+              <item row="0" column="0" colspan="2">
+               <widget class="QCheckBox" name="cal_ckRES">
+                <property name="toolTip">
+                 <string>Create RES file</string>
+                </property>
+                <property name="text">
+                 <string>Create RES File</string>
+                </property>
+               </widget>
+              </item>
+             </layout>
+            </item>
+           </layout>
+          </item>
+          <item>
+           <layout class="QVBoxLayout" name="cal_plotRes"/>
+          </item>
+         </layout>
+        </widget>
        </item>
        <item>
         <spacer name="verticalSpacer_4">
@@ -1940,7 +1356,7 @@ Later steps in the process (saving, renaming) will not be done.</string>
        <item>
         <widget class="QGroupBox" name="slice_outputOptions">
          <property name="title">
-          <string>Output Options</string>
+          <string>Output</string>
          </property>
          <layout class="QVBoxLayout" name="verticalLayout_5">
           <item>
@@ -2008,15 +1424,15 @@ Later steps in the process (saving, renaming) will not be done.</string>
       </attribute>
       <layout class="QVBoxLayout" name="verticalLayout_25">
        <item>
-        <widget class="QGroupBox" name="slice_gbTimeSlice">
+        <widget class="QGroupBox" name="gbDiagnosticsInput">
          <property name="title">
-          <string>Time Slice</string>
+          <string>Input</string>
          </property>
-         <layout class="QVBoxLayout" name="verticalLayout_26">
+         <layout class="QVBoxLayout" name="verticalLayout_4">
           <item>
-           <layout class="QHBoxLayout" name="horizontalLayout_36">
+           <layout class="QHBoxLayout" name="loDiagnosticsInputFile">
             <item>
-             <widget class="MantidQt::MantidWidgets::MWRunFiles" name="slice_inputFile">
+             <widget class="MantidQt::MantidWidgets::MWRunFiles" name="slice_inputFile" native="true">
               <property name="sizePolicy">
                <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
                 <horstretch>0</horstretch>
@@ -2032,7 +1448,7 @@ Later steps in the process (saving, renaming) will not be done.</string>
               <property name="multipleFiles" stdset="0">
                <bool>true</bool>
               </property>
-              <property name="fileExtensions">
+              <property name="fileExtensions" stdset="0">
                <stringlist>
                 <string>.raw</string>
                </stringlist>
@@ -2049,7 +1465,7 @@ Later steps in the process (saving, renaming) will not be done.</string>
            </layout>
           </item>
           <item>
-           <layout class="QHBoxLayout" name="horizontalLayout_37">
+           <layout class="QHBoxLayout" name="loDiagnosticsCalibrationFile">
             <item>
              <widget class="QCheckBox" name="slice_ckUseCalib">
               <property name="text">
@@ -2058,7 +1474,7 @@ Later steps in the process (saving, renaming) will not be done.</string>
              </widget>
             </item>
             <item>
-             <widget class="MantidQt::MantidWidgets::MWRunFiles" name="slice_calibFile">
+             <widget class="MantidQt::MantidWidgets::MWRunFiles" name="slice_calibFile" native="true">
               <property name="enabled">
                <bool>false</bool>
               </property>
@@ -2080,7 +1496,7 @@ Later steps in the process (saving, renaming) will not be done.</string>
               <property name="optional" stdset="0">
                <bool>true</bool>
               </property>
-              <property name="fileExtensions">
+              <property name="fileExtensions" stdset="0">
                <stringlist>
                 <string>_calib.nxs</string>
                </stringlist>
@@ -2089,8 +1505,17 @@ Later steps in the process (saving, renaming) will not be done.</string>
             </item>
            </layout>
           </item>
+         </layout>
+        </widget>
+       </item>
+       <item>
+        <widget class="QGroupBox" name="gbTimeSlice">
+         <property name="title">
+          <string>Time Slice</string>
+         </property>
+         <layout class="QVBoxLayout" name="verticalLayout_26">
           <item>
-           <layout class="QHBoxLayout" name="horizontalLayout_19">
+           <layout class="QHBoxLayout" name="loTimeSlice">
             <item>
              <layout class="QVBoxLayout" name="slice_properties"/>
             </item>
@@ -2116,13 +1541,13 @@ Later steps in the process (saving, renaming) will not be done.</string>
         </spacer>
        </item>
        <item>
-        <widget class="QGroupBox" name="diag_outputOptions">
+        <widget class="QGroupBox" name="gbDiagnosticsOutput">
          <property name="title">
-          <string>Output Options</string>
+          <string>Output</string>
          </property>
          <layout class="QVBoxLayout" name="verticalLayout_30">
           <item>
-           <layout class="QHBoxLayout" name="horizontalLayout_39">
+           <layout class="QHBoxLayout" name="loDiagnosticsOutputOptions">
             <item>
              <widget class="QCheckBox" name="slice_ckVerbose">
               <property name="enabled">
@@ -2186,47 +1611,56 @@ Later steps in the process (saving, renaming) will not be done.</string>
       </attribute>
       <layout class="QVBoxLayout" name="verticalLayout_17">
        <item>
-        <layout class="QGridLayout" name="gridLayout_2">
-         <item row="0" column="1">
-          <widget class="MantidQt::MantidWidgets::MWRunFiles" name="transInputFile">
-           <property name="label" stdset="0">
-            <string/>
-           </property>
-           <property name="fileExtensions">
-            <stringlist>
-             <string>.raw</string>
-            </stringlist>
-           </property>
-          </widget>
-         </item>
-         <item row="1" column="1">
-          <widget class="MantidQt::MantidWidgets::MWRunFiles" name="transCanFile">
-           <property name="label" stdset="0">
-            <string/>
-           </property>
-           <property name="fileExtensions">
-            <stringlist>
-             <string>.raw</string>
-            </stringlist>
-           </property>
-          </widget>
-         </item>
-         <item row="0" column="0">
-          <widget class="QLabel" name="label_3">
-           <property name="text">
-            <string>Sample File: </string>
-           </property>
-          </widget>
-         </item>
-         <item row="1" column="0">
-          <widget class="QLabel" name="label_8">
-           <property name="text">
-            <string>Can/Background File:</string>
-           </property>
-          </widget>
-         </item>
-         <item row="2" column="0">
-          <spacer name="verticalSpacer_3">
+        <widget class="QGroupBox" name="gbTransmissionInput">
+         <property name="title">
+          <string>Input</string>
+         </property>
+         <layout class="QGridLayout" name="gridLayout_2">
+          <item row="0" column="1">
+           <widget class="MantidQt::MantidWidgets::MWRunFiles" name="transInputFile" native="true">
+            <property name="label" stdset="0">
+             <string/>
+            </property>
+            <property name="fileExtensions" stdset="0">
+             <stringlist>
+              <string>.raw</string>
+             </stringlist>
+            </property>
+           </widget>
+          </item>
+          <item row="1" column="1">
+           <widget class="MantidQt::MantidWidgets::MWRunFiles" name="transCanFile" native="true">
+            <property name="label" stdset="0">
+             <string/>
+            </property>
+            <property name="fileExtensions" stdset="0">
+             <stringlist>
+              <string>.raw</string>
+             </stringlist>
+            </property>
+           </widget>
+          </item>
+          <item row="0" column="0">
+           <widget class="QLabel" name="label_3">
+            <property name="text">
+             <string>Sample File: </string>
+            </property>
+           </widget>
+          </item>
+          <item row="1" column="0">
+           <widget class="QLabel" name="label_8">
+            <property name="text">
+             <string>Can/Background File:</string>
+            </property>
+           </widget>
+          </item>
+         </layout>
+        </widget>
+       </item>
+       <item>
+        <layout class="QVBoxLayout" name="verticalLayout_3">
+         <item>
+          <spacer name="verticalSpacer">
            <property name="orientation">
             <enum>Qt::Vertical</enum>
            </property>
@@ -2243,7 +1677,7 @@ Later steps in the process (saving, renaming) will not be done.</string>
        <item>
         <widget class="QGroupBox" name="trans_OutputOptions">
          <property name="title">
-          <string>Output Options</string>
+          <string>Output</string>
          </property>
          <layout class="QVBoxLayout" name="verticalLayout_29">
           <item>
@@ -2323,14 +1757,14 @@ Later steps in the process (saving, renaming) will not be done.</string>
          </property>
          <layout class="QVBoxLayout" name="verticalLayout_12">
           <item>
-           <widget class="MantidQt::MantidWidgets::DataSelector" name="sqw_dsSampleInput">
+           <widget class="MantidQt::MantidWidgets::DataSelector" name="sqw_dsSampleInput" native="true">
             <property name="sizePolicy">
              <sizepolicy hsizetype="Minimum" vsizetype="Fixed">
               <horstretch>0</horstretch>
               <verstretch>0</verstretch>
              </sizepolicy>
             </property>
-            <property name="autoLoad">
+            <property name="autoLoad" stdset="0">
              <bool>false</bool>
             </property>
             <property name="loadLabelText" stdset="0">
@@ -2693,7 +2127,7 @@ Later steps in the process (saving, renaming) will not be done.</string>
        <item>
         <widget class="QGroupBox" name="sqw_outputOptions">
          <property name="title">
-          <string>Output Options</string>
+          <string>Output</string>
          </property>
          <layout class="QVBoxLayout" name="verticalLayout_27">
           <item>
@@ -2797,7 +2231,7 @@ Later steps in the process (saving, renaming) will not be done.</string>
           <item>
            <layout class="QGridLayout" name="moment_gridLayout_9">
             <item row="0" column="0" colspan="2">
-             <widget class="MantidQt::MantidWidgets::DataSelector" name="moment_dsInput">
+             <widget class="MantidQt::MantidWidgets::DataSelector" name="moment_dsInput" native="true">
               <property name="sizePolicy">
                <sizepolicy hsizetype="Minimum" vsizetype="Fixed">
                 <horstretch>0</horstretch>
@@ -2817,7 +2251,7 @@ Later steps in the process (saving, renaming) will not be done.</string>
                 <string>_sqw.nxs</string>
                </stringlist>
               </property>
-              <property name="showLoad">
+              <property name="showLoad" stdset="0">
                <bool>false</bool>
               </property>
              </widget>
@@ -2909,7 +2343,7 @@ Later steps in the process (saving, renaming) will not be done.</string>
        <item>
         <widget class="QGroupBox" name="groupBox_2">
          <property name="title">
-          <string>Output Options</string>
+          <string>Output</string>
          </property>
          <layout class="QVBoxLayout" name="moment_verticalLayout_26">
           <item>
@@ -2968,393 +2402,6 @@ Later steps in the process (saving, renaming) will not be done.</string>
        </item>
       </layout>
      </widget>
-     <widget class="QWidget" name="tabDiagnoseDetectors">
-      <attribute name="title">
-       <string>Diagnose Detectors</string>
-      </attribute>
-      <layout class="QVBoxLayout" name="verticalLayout_4">
-       <item>
-        <widget class="QCheckBox" name="ckRunDiag">
-         <property name="enabled">
-          <bool>true</bool>
-         </property>
-         <property name="text">
-          <string>Find Bad Detectors</string>
-         </property>
-         <property name="checked">
-          <bool>true</bool>
-         </property>
-        </widget>
-       </item>
-      </layout>
-     </widget>
-     <widget class="QWidget" name="tabAbsoluteUnits">
-      <attribute name="title">
-       <string>Absolute Units</string>
-      </attribute>
-      <layout class="QVBoxLayout" name="verticalLayout_11">
-       <item>
-        <widget class="QCheckBox" name="ckRunAbsol">
-         <property name="enabled">
-          <bool>true</bool>
-         </property>
-         <property name="text">
-          <string>Perform Absolute Normalisation</string>
-         </property>
-         <property name="checked">
-          <bool>false</bool>
-         </property>
-        </widget>
-       </item>
-       <item>
-        <widget class="QGroupBox" name="gbCalRuns">
-         <property name="enabled">
-          <bool>true</bool>
-         </property>
-         <property name="title">
-          <string>Run Files</string>
-         </property>
-         <layout class="QVBoxLayout" name="verticalLayout_31">
-          <item>
-           <widget class="MantidQt::MantidWidgets::MWRunFiles" name="absRunFiles">
-            <property name="label" stdset="0">
-             <string>Abs Units Vanadium</string>
-            </property>
-           </widget>
-          </item>
-          <item>
-           <widget class="MantidQt::MantidWidgets::MWRunFiles" name="absMapFile">
-            <property name="findRunFiles" stdset="0">
-             <bool>false</bool>
-            </property>
-            <property name="label" stdset="0">
-             <string>Map File  </string>
-            </property>
-            <property name="multipleFiles" stdset="0">
-             <bool>false</bool>
-            </property>
-            <property name="optional" stdset="0">
-             <bool>true</bool>
-            </property>
-            <property name="algorithmAndProperty" stdset="0">
-             <string>GroupDetectors|MapFile</string>
-            </property>
-           </widget>
-          </item>
-          <item>
-           <widget class="MantidQt::MantidWidgets::MWRunFiles" name="absWhiteFile">
-            <property name="label" stdset="0">
-             <string>Detector Vanadium (Abs Units)</string>
-            </property>
-            <property name="multipleFiles" stdset="0">
-             <bool>false</bool>
-            </property>
-            <property name="optional" stdset="0">
-             <bool>true</bool>
-            </property>
-           </widget>
-          </item>
-         </layout>
-        </widget>
-       </item>
-       <item>
-        <layout class="QHBoxLayout" name="horizontalLayout_17">
-         <item>
-          <widget class="QGroupBox" name="gbInteg">
-           <property name="styleSheet">
-            <string notr="true"/>
-           </property>
-           <property name="title">
-            <string>Integration (meV)</string>
-           </property>
-           <layout class="QGridLayout" name="gridLayout_17">
-            <item row="2" column="1">
-             <widget class="QLabel" name="label_29">
-              <property name="text">
-               <string>E Min</string>
-              </property>
-              <property name="alignment">
-               <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
-              </property>
-             </widget>
-            </item>
-            <item row="2" column="2">
-             <widget class="QLineEdit" name="leVanELow">
-              <property name="maximumSize">
-               <size>
-                <width>60</width>
-                <height>16777215</height>
-               </size>
-              </property>
-             </widget>
-            </item>
-            <item row="3" column="1">
-             <widget class="QLabel" name="label_30">
-              <property name="text">
-               <string>E Max</string>
-              </property>
-              <property name="alignment">
-               <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
-              </property>
-             </widget>
-            </item>
-            <item row="3" column="2">
-             <widget class="QLineEdit" name="leVanEHigh">
-              <property name="maximumSize">
-               <size>
-                <width>60</width>
-                <height>16777215</height>
-               </size>
-              </property>
-             </widget>
-            </item>
-            <item row="1" column="1">
-             <widget class="QLabel" name="label_31">
-              <property name="text">
-               <string>Incident Energy</string>
-              </property>
-              <property name="alignment">
-               <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
-              </property>
-             </widget>
-            </item>
-            <item row="1" column="2">
-             <widget class="QLineEdit" name="leVanEi">
-              <property name="minimumSize">
-               <size>
-                <width>0</width>
-                <height>0</height>
-               </size>
-              </property>
-              <property name="maximumSize">
-               <size>
-                <width>70</width>
-                <height>16777215</height>
-               </size>
-              </property>
-             </widget>
-            </item>
-            <item row="1" column="4">
-             <spacer name="horizontalSpacer_24">
-              <property name="orientation">
-               <enum>Qt::Horizontal</enum>
-              </property>
-              <property name="sizeHint" stdset="0">
-               <size>
-                <width>40</width>
-                <height>20</height>
-               </size>
-              </property>
-             </spacer>
-            </item>
-            <item row="1" column="0">
-             <spacer name="horizontalSpacer_25">
-              <property name="orientation">
-               <enum>Qt::Horizontal</enum>
-              </property>
-              <property name="sizeHint" stdset="0">
-               <size>
-                <width>40</width>
-                <height>20</height>
-               </size>
-              </property>
-             </spacer>
-            </item>
-            <item row="1" column="3">
-             <widget class="QLabel" name="lbValAbsEi">
-              <property name="palette">
-               <palette>
-                <active>
-                 <colorrole role="WindowText">
-                  <brush brushstyle="SolidPattern">
-                   <color alpha="255">
-                    <red>170</red>
-                    <green>0</green>
-                    <blue>0</blue>
-                   </color>
-                  </brush>
-                 </colorrole>
-                </active>
-                <inactive>
-                 <colorrole role="WindowText">
-                  <brush brushstyle="SolidPattern">
-                   <color alpha="255">
-                    <red>170</red>
-                    <green>0</green>
-                    <blue>0</blue>
-                   </color>
-                  </brush>
-                 </colorrole>
-                </inactive>
-                <disabled>
-                 <colorrole role="WindowText">
-                  <brush brushstyle="SolidPattern">
-                   <color alpha="255">
-                    <red>118</red>
-                    <green>116</green>
-                    <blue>108</blue>
-                   </color>
-                  </brush>
-                 </colorrole>
-                </disabled>
-               </palette>
-              </property>
-              <property name="styleSheet">
-               <string notr="true"/>
-              </property>
-              <property name="text">
-               <string>*</string>
-              </property>
-             </widget>
-            </item>
-           </layout>
-          </widget>
-         </item>
-         <item>
-          <widget class="QGroupBox" name="gbMasses">
-           <property name="sizePolicy">
-            <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
-             <horstretch>0</horstretch>
-             <verstretch>0</verstretch>
-            </sizepolicy>
-           </property>
-           <property name="title">
-            <string>Masses (for Absolute Units)</string>
-           </property>
-           <layout class="QGridLayout" name="gridLayout_18">
-            <item row="0" column="1">
-             <widget class="QLabel" name="label_32">
-              <property name="layoutDirection">
-               <enum>Qt::LeftToRight</enum>
-              </property>
-              <property name="text">
-               <string>Vanadium mass</string>
-              </property>
-              <property name="alignment">
-               <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
-              </property>
-             </widget>
-            </item>
-            <item row="1" column="1">
-             <widget class="QLabel" name="label_33">
-              <property name="layoutDirection">
-               <enum>Qt::LeftToRight</enum>
-              </property>
-              <property name="text">
-               <string>Sample mass</string>
-              </property>
-              <property name="alignment">
-               <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
-              </property>
-             </widget>
-            </item>
-            <item row="2" column="1">
-             <widget class="QLabel" name="label_34">
-              <property name="layoutDirection">
-               <enum>Qt::LeftToRight</enum>
-              </property>
-              <property name="text">
-               <string>Sample RMM</string>
-              </property>
-              <property name="alignment">
-               <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
-              </property>
-             </widget>
-            </item>
-            <item row="2" column="2">
-             <widget class="QLineEdit" name="leRMMMass">
-              <property name="sizePolicy">
-               <sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
-                <horstretch>0</horstretch>
-                <verstretch>0</verstretch>
-               </sizepolicy>
-              </property>
-              <property name="maximumSize">
-               <size>
-                <width>60</width>
-                <height>16777215</height>
-               </size>
-              </property>
-             </widget>
-            </item>
-            <item row="1" column="2">
-             <widget class="QLineEdit" name="leSamMass">
-              <property name="sizePolicy">
-               <sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
-                <horstretch>0</horstretch>
-                <verstretch>0</verstretch>
-               </sizepolicy>
-              </property>
-              <property name="maximumSize">
-               <size>
-                <width>60</width>
-                <height>16777215</height>
-               </size>
-              </property>
-             </widget>
-            </item>
-            <item row="0" column="2">
-             <widget class="QLineEdit" name="leVanMass">
-              <property name="sizePolicy">
-               <sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
-                <horstretch>0</horstretch>
-                <verstretch>0</verstretch>
-               </sizepolicy>
-              </property>
-              <property name="maximumSize">
-               <size>
-                <width>60</width>
-                <height>16777215</height>
-               </size>
-              </property>
-             </widget>
-            </item>
-            <item row="0" column="3">
-             <spacer name="horizontalSpacer_26">
-              <property name="orientation">
-               <enum>Qt::Horizontal</enum>
-              </property>
-              <property name="sizeHint" stdset="0">
-               <size>
-                <width>40</width>
-                <height>20</height>
-               </size>
-              </property>
-             </spacer>
-            </item>
-            <item row="0" column="0">
-             <spacer name="horizontalSpacer_27">
-              <property name="orientation">
-               <enum>Qt::Horizontal</enum>
-              </property>
-              <property name="sizeHint" stdset="0">
-               <size>
-                <width>40</width>
-                <height>20</height>
-               </size>
-              </property>
-             </spacer>
-            </item>
-           </layout>
-          </widget>
-         </item>
-        </layout>
-       </item>
-       <item>
-        <spacer name="verticalSpacer">
-         <property name="orientation">
-          <enum>Qt::Vertical</enum>
-         </property>
-         <property name="sizeHint" stdset="0">
-          <size>
-           <width>20</width>
-           <height>40</height>
-          </size>
-         </property>
-        </spacer>
-       </item>
-      </layout>
-     </widget>
     </widget>
    </item>
    <item>
@@ -3450,24 +2497,9 @@ Later steps in the process (saving, renaming) will not be done.</string>
    <extends>QWidget</extends>
    <header>MantidQtMantidWidgets/DataSelector.h</header>
   </customwidget>
-  <customwidget>
-   <class>MantidQt::MantidWidgets::DataSelector</class>
-   <extends>QWidget</extends>
-   <header>MantidQtMantidWidgets/DataSelector.h</header>
-  </customwidget>
  </customwidgets>
  <tabstops>
   <tabstop>tabWidget</tabstop>
-  <tabstop>ckSumSpecs</tabstop>
-  <tabstop>pbBack</tabstop>
-  <tabstop>cbNormal</tabstop>
-  <tabstop>leEGuess</tabstop>
-  <tabstop>ckFixEi</tabstop>
-  <tabstop>leELow</tabstop>
-  <tabstop>leEWidth</tabstop>
-  <tabstop>leEHigh</tabstop>
-  <tabstop>leNameSPE</tabstop>
-  <tabstop>pbBrowseSPE</tabstop>
   <tabstop>save_ckSPE</tabstop>
   <tabstop>save_ckNexus</tabstop>
   <tabstop>pbRun</tabstop>
@@ -3476,29 +2508,16 @@ Later steps in the process (saving, renaming) will not be done.</string>
   <tabstop>leSpectraMin</tabstop>
   <tabstop>leSpectraMax</tabstop>
   <tabstop>rebin_ckDNR</tabstop>
-  <tabstop>rebin_leELow</tabstop>
-  <tabstop>rebin_leEWidth</tabstop>
-  <tabstop>rebin_leEHigh</tabstop>
+  <tabstop>entryRebinLow</tabstop>
+  <tabstop>entryRebinWidth</tabstop>
+  <tabstop>entryRebinHigh</tabstop>
   <tabstop>pbBack_2</tabstop>
   <tabstop>pbPlotRaw</tabstop>
   <tabstop>ckSumFiles</tabstop>
   <tabstop>cbMappingOptions</tabstop>
-  <tabstop>cbReflection</tabstop>
   <tabstop>leNoGroups</tabstop>
   <tabstop>ckUseCalib</tabstop>
-  <tabstop>ckRunDiag</tabstop>
-  <tabstop>ckRunAbsol</tabstop>
-  <tabstop>cbAnalyser</tabstop>
-  <tabstop>leVanEi</tabstop>
-  <tabstop>leVanELow</tabstop>
-  <tabstop>leVanEHigh</tabstop>
-  <tabstop>leVanMass</tabstop>
-  <tabstop>leSamMass</tabstop>
-  <tabstop>leRMMMass</tabstop>
   <tabstop>cbInst</tabstop>
-  <tabstop>runFiles</tabstop>
-  <tabstop>mapFile</tabstop>
-  <tabstop>whiteBeamFile</tabstop>
   <tabstop>ind_runFiles</tabstop>
   <tabstop>ind_calibFile</tabstop>
   <tabstop>ckLoadLogs</tabstop>
@@ -3507,10 +2526,8 @@ Later steps in the process (saving, renaming) will not be done.</string>
   <tabstop>leDetailedBalance</tabstop>
   <tabstop>ckScaleMultiplier</tabstop>
   <tabstop>leScaleMultiplier</tabstop>
-  <tabstop>motorNameEdit</tabstop>
-  <tabstop>seOffsetEdit</tabstop>
-  <tabstop>cbIndRebType</tabstop>
-  <tabstop>leRebinString</tabstop>
+  <tabstop>comboRebinType</tabstop>
+  <tabstop>entryRebinString</tabstop>
   <tabstop>save_ckNxSPE</tabstop>
   <tabstop>save_ckAscii</tabstop>
   <tabstop>save_ckAclimax</tabstop>
@@ -3519,8 +2536,6 @@ Later steps in the process (saving, renaming) will not be done.</string>
   <tabstop>ckRenameWorkspace</tabstop>
   <tabstop>ckFold</tabstop>
   <tabstop>ckCm1Units</tabstop>
-  <tabstop>cal_leRunNo</tabstop>
-  <tabstop>cal_pbPlot</tabstop>
   <tabstop>cal_ckIntensityScaleMultiplier</tabstop>
   <tabstop>cal_leIntensityScaleMultiplier</tabstop>
   <tabstop>cal_ckResScale</tabstop>
@@ -3550,9 +2565,6 @@ Later steps in the process (saving, renaming) will not be done.</string>
   <tabstop>sqw_ckVerbose</tabstop>
   <tabstop>sqw_cbPlotType</tabstop>
   <tabstop>sqw_ckSave</tabstop>
-  <tabstop>absRunFiles</tabstop>
-  <tabstop>absMapFile</tabstop>
-  <tabstop>absWhiteFile</tabstop>
   <tabstop>pbManageDirectories</tabstop>
   <tabstop>cal_ckVerbose</tabstop>
   <tabstop>cal_ckSave</tabstop>
diff --git a/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/C2ETab.h b/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/IndirectDataReductionTab.h
similarity index 58%
rename from Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/C2ETab.h
rename to Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/IndirectDataReductionTab.h
index 1f9d97b1ba8e1f33a99f5a9ded1fedb262897928..b342e04ce032b368140cdfdfd2a91cc73dd53643 100644
--- a/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/C2ETab.h
+++ b/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/IndirectDataReductionTab.h
@@ -1,24 +1,23 @@
-#ifndef MANTID_CUSTOMINTERFACES_C2ETAB_H_
-#define MANTID_CUSTOMINTERFACES_C2ETAB_H_
+#ifndef MANTID_CUSTOMINTERFACES_INDIRECTDATAREDUCTIONTAB_H_
+#define MANTID_CUSTOMINTERFACES_INDIRECTDATAREDUCTIONTAB_H_
 
 #include "MantidAPI/AlgorithmManager.h"
 #include "MantidAPI/AnalysisDataService.h"
 #include "MantidKernel/System.h"
 #include "MantidQtAPI/AlgorithmRunner.h"
+#include "MantidQtAPI/PythonRunner.h"
 #include "MantidQtAPI/QwtWorkspaceSpectrumData.h"
-#include "MantidQtCustomInterfaces/ConvertToEnergy.h"
+#include "MantidQtCustomInterfaces/IndirectDataReduction.h"
 #include "MantidQtMantidWidgets/RangeSelector.h"
 
-#include <QMap>
 #include <QDoubleValidator>
-#include <QtDoublePropertyManager>
+#include <QMap>
 #include <QtIntPropertyManager>
 #include <QtTreePropertyBrowser>
 
 #include <qwt_plot.h>
 #include <qwt_plot_curve.h>
 
-
 // Suppress a warning coming out of code that isn't ours
 #if defined(__INTEL_COMPILER)
   #pragma warning disable 1125
@@ -41,9 +40,7 @@ namespace MantidQt
 {
 namespace CustomInterfaces
 {
-
-
-  /** C2ETab : TODO: DESCRIPTION
+  /** IndirectDataReductionTab : TODO: DESCRIPTION
     
     @author Samuel Jackson
     @date 13/08/2013
@@ -68,54 +65,89 @@ namespace CustomInterfaces
     File change history is stored at: <https://github.com/mantidproject/mantid>
     Code Documentation is available at: <http://doxygen.mantidproject.org>
   */
-  class DLLExport C2ETab : public QWidget
+  class DLLExport IndirectDataReductionTab : public QObject
   {
     Q_OBJECT
 
   public:
-    C2ETab(Ui::ConvertToEnergy& uiForm, QWidget * parent = 0);
-    virtual ~C2ETab();
+    IndirectDataReductionTab(Ui::IndirectDataReduction& uiForm, QObject * parent = 0);
+    virtual ~IndirectDataReductionTab();
+
+  public slots:
     void runTab();
     void setupTab();
     void validateTab();
 
   protected slots:
-    /// Slot to handle when an algorithm finishs running
+    /// Slot to handle when an algorithm finishes running
     virtual void algorithmFinished(bool error);
 
   protected:
-    // Run the load algorithm with the given file name and output name 
+    /// Run the load algorithm with the given file name and output name 
     bool loadFile(const QString& filename, const QString& outputName);
+
+    /// Function to get details about the instrument configuration defined on C2E tab
+    std::map<QString, QString> getInstrumentDetails();
+
     /// Function to plot a workspace to the miniplot using a workspace name
-    void plotMiniPlot(const QString& workspace, size_t index);
+    void plotMiniPlot(const QString& workspace, size_t index, const QString& plotID, const QString& curveID = "");
     /// Function to plot a workspace to the miniplot using a workspace pointer
-    void plotMiniPlot(const Mantid::API::MatrixWorkspace_const_sptr & workspace, size_t wsIndex);
+    void plotMiniPlot(const Mantid::API::MatrixWorkspace_const_sptr & workspace, size_t wsIndex, const QString& plotID, const QString& curveID = "");
+    /// Function to replot a miniplot
+    void replot(const QString& plotID);
+
     /// Function to get the range of the curve displayed on the mini plot
-    std::pair<double,double> getCurveRange();
+    std::pair<double, double> getCurveRange(const QString& plotID);
+    /// Function to set the range of an axis on a plot
+    void setAxisRange(const QString& plotID, QwtPlot::Axis axis, std::pair<double, double> range);
+    /// Function to autoscale a given axis based on the data in a curve
+    void setXAxisToCurve(const QString& plotID, const QString& curveID);
+
     /// Function to set the range limits of the plot
-    void setPlotRange(QtProperty* min, QtProperty* max, const std::pair<double, double>& bounds);
+    void setPlotRange(const QString& rsID, QtProperty* min, QtProperty* max, const std::pair<double, double>& bounds);
     /// Function to set the range selector on the mini plot
-    void setMiniPlotGuides(QtProperty* lower, QtProperty* upper, const std::pair<double, double>& bounds);
+    void setMiniPlotGuides(const QString& rsID, QtProperty* lower, QtProperty* upper, const std::pair<double, double>& bounds);
+
     /// Function to run an algorithm on a seperate thread
-    void runAlgorithm(const Mantid::API::Algorithm_sptr algorithm);
+    void runAlgorithm(const Mantid::API::IAlgorithm_sptr algorithm);
+
+    /// Parent QWidget (if applicable)
+    QWidget *m_parentWidget;
 
     /// Plot of the input
-    QwtPlot* m_plot;
+    std::map<QString, QwtPlot *> m_plots;
     /// Curve on the plot
-    QwtPlotCurve* m_curve;
+    std::map<QString, QwtPlotCurve *> m_curves;
     /// Range selector widget for mini plot
-    MantidQt::MantidWidgets::RangeSelector* m_rangeSelector;
+    std::map<QString, MantidQt::MantidWidgets::RangeSelector *> m_rangeSelectors;
     /// Tree of the properties
-    QtTreePropertyBrowser* m_propTree;
+    std::map<QString, QtTreePropertyBrowser *> m_propTrees;
+
     /// Internal list of the properties
     QMap<QString, QtProperty*> m_properties;
+
     /// Double manager to create properties
     QtDoublePropertyManager* m_dblManager;
+    /// Boolean manager to create properties
+    QtBoolPropertyManager* m_blnManager;
+    /// Group manager to create properties
+    QtGroupPropertyManager* m_grpManager;
+
     /// Double editor facotry for the properties browser
     DoubleEditorFactory* m_dblEdFac;
     /// Algorithm runner object to execute algorithms on a seperate thread from the gui
     MantidQt::API::AlgorithmRunner* m_algRunner;
 
+    /// Use a Python runner for when we need the output of a script
+    MantidQt::API::PythonRunner m_pythonRunner;
+
+    /// Validator for int inputs
+    QIntValidator *m_valInt;
+    /// Validator for double inputs
+    QDoubleValidator *m_valDbl;
+    /// Validator for positive double inputs
+    QDoubleValidator *m_valPosDbl;
+
   signals:
     /// Send signal to parent window to show a message box to user
     void showMessageBox(const QString& message);
@@ -131,10 +163,10 @@ namespace CustomInterfaces
     virtual bool validate() = 0;
 
   protected:
-    Ui::ConvertToEnergy m_uiForm;
+    Ui::IndirectDataReduction m_uiForm;
 
   };
 } // namespace CustomInterfaces
 } // namespace Mantid
 
-#endif  /* MANTID_CUSTOMINTERFACES_C2ETAB_H_ */
+#endif  /* MANTID_CUSTOMINTERFACES_INDIRECTDATAREDUCTIONTAB_H_ */
diff --git a/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/IndirectDiagnostics.h b/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/IndirectDiagnostics.h
new file mode 100644
index 0000000000000000000000000000000000000000..6e502e6ddeb98bd26a697cd2fe1b6fe064ee1f76
--- /dev/null
+++ b/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/IndirectDiagnostics.h
@@ -0,0 +1,81 @@
+#ifndef MANTIDQTCUSTOMINTERFACES_INDIRECTDIAGNOSTICS_H_
+#define MANTIDQTCUSTOMINTERFACES_INDIRECTDIAGNOSTICS_H_
+
+#include "MantidQtCustomInterfaces/IndirectDataReductionTab.h"
+
+#include "MantidAPI/MatrixWorkspace.h"
+#include "MantidKernel/System.h"
+
+// Suppress a warning coming out of code that isn't ours
+#if defined(__INTEL_COMPILER)
+  #pragma warning disable 1125
+#elif defined(__GNUC__)
+  #if (__GNUC__ >= 4 && __GNUC_MINOR__ >= 6 )
+    #pragma GCC diagnostic push
+  #endif
+  #pragma GCC diagnostic ignored "-Woverloaded-virtual"
+#endif
+#include <QtCheckBoxFactory>
+#if defined(__INTEL_COMPILER)
+  #pragma warning enable 1125
+#elif defined(__GNUC__)
+  #if (__GNUC__ >= 4 && __GNUC_MINOR__ >= 6 )
+    #pragma GCC diagnostic pop
+  #endif
+#endif
+
+namespace MantidQt
+{
+namespace CustomInterfaces
+{
+  /** IndirectDiagnostics
+
+    @author Dan Nixon
+    @date 23/07/2014
+
+    Copyright &copy; 2013 ISIS Rutherford Appleton Laboratory & NScD Oak Ridge National Laboratory
+
+    This file is part of Mantid.
+
+    Mantid is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 3 of the License, or
+    (at your option) any later version.
+
+    Mantid is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+    File change history is stored at: <https://github.com/mantidproject/mantid>
+    Code Documentation is available at: <http://doxygen.mantidproject.org>
+  */
+  class DLLExport IndirectDiagnostics : public IndirectDataReductionTab
+  {
+    Q_OBJECT
+
+  public:
+    IndirectDiagnostics(Ui::IndirectDataReduction& uiForm, QWidget * parent = 0);
+    virtual ~IndirectDiagnostics();
+
+    virtual void setup();
+    virtual void run();
+    virtual bool validate();
+
+  private slots:
+    void slicePlotRaw();
+    void sliceTwoRanges(QtProperty*, bool);
+    void sliceCalib(bool state);
+    void sliceMinChanged(double val);
+    void sliceMaxChanged(double val);
+    void sliceUpdateRS(QtProperty*, double);
+    void setDefaultInstDetails();
+
+  };
+} // namespace CustomInterfaces
+} // namespace Mantid
+
+#endif //MANTIDQTCUSTOMINTERFACES_INDIRECTDIAGNOSTICS_H__
diff --git a/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/IndirectMoments.h b/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/IndirectMoments.h
index 6955860092c1fd78e1bef9d5b6660856d17ee31d..f3602cc1124b3f693bfdf982b430d372cd52b2de 100644
--- a/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/IndirectMoments.h
+++ b/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/IndirectMoments.h
@@ -1,8 +1,11 @@
 #ifndef MANTID_CUSTOMINTERFACES_INDIRECTMOMENTS_H_
 #define MANTID_CUSTOMINTERFACES_INDIRECTMOMENTS_H_
 
+#include "MantidQtCustomInterfaces/IndirectDataReductionTab.h"
+
 #include "MantidKernel/System.h"
-#include "MantidQtCustomInterfaces/C2ETab.h"
+
+#include <QFont>
 
 namespace MantidQt
 {
@@ -34,12 +37,12 @@ namespace CustomInterfaces
     File change history is stored at: <https://github.com/mantidproject/mantid>
     Code Documentation is available at: <http://doxygen.mantidproject.org>
   */
-  class DLLExport IndirectMoments : public C2ETab
+  class DLLExport IndirectMoments : public IndirectDataReductionTab
   {
     Q_OBJECT
 
   public:
-    IndirectMoments(Ui::ConvertToEnergy& uiForm, QWidget * parent = 0);
+    IndirectMoments(Ui::IndirectDataReduction& uiForm, QWidget * parent = 0);
     virtual ~IndirectMoments();
 
     virtual void setup();
@@ -47,7 +50,7 @@ namespace CustomInterfaces
     virtual bool validate();
 
   protected slots:
-    //Handle when a file/workspace is ready for plotting
+    // Handle when a file/workspace is ready for plotting
     void handleSampleInputReady(const QString&);
     /// Slot for when the min range on the range selector changes
     void minValueChanged(double min);
@@ -60,4 +63,4 @@ namespace CustomInterfaces
 } // namespace CustomInterfaces
 } // namespace Mantid
 
-#endif  /* MANTID_CUSTOMINTERFACES_INDIRECTMOMENTS_H_ */
\ No newline at end of file
+#endif  /* MANTID_CUSTOMINTERFACES_INDIRECTMOMENTS_H_ */
diff --git a/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/IndirectSqw.h b/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/IndirectSqw.h
new file mode 100644
index 0000000000000000000000000000000000000000..ad26ef5efddfb734edbf97b3fbc9df5b91a068c8
--- /dev/null
+++ b/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/IndirectSqw.h
@@ -0,0 +1,57 @@
+#ifndef MANTIDQTCUSTOMINTERFACES_INDIRECTSQW_H_
+#define MANTIDQTCUSTOMINTERFACES_INDIRECTSQW_H_
+
+#include "MantidQtCustomInterfaces/IndirectDataReductionTab.h"
+
+#include "MantidKernel/System.h"
+
+namespace MantidQt
+{
+namespace CustomInterfaces
+{
+  /** IndirectSqw
+
+    @author Dan Nixon
+    @date 23/07/2014
+
+    Copyright &copy; 2013 ISIS Rutherford Appleton Laboratory & NScD Oak Ridge National Laboratory
+
+    This file is part of Mantid.
+
+    Mantid is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 3 of the License, or
+    (at your option) any later version.
+
+    Mantid is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+    File change history is stored at: <https://github.com/mantidproject/mantid>
+    Code Documentation is available at: <http://doxygen.mantidproject.org>
+  */
+  class DLLExport IndirectSqw : public IndirectDataReductionTab
+  {
+    Q_OBJECT
+
+  public:
+    IndirectSqw(Ui::IndirectDataReduction& uiForm, QWidget * parent = 0);
+    virtual ~IndirectSqw();
+
+    virtual void setup();
+    virtual void run();
+    virtual bool validate();
+
+  private slots:
+    void sOfQwRebinE(bool state);
+    void sOfQwPlotInput();
+
+  };
+} // namespace CustomInterfaces
+} // namespace Mantid
+
+#endif //MANTIDQTCUSTOMINTERFACES_INDIRECTSQW_H_
diff --git a/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Transmission.h b/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/IndirectTransmission.h
similarity index 72%
rename from Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Transmission.h
rename to Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/IndirectTransmission.h
index 5ca32ebede213e83a51493adc41b40a8df3184fb..8fa3ad3cb3b791f40e9b95876f69847d17e23785 100644
--- a/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Transmission.h
+++ b/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/IndirectTransmission.h
@@ -1,7 +1,7 @@
-#ifndef MANTID_CUSTOMINTERFACES_TRANSMISSION_H_
-#define MANTID_CUSTOMINTERFACES_TRANSMISSION_H_
+#ifndef MANTID_CUSTOMINTERFACES_INDIRECTTRANSMISSION_H_
+#define MANTID_CUSTOMINTERFACES_INDIRECTTRANSMISSION_H_
 
-#include "MantidQtCustomInterfaces/C2ETab.h"
+#include "MantidQtCustomInterfaces/IndirectDataReductionTab.h"
 #include "MantidKernel/System.h"
 
 
@@ -9,7 +9,7 @@ namespace MantidQt
 {
 namespace CustomInterfaces
 {
-  /** Transmission : TODO: DESCRIPTION
+  /** IndirectTransmission : TODO: DESCRIPTION
     
 
     @author Samuel Jackson
@@ -35,13 +35,13 @@ namespace CustomInterfaces
     File change history is stored at: <https://github.com/mantidproject/mantid>
     Code Documentation is available at: <http://doxygen.mantidproject.org>
   */
-  class DLLExport Transmission : public C2ETab
+  class DLLExport IndirectTransmission : public IndirectDataReductionTab
   {
     Q_OBJECT
 
   public:
-    Transmission(Ui::ConvertToEnergy& uiForm, QWidget * parent = 0);
-    virtual ~Transmission();
+    IndirectTransmission(Ui::IndirectDataReduction& uiForm, QWidget * parent = 0);
+    virtual ~IndirectTransmission();
 
     virtual void setup();
     virtual void run();
@@ -51,4 +51,4 @@ namespace CustomInterfaces
 } // namespace CustomInterfaces
 } // namespace Mantid
 
-#endif  /* MANTID_CUSTOMINTERFACES_TRANSMISSION_H_ */
+#endif  /* MANTID_CUSTOMINTERFACES_INDIRECTTRANSMISSION_H_ */
diff --git a/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/SANSAddFiles.h b/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/SANSAddFiles.h
index 83a90bcfe65cbb280c6a16284e0804168f6114e4..fd9c38103569307cbc1d17089c9757d6d709b663 100644
--- a/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/SANSAddFiles.h
+++ b/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/SANSAddFiles.h
@@ -29,9 +29,9 @@ private:
   //set to true when execution of the python scripts starts and false on completion
   bool m_pythonRunning;
   //this is set to the extensions supported by the Load algorithm
-  std::set<std::string> m_exts;
+  std::vector<std::string> m_exts;
   //this is set to the extensions supported by LoadRaw
-  std::set<std::string> m_rawExts;
+  std::vector<std::string> m_rawExts;
   ///the directory to which files will be saved
   QString m_outDir;
   ///The text that goes into the beginning of the output directory message
diff --git a/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/deltaECalc.h b/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/deltaECalc.h
index ec4a94e43a83a4950f57de16fa65d3bfb0491288..0487b818852ab94b5145e99a63aaa04995b25bd5 100644
--- a/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/deltaECalc.h
+++ b/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/deltaECalc.h
@@ -2,7 +2,7 @@
 #define MANTIDQTCUSTOMINTERFACES_DELTAECALC_H_
 
 #include "MantidQtMantidWidgets/pythonCalc.h"
-#include "ui_ConvertToEnergy.h"
+#include "ui_DirectConvertToEnergy.h"
 #include <QFileInfo>
 
 namespace MantidQt
@@ -12,7 +12,7 @@ namespace MantidQt
     class deltaECalc : public MantidWidgets::pythonCalc
     {
     public:
-      deltaECalc(QWidget * const interface, const Ui::ConvertToEnergy &userSettings, const bool removalBg, 
+      deltaECalc(QWidget * const interface, const Ui::DirectConvertToEnergy &userSettings, const bool removalBg, 
 		 const double TOFWinSt, const double TOFWinEnd);
       void setDiagnosedWorkspaceName(const QString &maskWS);
       void createProcessingScript(const QStringList & inFiles, const QString &whiteB,
@@ -31,7 +31,7 @@ namespace MantidQt
       std::string insertNumber(const std::string &filename, const int number) const;
     private:
       /// the form that ws filled in by the user
-      const Ui::ConvertToEnergy &m_sets;
+      const Ui::DirectConvertToEnergy &m_sets;
       /// whether to the remove background count rate from the data
       const bool m_bgRemove;
 	    /// used in remove background, the start of the background region
diff --git a/Code/Mantid/MantidQt/CustomInterfaces/src/C2ETab.cpp b/Code/Mantid/MantidQt/CustomInterfaces/src/C2ETab.cpp
deleted file mode 100644
index 649e8ebf4252f6ecaf9d5b5939944dfcf234ef33..0000000000000000000000000000000000000000
--- a/Code/Mantid/MantidQt/CustomInterfaces/src/C2ETab.cpp
+++ /dev/null
@@ -1,188 +0,0 @@
-#include "MantidQtCustomInterfaces/C2ETab.h"
-
-namespace MantidQt
-{
-namespace CustomInterfaces
-{
-
-  //----------------------------------------------------------------------------------------------
-  /** Constructor
-   */
-  C2ETab::C2ETab(Ui::ConvertToEnergy& uiForm, QWidget * parent) : QWidget(parent),
-      m_plot(new QwtPlot(parent)), m_curve(new QwtPlotCurve()), m_rangeSelector(new MantidWidgets::RangeSelector(m_plot)),
-      m_propTree(new QtTreePropertyBrowser()), m_properties(), m_dblManager(new QtDoublePropertyManager()), 
-      m_dblEdFac(new DoubleEditorFactory()), m_algRunner(new MantidQt::API::AlgorithmRunner(this)), m_uiForm(uiForm)
-  {
-    QObject::connect(m_algRunner, SIGNAL(algorithmComplete(bool)), this, SLOT(algorithmFinished(bool)));
-  }
-    
-  //----------------------------------------------------------------------------------------------
-  /** Destructor
-   */
-  C2ETab::~C2ETab()
-  {
-  }
-  
-  void C2ETab::runTab()
-  {
-    if(validate())
-    {
-      run();
-    }
-  }
-
-  void C2ETab::setupTab()
-  {
-    setup();
-  }
-
-  void C2ETab::validateTab()
-  {
-    validate();
-  }
-
-  /**
-   * Run the load algorithm with the supplied filename
-   * 
-   * @param filename :: The name of the file to load
-   * @param outputName :: The name of the output workspace
-   * @return If the algorithm was successful
-   */
-  bool C2ETab::loadFile(const QString& filename, const QString& outputName)
-  {
-    using namespace Mantid::API;
-
-    Algorithm_sptr load = AlgorithmManager::Instance().createUnmanaged("Load", -1);
-    load->initialize();
-    load->setProperty("Filename", filename.toStdString());
-    load->setProperty("OutputWorkspace", outputName.toStdString());
-    load->execute();
-    
-    //if reloading fails we're out of options
-    if(!load->isExecuted())
-    {
-      return false;
-    }
-
-    return true;
-  }
-
-  /**
-   * Plot a workspace to the miniplot given a workspace name and
-   * a specturm index.
-   *
-   * This method uses the analysis data service to retrieve the workspace.
-   * 
-   * @param workspace :: The name of the workspace
-   * @param index :: The spectrum index of the workspace
-   */
-  void C2ETab::plotMiniPlot(const QString& workspace, size_t index)
-  {
-    using namespace Mantid::API;
-    auto ws = AnalysisDataService::Instance().retrieveWS<const MatrixWorkspace>(workspace.toStdString());
-    plotMiniPlot(ws, index);
-  }
-
-  /**
-   * Gets the range of the curve plotted in the mini plot
-   *
-   * @return A pair containing the maximum and minimum points of the curve
-   */
-  std::pair<double,double> C2ETab::getCurveRange()
-  {
-    size_t npts = m_curve->data().size();
-
-    if( npts < 2 )
-      throw std::invalid_argument("Too few points on data curve to determine range.");
-
-    return std::make_pair(m_curve->data().x(0), m_curve->data().x(npts-1));
-  }
-
-  /**
-   * Plot a workspace to the miniplot given a workspace pointer and
-   * a specturm index.
-   * 
-   * @param workspace :: Pointer to the workspace
-   * @param wsIndex :: The spectrum index of the workspace
-   */
-  void C2ETab::plotMiniPlot(const Mantid::API::MatrixWorkspace_const_sptr & workspace, size_t wsIndex)
-  {
-    using Mantid::MantidVec;
-
-    //check if we can plot
-    if( wsIndex >= workspace->getNumberHistograms() || workspace->readX(0).size() < 2 )
-    {
-      return;
-    }
-
-    QwtWorkspaceSpectrumData wsData(*workspace, static_cast<int>(wsIndex), false);
-
-    if ( m_curve != NULL )
-    {
-      m_curve->attach(0);
-      delete m_curve;
-      m_curve = NULL;
-    }
-
-    size_t nhist = workspace->getNumberHistograms();
-    if ( wsIndex >= nhist )
-    {
-      emit showMessageBox("Error: Workspace index out of range.");
-    }
-    else
-    {
-      m_curve = new QwtPlotCurve();
-      m_curve->setData(wsData);
-      m_curve->attach(m_plot);
-
-      m_plot->replot();
-    }
-  }
-
-    /**
-   * Sets the edge bounds of plot to prevent the user inputting invalid values
-   * 
-   * @param min :: The lower bound property in the property browser
-   * @param max :: The upper bound property in the property browser
-   * @param bounds :: The upper and lower bounds to be set
-   */
-  void C2ETab::setPlotRange(QtProperty* min, QtProperty* max, const std::pair<double, double>& bounds)
-  {
-    m_dblManager->setMinimum(min, bounds.first);
-    m_dblManager->setMaximum(min, bounds.second);
-    m_dblManager->setMinimum(max, bounds.first);
-    m_dblManager->setMaximum(max, bounds.second);
-    m_rangeSelector->setRange(bounds.first, bounds.second);
-  }
-
-  /**
-   * Set the position of the guides on the mini plot
-   * 
-   * @param lower :: The lower bound property in the property browser
-   * @param upper :: The upper bound property in the property browser
-   * @param bounds :: The upper and lower bounds to be set
-   */
-  void C2ETab::setMiniPlotGuides(QtProperty* lower, QtProperty* upper, const std::pair<double, double>& bounds)
-  {
-    m_dblManager->setValue(lower, bounds.first);
-    m_dblManager->setValue(upper, bounds.second);
-    m_rangeSelector->setMinimum(bounds.first);
-    m_rangeSelector->setMaximum(bounds.second);
-  }
-
-  void C2ETab::runAlgorithm(const Mantid::API::Algorithm_sptr algorithm)
-  {
-    algorithm->setRethrows(true);
-    m_algRunner->startAlgorithm(algorithm);
-  }
-
-  void C2ETab::algorithmFinished(bool error)
-  {
-    if(error)
-    {
-      emit showMessageBox("Error running SofQWMoments. \nSee results log for details.");
-    }
-  }
-
-} // namespace CustomInterfaces
-} // namespace Mantid
diff --git a/Code/Mantid/MantidQt/CustomInterfaces/src/ConvertToEnergy.cpp b/Code/Mantid/MantidQt/CustomInterfaces/src/ConvertToEnergy.cpp
deleted file mode 100644
index fa3061f06a548095931c3610560cc0a77e7fead0..0000000000000000000000000000000000000000
--- a/Code/Mantid/MantidQt/CustomInterfaces/src/ConvertToEnergy.cpp
+++ /dev/null
@@ -1,365 +0,0 @@
-//----------------------
-// Includes
-//----------------------
-#include "MantidQtCustomInterfaces/ConvertToEnergy.h"
-#include "MantidQtCustomInterfaces/Homer.h" // user interface for Direct instruments
-#include "MantidQtCustomInterfaces/Indirect.h" // user interface for Indirect instruments
-#include "MantidQtAPI/ManageUserDirectories.h"
-
-#include "MantidKernel/ConfigService.h"
-#include "MantidAPI/AnalysisDataService.h"
-#include "MantidAPI/ExperimentInfo.h"
-
-#include <QMessageBox>
-#include <QDir>
-
-#include <QDesktopServices>
-#include <QUrl>
-
-//Add this class to the list of specialised dialogs in this namespace
-namespace MantidQt
-{
-  namespace CustomInterfaces
-  {
-    DECLARE_SUBWINDOW(ConvertToEnergy);
-  }
-}
-
-using namespace MantidQt::CustomInterfaces;
-//----------------------
-// Public member functions
-//----------------------
-
-/**
- * Default constructor for class. Initialises interface pointers to NULL values.
- * @param parent :: This is a pointer to the "parent" object in Qt, most likely the main MantidPlot window.
- */
-ConvertToEnergy::ConvertToEnergy(QWidget *parent) :
-  UserSubWindow(parent), m_directInstruments(NULL), m_indirectInstruments(NULL), 
-  m_curInterfaceSetup(""), m_curEmodeType(ConvertToEnergy::Undefined), m_settingsGroup("CustomInterfaces/ConvertToEnergy")
-{
-}
-
-/**
- * Destructor
- */
-ConvertToEnergy::~ConvertToEnergy()
-{
-  saveSettings();
-}
-
-/**
- * On user clicking the "help" button on the interface, directs their request to the relevant
- * interface's helpClicked() function.
- */
-void ConvertToEnergy::helpClicked()
-{
-  switch ( m_curEmodeType )
-  {
-  case Direct:
-    m_directInstruments->helpClicked();
-    break;
-  case InDirect:
-    m_indirectInstruments->helpClicked();
-    break;
-  default:
-    QDesktopServices::openUrl(QUrl(QString("http://www.mantidproject.org/") +
-				   "ConvertToEnergy"));
-  }
-}
-
-/**
- * This is the function called when the "Run" button is clicked. It will call the relevent function
- * in the subclass.
- */
-void ConvertToEnergy::runClicked()
-{
-  switch ( m_curEmodeType )
-  {
-  case Direct:
-    m_directInstruments->runClicked();
-    break;
-  case InDirect:
-    m_indirectInstruments->runClicked();
-    break;
-  case Undefined:
-  default:
-    showInformationBox("This interface is not configured to use the instrument you have selected.\nPlease check your instrument selection.");
-  }
-}
-
-/**
- * Sets up Qt UI file and connects signals, slots. 
- */
-void ConvertToEnergy::initLayout()
-{
-  m_uiForm.setupUi(this);
-  m_curInterfaceSetup = "";
-  m_curEmodeType = Undefined;
-
-  // Assume we get a incompatiable instrument to start with
-  m_uiForm.pbRun->setEnabled(false);
-
-  // Signal / Slot Connections Set Up Here
-
-  // signal/slot connections to respond to changes in instrument selection combo boxes
-  connect(m_uiForm.cbInst, SIGNAL(instrumentSelectionChanged(const QString&)), this, SLOT(userSelectInstrument(const QString&)));
-
-  // connect "?" (Help) Button
-  connect(m_uiForm.pbHelp, SIGNAL(clicked()), this, SLOT(helpClicked()));
-  // connect the "Run" button
-  connect(m_uiForm.pbRun, SIGNAL(clicked()), this, SLOT(runClicked()));
-  // connect the "Manage User Directories" Button
-  connect(m_uiForm.pbManageDirectories, SIGNAL(clicked()), this, SLOT(openDirectoryDialog()));
-
-}
-
-/**
- * This function is ran after initLayout(), and runPythonCode is unavailable before this function
- * has run (because of the setup of the base class). For this reason, "setup" functions that require
- * Python scripts are located here.
- */
-void ConvertToEnergy::initLocalPython()
-{
-  // select starting instrument
-  readSettings();
-
-  if ( m_curInterfaceSetup == "" )
-  {
-    userSelectInstrument(m_uiForm.cbInst->currentText());
-  }
-}
-
-/**
- * Read settings from the persistent store
- */
-void ConvertToEnergy::readSettings()
-{
-  QSettings settings;
-  settings.beginGroup(m_settingsGroup);
-  QString instrName = settings.value("instrument-name", "").toString();
-  settings.endGroup();
-
-  setDefaultInstrument(instrName);
-}
-
-/**
- * Save settings to a persistent storage
- */
-void ConvertToEnergy::saveSettings()
-{
-  QSettings settings;
-  settings.beginGroup(m_settingsGroup);
-  QString instrName;
-  if( m_curEmodeType == Undefined )
-  {
-    instrName = "";
-  }
-  else
-  {
-    instrName = m_uiForm.cbInst->currentText();
-  }
-
-  settings.setValue("instrument-name", instrName);
-  settings.endGroup();
-}
-
-/**
- * Sets up the initial instrument for the interface. This value is taken from the users'
- * settings in the menu View -> Preferences -> Mantid -> Instrument
- * @param name :: The name of the default instrument
- */
-void ConvertToEnergy::setDefaultInstrument(const QString & name)
-{
-  if( name.isEmpty() ) return;
-
-  int index = m_uiForm.cbInst->findText(name);
-  if( index >= 0 )
-  {
-    m_uiForm.cbInst->setCurrentIndex(index);
-  }
-}
-
-
-/**
- * This function: 1. loads the instrument and gets the value of deltaE-mode parameter
- *				 2. Based on this value, makes the necessary changes to the form setup (direct or indirect).
- * @param name :: name of the instrument from the QComboBox
- */
-void ConvertToEnergy::instrumentSelectChanged(const QString& name)
-{
-  if ( ! m_uiForm.cbInst->isVisible() )
-  {
-    return;
-  }
-
-  QString defFile = (Mantid::API::ExperimentInfo::getInstrumentFilename(name.toStdString())).c_str();
-
-  if ( defFile == "" )
-  {
-    m_curEmodeType = Undefined;
-    return;
-  }
-
-  DeltaEMode desired = instrumentDeltaEMode(defFile);
-
-  if ( desired == Undefined )
-  {
-    m_curEmodeType = Undefined;
-    QMessageBox::warning(this, "MantidPlot", "Selected instrument (" + name + ") does not have a parameter to signify it's deltaE-mode");
-    m_uiForm.cbInst->blockSignals(true);
-    m_uiForm.cbInst->setCurrentIndex(m_uiForm.cbInst->findText(m_curInterfaceSetup));
-    m_uiForm.cbInst->blockSignals(false);
-    return;
-  }
-
-  DeltaEMode current;
-
-  if ( m_curInterfaceSetup == "" )
-  {
-    current = Undefined;
-  }
-  else
-  {
-    current = DeltaEMode(m_uiForm.swInstrument->currentIndex());
-  }
-
-  if ( desired != current || m_curInterfaceSetup != name )
-  {
-    changeInterface(desired);
-  }
-
-  m_curInterfaceSetup = name;
-  m_curEmodeType = desired;
-  m_uiForm.pbRun->setEnabled(true);
-
-}
-
-/**
- * Runs a Python script to discover whether the selected instrument is direct or indirect.
- * @param defFile :: path to instrument definition file.
- * @return 'Undefined' deltaE-mode not found, otherwise the relevant value ('Direct' or 'InDirect')
- */
-ConvertToEnergy::DeltaEMode ConvertToEnergy::instrumentDeltaEMode(const QString& defFile)
-{
-  QString pyInput =
-    "from mantid.simpleapi import LoadEmptyInstrument,mtd\n"
-    "ws_name = '__empty_%2'\n"
-    "if not mtd.doesExist(ws_name):\n"
-    "  LoadEmptyInstrument(Filename=r'%1', OutputWorkspace=ws_name)\n"
-    "instrument = mtd[ws_name].getInstrument()\n"
-    "try:\n"
-    "    print instrument.getStringParameter('deltaE-mode')[0]\n"
-    "except IndexError, message:\n" // the above line will raise an IndexError in Python
-    "    print ''\n"; // if the instrument doesn't have this parameter.
-
-  pyInput = pyInput.arg(defFile,m_uiForm.cbInst->currentText());
-
-  QString pyOutput = runPythonCode(pyInput).trimmed();
-
-  if ( pyOutput == "direct" )
-  {
-    return Direct;
-  }
-  else if ( pyOutput == "indirect" )
-  {
-    return InDirect;
-  }
-  else
-  {
-    return Undefined;
-  }
-}
-
-/**
- * Makes the changes necessary for switching between Direct and Indirect interfaces.
- * @param desired :: The interface format that is to be changed to.
- */
-void ConvertToEnergy::changeInterface(DeltaEMode desired)
-{
-  QString curInstPrefix = m_uiForm.cbInst->itemData(m_uiForm.cbInst->currentIndex()).toString();;
-  switch ( desired )
-  {
-  case Direct:
-    m_uiForm.tabWidget->removeTab(m_uiForm.tabWidget->indexOf(m_uiForm.tabCalibration));
-    m_uiForm.tabWidget->removeTab(m_uiForm.tabWidget->indexOf(m_uiForm.tabSofQW));
-    m_uiForm.tabWidget->removeTab(m_uiForm.tabWidget->indexOf(m_uiForm.tabMoments));
-    m_uiForm.tabWidget->removeTab(m_uiForm.tabWidget->indexOf(m_uiForm.tabTimeSlice));
-    m_uiForm.tabWidget->removeTab(m_uiForm.tabWidget->indexOf(m_uiForm.tabTransmission));
-    m_uiForm.tabWidget->addTab(m_uiForm.tabDiagnoseDetectors, "Diagnose Detectors");
-    m_uiForm.tabWidget->addTab(m_uiForm.tabAbsoluteUnits, "Absolute Units");
-    if ( m_directInstruments == NULL )
-    {
-      m_directInstruments = new Homer(qobject_cast<QWidget*>(this->parent()), m_uiForm);
-      m_directInstruments->initLayout();
-      connect(m_directInstruments, SIGNAL(runAsPythonScript(const QString&, bool)),
-	      this, SIGNAL(runAsPythonScript(const QString&, bool)));
-      m_directInstruments->initializeLocalPython();
-    }
-    m_directInstruments->setIDFValues(curInstPrefix);
-    break;
-  case InDirect:
-    m_uiForm.tabWidget->removeTab(m_uiForm.tabWidget->indexOf(m_uiForm.tabDiagnoseDetectors));
-    m_uiForm.tabWidget->removeTab(m_uiForm.tabWidget->indexOf(m_uiForm.tabAbsoluteUnits));
-    m_uiForm.tabWidget->addTab(m_uiForm.tabCalibration, "Calibration");
-    m_uiForm.tabWidget->addTab(m_uiForm.tabTimeSlice, "Diagnostics");
-    m_uiForm.tabWidget->addTab(m_uiForm.tabTransmission, "Transmission");
-    m_uiForm.tabWidget->addTab(m_uiForm.tabSofQW, "S(Q, w)");
-    m_uiForm.tabWidget->addTab(m_uiForm.tabMoments, "Moments");
-    if ( m_indirectInstruments == NULL )
-    {
-      m_indirectInstruments = new Indirect(qobject_cast<QWidget*>(this->parent()), m_uiForm);
-      m_indirectInstruments->initLayout();
-      connect(m_indirectInstruments, SIGNAL(runAsPythonScript(const QString&, bool)),
-	      this, SIGNAL(runAsPythonScript(const QString&, bool)));
-      m_indirectInstruments->initializeLocalPython();
-    }
-    m_indirectInstruments->performInstSpecific();
-    m_indirectInstruments->setIDFValues(curInstPrefix);
-    break;
-  default:
-    QMessageBox::information(this, "MantidPlot", "Undefined interface type detected.");
-    return;
-  }
-  m_uiForm.swInstrument->setCurrentIndex(desired);
-  m_uiForm.swInputFiles->setCurrentIndex(desired);
-  m_uiForm.swAnalysis->setCurrentIndex(desired);
-  m_uiForm.swConvertToEnergy->setCurrentIndex(desired);
-  m_uiForm.swRebin->setCurrentIndex(desired);
-  m_uiForm.swSave->setCurrentIndex(desired);
-}
-
-/**
- * If the instrument selection has changed, calls instrumentSelectChanged
- * @param prefix :: instrument name from QComboBox object
- */
-void ConvertToEnergy::userSelectInstrument(const QString& prefix) 
-{
-  if ( prefix != m_curInterfaceSetup )
-  {
-    // Remove the old empty instrument workspace if it is there
-    std::string ws_name = "__empty_" + m_curInterfaceSetup.toStdString();
-    Mantid::API::AnalysisDataServiceImpl& dataStore = Mantid::API::AnalysisDataService::Instance();
-    if( dataStore.doesExist(ws_name) )
-    {
-      dataStore.remove(ws_name);
-    }
-
-    m_uiForm.pbRun->setEnabled(false);
-    m_uiForm.cbInst->setEnabled(false);
-    instrumentSelectChanged(prefix);
-    m_uiForm.pbRun->setEnabled(true);
-    m_uiForm.cbInst->setEnabled(true);
-  }
-  if( m_curEmodeType != InDirect )
-  {
-    m_uiForm.pbRun->setEnabled(true);
-  }
-}
-
-void ConvertToEnergy::openDirectoryDialog()
-{
-  MantidQt::API::ManageUserDirectories *ad = new MantidQt::API::ManageUserDirectories(this);
-  ad->show();
-  ad->setFocus();
-}
diff --git a/Code/Mantid/MantidQt/CustomInterfaces/src/CreateMDWorkspaceAlgDialog.cpp b/Code/Mantid/MantidQt/CustomInterfaces/src/CreateMDWorkspaceAlgDialog.cpp
index 8749d77d5501197878ad971327d62033460b5192..7c4e45513b9dcc55fe1e781f38c445ef6d57aeac 100644
--- a/Code/Mantid/MantidQt/CustomInterfaces/src/CreateMDWorkspaceAlgDialog.cpp
+++ b/Code/Mantid/MantidQt/CustomInterfaces/src/CreateMDWorkspaceAlgDialog.cpp
@@ -26,7 +26,7 @@ CreateMDWorkspaceAlgDialog::CreateMDWorkspaceAlgDialog()
   auto QModes = convertToMD->getPointerToProperty("QDimensions")->allowedValues();
   if ( QModes.empty() ) // avoid weird situations with factory not initiated
   {
-    QModes.insert("No Q modes available; error Initiating Q-conversion factory");
+    QModes.push_back("No Q modes available; error Initiating Q-conversion factory");
   }
   for ( auto it = QModes.begin(); it != QModes.end(); ++it )
   {
diff --git a/Code/Mantid/MantidQt/CustomInterfaces/src/DirectConvertToEnergy.cpp b/Code/Mantid/MantidQt/CustomInterfaces/src/DirectConvertToEnergy.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..0b4c427a9533c90b6497ae6abe7f06e6cb3e40a5
--- /dev/null
+++ b/Code/Mantid/MantidQt/CustomInterfaces/src/DirectConvertToEnergy.cpp
@@ -0,0 +1,257 @@
+//----------------------
+// Includes
+//----------------------
+#include "MantidQtCustomInterfaces/DirectConvertToEnergy.h"
+#include "MantidQtCustomInterfaces/Homer.h" // user interface for Direct instruments
+#include "MantidQtAPI/ManageUserDirectories.h"
+
+#include "MantidKernel/ConfigService.h"
+#include "MantidAPI/AlgorithmManager.h"
+#include "MantidAPI/AnalysisDataService.h"
+#include "MantidAPI/ExperimentInfo.h"
+
+#include <QMessageBox>
+#include <QDir>
+
+#include <QDesktopServices>
+#include <QUrl>
+
+//Add this class to the list of specialised dialogs in this namespace
+namespace MantidQt
+{
+  namespace CustomInterfaces
+  {
+    DECLARE_SUBWINDOW(DirectConvertToEnergy);
+  }
+}
+
+namespace
+{
+  Mantid::Kernel::Logger g_log("DirectConvertToEnergy");
+}
+
+using namespace MantidQt::CustomInterfaces;
+//----------------------
+// Public member functions
+//----------------------
+
+/**
+ * Default constructor for class. Initialises interface pointers to NULL values.
+ * @param parent :: This is a pointer to the "parent" object in Qt, most likely the main MantidPlot window.
+ */
+DirectConvertToEnergy::DirectConvertToEnergy(QWidget *parent) :
+  UserSubWindow(parent), m_directInstruments(NULL),
+  m_curInterfaceSetup(""), m_curEmodeType(DirectConvertToEnergy::Undefined), m_settingsGroup("CustomInterfaces/DirectConvertToEnergy"),
+  m_algRunner(new MantidQt::API::AlgorithmRunner(this))
+{
+  //Signals to report load instrument algo result
+  connect(m_algRunner, SIGNAL(algorithmComplete(bool)), this, SLOT(instrumentLoadingDone(bool)));
+}
+
+/**
+ * Destructor
+ */
+DirectConvertToEnergy::~DirectConvertToEnergy()
+{
+  //Make sure no algos are sunning after the window has been closed
+  m_algRunner->cancelRunningAlgorithm();
+
+  saveSettings();
+}
+
+/**
+ * On user clicking the "help" button on the interface, directs their request to the relevant
+ * interface's helpClicked() function.
+ */
+void DirectConvertToEnergy::helpClicked()
+{
+  m_directInstruments->helpClicked();
+}
+
+/**
+ * This is the function called when the "Run" button is clicked. It will call the relevent function
+ * in the subclass.
+ */
+void DirectConvertToEnergy::runClicked()
+{
+  m_directInstruments->runClicked();
+}
+
+/**
+ * Sets up Qt UI file and connects signals, slots. 
+ */
+void DirectConvertToEnergy::initLayout()
+{
+  m_uiForm.setupUi(this);
+  m_curInterfaceSetup = "";
+  m_curEmodeType = Undefined;
+
+  // Assume we get a incompatiable instrument to start with
+  m_uiForm.pbRun->setEnabled(false);
+
+  // Signal / Slot Connections Set Up Here
+
+  // signal/slot connections to respond to changes in instrument selection combo boxes
+  connect(m_uiForm.cbInst, SIGNAL(instrumentSelectionChanged(const QString&)), this, SLOT(userSelectInstrument(const QString&)));
+
+  // connect "?" (Help) Button
+  connect(m_uiForm.pbHelp, SIGNAL(clicked()), this, SLOT(helpClicked()));
+  // connect the "Run" button
+  connect(m_uiForm.pbRun, SIGNAL(clicked()), this, SLOT(runClicked()));
+  // connect the "Manage User Directories" Button
+  connect(m_uiForm.pbManageDirectories, SIGNAL(clicked()), this, SLOT(openDirectoryDialog()));
+
+}
+
+/**
+ * This function is ran after initLayout(), and runPythonCode is unavailable before this function
+ * has run (because of the setup of the base class). For this reason, "setup" functions that require
+ * Python scripts are located here.
+ */
+void DirectConvertToEnergy::initLocalPython()
+{
+  // select starting instrument
+  readSettings();
+
+  if ( m_curInterfaceSetup == "" )
+  {
+    userSelectInstrument(m_uiForm.cbInst->currentText());
+  }
+}
+
+/**
+ * Read settings from the persistent store
+ */
+void DirectConvertToEnergy::readSettings()
+{
+  QSettings settings;
+  settings.beginGroup(m_settingsGroup);
+  QString instrName = settings.value("instrument-name", "").toString();
+  settings.endGroup();
+
+  setDefaultInstrument(instrName);
+}
+
+/**
+ * Save settings to a persistent storage
+ */
+void DirectConvertToEnergy::saveSettings()
+{
+  QSettings settings;
+  settings.beginGroup(m_settingsGroup);
+  QString instrName;
+  if( m_curEmodeType == Undefined )
+  {
+    instrName = "";
+  }
+  else
+  {
+    instrName = m_uiForm.cbInst->currentText();
+  }
+
+  settings.setValue("instrument-name", instrName);
+  settings.endGroup();
+}
+
+/**
+ * Sets up the initial instrument for the interface. This value is taken from the users'
+ * settings in the menu View -> Preferences -> Mantid -> Instrument
+ * @param name :: The name of the default instrument
+ */
+void DirectConvertToEnergy::setDefaultInstrument(const QString & name)
+{
+  if( name.isEmpty() ) return;
+
+  int index = m_uiForm.cbInst->findText(name);
+  if( index >= 0 )
+  {
+    m_uiForm.cbInst->setCurrentIndex(index);
+  }
+}
+
+/**
+ * This function: 1. loads the instrument and gets the value of deltaE-mode parameter
+ *				 2. Based on this value, makes the necessary changes to the form setup (direct or indirect).
+ * @param name :: name of the instrument from the QComboBox
+ */
+void DirectConvertToEnergy::instrumentSelectChanged(const QString& name)
+{
+  QString defFile = (Mantid::API::ExperimentInfo::getInstrumentFilename(name.toStdString())).c_str();
+  if((defFile == "") || !m_uiForm.cbInst->isVisible())
+  {
+    g_log.error("Instument loading failed!");
+    m_uiForm.cbInst->setEnabled(true);
+    m_uiForm.pbRun->setEnabled(true);
+    return;
+  }
+
+  m_curInterfaceSetup = name;
+
+  QString outWS = "__empty_" + m_uiForm.cbInst->currentText();
+
+  Mantid::API::IAlgorithm_sptr instLoader = Mantid::API::AlgorithmManager::Instance().create("LoadEmptyInstrument", -1);
+  instLoader->initialize();
+  instLoader->setProperty("Filename", defFile.toStdString());
+  instLoader->setProperty("OutputWorkspace", outWS.toStdString());
+ 
+  //Ensure no other algorithm is running
+  m_algRunner->cancelRunningAlgorithm();
+  m_algRunner->startAlgorithm(instLoader);
+}
+
+/**
+ * Tasks to be carried out after an empty instument has finished loading
+ */
+void DirectConvertToEnergy::instrumentLoadingDone(bool error)
+{
+  QString curInstPrefix = m_uiForm.cbInst->itemData(m_uiForm.cbInst->currentIndex()).toString();
+  if((curInstPrefix == "") || error)
+  {
+    g_log.error("Instument loading failed! (this can be caused by having both direct and indirect interfaces open)");
+    m_uiForm.cbInst->setEnabled(true);
+    m_uiForm.pbRun->setEnabled(true);
+    return;
+  }
+
+  if(m_directInstruments == NULL)
+  {
+    m_directInstruments = new Homer(qobject_cast<QWidget*>(this->parent()), m_uiForm);
+    m_directInstruments->initLayout();
+    connect(m_directInstruments, SIGNAL(runAsPythonScript(const QString&, bool)),
+        this, SIGNAL(runAsPythonScript(const QString&, bool)));
+    m_directInstruments->initializeLocalPython();
+  }
+  m_directInstruments->setIDFValues(curInstPrefix);
+
+  m_uiForm.cbInst->setEnabled(true);
+  m_uiForm.pbRun->setEnabled(true);
+}
+
+/**
+ * If the instrument selection has changed, calls instrumentSelectChanged
+ * @param prefix :: instrument name from QComboBox object
+ */
+void DirectConvertToEnergy::userSelectInstrument(const QString& prefix) 
+{
+  if ( prefix != m_curInterfaceSetup )
+  {
+    // Remove the old empty instrument workspace if it is there
+    std::string ws_name = "__empty_" + m_curInterfaceSetup.toStdString();
+    Mantid::API::AnalysisDataServiceImpl& dataStore = Mantid::API::AnalysisDataService::Instance();
+    if( dataStore.doesExist(ws_name) )
+    {
+      dataStore.remove(ws_name);
+    }
+
+    m_uiForm.pbRun->setEnabled(false);
+    m_uiForm.cbInst->setEnabled(false);
+    instrumentSelectChanged(prefix);
+  }
+}
+
+void DirectConvertToEnergy::openDirectoryDialog()
+{
+  MantidQt::API::ManageUserDirectories *ad = new MantidQt::API::ManageUserDirectories(this);
+  ad->show();
+  ad->setFocus();
+}
diff --git a/Code/Mantid/MantidQt/CustomInterfaces/src/Homer.cpp b/Code/Mantid/MantidQt/CustomInterfaces/src/Homer.cpp
index 6161e99660add6f4f2717bf750d0c7f3c71dc40d..7c1155de353db146a65a571605f020b7eb66fef6 100644
--- a/Code/Mantid/MantidQt/CustomInterfaces/src/Homer.cpp
+++ b/Code/Mantid/MantidQt/CustomInterfaces/src/Homer.cpp
@@ -35,7 +35,7 @@ using namespace MantidQt::CustomInterfaces;
 // Public member functions
 //----------------------
 ///Constructor
-Homer::Homer(QWidget *parent, Ui::ConvertToEnergy & uiForm) : 
+Homer::Homer(QWidget *parent, Ui::DirectConvertToEnergy & uiForm) : 
   UserSubWindow(parent), m_uiForm(uiForm),
   m_backgroundDialog(NULL), m_diagPage(NULL),m_saveChanged(false),
   m_backgroundWasVisible(false), m_absEiDirty(false), m_topSettingsGroup("CustomInterfaces/Homer")
@@ -424,11 +424,11 @@ void Homer::syncBackgroundSettings()
 {
   if( m_backgroundDialog->removeBackground() )
   {
-    m_uiForm.pbBack->setText("bg removal: on");
+    m_uiForm.pbBack->setText("BG removal: on");
   }
   else
   {
-    m_uiForm.pbBack->setText("bg removal: none");
+    m_uiForm.pbBack->setText("BG removal: none");
   }
   // send the values to the detector diagnostics form, they are used as suggested values
   QPair<double,double> bgRange = m_backgroundDialog->getRange();
diff --git a/Code/Mantid/MantidQt/CustomInterfaces/src/Indirect.cpp b/Code/Mantid/MantidQt/CustomInterfaces/src/Indirect.cpp
deleted file mode 100644
index df2e069f813202a7638be898e4bdcb17366beee1..0000000000000000000000000000000000000000
--- a/Code/Mantid/MantidQt/CustomInterfaces/src/Indirect.cpp
+++ /dev/null
@@ -1,2100 +0,0 @@
-#include "MantidQtCustomInterfaces/Indirect.h"
-#include "MantidQtCustomInterfaces/Transmission.h"
-#include "MantidQtCustomInterfaces/IndirectMoments.h"
-#include "MantidQtCustomInterfaces/UserInputValidator.h"
-#include "MantidQtCustomInterfaces/Background.h"
-
-#include "MantidKernel/ConfigService.h"
-#include "MantidAPI/AnalysisDataService.h"
-#include "MantidAPI/MatrixWorkspace.h"
-
-#include <cmath>
-#include <Poco/NObserver.h>
-
-#include <QUrl>
-#include <QDesktopServices>
-#include <QDir>
-#include <QFileDialog>
-#include <QInputDialog>
-#include <QLineEdit>
-
-// Suppress a warning coming out of code that isn't ours
-#if defined(__INTEL_COMPILER)
-  #pragma warning disable 1125
-#elif defined(__GNUC__)
-  #if (__GNUC__ >= 4 && __GNUC_MINOR__ >= 6 )
-    #pragma GCC diagnostic push
-  #endif
-  #pragma GCC diagnostic ignored "-Woverloaded-virtual"
-#endif
-#include "qttreepropertybrowser.h"
-#include "qtpropertymanager.h"
-#include "qteditorfactory.h"
-#include "DoubleEditorFactory.h"
-#if defined(__INTEL_COMPILER)
-  #pragma warning enable 1125
-#elif defined(__GNUC__)
-  #if (__GNUC__ >= 4 && __GNUC_MINOR__ >= 6 )
-    #pragma GCC diagnostic pop
-  #endif
-#endif
-#include <QtCheckBoxFactory>
-
-using namespace MantidQt::CustomInterfaces;
-using namespace MantidQt;
-using Mantid::MantidVec;
-
-/**
-* This is the constructor for the Indirect Instruments Interface.
-* It is used primarily to ensure sane values for member variables.
-*/
-Indirect::Indirect(QWidget *parent, Ui::ConvertToEnergy & uiForm) : 
-  UserSubWindow(parent), m_uiForm(uiForm), m_backgroundDialog(NULL),
-  m_changeObserver(*this, &Indirect::handleDirectoryChange),
-  m_bgRemoval(false), m_valInt(NULL), m_valDbl(NULL), m_valPosDbl(NULL), 
-  // Null pointers - Calibration Tab
-  m_calCalPlot(NULL), m_calResPlot(NULL),
-  m_calCalR1(NULL), m_calCalR2(NULL), m_calResR1(NULL),
-  m_calCalCurve(NULL), m_calResCurve(NULL),
-  // Null pointers - Diagnostics Tab
-  m_sltPlot(NULL), m_sltR1(NULL), m_sltR2(NULL), m_sltDataCurve(NULL),
-  // Additional tab interfaces
-  m_tab_trans(new Transmission(m_uiForm,this)),
-  m_tab_moments(new IndirectMoments(m_uiForm,this))
-{
-  // Constructor
-}
-/**
-* This function performs any one-time actions needed when the Inelastic interface
-* is first selected, such as connecting signals to slots.
-*/
-void Indirect::initLayout()
-{
-  Mantid::Kernel::ConfigService::Instance().addObserver(m_changeObserver);
-
-  m_settingsGroup = "CustomInterfaces/ConvertToEnergy/Indirect/";
-
-  setupCalibration(); // setup the calibration miniplots
-  setupSlice(); // setup the slice miniplot
-
-  // "Energy Transfer" tab
-  connect(m_uiForm.cbAnalyser, SIGNAL(activated(int)), this, SLOT(analyserSelected(int)));
-  connect(m_uiForm.cbReflection, SIGNAL(activated(int)), this, SLOT(reflectionSelected(int)));
-  connect(m_uiForm.cbMappingOptions, SIGNAL(currentIndexChanged(const QString&)), this, SLOT(mappingOptionSelected(const QString&)));
-  connect(m_uiForm.pbBack_2, SIGNAL(clicked()), this, SLOT(backgroundClicked()));
-  connect(m_uiForm.pbPlotRaw, SIGNAL(clicked()), this, SLOT(plotRaw()));
-  connect(m_uiForm.rebin_ckDNR, SIGNAL(toggled(bool)), this, SLOT(rebinCheck(bool)));
-  connect(m_uiForm.ckDetailedBalance, SIGNAL(toggled(bool)), this, SLOT(detailedBalanceCheck(bool)));
-
-  connect(m_uiForm.ckScaleMultiplier, SIGNAL(toggled(bool)), this, SLOT(scaleMultiplierCheck(bool)));
-
-  connect(m_uiForm.ind_calibFile, SIGNAL(fileTextChanged(const QString &)), this, SLOT(calibFileChanged(const QString &)));
-  connect(m_uiForm.ckUseCalib, SIGNAL(toggled(bool)), this, SLOT(useCalib(bool)));
-
-  connect(m_uiForm.tabWidget, SIGNAL(currentChanged(int)), this, SLOT(tabChanged(int)));
-  connect(m_uiForm.cbIndRebType, SIGNAL(currentIndexChanged(int)), m_uiForm.swIndRebin, SLOT(setCurrentIndex(int)));
-
-  connect(m_uiForm.ind_runFiles, SIGNAL(fileTextChanged(const QString &)), this, SLOT(pbRunEditing()));
-  connect(m_uiForm.ind_runFiles, SIGNAL(findingFiles()), this, SLOT(pbRunFinding()));
-  connect(m_uiForm.ind_runFiles, SIGNAL(fileFindingFinished()), this, SLOT(pbRunFinished()));
-
-  // "Calibration" tab
-  connect(m_uiForm.cal_leRunNo, SIGNAL(filesFound()), this, SLOT(calPlotRaw()));
-  connect(m_uiForm.cal_pbPlot, SIGNAL(clicked()), this, SLOT(calPlotRaw()));
-  connect(m_uiForm.cal_ckRES, SIGNAL(toggled(bool)), this, SLOT(resCheck(bool)));
-  connect(m_uiForm.cal_ckRES, SIGNAL(toggled(bool)), m_uiForm.cal_ckResScale, SLOT(setEnabled(bool)));
-  connect(m_uiForm.cal_ckResScale, SIGNAL(toggled(bool)), m_uiForm.cal_leResScale, SLOT(setEnabled(bool)));
-  connect(m_uiForm.cal_ckIntensityScaleMultiplier, SIGNAL(toggled(bool)), this, SLOT(intensityScaleMultiplierCheck(bool)));
-  connect(m_uiForm.cal_leIntensityScaleMultiplier, SIGNAL(textChanged(const QString &)), this, SLOT(calibValidateIntensity(const QString &)));
-
-  // "SofQW" tab
-  connect(m_uiForm.sqw_ckRebinE, SIGNAL(toggled(bool)), this, SLOT(sOfQwRebinE(bool)));
-  connect(m_uiForm.sqw_dsSampleInput, SIGNAL(loadClicked()), this, SLOT(sOfQwPlotInput()));
-
-  // "Slice" tab
-  connect(m_uiForm.slice_inputFile, SIGNAL(filesFound()), this, SLOT(slicePlotRaw()));
-  connect(m_uiForm.slice_pbPlotRaw, SIGNAL(clicked()), this, SLOT(slicePlotRaw()));
-  connect(m_uiForm.slice_ckUseCalib, SIGNAL(toggled(bool)), this, SLOT(sliceCalib(bool)));
-
-  // additional tabs
-  connect(m_tab_trans, SIGNAL(runAsPythonScript(const QString&, bool)), this, SIGNAL(runAsPythonScript(const QString&, bool)));
-  connect(m_tab_moments, SIGNAL(runAsPythonScript(const QString&, bool)), this, SIGNAL(runAsPythonScript(const QString&, bool)));
-  
-  connect(m_tab_trans, SIGNAL(showMessageBox(const QString&)), this, SLOT(showMessageBox(const QString&)));
-  connect(m_tab_moments, SIGNAL(showMessageBox(const QString&)), this, SLOT(showMessageBox(const QString&)));
-
-  // create validators
-  m_valInt = new QIntValidator(this);
-  m_valDbl = new QDoubleValidator(this);
-  m_valPosDbl = new QDoubleValidator(this);
-
-
-  // Tolerance chosen arbitrarily. Avoids dividing by zero elsewhere.
-  const double tolerance = 0.00001;
-  m_valPosDbl->setBottom(tolerance);
-
-  // apply validators
-  m_uiForm.leNoGroups->setValidator(m_valInt);
-  m_uiForm.leDetailedBalance->setValidator(m_valPosDbl);
-  m_uiForm.leSpectraMin->setValidator(m_valInt);
-  m_uiForm.leSpectraMax->setValidator(m_valInt);
-  m_uiForm.rebin_leELow->setValidator(m_valDbl);
-  m_uiForm.rebin_leEWidth->setValidator(m_valDbl);
-  m_uiForm.rebin_leEHigh->setValidator(m_valDbl);
-
-  m_uiForm.leScaleMultiplier->setValidator(m_valPosDbl);
-  m_uiForm.cal_leIntensityScaleMultiplier->setValidator(m_valDbl);
-  m_uiForm.cal_leResScale->setValidator(m_valDbl);
-  
-  m_uiForm.sqw_leELow->setValidator(m_valDbl);
-  m_uiForm.sqw_leEWidth->setValidator(m_valDbl);
-  m_uiForm.sqw_leEHigh->setValidator(m_valDbl);
-  m_uiForm.sqw_leQLow->setValidator(m_valDbl);
-  m_uiForm.sqw_leQWidth->setValidator(m_valDbl);
-  m_uiForm.sqw_leQHigh->setValidator(m_valDbl);
-
-
-  // set default values for save formats
-  m_uiForm.save_ckSPE->setChecked(false);
-  m_uiForm.save_ckNexus->setChecked(true);
-
-  m_uiForm.cal_valIntensityScaleMultiplier->setText(" ");
-
-  // nudge "Background Removal" button to display whether it is
-  // set to "OFF" or "ON".
-  backgroundRemoval();
-  // nudge tabChanged too, so that we start off with a "Run Energy Transfer" button
-  // instead of a "Run" button which then changes when clicking on a different tab.
-  tabChanged(0);
-
-  loadSettings();
-}
-/**
-* This function will hold any Python-dependent setup actions for the interface.
-*/
-void Indirect::initLocalPython()
-{
-  // Nothing to do here at the moment.
-}
-
-/**
-* This function opens a web browser window to the Mantid Project wiki page for this
-* interface ("Inelastic" subsection of ConvertToEnergy).
-*/
-void Indirect::helpClicked()
-{
-  QString tabName = m_uiForm.tabWidget->tabText(m_uiForm.tabWidget->currentIndex());
-  QString url = "http://www.mantidproject.org/Indirect:";
-  if ( tabName == "Energy Transfer" )
-    url += "EnergyTransfer";
-  else if ( tabName == "Calibration" )
-    url += "Calibration";
-  else if ( tabName == "Diagnostics" )
-    url += "Diagnostics";
-  else if ( tabName == "S(Q, w)" )
-    url += "SofQW";
-  else if (tabName == "Transmission")
-    url += "Transmission";
-  else if (tabName == "Moments")
-    url += "Moments";
-  QDesktopServices::openUrl(QUrl(url));
-}
-/**
-* This function will control the actions needed for the Indirect interface when the
-* "Run" button is clicked by the user.
-*/
-void Indirect::runClicked()
-{
-  QString tabName = m_uiForm.tabWidget->tabText(m_uiForm.tabWidget->currentIndex());
-
-  if ( tabName == "Energy Transfer" )
-  {
-    runConvertToEnergy();
-  }
-  else if ( tabName == "Calibration" )
-  {
-    calibCreate();
-  }
-  else if ( tabName == "Diagnostics" )
-  {
-    sliceRun();
-  }
-  else if ( tabName == "S(Q, w)" )
-  {
-    sOfQwClicked();
-  }
-  else if (tabName == "Transmission")
-  {
-    m_tab_trans->runTab();
-  }
-  else if(tabName == "Moments")
-  {
-    m_tab_moments->runTab();
-  }
-}
-
-void Indirect::runConvertToEnergy()
-{
-  if ( ! validateInput() )
-  {
-    showInformationBox("Please check the input highlighted in red.");
-    return;
-  }
-
-  QString pyInput =
-    "import inelastic_indirect_reducer as iir\n"
-    "reducer = iir.IndirectReducer()\n"
-    "reducer.set_instrument_name('" + m_uiForm.cbInst->currentText() + "')\n"
-    "reducer.set_detector_range(" +m_uiForm.leSpectraMin->text()+ "-1, " +m_uiForm.leSpectraMax->text()+ "-1)\n"
-    "reducer.set_parameter_file('" + QString::fromStdString(Mantid::Kernel::ConfigService::Instance().getString("instrumentDefinition.directory")) + m_uiForm.cbInst->currentText() + "_" + m_uiForm.cbAnalyser->currentText() + "_" + m_uiForm.cbReflection->currentText() + "_Parameters.xml')\n";
-
-  QStringList files = m_uiForm.ind_runFiles->getFilenames();
-  for ( QStringList::iterator it = files.begin(); it != files.end(); ++it )
-  {
-    pyInput += "reducer.append_data_file(r'" + *it + "')\n";
-  }
-
-  if ( m_uiForm.ckSumFiles->isChecked() )
-  {
-    pyInput += "reducer.set_sum_files(True)\n";
-  }
-
-  if ( m_bgRemoval )
-  {
-    QPair<double,double> background = m_backgroundDialog->getRange();
-    pyInput += "reducer.set_background("+QString::number(background.first)+", "+QString::number(background.second)+")\n";
-  }
-
-  if ( m_uiForm.ckUseCalib->isChecked() )
-  {
-    pyInput +=
-      "from IndirectCommon import loadNexus\n"
-      "reducer.set_calibration_workspace(loadNexus(r'"+m_uiForm.ind_calibFile->getFirstFilename()+"'))\n";
-  }
-
-  if ( m_uiForm.ckLoadLogs->isChecked() )
-  {
-    pyInput += "reducer.set_load_logs(True)\n";
-  }
-
-  if ( ! m_uiForm.rebin_ckDNR->isChecked() )
-  {
-    QString rebin;
-    if ( m_uiForm.cbIndRebType->currentIndex() == 0 )
-    {
-      rebin = m_uiForm.rebin_leELow->text() + "," + m_uiForm.rebin_leEWidth->text() + "," + m_uiForm.rebin_leEHigh->text();
-    }
-    else
-    {
-      rebin = m_uiForm.leRebinString->text();
-    }
-    pyInput += "reducer.set_rebin_string('"+rebin+"')\n";
-  }
-
-  if ( m_uiForm.ckDetailedBalance->isChecked() )
-  {
-    pyInput += "reducer.set_detailed_balance(" + m_uiForm.leDetailedBalance->text() + ")\n";
-  }
-
-  if ( m_uiForm.ckScaleMultiplier->isChecked() )
-  {
-    pyInput += "reducer.set_scale_factor(" + m_uiForm.leScaleMultiplier->text() + ")\n";
-  }
-
-  if ( m_uiForm.cbMappingOptions->currentText() != "Default" )
-  {
-    QString grouping = createMapFile(m_uiForm.cbMappingOptions->currentText());
-    pyInput += "reducer.set_grouping_policy('" + grouping + "')\n";
-  }
-
-  if ( ! m_uiForm.ckRenameWorkspace->isChecked() )
-  {
-    pyInput += "reducer.set_rename(False)\n";
-  }
-
-  if ( ! m_uiForm.ckFold->isChecked() )
-  {
-    pyInput += "reducer.set_fold_multiple_frames(False)\n";
-  }
-
-  if( m_uiForm.ckCm1Units->isChecked() )
-  {
-    pyInput += "reducer.set_save_to_cm_1(True)\n";
-  }
-  
-  pyInput += "reducer.set_save_formats([" + savePyCode() + "])\n";
-
-  pyInput +=
-    "reducer.reduce()\n"
-    "ws_list = reducer.get_result_workspaces()\n";
-
-  // Plot Output options
-  switch ( m_uiForm.ind_cbPlotOutput->currentIndex() )
-  {
-  case 0: // "None"
-    break;
-  case 1: // "Spectra"
-    {
-      // Plot a spectra of the first result workspace
-      pyInput += 
-        "if ( len(ws_list) > 0 ):\n"
-        "  nSpec = mtd[ws_list[0]].getNumberHistograms()\n"
-        "  plotSpectrum(ws_list[0], range(0, nSpec))\n";
-    }
-    break;
-  case 2: // "Contour"
-    {
-      // Plot a 2D Contour Lines of the first result workspace
-      pyInput += 
-        "if ( len(ws_list) > 0 ):\n"
-        "  ws = importMatrixWorkspace(ws_list[0])\n"
-        "  ws.plotGraph2D()\n";
-    }
-    break;
-  }
-
-  // add sample logs to each of the workspaces
-  QString calibChecked = m_uiForm.ckUseCalib->isChecked() ? "True" : "False";
-  QString detailedBalance = m_uiForm.ckDetailedBalance->isChecked() ? "True" : "False";
-  QString scaled = m_uiForm.ckScaleMultiplier->isChecked() ? "True" : "False";
-  pyInput += "calibCheck = "+calibChecked+"\n"
-             "detailedBalance = "+detailedBalance+"\n"
-             "scaled = "+scaled+"\n"
-             "for ws in ws_list:\n"
-             "  AddSampleLog(Workspace=ws, LogName='calib_file', LogType='String', LogText=str(calibCheck))\n"
-             "  if calibCheck:\n"
-             "    AddSampleLog(Workspace=ws, LogName='calib_file_name', LogType='String', LogText='"+m_uiForm.ind_calibFile->getFirstFilename()+"')\n"
-             "  AddSampleLog(Workspace=ws, LogName='detailed_balance', LogType='String', LogText=str(detailedBalance))\n"
-             "  if detailedBalance:\n"
-             "    AddSampleLog(Workspace=ws, LogName='detailed_balance_temp', LogType='Number', LogText='"+m_uiForm.leDetailedBalance->text()+"')\n"
-             "  AddSampleLog(Workspace=ws, LogName='scale', LogType='String', LogText=str(scaled))\n"
-             "  if scaled:\n"
-             "    AddSampleLog(Workspace=ws, LogName='scale_factor', LogType='Number', LogText='"+m_uiForm.leScaleMultiplier->text()+"')\n";
-
-  QString pyOutput = runPythonCode(pyInput).trimmed();
-}
-
-/**
-* This function holds any steps that must be performed on the selection of an instrument,
-* for example loading values from the Instrument Definition File (IDF).
-* @param prefix :: The selected instruments prefix in Mantid.
-*/
-void Indirect::setIDFValues(const QString & prefix)
-{
-  UNUSED_ARG(prefix);
-  // empty ComboBoxes, LineEdits,etc of previous values
-  m_uiForm.cbAnalyser->clear();
-  m_uiForm.cbReflection->clear();
-  clearReflectionInfo();
-
-  rebinCheck(m_uiForm.rebin_ckDNR->isChecked());
-  detailedBalanceCheck(m_uiForm.ckDetailedBalance->isChecked());
-  resCheck(m_uiForm.cal_ckRES->isChecked());
-
-  scaleMultiplierCheck(m_uiForm.ckScaleMultiplier->isChecked());
-
-  // Get list of analysers and populate cbAnalyser
-  QString pyInput = 
-    "from IndirectEnergyConversion import getInstrumentDetails\n"
-    "result = getInstrumentDetails('" + m_uiForm.cbInst->currentText() + "')\n"
-    "print result\n";
-
-  QString pyOutput = runPythonCode(pyInput).trimmed();
-
-  if ( pyOutput == "" )
-  {
-    showInformationBox("Could not get list of analysers from Instrument Parameter file.");
-  }
-  else
-  {
-    QStringList analysers = pyOutput.split("\n", QString::SkipEmptyParts);
-
-    for (int i = 0; i< analysers.count(); i++ )
-    {
-      QString text; // holds Text field of combo box (name of analyser)
-
-      if ( text != "diffraction" ) // do not put diffraction into the analyser list
-      {
-        QVariant data; // holds Data field of combo box (list of reflections)
-
-        QStringList analyser = analysers[i].split("-", QString::SkipEmptyParts);
-
-        text = analyser[0];
-
-        if ( analyser.count() > 1 )
-        {
-          QStringList reflections = analyser[1].split(",", QString::SkipEmptyParts);
-          data = QVariant(reflections);
-          m_uiForm.cbAnalyser->addItem(text, data);
-        }
-        else
-        {
-          m_uiForm.cbAnalyser->addItem(text);
-        }
-      }
-    }
-
-    analyserSelected(m_uiForm.cbAnalyser->currentIndex());
-  }
-}
-
-/**
-* This function holds any steps that must be performed on the layout that are specific
-* to the currently selected instrument.
-*/
-void Indirect::performInstSpecific()
-{
-  setInstSpecificWidget("cm-1-convert-choice", m_uiForm.ckCm1Units, QCheckBox::Off);
-  setInstSpecificWidget("save-aclimax-choice", m_uiForm.save_ckAclimax, QCheckBox::Off);
-}
-
-/**
-* This function either shows or hides the given QCheckBox, based on the named property
-* inside the instrument param file.  When hidden, the default state will be used to
-* reset to the "unused" state of the checkbox.
-*
-* @param parameterName :: The name of the property to look for inside the current inst param file.
-* @param checkBox :: The checkbox to set the state of, and to either hide or show based on the current inst.
-* @param defaultState :: The state to which the checkbox will be set upon hiding it.
-*/
-void Indirect::setInstSpecificWidget(const std::string & parameterName, QCheckBox * checkBox, QCheckBox::ToggleState defaultState)
-{
-  // Get access to instrument specific parameters via the loaded empty workspace.
-  std::string instName = m_uiForm.cbInst->currentText().toStdString();
-  Mantid::API::MatrixWorkspace_sptr input = boost::dynamic_pointer_cast<Mantid::API::MatrixWorkspace>(Mantid::API::AnalysisDataService::Instance().retrieve("__empty_" + instName));
-  if(NULL == input)
-    return;
-  Mantid::Geometry::Instrument_const_sptr instr = input->getInstrument();
-
-  // See if the instrument params file requests that the checkbox be shown to the user.
-  std::vector<std::string> showParams = instr->getStringParameter(parameterName);
-  
-  std::string show = "";
-  if(!showParams.empty())
-    show = showParams[0];
-  
-  if(show == "Show")
-    checkBox->setHidden(false);
-  else
-  {
-    checkBox->setHidden(true);
-    checkBox->setState(defaultState);
-  }
-}
-
-void Indirect::closeEvent(QCloseEvent* close)
-{
-  (void) close;
-  Mantid::Kernel::ConfigService::Instance().removeObserver(m_changeObserver);
-}
-
-void Indirect::handleDirectoryChange(Mantid::Kernel::ConfigValChangeNotification_ptr pNf)
-{
-  std::string key = pNf->key();
-  // std::string preValue = pNf->preValue(); // Unused
-  // std::string curValue = pNf->curValue(); // Unused
-
-  if ( key == "datasearch.directories" || key == "defaultsave.directory" )
-  {
-    loadSettings();
-  }
-}
-/**
-* This function clears the values of the QLineEdit objec  ts used to hold Reflection-specific
-* information.
-*/
-void Indirect::clearReflectionInfo()
-{
-  m_uiForm.leSpectraMin->clear();
-  m_uiForm.leSpectraMax->clear();
-  m_uiForm.leEfixed->clear();
-}
-/**
-* This function creates the mapping/grouping file for the data analysis.
-* @param groupType :: Type of grouping (All, Group, Indiviual)
-* @return path to mapping file, or an empty string if file could not be created.
-*/
-QString Indirect::createMapFile(const QString& groupType)
-{
-  QString groupFile, ngroup, nspec;
-  QString ndet = "( "+m_uiForm.leSpectraMax->text()+" - "+m_uiForm.leSpectraMin->text()+") + 1";
-
-  if ( groupType == "File" )
-  {
-    groupFile = m_uiForm.ind_mapFile->getFirstFilename();
-    if ( groupFile == "" )
-    {
-      showInformationBox("You must enter a path to the .map file.");
-    }
-    return groupFile;
-  }
-  else if ( groupType == "Groups" )
-  {
-    ngroup = m_uiForm.leNoGroups->text();
-    nspec = "( " +ndet+ " ) / " +ngroup;
-  }
-  else if ( groupType == "All" )
-  {
-    return "All";
-  }
-  else if ( groupType == "Individual" )
-  {
-    return "Individual";
-  }
-
-  groupFile = m_uiForm.cbInst->itemData(m_uiForm.cbInst->currentIndex()).toString().toLower();
-  groupFile += "_" + m_uiForm.cbAnalyser->currentText() + m_uiForm.cbReflection->currentText();
-  groupFile += "_" + groupType + ".map";	
-
-  QString pyInput =
-    "import IndirectEnergyConversion as ind\n"
-    "mapfile = ind.createMappingFile('"+groupFile+"', %1, %2, %3)\n"
-    "print mapfile\n";
-  pyInput = pyInput.arg(ngroup);
-  pyInput = pyInput.arg(nspec);
-  pyInput = pyInput.arg(m_uiForm.leSpectraMin->text());
-
-  QString pyOutput = runPythonCode(pyInput).trimmed();
-
-  return pyOutput;
-}
-/**
-* This function creates the Python script necessary to set the variables used for saving data
-* in the main convert_to_energy script.
-* @return python code as a string
-*/
-QString Indirect::savePyCode()
-{
-  QStringList fileFormats;
-  QString fileFormatList;
-
-  if ( m_uiForm.save_ckNexus->isChecked() )
-    fileFormats << "nxs";
-  if ( m_uiForm.save_ckSPE->isChecked() )
-    fileFormats << "spe";
-  if ( m_uiForm.save_ckNxSPE->isChecked() )
-    fileFormats << "nxspe";
-  if ( m_uiForm.save_ckAscii->isChecked() )
-    fileFormats << "ascii";
-  if ( m_uiForm.save_ckAclimax->isChecked() )
-    fileFormats << "aclimax";
-
-  if ( fileFormats.size() != 0 )
-    fileFormatList = "'" + fileFormats.join("', '") + "'";
-  else
-    fileFormatList = "";
-
-  return fileFormatList;
-}
-/**
-* This function is called after calib has run and creates a RES file for use in later analysis (Fury,etc)
-* @param file :: the input file (WBV run.raw)
-*/
-void Indirect::createRESfile(const QString& file)
-{
-  QString scaleFactor("1.0");
-  if(m_uiForm.cal_ckResScale->isChecked())
-  {
-    if(!m_uiForm.cal_leResScale->text().isEmpty())
-    {
-      scaleFactor = m_uiForm.cal_leResScale->text();
-    }
-  }
-
-  QString pyInput =
-    "from IndirectEnergyConversion import resolution\n"
-    "iconOpt = { 'first': " +QString::number(m_calDblMng->value(m_calResProp["SpecMin"]))+
-    ", 'last': " +QString::number(m_calDblMng->value(m_calResProp["SpecMax"]))+"}\n"
-
-    "instrument = '" + m_uiForm.cbInst->currentText() + "'\n"
-    "analyser = '" + m_uiForm.cbAnalyser->currentText() + "'\n"
-    "reflection = '" + m_uiForm.cbReflection->currentText() + "'\n";
-
-  if ( m_uiForm.cal_ckPlotResult->isChecked() ) { pyInput +=	"plot = True\n"; }
-  else { pyInput += "plot = False\n"; }
-
-  if ( m_uiForm.cal_ckVerbose->isChecked() ) { pyInput +=  "verbose = True\n"; }
-  else { pyInput += "verbose = False\n"; }
-
-  if ( m_uiForm.cal_ckSave->isChecked() ) { pyInput +=  "save = True\n"; }
-  else { pyInput += "save = False\n"; }
-
-  QString rebinParam = QString::number(m_calDblMng->value(m_calResProp["ELow"])) + "," +
-    QString::number(m_calDblMng->value(m_calResProp["EWidth"])) + "," +
-    QString::number(m_calDblMng->value(m_calResProp["EHigh"]));
-
-  QString background = "[ " +QString::number(m_calDblMng->value(m_calResProp["Start"]))+ ", " +QString::number(m_calDblMng->value(m_calResProp["End"]))+"]";
-
-  QString scaled = m_uiForm.cal_ckIntensityScaleMultiplier->isChecked() ? "True" : "False";
-  pyInput +=
-    "background = " + background + "\n"
-    "rebinParam = '" + rebinParam + "'\n"
-    "file = " + file + "\n"
-    "ws = resolution(file, iconOpt, rebinParam, background, instrument, analyser, reflection, Verbose=verbose, Plot=plot, Save=save, factor="+scaleFactor+")\n"
-    "scaled = "+ scaled +"\n"
-    "scaleFactor = "+m_uiForm.cal_leIntensityScaleMultiplier->text()+"\n"
-    "backStart = "+QString::number(m_calDblMng->value(m_calCalProp["BackMin"]))+"\n"
-    "backEnd = "+QString::number(m_calDblMng->value(m_calCalProp["BackMax"]))+"\n"
-    "rebinLow = "+QString::number(m_calDblMng->value(m_calResProp["ELow"]))+"\n"
-    "rebinWidth = "+QString::number(m_calDblMng->value(m_calResProp["EWidth"]))+"\n"
-    "rebinHigh = "+QString::number(m_calDblMng->value(m_calResProp["EHigh"]))+"\n"
-    "AddSampleLog(Workspace=ws, LogName='scale', LogType='String', LogText=str(scaled))\n"
-    "if scaled:"
-    "  AddSampleLog(Workspace=ws, LogName='scale_factor', LogType='Number', LogText=str(scaleFactor))\n"
-    "AddSampleLog(Workspace=ws, LogName='back_start', LogType='Number', LogText=str(backStart))\n"
-    "AddSampleLog(Workspace=ws, LogName='back_end', LogType='Number', LogText=str(backEnd))\n"
-    "AddSampleLog(Workspace=ws, LogName='rebin_low', LogType='Number', LogText=str(rebinLow))\n"
-    "AddSampleLog(Workspace=ws, LogName='rebin_width', LogType='Number', LogText=str(rebinWidth))\n"
-    "AddSampleLog(Workspace=ws, LogName='rebin_high', LogType='Number', LogText=str(rebinHigh))\n";
-
-  QString pyOutput = runPythonCode(pyInput).trimmed();
-
-  if ( pyOutput != "" )
-  {
-    showInformationBox("Unable to create RES file: \n" + pyOutput);
-  }
-}
-/**
-* This function validates the input for the Convert To Energy process, highlighting invalid items.
-* @return true if input is ok, false otherwise
-*/
-bool Indirect::validateInput()
-{
-  bool valid = true;
-
-  // run files input
-  if ( ! m_uiForm.ind_runFiles->isValid() )
-  {
-    valid = false;
-  }
-
-  // calib file input
-  if ( m_uiForm.ckUseCalib->isChecked() && !m_uiForm.ind_calibFile->isValid() )
-  {
-    valid = false;
-  }
-
-  // mapping selection
-  if (
-    ( m_uiForm.cbMappingOptions->currentText() == "Groups" && m_uiForm.leNoGroups->text() == "" ) 
-    ||
-    ( m_uiForm.cbMappingOptions->currentText() == "File" && ! m_uiForm.ind_mapFile->isValid() )
-    )
-  {
-    valid = false;
-    m_uiForm.valNoGroups->setText("*");
-  }
-  else
-  {
-    m_uiForm.valNoGroups->setText("");
-  }
-
-  int dummyPos = 0;
-
-  QString text = m_uiForm.leDetailedBalance->text();
-  QValidator::State fieldState = m_uiForm.leDetailedBalance->validator()->validate(text, dummyPos);
-
-  // detailed balance
-  if ( m_uiForm.ckDetailedBalance->isChecked() && fieldState != QValidator::Acceptable )
-  {
-    valid = false;
-    m_uiForm.valDetailedBalance->setText("*");
-  }
-  else
-  {
-    m_uiForm.valDetailedBalance->setText("");
-  }
-
-  int dummyPos2 = 0;
-
-  // scale multiplier
-  QString scaleMultiplierText = m_uiForm.leScaleMultiplier->text();
-  QValidator::State fieldState2 = m_uiForm.leScaleMultiplier->validator()->validate(scaleMultiplierText, dummyPos2);
-
-  if ( m_uiForm.ckScaleMultiplier->isChecked() && fieldState2 != QValidator::Acceptable )
-  {
-    valid = false;
-    m_uiForm.valScaleMultiplier->setText("*");
-  }
-  else
-  {
-    m_uiForm.valScaleMultiplier->setText("");
-  }
-
-
-  // SpectraMin/SpectraMax
-  const QString specMin = m_uiForm.leSpectraMin->text();
-  const QString specMax = m_uiForm.leSpectraMax->text();
-
-  if (specMin.isEmpty() || specMax.isEmpty() ||
-      (specMin.toDouble() < 1 || specMax.toDouble() < 1) ||  
-      (specMin.toDouble() > specMax.toDouble()))
-  {
-    valid = false;
-    m_uiForm.valSpectraMin->setText("*");
-    m_uiForm.valSpectraMax->setText("*");
-  }
-  else
-  {
-    m_uiForm.valSpectraMin->setText("");
-    m_uiForm.valSpectraMax->setText("");
-  }
-
-  if ( ! m_uiForm.rebin_ckDNR->isChecked() )
-  {
-    if ( m_uiForm.cbIndRebType->currentIndex() == 0 )
-    {
-    if ( m_uiForm.rebin_leELow->text() == "" )
-    {
-      valid = false;
-      m_uiForm.valELow->setText("*");
-    }
-    else
-    {
-      m_uiForm.valELow->setText("");
-    }
-
-    if ( m_uiForm.rebin_leEWidth->text() == "" )
-    {
-      valid = false;
-      m_uiForm.valEWidth->setText("*");
-    }
-    else
-    {
-      m_uiForm.valEWidth->setText("");
-    }
-
-    if ( m_uiForm.rebin_leEHigh->text() == "" )
-    {
-      valid = false;
-      m_uiForm.valEHigh->setText("*");
-    }
-    else
-    {
-      m_uiForm.valEHigh->setText("");
-    }
-
-    if ( m_uiForm.rebin_leELow->text().toDouble() > m_uiForm.rebin_leEHigh->text().toDouble() )
-    {
-      valid = false;
-      m_uiForm.valELow->setText("*");
-      m_uiForm.valEHigh->setText("*");
-    }
-    }
-    else
-    {
-      if ( m_uiForm.leRebinString->text() == "" )
-      {
-        valid = false;
-      }
-    }
-  }
-  else
-  {
-    m_uiForm.valELow->setText("");
-    m_uiForm.valEWidth->setText("");
-    m_uiForm.valEHigh->setText("");
-  }
-
-
-  return valid;
-}
-/**
- * Validates user input on the calibration tab.
- */
-QString Indirect::validateCalib()
-{
-  UserInputValidator uiv;
-  
-  uiv.checkMWRunFilesIsValid("Run", m_uiForm.cal_leRunNo);
-
-  auto peakRange = std::make_pair(m_calDblMng->value(m_calCalProp["PeakMin"]), m_calDblMng->value(m_calCalProp["PeakMax"]));
-  auto backRange = std::make_pair(m_calDblMng->value(m_calCalProp["BackMin"]), m_calDblMng->value(m_calCalProp["BackMax"]));
-
-  uiv.checkValidRange("Peak Range", peakRange);
-  uiv.checkValidRange("Back Range", backRange);
-  uiv.checkRangesDontOverlap(peakRange, backRange);
-
-  if ( m_uiForm.cal_ckRES->isChecked() )
-  {
-    auto backgroundRange = std::make_pair(m_calDblMng->value(m_calResProp["Start"]), m_calDblMng->value(m_calResProp["End"]));
-    uiv.checkValidRange("Background", backgroundRange);
-
-    double eLow   = m_calDblMng->value(m_calResProp["ELow"]);
-    double eHigh  = m_calDblMng->value(m_calResProp["EHigh"]);
-    double eWidth = m_calDblMng->value(m_calResProp["EWidth"]);
-
-    uiv.checkBins(eLow, eWidth, eHigh);
-  }
-
-  if( m_uiForm.cal_ckIntensityScaleMultiplier->isChecked()
-    && m_uiForm.cal_leIntensityScaleMultiplier->text().isEmpty() )
-  {
-    uiv.addErrorMessage("You must enter a scale for the calibration file");
-  }
-
-  if( m_uiForm.cal_ckResScale->isChecked() && m_uiForm.cal_leResScale->text().isEmpty() )
-  {
-    uiv.addErrorMessage("You must enter a scale for the resolution file");
-  }
-
-  return uiv.generateErrorMessage();
-}
-
-void Indirect::validateSofQ(int)
-{
-  validateSofQw();
-}
-
-bool Indirect::validateSofQw()
-{
-  bool valid = true;
-
-
-  UserInputValidator uiv;
-  uiv.checkDataSelectorIsValid("Sample", m_uiForm.sqw_dsSampleInput);
-  QString error = uiv.generateErrorMessage();
-
-  if (!error.isEmpty())
-  {
-    valid = false;
-    showInformationBox(error);
-  }
-
-  if ( m_uiForm.sqw_ckRebinE->isChecked() )
-  {
-    if ( m_uiForm.sqw_leELow->text() == "" )
-    {
-      valid = false;
-      m_uiForm.sqw_valELow->setText("*");
-    }
-    else
-    {
-      m_uiForm.sqw_valELow->setText(" ");
-    }
-
-    if ( m_uiForm.sqw_leEWidth->text() == "" )
-    {
-      valid = false;
-      m_uiForm.sqw_valEWidth->setText("*");
-    }
-    else
-    {
-      m_uiForm.sqw_valEWidth->setText(" ");
-    }
-    if ( m_uiForm.sqw_leEHigh->text() == "" )
-    {
-      valid = false;
-      m_uiForm.sqw_valEHigh->setText("*");
-    }
-    else
-    {
-      m_uiForm.sqw_valEHigh->setText(" ");
-    }
-  }
-
-  if ( m_uiForm.sqw_leQLow->text() == "" )
-  {
-    valid = false;
-    m_uiForm.sqw_valQLow->setText("*");
-  }
-  else
-  {
-    m_uiForm.sqw_valQLow->setText(" ");
-  }
-
-  if ( m_uiForm.sqw_leQWidth->text() == "" )
-  {
-    valid = false;
-    m_uiForm.sqw_valQWidth->setText("*");
-  }
-  else
-  {
-    m_uiForm.sqw_valQWidth->setText(" ");
-  }
-  if ( m_uiForm.sqw_leQHigh->text() == "" )
-  {
-    valid = false;
-    m_uiForm.sqw_valQHigh->setText("*");
-  }
-  else
-  {
-    m_uiForm.sqw_valQHigh->setText(" ");
-  }
-  return valid;
-}
-
-QString Indirect::validateSlice()
-{
-  UserInputValidator uiv;
-
-  uiv.checkMWRunFilesIsValid("Input", m_uiForm.slice_inputFile);
-  if( m_uiForm.slice_ckUseCalib->isChecked() )
-    uiv.checkMWRunFilesIsValid("Calibration", m_uiForm.slice_inputFile);
-
-  auto rangeOne = std::make_pair(m_sltDblMng->value(m_sltProp["R1S"]), m_sltDblMng->value(m_sltProp["R1E"]));
-  uiv.checkValidRange("Range One", rangeOne);
-
-  bool useTwoRanges = m_sltBlnMng->value(m_sltProp["UseTwoRanges"]);
-  if( useTwoRanges )
-  {
-    auto rangeTwo = std::make_pair(m_sltDblMng->value(m_sltProp["R2S"]), m_sltDblMng->value(m_sltProp["R2E"]));
-    uiv.checkValidRange("Range Two", rangeTwo);
-
-    uiv.checkRangesDontOverlap(rangeOne, rangeTwo);
-  }
-
-  auto specRange = std::make_pair(m_sltDblMng->value(m_sltProp["SpecMin"]), m_sltDblMng->value(m_sltProp["SpecMax"]));
-  uiv.checkValidRange("Spectra Range", specRange);
-
-  return uiv.generateErrorMessage();
-}
-
-void Indirect::loadSettings()
-{  
-  // set values of m_dataDir and m_saveDir
-  m_dataDir = QString::fromStdString(Mantid::Kernel::ConfigService::Instance().getString("datasearch.directories"));
-  m_dataDir.replace(" ","");
-  if(m_dataDir.length() > 0)
-    m_dataDir = m_dataDir.split(";", QString::SkipEmptyParts)[0];
-  m_saveDir = QString::fromStdString(Mantid::Kernel::ConfigService::Instance().getString("defaultsave.directory"));
-  
-  QSettings settings;
-  // Load settings for MWRunFile widgets
-  settings.beginGroup(m_settingsGroup + "DataFiles");
-  settings.setValue("last_directory", m_dataDir);
-  m_uiForm.ind_runFiles->readSettings(settings.group());
-  m_uiForm.cal_leRunNo->readSettings(settings.group());
-  m_uiForm.slice_inputFile->readSettings(settings.group());
-  settings.endGroup();
-
-  settings.beginGroup(m_settingsGroup + "ProcessedFiles");
-  settings.setValue("last_directory", m_saveDir);
-  m_uiForm.ind_calibFile->readSettings(settings.group());
-  m_uiForm.ind_mapFile->readSettings(settings.group());
-  m_uiForm.slice_calibFile->readSettings(settings.group());
-  m_uiForm.moment_dsInput->readSettings(settings.group());
-  m_uiForm.transInputFile->readSettings(settings.group());
-  m_uiForm.transCanFile->readSettings(settings.group());
-  m_uiForm.sqw_dsSampleInput->readSettings(settings.group());
-  settings.endGroup();
-}
-
-void Indirect::saveSettings()
-{
-  // The only settings that we want to keep are the instrument / analyser / reflection ones
-  // Instrument is handled in ConvertToEnergy class
-}
-
-void Indirect::setupCalibration()
-{
-  // General
-  m_calDblMng = new QtDoublePropertyManager();
-  m_calGrpMng = new QtGroupPropertyManager();
-
-  /* Calib */
-  m_calCalTree = new QtTreePropertyBrowser();
-  m_uiForm.cal_treeCal->addWidget(m_calCalTree);
-
-  DoubleEditorFactory *doubleEditorFactory = new DoubleEditorFactory();
-  m_calCalTree->setFactoryForManager(m_calDblMng, doubleEditorFactory);
-
-  m_calCalProp["PeakMin"] = m_calDblMng->addProperty("Peak Min");
-  m_calCalProp["PeakMax"] = m_calDblMng->addProperty("Peak Max");
-  m_calCalProp["BackMin"] = m_calDblMng->addProperty("Back Min");
-  m_calCalProp["BackMax"] = m_calDblMng->addProperty("Back Max");
-
-
-  m_calCalTree->addProperty(m_calCalProp["PeakMin"]);
-  m_calCalTree->addProperty(m_calCalProp["PeakMax"]);
-  m_calCalTree->addProperty(m_calCalProp["BackMin"]);
-  m_calCalTree->addProperty(m_calCalProp["BackMax"]);
-
-  m_calCalPlot = new QwtPlot(this);
-  m_calCalPlot->setAxisFont(QwtPlot::xBottom, this->font());
-  m_calCalPlot->setAxisFont(QwtPlot::yLeft, this->font());
-  m_uiForm.cal_plotCal->addWidget(m_calCalPlot);
-  m_calCalPlot->setCanvasBackground(Qt::white);
-
-  // R1 = Peak, R2 = Background
-  m_calCalR1 = new MantidWidgets::RangeSelector(m_calCalPlot);
-  connect(m_calCalR1, SIGNAL(minValueChanged(double)), this, SLOT(calMinChanged(double)));
-  connect(m_calCalR1, SIGNAL(maxValueChanged(double)), this, SLOT(calMaxChanged(double)));
-  m_calCalR2 = new MantidWidgets::RangeSelector(m_calCalPlot);
-  m_calCalR2->setColour(Qt::darkGreen); // dark green to signify background range
-  connect(m_calCalR2, SIGNAL(minValueChanged(double)), this, SLOT(calMinChanged(double)));
-  connect(m_calCalR2, SIGNAL(maxValueChanged(double)), this, SLOT(calMaxChanged(double)));
-
-  // Res
-  m_calResTree = new QtTreePropertyBrowser();
-  m_uiForm.cal_treeRes->addWidget(m_calResTree);
-
-  m_calResTree->setFactoryForManager(m_calDblMng, doubleEditorFactory);
-
-  // Res - Spectra Selection
-  m_calResProp["SpecMin"] = m_calDblMng->addProperty("Spectra Min");
-  m_calResProp["SpecMax"] = m_calDblMng->addProperty("Spectra Max");
-  m_calResTree->addProperty(m_calResProp["SpecMin"]);
-  m_calDblMng->setDecimals(m_calResProp["SpecMin"], 0);
-  m_calResTree->addProperty(m_calResProp["SpecMax"]);
-  m_calDblMng->setDecimals(m_calResProp["SpecMax"], 0);
-
-  // Res - Background Properties
-  QtProperty* resBG = m_calGrpMng->addProperty("Background");
-  m_calResProp["Start"] = m_calDblMng->addProperty("Start");
-  m_calResProp["End"] = m_calDblMng->addProperty("End");
-  resBG->addSubProperty(m_calResProp["Start"]);
-  resBG->addSubProperty(m_calResProp["End"]);
-  m_calResTree->addProperty(resBG);
-  
-  // Res - rebinning
-  const int NUM_DECIMALS = 3;
-  QtProperty* resRB = m_calGrpMng->addProperty("Rebinning");
-  
-  m_calResProp["ELow"] = m_calDblMng->addProperty("Low");
-  m_calDblMng->setDecimals(m_calResProp["ELow"], NUM_DECIMALS);
-  m_calDblMng->setValue(m_calResProp["ELow"], -0.2);
-  
-  m_calResProp["EWidth"] = m_calDblMng->addProperty("Width");
-  m_calDblMng->setDecimals(m_calResProp["EWidth"], NUM_DECIMALS);
-  m_calDblMng->setValue(m_calResProp["EWidth"], 0.002);
-  m_calDblMng->setMinimum(m_calResProp["EWidth"], 0.001);
-
-  m_calResProp["EHigh"] = m_calDblMng->addProperty("High");
-  m_calDblMng->setDecimals(m_calResProp["EHigh"], NUM_DECIMALS);
-  m_calDblMng->setValue(m_calResProp["EHigh"], 0.2);
-  
-  resRB->addSubProperty(m_calResProp["ELow"]);
-  resRB->addSubProperty(m_calResProp["EWidth"]);
-  resRB->addSubProperty(m_calResProp["EHigh"]);
-  
-  m_calResTree->addProperty(resRB);
-
-  m_calResPlot = new QwtPlot(this);
-  m_calResPlot->setAxisFont(QwtPlot::xBottom, this->font());
-  m_calResPlot->setAxisFont(QwtPlot::yLeft, this->font());
-  m_uiForm.cal_plotRes->addWidget(m_calResPlot);
-  m_calResPlot->setCanvasBackground(Qt::white);
-
-  // Create ResR2 first so ResR1 is drawn above it.
-  m_calResR2 = new MantidWidgets::RangeSelector(m_calResPlot, 
-    MantidQt::MantidWidgets::RangeSelector::XMINMAX, true, false);
-  m_calResR2->setColour(Qt::darkGreen);
-  m_calResR1 = new MantidWidgets::RangeSelector(m_calResPlot, MantidQt::MantidWidgets::RangeSelector::XMINMAX, true, true);
-
-  connect(m_calResR1, SIGNAL(minValueChanged(double)), this, SLOT(calMinChanged(double)));
-  connect(m_calResR1, SIGNAL(maxValueChanged(double)), this, SLOT(calMaxChanged(double)));
-  connect(m_calResR2, SIGNAL(minValueChanged(double)), this, SLOT(calMinChanged(double)));
-  connect(m_calResR2, SIGNAL(maxValueChanged(double)), this, SLOT(calMaxChanged(double)));
-  connect(m_calResR1, SIGNAL(rangeChanged(double, double)), m_calResR2, SLOT(setRange(double, double)));
-  connect(m_calDblMng, SIGNAL(valueChanged(QtProperty*, double)), this, SLOT(calUpdateRS(QtProperty*, double)));
-  connect(m_calDblMng, SIGNAL(valueChanged(QtProperty*, double)), this, SLOT(calUpdateRS(QtProperty*, double)));
-  connect(m_calDblMng, SIGNAL(valueChanged(QtProperty*, double)), this, SLOT(calUpdateRS(QtProperty*, double)));
-}
-
-void Indirect::setupSlice()
-{
-  // Property Tree
-  m_sltTree = new QtTreePropertyBrowser();
-  m_uiForm.slice_properties->addWidget(m_sltTree);
-
-  // Create Manager Objects
-  m_sltDblMng = new QtDoublePropertyManager();
-  m_sltBlnMng = new QtBoolPropertyManager();
-  m_sltGrpMng = new QtGroupPropertyManager();
-
-  // Editor Factories
-  DoubleEditorFactory *doubleEditorFactory = new DoubleEditorFactory();
-  QtCheckBoxFactory *checkboxFactory = new QtCheckBoxFactory();
-  m_sltTree->setFactoryForManager(m_sltDblMng, doubleEditorFactory);
-  m_sltTree->setFactoryForManager(m_sltBlnMng, checkboxFactory);
-
-  // Create Properties
-  m_sltProp["SpecMin"] = m_sltDblMng->addProperty("Spectra Min");
-  m_sltProp["SpecMax"] = m_sltDblMng->addProperty("Spectra Max");
-  m_sltDblMng->setDecimals(m_sltProp["SpecMin"], 0);
-  m_sltDblMng->setMinimum(m_sltProp["SpecMin"], 1);
-  m_sltDblMng->setDecimals(m_sltProp["SpecMax"], 0);
-
-  m_sltProp["R1S"] = m_sltDblMng->addProperty("Start");
-  m_sltProp["R1E"] = m_sltDblMng->addProperty("End");
-  m_sltProp["R2S"] = m_sltDblMng->addProperty("Start");
-  m_sltProp["R2E"] = m_sltDblMng->addProperty("End");
-
-  m_sltProp["UseTwoRanges"] = m_sltBlnMng->addProperty("Use Two Ranges");
-
-  m_sltProp["Range1"] = m_sltGrpMng->addProperty("Range One");
-  m_sltProp["Range1"]->addSubProperty(m_sltProp["R1S"]);
-  m_sltProp["Range1"]->addSubProperty(m_sltProp["R1E"]);
-  m_sltProp["Range2"] = m_sltGrpMng->addProperty("Range Two");
-  m_sltProp["Range2"]->addSubProperty(m_sltProp["R2S"]);
-  m_sltProp["Range2"]->addSubProperty(m_sltProp["R2E"]);
-
-  m_sltTree->addProperty(m_sltProp["SpecMin"]);
-  m_sltTree->addProperty(m_sltProp["SpecMax"]);
-  m_sltTree->addProperty(m_sltProp["Range1"]);
-  m_sltTree->addProperty(m_sltProp["UseTwoRanges"]);
-  m_sltTree->addProperty(m_sltProp["Range2"]);
-
-  // Create Slice Plot Widget for Range Selection
-  m_sltPlot = new QwtPlot(this);
-  m_sltPlot->setAxisFont(QwtPlot::xBottom, this->font());
-  m_sltPlot->setAxisFont(QwtPlot::yLeft, this->font());
-  m_uiForm.slice_plot->addWidget(m_sltPlot);
-  m_sltPlot->setCanvasBackground(Qt::white);
-  // We always want one range selector... the second one can be controlled from
-  // within the sliceTwoRanges(bool state) function
-  m_sltR1 = new MantidWidgets::RangeSelector(m_sltPlot);
-  connect(m_sltR1, SIGNAL(minValueChanged(double)), this, SLOT(sliceMinChanged(double)));
-  connect(m_sltR1, SIGNAL(maxValueChanged(double)), this, SLOT(sliceMaxChanged(double)));
-
-  // second range
-  // create the second range
-  m_sltR2 = new MantidWidgets::RangeSelector(m_sltPlot);
-  m_sltR2->setColour(Qt::darkGreen); // dark green for background
-  connect(m_sltR1, SIGNAL(rangeChanged(double, double)), m_sltR2, SLOT(setRange(double, double)));
-  connect(m_sltR2, SIGNAL(minValueChanged(double)), this, SLOT(sliceMinChanged(double)));
-  connect(m_sltR2, SIGNAL(maxValueChanged(double)), this, SLOT(sliceMaxChanged(double)));
-  m_sltR2->setRange(m_sltR1->getRange());
-
-  // Refresh the plot window
-  m_sltPlot->replot();
-
-  connect(m_sltDblMng, SIGNAL(valueChanged(QtProperty*, double)), this, SLOT(sliceUpdateRS(QtProperty*, double)));
-  connect(m_sltBlnMng, SIGNAL(valueChanged(QtProperty*, bool)), this, SLOT(sliceTwoRanges(QtProperty*, bool)));
-
-  sliceTwoRanges(0, false); // set default value
-}
-
-/**
- * Called when a user starts to type / edit the runs to load.
- */
-void Indirect::pbRunEditing()
-{
-  m_uiForm.pbRun->setEnabled(false);
-  m_uiForm.pbRun->setText("Editing...");
-}
-
-/**
- * Called when the FileFinder starts finding the files.
- */
-void Indirect::pbRunFinding()
-{
-  m_uiForm.pbRun->setText("Finding files...");
-  m_uiForm.ind_runFiles->setEnabled(false);
-}
-
-/**
- * Called when the FileFinder has finished finding the files.
- */
-void Indirect::pbRunFinished()
-{
-  m_uiForm.pbRun->setEnabled(true);
-  m_uiForm.ind_runFiles->setEnabled(true);
-  tabChanged(m_uiForm.tabWidget->currentIndex());
-}
-
-/**
-* This function is called when the user selects an analyser from the cbAnalyser QComboBox
-* object. It's main purpose is to initialise the values for the Reflection ComboBox.
-* @param index :: Index of the value selected in the combo box.
-*/
-void Indirect::analyserSelected(int index)
-{
-  // populate Reflection combobox with correct values for Analyser selected.
-  m_uiForm.cbReflection->clear();
-  clearReflectionInfo();
-
-
-  QVariant currentData = m_uiForm.cbAnalyser->itemData(index);
-  if ( currentData == QVariant::Invalid )
-  {
-    m_uiForm.lbReflection->setEnabled(false);
-    m_uiForm.cbReflection->setEnabled(false);
-    return;
-  }
-  else
-  {
-    m_uiForm.lbReflection->setEnabled(true);
-    m_uiForm.cbReflection->setEnabled(true);
-    QStringList reflections = currentData.toStringList();
-    for ( int i = 0; i < reflections.count(); i++ )
-    {
-      m_uiForm.cbReflection->addItem(reflections[i]);
-    }
-  }
-
-  reflectionSelected(m_uiForm.cbReflection->currentIndex());
-}
-/**
-* This function is called when the user selects a reflection from the cbReflection QComboBox
-* object.
-* @param index :: Index of the value selected in the combo box.
-*/
-void Indirect::reflectionSelected(int index)
-{
-  UNUSED_ARG(index);
-  // first, clear values in assosciated boxes:
-  clearReflectionInfo();
-
-  QString pyInput =
-    "from IndirectEnergyConversion import getReflectionDetails\n"
-    "instrument = '" + m_uiForm.cbInst->currentText() + "'\n"
-    "analyser = '" + m_uiForm.cbAnalyser->currentText() + "'\n"
-    "reflection = '" + m_uiForm.cbReflection->currentText() + "'\n"
-    "print getReflectionDetails(instrument, analyser, reflection)\n";
-
-  QString pyOutput = runPythonCode(pyInput).trimmed();
-
-  QStringList values = pyOutput.split("\n", QString::SkipEmptyParts);
-
-  if ( values.count() < 3 )
-  {
-    showInformationBox("Could not gather necessary data from parameter file.");
-    return;
-  }
-  else
-  {
-    QString analysisType = values[0];
-    m_uiForm.leSpectraMin->setText(values[1]);
-    m_uiForm.leSpectraMax->setText(values[2]);
-    m_calDblMng->setValue(m_calResProp["SpecMin"], values[1].toDouble());
-    m_calDblMng->setValue(m_calResProp["SpecMax"], values[2].toDouble());
-    m_sltDblMng->setValue(m_sltProp["SpecMin"], values[1].toDouble());
-    m_sltDblMng->setValue(m_sltProp["SpecMax"], values[2].toDouble());
-    
-    if ( values.count() >= 8 )
-    {
-      m_uiForm.leEfixed->setText(values[3]);
-      
-      m_calDblMng->setValue(m_calCalProp["PeakMin"], values[4].toDouble());
-      m_calDblMng->setValue(m_calCalProp["PeakMax"], values[5].toDouble());
-      m_calDblMng->setValue(m_calCalProp["BackMin"], values[6].toDouble());
-      m_calDblMng->setValue(m_calCalProp["BackMax"], values[7].toDouble());
-
-      m_sltDblMng->setValue(m_sltProp["R1S"], values[4].toDouble());
-      m_sltDblMng->setValue(m_sltProp["R1E"], values[5].toDouble());
-      m_sltDblMng->setValue(m_sltProp["R2S"], values[6].toDouble());
-      m_sltDblMng->setValue(m_sltProp["R2E"], values[7].toDouble());
-    }
-    else
-    {
-      m_uiForm.leEfixed->clear();
-    }
-    // Default rebinning parameters can be set in instrument parameter file
-    if ( values.count() == 9 )
-    {
-      m_uiForm.leRebinString->setText(values[8]);
-      m_uiForm.rebin_ckDNR->setChecked(false);
-      QStringList rbp = values[8].split(",", QString::SkipEmptyParts);
-      if ( rbp.size() == 3 )
-      {
-        m_uiForm.rebin_leELow->setText(rbp[0]);
-        m_uiForm.rebin_leEWidth->setText(rbp[1]);
-        m_uiForm.rebin_leEHigh->setText(rbp[2]);
-        m_uiForm.cbIndRebType->setCurrentIndex(0);
-      }
-      else
-      {
-        m_uiForm.cbIndRebType->setCurrentIndex(1);
-      }
-    }
-    else
-    {
-      m_uiForm.rebin_ckDNR->setChecked(true);
-      m_uiForm.rebin_leELow->setText("");
-      m_uiForm.rebin_leEWidth->setText("");
-      m_uiForm.rebin_leEHigh->setText("");
-      m_uiForm.leRebinString->setText("");
-    }
-  }
-
-  // clear validation markers
-  validateInput();
-  validateCalib();
-  validateSlice();
-}
-/**
-* This function runs when the user makes a selection on the cbMappingOptions QComboBox.
-* @param groupType :: Value of selection made by user.
-*/
-void Indirect::mappingOptionSelected(const QString& groupType)
-{
-  if ( groupType == "File" )
-  {
-    m_uiForm.swMapping->setCurrentIndex(0);
-  }
-  else if ( groupType == "Groups" )
-  {
-    m_uiForm.swMapping->setCurrentIndex(1);
-  }
-  else if ( groupType == "All" || groupType == "Individual" || groupType == "Default" )
-  {
-    m_uiForm.swMapping->setCurrentIndex(2);
-  }
-}
-
-void Indirect::tabChanged(int index)
-{
-  QString tabName = m_uiForm.tabWidget->tabText(index);
-  m_uiForm.pbRun->setText("Run " + tabName);
-}
-/**
-* This function is called when the user clicks on the Background Removal button. It
-* displays the Background Removal dialog, initialising it if it hasn't been already.
-*/
-void Indirect::backgroundClicked()
-{
-  if ( m_backgroundDialog == NULL )
-  {
-    m_backgroundDialog = new Background(this);
-    connect(m_backgroundDialog, SIGNAL(accepted()), this, SLOT(backgroundRemoval()));
-    connect(m_backgroundDialog, SIGNAL(rejected()), this, SLOT(backgroundRemoval()));
-    m_backgroundDialog->show();
-  }
-  else
-  {
-    m_backgroundDialog->show();
-  }
-}
-/**
-* Slot called when m_backgroundDialog is closed. Assesses whether user desires background removal.
-* Can be called before m_backgroundDialog even exists, for the purposes of setting the button to
-* it's initial (default) value.
-*/
-void Indirect::backgroundRemoval()
-{
-  if ( NULL != m_backgroundDialog )
-    m_bgRemoval = m_backgroundDialog->removeBackground();
-  
-  if (m_bgRemoval)
-    m_uiForm.pbBack_2->setText("Background Removal (On)");
-  else
-    m_uiForm.pbBack_2->setText("Background Removal (Off)");
-}
-/**
-* Plots raw time data from .raw file before any data conversion has been performed.
-*/
-void Indirect::plotRaw()
-{
-  if ( m_uiForm.ind_runFiles->isValid() )
-  {
-    bool ok;
-    QString spectraRange = QInputDialog::getText(this, "Insert Spectra Ranges", "Range: ", QLineEdit::Normal, m_uiForm.leSpectraMin->text() +"-"+ m_uiForm.leSpectraMax->text(), &ok);
-
-    if ( !ok || spectraRange.isEmpty() )
-    {
-      return;
-    }
-    QStringList specList = spectraRange.split("-");
-
-    QString rawFile = m_uiForm.ind_runFiles->getFirstFilename();
-    if ( (specList.size() > 2) || ( specList.size() < 1) )
-    {
-      showInformationBox("Invalid input. Must be of form <SpecMin>-<SpecMax>");
-      return;
-    }
-    if ( specList.size() == 1 )
-    {
-      specList.append(specList[0]);
-    }
-
-    QString bgrange;
-
-    if ( m_bgRemoval )
-    {
-      QPair<double, double> range = m_backgroundDialog->getRange();
-      bgrange = "[ " + QString::number(range.first) + "," + QString::number(range.second) + " ]";
-    }
-    else
-    {
-      bgrange = "[-1, -1]";
-    }
-
-    QString pyInput =
-      "from mantid.simpleapi import CalculateFlatBackground,GroupDetectors,Load\n"
-      "from mantidplot import plotSpectrum\n"
-      "import os.path as op\n"
-      "file = r'" + rawFile + "'\n"
-      "name = op.splitext( op.split(file)[1] )[0]\n"
-      "bgrange = " + bgrange + "\n"
-      "Load(Filename=file, OutputWorkspace=name, SpectrumMin="+specList[0]+", SpectrumMax="+specList[1]+")\n"
-      "if ( bgrange != [-1, -1] ):\n"
-      "    #Remove background\n"
-      "    CalculateFlatBackground(InputWorkspace=name, OutputWorkspace=name+'_bg', StartX=bgrange[0], EndX=bgrange[1], Mode='Mean')\n"
-      "    GroupDetectors(InputWorkspace=name+'_bg', OutputWorkspace=name+'_grp', DetectorList=range("+specList[0]+","+specList[1]+"+1))\n"
-      "    GroupDetectors(InputWorkspace=name, OutputWorkspace=name+'_grp_raw', DetectorList=range("+specList[0]+","+specList[1]+"+1))\n"
-      "else: # Just group detectors as they are\n"
-      "    GroupDetectors(InputWorkspace=name, OutputWorkspace=name+'_grp', DetectorList=range("+specList[0]+","+specList[1]+"+1))\n"
-      "graph = plotSpectrum(name+'_grp', 0)\n";
-
-    QString pyOutput = runPythonCode(pyInput).trimmed();
-    
-    if ( pyOutput != "" )
-    {
-      showInformationBox(pyOutput);
-    }
-  }
-  else
-  {
-    showInformationBox("You must select a run file.");
-  }
-}
-/**
-* This function will disable the necessary elements of the interface when the user selects "Do Not Rebin"
-* and enable them again when this is de-selected.
-* @param state :: whether the "Do Not Rebin" checkbox is checked
-*/
-void Indirect::rebinCheck(bool state) 
-{
-  QString val;
-  if ( state ) val = " ";
-  else val = "*";
-  m_uiForm.rebin_lbLow->setEnabled( !state );
-  m_uiForm.rebin_lbWidth->setEnabled( !state );
-  m_uiForm.rebin_lbHigh->setEnabled( !state );
-  m_uiForm.rebin_leELow->setEnabled( !state );
-  m_uiForm.rebin_leEWidth->setEnabled( !state );
-  m_uiForm.rebin_leEHigh->setEnabled( !state );
-  m_uiForm.valELow->setEnabled(!state);
-  m_uiForm.valELow->setText(val);
-  m_uiForm.valEWidth->setEnabled(!state);
-  m_uiForm.valEWidth->setText(val);
-  m_uiForm.valEHigh->setEnabled(!state);
-  m_uiForm.valEHigh->setText(val);
-}
-/**
-* Disables/enables the relevant parts of the UI when user checks/unchecks the Detailed Balance
-* ckDetailedBalance checkbox.
-* @param state :: state of the checkbox
-*/
-void Indirect::detailedBalanceCheck(bool state)
-{
-  m_uiForm.leDetailedBalance->setEnabled(state);
-  m_uiForm.lbDBKelvin->setEnabled(state);
-}
-/**
-* This function enables/disables the display of the options involved in creating the RES file.
-* @param state :: whether checkbox is checked or unchecked
-*/
-void Indirect::resCheck(bool state)
-{
-  m_calResR1->setVisible(state);
-  m_calResR2->setVisible(state);
-}
-
-
-
-/**
-* Disables/enables the relevant parts of the UI when user checks/unchecks the 'Multiplication Factor (Scale):'
-* ckScaleMultiplier checkbox.
-* @param state :: state of the checkbox
-*/
-void Indirect::scaleMultiplierCheck(bool state)
-{
-  m_uiForm.leScaleMultiplier->setEnabled(state);
-}
-
-void Indirect::intensityScaleMultiplierCheck(bool state)
-{
-  m_uiForm.cal_leIntensityScaleMultiplier->setEnabled(state);
-}
-
-void Indirect::calibValidateIntensity(const QString & text)
-{
-  if(!text.isEmpty())
-  {
-    m_uiForm.cal_valIntensityScaleMultiplier->setText(" ");
-  }
-  else
-  {
-    m_uiForm.cal_valIntensityScaleMultiplier->setText("*");
-  }
-}
-
-void Indirect::useCalib(bool state)
-{
-  m_uiForm.ind_calibFile->isOptional(!state);
-  m_uiForm.ind_calibFile->setEnabled(state);
-}
-/**
-* This function is called when the user clicks on the "Create Calibration File" button.
-* Pretty much does what it says on the tin.
-*/
-void Indirect::calibCreate()
-{
-  QString file = m_uiForm.cal_leRunNo->getFirstFilename();
-  QString error = validateCalib();
-  if ( ! error.isEmpty() )
-  {
-    showInformationBox(error);
-  }
-  else
-  {
-    QString filenames = "[r'"+m_uiForm.cal_leRunNo->getFilenames().join("', r'")+"']";
-
-    QString reducer = "from mantid.simpleapi import SaveNexus\n"
-      "from inelastic_indirect_reduction_steps import CreateCalibrationWorkspace\n"
-      "calib = CreateCalibrationWorkspace()\n"
-      "calib.set_files(" + filenames + ")\n"
-      "calib.set_detector_range(" + m_uiForm.leSpectraMin->text() + "-1, " + m_uiForm.leSpectraMax->text() + "-1)\n"
-      "calib.set_parameters(" + m_calCalProp["BackMin"]->valueText() + "," 
-        + m_calCalProp["BackMax"]->valueText() + ","
-        + m_calCalProp["PeakMin"]->valueText() + ","
-        + m_calCalProp["PeakMax"]->valueText() + ")\n"
-      "calib.set_analyser('" + m_uiForm.cbAnalyser->currentText() + "')\n"
-      "calib.set_reflection('" + m_uiForm.cbReflection->currentText() + "')\n";
-
-    //scale values by arbitrary scalar if requested
-    if(m_uiForm.cal_ckIntensityScaleMultiplier->isChecked())
-    {
-      QString scale = m_uiForm.cal_leIntensityScaleMultiplier->text(); 
-      if(scale.isEmpty())
-      {
-        scale = "1.0";
-      }
-      reducer += "calib.set_intensity_scale("+scale+")\n";
-    }
-
-    reducer += "calib.execute(None, None)\n"
-      "result = calib.result_workspace()\n"
-      "print result\n";
-
-    if( m_uiForm.cal_ckSave->isChecked() )
-    {
-      reducer +=
-        "SaveNexus(InputWorkspace=result, Filename=result+'.nxs')\n";
-    }
-
-    if ( m_uiForm.cal_ckPlotResult->isChecked() )
-    {
-      reducer += "from mantidplot import plotTimeBin\n"
-        "plotTimeBin(result, 0)\n";
-    }
-
-    QString pyOutput = runPythonCode(reducer).trimmed();
-
-    if ( pyOutput == "" )
-    {
-      showInformationBox("An error occurred creating the calib file.\n");
-    }
-    else
-    {
-      if ( m_uiForm.cal_ckRES->isChecked() )
-      {
-        createRESfile(filenames);
-      }
-      m_uiForm.ind_calibFile->setFileTextWithSearch(pyOutput + ".nxs");
-      m_uiForm.ckUseCalib->setChecked(true);
-    }
-  }
-}
-/**
-* Controls the ckUseCalib checkbox to automatically check it when a user inputs a file from clicking on 'browse'.
-* @param calib :: path to calib file
-*/
-void Indirect::calibFileChanged(const QString & calib)
-{
-  if ( calib.isEmpty() )
-  {
-    m_uiForm.ckUseCalib->setChecked(false);
-  }
-  else
-  {
-    m_uiForm.ckUseCalib->setChecked(true);
-  }
-}
-// CALIBRATION TAB
-void Indirect::calPlotRaw()
-{
-  QString filename = m_uiForm.cal_leRunNo->getFirstFilename();
-  
-  if ( filename.isEmpty() )
-  {
-    return;
-  }
-    
-  QFileInfo fi(filename);
-  QString wsname = fi.baseName();
-  QString pyInput = "Load(Filename=r'" + filename + "', OutputWorkspace='" + wsname + "', SpectrumMin="
-    + m_uiForm.leSpectraMin->text() + ", SpectrumMax="
-    + m_uiForm.leSpectraMax->text() + ")\n";
-
-  pyInput = "try:\n  " +
-               pyInput +
-            "except ValueError as ve:" +
-            "  print str(ve)";
-
-  QString pyOutput = runPythonCode(pyInput);
-  
-  if( ! pyOutput.isEmpty() )
-  {
-    showInformationBox("Unable to load file.  Error: \n\n" + pyOutput + "\nCheck whether your file exists and matches the selected instrument in the Energy Transfer tab.");
-    return;
-  }
-
-  Mantid::API::MatrixWorkspace_sptr input = boost::dynamic_pointer_cast<Mantid::API::MatrixWorkspace>(Mantid::API::AnalysisDataService::Instance().retrieve(wsname.toStdString()));
-
-  const MantidVec & dataX = input->readX(0);
-  const MantidVec & dataY = input->readY(0);
-
-  if ( m_calCalCurve != NULL )
-  {
-    m_calCalCurve->attach(0);
-    delete m_calCalCurve;
-    m_calCalCurve = 0;
-  }
-
-  m_calCalCurve = new QwtPlotCurve();
-  m_calCalCurve->setData(&dataX[0], &dataY[0], static_cast<int>(input->blocksize()));
-  m_calCalCurve->attach(m_calCalPlot);
-
-  std::pair<double, double> range(dataX.front(), dataX.back());
-  m_calCalPlot->setAxisScale(QwtPlot::xBottom, range.first, range.second);
-  setPlotRange(m_calCalR1, m_calDblMng, std::pair<QtProperty*,QtProperty*>(m_calCalProp["PeakMin"], m_calCalProp["PeakMax"]), range);
-  setPlotRange(m_calCalR2, m_calDblMng, std::pair<QtProperty*,QtProperty*>(m_calCalProp["BackMin"], m_calCalProp["BackMax"]), range);
-
-  // Replot
-  m_calCalPlot->replot();
-
-  // also replot the energy
-  calPlotEnergy();
-}
-
-void Indirect::calPlotEnergy()
-{
-  if ( ! m_uiForm.cal_leRunNo->isValid() )
-  {
-    showInformationBox("Run number not valid.");
-    return;
-  }
-
-  QString files = "[r'" + m_uiForm.cal_leRunNo->getFilenames().join("', r'") + "']";
-  QString pyInput =
-    "from IndirectEnergyConversion import resolution\n"
-    "iconOpt = { 'first': " +QString::number(m_calDblMng->value(m_calResProp["SpecMin"]))+
-    ", 'last': " +QString::number(m_calDblMng->value(m_calResProp["SpecMax"]))+ "}\n"
-    "instrument = '" + m_uiForm.cbInst->currentText() + "'\n"
-    "analyser = '" + m_uiForm.cbAnalyser->currentText() + "'\n"
-    "reflection = '" + m_uiForm.cbReflection->currentText() + "'\n"
-    "files = " + files + "\n"
-    "outWS = resolution(files, iconOpt, '', '', instrument, analyser, reflection, Res=False)\n"
-    "print outWS\n";
-  QString pyOutput = runPythonCode(pyInput).trimmed();
-
-  //something went wrong in the python
-  if(pyOutput == "None")
-  {
-    showInformationBox("Failed to convert to energy. See log for details.");
-    return;
-  }
-  
-  Mantid::API::MatrixWorkspace_sptr input = boost::dynamic_pointer_cast<Mantid::API::MatrixWorkspace>(Mantid::API::AnalysisDataService::Instance().retrieve(pyOutput.toStdString()));
-
-  const MantidVec & dataX = input->readX(0);
-  const MantidVec & dataY = input->readY(0);
-
-  if ( m_calResCurve != NULL )
-  {
-    m_calResCurve->attach(0);
-    delete m_calResCurve;
-    m_calResCurve = 0;
-  }
-
-  m_calResCurve = new QwtPlotCurve();
-  m_calResCurve->setData(&dataX[0], &dataY[0], static_cast<int>(input->blocksize()));
-  m_calResCurve->attach(m_calResPlot);
-  
-  std::pair<double, double> range(dataX.front(), dataX.back());
-  m_calResPlot->setAxisScale(QwtPlot::xBottom, range.first, range.second);
-
-  setPlotRange(m_calResR1, m_calDblMng, std::pair<QtProperty*,QtProperty*>(m_calResProp["ELow"], m_calResProp["EHigh"]), range);
-  setPlotRange(m_calResR2, m_calDblMng, std::pair<QtProperty*,QtProperty*>(m_calResProp["Start"], m_calResProp["End"]), range);
-
-  calSetDefaultResolution(input);
-
-  // Replot
-  m_calResPlot->replot();
-}
-
-void Indirect::calSetDefaultResolution(Mantid::API::MatrixWorkspace_const_sptr ws)
-{
-  auto inst = ws->getInstrument();
-  auto analyser = inst->getStringParameter("analyser");
-
-  if(analyser.size() > 0)
-  {
-    auto comp = inst->getComponentByName(analyser[0]);
-    auto params = comp->getNumberParameter("resolution", true);
-
-    //set the default instrument resolution
-    if(params.size() > 0)
-    {
-      double res = params[0];
-      m_calDblMng->setValue(m_calResProp["ELow"], -res*10);
-      m_calDblMng->setValue(m_calResProp["EHigh"], res*10);
-
-      m_calDblMng->setValue(m_calResProp["Start"], -res*9);
-      m_calDblMng->setValue(m_calResProp["End"], -res*8);
-    }
-
-  }
-}
-
-
-void Indirect::calMinChanged(double val)
-{
-  MantidWidgets::RangeSelector* from = qobject_cast<MantidWidgets::RangeSelector*>(sender());
-  if ( from == m_calCalR1 )
-  {
-    m_calDblMng->setValue(m_calCalProp["PeakMin"], val);
-  }
-  else if ( from == m_calCalR2 )
-  {
-    m_calDblMng->setValue(m_calCalProp["BackMin"], val);
-  }
-  else if ( from == m_calResR1 )
-  {
-    m_calDblMng->setValue(m_calResProp["ELow"], val);
-  }
-  else if ( from == m_calResR2 )
-  {
-    m_calDblMng->setValue(m_calResProp["Start"], val);
-  }
-}
-
-void Indirect::calMaxChanged(double val)
-{
-  MantidWidgets::RangeSelector* from = qobject_cast<MantidWidgets::RangeSelector*>(sender());
-  if ( from == m_calCalR1 )
-  {
-    m_calDblMng->setValue(m_calCalProp["PeakMax"], val);
-  }
-  else if ( from == m_calCalR2 )
-  {
-    m_calDblMng->setValue(m_calCalProp["BackMax"], val);
-  }
-  else if ( from == m_calResR1 )
-  {
-    m_calDblMng->setValue(m_calResProp["EHigh"], val);
-  }
-  else if ( from == m_calResR2 )
-  {
-    m_calDblMng->setValue(m_calResProp["End"], val);
-  }
-}
-
-void Indirect::calUpdateRS(QtProperty* prop, double val)
-{
-  if ( prop == m_calCalProp["PeakMin"] ) m_calCalR1->setMinimum(val);
-  else if ( prop == m_calCalProp["PeakMax"] ) m_calCalR1->setMaximum(val);
-  else if ( prop == m_calCalProp["BackMin"] ) m_calCalR2->setMinimum(val);
-  else if ( prop == m_calCalProp["BackMax"] ) m_calCalR2->setMaximum(val);
-  else if ( prop == m_calResProp["Start"] ) m_calResR2->setMinimum(val);
-  else if ( prop == m_calResProp["End"] ) m_calResR2->setMaximum(val);
-  else if ( prop == m_calResProp["ELow"] ) m_calResR1->setMinimum(val);
-  else if ( prop == m_calResProp["EHigh"] ) m_calResR1->setMaximum(val);
-}
-
-void Indirect::sOfQwClicked()
-{
-  if ( validateSofQw() )
-  {
-    QString rebinString = m_uiForm.sqw_leQLow->text()+","+m_uiForm.sqw_leQWidth->text()+","+m_uiForm.sqw_leQHigh->text();
-    QString pyInput = "from mantid.simpleapi import *\n";
-
-    if(m_uiForm.sqw_dsSampleInput->isFileSelectorVisible())
-    {
-      //load the file
-      pyInput += "filename = r'" + m_uiForm.sqw_dsSampleInput->getFullFilePath() + "'\n"
-      "(dir, file) = os.path.split(filename)\n"
-      "(sqwInput, ext) = os.path.splitext(file)\n"
-      "LoadNexus(Filename=filename, OutputWorkspace=sqwInput)\n";
-    }
-    else
-    {
-      //get the workspace
-      pyInput += "sqwInput = '" + m_uiForm.sqw_dsSampleInput->getCurrentDataName() + "'\n";
-    }
-
-    // Create output name before rebinning
-    pyInput += "sqwOutput = sqwInput[:-3] + 'sqw'\n";
-
-    if ( m_uiForm.sqw_ckRebinE->isChecked() )
-    {
-      QString eRebinString = m_uiForm.sqw_leELow->text()+","+m_uiForm.sqw_leEWidth->text()+","+m_uiForm.sqw_leEHigh->text();
-      pyInput += "Rebin(InputWorkspace=sqwInput, OutputWorkspace=sqwInput+'_r', Params='" + eRebinString + "')\n"
-        "sqwInput += '_r'\n";
-    }
-    pyInput +=
-      "efixed = " + m_uiForm.leEfixed->text() + "\n"
-      "rebin = '" + rebinString + "'\n";
-
-    QString rebinType = m_uiForm.sqw_cbRebinType->currentText();
-    if(rebinType == "Centre (SofQW)")
-      pyInput += "SofQW(InputWorkspace=sqwInput, OutputWorkspace=sqwOutput, QAxisBinning=rebin, EMode='Indirect', EFixed=efixed)\n";
-    else if(rebinType == "Parallelepiped (SofQW2)")
-      pyInput += "SofQW2(InputWorkspace=sqwInput, OutputWorkspace=sqwOutput, QAxisBinning=rebin, EMode='Indirect', EFixed=efixed)\n";
-    else if(rebinType == "Parallelepiped/Fractional Area (SofQW3)")
-      pyInput += "SofQW3(InputWorkspace=sqwInput, OutputWorkspace=sqwOutput, QAxisBinning=rebin, EMode='Indirect', EFixed=efixed)\n";
-
-    pyInput += "AddSampleLog(Workspace=sqwOutput, LogName='rebin_type', LogType='String', LogText='"+rebinType+"')\n";
-
-    if ( m_uiForm.sqw_ckSave->isChecked() )
-    {
-      pyInput += "SaveNexus(InputWorkspace=sqwOutput, Filename=sqwOutput+'.nxs')\n";
-
-      if (m_uiForm.sqw_ckVerbose->isChecked())
-      {
-        pyInput += "logger.notice(\"Resolution file saved to default save directory.\")\n";
-      }
-    }
-
-    if ( m_uiForm.sqw_cbPlotType->currentText() == "Contour" )
-    {
-      pyInput += "importMatrixWorkspace(sqwOutput).plotGraph2D()\n";
-    }
-    else if ( m_uiForm.sqw_cbPlotType->currentText() == "Spectra" )
-    {
-      pyInput +=
-        "nspec = mtd[sqwOutput].getNumberHistograms()\n"
-        "plotSpectrum(sqwOutput, range(0, nspec))\n";
-    }
-        
-    QString pyOutput = runPythonCode(pyInput).trimmed();
-  }
-  else
-  {
-    showInformationBox("Some of your input is invalid. Please check the input highlighted.");
-  }
-}
-
-void Indirect::sOfQwRebinE(bool state)
-{
-  QString val;
-  if ( state ) val = "*";
-  else val = " ";
-  m_uiForm.sqw_leELow->setEnabled(state);
-  m_uiForm.sqw_leEWidth->setEnabled(state);
-  m_uiForm.sqw_leEHigh->setEnabled(state);
-  m_uiForm.sqw_valELow->setEnabled(state);
-  m_uiForm.sqw_valELow->setText(val);
-  m_uiForm.sqw_valEWidth->setEnabled(state);
-  m_uiForm.sqw_valEWidth->setText(val);
-  m_uiForm.sqw_valEHigh->setEnabled(state);
-  m_uiForm.sqw_valEHigh->setText(val);
-  m_uiForm.sqw_lbELow->setEnabled(state);
-  m_uiForm.sqw_lbEWidth->setEnabled(state);
-  m_uiForm.sqw_lbEHigh->setEnabled(state);
-}
-
-void Indirect::sOfQwPlotInput()
-{
-  QString pyInput = "from mantid.simpleapi import *\n"
-    "from mantidplot import *\n";
-
-  if (m_uiForm.sqw_dsSampleInput->isValid())
-  {
-    if(m_uiForm.sqw_dsSampleInput->isFileSelectorVisible())
-    {
-      //load the file
-      pyInput += "filename = r'" + m_uiForm.sqw_dsSampleInput->getFullFilePath() + "'\n"
-      "(dir, file) = os.path.split(filename)\n"
-      "(sqwInput, ext) = os.path.splitext(file)\n"
-      "LoadNexus(Filename=filename, OutputWorkspace=sqwInput)\n";
-    }
-    else
-    {
-      //get the workspace
-      pyInput += "sqwInput = '" + m_uiForm.sqw_dsSampleInput->getCurrentDataName() + "'\n";
-    }
-
-    pyInput += "ConvertSpectrumAxis(InputWorkspace=sqwInput, OutputWorkspace=sqwInput[:-4]+'_rqw', Target='ElasticQ', EMode='Indirect')\n"
-    "ws = importMatrixWorkspace(sqwInput[:-4]+'_rqw')\n"
-    "ws.plotGraph2D()\n";
-
-    QString pyOutput = runPythonCode(pyInput).trimmed();
-  }
-  else
-  {
-    showInformationBox("Invalid filename.");
-  }
-}
-
-// SLICE
-void Indirect::sliceRun()
-{
-  QString error = validateSlice();
-  if ( ! error.isEmpty() )
-  {
-    showInformationBox(error);
-    return;
-  }
-
-  QString pyInput =
-    "from IndirectEnergyConversion import slice\n"
-    "tofRange = [" + QString::number(m_sltDblMng->value(m_sltProp["R1S"])) + ","
-    + QString::number(m_sltDblMng->value(m_sltProp["R1E"]));
-  if ( m_sltBlnMng->value(m_sltProp["UseTwoRanges"]) )
-  {
-    pyInput +=
-      "," + QString::number(m_sltDblMng->value(m_sltProp["R2S"])) + ","
-      + QString::number(m_sltDblMng->value(m_sltProp["R2E"])) + "]\n";
-  }
-  else
-  {
-    pyInput += "]\n";
-  }
-  if ( m_uiForm.slice_ckUseCalib->isChecked() )
-  {
-    pyInput +=
-      "calib = r'" + m_uiForm.slice_calibFile->getFirstFilename() + "'\n";
-  }
-  else
-  {
-    pyInput +=
-      "calib = ''\n";
-  }
-  QString filenames = m_uiForm.slice_inputFile->getFilenames().join("', r'");
-  QString suffix = m_uiForm.cbAnalyser->currentText() + m_uiForm.cbReflection->currentText();
-  pyInput +=
-    "rawfile = [r'" + filenames + "']\n"
-    "spectra = ["+ QString::number(m_sltDblMng->value(m_sltProp["SpecMin"])) + "," + QString::number(m_sltDblMng->value(m_sltProp["SpecMax"])) +"]\n"
-    "suffix = '" + suffix + "'\n";
-
-  if ( m_uiForm.slice_ckVerbose->isChecked() ) pyInput += "verbose = True\n";
-  else pyInput += "verbose = False\n";
-
-  if ( m_uiForm.slice_ckPlot->isChecked() ) pyInput += "plot = True\n";
-  else pyInput += "plot = False\n";
-
-  if ( m_uiForm.slice_ckSave->isChecked() ) pyInput += "save = True\n";
-  else pyInput += "save = False\n";
-
-  pyInput +=
-    "slice(rawfile, calib, tofRange, spectra, suffix, Save=save, Verbose=verbose, Plot=plot)";
-
-  QString pyOutput = runPythonCode(pyInput).trimmed();
-}
-
-void Indirect::slicePlotRaw()
-{
-  if ( m_uiForm.slice_inputFile->isValid() )
-  {
-    QString filename = m_uiForm.slice_inputFile->getFirstFilename();
-    QFileInfo fi(filename);
-    QString wsname = fi.baseName();
-
-    QString pyInput = "Load(Filename=r'" + filename + "', OutputWorkspace='" + wsname + "', SpectrumMin="
-      + m_uiForm.leSpectraMin->text() + ", SpectrumMax="
-      + m_uiForm.leSpectraMax->text() + ")\n";
-    
-    pyInput = "try:\n  " +
-                pyInput +
-              "except ValueError as ve:" +
-              "  print str(ve)";
-
-    QString pyOutput = runPythonCode(pyInput);
-    
-    if( ! pyOutput.isEmpty() )
-    {
-      showInformationBox("Unable to load file: \n\n\"" + pyOutput + "\".\n\nCheck whether your file exists and matches the selected instrument in the EnergyTransfer tab.");
-      return;
-    }
-
-    Mantid::API::MatrixWorkspace_sptr input = boost::dynamic_pointer_cast<Mantid::API::MatrixWorkspace>(Mantid::API::AnalysisDataService::Instance().retrieve(wsname.toStdString()));
-
-    const MantidVec & dataX = input->readX(0);
-    const MantidVec & dataY = input->readY(0);
-
-    if ( m_sltDataCurve != NULL )
-    {
-      m_sltDataCurve->attach(0);
-      delete m_sltDataCurve;
-      m_sltDataCurve = 0;
-    }
-
-    m_sltDataCurve = new QwtPlotCurve();
-    m_sltDataCurve->setData(&dataX[0], &dataY[0], static_cast<int>(input->blocksize()));
-    m_sltDataCurve->attach(m_sltPlot);
-
-    std::pair<double, double> range(dataX.front(), dataX.back());
-    m_calResPlot->setAxisScale(QwtPlot::xBottom, range.first, range.second);
-    setPlotRange(m_sltR1, m_sltDblMng, std::pair<QtProperty*,QtProperty*>(m_sltProp["R1S"], m_sltProp["R1E"]), range);
-    setPlotRange(m_sltR2, m_sltDblMng, std::pair<QtProperty*,QtProperty*>(m_sltProp["R2S"], m_sltProp["R2E"]), range);
-
-    // Replot
-    m_sltPlot->replot();
-  }
-  else
-  {
-    showInformationBox("Selected input files are invalid.");
-  }
-
-}
-
-void Indirect::sliceTwoRanges(QtProperty*, bool state)
-{
-  m_sltR2->setVisible(state);
-}
-
-void Indirect::sliceCalib(bool state)
-{
-  m_uiForm.slice_calibFile->setEnabled(state);
-  m_uiForm.slice_calibFile->isOptional(!state);
-}
-
-void Indirect::sliceMinChanged(double val)
-{
-  MantidWidgets::RangeSelector* from = qobject_cast<MantidWidgets::RangeSelector*>(sender());
-  if ( from == m_sltR1 )
-  {
-    m_sltDblMng->setValue(m_sltProp["R1S"], val);
-  }
-  else if ( from == m_sltR2 )
-  {
-    m_sltDblMng->setValue(m_sltProp["R2S"], val);
-  }
-}
-
-void Indirect::sliceMaxChanged(double val)
-{
-  MantidWidgets::RangeSelector* from = qobject_cast<MantidWidgets::RangeSelector*>(sender());
-  if ( from == m_sltR1 )
-  {
-    m_sltDblMng->setValue(m_sltProp["R1E"], val);
-  }
-  else if ( from == m_sltR2 )
-  {
-    m_sltDblMng->setValue(m_sltProp["R2E"], val);
-  }
-}
-
-void Indirect::sliceUpdateRS(QtProperty* prop, double val)
-{
-  if ( prop == m_sltProp["R1S"] ) m_sltR1->setMinimum(val);
-  else if ( prop == m_sltProp["R1E"] ) m_sltR1->setMaximum(val);
-  else if ( prop == m_sltProp["R2S"] ) m_sltR2->setMinimum(val);
-  else if ( prop == m_sltProp["R2E"] ) m_sltR2->setMaximum(val);
-}
-
-/**
- * Slot to wrap the protected showInformationBox method defined
- * in UserSubWindow and provide access to composed tabs.
- * 
- * @param message :: The message to display in the message box
- */
-void Indirect::showMessageBox(const QString& message)
-{
-  showInformationBox(message);
-}
-
-void Indirect::setPlotRange(MantidWidgets::RangeSelector* rangeSelector, QtDoublePropertyManager* dblManager, 
-  const std::pair<QtProperty*, QtProperty*> props, const std::pair<double, double>& bounds)
-{
-  dblManager->setMinimum(props.first, bounds.first);
-  dblManager->setMaximum(props.first, bounds.second);
-  dblManager->setMinimum(props.second, bounds.first);
-  dblManager->setMaximum(props.second, bounds.second);
-  rangeSelector->setRange(bounds.first, bounds.second);
-}
diff --git a/Code/Mantid/MantidQt/CustomInterfaces/src/IndirectCalibration.cpp b/Code/Mantid/MantidQt/CustomInterfaces/src/IndirectCalibration.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..f612fb33f8e009eef9227342cab22f514412b8f5
--- /dev/null
+++ b/Code/Mantid/MantidQt/CustomInterfaces/src/IndirectCalibration.cpp
@@ -0,0 +1,606 @@
+#include "MantidQtCustomInterfaces/IndirectCalibration.h"
+
+#include "MantidKernel/Logger.h"
+
+#include <QFileInfo>
+
+namespace
+{
+  Mantid::Kernel::Logger g_log("IndirectCalibration");
+}
+
+namespace MantidQt
+{
+namespace CustomInterfaces
+{
+  //----------------------------------------------------------------------------------------------
+  /** Constructor
+   */
+  IndirectCalibration::IndirectCalibration(Ui::IndirectDataReduction& uiForm, QWidget * parent) :
+      IndirectDataReductionTab(uiForm, parent)
+  {
+    DoubleEditorFactory *doubleEditorFactory = new DoubleEditorFactory();
+
+    // CAL PROPERTY TREE
+    m_propTrees["CalPropTree"] = new QtTreePropertyBrowser();
+    m_propTrees["CalPropTree"]->setFactoryForManager(m_dblManager, doubleEditorFactory);
+    m_uiForm.cal_treeCal->addWidget(m_propTrees["CalPropTree"]);
+
+    // Cal Property Tree: Peak/Background
+    m_properties["CalPeakMin"] = m_dblManager->addProperty("Peak Min");
+    m_properties["CalPeakMax"] = m_dblManager->addProperty("Peak Max");
+    m_properties["CalBackMin"] = m_dblManager->addProperty("Back Min");
+    m_properties["CalBackMax"] = m_dblManager->addProperty("Back Max");
+
+    m_propTrees["CalPropTree"]->addProperty(m_properties["CalPeakMin"]);
+    m_propTrees["CalPropTree"]->addProperty(m_properties["CalPeakMax"]);
+    m_propTrees["CalPropTree"]->addProperty(m_properties["CalBackMin"]);
+    m_propTrees["CalPropTree"]->addProperty(m_properties["CalBackMax"]);
+
+    // CAL PLOT
+    m_plots["CalPlot"] = new QwtPlot(m_parentWidget);
+    m_plots["CalPlot"]->setAxisFont(QwtPlot::xBottom, parent->font());
+    m_plots["CalPlot"]->setAxisFont(QwtPlot::yLeft, parent->font());
+    m_plots["CalPlot"]->setCanvasBackground(Qt::white);
+    m_uiForm.cal_plotCal->addWidget(m_plots["CalPlot"]);
+
+    // Cal plot range selectors
+    m_rangeSelectors["CalPeak"] = new MantidWidgets::RangeSelector(m_plots["CalPlot"]);
+    m_rangeSelectors["CalBackground"] = new MantidWidgets::RangeSelector(m_plots["CalPlot"]);
+    m_rangeSelectors["CalBackground"]->setColour(Qt::darkGreen); //Dark green to signify background range
+
+    // RES PROPERTY TREE
+    m_propTrees["ResPropTree"] = new QtTreePropertyBrowser();
+    m_propTrees["ResPropTree"]->setFactoryForManager(m_dblManager, doubleEditorFactory);
+    m_uiForm.cal_treeRes->addWidget(m_propTrees["ResPropTree"]);
+
+    // Res Property Tree: Spectra Selection
+    m_properties["ResSpecMin"] = m_dblManager->addProperty("Spectra Min");
+    m_propTrees["ResPropTree"]->addProperty(m_properties["ResSpecMin"]);
+    m_dblManager->setDecimals(m_properties["ResSpecMin"], 0);
+
+    m_properties["ResSpecMax"] = m_dblManager->addProperty("Spectra Max");
+    m_propTrees["ResPropTree"]->addProperty(m_properties["ResSpecMax"]);
+    m_dblManager->setDecimals(m_properties["ResSpecMax"], 0);
+
+    // Res Property Tree: Background Properties
+    QtProperty* resBG = m_grpManager->addProperty("Background");
+    m_propTrees["ResPropTree"]->addProperty(resBG);
+
+    m_properties["ResStart"] = m_dblManager->addProperty("Start");
+    resBG->addSubProperty(m_properties["ResStart"]);
+
+    m_properties["ResEnd"] = m_dblManager->addProperty("End");
+    resBG->addSubProperty(m_properties["ResEnd"]);
+
+    // Res Property Tree: Rebinning
+    const int NUM_DECIMALS = 3;
+    QtProperty* resRB = m_grpManager->addProperty("Rebinning");
+    m_propTrees["ResPropTree"]->addProperty(resRB);
+
+    m_properties["ResELow"] = m_dblManager->addProperty("Low");
+    m_dblManager->setDecimals(m_properties["ResELow"], NUM_DECIMALS);
+    m_dblManager->setValue(m_properties["ResELow"], -0.2);
+    resRB->addSubProperty(m_properties["ResELow"]);
+
+    m_properties["ResEWidth"] = m_dblManager->addProperty("Width");
+    m_dblManager->setDecimals(m_properties["ResEWidth"], NUM_DECIMALS);
+    m_dblManager->setValue(m_properties["ResEWidth"], 0.002);
+    m_dblManager->setMinimum(m_properties["ResEWidth"], 0.001);
+    resRB->addSubProperty(m_properties["ResEWidth"]);
+
+    m_properties["ResEHigh"] = m_dblManager->addProperty("High");
+    m_dblManager->setDecimals(m_properties["ResEHigh"], NUM_DECIMALS);
+    m_dblManager->setValue(m_properties["ResEHigh"], 0.2);
+    resRB->addSubProperty(m_properties["ResEHigh"]);
+
+    // RES PLOT
+    m_plots["ResPlot"] = new QwtPlot(m_parentWidget);
+    m_plots["ResPlot"]->setAxisFont(QwtPlot::xBottom, parent->font());
+    m_plots["ResPlot"]->setAxisFont(QwtPlot::yLeft, parent->font());
+    m_plots["ResPlot"]->setCanvasBackground(Qt::white);
+    m_uiForm.cal_plotRes->addWidget(m_plots["ResPlot"]);
+
+    // Res plot range selectors
+    // Create ResBackground first so ResPeak is drawn above it
+    m_rangeSelectors["ResBackground"] = new MantidWidgets::RangeSelector(m_plots["ResPlot"],
+        MantidQt::MantidWidgets::RangeSelector::XMINMAX, true, false);
+    m_rangeSelectors["ResBackground"]->setColour(Qt::darkGreen);
+    m_rangeSelectors["ResPeak"] = new MantidWidgets::RangeSelector(m_plots["ResPlot"],
+        MantidQt::MantidWidgets::RangeSelector::XMINMAX, true, true);
+    
+    // MISC UI
+    m_uiForm.cal_leIntensityScaleMultiplier->setValidator(m_valDbl);
+    m_uiForm.cal_leResScale->setValidator(m_valDbl);
+    m_uiForm.cal_valIntensityScaleMultiplier->setText(" ");
+
+    // SIGNAL/SLOT CONNECTIONS
+    connect(m_rangeSelectors["ResPeak"], SIGNAL(rangeChanged(double, double)), m_rangeSelectors["ResBackground"], SLOT(setRange(double, double)));
+
+    // Update property map when a range seclector is moved
+    connect(m_rangeSelectors["CalPeak"], SIGNAL(minValueChanged(double)), this, SLOT(calMinChanged(double)));
+    connect(m_rangeSelectors["CalPeak"], SIGNAL(maxValueChanged(double)), this, SLOT(calMaxChanged(double)));
+    connect(m_rangeSelectors["CalBackground"], SIGNAL(minValueChanged(double)), this, SLOT(calMinChanged(double)));
+    connect(m_rangeSelectors["CalBackground"], SIGNAL(maxValueChanged(double)), this, SLOT(calMaxChanged(double)));
+    connect(m_rangeSelectors["ResPeak"], SIGNAL(minValueChanged(double)), this, SLOT(calMinChanged(double)));
+    connect(m_rangeSelectors["ResPeak"], SIGNAL(maxValueChanged(double)), this, SLOT(calMaxChanged(double)));
+    connect(m_rangeSelectors["ResBackground"], SIGNAL(minValueChanged(double)), this, SLOT(calMinChanged(double)));
+    connect(m_rangeSelectors["ResBackground"], SIGNAL(maxValueChanged(double)), this, SLOT(calMaxChanged(double)));
+    // Update range selctor positions when a value in the double manager changes
+    connect(m_dblManager, SIGNAL(valueChanged(QtProperty*, double)), this, SLOT(calUpdateRS(QtProperty*, double)));
+    // Plot miniplots after a file has loaded
+    connect(m_uiForm.cal_leRunNo, SIGNAL(filesFound()), this, SLOT(calPlotRaw()));
+    // Plot miniplots when the user clicks Plot Raw
+    connect(m_uiForm.cal_pbPlot, SIGNAL(clicked()), this, SLOT(calPlotRaw()));
+    // Toggle RES file options when user toggles Create RES File checkbox
+    connect(m_uiForm.cal_ckRES, SIGNAL(toggled(bool)), this, SLOT(resCheck(bool)));
+    // Toggle RES range selector when user toggles Create RES File checkbox
+    connect(m_uiForm.cal_ckRES, SIGNAL(toggled(bool)), m_uiForm.cal_ckResScale, SLOT(setEnabled(bool)));
+    // Enable/disable RES scaling option when user toggles Scale RES checkbox
+    connect(m_uiForm.cal_ckResScale, SIGNAL(toggled(bool)), m_uiForm.cal_leResScale, SLOT(setEnabled(bool)));
+    // Enable/dosable scale factor option when user toggles Intensity Scale Factor checkbox
+    connect(m_uiForm.cal_ckIntensityScaleMultiplier, SIGNAL(toggled(bool)), this, SLOT(intensityScaleMultiplierCheck(bool)));
+    // Validate the value entered in scale factor option whenever it changes
+    connect(m_uiForm.cal_leIntensityScaleMultiplier, SIGNAL(textChanged(const QString &)), this, SLOT(calibValidateIntensity(const QString &)));
+
+    // Nudge resCheck to ensure res range selectors are only shown when Create RES file is checked
+    resCheck(m_uiForm.cal_ckRES->isChecked());
+  }
+    
+  //----------------------------------------------------------------------------------------------
+  /** Destructor
+   */
+  IndirectCalibration::~IndirectCalibration()
+  {
+  }
+  
+  void IndirectCalibration::setup()
+  {
+  }
+
+  void IndirectCalibration::run()
+  {
+    QString file = m_uiForm.cal_leRunNo->getFirstFilename();
+    QString filenames = "[r'"+m_uiForm.cal_leRunNo->getFilenames().join("', r'")+"']";
+
+    QString reducer = "from mantid.simpleapi import SaveNexus\n"
+      "from inelastic_indirect_reduction_steps import CreateCalibrationWorkspace\n"
+      "calib = CreateCalibrationWorkspace()\n"
+      "calib.set_files(" + filenames + ")\n"
+      "calib.set_detector_range(" + m_uiForm.leSpectraMin->text() + "-1, " + m_uiForm.leSpectraMax->text() + "-1)\n"
+      "calib.set_parameters(" + m_properties["CalBackMin"]->valueText() + "," 
+      + m_properties["CalBackMax"]->valueText() + ","
+      + m_properties["CalPeakMin"]->valueText() + ","
+      + m_properties["CalPeakMax"]->valueText() + ")\n"
+      "calib.set_analyser('" + m_uiForm.cbAnalyser->currentText() + "')\n"
+      "calib.set_reflection('" + m_uiForm.cbReflection->currentText() + "')\n";
+
+    //Scale values by arbitrary scalar if requested
+    if(m_uiForm.cal_ckIntensityScaleMultiplier->isChecked())
+    {
+      QString scale = m_uiForm.cal_leIntensityScaleMultiplier->text(); 
+      if(scale.isEmpty())
+      {
+          scale = "1.0";
+        }
+        reducer += "calib.set_intensity_scale("+scale+")\n";
+      }
+
+      reducer += "calib.execute(None, None)\n"
+        "result = calib.result_workspace()\n"
+        "print result\n";
+
+      if( m_uiForm.cal_ckSave->isChecked() )
+      {
+        reducer +=
+          "SaveNexus(InputWorkspace=result, Filename=result+'.nxs')\n";
+      }
+
+      if ( m_uiForm.cal_ckPlotResult->isChecked() )
+      {
+        reducer += "from mantidplot import plotTimeBin\n"
+          "plotTimeBin(result, 0)\n";
+      }
+
+      QString pyOutput = m_pythonRunner.runPythonCode(reducer).trimmed();
+
+      if ( pyOutput == "" )
+      {
+        emit showMessageBox("An error occurred creating the calib file.\n");
+      }
+      else
+      {
+        if ( m_uiForm.cal_ckRES->isChecked() )
+        {
+          createRESfile(filenames);
+        }
+        m_uiForm.ind_calibFile->setFileTextWithSearch(pyOutput + ".nxs");
+        m_uiForm.ckUseCalib->setChecked(true);
+      }
+  }
+
+  bool IndirectCalibration::validate()
+  {
+    MantidQt::CustomInterfaces::UserInputValidator uiv;
+
+    uiv.checkMWRunFilesIsValid("Run", m_uiForm.cal_leRunNo);
+
+    auto peakRange = std::make_pair(m_dblManager->value(m_properties["CalPeakMin"]), m_dblManager->value(m_properties["CalPeakMax"]));
+    auto backRange = std::make_pair(m_dblManager->value(m_properties["CalBackMin"]), m_dblManager->value(m_properties["CalBackMax"]));
+
+    uiv.checkValidRange("Peak Range", peakRange);
+    uiv.checkValidRange("Back Range", backRange);
+    uiv.checkRangesDontOverlap(peakRange, backRange);
+
+    if ( m_uiForm.cal_ckRES->isChecked() )
+    {
+      auto backgroundRange = std::make_pair(m_dblManager->value(m_properties["ResStart"]), m_dblManager->value(m_properties["ResEnd"]));
+      uiv.checkValidRange("Background", backgroundRange);
+
+      double eLow   = m_dblManager->value(m_properties["ResELow"]);
+      double eHigh  = m_dblManager->value(m_properties["ResEHigh"]);
+      double eWidth = m_dblManager->value(m_properties["ResEWidth"]);
+
+      uiv.checkBins(eLow, eWidth, eHigh);
+    }
+
+    if( m_uiForm.cal_ckIntensityScaleMultiplier->isChecked()
+        && m_uiForm.cal_leIntensityScaleMultiplier->text().isEmpty() )
+    {
+      uiv.addErrorMessage("You must enter a scale for the calibration file");
+    }
+
+    if( m_uiForm.cal_ckResScale->isChecked() && m_uiForm.cal_leResScale->text().isEmpty() )
+    {
+      uiv.addErrorMessage("You must enter a scale for the resolution file");
+    }
+
+    QString error = uiv.generateErrorMessage();
+
+    if(error != "")
+      g_log.warning(error.toStdString());
+
+    return (error == "");
+  }
+
+  /**
+   * Sets default spectra, peak and background ranges
+   */
+  void IndirectCalibration::setDefaultInstDetails()
+  {
+    //Get spectra, peak and background details
+    std::map<QString, QString> instDetails = getInstrumentDetails();
+
+    //Set spectra range
+    m_dblManager->setValue(m_properties["ResSpecMin"], instDetails["SpectraMin"].toDouble());
+    m_dblManager->setValue(m_properties["ResSpecMax"], instDetails["SpectraMax"].toDouble());
+
+    //Set pean and background ranges
+    if(instDetails.size() >= 8)
+    {
+      setMiniPlotGuides("CalPeak", m_properties["CalPeakMin"], m_properties["CalPeakMax"],
+          std::pair<double, double>(instDetails["PeakMin"].toDouble(), instDetails["PeakMax"].toDouble()));
+      setMiniPlotGuides("CalBackground", m_properties["CalBackMin"], m_properties["CalBackMax"],
+          std::pair<double, double>(instDetails["BackMin"].toDouble(), instDetails["BackMax"].toDouble()));
+    }
+  }
+
+  /**
+   * Replots the raw data mini plot and the energy mini plot
+   */
+  void IndirectCalibration::calPlotRaw()
+  {
+    setDefaultInstDetails();
+
+    QString filename = m_uiForm.cal_leRunNo->getFirstFilename();
+
+    if ( filename.isEmpty() )
+    {
+      emit showMessageBox("Cannot plot raw data without filename");
+      return;
+    }
+
+    QFileInfo fi(filename);
+    QString wsname = fi.baseName();
+    QString pyInput = "Load(Filename=r'" + filename + "', OutputWorkspace='" + wsname + "', SpectrumMin="
+      + m_uiForm.leSpectraMin->text() + ", SpectrumMax="
+      + m_uiForm.leSpectraMax->text() + ")\n";
+
+    pyInput = "try:\n  " +
+      pyInput +
+      "except ValueError as ve:" +
+      "  print str(ve)";
+
+    QString pyOutput = m_pythonRunner.runPythonCode(pyInput);
+
+    if(!pyOutput.isEmpty())
+    {
+      emit showMessageBox("Unable to load file. Error: \n\n" + pyOutput + "\nCheck whether your file exists and matches the selected instrument in the Energy Transfer tab.");
+      return;
+    }
+
+    Mantid::API::MatrixWorkspace_sptr input = boost::dynamic_pointer_cast<Mantid::API::MatrixWorkspace>(
+        Mantid::API::AnalysisDataService::Instance().retrieve(wsname.toStdString()));
+
+    const Mantid::MantidVec & dataX = input->readX(0);
+    std::pair<double, double> range(dataX.front(), dataX.back());
+
+    plotMiniPlot(input, 0, "CalPlot", "CalCurve");
+    setXAxisToCurve("CalPlot", "CalCurve");
+
+    setPlotRange("CalPeak", m_properties["CalELow"], m_properties["CalEHigh"], range);
+    setPlotRange("CalBackground", m_properties["CalStart"], m_properties["CalEnd"], range);
+
+    replot("CalPlot");
+
+    //Also replot the energy
+    calPlotEnergy();
+  }
+
+  /**
+   * Replots the energy mini plot
+   */
+  void IndirectCalibration::calPlotEnergy()
+  {
+    if ( ! m_uiForm.cal_leRunNo->isValid() )
+    {
+      emit showMessageBox("Run number not valid.");
+      return;
+    }
+
+    QString files = "[r'" + m_uiForm.cal_leRunNo->getFilenames().join("', r'") + "']";
+    QString pyInput =
+      "from IndirectEnergyConversion import resolution\n"
+      "iconOpt = { 'first': " +QString::number(m_dblManager->value(m_properties["ResSpecMin"]))+
+      ", 'last': " +QString::number(m_dblManager->value(m_properties["ResSpecMax"]))+ "}\n"
+      "instrument = '" + m_uiForm.cbInst->currentText() + "'\n"
+      "analyser = '" + m_uiForm.cbAnalyser->currentText() + "'\n"
+      "reflection = '" + m_uiForm.cbReflection->currentText() + "'\n"
+      "files = " + files + "\n"
+      "outWS = resolution(files, iconOpt, '', '', instrument, analyser, reflection, Res=False)\n"
+      "print outWS\n";
+    QString pyOutput = m_pythonRunner.runPythonCode(pyInput).trimmed();
+
+    //Something went wrong in the Python
+    if(pyOutput == "None")
+    {
+      emit showMessageBox("Failed to convert to energy. See log for details.");
+      return;
+    }
+
+    Mantid::API::MatrixWorkspace_sptr input = boost::dynamic_pointer_cast<Mantid::API::MatrixWorkspace>(
+        Mantid::API::AnalysisDataService::Instance().retrieve(pyOutput.toStdString()));
+
+    const Mantid::MantidVec & dataX = input->readX(0);
+    std::pair<double, double> range(dataX.front(), dataX.back());
+
+    setPlotRange("ResBackground", m_properties["ResStart"], m_properties["ResEnd"], range);
+
+    plotMiniPlot(input, 0, "ResPlot", "ResCurve");
+    setXAxisToCurve("ResPlot", "ResCurve");
+
+    calSetDefaultResolution(input);
+
+    replot("ResPlot");
+  }
+
+  /**
+   * Set default background and rebinning properties for a given instument
+   * and analyser
+   *
+   * @param ws :: Mantid workspace containing the loaded instument
+   */
+  void IndirectCalibration::calSetDefaultResolution(Mantid::API::MatrixWorkspace_const_sptr ws)
+  {
+    auto inst = ws->getInstrument();
+    auto analyser = inst->getStringParameter("analyser");
+
+    if(analyser.size() > 0)
+    {
+      auto comp = inst->getComponentByName(analyser[0]);
+
+      if(!comp)
+        return;
+
+      auto params = comp->getNumberParameter("resolution", true);
+
+      //Set the default instrument resolution
+      if(params.size() > 0)
+      {
+        double res = params[0];
+
+        //Set default rebinning bounds
+        std::pair<double, double> peakRange(-res*10, res*10);
+        setMiniPlotGuides("ResPeak", m_properties["ResELow"], m_properties["ResEHigh"], peakRange);
+
+        //Set default background bounds
+        std::pair<double, double> backgroundRange(-res*9, -res*8);
+        setMiniPlotGuides("ResBackground", m_properties["ResStart"], m_properties["ResEnd"], backgroundRange);
+      }
+    }
+  }
+
+  /**
+   * Handles a range selector having it's minumum value changed.
+   * Updates property in property map.
+   *
+   * @param val :: New minumum value
+   */
+  void IndirectCalibration::calMinChanged(double val)
+  {
+    MantidWidgets::RangeSelector* from = qobject_cast<MantidWidgets::RangeSelector*>(sender());
+    if ( from == m_rangeSelectors["CalPeak"] )
+    {
+      m_dblManager->setValue(m_properties["CalPeakMin"], val);
+    }
+    else if ( from == m_rangeSelectors["CalBackground"] )
+    {
+      m_dblManager->setValue(m_properties["CalBackMin"], val);
+    }
+    else if ( from == m_rangeSelectors["ResPeak"] )
+    {
+      m_dblManager->setValue(m_properties["ResELow"], val);
+    }
+    else if ( from == m_rangeSelectors["ResBackground"] )
+    {
+      m_dblManager->setValue(m_properties["ResStart"], val);
+    }
+  }
+
+  /**
+   * Handles a range selector having it's maxumum value changed.
+   * Updates property in property map.
+   *
+   * @param val :: New maxumum value
+   */
+  void IndirectCalibration::calMaxChanged(double val)
+  {
+    MantidWidgets::RangeSelector* from = qobject_cast<MantidWidgets::RangeSelector*>(sender());
+    if ( from == m_rangeSelectors["CalPeak"] )
+    {
+      m_dblManager->setValue(m_properties["CalPeakMax"], val);
+    }
+    else if ( from == m_rangeSelectors["CalBackground"] )
+    {
+      m_dblManager->setValue(m_properties["CalBackMax"], val);
+    }
+    else if ( from == m_rangeSelectors["ResPeak"] )
+    {
+      m_dblManager->setValue(m_properties["ResEHigh"], val);
+    }
+    else if ( from == m_rangeSelectors["ResBackground"] )
+    {
+      m_dblManager->setValue(m_properties["ResEnd"], val);
+    }
+  }
+
+  /**
+   * Update a range selector given a QtProperty and new value
+   *
+   * @param prop :: The property to update
+   * @param val :: New value for property
+   */
+  void IndirectCalibration::calUpdateRS(QtProperty* prop, double val)
+  {
+    if ( prop == m_properties["CalPeakMin"] ) m_rangeSelectors["CalPeak"]->setMinimum(val);
+    else if ( prop == m_properties["CalPeakMax"] ) m_rangeSelectors["CalPeak"]->setMaximum(val);
+    else if ( prop == m_properties["CalBackMin"] ) m_rangeSelectors["CalBackground"]->setMinimum(val);
+    else if ( prop == m_properties["CalBackMax"] ) m_rangeSelectors["CalBackground"]->setMaximum(val);
+    else if ( prop == m_properties["ResStart"] ) m_rangeSelectors["ResBackground"]->setMinimum(val);
+    else if ( prop == m_properties["ResEnd"] ) m_rangeSelectors["ResBackground"]->setMaximum(val);
+    else if ( prop == m_properties["ResELow"] ) m_rangeSelectors["ResPeak"]->setMinimum(val);
+    else if ( prop == m_properties["ResEHigh"] ) m_rangeSelectors["ResPeak"]->setMaximum(val);
+  }
+
+  /**
+  * This function enables/disables the display of the options involved in creating the RES file.
+  *
+  * @param state :: whether checkbox is checked or unchecked
+  */
+  void IndirectCalibration::resCheck(bool state)
+  {
+    m_rangeSelectors["ResPeak"]->setVisible(state);
+    m_rangeSelectors["ResBackground"]->setVisible(state);
+  }
+
+  /**
+   * This function is called after calib has run and creates a RES file for use in later analysis (Fury,etc)
+   * 
+   * @param file :: the input file (WBV run.raw)
+   */
+  void IndirectCalibration::createRESfile(const QString& file)
+  {
+    QString scaleFactor("1.0");
+    if(m_uiForm.cal_ckResScale->isChecked())
+    {
+      if(!m_uiForm.cal_leResScale->text().isEmpty())
+      {
+        scaleFactor = m_uiForm.cal_leResScale->text();
+      }
+    }
+
+    QString pyInput =
+      "from IndirectEnergyConversion import resolution\n"
+      "iconOpt = { 'first': " +QString::number(m_dblManager->value(m_properties["ResSpecMin"]))+
+      ", 'last': " +QString::number(m_dblManager->value(m_properties["ResSpecMax"]))+"}\n"
+
+      "instrument = '" + m_uiForm.cbInst->currentText() + "'\n"
+      "analyser = '" + m_uiForm.cbAnalyser->currentText() + "'\n"
+      "reflection = '" + m_uiForm.cbReflection->currentText() + "'\n";
+
+    if ( m_uiForm.cal_ckPlotResult->isChecked() ) { pyInput +=	"plot = True\n"; }
+    else { pyInput += "plot = False\n"; }
+
+    if ( m_uiForm.cal_ckVerbose->isChecked() ) { pyInput +=  "verbose = True\n"; }
+    else { pyInput += "verbose = False\n"; }
+
+    if ( m_uiForm.cal_ckSave->isChecked() ) { pyInput +=  "save = True\n"; }
+    else { pyInput += "save = False\n"; }
+
+    QString rebinParam = QString::number(m_dblManager->value(m_properties["ResELow"])) + "," +
+      QString::number(m_dblManager->value(m_properties["ResEWidth"])) + "," +
+      QString::number(m_dblManager->value(m_properties["ResEHigh"]));
+
+    QString background = "[ " +QString::number(m_dblManager->value(m_properties["ResStart"]))+ ", " +QString::number(m_dblManager->value(m_properties["ResEnd"]))+"]";
+
+    QString scaled = m_uiForm.cal_ckIntensityScaleMultiplier->isChecked() ? "True" : "False";
+    pyInput +=
+      "background = " + background + "\n"
+      "rebinParam = '" + rebinParam + "'\n"
+      "file = " + file + "\n"
+      "ws = resolution(file, iconOpt, rebinParam, background, instrument, analyser, reflection, Verbose=verbose, Plot=plot, Save=save, factor="+scaleFactor+")\n"
+      "scaled = "+ scaled +"\n"
+      "scaleFactor = "+m_uiForm.cal_leIntensityScaleMultiplier->text()+"\n"
+      "backStart = "+QString::number(m_dblManager->value(m_properties["CalBackMin"]))+"\n"
+      "backEnd = "+QString::number(m_dblManager->value(m_properties["CalBackMax"]))+"\n"
+      "rebinLow = "+QString::number(m_dblManager->value(m_properties["ResELow"]))+"\n"
+      "rebinWidth = "+QString::number(m_dblManager->value(m_properties["ResEWidth"]))+"\n"
+      "rebinHigh = "+QString::number(m_dblManager->value(m_properties["ResEHigh"]))+"\n"
+      "AddSampleLog(Workspace=ws, LogName='scale', LogType='String', LogText=str(scaled))\n"
+      "if scaled:"
+      "  AddSampleLog(Workspace=ws, LogName='scale_factor', LogType='Number', LogText=str(scaleFactor))\n"
+      "AddSampleLog(Workspace=ws, LogName='back_start', LogType='Number', LogText=str(backStart))\n"
+      "AddSampleLog(Workspace=ws, LogName='back_end', LogType='Number', LogText=str(backEnd))\n"
+      "AddSampleLog(Workspace=ws, LogName='rebin_low', LogType='Number', LogText=str(rebinLow))\n"
+      "AddSampleLog(Workspace=ws, LogName='rebin_width', LogType='Number', LogText=str(rebinWidth))\n"
+      "AddSampleLog(Workspace=ws, LogName='rebin_high', LogType='Number', LogText=str(rebinHigh))\n";
+
+    QString pyOutput = m_pythonRunner.runPythonCode(pyInput).trimmed();
+
+    if ( pyOutput != "" )
+    {
+      emit showMessageBox("Unable to create RES file: \n" + pyOutput);
+    }
+  }
+
+  /**
+   * Enables or disables the scale multiplier input box when
+   * the check box state changes
+   *
+   * @param state :: True to enable input, false to disable
+   */
+  void IndirectCalibration::intensityScaleMultiplierCheck(bool state)
+  {
+    m_uiForm.cal_leIntensityScaleMultiplier->setEnabled(state);
+  }
+
+  /**
+   * Hides/shows the required indicator of the scale multiplier
+   * input box
+   *
+   * @param text :: Text currently in box
+   */
+  void IndirectCalibration::calibValidateIntensity(const QString & text)
+  {
+    if(!text.isEmpty())
+    {
+      m_uiForm.cal_valIntensityScaleMultiplier->setText(" ");
+    }
+    else
+    {
+      m_uiForm.cal_valIntensityScaleMultiplier->setText("*");
+    }
+  }
+
+} // namespace CustomInterfaces
+} // namespace Mantid
diff --git a/Code/Mantid/MantidQt/CustomInterfaces/src/IndirectConvertToEnergy.cpp b/Code/Mantid/MantidQt/CustomInterfaces/src/IndirectConvertToEnergy.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..751174b4e49597c869f624248b165372f3bb592b
--- /dev/null
+++ b/Code/Mantid/MantidQt/CustomInterfaces/src/IndirectConvertToEnergy.cpp
@@ -0,0 +1,847 @@
+#include "MantidQtCustomInterfaces/IndirectConvertToEnergy.h"
+
+#include "MantidQtCustomInterfaces/Background.h"
+
+#include <QInputDialog>
+
+namespace MantidQt
+{
+namespace CustomInterfaces
+{
+  //----------------------------------------------------------------------------------------------
+  /** Constructor
+   */
+  IndirectConvertToEnergy::IndirectConvertToEnergy(Ui::IndirectDataReduction& uiForm, QWidget * parent) :
+      IndirectDataReductionTab(uiForm, parent), m_backgroundDialog(NULL), m_bgRemoval(false)
+  {
+    // Add validators to UI form
+    m_uiForm.leScaleMultiplier->setValidator(m_valPosDbl);
+    m_uiForm.leNoGroups->setValidator(m_valInt);
+    m_uiForm.leDetailedBalance->setValidator(m_valPosDbl);
+
+    m_uiForm.leSpectraMin->setValidator(m_valInt);
+    m_uiForm.leSpectraMax->setValidator(m_valInt);
+
+    m_uiForm.entryRebinLow->setValidator(m_valDbl);
+    m_uiForm.entryRebinWidth->setValidator(m_valDbl);
+    m_uiForm.entryRebinHigh->setValidator(m_valDbl);
+    
+    // SIGNAL/SLOT CONNECTIONS
+    // Updates current analyser when analyser is selected from drop down
+    connect(m_uiForm.cbAnalyser, SIGNAL(activated(int)), this, SLOT(analyserSelected(int)));
+    // Updates current reflection when reflection is selected from drop down
+    connect(m_uiForm.cbReflection, SIGNAL(activated(int)), this, SLOT(reflectionSelected(int)));
+    // Shows required mapping option UI widgets when a new mapping option is selected from drop down
+    connect(m_uiForm.cbMappingOptions, SIGNAL(currentIndexChanged(const QString&)), this, SLOT(mappingOptionSelected(const QString&)));
+    // Shows background removal dialog when user clicks Background Removal
+    connect(m_uiForm.pbBack_2, SIGNAL(clicked()), this, SLOT(backgroundClicked()));
+    // Plots raw input data when user clicks Plot Time
+    connect(m_uiForm.pbPlotRaw, SIGNAL(clicked()), this, SLOT(plotRaw()));
+    // Enables/disables rebin options when user toggles Do Not Rebin checkbox
+    connect(m_uiForm.rebin_ckDNR, SIGNAL(toggled(bool)), this, SLOT(rebinEntryToggle(bool)));
+    // Enables/disables detail balance option when user toggle Detailed Balance checkbox
+    connect(m_uiForm.ckDetailedBalance, SIGNAL(toggled(bool)), this, SLOT(detailedBalanceCheck(bool)));
+    // Enables/disables scale multiply option when user toggles Scale checkbox
+    connect(m_uiForm.ckScaleMultiplier, SIGNAL(toggled(bool)), this, SLOT(scaleMultiplierCheck(bool)));
+    connect(m_uiForm.ind_calibFile, SIGNAL(fileTextChanged(const QString &)), this, SLOT(calibFileChanged(const QString &)));
+    // Enables/disables calibration file options when user toggles Use Calib File checkbox
+    connect(m_uiForm.ckUseCalib, SIGNAL(toggled(bool)), this, SLOT(useCalib(bool)));
+    // Displays correct UI widgets for selected rebin type when changed via Rebin Steps drop down
+    connect(m_uiForm.comboRebinType, SIGNAL(currentIndexChanged(int)), m_uiForm.swIndRebin, SLOT(setCurrentIndex(int)));
+    // Shows message on run buton when user is inputting a run number
+    connect(m_uiForm.ind_runFiles, SIGNAL(fileTextChanged(const QString &)), this, SLOT(pbRunEditing()));
+    // Shows message on run button when Mantid is finding the file for a given run number
+    connect(m_uiForm.ind_runFiles, SIGNAL(findingFiles()), this, SLOT(pbRunFinding()));
+    // Reverts run button back to normal when file finding has finished
+    connect(m_uiForm.ind_runFiles, SIGNAL(fileFindingFinished()), this, SLOT(pbRunFinished()));
+    // Perform validation when editing an option
+    connect(m_uiForm.leDetailedBalance, SIGNAL(textChanged(const QString &)), this, SLOT(validateTab()));
+    connect(m_uiForm.leScaleMultiplier, SIGNAL(textChanged(const QString &)), this, SLOT(validateTab()));
+    connect(m_uiForm.leSpectraMin, SIGNAL(textChanged(const QString &)), this, SLOT(validateTab()));
+    connect(m_uiForm.leSpectraMax, SIGNAL(textChanged(const QString &)), this, SLOT(validateTab()));
+    connect(m_uiForm.entryRebinLow, SIGNAL(textChanged(const QString &)), this, SLOT(validateTab()));
+    connect(m_uiForm.entryRebinWidth, SIGNAL(textChanged(const QString &)), this, SLOT(validateTab()));
+    connect(m_uiForm.entryRebinHigh, SIGNAL(textChanged(const QString &)), this, SLOT(validateTab()));
+
+    // Update UI widgets to show default values
+    mappingOptionSelected(m_uiForm.cbMappingOptions->currentText());
+    rebinEntryToggle(m_uiForm.rebin_ckDNR->isChecked());
+    backgroundRemoval();
+
+    // Validate to remove invalid markers
+    validateTab();
+  }
+
+  //----------------------------------------------------------------------------------------------
+  /** Destructor
+   */
+  IndirectConvertToEnergy::~IndirectConvertToEnergy()
+  {
+  }
+  
+  void IndirectConvertToEnergy::setup()
+  {
+  }
+
+  void IndirectConvertToEnergy::run()
+  {
+    QString pyInput =
+      "import inelastic_indirect_reducer as iir\n"
+      "reducer = iir.IndirectReducer()\n"
+      "reducer.set_instrument_name('" + m_uiForm.cbInst->currentText() + "')\n"
+      "reducer.set_detector_range(" +m_uiForm.leSpectraMin->text()+ "-1, " +m_uiForm.leSpectraMax->text()+ "-1)\n"
+      "reducer.set_parameter_file('" + QString::fromStdString(Mantid::Kernel::ConfigService::Instance().getString("instrumentDefinition.directory")) + m_uiForm.cbInst->currentText() + "_" + m_uiForm.cbAnalyser->currentText() + "_" + m_uiForm.cbReflection->currentText() + "_Parameters.xml')\n";
+
+    QStringList files = m_uiForm.ind_runFiles->getFilenames();
+    for ( QStringList::iterator it = files.begin(); it != files.end(); ++it )
+    {
+      pyInput += "reducer.append_data_file(r'" + *it + "')\n";
+    }
+
+    if ( m_uiForm.ckSumFiles->isChecked() )
+    {
+      pyInput += "reducer.set_sum_files(True)\n";
+    }
+
+    if ( m_bgRemoval )
+    {
+      QPair<double,double> background = m_backgroundDialog->getRange();
+      pyInput += "reducer.set_background("+QString::number(background.first)+", "+QString::number(background.second)+")\n";
+    }
+
+    if ( m_uiForm.ckUseCalib->isChecked() )
+    {
+      pyInput +=
+        "from IndirectCommon import loadNexus\n"
+        "reducer.set_calibration_workspace(loadNexus(r'"+m_uiForm.ind_calibFile->getFirstFilename()+"'))\n";
+    }
+
+    if ( m_uiForm.ckLoadLogs->isChecked() )
+    {
+      pyInput += "reducer.set_load_logs(True)\n";
+    }
+
+    if ( ! m_uiForm.rebin_ckDNR->isChecked() )
+    {
+      QString rebin;
+      if ( m_uiForm.comboRebinType->currentIndex() == 0 )
+      {
+        rebin = m_uiForm.entryRebinLow->text() + "," + m_uiForm.entryRebinWidth->text() + "," + m_uiForm.entryRebinHigh->text();
+      }
+      else
+      {
+        rebin = m_uiForm.entryRebinString->text();
+      }
+      pyInput += "reducer.set_rebin_string('"+rebin+"')\n";
+    }
+
+    if ( m_uiForm.ckDetailedBalance->isChecked() )
+    {
+      pyInput += "reducer.set_detailed_balance(" + m_uiForm.leDetailedBalance->text() + ")\n";
+    }
+
+    if ( m_uiForm.ckScaleMultiplier->isChecked() )
+    {
+      pyInput += "reducer.set_scale_factor(" + m_uiForm.leScaleMultiplier->text() + ")\n";
+    }
+
+    if ( m_uiForm.cbMappingOptions->currentText() != "Default" )
+    {
+      QString grouping = createMapFile(m_uiForm.cbMappingOptions->currentText());
+      pyInput += "reducer.set_grouping_policy('" + grouping + "')\n";
+    }
+
+    if ( ! m_uiForm.ckRenameWorkspace->isChecked() )
+    {
+      pyInput += "reducer.set_rename(False)\n";
+    }
+
+    if ( ! m_uiForm.ckFold->isChecked() )
+    {
+      pyInput += "reducer.set_fold_multiple_frames(False)\n";
+    }
+
+    if( m_uiForm.ckCm1Units->isChecked() )
+    {
+      pyInput += "reducer.set_save_to_cm_1(True)\n";
+    }
+
+    pyInput += "reducer.set_save_formats([" + savePyCode() + "])\n";
+
+    pyInput +=
+      "reducer.reduce()\n"
+      "ws_list = reducer.get_result_workspaces()\n";
+
+    // Plot Output options
+    switch ( m_uiForm.ind_cbPlotOutput->currentIndex() )
+    {
+      case 0: // "None"
+        break;
+      case 1: // "Spectra"
+        {
+          // Plot a spectra of the first result workspace
+          pyInput += 
+            "if ( len(ws_list) > 0 ):\n"
+            "  nSpec = mtd[ws_list[0]].getNumberHistograms()\n"
+            "  plotSpectrum(ws_list[0], range(0, nSpec))\n";
+        }
+        break;
+      case 2: // "Contour"
+        {
+          // Plot a 2D Contour Lines of the first result workspace
+          pyInput += 
+            "if ( len(ws_list) > 0 ):\n"
+            "  ws = importMatrixWorkspace(ws_list[0])\n"
+            "  ws.plotGraph2D()\n";
+        }
+        break;
+    }
+
+    // add sample logs to each of the workspaces
+    QString calibChecked = m_uiForm.ckUseCalib->isChecked() ? "True" : "False";
+    QString detailedBalance = m_uiForm.ckDetailedBalance->isChecked() ? "True" : "False";
+    QString scaled = m_uiForm.ckScaleMultiplier->isChecked() ? "True" : "False";
+    pyInput += "calibCheck = "+calibChecked+"\n"
+      "detailedBalance = "+detailedBalance+"\n"
+      "scaled = "+scaled+"\n"
+      "for ws in ws_list:\n"
+      "  AddSampleLog(Workspace=ws, LogName='calib_file', LogType='String', LogText=str(calibCheck))\n"
+      "  if calibCheck:\n"
+      "    AddSampleLog(Workspace=ws, LogName='calib_file_name', LogType='String', LogText='"+m_uiForm.ind_calibFile->getFirstFilename()+"')\n"
+      "  AddSampleLog(Workspace=ws, LogName='detailed_balance', LogType='String', LogText=str(detailedBalance))\n"
+      "  if detailedBalance:\n"
+      "    AddSampleLog(Workspace=ws, LogName='detailed_balance_temp', LogType='Number', LogText='"+m_uiForm.leDetailedBalance->text()+"')\n"
+      "  AddSampleLog(Workspace=ws, LogName='scale', LogType='String', LogText=str(scaled))\n"
+      "  if scaled:\n"
+      "    AddSampleLog(Workspace=ws, LogName='scale_factor', LogType='Number', LogText='"+m_uiForm.leScaleMultiplier->text()+"')\n";
+
+    QString pyOutput = m_pythonRunner.runPythonCode(pyInput).trimmed();
+  }
+
+  bool IndirectConvertToEnergy::validate()
+  {
+    bool valid = true;
+
+    // run files input
+    if ( ! m_uiForm.ind_runFiles->isValid() )
+    {
+      valid = false;
+    }
+
+    // calib file input
+    if ( m_uiForm.ckUseCalib->isChecked() && !m_uiForm.ind_calibFile->isValid() )
+    {
+      valid = false;
+    }
+
+    // mapping selection
+    if (
+        ( m_uiForm.cbMappingOptions->currentText() == "Groups" && m_uiForm.leNoGroups->text() == "" ) 
+        ||
+        ( m_uiForm.cbMappingOptions->currentText() == "File" && ! m_uiForm.ind_mapFile->isValid() )
+       )
+    {
+      valid = false;
+      m_uiForm.valNoGroups->setText("*");
+    }
+    else
+    {
+      m_uiForm.valNoGroups->setText("");
+    }
+
+    int dummyPos = 0;
+
+    QString text = m_uiForm.leDetailedBalance->text();
+    QValidator::State fieldState = m_uiForm.leDetailedBalance->validator()->validate(text, dummyPos);
+
+    // detailed balance
+    if ( m_uiForm.ckDetailedBalance->isChecked() && fieldState != QValidator::Acceptable )
+    {
+      valid = false;
+      m_uiForm.valDetailedBalance->setText("*");
+    }
+    else
+    {
+      m_uiForm.valDetailedBalance->setText("");
+    }
+
+    int dummyPos2 = 0;
+
+    // scale multiplier
+    QString scaleMultiplierText = m_uiForm.leScaleMultiplier->text();
+    QValidator::State fieldState2 = m_uiForm.leScaleMultiplier->validator()->validate(scaleMultiplierText, dummyPos2);
+
+    if ( m_uiForm.ckScaleMultiplier->isChecked() && fieldState2 != QValidator::Acceptable )
+    {
+      valid = false;
+      m_uiForm.valScaleMultiplier->setText("*");
+    }
+    else
+    {
+      m_uiForm.valScaleMultiplier->setText("");
+    }
+
+    // SpectraMin/SpectraMax
+    const QString specMin = m_uiForm.leSpectraMin->text();
+    const QString specMax = m_uiForm.leSpectraMax->text();
+
+    if (specMin.isEmpty() || specMax.isEmpty() ||
+        (specMin.toDouble() < 1 || specMax.toDouble() < 1) ||  
+        (specMin.toDouble() > specMax.toDouble()))
+    {
+      valid = false;
+      m_uiForm.valSpectraMin->setText("*");
+      m_uiForm.valSpectraMax->setText("*");
+    }
+    else
+    {
+      m_uiForm.valSpectraMin->setText("");
+      m_uiForm.valSpectraMax->setText("");
+    }
+
+    if ( ! m_uiForm.rebin_ckDNR->isChecked() )
+    {
+      if ( m_uiForm.comboRebinType->currentIndex() == 0 )
+      {
+        if ( m_uiForm.entryRebinLow->text() == "" )
+        {
+          valid = false;
+          m_uiForm.valELow->setText("*");
+        }
+        else
+        {
+          m_uiForm.valELow->setText("");
+        }
+
+        if ( m_uiForm.entryRebinWidth->text() == "" )
+        {
+          valid = false;
+          m_uiForm.valEWidth->setText("*");
+        }
+        else
+        {
+          m_uiForm.valEWidth->setText("");
+        }
+
+        if ( m_uiForm.entryRebinHigh->text() == "" )
+        {
+          valid = false;
+          m_uiForm.valEHigh->setText("*");
+        }
+        else
+        {
+          m_uiForm.valEHigh->setText("");
+        }
+
+        if ( m_uiForm.entryRebinLow->text().toDouble() > m_uiForm.entryRebinHigh->text().toDouble() )
+        {
+          valid = false;
+          m_uiForm.valELow->setText("*");
+          m_uiForm.valEHigh->setText("*");
+        }
+      }
+      else
+      {
+        if ( m_uiForm.entryRebinString->text() == "" )
+        {
+          valid = false;
+        }
+      }
+    }
+    else
+    {
+      m_uiForm.valELow->setText("");
+      m_uiForm.valEWidth->setText("");
+      m_uiForm.valEHigh->setText("");
+    }
+
+    return valid;
+  }
+
+  /**
+   * This function is called when the user selects an analyser from the cbAnalyser QComboBox
+   * object. It's main purpose is to initialise the values for the Reflection ComboBox.
+   * @param index :: Index of the value selected in the combo box.
+   */
+  void IndirectConvertToEnergy::analyserSelected(int index)
+  {
+    // populate Reflection combobox with correct values for Analyser selected.
+    m_uiForm.cbReflection->clear();
+    clearReflectionInfo();
+
+    QVariant currentData = m_uiForm.cbAnalyser->itemData(index);
+    if ( currentData == QVariant::Invalid )
+    {
+      m_uiForm.lbReflection->setEnabled(false);
+      m_uiForm.cbReflection->setEnabled(false);
+      return;
+    }
+    else
+    {
+      m_uiForm.lbReflection->setEnabled(true);
+      m_uiForm.cbReflection->setEnabled(true);
+      QStringList reflections = currentData.toStringList();
+      for ( int i = 0; i < reflections.count(); i++ )
+      {
+        m_uiForm.cbReflection->addItem(reflections[i]);
+      }
+    }
+
+    reflectionSelected(m_uiForm.cbReflection->currentIndex());
+  }
+
+  /**
+   * This function is called when the user selects a reflection from the cbReflection QComboBox
+   * object.
+   * @param index :: Index of the value selected in the combo box.
+   */
+  void IndirectConvertToEnergy::reflectionSelected(int index)
+  {
+    UNUSED_ARG(index);
+    // first, clear values in assosciated boxes:
+    clearReflectionInfo();
+
+    std::map<QString, QString> instDetails = getInstrumentDetails();
+
+    if ( instDetails.size() < 3 )
+    {
+      emit showMessageBox("Could not gather necessary data from parameter file.");
+      return;
+    }
+    else
+    {
+      m_uiForm.leSpectraMin->setText(instDetails["SpectraMin"]);
+      m_uiForm.leSpectraMax->setText(instDetails["SpectraMax"]);
+
+      if ( instDetails.size() >= 8 )
+      {
+        m_uiForm.leEfixed->setText(instDetails["EFixed"]);
+      }
+      else
+      {
+        m_uiForm.leEfixed->clear();
+      }
+
+      // Default rebinning parameters can be set in instrument parameter file
+      if ( instDetails.size() == 9 )
+      {
+        m_uiForm.entryRebinString->setText(instDetails["RebinString"]);
+        m_uiForm.rebin_ckDNR->setChecked(false);
+        QStringList rbp = instDetails["RebinString"].split(",", QString::SkipEmptyParts);
+        if ( rbp.size() == 3 )
+        {
+          m_uiForm.entryRebinLow->setText(rbp[0]);
+          m_uiForm.entryRebinWidth->setText(rbp[1]);
+          m_uiForm.entryRebinHigh->setText(rbp[2]);
+          m_uiForm.comboRebinType->setCurrentIndex(0);
+        }
+        else
+        {
+          m_uiForm.comboRebinType->setCurrentIndex(1);
+        }
+      }
+      else
+      {
+        m_uiForm.rebin_ckDNR->setChecked(true);
+        m_uiForm.entryRebinLow->setText("");
+        m_uiForm.entryRebinWidth->setText("");
+        m_uiForm.entryRebinHigh->setText("");
+        m_uiForm.entryRebinString->setText("");
+      }
+    }
+  }
+
+  /**
+   * This function runs when the user makes a selection on the cbMappingOptions QComboBox.
+   * @param groupType :: Value of selection made by user.
+   */
+  void IndirectConvertToEnergy::mappingOptionSelected(const QString& groupType)
+  {
+    if ( groupType == "File" )
+    {
+      m_uiForm.swMapping->setCurrentIndex(0);
+    }
+    else if ( groupType == "Groups" )
+    {
+      m_uiForm.swMapping->setCurrentIndex(1);
+    }
+    else if ( groupType == "All" || groupType == "Individual" || groupType == "Default" )
+    {
+      m_uiForm.swMapping->setCurrentIndex(2);
+    }
+  }
+
+  /**
+   * This function is called when the user clicks on the Background Removal button. It
+   * displays the Background Removal dialog, initialising it if it hasn't been already.
+   */
+  void IndirectConvertToEnergy::backgroundClicked()
+  {
+    if(!m_backgroundDialog)
+    {
+      m_backgroundDialog = new Background(m_parentWidget);
+      connect(m_backgroundDialog, SIGNAL(accepted()), this, SLOT(backgroundRemoval()));
+      connect(m_backgroundDialog, SIGNAL(rejected()), this, SLOT(backgroundRemoval()));
+    }
+    m_backgroundDialog->show();
+  }
+
+  /**
+   * Slot called when m_backgroundDialog is closed. Assesses whether user desires background removal.
+   * Can be called before m_backgroundDialog even exists, for the purposes of setting the button to
+   * it's initial (default) value.
+   */
+  void IndirectConvertToEnergy::backgroundRemoval()
+  {
+    if(m_backgroundDialog != NULL)
+      m_bgRemoval = m_backgroundDialog->removeBackground();
+
+    if(m_bgRemoval)
+      m_uiForm.pbBack_2->setText("Background Removal (On)");
+    else
+      m_uiForm.pbBack_2->setText("Background Removal (Off)");
+  }
+
+  /**
+   * This function holds any steps that must be performed on the selection of an instrument,
+   * for example loading values from the Instrument Definition File (IDF).
+   * @param prefix :: The selected instruments prefix in Mantid.
+   */
+  void IndirectConvertToEnergy::setIDFValues(const QString & prefix)
+  {
+    UNUSED_ARG(prefix);
+    // empty ComboBoxes, LineEdits,etc of previous values
+    m_uiForm.cbAnalyser->clear();
+    m_uiForm.cbReflection->clear();
+    clearReflectionInfo();
+
+    rebinEntryToggle(m_uiForm.rebin_ckDNR->isChecked());
+    detailedBalanceCheck(m_uiForm.ckDetailedBalance->isChecked());
+    /* resCheck(m_uiForm.cal_ckRES->isChecked()); */
+
+    scaleMultiplierCheck(m_uiForm.ckScaleMultiplier->isChecked());
+
+    // Get list of analysers and populate cbAnalyser
+    QString pyInput = 
+      "from IndirectEnergyConversion import getInstrumentDetails\n"
+      "result = getInstrumentDetails('" + m_uiForm.cbInst->currentText() + "')\n"
+      "print result\n";
+
+    QString pyOutput = m_pythonRunner.runPythonCode(pyInput, false).trimmed();
+
+    if ( pyOutput == "" )
+    {
+      emit showMessageBox("Could not get list of analysers from Instrument Parameter file.");
+    }
+    else
+    {
+      QStringList analysers = pyOutput.split("\n", QString::SkipEmptyParts);
+
+      for (int i = 0; i< analysers.count(); i++ )
+      {
+        QString text; // holds Text field of combo box (name of analyser)
+
+        if ( text != "diffraction" ) // do not put diffraction into the analyser list
+        {
+          QVariant data; // holds Data field of combo box (list of reflections)
+
+          QStringList analyser = analysers[i].split("-", QString::SkipEmptyParts);
+
+          text = analyser[0];
+
+          if ( analyser.count() > 1 )
+          {
+            QStringList reflections = analyser[1].split(",", QString::SkipEmptyParts);
+            data = QVariant(reflections);
+            m_uiForm.cbAnalyser->addItem(text, data);
+          }
+          else
+          {
+            m_uiForm.cbAnalyser->addItem(text);
+          }
+        }
+      }
+
+      analyserSelected(m_uiForm.cbAnalyser->currentIndex());
+    }
+  }
+
+  /**
+   * This function clears the values of the QLineEdit objec  ts used to hold Reflection-specific
+   * information.
+   */
+  void IndirectConvertToEnergy::clearReflectionInfo()
+  {
+    m_uiForm.leSpectraMin->clear();
+    m_uiForm.leSpectraMax->clear();
+    m_uiForm.leEfixed->clear();
+  }
+
+  /**
+   * This function will disable the necessary elements of the interface when the user selects "Do Not Rebin"
+   * and enable them again when this is de-selected.
+   *
+   * @param state :: whether the "Do Not Rebin" checkbox is checked
+   */
+  void IndirectConvertToEnergy::rebinEntryToggle(bool state) 
+  {
+    //Determine value for single rebin field
+    QString val;
+    if(state)
+      val = " ";
+    else
+      val = "*";
+
+    //Rebin mode selection
+    m_uiForm.comboRebinType->setEnabled(!state);
+    m_uiForm.labelRebinSteps->setEnabled(!state);
+
+    //Single rebin text entry
+    m_uiForm.labelRebinLow->setEnabled( !state );
+    m_uiForm.labelRebinWidth->setEnabled( !state );
+    m_uiForm.labelRebinHigh->setEnabled( !state );
+    m_uiForm.entryRebinLow->setEnabled( !state );
+    m_uiForm.entryRebinWidth->setEnabled( !state );
+    m_uiForm.entryRebinHigh->setEnabled( !state );
+
+    //Rebin required markers
+    m_uiForm.valELow->setEnabled(!state);
+    m_uiForm.valELow->setText(val);
+    m_uiForm.valEWidth->setEnabled(!state);
+    m_uiForm.valEWidth->setText(val);
+    m_uiForm.valEHigh->setEnabled(!state);
+    m_uiForm.valEHigh->setText(val);
+
+    //Rebin string entry
+    m_uiForm.entryRebinString->setEnabled(!state);
+    m_uiForm.labelRebinString->setEnabled(!state);
+  }
+
+  /**
+   * Disables/enables the relevant parts of the UI when user checks/unchecks the Detailed Balance
+   * ckDetailedBalance checkbox.
+   * @param state :: state of the checkbox
+   */
+  void IndirectConvertToEnergy::detailedBalanceCheck(bool state)
+  {
+    m_uiForm.leDetailedBalance->setEnabled(state);
+    m_uiForm.lbDBKelvin->setEnabled(state);
+  }
+
+  /**
+   * Disables/enables the relevant parts of the UI when user checks/unchecks the 'Multiplication Factor (Scale):'
+   * ckScaleMultiplier checkbox.
+   * @param state :: state of the checkbox
+   */
+  void IndirectConvertToEnergy::scaleMultiplierCheck(bool state)
+  {
+    m_uiForm.leScaleMultiplier->setEnabled(state);
+  }
+
+  /**
+   * This function creates the mapping/grouping file for the data analysis.
+   * @param groupType :: Type of grouping (All, Group, Indiviual)
+   * @return path to mapping file, or an empty string if file could not be created.
+   */
+  QString IndirectConvertToEnergy::createMapFile(const QString& groupType)
+  {
+    QString groupFile, ngroup, nspec;
+    QString ndet = "( "+m_uiForm.leSpectraMax->text()+" - "+m_uiForm.leSpectraMin->text()+") + 1";
+
+    if ( groupType == "File" )
+    {
+      groupFile = m_uiForm.ind_mapFile->getFirstFilename();
+      if ( groupFile == "" )
+      {
+        emit showMessageBox("You must enter a path to the .map file.");
+      }
+      return groupFile;
+    }
+    else if ( groupType == "Groups" )
+    {
+      ngroup = m_uiForm.leNoGroups->text();
+      nspec = "( " +ndet+ " ) / " +ngroup;
+    }
+    else if ( groupType == "All" )
+    {
+      return "All";
+    }
+    else if ( groupType == "Individual" )
+    {
+      return "Individual";
+    }
+
+    groupFile = m_uiForm.cbInst->itemData(m_uiForm.cbInst->currentIndex()).toString().toLower();
+    groupFile += "_" + m_uiForm.cbAnalyser->currentText() + m_uiForm.cbReflection->currentText();
+    groupFile += "_" + groupType + ".map";	
+
+    QString pyInput =
+      "import IndirectEnergyConversion as ind\n"
+      "mapfile = ind.createMappingFile('"+groupFile+"', %1, %2, %3)\n"
+      "print mapfile\n";
+    pyInput = pyInput.arg(ngroup);
+    pyInput = pyInput.arg(nspec);
+    pyInput = pyInput.arg(m_uiForm.leSpectraMin->text());
+
+    QString pyOutput = m_pythonRunner.runPythonCode(pyInput).trimmed();
+
+    return pyOutput;
+  }
+
+  /**
+   * This function creates the Python script necessary to set the variables used for saving data
+   * in the main convert_to_energy script.
+   * @return python code as a string
+   */
+  QString IndirectConvertToEnergy::savePyCode()
+  {
+    QStringList fileFormats;
+    QString fileFormatList;
+
+    if ( m_uiForm.save_ckNexus->isChecked() )
+      fileFormats << "nxs";
+    if ( m_uiForm.save_ckSPE->isChecked() )
+      fileFormats << "spe";
+    if ( m_uiForm.save_ckNxSPE->isChecked() )
+      fileFormats << "nxspe";
+    if ( m_uiForm.save_ckAscii->isChecked() )
+      fileFormats << "ascii";
+    if ( m_uiForm.save_ckAclimax->isChecked() )
+      fileFormats << "aclimax";
+
+    if ( fileFormats.size() != 0 )
+      fileFormatList = "'" + fileFormats.join("', '") + "'";
+    else
+      fileFormatList = "";
+
+    return fileFormatList;
+  }
+
+  /**
+   * Plots raw time data from .raw file before any data conversion has been performed.
+   */
+  void IndirectConvertToEnergy::plotRaw()
+  {
+    if ( m_uiForm.ind_runFiles->isValid() )
+    {
+      bool ok;
+      QString spectraRange = QInputDialog::getText(0, "Insert Spectra Ranges", "Range: ", QLineEdit::Normal, m_uiForm.leSpectraMin->text() +"-"+ m_uiForm.leSpectraMax->text(), &ok);
+
+      if ( !ok || spectraRange.isEmpty() )
+      {
+        return;
+      }
+      QStringList specList = spectraRange.split("-");
+
+      QString rawFile = m_uiForm.ind_runFiles->getFirstFilename();
+      if ( (specList.size() > 2) || ( specList.size() < 1) )
+      {
+        emit showMessageBox("Invalid input. Must be of form <SpecMin>-<SpecMax>");
+        return;
+      }
+      if ( specList.size() == 1 )
+      {
+        specList.append(specList[0]);
+      }
+
+      QString bgrange;
+
+      if ( m_bgRemoval )
+      {
+        QPair<double, double> range = m_backgroundDialog->getRange();
+        bgrange = "[ " + QString::number(range.first) + "," + QString::number(range.second) + " ]";
+      }
+      else
+      {
+        bgrange = "[-1, -1]";
+      }
+
+      QString pyInput =
+        "from mantid.simpleapi import CalculateFlatBackground,GroupDetectors,Load\n"
+        "from mantidplot import plotSpectrum\n"
+        "import os.path as op\n"
+        "file = r'" + rawFile + "'\n"
+        "name = op.splitext( op.split(file)[1] )[0]\n"
+        "bgrange = " + bgrange + "\n"
+        "Load(Filename=file, OutputWorkspace=name, SpectrumMin="+specList[0]+", SpectrumMax="+specList[1]+")\n"
+        "if ( bgrange != [-1, -1] ):\n"
+        "    #Remove background\n"
+        "    CalculateFlatBackground(InputWorkspace=name, OutputWorkspace=name+'_bg', StartX=bgrange[0], EndX=bgrange[1], Mode='Mean')\n"
+        "    GroupDetectors(InputWorkspace=name+'_bg', OutputWorkspace=name+'_grp', DetectorList=range("+specList[0]+","+specList[1]+"+1))\n"
+        "    GroupDetectors(InputWorkspace=name, OutputWorkspace=name+'_grp_raw', DetectorList=range("+specList[0]+","+specList[1]+"+1))\n"
+        "else: # Just group detectors as they are\n"
+        "    GroupDetectors(InputWorkspace=name, OutputWorkspace=name+'_grp', DetectorList=range("+specList[0]+","+specList[1]+"+1))\n"
+        "graph = plotSpectrum(name+'_grp', 0)\n";
+
+      QString pyOutput = m_pythonRunner.runPythonCode(pyInput).trimmed();
+
+      if ( pyOutput != "" )
+      {
+        emit showMessageBox(pyOutput);
+      }
+    }
+    else
+    {
+      emit showMessageBox("You must select a run file.");
+    }
+  }
+
+  void IndirectConvertToEnergy::useCalib(bool state)
+  {
+    m_uiForm.ind_calibFile->isOptional(!state);
+    m_uiForm.ind_calibFile->setEnabled(state);
+  }
+
+  /**
+   * Controls the ckUseCalib checkbox to automatically check it when a user inputs a file from clicking on 'browse'.
+   * @param calib :: path to calib file
+   */
+  void IndirectConvertToEnergy::calibFileChanged(const QString & calib)
+  {
+    if ( calib.isEmpty() )
+    {
+      m_uiForm.ckUseCalib->setChecked(false);
+    }
+    else
+    {
+      m_uiForm.ckUseCalib->setChecked(true);
+    }
+  }
+
+  /**
+   * Called when a user starts to type / edit the runs to load.
+   */
+  void IndirectConvertToEnergy::pbRunEditing()
+  {
+    m_uiForm.pbRun->setEnabled(false);
+    m_uiForm.pbRun->setText("Editing...");
+  }
+
+  /**
+   * Called when the FileFinder starts finding the files.
+   */
+  void IndirectConvertToEnergy::pbRunFinding()
+  {
+    m_uiForm.pbRun->setText("Finding files...");
+    m_uiForm.ind_runFiles->setEnabled(false);
+  }
+
+  /**
+   * Called when the FileFinder has finished finding the files.
+   */
+  void IndirectConvertToEnergy::pbRunFinished()
+  {
+    if(!m_uiForm.ind_runFiles->isValid())
+    {
+      m_uiForm.pbRun->setText("Invalid Run");
+    }
+    else
+    {
+      m_uiForm.pbRun->setText("Run");
+      m_uiForm.pbRun->setEnabled(true);
+    }
+    m_uiForm.ind_runFiles->setEnabled(true);
+  }
+
+} // namespace CustomInterfaces
+} // namespace Mantid
diff --git a/Code/Mantid/MantidQt/CustomInterfaces/src/IndirectDataReduction.cpp b/Code/Mantid/MantidQt/CustomInterfaces/src/IndirectDataReduction.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..4f2fe9195e6998bfdf60c65982557ede95ce6829
--- /dev/null
+++ b/Code/Mantid/MantidQt/CustomInterfaces/src/IndirectDataReduction.cpp
@@ -0,0 +1,420 @@
+//----------------------
+// Includes
+//----------------------
+#include "MantidQtCustomInterfaces/IndirectDataReduction.h"
+
+#include "MantidAPI/AlgorithmManager.h"
+#include "MantidAPI/AnalysisDataService.h"
+#include "MantidAPI/ExperimentInfo.h"
+#include "MantidKernel/ConfigService.h"
+#include "MantidQtAPI/ManageUserDirectories.h"
+#include "MantidQtCustomInterfaces/IndirectCalibration.h"
+#include "MantidQtCustomInterfaces/IndirectConvertToEnergy.h"
+#include "MantidQtCustomInterfaces/IndirectDiagnostics.h"
+#include "MantidQtCustomInterfaces/IndirectMoments.h"
+#include "MantidQtCustomInterfaces/IndirectSqw.h"
+#include "MantidQtCustomInterfaces/IndirectTransmission.h"
+
+#include <QDesktopServices>
+#include <QDir>
+#include <QMessageBox>
+#include <QUrl>
+
+//Add this class to the list of specialised dialogs in this namespace
+namespace MantidQt
+{
+  namespace CustomInterfaces
+  {
+    DECLARE_SUBWINDOW(IndirectDataReduction);
+  }
+}
+
+namespace
+{
+  Mantid::Kernel::Logger g_log("IndirectDataReduction");
+}
+
+using namespace MantidQt::CustomInterfaces;
+using namespace MantidQt;
+//----------------------
+// Public member functions
+//----------------------
+
+/**
+ * Default constructor for class. Initialises interface pointers to NULL values.
+ * @param parent :: This is a pointer to the "parent" object in Qt, most likely the main MantidPlot window.
+ */
+IndirectDataReduction::IndirectDataReduction(QWidget *parent) :
+  UserSubWindow(parent),
+  m_curInterfaceSetup(""),
+  m_settingsGroup("CustomInterfaces/IndirectDataReduction"),
+  m_algRunner(new MantidQt::API::AlgorithmRunner(this)),
+  m_changeObserver(*this, &IndirectDataReduction::handleDirectoryChange)
+{
+  //Signals to report load instrument algo result
+  connect(m_algRunner, SIGNAL(algorithmComplete(bool)), this, SLOT(instrumentLoadingDone(bool)));
+}
+
+/**
+ * Destructor
+ */
+IndirectDataReduction::~IndirectDataReduction()
+{
+  //Make sure no algos are sunning after the window has been closed
+  m_algRunner->cancelRunningAlgorithm();
+
+  saveSettings();
+}
+
+/**
+ * On user clicking the "help" button on the interface, directs their request to the relevant
+ * interface's helpClicked() function.
+ */
+void IndirectDataReduction::helpClicked()
+{
+  QString tabName = m_uiForm.tabWidget->tabText(
+      m_uiForm.tabWidget->currentIndex());
+  QString url = "http://www.mantidproject.org/Indirect:";
+  if ( tabName == "Energy Transfer" )
+    url += "EnergyTransfer";
+  else if ( tabName == "Calibration" )
+    url += "Calibration";
+  else if ( tabName == "Diagnostics" )
+    url += "Diagnostics";
+  else if ( tabName == "S(Q, w)" )
+    url += "SofQW";
+  else if (tabName == "Transmission")
+    url += "Transmission";
+  else if (tabName == "Moments")
+    url += "Moments";
+  QDesktopServices::openUrl(QUrl(url));
+}
+
+/**
+ * This is the function called when the "Run" button is clicked. It will call the relevent function
+ * in the subclass.
+ */
+void IndirectDataReduction::runClicked()
+{
+  QString tabName = m_uiForm.tabWidget->tabText(m_uiForm.tabWidget->currentIndex());
+  if ( tabName == "Energy Transfer" )
+    m_tab_convert_to_energy->runTab();
+  else if ( tabName == "Calibration" )
+    m_tab_calibration->runTab();
+  else if ( tabName == "Diagnostics" )
+    m_tab_diagnostics->runTab();
+  else if ( tabName == "S(Q, w)" )
+    m_tab_sqw->runTab();
+  else if (tabName == "Transmission")
+    m_tab_trans->runTab();
+  else if(tabName == "Moments")
+    m_tab_moments->runTab();
+}
+
+/**
+ * Sets up Qt UI file and connects signals, slots. 
+ */
+void IndirectDataReduction::initLayout()
+{
+  m_uiForm.setupUi(this);
+
+  m_tab_convert_to_energy = new IndirectConvertToEnergy(m_uiForm, this);
+  m_tab_sqw = new IndirectSqw(m_uiForm, this);
+  m_tab_diagnostics = new IndirectDiagnostics(m_uiForm, this);
+  m_tab_calibration = new IndirectCalibration(m_uiForm, this);
+  m_tab_trans = new IndirectTransmission(m_uiForm, this);
+  m_tab_moments = new IndirectMoments(m_uiForm, this);
+
+  // Assume we get a incompatiable instrument to start with
+  m_uiForm.pbRun->setEnabled(false);
+
+  // Signal / Slot Connections Set Up Here
+
+  // signal/slot connections to respond to changes in instrument selection combo boxes
+  connect(m_uiForm.cbInst, SIGNAL(instrumentSelectionChanged(const QString&)), this, SLOT(userSelectInstrument(const QString&)));
+
+  // connect "?" (Help) Button
+  connect(m_uiForm.pbHelp, SIGNAL(clicked()), this, SLOT(helpClicked()));
+  // connect the "Run" button
+  connect(m_uiForm.pbRun, SIGNAL(clicked()), this, SLOT(runClicked()));
+  // connect the "Manage User Directories" Button
+  connect(m_uiForm.pbManageDirectories, SIGNAL(clicked()), this, SLOT(openDirectoryDialog()));
+
+  // ignals for tabs running Python
+  connect(m_tab_convert_to_energy, SIGNAL(runAsPythonScript(const QString&, bool)), this, SIGNAL(runAsPythonScript(const QString&, bool)));
+  connect(m_tab_sqw, SIGNAL(runAsPythonScript(const QString&, bool)), this, SIGNAL(runAsPythonScript(const QString&, bool)));
+  connect(m_tab_calibration, SIGNAL(runAsPythonScript(const QString&, bool)), this, SIGNAL(runAsPythonScript(const QString&, bool)));
+  connect(m_tab_diagnostics, SIGNAL(runAsPythonScript(const QString&, bool)), this, SIGNAL(runAsPythonScript(const QString&, bool)));
+  connect(m_tab_trans, SIGNAL(runAsPythonScript(const QString&, bool)), this, SIGNAL(runAsPythonScript(const QString&, bool)));
+  connect(m_tab_moments, SIGNAL(runAsPythonScript(const QString&, bool)), this, SIGNAL(runAsPythonScript(const QString&, bool)));
+
+  // ignals for tabs showing mesage boxes
+  connect(m_tab_convert_to_energy, SIGNAL(showMessageBox(const QString&)), this, SLOT(showMessageBox(const QString&)));
+  connect(m_tab_sqw, SIGNAL(showMessageBox(const QString&)), this, SLOT(showMessageBox(const QString&)));
+  connect(m_tab_calibration, SIGNAL(showMessageBox(const QString&)), this, SLOT(showMessageBox(const QString&)));
+  connect(m_tab_diagnostics, SIGNAL(showMessageBox(const QString&)), this, SLOT(showMessageBox(const QString&)));
+  connect(m_tab_trans, SIGNAL(showMessageBox(const QString&)), this, SLOT(showMessageBox(const QString&)));
+  connect(m_tab_moments, SIGNAL(showMessageBox(const QString&)), this, SLOT(showMessageBox(const QString&)));
+
+  // Run any tab setup code
+  m_tab_convert_to_energy->setupTab();
+  m_tab_sqw->setupTab();
+  m_tab_diagnostics->setupTab();
+  m_tab_calibration->setupTab();
+  m_tab_trans->setupTab();
+  m_tab_moments->setupTab();
+}
+
+/**
+ * This function is ran after initLayout(), and runPythonCode is unavailable before this function
+ * has run (because of the setup of the base class). For this reason, "setup" functions that require
+ * Python scripts are located here.
+ */
+void IndirectDataReduction::initLocalPython()
+{
+  // select starting instrument
+  readSettings();
+
+  if ( m_curInterfaceSetup == "" )
+  {
+    userSelectInstrument(m_uiForm.cbInst->currentText());
+  }
+}
+
+/**
+ * Read settings from the persistent store
+ */
+void IndirectDataReduction::readSettings()
+{
+  QSettings settings;
+  settings.beginGroup(m_settingsGroup);
+  QString instrName = settings.value("instrument-name", "").toString();
+  settings.endGroup();
+
+  setDefaultInstrument(instrName);
+}
+
+/**
+ * Save settings to a persistent storage
+ */
+void IndirectDataReduction::saveSettings()
+{
+  QSettings settings;
+  settings.beginGroup(m_settingsGroup);
+  QString instrName;
+
+  instrName = m_uiForm.cbInst->currentText();
+
+  settings.setValue("instrument-name", instrName);
+  settings.endGroup();
+}
+
+/**
+ * Sets up the initial instrument for the interface. This value is taken from the users'
+ * settings in the menu View -> Preferences -> Mantid -> Instrument
+ * @param name :: The name of the default instrument
+ */
+void IndirectDataReduction::setDefaultInstrument(const QString & name)
+{
+  if( name.isEmpty() ) return;
+
+  int index = m_uiForm.cbInst->findText(name);
+  if( index >= 0 )
+  {
+    m_uiForm.cbInst->setCurrentIndex(index);
+  }
+}
+
+/**
+ * This function: 1. loads the instrument and gets the value of deltaE-mode parameter
+ *				 2. Based on this value, makes the necessary changes to the form setup (direct or indirect).
+ * @param name :: name of the instrument from the QComboBox
+ */
+void IndirectDataReduction::instrumentSelectChanged(const QString& name)
+{
+  QString defFile = (Mantid::API::ExperimentInfo::getInstrumentFilename(name.toStdString())).c_str();
+  if((defFile == "") || !m_uiForm.cbInst->isVisible())
+  {
+    g_log.error("Instument loading failed!");
+    m_uiForm.cbInst->setEnabled(true);
+    m_uiForm.pbRun->setEnabled(true);
+    return;
+  }
+
+  QString outWS = "__empty_" + m_uiForm.cbInst->currentText();
+
+  m_curInterfaceSetup = name;
+
+  //Load the empty instrument into the workspace __empty_[name]
+  //This used to be done in Python
+  Mantid::API::IAlgorithm_sptr instLoader = Mantid::API::AlgorithmManager::Instance().create("LoadEmptyInstrument", -1);
+  instLoader->initialize();
+  instLoader->setProperty("Filename", defFile.toStdString());
+  instLoader->setProperty("OutputWorkspace", outWS.toStdString());
+
+  //Ensure no other algorithm is running
+  m_algRunner->cancelRunningAlgorithm();
+  m_algRunner->startAlgorithm(instLoader);
+}
+
+/**
+ * Tasks to be carried out after an empty instument has finished loading
+ */
+void IndirectDataReduction::instrumentLoadingDone(bool error)
+{
+  QString curInstPrefix = m_uiForm.cbInst->itemData(m_uiForm.cbInst->currentIndex()).toString();
+  if((curInstPrefix == "") || error)
+  {
+    g_log.error("Instument loading failed! (this can be caused by having both direct and indirect interfaces open)");
+    m_uiForm.cbInst->setEnabled(true);
+    m_uiForm.pbRun->setEnabled(true);
+    return;
+  }
+
+  performInstSpecific();
+  setIDFValues(curInstPrefix);
+
+  m_uiForm.pbRun->setEnabled(true);
+  m_uiForm.cbInst->setEnabled(true);
+}
+
+/**
+ * If the instrument selection has changed, calls instrumentSelectChanged
+ * @param prefix :: instrument name from QComboBox object
+ */
+void IndirectDataReduction::userSelectInstrument(const QString& prefix) 
+{
+  if ( prefix != m_curInterfaceSetup )
+  {
+    // Remove the old empty instrument workspace if it is there
+    std::string ws_name = "__empty_" + m_curInterfaceSetup.toStdString();
+    Mantid::API::AnalysisDataServiceImpl& dataStore = Mantid::API::AnalysisDataService::Instance();
+    if( dataStore.doesExist(ws_name) )
+    {
+      dataStore.remove(ws_name);
+    }
+
+    m_uiForm.pbRun->setEnabled(false);
+    m_uiForm.cbInst->setEnabled(false);
+    instrumentSelectChanged(prefix);
+  }
+}
+
+void IndirectDataReduction::openDirectoryDialog()
+{
+  MantidQt::API::ManageUserDirectories *ad = new MantidQt::API::ManageUserDirectories(this);
+  ad->show();
+  ad->setFocus();
+}
+
+/**
+* This function holds any steps that must be performed on the selection of an instrument,
+* for example loading values from the Instrument Definition File (IDF).
+* @param prefix :: The selected instruments prefix in Mantid.
+*/
+void IndirectDataReduction::setIDFValues(const QString & prefix)
+{
+  dynamic_cast<IndirectConvertToEnergy *>(m_tab_convert_to_energy)->setIDFValues(prefix);
+}
+
+/**
+* This function holds any steps that must be performed on the layout that are specific
+* to the currently selected instrument.
+*/
+void IndirectDataReduction::performInstSpecific()
+{
+  setInstSpecificWidget("cm-1-convert-choice", m_uiForm.ckCm1Units, QCheckBox::Off);
+  setInstSpecificWidget("save-aclimax-choice", m_uiForm.save_ckAclimax, QCheckBox::Off);
+}
+
+/**
+* This function either shows or hides the given QCheckBox, based on the named property
+* inside the instrument param file.  When hidden, the default state will be used to
+* reset to the "unused" state of the checkbox.
+*
+* @param parameterName :: The name of the property to look for inside the current inst param file.
+* @param checkBox :: The checkbox to set the state of, and to either hide or show based on the current inst.
+* @param defaultState :: The state to which the checkbox will be set upon hiding it.
+*/
+void IndirectDataReduction::setInstSpecificWidget(const std::string & parameterName, QCheckBox * checkBox, QCheckBox::ToggleState defaultState)
+{
+  // Get access to instrument specific parameters via the loaded empty workspace.
+  std::string instName = m_uiForm.cbInst->currentText().toStdString();
+  Mantid::API::MatrixWorkspace_sptr input = boost::dynamic_pointer_cast<Mantid::API::MatrixWorkspace>(Mantid::API::AnalysisDataService::Instance().retrieve("__empty_" + instName));
+  if(input == NULL)
+    return;
+
+  Mantid::Geometry::Instrument_const_sptr instr = input->getInstrument();
+
+  // See if the instrument params file requests that the checkbox be shown to the user.
+  std::vector<std::string> showParams = instr->getStringParameter(parameterName);
+  
+  std::string show = "";
+  if(!showParams.empty())
+    show = showParams[0];
+  
+  if(show == "Show")
+    checkBox->setHidden(false);
+  else
+  {
+    checkBox->setHidden(true);
+    checkBox->setState(defaultState);
+  }
+}
+
+void IndirectDataReduction::closeEvent(QCloseEvent* close)
+{
+  (void) close;
+  Mantid::Kernel::ConfigService::Instance().removeObserver(m_changeObserver);
+}
+
+void IndirectDataReduction::handleDirectoryChange(Mantid::Kernel::ConfigValChangeNotification_ptr pNf)
+{
+  std::string key = pNf->key();
+
+  if ( key == "datasearch.directories" || key == "defaultsave.directory" )
+  {
+    loadSettings();
+  }
+}
+
+void IndirectDataReduction::loadSettings()
+{  
+  // set values of m_dataDir and m_saveDir
+  m_dataDir = QString::fromStdString(Mantid::Kernel::ConfigService::Instance().getString("datasearch.directories"));
+  m_dataDir.replace(" ","");
+  if(m_dataDir.length() > 0)
+    m_dataDir = m_dataDir.split(";", QString::SkipEmptyParts)[0];
+  m_saveDir = QString::fromStdString(Mantid::Kernel::ConfigService::Instance().getString("defaultsave.directory"));
+  
+  QSettings settings;
+  // Load settings for MWRunFile widgets
+  settings.beginGroup(m_settingsGroup + "DataFiles");
+  settings.setValue("last_directory", m_dataDir);
+  m_uiForm.ind_runFiles->readSettings(settings.group());
+  m_uiForm.cal_leRunNo->readSettings(settings.group());
+  m_uiForm.slice_inputFile->readSettings(settings.group());
+  settings.endGroup();
+
+  settings.beginGroup(m_settingsGroup + "ProcessedFiles");
+  settings.setValue("last_directory", m_saveDir);
+  m_uiForm.ind_calibFile->readSettings(settings.group());
+  m_uiForm.ind_mapFile->readSettings(settings.group());
+  m_uiForm.slice_calibFile->readSettings(settings.group());
+  m_uiForm.moment_dsInput->readSettings(settings.group());
+  m_uiForm.transInputFile->readSettings(settings.group());
+  m_uiForm.transCanFile->readSettings(settings.group());
+  m_uiForm.sqw_dsSampleInput->readSettings(settings.group());
+  settings.endGroup();
+}
+
+/**
+ * Slot to wrap the protected showInformationBox method defined
+ * in UserSubWindow and provide access to composed tabs.
+ * 
+ * @param message :: The message to display in the message box
+ */
+void IndirectDataReduction::showMessageBox(const QString& message)
+{
+  showInformationBox(message);
+}
diff --git a/Code/Mantid/MantidQt/CustomInterfaces/src/IndirectDataReductionTab.cpp b/Code/Mantid/MantidQt/CustomInterfaces/src/IndirectDataReductionTab.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..69d8d3a5a5b1978e56bc6451624422a427398499
--- /dev/null
+++ b/Code/Mantid/MantidQt/CustomInterfaces/src/IndirectDataReductionTab.cpp
@@ -0,0 +1,309 @@
+#include "MantidQtCustomInterfaces/IndirectDataReductionTab.h"
+
+#include "MantidKernel/Logger.h"
+
+namespace
+{
+  Mantid::Kernel::Logger g_log("IndirectDataReductionTab");
+}
+
+namespace MantidQt
+{
+namespace CustomInterfaces
+{
+  //----------------------------------------------------------------------------------------------
+  /** Constructor
+   */
+  IndirectDataReductionTab::IndirectDataReductionTab(Ui::IndirectDataReduction& uiForm, QObject* parent) : QObject(parent),
+      m_plots(), m_curves(), m_rangeSelectors(),
+      m_properties(),
+      m_dblManager(new QtDoublePropertyManager()), m_blnManager(new QtBoolPropertyManager()), m_grpManager(new QtGroupPropertyManager()),
+      m_dblEdFac(new DoubleEditorFactory()),
+      m_uiForm(uiForm)
+  {
+    m_parentWidget = dynamic_cast<QWidget *>(parent);
+
+    m_algRunner = new MantidQt::API::AlgorithmRunner(m_parentWidget);
+    m_valInt = new QIntValidator(m_parentWidget);
+    m_valDbl = new QDoubleValidator(m_parentWidget);
+    m_valPosDbl = new QDoubleValidator(m_parentWidget);
+
+    const double tolerance = 0.00001;
+    m_valPosDbl->setBottom(tolerance);
+
+    QObject::connect(m_algRunner, SIGNAL(algorithmComplete(bool)), this, SLOT(algorithmFinished(bool)));
+    connect(&m_pythonRunner, SIGNAL(runAsPythonScript(const QString&, bool)), this, SIGNAL(runAsPythonScript(const QString&, bool)));
+  }
+
+  //----------------------------------------------------------------------------------------------
+  /** Destructor
+   */
+  IndirectDataReductionTab::~IndirectDataReductionTab()
+  {
+  }
+  
+  void IndirectDataReductionTab::runTab()
+  {
+    if(validate())
+    {
+      run();
+    }
+    else
+    {
+      g_log.warning("Failed to validate indirect tab input!");
+    }
+  }
+
+  void IndirectDataReductionTab::setupTab()
+  {
+    setup();
+  }
+
+  void IndirectDataReductionTab::validateTab()
+  {
+    validate();
+  }
+
+  /**
+   * Run the load algorithm with the supplied filename
+   * 
+   * @param filename :: The name of the file to load
+   * @param outputName :: The name of the output workspace
+   * @return If the algorithm was successful
+   */
+  bool IndirectDataReductionTab::loadFile(const QString& filename, const QString& outputName)
+  {
+    using namespace Mantid::API;
+
+    Algorithm_sptr load = AlgorithmManager::Instance().createUnmanaged("Load", -1);
+    load->initialize();
+    load->setProperty("Filename", filename.toStdString());
+    load->setProperty("OutputWorkspace", outputName.toStdString());
+    load->execute();
+    
+    //If reloading fails we're out of options
+    return load->isExecuted();
+  }
+
+  /**
+   * Gets details for the current indtrument configuration defined in Convert To Energy tab
+   *
+   * @return :: Map of information ID to value
+   */
+  std::map<QString, QString> IndirectDataReductionTab::getInstrumentDetails()
+  {
+    std::map<QString, QString> instDetails;
+    
+    QString pyInput =
+      "from IndirectEnergyConversion import getReflectionDetails\n"
+      "instrument = '" + m_uiForm.cbInst->currentText() + "'\n"
+      "analyser = '" + m_uiForm.cbAnalyser->currentText() + "'\n"
+      "reflection = '" + m_uiForm.cbReflection->currentText() + "'\n"
+      "print getReflectionDetails(instrument, analyser, reflection)\n";
+
+    QString pyOutput = m_pythonRunner.runPythonCode(pyInput).trimmed();
+
+    QStringList values = pyOutput.split("\n", QString::SkipEmptyParts);
+
+    if(values.count() > 3)
+    {
+      instDetails["AnalysisType"] = values[0];
+      instDetails["SpectraMin"] = values[1];
+      instDetails["SpectraMax"] = values[2];
+
+      if(values.count() >= 8)
+      {
+        instDetails["EFixed"] = values[3];
+        instDetails["PeakMin"] = values[4];
+        instDetails["PeakMax"] = values[5];
+        instDetails["BackMin"] = values[6];
+        instDetails["BackMax"] = values[7];
+      }
+
+      if(values.count() >= 9)
+      {
+        instDetails["RebinString"] = values[8];
+      }
+    }
+
+    return instDetails;
+  }
+
+  /**
+   * Gets the range of the curve plotted in the mini plot
+   *
+   * @param curveID :: The string index of the curve in the m_curves map
+   * @return A pair containing the maximum and minimum points of the curve
+   */
+  std::pair<double,double> IndirectDataReductionTab::getCurveRange(const QString& curveID)
+  {
+    size_t npts = m_curves[curveID]->data().size();
+
+    if( npts < 2 )
+      throw std::invalid_argument("Too few points on data curve to determine range.");
+
+    return std::make_pair(m_curves[curveID]->data().x(0), m_curves[curveID]->data().x(npts-1));
+  }
+
+  /**
+   * Set the range of an axis on a miniplot
+   *
+   * @param plotID :: Index of plot in m_plots map
+   * @param axis :: ID of axis to set range of
+   * @param range :: Pair of double values specifying range
+   */
+  void IndirectDataReductionTab::setAxisRange(const QString& plotID, QwtPlot::Axis axis,
+      std::pair<double, double> range)
+  {
+    m_plots[plotID]->setAxisScale(axis, range.first, range.second);
+  }
+
+  /**
+   * Sets the X axis of a plot to match the range of x values on a curve
+   *
+   * @param plotID :: Index of plot in m_plots map
+   * @param curveID :: Index of curve in m_curves map
+   */
+  void IndirectDataReductionTab::setXAxisToCurve(const QString& plotID, const QString& curveID)
+  {
+    auto range = getCurveRange(curveID);
+    setAxisRange(plotID, QwtPlot::xBottom, range);
+  }
+
+  /**
+   * Plot a workspace to the miniplot given a workspace name and
+   * a specturm index.
+   *
+   * This method uses the analysis data service to retrieve the workspace.
+   * 
+   * @param workspace :: The name of the workspace
+   * @param index :: The spectrum index of the workspace
+   * @param plotID :: String index of the plot in the m_plots map
+   * @param curveID :: String index of the curve in the m_curves map, defaults to plot ID
+   */
+  void IndirectDataReductionTab::plotMiniPlot(const QString& workspace, size_t index,
+      const QString& plotID, const QString& curveID)
+  {
+    using namespace Mantid::API;
+    auto ws = AnalysisDataService::Instance().retrieveWS<const MatrixWorkspace>(workspace.toStdString());
+    plotMiniPlot(ws, index, plotID, curveID);
+  }
+
+  /**
+   * Replot a given mini plot
+   *
+   * @param plotID :: ID of plot in m_plots map
+   */
+  void IndirectDataReductionTab::replot(const QString& plotID)
+  {
+    m_plots[plotID]->replot();
+  }
+
+  /**
+   * Plot a workspace to the miniplot given a workspace pointer and
+   * a specturm index.
+   * 
+   * @param workspace :: Pointer to the workspace
+   * @param wsIndex :: The spectrum index of the workspace
+   * @param plotID :: String index of the plot in the m_plots map
+   * @param curveID :: String index of the curve in the m_curves map, defaults to plot ID
+   */
+  void IndirectDataReductionTab::plotMiniPlot(const Mantid::API::MatrixWorkspace_const_sptr & workspace, size_t wsIndex,
+      const QString& plotID, const QString& curveID)
+  {
+    using Mantid::MantidVec;
+
+    QString cID = curveID;
+    if(cID == "")
+      cID = plotID;
+
+    //check if we can plot
+    if( wsIndex >= workspace->getNumberHistograms() || workspace->readX(0).size() < 2 )
+      return;
+
+    QwtWorkspaceSpectrumData wsData(*workspace, static_cast<int>(wsIndex), false);
+
+    if ( m_curves[cID] != NULL )
+    {
+      m_curves[cID]->attach(0);
+      delete m_curves[cID];
+      m_curves[cID] = NULL;
+    }
+
+    size_t nhist = workspace->getNumberHistograms();
+    if ( wsIndex >= nhist )
+    {
+      emit showMessageBox("Error: Workspace index out of range.");
+    }
+    else
+    {
+      m_curves[cID] = new QwtPlotCurve();
+      m_curves[cID]->setData(wsData);
+      m_curves[cID]->attach(m_plots[plotID]);
+
+      m_plots[plotID]->replot();
+    }
+  }
+
+  /**
+   * Sets the edge bounds of plot to prevent the user inputting invalid values
+   * Also sets limits for range selector movement
+   * 
+   * @param rsID :: The string index of the range selector in the map m_rangeSelectors
+   * @param min :: The lower bound property in the property browser
+   * @param max :: The upper bound property in the property browser
+   * @param bounds :: The upper and lower bounds to be set
+   */
+  void IndirectDataReductionTab::setPlotRange(const QString& rsID, QtProperty* min, QtProperty* max,
+      const std::pair<double, double>& bounds)
+  {
+    m_dblManager->setMinimum(min, bounds.first);
+    m_dblManager->setMaximum(min, bounds.second);
+    m_dblManager->setMinimum(max, bounds.first);
+    m_dblManager->setMaximum(max, bounds.second);
+    m_rangeSelectors[rsID]->setRange(bounds.first, bounds.second);
+  }
+
+  /**
+   * Set the position of the guides on the mini plot
+   * 
+   * @param rsID :: The string index of the range selector in the map m_rangeSelectors
+   * @param lower :: The lower bound property in the property browser
+   * @param upper :: The upper bound property in the property browser
+   * @param bounds :: The upper and lower bounds to be set
+   */
+  void IndirectDataReductionTab::setMiniPlotGuides(const QString& rsID, QtProperty* lower, QtProperty* upper,
+      const std::pair<double, double>& bounds)
+  {
+    m_dblManager->setValue(lower, bounds.first);
+    m_dblManager->setValue(upper, bounds.second);
+    m_rangeSelectors[rsID]->setMinimum(bounds.first);
+    m_rangeSelectors[rsID]->setMaximum(bounds.second);
+  }
+
+  /**
+   * Runs an algorithm async
+   *
+   * @param algorithm :: The algorithm to be run
+   */
+  void IndirectDataReductionTab::runAlgorithm(const Mantid::API::IAlgorithm_sptr algorithm)
+  {
+    algorithm->setRethrows(true);
+    m_algRunner->startAlgorithm(algorithm);
+  }
+
+  /**
+   * Handles getting the results of an algorithm running async
+   *
+   * @param error :: True if execution failed, false otherwise
+   */
+  void IndirectDataReductionTab::algorithmFinished(bool error)
+  {
+    if(error)
+    {
+      emit showMessageBox("Error running SofQWMoments. \nSee results log for details.");
+    }
+  }
+
+} // namespace CustomInterfaces
+} // namespace Mantid
diff --git a/Code/Mantid/MantidQt/CustomInterfaces/src/IndirectDiagnostics.cpp b/Code/Mantid/MantidQt/CustomInterfaces/src/IndirectDiagnostics.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..74678ac23425fb5c023153398046d134c4569a76
--- /dev/null
+++ b/Code/Mantid/MantidQt/CustomInterfaces/src/IndirectDiagnostics.cpp
@@ -0,0 +1,339 @@
+#include "MantidQtCustomInterfaces/IndirectDiagnostics.h"
+
+#include "MantidAPI/MatrixWorkspace.h"
+#include "MantidKernel/Logger.h"
+#include "MantidQtCustomInterfaces/UserInputValidator.h"
+
+#include <QFileInfo>
+
+namespace
+{
+  Mantid::Kernel::Logger g_log("IndirectDiagnostics");
+}
+
+namespace MantidQt
+{
+namespace CustomInterfaces
+{
+  //----------------------------------------------------------------------------------------------
+  /** Constructor
+   */
+  IndirectDiagnostics::IndirectDiagnostics(Ui::IndirectDataReduction& uiForm, QWidget * parent) :
+      IndirectDataReductionTab(uiForm, parent)
+  {
+    // Property Tree
+    m_propTrees["SlicePropTree"] = new QtTreePropertyBrowser();
+    m_uiForm.slice_properties->addWidget(m_propTrees["SlicePropTree"]);
+
+    // Editor Factories
+    DoubleEditorFactory *doubleEditorFactory = new DoubleEditorFactory();
+    QtCheckBoxFactory *checkboxFactory = new QtCheckBoxFactory();
+    m_propTrees["SlicePropTree"]->setFactoryForManager(m_dblManager, doubleEditorFactory);
+    m_propTrees["SlicePropTree"]->setFactoryForManager(m_blnManager, checkboxFactory);
+
+    // Create Properties
+    m_properties["SpecMin"] = m_dblManager->addProperty("Spectra Min");
+    m_properties["SpecMax"] = m_dblManager->addProperty("Spectra Max");
+
+    m_dblManager->setDecimals(m_properties["SpecMin"], 0);
+    m_dblManager->setMinimum(m_properties["SpecMin"], 1);
+    m_dblManager->setDecimals(m_properties["SpecMax"], 0);
+
+    m_properties["PeakStart"] = m_dblManager->addProperty("Start");
+    m_properties["PeakEnd"] = m_dblManager->addProperty("End");
+
+    m_properties["BackgroundStart"] = m_dblManager->addProperty("Start");
+    m_properties["BackgroundEnd"] = m_dblManager->addProperty("End");
+
+    m_properties["UseTwoRanges"] = m_blnManager->addProperty("Use Two Ranges");
+
+    m_properties["Range1"] = m_grpManager->addProperty("Peak");
+    m_properties["Range1"]->addSubProperty(m_properties["PeakStart"]);
+    m_properties["Range1"]->addSubProperty(m_properties["PeakEnd"]);
+
+    m_properties["Range2"] = m_grpManager->addProperty("Background");
+    m_properties["Range2"]->addSubProperty(m_properties["BackgroundStart"]);
+    m_properties["Range2"]->addSubProperty(m_properties["BackgroundEnd"]);
+
+    m_propTrees["SlicePropTree"]->addProperty(m_properties["SpecMin"]);
+    m_propTrees["SlicePropTree"]->addProperty(m_properties["SpecMax"]);
+    m_propTrees["SlicePropTree"]->addProperty(m_properties["Range1"]);
+    m_propTrees["SlicePropTree"]->addProperty(m_properties["UseTwoRanges"]);
+    m_propTrees["SlicePropTree"]->addProperty(m_properties["Range2"]);
+
+    // Slice plot
+    m_plots["SlicePlot"] = new QwtPlot(m_parentWidget);
+    m_curves["SlicePlot"] = new QwtPlotCurve();
+    m_rangeSelectors["SlicePeak"] = new MantidWidgets::RangeSelector(m_plots["SlicePlot"]);
+    m_rangeSelectors["SliceBackground"] = new MantidWidgets::RangeSelector(m_plots["SlicePlot"]);
+
+    m_plots["SlicePlot"]->setAxisFont(QwtPlot::xBottom, parent->font());
+    m_plots["SlicePlot"]->setAxisFont(QwtPlot::yLeft, parent->font());
+    m_plots["SlicePlot"]->setCanvasBackground(Qt::white);
+    m_uiForm.slice_plot->addWidget(m_plots["SlicePlot"]);
+
+    // Setup second range
+    m_rangeSelectors["SliceBackground"]->setColour(Qt::darkGreen); // Dark green for background
+    m_rangeSelectors["SliceBackground"]->setRange(m_rangeSelectors["SlicePeak"]->getRange());
+
+    // Refresh the plot window
+    m_plots["SlicePlot"]->replot();
+
+    // SIGNAL/SLOT CONNECTIONS
+    /* connect(m_rangeSelectors["SlicePeak"], SIGNAL(rangeChanged(double, double)), m_rangeSelectors["SliceBackground"], SLOT(setRange(double, double))); */
+
+    // Update properties when a range selector is changed
+    connect(m_rangeSelectors["SlicePeak"], SIGNAL(minValueChanged(double)), this, SLOT(sliceMinChanged(double)));
+    connect(m_rangeSelectors["SlicePeak"], SIGNAL(maxValueChanged(double)), this, SLOT(sliceMaxChanged(double)));
+    connect(m_rangeSelectors["SliceBackground"], SIGNAL(minValueChanged(double)), this, SLOT(sliceMinChanged(double)));
+    connect(m_rangeSelectors["SliceBackground"], SIGNAL(maxValueChanged(double)), this, SLOT(sliceMaxChanged(double)));
+    // Update range seelctors when a property is changed
+    connect(m_dblManager, SIGNAL(valueChanged(QtProperty*, double)), this, SLOT(sliceUpdateRS(QtProperty*, double)));
+    // Enable/disable second range options when checkbox is toggled
+    connect(m_blnManager, SIGNAL(valueChanged(QtProperty*, bool)), this, SLOT(sliceTwoRanges(QtProperty*, bool)));
+    // Plot slice miniplot when file has finished loading
+    connect(m_uiForm.slice_inputFile, SIGNAL(filesFound()), this, SLOT(slicePlotRaw()));
+    // Plot slice miniplot when user clicks Plot Raw
+    connect(m_uiForm.slice_pbPlotRaw, SIGNAL(clicked()), this, SLOT(slicePlotRaw()));
+    // Enables/disables calibration file selection when user toggles Use Calibratin File checkbox
+    connect(m_uiForm.slice_ckUseCalib, SIGNAL(toggled(bool)), this, SLOT(sliceCalib(bool)));
+
+    // Set default UI state
+    sliceTwoRanges(0, false);
+  }
+    
+  //----------------------------------------------------------------------------------------------
+  /** Destructor
+   */
+  IndirectDiagnostics::~IndirectDiagnostics()
+  {
+  }
+  
+  void IndirectDiagnostics::setup()
+  {
+  }
+
+  void IndirectDiagnostics::run()
+  {
+    QString pyInput =
+      "from IndirectEnergyConversion import slice\n"
+      "tofRange = [" + QString::number(m_dblManager->value(m_properties["PeakStart"])) + ","
+      + QString::number(m_dblManager->value(m_properties["PeakEnd"]));
+    if ( m_blnManager->value(m_properties["UseTwoRanges"]) )
+    {
+      pyInput +=
+        "," + QString::number(m_dblManager->value(m_properties["BackgroundStart"])) + ","
+        + QString::number(m_dblManager->value(m_properties["BackgroundEnd"])) + "]\n";
+    }
+    else
+    {
+      pyInput += "]\n";
+    }
+    if ( m_uiForm.slice_ckUseCalib->isChecked() )
+    {
+      pyInput +=
+        "calib = r'" + m_uiForm.slice_calibFile->getFirstFilename() + "'\n";
+    }
+    else
+    {
+      pyInput +=
+        "calib = ''\n";
+    }
+    QString filenames = m_uiForm.slice_inputFile->getFilenames().join("', r'");
+    QString suffix = m_uiForm.cbAnalyser->currentText() + m_uiForm.cbReflection->currentText();
+    pyInput +=
+      "rawfile = [r'" + filenames + "']\n"
+      "spectra = ["+ QString::number(m_dblManager->value(m_properties["SpecMin"])) + "," + QString::number(m_dblManager->value(m_properties["SpecMax"])) +"]\n"
+      "suffix = '" + suffix + "'\n";
+
+    if(m_uiForm.slice_ckVerbose->isChecked())
+      pyInput += "verbose = True\n";
+    else
+      pyInput += "verbose = False\n";
+
+    if(m_uiForm.slice_ckPlot->isChecked())
+      pyInput += "plot = True\n";
+    else
+      pyInput += "plot = False\n";
+
+    if(m_uiForm.slice_ckSave->isChecked())
+      pyInput += "save = True\n";
+    else
+      pyInput += "save = False\n";
+
+    pyInput +=
+      "slice(rawfile, calib, tofRange, spectra, suffix, Save=save, Verbose=verbose, Plot=plot)";
+
+    QString pyOutput = m_pythonRunner.runPythonCode(pyInput).trimmed();
+  }
+
+  bool IndirectDiagnostics::validate()
+  {
+    UserInputValidator uiv;
+
+    uiv.checkMWRunFilesIsValid("Input", m_uiForm.slice_inputFile);
+    if( m_uiForm.slice_ckUseCalib->isChecked() )
+      uiv.checkMWRunFilesIsValid("Calibration", m_uiForm.slice_inputFile);
+
+    auto rangeOne = std::make_pair(m_dblManager->value(m_properties["PeakStart"]), m_dblManager->value(m_properties["PeakEnd"]));
+    uiv.checkValidRange("Range One", rangeOne);
+
+    bool useTwoRanges = m_blnManager->value(m_properties["UseTwoRanges"]);
+    if( useTwoRanges )
+    {
+      auto rangeTwo = std::make_pair(m_dblManager->value(m_properties["BackgroundStart"]), m_dblManager->value(m_properties["BackgroundEnd"]));
+      uiv.checkValidRange("Range Two", rangeTwo);
+
+      uiv.checkRangesDontOverlap(rangeOne, rangeTwo);
+    }
+
+    auto specRange = std::make_pair(m_dblManager->value(m_properties["SpecMin"]), m_dblManager->value(m_properties["SpecMax"]));
+    uiv.checkValidRange("Spectra Range", specRange);
+
+    QString error = uiv.generateErrorMessage();
+
+    if(error != "")
+      g_log.warning(error.toStdString());
+
+    return (error == "");
+  }
+
+  /**
+   * Sets default spectra, peak and background ranges
+   */
+  void IndirectDiagnostics::setDefaultInstDetails()
+  {
+    //Get spectra, peak and background details
+    std::map<QString, QString> instDetails = getInstrumentDetails();
+
+    //Set spectra range
+    m_dblManager->setValue(m_properties["SpecMin"], instDetails["SpectraMin"].toDouble());
+    m_dblManager->setValue(m_properties["SpecMax"], instDetails["SpectraMax"].toDouble());
+
+    //Set peak and background ranges
+    if(instDetails.size() >= 8)
+    {
+      setMiniPlotGuides("SlicePeak", m_properties["PeakStart"], m_properties["PeakEnd"],
+          std::pair<double, double>(instDetails["PeakMin"].toDouble(), instDetails["PeakMax"].toDouble()));
+      setMiniPlotGuides("SliceBackground", m_properties["BackStart"], m_properties["BackEnd"],
+          std::pair<double, double>(instDetails["BackMin"].toDouble(), instDetails["BackMax"].toDouble()));
+    }
+  }
+
+  /**
+   * Redraw the raw input plot
+   */
+  void IndirectDiagnostics::slicePlotRaw()
+  {
+    setDefaultInstDetails();
+
+    if ( m_uiForm.slice_inputFile->isValid() )
+    {
+      QString filename = m_uiForm.slice_inputFile->getFirstFilename();
+      QFileInfo fi(filename);
+      QString wsname = fi.baseName();
+
+      QString pyInput = "Load(Filename=r'" + filename + "', OutputWorkspace='" + wsname + "', SpectrumMin="
+        + m_uiForm.leSpectraMin->text() + ", SpectrumMax="
+        + m_uiForm.leSpectraMax->text() + ")\n";
+
+      pyInput = "try:\n  " +
+        pyInput +
+        "except ValueError as ve:" +
+        "  print str(ve)";
+
+      QString pyOutput = m_pythonRunner.runPythonCode(pyInput);
+
+      if( ! pyOutput.isEmpty() )
+      {
+        emit showMessageBox("Unable to load file: \n\n\"" + pyOutput + "\".\n\nCheck whether your file exists and matches the selected instrument in the EnergyTransfer tab.");
+        return;
+      }
+
+      Mantid::API::MatrixWorkspace_sptr input = boost::dynamic_pointer_cast<Mantid::API::MatrixWorkspace>(
+          Mantid::API::AnalysisDataService::Instance().retrieve(wsname.toStdString()));
+
+      const Mantid::MantidVec & dataX = input->readX(0);
+      std::pair<double, double> range(dataX.front(), dataX.back());
+
+      plotMiniPlot(input, 0, "SlicePlot");
+      setXAxisToCurve("SlicePlot", "SlicePlot");
+
+      setPlotRange("SlicePeak", m_properties["PeakStart"], m_properties["PeakEnd"], range);
+      setPlotRange("SliceBackground", m_properties["BackgroundStart"], m_properties["BackgroundEnd"], range);
+
+      replot("SlicePlot");
+    }
+    else
+    {
+      emit showMessageBox("Selected input files are invalid.");
+    }
+  }
+
+  /**
+   * Set if the second slice range selectors should be shown on the plot
+   *
+   * @param state :: True to show the second range selectors, false to hide
+   */
+  void IndirectDiagnostics::sliceTwoRanges(QtProperty*, bool state)
+  {
+    m_rangeSelectors["SliceBackground"]->setVisible(state);
+  }
+
+  /**
+   * Enables/disables the calibration file field and validator
+   *
+   * @param state :: True to enable calibration file, false otherwise
+   */
+  void IndirectDiagnostics::sliceCalib(bool state)
+  {
+    m_uiForm.slice_calibFile->setEnabled(state);
+    m_uiForm.slice_calibFile->isOptional(!state);
+  }
+
+  /**
+   * Handles the value of a range selector minimum value being changed
+   *
+   * @param val :: New minimum value
+   */
+  void IndirectDiagnostics::sliceMinChanged(double val)
+  {
+    MantidWidgets::RangeSelector* from = qobject_cast<MantidWidgets::RangeSelector*>(sender());
+
+    if ( from == m_rangeSelectors["SlicePeak"] )
+      m_dblManager->setValue(m_properties["PeakStart"], val);
+    else if ( from == m_rangeSelectors["SliceBackground"] )
+      m_dblManager->setValue(m_properties["BackgroundStart"], val);
+  }
+
+  /**
+   * Handles the value of a range selector maximum value being changed
+   *
+   * @param val :: New maximum value
+   */
+  void IndirectDiagnostics::sliceMaxChanged(double val)
+  {
+    MantidWidgets::RangeSelector* from = qobject_cast<MantidWidgets::RangeSelector*>(sender());
+
+    if ( from == m_rangeSelectors["SlicePeak"] )
+      m_dblManager->setValue(m_properties["PeakEnd"], val);
+    else if ( from == m_rangeSelectors["SliceBackground"] )
+      m_dblManager->setValue(m_properties["BackgroundEnd"], val);
+  }
+
+  /**
+   * Update the value of a range selector given a QtProperty
+   *
+   * @param prop :: Pointer to the QtProperty
+   * @param val :: New value of the range selector
+   */
+  void IndirectDiagnostics::sliceUpdateRS(QtProperty* prop, double val)
+  {
+    if ( prop == m_properties["PeakStart"] )      m_rangeSelectors["SlicePeak"]->setMinimum(val);
+    else if ( prop == m_properties["PeakEnd"] ) m_rangeSelectors["SlicePeak"]->setMaximum(val);
+    else if ( prop == m_properties["BackgroundStart"] ) m_rangeSelectors["SliceBackground"]->setMinimum(val);
+    else if ( prop == m_properties["BackgroundEnd"] ) m_rangeSelectors["SliceBackground"]->setMaximum(val);
+  }
+
+} // namespace CustomInterfaces
+} // namespace Mantid
diff --git a/Code/Mantid/MantidQt/CustomInterfaces/src/IndirectMoments.cpp b/Code/Mantid/MantidQt/CustomInterfaces/src/IndirectMoments.cpp
index e549deca7bd8039d6290bf3dabd4d5ce76938fc9..36fd92e82a3103f2cdd2df5424217457ee0fdeb6 100644
--- a/Code/Mantid/MantidQt/CustomInterfaces/src/IndirectMoments.cpp
+++ b/Code/Mantid/MantidQt/CustomInterfaces/src/IndirectMoments.cpp
@@ -1,8 +1,9 @@
 #include "MantidQtCustomInterfaces/IndirectMoments.h"
+
 #include "MantidQtCustomInterfaces/UserInputValidator.h"
 
-#include <QFileInfo>
 #include <QDoubleValidator>
+#include <QFileInfo>
 
 namespace MantidQt
 {
@@ -12,27 +13,32 @@ namespace CustomInterfaces
   //----------------------------------------------------------------------------------------------
   /** Constructor
    */
-  IndirectMoments::IndirectMoments(Ui::ConvertToEnergy& uiForm, QWidget * parent) : C2ETab(uiForm, parent)
+  IndirectMoments::IndirectMoments(Ui::IndirectDataReduction& uiForm, QWidget * parent) : IndirectDataReductionTab(uiForm, parent)
   {
     const unsigned int NUM_DECIMALS = 6;
 
-    m_propTree->setFactoryForManager(m_dblManager, m_dblEdFac);
-    m_rangeSelector->setInfoOnly(false);
+    m_plots["MomentsPlot"] = new QwtPlot(m_parentWidget);
+    m_curves["MomentsPlotCurve"] = new QwtPlotCurve();
+    m_rangeSelectors["MomentsRangeSelector"] = new MantidWidgets::RangeSelector(m_plots["MomentsPlot"]);
+    m_propTrees["MomentsPropTree"] = new QtTreePropertyBrowser();
+
+    m_propTrees["MomentsPropTree"]->setFactoryForManager(m_dblManager, m_dblEdFac);
+    m_rangeSelectors["MomentsRangeSelector"]->setInfoOnly(false);
 
     // initilise plot
-    m_plot->setCanvasBackground(Qt::white);
-    m_plot->setAxisFont(QwtPlot::xBottom, parent->font());
-    m_plot->setAxisFont(QwtPlot::yLeft, parent->font());
+    m_plots["MomentsPlot"]->setCanvasBackground(Qt::white);
+    m_plots["MomentsPlot"]->setAxisFont(QwtPlot::xBottom, parent->font());
+    m_plots["MomentsPlot"]->setAxisFont(QwtPlot::yLeft, parent->font());
 
     //add the plot to the ui form
-    m_uiForm.moment_plotSpace->addWidget(m_plot);
+    m_uiForm.moment_plotSpace->addWidget(m_plots["MomentsPlot"]);
     //add the properties browser to the ui form
-    m_uiForm.moment_treeSpace->addWidget(m_propTree);
+    m_uiForm.moment_treeSpace->addWidget(m_propTrees["MomentsPropTree"]);
     m_properties["EMin"] = m_dblManager->addProperty("EMin");
     m_properties["EMax"] = m_dblManager->addProperty("EMax");
 
-    m_propTree->addProperty(m_properties["EMin"]);
-    m_propTree->addProperty(m_properties["EMax"]);
+    m_propTrees["MomentsPropTree"]->addProperty(m_properties["EMin"]);
+    m_propTrees["MomentsPropTree"]->addProperty(m_properties["EMax"]);
 
     m_dblManager->setDecimals(m_properties["EMin"], NUM_DECIMALS);
     m_dblManager->setDecimals(m_properties["EMax"], NUM_DECIMALS);
@@ -43,8 +49,8 @@ namespace CustomInterfaces
     connect(m_uiForm.moment_ckScale, SIGNAL(toggled(bool)), m_uiForm.moment_leScale, SLOT(setEnabled(bool)));
     connect(m_uiForm.moment_ckScale, SIGNAL(toggled(bool)), m_uiForm.moment_validScale, SLOT(setVisible(bool)));
     
-    connect(m_rangeSelector, SIGNAL(minValueChanged(double)), this, SLOT(minValueChanged(double)));
-    connect(m_rangeSelector, SIGNAL(maxValueChanged(double)), this, SLOT(maxValueChanged(double)));
+    connect(m_rangeSelectors["MomentsRangeSelector"], SIGNAL(minValueChanged(double)), this, SLOT(minValueChanged(double)));
+    connect(m_rangeSelectors["MomentsRangeSelector"], SIGNAL(maxValueChanged(double)), this, SLOT(maxValueChanged(double)));
     connect(m_dblManager, SIGNAL(valueChanged(QtProperty*, double)), this, SLOT(updateProperties(QtProperty*, double)));
 
     m_uiForm.moment_validScale->setStyleSheet("QLabel { color : #aa0000; }");
@@ -55,10 +61,11 @@ namespace CustomInterfaces
    */
   IndirectMoments::~IndirectMoments()
   {
-
   }
   
-  void IndirectMoments::setup() {}
+  void IndirectMoments::setup()
+  {
+  }
 
   void IndirectMoments::run()
   {
@@ -79,7 +86,7 @@ namespace CustomInterfaces
       scale = scaleString.toDouble();
     }
 
-    Algorithm_sptr momentsAlg = AlgorithmManager::Instance().createUnmanaged("SofQWMoments", -1);
+    IAlgorithm_sptr momentsAlg = AlgorithmManager::Instance().create("SofQWMoments", -1);
     momentsAlg->initialize();
     momentsAlg->setProperty("Sample", workspaceName.toStdString());
     momentsAlg->setProperty("Scale", scale);
@@ -118,10 +125,10 @@ namespace CustomInterfaces
 
   void IndirectMoments::handleSampleInputReady(const QString& filename)
   {
-    plotMiniPlot(filename, 0);
-    std::pair<double,double> range = getCurveRange();
-    setMiniPlotGuides(m_properties["EMin"], m_properties["EMax"], range);
-    setPlotRange(m_properties["EMin"], m_properties["EMax"], range);
+    plotMiniPlot(filename, 0, "MomentsPlot", "MomentsPlotCurve");
+    std::pair<double,double> range = getCurveRange("MomentsPlotCurve");
+    setMiniPlotGuides("MomentsRangeSelector", m_properties["EMin"], m_properties["EMax"], range);
+    setPlotRange("MomentsRangeSelector", m_properties["EMin"], m_properties["EMax"], range);
   }
 
   /**
@@ -161,7 +168,7 @@ namespace CustomInterfaces
       }
       else 
       {
-        m_rangeSelector->setMinimum(val);
+        m_rangeSelectors["MomentsRangeSelector"]->setMinimum(val);
       }
     }
     else if (prop == m_properties["EMax"])
@@ -173,9 +180,10 @@ namespace CustomInterfaces
       }
       else 
       {
-        m_rangeSelector->setMaximum(val);
+        m_rangeSelectors["MomentsRangeSelector"]->setMaximum(val);
       }
     }
   }
+
 } // namespace CustomInterfaces
 } // namespace Mantid
diff --git a/Code/Mantid/MantidQt/CustomInterfaces/src/IndirectSqw.cpp b/Code/Mantid/MantidQt/CustomInterfaces/src/IndirectSqw.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..3b5231bad1434a827a851a96ff1f5e1d763f6c11
--- /dev/null
+++ b/Code/Mantid/MantidQt/CustomInterfaces/src/IndirectSqw.cpp
@@ -0,0 +1,246 @@
+#include "MantidQtCustomInterfaces/IndirectSqw.h"
+
+#include "MantidQtCustomInterfaces/UserInputValidator.h"
+
+namespace MantidQt
+{
+namespace CustomInterfaces
+{
+  //----------------------------------------------------------------------------------------------
+  /** Constructor
+   */
+  IndirectSqw::IndirectSqw(Ui::IndirectDataReduction& uiForm, QWidget * parent) :
+      IndirectDataReductionTab(uiForm, parent)
+  {
+    connect(m_uiForm.sqw_ckRebinE, SIGNAL(toggled(bool)), this, SLOT(sOfQwRebinE(bool)));
+    connect(m_uiForm.sqw_dsSampleInput, SIGNAL(loadClicked()), this, SLOT(sOfQwPlotInput()));
+
+    m_uiForm.sqw_leELow->setValidator(m_valDbl);
+    m_uiForm.sqw_leEWidth->setValidator(m_valDbl);
+    m_uiForm.sqw_leEHigh->setValidator(m_valDbl);
+    m_uiForm.sqw_leQLow->setValidator(m_valDbl);
+    m_uiForm.sqw_leQWidth->setValidator(m_valDbl);
+    m_uiForm.sqw_leQHigh->setValidator(m_valDbl);
+  }
+    
+  //----------------------------------------------------------------------------------------------
+  /** Destructor
+   */
+  IndirectSqw::~IndirectSqw()
+  {
+  }
+  
+  void IndirectSqw::setup()
+  {
+  }
+
+  void IndirectSqw::run()
+  {
+    QString rebinString = m_uiForm.sqw_leQLow->text()+","+m_uiForm.sqw_leQWidth->text()+","+m_uiForm.sqw_leQHigh->text();
+    QString pyInput = "from mantid.simpleapi import *\n";
+
+    if(m_uiForm.sqw_dsSampleInput->isFileSelectorVisible())
+    {
+      //load the file
+      pyInput += "filename = r'" + m_uiForm.sqw_dsSampleInput->getFullFilePath() + "'\n"
+        "(dir, file) = os.path.split(filename)\n"
+        "(sqwInput, ext) = os.path.splitext(file)\n"
+        "LoadNexus(Filename=filename, OutputWorkspace=sqwInput)\n";
+    }
+    else
+    {
+      //get the workspace
+      pyInput += "sqwInput = '" + m_uiForm.sqw_dsSampleInput->getCurrentDataName() + "'\n";
+    }
+
+    // Create output name before rebinning
+    pyInput += "sqwOutput = sqwInput[:-3] + 'sqw'\n";
+
+    if ( m_uiForm.sqw_ckRebinE->isChecked() )
+    {
+      QString eRebinString = m_uiForm.sqw_leELow->text()+","+m_uiForm.sqw_leEWidth->text()+","+m_uiForm.sqw_leEHigh->text();
+      pyInput += "Rebin(InputWorkspace=sqwInput, OutputWorkspace=sqwInput+'_r', Params='" + eRebinString + "')\n"
+        "sqwInput += '_r'\n";
+    }
+    pyInput +=
+      "efixed = " + m_uiForm.leEfixed->text() + "\n"
+      "rebin = '" + rebinString + "'\n";
+
+    QString rebinType = m_uiForm.sqw_cbRebinType->currentText();
+    if(rebinType == "Centre (SofQW)")
+      pyInput += "SofQW(InputWorkspace=sqwInput, OutputWorkspace=sqwOutput, QAxisBinning=rebin, EMode='Indirect', EFixed=efixed)\n";
+    else if(rebinType == "Parallelepiped (SofQW2)")
+      pyInput += "SofQW2(InputWorkspace=sqwInput, OutputWorkspace=sqwOutput, QAxisBinning=rebin, EMode='Indirect', EFixed=efixed)\n";
+    else if(rebinType == "Parallelepiped/Fractional Area (SofQW3)")
+      pyInput += "SofQW3(InputWorkspace=sqwInput, OutputWorkspace=sqwOutput, QAxisBinning=rebin, EMode='Indirect', EFixed=efixed)\n";
+
+    pyInput += "AddSampleLog(Workspace=sqwOutput, LogName='rebin_type', LogType='String', LogText='"+rebinType+"')\n";
+
+    if ( m_uiForm.sqw_ckSave->isChecked() )
+    {
+      pyInput += "SaveNexus(InputWorkspace=sqwOutput, Filename=sqwOutput+'.nxs')\n";
+
+      if (m_uiForm.sqw_ckVerbose->isChecked())
+      {
+        pyInput += "logger.notice(\"Resolution file saved to default save directory.\")\n";
+      }
+    }
+
+    if ( m_uiForm.sqw_cbPlotType->currentText() == "Contour" )
+    {
+      pyInput += "importMatrixWorkspace(sqwOutput).plotGraph2D()\n";
+    }
+    else if ( m_uiForm.sqw_cbPlotType->currentText() == "Spectra" )
+    {
+      pyInput +=
+        "nspec = mtd[sqwOutput].getNumberHistograms()\n"
+        "plotSpectrum(sqwOutput, range(0, nspec))\n";
+    }
+
+    QString pyOutput = m_pythonRunner.runPythonCode(pyInput).trimmed();
+  }
+
+  bool IndirectSqw::validate()
+  {
+    bool valid = true;
+
+    UserInputValidator uiv;
+    uiv.checkDataSelectorIsValid("Sample", m_uiForm.sqw_dsSampleInput);
+    QString error = uiv.generateErrorMessage();
+
+    if (!error.isEmpty())
+    {
+      valid = false;
+      emit showMessageBox(error);
+    }
+
+    if ( m_uiForm.sqw_ckRebinE->isChecked() )
+    {
+      if ( m_uiForm.sqw_leELow->text() == "" )
+      {
+        valid = false;
+        m_uiForm.sqw_valELow->setText("*");
+      }
+      else
+      {
+        m_uiForm.sqw_valELow->setText(" ");
+      }
+
+      if ( m_uiForm.sqw_leEWidth->text() == "" )
+      {
+        valid = false;
+        m_uiForm.sqw_valEWidth->setText("*");
+      }
+      else
+      {
+        m_uiForm.sqw_valEWidth->setText(" ");
+      }
+
+      if ( m_uiForm.sqw_leEHigh->text() == "" )
+      {
+        valid = false;
+        m_uiForm.sqw_valEHigh->setText("*");
+      }
+      else
+      {
+        m_uiForm.sqw_valEHigh->setText(" ");
+      }
+    }
+
+    if ( m_uiForm.sqw_leQLow->text() == "" )
+    {
+      valid = false;
+      m_uiForm.sqw_valQLow->setText("*");
+    }
+    else
+    {
+      m_uiForm.sqw_valQLow->setText(" ");
+    }
+
+    if ( m_uiForm.sqw_leQWidth->text() == "" )
+    {
+      valid = false;
+      m_uiForm.sqw_valQWidth->setText("*");
+    }
+    else
+    {
+      m_uiForm.sqw_valQWidth->setText(" ");
+    }
+
+    if ( m_uiForm.sqw_leQHigh->text() == "" )
+    {
+      valid = false;
+      m_uiForm.sqw_valQHigh->setText("*");
+    }
+    else
+    {
+      m_uiForm.sqw_valQHigh->setText(" ");
+    }
+
+    return valid;
+  }
+
+  /**
+   * Enabled/disables the rebin in energy UI widgets
+   *
+   * @param state :: True to enable RiE UI, false to disable
+   */
+  void IndirectSqw::sOfQwRebinE(bool state)
+  {
+    QString val;
+    if ( state ) val = "*";
+    else val = " ";
+    m_uiForm.sqw_leELow->setEnabled(state);
+    m_uiForm.sqw_leEWidth->setEnabled(state);
+    m_uiForm.sqw_leEHigh->setEnabled(state);
+    m_uiForm.sqw_valELow->setEnabled(state);
+    m_uiForm.sqw_valELow->setText(val);
+    m_uiForm.sqw_valEWidth->setEnabled(state);
+    m_uiForm.sqw_valEWidth->setText(val);
+    m_uiForm.sqw_valEHigh->setEnabled(state);
+    m_uiForm.sqw_valEHigh->setText(val);
+    m_uiForm.sqw_lbELow->setEnabled(state);
+    m_uiForm.sqw_lbEWidth->setEnabled(state);
+    m_uiForm.sqw_lbEHigh->setEnabled(state);
+  }
+
+  /**
+   * Handles the Plot Input button
+   *
+   * Creates a colour 2D plot of the data
+   */
+  void IndirectSqw::sOfQwPlotInput()
+  {
+    QString pyInput = "from mantid.simpleapi import *\n"
+      "from mantidplot import *\n";
+
+    if (m_uiForm.sqw_dsSampleInput->isValid())
+    {
+      if(m_uiForm.sqw_dsSampleInput->isFileSelectorVisible())
+      {
+        //Load file into workspacwe
+        pyInput += "filename = r'" + m_uiForm.sqw_dsSampleInput->getFullFilePath() + "'\n"
+          "(dir, file) = os.path.split(filename)\n"
+          "(sqwInput, ext) = os.path.splitext(file)\n"
+          "LoadNexus(Filename=filename, OutputWorkspace=sqwInput)\n";
+      }
+      else
+      {
+        //Use existing workspace
+        pyInput += "sqwInput = '" + m_uiForm.sqw_dsSampleInput->getCurrentDataName() + "'\n";
+      }
+
+      pyInput += "ConvertSpectrumAxis(InputWorkspace=sqwInput, OutputWorkspace=sqwInput[:-4]+'_rqw', Target='ElasticQ', EMode='Indirect')\n"
+        "ws = importMatrixWorkspace(sqwInput[:-4]+'_rqw')\n"
+        "ws.plotGraph2D()\n";
+
+      QString pyOutput = m_pythonRunner.runPythonCode(pyInput).trimmed();
+    }
+    else
+    {
+      emit showMessageBox("Invalid filename.");
+    }
+  }
+
+} // namespace CustomInterfaces
+} // namespace Mantid
diff --git a/Code/Mantid/MantidQt/CustomInterfaces/src/Transmission.cpp b/Code/Mantid/MantidQt/CustomInterfaces/src/IndirectTransmission.cpp
similarity index 84%
rename from Code/Mantid/MantidQt/CustomInterfaces/src/Transmission.cpp
rename to Code/Mantid/MantidQt/CustomInterfaces/src/IndirectTransmission.cpp
index e1c6ccad0f9c0c6e5d543feb6d59287460ded423..2bd6e87b540b2b8963a6dc7e6d07dc1d0b8c55a3 100644
--- a/Code/Mantid/MantidQt/CustomInterfaces/src/Transmission.cpp
+++ b/Code/Mantid/MantidQt/CustomInterfaces/src/IndirectTransmission.cpp
@@ -1,4 +1,4 @@
-#include "MantidQtCustomInterfaces/Transmission.h"
+#include "MantidQtCustomInterfaces/IndirectTransmission.h"
 
 #include <QFileInfo>
 
@@ -10,24 +10,24 @@ namespace CustomInterfaces
   //----------------------------------------------------------------------------------------------
   /** Constructor
    */
-  Transmission::Transmission(Ui::ConvertToEnergy& uiForm, QWidget * parent) :
-      C2ETab(uiForm, parent)
+  IndirectTransmission::IndirectTransmission(Ui::IndirectDataReduction& uiForm, QWidget * parent) :
+      IndirectDataReductionTab(uiForm, parent)
   {
   }
     
   //----------------------------------------------------------------------------------------------
   /** Destructor
    */
-  Transmission::~Transmission()
+  IndirectTransmission::~IndirectTransmission()
   {
 
   }
   
-  void Transmission::setup()
+  void IndirectTransmission::setup()
   {
   }
 
-  void Transmission::run()
+  void IndirectTransmission::run()
   {
     QString sampleNo = m_uiForm.transInputFile->getFirstFilename();
     QString canNo = m_uiForm.transCanFile->getFirstFilename();
@@ -66,7 +66,7 @@ namespace CustomInterfaces
     emit runAsPythonScript(pyInput, true);
   }
 
-  bool Transmission::validate()
+  bool IndirectTransmission::validate()
   {
     QString currentInst = m_uiForm.cbInst->currentText();
 
diff --git a/Code/Mantid/MantidQt/CustomInterfaces/src/SANSAddFiles.cpp b/Code/Mantid/MantidQt/CustomInterfaces/src/SANSAddFiles.cpp
index e97ad25caad4553cd9fd9b034c23e2db70afcd69..c700e19be24d442298c6d0bb9f0708f12f96e6a4 100644
--- a/Code/Mantid/MantidQt/CustomInterfaces/src/SANSAddFiles.cpp
+++ b/Code/Mantid/MantidQt/CustomInterfaces/src/SANSAddFiles.cpp
@@ -276,8 +276,8 @@ void SANSAddFiles::runPythonAddFiles()
   code_torun += ext+"'";
   
   code_torun += ", rawTypes=(";
-  std::set<std::string>::const_iterator end = m_rawExts.end();
-  for(std::set<std::string>::const_iterator j=m_rawExts.begin(); j != end; ++j)
+  std::vector<std::string>::const_iterator end = m_rawExts.end();
+  for(std::vector<std::string>::const_iterator j=m_rawExts.begin(); j != end; ++j)
   {
     code_torun += "'"+QString::fromStdString(*j)+"',";
   }
@@ -339,8 +339,8 @@ void SANSAddFiles::new2AddBrowse()
   
 	QString fileFilter = "Files (";
 
-  std::set<std::string>::const_iterator end = m_exts.end();
-  for(std::set<std::string>::const_iterator i = m_exts.begin(); i != end; ++i)
+  std::vector<std::string>::const_iterator end = m_exts.end();
+  for(std::vector<std::string>::const_iterator i = m_exts.begin(); i != end; ++i)
   {
     fileFilter += " *"+QString::fromStdString(*i);
   }
diff --git a/Code/Mantid/MantidQt/CustomInterfaces/src/SANSRunWindow.cpp b/Code/Mantid/MantidQt/CustomInterfaces/src/SANSRunWindow.cpp
index a7d0606743db9d05154b67196cc51f72e9f2b764..dc2fff810eb0a24adc84c81dc69885664466c9fc 100644
--- a/Code/Mantid/MantidQt/CustomInterfaces/src/SANSRunWindow.cpp
+++ b/Code/Mantid/MantidQt/CustomInterfaces/src/SANSRunWindow.cpp
@@ -3443,7 +3443,7 @@ QStringList SANSRunWindow::getSaveAlgs()
  */
 void SANSRunWindow::handleMantidDeleteWorkspace(Mantid::API::WorkspacePostDeleteNotification_ptr p_dnf)
 {
-  QString wkspName = QString::fromStdString(p_dnf->object_name());
+  QString wkspName = QString::fromStdString(p_dnf->objectName());
   if ( m_workspaceNames.find(wkspName) != m_workspaceNames.end() )
   {
     forceDataReload();
diff --git a/Code/Mantid/MantidQt/CustomInterfaces/src/StepScan.cpp b/Code/Mantid/MantidQt/CustomInterfaces/src/StepScan.cpp
index 53af8fe05b13ed7a3380f0e7458f57951ed6f31f..1281594d11f4654e9cd96fd8aeaed82e0bfc01ad 100644
--- a/Code/Mantid/MantidQt/CustomInterfaces/src/StepScan.cpp
+++ b/Code/Mantid/MantidQt/CustomInterfaces/src/StepScan.cpp
@@ -642,14 +642,14 @@ void StepScan::plotCurve()
 
 void StepScan::handleAddEvent(Mantid::API::WorkspaceAddNotification_ptr pNf)
 {
-  checkForMaskWorkspace(pNf->object_name());
+  checkForMaskWorkspace(pNf->objectName());
 }
 
 void StepScan::handleReplEvent(Mantid::API::WorkspaceAfterReplaceNotification_ptr pNf)
 {
-  checkForMaskWorkspace(pNf->object_name());
-  checkForResultTableUpdate(pNf->object_name());
-  checkForVaryingLogs(pNf->object_name());
+  checkForMaskWorkspace(pNf->objectName());
+  checkForResultTableUpdate(pNf->objectName());
+  checkForVaryingLogs(pNf->objectName());
 }
 
 void StepScan::addReplaceObserverOnce()
diff --git a/Code/Mantid/MantidQt/CustomInterfaces/src/deltaECalc.cpp b/Code/Mantid/MantidQt/CustomInterfaces/src/deltaECalc.cpp
index 1e95f57548db94d53c221ee1279390fb41d44321..4e4393bfc20fdf97c772126e6041df9cd17da59e 100644
--- a/Code/Mantid/MantidQt/CustomInterfaces/src/deltaECalc.cpp
+++ b/Code/Mantid/MantidQt/CustomInterfaces/src/deltaECalc.cpp
@@ -21,7 +21,7 @@ const QString deltaECalc::tempWS = "mono_sample_temporyWS";
 * @param TOFWinEnd :: end of TOF range for background
 * @throw invalid_argument where problems with user data prevent the calculation from proceeding
 */
-deltaECalc::deltaECalc(QWidget * const interface, const Ui::ConvertToEnergy &userSettings, 
+deltaECalc::deltaECalc(QWidget * const interface, const Ui::DirectConvertToEnergy &userSettings, 
                        const bool removalBg, const double TOFWinSt, const double TOFWinEnd) :
   pythonCalc(interface), m_sets(userSettings), m_bgRemove(removalBg), m_TOFWinSt(TOFWinSt), m_TOFWinEnd(TOFWinEnd), m_diagnosedWS("")
 {
diff --git a/Code/Mantid/MantidQt/CustomInterfaces/test/WorkspaceInADSTest.h b/Code/Mantid/MantidQt/CustomInterfaces/test/WorkspaceInADSTest.h
index acbfa92a50c3bd69c2f944a70952e39561aaafdb..2290766f57984aaff38ed3255abdbf137a8a669b 100644
--- a/Code/Mantid/MantidQt/CustomInterfaces/test/WorkspaceInADSTest.h
+++ b/Code/Mantid/MantidQt/CustomInterfaces/test/WorkspaceInADSTest.h
@@ -73,7 +73,8 @@ public:
   void testExtractExistingUB()
   {
     MatrixWorkspace_sptr ws(new Mantid::DataObjects::Workspace2D());
-    ws->mutableSample().setOrientedLattice(new Mantid::Geometry::OrientedLattice(1, 2, 3));
+    Mantid::Geometry::OrientedLattice ol(1, 2, 3);
+    ws->mutableSample().setOrientedLattice(&ol);
     AnalysisDataService::Instance().addOrReplace("ws", ws);
 
     WorkspaceInADS memento("ws");
diff --git a/Code/Mantid/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/FitPropertyBrowser.h b/Code/Mantid/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/FitPropertyBrowser.h
index d12487ba83c24bd249d2fe1720bdcf37a02cc379..7b652ff7c64896e42944e3483569343ce6f1074c 100644
--- a/Code/Mantid/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/FitPropertyBrowser.h
+++ b/Code/Mantid/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/FitPropertyBrowser.h
@@ -224,7 +224,7 @@ public:
 
 
 public slots:
-  virtual void fit(){ doFit(500); }
+  virtual void fit();
   virtual void sequentialFit();
   void undoFit();
   void clear();
@@ -379,6 +379,7 @@ protected:
   QtProperty *m_minimizer;
   QtProperty *m_ignoreInvalidData;
   QtProperty *m_costFunction;
+  QtProperty *m_maxIterations;
   QtProperty *m_logValue;
   QtProperty *m_plotDiff;
   QtProperty *m_plotCompositeMembers;
diff --git a/Code/Mantid/MantidQt/MantidWidgets/src/CatalogSearch.cpp b/Code/Mantid/MantidQt/MantidWidgets/src/CatalogSearch.cpp
index b888a4d3c6c3551638be1be3ca7bdf7d69d918d1..2026aa512fde65085785eef42992493bb147a929 100644
--- a/Code/Mantid/MantidQt/MantidWidgets/src/CatalogSearch.cpp
+++ b/Code/Mantid/MantidQt/MantidWidgets/src/CatalogSearch.cpp
@@ -755,6 +755,9 @@ namespace MantidQt
       resultsTable->setColumnHidden(headerIndexByName(resultsTable, "DatabaseID"),true);
       resultsTable->setColumnHidden(headerIndexByName(resultsTable, "SessionID"), true);
 
+      //Resize InvestigationID column to fit contents
+      resultsTable->resizeColumnToContents(headerIndexByName(resultsTable, "InvestigationID"));
+
       // Sort by endDate with the most recent being first.
       resultsTable->setSortingEnabled(true);
       resultsTable->sortByColumn(headerIndexByName(resultsTable, "Start date"),Qt::DescendingOrder);
diff --git a/Code/Mantid/MantidQt/MantidWidgets/src/FitPropertyBrowser.cpp b/Code/Mantid/MantidQt/MantidWidgets/src/FitPropertyBrowser.cpp
index aa9a8c851013e36723387bcb447081cb34f41332..7569e77f952bcddb3d7efc1411384f3c1cdd19a1 100644
--- a/Code/Mantid/MantidQt/MantidWidgets/src/FitPropertyBrowser.cpp
+++ b/Code/Mantid/MantidQt/MantidWidgets/src/FitPropertyBrowser.cpp
@@ -188,7 +188,8 @@ void FitPropertyBrowser::init()
                << "Conjugate gradient (Fletcher-Reeves imp.)"
                << "Conjugate gradient (Polak-Ribiere imp.)"
                << "BFGS"
-               << "Damping";
+               << "Damping"
+               << "Fake";
 
   m_ignoreInvalidData = m_boolManager->addProperty("Ignore invalid data");
   setIgnoreInvalidData( settings.value("Ignore invalid data",false).toBool() );
@@ -198,6 +199,8 @@ void FitPropertyBrowser::init()
   m_costFunctions << "Least squares" << "Rwp";
                   //<< "Ignore positive peaks";
   m_enumManager->setEnumNames(m_costFunction,m_costFunctions);
+  m_maxIterations = m_intManager->addProperty("Max Iterations");
+  m_intManager->setValue( m_maxIterations, settings.value("Max Iterations",500).toInt() );
 
   m_plotDiff = m_boolManager->addProperty("Plot Difference");
   bool plotDiff = settings.value("Plot Difference",QVariant(true)).toBool();
@@ -232,6 +235,7 @@ void FitPropertyBrowser::init()
   settingsGroup->addSubProperty(m_minimizer);
   settingsGroup->addSubProperty(m_ignoreInvalidData);
   settingsGroup->addSubProperty(m_costFunction);
+  settingsGroup->addSubProperty(m_maxIterations);
   settingsGroup->addSubProperty(m_plotDiff);
   settingsGroup->addSubProperty(m_plotCompositeMembers);
   settingsGroup->addSubProperty(m_convolveMembers);
@@ -1097,7 +1101,11 @@ std::string FitPropertyBrowser::minimizer(bool withProperties)const
     foreach(QtProperty* prop,m_minimizerProperties)
     {
       minimStr += "," + prop->propertyName() + "=";
-      if ( prop->propertyManager() == m_doubleManager )
+      if ( prop->propertyManager() == m_intManager )
+      {
+        minimStr += QString::number( m_intManager->value(prop) );
+      }
+      else if ( prop->propertyManager() == m_doubleManager )
       {
         minimStr += QString::number( m_doubleManager->value(prop) );
       }
@@ -1105,10 +1113,14 @@ std::string FitPropertyBrowser::minimizer(bool withProperties)const
       {
         minimStr += QString::number( m_boolManager->value(prop) );
       }
-      else
+      else if ( prop->propertyManager() == m_stringManager )
       {
         minimStr += m_stringManager->value(prop);
       }
+      else
+      {
+        throw std::runtime_error("The fit browser doesn't support the type of minimizer's property " + prop->propertyName().toStdString() );
+      }
     }
   }
   return minimStr.toStdString();
@@ -1272,6 +1284,13 @@ void FitPropertyBrowser::intChanged(QtProperty* prop)
     if (!h) return;
     h->setFunctionWorkspace();
   }
+  else if (prop == m_maxIterations)
+  {
+      QSettings settings;
+      settings.beginGroup("Mantid/FitBrowser");
+      int val = m_intManager->value(prop);
+      settings.setValue(prop->propertyName(), val);
+  }
   else
   {// it could be an attribute
     PropertyHandler* h = getHandler()->findHandler(prop);
@@ -3084,6 +3103,15 @@ Mantid::API::Workspace_sptr FitPropertyBrowser::createMatrixFromTableWorkspace()
   }
 }
 
+/**
+  * Do the fit.
+  */
+void FitPropertyBrowser::fit()
+{
+    int maxIterations = m_intManager->value(m_maxIterations);
+    doFit( maxIterations );
+}
+
 /**=================================================================================================
  * Slot connected to the change signals of properties m_xColumn, m_yColumn, and m_errColumn.
  * @param prop :: Property that changed.
@@ -3142,10 +3170,33 @@ void FitPropertyBrowser::minimizerChanged()
       double val = *prp;
       m_doubleManager->setValue( prop, val );
     }
-    else
+    else if ( auto prp = dynamic_cast<Mantid::Kernel::PropertyWithValue<int>* >(*it) )
+    {
+      prop = m_intManager->addProperty( propName );
+      int val = *prp;
+      m_intManager->setValue( prop, val );
+    }
+    else if ( auto prp = dynamic_cast<Mantid::Kernel::PropertyWithValue<size_t>* >(*it) )
+    {
+      prop = m_intManager->addProperty( propName );
+      size_t val = *prp;
+      m_intManager->setValue( prop, static_cast<int>(val) );
+    }
+    else if ( auto prp = dynamic_cast<Mantid::Kernel::PropertyWithValue<std::string>* >(*it) )
     {
       prop = m_stringManager->addProperty( propName );
       QString val = QString::fromStdString( prp->value() );
+      m_stringManager->setValue( prop, val );
+    }
+    else if ( dynamic_cast<Mantid::API::IWorkspaceProperty* >(*it) )
+    {
+      prop = m_stringManager->addProperty( propName );
+      m_stringManager->setValue( prop, QString::fromStdString( (**it).value() ) );
+    }
+    else
+    {
+        QMessageBox::warning(this,"MantidPlot - Error","Type of minimizer's property " + propName + " is not yet supported by the browser.");
+        continue;
     }
     // set the tooltip from property doc string
     QString toolTip = QString::fromStdString( (**it).documentation() );
diff --git a/Code/Mantid/MantidQt/MantidWidgets/src/MWRunFiles.cpp b/Code/Mantid/MantidQt/MantidWidgets/src/MWRunFiles.cpp
index 751e736206271cbe434e2367717281287bddc167..f269286f0aef02879582e3c8ff7e6ac84de506af 100644
--- a/Code/Mantid/MantidQt/MantidWidgets/src/MWRunFiles.cpp
+++ b/Code/Mantid/MantidQt/MantidWidgets/src/MWRunFiles.cpp
@@ -933,7 +933,7 @@ QStringList MWRunFiles::getFileExtensionsFromAlgorithm(const QString & algName,
   FileProperty *fileProp = dynamic_cast<FileProperty*>(prop);
   MultipleFileProperty *multiFileProp = dynamic_cast<MultipleFileProperty*>(prop);
 
-  std::set<std::string> allowed;
+  std::vector<std::string> allowed;
   QString preferredExt;
 
   if( fileProp )
@@ -951,9 +951,9 @@ QStringList MWRunFiles::getFileExtensionsFromAlgorithm(const QString & algName,
     return fileExts;
   }
 
-  std::set<std::string>::const_iterator iend = allowed.end();
+  std::vector<std::string>::const_iterator iend = allowed.end();
   int index(0);
-  for(std::set<std::string>::const_iterator it = allowed.begin(); it != iend; ++it)
+  for(std::vector<std::string>::const_iterator it = allowed.begin(); it != iend; ++it)
   {
     if ( ! it->empty() )
     {
diff --git a/Code/Mantid/MantidQt/MantidWidgets/src/WorkspaceSelector.cpp b/Code/Mantid/MantidQt/MantidWidgets/src/WorkspaceSelector.cpp
index e10d3dd1ad663b6495ae292d8639a7d654b77a7f..5c322016155aafbf6e0f8ea1b73f65e2037468c4 100644
--- a/Code/Mantid/MantidQt/MantidWidgets/src/WorkspaceSelector.cpp
+++ b/Code/Mantid/MantidQt/MantidWidgets/src/WorkspaceSelector.cpp
@@ -168,12 +168,12 @@ void WorkspaceSelector::setValidatingAlgorithm(const QString & algName)
 void WorkspaceSelector::handleAddEvent(Mantid::API::WorkspaceAddNotification_ptr pNf) 
 {
   if ( !showHiddenWorkspaces() &&
-      Mantid::API::AnalysisDataService::Instance().isHiddenDataServiceObject(pNf->object_name()) )
+      Mantid::API::AnalysisDataService::Instance().isHiddenDataServiceObject(pNf->objectName()) )
   {
     return;
   }
 
-  QString name = QString::fromStdString( pNf->object_name() );
+  QString name = QString::fromStdString( pNf->objectName() );
   if ( checkEligibility(name, pNf->object() ) )
   {
     addItem(name);
@@ -182,7 +182,7 @@ void WorkspaceSelector::handleAddEvent(Mantid::API::WorkspaceAddNotification_ptr
 
 void WorkspaceSelector::handleRemEvent(Mantid::API::WorkspacePostDeleteNotification_ptr pNf)
 {
-  QString name = QString::fromStdString(pNf->object_name());
+  QString name = QString::fromStdString(pNf->objectName());
   int index = findText(name);
   if ( index != -1 )
   {
@@ -197,11 +197,11 @@ void WorkspaceSelector::handleClearEvent(Mantid::API::ClearADSNotification_ptr)
 
 void WorkspaceSelector::handleRenameEvent(Mantid::API::WorkspaceRenameNotification_ptr pNf)
 {
-  QString name = QString::fromStdString(pNf->object_name());
-  QString newName = QString::fromStdString(pNf->new_objectname());
+  QString name = QString::fromStdString(pNf->objectName());
+  QString newName = QString::fromStdString(pNf->newObjectName());
   auto& ads = Mantid::API::AnalysisDataService::Instance();
 
-  bool eligible = checkEligibility(newName, ads.retrieve(pNf->new_objectname()));
+  bool eligible = checkEligibility(newName, ads.retrieve(pNf->newObjectName()));
   int index = findText(name);
   int newIndex = findText(newName); 
   if(eligible)
@@ -228,10 +228,10 @@ void WorkspaceSelector::handleRenameEvent(Mantid::API::WorkspaceRenameNotificati
 void WorkspaceSelector::handleReplaceEvent(Mantid::API::WorkspaceAfterReplaceNotification_ptr pNf)
 {
 
-  QString name = QString::fromStdString(pNf->object_name());
+  QString name = QString::fromStdString(pNf->objectName());
   auto& ads = Mantid::API::AnalysisDataService::Instance();
 
-  bool eligible = checkEligibility(name , ads.retrieve(pNf->object_name())); 
+  bool eligible = checkEligibility(name , ads.retrieve(pNf->objectName()));
   int index = findText(name); 
 
   // if it is inside and it is eligible do nothing
diff --git a/Code/Mantid/MantidQt/SliceViewer/src/QScienceSpinBox.cpp b/Code/Mantid/MantidQt/SliceViewer/src/QScienceSpinBox.cpp
index c90296257b8c311af51db5c8b1baea9e662d676a..a099a2e20e83e4d9b5cb0622f961a0dd1c7e81cf 100644
--- a/Code/Mantid/MantidQt/SliceViewer/src/QScienceSpinBox.cpp
+++ b/Code/Mantid/MantidQt/SliceViewer/src/QScienceSpinBox.cpp
@@ -24,7 +24,7 @@ bool isIntermediateValueHelper(qint64 num, qint64 min, qint64 max, qint64 *match
   qint64 tmp = num;
 
   int numDigits = 0;
-  int digits[10];
+  int digits[] = {0,0,0,0,0,0,0,0,0,0};
   if (tmp == 0) {
     numDigits = 1;
     digits[0] = 0;
diff --git a/Code/Mantid/Vates/ParaviewPlugins/ParaViewWidgets/QtWidgets/DimensionWidget.cpp b/Code/Mantid/Vates/ParaviewPlugins/ParaViewWidgets/QtWidgets/DimensionWidget.cpp
index 224b9bd990cacd301c08f2702d5708911411a449..66f4fafd4cf509b7aaca7f6bd7cc6b67dd1afdf6 100644
--- a/Code/Mantid/Vates/ParaviewPlugins/ParaViewWidgets/QtWidgets/DimensionWidget.cpp
+++ b/Code/Mantid/Vates/ParaviewPlugins/ParaViewWidgets/QtWidgets/DimensionWidget.cpp
@@ -24,7 +24,8 @@ using namespace Mantid::VATES;
 Constructor
 */
 DimensionWidget::DimensionWidget() :
-  m_pDimensionPresenter(NULL), m_initialBinDisplay(BinDisplay::Simple)
+  m_layout(NULL), m_binLayout(NULL), m_axisLayout(NULL), m_currentDimensionIndex(0),
+  m_currentBinWidgetIndex(0), m_pDimensionPresenter(NULL), m_initialBinDisplay(BinDisplay::Simple)
 {
   m_binStackedWidget = new QStackedWidget;
   BinInputWidget* simple = new SimpleBinInputWidget;
@@ -32,7 +33,6 @@ DimensionWidget::DimensionWidget() :
   m_binStackedWidget->addWidget(simple);
   m_binStackedWidget->addWidget(lowstephigh);
   m_binStackedWidget->addWidget(new QLabel(""));
-  m_currentBinWidgetIndex = 0;
   m_binStackedWidget->setCurrentIndex(m_currentBinWidgetIndex);
 
   using namespace Mantid::Geometry;
diff --git a/Code/Mantid/Vates/VatesAPI/src/EventNexusLoadingPresenter.cpp b/Code/Mantid/Vates/VatesAPI/src/EventNexusLoadingPresenter.cpp
index 6e566d3cfad1205eed817690ab0b59ba868b33f6..8f5ebcfbdf4057297b4a211f071ab1d2c51b460f 100644
--- a/Code/Mantid/Vates/VatesAPI/src/EventNexusLoadingPresenter.cpp
+++ b/Code/Mantid/Vates/VatesAPI/src/EventNexusLoadingPresenter.cpp
@@ -1,3 +1,4 @@
+#include "MantidAPI/IEventWorkspace.h"
 #include "MantidVatesAPI/EventNexusLoadingPresenter.h"
 #include "MantidVatesAPI/MDLoadingView.h"
 #include "MantidGeometry/MDGeometry/MDGeometryXMLBuilder.h"
@@ -16,32 +17,34 @@ namespace Mantid
   namespace VATES
   {
     /*
-    Constructor
-    @param view : MVP view
-    @param filename : name of file to load
-    @throw invalid_argument if file name is empty
-    @throw invalid_arument if view is null
-    @throw logic_error if cannot use the reader-presenter for this filetype.
-    */
-    EventNexusLoadingPresenter::EventNexusLoadingPresenter(MDLoadingView* view, const std::string filename) : MDEWLoadingPresenter(view), m_filename(filename), m_wsTypeName("")
+     Constructor
+     @param view : MVP view
+     @param filename : name of file to load
+     @throw invalid_argument if file name is empty
+     @throw invalid_arument if view is null
+     @throw logic_error if cannot use the reader-presenter for this filetype.
+     */
+    EventNexusLoadingPresenter::EventNexusLoadingPresenter(MDLoadingView* view,
+        const std::string filename) :
+        MDEWLoadingPresenter(view), m_filename(filename), m_wsTypeName("")
     {
-      if(this->m_filename.empty())
+      if (this->m_filename.empty())
       {
         throw std::invalid_argument("File name is an empty string.");
       }
-      if(NULL == this->m_view)
+      if (NULL == this->m_view)
       {
         throw std::invalid_argument("View is NULL.");
       }
     }
 
     /*
-    Indicates whether this presenter is capable of handling the type of file that is attempted to be loaded.
-    @return false if the file cannot be read.
-    */
+     Indicates whether this presenter is capable of handling the type of file that is attempted to be loaded.
+     @return false if the file cannot be read.
+     */
     bool EventNexusLoadingPresenter::canReadFile() const
     {
-      if(!canLoadFileBasedOnExtension(m_filename, ".nxs"))
+      if (!canLoadFileBasedOnExtension(m_filename, ".nxs"))
       {
         return 0;
       }
@@ -54,8 +57,7 @@ namespace Mantid
         try
         {
           file->openGroup("entry", "NXentry");
-        }
-        catch(::NeXus::Exception &)
+        } catch (::NeXus::Exception &)
         {
           file->close();
           return 0;
@@ -68,16 +70,16 @@ namespace Mantid
         {
           if (it->first.find("_events") != std::string::npos)
           {
-            hasEvents=true;
+            hasEvents = true;
             break;
           }
         }
         file->close();
         return hasEvents ? 1 : 0;
-      }
-      catch (std::exception & e)
+      } catch (std::exception & e)
       {
-        std::cerr << "Could not open " << this->m_filename << " as an EventNexus file because of exception: " << e.what() << std::endl;
+        std::cerr << "Could not open " << this->m_filename
+            << " as an EventNexus file because of exception: " << e.what() << std::endl;
         // Clean up, if possible
         if (file)
           file->close();
@@ -86,39 +88,59 @@ namespace Mantid
     }
 
     /*
-    Executes the underlying algorithm to create the MVP model.
-    @param factory : visualisation factory to use.
-    @param loadingProgressUpdate : Handler for GUI updates while algorithm progresses.
-    @param drawingProgressUpdate : Handler for GUI updates while vtkDataSetFactory::create occurs.
-    */
-    vtkDataSet* EventNexusLoadingPresenter::execute(vtkDataSetFactory* factory, ProgressAction& loadingProgressUpdate, ProgressAction& drawingProgressUpdate)
+     Executes the underlying algorithm to create the MVP model.
+     @param factory : visualisation factory to use.
+     @param loadingProgressUpdate : Handler for GUI updates while algorithm progresses.
+     @param drawingProgressUpdate : Handler for GUI updates while vtkDataSetFactory::create occurs.
+     */
+    vtkDataSet* EventNexusLoadingPresenter::execute(vtkDataSetFactory* factory,
+        ProgressAction& loadingProgressUpdate, ProgressAction& drawingProgressUpdate)
     {
       using namespace Mantid::API;
       using namespace Mantid::Geometry;
 
       this->m_view->getLoadInMemory(); //TODO, nexus reader algorithm currently has no use of this.
 
-      if(this->shouldLoad())
+      if (this->shouldLoad())
       {
-        Poco::NObserver<ProgressAction, Mantid::API::Algorithm::ProgressNotification> observer(loadingProgressUpdate, &ProgressAction::handler);
+        Poco::NObserver<ProgressAction, Mantid::API::Algorithm::ProgressNotification> observer(
+            loadingProgressUpdate, &ProgressAction::handler);
         AnalysisDataService::Instance().remove("MD_EVENT_WS_ID");
 
-        IAlgorithm_sptr alg = AlgorithmManager::Instance().create("OneStepMDEW");
-        alg->initialize();
-        alg->setRethrows(true);
-        alg->setPropertyValue("Filename", this->m_filename);
-        alg->setPropertyValue("OutputWorkspace", "MD_EVENT_WS_ID");
-        alg->addObserver(observer);
-        alg->execute();
-        alg->removeObserver(observer);
+        Algorithm_sptr loadAlg = AlgorithmManager::Instance().createUnmanaged("LoadEventNexus");
+        loadAlg->initialize();
+        loadAlg->setChild(true);
+        loadAlg->setPropertyValue("Filename", this->m_filename);
+        loadAlg->setPropertyValue("OutputWorkspace", "temp_ws");
+        loadAlg->addObserver(observer);
+        loadAlg->executeAsChildAlg();
+        loadAlg->removeObserver(observer);
+
+        Mantid::API::IEventWorkspace_sptr tempWS = loadAlg->getProperty("OutputWorkspace");
+
+        Algorithm_sptr convertAlg = AlgorithmManager::Instance().createUnmanaged(
+            "ConvertToDiffractionMDWorkspace", 1);
+        convertAlg->initialize();
+        convertAlg->setChild(true);
+        convertAlg->setProperty("InputWorkspace", tempWS);
+        convertAlg->setProperty<bool>("ClearInputWorkspace", false);
+        convertAlg->setProperty<bool>("LorentzCorrection", true);
+        convertAlg->setPropertyValue("OutputWorkspace", "converted_ws");
+        convertAlg->addObserver(observer);
+        convertAlg->executeAsChildAlg();
+        convertAlg->removeObserver(observer);
+
+        IMDEventWorkspace_sptr outWS = convertAlg->getProperty("OutputWorkspace");
+        AnalysisDataService::Instance().addOrReplace("MD_EVENT_WS_ID", outWS);
       }
 
-      Workspace_sptr result=AnalysisDataService::Instance().retrieve("MD_EVENT_WS_ID");
-      Mantid::API::IMDEventWorkspace_sptr eventWs = boost::dynamic_pointer_cast<Mantid::API::IMDEventWorkspace>(result);
+      Workspace_sptr result = AnalysisDataService::Instance().retrieve("MD_EVENT_WS_ID");
+      Mantid::API::IMDEventWorkspace_sptr eventWs = boost::dynamic_pointer_cast<
+          Mantid::API::IMDEventWorkspace>(result);
       m_wsTypeName = eventWs->id();
 
       factory->setRecursionDepth(this->m_view->getRecursionDepth());
-      vtkDataSet* visualDataSet = factory->oneStepCreate(eventWs, drawingProgressUpdate);//HACK: progressUpdate should be argument for drawing!
+      vtkDataSet* visualDataSet = factory->oneStepCreate(eventWs, drawingProgressUpdate); //HACK: progressUpdate should be argument for drawing!
 
       this->extractMetadata(eventWs);
       this->appendMetadata(visualDataSet, eventWs->getName());
@@ -127,18 +149,18 @@ namespace Mantid
     }
 
     /**
-    @return boolean indicating whether the T dimension is available.
-    @throw runtime_error if execute has not been run first.
-    */
+     @return boolean indicating whether the T dimension is available.
+     @throw runtime_error if execute has not been run first.
+     */
     bool EventNexusLoadingPresenter::hasTDimensionAvailable() const
     {
       return false; //OneStepMDEW uses ConvertToDiffractionMDWorkspace, which always generates 3 dimensional MDEW
     }
 
     /*
-    @return timestep values.
-    @throw runtime_error if execute has not been run first.
-    */
+     @return timestep values.
+     @throw runtime_error if execute has not been run first.
+     */
     std::vector<double> EventNexusLoadingPresenter::getTimeStepValues() const
     {
       throw std::runtime_error("Does not have a 4th Dimension, so can be no T-axis");
@@ -151,23 +173,23 @@ namespace Mantid
     }
 
     /**
-    Executes any meta-data loading required.
-    */
+     Executes any meta-data loading required.
+     */
     void EventNexusLoadingPresenter::executeLoadMetadata()
     {
       /*Effectively a do-nothing implementation. 
 
-      Do not have a metadataonly switch for the underlying algorithm, therfore would be costly to load metadata.
-      For these file types we know that we get 3 dimensions anyway so do not need anyfurther geometry information until the point
-      at which it must be added to the outgoing vtkdataset.
-      */
+       Do not have a metadataonly switch for the underlying algorithm, therfore would be costly to load metadata.
+       For these file types we know that we get 3 dimensions anyway so do not need anyfurther geometry information until the point
+       at which it must be added to the outgoing vtkdataset.
+       */
       this->m_isSetup = true;
     }
 
     /*
-    Getter for the workspace type name.
-    @return Workspace Type Name
-    */
+     Getter for the workspace type name.
+     @return Workspace Type Name
+     */
     std::string EventNexusLoadingPresenter::getWorkspaceTypeName()
     {
       return m_wsTypeName;
diff --git a/Code/Mantid/Vates/VatesAPI/src/SynchronisingGeometryPresenter.cpp b/Code/Mantid/Vates/VatesAPI/src/SynchronisingGeometryPresenter.cpp
index 692d5e84d85f2a58a7cb6c407c04f82c4d8c3f45..cbc920dca153826f5371007dc4ed4cd5a69a989d 100644
--- a/Code/Mantid/Vates/VatesAPI/src/SynchronisingGeometryPresenter.cpp
+++ b/Code/Mantid/Vates/VatesAPI/src/SynchronisingGeometryPresenter.cpp
@@ -192,7 +192,10 @@ namespace Mantid
         std::replace_if(m_dimensions.begin(), m_dimensions.end(), FindModelId(pDimensionPresenter->getAppliedModel()->getDimensionId()), pDimensionPresenter->getAppliedModel());
         //Insert an axis-mapping for this expanded dimension.
         VecDimPresenter_sptr::iterator location = std::find_if(m_dimPresenters.begin(), m_dimPresenters.end(), FindId(pDimensionPresenter->getAppliedModel()->getDimensionId()));
-        insertMappedPresenter((*location));
+        if (location != m_dimPresenters.end())
+        {
+          insertMappedPresenter((*location));
+        }
         shuffleMappedPresenters();
       
     }
diff --git a/Code/Mantid/Vates/VatesAPI/src/TimeStepToTimeStep.cpp b/Code/Mantid/Vates/VatesAPI/src/TimeStepToTimeStep.cpp
index 48a27656d081b29e12764d5fd1a35d72e96f8dd9..fedadd8a48293d94194fb613727a00941c1e4edd 100644
--- a/Code/Mantid/Vates/VatesAPI/src/TimeStepToTimeStep.cpp
+++ b/Code/Mantid/Vates/VatesAPI/src/TimeStepToTimeStep.cpp
@@ -4,7 +4,8 @@ namespace Mantid
 {
 namespace VATES
 {
-TimeStepToTimeStep::TimeStepToTimeStep(double timeMin, double timeMax, size_t intervalStep)
+TimeStepToTimeStep::TimeStepToTimeStep(double timeMin, double timeMax, size_t intervalStep) :
+  m_timeRange(0.0), m_nIntervalSteps(0)
 {
   UNUSED_ARG(timeMin);
   UNUSED_ARG(timeMax);
@@ -16,7 +17,7 @@ TimeStepToTimeStep TimeStepToTimeStep::construct(double timeMin, double timeMax,
   return TimeStepToTimeStep(timeMin, timeMax, nIntervalSteps);
 }
 
-TimeStepToTimeStep::TimeStepToTimeStep()
+TimeStepToTimeStep::TimeStepToTimeStep() : m_timeRange(0.0), m_nIntervalSteps(0)
 {
 }
 
diff --git a/Code/Mantid/Vates/VatesAPI/src/TimeToTimeStep.cpp b/Code/Mantid/Vates/VatesAPI/src/TimeToTimeStep.cpp
index 1a27f9141c5cf78f31c2b2b42833544eaf015ee0..d3e0467f28ade704b5ec30235907af99f694eeac 100644
--- a/Code/Mantid/Vates/VatesAPI/src/TimeToTimeStep.cpp
+++ b/Code/Mantid/Vates/VatesAPI/src/TimeToTimeStep.cpp
@@ -37,7 +37,8 @@ TimeToTimeStep::TimeToTimeStep(double timeMin, double timeMax, size_t nIntervalS
 /**
   Default constructor.
 */
-TimeToTimeStep::TimeToTimeStep(): m_runnable(false)
+TimeToTimeStep::TimeToTimeStep(): m_timeMin(0.0), m_timeMax(0.0), m_timeRange(0.0),
+  m_c(0.0), m_fraction(0.0), m_nIntervalSteps(0), m_runnable(false)
 {
 }
 
diff --git a/Code/Mantid/Vates/VatesAPI/test/EventNexusLoadingPresenterTest.h b/Code/Mantid/Vates/VatesAPI/test/EventNexusLoadingPresenterTest.h
index 06e939801133c27a69aeb774e6f8057e71bbd5aa..52eb60420c0667996be1b25aff6fe3ad106fe70d 100644
--- a/Code/Mantid/Vates/VatesAPI/test/EventNexusLoadingPresenterTest.h
+++ b/Code/Mantid/Vates/VatesAPI/test/EventNexusLoadingPresenterTest.h
@@ -74,7 +74,7 @@ void testExecution()
   EXPECT_CALL(factory, create(_)).WillOnce(testing::Return(vtkUnstructuredGrid::New()));
   EXPECT_CALL(factory, setRecursionDepth(_)).Times(1);
 
-  MockProgressAction mockLoadingProgressUpdate;
+  NiceMock<MockProgressAction> mockLoadingProgressUpdate;
   MockProgressAction mockDrawingProgressUpdate;
 
   //Create the presenter and runit!
@@ -132,4 +132,4 @@ void testGetWorkspaceTypeName()
 
 
 };
-#endif
\ No newline at end of file
+#endif
diff --git a/Code/Mantid/Vates/VatesSimpleGui/ViewWidgets/src/MdViewerWidget.cpp b/Code/Mantid/Vates/VatesSimpleGui/ViewWidgets/src/MdViewerWidget.cpp
index 48caa4a045a3aaf7d9f3eeb0f29418b4e8c44194..57d4f56a7f576a76412d88ec47e6c876b7c6beb9 100644
--- a/Code/Mantid/Vates/VatesSimpleGui/ViewWidgets/src/MdViewerWidget.cpp
+++ b/Code/Mantid/Vates/VatesSimpleGui/ViewWidgets/src/MdViewerWidget.cpp
@@ -99,7 +99,9 @@ REGISTER_VATESGUI(MdViewerWidget)
 /**
  * This constructor is used in the plugin mode operation of the VSI.
  */
-MdViewerWidget::MdViewerWidget() : VatesViewerInterface()
+MdViewerWidget::MdViewerWidget() : VatesViewerInterface(), currentView(NULL),
+  dataLoader(NULL), hiddenView(NULL), lodAction(NULL), screenShot(NULL), viewLayout(NULL),
+  viewSettings(NULL)
 {
   // Calling workspace observer functions.
   observeAfterReplace();
diff --git a/Code/Mantid/docs/source/algorithms/ApplyCalibration-v1.rst b/Code/Mantid/docs/source/algorithms/ApplyCalibration-v1.rst
index 539d65f7d8f8b609216d4ad1171053ce88be8a8e..a2bbaf17f7739413fab03d372aba98cc84b71317 100644
--- a/Code/Mantid/docs/source/algorithms/ApplyCalibration-v1.rst
+++ b/Code/Mantid/docs/source/algorithms/ApplyCalibration-v1.rst
@@ -24,6 +24,8 @@ Usage
 -----
 **Example - move three detectors to specified positions that would be got from calibration**
 
+.. include:: ../usagedata-note.txt 
+
 .. testcode:: ExApplyCalibSimple
 
    from mantid.kernel import V3D
diff --git a/Code/Mantid/docs/source/algorithms/ApplyDetailedBalance-v1.rst b/Code/Mantid/docs/source/algorithms/ApplyDetailedBalance-v1.rst
index 2562f8d1ed6448548c423154a7f254eaa7d82a2e..cd8a8df2b313fc9924c96b39e732ac09b5293255 100644
--- a/Code/Mantid/docs/source/algorithms/ApplyDetailedBalance-v1.rst
+++ b/Code/Mantid/docs/source/algorithms/ApplyDetailedBalance-v1.rst
@@ -31,7 +31,7 @@ vol 1
 Usage
 -----
 
-**Example - Run LoadprofResolution for both TableWorkspace and workspace with XX Instrument**
+**Example - Run Applied Detailed Balance**
 
 .. testcode:: ExApplyDetailedBalanceSimple
 
diff --git a/Code/Mantid/docs/source/algorithms/CentroidPeaks-v1.rst b/Code/Mantid/docs/source/algorithms/CentroidPeaks-v1.rst
index 1a503610dbfeca1fa402b2a8075749dd10ced84b..cba09f9377bfe1b6c10a3c57b6965da3283e872a 100644
--- a/Code/Mantid/docs/source/algorithms/CentroidPeaks-v1.rst
+++ b/Code/Mantid/docs/source/algorithms/CentroidPeaks-v1.rst
@@ -15,4 +15,22 @@ peak by calculating the average of the coordinates of all events within
 a given radius of the peak, weighted by the weight (signal) of the event
 for event workspaces or the intensity for histogrammed workspaces.
 
+Usage
+-----
+
+.. code-block:: python
+
+    # Load a SCD data set from systemtests Data and find the peaks
+    LoadEventNexus(Filename='/home/vel/workspace/TOPAZ_3132_event.nxs', OutputWorkspace='TOPAZ_3132_nxs')
+    ConvertToDiffractionMDWorkspace(InputWorkspace='TOPAZ_3132_nxs', OutputWorkspace='TOPAZ_3132_md', LorentzCorrection=True)
+    peaks = FindPeaksMD(InputWorkspace='TOPAZ_3132_md', PeakDistanceThreshold=0.14999999999999999, MaxPeaks=100)
+    FindUBUsingFFT(PeaksWorkspace='peaks', MinD=2, MaxD=16)
+    IndexPeaks(PeaksWorkspace='peaks', NumIndexed=100, AverageError=0.013759860303255647)
+    peak = peaks.getPeak(0)
+    print peak.getBinCount()
+    peaks = CentroidPeaks(InPeaksWorkspace='peaks', InputWorkspace='TOPAZ_3132_nxs')
+    peak = peaks.getPeak(0)
+    print peak.getBinCount()
+
+
 .. categories::
diff --git a/Code/Mantid/docs/source/algorithms/ClearInstrumentParameters-v1.rst b/Code/Mantid/docs/source/algorithms/ClearInstrumentParameters-v1.rst
new file mode 100644
index 0000000000000000000000000000000000000000..c40e27d51489b845ed5a4a00faaed5cff496e410
--- /dev/null
+++ b/Code/Mantid/docs/source/algorithms/ClearInstrumentParameters-v1.rst
@@ -0,0 +1,21 @@
+.. algorithm::
+
+.. summary::
+
+.. alias::
+
+.. properties::
+
+Description
+-----------
+
+This algorithm clears all the parameters associated with a workspace's instrument.
+
+Parameters are used by Mantid to tweak an instrument's values without having to change
+the `instrument definition file <http://mantidproject.org/InstrumentDefinitionFile>`__ itself.
+
+The LocationParameters property specifies whether or not to clear any calibration parameters
+used to adjust the location of any components. Specifically, it will clear the "x", "y", "z",
+"r-position", "t-position", "p-position", "rotx", "roty", and "rotz" parameters.
+
+.. categories::
diff --git a/Code/Mantid/docs/source/algorithms/ConjoinWorkspaces-v1.rst b/Code/Mantid/docs/source/algorithms/ConjoinWorkspaces-v1.rst
index a35b276a77f1e814ca609277278398c56a55c17b..b5e9e91980e1c9cc99006cdda95e4d375a1a6001 100644
--- a/Code/Mantid/docs/source/algorithms/ConjoinWorkspaces-v1.rst
+++ b/Code/Mantid/docs/source/algorithms/ConjoinWorkspaces-v1.rst
@@ -47,4 +47,26 @@ The input workspaces must come from the same instrument, have common
 units and bins and no detectors that contribute to spectra should
 overlap.
 
+Usage
+-----
+
+**ConjoinWorkspaces Example**
+
+.. testcode:: ConjoinWorkspacesEx
+
+    ws1 = CreateSampleWorkspace(WorkspaceType="Histogram", NumBanks=2, BankPixelWidth=1, BinWidth=10, Xmax=50)
+    print "Number of spectra in first workspace", ws1.getNumberHistograms()
+    ws2 = CreateSampleWorkspace(WorkspaceType="Histogram", NumBanks=3, BankPixelWidth=1, BinWidth=10, Xmax=50)
+    print "Number of spectra in second workspace", ws2.getNumberHistograms()
+    ConjoinWorkspaces(InputWorkspace1=ws1, InputWorkspace2=ws2, CheckOverlapping=False)
+    print "Number of spectra after ConjoinWorkspaces", mtd['ws1'].getNumberHistograms()
+
+Output:
+
+.. testoutput:: ConjoinWorkspacesEx
+
+    Number of spectra in first workspace 2
+    Number of spectra in second workspace 3
+    Number of spectra after ConjoinWorkspaces 5
+
 .. categories::
diff --git a/Code/Mantid/docs/source/algorithms/ConvertToDiffractionMDWorkspace-v1.rst b/Code/Mantid/docs/source/algorithms/ConvertToDiffractionMDWorkspace-v1.rst
index 2929ce54e432f4c3d0708b635a0865b1b7ae7ea1..f814ae34f586d6f566b145d14cc23b763fd9b5ac 100644
--- a/Code/Mantid/docs/source/algorithms/ConvertToDiffractionMDWorkspace-v1.rst
+++ b/Code/Mantid/docs/source/algorithms/ConvertToDiffractionMDWorkspace-v1.rst
@@ -87,4 +87,24 @@ Performance Notes
 -  32-core AMD Opteron 2.7 GHz computer: measured between 8 and 9
    million events per second (400-1000 million event workspaces).
 
+Usage 
+
+**Example - Convert re-binned MARI 2D workspace to 3D MD workspace for further analysis/merging with data at different temperatures :**
+
+.. testcode:: ExConvertToDiffractionMDWorkspace
+
+   # create or load event workspace
+   events = CreateSampleWorkspace(OutputWorkspace='events', WorkspaceType='Event', Function='Multiple Peaks')
+   # convert to  MD workspace
+   md = ConvertToDiffractionMDWorkspace(InputWorkspace=events, OutputWorkspace='md', OneEventPerBin=False, LorentzCorrection=True, SplitThreshold=150, Version=1)
+
+   # A way to look at these results as a text:
+   print "Resulting MD workspace has {0} events and {1} dimensions".format(md.getNEvents(),md.getNumDims())
+
+**Output:**
+
+.. testoutput:: ExConvertToDiffractionMDWorkspace
+
+   Resulting MD workspace has 520128 events and 3 dimensions
+
 .. categories::
diff --git a/Code/Mantid/docs/source/algorithms/ConvertToDiffractionMDWorkspace-v2.rst b/Code/Mantid/docs/source/algorithms/ConvertToDiffractionMDWorkspace-v2.rst
index 2929ce54e432f4c3d0708b635a0865b1b7ae7ea1..eaf25f37fbd562214fa520dd0daa15b7abda0d81 100644
--- a/Code/Mantid/docs/source/algorithms/ConvertToDiffractionMDWorkspace-v2.rst
+++ b/Code/Mantid/docs/source/algorithms/ConvertToDiffractionMDWorkspace-v2.rst
@@ -87,4 +87,24 @@ Performance Notes
 -  32-core AMD Opteron 2.7 GHz computer: measured between 8 and 9
    million events per second (400-1000 million event workspaces).
 
+Usage 
+
+**Example - Convert re-binned MARI 2D workspace to 3D MD workspace for further analysis/merging with data at different temperatures :**
+
+.. testcode:: ExConvertToDiffractionMDWorkspace
+
+   # create or load event workspace
+   events = CreateSampleWorkspace(OutputWorkspace='events', WorkspaceType='Event', Function='Multiple Peaks')
+   # convert to  MD workspace
+   md = ConvertToDiffractionMDWorkspace(InputWorkspace=events, OutputWorkspace='md', OneEventPerBin=False, LorentzCorrection=True, SplitThreshold=150)
+
+   # A way to look at these results as a text:
+   print "Resulting MD workspace has {0} events and {1} dimensions".format(md.getNEvents(),md.getNumDims())
+
+**Output:**
+
+.. testoutput:: ExConvertToDiffractionMDWorkspace
+
+   Resulting MD workspace has 520128 events and 3 dimensions
+
 .. categories::
diff --git a/Code/Mantid/docs/source/algorithms/CopyInstrumentParameters-v1.rst b/Code/Mantid/docs/source/algorithms/CopyInstrumentParameters-v1.rst
index b51288fd625572348dec3ef456d0ecbbcd98e42f..0be8e549b8320686311a51e5f27bdb0d07f8626c 100644
--- a/Code/Mantid/docs/source/algorithms/CopyInstrumentParameters-v1.rst
+++ b/Code/Mantid/docs/source/algorithms/CopyInstrumentParameters-v1.rst
@@ -25,6 +25,8 @@ Usage
 -----
 **Example - Copy parameters that contain the movement of 3 detectors**
 
+.. include:: ../usagedata-note.txt 
+
 .. testcode:: ExCopyInstrumentParametersSimple
 
    # We load two workspaces with same instument
diff --git a/Code/Mantid/docs/source/algorithms/CreateCalFileByNames-v1.rst b/Code/Mantid/docs/source/algorithms/CreateCalFileByNames-v1.rst
index 615a8d62fb84fdbe83a55704a158be3022078575..2495e33d5e0483f0b802ed693731a0a3b11a41fa 100644
--- a/Code/Mantid/docs/source/algorithms/CreateCalFileByNames-v1.rst
+++ b/Code/Mantid/docs/source/algorithms/CreateCalFileByNames-v1.rst
@@ -36,6 +36,8 @@ Usage
 -----
 **Example - create cal file from GEM instrument**
 
+.. include:: ../usagedata-note.txt 
+
 .. testcode:: ExCreateCalFileByNamesSimple
 
    import os
diff --git a/Code/Mantid/docs/source/algorithms/CreateDummyCalFile-v1.rst b/Code/Mantid/docs/source/algorithms/CreateDummyCalFile-v1.rst
index 98d4ad65baf48c9739aedb29aabb00cca06f235e..55215d54bfdb42eaa808d39895273d1f5684dbea 100644
--- a/Code/Mantid/docs/source/algorithms/CreateDummyCalFile-v1.rst
+++ b/Code/Mantid/docs/source/algorithms/CreateDummyCalFile-v1.rst
@@ -28,6 +28,8 @@ Usage
 -----
 **Example - CreateDummyCalFile for MUSR**
 
+.. include:: ../usagedata-note.txt 
+
 .. testcode:: ExCreateDummyCalFileSimple
 
    import os
diff --git a/Code/Mantid/docs/source/algorithms/CreateGroupingWorkspace-v1.rst b/Code/Mantid/docs/source/algorithms/CreateGroupingWorkspace-v1.rst
index fc9cc6c5c4dc9d001ab51226469a537801ac547a..24597cffdb6a0c568a462bd5be4d14cc7f4b7899 100644
--- a/Code/Mantid/docs/source/algorithms/CreateGroupingWorkspace-v1.rst
+++ b/Code/Mantid/docs/source/algorithms/CreateGroupingWorkspace-v1.rst
@@ -29,6 +29,8 @@ Usage
 
 **Example - CreateGoupingWorkspace for MUSR Instrument**
 
+.. include:: ../usagedata-note.txt 
+
 .. testcode:: ExCreateGroupingWorkspaceSimple
 
    # Run algorithm with instrument specified
diff --git a/Code/Mantid/docs/source/algorithms/CreateLeBailFitInput-v1.rst b/Code/Mantid/docs/source/algorithms/CreateLeBailFitInput-v1.rst
index aca3cfbe9645055ba363b58d813481b639a98e0c..b0193eebac37450cf085dae5ab15940e416f7e9c 100644
--- a/Code/Mantid/docs/source/algorithms/CreateLeBailFitInput-v1.rst
+++ b/Code/Mantid/docs/source/algorithms/CreateLeBailFitInput-v1.rst
@@ -67,7 +67,6 @@ Usage
 
   DeleteWorkspace(partablews)
   DeleteWorkspace(braggtablews)
-  DeleteWorkspace("TempXXX")
 
 
 Output:
@@ -75,7 +74,6 @@ Output:
 .. testoutput:: ExCreateLBInputs
 
   GeneraateHKL? =  False
-  LaB6_HKL_Table
   Number Bragg peaks from .hkl file is 76.  Number of peak profile parameters is 30.
 
 
diff --git a/Code/Mantid/docs/source/algorithms/CropWorkspace-v1.rst b/Code/Mantid/docs/source/algorithms/CropWorkspace-v1.rst
index aedf5cb4f1ad1fa24a2d447236992405c501c538..205b96ecdc952ab7c62258efc8a493c16d980881 100644
--- a/Code/Mantid/docs/source/algorithms/CropWorkspace-v1.rst
+++ b/Code/Mantid/docs/source/algorithms/CropWorkspace-v1.rst
@@ -26,4 +26,27 @@ boundary within the range will be used. Note that if none of the
 optional properties are given, then the output workspace will be a copy
 of the input one.
 
+Usage
+-----
+**Example - Crop a 5-bin workspace**
+
+.. testcode:: ExCropWorkspace
+
+   # Create a workspace with 1 spectrum with five bins of width 10
+   ws = CreateSampleWorkspace(WorkspaceType="Histogram",  NumBanks=1, BankPixelWidth=1, BinWidth=10, Xmax=50)
+
+   # Run algorithm  removing first and last bins
+   OutputWorkspace = CropWorkspace(InputWorkspace=ws,XMin=10.0,XMax=40.0)
+
+   # Show workspaces
+   print "TOF Before CropWorkspace",ws.readX(0)
+   print "TOF After CropWorkspace",OutputWorkspace.readX(0)
+   
+Output:
+
+.. testoutput:: ExCropWorkspace
+
+   TOF Before CropWorkspace [  0.  10.  20.  30.  40.  50.]
+   TOF After CropWorkspace [ 10.  20.  30.  40.]
+
 .. categories::
diff --git a/Code/Mantid/docs/source/algorithms/CrossCorrelate-v1.rst b/Code/Mantid/docs/source/algorithms/CrossCorrelate-v1.rst
index f45942485686fb586218a4ec1a145aabdb9d262a..099e148fc2719e7cb8b7e229b632ee30406befcf 100644
--- a/Code/Mantid/docs/source/algorithms/CrossCorrelate-v1.rst
+++ b/Code/Mantid/docs/source/algorithms/CrossCorrelate-v1.rst
@@ -21,4 +21,26 @@ reference. The cross correlation function is computed in the range
 More details can be found
 `here. <http://en.wikipedia.org/wiki/Cross-correlation>`__
 
+Usage
+-----
+**Example - Crosscorrelate 2 spectra**
+
+.. testcode:: ExCrossCorrelate
+
+   
+   #Create a workspace with 2 spectra with five bins of width 0.5
+   ws = CreateSampleWorkspace(BankPixelWidth=1, XUnit='dSpacing', XMax=5, BinWidth=0.5)
+   ws = ScaleX(InputWorkspace='ws', Factor=0.5, Operation='Add', IndexMin=1, IndexMax=1)
+   # Run algorithm  CrossCorrelate
+   OutputWorkspace = CrossCorrelate(InputWorkspace='ws', WorkspaceIndexMax=1, XMin=2, XMax=4)
+
+   # Show workspaces
+   print "AutoCorrelation",OutputWorkspace.readY(0)
+   print "CrossCorrelation",OutputWorkspace.readY(1)
+
+.. testoutput:: ExCrossCorrelate
+
+   AutoCorrelation [-0.01890212  1.         -0.01890212]
+   CrossCorrelation [-0.68136257  0.16838401  0.45685055]
+
 .. categories::
diff --git a/Code/Mantid/docs/source/algorithms/DiffractionEventCalibrateDetectors-v1.rst b/Code/Mantid/docs/source/algorithms/DiffractionEventCalibrateDetectors-v1.rst
index 834a9ac43b3c62f77aa163df998810165f8b9f5e..bddf2fc17084f5f0e1098d54f601dd3730ff6a29 100644
--- a/Code/Mantid/docs/source/algorithms/DiffractionEventCalibrateDetectors-v1.rst
+++ b/Code/Mantid/docs/source/algorithms/DiffractionEventCalibrateDetectors-v1.rst
@@ -13,4 +13,34 @@ Moves the detectors in an instrument to optimize the maximum intensity
 of each detector using gsl\_multimin\_fminimizer\_nmsimplex. Only bin
 data close to peak you wish to maximize.
 
+Usage
+-----
+
+**Example: move detectors to maximize intensity**
+
+.. testcode:: ExDiffractionEventCalibrateDetectors
+                   
+    import os
+    ws = CreateSampleWorkspace("Event",NumBanks=1,BankPixelWidth=1)
+    ws = MoveInstrumentComponent(Workspace='ws', ComponentName='bank1', X=0.5, RelativePosition=False)
+    wsD = ConvertUnits(InputWorkspace='ws',  Target='dSpacing')
+    maxD = Max(wsD)
+    #Peak is at 2.69 in dSpace
+    DiffractionEventCalibrateDetectors(InputWorkspace='ws', Params = "2.6, 0.001, 2.8",
+        LocationOfPeakToOptimize=2.67, BankName="bank1", DetCalFilename="Test.DetCal")
+    LoadIsawDetCal(InputWorkspace='ws',Filename=os.path.join(config["defaultsave.directory"], 'Test.DetCal'))
+    ws = ConvertUnits(InputWorkspace='ws',  Target='dSpacing')
+    maxA = Max(ws)
+    print "Peak in dSpace", 0.5*(maxD.readX(0)[0]+maxD.readX(0)[1])
+    print "Peak from calibration", 0.5*(maxA.readX(0)[0]+maxA.readX(0)[1])
+
+Output:
+
+.. testoutput:: ExDiffractionEventCalibrateDetectors
+
+    Peak in dSpace 2.69077317913
+    Peak from calibration 2.67124691143
+
+
 .. categories::
+
diff --git a/Code/Mantid/docs/source/algorithms/EnginXCalibrate-v1.rst b/Code/Mantid/docs/source/algorithms/EnginXCalibrate-v1.rst
index f985bfd79a7049c826ebf656ba6922906faa613b..c2604424dc7f8da0e36b434e75d5c33da7496eeb 100644
--- a/Code/Mantid/docs/source/algorithms/EnginXCalibrate-v1.rst
+++ b/Code/Mantid/docs/source/algorithms/EnginXCalibrate-v1.rst
@@ -19,3 +19,25 @@ The calibration run is focussed and then fitted using expected Bragg peak positi
 Allows to correct for deviations in sample position.
 
 .. categories::
+
+Usage
+-----
+
+.. include:: ../usagedata-note.txt
+
+**Example - Calculate Difc and Zero:**
+
+.. testcode:: Ex
+
+   Difc, Zero = EnginXCalibrate(FileName="ENGINX00213855.nxs",
+                                     ExpectedPeaks=[1.097, 2.1], Bank=1)
+
+   print "Difc: %.2f" % (Difc)
+   print "Zero: %.2f" % (Zero)
+
+Output:
+
+.. testoutput:: Ex
+
+   Difc: 18404.93
+   Zero: -10.89
diff --git a/Code/Mantid/docs/source/algorithms/EnginXCalibrateFull-v1.rst b/Code/Mantid/docs/source/algorithms/EnginXCalibrateFull-v1.rst
index 646001d2f5145a283721877a3e0ffc5150b5f73f..ab52856b844dc92120d4fa680ea6f1015ac1e05c 100644
--- a/Code/Mantid/docs/source/algorithms/EnginXCalibrateFull-v1.rst
+++ b/Code/Mantid/docs/source/algorithms/EnginXCalibrateFull-v1.rst
@@ -24,3 +24,26 @@ The result of the calibration is accepted by both :ref:`algm-EnginXCalibrate` an
 Expects the *long* calibration run, which provides a decent pattern for every pixel.
 
 .. categories::
+
+Usage
+-----
+
+.. include:: ../usagedata-note.txt
+
+**Example - Calculate Difc and Zero:**
+
+.. testcode:: Ex
+
+   table = EnginXCalibrateFull(Filename="ENGINX00213855focussed.nxs",
+                                     ExpectedPeaks=[1.097, 2.1], Bank=1)
+
+   pos =  table.column(1)[0]
+   print "Det ID:", table.column(0)[0]
+   print "Calibrated position: (%.3f,%.3f,%.3f)" % (pos.getX(),pos.getY(),pos.getZ())
+
+Output:
+
+.. testoutput:: Ex
+
+   Det ID: 100001
+   Calibrated position: (1.506,0.000,0.002)
diff --git a/Code/Mantid/docs/source/algorithms/EnginXFocus-v1.rst b/Code/Mantid/docs/source/algorithms/EnginXFocus-v1.rst
index cd8ba9d451cabf95b09dec500b3a667868137ac1..13f2faac63a349b5463fc51143885f71937d245f 100644
--- a/Code/Mantid/docs/source/algorithms/EnginXFocus-v1.rst
+++ b/Code/Mantid/docs/source/algorithms/EnginXFocus-v1.rst
@@ -17,6 +17,11 @@ Description
 Performs a TOF to dSpacing conversion using calibrated pixel positions, focuses the values in dSpacing
 and then converts them back to TOF.
 
+Usage
+-----
+
+.. include:: ../usagedata-note.txt
+
 **Example - Simple focussing of and EnginX data file:**
 
 .. testcode:: ExSimple
diff --git a/Code/Mantid/docs/source/algorithms/FixGSASInstrumentFile-v1.rst b/Code/Mantid/docs/source/algorithms/FixGSASInstrumentFile-v1.rst
index ddc72cbbfe11528c2d4fc8582ff78bea647b52bb..deff928a2e29f6e4638a7c35a2a27f3d3499c8c7 100644
--- a/Code/Mantid/docs/source/algorithms/FixGSASInstrumentFile-v1.rst
+++ b/Code/Mantid/docs/source/algorithms/FixGSASInstrumentFile-v1.rst
@@ -22,18 +22,9 @@ Usage
 
 .. testcode:: ExHistSimple
 
-  # Set up default directory and file name
+  # Create filename (puts it in home directory to guarantee it exists)
   import os
-
-  defaultsavepath = config["defaultsave.directory"]
-  if config.hasProperty("defaultsave.directory"):
-    defaultpath = config["defaultsave.directory"]
-  elif config.hasProperty("default.savedirectory"):
-    defaultpath = config["default.savedirectory"]
-  else:
-    defaultpath = "/tmp/"
-
-  savefile = os.path.join(defaultpath, "fixed.iparm")
+  savefile = os.path.expanduser("~/fixed.iparm")
 
   # Run the algorithm
   FixGSASInstrumentFile(InputFilename="PG3HR60_FmPython.iparm", OutputFilename=savefile)
@@ -41,6 +32,7 @@ Usage
   # Load new file and check each line
   wfile = open(savefile, "r")
   lines = wfile.readlines()
+  wfile.close()
   numlinefewer80b = 0
   for line in lines:
     if len(line) > 0:
diff --git a/Code/Mantid/docs/source/algorithms/GenerateEventsFilter-v1.rst b/Code/Mantid/docs/source/algorithms/GenerateEventsFilter-v1.rst
index 4f3ec49ab74f0a45250403629e23833f87c1acf7..7eaaace49bfbe988dcb95fa0c60b4949945ba875 100644
--- a/Code/Mantid/docs/source/algorithms/GenerateEventsFilter-v1.rst
+++ b/Code/Mantid/docs/source/algorithms/GenerateEventsFilter-v1.rst
@@ -81,29 +81,14 @@ this algorithm:
    equal or within the tolerance of the log value as v\_0 + n x delta\_v
    +/- tolerance\_v.
 
-Parameter: *Centre*
-###################
-
-The input Boolean parameter *centre* is for filtering by log value(s).
-If option *centre* is taken, then for each interval,
-
--  starting time = log\_time - tolerance\_time;
--  stopping time = log\_time - tolerance\_time;
-
-It is a shift to left.
-
-Parameter: *LogValueTolerance* and *LogValueInterval*
-#####################################################
 
-These two parameters are used to determine the log value intervals for
-filtering events.
+Generate event filters by sample log value
+==========================================
 
-Let user-specified minimum log value to be 'min', LogValueTolerance to
-be 'tol', and LogValueInterval to be 'delta', then the log value
-intervals are (min-tol, min-tol+delta), (min-tol+delta, min-tol+2delta),
-...
+The sample log will be divided to intervals as :math:`v_0, v_1, \cdots, v_{i-1}, v_i, v_{i+1}, \cdots`. 
+All log entries, whose values falls into range :math:`[v_j, v_{j+1})`, will be assigned to
+a same workspace group. 
 
-The default value of LogValueTolerance is LogValueInterval divided by 2.
 
 About how log value is recorded
 ###############################
@@ -130,6 +115,75 @@ splitter will start from the first log time.
 while :ref:`GenerateEventsFilter <algm-GenerateEventsFilter>` can improve the
 resolution to 1 microsecond.
 
+Algorithm Parameters and Examples
+---------------------------------
+
+Here are the introductions to some important parameters (i.e., algorithm's properties). 
+
+
+Parameter: *Centre*
+###################
+
+The input Boolean parameter *centre* is for filtering by log value(s).
+If option *centre* is taken, then for each interval,
+
+-  starting time = log\_time - tolerance\_time;
+-  stopping time = log\_time - tolerance\_time;
+
+It is a shift to left.
+
+Parameter: *MinimumLogValue*, *MaximumLogValue*, *LogValueTolerance* and *LogValueInterval*
+###########################################################################################
+
+These four parameters are used to determine the log value intervals for
+filtering events.
+
+Double value log
+================
+
+Let user-specified minimum log value to be :math:`L_{min}`, 
+LogValueTolerance to be :math:`t`, and LogValueInterval to be :math:`\delta`, 
+then the log value intervals are 
+
+.. math:: [L_{min}-t, L_{min}-tol+\delta), [L_{min}-tol+\delta, L_{min}-tol+2\cdot\delta), \cdots
+
+The default value of LogValueTolerance is LogValueInterval divided by 2.
+
+Integer value log
+=================
+
+It is a little bit different for sample log recorded with integer. 
+
+- *MinimumLogValue* and *MaximumLogValue* can be same such that only entries with exacly the same log value 
+  will be considered;
+- If *LogValueInterval* is not give (i.e., default value is used), then any log enetry with log value
+  larger and equal to *MinimumLogValue* and smaller and equal to *MaximumLogValue* will be considered. 
+  Be noticed that in the same case for double value log, log entry with value equal to *MaximumLogValue*
+  will be excluded. 
+
+
+
+Example: Filter by double log value from :math:`s_0` to :math:`s_f`
+###################################################################
+
+There are two setup to acquire the same result: 
+
+- Use single-log-value mode:
+
+  - MinimumLogValue = :math:`s_0`
+  - MaximumLogValue = :math:`s_f`
+  - LogValueInterval is left to default
+  
+- Use multiple-log-value mode:
+
+  - MinimumLogValue = :math:`s_0`
+  - MaximumLogValue = :math:`s_f`
+  - LogValueInterval = :math:`s_f - s_0`
+  - LogValueTolerance = 0
+  
+
+
+
 Usage
 -----
 
diff --git a/Code/Mantid/docs/source/algorithms/IntegratePeakTimeSlices-v1.rst b/Code/Mantid/docs/source/algorithms/IntegratePeakTimeSlices-v1.rst
index ba351b2560080526241f01fd57ca714a0599af5a..55824d870925470970bfe0431ed691a84b083da5 100644
--- a/Code/Mantid/docs/source/algorithms/IntegratePeakTimeSlices-v1.rst
+++ b/Code/Mantid/docs/source/algorithms/IntegratePeakTimeSlices-v1.rst
@@ -45,4 +45,20 @@ give good results.
 This Algorithm is also used by the :ref:`algm-PeakIntegration`
 algorithm when the Fit tag is selected.
 
+Usage
+-----
+
+.. code-block:: python
+
+    # Load a SCD data set from systemtests Data and find the peaks
+    LoadEventNexus(Filename=r'TOPAZ_3132_event.nxs',OutputWorkspace='TOPAZ_3132_nxs')
+    ConvertToDiffractionMDWorkspace(InputWorkspace='TOPAZ_3132_nxs',OutputWorkspace='TOPAZ_3132_md',LorentzCorrection='1')
+    FindPeaksMD(InputWorkspace='TOPAZ_3132_md',PeakDistanceThreshold='0.15',MaxPeaks='100',OutputWorkspace='peaks')
+    FindUBUsingFFT(PeaksWorkspace='peaks',MinD='2',MaxD='16')
+    IndexPeaks(PeaksWorkspace='peaks')
+
+    # Run the Integration algorithm and print results
+    peak0,int,sig = IntegratePeakTimeSlices(InputWorkspace='TOPAZ_3132_nxs', Peaks='peaks', Intensity=4580.8587719746683, SigmaIntensity=190.21154129339735)
+    print "Intensity and SigmaIntensity of peak 0  = ",int,sig
+
 .. categories::
diff --git a/Code/Mantid/docs/source/algorithms/LoadBBY-v1.rst b/Code/Mantid/docs/source/algorithms/LoadBBY-v1.rst
index 6f087cdd975283443e5f9ff9499cb5c53f34c4e1..353f6d09022ecd2482ed9c39efc00cec8caaa111 100644
--- a/Code/Mantid/docs/source/algorithms/LoadBBY-v1.rst
+++ b/Code/Mantid/docs/source/algorithms/LoadBBY-v1.rst
@@ -12,3 +12,22 @@ Description
 Load data from the Bilby beamline at ANSTO.
 
 .. categories::
+
+Usage
+-----
+
+.. include:: ../usagedata-note.txt
+
+**Example - Load a Bilby dataset:**
+
+.. testcode:: ExSimple
+
+   ws = LoadBBY('Bilby_EOS.bin');
+
+   print "Number of spectra:", ws.getNumberHistograms()
+
+Output:
+
+.. testoutput:: ExSimple
+
+   Number of spectra: 61440
diff --git a/Code/Mantid/docs/source/algorithms/LoadFullprofResolution-v1.rst b/Code/Mantid/docs/source/algorithms/LoadFullprofResolution-v1.rst
index 576beddd696b16d4b2c606508da7a974aed63560..f1e088e66b07575b91d693d1a45aa2dd788da59e 100644
--- a/Code/Mantid/docs/source/algorithms/LoadFullprofResolution-v1.rst
+++ b/Code/Mantid/docs/source/algorithms/LoadFullprofResolution-v1.rst
@@ -33,6 +33,8 @@ Usage
 
 **Example - Run LoadprofResolution for both TableWorkspace and workspace with MUSR Instrument**
 
+.. include:: ../usagedata-note.txt
+
 .. testcode:: ExLoadFullprofResolutionSimple
 
    # We run LoadFullprof Resolution with both the OutputTable workspace
diff --git a/Code/Mantid/docs/source/algorithms/LoadGSASInstrumentFile-v1.rst b/Code/Mantid/docs/source/algorithms/LoadGSASInstrumentFile-v1.rst
index 91985613b1fb6d437a6514e9a9a6df9fb864d736..4783efc33ea0a8cd4b7188135a88de511b7b87b1 100644
--- a/Code/Mantid/docs/source/algorithms/LoadGSASInstrumentFile-v1.rst
+++ b/Code/Mantid/docs/source/algorithms/LoadGSASInstrumentFile-v1.rst
@@ -23,6 +23,8 @@ Usage
 
 **Example - Run LoadGSASInstrumentFile for both TableWorkspace and workspace with Instrument**
 
+.. include:: ../usagedata-note.txt
+
 .. testcode:: ExLoadGSASInstrumentFileSimple
 
    # We load a GSAS Instrument file with 2 Banks
diff --git a/Code/Mantid/docs/source/algorithms/LoadIDFFromNexus-v1.rst b/Code/Mantid/docs/source/algorithms/LoadIDFFromNexus-v1.rst
index 76d6a0b9a0bc0f0d172ee174a0d38504a40c82c2..73270c22730c34793a9b3941b141a16248ea43d2 100644
--- a/Code/Mantid/docs/source/algorithms/LoadIDFFromNexus-v1.rst
+++ b/Code/Mantid/docs/source/algorithms/LoadIDFFromNexus-v1.rst
@@ -19,6 +19,8 @@ Usage
 -----
 **Example - Load an IDF with differently named component**
 
+.. include:: ../usagedata-note.txt
+
 .. testcode:: ExLoadIDFFromnNexusSimple
 
    result = Load("MUSR00015189")
diff --git a/Code/Mantid/docs/source/algorithms/LoadILL-v1.rst b/Code/Mantid/docs/source/algorithms/LoadILL-v1.rst
index 25137cb7405f37e41a3704f13cfe7c67b8dd3498..7bdc9b5e89e10400f69436849a4ad1c0cf2d43d5 100644
--- a/Code/Mantid/docs/source/algorithms/LoadILL-v1.rst
+++ b/Code/Mantid/docs/source/algorithms/LoadILL-v1.rst
@@ -21,4 +21,72 @@ be loaded from the Vanadium data.
 
 To date this algorithm only supports: IN4, IN5 and IN6
 
+Usage
+-----
+
+**Example - Load a regular histogram Nexus file:**
+(see :ref:`algm-LoadILL` for more options)
+
+.. code-block:: python
+
+   # Regular data file.
+   dataRegular = 'ILLIN6_151460.nxs'
+
+   # Load ILL dataset
+   ws = Load(dataRegular)
+
+   print "This workspace has", ws.getNumDims(), "dimensions and has", ws.getNumberHistograms(), "histograms."
+
+Output:
+
+   This workspace has 2 dimensions and has 340 histograms.
+
+
+
+**Example - Load a histogram Nexus file where the dispersion peak is higher than the elastic peak.
+An auxiliary vanadium file is needed to locate the elastic peak.:**
+(see :ref:`algm-LoadILL` for more options)
+
+.. code-block:: python
+
+   # Data file where the dispersion peak is higher than the elastic peak.
+   dataDispersionPeak = 'ILLIN5_Sample_096003.nxs'
+
+   # Vanadium file collected in the same conditions as the dispersion peak dataset.
+   vanaDispersionPeak = 'ILLIN5_Vana_095893.nxs'
+
+   # Load ILL dispersion peak dataset and a vanadium dataset
+   ws = Load(dataDispersionPeak, FilenameVanadium=vanaDispersionPeak)
+
+   print "This workspace has", ws.getNumDims(), "dimensions and has", ws.getNumberHistograms(), "histograms."
+
+Output:
+
+   This workspace has 2 dimensions and has 98305 histograms.
+
+**Example - Same example as above, but the vanadium file is loaded in advance. The dataset for the dispersion peak is loaded after, using the auxiliary vanadium workspace.:**
+(see :ref:`algm-LoadILL` for more options)
+
+.. code-block:: python
+
+   # Data file where the dispersion peak is higher than the elastic peak.
+   dataDispersionPeak = 'ILLIN5_Sample_096003.nxs'
+
+   # Vanadium file collected in the same conditions as the dispersion peak dataset.
+   vanaDispersionPeak = 'ILLIN5_Vana_095893.nxs'
+
+   # Load the Vanadium
+   wsVana = Load(dataDispersionPeak)
+
+   # Load ILL dispersion peak dataset and a vanadium dataset
+   wsData = Load(dataDispersionPeak, WorkspaceVanadium=wsVana)
+
+   print "The Vanadium workspace has", wsVana.getNumDims(), "dimensions and has", wsVana.getNumberHistograms(), "histograms."
+   print "The Data workspace has", wsData.getNumDims(), "dimensions and has", wsData.getNumberHistograms(), "histograms."
+
+Output:
+
+	The Vanadium workspace has 2 dimensions and has 98305 histograms.
+	The Data workspace has 2 dimensions and has 98305 histograms.
+
 .. categories::
diff --git a/Code/Mantid/docs/source/algorithms/LoadILLAscii-v1.rst b/Code/Mantid/docs/source/algorithms/LoadILLAscii-v1.rst
index 5d16f3cba056edb5259838986c2944edea9c76a3..65817267b599ee2b682394510f2567550d8ed33a 100644
--- a/Code/Mantid/docs/source/algorithms/LoadILLAscii-v1.rst
+++ b/Code/Mantid/docs/source/algorithms/LoadILLAscii-v1.rst
@@ -9,9 +9,26 @@
 Description
 -----------
 
- Loads an ILL Ascii / Raw data file into an MDEventWorkspace with the given name.
- To date this Loader is only compatible with non-TOF instruments.
+Loads an ILL Ascii / Raw data file into an MDEventWorkspace with the given name.
+To date this Loader is only compatible with non-TOF instruments.
 
- Supported instruments : ILL D2B
+Supported instruments : ILL D2B
 
- .. categories::
+Usage
+-----
+
+**Example - Load ILL D2B Ascii file:**
+(see :ref:`algm-LoadILLAscii` for more options)
+
+.. code-block:: python
+
+   # Load ILL D2B data file into a Multi dimensional workspace.
+   ws = Load('ILLD2B_121459.txt')
+
+   print "This workspace has", ws.getNumDims(), "dimensions and", ws.getNEvents(), "events."
+
+Output:
+
+	This workspace has 3 dimensions and 409600 events.
+
+.. categories::
diff --git a/Code/Mantid/docs/source/algorithms/LoadILLIndirect-v1.rst b/Code/Mantid/docs/source/algorithms/LoadILLIndirect-v1.rst
index ac1a29d18dd968218cbd87f3d6f44b3b63036c97..2c6fdded0796481735e52bae9fe006ee33546eb2 100644
--- a/Code/Mantid/docs/source/algorithms/LoadILLIndirect-v1.rst
+++ b/Code/Mantid/docs/source/algorithms/LoadILLIndirect-v1.rst
@@ -16,4 +16,20 @@ The Units axis is defined with *empty* units. The main purpose of this loader is
 
 To date this algorithm only supports: IN16B
 
+Usage
+-----
+
+**Example - Load ILL IN16B NeXus file:**
+
+.. code-block:: python
+
+   # Load ILL IN16B data file into a workspace 2D.
+   ws = Load('ILLIN16B_034745.nxs')
+
+   print "This workspace has", ws.getNumDims(), "dimensions and has", ws.getNumberHistograms(), "histograms."
+
+Output:
+
+	This workspace has 2 dimensions and has 2057 histograms.
+
 .. categories::
diff --git a/Code/Mantid/docs/source/algorithms/LoadILLReflectometry-v1.rst b/Code/Mantid/docs/source/algorithms/LoadILLReflectometry-v1.rst
new file mode 100644
index 0000000000000000000000000000000000000000..5171caebaeeedc5f3a7dd0dcb1dbff3b31845542
--- /dev/null
+++ b/Code/Mantid/docs/source/algorithms/LoadILLReflectometry-v1.rst
@@ -0,0 +1,36 @@
+.. algorithm::
+
+.. summary::
+
+.. alias::
+
+.. properties::
+
+Description
+-----------
+
+Loads an ILL Reflectometry instrument NeXus file into a `Workspace2D <http://www.mantidproject.org/Workspace2D>`_ with
+the given name.
+
+This loader reads the detector position from the NeXus file and places it at the right position.
+It supports both TOF and non TOF modes.
+
+To date this Loader only supports D17 data.
+
+Usage
+-----
+
+**Example - Load ILL D17 NeXus file:**
+
+.. code-block:: python
+
+   # Load ILL D17 data file into a workspace 2D.
+   ws = Load('ILLD17_111686.nxs')
+
+   print "This workspace has", ws.getNumDims(), "dimensions and has", ws.getNumberHistograms(), "histograms."
+
+Output:
+	
+	This workspace has 2 dimensions and has 258 histograms.
+
+.. categories::
diff --git a/Code/Mantid/docs/source/algorithms/LoadILLSANS-v1.rst b/Code/Mantid/docs/source/algorithms/LoadILLSANS-v1.rst
index 767a999dd78c211ddcf4cd43ef81065860674e10..7310cce7dcde4d1630c5ac38a086135a02ad856f 100644
--- a/Code/Mantid/docs/source/algorithms/LoadILLSANS-v1.rst
+++ b/Code/Mantid/docs/source/algorithms/LoadILLSANS-v1.rst
@@ -12,4 +12,23 @@ Description
 Loads an ILL D33 nexus file into a :ref:`Workspace2D <Workspace2D>` with
 the given name.
 
+This loader reads the detector positions from the NeXus file and places all the five detectors (front and back) at the right positions.
+It supports both TOF and non TOF modes.
+
+Usage
+-----
+
+**Example - Load ILL D33 NeXus file:**
+
+.. code-block:: python
+
+   # Load ILL D33 data file into a workspace 2D.
+   ws = Load('ILLD33_sample_001425.nxs')
+
+   print "This workspace has", ws.getNumDims(), "dimensions and has", ws.getNumberHistograms(), "histograms."
+
+Output:
+	
+	This workspace has 2 dimensions and has 65538 histograms.
+
 .. categories::
diff --git a/Code/Mantid/docs/source/algorithms/LoadInstrumentFromNexus-v1.rst b/Code/Mantid/docs/source/algorithms/LoadInstrumentFromNexus-v1.rst
index 93a446c3ffd1a91ed1d014385241abe48c88f3e0..d1715bac3fcf7a55b21189b94ab4a9f7ac95aee4 100644
--- a/Code/Mantid/docs/source/algorithms/LoadInstrumentFromNexus-v1.rst
+++ b/Code/Mantid/docs/source/algorithms/LoadInstrumentFromNexus-v1.rst
@@ -9,15 +9,12 @@
 Description
 -----------
 
-Attempts to load information about the instrument from a ISIS NeXus
-file. In particular attempt to read L2 and 2-theta detector position
-values and add detectors which are positioned relative to the sample in
-spherical coordinates as (r,theta,phi)=(L2,2-theta,0.0). Also adds dummy
-source and samplepos components to instrument.
+Attempts to load information about the instrument from a ISIS NeXus file. 
+In particular, it attempts to read the reference frame axis. 
+Also adds dummy source and samplepos components to instrument.
 
 LoadInstrumentFromNexus is intended to be used as a child algorithm of
-other Load algorithms, rather than being used directly. It is used by
-LoadMuonNexus version 1.
+other Load algorithms, rather than being used directly. 
 
 Usage
 -----
@@ -26,22 +23,23 @@ Usage
 
 .. include:: ../usagedata-note.txt
 
-.. testcode:: Ex
+.. testcode:: ExLoadMUSR
 
    # Create a dummy ws containing arbitrary data, into which we will load the instrument.
    ws = CreateSampleWorkspace("Histogram","Flat background")
    LoadInstrumentFromNexus(ws, "MUSR00015189.nxs")
    inst = ws.getInstrument()
+   source = inst.getSource()
 
    print "The name of the instrument is \"%s\"." % inst.getName().strip()
-   print ("The reference frame axis pointing along the beam is %s." % 
-         inst.getReferenceFrame().pointingAlongBeam())
+   print ("The source postion is at:  %s." % str(source.getPos()) )
+
 
 Output:
 
-.. testoutput:: Ex
+.. testoutput:: ExLoadMUSR
 
    The name of the instrument is "MUSR".
-   The reference frame axis pointing along the beam is Z.
+   The source postion is at:  [0,-10,0].
 
 .. categories::
diff --git a/Code/Mantid/docs/source/algorithms/LoadIsawDetCal-v1.rst b/Code/Mantid/docs/source/algorithms/LoadIsawDetCal-v1.rst
index 1fe322da145767cdb4ca342090d09c29907d70a8..f258d97268f39ec6ab33e6891a762eb5726d2d72 100644
--- a/Code/Mantid/docs/source/algorithms/LoadIsawDetCal-v1.rst
+++ b/Code/Mantid/docs/source/algorithms/LoadIsawDetCal-v1.rst
@@ -12,4 +12,33 @@ Description
 Moves the detectors in an instrument using the origin and 2 vectors of
 the rotated plane from an ISAW DetCal file.
 
+Usage
+-----
+ 
+.. testcode:: LoadIsawDetCal
+    
+    #Write a ISAW DetCal file 
+    import mantid    
+    filename=mantid.config.getString("defaultsave.directory")+"loadIsawDetCalTest.DetCal"
+    f=open(filename,'w') 
+    f.write("5      1    256    256 50.1000 49.9000  0.2000  55.33   50.0000   16.7548  -16.7548  0.00011 -0.00002  1.00000  0.00000  1.00000  0.00000\n")
+    f.close() 
+             
+    iw = LoadEmptyInstrument(Filename="IDFs_for_UNIT_TESTING/MINITOPAZ_Definition.xml",)
+    LoadIsawDetCal(InputWorkspace=iw,FileName=filename)
+    bank = iw.getInstrument().getComponentByName("bank1")
+    print "Position after LoadDetCal :",bank.getPos()
+    
+.. testcleanup:: LoadIsawDetCal
+    
+    import os,mantid   
+    filename=mantid.config.getString("defaultsave.directory")+"loadIsawDetCalTest.DetCal"
+    os.remove(filename)
+ 
+Output:
+ 
+.. testoutput:: LoadIsawDetCal
+    
+    Position after LoadDetCal : [0.5,0.167548,-0.167548]
+
 .. categories::
diff --git a/Code/Mantid/docs/source/algorithms/LoadIsawSpectrum-v1.rst b/Code/Mantid/docs/source/algorithms/LoadIsawSpectrum-v1.rst
index 57b5d23816201917da5932f958954ad9e3fbc1e0..6ded13bf41997fefbbb3cf6e25ae9a932ebba36f 100644
--- a/Code/Mantid/docs/source/algorithms/LoadIsawSpectrum-v1.rst
+++ b/Code/Mantid/docs/source/algorithms/LoadIsawSpectrum-v1.rst
@@ -13,4 +13,50 @@ Load incident spectrum and detector efficiency correction file
 containing spectra for each detector. The spectra are created by
 "TOPAZ\_spectrum.py" from files of vanadium or TiZr and background.
 
+Usage
+-----
+
+.. testcode:: LoadIsawSpectrum
+
+    #Write a ISAW Spectrum file 
+    import mantid    
+    filename=mantid.config.getString("defaultsave.directory")+"loadIsawSpectrumTest.dat"  
+    f=open(filename,'w') 
+    f.write("# Column  Unit    Quantity\n") 
+    f.write("# ------  ------  --------\n") 
+    f.write("#      1  us      time-of-flight\n") 
+    f.write("#      2  counts  counts per us corrected for vanadium rod absorption\n") 
+    f.write("#      3  A       wavelength\n") 
+    f.write("#      4  counts  counts per us uncorrected for absorption\n") 
+    f.write("#      5          transmission\n") 
+    f.write("#\n") 
+    f.write("Bank 1     DetNum 17\n") 
+    f.write("      400.000      -23.878       0.0856      -22.409       0.9385\n") 
+    f.write("      401.600      -23.878       0.0859      -22.409       0.9385\n") 
+    f.write("      403.200      -23.879       0.0863      -22.409       0.9385\n") 
+    f.write("      404.800      -23.879       0.0866      -22.409       0.9385\n") 
+    f.write("      406.400      -23.879       0.0870      -22.409       0.9384\n") 
+    f.write("      408.000      -21.966       0.0873      -20.614       0.9384\n") 
+    f.close() 
+         
+         
+    ow = LoadIsawSpectrum(SpectraFile=filename,InstrumentName="TOPAZ")
+         
+        #check the results 
+    print "x=",ow.readX(0) 
+    print "y=",ow.readY(0) 
+    
+.. testcleanup:: LoadIsawSpectrum
+
+    import os,mantid   
+    filename=mantid.config.getString("defaultsave.directory")+"loadIsawSpectrumTest.dat"
+    os.remove(filename)
+
+Output:
+
+.. testoutput:: LoadIsawSpectrum
+
+    x= [ 399.2  400.8  402.4  404.   405.6  407.2  408.8]
+    y= [-0.00471167 -0.00471167 -0.00471187 -0.00471187 -0.00471187 -0.00433439]
+
 .. categories::
diff --git a/Code/Mantid/docs/source/algorithms/LoadLLB-v1.rst b/Code/Mantid/docs/source/algorithms/LoadLLB-v1.rst
index b1f35cb4afdf0db9aceb32d1be1401ab01d05131..15c054d6eb91f4d8ee9389adb0735fd60998bd42 100644
--- a/Code/Mantid/docs/source/algorithms/LoadLLB-v1.rst
+++ b/Code/Mantid/docs/source/algorithms/LoadLLB-v1.rst
@@ -16,4 +16,21 @@ This loader calculates the elastic peak position (EPP) on the fly.
 
 To date this algorithm only supports the MIBEMOL instrument.
 
+Usage
+-----
+
+**Example - Load a LLB MIBEMOL NeXus file:**
+(see :ref:`algm-LoadLLB` for more options)
+
+.. code-block:: python
+
+   # Load the MIBEMOL dataset into a workspace2D.
+   ws = Load('LLB_d22418.nxs')
+
+   print "This workspace has", ws.getNumDims(), "dimensions and its title is:", ws.getTitle()
+
+Output:
+
+   This workspace has 2 dimensions and its title is: Lysozyme/D2O (c=80 mg/ml) Treg=293 K, Tch=288 K  wl=5.2A  sous pression (4.5 kbar)
+
 .. categories::
diff --git a/Code/Mantid/docs/source/algorithms/LoadParameterFile-v1.rst b/Code/Mantid/docs/source/algorithms/LoadParameterFile-v1.rst
index 2f708026c7ff7893df3030cddaf54577f731ff7c..15d9a529ff9260fae95da5cf3620097857a370ba 100644
--- a/Code/Mantid/docs/source/algorithms/LoadParameterFile-v1.rst
+++ b/Code/Mantid/docs/source/algorithms/LoadParameterFile-v1.rst
@@ -20,6 +20,9 @@ through :xml:`<component-link>` tags in an
 named 'test' to be associated with a component named 'bank\_90degnew'
 defined in the :ref:`IDF <InstrumentDefinitionFile>` of the HRPD instrument:
 
+Components may also be identified by the id of a detector. The example below also demonstrates how to define a
+parameter named 'test2' for a component whose detector has an id of '14'.
+
 .. code-block:: xml
 
     <?xml version="1.0" encoding="UTF-8" ?>
@@ -29,6 +32,10 @@ defined in the :ref:`IDF <InstrumentDefinitionFile>` of the HRPD instrument:
       <parameter name="test"> <value val="50.0" /> </parameter>
     </component-link>
 
+    <component-link id="14" >
+      <parameter name="test2"> <value val="50.0" /> </parameter>
+    </component-link>
+
     </parameter-file>
 
 .. categories::
diff --git a/Code/Mantid/docs/source/algorithms/LoadSassena-v1.rst b/Code/Mantid/docs/source/algorithms/LoadSassena-v1.rst
index 1fd55481f0c57e4c4b047ce9852e8399f3ff63dd..f5b232387908d878dade11b3bf9b9d40ad09b1ed 100644
--- a/Code/Mantid/docs/source/algorithms/LoadSassena-v1.rst
+++ b/Code/Mantid/docs/source/algorithms/LoadSassena-v1.rst
@@ -47,4 +47,46 @@ is the same:
 -  Y-values contain the structure factors
 -  one spectra for each q-vector
 
+Usage
+-----
+
+.. include:: ../usagedata-note.txt
+
+.. testcode:: Ex
+
+    ws = LoadSassena("loadSassenaExample.h5", TimeUnit=1.0)
+    print 'workspaces instantiated: ', ', '.join(ws.getNames())
+    fqtReal = ws[1] # Real part of F(Q,t)
+    # Let's fit it to a Gaussian. We start with an initial guess
+    intensity = 0.5
+    center = 0.0
+    sigma = 200.0
+    startX = -900.0
+    endX = 900.0 
+    myFunc = 'name=Gaussian,Height={0},PeakCentre={1},Sigma={2}'.format(intensity,center,sigma)
+
+    # Call the Fit algorithm and perform the fit
+    fitStatus, chiSq, covarianceTable, paramTable, fitWorkspace =\
+    Fit(Function=myFunc, InputWorkspace=fqtReal, WorkspaceIndex=0, StartX = startX, EndX=endX, Output='fit')
+
+    print "The fit was: " + fitStatus
+    print("Fitted Height value is: %.2f" % paramTable.column(1)[0])
+    print("Fitted centre value is: %.2f" % abs(paramTable.column(1)[1]))
+    print("Fitted sigma value is: %.1f" % paramTable.column(1)[2])
+    # fitWorkspace contains the data, the calculated and the difference patterns
+    print "Number of spectra in fitWorkspace is: " +  str(fitWorkspace.getNumberHistograms())
+    print("The 989th y-value of the fitted curve: %.3f" % fitWorkspace.readY(1)[989])
+
+Output:
+
+.. testoutput:: Ex
+
+    workspaces instantiated:  ws_qvectors, ws_fqt.Re, ws_fqt.Im
+    The fit was: success
+    Fitted Height value is: 1.00
+    Fitted centre value is: 0.00
+    Fitted sigma value is: 100.0
+    Number of spectra in fitWorkspace is: 3
+    The 989th y-value of the fitted curve: 0.673
+
 .. categories::
diff --git a/Code/Mantid/docs/source/algorithms/NormaliseVanadium-v1.rst b/Code/Mantid/docs/source/algorithms/NormaliseVanadium-v1.rst
index 53accad8c9bac45416c77a1f59559c9011435f4b..ccdefa6872380132b18b5b926c67c586bdb4abbe 100644
--- a/Code/Mantid/docs/source/algorithms/NormaliseVanadium-v1.rst
+++ b/Code/Mantid/docs/source/algorithms/NormaliseVanadium-v1.rst
@@ -12,4 +12,24 @@ Description
 Normalises all spectra of workspace to a specified wavelength. Following
 A.J.Schultz's anvred, scales the vanadium spectra.
 
+
+
+Usage
+-----
+
+.. testcode:: NormaliseVanadium
+
+    
+    inst = LoadEmptyInstrument(Filename='IDFs_for_UNIT_TESTING/MINITOPAZ_Definition.xml')
+    vanadium = CreateWorkspace(DataX='0,0.5,1,1.5,2,2.5,3,3.5,4,4.5,5', DataY='10.574151,10.873,11.07348,11.22903,11.42286,11.47365,11.37375,11.112,10.512181,10.653397', UnitX='wavelength', ParentWorkspace=inst)
+    norm_van = NormaliseVanadium(InputWorkspace=vanadium)
+    print "Wavelength = ", norm_van.readX(0)[2], " Y = ", norm_van.readY(0)[2]
+    
+Output:
+
+.. testoutput:: NormaliseVanadium
+
+    Wavelength =  1.0  Y =  1.00913495012
+
+
 .. categories::
diff --git a/Code/Mantid/docs/source/algorithms/PeakIntensityVsRadius-v1.rst b/Code/Mantid/docs/source/algorithms/PeakIntensityVsRadius-v1.rst
index 3de263f33d3ac8c8e45980011e06420899d55dc9..b18a65e4e2702b6f06083ae45e62e337c287abce 100644
--- a/Code/Mantid/docs/source/algorithms/PeakIntensityVsRadius-v1.rst
+++ b/Code/Mantid/docs/source/algorithms/PeakIntensityVsRadius-v1.rst
@@ -48,21 +48,21 @@ Usage
 
 .. code-block:: python
 
-    # Load a SCD data set and find the peaks
-    LoadEventNexus(Filename=r'TOPAZ_3131_event.nxs',OutputWorkspace='TOPAZ_3131_nxs')
-    ConvertToDiffractionMDWorkspace(InputWorkspace='TOPAZ_3131_nxs',OutputWorkspace='TOPAZ_3131_md',LorentzCorrection='1')
-    FindPeaksMD(InputWorkspace='TOPAZ_3131_md',PeakDistanceThreshold='0.15',MaxPeaks='100',OutputWorkspace='peaks')
+    # Load a SCD data set from systemtests Data and find the peaks
+    LoadEventNexus(Filename=r'TOPAZ_3132_event.nxs',OutputWorkspace='TOPAZ_3132_nxs')
+    ConvertToDiffractionMDWorkspace(InputWorkspace='TOPAZ_3132_nxs',OutputWorkspace='TOPAZ_3132_md',LorentzCorrection='1')
+    FindPeaksMD(InputWorkspace='TOPAZ_3132_md',PeakDistanceThreshold='0.15',MaxPeaks='100',OutputWorkspace='peaks')
     FindUBUsingFFT(PeaksWorkspace='peaks',MinD='2',MaxD='16')
     IndexPeaks(PeaksWorkspace='peaks')
 
     # Run the PeakIntensityVsRadius algorithm, where the background shell scales with the PeakRadius
-    PeakIntensityVsRadius(InputWorkspace='TOPAZ_3131_md',PeaksWorkspace='peaks',
+    PeakIntensityVsRadius(InputWorkspace='TOPAZ_3132_md',PeaksWorkspace='peaks',
         RadiusStart=0.00, RadiusEnd=0.15, NumSteps=51,
         BackgroundInnerFactor=1.5,BackgroundOuterFactor=2,
         OutputWorkspace='peak_vs_rad')
 
     # Run the PeakIntensityVsRadius algorithm, with fixed background shell radius
-    PeakIntensityVsRadius(InputWorkspace='TOPAZ_3131_md',PeaksWorkspace='peaks',
+    PeakIntensityVsRadius(InputWorkspace='TOPAZ_3132_md',PeaksWorkspace='peaks',
         RadiusStart=0.00, RadiusEnd=0.15, NumSteps=51,
         BackgroundInnerRadius=0.15,BackgroundOuterRadius=0.2,
         OutputWorkspace='peak_vs_rad_fixed')
diff --git a/Code/Mantid/docs/source/algorithms/PoldiCalculateSpectrum2D-v1.rst b/Code/Mantid/docs/source/algorithms/PoldiCalculateSpectrum2D-v1.rst
new file mode 100644
index 0000000000000000000000000000000000000000..263dfe7e725d6616000cbd0f107d91364788a58a
--- /dev/null
+++ b/Code/Mantid/docs/source/algorithms/PoldiCalculateSpectrum2D-v1.rst
@@ -0,0 +1,58 @@
+.. algorithm::
+
+.. summary::
+
+.. alias::
+
+.. properties::
+
+Description
+-----------
+
+PoldiCalculateSpectrum2D is a preliminary algorithm that can be used to calculate 2D POLDI-data from a set of peaks. These must come in a table of special format, which may be generated for example by :ref:`algm-PoldiFitPeaks1D`. Furthermore, the algorithm needs a MatrixWorkspace containing raw POLDI data with correct dimensions and a proper instrument definition.
+
+The 1D-peak intensities need to be integral intensities, so the peaks are integrated if necessary. If there is no profile information supplied in the peak table (:ref:`algm-PoldiFitPeaks1D` adds this automatically), it's possible to supply a profile function as parameter to this algorithm. If a profile function name is present in the peak table, the one supplied in the parameters has priority.
+
+At the moment all profiles are calculated independently, using Gaussian functions. In future versions of the algorithm this will be much more flexible, including background functions.
+
+Usage
+-----
+
+.. include:: ../usagedata-note.txt
+
+PoldiAutoCorrelation operates on a MatrixWorkspace with a valid POLDI instrument definition. The following short example demonstrates how to use the algorithm, processing data obtained from recording the spectrum of a Silicon standard material (powder).
+
+.. testcode:: ExSilicon2D
+
+    # Load data file with Si spectrum and instrument definition
+    raw_6904 = LoadSINQFile(Filename = "poldi2013n006904.hdf", Instrument = "POLDI")
+    LoadInstrument(raw_6904, InstrumentName = "POLDI")
+    
+    # Data needs to be truncated to correct dimensions.
+    truncated_6904 = PoldiTruncateData(raw_6904)
+    
+    # Perform correlation, peak search and fit
+    correlated_6904 = PoldiAutoCorrelation(truncated_6904)
+    peaks_6904 = PoldiPeakSearch(correlated_6904)
+    
+    PoldiFitPeaks1D(InputWorkspace = correlated_6904, FwhmMultiples = 4.0,
+                    PeakFunction = "Gaussian", PoldiPeakTable = peaks_6904,
+                    OutputWorkspace = "peaks_refined_6904", ResultTableWorkspace = "result_table_6904",
+                    FitCharacteristicsWorkspace = "raw_fit_results_6904",
+                    FitPlotsWorkspace = "fit_plots_6904")
+                    
+    # Calculate a 2D spectrum using the refined peaks
+    PoldiCalculateSpectrum2D(InputWorkspace=truncated_6904,
+                             PoldiPeakWorkspace="peaks_refined_6904",
+                             OutputWorkspace="simulated_6904")
+    
+After this step, there is a new workspace containing the simulated spectrum. It should look similar to the one in the following figure:
+
+.. figure:: /images/PoldiAutoCorrelation_Si_2D.png
+   :figwidth: 15 cm
+   :align: center
+   :alt: Raw POLDI data for Silicon powder standard (simulated).
+   
+   Simulated 2D-spectrum of silicon powder.
+
+.. categories::
diff --git a/Code/Mantid/docs/source/algorithms/PredictFractionalPeaks-v1.rst b/Code/Mantid/docs/source/algorithms/PredictFractionalPeaks-v1.rst
index e42ee0405d39092f6e4b3f8a765af73ce42c8e4d..58809e4d7d429a78bc7eaddb7926f221ce72dda7 100644
--- a/Code/Mantid/docs/source/algorithms/PredictFractionalPeaks-v1.rst
+++ b/Code/Mantid/docs/source/algorithms/PredictFractionalPeaks-v1.rst
@@ -27,17 +27,15 @@ Usage
 
 **Example:**
 
-.. This test is not run at the moment as it creates an exception in python.  Ticket 9642 is in place to fix this and reinstate the test
+.. testcode:: TopazExample
 
-.. code-block:: python
+   peaks = LoadIsawPeaks("TOPAZ_3007.peaks")
+   LoadIsawUB(peaks,"TOPAZ_3007.mat")
+   IndexPeaks(peaks)
 
-    ws=LoadIsawPeaks("TOPAZ_3007.peaks")
-    LoadIsawUB(ws,"ls5637.mat")
-    IndexPeaks(ws)
+   fractional_peaks = PredictFractionalPeaks(peaks, HOffset=[-0.5,0,0.5],KOffset=0,LOffset=0.2)
+   print "Number of fractional peaks:",fractional_peaks.getNumberPeaks()
 
-    PredictFractionalPeaks(ws,FracPeaks='wsPeaksOut',HOffset=[-0.5,0,0.5],KOffset=0,LOffset=0.2)
-
-
-
-    
+.. testoutput:: TopazExample
 
+   Number of fractional peaks: 117
diff --git a/Code/Mantid/docs/source/algorithms/ProcessBackground-v1.rst b/Code/Mantid/docs/source/algorithms/ProcessBackground-v1.rst
index 50e82ce4710e2c53af0b74e724a7b90dd42cf429..2486efe3167ae85c2adc1c45beb583076d51dac4 100644
--- a/Code/Mantid/docs/source/algorithms/ProcessBackground-v1.rst
+++ b/Code/Mantid/docs/source/algorithms/ProcessBackground-v1.rst
@@ -12,44 +12,351 @@ Description
 The algorithm ProcessBackground() provides several functions for user to
 process background to prepare Le Bail Fit.
 
-Simple Remove Peaks
-###################
 
-This algorithm is designed for refining the background based on the
-assumption that the all peaks have been fitted reasonably well. Then by
-removing the peaks by function 'X0 +/- n\*FWHM', the rest data points
-are background in a very high probability.
+There are a few functional options for user to choose.
+* SelectBackgroundPoints: selecting background points from diffraction data. Usually the output will be used to fit background;
+* RemovePeaks: removing peaks from a given MatrixWorks from diffraction data;
 
-An arbitrary background function can be fitted against this background
-by standard optimizer.
 
-Automatic Background Points Selection
-#####################################
+Select Background Points
+########################
 
 This feature is designed to select many background points with user's
 simple input. User is required to select only a few background points in
 the middle of two adjacent peaks. Algorithm will fit these few points
 (*BackgroundPoints*) to a background function of specified type.
 
-Examples
---------
+The purpose of this option is to select as many background data points as possible
+for future background function fitting. 
+
+Prior information can be given by two modes.  Property 'SelectionMode' determines which modes to use.  
+One (1)is from a list of X-values specified by users via property "BackgroundPoints". 
+The other (2) is through a (background) function, whose type is specified by property "BackgroundType" and 
+values are given via input table workspace "BackgroundTableWorkspace". 
+
+
+Select background points from given X-values
+============================================
+
+Here is how it works.  Assume that the :math:`X^{(u)}` is the list of x values specified by users. 
+
+* Create a data set (X, Y, E) from input workspace, where :math:`X_i` is the nearest value
+  to :math:`X^{(u)}_i`;
+* Fit the background function against the data set (X, Y, E);
+* Select the data points, which are within a certain range above and below the fitted background function;
+* The last step is to fit background function against the selected background points 
+
+Select background points from given function
+============================================
+
+
+In this approach, the difference from the other apporach is to use the user given background function
+to select data points within a range other than fitting the background function from given data points in the
+other approach. 
+Thus, it is just the last step of previous approach. 
+
+Output workspaces
+=================
+
+- OutputWorkspace: It contains 3 spectra.  
+
+  - spectrum 0: the selected background data points;
+  - spectrum 1: the fitted background function against the selected data points;
+  - spectrum 2: the difference of sepctrum 0 and 1
 
-Selecting background
+- OutputBackgroundParameterWorkspace: A table workspace containing the fitted parameter values including :math:`\chi^2`. 
+
+- UserBackgroundWorkspace: a MatrixWorkspace to visualize by user. 
+  
+  - spectrum 0: background function (either given by user or fit from given data points) that is used to select background points;
+  - spectrum 1: diffraction data with background (spectrum 0) removed;
+  - spectrum 2: upper boundary on data points to be selected for spectrum 1;
+  - spectrum 3: lower boundary on data points to be selected for spectrum 1
+
+
+Algorithm properties
+====================
+
+Besides the common algorithm properties, below is the list of properties specific to this function option. 
+
+- Inputs:
+
+  - LowerBoundary
+  - UpperBoundary
+  - BackgroundType
+  - SelectionMode
+  - BackgroundOrder and BackgroundPoints / BackgroundTableWorkspace
+  - NoiseTolerance
+  - NegativeNoiseTolerance
+  - OutputBackgroundType
+  - OutputBackgroundOrder
+
+- Outputs:
+  
+  - OutputBackgroundParameterWorkspace
+  - UserBackgroundWorkspace
+
+A suggested workflow 
 ####################
 
 Here is a good example to select background points from a powder
 diffraction pattern by calling ProcessBackground() in a self-consistent
 manner.
 
-| ``1. Select a set of background points (X values only), which can roughly describes the background, manually;``
-| ``2. Call ProcessBackground with Option='SelectBackgroundPoints' and SelectionMode='UserSpecifyBackground'.``
-| `` Â Ã‚ A good choice for background function to enter is 6-th order polynomial;``
-| ``3. Plot spectra 2 to 4 in UserBackgroundWorkspace to check whether 'Tolerance' is proper or not.``
-| `` Â Ã‚ If not then reset the tolerance and run ProcessBackground again with previous setup;``
-| ``4. Fit OutputWorkspace (the selected background) with a background function;``
-| ``5. Call ProcessBackground with Option='SelectBackgroundPoints' and SelectionMode='UserFunction'.``
-| `` Â Ã‚ Set the background parameter workspace as the output parameter table workspace obtained in the last step;``
-| ``6. Repeat step 4 and 5 for a few times until the background plot by fitted background function``
-| `` Â Ã‚ from selected background points is close enough to real background.``
+1) Select a set of background points (X values only), which can roughly describes the background, manually;
+
+2) Call ProcessBackground with Option='SelectBackgroundPoints' and SelectionMode='UserSpecifyBackground'.
+   A good choice for background function to enter is 6-th order polynomial;
+3) Plot spectra 2 to 4 in UserBackgroundWorkspace to check whether 'Tolerance' is proper or not.
+   If not then reset the tolerance and run ProcessBackground again with previous setup;
+
+4) Fit OutputWorkspace (the selected background) with a background function;
+
+5) Call ProcessBackground with Option='SelectBackgroundPoints' and SelectionMode='UserFunction'.
+   Set the background parameter workspace as the output parameter table workspace obtained in the last step;
+
+6) Repeat step 4 and 5 for a few times until the background plot by fitted background function
+   from selected background points is close enough to real background.
+
+Simple Remove Peaks
+###################
+
+This algorithm is to remove peaks and output the backgrounds,
+which can be used to fit an artibrary background function after calling this algorithm. 
+
+It is assumed that the all peaks have been fitted reasonably well. 
+Then by removing the peaks within range :math:`X_i^{(0)} \pm FWHM`,
+and save the rest data points, which are very likely backgrounds, to an output workspace.  
+
+Required and optional algorithm properties
+==========================================
+
+Besides the common algorithm properties, below is the list of properties specific to this function option. 
+
+- Inputs: 
+
+  - BraggPeakTableWorkspace
+  - NumberOfFWHM
+
+- Outputs:
+
+  - UserBackgroundWorkspace: a dummy output for not raising trouble with python script
+
+
+Add Region
+##########
+
+Replace a region, which is defined by 'LowerBoundary' and 'UpperBoundary', in a workspace
+from another reference workspace. 
+
+
+Required and optional algorithm properties
+==========================================
+
+- Inputs
+
+  - LowerBoundary (required)
+  - UpperBoundary (required)
+  - ReferenceWorkspace (required)
+
+
+Delete Region
+#############
+
+Removed a specified region, which is defined by 'LowerBoundary' and 'UpperBoundary', from the input workspace. 
+
+Required and optional algorithm properties
+==========================================
+
+- Inputs
+
+  - LowerBoundary (required)
+  - UpperBoundary (required)
+
+
+Usage
+-----
+
+**Example - Select background from a powgen data:**
+
+.. testcode:: testSelectBkgd
+
+  LoadAscii(Filename=r'PG3_15035-3.dat', OutputWorkspace='PG3_15035-3',Unit='TOF')
+
+  outputs = ProcessBackground(InputWorkspace='PG3_15035-3', WorkspaceIndex = 0, Options='SelectBackgroundPoints',
+        LowerBound='9726',UpperBound='119000', BackgroundType = 'Polynomial',  BackgroundOrder = 6,
+        SelectionMode='FitGivenDataPoints', BackgroundPointSelectMode = "All Background Points",
+        BackgroundPoints='10082,10591,11154,12615,13690,13715,15073,16893,17764,19628,21318,24192,35350,44212,50900,60000,69900,79000',
+        NoiseTolerance = 0.10,
+        OutputWorkspace='PG3_15035-3_BkgdPts', OutputBackgroundType = "Polynomial", OutputBackgroundOrder = 6,
+        OutputBackgroundParameterWorkspace = "OutBackgroundParameters", UserBackgroundWorkspace="UserTheory")
+
+  tbws = outputs[2]
+
+  print "Number of output workspace = %d, Number of selected background points = %d" %( len(outputs),  len(outputs[0].readX(0)))
+  print "Fitted background function: A0 = %.5e, A1 = %.5e, A2 = %.5e ..." % (tbws.cell(1, 1), tbws.cell(2, 1), tbws.cell(3,1))
+
+.. testcleanup:: testSelectBkgd
+
+  DeleteWorkspace(Workspace='PG3_15035-3')
+  for i in xrange(3):
+    DeleteWorkspace(Workspace=outputs[i])
+
+Output:
+
+.. testoutput:: testSelectBkgd
+
+  Number of output workspace = 3, Number of selected background points = 4944
+  Fitted background function: A0 = 5.43859e-01, A1 = -5.20674e-05, A2 = 2.84119e-09 ...
+
+**Example - Add Region:**
+
+.. testcode:: testAddRegion
+
+  import math
+  import random
+
+  vecx = []
+  vecy1 = []
+  vecy2 = []
+  vece = []
+
+  x0 = 0.0
+  dx = 0.01
+
+  random.seed(1)
+  for i in xrange(1000):
+    x = x0 + float(i) * dx
+    vecx.append(x)
+    y = (random.random() - 0.5) * 2.0 + 2.0 + math.exp(-(x-4.0)**2/0.1)
+    e = math.sqrt(y)
+    vecy1.append(y)
+    vecy2.append(-y)
+    vece.append(e)
+
+  ws1 = CreateWorkspace(DataX = vecx, DataY = vecy1, DataE = vece, NSpec = 1)
+  ws2 = CreateWorkspace(DataX = vecx, DataY = vecy2, DataE = vece, NSpec = 1)
+
+  outputs = ProcessBackground(InputWorkspace=ws1, WorkspaceIndex=0, OutputWorkspace="ws12", Options="AddRegion",
+        LowerBound = 3.0, UpperBound = 5.0, ReferenceWorkspace = ws2)
+
+  for i in [200, 400, 450, 500, 700]:
+    print "X = %.5f, Input Y[%d] = %.5f, Reference Y[%d] = %.5f, Output Y[%d] = %.5f" % (vecx[i], i, ws1.readY(0)[i], i, ws2.readY(0)[i], i, outputs[0].readY(0)[i])
+
+.. testcleanup:: testAddRegion
+
+  DeleteWorkspace(Workspace=ws1)
+  DeleteWorkspace(Workspace=ws2)
+  for i in xrange(3):
+    DeleteWorkspace(Workspace=outputs[i])
+
+Output:
+
+.. testoutput:: testAddRegion
+
+  X = 2.00000, Input Y[200] = 1.65069, Reference Y[200] = -1.65069, Output Y[200] = 1.65069
+  X = 4.00000, Input Y[400] = 3.81388, Reference Y[400] = -3.81388, Output Y[400] = -3.81388
+  X = 4.50000, Input Y[450] = 2.68751, Reference Y[450] = -2.68751, Output Y[450] = -2.68751
+  X = 5.00000, Input Y[500] = 2.00611, Reference Y[500] = -2.00611, Output Y[500] = 1.71367
+  X = 7.00000, Input Y[700] = 1.12037, Reference Y[700] = -1.12037, Output Y[700] = 2.87033
+
+**Example - Delete Region:**
+
+.. testcode:: testDelRegion
+
+  import math
+  import random
+
+  vecx = []
+  vecy = []
+  vece = []
+
+  x0 = 0.0
+  dx = 0.01
+
+  random.seed(1)
+  for i in xrange(1000):
+    x = x0 + float(i) * dx
+    vecx.append(x)
+    y = (random.random() - 0.5) * 2.0 + 2.0 + math.exp(-(x-4.0)**2/0.1)
+    e = math.sqrt(y)
+    vecy.append(y)
+    vece.append(e)
+
+  ws1 = CreateWorkspace(DataX = vecx, DataY = vecy, DataE = vece, NSpec = 1)
+
+  outputs = ProcessBackground(InputWorkspace=ws1, WorkspaceIndex=0, OutputWorkspace="ws2", Options="DeleteRegion",
+        LowerBound = 3.0, UpperBound = 5.0)
+
+  print "Input has %d data points; Output has %d data points." % ( len(ws1.readX(0)), len(outputs[0].readX(0)) )
+
+.. testcleanup:: testDelRegion
+
+  DeleteWorkspace(Workspace=ws1)
+  for i in xrange(3):
+    DeleteWorkspace(Workspace=outputs[i])
+
+Output:
+
+.. testoutput:: testDelRegion
+
+  Input has 1000 data points; Output has 799 data points.
+
+**Example - Remove peaks:**
+
+.. testcode:: testRmPeaks
+
+  import math
+  import random
+
+  vecx = []
+  vecy = []
+  vece = []
+  numpts = 1000
+  x0 = 0
+  dx = 0.01
+
+  random.seed(1)
+  for i in xrange(1000):
+    x = float(i)*dx
+    y = 5 + (random.random() - 1)*2. + 10*math.exp( -(x-2.0)**2/0.1**2 ) + 20*math.exp( -(x-7.5)**2/0.05**2 )
+    e = math.sqrt(y)
+    vecx.append(x)
+    vecy.append(y)
+    vece.append(e)
+
+  ws = CreateWorkspace(DataX = vecx, DataY = vecy, DataE = vece, NSpec = 1)
+  peaktb = CreateEmptyTableWorkspace()
+  peaktb.addColumn("double", "TOF_h")
+  peaktb.addColumn("double", "FWHM")
+  peaktb.addRow([2.0, 0.3])
+  peaktb.addRow([7.40, 0.13])
+
+  outputs = ProcessBackground(InputWorkspace=ws, WorkspaceIndex=0, OutputWorkspace="background",
+      Options="RemovePeaks", BraggPeakTableWorkspace=peaktb, NumberOfFWHM=3)
+
+  Fit(Function='name=Polynomial,n=1,A0=0.0,A1=0.0', InputWorkspace='background',  CreateOutput=True, StartX=0, EndX=9.9900000000000002,
+      OutputNormalisedCovarianceMatrix='background_NormalisedCovarianceMatrix', OutputParameters='background_Parameters', OutputWorkspace='background_Workspace')
+
+  outparws = mtd["background_Parameters"]
+  print "Input workspace has %d data points; Output workspace has %d data points." % (len(ws.readX(0)), len(outputs[0].readX(0)))
+  print "Fitted background parameters: A0 = %.5e, A1 = %.5e, Chi-square = %.5f" % (outparws.cell(0, 1), outparws.cell(1,1), outparws.cell(2,1))
+
+.. testcleanup:: testRmPeaks
+
+  DeleteWorkspace(Workspace=ws)
+  for i in xrange(3):
+      DeleteWorkspace(Workspace=outputs[i])
+  DeleteWorkspace(Workspace="background_NormalisedCovarianceMatrix")
+  DeleteWorkspace(Workspace="background_Parameters")
+  DeleteWorkspace(Workspace="background_Workspace")
+  DeleteWorkspace(Workspace="peaktb")
+
+Output:
+
+.. testoutput:: testRmPeaks
+
+  Input workspace has 1000 data points; Output workspace has 741 data points.
+  Fitted background parameters: A0 = 3.90254e+00, A1 = 1.09284e-02, Chi-square = 0.08237
 
 .. categories::
diff --git a/Code/Mantid/docs/source/algorithms/SassenaFFT-v1.rst b/Code/Mantid/docs/source/algorithms/SassenaFFT-v1.rst
index dee3bd40d988361b59bf7d587b9414eaaebf3026..4c7a47b8b50ef80229ac7d19bdb5a33241fde605 100644
--- a/Code/Mantid/docs/source/algorithms/SassenaFFT-v1.rst
+++ b/Code/Mantid/docs/source/algorithms/SassenaFFT-v1.rst
@@ -59,4 +59,48 @@ is transformed, the result is another Gaussian:
 
    SassenaFFTexample.jpg
 
+Usage
+-----
+
+**Example - Load a Sassena file, Fourier transform it, and do a fit of S(Q,E):**
+
+.. testcode:: Ex
+
+    ws = LoadSassena("loadSassenaExample.h5", TimeUnit=1.0)
+    SassenaFFT(ws, FFTonlyRealPart=1, Temp=1000, DetailedBalance=1)
+
+    print 'workspaces instantiated: ', ', '.join(ws.getNames())
+
+    sqt = ws[3] # S(Q,E)
+    # I(Q,t) is a Gaussian, thus S(Q,E) is a Gaussian too (at high temperatures)
+    # Let's fit it to a Gaussian. We start with an initial guess
+    intensity = 100.0
+    center = 0.0
+    sigma = 0.01    #in meV
+    startX = -0.1   #in meV
+    endX = 0.1 
+    myFunc = 'name=Gaussian,Height={0},PeakCentre={1},Sigma={2}'.format(intensity,center,sigma)
+
+    # Call the Fit algorithm and perform the fit
+    fitStatus, chiSq, covarianceTable, paramTable, fitWorkspace =\
+    Fit(Function=myFunc, InputWorkspace=sqt, WorkspaceIndex=0, StartX = startX, EndX=endX, Output='fit')
+
+    print "The fit was: " + fitStatus
+    print("Fitted Height value is: %.1f" % paramTable.column(1)[0])
+    print("Fitted centre value is: %.1f" % abs(paramTable.column(1)[1]))
+    print("Fitted sigma value is: %.4f" % paramTable.column(1)[2])
+    # fitWorkspace contains the data, the calculated and the difference patterns
+    print "Number of spectra in fitWorkspace is: " +  str(fitWorkspace.getNumberHistograms())
+
+Output:
+
+.. testoutput:: Ex
+
+    workspaces instantiated:  ws_qvectors, ws_fqt.Re, ws_fqt.Im, ws_sqw
+    The fit was: success
+    Fitted Height value is: 250.7
+    Fitted centre value is: 0.0
+    Fitted sigma value is: 0.0066
+    Number of spectra in fitWorkspace is: 3
+
 .. categories::
diff --git a/Code/Mantid/docs/source/algorithms/SaveLauenorm-v1.rst b/Code/Mantid/docs/source/algorithms/SaveLauenorm-v1.rst
new file mode 100644
index 0000000000000000000000000000000000000000..12e8e615f5bc15ed45d8c7d27cc4e982dd7b35de
--- /dev/null
+++ b/Code/Mantid/docs/source/algorithms/SaveLauenorm-v1.rst
@@ -0,0 +1,101 @@
+.. algorithm::
+
+.. summary::
+
+.. alias::
+
+.. properties::
+
+Description
+-----------
+Provide input files for the program LAUENORM which is used to perform a wavelength normalisation for
+Laue data using symmetry equivalent reflections measured at different wavelengths.
+
+Input_Files
+ 
+Unit 21     LAUE001      Input Laue data file.  This is normally a card image file with one  record  per  reflection (unmerged, unsorted data) containing the items: h k l lambda theta intensity and sig(intensity) in format (3I5,2F10.5,2I10).
+
+Unit 22     LAUE002      
+
+Unit 23     LAUE003      
+
+Continuing
+
+From: http://www.ccp4.ac.uk/cvs/viewvc.cgi/laue/doc/lauenorm.ptx?diff_format=s&revision=1.1.1.1&view=markup
+
+Usage
+-----
+**Example - a simple example of running SaveLauenorm.**
+
+.. testcode:: ExSaveLauenormSimple
+
+    import os
+
+    prefix = "~/MyPeaks"
+    file = os.path.join(os.path.expanduser("~"), "MyPeaks001")
+
+    #load a peaks workspace from file
+    peaks = LoadIsawPeaks(Filename=r'Peaks5637.integrate')
+    SaveLauenorm(InputWorkspace=peaks, Filename=prefix)
+
+    print os.path.isfile(file)
+
+Output:
+
+.. testoutput:: ExSaveLauenormSimple
+
+    True
+
+.. testcleanup:: ExSaveLauenormSimple
+
+    import os
+    def removeFiles(files):
+      for ws in files:
+        try:
+          os.remove(file)
+        except:
+          pass
+
+    removeFiles(["MyPeaks001","MyPeaks002","MyPeaks003","MyPeaks004","MyPeaks005","MyPeaks006","MyPeaks007","MyPeaks008","MyPeaks009"])
+
+**Example - an example of running SaveLauenorm with sorting and filtering options.**
+
+.. testcode:: ExSaveLauenormOptions
+
+    import os
+
+    #load a peaks workspace from file
+    peaks = LoadIsawPeaks(Filename=r'Peaks5637.integrate')
+    print "Number of peaks in table %d" % peaks.rowCount()
+    
+    prefix = "~/MyPeaks"
+    file = os.path.join(os.path.expanduser("~"), "MyPeaks009")
+    SaveLauenorm(InputWorkspace=peaks, Filename=prefix, MinWavelength=0.5, MaxWavelength=2,MinDSpacing=0.2, SortFilesBy='Bank')
+
+    ifile = open(file, 'r')
+    lines = ifile.readlines()
+    ifile.close()
+    print "Number of peaks in table %d" % len(lines)
+
+Output:
+
+.. testoutput:: ExSaveLauenormOptions
+
+    Number of peaks in table 434
+    Number of peaks in table 23
+
+.. testcleanup:: ExSaveLauenormOptions
+
+    import os
+    def removeFiles(files):
+      for ws in files:
+        try:
+          os.remove(file)
+        except:
+          pass
+
+    removeFiles(["MyPeaks001","MyPeaks002","MyPeaks003","MyPeaks004","MyPeaks005","MyPeaks006","MyPeaks007","MyPeaks008","MyPeaks009"])
+
+
+
+.. categories::
diff --git a/Code/Mantid/docs/source/algorithms/SaveParameterFile-v1.rst b/Code/Mantid/docs/source/algorithms/SaveParameterFile-v1.rst
new file mode 100644
index 0000000000000000000000000000000000000000..19fb988bc026ea74527b1fc2fbab60da9d510612
--- /dev/null
+++ b/Code/Mantid/docs/source/algorithms/SaveParameterFile-v1.rst
@@ -0,0 +1,19 @@
+.. algorithm::
+
+.. summary::
+
+.. alias::
+
+.. properties::
+
+Description
+-----------
+
+This algorithm allows instrument parameters to be saved into an
+`instrument parameter file <http://mantidproject.org/InstrumentParameterFile>`__.
+The parameter file can then be inspected and or modified. It can also be loaded back into
+Mantid using the `LoadParameterFile <http://mantidproject.org/LoadParameterFile>`__ algorithm.
+
+The SaveLocationParameters property specifies whether or not to save any calibration parameters
+used to adjust the location of any components. Specifically, it will skip "x", "y", "z",
+"r-position", "t-position", "p-position", "rotx", "roty", and "rotz" parameters.
diff --git a/Code/Mantid/docs/source/algorithms/SaveToSNSHistogramNexus-v1.rst b/Code/Mantid/docs/source/algorithms/SaveToSNSHistogramNexus-v1.rst
index 2fe5224c1e11bb8ecc75ff9349df48e178520a0b..f13075877b956326e99cc651fa428ba70d39b0f9 100644
--- a/Code/Mantid/docs/source/algorithms/SaveToSNSHistogramNexus-v1.rst
+++ b/Code/Mantid/docs/source/algorithms/SaveToSNSHistogramNexus-v1.rst
@@ -19,4 +19,15 @@ In addition, this only works for instruments that use
 example); in addition, the name in the instrument definition file must
 match the name in the NXS file.
 
+Usage
+-----
+
+.. code-block:: python
+
+    # Needs an SNS nexus file with rectangular detectors available from system tests
+    ws = Load(Filename='/home/vel/workspace/TOPAZ_3132_event.nxs',  LoaderName='LoadEventNexus', LoaderVersion=1)
+    SaveToSNSHistogramNexus(InputFilename="TOPAZ_3132_event.nxs",InputWorkspace=ws,OutputFilename=TOPAZ_3132_copy.nxs")
+
+
+
 .. categories::
diff --git a/Code/Mantid/docs/source/algorithms/SaveZODS-v1.rst b/Code/Mantid/docs/source/algorithms/SaveZODS-v1.rst
index 934f9370d3e6c8bf1a7222952d1f82112680abb0..7a1cc0bc1e6d2b4ad337731d4156e7e823b3c8d6 100644
--- a/Code/Mantid/docs/source/algorithms/SaveZODS-v1.rst
+++ b/Code/Mantid/docs/source/algorithms/SaveZODS-v1.rst
@@ -70,4 +70,30 @@ Description of data fields
    -  The grid of points (r = origin+i\*a1+j\*a2+k\*a3) specifies the
       centers of histogram, not the corners.
 
+Usage
+-----
+
+This algorithm can be run on a pre-existing `MDEventWorkspace <http://www.mantidproject.org/MDEventWorkspace>`_
+or a newly created one. The example below will be done with newly created one
+using :ref:`CreateMDWorkspace <algm-CreateMDWorkspace>`.
+
+**SaveZODS HKL MDHisto Example**
+
+.. testcode:: SaveZODSEx
+
+    ws = CreateMDHistoWorkspace(SignalInput='1,2,3,4,5,6,7,8', ErrorInput='1,1,1,1,1,1,1,1', 
+        Dimensionality='3', Extents='-2, 2, -2, 2, -2, 2', Names=['[H,0,0]','[0,K,0]','[0,0,L]'],
+        NumberOfBins='2,2,2', Units='lattice,lattice,lattice')
+    import os
+    savefile = os.path.join(config["defaultsave.directory"], "ZODS.h5")
+    SaveZODS(InputWorkspace=ws, FileName=savefile)
+    print "File created:", os.path.exists(savefile)
+
+Output:
+
+.. testoutput:: SaveZODSEx
+
+   File created: True 
+
+
 .. categories::
diff --git a/Code/Mantid/docs/source/algorithms/ScaleX-v1.rst b/Code/Mantid/docs/source/algorithms/ScaleX-v1.rst
index ebf3d6489f3553aa4fa994170f49807d3cdc6717..96e8f21b6c20f234d0c99402e6b3f66747d325bb 100644
--- a/Code/Mantid/docs/source/algorithms/ScaleX-v1.rst
+++ b/Code/Mantid/docs/source/algorithms/ScaleX-v1.rst
@@ -9,8 +9,9 @@
 Description
 -----------
 
-Scales the X axis and everty unique X-coordinate of a histogram or every
-event of the input workspace by the amount requested.
+Scales the X axis, the X-coordinate of histograms in a histogram workspace,
+and the X-coordinate of events in an event workspace by the
+requested amount.
 
 -  The amount can be specified either as:
 -  an absolute numerical value via the "Factor" argument or
diff --git a/Code/Mantid/docs/source/algorithms/SelectCellOfType-v1.rst b/Code/Mantid/docs/source/algorithms/SelectCellOfType-v1.rst
index 399dc34705a2f3c716348aba86b51855a558ddaf..d3b04a7ab37fdac3e5f8a0e9c13e85813a831639 100644
--- a/Code/Mantid/docs/source/algorithms/SelectCellOfType-v1.rst
+++ b/Code/Mantid/docs/source/algorithms/SelectCellOfType-v1.rst
@@ -27,4 +27,32 @@ Characterization", Alan D. Mighell, Vol. 106, Number 6, Nov-Dec 2001,
 Journal of Research of the National Institute of Standards and
 Technology, available from: `nvlpubs <nvlpubs.nist.gov/nistpubs/jres/106/6/j66mig.pdf>`_.
 
+Usage
+-----
+
+**Example:**
+
+.. testcode:: ExSelectCellOfType
+
+   ws=LoadIsawPeaks("TOPAZ_3007.peaks")
+   FindUBUsingFFT(ws,MinD=8.0,MaxD=13.0)
+   print "Lattice before SelectCellOfType:"
+   lattice = ws.sample().getOrientedLattice()
+   print lattice.a(),lattice.b(),lattice.c(),lattice.alpha(),lattice.beta(),lattice.gamma()
+   SelectCellOfType(PeaksWorkspace=ws, CellType='Monoclinic', Centering='C', Apply=True)
+   print "\nLattice after SelectCellOfType:"
+   lattice = ws.sample().getOrientedLattice()
+   print lattice.a(),lattice.b(),lattice.c(),lattice.alpha(),lattice.beta(),lattice.gamma()
+
+
+Output:
+
+.. testoutput:: ExSelectCellOfType
+
+   Lattice before SelectCellOfType:
+   8.60581864273 11.935925461 11.9418127661 107.429088323 98.7529124665 98.9511934747
+
+   Lattice after SelectCellOfType:
+   14.1310511523 19.247332564 8.60581864273 89.8811706749 105.07133377 89.970386662
+
 .. categories::
diff --git a/Code/Mantid/docs/source/algorithms/SelectCellWithForm-v1.rst b/Code/Mantid/docs/source/algorithms/SelectCellWithForm-v1.rst
index 54c02b884098d083adcc74e7d012fddb556663bb..3433b925001ac62fe0ff86b4cb6927bbbb586fad 100644
--- a/Code/Mantid/docs/source/algorithms/SelectCellWithForm-v1.rst
+++ b/Code/Mantid/docs/source/algorithms/SelectCellWithForm-v1.rst
@@ -27,4 +27,32 @@ Characterization", Alan D. Mighell, Vol. 106, Number 6, Nov-Dec 2001,
 Journal of Research of the National Institute of Standards and
 Technology, available from: `nvlpubs <nvlpubs.nist.gov/nistpubs/jres/106/6/j66mig.pdf>`_.
 
+Usage
+-----
+ 
+**Example:**
+ 
+.. testcode:: ExSelectCellWithForm
+   
+   ws=LoadIsawPeaks("TOPAZ_3007.peaks")
+   FindUBUsingFFT(ws,MinD=8.0,MaxD=13.0)
+   print "Lattice before SelectCellWithForm:"
+   lattice = ws.sample().getOrientedLattice()
+   print lattice.a(),lattice.b(),lattice.c(),lattice.alpha(),lattice.beta(),lattice.gamma()
+   SelectCellWithForm(PeaksWorkspace='ws', FormNumber=25, Apply=True)
+   print "\nLattice after SelectCellWithForm:"
+   lattice = ws.sample().getOrientedLattice()
+   print lattice.a(),lattice.b(),lattice.c(),lattice.alpha(),lattice.beta(),lattice.gamma()
+ 
+ 
+Output:
+ 
+.. testoutput:: ExSelectCellWithForm
+
+   Lattice before SelectCellWithForm:
+   8.60581864273 11.935925461 11.9418127661 107.429088323 98.7529124665 98.9511934747
+
+   Lattice after SelectCellWithForm:
+   14.1310511523 19.247332564 8.60581864273 89.8811706749 105.07133377 89.970386662
+
 .. categories::
diff --git a/Code/Mantid/docs/source/algorithms/SetupILLD33Reduction-v1.rst b/Code/Mantid/docs/source/algorithms/SetupILLD33Reduction-v1.rst
index 70f410de7198bc157016d5454f110cda3ef76a54..a45cf9b58dc81a0365e6463d4b8352f083eeff62 100644
--- a/Code/Mantid/docs/source/algorithms/SetupILLD33Reduction-v1.rst
+++ b/Code/Mantid/docs/source/algorithms/SetupILLD33Reduction-v1.rst
@@ -12,7 +12,80 @@ Description
 Create a PropertyManager object setting the reduction options for ILL
 D33 SANS TOF instrument. The property manager object is then added to
 the PropertyManagerDataService.
+This was based on the :ref:`SetupEQSANSReduction <algm-SetupEQSANSReduction>`.
 
 See :ref:`SANSReduction <algm-SANSReduction>` for details.
 
+Usage
+-----
+
+**Example - Reduces D33 data from a set of NeXus files:**
+
+.. code-block:: python
+
+	# List of detector IDs masked
+	maskedDetectors = [14709,14710,14711,14712,14713,14714,14715,14716,14717,14718,
+		14719,14720,14721,14722,14723,14724,14725,14726,14727,14728,14729,14730,14731,
+		14732,14733,14734,14735,14965,14966,14967,14968,14969,14970,14971,14972,14973,
+		14974,14975,14976,14977,14978,14979,14980,14981,14982,14983,14984,14985,14986,
+		14987,14988,14989,14990,14991,15221,15222,15223,15224,15225,15226,15227,15228,
+		15229,15230,15231,15232,15233,15234,15235,15236,15237,15238,15239,15240,15241,
+		15242,15243,15244,15245,15246,15247,15477,15478,15479,15480,15481,15482,15483,
+		15484,15485,15486,15487,15488,15489,15490,15491,15492,15493,15494,15495,15496,
+		15497,15498,15499,15500,15501,15502,15503,15733,15734,15735,15736,15737,15738,
+		15739,15740,15741,15742,15743,15744,15745,15746,15747,15748,15749,15750,15751,
+		15752,15753,15754,15755,15756,15757,15758,15759,15989,15990,15991,15992,15993,
+		15994,15995,15996,15997,15998,15999,16000,16001,16002,16003,16004,16005,16006,
+		16007,16008,16009,16010,16011,16012,16013,16014,16015,16245,16246,16247,16248,
+		16249,16250,16251,16252,16253,16254,16255,16256,16257,16258,16259,16260,16261,
+		16262,16263,16264,16265,16266,16267,16268,16269,16270,16271,16501,16502,16503,
+		16504,16505,16506,16507,16508,16509,16510,16511,16512,16513,16514,16515,16516,
+		16517,16518,16519,16520,16521,16522,16523,16524,16525,16526,16527,16757,16758,
+		16759,16760,16761,16762,16763,16764,16765,16766,16767,16768,16769,16770,16771,
+		16772,16773,16774,16775,16776,16777,16778,16779,16780,16781,16782,16783,17013,
+		17014,17015,17016,17017,17018,17019,17020,17021,17022,17023,17024,17025,17026,
+		17027,17028,17029,17030,17031,17032,17033,17034,17035,17036,17037,17038,17039,
+		17269,17270,17271,17272,17273,17274,17275,17276,17277,17278,17279,17280,17281,
+		17282,17283,17284,17285,17286,17287,17288,17289,17290,17291,17292,17293,17294,
+		17295,17525,17526,17527,17528,17529,17530,17531,17532,17533,17534,17535,17536,
+		17537,17538,17539,17540,17541,17542,17543,17544,17545,17546,17547,17548,17549,
+		17550,17551]
+
+	# Set all the necessary parameters to reduce the data
+	SetupILLD33Reduction(
+		MaskedDetectorList=maskedDetectors,
+		BeamCenterMethod="DirectBeam",
+		BeamCenterFile="ILLD33_direct_beam_transm_001427.nxs",
+		Normalisation="Timer",
+		DarkCurrentFile= "ILLD33_b4c_001420.nxs",
+		TransmissionMethod="DirectBeam",
+		TransmissionSampleDataFile= "ILLD33_sample_transm_001431.nxs",
+		TransmissionEmptyDataFile= "ILLD33_direct_beam_transm_001427.nxs",
+		BckTransmissionEmptyDataFile= "ILLD33_direct_beam_transm_001427.nxs",
+		TransmissionBeamRadius = 3,
+		TransmissionUseSampleDC=False,
+		BackgroundFiles= "ILLD33_empty_cell_001422.nxs",
+		BckTransmissionSampleDataFile="ILLD33_empty_cell_transm_001428.nxs",
+		DoAzimuthalAverage=False,	
+		Do2DReduction=False,
+		ComputeResolution=True,
+		ReductionProperties="d33")
+
+	# Reduce the sample data
+	output=SANSReduction(Filename="ILLD33_sample_001425.nxs", ReductionProperties="d33",OutputWorkspace="d33out")
+
+	# Rebin
+	Rebin(InputWorkspace='d33out',OutputWorkspace='d33out_rebin',Params='4,0.1,15')
+	
+	# Do a radial integration
+	SANSAzimuthalAverage1D(InputWorkspace='d33out_rebin',Binning='0.001,0.0002,0.03',OutputWorkspace='IQ_curve')
+
+	# Get the OutputWorkspace as a python workspace
+	iq = mtd['IQ_curve']
+	print "This workspace has", iq.getNumDims(), "dimensions and has", iq.getNumberHistograms(), "histograms."
+
+Output:
+
+	This workspace has 2 dimensions and has 1 histograms.
+
 .. categories::
diff --git a/Code/Mantid/docs/source/algorithms/ShowPossibleCells-v1.rst b/Code/Mantid/docs/source/algorithms/ShowPossibleCells-v1.rst
index 6bfbd635650c8369ee1cd8a85387b334a49c9dba..f790794f877de2965a2c6f6ff7fa77d3e449fa95 100644
--- a/Code/Mantid/docs/source/algorithms/ShowPossibleCells-v1.rst
+++ b/Code/Mantid/docs/source/algorithms/ShowPossibleCells-v1.rst
@@ -25,4 +25,25 @@ Journal of Research of the National Institute of Standards and
 Technology, available from:
 nvlpubs.nist.gov/nistpubs/jres/106/6/j66mig.pdf.
 
+Usage
+-----
+
+**Example:**
+
+.. testcode:: ExShowPossibleCells
+
+   ws=LoadIsawPeaks("TOPAZ_3007.peaks")
+   FindUBUsingFFT(ws,MinD=8.0,MaxD=13.0)
+   ShowPossibleCells(PeaksWorkspace=ws)
+   alg = ws.getHistory().lastAlgorithm()
+   print "Num Cells : ", alg.getPropertyValue("NumberOfCells")
+
+
+Output:
+
+.. testoutput:: ExShowPossibleCells
+
+   Num Cells :  2
+
+
 .. categories::
diff --git a/Code/Mantid/docs/source/algorithms/SortByQVectors-v1.rst b/Code/Mantid/docs/source/algorithms/SortByQVectors-v1.rst
index 85a2b0d72d6c75d7c7f861378012bd5fe5d01e46..b16f52b3251b8d50cdeab7149094d437e479be5f 100644
--- a/Code/Mantid/docs/source/algorithms/SortByQVectors-v1.rst
+++ b/Code/Mantid/docs/source/algorithms/SortByQVectors-v1.rst
@@ -13,4 +13,30 @@ This algorithm sorts a group workspace by the qvectors found in the
 qvectors file. Workspaces will be tranformed if the qvectors dimension
 is in the bins. Used for output from LoadSassena.
 
+Usage
+-----
+
+.. include:: ../usagedata-note.txt
+
+.. testcode:: ExSortByQVectors
+
+  
+    ws = LoadSassena("outputSassena_1.4.1.h5", TimeUnit=1.0)
+    print 'workspaces instantiated: ', ', '.join(ws.getNames())
+    SortByQVectors(InputWorkspace='ws')
+    ws0 = ws[0]
+    for i in range(0, ws0.getNumberHistograms()):
+            print ws0.dataY(i)[0]
+
+Output:
+
+.. testoutput:: ExSortByQVectors
+
+    workspaces instantiated:  ws_qvectors, ws_fq, ws_fq0, ws_fq2, ws_fqt.Re, ws_fqt.Im
+    0.0
+    0.00600600591861
+    0.0120120118372
+    0.0180180184543
+    0.0240240236744
+
 .. categories::
diff --git a/Code/Mantid/docs/source/algorithms/SortDetectors-v1.rst b/Code/Mantid/docs/source/algorithms/SortDetectors-v1.rst
index ce7dc07fe1a538eaf2a0eea0145cea93c91a9869..5b2a2d16d66627f2c88669934bb350a9f2ad96f5 100644
--- a/Code/Mantid/docs/source/algorithms/SortDetectors-v1.rst
+++ b/Code/Mantid/docs/source/algorithms/SortDetectors-v1.rst
@@ -22,8 +22,8 @@ Usage
    upIDs,upDistances,downIDs,downDistances=SortDetectors(ws)
    
    # No upstream detectors
-   print "Type of upID: ",type(upIDs)
-   print "Shape of upDistances: ", upDistances.shape
+   print "Type of upID:",type(upIDs)
+   print "Number of upDistances:",upDistances.shape[0]
    #Downstream detectors
    print "First few values of downIDs: ", downIDs[0:5]
    print "First few values of downDistances: ", downDistances[0], downDistances[1], downDistances[2], downDistances[3],downDistances[4]
@@ -36,8 +36,8 @@ Output:
 
 .. testoutput:: SortDetectors
 
-   Type of upID:  <type 'numpy.ndarray'>
-   Shape of upDistances:  (0,)
+   Type of upID: <type 'numpy.ndarray'>
+   Number of upDistances: 0
    First few values of downIDs:  [ 0  1 10 11  2]
    First few values of downDistances:  5.0 5.0000064 5.0000064 5.00001279998 5.00002559993
    
diff --git a/Code/Mantid/docs/source/algorithms/SortHKL-v1.rst b/Code/Mantid/docs/source/algorithms/SortHKL-v1.rst
index dbabfdf96fa860a02cbf81514a085fbb67141e9a..c4da97ede79f3d799e92793069d2329e12ce7f5b 100644
--- a/Code/Mantid/docs/source/algorithms/SortHKL-v1.rst
+++ b/Code/Mantid/docs/source/algorithms/SortHKL-v1.rst
@@ -14,4 +14,28 @@ the point group, the intensity is averaged and all the equivalent HKLs
 have the same average intensity. Outliers with zscore > 3 from each
 group of equivalent HKLs are not included in the average.
 
+Usage
+-----
+
+**Example - an example of running SortHKL with PointGroup option.**
+
+.. testcode:: ExSortHKLOption
+
+    #load a peaks workspace from file
+    peaks = LoadIsawPeaks(Filename=r'Peaks5637.integrate')
+    peak = peaks.getPeak(0)
+    print "HKL of first peak in table %d" % peak.getH(),peak.getK(),peak.getL()
+    
+    pw,chi2 = SortHKL(InputWorkspace=peaks, PointGroup='-31m (Trigonal - Rhombohedral)')
+    peak = pw.getPeak(0)
+    print "HKL of first peak in table %d" % peak.getH(),peak.getK(),peak.getL()
+
+Output:
+
+.. testoutput:: ExSortHKLOption
+
+    HKL of first peak in table 1 4.0 -9.0
+    HKL of first peak in table 1 3.0 -8.0
+
+
 .. categories::
diff --git a/Code/Mantid/docs/source/algorithms/Stitch1D-v3.rst b/Code/Mantid/docs/source/algorithms/Stitch1D-v3.rst
index 38e8cc8afd4bdceb0e1dde0f2dc9a3210272dd12..c35dd0ee04f6ffb474ebec6de1b33146f2213ba8 100644
--- a/Code/Mantid/docs/source/algorithms/Stitch1D-v3.rst
+++ b/Code/Mantid/docs/source/algorithms/Stitch1D-v3.rst
@@ -22,6 +22,16 @@ The workspaces must be histogrammed. Use
 :ref:`algm-ConvertToHistogram` on workspaces prior to
 passing them to this algorithm.
 
+**Special Value Processing**
+
+Special values, meaning infinite and NaN double precision values, are treated in a different way by the algorithm. The processing is as follows:
+
+#. The workspaces are initially rebinned, as prescribed by the rebin Params (determined automatically if not provided)
+#. Each spectra is searched for signal values and error values that are special values. Positions and type of special value are recorded
+#. Special values found in the previous step are set to zero
+#. Stitching proceeds, integration will not be performed considering any special values
+#. Post processing the indexes of the special values are used to put the special values back where they came from
+
 Usage
 -----
 **Example - a basic example using stitch1D to stitch two workspaces together.**
diff --git a/Code/Mantid/docs/source/concepts/index.rst b/Code/Mantid/docs/source/concepts/index.rst
index bde8bfc0f38b83913c89e7a3e082fd580cbbb464..6e96c12047ffb4e1f6dabfaf06677bb52fe9010c 100644
--- a/Code/Mantid/docs/source/concepts/index.rst
+++ b/Code/Mantid/docs/source/concepts/index.rst
@@ -5,7 +5,7 @@
    a toctree.
    See http://sphinx-doc.org/tutorial.html#defining-document-structure
 
-.. _contents:
+.. _concepts contents:
 
 ===============
  Concepts
diff --git a/Code/Mantid/instrument/IDFs_for_UNIT_TESTING/IDF_for_UNIT_TESTING2_paramFile.xml b/Code/Mantid/instrument/IDFs_for_UNIT_TESTING/IDF_for_UNIT_TESTING2_paramFile.xml
index e41e3966d94c73346d3891e6be22f4f8d44d6a5b..dc46e5af59f5106ad1d1a19f90be506121b1ce6e 100644
--- a/Code/Mantid/instrument/IDFs_for_UNIT_TESTING/IDF_for_UNIT_TESTING2_paramFile.xml
+++ b/Code/Mantid/instrument/IDFs_for_UNIT_TESTING/IDF_for_UNIT_TESTING2_paramFile.xml
@@ -9,4 +9,9 @@
   <parameter name="fjols-test-paramfile"> <value val="50.0" /> </parameter>
 </component-link>
 
+<component-link id="1301" >
+  <parameter name="testDouble"> <value val="25.0" /> </parameter>
+  <parameter name="testString" type="string"> <value val="hello world" /> </parameter>
+</component-link>
+
 </parameter-file>
diff --git a/Code/Mantid/instrument/LET_Definition_dr3to10.xml b/Code/Mantid/instrument/LET_Definition_dr3to10.xml
index d903e6a2b2f233b545d0085dbd050a389089f2c6..b904ce60b66e79c3f5ea17e1205341a66815ac5a 100644
--- a/Code/Mantid/instrument/LET_Definition_dr3to10.xml
+++ b/Code/Mantid/instrument/LET_Definition_dr3to10.xml
@@ -3,8 +3,8 @@
      see http://www.mantidproject.org/IDF -->
 <instrument xmlns="http://www.mantidproject.org/IDF/1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.mantidproject.org/IDF/1.0 Schema/IDFSchema.xsd" 
  name="LET" valid-from   ="2014-05-02 23:59:59"
-                       valid-to     ="2100-01-31 23:59:59"
-		       last-modified="2014-05-08 00:00:00">
+               valid-to     ="2014-07-11 23:59:59"
+               last-modified="2014-07-16 18:27:00">
  
    <defaults>
      <length unit="meter"/>
diff --git a/Code/Mantid/instrument/LET_Definition_dr3to11.xml b/Code/Mantid/instrument/LET_Definition_dr3to11.xml
new file mode 100644
index 0000000000000000000000000000000000000000..3cc255530c56f405e56f7113017cc963c3c3aa27
--- /dev/null
+++ b/Code/Mantid/instrument/LET_Definition_dr3to11.xml
@@ -0,0 +1,690 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- For help on the notation used to specify an Instrument Definition File 
+     see http://www.mantidproject.org/IDF -->
+<instrument xmlns="http://www.mantidproject.org/IDF/1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.mantidproject.org/IDF/1.0 Schema/IDFSchema.xsd" 
+ name="LET" valid-from   ="2014-07-12 00:00:01"
+               valid-to     ="2014-08-31 23:59:59"
+               last-modified="2014-07-16 18:30:0">
+ 
+   <defaults>
+     <length unit="meter"/>
+     <angle unit="degree"/>
+ <location r="0.0" t="0.0" p="0.0" ang="0.0" axis-x="0.0" axis-y="0.0" axis-z="1.0"/>
+     <reference-frame>
+       <!-- The z-axis is set parallel to and in the direction of the beam. the 
+        y-axis points up and the coordinate system is right handed. -->
+       <along-beam axis="z"/>
+       <pointing-up axis="y"/>
+       <handedness val="right"/>
+       <origin val="beam" /> 
+     </reference-frame>
+     <default-view view="cylindrical_y"/>
+     <!-- Comment "components-are-facing" out if you dont want the
+     components defined in this file to face a position by default -->    
+     <components-are-facing x="0.0" y="0.0" z="0.0" />
+   </defaults>
+   <!-- LIST OF PHYSICAL COMPONENTS (which the instrument consists of) -->
+   <!-- detector components -->
+    <properties>
+   </properties>
+   <component type="monitors" idlist="monitors">
+     <location/>
+   </component>
+<component type="door01" idlist="door01">
+ <location />
+ </component>
+<component type="door02" idlist="door02">
+ <location />
+ </component>
+<component type="door03" idlist="door03">
+ <location />
+ </component>
+<component type="door04" idlist="door04">
+ <location />
+ </component>
+<component type="door05" idlist="door05">
+ <location />
+ </component>
+<component type="door06" idlist="door06">
+ <location />
+ </component>
+<component type="door07" idlist="door07">
+ <location />
+ </component>
+<component type="door08" idlist="door08">
+ <location />
+ </component>
+<component type="door09" idlist="door09">
+ <location />
+ </component>
+<component type="door10" idlist="door10">
+ <location />
+ </component>
+<component type="door11" idlist="door11">
+ <location />
+ </component>
+<component type="door12" idlist="door12">
+ <location />
+ </component>
+ <!-- source and sample-position components -->
+   <component type="undulator">
+     <location z="-25.0"> <facing val="none"/> </location>
+   </component>
+ 
+   <component type="nickel-holder">
+     <location> <facing val="none"/> </location>
+   </component>
+ 
+   <!-- DEFINITION OF TYPES -->
+   <!-- Source types -->
+   <type name="undulator" is="Source">
+     <properties />
+     <cylinder id="some-shape">
+       <centre-of-bottom-base r="0.0" t="0.0" p="0.0" />
+       <axis x="0.0" y="0.0" z="1.0" /> 
+       <radius val="0.01" />
+       <height val="0.03" />
+     </cylinder> 
+     <algebra val="some-shape" />
+   </type>
+ 
+   <!-- Sample-position types -->
+   <type name="nickel-holder" is="SamplePos">
+     <properties />
+     <sphere id="some-shape">
+       <centre x="0.0"  y="0.0" z="0.0" />
+       <radius val="0.03" />
+     </sphere>
+     <algebra val="some-shape" />
+   </type>
+ 
+   <!-- Detectors types -->
+   <type name="monitors">
+     <component type="monitor">
+       <location r="17.758" t="180.0" p="0.0" name="monitor1" />
+       <location r="17.060" t="180.0" p="0.0" name="monitor2" />
+       <location r="16.558" t="180.0" p="0.0" name="monitor3" />
+       <location r="13.164" t="180.0" p="0.0" name="monitor4" />
+       <location r="9.255" t="180.0" p="0.0" name="monitor5" />
+       <location r="1.333" t="180.0" p="0.0" name="monitor6" />
+       <location r="1.088" t="180.0" p="0.0" name="monitor7" />
+       <location r="1.088" t="180.0" p="0.0" name="monitor8" />
+     </component>
+   </type>
+ 
+<type name="door01">
+ <component type="LETdoor">
+<location  x="  -1.8805    " z="  2.9519    "> <facing x="0" y="0" z="0"/> </location>
+ </component>
+ </type>
+ 
+<type name="door02">
+ <component type="LETdoor">
+<location  x="  -1.0525    " z="  3.3380    "> <facing x="0" y="0" z="0"/> </location>
+ </component>
+ </type>
+ 
+<type name="door03">
+ <component type="LETdoor">
+<location  x=" -0.15267    " z="  3.4967    "> <facing x="0" y="0" z="0"/> </location>
+ </component>
+ </type>
+ 
+<type name="door04">
+ <component type="LETdoor">
+<location  x="0.75754    " z="  3.4170    "> <facing x="0" y="0" z="0"/> </location>
+ </component>
+ </type>
+ 
+<type name="door05">
+ <component type="LETdoor">
+<location  x=" 1.6161    " z="  3.1045    "> <facing x="0" y="0" z="0"/> </location>
+ </component>
+ </type>
+ 
+<type name="door06">
+ <component type="LETdoor">
+<location  x=" 2.3646    " z="  2.5805    "> <facing x="0" y="0" z="0"/> </location>
+ </component>
+ </type>
+ 
+<type name="door07">
+ <component type="LETdoor">
+<location  x=" 2.9519    " z="  1.8805    "> <facing x="0" y="0" z="0"/> </location>
+ </component>
+ </type>
+ 
+<type name="door08">
+ <component type="LETdoor">
+<location  x=" 3.3380    " z="  1.0525    "> <facing x="0" y="0" z="0"/> </location>
+ </component>
+ </type>
+ 
+<type name="door09">
+ <component type="LETdoor">
+<location  x=" 3.4967    " z=" 0.15267    "> <facing x="0" y="0" z="0"/> </location>
+ </component>
+ </type>
+ 
+<type name="door10">
+ <component type="LETdoor">
+<location  x=" 3.4170    " z="-0.75754    "> <facing x="0" y="0" z="0"/> </location>
+ </component>
+ </type>
+ 
+<type name="door11">
+ <component type="LETdoor">
+<location  x=" 3.1045    " z=" -1.6161    "> <facing x="0" y="0" z="0"/> </location>
+ </component>
+ </type>
+ 
+<type name="door12">
+ <component type="LETdoor">
+<location  x=" 2.5805    " z=" -2.3646    "> <facing x="0" y="0" z="0"/> </location>
+ </component>
+ </type>
+ 
+ 
+ <type name="LETdoor">
+ <properties />
+ <component type="LETtube" outline="yes">
+<location  x="   -0.393024    " z="  -0.221369E-01" name="tube1" />
+<location  x="   -0.367765    " z="  -0.193752E-01" name="tube2" />
+<location  x="   -0.342486    " z="  -0.167970E-01" name="tube3" />
+<location  x="   -0.317189    " z="  -0.144023E-01" name="tube4" />
+<location  x="   -0.291876    " z="  -0.121914E-01" name="tube5" />
+<location  x="   -0.266547    " z="  -0.101643E-01" name="tube6" />
+<location  x="   -0.241204    " z="  -0.832121E-02" name="tube7" />
+<location  x="   -0.215848    " z="  -0.666210E-02" name="tube8" />
+<location  x="   -0.190481    " z="  -0.518712E-02" name="tube9" />
+<location  x="   -0.165104    " z="  -0.389635E-02" name="tube10" />
+<location  x="   -0.139718    " z="  -0.278984E-02" name="tube11" />
+<location  x="   -0.114325    " z="  -0.186766E-02" name="tube12" />
+<location  x="   -0.889254E-01" z="  -0.112986E-02" name="tube13" />
+<location  x="   -0.635215E-01" z="  -0.576474E-03" name="tube14" />
+<location  x="   -0.381142E-01" z="  -0.207534E-03" name="tube15" />
+<location  x="   -0.127050E-01" z="  -0.230596E-04" name="tube16" />
+<location  x="  0.127050E-01" z="  -0.230596E-04" name="tube17" />
+<location  x="  0.381142E-01" z="  -0.207534E-03" name="tube18" />
+<location  x="  0.635215E-01" z="  -0.576474E-03" name="tube19" />
+<location  x="  0.889254E-01" z="  -0.112986E-02" name="tube20" />
+<location  x="  0.114325    " z="  -0.186766E-02" name="tube21" />
+<location  x="  0.139718    " z="  -0.278984E-02" name="tube22" />
+<location  x="  0.165104    " z="  -0.389635E-02" name="tube23" />
+<location  x="  0.190481    " z="  -0.518712E-02" name="tube24" />
+<location  x="  0.215848    " z="  -0.666210E-02" name="tube25" />
+<location  x="  0.241204    " z="  -0.832121E-02" name="tube26" />
+<location  x="  0.266547    " z="  -0.101643E-01" name="tube27" />
+<location  x="  0.291876    " z="  -0.121914E-01" name="tube28" />
+<location  x="  0.317189    " z="  -0.144023E-01" name="tube29" />
+<location  x="  0.342486    " z="  -0.167970E-01" name="tube30" />
+<location  x="  0.367765    " z="  -0.193752E-01" name="tube31" />
+<location  x="  0.393024    " z="  -0.221369E-01" name="tube32" />
+ </component>
+ </type>
+ 
+ <type name="LETtube" outline="yes">
+ <component type="pixel">
+   <locations y="-2.00304" y-end="2.00304" n-elements="1024" />
+ </component>
+ </type>
+ 
+ <type name="monitor" is="monitor">
+  <properties/>
+  <cylinder id="some-shape">
+ <centre-of-bottom-base r="0.0" t="0.0" p="0.0" />
+ <axis x="0.0" y="0.0" z="1.0" />
+ <radius val="0.01" />
+ <height val="0.03" />
+ </cylinder>
+ <algebra val="some-shape" />
+ </type>
+ 
+ <type name="pixel" is="detector">
+ <cylinder id="cyl-approx">
+   <centre-of-bottom-base r="0.0" t="0.0" p="0.0" />
+   <axis x="0.0" y="0.2" z="0.0" />
+  <radius val="   0.127000E-01" />
+  <height val="   0.391602E-02" />
+ </cylinder>
+ <algebra val="cyl-approx" />
+  </type>
+ 
+  <!-- MONITOR ID LISTS -->
+   <idlist idname="monitors">
+     <id start="11" end="81" step="10"/>
+   </idlist>
+ 
+   <!-- DETECTOR ID LISTS -->
+   <idlist idname="door01">
+  <id start="1110001" end="1111024" />
+  <id start="1120001" end="1121024" />
+  <id start="1130001" end="1131024" />
+  <id start="1140001" end="1141024" />
+  <id start="1150001" end="1151024" />
+  <id start="1160001" end="1161024" />
+  <id start="1170001" end="1171024" />
+  <id start="1180001" end="1181024" />
+  <id start="1210001" end="1211024" />
+  <id start="1220001" end="1221024" />
+  <id start="1230001" end="1231024" />
+  <id start="1240001" end="1241024" />
+  <id start="1250001" end="1251024" />
+  <id start="1260001" end="1261024" />
+  <id start="1270001" end="1271024" />
+  <id start="1280001" end="1281024" />
+  <id start="1310001" end="1311024" />
+  <id start="1320001" end="1321024" />
+  <id start="1330001" end="1331024" />
+  <id start="1340001" end="1341024" />
+  <id start="1350001" end="1351024" />
+  <id start="1360001" end="1361024" />
+  <id start="1370001" end="1371024" />
+  <id start="1380001" end="1381024" />
+  <id start="1410001" end="1411024" />
+  <id start="1420001" end="1421024" />
+  <id start="1430001" end="1431024" />
+  <id start="1440001" end="1441024" />
+  <id start="1450001" end="1451024" />
+  <id start="1460001" end="1461024" />
+  <id start="1470001" end="1471024" />
+  <id start="1480001" end="1481024" />
+ </idlist>
+   <idlist idname="door02">
+  <id start="2110001" end="2111024" />
+  <id start="2120001" end="2121024" />
+  <id start="2130001" end="2131024" />
+  <id start="2140001" end="2141024" />
+  <id start="2150001" end="2151024" />
+  <id start="2160001" end="2161024" />
+  <id start="2170001" end="2171024" />
+  <id start="2180001" end="2181024" />
+  <id start="2210001" end="2211024" />
+  <id start="2220001" end="2221024" />
+  <id start="2230001" end="2231024" />
+  <id start="2240001" end="2241024" />
+  <id start="2250001" end="2251024" />
+  <id start="2260001" end="2261024" />
+  <id start="2270001" end="2271024" />
+  <id start="2280001" end="2281024" />
+  <id start="2310001" end="2311024" />
+  <id start="2320001" end="2321024" />
+  <id start="2330001" end="2331024" />
+  <id start="2340001" end="2341024" />
+  <id start="2350001" end="2351024" />
+  <id start="2360001" end="2361024" />
+  <id start="2370001" end="2371024" />
+  <id start="2380001" end="2381024" />
+  <id start="2410001" end="2411024" />
+  <id start="2420001" end="2421024" />
+  <id start="2430001" end="2431024" />
+  <id start="2440001" end="2441024" />
+  <id start="2450001" end="2451024" />
+  <id start="2460001" end="2461024" />
+  <id start="2470001" end="2471024" />
+  <id start="2480001" end="2481024" />
+ </idlist>
+   <idlist idname="door03">
+  <id start="3110001" end="3111024" />
+  <id start="3120001" end="3121024" />
+  <id start="3130001" end="3131024" />
+  <id start="3140001" end="3141024" />
+  <id start="3150001" end="3151024" />
+  <id start="3160001" end="3161024" />
+  <id start="3170001" end="3171024" />
+  <id start="3180001" end="3181024" />
+  <id start="3210001" end="3211024" />
+  <id start="3220001" end="3221024" />
+  <id start="3230001" end="3231024" />
+  <id start="3240001" end="3241024" />
+  <id start="3250001" end="3251024" />
+  <id start="3260001" end="3261024" />
+  <id start="3270001" end="3271024" />
+  <id start="3280001" end="3281024" />
+  <id start="3310001" end="3311024" />
+  <id start="3320001" end="3321024" />
+  <id start="3330001" end="3331024" />
+  <id start="3340001" end="3341024" />
+  <id start="3350001" end="3351024" />
+  <id start="3360001" end="3361024" />
+  <id start="3370001" end="3371024" />
+  <id start="3380001" end="3381024" />
+  <id start="3410001" end="3411024" />
+  <id start="3420001" end="3421024" />
+  <id start="3430001" end="3431024" />
+  <id start="3440001" end="3441024" />
+  <id start="3450001" end="3451024" />
+  <id start="3460001" end="3461024" />
+  <id start="3470001" end="3471024" />
+  <id start="3480001" end="3481024" />
+ </idlist>
+   <idlist idname="door04">
+  <id start="4110001" end="4111024" />
+  <id start="4120001" end="4121024" />
+  <id start="4130001" end="4131024" />
+  <id start="4140001" end="4141024" />
+  <id start="4150001" end="4151024" />
+  <id start="4160001" end="4161024" />
+  <id start="4170001" end="4171024" />
+  <id start="4180001" end="4181024" />
+  <id start="4210001" end="4211024" />
+  <id start="4220001" end="4221024" />
+  <id start="4230001" end="4231024" />
+  <id start="4240001" end="4241024" />
+  <id start="4250001" end="4251024" />
+  <id start="4260001" end="4261024" />
+  <id start="4270001" end="4271024" />
+  <id start="4280001" end="4281024" />
+  <id start="4310001" end="4311024" />
+  <id start="4320001" end="4321024" />
+  <id start="4330001" end="4331024" />
+  <id start="4340001" end="4341024" />
+  <id start="4350001" end="4351024" />
+  <id start="4360001" end="4361024" />
+  <id start="4370001" end="4371024" />
+  <id start="4380001" end="4381024" />
+  <id start="4410001" end="4411024" />
+  <id start="4420001" end="4421024" />
+  <id start="4430001" end="4431024" />
+  <id start="4440001" end="4441024" />
+  <id start="4450001" end="4451024" />
+  <id start="4460001" end="4461024" />
+  <id start="4470001" end="4471024" />
+  <id start="4480001" end="4481024" />
+ </idlist>
+   <idlist idname="door05">
+  <id start="5110001" end="5111024" />
+  <id start="5120001" end="5121024" />
+  <id start="5130001" end="5131024" />
+  <id start="5140001" end="5141024" />
+  <id start="5150001" end="5151024" />
+  <id start="5160001" end="5161024" />
+  <id start="5170001" end="5171024" />
+  <id start="5180001" end="5181024" />
+  <id start="5210001" end="5211024" />
+  <id start="5220001" end="5221024" />
+  <id start="5230001" end="5231024" />
+  <id start="5240001" end="5241024" />
+  <id start="5250001" end="5251024" />
+  <id start="5260001" end="5261024" />
+  <id start="5270001" end="5271024" />
+  <id start="5280001" end="5281024" />
+  <id start="5310001" end="5311024" />
+  <id start="5320001" end="5321024" />
+  <id start="5330001" end="5331024" />
+  <id start="5340001" end="5341024" />
+  <id start="5350001" end="5351024" />
+  <id start="5360001" end="5361024" />
+  <id start="5370001" end="5371024" />
+  <id start="5380001" end="5381024" />
+  <id start="5410001" end="5411024" />
+  <id start="5420001" end="5421024" />
+  <id start="5430001" end="5431024" />
+  <id start="5440001" end="5441024" />
+  <id start="5450001" end="5451024" />
+  <id start="5460001" end="5461024" />
+  <id start="5470001" end="5471024" />
+  <id start="5480001" end="5481024" />
+ </idlist>
+   <idlist idname="door06">
+  <id start="6110001" end="6111024" />
+  <id start="6120001" end="6121024" />
+  <id start="6130001" end="6131024" />
+  <id start="6140001" end="6141024" />
+  <id start="6150001" end="6151024" />
+  <id start="6160001" end="6161024" />
+  <id start="6170001" end="6171024" />
+  <id start="6180001" end="6181024" />
+  <id start="6210001" end="6211024" />
+  <id start="6220001" end="6221024" />
+  <id start="6230001" end="6231024" />
+  <id start="6240001" end="6241024" />
+  <id start="6250001" end="6251024" />
+  <id start="6260001" end="6261024" />
+  <id start="6270001" end="6271024" />
+  <id start="6280001" end="6281024" />
+  <id start="6310001" end="6311024" />
+  <id start="6320001" end="6321024" />
+  <id start="6330001" end="6331024" />
+  <id start="6340001" end="6341024" />
+  <id start="6350001" end="6351024" />
+  <id start="6360001" end="6361024" />
+  <id start="6370001" end="6371024" />
+  <id start="6380001" end="6381024" />
+  <id start="6410001" end="6411024" />
+  <id start="6420001" end="6421024" />
+  <id start="6430001" end="6431024" />
+  <id start="6440001" end="6441024" />
+  <id start="6450001" end="6451024" />
+  <id start="6460001" end="6461024" />
+  <id start="6470001" end="6471024" />
+  <id start="6480001" end="6481024" />
+ </idlist>
+   <idlist idname="door07">
+  <id start="7110001" end="7111024" />
+  <id start="7120001" end="7121024" />
+  <id start="7130001" end="7131024" />
+  <id start="7140001" end="7141024" />
+  <id start="7150001" end="7151024" />
+  <id start="7160001" end="7161024" />
+  <id start="7170001" end="7171024" />
+  <id start="7180001" end="7181024" />
+  <id start="7210001" end="7211024" />
+  <id start="7220001" end="7221024" />
+  <id start="7230001" end="7231024" />
+  <id start="7240001" end="7241024" />
+  <id start="7250001" end="7251024" />
+  <id start="7260001" end="7261024" />
+  <id start="7270001" end="7271024" />
+  <id start="7280001" end="7281024" />
+  <id start="7310001" end="7311024" />
+  <id start="7320001" end="7321024" />
+  <id start="7330001" end="7331024" />
+  <id start="7340001" end="7341024" />
+  <id start="7350001" end="7351024" />
+  <id start="7360001" end="7361024" />
+  <id start="7370001" end="7371024" />
+  <id start="7380001" end="7381024" />
+  <id start="7410001" end="7411024" />
+  <id start="7420001" end="7421024" />
+  <id start="7430001" end="7431024" />
+  <id start="7440001" end="7441024" />
+  <id start="7450001" end="7451024" />
+  <id start="7460001" end="7461024" />
+  <id start="7470001" end="7471024" />
+  <id start="7480001" end="7481024" />
+ </idlist>
+   <idlist idname="door08">
+  <id start="8110001" end="8111024" />
+  <id start="8120001" end="8121024" />
+  <id start="8130001" end="8131024" />
+  <id start="8140001" end="8141024" />
+  <id start="8150001" end="8151024" />
+  <id start="8160001" end="8161024" />
+  <id start="8170001" end="8171024" />
+  <id start="8180001" end="8181024" />
+  <id start="8210001" end="8211024" />
+  <id start="8220001" end="8221024" />
+  <id start="8230001" end="8231024" />
+  <id start="8240001" end="8241024" />
+  <id start="8250001" end="8251024" />
+  <id start="8260001" end="8261024" />
+  <id start="8270001" end="8271024" />
+  <id start="8280001" end="8281024" />
+  <id start="8310001" end="8311024" />
+  <id start="8320001" end="8321024" />
+  <id start="8330001" end="8331024" />
+  <id start="8340001" end="8341024" />
+  <id start="8350001" end="8351024" />
+  <id start="8360001" end="8361024" />
+  <id start="8370001" end="8371024" />
+  <id start="8380001" end="8381024" />
+  <id start="8410001" end="8411024" />
+  <id start="8420001" end="8421024" />
+  <id start="8430001" end="8431024" />
+  <id start="8440001" end="8441024" />
+  <id start="8450001" end="8451024" />
+  <id start="8460001" end="8461024" />
+  <id start="8470001" end="8471024" />
+  <id start="8480001" end="8481024" />
+ </idlist>
+   <idlist idname="door09">
+  <id start="9110001" end="9111024" />
+  <id start="9120001" end="9121024" />
+  <id start="9130001" end="9131024" />
+  <id start="9140001" end="9141024" />
+  <id start="9150001" end="9151024" />
+  <id start="9160001" end="9161024" />
+  <id start="9170001" end="9171024" />
+  <id start="9180001" end="9181024" />
+  <id start="9210001" end="9211024" />
+  <id start="9220001" end="9221024" />
+  <id start="9230001" end="9231024" />
+  <id start="9240001" end="9241024" />
+  <id start="9250001" end="9251024" />
+  <id start="9260001" end="9261024" />
+  <id start="9270001" end="9271024" />
+  <id start="9280001" end="9281024" />
+  <id start="9310001" end="9311024" />
+  <id start="9320001" end="9321024" />
+  <id start="9330001" end="9331024" />
+  <id start="9340001" end="9341024" />
+  <id start="9350001" end="9351024" />
+  <id start="9360001" end="9361024" />
+  <id start="9370001" end="9371024" />
+  <id start="9380001" end="9381024" />
+  <id start="9410001" end="9411024" />
+  <id start="9420001" end="9421024" />
+  <id start="9430001" end="9431024" />
+  <id start="9440001" end="9441024" />
+  <id start="9450001" end="9451024" />
+  <id start="9460001" end="9461024" />
+  <id start="9470001" end="9471024" />
+  <id start="9480001" end="9481024" />
+ </idlist>
+   <idlist idname="door10">
+  <id start="10110001" end="10111024" />
+  <id start="10120001" end="10121024" />
+  <id start="10130001" end="10131024" />
+  <id start="10140001" end="10141024" />
+  <id start="10150001" end="10151024" />
+  <id start="10160001" end="10161024" />
+  <id start="10170001" end="10171024" />
+  <id start="10180001" end="10181024" />
+  <id start="10210001" end="10211024" />
+  <id start="10220001" end="10221024" />
+  <id start="10230001" end="10231024" />
+  <id start="10240001" end="10241024" />
+  <id start="10250001" end="10251024" />
+  <id start="10260001" end="10261024" />
+  <id start="10270001" end="10271024" />
+  <id start="10280001" end="10281024" />
+  <id start="10310001" end="10311024" />
+  <id start="10320001" end="10321024" />
+  <id start="10330001" end="10331024" />
+  <id start="10340001" end="10341024" />
+  <id start="10350001" end="10351024" />
+  <id start="10360001" end="10361024" />
+  <id start="10370001" end="10371024" />
+  <id start="10380001" end="10381024" />
+  <id start="10410001" end="10411024" />
+  <id start="10420001" end="10421024" />
+  <id start="10430001" end="10431024" />
+  <id start="10440001" end="10441024" />
+  <id start="10450001" end="10451024" />
+  <id start="10460001" end="10461024" />
+  <id start="10470001" end="10471024" />
+  <id start="10480001" end="10481024" />
+ </idlist>
+   <idlist idname="door11">
+  <id start="11110001" end="11111024" />
+  <id start="11120001" end="11121024" />
+  <id start="11130001" end="11131024" />
+  <id start="11140001" end="11141024" />
+  <id start="11150001" end="11151024" />
+  <id start="11160001" end="11161024" />
+  <id start="11170001" end="11171024" />
+  <id start="11180001" end="11181024" />
+  <id start="11210001" end="11211024" />
+  <id start="11220001" end="11221024" />
+  <id start="11230001" end="11231024" />
+  <id start="11240001" end="11241024" />
+  <id start="11250001" end="11251024" />
+  <id start="11260001" end="11261024" />
+  <id start="11270001" end="11271024" />
+  <id start="11280001" end="11281024" />
+  <id start="11310001" end="11311024" />
+  <id start="11320001" end="11321024" />
+  <id start="11330001" end="11331024" />
+  <id start="11340001" end="11341024" />
+  <id start="11350001" end="11351024" />
+  <id start="11360001" end="11361024" />
+  <id start="11370001" end="11371024" />
+  <id start="11380001" end="11381024" />
+  <id start="11410001" end="11411024" />
+  <id start="11420001" end="11421024" />
+  <id start="11430001" end="11431024" />
+  <id start="11440001" end="11441024" />
+  <id start="11450001" end="11451024" />
+  <id start="11460001" end="11461024" />
+  <id start="11470001" end="11471024" />
+  <id start="11480001" end="11481024" />
+ </idlist>
+   <idlist idname="door12">
+  <id start="12110001" end="12111024" />
+  <id start="12120001" end="12121024" />
+  <id start="12130001" end="12131024" />
+  <id start="12140001" end="12141024" />
+  <id start="12150001" end="12151024" />
+  <id start="12160001" end="12161024" />
+  <id start="12170001" end="12171024" />
+  <id start="12180001" end="12181024" />
+  <id start="12210001" end="12211024" />
+  <id start="12220001" end="12221024" />
+  <id start="12230001" end="12231024" />
+  <id start="12240001" end="12241024" />
+  <id start="12250001" end="12251024" />
+  <id start="12260001" end="12261024" />
+  <id start="12270001" end="12271024" />
+  <id start="12280001" end="12281024" />
+  <id start="12310001" end="12311024" />
+  <id start="12320001" end="12321024" />
+  <id start="12330001" end="12331024" />
+  <id start="12340001" end="12341024" />
+  <id start="12350001" end="12351024" />
+  <id start="12360001" end="12361024" />
+  <id start="12370001" end="12371024" />
+  <id start="12380001" end="12381024" />
+  <id start="12410001" end="12411024" />
+  <id start="12420001" end="12421024" />
+  <id start="12430001" end="12431024" />
+  <id start="12440001" end="12441024" />
+  <id start="12450001" end="12451024" />
+  <id start="12460001" end="12461024" />
+  <id start="12470001" end="12471024" />
+  <id start="12480001" end="12481024" />
+ </idlist>
+  <!-- DETECTOR PARAMETERS -->
+  <component-link name="monitors">
+   <parameter name="DelayTime">
+      <value units="microseconds" val="0"/>
+   </parameter>
+  </component-link>
+
+  <!-- Set the same across the rest of the instrument -->
+  <component-link name = "LET">
+    <parameter name="TubePressure">
+      <value units="atm" val="10.0"/>
+    </parameter>
+    <parameter name="TubeThickness">
+      <value units="metre" val="0.0008"/>
+    </parameter>
+    <parameter name="DelayTime">
+      <value units="microseconds" val="-5.3"/>
+    </parameter>
+  </component-link>
+
+
+
+ </instrument>
+
diff --git a/Code/Mantid/instrument/LET_Parameters_dr3to11.xml b/Code/Mantid/instrument/LET_Parameters_dr3to11.xml
new file mode 100644
index 0000000000000000000000000000000000000000..82bc6ac987edd80aa139c7c6c65960c2e171d254
--- /dev/null
+++ b/Code/Mantid/instrument/LET_Parameters_dr3to11.xml
@@ -0,0 +1,410 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<parameter-file instrument = "LET" valid-from = "2013-06-12T00:00:00">
+
+<component-link name = "LET">
+
+<!-- files properties : -->
+
+<!-- The file which defines proper (calibrated) detector positions 
+     if None - it is undefined -->
+<parameter name="det_cal_file" type="string">
+   <value val="det_LET_cycle12-3.dat"/>
+</parameter>
+<!-- The file which defines detectors to spectra mapping; File extension has to be specified here but filepath not
+     if None - one2one map is used  -->
+<parameter name="map_file" type="string">
+   <value val="LET_one2one_123.map"/>
+</parameter>
+
+<!-- Extension of the data files obtained from DAE -->
+<parameter name="data_file_ext" type="string">
+   <value val=".raw"/>
+</parameter>
+<!-- The name of the hard mask file to use together with diag masking -->
+<parameter name="hard_mask_file" type="string">
+    <value val="hard.msk"/>
+</parameter>
+<!-- The map file used when calculating absolute units conversion integrals 
+     This map usually groups together large areas of detectors to obtain proper vanadium statistics  -->
+<parameter name="monovan_mapfile" type="string">
+   <value val="LET_rings_123.map"/>
+</parameter>
+
+
+
+
+<!-- RunNumber to use for diag instead of the input run number if none - use input run 
+     if yes, will probably change from command line-->
+<parameter name="mask_run" type="string">
+   <value val="None"/>
+</parameter>
+
+<!-- Energy conversion mode direct/indirect/elastic (the one the reducer understands) -->
+<parameter name="deltaE-mode" type="string">
+  <value val="direct"/>
+</parameter>
+
+<!-- normalise_method normalization. To compare different runs with different length one uses normalization by some flux-dependent parameter
+     Available values are: none (-largely meaningless), monitor-1,monitor-2, current 
+     the acceptable values are defined in DirectEnergyConversion initialization routine as recognized by direct energy conversion normalize method
+     these three are currently disabled/unknown:  uamph peak-->
+<parameter name="normalise_method" type="string">
+    <value val="monitor-1"/>
+</parameter>
+
+<!-- Monitor used to estimate total current on the sample  while normalizing by monitor 1.  -->
+<parameter name="norm-mon1-spec">
+  <value val="73729"/>
+</parameter>
+  
+<!-- Monitor after chopper used to estimate total current on the sample, if normalization is done on monitor 2  -->
+<parameter name="norm-mon2-spec"  type="int">
+    <value val="73729"/>
+</parameter>
+
+<!-- Time interval used for integration to estimate current on the sample 
+    This interval is usually taken around the monitor peak-->
+<parameter name="norm-mon1-min">
+  <value val="10000"/>
+</parameter>
+<parameter name="norm-mon1-max">
+  <value val="12000"/>
+</parameter>
+<parameter name="norm_mon_integration_range"  type="string">
+  <value val="norm-mon1-min:norm-mon1-max"/>
+</parameter>
+
+
+<!-- First spectra number (monitor number) to use when measuring incident energy
+    Should be spectra with well defined energy peak -->
+<parameter name="ei-mon1-spec"  type="int">
+  <value val="73734"/>
+</parameter>
+<!-- Second spectra number (monitor number) to use when measuring incident energy
+     Should be spectra with well defined energy peak -->
+<parameter name="ei-mon2-spec"  type="int">
+  <value val="5506"/>
+</parameter>
+
+<parameter name="ei_mon_spectra"  type="string">
+  <value val="ei-mon1-spec:ei-mon2-spec"/>
+</parameter>
+ 
+<!--if you use some detectors as monitors and work in event mode, one needs to specify the comma separated list of these detectors here 
+    to copy detectors spectra to monitors spectra collected in histogram mode. If no such monitors are used "None" 
+    (with brackets) has to be specified as the value
+-->
+<parameter name="spectra_to_monitors_list"  type="string">
+  <value val="5506"/>
+</parameter>
+<!-- Usually one wants to avoid loading monitors together with data except in special cases. One of this cases is 
+     MARI which monitors numbers are in the beginning of the spectra. If one loads them separately, 
+     spectra numbers change and ISIS hard masks (msk) prepared for workspace with monitors become invalid. 
+     This parameter is actual until Mantid Masking change     
+  -->
+<parameter name="load_monitors_with_workspace"  type="bool">
+<value val="False"/>
+</parameter>
+
+
+
+<parameter name="scale-factor">
+  <value val="1.7016e8"/>
+</parameter>
+
+<parameter name="wb-scale-factor">
+  <value val="1000"/>
+</parameter>
+
+<!-- Remove the count rate seen in the regions of the histograms defined as the background regions -->
+<parameter name="check_background"  type="bool">
+   <value val="False"/>
+</parameter>
+
+<!--  detector_van_range- integratin in E(mev) for detector(white beam) vanadium data [20,100] -->
+<parameter name="wb-integr-min">
+  <value val="0.5"/>
+</parameter>
+<parameter name="wb-integr-max">
+  <value val="200"/>
+</parameter>
+<parameter name="wb_integr_range"   type="string">
+    <value val="wb-integr-min:wb-integr-max"/>
+</parameter>
+
+
+<!-- integration range for background tests  (in TOF) - composite property 
+  Used in test to reject high backgound (FlatBackground) and in High Background tests integration in Diagnostics
+  if diag_background_test_range is not set -->
+<parameter name="bkgd-range-min"> 
+  <value val="90000"/>
+</parameter>
+<parameter name="bkgd-range-max">
+  <value val="95000"/>
+</parameter>
+<parameter name="background_range"  type="string">
+      <value val="bkgd-range-min:bkgd-range-max"/>
+</parameter>
+
+<!-- ******************************** DIAGNOSTICS DEFAILTS **************************************** -->
+
+<!-- Perform diag by bank. These are the spectrum numbers -->
+<parameter name="diag_spectra" type="string">
+  <value val="None"/>
+</parameter>
+
+<!-- Absolute lo threshold for vanadium diag (tiny) -->
+<parameter name="diag_tiny">
+  <value val="1e-10"/>
+</parameter>
+
+<!-- Absolute hi threshold for vanadium diag (large) -->
+<parameter name="diag_huge">
+  <value val="1e10"/>
+</parameter>
+
+<!-- Setting diag to reject zero backgrounds; If true then zeroes in (vanadium) data are masked as fail  -->
+<parameter name="diag_samp_zero"  type="bool">
+  <value val="False"/>
+</parameter>
+
+<!-- Fraction of median to consider counting low for the white beam diag (diag_van_median_rate_limit_hi sv_lo)-->
+<parameter name="diag_samp_lo">
+  <value val="0.0"/>
+</parameter>
+<!-- Fraction of median to consider counting high for the white beam diag (sv_hi)-->
+<parameter name="diag_samp_hi">
+  <value val="1.5"/>
+</parameter>
+
+<!-- Error criterion as a multiple of error bar for background (sv_sig) 
+  i.e. to fail the test, the magnitude of the
+  difference with respect to the median value must also exceed this number of error bars (default=3.3)
+-->  
+<parameter name="diag_samp_sig">
+  <value val="3.3"/>
+</parameter>
+
+<!-- Lower bound defining outliers as fraction of median value (v_out_lo)-->
+<parameter name="diag_van_out_lo">
+  <value val="0.01"/>
+</parameter>
+
+<!-- Upper bound defining outliers as fraction of median value (v_out_hi) -->
+<parameter name="diag_van_out_hi">
+  <value val="100."/>
+</parameter>
+
+<!-- Fraction of median to consider counting low for the white beam diag (vv_lo)  vanlo=0.1  -->
+<parameter name="diag_van_lo">
+  <value val="0.1"/>
+</parameter>
+
+<!-- Fraction of median to consider counting high for the white beam diag (vv_hi) vanhi=1.5 -->
+<parameter name="diag_van_hi">
+  <value val="2.0"/>
+</parameter>
+
+<!-- Error criterion as a multiple of error bar     van_sig  "
+    i.e. to fail the test, the magnitude of the difference with respect to the median value must also exceed this number of error bars (default=0.0)
+-->
+<parameter name="diag_van_sig">
+  <value val="0.0"/>
+</parameter>
+
+<!-- Variation for ratio test with second white beam -->
+<parameter name="diag_variation">
+  <value val="1.1"/>
+</parameter>
+<!-- The range used in diagnostics and rejecting high background.
+  If none, the diag background range uses background ranges from background_range. Has to be directly set otherwise -->
+<parameter name="diag_background_test_range"  type="string" >
+    <value val="None"/>
+</parameter>
+
+<!--  -->
+<!--  Bleeding corrections   -->
+
+<!--  the number of pixels ignored within the bleed test diagnostic -->
+<parameter name="diag_bleed_pixels">
+    <value val="80"/>
+</parameter>
+<!--  the maximum framerate allowed in a tube -->
+<parameter name="diag_bleed_maxrate">
+    <value val="0.01"/>
+</parameter>
+<!-- True if the bleed tests should be run use_bleeding-->
+<parameter name="diag_bleed_test"  type="bool">
+    <value val="True"/>
+</parameter>
+
+<!-- **************************************** DIAGNOSTICS DEFAILTS END ****************************************    -->
+
+
+<!-- **************************************** ABSOLUTE UNITS CORRECTION DEFAULTS ********************************  -->
+<!-- Absolute units conversion average -->
+<parameter name="monovan_lo_bound">
+  <value val="0.01"/>
+</parameter>
+
+<parameter name="monovan_hi_bound">
+  <value val="100"/>
+</parameter>
+
+<!-- This property is the part of the composite definition for abs_units_van_range: 
+ It specifies the relative to incident energy lower integration limit for monochromatic vanadium in the mono-vanadium integration -->
+<parameter name="monovan_lo_frac">
+  <value val="-0.8"/>
+</parameter>
+
+<!-- This property is the part of the composite definition for abs_units_van_range:
+ It specifies the the lower limit of energy range in the monochromatic-vanadium integration 
+ Used only if abs_units_van_range is set to val="monovan_lo_value,monovan_hi_value"-->
+<parameter name="monovan_lo_value">
+  <value val="-40."/>
+</parameter>
+
+<!-- This property is the part of the composite definition for abs_units_van_range
+ It specifies the relative to incident energy higher integration limit for monochromatic vanadium in the mono-vanadium integration -->
+<parameter name="monovan_hi_frac">
+  <value val="0.8"/>
+</parameter>
+<!-- This property is the part of the composite definition for abs_units_van_range
+ It specifies the the higher limit of energy range in the monochromatic-vanadium integration 
+ Used only if abs_units_van_range is set to val="monovan_lo_value,monovan_hi_value"-->
+<parameter name="monovan_hi_value">
+  <value val="40."/>
+</parameter>
+
+<!-- energy range for integration calculating absolute units correction vanadium data. 
+     if None, range is calculated from monovan_hi_frac/monovan_lo_frac 
+     - providing the fractions of the incident energy      
+     if one wants to specify the energy values here it has to be defined in the form:
+    <value val="monovan_lo_value,monovan_hi_value"/>      -->    
+<parameter name="abs_units_van_range"  type="string">
+  <value val="None"/>
+</parameter>
+<!-- Sample mass used in absolute units normalization and should usually be changed by user-->
+<parameter name="sample_mass">
+  <value val="1"/>
+</parameter>
+<!-- Sample rmm used in absolute units normalization should usually be changed by user -->
+<parameter name="sample_rmm">
+  <value val="1"/>
+</parameter>
+<!-- Vanaduim mass used in absolute units normalization and is usually instrument specific (changes rarely) -->
+<parameter name="vanadium-mass">
+  <value val="20.79"/>
+</parameter>
+<!-- if this value set to true, modo-vanadium run is not analyzed and masks obtained for arbitrary units are used for mono-vanadium -->
+<parameter name="use_sam_msk_on_monovan" type = "bool">
+  <value val="False"/>
+</parameter>
+
+<!-- if this value is provided (not None) it is string reperesentation of the number used instead of calculating mono-vanadium based normalization factor 
+   one does not need to provide mono-vanadium run if this value is provided as it will be used instead
+  -->
+<parameter name="mono_correction_factor" type="string">
+  <value val="None"/>
+</parameter>
+  
+<!-- **************************************** ABSOLUTE UNITS CORRECTION DEFAULTS END ****************************  -->
+
+<!-- if defined to true, fix incident energy to this value and do not calculate the energy from the run -->
+<parameter name="fixei"  type="bool">
+    <value val="False"/>
+</parameter>
+
+<!--  ****************************************  Workflow control **************************** -->
+
+<!-- This parameter controls the format of output data written by reducer. 
+    Three values are currently supported, namely .spe, .nxspe, and nexus (mantid workspace) (.nxs)
+     Three possible values for this are defined inin DirectEnergyConversion init routine as recognized by save method 
+     If None is there, no internal script saving occurs and one needs to use external save operations -->  
+<parameter name="save_format" type="string">
+   <value val="None"/>
+</parameter>
+
+<!-- If one wants to sum runs. By default no, as in addition to the key word one has to provide list of input run-numbers
+     but presence of this key here allows to propagate this key-word to the reducer   -->
+<parameter name="sum_runs"  type="bool">
+   <value val="False"/>
+</parameter>
+
+<!-- # Run Detector Efficiency Correction -->
+<parameter name="apply_detector_eff"  type="bool">
+   <value val="True"/>
+</parameter>
+<!-- # Multiply result by ki/kf value -->
+<parameter name="apply_kikf_correction"  type="bool">
+   <value val="True"/>
+</parameter>
+
+<!-- The if true, use only hard mask file specified above and do not run diagnostics procedures -->
+<parameter name="use_hard_mask_only" type="bool">
+    <value val="False"/>
+</parameter>
+
+<!-- Parameter specifies if one wants to run diagnostics (which include applying hard mask file) or not-->
+<parameter name="run_diagnostics" type="bool">
+    <value val="True"/>
+</parameter>
+
+
+
+<!-- If this parameter is set to true, dgreduce will try to load mask from the mask file
+     correspondent to the run if finds it and uses this mask as hard mask only (does not run diagnostics). 
+     If such file has not been found, it will run diagnostics and save the masks into mask file for reuse 
+     Hard Mask file, provided separately or as additional hard mask file is ignored in this case -->
+<parameter name="save_and_reuse_masks"  type="bool">
+   <value val="False"/>
+</parameter>
+
+
+<!-- List of the words which can be used as a command line arguments to define reducer keywords
+     the form is reducer_keword1=synonim1=synonim2=synonim3;reducer_keword1=synonim1a, so, 
+     the reducer keywords are the leftmost values of the keyword assignments below
+     Each keyword met in command line or file above are converted into reducer keyword as below
+-->  
+<parameter name="synonims" type="string">
+   <value val="normalise_method=norm_method;
+       fix_ei=fixei;
+       sum_runs=sum;
+       wb_integr_range=detector_van_range;
+       van_mass=vanadium-mass;
+       check_background = background;       
+       mon1_norm_spec=norm-mon1-spec;
+       mon2_norm_spec=norm-mon2-spec;       
+       scale_factor=scale-factor;
+       wb_scale_factor=wb-scale-factor;
+       monovan_integr_range=abs_units_van_range;
+       monovan_lo_value = monovan-integr-min;
+       monovan_hi_value = monovan-integr-max;       
+       use_hard_mask_only=hardmaskOnly;
+       bkgd_range = background_range;
+       background_test_range = diag_background_test_range;
+       hard_mask_file=hard_mask  =hardmaskPlus;       
+       van_out_lo = diag_van_median_rate_limit_lo=diag_van_out_lo;
+       van_out_hi = diag_van_median_rate_limit_hi=diag_van_out_hi;
+       van_lo     = diag_van_median_sigma_lo=diag_van_lo;
+       van_hi     = diag_van_median_sigma_hi=diag_van_hi;
+       van_sig    = diag_van_median_sigma=diag_van_sig;
+       tiny       = diag_tiny;
+       huge       = diag_huge=large;
+       samp_zero  = diag_remove_zero=diag_samp_zero;
+       samp_lo    = diag_samp_median_sigma_lo=diag_samp_lo;
+       samp_hi    = diag_samp_median_sigma_hi=diag_samp_hi;
+       samp_sig   = diag_samp_median_sigma=diag_samp_sig;
+       variation  = diag_variation;
+       bleed_test = bleed = diag_bleed_test;
+       bleed_maxrate = diag_bleed_maxrate;
+       bleed_pixels  = diag_bleed_pixels;
+       ei-mon2-spec = test_ei2_mon_spectra;
+       ei_mon_spectra=test_mon_spectra_composite"
+    />
+</parameter>
+ 
+  <!-- -->
+</component-link>
+
+</parameter-file>
diff --git a/Code/Mantid/instrument/POLDI_Definition_2013.xml b/Code/Mantid/instrument/POLDI_Definition_2013.xml
index 7295518aeeb11354fafce12e79ca31b423d8ef30..3c2abadcb573c541f0c494ab04f566a705598725 100644
--- a/Code/Mantid/instrument/POLDI_Definition_2013.xml
+++ b/Code/Mantid/instrument/POLDI_Definition_2013.xml
@@ -271,5 +271,8 @@
         <parameter name="element_separation">
             <value val="0.0025" />
         </parameter>
+        <parameter name="efficiency">
+            <value val="0.88" />
+        </parameter>
     </component>
-</instrument>
\ No newline at end of file
+</instrument>
diff --git a/Code/Mantid/instrument/SURF_Parameters.xml b/Code/Mantid/instrument/SURF_Parameters.xml
index 407716e97bc16f05a3d19e1dd3731ed8100a4ec2..7b90a98646dc0b53c0f506f91810512e7c3b41be 100644
--- a/Code/Mantid/instrument/SURF_Parameters.xml
+++ b/Code/Mantid/instrument/SURF_Parameters.xml
@@ -38,7 +38,7 @@
   </parameter>
 
   <parameter name="LambdaMax">
-    <value val="9.0"/>
+    <value val="7.0"/>
   </parameter>
 
   <!-- parameters for efficiency correction -->
diff --git a/Code/Mantid/instrument/Schema/IDFSchema.xsd b/Code/Mantid/instrument/Schema/IDFSchema.xsd
index d1ff50d46fec1a4c19495e89d7ff33137da6af8b..c502ae08648468ad8e819b5641e1b0a52f112412 100644
--- a/Code/Mantid/instrument/Schema/IDFSchema.xsd
+++ b/Code/Mantid/instrument/Schema/IDFSchema.xsd
@@ -728,6 +728,7 @@
               </xs:element>
             </xs:choice>
             <xs:attribute name="name"/>
+            <xs:attribute name="id"/>
             <xs:attribute name="type"/>
           </xs:complexType>
         </xs:element>
diff --git a/Code/Mantid/instrument/Schema/ParameterFileSchema.xsd b/Code/Mantid/instrument/Schema/ParameterFileSchema.xsd
index c898905e605a3f3e1cee4c7461072b54684de43d..232d72f9006af2f75eadb72d28fc16ab67c602f7 100644
--- a/Code/Mantid/instrument/Schema/ParameterFileSchema.xsd
+++ b/Code/Mantid/instrument/Schema/ParameterFileSchema.xsd
@@ -172,6 +172,7 @@
     </xs:choice>
     <xs:attribute name="type"/>
     <xs:attribute name="name"/>
+    <xs:attribute name="id"/>
     <xs:attribute name="idlist"/>
     <xs:attribute name="idstart"/>
     <xs:attribute name="idfillbyfirst"/>
diff --git a/Code/Mantid/instrument/WISH_Definition.xml b/Code/Mantid/instrument/WISH_Definition.xml
index 6cd0d5fa1675ae2a0bb4fab7442bd96a71e4308f..c5ff1b5666e596c9f56eb4e6494ae3c71bb5daf3 100644
--- a/Code/Mantid/instrument/WISH_Definition.xml
+++ b/Code/Mantid/instrument/WISH_Definition.xml
@@ -3,7 +3,7 @@
      see http://www.mantidproject.org/IDF -->
 <instrument xmlns="http://www.mantidproject.org/IDF/1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.mantidproject.org/IDF/1.0 Schema/IDFSchema.xsd" 
  name="WISH" valid-from   ="1900-01-31 23:59:59"
-                        valid-to     ="2012-09-26 17:24:36"
+                        valid-to     ="2012-10-21 17:24:36"
 		        last-modified="2012-11-13 12:00:00">
  
    <defaults>
diff --git a/Code/Mantid/instrument/WISH_Definition_10Panels.xml b/Code/Mantid/instrument/WISH_Definition_10Panels.xml
new file mode 100644
index 0000000000000000000000000000000000000000..cccb01da09a3882f64f28aa0cde178e172397a19
--- /dev/null
+++ b/Code/Mantid/instrument/WISH_Definition_10Panels.xml
@@ -0,0 +1,2916 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- For help on the notation used to specify an Instrument Definition File 
+     see http://www.mantidproject.org/IDF -->
+<instrument xmlns="http://www.mantidproject.org/IDF/1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.mantidproject.org/IDF/1.0 Schema/IDFSchema.xsd" 
+ name="WISH" valid-from   ="2013-11-01 23:59:59"
+                        valid-to     ="2100-01-31 23:59:59"
+		        last-modified="2012-11-13 16:00:00">
+ 
+   <defaults>
+     <length unit="meter"/>
+     <angle unit="degree"/>
+ <location r="0.0" t="0.0" p="0.0" ang="0.0" axis-x="0.0" axis-y="0.0" axis-z="1.0"/>
+     <reference-frame>
+       <!-- The z-axis is set parallel to and in the direction of the beam. the 
+        y-axis points up and the coordinate system is right handed. -->
+       <along-beam axis="z"/>
+       <pointing-up axis="y"/>
+       <handedness val="right"/>
+       <origin val="beam" /> 
+     </reference-frame>
+     <offsets spherical="vectors" />
+     <!-- Comment "components-are-facing" out if you dont want the
+     components defined in this file to face a position by default -->    
+     <components-are-facing x="0.0" y="0.0" z="0.0" />
+     <default-view view="cylindrical_y"/>
+   </defaults>
+   <!-- LIST OF PHYSICAL COMPONENTS (which the instrument consists of) -->
+   <!-- detector components -->
+    <properties>
+   </properties>
+   <component type="monitors" idlist="monitors">
+     <location/>
+   </component> 
+ <component type="panel01" idlist="panel01">
+ <location />
+ </component>
+ <component type="panel02" idlist="panel02">
+ <location />
+ </component>
+ <component type="panel03" idlist="panel03">
+ <location />
+ </component>
+ <component type="panel04" idlist="panel04">
+ <location />
+ </component>
+ <component type="panel05" idlist="panel05"> 
+ <location />
+ </component>
+ <component type="panel10" idlist="panel10"> 
+ <location />
+ </component>
+ <component type="panel09" idlist="panel09"> 
+ <location />
+ </component>
+ <component type="panel08" idlist="panel08"> 
+ <location />
+ </component>
+ <component type="panel07" idlist="panel07"> 
+ <location />
+ </component>
+ <component type="panel06" idlist="panel06"> 
+ <location />
+ </component>
+ <!-- source and sample-position components -->
+   <component type="undulator">
+     <location z="-40.0"> <facing val="none"/> </location>
+   </component>
+   <component type="nickel-holder">
+     <location> <facing val="none"/> </location>
+   </component>
+ 
+   <!-- DEFINITION OF TYPES -->
+   <!-- Source types -->
+   <type name="undulator" is="Source">
+     <properties />
+     <cylinder id="some-shape">
+       <centre-of-bottom-base r="0.0" t="0.0" p="0.0" />
+       <axis x="0.0" y="0.0" z="1.0" /> 
+       <radius val="0.01" />
+       <height val="0.03" />
+     </cylinder> 
+     <algebra val="some-shape" />
+   </type>
+ 
+   <!-- Sample-position types -->
+   <type name="nickel-holder" is="SamplePos">
+     <properties />
+     <sphere id="some-shape">
+       <centre x="0.0"  y="0.0" z="0.0" />
+       <radius val="0.03" />
+     </sphere>
+     <algebra val="some-shape" />
+   </type>
+ 
+   <!-- Detectors types -->
+   <type name="monitors">
+     <component type="monitor">
+       <location r="32.70" t="180.0" p="0.0" name="monitor1" />
+       <location r="30.964" t="180.0" p="0.0" name="monitor2" />
+       <location r="9.95" t="180.0" p="0.0" name="monitor3" />
+       <location r="1.5" t="180.0" p="0.0" name="monitor4" />
+       <location r="1.50" t="0.0" p="0.0" name="monitor5" />
+     </component>
+   </type>
+ 
+<type name="panel01">
+ <component type="WISHpanel">
+<location  x="-0.96521    " z="  1.9790    " name="WISHpanel01" > <facing x="0" y="0" z="0"/> </location>
+ </component>
+ </type>
+<type name="panel02">
+ <component type="WISHpanel">
+<location  x=" -1.8672    " z="  1.1668    " name="WISHpanel02" > <facing x="0" y="0" z="0"/> </location>
+ </component>
+ </type>
+<type name="panel03">
+ <component type="WISHpanel">
+<location  x=" -2.2018    " z="-0.96244E-07" name="WISHpanel03" > <facing x="0" y="0" z="0"/> </location>
+ </component>
+ </type>
+<type name="panel04">
+ <component type="WISHpanel">
+<location  x=" -1.8672    " z=" -1.1668    " name="WISHpanel04" > <facing x="0" y="0" z="0"/> </location>
+ </component>
+ </type>
+<type name="panel05">
+ <component type="WISHpanel">
+<location  x="-0.96521    " z=" -1.9790    " name="WISHpanel05" > <facing x="0" y="0" z="0"/> </location>
+ </component>
+ </type>
+<type name="panel10">
+ <component type="WISHpanel">
+<location  x="0.96521    " z=" -1.9790    " name="WISHpanel10" > <facing x="0" y="0" z="0"/> </location>
+ </component>
+ </type>
+<type name="panel09">
+ <component type="WISHpanel">
+<location  x=" 1.8672    " z=" -1.1668    " name="WISHpanel09" > <facing x="0" y="0" z="0"/> </location>
+ </component>
+ </type>
+<type name="panel08">
+ <component type="WISHpanel">
+<location  x=" 2.2018    " z="-0.96244E-07" name="WISHpanel08" > <facing x="0" y="0" z="0"/> </location>
+ </component>
+ </type>
+<type name="panel07">
+ <component type="WISHpanel">
+<location  x=" 1.8672    " z="  1.1668    " name="WISHpanel07" > <facing x="0" y="0" z="0"/> </location>
+ </component>
+ </type>
+<type name="panel06">
+ <component type="WISHpanel">
+<location  x=" 0.96521    " z="  1.9790    " name="WISHpanel01" > <facing x="0" y="0" z="0"/> </location>
+ </component>
+ </type>
+ <type name="WISHpanel">
+ <properties />
+ <component type="tubeup">
+<location  x="   0.603717    " z="  -0.825844E-01" name="tube001" />
+<location  x="   0.588122    " z="  -0.781998E-01" name="tube003" />
+<location  x="   0.572495    " z="  -0.739301E-01" name="tube005" />
+<location  x="   0.556837    " z="  -0.697755E-01" name="tube007" />
+<location  x="   0.541148    " z="  -0.657362E-01" name="tube009" />
+<location  x="   0.525431    " z="  -0.618124E-01" name="tube011" />
+<location  x="   0.509685    " z="  -0.580044E-01" name="tube013" />
+<location  x="   0.493911    " z="  -0.543124E-01" name="tube015" />
+<location  x="   0.478111    " z="  -0.507365E-01" name="tube017" />
+<location  x="   0.462284    " z="  -0.472769E-01" name="tube019" />
+<location  x="   0.446433    " z="  -0.439339E-01" name="tube021" />
+<location  x="   0.430558    " z="  -0.407076E-01" name="tube023" />
+<location  x="   0.414659    " z="  -0.375982E-01" name="tube025" />
+<location  x="   0.398738    " z="  -0.346059E-01" name="tube027" />
+<location  x="   0.382795    " z="  -0.317307E-01" name="tube029" />
+<location  x="   0.366831    " z="  -0.289730E-01" name="tube031" />
+<location  x="   0.350848    " z="  -0.263328E-01" name="tube033" />
+<location  x="   0.334846    " z="  -0.238102E-01" name="tube035" />
+<location  x="   0.318825    " z="  -0.214055E-01" name="tube037" />
+<location  x="   0.302787    " z="  -0.191187E-01" name="tube039" />
+<location  x="   0.286733    " z="  -0.169500E-01" name="tube041" />
+<location  x="   0.270664    " z="  -0.148994E-01" name="tube043" />
+<location  x="   0.254579    " z="  -0.129671E-01" name="tube045" />
+<location  x="   0.238481    " z="  -0.111532E-01" name="tube047" />
+<location  x="   0.222370    " z="  -0.945783E-02" name="tube049" />
+<location  x="   0.206247    " z="  -0.788102E-02" name="tube051" />
+<location  x="   0.190113    " z="  -0.642288E-02" name="tube053" />
+<location  x="   0.173968    " z="  -0.508349E-02" name="tube055" />
+<location  x="   0.157815    " z="  -0.386292E-02" name="tube057" />
+<location  x="   0.141652    " z="  -0.276124E-02" name="tube059" />
+<location  x="   0.125482    " z="  -0.177850E-02" name="tube061" />
+<location  x="   0.109305    " z="  -0.914756E-03" name="tube063" />
+<location  x="   0.931222E-01" z="  -0.170062E-03" name="tube065" />
+<location  x="   0.769343E-01" z="   0.455547E-03" name="tube067" />
+<location  x="   0.607423E-01" z="   0.962035E-03" name="tube069" />
+<location  x="   0.445470E-01" z="   0.134938E-02" name="tube071" />
+<location  x="   0.283492E-01" z="   0.161755E-02" name="tube073" />
+<location  x="   0.121499E-01" z="   0.176654E-02" name="tube075" />
+<location  x="  -0.405000E-02" z="   0.179634E-02" name="tube077" />
+<location  x="  -0.202497E-01" z="   0.170694E-02" name="tube079" />
+<location  x="  -0.364483E-01" z="   0.149836E-02" name="tube081" />
+<location  x="  -0.526450E-01" z="   0.117060E-02" name="tube083" />
+<location  x="  -0.688388E-01" z="   0.723683E-03" name="tube085" />
+<location  x="  -0.850289E-01" z="   0.157631E-03" name="tube087" />
+<location  x="  -0.101214    " z="  -0.527525E-03" name="tube089" />
+<location  x="  -0.117394    " z="  -0.133175E-02" name="tube091" />
+<location  x="  -0.133568    " z="  -0.225499E-02" name="tube093" />
+<location  x="  -0.149734    " z="  -0.329721E-02" name="tube095" />
+<location  x="  -0.165893    " z="  -0.445835E-02" name="tube097" />
+<location  x="  -0.182042    " z="  -0.573834E-02" name="tube099" />
+<location  x="  -0.198181    " z="  -0.713712E-02" name="tube101" />
+<location  x="  -0.214310    " z="  -0.865460E-02" name="tube103" />
+<location  x="  -0.230427    " z="  -0.102907E-01" name="tube105" />
+<location  x="  -0.246532    " z="  -0.120454E-01" name="tube107" />
+<location  x="  -0.262623    " z="  -0.139185E-01" name="tube109" />
+<location  x="  -0.278700    " z="  -0.159099E-01" name="tube111" />
+<location  x="  -0.294762    " z="  -0.180196E-01" name="tube113" />
+<location  x="  -0.310808    " z="  -0.202473E-01" name="tube115" />
+<location  x="  -0.326838    " z="  -0.225931E-01" name="tube117" />
+<location  x="  -0.342849    " z="  -0.250568E-01" name="tube119" />
+<location  x="  -0.358842    " z="  -0.276382E-01" name="tube121" />
+<location  x="  -0.374816    " z="  -0.303372E-01" name="tube123" />
+<location  x="  -0.390769    " z="  -0.331536E-01" name="tube125" />
+<location  x="  -0.406701    " z="  -0.360874E-01" name="tube127" />
+<location  x="  -0.422611    " z="  -0.391383E-01" name="tube129" />
+<location  x="  -0.438498    " z="  -0.423062E-01" name="tube131" />
+<location  x="  -0.454362    " z="  -0.455908E-01" name="tube133" />
+<location  x="  -0.470201    " z="  -0.489921E-01" name="tube135" />
+<location  x="  -0.486014    " z="  -0.525099E-01" name="tube137" />
+<location  x="  -0.501801    " z="  -0.561439E-01" name="tube139" />
+<location  x="  -0.517561    " z="  -0.598939E-01" name="tube141" />
+<location  x="  -0.533293    " z="  -0.637599E-01" name="tube143" />
+<location  x="  -0.548996    " z="  -0.677414E-01" name="tube145" />
+<location  x="  -0.564670    " z="  -0.718384E-01" name="tube147" />
+<location  x="  -0.580312    " z="  -0.760506E-01" name="tube149" />
+<location  x="  -0.595924    " z="  -0.803777E-01" name="tube151" />
+ </component>
+ <component type="tubedown">
+<location  x="   0.595924    " z="  -0.803777E-01" name="tube002" />
+<location  x="   0.580312    " z="  -0.760506E-01" name="tube004" />
+<location  x="   0.564670    " z="  -0.718384E-01" name="tube006" />
+<location  x="   0.548996    " z="  -0.677414E-01" name="tube008" />
+<location  x="   0.533293    " z="  -0.637599E-01" name="tube010" />
+<location  x="   0.517561    " z="  -0.598939E-01" name="tube012" />
+<location  x="   0.501801    " z="  -0.561439E-01" name="tube014" />
+<location  x="   0.486014    " z="  -0.525099E-01" name="tube016" />
+<location  x="   0.470201    " z="  -0.489921E-01" name="tube018" />
+<location  x="   0.454362    " z="  -0.455908E-01" name="tube020" />
+<location  x="   0.438498    " z="  -0.423062E-01" name="tube022" />
+<location  x="   0.422611    " z="  -0.391383E-01" name="tube024" />
+<location  x="   0.406701    " z="  -0.360874E-01" name="tube026" />
+<location  x="   0.390769    " z="  -0.331536E-01" name="tube028" />
+<location  x="   0.374816    " z="  -0.303372E-01" name="tube030" />
+<location  x="   0.358842    " z="  -0.276382E-01" name="tube032" />
+<location  x="   0.342849    " z="  -0.250568E-01" name="tube034" />
+<location  x="   0.326838    " z="  -0.225931E-01" name="tube036" />
+<location  x="   0.310808    " z="  -0.202473E-01" name="tube038" />
+<location  x="   0.294762    " z="  -0.180196E-01" name="tube040" />
+<location  x="   0.278700    " z="  -0.159099E-01" name="tube042" />
+<location  x="   0.262623    " z="  -0.139185E-01" name="tube044" />
+<location  x="   0.246532    " z="  -0.120454E-01" name="tube046" />
+<location  x="   0.230427    " z="  -0.102907E-01" name="tube048" />
+<location  x="   0.214310    " z="  -0.865460E-02" name="tube050" />
+<location  x="   0.198181    " z="  -0.713712E-02" name="tube052" />
+<location  x="   0.182042    " z="  -0.573834E-02" name="tube054" />
+<location  x="   0.165893    " z="  -0.445835E-02" name="tube056" />
+<location  x="   0.149734    " z="  -0.329721E-02" name="tube058" />
+<location  x="   0.133568    " z="  -0.225499E-02" name="tube060" />
+<location  x="   0.117394    " z="  -0.133175E-02" name="tube062" />
+<location  x="   0.101214    " z="  -0.527525E-03" name="tube064" />
+<location  x="   0.850289E-01" z="   0.157631E-03" name="tube066" />
+<location  x="   0.688388E-01" z="   0.723683E-03" name="tube068" />
+<location  x="   0.526450E-01" z="   0.117060E-02" name="tube070" />
+<location  x="   0.364483E-01" z="   0.149836E-02" name="tube072" />
+<location  x="   0.202497E-01" z="   0.170694E-02" name="tube074" />
+<location  x="   0.405000E-02" z="   0.179634E-02" name="tube076" />
+<location  x="  -0.121499E-01" z="   0.176654E-02" name="tube078" />
+<location  x="  -0.283492E-01" z="   0.161755E-02" name="tube080" />
+<location  x="  -0.445470E-01" z="   0.134938E-02" name="tube082" />
+<location  x="  -0.607423E-01" z="   0.962035E-03" name="tube084" />
+<location  x="  -0.769343E-01" z="   0.455547E-03" name="tube086" />
+<location  x="  -0.931222E-01" z="  -0.170062E-03" name="tube088" />
+<location  x="  -0.109305    " z="  -0.914756E-03" name="tube090" />
+<location  x="  -0.125482    " z="  -0.177850E-02" name="tube092" />
+<location  x="  -0.141652    " z="  -0.276124E-02" name="tube094" />
+<location  x="  -0.157815    " z="  -0.386292E-02" name="tube096" />
+<location  x="  -0.173968    " z="  -0.508349E-02" name="tube098" />
+<location  x="  -0.190113    " z="  -0.642288E-02" name="tube100" />
+<location  x="  -0.206247    " z="  -0.788102E-02" name="tube102" />
+<location  x="  -0.222370    " z="  -0.945783E-02" name="tube104" />
+<location  x="  -0.238481    " z="  -0.111532E-01" name="tube106" />
+<location  x="  -0.254579    " z="  -0.129671E-01" name="tube108" />
+<location  x="  -0.270664    " z="  -0.148994E-01" name="tube110" />
+<location  x="  -0.286733    " z="  -0.169500E-01" name="tube112" />
+<location  x="  -0.302787    " z="  -0.191187E-01" name="tube114" />
+<location  x="  -0.318825    " z="  -0.214055E-01" name="tube116" />
+<location  x="  -0.334846    " z="  -0.238102E-01" name="tube118" />
+<location  x="  -0.350848    " z="  -0.263328E-01" name="tube120" />
+<location  x="  -0.366831    " z="  -0.289730E-01" name="tube122" />
+<location  x="  -0.382795    " z="  -0.317307E-01" name="tube124" />
+<location  x="  -0.398738    " z="  -0.346059E-01" name="tube126" />
+<location  x="  -0.414659    " z="  -0.375982E-01" name="tube128" />
+<location  x="  -0.430558    " z="  -0.407076E-01" name="tube130" />
+<location  x="  -0.446433    " z="  -0.439339E-01" name="tube132" />
+<location  x="  -0.462284    " z="  -0.472769E-01" name="tube134" />
+<location  x="  -0.478111    " z="  -0.507365E-01" name="tube136" />
+<location  x="  -0.493911    " z="  -0.543124E-01" name="tube138" />
+<location  x="  -0.509685    " z="  -0.580044E-01" name="tube140" />
+<location  x="  -0.525431    " z="  -0.618124E-01" name="tube142" />
+<location  x="  -0.541148    " z="  -0.657362E-01" name="tube144" />
+<location  x="  -0.556837    " z="  -0.697755E-01" name="tube146" />
+<location  x="  -0.572495    " z="  -0.739301E-01" name="tube148" />
+<location  x="  -0.588122    " z="  -0.781998E-01" name="tube150" />
+<location  x="  -0.603717    " z="  -0.825844E-01" name="tube152" />
+ </component>
+ </type>
+ 
+ <type name="tubeup" outline="yes">
+ <component type="pixel">
+   <location y="  -0.517983    " name="pixel0001"/>
+   <location y="  -0.515950    " name="pixel0002"/>
+   <location y="  -0.513917    " name="pixel0003"/>
+   <location y="  -0.511884    " name="pixel0004"/>
+   <location y="  -0.509851    " name="pixel0005"/>
+   <location y="  -0.507817    " name="pixel0006"/>
+   <location y="  -0.505784    " name="pixel0007"/>
+   <location y="  -0.503751    " name="pixel0008"/>
+   <location y="  -0.501718    " name="pixel0009"/>
+   <location y="  -0.499685    " name="pixel0010"/>
+   <location y="  -0.497651    " name="pixel0011"/>
+   <location y="  -0.495618    " name="pixel0012"/>
+   <location y="  -0.493585    " name="pixel0013"/>
+   <location y="  -0.491552    " name="pixel0014"/>
+   <location y="  -0.489519    " name="pixel0015"/>
+   <location y="  -0.487485    " name="pixel0016"/>
+   <location y="  -0.485452    " name="pixel0017"/>
+   <location y="  -0.483419    " name="pixel0018"/>
+   <location y="  -0.481386    " name="pixel0019"/>
+   <location y="  -0.479353    " name="pixel0020"/>
+   <location y="  -0.477319    " name="pixel0021"/>
+   <location y="  -0.475286    " name="pixel0022"/>
+   <location y="  -0.473253    " name="pixel0023"/>
+   <location y="  -0.471220    " name="pixel0024"/>
+   <location y="  -0.469187    " name="pixel0025"/>
+   <location y="  -0.467153    " name="pixel0026"/>
+   <location y="  -0.465120    " name="pixel0027"/>
+   <location y="  -0.463087    " name="pixel0028"/>
+   <location y="  -0.461054    " name="pixel0029"/>
+   <location y="  -0.459021    " name="pixel0030"/>
+   <location y="  -0.456987    " name="pixel0031"/>
+   <location y="  -0.454954    " name="pixel0032"/>
+   <location y="  -0.452921    " name="pixel0033"/>
+   <location y="  -0.450888    " name="pixel0034"/>
+   <location y="  -0.448854    " name="pixel0035"/>
+   <location y="  -0.446821    " name="pixel0036"/>
+   <location y="  -0.444788    " name="pixel0037"/>
+   <location y="  -0.442755    " name="pixel0038"/>
+   <location y="  -0.440722    " name="pixel0039"/>
+   <location y="  -0.438688    " name="pixel0040"/>
+   <location y="  -0.436655    " name="pixel0041"/>
+   <location y="  -0.434622    " name="pixel0042"/>
+   <location y="  -0.432589    " name="pixel0043"/>
+   <location y="  -0.430556    " name="pixel0044"/>
+   <location y="  -0.428522    " name="pixel0045"/>
+   <location y="  -0.426489    " name="pixel0046"/>
+   <location y="  -0.424456    " name="pixel0047"/>
+   <location y="  -0.422423    " name="pixel0048"/>
+   <location y="  -0.420390    " name="pixel0049"/>
+   <location y="  -0.418356    " name="pixel0050"/>
+   <location y="  -0.416323    " name="pixel0051"/>
+   <location y="  -0.414290    " name="pixel0052"/>
+   <location y="  -0.412257    " name="pixel0053"/>
+   <location y="  -0.410224    " name="pixel0054"/>
+   <location y="  -0.408190    " name="pixel0055"/>
+   <location y="  -0.406157    " name="pixel0056"/>
+   <location y="  -0.404124    " name="pixel0057"/>
+   <location y="  -0.402091    " name="pixel0058"/>
+   <location y="  -0.400058    " name="pixel0059"/>
+   <location y="  -0.398024    " name="pixel0060"/>
+   <location y="  -0.395991    " name="pixel0061"/>
+   <location y="  -0.393958    " name="pixel0062"/>
+   <location y="  -0.391925    " name="pixel0063"/>
+   <location y="  -0.389892    " name="pixel0064"/>
+   <location y="  -0.387858    " name="pixel0065"/>
+   <location y="  -0.385825    " name="pixel0066"/>
+   <location y="  -0.383792    " name="pixel0067"/>
+   <location y="  -0.381759    " name="pixel0068"/>
+   <location y="  -0.379726    " name="pixel0069"/>
+   <location y="  -0.377692    " name="pixel0070"/>
+   <location y="  -0.375659    " name="pixel0071"/>
+   <location y="  -0.373626    " name="pixel0072"/>
+   <location y="  -0.371593    " name="pixel0073"/>
+   <location y="  -0.369560    " name="pixel0074"/>
+   <location y="  -0.367526    " name="pixel0075"/>
+   <location y="  -0.365493    " name="pixel0076"/>
+   <location y="  -0.363460    " name="pixel0077"/>
+   <location y="  -0.361427    " name="pixel0078"/>
+   <location y="  -0.359394    " name="pixel0079"/>
+   <location y="  -0.357360    " name="pixel0080"/>
+   <location y="  -0.355327    " name="pixel0081"/>
+   <location y="  -0.353294    " name="pixel0082"/>
+   <location y="  -0.351261    " name="pixel0083"/>
+   <location y="  -0.349228    " name="pixel0084"/>
+   <location y="  -0.347194    " name="pixel0085"/>
+   <location y="  -0.345161    " name="pixel0086"/>
+   <location y="  -0.343128    " name="pixel0087"/>
+   <location y="  -0.341095    " name="pixel0088"/>
+   <location y="  -0.339062    " name="pixel0089"/>
+   <location y="  -0.337028    " name="pixel0090"/>
+   <location y="  -0.334995    " name="pixel0091"/>
+   <location y="  -0.332962    " name="pixel0092"/>
+   <location y="  -0.330929    " name="pixel0093"/>
+   <location y="  -0.328896    " name="pixel0094"/>
+   <location y="  -0.326862    " name="pixel0095"/>
+   <location y="  -0.324829    " name="pixel0096"/>
+   <location y="  -0.322796    " name="pixel0097"/>
+   <location y="  -0.320763    " name="pixel0098"/>
+   <location y="  -0.318729    " name="pixel0099"/>
+   <location y="  -0.316696    " name="pixel0100"/>
+   <location y="  -0.314663    " name="pixel0101"/>
+   <location y="  -0.312630    " name="pixel0102"/>
+   <location y="  -0.310597    " name="pixel0103"/>
+   <location y="  -0.308563    " name="pixel0104"/>
+   <location y="  -0.306530    " name="pixel0105"/>
+   <location y="  -0.304497    " name="pixel0106"/>
+   <location y="  -0.302464    " name="pixel0107"/>
+   <location y="  -0.300431    " name="pixel0108"/>
+   <location y="  -0.298397    " name="pixel0109"/>
+   <location y="  -0.296364    " name="pixel0110"/>
+   <location y="  -0.294331    " name="pixel0111"/>
+   <location y="  -0.292298    " name="pixel0112"/>
+   <location y="  -0.290265    " name="pixel0113"/>
+   <location y="  -0.288231    " name="pixel0114"/>
+   <location y="  -0.286198    " name="pixel0115"/>
+   <location y="  -0.284165    " name="pixel0116"/>
+   <location y="  -0.282132    " name="pixel0117"/>
+   <location y="  -0.280099    " name="pixel0118"/>
+   <location y="  -0.278065    " name="pixel0119"/>
+   <location y="  -0.276032    " name="pixel0120"/>
+   <location y="  -0.273999    " name="pixel0121"/>
+   <location y="  -0.271966    " name="pixel0122"/>
+   <location y="  -0.269933    " name="pixel0123"/>
+   <location y="  -0.267899    " name="pixel0124"/>
+   <location y="  -0.265866    " name="pixel0125"/>
+   <location y="  -0.263833    " name="pixel0126"/>
+   <location y="  -0.261800    " name="pixel0127"/>
+   <location y="  -0.259767    " name="pixel0128"/>
+   <location y="  -0.257733    " name="pixel0129"/>
+   <location y="  -0.255700    " name="pixel0130"/>
+   <location y="  -0.253667    " name="pixel0131"/>
+   <location y="  -0.251634    " name="pixel0132"/>
+   <location y="  -0.249601    " name="pixel0133"/>
+   <location y="  -0.247567    " name="pixel0134"/>
+   <location y="  -0.245534    " name="pixel0135"/>
+   <location y="  -0.243501    " name="pixel0136"/>
+   <location y="  -0.241468    " name="pixel0137"/>
+   <location y="  -0.239435    " name="pixel0138"/>
+   <location y="  -0.237401    " name="pixel0139"/>
+   <location y="  -0.235368    " name="pixel0140"/>
+   <location y="  -0.233335    " name="pixel0141"/>
+   <location y="  -0.231302    " name="pixel0142"/>
+   <location y="  -0.229269    " name="pixel0143"/>
+   <location y="  -0.227235    " name="pixel0144"/>
+   <location y="  -0.225202    " name="pixel0145"/>
+   <location y="  -0.223169    " name="pixel0146"/>
+   <location y="  -0.221136    " name="pixel0147"/>
+   <location y="  -0.219103    " name="pixel0148"/>
+   <location y="  -0.217069    " name="pixel0149"/>
+   <location y="  -0.215036    " name="pixel0150"/>
+   <location y="  -0.213003    " name="pixel0151"/>
+   <location y="  -0.210970    " name="pixel0152"/>
+   <location y="  -0.208937    " name="pixel0153"/>
+   <location y="  -0.206903    " name="pixel0154"/>
+   <location y="  -0.204870    " name="pixel0155"/>
+   <location y="  -0.202837    " name="pixel0156"/>
+   <location y="  -0.200804    " name="pixel0157"/>
+   <location y="  -0.198771    " name="pixel0158"/>
+   <location y="  -0.196737    " name="pixel0159"/>
+   <location y="  -0.194704    " name="pixel0160"/>
+   <location y="  -0.192671    " name="pixel0161"/>
+   <location y="  -0.190638    " name="pixel0162"/>
+   <location y="  -0.188604    " name="pixel0163"/>
+   <location y="  -0.186571    " name="pixel0164"/>
+   <location y="  -0.184538    " name="pixel0165"/>
+   <location y="  -0.182505    " name="pixel0166"/>
+   <location y="  -0.180472    " name="pixel0167"/>
+   <location y="  -0.178438    " name="pixel0168"/>
+   <location y="  -0.176405    " name="pixel0169"/>
+   <location y="  -0.174372    " name="pixel0170"/>
+   <location y="  -0.172339    " name="pixel0171"/>
+   <location y="  -0.170306    " name="pixel0172"/>
+   <location y="  -0.168272    " name="pixel0173"/>
+   <location y="  -0.166239    " name="pixel0174"/>
+   <location y="  -0.164206    " name="pixel0175"/>
+   <location y="  -0.162173    " name="pixel0176"/>
+   <location y="  -0.160140    " name="pixel0177"/>
+   <location y="  -0.158106    " name="pixel0178"/>
+   <location y="  -0.156073    " name="pixel0179"/>
+   <location y="  -0.154040    " name="pixel0180"/>
+   <location y="  -0.152007    " name="pixel0181"/>
+   <location y="  -0.149974    " name="pixel0182"/>
+   <location y="  -0.147940    " name="pixel0183"/>
+   <location y="  -0.145907    " name="pixel0184"/>
+   <location y="  -0.143874    " name="pixel0185"/>
+   <location y="  -0.141841    " name="pixel0186"/>
+   <location y="  -0.139808    " name="pixel0187"/>
+   <location y="  -0.137774    " name="pixel0188"/>
+   <location y="  -0.135741    " name="pixel0189"/>
+   <location y="  -0.133708    " name="pixel0190"/>
+   <location y="  -0.131675    " name="pixel0191"/>
+   <location y="  -0.129642    " name="pixel0192"/>
+   <location y="  -0.127608    " name="pixel0193"/>
+   <location y="  -0.125575    " name="pixel0194"/>
+   <location y="  -0.123542    " name="pixel0195"/>
+   <location y="  -0.121509    " name="pixel0196"/>
+   <location y="  -0.119476    " name="pixel0197"/>
+   <location y="  -0.117442    " name="pixel0198"/>
+   <location y="  -0.115409    " name="pixel0199"/>
+   <location y="  -0.113376    " name="pixel0200"/>
+   <location y="  -0.111343    " name="pixel0201"/>
+   <location y="  -0.109310    " name="pixel0202"/>
+   <location y="  -0.107276    " name="pixel0203"/>
+   <location y="  -0.105243    " name="pixel0204"/>
+   <location y="  -0.103210    " name="pixel0205"/>
+   <location y="  -0.101177    " name="pixel0206"/>
+   <location y="  -0.991436E-01" name="pixel0207"/>
+   <location y="  -0.971104E-01" name="pixel0208"/>
+   <location y="  -0.950771E-01" name="pixel0209"/>
+   <location y="  -0.930439E-01" name="pixel0210"/>
+   <location y="  -0.910107E-01" name="pixel0211"/>
+   <location y="  -0.889775E-01" name="pixel0212"/>
+   <location y="  -0.869443E-01" name="pixel0213"/>
+   <location y="  -0.849111E-01" name="pixel0214"/>
+   <location y="  -0.828779E-01" name="pixel0215"/>
+   <location y="  -0.808447E-01" name="pixel0216"/>
+   <location y="  -0.788115E-01" name="pixel0217"/>
+   <location y="  -0.767783E-01" name="pixel0218"/>
+   <location y="  -0.747451E-01" name="pixel0219"/>
+   <location y="  -0.727119E-01" name="pixel0220"/>
+   <location y="  -0.706787E-01" name="pixel0221"/>
+   <location y="  -0.686455E-01" name="pixel0222"/>
+   <location y="  -0.666123E-01" name="pixel0223"/>
+   <location y="  -0.645791E-01" name="pixel0224"/>
+   <location y="  -0.625459E-01" name="pixel0225"/>
+   <location y="  -0.605127E-01" name="pixel0226"/>
+   <location y="  -0.584795E-01" name="pixel0227"/>
+   <location y="  -0.564463E-01" name="pixel0228"/>
+   <location y="  -0.544131E-01" name="pixel0229"/>
+   <location y="  -0.523799E-01" name="pixel0230"/>
+   <location y="  -0.503467E-01" name="pixel0231"/>
+   <location y="  -0.483135E-01" name="pixel0232"/>
+   <location y="  -0.462803E-01" name="pixel0233"/>
+   <location y="  -0.442471E-01" name="pixel0234"/>
+   <location y="  -0.422139E-01" name="pixel0235"/>
+   <location y="  -0.401807E-01" name="pixel0236"/>
+   <location y="  -0.381475E-01" name="pixel0237"/>
+   <location y="  -0.361143E-01" name="pixel0238"/>
+   <location y="  -0.340811E-01" name="pixel0239"/>
+   <location y="  -0.320479E-01" name="pixel0240"/>
+   <location y="  -0.300146E-01" name="pixel0241"/>
+   <location y="  -0.279814E-01" name="pixel0242"/>
+   <location y="  -0.259482E-01" name="pixel0243"/>
+   <location y="  -0.239150E-01" name="pixel0244"/>
+   <location y="  -0.218818E-01" name="pixel0245"/>
+   <location y="  -0.198486E-01" name="pixel0246"/>
+   <location y="  -0.178154E-01" name="pixel0247"/>
+   <location y="  -0.157822E-01" name="pixel0248"/>
+   <location y="  -0.137490E-01" name="pixel0249"/>
+   <location y="  -0.117158E-01" name="pixel0250"/>
+   <location y="  -0.968262E-02" name="pixel0251"/>
+   <location y="  -0.764941E-02" name="pixel0252"/>
+   <location y="  -0.561621E-02" name="pixel0253"/>
+   <location y="  -0.358301E-02" name="pixel0254"/>
+   <location y="  -0.154980E-02" name="pixel0255"/>
+   <location y="   0.483398E-03" name="pixel0256"/>
+   <location y="   0.251660E-02" name="pixel0257"/>
+   <location y="   0.454980E-02" name="pixel0258"/>
+   <location y="   0.658301E-02" name="pixel0259"/>
+   <location y="   0.861621E-02" name="pixel0260"/>
+   <location y="   0.106494E-01" name="pixel0261"/>
+   <location y="   0.126826E-01" name="pixel0262"/>
+   <location y="   0.147158E-01" name="pixel0263"/>
+   <location y="   0.167490E-01" name="pixel0264"/>
+   <location y="   0.187822E-01" name="pixel0265"/>
+   <location y="   0.208154E-01" name="pixel0266"/>
+   <location y="   0.228486E-01" name="pixel0267"/>
+   <location y="   0.248818E-01" name="pixel0268"/>
+   <location y="   0.269150E-01" name="pixel0269"/>
+   <location y="   0.289482E-01" name="pixel0270"/>
+   <location y="   0.309814E-01" name="pixel0271"/>
+   <location y="   0.330146E-01" name="pixel0272"/>
+   <location y="   0.350479E-01" name="pixel0273"/>
+   <location y="   0.370811E-01" name="pixel0274"/>
+   <location y="   0.391143E-01" name="pixel0275"/>
+   <location y="   0.411475E-01" name="pixel0276"/>
+   <location y="   0.431807E-01" name="pixel0277"/>
+   <location y="   0.452139E-01" name="pixel0278"/>
+   <location y="   0.472471E-01" name="pixel0279"/>
+   <location y="   0.492803E-01" name="pixel0280"/>
+   <location y="   0.513135E-01" name="pixel0281"/>
+   <location y="   0.533467E-01" name="pixel0282"/>
+   <location y="   0.553799E-01" name="pixel0283"/>
+   <location y="   0.574131E-01" name="pixel0284"/>
+   <location y="   0.594463E-01" name="pixel0285"/>
+   <location y="   0.614795E-01" name="pixel0286"/>
+   <location y="   0.635127E-01" name="pixel0287"/>
+   <location y="   0.655459E-01" name="pixel0288"/>
+   <location y="   0.675791E-01" name="pixel0289"/>
+   <location y="   0.696123E-01" name="pixel0290"/>
+   <location y="   0.716455E-01" name="pixel0291"/>
+   <location y="   0.736787E-01" name="pixel0292"/>
+   <location y="   0.757119E-01" name="pixel0293"/>
+   <location y="   0.777451E-01" name="pixel0294"/>
+   <location y="   0.797783E-01" name="pixel0295"/>
+   <location y="   0.818115E-01" name="pixel0296"/>
+   <location y="   0.838447E-01" name="pixel0297"/>
+   <location y="   0.858779E-01" name="pixel0298"/>
+   <location y="   0.879111E-01" name="pixel0299"/>
+   <location y="   0.899443E-01" name="pixel0300"/>
+   <location y="   0.919775E-01" name="pixel0301"/>
+   <location y="   0.940107E-01" name="pixel0302"/>
+   <location y="   0.960439E-01" name="pixel0303"/>
+   <location y="   0.980771E-01" name="pixel0304"/>
+   <location y="   0.100110    " name="pixel0305"/>
+   <location y="   0.102144    " name="pixel0306"/>
+   <location y="   0.104177    " name="pixel0307"/>
+   <location y="   0.106210    " name="pixel0308"/>
+   <location y="   0.108243    " name="pixel0309"/>
+   <location y="   0.110276    " name="pixel0310"/>
+   <location y="   0.112310    " name="pixel0311"/>
+   <location y="   0.114343    " name="pixel0312"/>
+   <location y="   0.116376    " name="pixel0313"/>
+   <location y="   0.118409    " name="pixel0314"/>
+   <location y="   0.120442    " name="pixel0315"/>
+   <location y="   0.122476    " name="pixel0316"/>
+   <location y="   0.124509    " name="pixel0317"/>
+   <location y="   0.126542    " name="pixel0318"/>
+   <location y="   0.128575    " name="pixel0319"/>
+   <location y="   0.130608    " name="pixel0320"/>
+   <location y="   0.132642    " name="pixel0321"/>
+   <location y="   0.134675    " name="pixel0322"/>
+   <location y="   0.136708    " name="pixel0323"/>
+   <location y="   0.138741    " name="pixel0324"/>
+   <location y="   0.140774    " name="pixel0325"/>
+   <location y="   0.142808    " name="pixel0326"/>
+   <location y="   0.144841    " name="pixel0327"/>
+   <location y="   0.146874    " name="pixel0328"/>
+   <location y="   0.148907    " name="pixel0329"/>
+   <location y="   0.150940    " name="pixel0330"/>
+   <location y="   0.152974    " name="pixel0331"/>
+   <location y="   0.155007    " name="pixel0332"/>
+   <location y="   0.157040    " name="pixel0333"/>
+   <location y="   0.159073    " name="pixel0334"/>
+   <location y="   0.161106    " name="pixel0335"/>
+   <location y="   0.163140    " name="pixel0336"/>
+   <location y="   0.165173    " name="pixel0337"/>
+   <location y="   0.167206    " name="pixel0338"/>
+   <location y="   0.169239    " name="pixel0339"/>
+   <location y="   0.171272    " name="pixel0340"/>
+   <location y="   0.173306    " name="pixel0341"/>
+   <location y="   0.175339    " name="pixel0342"/>
+   <location y="   0.177372    " name="pixel0343"/>
+   <location y="   0.179405    " name="pixel0344"/>
+   <location y="   0.181438    " name="pixel0345"/>
+   <location y="   0.183472    " name="pixel0346"/>
+   <location y="   0.185505    " name="pixel0347"/>
+   <location y="   0.187538    " name="pixel0348"/>
+   <location y="   0.189571    " name="pixel0349"/>
+   <location y="   0.191604    " name="pixel0350"/>
+   <location y="   0.193638    " name="pixel0351"/>
+   <location y="   0.195671    " name="pixel0352"/>
+   <location y="   0.197704    " name="pixel0353"/>
+   <location y="   0.199737    " name="pixel0354"/>
+   <location y="   0.201771    " name="pixel0355"/>
+   <location y="   0.203804    " name="pixel0356"/>
+   <location y="   0.205837    " name="pixel0357"/>
+   <location y="   0.207870    " name="pixel0358"/>
+   <location y="   0.209903    " name="pixel0359"/>
+   <location y="   0.211937    " name="pixel0360"/>
+   <location y="   0.213970    " name="pixel0361"/>
+   <location y="   0.216003    " name="pixel0362"/>
+   <location y="   0.218036    " name="pixel0363"/>
+   <location y="   0.220069    " name="pixel0364"/>
+   <location y="   0.222103    " name="pixel0365"/>
+   <location y="   0.224136    " name="pixel0366"/>
+   <location y="   0.226169    " name="pixel0367"/>
+   <location y="   0.228202    " name="pixel0368"/>
+   <location y="   0.230235    " name="pixel0369"/>
+   <location y="   0.232269    " name="pixel0370"/>
+   <location y="   0.234302    " name="pixel0371"/>
+   <location y="   0.236335    " name="pixel0372"/>
+   <location y="   0.238368    " name="pixel0373"/>
+   <location y="   0.240401    " name="pixel0374"/>
+   <location y="   0.242435    " name="pixel0375"/>
+   <location y="   0.244468    " name="pixel0376"/>
+   <location y="   0.246501    " name="pixel0377"/>
+   <location y="   0.248534    " name="pixel0378"/>
+   <location y="   0.250567    " name="pixel0379"/>
+   <location y="   0.252601    " name="pixel0380"/>
+   <location y="   0.254634    " name="pixel0381"/>
+   <location y="   0.256667    " name="pixel0382"/>
+   <location y="   0.258700    " name="pixel0383"/>
+   <location y="   0.260733    " name="pixel0384"/>
+   <location y="   0.262767    " name="pixel0385"/>
+   <location y="   0.264800    " name="pixel0386"/>
+   <location y="   0.266833    " name="pixel0387"/>
+   <location y="   0.268866    " name="pixel0388"/>
+   <location y="   0.270899    " name="pixel0389"/>
+   <location y="   0.272933    " name="pixel0390"/>
+   <location y="   0.274966    " name="pixel0391"/>
+   <location y="   0.276999    " name="pixel0392"/>
+   <location y="   0.279032    " name="pixel0393"/>
+   <location y="   0.281065    " name="pixel0394"/>
+   <location y="   0.283099    " name="pixel0395"/>
+   <location y="   0.285132    " name="pixel0396"/>
+   <location y="   0.287165    " name="pixel0397"/>
+   <location y="   0.289198    " name="pixel0398"/>
+   <location y="   0.291231    " name="pixel0399"/>
+   <location y="   0.293265    " name="pixel0400"/>
+   <location y="   0.295298    " name="pixel0401"/>
+   <location y="   0.297331    " name="pixel0402"/>
+   <location y="   0.299364    " name="pixel0403"/>
+   <location y="   0.301397    " name="pixel0404"/>
+   <location y="   0.303431    " name="pixel0405"/>
+   <location y="   0.305464    " name="pixel0406"/>
+   <location y="   0.307497    " name="pixel0407"/>
+   <location y="   0.309530    " name="pixel0408"/>
+   <location y="   0.311563    " name="pixel0409"/>
+   <location y="   0.313597    " name="pixel0410"/>
+   <location y="   0.315630    " name="pixel0411"/>
+   <location y="   0.317663    " name="pixel0412"/>
+   <location y="   0.319696    " name="pixel0413"/>
+   <location y="   0.321729    " name="pixel0414"/>
+   <location y="   0.323763    " name="pixel0415"/>
+   <location y="   0.325796    " name="pixel0416"/>
+   <location y="   0.327829    " name="pixel0417"/>
+   <location y="   0.329862    " name="pixel0418"/>
+   <location y="   0.331896    " name="pixel0419"/>
+   <location y="   0.333929    " name="pixel0420"/>
+   <location y="   0.335962    " name="pixel0421"/>
+   <location y="   0.337995    " name="pixel0422"/>
+   <location y="   0.340028    " name="pixel0423"/>
+   <location y="   0.342062    " name="pixel0424"/>
+   <location y="   0.344095    " name="pixel0425"/>
+   <location y="   0.346128    " name="pixel0426"/>
+   <location y="   0.348161    " name="pixel0427"/>
+   <location y="   0.350194    " name="pixel0428"/>
+   <location y="   0.352228    " name="pixel0429"/>
+   <location y="   0.354261    " name="pixel0430"/>
+   <location y="   0.356294    " name="pixel0431"/>
+   <location y="   0.358327    " name="pixel0432"/>
+   <location y="   0.360360    " name="pixel0433"/>
+   <location y="   0.362394    " name="pixel0434"/>
+   <location y="   0.364427    " name="pixel0435"/>
+   <location y="   0.366460    " name="pixel0436"/>
+   <location y="   0.368493    " name="pixel0437"/>
+   <location y="   0.370526    " name="pixel0438"/>
+   <location y="   0.372560    " name="pixel0439"/>
+   <location y="   0.374593    " name="pixel0440"/>
+   <location y="   0.376626    " name="pixel0441"/>
+   <location y="   0.378659    " name="pixel0442"/>
+   <location y="   0.380692    " name="pixel0443"/>
+   <location y="   0.382726    " name="pixel0444"/>
+   <location y="   0.384759    " name="pixel0445"/>
+   <location y="   0.386792    " name="pixel0446"/>
+   <location y="   0.388825    " name="pixel0447"/>
+   <location y="   0.390858    " name="pixel0448"/>
+   <location y="   0.392892    " name="pixel0449"/>
+   <location y="   0.394925    " name="pixel0450"/>
+   <location y="   0.396958    " name="pixel0451"/>
+   <location y="   0.398991    " name="pixel0452"/>
+   <location y="   0.401024    " name="pixel0453"/>
+   <location y="   0.403058    " name="pixel0454"/>
+   <location y="   0.405091    " name="pixel0455"/>
+   <location y="   0.407124    " name="pixel0456"/>
+   <location y="   0.409157    " name="pixel0457"/>
+   <location y="   0.411190    " name="pixel0458"/>
+   <location y="   0.413224    " name="pixel0459"/>
+   <location y="   0.415257    " name="pixel0460"/>
+   <location y="   0.417290    " name="pixel0461"/>
+   <location y="   0.419323    " name="pixel0462"/>
+   <location y="   0.421356    " name="pixel0463"/>
+   <location y="   0.423390    " name="pixel0464"/>
+   <location y="   0.425423    " name="pixel0465"/>
+   <location y="   0.427456    " name="pixel0466"/>
+   <location y="   0.429489    " name="pixel0467"/>
+   <location y="   0.431522    " name="pixel0468"/>
+   <location y="   0.433556    " name="pixel0469"/>
+   <location y="   0.435589    " name="pixel0470"/>
+   <location y="   0.437622    " name="pixel0471"/>
+   <location y="   0.439655    " name="pixel0472"/>
+   <location y="   0.441688    " name="pixel0473"/>
+   <location y="   0.443722    " name="pixel0474"/>
+   <location y="   0.445755    " name="pixel0475"/>
+   <location y="   0.447788    " name="pixel0476"/>
+   <location y="   0.449821    " name="pixel0477"/>
+   <location y="   0.451854    " name="pixel0478"/>
+   <location y="   0.453888    " name="pixel0479"/>
+   <location y="   0.455921    " name="pixel0480"/>
+   <location y="   0.457954    " name="pixel0481"/>
+   <location y="   0.459987    " name="pixel0482"/>
+   <location y="   0.462021    " name="pixel0483"/>
+   <location y="   0.464054    " name="pixel0484"/>
+   <location y="   0.466087    " name="pixel0485"/>
+   <location y="   0.468120    " name="pixel0486"/>
+   <location y="   0.470153    " name="pixel0487"/>
+   <location y="   0.472187    " name="pixel0488"/>
+   <location y="   0.474220    " name="pixel0489"/>
+   <location y="   0.476253    " name="pixel0490"/>
+   <location y="   0.478286    " name="pixel0491"/>
+   <location y="   0.480319    " name="pixel0492"/>
+   <location y="   0.482353    " name="pixel0493"/>
+   <location y="   0.484386    " name="pixel0494"/>
+   <location y="   0.486419    " name="pixel0495"/>
+   <location y="   0.488452    " name="pixel0496"/>
+   <location y="   0.490485    " name="pixel0497"/>
+   <location y="   0.492519    " name="pixel0498"/>
+   <location y="   0.494552    " name="pixel0499"/>
+   <location y="   0.496585    " name="pixel0500"/>
+   <location y="   0.498618    " name="pixel0501"/>
+   <location y="   0.500651    " name="pixel0502"/>
+   <location y="   0.502685    " name="pixel0503"/>
+   <location y="   0.504718    " name="pixel0504"/>
+   <location y="   0.506751    " name="pixel0505"/>
+   <location y="   0.508784    " name="pixel0506"/>
+   <location y="   0.510817    " name="pixel0507"/>
+   <location y="   0.512851    " name="pixel0508"/>
+   <location y="   0.514884    " name="pixel0509"/>
+   <location y="   0.516917    " name="pixel0510"/>
+   <location y="   0.518950    " name="pixel0511"/>
+   <location y="   0.520983    " name="pixel0512"/>
+ </component>
+ </type>
+ <type name="tubedown" outline="yes">
+ <component type="pixel">
+   <location y="  -0.520983    " name="pixel0001"/>
+   <location y="  -0.518950    " name="pixel0002"/>
+   <location y="  -0.516917    " name="pixel0003"/>
+   <location y="  -0.514884    " name="pixel0004"/>
+   <location y="  -0.512851    " name="pixel0005"/>
+   <location y="  -0.510817    " name="pixel0006"/>
+   <location y="  -0.508784    " name="pixel0007"/>
+   <location y="  -0.506751    " name="pixel0008"/>
+   <location y="  -0.504718    " name="pixel0009"/>
+   <location y="  -0.502685    " name="pixel0010"/>
+   <location y="  -0.500651    " name="pixel0011"/>
+   <location y="  -0.498618    " name="pixel0012"/>
+   <location y="  -0.496585    " name="pixel0013"/>
+   <location y="  -0.494552    " name="pixel0014"/>
+   <location y="  -0.492519    " name="pixel0015"/>
+   <location y="  -0.490485    " name="pixel0016"/>
+   <location y="  -0.488452    " name="pixel0017"/>
+   <location y="  -0.486419    " name="pixel0018"/>
+   <location y="  -0.484386    " name="pixel0019"/>
+   <location y="  -0.482353    " name="pixel0020"/>
+   <location y="  -0.480319    " name="pixel0021"/>
+   <location y="  -0.478286    " name="pixel0022"/>
+   <location y="  -0.476253    " name="pixel0023"/>
+   <location y="  -0.474220    " name="pixel0024"/>
+   <location y="  -0.472187    " name="pixel0025"/>
+   <location y="  -0.470153    " name="pixel0026"/>
+   <location y="  -0.468120    " name="pixel0027"/>
+   <location y="  -0.466087    " name="pixel0028"/>
+   <location y="  -0.464054    " name="pixel0029"/>
+   <location y="  -0.462021    " name="pixel0030"/>
+   <location y="  -0.459987    " name="pixel0031"/>
+   <location y="  -0.457954    " name="pixel0032"/>
+   <location y="  -0.455921    " name="pixel0033"/>
+   <location y="  -0.453888    " name="pixel0034"/>
+   <location y="  -0.451854    " name="pixel0035"/>
+   <location y="  -0.449821    " name="pixel0036"/>
+   <location y="  -0.447788    " name="pixel0037"/>
+   <location y="  -0.445755    " name="pixel0038"/>
+   <location y="  -0.443722    " name="pixel0039"/>
+   <location y="  -0.441688    " name="pixel0040"/>
+   <location y="  -0.439655    " name="pixel0041"/>
+   <location y="  -0.437622    " name="pixel0042"/>
+   <location y="  -0.435589    " name="pixel0043"/>
+   <location y="  -0.433556    " name="pixel0044"/>
+   <location y="  -0.431522    " name="pixel0045"/>
+   <location y="  -0.429489    " name="pixel0046"/>
+   <location y="  -0.427456    " name="pixel0047"/>
+   <location y="  -0.425423    " name="pixel0048"/>
+   <location y="  -0.423390    " name="pixel0049"/>
+   <location y="  -0.421356    " name="pixel0050"/>
+   <location y="  -0.419323    " name="pixel0051"/>
+   <location y="  -0.417290    " name="pixel0052"/>
+   <location y="  -0.415257    " name="pixel0053"/>
+   <location y="  -0.413224    " name="pixel0054"/>
+   <location y="  -0.411190    " name="pixel0055"/>
+   <location y="  -0.409157    " name="pixel0056"/>
+   <location y="  -0.407124    " name="pixel0057"/>
+   <location y="  -0.405091    " name="pixel0058"/>
+   <location y="  -0.403058    " name="pixel0059"/>
+   <location y="  -0.401024    " name="pixel0060"/>
+   <location y="  -0.398991    " name="pixel0061"/>
+   <location y="  -0.396958    " name="pixel0062"/>
+   <location y="  -0.394925    " name="pixel0063"/>
+   <location y="  -0.392892    " name="pixel0064"/>
+   <location y="  -0.390858    " name="pixel0065"/>
+   <location y="  -0.388825    " name="pixel0066"/>
+   <location y="  -0.386792    " name="pixel0067"/>
+   <location y="  -0.384759    " name="pixel0068"/>
+   <location y="  -0.382726    " name="pixel0069"/>
+   <location y="  -0.380692    " name="pixel0070"/>
+   <location y="  -0.378659    " name="pixel0071"/>
+   <location y="  -0.376626    " name="pixel0072"/>
+   <location y="  -0.374593    " name="pixel0073"/>
+   <location y="  -0.372560    " name="pixel0074"/>
+   <location y="  -0.370526    " name="pixel0075"/>
+   <location y="  -0.368493    " name="pixel0076"/>
+   <location y="  -0.366460    " name="pixel0077"/>
+   <location y="  -0.364427    " name="pixel0078"/>
+   <location y="  -0.362394    " name="pixel0079"/>
+   <location y="  -0.360360    " name="pixel0080"/>
+   <location y="  -0.358327    " name="pixel0081"/>
+   <location y="  -0.356294    " name="pixel0082"/>
+   <location y="  -0.354261    " name="pixel0083"/>
+   <location y="  -0.352228    " name="pixel0084"/>
+   <location y="  -0.350194    " name="pixel0085"/>
+   <location y="  -0.348161    " name="pixel0086"/>
+   <location y="  -0.346128    " name="pixel0087"/>
+   <location y="  -0.344095    " name="pixel0088"/>
+   <location y="  -0.342062    " name="pixel0089"/>
+   <location y="  -0.340028    " name="pixel0090"/>
+   <location y="  -0.337995    " name="pixel0091"/>
+   <location y="  -0.335962    " name="pixel0092"/>
+   <location y="  -0.333929    " name="pixel0093"/>
+   <location y="  -0.331896    " name="pixel0094"/>
+   <location y="  -0.329862    " name="pixel0095"/>
+   <location y="  -0.327829    " name="pixel0096"/>
+   <location y="  -0.325796    " name="pixel0097"/>
+   <location y="  -0.323763    " name="pixel0098"/>
+   <location y="  -0.321729    " name="pixel0099"/>
+   <location y="  -0.319696    " name="pixel0100"/>
+   <location y="  -0.317663    " name="pixel0101"/>
+   <location y="  -0.315630    " name="pixel0102"/>
+   <location y="  -0.313597    " name="pixel0103"/>
+   <location y="  -0.311563    " name="pixel0104"/>
+   <location y="  -0.309530    " name="pixel0105"/>
+   <location y="  -0.307497    " name="pixel0106"/>
+   <location y="  -0.305464    " name="pixel0107"/>
+   <location y="  -0.303431    " name="pixel0108"/>
+   <location y="  -0.301397    " name="pixel0109"/>
+   <location y="  -0.299364    " name="pixel0110"/>
+   <location y="  -0.297331    " name="pixel0111"/>
+   <location y="  -0.295298    " name="pixel0112"/>
+   <location y="  -0.293265    " name="pixel0113"/>
+   <location y="  -0.291231    " name="pixel0114"/>
+   <location y="  -0.289198    " name="pixel0115"/>
+   <location y="  -0.287165    " name="pixel0116"/>
+   <location y="  -0.285132    " name="pixel0117"/>
+   <location y="  -0.283099    " name="pixel0118"/>
+   <location y="  -0.281065    " name="pixel0119"/>
+   <location y="  -0.279032    " name="pixel0120"/>
+   <location y="  -0.276999    " name="pixel0121"/>
+   <location y="  -0.274966    " name="pixel0122"/>
+   <location y="  -0.272933    " name="pixel0123"/>
+   <location y="  -0.270899    " name="pixel0124"/>
+   <location y="  -0.268866    " name="pixel0125"/>
+   <location y="  -0.266833    " name="pixel0126"/>
+   <location y="  -0.264800    " name="pixel0127"/>
+   <location y="  -0.262767    " name="pixel0128"/>
+   <location y="  -0.260733    " name="pixel0129"/>
+   <location y="  -0.258700    " name="pixel0130"/>
+   <location y="  -0.256667    " name="pixel0131"/>
+   <location y="  -0.254634    " name="pixel0132"/>
+   <location y="  -0.252601    " name="pixel0133"/>
+   <location y="  -0.250567    " name="pixel0134"/>
+   <location y="  -0.248534    " name="pixel0135"/>
+   <location y="  -0.246501    " name="pixel0136"/>
+   <location y="  -0.244468    " name="pixel0137"/>
+   <location y="  -0.242435    " name="pixel0138"/>
+   <location y="  -0.240401    " name="pixel0139"/>
+   <location y="  -0.238368    " name="pixel0140"/>
+   <location y="  -0.236335    " name="pixel0141"/>
+   <location y="  -0.234302    " name="pixel0142"/>
+   <location y="  -0.232269    " name="pixel0143"/>
+   <location y="  -0.230235    " name="pixel0144"/>
+   <location y="  -0.228202    " name="pixel0145"/>
+   <location y="  -0.226169    " name="pixel0146"/>
+   <location y="  -0.224136    " name="pixel0147"/>
+   <location y="  -0.222103    " name="pixel0148"/>
+   <location y="  -0.220069    " name="pixel0149"/>
+   <location y="  -0.218036    " name="pixel0150"/>
+   <location y="  -0.216003    " name="pixel0151"/>
+   <location y="  -0.213970    " name="pixel0152"/>
+   <location y="  -0.211937    " name="pixel0153"/>
+   <location y="  -0.209903    " name="pixel0154"/>
+   <location y="  -0.207870    " name="pixel0155"/>
+   <location y="  -0.205837    " name="pixel0156"/>
+   <location y="  -0.203804    " name="pixel0157"/>
+   <location y="  -0.201771    " name="pixel0158"/>
+   <location y="  -0.199737    " name="pixel0159"/>
+   <location y="  -0.197704    " name="pixel0160"/>
+   <location y="  -0.195671    " name="pixel0161"/>
+   <location y="  -0.193638    " name="pixel0162"/>
+   <location y="  -0.191604    " name="pixel0163"/>
+   <location y="  -0.189571    " name="pixel0164"/>
+   <location y="  -0.187538    " name="pixel0165"/>
+   <location y="  -0.185505    " name="pixel0166"/>
+   <location y="  -0.183472    " name="pixel0167"/>
+   <location y="  -0.181438    " name="pixel0168"/>
+   <location y="  -0.179405    " name="pixel0169"/>
+   <location y="  -0.177372    " name="pixel0170"/>
+   <location y="  -0.175339    " name="pixel0171"/>
+   <location y="  -0.173306    " name="pixel0172"/>
+   <location y="  -0.171272    " name="pixel0173"/>
+   <location y="  -0.169239    " name="pixel0174"/>
+   <location y="  -0.167206    " name="pixel0175"/>
+   <location y="  -0.165173    " name="pixel0176"/>
+   <location y="  -0.163140    " name="pixel0177"/>
+   <location y="  -0.161106    " name="pixel0178"/>
+   <location y="  -0.159073    " name="pixel0179"/>
+   <location y="  -0.157040    " name="pixel0180"/>
+   <location y="  -0.155007    " name="pixel0181"/>
+   <location y="  -0.152974    " name="pixel0182"/>
+   <location y="  -0.150940    " name="pixel0183"/>
+   <location y="  -0.148907    " name="pixel0184"/>
+   <location y="  -0.146874    " name="pixel0185"/>
+   <location y="  -0.144841    " name="pixel0186"/>
+   <location y="  -0.142808    " name="pixel0187"/>
+   <location y="  -0.140774    " name="pixel0188"/>
+   <location y="  -0.138741    " name="pixel0189"/>
+   <location y="  -0.136708    " name="pixel0190"/>
+   <location y="  -0.134675    " name="pixel0191"/>
+   <location y="  -0.132642    " name="pixel0192"/>
+   <location y="  -0.130608    " name="pixel0193"/>
+   <location y="  -0.128575    " name="pixel0194"/>
+   <location y="  -0.126542    " name="pixel0195"/>
+   <location y="  -0.124509    " name="pixel0196"/>
+   <location y="  -0.122476    " name="pixel0197"/>
+   <location y="  -0.120442    " name="pixel0198"/>
+   <location y="  -0.118409    " name="pixel0199"/>
+   <location y="  -0.116376    " name="pixel0200"/>
+   <location y="  -0.114343    " name="pixel0201"/>
+   <location y="  -0.112310    " name="pixel0202"/>
+   <location y="  -0.110276    " name="pixel0203"/>
+   <location y="  -0.108243    " name="pixel0204"/>
+   <location y="  -0.106210    " name="pixel0205"/>
+   <location y="  -0.104177    " name="pixel0206"/>
+   <location y="  -0.102144    " name="pixel0207"/>
+   <location y="  -0.100110    " name="pixel0208"/>
+   <location y="  -0.980771E-01" name="pixel0209"/>
+   <location y="  -0.960439E-01" name="pixel0210"/>
+   <location y="  -0.940107E-01" name="pixel0211"/>
+   <location y="  -0.919775E-01" name="pixel0212"/>
+   <location y="  -0.899443E-01" name="pixel0213"/>
+   <location y="  -0.879111E-01" name="pixel0214"/>
+   <location y="  -0.858779E-01" name="pixel0215"/>
+   <location y="  -0.838447E-01" name="pixel0216"/>
+   <location y="  -0.818115E-01" name="pixel0217"/>
+   <location y="  -0.797783E-01" name="pixel0218"/>
+   <location y="  -0.777451E-01" name="pixel0219"/>
+   <location y="  -0.757119E-01" name="pixel0220"/>
+   <location y="  -0.736787E-01" name="pixel0221"/>
+   <location y="  -0.716455E-01" name="pixel0222"/>
+   <location y="  -0.696123E-01" name="pixel0223"/>
+   <location y="  -0.675791E-01" name="pixel0224"/>
+   <location y="  -0.655459E-01" name="pixel0225"/>
+   <location y="  -0.635127E-01" name="pixel0226"/>
+   <location y="  -0.614795E-01" name="pixel0227"/>
+   <location y="  -0.594463E-01" name="pixel0228"/>
+   <location y="  -0.574131E-01" name="pixel0229"/>
+   <location y="  -0.553799E-01" name="pixel0230"/>
+   <location y="  -0.533467E-01" name="pixel0231"/>
+   <location y="  -0.513135E-01" name="pixel0232"/>
+   <location y="  -0.492803E-01" name="pixel0233"/>
+   <location y="  -0.472471E-01" name="pixel0234"/>
+   <location y="  -0.452139E-01" name="pixel0235"/>
+   <location y="  -0.431807E-01" name="pixel0236"/>
+   <location y="  -0.411475E-01" name="pixel0237"/>
+   <location y="  -0.391143E-01" name="pixel0238"/>
+   <location y="  -0.370811E-01" name="pixel0239"/>
+   <location y="  -0.350479E-01" name="pixel0240"/>
+   <location y="  -0.330146E-01" name="pixel0241"/>
+   <location y="  -0.309814E-01" name="pixel0242"/>
+   <location y="  -0.289482E-01" name="pixel0243"/>
+   <location y="  -0.269150E-01" name="pixel0244"/>
+   <location y="  -0.248818E-01" name="pixel0245"/>
+   <location y="  -0.228486E-01" name="pixel0246"/>
+   <location y="  -0.208154E-01" name="pixel0247"/>
+   <location y="  -0.187822E-01" name="pixel0248"/>
+   <location y="  -0.167490E-01" name="pixel0249"/>
+   <location y="  -0.147158E-01" name="pixel0250"/>
+   <location y="  -0.126826E-01" name="pixel0251"/>
+   <location y="  -0.106494E-01" name="pixel0252"/>
+   <location y="  -0.861621E-02" name="pixel0253"/>
+   <location y="  -0.658301E-02" name="pixel0254"/>
+   <location y="  -0.454980E-02" name="pixel0255"/>
+   <location y="  -0.251660E-02" name="pixel0256"/>
+   <location y="  -0.483398E-03" name="pixel0257"/>
+   <location y="   0.154980E-02" name="pixel0258"/>
+   <location y="   0.358301E-02" name="pixel0259"/>
+   <location y="   0.561621E-02" name="pixel0260"/>
+   <location y="   0.764941E-02" name="pixel0261"/>
+   <location y="   0.968262E-02" name="pixel0262"/>
+   <location y="   0.117158E-01" name="pixel0263"/>
+   <location y="   0.137490E-01" name="pixel0264"/>
+   <location y="   0.157822E-01" name="pixel0265"/>
+   <location y="   0.178154E-01" name="pixel0266"/>
+   <location y="   0.198486E-01" name="pixel0267"/>
+   <location y="   0.218818E-01" name="pixel0268"/>
+   <location y="   0.239150E-01" name="pixel0269"/>
+   <location y="   0.259482E-01" name="pixel0270"/>
+   <location y="   0.279814E-01" name="pixel0271"/>
+   <location y="   0.300146E-01" name="pixel0272"/>
+   <location y="   0.320479E-01" name="pixel0273"/>
+   <location y="   0.340811E-01" name="pixel0274"/>
+   <location y="   0.361143E-01" name="pixel0275"/>
+   <location y="   0.381475E-01" name="pixel0276"/>
+   <location y="   0.401807E-01" name="pixel0277"/>
+   <location y="   0.422139E-01" name="pixel0278"/>
+   <location y="   0.442471E-01" name="pixel0279"/>
+   <location y="   0.462803E-01" name="pixel0280"/>
+   <location y="   0.483135E-01" name="pixel0281"/>
+   <location y="   0.503467E-01" name="pixel0282"/>
+   <location y="   0.523799E-01" name="pixel0283"/>
+   <location y="   0.544131E-01" name="pixel0284"/>
+   <location y="   0.564463E-01" name="pixel0285"/>
+   <location y="   0.584795E-01" name="pixel0286"/>
+   <location y="   0.605127E-01" name="pixel0287"/>
+   <location y="   0.625459E-01" name="pixel0288"/>
+   <location y="   0.645791E-01" name="pixel0289"/>
+   <location y="   0.666123E-01" name="pixel0290"/>
+   <location y="   0.686455E-01" name="pixel0291"/>
+   <location y="   0.706787E-01" name="pixel0292"/>
+   <location y="   0.727119E-01" name="pixel0293"/>
+   <location y="   0.747451E-01" name="pixel0294"/>
+   <location y="   0.767783E-01" name="pixel0295"/>
+   <location y="   0.788115E-01" name="pixel0296"/>
+   <location y="   0.808447E-01" name="pixel0297"/>
+   <location y="   0.828779E-01" name="pixel0298"/>
+   <location y="   0.849111E-01" name="pixel0299"/>
+   <location y="   0.869443E-01" name="pixel0300"/>
+   <location y="   0.889775E-01" name="pixel0301"/>
+   <location y="   0.910107E-01" name="pixel0302"/>
+   <location y="   0.930439E-01" name="pixel0303"/>
+   <location y="   0.950771E-01" name="pixel0304"/>
+   <location y="   0.971104E-01" name="pixel0305"/>
+   <location y="   0.991436E-01" name="pixel0306"/>
+   <location y="   0.101177    " name="pixel0307"/>
+   <location y="   0.103210    " name="pixel0308"/>
+   <location y="   0.105243    " name="pixel0309"/>
+   <location y="   0.107276    " name="pixel0310"/>
+   <location y="   0.109310    " name="pixel0311"/>
+   <location y="   0.111343    " name="pixel0312"/>
+   <location y="   0.113376    " name="pixel0313"/>
+   <location y="   0.115409    " name="pixel0314"/>
+   <location y="   0.117442    " name="pixel0315"/>
+   <location y="   0.119476    " name="pixel0316"/>
+   <location y="   0.121509    " name="pixel0317"/>
+   <location y="   0.123542    " name="pixel0318"/>
+   <location y="   0.125575    " name="pixel0319"/>
+   <location y="   0.127608    " name="pixel0320"/>
+   <location y="   0.129642    " name="pixel0321"/>
+   <location y="   0.131675    " name="pixel0322"/>
+   <location y="   0.133708    " name="pixel0323"/>
+   <location y="   0.135741    " name="pixel0324"/>
+   <location y="   0.137774    " name="pixel0325"/>
+   <location y="   0.139808    " name="pixel0326"/>
+   <location y="   0.141841    " name="pixel0327"/>
+   <location y="   0.143874    " name="pixel0328"/>
+   <location y="   0.145907    " name="pixel0329"/>
+   <location y="   0.147940    " name="pixel0330"/>
+   <location y="   0.149974    " name="pixel0331"/>
+   <location y="   0.152007    " name="pixel0332"/>
+   <location y="   0.154040    " name="pixel0333"/>
+   <location y="   0.156073    " name="pixel0334"/>
+   <location y="   0.158106    " name="pixel0335"/>
+   <location y="   0.160140    " name="pixel0336"/>
+   <location y="   0.162173    " name="pixel0337"/>
+   <location y="   0.164206    " name="pixel0338"/>
+   <location y="   0.166239    " name="pixel0339"/>
+   <location y="   0.168272    " name="pixel0340"/>
+   <location y="   0.170306    " name="pixel0341"/>
+   <location y="   0.172339    " name="pixel0342"/>
+   <location y="   0.174372    " name="pixel0343"/>
+   <location y="   0.176405    " name="pixel0344"/>
+   <location y="   0.178438    " name="pixel0345"/>
+   <location y="   0.180472    " name="pixel0346"/>
+   <location y="   0.182505    " name="pixel0347"/>
+   <location y="   0.184538    " name="pixel0348"/>
+   <location y="   0.186571    " name="pixel0349"/>
+   <location y="   0.188604    " name="pixel0350"/>
+   <location y="   0.190638    " name="pixel0351"/>
+   <location y="   0.192671    " name="pixel0352"/>
+   <location y="   0.194704    " name="pixel0353"/>
+   <location y="   0.196737    " name="pixel0354"/>
+   <location y="   0.198771    " name="pixel0355"/>
+   <location y="   0.200804    " name="pixel0356"/>
+   <location y="   0.202837    " name="pixel0357"/>
+   <location y="   0.204870    " name="pixel0358"/>
+   <location y="   0.206903    " name="pixel0359"/>
+   <location y="   0.208937    " name="pixel0360"/>
+   <location y="   0.210970    " name="pixel0361"/>
+   <location y="   0.213003    " name="pixel0362"/>
+   <location y="   0.215036    " name="pixel0363"/>
+   <location y="   0.217069    " name="pixel0364"/>
+   <location y="   0.219103    " name="pixel0365"/>
+   <location y="   0.221136    " name="pixel0366"/>
+   <location y="   0.223169    " name="pixel0367"/>
+   <location y="   0.225202    " name="pixel0368"/>
+   <location y="   0.227235    " name="pixel0369"/>
+   <location y="   0.229269    " name="pixel0370"/>
+   <location y="   0.231302    " name="pixel0371"/>
+   <location y="   0.233335    " name="pixel0372"/>
+   <location y="   0.235368    " name="pixel0373"/>
+   <location y="   0.237401    " name="pixel0374"/>
+   <location y="   0.239435    " name="pixel0375"/>
+   <location y="   0.241468    " name="pixel0376"/>
+   <location y="   0.243501    " name="pixel0377"/>
+   <location y="   0.245534    " name="pixel0378"/>
+   <location y="   0.247567    " name="pixel0379"/>
+   <location y="   0.249601    " name="pixel0380"/>
+   <location y="   0.251634    " name="pixel0381"/>
+   <location y="   0.253667    " name="pixel0382"/>
+   <location y="   0.255700    " name="pixel0383"/>
+   <location y="   0.257733    " name="pixel0384"/>
+   <location y="   0.259767    " name="pixel0385"/>
+   <location y="   0.261800    " name="pixel0386"/>
+   <location y="   0.263833    " name="pixel0387"/>
+   <location y="   0.265866    " name="pixel0388"/>
+   <location y="   0.267899    " name="pixel0389"/>
+   <location y="   0.269933    " name="pixel0390"/>
+   <location y="   0.271966    " name="pixel0391"/>
+   <location y="   0.273999    " name="pixel0392"/>
+   <location y="   0.276032    " name="pixel0393"/>
+   <location y="   0.278065    " name="pixel0394"/>
+   <location y="   0.280099    " name="pixel0395"/>
+   <location y="   0.282132    " name="pixel0396"/>
+   <location y="   0.284165    " name="pixel0397"/>
+   <location y="   0.286198    " name="pixel0398"/>
+   <location y="   0.288231    " name="pixel0399"/>
+   <location y="   0.290265    " name="pixel0400"/>
+   <location y="   0.292298    " name="pixel0401"/>
+   <location y="   0.294331    " name="pixel0402"/>
+   <location y="   0.296364    " name="pixel0403"/>
+   <location y="   0.298397    " name="pixel0404"/>
+   <location y="   0.300431    " name="pixel0405"/>
+   <location y="   0.302464    " name="pixel0406"/>
+   <location y="   0.304497    " name="pixel0407"/>
+   <location y="   0.306530    " name="pixel0408"/>
+   <location y="   0.308563    " name="pixel0409"/>
+   <location y="   0.310597    " name="pixel0410"/>
+   <location y="   0.312630    " name="pixel0411"/>
+   <location y="   0.314663    " name="pixel0412"/>
+   <location y="   0.316696    " name="pixel0413"/>
+   <location y="   0.318729    " name="pixel0414"/>
+   <location y="   0.320763    " name="pixel0415"/>
+   <location y="   0.322796    " name="pixel0416"/>
+   <location y="   0.324829    " name="pixel0417"/>
+   <location y="   0.326862    " name="pixel0418"/>
+   <location y="   0.328896    " name="pixel0419"/>
+   <location y="   0.330929    " name="pixel0420"/>
+   <location y="   0.332962    " name="pixel0421"/>
+   <location y="   0.334995    " name="pixel0422"/>
+   <location y="   0.337028    " name="pixel0423"/>
+   <location y="   0.339062    " name="pixel0424"/>
+   <location y="   0.341095    " name="pixel0425"/>
+   <location y="   0.343128    " name="pixel0426"/>
+   <location y="   0.345161    " name="pixel0427"/>
+   <location y="   0.347194    " name="pixel0428"/>
+   <location y="   0.349228    " name="pixel0429"/>
+   <location y="   0.351261    " name="pixel0430"/>
+   <location y="   0.353294    " name="pixel0431"/>
+   <location y="   0.355327    " name="pixel0432"/>
+   <location y="   0.357360    " name="pixel0433"/>
+   <location y="   0.359394    " name="pixel0434"/>
+   <location y="   0.361427    " name="pixel0435"/>
+   <location y="   0.363460    " name="pixel0436"/>
+   <location y="   0.365493    " name="pixel0437"/>
+   <location y="   0.367526    " name="pixel0438"/>
+   <location y="   0.369560    " name="pixel0439"/>
+   <location y="   0.371593    " name="pixel0440"/>
+   <location y="   0.373626    " name="pixel0441"/>
+   <location y="   0.375659    " name="pixel0442"/>
+   <location y="   0.377692    " name="pixel0443"/>
+   <location y="   0.379726    " name="pixel0444"/>
+   <location y="   0.381759    " name="pixel0445"/>
+   <location y="   0.383792    " name="pixel0446"/>
+   <location y="   0.385825    " name="pixel0447"/>
+   <location y="   0.387858    " name="pixel0448"/>
+   <location y="   0.389892    " name="pixel0449"/>
+   <location y="   0.391925    " name="pixel0450"/>
+   <location y="   0.393958    " name="pixel0451"/>
+   <location y="   0.395991    " name="pixel0452"/>
+   <location y="   0.398024    " name="pixel0453"/>
+   <location y="   0.400058    " name="pixel0454"/>
+   <location y="   0.402091    " name="pixel0455"/>
+   <location y="   0.404124    " name="pixel0456"/>
+   <location y="   0.406157    " name="pixel0457"/>
+   <location y="   0.408190    " name="pixel0458"/>
+   <location y="   0.410224    " name="pixel0459"/>
+   <location y="   0.412257    " name="pixel0460"/>
+   <location y="   0.414290    " name="pixel0461"/>
+   <location y="   0.416323    " name="pixel0462"/>
+   <location y="   0.418356    " name="pixel0463"/>
+   <location y="   0.420390    " name="pixel0464"/>
+   <location y="   0.422423    " name="pixel0465"/>
+   <location y="   0.424456    " name="pixel0466"/>
+   <location y="   0.426489    " name="pixel0467"/>
+   <location y="   0.428522    " name="pixel0468"/>
+   <location y="   0.430556    " name="pixel0469"/>
+   <location y="   0.432589    " name="pixel0470"/>
+   <location y="   0.434622    " name="pixel0471"/>
+   <location y="   0.436655    " name="pixel0472"/>
+   <location y="   0.438688    " name="pixel0473"/>
+   <location y="   0.440722    " name="pixel0474"/>
+   <location y="   0.442755    " name="pixel0475"/>
+   <location y="   0.444788    " name="pixel0476"/>
+   <location y="   0.446821    " name="pixel0477"/>
+   <location y="   0.448854    " name="pixel0478"/>
+   <location y="   0.450888    " name="pixel0479"/>
+   <location y="   0.452921    " name="pixel0480"/>
+   <location y="   0.454954    " name="pixel0481"/>
+   <location y="   0.456987    " name="pixel0482"/>
+   <location y="   0.459021    " name="pixel0483"/>
+   <location y="   0.461054    " name="pixel0484"/>
+   <location y="   0.463087    " name="pixel0485"/>
+   <location y="   0.465120    " name="pixel0486"/>
+   <location y="   0.467153    " name="pixel0487"/>
+   <location y="   0.469187    " name="pixel0488"/>
+   <location y="   0.471220    " name="pixel0489"/>
+   <location y="   0.473253    " name="pixel0490"/>
+   <location y="   0.475286    " name="pixel0491"/>
+   <location y="   0.477319    " name="pixel0492"/>
+   <location y="   0.479353    " name="pixel0493"/>
+   <location y="   0.481386    " name="pixel0494"/>
+   <location y="   0.483419    " name="pixel0495"/>
+   <location y="   0.485452    " name="pixel0496"/>
+   <location y="   0.487485    " name="pixel0497"/>
+   <location y="   0.489519    " name="pixel0498"/>
+   <location y="   0.491552    " name="pixel0499"/>
+   <location y="   0.493585    " name="pixel0500"/>
+   <location y="   0.495618    " name="pixel0501"/>
+   <location y="   0.497651    " name="pixel0502"/>
+   <location y="   0.499685    " name="pixel0503"/>
+   <location y="   0.501718    " name="pixel0504"/>
+   <location y="   0.503751    " name="pixel0505"/>
+   <location y="   0.505784    " name="pixel0506"/>
+   <location y="   0.507817    " name="pixel0507"/>
+   <location y="   0.509851    " name="pixel0508"/>
+   <location y="   0.511884    " name="pixel0509"/>
+   <location y="   0.513917    " name="pixel0510"/>
+   <location y="   0.515950    " name="pixel0511"/>
+   <location y="   0.517983    " name="pixel0512"/>
+ </component>
+ </type>
+ 
+ <type name="monitor" is="monitor">
+  <properties/>
+  <cylinder id="some-shape">
+ <centre-of-bottom-base r="0.0" t="0.0" p="0.0" />
+ <axis x="0.0" y="0.0" z="1.0" />
+ <radius val="0.01" />
+ <height val="0.03" />
+ </cylinder>
+ <algebra val="some-shape" />
+ </type>
+
+  <type name="pixel" is="detector">
+    <cylinder id="cyl-approx">
+      <centre-of-bottom-base r="0.0" t="0.0" p="0.0" />
+      <axis x="0.0" y="0.2" z="0.0" />
+      <radius val="0.004" />
+      <height val="   0.203320E-02" />
+    </cylinder>
+    <algebra val="cyl-approx" />
+  </type>
+ 
+  <!-- MONITOR ID LISTS -->
+   <idlist idname="monitors">
+     <id start="1" end="5" />
+   </idlist>
+ 
+   <!-- DETECTOR ID LISTS -->
+  <idlist idname="panel01">
+   <id start="01707000" end="01707511" />
+   <id start="01705000" end="01705511" />
+   <id start="01703000" end="01703511" />
+   <id start="01701000" end="01701511" />
+   <id start="01623000" end="01623511" />
+   <id start="01621000" end="01621511" />
+   <id start="01619000" end="01619511" />
+   <id start="01617000" end="01617511" />
+   <id start="01615000" end="01615511" />
+   <id start="01613000" end="01613511" />
+   <id start="01611000" end="01611511" />
+   <id start="01609000" end="01609511" />
+   <id start="01607000" end="01607511" />
+   <id start="01605000" end="01605511" />
+   <id start="01603000" end="01603511" />
+   <id start="01601000" end="01601511" />
+   <id start="01523000" end="01523511" />
+   <id start="01521000" end="01521511" />
+   <id start="01519000" end="01519511" />
+   <id start="01517000" end="01517511" />
+   <id start="01515000" end="01515511" />
+   <id start="01513000" end="01513511" />
+   <id start="01511000" end="01511511" />
+   <id start="01509000" end="01509511" />
+   <id start="01507000" end="01507511" />
+   <id start="01505000" end="01505511" />
+   <id start="01503000" end="01503511" />
+   <id start="01501000" end="01501511" />
+   <id start="01423000" end="01423511" />
+   <id start="01421000" end="01421511" />
+   <id start="01419000" end="01419511" />
+   <id start="01417000" end="01417511" />
+   <id start="01415000" end="01415511" />
+   <id start="01413000" end="01413511" />
+   <id start="01411000" end="01411511" />
+   <id start="01409000" end="01409511" />
+   <id start="01407000" end="01407511" />
+   <id start="01405000" end="01405511" />
+   <id start="01403000" end="01403511" />
+   <id start="01401000" end="01401511" />
+   <id start="01323000" end="01323511" />
+   <id start="01321000" end="01321511" />
+   <id start="01319000" end="01319511" />
+   <id start="01317000" end="01317511" />
+   <id start="01315000" end="01315511" />
+   <id start="01313000" end="01313511" />
+   <id start="01311000" end="01311511" />
+   <id start="01309000" end="01309511" />
+   <id start="01307000" end="01307511" />
+   <id start="01305000" end="01305511" />
+   <id start="01303000" end="01303511" />
+   <id start="01301000" end="01301511" />
+   <id start="01223000" end="01223511" />
+   <id start="01221000" end="01221511" />
+   <id start="01219000" end="01219511" />
+   <id start="01217000" end="01217511" />
+   <id start="01215000" end="01215511" />
+   <id start="01213000" end="01213511" />
+   <id start="01211000" end="01211511" />
+   <id start="01209000" end="01209511" />
+   <id start="01207000" end="01207511" />
+   <id start="01205000" end="01205511" />
+   <id start="01203000" end="01203511" />
+   <id start="01201000" end="01201511" />
+   <id start="01123000" end="01123511" />
+   <id start="01121000" end="01121511" />
+   <id start="01119000" end="01119511" />
+   <id start="01117000" end="01117511" />
+   <id start="01115000" end="01115511" />
+   <id start="01113000" end="01113511" />
+   <id start="01111000" end="01111511" />
+   <id start="01109000" end="01109511" />
+   <id start="01107000" end="01107511" />
+   <id start="01105000" end="01105511" />
+   <id start="01103000" end="01103511" />
+   <id start="01101000" end="01101511" />
+   <id start="01706000" end="01706511" />
+   <id start="01704000" end="01704511" />
+   <id start="01702000" end="01702511" />
+   <id start="01700000" end="01700511" />
+   <id start="01622000" end="01622511" />
+   <id start="01620000" end="01620511" />
+   <id start="01618000" end="01618511" />
+   <id start="01616000" end="01616511" />
+   <id start="01614000" end="01614511" />
+   <id start="01612000" end="01612511" />
+   <id start="01610000" end="01610511" />
+   <id start="01608000" end="01608511" />
+   <id start="01606000" end="01606511" />
+   <id start="01604000" end="01604511" />
+   <id start="01602000" end="01602511" />
+   <id start="01600000" end="01600511" />
+   <id start="01522000" end="01522511" />
+   <id start="01520000" end="01520511" />
+   <id start="01518000" end="01518511" />
+   <id start="01516000" end="01516511" />
+   <id start="01514000" end="01514511" />
+   <id start="01512000" end="01512511" />
+   <id start="01510000" end="01510511" />
+   <id start="01508000" end="01508511" />
+   <id start="01506000" end="01506511" />
+   <id start="01504000" end="01504511" />
+   <id start="01502000" end="01502511" />
+   <id start="01500000" end="01500511" />
+   <id start="01422000" end="01422511" />
+   <id start="01420000" end="01420511" />
+   <id start="01418000" end="01418511" />
+   <id start="01416000" end="01416511" />
+   <id start="01414000" end="01414511" />
+   <id start="01412000" end="01412511" />
+   <id start="01410000" end="01410511" />
+   <id start="01408000" end="01408511" />
+   <id start="01406000" end="01406511" />
+   <id start="01404000" end="01404511" />
+   <id start="01402000" end="01402511" />
+   <id start="01400000" end="01400511" />
+   <id start="01322000" end="01322511" />
+   <id start="01320000" end="01320511" />
+   <id start="01318000" end="01318511" />
+   <id start="01316000" end="01316511" />
+   <id start="01314000" end="01314511" />
+   <id start="01312000" end="01312511" />
+   <id start="01310000" end="01310511" />
+   <id start="01308000" end="01308511" />
+   <id start="01306000" end="01306511" />
+   <id start="01304000" end="01304511" />
+   <id start="01302000" end="01302511" />
+   <id start="01300000" end="01300511" />
+   <id start="01222000" end="01222511" />
+   <id start="01220000" end="01220511" />
+   <id start="01218000" end="01218511" />
+   <id start="01216000" end="01216511" />
+   <id start="01214000" end="01214511" />
+   <id start="01212000" end="01212511" />
+   <id start="01210000" end="01210511" />
+   <id start="01208000" end="01208511" />
+   <id start="01206000" end="01206511" />
+   <id start="01204000" end="01204511" />
+   <id start="01202000" end="01202511" />
+   <id start="01200000" end="01200511" />
+   <id start="01122000" end="01122511" />
+   <id start="01120000" end="01120511" />
+   <id start="01118000" end="01118511" />
+   <id start="01116000" end="01116511" />
+   <id start="01114000" end="01114511" />
+   <id start="01112000" end="01112511" />
+   <id start="01110000" end="01110511" />
+   <id start="01108000" end="01108511" />
+   <id start="01106000" end="01106511" />
+   <id start="01104000" end="01104511" />
+   <id start="01102000" end="01102511" />
+   <id start="01100000" end="01100511" />
+   </idlist>
+  <idlist idname="panel02">
+   <id start="02707000" end="02707511" />
+   <id start="02705000" end="02705511" />
+   <id start="02703000" end="02703511" />
+   <id start="02701000" end="02701511" />
+   <id start="02623000" end="02623511" />
+   <id start="02621000" end="02621511" />
+   <id start="02619000" end="02619511" />
+   <id start="02617000" end="02617511" />
+   <id start="02615000" end="02615511" />
+   <id start="02613000" end="02613511" />
+   <id start="02611000" end="02611511" />
+   <id start="02609000" end="02609511" />
+   <id start="02607000" end="02607511" />
+   <id start="02605000" end="02605511" />
+   <id start="02603000" end="02603511" />
+   <id start="02601000" end="02601511" />
+   <id start="02523000" end="02523511" />
+   <id start="02521000" end="02521511" />
+   <id start="02519000" end="02519511" />
+   <id start="02517000" end="02517511" />
+   <id start="02515000" end="02515511" />
+   <id start="02513000" end="02513511" />
+   <id start="02511000" end="02511511" />
+   <id start="02509000" end="02509511" />
+   <id start="02507000" end="02507511" />
+   <id start="02505000" end="02505511" />
+   <id start="02503000" end="02503511" />
+   <id start="02501000" end="02501511" />
+   <id start="02423000" end="02423511" />
+   <id start="02421000" end="02421511" />
+   <id start="02419000" end="02419511" />
+   <id start="02417000" end="02417511" />
+   <id start="02415000" end="02415511" />
+   <id start="02413000" end="02413511" />
+   <id start="02411000" end="02411511" />
+   <id start="02409000" end="02409511" />
+   <id start="02407000" end="02407511" />
+   <id start="02405000" end="02405511" />
+   <id start="02403000" end="02403511" />
+   <id start="02401000" end="02401511" />
+   <id start="02323000" end="02323511" />
+   <id start="02321000" end="02321511" />
+   <id start="02319000" end="02319511" />
+   <id start="02317000" end="02317511" />
+   <id start="02315000" end="02315511" />
+   <id start="02313000" end="02313511" />
+   <id start="02311000" end="02311511" />
+   <id start="02309000" end="02309511" />
+   <id start="02307000" end="02307511" />
+   <id start="02305000" end="02305511" />
+   <id start="02303000" end="02303511" />
+   <id start="02301000" end="02301511" />
+   <id start="02223000" end="02223511" />
+   <id start="02221000" end="02221511" />
+   <id start="02219000" end="02219511" />
+   <id start="02217000" end="02217511" />
+   <id start="02215000" end="02215511" />
+   <id start="02213000" end="02213511" />
+   <id start="02211000" end="02211511" />
+   <id start="02209000" end="02209511" />
+   <id start="02207000" end="02207511" />
+   <id start="02205000" end="02205511" />
+   <id start="02203000" end="02203511" />
+   <id start="02201000" end="02201511" />
+   <id start="02123000" end="02123511" />
+   <id start="02121000" end="02121511" />
+   <id start="02119000" end="02119511" />
+   <id start="02117000" end="02117511" />
+   <id start="02115000" end="02115511" />
+   <id start="02113000" end="02113511" />
+   <id start="02111000" end="02111511" />
+   <id start="02109000" end="02109511" />
+   <id start="02107000" end="02107511" />
+   <id start="02105000" end="02105511" />
+   <id start="02103000" end="02103511" />
+   <id start="02101000" end="02101511" />
+   <id start="02706000" end="02706511" />
+   <id start="02704000" end="02704511" />
+   <id start="02702000" end="02702511" />
+   <id start="02700000" end="02700511" />
+   <id start="02622000" end="02622511" />
+   <id start="02620000" end="02620511" />
+   <id start="02618000" end="02618511" />
+   <id start="02616000" end="02616511" />
+   <id start="02614000" end="02614511" />
+   <id start="02612000" end="02612511" />
+   <id start="02610000" end="02610511" />
+   <id start="02608000" end="02608511" />
+   <id start="02606000" end="02606511" />
+   <id start="02604000" end="02604511" />
+   <id start="02602000" end="02602511" />
+   <id start="02600000" end="02600511" />
+   <id start="02522000" end="02522511" />
+   <id start="02520000" end="02520511" />
+   <id start="02518000" end="02518511" />
+   <id start="02516000" end="02516511" />
+   <id start="02514000" end="02514511" />
+   <id start="02512000" end="02512511" />
+   <id start="02510000" end="02510511" />
+   <id start="02508000" end="02508511" />
+   <id start="02506000" end="02506511" />
+   <id start="02504000" end="02504511" />
+   <id start="02502000" end="02502511" />
+   <id start="02500000" end="02500511" />
+   <id start="02422000" end="02422511" />
+   <id start="02420000" end="02420511" />
+   <id start="02418000" end="02418511" />
+   <id start="02416000" end="02416511" />
+   <id start="02414000" end="02414511" />
+   <id start="02412000" end="02412511" />
+   <id start="02410000" end="02410511" />
+   <id start="02408000" end="02408511" />
+   <id start="02406000" end="02406511" />
+   <id start="02404000" end="02404511" />
+   <id start="02402000" end="02402511" />
+   <id start="02400000" end="02400511" />
+   <id start="02322000" end="02322511" />
+   <id start="02320000" end="02320511" />
+   <id start="02318000" end="02318511" />
+   <id start="02316000" end="02316511" />
+   <id start="02314000" end="02314511" />
+   <id start="02312000" end="02312511" />
+   <id start="02310000" end="02310511" />
+   <id start="02308000" end="02308511" />
+   <id start="02306000" end="02306511" />
+   <id start="02304000" end="02304511" />
+   <id start="02302000" end="02302511" />
+   <id start="02300000" end="02300511" />
+   <id start="02222000" end="02222511" />
+   <id start="02220000" end="02220511" />
+   <id start="02218000" end="02218511" />
+   <id start="02216000" end="02216511" />
+   <id start="02214000" end="02214511" />
+   <id start="02212000" end="02212511" />
+   <id start="02210000" end="02210511" />
+   <id start="02208000" end="02208511" />
+   <id start="02206000" end="02206511" />
+   <id start="02204000" end="02204511" />
+   <id start="02202000" end="02202511" />
+   <id start="02200000" end="02200511" />
+   <id start="02122000" end="02122511" />
+   <id start="02120000" end="02120511" />
+   <id start="02118000" end="02118511" />
+   <id start="02116000" end="02116511" />
+   <id start="02114000" end="02114511" />
+   <id start="02112000" end="02112511" />
+   <id start="02110000" end="02110511" />
+   <id start="02108000" end="02108511" />
+   <id start="02106000" end="02106511" />
+   <id start="02104000" end="02104511" />
+   <id start="02102000" end="02102511" />
+   <id start="02100000" end="02100511" />
+   </idlist>
+  <idlist idname="panel03">
+   <id start="03707000" end="03707511" />
+   <id start="03705000" end="03705511" />
+   <id start="03703000" end="03703511" />
+   <id start="03701000" end="03701511" />
+   <id start="03623000" end="03623511" />
+   <id start="03621000" end="03621511" />
+   <id start="03619000" end="03619511" />
+   <id start="03617000" end="03617511" />
+   <id start="03615000" end="03615511" />
+   <id start="03613000" end="03613511" />
+   <id start="03611000" end="03611511" />
+   <id start="03609000" end="03609511" />
+   <id start="03607000" end="03607511" />
+   <id start="03605000" end="03605511" />
+   <id start="03603000" end="03603511" />
+   <id start="03601000" end="03601511" />
+   <id start="03523000" end="03523511" />
+   <id start="03521000" end="03521511" />
+   <id start="03519000" end="03519511" />
+   <id start="03517000" end="03517511" />
+   <id start="03515000" end="03515511" />
+   <id start="03513000" end="03513511" />
+   <id start="03511000" end="03511511" />
+   <id start="03509000" end="03509511" />
+   <id start="03507000" end="03507511" />
+   <id start="03505000" end="03505511" />
+   <id start="03503000" end="03503511" />
+   <id start="03501000" end="03501511" />
+   <id start="03423000" end="03423511" />
+   <id start="03421000" end="03421511" />
+   <id start="03419000" end="03419511" />
+   <id start="03417000" end="03417511" />
+   <id start="03415000" end="03415511" />
+   <id start="03413000" end="03413511" />
+   <id start="03411000" end="03411511" />
+   <id start="03409000" end="03409511" />
+   <id start="03407000" end="03407511" />
+   <id start="03405000" end="03405511" />
+   <id start="03403000" end="03403511" />
+   <id start="03401000" end="03401511" />
+   <id start="03323000" end="03323511" />
+   <id start="03321000" end="03321511" />
+   <id start="03319000" end="03319511" />
+   <id start="03317000" end="03317511" />
+   <id start="03315000" end="03315511" />
+   <id start="03313000" end="03313511" />
+   <id start="03311000" end="03311511" />
+   <id start="03309000" end="03309511" />
+   <id start="03307000" end="03307511" />
+   <id start="03305000" end="03305511" />
+   <id start="03303000" end="03303511" />
+   <id start="03301000" end="03301511" />
+   <id start="03223000" end="03223511" />
+   <id start="03221000" end="03221511" />
+   <id start="03219000" end="03219511" />
+   <id start="03217000" end="03217511" />
+   <id start="03215000" end="03215511" />
+   <id start="03213000" end="03213511" />
+   <id start="03211000" end="03211511" />
+   <id start="03209000" end="03209511" />
+   <id start="03207000" end="03207511" />
+   <id start="03205000" end="03205511" />
+   <id start="03203000" end="03203511" />
+   <id start="03201000" end="03201511" />
+   <id start="03123000" end="03123511" />
+   <id start="03121000" end="03121511" />
+   <id start="03119000" end="03119511" />
+   <id start="03117000" end="03117511" />
+   <id start="03115000" end="03115511" />
+   <id start="03113000" end="03113511" />
+   <id start="03111000" end="03111511" />
+   <id start="03109000" end="03109511" />
+   <id start="03107000" end="03107511" />
+   <id start="03105000" end="03105511" />
+   <id start="03103000" end="03103511" />
+   <id start="03101000" end="03101511" />
+   <id start="03706000" end="03706511" />
+   <id start="03704000" end="03704511" />
+   <id start="03702000" end="03702511" />
+   <id start="03700000" end="03700511" />
+   <id start="03622000" end="03622511" />
+   <id start="03620000" end="03620511" />
+   <id start="03618000" end="03618511" />
+   <id start="03616000" end="03616511" />
+   <id start="03614000" end="03614511" />
+   <id start="03612000" end="03612511" />
+   <id start="03610000" end="03610511" />
+   <id start="03608000" end="03608511" />
+   <id start="03606000" end="03606511" />
+   <id start="03604000" end="03604511" />
+   <id start="03602000" end="03602511" />
+   <id start="03600000" end="03600511" />
+   <id start="03522000" end="03522511" />
+   <id start="03520000" end="03520511" />
+   <id start="03518000" end="03518511" />
+   <id start="03516000" end="03516511" />
+   <id start="03514000" end="03514511" />
+   <id start="03512000" end="03512511" />
+   <id start="03510000" end="03510511" />
+   <id start="03508000" end="03508511" />
+   <id start="03506000" end="03506511" />
+   <id start="03504000" end="03504511" />
+   <id start="03502000" end="03502511" />
+   <id start="03500000" end="03500511" />
+   <id start="03422000" end="03422511" />
+   <id start="03420000" end="03420511" />
+   <id start="03418000" end="03418511" />
+   <id start="03416000" end="03416511" />
+   <id start="03414000" end="03414511" />
+   <id start="03412000" end="03412511" />
+   <id start="03410000" end="03410511" />
+   <id start="03408000" end="03408511" />
+   <id start="03406000" end="03406511" />
+   <id start="03404000" end="03404511" />
+   <id start="03402000" end="03402511" />
+   <id start="03400000" end="03400511" />
+   <id start="03322000" end="03322511" />
+   <id start="03320000" end="03320511" />
+   <id start="03318000" end="03318511" />
+   <id start="03316000" end="03316511" />
+   <id start="03314000" end="03314511" />
+   <id start="03312000" end="03312511" />
+   <id start="03310000" end="03310511" />
+   <id start="03308000" end="03308511" />
+   <id start="03306000" end="03306511" />
+   <id start="03304000" end="03304511" />
+   <id start="03302000" end="03302511" />
+   <id start="03300000" end="03300511" />
+   <id start="03222000" end="03222511" />
+   <id start="03220000" end="03220511" />
+   <id start="03218000" end="03218511" />
+   <id start="03216000" end="03216511" />
+   <id start="03214000" end="03214511" />
+   <id start="03212000" end="03212511" />
+   <id start="03210000" end="03210511" />
+   <id start="03208000" end="03208511" />
+   <id start="03206000" end="03206511" />
+   <id start="03204000" end="03204511" />
+   <id start="03202000" end="03202511" />
+   <id start="03200000" end="03200511" />
+   <id start="03122000" end="03122511" />
+   <id start="03120000" end="03120511" />
+   <id start="03118000" end="03118511" />
+   <id start="03116000" end="03116511" />
+   <id start="03114000" end="03114511" />
+   <id start="03112000" end="03112511" />
+   <id start="03110000" end="03110511" />
+   <id start="03108000" end="03108511" />
+   <id start="03106000" end="03106511" />
+   <id start="03104000" end="03104511" />
+   <id start="03102000" end="03102511" />
+   <id start="03100000" end="03100511" />
+   </idlist>
+  <idlist idname="panel04">
+   <id start="04707000" end="04707511" />
+   <id start="04705000" end="04705511" />
+   <id start="04703000" end="04703511" />
+   <id start="04701000" end="04701511" />
+   <id start="04623000" end="04623511" />
+   <id start="04621000" end="04621511" />
+   <id start="04619000" end="04619511" />
+   <id start="04617000" end="04617511" />
+   <id start="04615000" end="04615511" />
+   <id start="04613000" end="04613511" />
+   <id start="04611000" end="04611511" />
+   <id start="04609000" end="04609511" />
+   <id start="04607000" end="04607511" />
+   <id start="04605000" end="04605511" />
+   <id start="04603000" end="04603511" />
+   <id start="04601000" end="04601511" />
+   <id start="04523000" end="04523511" />
+   <id start="04521000" end="04521511" />
+   <id start="04519000" end="04519511" />
+   <id start="04517000" end="04517511" />
+   <id start="04515000" end="04515511" />
+   <id start="04513000" end="04513511" />
+   <id start="04511000" end="04511511" />
+   <id start="04509000" end="04509511" />
+   <id start="04507000" end="04507511" />
+   <id start="04505000" end="04505511" />
+   <id start="04503000" end="04503511" />
+   <id start="04501000" end="04501511" />
+   <id start="04423000" end="04423511" />
+   <id start="04421000" end="04421511" />
+   <id start="04419000" end="04419511" />
+   <id start="04417000" end="04417511" />
+   <id start="04415000" end="04415511" />
+   <id start="04413000" end="04413511" />
+   <id start="04411000" end="04411511" />
+   <id start="04409000" end="04409511" />
+   <id start="04407000" end="04407511" />
+   <id start="04405000" end="04405511" />
+   <id start="04403000" end="04403511" />
+   <id start="04401000" end="04401511" />
+   <id start="04323000" end="04323511" />
+   <id start="04321000" end="04321511" />
+   <id start="04319000" end="04319511" />
+   <id start="04317000" end="04317511" />
+   <id start="04315000" end="04315511" />
+   <id start="04313000" end="04313511" />
+   <id start="04311000" end="04311511" />
+   <id start="04309000" end="04309511" />
+   <id start="04307000" end="04307511" />
+   <id start="04305000" end="04305511" />
+   <id start="04303000" end="04303511" />
+   <id start="04301000" end="04301511" />
+   <id start="04223000" end="04223511" />
+   <id start="04221000" end="04221511" />
+   <id start="04219000" end="04219511" />
+   <id start="04217000" end="04217511" />
+   <id start="04215000" end="04215511" />
+   <id start="04213000" end="04213511" />
+   <id start="04211000" end="04211511" />
+   <id start="04209000" end="04209511" />
+   <id start="04207000" end="04207511" />
+   <id start="04205000" end="04205511" />
+   <id start="04203000" end="04203511" />
+   <id start="04201000" end="04201511" />
+   <id start="04123000" end="04123511" />
+   <id start="04121000" end="04121511" />
+   <id start="04119000" end="04119511" />
+   <id start="04117000" end="04117511" />
+   <id start="04115000" end="04115511" />
+   <id start="04113000" end="04113511" />
+   <id start="04111000" end="04111511" />
+   <id start="04109000" end="04109511" />
+   <id start="04107000" end="04107511" />
+   <id start="04105000" end="04105511" />
+   <id start="04103000" end="04103511" />
+   <id start="04101000" end="04101511" />
+   <id start="04706000" end="04706511" />
+   <id start="04704000" end="04704511" />
+   <id start="04702000" end="04702511" />
+   <id start="04700000" end="04700511" />
+   <id start="04622000" end="04622511" />
+   <id start="04620000" end="04620511" />
+   <id start="04618000" end="04618511" />
+   <id start="04616000" end="04616511" />
+   <id start="04614000" end="04614511" />
+   <id start="04612000" end="04612511" />
+   <id start="04610000" end="04610511" />
+   <id start="04608000" end="04608511" />
+   <id start="04606000" end="04606511" />
+   <id start="04604000" end="04604511" />
+   <id start="04602000" end="04602511" />
+   <id start="04600000" end="04600511" />
+   <id start="04522000" end="04522511" />
+   <id start="04520000" end="04520511" />
+   <id start="04518000" end="04518511" />
+   <id start="04516000" end="04516511" />
+   <id start="04514000" end="04514511" />
+   <id start="04512000" end="04512511" />
+   <id start="04510000" end="04510511" />
+   <id start="04508000" end="04508511" />
+   <id start="04506000" end="04506511" />
+   <id start="04504000" end="04504511" />
+   <id start="04502000" end="04502511" />
+   <id start="04500000" end="04500511" />
+   <id start="04422000" end="04422511" />
+   <id start="04420000" end="04420511" />
+   <id start="04418000" end="04418511" />
+   <id start="04416000" end="04416511" />
+   <id start="04414000" end="04414511" />
+   <id start="04412000" end="04412511" />
+   <id start="04410000" end="04410511" />
+   <id start="04408000" end="04408511" />
+   <id start="04406000" end="04406511" />
+   <id start="04404000" end="04404511" />
+   <id start="04402000" end="04402511" />
+   <id start="04400000" end="04400511" />
+   <id start="04322000" end="04322511" />
+   <id start="04320000" end="04320511" />
+   <id start="04318000" end="04318511" />
+   <id start="04316000" end="04316511" />
+   <id start="04314000" end="04314511" />
+   <id start="04312000" end="04312511" />
+   <id start="04310000" end="04310511" />
+   <id start="04308000" end="04308511" />
+   <id start="04306000" end="04306511" />
+   <id start="04304000" end="04304511" />
+   <id start="04302000" end="04302511" />
+   <id start="04300000" end="04300511" />
+   <id start="04222000" end="04222511" />
+   <id start="04220000" end="04220511" />
+   <id start="04218000" end="04218511" />
+   <id start="04216000" end="04216511" />
+   <id start="04214000" end="04214511" />
+   <id start="04212000" end="04212511" />
+   <id start="04210000" end="04210511" />
+   <id start="04208000" end="04208511" />
+   <id start="04206000" end="04206511" />
+   <id start="04204000" end="04204511" />
+   <id start="04202000" end="04202511" />
+   <id start="04200000" end="04200511" />
+   <id start="04122000" end="04122511" />
+   <id start="04120000" end="04120511" />
+   <id start="04118000" end="04118511" />
+   <id start="04116000" end="04116511" />
+   <id start="04114000" end="04114511" />
+   <id start="04112000" end="04112511" />
+   <id start="04110000" end="04110511" />
+   <id start="04108000" end="04108511" />
+   <id start="04106000" end="04106511" />
+   <id start="04104000" end="04104511" />
+   <id start="04102000" end="04102511" />
+   <id start="04100000" end="04100511" />
+   </idlist>
+  <idlist idname="panel05">
+   <id start="05707000" end="05707511" />
+   <id start="05705000" end="05705511" />
+   <id start="05703000" end="05703511" />
+   <id start="05701000" end="05701511" />
+   <id start="05623000" end="05623511" />
+   <id start="05621000" end="05621511" />
+   <id start="05619000" end="05619511" />
+   <id start="05617000" end="05617511" />
+   <id start="05615000" end="05615511" />
+   <id start="05613000" end="05613511" />
+   <id start="05611000" end="05611511" />
+   <id start="05609000" end="05609511" />
+   <id start="05607000" end="05607511" />
+   <id start="05605000" end="05605511" />
+   <id start="05603000" end="05603511" />
+   <id start="05601000" end="05601511" />
+   <id start="05523000" end="05523511" />
+   <id start="05521000" end="05521511" />
+   <id start="05519000" end="05519511" />
+   <id start="05517000" end="05517511" />
+   <id start="05515000" end="05515511" />
+   <id start="05513000" end="05513511" />
+   <id start="05511000" end="05511511" />
+   <id start="05509000" end="05509511" />
+   <id start="05507000" end="05507511" />
+   <id start="05505000" end="05505511" />
+   <id start="05503000" end="05503511" />
+   <id start="05501000" end="05501511" />
+   <id start="05423000" end="05423511" />
+   <id start="05421000" end="05421511" />
+   <id start="05419000" end="05419511" />
+   <id start="05417000" end="05417511" />
+   <id start="05415000" end="05415511" />
+   <id start="05413000" end="05413511" />
+   <id start="05411000" end="05411511" />
+   <id start="05409000" end="05409511" />
+   <id start="05407000" end="05407511" />
+   <id start="05405000" end="05405511" />
+   <id start="05403000" end="05403511" />
+   <id start="05401000" end="05401511" />
+   <id start="05323000" end="05323511" />
+   <id start="05321000" end="05321511" />
+   <id start="05319000" end="05319511" />
+   <id start="05317000" end="05317511" />
+   <id start="05315000" end="05315511" />
+   <id start="05313000" end="05313511" />
+   <id start="05311000" end="05311511" />
+   <id start="05309000" end="05309511" />
+   <id start="05307000" end="05307511" />
+   <id start="05305000" end="05305511" />
+   <id start="05303000" end="05303511" />
+   <id start="05301000" end="05301511" />
+   <id start="05223000" end="05223511" />
+   <id start="05221000" end="05221511" />
+   <id start="05219000" end="05219511" />
+   <id start="05217000" end="05217511" />
+   <id start="05215000" end="05215511" />
+   <id start="05213000" end="05213511" />
+   <id start="05211000" end="05211511" />
+   <id start="05209000" end="05209511" />
+   <id start="05207000" end="05207511" />
+   <id start="05205000" end="05205511" />
+   <id start="05203000" end="05203511" />
+   <id start="05201000" end="05201511" />
+   <id start="05123000" end="05123511" />
+   <id start="05121000" end="05121511" />
+   <id start="05119000" end="05119511" />
+   <id start="05117000" end="05117511" />
+   <id start="05115000" end="05115511" />
+   <id start="05113000" end="05113511" />
+   <id start="05111000" end="05111511" />
+   <id start="05109000" end="05109511" />
+   <id start="05107000" end="05107511" />
+   <id start="05105000" end="05105511" />
+   <id start="05103000" end="05103511" />
+   <id start="05101000" end="05101511" />
+   <id start="05706000" end="05706511" />
+   <id start="05704000" end="05704511" />
+   <id start="05702000" end="05702511" />
+   <id start="05700000" end="05700511" />
+   <id start="05622000" end="05622511" />
+   <id start="05620000" end="05620511" />
+   <id start="05618000" end="05618511" />
+   <id start="05616000" end="05616511" />
+   <id start="05614000" end="05614511" />
+   <id start="05612000" end="05612511" />
+   <id start="05610000" end="05610511" />
+   <id start="05608000" end="05608511" />
+   <id start="05606000" end="05606511" />
+   <id start="05604000" end="05604511" />
+   <id start="05602000" end="05602511" />
+   <id start="05600000" end="05600511" />
+   <id start="05522000" end="05522511" />
+   <id start="05520000" end="05520511" />
+   <id start="05518000" end="05518511" />
+   <id start="05516000" end="05516511" />
+   <id start="05514000" end="05514511" />
+   <id start="05512000" end="05512511" />
+   <id start="05510000" end="05510511" />
+   <id start="05508000" end="05508511" />
+   <id start="05506000" end="05506511" />
+   <id start="05504000" end="05504511" />
+   <id start="05502000" end="05502511" />
+   <id start="05500000" end="05500511" />
+   <id start="05422000" end="05422511" />
+   <id start="05420000" end="05420511" />
+   <id start="05418000" end="05418511" />
+   <id start="05416000" end="05416511" />
+   <id start="05414000" end="05414511" />
+   <id start="05412000" end="05412511" />
+   <id start="05410000" end="05410511" />
+   <id start="05408000" end="05408511" />
+   <id start="05406000" end="05406511" />
+   <id start="05404000" end="05404511" />
+   <id start="05402000" end="05402511" />
+   <id start="05400000" end="05400511" />
+   <id start="05322000" end="05322511" />
+   <id start="05320000" end="05320511" />
+   <id start="05318000" end="05318511" />
+   <id start="05316000" end="05316511" />
+   <id start="05314000" end="05314511" />
+   <id start="05312000" end="05312511" />
+   <id start="05310000" end="05310511" />
+   <id start="05308000" end="05308511" />
+   <id start="05306000" end="05306511" />
+   <id start="05304000" end="05304511" />
+   <id start="05302000" end="05302511" />
+   <id start="05300000" end="05300511" />
+   <id start="05222000" end="05222511" />
+   <id start="05220000" end="05220511" />
+   <id start="05218000" end="05218511" />
+   <id start="05216000" end="05216511" />
+   <id start="05214000" end="05214511" />
+   <id start="05212000" end="05212511" />
+   <id start="05210000" end="05210511" />
+   <id start="05208000" end="05208511" />
+   <id start="05206000" end="05206511" />
+   <id start="05204000" end="05204511" />
+   <id start="05202000" end="05202511" />
+   <id start="05200000" end="05200511" />
+   <id start="05122000" end="05122511" />
+   <id start="05120000" end="05120511" />
+   <id start="05118000" end="05118511" />
+   <id start="05116000" end="05116511" />
+   <id start="05114000" end="05114511" />
+   <id start="05112000" end="05112511" />
+   <id start="05110000" end="05110511" />
+   <id start="05108000" end="05108511" />
+   <id start="05106000" end="05106511" />
+   <id start="05104000" end="05104511" />
+   <id start="05102000" end="05102511" />
+   <id start="05100000" end="05100511" />
+   </idlist>
+  <idlist idname="panel10">
+   <id start="10707000" end="10707511" />
+   <id start="10705000" end="10705511" />
+   <id start="10703000" end="10703511" />
+   <id start="10701000" end="10701511" />
+   <id start="10623000" end="10623511" />
+   <id start="10621000" end="10621511" />
+   <id start="10619000" end="10619511" />
+   <id start="10617000" end="10617511" />
+   <id start="10615000" end="10615511" />
+   <id start="10613000" end="10613511" />
+   <id start="10611000" end="10611511" />
+   <id start="10609000" end="10609511" />
+   <id start="10607000" end="10607511" />
+   <id start="10605000" end="10605511" />
+   <id start="10603000" end="10603511" />
+   <id start="10601000" end="10601511" />
+   <id start="10523000" end="10523511" />
+   <id start="10521000" end="10521511" />
+   <id start="10519000" end="10519511" />
+   <id start="10517000" end="10517511" />
+   <id start="10515000" end="10515511" />
+   <id start="10513000" end="10513511" />
+   <id start="10511000" end="10511511" />
+   <id start="10509000" end="10509511" />
+   <id start="10507000" end="10507511" />
+   <id start="10505000" end="10505511" />
+   <id start="10503000" end="10503511" />
+   <id start="10501000" end="10501511" />
+   <id start="10423000" end="10423511" />
+   <id start="10421000" end="10421511" />
+   <id start="10419000" end="10419511" />
+   <id start="10417000" end="10417511" />
+   <id start="10415000" end="10415511" />
+   <id start="10413000" end="10413511" />
+   <id start="10411000" end="10411511" />
+   <id start="10409000" end="10409511" />
+   <id start="10407000" end="10407511" />
+   <id start="10405000" end="10405511" />
+   <id start="10403000" end="10403511" />
+   <id start="10401000" end="10401511" />
+   <id start="10323000" end="10323511" />
+   <id start="10321000" end="10321511" />
+   <id start="10319000" end="10319511" />
+   <id start="10317000" end="10317511" />
+   <id start="10315000" end="10315511" />
+   <id start="10313000" end="10313511" />
+   <id start="10311000" end="10311511" />
+   <id start="10309000" end="10309511" />
+   <id start="10307000" end="10307511" />
+   <id start="10305000" end="10305511" />
+   <id start="10303000" end="10303511" />
+   <id start="10301000" end="10301511" />
+   <id start="10223000" end="10223511" />
+   <id start="10221000" end="10221511" />
+   <id start="10219000" end="10219511" />
+   <id start="10217000" end="10217511" />
+   <id start="10215000" end="10215511" />
+   <id start="10213000" end="10213511" />
+   <id start="10211000" end="10211511" />
+   <id start="10209000" end="10209511" />
+   <id start="10207000" end="10207511" />
+   <id start="10205000" end="10205511" />
+   <id start="10203000" end="10203511" />
+   <id start="10201000" end="10201511" />
+   <id start="10123000" end="10123511" />
+   <id start="10121000" end="10121511" />
+   <id start="10119000" end="10119511" />
+   <id start="10117000" end="10117511" />
+   <id start="10115000" end="10115511" />
+   <id start="10113000" end="10113511" />
+   <id start="10111000" end="10111511" />
+   <id start="10109000" end="10109511" />
+   <id start="10107000" end="10107511" />
+   <id start="10105000" end="10105511" />
+   <id start="10103000" end="10103511" />
+   <id start="10101000" end="10101511" />
+   <id start="10706000" end="10706511" />
+   <id start="10704000" end="10704511" />
+   <id start="10702000" end="10702511" />
+   <id start="10700000" end="10700511" />
+   <id start="10622000" end="10622511" />
+   <id start="10620000" end="10620511" />
+   <id start="10618000" end="10618511" />
+   <id start="10616000" end="10616511" />
+   <id start="10614000" end="10614511" />
+   <id start="10612000" end="10612511" />
+   <id start="10610000" end="10610511" />
+   <id start="10608000" end="10608511" />
+   <id start="10606000" end="10606511" />
+   <id start="10604000" end="10604511" />
+   <id start="10602000" end="10602511" />
+   <id start="10600000" end="10600511" />
+   <id start="10522000" end="10522511" />
+   <id start="10520000" end="10520511" />
+   <id start="10518000" end="10518511" />
+   <id start="10516000" end="10516511" />
+   <id start="10514000" end="10514511" />
+   <id start="10512000" end="10512511" />
+   <id start="10510000" end="10510511" />
+   <id start="10508000" end="10508511" />
+   <id start="10506000" end="10506511" />
+   <id start="10504000" end="10504511" />
+   <id start="10502000" end="10502511" />
+   <id start="10500000" end="10500511" />
+   <id start="10422000" end="10422511" />
+   <id start="10420000" end="10420511" />
+   <id start="10418000" end="10418511" />
+   <id start="10416000" end="10416511" />
+   <id start="10414000" end="10414511" />
+   <id start="10412000" end="10412511" />
+   <id start="10410000" end="10410511" />
+   <id start="10408000" end="10408511" />
+   <id start="10406000" end="10406511" />
+   <id start="10404000" end="10404511" />
+   <id start="10402000" end="10402511" />
+   <id start="10400000" end="10400511" />
+   <id start="10322000" end="10322511" />
+   <id start="10320000" end="10320511" />
+   <id start="10318000" end="10318511" />
+   <id start="10316000" end="10316511" />
+   <id start="10314000" end="10314511" />
+   <id start="10312000" end="10312511" />
+   <id start="10310000" end="10310511" />
+   <id start="10308000" end="10308511" />
+   <id start="10306000" end="10306511" />
+   <id start="10304000" end="10304511" />
+   <id start="10302000" end="10302511" />
+   <id start="10300000" end="10300511" />
+   <id start="10222000" end="10222511" />
+   <id start="10220000" end="10220511" />
+   <id start="10218000" end="10218511" />
+   <id start="10216000" end="10216511" />
+   <id start="10214000" end="10214511" />
+   <id start="10212000" end="10212511" />
+   <id start="10210000" end="10210511" />
+   <id start="10208000" end="10208511" />
+   <id start="10206000" end="10206511" />
+   <id start="10204000" end="10204511" />
+   <id start="10202000" end="10202511" />
+   <id start="10200000" end="10200511" />
+   <id start="10122000" end="10122511" />
+   <id start="10120000" end="10120511" />
+   <id start="10118000" end="10118511" />
+   <id start="10116000" end="10116511" />
+   <id start="10114000" end="10114511" />
+   <id start="10112000" end="10112511" />
+   <id start="10110000" end="10110511" />
+   <id start="10108000" end="10108511" />
+   <id start="10106000" end="10106511" />
+   <id start="10104000" end="10104511" />
+   <id start="10102000" end="10102511" />
+   <id start="10100000" end="10100511" />
+   </idlist>
+  <idlist idname="panel09">
+   <id start="09707000" end="09707511" />
+   <id start="09705000" end="09705511" />
+   <id start="09703000" end="09703511" />
+   <id start="09701000" end="09701511" />
+   <id start="09623000" end="09623511" />
+   <id start="09621000" end="09621511" />
+   <id start="09619000" end="09619511" />
+   <id start="09617000" end="09617511" />
+   <id start="09615000" end="09615511" />
+   <id start="09613000" end="09613511" />
+   <id start="09611000" end="09611511" />
+   <id start="09609000" end="09609511" />
+   <id start="09607000" end="09607511" />
+   <id start="09605000" end="09605511" />
+   <id start="09603000" end="09603511" />
+   <id start="09601000" end="09601511" />
+   <id start="09523000" end="09523511" />
+   <id start="09521000" end="09521511" />
+   <id start="09519000" end="09519511" />
+   <id start="09517000" end="09517511" />
+   <id start="09515000" end="09515511" />
+   <id start="09513000" end="09513511" />
+   <id start="09511000" end="09511511" />
+   <id start="09509000" end="09509511" />
+   <id start="09507000" end="09507511" />
+   <id start="09505000" end="09505511" />
+   <id start="09503000" end="09503511" />
+   <id start="09501000" end="09501511" />
+   <id start="09423000" end="09423511" />
+   <id start="09421000" end="09421511" />
+   <id start="09419000" end="09419511" />
+   <id start="09417000" end="09417511" />
+   <id start="09415000" end="09415511" />
+   <id start="09413000" end="09413511" />
+   <id start="09411000" end="09411511" />
+   <id start="09409000" end="09409511" />
+   <id start="09407000" end="09407511" />
+   <id start="09405000" end="09405511" />
+   <id start="09403000" end="09403511" />
+   <id start="09401000" end="09401511" />
+   <id start="09323000" end="09323511" />
+   <id start="09321000" end="09321511" />
+   <id start="09319000" end="09319511" />
+   <id start="09317000" end="09317511" />
+   <id start="09315000" end="09315511" />
+   <id start="09313000" end="09313511" />
+   <id start="09311000" end="09311511" />
+   <id start="09309000" end="09309511" />
+   <id start="09307000" end="09307511" />
+   <id start="09305000" end="09305511" />
+   <id start="09303000" end="09303511" />
+   <id start="09301000" end="09301511" />
+   <id start="09223000" end="09223511" />
+   <id start="09221000" end="09221511" />
+   <id start="09219000" end="09219511" />
+   <id start="09217000" end="09217511" />
+   <id start="09215000" end="09215511" />
+   <id start="09213000" end="09213511" />
+   <id start="09211000" end="09211511" />
+   <id start="09209000" end="09209511" />
+   <id start="09207000" end="09207511" />
+   <id start="09205000" end="09205511" />
+   <id start="09203000" end="09203511" />
+   <id start="09201000" end="09201511" />
+   <id start="09123000" end="09123511" />
+   <id start="09121000" end="09121511" />
+   <id start="09119000" end="09119511" />
+   <id start="09117000" end="09117511" />
+   <id start="09115000" end="09115511" />
+   <id start="09113000" end="09113511" />
+   <id start="09111000" end="09111511" />
+   <id start="09109000" end="09109511" />
+   <id start="09107000" end="09107511" />
+   <id start="09105000" end="09105511" />
+   <id start="09103000" end="09103511" />
+   <id start="09101000" end="09101511" />
+   <id start="09706000" end="09706511" />
+   <id start="09704000" end="09704511" />
+   <id start="09702000" end="09702511" />
+   <id start="09700000" end="09700511" />
+   <id start="09622000" end="09622511" />
+   <id start="09620000" end="09620511" />
+   <id start="09618000" end="09618511" />
+   <id start="09616000" end="09616511" />
+   <id start="09614000" end="09614511" />
+   <id start="09612000" end="09612511" />
+   <id start="09610000" end="09610511" />
+   <id start="09608000" end="09608511" />
+   <id start="09606000" end="09606511" />
+   <id start="09604000" end="09604511" />
+   <id start="09602000" end="09602511" />
+   <id start="09600000" end="09600511" />
+   <id start="09522000" end="09522511" />
+   <id start="09520000" end="09520511" />
+   <id start="09518000" end="09518511" />
+   <id start="09516000" end="09516511" />
+   <id start="09514000" end="09514511" />
+   <id start="09512000" end="09512511" />
+   <id start="09510000" end="09510511" />
+   <id start="09508000" end="09508511" />
+   <id start="09506000" end="09506511" />
+   <id start="09504000" end="09504511" />
+   <id start="09502000" end="09502511" />
+   <id start="09500000" end="09500511" />
+   <id start="09422000" end="09422511" />
+   <id start="09420000" end="09420511" />
+   <id start="09418000" end="09418511" />
+   <id start="09416000" end="09416511" />
+   <id start="09414000" end="09414511" />
+   <id start="09412000" end="09412511" />
+   <id start="09410000" end="09410511" />
+   <id start="09408000" end="09408511" />
+   <id start="09406000" end="09406511" />
+   <id start="09404000" end="09404511" />
+   <id start="09402000" end="09402511" />
+   <id start="09400000" end="09400511" />
+   <id start="09322000" end="09322511" />
+   <id start="09320000" end="09320511" />
+   <id start="09318000" end="09318511" />
+   <id start="09316000" end="09316511" />
+   <id start="09314000" end="09314511" />
+   <id start="09312000" end="09312511" />
+   <id start="09310000" end="09310511" />
+   <id start="09308000" end="09308511" />
+   <id start="09306000" end="09306511" />
+   <id start="09304000" end="09304511" />
+   <id start="09302000" end="09302511" />
+   <id start="09300000" end="09300511" />
+   <id start="09222000" end="09222511" />
+   <id start="09220000" end="09220511" />
+   <id start="09218000" end="09218511" />
+   <id start="09216000" end="09216511" />
+   <id start="09214000" end="09214511" />
+   <id start="09212000" end="09212511" />
+   <id start="09210000" end="09210511" />
+   <id start="09208000" end="09208511" />
+   <id start="09206000" end="09206511" />
+   <id start="09204000" end="09204511" />
+   <id start="09202000" end="09202511" />
+   <id start="09200000" end="09200511" />
+   <id start="09122000" end="09122511" />
+   <id start="09120000" end="09120511" />
+   <id start="09118000" end="09118511" />
+   <id start="09116000" end="09116511" />
+   <id start="09114000" end="09114511" />
+   <id start="09112000" end="09112511" />
+   <id start="09110000" end="09110511" />
+   <id start="09108000" end="09108511" />
+   <id start="09106000" end="09106511" />
+   <id start="09104000" end="09104511" />
+   <id start="09102000" end="09102511" />
+   <id start="09100000" end="09100511" />
+   </idlist>
+  <idlist idname="panel08">
+   <id start="08707000" end="08707511" />
+   <id start="08705000" end="08705511" />
+   <id start="08703000" end="08703511" />
+   <id start="08701000" end="08701511" />
+   <id start="08623000" end="08623511" />
+   <id start="08621000" end="08621511" />
+   <id start="08619000" end="08619511" />
+   <id start="08617000" end="08617511" />
+   <id start="08615000" end="08615511" />
+   <id start="08613000" end="08613511" />
+   <id start="08611000" end="08611511" />
+   <id start="08609000" end="08609511" />
+   <id start="08607000" end="08607511" />
+   <id start="08605000" end="08605511" />
+   <id start="08603000" end="08603511" />
+   <id start="08601000" end="08601511" />
+   <id start="08523000" end="08523511" />
+   <id start="08521000" end="08521511" />
+   <id start="08519000" end="08519511" />
+   <id start="08517000" end="08517511" />
+   <id start="08515000" end="08515511" />
+   <id start="08513000" end="08513511" />
+   <id start="08511000" end="08511511" />
+   <id start="08509000" end="08509511" />
+   <id start="08507000" end="08507511" />
+   <id start="08505000" end="08505511" />
+   <id start="08503000" end="08503511" />
+   <id start="08501000" end="08501511" />
+   <id start="08423000" end="08423511" />
+   <id start="08421000" end="08421511" />
+   <id start="08419000" end="08419511" />
+   <id start="08417000" end="08417511" />
+   <id start="08415000" end="08415511" />
+   <id start="08413000" end="08413511" />
+   <id start="08411000" end="08411511" />
+   <id start="08409000" end="08409511" />
+   <id start="08407000" end="08407511" />
+   <id start="08405000" end="08405511" />
+   <id start="08403000" end="08403511" />
+   <id start="08401000" end="08401511" />
+   <id start="08323000" end="08323511" />
+   <id start="08321000" end="08321511" />
+   <id start="08319000" end="08319511" />
+   <id start="08317000" end="08317511" />
+   <id start="08315000" end="08315511" />
+   <id start="08313000" end="08313511" />
+   <id start="08311000" end="08311511" />
+   <id start="08309000" end="08309511" />
+   <id start="08307000" end="08307511" />
+   <id start="08305000" end="08305511" />
+   <id start="08303000" end="08303511" />
+   <id start="08301000" end="08301511" />
+   <id start="08223000" end="08223511" />
+   <id start="08221000" end="08221511" />
+   <id start="08219000" end="08219511" />
+   <id start="08217000" end="08217511" />
+   <id start="08215000" end="08215511" />
+   <id start="08213000" end="08213511" />
+   <id start="08211000" end="08211511" />
+   <id start="08209000" end="08209511" />
+   <id start="08207000" end="08207511" />
+   <id start="08205000" end="08205511" />
+   <id start="08203000" end="08203511" />
+   <id start="08201000" end="08201511" />
+   <id start="08123000" end="08123511" />
+   <id start="08121000" end="08121511" />
+   <id start="08119000" end="08119511" />
+   <id start="08117000" end="08117511" />
+   <id start="08115000" end="08115511" />
+   <id start="08113000" end="08113511" />
+   <id start="08111000" end="08111511" />
+   <id start="08109000" end="08109511" />
+   <id start="08107000" end="08107511" />
+   <id start="08105000" end="08105511" />
+   <id start="08103000" end="08103511" />
+   <id start="08101000" end="08101511" />
+   <id start="08706000" end="08706511" />
+   <id start="08704000" end="08704511" />
+   <id start="08702000" end="08702511" />
+   <id start="08700000" end="08700511" />
+   <id start="08622000" end="08622511" />
+   <id start="08620000" end="08620511" />
+   <id start="08618000" end="08618511" />
+   <id start="08616000" end="08616511" />
+   <id start="08614000" end="08614511" />
+   <id start="08612000" end="08612511" />
+   <id start="08610000" end="08610511" />
+   <id start="08608000" end="08608511" />
+   <id start="08606000" end="08606511" />
+   <id start="08604000" end="08604511" />
+   <id start="08602000" end="08602511" />
+   <id start="08600000" end="08600511" />
+   <id start="08522000" end="08522511" />
+   <id start="08520000" end="08520511" />
+   <id start="08518000" end="08518511" />
+   <id start="08516000" end="08516511" />
+   <id start="08514000" end="08514511" />
+   <id start="08512000" end="08512511" />
+   <id start="08510000" end="08510511" />
+   <id start="08508000" end="08508511" />
+   <id start="08506000" end="08506511" />
+   <id start="08504000" end="08504511" />
+   <id start="08502000" end="08502511" />
+   <id start="08500000" end="08500511" />
+   <id start="08422000" end="08422511" />
+   <id start="08420000" end="08420511" />
+   <id start="08418000" end="08418511" />
+   <id start="08416000" end="08416511" />
+   <id start="08414000" end="08414511" />
+   <id start="08412000" end="08412511" />
+   <id start="08410000" end="08410511" />
+   <id start="08408000" end="08408511" />
+   <id start="08406000" end="08406511" />
+   <id start="08404000" end="08404511" />
+   <id start="08402000" end="08402511" />
+   <id start="08400000" end="08400511" />
+   <id start="08322000" end="08322511" />
+   <id start="08320000" end="08320511" />
+   <id start="08318000" end="08318511" />
+   <id start="08316000" end="08316511" />
+   <id start="08314000" end="08314511" />
+   <id start="08312000" end="08312511" />
+   <id start="08310000" end="08310511" />
+   <id start="08308000" end="08308511" />
+   <id start="08306000" end="08306511" />
+   <id start="08304000" end="08304511" />
+   <id start="08302000" end="08302511" />
+   <id start="08300000" end="08300511" />
+   <id start="08222000" end="08222511" />
+   <id start="08220000" end="08220511" />
+   <id start="08218000" end="08218511" />
+   <id start="08216000" end="08216511" />
+   <id start="08214000" end="08214511" />
+   <id start="08212000" end="08212511" />
+   <id start="08210000" end="08210511" />
+   <id start="08208000" end="08208511" />
+   <id start="08206000" end="08206511" />
+   <id start="08204000" end="08204511" />
+   <id start="08202000" end="08202511" />
+   <id start="08200000" end="08200511" />
+   <id start="08122000" end="08122511" />
+   <id start="08120000" end="08120511" />
+   <id start="08118000" end="08118511" />
+   <id start="08116000" end="08116511" />
+   <id start="08114000" end="08114511" />
+   <id start="08112000" end="08112511" />
+   <id start="08110000" end="08110511" />
+   <id start="08108000" end="08108511" />
+   <id start="08106000" end="08106511" />
+   <id start="08104000" end="08104511" />
+   <id start="08102000" end="08102511" />
+   <id start="08100000" end="08100511" />
+   </idlist>
+  <idlist idname="panel07">
+   <id start="07707000" end="07707511" />
+   <id start="07705000" end="07705511" />
+   <id start="07703000" end="07703511" />
+   <id start="07701000" end="07701511" />
+   <id start="07623000" end="07623511" />
+   <id start="07621000" end="07621511" />
+   <id start="07619000" end="07619511" />
+   <id start="07617000" end="07617511" />
+   <id start="07615000" end="07615511" />
+   <id start="07613000" end="07613511" />
+   <id start="07611000" end="07611511" />
+   <id start="07609000" end="07609511" />
+   <id start="07607000" end="07607511" />
+   <id start="07605000" end="07605511" />
+   <id start="07603000" end="07603511" />
+   <id start="07601000" end="07601511" />
+   <id start="07523000" end="07523511" />
+   <id start="07521000" end="07521511" />
+   <id start="07519000" end="07519511" />
+   <id start="07517000" end="07517511" />
+   <id start="07515000" end="07515511" />
+   <id start="07513000" end="07513511" />
+   <id start="07511000" end="07511511" />
+   <id start="07509000" end="07509511" />
+   <id start="07507000" end="07507511" />
+   <id start="07505000" end="07505511" />
+   <id start="07503000" end="07503511" />
+   <id start="07501000" end="07501511" />
+   <id start="07423000" end="07423511" />
+   <id start="07421000" end="07421511" />
+   <id start="07419000" end="07419511" />
+   <id start="07417000" end="07417511" />
+   <id start="07415000" end="07415511" />
+   <id start="07413000" end="07413511" />
+   <id start="07411000" end="07411511" />
+   <id start="07409000" end="07409511" />
+   <id start="07407000" end="07407511" />
+   <id start="07405000" end="07405511" />
+   <id start="07403000" end="07403511" />
+   <id start="07401000" end="07401511" />
+   <id start="07323000" end="07323511" />
+   <id start="07321000" end="07321511" />
+   <id start="07319000" end="07319511" />
+   <id start="07317000" end="07317511" />
+   <id start="07315000" end="07315511" />
+   <id start="07313000" end="07313511" />
+   <id start="07311000" end="07311511" />
+   <id start="07309000" end="07309511" />
+   <id start="07307000" end="07307511" />
+   <id start="07305000" end="07305511" />
+   <id start="07303000" end="07303511" />
+   <id start="07301000" end="07301511" />
+   <id start="07223000" end="07223511" />
+   <id start="07221000" end="07221511" />
+   <id start="07219000" end="07219511" />
+   <id start="07217000" end="07217511" />
+   <id start="07215000" end="07215511" />
+   <id start="07213000" end="07213511" />
+   <id start="07211000" end="07211511" />
+   <id start="07209000" end="07209511" />
+   <id start="07207000" end="07207511" />
+   <id start="07205000" end="07205511" />
+   <id start="07203000" end="07203511" />
+   <id start="07201000" end="07201511" />
+   <id start="07123000" end="07123511" />
+   <id start="07121000" end="07121511" />
+   <id start="07119000" end="07119511" />
+   <id start="07117000" end="07117511" />
+   <id start="07115000" end="07115511" />
+   <id start="07113000" end="07113511" />
+   <id start="07111000" end="07111511" />
+   <id start="07109000" end="07109511" />
+   <id start="07107000" end="07107511" />
+   <id start="07105000" end="07105511" />
+   <id start="07103000" end="07103511" />
+   <id start="07101000" end="07101511" />
+   <id start="07706000" end="07706511" />
+   <id start="07704000" end="07704511" />
+   <id start="07702000" end="07702511" />
+   <id start="07700000" end="07700511" />
+   <id start="07622000" end="07622511" />
+   <id start="07620000" end="07620511" />
+   <id start="07618000" end="07618511" />
+   <id start="07616000" end="07616511" />
+   <id start="07614000" end="07614511" />
+   <id start="07612000" end="07612511" />
+   <id start="07610000" end="07610511" />
+   <id start="07608000" end="07608511" />
+   <id start="07606000" end="07606511" />
+   <id start="07604000" end="07604511" />
+   <id start="07602000" end="07602511" />
+   <id start="07600000" end="07600511" />
+   <id start="07522000" end="07522511" />
+   <id start="07520000" end="07520511" />
+   <id start="07518000" end="07518511" />
+   <id start="07516000" end="07516511" />
+   <id start="07514000" end="07514511" />
+   <id start="07512000" end="07512511" />
+   <id start="07510000" end="07510511" />
+   <id start="07508000" end="07508511" />
+   <id start="07506000" end="07506511" />
+   <id start="07504000" end="07504511" />
+   <id start="07502000" end="07502511" />
+   <id start="07500000" end="07500511" />
+   <id start="07422000" end="07422511" />
+   <id start="07420000" end="07420511" />
+   <id start="07418000" end="07418511" />
+   <id start="07416000" end="07416511" />
+   <id start="07414000" end="07414511" />
+   <id start="07412000" end="07412511" />
+   <id start="07410000" end="07410511" />
+   <id start="07408000" end="07408511" />
+   <id start="07406000" end="07406511" />
+   <id start="07404000" end="07404511" />
+   <id start="07402000" end="07402511" />
+   <id start="07400000" end="07400511" />
+   <id start="07322000" end="07322511" />
+   <id start="07320000" end="07320511" />
+   <id start="07318000" end="07318511" />
+   <id start="07316000" end="07316511" />
+   <id start="07314000" end="07314511" />
+   <id start="07312000" end="07312511" />
+   <id start="07310000" end="07310511" />
+   <id start="07308000" end="07308511" />
+   <id start="07306000" end="07306511" />
+   <id start="07304000" end="07304511" />
+   <id start="07302000" end="07302511" />
+   <id start="07300000" end="07300511" />
+   <id start="07222000" end="07222511" />
+   <id start="07220000" end="07220511" />
+   <id start="07218000" end="07218511" />
+   <id start="07216000" end="07216511" />
+   <id start="07214000" end="07214511" />
+   <id start="07212000" end="07212511" />
+   <id start="07210000" end="07210511" />
+   <id start="07208000" end="07208511" />
+   <id start="07206000" end="07206511" />
+   <id start="07204000" end="07204511" />
+   <id start="07202000" end="07202511" />
+   <id start="07200000" end="07200511" />
+   <id start="07122000" end="07122511" />
+   <id start="07120000" end="07120511" />
+   <id start="07118000" end="07118511" />
+   <id start="07116000" end="07116511" />
+   <id start="07114000" end="07114511" />
+   <id start="07112000" end="07112511" />
+   <id start="07110000" end="07110511" />
+   <id start="07108000" end="07108511" />
+   <id start="07106000" end="07106511" />
+   <id start="07104000" end="07104511" />
+   <id start="07102000" end="07102511" />
+   <id start="07100000" end="07100511" />
+   </idlist>  
+  <idlist idname="panel06">
+   <id start="06707000" end="06707511" />
+   <id start="06705000" end="06705511" />
+   <id start="06703000" end="06703511" />
+   <id start="06701000" end="06701511" />
+   <id start="06623000" end="06623511" />
+   <id start="06621000" end="06621511" />
+   <id start="06619000" end="06619511" />
+   <id start="06617000" end="06617511" />
+   <id start="06615000" end="06615511" />
+   <id start="06613000" end="06613511" />
+   <id start="06611000" end="06611511" />
+   <id start="06609000" end="06609511" />
+   <id start="06607000" end="06607511" />
+   <id start="06605000" end="06605511" />
+   <id start="06603000" end="06603511" />
+   <id start="06601000" end="06601511" />
+   <id start="06523000" end="06523511" />
+   <id start="06521000" end="06521511" />
+   <id start="06519000" end="06519511" />
+   <id start="06517000" end="06517511" />
+   <id start="06515000" end="06515511" />
+   <id start="06513000" end="06513511" />
+   <id start="06511000" end="06511511" />
+   <id start="06509000" end="06509511" />
+   <id start="06507000" end="06507511" />
+   <id start="06505000" end="06505511" />
+   <id start="06503000" end="06503511" />
+   <id start="06501000" end="06501511" />
+   <id start="06423000" end="06423511" />
+   <id start="06421000" end="06421511" />
+   <id start="06419000" end="06419511" />
+   <id start="06417000" end="06417511" />
+   <id start="06415000" end="06415511" />
+   <id start="06413000" end="06413511" />
+   <id start="06411000" end="06411511" />
+   <id start="06409000" end="06409511" />
+   <id start="06407000" end="06407511" />
+   <id start="06405000" end="06405511" />
+   <id start="06403000" end="06403511" />
+   <id start="06401000" end="06401511" />
+   <id start="06323000" end="06323511" />
+   <id start="06321000" end="06321511" />
+   <id start="06319000" end="06319511" />
+   <id start="06317000" end="06317511" />
+   <id start="06315000" end="06315511" />
+   <id start="06313000" end="06313511" />
+   <id start="06311000" end="06311511" />
+   <id start="06309000" end="06309511" />
+   <id start="06307000" end="06307511" />
+   <id start="06305000" end="06305511" />
+   <id start="06303000" end="06303511" />
+   <id start="06301000" end="06301511" />
+   <id start="06223000" end="06223511" />
+   <id start="06221000" end="06221511" />
+   <id start="06219000" end="06219511" />
+   <id start="06217000" end="06217511" />
+   <id start="06215000" end="06215511" />
+   <id start="06213000" end="06213511" />
+   <id start="06211000" end="06211511" />
+   <id start="06209000" end="06209511" />
+   <id start="06207000" end="06207511" />
+   <id start="06205000" end="06205511" />
+   <id start="06203000" end="06203511" />
+   <id start="06201000" end="06201511" />
+   <id start="06123000" end="06123511" />
+   <id start="06121000" end="06121511" />
+   <id start="06119000" end="06119511" />
+   <id start="06117000" end="06117511" />
+   <id start="06115000" end="06115511" />
+   <id start="06113000" end="06113511" />
+   <id start="06111000" end="06111511" />
+   <id start="06109000" end="06109511" />
+   <id start="06107000" end="06107511" />
+   <id start="06105000" end="06105511" />
+   <id start="06103000" end="06103511" />
+   <id start="06101000" end="06101511" />
+   <id start="06706000" end="06706511" />
+   <id start="06704000" end="06704511" />
+   <id start="06702000" end="06702511" />
+   <id start="06700000" end="06700511" />
+   <id start="06622000" end="06622511" />
+   <id start="06620000" end="06620511" />
+   <id start="06618000" end="06618511" />
+   <id start="06616000" end="06616511" />
+   <id start="06614000" end="06614511" />
+   <id start="06612000" end="06612511" />
+   <id start="06610000" end="06610511" />
+   <id start="06608000" end="06608511" />
+   <id start="06606000" end="06606511" />
+   <id start="06604000" end="06604511" />
+   <id start="06602000" end="06602511" />
+   <id start="06600000" end="06600511" />
+   <id start="06522000" end="06522511" />
+   <id start="06520000" end="06520511" />
+   <id start="06518000" end="06518511" />
+   <id start="06516000" end="06516511" />
+   <id start="06514000" end="06514511" />
+   <id start="06512000" end="06512511" />
+   <id start="06510000" end="06510511" />
+   <id start="06508000" end="06508511" />
+   <id start="06506000" end="06506511" />
+   <id start="06504000" end="06504511" />
+   <id start="06502000" end="06502511" />
+   <id start="06500000" end="06500511" />
+   <id start="06422000" end="06422511" />
+   <id start="06420000" end="06420511" />
+   <id start="06418000" end="06418511" />
+   <id start="06416000" end="06416511" />
+   <id start="06414000" end="06414511" />
+   <id start="06412000" end="06412511" />
+   <id start="06410000" end="06410511" />
+   <id start="06408000" end="06408511" />
+   <id start="06406000" end="06406511" />
+   <id start="06404000" end="06404511" />
+   <id start="06402000" end="06402511" />
+   <id start="06400000" end="06400511" />
+   <id start="06322000" end="06322511" />
+   <id start="06320000" end="06320511" />
+   <id start="06318000" end="06318511" />
+   <id start="06316000" end="06316511" />
+   <id start="06314000" end="06314511" />
+   <id start="06312000" end="06312511" />
+   <id start="06310000" end="06310511" />
+   <id start="06308000" end="06308511" />
+   <id start="06306000" end="06306511" />
+   <id start="06304000" end="06304511" />
+   <id start="06302000" end="06302511" />
+   <id start="06300000" end="06300511" />
+   <id start="06222000" end="06222511" />
+   <id start="06220000" end="06220511" />
+   <id start="06218000" end="06218511" />
+   <id start="06216000" end="06216511" />
+   <id start="06214000" end="06214511" />
+   <id start="06212000" end="06212511" />
+   <id start="06210000" end="06210511" />
+   <id start="06208000" end="06208511" />
+   <id start="06206000" end="06206511" />
+   <id start="06204000" end="06204511" />
+   <id start="06202000" end="06202511" />
+   <id start="06200000" end="06200511" />
+   <id start="06122000" end="06122511" />
+   <id start="06120000" end="06120511" />
+   <id start="06118000" end="06118511" />
+   <id start="06116000" end="06116511" />
+   <id start="06114000" end="06114511" />
+   <id start="06112000" end="06112511" />
+   <id start="06110000" end="06110511" />
+   <id start="06108000" end="06108511" />
+   <id start="06106000" end="06106511" />
+   <id start="06104000" end="06104511" />
+   <id start="06102000" end="06102511" />
+   <id start="06100000" end="06100511" />
+   </idlist>
+ </instrument>
diff --git a/Code/Mantid/instrument/WISH_Definition_6Panel.xml b/Code/Mantid/instrument/WISH_Definition_6Panel.xml
index f3feada532329d34933a993219f455d6a18db964..f84b2a19838d4324885eff3bdada412ac9d94d6d 100644
--- a/Code/Mantid/instrument/WISH_Definition_6Panel.xml
+++ b/Code/Mantid/instrument/WISH_Definition_6Panel.xml
@@ -2,7 +2,7 @@
 <!-- For help on the notation used to specify an Instrument Definition File 
      see http://www.mantidproject.org/IDF -->
 <instrument xmlns="http://www.mantidproject.org/IDF/1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.mantidproject.org/IDF/1.0 Schema/IDFSchema.xsd" 
- name="WISH" valid-from   ="2012-09-26 17:24:36"
+ name="WISH" valid-from   ="2012-10-21 17:24:36"
                         valid-to     ="2013-07-01 17:24:36"
 		        last-modified="2013-10-10 09:00:00">
  
diff --git a/Code/Mantid/instrument/WISH_Definition_9Panels.xml b/Code/Mantid/instrument/WISH_Definition_9Panels.xml
index 34d0748d696174be187631fad5f66e20b90b61da..6c2587283cc70ccc186fa67496acecb4ef11e7b5 100644
--- a/Code/Mantid/instrument/WISH_Definition_9Panels.xml
+++ b/Code/Mantid/instrument/WISH_Definition_9Panels.xml
@@ -3,7 +3,7 @@
      see http://www.mantidproject.org/IDF -->
 <instrument xmlns="http://www.mantidproject.org/IDF/1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.mantidproject.org/IDF/1.0 Schema/IDFSchema.xsd" 
  name="WISH" valid-from   ="2013-07-01 17:24:36"
-                        valid-to     ="2100-01-31 23:59:59"
+                        valid-to     ="2013-11-01 23:59:59"
 		        last-modified="2012-11-13 16:00:00">
  
    <defaults>
diff --git a/Code/Mantid/scripts/CMakeLists.txt b/Code/Mantid/scripts/CMakeLists.txt
index f095712435d46dea9fe9f022e51142c56f9198d9..5fa83e35f01b15244516c941d8e9ca754d9a89d8 100644
--- a/Code/Mantid/scripts/CMakeLists.txt
+++ b/Code/Mantid/scripts/CMakeLists.txt
@@ -4,8 +4,8 @@ set ( TEST_PY_FILES
       test/SettingsTest.py
       test/DgreduceTest.py
       test/DirectEnergyConversionTest.py
+      test/IndirectCommonTests.py
       test/ReflectometryQuickAuxiliaryTest.py 
-      test/ExtendedUnitCellTest.py
       test/SansIsisGuiSettings.py
       test/ReductionSettingsTest.py
       )
diff --git a/Code/Mantid/scripts/CrystalTools/ExtendedUnitCell.py b/Code/Mantid/scripts/CrystalTools/ExtendedUnitCell.py
deleted file mode 100644
index 42857ebe35380138732de90e3c4213e1d029f81a..0000000000000000000000000000000000000000
--- a/Code/Mantid/scripts/CrystalTools/ExtendedUnitCell.py
+++ /dev/null
@@ -1,57 +0,0 @@
-from mantid.simpleapi import *  # New API
-from mantid.kernel import *
-from mantid.geometry import UnitCell
-import numpy
-import math
-
-
-
-class ExtendedUnitCell(UnitCell):
-    
-    def __init__(self, cell):
-        super(ExtendedUnitCell, self).__init__(cell.a(), cell.b(), cell.c(), cell.alpha(), cell.beta(), cell.gamma())
-        
-        
-    def recAnglesFromReflections(self, horizontalReflectionX, horizontalReflectionY, desiredReflection):
-        horizontalReflectionX = numpy.array(horizontalReflectionX)
-        horizontalReflectionY = numpy.array(horizontalReflectionY)
-        desiredReflection = numpy.array(desiredReflection)
-        
-        horizontalReflectionX = numpy.matrix(numpy.reshape( horizontalReflectionX, (3, 1)))
-        horizontalReflectionY = numpy.matrix(numpy.reshape( horizontalReflectionY, (3, 1)))
-        desiredReflection = numpy.matrix(numpy.reshape( desiredReflection, (3, 1)))
-        
-        ubMatrix = numpy.matrix(self.getB())
-
-        horizontalReflectionXOrth = numpy.array((ubMatrix  *  horizontalReflectionX).T).flatten()
-        horizontalReflectionYOrth= numpy.array((ubMatrix * horizontalReflectionY).T).flatten()
-        desiredReflectionOrth =  numpy.array((ubMatrix * desiredReflection).T).flatten()
-
-        toDegrees = 180/math.pi
-        
-        scalarProdRX = numpy.dot( desiredReflectionOrth, horizontalReflectionXOrth )
-        sign=numpy.sign(scalarProdRX);
-        angle_r1_px=sign * toDegrees * numpy.arccos(scalarProdRX/( numpy.linalg.norm(desiredReflectionOrth) * numpy.linalg.norm(horizontalReflectionXOrth)) );
-        
-        scalarProdRY = numpy.dot( desiredReflectionOrth, horizontalReflectionYOrth )
-        sign=numpy.sign(scalarProdRY);
-        angle_r1_py=sign * toDegrees * numpy.arccos(scalarProdRY/( numpy.linalg.norm(desiredReflectionOrth) * numpy.linalg.norm(horizontalReflectionYOrth)) );
-        
-        crossProdYX = numpy.cross(horizontalReflectionYOrth, horizontalReflectionXOrth)
-        nP=crossProdYX/numpy.linalg.norm(crossProdYX); 
-        
-        # Now figure out angle between reflection and the scattering plane.
-        scalarProdRZ = numpy.dot( desiredReflectionOrth, nP )
-        sign=numpy.sign(scalarProdRZ);
-        angle_r1_pz = sign * toDegrees * numpy.arccos(scalarProdRZ/( numpy.linalg.norm(desiredReflectionOrth)) );
-       
-        #print angle_r1_px
-        #print angle_r1_py
-        #print angle_r1_pz
-     
-        return (angle_r1_px, angle_r1_py, angle_r1_pz)
-        
-        
-def createFromLatticeParameters(a, b, c, alpha, beta, gamma):
-    cell = UnitCell(a, b, c, alpha, beta, gamma)
-    return ExtendedUnitCell(cell)
\ No newline at end of file
diff --git a/Code/Mantid/scripts/Inelastic/IndirectCommon.py b/Code/Mantid/scripts/Inelastic/IndirectCommon.py
index 54e0badc6a1b47263a22f60a5035d29ebaf4a6fd..62a1b7f72282a244aa09579cf5ce6e6f196efb52 100644
--- a/Code/Mantid/scripts/Inelastic/IndirectCommon.py
+++ b/Code/Mantid/scripts/Inelastic/IndirectCommon.py
@@ -5,6 +5,7 @@ from mantid import config, logger
 from IndirectImport import import_mantidplot
 
 import sys, platform, os.path, math, datetime, re
+import numpy as np
 import itertools
 
 def StartTime(prog):
@@ -45,7 +46,7 @@ def getInstrRun(ws_name):
     run_number = str(ws.getRunNumber())
     if run_number == '0':
         #attempt to parse run number off of name
-        match = re.match('([a-zA-Z]+)([0-9]+)', ws_name)
+        match = re.match(r'([a-zA-Z]+)([0-9]+)', ws_name)
         if match:
             run_number = match.group(2)
         else:
@@ -86,7 +87,11 @@ def getWSprefix(wsname):
         analyser = ''
         reflection = ''
 
-    prefix = run_name + '_' + analyser + reflection + '_'
+    prefix = run_name + '_' + analyser + reflection
+
+    if len(analyser + reflection) > 0:
+        prefix += '_'
+   
     return prefix
 
 def getEfixed(workspace, detIndex=0):
@@ -111,17 +116,6 @@ def getDefaultWorkingDirectory():
 
     return workdir
 
-def getRunTitle(workspace):
-    ws = mtd[workspace]
-    title = ws.getRun()['run_title'].value.strip()
-    runNo = ws.getRun()['run_number'].value
-    inst = ws.getInstrument().getName()
-    ins = config.getFacility().instrument(ins).shortName().lower()
-    valid = "-_.() %s%s" % (string.ascii_letters, string.digits)
-    title = ''.join(ch for ch in title if ch in valid)
-    title = ins + runNo + '-' + title
-    return title
-
 def createQaxis(inputWS):
     result = []
     ws = mtd[inputWS]
@@ -150,7 +144,7 @@ def createQaxis(inputWS):
             result.append(float(axis.label(i)))
     return result
 
-def GetWSangles(inWS,verbose=False):
+def GetWSangles(inWS):
     nhist = mtd[inWS].getNumberHistograms()						# get no. of histograms/groups
     sourcePos = mtd[inWS].getInstrument().getSource().getPos()
     samplePos = mtd[inWS].getInstrument().getSample().getPos() 
@@ -162,37 +156,28 @@ def GetWSangles(inWS,verbose=False):
         angles.append(twoTheta)						# add angle
     return angles
 
-def GetThetaQ(inWS):
-    nhist = mtd[inWS].getNumberHistograms()						# get no. of histograms/groups
-    efixed = getEfixed(inWS)
+def GetThetaQ(ws):
+    nhist = mtd[ws].getNumberHistograms()						# get no. of histograms/groups
+    efixed = getEfixed(ws)
     wavelas = math.sqrt(81.787/efixed)					   # elastic wavelength
     k0 = 4.0*math.pi/wavelas
-    d2r = math.pi/180.0
-    sourcePos = mtd[inWS].getInstrument().getSource().getPos()
-    samplePos = mtd[inWS].getInstrument().getSample().getPos() 
-    beamPos = samplePos - sourcePos
-    theta = []
-    Q = []
-    for index in range(0,nhist):
-        detector = mtd[inWS].getDetector(index)					# get index
-        twoTheta = detector.getTwoTheta(samplePos, beamPos)*180.0/math.pi		# calc angle
-        theta.append(twoTheta)						# add angle
-        Q.append(k0*math.sin(0.5*twoTheta*d2r))
-    return theta,Q
-
-def ExtractFloat(a):                              #extract values from line of ascii
-    extracted = []
-    elements = a.split()							#split line on spaces
-    for n in elements:
-        extracted.append(float(n))
-    return extracted                                 #values as list
-
-def ExtractInt(a):                              #extract values from line of ascii
-    extracted = []
-    elements = a.split()							#split line on spaces
-    for n in elements:
-        extracted.append(int(n))
-    return extracted                                 #values as list
+
+    theta = np.array(GetWSangles(ws))
+    Q = k0 * np.sin(0.5 * np.radians(theta))
+
+    return theta, Q
+
+def ExtractFloat(data_string):
+    """ Extract float values from an ASCII string"""
+    values = data_string.split()
+    values = map(float, values)
+    return values
+
+def ExtractInt(data_string):
+    """ Extract int values from an ASCII string"""
+    values = data_string.split()
+    values = map(int, values)
+    return values
 
 def PadArray(inarray,nfixed):                   #pad a list to specified size
 	npt=len(inarray)
@@ -255,7 +240,7 @@ def CheckXrange(x_range,type):
         if math.fabs(upper) < 1e-5:
             raise ValueError(type + ' - input maximum ('+str(upper)+') is Zero')
         if upper < lower:
-            raise ValueError(type + ' - input max ('+str(upper)+') < min ('+lower+')')
+            raise ValueError(type + ' - input max ('+str(upper)+') < min ('+str(lower)+')')
 
 def CheckElimits(erange,Xin):
     nx = len(Xin)-1
@@ -269,7 +254,7 @@ def CheckElimits(erange,Xin):
     if erange[1] > Xin[nx]:
         raise ValueError('Elimits - input emax ( '+str(erange[1])+' ) > data emax ( '+str(Xin[nx])+' )')
     if erange[1] < erange[0]:
-        raise ValueError('Elimits - input emax ( '+str(erange[1])+' ) < emin ( '+erange[0]+' )')
+        raise ValueError('Elimits - input emax ( '+str(erange[1])+' ) < emin ( '+str(erange[0])+' )')
 
 def getInstrumentParameter(ws, param_name):
     """Get an named instrument parameter from a workspace.
@@ -352,17 +337,15 @@ def convertToElasticQ(input_ws, output_ws=None):
   elif axis.isNumeric():
       #check that units are Momentum Transfer
       if axis.getUnit().unitID() != 'MomentumTransfer':
-          logger.error('Input must have axis values of Q')
-          sys.exit()
+          raise RuntimeError('Input must have axis values of Q')
       
       CloneWorkspace(input_ws, OutputWorkspace=output_ws)
   else:
-    logger.error('Input workspace must have either spectra or numeric axis.')
-    sys.exit()
+    raise RuntimeError('Input workspace must have either spectra or numeric axis.')
   
 def transposeFitParametersTable(params_table, output_table=None):
   """
-    Transpose the parameter table created of Fit.
+    Transpose the parameter table created from a multi domain Fit.
 
     This function will make the output consistent with PlotPeakByLogValue.
     @param params_table - the parameter table output from Fit.
@@ -371,9 +354,8 @@ def transposeFitParametersTable(params_table, output_table=None):
   """
   params_table = mtd[params_table]
 
-  table_ws = '__tmp_furyfitmulti_table_ws'
-  CreateEmptyTableWorkspace(OutputWorkspace=table_ws)
-  table_ws = mtd[table_ws]
+  table_ws = '__tmp_table_ws'
+  table_ws = CreateEmptyTableWorkspace(OutputWorkspace=table_ws)
 
   param_names = params_table.column(0)[:-1] #-1 to remove cost function
   param_values = params_table.column(1)[:-1]
diff --git a/Code/Mantid/scripts/Inelastic/IndirectDataAnalysis.py b/Code/Mantid/scripts/Inelastic/IndirectDataAnalysis.py
index ba3a786e65099cfc792ba372e0dc79e730a57dbe..d405ab8c33063098e666beb46b41d8cce72d8048 100644
--- a/Code/Mantid/scripts/Inelastic/IndirectDataAnalysis.py
+++ b/Code/Mantid/scripts/Inelastic/IndirectDataAnalysis.py
@@ -760,6 +760,13 @@ def msdfit(ws, startX, endX, spec_min=0, spec_max=None, Save=False, Verbose=Fals
     msd_parameters = msdWS+'_Parameters'
     RenameWorkspace(msdWS, OutputWorkspace=msd_parameters)
 
+    params_table = mtd[msd_parameters]
+    
+    #msd value should be positive, but the fit output is negative
+    msd = params_table.column('A1')
+    for i, value in enumerate(msd):
+        params_table.setCell('A1', i, value * -1)
+
     #create workspaces for each of the parameters
     group = []
 
diff --git a/Code/Mantid/scripts/Inelastic/inelastic_indirect_reduction_steps.py b/Code/Mantid/scripts/Inelastic/inelastic_indirect_reduction_steps.py
index 3fd212873bf11b8ce1743bb09cfc0cefffc27b97..7f99201aebed14c0625c8ec2b7c6e14b7b5514f0 100644
--- a/Code/Mantid/scripts/Inelastic/inelastic_indirect_reduction_steps.py
+++ b/Code/Mantid/scripts/Inelastic/inelastic_indirect_reduction_steps.py
@@ -996,7 +996,8 @@ class SaveItem(ReductionStep):
             elif format == 'nxspe':
                 SaveNXSPE(InputWorkspace=file_ws,Filename= filename+'.nxspe')
             elif format == 'ascii':
-                SaveAscii(InputWorkspace=file_ws,Filename= filename+'.dat')
+                #version 1 of SaveASCII produces output that works better with excel/origin
+                SaveAscii(InputWorkspace=file_ws,Filename= filename+'.dat', Version=1)
             elif format == 'gss':
                 ConvertUnits(InputWorkspace=file_ws,OutputWorkspace= "__save_item_temp",Target= "TOF")
                 SaveGSS(InputWorkspace="__save_item_temp",Filename= filename+".gss")
diff --git a/Code/Mantid/scripts/Interface/reduction_application.py b/Code/Mantid/scripts/Interface/reduction_application.py
index b8dc94cefedf34d46b70d7c24e67ceca9c5d057a..af890a155309529c9f60c3dc567f21891897f094 100644
--- a/Code/Mantid/scripts/Interface/reduction_application.py
+++ b/Code/Mantid/scripts/Interface/reduction_application.py
@@ -3,7 +3,6 @@
 """
 import sys, os
 import traceback
-import math
 
 # Check whether Mantid is available
 IS_IN_MANTIDPLOT = False
@@ -19,7 +18,7 @@ except:
     sip.setapi('QVariant',2)
     pass
 
-from PyQt4 import QtGui, QtCore, uic
+from PyQt4 import QtGui, QtCore
 
 REDUCTION_WARNING = False
 WARNING_MESSAGE = ""
@@ -107,12 +106,11 @@ class ReductionGUI(QtGui.QMainWindow, ui.ui_reduction_main.Ui_SANSReduction):
             self.reduce_button.hide()
         self.cluster_button.hide()
         self.connect(self.export_button, QtCore.SIGNAL("clicked()"), self._export)
-        self.connect(self.reduce_button, QtCore.SIGNAL("clicked()"), self.reduce_clicked)  
+        self.connect(self.reduce_button, QtCore.SIGNAL("clicked()"), self.reduce_clicked)
         self.connect(self.save_button, QtCore.SIGNAL("clicked()"), self._save)  
-        self.connect(self.interface_chk, QtCore.SIGNAL("clicked(bool)"), self._interface_choice)  
+        self.connect(self.interface_chk, QtCore.SIGNAL("clicked(bool)"), self._interface_choice)
         
         self.interface_chk.setChecked(self.general_settings.advanced)
-            
 
         # Of the widgets that are part of the application, one is the ApplicationWindow.
         # The ApplicationWindow will send a shutting_down() signal when quitting,
@@ -121,7 +119,7 @@ class ReductionGUI(QtGui.QMainWindow, ui.ui_reduction_main.Ui_SANSReduction):
         for w in QtCore.QCoreApplication.instance().topLevelWidgets():
             self.connect(w, QtCore.SIGNAL("shutting_down()"), self.close)
             
-        self.general_settings.progress.connect(self._progress_updated)    
+        self.general_settings.progress.connect(self._progress_updated)
         
     def _set_window_title(self):
         """
@@ -160,7 +158,7 @@ class ReductionGUI(QtGui.QMainWindow, ui.ui_reduction_main.Ui_SANSReduction):
                     self._facility = facility
                     break
         if self._facility is None:
-            self._facility = str(c.facility().name())
+            self._facility = ConfigService.Instance().getFacility().name()
                 
         self.general_settings.facility_name = self._facility
         self._interface = instrument_factory(self._instrument, settings=self.general_settings)
@@ -191,6 +189,7 @@ class ReductionGUI(QtGui.QMainWindow, ui.ui_reduction_main.Ui_SANSReduction):
             if load_last:
                 self._interface.load_last_reduction()
         else:
+            print "Could not generate an interface for instrument %s" % self._instrument
             self.close()
             
         return True
@@ -201,7 +200,7 @@ class ReductionGUI(QtGui.QMainWindow, ui.ui_reduction_main.Ui_SANSReduction):
         """
         self.file_menu.clear()
 
-        newAction = QtGui.QAction("&New...", self)
+        newAction = QtGui.QAction("&New Reduction...", self)
         newAction.setShortcut("Ctrl+N")
         newAction.setStatusTip("Start a new reduction")
         self.connect(newAction, QtCore.SIGNAL("triggered()"), self._new)
@@ -355,7 +354,7 @@ class ReductionGUI(QtGui.QMainWindow, ui.ui_reduction_main.Ui_SANSReduction):
                 for res in compute_resources:
                     self.resource_combo.addItem(QtGui.QApplication.translate("Dialog", res, None, QtGui.QApplication.UnicodeUTF8))
             
-        # Fill out the defaults    
+        # Fill out the defaults
         dialog = ClusterDialog(self._compute_resources)
         if self.general_settings.cluster_user is not None:
             dialog.username_edit.setText(str(self.general_settings.cluster_user))
@@ -408,8 +407,8 @@ class ReductionGUI(QtGui.QMainWindow, ui.ui_reduction_main.Ui_SANSReduction):
         else:    
             settings = QtCore.QSettings()
             
-            settings.setValue("instrument_name", self._instrument)            
-            settings.setValue("last_file", self._filename)            
+            settings.setValue("instrument_name", self._instrument)
+            settings.setValue("last_file", self._filename)
             settings.setValue("recent_files", self._recent_files)
             settings.setValue("last_directory", str(self._last_directory))
             settings.setValue("last_export_directory", str(self._last_export_directory))
@@ -487,7 +486,7 @@ class ReductionGUI(QtGui.QMainWindow, ui.ui_reduction_main.Ui_SANSReduction):
             self._instrument = found_instrument
             self.setup_layout()
             
-        self.reduce_button.setEnabled(False)   
+        self.reduce_button.setEnabled(False)
         self.export_button.setEnabled(False)
         self.save_button.setEnabled(False)
         self.interface_chk.setEnabled(False)
@@ -559,7 +558,7 @@ class ReductionGUI(QtGui.QMainWindow, ui.ui_reduction_main.Ui_SANSReduction):
             fname = self._instrument + '_'
                 
         fname_qstr = QtGui.QFileDialog.getSaveFileName(self, "Reduction settings - Save settings",
-                                                       self._last_directory + '/' + fname,  
+                                                       self._last_directory + '/' + fname,
                                                        "Settings files (*.xml)")
         fname = str(QtCore.QFileInfo(fname_qstr).filePath())
         if len(fname)>0:
@@ -569,7 +568,7 @@ class ReductionGUI(QtGui.QMainWindow, ui.ui_reduction_main.Ui_SANSReduction):
                 self._recent_files.remove(fname)
             self._recent_files.insert(0,fname)
             while len(self._recent_files) > 10:
-                self._recent_files.pop()                
+                self._recent_files.pop()
             self._last_directory = str(QtCore.QFileInfo(fname_qstr).path())
             self._filename = fname
             self._save()
@@ -616,4 +615,3 @@ def start(argv):
 if __name__ == '__main__':
     start(argv=sys.argv)
 
-        
diff --git a/Code/Mantid/scripts/Interface/reduction_gui/instruments/interface.py b/Code/Mantid/scripts/Interface/reduction_gui/instruments/interface.py
index 037f9dfb8a66dcf59c1b3dcf7db23c7f08abc9b6..c8fa34b3d7ffbb87982cea53b2a4a6bc95812956 100644
--- a/Code/Mantid/scripts/Interface/reduction_gui/instruments/interface.py
+++ b/Code/Mantid/scripts/Interface/reduction_gui/instruments/interface.py
@@ -14,8 +14,8 @@ class InstrumentInterface(object):
     """
     ## List of widgets with associated observers
     widgets = []
-    ERROR_REPORT_NAME = "sans_error_report.xml"    
-    LAST_REDUCTION_NAME = ".mantid_last_reduction.xml"    
+    ERROR_REPORT_NAME = "sans_error_report.xml"
+    LAST_REDUCTION_NAME = ".mantid_last_reduction.xml"
     ERROR_REPORT_DIR = ""
     
     def __init__(self, name, settings):
@@ -88,9 +88,12 @@ class InstrumentInterface(object):
             populate the UI with them
             @param file_name: XML file to be loaded
         """
-        if self.scripter.check_xml_compatibility(file_name):
+        if self.scripter.check_xml_compatibility(file_name, 'Instrument'):
             self.scripter.from_xml(file_name)
             self.scripter.push_state()
+        elif self.scripter.check_xml_compatibility(file_name, 'SetupInfo'):
+            self.scripter.from_xml(file_name, True)
+            self.scripter.push_state()
         
     def save_file(self, file_name):
         """
@@ -185,7 +188,7 @@ class InstrumentInterface(object):
             red_path = os.path.join(self.ERROR_REPORT_DIR, self.LAST_REDUCTION_NAME)
             self.save_file(red_path)
         except:
-            print "Could not save last reduction\n  %s" % str(traceback.format_exc())        
+            print "Could not save last reduction\n  %s" % str(traceback.format_exc())
         
         try:
             self.set_running(True)
@@ -202,14 +205,14 @@ class InstrumentInterface(object):
             else:
                 msg = "Reduction could not be executed:\n\n%s" % sys.exc_value
                 log_path = os.path.join(self.ERROR_REPORT_DIR, self.ERROR_REPORT_NAME)
-                msg += "\n\nWhen contacting the Mantid Team, please send this file:\n%s\n" % log_path                
+                msg += "\n\nWhen contacting the Mantid Team, please send this file:\n%s\n" % log_path
             self._warning("Reduction failed", msg)
             self._error_report(traceback.format_exc())
         except:
             msg = "Reduction could not be executed:\n\n%s" % sys.exc_value
             msg += "\n\nPlease check your reduction parameters\n"
             log_path = os.path.join(self.ERROR_REPORT_DIR, self.ERROR_REPORT_NAME)
-            msg += "\n\nWhen contacting the Mantid Team, please send this file:\n%s\n" % log_path            
+            msg += "\n\nWhen contacting the Mantid Team, please send this file:\n%s\n" % log_path
             self._warning("Reduction failed", msg)
             self._error_report(traceback.format_exc())
         # Update widgets
diff --git a/Code/Mantid/scripts/Interface/reduction_gui/reduction/sans/eqsans_background_script.py b/Code/Mantid/scripts/Interface/reduction_gui/reduction/sans/eqsans_background_script.py
index aff6d758f9b42b85f5ae6b89f0e1cd6aecb2dd0c..f370068338852a90baba8d75d3ce3141341c6f00 100644
--- a/Code/Mantid/scripts/Interface/reduction_gui/reduction/sans/eqsans_background_script.py
+++ b/Code/Mantid/scripts/Interface/reduction_gui/reduction/sans/eqsans_background_script.py
@@ -26,6 +26,25 @@ class Background(BaseBackground):
             return "BckDirectBeamTransmission(\"%s\", \"%s\", beam_radius=%g)\n" % \
             (self.sample_file, self.direct_beam, self.beam_radius)
 
+        def from_setup_info(self, xml_str):
+            """
+                Read in data from XML using the string representation of the setup algorithm used
+                to prepare the reduction properties.
+                @param xml_str: text to read the data from
+            """
+            self.reset()
+            from mantid.api import Algorithm
+            dom = xml.dom.minidom.parseString(xml_str)
+            
+            process_dom = dom.getElementsByTagName("SASProcess")[0]
+            setup_alg_str = BaseScriptElement.getStringElement(process_dom, 'SetupInfo')
+            alg=Algorithm.fromString(str(setup_alg_str))
+            
+            self.sample_file = BaseScriptElement.getPropertyValue(alg, "BckTransmissionSampleDataFile", default='')
+            self.direct_beam = BaseScriptElement.getPropertyValue(alg, "BckTransmissionEmptyDataFile", default='')
+            self.beam_radius = BaseScriptElement.getPropertyValue(alg, "BckTransmissionBeamRadius", 
+                                                                  default=SampleData.DirectBeam.beam_radius)
+
     trans_calculation_method = DirectBeam()
     # Option list
     option_list = [DirectBeam]
@@ -68,15 +87,31 @@ class Background(BaseBackground):
         """
             Read in data from XML
             @param xml_str: text to read the data from
-        """    
-        self.reset()   
+        """
+        self.reset()
         super(Background, self).from_xml(xml_str)
         
         dom = xml.dom.minidom.parseString(xml_str)
         element_list = dom.getElementsByTagName("Background")
         if len(element_list)>0:
-            instrument_dom = element_list[0]      
+            instrument_dom = element_list[0]
             self.combine_transmission_frames = BaseScriptElement.getBoolElement(instrument_dom, "combine_transmission_frames",
                                                                                 default = Background.combine_transmission_frames)
 
-    
\ No newline at end of file
+    def from_setup_info(self, xml_str):
+        """
+            Read in data from XML using the string representation of the setup algorithm used
+            to prepare the reduction properties.
+            @param xml_str: text to read the data from
+        """
+        self.reset()
+        super(Background, self).from_setup_info(xml_str)
+        
+        from mantid.api import Algorithm
+        dom = xml.dom.minidom.parseString(xml_str)
+        
+        process_dom = dom.getElementsByTagName("SASProcess")[0]
+        setup_alg_str = BaseScriptElement.getStringElement(process_dom, 'SetupInfo')
+        alg=Algorithm.fromString(str(setup_alg_str))
+        self.combine_transmission_frames = BaseScriptElement.getPropertyValue(alg, "BckFitFramesTogether",
+                                                                              default=SampleData.combine_transmission_frames)
diff --git a/Code/Mantid/scripts/Interface/reduction_gui/reduction/sans/eqsans_data_script.py b/Code/Mantid/scripts/Interface/reduction_gui/reduction/sans/eqsans_data_script.py
index 9b00d8d1d3ae1c729e114e73dab812a65d6045d3..749efe6d9948e3522647c8b6b06c62ea96202c36 100755
--- a/Code/Mantid/scripts/Interface/reduction_gui/reduction/sans/eqsans_data_script.py
+++ b/Code/Mantid/scripts/Interface/reduction_gui/reduction/sans/eqsans_data_script.py
@@ -29,7 +29,7 @@ class DataSets(BaseSampleData):
         script_sample = super(DataSets, self).to_script(data_file)
         script_bck = self.background.to_script()
         return "%s\n%s" % (script_sample, script_bck)
-            
+    
     def to_xml(self):
         """
             Create XML from the current data.
@@ -42,8 +42,17 @@ class DataSets(BaseSampleData):
         """
             Read in data from XML
             @param xml_str: text to read the data from
-        """    
+        """
         self.reset()
         super(DataSets, self).from_xml(xml_str)
         self.background.from_xml(xml_str)
-    
\ No newline at end of file
+    
+    def from_setup_info(self, xml_str):
+        """
+            Read in data from XML using the string representation of the setup algorithm used
+            to prepare the reduction properties.
+            @param xml_str: text to read the data from
+        """
+        self.reset()
+        super(DataSets, self).from_setup_info(xml_str)
+        self.background.from_setup_info(xml_str)
\ No newline at end of file
diff --git a/Code/Mantid/scripts/Interface/reduction_gui/reduction/sans/eqsans_options_script.py b/Code/Mantid/scripts/Interface/reduction_gui/reduction/sans/eqsans_options_script.py
index f005422392bdb0775467b0d84f3f768e5473f473..4692d1328972791afe739f1558464b59927effd0 100644
--- a/Code/Mantid/scripts/Interface/reduction_gui/reduction/sans/eqsans_options_script.py
+++ b/Code/Mantid/scripts/Interface/reduction_gui/reduction/sans/eqsans_options_script.py
@@ -87,8 +87,7 @@ class ReductionOptions(BaseOptions):
             script += "  CorrectForFlightPath=1,\n"
         else:
             script += "  CorrectForFlightPath=0,\n"
-                      
-                      
+            
         if self.solid_angle_corr:
             script += "  SolidAngleCorrection=1,\n"
         else:
@@ -142,7 +141,7 @@ class ReductionOptions(BaseOptions):
             script += "Resolution(sample_aperture_diameter=%g)\n" % self.sample_aperture_diameter
 
         if not self.perform_TOF_correction:
-            script += "ReductionSingleton().get_data_loader().skip_tof_correction(True)\n"
+            script += "SkipTOFCorrection()\n"
         else:
             # Flight path correction
             script += "PerformFlightPathCorrection(%s)\n" % self.correct_for_flight_path
@@ -183,7 +182,7 @@ class ReductionOptions(BaseOptions):
             Read in data from XML
             @param xml_str: text to read the data from
         """    
-        self.reset()   
+        self.reset()
         super(ReductionOptions, self).from_xml(xml_str)
         
         dom = xml.dom.minidom.parseString(xml_str)
@@ -219,4 +218,41 @@ class ReductionOptions(BaseOptions):
         self.use_beam_monitor = BaseScriptElement.getBoolElement(dom, "UseBeamMonitor",
                                                                  default = ReductionOptions.use_beam_monitor)
         self.beam_monitor_reference = BaseScriptElement.getStringElement(dom, "BeamMonitorRef",
-                                                                         default = ReductionOptions.beam_monitor_reference)
\ No newline at end of file
+                                                                         default = ReductionOptions.beam_monitor_reference)
+        
+    def from_setup_info(self, xml_str):
+        """
+            Read in data from XML using the string representation of the setup algorithm used
+            to prepare the reduction properties.
+            @param xml_str: text to read the data from
+        """
+        self.reset()
+        super(ReductionOptions, self).from_setup_info(xml_str)
+        
+        from mantid.api import Algorithm
+        dom = xml.dom.minidom.parseString(xml_str)
+        
+        process_dom = dom.getElementsByTagName("SASProcess")[0]
+        setup_alg_str = BaseScriptElement.getStringElement(process_dom, 'SetupInfo')
+        alg=Algorithm.fromString(str(setup_alg_str))
+        self.use_config_cutoff = BaseScriptElement.getPropertyValue(alg, "UseConfigTOFCuts",
+                                                                    default=ReductionOptions.use_config_cutoff)
+        self.correct_for_flight_path = BaseScriptElement.getPropertyValue(alg, "CorrectForFlightPath",
+                                                                          default=ReductionOptions.correct_for_flight_path)
+        self.low_TOF_cut = BaseScriptElement.getPropertyValue(alg, "LowTOFCut",
+                                                              default=ReductionOptions.low_TOF_cut)
+        self.high_TOF_cut = BaseScriptElement.getPropertyValue(alg, "HighTOFCut",
+                                                               default=ReductionOptions.high_TOF_cut)
+        self.use_config_mask = BaseScriptElement.getPropertyValue(alg, "UseConfigMask",
+                                                                  default=ReductionOptions.use_config_mask)
+        self.compute_resolution = BaseScriptElement.getPropertyValue(alg, "ComputeResolution",
+                                                                     default=ReductionOptions.compute_resolution)
+        self.sample_aperture_diameter = BaseScriptElement.getPropertyValue(alg, "SampleApertureDiameter",
+                                                                           default=ReductionOptions.sample_aperture_diameter)
+        self.perform_TOF_correction = not BaseScriptElement.getPropertyValue(alg, "SkipTOFCorrection",
+                                                                             default=False)
+        norm_option = BaseScriptElement.getPropertyValue(alg, "Normalisation", default = 'Monitor')
+        self.use_beam_monitor = norm_option=='Monitor'
+        self.beam_monitor_reference = BaseScriptElement.getPropertyValue(alg, "MonitorReferenceFile",
+                                                                         default=ReductionOptions.beam_monitor_reference)
+        
\ No newline at end of file
diff --git a/Code/Mantid/scripts/Interface/reduction_gui/reduction/sans/eqsans_sample_script.py b/Code/Mantid/scripts/Interface/reduction_gui/reduction/sans/eqsans_sample_script.py
index b555950a9015fb3cea1bd2a6ab238c81ccf2e81f..0f53b4b6db4b1de7af9d44d80c15bd38ea313966 100644
--- a/Code/Mantid/scripts/Interface/reduction_gui/reduction/sans/eqsans_sample_script.py
+++ b/Code/Mantid/scripts/Interface/reduction_gui/reduction/sans/eqsans_sample_script.py
@@ -60,4 +60,20 @@ class SampleData(BaseSampleData):
             self.combine_transmission_frames = BaseScriptElement.getBoolElement(instrument_dom, "combine_transmission_frames",
                                                                                 default = SampleData.combine_transmission_frames)
 
-    
\ No newline at end of file
+    def from_setup_info(self, xml_str):
+        """
+            Read in data from XML using the string representation of the setup algorithm used
+            to prepare the reduction properties.
+            @param xml_str: text to read the data from
+        """
+        self.reset()
+        super(SampleData, self).from_setup_info(xml_str)
+        
+        from mantid.api import Algorithm
+        dom = xml.dom.minidom.parseString(xml_str)
+        
+        process_dom = dom.getElementsByTagName("SASProcess")[0]
+        setup_alg_str = BaseScriptElement.getStringElement(process_dom, 'SetupInfo')
+        alg=Algorithm.fromString(str(setup_alg_str))
+        self.combine_transmission_frames = BaseScriptElement.getPropertyValue(alg, "FitFramesTogether",
+                                                                              default=SampleData.combine_transmission_frames)
diff --git a/Code/Mantid/scripts/Interface/reduction_gui/reduction/sans/hfir_background_script.py b/Code/Mantid/scripts/Interface/reduction_gui/reduction/sans/hfir_background_script.py
index 7b6892b26c8e024fd83328f0ba640658ffcd796c..3aa97d997f5a37e8e4901dd3d63bf1ecd375ff1f 100644
--- a/Code/Mantid/scripts/Interface/reduction_gui/reduction/sans/hfir_background_script.py
+++ b/Code/Mantid/scripts/Interface/reduction_gui/reduction/sans/hfir_background_script.py
@@ -4,8 +4,6 @@
     be used independently of the interface implementation
 """
 import xml.dom.minidom
-import copy
-import os
 from reduction_gui.reduction.scripter import BaseScriptElement
 from reduction_gui.reduction.sans.hfir_sample_script import SampleData
 
@@ -39,6 +37,25 @@ class Background(BaseScriptElement):
             return "BckDirectBeamTransmission(\"%s\", \"%s\", beam_radius=%g)\n" % \
             (self.sample_file, self.direct_beam, self.beam_radius)
         
+        def from_setup_info(self, xml_str):
+            """
+                Read in data from XML using the string representation of the setup algorithm used
+                to prepare the reduction properties.
+                @param xml_str: text to read the data from
+            """
+            self.reset()
+            from mantid.api import Algorithm
+            dom = xml.dom.minidom.parseString(xml_str)
+            
+            process_dom = dom.getElementsByTagName("SASProcess")[0]
+            setup_alg_str = BaseScriptElement.getStringElement(process_dom, 'SetupInfo')
+            alg=Algorithm.fromString(str(setup_alg_str))
+            
+            self.sample_file = BaseScriptElement.getPropertyValue(alg, "BckTransmissionSampleDataFile", default='')
+            self.direct_beam = BaseScriptElement.getPropertyValue(alg, "BckTransmissionEmptyDataFile", default='')
+            self.beam_radius = BaseScriptElement.getPropertyValue(alg, "BckTransmissionBeamRadius", 
+                                                                  default=SampleData.DirectBeam.beam_radius)
+
     class BeamSpreader(SampleData.BeamSpreader):
         def __init__(self, state=None):
             SampleData.BeamSpreader.__init__(self)
@@ -66,6 +83,29 @@ class Background(BaseScriptElement):
              self.sample_scatt, self.direct_scatt, 
              self.spreader_trans, self.spreader_trans_spread) 
         
+        def from_setup_info(self, xml_str):
+            """
+                Read in data from XML using the string representation of the setup algorithm used
+                to prepare the reduction properties.
+                @param xml_str: text to read the data from
+            """
+            self.reset()
+            from mantid.api import Algorithm
+            dom = xml.dom.minidom.parseString(xml_str)
+            
+            process_dom = dom.getElementsByTagName("SASProcess")[0]
+            setup_alg_str = BaseScriptElement.getStringElement(process_dom, 'SetupInfo')
+            alg=Algorithm.fromString(str(setup_alg_str))
+            
+            self.sample_scatt = BaseScriptElement.getPropertyValue(alg, "BckTransSampleScatteringFilename", default='')
+            self.sample_spreader = BaseScriptElement.getPropertyValue(alg, "BckTransSampleSpreaderFilename", default='')
+            self.direct_scatt = BaseScriptElement.getPropertyValue(alg, "BckTransDirectScatteringFilename", default='')
+            self.direct_spreader = BaseScriptElement.getPropertyValue(alg, "BckTransDirectSpreaderFilename", default='')
+            self.spreader_trans = BaseScriptElement.getPropertyValue(alg, "BckSpreaderTransmissionValue", 
+                                                                     default=SampleData.BeamSpreader.spreader_trans)
+            self.spreader_trans_spread = BaseScriptElement.getPropertyValue(alg, "BckSpreaderTransmissionError", 
+                                                                            default=SampleData.BeamSpreader.spreader_trans_spread)
+
     dark_current_corr = False
     dark_current_file = ''
     
@@ -90,13 +130,13 @@ class Background(BaseScriptElement):
         # Dark current
         if self.dark_current_corr:
             if len(str(self.dark_current_file).strip())==0:
-                raise RuntimeError, "Dark current subtraction was selected but no dark current data file was entered."            
+                raise RuntimeError, "Dark current subtraction was selected but no dark current data file was entered."
             script += "DarkCurrent(\"%s\")\n" % self.dark_current_file
         
         # Background
         if self.background_corr:
             if len(str(self.background_file).strip())==0:
-                raise RuntimeError, "Background subtraction was selected but no background data file was entered."            
+                raise RuntimeError, "Background subtraction was selected but no background data file was entered."
             script += "Background(\"%s\")\n" % self.background_file
             
             # Background transmission
@@ -110,7 +150,7 @@ class Background(BaseScriptElement):
                 if self.trans_dark_current is not None and len(str(self.trans_dark_current))>0:
                     script += "BckTransmissionDarkCurrent(\"%s\")\n" % str(self.trans_dark_current)
             
-        return script           
+        return script
     
     def update(self):
         """
@@ -157,7 +197,7 @@ class Background(BaseScriptElement):
             instrument_dom = element_list[0]   
             
             self.sample_thickness = BaseScriptElement.getFloatElement(instrument_dom, "sample_thickness",
-                                                                      default=Background.sample_thickness)      
+                                                                      default=Background.sample_thickness)
             
             self.dark_current_corr = BaseScriptElement.getBoolElement(instrument_dom, "dark_current_corr",
                                                                       default = Background.dark_current_corr)
@@ -171,7 +211,7 @@ class Background(BaseScriptElement):
                                                                            default = Background.bck_transmission_enabled)
 
             self.bck_transmission = BaseScriptElement.getFloatElement(instrument_dom, "bck_trans",
-                                                                  default=Background.bck_transmission)      
+                                                                  default=Background.bck_transmission)
             self.bck_transmission_spread = BaseScriptElement.getFloatElement(instrument_dom, "bck_trans_spread",
                                                                   default=Background.bck_transmission_spread)  
             self.calculate_transmission = BaseScriptElement.getBoolElement(instrument_dom, "calculate_trans",
@@ -187,6 +227,41 @@ class Background(BaseScriptElement):
                     self.trans_calculation_method = method
                     break
 
+    def from_setup_info(self, xml_str):
+        """
+            Read in data from XML using the string representation of the setup algorithm used
+            to prepare the reduction properties.
+            @param xml_str: text to read the data from
+        """
+        self.reset()
+        from mantid.api import Algorithm
+        dom = xml.dom.minidom.parseString(xml_str)
+        
+        process_dom = dom.getElementsByTagName("SASProcess")[0]
+        setup_alg_str = BaseScriptElement.getStringElement(process_dom, 'SetupInfo')
+        alg=Algorithm.fromString(str(setup_alg_str))
+
+        self.background_file = BaseScriptElement.getPropertyValue(alg, "BackgroundFiles", default='')
+        self.background_corr = len(self.background_file)>0
+        self.bck_transmission_enabled = True
+        trans_method = BaseScriptElement.getPropertyValue(alg, "BckTransmissionMethod", default='Value')
+        
+        # Transmission
+        self.bck_transmission = BaseScriptElement.getPropertyValue(alg, "BckTransmissionValue", default=SampleData.transmission)
+        self.bck_transmission_spread = BaseScriptElement.getPropertyValue(alg, "BckTransmissionError", default=SampleData.transmission_spread)
+        
+        self.trans_dark_current = BaseScriptElement.getPropertyValue(alg, "BckTransmissionDarkCurrentFile", default='')
+        self.theta_dependent = BaseScriptElement.getPropertyValue(alg, "BckThetaDependentTransmission",
+                                                                  default = SampleData.theta_dependent)
+
+        self.calculate_transmission = trans_method in ['DirectBeam', 'BeamSpreader']
+        if trans_method=='DirectBeam':
+            self.trans_calculation_method = Background.DirectBeam()
+            self.trans_calculation_method.from_setup_info(xml_str)
+        elif trans_method=='BeamSpreader':
+            self.trans_calculation_method = Background.BeamSpreader()
+            self.trans_calculation_method.from_setup_info(xml_str)
+
     def reset(self):
         """
             Reset state
@@ -195,9 +270,9 @@ class Background(BaseScriptElement):
         self.dark_current_file = ''
         self.background_corr = Background.background_corr
         self.background_file = ''
-        self.bck_transmission_enabled = Background.bck_transmission_enabled      
-        self.bck_transmission = Background.bck_transmission      
-        self.bck_transmission_spread = Background.bck_transmission_spread  
+        self.bck_transmission_enabled = Background.bck_transmission_enabled
+        self.bck_transmission = Background.bck_transmission
+        self.bck_transmission_spread = Background.bck_transmission_spread
         self.calculate_transmission = Background.calculate_transmission
         self.theta_dependent = Background.theta_dependent
         self.trans_dark_current = Background.trans_dark_current
diff --git a/Code/Mantid/scripts/Interface/reduction_gui/reduction/sans/hfir_detector_script.py b/Code/Mantid/scripts/Interface/reduction_gui/reduction/sans/hfir_detector_script.py
index ade1f02c9b56420db24549e8d582c63057d5f34c..b39b838ac4561df4d1ed69385b44a0906bf756a6 100644
--- a/Code/Mantid/scripts/Interface/reduction_gui/reduction/sans/hfir_detector_script.py
+++ b/Code/Mantid/scripts/Interface/reduction_gui/reduction/sans/hfir_detector_script.py
@@ -2,8 +2,6 @@
     
 """
 import xml.dom.minidom
-import copy
-import os
 from reduction_gui.reduction.scripter import BaseScriptElement
 
 # Check whether we are running in MantidPlot
@@ -88,7 +86,7 @@ class Detector(BaseScriptElement):
         else:
             script += "NoSensitivityCorrection()\n"
                     
-        return script           
+        return script
     
     def options(self):
         """
@@ -172,12 +170,9 @@ class Detector(BaseScriptElement):
             Read in data from XML
             @param xml_str: text to read the data from
         """ 
-        self.reset()      
+        self.reset()
         dom = xml.dom.minidom.parseString(xml_str)
         
-        # Get Mantid version
-        mtd_version = BaseScriptElement.getMantidBuildVersion(dom)
-
         # Sensitivity correction
         element_list = dom.getElementsByTagName("Sensitivity")
         if len(element_list)>0:
@@ -225,6 +220,56 @@ class Detector(BaseScriptElement):
             self.use_direct_beam = BaseScriptElement.getBoolElement(beam_finder_dom, "use_direct_beam",
                                                                default = Detector.use_direct_beam) 
 
+    def from_setup_info(self, xml_str):
+        """
+            Read in data from XML using the string representation of the setup algorithm used
+            to prepare the reduction properties.
+            @param xml_str: text to read the data from
+        """
+        self.reset()
+        from mantid.api import Algorithm
+        dom = xml.dom.minidom.parseString(xml_str)
+        
+        process_dom = dom.getElementsByTagName("SASProcess")[0]
+        setup_alg_str = BaseScriptElement.getStringElement(process_dom, 'SetupInfo')
+        alg=Algorithm.fromString(str(setup_alg_str))
+
+        # Sensitivity correction
+        self.sensitivity_data = BaseScriptElement.getPropertyValue(alg, "SensitivityFile", default='')
+        self.sensitivity_corr = len(self.sensitivity_data)>0
+        self.sensitivity_dark = BaseScriptElement.getPropertyValue(alg, "SensitivityDarkCurrentFile", default='')
+        self.use_sample_dark = BaseScriptElement.getPropertyValue(alg, "UseDefaultDC",
+                                                                  default = Detector.use_sample_dark)
+        self.min_sensitivity = BaseScriptElement.getPropertyValue(alg, "MinEfficiency",
+                                                                  default=Detector.min_sensitivity)
+        self.max_sensitivity = BaseScriptElement.getPropertyValue(alg, "MaxEfficiency",
+                                                                  default=Detector.max_sensitivity)
+        
+        sensitivity_center_method = BaseScriptElement.getPropertyValue(alg, "SensitivityBeamCenterMethod",
+                                                                       default='None')
+        self.flood_use_finder = sensitivity_center_method in ['DirectBeam', 'Scattering']
+        self.flood_use_direct_beam = sensitivity_center_method=='DirectBeam'
+        self.use_sample_beam_center =  sensitivity_center_method=='None'
+        self.flood_x_position = BaseScriptElement.getPropertyValue(alg, "SensitivityBeamCenterX",
+                                                                   default=Detector.flood_x_position)
+        self.flood_y_position = BaseScriptElement.getPropertyValue(alg, "SensitivityBeamCenterY",
+                                                                   default=Detector.flood_y_position)
+        self.flood_beam_file = BaseScriptElement.getPropertyValue(alg, "SensitivityBeamCenterFile", default='')
+        self.flood_beam_radius = BaseScriptElement.getPropertyValue(alg, "SensitivityBeamCenterRadius",
+                                                                   default=Detector.flood_beam_radius) 
+        
+        # Beam center
+        center_method = BaseScriptElement.getPropertyValue(alg, "BeamCenterMethod", default='None')
+        self.use_finder = center_method in ['DirectBeam', 'Scattering']
+        self.use_direct_beam = center_method=='DirectBeam'
+        self.x_position = BaseScriptElement.getPropertyValue(alg, "BeamCenterX",
+                                                                   default=Detector.x_position)
+        self.y_position = BaseScriptElement.getPropertyValue(alg, "BeamCenterY",
+                                                                   default=Detector.y_position)
+        self.beam_file = BaseScriptElement.getPropertyValue(alg, "BeamCenterFile", default='')
+        self.beam_radius = BaseScriptElement.getPropertyValue(alg, "BeamRadius",
+                                                                    default=Detector.beam_radius) 
+
     def reset(self):
         """
             Reset state
diff --git a/Code/Mantid/scripts/Interface/reduction_gui/reduction/sans/hfir_options_script.py b/Code/Mantid/scripts/Interface/reduction_gui/reduction/sans/hfir_options_script.py
index 1c2263b600aad939213885e9dfa97c0453da066f..7d8bf4463d4cf7ced2a26c9822da3da2f9eab9fd 100644
--- a/Code/Mantid/scripts/Interface/reduction_gui/reduction/sans/hfir_options_script.py
+++ b/Code/Mantid/scripts/Interface/reduction_gui/reduction/sans/hfir_options_script.py
@@ -4,8 +4,6 @@
     be used independently of the interface implementation
 """
 import xml.dom.minidom
-import copy
-import os
 from reduction_gui.reduction.scripter import BaseScriptElement
 
 class ReductionOptions(BaseScriptElement):
@@ -131,7 +129,7 @@ class ReductionOptions(BaseScriptElement):
         if not self.use_data_directory:
             script += "OutputPath(\"%s\")\n" % self.output_directory
         
-        return script           
+        return script
     
     def _normalization_options(self):
         """
@@ -213,12 +211,9 @@ class ReductionOptions(BaseScriptElement):
             Read in data from XML
             @param xml_str: text to read the data from
         """    
-        self.reset()   
+        self.reset()
         dom = xml.dom.minidom.parseString(xml_str)
         
-        # Get Mantid version
-        mtd_version = BaseScriptElement.getMantidBuildVersion(dom)
-        
         instrument_dom = dom.getElementsByTagName("Instrument")[0]
         self.nx_pixels = BaseScriptElement.getIntElement(instrument_dom, "nx_pixels",
                                                          default=ReductionOptions.nx_pixels) 
@@ -303,6 +298,77 @@ class ReductionOptions(BaseScriptElement):
             self.scaling_beam_diam = BaseScriptElement.getFloatElement(scale_dom, "scaling_beam_diam",
                                                                        default=ReductionOptions.scaling_beam_diam)
 
+    def from_setup_info(self, xml_str):
+        """
+            Read in data from XML using the string representation of the setup algorithm used
+            to prepare the reduction properties.
+            @param xml_str: text to read the data from
+        """
+        self.reset()
+        from mantid.api import Algorithm
+
+        dom = xml.dom.minidom.parseString(xml_str)
+        process_dom = dom.getElementsByTagName("SASProcess")[0]
+        setup_alg_str = BaseScriptElement.getStringElement(process_dom, 'SetupInfo')
+        alg=Algorithm.fromString(str(setup_alg_str))
+
+        self.sample_detector_distance = BaseScriptElement.getPropertyValue(alg, "SampleDetectorDistance", default=ReductionOptions.sample_detector_distance)
+        self.detector_offset = BaseScriptElement.getPropertyValue(alg, "SampleDetectorDistanceOffset", default=ReductionOptions.detector_offset)
+        self.wavelength = BaseScriptElement.getPropertyValue(alg, "Wavelength", default=ReductionOptions.wavelength)
+        self.wavelength_spread = BaseScriptElement.getPropertyValue(alg, "WavelengthSpread", default=ReductionOptions.wavelength_spread)
+        
+        self.solid_angle_corr = BaseScriptElement.getPropertyValue(alg, "SolidAngleCorrection", default = ReductionOptions.solid_angle_corr)
+        self.output_directory = BaseScriptElement.getPropertyValue(alg, "OutputDirectory", default = ReductionOptions.output_directory)
+        self.use_data_directory = not len(self.output_directory)>0
+        
+        # Dark current
+        self.dark_current_data = BaseScriptElement.getPropertyValue(alg, "DarkCurrentFile", default = '')
+        self.dark_current_corr = len(self.dark_current_data)>0
+
+        self.n_q_bins = BaseScriptElement.getPropertyValue(alg, "IQNumberOfBins", default=ReductionOptions.n_q_bins)
+        self.n_sub_pix = BaseScriptElement.getPropertyValue(alg, "NumberOfSubpixels", default=ReductionOptions.n_sub_pix)
+        self.log_binning = BaseScriptElement.getPropertyValue(alg, "IQLogBinning", default = ReductionOptions.log_binning)
+
+        # Normalization
+        norm_option = BaseScriptElement.getPropertyValue(alg, "Normalisation", default = 'Monitor')
+        self.normalization = ReductionOptions.normalization
+        if norm_option=='Timer':
+            self.normalization = ReductionOptions.NORMALIZATION_TIME
+        elif norm_option=='Monitor' or norm_option=='BeamProfileAndCharge':
+            self.normalization = ReductionOptions.NORMALIZATION_MONITOR
+        elif norm_option=='None':
+            self.normalization = ReductionOptions.NORMALIZATION_NONE
+        
+        # Mask
+        mask = BaseScriptElement.getPropertyValue(alg, "MaskedEdges", default = [])
+        if type(mask).__name__=='ndarray':
+            mask = mask.tolist()
+        if len(mask)==4:
+            self.top = mask[3]
+            self.bottom = mask[2]
+            self.right = mask[1]
+            self.left = mask[0]
+        self.detector_ids = BaseScriptElement.getPropertyValue(alg, "MaskedDetectorList", default=[])
+        if type(self.detector_ids).__name__=='ndarray':
+            self.detector_ids = self.detector_ids.tolist()
+        self.use_mask_file = len(self.detector_ids)>0
+
+        # Absolute scaling
+        scale_option = BaseScriptElement.getPropertyValue(alg, "AbsoluteScaleMethod", default = 'None')
+        self.calculate_scale = False
+        self.scaling_factor = 1.0
+        if scale_option=='Value':
+            self.scaling_factor = BaseScriptElement.getPropertyValue(alg, "AbsoluteScalingFactor", default=ReductionOptions.scaling_factor)
+        elif scale_option=='ReferenceData':
+            self.calculate_scale = True
+            self.scaling_direct_file = BaseScriptElement.getPropertyValue(alg, "AbsoluteScalingReferenceFilename")
+            self.scaling_att_trans = BaseScriptElement.getPropertyValue(alg, "AbsoluteScalingAttenuatorTrans", default=ReductionOptions.scaling_att_trans)
+            self.manual_beam_diam = False
+            if alg.existsProperty("AbsoluteScalingBeamDiameter"):
+                if not alg.getProperty("AbsoluteScalingBeamDiameter").isDefault:
+                    self.scaling_beam_diam = BaseScriptElement.getPropertyValue(alg, "AbsoluteScalingBeamDiameter", default=ReductionOptions.scaling_beam_diam)
+                    self.manual_beam_diam = True
+
     def reset(self):
         """
             Reset state
diff --git a/Code/Mantid/scripts/Interface/reduction_gui/reduction/sans/hfir_sample_script.py b/Code/Mantid/scripts/Interface/reduction_gui/reduction/sans/hfir_sample_script.py
index 11c101cbe222974fb29d513cf95cd300623d35b9..109f1b86f615e97237a1bcc31ffcf05768030276 100644
--- a/Code/Mantid/scripts/Interface/reduction_gui/reduction/sans/hfir_sample_script.py
+++ b/Code/Mantid/scripts/Interface/reduction_gui/reduction/sans/hfir_sample_script.py
@@ -4,7 +4,6 @@
     be used independently of the interface implementation
 """
 import xml.dom.minidom
-import copy
 import os
 from reduction_gui.reduction.scripter import BaseScriptElement 
 
@@ -62,15 +61,34 @@ class SampleData(BaseScriptElement):
                 self.sample_file = BaseScriptElement.getStringElement(instrument_dom, "sample_file")
                 self.direct_beam = BaseScriptElement.getStringElement(instrument_dom, "direct_beam")
                 self.beam_radius = BaseScriptElement.getFloatElement(instrument_dom, "beam_radius",
-                                                                     default=SampleData.DirectBeam.beam_radius)           
-        
+                                                                     default=SampleData.DirectBeam.beam_radius)
+
+        def from_setup_info(self, xml_str):
+            """
+                Read in data from XML using the string representation of the setup algorithm used
+                to prepare the reduction properties.
+                @param xml_str: text to read the data from
+            """
+            self.reset()
+            from mantid.api import Algorithm
+            dom = xml.dom.minidom.parseString(xml_str)
+            
+            process_dom = dom.getElementsByTagName("SASProcess")[0]
+            setup_alg_str = BaseScriptElement.getStringElement(process_dom, 'SetupInfo')
+            alg=Algorithm.fromString(str(setup_alg_str))
+            
+            self.sample_file = BaseScriptElement.getPropertyValue(alg, "TransmissionSampleDataFile", default='')
+            self.direct_beam = BaseScriptElement.getPropertyValue(alg, "TransmissionEmptyDataFile", default='')
+            self.beam_radius = BaseScriptElement.getPropertyValue(alg, "TransmissionBeamRadius", 
+                                                                  default=SampleData.DirectBeam.beam_radius)
+
         def reset(self):
             """
                 Reset state
             """
             self.sample_file = ''
             self.direct_beam = ''
-            self.beam_radius = SampleData.DirectBeam.beam_radius   
+            self.beam_radius = SampleData.DirectBeam.beam_radius
             
     class BeamSpreader(BaseScriptElement):
         sample_scatt = ''
@@ -128,9 +146,32 @@ class SampleData(BaseScriptElement):
                 self.direct_scatt = BaseScriptElement.getStringElement(instrument_dom, "direct_scatt")
                 self.direct_spreader = BaseScriptElement.getStringElement(instrument_dom, "direct_spreader")
                 self.spreader_trans = BaseScriptElement.getFloatElement(instrument_dom, "spreader_trans",
-                                                                     default=SampleData.BeamSpreader.spreader_trans)           
+                                                                     default=SampleData.BeamSpreader.spreader_trans)
                 self.spreader_trans_spread = BaseScriptElement.getFloatElement(instrument_dom, "spreader_trans_spread",
-                                                                     default=SampleData.BeamSpreader.spreader_trans_spread)           
+                                                                     default=SampleData.BeamSpreader.spreader_trans_spread)
+
+        def from_setup_info(self, xml_str):
+            """
+                Read in data from XML using the string representation of the setup algorithm used
+                to prepare the reduction properties.
+                @param xml_str: text to read the data from
+            """
+            self.reset()
+            from mantid.api import Algorithm
+            dom = xml.dom.minidom.parseString(xml_str)
+            
+            process_dom = dom.getElementsByTagName("SASProcess")[0]
+            setup_alg_str = BaseScriptElement.getStringElement(process_dom, 'SetupInfo')
+            alg=Algorithm.fromString(str(setup_alg_str))
+            
+            self.sample_scatt = BaseScriptElement.getPropertyValue(alg, "TransSampleScatteringFilename", default='')
+            self.sample_spreader = BaseScriptElement.getPropertyValue(alg, "TransSampleSpreaderFilename", default='')
+            self.direct_scatt = BaseScriptElement.getPropertyValue(alg, "TransDirectScatteringFilename", default='')
+            self.direct_spreader = BaseScriptElement.getPropertyValue(alg, "TransDirectSpreaderFilename", default='')
+            self.spreader_trans = BaseScriptElement.getPropertyValue(alg, "SpreaderTransmissionValue", 
+                                                                     default=SampleData.BeamSpreader.spreader_trans)
+            self.spreader_trans_spread = BaseScriptElement.getPropertyValue(alg, "SpreaderTransmissionError", 
+                                                                            default=SampleData.BeamSpreader.spreader_trans_spread)
 
         def reset(self):
             """
@@ -140,8 +181,8 @@ class SampleData(BaseScriptElement):
             self.sample_spreader = ''
             self.direct_scatt = ''
             self.direct_spreader = ''
-            self.spreader_trans = SampleData.BeamSpreader.spreader_trans           
-            self.spreader_trans_spread = SampleData.BeamSpreader.spreader_trans_spread     
+            self.spreader_trans = SampleData.BeamSpreader.spreader_trans
+            self.spreader_trans_spread = SampleData.BeamSpreader.spreader_trans_spread
 
     transmission = 1.0
     transmission_spread = 0.0
@@ -155,7 +196,7 @@ class SampleData(BaseScriptElement):
     data_files = []
     separate_jobs = False
 
-     # Option list
+    # Option list
     option_list = [DirectBeam, BeamSpreader]
     
     def get_data_file_list(self):
@@ -245,7 +286,7 @@ class SampleData(BaseScriptElement):
         xml += "  <separate_jobs>%s</separate_jobs>\n" % str(self.separate_jobs)
         xml += "  <sample_thickness>%g</sample_thickness>\n" % self.sample_thickness
         for item in self.data_files:
-            xml += "  <data_file>%s</data_file>\n" % item.strip()        
+            xml += "  <data_file>%s</data_file>\n" % item.strip()
         xml += "</SampleData>\n"
 
         return xml
@@ -255,19 +296,16 @@ class SampleData(BaseScriptElement):
             Read in data from XML
             @param xml_str: text to read the data from
         """   
-        self.reset()    
+        self.reset()
         dom = xml.dom.minidom.parseString(xml_str)
         
-        # Get Mantid version
-        mtd_version = BaseScriptElement.getMantidBuildVersion(dom)
-
         element_list = dom.getElementsByTagName("Transmission")
         if len(element_list)>0:
-            instrument_dom = element_list[0]      
+            instrument_dom = element_list[0]
             self.transmission = BaseScriptElement.getFloatElement(instrument_dom, "trans",
-                                                                  default=SampleData.transmission)      
+                                                                  default=SampleData.transmission)
             self.transmission_spread = BaseScriptElement.getFloatElement(instrument_dom, "trans_spread",
-                                                                  default=SampleData.transmission_spread)  
+                                                                  default=SampleData.transmission_spread)
             self.calculate_transmission = BaseScriptElement.getBoolElement(instrument_dom, "calculate_trans",
                                                                            default = SampleData.calculate_transmission)
             self.theta_dependent = BaseScriptElement.getBoolElement(instrument_dom, "theta_dependent",
@@ -284,20 +322,55 @@ class SampleData(BaseScriptElement):
         # Data file section
         element_list = dom.getElementsByTagName("SampleData")
         if len(element_list)>0:
-            sample_data_dom = element_list[0]      
+            sample_data_dom = element_list[0]
             self.data_files = BaseScriptElement.getStringList(sample_data_dom, "data_file")
             self.sample_thickness = BaseScriptElement.getFloatElement(sample_data_dom, "sample_thickness",
-                                                                      default=SampleData.sample_thickness)      
+                                                                      default=SampleData.sample_thickness)
             self.separate_jobs = BaseScriptElement.getBoolElement(sample_data_dom, "separate_jobs",
                                                                   default = SampleData.separate_jobs) 
 
-    
+    def from_setup_info(self, xml_str):
+        """
+            Read in data from XML using the string representation of the setup algorithm used
+            to prepare the reduction properties.
+            @param xml_str: text to read the data from
+        """
+        self.reset()
+        from mantid.api import Algorithm
+        dom = xml.dom.minidom.parseString(xml_str)
+        
+        process_dom = dom.getElementsByTagName("SASProcess")[0]
+        setup_alg_str = BaseScriptElement.getStringElement(process_dom, 'SetupInfo')
+        alg=Algorithm.fromString(str(setup_alg_str))
+        
+        # Transmission
+        self.transmission = BaseScriptElement.getPropertyValue(alg, "TransmissionValue", default=SampleData.transmission)
+        self.transmission_spread = BaseScriptElement.getPropertyValue(alg, "TransmissionError", default=SampleData.transmission_spread)
+        self.dark_current = BaseScriptElement.getPropertyValue(alg, "TransmissionDarkCurrentFile", default='')
+        self.theta_dependent = BaseScriptElement.getPropertyValue(alg, "ThetaDependentTransmission",
+                                                                  default = SampleData.theta_dependent)
+        self.sample_thickness = BaseScriptElement.getPropertyValue(alg, "SampleThickness",
+                                                                   default = SampleData.sample_thickness)
+
+        trans_method = BaseScriptElement.getPropertyValue(alg, "TransmissionMethod", default='Value')
+        
+        self.calculate_transmission = trans_method in ['DirectBeam', 'BeamSpreader']
+        if trans_method=='DirectBeam':
+            self.calculation_method = SampleData.DirectBeam()
+            self.calculation_method.from_setup_info(xml_str)
+        elif trans_method=='BeamSpreader':
+            self.calculation_method = SampleData.BeamSpreader()
+            self.calculation_method.from_setup_info(xml_str)
+
+        # Data file section
+        self.data_files = [BaseScriptElement.getStringElement(process_dom, 'Filename', '')]
+
     def reset(self):
         """
             Reset state
         """
-        self.transmission = SampleData.transmission      
-        self.transmission_spread = SampleData.transmission_spread  
+        self.transmission = SampleData.transmission
+        self.transmission_spread = SampleData.transmission_spread
         self.calculate_transmission = SampleData.calculate_transmission
         self.calculation_method = SampleData.calculation_method
         self.theta_dependent = SampleData.theta_dependent
diff --git a/Code/Mantid/scripts/Interface/reduction_gui/reduction/scripter.py b/Code/Mantid/scripts/Interface/reduction_gui/reduction/scripter.py
index 5c1c5e3ed0571570a688f79f411cb8f6c71c2e36..e10b8213bd1a9d98f932f1cea8a0ad90937ce67f 100644
--- a/Code/Mantid/scripts/Interface/reduction_gui/reduction/scripter.py
+++ b/Code/Mantid/scripts/Interface/reduction_gui/reduction/scripter.py
@@ -7,7 +7,7 @@ try:
     from mantid.kernel import ConfigService, Logger, version_str
     HAS_MANTID = True
 except:
-    HAS_MANTID = False  
+    HAS_MANTID = False
 
 try:
     import mantidplot
@@ -21,8 +21,6 @@ import time
 import platform
 import re
 import os
-import stat
-import traceback
 
 class BaseScriptElement(object):
     """
@@ -110,7 +108,7 @@ class BaseScriptElement(object):
         for node in nodelist:
             if node.nodeType == node.TEXT_NODE:
                 rc = rc + node.data
-        return rc       
+        return rc
 
     @classmethod
     def getContent(cls, dom, tag):
@@ -167,7 +165,7 @@ class BaseScriptElement(object):
         if len(element_list)>0:
             for l in element_list:
                 elem_list.append(BaseScriptElement.getText(l.childNodes).strip())
-        return elem_list    
+        return elem_list
 
     @classmethod
     def getBoolElement(cls, dom, tag, true_tag='true', default=False):
@@ -192,6 +190,24 @@ class BaseScriptElement(object):
                 return change_set
         return -1
 
+    @classmethod
+    def getPropertyValue(cls, algorithm, property_name, default=None):
+        """
+            Look up the property of a Mantid algorithm object and return
+            its value or the specified default
+            @param algorithm: Mantid algorithm object
+            @param property_name: name of the property
+            @param default: default value to return
+        """
+        if algorithm.existsProperty(property_name):
+            prop = algorithm.getProperty(property_name)
+            # If we have a number and it's very close to the maximum value we
+            # can handle, treat is as an EMPTY_DBL
+            if prop.type=='number' and prop.value>sys.float_info.max/10.0:
+                return default
+            return prop.value
+        return default
+    
     @classmethod
     def addElementToSection(cls, xml_str, parent_name, tag, content=None):
         """
@@ -332,28 +348,39 @@ class BaseReductionScripter(object):
         for item in self._observers:
             item.push()
 
-    def verify_instrument(self, file_name):
+    def verify_instrument(self, file_name, id_element=None):
         """
             Verify that the current scripter object is of the right 
             class for a given data file
             @param file_name: name of the file to check 
+            @param id_element: element name used to distinguish between formats
         """
         f = open(file_name, 'r')
         xml_str = f.read()
         dom = xml.dom.minidom.parseString(xml_str)
         element_list = dom.getElementsByTagName("Reduction")
         if len(element_list)>0:
-            instrument_dom = element_list[0]       
+            instrument_dom = element_list[0]
             found_name = BaseScriptElement.getStringElement(instrument_dom, 
                                                             "instrument_name", 
                                                             default=self.instrument_name).strip()
+            # If we have an ID element and it can't be found, return None
+            if id_element is not None:
+                id_list = dom.getElementsByTagName(id_element)
+                if len(id_list)==0:
+                    return None
             return found_name
         else:
             raise RuntimeError, "The format of the provided file is not recognized"
 
-    def check_xml_compatibility(self, file_name):
+    def check_xml_compatibility(self, file_name, id_element=None):
+        """
+            Check that an xml file is compatible with the current instrument
+            @param file_name: path of the file to check
+            @param id_element: if specified, we will check that an element of that name exists
+        """
         try:
-            instr = self.verify_instrument(file_name)
+            instr = self.verify_instrument(file_name, id_element=id_element)
             return instr==self.instrument_name
         except:
             # Could not load file or identify it's instrument
@@ -398,7 +425,7 @@ class BaseReductionScripter(object):
             f.write(content)
             f.close()
         
-    def from_xml(self, file_name):
+    def from_xml(self, file_name, use_setup_info=False):
         """
             Read in reduction parameters from XML
             @param file_name: name of the XML file to read
@@ -407,7 +434,10 @@ class BaseReductionScripter(object):
         xml_str = f.read()
         for item in self._observers:
             if item.state() is not None:
-                item.state().from_xml(xml_str)
+                if use_setup_info is False:
+                    item.state().from_xml(xml_str)
+                elif hasattr(item.state(), 'from_setup_info'):
+                    item.state().from_setup_info(xml_str)
 
     def to_script(self, file_name=None):
         """
diff --git a/Code/Mantid/scripts/Interface/ui/reflectometer/refl_gui.py b/Code/Mantid/scripts/Interface/ui/reflectometer/refl_gui.py
index c5a419f8f51e3e70d99d64e23758651b4d25c5f6..cbc30f492b3df94cb2a5a4c65c0072b324ec0716 100644
--- a/Code/Mantid/scripts/Interface/ui/reflectometer/refl_gui.py
+++ b/Code/Mantid/scripts/Interface/ui/reflectometer/refl_gui.py
@@ -338,7 +338,23 @@ class ReflGui(QtGui.QMainWindow, refl_window.Ui_windowRefl):
         self.actionCopy.triggered.connect(self._copy_cells)
         self.actionChoose_Columns.triggered.connect(self._choose_columns)
         self.actionRefl_Gui_Options.triggered.connect(self._options_dialog)
-
+        
+        
+    def __valid_rb(self):
+        # Ensure that you cannot put zero in for an rb search
+        rbSearchValidator = QtGui.QIntValidator(self)
+        current_text = self.textRB.text()
+        rbSearchValidator.setBottom(1)
+        state = rbSearchValidator.validate(current_text, 0)[0]
+        if state == QtGui.QValidator.Acceptable:
+            return True
+        else:
+            self.textRB.clear()
+            if current_text:
+                logger.warning("RB search restricted to numbers > 0")
+            return False
+        
+ 
     def _populate_runs_list(self):
         """
         Populate the list at the right with names of runs and workspaces from the ADS and archives
@@ -349,7 +365,7 @@ class ReflGui(QtGui.QMainWindow, refl_window.Ui_windowRefl):
         if self.ads_get:
             self._populate_runs_listADSWorkspaces()
         
-        if self.textRB.text():
+        if self.__valid_rb():
                   
             if self.__icat_search:
                 """
@@ -402,7 +418,7 @@ class ReflGui(QtGui.QMainWindow, refl_window.Ui_windowRefl):
                     elif not self.__instrumentRuns.getInstrument() == selectedInstrument:
                         self.__instrumentRuns =  LatestISISRuns(selectedInstrument)
                         self.spinDepth.setMaximum(self.__instrumentRuns.getNumCycles())
-                    if self.textRB.text():
+                    if self.__valid_rb():
                         runs = []
                         self.statusMain.showMessage("Searching Journals for RB number: " + self.textRB.text())
                         
diff --git a/Code/Mantid/scripts/SANS/SANSadd2.py b/Code/Mantid/scripts/SANS/SANSadd2.py
index f3116d0a0dbccb5e8998c21282915cd93fdc206a..7f3caa5d9a02b682d55d46bc743d2808b96e9877 100644
--- a/Code/Mantid/scripts/SANS/SANSadd2.py
+++ b/Code/Mantid/scripts/SANS/SANSadd2.py
@@ -268,9 +268,9 @@ def _isType(ext, allTypes):
 
 def _copyLog(lastPath, logFile, pathout):
   try :
-    logFile = lastPath+'/'+logFile
+    logFile = os.path.join(lastPath, logFile)
     if os.path.exists(logFile):
-        copyfile(logFile, pathout+'/'+os.path.basename(logFile))
+        copyfile(logFile, os.path.join(pathout, os.path.basename(logFile)))
     else:
         logger.notice("Could not find log file %s" % logFile)
   except Exception, reason:
diff --git a/Code/Mantid/scripts/SANS/isis_instrument.py b/Code/Mantid/scripts/SANS/isis_instrument.py
index 60aedf78b72a86b33dab57283708a4882a80a855..5271cd686ac23ddaff6ddbe9d8a9b4f0b7ca5c35 100644
--- a/Code/Mantid/scripts/SANS/isis_instrument.py
+++ b/Code/Mantid/scripts/SANS/isis_instrument.py
@@ -24,7 +24,7 @@ class BaseInstrument(object):
             instr_filen = self._NAME+'_Definition.xml'
             
         config = ConfigService.Instance()
-        self._definition_file = config["instrumentDefinition.directory"]+'/'+instr_filen
+        self._definition_file = os.path.join(config["instrumentDefinition.directory"], instr_filen)
 
         inst_ws_name = self.load_empty()
         self.definition = AnalysisDataService.retrieve(inst_ws_name).getInstrument()
@@ -770,8 +770,7 @@ class LOQ(ISISInstrument):
         """
             Loads information about the setup used for LOQ transmission runs
         """
-        trans_definition_file = config.getString('instrumentDefinition.directory')
-        trans_definition_file += '/'+self._NAME+'_trans_Definition.xml'
+        trans_definition_file = os.path.join(config.getString('instrumentDefinition.directory'), self._NAME+'_trans_Definition.xml')
         LoadInstrument(Workspace=ws_trans,Filename= trans_definition_file, RewriteSpectraMap=False)
         LoadInstrument(Workspace=ws_direct, Filename = trans_definition_file, RewriteSpectraMap=False)
 
diff --git a/Code/Mantid/scripts/SANS/isis_reduction_steps.py b/Code/Mantid/scripts/SANS/isis_reduction_steps.py
index c1b2ab56f8e621355b598c7b543eaf12b7345418..6862db073f1542e5ced129108c9a38795c186dfd 100644
--- a/Code/Mantid/scripts/SANS/isis_reduction_steps.py
+++ b/Code/Mantid/scripts/SANS/isis_reduction_steps.py
@@ -1515,10 +1515,6 @@ class CalculateNormISIS(object):
     def  __init__(self, wavelength_deps=[]):
         super(CalculateNormISIS, self).__init__()
         self._wave_steps = wavelength_deps
-        #algorithm to be used to load pixel correction files
-        self._load='LoadRKH'
-        #a parameters string to add as the last argument to the above algorithm
-        self._load_params='FirstColumnValue="SpectrumNumber"'
         self._high_angle_pixel_file = ""
         self._low_angle_pixel_file = ""
         self._pixel_file = ""
@@ -1571,20 +1567,18 @@ class CalculateNormISIS(object):
         return wave_adj
 
     def _loadPixelCorrection(self):
-        # read pixel correction file
-        # note the python code below is an attempt to emulate function overloading
-        # If a derived class overwrite self._load and self._load_params then 
-        # a custom specific loading can be achieved 
-        pixel_adj = ''
+        '''
+        Reads in a pixel correction file if one has been specified.
+        
+        @return the name of the workspace, else an empty string if there was no
+                correction file.
+        '''
         if self._pixel_file:
-            pixel_adj = self.PIXEL_CORR_NAME
-            load_com = self._load+'(Filename="'+self._pixel_file+'",OutputWorkspace="'+pixel_adj+'"'
-            if self._load_params:
-                load_com  += ','+self._load_params
-            load_com += ')'
-            eval(load_com)
-
-        return pixel_adj
+            LoadRKH(Filename=self._pixel_file,
+                    OutputWorkspace=self.PIXEL_CORR_NAME,
+                    FirstColumnValue="SpectrumNumber")
+            return self.PIXEL_CORR_NAME
+        return ''
 
     def _is_point_data(self, wksp):
         """
@@ -2258,7 +2252,7 @@ class UserFile(ReductionStep):
                     idx = filepath.rfind(']')
                     filepath = filepath[idx + 1:]
                 if not os.path.isabs(filepath):
-                    filepath = reducer.user_file_path+'/'+filepath
+                    filepath = os.path.join(reducer.user_file_path, filepath)
 
                 # If a filepath has been provided, then it must exist to continue.
                 if filepath and not os.path.isfile(filepath):
diff --git a/Code/Mantid/scripts/reduction_workflow/instruments/sans/sns_command_interface.py b/Code/Mantid/scripts/reduction_workflow/instruments/sans/sns_command_interface.py
index a46622e9e27542c0382f4605df2d03858f298c65..0a45b120072995e66a1ff832171702a8bd161332 100644
--- a/Code/Mantid/scripts/reduction_workflow/instruments/sans/sns_command_interface.py
+++ b/Code/Mantid/scripts/reduction_workflow/instruments/sans/sns_command_interface.py
@@ -74,6 +74,9 @@ def SetTOFTailsCutoff(low_cut=0.0, high_cut=0.0):
 def UseConfigTOFTailsCutoff(use_config=True):
     ReductionSingleton().reduction_properties["UseConfigTOFCuts"]=use_config
     
+def SkipTOFCorrection(skip=True):
+    ReductionSingleton().reduction_properties["SkipTOFCorrection"]=skip
+    
 def UseConfigMask(use_config=True):
     ReductionSingleton().reduction_properties["UseConfigMask"]=use_config
     
diff --git a/Code/Mantid/scripts/test/ExtendedUnitCellTest.py b/Code/Mantid/scripts/test/ExtendedUnitCellTest.py
deleted file mode 100644
index 9e571be9f4940864ecaabbf5cd43b3757a3e20b8..0000000000000000000000000000000000000000
--- a/Code/Mantid/scripts/test/ExtendedUnitCellTest.py
+++ /dev/null
@@ -1,94 +0,0 @@
-import unittest
-import math
-from mantid.simpleapi import *
-from CrystalTools.ExtendedUnitCell import *
-
-def toDegrees(angleInRads):
-        return angleInRads*180/math.pi
-    
-class ExtendedUnitCellTest(unittest.TestCase):
-    
-    # Miller indices of reflections comprising the horizontal plane.
-    recDir1 = [1, 0, 0]
-    recDir2 = [0, 0, 1]
-    
-    decimalPlaces = 6
-    
-    def test_creation(self):
-         a = b = c = 1
-         alpha = beta = gamma = 90
-         cell = createFromLatticeParameters(a, b, c, alpha, beta, gamma)
-         self.assertTrue(isinstance(cell, ExtendedUnitCell))
-         # Check that we can access some sample base methods.
-         self.assertEquals(a, cell.a())
-         self.assertEquals(b, cell.b())
-         self.assertEquals(c, cell.c())
-         self.assertEquals(alpha, cell.alpha())
-         self.assertEquals(beta, cell.beta())
-         self.assertEquals(gamma, cell.gamma())
-         
-    def test_create_from_existing(self):
-        baseCell = UnitCell(1,1,1,90,90,90)
-        extendedCell = ExtendedUnitCell(baseCell)
-        self.assertTrue(isinstance(extendedCell, ExtendedUnitCell))
-         
-    def test_inplane_reflections_111(self):
-        a = b = c = 1
-        alpha = beta = gamma = 90
-        cell = createFromLatticeParameters(a, b, c, alpha, beta, gamma)
-        x, y, z = cell.recAnglesFromReflections(self.recDir1, self.recDir2, [1,1,1])
-        
-        self.assertEquals(toDegrees( math.acos(1/math.sqrt(3))), x)
-        self.assertEquals(toDegrees( math.acos(1/math.sqrt(3))), y)
-        self.assertEquals(toDegrees( math.acos(1/math.sqrt(3))), z)
-     
-    def test_inplane_reflections_211(self):
-        a = b = c = 1
-        alpha = beta = gamma = 90
-        cell = createFromLatticeParameters(a, b, c, alpha, beta, gamma)
-        x, y, z = cell.recAnglesFromReflections(self.recDir1, self.recDir2, [2,1,1])
-        
-        self.assertAlmostEqual(toDegrees( math.acos(math.sqrt(4)/math.sqrt(6))), x, self.decimalPlaces)
-        self.assertAlmostEqual(toDegrees( math.acos(math.sqrt(1)/math.sqrt(6))), y, self.decimalPlaces)
-        self.assertAlmostEqual(toDegrees( math.acos(math.sqrt(1)/math.sqrt(6))), z, self.decimalPlaces)
-
-    def test_inplane_reflections_311(self):
-        a = b = c = 1
-        alpha = beta = gamma = 90
-        cell = createFromLatticeParameters(a, b, c, alpha, beta, gamma)
-        x, y, z = cell.recAnglesFromReflections(self.recDir1, self.recDir2, [3,1,1])
-        
-        self.assertAlmostEqual(toDegrees( math.acos(math.sqrt(9)/math.sqrt(11))), x, self.decimalPlaces)
-        self.assertAlmostEqual(toDegrees( math.acos(math.sqrt(1)/math.sqrt(11))), y, self.decimalPlaces)
-        self.assertAlmostEqual(toDegrees( math.acos(math.sqrt(1)/math.sqrt(11))), z, self.decimalPlaces)
-
-         
-    def test_inplane_reflections_311_other_horizontal_plane(self):
-        a = b = c = 1
-        alpha = beta = gamma = 90
-        cell = createFromLatticeParameters(a, b, c, alpha, beta, gamma)
-        
-        # Definition of the horizontal plane
-        recDir1 = [0,0,1] 
-        recDir2 = [0,1,0]
-        
-        x, y, z = cell.recAnglesFromReflections(recDir1, recDir2, [3,1,1])
-        
-        self.assertAlmostEqual(toDegrees( math.acos(math.sqrt(1)/math.sqrt(11))), x, self.decimalPlaces)
-        self.assertAlmostEqual(toDegrees( math.acos(math.sqrt(1)/math.sqrt(11))), y, self.decimalPlaces)
-        self.assertAlmostEqual(toDegrees( math.acos(math.sqrt(9)/math.sqrt(11))), z, self.decimalPlaces)
-        
-    def test_inplane_reflections_111_othorombiccell(self):
-        a = b = 1
-        c = 2
-        alpha = beta = gamma = 90
-        cell = createFromLatticeParameters(a, b, c, alpha, beta, gamma)
-        
-        x, y, z = cell.recAnglesFromReflections(self.recDir1, self.recDir2, [1,1,1])
-        
-        self.assertTrue(math.acos(math.sqrt(4)/math.sqrt(6)), x)
-        self.assertTrue(math.acos(math.sqrt(1)/math.sqrt(6)), y)
-        self.assertTrue(math.acos(math.sqrt(1)/math.sqrt(6)), z)
-
-if __name__ == '__main__':
-    unittest.main()
\ No newline at end of file
diff --git a/Code/Mantid/scripts/test/IndirectCommonTests.py b/Code/Mantid/scripts/test/IndirectCommonTests.py
new file mode 100644
index 0000000000000000000000000000000000000000..5edbec178b75ae62d70b4f5184ccb8dc738b1cd0
--- /dev/null
+++ b/Code/Mantid/scripts/test/IndirectCommonTests.py
@@ -0,0 +1,429 @@
+"""Test suite for the utility functions in the IndirectCommon script file
+
+These scripts are used by the ISIS Indirect geometry interfaces such as Indirect Convert to Energy,
+Data Analysis, and Bayes.   
+"""
+import os
+import unittest
+import numpy as np
+
+from mantid.simpleapi import *
+import IndirectCommon as indirect_common
+
+class IndirectCommonTests(unittest.TestCase):
+
+    _default_config = {}
+
+    def setUp(self):
+        self._config_defaults = config
+
+    def tearDown(self):
+        config = self._config_defaults
+
+    def test_loadInst(self):
+        indirect_common.loadInst('IRIS')
+
+        ws_name = '__empty_IRIS'
+        ws = mtd[ws_name]
+        instrument = ws.getInstrument()
+        self.assertEqual(instrument.getName(), 'IRIS')
+
+    def test_loadNexus(self):
+        ws_name = indirect_common.loadNexus('IRS26173_ipg.nxs')
+        self.assertEqual(ws_name, 'IRS26173_ipg')
+        self.assertTrue(mtd.doesExist(ws_name))
+
+    def test_getInstrRun_from_name(self):
+        ws = self.make_dummy_QENS_workspace()
+        (instrument, run_number) = indirect_common.getInstrRun(ws)
+
+        self.assertEqual(run_number, '1')
+        self.assertEqual(instrument, 'irs')
+
+    def test_getInstrRun_from_workspace(self):
+        ws = self.make_dummy_QENS_workspace(add_logs=False)
+        ws = RenameWorkspace(ws, OutputWorkspace="IRS26173")
+
+        (instrument, run_number) = indirect_common.getInstrRun(ws.name())
+
+        self.assertEqual(run_number, '26173')
+        self.assertEqual(instrument, 'irs')
+
+    def test_getInstrRun_failure(self):
+        ws = self.make_dummy_QENS_workspace(add_logs=False)
+        self.assertRaises(RuntimeError, indirect_common.getInstrRun, ws)
+
+    def test_getWSprefix_ISIS(self):
+        config['default.facility'] = 'ISIS'
+        ws = self.make_dummy_QENS_workspace()
+
+        ws_name = indirect_common.getWSprefix(ws)
+
+        self.assertEqual(ws_name, 'irs1_graphite002_', 
+                        "The workspace prefix does not match the expected value")
+
+    def test_getWSprefix_ILL(self):
+        config['default.facility'] = 'ILL'
+        ws = self.make_dummy_QENS_workspace(instrument_name='IN16B')
+
+        ws_name = indirect_common.getWSprefix(ws)
+
+        self.assertEqual(ws_name, 'in16b_1_',
+                         "The workspace prefix does not match the expected value")
+
+    def test_getEFixed(self):
+        ws = CreateSampleWorkspace()
+        ws = self.load_instrument(ws,'IRIS')
+
+        e_fixed = indirect_common.getEfixed(ws.name())
+        self.assertEqual(e_fixed, 1.8450, 
+                         "The EFixed value does not match the expected value")
+
+    def test_getEFixed_failure(self):
+        ws = CreateSampleWorkspace()
+        self.assertRaises(IndexError, indirect_common.getEfixed, ws.name())
+
+    def test_getDefaultWorkingDirectory(self):
+        config['defaultsave.directory'] = os.path.expanduser('~')
+        workdir = indirect_common.getDefaultWorkingDirectory()
+        self.assertEquals(os.path.expanduser('~'), workdir, 
+                          "The working directory does not match the expected one")
+
+    def test_getDefaultWorkingDirectory_failure(self):
+        config['defaultsave.directory'] = ''
+        self.assertRaises(IOError, indirect_common.getDefaultWorkingDirectory)
+
+    def test_createQaxis(self):
+        ws = self.make_dummy_QENS_workspace()
+        expected_result = [0.48372274526965614, 0.5253047207470043, 0.5667692111215948, 0.6079351677527526, 0.6487809073399486]
+        actual_result = indirect_common.createQaxis(ws)
+        self.assert_lists_match(expected_result, actual_result)        
+
+    def test_GetWSangles(self):
+        ws = self.make_dummy_QENS_workspace()
+        expected_result = [29.700000000000006, 32.32, 34.949999999999996, 37.58, 40.209999999999994]
+        actual_result = indirect_common.GetWSangles(ws)
+        self.assert_lists_match(expected_result, actual_result)
+
+    def test_GetThetaQ(self):
+        ws = self.make_dummy_QENS_workspace()
+        expected_theta_result = [29.700000000000006, 32.32, 34.949999999999996, 37.58, 40.209999999999994]
+        expected_Q_result = [0.48372274526965625, 0.5253047207470042, 0.5667692111215948, 0.6079351677527525, 0.6487809073399485]
+        actual_theta_result, actual_Q_result =  indirect_common.GetThetaQ(ws)
+        self.assert_lists_match(expected_theta_result, actual_theta_result)
+        self.assert_lists_match(expected_Q_result, actual_Q_result)
+
+    def test_ExtractFloat(self):
+        data = "0.0 1 .2 3e-3 4.3 -5.5 6.0"
+        expected_result = [0, 1, 0.2, 3e-3, 4.3, -5.5, 6.0]
+        actual_result = indirect_common.ExtractFloat(data)
+        self.assert_lists_match(expected_result, actual_result)
+
+    def test_ExtractInt(self):
+        data = "-2 -1 0 1 2 3 4 5"
+        expected_result = [-2, -1, 0, 1, 2, 3, 4, 5]
+        actual_result = indirect_common.ExtractInt(data)
+        self.assert_lists_match(expected_result, actual_result)
+
+    def test_PadArray(self):
+        data = [0,1,2,3,4,5]
+        expected_result = [0,1,2,3,4,5,0,0,0,0]
+        actual_result = indirect_common.PadArray(data, 10)
+        self.assert_lists_match(expected_result, actual_result)
+
+    def test_CheckAnalysers(self):
+        ws1 = self.make_dummy_QENS_workspace(output_name="ws1")
+        ws2 = self.make_dummy_QENS_workspace(output_name="ws2")
+        
+        self.assert_does_not_raise(ValueError, indirect_common.CheckAnalysers, ws1, ws2, True)
+
+    def test_CheckAnalysers_fails_on_analyser_mismatch(self):
+        ws1 = self.make_dummy_QENS_workspace(output_name="ws1", analyser='graphite')
+        ws2 = self.make_dummy_QENS_workspace(output_name="ws2", analyser='fmica')
+
+        self.assertRaises(ValueError, indirect_common.CheckAnalysers, ws1, ws2, True)
+
+    def test_CheckAnalysers_fails_on_reflection_mismatch(self):
+        ws1 = self.make_dummy_QENS_workspace(output_name="ws1", reflection='002')
+        ws2 = self.make_dummy_QENS_workspace(output_name="ws2", reflection='004')
+
+        self.assertRaises(ValueError, indirect_common.CheckAnalysers, ws1, ws2, True)
+
+    def test_CheckHistZero(self):
+        ws = self.make_dummy_QENS_workspace()
+        self.assert_does_not_raise(ValueError, indirect_common.CheckHistZero, ws)
+
+    def test_CheckHistSame(self):
+        ws1 = self.make_dummy_QENS_workspace(output_name='ws1')
+        ws2 = self.make_dummy_QENS_workspace(output_name='ws2')
+        self.assert_does_not_raise(ValueError, indirect_common.CheckHistSame, ws1, 'ws1', ws2, 'ws2')
+
+    def test_CheckHistSame_fails_on_x_range_mismatch(self):
+        ws1 = self.make_dummy_QENS_workspace(output_name='ws1')
+        ws2 = self.make_dummy_QENS_workspace(output_name='ws2')
+        CropWorkspace(ws2, XMin=10, OutputWorkspace=ws2)
+
+        self.assertRaises(ValueError, indirect_common.CheckHistSame, ws1, 'ws1', ws2, 'ws2')
+
+    def test_CheckHistSame_fails_on_spectrum_range_mismatch(self):
+        ws1 = self.make_dummy_QENS_workspace(output_name='ws1')
+        ws2 = self.make_dummy_QENS_workspace(output_name='ws2')
+        CropWorkspace(ws2, StartWorkspaceIndex=2, OutputWorkspace=ws2)
+
+        self.assertRaises(ValueError, indirect_common.CheckHistSame, ws1, 'ws1', ws2, 'ws2')
+
+    def test_CheckXrange(self):
+        x_range = [1,10]
+        self.assert_does_not_raise(ValueError, indirect_common.CheckXrange, x_range, 'A Range')
+
+    def test_CheckXrange_with_two_ranges(self):
+        x_range = [1,10,15,20]
+        self.assert_does_not_raise(ValueError, indirect_common.CheckXrange, x_range, 'A Range')
+
+    def test_CheckXrange_lower_close_to_zero(self):
+        x_range = [-5,0]
+        self.assertRaises(ValueError, indirect_common.CheckXrange, x_range, 'A Range')
+
+    def test_CheckXrange_upper_close_to_zero(self):
+        x_range = [0,5]
+        self.assertRaises(ValueError, indirect_common.CheckXrange, x_range, 'A Range')
+
+    def test_CheckXrange_invalid_range(self):
+        x_range = [10,5]
+        self.assertRaises(ValueError, indirect_common.CheckXrange, x_range, 'A Range')
+
+    def test_CheckElimits(self):
+        energy_range = [-0.5, 0.5]
+        x_range = np.arange(-0.6, 0.61, 0.01)
+        self.assert_does_not_raise(ValueError, indirect_common.CheckElimits, energy_range, x_range)
+
+    def test_CheckElimits_lower_bound(self):
+        energy_range = [-0.5, 0.4]
+        x_range = np.arange(-0.49, 0.5, 0.01)
+        self.assertRaises(ValueError, indirect_common.CheckElimits, energy_range, x_range)
+
+    def test_CheckElimits_upper_bound(self):
+        energy_range = [-0.5, 0.5]
+        x_range = np.arange(-0.5, 0.5, 0.01)
+        self.assertRaises(ValueError, indirect_common.CheckElimits, energy_range, x_range)
+
+    def test_CheckElimits_invalid_range(self):
+        energy_range = [0.5, -0.5]
+        x_range = np.arange(-0.5, 0.51, 0.01)
+        self.assertRaises(ValueError, indirect_common.CheckElimits, energy_range, x_range)
+
+    def test_convertToElasticQ(self):
+        ws = self.make_dummy_QENS_workspace()
+        indirect_common.convertToElasticQ(ws)
+        self.assert_workspace_units_match_expected('MomentumTransfer', ws)
+        self.assert_has_numeric_axis(ws)
+
+    def test_convertToElasticQ_output_in_different_workspace(self):
+        ws = self.make_dummy_QENS_workspace()
+        output_workspace = 'ws2'
+        indirect_common.convertToElasticQ(ws, output_ws=output_workspace)
+
+        #check original wasn't modified
+        self.assert_workspace_units_match_expected('Label', ws)
+        self.assert_has_spectrum_axis(ws)
+
+        #check new workspace matches what we expect
+        self.assert_workspace_units_match_expected('MomentumTransfer', output_workspace)
+        self.assert_has_numeric_axis(output_workspace)
+
+    def test_convertToElasticQ_workspace_already_in_Q(self):
+        ws = self.make_dummy_QENS_workspace()
+        e_fixed = indirect_common.getEfixed(ws)
+        ConvertSpectrumAxis(ws,Target='ElasticQ',EMode='Indirect',EFixed=e_fixed,OutputWorkspace=ws)
+
+        indirect_common.convertToElasticQ(ws)
+
+        self.assert_workspace_units_match_expected('MomentumTransfer', ws)
+        self.assert_has_numeric_axis(ws)
+
+    def test_convertToElasticQ_with_numeric_axis_not_in_Q(self):
+        ws = self.make_dummy_QENS_workspace()
+
+        #convert spectrum axis to units of Q
+        e_fixed = indirect_common.getEfixed(ws)
+        ConvertSpectrumAxis(ws,Target='ElasticQ',EMode='Indirect',EFixed=e_fixed,OutputWorkspace=ws)
+        #set the units to be something we didn't expect
+        unit = mtd[ws].getAxis(1).setUnit("Label")
+        unit.setLabel('Random Units', '')
+
+        self.assertRaises(RuntimeError, indirect_common.convertToElasticQ, ws)
+
+    def test_transposeFitParametersTable(self):
+        ws = self.make_dummy_QENS_workspace()
+        params_table = self.make_multi_domain_parameter_table(ws)
+        indirect_common.transposeFitParametersTable(params_table)
+        self.assert_table_workspace_dimensions(params_table, expected_row_count=5, expected_column_count=11)
+
+    def test_transposeFitParametersTable_rename_output(self):
+        ws = self.make_dummy_QENS_workspace()
+        params_table = self.make_multi_domain_parameter_table(ws)
+        output_name = "new_table"
+
+        indirect_common.transposeFitParametersTable(params_table, output_name)
+
+        self.assert_table_workspace_dimensions(params_table, expected_row_count=26, expected_column_count=3)
+        self.assert_table_workspace_dimensions(output_name, expected_row_count=5, expected_column_count=11)
+
+    def test_search_for_fit_params(self):
+        ws = self.make_dummy_QENS_workspace()
+
+        #make a parameter table to search in
+        function = "name=LinearBackground, A0=0, A1=0;"
+        function += "name=Gaussian, Sigma=0.1, PeakCentre=0, Height=10;"
+        table_ws = PlotPeakByLogValue(Input=ws+",v", Function=function)
+
+        params = indirect_common.search_for_fit_params("Sigma", table_ws.name())
+
+        self.assertEqual(len(params), 1)
+        self.assertEqual(params[0], "f1.Sigma")
+
+    def test_convertParametersToWorkspace(self):
+        ws = self.make_dummy_QENS_workspace()
+
+        #make a parameter table to search in
+        function = "name=LinearBackground, A0=0, A1=0;"
+        function += "name=Gaussian, Sigma=0.1, PeakCentre=0, Height=10;"
+        table_ws = PlotPeakByLogValue(Input=ws + ",v0:10", Function=function)
+
+        param_names = ['A0', 'Sigma', 'PeakCentre']
+        indirect_common.convertParametersToWorkspace(table_ws.name(), 'axis-1', param_names, "params_workspace")
+        params_workspace = mtd["params_workspace"]
+
+        self.assert_matrix_workspace_dimensions(params_workspace.name(), 
+                                                expected_num_histograms=3, expected_blocksize=5)
+
+    def test_addSampleLogs(self):
+        ws = CreateSampleWorkspace()
+        logs = {}
+        logs['FloatLog'] = 3.149
+        logs['IntLog'] = 42
+        logs['StringLog'] = "A String Log"
+        logs['BooleanLog'] = True
+
+        indirect_common.addSampleLogs(ws, logs)
+
+        self.assert_logs_match_expected(ws.name(), logs)
+
+    def test_addSampleLogs_empty_dict(self):
+        ws = CreateSampleWorkspace()
+        logs = {}
+        self.assert_does_not_raise(Exception, indirect_common.addSampleLogs, ws, logs)
+
+    #-----------------------------------------------------------
+    # Custom assertion functions
+    #-----------------------------------------------------------
+
+    def assert_lists_match(self, expected, actual):
+        self.assertTrue(isinstance(expected, list))
+        np.testing.assert_array_equal(expected, actual, "The results do not match")
+
+    def assert_does_not_raise(self, exception_type, func, *args):
+        """ Check if this function raises the expected exception """
+        try:
+            func(*args)
+        except exception_type:
+            self.fail("%s should not of raised anything but it did." % func.__name__)
+
+    def assert_workspace_units_match_expected(self, expected_unit_ID, ws, axis_number=1):
+        axis = mtd[ws].getAxis(axis_number)
+        actual_unit_ID = axis.getUnit().unitID()
+        self.assertEquals(expected_unit_ID, actual_unit_ID)
+
+    def assert_has_spectrum_axis(self, ws, axis_number=1):
+        axis = mtd[ws].getAxis(axis_number)
+        self.assertTrue(axis.isSpectra())
+
+    def assert_has_numeric_axis(self, ws, axis_number=1):
+        axis = mtd[ws].getAxis(axis_number)
+        self.assertTrue(axis.isNumeric())
+
+    def assert_table_workspace_dimensions(self, workspace, expected_column_count, expected_row_count):
+        actual_row_count = mtd[workspace].rowCount()
+        actual_column_count = mtd[workspace].columnCount()
+        self.assertEquals(expected_row_count, actual_row_count,
+                          "Number of rows does not match expected (%d != %d)" 
+                          % (expected_row_count, actual_row_count))
+        self.assertEquals(expected_column_count, actual_column_count,
+                          "Number of columns does not match expected (%d != %d)" 
+                          % (expected_column_count, actual_column_count))
+
+    def assert_matrix_workspace_dimensions(self, workspace, expected_num_histograms, expected_blocksize):
+        actual_blocksize = mtd[workspace].blocksize()
+        actual_num_histograms = mtd[workspace].getNumberHistograms()
+        self.assertEqual(actual_num_histograms, expected_num_histograms,
+                         "Number of histograms does not match expected (%d != %d)"
+                         % (expected_num_histograms, actual_num_histograms))
+        self.assertEqual(expected_blocksize, actual_blocksize,
+                         "Workspace blocksize does not match expected (%d != %d)"
+                         % (expected_blocksize, actual_blocksize))
+
+    def assert_logs_match_expected(self, workspace, expected_logs):
+        run = mtd[workspace].getRun()
+        for log_name, log_value in expected_logs.iteritems():
+            self.assertTrue(run.hasProperty(log_name),
+                            "The log %s is missing from the workspace" % log_name)
+            self.assertEqual(str(run.getProperty(log_name).value), str(log_value), 
+                             "The expected value of log %s did not match (%s != %s)" % 
+                             (log_name, str(log_value), run.getProperty(log_name).value))
+
+    #-----------------------------------------------------------
+    # Test helper functions
+    #-----------------------------------------------------------
+
+    def make_dummy_QENS_workspace(self, output_name="ws", instrument_name='IRIS', 
+                                  analyser='graphite', reflection='002', add_logs=True):
+        """ Make a workspace that looks like QENS data """
+        ws = CreateSampleWorkspace(OutputWorkspace=output_name)
+        self.load_instrument(ws, instrument_name, analyser, reflection)
+        ws = CropWorkspace(ws, StartWorkspaceIndex=3, EndWorkspaceIndex=7, OutputWorkspace=output_name)
+
+        if add_logs:
+            AddSampleLog(ws, LogName='run_number', LogType='Number', LogText='00001')
+    
+        return ws.name()
+
+    def make_multi_domain_function(self, ws, function):
+        """ Make a multi domain function from a regular function string """
+        multi_domain_composite = 'composite=MultiDomainFunction,NumDeriv=1;'
+        component =  '(composite=CompositeFunction,$domains=i;%s);' % function
+        
+        fit_kwargs = {}
+        num_spectra = mtd[ws].getNumberHistograms()
+        for i in range(0, num_spectra):
+            multi_domain_composite += component
+            if i > 0:
+                fit_kwargs['WorkspaceIndex_%d' % i] = i
+                fit_kwargs['InputWorkspace_%d' % i] = ws
+
+        return multi_domain_composite, fit_kwargs
+
+    def make_multi_domain_parameter_table(self, ws):
+        """ Fit a multi domain function to get a table of parameters """
+        table_name = "test_fit"
+        function = "name=LinearBackground, A0=0, A1=0;"
+        function += "name=Gaussian, Sigma=0.1, PeakCentre=0, Height=10;"
+        multi_domain_function, fit_kwargs = self.make_multi_domain_function(ws, function)
+        Fit(Function=multi_domain_function, InputWorkspace=ws, WorkspaceIndex=0,
+            Output=table_name, CreateOutput=True, MaxIterations=0, **fit_kwargs)
+        return table_name + "_Parameters"
+
+    def load_instrument(self, ws, instrument, analyser='graphite', reflection='002'):
+        """Load an instrument parameter from the ipf directory"""
+        LoadInstrument(ws, InstrumentName=instrument)
+
+        if config['default.facility'] != 'ILL':
+            parameter_file_name = '%s_%s_%s_Parameters.xml' % (instrument, analyser, reflection)
+            ipf = os.path.join(config['instrumentDefinition.directory'], 
+                               parameter_file_name)
+            LoadParameterFile(ws, Filename=ipf)
+    
+        return ws
+
+
+if __name__=="__main__":
+    unittest.main()
\ No newline at end of file
diff --git a/Code/Tools/DOI/doi.py b/Code/Tools/DOI/doi.py
index 2a5241098aa42d2a9e1d6b8d81210a3086624f96..8e55bbda69b8531fc54c042f3cc3ede1785097cf 100644
--- a/Code/Tools/DOI/doi.py
+++ b/Code/Tools/DOI/doi.py
@@ -109,8 +109,9 @@ def build_xml_form(doi, relationships, creator_name_list, version_str):
         ET.SubElement(creator, 'creatorName').text = creator_name
 
     # Titles are defined as a "name or title by which a resource is known".
-    title_text_list = 'Mantid: Manipulation and Analysis Toolkit for ' + \
-                      'Instrument Data.',
+    title_version = " " + version_str if version_str else ""
+    title_text_list = 'Mantid%s: Manipulation and Analysis' % title_version + \
+                      ' Toolkit for Instrument Data.',
     titles = ET.SubElement(root, 'titles')
     for title_text in title_text_list:
         ET.SubElement(titles, 'title').text = title_text
diff --git a/Code/Tools/Pylint/README.md b/Code/Tools/Pylint/README.md
new file mode 100644
index 0000000000000000000000000000000000000000..da0921051b9c4704d4b9740d963f05dceeb83347
--- /dev/null
+++ b/Code/Tools/Pylint/README.md
@@ -0,0 +1,2 @@
+This directory contains a CMake template for generating a configuration file
+for [Pylint](http://www.pylint.org/) along with a high-level runner script.
diff --git a/Code/Tools/Pylint/pylint.cfg b/Code/Tools/Pylint/pylint.cfg
new file mode 100644
index 0000000000000000000000000000000000000000..e3675ca90a4e208f6110d55d8cbb7743b645dc40
--- /dev/null
+++ b/Code/Tools/Pylint/pylint.cfg
@@ -0,0 +1,262 @@
+[MASTER]
+
+# Specify a configuration file.
+#rcfile=
+
+# Python code to execute, usually for sys.path manipulation such as
+# pygtk.require().
+#init-hook=
+
+# Profiled execution.
+profile=no
+
+# Add files or directories to the blacklist. They should be base names, not
+# paths.
+ignore=CVS
+
+# Pickle collected data for later comparisons.
+persistent=yes
+
+# List of plugins (as comma separated values of python modules names) to load,
+# usually to register additional checkers.
+load-plugins=
+
+
+[MESSAGES CONTROL]
+
+# Enable the message, report, category or checker with the given id(s). You can
+# either give multiple identifier separated by comma (,) or put this option
+# multiple time.
+#enable=
+
+# Disable the message, report, category or checker with the given id(s). You
+# can either give multiple identifier separated by comma (,) or put this option
+# multiple time (only on the command line, not in the configuration file where
+# it should appear only once).
+
+# Disabled id descriptions:
+#
+#    W0142 - Usage of * & ** in function calls to pass through arguments
+#    I0011 - Warning about disabling a check inline using
+#    F0401 - Unable to import module
+#    W0614 - Unused import from wildcard import
+#    E0602 - Undefined variable (we get a lot from the mantid.simpleapi module)
+#    C0111 - Missing module docstring
+#    C0326 - Spaces around equality and commas
+#    W0401 - Wildcard imports
+#    R0201 - Method could be used as a function. All algorithms do this in the category method
+#
+disable=W0142,I0011,F0401,W0614,E0602,C0111,C0326,W0401,R0201
+
+
+[REPORTS]
+
+# Set the output format. Available formats are text, parseable, colorized, msvs
+# (visual studio) and html
+output-format=colorized
+
+# Include message's id in output
+include-ids=yes
+
+# Put messages in a separate file for each module / package specified on the
+# command line instead of printing them on stdout. Reports (if any) will be
+# written in a file name "pylint_global.[txt|html]".
+files-output=no
+
+# Tells whether to display a full report or only the messages
+reports=no
+
+# Python expression which should return a note less than 10 (10 is the highest
+# note). You have access to the variables errors warning, statement which
+# respectively contain the number of errors / warnings messages and the total
+# number of statements analyzed. This is used by the global evaluation report
+# (RP0004).
+evaluation=10.0 - ((float(5 * error + warning + refactor + convention) / statement) * 10)
+
+# Add a comment according to your evaluation note. This is used by the global
+# evaluation report (RP0004).
+comment=no
+
+
+[FORMAT]
+
+# Maximum number of characters on a single line.
+max-line-length=100
+
+# Maximum number of lines in a module
+max-module-lines=1000
+
+# String used as indentation unit. This is usually " " (4 spaces) or "\t" (1
+# tab).
+indent-string="    "
+
+
+[BASIC]
+
+# Required attributes for module, separated by a comma
+required-attributes=
+
+# List of builtins function names that should not be used, separated by a comma
+bad-functions=map,filter,apply,input
+
+# Regular expression which should only match correct module names
+module-rgx=(([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+))$
+
+# Regular expression which should only match correct module level names
+const-rgx=(([A-Z_][A-Z0-9_]*)|(__.*__))$
+
+# Regular expression which should only match correct class names
+class-rgx=[A-Z_][a-zA-Z0-9]+$
+
+# Regular expression which should only match correct function names
+function-rgx=[a-z_][a-z0-9_]{2,30}$
+
+# Regular expression which should only match correct method names
+method-rgx=[a-zA-Z_][a-zA-Z0-9_]{2,30}$
+
+# Regular expression which should only match correct instance attribute names
+attr-rgx=[a-zA-Z_][a-zA-Z0-9_]{2,30}$
+
+# Regular expression which should only match correct argument names
+argument-rgx=[a-zA-Z_][a-zA-Z0-9_]{2,30}$
+
+# Regular expression which should only match correct variable names
+variable-rgx=[a-zA-Z_][a-zA-Z0-9_]{2,30}$
+
+# Regular expression which should only match correct list comprehension /
+# generator expression variable names
+inlinevar-rgx=[A-Za-z_][A-Za-z0-9_]*$
+
+# Good variable names which should always be accepted, separated by a comma
+good-names=i,j,k,ex,Run,_
+
+# Bad variable names which should always be refused, separated by a comma
+bad-names=foo,bar,baz,toto,tutu,tata
+
+# Regular expression which should only match functions or classes name which do
+# not require a docstring
+no-docstring-rgx=.*
+
+
+[SIMILARITIES]
+
+# Minimum lines number of a similarity.
+min-similarity-lines=4
+
+# Ignore comments when computing similarities.
+ignore-comments=yes
+
+# Ignore docstrings when computing similarities.
+ignore-docstrings=yes
+
+
+[MISCELLANEOUS]
+
+# List of note tags to take in consideration, separated by a comma.
+notes=FIXME,XXX,TODO
+
+
+[TYPECHECK]
+
+# Tells whether missing members accessed in mixin class should be ignored. A
+# mixin class is detected if its name ends with "mixin" (case insensitive).
+ignore-mixin-members=yes
+
+# List of classes names for which member attributes should not be checked
+# (useful for classes with attributes dynamically set).
+ignored-classes=SQLObject
+
+# When zope mode is activated, add a predefined set of Zope acquired attributes
+# to generated-members.
+zope=no
+
+# List of members which are set dynamically and missed by pylint inference
+# system, and so shouldn't trigger E0201 when accessed. Python regular
+# expressions are accepted.
+generated-members=REQUEST,acl_users,aq_parent,mantid.simpleapi
+
+
+[VARIABLES]
+
+# Tells whether we should check for unused import in __init__ files.
+init-import=no
+
+# A regular expression matching the beginning of the name of dummy variables
+# (i.e. not used).
+dummy-variables-rgx=_|dummy
+
+# List of additional names supposed to be defined in builtins. Remember that
+# you should avoid to define new builtins when possible.
+additional-builtins=
+
+
+[CLASSES]
+
+# List of interface methods to ignore, separated by a comma. This is used for
+# instance to not check methods defines in Zope's Interface base class.
+ignore-iface-methods=isImplementedBy,deferred,extends,names,namesAndDescriptions,queryDescriptionFor,getBases,getDescriptionFor,getDoc,getName,getTaggedValue,getTaggedValueTags,isEqualOrExtendedBy,setTaggedValue,isImplementedByInstancesOf,adaptWith,is_implemented_by
+
+# List of method names used to declare (i.e. assign) instance attributes.
+defining-attr-methods=__init__,__new__,setUp
+
+# List of valid names for the first argument in a class method.
+valid-classmethod-first-arg=cls
+
+
+[DESIGN]
+
+# Maximum number of arguments for function / method
+max-args=5
+
+# Argument names that match this expression will be ignored. Default to name
+# with leading underscore
+ignored-argument-names=_.*
+
+# Maximum number of locals for function / method body
+max-locals=15
+
+# Maximum number of return / yield for function / method body
+max-returns=6
+
+# Maximum number of branch for function / method body
+max-branchs=12
+
+# Maximum number of statements in function / method body
+max-statements=50
+
+# Maximum number of parents for a class (see R0901).
+max-parents=7
+
+# Maximum number of attributes for a class (see R0902).
+max-attributes=7
+
+# Minimum number of public methods for a class (see R0903).
+min-public-methods=2
+
+# Maximum number of public methods for a class (see R0904).
+max-public-methods=20
+
+
+[IMPORTS]
+
+# Deprecated modules which should not be used, separated by a comma
+deprecated-modules=regsub,string,TERMIOS,Bastion,rexec
+
+# Create a graph of every (i.e. internal and external) dependencies in the
+# given file (report RP0402 must not be disabled)
+import-graph=
+
+# Create a graph of external dependencies in the given file (report RP0402 must
+# not be disabled)
+ext-import-graph=
+
+# Create a graph of internal dependencies in the given file (report RP0402 must
+# not be disabled)
+int-import-graph=
+
+
+[EXCEPTIONS]
+
+# Exceptions that will emit a warning when being caught. Defaults to
+# "Exception"
+overgeneral-exceptions=Exception
diff --git a/Code/Tools/Pylint/run_pylint.py b/Code/Tools/Pylint/run_pylint.py
new file mode 100644
index 0000000000000000000000000000000000000000..d86d712b0aaaef749666b4c077c657fb1f22f8ac
--- /dev/null
+++ b/Code/Tools/Pylint/run_pylint.py
@@ -0,0 +1,395 @@
+"""
+    runpylint
+    ~~~~~~~~~
+
+    Run pylint on selected Python files/directories. By default the output is sent to stdout
+    but there is an option to save to a file
+"""
+from __future__ import print_function
+
+from contextlib import contextmanager
+import logging
+from optparse import OptionParser
+import os.path
+import subprocess as subp
+import sys
+
+# Default output format
+DEFAULT_PYLINT_FORMAT = 'text'
+# Exe to call
+DEFAULT_PYLINT_EXE = 'pylint'
+# Default log level
+DEFAULT_LOG_LEVEL = logging.WARNING
+# Default config file
+DEFAULT_RCFILE = os.path.join(os.path.dirname(__file__), "pylint.cfg")
+
+#------------------------------------------------------------------------------
+
+@contextmanager
+def temp_dir_change(directory):
+    """
+    Change directory temporarily for a given context
+
+    Args:
+      directory (str): A string denoting the new directory
+    """
+    start_dir = os.getcwd()
+    if directory == start_dir:
+        yield
+    else:
+        os.chdir(directory)
+        yield
+        os.chdir(start_dir)
+
+#------------------------------------------------------------------------------
+
+class Results(object):
+    """
+    Keep track of the check pass/failure status
+    """
+
+    def __init__(self):
+        self.totalchecks = 0
+        self.failures = [] #list of module names
+
+    @property
+    def success(self):
+        """
+        Return true if all files were clean
+        """
+        return (len(self.failures) == 0)
+
+    def add(self, modulename, status):
+        """
+        Add either pass/fail depending on status
+
+        Args:
+          modulename (str): A string containing the name of the module
+                            that failed
+          status (bool): True/false status
+        """
+        if status:
+            self.add_passed()
+        else:
+            self.add_failed(modulename)
+
+    def add_passed(self):
+        """
+        Increment the number of checks but not the number of failures
+        """
+        self.totalchecks += 1
+
+    def add_failed(self, modulename):
+        """
+        Increment the number of checks and track a failure in the
+        given module.
+
+        Args:
+          modulename (str): A string containing the name of the module
+                            that failed
+        """
+        self.totalchecks += 1
+        self.failures.append(modulename)
+
+    def summary(self):
+        """
+        Return a string summary of the check status
+        """
+        HEADER = "%d%% checks passed, %d checks failed out of %d"
+        if self.success:
+            msg = HEADER % (100, 0, self.totalchecks)
+        else:
+            nfailed = len(self.failures)
+            npassed = self.totalchecks - nfailed
+            percentpass = npassed*100.0/self.totalchecks
+            msg = HEADER % (percentpass, nfailed, self.totalchecks)
+            msg += "\nChecks of the following modules FAILED:\n\t"
+            msg += "\n\t".join(self.failures)
+        return msg
+
+    def update(self, other):
+        """
+        Update this object with results from another
+        """
+        self.totalchecks += other.totalchecks
+        self.failures.extend(other.failures)
+
+#------------------------------------------------------------------------------
+
+def main(argv):
+    """
+    Main entry point
+
+    Args:
+      argv (list): List of strings giving command line arguments, including
+                   the python exe name
+    """
+    logging.basicConfig(level=DEFAULT_LOG_LEVEL)
+
+    options, args = parse_arguments(argv[1:])
+    setup_environment(options.mantidpath)
+    serializer = get_serializer(options.output)
+
+    status = run_checks(args, serializer, options)
+    if type(serializer) == file:
+        serializer.close()
+
+    if status or options.nofail:
+        return 0
+    else:
+        return 1
+
+#------------------------------------------------------------------------------
+
+def parse_arguments(argv):
+    """
+    Parse arguments for script input
+   
+    Args:
+      argv (list): List of strings giving command line arguments
+    """
+    # Setup options
+    parser = OptionParser(usage="%prog [options] TARGET")
+    parser.add_option("-b", "--basedir", dest="basedir", metavar="BASEDIR",
+                      help="If provided, use this as the base for all relative paths."
+                           "The default is the current working directory.")
+    parser.add_option("-e", "--exe", dest="exe", metavar="EXEPATH",
+                      help="If provided, use this as the executable path."
+                           "Default is to simply call 'pylint'")
+    parser.add_option("-f", "--format", dest="format", metavar = "FORMAT",
+                      help="If provided, use the given format type "\
+                           "[default=%s]. Options are: text, html, msvs, "\
+                           "parseable" % DEFAULT_PYLINT_FORMAT)
+    parser.add_option("-m", "--mantidpath", dest="mantidpath", metavar="MANTIDPATH",
+                      help="If provided, use this as the MANTIDPATH, overriding"
+                           "anything that is currently set.")
+    parser.add_option("-n", "--nofail", action="store_true",dest="nofail",
+                      help="If specified, then script will always return an exit status of 0.")
+    parser.add_option("-r", "--rcfile", dest="rcfile", metavar = "CFG_FILE",
+                      help="If provided, use this configuration file "
+                           "instead of the default one")
+    parser.add_option("-o", "--output", dest="output", metavar="FILE",
+                      help="If provided, store the output in the given file.")
+    parser.add_option("-x", "--exclude", dest="exclude", metavar="EXCLUDES",
+                      help="If provided, a space-separated list of "
+                            "files/directories to exclude. Relative paths are "
+                            "taken as relative to --basedir")
+
+    parser.set_defaults(format=DEFAULT_PYLINT_FORMAT, exe=DEFAULT_PYLINT_EXE, nofail=False,
+                        basedir=os.getcwd(), rcfile=DEFAULT_RCFILE, exclude="")
+
+    options, args = parser.parse_args(argv)
+    if len(args) < 1:
+        print("ERROR: Incorrect number of arguments '%s'" % args)
+        print()
+        parser.print_help()
+        sys.exit(1)
+
+    # rcfile needs to be absolute
+    if options.rcfile is not None and not os.path.isabs(options.rcfile):
+        options.rcfile = os.path.join(os.getcwd(), options.rcfile)
+    # exclude option is more helpful as a list
+    options.exclude = options.exclude.split()
+
+    return options, args
+
+#------------------------------------------------------------------------------
+
+def setup_environment(mantidpath):
+    """
+    Setup and check environment can import mantid.
+
+    Args:
+      mantidpath (str): A string that points to a directory containing
+                        the 'mantid' module
+    """
+    if mantidpath is not None:
+        setup_mantidpath(mantidpath)
+    errors = check_module_imports()
+    if errors != "":
+        raise ValueError(errors)
+
+def setup_mantidpath(mantidpath):
+    """
+    Setup the environment ready for the subprocess call.
+    Inserts the given path at the front of the PYTHONPATH and
+    sets the MANTIDPATH variable
+
+    Args:
+      mantidpath (str): A string that points to a directory containing
+                        the 'mantid' module
+    """
+    # Check for mantid module
+    if not os.path.isfile(os.path.join(mantidpath, "mantid","__init__.py")):
+        raise ValueError("Unable to find mantid python module in '%s'"\
+                           % mantidpath)
+
+    os.environ["MANTIDPATH"] = mantidpath
+    cur_pypath = os.environ.get("PYTHONPATH", "")
+    # for subprocesses
+    os.environ["PYTHONPATH"] = mantidpath + os.pathsep + cur_pypath 
+    sys.path.insert(0, mantidpath) # for current process
+
+#------------------------------------------------------------------------------
+
+def check_module_imports():
+    """
+    Returns an empty string if the environment variables
+    are set so that the mantid module is importable else
+    it returns an error string.
+
+    Returns:
+      str: String indicating success/failure
+    """
+    msg = ""
+    try:
+        import mantid
+    except ImportError, exc:
+        msg = "Unable to import mantid module: '%s'\n"\
+              "Try passing the -m option along with the path to the module"\
+                % str(exc)
+    return msg
+
+#------------------------------------------------------------------------------
+
+def get_serializer(filename):
+    """
+    If no file name is provided then returns sys.stdout, else
+    it creates the file and returns the handle
+
+    Args:
+      filename (str): Path to the filename for the output
+    """
+    if filename is None:
+        return sys.stdout
+    else:
+        return open(filename, 'w')
+
+#------------------------------------------------------------------------------
+
+def run_checks(targets, serializer, options):
+    """
+    Run pylint on the chosen targets
+
+    Args:
+      targets (list): A list of relative directory/file targets relative 
+                      to options.basedir
+      serializer (file-like): An object with a write method that will receive
+                              the output
+      options (object): Settings to use when running pylint
+    Returns:
+      bool: Success/failure
+    """
+    overall_stats = Results()
+    # convert to excludes absolute paths
+    def make_abs(path):
+        return os.path.join(options.basedir, path)
+    excludes = map(make_abs, options.exclude)
+
+    for target in targets:
+        # pylint will only check modules or packages so we need to do some additional work
+        # for plain directories
+        targetpath = os.path.join(options.basedir, target)
+        pkg_init = os.path.join(targetpath, "__init__.py")
+        if os.path.isfile(targetpath) or os.path.isfile(pkg_init):
+            overall_stats.add(exec_pylint_on_importable(targetpath, serializer, options))
+        else:
+            overall_stats.update(exec_pylint_on_all(targetpath, serializer, options, excludes))
+    ##
+    print(overall_stats.summary())
+
+    return overall_stats.success
+
+#------------------------------------------------------------------------------
+
+def exec_pylint_on_all(dirpath, serializer, options, excludes=[]):
+    """
+    Executes pylint on .py files and packages from the given starting directory
+
+    Args:
+      dirpath (str): A string giving a directory to parse
+      serializer (file-like): An object with a write method that will receive
+                              the output
+      options (object): Settings to use when running pylint
+      excludes (list): A list of absolute paths to exclude from the checks
+    Returns:
+      Results: Object detailing passes and failures
+    """
+    def skip_item(abspath):
+        for excluded in excludes:
+            if abspath.startswith(excluded):
+                return True
+        return False
+    logging.debug("Discovering all importable python modules/packages"
+                  " from '%s'" , dirpath)
+    targets  = find_importable_targets(dirpath)
+    stats = Results()
+    for item in targets:
+        if skip_item(item):
+            logging.debug("Skipping item '%s' by request", item)
+        else:
+            stats.add(item, exec_pylint_on_importable(item, serializer, options))
+    return stats
+
+#------------------------------------------------------------------------------
+
+def find_importable_targets(dirpath):
+    """
+    Returns a list of modules and packages that can be found, using the given
+    directory as a starting point. Files that are part of a package are not
+    included.
+
+    Args:
+      dirpath (str): Starts the search from this directory
+    Returns:
+      list: A list of module and package targets that were found
+    """
+    def package_walk(path):
+        contents = os.listdir(path)
+        importables = []
+        for item in contents:
+            abspath = os.path.join(path, item)
+            pkg_init = os.path.join(abspath, "__init__.py")
+            if (os.path.isfile(abspath) and item.endswith(".py")) or \
+                os.path.isfile(pkg_init):
+                 importables.append(abspath)
+            elif os.path.isdir(abspath):
+                importables.extend(package_walk(abspath))
+        return importables
+    #
+    return package_walk(dirpath)
+
+#------------------------------------------------------------------------------
+
+def exec_pylint_on_importable(srcpath, serializer, options):
+    """
+    Runs the pylint executable on the given file/package path to produce output
+    in the chosen format
+
+    Args:
+      srcpath (str): A string giving a path to a file or package to analyze
+      serializer (file-like): An object with a write method that will receive
+                              the output
+      options (object): Settings to use when running pylint
+    """
+    logging.info("Running pylint on '%s'", srcpath)
+    cmd = [options.exe]
+    cmd.extend(["-f", options.format])
+    if options.rcfile is not None:
+        cmd.extend(["--rcfile=" + options.rcfile])
+    # and finally, source module
+    # pylint runs by importing the modules so we strip the filepath
+    # and change directory to the containing folder
+    cmd.append(os.path.basename(srcpath))
+
+    logging.debug("Command '%s'" , " ".join(cmd))
+    with temp_dir_change(os.path.dirname(srcpath)):
+        status = subp.call(cmd, stdout=serializer)
+
+    return (status == 0)
+
+#------------------------------------------------------------------------------
+
+
+if __name__ == '__main__':
+    sys.exit(main(sys.argv))
diff --git a/Test/AutoTestData/ILLD2B_123944 b/Test/AutoTestData/ILLD2B_123944
deleted file mode 100644
index d492478c552fb058ea7c992fd4eb9a06fdf81e06..0000000000000000000000000000000000000000
--- a/Test/AutoTestData/ILLD2B_123944
+++ /dev/null
@@ -1,11578 +0,0 @@
-RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR
-  123944       0       4                                                        
-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
-      80       1                                                                
-Inst User L.C.   Date     Time                                                  
-D2B MatteoSuar18-Jul-13 15:51:34                                                
-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
-      80       1                                                                
-Title                                                                   Scantype
-Spinel LMOILL2 1.6  RT                                                  2theta  
-IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
-      31       4                                                                
-   nvers   ntype   kctrl   manip   nbang   nkmes  npdone   jcode   ipara   ianal
-   imode    itgv  iregul   ivolt    naxe npstart  ilast1     isa  flgkif      ih
-      ik   nbsqs  nb_det  nbdata icdesc1 icdesc2 icdesc3 icdesc4 icdesc5 icdesc6
- icdesc7                                                                        
-       4       2       4       1       3      25      25       0       1       0
-       0       0       0       0       2       0       0       0       0       0
-       0       0       1   16384       1       2       3       0       0       0
-       0                                                                        
-FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
-      50      10                                                                
-        H (Hmin)        K (Kmin)        L (Lmin)             phi             chi
-           omega  2theta (gamma)             psi         ub(1,1)         ub(1,2)
-         ub(1,3)         ub(2,1)         ub(2,2)         ub(2,3)         ub(3,1)
-         ub(3,2)         ub(3,3)      wavelength  dmonochromator       danalyser
-          energy            Hmax            Kmax            Lmax          DeltaH
-          DeltaK          DeltaL     Deltaenergy         Ki (Kf)       Ddetector
-            xoff            zoff          radius            yoff        attenuat
-      scan start       scan step      scan width          preset    add.bkg.step
-   add.bkg.width  add.bkg.preset  couplingfactor         (spare)         (spare)
-       Temp-s.pt      Temp-Regul     Temp-sample       Voltmeter       Mag.field
-  0.00000000E+00  0.00000000E+00  0.00000000E+00  0.00000000E+00  0.49975000E+02
-  0.40200001E+00  0.15310000E+03  0.00000000E+00  0.10000000E+01  0.00000000E+00
-  0.00000000E+00  0.00000000E+00  0.10000000E+01  0.00000000E+00  0.00000000E+00
-  0.00000000E+00  0.10000000E+01  0.16000000E+01  0.00000000E+00  0.00000000E+00
-  0.00000000E+00  0.00000000E+00  0.00000000E+00  0.00000000E+00  0.00000000E+00
-  0.00000000E+00  0.00000000E+00  0.00000000E+00  0.00000000E+00  0.00000000E+00
-  0.00000000E+00  0.00000000E+00  0.00000000E+00  0.00000000E+00  0.00000000E+00
-  0.15250000E+03  0.50000000E-01  0.11999970E+01  0.30000000E+06  0.00000000E+00
-  0.00000000E+00  0.00000000E+00  0.00000000E+00  0.00000000E+00  0.00000000E+00
-  0.00000000E+00  0.00000000E+00  0.00000000E+00  0.00000000E+00  0.00000000E+00
-SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS
-       1      24      25  123944       0       1                                
-FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
-       6       1                                                                
-            time         monitor       Total Cou     angles*1000                
-  0.35771000E+05  0.30000000E+06  0.16328000E+05  0.15250400E+06  0.40200000E+03
-  0.50810000E+05                                                                
-IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
-   16384                                                                        
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       1
-       1       2       0       0       0       0       0       1       0       1
-       1       2       3       1       0       2       0       1       1       0
-       0       0       0       1       0       0       0       0       0       1
-       0       0       2       0       0       1       0       1       1       1
-       0       2       1       0       0       2       0       2       0       2
-       1       1       0       0       0       0       0       0       0       0
-       0       0       2       0       0       3       1       0       0       0
-       0       1       0       1       0       0       1       0       2       2
-       1       0       0       1       0       0       0       1       0       1
-       0       0       2       0       0       1       1       1       0       1
-       0       0       0       1       1       1       0       1       0       3
-       1       1       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       2       1
-       0       0       0       0       0       0       0       1       1       0
-       0       0       1       0       0       0       0       0       0       0
-       1       0       1       1       1       0       0       1       0       0
-       0       0       0       0       0       1       1       1       1       0
-       0       1       0       0       0       2       1       1       1       0
-       0       0       0       1       1       0       0       0       0       0
-       0       3       2       0       0       1       0       0       0       1
-       1       2       0       1       1       0       0       1       0       2
-       1       0       0       0       0       2       1       0       1       0
-       0       1       1       0       1       1       1       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       1       0       0
-       0       0       0       1       0       0       1       1       1       1
-       0       1       1       0       0       1       0       1       0       1
-       1       2       0       1       1       1       0       1       0       0
-       0       0       0       0       0       0       1       0       2       0
-       0       1       0       0       0       1       1       1       1       2
-       0       0       0       1       1       0       1       1       0       0
-       0       0       0       1       0       1       1       1       1       1
-       0       0       0       0       0       2       1       0       0       1
-       2       1       0       0       1       0       1       0       1       1
-       0       0       0       0       0       0       2       0       0       0
-       1       1       0       0       0       1       1       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       1       0       0       5       2       1       1       0       0       1
-       0       0       0       0       0       0       0       1       0       0
-       0       0       2       1       0       0       0       0       0       0
-       1       4       0       0       0       0       1       1       0       0
-       1       0       2       0       0       0       0       3       0       0
-       0       0       1       2       1       0       0       2       0       1
-       1       0       3       1       1       2       1       0       2       0
-       0       0       0       3       1       0       0       0       1       1
-       0       0       1       0       0       2       2       2       0       1
-       1       0       0       2       0       0       0       2       0       0
-       1       1       1       2       0       0       0       1       0       1
-       1       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       1       0       2       1       0       0
-       1       0       1       1       1       0       0       1       1       3
-       2       1       0       1       1       3       0       1       1       1
-       0       2       1       2       1       0       0       1       1       1
-       1       0       0       2       0       0       1       0       1       0
-       1       3       1       0       0       1       1       0       2       3
-       0       0       0       1       2       1       2       2       0       0
-       1       1       3       2       2       1       1       0       0       1
-       0       1       0       1       1       0       0       1       0       0
-       0       1       0       0       1       0       0       0       1       2
-       0       0       1       0       0       0       0       0       1       0
-       3       2       1       0       2       0       0       0       0       1
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       1       3       0       0       1       0
-       0       1       1       1       0       1       0       1       1       1
-       2       2       0       0       0       1       0       0       2       0
-       2       0       2       0       0       2       0       0       1       0
-       1       0       1       0       0       2       2       0       1       1
-       0       2       0       1       0       1       1       2       1       2
-       0       1       2       1       1       0       2       1       2       0
-       0       1       0       2       1       1       1       0       0       0
-       0       2       0       1       1       2       0       0       1       0
-       2       0       1       0       2       2       1       1       1       0
-       0       0       1       0       0       3       1       1       0       0
-       1       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       1       2       4       0       1       1       2       1       5       1
-       0       1       2       2       6       2       5       3       5       4
-       7       3       2       5       4       2       4       6       2       1
-       6       5       3       7       6       3       4       6       1       5
-       5       5       5      10       7       3       6       7       4       4
-       8       3       9       3       4       4       6       6       4       6
-       6      10       4       5       8       5       7       0       3       4
-       4       5       6       6       5       6       3       3       4       4
-       8       3       4       1       5       3       2       2       1       2
-       2       2       7       2       1       3       1       3       1       3
-       3       3       3       1       1       0       1       1       2       1
-       0       0       0       1       0       0       0       0       0       0
-       0       2       2       1       2       3       4       1       3       5
-       2       3       7       2       1       4       3       2       4       0
-       1       3       1       0       1       1       2       2       3       0
-       2       2       1       2       2       2       7       3       4       4
-       1       2       1       4       1       2       3       6       3       6
-       2       4       4       6       1       3       2       2       2       4
-       1       4       3       6       7       3       2       2       0       3
-       3       6       1       3       4       3       1       2       3       2
-       1       3       4       5       4       3       4       1       5       4
-       1       3       1       4       1       1       2       1       3       3
-       2       3       3       5       2       4       3       1       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       1       0       1       3       2
-       3       1       3       4       4       2       4       4       4       3
-       3       4       0       3       0       1       6       0       4       3
-       6       2       4       2       1       2       1       2       3       4
-       6       2       2       5       7       3       3       1       2       4
-       4       5       3       4       1       2       3       2       3       1
-       2       4       3       1       3       2       2       4       2       4
-       3       2       3       2       4       3       1       1       6       3
-       3       1       6       1       1       3       2       3       4       6
-       2       1       1       3       0       3       1       3       5       3
-       3       2       4       5       2       4       2       3       2       2
-       0       2       1       1       0       0       0       0       0       0
-       0       0       0       0       2       0       1       1       2       3
-       2       2       2       2       1       2       2       1       0       1
-       2       1       3       0       2       1       6       1       2       3
-       3       1       0       5       2       0       0       5       3       0
-       4       4       4       0       2       5       4       2       1       1
-       1       2       1       1       3       2       2       2       2       1
-       3       0       4       2       4       2       2       3       0       1
-       2       2       3       3       2       3       2       5       3       1
-       3       3       4       4       3       2       4       1       2       2
-       2       1       3       0       2       2       2       1       2       1
-       1       2       1       1       1       0       1       1       0       2
-       1       6       0       1       1       1       1       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       1       0       1       1       0       2       0
-       2       0       2       1       3       6       1       2       1       0
-       5       1       0       2       4       0       0       0       3       3
-       1       2       0       2       2       1       0       1       2       2
-       2       2       2       3       2       4       2       1       1       2
-       1       5       2       3       2       1       2       1       1       4
-       3       3       0       5       3       4       3       1       2       3
-       2       1       1       0       2       5       0       3       1       2
-       2       1       3       1       0       4       2       0       3       5
-       2       4       4       2       1       1       2       1       1       1
-       3       2       2       0       1       1       0       3       2       3
-       2       3       0       0       0       0       0       0       0       0
-       0       0       0       0       0       1       1       0       1       1
-       1       2       2       1       1       0       3       0       2       2
-       1       1       0       1       4       1       4       2       2       4
-       1       3       0       2       1       2       2       0       4       1
-       3       3       4       0       1       1       1       1       0       3
-       1       2       2       3       2       0       3       1       2       1
-       0       3       2       1       2       2       1       1       2       2
-       5       0       1       2       0       2       2       0       0       1
-       2       1       0       1       1       2       0       4       1       2
-       2       5       0       2       1       0       2       1       2       0
-       1       0       1       3       0       1       2       0       1       1
-       2       1       0       2       0       1       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       1       2       4       0       4       2       3       1       2
-       0       1       1       4       2       1       0       1       3       5
-       1       4       1       1       2       1       4       3       2       3
-       2       1       0       2       4       2       1       6       1       2
-       2       1       5       0       0       2       0       0       1       3
-       1       4       1       1       1       1       2       1       1       4
-       1       2       0       2       0       1       0       4       3       0
-       3       1       1       3       0       0       1       1       1       1
-       2       0       2       0       2       3       2       0       3       2
-       1       0       1       1       1       0       1       0       5       1
-       1       0       4       1       2       1       1       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       1       1       1       1       4       1       0       0       2
-       1       2       0       1       1       0       0       2       4       3
-       0       1       3       2       0       2       1       1       1       0
-       0       1       0       2       3       1       1       2       2       1
-       0       2       0       1       1       1       1       1       0       3
-       2       0       2       1       3       2       1       2       2       0
-       3       2       0       4       2       1       0       2       4       1
-       4       1       2       1       0       5       1       3       0       2
-       1       4       0       1       0       0       1       0       0       3
-       0       1       3       2       1       1       1       0       1       5
-       4       1       3       3       0       0       1       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       1       0       1       1       1       2
-       0       1       2       0       1       3       2       2       3       3
-       1       3       1       0       1       3       1       0       1       0
-       0       0       0       3       1       0       2       2       1       3
-       0       3       2       1       3       1       1       1       1       5
-       1       4       0       2       4       0       2       1       4       1
-       0       2       2       1       3       1       2       4       1       1
-       3       2       2       1       2       0       0       2       1       3
-       0       2       2       0       1       4       2       3       1       2
-       1       0       2       2       1       1       3       0       1       1
-       0       2       0       1       0       4       4       0       1       2
-       2       0       0       0       0       0       0       0       0       0
-       0       0       0       1       0       1       1       2       3       3
-       1       2       0       3       2       0       1       0       1       1
-       4       2       0       3       0       0       1       1       1       1
-       0       1       1       3       2       0       0       3       1       2
-       2       0       1       0       1       0       2       2       0       1
-       1       0       3       0       2       0       1       2       2       2
-       1       2       1       0       1       1       2       1       1       1
-       1       1       1       4       3       1       0       1       0       2
-       2       0       1       0       1       1       1       1       0       0
-       1       2       2       0       2       1       0       2       2       3
-       1       2       0       1       2       0       0       0       0       1
-       1       1       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       1       1       1       2       2       1       0       0
-       3       3       0       4       1       1       1       0       0       1
-       3       0       2       3       4       1       2       3       3       2
-       1       0       1       4       0       0       0       2       1       0
-       1       0       3       1       3       0       0       0       1       4
-       0       0       0       2       1       1       3       0       2       0
-       0       2       0       1       1       0       2       2       3       1
-       2       1       0       2       2       1       1       2       1       1
-       1       2       0       4       3       0       5       0       0       0
-       0       0       2       4       0       0       0       0       0       1
-       2       1       0       1       1       1       1       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       1       4       0       0       2       1       1       1
-       3       4       0       1       1       1       1       2       0       1
-       0       1       2       3       3       0       0       3       2       1
-       2       3       1       1       1       0       3       1       3       2
-       0       0       0       1       0       0       0       1       1       1
-       2       3       4       2       2       1       1       0       1       2
-       1       3       3       0       1       2       2       3       1       1
-       1       0       0       3       2       4       0       0       4       4
-       1       1       1       2       2       1       3       3       1       0
-       1       4       1       1       1       0       1       4       1       2
-       0       2       2       2       0       0       1       4       2       1
-       1       0       1       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       1       0       1       2
-       0       2       2       1       0       1       1       1       3       1
-       2       1       2       1       3       0       1       1       2       1
-       2       1       1       0       0       1       3       1       1       4
-       3       1       1       3       2       1       1       3       2       2
-       3       2       3       3       1       2       4       0       1       0
-       1       1       1       0       0       2       1       0       3       2
-       4       3       1       0       1       1       2       1       2       2
-       1       3       1       2       0       2       0       1       0       0
-       3       0       2       1       1       0       0       1       4       0
-       1       2       2       3       1       0       1       0       1       1
-       1       2       0       0       0       0       0       0       0       0
-       0       0       0       0       0       1       0       0       0       0
-       1       3       0       3       0       4       1       4       0       0
-       2       1       1       2       3       3       1       1       2       2
-       1       0       1       1       2       0       4       1       4       2
-       2       3       2       0       1       2       0       0       2       3
-       1       1       5       1       5       1       2       2       2       0
-       2       0       5       0       1       3       2       1       0       2
-       3       1       0       0       3       3       1       2       1       2
-       2       1       1       3       1       2       0       2       3       0
-       2       2       0       1       3       5       1       1       1       2
-       2       1       3       0       2       2       2       2       1       2
-       1       0       0       0       0       3       1       2       1       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       1       0       1       2       1       4       0       0       2       3
-       3       3       1       2       0       0       0       3       1       3
-       1       1       1       0       0       1       1       2       1       4
-       1       2       3       4       3       2       1       1       1       1
-       0       1       0       1       0       2       1       0       1       1
-       0       3       1       2       4       1       0       2       1       2
-       1       3       1       0       2       1       0       2       1       1
-       1       3       0       0       0       0       2       1       0       0
-       2       0       2       0       1       0       1       4       4       1
-       0       1       4       1       0       0       3       1       0       0
-       1       1       0       2       0       1       0       2       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       1       1       0       0       0       0       1
-       2       2       3       1       1       1       1       1       1       0
-       1       1       0       1       3       3       0       2       0       1
-       2       0       3       1       2       3       1       2       1       0
-       2       2       2       1       2       1       1       0       2       2
-       0       3       1       0       1       0       1       1       1       3
-       0       0       0       1       1       1       0       0       1       0
-       1       2       3       0       4       1       0       0       0       2
-       0       1       4       1       0       1       1       3       2       1
-       2       0       2       2       1       1       1       0       0       1
-       2       3       2       1       2       1       0       1       2       1
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       1       1       0       2       0       1       2       1       2       1
-       0       0       0       0       0       2       1       3       1       0
-       0       1       0       2       0       2       2       3       0       2
-       1       2       0       1       0       2       2       0       1       0
-       2       1       1       1       0       1       1       1       1       0
-       0       2       2       0       1       0       5       1       2       0
-       0       0       2       0       1       1       5       0       1       2
-       0       0       1       0       0       0       0       2       0       0
-       2       1       0       1       0       2       2       3       0       2
-       0       1       1       1       0       2       0       0       1       1
-       0       0       1       2       1       5       1       0       0       1
-       2       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       1       1       2       1       3
-       0       2       1       2       0       1       1       1       0       0
-       1       0       3       2       5       0       1       0       2       1
-       0       0       4       1       4       1       2       2       1       0
-       5       1       3       0       1       3       3       5       4       2
-       0       0       0       2       4       1       0       3       1       2
-       1       2       1       1       4       1       1       4       1       0
-       0       1       0       2       1       3       2       2       1       1
-       2       5       0       3       0       2       1       2       2       1
-       1       2       2       0       1       1       2       0       1       3
-       6       3       0       3       1       1       1       3       0       1
-       1       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       1       0       0       0       0       2       1       1       1
-       1       2       1       1       2       2       2       0       0       0
-       4       0       2       1       2       0       1       2       3       1
-       0       3       1       3       0       1       0       1       1       0
-       1       4       1       1       2       1       0       2       2       1
-       1       3       0       0       0       1       1       0       2       2
-       0       0       0       1       2       0       1       0       1       1
-       1       0       2       1       2       1       1       0       0       0
-       0       0       3       0       1       1       1       1       0       1
-       2       1       2       0       1       1       0       2       1       0
-       1       0       1       2       0       1       1       0       1       0
-       0       1       0       1       0       0       0       0       0       0
-       0       0       0       1       0       1       2       1       1       1
-       1       0       0       0       1       2       1       0       1       2
-       1       0       3       1       0       1       0       2       2       0
-       1       1       1       2       2       3       1       0       2       0
-       2       0       1       3       1       0       4       0       0       1
-       2       1       1       0       1       1       0       1       1       0
-       0       3       1       0       2       1       1       0       1       1
-       1       1       1       0       2       2       0       4       0       2
-       2       2       1       2       2       1       0       0       2       0
-       6       2       1       2       2       4       0       1       1       1
-       0       1       2       0       2       2       2       0       4       1
-       2       0       2       2       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       3       2       2       0       5       1       0       0
-       2       2       3       3       0       1       0       1       0       1
-       1       1       2       1       1       2       2       0       2       1
-       1       1       1       0       1       1       1       0       2       3
-       0       1       1       0       2       0       0       2       1       0
-       0       3       3       1       0       2       1       1       2       2
-       2       0       2       1       1       1       0       2       2       0
-       2       0       0       0       2       2       0       0       1       3
-       2       0       1       0       0       0       1       2       2       1
-       2       0       2       0       2       3       3       0       1       0
-       1       0       1       0       2       1       0       0       3       1
-       2       0       0       0       0       0       0       0       0       0
-       0       0       0       0       1       0       0       1       0       1
-       0       0       0       0       0       3       1       0       0       0
-       0       0       2       4       1       1       1       1       2       2
-       0       0       1       0       1       0       2       0       3       0
-       2       2       1       0       2       1       2       1       0       1
-       1       2       2       3       0       3       2       1       1       0
-       1       2       0       1       2       0       1       1       2       1
-       0       2       0       3       0       1       0       3       1       4
-       3       0       0       1       0       0       0       2       0       0
-       3       3       1       2       1       1       0       0       1       3
-       1       1       1       2       2       2       2       1       2       1
-       1       1       1       0       2       0       0       1       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       1       1       1       0
-       0       2       1       1       1       1       2       0       1       2
-       1       2       0       0       0       0       0       1       0       1
-       1       1       1       0       1       2       0       0       4       0
-       0       0       1       3       3       0       1       2       2       2
-       1       1       0       0       1       3       1       1       2       2
-       1       2       0       1       0       3       1       5       2       0
-       0       0       1       0       2       4       2       0       0       2
-       3       1       5       0       2       0       0       1       1       1
-       4       0       1       2       1       0       2       0       0       0
-       0       0       1       0       2       1       1       1       0       2
-       2       0       1       0       2       0       1       1       0       1
-       0       0       0       0       0       0       0       0       0       0
-       0       1       1       2       4       2       0       2       1       2
-       0       0       0       1       2       3       0       2       0       0
-       0       1       1       1       0       1       2       1       1       0
-       1       1       0       0       1       2       1       1       2       1
-       1       0       3       2       1       2       4       0       2       3
-       1       1       0       2       1       0       0       2       1       1
-       1       2       1       0       1       1       2       2       0       0
-       2       1       0       1       1       2       4       2       0       2
-       1       0       0       0       0       1       1       1       1       1
-       1       1       1       2       1       1       2       1       0       1
-       1       1       0       1       3       1       2       1       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       2       1       2       0       2       0       1       2
-       3       2       1       0       1       1       3       1       2       3
-       2       0       1       2       0       0       0       1       6       3
-       2       1       1       2       2       2       3       0       0       2
-       2       0       0       1       3       2       0       3       2       0
-       3       1       3       2       0       0       1       2       1       0
-       0       2       1       0       0       3       0       1       1       1
-       4       0       0       2       2       1       0       0       0       0
-       1       0       0       1       1       0       1       1       0       0
-       2       0       1       0       1       0       0       0       0       0
-       0       1       2       2       1       0       3       1       2       2
-       1       0       0       1       0       0       0       0       0       0
-       0       0       0       0       0       0       1       2       1       1
-       0       1       2       1       1       3       2       0       3       2
-       1       1       2       0       2       0       2       3       0       3
-       1       1       0       0       0       1       2       1       0       0
-       2       0       1       2       1       0       1       2       1       0
-       1       0       0       1       2       0       1       1       0       3
-       3       1       1       0       2       3       1       1       1       0
-       0       0       1       2       0       1       1       2       2       2
-       4       1       0       0       1       1       2       0       2       1
-       0       2       0       1       2       0       0       1       0       0
-       0       2       1       2       1       3       0       1       1       3
-       1       0       0       0       2       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       1       2       0
-       3       0       0       0       3       1       1       1       1       0
-       2       2       2       0       0       1       1       1       0       1
-       1       0       0       2       0       5       0       0       0       2
-       0       1       0       0       0       1       4       2       1       4
-       2       0       1       0       0       0       1       1       2       1
-       1       1       1       1       1       2       1       0       0       2
-       1       2       1       2       0       1       0       1       2       0
-       1       1       1       1       0       0       1       2       0       1
-       1       0       2       0       0       3       1       1       0       1
-       0       0       2       0       0       0       2       1       1       1
-       0       0       1       0       2       1       0       1       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       1       1       0       0       0       1       1       4
-       0       1       0       2       1       3       1       1       1       1
-       1       1       1       0       0       1       1       1       0       1
-       0       2       0       2       1       4       0       3       3       0
-       1       1       1       1       1       2       0       2       3       1
-       2       2       3       2       1       0       1       1       1       1
-       2       0       2       2       1       1       2       3       1       1
-       0       1       1       3       1       3       2       0       1       2
-       0       1       1       0       1       2       2       0       0       2
-       1       0       2       1       2       1       1       1       2       0
-       0       0       0       1       0       1       2       1       2       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       2       0
-       0       1       1       3       0       0       0       0       1       2
-       0       0       0       1       2       1       2       0       1       1
-       0       2       2       2       0       1       1       0       2       2
-       2       2       1       1       1       1       3       2       1       0
-       0       1       2       2       2       1       1       0       2       1
-       1       1       0       2       0       3       0       0       1       1
-       2       3       3       0       2       1       1       0       0       2
-       1       1       3       3       1       3       1       0       1       0
-       0       0       1       1       1       0       0       1       1       1
-       4       1       2       3       1       0       2       0       1       3
-       0       1       1       0       0       2       1       0       1       1
-       1       1       1       0       1       0       0       0       0       0
-       0       0       0       0       0       0       1       0       3       2
-       1       4       1       0       3       2       4       2       3       3
-       1       0       0       1       2       5       3       2       2       2
-       2       6       2       2       2       1       5       4       2       6
-       2       4       7       2       2       2       2       0       1       2
-       3       2       3       2       1       4       3       4       7       3
-       3       2       4       5       4       3       1       3       5       5
-       7       3       2       4       5       2       9       2       2       4
-       5       3       4       3       7       2       1       3       3       4
-       2       5       2       2       4       1       1       0       3       3
-       1       4       3       4       2       1       3       2       1       3
-       1       0       1       4       2       1       1       2       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       1
-       1       8       6       8       8      14       7      12       4       6
-       3       8       4       2       8       7       4       5       3       1
-       1       3       4       2       0       2       0       2       4       0
-       2       4       0       1       2       0       0       3       4       3
-       1       2       3       3       0       0       0       1       4       3
-       1       0       2       1       1       1       0       0       1       2
-       0       0       2       0       2       2       1       1       3       1
-       3       1       0       1       3       1       0       1       1       4
-       3       3       2       4       1       2       1       2       2       3
-       4       5       3       2       2       4       4       2       2       5
-       4       2       6       4       6       4       6       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       1       1       0       1       2       1       2       0       0       0
-       2       0       1       1       1       1       1       2       0       3
-       0       1       3       0       1       2       0       2       1       0
-       1       2       1       0       1       2       1       0       0       4
-       0       1       1       1       1       1       0       1       1       2
-       2       2       1       2       1       2       1       1       0       0
-       1       0       1       4       1       1       1       0       0       1
-       1       0       3       0       2       0       1       2       0       1
-       0       3       0       1       1       1       1       2       1       1
-       0       0       3       2       1       3       4       2       1       1
-       1       1       1       0       0       1       2       0       1       2
-       1       2       1       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       1
-       0       0       0       0       1       1       0       0       1       2
-       4       2       0       1       1       1       0       1       1       0
-       1       2       5       2       1       1       1       0       2       0
-       0       0       1       1       0       3       0       1       0       0
-       0       1       3       0       2       2       1       0       5       2
-       0       0       0       0       3       1       1       2       3       0
-       1       0       1       0       0       0       0       0       2       4
-       3       1       1       2       1       1       1       0       0       1
-       1       1       0       0       1       2       0       0       1       0
-       2       3       2       0       0       1       1       1       1       0
-       0       0       3       1       2       2       1       0       1       2
-       1       2       0       1       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       1       0
-       0       1       3       0       0       0       1       0       0       1
-       0       1       2       0       1       1       2       1       0       2
-       1       0       0       1       0       2       0       0       1       0
-       1       0       0       3       1       2       1       2       0       1
-       2       2       1       0       1       1       2       1       0       1
-       0       0       1       2       1       2       0       0       1       1
-       2       3       0       1       0       1       1       0       0       1
-       1       0       1       1       1       1       1       1       0       0
-       0       2       2       1       3       3       1       0       0       1
-       3       1       1       0       0       1       0       0       0       1
-       1       0       2       0       2       0       0       0       2       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       1       0
-       1       0       0       0       1       2       1       2       4       1
-       2       0       2       3       1       0       3       2       2       1
-       0       0       1       1       1       3       0       2       1       0
-       2       2       1       0       1       3       1       0       0       0
-       1       2       2       1       1       1       2       3       1       1
-       1       1       0       2       1       1       0       3       1       2
-       1       2       1       1       2       1       1       0       2       0
-       0       0       1       1       1       0       2       2       1       4
-       1       0       3       0       4       1       2       1       2       1
-       1       0       0       1       0       0       1       2       1       2
-       1       0       1       0       1       2       1       2       1       4
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       2       1       0
-       1       1       1       1       1       2       1       1       0       1
-       0       2       0       0       0       1       2       1       2       0
-       2       0       0       2       0       1       2       0       0       1
-       1       1       0       0       0       0       1       1       0       3
-       1       0       2       1       0       0       0       1       2       0
-       0       1       0       0       3       1       1       1       1       1
-       0       2       0       1       1       0       0       1       0       1
-       1       2       0       0       0       0       0       0       1       0
-       1       0       0       1       1       2       1       2       1       0
-       0       1       1       2       3       1       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       1       1       0
-       1       0       1       2       0       1       1       1       0       0
-       0       1       1       1       1       1       1       0       0       2
-       5       0       0       2       2       1       2       3       1       2
-       2       0       0       1       0       0       0       0       2       1
-       3       0       3       0       2       2       1       1       0       2
-       1       4       0       2       0       1       1       0       2       0
-       1       0       3       0       2       3       1       0       2       1
-       0       1       0       0       1       0       3       1       0       2
-       0       1       0       0       0       1       1       3       1       1
-       0       2       3       2       1       1       0       0       4       0
-       0       2       2       2       1       1       1       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       1       1       1       1       1       0       1       1       2
-       0       2       1       0       3       0       0       0       0       3
-       1       0       0       1       3       0       0       0       1       0
-       0       1       1       0       1       0       3       1       0       0
-       1       0       2       0       1       0       0       3       0       0
-       2       1       2       1       2       2       0       0       4       4
-       1       2       3       0       0       0       1       1       1       0
-       0       1       1       1       1       1       2       0       1       1
-       1       1       0       2       1       1       1       1       1       1
-       1       2       4       0       1       0       3       1       0       2
-       0       2       1       1       0       2       0       0       1       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       1       1       0       2       1
-       0       0       2       0       2       0       1       0       0       1
-       1       2       2       4       2       1       1       1       0       1
-       1       0       0       0       1       0       1       0       1       3
-       1       2       1       2       0       0       0       1       1       2
-       3       0       1       2       1       1       0       0       1       0
-       2       1       2       1       1       1       2       0       2       1
-       3       3       0       0       2       1       1       1       0       1
-       3       2       1       0       1       3       1       1       1       0
-       1       2       1       2       0       2       3       2       1       3
-       0       1       2       0       1       1       1       1       1       1
-       0       2       2       1       0       0       0       0       0       0
-       0       0       0       0       0       0       0       2       0       1
-       0       3       6       3       4       1       1       4       0       3
-       0       2       2       1       4       1       2       2       0       2
-       1       3       1       2       1       5       2       3       0       1
-       1       2       3       5       0       0       0       4       4       1
-       2       2       3       2       2       2       1       3       2       2
-       6       4       2       2       3       1       3       7       5       2
-       1       5       3       2       3       3       3       0       3       7
-       2       4       1       2       2       4       1       4       0       3
-       0       1       6       1       3       2       1       0       3       1
-       2       1       3       0       2       0       2       2       0       2
-       0       0       1       0       0       0       1       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       1       0
-       0       0       0       1       1       1       4       2       1       1
-       1       1       1       0       1       0       0       0       0       1
-       3       1       0       1       0       1       0       2       1       0
-       0       0       1       1       3       0       0       0       0       2
-       1       1       3       1       1       0       2       0       1       1
-       2       1       0       2       0       0       1       1       1       1
-       3       2       1       0       1       0       0       0       0       0
-       2       0       2       2       1       0       0       1       0       0
-       0       0       0       0       0       3       0       0       1       0
-       2       2       2       0       0       0       1       1       1       0
-       1       1       0       0       0       1       2       0       2       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       1       2       0       1       1
-       0       1       0       1       1       0       0       1       1       0
-       0       3       0       0       0       0       0       0       0       1
-       0       0       2       0       0       0       1       1       2       0
-       2       1       1       0       1       2       2       1       1       1
-       2       0       1       1       3       2       1       1       0       0
-       0       1       0       0       2       1       2       1       1       2
-       2       1       1       1       1       0       1       1       0       2
-       2       1       2       2       2       1       2       1       2       2
-       0       2       0       1       0       0       0       1       0       3
-       1       3       0       1       1       2       2       2       2       2
-       0       0       0       0       0       0       1       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       1       1       0
-       0       2       0       2       0       0       3       0       0       2
-       1       3       0       1       1       0       1       1       1       1
-       0       0       0       0       2       0       2       0       2       3
-       0       0       3       2       1       3       3       2       1       0
-       1       0       1       0       1       1       2       0       0       2
-       1       0       1       0       0       3       0       0       1       3
-       2       3       1       0       1       2       1       2       1       0
-       0       2       3       2       0       1       0       1       2       1
-       0       1       1       0       0       1       0       0       2       1
-       2       3       0       0       0       1       0       0       0       1
-       1       1       0       0       2       0       1       1       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       1       0       0       0       1       0       1       1       2
-       1       2       1       2       0       0       0       1       2       0
-       0       2       0       2       0       1       2       2       2       1
-       1       2       2       1       2       0       1       1       0       1
-       2       3       1       0       0       2       2       2       0       2
-       0       3       1       1       3       2       0       2       4       2
-       2       2       1       2       1       0       2       1       1       0
-       0       2       0       1       1       0       3       0       2       4
-       0       1       1       2       1       1       1       2       4       2
-       1       1       2       0       1       1       0       0       2       0
-       0       2       0       1       0       0       1       0       0       1
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       1       0       1       2       3       4       1       0       1
-       0       1       1       1       2       3       2       1       0       1
-       0       1       0       0       0       0       1       0       1       0
-       1       1       0       1       2       2       0       2       0       0
-       1       1       1       2       2       1       2       0       0       0
-       0       2       0       0       0       0       2       1       0       1
-       1       0       0       0       0       2       2       0       0       0
-       1       1       1       3       0       2       0       1       1       0
-       0       1       2       1       0       0       1       0       0       1
-       0       3       0       1       2       1       1       1       0       0
-       0       0       0       1       0       0       1       0       2       1
-       2       2       1       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       2       1
-       0       1       0       2       1       0       2       0       0       0
-       2       2       3       1       0       1       1       1       0       3
-       1       0       1       2       1       1       1       0       1       1
-       0       0       1       1       1       0       0       1       2       1
-       3       3       0       1       0       0       2       0       1       3
-       1       0       1       1       0       0       1       1       3       3
-       1       0       0       1       1       1       1       1       1       0
-       1       1       0       1       2       0       0       0       0       0
-       1       1       2       0       1       3       0       0       0       0
-       3       0       0       2       3       1       0       2       0       0
-       2       0       1       2       0       0       2       0       1       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       1       0       0       0       2       1       1
-       1       1       1       0       0       0       1       3       2       2
-       3       0       1       2       2       0       0       0       1       3
-       1       1       0       1       2       1       0       1       2       1
-       0       1       0       1       1       1       0       1       3       1
-       0       0       2       1       0       0       4       3       1       3
-       1       0       1       2       2       0       1       1       0       1
-       0       1       1       1       2       0       1       0       0       0
-       1       1       1       2       1       1       0       0       2       2
-       0       1       2       1       0       1       3       0       0       0
-       1       1       0       1       1       0       0       1       0       1
-       0       0       0       3       3       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       3       0       0
-       1       1       0       1       2       0       1       0       2       0
-       1       0       1       3       0       0       2       2       0       0
-       0       0       0       1       0       1       3       1       0       0
-       2       0       0       1       0       0       3       1       1       3
-       0       1       0       2       2       0       0       1       0       0
-       0       2       0       2       1       2       0       0       1       4
-       0       2       1       2       0       0       1       2       2       3
-       0       0       0       1       1       1       3       0       1       1
-       0       0       0       1       0       1       0       2       2       0
-       0       0       0       2       0       1       0       1       2       1
-       0       1       1       2       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       1       0       1       1       0       0       2       0       3
-       0       2       0       0       1       0       0       0       1       0
-       0       0       1       0       2       1       1       2       0       0
-       2       1       0       0       0       1       2       0       0       3
-       2       0       0       1       1       2       0       0       0       0
-       2       1       1       3       0       0       0       0       1       2
-       0       0       1       0       1       0       0       1       1       0
-       0       1       0       1       0       1       1       0       0       2
-       1       0       0       1       0       0       0       1       1       0
-       0       4       2       2       0       0       0       0       0       1
-       0       4       1       1       1       1       0       2       0       1
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       1       0       0       0       0
-       1       0       3       2       0       1       1       0       1       0
-       0       1       0       2       2       0       1       1       0       2
-       0       0       0       0       2       2       0       1       1       0
-       0       2       0       1       0       2       0       0       1       0
-       0       1       1       1       5       0       1       2       1       0
-       1       1       1       3       1       1       2       0       0       1
-       1       2       0       1       1       1       1       2       1       1
-       0       2       2       0       0       1       2       0       2       2
-       0       0       3       0       2       1       1       3       0       1
-       0       0       0       0       0       0       1       2       2       0
-       1       0       1       2       0       0       1       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       1
-       0       0       0       3       0       0       0       1       0       1
-       0       1       2       1       1       1       1       3       0       1
-       0       1       1       0       1       1       1       0       0       2
-       2       0       0       2       0       1       0       0       2       0
-       1       1       1       0       0       0       0       0       1       0
-       1       0       0       2       1       0       0       1       0       1
-       1       1       0       0       2       0       0       2       0       0
-       3       0       1       2       0       1       1       0       2       1
-       0       1       1       0       0       0       0       0       2       0
-       0       2       1       2       0       1       1       1       1       0
-       1       1       0       1       0       1       2       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       1       0       0       0       1       0       1       0       0       0
-       0       1       1       1       1       0       1       0       0       1
-       1       0       3       0       1       1       1       2       1       0
-       0       0       1       2       1       2       1       1       1       1
-       0       0       0       1       1       0       0       1       1       0
-       0       1       1       2       3       0       1       0       2       2
-       2       1       0       0       0       1       1       2       3       0
-       5       1       0       0       1       4       1       0       1       0
-       1       2       1       1       0       0       2       0       0       1
-       0       3       0       0       4       2       1       0       1       0
-       1       1       1       1       0       0       0       3       2       0
-       0       1       0       1       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       3       0
-       2       0       0       2       0       3       1       3       1       2
-       1       1       3       0       1       1       1       3       7       3
-       0       2       2       0       1       0       1       0       1       0
-       0       0       0       2       2       0       1       1       0       1
-       0       3       1       2       2       1       1       2       3       1
-       1       0       0       1       0       1       0       2       2       0
-       3       0       1       0       2       4       0       0       0       3
-       0       1       0       2       0       0       0       0       0       2
-       1       1       3       0       0       0       1       0       2       0
-       1       0       0       0       0       1       2       2       0       1
-       3       1       0       2       0       2       0       2       2       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       1       0       0       0       0
-       0       2       2       1       1       0       0       1       0       0
-       2       1       0       0       0       1       1       0       0       1
-       2       0       2       0       2       1       1       0       0       3
-       0       0       0       2       0       1       1       0       1       1
-       0       2       0       0       1       0       2       2       0       0
-       0       0       4       0       1       0       1       3       0       0
-       0       2       1       1       1       1       1       0       2       2
-       2       3       0       0       2       1       1       1       1       1
-       1       0       1       0       1       2       2       0       2       0
-       0       1       1       1       0       0       1       1       0       0
-       0       1       1       1       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       1
-       0       0       0       0       0       2       1       2       0       1
-       1       0       0       0       0       1       0       1       0       1
-       1       1       1       3       0       4       1       1       0       0
-       2       0       1       0       1       0       2       1       0       0
-       3       0       0       0       1       0       2       0       1       0
-       1       0       0       1       0       1       0       0       2       2
-       1       2       0       1       2       0       1       1       1       0
-       0       1       0       1       0       1       1       0       0       1
-       1       1       1       1       1       1       0       1       0       0
-       0       0       1       0       2       2       1       0       2       2
-       1       0       0       1       1       0       0       2       0       0
-       1       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       1       1       2       1       1
-       1       0       0       0       2       2       2       2       0       0
-       1       0       0       0       1       0       0       0       0       1
-       1       0       1       2       0       0       2       1       2       1
-       4       0       1       0       1       1       2       1       0       0
-       0       0       2       1       2       1       1       1       1       2
-       0       4       0       1       0       0       1       0       3       0
-       0       1       1       0       1       1       1       3       0       1
-       0       0       2       0       0       0       0       3       1       1
-       1       0       0       3       0       0       2       4       1       0
-       0       0       1       1       1       0       3       2       2       0
-       0       1       1       2       0       1       1       0       0       1
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       1       1       1       1       2
-       2       0       0       1       0       2       0       1       0       0
-       0       0       2       0       1       0       0       1       2       3
-       0       0       1       1       0       1       0       0       1       0
-       1       0       1       1       3       0       0       1       4       0
-       0       0       1       1       0       1       1       1       0       2
-       0       0       1       3       1       0       1       2       1       2
-       4       2       0       1       3       2       2       3       0       0
-       0       1       0       3       1       1       2       0       1       2
-       0       0       0       1       0       1       0       1       3       1
-       1       0       0       3       0       2       0       0       0       0
-       1       1       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       1       0       0       2       1       0       0       1
-       0       1       0       0       0       0       0       1       0       0
-       0       1       0       1       0       1       2       0       1       2
-       1       0       2       1       1       0       0       0       1       0
-       1       1       1       2       1       1       3       0       0       0
-       1       2       1       0       2       2       2       3       0       1
-       1       1       0       2       0       0       1       0       0       4
-       0       3       2       0       0       1       2       2       1       0
-       1       1       0       1       2       0       2       1       0       0
-       0       0       2       1       0       0       1       2       1       2
-       4       3       2       2       0       0       1       1       2       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       1       0       0       0       1       1       2       0       1       2
-       0       1       0       2       1       1       3       0       0       1
-       0       2       2       0       2       0       1       1       0       0
-       1       3       1       0       1       2       1       2       1       2
-       0       3       0       2       0       2       0       2       1       0
-       1       3       0       0       0       2       0       1       1       1
-       0       1       0       1       0       1       1       1       0       2
-       0       1       2       2       3       1       0       0       0       1
-       0       0       0       1       1       0       0       0       0       0
-       1       0       1       1       2       1       1       5       2       0
-       1       0       0       1       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       1
-       0       3       1       2       1       1       1       0       2       0
-       4       2       1       1       1       1       2       1       0       1
-       0       1       2       1       0       1       0       0       2       2
-       0       0       0       2       0       2       3       1       1       1
-       1       1       1       1       1       0       1       0       2       3
-       0       1       1       1       0       0       1       1       1       0
-       1       1       0       0       0       2       1       0       2       1
-       2       0       0       2       1       0       1       0       1       0
-       1       2       2       0       1       0       0       0       3       1
-       2       0       0       2       0       4       0       2       2       0
-       1       1       2       1       1       0       1       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       2       0       0       1       1       0       0       1       1       1
-       1       1       0       0       3       1       0       1       0       3
-       0       0       1       1       0       0       1       1       2       1
-       1       1       1       0       2       1       0       0       0       2
-       2       1       0       1       0       0       2       2       1       0
-       0       2       0       1       2       1       1       0       0       0
-       2       1       3       0       2       1       2       0       2       0
-       1       2       0       1       2       1       1       1       0       1
-       0       0       1       1       1       0       0       2       0       0
-       1       1       0       3       0       1       1       1       1       1
-       0       1       3       0       0       0       0       0       1       1
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       1       1       2       0       0
-       1       2       0       1       0       1       0       2       1       5
-       2       0       1       1       0       1       2       2       1       1
-       0       3       1       1       1       1       1       1       2       0
-       1       0       0       0       1       1       2       1       1       0
-       1       0       1       0       0       0       1       0       2       1
-       1       1       0       1       0       1       1       3       0       1
-       0       1       2       3       0       1       1       2       0       0
-       0       0       1       1       3       1       3       3       0       0
-       0       1       2       0       0       1       0       0       0       0
-       1       2       0       1       1       1       3       2       0       1
-       0       0       0       0       0       1       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       1       0       0       1       0       0       1
-       2       1       1       0       1       2       2       0       1       3
-       3       2       1       1       1       1       2       1       0       0
-       0       2       0       1       1       0       0       2       0       1
-       1       3       2       3       0       1       1       1       3       2
-       1       0       0       0       0       3       1       3       2       1
-       4       0       1       0       0       1       0       5       1       2
-       0       0       1       1       1       1       0       1       2       1
-       0       0       1       2       4       1       0       1       1       0
-       0       0       1       0       0       4       1       2       0       1
-       2       1       0       0       2       0       1       0       1       0
-       1       1       1       1       0       1       0       0       0       0
-       0       0       0       0       0       0       0       0       3       7
-       3       6       8       8       7       9       9      13       6       5
-       4       7       5       9       8       4       9       9      14       9
-       8       6      10      11       8      10       7       9       5       9
-      10       6       6      14       9      10       4       8      11      15
-      10      11       7      12      14      12      12      12      13      10
-       9       7      11      14       8      16      13      11      10      11
-      15      11      11      10      16      19       7      14      16      12
-      16      15      11       7      12      10       9      20      12      17
-      14       9       9      14      10       5      15       9      12       6
-       6       7       6      11      12       9       8       7      10       8
-       6       7       9       5       5       0       1       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       3       0       3       0       1
-       1       2       1       2       1       0       0       0       0       0
-       2       1       0       1       1       0       1       1       3       0
-       0       2       0       0       1       2       0       2       2       0
-       0       1       1       0       1       1       2       1       5       0
-       2       2       1       0       0       0       0       2       1       2
-       1       0       1       1       1       0       0       1       1       1
-       0       0       0       0       2       0       0       2       0       0
-       1       1       0       1       2       1       0       5       0       2
-       1       0       1       0       1       2       0       0       1       1
-       3       0       2       0       0       1       2       0       0       1
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       1       0       1       1       2       3       0
-       3       1       0       0       3       0       0       0       1       0
-       0       0       0       0       0       2       1       0       1       1
-       0       1       1       2       0       1       0       1       6       0
-       1       1       2       2       1       2       0       1       2       1
-       2       3       1       2       0       0       1       0       0       2
-       1       0       0       0       1       2       2       0       0       0
-       1       2       5       2       0       1       1       0       1       0
-       1       1       3       0       0       2       1       1       1       1
-       0       1       1       0       2       3       1       2       0       1
-       0       2       0       1       0       0       0       1       0       0
-       0       1       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       1       1       0       1       0       2
-       3       2       1       2       1       2       0       0       2       1
-       1       3       1       3       2       0       1       1       1       3
-       2       0       1       1       1       0       2       3       2       2
-       2       0       0       0       0       1       1       1       2       1
-       0       0       1       1       0       1       2       2       0       2
-       1       1       1       0       0       1       1       0       1       0
-       2       2       2       2       1       0       0       2       2       0
-       2       0       2       3       1       0       0       0       1       1
-       0       1       0       1       3       2       0       1       2       1
-       0       1       1       0       1       0       0       1       1       0
-       3       0       0       2       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       1       0       1       1       0       0       0
-       0       1       0       2       0       1       0       2       2       1
-       1       0       3       1       1       1       1       0       1       1
-       0       1       0       1       0       0       1       0       2       1
-       2       1       0       1       1       1       0       2       1       1
-       0       0       2       3       1       1       1       1       2       0
-       0       2       1       1       0       1       0       0       1       2
-       2       0       0       0       1       0       1       0       0       0
-       2       1       2       0       2       3       1       0       3       1
-       0       0       0       2       1       0       2       0       1       2
-       0       1       0       0       1       2       1       0       1       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       1       1       0       2       1
-       0       0       3       2       3       2       2       2       0       1
-       1       0       1       2       1       0       0       0       1       4
-       1       3       1       1       1       0       1       1       1       0
-       2       1       1       0       2       1       1       1       2       0
-       2       0       2       1       0       1       0       1       1       1
-       0       1       0       1       0       2       3       3       0       1
-       1       3       2       3       0       0       1       3       0       0
-       0       0       2       0       1       0       0       0       1       0
-       2       1       0       0       2       0       4       1       1       1
-       0       0       0       1       2       0       0       1       0       3
-       0       0       0       2       1       0       0       0       0       0
-       0       0       0       0       0       0       0       0       1       0
-       0       2       1       0       0       1       0       2       0       1
-       0       2       2       3       1       1       2       2       1       2
-       1       3       1       2       0       2       1       5       2       5
-       0       4       1       1       1       0       2       1       0       2
-       3       2       3       3       2       3       4       1       2       1
-       1       2       3       2       2       1       2       3       1       2
-       2       1       1       0       1       0       2       5       2       1
-       2       2       2       0       0       3       2       1       3       1
-       3       1       4       2       3       2       1       1       0       1
-       2       0       3       2       1       2       1       3       1       2
-       2       0       0       1       1       1       2       1       1       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       1       1       0       2       1       1       2       1       1       0
-       3       2       0       2       0       1       0       0       0       1
-       2       0       2       2       0       1       2       0       0       1
-       2       0       0       1       0       2       2       1       2       0
-       0       1       1       2       0       1       0       2       0       0
-       1       2       1       2       0       0       1       0       3       0
-       0       2       1       0       1       1       1       1       0       1
-       1       0       0       0       0       0       0       0       1       1
-       2       0       0       1       0       0       0       2       0       2
-       0       1       0       1       1       0       0       2       0       1
-       1       0       3       0       0       1       0       0       1       1
-       1       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       2       1       1       0       0
-       0       0       0       1       1       1       0       1       2       1
-       1       0       0       1       0       1       0       0       1       0
-       0       0       1       2       0       0       0       0       0       0
-       1       1       2       2       1       0       2       0       1       0
-       0       1       2       2       0       2       0       2       1       0
-       1       0       1       3       1       2       2       0       0       0
-       1       1       0       2       0       0       1       0       0       2
-       1       0       2       0       2       0       1       0       0       3
-       2       1       1       1       2       2       2       0       0       1
-       2       0       0       0       1       0       2       0       0       3
-       1       0       1       1       1       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       1       1       3
-       0       1       1       0       0       0       0       0       2       0
-       0       0       0       2       1       1       0       1       1       0
-       0       1       1       0       3       0       0       1       1       2
-       1       4       1       0       1       1       0       2       1       0
-       2       0       3       2       1       0       2       1       0       1
-       2       1       3       2       1       2       2       1       2       1
-       0       3       1       0       0       0       1       0       2       0
-       0       1       1       1       0       1       1       0       1       0
-       0       2       2       2       2       2       2       0       0       0
-       1       2       0       0       1       2       1       2       1       0
-       0       0       1       0       0       2       2       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       3       0       1       0       2       0       3       1
-       1       1       0       1       1       2       2       1       0       2
-       2       1       1       1       0       1       1       0       0       0
-       2       1       0       3       1       0       1       0       2       2
-       1       1       0       0       0       1       0       3       1       1
-       1       0       1       1       1       0       0       3       1       0
-       0       0       3       0       3       2       1       2       0       4
-       1       2       0       0       1       1       1       0       1       1
-       0       1       0       1       0       0       0       1       1       2
-       1       2       0       3       1       1       1       2       2       0
-       1       0       0       1       1       0       2       1       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       1       2       0       1       1       1       0
-       1       0       2       2       1       0       1       0       2       0
-       2       2       0       0       0       0       1       1       2       1
-       1       0       3       2       1       1       0       2       0       0
-       1       1       0       3       0       3       1       1       1       1
-       4       0       2       0       1       0       1       1       0       1
-       1       1       1       0       1       1       0       1       0       0
-       2       0       2       1       1       2       1       2       0       0
-       0       0       1       3       0       1       1       0       1       0
-       1       3       0       1       0       1       0       0       0       0
-       2       0       0       0       1       1       3       2       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       2       0       1       0
-       3       1       1       1       0       1       1       0       3       0
-       0       0       2       0       5       1       2       1       1       0
-       1       1       0       2       0       0       0       1       2       0
-       1       1       0       1       0       0       0       0       0       1
-       0       1       0       0       5       3       0       1       1       2
-       1       0       1       1       0       0       1       1       1       1
-       1       1       1       0       1       2       0       1       0       1
-       1       1       0       0       2       0       3       1       0       0
-       0       0       1       0       1       0       2       1       0       0
-       1       0       1       1       0       1       1       0       0       2
-       0       0       0       0       1       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       2       1       2
-       2       3       4       2       2       3       1       2       2       2
-       2       3       8       1       4       3       3       4       3       4
-       4       3       6       0       3       0       6       7       1       5
-       6       3       2       1       6       7       4       1       4       1
-       4       5       4       5       5       5       3       5       5       4
-       4       7       5       5       0       3       2       5       5       7
-       2       4       4       3       2       6       5       4       0       7
-       1       3       2       3       0       1       4       2       2      10
-       5       6       2       2       4       1       4       2       3       3
-       3       2       2       5       1       4       3       5       1       3
-       5       3       2       4       0       2       2       1       3       0
-       1       0       0       0       0       0       0       0       0       0
-       0       0       0       1       0       0       0       0       0       1
-       1       1       0       1       0       0       0       0       0       0
-       1       3       1       2       0       1       2       0       0       1
-       0       1       1       0       0       0       5       2       0       2
-       1       0       2       3       0       0       1       2       0       2
-       0       2       0       2       1       1       1       1       0       2
-       0       0       1       2       2       1       1       1       0       1
-       1       1       1       1       1       2       1       2       2       1
-       1       1       2       0       0       1       3       1       0       2
-       0       2       1       1       1       1       1       1       2       0
-       1       0       0       1       1       0       3       0       2       0
-       0       1       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       1       1       3
-       0       0       1       0       0       0       0       1       2       0
-       0       3       1       1       0       0       1       0       1       1
-       1       0       0       1       1       0       1       0       1       2
-       1       3       1       2       0       0       0       1       1       1
-       1       1       0       0       2       0       1       2       3       2
-       3       0       2       1       0       1       0       0       0       2
-       2       0       0       0       1       1       4       1       3       2
-       4       1       0       2       0       3       1       1       2       2
-       0       1       0       1       2       0       1       2       1       0
-       1       1       0       0       4       1       0       0       1       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       1       0       2
-       0       1       0       0       1       2       1       1       2       0
-       2       1       2       0       0       1       1       0       0       2
-       1       0       0       1       0       0       0       1       0       0
-       3       2       1       0       2       0       0       0       1       2
-       0       0       2       1       1       2       1       1       0       0
-       0       1       0       1       2       0       1       2       2       0
-       1       0       1       0       0       0       1       0       1       0
-       2       1       0       1       0       0       0       1       1       1
-       1       0       0       1       0       0       0       1       2       3
-       1       0       1       2       2       2       0       1       1       2
-       1       0       0       2       0       1       0       0       2       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       1       0       0       3       1       0       2       1       1
-       1       0       1       0       1       1       2       0       0       1
-       1       2       0       2       0       1       0       1       1       1
-       0       0       2       0       2       0       2       2       0       1
-       1       0       0       2       2       0       1       0       1       2
-       1       1       1       1       3       0       2       2       1       0
-       0       0       0       0       0       1       0       1       2       1
-       2       1       1       0       1       0       0       1       3       0
-       1       2       0       3       1       0       1       2       0       0
-       0       1       3       1       2       0       0       1       1       1
-       1       0       1       0       1       3       1       0       1       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       1       1       0       1       1       0       0       1
-       0       1       0       0       0       1       1       0       1       1
-       0       0       1       1       0       1       0       1       1       3
-       0       2       2       0       0       2       1       2       3       1
-       1       1       0       1       2       0       0       2       1       1
-       0       0       1       2       3       1       1       0       0       1
-       0       0       1       2       0       1       1       0       1       0
-       1       2       1       0       0       1       0       1       2       0
-       0       0       0       1       0       0       1       1       2       0
-       2       1       1       2       1       0       1       2       0       0
-       1       0       2       1       0       1       0       0       0       0
-       1       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       2       1       0
-       0       0       0       2       0       1       0       2       1       0
-       1       0       2       1       1       0       1       1       0       0
-       2       1       0       0       0       0       2       0       3       0
-       0       1       0       2       5       2       0       0       1       0
-       1       1       1       2       1       1       1       0       0       2
-       0       0       3       1       2       0       1       2       2       3
-       2       1       0       1       0       0       1       2       1       3
-       2       0       2       1       0       1       1       0       1       2
-       0       0       0       0       0       0       1       1       0       0
-       0       0       0       1       1       0       0       0       0       0
-       1       1       1       0       0       0       0       1       0       0
-       0       0       0       0       0       0       0       0       0       3
-       0       0       1       2       1       0       1       2       2       0
-       1       3       1       3       3       2       3       3       1       1
-       2       0       2       3       3       3       1       3       2       6
-       0       1       1       2       2       1       3       4       2       3
-       1       4       2       3       2       1       4       2       2       1
-       2       4       3       4       3       3       2       1       3       5
-       0       1       5       2       2       1       1       0       2       3
-       1       0       1       2       1       4       2       4       1       2
-       5       2       3       1       1       2       2       2       1       1
-       3       1       2       2       2       0       1       2       2       5
-       4       3       1       1       3       3       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       1       1       0       0       1       2       1
-       0       1       1       2       0       0       1       0       0       0
-       3       1       1       1       2       2       0       0       1       0
-       1       1       1       1       0       3       2       0       2       0
-       2       1       0       0       1       0       1       0       0       1
-       1       0       1       1       0       2       0       1       0       1
-       1       1       0       1       2       3       4       0       1       0
-       0       0       0       0       1       0       0       2       2       0
-       3       1       0       0       1       1       1       2       1       0
-       0       1       0       0       1       2       0       1       2       0
-       2       1       0       1       1       0       0       1       0       0
-       1       0       0       0       0       0       0       0       0       0
-       0       0       0       0       1       2       0       2       0       2
-       1       0       1       0       0       1       2       2       1       1
-       1       1       1       1       1       1       0       1       0       0
-       1       0       2       0       2       0       3       0       1       1
-       0       1       0       2       1       0       0       0       1       3
-       0       1       0       0       1       0       0       3       1       0
-       1       1       0       0       0       2       1       0       0       0
-       0       1       1       0       1       1       1       1       1       1
-       1       2       1       0       0       1       1       2       1       0
-       1       1       1       0       0       0       0       1       1       0
-       0       1       2       0       0       2       0       1       0       1
-       1       1       1       1       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       2       0
-       1       0       0       0       1       0       0       2       0       0
-       0       2       0       1       1       0       0       1       0       0
-       0       0       0       0       1       0       1       0       1       0
-       0       2       1       0       2       0       0       1       0       1
-       1       0       2       1       0       0       3       1       1       0
-       1       1       0       1       1       1       2       0       1       0
-       1       1       1       1       1       0       0       1       0       1
-       0       1       2       1       3       1       1       0       0       1
-       0       3       0       0       1       3       0       2       1       2
-       1       1       0       0       1       2       1       1       0       0
-       0       2       0       2       0       1       0       0       2       1
-       0       0       0       0       0       0       0       0       0       0
-       0       0       2       0       0       1       0       1       1       1
-       1       1       1       0       1       1       0       1       0       1
-       1       1       1       2       0       0       2       1       0       1
-       2       2       1       0       0       0       3       1       0       2
-       0       0       1       1       0       0       1       2       2       0
-       1       1       2       0       2       3       3       0       1       0
-       1       0       0       2       1       0       0       1       1       0
-       3       2       1       0       2       0       0       1       0       1
-       3       1       1       1       1       0       1       2       1       0
-       2       0       1       0       3       0       0       1       0       1
-       0       3       1       2       0       0       0       1       0       0
-       0       1       0       1       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       1
-       1       1       1       0       0       1       1       0       0       2
-       0       0       0       1       1       1       1       3       3       1
-       0       1       0       0       0       0       1       0       0       0
-       1       0       2       0       0       1       3       3       1       2
-       0       0       0       2       0       1       0       1       1       1
-       1       2       1       2       0       1       1       1       1       0
-       0       2       0       0       1       1       1       0       0       1
-       0       3       0       0       1       1       1       1       1       1
-       1       0       0       0       1       1       2       1       3       2
-       1       0       0       2       2       0       0       1       0       0
-       1       1       3       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       1
-       0       0       2       0       1       1       1       0       0       0
-       1       0       0       0       0       0       0       0       0       0
-       0       0       0       2       0       1       0       0       0       0
-       2       0       0       1       0       3       0       1       1       0
-       0       0       1       1       1       1       0       2       0       1
-       1       0       0       2       0       0       0       0       1       0
-       1       1       1       0       2       1       1       0       0       1
-       0       0       1       1       0       2       1       2       0       0
-       1       0       2       1       1       0       0       2       0       0
-       2       1       1       0       1       0       2       2       0       0
-       0       1       1       0       0       0       2       1       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       1       0
-       1       1       0       0       1       0       1       1       1       1
-       2       0       1       0       0       0       2       1       1       0
-       1       1       0       2       1       0       0       4       0       0
-       0       2       1       0       0       2       1       1       1       1
-       1       2       1       2       2       1       2       1       1       0
-       1       0       0       0       1       0       0       1       0       2
-       2       0       1       0       1       0       2       0       1       1
-       2       1       0       0       1       1       1       1       1       1
-       0       0       1       1       0       0       2       0       0       3
-       2       2       0       1       2       0       2       0       1       1
-       0       2       0       2       1       1       0       0       0       1
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       1       2       2       0       1       1
-       2       2       3       0       2       1       0       1       3       1
-       2       4       1       0       4       1       1       4       2       0
-       3       1       3       2       0       0       1       2       1       3
-       1       1       1       2       1       0       2       0       2       3
-       0       0       1       2       1       0       0       3       1       0
-       2       2       2       0       0       0       0       2       0       1
-       1       2       1       1       1       0       4       3       1       1
-       1       4       1       1       0       2       2       1       2       2
-       0       2       1       1       3       1       0       5       1       0
-       2       1       1       1       2       2       3       1       2       1
-       3       2       1       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       1       0       1       0       4       2       1       1       0       0
-       0       1       3       0       0       1       0       2       2       3
-       0       2       1       2       2       0       0       0       1       1
-       0       0       1       1       0       0       1       0       2       0
-       2       0       1       3       1       0       0       3       1       1
-       0       1       0       2       0       2       0       3       1       1
-       0       1       2       0       1       0       2       1       3       0
-       0       2       0       1       1       0       2       1       0       5
-       0       0       1       2       1       1       1       1       0       1
-       2       2       1       2       2       1       1       2       1       0
-       1       0       0       1       0       0       1       1       1       0
-       0       0       0       0       0       0       2       0       0       1
-       2       0       0       0       1       2       2       0       0       0
-       1       1       3       1       1       0       1       3       2       2
-       1       1       1       1       0       0       1       1       1       0
-       2       0       0       1       1       0       2       0       1       0
-       0       1       1       2       2       3       0       1       1       1
-       0       0       0       1       1       1       0       0       0       3
-       2       1       0       0       1       0       2       1       2       0
-       0       0       2       0       0       1       0       0       2       0
-       2       0       0       1       2       3       0       1       0       1
-       0       2       1       0       0       0       1       2       0       0
-       2       0       2       2       0       0       0       0       1       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       1
-       1       0       2       1       0       1       1       3       2       1
-       0       3       0       0       2       1       0       1       0       0
-       2       2       0       1       0       1       0       3       2       0
-       0       1       1       1       3       1       1       1       2       0
-       0       0       0       1       1       2       2       0       1       1
-       2       1       0       1       3       3       2       1       0       2
-       1       0       1       1       0       1       2       1       1       0
-       1       1       0       1       0       1       3       0       1       3
-       2       1       3       1       0       0       0       0       0       0
-       0       0       0       1       2       0       2       0       0       2
-       0       3       2       0       2       1       4       3       1       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       1       0       1       1       0
-       1       2       1       1       2       0       1       0       0       0
-       0       2       1       0       1       1       2       1       1       0
-       0       1       1       2       2       0       5       0       2       1
-       0       2       3       2       4       1       1       2       3       0
-       3       4       2       2       1       1       3       1       2       1
-       0       0       0       1       2       1       3       1       2       0
-       0       1       2       0       1       1       1       1       2       1
-       2       2       1       0       3       1       1       1       2       0
-       0       1       0       2       2       1       2       1       0       0
-       1       0       1       0       3       0       1       1       0       2
-       2       2       0       1       1       1       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       1       1       1       0
-       1       0       1       2       2       4       1       0       2       1
-       1       2       0       2       1       0       0       1       2       1
-       1       1       0       2       2       2       0       2       0       3
-       1       0       0       0       0       3       4       0       1       1
-       1       4       0       3       0       2       3       2       0       3
-       1       0       0       0       1       0       1       0       0       3
-       0       0       0       0       1       0       0       0       1       1
-       2       0       0       3       0       1       0       1       1       0
-       1       0       0       1       0       1       0       0       1       1
-       1       1       0       0       1       0       0       1       0       3
-       1       1       0       1       1       1       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       1       2       0       0
-       0       1       1       0       0       2       0       0       1       0
-       1       1       0       1       1       1       0       0       0       1
-       0       0       1       0       2       2       0       2       2       0
-       1       1       0       1       1       0       0       1       2       0
-       0       0       1       2       1       0       0       0       0       2
-       0       0       2       1       0       0       1       0       0       0
-       4       0       0       0       0       1       1       1       0       2
-       0       0       0       0       1       1       1       1       1       2
-       1       2       0       0       0       0       2       0       2       0
-       0       1       0       1       2       3       0       3       0       0
-       1       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       3       3       1       0       0       3       1       1       1       1
-       1       3       0       0       1       1       1       0       0       0
-       1       0       1       3       1       0       2       3       4       1
-       1       2       2       3       2       1       1       1       2       2
-       1       1       1       2       1       0       1       0       1       1
-       0       0       1       1       0       0       3       1       1       1
-       2       3       3       2       1       0       2       2       3       4
-       1       2       1       1       1       0       0       1       1       1
-       1       1       2       1       0       3       2       0       0       0
-       0       1       1       0       1       0       0       1       0       0
-       3       0       2       3       2       0       1       0       0       0
-       0       0       0       0       0       0       0       0       0       2
-       1       1       0       0       0       1       2       2       1       0
-       3       1       0       2       0       2       0       0       1       0
-       0       1       1       0       0       0       1       2       0       1
-       0       1       0       0       1       1       1       1       1       0
-       1       1       0       1       5       0       1       0       3       2
-       1       2       1       1       2       1       2       0       1       0
-       2       1       0       1       3       1       1       0       0       1
-       0       2       1       1       2       2       2       0       2       2
-       1       1       1       2       1       3       0       2       3       3
-       1       1       1       1       1       2       2       1       0       0
-       3       1       0       1       1       0       1       0       1       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       1
-       1       0       0       1       0       2       0       0       0       0
-       1       1       1       1       0       0       1       0       0       0
-       1       1       1       0       0       2       0       1       1       0
-       0       1       1       0       2       1       1       0       1       3
-       1       0       0       1       0       0       2       1       1       1
-       1       2       3       0       2       1       1       2       1       0
-       2       0       1       0       2       1       2       0       1       0
-       0       0       0       0       0       3       0       0       2       0
-       1       0       2       0       0       1       2       2       1       2
-       0       1       1       0       0       0       0       1       0       0
-       3       1       1       1       1       1       2       0       1       0
-       0       0       0       0       0       0       0       0       0       0
-       1       1       0       1       2       0       2       1       2       1
-       0       0       0       1       0       0       0       0       1       0
-       0       2       1       0       0       0       1       1       2       1
-       1       1       1       0       1       3       3       0       0       0
-       0       2       0       0       0       0       1       2       2       1
-       2       0       0       0       1       0       0       0       1       2
-       1       0       1       1       4       0       3       0       0       0
-       1       0       2       1       0       0       2       3       2       1
-       1       1       0       1       2       3       0       2       2       0
-       1       3       0       2       3       0       0       2       3       0
-       4       3       0       1       0       1       0       1       1       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       1       1       1       0
-       3       0       0       4       1       1       1       1       0       1
-       2       0       1       0       2       1       2       2       1       0
-       1       1       1       0       0       0       1       2       2       2
-       0       0       0       1       0       2       0       0       1       2
-       1       0       1       2       2       1       2       1       0       0
-       1       1       1       0       0       6       0       2       1       0
-       0       2       0       0       0       0       1       1       0       2
-       1       2       0       1       1       0       0       1       2       0
-       2       0       1       0       0       1       3       0       0       2
-       3       2       1       0       0       0       1       0       1       2
-       0       0       1       1       1       0       1       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       1       0       1       1       0       0       1       2
-       0       2       3       3       0       2       0       0       0       0
-       0       0       0       0       0       1       1       3       2       0
-       0       1       1       0       1       0       1       3       1       0
-       1       0       0       2       1       0       1       1       2       0
-       1       0       0       1       0       3       1       2       0       3
-       3       0       0       0       1       0       1       1       0       1
-       0       0       0       0       1       1       1       0       0       1
-       1       0       2       1       1       0       0       2       0       1
-       0       0       1       0       1       1       1       0       2       0
-       0       1       0       1       0       0       1       0       0       0
-       0       0       1       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       2       1       0       2       2       3       1       0       1
-       0       0       0       0       0       1       2       1       0       2
-       1       1       0       1       2       2       1       1       0       0
-       1       0       2       3       1       1       0       0       1       0
-       1       2       0       0       1       0       2       0       0       2
-       0       0       0       0       0       0       0       1       1       1
-       4       0       0       1       1       0       2       0       0       1
-       1       0       2       0       2       3       2       2       1       0
-       1       0       1       3       2       0       2       0       1       2
-       2       2       1       1       2       0       1       1       1       1
-       1       1       0       2       1       1       2       0       1       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       1       0       0       3       1       1       1
-       0       2       0       1       1       0       0       0       2       0
-       0       0       2       1       1       0       1       0       1       1
-       0       2       0       1       0       2       1       0       1       1
-       0       1       0       2       0       0       0       0       0       0
-       1       0       1       0       0       1       1       1       1       1
-       0       3       1       1       1       0       0       1       1       1
-       0       0       0       2       1       2       1       1       2       0
-       0       0       2       1       0       1       3       0       0       0
-       0       0       3       0       1       1       1       2       2       1
-       0       0       1       0       0       2       1       0       1       1
-       0       0       1       1       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       2       1       1       1       1       0       1       1       2
-       1       1       0       0       1       2       0       2       0       2
-       1       0       1       0       0       0       0       0       2       1
-       1       0       1       0       1       2       2       0       0       1
-       1       0       2       0       0       1       2       2       1       1
-       1       1       4       1       1       2       1       0       1       0
-       0       1       2       0       1       0       0       1       1       1
-       1       0       0       3       1       0       0       1       3       1
-       1       0       1       3       0       1       0       1       4       1
-       0       0       0       1       0       1       1       1       1       0
-       0       0       0       1       1       1       0       0       1       0
-       0       0       0       0       0       0       0       0       0       2
-       0       4       0       3       1       1       1       1       1       0
-       2       0       2       1       2       1       1       1       1       0
-       1       1       0       0       0       0       0       2       0       1
-       0       0       0       2       1       1       0       1       0       0
-       0       0       0       1       0       0       0       1       2       1
-       2       0       2       0       2       2       2       1       0       1
-       1       0       2       0       2       1       0       4       1       0
-       0       0       1       2       0       0       3       0       0       0
-       2       1       1       5       0       2       2       0       2       1
-       0       5       0       0       0       0       0       2       2       1
-       0       0       0       0       0       1       1       2       1       2
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       1       1       1       2       0       0
-       2       0       1       0       1       0       0       0       2       1
-       0       0       1       0       2       1       1       1       2       0
-       0       2       0       4       1       1       0       0       0       0
-       2       0       1       0       1       0       2       0       0       0
-       0       1       1       2       1       0       1       1       1       2
-       1       4       1       3       0       1       0       1       0       0
-       1       1       0       2       1       0       2       0       1       0
-       0       2       0       1       1       1       1       1       0       1
-       2       0       1       0       0       0       0       0       2       0
-       0       2       3       0       0       1       0       1       0       2
-       0       0       1       2       2       1       0       0       1       0
-       0       0       0       0       0       0       0       0       0       2
-       1       0       1       1       1       1       0       1       0       1
-       2       2       0       1       0       0       0       1       2       1
-       1       1       1       1       1       0       1       1       1       0
-       0       0       0       1       1       1       0       2       0       0
-       0       2       2       2       0       0       0       0       1       1
-       1       1       1       0       1       0       1       1       1       1
-       0       0       1       0       0       2       1       1       3       0
-       1       0       1       1       1       2       1       1       1       1
-       0       3       2       4       0       0       1       0       0       1
-       0       1       0       1       1       0       2       1       0       0
-       1       1       1       1       1       1       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       1       1       0       0
-       2       2       0       1       0       2       2       1       1       0
-       0       1       1       2       1       1       1       1       1       3
-       2       4       1       1       2       1       0       0       1       0
-       1       2       1       1       1       0       0       1       0       0
-       1       1       0       2       2       4       0       1       2       0
-       1       3       2       1       1       3       1       1       0       1
-       1       0       0       2       1       0       0       0       1       0
-       1       0       1       2       0       1       1       2       1       0
-       0       1       2       1       0       1       1       1       1       0
-       0       0       1       0       1       1       1       1       2       0
-       1       1       2       0       0       0       0       0       0       0
-       0       0       0       0       0       0       1       1       0       0
-       0       2       0       3       2       0       0       3       4       1
-       2       1       1       0       1       2       2       1       0       0
-       0       0       3       1       1       1       1       1       2       2
-       1       0       0       0       0       1       0       2       1       1
-       2       0       3       1       1       2       0       0       2       1
-       2       1       0       1       0       1       0       1       0       1
-       1       0       0       0       0       1       2       1       0       1
-       0       2       1       1       2       0       1       1       1       0
-       0       0       5       0       1       1       0       0       2       1
-       0       0       2       0       2       3       0       2       1       0
-       0       1       0       1       0       0       0       1       2       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       1       0       0       0       3       0       2       2
-       1       0       0       0       1       1       0       1       0       1
-       1       1       1       0       0       2       0       1       1       2
-       1       0       0       1       1       0       1       1       0       2
-       1       2       0       0       1       1       0       1       2       0
-       0       0       3       1       0       0       1       0       1       1
-       2       1       1       3       2       1       1       0       2       1
-       2       0       0       0       4       3       3       0       0       1
-       1       0       1       0       1       2       2       0       1       1
-       3       2       0       0       0       0       1       1       0       1
-       3       0       0       0       0       0       1       1       2       1
-       1       0       0       1       2       0       0       0       0       0
-       0       0       0       0       0       1       0       0       0       1
-       1       2       0       1       0       0       0       0       1       1
-       0       0       1       0       2       0       3       0       1       1
-       4       3       2       0       0       3       0       1       0       2
-       1       1       0       3       0       0       2       2       1       1
-       2       2       0       0       0       3       1       0       0       3
-       0       1       2       1       1       0       0       0       0       2
-       1       0       2       1       0       2       0       1       0       1
-       1       0       1       0       1       1       0       1       1       3
-       2       0       1       3       1       0       0       3       1       3
-       1       0       1       0       0       1       3       2       0       0
-       1       3       0       2       1       1       2       1       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       1       1       3       2       0       0
-       0       1       2       1       1       1       1       0       0       2
-       1       1       0       0       0       1       0       2       1       0
-       0       0       1       0       1       1       1       0       1       0
-       1       1       0       2       2       0       1       1       0       2
-       2       1       2       3       0       2       2       2       2       0
-       1       0       1       1       1       0       1       1       0       0
-       1       1       0       1       1       1       1       0       1       1
-       0       0       0       0       1       1       1       2       0       2
-       1       1       0       2       0       1       1       1       0       1
-       0       1       0       2       1       2       1       0       0       1
-       0       1       0       0       0       1       0       0       0       0
-       0       0       0       0       0       0       1       0       0       2
-       0       3       1       0       0       3       2       0       2       1
-       0       0       1       1       0       1       1       1       0       0
-       4       1       0       0       3       3       1       2       1       2
-       0       1       1       1       2       1       2       1       0       1
-       1       1       1       1       1       1       0       1       1       0
-       0       1       0       0       0       1       2       2       1       1
-       0       0       1       0       0       1       1       1       0       1
-       1       0       0       1       0       1       0       1       0       0
-       4       1       4       0       0       0       3       0       1       2
-       1       0       1       3       0       0       0       1       1       0
-       0       1       0       2       0       0       1       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       1       0       0       0       1       3       0       1       1
-       0       0       2       0       1       2       1       1       2       2
-       3       0       2       2       1       2       1       1       2       1
-       2       0       0       1       0       0       2       0       0       1
-       0       1       1       0       0       0       1       0       1       0
-       2       1       1       0       0       0       0       1       1       0
-       0       0       0       0       0       4       0       1       1       1
-       2       0       1       1       1       0       0       1       0       0
-       1       0       0       1       1       0       1       0       0       1
-       2       2       1       2       2       1       0       0       0       2
-       0       0       2       1       0       0       3       1       2       0
-       1       1       0       0       0       0       0       0       0       0
-       0       0       1       1       0       1       2       1       2       0
-       1       2       1       0       0       1       1       1       0       0
-       1       0       1       1       0       3       3       0       1       0
-       2       2       1       2       1       2       1       1       2       1
-       1       0       1       1       0       0       1       2       0       2
-       0       0       0       0       1       0       0       1       1       0
-       0       1       0       1       0       0       0       1       1       1
-       0       0       1       1       0       0       1       1       2       1
-       0       0       0       1       1       1       0       1       1       1
-       0       0       1       1       1       1       3       0       2       2
-       2       0       0       2       3       0       1       0       1       0
-       1       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       1       1       0       0       0       2       4       0       0       5
-       0       1       1       2       2       3       0       1       2       0
-       0       0       2       3       4       3       6       0       0       1
-       4       0       3       1       3       1       1       0       0       1
-       1       1       2       2       2       0       3       2       1       1
-       0       2       0       0       3       0       2       2       5       1
-       1       1       0       1       0       0       3       0       3       2
-       0       1       1       1       0       2       2       0       0       0
-       2       3       3       0       0       1       2       5       3       1
-       1       1       0       0       1       1       0       3       4       0
-       2       1       0       0       3       1       0       0       0       0
-       0       0       0       0       0       0       1       2       1       2
-       1       3       1       2       0       6       0       1       1       3
-       1       2       2       0       3       0       0       4       4       0
-       1       0       1       1       0       1       2       0       1       1
-       2       1       3       1       2       1       1       0       2       0
-       1       0       2       1       1       0       2       1       1       3
-       1       0       2       0       1       1       0       3       4       2
-       0       1       0       0       1       2       2       0       1       1
-       1       0       0       2       3       0       0       0       2       1
-       0       1       1       1       4       2       3       2       2       2
-       1       0       1       1       1       1       1       1       1       1
-       4       4       2       0       1       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       1       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       1       1       2
-       5       3       1       2       0       0       0       0       0       0
-       0       1       0       0       0       0       1       1       0       0
-       5       2       1       5       3       1       2       0       3       2
-       0       0       2       1       0       0       0       0       0       0
-       0       1       0       3       2       2       1       0       0       1
-       0       1       1       3       2       1       0       3       0       1
-       0       2       1       0       1       1       1       1       0       1
-       1       1       1       2       0       1       1       0       0       2
-       1       1       2       0       0       0       1       1       0       1
-       0       1       1       2       2       2       2       0       0       1
-       3       1       1       0       0       0       1       2       0       1
-       0       0       0       0       2       0       1       0       0       2
-       1       0       1       1       3       0       1       0       0       0
-       1       1       1       1       0       4       3       2       0       0
-       0       0       0       0       0       1       0       1       0       1
-       0       4       0       1       0       5       1       3       0       2
-       0       1       1       1       1       2       0       0       0       0
-       0       1       0       0       0       0       0       0       2       3
-       0       0       2       0       2       1       0       3       4       1
-       1       2       1       1       0       0       1       1       0       0
-       1       3       2       1       0       1       3       0       1       2
-       1       0       1       1       1       0       1       1       1       0
-       0       1       0       1       0       0       0       0       1       0
-       0       0       0       0                                                
-SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS
-       2      23      25  123944       0       1                                
-FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
-       6       1                                                                
-            time         monitor       Total Cou     angles*1000                
-  0.35870000E+05  0.30000000E+06  0.16471000E+05  0.15255200E+06  0.40200000E+03
-  0.50810000E+05                                                                
-IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
-   16384                                                                        
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       1       0       1       0       1       1       0
-       0       0       0       0       2       0       0       0       0       0
-       0       0       0       0       0       0       2       0       0       0
-       0       2       2       2       0       0       0       0       0       0
-       2       1       0       1       1       0       1       0       1       0
-       0       0       0       0       1       1       0       1       0       2
-       0       0       1       1       0       0       0       0       1       0
-       0       0       0       1       2       0       1       0       1       0
-       0       1       0       2       0       1       0       1       2       1
-       1       1       0       1       0       1       0       1       1       2
-       0       0       1       0       0       0       1       0       1       0
-       0       2       0       0       1       1       1       1       1       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       1       0       1       1       2
-       0       0       0       0       1       0       0       1       0       2
-       0       1       0       2       1       0       1       0       2       0
-       1       0       0       1       1       0       1       0       0       1
-       0       1       0       0       1       0       0       2       2       2
-       2       0       1       0       0       0       1       0       0       2
-       2       0       1       0       0       1       2       1       1       0
-       0       1       0       0       1       3       0       2       0       0
-       2       1       1       0       2       0       3       0       0       1
-       1       1       1       1       0       0       0       2       1       2
-       2       0       0       1       0       0       1       0       1       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       2       0
-       0       1       0       0       2       2       1       0       1       1
-       0       0       0       0       1       1       1       0       0       0
-       0       0       0       0       0       0       0       1       2       0
-       0       2       1       2       0       1       1       0       0       0
-       0       0       0       1       1       0       0       0       0       1
-       0       1       0       1       0       1       1       0       0       1
-       0       0       2       1       1       1       1       0       0       0
-       0       1       0       0       0       0       1       1       1       1
-       0       1       1       0       0       0       0       0       1       1
-       0       1       0       1       0       0       0       1       1       0
-       0       0       1       1       0       2       1       0       1       0
-       0       0       0       0       0       0       0       0       0       0
-       0       1       1       0       0       0       0       0       0       0
-       1       2       0       0       0       1       0       0       0       1
-       3       0       0       1       0       0       2       0       0       1
-       0       1       1       1       2       1       0       0       1       2
-       0       2       2       0       2       1       1       0       0       0
-       1       1       0       2       0       0       0       1       0       1
-       0       0       0       1       1       1       2       0       0       1
-       0       1       0       1       1       0       0       2       0       0
-       0       0       2       1       2       0       0       1       1       0
-       0       0       2       0       1       0       1       0       2       0
-       3       0       4       0       0       1       0       1       0       0
-       0       1       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       2       0       1       0
-       1       0       0       1       0       2       1       0       0       2
-       1       2       0       1       1       0       0       1       2       0
-       2       2       0       0       4       0       0       1       2       0
-       0       0       1       0       2       1       0       1       1       2
-       0       0       1       0       1       0       0       0       1       0
-       0       1       0       0       0       2       0       0       0       0
-       0       0       3       0       0       0       0       1       0       0
-       0       0       1       1       1       2       1       1       0       0
-       0       1       1       0       2       1       2       0       1       0
-       0       0       3       1       0       2       1       1       0       1
-       1       1       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       2       0       0       1       0       0
-       1       0       0       0       0       0       2       0       1       0
-       1       0       0       0       0       1       0       0       0       0
-       3       1       1       1       3       0       1       0       0       2
-       0       1       1       1       1       1       0       2       0       0
-       0       2       0       1       0       0       0       0       1       3
-       0       0       2       1       0       1       1       0       0       1
-       1       2       1       0       0       1       0       0       1       0
-       1       1       1       1       0       1       0       1       1       0
-       1       1       0       0       0       0       0       0       2       1
-       2       1       1       0       1       0       1       0       1       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       1
-       1       0       0       1       0       1       2       4       0       1
-       3       2       5       6       3       3       3       5       4       3
-       3       3       4       4       2       3       4       2       4       3
-       4       3       7       2       9       6       5       4       5       7
-       5       7       8       2       2       6       4       3       7       5
-       3      12       5       7       5       5       9       7       7       7
-       5       5       7       3       2       6       3       2       3       8
-       6       4      10       1       6       5       5       6       3       4
-       9       5       2       4       2       3       4       2       4       2
-       4       3       1       4       5       3       3       0       4       3
-       0       3       1       2       0       1       2       1       2       0
-       1       0       0       0       0       0       0       0       0       0
-       1       0       2       2       2       5       2       1       1       5
-       4       4       1       2       2       1       2       3       2       7
-       1       1       4       5       1       3       1       1       1       2
-       4       5       1       3       1       2       6       2       2       8
-       4       3       4       6       4       3       2       5       2       1
-       2       6       7       2       4       6       2       4       3       3
-       5       5       4       3       6       4       7       5       1       4
-       5       2       5       4       3       5       4       9       2       3
-       1       3       3       1       2       0       5       1       3       2
-       4       0       1       3       5       2       4       3       3       1
-       0       1       3       2       3       3       1       2       1       2
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       1       1       2       0       3       0
-       0       1       4       3       4       1       1       0       5       6
-       3       3       0       5       3       2       6       1       3       0
-       6       2       2       4       4       4       2       4       4       2
-       4       2       3       1       2       2       1       4       1       1
-       4       4       4       2       2       0       2       1       4       4
-       3       4       2       0       2       0       6       1       2       4
-       3       5       4       4       3       4       4       2       7       2
-       2       0       3       3       3       2       1       2       6       2
-       5       0       4       1       1       4       3       0       3       3
-       1       1       3       1       2       4       3       3       2       3
-       1       3       2       0       0       0       0       0       0       0
-       0       0       0       3       0       0       0       3       3       3
-       0       2       1       2       1       3       2       2       0       0
-       2       3       1       3       1       3       3       3       2       1
-       4       5       3       4       2       2       4       0       1       2
-       0       1       5       2       3       2       2       4       3       1
-       2       2       1       1       2       1       0       4       3       1
-       3       1       3       1       2       4       1       2       2       2
-       2       0       5       1       3       2       4       1       1       3
-       2       2       0       2       1       3       5       1       3       1
-       0       3       2       5       2       1       1       3       3       2
-       0       2       3       3       4       2       2       1       2       1
-       2       1       0       4       3       0       1       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       1
-       0       0       1       2       1       1       0       3       0       1
-       2       3       3       1       3       0       0       0       0       1
-       2       2       1       2       1       2       1       2       0       1
-       2       2       3       0       3       2       3       1       4       0
-       0       1       2       1       0       1       1       3       3       0
-       2       2       2       1       2       2       0       3       0       1
-       2       1       0       3       0       0       3       2       0       1
-       4       3       1       1       3       1       2       2       1       2
-       2       3       1       2       2       2       1       4       2       1
-       1       2       3       0       4       0       4       4       0       2
-       3       1       1       0       1       1       3       0       1       2
-       0       0       1       0       0       0       0       0       0       0
-       0       0       0       0       0       1       0       0       3       2
-       1       3       5       1       2       1       1       3       1       0
-       1       4       0       1       2       1       3       0       1       2
-       2       2       2       1       2       0       2       3       1       1
-       3       3       1       0       0       4       2       2       3       0
-       1       4       2       2       3       2       2       2       4       4
-       2       2       2       2       3       0       3       2       3       2
-       3       2       1       1       1       2       4       1       0       1
-       0       1       1       2       1       1       0       0       1       0
-       1       2       2       1       2       3       5       1       3       3
-       3       0       2       1       1       1       3       1       2       0
-       4       3       1       1       1       1       1       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       4       2       0       0       1       1       2       5
-       1       1       0       1       1       1       1       2       0       1
-       1       2       2       3       0       3       1       2       4       1
-       3       0       2       0       3       2       0       0       3       1
-       1       1       2       2       1       3       2       1       1       1
-       1       1       2       3       2       4       2       3       2       0
-       0       1       3       0       1       1       1       2       2       3
-       1       1       1       1       1       3       3       4       6       2
-       1       2       1       2       2       1       3       4       2       0
-       1       2       1       1       2       1       2       1       0       1
-       2       1       0       0       2       1       0       0       1       1
-       0       0       0       0       0       0       0       0       0       0
-       0       0       2       0       2       1       1       1       2       0
-       2       1       4       3       1       2       1       2       3       1
-       2       0       2       3       2       5       0       1       1       3
-       3       1       1       1       1       0       0       0       3       1
-       1       1       1       2       3       2       5       1       1       2
-       4       1       2       4       1       3       0       4       2       1
-       0       2       0       1       3       3       1       1       2       2
-       1       1       1       3       1       5       1       0       1       1
-       0       2       2       2       0       1       0       4       1       1
-       1       2       0       2       2       0       1       1       0       1
-       2       2       2       1       1       0       0       1       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       1       0       1       1       1       2       0
-       0       2       1       0       0       4       1       3       3       1
-       0       2       2       0       1       4       0       1       1       3
-       1       0       1       3       3       2       0       0       1       2
-       0       2       4       0       1       3       4       0       0       1
-       1       3       2       2       2       0       1       8       0       1
-       3       0       1       3       1       1       3       2       1       2
-       2       4       0       1       1       2       0       6       0       1
-       1       1       1       0       0       0       1       1       2       1
-       0       0       3       1       1       1       1       0       1       0
-       2       1       1       1       1       1       3       3       3       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       1       1       1       0       0       2       2       2
-       0       2       0       2       1       3       2       2       1       1
-       0       1       1       0       0       2       0       1       1       1
-       1       1       0       1       2       1       1       1       0       0
-       0       2       0       0       0       1       2       2       1       2
-       3       0       2       4       2       0       2       2       1       1
-       0       2       1       1       2       1       2       2       1       2
-       0       1       4       3       2       2       1       1       2       1
-       2       2       0       1       1       4       1       2       0       0
-       1       0       1       1       1       0       1       0       1       2
-       0       0       1       1       0       1       2       1       0       1
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       2       2       0       1       2       2       1       2       2
-       1       1       1       1       0       0       4       3       1       2
-       3       0       2       0       0       2       1       1       3       1
-       1       1       1       1       3       0       0       3       4       0
-       0       0       4       1       2       1       2       1       2       3
-       2       3       3       1       0       2       0       0       1       3
-       4       1       0       3       1       1       0       1       2       2
-       2       2       2       1       1       1       0       1       1       1
-       0       1       1       2       2       1       1       3       1       1
-       2       2       0       0       1       0       1       1       0       0
-       4       2       2       1       0       2       0       1       1       0
-       0       0       0       0       0       0       0       0       0       0
-       0       1       2       0       0       1       3       0       3       0
-       1       2       3       0       0       2       2       1       0       0
-       1       1       0       3       0       2       1       3       0       1
-       1       2       3       0       3       3       1       1       1       2
-       2       0       2       0       1       1       0       5       2       1
-       2       2       0       3       0       0       2       1       2       3
-       0       3       2       1       1       2       1       4       3       0
-       0       2       4       1       1       1       1       3       1       1
-       2       0       0       1       2       0       0       2       2       1
-       0       1       4       0       1       1       1       1       0       1
-       1       1       0       1       3       1       0       0       1       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       2       0       1       1
-       1       2       1       2       2       2       2       0       3       1
-       1       1       1       2       1       2       1       1       2       1
-       1       1       4       4       1       2       0       0       2       1
-       1       4       0       0       1       2       2       2       1       2
-       0       0       2       0       2       1       2       2       2       2
-       2       0       0       1       2       1       2       2       1       1
-       1       1       1       3       1       3       0       2       0       0
-       4       1       1       0       0       1       2       3       1       1
-       0       2       0       3       2       0       3       2       2       3
-       0       2       1       1       1       2       1       0       0       2
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       1       1       2       0       1
-       0       2       0       1       2       3       1       1       0       3
-       0       0       0       2       3       2       2       0       0       2
-       2       1       1       0       2       1       3       1       2       1
-       0       5       2       1       6       2       0       1       2       0
-       2       1       0       0       0       1       2       0       1       1
-       1       1       3       3       0       2       4       3       0       1
-       0       0       1       3       0       0       2       3       0       3
-       2       3       0       2       0       1       0       3       2       0
-       0       1       3       0       3       1       2       2       1       3
-       0       1       2       3       1       3       1       1       0       1
-       1       1       1       4       0       1       2       0       1       1
-       1       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       1
-       0       0       0       1       2       2       2       1       0       2
-       1       0       0       0       1       1       0       1       2       0
-       0       1       3       1       1       0       2       1       4       0
-       1       0       0       0       3       1       1       1       1       1
-       2       1       1       1       2       0       1       2       0       1
-       2       3       1       0       3       0       1       1       0       0
-       1       1       1       2       0       1       0       1       0       0
-       1       1       2       2       1       0       1       1       0       0
-       1       2       2       0       1       0       1       1       1       2
-       2       1       2       0       3       0       0       2       3       2
-       1       1       0       0       1       2       0       0       0       0
-       0       0       0       0       0       0       0       1       0       2
-       0       0       2       1       2       0       1       1       1       0
-       0       0       2       1       0       2       0       1       1       1
-       2       1       3       2       0       2       1       0       2       2
-       2       1       0       2       1       1       4       0       2       3
-       1       0       2       0       1       1       0       1       1       2
-       1       0       0       2       2       2       2       1       1       0
-       1       1       1       5       1       0       3       1       1       4
-       0       2       0       3       3       2       1       1       2       2
-       4       3       1       0       1       1       1       1       2       2
-       0       0       1       0       3       0       0       0       2       5
-       2       1       2       1       2       2       1       0       2       0
-       1       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       4       0       0       1       0       0       3       1       1
-       0       0       0       0       4       2       4       0       1       0
-       1       0       0       0       1       0       0       1       1       0
-       1       1       2       0       3       2       3       2       1       1
-       4       3       0       0       2       3       3       0       1       0
-       0       1       0       2       2       0       0       1       1       2
-       1       0       0       1       1       1       0       1       4       0
-       2       1       1       0       1       0       1       1       0       0
-       1       1       0       0       1       2       1       1       2       1
-       3       2       1       2       0       0       1       1       0       1
-       1       0       0       1       1       4       2       2       3       1
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       1       0       1       1       1
-       0       2       0       0       2       0       1       2       2       0
-       4       1       0       0       3       2       1       0       1       0
-       1       1       1       1       1       0       2       0       1       2
-       1       2       0       0       2       0       4       1       0       1
-       1       0       0       0       0       2       3       0       2       1
-       3       2       2       2       1       2       1       0       3       1
-       3       1       1       2       0       4       6       1       0       2
-       2       1       0       2       0       2       2       0       2       3
-       1       1       1       1       1       2       1       0       0       1
-       1       1       0       0       0       3       1       2       1       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       2       0       1       0       1       2       2       0
-       2       1       1       2       1       1       3       2       2       2
-       2       0       0       1       1       0       2       1       2       2
-       1       3       2       0       1       2       2       0       1       0
-       4       2       0       2       2       0       2       0       3       2
-       0       3       3       1       1       3       3       2       1       1
-       4       1       1       2       1       1       1       1       2       0
-       1       0       1       1       1       1       1       0       1       2
-       2       0       2       2       0       1       2       0       2       0
-       0       3       1       1       2       1       1       0       2       0
-       0       3       3       1       1       1       0       2       0       1
-       1       0       1       1       0       0       0       0       0       0
-       0       0       0       0       0       0       0       2       0       0
-       2       2       2       2       2       1       1       1       1       2
-       2       1       0       1       1       1       2       1       1       2
-       0       1       3       0       0       1       0       1       0       0
-       0       0       1       1       1       2       2       1       2       1
-       0       0       2       0       3       2       4       2       0       1
-       1       1       2       0       1       1       1       0       3       2
-       1       1       0       2       4       1       0       0       1       1
-       0       1       1       2       1       1       0       0       2       2
-       0       2       3       1       0       1       0       0       1       2
-       1       3       0       0       1       0       2       3       0       1
-       0       0       3       1       0       1       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       1       2       1       1       2       0       1       1
-       0       1       2       0       1       1       3       1       0       1
-       1       2       1       0       1       1       1       3       1       1
-       3       0       1       2       2       1       0       4       1       1
-       0       0       0       1       1       0       0       0       1       1
-       0       1       1       1       1       2       1       5       1       0
-       4       2       3       1       0       1       1       3       2       1
-       3       0       2       1       1       1       1       2       1       1
-       1       0       1       0       0       0       0       1       0       0
-       1       2       2       1       0       0       1       2       1       0
-       1       1       2       1       1       0       2       0       0       2
-       0       0       1       0       0       0       0       0       0       0
-       0       0       0       0       3       0       0       0       3       0
-       0       0       1       0       2       0       1       1       2       1
-       2       1       1       1       1       4       0       0       1       2
-       4       1       0       0       1       0       0       1       0       1
-       1       3       0       0       0       0       0       0       0       2
-       1       2       2       2       0       1       1       2       1       1
-       0       0       2       2       0       0       2       1       0       1
-       2       2       1       3       1       0       4       1       0       1
-       0       0       0       0       4       1       0       1       1       2
-       2       0       0       1       2       2       0       1       1       2
-       0       2       0       0       1       3       0       1       0       2
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       1       1       0       0
-       0       3       2       0       1       0       1       1       2       0
-       2       2       1       1       1       2       1       1       0       1
-       0       0       3       0       1       1       1       1       1       2
-       3       3       1       0       1       1       0       1       2       1
-       1       0       1       0       1       2       0       2       0       0
-       3       2       1       2       0       1       3       0       1       2
-       1       1       1       2       0       1       0       1       0       1
-       0       1       1       1       3       0       1       1       0       1
-       1       1       2       1       0       1       3       1       0       2
-       0       1       1       0       2       0       1       1       0       1
-       0       1       2       2       2       0       2       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       1       2       2       2       2       0       0       1       0       2
-       0       3       1       0       1       0       1       3       0       1
-       1       1       0       1       1       3       1       1       0       0
-       0       0       1       2       0       2       1       1       0       2
-       2       2       3       2       1       0       2       0       1       2
-       0       1       3       1       2       2       3       1       4       1
-       2       3       0       1       4       1       0       0       2       1
-       0       2       1       2       0       0       0       0       2       0
-       1       2       0       1       2       0       0       1       0       0
-       2       0       1       0       0       0       1       1       2       0
-       0       1       4       0       0       3       5       2       1       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       1       1       1       0       0       0       2       1
-       0       2       1       0       0       1       0       1       2       1
-       2       1       0       3       3       1       1       1       0       0
-       1       2       1       2       1       2       0       3       1       4
-       0       2       1       1       0       3       1       4       0       0
-       2       1       0       1       1       1       2       0       2       2
-       0       1       1       1       0       0       3       1       1       0
-       1       2       1       3       0       0       0       1       3       1
-       1       3       2       0       1       2       1       0       0       0
-       1       0       2       3       0       0       0       3       0       1
-       1       0       1       2       1       0       1       0       0       0
-       1       0       0       0       0       0       0       0       0       0
-       0       0       0       0       2       1       0       1       1       5
-       1       1       0       2       2       1       1       0       1       0
-       0       2       0       0       0       0       1       1       1       1
-       2       1       0       1       1       0       2       0       1       2
-       1       1       0       0       2       0       1       1       2       0
-       3       0       0       0       0       1       0       1       0       2
-       0       3       1       4       1       0       0       0       0       1
-       2       1       2       1       1       0       1       0       3       1
-       1       4       3       0       2       1       0       2       0       1
-       1       2       0       0       2       1       0       0       2       0
-       1       0       2       2       2       0       3       0       1       3
-       1       0       1       1       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       1       1       1       2       1       1       3       2       0       0
-       1       1       1       2       1       3       0       3       1       0
-       1       0       0       1       3       1       2       1       0       0
-       1       3       1       1       1       0       1       4       1       0
-       0       2       2       2       2       0       0       0       1       3
-       2       1       0       0       3       1       1       2       1       1
-       0       0       0       2       0       0       2       2       2       1
-       0       1       0       0       0       0       0       0       0       0
-       2       0       0       1       1       1       1       0       0       3
-       0       2       1       1       2       3       0       1       1       0
-       0       2       1       0       0       1       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       1       1       3       2       0       1       1       0       0       2
-       0       1       3       0       0       1       0       1       3       2
-       1       1       0       1       1       0       2       0       0       3
-       1       1       0       1       0       2       1       2       2       0
-       0       1       3       2       2       0       1       4       0       2
-       2       3       1       0       1       1       1       1       2       1
-       1       2       1       2       1       0       2       1       0       1
-       2       2       0       0       2       2       1       2       0       0
-       2       3       1       0       3       0       0       1       0       0
-       0       1       1       1       0       2       0       3       0       3
-       1       0       0       1       1       0       1       2       0       0
-       0       0       1       0       0       0       0       0       0       0
-       0       0       0       0       0       0       1       0       0       0
-       0       1       1       1       0       1       0       1       0       1
-       2       2       3       0       0       3       2       2       2       4
-       2       2       1       2       0       5       2       3       2       2
-       3       1       1       2       2       1       0       0       1       0
-       0       0       0       1       2       0       0       2       0       3
-       3       1       2       3       5       1       0       3       0       1
-       1       0       0       2       0       3       1       0       2       0
-       1       3       0       0       0       2       0       2       0       1
-       2       0       0       0       0       3       0       1       0       1
-       0       1       0       1       3       0       0       0       2       2
-       0       0       1       0       1       3       0       1       2       1
-       3       1       0       0       0       0       0       0       0       0
-       0       0       0       0       0       1       1       1       2       2
-       2       0       0       1       2       3       0       1       2       2
-       1       2       3       0       0       1       3       0       0       5
-       2       0       2       2       2       4       1       1       2       1
-       4       4       3       1       4       3       2       3       5       4
-       4       3       5       1       4       1       3       2       7       4
-       4       4       7       7       7       3       2       3       5       1
-       6       2       8       4       3       8       2       3       7       3
-       6       5       3       5       1       4       8       1       3       3
-       3       2       2       4       4       2       0       2       3       3
-       3       2       1       2       2       0       1       0       1       1
-       1       2       2       2       2       2       1       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       1       1
-       1       2       4       6      19      15      19      14       8      15
-       7       5       6      13      10       5       4       3       5       1
-       3       4       3       4       2       3       3       0       1       1
-       2       2       1       1       2       1       0       1       3       2
-       2       2       0       3       0       1       3       2       2       1
-       1       1       1       4       1       0       1       0       0       2
-       1       1       0       0       3       1       1       1       2       1
-       2       1       1       3       0       1       0       2       3       1
-       3       4       4       4       1       4       1       2       5       4
-       5       4       3       3       3       7       2       5       7       5
-      10       4       7       7       4       6       1       4       3       0
-       0       0       0       0       0       0       0       0       0       0
-       0       1       0       2       0       0       1       0       1       2
-       1       4       1       0       0       2       0       2       2       0
-       1       1       3       2       0       1       0       0       2       1
-       2       0       0       0       1       1       0       3       1       1
-       0       1       0       2       1       1       2       1       3       0
-       3       1       1       0       1       0       0       1       2       1
-       0       0       2       1       0       0       1       0       2       1
-       3       0       0       1       2       1       2       0       3       2
-       0       2       2       2       1       0       3       2       0       2
-       0       1       2       2       1       0       2       4       2       2
-       3       1       4       2       1       0       4       1       0       2
-       2       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       1       0       1
-       0       0       1       1       0       0       0       0       1       2
-       0       0       2       1       0       0       0       1       0       1
-       0       1       3       0       2       0       0       0       0       1
-       1       0       0       1       0       1       2       1       2       1
-       2       1       2       0       1       3       2       0       0       1
-       0       2       3       2       1       2       1       1       0       0
-       0       3       1       2       0       5       0       1       1       1
-       1       0       1       0       2       1       0       1       1       0
-       1       1       1       0       2       2       1       0       1       3
-       0       0       0       0       0       3       1       0       0       0
-       3       0       0       0       2       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       2       1       1       1       1       0       1       1       2
-       0       2       1       0       0       1       1       0       1       2
-       1       1       2       0       2       1       0       1       0       0
-       1       1       1       0       0       1       1       4       2       1
-       0       1       0       2       2       1       1       1       0       1
-       0       1       1       0       1       2       2       2       0       1
-       1       0       0       1       2       0       0       3       0       1
-       0       0       2       0       0       1       1       1       0       0
-       0       1       1       2       0       1       0       0       0       3
-       1       2       0       1       2       0       1       0       3       0
-       2       1       2       0       1       1       1       3       0       0
-       0       1       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       2       0       1       1       0       0       1       3       2       0
-       1       0       1       1       2       0       0       1       1       1
-       1       0       0       3       0       1       1       4       1       0
-       0       0       0       1       0       2       0       4       0       0
-       1       1       0       0       1       1       2       1       1       2
-       3       2       0       0       3       0       0       1       1       2
-       4       1       1       1       1       1       1       2       1       1
-       3       0       2       1       1       1       0       0       1       0
-       0       2       0       2       0       1       2       2       2       2
-       1       1       1       0       2       0       2       2       0       0
-       1       0       3       0       3       0       1       2       3       0
-       1       1       0       0       0       0       0       0       0       0
-       0       1       1       0       1       1       0       1       0       1
-       0       1       0       0       2       2       0       1       3       3
-       0       4       1       1       2       2       0       1       0       0
-       0       4       1       1       1       0       1       0       0       0
-       1       1       0       0       0       1       1       2       1       3
-       1       1       4       1       0       0       0       0       0       1
-       0       1       2       1       1       1       0       1       0       2
-       1       1       1       1       4       1       1       4       1       0
-       0       2       0       0       0       0       1       3       1       0
-       0       0       1       2       1       0       2       0       1       1
-       0       2       2       1       0       1       3       2       1       2
-       1       0       1       1       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       1       2       1
-       1       1       0       0       1       1       0       1       0       1
-       1       3       1       2       1       1       0       0       0       3
-       0       1       0       0       1       1       1       0       1       0
-       2       1       1       2       1       1       0       2       2       1
-       3       3       3       0       2       3       0       1       0       0
-       1       1       0       0       1       3       2       4       0       0
-       1       1       0       0       0       1       1       1       0       1
-       1       0       1       2       0       1       1       0       1       3
-       0       1       1       1       1       0       1       0       0       1
-       0       0       1       0       0       0       0       1       1       0
-       2       0       1       1       1       0       1       1       1       0
-       0       0       0       0       0       0       0       0       0       1
-       0       2       0       1       0       2       0       1       0       1
-       1       0       0       1       0       0       1       1       0       1
-       2       1       2       0       1       0       2       0       1       0
-       1       0       0       1       3       0       0       2       1       1
-       3       3       1       1       0       0       1       3       0       0
-       0       2       2       1       2       3       1       0       2       1
-       1       1       3       2       0       2       1       0       1       1
-       1       0       2       0       3       0       1       1       1       0
-       0       0       1       1       0       3       2       1       1       2
-       1       0       0       0       2       0       2       1       1       0
-       1       0       1       1       2       0       2       1       1       2
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       2       1       1       2       0       1
-       1       2       3       1       0       3       0       0       0       3
-       0       0       2       0       0       0       2       4       1       1
-       0       0       0       0       1       0       1       1       1       3
-       2       2       1       1       2       1       0       3       2       1
-       1       1       4       0       2       3       1       1       1       0
-       1       0       6       0       1       1       2       1       1       0
-       1       1       1       1       1       3       2       0       0       0
-       0       1       1       1       0       2       0       2       0       1
-       1       2       2       0       2       1       1       3       0       0
-       2       1       1       0       2       0       4       1       0       1
-       0       0       1       2       0       0       0       0       0       0
-       0       0       0       0       0       0       0       1       0       1
-       3       1       0       3       2       0       2       0       2       3
-       1       1       0       2       1       2       1       0       0       3
-       2       4       5       3       3       2       1       2       2       2
-       0       6       2       1       3       1       1       3       4       1
-       3       1       4       5       3       1       0       2       2       3
-       2       0       1       3       4       3       1       2       2       1
-       1       0       5       2       2       2       0       3       0       0
-       3       3       3       0       2       1       2       2       2       1
-       1       0       2       4       3       0       4       2       2       0
-       0       0       1       1       1       1       0       1       1       2
-       1       1       0       0       2       2       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       1       1       1
-       0       1       2       0       0       0       1       2       0       3
-       2       0       1       2       0       0       1       4       1       0
-       3       4       1       0       0       2       1       2       1       0
-       2       0       0       0       1       2       0       0       1       0
-       0       0       0       3       2       2       0       3       1       2
-       0       1       1       1       1       0       0       0       1       0
-       0       0       2       0       0       1       1       1       1       1
-       4       0       0       1       1       1       1       0       0       0
-       2       2       1       1       1       0       0       1       1       3
-       1       0       0       0       3       2       1       0       0       3
-       1       0       0       1       0       1       1       0       1       1
-       2       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       1       0       2       0
-       0       1       1       1       0       1       1       2       1       1
-       0       1       2       0       0       1       2       0       1       1
-       1       1       3       1       2       0       0       1       1       0
-       0       1       0       2       2       2       2       1       0       1
-       1       0       3       1       0       1       2       0       1       3
-       0       0       0       1       2       1       1       0       2       2
-       1       2       2       0       3       0       1       1       1       0
-       1       2       0       0       0       0       2       1       1       1
-       2       2       1       1       0       1       0       3       3       1
-       1       2       0       1       2       0       0       0       2       1
-       1       0       2       0       0       1       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       1       0       1       2
-       2       0       1       1       0       0       0       2       0       0
-       1       0       1       1       2       3       2       0       0       1
-       0       0       0       1       1       0       0       0       0       3
-       1       0       0       1       0       1       0       0       1       3
-       0       1       0       1       1       2       0       0       0       1
-       0       2       0       0       5       1       3       2       0       0
-       0       1       0       4       1       1       2       2       0       1
-       2       4       2       3       3       1       2       0       0       0
-       1       0       1       0       0       0       1       0       1       1
-       0       0       0       2       0       0       1       1       1       0
-       5       1       2       0       4       1       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       2       2       2       0       0       0       2
-       1       1       1       0       2       2       0       4       3       1
-       0       1       1       1       1       0       0       1       2       1
-       0       2       0       2       0       1       0       1       0       2
-       0       2       0       0       0       2       0       1       0       2
-       1       0       1       0       2       1       2       0       0       2
-       0       0       2       2       0       1       1       0       1       0
-       0       0       3       1       2       0       2       1       3       0
-       1       3       0       1       2       0       3       2       0       0
-       1       2       1       2       2       3       2       0       0       0
-       1       3       2       0       1       3       1       0       0       1
-       0       0       1       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       1       2       0       1       0       1       0       1       0
-       1       2       0       1       1       2       1       0       0       1
-       1       1       0       0       1       2       0       1       1       0
-       2       2       1       0       3       1       0       1       1       0
-       1       2       3       1       0       0       1       1       0       0
-       2       1       0       2       2       0       0       2       0       0
-       1       0       0       0       1       2       1       0       0       1
-       2       0       0       0       0       4       3       0       0       1
-       2       2       1       1       1       2       1       1       1       1
-       0       0       1       2       0       1       1       2       0       4
-       0       1       3       0       2       0       2       1       0       2
-       1       1       1       1       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       2       0       1       0       0       1       0       1
-       1       1       2       1       0       2       1       0       0       0
-       1       0       3       0       1       2       0       1       1       2
-       0       1       2       2       0       0       0       2       1       0
-       0       0       1       1       1       3       0       1       0       1
-       3       1       1       2       1       0       1       0       0       0
-       1       0       0       0       1       0       1       1       1       3
-       1       0       1       2       1       0       3       1       0       1
-       0       2       0       1       0       2       0       1       0       1
-       1       2       0       0       0       1       1       0       2       0
-       2       1       0       1       2       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       1       0       0       1
-       0       0       1       0       1       3       0       2       2       1
-       0       1       0       3       0       1       1       2       3       2
-       0       0       0       2       0       1       1       0       1       1
-       1       1       2       3       0       0       1       0       0       0
-       0       0       0       2       2       1       0       2       1       1
-       2       3       1       2       1       2       0       3       1       2
-       0       1       2       2       1       1       1       1       1       0
-       1       4       1       1       0       0       0       2       0       1
-       2       0       0       0       0       3       1       2       0       1
-       0       0       1       0       0       0       0       1       2       1
-       0       0       1       0       0       2       1       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       1       0       1       2       0       2       0       0       4
-       3       0       2       2       0       1       0       1       0       1
-       1       0       2       0       1       1       0       2       0       0
-       3       1       0       1       2       0       2       0       1       3
-       0       0       0       0       1       0       0       0       2       0
-       1       0       2       1       2       1       0       0       2       0
-       0       3       2       2       0       2       2       2       1       0
-       2       0       0       1       1       0       1       3       2       1
-       1       2       0       0       0       0       0       2       0       0
-       0       1       1       2       0       1       1       1       0       1
-       0       0       2       0       1       1       1       4       1       3
-       0       0       4       0       0       0       0       0       1       0
-       0       0       0       0       0       0       0       0       0       0
-       0       1       0       0       1       1       1       1       3       1
-       3       0       1       2       2       0       1       0       2       1
-       1       1       0       0       1       0       0       1       0       2
-       0       3       0       0       0       0       0       0       1       0
-       2       2       2       0       0       1       1       0       0       0
-       0       1       1       0       1       0       2       1       2       1
-       3       0       1       0       1       0       1       1       0       1
-       0       1       1       0       1       1       1       1       1       1
-       2       0       3       0       0       0       0       0       2       0
-       0       0       0       2       0       1       1       1       2       1
-       0       1       0       1       1       2       0       0       0       3
-       0       1       1       0       0       0       0       0       0       0
-       0       0       0       0       0       0       1       0       1       0
-       0       0       1       0       0       1       1       5       0       0
-       0       0       2       2       0       0       2       0       1       1
-       1       1       3       2       1       1       2       1       0       1
-       0       2       2       1       0       1       2       1       2       0
-       0       0       0       0       1       0       2       1       0       1
-       3       1       2       1       0       1       0       1       2       1
-       1       1       2       0       0       1       1       1       0       0
-       1       2       0       0       0       1       1       1       1       1
-       0       1       0       0       1       1       0       1       1       0
-       3       1       1       0       2       0       1       2       1       1
-       0       0       1       1       1       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       2       2
-       1       0       1       1       0       1       0       1       2       1
-       0       5       0       0       2       1       0       0       0       1
-       2       1       1       2       1       0       0       0       2       0
-       2       0       2       0       1       1       0       1       0       1
-       1       1       1       0       0       0       1       3       0       0
-       1       0       0       0       0       2       1       1       2       2
-       0       1       0       1       1       0       1       1       0       2
-       1       0       0       1       2       3       0       0       0       2
-       1       0       1       0       1       0       0       0       0       1
-       0       0       1       1       0       3       1       0       2       1
-       1       1       2       0       0       0       1       0       0       0
-       0       0       0       0       0       0       0       0       0       1
-       0       2       0       0       0       2       0       1       3       1
-       3       1       0       1       0       0       2       1       1       0
-       1       1       0       1       0       0       1       2       0       1
-       0       1       0       0       0       0       1       0       0       1
-       0       1       1       1       0       1       1       0       0       1
-       0       0       1       0       0       0       0       1       1       0
-       0       1       1       0       1       0       0       2       0       2
-       1       0       1       1       2       2       1       1       1       1
-       0       1       0       1       0       0       0       0       0       0
-       0       2       1       3       0       1       0       0       1       2
-       0       0       2       1       0       0       4       2       2       0
-       1       0       0       1       0       0       1       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       1       0       0
-       0       2       1       4       1       1       1       2       2       0
-       3       0       0       0       1       1       4       2       1       4
-       0       1       3       2       0       3       0       2       2       0
-       2       4       2       1       1       3       0       1       2       1
-       0       1       1       1       0       0       2       1       0       0
-       3       1       0       1       3       0       1       1       0       3
-       0       2       0       1       1       0       2       0       0       1
-       1       1       0       1       0       0       0       2       2       1
-       2       0       0       1       1       1       2       0       2       2
-       1       0       1       1       1       2       2       0       0       2
-       2       1       0       1       0       5       0       1       3       1
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       1       0       1       0       0       0       0
-       1       0       0       3       1       0       2       0       2       0
-       0       0       1       1       0       2       1       0       1       1
-       0       2       2       0       2       0       0       0       0       1
-       1       0       1       4       0       0       3       0       0       1
-       0       0       1       1       0       3       0       0       0       1
-       0       1       2       2       1       0       0       0       1       0
-       0       0       2       2       1       1       0       1       0       1
-       1       0       0       1       2       0       1       0       0       1
-       1       0       1       0       1       0       0       0       2       3
-       2       1       0       0       0       0       3       1       1       0
-       1       0       1       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       1       1       1
-       1       3       2       1       0       2       1       0       0       1
-       1       2       0       1       3       1       0       1       1       1
-       0       1       0       3       0       2       1       0       0       0
-       0       0       1       2       1       1       1       0       0       1
-       0       0       0       0       0       2       2       2       1       0
-       0       0       0       3       1       0       0       4       3       0
-       1       2       0       0       0       2       2       1       1       0
-       1       1       1       1       2       2       1       0       1       2
-       2       0       2       0       1       4       0       0       1       2
-       1       0       0       2       2       0       1       0       0       2
-       1       0       0       3       2       1       1       0       0       0
-       1       2       0       0       0       0       0       0       0       0
-       0       0       0       0       0       1       0       0       0       2
-       0       1       3       0       1       0       2       2       0       0
-       1       0       0       1       0       1       1       1       0       0
-       3       2       2       0       1       0       3       1       1       0
-       0       0       0       2       1       0       0       1       2       1
-       0       0       1       1       1       2       0       0       1       0
-       0       2       0       2       1       1       0       2       2       1
-       0       0       0       0       0       0       0       0       1       1
-       0       0       1       1       1       1       0       1       1       2
-       1       1       0       1       2       0       0       0       1       1
-       4       1       0       0       1       1       3       0       0       0
-       1       1       0       1       0       1       0       0       0       1
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       2       0       2       0
-       2       1       0       1       0       1       2       1       0       0
-       2       0       0       1       1       0       0       2       0       0
-       0       2       0       0       2       1       0       2       0       2
-       1       0       1       2       0       0       1       0       0       2
-       2       1       1       1       0       3       2       2       2       1
-       0       2       0       0       0       0       2       0       0       0
-       0       1       3       1       1       1       2       1       0       0
-       1       2       0       0       2       2       0       1       1       0
-       1       1       0       0       0       3       0       0       1       0
-       1       0       0       0       0       2       0       0       0       1
-       1       1       0       2       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       1       0       2       0       0       1       0       1
-       1       0       1       1       1       1       2       2       1       0
-       0       1       2       2       1       0       1       0       2       1
-       2       2       0       1       1       3       2       1       4       0
-       0       2       0       1       2       0       1       0       0       3
-       2       2       0       1       0       0       2       1       1       1
-       0       0       1       2       1       0       1       2       2       1
-       1       2       1       2       0       0       1       1       0       3
-       2       3       0       3       0       3       4       0       0       1
-       1       6       0       0       0       0       1       0       0       3
-       0       0       1       1       0       0       1       0       0       1
-       1       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       1       0
-       1       0       0       0       0       1       1       0       0       1
-       1       1       3       0       1       0       0       1       1       2
-       1       2       0       0       1       0       1       3       0       1
-       0       2       0       1       0       0       0       1       0       2
-       2       0       2       2       1       0       0       0       3       2
-       2       0       0       0       1       0       1       3       1       0
-       0       3       2       0       2       0       1       1       1       0
-       0       1       1       0       1       2       1       3       0       0
-       1       1       0       0       0       0       0       0       1       0
-       2       0       0       1       0       1       1       0       0       2
-       0       3       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       2       0
-       2       0       1       0       0       1       1       0       2       2
-       1       2       2       0       0       0       1       1       0       0
-       1       0       0       1       1       3       0       0       0       1
-       1       0       0       0       2       0       1       0       0       2
-       0       0       0       1       0       1       1       3       3       1
-       3       4       2       3       1       4       1       2       2       3
-       1       1       2       0       0       0       0       0       2       1
-       1       1       0       0       1       1       0       1       1       2
-       1       0       2       0       2       0       2       1       2       0
-       2       2       0       3       1       2       1       2       0       2
-       1       1       0       0       1       1       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       1       1       0       0       0       0       0       1       0
-       1       0       1       0       0       0       2       0       2       2
-       0       0       2       0       1       0       1       0       1       1
-       0       0       1       0       0       0       0       0       2       2
-       0       2       3       0       0       1       1       2       3       3
-       1       1       2       1       2       1       1       1       2       0
-       0       0       0       0       2       1       2       1       1       2
-       0       2       1       0       2       1       0       0       1       1
-       1       1       0       0       0       0       0       2       0       0
-       1       1       0       0       3       0       0       2       2       1
-       0       0       0       3       2       0       0       2       0       1
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       1       0       1       0       0       1
-       0       1       0       1       1       0       2       1       1       1
-       0       0       1       1       0       1       2       1       2       1
-       2       0       0       0       1       1       2       3       0       0
-       0       0       1       1       1       1       1       0       0       0
-       0       1       0       1       1       0       1       0       2       1
-       2       1       1       0       1       1       0       1       1       1
-       0       3       2       0       1       0       1       0       0       1
-       2       1       0       2       2       0       1       1       1       0
-       0       3       2       0       3       1       0       0       0       0
-       3       2       1       0       0       3       2       0       3       0
-       0       1       0       0       1       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       1       1       2
-       1       0       2       0       4       1       1       4       2       2
-       1       2       3       0       2       1       1       1       3       0
-       0       0       0       2       1       1       0       1       2       1
-       2       0       3       1       1       1       0       0       0       0
-       0       3       0       5       2       0       0       1       1       1
-       2       1       1       0       3       1       0       0       0       4
-       0       1       0       2       1       1       0       0       0       1
-       0       1       2       1       1       2       0       2       0       0
-       0       0       1       2       1       1       0       2       1       3
-       1       1       1       0       0       2       0       1       2       0
-       1       1       1       2       0       0       0       0       0       0
-       0       0       0       0       0       0       3       0       1       8
-       3       7       8       7      11       4       6      10       7       7
-       9       5       3       8      11      12       7      10      11      10
-       7      11      10      11      11      11      13       8       7       8
-       6       6      11      10      13      16       6      15      13      11
-       9      11       9      17      16      16       9      18       9      10
-       8       9      12      16      11      12       9      23      16      16
-      17       6      21      17      15      10      15      16      21      13
-      13       6      16      13      15      19      13       8      13      10
-      14       9       9      14      14      11      10      10       7      10
-       5       9      13      11       9      11       6       7       9       8
-       6       8       8       2       2       1       1       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       1       1       0       4       1       1
-       2       4       1       4       1       1       4       0       1       3
-       2       3       2       0       1       0       1       2       0       0
-       3       2       0       0       2       3       1       2       0       0
-       0       0       1       0       1       3       0       0       1       0
-       0       0       1       5       1       2       1       1       1       1
-       0       1       2       0       2       3       3       1       1       0
-       3       2       1       0       0       0       1       2       0       0
-       2       0       0       1       0       1       0       1       1       1
-       1       0       3       1       1       0       1       0       0       1
-       0       1       0       0       2       1       0       1       0       0
-       2       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       1       1       4
-       1       1       0       0       2       1       0       3       1       3
-       1       1       1       1       1       0       1       0       1       0
-       0       1       2       3       0       0       0       1       0       0
-       1       1       0       0       0       1       1       1       0       0
-       0       1       0       1       3       1       0       1       0       2
-       1       2       2       2       0       2       1       2       1       0
-       1       0       3       0       0       0       1       0       2       0
-       0       0       1       1       1       3       2       0       3       2
-       1       1       0       0       0       0       1       0       0       0
-       0       1       1       0       0       1       3       1       0       1
-       0       1       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       2
-       1       0       2       2       3       1       1       0       3       1
-       3       1       0       0       3       1       0       0       0       0
-       1       0       1       1       2       0       0       2       1       1
-       1       3       0       0       1       2       2       2       2       0
-       0       1       3       0       0       2       0       1       0       2
-       0       2       2       1       3       0       0       2       0       4
-       0       1       1       1       3       0       1       1       0       2
-       0       1       2       3       1       0       0       3       2       1
-       0       0       0       0       0       0       0       2       0       0
-       1       1       1       0       0       0       0       1       0       4
-       0       1       0       0       1       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       1       2       1       1       0       1
-       0       0       0       1       0       1       1       1       2       1
-       0       2       1       1       1       2       1       0       2       0
-       0       2       1       0       1       0       0       0       1       1
-       0       1       1       1       1       3       0       0       1       0
-       0       0       0       2       2       2       1       1       2       0
-       2       0       2       3       2       3       1       1       0       1
-       0       1       2       0       2       1       0       0       0       0
-       0       1       1       2       0       1       2       2       0       1
-       1       1       0       0       0       2       1       3       1       4
-       0       1       1       0       1       0       0       1       0       0
-       1       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       1       0       1       0       0       0       1
-       1       0       1       2       0       0       0       0       4       1
-       1       0       2       0       0       1       1       0       1       1
-       1       0       1       1       1       1       0       1       1       0
-       2       0       2       0       3       2       1       2       1       0
-       1       1       0       2       2       2       1       0       0       0
-       3       0       2       0       0       2       2       0       0       0
-       0       1       1       1       2       2       1       0       0       1
-       0       0       2       1       1       0       0       1       0       1
-       0       0       1       1       0       1       0       1       2       0
-       1       0       0       1       0       1       0       1       1       1
-       1       0       1       2       2       0       1       1       0       0
-       0       0       0       0       0       0       0       0       2       2
-       1       0       1       1       0       0       2       0       2       5
-       2       2       0       3       2       1       0       3       1       0
-       3       3       1       2       2       2       1       1       1       3
-       1       0       0       2       3       2       4       2       0       0
-       2       2       4       0       3       2       0       3       0       2
-       2       4       3       0       0       2       1       0       4       0
-       1       3       3       2       2       4       1       3       2       1
-       2       3       0       4       1       3       1       2       2       1
-       4       3       0       3       3       2       1       1       3       3
-       1       1       1       3       3       2       2       1       1       1
-       1       1       4       1       5       0       1       1       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       3       2       3       1       0       2       1       1       1       1
-       1       2       1       2       1       0       0       0       1       0
-       1       1       1       0       3       2       0       1       2       0
-       2       1       1       2       0       1       3       1       1       1
-       0       1       1       3       2       1       1       1       3       2
-       3       3       0       0       1       1       1       0       0       0
-       0       1       1       1       0       0       0       1       1       0
-       2       1       0       2       1       0       0       1       0       2
-       2       2       2       1       1       1       2       3       0       2
-       0       2       1       2       0       0       0       2       0       0
-       1       1       0       0       2       2       3       1       0       0
-       1       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       1
-       2       1       1       0       0       1       0       1       0       0
-       1       0       1       0       0       0       0       0       0       0
-       1       1       1       0       0       0       3       0       0       0
-       2       0       0       0       0       1       0       0       0       1
-       0       1       1       3       0       2       0       2       1       0
-       1       0       2       0       4       1       0       1       1       0
-       1       3       0       1       1       2       0       2       0       1
-       1       3       1       0       0       0       0       1       2       1
-       0       2       1       0       1       2       1       0       0       1
-       3       0       1       1       2       0       1       0       0       1
-       0       0       1       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       1       0       2       0       1
-       0       0       0       1       2       1       2       1       1       1
-       0       0       1       2       1       0       1       0       1       0
-       0       2       0       1       1       0       3       0       0       0
-       1       1       0       2       0       1       0       0       1       1
-       1       3       2       2       0       0       2       0       1       0
-       2       0       1       2       0       0       0       1       2       1
-       2       1       0       1       1       0       0       0       1       2
-       0       0       1       0       1       2       0       1       0       1
-       2       0       1       0       0       0       0       1       0       2
-       0       1       1       5       0       1       1       1       2       1
-       0       0       0       2       1       2       0       1       0       0
-       0       0       0       0       0       0       0       0       1       1
-       2       0       1       0       0       1       0       2       2       0
-       0       0       1       0       1       0       1       2       0       0
-       2       0       2       1       0       0       0       3       1       2
-       1       1       0       0       0       0       0       1       1       1
-       0       2       1       0       2       2       0       0       0       0
-       1       0       0       2       1       0       0       1       1       1
-       1       1       2       1       0       1       3       0       2       1
-       1       0       0       1       0       3       0       0       2       0
-       1       0       0       1       0       2       1       1       0       2
-       3       0       1       2       0       0       0       0       0       0
-       0       1       0       2       1       0       1       0       1       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       1       1       0       1       1       0
-       1       0       1       1       1       0       0       0       0       1
-       0       3       1       0       0       2       2       1       0       0
-       1       0       0       3       1       1       0       1       2       1
-       1       0       0       2       1       1       1       0       0       0
-       0       1       0       0       2       0       0       1       1       1
-       1       0       0       0       1       2       2       1       0       1
-       1       1       1       2       0       1       0       0       1       3
-       2       4       0       2       2       2       1       0       0       0
-       0       0       0       0       0       0       0       0       1       0
-       0       0       2       2       0       1       3       1       0       0
-       0       1       0       0       0       0       0       0       0       0
-       0       0       0       0       1       0       0       1       0       2
-       0       0       0       1       0       1       0       0       0       0
-       0       0       1       0       1       0       0       0       2       2
-       0       1       1       0       0       0       1       5       0       1
-       0       1       0       3       4       1       1       1       0       1
-       0       0       0       1       0       1       2       2       0       1
-       0       1       2       2       0       2       0       0       3       1
-       1       1       0       1       0       2       0       0       0       3
-       0       2       1       1       0       0       0       0       0       1
-       0       2       3       2       0       1       0       1       0       0
-       0       2       1       0       1       1       0       0       1       0
-       0       1       0       1       1       1       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       1
-       2       3       5       2       0       3       2       0       3       3
-       6       1       3       4       2       3       1       3       3       0
-       3       4       2       9       9       3       1       1       1       3
-       7       4       0       4       3       1       5       3       3       2
-       5       5       3       3       4       5       2       3       2       4
-       0       4       4       3       2       7       1       1       1       4
-       1       4       1       1       4       2       4       3       7       3
-       2       4       2       5       3       2       6       5       3       2
-       3       3       3       7       3       1       2       0       3       1
-       2       0       6       1       2       2       1       2       3       4
-       2       3       4       5       2       3       3       3       1       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       2       0       0
-       0       0       0       2       1       4       0       1       0       0
-       3       2       1       0       0       2       1       2       1       0
-       1       0       1       0       0       0       2       0       0       0
-       2       1       0       0       2       2       0       1       0       0
-       0       2       3       0       1       0       0       0       0       2
-       0       1       0       2       0       1       2       1       1       1
-       0       1       1       2       0       2       4       0       2       1
-       1       0       1       2       0       0       2       0       0       1
-       1       0       1       0       1       0       0       3       2       0
-       1       0       2       0       1       2       0       2       0       1
-       1       1       1       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       3       0       0       1       1       1       0       3
-       3       1       1       1       0       0       1       1       1       0
-       1       2       0       0       2       2       0       0       0       0
-       1       0       1       3       0       0       0       2       1       0
-       1       1       2       2       0       0       0       0       0       2
-       0       0       3       0       2       0       0       0       0       0
-       3       1       0       1       1       0       0       0       0       2
-       1       1       0       1       0       0       3       0       2       0
-       0       1       0       3       0       0       1       1       0       1
-       1       1       1       0       1       0       0       1       1       0
-       1       0       0       0       0       1       1       1       1       2
-       0       0       0       1       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       1       0
-       0       1       0       0       1       3       0       1       1       0
-       0       0       0       0       2       1       0       3       1       2
-       1       0       0       0       1       2       1       1       1       0
-       0       2       1       0       0       0       1       2       1       0
-       0       0       1       1       1       2       1       0       0       0
-       0       0       1       0       1       0       0       0       2       1
-       0       3       0       0       1       1       1       1       0       0
-       0       0       0       1       1       1       1       0       1       1
-       1       0       1       2       0       0       1       1       0       0
-       2       1       0       1       1       1       1       0       1       0
-       0       1       1       0       2       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       1       1       1       1       1       2       2       0       0       1
-       0       0       0       2       0       1       1       0       1       2
-       1       0       0       3       0       0       2       2       1       0
-       1       0       2       0       2       0       2       3       1       0
-       1       2       0       1       1       0       0       0       0       1
-       1       0       1       0       0       0       0       2       3       0
-       0       1       0       2       1       0       0       0       2       2
-       0       5       0       4       0       2       0       1       0       0
-       1       0       0       0       0       0       1       0       0       0
-       0       1       1       0       0       2       0       1       1       2
-       2       2       0       1       0       0       1       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       1       0       0       1       2       1       0       1
-       1       0       0       1       0       0       1       0       0       2
-       1       0       1       0       1       1       1       1       1       1
-       2       0       2       0       0       1       1       1       1       0
-       0       1       0       0       2       1       2       0       2       2
-       0       1       2       1       3       0       0       1       0       0
-       0       1       0       1       1       2       0       0       1       2
-       0       1       1       0       0       0       2       1       1       1
-       0       2       0       0       0       0       1       1       1       2
-       0       4       3       1       0       1       1       1       3       0
-       0       0       2       2       0       1       2       0       0       0
-       0       1       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       1       0
-       1       0       0       1       0       1       1       0       1       0
-       1       0       1       2       1       1       2       1       2       2
-       0       0       0       0       0       0       1       1       0       2
-       1       1       0       1       0       0       1       3       0       0
-       2       0       2       1       0       0       0       0       1       0
-       0       1       1       0       1       0       1       1       2       0
-       1       0       1       0       1       1       0       0       0       0
-       0       1       0       0       0       0       0       3       0       1
-       1       0       0       0       0       1       1       0       5       0
-       1       0       0       1       0       1       1       0       0       2
-       1       0       0       0       0       0       1       0       0       0
-       0       0       0       0       0       0       0       0       1       2
-       2       1       1       1       3       1       4       2       2       1
-       1       3       3       0       3       2       4       2       1       2
-       1       0       2       3       5       4       2       0       2       1
-       3       4       0       0       0       2       1       2       1       1
-       1       2       4       2       2       0       3       5       2       1
-       5       4       4       2       6       8       3       1       1       4
-       3       2       5       1       3       2       1       2       3       2
-       4       1       3       2       1       3       1       1       4       1
-       3       0       3       4       2       1       1       4       1       1
-       1       3       3       2       2       4       1       0       3       2
-       1       2       3       2       3       0       1       0       2       1
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       1       1       1       0       1       2       2       0       1       0
-       0       3       0       0       3       1       0       1       1       0
-       1       2       0       1       1       0       0       1       0       0
-       0       0       0       0       1       0       1       1       1       2
-       0       2       0       0       1       1       0       0       0       1
-       0       1       0       0       0       2       2       0       0       2
-       2       2       0       2       0       2       0       0       3       1
-       1       1       0       0       1       1       1       0       1       2
-       2       1       1       2       0       1       0       1       2       0
-       1       0       2       0       1       0       1       2       1       0
-       0       1       1       0       4       1       1       1       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       1       0       2       0       2
-       1       2       2       0       0       0       0       3       0       1
-       0       1       1       0       0       1       1       0       1       1
-       2       0       2       0       2       0       2       0       1       0
-       2       1       0       0       2       0       2       0       1       0
-       0       1       0       0       0       1       3       0       1       0
-       1       0       1       2       0       3       0       1       1       0
-       0       0       1       1       1       1       0       1       0       0
-       4       2       1       1       2       3       0       0       1       1
-       1       1       2       0       0       1       1       0       0       1
-       0       1       1       1       0       1       2       1       0       0
-       0       0       1       1       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       1       0       0       0       0       1       1       1       2       1
-       0       0       0       2       0       1       1       1       1       0
-       2       2       1       0       2       3       0       0       0       3
-       3       2       1       1       2       0       1       2       0       0
-       0       2       0       1       1       0       0       0       0       1
-       0       2       1       0       0       1       0       1       0       0
-       3       0       0       0       1       1       3       1       1       0
-       1       1       0       2       0       1       1       0       2       0
-       2       0       0       0       2       0       0       0       0       0
-       1       0       1       3       0       1       1       0       0       1
-       1       3       1       2       2       2       1       0       1       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       1       0       0       0       0       0
-       0       1       1       0       2       0       2       1       1       2
-       1       0       1       1       0       0       2       0       0       0
-       0       1       0       1       3       0       1       2       1       0
-       1       0       1       2       1       1       2       1       0       0
-       2       0       2       2       1       1       1       1       0       0
-       1       4       2       2       0       2       0       1       0       1
-       1       1       2       1       2       1       1       0       1       2
-       2       0       0       1       0       1       1       1       1       0
-       1       0       1       1       0       0       4       1       0       1
-       0       1       1       0       1       2       1       1       0       1
-       0       1       1       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       1       0       2       1       1       1
-       0       1       1       0       0       0       0       0       0       1
-       1       1       1       0       2       0       1       2       0       3
-       0       1       0       0       2       0       2       1       1       2
-       0       1       0       1       1       0       0       0       1       1
-       0       2       0       0       2       0       1       0       1       2
-       0       1       3       1       1       1       0       0       1       2
-       1       1       1       0       1       2       0       2       1       0
-       1       1       1       1       2       1       0       1       1       4
-       1       2       1       0       3       0       2       0       2       1
-       1       0       0       0       1       0       2       2       0       1
-       2       2       1       0       1       0       0       0       0       0
-       0       0       0       0       0       0       0       0       1       1
-       1       1       0       2       0       1       0       0       0       1
-       1       1       4       0       0       1       1       1       0       2
-       1       0       1       3       2       0       1       2       0       0
-       1       0       1       1       2       4       3       0       1       3
-       1       0       0       2       0       0       2       2       0       0
-       4       1       1       3       1       0       1       1       1       0
-       0       0       0       1       2       0       2       0       0       0
-       1       0       3       0       1       1       0       1       1       1
-       1       0       2       5       1       0       1       1       0       1
-       1       1       1       2       0       0       0       1       1       0
-       0       0       2       1       1       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       1       1       1       1       1       1       2
-       1       5       1       2       0       0       2       0       0       0
-       1       0       2       0       1       0       0       1       1       1
-       1       2       1       1       0       0       0       0       1       1
-       2       0       1       0       2       1       3       0       0       2
-       0       1       1       0       1       0       0       2       1       2
-       1       1       2       1       1       0       2       1       1       0
-       0       1       2       0       1       0       1       0       0       0
-       1       0       1       0       1       1       1       1       1       0
-       1       0       1       0       0       3       0       2       2       0
-       2       0       0       1       2       0       1       1       1       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       1       2       2       1       0       3       3
-       3       3       1       1       0       0       1       1       0       1
-       1       5       1       1       2       5       0       3       3       1
-       3       1       2       2       3       2       2       0       4       4
-       1       2       1       2       0       2       1       3       2       3
-       2       2       1       1       2       3       5       1       0       2
-       1       1       1       2       0       1       0       4       0       0
-       7       3       1       1       0       3       1       2       2       2
-       3       0       0       1       3       1       2       1       2       1
-       3       1       0       1       0       1       3       0       2       1
-       0       2       4       0       2       1       2       1       2       2
-       2       0       0       0       2       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       1       1       0       0       0
-       2       0       1       0       0       0       2       3       4       2
-       2       2       1       4       0       3       2       0       1       2
-       2       0       1       1       1       0       0       0       1       0
-       0       1       0       2       2       2       1       0       1       1
-       3       0       1       1       2       0       1       1       0       0
-       1       0       1       0       1       2       1       0       1       0
-       1       1       1       0       0       0       2       0       0       1
-       0       1       2       0       1       0       0       3       2       0
-       1       0       0       2       1       1       1       1       4       2
-       0       2       0       0       0       1       1       1       0       2
-       0       0       1       1       1       0       0       0       0       0
-       0       0       0       1       1       0       0       0       2       2
-       0       1       1       0       0       1       0       1       0       1
-       0       1       1       3       0       1       2       0       2       1
-       1       1       0       1       1       1       3       2       0       2
-       2       1       1       1       0       2       0       0       2       1
-       0       0       1       1       1       1       0       1       0       1
-       1       1       0       1       0       1       0       2       1       0
-       1       2       0       0       0       0       0       0       1       2
-       1       1       1       0       1       0       0       1       1       0
-       0       2       0       0       0       1       1       0       1       0
-       0       1       0       2       1       0       2       0       0       1
-       1       0       0       0       1       0       0       0       0       1
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       1
-       1       1       2       1       1       0       1       0       1       1
-       0       0       0       0       0       0       1       0       1       0
-       3       1       2       1       1       1       1       0       4       1
-       1       1       2       0       1       1       0       0       0       1
-       1       1       1       2       0       1       3       1       0       0
-       0       0       1       1       2       2       0       2       1       0
-       1       0       1       1       3       3       2       0       3       2
-       0       1       1       2       3       2       0       1       1       0
-       0       1       0       1       2       1       0       1       1       1
-       2       0       0       0       2       3       0       1       0       0
-       0       1       1       0       0       0       1       2       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       1       1       1       1       2       0       1
-       1       0       1       0       0       1       0       1       1       2
-       1       2       0       3       0       0       2       0       0       2
-       1       2       0       1       2       3       5       1       0       3
-       0       1       2       2       1       0       2       0       0       2
-       1       1       3       2       1       4       1       1       1       0
-       0       2       1       2       1       0       2       0       0       4
-       2       0       3       1       1       1       2       3       2       0
-       5       3       2       2       5       0       1       1       1       3
-       3       0       0       3       0       4       0       1       2       1
-       0       0       2       3       0       2       5       1       2       2
-       0       0       2       0       0       1       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       1       1       0       0       1
-       1       3       1       0       0       1       0       2       0       1
-       0       0       0       1       2       4       2       1       1       0
-       2       0       2       1       1       1       1       0       1       0
-       0       1       0       1       0       2       0       1       1       0
-       1       1       1       1       2       0       0       0       0       0
-       3       1       0       0       2       0       0       2       1       1
-       0       0       1       0       0       1       0       0       1       2
-       0       0       3       1       0       0       2       0       0       1
-       0       1       0       0       1       1       1       1       0       1
-       0       1       0       1       2       1       0       0       1       3
-       2       3       2       2       1       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       1       0       0       0       0       1       0       0       0       0
-       0       0       2       0       0       1       2       1       0       0
-       0       0       2       0       1       1       0       1       0       1
-       1       0       2       0       1       0       3       1       1       2
-       1       1       1       2       1       2       1       0       1       1
-       1       0       0       3       1       1       1       0       0       1
-       2       4       1       0       1       1       0       0       1       2
-       0       1       1       2       0       2       0       0       0       2
-       1       1       1       1       0       3       2       2       2       0
-       2       2       1       2       1       1       1       1       1       0
-       2       0       0       2       3       1       5       0       3       3
-       1       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       1       1
-       1       2       1       0       0       0       0       2       2       3
-       1       1       2       1       0       2       2       0       2       1
-       1       2       1       1       3       1       0       4       1       2
-       0       0       0       2       2       0       0       0       1       1
-       2       2       2       4       4       4       2       0       1       1
-       3       1       0       0       0       2       2       1       3       2
-       5       3       1       0       1       1       0       1       3       1
-       1       1       1       2       0       2       1       2       4       0
-       3       1       1       0       0       2       2       1       1       0
-       3       2       2       0       0       1       0       0       2       1
-       0       2       1       3       2       1       0       1       1       1
-       0       0       0       0       0       0       0       0       0       1
-       3       0       1       1       1       1       0       0       2       1
-       1       3       1       1       1       0       1       0       1       2
-       0       2       2       0       1       0       2       2       1       0
-       0       0       3       0       0       0       0       0       0       2
-       1       0       1       0       0       0       0       0       1       0
-       1       0       0       0       1       1       1       0       1       3
-       1       1       0       1       1       0       1       1       0       0
-       2       1       0       0       4       0       1       1       1       4
-       2       0       2       1       0       0       2       0       0       1
-       2       2       1       0       0       1       1       2       1       0
-       1       0       0       1       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       1       1       0       1       0       0       0       1       2       1
-       2       2       2       1       3       2       1       0       2       2
-       1       0       1       1       1       0       1       1       0       0
-       1       0       0       1       0       0       1       0       0       2
-       1       0       3       1       2       1       0       2       1       1
-       0       2       0       1       0       2       0       2       0       2
-       0       1       2       1       0       1       1       0       0       0
-       1       2       0       1       1       0       1       1       1       1
-       1       2       1       0       1       1       1       2       1       1
-       0       2       2       3       0       3       1       4       0       1
-       0       0       1       0       0       2       1       0       1       1
-       0       0       0       0       0       0       0       0       0       1
-       1       1       0       1       0       0       1       2       1       1
-       0       2       3       0       0       1       1       0       1       1
-       2       0       2       2       0       1       1       0       1       1
-       0       1       0       0       0       1       0       1       3       2
-       1       0       1       2       0       0       0       0       1       0
-       0       2       2       0       1       1       1       1       2       1
-       1       0       1       0       1       1       2       0       0       1
-       0       2       2       2       3       2       3       1       1       2
-       5       0       1       2       0       2       1       2       0       1
-       4       1       0       0       1       2       2       1       2       2
-       1       1       2       0       1       0       1       0       2       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       1       0       2       0       0       1
-       2       0       2       1       0       3       0       0       1       3
-       1       2       1       0       2       1       1       1       1       1
-       0       0       1       1       0       0       1       3       0       0
-       2       1       0       0       3       2       1       0       2       0
-       0       1       2       0       1       2       1       2       0       2
-       0       0       0       0       0       0       0       0       3       0
-       0       1       2       0       0       0       1       2       0       2
-       2       1       2       2       0       0       0       2       2       4
-       0       0       2       0       1       0       1       0       0       2
-       1       1       0       0       1       2       0       0       0       0
-       2       3       2       0       2       1       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       1       1       2       0       2       0       0       1       0
-       0       2       0       1       2       2       5       0       0       0
-       0       2       0       0       2       1       0       1       0       0
-       0       0       1       0       1       3       2       1       0       1
-       1       0       3       1       0       1       0       0       1       0
-       0       1       0       1       1       1       0       1       2       1
-       0       1       0       0       1       0       2       1       0       0
-       0       0       0       0       2       1       1       0       0       1
-       1       1       0       1       1       1       0       0       0       1
-       2       0       1       0       2       1       0       1       3       0
-       0       1       0       1       0       1       1       0       2       1
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       1       1       2       0       0       1       1       1       3       0
-       3       1       0       0       2       2       2       2       1       0
-       1       1       1       1       0       0       0       1       1       0
-       0       0       0       2       1       1       0       0       2       0
-       0       0       0       2       1       1       2       0       0       0
-       0       2       3       3       1       0       0       2       0       1
-       0       0       3       0       1       0       0       1       1       3
-       2       0       1       1       0       0       2       2       1       0
-       0       2       0       0       1       1       1       1       1       1
-       3       1       0       1       3       0       0       1       0       0
-       1       1       0       0       0       0       1       0       1       0
-       3       2       0       0       0       0       0       0       0       0
-       0       0       1       1       0       1       1       2       1       1
-       1       0       0       4       0       1       2       1       0       1
-       0       0       0       1       1       1       1       1       1       0
-       0       0       0       1       1       1       0       0       0       0
-       1       4       1       2       0       0       1       0       2       1
-       0       0       3       0       0       2       0       1       0       1
-       1       0       0       1       0       2       0       0       2       0
-       1       1       1       0       1       1       1       0       2       2
-       0       2       0       0       1       0       2       1       1       0
-       1       2       0       1       0       1       1       3       0       2
-       0       0       1       3       4       2       1       1       2       1
-       2       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       1       0       0       0       2
-       0       0       1       0       1       1       1       0       1       2
-       2       1       0       0       0       1       1       2       1       1
-       0       1       0       0       0       1       1       1       0       0
-       0       2       1       0       1       2       2       1       1       1
-       0       0       2       0       0       2       0       1       1       2
-       0       1       0       1       0       2       0       1       0       0
-       2       2       0       2       1       0       1       1       1       2
-       1       0       0       1       0       0       2       0       2       1
-       2       2       1       0       3       2       0       1       2       0
-       0       0       1       1       0       2       0       1       1       0
-       0       0       1       1       3       2       1       0       1       0
-       0       0       0       0       0       0       0       0       0       2
-       1       1       1       2       1       3       0       0       0       0
-       1       0       1       1       0       1       1       3       1       0
-       0       1       0       0       1       1       2       1       0       1
-       1       1       1       1       1       1       0       0       1       1
-       0       2       1       3       0       1       1       0       2       1
-       1       0       2       1       1       1       1       2       1       2
-       1       2       1       0       0       1       1       1       1       1
-       1       0       0       2       1       1       2       1       2       1
-       2       0       0       0       0       0       1       0       1       0
-       1       0       0       0       0       1       3       0       5       0
-       2       2       1       1       1       0       0       0       1       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       1       0       2       0       3       1
-       0       2       0       1       1       0       1       2       3       0
-       2       1       1       0       2       0       1       2       2       0
-       3       2       1       3       2       0       1       0       0       1
-       1       2       0       0       0       2       0       2       1       1
-       3       0       3       1       0       2       0       1       2       1
-       0       0       0       2       2       1       3       1       0       1
-       0       1       1       1       0       1       1       1       0       0
-       0       2       2       0       2       1       2       0       0       0
-       0       0       2       0       2       2       1       1       1       2
-       0       0       1       1       0       0       0       0       0       0
-       1       0       1       4       1       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       1
-       1       3       1       0       3       1       0       1       0       0
-       1       1       0       0       1       1       2       3       1       1
-       1       1       2       0       3       1       1       1       0       0
-       0       0       1       0       0       1       0       2       0       2
-       0       2       0       1       2       0       1       1       1       2
-       0       1       1       0       1       0       1       2       0       1
-       0       1       0       2       1       1       2       1       2       0
-       2       1       0       1       1       0       2       2       1       1
-       0       2       1       1       0       1       1       0       2       0
-       1       2       0       0       0       2       3       0       0       1
-       0       1       1       5       2       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       1       0       0       0       1       1
-       1       0       2       1       3       0       2       2       0       0
-       0       2       0       2       0       2       2       0       0       0
-       0       1       0       1       0       1       0       2       0       0
-       0       1       2       0       0       2       1       2       1       3
-       2       0       0       1       0       2       1       2       0       1
-       0       0       3       0       1       1       0       1       2       2
-       0       0       2       1       1       1       0       1       0       0
-       0       0       1       0       0       0       2       0       1       1
-       0       2       0       0       1       1       0       1       0       0
-       0       3       1       2       0       1       1       2       1       1
-       0       0       1       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       1       0       1       4       0       1       1       1       0
-       2       0       2       0       1       0       1       1       0       2
-       0       0       1       0       0       3       0       1       1       0
-       0       1       1       1       0       1       3       2       0       0
-       0       2       2       1       0       0       0       2       0       2
-       1       2       1       1       0       0       1       1       1       2
-       1       2       2       0       3       2       2       0       2       0
-       0       1       0       0       0       0       1       1       1       0
-       2       1       0       0       0       1       1       2       0       2
-       1       1       0       0       0       0       2       0       1       0
-       1       1       3       3       0       1       1       1       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       1       0       1       0       2
-       2       1       1       1       0       1       1       1       0       1
-       1       2       0       1       3       1       1       2       2       1
-       2       1       0       1       4       1       0       0       2       1
-       2       3       1       0       1       1       0       3       2       1
-       1       1       2       1       2       0       1       1       1       3
-       4       4       4       0       1       2       4       0       0       0
-       1       1       0       0       1       0       1       0       0       1
-       0       0       0       1       1       1       0       1       0       2
-       1       1       0       0       0       0       1       1       0       1
-       0       1       1       0       0       0       1       1       0       0
-       1       3       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       1       0       1       0
-       1       0       1       0       1       0       0       1       0       0
-       0       0       1       1       2       6       1       1       0       1
-       1       1       0       0       1       0       1       0       0       2
-       0       2       3       0       1       4       0       2       1       0
-       0       0       0       1       0       0       0       1       1       1
-       2       0       0       0       2       1       0       2       3       0
-       0       2       2       0       1       2       3       0       1       0
-       2       1       1       1       0       1       1       1       2       1
-       2       1       1       2       0       1       1       0       1       2
-       1       2       1       2       3       3       1       2       0       3
-       1       1       0       0       1       1       0       1       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       1       3       1       0
-       3       1       2       1       0       1       3       2       0       0
-       0       1       2       0       3       1       1       1       0       3
-       2       0       3       2       0       2       1       1       0       0
-       1       2       0       0       1       1       2       1       1       2
-       1       1       0       1       3       2       0       0       0       1
-       2       2       0       0       1       0       0       3       1       3
-       2       3       1       0       1       3       0       0       1       1
-       0       1       0       0       0       0       1       0       2       2
-       0       1       0       2       0       0       0       1       0       0
-       0       1       2       1       2       3       0       2       1       0
-       1       1       0       2       0       0       0       0       0       0
-       0       0       0       0       0       0       0       2       0       0
-       3       1       2       1       0       1       1       1       0       0
-       0       3       1       1       1       2       2       1       0       0
-       2       1       1       2       0       1       1       0       1       0
-       1       3       1       2       1       2       0       0       0       1
-       0       1       1       0       2       1       4       1       2       0
-       1       2       1       2       2       0       0       2       1       0
-       3       1       3       1       1       2       0       0       1       1
-       2       3       2       1       5       0       0       3       0       1
-       0       0       0       2       1       1       1       1       1       0
-       0       1       2       2       0       0       3       0       1       2
-       0       0       1       1       0       1       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       3       0       0       3       0       0       2       1       0
-       2       1       0       1       1       2       1       1       0       2
-       1       0       1       2       4       2       2       1       0       1
-       1       0       1       2       0       1       0       2       1       1
-       0       1       0       1       1       1       1       2       0       0
-       1       2       0       3       0       2       1       0       3       3
-       1       1       0       0       0       0       0       0       1       0
-       0       1       0       0       1       3       1       2       4       0
-       0       0       1       1       1       1       2       2       0       1
-       1       0       0       2       1       0       5       1       1       0
-       1       2       1       0       1       1       1       0       0       0
-       1       0       1       0       0       0       0       0       0       0
-       0       0       0       1       0       0       2       1       1       2
-       0       2       1       0       1       2       0       1       0       1
-       0       0       0       1       1       2       1       1       1       0
-       3       0       0       1       0       1       1       2       1       0
-       1       0       1       2       1       2       1       2       1       0
-       0       0       1       1       2       1       2       2       1       1
-       0       1       0       1       2       2       1       1       1       2
-       1       1       1       0       1       1       0       0       2       1
-       2       3       1       2       4       1       0       1       0       1
-       1       1       0       1       0       1       0       1       4       1
-       0       3       0       3       0       0       1       2       1       1
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       1       0       0       1
-       1       3       2       2       1       1       1       2       2       2
-       1       3       0       0       0       0       1       1       2       0
-       1       1       2       2       1       2       3       2       0       3
-       0       2       0       1       1       3       4       0       0       3
-       1       2       1       1       0       4       0       3       1       2
-       1       3       0       1       2       3       1       1       1       2
-       3       3       3       2       1       2       2       2       2       1
-       2       1       0       0       2       3       1       1       0       1
-       0       1       2       2       0       2       3       1       0       2
-       4       2       0       1       0       0       0       0       0       0
-       4       0       2       1       0       2       0       0       0       0
-       0       0       0       0       1       1       0       1       0       0
-       1       1       1       1       0       2       1       1       2       5
-       0       0       0       1       1       0       3       4       2       0
-       1       1       0       2       0       1       1       1       1       1
-       1       0       0       1       0       0       0       1       2       0
-       0       1       1       2       1       0       3       1       1       0
-       2       2       0       0       1       1       1       0       3       2
-       2       0       0       1       0       1       1       1       1       2
-       0       0       2       0       1       0       0       0       1       0
-       1       0       0       0       0       0       1       0       0       0
-       0       3       1       1       2       2       3       2       2       2
-       1       0       0       2       3       1       2       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       1       1       0       1       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       3       1
-       0       6       3       1       1       1       0       0       0       0
-       0       0       0       0       0       0       1       2       0       2
-       0       1       4       3       0       1       1       2       1       1
-       0       2       0       0       1       0       1       2       1       1
-       1       1       1       2       0       0       1       2       0       2
-       2       4       1       1       1       1       0       2       1       4
-       2       2       1       0       0       1       1       0       1       1
-       0       2       0       2       0       2       0       2       1       1
-       1       1       1       1       0       0       0       0       0       0
-       0       1       0       1       0       0       1       0       0       3
-       0       2       0       1       0       0       0       1       0       2
-       1       0       0       1       0       1       0       0       0       1
-       0       0       1       1       1       2       3       1       2       0
-       0       1       2       1       2       0       1       2       2       1
-       2       0       1       0       2       2       1       2       2       1
-       0       1       1       1       2       0       4       0       1       0
-       0       1       0       1       0       0       0       0       1       2
-       0       3       0       0       0       2       2       2       4       0
-       2       1       0       0       2       3       1       2       1       1
-       2       1       0       3       1       3       0       3       2       0
-       3       1       3       1       0       0       0       0       2       0
-       0       1       1       0       1       2       0       1       0       0
-       0       0       0       0       1       1       1       0       0       1
-       1       2       0       0                                                
-SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS
-       3      22      25  123944       0       1                                
-FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
-       6       1                                                                
-            time         monitor       Total Cou     angles*1000                
-  0.35739000E+05  0.30000000E+06  0.16464000E+05  0.15260500E+06  0.40200000E+03
-  0.50810000E+05                                                                
-IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
-   16384                                                                        
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       1       0       1       0       0
-       2       1       0       1       0       0       0       0       0       0
-       1       2       1       0       0       1       0       1       1       0
-       0       2       0       0       0       0       1       0       1       1
-       0       1       1       0       1       1       1       1       1       1
-       0       2       0       2       2       0       1       0       0       0
-       0       0       0       0       1       1       3       0       2       0
-       1       0       0       0       0       0       0       2       2       0
-       1       0       0       0       0       0       0       0       1       1
-       1       0       1       1       0       0       0       0       1       0
-       0       1       0       0       1       0       2       0       0       0
-       0       0       0       0       0       1       1       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       1       0       0       1       0
-       0       1       0       1       1       1       1       1       0       1
-       0       1       1       0       0       1       1       2       0       0
-       0       1       0       1       2       0       1       0       0       1
-       1       1       0       0       0       0       1       2       1       0
-       0       0       0       0       1       1       3       0       0       0
-       0       1       1       1       0       1       0       1       1       1
-       1       0       0       0       1       1       1       0       0       1
-       2       0       2       1       0       0       0       1       1       2
-       1       0       0       0       1       1       0       1       0       1
-       2       1       1       2       0       1       1       1       1       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       1       0
-       0       0       0       1       0       0       2       0       0       0
-       0       0       3       1       0       0       1       1       0       0
-       0       0       0       0       1       1       0       1       0       0
-       0       0       0       0       0       1       1       0       0       0
-       0       2       0       0       0       0       1       1       0       1
-       1       1       1       2       2       0       0       1       1       1
-       0       0       2       2       1       0       0       0       0       0
-       1       1       1       0       1       1       0       0       1       0
-       0       0       0       1       1       0       1       2       0       0
-       1       1       0       1       0       0       0       1       1       0
-       0       0       1       1       1       1       1       1       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       1       0       1       0       0       1       1
-       0       2       0       0       0       0       0       0       2       1
-       0       2       1       2       0       0       1       0       1       0
-       1       0       0       0       1       0       0       1       1       1
-       0       1       0       1       0       2       1       0       2       0
-       0       1       0       1       3       1       1       0       1       0
-       1       1       1       2       0       0       0       2       1       1
-       0       1       0       2       0       0       0       0       1       2
-       0       0       0       1       0       0       0       1       0       0
-       1       1       0       0       0       1       0       0       1       0
-       0       1       1       1       1       1       1       1       0       0
-       0       0       1       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       1       1       1       1
-       0       0       0       0       1       0       1       0       0       0
-       1       0       1       1       1       0       0       0       0       1
-       2       1       0       0       0       4       1       0       4       1
-       0       0       1       0       0       0       1       2       1       0
-       1       2       0       2       0       4       1       1       0       0
-       3       1       1       1       1       1       1       1       1       1
-       1       1       1       0       0       0       0       1       0       0
-       0       0       1       0       0       0       0       1       0       3
-       1       0       0       0       1       0       0       0       1       1
-       1       1       1       0       0       0       0       2       0       0
-       1       0       1       0       1       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       1       0       1       3       0       3       1       0       2
-       0       0       2       1       1       0       0       0       1       3
-       1       1       1       1       0       3       2       0       0       0
-       0       4       0       1       1       1       2       1       0       1
-       0       1       0       0       0       1       4       2       1       1
-       1       1       1       1       2       0       0       0       2       1
-       2       3       0       0       1       0       1       1       0       0
-       1       1       1       0       0       0       0       0       0       0
-       3       1       0       0       0       2       1       2       0       0
-       2       1       0       2       1       1       2       2       0       0
-       0       1       1       0       0       2       0       0       1       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       1
-       0       1       0       1       2       0       1       1       5       2
-       0       2       3       6       1       2       4       4       2       1
-       2       2       5       2       4       5       5       8       0      10
-       6       2       2       5       4       4       4       2       6       8
-       4       4       7       5       7       5       4       6       3       8
-       2       4       6       1       5       5       8       5       7       6
-       3       8       3       4       3       3       8       4       4       3
-      12       7       7       5      12       4       9       4       1       4
-       1       3       5       4       5       4       3       3       5       7
-       4       5       1       2       1       3       2       0       0       0
-       7       0       2       1       2       1       2       0       0       0
-       0       0       1       1       0       0       0       0       0       0
-       0       2       0       1       4       4       3       4       3       1
-       1       2       1       0       2       0       2       3       2       3
-       3       3       2       4       3       0       1       3       2       4
-       3       3       2       2       5       2       1       4       3       6
-       6       3       4       6       2       9       2       4       5       0
-       3       2       7       4       3       1       1       3       8       4
-       0       4       3       1       4       2       1       3       7       6
-       3       5       3       5       2       3       2       5       2       2
-       5       4       4       5       3       1       6       4       5       5
-       5       3       2       2       5       2       4       3       3       4
-       1       1       2       3       3       1       1       3       0       1
-       1       1       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       1       0       2       1       4       2
-       3       3       6       3       2       0       1       3       6       1
-       1       4       2       2       2       6       2       4       2       1
-       3       3       4       2       3       4       0       3       4       2
-       0       2       5       3       3       3       1       0       3       2
-       2       5       4       0       0       1       1       1       3       3
-       1       4       3       2       3       1       2       5       1       1
-       3       5       4       3       2       1       6       0       1       2
-       4       2       6       2       1       4       2       2       3       9
-       4       1       2       1       3       5       1       2       3       4
-       6       0       3       1       3       0       0       2       2       4
-       2       3       3       0       0       0       0       0       0       0
-       0       0       0       0       0       1       2       1       1       5
-       1       4       2       1       3       2       2       3       2       3
-       2       4       1       3       3       1       2       1       1       3
-       0       2       3       2       1       1       2       0       1       3
-       2       3       0       1       3       6       4       1       8       1
-       3       2       2       3       2       0       2       3       4       1
-       0       0       2       3       2       4       4       3       3       1
-       1       1       6       3       3       4       2       1       1       0
-       0       3       4       0       4       4       2       2       2       4
-       0       2       1       2       0       0       2       1       1       3
-       4       2       3       2       1       5       2       1       3       2
-       1       3       0       2       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       1       0       0       1       0       0       2       4       1       0
-       4       0       1       2       3       1       2       0       2       1
-       2       2       2       2       1       3       0       2       5       2
-       3       2       2       1       0       1       3       2       3       2
-       0       0       0       0       2       2       1       6       2       2
-       1       1       0       1       0       4       1       2       1       4
-       1       1       2       1       0       2       2       1       5       3
-       2       2       0       1       0       1       2       1       3       0
-       2       4       2       4       0       1       0       3       1       2
-       2       3       1       4       1       3       2       4       0       3
-       0       1       0       0       2       1       1       3       2       0
-       2       0       0       1       0       0       0       0       0       0
-       0       0       0       0       0       0       1       0       2       1
-       3       2       3       0       1       1       1       2       2       1
-       4       1       5       0       1       0       1       3       2       2
-       1       6       2       6       0       3       4       0       4       0
-       1       4       1       3       1       2       2       0       2       2
-       2       1       4       1       0       0       1       2       2       0
-       2       1       1       1       1       2       1       4       2       2
-       0       2       4       1       1       1       2       1       0       0
-       2       4       1       0       3       1       2       0       2       2
-       0       0       3       3       1       1       1       1       1       1
-       1       0       2       3       1       1       0       3       2       1
-       0       0       0       3       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       1       0       0       2       1       1       2       0       1
-       0       4       4       0       2       2       0       4       2       3
-       2       0       0       1       1       4       1       3       1       3
-       0       2       3       1       2       0       4       2       3       3
-       1       0       1       2       1       4       0       1       4       1
-       1       2       3       1       3       3       2       1       3       4
-       3       2       1       2       1       3       2       1       4       1
-       0       2       0       1       0       0       0       0       1       1
-       3       0       0       1       3       0       2       2       3       1
-       2       3       0       2       2       0       0       3       0       1
-       0       4       2       2       3       1       3       0       0       2
-       0       0       0       0       0       0       0       0       0       0
-       0       0       1       1       2       0       1       0       1       2
-       2       2       0       4       5       0       1       1       1       3
-       0       2       1       3       2       4       1       1       0       4
-       4       2       1       5       2       1       2       4       2       4
-       1       1       1       3       2       2       0       1       1       0
-       1       0       3       4       0       3       4       2       0       3
-       4       2       4       1       0       0       0       3       3       1
-       5       0       1       0       0       1       2       0       0       2
-       2       4       0       2       2       1       1       3       3       3
-       1       0       0       0       0       2       2       1       2       0
-       0       2       1       0       1       1       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       2       2       1       1       2       1
-       2       1       0       0       1       1       2       1       0       1
-       0       0       3       0       1       1       1       1       0       2
-       0       4       1       1       1       1       3       2       0       1
-       4       2       0       0       2       2       3       0       1       4
-       2       3       4       2       1       1       3       1       1       1
-       2       2       1       1       0       4       1       1       2       0
-       2       2       1       0       1       3       4       0       1       1
-       4       1       1       0       1       0       1       1       2       0
-       1       1       1       3       0       1       1       1       0       4
-       2       0       1       3       0       1       2       3       2       1
-       1       0       0       0       0       0       0       0       0       0
-       0       0       1       0       4       1       1       3       3       2
-       1       0       0       2       0       0       1       0       0       1
-       1       2       1       0       1       1       0       2       0       1
-       2       3       1       0       2       0       2       2       0       2
-       0       1       2       1       2       0       1       2       2       0
-       2       1       0       2       2       2       2       1       2       0
-       2       0       1       1       1       2       0       1       1       1
-       2       2       0       2       2       0       0       5       2       1
-       2       0       1       2       2       2       0       0       1       0
-       0       1       3       0       2       3       1       1       0       1
-       0       1       2       1       1       2       0       1       3       1
-       1       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       2       0       2       2       0       1       1       0
-       3       3       2       2       2       1       1       1       1       3
-       1       1       3       1       2       1       1       0       3       0
-       0       1       1       2       1       2       3       0       1       1
-       1       0       1       0       2       2       1       2       2       2
-       3       0       1       0       1       0       3       2       1       1
-       1       4       1       5       2       1       1       0       2       0
-       1       1       1       0       2       0       1       3       0       0
-       3       1       0       0       1       2       0       2       2       2
-       0       1       1       1       0       1       1       1       1       1
-       1       0       0       1       0       2       1       1       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       1       0       0       0       1       2       1       0
-       2       3       0       1       2       0       3       4       0       2
-       2       1       4       1       3       1       1       2       4       2
-       1       1       2       0       0       0       3       2       1       0
-       2       3       3       1       2       3       1       1       0       0
-       2       2       1       1       1       1       1       1       0       1
-       0       1       4       2       1       4       3       4       2       0
-       3       2       2       0       2       3       0       2       2       4
-       3       0       2       0       1       2       1       2       0       0
-       0       1       1       1       2       0       1       2       0       4
-       4       2       0       0       3       1       3       2       0       0
-       0       2       0       1       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       1       2       2
-       0       1       4       4       2       4       1       2       1       1
-       2       2       3       2       2       2       0       1       3       2
-       2       1       2       0       0       1       0       0       0       4
-       2       1       1       1       1       1       3       2       2       2
-       3       3       1       1       2       2       3       0       2       2
-       1       3       2       2       1       2       2       1       1       1
-       0       4       4       3       2       1       1       1       4       0
-       4       3       3       1       3       1       4       0       0       0
-       0       1       3       1       1       0       4       2       2       2
-       2       0       1       1       3       3       1       0       1       0
-       2       1       2       0       0       1       0       0       0       0
-       0       0       0       0       1       1       2       1       2       0
-       2       0       2       1       1       0       1       1       2       2
-       1       0       0       0       1       0       1       1       4       0
-       2       0       0       1       1       0       1       0       1       2
-       2       1       1       0       2       1       2       0       1       3
-       2       1       1       0       0       1       1       0       0       1
-       2       0       2       0       0       2       2       2       1       1
-       0       0       3       1       2       0       1       0       0       1
-       1       1       0       1       1       1       0       1       0       2
-       2       1       2       2       1       1       1       2       0       2
-       0       1       0       2       1       2       1       0       1       1
-       1       2       1       1       0       1       2       0       1       0
-       0       1       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       1       1
-       0       3       1       0       0       2       0       1       0       4
-       4       2       0       1       3       1       1       1       0       1
-       2       1       0       1       0       5       1       0       2       3
-       3       1       1       1       2       0       0       0       0       1
-       1       0       0       0       2       1       2       1       0       1
-       4       0       1       1       0       1       0       0       1       1
-       1       0       1       0       2       1       2       1       1       1
-       1       1       1       1       1       1       3       1       0       0
-       2       0       0       3       2       1       2       1       2       1
-       2       0       0       0       0       1       0       0       1       3
-       3       3       1       1       0       0       3       1       0       0
-       0       0       0       0       0       0       0       0       0       1
-       1       1       0       2       1       0       2       6       1       2
-       0       0       0       2       0       1       0       1       3       0
-       1       2       1       1       1       1       0       2       2       3
-       1       0       3       3       2       0       2       2       2       0
-       1       0       2       1       1       0       3       2       2       0
-       4       1       0       0       1       2       3       0       3       0
-       2       0       0       3       2       1       0       2       2       1
-       0       3       1       1       1       0       1       1       2       2
-       1       0       5       1       2       1       1       2       0       2
-       0       0       4       0       0       0       1       2       2       0
-       2       1       1       0       1       0       1       0       2       1
-       1       1       1       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       1       0       0       0       0       1       3       1       2
-       0       2       2       1       1       2       0       1       0       0
-       2       1       0       0       0       2       1       3       0       0
-       2       0       2       2       1       3       1       1       2       0
-       0       0       1       1       0       0       2       0       0       2
-       3       0       1       1       0       1       0       0       1       3
-       0       0       0       0       0       1       4       4       1       0
-       1       2       1       1       1       0       2       1       4       0
-       1       0       1       1       1       1       0       1       0       1
-       0       2       0       0       1       1       1       1       2       0
-       1       1       1       1       1       2       3       1       0       0
-       1       0       0       0       0       0       0       0       0       0
-       0       0       0       1       0       1       2       1       0       0
-       1       1       2       0       1       2       0       1       0       0
-       2       0       0       1       1       1       1       0       1       3
-       0       2       1       1       0       1       1       4       0       0
-       1       2       0       0       0       2       0       1       2       1
-       1       2       0       0       1       0       1       2       0       1
-       1       3       2       4       0       2       3       4       5       0
-       1       2       1       1       0       1       2       1       1       4
-       1       0       2       1       1       3       0       3       1       2
-       2       2       0       1       0       3       1       1       3       3
-       3       0       0       2       3       2       0       1       0       0
-       0       0       1       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       1       0       0       0       0       1       1       0       0
-       1       0       3       3       2       1       1       3       3       0
-       0       1       1       1       2       1       1       2       1       2
-       1       2       0       2       1       2       2       2       1       2
-       1       0       0       1       0       2       3       2       1       0
-       1       2       0       2       4       4       2       0       1       1
-       2       1       0       3       0       1       2       2       3       0
-       0       1       3       0       1       2       2       1       0       2
-       0       0       1       0       1       2       1       1       2       2
-       0       0       2       0       0       1       2       2       3       2
-       3       0       3       0       0       0       0       0       1       0
-       3       0       0       1       0       0       0       0       0       0
-       0       0       0       3       1       1       1       2       2       1
-       2       2       2       0       0       0       1       1       1       3
-       1       1       2       2       1       1       1       1       0       0
-       1       2       2       3       1       0       1       0       1       0
-       2       2       0       1       0       0       0       3       1       1
-       0       1       2       0       2       0       3       0       0       1
-       0       0       3       2       3       2       1       2       0       1
-       0       1       4       0       2       3       2       2       0       1
-       2       2       1       1       1       4       1       1       1       2
-       0       1       3       1       3       0       2       4       1       1
-       2       2       2       2       0       0       1       0       1       1
-       0       1       1       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       1
-       1       1       0       0       1       0       1       1       1       1
-       1       0       2       1       0       1       0       0       0       2
-       4       3       2       0       0       0       0       0       0       1
-       1       1       1       1       1       1       2       4       0       0
-       0       1       1       2       2       1       1       1       1       3
-       0       0       0       4       1       6       0       1       2       1
-       1       0       2       3       0       0       1       0       0       1
-       0       0       1       1       1       1       1       1       1       0
-       2       1       3       1       0       0       2       0       2       0
-       0       1       0       0       0       1       0       1       1       1
-       1       0       1       1       1       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       2       0       0
-       0       0       0       1       1       1       0       0       0       0
-       0       1       0       0       1       1       0       2       1       1
-       1       1       2       3       0       2       0       1       0       0
-       0       3       3       0       2       2       3       0       0       1
-       0       1       0       2       1       0       1       1       0       1
-       2       1       3       1       1       1       0       1       0       2
-       1       0       0       2       0       1       3       1       1       0
-       3       0       2       1       2       3       0       2       5       1
-       3       1       0       3       3       1       1       0       0       1
-       2       2       2       2       1       1       0       0       0       4
-       2       1       0       1       2       0       0       1       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       1
-       2       2       1       0       1       0       1       1       1       1
-       0       2       0       1       3       1       1       0       1       0
-       0       0       3       1       2       1       1       0       4       2
-       0       0       2       0       0       0       0       0       0       1
-       1       1       0       1       3       2       1       2       0       0
-       1       3       0       2       1       1       1       0       0       2
-       0       2       0       1       2       0       1       1       1       1
-       2       0       1       2       1       0       1       0       2       1
-       1       2       0       2       1       2       2       1       1       2
-       3       0       1       0       2       1       1       1       0       4
-       2       0       1       1       0       1       0       0       0       0
-       0       0       0       0       0       0       0       0       1       1
-       0       0       1       2       2       1       1       1       0       1
-       4       2       1       0       1       3       0       1       0       1
-       0       1       0       1       0       0       1       0       2       1
-       1       2       0       2       2       2       1       0       2       3
-       0       1       2       1       0       1       0       0       1       1
-       1       1       1       0       0       1       1       0       0       4
-       2       2       0       0       1       1       3       1       2       1
-       1       0       1       0       0       3       2       1       1       2
-       2       1       0       0       1       0       3       0       1       3
-       2       2       1       2       1       2       2       0       1       0
-       1       1       0       1       0       0       0       0       1       1
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       2       1       1       1       1       2       0       4       2       1
-       0       1       1       0       0       1       1       3       1       1
-       2       3       1       0       1       1       0       0       3       1
-       1       2       1       2       2       0       3       1       3       0
-       0       0       1       0       1       0       0       0       1       0
-       1       1       3       1       1       0       1       2       1       2
-       1       2       1       1       2       0       0       2       1       2
-       0       1       1       1       1       1       2       1       2       1
-       0       3       2       0       1       0       4       0       2       0
-       1       1       0       0       0       2       2       0       0       0
-       0       1       0       2       1       1       1       1       3       0
-       0       1       3       0       0       0       0       0       0       0
-       0       0       0       0       1       2       1       0       0       0
-       0       1       0       0       0       1       2       1       0       1
-       0       0       0       1       0       0       1       1       1       0
-       0       3       0       0       0       0       2       0       1       0
-       1       0       1       2       0       1       3       0       0       2
-       2       3       2       0       1       1       0       0       2       0
-       1       3       2       0       1       1       1       2       1       2
-       1       2       1       1       0       0       0       2       1       0
-       1       1       0       0       2       3       0       2       1       3
-       0       0       2       2       3       0       2       3       3       1
-       1       3       1       1       1       1       1       0       2       0
-       2       1       0       1       1       1       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       3       1
-       1       0       2       0       1       0       2       1       0       0
-       2       1       2       0       1       1       0       1       3       1
-       1       1       2       0       0       0       1       1       0       1
-       0       4       2       1       1       1       1       2       2       1
-       1       3       1       0       2       1       1       1       0       2
-       2       2       2       2       2       0       1       1       1       0
-       1       3       2       0       1       5       2       0       0       1
-       0       1       2       1       0       2       2       0       1       1
-       0       1       0       0       0       0       0       1       3       0
-       0       0       1       1       3       0       2       2       1       1
-       0       1       2       0       0       0       3       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       1       1       2       0       0       1       0       4
-       0       1       1       0       1       2       1       1       0       1
-       1       0       2       3       0       2       0       0       1       1
-       1       0       0       0       1       1       1       1       0       0
-       0       1       0       1       1       1       0       1       0       2
-       1       0       1       2       2       0       3       1       0       0
-       2       0       0       0       1       3       1       2       1       3
-       0       0       1       1       3       0       1       1       3       1
-       1       3       0       4       3       0       0       0       1       0
-       2       3       1       2       1       4       0       1       4       0
-       0       0       1       0       1       1       1       5       0       2
-       0       0       1       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       1
-       1       0       0       2       1       0       0       1       0       1
-       3       0       1       2       0       2       1       0       0       3
-       1       1       2       0       1       2       1       0       3       1
-       0       0       1       1       0       0       2       1       1       0
-       0       1       0       1       0       1       0       2       1       0
-       3       1       1       1       0       0       0       0       2       2
-       4       2       2       4       1       1       0       1       0       0
-       1       3       0       1       1       2       0       5       0       1
-       1       3       1       0       1       0       1       1       4       2
-       0       0       1       1       1       0       2       5       1       2
-       2       1       4       1       4       1       0       2       1       2
-       1       2       3       0       0       0       0       0       0       0
-       0       0       0       0       0       0       1       0       2       0
-       3       1       1       1       3       1       0       1       2       1
-       1       0       3       4       4       2       1       1       1       3
-       2       2       2       1       2       2       0       1       1       2
-       1       0       2       3       5       2       0       5       2       4
-       1       5       4       4       6       3       6       3       3       2
-       3       3       3       2       4       2       3       4       2       5
-       5       5       3       4       2       5       1       3       1       2
-       2       1       0       1       3       2       5       3       0       4
-       1       2       4       1       1       2       3       3       1       4
-       1       3       2       2       3       1       1       1       0       2
-       0       0       1       1       0       3       1       0       1       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       1       1       1       2
-       2       7       7       9       4      11       6      21      12      10
-       6       9      10      14       7       8      10       9       6       5
-       6       7       8       5       2       3       2       5       4       3
-       2       3       2       2       1       2       1       1       1       1
-       2       1       2       0       2       1       2       1       1       1
-       0       1       0       1       0       1       0       1       0       2
-       1       1       0       2       3       0       1       3       1       1
-       3       1       0       5       2       6       8       4       1       7
-       4       1       1       4       2       0       3       5       3       2
-       1       5       5       0       4       5       4       7       7       3
-       5      11       6       7       1       8       2       3       1       0
-       0       0       0       0       0       0       0       0       0       0
-       0       1       0       3       0       2       1       5       0       0
-       0       0       0       1       2       2       0       0       1       2
-       0       3       0       0       0       2       1       2       3       2
-       1       2       0       0       1       2       2       1       0       0
-       1       2       2       1       3       3       0       1       1       3
-       1       1       0       5       2       0       3       0       2       1
-       2       1       1       0       0       1       1       0       3       2
-       4       2       3       1       2       0       0       1       2       0
-       0       3       1       5       2       1       2       0       0       1
-       1       1       4       1       1       2       2       2       1       0
-       4       2       2       0       0       2       2       1       1       0
-       1       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       1       2       0       1       0       0       1       1
-       0       0       0       1       0       3       1       1       1       0
-       0       0       0       2       0       4       1       0       2       3
-       1       2       0       2       0       2       0       1       3       2
-       1       0       1       1       1       1       0       2       1       0
-       0       1       0       1       2       0       0       2       0       1
-       1       2       2       0       2       3       3       0       0       0
-       0       0       1       0       1       1       1       1       0       4
-       0       2       1       1       0       1       1       1       4       1
-       0       2       0       0       2       2       0       3       2       1
-       0       2       0       0       2       2       1       0       3       0
-       1       1       0       2       0       1       1       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       3       0       0       0       0       2       1
-       2       4       1       0       1       0       0       0       1       1
-       2       1       0       0       0       1       1       2       1       0
-       1       1       0       2       0       2       0       2       0       0
-       2       1       0       1       0       1       3       1       0       0
-       1       0       2       2       1       2       0       2       0       1
-       0       2       1       1       0       0       3       0       3       0
-       1       2       4       1       0       1       3       1       2       2
-       1       1       1       0       0       3       1       0       0       1
-       3       0       1       2       2       2       2       0       0       0
-       1       0       2       1       1       1       1       1       0       1
-       1       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       1       0       0       0       1
-       2       2       1       1       0       1       1       0       1       0
-       1       1       0       2       1       1       5       1       0       0
-       1       0       0       1       0       1       2       0       1       0
-       0       2       1       0       0       1       0       0       1       1
-       0       1       2       1       1       4       1       0       1       1
-       1       0       0       3       4       1       3       1       0       1
-       1       1       0       0       1       0       1       0       2       0
-       2       2       1       1       1       0       0       3       0       0
-       2       0       2       1       2       2       2       1       1       2
-       2       2       1       0       0       2       2       0       0       0
-       1       1       2       0       0       0       0       1       1       0
-       2       0       0       0       0       0       0       0       0       0
-       0       0       0       1       2       2       2       2       3       1
-       2       2       0       1       0       2       1       0       1       2
-       1       0       1       3       1       1       1       2       0       2
-       2       0       3       0       0       2       1       1       0       1
-       0       0       0       0       1       0       2       4       1       3
-       0       3       2       0       1       0       2       0       1       0
-       1       1       0       2       1       2       2       1       0       1
-       1       1       1       0       3       2       0       3       1       1
-       0       0       0       1       1       2       1       2       2       0
-       1       0       1       0       3       0       1       3       2       1
-       0       0       2       0       1       0       0       1       1       1
-       1       0       0       1       1       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       1       1       0       1       1       0
-       0       1       0       2       3       0       4       2       2       1
-       0       0       2       1       0       1       2       2       1       2
-       1       2       1       1       2       1       1       1       1       2
-       0       1       2       1       1       0       3       1       0       3
-       0       1       2       2       0       1       1       2       1       2
-       0       1       1       0       2       1       1       0       1       0
-       0       3       1       0       2       4       0       0       0       2
-       0       6       0       1       0       0       2       0       0       1
-       1       0       1       1       3       3       0       2       2       0
-       0       1       0       0       0       0       0       0       4       1
-       0       1       2       0       0       2       1       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       1       0       1       2       1       2       3       0       0       1
-       2       1       2       0       1       0       0       2       2       2
-       4       0       0       0       1       0       0       1       0       0
-       2       1       0       0       1       1       3       2       0       2
-       0       1       0       2       2       1       0       1       1       0
-       1       1       2       1       2       2       0       1       1       1
-       0       1       0       1       0       1       4       1       0       2
-       2       0       0       0       1       4       0       2       1       2
-       3       2       2       0       0       0       0       0       2       0
-       1       0       4       0       2       0       0       1       0       1
-       0       0       1       1       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       1       0       1       2       2       1       3       2
-       1       1       0       1       2       0       1       0       0       2
-       1       1       1       2       1       0       0       1       2       0
-       0       0       2       1       2       0       0       1       0       0
-       2       0       0       1       1       0       0       0       3       0
-       1       2       0       0       0       1       0       1       2       0
-       0       3       0       1       1       1       2       1       3       1
-       2       2       1       1       0       1       0       0       1       2
-       1       1       1       1       1       3       1       0       0       0
-       2       1       1       2       2       0       1       0       1       0
-       1       0       1       3       0       1       1       1       3       1
-       0       2       1       0       1       0       0       0       0       0
-       0       0       0       0       0       1       1       2       0       2
-       0       2       1       2       2       0       2       2       2       1
-       2       2       0       1       2       2       2       2       0       2
-       2       0       0       2       0       2       5       2       0       1
-       5       1       5       1       3       2       0       1       4       1
-       1       3       0       1       4       5       3       3       0       2
-       1       3       3       2       1       3       3       0       1       0
-       1       1       3       3       4       3       0       0       2       1
-       5       1       1       1       3       3       3       2       1       1
-       0       2       3       1       1       1       0       0       0       0
-       1       1       1       0       1       3       0       1       0       2
-       4       0       0       2       1       0       1       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       2       0       4       1       1       2       1       2
-       0       0       1       1       0       1       0       0       0       1
-       0       0       1       0       0       1       0       1       1       1
-       2       2       1       0       1       1       2       0       1       1
-       2       1       0       4       0       0       0       3       2       4
-       0       3       1       0       1       1       0       1       0       0
-       1       1       1       0       2       1       3       0       0       0
-       1       2       1       1       0       2       0       1       1       3
-       2       0       2       1       1       2       1       0       2       2
-       0       0       0       0       2       0       1       1       2       0
-       2       0       0       1       0       0       0       0       0       0
-       1       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       2       1       0       0
-       0       0       2       0       1       1       0       0       3       0
-       1       0       0       1       4       1       0       0       0       2
-       2       1       0       0       1       2       1       0       0       0
-       3       0       0       1       1       0       1       2       1       1
-       0       1       1       2       0       0       2       2       3       3
-       1       0       1       1       2       1       3       4       1       2
-       1       0       2       0       2       1       0       0       0       0
-       3       1       2       3       2       1       2       1       3       1
-       0       1       2       0       0       0       0       3       0       0
-       0       2       0       4       1       0       1       2       0       1
-       2       1       1       1       0       0       0       0       1       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       1       2       2
-       1       1       0       0       0       1       1       0       2       1
-       1       0       3       3       0       1       3       3       1       2
-       2       0       1       1       0       3       0       2       1       0
-       0       0       3       1       1       0       1       0       0       0
-       1       1       1       0       2       0       0       1       1       0
-       0       1       0       3       2       0       1       3       0       1
-       0       1       2       0       1       1       0       3       0       0
-       1       1       1       3       2       0       1       0       0       0
-       1       3       1       1       1       0       1       0       2       1
-       2       0       2       0       0       0       2       1       1       0
-       2       0       1       1       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       1       1       0       1       1       1       0       1       2
-       0       0       0       2       2       2       2       2       0       0
-       2       2       0       0       0       2       3       0       0       2
-       0       0       0       2       0       1       3       0       0       2
-       1       0       3       0       2       1       1       1       0       0
-       0       1       1       0       2       1       1       0       1       3
-       3       0       1       0       0       0       2       4       0       0
-       0       2       1       1       2       2       0       2       0       2
-       2       0       1       0       0       2       2       2       1       1
-       0       0       2       1       1       0       0       0       1       0
-       2       0       0       3       2       0       1       0       2       2
-       0       0       1       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       2       1       0       0       0       1       1       1       0       3
-       0       1       0       2       2       1       0       0       0       2
-       1       1       0       1       1       2       1       2       1       4
-       1       0       1       2       2       2       0       1       1       2
-       5       0       0       0       3       1       2       2       0       1
-       0       1       1       1       2       1       1       0       2       2
-       1       1       1       2       1       0       1       0       2       1
-       2       0       2       2       0       1       0       2       0       0
-       1       3       0       2       2       0       0       0       0       3
-       1       3       2       0       1       1       2       1       0       1
-       3       0       1       2       1       0       0       0       1       0
-       3       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       1
-       1       0       0       0       2       0       0       0       1       0
-       1       1       0       0       0       0       0       1       0       2
-       0       2       2       1       1       0       1       1       1       2
-       0       0       0       2       0       2       1       2       2       0
-       2       3       1       2       0       1       2       1       1       2
-       0       1       0       0       3       0       1       1       3       2
-       1       2       0       1       0       3       1       0       0       0
-       0       0       2       1       0       1       0       0       2       2
-       0       0       1       2       2       2       0       0       1       1
-       1       1       0       0       1       0       1       2       2       2
-       0       1       1       0       0       1       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       1       1       1       2
-       0       0       2       0       0       1       0       4       2       1
-       1       2       1       0       0       0       2       0       0       1
-       3       2       0       0       1       2       1       4       0       1
-       0       4       1       3       2       1       0       1       0       0
-       1       1       1       1       0       0       0       2       6       1
-       0       1       3       0       2       1       0       2       0       2
-       1       0       1       1       0       1       2       2       3       1
-       0       1       1       1       0       1       1       1       0       2
-       1       3       1       0       0       0       3       1       0       0
-       0       1       5       0       0       1       3       2       1       1
-       0       1       2       3       1       0       2       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       2       0       1       0       1       1       1       0       2
-       1       1       0       1       0       0       1       0       2       1
-       2       0       1       1       1       0       0       2       0       1
-       1       0       2       0       0       0       3       2       0       0
-       0       1       1       0       0       0       2       0       0       3
-       2       2       1       0       2       1       0       0       1       0
-       1       1       1       1       2       3       2       1       2       0
-       0       0       0       0       0       0       4       1       1       1
-       2       1       0       0       1       0       1       2       1       0
-       0       0       2       3       1       0       1       2       1       1
-       0       0       1       2       1       2       0       1       1       1
-       2       1       0       1       0       1       0       0       0       0
-       0       0       0       0       0       0       0       1       0       0
-       0       0       0       0       0       0       1       1       3       1
-       0       1       1       3       1       2       0       0       0       1
-       0       1       0       0       3       0       0       1       2       1
-       1       0       1       1       1       0       2       0       0       1
-       0       1       1       0       2       0       0       0       1       2
-       0       1       0       1       1       0       2       1       0       0
-       2       1       2       1       0       1       0       1       1       1
-       1       1       2       1       2       0       0       0       0       2
-       1       0       0       1       2       2       0       0       0       1
-       3       0       0       3       0       0       0       0       0       2
-       0       0       0       1       1       1       1       1       1       1
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       1       0       0       0       0       1
-       0       0       2       1       0       1       1       0       0       0
-       0       1       0       0       1       0       0       1       0       1
-       1       0       0       1       0       0       1       0       1       1
-       0       1       0       2       1       1       1       0       2       1
-       2       2       0       1       1       0       1       1       0       2
-       1       0       4       0       0       1       0       0       1       0
-       0       0       1       0       0       1       0       2       0       0
-       0       2       0       1       2       1       1       2       1       3
-       0       1       1       0       1       1       0       1       3       0
-       0       2       2       0       1       1       0       0       0       0
-       1       0       1       1       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       1       0       0       0       0       0
-       3       1       1       1       1       1       0       1       1       2
-       0       0       0       0       1       0       1       0       2       0
-       1       1       0       2       1       1       0       1       0       1
-       0       0       0       1       0       0       0       1       2       0
-       0       2       2       0       0       1       0       2       2       1
-       1       5       2       0       0       0       1       1       2       3
-       0       1       0       1       0       1       0       1       0       0
-       0       2       2       1       0       0       0       0       0       0
-       0       0       0       1       0       0       2       3       0       1
-       0       0       2       0       0       1       0       1       0       2
-       1       0       0       0       1       0       1       2       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       1       0       0       0       0       1       1       0
-       0       0       1       0       0       0       1       0       0       2
-       2       2       2       1       2       1       0       0       1       1
-       2       1       0       0       0       0       0       0       0       0
-       1       0       0       1       3       1       3       3       0       0
-       0       2       1       0       2       1       1       0       0       1
-       0       1       1       0       0       2       1       1       3       0
-       0       3       2       0       0       0       3       2       1       1
-       1       1       0       0       1       0       1       0       1       1
-       1       1       1       0       0       0       1       0       1       2
-       1       1       1       0       0       3       0       1       2       2
-       1       0       0       1       2       2       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       1       1       0       2       0       0       3       0       3       0
-       2       1       2       2       3       5       2       1       2       3
-       2       1       3       2       1       3       1       2       2       0
-       1       1       0       3       2       0       1       0       1       0
-       1       3       0       2       2       1       1       0       2       1
-       1       1       1       1       0       0       1       1       0       1
-       0       3       0       1       1       0       0       1       2       1
-       0       5       2       0       1       0       3       1       1       2
-       1       1       2       1       1       1       1       3       1       5
-       1       4       1       1       0       2       2       1       2       1
-       2       1       2       0       1       1       1       1       1       2
-       0       0       1       0       0       0       0       0       0       0
-       0       0       0       0       0       2       0       1       1       2
-       0       0       0       0       0       0       1       1       0       3
-       0       3       1       0       1       0       0       0       1       0
-       0       1       0       1       0       0       0       2       0       2
-       1       2       2       0       2       1       1       2       0       1
-       1       3       0       0       3       0       0       2       0       1
-       3       1       0       1       0       2       0       1       2       0
-       2       0       1       2       0       1       0       2       2       1
-       1       1       3       0       0       1       0       1       0       0
-       0       0       0       2       1       0       0       2       2       0
-       1       1       1       0       1       2       0       2       1       0
-       2       0       1       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       1       0       1
-       0       1       1       0       1       1       2       2       1       1
-       3       0       0       3       1       1       2       1       1       2
-       0       1       0       1       0       1       1       1       1       0
-       0       0       1       0       1       1       2       1       0       2
-       0       1       2       3       2       2       0       2       1       2
-       2       2       2       0       0       0       1       0       0       0
-       2       1       0       0       3       2       2       0       1       0
-       1       1       2       2       1       0       0       0       2       1
-       0       1       1       1       0       0       0       1       0       1
-       2       0       0       1       0       0       0       1       0       1
-       0       0       2       1       1       1       0       1       2       1
-       1       0       1       0       0       0       0       0       0       0
-       0       0       0       0       1       0       1       0       0       0
-       2       1       3       0       0       0       1       1       0       2
-       3       1       2       1       1       0       0       1       3       2
-       0       0       1       2       1       1       1       0       0       2
-       2       4       0       2       2       2       1       2       1       3
-       0       1       1       1       2       0       1       0       1       0
-       0       0       0       1       0       2       0       0       1       2
-       1       1       1       2       1       2       0       1       1       0
-       2       0       1       2       1       0       3       0       1       0
-       0       0       2       3       1       1       0       0       2       0
-       0       1       0       2       1       2       2       1       2       0
-       3       1       0       1       0       0       1       1       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       3       3       1       0       2       0
-       1       0       1       3       2       0       0       1       0       0
-       1       1       1       1       0       0       0       1       4       0
-       1       0       3       2       3       1       2       0       2       0
-       0       1       1       0       0       2       1       0       3       0
-       0       0       0       0       1       2       0       1       1       0
-       1       1       1       1       1       1       2       0       0       1
-       1       1       1       1       0       0       1       1       3       1
-       0       0       2       1       1       0       0       1       1       3
-       0       0       0       0       1       0       0       1       0       2
-       0       0       1       1       0       2       1       0       2       1
-       0       0       1       0       1       1       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       2       2       0       1       0       0       0
-       0       0       0       0       0       0       2       1       0       2
-       1       1       1       1       0       0       2       2       1       1
-       2       0       0       1       1       0       2       0       1       0
-       0       1       2       0       0       1       2       1       0       1
-       3       0       1       0       0       1       2       3       2       1
-       2       1       0       1       1       2       0       0       1       1
-       2       0       2       0       1       0       0       0       2       3
-       0       3       1       1       1       0       0       0       0       1
-       0       1       1       1       1       1       0       1       1       0
-       2       0       3       2       2       1       1       3       0       2
-       0       1       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       2       1       0       0       1       1       1
-       3       0       0       0       0       0       0       2       0       3
-       1       0       1       1       0       1       1       0       1       1
-       0       0       0       0       1       0       0       1       0       0
-       0       0       1       1       0       0       2       0       1       2
-       0       1       1       0       1       1       1       1       0       0
-       0       1       0       0       0       1       1       2       1       0
-       0       1       0       1       1       3       0       1       1       0
-       0       1       0       0       1       2       0       1       2       3
-       3       1       1       2       2       3       1       0       1       0
-       1       2       1       0       1       1       1       3       0       0
-       4       1       1       1       1       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       2
-       2       1       3       0       0       1       2       1       1       0
-       1       2       0       1       1       0       1       0       1       0
-       1       2       1       1       2       0       0       0       2       1
-       1       1       1       0       1       0       1       0       0       2
-       2       2       2       0       0       2       1       0       1       1
-       2       0       2       1       0       1       1       0       0       1
-       1       0       1       1       0       1       1       3       1       0
-       0       0       0       0       1       3       0       2       1       2
-       1       2       5       0       2       1       2       1       0       2
-       1       0       1       0       0       0       1       2       1       2
-       2       1       2       1       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       1
-       1       0       1       0       0       0       1       1       0       0
-       3       2       0       0       1       0       3       1       0       1
-       3       2       1       0       0       1       1       0       2       0
-       1       0       2       1       1       2       1       2       3       1
-       0       2       0       2       2       1       0       1       0       2
-       1       1       0       3       0       0       1       0       0       1
-       1       0       1       1       2       0       0       1       0       2
-       0       0       1       1       1       1       1       0       1       0
-       0       0       2       0       2       0       2       2       1       1
-       0       0       1       0       0       0       0       2       0       1
-       2       1       6       1       0       0       1       1       0       0
-       0       1       0       0       0       0       0       0       0       0
-       0       0       0       0       0       1       2       0       2       1
-       1       0       1       1       1       0       0       1       1       2
-       1       3       1       0       0       0       0       1       2       2
-       0       1       0       1       2       1       1       0       2       0
-       0       2       1       2       1       1       1       1       0       0
-       1       3       0       0       0       1       1       1       1       1
-       1       2       1       0       2       0       1       1       1       2
-       1       1       0       2       1       3       1       1       1       1
-       2       2       1       1       0       1       0       2       2       3
-       0       0       1       0       0       2       1       0       2       0
-       0       0       0       1       0       2       1       1       0       0
-       0       0       0       2       1       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       2       1       0       1       2       2
-       0       3       1       2       1       0       1       1       0       2
-       0       6       0       0       0       1       1       2       1       3
-       3       4       1       2       1       0       2       0       2       1
-       3       0       0       2       1       3       1       1       2       0
-       1       1       0       2       0       2       5       1       1       3
-       2       1       2       2       2       1       1       1       1       1
-       0       1       1       2       0       2       2       0       1       0
-       1       0       2       1       0       0       2       1       1       1
-       1       0       0       0       1       0       0       2       1       1
-       1       0       2       0       1       0       1       1       1       0
-       0       0       1       2       0       1       2       0       0       0
-       0       0       0       0       0       0       0       0       2       7
-       8       5       7      11       4       8       8      10       7       8
-      14       9       9       7       4      12       6      12       7      11
-       8      12       8       9       9       7      17      12      10      10
-      11      10       7      12      12       8      11      15      14      19
-       9      13      15      12       8      15      11      13      15      11
-       7      11      14      13      17      14      16      13      12      18
-      13      13      15      11       8      13      14      11      18      10
-      12       9      12      10      17      15      12      18       6      10
-       9       9      11       9      11       8      12       2       9       8
-      12       9       9       8       6       7      10       3      10       4
-       6      10       7       1       2       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       1       0       2       2       0       0       1       2       0
-       2       0       2       1       0       0       1       3       1       1
-       0       1       0       1       2       1       0       0       1       0
-       1       0       3       1       0       0       0       4       0       1
-       2       1       2       2       1       1       1       4       1       1
-       1       1       0       1       0       2       0       2       0       2
-       0       0       1       1       1       1       2       2       1       2
-       1       0       2       1       1       1       0       0       1       0
-       2       1       0       2       3       2       1       1       0       2
-       0       2       0       0       0       1       2       3       1       0
-       2       1       0       3       1       1       0       0       2       1
-       1       0       0       0       0       0       0       0       0       0
-       0       0       0       2       0       1       0       0       0       0
-       1       1       0       1       2       1       0       0       1       0
-       0       1       2       1       1       0       2       1       2       3
-       1       0       1       3       0       2       0       2       1       0
-       1       1       1       1       0       3       0       3       0       2
-       1       0       0       0       0       1       1       2       0       0
-       0       1       3       2       2       0       1       1       2       1
-       1       2       3       0       0       1       1       0       0       0
-       0       0       2       0       0       2       1       1       2       1
-       1       1       2       0       0       2       2       2       1       1
-       2       0       0       0       2       1       1       3       0       1
-       1       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       1       1       2       0       1       1       1
-       1       0       0       0       0       0       1       2       1       0
-       0       1       0       0       1       2       3       3       0       2
-       1       0       1       2       2       0       1       2       3       1
-       0       3       0       0       2       2       0       1       1       1
-       0       1       0       1       1       2       1       0       0       0
-       0       1       1       1       1       0       2       0       1       1
-       0       0       0       0       0       1       0       0       0       0
-       0       1       0       0       2       1       1       1       1       0
-       0       1       2       0       2       1       1       1       4       0
-       0       1       0       1       1       0       0       1       2       2
-       1       2       0       0       1       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       1
-       0       0       0       0       0       0       1       1       0       1
-       0       1       0       0       1       0       0       0       1       2
-       1       0       1       2       1       1       0       0       0       1
-       0       0       1       0       1       2       0       0       0       0
-       0       0       0       1       1       1       1       4       0       0
-       0       1       0       0       0       0       1       0       1       0
-       1       1       0       2       3       2       0       4       1       0
-       0       0       0       0       1       1       1       1       0       0
-       2       1       0       0       1       1       2       0       2       2
-       0       2       0       0       2       1       0       0       0       3
-       0       1       0       1       0       1       0       1       1       1
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       1       0       0       0
-       1       0       2       1       0       1       0       1       2       0
-       0       1       0       4       1       1       1       0       3       1
-       1       2       1       0       0       0       0       2       1       1
-       2       1       1       0       0       2       1       2       1       0
-       1       0       0       2       2       2       1       3       1       2
-       2       0       1       1       1       0       0       0       0       1
-       0       1       2       1       2       2       1       2       2       0
-       1       1       1       1       2       0       1       2       1       0
-       4       1       0       0       1       1       1       0       0       0
-       1       0       0       1       0       0       2       0       2       2
-       1       1       0       0       0       1       0       0       0       1
-       0       0       0       0       0       0       0       0       0       2
-       2       3       1       0       1       0       0       4       0       1
-       1       4       1       1       1       0       0       2       2       3
-       0       1       2       2       3       4       1       1       1       5
-       0       1       1       1       1       4       2       2       2       4
-       3       1       3       1       2       3       7       2       3       1
-       4       4       3       3       2       1       1       1       3       0
-       1       2       1       1       2       7       2       4       3       2
-       3       4       3       2       1       2       5       4       2       4
-       4       3       3       2       5       1       4       3       0       1
-       3       5       4       3       0       1       2       1       1       3
-       0       4       1       1       1       2       1       1       1       2
-       0       1       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       1       1
-       0       1       1       0       2       0       3       2       2       2
-       0       0       0       0       1       0       0       0       0       0
-       3       0       1       0       0       0       1       1       0       0
-       2       1       1       1       0       0       1       0       1       0
-       1       1       1       0       1       1       1       0       1       1
-       2       1       1       0       1       1       0       1       0       1
-       2       0       1       0       0       1       1       3       0       0
-       0       0       0       3       2       0       0       0       0       0
-       0       1       2       0       0       0       0       0       0       1
-       0       0       1       1       2       1       0       3       0       0
-       1       0       0       1       1       1       2       0       1       1
-       1       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       2       2       0       1
-       0       0       0       2       0       0       3       0       0       0
-       1       1       2       1       1       0       1       1       0       1
-       0       0       1       1       2       2       1       1       1       3
-       0       3       1       1       0       1       1       3       0       0
-       0       1       0       0       2       1       0       0       1       0
-       0       1       0       1       0       1       3       1       1       2
-       1       1       1       0       1       1       2       1       0       0
-       0       1       1       0       0       0       0       1       0       0
-       1       1       1       0       1       1       2       1       0       1
-       0       0       3       1       1       0       1       0       3       0
-       1       0       0       0       1       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       1       0       0       1       2       1
-       0       0       1       0       1       0       0       1       2       0
-       1       2       2       0       0       1       3       0       0       1
-       0       1       1       1       2       1       1       1       0       2
-       0       2       4       0       1       1       1       2       0       1
-       1       0       0       1       1       1       2       0       0       3
-       0       3       0       1       1       1       0       0       0       3
-       1       2       0       1       0       2       0       1       3       1
-       0       1       1       2       0       0       1       0       0       0
-       0       4       1       1       2       0       0       1       1       1
-       0       0       1       1       0       0       2       1       2       0
-       0       0       1       1       1       1       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       1       1       0       0       0       0       0
-       2       1       4       0       0       1       1       2       2       0
-       0       1       0       1       0       0       1       1       1       1
-       1       0       0       0       6       1       1       0       0       1
-       2       2       1       2       1       0       0       2       1       2
-       0       2       1       1       0       0       2       0       1       1
-       2       1       2       0       0       2       1       1       1       1
-       0       3       0       0       1       1       0       1       1       0
-       1       0       1       1       2       0       0       1       0       0
-       1       1       3       0       1       1       0       0       1       1
-       1       2       3       1       0       0       1       0       1       1
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       1       0       2       0       3       1       0       2       0       1
-       0       0       0       0       0       0       1       0       0       2
-       0       0       0       0       0       1       2       1       3       1
-       0       2       1       0       0       1       2       0       0       0
-       0       2       0       2       0       1       0       1       1       1
-       0       1       0       2       0       2       0       0       0       2
-       1       1       1       0       0       0       1       1       1       2
-       0       1       0       2       0       0       2       1       1       0
-       2       2       2       0       1       2       1       0       2       1
-       0       0       0       1       0       0       0       1       1       1
-       0       0       0       0       0       1       0       0       2       0
-       1       1       0       0       0       0       0       0       0       0
-       0       0       0       0       0       1       0       0       2       0
-       2       1       2       0       0       1       0       1       0       0
-       0       1       0       2       0       1       1       2       1       2
-       2       2       1       1       0       0       3       0       1       1
-       1       1       0       0       1       0       0       0       0       1
-       3       0       0       2       1       1       2       1       1       0
-       2       0       3       0       1       0       0       1       1       1
-       1       0       0       1       1       1       2       0       0       2
-       1       0       1       2       1       0       2       4       0       0
-       0       0       1       0       3       1       1       0       2       0
-       1       0       0       1       3       0       0       2       1       3
-       0       1       0       0       0       0       1       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       3
-       2       2       2       4       7       3       1       0       2       6
-       4       5       4       5       4       4       3       8       2       2
-       4       2       0       3       4       3       2       2       1       4
-       2       1       1       5       3       3       0       3       1       5
-       1       1       3       4       0       1       1       1       0       4
-       3       3       1       2       3       1       4       4       1       4
-       4       1       2       2       2       1       2       3       3       2
-       1       2       3       3       2       2       4       3       0       3
-       1       0       1       0       2       4       4       3       2       1
-       2       3       2       3       2       3       0       3       3       4
-       3       5       2       5       1       4       4       2       1       2
-       0       0       0       0       0       0       0       0       0       0
-       0       0       1       0       1       1       0       0       0       2
-       0       0       0       0       1       1       2       0       2       1
-       1       0       3       0       0       1       0       1       0       0
-       0       1       1       1       1       1       0       4       2       0
-       2       0       0       0       2       1       0       0       3       3
-       0       1       0       1       0       3       0       0       0       1
-       3       1       0       0       1       1       0       0       0       1
-       0       0       0       1       0       1       0       1       1       2
-       1       0       2       3       0       1       0       0       0       1
-       2       1       1       1       0       0       0       1       1       0
-       0       1       1       1       0       0       0       0       0       1
-       0       0       0       1       1       1       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       1       0       0       1       0       1       1       1       0
-       0       0       1       2       0       3       0       1       0       1
-       1       1       0       1       1       2       0       0       1       1
-       0       4       2       2       1       3       2       0       3       1
-       1       1       1       1       0       0       1       0       0       0
-       1       0       0       0       3       0       3       0       0       0
-       0       0       1       1       2       1       0       1       1       1
-       1       1       0       1       0       1       0       2       0       0
-       1       1       1       1       2       2       0       2       0       2
-       3       2       0       1       1       1       3       0       2       1
-       1       1       0       2       1       1       1       1       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       1       0       1
-       0       2       1       1       0       0       1       2       1       1
-       0       2       1       0       0       0       1       0       2       0
-       1       0       0       0       0       0       0       0       2       0
-       1       1       0       0       0       1       1       2       2       0
-       1       0       0       0       0       2       1       0       0       0
-       1       0       0       1       1       0       0       2       1       1
-       1       1       0       0       0       1       0       2       0       0
-       0       2       2       1       0       1       0       1       0       2
-       1       1       0       1       0       0       0       0       0       0
-       1       0       0       2       0       0       1       0       0       0
-       3       0       0       1       1       0       1       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       1
-       0       2       0       3       2       0       1       0       2       0
-       1       0       1       0       1       1       0       0       0       2
-       1       2       0       0       1       0       2       0       1       3
-       0       0       2       0       0       0       0       0       0       1
-       1       0       0       1       1       0       0       1       1       1
-       0       1       0       0       0       0       2       1       0       0
-       1       0       1       0       1       0       0       0       1       2
-       2       0       1       0       0       0       0       0       1       1
-       4       0       1       2       0       0       0       0       0       1
-       0       0       1       0       1       0       0       2       1       0
-       1       2       0       0       2       1       2       1       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       2       3       1       1       0       0       1       0
-       1       0       1       2       0       1       0       1       0       1
-       3       1       1       1       1       0       1       0       0       1
-       3       0       1       0       1       1       2       0       2       1
-       3       1       2       0       1       0       0       0       1       0
-       2       1       1       0       2       1       2       3       2       0
-       2       0       2       0       0       1       3       3       3       1
-       2       1       0       1       0       1       0       0       0       0
-       1       1       0       1       1       0       0       4       1       1
-       1       1       2       2       1       2       0       0       3       2
-       0       0       0       2       2       1       0       2       2       1
-       1       0       1       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       1       0       0       1       0       0
-       0       1       0       0       0       0       0       0       1       1
-       0       1       0       0       0       0       2       1       2       0
-       1       2       0       0       1       1       2       0       3       0
-       1       0       1       1       0       1       0       2       1       2
-       0       0       0       0       1       2       2       0       1       2
-       1       1       1       0       4       0       2       0       2       1
-       1       0       0       2       2       1       0       0       0       1
-       1       0       0       1       1       0       1       1       0       0
-       1       0       1       1       1       0       3       0       0       0
-       1       0       0       0       0       0       0       1       1       0
-       1       0       1       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       2
-       1       3       3       2       1       1       1       0       2       2
-       1       2       3       5       5       1       1       0       2       1
-       3       3       2       0       2       1       1       3       0       0
-       1       0       1       1       1       2       3       3       2       0
-       1       3       1       3       4       1       3       1       3       2
-       3       2       2       0       3       1       2       3       4       1
-       2       2       3       2       3       1       2       1       2       1
-       1       2       3       1       1       2       0       1       3       1
-       4       2       1       2       1       3       3       2       1       1
-       5       1       2       0       2       1       1       1       5       2
-       1       3       2       2       3       3       0       0       1       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       2       1       0       0       0       1       0       0       1       1
-       0       2       0       1       2       2       1       1       1       0
-       1       0       1       3       0       0       2       2       2       0
-       1       0       0       0       0       1       0       0       0       1
-       1       0       0       1       0       0       1       0       2       1
-       2       1       2       2       1       0       1       1       2       1
-       1       0       0       1       0       2       0       2       0       0
-       1       0       0       1       0       0       1       0       3       2
-       2       1       3       0       0       1       0       1       0       0
-       1       1       0       2       1       0       1       0       2       0
-       0       2       0       0       0       0       0       1       1       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       1       0       0       0       0       1
-       3       0       0       0       0       0       0       0       3       0
-       0       0       3       0       2       0       0       1       1       0
-       0       1       1       1       0       1       1       0       0       1
-       2       3       0       1       0       1       1       1       1       2
-       1       1       1       0       1       1       1       2       0       0
-       0       2       0       3       0       1       1       0       2       2
-       1       0       2       0       2       0       1       2       0       0
-       2       0       0       1       0       1       0       0       0       0
-       1       0       0       1       2       1       0       0       0       0
-       4       3       2       0       1       1       1       1       0       0
-       1       2       1       2       0       0       0       1       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       1       0       0
-       0       0       2       2       0       0       1       0       0       1
-       2       1       0       0       0       0       1       0       0       0
-       0       0       0       0       1       1       3       0       0       0
-       0       0       0       0       0       1       1       1       1       1
-       0       0       0       1       0       1       0       3       0       0
-       0       1       0       0       2       2       1       0       3       2
-       2       3       3       1       4       0       0       1       0       4
-       0       0       1       2       1       0       1       0       1       1
-       0       0       1       2       0       1       0       1       0       0
-       0       1       0       0       1       0       2       1       0       1
-       0       0       0       2       3       0       2       3       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       1       1       0       0       1
-       0       2       1       0       0       1       0       1       3       1
-       1       1       0       1       0       1       2       2       1       0
-       0       1       0       1       0       1       1       0       0       0
-       1       1       0       1       1       0       0       0       1       1
-       1       1       2       1       0       0       0       2       2       2
-       0       2       0       2       0       1       2       0       1       1
-       2       0       1       1       2       1       0       0       0       3
-       2       0       1       1       1       0       2       1       0       0
-       1       0       0       1       0       1       0       1       2       0
-       1       0       0       3       2       1       1       1       0       0
-       0       1       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       1       0       0       0       0       1       1
-       2       0       1       1       0       1       1       0       0       0
-       1       0       0       1       0       1       1       0       0       0
-       1       2       0       1       0       2       1       1       2       1
-       1       0       0       2       0       1       0       1       0       0
-       0       1       0       0       0       0       0       0       0       0
-       0       1       0       1       0       0       1       2       1       1
-       0       1       1       2       0       0       0       1       0       1
-       0       2       1       0       0       0       0       1       0       0
-       0       1       2       2       2       2       2       0       3       1
-       1       0       0       0       0       2       0       0       0       0
-       0       1       1       2       0       0       0       0       0       0
-       0       0       0       0       0       0       0       1       2       0
-       0       1       0       0       0       0       0       1       2       0
-       0       0       1       1       0       3       2       0       0       1
-       1       0       0       1       1       1       2       1       1       0
-       1       0       0       1       1       0       0       1       0       0
-       0       1       0       1       0       1       2       0       1       1
-       0       1       0       0       0       1       1       1       0       0
-       2       1       0       0       0       0       2       2       0       0
-       0       1       2       1       2       0       0       0       0       0
-       1       0       0       4       0       0       0       1       1       0
-       2       0       2       0       2       2       0       0       1       1
-       0       2       1       0       1       0       1       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       1
-       2       0       1       1       0       1       3       0       0       1
-       1       2       0       0       0       1       2       1       0       0
-       0       0       0       0       1       2       0       1       2       0
-       2       0       0       1       0       0       0       1       0       0
-       1       1       1       4       0       2       0       0       1       1
-       2       0       1       0       0       0       2       0       0       0
-       1       0       1       1       3       1       1       1       1       0
-       0       2       0       0       0       0       1       0       1       1
-       1       0       2       0       0       0       0       1       1       2
-       1       1       1       1       0       1       2       1       0       2
-       0       1       2       1       0       0       2       0       0       1
-       0       0       1       0       0       0       0       0       0       0
-       0       0       0       0       0       1       0       0       3       2
-       3       0       0       2       2       2       1       2       2       1
-       3       3       0       1       1       4       1       2       4       3
-       2       1       2       4       3       4       2       3       2       5
-       7       5       1       1       2       2       4       4       1       5
-       3       3       1       0       2       2       8       1       3       5
-       1       1       1       2       4       0       3       1       1       1
-       3       0       3       2       2       1       1       1       3       3
-       2       2       2       2       4       2       1       3       2       1
-       0       2       2       1       1       1       2       2       1       2
-       2       6       2       2       0       2       0       1       1       0
-       0       1       1       2       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       1       1       0       0       0       0       3
-       1       0       0       0       2       1       1       1       5       0
-       1       1       1       2       1       0       0       2       1       1
-       1       0       0       1       0       1       0       1       1       1
-       0       4       0       0       1       0       0       0       1       1
-       0       1       0       0       0       0       1       1       0       0
-       0       0       1       1       0       3       0       0       1       1
-       3       1       1       2       0       2       0       2       2       2
-       0       1       0       0       0       1       3       1       0       1
-       0       1       0       0       3       0       2       0       0       2
-       2       0       3       1       0       1       0       1       1       0
-       1       0       1       1       0       0       0       0       0       0
-       0       0       0       0       0       0       1       0       0       0
-       0       0       0       0       0       2       0       2       1       1
-       2       1       2       0       0       1       1       0       0       2
-       1       1       0       1       1       2       1       0       0       0
-       2       2       0       1       0       1       3       2       1       2
-       2       1       2       0       2       0       1       3       0       1
-       1       1       0       1       2       4       0       0       2       1
-       2       0       1       1       0       1       0       1       1       1
-       1       0       1       3       0       2       0       1       2       1
-       0       1       1       2       0       0       1       0       2       1
-       0       3       1       4       0       2       0       0       0       0
-       1       0       1       0       0       0       0       0       1       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       1       2       3       0       0       1       1
-       3       4       3       1       0       1       1       0       1       2
-       2       1       1       1       1       2       2       1       0       1
-       0       2       0       0       1       1       2       2       1       3
-       3       0       0       0       1       0       3       2       0       2
-       0       0       1       0       0       0       0       2       3       1
-       1       3       1       0       1       1       0       1       1       0
-       1       1       0       3       3       0       0       1       1       0
-       0       2       1       1       0       1       2       1       0       1
-       0       0       2       1       1       1       0       2       3       0
-       4       0       1       2       0       0       0       1       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       1       0       1       0       0
-       0       0       2       0       1       1       0       1       3       1
-       2       1       0       1       1       1       0       0       0       2
-       1       0       2       1       1       3       2       1       1       3
-       1       1       2       1       4       2       2       1       1       2
-       2       1       2       1       0       0       2       2       2       0
-       2       3       5       0       1       1       2       0       2       1
-       2       1       2       0       0       1       0       1       1       2
-       1       2       1       0       0       1       2       0       3       1
-       1       1       2       1       2       1       0       0       3       2
-       2       1       0       5       0       3       1       1       2       1
-       4       0       1       0       2       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       1       0       2       0
-       1       1       2       1       0       3       1       0       1       1
-       0       1       0       0       0       0       0       1       4       1
-       1       0       1       3       0       1       2       1       1       0
-       2       1       0       0       4       3       2       1       1       1
-       2       1       0       2       0       0       0       2       0       2
-       1       0       1       1       2       1       0       0       0       1
-       1       1       1       2       1       2       3       2       2       1
-       0       3       0       2       1       1       2       1       0       1
-       1       0       0       2       4       2       1       1       0       1
-       2       0       0       3       0       1       2       0       0       1
-       0       3       0       2       2       1       1       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       2       0       0       0       2       1       0       1
-       1       1       0       0       2       1       1       1       2       0
-       0       0       1       1       0       0       1       0       3       0
-       2       0       0       0       1       1       0       0       0       2
-       0       1       1       0       0       0       0       0       0       1
-       2       3       2       0       1       1       2       0       1       2
-       0       0       0       2       1       0       0       0       0       1
-       0       3       1       0       0       0       2       1       4       0
-       0       1       2       3       1       1       2       0       0       0
-       1       1       0       0       0       0       0       2       0       0
-       0       2       0       0       1       1       1       2       1       0
-       1       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       2       0       1
-       0       1       1       3       0       0       1       0       1       0
-       1       2       2       2       1       2       0       1       2       0
-       0       1       1       3       2       1       0       1       2       2
-       1       1       0       0       0       1       0       2       1       3
-       0       1       2       3       1       1       1       3       0       0
-       2       1       1       2       0       2       0       3       0       1
-       2       3       4       1       1       1       2       0       2       1
-       3       0       1       1       0       0       1       3       0       0
-       2       3       1       0       0       2       2       0       0       3
-       0       0       0       1       2       3       1       0       1       0
-       3       3       3       2       2       1       0       0       1       1
-       0       0       0       0       0       0       0       0       0       1
-       0       1       0       0       0       1       0       0       0       3
-       0       0       0       1       1       2       1       1       1       0
-       0       0       1       0       1       1       0       1       0       0
-       1       1       1       0       1       4       1       0       0       2
-       0       2       0       0       2       1       0       1       1       1
-       0       0       2       1       0       0       0       2       0       1
-       0       3       0       0       1       0       1       0       2       1
-       3       1       1       0       3       3       1       1       1       1
-       1       0       0       1       0       0       0       1       3       1
-       0       2       2       2       1       1       2       2       1       0
-       2       1       0       1       0       0       0       0       0       0
-       0       1       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       1       1       0       3
-       0       0       0       0       3       1       3       0       0       0
-       1       2       1       1       1       1       3       3       1       0
-       0       0       1       2       0       0       0       0       1       2
-       4       1       1       1       0       4       1       1       0       0
-       1       0       0       2       0       0       2       3       0       1
-       0       2       3       3       2       2       2       3       0       1
-       1       1       0       0       1       0       0       0       0       1
-       2       1       0       1       3       0       1       0       0       1
-       1       0       0       2       0       0       0       1       0       0
-       0       1       1       2       1       3       1       0       0       2
-       1       1       1       1       2       2       1       0       1       0
-       0       0       0       0       0       0       0       0       0       0
-       1       0       0       0       1       1       2       0       0       1
-       0       0       0       1       1       1       5       1       1       1
-       0       2       2       1       0       0       1       0       1       1
-       2       0       0       4       2       1       1       1       0       0
-       2       0       1       0       1       1       0       2       3       2
-       1       0       0       1       0       0       1       0       1       0
-       0       1       0       0       1       2       0       2       1       0
-       3       0       0       1       1       2       1       0       0       0
-       0       1       0       0       1       0       0       1       1       0
-       0       0       1       1       1       2       3       3       0       2
-       0       1       2       4       0       2       1       0       0       1
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       1       0       1       1       0
-       2       0       1       2       3       1       0       1       0       0
-       1       0       0       0       1       3       3       2       1       0
-       0       1       2       0       0       1       1       1       2       0
-       0       0       1       0       1       0       0       0       1       0
-       0       1       0       0       2       1       1       0       1       0
-       0       2       0       0       1       1       1       1       2       1
-       2       0       1       0       0       0       0       2       1       0
-       0       2       1       0       0       0       1       0       3       2
-       0       0       1       0       0       0       1       2       0       3
-       1       2       0       1       0       0       3       1       1       1
-       0       1       1       0       1       0       2       0       0       0
-       0       0       0       0       0       0       0       0       1       0
-       0       0       1       1       0       1       0       0       1       0
-       0       1       1       0       1       1       0       0       0       2
-       0       0       1       1       1       1       0       0       1       0
-       1       1       2       0       2       2       0       4       2       3
-       0       0       0       0       0       0       1       2       0       2
-       1       0       0       1       0       2       1       3       2       1
-       1       1       0       0       3       0       2       1       1       1
-       0       0       1       1       0       1       0       0       0       0
-       1       0       0       2       3       1       0       1       0       1
-       1       0       0       1       0       0       2       0       2       0
-       0       2       0       1       0       0       1       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       1       0       2       0       1       0       1       0       1       3
-       3       2       2       2       1       0       0       0       1       3
-       1       2       1       0       1       0       1       0       1       2
-       1       2       2       0       0       0       1       0       1       2
-       1       0       0       1       0       0       2       2       1       0
-       0       2       0       3       2       0       1       1       1       0
-       1       1       0       1       0       1       1       0       0       1
-       0       2       0       2       0       1       2       2       2       1
-       0       0       0       1       1       1       0       0       0       0
-       1       1       1       0       1       1       1       0       1       0
-       1       1       0       0       1       2       1       0       1       0
-       2       1       0       0       0       0       0       0       0       0
-       0       0       1       0       2       1       1       0       1       1
-       0       0       1       1       2       2       1       0       0       1
-       0       1       1       2       0       1       0       1       1       0
-       0       0       0       0       0       0       1       0       0       1
-       2       0       1       2       2       0       2       1       2       1
-       2       0       3       1       0       1       1       0       0       1
-       2       1       0       3       0       2       1       1       1       3
-       2       1       2       1       0       1       1       2       0       1
-       2       0       0       0       0       1       3       0       0       0
-       1       1       0       1       0       3       1       1       0       2
-       1       1       3       1       0       2       3       2       2       0
-       2       0       1       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       1       2       0       0       0
-       2       1       0       0       1       0       2       0       0       1
-       1       1       0       1       2       2       2       0       0       0
-       1       0       0       0       0       2       0       1       2       1
-       1       1       1       1       1       0       0       1       0       0
-       0       2       0       1       2       1       0       0       2       1
-       1       2       0       1       0       0       1       0       2       1
-       1       1       0       0       3       0       1       2       1       1
-       2       0       0       0       1       0       2       0       0       2
-       0       0       3       2       0       0       1       0       0       1
-       1       4       0       1       1       2       0       2       4       1
-       0       0       0       0       2       0       0       0       0       0
-       0       0       0       0       0       0       0       0       1       0
-       2       0       2       1       1       1       0       1       0       3
-       1       1       0       2       2       0       0       0       0       1
-       1       2       0       1       0       1       1       0       2       1
-       1       3       0       1       0       2       2       2       1       2
-       0       2       2       2       0       0       0       0       2       4
-       2       2       0       1       0       0       0       3       0       0
-       1       0       1       1       2       1       1       1       0       2
-       1       1       1       1       1       2       0       1       0       2
-       1       1       0       3       1       2       0       3       0       1
-       1       1       1       1       1       1       2       0       1       2
-       1       0       1       1       1       1       4       1       1       1
-       2       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       2
-       1       2       1       1       1       1       1       0       0       1
-       3       1       2       1       1       0       0       0       1       3
-       3       1       0       1       2       0       1       2       0       3
-       2       1       0       1       0       1       0       1       0       0
-       2       1       2       0       1       1       1       0       1       3
-       0       1       2       0       1       0       0       0       1       1
-       0       0       3       1       0       0       2       0       1       3
-       0       1       0       1       0       2       2       0       2       2
-       2       0       2       0       0       0       0       1       0       2
-       2       2       0       0       2       1       1       1       1       1
-       0       2       1       2       0       2       1       0       1       0
-       0       0       0       0       0       0       0       0       1       1
-       0       0       2       0       0       1       0       0       0       1
-       0       2       0       1       2       0       3       0       1       2
-       0       0       3       0       2       1       0       1       0       2
-       0       3       0       3       0       2       0       0       0       1
-       1       1       0       0       0       1       1       2       0       2
-       0       2       0       0       0       1       0       2       0       1
-       0       0       0       2       1       0       1       1       1       2
-       0       0       0       2       0       0       1       1       0       4
-       1       0       0       2       1       1       2       1       1       0
-       1       2       0       1       0       0       2       0       1       0
-       2       0       1       0       2       1       0       1       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       2       0       1       0
-       0       1       1       1       3       0       2       1       2       0
-       1       0       0       3       1       1       1       0       1       0
-       0       1       0       1       0       0       4       1       1       0
-       0       3       1       0       2       1       0       0       1       1
-       0       1       1       2       1       2       1       0       1       1
-       0       1       1       2       1       2       0       0       0       2
-       2       0       1       0       1       1       1       1       0       0
-       1       0       0       0       0       0       2       2       2       2
-       0       3       1       0       2       1       0       1       2       1
-       1       1       1       1       2       1       1       1       1       3
-       1       1       0       1       1       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       2       1       1       2       1       2       0       0       0
-       0       0       0       0       1       0       1       2       1       0
-       3       0       1       2       1       1       0       2       1       0
-       0       2       2       1       1       1       1       2       0       1
-       2       0       0       1       0       0       0       0       2       1
-       1       0       1       1       1       2       0       1       0       1
-       1       0       0       2       0       2       0       0       0       1
-       0       1       1       1       1       0       0       1       0       0
-       1       3       3       2       0       1       2       2       0       0
-       2       3       1       0       2       0       2       2       2       1
-       1       1       1       2       3       1       1       0       0       1
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       1       2       1       1       0
-       1       0       0       2       1       1       0       0       2       1
-       2       1       0       1       3       0       0       1       1       0
-       3       2       0       1       1       2       0       2       2       1
-       3       1       0       1       0       2       1       1       2       2
-       0       1       0       1       1       0       0       0       0       1
-       2       1       0       5       0       0       1       2       2       0
-       1       0       1       2       2       0       1       2       2       0
-       1       0       0       0       0       0       0       4       1       1
-       0       1       3       0       1       1       2       1       0       1
-       1       0       2       0       1       0       1       1       0       2
-       1       2       0       0       1       0       0       0       0       0
-       0       0       0       0       0       0       0       1       1       2
-       1       1       2       0       0       0       1       1       1       0
-       0       1       0       1       0       0       0       0       1       0
-       0       1       0       3       3       2       0       1       2       0
-       1       0       0       0       1       2       0       0       0       1
-       0       0       1       1       2       1       0       1       2       0
-       1       0       1       1       0       0       0       0       1       0
-       3       1       0       0       1       0       1       2       0       1
-       1       0       1       1       0       2       3       1       1       1
-       1       0       1       1       1       0       0       1       0       1
-       1       0       2       1       2       1       0       2       3       0
-       0       0       1       0       0       1       0       0       1       1
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       1       0       1       0       1       0
-       0       1       0       1       1       0       3       1       2       1
-       0       3       2       1       2       0       0       3       1       3
-       0       3       0       0       0       0       1       1       0       2
-       0       1       0       1       2       0       1       0       2       2
-       1       2       1       1       2       2       1       1       1       1
-       1       3       1       1       1       1       1       0       0       3
-       3       3       2       2       0       1       2       2       2       0
-       3       1       1       4       2       0       1       2       0       2
-       0       0       0       2       3       1       2       0       2       2
-       2       0       1       1       0       2       2       2       0       1
-       1       2       0       1       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       1
-       0       2       0       1       1       1       1       1       0       0
-       0       0       0       1       0       2       0       0       1       0
-       1       1       4       3       2       1       0       0       1       1
-       0       2       0       1       2       0       0       1       1       2
-       1       1       0       0       1       1       1       0       0       1
-       0       3       1       0       2       0       0       2       1       1
-       0       0       0       2       1       0       2       1       0       1
-       0       0       0       0       3       0       1       1       0       0
-       0       3       1       1       0       1       1       0       1       0
-       1       1       0       0       0       2       0       2       2       1
-       3       0       0       0       1       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       2       1       1       2       0       1       1       2       3
-       0       1       0       0       1       1       1       1       3       0
-       1       4       1       1       0       2       1       1       1       1
-       0       4       3       1       1       1       0       1       1       1
-       1       0       0       1       0       0       2       1       0       3
-       1       1       0       0       2       0       1       1       2       1
-       1       3       0       1       1       0       0       1       0       3
-       2       2       3       0       2       1       1       0       1       0
-       1       0       1       0       0       2       1       1       1       0
-       2       1       0       0       0       1       0       1       1       1
-       1       0       1       1       2       0       0       1       1       0
-       0       2       0       0       0       0       0       0       0       0
-       0       0       0       0       0       1       1       3       1       1
-       0       2       0       0       0       0       1       1       0       1
-       2       1       2       2       0       2       2       1       0       2
-       1       0       1       0       0       0       0       0       0       0
-       0       0       3       0       0       1       1       0       1       1
-       1       0       3       2       1       1       0       1       1       1
-       1       2       1       0       1       1       2       1       0       2
-       1       1       0       1       0       2       0       1       0       2
-       1       2       2       2       0       0       2       1       1       1
-       0       1       0       0       1       0       0       0       0       0
-       0       2       1       2       0       0       1       1       1       1
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       1       0       0       2       2       0       1
-       3       0       1       0       1       2       2       4       2       1
-       3       0       3       1       1       5       1       2       1       4
-       3       1       3       0       3       1       2       2       3       1
-       1       2       2       3       3       0       4       1       3       4
-       0       0       0       2       1       0       3       0       0       2
-       5       4       3       3       4       2       0       1       3       2
-       3       1       2       2       1       1       0       5       0       0
-       2       1       0       0       2       2       0       0       2       2
-       2       2       1       0       1       1       3       3       1       1
-       1       1       2       2       0       2       1       1       1       0
-       0       1       1       1       0       1       0       0       0       0
-       0       0       0       0       0       0       0       0       1       4
-       3       1       0       1       3       1       0       1       0       1
-       0       1       1       2       3       1       2       0       1       1
-       0       0       1       0       2       2       1       0       2       0
-       2       2       1       0       0       0       1       3       0       1
-       2       0       1       0       2       1       1       3       0       1
-       1       3       4       1       1       0       0       2       0       1
-       1       1       1       1       0       0       0       2       1       0
-       1       3       4       1       1       1       3       2       0       1
-       0       0       3       0       1       1       2       2       1       1
-       2       0       1       0       0       2       1       3       4       1
-       2       2       1       3       0       1       1       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       3       0
-       4       3       1       1       2       0       0       0       0       0
-       2       0       0       0       0       0       0       3       2       2
-       1       3       2       2       1       0       3       0       0       0
-       2       0       0       0       1       1       0       1       4       2
-       3       4       2       0       0       0       0       2       0       0
-       1       0       0       1       3       1       0       1       2       3
-       1       2       1       0       1       1       0       3       0       1
-       1       2       2       2       0       0       1       4       2       1
-       0       3       0       0       2       0       1       0       1       0
-       0       0       0       3       1       1       2       1       4       0
-       0       0       1       0       0       0       1       2       0       0
-       0       0       0       1       1       0       0       0       0       1
-       1       2       2       0       0       1       1       0       0       2
-       1       1       1       1       1       0       0       1       2       3
-       1       0       1       0       0       2       4       2       2       1
-       0       2       3       0       4       1       2       2       1       1
-       1       2       1       0       0       2       1       1       2       0
-       1       2       0       3       2       0       2       3       5       0
-       0       0       1       0       0       3       1       2       1       2
-       0       1       2       1       3       2       2       1       1       1
-       1       0       2       1       2       0       0       1       2       0
-       2       2       0       0       1       1       1       1       1       0
-       0       0       0       0       0       1       0       1       0       0
-       0       0       0       1                                                
-SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS
-       4      21      25  123944       0       1                                
-FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
-       6       1                                                                
-            time         monitor       Total Cou     angles*1000                
-  0.35682000E+05  0.30000000E+06  0.15950000E+05  0.15265200E+06  0.40200000E+03
-  0.50810000E+05                                                                
-IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
-   16384                                                                        
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       1       0       2       1       0       0
-       2       1       0       0       0       0       1       0       1       0
-       0       1       0       1       0       0       2       1       0       0
-       0       1       1       0       0       0       0       1       1       0
-       1       0       0       0       1       0       0       1       1       0
-       0       2       0       0       0       1       0       0       2       0
-       0       0       0       1       0       2       2       0       1       1
-       0       0       0       1       0       0       2       1       0       0
-       1       0       1       0       0       0       0       0       0       1
-       1       1       1       0       1       2       1       0       0       0
-       1       0       1       1       0       1       0       0       0       0
-       0       1       0       1       0       0       0       1       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       2       0       1       0
-       0       0       0       1       1       1       0       2       0       2
-       1       0       0       0       1       0       0       0       0       0
-       0       0       0       0       2       0       1       0       1       0
-       0       0       0       0       1       1       0       0       0       3
-       0       2       0       1       0       0       2       0       0       2
-       0       1       1       0       1       1       3       3       0       0
-       1       2       0       0       0       1       0       0       0       1
-       0       1       2       1       0       1       0       0       1       0
-       1       1       0       0       0       2       0       0       1       0
-       0       0       0       1       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       1       0       1
-       0       1       1       2       1       0       1       1       0       0
-       0       1       0       1       1       0       0       2       1       0
-       0       1       1       0       1       1       0       0       0       1
-       1       0       1       0       0       1       0       0       0       0
-       1       1       2       1       0       0       0       1       2       0
-       0       0       0       1       0       0       0       2       1       0
-       0       1       1       0       0       2       0       1       0       2
-       1       1       1       2       0       0       0       0       1       0
-       0       0       1       0       0       0       1       0       1       2
-       2       1       2       1       1       0       1       1       3       1
-       2       0       1       1       0       1       1       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       1       2       0       3
-       0       0       1       0       1       0       0       0       0       2
-       0       0       1       0       1       0       0       0       1       1
-       1       0       0       0       0       0       1       0       0       2
-       0       0       0       1       1       0       1       0       1       1
-       0       2       0       1       1       0       2       0       0       1
-       1       0       0       0       0       0       1       0       0       0
-       0       0       0       0       0       0       1       1       0       0
-       2       0       0       1       0       1       1       1       0       0
-       0       0       2       0       0       0       1       0       2       1
-       2       1       0       0       0       0       1       0       0       0
-       0       0       1       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       2
-       0       0       1       1       1       0       0       1       0       0
-       2       0       0       0       2       1       1       1       1       1
-       1       1       2       1       1       0       1       1       1       3
-       0       1       2       0       1       1       0       0       1       3
-       0       0       1       0       0       3       0       2       0       1
-       0       0       0       1       1       1       2       1       1       1
-       0       0       0       1       0       0       1       1       0       0
-       2       0       1       0       0       1       0       0       1       0
-       1       3       0       1       0       0       3       1       2       1
-       1       1       1       1       2       1       2       2       2       0
-       0       0       3       0       1       1       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       1       0       0       0       1       0       1       0       1
-       1       0       0       0       2       0       0       1       1       2
-       3       3       2       1       1       0       0       1       0       3
-       0       2       1       2       0       2       0       0       1       0
-       0       0       1       1       1       1       0       0       0       0
-       0       1       1       0       0       1       0       2       0       1
-       1       0       1       0       0       3       0       2       4       0
-       1       0       1       1       1       1       1       1       1       0
-       1       1       0       0       2       0       0       0       2       1
-       2       1       0       0       0       0       3       1       1       1
-       0       3       0       1       0       1       0       0       0       0
-       0       1       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       2       0       1       1       2       2       2       2       1       6
-       1       3       2       1       4       4       2       1       2       0
-       4       4       2       3       3       4       7       3       7       6
-       3       5       6       4       3       4       6       6       5       3
-       5       1       6       5       6       5       5       3       5       3
-       6       4       1       6       2       5       8       3       4       2
-       4       3       4       7       3       6       2       4       8       3
-       4       4       5       4       2       4       2       3       3       1
-       5       3       4       6       6       4       3       2       5       2
-       4       5       4       1       1       3       3       3       1       1
-       0       1       0       0       0       1       1       1       0       1
-       0       0       0       0       0       0       0       0       1       0
-       0       0       2       3       3       0       2       2       4       1
-       1       0       2       0       1       4       1       1       0       4
-       2       0       1       4       5       0       4       2       4       4
-       4       3       4       4       1       5       5       3       2       2
-       4       3       2       2       2       4       1       2       2       5
-       3       4       3       1       1       7       6       3       3       3
-       2       3       3       2       0       2       2       2       2       7
-       1       1       2       1       4       1       5       2       1       4
-       4       6       3       0       2       4       2       0       1       3
-       2       4       6       5       1       2       4       4       3       1
-       2       2       1       2       1       2       4       1       0       1
-       2       1       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       1       1       5       4
-       1       4       3       4       7       0       3       6       5       1
-       3       4       3       2       3       4       3       4       1       5
-       3       1       5       3       3       1       2       5       0       3
-       2       6       1       4       2       3       4       3       4       9
-       4       6       2       1       2       6       4       6       2       2
-       2       7       4       1       2       4       1       1       4       4
-       1       1       1       4       3       2       2       3       0       4
-       2       4       5       2       3       1       1       2       2       2
-       4       5       5       2       1       1       1       4       1       3
-       3       1       1       3       1       2       2       4       2       5
-       1       1       0       2       0       0       0       0       0       0
-       0       0       0       1       2       1       2       0       0       2
-       4       3       0       2       2       3       2       2       2       1
-       3       3       4       5       6       0       1       0       1       2
-       3       1       4       3       3       2       5       2       2       3
-       1       2       1       5       4       1       3       4       0       2
-       2       1       4       3       1       0       5       0       0       2
-       1       2       5       2       2       1       4       2       2       1
-       2       0       1       2       2       4       1       1       0       0
-       2       3       2       2       2       3       0       2       3       3
-       1       5       5       2       3       6       3       1       2       3
-       2       3       1       4       5       0       3       0       1       1
-       3       3       1       0       2       1       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       1       3       3       0
-       0       1       2       4       2       1       1       1       4       1
-       3       1       1       0       1       2       3       4       1       1
-       0       2       1       1       1       2       3       0       2       1
-       1       3       2       2       3       4       0       2       8       2
-       2       2       0       2       1       1       0       4       0       1
-       2       1       0       1       6       3       1       0       1       1
-       3       3       5       3       3       3       1       1       2       0
-       2       0       0       0       1       2       4       1       4       1
-       5       2       2       3       3       0       2       0       1       0
-       0       1       0       0       1       2       2       0       1       1
-       1       1       0       0       0       0       0       0       0       0
-       0       0       0       0       0       1       1       0       1       3
-       3       3       1       2       2       4       1       2       2       0
-       0       0       0       1       3       2       1       3       0       2
-       0       5       3       0       2       3       2       2       2       0
-       2       0       0       1       2       0       1       2       1       1
-       1       1       1       2       3       1       1       2       4       1
-       0       0       3       2       2       2       4       1       0       1
-       1       2       3       0       1       0       1       3       0       1
-       3       1       2       0       3       6       3       1       2       1
-       1       2       1       1       1       1       2       1       4       0
-       0       2       1       2       1       1       4       4       0       2
-       3       2       1       0       2       1       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       1       0       2       1       3       2       2       1       1       2
-       3       4       1       2       2       2       2       0       0       2
-       1       0       3       0       2       3       1       1       1       2
-       0       1       1       1       2       1       1       5       0       4
-       1       0       4       1       2       5       2       2       0       6
-       2       2       1       1       3       1       0       0       1       0
-       1       0       2       1       1       2       0       1       0       2
-       0       4       3       4       0       0       3       4       4       0
-       2       1       1       2       0       0       3       0       0       0
-       0       1       0       1       1       0       2       0       0       1
-       2       3       0       3       1       1       1       2       0       1
-       0       0       0       0       0       0       0       0       0       0
-       0       3       0       1       2       0       1       2       2       2
-       1       2       2       1       1       0       0       2       3       2
-       1       3       0       0       1       2       0       3       1       0
-       3       0       1       1       2       2       1       2       1       1
-       4       1       0       3       1       3       2       2       0       3
-       1       2       0       2       1       3       0       2       0       1
-       2       3       3       0       0       2       3       3       2       2
-       3       2       2       1       2       3       3       1       1       3
-       0       4       2       1       1       1       2       1       0       1
-       1       5       2       0       2       3       1       3       2       2
-       1       0       3       0       2       4       1       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       1       2       0       4
-       1       0       0       0       1       1       1       2       1       0
-       5       3       2       3       1       2       1       1       1       0
-       3       3       2       1       0       0       2       3       3       3
-       3       1       1       3       0       2       1       1       2       1
-       1       2       0       2       0       1       0       1       0       5
-       1       0       0       1       1       3       2       1       1       3
-       0       1       2       0       2       0       1       1       1       1
-       3       1       2       2       1       0       5       0       2       0
-       2       1       2       4       2       0       1       1       1       2
-       1       1       3       0       1       1       0       1       3       2
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       2       0       1       1       2       1       1
-       2       3       0       3       0       1       1       1       2       1
-       2       0       2       0       1       2       1       2       0       1
-       1       0       2       1       0       1       0       0       2       0
-       1       0       1       2       2       2       1       1       6       3
-       1       1       2       0       2       1       0       1       3       1
-       2       0       0       2       0       1       0       3       1       2
-       2       2       1       2       0       0       1       2       2       1
-       0       0       2       0       2       0       0       1       1       0
-       1       2       2       1       2       1       2       3       3       0
-       1       0       0       1       0       0       3       1       0       0
-       0       1       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       2
-       0       0       1       2       1       3       0       2       1       0
-       0       1       2       2       1       1       1       0       1       0
-       1       3       2       3       1       3       2       1       0       1
-       2       1       2       2       2       0       0       1       2       2
-       1       2       0       1       1       0       1       1       1       2
-       4       2       1       0       3       3       5       1       3       1
-       1       3       1       3       0       4       0       2       2       2
-       1       2       1       1       2       0       4       2       1       0
-       1       1       0       1       2       0       0       4       7       1
-       4       2       1       1       4       2       0       1       2       0
-       0       1       1       0       1       0       1       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       3       2       3       0       0       1       0
-       0       1       1       1       0       2       0       1       0       0
-       1       1       0       0       1       1       2       3       0       2
-       2       2       0       1       1       1       2       0       2       3
-       1       1       3       0       2       1       1       3       3       4
-       0       2       2       1       4       3       3       0       0       2
-       0       1       0       0       0       3       3       1       1       2
-       1       2       1       0       3       1       0       1       0       1
-       1       1       0       5       0       0       2       1       1       1
-       0       0       1       1       0       0       3       2       2       1
-       1       1       0       0       2       2       0       1       2       0
-       0       0       1       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       1       2       0
-       2       4       0       4       4       3       1       1       4       2
-       1       5       1       2       3       0       1       1       1       4
-       0       2       0       2       2       2       1       1       3       0
-       1       2       2       2       2       3       3       2       1       0
-       2       2       3       1       2       5       2       4       2       0
-       0       0       1       0       0       2       2       2       0       1
-       5       1       1       4       4       1       0       0       1       2
-       0       0       0       1       0       2       4       2       0       3
-       2       0       1       1       0       0       2       0       1       1
-       2       2       1       2       0       1       1       1       0       2
-       1       2       0       0       0       0       0       0       0       0
-       0       0       0       0       1       1       1       1       1       0
-       1       1       0       0       0       0       0       2       1       1
-       2       0       1       2       6       1       1       1       0       0
-       1       1       0       2       1       2       2       1       0       1
-       1       2       3       1       0       2       0       0       1       0
-       3       0       0       1       2       1       3       2       2       2
-       1       4       3       1       1       3       1       1       0       2
-       1       0       4       0       2       3       0       1       2       1
-       0       0       3       1       0       1       0       1       2       1
-       1       2       0       1       1       1       3       2       3       2
-       1       0       3       0       0       1       2       1       1       1
-       1       0       0       1       0       1       0       0       2       0
-       2       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       2
-       2       0       2       1       1       4       3       2       1       1
-       3       3       2       0       1       1       3       0       3       0
-       1       2       2       1       1       4       2       1       3       1
-       2       1       1       0       2       1       4       5       1       2
-       2       4       1       1       1       1       0       0       2       1
-       0       1       0       1       0       0       2       4       0       2
-       2       0       1       2       2       2       0       0       0       3
-       1       2       1       2       4       3       1       1       1       0
-       0       1       1       1       0       1       0       2       1       1
-       3       2       1       1       1       2       0       1       2       2
-       1       2       1       1       1       1       4       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       1       0       0       1       2       0       1       1       2       1
-       1       0       0       0       2       1       2       2       0       0
-       0       2       2       2       0       0       1       4       0       0
-       1       2       3       1       2       0       1       1       2       0
-       2       3       2       1       2       1       0       2       1       3
-       2       1       2       1       1       1       0       2       0       1
-       1       2       0       2       1       1       1       3       1       1
-       0       1       1       0       1       4       1       0       1       3
-       1       1       0       0       3       1       0       2       1       3
-       1       1       4       2       1       0       1       2       4       4
-       3       3       2       2       0       3       0       1       1       0
-       1       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       2       1       0       1       2       1       0       0       0       0
-       0       0       2       0       1       1       2       2       1       1
-       3       3       0       0       2       1       1       1       2       1
-       1       1       0       0       1       0       0       1       2       0
-       1       0       1       1       0       1       1       1       2       1
-       0       2       3       1       2       2       3       1       0       0
-       1       0       0       2       2       0       3       0       2       2
-       2       0       3       0       3       3       0       2       1       2
-       0       1       1       2       1       0       0       0       1       1
-       1       0       3       0       0       1       1       0       0       2
-       0       1       1       0       0       1       1       2       3       0
-       0       1       0       0       0       0       0       0       0       0
-       0       0       0       1       0       0       0       1       2       0
-       0       1       1       1       2       1       2       1       0       2
-       1       2       2       2       0       2       2       0       0       0
-       0       3       6       1       1       0       3       2       1       0
-       1       4       0       0       1       0       0       0       0       1
-       0       1       1       1       1       2       3       1       3       0
-       0       2       0       0       1       1       5       1       2       1
-       1       2       2       5       1       4       3       2       0       1
-       1       3       1       4       2       1       3       1       2       2
-       0       0       2       3       0       0       0       2       1       0
-       4       0       0       3       1       2       2       1       1       3
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       1       0       1       0       0       0       1       0       2
-       3       2       2       0       1       0       1       0       1       3
-       0       0       0       3       3       0       0       3       2       1
-       1       1       0       2       0       1       1       2       0       0
-       0       1       1       0       1       2       1       0       2       1
-       0       2       3       0       1       3       2       0       2       5
-       0       1       2       0       3       0       1       2       0       3
-       0       0       2       0       1       0       2       0       1       0
-       1       1       2       1       1       1       0       0       1       1
-       1       2       2       2       0       1       2       1       1       1
-       2       2       1       2       0       0       0       0       1       2
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       2       0       2       1       0
-       2       1       0       3       4       0       0       0       0       1
-       1       1       0       1       2       2       1       2       1       0
-       0       0       1       4       1       3       0       0       1       3
-       0       0       0       2       3       1       0       1       4       1
-       2       0       0       0       3       0       2       0       2       5
-       0       1       0       1       1       0       0       2       1       4
-       0       0       0       4       1       2       1       1       0       2
-       1       1       2       2       0       3       0       2       0       2
-       0       0       2       2       1       1       4       0       2       2
-       1       3       2       2       1       2       1       3       0       0
-       0       0       3       0       1       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       1       0       2       1       0       0       0       0       1       1
-       1       0       0       1       2       1       0       0       4       3
-       4       3       4       0       1       1       1       0       0       0
-       0       0       1       1       1       1       1       0       2       0
-       0       1       2       2       0       1       0       2       1       0
-       0       1       1       0       1       2       1       2       2       0
-       0       0       1       1       0       1       1       2       2       0
-       3       1       1       3       1       0       0       0       3       2
-       1       1       0       1       0       2       1       0       1       2
-       2       1       3       5       1       1       1       1       1       5
-       0       3       1       2       2       3       1       0       1       0
-       1       0       0       0       0       0       0       0       0       0
-       0       0       0       0       2       1       1       1       1       1
-       1       2       0       0       0       3       1       1       4       1
-       0       1       1       1       2       0       0       2       0       1
-       0       0       0       0       2       0       0       0       1       1
-       0       1       1       1       3       2       2       0       1       0
-       3       0       1       0       0       0       1       1       3       1
-       0       1       2       1       0       0       1       2       0       0
-       2       1       3       2       3       1       0       1       2       2
-       2       0       2       0       2       0       2       1       0       0
-       2       1       0       0       0       0       4       0       0       1
-       0       1       2       2       1       0       1       0       1       5
-       2       1       0       0       0       0       1       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       2       1       2       0
-       2       1       0       2       0       4       2       0       0       2
-       1       1       2       3       0       0       0       1       2       2
-       2       1       0       3       1       1       0       1       3       0
-       2       0       1       2       1       1       1       2       2       0
-       1       2       1       2       1       1       2       0       0       3
-       2       1       2       1       0       1       1       0       0       2
-       0       1       0       0       2       1       0       3       2       1
-       0       1       1       1       2       2       0       1       1       2
-       0       0       2       1       1       0       0       0       2       1
-       0       1       1       0       2       3       2       1       3       2
-       0       2       3       0       2       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       1       1       1       0       2       2       0       1       0
-       1       3       0       0       2       3       0       0       1       0
-       2       0       1       2       1       2       0       0       0       1
-       2       2       2       1       1       0       1       0       0       1
-       0       0       1       0       2       3       1       2       1       0
-       0       0       5       0       0       2       0       2       0       0
-       0       0       1       2       0       3       0       2       0       0
-       1       2       0       3       2       3       3       2       0       1
-       2       1       1       3       2       0       2       2       0       0
-       2       1       0       2       0       1       1       2       1       2
-       2       1       3       0       1       3       1       0       0       0
-       2       1       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       4       1       1       0       2       0
-       0       1       1       1       2       0       1       0       1       0
-       1       2       0       1       4       0       2       4       2       0
-       2       0       0       0       0       0       0       3       1       1
-       0       2       1       0       3       0       1       4       0       0
-       3       0       0       2       1       2       1       2       0       0
-       0       0       1       1       1       0       2       0       2       0
-       1       2       1       2       1       0       1       1       2       0
-       2       1       0       0       2       0       0       0       3       1
-       1       0       2       1       0       2       1       1       1       1
-       0       0       0       3       0       5       0       1       0       1
-       0       2       0       0       0       0       0       0       0       0
-       0       0       0       0       2       0       1       2       0       1
-       2       1       0       2       1       1       1       1       1       0
-       0       0       0       2       1       1       1       0       2       0
-       1       0       1       0       1       0       0       0       0       1
-       0       2       1       2       0       2       1       2       0       2
-       0       1       2       0       1       1       3       0       3       2
-       1       2       2       1       2       1       0       1       0       1
-       3       2       1       0       1       3       0       1       0       2
-       1       0       2       3       1       1       2       1       0       0
-       2       1       1       1       0       3       2       2       0       1
-       1       0       2       0       2       0       1       1       0       0
-       1       1       0       0       0       0       1       0       1       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       1       0       0
-       1       1       2       3       1       0       1       2       0       1
-       2       2       4       2       1       4       0       0       1       1
-       1       0       1       1       1       0       2       0       0       2
-       0       1       3       3       1       0       2       1       0       1
-       1       0       2       2       1       1       0       3       3       2
-       1       0       4       1       2       2       3       4       1       1
-       0       2       3       0       2       3       0       2       2       1
-       0       1       1       1       1       3       0       3       2       2
-       2       0       0       1       1       1       0       0       0       1
-       0       1       0       1       1       1       0       1       0       0
-       0       0       0       0       3       1       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       2       0       0       0       0       1
-       1       0       0       0       1       2       3       2       1       0
-       0       1       0       0       0       1       3       3       0       1
-       0       0       0       3       1       0       1       4       2       0
-       2       0       1       1       1       4       1       3       1       2
-       0       1       0       1       1       2       1       0       0       0
-       2       0       2       2       1       1       0       3       2       1
-       2       0       1       1       1       2       0       0       1       2
-       1       2       2       2       0       0       1       0       0       0
-       0       1       2       1       0       1       0       3       3       2
-       1       1       0       2       5       1       1       1       0       2
-       1       1       1       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       1
-       0       0       0       0       2       0       1       1       0       1
-       1       1       2       2       1       1       0       2       1       1
-       2       3       1       0       1       1       0       1       1       4
-       3       2       3       2       1       2       2       1       2       0
-       0       0       0       2       0       0       3       1       1       3
-       1       1       2       3       0       1       1       0       0       2
-       0       1       2       0       1       0       3       2       1       1
-       1       1       3       0       1       2       0       0       2       0
-       0       1       0       0       3       0       2       1       0       0
-       0       1       0       2       1       1       3       1       0       1
-       1       0       1       2       0       1       1       0       2       1
-       0       4       0       3       0       0       0       0       0       0
-       0       0       0       0       0       0       0       1       1       0
-       1       1       0       2       0       1       7       0       2       1
-       0       3       2       2       3       2       1       1       2       1
-       1       2       1       2       2       2       2       0       1       1
-       2       0       4       6       0       1       2       0       5       4
-       3       3       3       4       3       1       3       2       1       2
-       2       0       3       5       2       3       2       1       4       1
-       2       1       4       2       6       3       3       1       0       5
-       3       1       1       1       3       3       2       5       1       0
-       0       1       2       1       1       3       1       1       0       2
-       1       0       3       1       3       0       0       3       0       1
-       1       1       4       0       4       0       1       1       0       1
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       2       4       9       8      10      12       3       9       8      10
-      10      13       8       9      11      12      12       8       9       8
-      15       5       6       5       6       7       6       3       4       3
-       6       5       1       1       0       2       0       2       2       0
-       1       3       2       2       0       1       0       2       1       2
-       2       1       0       3       0       1       2       0       1       0
-       1       0       0       2       1       0       1       1       0       3
-       2       2       1       3       2       0       2       5       4       4
-       3       3       1       4       5       5       3       5       3       4
-       5       5       7       3       3       4      10       8       7      11
-       6       5       5       5      10       6       2       3       0       1
-       0       0       0       0       0       0       0       0       0       0
-       1       1       0       0       0       0       1       1       2       1
-       1       3       3       0       0       2       3       1       1       2
-       0       1       0       1       0       0       2       0       2       2
-       1       1       2       1       2       2       2       0       1       0
-       1       1       0       0       0       0       2       1       0       1
-       1       2       1       2       2       1       0       0       0       0
-       1       1       0       0       1       0       1       0       1       0
-       0       0       1       3       1       1       2       0       3       3
-       1       3       2       3       2       0       1       2       2       1
-       2       1       2       1       0       0       0       1       1       2
-       1       2       1       0       2       2       0       1       1       1
-       0       0       2       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       1       2       0       0       0       2       2
-       2       0       1       1       3       1       0       0       0       4
-       2       1       1       4       1       3       0       0       0       0
-       2       1       0       0       0       1       4       0       2       2
-       2       0       1       3       2       1       0       3       2       0
-       1       2       0       2       1       2       0       0       3       0
-       2       0       5       0       0       1       1       0       0       0
-       1       0       0       2       1       1       0       2       1       1
-       4       0       1       0       0       0       0       1       3       0
-       3       0       0       1       0       2       3       2       4       0
-       1       2       0       1       1       0       1       0       1       1
-       2       1       3       0       0       1       0       0       0       0
-       0       0       0       0       0       0       0       0       1       1
-       0       1       1       0       2       0       1       2       0       1
-       1       0       1       0       0       0       1       3       2       1
-       2       1       0       0       0       0       0       1       1       0
-       1       0       0       0       1       1       0       2       2       1
-       1       1       2       0       0       1       3       0       2       2
-       1       2       0       2       1       1       1       0       0       3
-       1       1       0       1       1       1       1       1       0       0
-       0       3       0       1       1       2       1       1       1       4
-       0       1       1       2       0       0       1       4       0       0
-       0       1       1       2       1       2       0       0       1       3
-       1       0       2       0       3       0       2       0       1       0
-       1       1       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       1       0       3       0       0       3       1       1       1       3
-       0       2       0       1       0       2       1       1       2       0
-       0       1       5       0       0       1       1       0       2       1
-       0       1       1       1       1       1       2       2       0       2
-       1       0       1       0       4       1       0       2       1       4
-       1       1       2       0       1       1       1       1       2       0
-       0       0       2       1       3       8       0       0       1       0
-       1       1       0       1       1       3       0       3       0       0
-       0       1       0       2       0       1       0       0       0       1
-       2       1       2       2       1       2       0       2       0       1
-       1       3       0       0       1       0       2       1       0       0
-       3       0       0       0       0       0       0       0       0       0
-       0       0       0       0       1       1       1       4       0       0
-       1       1       0       2       1       0       2       1       1       2
-       2       1       2       1       2       0       1       2       3       1
-       2       1       1       2       4       0       1       0       0       1
-       0       1       0       1       1       0       3       1       0       1
-       1       1       2       0       0       1       2       2       2       0
-       0       1       3       1       1       2       2       0       1       0
-       0       3       1       0       0       0       1       0       0       1
-       2       0       2       0       0       3       1       0       1       0
-       0       0       0       0       1       4       1       1       0       0
-       0       0       1       1       2       1       2       1       0       1
-       1       0       1       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       1       0       0
-       1       1       0       3       0       2       0       1       0       0
-       0       0       0       2       0       0       2       2       2       1
-       0       1       1       2       0       2       0       0       0       2
-       0       1       2       0       0       0       1       1       1       2
-       3       2       1       0       1       2       0       0       1       1
-       2       0       1       2       1       0       1       0       2       2
-       1       2       0       1       2       1       1       1       1       0
-       0       0       1       1       0       2       0       0       0       2
-       1       6       0       0       0       1       0       0       1       0
-       0       1       1       0       0       0       1       0       1       1
-       1       0       1       0       0       1       1       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       2       1       0       1       1       0       1       1
-       0       0       4       0       1       0       0       0       1       2
-       0       1       0       0       0       0       1       1       1       0
-       1       1       0       0       1       1       1       1       1       1
-       1       1       1       3       0       0       1       0       2       0
-       2       3       2       3       2       1       1       2       1       1
-       0       0       0       0       1       1       3       0       2       2
-       0       1       3       0       0       3       0       0       0       1
-       3       0       2       0       0       1       2       0       0       0
-       1       2       1       1       1       3       2       0       1       1
-       1       0       0       1       0       0       0       1       1       0
-       0       1       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       1       1       1       0       0       2
-       2       0       0       1       1       1       2       2       0       2
-       1       2       1       1       0       0       0       2       0       1
-       1       1       1       0       1       0       0       1       1       1
-       1       0       1       0       0       0       3       0       2       1
-       0       2       1       2       1       0       1       1       1       0
-       1       1       1       2       0       2       2       0       1       0
-       3       1       2       1       0       0       1       0       0       0
-       0       0       1       1       0       1       0       0       1       1
-       1       0       0       0       3       0       0       0       2       1
-       0       0       3       0       1       0       0       0       1       3
-       1       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       1       0       0
-       3       1       1       1       0       1       3       1       0       1
-       0       0       0       0       1       1       1       1       1       1
-       1       2       0       0       2       1       1       1       0       0
-       1       3       1       0       1       1       0       2       0       1
-       3       2       2       1       5       1       2       3       3       1
-       3       1       2       2       2       1       3       0       1       0
-       0       1       3       0       0       1       0       4       1       3
-       2       3       1       0       0       2       1       0       1       0
-       1       1       1       1       2       3       0       2       0       0
-       0       0       2       4       3       1       0       0       1       2
-       2       2       1       0       0       0       1       2       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       3       0       0       1       4       0       2       1
-       1       1       2       2       2       1       2       1       1       1
-       0       1       1       2       0       0       1       1       0       2
-       0       2       1       1       1       1       1       1       3       0
-       0       2       2       1       2       1       0       1       0       0
-       0       1       1       2       0       0       1       1       1       3
-       2       1       0       0       0       1       2       1       1       0
-       1       0       2       2       0       2       2       1       0       0
-       2       0       1       0       2       2       4       2       0       0
-       2       4       1       0       0       0       1       1       1       1
-       1       0       0       0       0       0       1       0       2       0
-       0       1       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       2       1
-       1       2       1       3       0       1       0       1       0       1
-       0       1       0       0       1       2       0       0       0       0
-       1       0       1       1       0       1       2       1       0       2
-       2       0       0       0       1       2       0       0       1       0
-       0       1       1       0       1       2       2       1       2       2
-       1       1       0       2       0       2       4       0       3       1
-       1       1       2       1       2       1       0       2       1       2
-       0       0       2       0       0       0       1       1       0       1
-       0       2       2       0       0       1       0       1       0       1
-       1       4       0       0       0       1       2       2       3       4
-       1       0       0       1       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       1       0       1
-       0       0       1       1       0       2       2       2       0       1
-       0       1       0       0       1       0       0       2       2       0
-       1       1       0       0       2       1       0       0       2       0
-       0       2       0       0       1       1       1       1       1       3
-       0       0       2       1       0       0       0       1       0       0
-       3       1       1       0       1       0       2       1       1       0
-       0       1       2       0       1       3       1       0       1       0
-       2       1       0       2       4       0       2       1       4       0
-       2       1       0       1       1       1       0       2       2       1
-       1       0       0       0       1       3       0       1       1       1
-       1       0       0       2       2       2       1       2       1       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       1       0       0       5       0       2
-       0       1       2       0       0       3       2       0       1       0
-       2       0       2       1       1       1       0       1       2       1
-       0       2       0       1       0       1       1       0       1       0
-       3       1       2       2       0       2       1       1       0       1
-       1       2       3       0       0       1       1       2       1       0
-       1       2       3       0       1       0       1       1       1       0
-       0       0       0       3       1       2       1       0       2       2
-       3       0       1       0       2       0       0       1       0       2
-       0       2       1       0       0       0       2       0       1       1
-       1       1       0       2       2       1       1       1       0       0
-       0       0       0       1       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       1       1       3       2       0       0       2       0
-       2       1       0       2       2       2       0       1       0       1
-       0       0       2       1       1       0       0       0       0       1
-       0       1       2       2       0       0       1       0       1       0
-       0       0       2       0       0       1       0       2       1       0
-       0       1       0       0       1       0       1       1       1       0
-       0       3       0       0       2       2       0       0       4       1
-       0       0       2       2       0       0       1       1       1       1
-       2       2       2       0       0       0       0       3       0       0
-       1       0       2       1       1       0       1       0       0       0
-       0       1       1       0       2       1       1       2       0       0
-       0       0       2       0       0       0       0       0       0       0
-       0       0       0       0       0       0       1       0       0       0
-       1       1       1       0       0       1       1       2       0       1
-       2       2       1       2       0       2       3       0       0       1
-       0       1       0       3       1       0       0       0       0       1
-       0       2       0       1       0       2       2       1       3       1
-       1       1       1       1       1       1       1       2       0       2
-       1       2       0       1       0       0       0       3       0       0
-       1       3       3       0       1       2       0       3       1       0
-       1       2       0       0       2       0       0       0       1       0
-       2       1       0       0       1       2       1       0       1       3
-       1       0       2       0       0       1       2       0       4       2
-       1       0       2       1       0       0       0       0       1       2
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       1       0       0       1       0       1
-       0       0       0       0       3       1       1       0       1       1
-       1       2       1       2       2       0       1       1       2       3
-       2       1       0       0       1       0       1       2       0       1
-       1       1       0       1       0       0       1       3       0       0
-       0       1       0       2       1       3       1       1       3       0
-       0       0       1       0       3       1       0       1       0       1
-       3       1       1       1       0       1       0       1       1       0
-       1       1       1       0       3       1       1       0       1       0
-       1       0       0       0       0       0       0       0       1       1
-       1       0       0       0       0       1       1       2       1       0
-       0       0       2       0       1       0       0       0       1       0
-       0       0       0       0       0       0       0       0       0       0
-       0       1       2       0       0       0       0       0       1       0
-       2       0       0       1       1       0       2       0       3       4
-       1       1       2       0       0       1       0       2       1       0
-       1       0       1       2       1       0       2       0       1       0
-       0       0       1       1       2       3       3       0       0       0
-       0       2       1       0       2       2       2       1       0       0
-       0       1       3       0       1       0       0       1       2       1
-       0       1       2       3       1       0       0       1       0       0
-       1       1       0       1       0       0       0       3       0       1
-       0       0       2       1       1       0       1       0       0       1
-       0       1       2       2       1       3       2       1       2       0
-       0       1       0       2       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       1       1       1       0       0       1       0       1       0
-       2       1       0       0       0       0       0       2       2       1
-       0       1       2       0       0       0       2       2       1       2
-       2       0       0       0       1       0       0       2       1       2
-       0       2       0       1       1       2       0       0       0       0
-       0       0       0       1       1       0       2       0       0       1
-       1       0       0       2       1       0       0       0       1       0
-       2       0       2       0       0       2       1       1       2       2
-       0       0       2       2       0       1       2       0       1       0
-       1       0       0       1       0       2       0       1       1       0
-       0       1       0       0       1       0       0       1       1       1
-       1       0       0       1       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       2       1       2       0       0       0       1       0       1       0
-       4       1       2       0       1       1       4       2       1       0
-       0       2       1       1       2       1       0       0       1       0
-       2       1       0       0       0       1       0       0       2       2
-       1       1       0       1       2       0       2       1       1       1
-       0       1       3       1       0       0       0       1       2       2
-       1       0       0       0       1       1       2       2       0       0
-       0       2       1       0       2       3       0       2       0       0
-       2       0       2       0       2       0       1       0       2       0
-       2       1       1       1       0       0       1       0       0       3
-       0       1       1       0       2       1       0       1       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       2       1       0       0
-       0       1       1       2       2       0       0       2       2       0
-       0       1       0       1       1       1       1       1       0       2
-       0       1       1       1       0       0       2       1       0       0
-       1       2       0       0       0       1       0       3       1       1
-       1       1       0       2       3       1       1       1       0       0
-       0       1       1       1       1       0       0       0       1       2
-       0       0       1       0       0       0       0       0       0       2
-       1       2       2       1       0       1       0       1       1       0
-       1       1       0       0       1       0       0       1       1       2
-       0       2       1       0       2       0       0       1       1       0
-       2       1       0       1       0       2       2       1       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       1       0       3       1       1       1       1       0       0
-       0       2       0       0       1       0       0       1       1       1
-       2       1       1       1       0       0       1       0       2       2
-       0       0       0       0       1       0       3       2       0       1
-       1       0       1       0       1       1       1       2       0       2
-       0       1       1       0       0       0       0       0       1       0
-       3       1       3       3       0       0       0       0       0       0
-       1       0       1       1       2       1       0       0       0       0
-       0       0       0       1       1       2       0       2       0       3
-       0       1       0       0       0       1       0       2       0       1
-       2       2       1       1       1       0       1       1       1       0
-       0       0       0       1       1       0       0       0       0       0
-       1       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       1       1       1
-       2       0       0       1       2       1       2       0       0       2
-       1       2       4       5       3       1       2       1       2       1
-       1       3       4       1       4       0       0       5       3       1
-       1       4       4       0       3       0       1       4       1       0
-       3       1       1       2       3       2       2       2       3       0
-       1       1       2       1       3       4       0       0       1       3
-       3       0       1       1       1       0       3       0       1       2
-       2       2       4       1       2       2       3       0       1       1
-       0       0       3       3       2       0       4       3       3       1
-       2       2       3       2       1       1       2       2       3       0
-       2       0       3       0       3       1       0       2       1       1
-       0       0       1       0       0       0       0       0       0       0
-       0       0       0       0       1       1       0       0       0       0
-       1       0       1       1       0       0       0       2       1       0
-       0       0       0       0       3       1       3       0       0       0
-       2       1       1       0       0       1       1       0       0       2
-       0       0       1       0       1       1       1       2       0       1
-       1       0       1       1       0       2       1       0       2       2
-       1       0       1       0       0       1       0       0       0       0
-       1       0       0       0       0       0       1       4       0       2
-       0       0       1       0       3       0       1       1       0       0
-       0       2       0       0       0       0       1       3       3       0
-       1       1       0       0       0       1       2       2       0       0
-       0       1       0       0       0       2       0       0       0       0
-       0       0       0       0       0       0       0       0       0       1
-       0       1       2       2       0       0       3       0       0       1
-       0       0       0       3       1       0       1       0       0       0
-       0       1       0       1       0       0       0       2       1       0
-       2       2       1       0       0       0       0       1       0       0
-       0       0       1       1       1       1       2       1       0       2
-       1       0       0       1       0       0       0       1       0       3
-       0       0       0       1       0       1       1       1       0       1
-       0       1       0       1       0       0       2       0       1       0
-       1       0       1       0       1       0       1       2       1       0
-       0       1       0       0       0       2       0       0       1       2
-       0       0       1       2       0       0       1       0       2       1
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       2       1       0       0       1       2
-       1       1       0       0       0       0       1       0       0       0
-       2       0       1       0       4       1       2       1       0       0
-       1       0       1       2       0       2       0       0       0       3
-       1       0       0       1       0       1       0       0       0       0
-       1       1       0       0       0       1       0       1       0       1
-       0       2       2       0       2       0       1       1       0       0
-       1       2       2       1       1       3       2       0       1       0
-       0       1       2       0       0       2       0       0       0       1
-       0       2       0       1       1       1       0       1       0       0
-       1       2       2       0       0       0       0       1       0       0
-       0       2       1       0       2       0       0       1       0       1
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       1       0       1       1       0       2
-       0       3       0       1       0       2       0       0       1       2
-       1       1       0       0       0       1       2       0       2       0
-       1       1       1       1       0       0       0       2       1       1
-       2       0       0       0       0       0       0       1       2       1
-       2       0       1       0       1       0       1       0       0       0
-       0       2       2       1       2       1       0       1       3       1
-       2       2       1       1       2       0       1       1       1       2
-       1       0       0       4       0       2       1       3       2       2
-       2       1       0       0       0       1       0       0       1       0
-       1       0       0       1       1       1       4       0       0       1
-       1       0       0       0       1       2       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       1       1       0       0       0       0       1       0
-       1       0       0       0       0       1       0       0       0       1
-       1       2       2       2       1       1       3       1       1       1
-       1       0       0       0       2       1       0       1       4       3
-       0       1       1       1       0       1       1       1       1       2
-       1       3       2       1       1       0       0       1       0       1
-       0       0       0       1       1       2       0       1       1       0
-       0       0       0       2       1       1       0       0       0       1
-       2       1       1       1       0       0       0       0       0       0
-       1       0       1       1       0       1       1       1       1       3
-       0       0       1       2       0       2       1       1       1       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       2       0       2       1       2       1
-       0       1       0       0       0       1       0       2       2       1
-       0       0       1       0       1       0       1       0       0       1
-       0       2       1       0       0       1       0       0       2       1
-       0       0       1       0       3       0       2       0       0       0
-       0       1       0       1       0       0       1       0       2       1
-       1       2       1       3       0       1       0       0       1       1
-       0       0       1       1       0       0       0       3       0       1
-       1       0       1       2       2       2       0       1       0       1
-       9       2       0       2       2       0       1       1       3       1
-       1       2       1       0       0       1       0       0       1       2
-       3       2       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       2       1       1       0       0       0       0       2       0       0
-       1       2       1       0       0       0       1       1       0       0
-       0       1       0       1       1       1       0       0       1       0
-       1       1       2       1       0       1       1       1       2       0
-       0       1       1       0       2       0       1       0       1       0
-       0       2       0       2       1       2       1       0       0       1
-       0       2       0       1       0       1       0       0       1       0
-       1       0       0       0       1       0       0       0       1       1
-       0       0       1       1       0       3       0       1       0       1
-       2       2       0       0       1       2       1       1       4       3
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       1
-       1       0       2       3       2       0       1       0       0       0
-       3       3       0       3       1       0       2       0       0       0
-       2       0       0       0       1       2       0       0       1       0
-       1       1       0       1       1       2       0       0       1       1
-       0       0       0       0       2       0       0       0       2       0
-       0       2       0       4       3       0       0       1       0       0
-       0       1       1       0       0       0       1       2       0       0
-       0       1       2       2       0       0       0       0       1       1
-       0       1       0       2       0       0       2       2       1       0
-       1       2       1       0       0       0       3       0       0       1
-       1       1       2       0       2       0       1       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       2       2       2       1       0       1
-       0       0       0       1       3       0       2       2       2       1
-       0       2       0       0       3       0       0       2       0       2
-       2       0       0       1       1       0       0       1       0       1
-       2       1       1       1       1       2       0       0       0       0
-       1       0       0       0       4       2       0       2       0       0
-       0       0       1       0       1       1       0       0       0       0
-       1       1       1       1       3       0       1       0       0       1
-       0       2       5       0       0       1       0       0       1       3
-       0       1       0       2       0       1       0       2       2       4
-       1       1       0       1       0       2       1       1       4       0
-       0       1       1       3       1       1       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       1       0       1
-       1       2       0       1       3       2       0       1       0       1
-       3       4       1       1       2       0       1       1       4       0
-       3       2       0       3       3       1       0       3       0       2
-       0       1       0       1       1       3       2       1       0       2
-       1       4       2       0       4       1       0       1       0       1
-       0       3       2       2       3       0       0       4       3       6
-       1       0       0       2       0       1       1       2       1       0
-       1       0       1       0       1       0       0       1       0       3
-       2       0       1       2       2       1       3       1       1       4
-       1       0       1       3       3       0       1       0       1       0
-       1       1       2       2       1       0       0       0       0       0
-       0       0       0       0       0       0       0       3       4       7
-       7      11       8       8       7      10       6       7       5       8
-       6       6       6       9      10       6       7       6       3      15
-       7       6       3       4      10       6       8       8       9       7
-       3      11      12       3       3       9       7      11       6      16
-      12      11      10       2       9      11      13      10       8      13
-       8       3      10       8      12      12       6      13       9      11
-       9      12       8       9       8       7       7       8       9      10
-       9      14       9      11       8       5       6      10       8       9
-      10       8       6       6       8       9       6      11       4       3
-       6      10      10       4       4       3       7       6       8       9
-       6       6       5       3       0       1       3       1       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       2       0       0       3       2       2       2
-       0       1       2       0       1       1       1       0       2       0
-       1       1       1       2       0       1       2       1       1       1
-       1       0       1       0       1       1       0       2       1       0
-       2       1       0       0       0       1       0       1       0       1
-       1       1       1       2       0       2       1       0       1       0
-       1       0       0       0       1       1       0       0       2       0
-       0       0       0       0       0       2       1       3       0       1
-       1       3       1       2       0       0       0       0       0       1
-       0       2       1       0       1       2       1       1       2       0
-       0       2       1       0       0       3       2       1       2       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       1       0       1       0       0
-       3       0       1       0       1       1       1       0       0       0
-       1       0       1       1       0       1       1       0       0       0
-       0       0       0       0       1       1       0       0       0       0
-       2       1       2       2       0       0       0       0       1       0
-       2       0       0       0       0       2       0       2       0       1
-       2       3       0       0       0       1       0       1       0       1
-       2       1       1       1       0       0       0       1       0       1
-       2       0       2       2       2       0       2       0       1       1
-       1       0       0       0       0       0       1       1       2       1
-       2       0       1       0       1       1       0       1       1       2
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       1       1       0       2       1
-       4       1       4       0       4       0       2       3       0       0
-       1       2       1       1       1       0       2       4       2       0
-       0       0       0       2       1       1       1       2       2       1
-       1       2       2       3       0       0       1       1       1       0
-       0       1       1       0       0       0       0       1       0       0
-       0       2       0       1       0       0       1       0       1       0
-       1       0       0       1       1       1       1       1       2       1
-       0       1       1       0       0       2       0       0       2       2
-       1       0       0       2       1       2       0       5       0       0
-       1       3       1       2       0       1       1       1       0       2
-       0       0       1       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       2       0       0       2       3       2       1       0       1
-       0       0       1       0       0       2       2       1       2       2
-       1       0       1       2       1       2       2       1       2       2
-       1       1       1       0       1       0       1       1       0       3
-       0       0       1       2       2       3       0       3       1       0
-       2       0       1       1       0       1       2       2       0       2
-       0       1       0       3       0       1       1       0       2       0
-       1       1       0       0       1       0       1       1       1       2
-       0       0       2       1       0       0       2       0       2       0
-       2       1       0       1       2       0       1       0       2       1
-       2       1       0       2       1       1       0       2       2       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       1       0       0       0       1
-       0       0       0       0       1       0       2       1       0       2
-       0       3       1       0       2       2       1       0       1       3
-       2       0       2       3       1       1       1       0       3       0
-       1       1       0       2       1       0       0       1       0       1
-       1       1       1       0       1       1       0       0       0       0
-       1       1       1       2       3       0       1       1       2       1
-       0       0       2       0       1       1       0       2       2       1
-       1       1       1       0       0       1       1       0       0       0
-       0       1       0       3       1       1       0       1       1       0
-       1       1       3       0       1       0       1       2       0       0
-       0       0       1       1       2       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       2
-       0       0       3       1       1       2       1       1       0       1
-       1       1       2       1       1       1       1       1       2       2
-       3       0       1       2       3       2       4       3       2       3
-       1       2       1       2       2       3       1       1       1       4
-       2       0       1       3       2       2       2       2       1       2
-       2       3       3       2       0       0       3       3       1       3
-       3       2       2       3       0       2       4       2       3       3
-       2       2       3       3       2       3       2       4       5       2
-       1       3       4       1       1       0       4       4       2       2
-       2       1       3       2       3       1       3       2       8       5
-       0       1       1       1       4       1       1       0       1       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       1
-       0       0       0       1       0       1       0       1       1       0
-       1       1       1       1       0       0       0       2       0       0
-       0       0       1       1       2       2       0       0       0       2
-       0       0       1       1       1       1       1       2       0       0
-       1       1       1       0       3       1       1       1       0       0
-       1       0       1       0       0       0       1       2       0       1
-       2       0       0       1       0       2       1       1       2       0
-       2       2       2       0       1       0       0       1       0       0
-       3       0       2       1       0       2       1       2       0       0
-       2       0       1       2       0       2       2       0       2       0
-       0       1       2       1       1       1       1       1       2       0
-       0       1       0       0       0       0       0       0       0       0
-       0       0       0       0       1       1       0       2       0       0
-       0       0       0       1       1       0       0       0       0       0
-       0       1       2       2       0       1       1       0       0       2
-       0       0       2       1       3       0       1       2       1       0
-       2       0       0       1       4       0       1       2       1       2
-       0       0       1       1       0       0       0       0       0       1
-       1       1       1       1       1       0       1       0       1       0
-       0       0       0       0       0       1       0       2       0       0
-       1       1       1       1       1       1       2       1       1       3
-       0       1       0       4       2       1       1       1       2       0
-       2       1       1       1       2       1       0       1       0       0
-       0       0       1       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       1
-       0       0       1       1       1       0       0       3       2       0
-       0       2       1       1       1       0       1       0       2       3
-       3       0       0       0       1       0       4       0       0       2
-       0       1       1       1       2       0       0       0       1       0
-       2       1       0       0       1       1       3       2       1       2
-       0       1       1       1       0       0       0       1       0       1
-       0       2       0       0       1       4       0       0       1       3
-       1       0       0       3       2       1       0       1       1       1
-       0       0       2       1       0       1       0       1       0       2
-       0       0       0       0       2       1       0       0       0       0
-       1       1       2       2       1       0       0       1       0       0
-       0       0       0       0       0       0       0       0       0       0
-       1       0       0       2       0       3       2       0       3       2
-       1       0       1       2       0       1       0       1       2       1
-       0       2       1       1       0       0       0       1       1       0
-       0       1       4       1       0       0       0       1       0       2
-       0       0       1       1       1       0       1       0       1       1
-       1       0       3       1       1       0       0       0       0       2
-       1       1       1       3       0       1       1       1       1       0
-       0       0       3       0       0       3       1       1       1       0
-       1       0       3       0       1       0       0       0       1       1
-       1       1       2       0       0       2       0       0       0       1
-       2       0       0       0       1       1       0       0       0       1
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       1       3       3       2       0
-       0       0       1       0       0       0       1       0       0       0
-       0       2       0       1       0       2       2       1       2       0
-       0       1       0       0       0       1       2       0       0       1
-       1       0       2       3       0       0       0       1       2       1
-       1       1       1       1       1       1       0       1       1       1
-       0       2       0       0       0       1       1       0       1       1
-       2       1       0       2       0       0       1       0       0       0
-       2       0       0       2       0       1       0       3       1       0
-       0       0       0       0       0       1       2       0       1       0
-       0       1       1       3       3       0       0       0       0       0
-       2       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       1       1       0       3       0
-       1       1       1       2       0       0       2       1       1       0
-       2       0       0       0       1       2       0       0       0       0
-       0       2       0       0       1       0       0       2       0       1
-       1       2       1       2       0       2       1       1       1       0
-       2       0       0       0       1       1       2       1       0       0
-       2       0       0       0       1       1       0       1       1       2
-       0       1       0       1       0       0       1       3       1       1
-       2       0       1       1       2       1       0       2       0       1
-       1       0       0       3       2       1       1       1       0       1
-       1       2       2       0       0       0       0       1       1       0
-       1       0       0       2       1       1       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       1       0       1       1       1
-       2       4       1       3       2       4       2       1       1       3
-       1       1       3       1       3       3       3       1       2       2
-       1       3       1       2       3       3       3       2       5       2
-       3       2       2       3       0       5       1       1       1       2
-       0       0       1       1       2       2       0       1       1       5
-       0       1       1       2       3       2       1       0       2       1
-       2       2       2       2       2       1       3       2       2       2
-       2       3       3       0       1       3       2       1       1       3
-       4       0       0       4       0       2       0       2       3       3
-       3       3       4       1       5       2       4       2       1       1
-       0       1       3       4       6       5       2       3       3       1
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       2       1       1       0
-       0       0       1       0       3       0       2       1       0       1
-       1       1       1       4       0       0       1       0       0       1
-       1       0       1       0       2       0       1       1       2       3
-       1       1       1       0       0       0       1       1       1       0
-       1       0       0       0       2       3       0       0       0       2
-       2       0       0       0       1       3       1       0       1       0
-       2       0       0       0       0       0       1       1       0       1
-       0       0       0       0       0       1       1       1       0       2
-       0       1       1       1       0       0       0       3       2       1
-       2       0       1       3       0       0       2       1       1       2
-       2       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       1       1       0       2       1       0       0
-       0       0       0       1       2       0       1       1       5       0
-       0       1       0       1       2       1       0       1       0       1
-       1       0       0       0       0       1       0       0       0       0
-       0       1       0       1       0       0       1       0       0       2
-       0       0       0       0       1       1       0       2       0       0
-       1       1       1       2       1       1       1       0       0       0
-       1       0       0       2       0       4       1       1       1       0
-       0       1       0       1       2       1       1       2       0       1
-       1       1       1       2       0       0       2       1       0       1
-       1       0       1       1       1       1       1       2       4       1
-       0       0       1       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       1       0       2
-       2       3       0       1       2       0       0       2       1       0
-       1       1       1       1       0       2       0       2       0       2
-       2       1       0       1       0       0       3       0       1       0
-       0       2       0       0       1       0       1       0       1       1
-       1       4       0       1       0       0       1       1       1       3
-       0       0       0       0       0       0       0       1       1       1
-       0       0       4       2       1       0       0       1       1       1
-       0       1       0       0       3       0       0       1       1       0
-       3       0       2       2       1       1       0       0       1       1
-       2       0       0       0       1       1       0       0       1       0
-       0       2       3       1       3       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       1       0       0       1       0
-       1       2       2       0       0       1       1       1       2       1
-       2       2       1       0       2       0       1       1       1       1
-       0       0       0       1       0       1       1       0       2       1
-       1       1       0       0       0       1       2       0       0       0
-       0       2       0       2       2       1       1       0       1       0
-       1       0       2       1       1       0       0       0       0       1
-       1       0       2       0       1       0       0       2       0       0
-       1       1       1       0       1       1       0       1       3       1
-       1       2       2       1       1       2       1       0       1       2
-       2       1       0       1       1       1       0       0       0       0
-       0       4       1       1       0       1       3       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       1       1       2       0       0       1       3       3
-       1       1       0       1       2       0       0       1       1       0
-       0       1       0       1       0       1       0       0       2       1
-       2       1       2       2       0       0       1       2       0       2
-       0       2       2       0       1       1       2       0       0       0
-       1       1       0       1       0       3       0       2       1       1
-       1       0       0       2       2       1       0       1       1       1
-       0       0       0       2       1       1       1       3       0       1
-       0       3       0       0       1       1       2       1       0       1
-       1       3       1       2       1       0       0       0       0       0
-       0       0       0       1       2       1       0       1       1       0
-       1       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       1       0       0       0       0
-       1       0       1       1       1       0       1       0       1       0
-       0       0       1       0       0       2       2       0       2       0
-       0       2       2       3       2       1       0       0       2       1
-       0       3       0       0       0       1       1       0       0       0
-       3       0       0       0       0       0       1       0       0       0
-       0       3       3       0       0       2       4       2       2       1
-       0       0       1       1       2       0       1       0       0       0
-       0       0       0       0       0       2       1       2       0       0
-       4       0       2       1       2       1       1       1       1       1
-       0       1       0       1       0       0       0       0       1       0
-       0       1       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       1       1
-       0       2       2       2       0       3       1       2       0       1
-       0       3       1       3       1       5       1       0       0       3
-       2       3       2       1       2       1       6       9       1       1
-       1       1       1       1       1       1       0       0       1       2
-       1       1       3       2       1       3       2       0       0       2
-       2       0       2       1       1       1       4       1       0       1
-       1       3       2       2       1       3       0       0       1       0
-       2       1       5       4       1       1       0       2       2       2
-       0       3       1       4       2       0       1       4       3       3
-       3       2       1       0       1       3       2       2       2       3
-       0       1       2       2       1       2       1       0       0       1
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       1       0
-       0       1       0       2       0       0       0       1       2       0
-       1       0       1       0       4       0       1       1       2       2
-       1       0       1       1       0       2       2       1       1       0
-       0       2       1       0       1       0       2       1       0       1
-       0       1       0       0       0       0       0       1       1       0
-       1       0       0       0       3       1       0       0       2       1
-       0       0       1       1       1       3       1       0       0       1
-       1       0       0       0       2       0       0       1       0       0
-       2       0       0       2       0       1       1       0       3       1
-       1       0       1       0       0       0       0       1       0       0
-       2       1       1       0       0       0       0       1       2       0
-       1       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       1       2       0       0
-       0       1       0       0       0       0       1       1       0       0
-       0       1       0       2       1       1       0       0       0       0
-       3       0       1       2       2       1       0       1       0       0
-       1       2       1       1       0       1       1       2       0       1
-       0       1       1       0       1       0       0       0       1       0
-       2       1       0       1       1       1       0       0       0       1
-       1       0       1       1       3       0       0       0       1       0
-       0       0       0       1       1       2       0       0       1       1
-       4       2       2       1       1       4       1       0       2       0
-       1       0       0       1       1       0       0       1       0       1
-       0       2       1       2       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       1
-       1       0       5       1       0       0       0       0       0       1
-       0       3       0       1       1       0       1       1       3       0
-       0       1       0       1       0       0       1       1       3       0
-       1       0       1       1       0       1       1       1       1       0
-       0       1       1       0       0       0       2       0       1       0
-       0       0       2       1       1       0       2       0       1       0
-       0       1       0       0       1       0       2       0       0       0
-       0       3       1       0       1       2       0       0       0       0
-       0       3       0       1       1       0       2       1       1       0
-       0       1       0       0       2       1       1       1       1       0
-       2       0       0       3       0       2       0       0       1       0
-       2       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       1       1       0       0       0
-       0       0       2       0       1       1       0       1       2       1
-       0       1       1       1       0       0       2       2       1       0
-       0       0       2       1       0       4       0       0       2       0
-       0       1       0       1       0       1       0       1       1       2
-       0       2       0       1       0       1       3       0       0       0
-       0       0       2       1       0       3       0       0       4       1
-       1       2       0       1       1       1       1       2       0       0
-       0       0       1       0       0       1       0       0       0       2
-       1       0       3       1       0       1       1       2       1       2
-       1       0       1       0       0       2       0       0       0       1
-       1       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       1       1       0       1
-       0       1       0       2       2       1       0       0       1       2
-       2       2       1       1       1       2       1       0       0       1
-       0       1       0       1       2       0       1       2       0       1
-       0       0       0       0       0       0       2       2       0       1
-       1       0       2       0       1       0       1       0       0       0
-       0       4       0       0       4       1       1       0       2       1
-       1       2       0       1       2       1       2       0       1       0
-       0       1       0       1       1       0       0       1       0       2
-       3       1       2       1       1       1       0       0       3       2
-       1       0       1       1       0       0       1       0       0       1
-       0       1       1       2       1       0       0       0       0       0
-       0       0       0       0       0       0       0       1       0       1
-       1       0       1       0       0       1       1       1       2       1
-       0       1       1       1       1       1       2       0       2       1
-       0       0       1       2       0       3       1       0       1       0
-       0       0       0       2       0       0       0       1       1       0
-       1       2       3       0       3       0       1       0       0       1
-       0       0       1       1       1       2       0       1       1       0
-       1       0       1       0       1       0       0       2       2       3
-       1       1       0       2       1       0       0       0       1       1
-       0       1       1       1       0       1       1       0       2       1
-       1       1       0       2       2       2       0       2       2       2
-       1       0       0       0       0       1       0       1       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       2       0       2       1       1       1       0       0
-       2       0       0       1       2       0       1       0       1       0
-       0       1       1       0       0       1       1       2       2       0
-       1       0       2       3       0       1       0       0       1       0
-       0       0       1       0       0       0       2       2       0       0
-       0       2       0       0       0       1       0       0       0       1
-       1       1       0       3       3       2       0       0       0       2
-       0       2       2       0       1       0       0       0       1       1
-       0       3       1       2       1       0       0       1       0       0
-       0       3       0       1       1       2       0       4       0       1
-       0       1       0       1       4       0       2       1       0       1
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       1       3       1       6       0       5
-       2       2       0       3       1       4       1       3       4       1
-       1       2       2       0       1       2       2       5       1       4
-       3       3       3       2       2       5       2       1       5       6
-       3       4       2       0       2       7       4       8       2       3
-       5       4       6       3       2       2       6       4       1       2
-       7       4       3       5       5       1       4       1       9       4
-       4       2       3       5       5       1       2       4       7       7
-       1       2       4       1       3       3       4       3       3       1
-       3       3       3       4       0       4       1       4       2       2
-       1       2       3       1       3       0       2       0       1       2
-       1       1       0       0       0       1       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       1       0       1       0       1       3
-       1       0       2       0       2       0       1       0       0       0
-       1       0       0       3       3       0       0       0       0       1
-       1       0       0       0       2       0       1       1       2       2
-       1       1       0       0       1       2       1       1       0       1
-       0       1       3       2       0       1       1       2       3       2
-       1       4       0       1       0       2       1       1       1       2
-       1       0       1       0       3       1       1       3       0       1
-       0       1       4       1       1       2       0       2       0       0
-       0       2       2       1       2       0       0       0       2       0
-       1       0       1       0       0       0       2       0       1       1
-       1       0       1       0       1       0       0       0       0       0
-       0       0       0       0       0       0       1       2       1       2
-       1       1       0       0       0       1       2       1       0       0
-       2       1       0       0       0       1       0       0       1       1
-       0       0       0       0       1       1       1       0       2       0
-       0       2       1       0       2       0       2       2       0       1
-       2       1       1       2       0       2       0       1       0       2
-       3       1       0       1       0       1       1       1       1       1
-       1       2       0       0       0       2       0       1       1       1
-       2       2       0       0       2       1       2       1       2       0
-       1       0       1       1       0       1       1       0       2       4
-       0       1       1       2       1       0       0       2       1       2
-       0       0       0       0       1       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       1
-       0       1       1       0       2       0       0       0       1       0
-       1       1       1       0       0       2       1       1       0       0
-       0       0       1       1       2       0       1       2       0       1
-       0       1       1       2       0       1       1       0       0       2
-       1       1       0       1       1       2       0       1       0       0
-       1       1       0       2       1       0       0       2       1       0
-       0       1       2       0       1       0       0       1       0       0
-       0       1       2       0       1       0       1       3       1       0
-       1       0       2       0       3       0       2       2       1       0
-       0       0       1       1       2       1       1       1       2       1
-       0       1       0       0       0       0       0       0       1       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       1       0
-       1       1       2       2       1       0       0       1       2       2
-       0       1       1       0       1       1       2       0       0       2
-       2       1       1       1       1       1       2       1       3       2
-       2       1       0       1       1       0       1       0       1       2
-       2       2       2       0       3       0       0       1       2       3
-       1       3       3       0       1       2       2       0       0       2
-       0       2       0       0       2       3       0       0       1       2
-       4       0       2       3       4       1       3       1       0       2
-       1       1       2       2       2       1       0       2       1       3
-       2       0       1       1       2       1       1       0       3       3
-       0       4       3       1       0       1       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       1       0       1
-       0       2       1       1       1       1       0       1       1       0
-       0       1       0       1       0       1       2       1       1       0
-       0       0       1       1       0       0       0       0       0       1
-       5       0       0       1       1       0       0       0       1       0
-       0       1       0       2       2       0       0       0       1       0
-       0       1       0       0       2       0       0       1       1       0
-       0       0       2       0       1       0       1       1       0       1
-       0       0       0       0       1       0       0       1       0       0
-       0       2       0       1       1       0       2       2       1       0
-       0       0       2       0       1       1       3       1       1       0
-       0       1       0       2       1       1       1       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       1       0       1       2       0       1       1       1       1
-       2       1       2       1       4       0       1       0       1       0
-       1       1       0       0       3       0       0       0       1       0
-       0       2       1       1       0       1       1       0       1       0
-       2       1       0       1       0       2       0       0       1       2
-       1       3       0       0       0       0       0       1       0       2
-       1       0       1       2       1       0       1       2       1       1
-       1       2       1       1       1       0       0       0       1       2
-       0       2       4       1       1       1       1       0       0       0
-       0       1       3       0       1       0       0       0       0       1
-       0       4       1       0       0       0       0       1       1       0
-       1       2       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       1       0       1
-       1       1       0       2       2       2       1       2       4       0
-       1       2       1       0       1       1       1       1       2       3
-       0       2       1       3       0       3       5       1       2       0
-       3       1       1       2       2       0       0       1       3       1
-       4       2       1       1       2       1       2       2       2       3
-       2       0       2       4       2       5       5       0       2       1
-       0       2       0       1       0       0       1       3       1       0
-       1       2       2       1       1       1       3       1       0       0
-       3       1       1       0       0       2       1       0       1       4
-       1       0       2       0       2       1       1       2       1       1
-       2       0       1       1       2       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       2
-       1       1       1       1       0       0       1       1       0       1
-       1       1       3       1       2       2       1       1       0       0
-       2       1       0       1       0       1       0       2       0       0
-       1       2       0       0       2       1       2       0       0       1
-       0       0       1       2       0       0       0       0       1       1
-       0       0       3       0       1       0       1       1       0       1
-       1       3       1       1       1       2       1       1       1       0
-       1       1       0       0       3       2       0       2       2       0
-       0       2       2       1       2       1       1       0       1       0
-       2       2       0       1       2       1       1       0       0       2
-       1       2       0       2       0       1       1       0       1       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       1
-       1       4       1       0       2       1       1       0       1       1
-       0       1       1       1       0       2       1       1       1       0
-       1       2       0       1       1       0       2       0       0       0
-       2       1       0       1       1       2       0       1       0       0
-       1       1       0       0       2       0       1       0       1       0
-       0       0       1       1       0       0       1       0       1       2
-       1       1       1       1       0       0       1       2       2       0
-       2       0       0       1       1       0       0       1       1       1
-       0       3       1       2       0       2       0       1       0       1
-       0       2       2       1       2       0       0       1       2       2
-       1       0       1       1       2       2       3       1       1       0
-       0       0       0       0       0       0       0       0       2       0
-       2       1       0       0       2       0       2       0       1       0
-       2       0       0       1       1       0       0       0       0       2
-       0       2       0       3       1       3       1       1       0       0
-       0       0       0       0       0       0       2       3       1       1
-       1       0       3       1       0       1       0       1       0       0
-       3       1       0       1       2       2       2       1       0       1
-       0       1       0       1       1       1       0       1       2       2
-       1       1       2       0       0       0       0       0       0       1
-       1       1       1       0       1       1       0       2       2       2
-       2       1       0       2       0       3       3       0       1       0
-       0       0       0       0       1       0       1       1       2       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       2       1       1       2       1
-       3       1       1       2       0       0       2       3       3       0
-       0       0       2       1       2       2       1       0       1       1
-       4       1       1       0       1       1       2       0       1       0
-       2       1       2       3       2       0       3       1       1       1
-       0       1       1       2       0       1       1       4       0       1
-       1       0       1       1       0       0       1       1       1       0
-       1       4       1       0       1       1       0       0       3       2
-       1       0       2       0       0       2       2       0       0       0
-       0       1       1       1       1       1       0       1       0       0
-       2       1       1       0       1       0       2       1       0       1
-       1       1       3       0       1       1       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       3       0       2       0       0       1       0
-       0       2       0       1       1       1       1       0       0       1
-       0       1       0       0       0       3       1       1       1       1
-       2       1       1       0       0       0       0       0       0       0
-       0       1       3       0       1       2       3       1       1       1
-       0       0       0       1       1       0       1       0       0       2
-       0       0       1       2       0       0       1       0       1       3
-       2       1       0       0       0       0       2       0       1       1
-       0       0       0       0       0       2       0       1       0       1
-       2       0       0       2       0       0       0       0       1       1
-       1       0       1       1       1       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       1       1       0       2       0       0       1       0       2       0
-       1       1       0       0       0       1       3       1       2       2
-       1       1       1       0       1       0       0       1       0       2
-       1       0       0       1       1       1       0       1       1       0
-       4       0       1       1       1       0       0       3       0       1
-       0       0       0       0       1       2       0       1       0       1
-       1       1       0       0       2       1       0       1       0       2
-       0       0       0       0       1       3       1       1       0       1
-       0       0       0       1       0       1       1       2       0       1
-       2       1       0       1       0       1       0       0       3       1
-       2       0       0       1       1       2       1       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       2       1       0       2       2       2
-       0       0       2       2       0       1       2       1       0       1
-       2       0       1       0       1       1       2       0       0       0
-       1       0       0       0       1       2       1       2       0       1
-       1       1       0       1       2       1       1       1       2       1
-       0       1       1       0       0       1       1       0       0       0
-       2       0       1       0       1       2       2       0       0       0
-       0       0       2       2       1       1       0       1       1       1
-       1       1       0       1       0       1       1       1       2       1
-       0       0       2       1       2       0       2       1       1       1
-       1       1       1       0       1       0       0       1       4       0
-       1       1       1       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       1       0       1       1       0
-       0       2       1       1       2       0       2       0       2       2
-       1       1       1       1       0       1       1       1       1       0
-       1       0       0       1       3       2       1       2       0       0
-       1       2       0       1       0       4       0       1       0       0
-       2       0       1       0       0       2       2       1       1       1
-       1       0       0       1       1       0       1       0       0       0
-       1       1       0       3       2       0       0       2       2       1
-       3       2       2       2       1       2       1       2       1       1
-       2       1       2       2       0       1       0       0       1       0
-       0       1       1       0       0       1       0       1       2       0
-       4       0       0       1       2       0       0       0       1       0
-       0       0       0       0       0       0       0       0       0       0
-       0       1       1       3       2       1       1       0       1       1
-       0       3       1       1       1       1       0       0       0       0
-       1       0       1       0       1       2       1       2       1       0
-       0       0       0       3       0       1       1       0       2       1
-       1       0       3       0       1       0       1       0       0       2
-       1       0       1       2       0       2       3       1       2       0
-       0       0       1       0       2       1       0       1       1       0
-       1       0       1       1       2       2       1       1       2       1
-       1       1       0       0       0       1       2       1       0       0
-       2       2       0       1       1       4       2       1       2       0
-       1       1       1       2       2       0       1       0       1       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       2       1       0       0
-       0       0       0       1       2       0       1       1       1       0
-       2       0       1       0       1       1       3       2       1       1
-       1       1       2       1       0       1       0       1       0       1
-       1       2       0       1       1       1       2       1       0       0
-       1       1       0       1       2       2       2       1       0       2
-       1       0       1       0       2       3       0       1       0       0
-       0       1       1       2       1       4       1       1       2       1
-       0       2       1       0       2       0       1       0       0       1
-       0       1       0       0       1       0       2       0       1       1
-       2       1       0       1       2       0       3       1       2       2
-       2       0       2       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       1       1
-       1       2       0       1       0       0       0       0       2       1
-       0       1       2       1       0       4       0       0       1       1
-       1       2       2       1       1       0       0       0       1       0
-       0       0       0       2       2       0       2       3       1       1
-       0       0       2       0       0       0       1       0       1       0
-       1       0       0       0       3       0       0       0       2       2
-       1       0       0       0       4       0       0       1       3       3
-       0       2       3       0       0       0       1       4       0       2
-       0       0       3       1       0       1       1       0       0       2
-       0       2       0       0       0       1       1       1       2       1
-       1       1       3       0       1       1       0       1       0       1
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       1       1       2
-       0       0       0       1       1       2       0       3       2       1
-       0       0       3       1       1       1       0       1       2       1
-       0       2       1       1       0       0       0       0       0       0
-       0       1       2       1       1       0       1       1       2       0
-       0       1       2       0       2       0       0       0       4       0
-       0       1       1       0       0       0       3       0       0       0
-       0       1       2       0       2       2       1       1       0       2
-       2       1       1       0       1       2       1       1       0       2
-       1       2       1       0       1       1       1       1       1       1
-       1       2       1       2       0       1       1       3       1       0
-       1       2       1       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       1       2       0
-       0       2       1       0       1       0       1       0       0       1
-       1       2       1       1       1       1       0       0       1       0
-       1       0       0       0       0       0       1       2       0       1
-       0       2       1       1       0       2       1       1       1       1
-       1       0       0       0       1       0       0       1       0       0
-       0       0       1       1       0       0       2       0       1       0
-       0       0       0       1       0       1       0       1       0       2
-       0       2       2       0       1       1       2       0       1       1
-       0       0       2       1       2       1       0       0       0       1
-       0       2       1       2       0       1       2       1       0       0
-       2       0       1       0       1       1       1       1       0       1
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       1       1       2       0       2
-       1       0       0       0       0       1       0       1       2       0
-       2       0       0       1       1       2       1       1       4       0
-       2       0       0       2       0       0       2       1       1       1
-       0       2       0       3       0       2       2       0       1       2
-       2       0       2       0       1       0       0       0       0       2
-       2       1       0       1       1       2       1       0       1       2
-       2       3       1       1       2       1       0       1       0       0
-       3       0       1       0       0       2       2       1       1       1
-       1       1       1       0       1       3       2       1       1       3
-       2       3       0       0       1       0       2       1       1       2
-       0       1       1       1       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       1       0       1       1       0       0       1       4
-       2       1       2       2       2       2       0       2       2       0
-       0       0       1       2       1       0       1       1       0       2
-       0       2       0       1       0       2       1       2       0       0
-       0       2       0       3       0       0       0       1       0       1
-       1       2       0       1       1       0       1       0       1       0
-       1       0       0       0       1       1       0       1       1       2
-       1       2       3       0       0       1       1       1       1       1
-       0       0       0       0       1       0       1       1       0       1
-       1       1       1       1       1       2       1       1       1       0
-       1       0       0       2       1       2       0       0       1       0
-       1       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       1       0       2       1
-       2       0       3       2       0       1       1       1       0       0
-       2       0       0       2       1       4       2       1       2       0
-       1       1       1       2       0       1       0       2       2       2
-       0       0       0       1       1       1       0       0       1       0
-       0       1       1       0       1       0       2       0       3       1
-       1       2       1       1       1       2       1       1       0       1
-       2       2       2       0       0       4       0       3       0       1
-       0       1       1       1       0       2       3       0       1       1
-       1       1       1       1       1       1       1       0       1       0
-       2       1       3       1       1       1       1       2       2       2
-       0       0       4       1       0       0       0       0       0       0
-       1       0       0       0       0       0       1       2       3       0
-       0       1       1       1       1       1       2       0       1       0
-       1       1       0       1       3       1       1       4       1       1
-       1       3       0       2       0       1       0       1       1       0
-       0       1       0       0       0       0       0       1       1       0
-       1       1       1       0       2       0       0       1       0       3
-       1       2       0       0       2       0       0       1       0       2
-       1       1       0       2       1       1       1       0       0       2
-       1       0       2       1       0       1       2       1       0       0
-       0       3       1       0       0       0       0       1       2       1
-       0       0       0       1       1       0       1       1       0       1
-       1       0       1       1       1       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       1       0       0       0       1       2       2       1
-       0       1       0       5       3       0       3       1       1       0
-       0       0       0       0       3       0       2       0       1       2
-       1       1       1       0       0       3       0       1       2       0
-       1       0       1       0       0       0       3       1       1       0
-       1       1       4       0       1       0       0       2       0       1
-       0       0       0       0       0       0       0       0       1       0
-       1       2       1       0       1       1       2       1       1       2
-       1       2       2       0       2       0       2       1       4       0
-       0       3       0       1       1       0       0       0       0       0
-       4       1       2       4       1       0       2       2       1       0
-       2       1       0       0       0       0       0       0       0       0
-       0       0       0       2       2       1       0       1       1       0
-       2       1       0       2       2       1       0       2       0       1
-       1       3       0       0       1       3       2       0       2       1
-       0       0       2       1       0       0       0       1       0       1
-       3       0       1       1       0       0       0       4       2       1
-       2       1       1       1       0       2       0       1       0       1
-       0       1       1       0       0       2       1       1       1       1
-       0       0       1       0       0       0       0       1       0       1
-       0       0       0       2       1       0       2       0       1       0
-       0       1       0       2       2       2       1       1       1       1
-       2       0       1       1       0       1       0       3       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       1       0       1       1
-       0       1       2       1       2       1       0       1       0       2
-       1       1       2       0       3       2       2       1       1       1
-       1       3       2       2       2       4       2       2       4       2
-       0       2       2       2       2       0       1       2       1       1
-       0       4       3       1       0       2       0       2       1       2
-       1       0       0       1       1       1       1       1       5       1
-       1       0       2       3       2       3       1       3       2       1
-       1       2       3       1       2       1       2       0       1       1
-       0       2       0       0       1       1       1       0       1       2
-       1       1       3       1       2       2       1       2       0       0
-       1       2       1       1       3       2       0       0       0       0
-       0       0       0       0       0       0       0       0       0       1
-       0       0       3       1       1       1       0       2       0       0
-       0       0       1       0       1       1       2       1       0       1
-       2       0       0       1       1       1       0       0       0       0
-       1       3       3       3       0       4       0       5       2       1
-       1       1       0       2       0       0       0       4       2       3
-       2       1       0       3       2       1       1       1       0       4
-       1       0       1       2       3       1       2       2       2       1
-       0       2       3       2       1       0       0       1       0       0
-       2       0       1       0       1       1       1       1       0       0
-       3       1       1       2       4       0       0       1       1       3
-       1       0       3       0       2       0       1       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       1       0       2       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       1       1       3
-       2       2       1       1       0       0       0       0       0       0
-       0       1       0       0       0       0       1       2       1       1
-       0       1       3       1       1       1       2       1       2       0
-       3       1       0       0       0       0       1       1       1       1
-       2       0       1       1       1       0       0       0       1       1
-       2       0       2       1       1       0       5       0       3       3
-       1       1       1       0       2       0       2       0       2       1
-       2       1       0       2       0       2       3       1       3       2
-       0       0       2       0       0       1       0       0       1       1
-       0       1       0       0       1       3       0       0       0       2
-       2       0       0       1       0       1       1       1       2       1
-       1       0       1       0       0       1       0       0       0       0
-       0       0       3       1       0       3       2       0       1       3
-       0       2       0       2       0       2       1       0       1       1
-       1       0       0       0       0       0       0       1       2       1
-       2       2       2       1       1       0       2       3       0       0
-       1       2       1       2       1       3       0       0       0       1
-       2       2       1       1       3       3       1       1       2       5
-       0       2       1       0       1       1       2       0       0       0
-       2       1       2       1       0       0       2       1       1       1
-       1       0       1       1       0       0       0       1       0       2
-       1       2       1       1       1       0       2       3       0       1
-       1       0       0       2       0       0       0       0       0       0
-       0       0       0       1                                                
-SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS
-       5      20      25  123944       0       1                                
-FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
-       6       1                                                                
-            time         monitor       Total Cou     angles*1000                
-  0.35764000E+05  0.30000000E+06  0.16073000E+05  0.15270300E+06  0.40200000E+03
-  0.50810000E+05                                                                
-IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
-   16384                                                                        
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       1
-       0       0       2       0       0       0       1       0       0       0
-       2       0       1       0       0       0       0       0       0       1
-       0       0       1       0       0       0       0       0       0       0
-       0       1       0       1       2       0       0       0       0       1
-       1       1       2       0       0       1       0       1       2       0
-       0       0       1       1       1       1       1       0       1       0
-       0       0       1       0       1       0       0       1       1       1
-       0       1       2       1       0       0       1       1       1       0
-       0       0       0       0       0       1       0       1       0       0
-       0       0       1       1       0       0       0       0       1       0
-       0       1       1       1       1       0       1       0       3       0
-       1       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       1       0       1
-       0       0       2       0       0       0       1       0       0       0
-       2       0       1       1       1       0       0       0       3       0
-       0       0       1       1       0       2       0       1       0       2
-       0       1       0       1       1       0       1       0       0       0
-       1       1       0       0       1       1       1       0       2       1
-       0       0       1       0       0       0       0       0       1       0
-       0       0       2       0       0       2       1       1       0       0
-       0       0       0       0       2       0       0       0       1       0
-       0       1       0       3       0       0       0       1       0       0
-       1       0       0       0       1       1       0       0       1       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       1
-       0       2       0       1       1       0       0       1       0       0
-       0       2       0       2       1       3       0       0       1       0
-       1       1       0       0       0       0       1       0       1       0
-       0       1       0       0       1       1       1       0       2       1
-       0       1       1       0       2       1       2       0       1       0
-       0       1       0       1       1       2       0       1       1       1
-       1       0       1       1       0       0       2       1       2       2
-       2       0       0       1       0       2       0       0       0       1
-       0       1       0       3       0       0       0       1       1       0
-       1       0       2       0       1       0       0       0       0       2
-       1       2       1       0       1       0       2       0       0       0
-       1       0       0       0       0       0       0       0       0       0
-       0       0       2       0       0       1       1       0       0       0
-       0       0       0       0       0       1       0       1       0       1
-       2       1       2       0       0       0       0       0       0       1
-       0       1       1       1       0       1       0       2       1       1
-       1       1       0       1       0       0       1       0       2       0
-       0       1       1       0       1       1       0       0       1       2
-       0       0       0       0       0       0       1       1       0       2
-       1       2       1       0       1       0       0       1       1       1
-       2       0       2       0       0       1       0       0       2       1
-       1       2       1       0       2       0       2       2       0       1
-       2       1       2       1       0       0       2       2       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       1       1       0       4       1       1
-       1       0       0       1       1       0       1       0       0       2
-       3       0       0       0       0       0       1       1       3       1
-       0       2       1       0       0       2       0       0       0       0
-       1       0       0       1       0       1       0       1       1       0
-       0       2       3       0       0       0       2       0       2       2
-       2       3       1       1       0       0       0       0       1       2
-       1       0       1       0       0       0       0       1       1       1
-       2       1       0       1       1       0       0       1       2       0
-       0       1       1       1       0       0       1       0       0       2
-       0       0       0       1       1       1       0       2       0       1
-       0       0       0       0       1       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       1       0       1       1       1       0       1
-       0       0       1       0       1       0       1       2       1       0
-       2       0       0       1       1       2       0       0       0       0
-       0       0       1       1       2       2       1       1       3       0
-       0       2       0       1       1       2       1       1       1       1
-       0       0       0       0       0       0       1       2       2       1
-       0       0       1       3       2       1       1       0       2       1
-       0       2       1       1       0       0       0       0       0       0
-       1       1       0       1       0       2       0       1       0       1
-       0       2       2       2       0       1       0       3       2       3
-       1       2       1       0       1       0       0       1       1       0
-       0       1       1       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       2
-       0       2       0       0       0       0       3       3       1       0
-       1       1       4       3       3       3       2       6       3       5
-       5       1       3       5       5       4       4       9       3       1
-       6       6       3       6       5       5       4       2       3       5
-       3       2       3       2       9       7       7       8       3       4
-      10       2       6       5       6       1       4       5       5       6
-       0       4       4       8       5       5       9       3       5       3
-       6       7       3       1       2       3       2       6       7       4
-       2       3       3       3       3       3       7       4       1       3
-       1       6       5       3       2       2       6       5       3       3
-       3       2       0       2       2       2       0       0       2       0
-       1       0       0       0       0       0       0       0       0       0
-       0       1       3       1       2       5       3       3       1       2
-       1       2       4       3       0       6       2       1       1       3
-       3       2       2       2       1       1       2       2       1       3
-       3       5       3       2       4       2       5       1       4       6
-       2       4       2       3       2       2       1       2       3       2
-       2       0       5       5       2       3       1       3       2       2
-       3       3       3       4       3       1       6       5       4       5
-       2       3       2       3       7       2       4       3       3       1
-       2       5       3       3       2       5       4       4       4       0
-       4       0       2       4       2       1       2       1       3       3
-       1       4       2       1       5       1       2       1       1       0
-       2       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       1       1       1       2       5       4
-       3       2       1       2       3       4       2       5       2       0
-       3       3       2       2       2       3       0       4       0       3
-       2       5       3       1       1       4       3       3       4       4
-       5       3       2       5       2       1       4       0       3       5
-       3       1       0       2       2       1       3       1       2       5
-       2       4       4       3       3       1       2       5       2       1
-       3       2       3       1       2       3       4       2       2       2
-       1       1       2       3       1       2       2       1       5       6
-       4       2       3       1       3       2       1       3       1       4
-       2       3       0       1       3       2       2       5       1       1
-       1       3       0       0       0       1       0       0       0       0
-       0       0       0       0       0       0       0       1       1       3
-       3       3       1       3       1       3       2       4       2       1
-       3       2       2       1       5       1       3       2       0       2
-       1       3       3       1       3       1       3       2       3       3
-       2       1       2       2       4       1       3       0       1       1
-       1       1       1       3       2       2       2       1       2       4
-       0       1       0       3       0       1       1       3       5       2
-       2       3       4       4       2       3       1       3       2       4
-       2       3       3       3       1       1       4       2       5       0
-       1       2       0       2       2       1       3       1       3       2
-       5       2       1       0       1       2       3       3       1       2
-       2       2       1       1       0       1       1       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       1       1       2       1       2       2       0       2
-       0       4       2       2       2       3       3       1       0       0
-       2       4       2       3       0       1       4       1       1       0
-       2       3       1       1       0       4       2       2       5       4
-       1       2       1       1       1       2       3       2       2       0
-       5       0       2       3       0       1       0       1       2       4
-       2       4       0       4       3       3       1       3       1       3
-       3       2       0       2       3       2       2       2       2       0
-       1       2       2       1       1       3       2       2       3       1
-       1       2       2       2       2       1       3       3       2       1
-       1       0       0       2       1       5       0       4       1       2
-       0       2       0       0       0       0       0       0       0       0
-       0       0       0       0       0       2       1       1       1       0
-       1       5       3       1       0       2       1       3       2       1
-       0       3       1       1       1       0       1       1       1       6
-       1       1       0       3       2       2       1       1       3       0
-       3       2       4       1       0       3       1       3       1       0
-       1       2       1       0       4       3       3       1       2       4
-       0       1       0       0       1       2       1       1       2       3
-       6       4       3       2       3       1       0       1       1       3
-       2       2       1       0       2       3       1       1       3       1
-       0       1       2       4       1       6       1       0       0       1
-       1       3       2       6       2       3       4       2       0       2
-       3       3       3       0       1       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       3       3       2       1       1       0       2
-       2       1       3       1       3       0       0       0       4       1
-       2       2       1       3       2       0       2       4       2       3
-       1       1       1       1       4       4       1       1       3       2
-       3       1       0       2       3       0       2       1       0       0
-       1       1       2       4       1       1       4       0       2       0
-       2       2       2       1       1       1       1       6       3       4
-       0       0       1       1       2       3       0       0       2       1
-       4       2       1       3       0       4       2       1       2       1
-       2       2       1       3       1       1       2       1       2       1
-       3       1       1       1       1       2       3       0       0       1
-       0       0       0       0       0       0       0       0       0       0
-       0       1       2       1       1       0       2       2       2       3
-       3       1       3       0       2       1       1       0       1       1
-       1       2       2       4       3       2       2       2       2       0
-       2       1       4       3       5       0       1       3       0       3
-       0       3       0       1       2       1       0       1       1       1
-       0       2       3       1       3       1       3       2       0       2
-       2       0       4       1       1       2       1       1       1       2
-       2       1       1       0       1       0       0       4       0       0
-       0       1       1       3       0       1       2       1       3       2
-       2       3       1       1       4       1       0       3       0       3
-       3       4       2       0       2       1       0       1       1       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       1       0       1       0       1       0       4       1       2
-       2       2       0       5       1       2       2       1       1       1
-       1       1       1       2       2       1       1       1       0       2
-       0       0       1       1       0       3       2       1       3       2
-       1       1       2       3       1       3       1       1       2       2
-       0       1       1       1       0       2       1       0       1       2
-       1       2       2       3       1       2       1       3       1       1
-       1       2       1       3       2       1       2       3       2       1
-       1       2       0       2       3       0       2       1       3       1
-       1       1       2       3       1       1       2       1       2       2
-       2       4       3       2       0       1       3       2       0       2
-       1       0       0       0       0       0       0       0       0       0
-       0       0       0       1       2       1       0       1       2       3
-       0       2       2       0       1       3       1       1       1       2
-       0       1       2       1       2       5       1       1       0       1
-       0       0       1       2       2       2       3       1       4       4
-       0       0       1       0       1       3       4       1       0       5
-       1       1       3       1       4       0       0       3       1       1
-       3       0       2       1       1       5       0       2       2       2
-       2       2       2       0       1       0       0       0       2       2
-       3       1       0       0       3       1       3       1       2       1
-       0       1       1       1       2       1       1       1       2       2
-       1       2       2       3       2       0       1       0       0       0
-       2       1       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       1
-       2       1       0       2       2       1       3       2       3       0
-       1       0       1       1       3       1       0       0       3       4
-       0       2       2       3       2       0       1       1       1       2
-       0       1       3       0       2       2       2       1       0       4
-       1       3       1       1       1       0       1       3       1       3
-       0       1       1       1       1       4       5       2       2       3
-       0       1       1       0       0       0       1       1       2       0
-       3       2       0       0       1       2       0       2       0       2
-       1       0       3       3       4       2       1       0       0       1
-       2       1       0       1       0       1       0       1       1       4
-       1       1       2       1       2       0       1       2       1       0
-       0       0       0       0       0       0       0       0       0       0
-       1       0       0       2       0       0       1       0       0       0
-       2       1       1       1       2       2       4       2       0       2
-       1       0       2       1       2       1       1       0       0       0
-       1       3       1       0       4       1       0       0       0       1
-       2       0       1       1       2       0       0       3       0       2
-       0       0       1       0       3       2       2       0       0       3
-       1       4       1       1       1       0       0       2       1       1
-       1       4       3       2       1       2       5       2       1       0
-       0       2       0       2       0       2       1       1       2       3
-       1       4       1       3       1       3       2       4       1       1
-       1       1       2       2       3       1       1       0       0       0
-       1       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       1       2       0       1
-       0       0       4       2       0       2       1       3       0       0
-       2       2       1       1       0       1       4       0       1       1
-       2       1       1       2       4       3       3       1       1       2
-       2       3       1       3       3       2       3       1       1       2
-       0       2       1       2       2       2       2       0       3       2
-       1       5       1       4       4       1       1       2       2       4
-       0       1       1       1       2       1       1       0       2       2
-       5       3       0       0       1       3       0       3       1       1
-       3       1       0       1       0       2       3       0       0       0
-       1       0       0       0       0       0       0       0       3       4
-       1       1       0       1       1       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       3       2       1       1       0       3       2       0       1       0
-       1       2       2       2       1       0       1       1       1       2
-       3       2       1       2       2       3       2       2       2       1
-       1       0       1       0       2       1       0       1       2       1
-       2       1       0       1       1       0       3       1       1       3
-       1       1       2       1       1       3       0       0       0       0
-       0       0       2       1       0       2       0       3       0       2
-       0       0       0       0       1       1       1       1       3       1
-       2       0       1       1       0       1       2       2       2       5
-       2       3       0       2       2       3       1       0       0       2
-       1       0       2       1       0       2       0       1       1       2
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       1       1
-       0       0       1       1       0       3       1       0       1       2
-       2       0       0       3       1       3       1       2       1       0
-       1       3       2       1       0       1       2       1       0       1
-       3       2       1       2       3       0       1       0       1       2
-       0       1       2       0       1       0       1       1       0       1
-       1       0       2       1       1       3       3       1       4       2
-       2       0       1       3       4       3       0       0       0       0
-       0       1       0       0       0       2       0       1       1       2
-       2       1       2       2       0       0       1       1       3       0
-       3       2       3       1       0       3       2       1       0       1
-       0       0       2       1       3       1       1       1       0       0
-       0       0       0       0       0       0       0       0       0       0
-       2       0       2       0       0       2       4       0       1       1
-       1       1       1       3       2       1       0       1       0       1
-       0       0       0       0       1       1       1       0       1       0
-       0       0       3       1       0       2       0       1       2       1
-       1       1       0       3       2       0       0       1       2       0
-       0       1       0       0       1       2       1       1       0       0
-       1       1       0       0       0       1       2       1       0       0
-       3       1       1       1       2       1       1       1       1       3
-       1       2       0       1       1       2       0       1       1       0
-       2       2       1       0       2       2       1       2       1       1
-       2       1       1       3       5       0       0       1       0       1
-       0       1       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       1       1       1       1       0       0       0       1       0
-       1       1       0       0       2       0       1       2       1       1
-       1       1       1       3       0       2       1       0       2       0
-       0       2       1       0       3       0       0       3       0       2
-       2       2       1       3       2       1       1       5       2       1
-       2       4       1       1       1       2       2       2       0       1
-       1       0       2       1       0       1       0       0       0       2
-       1       0       4       2       3       0       1       1       0       2
-       1       2       1       2       1       1       2       2       2       0
-       0       2       1       1       1       1       0       1       0       2
-       0       2       0       0       0       2       1       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       1       1       0       1       1       1       1
-       1       2       1       2       0       3       2       2       3       0
-       1       0       1       0       1       1       1       1       2       0
-       2       0       2       1       1       2       1       1       0       1
-       2       3       1       1       1       1       2       1       0       1
-       2       1       0       1       0       4       0       0       2       1
-       4       0       0       0       0       0       0       2       1       0
-       2       0       2       4       1       0       2       1       4       0
-       1       2       1       0       1       1       1       2       2       2
-       3       1       1       0       1       2       1       0       3       2
-       0       0       3       3       2       1       0       1       2       1
-       0       0       0       1       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       1       0       0       1       1       2       1       0       0
-       1       1       0       2       1       1       1       0       2       3
-       3       1       4       0       3       1       1       2       2       2
-       2       1       2       0       3       2       1       1       0       0
-       2       2       0       3       3       0       1       1       1       2
-       1       1       0       1       2       2       2       0       1       0
-       1       3       0       0       4       0       1       2       1       0
-       1       0       1       0       0       0       2       1       3       1
-       1       4       2       0       0       0       2       5       0       2
-       1       1       1       0       2       2       1       2       5       0
-       1       2       1       2       0       0       0       1       0       2
-       1       1       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       1       1       3
-       0       0       0       1       1       1       0       2       2       3
-       0       2       0       3       0       2       2       1       1       2
-       1       0       2       3       1       2       0       2       3       2
-       1       1       0       0       0       2       1       1       3       0
-       0       2       3       2       0       2       0       3       1       1
-       1       0       0       4       1       2       2       0       0       0
-       2       1       1       1       2       2       1       1       2       0
-       1       2       3       0       1       0       1       2       3       2
-       0       0       2       3       3       0       0       1       0       0
-       1       2       2       2       0       3       0       0       1       1
-       2       3       2       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       1       1       1       0       2       2       1       0       0
-       3       0       1       0       3       2       0       2       2       1
-       0       4       0       1       1       1       1       1       0       0
-       0       0       0       2       4       2       2       0       1       1
-       0       1       0       2       2       0       0       1       1       1
-       1       1       0       1       1       2       1       0       0       1
-       1       3       2       0       2       0       2       1       2       1
-       2       0       3       1       2       0       1       0       1       0
-       2       0       1       1       0       0       2       0       2       0
-       1       2       0       0       1       0       1       1       0       2
-       2       3       0       1       0       0       1       2       2       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       2       1       1
-       0       2       1       0       1       0       3       0       0       0
-       1       0       0       1       0       1       0       0       1       3
-       0       2       0       0       0       1       0       2       0       3
-       2       2       1       0       2       2       2       0       2       0
-       2       1       2       1       0       2       0       1       3       1
-       2       0       0       1       1       1       2       1       0       0
-       1       1       1       0       1       2       1       0       2       0
-       0       1       0       2       1       3       1       2       0       3
-       0       2       2       0       0       1       1       1       1       1
-       0       0       1       1       1       1       1       3       0       0
-       0       0       0       2       1       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       1
-       0       2       2       0       2       0       2       0       0       0
-       1       1       1       1       1       1       1       1       4       0
-       1       1       2       1       0       1       3       1       0       0
-       0       0       1       0       1       2       0       1       0       5
-       1       0       1       1       3       0       2       0       0       0
-       0       3       2       1       2       2       2       0       0       0
-       1       0       2       3       2       0       2       1       1       0
-       3       2       0       1       0       0       1       1       2       0
-       1       1       1       1       0       0       2       3       0       2
-       0       0       2       1       3       2       5       1       1       0
-       1       0       2       0       1       1       0       0       1       1
-       0       0       0       0       0       0       0       0       0       1
-       0       2       0       0       0       0       0       0       1       1
-       1       0       1       0       3       0       1       1       1       0
-       1       1       1       1       0       0       2       0       0       2
-       0       3       0       0       1       2       0       0       2       3
-       2       1       0       0       0       0       1       0       0       4
-       2       0       0       1       0       3       1       3       0       0
-       1       0       2       1       0       1       0       0       0       0
-       2       1       2       0       0       0       1       2       0       1
-       1       1       1       1       1       0       0       1       0       2
-       0       0       4       4       1       3       0       1       1       2
-       1       0       1       1       3       1       1       0       1       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       1       0       0       1       0       2       2       3       1       1
-       1       1       1       2       1       1       1       1       1       1
-       0       0       2       0       0       0       0       0       1       3
-       1       0       2       2       2       3       0       1       1       1
-       0       0       0       2       2       2       5       0       2       1
-       0       2       1       2       2       3       0       2       1       2
-       0       3       2       0       1       1       1       0       1       1
-       1       3       2       1       4       0       2       0       2       1
-       1       0       1       1       2       1       1       0       0       2
-       3       1       1       3       2       1       2       0       1       0
-       2       2       1       1       0       0       1       0       2       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       1       0       0       0       0       1       1
-       2       1       1       0       2       0       0       2       0       1
-       0       1       1       0       0       1       0       0       0       1
-       2       1       0       1       2       1       0       1       0       2
-       1       0       1       0       3       0       1       0       2       1
-       1       1       4       2       1       0       0       2       0       4
-       4       1       0       3       0       0       2       3       1       0
-       5       0       0       3       0       3       1       2       3       1
-       0       2       2       2       0       1       1       0       1       0
-       2       0       2       2       1       1       0       3       1       0
-       0       0       0       5       0       1       1       1       1       1
-       1       3       0       1       0       2       0       0       1       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       2       0
-       0       0       1       0       1       1       2       1       1       3
-       0       0       2       2       1       2       0       0       4       2
-       1       1       0       1       0       2       2       0       0       1
-       1       1       3       2       1       2       2       0       1       0
-       1       2       1       1       1       3       2       0       1       2
-       0       1       0       2       1       0       2       0       0       1
-       2       1       0       0       0       0       1       2       0       2
-       1       2       3       2       0       2       1       0       2       1
-       2       0       0       0       0       2       1       2       2       0
-       0       0       0       1       2       1       2       0       2       3
-       0       0       0       0       1       0       2       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       2       1       2       0       1       3       0       0
-       0       0       1       1       1       1       2       1       2       0
-       2       1       0       1       1       1       0       0       1       0
-       2       0       1       2       1       0       2       1       0       1
-       1       1       0       0       1       3       3       0       1       3
-       1       1       1       4       5       0       3       1       1       3
-       0       1       1       3       1       0       1       3       0       2
-       0       0       2       0       1       1       2       2       1       1
-       1       2       1       0       1       2       1       1       1       0
-       1       1       1       0       2       2       4       0       0       2
-       2       0       2       1       0       1       1       3       2       2
-       0       1       0       1       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       1       0       0       0       1       0       2       3       2       1
-       1       0       2       3       1       2       1       3       2       1
-       0       3       2       2       0       0       0       1       1       1
-       0       0       1       1       0       2       0       0       2       2
-       3       1       1       0       0       2       0       0       1       3
-       0       4       1       3       2       1       1       2       0       0
-       2       3       3       2       1       2       1       1       1       1
-       0       1       0       1       0       2       1       0       0       1
-       0       1       0       0       2       1       1       0       2       0
-       2       0       1       0       0       0       0       1       1       0
-       2       1       1       0       0       1       1       0       1       0
-       0       3       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       1       0       0       1
-       2       2       1       2       2       0       1       0       0       0
-       4       2       2       2       1       1       1       1       1       1
-       3       1       1       0       1       3       2       2       0       1
-       4       4       2       3       1       2       4       1       2       2
-       3       2       2       2       3       0       1       3       1       2
-       4       2       1       2       0       1       2       1       2       2
-       2       5       6       2       3       2       0       2       0       0
-       1       1       3       3       2       0       1       3       2       2
-       3       1       1       3       6       0       0       3       3       1
-       0       0       1       1       1       1       1       1       0       1
-       3       1       2       0       2       2       0       1       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       1       0       0
-       2       4      15       3      11       7      11      11       9       8
-       6      12      10       4      10       7      10       7      16      14
-       7       7       4       9       7      11       7       4       9       0
-       3       5       4       3       1       3       1       1       1       0
-       1       2       3       1       1       0       0       3       3       3
-       1       0       1       0       1       2       0       0       1       2
-       1       2       2       2       5       0       2       2       6       3
-       0       2       3       3       2       2       5       3       3       5
-       3       4       0       3       3       5       5       7       6       4
-       4       5       2       5       7       6       6       8       5       7
-       5       7       7       6      11       5       5       0       1       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       1       0       0       3       1       1       1       0
-       0       1       5       1       2       0       0       0       1       0
-       0       2       2       0       1       1       1       2       1       3
-       0       0       2       0       0       1       2       0       2       0
-       1       1       0       3       1       2       1       4       0       1
-       1       2       2       2       0       1       0       1       0       3
-       1       1       2       0       1       0       0       2       1       0
-       3       0       1       1       1       1       1       2       1       1
-       1       0       1       0       0       1       1       0       0       0
-       4       1       1       0       3       0       1       1       1       3
-       0       0       1       3       0       0       3       1       2       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       1       0       0       0       0       1       0       4       1
-       1       0       0       1       4       1       1       0       0       3
-       0       0       1       2       2       2       2       2       1       0
-       0       1       0       1       0       2       0       0       2       2
-       0       0       1       3       0       2       4       0       0       2
-       0       0       2       1       2       0       2       0       1       0
-       0       3       0       1       0       2       1       1       2       0
-       0       0       1       0       1       0       2       0       0       0
-       0       0       1       0       1       1       1       0       1       0
-       0       0       2       0       0       3       1       1       0       1
-       0       2       2       2       2       1       2       2       0       1
-       2       0       1       2       1       0       1       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       2       3       2       0       2       0       2       4       1
-       2       3       0       2       2       0       1       1       2       0
-       0       2       1       0       4       0       1       0       1       1
-       0       1       0       1       0       0       0       0       3       1
-       2       1       0       0       0       0       3       3       0       1
-       0       1       1       2       0       1       0       1       1       0
-       0       1       2       2       2       1       0       3       0       0
-       0       2       2       0       2       0       3       1       1       1
-       2       1       0       1       1       1       1       1       0       1
-       0       0       1       1       0       1       0       1       2       0
-       0       2       0       0       0       0       0       0       0       0
-       3       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       1       0       0       0
-       0       1       0       1       2       2       0       1       0       1
-       2       1       1       0       1       2       1       2       1       2
-       0       0       0       1       0       1       1       2       1       1
-       3       3       1       2       2       0       1       1       0       1
-       1       0       2       3       1       2       2       0       0       0
-       2       1       0       0       0       0       0       1       1       1
-       1       2       1       0       2       2       3       1       2       1
-       0       4       1       2       1       1       0       1       1       1
-       0       0       3       2       0       0       1       0       1       3
-       0       2       1       1       1       1       1       1       1       0
-       2       0       2       2       0       0       0       0       3       1
-       1       0       0       0       0       0       0       0       0       0
-       0       0       1       1       1       3       1       0       3       2
-       4       0       3       1       2       2       0       2       1       0
-       1       1       3       1       1       2       1       1       2       3
-       1       1       0       0       0       2       2       2       1       4
-       1       0       1       0       0       1       1       0       0       1
-       2       0       0       3       2       1       0       0       1       0
-       3       0       1       2       2       0       0       0       0       1
-       1       1       3       0       1       0       0       2       1       3
-       1       2       0       2       0       1       0       0       0       1
-       1       3       0       0       0       0       0       1       1       1
-       0       0       0       0       1       2       2       0       0       1
-       1       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       1       0
-       1       1       2       0       1       1       0       0       0       1
-       0       0       2       1       1       0       1       2       0       0
-       0       0       0       0       0       0       0       1       1       1
-       3       2       0       1       1       1       3       2       0       2
-       0       0       1       0       1       1       3       0       2       1
-       1       2       1       1       0       1       1       1       1       2
-       4       0       2       0       3       0       1       1       1       2
-       2       1       1       0       0       1       0       2       0       1
-       1       0       1       1       0       4       2       2       1       2
-       2       0       0       0       1       0       1       0       1       1
-       0       0       1       1       1       1       2       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       1       0       2       0       1       0       0       0       0       0
-       1       0       1       0       1       0       2       2       3       0
-       0       1       2       0       1       1       0       1       0       1
-       0       1       2       1       0       3       2       3       3       1
-       0       1       0       1       1       1       0       2       0       2
-       0       1       0       0       1       2       2       0       0       1
-       0       1       0       0       2       2       1       1       1       1
-       0       1       1       1       1       4       1       2       3       0
-       1       2       2       1       1       2       1       0       3       1
-       1       0       1       2       1       0       2       1       1       1
-       1       0       0       1       0       0       1       0       1       1
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       1       0       1       2       0       0
-       1       0       1       4       1       1       4       1       1       2
-       0       1       1       2       1       0       0       0       0       1
-       1       1       0       1       1       1       0       1       3       0
-       1       1       2       0       2       2       0       2       0       0
-       1       2       0       2       2       0       1       1       0       0
-       1       0       1       0       0       2       1       1       0       2
-       2       1       1       3       3       0       1       1       1       1
-       0       0       0       1       1       0       0       1       1       2
-       0       1       1       0       1       2       1       0       1       3
-       1       2       2       0       0       1       0       1       0       1
-       1       1       0       1       0       0       0       0       0       0
-       0       0       0       0       0       1       0       0       2       2
-       2       0       0       1       1       0       5       2       2       2
-       0       0       3       0       2       0       1       1       3       1
-       1       0       0       0       1       0       0       1       2       3
-       3       0       0       3       1       1       0       1       1       1
-       2       1       0       3       1       2       2       0       2       0
-       0       1       3       2       0       3       1       0       3       4
-       0       3       1       2       2       2       3       3       1       1
-       0       4       2       1       1       0       3       3       0       0
-       1       2       2       2       0       1       2       3       3       2
-       1       1       0       1       2       4       1       0       1       1
-       0       0       1       1       3       1       2       1       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       1       0       0
-       1       2       0       3       3       1       1       0       1       1
-       0       0       0       1       0       0       2       1       0       0
-       0       0       3       2       1       2       2       2       1       1
-       2       1       0       1       0       1       0       0       0       3
-       1       1       1       0       1       1       0       0       0       3
-       2       1       0       3       0       1       1       1       2       1
-       0       1       2       2       1       0       0       2       2       1
-       3       2       0       1       0       0       0       1       1       0
-       2       1       0       1       1       0       2       0       0       0
-       2       0       2       0       0       1       3       0       0       0
-       0       0       0       0       0       0       0       0       1       1
-       1       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       1       0       2
-       0       0       1       1       2       2       1       1       1       1
-       1       0       1       0       0       1       0       0       0       1
-       0       0       2       0       1       1       1       1       1       1
-       1       0       0       2       2       0       1       0       4       1
-       2       0       3       0       0       2       1       2       1       1
-       0       2       0       0       4       0       2       1       0       0
-       1       1       1       1       2       3       2       0       3       0
-       1       1       4       3       1       0       1       0       0       2
-       2       1       1       1       0       2       0       0       2       1
-       0       2       0       2       3       3       0       0       1       2
-       3       0       2       1       1       1       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       2       1       0       1       2       0       2       0       0
-       0       0       1       3       0       0       2       1       2       0
-       0       2       0       2       1       1       1       1       2       1
-       0       0       0       0       3       0       1       0       0       0
-       0       2       0       2       1       1       3       1       1       1
-       1       1       0       2       1       0       0       0       1       2
-       0       0       2       0       0       1       1       1       0       1
-       0       1       0       0       1       0       1       1       0       1
-       0       2       0       3       2       3       0       3       1       0
-       0       1       2       3       1       0       0       1       0       0
-       2       2       1       0       2       2       1       1       0       1
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       1       0       1       1       0       1       1
-       1       1       0       0       0       0       2       2       1       0
-       0       0       0       1       2       1       2       0       2       1
-       3       0       1       0       0       1       0       3       3       0
-       1       1       2       0       2       2       1       0       3       0
-       1       1       0       1       2       1       2       4       0       2
-       2       2       1       2       0       1       0       3       0       2
-       2       2       2       0       3       2       2       1       2       1
-       1       3       1       3       2       0       2       5       2       0
-       0       0       1       1       0       2       1       0       1       1
-       1       0       1       2       0       1       2       2       0       0
-       2       0       1       1       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       2       1       1       0       4       1       2       0       1
-       2       1       1       0       0       0       2       1       0       1
-       0       0       1       2       0       0       0       0       2       2
-       1       0       0       1       2       2       0       1       1       0
-       1       1       0       0       0       1       2       1       0       0
-       1       2       1       1       4       3       0       1       2       1
-       1       2       3       1       1       4       1       1       1       1
-       0       0       1       0       0       1       1       2       0       2
-       2       0       0       1       1       1       0       0       2       0
-       0       1       0       1       3       1       0       2       3       2
-       0       0       1       0       0       2       0       0       1       0
-       1       2       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       2       0       3       0
-       2       0       0       1       3       2       1       1       1       2
-       1       0       1       0       0       2       0       2       0       0
-       0       1       3       1       1       2       1       0       1       1
-       0       5       1       6       2       1       1       2       0       2
-       0       1       0       0       3       0       0       2       0       2
-       1       0       2       0       0       0       2       3       1       0
-       0       1       1       1       0       0       0       0       1       0
-       0       0       1       1       1       1       0       1       1       0
-       0       0       2       1       0       1       0       1       0       4
-       2       0       1       1       0       1       1       1       1       0
-       1       0       1       0       1       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       1       0       0       0       0       0       1
-       0       0       0       3       3       1       0       1       1       0
-       2       2       0       5       0       3       1       0       0       2
-       1       1       2       0       1       1       0       0       0       1
-       0       1       2       1       4       0       2       1       1       1
-       0       1       0       3       2       1       0       2       2       0
-       1       1       0       0       1       1       1       1       0       2
-       2       1       0       0       0       0       0       0       1       1
-       0       0       2       1       0       1       1       3       1       2
-       1       1       0       1       1       3       1       0       0       2
-       0       1       0       2       1       0       0       0       1       1
-       0       1       1       1       3       0       1       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       1       3       2       0       0       0       0       0       1
-       1       1       0       2       2       2       0       1       0       2
-       0       1       1       0       1       2       1       0       0       1
-       0       1       1       0       0       1       0       1       2       0
-       0       1       0       0       0       0       1       0       3       1
-       0       0       1       0       0       1       1       0       2       2
-       1       0       1       1       0       1       1       0       3       2
-       2       0       1       0       0       1       1       2       0       1
-       0       1       3       0       0       1       0       1       2       1
-       0       2       1       1       0       2       1       0       0       1
-       1       1       1       0       2       2       1       2       1       2
-       2       0       2       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       1       0
-       1       1       0       0       0       0       1       0       0       2
-       1       0       0       0       0       2       1       0       0       0
-       1       1       1       1       1       0       1       0       2       2
-       2       0       1       0       0       1       1       1       0       0
-       0       3       1       0       1       0       0       1       1       2
-       0       0       0       1       0       1       0       0       2       0
-       0       0       2       0       1       0       0       0       2       0
-       1       1       0       2       0       1       0       1       0       2
-       1       1       1       0       0       1       1       0       0       0
-       0       0       2       0       2       4       0       0       0       1
-       0       0       0       0       1       0       0       0       0       0
-       0       1       0       0       0       0       0       0       0       0
-       0       0       0       0       0       1       0       0       2       0
-       3       1       0       0       1       0       2       0       0       0
-       0       3       2       0       0       0       0       0       2       0
-       0       0       0       2       1       0       1       1       1       2
-       1       1       0       0       2       1       2       0       2       1
-       0       2       2       0       1       0       1       1       1       0
-       0       2       1       2       1       3       2       2       2       3
-       0       1       1       0       0       0       2       0       0       1
-       1       2       2       1       0       0       1       1       0       0
-       2       1       2       0       1       0       0       1       0       0
-       0       1       1       2       1       1       1       1       2       1
-       0       2       2       1       0       0       1       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       1       0       0       0       0       0       0       1       0
-       1       2       2       0       2       1       2       1       0       2
-       2       0       2       1       1       2       2       0       1       0
-       0       0       1       1       1       0       0       2       0       1
-       3       0       1       1       0       2       2       1       3       1
-       0       3       1       1       0       1       1       1       1       0
-       0       0       0       1       1       0       1       1       0       3
-       3       1       3       0       1       1       1       0       0       1
-       3       0       0       1       2       1       0       3       3       1
-       0       3       0       3       1       0       3       2       2       0
-       0       2       2       1       2       2       0       0       1       0
-       0       1       0       0       2       1       0       1       1       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       1       0       0       1       1
-       0       1       1       0       1       0       0       1       0       1
-       2       0       0       1       2       1       0       1       0       1
-       0       0       0       0       0       1       0       0       1       0
-       1       0       0       1       0       1       0       1       1       1
-       0       0       1       0       2       0       1       0       0       2
-       2       0       0       0       1       1       0       0       0       1
-       0       1       1       1       1       1       1       1       1       1
-       3       0       0       1       0       0       0       2       2       0
-       1       1       1       2       1       1       2       2       3       0
-       0       1       1       0       0       1       1       1       2       4
-       1       0       1       0       3       0       1       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       3       0       3       1       2       2       0       1
-       2       0       4       4       1       2       1       0       1       1
-       1       2       2       1       2       1       3       2       1       1
-       1       0       1       3       6       1       3       1       2       2
-       3       1       3       1       3       1       2       4       4       0
-       3       3       1       1       0       5       2       2       2       1
-       3       1       1       1       0       3       3       0       1       4
-       2       1       2       4       1       2       0       1       1       0
-       1       0       5       1       0       2       1       2       4       2
-       2       1       1       0       7       2       2       1       1       1
-       1       0       1       2       1       1       0       3       1       1
-       2       0       1       0       0       0       0       0       0       0
-       0       0       0       1       1       2       0       0       1       0
-       0       1       0       0       0       2       3       1       0       2
-       1       3       0       0       0       1       0       0       1       2
-       0       0       1       0       1       1       0       2       0       0
-       0       2       1       2       0       0       0       1       2       2
-       0       2       1       2       1       2       0       1       1       1
-       0       0       1       2       1       1       1       0       1       0
-       0       0       0       0       0       1       2       0       3       0
-       0       1       0       1       1       1       2       3       0       0
-       0       1       0       0       4       1       2       2       0       2
-       1       0       0       0       0       0       1       1       0       0
-       1       1       1       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       1       0       1       1       1       2       0       0       1       2
-       1       2       2       1       1       0       0       1       2       1
-       2       1       1       1       3       1       0       0       2       0
-       0       0       3       1       1       1       3       0       0       2
-       0       1       1       0       1       2       0       0       0       1
-       0       0       0       1       0       0       0       0       1       0
-       1       1       2       1       1       1       1       2       1       1
-       0       1       0       1       0       1       0       0       0       0
-       2       0       2       1       0       0       1       1       3       1
-       0       0       0       0       1       1       0       2       1       0
-       0       0       0       0       0       0       1       0       2       0
-       1       1       0       0       0       0       0       0       0       0
-       0       0       0       0       0       1       0       0       1       1
-       1       0       1       2       0       1       1       2       2       1
-       1       0       1       2       1       0       1       1       0       1
-       0       0       1       0       1       1       0       1       1       2
-       1       2       0       1       2       1       1       3       1       1
-       2       1       0       1       0       0       1       1       0       1
-       0       0       0       0       2       1       0       0       1       2
-       1       2       0       3       0       2       1       2       0       0
-       2       0       1       0       0       1       0       1       2       1
-       1       0       0       4       1       2       3       1       3       0
-       1       0       0       1       1       2       0       1       1       1
-       0       0       1       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       2       1       0       1
-       2       1       1       1       3       1       0       0       0       1
-       0       0       0       2       0       0       5       0       1       2
-       2       0       0       0       0       1       2       1       1       1
-       0       1       1       0       1       2       0       0       0       0
-       2       1       0       1       1       1       1       0       1       0
-       0       2       0       2       0       2       2       0       0       0
-       0       0       0       0       2       1       2       1       1       3
-       0       2       0       1       0       1       1       0       0       2
-       2       0       1       1       1       0       0       1       0       1
-       1       1       0       0       0       0       1       1       0       0
-       0       1       1       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       2
-       1       0       1       1       1       0       3       1       0       0
-       1       2       1       1       0       0       3       0       0       1
-       0       0       0       1       3       1       2       1       0       0
-       2       0       0       1       0       0       3       0       1       0
-       0       2       1       0       2       2       1       1       0       1
-       0       1       0       4       0       1       3       2       3       1
-       0       1       1       2       1       0       1       0       0       2
-       4       1       0       2       2       1       2       1       0       0
-       2       2       1       2       0       3       4       0       2       1
-       1       0       1       1       1       0       0       1       0       0
-       1       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       1       0       0       0       0       0       3       0       0
-       0       0       3       0       0       2       1       0       0       1
-       1       1       0       0       0       0       0       2       1       0
-       1       1       1       1       2       2       1       2       0       1
-       1       1       0       0       0       0       0       2       0       0
-       0       0       0       0       0       2       0       1       2       1
-       0       2       1       3       1       1       0       0       2       1
-       1       0       2       1       2       1       2       0       0       0
-       0       0       0       0       1       1       2       0       1       1
-       1       0       0       1       1       2       1       3       1       1
-       1       0       0       0       0       1       1       1       0       3
-       1       2       1       2       1       0       0       0       0       0
-       0       0       0       0       0       0       0       2       0       0
-       0       1       0       2       1       0       2       1       0       0
-       0       0       0       1       1       1       0       1       3       1
-       1       0       0       2       1       2       1       0       1       1
-       0       0       0       1       4       0       0       1       1       1
-       1       0       1       0       0       1       1       1       0       1
-       0       1       1       0       2       1       0       0       0       0
-       0       0       1       0       1       0       1       0       0       1
-       2       0       0       0       0       1       3       1       1       0
-       1       0       1       0       1       1       0       0       0       0
-       1       0       0       1       0       1       0       2       0       0
-       0       0       0       1       1       0       2       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       1       0       0       1       1       2       0       2       0       0
-       1       1       0       2       1       0       2       1       0       1
-       0       2       1       1       1       2       0       1       1       0
-       1       0       1       1       0       0       2       0       0       1
-       0       0       0       0       0       0       0       0       2       1
-       1       1       0       0       0       3       2       0       2       0
-       0       0       0       2       1       0       0       2       0       0
-       0       1       0       0       2       2       0       2       1       2
-       1       0       3       1       0       0       0       0       0       1
-       3       2       0       0       2       1       0       0       0       0
-       2       1       0       1       0       2       2       1       1       1
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       1       1       0       2
-       0       0       0       1       1       0       2       1       1       2
-       1       0       1       0       0       0       1       0       0       1
-       0       1       0       0       3       1       1       1       1       1
-       0       3       0       0       0       0       0       1       1       0
-       1       0       1       0       1       0       0       2       1       0
-       1       0       1       0       2       1       0       0       0       1
-       0       0       0       0       1       0       0       3       0       0
-       2       1       1       2       1       0       1       1       0       1
-       3       0       2       0       2       1       2       1       0       2
-       2       1       0       1       1       0       1       2       1       1
-       0       4       0       2       1       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       1       1       0       0       0       0
-       1       4       2       2       1       1       6       1       3       2
-       1       1       4       1       1       3       1       1       3       2
-       2       0       3       1       4       3       2       3       2       4
-       4       2       3       0       1       4       0       0       3       1
-       1       1       3       3       3       1       0       3       0       0
-       3       1       0       4       3       0       4       0       0       2
-       1       1       1       2       1       1       6       0       3       0
-       1       1       2       3       2       0       1       1       0       1
-       1       2       0       1       1       1       1       0       0       1
-       1       0       3       0       0       1       1       1       3       2
-       2       0       1       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       1       1       5
-       2       5       4       6       5       7       6       7       7      11
-       3       5       4       7       2       7       7       7      10       6
-       6       4       8       9       9       4       5       4       1       5
-      10       6       5       8      10       9       3       6       7       7
-      10       7       5       7      10       5       2       2      10       9
-       7       5       5       8       6       8       5      11       8       2
-       8       4       8       5       0       7       6       4       4       1
-       7       8       4       3       8       8       4       3       8       6
-       3       2       6       3       4       8       5       8       7      10
-       3       9       3       5      10       6       6       6       2       7
-       7       6       5       4       1       2       1       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       3       1       0       0       3       1       3
-       1       1       1       0       0       2       1       1       1       1
-       1       0       2       1       3       2       0       3       1       0
-       0       1       1       2       2       0       2       1       0       3
-       1       2       0       1       1       0       0       0       0       1
-       0       0       2       0       1       3       0       0       1       1
-       1       0       0       2       1       0       2       3       1       2
-       4       3       1       0       0       1       2       1       1       1
-       1       1       0       1       0       0       0       4       0       0
-       0       0       0       0       1       0       4       1       1       1
-       0       2       2       2       0       0       0       0       0       2
-       0       2       0       0       0       0       0       0       0       0
-       0       0       0       1       0       0       0       1       0       1
-       0       0       0       1       1       1       0       2       1       1
-       2       1       1       1       3       2       0       1       0       2
-       0       0       1       0       0       2       2       0       1       1
-       1       1       0       0       0       0       1       1       2       1
-       1       0       0       0       1       1       1       0       0       1
-       3       1       1       1       0       0       2       1       0       1
-       0       0       0       0       0       1       1       1       1       2
-       0       1       1       2       1       1       1       0       0       0
-       2       0       1       1       3       0       0       1       1       1
-       2       0       3       2       1       2       0       0       1       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       1       1       0       1       4
-       0       0       0       2       1       0       1       0       0       3
-       3       1       1       1       0       2       2       4       0       0
-       1       2       1       0       1       0       0       2       0       1
-       2       1       0       1       1       0       0       0       2       1
-       2       1       0       0       0       1       0       1       2       1
-       1       0       0       2       0       1       1       2       3       0
-       1       0       1       1       0       0       2       4       2       2
-       1       1       0       0       1       0       1       2       1       2
-       1       0       1       0       0       2       0       3       1       2
-       1       2       0       0       1       0       1       0       0       1
-       1       0       1       1       0       0       0       0       0       0
-       0       0       0       0       0       0       0       1       0       0
-       0       3       1       1       0       0       2       0       1       0
-       1       0       0       2       1       0       1       0       0       1
-       0       1       0       0       1       0       1       0       2       2
-       2       1       1       1       0       0       3       2       0       0
-       2       1       2       1       2       0       1       0       1       1
-       1       1       1       3       0       2       0       1       0       1
-       1       0       0       0       1       0       2       1       1       0
-       1       1       0       1       3       0       1       2       1       0
-       0       0       2       1       1       0       2       2       1       1
-       0       0       0       0       1       1       3       0       1       1
-       1       0       1       1       1       1       1       1       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       1       0       0
-       4       0       1       1       0       0       1       1       1       0
-       1       0       0       0       0       0       1       0       2       1
-       1       0       3       1       0       0       0       1       1       0
-       2       2       1       0       2       1       1       0       2       1
-       0       1       0       2       0       1       0       0       2       1
-       2       0       1       1       1       0       0       1       0       1
-       1       2       1       0       1       3       0       0       1       0
-       2       1       0       0       0       0       0       1       0       0
-       1       0       0       1       3       0       1       1       3       0
-       2       0       2       0       1       1       1       0       0       1
-       2       0       2       2       2       0       1       1       0       0
-       0       0       0       0       0       0       0       1       1       1
-       1       3       3       0       1       3       0       5       3       0
-       3       1       4       0       2       4       2       2       4       0
-       1       2       1       2       3       3       0       1       5       2
-       1       6       3       3       3       5       3       3       2       2
-       0       2       3       0       3       0       3       1       5       0
-       1       4       0       4       0       4       4       2       2       3
-       2       2       3       2       1       4       0       4       1       2
-       6       1       0       1       3       0       0       0       3       3
-       0       2       1       3       3       1       0       2       2       2
-       4       2       1       1       2       2       3       3       2       1
-       2       1       1       3       1       2       0       0       0       0
-       1       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       1       0       0       2       0       1       3
-       1       0       0       0       0       0       0       1       1       0
-       1       3       2       0       1       2       1       1       0       0
-       3       1       1       0       1       1       1       0       1       1
-       0       1       1       0       2       3       0       1       0       1
-       2       2       0       2       1       0       0       1       0       2
-       1       0       0       1       3       2       1       0       1       0
-       0       0       0       0       0       1       1       1       2       1
-       1       0       1       1       0       1       0       0       3       0
-       0       0       0       1       1       1       0       2       1       0
-       0       2       3       1       2       4       0       0       0       0
-       0       0       1       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       2       0       2       0       1       0       2       1
-       1       0       0       0       1       0       0       1       0       1
-       0       0       1       2       0       0       1       0       0       0
-       0       1       1       2       1       2       0       1       2       0
-       2       0       0       0       1       0       0       0       2       2
-       0       1       2       1       0       0       3       3       0       1
-       0       0       1       1       0       0       1       0       1       2
-       0       2       0       0       2       0       2       1       0       1
-       0       1       1       1       0       1       2       0       2       2
-       0       0       1       0       1       0       2       3       1       1
-       1       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       1       0       0       0       2
-       4       1       0       1       0       0       1       2       1       1
-       1       0       1       0       1       0       0       3       3       1
-       2       1       2       2       1       1       1       1       1       4
-       0       0       1       1       0       1       0       1       0       0
-       1       1       1       0       0       1       0       1       0       0
-       0       2       0       2       0       1       1       1       0       1
-       1       1       1       0       2       1       3       0       1       2
-       2       0       1       0       1       1       1       0       0       1
-       1       1       1       0       1       0       0       2       0       1
-       1       1       1       0       0       1       0       1       1       0
-       0       0       0       0       1       2       0       1       0       0
-       0       0       0       0       0       0       0       0       0       2
-       0       1       1       0       0       2       0       3       1       0
-       1       1       1       0       0       3       0       1       2       1
-       0       0       1       3       0       2       1       5       0       0
-       0       1       1       1       2       1       0       0       0       0
-       4       0       1       1       1       0       4       0       0       0
-       1       2       0       0       2       0       1       0       0       0
-       1       1       0       0       4       2       0       0       3       0
-       0       2       2       2       0       0       0       0       0       0
-       3       1       1       2       2       0       0       1       1       0
-       1       1       1       1       3       0       0       1       0       1
-       1       1       0       1       1       1       0       0       1       2
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       1       0       0       1       1       1       0       0       0       2
-       0       1       1       0       0       0       2       2       1       0
-       2       2       1       1       0       2       0       0       2       1
-       1       1       1       0       0       1       0       0       0       0
-       0       1       0       0       0       0       0       0       0       1
-       1       0       1       0       2       0       1       1       2       2
-       3       0       1       0       1       0       0       0       1       1
-       1       1       2       1       0       0       1       1       0       0
-       0       2       3       0       1       1       0       2       0       1
-       1       0       0       2       1       0       1       3       1       0
-       0       2       1       2       1       0       0       2       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       1       1       2       1       0       0
-       1       0       1       4       1       1       1       0       1       1
-       1       1       2       0       1       0       1       2       2       0
-       0       2       0       2       0       1       0       1       0       1
-       0       0       0       0       1       2       0       2       0       1
-       6       1       2       0       0       0       0       0       0       1
-       0       1       1       0       1       1       1       2       0       1
-       0       5       1       1       0       2       0       0       2       3
-       1       0       1       1       1       1       0       0       2       0
-       2       2       0       0       0       0       0       2       2       0
-       1       0       1       1       1       0       1       1       0       2
-       0       1       0       1       3       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       2       1       2       2       0
-       0       2       1       1       0       2       2       3       3       2
-       3       0       0       1       2       3       1       3       1       3
-       1       0       1       1       1       0       4       0       0       2
-       1       1       3       2       2       1       1       0       0       0
-       1       2       0       1       0       1       1       3       3       4
-       1       1       1       1       1       4       0       4       2       5
-       0       1       0       1       0       3       2       5       2       1
-       0       2       0       0       1       1       4       1       0       0
-       2       1       2       0       2       2       2       2       1       3
-       1       2       4       0       2       2       0       2       0       2
-       1       2       1       1       2       5       4       3       2       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       2       0       1       0       0       1       2
-       2       1       1       0       0       0       1       0       2       1
-       1       0       2       0       1       1       0       1       1       0
-       2       1       2       1       3       0       0       1       0       0
-       0       0       1       0       1       1       1       2       0       0
-       3       1       0       0       0       1       0       0       1       1
-       0       1       3       0       1       2       0       1       3       1
-       1       0       1       2       0       1       0       3       0       2
-       1       1       0       2       2       0       1       1       0       0
-       1       1       1       0       2       1       1       0       1       2
-       3       0       2       2       1       0       1       0       0       0
-       0       1       0       0       1       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       1       0       1       0       0       0       1       3       0
-       0       2       1       2       0       1       0       0       0       1
-       1       0       0       0       1       0       1       0       2       0
-       2       0       0       1       0       2       0       3       1       0
-       1       0       2       0       1       1       0       0       0       1
-       0       1       1       1       0       0       1       0       0       1
-       1       0       0       0       2       3       0       0       0       1
-       0       0       0       0       0       1       3       1       0       1
-       1       0       0       1       1       1       0       0       0       2
-       0       0       2       0       0       0       0       1       1       1
-       0       1       0       1       0       2       2       0       2       2
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       1       0       2       4
-       2       1       1       0       2       2       1       1       0       0
-       0       0       1       0       0       0       0       0       1       0
-       1       1       0       1       0       0       1       0       0       0
-       0       0       1       0       1       1       0       2       0       1
-       1       2       1       1       1       0       0       0       0       0
-       0       0       1       0       3       0       1       0       0       2
-       1       1       1       1       0       0       0       1       0       1
-       0       1       2       1       1       0       2       1       0       0
-       0       2       2       4       0       0       1       1       0       0
-       2       1       4       0       1       4       0       1       0       0
-       0       1       0       0       2       0       2       1       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       1       0       1
-       0       0       1       1       1       1       1       1       0       0
-       3       1       1       1       1       3       1       0       0       2
-       1       1       0       3       2       1       1       0       1       0
-       1       0       1       0       1       3       1       0       0       0
-       1       0       2       0       0       0       4       1       0       0
-       1       4       0       0       3       1       2       2       2       1
-       1       0       2       1       2       0       1       2       2       0
-       0       0       0       0       2       2       2       1       0       1
-       1       0       0       0       1       1       2       2       1       2
-       1       0       0       1       4       1       2       2       0       1
-       0       1       0       2       0       1       0       0       1       0
-       0       0       0       0       0       0       0       0       0       0
-       0       1       0       1       1       0       0       1       1       0
-       0       2       1       0       1       0       1       0       1       1
-       2       2       2       1       1       3       2       0       1       0
-       0       2       1       0       0       1       3       0       0       2
-       3       0       1       0       0       0       2       0       1       2
-       1       1       1       3       1       2       2       0       0       0
-       1       0       0       1       2       2       0       0       0       1
-       0       1       2       0       0       0       1       0       0       0
-       0       2       1       1       0       0       1       0       1       2
-       0       1       1       0       0       1       0       0       0       0
-       2       0       1       1       2       2       1       0       1       1
-       1       1       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       1       0
-       2       1       1       1       1       0       1       1       1       1
-       0       0       0       2       2       2       2       0       1       1
-       1       0       0       2       0       0       0       1       1       0
-       2       0       0       0       0       2       2       1       0       0
-       1       1       1       1       2       1       0       1       2       0
-       0       0       3       1       0       0       0       0       2       1
-       0       0       0       1       0       1       0       1       1       1
-       2       2       1       1       0       1       1       1       0       0
-       2       1       1       0       1       0       0       0       3       0
-       1       1       1       0       0       0       1       1       0       1
-       1       0       0       1       0       1       0       1       0       0
-       0       0       0       0       0       0       0       0       1       2
-       2       0       2       0       2       6       2       0       1       5
-       2       1       1       1       1       1       0       2       1       0
-       0       1       0       0       1       1       1       2       2       2
-       1       0       0       0       1       4       3       0       1       1
-       0       0       0       1       0       0       1       1       0       1
-       0       0       1       1       0       2       2       0       2       1
-       2       0       4       3       1       2       2       1       0       2
-       1       3       1       1       2       1       6       0       2       1
-       1       0       0       0       1       1       2       0       3       2
-       2       0       1       0       1       2       0       3       0       3
-       2       3       3       1       2       1       1       0       0       1
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       2       2       0       0       0       1       0       0
-       2       1       0       0       1       0       1       1       1       3
-       0       0       2       0       1       3       0       1       1       1
-       1       0       0       1       1       0       1       1       1       3
-       0       0       1       2       1       1       1       3       2       0
-       0       1       1       1       1       2       1       1       0       0
-       4       0       1       1       0       0       3       0       1       1
-       3       1       0       2       1       0       2       1       1       2
-       1       3       4       4       0       1       1       2       2       1
-       0       0       0       1       2       2       2       1       1       0
-       1       0       0       1       1       0       1       0       1       0
-       1       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       1       1       3       0       0
-       2       1       2       0       0       1       1       0       1       1
-       0       0       1       1       0       1       0       1       1       0
-       2       1       1       0       2       0       0       0       0       2
-       1       0       1       1       0       0       1       1       0       1
-       0       2       2       0       0       1       1       1       1       0
-       1       0       0       0       1       0       0       2       0       0
-       0       0       0       1       0       1       2       0       0       2
-       0       0       3       0       0       1       0       2       1       0
-       0       3       0       4       0       0       0       4       2       0
-       0       0       0       0       2       0       2       2       0       3
-       2       3       0       0       1       2       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       1
-       0       1       1       0       0       1       0       2       0       1
-       2       1       2       0       1       0       1       0       0       0
-       1       1       2       3       2       2       0       1       3       0
-       0       0       3       0       0       0       3       0       3       0
-       0       2       1       1       1       1       1       0       1       0
-       0       1       1       1       0       0       0       1       1       0
-       0       0       3       2       2       0       0       2       2       2
-       0       1       1       3       0       3       0       0       0       1
-       1       0       2       0       1       0       2       0       1       2
-       0       0       0       1       2       1       0       0       1       1
-       0       1       1       2       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       1       0       1       0       0       0       1       1
-       2       0       1       0       0       1       0       1       1       0
-       1       1       0       1       0       1       0       0       0       2
-       0       0       2       3       1       1       0       0       1       3
-       1       0       2       0       3       0       0       0       1       1
-       2       1       3       1       2       1       2       3       0       3
-       0       0       0       1       0       0       2       0       0       0
-       0       1       0       4       1       2       0       1       4       2
-       0       1       1       2       0       2       0       1       0       3
-       2       1       0       1       1       1       1       1       1       1
-       1       1       2       0       1       2       0       1       1       0
-       0       1       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       1       4       0       1       3       1       0       0       0       1
-       1       0       0       1       0       0       0       1       0       0
-       0       1       0       0       1       0       1       3       2       3
-       1       2       1       1       0       1       2       0       0       1
-       1       1       0       2       1       0       0       2       0       0
-       0       0       0       0       0       1       0       0       2       1
-       0       2       0       1       2       0       1       0       0       1
-       1       0       1       0       0       1       0       1       0       2
-       0       0       1       2       1       1       0       2       2       1
-       1       1       0       1       1       1       2       2       1       2
-       1       2       2       1       1       0       1       0       0       0
-       0       0       0       0       0       0       1       1       0       2
-       0       0       1       0       3       1       0       2       0       1
-       0       1       0       0       1       1       1       2       0       1
-       3       1       0       0       1       1       1       2       1       0
-       0       0       3       2       0       1       0       0       0       0
-       0       1       0       0       0       0       1       0       0       0
-       2       1       0       1       1       0       0       1       0       2
-       0       2       1       0       5       2       1       1       2       1
-       1       2       0       0       0       0       2       1       0       0
-       3       2       1       0       0       0       1       2       1       0
-       0       0       1       1       0       1       0       3       0       2
-       2       0       2       1       2       0       0       1       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       1       0       2       1       0       1       2       2       1       0
-       0       0       1       1       0       1       0       2       0       0
-       0       2       2       0       0       1       0       1       4       1
-       3       0       0       2       2       1       2       1       1       0
-       0       1       1       2       0       2       2       0       0       2
-       1       1       1       1       1       2       0       1       1       2
-       2       2       2       2       1       0       1       0       0       1
-       1       3       0       2       0       1       1       1       2       1
-       0       0       0       1       1       0       0       1       1       0
-       2       2       0       1       1       1       0       2       0       4
-       1       2       1       0       1       0       1       1       2       1
-       3       0       0       0       0       0       0       0       0       0
-       0       0       0       2       1       2       2       2       3       0
-       1       1       3       2       2       1       3       5       4       2
-       4       2       7       2       4       2       0       4       3       2
-       5       2       1       1       3       2       4       3       0       8
-       2       2       4       7       3       9       8       6      10       3
-       4       9       7       4       3       4       6       2       5       8
-       7       6       1       6       5       2       3       4       4       3
-       8       7       9       4       5       3       5       9       7       1
-       3       6       2       3       4       2       6       2       3       7
-       5       6       4       3       3       3       4       5       8       1
-       2       3       1       3       2       2       4       2       1       3
-       0       1       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       1       3       1       3
-       0       0       1       0       1       1       0       1       2       0
-       0       2       1       1       1       1       1       3       3       0
-       0       1       1       3       1       0       1       0       0       0
-       1       2       0       1       2       0       1       0       1       0
-       2       0       1       1       1       1       0       1       0       0
-       0       0       0       1       0       0       0       2       1       1
-       1       0       2       2       0       0       1       1       1       1
-       1       0       0       0       2       1       1       2       2       1
-       0       1       1       1       2       1       2       0       1       0
-       0       2       0       0       3       1       0       0       0       1
-       0       0       0       1       0       0       0       0       0       0
-       0       0       0       1       0       0       0       1       0       0
-       0       1       0       1       0       1       2       1       0       0
-       2       0       0       1       0       1       0       1       1       0
-       1       2       1       2       0       3       0       1       2       1
-       0       2       0       0       1       0       2       4       1       0
-       3       0       1       3       2       1       2       0       0       1
-       0       3       0       0       0       1       2       0       1       0
-       0       1       2       0       2       0       1       2       1       1
-       3       1       0       2       0       1       1       0       1       0
-       1       1       1       3       0       1       1       0       0       0
-       0       2       0       0       0       1       0       1       1       2
-       0       0       0       0       1       2       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       1       1       0
-       0       1       0       2       2       1       0       0       0       0
-       1       0       1       1       1       0       1       2       1       2
-       1       2       1       4       0       4       0       1       0       0
-       1       1       2       1       2       0       3       2       2       1
-       1       0       0       0       1       0       0       2       1       2
-       3       0       0       5       0       1       1       1       0       2
-       2       1       2       0       2       2       2       0       1       2
-       0       1       1       0       0       1       0       2       2       2
-       3       1       0       1       0       0       0       0       3       1
-       1       2       3       0       1       4       1       2       0       1
-       2       0       0       2       1       1       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       1       0       0       1       1       1
-       1       1       0       1       2       1       1       0       1       2
-       2       0       0       0       2       2       2       0       3       0
-       0       1       1       0       0       0       1       1       1       5
-       0       0       2       1       1       0       2       3       2       1
-       2       1       0       3       1       4       2       4       2       1
-       1       1       0       1       1       0       2       2       2       0
-       3       2       3       2       0       2       1       2       1       3
-       0       3       1       3       2       2       2       1       1       1
-       0       4       2       3       0       0       2       2       4       3
-       2       4       3       1       5       4       1       1       0       1
-       3       2       1       1       0       1       1       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       1       0       0       0       0       1
-       0       1       1       2       0       1       1       1       0       0
-       0       0       0       2       0       1       3       2       0       0
-       0       1       4       0       1       0       1       0       0       1
-       0       1       1       1       1       2       0       0       1       0
-       1       0       2       0       0       1       2       1       0       1
-       0       1       1       0       0       0       1       1       0       1
-       1       1       2       0       0       0       0       1       1       0
-       0       0       0       1       0       2       1       2       1       2
-       0       2       0       1       3       0       1       0       0       0
-       2       1       1       1       0       1       1       1       0       3
-       1       3       0       2       0       1       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       1       1       1       0       0       0       1       0
-       1       0       0       0       0       1       0       1       0       1
-       1       0       1       0       1       0       1       1       0       2
-       2       3       0       0       0       0       1       1       0       1
-       0       1       1       1       4       2       0       1       0       1
-       1       0       3       0       0       1       0       3       0       1
-       0       2       2       1       1       0       2       2       0       1
-       1       0       0       2       0       0       1       1       2       3
-       0       0       1       0       2       0       0       1       1       1
-       0       1       1       0       1       3       1       1       2       0
-       1       1       1       0       0       0       0       1       0       0
-       0       1       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       1       1       3       2       0       3       1       0       1
-       0       4       0       1       0       2       2       3       2       1
-       1       0       3       1       0       3       4       3       2       1
-       2       0       2       1       2       2       1       1       1       3
-       2       1       1       2       2       5       1       2       4       1
-       1       1       1       1       0       0       1       2       2       1
-       3       2       1       3       1       3       3       1       4       4
-       2       4       1       5       0       3       0       0       2       0
-       1       1       0       0       2       0       0       1       2       3
-       1       3       2       0       3       0       3       2       0       1
-       1       1       1       1       1       0       0       1       0       0
-       0       0       0       0       0       0       0       0       1       1
-       2       0       0       1       1       0       1       3       1       0
-       0       3       4       1       1       1       0       1       2       0
-       0       2       1       0       0       0       3       1       0       1
-       1       2       1       0       2       0       0       1       0       0
-       1       1       2       0       0       1       2       0       2       2
-       0       1       0       1       1       1       0       1       2       0
-       0       2       1       1       0       0       0       1       0       2
-       0       1       0       0       1       1       0       2       0       2
-       0       0       1       1       0       0       0       4       2       1
-       1       1       0       2       2       1       2       1       3       0
-       0       1       1       1       0       0       0       0       0       1
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       1
-       1       1       0       2       1       0       1       1       0       1
-       0       0       1       1       4       0       2       4       1       1
-       0       2       0       0       0       2       0       0       1       0
-       2       1       1       0       1       1       2       1       0       1
-       1       1       1       1       0       0       1       0       2       1
-       1       1       1       0       1       1       2       0       2       1
-       0       1       1       2       0       3       2       3       0       2
-       0       1       0       1       2       0       1       3       0       0
-       0       0       2       1       1       1       2       2       0       0
-       3       2       0       1       1       1       0       0       1       1
-       0       1       0       1       1       1       1       1       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       3       1       1       1       1
-       1       1       0       1       0       1       1       3       0       0
-       4       0       1       1       0       3       0       0       1       0
-       0       0       1       3       0       2       2       0       2       1
-       0       1       0       2       0       2       2       0       1       0
-       1       0       0       0       0       2       4       4       2       1
-       0       2       2       3       0       0       0       0       2       1
-       2       0       0       0       1       2       2       0       2       1
-       0       0       1       0       0       2       0       0       0       3
-       2       1       1       0       0       0       3       2       1       0
-       0       2       0       0       0       2       0       1       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       1       0       2
-       1       1       0       0       0       2       1       0       1       1
-       1       1       1       1       0       2       1       0       2       2
-       1       1       0       3       2       1       1       0       0       1
-       1       0       2       0       1       0       0       1       2       1
-       1       3       1       0       0       0       0       1       2       1
-       1       0       0       1       0       2       1       0       1       1
-       0       0       0       2       2       2       2       1       1       1
-       0       2       4       2       0       1       1       0       0       1
-       0       2       2       0       0       1       0       1       0       1
-       1       0       0       0       2       1       1       1       0       0
-       2       0       2       0       0       0       1       0       1       0
-       0       0       0       0       0       0       0       0       0       0
-       0       1       1       2       1       1       0       2       1       0
-       1       0       2       0       0       0       0       2       0       1
-       0       1       1       1       0       1       0       2       0       0
-       1       1       1       0       1       0       2       0       0       3
-       1       1       1       1       1       2       1       2       0       0
-       2       3       1       0       0       0       1       0       1       0
-       0       1       1       1       1       1       1       0       0       0
-       0       0       1       1       0       0       0       1       1       1
-       3       2       0       1       0       0       1       0       1       0
-       0       1       0       0       0       1       0       0       2       2
-       0       0       0       0       1       1       0       0       1       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       1       1       0       1       3       2       1       1       1       1
-       0       1       1       1       2       3       2       0       1       0
-       2       0       2       0       1       0       1       1       0       0
-       0       1       2       3       0       1       0       0       0       1
-       1       0       0       1       2       1       0       3       0       0
-       1       1       0       0       2       1       0       1       0       1
-       0       0       1       0       0       0       1       1       2       1
-       3       1       2       0       2       0       0       2       1       0
-       0       1       0       1       2       1       1       0       2       2
-       0       0       0       2       2       0       1       1       0       0
-       2       1       1       1       1       0       0       1       0       1
-       1       0       0       0       0       0       0       0       0       0
-       0       1       0       0       1       1       0       0       0       1
-       0       1       0       1       0       0       1       1       0       1
-       1       0       0       0       1       3       1       0       2       2
-       0       1       1       0       1       0       0       2       0       1
-       1       1       0       0       2       0       1       1       1       0
-       0       0       0       0       0       0       4       4       1       0
-       1       3       0       1       1       0       1       0       3       0
-       1       1       0       2       0       0       0       1       0       1
-       1       2       0       0       1       0       2       0       2       1
-       1       0       1       0       1       0       0       1       0       3
-       0       1       2       1       1       1       2       0       1       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       1       1       1       0
-       1       0       0       0       1       0       1       0       1       1
-       0       1       1       0       2       1       2       0       1       0
-       4       0       1       1       2       2       2       0       0       0
-       0       0       1       2       0       1       0       2       1       0
-       1       0       1       0       0       1       1       0       1       0
-       2       0       0       1       3       1       1       0       1       1
-       1       2       0       0       0       0       1       1       2       2
-       0       0       0       1       0       1       1       1       0       2
-       0       1       0       2       0       0       1       1       1       0
-       0       2       1       1       1       0       1       0       1       0
-       0       1       0       3       0       1       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       5       2       0       0       2       1       0       0       0
-       0       2       1       1       1       3       2       1       1       1
-       2       2       1       0       1       1       2       0       2       0
-       1       1       2       0       1       0       0       0       4       1
-       0       0       0       1       0       1       0       0       0       0
-       0       0       3       0       0       1       2       1       2       2
-       0       2       0       5       2       1       2       1       1       2
-       1       2       1       2       1       1       1       3       0       0
-       0       0       1       2       0       1       1       0       0       2
-       0       0       4       0       2       0       0       1       1       0
-       1       0       2       1       0       1       1       0       0       1
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       1       1       0       0       1       1
-       0       0       0       2       0       1       1       1       2       1
-       1       1       2       0       0       0       0       2       0       1
-       0       1       1       2       1       1       2       2       0       0
-       0       0       3       3       1       1       3       0       1       1
-       0       0       1       3       1       1       1       0       1       1
-       2       0       0       0       1       1       0       2       0       0
-       1       2       1       0       0       0       2       0       0       1
-       0       2       2       0       1       0       0       3       0       1
-       0       2       2       1       0       1       0       0       0       0
-       1       1       1       1       1       1       3       0       1       1
-       1       3       1       0       4       0       1       0       0       0
-       0       0       0       0       0       0       0       0       0       3
-       1       1       2       0       1       1       0       0       0       1
-       2       2       0       2       0       0       0       1       1       1
-       0       1       0       1       0       1       2       0       3       0
-       0       1       1       0       1       2       2       0       2       0
-       1       0       0       1       1       1       0       0       0       1
-       1       2       0       1       1       0       0       0       0       1
-       2       3       1       0       2       1       0       0       0       1
-       1       1       1       0       1       0       0       1       1       1
-       1       0       2       1       1       1       0       0       2       0
-       0       1       2       0       1       0       0       2       1       1
-       3       1       1       1       1       1       2       0       0       0
-       1       0       0       0       0       0       0       0       0       0
-       0       0       0       1       0       0       2       1       2       0
-       0       0       1       2       0       0       0       2       1       1
-       1       2       0       2       1       2       1       1       2       1
-       2       0       0       0       1       1       2       2       1       4
-       3       1       1       2       1       1       4       1       1       0
-       2       0       0       0       2       0       1       0       0       0
-       1       1       2       0       1       1       1       0       1       0
-       0       2       0       0       1       2       0       2       2       1
-       1       1       1       4       1       1       1       0       0       1
-       1       2       1       2       1       1       2       0       1       2
-       0       2       0       0       1       1       1       3       1       0
-       1       1       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       1
-       1       0       1       1       1       0       0       3       1       1
-       1       2       3       0       1       0       1       0       2       1
-       1       0       3       0       2       1       1       3       0       1
-       0       1       0       1       0       0       1       1       0       4
-       0       0       0       1       2       0       3       1       2       0
-       0       1       2       2       3       1       1       1       2       1
-       1       0       0       0       3       2       1       1       1       1
-       0       1       0       1       0       0       1       0       0       0
-       1       1       1       1       0       3       2       3       2       2
-       3       0       1       1       2       1       1       1       1       1
-       1       1       0       0       1       0       1       2       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       1       1       1       2       3
-       1       0       1       1       1       2       2       1       1       1
-       1       2       1       1       1       1       1       2       0       1
-       2       2       0       1       1       1       0       0       0       0
-       0       1       2       1       0       0       2       0       1       0
-       1       1       0       1       1       1       1       0       0       1
-       1       4       2       0       1       1       1       1       2       1
-       1       0       2       0       3       1       1       0       0       1
-       1       1       0       1       1       2       0       0       0       0
-       1       2       1       0       1       1       1       0       0       0
-       0       1       0       3       1       0       0       3       3       1
-       0       2       2       0       0       1       0       0       0       0
-       0       0       0       0       0       0       1       1       1       1
-       0       1       1       0       1       0       0       0       1       3
-       0       0       1       0       0       4       3       1       1       2
-       3       0       1       2       0       3       2       0       2       0
-       1       0       0       1       0       1       1       0       1       3
-       2       4       1       0       1       1       1       1       1       1
-       0       1       1       1       0       1       2       0       0       0
-       2       0       1       0       1       3       0       1       2       2
-       0       1       0       1       0       1       1       0       1       1
-       1       1       0       0       2       2       1       2       0       0
-       1       0       0       1       1       1       2       1       1       2
-       3       0       0       2       0       1       3       1       2       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       1       2       0       1
-       0       1       0       0       0       0       0       2       1       2
-       0       0       2       2       0       1       1       1       1       1
-       7       0       2       1       1       0       0       2       4       1
-       2       1       0       0       1       1       1       0       2       0
-       1       1       3       0       0       1       3       1       1       0
-       0       0       1       1       0       2       0       0       0       0
-       0       4       0       2       0       1       0       1       1       2
-       0       3       2       1       3       1       2       2       0       1
-       0       1       0       1       0       1       0       0       2       1
-       1       1       1       2       0       0       1       1       0       1
-       2       0       1       0       0       0       0       0       0       0
-       0       0       0       0       0       0       1       0       1       0
-       1       0       0       0       1       3       0       0       1       0
-       0       1       0       1       3       3       0       0       1       0
-       1       0       1       0       0       1       0       0       1       0
-       1       1       2       0       1       1       0       0       2       1
-       1       0       0       0       0       1       3       0       0       1
-       0       2       0       1       0       1       1       2       0       1
-       2       0       3       0       1       0       0       0       1       0
-       0       1       0       1       1       3       0       1       2       1
-       1       0       2       3       1       1       2       1       3       1
-       3       1       2       0       1       1       2       1       0       2
-       2       0       0       0       0       0       1       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       1       0       0       2       0       0       0
-       1       2       1       1       1       1       0       0       4       0
-       1       1       3       0       3       1       1       0       0       0
-       0       0       1       0       1       0       1       3       0       1
-       3       1       0       2       1       2       0       3       1       1
-       2       1       0       0       0       1       0       0       3       0
-       1       0       1       0       0       0       0       3       0       1
-       0       1       1       1       1       0       0       2       3       0
-       0       1       0       1       0       0       2       1       2       1
-       0       1       1       0       1       0       0       1       2       1
-       2       0       0       1       2       1       0       2       1       1
-       1       0       0       0       0       0       0       0       0       0
-       0       0       1       0       5       0       2       0       2       1
-       1       1       0       2       1       4       1       0       0       1
-       1       0       1       0       2       1       1       2       1       1
-       2       1       0       3       2       1       3       0       4       1
-       2       1       1       0       1       1       1       3       1       1
-       1       3       0       1       0       3       1       2       0       0
-       1       1       2       0       2       2       2       0       1       1
-       0       1       1       3       1       2       5       1       2       1
-       4       3       1       1       1       0       0       1       0       0
-       0       2       1       0       0       1       0       1       0       0
-       0       2       0       1       0       0       2       1       2       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       1       0       2       1       4
-       0       0       2       3       3       2       0       2       0       1
-       1       1       1       2       3       1       0       1       0       2
-       1       4       2       0       1       1       1       1       0       0
-       1       1       3       2       1       2       2       1       2       1
-       1       0       1       1       4       3       0       3       3       1
-       2       1       1       0       1       1       2       2       1       1
-       0       0       1       2       3       1       1       2       1       2
-       3       3       2       2       1       2       2       0       2       2
-       3       4       0       2       0       0       1       0       2       1
-       2       0       1       2       2       2       0       2       1       3
-       2       1       3       0       0       1       0       1       0       0
-       0       0       0       0       0       1       0       0       1       1
-       4       1       2       0       2       1       2       1       0       2
-       1       3       0       0       1       1       0       0       2       3
-       2       1       1       1       0       0       1       0       1       4
-       2       2       1       0       2       1       0       0       2       2
-       1       0       2       1       1       0       2       1       0       0
-       0       0       2       2       3       0       1       0       1       2
-       1       3       0       0       2       1       2       2       2       0
-       0       3       0       1       1       0       1       0       0       1
-       2       0       1       1       1       2       1       2       0       0
-       2       2       0       0       0       1       1       2       2       1
-       0       2       2       2       1       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       1       1       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       1       3
-       3       2       1       4       0       0       0       0       0       0
-       0       0       0       0       0       0       1       1       1       7
-       1       3       5       3       1       1       1       3       0       0
-       2       0       1       1       0       1       2       2       0       2
-       2       0       1       2       0       1       2       2       0       0
-       0       0       0       1       0       2       0       2       1       2
-       2       0       1       1       0       2       2       1       2       1
-       1       3       2       1       2       0       0       3       2       2
-       0       0       2       2       1       1       1       1       2       1
-       0       0       0       0       1       1       0       1       3       0
-       3       1       0       0       0       1       2       1       3       0
-       0       0       1       0       0       0       0       1       0       0
-       0       0       0       1       1       1       3       1       1       0
-       3       0       2       2       0       3       0       2       0       1
-       1       1       2       1       1       2       1       1       2       2
-       0       3       5       1       0       0       1       0       1       1
-       0       1       3       1       1       1       3       1       2       0
-       2       1       1       1       0       0       2       1       0       4
-       1       1       0       3       0       1       1       1       0       0
-       1       3       0       2       0       2       2       2       0       1
-       0       1       0       2       1       1       0       0       3       1
-       3       1       3       1       0       1       0       0       2       0
-       1       1       0       0       0       0       0       0       1       0
-       0       0       0       1                                                
-SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS
-       6      19      25  123944       0       1                                
-FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
-       6       1                                                                
-            time         monitor       Total Cou     angles*1000                
-  0.35693000E+05  0.30000000E+06  0.15918000E+05  0.15275200E+06  0.40200000E+03
-  0.50810000E+05                                                                
-IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
-   16384                                                                        
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       1       0       1       0       0
-       2       0       3       0       0       1       2       0       0       0
-       1       0       0       1       1       2       0       0       2       2
-       1       0       1       0       0       1       0       1       1       0
-       0       0       1       1       0       0       1       1       2       0
-       1       0       0       1       0       0       0       0       0       0
-       0       1       0       0       0       0       0       1       1       0
-       0       0       0       0       0       0       1       0       0       0
-       0       0       0       0       0       0       1       0       0       0
-       1       0       0       2       2       0       0       0       0       0
-       0       0       0       0       0       0       0       2       0       0
-       0       0       0       0       1       0       1       0       1       0
-       0       0       1       0       0       0       0       0       0       0
-       0       0       0       0       0       1       0       3       0       1
-       1       1       2       0       1       0       1       0       1       0
-       3       0       1       1       1       0       0       1       2       0
-       1       0       0       0       0       0       1       3       2       1
-       1       0       0       1       1       0       0       3       0       0
-       1       0       0       0       1       0       0       1       0       1
-       1       0       0       1       0       0       0       0       0       1
-       1       0       0       1       0       1       0       0       2       1
-       0       0       1       0       0       1       0       0       0       1
-       0       0       1       0       1       1       1       0       0       3
-       1       0       2       0       1       0       0       2       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       1       0
-       0       2       0       1       0       1       0       0       0       1
-       1       1       1       0       1       2       0       0       0       0
-       1       0       0       0       1       0       0       0       0       1
-       2       0       0       0       1       0       1       1       1       1
-       0       1       0       0       0       0       0       2       1       1
-       2       2       0       1       0       1       1       0       0       0
-       0       2       1       0       0       1       0       2       1       0
-       0       1       1       0       1       0       1       0       0       0
-       0       1       0       1       2       2       0       1       1       0
-       1       0       2       1       0       1       2       1       0       0
-       1       0       1       0       0       1       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       1       1       1       0
-       0       2       3       1       0       0       0       0       0       1
-       0       0       0       1       1       1       0       1       0       2
-       0       1       1       0       0       0       1       1       1       0
-       3       0       1       0       4       2       2       4       0       1
-       0       0       1       0       1       1       0       0       1       0
-       1       0       0       0       1       0       1       0       4       1
-       0       0       1       4       0       1       1       1       0       1
-       0       1       0       0       0       0       0       1       0       0
-       0       1       2       0       1       0       2       2       0       1
-       0       1       1       1       0       2       2       0       2       0
-       1       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       1       0       0
-       0       1       0       1       1       0       0       0       0       1
-       0       2       2       1       0       2       1       0       1       1
-       0       1       2       1       2       1       1       0       0       0
-       2       1       0       0       0       1       1       0       0       2
-       1       4       2       0       1       1       0       2       0       0
-       1       0       0       1       1       1       0       2       0       1
-       0       1       1       0       1       0       0       0       0       0
-       0       1       0       1       0       0       2       2       1       2
-       0       1       0       1       0       0       0       2       1       1
-       0       1       0       0       1       1       1       0       0       0
-       0       1       1       0       1       1       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       1       1       1       0       2       0
-       5       0       1       0       0       0       1       0       1       0
-       0       0       0       2       0       0       1       3       1       0
-       0       1       1       1       1       0       2       3       0       0
-       1       0       0       1       2       2       1       1       1       0
-       0       1       3       0       2       2       0       2       1       1
-       0       0       0       1       4       0       1       2       3       2
-       0       2       2       2       1       2       1       2       1       1
-       0       1       0       0       2       0       0       2       1       1
-       1       1       0       1       1       1       1       0       0       2
-       0       1       0       0       0       2       1       0       0       1
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       3       2       2       0       0       1       4       0       0
-       2       1       3       1       5       4       2       2       3       5
-       4       7       2       3       3       2       8       1       8       2
-       9       7       3       6       4       3       6      10       4       7
-       8       3       4       7       2       4       6       5       3       7
-       3       6       6       7       2       6      10       5       6       4
-       4       3       2       4       5       7       2       6       8       2
-      12       5       6       4       3       3       2       5       5       7
-       5       4       4       4       5       4       4       4       5       4
-       4       1       1       6       3       2       2       4       3       5
-       2       0       3       2       1       0       1       1       0       0
-       2       1       0       0       0       0       0       0       0       0
-       0       3       1       4       3       0       4       0       4       8
-       1       3       1       2       6       1       5       1       3       3
-       5       6       2       1       1       1       0       1       1       4
-       0       3       2       5       6       6       0       1       1       2
-       5       2       2       4       2       7       2       7       1       2
-       3       1       5       4       4       2       2       3       2       5
-       1       2       1       0       2       1       0       5       4       3
-       6       4       5       0       5       1       4       2       0       2
-       5       2       3       2       3       0       2       3       2       2
-       2       3       3       1       0       4       4       0       1       4
-       2       1       5       2       0       5       2       4       2       0
-       0       1       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       1       1       0       1       1       2
-       1       3       4       5       6       4       3       1       1       1
-       8       2       4       5       0       6       2       6       1       4
-       1       1       1       4       5       6       5       2       4       2
-       2       2       4       1       6       3       5       6       1       1
-       5       5       2       3       2       4       2       5       3       5
-       1       3       3       3       4       2       3       3       1       4
-       5       7       4       3       4       5       3       1       1       1
-       1       2       6       3       7       1       2       0       2       2
-       4       2       1       3       6       2       2       1       5       5
-       3       2       0       0       1       0       2       3       1       2
-       3       2       1       0       1       0       0       0       0       0
-       0       1       0       3       0       1       1       0       3       6
-       3       2       4       3       2       2       2       1       0       2
-       1       2       0       1       2       4       1       2       1       5
-       1       3       2       4       1       1       4       4       2       1
-       2       1       0       3       3       2       4       0       9       1
-       5       2       2       1       4       3       5       6       2       4
-       5       1       4       1       1       2       0       1       2       3
-       1       3       4       2       4       2       4       4       1       3
-       0       2       4       4       3       3       3       2       4       3
-       0       3       2       0       3       3       2       2       3       2
-       4       0       4       0       1       1       0       4       2       2
-       3       0       3       3       0       0       1       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       1       0       5       1       4       2       0       0       4       2
-       1       1       2       2       0       2       4       0       1       2
-       2       2       2       3       1       6       1       4       3       2
-       2       0       2       2       1       2       4       3       5       2
-       2       2       1       0       1       5       0       1       2       4
-       1       3       1       6       1       1       3       1       2       3
-       1       1       1       1       1       4       2       1       1       0
-       2       1       1       0       1       1       2       2       2       1
-       1       3       1       2       3       2       4       1       0       2
-       0       3       1       2       1       3       1       3       1       3
-       3       2       2       1       3       0       5       1       2       3
-       3       1       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       1       0       1
-       1       2       4       1       3       1       1       1       1       0
-       0       2       6       1       2       2       0       1       1       2
-       0       1       0       0       1       3       2       2       1       0
-       5       2       1       0       0       2       0       2       1       1
-       2       1       1       1       2       3       2       4       1       2
-       2       2       0       3       0       1       0       1       2       1
-       3       2       2       2       5       2       0       1       2       5
-       1       0       4       2       1       4       1       2       2       1
-       3       2       1       3       1       3       0       2       0       2
-       2       0       0       1       1       0       0       5       3       1
-       4       0       2       3       0       1       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       1       1       0       2       0       1       3       3       3
-       0       1       5       0       0       2       2       2       1       2
-       3       2       2       2       4       1       1       2       1       0
-       3       1       1       4       2       1       2       3       5       0
-       1       2       2       0       3       1       1       3       1       2
-       4       3       3       1       3       2       3       3       0       1
-       0       1       0       4       0       2       3       2       4       1
-       2       1       2       0       1       2       2       2       1       2
-       2       1       0       0       2       0       3       1       0       1
-       3       0       3       2       0       2       1       0       2       0
-       3       1       0       1       1       1       2       2       1       1
-       0       0       0       0       0       0       0       0       0       0
-       0       2       1       0       3       0       0       2       1       1
-       1       0       1       3       0       2       4       3       2       0
-       0       0       2       2       0       1       3       0       0       1
-       3       3       3       1       1       3       3       4       1       1
-       1       3       2       2       1       3       1       0       1       1
-       2       1       2       2       2       1       0       0       2       0
-       2       2       1       1       4       2       4       1       1       1
-       0       1       2       2       0       1       3       0       2       3
-       3       4       2       0       3       1       1       0       1       1
-       1       1       3       2       3       2       1       2       2       4
-       0       1       1       0       1       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       1       1       0       1       1       1       1       2
-       3       1       2       0       1       0       0       0       1       1
-       7       4       2       1       1       4       0       1       2       3
-       2       1       1       3       4       1       2       1       2       2
-       1       3       1       1       1       2       1       3       3       1
-       1       1       0       1       1       2       0       2       1       2
-       2       2       0       0       3       2       0       3       2       1
-       3       1       3       1       3       2       1       3       0       2
-       5       1       2       0       1       2       3       3       2       2
-       0       3       0       1       3       2       1       5       2       1
-       3       2       1       1       2       1       2       1       2       1
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       1       1       1       1       1       1       0
-       6       2       2       3       3       3       3       1       0       0
-       1       0       1       1       1       0       3       2       2       1
-       0       0       2       1       2       2       0       2       1       1
-       0       1       3       4       2       2       1       3       1       0
-       1       0       1       1       1       1       4       2       0       2
-       3       1       0       0       1       2       1       2       0       3
-       3       3       0       1       1       3       3       2       1       0
-       2       0       2       1       1       3       1       1       1       3
-       2       2       1       3       1       0       0       0       0       0
-       3       3       2       1       0       1       1       1       2       1
-       3       0       2       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       1       0       1       2       2       1       0       2       3       2
-       2       2       2       1       2       1       0       2       2       1
-       0       4       0       4       3       0       3       0       0       3
-       1       0       2       2       1       3       0       2       1       2
-       2       2       0       2       1       3       2       2       3       1
-       2       1       1       2       2       1       1       1       1       1
-       0       1       3       3       1       3       2       0       2       2
-       0       3       3       1       2       2       0       0       1       3
-       2       1       2       1       1       1       2       1       0       0
-       0       1       2       1       1       1       1       0       1       1
-       1       2       0       2       1       1       2       0       1       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       1       0       2       3       2       0       0       1
-       1       1       2       1       5       0       2       1       4       2
-       0       0       3       2       1       0       1       2       1       1
-       1       2       2       1       0       3       1       1       2       1
-       1       2       2       2       0       2       1       2       1       0
-       0       1       0       1       3       2       0       1       1       1
-       1       2       3       3       1       1       0       3       2       2
-       1       0       1       1       1       0       2       3       1       0
-       1       0       2       5       1       1       0       0       1       2
-       3       1       1       1       0       2       1       0       1       0
-       1       2       4       1       1       0       2       0       0       1
-       1       1       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       1       2       2       3       2       4       0       1       1       1
-       3       2       1       1       1       2       3       1       1       2
-       0       2       5       2       2       1       1       0       0       3
-       1       0       2       0       3       1       1       2       3       1
-       4       2       3       1       3       1       4       3       1       2
-       2       0       1       1       2       4       1       0       1       0
-       0       0       2       2       1       2       0       2       0       1
-       2       1       1       3       2       0       0       0       1       3
-       2       1       0       1       2       3       2       1       0       2
-       3       2       2       0       1       0       2       0       1       1
-       1       0       0       0       0       0       0       0       0       0
-       0       0       0       1       1       3       1       1       1       1
-       2       0       2       0       0       0       0       0       0       3
-       0       0       1       2       3       3       2       1       0       1
-       1       2       0       3       2       1       0       2       0       2
-       3       1       0       1       2       2       2       0       0       1
-       2       0       1       2       0       2       0       1       3       3
-       0       1       1       4       0       2       0       1       2       1
-       1       2       2       5       2       2       2       0       0       3
-       0       0       2       2       2       0       1       0       1       2
-       0       1       0       1       1       0       2       1       0       1
-       1       0       3       2       1       0       2       2       3       3
-       1       4       1       0       0       1       2       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       1       0
-       1       1       0       1       0       1       1       0       2       1
-       0       1       0       2       3       0       2       2       1       3
-       2       1       1       1       4       2       2       2       2       2
-       2       1       0       0       0       0       2       2       1       2
-       3       2       2       0       2       2       3       2       2       1
-       0       2       1       1       2       1       1       3       2       2
-       2       3       2       5       0       0       2       1       1       1
-       0       0       4       1       0       0       0       0       1       0
-       0       2       4       2       0       0       0       3       1       4
-       0       2       1       1       1       1       1       0       1       0
-       1       0       0       0       1       1       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       1       1       1       1       2       0       2       1
-       0       0       1       1       0       1       0       3       1       2
-       1       2       1       1       2       0       0       0       0       1
-       2       1       1       4       0       0       2       0       0       1
-       1       1       1       0       0       1       0       1       0       1
-       0       1       1       0       1       1       0       2       0       0
-       0       2       0       2       0       3       1       3       0       0
-       2       1       3       1       1       6       2       0       1       0
-       0       3       1       2       0       3       2       1       1       1
-       1       1       0       2       1       2       1       1       0       1
-       1       2       1       0       3       0       0       1       1       1
-       1       1       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       1       1       1       1       1       2       2       0
-       0       2       0       1       1       0       0       2       0       2
-       1       4       1       0       1       0       1       0       4       2
-       0       2       0       2       2       1       4       0       0       0
-       1       2       1       0       0       1       1       1       3       2
-       0       4       1       0       4       0       1       1       3       0
-       0       0       0       3       2       0       0       0       2       2
-       3       1       0       0       2       2       1       4       2       1
-       1       0       2       0       4       1       1       1       0       0
-       1       1       1       1       1       1       2       0       1       0
-       3       1       1       0       0       1       1       0       0       2
-       1       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       1       2       1       2       1
-       1       1       1       0       1       0       0       3       2       1
-       1       0       1       1       0       1       0       0       1       1
-       0       1       0       1       0       1       0       0       2       2
-       0       2       1       2       1       0       0       4       2       0
-       0       1       1       2       2       0       2       1       1       2
-       2       6       2       2       2       1       0       1       1       2
-       3       0       0       3       0       2       2       2       1       3
-       2       3       2       2       4       1       4       0       4       1
-       3       0       3       0       2       2       3       3       1       2
-       3       1       0       0       1       0       0       0       2       0
-       0       1       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       1       0       0       1       0       1       1
-       2       0       1       0       1       1       1       0       2       3
-       3       0       1       0       1       0       1       0       1       1
-       2       1       2       1       1       0       1       1       1       3
-       1       2       1       7       1       3       2       0       0       3
-       2       1       2       0       1       2       2       3       2       5
-       2       1       1       0       1       1       1       1       1       0
-       0       0       3       3       1       1       1       0       0       1
-       0       0       1       0       3       0       0       1       1       0
-       3       1       1       2       2       0       2       1       2       0
-       0       1       1       0       1       0       1       2       2       0
-       2       2       1       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       1       1       2
-       0       0       1       0       1       3       0       0       1       2
-       1       0       2       1       2       1       1       1       2       0
-       1       0       1       0       2       1       2       1       2       3
-       0       1       1       1       1       1       1       4       0       2
-       2       0       0       2       2       4       3       2       0       1
-       1       2       1       1       4       2       0       2       0       2
-       1       0       1       1       2       0       3       1       0       1
-       2       1       2       0       3       2       2       2       1       2
-       2       0       2       1       5       0       4       1       3       2
-       1       0       1       1       2       3       0       1       1       1
-       2       2       3       1       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       1
-       1       1       1       2       0       0       0       1       0       0
-       0       0       1       1       1       0       0       0       3       0
-       2       1       0       3       2       1       2       0       0       1
-       0       1       1       1       1       0       1       1       0       0
-       1       1       0       2       1       0       1       2       1       2
-       0       2       2       0       0       1       1       0       0       2
-       1       2       0       0       2       2       0       3       1       1
-       0       3       2       0       2       1       0       0       0       1
-       2       1       0       2       4       3       1       0       1       1
-       1       1       1       1       0       0       0       0       0       0
-       0       1       0       3       0       1       1       0       0       1
-       0       2       1       0       0       0       0       0       0       0
-       0       0       0       0       1       2       1       2       0       1
-       3       1       2       0       1       1       1       0       1       2
-       0       3       0       3       1       1       2       1       2       0
-       0       0       1       1       0       4       0       4       2       1
-       2       0       2       0       2       1       0       2       1       1
-       0       2       2       3       1       2       1       0       2       2
-       1       4       0       2       1       1       0       2       0       0
-       1       2       2       1       4       0       1       3       1       1
-       1       2       1       0       0       0       0       1       1       1
-       0       2       1       1       1       0       0       4       0       1
-       0       0       1       1       0       3       1       3       2       2
-       1       1       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       1       0       1
-       1       0       1       1       2       1       2       1       1       2
-       1       0       0       1       2       2       0       1       2       1
-       0       4       0       0       3       1       2       0       2       2
-       0       3       3       0       0       2       1       0       0       0
-       3       0       1       1       0       3       2       2       1       1
-       0       2       2       1       1       1       0       1       0       1
-       0       2       1       1       2       0       0       2       2       0
-       2       1       2       5       2       0       3       1       2       2
-       1       0       0       0       0       1       2       0       2       1
-       0       1       1       1       1       3       0       1       0       1
-       1       1       2       3       0       0       2       0       0       0
-       0       0       0       0       0       0       0       0       0       1
-       2       0       1       2       0       0       2       0       2       0
-       1       0       0       1       0       1       1       2       0       2
-       1       0       0       1       2       1       0       1       4       4
-       0       4       1       3       0       0       0       0       0       0
-       0       1       2       1       1       2       1       4       2       0
-       0       0       0       1       0       1       1       0       1       2
-       1       0       2       0       0       2       1       1       0       2
-       0       1       0       0       2       0       1       0       1       0
-       1       1       0       0       0       1       0       1       1       0
-       1       2       0       1       2       0       0       0       0       0
-       2       0       0       1       0       0       0       1       0       0
-       0       0       0       0       1       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       1       0       3       1       0       2       2       1       1
-       2       0       3       2       1       1       0       1       2       0
-       2       0       2       1       0       2       3       2       1       0
-       2       2       3       1       0       0       0       1       1       0
-       0       3       0       2       1       2       3       1       1       0
-       0       4       2       1       0       3       3       0       1       0
-       2       5       0       0       1       1       1       1       2       2
-       1       2       2       0       0       0       1       0       0       0
-       0       2       0       0       1       3       0       0       1       1
-       3       1       1       1       3       2       0       0       0       0
-       0       3       2       1       0       0       0       0       1       1
-       1       0       0       0       0       0       0       0       0       0
-       0       0       0       0       1       1       0       0       1       0
-       0       0       0       0       1       1       0       2       2       2
-       1       2       0       1       0       1       0       0       2       0
-       1       2       0       3       0       2       0       2       2       1
-       1       0       0       0       1       2       1       3       1       0
-       0       2       1       0       0       3       0       2       1       2
-       2       0       0       2       2       0       1       0       1       0
-       3       0       0       0       1       2       0       2       1       1
-       0       3       1       0       2       1       0       1       0       0
-       0       2       1       0       0       1       1       0       0       0
-       0       1       0       0       3       1       2       2       2       2
-       2       2       1       1       0       0       1       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       1       1       0       0
-       2       1       1       1       1       0       1       2       1       0
-       1       3       0       1       1       1       2       2       1       1
-       1       2       2       0       1       0       1       0       1       3
-       1       2       5       0       2       2       0       1       2       0
-       0       1       3       1       3       3       3       1       1       1
-       2       1       6       2       3       2       0       4       0       0
-       2       1       1       3       2       1       0       1       1       3
-       0       1       1       1       1       3       2       1       0       1
-       2       0       1       0       1       0       0       0       1       0
-       2       1       0       0       1       0       3       1       1       0
-       0       1       0       1       1       0       1       0       1       0
-       0       0       0       0       0       0       0       0       0       0
-       0       1       2       0       2       1       4       1       3       0
-       1       2       2       0       0       1       1       3       0       0
-       2       1       2       3       1       0       1       1       2       1
-       3       1       1       1       0       0       1       2       2       1
-       0       2       0       2       1       1       0       0       0       0
-       0       0       2       1       1       1       2       2       1       0
-       4       1       0       0       0       3       0       0       2       0
-       1       2       2       2       0       3       1       1       0       3
-       1       2       0       1       2       0       2       1       1       0
-       1       1       0       2       0       3       2       2       1       3
-       0       1       1       0       0       0       0       2       0       5
-       2       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       1       0       1       1       3       0       0       0       0
-       0       2       2       1       1       0       0       0       0       0
-       0       0       0       2       0       1       1       2       0       0
-       1       3       1       1       1       1       1       1       0       2
-       1       2       2       1       2       1       1       0       0       2
-       2       2       0       1       1       2       1       1       0       1
-       2       1       1       3       1       1       0       0       0       2
-       1       0       2       1       2       3       1       0       1       2
-       0       0       0       3       1       0       0       1       0       0
-       1       0       5       0       0       0       0       0       2       1
-       2       0       0       0       1       0       0       2       0       1
-       2       1       0       0       1       0       0       0       0       0
-       0       0       0       0       0       1       1       0       1       0
-       0       1       0       0       0       2       1       0       1       3
-       2       1       1       3       0       1       2       1       0       0
-       1       0       0       2       3       2       0       2       4       1
-       1       0       0       1       3       1       0       1       3       0
-       2       1       2       2       1       2       3       1       0       2
-       0       1       3       1       3       4       2       2       2       0
-       4       0       3       2       1       0       3       0       2       1
-       0       3       3       0       1       1       1       2       0       1
-       2       1       1       0       0       3       1       0       2       2
-       0       2       5       1       1       1       1       0       0       0
-       3       1       3       2       2       1       1       1       1       3
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       2       1
-       3       1       6       9       4       9       5       8       6       7
-       9       9       9      16      10       6      10      13      15      11
-      13      11      12       8       8       8      14       6       9       4
-       5       4       9       2       1       0       3       4       3       5
-       2       0       4       1       2       2       0       2       2       1
-       1       3       1       1       0       3       2       0       3       2
-       2       2       3       5       2       2       2       1       3       4
-       3       5       2       4       3       3       4       4       5       2
-       9       1       2       8       7       4       5      11       3       6
-       9      10       7       6      10       9      11       8       6       8
-       8       9      14       9      10       2       6       1       1       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       1       1       0       0       1       0       0       4
-       0       1       5       0       0       3       1       1       1       1
-       0       0       1       0       1       0       0       0       2       0
-       1       0       0       0       2       1       1       1       0       1
-       2       1       0       0       1       0       2       1       2       0
-       2       2       2       0       2       2       0       2       0       1
-       1       0       0       3       0       3       4       1       1       0
-       0       2       0       1       0       0       0       1       1       0
-       1       0       3       0       3       0       1       0       1       4
-       0       1       0       3       0       0       1       2       0       0
-       3       2       1       1       0       1       1       1       0       2
-       1       1       0       1       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       1
-       0       1       1       0       0       0       1       0       3       0
-       0       2       2       2       3       1       0       1       2       0
-       1       1       0       1       2       1       1       0       1       0
-       1       3       0       1       1       0       1       0       1       0
-       3       1       0       0       1       0       1       1       0       0
-       1       1       0       2       1       2       2       1       2       2
-       1       1       1       0       1       0       1       2       0       3
-       2       1       0       2       0       0       2       0       0       1
-       1       0       3       2       0       1       2       1       0       2
-       1       0       3       0       0       1       0       1       1       0
-       0       2       1       1       1       1       0       0       0       0
-       0       0       0       0       0       0       0       0       1       0
-       0       0       0       0       2       0       0       1       2       2
-       1       0       1       1       0       0       3       2       1       0
-       0       1       3       0       1       1       0       1       1       1
-       3       0       1       1       1       1       0       1       1       1
-       0       1       1       0       1       2       2       2       2       0
-       1       0       0       3       1       3       2       2       0       1
-       2       2       2       1       0       0       0       2       2       0
-       0       1       3       0       1       0       2       2       2       0
-       2       2       1       0       1       1       2       1       2       0
-       1       2       2       1       1       1       0       2       0       0
-       1       0       0       1       1       0       1       0       1       1
-       0       1       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       1
-       0       0       0       1       2       0       0       2       1       2
-       1       2       2       0       0       0       0       2       0       0
-       0       1       0       0       0       0       0       2       0       1
-       0       0       2       0       0       1       1       2       1       0
-       0       0       2       0       0       1       1       1       2       1
-       0       1       0       3       3       2       1       0       1       2
-       0       2       0       0       2       1       1       0       1       2
-       0       0       0       1       0       1       1       0       1       1
-       0       1       0       1       0       0       1       0       0       0
-       1       0       0       1       1       1       1       1       0       1
-       3       1       1       0       3       1       2       1       0       0
-       1       0       0       0       0       0       0       0       0       0
-       0       1       0       0       1       2       1       1       2       2
-       3       0       1       0       1       0       2       2       0       2
-       3       4       1       0       1       0       3       2       1       1
-       1       1       0       2       3       0       1       2       1       0
-       0       2       2       1       0       1       0       2       0       2
-       1       1       0       1       0       2       1       1       0       0
-       2       2       1       0       0       1       0       1       2       1
-       0       0       2       1       1       1       0       1       0       0
-       1       2       2       1       2       2       0       1       1       0
-       1       2       2       1       1       1       1       1       0       3
-       2       1       1       0       1       0       2       2       2       0
-       2       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       1       0
-       2       0       3       0       3       1       1       1       0       0
-       0       0       1       1       1       1       1       1       0       2
-       1       1       1       0       0       1       2       1       2       2
-       1       3       1       2       2       1       1       1       1       1
-       1       1       0       2       2       1       1       1       0       1
-       3       2       1       1       0       1       1       1       0       2
-       0       1       2       0       0       1       2       1       0       0
-       0       2       1       0       2       0       2       0       1       1
-       1       0       0       1       0       0       0       0       0       1
-       1       0       1       1       2       1       1       0       2       2
-       0       0       1       0       0       0       1       2       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       3       2       1       0       0       1       0       1
-       1       0       1       1       0       1       0       1       0       0
-       0       0       0       0       1       0       3       1       2       3
-       0       1       1       0       1       3       0       3       2       0
-       1       2       1       2       0       0       4       2       0       1
-       1       2       1       2       0       1       0       1       0       3
-       1       1       2       0       0       1       1       2       0       1
-       0       0       1       0       1       0       0       0       0       1
-       0       0       0       0       1       2       0       0       1       2
-       0       0       0       1       1       1       0       2       1       3
-       1       0       0       0       0       0       1       0       0       1
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       1       0       1       1       1
-       0       1       1       2       2       1       0       2       0       0
-       0       0       0       0       0       0       1       1       0       2
-       3       0       1       2       2       2       0       1       1       0
-       1       0       0       0       1       0       2       1       1       0
-       1       1       1       2       1       2       0       1       0       0
-       2       0       2       0       1       2       4       1       0       1
-       1       0       0       0       1       1       0       1       0       1
-       2       1       1       2       1       1       2       0       0       3
-       0       0       1       0       1       4       0       1       0       1
-       4       0       1       0       2       4       1       0       1       0
-       1       0       0       2       0       0       0       0       0       0
-       0       0       0       0       0       0       1       0       0       1
-       1       0       1       1       0       1       3       0       1       2
-       0       0       0       3       2       2       2       1       0       0
-       1       0       2       1       2       0       2       1       2       2
-       0       0       2       0       0       2       1       0       2       0
-       1       4       1       1       1       5       2       0       2       1
-       0       1       1       1       1       0       1       2       0       0
-       2       0       1       1       3       0       2       1       1       2
-       3       2       1       3       2       0       1       0       2       1
-       2       2       0       1       0       1       0       1       1       1
-       1       0       0       1       0       2       0       0       1       1
-       0       1       1       0       1       0       0       2       1       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       1       0       1       0
-       0       0       1       2       0       0       2       1       1       0
-       4       0       1       1       2       1       1       2       0       0
-       1       1       1       1       0       1       0       0       0       2
-       0       0       3       3       1       1       2       2       2       2
-       4       2       3       2       1       0       3       2       1       0
-       1       1       0       1       0       3       1       0       1       4
-       0       1       1       2       0       2       2       2       2       0
-       1       3       1       1       1       1       1       1       3       2
-       1       0       0       1       1       0       1       1       1       1
-       2       1       0       2       0       1       1       0       1       1
-       2       0       2       1       1       1       3       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       2
-       0       0       0       0       1       0       0       0       0       0
-       1       0       0       2       1       1       1       2       0       3
-       2       1       1       0       3       3       0       0       1       0
-       0       0       0       0       0       1       1       0       0       0
-       1       1       0       0       0       1       0       0       1       0
-       1       0       0       0       3       3       1       0       0       1
-       1       1       0       1       2       0       0       1       0       1
-       0       2       2       1       1       0       0       0       0       0
-       5       0       1       1       1       1       3       0       1       1
-       1       1       3       3       0       0       1       0       2       2
-       1       0       2       2       0       0       0       1       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       2       1
-       0       2       3       1       1       0       2       3       2       2
-       1       1       3       0       3       1       1       0       1       0
-       2       0       3       1       0       1       3       2       0       2
-       1       0       0       0       1       0       0       2       0       0
-       0       2       1       2       1       0       1       1       1       1
-       0       0       1       1       1       1       1       0       1       1
-       0       0       1       1       1       1       3       3       1       4
-       1       1       0       1       1       0       1       1       3       0
-       1       0       4       2       1       2       3       1       0       0
-       2       0       1       1       1       1       0       3       2       0
-       0       2       0       2       0       1       1       1       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       1       1       1       1       0       0       1       3
-       1       1       1       0       5       1       0       0       0       1
-       1       0       0       1       1       2       0       0       3       1
-       2       0       1       1       0       1       1       0       1       2
-       1       2       2       0       2       0       0       2       0       1
-       3       0       0       1       2       1       0       1       0       0
-       1       1       0       0       0       1       2       1       1       1
-       0       0       1       0       0       1       1       1       0       0
-       1       1       0       2       0       2       2       0       1       0
-       1       2       1       0       0       1       0       1       0       0
-       0       1       1       0       1       0       0       0       0       1
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       1       0       0       0       1       0       0       1       2
-       0       0       0       1       0       0       1       3       0       0
-       0       1       0       0       2       0       1       1       3       1
-       0       1       1       1       1       1       2       0       1       0
-       1       1       0       0       1       1       1       1       1       1
-       0       1       1       0       0       1       1       2       0       3
-       1       0       3       3       1       0       1       0       0       1
-       1       1       0       1       0       2       0       1       1       1
-       1       1       0       2       1       2       0       3       0       1
-       2       1       1       1       1       1       1       1       1       0
-       1       1       0       0       1       2       2       1       1       0
-       0       1       0       1       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       1       3
-       0       3       0       0       0       1       1       0       1       0
-       1       1       0       0       1       0       0       1       0       1
-       0       0       0       3       2       0       2       0       1       2
-       4       2       0       0       0       0       1       1       1       0
-       1       1       1       0       0       2       1       1       2       0
-       0       0       2       0       0       2       0       0       1       2
-       2       0       1       2       1       1       0       2       1       1
-       1       0       2       2       3       1       1       1       0       1
-       0       2       2       0       2       1       2       2       1       0
-       3       0       2       0       0       4       0       1       0       4
-       1       1       2       1       0       2       1       1       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       2       0       2       0       0       1       2       2
-       1       1       0       1       0       1       0       0       3       0
-       0       1       0       1       0       3       2       0       1       1
-       1       2       4       1       0       0       0       1       1       1
-       1       1       2       1       0       0       0       1       1       2
-       0       0       1       0       0       1       3       0       0       1
-       0       2       0       1       3       2       1       1       1       0
-       0       0       2       1       1       0       1       0       2       1
-       0       1       0       0       1       0       0       0       1       2
-       1       0       0       2       0       0       1       1       0       1
-       1       0       3       0       1       0       2       0       0       0
-       0       0       0       1       0       1       0       2       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       2       0       1       0       0       2       0       0
-       2       1       1       1       1       0       0       0       0       0
-       0       3       2       1       1       3       1       1       1       0
-       0       0       0       2       1       2       0       1       1       1
-       0       0       2       1       4       0       2       2       2       0
-       1       3       1       0       2       2       0       0       1       1
-       1       1       2       3       2       0       0       0       0       0
-       1       1       1       1       0       1       1       0       0       5
-       2       0       0       3       5       1       1       2       1       2
-       0       1       0       0       1       1       0       1       1       0
-       3       0       1       0       2       2       4       2       1       3
-       3       0       0       2       1       0       0       1       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       1       1       0       1       0       1       2
-       1       1       4       0       0       1       0       0       2       0
-       0       0       0       0       0       0       1       0       1       0
-       1       1       1       0       2       1       2       0       2       0
-       0       2       1       0       1       1       0       0       1       0
-       0       1       0       0       0       2       0       0       2       0
-       1       2       1       2       0       0       0       0       1       1
-       1       0       1       0       1       0       0       1       0       1
-       1       1       0       1       1       1       0       0       1       0
-       0       3       1       0       1       0       2       0       2       2
-       1       1       2       0       1       0       1       0       1       1
-       4       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       1       2       0       1
-       0       1       0       0       0       0       0       2       0       0
-       1       1       0       0       1       0       0       0       2       1
-       0       1       1       1       2       1       1       0       0       2
-       1       1       1       2       1       2       1       2       2       1
-       0       0       0       2       2       1       0       0       2       1
-       0       0       0       1       2       0       1       1       1       0
-       2       1       1       0       0       2       0       0       1       0
-       0       0       0       2       2       1       0       2       0       3
-       1       1       0       2       1       1       2       1       1       0
-       4       2       1       1       0       1       5       1       0       2
-       0       0       0       1       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       1       0
-       0       2       1       2       2       0       3       0       0       1
-       0       2       0       1       1       1       1       2       0       1
-       0       0       0       1       1       2       1       0       2       2
-       0       1       1       1       1       0       0       4       0       0
-       1       0       0       1       2       0       0       0       0       2
-       0       2       2       3       2       1       1       1       1       1
-       0       0       0       2       1       0       1       2       1       0
-       2       2       2       1       0       0       1       0       1       1
-       2       1       1       0       1       1       1       0       0       2
-       1       1       0       0       0       0       0       0       1       2
-       0       1       0       0       0       1       1       1       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       1       0       1       1       0
-       0       0       1       0       0       1       0       2       0       2
-       1       0       1       1       2       0       0       0       0       0
-       0       0       0       0       1       2       0       1       0       0
-       0       0       2       1       1       0       0       3       0       1
-       1       0       0       1       2       0       1       1       0       1
-       0       1       0       1       0       0       1       2       1       1
-       1       0       0       1       2       0       1       0       0       0
-       0       0       1       0       0       0       3       1       0       0
-       2       0       0       2       0       1       2       0       1       2
-       1       0       2       1       1       1       4       1       3       2
-       0       0       2       0       0       1       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       1       0       2       3       2       1       0       2       0       0
-       3       1       1       1       3       2       3       2       1       0
-       4       4       0       1       2       3       1       1       0       1
-       0       2       0       2       2       1       1       1       3       1
-       4       4       4       5       3       1       5       6       3       1
-       0       2       4       2       3       1       0       1       0       3
-       2       3       2       0       1       3       0       0       3       0
-       0       2       0       3       3       1       1       4       1       3
-       1       0       2       1       2       1       0       1       3       3
-       3       3       3       0       2       1       2       1       2       0
-       1       2       1       0       3       2       2       0       1       1
-       1       0       0       0       0       0       0       0       0       0
-       0       0       0       1       0       0       1       1       1       0
-       1       1       1       0       0       1       0       0       1       1
-       1       0       0       0       2       0       2       1       3       0
-       0       0       0       2       2       0       0       2       2       2
-       3       0       0       0       3       1       1       1       0       1
-       2       2       1       0       1       2       0       0       2       3
-       0       0       2       2       0       1       0       1       0       0
-       0       0       0       1       1       3       0       0       2       2
-       3       0       1       1       2       0       0       0       0       0
-       0       0       0       1       2       0       1       0       0       0
-       2       0       0       0       0       0       1       0       0       1
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       1       1       1       2       1       2       1       0
-       1       1       1       0       1       1       1       0       1       2
-       5       1       0       3       0       2       0       0       3       0
-       1       2       1       0       1       1       4       0       3       1
-       2       2       2       0       0       0       0       0       1       0
-       0       0       0       0       0       0       1       0       1       0
-       2       0       1       2       0       1       1       1       0       1
-       1       2       1       1       0       0       3       3       1       2
-       0       2       1       0       1       1       0       1       0       1
-       2       1       0       0       2       0       0       2       1       0
-       1       2       1       0       0       1       0       0       0       1
-       0       0       1       1       0       0       0       0       0       0
-       0       0       0       0       2       0       0       0       1       2
-       1       0       0       1       2       2       0       1       0       0
-       0       0       0       0       1       1       1       3       2       1
-       0       0       1       0       1       0       0       1       1       2
-       0       0       1       1       1       1       3       2       1       0
-       1       0       0       0       1       0       5       2       0       0
-       0       1       1       0       0       0       0       0       3       0
-       0       2       2       0       0       1       2       0       1       1
-       1       2       0       0       4       1       1       1       1       0
-       0       1       1       0       0       1       0       0       0       0
-       0       2       1       3       4       0       2       0       0       2
-       1       0       1       1       1       1       0       0       0       1
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       1       1       1       0       0
-       1       2       0       2       1       1       0       1       1       0
-       0       1       1       1       0       3       3       0       4       2
-       0       1       1       0       0       0       0       0       0       0
-       2       0       1       1       0       2       1       0       0       0
-       2       3       1       2       1       0       2       0       1       1
-       0       0       0       0       0       1       0       1       2       0
-       0       0       1       0       0       2       0       0       0       2
-       1       1       0       0       1       0       1       0       0       0
-       2       2       0       1       0       1       1       0       1       0
-       2       0       1       0       1       2       0       0       0       0
-       0       2       0       0       1       1       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       1       1       1       0       0       0       1       1       2       2
-       0       0       1       2       0       0       0       1       0       2
-       2       0       0       3       0       0       0       4       1       1
-       0       2       0       0       0       0       1       1       0       0
-       1       0       0       1       2       4       1       0       3       1
-       0       0       2       0       0       1       0       0       2       2
-       0       1       1       2       1       0       1       0       0       2
-       1       0       0       1       1       1       2       0       0       1
-       1       2       1       1       3       0       1       0       0       0
-       0       0       1       1       1       1       0       0       1       2
-       1       0       0       2       0       1       2       0       2       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       2       0       0       1       1       0       2
-       1       1       1       1       0       0       0       0       0       0
-       2       1       1       1       2       2       0       1       0       0
-       3       0       1       0       0       1       1       1       1       1
-       2       1       0       1       1       2       0       2       1       1
-       1       1       0       1       1       1       1       1       0       2
-       1       1       1       1       0       1       1       0       0       2
-       0       0       1       2       0       0       1       0       0       0
-       0       0       1       0       0       1       2       1       1       0
-       1       1       1       0       0       0       2       1       2       2
-       1       0       0       1       1       0       1       0       1       0
-       2       2       0       1       0       0       0       0       0       0
-       0       0       0       0       0       0       0       2       0       3
-       0       1       1       1       0       0       0       4       0       1
-       2       1       0       1       1       0       0       0       1       2
-       1       0       0       1       1       0       2       2       1       0
-       1       0       1       0       1       0       1       1       1       1
-       0       0       0       2       1       1       0       0       0       1
-       3       1       3       1       0       3       2       1       0       2
-       0       0       1       1       0       4       2       0       2       1
-       1       0       0       2       1       2       0       2       0       1
-       1       0       0       3       0       1       1       2       1       1
-       1       0       0       1       1       2       1       1       1       0
-       0       0       3       0       0       0       0       2       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       1       0       3       1       2       3       2       0
-       0       1       0       1       0       3       0       2       3       1
-       0       1       1       2       1       1       0       2       2       0
-       3       2       0       0       0       4       1       0       1       3
-       0       0       0       0       0       1       2       1       0       1
-       0       0       0       0       1       0       0       0       1       2
-       0       0       2       1       1       2       1       2       2       1
-       0       0       1       2       4       2       0       1       2       3
-       0       1       0       0       0       1       1       0       2       1
-       0       0       1       1       1       1       2       1       0       0
-       2       2       0       0       3       3       0       0       1       1
-       0       0       1       0       0       0       0       0       0       0
-       0       0       1       1       1       0       0       0       0       2
-       1       2       2       0       0       1       2       1       0       0
-       0       1       0       1       1       0       1       0       0       2
-       2       4       1       1       0       2       1       3       1       2
-       4       0       0       0       2       2       2       0       1       0
-       1       0       0       2       3       1       2       2       0       1
-       0       2       2       0       2       1       0       1       1       2
-       0       0       3       0       0       3       0       1       0       1
-       3       2       1       0       0       0       0       1       2       0
-       1       1       0       0       0       0       0       1       2       2
-       0       2       0       0       1       2       1       2       1       1
-       1       0       1       1       0       1       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       2       0       1       0       2       1
-       2       1       3       2       1       2       1       2       1       1
-       3       2       0       2       1       1       0       4       2       2
-       1       1       1       4       2       0       2       4       2       1
-       2       1       1       2       3       1       0       3       3       2
-       2       2       0       2       2       3       0       5       0       1
-       2       2       2       2       2       5       1       0       5       3
-       3       2       2       3       2       3       3       2       0       1
-       3       2       0       4       0       1       1       0       0       1
-       0       0       4       1       0       3       1       3       1       0
-       2       2       0       2       3       0       2       0       1       1
-       0       4       0       1       0       2       0       0       0       0
-       0       0       0       0       0       0       0       1       1       1
-       4       3       4       7       1       1       5       5       2       3
-       5       6       6       5       4       6       2       6       7       2
-       2       5       3       5       4       6       4       2       6       3
-       3       3       2       5       5       2       4       6       4       5
-       7       3       5       3       4       8       2       2       4       4
-       5       2       3       6       3       5       2       5       3       5
-       4       5       1       3       4       0       3       1       3       7
-       4       5       5       7       1       3       7       3       1       5
-       5       4       6       5       1       6       6       8      10       3
-       2       4       2       9       5       3       3       3       5       3
-       4       3       5       2       2       3       2       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       1       0       2       2       2       0       2       0       0
-       0       0       1       0       2       3       1       1       2       0
-       0       2       2       0       1       2       1       1       1       1
-       0       1       1       3       2       1       0       1       0       2
-       0       0       2       2       1       0       1       1       0       1
-       1       1       0       0       3       0       2       1       0       0
-       1       2       2       1       1       1       0       0       2       1
-       4       3       1       2       1       1       1       1       0       0
-       1       0       1       0       1       1       0       1       2       1
-       2       2       0       0       0       1       1       1       0       0
-       1       1       0       2       1       0       1       1       0       1
-       1       0       0       0       0       0       0       0       0       0
-       0       0       1       1       0       0       1       0       1       1
-       0       3       1       1       0       1       1       3       0       0
-       0       0       1       0       0       0       0       0       0       2
-       0       0       0       0       1       0       0       0       1       1
-       0       2       0       2       0       0       0       1       3       0
-       2       0       1       4       0       1       0       0       1       0
-       0       2       0       0       1       0       1       2       2       2
-       0       0       1       2       1       0       0       1       0       1
-       1       1       1       1       2       3       0       0       1       1
-       2       1       2       0       1       0       0       0       0       1
-       0       2       1       0       1       1       1       0       0       0
-       1       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       2       1       0       0       0       1       0       0
-       3       2       0       1       1       2       2       2       2       2
-       0       1       1       1       1       2       4       2       1       2
-       0       0       1       1       1       0       0       2       2       1
-       1       1       1       0       0       0       1       1       1       0
-       2       1       2       1       1       0       1       1       0       0
-       1       1       1       1       2       1       1       1       3       0
-       0       1       0       1       0       1       2       0       1       0
-       1       2       0       1       3       0       1       0       0       0
-       1       1       1       0       3       2       2       1       0       1
-       0       1       1       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       1       1       0       0       0       1       0       2       0       0
-       2       0       1       2       0       1       1       1       1       0
-       0       0       3       2       0       2       1       2       2       2
-       2       1       1       1       1       0       0       0       0       0
-       0       1       2       0       1       1       2       2       2       1
-       0       1       1       0       1       3       3       4       1       2
-       0       4       0       2       0       0       1       1       0       1
-       3       2       1       2       0       2       0       1       0       0
-       0       1       0       0       0       0       0       1       1       0
-       2       1       1       1       1       0       0       1       2       0
-       1       2       1       1       0       1       0       0       1       1
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       1       0       1
-       0       0       4       2       0       2       1       2       2       0
-       2       1       0       0       0       1       0       0       1       4
-       0       1       1       0       0       0       0       3       1       1
-       1       0       2       2       1       1       1       0       6       0
-       1       0       1       1       1       1       1       0       1       2
-       0       1       1       2       3       1       1       1       0       2
-       2       1       4       1       0       1       0       0       0       2
-       0       0       0       1       2       1       2       0       0       3
-       0       0       1       0       0       0       0       1       0       1
-       1       1       3       0       1       1       1       0       0       2
-       2       4       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       1       0
-       3       1       0       2       0       0       2       0       0       3
-       2       1       0       2       1       1       1       1       4       1
-       1       2       0       0       1       2       2       3       4       5
-       1       0       1       4       3       1       0       5       0       0
-       1       4       0       0       3       3       3       0       4       1
-       3       0       3       1       0       1       4       1       3       3
-       0       3       1       1       5       2       2       1       2       1
-       1       1       2       4       1       3       1       4       4       2
-       2       0       1       1       0       1       3       1       3       2
-       0       2       1       2       1       2       0       3       0       0
-       1       2       4       1       3       2       0       1       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       1       0       0       1       0       1       1       4       1       1
-       0       1       1       1       1       0       0       2       0       2
-       0       1       1       0       0       1       1       1       0       2
-       1       2       1       0       0       2       1       1       1       2
-       0       2       0       1       2       0       0       2       2       3
-       4       0       0       0       2       1       1       0       1       2
-       0       0       4       3       2       0       1       1       1       1
-       0       0       0       0       1       0       2       0       2       3
-       4       0       0       0       0       0       2       1       1       1
-       1       2       0       2       1       0       1       0       1       0
-       2       0       0       1       0       1       3       1       0       0
-       0       1       0       0       0       0       0       0       0       0
-       0       0       0       0       2       2       0       0       0       0
-       1       2       2       1       1       3       0       1       0       1
-       1       1       1       2       1       0       2       0       0       3
-       0       0       2       2       0       0       0       0       1       0
-       2       0       0       1       0       3       0       3       2       0
-       2       2       1       1       0       0       1       1       1       1
-       0       1       0       2       0       2       2       2       0       0
-       2       2       0       0       0       0       0       0       2       1
-       1       0       0       0       1       1       1       0       1       0
-       0       0       4       0       0       1       1       1       0       1
-       0       0       2       3       1       2       1       0       4       2
-       1       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       1       0       0
-       1       1       0       2       2       1       1       1       1       2
-       1       1       1       2       0       1       2       1       1       3
-       0       0       2       1       1       1       1       2       2       0
-       0       0       0       0       3       0       0       1       0       0
-       0       0       0       0       1       1       1       0       1       0
-       1       1       1       0       2       0       2       1       2       0
-       0       1       2       0       0       0       1       0       3       0
-       0       1       0       0       0       0       0       1       0       0
-       0       0       0       0       1       1       1       0       0       0
-       2       0       0       0       0       0       0       0       0       0
-       0       2       2       1       1       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       1       0       2       1       0       0       1       0       1       1
-       0       0       0       1       3       2       0       3       1       3
-       0       1       0       1       1       3       0       1       1       1
-       0       1       2       1       0       0       2       0       3       0
-       2       0       0       0       1       1       0       1       0       0
-       1       1       0       0       1       2       0       1       0       1
-       3       1       1       1       2       1       1       0       0       2
-       2       1       0       0       0       2       1       3       3       1
-       1       1       1       2       0       1       2       3       1       2
-       0       1       0       0       1       0       1       0       2       1
-       3       1       2       1       2       0       0       1       0       0
-       1       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       1       1       2       1       2
-       1       1       2       0       3       0       1       0       0       0
-       1       1       1       0       2       1       1       0       0       3
-       0       1       1       0       1       0       1       0       1       0
-       0       1       1       2       2       0       3       2       1       1
-       0       0       0       1       1       2       0       1       1       3
-       0       1       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       1       1       1       0       0       0       0       1
-       0       0       1       0       1       1       1       0       1       1
-       1       1       1       1       0       0       0       2       1       0
-       0       0       1       0       0       0       0       0       0       0
-       0       0       0       0       1       0       1       1       0       0
-       0       0       0       1       0       1       1       2       1       3
-       1       0       0       0       3       2       0       4       0       0
-       1       0       0       0       1       0       0       1       1       2
-       0       1       5       2       0       2       1       0       0       0
-       2       0       0       3       0       0       1       0       1       1
-       2       2       1       0       4       2       1       0       2       0
-       1       0       1       1       0       0       1       0       0       0
-       0       0       3       2       0       2       0       0       0       0
-       1       0       0       0       0       0       2       1       1       0
-       3       0       1       0       1       1       1       0       1       0
-       1       0       0       0       1       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       2       0       0       1
-       0       0       3       4       1       1       2       1       2       2
-       2       0       0       1       2       1       5       0       3       1
-       0       1       1       0       1       0       2       1       4       3
-       2       0       2       1       0       3       2       1       0       0
-       2       2       0       1       1       0       2       0       2       1
-       0       2       0       1       0       0       3       1       1       1
-       2       0       1       1       2       0       0       0       1       0
-       3       2       5       0       1       2       2       1       1       1
-       0       2       0       0       2       0       0       1       0       1
-       3       0       2       1       2       1       2       1       0       1
-       1       4       1       3       1       0       2       3       2       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       1       0       0       0       2       0       2       0
-       0       2       1       1       0       1       0       1       1       0
-       2       2       0       1       1       0       0       0       0       0
-       0       2       1       2       2       0       0       0       0       2
-       0       0       0       2       1       0       1       0       0       0
-       0       0       1       0       0       0       0       1       0       1
-       3       1       3       0       1       0       0       0       0       1
-       1       1       1       0       0       1       0       1       2       0
-       0       1       0       1       1       1       1       0       0       1
-       2       2       1       1       2       3       2       1       1       0
-       1       0       1       0       0       0       0       2       2       1
-       0       1       0       0       1       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       1       1       1       1       0       1
-       0       0       2       1       2       1       1       2       0       0
-       1       0       0       3       2       0       1       2       1       1
-       0       0       1       2       0       1       0       0       1       0
-       4       0       0       1       0       1       2       0       0       2
-       0       1       3       0       1       0       0       1       1       0
-       0       1       0       2       1       0       0       0       2       0
-       1       0       1       0       1       0       0       0       2       0
-       1       1       1       1       3       0       0       0       2       2
-       1       1       0       1       0       0       0       2       0       0
-       1       1       0       1       3       1       1       2       1       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       1
-       0       0       1       1       1       3       2       0       3       0
-       1       0       0       0       0       0       0       0       0       1
-       0       0       0       1       0       3       1       0       0       0
-       1       0       1       1       0       0       0       2       0       1
-       1       1       1       1       1       3       0       2       0       1
-       0       0       1       0       2       0       0       1       2       1
-       0       2       0       1       0       4       2       0       1       0
-       1       2       1       1       1       0       1       0       0       0
-       0       0       0       0       1       2       0       0       0       2
-       0       1       0       1       0       1       0       1       1       1
-       2       0       0       1       1       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       2       0
-       0       1       1       2       1       0       0       0       0       0
-       3       3       1       0       0       4       0       0       2       0
-       1       0       1       2       1       0       1       1       1       0
-       1       1       0       0       2       0       0       1       2       2
-       0       0       0       2       0       2       2       1       1       3
-       1       2       1       0       0       1       1       2       0       0
-       1       0       1       4       2       3       0       0       1       0
-       0       1       3       0       0       2       1       2       1       1
-       0       0       1       2       1       0       2       0       1       1
-       0       2       1       4       1       0       1       1       0       1
-       1       1       0       1       1       1       1       0       1       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       1       1       0       0       1       0       1       0
-       0       0       1       2       1       0       0       2       0       0
-       0       1       0       0       1       0       1       1       2       0
-       1       1       0       0       2       1       1       0       1       0
-       0       1       1       1       1       0       1       0       2       1
-       0       1       1       3       0       0       1       2       0       2
-       3       2       2       1       2       0       1       2       0       1
-       0       1       1       2       2       2       0       1       0       1
-       1       0       1       2       1       0       1       1       0       1
-       2       1       1       0       2       1       1       0       0       1
-       0       0       2       0       0       1       1       2       0       0
-       1       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       1       1       1       0       2
-       0       0       2       1       1       0       0       0       0       1
-       0       0       0       1       0       0       1       0       0       2
-       1       2       1       0       0       1       1       1       0       0
-       2       0       1       0       1       0       0       2       0       1
-       0       0       0       0       1       1       2       2       1       1
-       0       3       1       0       1       1       0       1       0       1
-       0       2       0       1       0       0       1       0       1       1
-       0       1       0       4       1       1       0       1       1       0
-       0       3       0       2       1       2       0       2       0       1
-       2       0       0       0       1       2       1       0       0       3
-       1       3       1       0       0       0       0       1       0       0
-       0       0       0       0       0       0       0       0       0       0
-       1       1       2       4       4       1       0       0       1       2
-       3       3       1       3       3       1       3       1       0       3
-       1       0       0       1       0       1       0       2       0       0
-       0       0       0       3       0       2       3       0       0       3
-       1       0       1       2       1       2       1       1       2       0
-       1       2       1       1       3       0       0       2       2       4
-       0       0       4       0       0       0       0       0       0       1
-       0       0       0       0       0       3       1       2       1       1
-       2       1       2       1       2       0       0       0       1       2
-       0       0       0       1       0       2       2       0       2       1
-       1       2       1       0       1       0       1       0       0       1
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       2       0       0       1       3       0       2       3       1
-       0       0       1       0       0       0       2       0       0       1
-       1       0       0       0       0       1       0       1       0       0
-       1       0       1       2       0       0       0       0       3       0
-       1       3       0       1       1       1       1       0       0       0
-       0       2       2       3       3       4       0       5       0       0
-       1       0       1       4       0       0       1       1       1       0
-       1       1       2       1       1       1       0       0       0       2
-       0       1       0       0       0       0       0       3       1       0
-       0       1       0       0       0       1       0       2       0       2
-       4       0       2       0       3       0       0       1       2       0
-       0       1       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       1       1
-       0       0       4       1       1       1       0       0       0       1
-       1       0       3       0       1       0       0       1       0       3
-       1       1       0       0       0       0       1       2       1       0
-       1       2       2       0       0       1       1       0       3       0
-       0       0       0       1       0       1       1       0       4       2
-       0       1       0       2       1       0       1       2       1       0
-       1       0       1       0       2       0       0       1       1       1
-       1       1       0       1       0       1       1       1       0       0
-       0       1       0       0       0       2       3       0       1       3
-       0       0       1       1       0       1       5       2       2       2
-       0       0       2       1       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       1       3       0       0       1       2       1
-       0       0       1       0       1       2       1       0       0       0
-       1       1       0       0       0       0       1       1       0       1
-       0       0       0       1       0       0       0       1       1       2
-       2       1       0       1       0       1       3       0       0       2
-       0       1       0       0       3       1       1       2       1       0
-       0       1       1       0       0       0       1       0       1       1
-       0       1       2       1       2       0       2       1       0       1
-       1       1       1       0       0       0       0       1       0       0
-       2       0       1       3       2       1       1       0       0       1
-       1       2       0       0       1       1       0       1       0       2
-       0       0       0       0       0       0       0       0       0       0
-       1       0       1       1       2       1       0       0       0       0
-       1       0       4       1       1       1       0       2       0       2
-       2       0       1       2       1       1       1       0       2       0
-       1       1       0       0       0       1       0       1       1       0
-       1       1       2       3       0       1       0       2       0       0
-       0       1       0       1       1       0       4       1       1       1
-       3       0       1       1       0       6       0       1       2       0
-       1       1       1       2       1       1       1       0       0       0
-       2       0       0       1       0       1       2       1       0       2
-       0       1       1       1       1       0       1       2       1       1
-       0       0       5       2       0       0       1       1       1       2
-       0       1       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       2
-       0       1       1       0       1       2       1       0       0       0
-       0       4       0       0       0       1       2       0       2       1
-       2       0       1       0       1       1       2       1       1       0
-       1       2       2       0       0       2       0       0       0       0
-       1       0       1       0       1       0       1       1       0       1
-       1       2       2       0       0       0       1       0       4       1
-       0       1       1       1       0       0       1       1       0       0
-       2       0       0       1       0       2       0       1       0       1
-       1       1       1       1       0       0       0       0       1       0
-       2       2       0       1       0       0       1       0       2       1
-       0       1       1       0       1       0       0       0       0       0
-       0       0       0       0       0       0       0       2       2       0
-       3       0       0       1       0       1       0       0       0       0
-       1       0       1       0       4       1       0       1       0       3
-       0       2       1       1       0       2       0       1       0       0
-       0       0       0       2       0       1       1       2       1       0
-       1       1       1       0       0       1       0       2       2       2
-       2       1       0       1       1       1       0       2       0       0
-       1       1       0       2       1       0       1       0       0       2
-       1       4       1       2       3       0       1       0       2       0
-       1       0       0       2       0       3       0       1       0       1
-       0       2       0       1       0       0       1       1       2       1
-       0       0       1       0       3       0       1       1       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       1
-       1       1       2       0       0       0       1       1       0       0
-       0       1       0       1       1       0       0       1       4       2
-       1       2       2       2       0       0       2       1       0       0
-       1       0       1       0       0       2       1       1       1       1
-       1       0       1       0       4       1       0       2       3       1
-       2       0       1       1       1       4       1       5       1       0
-       1       1       1       0       2       0       4       0       1       3
-       1       0       0       1       0       2       2       4       0       0
-       4       0       0       0       3       1       2       1       0       4
-       0       1       0       0       2       2       1       2       0       1
-       0       1       0       0       0       1       1       0       1       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       1       1       1       3       1       0       2       3
-       1       4       3       3       3       2       6       2       3       4
-       4       2       2       4       2       1       4       4       1       6
-       3       2       5       5       6       4       2       3       4       7
-       3       5       4       8       6       8       7       7       6       6
-       9       1       8       4       8       6       3       2       5       5
-       5      12       9       1       3       4       5       8       7       7
-       3      12       8       5       3       3       5       4       6       7
-       4       3       3       9       7       2       8       6       3       3
-       5       2       3       4       7       5       2       4       4       1
-       3       5       3       3       1       4       3       3       7       1
-       3       1       0       2       1       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       1       1       1       0       0       0       0
-       3       0       1       1       1       0       1       2       0       0
-       0       0       0       4       0       0       2       0       1       1
-       1       2       0       1       1       1       0       0       0       1
-       0       2       0       1       0       2       1       0       0       0
-       0       3       0       1       0       2       0       2       2       0
-       3       1       1       0       1       1       1       0       1       1
-       1       1       1       0       1       0       1       2       1       1
-       0       1       0       0       0       1       0       0       1       0
-       0       1       0       1       0       1       0       0       0       1
-       0       1       0       1       2       0       1       1       1       0
-       1       0       1       2       0       0       0       0       0       0
-       0       0       0       0       1       1       2       1       0       0
-       1       1       1       0       2       0       3       2       3       2
-       2       0       1       2       0       0       1       0       0       0
-       0       1       0       2       0       0       1       0       1       0
-       1       0       2       1       0       2       0       1       2       2
-       0       3       2       1       0       0       1       1       1       2
-       0       0       2       1       0       2       3       0       0       2
-       2       2       2       1       0       0       1       1       0       0
-       0       1       1       0       1       3       0       0       0       0
-       3       1       0       0       2       1       1       1       0       0
-       1       0       1       0       0       0       0       3       0       0
-       0       2       0       0       0       0       1       1       1       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       1
-       1       0       1       2       2       1       1       1       0       0
-       0       2       0       0       1       1       1       0       0       0
-       1       0       1       1       1       0       1       0       1       0
-       2       1       0       3       0       0       1       1       2       1
-       0       3       2       1       0       0       1       1       1       0
-       0       0       0       2       1       2       1       0       0       1
-       0       1       2       0       1       0       2       0       0       2
-       1       1       2       0       1       3       0       1       0       0
-       0       0       2       3       0       1       3       0       1       1
-       1       2       2       0       0       0       1       1       2       0
-       0       1       0       1       2       0       1       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       1       1       0       1       1
-       0       1       0       1       1       0       1       2       1       2
-       4       2       0       0       0       1       0       1       1       3
-       1       3       2       1       2       0       0       2       4       0
-       2       2       0       3       1       3       1       1       0       0
-       3       1       1       2       1       1       1       2       0       1
-       2       1       0       1       1       2       3       2       2       0
-       3       2       2       0       2       2       2       1       1       4
-       4       0       1       1       0       4       0       1       2       3
-       4       3       3       0       1       2       0       1       1       2
-       0       5       0       0       0       0       4       0       2       0
-       5       0       1       0       1       0       1       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       1       2       0       1       2
-       2       1       0       0       0       2       0       1       1       0
-       1       2       0       1       0       0       4       0       0       1
-       0       1       0       0       1       0       2       1       0       0
-       1       1       0       4       1       1       0       2       1       1
-       1       1       0       0       1       1       1       2       1       2
-       0       0       1       2       0       0       0       1       1       1
-       0       0       0       0       0       0       2       1       0       0
-       0       1       0       0       0       0       0       1       2       0
-       2       0       1       1       0       1       1       1       0       1
-       0       0       0       0       0       0       1       1       0       1
-       1       0       2       0       1       1       0       0       0       0
-       0       0       0       0       0       0       0       0       0       2
-       0       0       0       1       1       0       2       0       0       0
-       1       0       1       1       0       3       2       4       1       0
-       1       0       2       1       0       0       0       0       0       1
-       1       1       1       4       0       0       1       1       1       2
-       1       0       1       1       1       0       4       0       1       3
-       0       3       1       0       0       3       0       1       0       1
-       1       2       1       3       0       3       0       0       0       1
-       3       0       1       3       2       1       2       1       0       0
-       3       0       3       2       1       0       2       1       1       0
-       0       0       1       0       0       0       1       1       1       2
-       3       1       2       1       2       0       1       1       1       1
-       1       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       3       1       4       5       0       2       1       4
-       3       1       0       2       2       2       2       1       1       2
-       1       2       4       1       0       1       2       1       2       2
-       6       1       2       2       1       1       3       1       1       1
-       2       4       1       0       2       0       2       2       2       4
-       1       1       2       0       1       2       0       1       2       1
-       1       1       1       3       3       1       1       4       0       2
-       0       0       0       3       1       0       2       1       2       1
-       2       1       3       1       0       0       1       4       1       0
-       1       1       3       2       3       3       1       1       0       4
-       2       2       1       0       0       3       2       1       0       1
-       0       0       0       0       0       0       0       0       0       0
-       1       0       2       2       0       1       0       1       0       4
-       1       0       0       1       0       1       1       0       0       0
-       2       1       2       2       0       1       0       0       1       1
-       2       0       1       2       3       3       0       1       1       1
-       0       3       1       2       0       0       1       2       1       1
-       2       1       2       4       0       1       0       0       0       0
-       0       1       1       2       0       3       1       1       0       0
-       0       0       3       0       0       2       0       0       2       1
-       1       0       1       2       2       1       3       1       2       0
-       2       0       2       0       1       1       1       2       1       2
-       0       0       0       0       0       0       0       1       1       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       1       0       1
-       0       1       0       1       1       0       0       1       0       0
-       1       1       0       0       1       1       1       2       1       1
-       1       0       2       0       1       1       1       1       0       0
-       0       1       1       1       0       2       2       0       0       1
-       2       1       1       0       1       1       1       0       0       1
-       2       2       0       0       2       0       2       2       2       2
-       2       0       0       0       1       1       0       1       1       2
-       2       1       1       0       2       3       2       3       0       0
-       1       1       0       2       0       1       0       1       1       1
-       1       0       1       2       3       0       0       1       0       1
-       0       1       1       3       0       1       1       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       1       0       1       1       0       0       1       1       1       1
-       1       1       0       0       0       0       2       0       0       0
-       1       0       1       0       0       0       2       2       0       2
-       0       2       1       0       0       1       0       3       2       0
-       2       2       1       3       0       3       1       1       2       0
-       1       1       0       2       1       1       0       2       0       1
-       1       3       3       1       0       1       1       3       2       0
-       1       1       0       0       0       0       0       0       1       0
-       0       0       1       0       0       0       2       2       2       3
-       1       3       1       0       1       0       1       1       2       1
-       1       1       0       0       0       2       0       0       1       1
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       1       1       1       1
-       1       0       1       0       3       1       2       2       0       1
-       0       0       0       1       0       0       0       2       3       0
-       1       3       0       0       1       1       2       0       4       1
-       0       0       1       2       0       2       0       0       0       0
-       0       0       1       0       1       0       2       1       1       2
-       1       2       2       1       0       0       1       0       1       0
-       1       1       1       2       1       0       1       2       3       2
-       1       0       0       0       1       2       1       0       0       2
-       1       1       1       0       2       0       1       0       0       0
-       1       0       0       0       1       1       0       2       0       1
-       0       0       2       1       1       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       4       1       0       0       2       0       1       0       1       1
-       0       2       1       0       0       0       1       1       0       1
-       0       1       1       0       1       1       0       1       1       1
-       0       1       1       0       2       1       1       1       1       3
-       0       1       1       0       2       2       2       0       0       0
-       0       2       0       2       2       1       2       2       0       1
-       2       1       0       3       0       2       1       0       0       1
-       0       0       1       2       0       3       0       0       0       0
-       0       0       1       2       1       0       0       1       0       1
-       1       1       0       1       0       0       0       0       1       1
-       2       0       1       1       1       2       0       2       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       2       1       0       1       1       1       0       1       1
-       1       1       0       1       1       1       1       1       1       2
-       0       1       3       4       3       1       0       0       1       0
-       0       0       0       1       1       2       0       0       0       1
-       0       0       1       0       0       2       0       1       3       0
-       0       1       2       0       2       0       1       1       1       0
-       0       0       0       0       1       2       1       0       1       1
-       1       0       1       0       1       3       0       0       0       2
-       3       2       0       1       2       0       1       0       0       0
-       0       2       1       0       0       1       1       2       2       0
-       0       0       0       1       1       2       1       0       1       1
-       0       1       0       0       0       0       0       0       0       0
-       0       2       1       0       0       2       0       2       0       3
-       1       2       3       1       0       0       1       0       2       1
-       0       0       3       1       0       0       0       1       1       0
-       2       1       1       1       2       2       0       0       0       0
-       1       0       0       0       0       0       1       1       0       0
-       0       1       3       3       2       0       0       1       1       1
-       1       0       3       0       0       0       2       2       3       1
-       0       0       0       0       1       1       1       0       1       0
-       1       1       0       2       2       1       0       1       2       1
-       0       0       1       1       0       0       1       0       1       0
-       1       1       1       2       3       1       2       1       0       1
-       1       0       0       1       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       1       3       1
-       2       1       1       2       1       0       2       0       0       2
-       2       2       0       0       1       0       2       1       0       1
-       0       0       1       1       0       0       0       1       0       1
-       2       1       1       0       0       1       1       0       2       2
-       0       2       1       0       0       0       2       1       0       5
-       1       1       0       1       2       0       1       2       0       0
-       1       1       2       0       0       1       0       0       2       0
-       0       2       2       1       0       0       0       1       1       1
-       0       1       0       1       0       1       0       0       2       0
-       3       1       2       0       1       1       1       2       0       0
-       1       0       2       1       0       2       1       0       0       0
-       0       0       0       0       0       0       0       0       1       0
-       1       1       1       2       4       1       2       2       1       0
-       1       0       1       3       0       1       2       0       1       0
-       1       1       1       1       0       1       1       2       0       0
-       2       1       0       3       0       1       0       0       0       0
-       2       1       2       0       1       0       2       3       0       0
-       0       1       2       1       4       0       0       1       0       1
-       0       2       2       0       2       1       0       0       0       2
-       1       1       1       1       0       1       0       1       2       0
-       3       0       0       0       2       2       3       1       1       0
-       0       2       2       0       0       1       1       2       0       0
-       1       1       2       3       1       1       1       3       0       1
-       1       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       1       0       1       1       2       0
-       0       1       1       0       2       0       4       1       0       0
-       0       0       0       3       3       0       3       2       0       1
-       2       1       0       0       0       2       0       0       1       2
-       2       1       0       1       4       1       0       0       2       1
-       0       0       0       1       2       1       1       1       2       0
-       2       1       0       0       0       1       1       1       1       1
-       2       1       2       0       1       0       1       0       0       0
-       0       0       3       0       1       1       1       0       0       1
-       0       0       0       0       1       0       2       1       1       0
-       2       1       1       0       1       1       1       0       0       0
-       1       1       2       0       1       0       0       1       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       1       0       1       1       3       0       0       0       3
-       0       1       2       0       1       2       0       1       0       1
-       0       2       0       1       1       0       2       0       0       0
-       0       0       0       0       1       1       0       0       1       1
-       0       2       1       0       0       0       1       1       0       2
-       0       2       1       1       2       0       1       0       1       0
-       0       0       1       0       0       2       1       1       0       2
-       4       0       0       1       0       0       1       1       1       3
-       0       0       0       1       3       0       0       0       0       0
-       1       1       0       1       2       0       2       1       0       1
-       1       0       2       2       1       1       1       2       0       0
-       0       0       1       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       2       0       2
-       0       2       0       1       2       1       2       0       0       0
-       3       0       1       1       0       1       1       1       1       1
-       1       1       1       1       2       0       0       1       0       1
-       2       1       0       1       0       0       0       1       1       0
-       0       0       1       3       1       0       0       0       0       1
-       1       3       1       2       1       0       2       1       1       1
-       0       4       0       0       0       1       1       0       1       0
-       1       0       1       1       0       1       1       0       1       2
-       2       0       0       0       0       0       2       1       0       0
-       0       1       1       2       3       2       1       0       1       0
-       0       2       3       1       1       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       1
-       0       2       1       2       1       3       2       1       0       0
-       1       0       0       2       2       1       0       1       0       2
-       3       0       0       1       1       1       0       1       0       0
-       1       2       1       0       1       1       0       1       1       0
-       2       2       3       1       0       1       0       2       0       2
-       1       2       2       1       0       0       2       1       1       0
-       0       0       2       2       0       2       0       0       1       1
-       1       2       0       2       0       0       0       3       0       0
-       0       0       0       2       4       2       0       3       0       1
-       0       2       1       1       1       1       0       0       1       2
-       1       0       1       1       0       1       0       0       2       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       1       1       1       0       0       1       0       0
-       0       0       2       1       2       0       2       1       0       0
-       1       2       0       2       0       2       1       0       1       3
-       0       3       0       1       0       2       1       3       0       0
-       2       0       0       0       5       0       1       0       1       0
-       2       1       0       0       1       2       0       0       1       0
-       0       1       0       0       0       0       1       0       1       2
-       0       1       1       0       0       0       2       3       2       2
-       0       2       0       1       0       0       0       0       1       0
-       0       1       0       1       1       1       1       0       1       1
-       0       0       1       2       1       2       0       1       0       0
-       0       1       1       1       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       1
-       0       0       1       1       1       1       1       0       1       1
-       1       3       0       1       1       1       2       1       3       2
-       0       0       0       0       1       0       1       1       2       1
-       1       2       0       0       1       0       0       0       0       3
-       1       2       0       0       0       0       0       2       1       1
-       1       1       1       0       1       0       2       0       2       1
-       0       1       1       0       0       1       0       3       1       0
-       2       2       1       0       1       1       0       0       1       1
-       1       1       2       2       2       2       1       2       3       1
-       1       0       1       0       0       0       2       0       0       0
-       3       1       0       0       3       1       1       0       1       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       1       0       2       2       0       2
-       1       0       1       2       0       0       2       0       2       2
-       1       0       2       0       0       1       0       1       0       2
-       1       1       0       1       0       2       3       0       1       1
-       0       2       0       2       0       0       1       0       1       1
-       0       1       2       0       1       0       1       0       0       1
-       1       1       3       2       0       1       3       0       1       0
-       1       3       2       1       0       2       0       0       2       1
-       2       1       0       2       0       0       1       1       1       0
-       2       2       1       1       3       1       1       0       0       1
-       0       1       0       1       0       3       1       0       0       1
-       0       0       1       1       0       0       0       0       0       0
-       0       0       0       0       0       0       1       2       2       1
-       1       0       1       2       1       0       2       0       0       2
-       0       0       1       1       0       0       0       0       3       2
-       1       1       1       0       1       0       2       0       4       2
-       0       1       1       0       1       0       0       0       3       1
-       2       2       2       0       2       1       2       1       0       1
-       1       0       2       1       0       2       1       1       0       1
-       2       1       2       1       2       0       1       2       1       1
-       1       1       1       3       1       0       3       2       0       3
-       0       2       1       1       2       2       1       1       0       0
-       0       1       2       1       1       0       1       1       0       1
-       0       0       0       1       0       1       1       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       1       2       0       1       0
-       0       0       2       2       1       0       3       0       2       2
-       2       0       1       1       0       0       1       2       0       1
-       0       0       0       1       1       1       0       0       1       0
-       0       2       3       0       1       3       0       0       1       0
-       0       0       1       2       1       1       2       0       0       1
-       2       1       1       2       0       1       0       1       0       1
-       0       0       1       0       2       1       0       1       0       0
-       0       1       0       0       2       3       2       0       0       1
-       3       1       1       2       0       0       1       1       2       1
-       1       1       1       0       1       0       0       2       2       1
-       1       1       0       0       0       0       0       0       0       0
-       0       0       2       1       2       0       1       1       0       2
-       0       0       1       1       2       0       1       0       1       0
-       3       0       0       1       1       0       1       2       0       2
-       0       1       0       1       1       2       0       0       1       0
-       0       2       1       0       2       2       0       1       2       2
-       2       0       0       2       1       1       2       1       2       1
-       0       0       4       2       1       0       2       2       1       1
-       1       2       1       2       1       3       2       1       1       0
-       0       0       2       1       2       1       1       0       1       2
-       1       1       0       0       2       0       0       1       0       1
-       1       0       0       2       0       0       1       0       1       1
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       2       2       0
-       1       1       2       2       0       3       0       0       2       3
-       3       1       0       1       1       1       2       1       1       1
-       1       2       1       5       1       1       0       2       4       2
-       1       5       2       3       3       5       3       1       4       2
-       1       3       1       4       2       2       2       2       4       0
-       0       2       3       1       2       2       4       1       0       0
-       2       2       1       4       0       0       1       2       5       0
-       0       2       2       3       3       1       1       0       1       1
-       3       0       3       0       0       3       1       1       2       0
-       1       1       0       0       1       1       2       3       3       1
-       0       0       1       0       1       0       0       0       0       0
-       0       0       0       0       1       0       0       1       1       2
-       3       4       1       1       2       2       3       0       0       1
-       0       0       1       0       1       1       1       0       1       2
-       1       2       1       0       2       0       2       1       0       3
-       1       2       0       0       2       2       1       1       1       0
-       1       0       2       0       1       2       0       1       0       0
-       2       1       1       0       1       0       1       1       0       2
-       3       2       2       0       0       1       1       2       2       1
-       1       2       2       0       1       1       3       1       1       0
-       0       0       1       0       1       1       1       0       1       0
-       0       0       3       0       1       1       0       2       0       0
-       2       1       2       0       0       1       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       1       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       1       0       1       2
-       0       4       0       3       2       0       0       0       0       0
-       0       1       0       0       0       1       0       1       3       0
-       2       2       1       0       0       1       0       3       1       0
-       2       1       0       0       1       0       2       1       3       1
-       2       2       0       2       0       0       1       1       1       0
-       1       0       0       3       1       0       1       1       1       0
-       2       2       1       2       1       1       0       1       0       0
-       2       2       1       1       0       1       1       4       3       4
-       1       2       0       1       1       1       0       0       1       0
-       0       1       0       0       3       1       1       2       1       2
-       2       0       3       0       0       0       0       0       2       0
-       1       0       1       0       1       0       1       0       0       0
-       0       0       0       2       1       0       0       0       0       1
-       1       0       1       0       1       0       0       0       2       0
-       1       0       2       4       3       0       1       1       1       1
-       0       3       1       2       1       0       1       1       1       2
-       0       1       2       3       1       2       0       2       4       2
-       1       1       0       1       3       0       1       2       5       2
-       3       2       1       2       0       1       1       3       0       1
-       0       1       2       1       1       0       0       0       1       2
-       0       0       0       1       2       1       2       1       1       0
-       1       0       1       0       2       1       2       2       0       1
-       0       0       0       0       0       0       0       1       2       0
-       0       0       0       0                                                
-SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS
-       7      18      25  123944       0       1                                
-FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
-       6       1                                                                
-            time         monitor       Total Cou     angles*1000                
-  0.35860000E+05  0.30000000E+06  0.16132000E+05  0.15280300E+06  0.40200000E+03
-  0.50810000E+05                                                                
-IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
-   16384                                                                        
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       1       0       0       0       0       0
-       2       0       0       0       0       0       1       0       1       0
-       0       1       1       0       2       0       0       0       0       0
-       1       0       0       0       1       1       0       1       0       0
-       0       1       0       0       0       0       0       1       0       0
-       0       0       0       0       0       0       3       0       0       0
-       0       1       0       3       0       0       1       0       0       0
-       1       1       2       0       1       0       0       0       1       0
-       1       1       2       0       2       1       1       0       0       1
-       0       1       0       1       1       0       0       1       0       1
-       1       0       1       0       0       0       0       0       0       0
-       1       0       2       0       1       0       0       1       0       0
-       1       1       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       2       1       0
-       0       1       1       0       1       0       0       0       0       1
-       1       1       1       0       0       1       0       0       0       0
-       1       0       0       0       0       0       0       1       0       0
-       2       1       2       0       0       0       2       0       0       0
-       0       0       1       1       0       2       0       0       0       0
-       0       1       0       1       2       0       0       0       0       1
-       1       1       0       0       0       1       2       0       0       1
-       0       1       1       0       1       0       1       0       2       0
-       0       0       1       0       0       1       0       1       1       1
-       0       0       1       1       2       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       1       0       1       0       4       0       1       0       0       1
-       1       0       0       1       2       0       1       0       2       0
-       1       1       1       1       0       1       1       1       0       1
-       1       0       0       1       1       1       1       0       0       0
-       2       0       0       2       0       1       1       1       1       1
-       0       0       1       0       0       0       2       1       3       0
-       0       0       1       0       0       0       0       0       0       1
-       1       0       0       2       0       0       1       0       1       1
-       0       1       0       2       1       0       0       1       0       0
-       0       0       1       1       0       1       0       0       0       1
-       1       0       0       0       0       0       0       1       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       1       0       1       3       0       0       0       0       0
-       1       0       1       1       0       0       0       1       0       0
-       0       1       0       2       1       0       1       0       1       1
-       0       0       1       1       0       1       1       2       2       0
-       0       1       2       1       1       0       0       2       1       0
-       2       0       0       1       1       0       1       1       0       2
-       1       1       0       1       0       2       1       0       3       1
-       1       1       1       0       0       1       1       1       0       0
-       0       1       0       0       1       0       0       1       1       1
-       1       1       1       1       0       3       2       0       1       2
-       2       1       1       1       0       0       2       0       0       0
-       2       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       1       0       2       0       3       1
-       3       0       1       2       0       0       0       1       0       0
-       0       1       2       1       0       0       4       0       0       0
-       1       2       1       0       1       2       2       1       1       0
-       1       0       1       2       3       1       3       1       2       1
-       2       2       1       0       1       1       0       2       2       2
-       1       1       0       0       0       0       1       3       1       0
-       0       0       1       1       2       2       1       0       0       1
-       0       0       1       1       0       1       2       1       0       0
-       1       0       2       1       1       1       3       1       0       0
-       1       1       0       1       0       2       0       0       1       0
-       0       1       0       1       0       1       0       0       1       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       1       0       2       1       3       0       0
-       1       1       2       0       0       0       1       0       0       0
-       1       1       0       1       0       0       0       0       0       2
-       0       1       0       0       2       2       3       3       3       3
-       2       2       1       0       2       1       0       2       0       1
-       1       0       0       1       1       0       1       1       1       0
-       0       2       0       0       1       0       1       1       0       0
-       1       1       0       1       0       2       2       0       1       0
-       0       0       2       3       1       1       0       3       1       1
-       0       0       0       1       1       1       0       0       1       1
-       2       0       0       0       1       1       0       0       0       0
-       0       0       1       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       2       0       0       1       0       1       3       2       1
-       5       5       1       2       1       5       2       4       4       3
-       1       3       4       7       1       5       4       6       4       2
-       5       5       5       6       5       3       6       5       7       5
-       9       5       5       8       4       7       5       8       6       7
-       3       7       4       3       5       2       4       7       3       2
-       4       4       7       4       5      10       1       6       3       5
-       4       5      10       4       6       8       6       3       4       3
-       7       3       7       8       6       6       2       3       2       3
-       4       2       3       1       2       2       2       0       5       5
-       1       2       3       0       1       2       0       1       0       1
-       0       1       0       0       0       0       0       0       0       0
-       0       1       2       3       3       2       2       4       2       2
-       5       3       4       0       2       2       1       0       1       2
-       2       0       0       3       3       5       4       1       4       1
-       1       2       3       2       6       3       6       2       5       3
-       4       5       4       2       2       2       2       4       3       2
-       5       1       1       2       5       4       3       2       3       5
-       0       5       3       4       0       4       4       3       7       4
-       0       4       4       2       3       4       4       5       5       4
-       3       3       3       3       5       2       1       0       2       4
-       3       1       2       2       2       3       5       0       1       1
-       0       1       3       2       1       3       1       3       1       4
-       1       1       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       1       0       2       0       1
-       5       5       1       2       5       2       3       5       4       4
-       1       3       6       4       4       4       1       2       1       1
-       2       2       2       4       2       3       2       2       4       0
-       4       5       4       4       7       2       3       2       5       2
-       0       4       2       2       6       6       5       4       3       1
-       4       1       0       4       4       4       2       3       3       2
-       1       1       1       6       1       1       1       1       3       4
-       2       1       6       2       1       2       6       2       1       2
-       4       1       4       1       1       1       3       2       5       2
-       2       5       3       4       2       4       3       1       3       2
-       5       1       1       1       1       0       0       0       0       0
-       0       0       0       0       0       1       3       2       2       2
-       1       1       1       2       1       3       2       3       0       1
-       1       1       6       2       0       0       1       4       3       1
-       3       0       1       4       1       0       1       1       3       1
-       2       4       2       5       3       2       3       1       3       3
-       3       1       1       2       1       1       1       0       1       3
-       2       0       1       6       1       2       1       3       1       4
-       4       0       2       0       5       0       2       1       3       3
-       1       3       1       1       2       0       2       1       2       3
-       3       2       3       1       0       1       2       3       1       2
-       1       2       2       2       0       1       1       2       0       0
-       1       4       0       1       0       1       2       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       2       1       0       1       2       0       3       1       3
-       2       2       0       1       2       1       0       1       2       2
-       0       5       2       1       2       1       3       1       1       5
-       2       1       1       1       2       1       2       3       5       5
-       2       0       4       3       2       4       0       1       0       1
-       0       1       3       0       3       3       3       1       2       2
-       0       1       3       5       0       4       1       3       1       2
-       3       2       4       2       0       1       1       0       3       0
-       1       1       1       0       2       2       2       4       2       0
-       1       1       0       2       1       0       0       0       0       4
-       0       4       0       2       0       2       1       0       1       1
-       4       2       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       1       1       3       2
-       3       3       1       2       0       1       3       0       2       1
-       3       1       1       2       1       0       2       1       1       3
-       1       3       0       2       3       2       2       3       4       2
-       1       3       2       3       1       1       1       1       3       3
-       0       3       1       3       3       2       2       1       1       0
-       1       3       0       2       2       0       3       4       1       2
-       3       3       1       2       2       0       1       1       1       2
-       0       2       1       3       1       0       0       2       0       7
-       3       1       2       2       1       2       5       1       2       1
-       1       0       1       1       1       2       1       4       1       0
-       0       1       0       2       0       0       1       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       3       2       1       0       2       1       0       2       2
-       6       2       1       2       0       3       2       0       1       4
-       1       0       2       1       1       2       0       2       2       0
-       3       1       2       2       2       1       1       2       2       1
-       1       1       0       4       0       1       1       4       3       0
-       2       1       1       3       2       2       3       0       1       3
-       1       3       1       1       3       2       2       2       4       0
-       1       3       2       4       1       1       4       0       2       1
-       2       0       2       0       1       1       2       3       1       0
-       1       2       3       2       2       2       5       2       2       6
-       1       2       2       2       3       4       0       2       1       0
-       1       0       0       0       0       0       0       0       0       0
-       1       0       2       2       4       0       4       3       2       2
-       0       4       1       0       1       0       1       1       2       3
-       4       2       2       2       4       4       3       4       4       0
-       1       2       0       1       2       2       3       1       0       1
-       3       0       0       1       0       3       0       1       1       1
-       1       1       4       0       2       3       0       2       4       2
-       1       3       0       4       4       0       1       2       0       1
-       2       1       3       2       0       3       0       1       3       1
-       1       2       3       2       1       3       3       2       3       1
-       5       1       3       1       1       2       1       2       0       1
-       5       0       2       4       0       0       1       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       1       1       0       0       1       1
-       3       4       2       2       2       1       2       1       3       2
-       3       1       1       3       1       2       0       3       1       0
-       0       0       1       1       3       1       4       2       2       1
-       2       2       2       0       1       1       1       5       2       3
-       0       1       1       0       1       3       0       1       2       2
-       2       5       0       0       1       2       1       2       1       0
-       3       2       1       2       1       1       0       0       0       0
-       2       1       2       1       2       0       0       3       2       3
-       0       3       0       0       4       1       2       2       2       1
-       1       5       1       1       1       0       0       0       0       2
-       1       0       0       0       0       0       0       0       0       0
-       0       0       1       0       2       2       3       0       1       2
-       1       1       3       0       0       1       3       1       2       0
-       3       1       1       0       1       4       1       0       2       0
-       3       1       1       3       1       0       2       1       0       2
-       1       2       2       0       2       2       0       2       2       0
-       4       1       0       5       1       2       0       0       3       2
-       3       1       2       0       0       1       0       1       1       3
-       2       0       4       0       2       1       1       1       1       2
-       0       2       0       2       2       1       0       1       0       0
-       1       2       3       0       2       1       1       1       3       4
-       0       1       1       0       0       2       2       1       2       2
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       2       0       0
-       1       2       0       1       0       1       0       1       1       1
-       0       2       0       3       0       2       2       3       2       0
-       2       1       2       1       2       2       2       2       2       2
-       1       1       2       2       0       3       1       1       1       1
-       2       2       2       1       3       1       2       0       3       0
-       0       0       0       2       3       2       0       1       1       1
-       3       2       0       3       0       1       0       2       1       2
-       3       0       8       0       3       1       1       1       3       0
-       0       2       0       0       1       1       3       2       0       2
-       2       0       0       0       1       1       1       0       3       3
-       1       2       3       0       2       1       2       2       0       0
-       0       1       0       0       0       0       0       0       0       0
-       0       0       1       0       0       3       1       1       1       1
-       1       1       1       0       1       2       0       1       2       1
-       1       1       3       2       2       1       1       0       1       1
-       2       6       0       5       0       1       3       1       2       2
-       2       4       2       3       1       2       3       2       2       2
-       0       1       1       1       0       3       1       0       4       2
-       1       1       2       1       0       2       2       1       0       1
-       1       2       1       1       1       0       0       2       0       2
-       0       0       0       3       1       1       2       2       2       3
-       1       1       0       2       4       1       1       2       1       0
-       0       1       3       1       2       2       1       2       0       0
-       1       1       1       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       2       0       1
-       3       0       0       3       1       2       2       0       0       1
-       5       4       1       1       0       3       1       1       1       0
-       1       3       1       0       1       0       2       0       0       3
-       3       0       1       0       1       1       1       2       0       4
-       2       4       0       2       2       2       0       1       0       0
-       1       4       0       3       0       3       2       0       1       0
-       0       0       5       1       4       0       2       1       1       2
-       0       3       3       0       1       2       1       2       0       1
-       1       3       1       5       1       0       0       0       1       0
-       1       2       2       0       0       1       0       2       1       0
-       2       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       3       1       1       1
-       0       0       1       1       0       1       2       1       2       2
-       1       1       2       1       0       1       1       1       0       1
-       0       2       0       1       0       1       1       1       0       3
-       0       0       1       0       1       1       1       2       0       1
-       0       1       1       3       0       0       1       1       1       3
-       0       2       1       2       1       0       0       1       0       0
-       3       2       1       2       0       0       1       2       2       1
-       0       3       1       0       2       1       1       1       1       1
-       1       1       1       2       0       0       3       2       1       0
-       1       2       0       1       0       0       1       0       0       0
-       1       3       0       3       2       0       2       0       1       0
-       0       1       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       1
-       0       0       2       2       0       0       0       0       1       1
-       0       1       3       0       2       0       0       0       2       0
-       0       0       3       0       0       0       1       2       3       0
-       0       0       1       1       1       0       1       1       1       3
-       1       0       1       1       1       1       0       1       1       2
-       1       0       0       1       1       0       4       1       2       1
-       2       2       1       3       1       0       2       1       0       2
-       0       0       2       2       1       0       0       0       2       1
-       1       6       2       0       2       0       2       1       1       0
-       0       1       1       1       0       1       1       3       3       0
-       0       3       0       3       1       1       2       1       1       0
-       0       0       0       0       0       0       0       0       0       0
-       2       0       1       0       0       4       0       2       1       3
-       0       1       1       1       1       0       0       0       1       2
-       0       1       0       0       1       0       2       4       0       0
-       1       1       0       0       0       3       0       0       1       1
-       2       1       0       2       3       3       2       2       2       0
-       1       1       0       2       0       1       1       2       1       2
-       1       2       3       0       2       0       1       0       1       3
-       4       2       1       1       0       1       0       3       2       1
-       3       1       1       1       1       1       2       1       2       1
-       2       1       0       1       1       2       2       4       2       0
-       1       1       3       2       3       0       1       5       0       0
-       1       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       1       0       1       2       1       0       2       0       0
-       2       2       1       2       2       0       1       0       1       0
-       1       0       0       3       2       1       2       0       0       1
-       2       2       0       1       1       2       1       2       0       1
-       1       0       0       0       3       0       1       1       3       0
-       1       3       1       3       3       0       1       1       0       0
-       2       1       2       0       1       2       2       1       0       1
-       1       0       1       4       1       1       1       0       1       2
-       1       3       3       1       0       0       2       0       0       3
-       1       1       0       1       0       0       3       2       0       0
-       1       2       1       1       0       0       1       1       0       1
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       2       0       0       0       3       0       1
-       1       1       1       3       0       1       3       2       1       1
-       0       0       2       0       1       0       0       0       1       1
-       0       1       2       3       1       0       1       1       1       0
-       2       3       2       3       1       2       1       3       2       1
-       3       1       0       2       0       0       2       1       0       0
-       2       1       0       0       1       0       1       1       1       0
-       1       1       1       4       3       4       1       3       1       2
-       2       0       1       1       0       0       0       1       1       0
-       1       1       1       2       1       3       1       1       2       2
-       1       4       1       0       1       0       1       2       0       2
-       0       1       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       2       1       3       1       0       2       1       1
-       2       2       1       2       3       0       0       1       0       0
-       0       1       2       2       0       0       1       2       2       1
-       1       1       0       0       3       2       0       3       0       0
-       0       2       4       2       2       0       1       0       0       0
-       5       0       2       0       1       1       1       1       4       2
-       2       0       0       2       2       0       0       1       2       2
-       1       0       4       2       1       2       3       2       0       1
-       2       3       1       2       1       2       1       2       1       0
-       1       1       3       1       2       3       2       1       1       1
-       2       0       1       2       0       0       1       1       0       0
-       0       0       0       1       0       0       0       0       0       0
-       0       0       0       1       0       2       0       1       1       0
-       0       1       0       0       2       0       1       2       0       1
-       0       0       1       2       1       0       1       0       1       1
-       0       2       1       1       0       2       1       2       0       5
-       1       1       2       1       0       0       1       2       1       1
-       0       2       2       0       1       3       2       1       1       2
-       3       0       1       3       4       0       2       3       2       1
-       1       1       1       1       1       1       1       0       2       1
-       1       1       4       2       1       2       0       1       2       4
-       2       0       0       2       1       1       2       2       1       3
-       0       0       1       0       0       3       1       2       1       2
-       1       0       1       1       1       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       1
-       1       0       0       1       1       3       2       1       1       0
-       1       0       2       3       1       1       0       1       1       1
-       0       0       1       0       0       0       1       0       2       1
-       0       2       0       0       2       0       2       1       1       1
-       3       3       1       0       0       0       2       0       0       1
-       5       1       4       1       2       2       1       1       1       2
-       3       2       0       4       1       1       1       2       2       1
-       0       0       0       2       1       1       0       0       1       1
-       2       1       0       1       0       0       2       1       0       3
-       1       0       2       1       0       1       0       1       0       0
-       0       1       0       0       1       0       0       1       2       1
-       0       0       1       1       0       0       0       0       0       0
-       0       0       0       0       0       1       3       2       0       2
-       1       0       1       0       0       0       0       0       0       0
-       1       1       0       1       2       2       0       2       1       2
-       1       2       2       1       1       0       2       1       1       0
-       2       3       2       2       0       2       1       0       0       2
-       3       2       0       2       1       2       0       1       1       1
-       1       6       0       2       2       0       1       2       0       2
-       0       1       2       1       0       2       4       0       2       2
-       1       0       1       2       1       2       0       2       1       4
-       1       1       1       1       2       3       2       0       2       2
-       2       1       0       1       0       4       0       1       2       0
-       0       0       2       1       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       1       0       0       0
-       0       1       0       3       1       1       2       2       1       1
-       1       1       0       2       0       4       1       0       1       2
-       1       1       0       1       0       1       3       1       1       1
-       3       1       0       0       2       1       2       1       0       2
-       0       0       0       2       1       2       2       1       1       0
-       1       1       2       1       1       1       1       1       0       1
-       2       0       1       1       2       2       2       1       3       4
-       1       1       0       1       1       0       1       3       3       1
-       0       0       0       0       0       1       2       1       2       0
-       1       1       1       0       1       1       2       1       2       1
-       3       0       1       1       1       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       1       0       1       0       0       0       0       0       0
-       0       1       1       0       0       2       2       1       0       0
-       2       1       0       1       1       2       0       2       1       1
-       0       4       0       0       0       1       1       0       0       0
-       1       2       1       0       2       1       3       1       1       1
-       0       1       0       1       0       0       1       3       2       2
-       0       1       1       1       2       1       0       0       0       1
-       1       1       1       2       1       3       2       1       0       2
-       0       1       2       1       1       2       0       1       1       0
-       4       0       1       0       0       0       1       2       0       1
-       0       0       1       0       0       0       0       0       0       0
-       0       0       1       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       1
-       0       1       1       0       2       1       0       0       0       1
-       1       0       1       2       0       0       1       1       0       0
-       0       2       1       2       0       1       0       1       1       1
-       0       1       0       1       1       1       1       0       1       1
-       0       1       0       2       0       1       1       0       0       2
-       2       1       0       1       1       2       1       2       4       3
-       1       1       2       2       1       2       1       1       0       0
-       2       1       1       0       0       1       2       1       2       1
-       0       6       0       0       2       1       2       0       1       0
-       2       3       2       0       2       0       4       2       1       1
-       0       0       2       0       0       0       4       2       0       0
-       2       2       0       0       0       0       0       0       0       0
-       0       0       0       0       0       1       2       1       2       0
-       1       1       1       0       0       0       1       1       1       1
-       1       1       0       2       1       3       0       0       1       2
-       2       0       0       2       1       2       1       0       0       0
-       2       2       3       1       1       0       2       0       2       0
-       2       0       0       0       1       2       0       1       2       0
-       0       0       3       1       1       0       3       1       2       0
-       0       0       1       0       0       0       2       2       2       0
-       2       1       2       0       1       0       0       1       2       0
-       1       1       0       2       0       0       1       2       4       2
-       0       1       3       1       0       2       1       1       1       4
-       2       0       1       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       1       2       1       1       2       1       1       3       1       1
-       1       0       2       1       0       1       2       2       1       1
-       1       2       2       2       2       0       3       2       2       0
-       2       1       2       3       4       0       1       1       1       0
-       0       2       1       0       0       2       3       0       1       0
-       0       1       2       3       3       1       2       1       3       0
-       0       0       2       1       1       0       0       3       2       3
-       0       2       0       2       0       1       2       0       1       0
-       0       0       3       1       2       0       1       1       4       1
-       0       1       1       1       1       0       0       0       1       1
-       0       1       0       0       2       0       1       2       1       0
-       0       0       0       0       0       0       0       0       0       0
-       0       1       1       2       0       0       1       1       1       2
-       1       1       0       2       1       2       0       0       1       3
-       2       1       0       2       3       2       2       0       2       0
-       3       4       0       1       0       0       2       0       3       1
-       1       0       0       1       0       2       1       1       2       0
-       2       1       3       3       1       1       0       2       1       2
-       1       1       4       0       1       1       0       1       1       2
-       2       0       1       2       2       0       3       0       0       0
-       0       0       1       1       0       1       0       0       0       1
-       2       1       2       3       2       0       1       0       0       4
-       0       1       0       2       0       3       1       1       2       1
-       2       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       1       1       1       2       2       3       1       2
-       1       1       2       2       0       0       0       1       0       2
-       2       3       2       1       1       3       0       3       0       1
-       1       1       1       3       1       3       1       2       0       2
-       0       2       3       0       1       0       3       1       3       0
-       0       0       0       0       0       1       0       0       3       2
-       0       1       1       1       1       0       1       0       0       1
-       0       1       0       0       1       2       1       1       0       1
-       2       1       0       3       2       1       1       0       1       1
-       2       0       0       0       1       0       0       2       2       0
-       0       1       1       0       0       2       1       1       2       0
-       2       1       1       0       0       0       0       0       0       0
-       0       0       0       0       0       0       1       0       1       1
-       0       2       1       1       1       1       0       0       1       0
-       3       0       3       1       1       2       1       1       3       5
-       2       0       1       3       1       3       2       2       3       0
-       0       1       1       0       0       0       0       0       1       1
-       3       1       1       1       2       2       3       1       0       2
-       1       0       3       3       0       1       2       2       2       2
-       2       0       3       5       0       2       2       1       1       2
-       0       0       3       1       2       1       3       1       1       2
-       2       0       3       3       0       1       1       1       0       1
-       1       1       1       5       2       2       0       1       3       2
-       0       1       0       2       1       0       0       1       1       0
-       0       1       1       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       2       3       3       3       4       7       7       7      11      14
-      11      11      13      12      15       8      12      13      14       9
-      10      11       9      13      14      16       8       9       9       3
-      12       5       4       6       3       3       8       4       5       3
-       6       2       3       0       5       1       1       3       2       0
-       1       1       3       2       3       2       1       2       3       3
-       4       3       0       4       4       4       3       3       3       3
-       6       0       2       3       2       5       4       1      13       6
-       9       9       6       4       5       5      10      11      10      11
-      10      10      10       7      11      13       5      10      11      10
-      11      16       4      20      12       3       5       2       0       1
-       0       0       0       0       0       0       0       0       0       0
-       1       0       0       0       2       1       0       1       2       1
-       0       2       2       0       0       2       0       1       1       3
-       1       0       1       1       3       2       2       2       0       1
-       3       1       0       2       0       1       4       0       0       0
-       2       2       0       0       0       0       3       1       1       1
-       3       1       0       1       1       2       2       2       0       1
-       2       2       2       1       1       1       1       1       3       1
-       0       2       1       2       3       1       0       5       1       2
-       4       1       4       2       2       2       1       0       1       1
-       0       1       1       1       3       0       1       1       0       1
-       2       1       1       1       0       2       2       1       0       2
-       2       0       0       1       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       1       1       0       0       1       0       0
-       1       2       1       0       0       2       2       1       2       1
-       0       1       2       1       3       2       1       3       1       1
-       0       0       1       1       0       3       1       1       1       0
-       2       2       1       0       1       2       1       0       0       1
-       1       2       1       0       2       2       0       0       0       3
-       2       0       0       2       1       1       3       1       2       2
-       1       2       0       1       1       0       1       0       0       2
-       0       0       2       1       0       2       0       0       1       0
-       3       0       0       2       2       0       3       3       0       1
-       0       0       2       3       0       2       0       1       0       4
-       0       1       0       0       3       1       0       0       0       0
-       0       0       0       0       0       0       1       1       0       1
-       1       0       1       2       2       1       1       4       2       1
-       1       1       1       0       2       0       1       1       1       0
-       0       2       1       1       0       1       0       0       0       0
-       2       4       0       0       0       0       0       1       0       0
-       1       0       0       1       1       2       1       0       1       2
-       0       0       1       0       1       3       0       0       0       2
-       0       1       2       0       1       1       2       0       2       0
-       3       1       0       0       0       1       0       2       1       0
-       1       2       0       0       1       3       1       1       0       3
-       3       1       3       1       3       1       3       2       0       1
-       3       1       0       0       1       0       0       0       0       0
-       1       1       1       0       0       0       0       0       0       0
-       0       0       0       0       0       0       1       1       1       1
-       0       1       1       1       1       3       2       0       4       0
-       1       1       1       0       0       1       0       1       2       0
-       4       1       0       0       1       0       0       2       0       0
-       1       0       3       2       2       3       1       0       1       1
-       0       1       1       1       1       1       2       1       2       0
-       0       1       0       0       1       1       0       0       1       0
-       2       1       1       0       2       3       1       0       0       0
-       2       0       1       1       2       1       1       0       0       0
-       1       0       0       0       3       2       0       0       2       1
-       3       2       0       1       0       0       1       1       0       0
-       1       0       2       1       0       2       2       0       0       1
-       2       0       0       0       0       0       0       0       0       0
-       0       1       0       0       0       1       1       0       0       0
-       2       4       0       5       2       0       2       2       1       3
-       2       1       2       1       0       0       1       0       2       2
-       0       1       1       1       3       3       1       1       0       2
-       1       0       0       0       1       1       0       1       3       1
-       2       1       2       0       0       0       0       0       0       1
-       1       1       1       1       1       0       1       0       0       1
-       1       2       0       0       0       3       4       1       0       0
-       0       0       0       3       0       1       1       2       3       0
-       1       0       0       1       3       0       2       1       1       0
-       0       1       1       1       1       1       3       0       1       2
-       0       0       0       1       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       1       0       0
-       0       1       0       2       0       0       3       1       2       0
-       2       0       2       1       0       0       3       2       0       2
-       0       2       0       2       1       0       0       0       1       1
-       1       0       3       3       0       2       3       3       0       1
-       3       2       2       2       1       0       1       1       0       0
-       2       1       0       1       1       1       3       1       1       1
-       0       0       0       0       1       2       2       2       0       1
-       1       0       3       1       1       0       0       0       0       2
-       0       0       0       0       0       1       2       0       2       1
-       1       0       2       1       0       0       0       3       0       1
-       2       0       1       2       0       1       1       1       0       0
-       0       0       0       0       0       0       0       0       0       0
-       1       1       0       2       0       2       1       1       1       1
-       0       1       0       0       1       1       1       0       1       0
-       2       1       0       0       0       1       1       0       0       0
-       0       0       1       2       1       0       1       0       1       1
-       1       1       0       1       3       0       1       1       0       2
-       0       0       0       1       2       1       0       1       1       2
-       0       2       1       0       1       0       2       0       1       0
-       0       0       0       0       1       0       0       3       2       0
-       0       1       1       0       0       3       0       3       1       0
-       1       1       2       1       0       2       2       2       2       3
-       2       0       0       0       2       0       1       0       1       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       1       0       1       1       1       2
-       1       0       2       0       2       0       1       0       1       0
-       2       0       0       0       0       0       0       2       0       0
-       2       2       1       0       2       2       1       2       1       0
-       0       1       0       0       1       2       0       1       0       1
-       0       1       0       2       2       1       2       1       1       0
-       0       1       2       1       3       0       0       0       1       1
-       0       2       1       0       2       0       2       3       3       1
-       1       0       0       1       3       0       0       1       0       2
-       0       0       0       3       1       1       3       1       0       3
-       1       0       0       2       0       2       0       1       0       2
-       1       2       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       1       0       0       1
-       0       0       1       2       1       0       0       0       0       0
-       4       0       0       0       0       2       1       2       0       1
-       0       2       1       0       0       0       1       1       2       2
-       2       0       1       1       2       2       1       1       0       0
-       0       0       0       1       0       0       1       0       0       0
-       0       0       0       1       0       0       1       1       2       2
-       3       0       0       1       1       0       1       1       3       1
-       1       3       2       1       0       0       0       2       3       0
-       0       3       0       0       1       0       0       1       0       3
-       2       2       0       1       3       2       1       0       1       0
-       0       3       0       1       0       4       1       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       1       0       2       1       1       1       0       0       1       2
-       1       3       0       1       0       1       3       0       2       1
-       2       2       0       0       2       1       0       1       1       2
-       0       1       1       0       0       1       0       1       2       0
-       0       0       2       0       0       2       2       0       2       2
-       1       1       0       1       0       3       0       0       0       3
-       0       0       0       3       1       1       0       4       2       1
-       1       3       0       1       1       2       1       2       0       1
-       0       1       0       0       1       1       0       1       1       1
-       2       1       0       0       0       0       0       0       1       2
-       1       2       0       2       1       2       1       2       1       1
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       1       0       0       0       2
-       2       1       0       1       3       2       0       0       0       0
-       0       2       0       1       1       0       1       3       1       0
-       0       1       0       1       0       1       0       0       2       0
-       1       1       2       0       2       1       1       0       0       1
-       1       1       0       1       1       1       0       0       0       1
-       0       2       0       0       1       0       2       1       0       0
-       2       2       1       1       1       2       1       0       0       1
-       1       1       0       0       1       2       1       1       2       2
-       2       2       0       1       0       2       0       2       2       2
-       1       1       1       2       0       2       0       1       3       2
-       0       0       1       0       1       0       0       0       0       1
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       1       2       1       2       1       1       0       1       1       1
-       1       1       0       0       0       1       0       1       0       1
-       2       1       2       0       1       0       2       1       0       2
-       0       2       1       0       0       2       1       1       1       1
-       3       0       1       1       2       0       5       1       1       0
-       2       4       0       1       1       1       1       0       1       1
-       3       0       1       2       1       1       0       0       3       1
-       1       1       0       0       1       1       1       2       0       2
-       1       0       1       0       1       1       1       0       1       0
-       0       1       1       0       1       1       0       2       0       1
-       1       0       1       2       0       0       0       1       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       1       2       1       3       1       1       1       1       2
-       0       1       0       1       2       1       1       1       2       0
-       2       1       1       0       0       0       1       2       1       0
-       1       1       1       0       1       1       2       0       0       0
-       4       2       2       0       0       0       2       2       2       0
-       0       1       0       0       0       2       0       0       2       4
-       2       5       0       1       1       0       0       1       1       3
-       1       0       2       0       0       2       2       1       0       1
-       0       1       3       2       2       2       1       1       2       0
-       0       2       1       4       1       0       1       0       3       0
-       1       3       1       0       1       1       1       0       0       1
-       0       2       1       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       1       0       0       1       2       1       1       3       1       1
-       0       0       1       2       0       0       2       1       3       3
-       0       0       1       1       3       1       0       0       0       1
-       1       2       4       3       1       1       0       1       1       0
-       2       1       0       1       0       2       0       1       1       2
-       0       1       1       1       2       0       2       0       0       0
-       1       1       0       0       1       4       1       0       2       1
-       0       1       2       3       1       0       0       1       0       2
-       0       1       0       0       0       1       2       2       1       1
-       1       1       2       1       0       1       4       2       0       0
-       0       0       2       1       2       2       0       2       1       2
-       0       0       0       1       0       0       0       0       0       0
-       0       0       0       0       0       0       1       1       0       0
-       1       1       0       0       0       2       2       0       0       1
-       2       0       3       1       2       0       2       0       1       0
-       1       1       0       3       0       0       3       1       1       1
-       1       0       0       0       1       1       3       2       2       0
-       0       2       0       0       1       1       1       1       3       0
-       1       0       0       0       1       2       1       0       1       1
-       0       0       2       2       1       0       1       1       0       0
-       0       1       1       2       2       2       2       0       1       2
-       1       2       0       2       3       2       1       0       2       1
-       0       1       1       0       1       1       0       0       0       0
-       1       1       1       0       0       1       0       0       0       1
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       1       3       2       1       0       0       0       1       0
-       1       1       1       1       1       0       2       2       1       2
-       1       0       0       0       0       0       1       0       1       1
-       0       0       0       2       0       1       0       2       0       2
-       1       1       2       2       2       0       3       2       1       3
-       1       4       0       0       0       0       4       0       0       0
-       1       0       3       1       1       0       0       1       2       0
-       2       2       1       1       2       1       0       0       0       1
-       2       3       1       0       0       2       0       2       0       4
-       2       0       1       0       0       1       0       1       0       2
-       0       1       0       2       0       2       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       1       0       0       1       0       0       1
-       1       0       0       1       1       1       2       1       4       0
-       2       0       1       1       0       1       2       1       2       2
-       0       2       1       2       1       0       2       2       0       1
-       1       3       3       1       0       1       1       1       0       0
-       3       2       5       0       1       1       0       0       0       2
-       3       1       1       4       0       1       0       1       1       1
-       0       3       1       2       3       1       0       2       1       3
-       1       0       1       0       2       1       3       2       1       1
-       2       0       2       1       2       1       2       1       3       2
-       3       1       4       2       3       1       0       1       2       3
-       0       1       0       0       2       1       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       2       1       0       0       0       1       0       0       0       2
-       0       2       0       0       1       0       0       1       2       1
-       0       0       0       3       2       4       1       1       0       0
-       0       0       1       0       2       2       0       1       0       0
-       1       1       2       1       2       1       1       0       0       3
-       0       1       1       0       2       1       0       0       2       0
-       1       0       1       0       2       0       1       0       3       1
-       1       1       0       1       0       2       1       2       0       1
-       1       0       1       0       0       0       1       1       0       0
-       3       0       0       0       0       0       1       2       1       2
-       0       2       3       2       0       0       0       0       2       0
-       1       0       1       1       0       0       0       0       0       0
-       0       0       0       0       0       0       1       0       1       2
-       0       1       1       1       0       0       3       1       1       0
-       1       1       0       0       0       0       1       1       2       2
-       1       1       1       1       2       0       0       4       0       0
-       1       1       0       1       1       1       1       1       0       0
-       2       0       1       1       3       0       1       1       3       0
-       0       1       0       1       1       0       2       2       1       1
-       0       0       3       1       0       1       1       1       1       0
-       2       0       0       0       0       2       1       1       0       0
-       3       3       0       1       2       2       0       0       0       2
-       1       0       1       0       0       0       0       1       1       1
-       0       2       0       0       1       1       2       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       2       1       0       0       0
-       0       0       0       4       0       1       0       1       1       1
-       0       0       4       0       1       2       0       0       0       1
-       1       1       1       1       1       0       1       0       1       0
-       0       0       0       0       1       0       0       0       1       3
-       0       0       1       0       0       1       3       0       1       2
-       0       0       2       1       0       2       0       2       0       0
-       1       2       1       0       2       0       2       2       2       0
-       2       0       1       2       2       1       0       1       0       0
-       3       0       3       0       0       0       0       1       0       1
-       1       1       0       0       0       0       1       1       0       0
-       2       0       2       0       0       2       3       0       1       1
-       0       0       0       0       0       0       0       0       0       0
-       1       0       0       0       0       0       0       0       1       0
-       0       0       0       0       3       1       0       1       0       1
-       0       0       0       1       0       0       0       3       0       0
-       1       1       1       1       0       1       1       0       2       1
-       2       1       0       1       0       0       0       2       0       0
-       1       0       0       1       2       0       0       0       0       1
-       1       0       0       1       1       0       1       1       0       0
-       0       2       0       1       0       0       2       1       2       1
-       1       0       1       0       0       0       0       0       0       1
-       3       1       0       2       1       2       0       2       0       5
-       0       0       0       0       3       0       0       2       1       0
-       1       2       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       1       1       0
-       0       1       1       3       3       1       2       1       3       1
-       1       1       3       1       1       2       2       2       1       1
-       0       3       1       4       2       2       1       0       0       2
-       4       3       2       3       1       2       2       2       0       3
-       4       3       2       7       2       4       5       1       2       2
-       2       2       4       3       4       2       5       2       4       0
-       1       2       6       3       1       3       1       2       2       2
-       4       4       2       3       3       3       3       3       1       1
-       4       1       3       1       1       3       2       2       0       3
-       1       3       2       3       1       2       0       2       2       2
-       3       2       0       3       2       2       0       1       1       1
-       1       0       0       0       0       0       0       0       0       0
-       0       0       0       2       1       3       1       0       0       0
-       0       1       2       0       2       1       1       0       0       0
-       1       0       1       1       0       0       1       1       3       0
-       0       0       1       1       2       1       0       2       1       0
-       0       1       1       2       1       0       1       0       0       0
-       0       0       4       1       2       0       0       1       0       1
-       0       0       0       0       0       1       1       0       2       1
-       0       1       0       1       1       1       0       1       2       0
-       2       1       4       0       1       0       0       0       0       1
-       1       2       1       2       0       1       0       0       0       3
-       2       0       0       1       1       0       1       0       0       1
-       0       1       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       1       0
-       1       0       0       1       0       2       0       0       3       0
-       1       0       1       2       0       0       1       2       1       1
-       0       1       1       1       2       0       0       1       5       0
-       2       1       0       0       3       3       0       1       0       2
-       0       1       0       1       0       0       1       1       0       1
-       1       2       2       2       0       1       1       0       0       0
-       1       0       3       2       0       1       3       1       0       0
-       1       2       1       2       0       0       1       1       0       1
-       2       0       0       0       0       1       0       0       0       1
-       1       0       0       2       0       1       1       1       0       1
-       1       1       2       1       0       1       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       1       0       0
-       4       1       1       0       0       0       1       2       1       0
-       1       2       0       0       2       1       1       1       4       2
-       0       2       0       0       0       1       2       0       0       0
-       1       0       0       1       1       0       1       0       0       0
-       0       2       1       2       1       0       1       3       1       0
-       0       2       0       3       0       1       1       0       2       1
-       0       1       0       1       1       0       0       4       0       0
-       0       0       0       3       2       3       1       1       1       1
-       1       0       2       4       0       1       1       0       0       0
-       0       1       1       0       0       2       1       1       0       0
-       0       1       1       0       2       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       1       0       1       1       4
-       1       2       2       2       0       0       1       2       0       1
-       1       0       1       0       0       0       0       0       1       1
-       2       1       1       0       1       1       0       1       1       0
-       0       0       1       1       2       0       0       0       1       0
-       0       0       1       0       2       2       1       1       1       1
-       2       1       0       0       2       2       0       2       2       1
-       2       1       0       2       0       2       0       0       0       0
-       1       1       0       1       0       2       0       0       0       1
-       1       1       0       1       0       2       0       0       0       2
-       1       1       0       1       0       0       0       0       3       2
-       2       2       0       1       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       1       0       0       1       1       3
-       0       1       1       1       0       2       3       0       0       0
-       0       1       0       1       0       1       1       2       0       0
-       1       2       2       0       2       0       0       1       1       2
-       0       0       0       0       1       5       1       1       2       2
-       0       0       2       0       0       2       1       1       0       1
-       0       1       2       2       2       1       1       0       0       1
-       0       1       1       0       2       0       1       2       2       0
-       0       0       0       1       3       3       1       2       3       2
-       2       2       3       4       1       1       0       1       1       0
-       2       1       3       0       2       0       0       0       0       1
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       2       1       0       1       2
-       0       1       1       0       0       1       0       0       3       0
-       2       0       1       2       0       3       2       2       3       0
-       1       1       0       0       0       1       0       0       4       1
-       1       1       0       3       0       0       1       1       1       0
-       0       0       1       3       1       0       0       0       2       2
-       2       1       0       0       1       0       1       1       1       2
-       0       0       0       2       1       2       3       0       1       2
-       3       0       3       0       0       2       0       0       1       0
-       0       1       1       1       0       1       0       0       0       1
-       0       1       2       1       2       3       0       1       2       1
-       0       1       1       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       1       2
-       1       1       0       0       0       1       1       0       0       2
-       2       1       0       0       2       1       1       1       0       0
-       0       2       1       0       1       2       0       1       0       2
-       2       0       1       1       0       1       0       0       0       0
-       1       1       1       0       0       1       0       1       1       0
-       1       0       2       1       2       0       0       2       2       2
-       1       0       0       0       3       2       2       2       2       0
-       0       1       1       1       0       2       1       2       1       2
-       1       2       1       0       1       2       2       1       0       0
-       0       1       2       1       0       2       1       1       1       1
-       0       1       1       2       2       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       1       1       1       1       1       0       1       0       0
-       0       1       0       2       0       0       1       2       1       1
-       0       1       0       0       1       0       2       1       1       0
-       1       1       2       0       2       1       2       0       1       1
-       0       0       1       1       1       1       1       2       2       0
-       3       1       1       0       0       0       1       2       2       0
-       0       0       1       2       1       0       1       0       0       2
-       1       0       0       1       0       1       1       0       0       1
-       3       2       1       0       1       1       1       0       1       0
-       2       0       0       2       0       0       2       2       2       2
-       0       2       1       0       1       1       1       0       0       1
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       1       0       0       1       2       0       0
-       1       0       1       1       1       0       0       2       0       3
-       1       0       0       1       0       0       0       1       1       0
-       0       1       1       2       1       0       2       2       1       3
-       1       2       0       0       1       2       1       0       2       0
-       0       3       1       1       2       1       0       0       1       1
-       1       1       1       1       0       1       1       1       1       1
-       1       2       0       2       2       0       1       2       2       0
-       1       2       1       1       1       0       0       1       0       1
-       2       0       0       2       0       1       0       0       1       2
-       1       0       1       2       1       1       2       0       1       3
-       0       1       1       0       0       0       1       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       1       1       0       0       1       4
-       2       1       1       0       0       2       1       0       3       4
-       0       1       2       6       2       3       1       4       3       2
-       2       2       0       1       0       1       2       2       0       0
-       2       4       1       0       0       6       3       1       0       2
-       1       1       0       1       0       3       0       2       0       4
-       1       0       1       3       3       1       2       1       3       1
-       4       3       2       1       0       2       0       0       0       3
-       3       1       1       1       1       1       2       3       3       0
-       1       3       1       2       1       1       0       1       2       3
-       1       1       0       0       1       3       1       1       2       3
-       0       0       1       0       0       1       0       0       0       0
-       0       0       0       0       0       0       0       0       3       2
-       5       6       4       3       4       1       2       3       2       6
-       6       2       5       1       3       0       6       7       4       3
-       6       2       4       2       5       1       1       6       3       3
-       4       1       1       1       0       2       1       2       3       5
-       3       1       2       3       3       4       2       1       4       3
-       2       1       5       0       2       3       3       3       5       1
-       4       1       1       1       4       5       6       3       3       5
-       2       3       0       4       2       3       8       4       4       6
-       6       0       5       4       5       5       5       1       4       3
-       0       3       4       1       2       5       7       3       3       3
-       5       4       3       7       1       0       0       1       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       1       0       0       0       3       2       1
-       1       0       0       1       4       0       1       1       0       0
-       2       0       1       3       2       2       1       1       1       1
-       1       1       2       2       1       1       2       2       1       0
-       3       0       0       2       0       0       0       1       0       1
-       0       1       0       1       2       3       0       2       1       1
-       1       0       3       1       2       0       0       1       0       1
-       2       2       0       4       0       0       1       2       1       0
-       1       3       0       2       0       1       3       0       0       0
-       1       3       0       1       1       0       0       0       0       1
-       2       0       0       2       1       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       1       1       0       2       0       0       1       1
-       1       1       1       2       1       0       2       0       1       0
-       0       0       2       2       2       0       1       0       1       0
-       3       1       3       4       0       1       1       0       0       0
-       0       1       3       0       2       1       1       1       0       1
-       0       1       0       1       1       0       2       2       3       1
-       1       0       0       0       0       0       0       1       0       1
-       1       1       2       0       3       0       0       1       0       1
-       0       3       3       2       0       2       1       1       0       3
-       1       1       0       0       1       2       0       0       2       1
-       0       2       2       0       2       0       1       2       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       1       0       0       2       1
-       1       1       0       1       0       4       2       1       1       1
-       1       2       1       0       1       2       1       1       1       1
-       0       1       0       2       1       0       0       2       2       1
-       0       1       3       0       1       0       2       2       1       0
-       2       0       0       0       0       0       0       0       2       1
-       3       0       1       0       1       1       0       3       0       2
-       0       0       0       0       1       0       1       1       1       1
-       1       3       2       1       0       0       0       0       0       2
-       1       1       1       2       0       1       1       1       0       1
-       0       0       2       1       1       1       0       1       0       1
-       1       1       0       0       2       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       2       0       1       0       0       2       2       0       0       0
-       0       0       1       0       0       0       3       1       4       1
-       0       0       1       1       0       0       1       0       0       1
-       1       0       1       0       2       0       3       0       2       0
-       1       1       1       1       1       0       1       1       0       1
-       1       1       2       1       1       0       1       0       0       0
-       1       1       2       0       0       1       2       1       0       0
-       1       0       0       1       0       2       2       1       0       0
-       1       3       0       1       0       1       1       1       4       1
-       1       3       0       0       1       2       1       3       0       1
-       1       0       0       1       0       1       0       0       1       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       1       0       2       1
-       1       0       1       0       0       2       2       2       2       1
-       2       1       0       1       2       1       2       2       0       1
-       0       1       1       0       1       2       1       0       1       0
-       1       0       3       0       0       1       1       2       1       0
-       0       0       1       1       0       1       0       1       2       1
-       1       2       0       1       1       1       1       0       2       1
-       1       0       1       2       2       0       1       3       2       1
-       2       0       2       1       1       1       1       0       0       0
-       1       1       1       1       0       2       0       1       0       1
-       0       1       3       0       3       2       2       0       2       1
-       0       0       1       0       1       0       0       0       0       0
-       0       0       0       0       0       0       0       0       1       1
-       0       3       1       1       1       3       1       1       1       0
-       0       1       0       2       1       0       2       2       2       2
-       2       1       1       3       0       3       0       2       0       1
-       5       2       0       3       1       4       2       3       2       2
-       1       2       1       2       5       2       1       1       4       0
-       1       4       2       1       1       1       0       3       3       1
-       3       1       2       2       4       1       2       2       0       1
-       1       0       2       1       3       4       2       2       0       2
-       1       1       0       4       0       0       3       2       1       0
-       1       2       2       1       2       2       0       1       2       1
-       1       2       2       2       0       1       0       0       1       0
-       1       1       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       1
-       1       0       0       0       0       1       0       1       1       1
-       1       0       0       0       1       0       0       0       0       1
-       1       1       0       1       1       0       0       1       2       0
-       0       0       3       3       1       0       2       0       0       1
-       0       1       1       2       0       1       0       2       0       1
-       1       1       1       0       1       1       0       0       2       0
-       0       0       0       2       2       0       1       1       0       1
-       2       1       0       0       0       2       1       2       0       1
-       1       1       1       0       1       2       1       0       2       1
-       0       0       0       2       1       0       0       0       0       2
-       1       0       1       1       1       0       0       2       1       0
-       0       0       1       0       0       0       0       0       0       0
-       0       0       0       1       0       0       0       0       0       0
-       0       0       0       1       1       2       0       0       0       2
-       0       1       0       1       2       0       2       1       1       0
-       2       0       0       0       1       1       1       2       1       0
-       0       2       1       0       0       1       1       0       2       1
-       0       0       0       1       1       1       1       0       1       0
-       0       0       2       1       4       0       0       0       0       0
-       1       0       1       2       1       1       1       1       0       1
-       0       2       1       0       1       1       2       1       2       2
-       0       0       1       2       3       1       0       0       0       4
-       2       2       2       0       1       0       1       0       1       2
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       2       1
-       1       0       0       2       1       1       2       0       1       0
-       1       1       1       0       1       1       0       0       1       1
-       0       1       2       2       0       0       0       3       0       1
-       2       0       0       1       1       1       1       1       0       0
-       1       0       1       0       0       3       0       0       0       0
-       2       2       1       2       1       2       1       1       0       3
-       0       3       0       2       2       0       0       2       0       0
-       2       0       0       1       0       1       1       0       0       1
-       2       0       0       1       1       0       0       1       1       2
-       2       1       0       0       0       0       0       1       0       0
-       0       1       1       1       2       1       1       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       1       1       0       1       1       0       0
-       1       0       1       0       0       0       3       3       0       1
-       0       3       2       1       0       1       0       0       1       1
-       1       1       0       3       0       1       0       1       1       0
-       1       0       1       1       1       1       0       1       0       3
-       0       0       1       3       2       1       0       0       0       1
-       1       3       2       2       1       1       1       1       1       4
-       1       0       0       1       0       1       0       0       1       2
-       0       2       1       1       1       1       0       2       0       0
-       3       0       0       2       0       2       0       0       1       2
-       0       0       0       0       1       1       2       0       0       1
-       1       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       1
-       0       0       0       0       3       0       0       1       0       1
-       0       0       0       4       2       2       0       2       3       2
-       2       1       0       0       1       2       1       2       0       0
-       2       1       1       1       0       2       0       2       0       1
-       0       2       0       1       0       1       0       1       0       1
-       0       1       1       3       3       0       0       1       0       0
-       2       2       3       1       1       0       2       1       0       0
-       0       0       0       0       0       1       2       0       1       1
-       0       2       3       0       0       0       0       1       0       1
-       1       2       0       3       0       3       2       0       2       2
-       3       1       0       1       3       0       2       0       0       1
-       1       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       1       0       0       1       1
-       0       0       0       1       2       1       1       0       2       1
-       0       2       0       1       2       0       0       3       0       1
-       0       0       0       3       0       0       0       0       1       0
-       3       1       0       0       0       1       1       1       1       1
-       1       1       0       3       2       1       0       1       1       1
-       1       0       0       2       1       2       2       1       2       2
-       0       2       0       2       2       2       2       2       0       0
-       2       0       3       0       1       5       0       0       0       1
-       1       0       1       0       1       1       0       0       0       1
-       3       2       1       0       0       1       1       0       1       0
-       1       0       1       0       1       0       1       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       1       0       1
-       1       3       4       0       3       2       2       3       3       3
-       1       0       1       1       1       2       1       1       2       3
-       3       3       2       1       0       1       0       0       2       1
-       0       0       1       2       5       2       3       3       3       1
-       0       1       0       2       1       0       1       2       4       2
-       0       0       1       4       0       0       2       3       0       1
-       1       1       6       0       0       2       1       0       1       0
-       1       0       2       0       1       1       0       4       0       0
-       1       1       0       3       0       2       2       1       0       1
-       3       1       1       0       1       1       1       2       1       2
-       1       3       1       0       2       1       0       4       0       0
-       1       1       0       0       0       0       0       0       0       0
-       0       0       1       0       0       0       0       1       0       0
-       1       2       3       2       1       0       0       1       1       1
-       1       1       1       0       0       0       1       0       2       2
-       0       0       1       1       1       1       1       0       2       0
-       2       0       0       1       2       0       0       0       1       1
-       2       0       2       0       0       1       1       2       1       0
-       0       1       0       0       0       1       1       0       1       2
-       1       0       1       1       0       0       0       2       1       2
-       0       4       3       0       1       1       0       1       2       0
-       1       1       0       0       3       0       0       0       1       2
-       0       1       0       0       0       0       1       1       0       0
-       0       1       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       1       0       0       0       2       0       0       0
-       3       0       1       1       1       1       0       0       0       0
-       2       0       0       1       0       1       3       0       1       0
-       0       2       0       1       0       1       0       1       0       1
-       4       0       0       1       1       2       1       1       0       1
-       1       0       1       3       0       1       0       0       0       2
-       1       2       2       0       0       2       0       1       1       0
-       0       0       0       0       3       3       0       2       1       1
-       0       0       1       1       1       0       1       0       1       0
-       1       1       0       1       1       1       0       1       0       0
-       0       0       1       1       1       1       2       0       3       1
-       0       0       1       1       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       1       0
-       1       1       2       1       0       1       1       1       0       1
-       0       0       1       0       1       0       1       1       1       3
-       1       1       3       1       2       0       0       1       2       3
-       2       0       1       2       2       1       0       2       2       3
-       1       0       1       0       1       2       0       2       0       0
-       1       0       2       0       2       2       0       1       0       0
-       1       1       0       1       1       0       1       1       1       0
-       0       1       2       1       0       0       0       2       2       2
-       1       0       1       0       1       0       1       1       2       1
-       1       0       0       1       0       1       1       1       0       0
-       2       2       1       1       0       0       1       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       1       0
-       1       0       0       0       0       2       0       1       3       0
-       2       1       0       1       1       0       1       0       2       0
-       0       0       0       0       0       0       2       2       1       1
-       1       1       0       2       2       1       1       2       1       1
-       2       2       1       1       0       0       1       1       0       0
-       1       1       2       2       1       0       0       1       0       2
-       0       1       1       0       2       0       2       0       1       0
-       0       1       0       2       0       0       2       2       3       0
-       4       0       1       1       1       0       1       0       1       0
-       1       0       0       0       0       3       1       1       1       2
-       0       0       1       1       1       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       1       0       0       0       1       0       0
-       1       0       0       0       2       2       2       0       0       2
-       1       1       2       0       3       0       0       1       1       2
-       1       2       1       0       0       2       0       2       4       2
-       1       3       1       1       3       1       0       0       2       0
-       1       1       0       1       1       0       3       0       2       0
-       1       0       2       1       2       0       0       0       2       0
-       1       2       1       0       0       0       1       1       2       1
-       3       0       2       1       1       2       0       0       0       0
-       1       1       0       0       3       0       0       2       2       1
-       0       0       1       1       0       1       0       2       0       1
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       1       0       2
-       0       0       0       1       1       0       0       2       0       1
-       0       0       1       0       0       1       2       2       0       1
-       1       0       0       0       2       2       1       1       0       1
-       1       0       1       0       1       0       1       1       1       1
-       1       3       1       0       1       0       0       0       3       0
-       1       1       0       0       2       0       2       0       0       0
-       1       1       2       0       2       0       2       1       1       1
-       1       1       0       1       0       1       1       2       2       1
-       0       0       3       3       1       1       1       0       0       0
-       0       2       2       1       2       1       0       0       0       1
-       1       2       1       1       1       2       0       0       0       0
-       0       0       0       0       0       0       0       1       2       0
-       1       3       0       1       3       2       2       0       1       0
-       1       0       1       2       0       3       3       1       2       1
-       1       0       2       2       0       1       2       3       0       0
-       0       0       0       1       0       1       2       1       0       0
-       0       0       0       0       2       0       0       0       0       1
-       1       1       3       1       0       1       0       1       0       0
-       0       0       1       3       0       1       0       0       0       2
-       4       1       3       2       1       0       1       3       1       1
-       1       1       1       1       1       2       0       1       1       0
-       0       4       1       3       5       1       1       2       1       0
-       1       2       3       2       1       0       1       2       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       1       1       0       1       0       0       2       1       0       1
-       0       0       0       0       1       1       3       0       1       3
-       2       0       1       3       0       1       0       0       0       2
-       0       2       2       1       0       0       2       2       2       2
-       2       1       1       0       1       0       0       1       1       0
-       1       1       1       0       0       3       0       1       0       1
-       0       0       2       0       0       0       1       2       2       2
-       1       0       1       0       1       0       0       2       1       2
-       0       0       2       1       0       0       0       0       2       2
-       0       0       2       1       2       2       1       1       0       0
-       3       2       0       1       1       0       1       0       0       2
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       1       0       2       0       0       1
-       2       1       2       0       1       0       0       0       0       0
-       0       1       0       1       0       0       1       2       0       1
-       2       1       0       0       0       0       1       2       0       1
-       1       1       0       1       0       2       2       1       2       0
-       2       0       1       0       0       0       2       2       1       0
-       0       0       0       0       1       0       1       0       0       2
-       1       0       3       0       1       2       1       1       0       0
-       3       0       0       1       0       0       0       1       1       1
-       2       0       1       4       0       1       0       1       0       0
-       0       0       2       1       1       0       1       0       0       4
-       1       0       1       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       1       1       1       0       0       1       2       1       2       0
-       1       1       2       0       2       0       2       1       0       2
-       0       2       0       1       1       2       0       0       1       1
-       0       2       0       1       0       0       1       0       1       1
-       0       0       2       2       0       0       2       1       1       2
-       0       0       0       0       1       2       3       1       1       1
-       1       1       4       1       2       0       0       0       1       1
-       2       1       2       0       0       0       1       0       0       0
-       1       1       1       1       1       1       0       1       0       1
-       0       0       0       0       0       0       1       1       2       0
-       0       0       1       0       1       0       1       0       1       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       2       1       0       1       1       0       0
-       3       0       2       0       1       1       2       0       1       0
-       2       1       2       0       0       1       1       1       0       0
-       1       0       1       1       1       0       2       0       1       0
-       1       1       0       2       0       1       0       0       1       1
-       1       0       2       0       2       2       1       1       0       0
-       1       1       2       0       0       0       0       1       0       1
-       1       1       1       1       1       0       0       0       1       0
-       1       1       2       1       2       0       2       0       3       1
-       0       1       2       0       0       0       1       1       0       0
-       0       0       0       0       2       0       0       1       1       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       1       0       1       0       0       1       1       0
-       2       2       1       0       0       2       1       1       1       0
-       1       1       1       2       1       0       1       1       1       2
-       1       2       1       1       0       1       1       0       0       0
-       2       1       0       0       1       1       0       1       0       3
-       0       0       0       0       0       0       0       0       1       1
-       1       0       1       0       2       0       3       0       0       0
-       1       2       0       1       0       2       0       0       0       1
-       1       0       0       1       1       0       0       1       0       1
-       1       0       0       0       1       0       0       1       0       2
-       0       0       0       1       1       1       3       1       0       1
-       1       0       0       0       1       1       0       0       0       0
-       0       0       0       0       0       0       1       0       0       1
-       1       1       1       0       0       1       1       1       0       1
-       0       0       0       0       0       0       0       1       0       1
-       0       0       0       0       1       2       0       0       0       0
-       1       1       1       0       0       0       1       1       1       2
-       0       2       0       0       0       2       0       1       1       2
-       0       0       0       1       1       0       0       2       2       1
-       1       1       0       0       1       1       0       0       0       0
-       0       1       0       0       0       0       0       0       0       1
-       0       1       0       0       1       2       0       0       1       1
-       0       2       2       2       0       1       0       1       0       0
-       1       2       0       0       1       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       1
-       0       0       1       2       1       1       1       1       1       0
-       1       0       1       4       3       1       3       2       1       0
-       1       0       0       0       0       3       2       2       1       3
-       2       1       0       0       1       1       4       1       0       2
-       3       1       1       0       3       1       3       0       1       0
-       1       2       2       1       2       0       2       0       0       1
-       2       3       1       2       2       1       1       1       1       2
-       2       1       1       0       2       1       0       1       4       1
-       2       0       1       0       0       0       3       3       3       0
-       2       1       0       1       1       1       3       1       0       5
-       1       1       2       1       2       2       1       1       1       1
-       0       2       0       0       0       0       0       0       0       0
-       0       0       1       1       1       3       4       2       6       7
-       2       1       5       3       0       5       7       6       2       3
-       4       7       1       5       3       3       2       1       4       3
-       7       3       2       7       4       7       5       8       6       7
-       5       6       5       6       9       6       7       7       3       9
-       4       4       4       8       5       5       5       5       8       4
-       5       6       6      13       6       7       4       4       8       7
-       7       7       7      10       7       5       5       4       6       3
-       7       1       7       7       8      11       5       9       5       3
-       7       7      10       4       4       5       4       2       3       6
-       4       2       3       5       6       0       5       6       3       3
-       5       0       1       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       1       0       0       1       1       1
-       2       1       2       1       0       2       0       2       2       0
-       1       2       0       2       0       0       1       2       0       0
-       1       1       1       1       0       0       1       2       1       1
-       1       2       0       1       2       1       0       0       0       0
-       1       2       0       1       0       0       1       2       1       0
-       3       1       0       3       2       0       0       0       1       1
-       1       1       0       0       1       4       0       0       0       0
-       2       1       0       0       1       0       0       2       1       0
-       0       0       0       1       0       1       1       1       3       1
-       1       0       1       0       1       2       1       4       2       0
-       0       1       0       0       1       0       0       2       0       0
-       0       0       0       2       0       2       0       0       1       2
-       1       1       1       2       1       0       0       1       2       0
-       1       1       3       0       0       3       1       0       3       0
-       3       0       1       2       0       2       3       1       2       0
-       1       1       1       3       1       2       1       1       0       1
-       2       0       0       0       2       0       2       1       0       1
-       1       0       0       0       0       2       2       1       1       0
-       0       0       0       0       1       2       1       1       0       1
-       1       0       0       0       0       1       2       2       0       2
-       2       0       2       1       0       1       2       2       1       2
-       2       0       0       0       1       0       1       1       0       0
-       0       0       0       1       0       3       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       2       0
-       0       0       0       1       1       1       1       0       1       0
-       0       3       0       2       3       2       0       0       0       0
-       1       1       0       0       0       2       0       0       0       4
-       1       2       2       0       2       1       0       1       1       0
-       1       0       1       1       1       1       0       0       0       1
-       1       1       0       1       1       1       0       0       2       2
-       0       1       2       0       1       3       0       0       2       3
-       3       3       1       3       1       1       0       1       0       1
-       3       2       0       1       1       0       1       1       1       0
-       2       1       2       0       1       1       1       1       1       0
-       1       3       1       0       0       4       1       0       1       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       1       2       3       1       1
-       1       0       1       1       0       1       1       0       1       3
-       2       2       1       2       2       1       2       0       3       1
-       3       2       1       2       2       1       3       0       2       2
-       0       0       1       1       1       1       1       1       0       1
-       3       1       1       0       4       0       2       5       2       0
-       1       1       1       0       1       2       2       1       2       0
-       1       1       1       0       0       2       2       3       4       1
-       3       0       0       3       2       0       2       2       2       0
-       0       2       1       1       2       2       1       1       3       4
-       2       2       2       0       1       3       2       0       2       1
-       2       0       1       1       3       0       1       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       2       1
-       1       1       2       1       0       2       0       1       1       1
-       0       0       1       1       1       0       0       1       1       3
-       2       1       0       2       1       4       2       1       1       0
-       0       1       0       0       1       0       1       0       2       0
-       0       1       1       0       0       1       1       1       2       0
-       0       2       2       1       0       1       0       2       0       2
-       0       0       2       0       0       0       0       0       1       0
-       2       0       0       0       0       0       0       0       2       0
-       0       1       0       3       0       0       1       0       3       0
-       2       0       1       0       0       0       0       0       1       1
-       1       0       1       1       2       2       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       2       1       3       1       0       0       0       3       0       1
-       1       3       1       2       2       0       2       0       0       1
-       0       0       0       0       2       0       0       1       0       0
-       1       1       0       0       0       1       0       2       1       1
-       0       1       1       2       1       2       0       0       0       0
-       2       0       1       0       2       3       1       0       1       1
-       1       1       1       0       0       2       1       0       1       2
-       1       2       1       2       2       0       0       0       2       0
-       0       1       1       1       1       1       2       1       1       0
-       0       0       1       2       0       2       2       1       1       0
-       1       2       1       1       1       2       1       1       2       0
-       0       0       1       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       2
-       0       3       5       0       3       3       3       1       1       4
-       1       3       2       4       5       1       2       2       1       2
-       2       4       0       1       0       2       1       3       2       0
-       1       1       1       2       0       5       1       3       4       1
-       2       1       2       2       1       2       0       2       1       1
-       1       3       2       0       1       2       2       1       1       1
-       1       0       2       2       2       0       1       2       2       2
-       3       1       2       3       2       3       2       1       1       2
-       1       1       1       1       1       2       1       2       0       2
-       0       1       2       1       1       1       1       1       1       3
-       1       1       2       0       0       0       0       0       0       1
-       0       0       0       0       0       0       0       0       1       0
-       1       1       4       1       1       0       1       3       0       1
-       2       0       2       3       1       1       2       1       0       2
-       0       1       1       1       1       0       0       4       2       0
-       1       1       0       0       1       1       1       0       4       0
-       2       0       2       0       1       0       2       1       2       2
-       0       1       0       1       0       0       2       1       1       3
-       0       1       0       2       0       0       0       0       2       0
-       0       0       0       1       1       3       2       2       3       2
-       0       2       1       2       1       1       2       0       2       2
-       1       0       1       3       1       2       3       0       2       0
-       0       1       0       2       0       1       0       0       0       1
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       1       0       0       2       1       1       3
-       0       0       2       0       2       1       1       2       1       2
-       2       0       1       0       1       0       0       1       0       0
-       1       1       1       0       1       0       0       2       0       1
-       0       2       1       1       0       0       3       1       2       0
-       1       1       1       2       2       1       0       3       1       1
-       2       0       1       0       1       0       0       0       0       1
-       0       0       2       2       1       0       1       1       2       1
-       1       0       3       1       1       0       0       0       1       0
-       1       0       0       0       0       2       2       0       0       1
-       0       2       0       1       0       0       2       0       0       0
-       0       0       0       0       0       0       0       0       0       2
-       0       0       0       0       3       0       0       1       3       1
-       0       0       1       0       0       0       0       1       0       0
-       0       1       1       1       1       1       0       2       1       1
-       0       2       1       0       2       0       1       1       0       4
-       1       1       0       1       2       1       0       1       0       0
-       4       0       0       0       0       1       0       3       2       2
-       1       1       0       0       2       0       1       2       0       2
-       1       2       0       0       1       1       0       0       1       0
-       1       1       0       2       1       1       2       1       2       2
-       2       0       1       0       2       1       0       1       0       0
-       2       1       1       0       0       1       1       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       1       0       1       1       0       0       2       1       3       1
-       2       1       2       0       0       1       2       1       1       0
-       0       0       2       2       0       1       2       1       0       2
-       2       1       3       2       1       0       0       2       2       0
-       1       0       1       1       1       1       0       1       1       3
-       0       1       4       1       1       0       3       2       2       1
-       1       2       1       3       2       4       0       1       1       0
-       0       2       0       0       1       2       0       1       0       2
-       0       0       0       3       1       0       2       1       0       1
-       1       2       0       0       0       0       0       0       1       1
-       0       1       0       0       0       1       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       3       1       2       0       1       1       0       0       3       2
-       1       0       0       0       0       0       0       1       1       1
-       1       0       3       0       0       1       1       0       1       2
-       0       0       1       1       0       1       1       2       0       1
-       0       2       1       0       0       0       1       0       1       1
-       1       0       2       1       0       0       0       1       0       1
-       0       0       4       1       1       0       1       0       1       2
-       0       2       1       0       0       0       1       1       1       0
-       0       0       0       0       0       2       0       1       0       0
-       1       0       0       1       0       2       1       0       1       0
-       0       0       1       1       0       1       0       2       1       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       1       1       1       1       1       1       0       0
-       1       1       0       3       0       0       1       0       1       1
-       0       3       1       1       2       2       0       0       0       0
-       0       3       1       0       1       0       0       2       1       1
-       0       2       0       2       1       1       3       4       0       3
-       2       1       0       2       3       0       2       0       0       0
-       0       0       0       1       0       0       1       0       1       0
-       0       1       1       0       3       1       0       0       0       1
-       1       0       1       2       1       1       0       1       0       3
-       1       1       0       1       1       0       2       2       1       3
-       0       0       0       0       0       1       1       1       2       0
-       0       1       0       0       0       0       0       0       0       0
-       0       0       1       0       2       1       1       1       0       1
-       0       1       0       0       0       1       0       1       1       1
-       2       1       0       1       3       1       1       1       0       1
-       0       2       1       3       3       1       0       0       0       1
-       2       0       1       2       1       0       1       1       0       1
-       1       0       0       2       1       1       1       2       1       1
-       1       0       1       2       0       3       1       1       3       2
-       0       2       2       0       1       2       1       0       1       1
-       1       0       0       0       0       1       1       0       1       0
-       0       2       1       0       2       0       0       0       0       0
-       0       0       0       0       1       0       0       2       0       1
-       2       0       1       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       1       1       0       1       1       0       1       0       0       1
-       0       0       1       3       1       1       2       2       0       2
-       1       0       4       1       3       1       1       1       0       1
-       2       1       1       1       0       0       0       1       1       1
-       2       3       4       2       1       0       3       1       1       3
-       2       2       0       1       0       1       1       0       0       1
-       0       0       0       0       0       1       1       0       0       0
-       1       0       0       2       1       1       0       0       0       1
-       1       0       1       0       0       2       1       0       0       1
-       2       0       0       1       0       1       0       3       2       2
-       0       1       0       1       1       0       1       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       2       1       0       0       1       0       0       0
-       1       1       1       1       1       0       2       2       0       0
-       1       0       0       1       1       1       0       0       2       1
-       1       2       0       3       0       1       0       1       1       3
-       0       0       1       1       3       2       1       0       2       0
-       0       2       0       1       1       0       1       0       2       0
-       0       2       0       0       2       1       0       1       1       3
-       0       2       1       0       2       0       1       1       0       1
-       0       1       0       0       1       2       1       1       0       0
-       2       0       1       2       0       1       2       2       0       2
-       1       0       1       1       3       1       0       1       2       0
-       1       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       1       0       0       1       0
-       1       1       0       0       0       1       0       1       0       2
-       0       0       2       1       1       3       1       0       0       0
-       2       1       1       0       0       4       4       1       2       1
-       2       0       0       0       1       1       1       1       3       0
-       1       1       0       2       0       0       1       2       1       1
-       1       0       0       1       0       0       1       1       1       0
-       1       0       1       1       0       1       2       0       1       1
-       2       0       0       1       0       0       2       1       0       0
-       3       0       1       1       1       0       0       1       1       1
-       3       2       0       1       0       0       1       1       0       0
-       0       0       3       1       2       0       0       0       0       0
-       0       0       0       0       0       0       0       0       1       0
-       0       1       0       0       0       0       0       1       0       3
-       2       0       0       1       0       0       0       2       0       0
-       0       0       4       1       0       2       0       1       2       0
-       1       0       0       0       1       0       0       3       0       2
-       1       3       1       0       3       1       0       0       1       0
-       3       1       1       3       1       0       2       1       1       1
-       1       1       0       3       1       1       1       2       1       1
-       0       2       0       0       0       1       1       1       0       1
-       0       0       1       2       0       2       1       0       2       1
-       3       1       2       0       2       0       1       1       0       1
-       0       0       1       2       3       1       1       1       1       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       2       1       0       0       1
-       0       0       1       0       0       1       2       1       0       1
-       0       0       2       0       1       0       1       1       0       2
-       0       0       4       2       0       1       1       0       1       0
-       0       0       1       1       1       0       1       2       1       0
-       0       0       0       0       1       3       2       1       0       2
-       1       0       1       0       2       1       0       1       2       0
-       1       1       0       1       0       2       1       0       0       1
-       0       1       0       0       1       1       1       0       1       2
-       2       1       1       1       1       0       0       2       0       0
-       1       0       0       1       2       0       0       0       3       1
-       1       3       0       1       0       1       0       0       0       0
-       0       0       0       0       0       0       0       0       0       1
-       0       0       1       0       0       1       1       0       0       0
-       0       2       2       1       2       1       0       2       2       0
-       3       0       1       1       0       0       0       1       2       0
-       0       0       2       0       0       0       1       1       3       1
-       1       0       1       1       1       0       0       0       0       2
-       1       0       1       0       1       1       0       2       0       0
-       1       0       2       1       3       1       0       0       0       1
-       4       1       0       2       1       3       0       4       3       0
-       1       2       0       3       1       0       0       3       1       0
-       2       1       1       1       1       1       0       3       1       1
-       1       2       0       2       2       2       0       2       0       2
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       1       1       1       1       0       0       1
-       1       0       1       1       1       2       1       2       1       1
-       0       0       1       3       1       1       1       3       2       0
-       0       0       0       0       1       3       2       3       0       1
-       2       0       0       1       1       0       2       0       1       0
-       0       1       0       1       0       1       1       1       3       2
-       1       0       0       2       0       3       1       0       1       0
-       2       1       1       0       0       2       0       1       0       0
-       2       0       2       0       3       0       0       1       1       2
-       1       1       0       0       2       1       0       1       1       2
-       0       0       1       1       0       1       3       0       2       2
-       0       0       1       0       2       1       0       0       0       0
-       0       0       0       0       0       0       0       0       0       1
-       2       1       0       1       0       0       1       1       2       0
-       0       0       0       2       1       1       1       4       0       0
-       1       1       1       1       0       1       1       0       1       1
-       0       0       1       0       1       0       2       0       0       4
-       1       0       2       0       2       0       2       0       0       1
-       0       0       1       0       0       1       3       1       1       1
-       2       2       2       1       1       0       0       3       1       0
-       2       0       2       0       1       1       0       1       0       2
-       1       0       2       0       4       2       1       0       1       0
-       1       1       2       1       0       2       0       0       1       0
-       2       1       1       1       0       1       0       0       1       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       1       1       1       1       1       1       2
-       1       2       0       0       1       2       3       1       2       2
-       0       1       4       1       1       1       0       0       1       3
-       2       1       1       0       2       1       3       2       0       1
-       3       4       0       0       0       0       2       2       1       1
-       0       1       2       1       0       0       1       0       2       0
-       0       1       1       1       2       2       3       3       1       1
-       0       3       0       1       2       0       3       0       2       0
-       1       2       1       0       1       1       0       0       0       0
-       1       1       0       2       0       0       0       2       2       0
-       2       2       1       1       1       2       1       2       0       2
-       2       2       0       1       0       0       0       0       0       0
-       0       0       0       0       0       0       1       0       0       1
-       1       3       2       2       1       3       0       2       2       2
-       0       1       1       2       0       1       2       0       1       1
-       0       0       1       0       2       0       0       0       1       1
-       1       1       1       1       1       2       0       1       3       2
-       0       2       2       0       1       1       0       2       2       1
-       3       0       2       1       0       0       1       2       1       0
-       1       1       0       0       0       0       0       0       2       1
-       1       0       0       1       2       1       2       1       0       1
-       0       1       1       2       0       0       3       0       0       0
-       0       1       0       0       0       2       2       2       0       1
-       2       1       1       0       0       0       1       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       1       0       0       0       4       1       2       2       1
-       1       1       1       1       0       3       1       2       0       1
-       0       1       0       1       1       0       2       0       0       0
-       1       1       0       3       0       1       2       2       1       0
-       0       1       1       0       2       3       0       0       0       1
-       1       1       0       0       2       1       0       0       0       0
-       2       3       0       2       2       2       0       1       1       1
-       0       1       1       0       0       3       2       2       3       2
-       0       2       4       0       1       1       1       1       0       1
-       2       0       1       1       2       0       2       0       1       0
-       0       2       3       1       1       2       0       0       1       1
-       1       2       2       0       0       0       0       0       0       0
-       0       0       0       1       1       0       1       0       0       1
-       2       1       0       0       0       4       3       2       1       3
-       1       3       2       1       0       2       3       2       1       1
-       0       0       0       0       1       1       0       0       2       1
-       3       1       2       1       2       2       0       0       1       2
-       3       0       2       0       1       0       1       1       2       1
-       2       1       0       1       0       0       0       2       0       1
-       1       0       1       0       0       1       2       2       1       3
-       1       2       1       0       0       3       3       1       1       0
-       0       2       1       1       2       2       2       3       0       0
-       2       2       0       2       1       0       1       0       0       0
-       1       0       0       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       0       1       0       0       2       0       2       2
-       1       2       2       1       3       0       0       0       0       4
-       1       2       1       1       0       1       1       6       3       1
-       1       2       2       2       0       2       0       3       1       1
-       2       3       1       5       2       1       1       1       4       0
-       0       1       1       3       0       2       2       0       1       0
-       1       2       0       0       4       1       6       2       1       3
-       0       1       1       3       0       2       0       0       1       2
-       3       0       2       0       1       1       4       0       2       0
-       1       1       0       0       2       0       2       1       0       2
-       0       0       1       3       1       2       1       2       1       3
-       1       0       1       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       3       0       0
-       1       4       2       0       1       1       0       1       3       0
-       0       1       0       0       2       1       1       2       0       0
-       2       1       2       0       2       0       0       5       0       2
-       0       0       2       0       1       0       1       0       1       0
-       0       1       0       0       1       2       2       1       1       1
-       1       0       1       2       2       1       1       0       1       1
-       2       0       1       0       0       0       0       0       1       0
-       0       0       3       2       2       1       0       1       2       0
-       1       4       0       0       0       0       0       1       1       0
-       1       0       0       1       1       1       2       0       0       0
-       2       1       0       0       2       0       0       1       1       0
-       0       0       0       0       0       0       0       0       0       0
-       0       0       2       0       0       0       0       0       0       0
-       0       0       0       0       0       0       0       1       1       3
-       6       5       1       1       2       1       0       0       0       0
-       1       0       0       0       0       2       1       0       1       1
-       1       1       3       1       2       0       3       2       1       2
-       0       1       0       1       0       2       0       0       0       2
-       1       0       0       3       0       2       3       2       1       2
-       1       1       1       0       0       2       2       0       0       0
-       2       0       1       1       0       0       1       3       4       2
-       2       1       1       1       2       1       0       1       1       3
-       3       1       0       1       1       1       1       3       3       2
-       0       1       1       1       1       1       1       1       0       1
-       1       0       1       1       0       1       0       1       0       0
-       1       0       0       0       0       1       0       0       0       0
-       0       0       0       3       0       1       1       1       2       2
-       0       3       2       0       1       0       0       1       1       2
-       0       3       0       2       0       1       0       1       2       4
-       1       2       2       0       1       3       1       3       1       2
-       1       0       1       1       1       2       1       0       1       1
-       2       1       1       1       0       0       1       0       1       1
-       1       0       0       1       0       2       1       0       3       0
-       2       1       1       1       1       1       1       0       0       2
-       2       1       1       2       1       0       1       2       3       0
-       0       1       1       1       1       2       0       2       0       0
-       0       1       0       0       1       0       1       0       1       1
-       0       1       0       0                                                
diff --git a/Test/AutoTestData/Bilby_EOS.bin b/Test/AutoTestData/UsageData/Bilby_EOS.bin
similarity index 100%
rename from Test/AutoTestData/Bilby_EOS.bin
rename to Test/AutoTestData/UsageData/Bilby_EOS.bin
diff --git a/Test/AutoTestData/UsageData/ENGINX00213855focussed.nxs b/Test/AutoTestData/UsageData/ENGINX00213855focussed.nxs
new file mode 100644
index 0000000000000000000000000000000000000000..2deea73b74f8e9f039b105114f1c6545fd8f7c24
Binary files /dev/null and b/Test/AutoTestData/UsageData/ENGINX00213855focussed.nxs differ
diff --git a/Test/AutoTestData/UsageData/PG3_15035-3.dat b/Test/AutoTestData/UsageData/PG3_15035-3.dat
new file mode 100644
index 0000000000000000000000000000000000000000..329664e79b2117ea2dd0accd911f26c01881ec66
--- /dev/null
+++ b/Test/AutoTestData/UsageData/PG3_15035-3.dat
@@ -0,0 +1,6332 @@
+# File generated by Mantid:
+# Instrument: POWGEN
+# The X-axis unit is: Time-of-flight
+# The Y-axis unit is: Counts per microAmp.hour
+# Data for spectra :3
+# Time-of-flight              Y                 E
+     9713.81688        0.17857737        0.11256456
+     9717.70240        0.04554155        0.11796900
+     9721.58948        0.03985765        0.12209947
+     9725.47812        0.01137996        0.10979867
+     9729.36831        0.09902848        0.11527778
+     9733.26006        0.00649792        0.11770249
+     9737.15336        0.66200917        0.10272054
+     9741.04822        0.62684726        0.11826034
+     9744.94464        0.30371906        0.11897419
+     9748.84262        0.14610428        0.09951575
+     9752.74216        0.11310704        0.09402820
+     9756.64326        0.19842784        0.09303995
+     9760.54591        0.08360729        0.09007595
+     9764.45013        0.12215652        0.07757686
+     9768.35591        0.09572281        0.07619596
+     9772.26325        0.23632276        0.07508868
+     9776.17216        0.17599983        0.07698770
+     9780.08263        0.09227814        0.06938087
+     9783.99466        0.14660664        0.06232718
+     9787.90826        0.14108784        0.06226339
+     9791.82342        0.13759362        0.06127224
+     9795.74015        0.18944094        0.05198827
+     9799.65845        0.12099169        0.05936891
+     9803.57831        0.14204983        0.05757106
+     9807.49974        0.16987217        0.05181910
+     9811.42274        0.18787657        0.04888203
+     9815.34731        0.22047326        0.04068075
+     9819.27345        0.25217727        0.04439677
+     9823.20116        0.09648074        0.04552900
+     9827.13044        0.18760124        0.04192960
+     9831.06129        0.13355678        0.04394009
+     9834.99372        0.14735810        0.04170422
+     9838.92771        0.22465642        0.03965817
+     9842.86328        0.12821964        0.04019002
+     9846.80043        0.18973756        0.03568900
+     9850.73915        0.18693895        0.03461408
+     9854.67945        0.20842784        0.03409902
+     9858.62132        0.19129848        0.03228196
+     9862.56477        0.13414438        0.03371326
+     9866.50979        0.19934332        0.03195667
+     9870.45640        0.10959958        0.03199208
+     9874.40458        0.20753796        0.02876194
+     9878.35434        0.20339425        0.02778723
+     9882.30568        0.17131325        0.02830028
+     9886.25860        0.17420892        0.02980596
+     9890.21311        0.27894184        0.02875588
+     9894.16919        0.57350756        0.03259014
+     9898.12686        0.95459691        0.03706347
+     9902.08611        0.93278059        0.03421051
+     9906.04695        0.55963662        0.03295104
+     9910.00936        0.38576739        0.02695241
+     9913.97337        0.32873135        0.02436408
+     9917.93896        0.27161963        0.02572044
+     9921.90613        0.19814547        0.02416271
+     9925.87490        0.17549846        0.02284785
+     9929.84525        0.19119465        0.02186419
+     9933.81718        0.22101789        0.02163825
+     9937.79071        0.19565682        0.02213815
+     9941.76583        0.23016715        0.02158370
+     9945.74253        0.28647963        0.02237791
+     9949.72083        0.51566337        0.02534777
+     9953.70072        0.84775864        0.02823802
+     9957.68220        0.77637989        0.02795513
+     9961.66527        0.50864548        0.02313291
+     9965.64994        0.36939336        0.02184788
+     9969.63620        0.24156633        0.01989709
+     9973.62405        0.24378987        0.01963988
+     9977.61350        0.22175759        0.01858778
+     9981.60455        0.21958219        0.01800159
+     9985.59719        0.20242908        0.01750811
+     9989.59143        0.21041768        0.01703943
+     9993.58726        0.18368990        0.01769455
+     9997.58470        0.20755145        0.01740877
+    10001.58373        0.20585650        0.01811944
+    10005.58437        0.26483104        0.01754292
+    10009.58660        0.37028956        0.01845207
+    10013.59044        0.35023873        0.01795056
+    10017.59587        0.29360694        0.01753153
+    10021.60291        0.26398217        0.01623759
+    10025.61155        0.23475037        0.01556519
+    10029.62180        0.20982252        0.01650643
+    10033.63364        0.17601587        0.01578774
+    10037.64710        0.19708577        0.01555102
+    10041.66216        0.21453316        0.01512529
+    10045.67882        0.21355107        0.01472423
+    10049.69709        0.22146671        0.01445749
+    10053.71697        0.20322615        0.01499425
+    10057.73846        0.18893243        0.01482603
+    10061.76155        0.21016108        0.01456140
+    10065.78626        0.18949839        0.01379243
+    10069.81257        0.22589035        0.01418497
+    10073.84050        0.18578773        0.01476388
+    10077.87003        0.18954718        0.01461352
+    10081.90118        0.18585251        0.01381723
+    10085.93394        0.19250082        0.01415042
+    10089.96832        0.18771809        0.01479936
+    10094.00430        0.20500816        0.01367448
+    10098.04191        0.17664541        0.01419719
+    10102.08112        0.20518606        0.01327819
+    10106.12195        0.19410178        0.01373867
+    10110.16440        0.21742949        0.01394607
+    10114.20847        0.27824707        0.01382799
+    10118.25415        0.36207697        0.01486667
+    10122.30145        0.52081535        0.01633343
+    10126.35038        0.70228397        0.01813303
+    10130.40092        0.63605425        0.01764651
+    10134.45308        0.45060210        0.01560101
+    10138.50686        0.34105935        0.01425816
+    10142.56226        0.28043067        0.01361984
+    10146.61928        0.24107281        0.01300915
+    10150.67793        0.21139043        0.01253534
+    10154.73820        0.20658984        0.01348964
+    10158.80010        0.19525558        0.01295207
+    10162.86362        0.21301292        0.01294668
+    10166.92876        0.23585631        0.01261949
+    10170.99554        0.20782143        0.01297856
+    10175.06393        0.25353841        0.01270955
+    10179.13396        0.31134139        0.01337393
+    10183.20561        0.35291474        0.01413254
+    10187.27890        0.44829071        0.01435127
+    10191.35381        0.36873262        0.01432956
+    10195.43035        0.27983958        0.01356656
+    10199.50852        0.24332762        0.01239543
+    10203.58832        0.21576234        0.01242930
+    10207.66976        0.21019210        0.01201098
+    10211.75283        0.20504251        0.01224157
+    10215.83753        0.19133772        0.01239644
+    10219.92386        0.20646904        0.01159200
+    10224.01183        0.22494122        0.01192724
+    10228.10144        0.20984814        0.01173330
+    10232.19268        0.19747943        0.01193876
+    10236.28556        0.23260889        0.01230541
+    10240.38007        0.27023862        0.01221535
+    10244.47622        0.29486298        0.01297215
+    10248.57401        0.29151411        0.01289594
+    10252.67344        0.25844170        0.01228382
+    10256.77451        0.24712645        0.01228038
+    10260.87722        0.24382691        0.01176524
+    10264.98157        0.19920189        0.01213170
+    10269.08756        0.23079085        0.01189553
+    10273.19520        0.19869859        0.01153508
+    10277.30448        0.20289495        0.01149554
+    10281.41540        0.21261536        0.01205523
+    10285.52797        0.21365950        0.01185590
+    10289.64218        0.21560519        0.01194278
+    10293.75803        0.20059539        0.01172328
+    10297.87554        0.25357464        0.01185751
+    10301.99469        0.28892094        0.01261657
+    10306.11548        0.34398593        0.01260093
+    10310.23793        0.37988494        0.01291947
+    10314.36203        0.31043823        0.01261349
+    10318.48777        0.28645080        0.01208699
+    10322.61517        0.23960708        0.01213485
+    10326.74421        0.23735712        0.01141229
+    10330.87491        0.20421279        0.01216506
+    10335.00726        0.20409713        0.01182866
+    10339.14126        0.20552918        0.01152685
+    10343.27692        0.19109250        0.01148131
+    10347.41423        0.20464720        0.01137654
+    10351.55320        0.20415993        0.01168353
+    10355.69382        0.22816875        0.01098760
+    10359.83609        0.24286205        0.01179982
+    10363.98003        0.27785331        0.01193628
+    10368.12562        0.34660970        0.01270541
+    10372.27287        0.37139797        0.01334255
+    10376.42178        0.33232533        0.01222457
+    10380.57235        0.28073997        0.01193693
+    10384.72458        0.23070991        0.01170032
+    10388.87847        0.20726803        0.01142399
+    10393.03402        0.21319475        0.01137792
+    10397.19123        0.20388020        0.01111183
+    10401.35011        0.20243068        0.01114309
+    10405.51065        0.21195246        0.01067530
+    10409.67285        0.22178631        0.01078438
+    10413.83672        0.21284045        0.01095426
+    10418.00226        0.24850955        0.01131369
+    10422.16946        0.26147898        0.01113347
+    10426.33833        0.34493218        0.01231016
+    10430.50886        0.53149277        0.01366091
+    10434.68106        0.71396866        0.01527792
+    10438.85494        0.59933414        0.01414850
+    10443.03048        0.43425490        0.01298470
+    10447.20769        0.33252791        0.01209169
+    10451.38657        0.28000615        0.01124611
+    10455.56713        0.22899778        0.01105180
+    10459.74936        0.22826824        0.01088135
+    10463.93326        0.21777540        0.01074927
+    10468.11883        0.21417002        0.01060708
+    10472.30608        0.22301570        0.01047291
+    10476.49500        0.20634982        0.00988014
+    10480.68560        0.20669352        0.01005636
+    10484.87787        0.20713225        0.00997430
+    10489.07182        0.20970928        0.01035202
+    10493.26745        0.22091075        0.01052056
+    10497.46476        0.25879262        0.01101741
+    10501.66374        0.26130257        0.01059147
+    10505.86441        0.25486494        0.01075751
+    10510.06676        0.23779563        0.00989116
+    10514.27078        0.21873944        0.01031735
+    10518.47649        0.21743045        0.00983274
+    10522.68388        0.21923684        0.00971562
+    10526.89295        0.20539202        0.01016412
+    10531.10371        0.20804748        0.01014182
+    10535.31615        0.21014012        0.00987843
+    10539.53028        0.19455281        0.00985360
+    10543.74609        0.20873341        0.00969278
+    10547.96359        0.19084633        0.00991370
+    10552.18278        0.20813004        0.00975504
+    10556.40365        0.18764308        0.00958338
+    10560.62621        0.21152545        0.00970710
+    10564.85046        0.20327542        0.00978350
+    10569.07640        0.20184970        0.00976198
+    10573.30403        0.21680106        0.00934970
+    10577.53335        0.20190082        0.00958851
+    10581.76437        0.20497361        0.00945206
+    10585.99707        0.20437897        0.00939211
+    10590.23147        0.21082066        0.00941496
+    10594.46756        0.19113801        0.00950032
+    10598.70535        0.19669684        0.00948108
+    10602.94483        0.20544685        0.00929380
+    10607.18601        0.19716899        0.00946405
+    10611.42888        0.22093035        0.00931497
+    10615.67346        0.22862027        0.00918284
+    10619.91973        0.22064392        0.00927805
+    10624.16769        0.22136687        0.00946232
+    10628.41736        0.23488585        0.00935884
+    10632.66873        0.22715589        0.00944745
+    10636.92180        0.23481399        0.00916649
+    10641.17656        0.21815973        0.00948027
+    10645.43303        0.19824516        0.00920722
+    10649.69121        0.20648142        0.00914553
+    10653.95108        0.19961226        0.00923740
+    10658.21266        0.20860305        0.00892384
+    10662.47595        0.21585613        0.00895449
+    10666.74094        0.20288273        0.00885591
+    10671.00764        0.20909074        0.00909259
+    10675.27604        0.21425678        0.00886405
+    10679.54615        0.20735275        0.00927880
+    10683.81797        0.23315342        0.00886194
+    10688.09150        0.24653968        0.00917951
+    10692.36673        0.33992522        0.01019247
+    10696.64368        0.49267176        0.01108138
+    10700.92234        0.71816818        0.01234820
+    10705.20271        0.70344276        0.01236412
+    10709.48479        0.54477561        0.01156919
+    10713.76858        0.38202437        0.01031571
+    10718.05409        0.29055243        0.00936916
+    10722.34131        0.25438644        0.00888085
+    10726.63025        0.23798744        0.00869649
+    10730.92090        0.23815409        0.00878940
+    10735.21327        0.22423710        0.00862682
+    10739.50735        0.21069571        0.00836747
+    10743.80315        0.21091461        0.00853623
+    10748.10068        0.19255368        0.00833293
+    10752.39992        0.22353602        0.00840875
+    10756.70088        0.21850526        0.00834852
+    10761.00356        0.22030837        0.00844328
+    10765.30796        0.21852879        0.00849299
+    10769.61408        0.22760206        0.00862170
+    10773.92193        0.23207183        0.00840278
+    10778.23150        0.23487038        0.00849035
+    10782.54279        0.23409437        0.00844474
+    10786.85581        0.20342115        0.00845994
+    10791.17055        0.21889118        0.00812324
+    10795.48702        0.21489106        0.00831205
+    10799.80521        0.20661802        0.00833730
+    10804.12513        0.21279220        0.00825289
+    10808.44678        0.20527116        0.00845791
+    10812.77016        0.21210097        0.00827336
+    10817.09527        0.21103241        0.00816361
+    10821.42211        0.21167034        0.00830709
+    10825.75068        0.22696791        0.00834671
+    10830.08098        0.27147036        0.00865299
+    10834.41301        0.34903470        0.00923442
+    10838.74677        0.57844020        0.01081729
+    10843.08227        0.79430116        0.01219599
+    10847.41951        0.77511338        0.01205489
+    10851.75847        0.56490583        0.01052248
+    10856.09918        0.40663539        0.00948292
+    10860.44162        0.31158679        0.00889231
+    10864.78579        0.27312717        0.00835003
+    10869.13171        0.24546020        0.00816451
+    10873.47936        0.25233713        0.00820832
+    10877.82875        0.23082204        0.00818054
+    10882.17988        0.21296911        0.00798238
+    10886.53276        0.21580649        0.00799346
+    10890.88737        0.23320483        0.00806375
+    10895.24372        0.25323390        0.00789969
+    10899.60182        0.27987306        0.00837042
+    10903.96166        0.38574386        0.00935010
+    10908.32325        0.66054084        0.01070358
+    10912.68658        1.20061734        0.01357821
+    10917.05165        1.65818153        0.01551381
+    10921.41847        1.42915996        0.01459188
+    10925.78704        0.94211352        0.01232040
+    10930.15735        0.60072494        0.01039452
+    10934.52942        0.40584598        0.00939495
+    10938.90323        0.30639900        0.00855112
+    10943.27879        0.28113460        0.00808483
+    10947.65610        0.24492793        0.00806186
+    10952.03516        0.23431843        0.00779431
+    10956.41598        0.22791914        0.00795929
+    10960.79854        0.21382119        0.00774596
+    10965.18286        0.22435671        0.00755286
+    10969.56894        0.20744776        0.00778101
+    10973.95676        0.20701473        0.00763070
+    10978.34635        0.21058930        0.00763922
+    10982.73769        0.20776194        0.00747853
+    10987.13078        0.23853428        0.00784486
+    10991.52563        0.21557172        0.00752957
+    10995.92224        0.22351601        0.00761739
+    11000.32061        0.23029691        0.00750121
+    11004.72074        0.19965247        0.00751960
+    11009.12263        0.21996464        0.00762420
+    11013.52628        0.19842886        0.00758118
+    11017.93169        0.21163085        0.00740468
+    11022.33886        0.20508897        0.00745391
+    11026.74780        0.21286222        0.00766300
+    11031.15850        0.20998315        0.00733122
+    11035.57096        0.20874954        0.00767971
+    11039.98519        0.20300059        0.00743179
+    11044.40118        0.22263325        0.00745587
+    11048.81894        0.24006893        0.00750489
+    11053.23847        0.26304300        0.00782636
+    11057.65976        0.35897200        0.00833008
+    11062.08283        0.54169733        0.00956074
+    11066.50766        0.80278141        0.01097310
+    11070.93426        0.78151989        0.01083581
+    11075.36264        0.56284976        0.00964001
+    11079.79278        0.40183387        0.00856374
+    11084.22470        0.30965473        0.00795424
+    11088.65839        0.26159307        0.00734984
+    11093.09385        0.23160228        0.00736977
+    11097.53109        0.23290555        0.00723337
+    11101.97010        0.21925074        0.00731709
+    11106.41089        0.21234518        0.00719985
+    11110.85346        0.20981058        0.00714885
+    11115.29780        0.21189036        0.00717476
+    11119.74392        0.20579849        0.00712206
+    11124.19181        0.20317645        0.00734175
+    11128.64149        0.20619540        0.00687236
+    11133.09295        0.20929324        0.00716874
+    11137.54618        0.20241780        0.00715181
+    11142.00120        0.20138877        0.00721176
+    11146.45800        0.20533559        0.00727013
+    11150.91659        0.20565101        0.00709621
+    11155.37695        0.20074758        0.00704709
+    11159.83910        0.20205534        0.00712626
+    11164.30304        0.20112570        0.00716367
+    11168.76876        0.19730687        0.00709961
+    11173.23627        0.20821321        0.00710207
+    11177.70556        0.20425759        0.00714736
+    11182.17665        0.20752491        0.00695448
+    11186.64952        0.19869997        0.00707395
+    11191.12418        0.20793483        0.00718104
+    11195.60063        0.19400505        0.00724951
+    11200.07887        0.20235577        0.00705167
+    11204.55890        0.19719012        0.00707063
+    11209.04072        0.22315158        0.00692740
+    11213.52434        0.22272451        0.00731038
+    11218.00975        0.26222188        0.00737306
+    11222.49695        0.30037614        0.00781789
+    11226.98595        0.30977578        0.00768582
+    11231.47674        0.25520516        0.00762244
+    11235.96933        0.23055260        0.00739304
+    11240.46372        0.22874469        0.00726079
+    11244.95991        0.21740312        0.00715362
+    11249.45789        0.21327440        0.00708499
+    11253.95767        0.19609503        0.00716972
+    11258.45926        0.20235721        0.00717231
+    11262.96264        0.21411446        0.00708717
+    11267.46783        0.22073641        0.00697729
+    11271.97481        0.21693861        0.00694896
+    11276.48360        0.20998106        0.00729075
+    11280.99420        0.22820437        0.00718122
+    11285.50659        0.24977042        0.00735572
+    11290.02080        0.33193143        0.00790585
+    11294.53681        0.50357672        0.00902996
+    11299.05462        0.92111631        0.01122558
+    11303.57424        1.52679997        0.01375914
+    11308.09567        1.62576962        0.01421206
+    11312.61891        1.15225857        0.01223707
+    11317.14396        0.71288472        0.01023586
+    11321.67082        0.48283668        0.00890869
+    11326.19948        0.34740403        0.00812140
+    11330.72996        0.27198162        0.00749967
+    11335.26226        0.25099663        0.00729073
+    11339.79636        0.23173066        0.00711823
+    11344.33228        0.23481433        0.00679925
+    11348.87001        0.20978936        0.00711639
+    11353.40956        0.21329957        0.00699484
+    11357.95092        0.21151929        0.00703689
+    11362.49410        0.21463499        0.00691949
+    11367.03910        0.22336117        0.00694641
+    11371.58592        0.22891996        0.00699999
+    11376.13455        0.25950620        0.00713053
+    11380.68501        0.32793065        0.00768844
+    11385.23728        0.43734319        0.00840230
+    11389.79137        0.47058901        0.00869176
+    11394.34729        0.40921783        0.00818199
+    11398.90503        0.31331096        0.00757485
+    11403.46459        0.25604258        0.00731338
+    11408.02598        0.22470977        0.00718853
+    11412.58919        0.22045361        0.00687683
+    11417.15422        0.21818504        0.00679990
+    11421.72109        0.21582554        0.00709183
+    11426.28977        0.21214933        0.00682562
+    11430.86029        0.20913254        0.00682029
+    11435.43263        0.20967733        0.00670749
+    11440.00681        0.21753216        0.00679051
+    11444.58281        0.21196652        0.00684866
+    11449.16064        0.20043413        0.00680660
+    11453.74031        0.22435135        0.00700914
+    11458.32180        0.24396768        0.00707011
+    11462.90513        0.31469507        0.00746191
+    11467.49029        0.45280385        0.00842797
+    11472.07729        0.61250259        0.00926717
+    11476.66612        0.58331773        0.00931838
+    11481.25679        0.44970976        0.00821015
+    11485.84929        0.32784060        0.00758878
+    11490.44363        0.26528791        0.00718250
+    11495.03981        0.23777734        0.00700459
+    11499.63782        0.23449376        0.00696953
+    11504.23768        0.21624119        0.00670312
+    11508.83937        0.21317638        0.00670913
+    11513.44291        0.20773175        0.00681505
+    11518.04829        0.21466178        0.00647089
+    11522.65551        0.21229500        0.00668872
+    11527.26457        0.21902823        0.00671339
+    11531.87547        0.20846662        0.00657326
+    11536.48822        0.21935101        0.00661612
+    11541.10282        0.23908722        0.00684900
+    11545.71926        0.29468081        0.00718278
+    11550.33755        0.43730741        0.00809606
+    11554.95768        0.71713445        0.00961290
+    11559.57967        0.98209515        0.01086249
+    11564.20350        0.83793085        0.01015477
+    11568.82918        0.59354847        0.00895062
+    11573.45671        0.42751129        0.00793529
+    11578.08609        0.30761397        0.00717175
+    11582.71733        0.25960614        0.00683699
+    11587.35042        0.23209975        0.00684192
+    11591.98536        0.22889403        0.00651321
+    11596.62215        0.20858460        0.00669940
+    11601.26080        0.22170460        0.00641587
+    11605.90130        0.21665534        0.00641347
+    11610.54366        0.20709455        0.00633982
+    11615.18788        0.21460509        0.00656523
+    11619.83396        0.21825376        0.00655029
+    11624.48189        0.23621182        0.00672598
+    11629.13168        0.25950981        0.00679893
+    11633.78334        0.37255331        0.00739203
+    11638.43685        0.59521103        0.00873505
+    11643.09222        1.12302373        0.01123084
+    11647.74946        1.64590882        0.01318098
+    11652.40856        1.47379770        0.01256752
+    11657.06952        0.98383869        0.01054377
+    11661.73235        0.59676551        0.00873568
+    11666.39704        0.41743676        0.00779515
+    11671.06360        0.32170759        0.00702540
+    11675.73203        0.26604568        0.00677069
+    11680.40232        0.24301704        0.00658734
+    11685.07448        0.23153862        0.00643381
+    11689.74851        0.21587731        0.00630735
+    11694.42441        0.21154022        0.00647329
+    11699.10218        0.20532869        0.00634381
+    11703.78182        0.21143494        0.00644117
+    11708.46333        0.20561509        0.00644263
+    11713.14672        0.21246007        0.00628874
+    11717.83198        0.20551161        0.00622936
+    11722.51911        0.21766383        0.00635215
+    11727.20812        0.21000851        0.00628810
+    11731.89900        0.24731962        0.00646884
+    11736.59176        0.26705919        0.00677652
+    11741.28640        0.27728171        0.00681091
+    11745.98291        0.26348864        0.00656966
+    11750.68131        0.24218957        0.00657461
+    11755.38158        0.21889688        0.00624899
+    11760.08373        0.21714859        0.00623223
+    11764.78776        0.21604718        0.00626522
+    11769.49368        0.19974571        0.00601904
+    11774.20148        0.20115323        0.00600768
+    11778.91116        0.19770362        0.00619600
+    11783.62272        0.20201471        0.00613145
+    11788.33617        0.18603449        0.00621096
+    11793.05151        0.19345834        0.00596486
+    11797.76873        0.19606965        0.00620456
+    11802.48783        0.19994797        0.00619388
+    11807.20883        0.19510202        0.00613941
+    11811.93171        0.18509664        0.00609311
+    11816.65649        0.20686605        0.00610898
+    11821.38315        0.19684006        0.00619974
+    11826.11170        0.18420094        0.00599266
+    11830.84215        0.19694374        0.00615529
+    11835.57448        0.18964525        0.00605777
+    11840.30871        0.19639353        0.00613398
+    11845.04484        0.18518559        0.00609113
+    11849.78285        0.20078216        0.00602302
+    11854.52277        0.19693645        0.00592765
+    11859.26458        0.19577507        0.00603177
+    11864.00828        0.19023787        0.00593078
+    11868.75389        0.19557760        0.00588978
+    11873.50139        0.19836989        0.00589142
+    11878.25079        0.20470245        0.00601530
+    11883.00209        0.19531926        0.00603392
+    11887.75529        0.19556922        0.00582893
+    11892.51039        0.20328640        0.00597389
+    11897.26740        0.20723185        0.00594653
+    11902.02630        0.20238833        0.00602296
+    11906.78711        0.21438470        0.00614447
+    11911.54983        0.26412834        0.00639969
+    11916.31445        0.35448601        0.00694186
+    11921.08097        0.58327430        0.00826806
+    11925.84941        0.80783043        0.00931734
+    11930.61975        0.73959235        0.00892018
+    11935.39199        0.52214179        0.00789311
+    11940.16615        0.38808472        0.00703467
+    11944.94222        0.28683129        0.00654168
+    11949.72019        0.24428983        0.00627917
+    11954.50008        0.21268438        0.00606459
+    11959.28188        0.21844871        0.00588773
+    11964.06559        0.20864369        0.00587206
+    11968.85122        0.20189133        0.00583053
+    11973.63876        0.19610461        0.00594101
+    11978.42822        0.20047139        0.00583679
+    11983.21959        0.20174067        0.00578326
+    11988.01288        0.20268635        0.00585272
+    11992.80808        0.19772133        0.00595216
+    11997.60520        0.21299931        0.00596472
+    12002.40425        0.20349041        0.00590549
+    12007.20521        0.20948034        0.00588060
+    12012.00809        0.23976501        0.00616302
+    12016.81289        0.30410217        0.00664624
+    12021.61962        0.41114113        0.00703849
+    12026.42827        0.41488621        0.00724260
+    12031.23884        0.34937825        0.00675649
+    12036.05133        0.27923275        0.00637854
+    12040.86575        0.24324598        0.00606671
+    12045.68210        0.22194659        0.00605384
+    12050.50037        0.21270962        0.00587904
+    12055.32057        0.20091245        0.00588517
+    12060.14270        0.19961604        0.00575094
+    12064.96676        0.20392932        0.00584248
+    12069.79274        0.19632791        0.00589178
+    12074.62066        0.19685190        0.00584134
+    12079.45051        0.18958500        0.00564984
+    12084.28229        0.20246372        0.00570514
+    12089.11600        0.19985325        0.00596275
+    12093.95165        0.19365317        0.00595159
+    12098.78923        0.18831158        0.00596563
+    12103.62875        0.18972847        0.00588814
+    12108.47020        0.19855709        0.00581064
+    12113.31359        0.20223068        0.00570700
+    12118.15891        0.20778638        0.00565087
+    12123.00617        0.20094903        0.00582105
+    12127.85538        0.19956880        0.00571855
+    12132.70652        0.20755518        0.00573997
+    12137.55960        0.19033286        0.00573825
+    12142.41463        0.19597192        0.00567351
+    12147.27159        0.18923486        0.00582757
+    12152.13050        0.20028225        0.00574150
+    12156.99135        0.18809097        0.00581308
+    12161.85415        0.19875845        0.00579865
+    12166.71889        0.19747263        0.00594156
+    12171.58558        0.19997830        0.00582512
+    12176.45421        0.19982764        0.00580658
+    12181.32479        0.19559996        0.00568654
+    12186.19732        0.20437500        0.00577813
+    12191.07180        0.20600494        0.00590702
+    12195.94823        0.20320445        0.00576516
+    12200.82661        0.20934106        0.00579441
+    12205.70694        0.22777548        0.00593842
+    12210.58922        0.27276883        0.00611967
+    12215.47346        0.37802577        0.00683635
+    12220.35965        0.62186919        0.00811420
+    12225.24779        0.86828507        0.00920231
+    12230.13789        0.81671721        0.00900142
+    12235.02995        0.56953617        0.00783556
+    12239.92396        0.39373873        0.00699216
+    12244.81993        0.29150545        0.00641542
+    12249.71786        0.23968247        0.00599585
+    12254.61774        0.21646664        0.00601678
+    12259.51959        0.20790713        0.00592787
+    12264.42340        0.21845135        0.00581678
+    12269.32917        0.21064602        0.00575937
+    12274.23690        0.20188624        0.00597666
+    12279.14659        0.20904274        0.00581108
+    12284.05825        0.21103404        0.00581970
+    12288.97188        0.20198137        0.00586476
+    12293.88747        0.19986400        0.00576476
+    12298.80502        0.21905414        0.00577835
+    12303.72454        0.21939979        0.00586264
+    12308.64603        0.25751045        0.00619199
+    12313.56949        0.31277712        0.00649147
+    12318.49492        0.49965687        0.00756075
+    12323.42232        0.92700527        0.00944157
+    12328.35169        1.63198513        0.01200635
+    12333.28303        1.78582292        0.01243256
+    12338.21634        1.29716110        0.01093545
+    12343.15163        0.82308945        0.00900766
+    12348.08889        0.50737893        0.00752405
+    12353.02812        0.36166987        0.00678806
+    12357.96933        0.26999695        0.00622380
+    12362.91252        0.26225569        0.00604311
+    12367.85769        0.21366123        0.00610598
+    12372.80483        0.21937116        0.00582935
+    12377.75395        0.20360267        0.00586373
+    12382.70505        0.21009262        0.00594458
+    12387.65813        0.19955778        0.00583685
+    12392.61320        0.20851751        0.00566820
+    12397.57024        0.20752036        0.00583124
+    12402.52927        0.19904467        0.00582655
+    12407.49028        0.20816208        0.00571219
+    12412.45328        0.20250283        0.00575526
+    12417.41826        0.20578412        0.00596125
+    12422.38523        0.24350962        0.00609117
+    12427.35418        0.31062514        0.00641202
+    12432.32512        0.44158231        0.00726266
+    12437.29805        0.60483895        0.00810882
+    12442.27297        0.60206809        0.00807526
+    12447.24988        0.46742978        0.00736416
+    12452.22878        0.33021035        0.00665876
+    12457.20967        0.27207926        0.00618456
+    12462.19256        0.23055995        0.00606352
+    12467.17743        0.21118362        0.00593977
+    12472.16431        0.21091104        0.00575039
+    12477.15317        0.20231699        0.00581303
+    12482.14403        0.20525616        0.00568553
+    12487.13689        0.19825443        0.00575427
+    12492.13174        0.20717693        0.00578114
+    12497.12860        0.19999042        0.00572896
+    12502.12745        0.19684155        0.00561691
+    12507.12830        0.19474001        0.00564660
+    12512.13115        0.19494979        0.00573892
+    12517.13600        0.19406525        0.00563792
+    12522.14286        0.18612761        0.00579308
+    12527.15172        0.18732512        0.00569765
+    12532.16258        0.19347421        0.00563466
+    12537.17544        0.20235440        0.00581586
+    12542.19031        0.22103718        0.00580443
+    12547.20719        0.24140675        0.00603909
+    12552.22607        0.25592071        0.00612945
+    12557.24696        0.23233533        0.00578689
+    12562.26986        0.21025606        0.00573412
+    12567.29477        0.20623207        0.00563276
+    12572.32168        0.19733526        0.00558237
+    12577.35061        0.19540205        0.00574665
+    12582.38155        0.18936341        0.00565550
+    12587.41451        0.19078324        0.00556640
+    12592.44947        0.18731175        0.00558046
+    12597.48645        0.19120791        0.00550756
+    12602.52545        0.19079597        0.00561733
+    12607.56646        0.19001558        0.00557922
+    12612.60948        0.18063975        0.00555323
+    12617.65453        0.19664443        0.00553945
+    12622.70159        0.18652260        0.00557366
+    12627.75067        0.19427479        0.00558361
+    12632.80177        0.19105479        0.00556636
+    12637.85489        0.18939053        0.00562373
+    12642.91003        0.18095375        0.00568985
+    12647.96720        0.18191924        0.00563644
+    12653.02638        0.20172619        0.00548785
+    12658.08759        0.18971106        0.00559480
+    12663.15083        0.18408985        0.00549179
+    12668.21609        0.19130033        0.00561125
+    12673.28338        0.19239073        0.00549858
+    12678.35269        0.20179250        0.00552776
+    12683.42403        0.19811743        0.00545564
+    12688.49740        0.18883168        0.00553729
+    12693.57280        0.19069471        0.00552507
+    12698.65023        0.18372221        0.00551284
+    12703.72969        0.19371812        0.00552335
+    12708.81118        0.19869295        0.00554997
+    12713.89470        0.20379846        0.00550184
+    12718.98026        0.19594538        0.00557295
+    12724.06785        0.20068260        0.00555403
+    12729.15748        0.19111189        0.00556927
+    12734.24914        0.19483440        0.00562693
+    12739.34284        0.20047281        0.00551414
+    12744.43858        0.19661662        0.00555822
+    12749.53636        0.21169840        0.00557725
+    12754.63617        0.23928938        0.00579432
+    12759.73803        0.30183231        0.00618618
+    12764.84192        0.48479323        0.00707749
+    12769.94786        0.93806536        0.00912191
+    12775.05584        1.77236158        0.01198713
+    12780.16586        2.34306828        0.01348266
+    12785.27793        1.90282291        0.01229803
+    12790.39204        1.16476878        0.00997109
+    12795.50819        0.69758931        0.00811560
+    12800.62640        0.45665403        0.00702183
+    12805.74665        0.33335639        0.00623835
+    12810.86895        0.27372616        0.00583815
+    12815.99329        0.24356374        0.00578586
+    12821.11969        0.22544301        0.00569284
+    12826.24814        0.19910503        0.00557528
+    12831.37864        0.20147069        0.00556389
+    12836.51119        0.20311198        0.00539470
+    12841.64579        0.20454054        0.00547111
+    12846.78245        0.19602199        0.00545673
+    12851.92117        0.19593773        0.00545857
+    12857.06193        0.18887712        0.00540646
+    12862.20476        0.18964916        0.00547672
+    12867.34964        0.19799487        0.00537235
+    12872.49658        0.20055411        0.00538252
+    12877.64558        0.19936809        0.00540606
+    12882.79664        0.19457884        0.00548077
+    12887.94976        0.21044248        0.00545527
+    12893.10494        0.22939246        0.00561643
+    12898.26218        0.25309415        0.00571928
+    12903.42148        0.23900357        0.00565752
+    12908.58285        0.22026493        0.00572012
+    12913.74628        0.21338224        0.00536135
+    12918.91178        0.19285075        0.00537088
+    12924.07935        0.19520832        0.00539579
+    12929.24898        0.19786411        0.00525788
+    12934.42068        0.20033789        0.00539940
+    12939.59445        0.18737064        0.00538362
+    12944.77028        0.17925826        0.00541893
+    12949.94819        0.19261721        0.00534885
+    12955.12817        0.20286114        0.00526666
+    12960.31022        0.18436025        0.00536637
+    12965.49435        0.19721148        0.00534258
+    12970.68055        0.19074495        0.00527197
+    12975.86882        0.19784809        0.00523993
+    12981.05917        0.19687059        0.00533457
+    12986.25159        0.18847647        0.00532072
+    12991.44609        0.20484408        0.00531655
+    12996.64267        0.21505069        0.00536517
+    13001.84132        0.23717514        0.00545246
+    13007.04206        0.28523884        0.00604111
+    13012.24488        0.46444353        0.00684870
+    13017.44978        0.81793625        0.00836123
+    13022.65676        1.10935929        0.00945763
+    13027.86582        0.98906365        0.00905313
+    13033.07697        0.68205910        0.00773679
+    13038.29020        0.44728781        0.00661109
+    13043.50551        0.32238517        0.00606715
+    13048.72291        0.25771455        0.00556076
+    13053.94240        0.22227817        0.00550478
+    13059.16398        0.20753018        0.00534146
+    13064.38765        0.21806567        0.00538899
+    13069.61340        0.19987103        0.00534239
+    13074.84125        0.19885042        0.00539520
+    13080.07118        0.20123359        0.00529122
+    13085.30321        0.19194545        0.00525732
+    13090.53733        0.18689045        0.00533608
+    13095.77355        0.20178794        0.00524818
+    13101.01186        0.19544263        0.00524076
+    13106.25226        0.20869311        0.00520468
+    13111.49476        0.19549655        0.00528697
+    13116.73936        0.21463963        0.00536942
+    13121.98606        0.21326224        0.00543432
+    13127.23485        0.24614098        0.00570167
+    13132.48574        0.35234797        0.00618625
+    13137.73874        0.60770261        0.00748434
+    13142.99383        1.14072553        0.00949587
+    13148.25103        1.80528106        0.01163147
+    13153.51033        1.81623037        0.01167226
+    13158.77174        1.24820593        0.00987577
+    13164.03525        0.74955170        0.00797420
+    13169.30086        0.46997162        0.00683371
+    13174.56858        0.33927760        0.00614286
+    13179.83841        0.27573634        0.00567535
+    13185.11034        0.23330176        0.00546479
+    13190.38439        0.21787870        0.00546152
+    13195.66054        0.21132906        0.00534451
+    13200.93880        0.21647661        0.00523727
+    13206.21918        0.20161249        0.00537363
+    13211.50167        0.20095722        0.00527649
+    13216.78627        0.20016649        0.00522306
+    13222.07298        0.20107088        0.00518761
+    13227.36181        0.19300515        0.00522990
+    13232.65276        0.20577448        0.00525748
+    13237.94582        0.20000007        0.00515690
+    13243.24100        0.20407784        0.00520282
+    13248.53829        0.20435282        0.00524339
+    13253.83771        0.21102003        0.00520236
+    13259.13924        0.23622432        0.00547626
+    13264.44290        0.31011289        0.00595466
+    13269.74868        0.50689917        0.00678404
+    13275.05658        0.91344700        0.00858937
+    13280.36660        1.28848580        0.00994794
+    13285.67874        1.16810283        0.00951839
+    13290.99302        0.78419507        0.00807984
+    13296.30941        0.50625459        0.00685989
+    13301.62794        0.33919997        0.00608995
+    13306.94859        0.26542899        0.00554342
+    13312.27137        0.22996950        0.00534672
+    13317.59628        0.21117269        0.00529118
+    13322.92331        0.20534280        0.00526692
+    13328.25248        0.20535118        0.00514440
+    13333.58379        0.19155352        0.00517502
+    13338.91722        0.20220048        0.00519347
+    13344.25279        0.19012272        0.00511082
+    13349.59049        0.18853512        0.00522105
+    13354.93032        0.18443797        0.00519983
+    13360.27230        0.19041205        0.00509947
+    13365.61640        0.19648710        0.00503256
+    13370.96265        0.18888526        0.00512094
+    13376.31104        0.20039889        0.00500548
+    13381.66156        0.19449438        0.00515292
+    13387.01422        0.19637986        0.00506408
+    13392.36903        0.20168411        0.00519744
+    13397.72598        0.22027861        0.00524203
+    13403.08507        0.25827184        0.00548570
+    13408.44630        0.34572391        0.00602914
+    13413.80968        0.46006390        0.00659935
+    13419.17520        0.45718710        0.00662569
+    13424.54287        0.37181668        0.00622633
+    13429.91269        0.28552920        0.00556822
+    13435.28466        0.24104934        0.00540480
+    13440.65877        0.21856414        0.00511946
+    13446.03503        0.20523903        0.00508009
+    13451.41345        0.18858613        0.00511491
+    13456.79401        0.17957951        0.00501473
+    13462.17673        0.19162020        0.00498019
+    13467.56160        0.19124456        0.00504115
+    13472.94863        0.18365348        0.00507838
+    13478.33781        0.18196342        0.00503229
+    13483.72914        0.18348784        0.00501367
+    13489.12263        0.19648687        0.00495338
+    13494.51828        0.18696891        0.00503809
+    13499.91609        0.18128800        0.00504766
+    13505.31606        0.18965555        0.00502504
+    13510.71818        0.17823831        0.00495099
+    13516.12247        0.18572712        0.00489655
+    13521.52892        0.17789930        0.00495945
+    13526.93753        0.18089780        0.00504900
+    13532.34831        0.18894916        0.00501013
+    13537.76124        0.20559226        0.00507892
+    13543.17635        0.22198021        0.00528102
+    13548.59362        0.28550745        0.00559446
+    13554.01306        0.34157930        0.00585126
+    13559.43466        0.32094648        0.00580659
+    13564.85844        0.26828510        0.00553963
+    13570.28438        0.23158463        0.00526836
+    13575.71249        0.20640106        0.00518817
+    13581.14278        0.19278526        0.00500704
+    13586.57524        0.18046092        0.00498179
+    13592.00987        0.17671640        0.00494497
+    13597.44667        0.17271465        0.00504331
+    13602.88565        0.17683686        0.00495518
+    13608.32680        0.16915392        0.00501959
+    13613.77013        0.17485459        0.00503091
+    13619.21564        0.19440624        0.00493167
+    13624.66333        0.19049777        0.00501619
+    13630.11319        0.17888607        0.00489457
+    13635.56524        0.18062994        0.00491808
+    13641.01946        0.17686860        0.00496815
+    13646.47587        0.18266232        0.00500948
+    13651.93446        0.18810141        0.00493106
+    13657.39524        0.18039166        0.00492080
+    13662.85819        0.18336286        0.00493818
+    13668.32334        0.18228228        0.00501924
+    13673.79067        0.18684579        0.00487138
+    13679.26018        0.18560770        0.00492053
+    13684.73189        0.18166216        0.00501273
+    13690.20578        0.17796016        0.00485637
+    13695.68186        0.17411711        0.00495419
+    13701.16013        0.18145378        0.00499937
+    13706.64060        0.18671379        0.00488906
+    13712.12325        0.17446850        0.00492343
+    13717.60810        0.18299134        0.00497654
+    13723.09515        0.17471161        0.00488164
+    13728.58439        0.17591167        0.00489285
+    13734.07582        0.18172447        0.00490426
+    13739.56945        0.17921565        0.00493515
+    13745.06528        0.17921065        0.00489188
+    13750.56330        0.19048612        0.00484716
+    13756.06353        0.17676885        0.00488320
+    13761.56595        0.17508205        0.00487212
+    13767.07058        0.18055415        0.00499174
+    13772.57741        0.18199472        0.00504913
+    13778.08644        0.17684924        0.00506923
+    13783.59767        0.17789319        0.00502929
+    13789.11111        0.19220820        0.00489356
+    13794.62676        0.17503259        0.00496016
+    13800.14461        0.18295761        0.00511927
+    13805.66467        0.18371747        0.00496570
+    13811.18693        0.18825523        0.00498904
+    13816.71141        0.18659677        0.00507884
+    13822.23809        0.21090176        0.00507279
+    13827.76699        0.27163273        0.00538545
+    13833.29809        0.40341323        0.00620498
+    13838.83141        0.73920452        0.00764706
+    13844.36695        1.09944987        0.00895284
+    13849.90469        1.10312346        0.00894599
+    13855.44465        0.77384153        0.00782701
+    13860.98683        0.49906017        0.00665445
+    13866.53123        0.33889471        0.00596731
+    13872.07784        0.26357358        0.00539907
+    13877.62667        0.22799907        0.00514393
+    13883.17772        0.19969975        0.00512218
+    13888.73099        0.19312988        0.00514188
+    13894.28648        0.19926495        0.00491101
+    13899.84420        0.19023051        0.00488070
+    13905.40414        0.19125445        0.00494124
+    13910.96630        0.18718987        0.00486756
+    13916.53068        0.18352187        0.00498604
+    13922.09730        0.18814472        0.00499422
+    13927.66614        0.18476647        0.00497057
+    13933.23720        0.17945007        0.00490326
+    13938.81050        0.18623412        0.00492459
+    13944.38602        0.19405239        0.00502074
+    13949.96378        0.19251069        0.00502138
+    13955.54376        0.19565640        0.00497865
+    13961.12598        0.19931743        0.00499371
+    13966.71043        0.21139353        0.00497803
+    13972.29711        0.24233258        0.00517886
+    13977.88603        0.33626335        0.00577444
+    13983.47719        0.60827836        0.00700438
+    13989.07058        1.22535311        0.00932749
+    13994.66621        2.31788923        0.01240132
+    14000.26407        2.95927618        0.01378609
+    14005.86418        2.34451385        0.01240491
+    14011.46652        1.42118171        0.00991102
+    14017.07111        0.81836808        0.00789954
+    14022.67794        0.50116814        0.00651064
+    14028.28701        0.35417594        0.00580179
+    14033.89832        0.27502160        0.00538677
+    14039.51188        0.23298299        0.00519684
+    14045.12769        0.21107467        0.00500755
+    14050.74574        0.20725875        0.00498973
+    14056.36604        0.20371748        0.00493676
+    14061.98858        0.19926669        0.00493197
+    14067.61338        0.19307656        0.00488280
+    14073.24043        0.18290718        0.00485314
+    14078.86972        0.18999485        0.00493927
+    14084.50127        0.18366627        0.00490967
+    14090.13507        0.18262268        0.00497908
+    14095.77112        0.17982858        0.00498751
+    14101.40943        0.19267510        0.00479765
+    14107.05000        0.18688305        0.00489352
+    14112.69282        0.17739550        0.00482014
+    14118.33789        0.17019820        0.00493356
+    14123.98523        0.18912984        0.00496956
+    14129.63482        0.18152000        0.00485480
+    14135.28668        0.18287630        0.00488531
+    14140.94079        0.19315431        0.00498266
+    14146.59717        0.22647447        0.00506446
+    14152.25581        0.26027786        0.00530179
+    14157.91671        0.28513361        0.00551626
+    14163.57988        0.27445910        0.00532643
+    14169.24531        0.23180232        0.00508470
+    14174.91301        0.20568110        0.00495175
+    14180.58297        0.19045525        0.00494536
+    14186.25520        0.17066460        0.00492803
+    14191.92971        0.18615980        0.00480669
+    14197.60648        0.18533227        0.00472519
+    14203.28552        0.17996289        0.00473547
+    14208.96683        0.18371717        0.00483968
+    14214.65042        0.17769167        0.00484549
+    14220.33628        0.17453539        0.00485529
+    14226.02442        0.18765714        0.00462319
+    14231.71483        0.17467844        0.00477577
+    14237.40751        0.16719503        0.00475173
+    14243.10247        0.16982183        0.00485117
+    14248.79972        0.17340558        0.00480426
+    14254.49924        0.17565629        0.00486682
+    14260.20104        0.17223824        0.00480057
+    14265.90512        0.17906449        0.00477336
+    14271.61148        0.17720835        0.00488109
+    14277.32012        0.17346494        0.00479288
+    14283.03105        0.17465393        0.00477820
+    14288.74426        0.17184854        0.00474207
+    14294.45976        0.17708367        0.00474906
+    14300.17754        0.16719022        0.00477394
+    14305.89762        0.17038669        0.00468298
+    14311.61997        0.16881158        0.00480014
+    14317.34462        0.16770441        0.00479790
+    14323.07156        0.17264373        0.00482256
+    14328.80079        0.17710603        0.00482085
+    14334.53231        0.17398147        0.00472538
+    14340.26612        0.16703805        0.00472710
+    14346.00223        0.16583783        0.00481755
+    14351.74063        0.17185669        0.00479199
+    14357.48133        0.17113954        0.00485441
+    14363.22432        0.17327197        0.00481216
+    14368.96961        0.17682877        0.00480496
+    14374.71720        0.18085050        0.00468026
+    14380.46708        0.17511095        0.00468950
+    14386.21927        0.17280982        0.00485218
+    14391.97376        0.17432210        0.00469019
+    14397.73055        0.16680754        0.00467475
+    14403.48964        0.17246836        0.00479387
+    14409.25103        0.17480590        0.00480565
+    14415.01474        0.17457915        0.00481815
+    14420.78074        0.17383996        0.00467886
+    14426.54905        0.18236166        0.00470919
+    14432.31967        0.17940836        0.00465153
+    14438.09260        0.17145571        0.00470652
+    14443.86784        0.17078604        0.00473615
+    14449.64539        0.17689140        0.00471823
+    14455.42524        0.17305430        0.00465203
+    14461.20741        0.17672317        0.00475473
+    14466.99190        0.17431770        0.00477337
+    14472.77869        0.18424600        0.00484345
+    14478.56780        0.20483478        0.00493418
+    14484.35923        0.24437509        0.00520582
+    14490.15298        0.28016000        0.00534649
+    14495.94904        0.26501380        0.00520270
+    14501.74742        0.22630410        0.00495632
+    14507.54812        0.20736330        0.00479484
+    14513.35113        0.18880035        0.00484117
+    14519.15647        0.17537988        0.00474889
+    14524.96414        0.17715140        0.00462031
+    14530.77412        0.16902588        0.00468982
+    14536.58643        0.17485881        0.00467783
+    14542.40107        0.17534887        0.00470474
+    14548.21803        0.17634436        0.00460043
+    14554.03732        0.17261019        0.00463760
+    14559.85893        0.17080077        0.00479827
+    14565.68287        0.17128780        0.00473472
+    14571.50915        0.17096233        0.00464911
+    14577.33775        0.17179703        0.00467418
+    14583.16869        0.16724360        0.00484728
+    14589.00195        0.17514252        0.00465991
+    14594.83755        0.16892187        0.00482017
+    14600.67549        0.16589550        0.00472370
+    14606.51576        0.17495925        0.00475994
+    14612.35837        0.17446734        0.00478627
+    14618.20331        0.18098604        0.00470324
+    14624.05059        0.17975027        0.00473847
+    14629.90021        0.18320588        0.00475124
+    14635.75217        0.19648619        0.00481306
+    14641.60647        0.22193263        0.00493853
+    14647.46311        0.31272889        0.00551095
+    14653.32210        0.53047951        0.00648806
+    14659.18343        0.97070231        0.00820954
+    14665.04710        1.39461327        0.00955553
+    14670.91312        1.32924897        0.00935443
+    14676.78149        0.89383839        0.00790817
+    14682.65220        0.55038046        0.00656281
+    14688.52526        0.37031693        0.00572068
+    14694.40067        0.26597916        0.00530415
+    14700.27843        0.22726139        0.00492266
+    14706.15854        0.20559014        0.00477930
+    14712.04100        0.18981368        0.00480192
+    14717.92582        0.18320723        0.00472984
+    14723.81299        0.18264528        0.00471519
+    14729.70252        0.18173123        0.00474210
+    14735.59440        0.17666935        0.00474097
+    14741.48863        0.17366735        0.00469583
+    14747.38523        0.17877827        0.00464565
+    14753.28418        0.18012277        0.00471112
+    14759.18550        0.17867472        0.00470314
+    14765.08917        0.17367210        0.00456596
+    14770.99521        0.17843681        0.00467494
+    14776.90361        0.17609661        0.00456335
+    14782.81437        0.17557653        0.00464030
+    14788.72749        0.16889428        0.00463520
+    14794.64298        0.17151177        0.00469844
+    14800.56084        0.16568694        0.00463925
+    14806.48107        0.17532474        0.00467296
+    14812.40366        0.17436085        0.00464915
+    14818.32862        0.17956070        0.00459666
+    14824.25595        0.19835797        0.00471934
+    14830.18565        0.21830541        0.00494551
+    14836.11773        0.28721842        0.00521897
+    14842.05217        0.42239518        0.00590904
+    14847.98900        0.54293570        0.00648049
+    14853.92819        0.48918932        0.00625562
+    14859.86976        0.37181468        0.00566355
+    14865.81371        0.26532012        0.00513888
+    14871.76004        0.22531308        0.00486824
+    14877.70874        0.20136715        0.00476000
+    14883.65982        0.18057502        0.00473474
+    14889.61329        0.18301988        0.00463421
+    14895.56913        0.17172368        0.00467714
+    14901.52736        0.17629355        0.00457621
+    14907.48797        0.17568471        0.00455756
+    14913.45097        0.17678604        0.00457097
+    14919.41635        0.17055981        0.00454932
+    14925.38411        0.16931430        0.00457330
+    14931.35427        0.17088040        0.00459870
+    14937.32681        0.18327216        0.00452336
+    14943.30174        0.16899304        0.00457354
+    14949.27906        0.16547688        0.00458691
+    14955.25877        0.16487204        0.00451341
+    14961.24088        0.17354847        0.00457610
+    14967.22537        0.17083487        0.00459737
+    14973.21226        0.16337889        0.00453527
+    14979.20155        0.16537862        0.00444942
+    14985.19323        0.17623430        0.00454779
+    14991.18730        0.17506887        0.00446796
+    14997.18378        0.17193483        0.00456102
+    15003.18265        0.16599858        0.00455400
+    15009.18393        0.16430896        0.00455420
+    15015.18760        0.16905581        0.00453220
+    15021.19367        0.16147123        0.00456387
+    15027.20215        0.16355456        0.00455024
+    15033.21303        0.17204661        0.00454171
+    15039.22632        0.16821327        0.00455626
+    15045.24201        0.16006519        0.00458711
+    15051.26011        0.17120656        0.00456438
+    15057.28061        0.16313823        0.00454743
+    15063.30352        0.18070739        0.00446285
+    15069.32884        0.16046586        0.00467081
+    15075.35657        0.16558321        0.00458947
+    15081.38672        0.16405175        0.00450926
+    15087.41927        0.16931911        0.00459294
+    15093.45424        0.16680982        0.00448572
+    15099.49162        0.17331168        0.00446833
+    15105.53142        0.16591193        0.00451264
+    15111.57363        0.16991622        0.00448922
+    15117.61826        0.16900588        0.00452671
+    15123.66531        0.16851099        0.00452134
+    15129.71477        0.16491023        0.00454518
+    15135.76666        0.15993693        0.00448583
+    15141.82097        0.16982348        0.00442794
+    15147.87769        0.16196852        0.00459967
+    15153.93685        0.17194171        0.00449315
+    15159.99842        0.17092123        0.00459411
+    15166.06242        0.16679933        0.00457308
+    15172.12884        0.17003936        0.00446504
+    15178.19770        0.17024362        0.00459961
+    15184.26898        0.17496719        0.00439915
+    15190.34268        0.17020599        0.00453233
+    15196.41882        0.17281231        0.00457408
+    15202.49739        0.16068647        0.00453179
+    15208.57839        0.17152320        0.00447216
+    15214.66182        0.18423320        0.00449763
+    15220.74768        0.20752085        0.00479665
+    15226.83598        0.27149015        0.00511173
+    15232.92672        0.31170733        0.00534406
+    15239.01989        0.29776846        0.00521541
+    15245.11549        0.25406480        0.00496268
+    15251.21354        0.21363256        0.00470155
+    15257.31403        0.19367576        0.00466649
+    15263.41695        0.17327419        0.00461451
+    15269.52232        0.16996395        0.00450376
+    15275.63013        0.17634655        0.00448676
+    15281.74038        0.16912298        0.00438544
+    15287.85308        0.17107103        0.00447127
+    15293.96822        0.16999100        0.00443932
+    15300.08580        0.17225087        0.00446231
+    15306.20584        0.16917075        0.00446810
+    15312.32832        0.17808658        0.00443178
+    15318.45325        0.17065961        0.00452744
+    15324.58063        0.17005530        0.00442081
+    15330.71047        0.16366012        0.00456504
+    15336.84275        0.16120209        0.00447453
+    15342.97749        0.16575195        0.00453348
+    15349.11468        0.16579954        0.00450901
+    15355.25432        0.17477441        0.00445088
+    15361.39643        0.16554849        0.00442605
+    15367.54098        0.17243784        0.00444193
+    15373.68800        0.16367814        0.00448598
+    15379.83748        0.16781496        0.00442822
+    15385.98941        0.16481203        0.00444616
+    15392.14381        0.16261760        0.00447739
+    15398.30066        0.17652033        0.00439429
+    15404.45998        0.16641643        0.00442816
+    15410.62177        0.16622422        0.00433863
+    15416.78602        0.17277619        0.00448036
+    15422.95273        0.19228029        0.00450541
+    15429.12191        0.19465222        0.00461297
+    15435.29356        0.21860110        0.00479687
+    15441.46768        0.23601757        0.00470788
+    15447.64427        0.20790581        0.00471820
+    15453.82332        0.19180414        0.00458076
+    15460.00485        0.18209308        0.00454989
+    15466.18885        0.17784508        0.00454492
+    15472.37533        0.17364797        0.00447848
+    15478.56428        0.16642027        0.00446194
+    15484.75571        0.16538540        0.00440753
+    15490.94961        0.16373546        0.00448110
+    15497.14599        0.16764118        0.00451848
+    15503.34485        0.17106103        0.00449665
+    15509.54618        0.17028623        0.00436649
+    15515.75000        0.16035809        0.00444652
+    15521.95630        0.16434949        0.00446777
+    15528.16509        0.16662051        0.00436960
+    15534.37635        0.16957072        0.00446836
+    15540.59010        0.16553192        0.00444809
+    15546.80634        0.17373609        0.00439946
+    15553.02506        0.17996117        0.00438209
+    15559.24627        0.16589563        0.00450888
+    15565.46997        0.17171091        0.00449799
+    15571.69616        0.17211368        0.00444090
+    15577.92484        0.17934253        0.00447240
+    15584.15601        0.16797737        0.00448298
+    15590.38967        0.16988011        0.00433534
+    15596.62582        0.16888673        0.00446862
+    15602.86447        0.17151020        0.00441515
+    15609.10562        0.17996555        0.00449349
+    15615.34926        0.18440634        0.00452475
+    15621.59540        0.19435194        0.00448608
+    15627.84404        0.22179092        0.00478137
+    15634.09518        0.30482144        0.00516261
+    15640.34882        0.49484456        0.00608469
+    15646.60496        0.79374435        0.00729223
+    15652.86360        0.97770589        0.00787683
+    15659.12474        0.79387386        0.00722547
+    15665.38839        0.51750899        0.00628753
+    15671.65455        0.35019843        0.00542942
+    15677.92321        0.25535850        0.00489786
+    15684.19438        0.21544880        0.00472693
+    15690.46806        0.18532487        0.00457525
+    15696.74424        0.18513028        0.00455628
+    15703.02294        0.17770671        0.00448697
+    15709.30415        0.17756317        0.00443968
+    15715.58787        0.17368538        0.00442149
+    15721.87411        0.17975951        0.00445062
+    15728.16286        0.17501495        0.00447009
+    15734.45412        0.16716014        0.00446008
+    15740.74790        0.16262019        0.00442412
+    15747.04420        0.17260952        0.00439965
+    15753.34302        0.16972800        0.00440494
+    15759.64436        0.18024048        0.00447199
+    15765.94822        0.16796548        0.00442797
+    15772.25460        0.17260152        0.00453624
+    15778.56350        0.17784811        0.00438880
+    15784.87492        0.17399219        0.00437432
+    15791.18887        0.16718640        0.00441410
+    15797.50535        0.15746921        0.00446476
+    15803.82435        0.18113717        0.00447881
+    15810.14588        0.18542924        0.00445869
+    15816.46994        0.18183705        0.00444604
+    15822.79653        0.17948609        0.00444627
+    15829.12564        0.18515286        0.00445098
+    15835.45730        0.18268095        0.00442197
+    15841.79148        0.18574734        0.00453504
+    15848.12819        0.21724407        0.00461779
+    15854.46745        0.29758879        0.00511253
+    15860.80923        0.48509820        0.00596921
+    15867.15356        0.81550636        0.00730242
+    15873.50042        1.07839475        0.00820321
+    15879.84982        0.95171457        0.00776859
+    15886.20176        0.63922784        0.00661292
+    15892.55624        0.40721962        0.00570650
+    15898.91326        0.29104680        0.00513611
+    15905.27283        0.23269908        0.00476513
+    15911.63494        0.20410993        0.00472652
+    15917.99959        0.18702913        0.00447658
+    15924.36679        0.18035558        0.00458688
+    15930.73654        0.18057315        0.00457368
+    15937.10883        0.17276719        0.00453936
+    15943.48367        0.18765952        0.00447178
+    15949.86107        0.17558926        0.00456499
+    15956.24101        0.17572772        0.00455410
+    15962.62351        0.17886027        0.00449127
+    15969.00856        0.17753288        0.00442968
+    15975.39616        0.17241440        0.00441314
+    15981.78632        0.17426305        0.00445155
+    15988.17903        0.17839945        0.00441604
+    15994.57431        0.17722337        0.00440848
+    16000.97214        0.18135372        0.00440666
+    16007.37252        0.17911692        0.00443791
+    16013.77547        0.18012943        0.00453188
+    16020.18098        0.17617767        0.00453306
+    16026.58906        0.17381307        0.00448806
+    16032.99969        0.17681952        0.00455095
+    16039.41289        0.18342767        0.00451340
+    16045.82866        0.18037554        0.00447785
+    16052.24699        0.17527005        0.00453241
+    16058.66789        0.19224210        0.00457819
+    16065.09135        0.20700070        0.00458946
+    16071.51739        0.22764077        0.00478594
+    16077.94600        0.29872132        0.00518224
+    16084.37718        0.51840416        0.00618886
+    16090.81093        1.06138176        0.00811347
+    16097.24725        2.10309503        0.01092209
+    16103.68615        3.20612158        0.01324680
+    16110.12762        3.04896019        0.01294046
+    16116.57168        2.04082175        0.01074072
+    16123.01830        1.15826563        0.00838842
+    16129.46751        0.66802634        0.00673816
+    16135.91930        0.43074698        0.00570244
+    16142.37367        0.31157682        0.00515228
+    16148.83062        0.25070383        0.00488544
+    16155.29015        0.21241694        0.00476375
+    16161.75226        0.21203801        0.00454059
+    16168.21697        0.20499059        0.00460662
+    16174.68425        0.19526115        0.00443501
+    16181.15413        0.19822002        0.00447335
+    16187.62659        0.18317915        0.00454920
+    16194.10164        0.18863342        0.00457153
+    16200.57928        0.18483111        0.00443356
+    16207.05951        0.18471720        0.00449800
+    16213.54233        0.18446636        0.00445291
+    16220.02775        0.17415972        0.00440679
+    16226.51576        0.18181914        0.00447534
+    16233.00637        0.17593495        0.00447667
+    16239.49957        0.18091035        0.00447501
+    16245.99537        0.18151288        0.00442634
+    16252.49377        0.18509640        0.00443575
+    16258.99477        0.18388289        0.00442009
+    16265.49836        0.18925647        0.00443421
+    16272.00456        0.18402113        0.00447158
+    16278.51337        0.19248807        0.00452705
+    16285.02477        0.18526951        0.00450402
+    16291.53878        0.18780955        0.00454144
+    16298.05540        0.19409061        0.00449277
+    16304.57462        0.20077430        0.00458773
+    16311.09645        0.23183023        0.00472815
+    16317.62089        0.30965641        0.00516273
+    16324.14794        0.52620385        0.00616672
+    16330.67759        1.05614541        0.00804104
+    16337.20987        2.21723366        0.01115715
+    16343.74475        3.84874196        0.01439474
+    16350.28225        4.32668321        0.01519816
+    16356.82236        3.14290119        0.01306250
+    16363.36509        1.80129718        0.01003979
+    16369.91044        0.97741473        0.00778658
+    16376.45840        0.57815951        0.00626650
+    16383.00898        0.37990478        0.00540544
+    16389.56219        0.29332547        0.00509864
+    16396.11801        0.24214586        0.00485011
+    16402.67646        0.22325250        0.00466250
+    16409.23753        0.20192910        0.00455917
+    16415.80122        0.19708531        0.00458804
+    16422.36754        0.20187389        0.00448229
+    16428.93649        0.19183724        0.00453512
+    16435.50807        0.19733448        0.00440019
+    16442.08227        0.17971465        0.00452472
+    16448.65910        0.18775983        0.00439362
+    16455.23857        0.17567897        0.00441696
+    16461.82066        0.18048165        0.00444565
+    16468.40539        0.17489687        0.00436665
+    16474.99275        0.17714501        0.00442920
+    16481.58275        0.18189328        0.00440687
+    16488.17538        0.18003389        0.00440550
+    16494.77065        0.18662669        0.00444958
+    16501.36856        0.18167300        0.00439052
+    16507.96911        0.17515502        0.00430796
+    16514.57230        0.16894467        0.00432459
+    16521.17812        0.17601937        0.00437745
+    16527.78660        0.16448540        0.00434428
+    16534.39771        0.17172272        0.00437379
+    16541.01147        0.17094521        0.00436787
+    16547.62787        0.17532711        0.00435688
+    16554.24693        0.17099661        0.00438947
+    16560.86862        0.17032207        0.00442145
+    16567.49297        0.18281272        0.00445932
+    16574.11997        0.21539376        0.00464044
+    16580.74962        0.30943308        0.00517016
+    16587.38192        0.50700323        0.00596882
+    16594.01687        0.86784072        0.00733473
+    16600.65448        1.16026927        0.00823319
+    16607.29474        1.03970672        0.00787836
+    16613.93766        0.67939152        0.00669912
+    16620.58323        0.43560409        0.00570597
+    16627.23146        0.30679283        0.00502582
+    16633.88236        0.23185369        0.00470074
+    16640.53591        0.21019227        0.00458243
+    16647.19212        0.18373315        0.00448845
+    16653.85100        0.17535553        0.00441626
+    16660.51254        0.17719341        0.00441692
+    16667.17675        0.17791031        0.00439021
+    16673.84362        0.16895547        0.00433435
+    16680.51315        0.16896384        0.00434029
+    16687.18536        0.17666977        0.00429218
+    16693.86023        0.17244708        0.00433223
+    16700.53778        0.16991605        0.00424058
+    16707.21799        0.16643220        0.00429598
+    16713.90088        0.16468996        0.00431571
+    16720.58644        0.16498422        0.00439658
+    16727.27467        0.16925855        0.00420992
+    16733.96558        0.15872787        0.00430459
+    16740.65917        0.16726450        0.00427521
+    16747.35543        0.16357107        0.00431045
+    16754.05438        0.16419402        0.00427541
+    16760.75600        0.15579963        0.00427571
+    16767.46030        0.16491282        0.00431097
+    16774.16729        0.16603012        0.00417471
+    16780.87695        0.16547444        0.00420267
+    16787.58930        0.16082435        0.00428370
+    16794.30434        0.16085626        0.00417861
+    16801.02206        0.16227792        0.00425551
+    16807.74247        0.15416172        0.00428153
+    16814.46557        0.15639265        0.00431950
+    16821.19135        0.15719045        0.00422277
+    16827.91983        0.15861663        0.00428033
+    16834.65100        0.16000721        0.00432643
+    16841.38486        0.15818103        0.00423325
+    16848.12141        0.16462044        0.00430607
+    16854.86066        0.16094370        0.00419895
+    16861.60260        0.16714708        0.00419122
+    16868.34725        0.15924371        0.00419422
+    16875.09458        0.16647923        0.00426392
+    16881.84462        0.16285245        0.00422811
+    16888.59736        0.16577023        0.00425649
+    16895.35280        0.15697066        0.00427734
+    16902.11094        0.16437408        0.00418929
+    16908.87178        0.15804631        0.00420092
+    16915.63533        0.16117979        0.00411312
+    16922.40159        0.16334951        0.00424636
+    16929.17055        0.16301703        0.00420572
+    16935.94222        0.16183645        0.00426507
+    16942.71659        0.17088135        0.00422651
+    16949.49368        0.16343482        0.00420504
+    16956.27348        0.16340057        0.00421083
+    16963.05599        0.16770557        0.00418402
+    16969.84121        0.16299412        0.00422044
+    16976.62915        0.15693549        0.00419395
+    16983.41980        0.16195623        0.00418197
+    16990.21316        0.15863651        0.00426515
+    16997.00925        0.16507717        0.00420707
+    17003.80805        0.15487695        0.00424778
+    17010.60958        0.16186871        0.00419546
+    17017.41382        0.15538404        0.00428301
+    17024.22079        0.15686635        0.00426656
+    17031.03047        0.15922306        0.00423704
+    17037.84289        0.16092801        0.00427561
+    17044.65802        0.16743084        0.00424930
+    17051.47589        0.16352346        0.00430150
+    17058.29648        0.16283588        0.00428285
+    17065.11980        0.16139199        0.00426235
+    17071.94584        0.16904956        0.00421438
+    17078.77462        0.17290777        0.00418549
+    17085.60613        0.17559284        0.00427792
+    17092.44037        0.16612725        0.00425506
+    17099.27735        0.18315116        0.00419702
+    17106.11706        0.19461231        0.00436273
+    17112.95951        0.23018532        0.00457889
+    17119.80469        0.32972394        0.00503965
+    17126.65261        0.58083940        0.00613494
+    17133.50328        1.13943411        0.00805292
+    17140.35668        1.96394023        0.01021293
+    17147.21282        2.34062252        0.01104063
+    17154.07170        1.83699461        0.00987782
+    17160.93333        1.12688013        0.00799342
+    17167.79771        0.64321675        0.00637241
+    17174.66483        0.39810570        0.00533539
+    17181.53469        0.28184042        0.00478068
+    17188.40731        0.22780241        0.00456127
+    17195.28267        0.19798815        0.00447242
+    17202.16078        0.19435024        0.00430372
+    17209.04165        0.18242131        0.00425563
+    17215.92526        0.17968899        0.00425898
+    17222.81163        0.17216482        0.00421022
+    17229.70076        0.17019138        0.00422284
+    17236.59264        0.16728465        0.00424504
+    17243.48727        0.17901784        0.00420242
+    17250.38467        0.16858354        0.00425691
+    17257.28482        0.16550787        0.00420315
+    17264.18774        0.16363890        0.00413281
+    17271.09341        0.15902624        0.00423094
+    17278.00185        0.16142981        0.00420062
+    17284.91305        0.16357074        0.00415352
+    17291.82702        0.15751957        0.00415032
+    17298.74375        0.15977584        0.00415434
+    17305.66324        0.16469389        0.00416104
+    17312.58551        0.15517537        0.00411266
+    17319.51054        0.15793936        0.00414766
+    17326.43835        0.15975575        0.00418945
+    17333.36892        0.16200743        0.00422831
+    17340.30227        0.16503371        0.00414199
+    17347.23839        0.16358811        0.00418529
+    17354.17729        0.15863195        0.00414846
+    17361.11896        0.16035280        0.00414721
+    17368.06341        0.16102282        0.00420490
+    17375.01063        0.16628928        0.00412640
+    17381.96063        0.15628996        0.00418357
+    17388.91342        0.16744769        0.00418860
+    17395.86898        0.17363732        0.00412536
+    17402.82733        0.18286560        0.00420673
+    17409.78846        0.21713709        0.00453385
+    17416.75238        0.29904811        0.00495660
+    17423.71908        0.51215704        0.00587149
+    17430.68857        0.91221557        0.00727227
+    17437.66084        1.25065962        0.00827239
+    17444.63591        1.13124052        0.00789851
+    17451.61376        0.75734297        0.00677426
+    17458.59441        0.46305459        0.00563947
+    17465.57784        0.30660130        0.00483415
+    17472.56408        0.24294881        0.00454324
+    17479.55310        0.20189295        0.00428762
+    17486.54492        0.18954709        0.00422284
+    17493.53954        0.17050114        0.00415870
+    17500.53696        0.17502058        0.00413113
+    17507.53717        0.16516083        0.00411598
+    17514.54019        0.16376097        0.00422258
+    17521.54600        0.16627910        0.00409250
+    17528.55462        0.16514892        0.00410481
+    17535.56604        0.15832038        0.00411933
+    17542.58027        0.15541994        0.00409903
+    17549.59730        0.15781821        0.00411902
+    17556.61714        0.15572897        0.00412825
+    17563.63979        0.14865260        0.00421937
+    17570.66524        0.15701261        0.00414313
+    17577.69351        0.15919245        0.00409255
+    17584.72459        0.16301000        0.00403834
+    17591.75848        0.15711331        0.00412567
+    17598.79518        0.15769444        0.00408330
+    17605.83470        0.15738070        0.00411271
+    17612.87703        0.15311492        0.00412930
+    17619.92218        0.16027660        0.00408000
+    17626.97015        0.15013201        0.00412493
+    17634.02094        0.15734074        0.00405850
+    17641.07455        0.15504179        0.00410385
+    17648.13098        0.15424343        0.00405096
+    17655.19023        0.15001475        0.00410746
+    17662.25231        0.16131279        0.00409912
+    17669.31721        0.16096363        0.00402368
+    17676.38493        0.15836300        0.00405983
+    17683.45549        0.15359891        0.00403348
+    17690.52887        0.16349390        0.00401433
+    17697.60508        0.15131723        0.00404743
+    17704.68412        0.15735020        0.00411500
+    17711.76600        0.15078833        0.00411552
+    17718.85070        0.16112004        0.00410916
+    17725.93824        0.15454283        0.00409498
+    17733.02862        0.15080524        0.00413108
+    17740.12183        0.15198964        0.00408779
+    17747.21788        0.16196678        0.00412366
+    17754.31677        0.16346139        0.00406261
+    17761.41849        0.15116102        0.00406507
+    17768.52306        0.15154105        0.00411997
+    17775.63047        0.15247214        0.00403616
+    17782.74072        0.16033241        0.00404587
+    17789.85382        0.16373208        0.00402997
+    17796.96976        0.14928416        0.00413265
+    17804.08855        0.15550714        0.00405012
+    17811.21018        0.16050399        0.00399884
+    17818.33467        0.15134013        0.00400701
+    17825.46200        0.15843690        0.00405917
+    17832.59219        0.15634988        0.00405847
+    17839.72522        0.16017670        0.00407187
+    17846.86111        0.15360093        0.00409907
+    17853.99986        0.14780292        0.00412313
+    17861.14146        0.15989709        0.00407161
+    17868.28591        0.16369210        0.00400625
+    17875.43323        0.15920609        0.00412794
+    17882.58340        0.15968255        0.00409318
+    17889.73643        0.15326157        0.00415645
+    17896.89233        0.17018044        0.00411100
+    17904.05109        0.16450152        0.00405814
+    17911.21271        0.15971800        0.00411645
+    17918.37719        0.15969020        0.00412667
+    17925.54454        0.16142221        0.00403847
+    17932.71476        0.15846347        0.00407574
+    17939.88785        0.14873271        0.00411994
+    17947.06380        0.15914953        0.00402778
+    17954.24263        0.15336972        0.00409927
+    17961.42432        0.15900198        0.00398169
+    17968.60889        0.15660499        0.00419560
+    17975.79634        0.15839049        0.00408550
+    17982.98666        0.16007554        0.00413303
+    17990.17985        0.16646534        0.00402841
+    17997.37592        0.16523752        0.00404094
+    18004.57487        0.16568634        0.00411737
+    18011.77670        0.17487280        0.00418445
+    18018.98141        0.17064297        0.00414276
+    18026.18901        0.18369823        0.00416361
+    18033.39948        0.20299654        0.00437994
+    18040.61284        0.28927937        0.00475213
+    18047.82909        0.48903922        0.00565352
+    18055.04822        0.99422842        0.00732379
+    18062.27024        1.98661141        0.00996559
+    18069.49515        3.21237305        0.01246835
+    18076.72294        3.37735454        0.01274522
+    18083.95363        2.38067218        0.01081809
+    18091.18721        1.36335044        0.00842540
+    18098.42369        0.76048909        0.00662402
+    18105.66306        0.45352577        0.00548819
+    18112.90532        0.31721450        0.00481950
+    18120.15049        0.24669530        0.00456274
+    18127.39855        0.21522878        0.00431049
+    18134.64951        0.19527435        0.00423951
+    18141.90336        0.18149491        0.00417804
+    18149.16013        0.18431494        0.00417662
+    18156.41979        0.17717419        0.00417354
+    18163.68236        0.17936496        0.00406449
+    18170.94783        0.17060685        0.00407098
+    18178.21621        0.16934406        0.00407005
+    18185.48750        0.17424476        0.00413097
+    18192.76169        0.16802255        0.00405605
+    18200.03880        0.16760093        0.00412466
+    18207.31881        0.16814557        0.00408956
+    18214.60174        0.16907382        0.00405393
+    18221.88758        0.16093839        0.00399987
+    18229.17634        0.16815773        0.00407408
+    18236.46801        0.16214566        0.00408320
+    18243.76259        0.16882986        0.00401831
+    18251.06010        0.16511042        0.00407473
+    18258.36052        0.16109182        0.00410990
+    18265.66387        0.17082802        0.00404080
+    18272.97013        0.16835293        0.00412283
+    18280.27932        0.17048067        0.00410591
+    18287.59143        0.17489631        0.00419384
+    18294.90647        0.15711363        0.00408262
+    18302.22443        0.16097589        0.00413669
+    18309.54532        0.16841072        0.00407250
+    18316.86914        0.16373159        0.00412814
+    18324.19589        0.16287101        0.00410100
+    18331.52556        0.16282640        0.00411018
+    18338.85817        0.15820285        0.00409021
+    18346.19372        0.16454272        0.00403292
+    18353.53220        0.16498356        0.00408890
+    18360.87361        0.16654289        0.00410113
+    18368.21796        0.17389986        0.00408433
+    18375.56525        0.18784300        0.00422307
+    18382.91547        0.23981350        0.00446619
+    18390.26864        0.36524618        0.00500237
+    18397.62474        0.64883725        0.00618548
+    18404.98379        1.26252911        0.00810350
+    18412.34579        2.09966416        0.01016158
+    18419.71073        2.41444867        0.01079354
+    18427.07861        1.81513970        0.00948623
+    18434.44944        1.10924513        0.00764882
+    18441.82322        0.62902844        0.00613501
+    18449.19995        0.39024466        0.00512181
+    18456.57963        0.27877237        0.00454649
+    18463.96226        0.22163835        0.00432956
+    18471.34785        0.19523150        0.00423454
+    18478.73639        0.18163974        0.00411292
+    18486.12788        0.17730887        0.00415114
+    18493.52233        0.16901100        0.00408767
+    18500.91974        0.16931444        0.00406597
+    18508.32011        0.16141446        0.00405787
+    18515.72344        0.17228562        0.00402141
+    18523.12973        0.16967195        0.00398747
+    18530.53898        0.16273083        0.00403221
+    18537.95119        0.16713977        0.00402115
+    18545.36638        0.16176348        0.00397160
+    18552.78452        0.16023789        0.00392461
+    18560.20564        0.15905922        0.00396737
+    18567.62972        0.15631149        0.00400995
+    18575.05677        0.16025901        0.00395261
+    18582.48679        0.15470172        0.00398868
+    18589.91979        0.15142163        0.00391807
+    18597.35575        0.15312806        0.00390054
+    18604.79470        0.15705937        0.00399663
+    18612.23662        0.14964284        0.00401496
+    18619.68151        0.15265376        0.00405657
+    18627.12938        0.15842843        0.00390532
+    18634.58023        0.15278586        0.00397734
+    18642.03407        0.15760690        0.00399778
+    18649.49088        0.15533063        0.00397445
+    18656.95068        0.14900648        0.00396710
+    18664.41346        0.15407312        0.00394367
+    18671.87922        0.15259994        0.00401727
+    18679.34797        0.15903281        0.00400838
+    18686.81971        0.15463022        0.00397113
+    18694.29444        0.14937422        0.00402324
+    18701.77216        0.15701158        0.00393333
+    18709.25287        0.15561775        0.00396896
+    18716.73657        0.15628762        0.00393479
+    18724.22326        0.15774044        0.00399050
+    18731.71295        0.15727974        0.00402616
+    18739.20564        0.17626758        0.00402407
+    18746.70132        0.20232530        0.00414265
+    18754.20000        0.26991060        0.00460880
+    18761.70168        0.44645071        0.00529247
+    18769.20636        0.81344221        0.00667215
+    18776.71404        1.31777884        0.00818190
+    18784.22473        1.51409056        0.00865793
+    18791.73842        1.18692218        0.00777134
+    18799.25511        0.73196370        0.00639088
+    18806.77482        0.44907080        0.00532188
+    18814.29753        0.29186537        0.00465820
+    18821.82325        0.23022266        0.00436706
+    18829.35197        0.19384118        0.00417626
+    18836.88372        0.17823926        0.00406934
+    18844.41847        0.17151261        0.00399496
+    18851.95624        0.16360496        0.00397055
+    18859.49702        0.16771375        0.00394776
+    18867.04082        0.15861415        0.00391412
+    18874.58763        0.15856853        0.00395724
+    18882.13747        0.15417784        0.00394514
+    18889.69032        0.15883754        0.00395178
+    18897.24620        0.15423873        0.00399786
+    18904.80510        0.16195460        0.00388611
+    18912.36702        0.14863213        0.00397540
+    18919.93197        0.14830256        0.00389235
+    18927.49994        0.15455290        0.00393449
+    18935.07094        0.15201594        0.00390353
+    18942.64497        0.15740355        0.00385613
+    18950.22203        0.15105131        0.00390452
+    18957.80212        0.14668141        0.00388127
+    18965.38524        0.15205457        0.00390116
+    18972.97139        0.14830760        0.00387706
+    18980.56058        0.14915839        0.00390087
+    18988.15280        0.14605301        0.00391597
+    18995.74806        0.16015601        0.00389340
+    19003.34636        0.15084681        0.00386065
+    19010.94770        0.15427722        0.00383856
+    19018.55208        0.15000927        0.00388527
+    19026.15950        0.15000990        0.00393282
+    19033.76997        0.15436368        0.00386071
+    19041.38347        0.15074482        0.00392149
+    19049.00003        0.14683774        0.00386549
+    19056.61963        0.14963163        0.00384867
+    19064.24227        0.15071498        0.00382437
+    19071.86797        0.15503397        0.00392032
+    19079.49672        0.15207034        0.00386955
+    19087.12852        0.14889007        0.00383263
+    19094.76337        0.14852345        0.00385600
+    19102.40127        0.14963831        0.00383645
+    19110.04224        0.15236606        0.00386596
+    19117.68625        0.14806220        0.00395257
+    19125.33333        0.15614731        0.00391519
+    19132.98346        0.15980051        0.00396214
+    19140.63665        0.17080428        0.00405402
+    19148.29291        0.21573764        0.00421001
+    19155.95222        0.29365039        0.00459814
+    19163.61461        0.40921022        0.00508434
+    19171.28005        0.45927082        0.00532383
+    19178.94856        0.38092613        0.00501783
+    19186.62014        0.28843014        0.00458093
+    19194.29479        0.21449747        0.00421409
+    19201.97251        0.18376808        0.00400767
+    19209.65330        0.16737700        0.00394618
+    19217.33716        0.16241507        0.00393543
+    19225.02409        0.15919763        0.00384927
+    19232.71410        0.16285814        0.00385757
+    19240.40719        0.15433485        0.00387719
+    19248.10335        0.15193342        0.00392575
+    19255.80259        0.15364614        0.00383175
+    19263.50491        0.14507908        0.00387076
+    19271.21032        0.15641058        0.00385800
+    19278.91880        0.15040508        0.00388464
+    19286.63037        0.15202733        0.00387928
+    19294.34502        0.15295981        0.00391113
+    19302.06276        0.14829632        0.00387992
+    19309.78358        0.14587714        0.00384340
+    19317.50750        0.15311322        0.00391620
+    19325.23450        0.15322797        0.00385058
+    19332.96459        0.14826655        0.00381715
+    19340.69778        0.15402130        0.00393129
+    19348.43406        0.15765357        0.00385938
+    19356.17343        0.15790962        0.00389569
+    19363.91590        0.15334574        0.00388196
+    19371.66147        0.15870556        0.00375529
+    19379.41013        0.15155255        0.00379944
+    19387.16190        0.14610364        0.00385236
+    19394.91676        0.14826568        0.00384113
+    19402.67473        0.14955447        0.00376401
+    19410.43580        0.14606391        0.00375405
+    19418.19997        0.14180975        0.00378601
+    19425.96725        0.14480052        0.00375996
+    19433.73764        0.14070706        0.00385765
+    19441.51113        0.15070397        0.00386425
+    19449.28774        0.14115754        0.00381079
+    19457.06745        0.14464791        0.00375967
+    19464.85028        0.15082275        0.00385158
+    19472.63622        0.15280512        0.00377320
+    19480.42528        0.14988168        0.00385771
+    19488.21745        0.14743626        0.00383282
+    19496.01273        0.14742462        0.00381474
+    19503.81114        0.14684131        0.00375417
+    19511.61266        0.13941360        0.00378367
+    19519.41731        0.14808813        0.00373739
+    19527.22507        0.14568546        0.00379697
+    19535.03596        0.14851977        0.00379427
+    19542.84998        0.13958704        0.00375413
+    19550.66712        0.14597015        0.00376894
+    19558.48739        0.14992373        0.00374618
+    19566.31078        0.15156095        0.00381440
+    19574.13730        0.15058037        0.00370547
+    19581.96696        0.15048920        0.00375382
+    19589.79975        0.15564860        0.00380046
+    19597.63567        0.14056817        0.00385460
+    19605.47472        0.14944553        0.00385292
+    19613.31691        0.14592516        0.00383022
+    19621.16224        0.14661402        0.00378150
+    19629.01070        0.14787289        0.00383610
+    19636.86231        0.14655276        0.00384241
+    19644.71705        0.15165080        0.00373257
+    19652.57494        0.14581164        0.00386121
+    19660.43597        0.14348191        0.00373236
+    19668.30014        0.14397765        0.00381121
+    19676.16746        0.14573843        0.00380084
+    19684.03793        0.14653625        0.00382545
+    19691.91154        0.13920946        0.00379711
+    19699.78831        0.14395322        0.00379039
+    19707.66822        0.14418649        0.00380973
+    19715.55129        0.14554683        0.00378005
+    19723.43751        0.14800391        0.00379445
+    19731.32689        0.15313804        0.00381062
+    19739.21942        0.14326293        0.00386424
+    19747.11511        0.14791229        0.00378521
+    19755.01395        0.14965500        0.00377201
+    19762.91596        0.15187047        0.00371220
+    19770.82112        0.14648679        0.00382514
+    19778.72945        0.15331672        0.00375147
+    19786.64094        0.14278188        0.00381862
+    19794.55560        0.15825292        0.00370770
+    19802.47342        0.14643480        0.00378748
+    19810.39441        0.13300656        0.00386093
+    19818.31857        0.14437903        0.00372053
+    19826.24590        0.15011212        0.00380144
+    19834.17640        0.15010762        0.00378755
+    19842.11007        0.14378008        0.00370904
+    19850.04691        0.14602492        0.00377514
+    19857.98693        0.14866676        0.00372512
+    19865.93012        0.15282199        0.00376783
+    19873.87650        0.14244527        0.00375155
+    19881.82605        0.14812528        0.00381668
+    19889.77878        0.14896285        0.00369838
+    19897.73469        0.15632159        0.00372747
+    19905.69378        0.14590099        0.00376347
+    19913.65606        0.14147276        0.00377773
+    19921.62152        0.14695695        0.00378363
+    19929.59017        0.14272708        0.00375736
+    19937.56201        0.14713276        0.00378659
+    19945.53703        0.15397758        0.00369541
+    19953.51525        0.15049417        0.00377383
+    19961.49665        0.15088516        0.00374373
+    19969.48125        0.16019275        0.00375205
+    19977.46904        0.17413045        0.00386323
+    19985.46003        0.20748544        0.00408378
+    19993.45422        0.30344190        0.00450001
+    20001.45160        0.52847745        0.00539623
+    20009.45218        0.93753496        0.00679851
+    20017.45596        1.49219436        0.00831410
+    20025.46294        1.56916260        0.00852112
+    20033.47313        1.14419289        0.00741435
+    20041.48652        0.70412159        0.00606567
+    20049.50311        0.43300080        0.00502349
+    20057.52291        0.28709273        0.00445231
+    20065.54592        0.22574169        0.00416697
+    20073.57214        0.18623464        0.00396904
+    20081.60157        0.17527827        0.00383313
+    20089.63421        0.16708579        0.00382274
+    20097.67006        0.16182065        0.00380574
+    20105.70913        0.15866278        0.00375303
+    20113.75141        0.14769892        0.00379925
+    20121.79691        0.15764902        0.00377674
+    20129.84563        0.15793866        0.00370338
+    20137.89757        0.14674559        0.00381231
+    20145.95273        0.15225789        0.00381092
+    20154.01111        0.15009905        0.00369393
+    20162.07272        0.15306304        0.00366594
+    20170.13755        0.15501749        0.00363846
+    20178.20560        0.15572490        0.00378096
+    20186.27688        0.14742839        0.00373135
+    20194.35139        0.14870061        0.00376649
+    20202.42913        0.15092049        0.00374930
+    20210.51011        0.15103752        0.00373287
+    20218.59431        0.15389137        0.00373747
+    20226.68175        0.15005027        0.00379749
+    20234.77242        0.15953438        0.00378890
+    20242.86633        0.16072521        0.00377212
+    20250.96348        0.15156735        0.00370286
+    20259.06386        0.14968827        0.00370191
+    20267.16749        0.14127039        0.00379408
+    20275.27435        0.15581424        0.00366087
+    20283.38446        0.14835684        0.00366847
+    20291.49782        0.14729440        0.00367807
+    20299.61442        0.14827523        0.00378849
+    20307.73426        0.15419735        0.00373402
+    20315.85736        0.15127198        0.00369006
+    20323.98370        0.15015588        0.00372781
+    20332.11329        0.15890506        0.00372303
+    20340.24614        0.15168620        0.00376378
+    20348.38224        0.14260549        0.00368649
+    20356.52159        0.14889405        0.00371531
+    20364.66420        0.15502111        0.00370022
+    20372.81006        0.15170899        0.00374974
+    20380.95919        0.14974136        0.00378766
+    20389.11157        0.15180792        0.00369214
+    20397.26721        0.15085760        0.00376617
+    20405.42612        0.15659164        0.00370058
+    20413.58829        0.15158273        0.00377845
+    20421.75373        0.15530103        0.00377062
+    20429.92243        0.16039901        0.00388004
+    20438.09440        0.18103808        0.00385194
+    20446.26964        0.19508086        0.00399857
+    20454.44814        0.26098622        0.00427040
+    20462.62992        0.44307417        0.00505512
+    20470.81497        0.82953109        0.00641702
+    20479.00330        1.64751175        0.00858717
+    20487.19490        2.72502215        0.01079687
+    20495.38978        3.13189487        0.01154990
+    20503.58794        2.37780652        0.01017068
+    20511.78937        1.42718434        0.00805693
+    20519.99409        0.80630639        0.00631251
+    20528.20208        0.47375021        0.00523758
+    20536.41337        0.31968142        0.00456139
+    20544.62793        0.25478362        0.00421718
+    20552.84578        0.20911088        0.00406732
+    20561.06692        0.19646234        0.00387401
+    20569.29135        0.17597688        0.00387846
+    20577.51906        0.17574879        0.00382273
+    20585.75007        0.17151216        0.00378616
+    20593.98437        0.17499804        0.00379998
+    20602.22197        0.16258606        0.00374532
+    20610.46285        0.16209624        0.00374994
+    20618.70704        0.16035789        0.00378907
+    20626.95452        0.15260038        0.00369367
+    20635.20530        0.15632812        0.00369516
+    20643.45939        0.15482996        0.00373606
+    20651.71677        0.15131930        0.00371655
+    20659.97746        0.15324331        0.00360142
+    20668.24145        0.15293149        0.00361940
+    20676.50874        0.14828374        0.00372573
+    20684.77935        0.14814033        0.00364017
+    20693.05326        0.15049870        0.00371604
+    20701.33048        0.14779677        0.00366460
+    20709.61101        0.14300238        0.00370936
+    20717.89486        0.15077738        0.00361422
+    20726.18201        0.14384475        0.00368778
+    20734.47249        0.14885850        0.00367786
+    20742.76628        0.14890566        0.00357396
+    20751.06338        0.14381512        0.00365410
+    20759.36381        0.14131435        0.00368516
+    20767.66755        0.14228723        0.00366534
+    20775.97462        0.14295485        0.00363577
+    20784.28501        0.14438665        0.00361628
+    20792.59872        0.14304241        0.00367773
+    20800.91576        0.14079578        0.00365850
+    20809.23613        0.14662395        0.00363327
+    20817.55983        0.14507482        0.00359566
+    20825.88685        0.14646958        0.00366642
+    20834.21720        0.13672196        0.00360251
+    20842.55089        0.14194921        0.00364435
+    20850.88791        0.14793102        0.00362834
+    20859.22827        0.14862471        0.00360943
+    20867.57196        0.14803290        0.00361957
+    20875.91899        0.14701006        0.00368476
+    20884.26935        0.14249395        0.00362001
+    20892.62306        0.15072447        0.00359226
+    20900.98011        0.14676030        0.00361603
+    20909.34050        0.14696997        0.00358844
+    20917.70424        0.14473054        0.00371419
+    20926.07132        0.14527305        0.00369105
+    20934.44175        0.15286183        0.00361283
+    20942.81553        0.14898678        0.00369400
+    20951.19265        0.16073211        0.00371514
+    20959.57313        0.17758325        0.00389123
+    20967.95696        0.24442355        0.00411762
+    20976.34414        0.37109555        0.00473874
+    20984.73468        0.61501559        0.00563960
+    20993.12857        0.99254839        0.00681377
+    21001.52582        1.11589759        0.00715607
+    21009.92643        0.86755475        0.00647877
+    21018.33041        0.55851837        0.00542419
+    21026.73774        0.36006575        0.00463749
+    21035.14843        0.25851830        0.00412266
+    21043.56249        0.20837615        0.00388480
+    21051.97992        0.17420085        0.00379397
+    21060.40071        0.16948436        0.00370018
+    21068.82487        0.16201097        0.00368013
+    21077.25240        0.16292750        0.00370695
+    21085.68330        0.15473739        0.00366353
+    21094.11757        0.15980243        0.00363205
+    21102.55522        0.15616757        0.00364263
+    21110.99624        0.14534231        0.00367167
+    21119.44064        0.15337413        0.00362259
+    21127.88842        0.14584104        0.00366175
+    21136.33957        0.14880004        0.00363079
+    21144.79411        0.14357388        0.00362693
+    21153.25203        0.13733593        0.00364355
+    21161.71333        0.14568736        0.00364198
+    21170.17801        0.14896367        0.00361076
+    21178.64608        0.14857037        0.00355486
+    21187.11754        0.14424035        0.00358684
+    21195.59239        0.14290905        0.00363311
+    21204.07063        0.14733006        0.00362855
+    21212.55225        0.13932900        0.00363648
+    21221.03727        0.14312051        0.00357402
+    21229.52569        0.14350321        0.00357990
+    21238.01750        0.13928723        0.00358079
+    21246.51271        0.14596057        0.00358707
+    21255.01131        0.14258923        0.00362739
+    21263.51332        0.14300131        0.00354167
+    21272.01872        0.15016738        0.00359824
+    21280.52753        0.14310382        0.00360024
+    21289.03974        0.14273632        0.00361899
+    21297.55536        0.13811948        0.00358770
+    21306.07438        0.14128870        0.00360794
+    21314.59681        0.14249391        0.00360091
+    21323.12265        0.14661423        0.00362250
+    21331.65190        0.14434512        0.00363552
+    21340.18456        0.13657695        0.00362862
+    21348.72063        0.14065737        0.00364217
+    21357.26012        0.14510733        0.00365169
+    21365.80302        0.14083273        0.00363374
+    21374.34934        0.14404779        0.00352931
+    21382.89908        0.14037699        0.00369465
+    21391.45224        0.14839067        0.00365843
+    21400.00882        0.14388502        0.00361456
+    21408.56883        0.13527786        0.00359374
+    21417.13226        0.13726116        0.00366213
+    21425.69911        0.14156536        0.00372596
+    21434.26939        0.14035716        0.00369729
+    21442.84310        0.14845596        0.00367795
+    21451.42023        0.14271740        0.00368465
+    21460.00080        0.14016011        0.00365840
+    21468.58480        0.14043330        0.00373461
+    21477.17224        0.14583863        0.00372119
+    21485.76310        0.14700008        0.00366669
+    21494.35741        0.14870148        0.00369182
+    21502.95515        0.15730089        0.00380332
+    21511.55633        0.18888585        0.00392617
+    21520.16096        0.24540033        0.00425289
+    21528.76902        0.35793006        0.00475584
+    21537.38053        0.51331825        0.00542044
+    21545.99548        0.59872634        0.00568572
+    21554.61388        0.49591886        0.00533521
+    21563.23573        0.36091455        0.00477535
+    21571.86102        0.25851757        0.00425456
+    21580.48976        0.19359052        0.00400184
+    21589.12196        0.17606591        0.00395224
+    21597.75761        0.16474268        0.00390373
+    21606.39671        0.16543313        0.00381316
+    21615.03927        0.15718789        0.00381823
+    21623.68529        0.16260511        0.00382750
+    21632.33476        0.15719903        0.00381147
+    21640.98769        0.15065386        0.00382171
+    21649.64409        0.15748181        0.00371144
+    21658.30395        0.15235029        0.00372584
+    21666.96727        0.14597535        0.00376912
+    21675.63406        0.14500814        0.00377004
+    21684.30431        0.14455341        0.00379412
+    21692.97803        0.14450569        0.00380088
+    21701.65522        0.14671367        0.00375364
+    21710.33588        0.14815196        0.00375350
+    21719.02002        0.14764786        0.00373330
+    21727.70763        0.15208323        0.00366303
+    21736.39871        0.14463413        0.00368085
+    21745.09327        0.15306812        0.00371242
+    21753.79131        0.14123343        0.00370512
+    21762.49282        0.14749567        0.00366299
+    21771.19782        0.14584815        0.00376683
+    21779.90630        0.15058029        0.00365429
+    21788.61826        0.13764256        0.00373314
+    21797.33371        0.14656181        0.00372474
+    21806.05264        0.14255572        0.00378679
+    21814.77506        0.14680654        0.00373897
+    21823.50097        0.14433777        0.00370064
+    21832.23037        0.13910408        0.00377498
+    21840.96327        0.14512114        0.00379570
+    21849.69965        0.14229248        0.00373109
+    21858.43953        0.14951879        0.00376585
+    21867.18291        0.14358524        0.00379269
+    21875.92978        0.14423371        0.00376698
+    21884.68015        0.14533341        0.00375079
+    21893.43402        0.15017666        0.00377591
+    21902.19140        0.14338854        0.00381460
+    21910.95227        0.14588272        0.00376290
+    21919.71665        0.13408190        0.00388287
+    21928.48454        0.15459545        0.00365623
+    21937.25594        0.14387589        0.00374951
+    21946.03084        0.14430674        0.00380699
+    21954.80925        0.15073668        0.00372306
+    21963.59117        0.15372766        0.00376661
+    21972.37661        0.14663735        0.00373996
+    21981.16556        0.14858856        0.00382400
+    21989.95803        0.15486807        0.00375090
+    21998.75401        0.14609300        0.00372128
+    22007.55351        0.15474052        0.00383084
+    22016.35653        0.15399915        0.00389316
+    22025.16308        0.15314732        0.00384747
+    22033.97314        0.15728581        0.00383304
+    22042.78673        0.16696926        0.00384124
+    22051.60385        0.16809393        0.00392171
+    22060.42449        0.16859270        0.00394686
+    22069.24866        0.18221457        0.00398919
+    22078.07636        0.20703099        0.00417004
+    22086.90759        0.26205108        0.00447777
+    22095.74235        0.42020914        0.00523764
+    22104.58065        0.81342145        0.00666686
+    22113.42248        1.68544190        0.00918981
+    22122.26785        3.19727794        0.01238699
+    22131.11675        4.79963219        0.01506174
+    22139.96920        4.81179284        0.01508394
+    22148.82519        3.36579533        0.01272540
+    22157.68472        1.91743175        0.00975940
+    22166.54779        1.05258188        0.00750532
+    22175.41441        0.61793074        0.00595948
+    22184.28458        0.39222978        0.00509937
+    22193.15829        0.28979034        0.00456223
+    22202.03556        0.25202960        0.00431636
+    22210.91637        0.21452416        0.00432163
+    22219.80074        0.20230711        0.00412264
+    22228.68866        0.18373610        0.00407136
+    22237.58013        0.18029937        0.00399565
+    22246.47516        0.17974093        0.00396772
+    22255.37375        0.17006836        0.00398384
+    22264.27590        0.16366512        0.00395908
+    22273.18161        0.16610163        0.00388208
+    22282.09089        0.15723600        0.00387510
+    22291.00372        0.15669154        0.00380919
+    22299.92012        0.15548118        0.00385625
+    22308.84009        0.15105160        0.00383951
+    22317.76363        0.15087658        0.00381441
+    22326.69073        0.14559306        0.00388629
+    22335.62141        0.14803966        0.00387981
+    22344.55566        0.14894849        0.00383255
+    22353.49348        0.15353135        0.00375377
+    22362.43488        0.14581746        0.00383341
+    22371.37985        0.14873891        0.00382957
+    22380.32840        0.15600969        0.00379392
+    22389.28054        0.14851823        0.00377915
+    22398.23625        0.15017078        0.00381021
+    22407.19554        0.14642611        0.00381337
+    22416.15842        0.14407767        0.00379844
+    22425.12488        0.14795115        0.00380583
+    22434.09493        0.14402165        0.00380265
+    22443.06857        0.14620719        0.00375356
+    22452.04580        0.14310532        0.00373363
+    22461.02662        0.14743395        0.00375225
+    22470.01103        0.14611232        0.00370211
+    22478.99903        0.14940546        0.00380485
+    22487.99063        0.14555638        0.00377522
+    22496.98583        0.14005138        0.00371542
+    22505.98462        0.14559056        0.00380793
+    22514.98702        0.14245961        0.00370520
+    22523.99301        0.13561888        0.00384939
+    22533.00261        0.14830822        0.00374488
+    22542.01581        0.15059996        0.00366931
+    22551.03262        0.14068265        0.00386488
+    22560.05303        0.14394928        0.00380064
+    22569.07705        0.14581648        0.00372894
+    22578.10468        0.14880105        0.00370574
+    22587.13592        0.14018520        0.00381674
+    22596.17078        0.14325899        0.00383923
+    22605.20925        0.14874090        0.00385743
+    22614.25133        0.14966704        0.00377767
+    22623.29703        0.14803774        0.00384627
+    22632.34635        0.14327429        0.00382008
+    22641.39929        0.14600674        0.00380736
+    22650.45585        0.14523549        0.00387337
+    22659.51603        0.15132254        0.00380914
+    22668.57984        0.15405924        0.00385285
+    22677.64727        0.14851442        0.00386146
+    22686.71833        0.15012194        0.00386735
+    22695.79301        0.15258726        0.00389548
+    22704.87133        0.15379266        0.00385396
+    22713.95328        0.16928932        0.00393266
+    22723.03886        0.18974773        0.00403194
+    22732.12808        0.23106355        0.00429959
+    22741.22093        0.34762009        0.00500003
+    22750.31742        0.62160337        0.00610516
+    22759.41754        1.14548004        0.00797642
+    22768.52131        1.88028632        0.00994668
+    22777.62872        2.24951747        0.01087701
+    22786.73977        1.82691618        0.00988660
+    22795.85447        1.17213331        0.00813784
+    22804.97281        0.68788449        0.00644827
+    22814.09480        0.41353390        0.00531520
+    22823.22043        0.29210061        0.00467972
+    22832.34972        0.22439064        0.00421711
+    22841.48266        0.19602971        0.00412250
+    22850.61926        0.17729631        0.00412441
+    22859.75950        0.16547080        0.00410391
+    22868.90341        0.15683326        0.00408584
+    22878.05097        0.15506570        0.00395896
+    22887.20219        0.16205970        0.00392022
+    22896.35707        0.15773221        0.00391919
+    22905.51561        0.15389713        0.00395144
+    22914.67782        0.14437920        0.00393525
+    22923.84369        0.14944501        0.00401838
+    22933.01323        0.14781020        0.00392930
+    22942.18643        0.15002921        0.00389088
+    22951.36331        0.15109551        0.00386906
+    22960.54385        0.14582886        0.00381406
+    22969.72807        0.14064499        0.00398485
+    22978.91596        0.14456415        0.00391399
+    22988.10753        0.14477461        0.00386731
+    22997.30277        0.15104639        0.00402887
+    23006.50169        0.14377471        0.00384259
+    23015.70429        0.14464753        0.00398044
+    23024.91057        0.14475422        0.00387925
+    23034.12054        0.14338615        0.00380073
+    23043.33419        0.14542085        0.00398073
+    23052.55152        0.13658592        0.00386046
+    23061.77254        0.13736561        0.00395539
+    23070.99725        0.13339483        0.00393506
+    23080.22565        0.13130917        0.00399795
+    23089.45774        0.14097550        0.00384085
+    23098.69352        0.14017288        0.00393050
+    23107.93300        0.14189560        0.00392536
+    23117.17617        0.14548553        0.00394919
+    23126.42304        0.13758579        0.00387889
+    23135.67361        0.13829316        0.00398304
+    23144.92788        0.13770014        0.00393943
+    23154.18585        0.14840110        0.00390468
+    23163.44753        0.13649141        0.00394458
+    23172.71291        0.14108639        0.00399897
+    23181.98199        0.13716392        0.00397263
+    23191.25478        0.14586548        0.00395726
+    23200.53129        0.13577307        0.00397664
+    23209.81150        0.14221093        0.00390046
+    23219.09542        0.13641256        0.00397721
+    23228.38306        0.14200115        0.00397722
+    23237.67442        0.14027826        0.00395440
+    23246.96948        0.15364547        0.00390972
+    23256.26827        0.14115723        0.00404485
+    23265.57078        0.13948376        0.00404297
+    23274.87701        0.13729559        0.00400286
+    23284.18696        0.14918125        0.00404462
+    23293.50063        0.14469746        0.00399870
+    23302.81803        0.14271305        0.00398350
+    23312.13916        0.14938015        0.00401732
+    23321.46402        0.14868735        0.00405666
+    23330.79260        0.14816439        0.00408999
+    23340.12492        0.14503434        0.00409866
+    23349.46097        0.14763138        0.00405510
+    23358.80075        0.14478060        0.00400862
+    23368.14427        0.15051868        0.00406422
+    23377.49153        0.14718930        0.00409631
+    23386.84253        0.15289856        0.00412641
+    23396.19727        0.14258190        0.00408257
+    23405.55574        0.15891447        0.00415679
+    23414.91797        0.17392589        0.00420012
+    23424.28393        0.19807033        0.00443154
+    23433.65365        0.26578614        0.00488898
+    23443.02711        0.43688916        0.00576004
+    23452.40432        0.80024899        0.00728277
+    23461.78528        1.43246377        0.00944843
+    23471.17000        2.15364186        0.01145396
+    23480.55846        2.33258406        0.01188613
+    23489.95069        1.81881788        0.01058782
+    23499.34667        1.12468359        0.00856859
+    23508.74641        0.66336288        0.00689855
+    23518.14990        0.41211679        0.00566204
+    23527.55716        0.28347582        0.00495391
+    23536.96819        0.22344162        0.00461791
+    23546.38297        0.18988436        0.00441997
+    23555.80153        0.18016982        0.00436941
+    23565.22385        0.17280344        0.00430857
+    23574.64994        0.16082438        0.00431410
+    23584.07980        0.16132140        0.00426168
+    23593.51343        0.15681381        0.00429272
+    23602.95084        0.14935363        0.00424069
+    23612.39202        0.15186614        0.00414321
+    23621.83697        0.15133398        0.00413402
+    23631.28571        0.15097835        0.00414536
+    23640.73822        0.14605785        0.00411239
+    23650.19452        0.13669397        0.00410619
+    23659.65459        0.14001802        0.00413224
+    23669.11846        0.14156666        0.00417293
+    23678.58610        0.14280171        0.00418000
+    23688.05754        0.14111365        0.00424047
+    23697.53276        0.14493019        0.00408784
+    23707.01177        0.14183929        0.00415552
+    23716.49458        0.14395037        0.00411645
+    23725.98118        0.14148471        0.00415679
+    23735.47157        0.13857365        0.00413354
+    23744.96576        0.14163158        0.00414551
+    23754.46374        0.13887933        0.00415996
+    23763.96553        0.13767232        0.00420193
+    23773.47112        0.14109597        0.00408554
+    23782.98050        0.13442341        0.00423573
+    23792.49370        0.13242653        0.00413763
+    23802.01069        0.13381201        0.00415822
+    23811.53150        0.14015232        0.00416534
+    23821.05611        0.13375711        0.00429336
+    23830.58453        0.13362847        0.00421710
+    23840.11677        0.13161667        0.00422942
+    23849.65281        0.14268321        0.00416211
+    23859.19268        0.13935236        0.00416022
+    23868.73635        0.14181162        0.00418001
+    23878.28385        0.14066672        0.00416022
+    23887.83516        0.13787835        0.00424690
+    23897.39029        0.13742522        0.00420696
+    23906.94925        0.14552579        0.00415258
+    23916.51203        0.14055461        0.00417662
+    23926.07864        0.14069940        0.00430198
+    23935.64907        0.13507596        0.00421054
+    23945.22333        0.12976439        0.00430861
+    23954.80142        0.13930041        0.00429002
+    23964.38334        0.13867226        0.00417359
+    23973.96909        0.14003130        0.00413989
+    23983.55868        0.14614898        0.00416850
+    23993.15210        0.13360665        0.00425817
+    24002.74936        0.13229716        0.00415170
+    24012.35046        0.13962060        0.00429411
+    24021.95540        0.13829248        0.00422747
+    24031.56418        0.14001890        0.00430117
+    24041.17681        0.13337924        0.00418962
+    24050.79328        0.13336698        0.00436407
+    24060.41360        0.13911244        0.00424051
+    24070.03776        0.13419814        0.00426484
+    24079.66578        0.13970935        0.00420317
+    24089.29764        0.13685814        0.00434438
+    24098.93336        0.13735338        0.00416476
+    24108.57294        0.13491149        0.00427527
+    24118.21637        0.14151363        0.00425234
+    24127.86365        0.13394664        0.00428335
+    24137.51480        0.13900249        0.00431091
+    24147.16980        0.13272478        0.00419461
+    24156.82867        0.13547783        0.00425021
+    24166.49140        0.14311582        0.00424320
+    24176.15800        0.14192478        0.00433999
+    24185.82846        0.13174138        0.00428002
+    24195.50279        0.13776488        0.00432349
+    24205.18100        0.14089382        0.00420498
+    24214.86307        0.13964580        0.00423008
+    24224.54901        0.13945715        0.00426769
+    24234.23883        0.13050190        0.00420182
+    24243.93253        0.14330755        0.00427933
+    24253.63010        0.13548751        0.00424068
+    24263.33155        0.13541967        0.00441846
+    24273.03689        0.13778619        0.00426342
+    24282.74610        0.13479000        0.00425688
+    24292.45920        0.14042501        0.00430219
+    24302.17618        0.13670721        0.00425795
+    24311.89705        0.13028020        0.00429853
+    24321.62181        0.13751279        0.00418465
+    24331.35046        0.13247656        0.00434217
+    24341.08300        0.14183207        0.00416078
+    24350.81943        0.13305519        0.00432308
+    24360.55976        0.13428887        0.00426524
+    24370.30399        0.13802424        0.00418345
+    24380.05211        0.12084483        0.00436881
+    24389.80413        0.13509683        0.00433201
+    24399.56005        0.14209308        0.00418241
+    24409.31987        0.13798925        0.00436661
+    24419.08360        0.13132920        0.00422033
+    24428.85124        0.13394539        0.00426127
+    24438.62278        0.13861489        0.00419574
+    24448.39822        0.12938168        0.00426308
+    24458.17758        0.12933085        0.00433019
+    24467.96085        0.12906619        0.00435837
+    24477.74804        0.14651167        0.00425209
+    24487.53914        0.13465017        0.00432297
+    24497.33415        0.13028371        0.00417835
+    24507.13309        0.13421507        0.00434433
+    24516.93594        0.13290946        0.00418101
+    24526.74272        0.14250388        0.00429261
+    24536.55341        0.13644176        0.00429658
+    24546.36803        0.13790459        0.00424009
+    24556.18658        0.13639515        0.00424160
+    24566.00906        0.13187054        0.00432965
+    24575.83546        0.13841681        0.00433683
+    24585.66579        0.13857182        0.00433761
+    24595.50006        0.13079731        0.00435826
+    24605.33826        0.12928881        0.00431326
+    24615.18040        0.13702350        0.00430600
+    24625.02647        0.13290554        0.00424947
+    24634.87648        0.13813441        0.00424663
+    24644.73043        0.13608372        0.00425017
+    24654.58832        0.13480032        0.00432354
+    24664.45016        0.13179096        0.00438781
+    24674.31594        0.13163504        0.00428020
+    24684.18566        0.13980221        0.00427106
+    24694.05934        0.13184613        0.00429800
+    24703.93696        0.14199037        0.00423945
+    24713.81854        0.13673985        0.00428854
+    24723.70406        0.13541187        0.00435360
+    24733.59354        0.13670704        0.00432521
+    24743.48698        0.13167439        0.00431161
+    24753.38438        0.13072115        0.00452703
+    24763.28573        0.14107823        0.00437860
+    24773.19104        0.12675111        0.00431721
+    24783.10032        0.14013982        0.00434922
+    24793.01356        0.13051251        0.00449069
+    24802.93077        0.13390458        0.00440471
+    24812.85194        0.13493105        0.00437939
+    24822.77708        0.12514124        0.00439570
+    24832.70619        0.12833102        0.00437722
+    24842.63927        0.13590253        0.00448498
+    24852.57633        0.13514578        0.00446127
+    24862.51736        0.12816879        0.00445478
+    24872.46237        0.13055559        0.00445553
+    24882.41135        0.13343868        0.00449600
+    24892.36432        0.12411612        0.00458856
+    24902.32126        0.13272425        0.00442743
+    24912.28219        0.13231331        0.00450941
+    24922.24710        0.12712499        0.00446511
+    24932.21600        0.13585928        0.00447865
+    24942.18889        0.13173212        0.00452071
+    24952.16576        0.14134196        0.00442440
+    24962.14663        0.13103392        0.00441692
+    24972.13149        0.13217889        0.00449117
+    24982.12034        0.13319689        0.00438711
+    24992.11319        0.13411938        0.00443318
+    25002.11003        0.12479525        0.00458882
+    25012.11088        0.13591875        0.00450278
+    25022.11572        0.13867438        0.00451475
+    25032.12457        0.13899198        0.00452331
+    25042.13742        0.13134229        0.00451116
+    25052.15427        0.15719199        0.00470553
+    25062.17514        0.18490137        0.00483595
+    25072.20001        0.22518721        0.00516620
+    25082.22889        0.29241928        0.00566391
+    25092.26178        0.36524962        0.00612421
+    25102.29868        0.37316024        0.00608952
+    25112.33960        0.31756558        0.00577337
+    25122.38454        0.25079984        0.00535662
+    25132.43349        0.19192605        0.00487968
+    25142.48646        0.16922407        0.00475439
+    25152.54346        0.15365090        0.00463295
+    25162.60448        0.13702202        0.00465573
+    25172.66952        0.13696493        0.00473386
+    25182.73859        0.12587963        0.00452950
+    25192.81168        0.13801731        0.00456255
+    25202.88881        0.13227454        0.00465301
+    25212.96996        0.13794451        0.00445481
+    25223.05515        0.13695524        0.00456429
+    25233.14437        0.13995567        0.00464793
+    25243.23763        0.13117212        0.00452560
+    25253.33492        0.13744459        0.00456812
+    25263.43626        0.13264280        0.00455951
+    25273.54163        0.13279613        0.00460992
+    25283.65105        0.13524516        0.00453842
+    25293.76451        0.13543694        0.00456609
+    25303.88202        0.13785795        0.00468288
+    25314.00357        0.13905368        0.00468968
+    25324.12917        0.13230944        0.00463078
+    25334.25882        0.12350848        0.00470873
+    25344.39253        0.13658219        0.00466572
+    25354.53028        0.13106735        0.00461011
+    25364.67209        0.13468966        0.00450800
+    25374.81796        0.13528873        0.00455856
+    25384.96789        0.13818422        0.00467713
+    25395.12188        0.13251811        0.00470494
+    25405.27993        0.13169140        0.00466992
+    25415.44204        0.13182366        0.00466094
+    25425.60822        0.13132237        0.00479330
+    25435.77846        0.13379297        0.00472497
+    25445.95277        0.13452786        0.00471484
+    25456.13115        0.13823690        0.00470478
+    25466.31360        0.13362244        0.00462956
+    25476.50013        0.12934768        0.00482054
+    25486.69073        0.12175995        0.00472847
+    25496.88541        0.13760474        0.00474549
+    25507.08416        0.14209030        0.00466490
+    25517.28699        0.13369686        0.00476732
+    25527.49391        0.13607496        0.00475795
+    25537.70491        0.13207705        0.00478980
+    25547.91999        0.13768228        0.00467873
+    25558.13916        0.12716126        0.00471979
+    25568.36241        0.14107748        0.00462533
+    25578.58976        0.13160050        0.00464970
+    25588.82119        0.12760035        0.00485233
+    25599.05672        0.12412552        0.00477270
+    25609.29634        0.13369101        0.00476476
+    25619.54006        0.13872618        0.00482260
+    25629.78788        0.13911058        0.00467380
+    25640.03979        0.13120098        0.00477345
+    25650.29581        0.13926703        0.00479783
+    25660.55593        0.13320611        0.00485954
+    25670.82015        0.13254887        0.00484183
+    25681.08848        0.13785277        0.00484861
+    25691.36091        0.13865697        0.00476868
+    25701.63746        0.13822995        0.00473105
+    25711.91811        0.13342205        0.00473705
+    25722.20288        0.13391886        0.00477634
+    25732.49176        0.12665554        0.00489771
+    25742.78476        0.13589961        0.00480834
+    25753.08187        0.13697036        0.00474844
+    25763.38310        0.13649935        0.00493763
+    25773.68846        0.13728617        0.00482127
+    25783.99793        0.12873537        0.00486430
+    25794.31153        0.13079355        0.00479168
+    25804.62926        0.13713262        0.00480561
+    25814.95111        0.13445812        0.00497012
+    25825.27709        0.13365352        0.00486584
+    25835.60720        0.12547708        0.00482119
+    25845.94144        0.12879793        0.00495585
+    25856.27982        0.12636441        0.00492751
+    25866.62233        0.13924531        0.00491370
+    25876.96898        0.13089111        0.00486048
+    25887.31977        0.14404388        0.00480458
+    25897.67470        0.13328882        0.00501564
+    25908.03376        0.14509742        0.00494932
+    25918.39698        0.14195751        0.00478994
+    25928.76434        0.14664919        0.00495478
+    25939.13584        0.13380363        0.00483905
+    25949.51150        0.13246538        0.00495738
+    25959.89130        0.13828607        0.00514240
+    25970.27526        0.14279214        0.00493892
+    25980.66337        0.14626521        0.00496878
+    25991.05563        0.15393348        0.00509265
+    26001.45206        0.16099427        0.00517386
+    26011.85264        0.19005575        0.00546342
+    26022.25738        0.23766461        0.00575541
+    26032.66628        0.30501797        0.00637644
+    26043.07935        0.34494390        0.00658363
+    26053.49658        0.32634018        0.00646259
+    26063.91798        0.27174744        0.00605515
+    26074.34354        0.21945363        0.00567436
+    26084.77328        0.18554849        0.00539857
+    26095.20719        0.15069306        0.00514232
+    26105.64527        0.14674653        0.00498679
+    26116.08753        0.14553237        0.00507750
+    26126.53397        0.15307750        0.00508999
+    26136.98458        0.13599074        0.00493332
+    26147.43938        0.13782936        0.00500019
+    26157.89835        0.13524423        0.00488146
+    26168.36151        0.13385962        0.00510882
+    26178.82885        0.13769769        0.00495906
+    26189.30039        0.13279491        0.00494150
+    26199.77611        0.13458091        0.00514369
+    26210.25602        0.13747946        0.00501559
+    26220.74012        0.13308417        0.00505602
+    26231.22842        0.12067239        0.00495457
+    26241.72091        0.13324709        0.00502688
+    26252.21760        0.13285956        0.00503454
+    26262.71848        0.13330360        0.00494117
+    26273.22357        0.13118144        0.00510240
+    26283.73286        0.14201654        0.00509626
+    26294.24635        0.13800633        0.00510120
+    26304.76405        0.13888984        0.00519492
+    26315.28596        0.14632668        0.00502783
+    26325.81207        0.13474652        0.00501726
+    26336.34240        0.13853158        0.00500701
+    26346.87693        0.13952831        0.00513314
+    26357.41568        0.14310259        0.00517379
+    26367.95865        0.14018250        0.00501774
+    26378.50583        0.13626097        0.00506009
+    26389.05724        0.13723260        0.00511520
+    26399.61286        0.14119093        0.00509708
+    26410.17270        0.13055027        0.00510058
+    26420.73677        0.12848821        0.00515030
+    26431.30507        0.12908836        0.00503993
+    26441.87759        0.14244653        0.00496658
+    26452.45434        0.13855105        0.00488988
+    26463.03532        0.13570508        0.00502045
+    26473.62054        0.12857280        0.00516996
+    26484.20998        0.13038162        0.00500120
+    26494.80367        0.13710360        0.00510780
+    26505.40159        0.13285335        0.00497549
+    26516.00375        0.12849238        0.00500502
+    26526.61015        0.13580550        0.00503243
+    26537.22080        0.13017387        0.00490143
+    26547.83568        0.14087266        0.00506983
+    26558.45482        0.12829522        0.00495450
+    26569.07820        0.13335553        0.00498550
+    26579.70583        0.13404232        0.00490541
+    26590.33771        0.12797082        0.00506871
+    26600.97385        0.13931062        0.00495545
+    26611.61424        0.12927542        0.00492620
+    26622.25888        0.12907479        0.00502730
+    26632.90779        0.13378594        0.00508677
+    26643.56095        0.13456865        0.00500236
+    26654.21838        0.12513747        0.00511901
+    26664.88006        0.13174642        0.00514928
+    26675.54601        0.13087930        0.00486130
+    26686.21623        0.13308928        0.00508036
+    26696.89072        0.13764963        0.00508472
+    26707.56948        0.13301988        0.00508307
+    26718.25250        0.13093660        0.00504256
+    26728.93980        0.13118794        0.00508542
+    26739.63138        0.13110912        0.00503982
+    26750.32723        0.13734361        0.00496518
+    26761.02736        0.13723829        0.00513767
+    26771.73178        0.12270916        0.00500725
+    26782.44047        0.13743726        0.00502659
+    26793.15344        0.13220434        0.00510559
+    26803.87071        0.13268685        0.00506524
+    26814.59225        0.13796107        0.00504495
+    26825.31809        0.13631502        0.00513335
+    26836.04822        0.13152062        0.00500560
+    26846.78264        0.14191399        0.00503257
+    26857.52135        0.13511915        0.00522964
+    26868.26436        0.14512954        0.00505924
+    26879.01166        0.13935325        0.00513470
+    26889.76327        0.13726916        0.00512663
+    26900.51917        0.13366690        0.00504170
+    26911.27938        0.13704044        0.00516999
+    26922.04389        0.13687377        0.00494140
+    26932.81271        0.13895177        0.00502081
+    26943.58584        0.13633941        0.00508810
+    26954.36327        0.14603716        0.00520364
+    26965.14502        0.13471606        0.00507327
+    26975.93107        0.15652175        0.00503066
+    26986.72145        0.13527338        0.00513539
+    26997.51614        0.14028054        0.00528740
+    27008.31514        0.14426751        0.00529746
+    27019.11847        0.15321083        0.00517199
+    27029.92612        0.16446871        0.00533350
+    27040.73809        0.18277473        0.00562527
+    27051.55438        0.22355631        0.00592969
+    27062.37500        0.32488844        0.00667173
+    27073.19995        0.55181695        0.00811791
+    27084.02923        0.92210109        0.01012420
+    27094.86284        1.39917592        0.01208126
+    27105.70079        1.67483956        0.01317354
+    27116.54307        1.59039449        0.01292526
+    27127.38969        1.20838640        0.01133259
+    27138.24064        0.80088448        0.00950109
+    27149.09594        0.50787152        0.00787678
+    27159.95558        0.34802743        0.00684045
+    27170.81956        0.24637136        0.00597661
+    27181.68789        0.18321970        0.00584778
+    27192.56056        0.17373600        0.00549211
+    27203.43759        0.15984148        0.00547966
+    27214.31896        0.15571569        0.00540221
+    27225.20469        0.15299614        0.00542566
+    27236.09477        0.15024444        0.00532657
+    27246.98921        0.14659078        0.00533375
+    27257.88800        0.14636057        0.00541356
+    27268.79116        0.14169501        0.00522819
+    27279.69868        0.14537422        0.00526185
+    27290.61056        0.14900486        0.00536236
+    27301.52680        0.14083872        0.00547883
+    27312.44741        0.13661048        0.00531474
+    27323.37239        0.14145529        0.00560784
+    27334.30174        0.12545013        0.00549015
+    27345.23546        0.13710154        0.00529250
+    27356.17355        0.14545118        0.00537852
+    27367.11602        0.13335886        0.00537726
+    27378.06287        0.13480349        0.00520656
+    27389.01409        0.13584711        0.00524185
+    27399.96970        0.14105571        0.00526346
+    27410.92969        0.13512508        0.00537299
+    27421.89406        0.12705766        0.00529531
+    27432.86282        0.14019408        0.00548656
+    27443.83596        0.13406847        0.00526898
+    27454.81350        0.13426793        0.00535795
+    27465.79542        0.12927233        0.00530829
+    27476.78174        0.14415414        0.00520422
+    27487.77245        0.12903222        0.00537308
+    27498.76756        0.13217127        0.00538269
+    27509.76707        0.13649325        0.00545669
+    27520.77098        0.13012021        0.00528554
+    27531.77928        0.13068550        0.00524209
+    27542.79200        0.12709678        0.00543293
+    27553.80911        0.13765417        0.00540447
+    27564.83064        0.13052892        0.00548766
+    27575.85657        0.13947334        0.00544376
+    27586.88691        0.13507015        0.00521318
+    27597.92167        0.13178190        0.00528115
+    27608.96084        0.14154421        0.00529846
+    27620.00442        0.12931545        0.00551878
+    27631.05242        0.12304155        0.00550270
+    27642.10484        0.13897227        0.00542283
+    27653.16168        0.13250001        0.00545068
+    27664.22295        0.13860344        0.00536734
+    27675.28864        0.12253118        0.00548984
+    27686.35875        0.13912200        0.00546136
+    27697.43330        0.13232460        0.00542211
+    27708.51227        0.13292504        0.00551058
+    27719.59568        0.12895879        0.00543372
+    27730.68351        0.14747624        0.00546050
+    27741.77579        0.13348498        0.00551326
+    27752.87250        0.13417252        0.00565899
+    27763.97365        0.13453142        0.00548445
+    27775.07924        0.14115485        0.00556690
+    27786.18927        0.13888244        0.00575041
+    27797.30374        0.13933870        0.00561581
+    27808.42266        0.13670616        0.00576885
+    27819.54603        0.13481790        0.00575204
+    27830.67385        0.13957008        0.00558936
+    27841.80612        0.13394893        0.00580019
+    27852.94284        0.13985934        0.00571399
+    27864.08402        0.14530720        0.00552273
+    27875.22965        0.13955334        0.00597565
+    27886.37975        0.16124088        0.00574416
+    27897.53430        0.15221547        0.00590684
+    27908.69331        0.16189387        0.00589609
+    27919.85679        0.15139032        0.00591171
+    27931.02473        0.16140443        0.00579996
+    27942.19714        0.15810621        0.00584536
+    27953.37402        0.14380080        0.00571228
+    27964.55537        0.14472458        0.00569467
+    27975.74119        0.13819422        0.00563534
+    27986.93149        0.14172385        0.00578924
+    27998.12626        0.13878375        0.00549296
+    28009.32551        0.12926398        0.00559544
+    28020.52924        0.14130489        0.00564178
+    28031.73745        0.13477980        0.00577356
+    28042.95015        0.13710860        0.00557921
+    28054.16733        0.12573080        0.00566792
+    28065.38900        0.12937121        0.00576364
+    28076.61515        0.13199477        0.00560074
+    28087.84580        0.12932074        0.00548209
+    28099.08094        0.14151048        0.00564618
+    28110.32057        0.13455963        0.00547351
+    28121.56470        0.11948370        0.00561515
+    28132.81332        0.13718621        0.00559599
+    28144.06645        0.12568380        0.00553312
+    28155.32407        0.13554583        0.00572712
+    28166.58620        0.12797285        0.00578787
+    28177.85284        0.13348158        0.00571922
+    28189.12398        0.13256056        0.00566861
+    28200.39963        0.14762825        0.00562899
+    28211.67979        0.13240269        0.00558110
+    28222.96446        0.13426469        0.00574988
+    28234.25365        0.13655081        0.00570869
+    28245.54735        0.14280818        0.00571746
+    28256.84557        0.16358662        0.00593322
+    28268.14831        0.18785961        0.00618506
+    28279.45556        0.22772795        0.00662398
+    28290.76735        0.30268812        0.00734735
+    28302.08365        0.36668498        0.00762118
+    28313.40449        0.38486591        0.00793848
+    28324.72985        0.36001147        0.00781335
+    28336.05974        0.30557578        0.00716025
+    28347.39417        0.24484488        0.00678715
+    28358.73312        0.20327021        0.00646672
+    28370.07662        0.18120459        0.00615813
+    28381.42465        0.16382478        0.00602022
+    28392.77722        0.16178657        0.00603129
+    28404.13433        0.14195783        0.00613720
+    28415.49598        0.15042933        0.00582583
+    28426.86218        0.14060231        0.00600319
+    28438.23292        0.13516481        0.00588020
+    28449.60822        0.14080767        0.00591301
+    28460.98806        0.14210440        0.00594648
+    28472.37246        0.13618008        0.00590668
+    28483.76141        0.13816623        0.00596969
+    28495.15491        0.14453504        0.00583787
+    28506.55297        0.13469473        0.00603136
+    28517.95559        0.12833997        0.00604403
+    28529.36278        0.13191068        0.00582485
+    28540.77452        0.14074787        0.00605058
+    28552.19083        0.13119966        0.00595069
+    28563.61171        0.12578953        0.00600781
+    28575.03715        0.12649837        0.00596581
+    28586.46717        0.13645568        0.00574599
+    28597.90175        0.13544361        0.00599286
+    28609.34091        0.14115191        0.00593074
+    28620.78465        0.13867958        0.00613478
+    28632.23296        0.13620408        0.00597807
+    28643.68586        0.13298452        0.00586869
+    28655.14333        0.13946838        0.00587208
+    28666.60539        0.13887634        0.00611123
+    28678.07203        0.13792700        0.00574742
+    28689.54326        0.13220178        0.00610600
+    28701.01908        0.12499013        0.00590733
+    28712.49948        0.14213287        0.00572661
+    28723.98448        0.14374048        0.00598597
+    28735.47408        0.13466513        0.00609210
+    28746.96827        0.12855392        0.00610909
+    28758.46706        0.13858118        0.00601611
+    28769.97044        0.13481306        0.00610622
+    28781.47843        0.13796781        0.00620682
+    28792.99102        0.13518887        0.00595533
+    28804.50822        0.12902178        0.00591016
+    28816.03002        0.12836587        0.00606079
+    28827.55643        0.12929620        0.00600468
+    28839.08746        0.13131192        0.00603432
+    28850.62309        0.13630108        0.00613208
+    28862.16334        0.14486514        0.00614338
+    28873.70821        0.14170675        0.00636197
+    28885.25769        0.13193758        0.00621049
+    28896.81179        0.13741884        0.00615238
+    28908.37052        0.13719909        0.00631827
+    28919.93386        0.12689298        0.00640386
+    28931.50184        0.13864168        0.00612702
+    28943.07444        0.13461388        0.00630482
+    28954.65167        0.14092607        0.00622925
+    28966.23353        0.13730817        0.00621160
+    28977.82002        0.13564467        0.00603525
+    28989.41115        0.14840617        0.00619083
+    29001.00692        0.14348296        0.00628494
+    29012.60732        0.12890782        0.00631619
+    29024.21236        0.14358813        0.00619839
+    29035.82205        0.12850835        0.00614793
+    29047.43637        0.12603225        0.00608909
+    29059.05535        0.13586330        0.00627751
+    29070.67897        0.13081183        0.00620539
+    29082.30724        0.14168303        0.00614598
+    29093.94017        0.13735934        0.00606610
+    29105.57774        0.12831258        0.00619866
+    29117.21997        0.12769360        0.00619864
+    29128.86686        0.13808647        0.00613254
+    29140.51841        0.14105843        0.00632713
+    29152.17462        0.12802347        0.00636441
+    29163.83548        0.13887506        0.00627815
+    29175.50102        0.14094242        0.00628021
+    29187.17122        0.13184597        0.00635953
+    29198.84609        0.13681460        0.00626151
+    29210.52563        0.14220178        0.00623229
+    29222.20984        0.13477330        0.00635615
+    29233.89872        0.13898485        0.00619494
+    29245.59228        0.12715412        0.00644297
+    29257.29052        0.13111746        0.00615967
+    29268.99343        0.13243978        0.00627246
+    29280.70103        0.13567189        0.00612286
+    29292.41331        0.13905910        0.00627162
+    29304.13028        0.14315108        0.00646354
+    29315.85193        0.14419773        0.00632039
+    29327.57827        0.14892702        0.00615898
+    29339.30930        0.13651943        0.00613548
+    29351.04502        0.13400915        0.00655076
+    29362.78544        0.14770817        0.00618183
+    29374.53056        0.13575660        0.00647155
+    29386.28037        0.13946134        0.00631520
+    29398.03488        0.14812429        0.00635724
+    29409.79409        0.14320491        0.00630765
+    29421.55801        0.14515873        0.00645133
+    29433.32664        0.14384693        0.00633394
+    29445.09997        0.14753363        0.00645602
+    29456.87801        0.14857709        0.00630976
+    29468.66076        0.15207134        0.00666552
+    29480.44822        0.15602422        0.00650176
+    29492.24040        0.16233269        0.00655764
+    29504.03730        0.15313943        0.00651778
+    29515.83891        0.16058436        0.00646706
+    29527.64525        0.15857760        0.00677480
+    29539.45631        0.17119447        0.00658501
+    29551.27209        0.17091498        0.00689318
+    29563.09260        0.18277592        0.00673700
+    29574.91783        0.18431599        0.00694587
+    29586.74780        0.21806943        0.00711783
+    29598.58250        0.25667338        0.00752979
+    29610.42193        0.35283974        0.00839377
+    29622.26610        0.51205717        0.00976294
+    29634.11501        0.92924777        0.01210554
+    29645.96865        1.66544832        0.01571733
+    29657.82704        2.98439675        0.02074784
+    29669.69017        4.82388130        0.02619733
+    29681.55805        6.70288242        0.03069107
+    29693.43067        7.68368722        0.03286478
+    29705.30804        7.11273281        0.03164267
+    29717.19017        5.46695138        0.02789160
+    29729.07704        3.69134509        0.02299121
+    29740.96867        2.28979823        0.01831381
+    29752.86506        1.39329888        0.01460906
+    29764.76621        0.85796165        0.01173219
+    29776.67211        0.55823345        0.00996810
+    29788.58278        0.39816689        0.00879318
+    29800.49822        0.32090062        0.00805716
+    29812.41842        0.27908114        0.00775814
+    29824.34338        0.23736775        0.00743644
+    29836.27312        0.21566280        0.00736270
+    29848.20763        0.19843722        0.00725858
+    29860.14691        0.21197134        0.00721645
+    29872.09097        0.18293009        0.00719206
+    29884.03981        0.18613199        0.00673470
+    29895.99342        0.18295434        0.00667503
+    29907.95182        0.18154279        0.00681425
+    29919.91500        0.17089828        0.00653475
+    29931.88297        0.17076551        0.00672898
+    29943.85572        0.14599342        0.00673412
+    29955.83326        0.15723781        0.00673175
+    29967.81560        0.16072274        0.00659770
+    29979.80272        0.14933163        0.00657102
+    29991.79464        0.14223545        0.00669359
+    30003.79136        0.14974544        0.00670529
+    30015.79288        0.15432568        0.00651638
+    30027.79920        0.14542650        0.00642219
+    30039.81032        0.15928178        0.00638084
+    30051.82624        0.14476001        0.00625134
+    30063.84697        0.14010268        0.00639372
+    30075.87251        0.14019863        0.00647663
+    30087.90286        0.14663613        0.00650559
+    30099.93802        0.14078279        0.00644499
+    30111.97799        0.13857262        0.00640930
+    30124.02279        0.14768478        0.00648065
+    30136.07239        0.14782876        0.00644314
+    30148.12682        0.13967007        0.00639793
+    30160.18607        0.14890589        0.00640273
+    30172.25015        0.14589144        0.00655996
+    30184.31905        0.15513119        0.00647067
+    30196.39278        0.14272553        0.00642029
+    30208.47133        0.15118280        0.00642968
+    30220.55472        0.14508818        0.00644648
+    30232.64294        0.15113449        0.00644373
+    30244.73600        0.13721391        0.00653908
+    30256.83390        0.14297765        0.00662639
+    30268.93663        0.13765012        0.00631410
+    30281.04420        0.13589460        0.00636464
+    30293.15662        0.14994118        0.00642063
+    30305.27388        0.14008178        0.00654606
+    30317.39599        0.14252367        0.00639729
+    30329.52295        0.13601257        0.00634181
+    30341.65476        0.14031137        0.00638952
+    30353.79142        0.13615914        0.00626285
+    30365.93294        0.13413371        0.00650358
+    30378.07931        0.12622798        0.00639415
+    30390.23054        0.14396496        0.00636787
+    30402.38664        0.13516761        0.00658896
+    30414.54759        0.14169859        0.00645891
+    30426.71341        0.14770807        0.00622206
+    30438.88410        0.13823648        0.00644285
+    30451.05965        0.13504793        0.00648135
+    30463.24007        0.13079075        0.00638516
+    30475.42537        0.15169164        0.00628230
+    30487.61554        0.11405275        0.00681215
+    30499.81059        0.13589605        0.00648339
+    30512.01051        0.14530234        0.00624094
+    30524.21531        0.14476877        0.00616836
+    30536.42500        0.14960394        0.00641295
+    30548.63957        0.14053633        0.00647468
+    30560.85903        0.13873797        0.00658653
+    30573.08337        0.14801390        0.00645743
+    30585.31260        0.12806579        0.00624484
+    30597.54673        0.13768676        0.00650092
+    30609.78575        0.14030807        0.00643865
+    30622.02966        0.13213202        0.00656963
+    30634.27847        0.14546616        0.00655343
+    30646.53218        0.14073969        0.00663732
+    30658.79080        0.12655693        0.00649364
+    30671.05431        0.13919360        0.00662498
+    30683.32274        0.14247200        0.00661300
+    30695.59606        0.12312630        0.00655547
+    30707.87430        0.14094642        0.00667159
+    30720.15745        0.13615899        0.00668629
+    30732.44552        0.12982854        0.00679703
+    30744.73849        0.14535602        0.00659007
+    30757.03639        0.13556006        0.00676493
+    30769.33920        0.14011484        0.00682259
+    30781.64694        0.14357649        0.00646518
+    30793.95960        0.14129982        0.00653718
+    30806.27718        0.15264329        0.00652315
+    30818.59969        0.12914523        0.00655288
+    30830.92713        0.13564084        0.00691983
+    30843.25950        0.15128900        0.00662095
+    30855.59681        0.13669138        0.00664587
+    30867.93905        0.13933185        0.00674124
+    30880.28622        0.13898585        0.00689001
+    30892.63834        0.14886451        0.00662497
+    30904.99539        0.14157713        0.00661186
+    30917.35739        0.14502965        0.00673190
+    30929.72433        0.15966299        0.00669186
+    30942.09622        0.14596911        0.00687549
+    30954.47306        0.14824973        0.00683524
+    30966.85485        0.14799789        0.00689962
+    30979.24159        0.15224286        0.00685118
+    30991.63329        0.16425128        0.00700273
+    31004.02994        0.15498227        0.00689832
+    31016.43155        0.17039863        0.00689583
+    31028.83813        0.16187492        0.00722105
+    31041.24966        0.16132247        0.00716825
+    31053.66616        0.15858222        0.00703339
+    31066.08763        0.18452976        0.00705422
+    31078.51406        0.16896440        0.00710450
+    31090.94547        0.17624880        0.00702950
+    31103.38185        0.18255552        0.00740909
+    31115.82320        0.18874020        0.00750980
+    31128.26953        0.20437313        0.00761993
+    31140.72084        0.22299805        0.00750804
+    31153.17712        0.21004298        0.00772255
+    31165.63840        0.25233888        0.00789704
+    31178.10465        0.28008756        0.00810252
+    31190.57589        0.35403034        0.00894708
+    31203.05212        0.45175034        0.00978589
+    31215.53334        0.69936967        0.01147234
+    31228.01956        1.20181559        0.01447695
+    31240.51077        2.18690389        0.01900251
+    31253.00697        4.02357867        0.02536856
+    31265.50817        6.97259264        0.03315490
+    31278.01438       10.57842846        0.04065678
+    31290.52558       13.69781799        0.04623802
+    31303.04179       14.35593191        0.04742173
+    31315.56301       12.61219809        0.04448252
+    31328.08923        9.51101868        0.03869395
+    31340.62047        6.33004998        0.03173726
+    31353.15672        3.82224523        0.02506695
+    31365.69798        2.29690755        0.01970887
+    31378.24426        1.42899320        0.01579944
+    31390.79556        0.91124989        0.01309184
+    31403.35188        0.62821363        0.01097106
+    31415.91322        0.44886515        0.01022356
+    31428.47958        0.38642153        0.00922543
+    31441.05097        0.32604046        0.00887422
+    31453.62739        0.28103149        0.00844756
+    31466.20884        0.26194397        0.00805065
+    31478.79533        0.23435172        0.00798886
+    31491.38685        0.21296909        0.00794524
+    31503.98340        0.20103231        0.00763923
+    31516.58499        0.20549175        0.00776958
+    31529.19163        0.20763805        0.00744779
+    31541.80330        0.17841531        0.00764562
+    31554.42003        0.18569568        0.00749894
+    31567.04179        0.18566029        0.00764853
+    31579.66861        0.17166679        0.00722136
+    31592.30048        0.17609098        0.00745788
+    31604.93740        0.16788846        0.00760318
+    31617.57937        0.17585692        0.00733140
+    31630.22641        0.17883912        0.00761621
+    31642.87850        0.16409502        0.00756677
+    31655.53565        0.17179717        0.00728705
+    31668.19786        0.15413707        0.00750025
+    31680.86514        0.15041713        0.00743912
+    31693.53749        0.14940618        0.00735676
+    31706.21490        0.15450781        0.00723916
+    31718.89739        0.14446577        0.00717010
+    31731.58495        0.15887244        0.00739352
+    31744.27758        0.15639785        0.00742642
+    31756.97529        0.14821046        0.00741258
+    31769.67808        0.14550425        0.00755958
+    31782.38595        0.14338326        0.00737643
+    31795.09891        0.15000613        0.00728702
+    31807.81695        0.13117018        0.00741031
+    31820.54007        0.13517313        0.00734279
+    31833.26829        0.14605573        0.00715886
+    31846.00160        0.13759508        0.00719275
+    31858.74000        0.15243048        0.00724683
+    31871.48349        0.14487055        0.00696683
+    31884.23209        0.13057978        0.00741665
+    31896.98578        0.13295503        0.00720467
+    31909.74457        0.13646969        0.00716331
+    31922.50847        0.13623031        0.00740011
+    31935.27748        0.14898096        0.00758598
+    31948.05159        0.13840761        0.00721016
+    31960.83081        0.13323479        0.00737450
+    31973.61514        0.12932852        0.00732101
+    31986.40459        0.13279924        0.00729833
+    31999.19915        0.13961139        0.00738619
+    32011.99883        0.14079222        0.00739152
+    32024.80363        0.13057388        0.00742827
+    32037.61355        0.13638214        0.00732449
+    32050.42859        0.12873628        0.00731907
+    32063.24876        0.13420928        0.00711450
+    32076.07406        0.12718838        0.00737694
+    32088.90449        0.14364595        0.00739462
+    32101.74006        0.11074050        0.00744635
+    32114.58075        0.12815935        0.00770874
+    32127.42658        0.13928836        0.00733767
+    32140.27755        0.13197155        0.00735581
+    32153.13367        0.14024385        0.00712210
+    32165.99492        0.12876725        0.00741469
+    32178.86132        0.13292331        0.00745549
+    32191.73286        0.12488301        0.00742921
+    32204.60955        0.13662416        0.00744622
+    32217.49140        0.13644153        0.00700815
+    32230.37840        0.13370072        0.00739705
+    32243.27055        0.13469889        0.00738221
+    32256.16785        0.14284902        0.00715946
+    32269.07032        0.13011665        0.00761840
+    32281.97795        0.13316428        0.00747610
+    32294.89074        0.13361744        0.00735722
+    32307.80870        0.12817565        0.00747899
+    32320.73182        0.13907980        0.00734659
+    32333.66011        0.13964065        0.00744291
+    32346.59358        0.12199017        0.00753730
+    32359.53222        0.13610103        0.00738272
+    32372.47603        0.12985820        0.00729766
+    32385.42502        0.13363636        0.00753347
+    32398.37919        0.13912901        0.00743187
+    32411.33854        0.14078107        0.00740238
+    32424.30308        0.13896038        0.00764958
+    32437.27280        0.11980325        0.00749236
+    32450.24771        0.14262845        0.00735451
+    32463.22781        0.13316762        0.00755424
+    32476.21310        0.13597147        0.00755830
+    32489.20358        0.13427428        0.00746714
+    32502.19926        0.12877945        0.00753288
+    32515.20014        0.12951191        0.00759229
+    32528.20622        0.12668493        0.00772921
+    32541.21751        0.14083024        0.00758531
+    32554.23399        0.14327415        0.00758306
+    32567.25569        0.13353519        0.00803445
+    32580.28259        0.14131337        0.00757671
+    32593.31470        0.14777788        0.00776425
+    32606.35203        0.13913584        0.00756682
+    32619.39457        0.13386043        0.00742631
+    32632.44233        0.14088584        0.00762488
+    32645.49530        0.12863656        0.00756719
+    32658.55350        0.11883735        0.00780768
+    32671.61692        0.12917498        0.00759023
+    32684.68557        0.13090031        0.00778504
+    32697.75944        0.13287719        0.00739724
+    32710.83855        0.12979192        0.00789130
+    32723.92288        0.12977108        0.00779760
+    32737.01245        0.12656454        0.00780935
+    32750.10726        0.12399015        0.00784954
+    32763.20730        0.12596493        0.00761047
+    32776.31258        0.14109999        0.00748464
+    32789.42311        0.12402261        0.00758376
+    32802.53888        0.12062077        0.00759455
+    32815.65989        0.13122849        0.00779844
+    32828.78616        0.12763811        0.00795437
+    32841.91767        0.11676558        0.00789897
+    32855.05444        0.12321367        0.00813183
+    32868.19646        0.12641570        0.00776391
+    32881.34374        0.13927651        0.00743083
+    32894.49628        0.13725822        0.00768246
+    32907.65407        0.13896891        0.00769328
+    32920.81714        0.12237014        0.00769645
+    32933.98546        0.12578605        0.00798812
+    32947.15906        0.12493070        0.00779635
+    32960.33792        0.14898964        0.00762076
+    32973.52206        0.14853605        0.00800035
+    32986.71146        0.14668168        0.00777175
+    32999.90615        0.14272596        0.00799878
+    33013.10611        0.13361463        0.00776737
+    33026.31135        0.13006357        0.00791368
+    33039.52188        0.12498375        0.00784119
+    33052.73769        0.12645817        0.00778160
+    33065.95878        0.13504576        0.00809875
+    33079.18517        0.12318914        0.00792152
+    33092.41684        0.11868623        0.00803355
+    33105.65381        0.11108685        0.00828161
+    33118.89607        0.12253896        0.00769510
+    33132.14363        0.11783672        0.00803480
+    33145.39648        0.13778771        0.00786258
+    33158.65464        0.12120633        0.00793980
+    33171.91810        0.12336284        0.00839793
+    33185.18687        0.12404695        0.00801789
+    33198.46095        0.13522060        0.00779857
+    33211.74033        0.13352422        0.00819796
+    33225.02503        0.12291570        0.00784652
+    33238.31504        0.13708315        0.00810086
+    33251.61036        0.12353591        0.00784647
+    33264.91101        0.13063662        0.00798973
+    33278.21697        0.11624882        0.00811665
+    33291.52826        0.12342223        0.00827865
+    33304.84487        0.13726660        0.00804476
+    33318.16681        0.11892618        0.00837073
+    33331.49407        0.12831008        0.00772866
+    33344.82667        0.13177812        0.00799172
+    33358.16460        0.11794978        0.00774855
+    33371.50787        0.13826416        0.00815161
+    33384.85647        0.13194938        0.00803117
+    33398.21041        0.12622799        0.00819609
+    33411.56970        0.12047856        0.00796571
+    33424.93433        0.11372873        0.00839340
+    33438.30430        0.12318925        0.00810183
+    33451.67962        0.13749309        0.00802736
+    33465.06029        0.12436625        0.00795980
+    33478.44632        0.13242895        0.00820491
+    33491.83770        0.13452257        0.00766169
+    33505.23443        0.13544760        0.00803895
+    33518.63652        0.11961482        0.00810155
+    33532.04398        0.11181403        0.00819301
+    33545.45680        0.12617201        0.00802196
+    33558.87498        0.10302212        0.00822493
+    33572.29853        0.12554166        0.00789425
+    33585.72745        0.13812524        0.00783747
+    33599.16174        0.11917018        0.00797662
+    33612.60140        0.12678712        0.00823239
+    33626.04645        0.14244007        0.00778741
+    33639.49686        0.12554662        0.00830025
+    33652.95266        0.12533585        0.00775114
+    33666.41384        0.12029617        0.00811057
+    33679.88041        0.11672677        0.00826869
+    33693.35236        0.10656290        0.00785669
+    33706.82970        0.12186885        0.00766375
+    33720.31243        0.12235032        0.00816412
+    33733.80056        0.11958586        0.00810335
+    33747.29408        0.12357162        0.00826376
+    33760.79300        0.13369418        0.00780571
+    33774.29731        0.12060569        0.00803902
+    33787.80703        0.12916623        0.00807458
+    33801.32216        0.12241016        0.00812786
+    33814.84268        0.13079271        0.00799959
+    33828.36862        0.12607130        0.00819375
+    33841.89997        0.14481373        0.00789317
+    33855.43673        0.11643534        0.00830102
+    33868.97890        0.12341600        0.00815876
+    33882.52650        0.14051872        0.00788389
+    33896.07951        0.13231371        0.00801453
+    33909.63794        0.12889738        0.00768563
+    33923.20179        0.13784952        0.00777783
+    33936.77107        0.12760352        0.00809511
+    33950.34578        0.13740396        0.00814799
+    33963.92592        0.12875250        0.00751371
+    33977.51149        0.11334228        0.00812809
+    33991.10250        0.13100084        0.00811756
+    34004.69894        0.11776005        0.00795294
+    34018.30082        0.11576465        0.00820627
+    34031.90814        0.13693530        0.00781934
+    34045.52090        0.13320298        0.00807777
+    34059.13911        0.13310852        0.00776960
+    34072.76276        0.13214827        0.00794639
+    34086.39187        0.13023549        0.00772957
+    34100.02643        0.13263992        0.00782998
+    34113.66644        0.12838413        0.00800776
+    34127.31190        0.11948184        0.00800753
+    34140.96283        0.12488699        0.00804538
+    34154.61921        0.13418252        0.00794516
+    34168.28106        0.13839439        0.00810342
+    34181.94837        0.13812775        0.00813469
+    34195.62115        0.14631726        0.00797369
+    34209.29940        0.14971848        0.00786644
+    34222.98312        0.13105500        0.00823610
+    34236.67231        0.12828994        0.00840975
+    34250.36698        0.12448302        0.00802301
+    34264.06713        0.13632108        0.00793469
+    34277.77276        0.12215521        0.00817865
+    34291.48387        0.12843194        0.00800498
+    34305.20046        0.12816814        0.00783906
+    34318.92254        0.13995227        0.00766238
+    34332.65011        0.11307210        0.00800942
+    34346.38317        0.11908622        0.00778950
+    34360.12172        0.12613874        0.00781054
+    34373.86577        0.11704261        0.00821517
+    34387.61532        0.12229070        0.00776634
+    34401.37036        0.14006268        0.00787835
+    34415.13091        0.13126927        0.00777094
+    34428.89696        0.11980843        0.00804117
+    34442.66852        0.11338226        0.00780584
+    34456.44559        0.12843410        0.00731419
+    34470.22817        0.13593077        0.00795804
+    34484.01626        0.13144010        0.00779025
+    34497.80987        0.12264027        0.00791292
+    34511.60899        0.14026888        0.00762747
+    34525.41363        0.12675299        0.00830374
+    34539.22380        0.11871032        0.00761353
+    34553.03949        0.11562504        0.00792623
+    34566.86070        0.14536068        0.00774740
+    34580.68745        0.13310075        0.00787187
+    34594.51972        0.13917084        0.00792550
+    34608.35753        0.13411959        0.00799957
+    34622.20087        0.12372543        0.00811922
+    34636.04975        0.11992490        0.00795837
+    34649.90417        0.11413614        0.00804391
+    34663.76414        0.11738111        0.00778439
+    34677.62964        0.12582704        0.00777285
+    34691.50069        0.12603409        0.00767897
+    34705.37729        0.11966438        0.00798827
+    34719.25944        0.12018237        0.00814823
+    34733.14715        0.11933374        0.00786389
+    34747.04041        0.12919893        0.00805135
+    34760.93922        0.12762931        0.00793897
+    34774.84360        0.11021941        0.00799205
+    34788.75354        0.12650928        0.00796530
+    34802.66904        0.11570670        0.00812129
+    34816.59011        0.11732762        0.00789221
+    34830.51674        0.12940799        0.00762714
+    34844.44895        0.12232029        0.00804066
+    34858.38673        0.12267185        0.00765507
+    34872.33008        0.11799432        0.00805225
+    34886.27901        0.12838001        0.00767994
+    34900.23353        0.11410219        0.00791324
+    34914.19362        0.11268931        0.00794080
+    34928.15930        0.12131950        0.00782124
+    34942.13056        0.12303560        0.00820094
+    34956.10741        0.12344426        0.00766425
+    34970.08986        0.11542702        0.00779538
+    34984.07789        0.13912028        0.00777372
+    34998.07152        0.12185458        0.00778760
+    35012.07075        0.11729507        0.00809504
+    35026.07558        0.12574729        0.00774858
+    35040.08601        0.12312017        0.00801505
+    35054.10204        0.12399865        0.00825014
+    35068.12369        0.13055581        0.00739099
+    35082.15093        0.11421548        0.00763566
+    35096.18379        0.12231371        0.00755402
+    35110.22227        0.11068388        0.00801384
+    35124.26636        0.13801246        0.00757436
+    35138.31606        0.11760350        0.00801621
+    35152.37139        0.11978093        0.00758212
+    35166.43234        0.13608080        0.00767804
+    35180.49891        0.11849348        0.00790119
+    35194.57111        0.12548498        0.00787717
+    35208.64894        0.11667093        0.00783890
+    35222.73240        0.11809241        0.00790669
+    35236.82149        0.12171947        0.00811492
+    35250.91622        0.12869880        0.00786216
+    35265.01659        0.11080558        0.00801091
+    35279.12259        0.11557096        0.00805135
+    35293.23424        0.11686103        0.00818472
+    35307.35154        0.14126515        0.00766111
+    35321.47448        0.13535694        0.00763678
+    35335.60307        0.12197727        0.00777960
+    35349.73731        0.11884281        0.00823097
+    35363.87720        0.11534211        0.00780140
+    35378.02275        0.12164032        0.00821128
+    35392.17396        0.11567721        0.00784324
+    35406.33083        0.11572914        0.00810837
+    35420.49337        0.11928384        0.00759068
+    35434.66156        0.12278462        0.00774173
+    35448.83543        0.13631960        0.00794708
+    35463.01496        0.12000076        0.00781787
+    35477.20017        0.11540729        0.00791087
+    35491.39105        0.12270197        0.00819858
+    35505.58760        0.13075771        0.00773827
+    35519.78984        0.12687386        0.00798637
+    35533.99775        0.12683643        0.00770255
+    35548.21135        0.13155996        0.00808604
+    35562.43064        0.11985591        0.00804180
+    35576.65561        0.12566694        0.00805214
+    35590.88627        0.12254749        0.00818742
+    35605.12263        0.12262172        0.00817340
+    35619.36468        0.13338759        0.00778612
+    35633.61242        0.11618261        0.00810992
+    35647.86587        0.11823534        0.00821611
+    35662.12501        0.12294714        0.00794682
+    35676.38986        0.11997482        0.00813639
+    35690.66042        0.11077757        0.00800348
+    35704.93668        0.12709388        0.00795147
+    35719.21866        0.12336475        0.00815654
+    35733.50635        0.11586603        0.00835816
+    35747.79975        0.13180571        0.00788614
+    35762.09887        0.11517432        0.00827048
+    35776.40371        0.13557472        0.00834134
+    35790.71427        0.11665419        0.00806086
+    35805.03056        0.12602673        0.00791487
+    35819.35257        0.11869431        0.00795235
+    35833.68031        0.11603540        0.00789948
+    35848.01378        0.13441513        0.00786895
+    35862.35299        0.12960942        0.00788926
+    35876.69793        0.09512229        0.00837412
+    35891.04861        0.10966531        0.00814919
+    35905.40503        0.12036214        0.00801887
+    35919.76719        0.10505403        0.00845002
+    35934.13509        0.13070462        0.00804154
+    35948.50875        0.12197830        0.00828724
+    35962.88815        0.12823464        0.00820015
+    35977.27331        0.11492888        0.00840957
+    35991.66422        0.12506965        0.00809690
+    36006.06088        0.11285304        0.00791645
+    36020.46331        0.10129912        0.00813151
+    36034.87149        0.11683345        0.00821252
+    36049.28544        0.10900348        0.00826973
+    36063.70515        0.12595481        0.00821685
+    36078.13064        0.13013193        0.00840221
+    36092.56189        0.11253525        0.00845988
+    36106.99891        0.14251875        0.00796295
+    36121.44171        0.13084682        0.00828112
+    36135.89029        0.11311234        0.00861176
+    36150.34465        0.12130336        0.00847498
+    36164.80478        0.11210375        0.00826412
+    36179.27071        0.13842207        0.00815032
+    36193.74241        0.11292289        0.00808253
+    36208.21991        0.11210826        0.00805308
+    36222.70320        0.10970504        0.00829017
+    36237.19228        0.11542790        0.00837246
+    36251.68716        0.12652628        0.00808382
+    36266.18783        0.12652416        0.00848054
+    36280.69431        0.12707538        0.00823876
+    36295.20659        0.12447517        0.00797261
+    36309.72467        0.11817381        0.00877646
+    36324.24856        0.09612404        0.00835464
+    36338.77826        0.10997285        0.00825556
+    36353.31377        0.12779055        0.00815362
+    36367.85509        0.11689055        0.00828209
+    36382.40224        0.10795780        0.00838270
+    36396.95520        0.13982551        0.00835926
+    36411.51398        0.13670580        0.00800269
+    36426.07858        0.10990379        0.00863664
+    36440.64902        0.12507203        0.00870841
+    36455.22528        0.12944042        0.00803450
+    36469.80737        0.11714132        0.00833777
+    36484.39529        0.10646067        0.00817781
+    36498.98905        0.12089897        0.00863973
+    36513.58864        0.13201053        0.00821123
+    36528.19408        0.12321148        0.00837354
+    36542.80536        0.12147711        0.00825215
+    36557.42248        0.12111913        0.00855177
+    36572.04545        0.12265463        0.00820472
+    36586.67426        0.11528700        0.00830731
+    36601.30893        0.12488197        0.00841659
+    36615.94946        0.12680542        0.00797956
+    36630.59584        0.12461865        0.00798581
+    36645.24808        0.11448747        0.00876103
+    36659.90618        0.12451390        0.00860760
+    36674.57014        0.12439404        0.00866717
+    36689.23997        0.10868060        0.00847017
+    36703.91566        0.12938198        0.00836794
+    36718.59723        0.13612393        0.00843657
+    36733.28467        0.12832493        0.00863925
+    36747.97798        0.11350642        0.00866857
+    36762.67717        0.13403420        0.00875227
+    36777.38224        0.12154817        0.00865119
+    36792.09320        0.12251948        0.00839652
+    36806.81003        0.11540081        0.00869242
+    36821.53276        0.12295584        0.00827458
+    36836.26137        0.12138714        0.00875663
+    36850.99587        0.10944362        0.00877132
+    36865.73627        0.11894337        0.00854876
+    36880.48257        0.12377567        0.00834095
+    36895.23476        0.12588607        0.00862724
+    36909.99285        0.09714379        0.00907116
+    36924.75685        0.13031885        0.00872677
+    36939.52675        0.11548735        0.00867711
+    36954.30257        0.12853861        0.00818001
+    36969.08429        0.11870783        0.00848204
+    36983.87192        0.12260183        0.00865145
+    36998.66547        0.12093913        0.00838163
+    37013.46494        0.12276824        0.00872067
+    37028.27032        0.12260440        0.00877946
+    37043.08163        0.12046229        0.00836325
+    37057.89886        0.12511732        0.00863057
+    37072.72202        0.13214660        0.00881213
+    37087.55111        0.12385612        0.00845619
+    37102.38613        0.10847270        0.00882097
+    37117.22709        0.10114640        0.00870477
+    37132.07398        0.12887568        0.00828330
+    37146.92681        0.11263941        0.00867541
+    37161.78558        0.11425793        0.00887189
+    37176.65029        0.12110075        0.00857652
+    37191.52095        0.11869720        0.00819933
+    37206.39756        0.12331076        0.00865004
+    37221.28012        0.12213746        0.00886790
+    37236.16863        0.11053139        0.00846401
+    37251.06310        0.13157742        0.00864063
+    37265.96352        0.11650287        0.00867657
+    37280.86991        0.11733704        0.00903368
+    37295.78226        0.11451447        0.00875301
+    37310.70057        0.10779169        0.00884393
+    37325.62485        0.12511321        0.00865341
+    37340.55510        0.12362570        0.00849558
+    37355.49132        0.12046633        0.00872595
+    37370.43352        0.11233101        0.00844838
+    37385.38169        0.11560115        0.00894060
+    37400.33584        0.13437147        0.00894156
+    37415.29598        0.11791053        0.00921791
+    37430.26210        0.13280285        0.00891426
+    37445.23420        0.11605428        0.00884790
+    37460.21229        0.11851574        0.00865670
+    37475.19638        0.11174210        0.00890042
+    37490.18646        0.11530561        0.00884221
+    37505.18253        0.12431026        0.00870775
+    37520.18461        0.12830675        0.00856112
+    37535.19268        0.11536071        0.00881484
+    37550.20676        0.11691810        0.00869556
+    37565.22684        0.12781013        0.00864159
+    37580.25293        0.12612858        0.00886752
+    37595.28503        0.12242418        0.00867441
+    37610.32315        0.11615572        0.00904547
+    37625.36727        0.12399751        0.00852593
+    37640.41742        0.11535340        0.00881195
+    37655.47359        0.12170702        0.00890516
+    37670.53578        0.11748261        0.00870312
+    37685.60399        0.11669513        0.00879089
+    37700.67823        0.11349785        0.00884531
+    37715.75851        0.12601020        0.00884042
+    37730.84481        0.11742677        0.00857380
+    37745.93715        0.11646901        0.00890602
+    37761.03552        0.11500380        0.00870868
+    37776.13994        0.12804199        0.00907472
+    37791.25039        0.11849822        0.00910336
+    37806.36689        0.13331935        0.00921718
+    37821.48944        0.12649179        0.00901397
+    37836.61803        0.11061595        0.00931593
+    37851.75268        0.11648897        0.00895338
+    37866.89338        0.11277335        0.00862934
+    37882.04014        0.13387738        0.00864818
+    37897.19296        0.13347051        0.00893078
+    37912.35183        0.12040609        0.00882115
+    37927.51677        0.14683279        0.00930674
+    37942.68778        0.12795920        0.00884841
+    37957.86486        0.13160601        0.00936263
+    37973.04800        0.12640211        0.00871808
+    37988.23722        0.12043564        0.00938495
+    38003.43252        0.11871431        0.00925296
+    38018.63389        0.12281379        0.00894966
+    38033.84134        0.11477193        0.00934276
+    38049.05488        0.13164912        0.00874309
+    38064.27450        0.12545363        0.00935492
+    38079.50021        0.10457818        0.00892867
+    38094.73201        0.11720237        0.00898716
+    38109.96990        0.12684491        0.00906725
+    38125.21389        0.14059613        0.00885410
+    38140.46398        0.12226144        0.00918331
+    38155.72016        0.13490835        0.00936444
+    38170.98245        0.14368438        0.00936971
+    38186.25084        0.13742547        0.00945160
+    38201.52534        0.16614494        0.00989499
+    38216.80595        0.21376088        0.01021116
+    38232.09268        0.28292781        0.01117111
+    38247.38551        0.40804218        0.01244054
+    38262.68447        0.59137737        0.01441158
+    38277.98954        0.94896420        0.01733750
+    38293.30074        1.31569121        0.01964613
+    38308.61806        1.70519633        0.02191386
+    38323.94151        1.87614126        0.02293086
+    38339.27108        1.87637501        0.02308656
+    38354.60679        1.71561308        0.02217162
+    38369.94863        1.41767387        0.02020143
+    38385.29661        1.06525789        0.01797619
+    38400.65073        0.76735741        0.01568198
+    38416.01099        0.51877148        0.01365704
+    38431.37740        0.35846208        0.01200395
+    38446.74995        0.26377576        0.01136458
+    38462.12865        0.22883675        0.01043907
+    38477.51350        0.17677720        0.00950821
+    38492.90450        0.17331885        0.00975224
+    38508.30167        0.14911231        0.00993820
+    38523.70499        0.14012104        0.00954866
+    38539.11447        0.14340391        0.00953787
+    38554.53011        0.10805155        0.00958276
+    38569.95193        0.12405605        0.00971056
+    38585.37991        0.12491272        0.00963660
+    38600.81406        0.12993828        0.00955358
+    38616.25438        0.13359981        0.00918617
+    38631.70089        0.13645334        0.00926844
+    38647.15357        0.13409776        0.00934445
+    38662.61243        0.11496869        0.00968030
+    38678.07747        0.12822313        0.00983429
+    38693.54870        0.11902992        0.00932917
+    38709.02612        0.13716622        0.00928912
+    38724.50973        0.11674562        0.00924750
+    38739.99954        0.13586768        0.00935483
+    38755.49554        0.11730645        0.00960544
+    38770.99774        0.12828799        0.00933269
+    38786.50613        0.12189711        0.00965244
+    38802.02074        0.11499322        0.00933298
+    38817.54155        0.10434616        0.00926047
+    38833.06856        0.12807774        0.00919341
+    38848.60179        0.13463219        0.00915758
+    38864.14123        0.11255106        0.00954108
+    38879.68689        0.11483722        0.00934646
+    38895.23876        0.12658699        0.00975560
+    38910.79686        0.11489337        0.00919645
+    38926.36118        0.12812194        0.00882776
+    38941.93172        0.12852684        0.00916950
+    38957.50849        0.11732632        0.00944185
+    38973.09150        0.12179504        0.00927372
+    38988.68073        0.12350664        0.00945064
+    39004.27620        0.11780062        0.00945265
+    39019.87792        0.11467913        0.00895418
+    39035.48587        0.13311244        0.00958928
+    39051.10006        0.11736413        0.00941521
+    39066.72050        0.12143138        0.00952101
+    39082.34719        0.12542196        0.00934270
+    39097.98013        0.10859451        0.00985365
+    39113.61932        0.10472735        0.00939358
+    39129.26477        0.10363977        0.00967470
+    39144.91647        0.11551592        0.00910103
+    39160.57444        0.11757737        0.01023219
+    39176.23867        0.13343953        0.00862940
+    39191.90917        0.12756789        0.00960262
+    39207.58593        0.12730032        0.00946625
+    39223.26896        0.13227802        0.00951237
+    39238.95827        0.11443511        0.00970053
+    39254.65385        0.11461518        0.00989077
+    39270.35572        0.12209551        0.00901952
+    39286.06386        0.13211042        0.00944168
+    39301.77828        0.12148310        0.00944493
+    39317.49900        0.12649859        0.00922906
+    39333.22599        0.11468456        0.00973274
+    39348.95929        0.11962977        0.00984839
+    39364.69887        0.10526120        0.00969152
+    39380.44475        0.12569367        0.00932927
+    39396.19693        0.12276726        0.00910161
+    39411.95541        0.12396044        0.00965649
+    39427.72019        0.08481425        0.00983747
+    39443.49128        0.12797431        0.00969276
+    39459.26867        0.12758107        0.00962033
+    39475.05238        0.13855391        0.00952485
+    39490.84240        0.12719047        0.00970174
+    39506.63874        0.10729009        0.01022173
+    39522.44139        0.11934902        0.00996765
+    39538.25037        0.11083739        0.00978060
+    39554.06567        0.11370490        0.00982712
+    39569.88730        0.08884094        0.01006398
+    39585.71525        0.11015442        0.00967617
+    39601.54954        0.11082869        0.00915362
+    39617.39016        0.11308935        0.01016536
+    39633.23711        0.11306152        0.00943019
+    39649.09041        0.08414255        0.00969443
+    39664.95004        0.13091992        0.00935764
+    39680.81602        0.12107300        0.00963835
+    39696.68835        0.12136553        0.00953398
+    39712.56703        0.10097921        0.00988360
+    39728.45205        0.12044635        0.00972182
+    39744.34343        0.11560055        0.01013880
+    39760.24117        0.12125954        0.00967151
+    39776.14527        0.11524366        0.00970509
+    39792.05572        0.14496934        0.00968976
+    39807.97255        0.10082041        0.00970164
+    39823.89574        0.10604266        0.00951838
+    39839.82529        0.12012615        0.00958108
+    39855.76122        0.12518334        0.00902924
+    39871.70353        0.09936591        0.00964305
+    39887.65221        0.12295919        0.00995776
+    39903.60727        0.09238891        0.01024321
+    39919.56871        0.11652848        0.01026226
+    39935.53654        0.12519749        0.00936584
+    39951.51076        0.11949438        0.00961060
+    39967.49136        0.12121981        0.00995868
+    39983.47836        0.11862737        0.01004936
+    39999.47175        0.11549860        0.00959028
+    40015.47154        0.10257721        0.00992308
+    40031.47773        0.11650706        0.01002257
+    40047.49032        0.11539676        0.00978653
+    40063.50931        0.12355575        0.00987999
+    40079.53472        0.10630248        0.00951525
+    40095.56653        0.10793981        0.00975383
+    40111.60476        0.12748691        0.00993521
+    40127.64940        0.11479775        0.00963832
+    40143.70046        0.11167712        0.00996296
+    40159.75794        0.11342254        0.00976002
+    40175.82184        0.11097918        0.01058716
+    40191.89217        0.12286295        0.00995821
+    40207.96893        0.10972288        0.00993244
+    40224.05212        0.11233790        0.00993873
+    40240.14174        0.10894061        0.00961029
+    40256.23779        0.12547748        0.00957889
+    40272.34029        0.09697635        0.01009168
+    40288.44922        0.11726533        0.00950564
+    40304.56460        0.11788851        0.00960443
+    40320.68643        0.13256147        0.00979134
+    40336.81470        0.11676502        0.01004802
+    40352.94943        0.10350138        0.01002012
+    40369.09061        0.12236310        0.00998347
+    40385.23825        0.10655837        0.00995900
+    40401.39234        0.10808617        0.01007000
+    40417.55290        0.11422881        0.00972035
+    40433.71992        0.11071801        0.00954831
+    40449.89341        0.11683329        0.00977625
+    40466.07337        0.13685260        0.00928453
+    40482.25979        0.11126162        0.01023987
+    40498.45270        0.12244761        0.01004994
+    40514.65208        0.12440597        0.01000562
+    40530.85794        0.11383040        0.00955908
+    40547.07028        0.11875935        0.01006049
+    40563.28911        0.12294607        0.00979916
+    40579.51443        0.14468295        0.01017243
+    40595.74623        0.10856255        0.01001313
+    40611.98453        0.10396470        0.01027865
+    40628.22933        0.08830405        0.01009627
+    40644.48062        0.11828535        0.00963210
+    40660.73841        0.09896476        0.01046777
+    40677.00270        0.12600239        0.00946039
+    40693.27351        0.11962542        0.00992754
+    40709.55082        0.11030941        0.00996195
+    40725.83464        0.10138252        0.01033237
+    40742.12497        0.11899478        0.01051444
+    40758.42182        0.11410965        0.01049283
+    40774.72519        0.12455644        0.01028834
+    40791.03508        0.11823817        0.00986723
+    40807.35149        0.10092669        0.01045083
+    40823.67443        0.11188241        0.00969966
+    40840.00390        0.11711165        0.00987646
+    40856.33990        0.10933829        0.01006686
+    40872.68244        0.10957845        0.01041455
+    40889.03151        0.09834202        0.01021925
+    40905.38713        0.11218747        0.01043553
+    40921.74928        0.13294016        0.00999958
+    40938.11798        0.11414364        0.00980880
+    40954.49323        0.10309693        0.01050710
+    40970.87502        0.10715786        0.01045558
+    40987.26337        0.10391302        0.00968394
+    41003.65828        0.12557600        0.01003300
+    41020.05974        0.12175241        0.01049918
+    41036.46777        0.11020735        0.01034041
+    41052.88235        0.10294711        0.01074694
+    41069.30351        0.11927060        0.01002344
+    41085.73123        0.11699117        0.01043158
+    41102.16552        0.10442591        0.01025338
+    41118.60639        0.10394265        0.01046988
+    41135.05383        0.10324461        0.01100790
+    41151.50785        0.11814438        0.01039887
+    41167.96845        0.09516416        0.01044981
+    41184.43564        0.12057272        0.01036350
+    41200.90942        0.08706375        0.01059998
+    41217.38978        0.12049311        0.01028811
+    41233.87674        0.11763987        0.01020665
+    41250.37029        0.11727558        0.01016241
+    41266.87043        0.10691745        0.00996231
+    41283.37718        0.11443243        0.01069336
+    41299.89053        0.10038381        0.01057758
+    41316.41049        0.11454637        0.01049249
+    41332.93705        0.11487301        0.01006156
+    41349.47023        0.12407103        0.01064350
+    41366.01002        0.10778955        0.01049265
+    41382.55642        0.12458279        0.01026850
+    41399.10944        0.13432752        0.00964857
+    41415.66909        0.10588249        0.01073266
+    41432.23536        0.12696246        0.01022481
+    41448.80825        0.12095076        0.00999826
+    41465.38777        0.12584115        0.01034435
+    41481.97393        0.11343347        0.01020054
+    41498.56672        0.11651220        0.01064223
+    41515.16614        0.09786796        0.01133242
+    41531.77221        0.11065126        0.01016096
+    41548.38492        0.12553562        0.01073546
+    41565.00427        0.11492191        0.01049349
+    41581.63027        0.11951958        0.00998514
+    41598.26293        0.12878301        0.01017611
+    41614.90223        0.13281160        0.01010462
+    41631.54819        0.15041350        0.01015337
+    41648.20081        0.12997675        0.01068085
+    41664.86009        0.11700251        0.01066292
+    41681.52604        0.12678111        0.01130516
+    41698.19865        0.12245966        0.01013303
+    41714.87793        0.12221119        0.01087386
+    41731.56388        0.10241959        0.01058691
+    41748.25650        0.13170429        0.01005902
+    41764.95581        0.11966030        0.01089064
+    41781.66179        0.13890121        0.01125221
+    41798.37445        0.13944582        0.01101661
+    41815.09380        0.13767855        0.01091189
+    41831.81984        0.15825376        0.01100258
+    41848.55257        0.20868469        0.01154984
+    41865.29199        0.25363394        0.01222965
+    41882.03811        0.34477500        0.01325605
+    41898.79092        0.51377904        0.01473988
+    41915.55044        0.71993785        0.01743468
+    41932.31666        1.04209977        0.02040398
+    41949.08958        1.40281425        0.02244511
+    41965.86922        1.68343732        0.02461325
+    41982.65557        1.81219211        0.02532077
+    41999.44863        1.85091787        0.02567250
+    42016.24841        1.65809613        0.02490691
+    42033.05491        1.40353052        0.02241749
+    42049.86813        1.06212908        0.01999922
+    42066.68808        0.79263927        0.01820297
+    42083.51475        0.55164715        0.01558542
+    42100.34816        0.40525849        0.01378507
+    42117.18830        0.30402410        0.01297041
+    42134.03517        0.24156485        0.01199256
+    42150.88879        0.18806313        0.01088607
+    42167.74914        0.18209143        0.01080136
+    42184.61624        0.15191191        0.01096436
+    42201.49009        0.14003593        0.01105013
+    42218.37069        0.13977632        0.01125808
+    42235.25803        0.13669864        0.01083418
+    42252.15214        0.12370327        0.01086037
+    42269.05300        0.13974401        0.01061917
+    42285.96062        0.14786010        0.01047571
+    42302.87500        0.12883947        0.01063307
+    42319.79615        0.12233116        0.01079940
+    42336.72407        0.13070039        0.01053044
+    42353.65876        0.12890463        0.01115440
+    42370.60023        0.12051425        0.01024424
+    42387.54847        0.12083816        0.01034447
+    42404.50348        0.12773762        0.01050024
+    42421.46529        0.09902753        0.01078403
+    42438.43387        0.10017888        0.01063340
+    42455.40925        0.12368238        0.01059574
+    42472.39141        0.11200971        0.01010501
+    42489.38037        0.11670660        0.01032779
+    42506.37612        0.11231415        0.01089962
+    42523.37867        0.10200479        0.01080369
+    42540.38802        0.11889658        0.01021067
+    42557.40418        0.10971005        0.01040547
+    42574.42714        0.11356327        0.01052435
+    42591.45691        0.11449959        0.01091273
+    42608.49349        0.11843315        0.01039669
+    42625.53689        0.11962724        0.01065980
+    42642.58710        0.13626983        0.00999177
+    42659.64414        0.12194223        0.01049328
+    42676.70800        0.11589641        0.00993050
+    42693.77868        0.11271289        0.01065790
+    42710.85619        0.10439791        0.01109203
+    42727.94053        0.11211387        0.01034694
+    42745.03171        0.12556123        0.01084923
+    42762.12972        0.12755521        0.01003518
+    42779.23457        0.10766664        0.01119858
+    42796.34627        0.11775176        0.01072364
+    42813.46481        0.11272557        0.01079938
+    42830.59019        0.10421625        0.01109803
+    42847.72243        0.11105172        0.01079872
+    42864.86152        0.10756124        0.01075750
+    42882.00746        0.10626976        0.01036464
+    42899.16026        0.11659184        0.01073183
+    42916.31993        0.10156933        0.01031240
+    42933.48646        0.09649151        0.01119794
+    42950.65985        0.11130682        0.01053996
+    42967.84011        0.11537448        0.01104380
+    42985.02725        0.11087673        0.01065375
+    43002.22126        0.10595100        0.01068553
+    43019.42215        0.11821048        0.01079218
+    43036.62992        0.12357138        0.01059643
+    43053.84457        0.10288673        0.01062545
+    43071.06611        0.11940106        0.01050443
+    43088.29454        0.11998799        0.01006677
+    43105.52985        0.13907334        0.01064278
+    43122.77206        0.12518716        0.01082910
+    43140.02117        0.12537792        0.01049633
+    43157.27718        0.12149833        0.01069520
+    43174.54009        0.11234565        0.01109986
+    43191.80991        0.10828148        0.01065481
+    43209.08663        0.10258663        0.01031703
+    43226.37027        0.10174919        0.01106257
+    43243.66082        0.10458894        0.01077147
+    43260.95828        0.12536887        0.01035151
+    43278.26266        0.12893480        0.01092075
+    43295.57397        0.11359457        0.01053309
+    43312.89220        0.10147334        0.01049676
+    43330.21735        0.10747181        0.01100064
+    43347.54944        0.08575287        0.01140054
+    43364.88846        0.11185215        0.01088502
+    43382.23442        0.10594595        0.01049301
+    43399.58731        0.11406089        0.01068297
+    43416.94715        0.10987576        0.01092687
+    43434.31392        0.09264147        0.01096464
+    43451.68765        0.11009936        0.01094911
+    43469.06833        0.10603677        0.01038039
+    43486.45595        0.11179524        0.01089712
+    43503.85053        0.12093895        0.01069800
+    43521.25208        0.11016299        0.01094608
+    43538.66058        0.12043674        0.01066222
+    43556.07604        0.11353647        0.01112567
+    43573.49847        0.11118602        0.01095106
+    43590.92787        0.13121410        0.01056106
+    43608.36424        0.12088278        0.01087627
+    43625.80759        0.13099563        0.01074069
+    43643.25791        0.11365011        0.01030534
+    43660.71521        0.11684863        0.01121018
+    43678.17950        0.13341270        0.01033542
+    43695.65077        0.09001946        0.01112213
+    43713.12903        0.11261716        0.01087454
+    43730.61428        0.10568736        0.01088063
+    43748.10653        0.10451689        0.01103180
+    43765.60577        0.11171610        0.01115933
+    43783.11201        0.10484254        0.01132122
+    43800.62526        0.09824441        0.01097110
+    43818.14551        0.09428708        0.01159097
+    43835.67277        0.08435095        0.01140246
+    43853.20704        0.10064245        0.01136465
+    43870.74832        0.10889861        0.01135512
+    43888.29662        0.09987627        0.01112398
+    43905.85194        0.10748983        0.01136635
+    43923.41428        0.12074171        0.01127992
+    43940.98364        0.10768629        0.01145791
+    43958.56004        0.11852077        0.01095940
+    43976.14346        0.10617112        0.01142122
+    43993.73392        0.10684219        0.01160850
+    44011.33141        0.09505336        0.01128533
+    44028.93594        0.12599497        0.01088127
+    44046.54752        0.10603410        0.01073393
+    44064.16614        0.11922280        0.01119405
+    44081.79180        0.09900758        0.01164328
+    44099.42452        0.11006444        0.01102608
+    44117.06429        0.11570197        0.01124740
+    44134.71112        0.11524201        0.01114614
+    44152.36500        0.11036317        0.01096850
+    44170.02595        0.08474723        0.01134580
+    44187.69396        0.12224584        0.01096782
+    44205.36903        0.11470919        0.01113940
+    44223.05118        0.11342054        0.01141057
+    44240.74040        0.12604762        0.01077883
+    44258.43670        0.10788909        0.01151240
+    44276.14007        0.11056085        0.01100456
+    44293.85053        0.11404369        0.01107485
+    44311.56807        0.10861533        0.01099523
+    44329.29270        0.09777712        0.01117174
+    44347.02441        0.11267918        0.01097052
+    44364.76322        0.11412851        0.01135226
+    44382.50913        0.11358875        0.01052946
+    44400.26213        0.12623558        0.01082260
+    44418.02224        0.11501542        0.01195975
+    44435.78945        0.10286051        0.01167088
+    44453.56376        0.11890454        0.01103089
+    44471.34519        0.10895493        0.01117029
+    44489.13373        0.10384367        0.01109778
+    44506.92938        0.11585181        0.01137190
+    44524.73215        0.09458712        0.01189233
+    44542.54204        0.10021468        0.01166090
+    44560.35906        0.12031842        0.01154585
+    44578.18320        0.13554097        0.01061807
+    44596.01448        0.12201900        0.01154296
+    44613.85288        0.10303154        0.01147487
+    44631.69842        0.11758350        0.01184068
+    44649.55110        0.10581481        0.01148821
+    44667.41092        0.10674836        0.01109834
+    44685.27789        0.11992649        0.01162993
+    44703.15200        0.12097998        0.01211691
+    44721.03326        0.12047173        0.01160629
+    44738.92167        0.11145499        0.01176360
+    44756.81724        0.12616870        0.01143196
+    44774.71997        0.12382401        0.01146659
+    44792.62986        0.11003343        0.01178564
+    44810.54691        0.11314330        0.01179426
+    44828.47113        0.11668608        0.01063630
+    44846.40252        0.11016624        0.01154038
+    44864.34108        0.11550493        0.01182509
+    44882.28681        0.12128483        0.01169994
+    44900.23973        0.13569365        0.01128872
+    44918.19982        0.10902263        0.01188992
+    44936.16710        0.11612451        0.01154297
+    44954.14157        0.12200973        0.01128745
+    44972.12323        0.12683580        0.01119754
+    44990.11208        0.12345411        0.01201852
+    45008.10812        0.09779953        0.01135827
+    45026.11137        0.10368823        0.01184713
+    45044.12181        0.12971377        0.01085276
+    45062.13946        0.11946441        0.01140069
+    45080.16431        0.10325948        0.01138845
+    45098.19638        0.11505678        0.01135175
+    45116.23566        0.10782671        0.01130238
+    45134.28215        0.11440561        0.01130088
+    45152.33587        0.11488623        0.01219689
+    45170.39680        0.11952244        0.01173303
+    45188.46496        0.11254950        0.01149848
+    45206.54034        0.07988562        0.01245061
+    45224.62296        0.10998851        0.01081347
+    45242.71281        0.12678226        0.01197281
+    45260.80990        0.11606757        0.01193394
+    45278.91422        0.12617182        0.01128671
+    45297.02579        0.10209782        0.01147270
+    45315.14460        0.10546875        0.01168139
+    45333.27065        0.11591880        0.01129141
+    45351.40396        0.10243470        0.01249180
+    45369.54452        0.10469751        0.01179736
+    45387.69234        0.10571861        0.01228458
+    45405.84742        0.11236577        0.01266524
+    45424.00976        0.11996012        0.01173573
+    45442.17936        0.11848239        0.01231550
+    45460.35623        0.09915711        0.01283152
+    45478.54037        0.09207889        0.01249153
+    45496.73179        0.11589053        0.01201298
+    45514.93048        0.09987202        0.01234695
+    45533.13646        0.10390960        0.01262651
+    45551.34971        0.11436965        0.01230964
+    45569.57025        0.10255009        0.01245542
+    45587.79808        0.09770691        0.01206559
+    45606.03320        0.11023224        0.01189922
+    45624.27561        0.10663951        0.01232544
+    45642.52532        0.12538386        0.01253073
+    45660.78233        0.10715122        0.01257108
+    45679.04664        0.12571504        0.01204154
+    45697.31826        0.10593031        0.01163767
+    45715.59719        0.12667082        0.01195681
+    45733.88343        0.11298915        0.01158738
+    45752.17698        0.11630599        0.01222342
+    45770.47785        0.12898593        0.01218834
+    45788.78604        0.13684543        0.01199733
+    45807.10156        0.12592164        0.01277775
+    45825.42440        0.10950674        0.01285246
+    45843.75457        0.10944573        0.01212375
+    45862.09207        0.14030290        0.01226504
+    45880.43691        0.09077617        0.01292888
+    45898.78908        0.10534705        0.01196114
+    45917.14860        0.11755822        0.01183787
+    45935.51546        0.10101852        0.01261966
+    45953.88966        0.11209867        0.01220256
+    45972.27122        0.09317799        0.01319428
+    45990.66013        0.12155324        0.01321631
+    46009.05639        0.11564968        0.01231182
+    46027.46001        0.11382494        0.01236567
+    46045.87100        0.11497118        0.01261167
+    46064.28935        0.09841236        0.01343198
+    46082.71506        0.11836498        0.01183680
+    46101.14815        0.11649856        0.01240219
+    46119.58861        0.08697855        0.01295889
+    46138.03644        0.10942540        0.01266511
+    46156.49166        0.10666407        0.01234742
+    46174.95426        0.11622761        0.01224340
+    46193.42424        0.10053802        0.01284489
+    46211.90161        0.10493722        0.01286850
+    46230.38637        0.10389380        0.01221872
+    46248.87852        0.11751359        0.01218536
+    46267.37807        0.12104078        0.01270461
+    46285.88502        0.11990464        0.01180576
+    46304.39938        0.11534644        0.01234509
+    46322.92114        0.12214379        0.01262982
+    46341.45031        0.09254005        0.01355133
+    46359.98689        0.10374904        0.01354871
+    46378.53088        0.09347808        0.01318512
+    46397.08229        0.11066278        0.01263444
+    46415.64113        0.13040808        0.01292366
+    46434.20738        0.13239807        0.01297373
+    46452.78107        0.11948534        0.01238981
+    46471.36218        0.11357388        0.01274913
+    46489.95072        0.13111983        0.01225123
+    46508.54670        0.09959658        0.01222686
+    46527.15012        0.12452560        0.01262263
+    46545.76098        0.11796848        0.01289855
+    46564.37929        0.09971096        0.01266874
+    46583.00504        0.11795963        0.01293942
+    46601.63824        0.15293326        0.01267984
+    46620.27890        0.12592676        0.01282466
+    46638.92701        0.13656880        0.01202501
+    46657.58258        0.13481293        0.01249277
+    46676.24561        0.12721986        0.01344347
+    46694.91611        0.15627488        0.01293108
+    46713.59408        0.15949268        0.01339082
+    46732.27951        0.16250213        0.01426316
+    46750.97243        0.21270405        0.01440853
+    46769.67281        0.26917013        0.01558524
+    46788.38068        0.32699075        0.01614891
+    46807.09604        0.43474938        0.01829853
+    46825.81887        0.66096577        0.02079295
+    46844.54920        0.95539836        0.02402032
+    46863.28702        1.48933182        0.02887397
+    46882.03234        2.09543156        0.03333857
+    46900.78515        2.60368101        0.03691738
+    46919.54546        3.02063784        0.03972903
+    46938.31328        3.26641252        0.04126170
+    46957.08861        3.22199429        0.04056419
+    46975.87144        3.02033709        0.03946062
+    46994.66179        2.47926013        0.03606158
+    47013.45966        1.98957110        0.03266902
+    47032.26504        1.46661903        0.02842779
+    47051.07795        1.06023545        0.02493524
+    47069.89838        0.75258546        0.02231464
+    47088.72634        0.48859454        0.01913872
+    47107.56183        0.37156752        0.01853465
+    47126.40485        0.33455651        0.01646260
+    47145.25541        0.26818044        0.01480608
+    47164.11352        0.18173243        0.01453163
+    47182.97916        0.19091160        0.01464011
+    47201.85235        0.15502040        0.01396972
+    47220.73309        0.18053061        0.01396203
+    47239.62139        0.14511755        0.01434067
+    47258.51723        0.14690215        0.01456123
+    47277.42064        0.11842364        0.01417589
+    47296.33161        0.14268075        0.01337767
+    47315.25014        0.15328794        0.01368618
+    47334.17624        0.14400717        0.01309687
+    47353.10991        0.14697443        0.01344288
+    47372.05116        0.12558697        0.01393654
+    47390.99998        0.12131499        0.01430510
+    47409.95638        0.14651016        0.01419041
+    47428.92036        0.12258221        0.01324293
+    47447.89193        0.13131254        0.01378408
+    47466.87109        0.10444775        0.01434788
+    47485.85783        0.10574141        0.01422320
+    47504.85218        0.09741852        0.01517635
+    47523.85412        0.12028652        0.01338688
+    47542.86366        0.10594913        0.01394355
+    47561.88080        0.10222008        0.01398345
+    47580.90556        0.12835785        0.01368896
+    47599.93792        0.10684157        0.01329603
+    47618.97789        0.13096246        0.01359529
+    47638.02549        0.09332192        0.01443087
+    47657.08070        0.13762024        0.01438357
+    47676.14353        0.14120362        0.01347956
+    47695.21399        0.12195908        0.01349995
+    47714.29207        0.12400248        0.01410782
+    47733.37779        0.11330379        0.01481240
+    47752.47114        0.13352811        0.01396383
+    47771.57213        0.10077000        0.01363794
+    47790.68076        0.10985343        0.01446704
+    47809.79703        0.11043817        0.01423022
+    47828.92095        0.13084049        0.01380645
+    47848.05252        0.09621797        0.01409834
+    47867.19174        0.08365674        0.01388155
+    47886.33861        0.13040826        0.01337704
+    47905.49315        0.11342908        0.01344950
+    47924.65535        0.11002937        0.01369274
+    47943.82521        0.09069339        0.01456148
+    47963.00274        0.10637254        0.01375988
+    47982.18794        0.07669767        0.01462624
+    48001.38081        0.10325275        0.01384151
+    48020.58137        0.10369115        0.01397081
+    48039.78960        0.10458945        0.01429918
+    48059.00552        0.10865141        0.01373040
+    48078.22912        0.09901765        0.01443935
+    48097.46041        0.10215444        0.01526156
+    48116.69939        0.10767313        0.01466303
+    48135.94607        0.10895652        0.01597761
+    48155.20045        0.10614647        0.01561621
+    48174.46253        0.11924035        0.01552645
+    48193.73232        0.14588399        0.01512717
+    48213.00981        0.14304675        0.01492042
+    48232.29501        0.14597973        0.01537749
+    48251.58793        0.14358018        0.01581871
+    48270.88857        0.16533456        0.01550141
+    48290.19692        0.17107623        0.01580678
+    48309.51300        0.16044180        0.01617716
+    48328.83681        0.16990389        0.01563361
+    48348.16834        0.14446777        0.01610511
+    48367.50761        0.15708905        0.01642004
+    48386.85461        0.12533450        0.01587957
+    48406.20935        0.14051632        0.01615355
+    48425.57184        0.13506865        0.01542473
+    48444.94207        0.14792590        0.01538680
+    48464.32004        0.14344840        0.01503020
+    48483.70577        0.14043704        0.01459422
+    48503.09925        0.11032634        0.01569283
+    48522.50049        0.10041554        0.01600129
+    48541.90949        0.12846573        0.01431644
+    48561.32626        0.11906851        0.01486667
+    48580.75079        0.13009059        0.01510236
+    48600.18309        0.09434844        0.01505315
+    48619.62316        0.11564749        0.01427440
+    48639.07101        0.08804428        0.01428320
+    48658.52664        0.13237118        0.01517935
+    48677.99005        0.10774599        0.01356017
+    48697.46124        0.10102607        0.01444231
+    48716.94023        0.09585642        0.01500853
+    48736.42701        0.13015427        0.01357262
+    48755.92158        0.07965167        0.01529622
+    48775.42394        0.11143493        0.01522447
+    48794.93411        0.09822271        0.01521837
+    48814.45209        0.11860223        0.01333675
+    48833.97787        0.10311369        0.01620146
+    48853.51146        0.10433770        0.01492123
+    48873.05286        0.08618848        0.01481388
+    48892.60209        0.12567425        0.01408306
+    48912.15913        0.11178569        0.01439827
+    48931.72399        0.12033132        0.01482939
+    48951.29668        0.10380219        0.01475140
+    48970.87720        0.12889582        0.01403628
+    48990.46555        0.10533527        0.01529085
+    49010.06174        0.12447875        0.01526180
+    49029.66576        0.09046157        0.01571998
+    49049.27763        0.10223871        0.01521774
+    49068.89734        0.13222876        0.01448595
+    49088.52490        0.10623300        0.01502271
+    49108.16031        0.13794520        0.01557235
+    49127.80357        0.13857236        0.01493540
+    49147.45469        0.11382246        0.01503701
+    49167.11367        0.11689495        0.01354595
+    49186.78052        0.09243566        0.01477117
+    49206.45523        0.10739020        0.01590244
+    49226.13781        0.09499472        0.01557596
+    49245.82827        0.12656672        0.01531733
+    49265.52660        0.11858975        0.01482356
+    49285.23281        0.12477254        0.01485588
+    49304.94690        0.10595533        0.01601053
+    49324.66888        0.11051729        0.01612454
+    49344.39875        0.09024121        0.01468279
+    49364.13651        0.09990266        0.01466462
+    49383.88216        0.07828268        0.01602524
+    49403.63572        0.08308742        0.01484781
+    49423.39717        0.10024924        0.01523165
+    49443.16653        0.11248827        0.01609156
+    49462.94380        0.11935364        0.01555573
+    49482.72897        0.10618886        0.01404753
+    49502.52207        0.10345494        0.01503842
+    49522.32308        0.09758597        0.01506738
+    49542.13200        0.10796070        0.01468720
+    49561.94886        0.12361238        0.01566807
+    49581.77364        0.12454747        0.01419366
+    49601.60635        0.08625432        0.01581842
+    49621.44699        0.09752062        0.01583958
+    49641.29557        0.09722091        0.01562239
+    49661.15209        0.09319706        0.01569606
+    49681.01655        0.08866529        0.01612606
+    49700.88895        0.12019582        0.01506225
+    49720.76931        0.14231610        0.01478481
+    49740.65762        0.11537877        0.01615769
+    49760.55388        0.11232238        0.01550102
+    49780.45810        0.08370522        0.01491522
+    49800.37028        0.12152211        0.01550053
+    49820.29043        0.10224826        0.01614734
+    49840.21855        0.10519716        0.01534508
+    49860.15464        0.11241748        0.01472599
+    49880.09870        0.10284572        0.01588317
+    49900.05074        0.10577532        0.01597969
+    49920.01076        0.09269250        0.01574058
+    49939.97876        0.11420441        0.01583903
+    49959.95475        0.08720326        0.01634894
+    49979.93874        0.10276176        0.01632413
+    49999.93071        0.11570618        0.01624306
+    50019.93068        0.10372507        0.01629285
+    50039.93866        0.10123827        0.01561110
+    50059.95463        0.13873731        0.01536440
+    50079.97861        0.04916806        0.01710047
+    50100.01060        0.11290477        0.01624192
+    50120.05061        0.12641145        0.01533003
+    50140.09863        0.09668800        0.01583024
+    50160.15467        0.10532117        0.01577422
+    50180.21873        0.09122817        0.01591818
+    50200.29082        0.10986897        0.01621450
+    50220.37093        0.12245252        0.01610236
+    50240.45908        0.09360126        0.01688322
+    50260.55527        0.11479764        0.01641322
+    50280.65949        0.11102275        0.01677243
+    50300.77175        0.11014600        0.01691929
+    50320.89206        0.09182264        0.01642720
+    50341.02042        0.10848676        0.01694490
+    50361.15683        0.10394726        0.01728406
+    50381.30129        0.10403586        0.01592662
+    50401.45381        0.10424124        0.01595806
+    50421.61439        0.10438487        0.01697627
+    50441.78304        0.10126478        0.01637776
+    50461.95975        0.11628158        0.01700453
+    50482.14453        0.08867580        0.01644230
+    50502.33739        0.10109138        0.01644974
+    50522.53833        0.10937008        0.01775408
+    50542.74734        0.13492413        0.01500206
+    50562.96444        0.14165278        0.01403777
+    50583.18963        0.11227519        0.01559969
+    50603.42290        0.08994377        0.01646361
+    50623.66427        0.11092021        0.01621113
+    50643.91374        0.08526192        0.01610468
+    50664.17130        0.09067652        0.01739456
+    50684.43697        0.10484182        0.01612935
+    50704.71075        0.08956800        0.01712774
+    50724.99263        0.08731088        0.01666426
+    50745.28263        0.13431120        0.01577667
+    50765.58074        0.07708056        0.01705596
+    50785.88697        0.12490133        0.01620333
+    50806.20133        0.11120205        0.01766490
+    50826.52381        0.10251946        0.01678500
+    50846.85442        0.07750677        0.01784390
+    50867.19316        0.09308270        0.01616160
+    50887.54004        0.08941457        0.01812604
+    50907.89505        0.10815085        0.01697791
+    50928.25821        0.11456857        0.01698577
+    50948.62951        0.10176618        0.01687028
+    50969.00896        0.11736322        0.01617081
+    50989.39657        0.10402613        0.01539459
+    51009.79233        0.08298610        0.01618434
+    51030.19624        0.09543619        0.01677533
+    51050.60832        0.12956755        0.01617097
+    51071.02857        0.08044505        0.01805630
+    51091.45698        0.11744475        0.01681977
+    51111.89356        0.09175396        0.01772737
+    51132.33832        0.10365240        0.01589003
+    51152.79125        0.09299590        0.01731484
+    51173.25237        0.14077702        0.01579185
+    51193.72167        0.10640394        0.01512898
+    51214.19916        0.10529854        0.01492773
+    51234.68484        0.08531699        0.01740724
+    51255.17871        0.10999903        0.01675677
+    51275.68078        0.12258665        0.01564496
+    51296.19106        0.10445821        0.01720351
+    51316.70953        0.10694488        0.01635653
+    51337.23622        0.11706059        0.01580374
+    51357.77111        0.06169700        0.01726935
+    51378.31422        0.09183398        0.01659218
+    51398.86555        0.10024419        0.01661893
+    51419.42509        0.08940679        0.01681712
+    51439.99286        0.11224434        0.01671769
+    51460.56886        0.11249599        0.01686339
+    51481.15309        0.10557710        0.01655878
+    51501.74555        0.08553738        0.01595216
+    51522.34625        0.08568963        0.01640692
+    51542.95518        0.11882439        0.01623763
+    51563.57237        0.12205623        0.01537402
+    51584.19780        0.07514978        0.01675080
+    51604.83147        0.11484700        0.01566767
+    51625.47341        0.11708663        0.01539737
+    51646.12360        0.10198643        0.01627880
+    51666.78205        0.11438617        0.01624528
+    51687.44876        0.11502056        0.01624849
+    51708.12374        0.10113888        0.01766324
+    51728.80699        0.12754985        0.01635271
+    51749.49851        0.13079370        0.01518207
+    51770.19831        0.12353942        0.01652992
+    51790.90639        0.12604216        0.01535859
+    51811.62275        0.10755636        0.01474048
+    51832.34740        0.09242138        0.01593797
+    51853.08034        0.08632340        0.01638081
+    51873.82157        0.10235880        0.01685776
+    51894.57110        0.14567814        0.01619670
+    51915.32893        0.10429193        0.01615377
+    51936.09506        0.09687696        0.01726981
+    51956.86950        0.10250574        0.01667990
+    51977.65225        0.13089597        0.01613416
+    51998.44331        0.09662637        0.01580627
+    52019.24268        0.12189476        0.01577231
+    52040.05038        0.10108119        0.01704766
+    52060.86640        0.09089796        0.01710523
+    52081.69075        0.10003489        0.01585962
+    52102.52342        0.12727851        0.01616624
+    52123.36443        0.12811583        0.01661133
+    52144.21378        0.12609587        0.01522459
+    52165.07147        0.12485928        0.01638668
+    52185.93749        0.10851758        0.01572503
+    52206.81187        0.08458343        0.01774667
+    52227.69459        0.10246340        0.01542916
+    52248.58567        0.09472734        0.01672203
+    52269.48511        0.08402866        0.01649291
+    52290.39290        0.10848833        0.01572079
+    52311.30906        0.11709740        0.01592009
+    52332.23358        0.12585457        0.01582711
+    52353.16647        0.12416236        0.01667262
+    52374.10774        0.11587038        0.01693205
+    52395.05738        0.10704502        0.01759011
+    52416.01541        0.09056404        0.01754422
+    52436.98181        0.10960496        0.01741120
+    52457.95661        0.10599524        0.01694082
+    52478.93979        0.09439823        0.01552442
+    52499.93136        0.09540496        0.01704897
+    52520.93134        0.11365047        0.01570696
+    52541.93971        0.11887009        0.01688906
+    52562.95648        0.11031901        0.01598607
+    52583.98167        0.10446335        0.01648210
+    52605.01526        0.13062979        0.01588337
+    52626.05727        0.10307341        0.01635212
+    52647.10769        0.08120294        0.01792812
+    52668.16653        0.09365844        0.01678948
+    52689.23380        0.11072938        0.01613514
+    52710.30949        0.10018277        0.01606964
+    52731.39362        0.12452295        0.01586543
+    52752.48617        0.06320473        0.01724496
+    52773.58717        0.09902526        0.01715368
+    52794.69660        0.08136005        0.01780530
+    52815.81448        0.12562839        0.01731443
+    52836.94081        0.10676544        0.01631148
+    52858.07558        0.08724874        0.01680465
+    52879.21881        0.11878376        0.01660396
+    52900.37050        0.11152354        0.01533258
+    52921.53065        0.12118447        0.01667811
+    52942.69926        0.09424968        0.01773596
+    52963.87634        0.13168847        0.01795361
+    52985.06189        0.09592065        0.01675634
+    53006.25592        0.09089833        0.01812419
+    53027.45842        0.12280657        0.01735861
+    53048.66940        0.08720602        0.01734078
+    53069.88887        0.11535067        0.01750724
+    53091.11683        0.10199310        0.01722737
+    53112.35327        0.09396581        0.01675575
+    53133.59821        0.09413662        0.01645716
+    53154.85165        0.10854967        0.01534614
+    53176.11359        0.12902898        0.01709729
+    53197.38404        0.08941254        0.01831467
+    53218.66299        0.08799527        0.01651694
+    53239.95046        0.08072317        0.01604615
+    53261.24644        0.11016209        0.01642100
+    53282.55094        0.09485439        0.01806767
+    53303.86396        0.10079775        0.01777595
+    53325.18550        0.11980400        0.01890033
+    53346.51558        0.10942439        0.01694874
+    53367.85418        0.09292410        0.01767462
+    53389.20133        0.09947895        0.01692491
+    53410.55701        0.14375367        0.01730530
+    53431.92123        0.11182061        0.01645177
+    53453.29400        0.14769756        0.01616253
+    53474.67531        0.10745208        0.01853160
+    53496.06518        0.11654350        0.01645720
+    53517.46361        0.09132137        0.01839242
+    53538.87060        0.11811013        0.01637190
+    53560.28614        0.12964653        0.01698288
+    53581.71026        0.14231676        0.01775488
+    53603.14294        0.11642563        0.01828764
+    53624.58420        0.10959219        0.01847084
+    53646.03403        0.13173424        0.01806625
+    53667.49245        0.16256978        0.01752498
+    53688.95944        0.13466080        0.01787760
+    53710.43503        0.14490192        0.01734266
+    53731.91920        0.15446472        0.01757985
+    53753.41197        0.14146330        0.02014789
+    53774.91333        0.16925561        0.01915945
+    53796.42330        0.11893040        0.01889258
+    53817.94187        0.15950276        0.01930331
+    53839.46905        0.16018587        0.01919328
+    53861.00483        0.11109310        0.01997068
+    53882.54924        0.18986800        0.01924897
+    53904.10226        0.15688476        0.01918779
+    53925.66390        0.20008816        0.01963966
+    53947.23416        0.24555626        0.01969413
+    53968.81306        0.27309099        0.02175758
+    53990.40058        0.37934450        0.02313106
+    54011.99674        0.48723638        0.02549503
+    54033.60154        0.66110386        0.02713788
+    54055.21498        0.95351283        0.03103437
+    54076.83707        1.32321972        0.03553964
+    54098.46780        1.82958887        0.04131354
+    54120.10719        2.49154585        0.04620485
+    54141.75523        3.12496966        0.05188981
+    54163.41193        3.73567324        0.05603041
+    54185.07730        3.96404216        0.05890759
+    54206.75133        4.09605339        0.05897815
+    54228.43403        4.01325164        0.05879268
+    54250.12540        3.54797970        0.05536354
+    54271.82545        3.13258951        0.05253631
+    54293.53418        2.51699403        0.04734398
+    54315.25160        1.92809736        0.04153875
+    54336.97770        1.46746701        0.03709942
+    54358.71249        1.12302485        0.03283530
+    54380.45597        0.82050699        0.03023572
+    54402.20816        0.55533024        0.02558866
+    54423.96904        0.41400696        0.02489777
+    54445.73863        0.36727877        0.02207816
+    54467.51692        0.25955817        0.02134449
+    54489.30393        0.23804994        0.02022470
+    54511.09965        0.25488239        0.01889572
+    54532.90409        0.18323832        0.01930181
+    54554.71725        0.16697102        0.01882046
+    54576.53914        0.17839282        0.01860322
+    54598.36975        0.15983885        0.01854978
+    54620.20910        0.16518331        0.01917675
+    54642.05719        0.12242427        0.01876997
+    54663.91401        0.14686056        0.01799574
+    54685.77957        0.09950800        0.01930685
+    54707.65389        0.12098766        0.01780049
+    54729.53695        0.11305290        0.01850572
+    54751.42876        0.08301823        0.01837272
+    54773.32933        0.11584002        0.01775840
+    54795.23867        0.06658589        0.01956449
+    54817.15676        0.10650625        0.01812099
+    54839.08362        0.09625267        0.01808595
+    54861.01926        0.12700018        0.01793379
+    54882.96367        0.11679694        0.01876605
+    54904.91685        0.11071275        0.01965352
+    54926.87882        0.11188477        0.01817562
+    54948.84957        0.13131747        0.01828517
+    54970.82911        0.13139282        0.01740198
+    54992.81744        0.09374779        0.01816632
+    55014.81457        0.09739848        0.01879028
+    55036.82049        0.10349306        0.01859680
+    55058.83522        0.08195812        0.01983263
+    55080.85876        0.12549072        0.01695250
+    55102.89110        0.12365300        0.01767391
+    55124.93226        0.11873114        0.01757075
+    55146.98223        0.12676364        0.01795906
+    55169.04102        0.09756984        0.01907968
+    55191.10864        0.12707157        0.01666811
+    55213.18508        0.10681124        0.01879534
+    55235.27036        0.11716819        0.01643952
+    55257.36446        0.09721207        0.01878361
+    55279.46741        0.08694124        0.01802354
+    55301.57920        0.11797876        0.01857490
+    55323.69983        0.13842846        0.01683079
+    55345.82931        0.07993996        0.02018089
+    55367.96764        0.09256787        0.01785696
+    55390.11483        0.10368940        0.01939078
+    55412.27087        0.11584707        0.01845001
+    55434.43578        0.13153941        0.01847401
+    55456.60956        0.10634247        0.01846695
+    55478.79220        0.10910097        0.01855927
+    55500.98372        0.09085863        0.01925451
+    55523.18411        0.07605763        0.01877212
+    55545.39338        0.13236542        0.01844716
+    55567.61154        0.11880640        0.01815575
+    55589.83859        0.11578130        0.01867481
+    55612.07452        0.10567265        0.01710362
+    55634.31935        0.12883734        0.01884777
+    55656.57308        0.13340191        0.01897985
+    55678.83571        0.10802994        0.01822512
+    55701.10724        0.08946494        0.01894788
+    55723.38768        0.09919018        0.01919421
+    55745.67704        0.10171910        0.01871539
+    55767.97531        0.10394895        0.01897351
+    55790.28250        0.11288108        0.01785455
+    55812.59861        0.11546717        0.01832368
+    55834.92365        0.06688706        0.01833981
+    55857.25762        0.09159413        0.01985430
+    55879.60053        0.09334866        0.01657938
+    55901.95237        0.12097893        0.01888928
+    55924.31315        0.11067151        0.01827387
+    55946.68287        0.09411325        0.01886237
+    55969.06155        0.10155413        0.01828101
+    55991.44917        0.06812441        0.01979513
+    56013.84575        0.07821929        0.01930564
+    56036.25129        0.10619139        0.01883739
+    56058.66579        0.10825833        0.01852028
+    56081.08925        0.08682649        0.01881523
+    56103.52169        0.08851683        0.01829120
+    56125.96310        0.08992199        0.01855029
+    56148.41348        0.10456347        0.01950040
+    56170.87285        0.11128969        0.01891731
+    56193.34120        0.07963818        0.01838427
+    56215.81854        0.11374348        0.01823045
+    56238.30486        0.07966132        0.01781919
+    56260.80018        0.11138013        0.01821742
+    56283.30450        0.12472415        0.01935447
+    56305.81783        0.08244735        0.01731137
+    56328.34015        0.09959729        0.01919396
+    56350.87149        0.07614562        0.02001635
+    56373.41184        0.08359076        0.01982188
+    56395.96120        0.06451858        0.01978340
+    56418.51959        0.11502371        0.01799884
+    56441.08700        0.11776125        0.01949456
+    56463.66343        0.07585905        0.01931424
+    56486.24890        0.10216792        0.01895889
+    56508.84339        0.09508228        0.01979455
+    56531.44693        0.11663097        0.01768341
+    56554.05951        0.08430083        0.01858147
+    56576.68113        0.10811117        0.01917721
+    56599.31181        0.09045709        0.01996943
+    56621.95153        0.08494205        0.01781528
+    56644.60031        0.11862439        0.01949385
+    56667.25815        0.09533956        0.01916648
+    56689.92506        0.07772743        0.01957776
+    56712.60103        0.07331499        0.01804059
+    56735.28607        0.10494512        0.01946588
+    56757.98018        0.11937879        0.01860025
+    56780.68337        0.07947313        0.01991763
+    56803.39565        0.11478762        0.01673664
+    56826.11700        0.10469245        0.01808145
+    56848.84745        0.11402904        0.01722198
+    56871.58699        0.10451289        0.01939403
+    56894.33563        0.10518505        0.01922435
+    56917.09336        0.09871984        0.02050394
+    56939.86020        0.12708277        0.01786524
+    56962.63614        0.11354056        0.01927348
+    56985.42120        0.10136053        0.01941234
+    57008.21536        0.10674474        0.02036569
+    57031.01865        0.11960711        0.01904336
+    57053.83106        0.11712361        0.01962373
+    57076.65259        0.09762055        0.02019539
+    57099.48325        0.11438930        0.01851446
+    57122.32304        0.09766405        0.01918681
+    57145.17197        0.11116751        0.01867116
+    57168.03004        0.11796172        0.01841311
+    57190.89725        0.07053060        0.02002491
+    57213.77361        0.12078144        0.01894193
+    57236.65912        0.12988561        0.01896377
+    57259.55379        0.12379548        0.01904165
+    57282.45761        0.10906806        0.01933666
+    57305.37059        0.09062917        0.02056727
+    57328.29274        0.08726390        0.01968891
+    57351.22406        0.07822810        0.01862387
+    57374.16455        0.08085292        0.01957776
+    57397.11421        0.10994586        0.01742781
+    57420.07306        0.10187974        0.01906552
+    57443.04109        0.11272131        0.01730525
+    57466.01830        0.06228201        0.01922536
+    57489.00471        0.09026286        0.02055610
+    57512.00031        0.10280921        0.01828734
+    57535.00511        0.10344301        0.01688559
+    57558.01911        0.08812528        0.02217921
+    57581.04232        0.13413909        0.01871068
+    57604.07474        0.09679807        0.01936187
+    57627.11637        0.09662315        0.02024765
+    57650.16722        0.10968956        0.01814119
+    57673.22728        0.10719372        0.01879728
+    57696.29657        0.11378577        0.01987747
+    57719.37509        0.10515019        0.01855688
+    57742.46284        0.10577610        0.01994678
+    57765.55983        0.09678008        0.01952824
+    57788.66605        0.12653594        0.01894050
+    57811.78152        0.11025191        0.01968479
+    57834.90623        0.14148777        0.01936261
+    57858.04019        0.09941163        0.01923287
+    57881.18341        0.12216440        0.01937268
+    57904.33588        0.10520768        0.02031289
+    57927.49762        0.14612954        0.01956016
+    57950.66862        0.09966622        0.01862029
+    57973.84888        0.13806663        0.01962500
+    57997.03842        0.10834951        0.02133145
+    58020.23724        0.09700047        0.02022365
+    58043.44533        0.07043495        0.01840572
+    58066.66271        0.11981921        0.01970157
+    58089.88938        0.10818747        0.02055447
+    58113.12533        0.09924513        0.02079710
+    58136.37058        0.07742169        0.02073306
+    58159.62513        0.06174198        0.02146033
+    58182.88898        0.10286379        0.02005391
+    58206.16214        0.08039454        0.02019753
+    58229.44460        0.09363988        0.02119549
+    58252.73638        0.14659668        0.01935386
+    58276.03747        0.11521866        0.02042710
+    58299.34789        0.08527242        0.02016121
+    58322.66763        0.12033457        0.01943428
+    58345.99669        0.11612402        0.02027244
+    58369.33509        0.11723633        0.02031679
+    58392.68283        0.09610220        0.01909406
+    58416.03990        0.11606234        0.02009474
+    58439.40632        0.10959504        0.02018404
+    58462.78208        0.09283266        0.01930735
+    58486.16719        0.11011434        0.02092056
+    58509.56166        0.09877000        0.02044196
+    58532.96548        0.10972821        0.02004253
+    58556.37867        0.06767880        0.02131629
+    58579.80122        0.10758039        0.01979762
+    58603.23314        0.07831064        0.02072492
+    58626.67443        0.08296996        0.01945028
+    58650.12510        0.09575525        0.02119574
+    58673.58515        0.11990675        0.01996183
+    58697.05459        0.09735512        0.02036358
+    58720.53341        0.08746847        0.01965602
+    58744.02162        0.11543817        0.01942355
+    58767.51923        0.10835286        0.01796234
+    58791.02624        0.08984052        0.01978268
+    58814.54265        0.08372622        0.02130087
+    58838.06847        0.13135963        0.01991655
+    58861.60369        0.10160404        0.02243025
+    58885.14834        0.07981271        0.02009226
+    58908.70240        0.10386483        0.01974977
+    58932.26588        0.12632926        0.01960668
+    58955.83878        0.06682880        0.01930756
+    58979.42112        0.10294627        0.02026302
+    59003.01289        0.08714021        0.01962356
+    59026.61409        0.06133125        0.02068947
+    59050.22474        0.08427997        0.02080111
+    59073.84483        0.09391205        0.02174748
+    59097.47436        0.10010487        0.02074815
+    59121.11335        0.11829614        0.01975737
+    59144.76180        0.08039330        0.02076157
+    59168.41970        0.09678050        0.02046322
+    59192.08707        0.10134669        0.01960010
+    59215.76391        0.10774265        0.02100507
+    59239.45021        0.11735613        0.02078072
+    59263.14599        0.06614516        0.02047605
+    59286.85125        0.13196612        0.01865642
+    59310.56599        0.08989220        0.01910714
+    59334.29022        0.08407861        0.02098298
+    59358.02393        0.11602894        0.02034661
+    59381.76714        0.09760955        0.02063851
+    59405.51985        0.06187621        0.02192793
+    59429.28206        0.11185179        0.02005492
+    59453.05377        0.09959086        0.01923361
+    59476.83499        0.10728364        0.01893520
+    59500.62573        0.06128584        0.02034194
+    59524.42598        0.07713120        0.01950116
+    59548.23575        0.09083602        0.02041278
+    59572.05504        0.08049648        0.01828666
+    59595.88386        0.10460311        0.01872483
+    59619.72222        0.09619963        0.02039441
+    59643.57011        0.10372924        0.01930678
+    59667.42753        0.08213186        0.02160070
+    59691.29451        0.08271235        0.02188983
+    59715.17102        0.10558243        0.02024064
+    59739.05709        0.06556556        0.02077833
+    59762.95271        0.11371317        0.02127758
+    59786.85790        0.10538683        0.01923975
+    59810.77264        0.11121816        0.02024124
+    59834.69695        0.13783605        0.01936382
+    59858.63083        0.09150781        0.02003904
+    59882.57428        0.08552702        0.02197762
+    59906.52731        0.10192633        0.01927819
+    59930.48992        0.06417559        0.02274279
+    59954.46212        0.09953748        0.02089976
+    59978.44390        0.09843164        0.02142048
+    60002.43528        0.08268473        0.02130896
+    60026.43625        0.10506574        0.02087497
+    60050.44683        0.10088426        0.02079973
+    60074.46701        0.11178847        0.02031402
+    60098.49679        0.07325214        0.02173819
+    60122.53619        0.08636875        0.02133526
+    60146.58521        0.08942578        0.02119396
+    60170.64384        0.09915211        0.02122630
+    60194.71210        0.07201061        0.02266547
+    60218.78998        0.08499663        0.02148877
+    60242.87750        0.09525938        0.02180228
+    60266.97465        0.10948521        0.02058757
+    60291.08144        0.11386910        0.02184354
+    60315.19787        0.05539065        0.02277456
+    60339.32395        0.12783292        0.02092808
+    60363.45968        0.09912887        0.02239803
+    60387.60506        0.12009994        0.02190730
+    60411.76011        0.07914345        0.02197561
+    60435.92481        0.07666593        0.02301969
+    60460.09918        0.08053522        0.02069513
+    60484.28322        0.09641054        0.02029431
+    60508.47693        0.07096139        0.02274968
+    60532.68032        0.07750228        0.02268818
+    60556.89340        0.11076091        0.02079767
+    60581.11615        0.11372682        0.02120005
+    60605.34860        0.08902986        0.02084360
+    60629.59074        0.07261744        0.02158517
+    60653.84258        0.07425865        0.02382937
+    60678.10411        0.08592157        0.02083240
+    60702.37535        0.05417419        0.02493518
+    60726.65630        0.08323334        0.02252691
+    60750.94697        0.13674312        0.02051559
+    60775.24735        0.08167801        0.02414048
+    60799.55744        0.12141640        0.01979778
+    60823.87727        0.12191799        0.02221648
+    60848.20682        0.07840557        0.02412253
+    60872.54610        0.10286185        0.01992772
+    60896.89512        0.08445430        0.02241096
+    60921.25388        0.06533356        0.02163115
+    60945.62238        0.13425308        0.02204135
+    60970.00063        0.08229133        0.02239685
+    60994.38863        0.08069704        0.02208570
+    61018.78638        0.07178718        0.02407901
+    61043.19390        0.10792644        0.02079069
+    61067.61118        0.07105944        0.02159622
+    61092.03822        0.08986616        0.02063056
+    61116.47504        0.08391490        0.02448190
+    61140.92163        0.11087491        0.02097071
+    61165.37799        0.10998383        0.02246333
+    61189.84415        0.08533006        0.02184130
+    61214.32008        0.09241416        0.02265247
+    61238.80581        0.13517703        0.02085880
+    61263.30133        0.07582181        0.02480290
+    61287.80665        0.09258092        0.02390902
+    61312.32178        0.07623295        0.02297350
+    61336.84671        0.14418781        0.02094069
+    61361.38144        0.12779090        0.02206981
+    61385.92600        0.08224436        0.02297618
+    61410.48037        0.11579426        0.02151263
+    61435.04456        0.08200540        0.02123096
+    61459.61858        0.06856100        0.02363274
+    61484.20242        0.11848710        0.02139310
+    61508.79611        0.09329211        0.02229736
+    61533.39962        0.07489172        0.02086378
+    61558.01298        0.11169693        0.02195113
+    61582.63619        0.10733094        0.02279867
+    61607.26924        0.09374343        0.02152066
+    61631.91215        0.07457149        0.02197995
+    61656.56492        0.09513816        0.02227367
+    61681.22754        0.08236719        0.02380277
+    61705.90003        0.10816490        0.01970419
+    61730.58239        0.10423280        0.02100744
+    61755.27463        0.12436644        0.02321223
+    61779.97674        0.08326367        0.02485768
+    61804.68873        0.09325205        0.02367514
+    61829.41060        0.04862952        0.02405038
+    61854.14237        0.11144530        0.02299412
+    61878.88402        0.09734087        0.02231686
+    61903.63558        0.09811602        0.02423713
+    61928.39703        0.09177750        0.02086723
+    61953.16839        0.07914667        0.02500269
+    61977.94966        0.11805132        0.02300740
+    62002.74084        0.07372017        0.02310212
+    62027.54193        0.10255875        0.02296814
+    62052.35295        0.08651744        0.02189384
+    62077.17389        0.07211646        0.02349162
+    62102.00476        0.08135794        0.02314716
+    62126.84556        0.11099476        0.02335690
+    62151.69630        0.12217029        0.02338288
+    62176.55698        0.09177220        0.02258164
+    62201.42760        0.08727836        0.02504941
+    62226.30817        0.12862887        0.02400779
+    62251.19870        0.09740960        0.02113318
+    62276.09918        0.07508045        0.02262359
+    62301.00962        0.08892857        0.02272564
+    62325.93002        0.10284817        0.02282944
+    62350.86039        0.07779020        0.02417601
+    62375.80074        0.12667260        0.02187085
+    62400.75106        0.10209391        0.02363276
+    62425.71136        0.08883359        0.02463580
+    62450.68164        0.08173038        0.02482324
+    62475.66191        0.03275363        0.02320584
+    62500.65218        0.14686142        0.02196424
+    62525.65244        0.12089141        0.02303127
+    62550.66270        0.09237153        0.02330506
+    62575.68297        0.05909160        0.02543912
+    62600.71324        0.07313689        0.02387769
+    62625.75352        0.11017010        0.02391921
+    62650.80383        0.12456891        0.02148561
+    62675.86415        0.07463220        0.02470981
+    62700.93449        0.07709685        0.02379396
+    62726.01487        0.11058286        0.02301524
+    62751.10527        0.08136393        0.02398203
+    62776.20571        0.07510296        0.02486568
+    62801.31620        0.06041188        0.02449643
+    62826.43672        0.09818453        0.02123681
+    62851.56730        0.12604989        0.02174105
+    62876.70792        0.07086646        0.02452367
+    62901.85861        0.09763598        0.02425273
+    62927.01935        0.11353672        0.02180521
+    62952.19016        0.14427681        0.02238669
+    62977.37104        0.10491777        0.02621737
+    63002.56198        0.11559947        0.02115345
+    63027.76301        0.08981767        0.02309804
+    63052.97411        0.08349136        0.02404210
+    63078.19530        0.12799644        0.02317324
+    63103.42658        0.05949496        0.02450646
+    63128.66795        0.09862616        0.02349068
+    63153.91942        0.08827218        0.02604911
+    63179.18099        0.05543734        0.02520872
+    63204.45266        0.12056685        0.02386010
+    63229.73444        0.10204259        0.02372785
+    63255.02633        0.05894103        0.02399566
+    63280.32834        0.11311487        0.02299062
+    63305.64048        0.12543852        0.02222348
+    63330.96273        0.12716743        0.02422693
+    63356.29512        0.08462684        0.02415170
+    63381.63764        0.10173742        0.02394040
+    63406.99029        0.09890557        0.02464091
+    63432.35309        0.12031469        0.02455610
+    63457.72603        0.10432171        0.02451268
+    63483.10912        0.12081122        0.02465744
+    63508.50236        0.13655481        0.02030596
+    63533.90576        0.11734817        0.02389350
+    63559.31933        0.14448975        0.02472952
+    63584.74305        0.08565244        0.02421502
+    63610.17695        0.06632369        0.02485025
+    63635.62102        0.11231120        0.02546231
+    63661.07527        0.10426433        0.02453502
+    63686.53970        0.09057258        0.02533763
+    63712.01432        0.06449022        0.02615015
+    63737.49912        0.13086029        0.02350782
+    63762.99412        0.11449111        0.02346693
+    63788.49932        0.13493260        0.02204311
+    63814.01472        0.11982536        0.02493885
+    63839.54032        0.09069123        0.02288490
+    63865.07614        0.05751084        0.02400652
+    63890.62217        0.09216768        0.02470135
+    63916.17842        0.11124908        0.02609581
+    63941.74489        0.11266037        0.02502647
+    63967.32159        0.08494703        0.02425830
+    63992.90852        0.09960055        0.02350079
+    64018.50568        0.08256881        0.02631471
+    64044.11308        0.07423563        0.02729040
+    64069.73073        0.09218609        0.02592649
+    64095.35862        0.10361775        0.02383732
+    64120.99676        0.10710713        0.02311346
+    64146.64516        0.06794639        0.03025742
+    64172.30382        0.08600610        0.02429345
+    64197.97274        0.08754954        0.02723239
+    64223.65193        0.08618263        0.02723496
+    64249.34139        0.10519710        0.02540634
+    64275.04113        0.06950517        0.02761148
+    64300.75115        0.06426713        0.02506739
+    64326.47145        0.07897226        0.02714096
+    64352.20203        0.10644458        0.02509960
+    64377.94291        0.10243724        0.02321807
+    64403.69409        0.10347378        0.02502299
+    64429.45557        0.06831782        0.02481003
+    64455.22735        0.09564007        0.02563197
+    64481.00944        0.05604526        0.02731421
+    64506.80185        0.07766818        0.02902940
+    64532.60457        0.10990905        0.02645181
+    64558.41761        0.09840226        0.02652485
+    64584.24098        0.07020824        0.02611971
+    64610.07467        0.10134503        0.02453209
+    64635.91870        0.06936683        0.02651604
+    64661.77307        0.11397618        0.02619352
+    64687.63778        0.10125608        0.02542019
+    64713.51283        0.12493042        0.02354932
+    64739.39824        0.05777875        0.02745883
+    64765.29400        0.10424701        0.02428515
+    64791.20012        0.08339920        0.02498540
+    64817.11660        0.07104829        0.02550887
+    64843.04344        0.10109187        0.02384477
+    64868.98066        0.13538549        0.02407796
+    64894.92825        0.04751534        0.02538562
+    64920.88622        0.08870794        0.02625306
+    64946.85458        0.10626324        0.02599186
+    64972.83332        0.09053443        0.02728025
+    64998.82245        0.05834609        0.02556187
+    65024.82198        0.10129528        0.02518037
+    65050.83191        0.08293123        0.02688711
+    65076.85224        0.10839148        0.02217980
+    65102.88299        0.08741499        0.02449443
+    65128.92414        0.10194819        0.02502631
+    65154.97571        0.08451009        0.02546902
+    65181.03770        0.09445803        0.02802758
+    65207.11011        0.08633409        0.02656437
+    65233.19296        0.11502639        0.02615050
+    65259.28623        0.10221136        0.02672598
+    65285.38995        0.08005443        0.02832129
+    65311.50410        0.07716372        0.03036436
+    65337.62871        0.10933420        0.02478131
+    65363.76376        0.10742534        0.02666512
+    65389.90926        0.09274938        0.02718293
+    65416.06523        0.10394986        0.02619486
+    65442.23165        0.08047435        0.02825764
+    65468.40855        0.12769521        0.02835985
+    65494.59591        0.13709955        0.02824038
+    65520.79375        0.07423795        0.03117377
+    65547.00207        0.07945588        0.02843053
+    65573.22087        0.12305148        0.02797057
+    65599.45015        0.08623708        0.02643601
+    65625.68993        0.14091626        0.02578615
+    65651.94021        0.10952601        0.02816636
+    65678.20099        0.11638683        0.02841576
+    65704.47227        0.10800370        0.02911297
+    65730.75406        0.09888926        0.02934241
+    65757.04636        0.12358653        0.02642246
+    65783.34918        0.15422513        0.02645007
+    65809.66252        0.09269052        0.02930262
+    65835.98638        0.19318519        0.02525709
+    65862.32078        0.13119449        0.02913700
+    65888.66570        0.08474746        0.03133718
+    65915.02117        0.20777609        0.02958601
+    65941.38718        0.16264607        0.03259982
+    65967.76373        0.19989837        0.03068889
+    65994.15084        0.21169742        0.03101119
+    66020.54850        0.32459129        0.03393753
+    66046.95672        0.32466851        0.03581806
+    66073.37550        0.43565315        0.03658087
+    66099.80485        0.57090151        0.03821819
+    66126.24477        0.65379299        0.04097317
+    66152.69527        0.91030619        0.04478462
+    66179.15635        1.12723908        0.04922803
+    66205.62801        1.51464798        0.05662940
+    66232.11026        1.86333086        0.05853414
+    66258.60311        2.29401070        0.06682432
+    66285.10655        2.79793381        0.07234422
+    66311.62059        2.96461676        0.07281798
+    66338.14524        3.26959518        0.07793906
+    66364.68050        3.46730232        0.07952690
+    66391.22637        3.39229944        0.08018042
+    66417.78286        3.28267831        0.07948321
+    66444.34997        3.02736363        0.07481370
+    66470.92771        2.85176535        0.07523971
+    66497.51608        2.31204986        0.06624525
+    66524.11509        1.95881352        0.06262941
+    66550.72474        1.68157462        0.05833753
+    66577.34503        1.37945061        0.05545963
+    66603.97596        1.23525223        0.05099341
+    66630.61756        0.85869907        0.04409970
+    66657.26980        0.72884111        0.04030360
+    66683.93271        0.60260035        0.03620584
+    66710.60628        0.40848975        0.03634437
+    66737.29053        0.38344810        0.03393104
+    66763.98544        0.33435399        0.03310569
+    66790.69104        0.21876684        0.03253930
+    66817.40731        0.28154869        0.03179214
+    66844.13428        0.25767900        0.02859824
+    66870.87193        0.19658420        0.02819877
+    66897.62028        0.18128309        0.02959187
+    66924.37933        0.14777133        0.02957007
+    66951.14908        0.12929238        0.02998081
+    66977.92954        0.13688564        0.02845853
+    67004.72071        0.11466826        0.02968728
+    67031.52260        0.10773973        0.02817153
+    67058.33521        0.18173106        0.02508004
+    67085.15854        0.11364343        0.02750910
+    67111.99260        0.12513677        0.02743075
+    67138.83740        0.12170736        0.02834695
+    67165.69294        0.17493532        0.02760026
+    67192.55921        0.11403928        0.02962804
+    67219.43624        0.10205148        0.02688897
+    67246.32401        0.10091408        0.02837846
+    67273.22254        0.12130362        0.02756323
+    67300.13183        0.10416349        0.02704575
+    67327.05188        0.12296152        0.02863906
+    67353.98270        0.13311470        0.02989744
+    67380.92430        0.15607209        0.02617322
+    67407.87667        0.12684686        0.02780562
+    67434.83982        0.08822738        0.02858704
+    67461.81375        0.07237021        0.02907110
+    67488.79848        0.09325641        0.02621599
+    67515.79400        0.06514354        0.02979070
+    67542.80032        0.16668251        0.02545025
+    67569.81744        0.13394684        0.02700162
+    67596.84536        0.14758668        0.02478259
+    67623.88410        0.09530098        0.02778754
+    67650.93365        0.12794261        0.02627108
+    67677.99403        0.12863038        0.02680773
+    67705.06523        0.10040625        0.02792680
+    67732.14725        0.10957813        0.02617447
+    67759.24011        0.09315803        0.02866405
+    67786.34381        0.05360952        0.02984049
+    67813.45834        0.06823178        0.02738470
+    67840.58373        0.09776310        0.02729649
+    67867.71996        0.09325316        0.02763881
+    67894.86705        0.10766319        0.02854952
+    67922.02500        0.11917587        0.02741648
+    67949.19381        0.09274110        0.02853577
+    67976.37348        0.13782754        0.02795119
+    68003.56403        0.06613566        0.02717729
+    68030.76546        0.05208523        0.02770142
+    68057.97776        0.08495375        0.03005455
+    68085.20096        0.09340677        0.02432823
+    68112.43504        0.13244012        0.02286339
+    68139.68001        0.09453499        0.02888663
+    68166.93588        0.11591972        0.02281062
+    68194.20266        0.12183050        0.02629073
+    68221.48034        0.10107234        0.02663098
+    68248.76893        0.16038994        0.02327377
+    68276.06844        0.08291656        0.02988799
+    68303.37886        0.06150749        0.02973875
+    68330.70022        0.06822738        0.02761176
+    68358.03250        0.07682865        0.02790079
+    68385.37571        0.11438136        0.02663114
+    68412.72986        0.06705343        0.02667211
+    68440.09495        0.12118295        0.02536192
+    68467.47099        0.09550988        0.02815137
+    68494.85798        0.12756902        0.02619437
+    68522.25592        0.10227049        0.03034568
+    68549.66482        0.10136511        0.02850530
+    68577.08469        0.15451704        0.02722729
+    68604.51552        0.08593913        0.02913837
+    68631.95733        0.10097396        0.02665427
+    68659.41011        0.09162223        0.02944353
+    68686.87388        0.09170734        0.02700009
+    68714.34863        0.11682189        0.02681912
+    68741.83436        0.10258190        0.03091045
+    68769.33110        0.06266542        0.03123162
+    68796.83883        0.08607696        0.03102719
+    68824.35757        0.09567620        0.02943887
+    68851.88731        0.08000044        0.03141382
+    68879.42806        0.14255548        0.02629200
+    68906.97984        0.10905125        0.02790990
+    68934.54263        0.07709423        0.02688684
+    68962.11644        0.11878716        0.02875422
+    68989.70129        0.04746873        0.03008646
+    69017.29717        0.09921350        0.02814209
+    69044.90409        0.09815399        0.02861941
+    69072.52205        0.07396573        0.02837015
+    69100.15106        0.09586424        0.02694910
+    69127.79112        0.13344703        0.02709475
+    69155.44224        0.10335169        0.02874604
+    69183.10442        0.07164818        0.02666900
+    69210.77766        0.09338864        0.02893335
+    69238.46197        0.17785950        0.02464957
+    69266.15735        0.12578091        0.03133652
+    69293.86382        0.07059665        0.02717099
+    69321.58136        0.10303335        0.02972948
+    69349.30999        0.14260778        0.02630165
+    69377.04972        0.04816282        0.03056092
+    69404.80054        0.08820843        0.02881750
+    69432.56246        0.13660472        0.02930461
+    69460.33548        0.05283896        0.03026195
+    69488.11962        0.12100208        0.02781496
+    69515.91486        0.07798342        0.02750216
+    69543.72123        0.06598009        0.02870131
+    69571.53872        0.05351826        0.02832096
+    69599.36733        0.08951423        0.02842271
+    69627.20708        0.12031819        0.02445235
+    69655.05796        0.13120207        0.02765815
+    69682.91999        0.11976284        0.02674352
+    69710.79316        0.12512753        0.02692364
+    69738.67747        0.05357186        0.02834932
+    69766.57294        0.10772650        0.02797087
+    69794.47957        0.04762254        0.03018395
+    69822.39736        0.05610283        0.02894373
+    69850.32632        0.13347764        0.02929121
+    69878.26645        0.09882125        0.02769056
+    69906.21776        0.07785656        0.02860408
+    69934.18025        0.06299380        0.03017110
+    69962.15392        0.11991887        0.02677836
+    69990.13878        0.11134319        0.02536218
+    70018.13484        0.05266262        0.02890507
+    70046.14209        0.11540197        0.02434852
+    70074.16055        0.11328067        0.02928964
+    70102.19021        0.08438651        0.02945121
+    70130.23109        0.08628575        0.02954149
+    70158.28318        0.06314957        0.03135119
+    70186.34649        0.11397119        0.02561382
+    70214.42103        0.05563413        0.02972318
+    70242.50680        0.09242081        0.02882877
+    70270.60380        0.04807702        0.02798017
+    70298.71205        0.07196848        0.03363093
+    70326.83153        0.15599630        0.02827217
+    70354.96226        0.07800878        0.02953563
+    70383.10425        0.04404237        0.03006285
+    70411.25749        0.11071468        0.02796409
+    70439.42199        0.09823108        0.03022499
+    70467.59776        0.03611550        0.02937909
+    70495.78480        0.09580367        0.02968157
+    70523.98311        0.12625966        0.02629906
+    70552.19271        0.08789554        0.02895268
+    70580.41358        0.09648879        0.02466414
+    70608.64575        0.05484519        0.02902315
+    70636.88921        0.10489758        0.02848568
+    70665.14396        0.07432033        0.02915101
+    70693.41002        0.09255130        0.02700116
+    70721.68739        0.06175461        0.03138195
+    70749.97606        0.09069724        0.03075164
+    70778.27605        0.08431926        0.02734419
+    70806.58736        0.13854763        0.02570112
+    70834.91000        0.08929140        0.02971490
+    70863.24396        0.10018804        0.02733242
+    70891.58926        0.11230790        0.02717137
+    70919.94589        0.12518849        0.02760581
+    70948.31387        0.09010572        0.03027571
+    70976.69320        0.11368955        0.02543649
+    71005.08387        0.10724041        0.02868167
+    71033.48591        0.06142310        0.02990543
+    71061.89930        0.08267595        0.03002427
+    71090.32406        0.11873405        0.02677988
+    71118.76019        0.14724550        0.02715700
+    71147.20770        0.12345744        0.02912983
+    71175.66658        0.10153493        0.03102557
+    71204.13685        0.10969698        0.02810989
+    71232.61850        0.05535489        0.03062159
+    71261.11155        0.07299594        0.02685903
+    71289.61599        0.07494568        0.02964741
+    71318.13184        0.13977880        0.02848703
+    71346.65909        0.06713963        0.02776993
+    71375.19776        0.07337257        0.02851773
+    71403.74783        0.08783331        0.03249239
+    71432.30933        0.05526448        0.03057157
+    71460.88226        0.10595382        0.02375174
+    71489.46661        0.12226143        0.02846584
+    71518.06240        0.05695876        0.02799828
+    71546.66962        0.08072677        0.02876799
+    71575.28829        0.14745644        0.02764613
+    71603.91840        0.11350971        0.02708160
+    71632.55997        0.11033041        0.02864697
+    71661.21300        0.07133289        0.02955214
+    71689.87748        0.07209985        0.03009635
+    71718.55343        0.09373532        0.02521447
+    71747.24085        0.07971067        0.02928526
+    71775.93975        0.11580898        0.02881976
+    71804.65013        0.10847583        0.02858169
+    71833.37199        0.03093352        0.03185909
+    71862.10533        0.07493459        0.02964302
+    71890.85018        0.06746412        0.02665334
+    71919.60652        0.07752078        0.03023697
+    71948.37436        0.09885833        0.02657644
+    71977.15371        0.06903483        0.02785760
+    72005.94457        0.08431790        0.02609402
+    72034.74695        0.03922192        0.02910996
+    72063.56085        0.02658386        0.03132104
+    72092.38627        0.07322297        0.02694256
+    72121.22323        0.09747396        0.02663467
+    72150.07172        0.09604907        0.02540898
+    72178.93174        0.01136404        0.03296281
+    72207.80332        0.05466798        0.03130947
+    72236.68644        0.12926429        0.02781375
+    72265.58111        0.05909192        0.02943246
+    72294.48735        0.07147319        0.03189374
+    72323.40514        0.10683484        0.02937124
+    72352.33450        0.08948762        0.02828545
+    72381.27544        0.07688952        0.02672439
+    72410.22795        0.04527130        0.02964686
+    72439.19204        0.12054931        0.02460766
+    72468.16771        0.08519559        0.02762837
+    72497.15498        0.06171879        0.03122804
+    72526.15384        0.05786332        0.02844293
+    72555.16430        0.08741907        0.02654421
+    72584.18637        0.10784884        0.02725105
+    72613.22005        0.07350492        0.02950107
+    72642.26533        0.09856618        0.02693312
+    72671.32224        0.11914698        0.03038314
+    72700.39077        0.07629192        0.02615587
+    72729.47092        0.08203412        0.02923388
+    72758.56271        0.08097592        0.02975011
+    72787.66614        0.11802375        0.02819184
+    72816.78120        0.09158707        0.02550176
+    72845.90792        0.09566916        0.02438233
+    72875.04628        0.06283767        0.02811620
+    72904.19630        0.07978247        0.02445529
+    72933.35798        0.09084244        0.02905191
+    72962.53132        0.07114546        0.02898132
+    72991.71633        0.08576254        0.03052518
+    73020.91302        0.09819502        0.02641524
+    73050.12138        0.11544273        0.02874792
+    73079.34143        0.09912740        0.02987428
+    73108.57317        0.04583768        0.02872600
+    73137.81660        0.06944542        0.03158583
+    73167.07173        0.06027116        0.02748309
+    73196.33855        0.04162976        0.02684125
+    73225.61709        0.08293597        0.02707591
+    73254.90734        0.12751534        0.02560418
+    73284.20930        0.06696758        0.02712972
+    73313.52298        0.05099596        0.02718851
+    73342.84839        0.08682651        0.02725518
+    73372.18553        0.14691045        0.02510840
+    73401.53441        0.04682335        0.02943624
+    73430.89502        0.03378240        0.02907347
+    73460.26738        0.08008280        0.03005405
+    73489.65148        0.08168802        0.02848894
+    73519.04735        0.07700986        0.02897371
+    73548.45496        0.04673696        0.03191156
+    73577.87435        0.01567654        0.03050486
+    73607.30550        0.07754276        0.02917421
+    73636.74842        0.09055491        0.02789238
+    73666.20312        0.04933635        0.03116780
+    73695.66960        0.05083352        0.02958442
+    73725.14787        0.06635232        0.02587194
+    73754.63793        0.06545003        0.02953469
+    73784.13978        0.10142043        0.02898649
+    73813.65344        0.05097861        0.02966886
+    73843.17890        0.08615318        0.02849640
+    73872.71617        0.09688110        0.02826435
+    73902.26526        0.05356810        0.02738675
+    73931.82616        0.07116011        0.02675390
+    73961.39889        0.05645924        0.03098893
+    73990.98345        0.08397239        0.02961427
+    74020.57985        0.08462748        0.02724299
+    74050.18808        0.10433492        0.02971158
+    74079.80815        0.07412365        0.03045981
+    74109.44008        0.05013426        0.02602752
+    74139.08385        0.10015924        0.02782749
+    74168.73949        0.09766896        0.03012742
+    74198.40698        0.06934892        0.03094469
+    74228.08634        0.02893284        0.02969060
+    74257.77758        0.08398070        0.02798069
+    74287.48069        0.07265867        0.03059111
+    74317.19568        0.10825071        0.02947022
+    74346.92256        0.06188758        0.02794567
+    74376.66133        0.13982164        0.02627416
+    74406.41199        0.09321594        0.02909803
+    74436.17456        0.05570985        0.03027989
+    74465.94903        0.10364222        0.02832014
+    74495.73541        0.08200593        0.02886759
+    74525.53370        0.05636945        0.02928140
+    74555.34392        0.11559403        0.02696744
+    74585.16605        0.10995107        0.02681309
+    74615.00012        0.04540771        0.03090210
+    74644.84612        0.07518651        0.03190694
+    74674.70406        0.11170228        0.03080823
+    74704.57394       -0.02283429        0.03241597
+    74734.45577        0.12792107        0.02837142
+    74764.34955        0.08128743        0.03058308
+    74794.25529        0.09008021        0.02842546
+    74824.17299        0.03803165        0.03107282
+    74854.10266        0.08184120        0.03362091
+    74884.04430        0.10502786        0.03092186
+    74913.99792        0.08222349        0.02958332
+    74943.96352        0.07159541        0.03171005
+    74973.94111        0.11815908        0.02895842
+    75003.93068        0.11138630        0.02808435
+    75033.93226        0.03717035        0.03188869
+    75063.94583        0.10718546        0.02928833
+    75093.97141        0.05422238        0.03304008
+    75124.00899        0.07159617        0.03301430
+    75154.05860        0.06960209        0.03296520
+    75184.12022        0.07451262        0.03369190
+    75214.19387        0.10689527        0.02732421
+    75244.27955        0.08651673        0.03115956
+    75274.37726        0.10626402        0.02995788
+    75304.48701        0.05551249        0.03256586
+    75334.60881        0.12554222        0.02663693
+    75364.74265        0.09081094        0.02674795
+    75394.88855        0.11279636        0.02892169
+    75425.04650        0.06522016        0.03112881
+    75455.21652        0.14522956        0.02671434
+    75485.39861        0.10662670        0.03006012
+    75515.59277        0.05932122        0.03102570
+    75545.79900        0.06246909        0.02723149
+    75576.01732        0.06820415        0.03320695
+    75606.24773        0.05574038        0.03404487
+    75636.49023        0.10676695        0.02966333
+    75666.74482        0.07500937        0.02928356
+    75697.01152        0.09786052        0.03014263
+    75727.29033        0.09105714        0.02931281
+    75757.58124        0.10458099        0.03051074
+    75787.88428        0.06419292        0.02985199
+    75818.19943        0.08758962        0.02938945
+    75848.52671        0.09979199        0.02778586
+    75878.86612        0.05768551        0.03242282
+    75909.21767        0.07596690        0.02772642
+    75939.58135        0.06037639        0.03136282
+    75969.95719        0.08818184        0.03104161
+    76000.34517        0.07620952        0.03262486
+    76030.74531        0.08984927        0.03371928
+    76061.15761        0.04067022        0.03464879
+    76091.58207        0.02273449        0.03027337
+    76122.01870        0.09201450        0.03065738
+    76152.46751        0.10809039        0.03054567
+    76182.92850        0.03933453        0.03219235
+    76213.40167        0.11178705        0.02857463
+    76243.88703        0.08055584        0.02956695
+    76274.38458        0.09320214        0.03000332
+    76304.89434        0.06198668        0.03093995
+    76335.41629       -0.01001489        0.03306013
+    76365.95046        0.07913965        0.03014616
+    76396.49684        0.04552950        0.03229181
+    76427.05544        0.06658635        0.03295735
+    76457.62626        0.07761910        0.02718175
+    76488.20931        0.10586170        0.02896658
+    76518.80460        0.09496221        0.02996601
+    76549.41212        0.07090814        0.02839148
+    76580.03188        0.09494420        0.02996032
+    76610.66390        0.07563891        0.03064263
+    76641.30816        0.06212593        0.02948648
+    76671.96468        0.06089996        0.03013230
+    76702.63347        0.03721975        0.03503838
+    76733.31452        0.10673191        0.02969597
+    76764.00785        0.06006980        0.03687009
+    76794.71345        0.09487808        0.02633782
+    76825.43134        0.14469929        0.02753966
+    76856.16151        0.12881489        0.02769897
+    76886.90397        0.08984909        0.03056720
+    76917.65874        0.04339804        0.02895053
+    76948.42580        0.05971113        0.03226862
+    76979.20517        0.03451099        0.03463246
+    77009.99685        0.03811112        0.02960215
+    77040.80085        0.13902857        0.03043706
+    77071.61717        0.09679239        0.03240848
+    77102.44582        0.11749550        0.02340781
+    77133.28680        0.07095050        0.02959070
+    77164.14011        0.03225576        0.03310056
+    77195.00577        0.05514544        0.03327838
+    77225.88377        0.09616975        0.03139631
+    77256.77412        0.13743608        0.02937487
+    77287.67683        0.05072595        0.03138010
+    77318.59190        0.11645468        0.02873443
+    77349.51934        0.06943012        0.03287744
+    77380.45915        0.10361149        0.02991063
+    77411.41133        0.10921069        0.03091930
+    77442.37590        0.08800686        0.03238233
+    77473.35285        0.05231300        0.02896368
+    77504.34219        0.08437132        0.03096738
+    77535.34392        0.06180229        0.03637397
+    77566.35806        0.06821701        0.02973712
+    77597.38461        0.08541644        0.03330371
+    77628.42356        0.03032228        0.03357876
+    77659.47493        0.12160146        0.02953765
+    77690.53872        0.07235952        0.03299527
+    77721.61493        0.11595651        0.02603836
+    77752.70358        0.07815993        0.02876810
+    77783.80466        0.12524735        0.02649061
+    77814.91818        0.09766288        0.02878171
+    77846.04415        0.05930943        0.03274407
+    77877.18257        0.09975331        0.03050013
+    77908.33344        0.09702128        0.02800418
+    77939.49677        0.05627018        0.03199311
+    77970.67257        0.07362975        0.03539742
+    78001.86084        0.09193357        0.03105580
+    78033.06159        0.10779469        0.03163759
+    78064.27481        0.12987221        0.03015402
+    78095.50052        0.15383532        0.03027163
+    78126.73872        0.09974697        0.03211021
+    78157.98942        0.08750272        0.03092264
+    78189.25261        0.12259410        0.02741358
+    78220.52831        0.06735929        0.03388989
+    78251.81653        0.08889481        0.03022087
+    78283.11725        0.10668792        0.03239507
+    78314.43050        0.05914316        0.03070454
+    78345.75627        0.08603126        0.03317013
+    78377.09457        0.02952972        0.03481518
+    78408.44541        0.05303587        0.03280906
+    78439.80879        0.15602282        0.02969479
+    78471.18471        0.09244163        0.02717924
+    78502.57319        0.06330880        0.03399449
+    78533.97422        0.04189739        0.03258728
+    78565.38781        0.07973211        0.02934676
+    78596.81396        0.10243107        0.03183558
+    78628.25269        0.06683024        0.03137041
+    78659.70399        0.10687444        0.02972954
+    78691.16787        0.06250407        0.03133651
+    78722.64434        0.06727888        0.03158100
+    78754.13339        0.07111926        0.03100227
+    78785.63505        0.10191862        0.03061632
+    78817.14930        0.08141682        0.03384766
+    78848.67616        0.07482740        0.02796657
+    78880.21563        0.10650599        0.03018840
+    78911.76772        0.10602803        0.03345791
+    78943.33242        0.09040480        0.03524867
+    78974.90976        0.05537918        0.03774054
+    79006.49972        0.08454922        0.03213058
+    79038.10232        0.09188132        0.03247000
+    79069.71756        0.08911629        0.02991051
+    79101.34545        0.07738257        0.02949892
+    79132.98599        0.07057734        0.03349772
+    79164.63918        0.06433065        0.02997921
+    79196.30504        0.07567231        0.03380696
+    79227.98356        0.07862632        0.03235605
+    79259.67475        0.09464496        0.03217570
+    79291.37862        0.15358092        0.03106247
+    79323.09517        0.03468828        0.03416587
+    79354.82441        0.13427342        0.03211873
+    79386.56634        0.03721134        0.03434724
+    79418.32097        0.06700008        0.02762759
+    79450.08830        0.10798704        0.03120270
+    79481.86833        0.04988535        0.03327817
+    79513.66108        0.07324258        0.03332674
+    79545.46654        0.04648601        0.03234845
+    79577.28473        0.12141692        0.03263275
+    79609.11564        0.04916215        0.03645823
+    79640.95929        0.06665046        0.03553473
+    79672.81567        0.06972859        0.03789947
+    79704.68480        0.13584711        0.03483204
+    79736.56668        0.10845520        0.03133798
+    79768.46130        0.07737610        0.03275597
+    79800.36869        0.10472919        0.03210208
+    79832.28883        0.06729498        0.03408717
+    79864.22175        0.08938747        0.03489675
+    79896.16744        0.12213541        0.03282586
+    79928.12590        0.07032019        0.03260832
+    79960.09716        0.07732791        0.03454661
+    79992.08119        0.07000887        0.03430581
+    80024.07803        0.08908596        0.03251462
+    80056.08766        0.04672061        0.03817192
+    80088.11009        0.01620189        0.03642591
+    80120.14534        0.04571753        0.03741636
+    80152.19340        0.04470039        0.03663299
+    80184.25427        0.06131436        0.03486104
+    80216.32797        0.11033886        0.03249981
+    80248.41451        0.06770642        0.03429558
+    80280.51387        0.07696491        0.03211599
+    80312.62608        0.07063723        0.03275533
+    80344.75113       -0.05216248        0.03652075
+    80376.88903        0.10258562        0.02953962
+    80409.03978        0.07983663        0.03640476
+    80441.20340        0.12067677        0.03300558
+    80473.37988        0.07009400        0.03613667
+    80505.56923        0.06273925        0.03591939
+    80537.77146        0.06962069        0.03375288
+    80569.98657        0.09264628        0.03700696
+    80602.21456        0.11301835        0.03617136
+    80634.45545        0.07810790        0.03062233
+    80666.70923        0.10305660        0.03164273
+    80698.97592        0.12638265        0.02883142
+    80731.25551        0.13562867        0.03294494
+    80763.54801        0.09458825        0.03646935
+    80795.85343        0.06054600        0.03187945
+    80828.17177        0.10597973        0.03187123
+    80860.50304        0.12148132        0.03066294
+    80892.84724        0.10364825        0.03182439
+    80925.20438        0.09434755        0.03413486
+    80957.57446        0.11887485        0.03246731
+    80989.95749        0.11794944        0.03154937
+    81022.35347        0.11724811        0.03505960
+    81054.76241        0.06457317        0.03315765
+    81087.18432        0.08334784        0.03476115
+    81119.61919        0.11143538        0.02950012
+    81152.06704        0.08003868        0.03388314
+    81184.52787        0.10740428        0.03229964
+    81217.00168        0.11312085        0.03069770
+    81249.48848        0.10892618        0.03338856
+    81281.98827        0.12129273        0.03115461
+    81314.50107        0.08135448        0.03246521
+    81347.02687        0.07111081        0.03818388
+    81379.56568        0.05160456        0.03421922
+    81412.11751        0.09339120        0.03408595
+    81444.68235        0.02283536        0.04080117
+    81477.26023        0.09994787        0.03069149
+    81509.85113        0.10194498        0.03465743
+    81542.45507        0.10045917        0.03084850
+    81575.07205        0.10808349        0.03318620
+    81607.70208        0.07082850        0.03550997
+    81640.34516        0.08077226        0.03317489
+    81673.00130        0.12066481        0.03287281
+    81705.67050        0.07899903        0.03594603
+    81738.35277        0.11188619        0.03157071
+    81771.04811        0.08213814        0.03427468
+    81803.75653        0.09418866        0.03380269
+    81836.47803        0.07228152        0.03661302
+    81869.21262        0.06132152        0.03793474
+    81901.96031        0.08407242        0.03142188
+    81934.72109        0.04335235        0.03554287
+    81967.49498        0.04138247        0.03807315
+    82000.28198        0.11886930        0.03563875
+    82033.08209        0.08167509        0.03606407
+    82065.89532        0.09375124        0.03562755
+    82098.72168        0.08810856        0.03719959
+    82131.56117        0.10374563        0.03326286
+    82164.41380        0.02811205        0.03319421
+    82197.27956        0.10882226        0.03539901
+    82230.15847        0.06782160        0.03482569
+    82263.05054        0.09507844        0.03851792
+    82295.95576        0.06853068        0.03306636
+    82328.87414        0.01929386        0.04263445
+    82361.80569        0.12461597        0.03039672
+    82394.75041        0.04901168        0.03812069
+    82427.70831        0.04110813        0.03794408
+    82460.67939        0.10281356        0.03576558
+    82493.66367        0.09614366        0.03653671
+    82526.66113        0.09866964        0.03852049
+    82559.67180        0.10503869        0.02994481
+    82592.69566        0.10714402        0.03435245
+    82625.73274        0.04770745        0.03697955
+    82658.78304        0.09474647        0.03694333
+    82691.84655        0.09316677        0.03300104
+    82724.92329        0.09409338        0.03613919
+    82758.01326        0.12162617        0.03219791
+    82791.11646        0.09384751        0.03324217
+    82824.23291        0.11502214        0.03312073
+    82857.36260        0.05636457        0.03972250
+    82890.50555        0.10342838        0.03684078
+    82923.66175        0.03639478        0.03630339
+    82956.83121        0.07961170        0.03180181
+    82990.01395        0.09203894        0.03347342
+    83023.20995        0.07214520        0.03481039
+    83056.41924        0.07828380        0.03296695
+    83089.64180        0.06437227        0.03240219
+    83122.87766        0.14076358        0.03851666
+    83156.12681        0.07430699        0.03895835
+    83189.38926        0.03719014        0.03460413
+    83222.66502        0.09502663        0.03590016
+    83255.95408        0.09346575        0.03687068
+    83289.25647        0.08158323        0.03329089
+    83322.57217        0.09760300        0.03805714
+    83355.90120        0.02278642        0.03623738
+    83389.24356        0.08366689        0.03759565
+    83422.59926        0.09103428        0.03691717
+    83455.96829        0.06734317        0.03499233
+    83489.35068        0.09215568        0.03278542
+    83522.74642        0.15973108        0.03763773
+    83556.15552        0.09424738        0.03717902
+    83589.57798        0.08748981        0.03593394
+    83623.01381        0.07621795        0.03551890
+    83656.46302        0.01801892        0.03933393
+    83689.92561        0.07304599        0.03750835
+    83723.40158        0.14004451        0.03390725
+    83756.89094        0.14968125        0.02963296
+    83790.39369        0.09609026        0.03847435
+    83823.90985        0.10570650        0.03476110
+    83857.43941        0.11177635        0.04007859
+    83890.98239        0.08446307        0.04008822
+    83924.53878        0.12372498        0.03338947
+    83958.10860        0.07653865        0.03793691
+    83991.69184        0.03809046        0.03544183
+    84025.28852        0.04367433        0.04257831
+    84058.89863        0.03774044        0.03764568
+    84092.52219        0.07127888        0.03797478
+    84126.15920        0.14162517        0.03087161
+    84159.80967        0.12572966        0.03143322
+    84193.47359        0.06422432        0.03894890
+    84227.15098        0.05950921        0.03457297
+    84260.84184        0.06865705        0.04027395
+    84294.54618        0.12834889        0.03855596
+    84328.26399        0.11153305        0.03583242
+    84361.99530        0.03458310        0.04223620
+    84395.74010        0.13369641        0.03222145
+    84429.49839        0.08525259        0.03720940
+    84463.27019        0.05311763        0.04125821
+    84497.05550        0.10525698        0.03708531
+    84530.85432        0.09014631        0.03874529
+    84564.66667        0.06947482        0.03803671
+    84598.49253        0.03820949        0.04311083
+    84632.33193        0.07534478        0.04056384
+    84666.18486        0.16133223        0.03753075
+    84700.05134        0.16497677        0.02889688
+    84733.93136        0.10612190        0.04195515
+    84767.82493        0.11037736        0.03794281
+    84801.73206        0.03619872        0.04160808
+    84835.65275        0.02992092        0.03591414
+    84869.58701        0.07794982        0.03438638
+    84903.53485        0.12866091        0.03541372
+    84937.49626        0.13367590        0.03443820
+    84971.47126        0.02423470        0.04147333
+    85005.45985        0.02298891        0.04041944
+    85039.46203        0.03784661        0.04310121
+    85073.47782        0.07578318        0.04037451
+    85107.50721        0.09000615        0.03988895
+    85141.55021        0.08888372        0.03879424
+    85175.60683        0.11479528        0.03517617
+    85209.67707        0.05959348        0.03891576
+    85243.76095        0.07213885        0.03949523
+    85277.85845        0.11687628        0.03671320
+    85311.96959       -0.01504819        0.04394838
+    85346.09438        0.09219451        0.04375776
+    85380.23282        0.06788519        0.04081444
+    85414.38491        0.06884329        0.04416461
+    85448.55067        0.01103366        0.04106125
+    85482.73009        0.06156007        0.04305624
+    85516.92318        0.09677518        0.03640618
+    85551.12995        0.03067453        0.03983918
+    85585.35040        0.04081919        0.03794692
+    85619.58454        0.05314519        0.04091943
+    85653.83237        0.07272166        0.03291507
+    85688.09391        0.07959571        0.03982285
+    85722.36914        0.06883074        0.03825680
+    85756.65809        0.08647174        0.04029735
+    85790.96075        0.05116626        0.03895944
+    85825.27714        0.07397725        0.03999172
+    85859.60725        0.16807444        0.03774158
+    85893.95109        0.13620489        0.04262393
+    85928.30867        0.08621091        0.03952785
+    85962.68000        0.11037233        0.03537883
+    85997.06507        0.10485877        0.03919073
+    86031.46389        0.11024263        0.03819362
+    86065.87648        0.11370422        0.03839491
+    86100.30283        0.04966903        0.04322825
+    86134.74295        0.07993602        0.04208893
+    86169.19685        0.00386743        0.04720977
+    86203.66453        0.08777621        0.03741067
+    86238.14599        0.09774490        0.03786999
+    86272.64125        0.11762926        0.03874538
+    86307.15031        0.03721424        0.04051124
+    86341.67317        0.06892375        0.04056733
+    86376.20984        0.01904174        0.04680313
+    86410.76032        0.06178401        0.04273219
+    86445.32463       -0.00687915        0.04362999
+    86479.90276        0.12828482        0.03657190
+    86514.49472        0.08471832        0.03737220
+    86549.10051        0.05852494        0.04264034
+    86583.72016        0.05136731        0.04470766
+    86618.35364        0.02322111        0.05017046
+    86653.00098        0.13596874        0.04089222
+    86687.66218        0.03679089        0.04306327
+    86722.33725        0.11208731        0.03592855
+    86757.02618        0.06871573        0.04318468
+    86791.72900        0.05965110        0.04633296
+    86826.44569        0.10806850        0.04119666
+    86861.17627        0.09545420        0.03813028
+    86895.92074        0.11237982        0.03893405
+    86930.67910        0.09168601        0.03377149
+    86965.45138        0.03168391        0.03831105
+    87000.23756        0.05821281        0.04215141
+    87035.03765        0.10213068        0.03750202
+    87069.85167        0.11212759        0.04077941
+    87104.67961        0.03298216        0.04283626
+    87139.52148        0.09103369        0.03879903
+    87174.37729        0.08653333        0.03730300
+    87209.24704        0.03597047        0.03947135
+    87244.13074        0.04304561        0.03993075
+    87279.02839        0.08756859        0.03774928
+    87313.94000        0.11291732        0.03601712
+    87348.86558        0.06162881        0.03829183
+    87383.80512        0.11106008        0.04060983
+    87418.75864        0.10729732        0.04330553
+    87453.72615        0.05042631        0.04377137
+    87488.70764        0.05736419        0.03699234
+    87523.70312        0.04299871        0.04630261
+    87558.71260        0.04280554        0.03956205
+    87593.73609        0.11887501        0.04689421
+    87628.77358        0.04988202        0.04935990
+    87663.82509        0.13947517        0.04660565
+    87698.89062        0.08790297        0.04330636
+    87733.97018        0.06947106        0.04536602
+    87769.06377        0.09254225        0.04082361
+    87804.17139        0.05681730        0.04639695
+    87839.29306        0.09511168        0.03960135
+    87874.42878        0.14574216        0.04477929
+    87909.57855        0.08766053        0.04244361
+    87944.74238        0.04852142        0.04514749
+    87979.92028        0.06240219        0.04153282
+    88015.11225        0.09996629        0.04025916
+    88050.31829        0.10698618        0.04365682
+    88085.53842        0.10879899        0.04525334
+    88120.77263        0.08466637        0.04577020
+    88156.02094        0.09571439        0.03881280
+    88191.28335        0.10340619        0.03926519
+    88226.55986        0.15160260        0.04457345
+    88261.85049        0.05181375        0.04484336
+    88297.15523        0.08322032        0.04020719
+    88332.47409        0.04516935        0.04174675
+    88367.80708        0.05219734        0.04517534
+    88403.15420        0.02900345        0.04718823
+    88438.51546        0.01327880        0.04941645
+    88473.89087        0.05410471        0.04696434
+    88509.28043        0.10328622        0.04159619
+    88544.68414        0.08216646        0.04228324
+    88580.10201        0.06256814        0.04455817
+    88615.53405        0.03465960        0.04920212
+    88650.98027        0.06490077        0.04319581
+    88686.44066        0.05285714        0.04574637
+    88721.91524        0.00575213        0.04956637
+    88757.40400        0.13392268        0.04624071
+    88792.90696        0.01565284        0.04865246
+    88828.42413        0.05112190        0.05399105
+    88863.95550        0.10582854        0.04363857
+    88899.50108        0.10209626        0.04351395
+    88935.06088        0.07690167        0.04401353
+    88970.63490        0.12318810        0.04604127
+    89006.22316        0.08866779        0.04463150
+    89041.82565        0.01578115        0.04905131
+    89077.44238        0.10604631        0.04700853
+    89113.07335        0.09850754        0.04678243
+    89148.71858        0.12622786        0.03643978
+    89184.37807        0.10187600        0.04241779
+    89220.05182        0.08098957        0.03980933
+    89255.73984        0.08152882        0.04798646
+    89291.44214        0.08239269        0.04508203
+    89327.15871        0.02165005        0.05159682
+    89362.88958        0.10055541        0.03549538
+    89398.63473        0.06556249        0.04301070
+    89434.39419        0.06637449        0.03963111
+    89470.16795        0.06520015        0.04643256
+    89505.95601        0.03283998        0.04825354
+    89541.75840       -0.01327004        0.04795657
+    89577.57510        0.10746387        0.03823059
+    89613.40613        0.08162918        0.04742398
+    89649.25149        0.07037759        0.04372771
+    89685.11119        0.04006615        0.04407146
+    89720.98524        0.15599407        0.04081825
+    89756.87363        0.02742049        0.04684254
+    89792.77638        0.18827678        0.04241224
+    89828.69349        0.12280413        0.04619809
+    89864.62497        0.19082462        0.04077710
+    89900.57082        0.06767555        0.04863593
+    89936.53105        0.10926479        0.04400392
+    89972.50566        0.08517843        0.04290899
+    90008.49466       -0.00367272        0.05035109
+    90044.49806        0.11245955        0.03878455
+    90080.51586        0.11758134        0.04447330
+    90116.54806        0.04102926        0.04089206
+    90152.59468        0.08079732        0.04624315
+    90188.65572        0.10180565        0.04388663
+    90224.73118       -0.02159112        0.04840708
+    90260.82108        0.11129692        0.04933603
+    90296.92540        0.04407674        0.04819537
+    90333.04417        0.07508563        0.04801395
+    90369.17739        0.08922669        0.05027862
+    90405.32506        0.07442906        0.04310469
+    90441.48719        0.07462901        0.04322049
+    90477.66379        0.08547913        0.04201611
+    90513.85485        0.03719266        0.04526670
+    90550.06040        0.08461019        0.04915585
+    90586.28042        0.09628947        0.04470712
+    90622.51493        0.11741077        0.04579601
+    90658.76394        0.05330002        0.04096269
+    90695.02744        0.14457705        0.03976156
+    90731.30545        0.08821828        0.04826956
+    90767.59798        0.09576236        0.04334368
+    90803.90502        0.19783013        0.04456428
+    90840.22658        0.09009986        0.04124281
+    90876.56267        0.03807056        0.04633515
+    90912.91329        0.04763975        0.05186041
+    90949.27846        0.08968787        0.04518065
+    90985.65817       -0.02823931        0.05662824
+    91022.05243        0.07033539        0.04614185
+    91058.46125        0.05126653        0.05520571
+    91094.88464        0.03147092        0.04793672
+    91131.32259        0.07459105        0.04634565
+    91167.77512        0.04667320        0.04686548
+    91204.24223        0.10077512        0.04389771
+    91240.72393        0.12380968        0.04682908
+    91277.22022        0.06797358        0.04787995
+    91313.73111        0.06627449        0.04607151
+    91350.25660        0.13699493        0.04755944
+    91386.79670        0.05726259        0.04934560
+    91423.35142        0.08377707        0.04712774
+    91459.92076        0.15229487        0.04092976
+    91496.50473        0.11084428        0.04494806
+    91533.10333        0.07057589        0.04107324
+    91569.71657        0.00507214        0.04199651
+    91606.34446        0.04975189        0.05000363
+    91642.98700       -0.00581615        0.05300745
+    91679.64419        0.15712245        0.04795124
+    91716.31605        0.05113688        0.04699936
+    91753.00258        0.09123560        0.04903104
+    91789.70378        0.05452229        0.05469040
+    91826.41966        0.03425828        0.05573776
+    91863.15023        0.11280542        0.04862844
+    91899.89549        0.14951879        0.03512521
+    91936.65544        0.01542599        0.05017426
+    91973.43011        0.03620107        0.04935837
+    92010.21948        0.05897516        0.05051864
+    92047.02357        0.01100366        0.05037476
+    92083.84238        0.14853129        0.05284168
+    92120.67591        0.13860631        0.04668083
+    92157.52418        0.11679768        0.04122880
+    92194.38719        0.08723996        0.05235711
+    92231.26495        0.07900556        0.04820091
+    92268.15745        0.05267221        0.05293874
+    92305.06472        0.08668951        0.04670028
+    92341.98674       -0.05596165        0.05929264
+    92378.92354        0.08281589        0.05637155
+    92415.87511        0.18104306        0.04737270
+    92452.84146        0.05243685        0.05708250
+    92489.82259        0.10070522        0.05182337
+    92526.81852        0.01246966        0.05732648
+    92563.82925        0.04321755        0.05683190
+    92600.85478        0.08678123        0.05123192
+    92637.89512        0.08399756        0.05300638
+    92674.95028        0.19534930        0.04813942
+    92712.02026        0.09655953        0.04746253
+    92749.10507        0.08709105        0.04691659
+    92786.20471        0.16529969        0.03951225
+    92823.31919        0.15220350        0.04570311
+    92860.44852        0.07726347        0.04613273
+    92897.59270        0.07437709        0.04796342
+    92934.75174        0.11736806        0.05177514
+    92971.92564        0.17725224        0.05053171
+    93009.11441        0.14670841        0.05093159
+    93046.31805        0.04548444        0.05003141
+    93083.53658        0.29244095        0.04967292
+    93120.77000        0.15901052        0.05109721
+    93158.01830        0.27133665        0.05572961
+    93195.28151        0.30816777        0.05010219
+    93232.55962        0.35162585        0.05540951
+    93269.85265        0.38226584        0.05655238
+    93307.16059        0.38266949        0.06120676
+    93344.48345        0.47648226        0.06153243
+    93381.82125        0.71489758        0.07466846
+    93419.17397        0.89117362        0.08194742
+    93456.54164        1.13536680        0.08616380
+    93493.92426        1.23651615        0.08868376
+    93531.32183        1.44991027        0.08464477
+    93568.73436        1.51519623        0.10001090
+    93606.16185        1.93850690        0.10384841
+    93643.60432        2.10982250        0.11077634
+    93681.06176        2.36699193        0.11580785
+    93718.53418        2.63346376        0.11540712
+    93756.02160        2.84561448        0.12092913
+    93793.52401        2.85877744        0.12116684
+    93831.04142        2.91110988        0.11832408
+    93868.57383        2.94845702        0.12201630
+    93906.12126        3.13505834        0.12089373
+    93943.68371        2.92291148        0.12514139
+    93981.26118        2.67693683        0.11684302
+    94018.85369        2.46637785        0.11432940
+    94056.46123        2.43185566        0.11281527
+    94094.08381        1.97936269        0.10526819
+    94131.72145        1.83199889        0.10384831
+    94169.37414        1.69930252        0.09451855
+    94207.04189        1.43795752        0.09021243
+    94244.72470        1.24889991        0.08332799
+    94282.42259        0.90354954        0.07835765
+    94320.13556        0.86459213        0.07488951
+    94357.86362        0.81613002        0.07345077
+    94395.60676        0.67403341        0.06503643
+    94433.36500        0.44452610        0.06691603
+    94471.13835        0.33696373        0.06184749
+    94508.92681        0.43007874        0.05456699
+    94546.73038        0.32917739        0.05861585
+    94584.54907        0.29039580        0.05391953
+    94622.38289        0.13519879        0.05086088
+    94660.23184        0.16740386        0.05724570
+    94698.09593        0.08526589        0.05568035
+    94735.97517        0.09753006        0.05113177
+    94773.86956        0.13237177        0.05601467
+    94811.77911        0.12767050        0.04700292
+    94849.70382        0.15444106        0.04828510
+    94887.64370        0.06784341        0.05520867
+    94925.59876        0.05268873        0.05293244
+    94963.56900        0.07946384        0.05408986
+    95001.55443        0.09811657        0.05143927
+    95039.55505        0.20125414        0.04266757
+    95077.57087        0.10093736        0.04984381
+    95115.60190       -0.05665023        0.05875456
+    95153.64814        0.10751717        0.05205783
+    95191.70960        0.05494692        0.05511634
+    95229.78628        0.10660507        0.04643725
+    95267.87820        0.06738890        0.05043238
+    95305.98535        0.05957081        0.05542856
+    95344.10774        0.11768804        0.04900140
+    95382.24539        0.08887619        0.04567649
+    95420.39829        0.16431343        0.04318524
+    95458.56645        0.12309268        0.04533978
+    95496.74987        0.06306782        0.05036818
+    95534.94857        0.09683831        0.03952920
+    95573.16255        0.06755770        0.05055870
+    95611.39182        0.12793437        0.05490053
+    95649.63637        0.09713939        0.04998837
+    95687.89623        0.08248816        0.04324008
+    95726.17139        0.12108292        0.04307561
+    95764.46185        0.07722632        0.04711540
+    95802.76764        0.11920934        0.04074134
+    95841.08875        0.09973537        0.04818629
+    95879.42518        0.06788915        0.05908567
+    95917.77695        0.02326440        0.04449012
+    95956.14406        0.04652575        0.04135062
+    95994.52652        0.09794790        0.04615183
+    96032.92433        0.11337177        0.04887259
+    96071.33750       -0.01425253        0.05066137
+    96109.76604        0.09428801        0.04172845
+    96148.20994        0.11874350        0.04517415
+    96186.66923        0.11690078        0.04295623
+    96225.14389        0.06843598        0.04682468
+    96263.63395        0.00377643        0.05152897
+    96302.13940        0.14516665        0.05039636
+    96340.66026        0.10718492        0.04668983
+    96379.19652        0.02896877        0.05079854
+    96417.74820        0.13234658        0.04587072
+    96456.31530        0.10712787        0.04666498
+    96494.89783        0.13676505        0.04606072
+    96533.49579        0.08976252        0.04147594
+    96572.10919        0.01165030        0.04602800
+    96610.73803        0.11786440        0.04907483
+    96649.38232        0.13287158        0.04153201
+    96688.04208        0.00451863        0.04768813
+    96726.71729        0.11041234        0.04031444
+    96765.40798        0.09732179        0.05008223
+    96804.11414       -0.01689978        0.05243228
+    96842.83579        0.01882145        0.04439777
+    96881.57292       -0.07903887        0.05516427
+    96920.32555        0.13187693        0.04988039
+    96959.09368        0.15421087        0.04055836
+    96997.87732        0.05320728        0.04413927
+    97036.67647        0.06041183        0.04234655
+    97075.49114        0.04534058        0.04987317
+    97114.32134        0.09599741        0.04835911
+    97153.16707        0.13950457        0.04844617
+    97192.02833        0.11949468        0.04545992
+    97230.90515        0.13386716        0.04184320
+    97269.79751       -0.01170481        0.04922734
+    97308.70543        0.07860879        0.04334700
+    97347.62891        0.06798194        0.05087618
+    97386.56796        0.03434039        0.04734588
+    97425.52259        0.02902727        0.05090113
+    97464.49280        0.11515147        0.04064769
+    97503.47859        0.09432470        0.04174469
+    97542.47999        0.11219710        0.04264529
+    97581.49698        0.13114120        0.04960212
+    97620.52958        0.03143805        0.04877883
+    97659.57779        0.10273047        0.04197864
+    97698.64162        0.06080597        0.04807766
+    97737.72108        0.10912486        0.05376156
+    97776.81616       -0.00146896        0.05423667
+    97815.92689        0.11287940        0.04441533
+    97855.05326        0.06156341        0.05328142
+    97894.19528       -0.03960253        0.05413674
+    97933.35296        0.14426832        0.04164775
+    97972.52630       -0.00257223        0.04852935
+    98011.71531        0.14477030        0.03699504
+    98050.92000        0.08489053        0.04680858
+    98090.14037        0.02656435        0.04787877
+    98129.37642        0.05564593        0.04728724
+    98168.62817        0.10306102        0.04358234
+    98207.89563        0.12351941        0.05201661
+    98247.17878        0.06240902        0.04550192
+    98286.47765        0.07404381        0.05321257
+    98325.79225        0.12514688        0.04025117
+    98365.12256        0.13373245        0.04066767
+    98404.46861        0.09451500        0.04863785
+    98443.83040        0.03609340        0.05303401
+    98483.20793        0.12265877        0.03766205
+    98522.60121        0.07416764        0.04936353
+    98562.01026       -0.06387298        0.05687624
+    98601.43506        0.04098706        0.04956009
+    98640.87563        0.15609150        0.04361031
+    98680.33198        0.04812472        0.05632937
+    98719.80412        0.07695410        0.04357588
+    98759.29204        0.05448748        0.04630280
+    98798.79575       -0.00070499        0.04918039
+    98838.31527        0.05685291        0.04438913
+    98877.85060        0.11676928        0.03692664
+    98917.40174        0.06029740        0.04815564
+    98956.96870        0.17241859        0.03997296
+    98996.55149        0.08380415        0.03722415
+    99036.15011        0.01039078        0.04756907
+    99075.76457        0.11548988        0.04108587
+    99115.39487        0.04896032        0.04920808
+    99155.04103        0.10176412        0.04432852
+    99194.70305        0.08208070        0.04525925
+    99234.38093        0.04780372        0.04358886
+    99274.07468        0.10483203        0.03827693
+    99313.78431        0.07237259        0.03866697
+    99353.50983        0.09731510        0.04404647
+    99393.25123       -0.02457417        0.04933615
+    99433.00853       -0.04238335        0.05191729
+    99472.78173        0.07409770        0.04085946
+    99512.57085        0.11429245        0.04481799
+    99552.37587        0.10319511        0.04612901
+    99592.19682        0.13050664        0.04909572
+    99632.03370        0.08848680        0.04349449
+    99671.88652       -0.04720643        0.05469726
+    99711.75527        0.12917971        0.04350607
+    99751.63997        0.06278551        0.04214289
+    99791.54063        0.07197004        0.03845190
+    99831.45725       -0.02691288        0.05062688
+    99871.38983        0.04074675        0.04486230
+    99911.33838        0.09915491        0.04193052
+    99951.30292        0.08213247        0.04104733
+    99991.28344        0.02796926        0.04421338
+   100031.27995        0.05662110        0.03968939
+   100071.29247        0.08209093        0.04102657
+   100111.32098        0.01275066        0.04534676
+   100151.36551        0.07114075        0.04247697
+   100191.42606       -0.02759215        0.05374997
+   100231.50263        0.04676257        0.04695521
+   100271.59523        0.07301320        0.04454500
+   100311.70387        0.03476644        0.04271131
+   100351.82855       -0.01844100        0.05107259
+   100391.96928        0.06112905        0.04008768
+   100432.12607        0.03416685        0.04658480
+   100472.29892        0.08443086        0.04339188
+   100512.48784        0.04851444        0.03954653
+   100552.69283        0.02572589        0.04636755
+   100592.91391       -0.00069973        0.04881353
+   100633.15108        0.08306833        0.04151505
+   100673.40434        0.05951267        0.05150655
+   100713.67370       -0.02796507        0.05447644
+   100753.95917        0.13395123        0.03790211
+   100794.26075        0.01582995        0.05312461
+   100834.57846       -0.02802621        0.05459553
+   100874.91229        0.03634343        0.04897447
+   100915.26225        0.08635390        0.04942338
+   100955.62836        0.09030364        0.03996511
+   100996.01061        0.07302218        0.03901403
+   101036.40901        0.03776343        0.04139634
+   101076.82358        0.04385753        0.04371086
+   101117.25431        0.05497010        0.04224619
+   101157.70121        0.08617968        0.04932366
+   101198.16429        0.07823221        0.04530724
+   101238.64355        0.02978116        0.05816948
+   101279.13901        0.07739669        0.04884092
+   101319.65067        0.05656237        0.04416228
+   101360.17853        0.05579208        0.04779200
+   101400.72260        0.14858940        0.03629022
+   101441.28289        0.09741027        0.04408956
+   101481.85940        0.14077051        0.04227005
+   101522.45214        0.02883966        0.04053040
+   101563.06113        0.09527362        0.04187635
+   101603.68635        0.02734971        0.04795939
+   101644.32782        0.05355088        0.04550689
+   101684.98556        0.09916825        0.04193616
+   101725.65955        0.11250089        0.03844864
+   101766.34981       -0.02330634        0.05383017
+   101807.05635        0.04168895        0.05003934
+   101847.77918        0.01695680        0.04543869
+   101888.51829        0.04906551        0.04509559
+   101929.27369        0.03635884        0.04449244
+   101970.04540        0.01518742        0.04347750
+   102010.83342        0.08543455        0.04497282
+   102051.63776        0.13877392        0.04564461
+   102092.45841        0.09537210        0.03744124
+   102133.29539        0.10317821        0.04205323
+   102174.14871        0.08376709        0.04305074
+   102215.01837        0.06186292        0.04575694
+   102255.90438        0.10743772        0.04227415
+   102296.80674        0.07101513        0.04240196
+   102337.72546        0.09603940        0.03273329
+   102378.66055       -0.00069045        0.04816602
+   102419.61202        0.13328225        0.03947156
+   102460.57986        0.05427414        0.05045511
+   102501.56409        0.01691414        0.04532436
+   102542.56472        0.09854784        0.04167381
+   102583.58175        0.09183171        0.04326995
+   102624.61518        0.07669825        0.04441887
+   102665.66503        0.05736358        0.04535585
+   102706.73129        0.01444781        0.04699265
+   102747.81398        0.06131518        0.03538405
+   102788.91311        0.04057767        0.04467613
+   102830.02867        0.00248437        0.04288851
+   102871.16069        0.01451544        0.04721258
+   102912.30915       -0.00671558        0.04631549
+   102953.47407        0.04861013        0.04885610
+   102994.65546        0.06466331        0.04424336
+   103035.85333        0.17183120        0.03520757
+   103077.06767        0.09370439        0.03980837
+   103118.29849       -0.01283007        0.04450425
+   103159.54581       -0.05106589        0.05169642
+   103200.80963        0.01396634        0.05116320
+   103242.08996        0.06697691        0.04655980
+   103283.38679        0.03621684        0.04880389
+   103324.70015        0.10653553        0.04473961
+   103366.03003        0.06100185        0.04447597
+   103407.37644        0.09865214        0.04031212
+   103448.73939        0.05306215        0.03997922
+   103490.11888        0.11136362        0.04092155
+   103531.51493        0.05291756        0.03987028
+   103572.92754        0.08349708        0.03708776
+   103614.35671        0.05447732        0.04186747
+   103655.80245        0.08665529        0.04139793
+   103697.26477        0.12219143        0.04498575
+   103738.74368        0.10806644        0.03814673
+   103780.23918        0.12148327        0.04472504
+   103821.75127        0.08320804        0.04276343
+   103863.27997        0.05775895        0.04137543
+   103904.82528        0.06421425        0.03958701
+   103946.38721        0.05984624        0.03924643
+   103987.96577        0.10787862        0.03964095
+   104029.56096        0.12174860        0.04219751
+   104071.17278        0.13211690        0.04070456
+   104112.80125        0.11666445        0.03090777
+   104154.44637        0.09858600        0.03882026
+   104196.10815        0.12313847        0.04005375
+   104237.78659        0.12370154        0.03593086
+   104279.48171        0.12123947        0.03789613
+   104321.19350        0.03049018        0.04644282
+   104362.92198        0.00583692        0.04535341
+   104404.66715        0.09598729        0.04059100
+   104446.42901        0.09128797        0.04410500
+   104488.20758        0.05911517        0.03876701
+   104530.00287        0.01516468        0.05089197
+   104571.81487        0.05728523        0.04957876
+   104613.64359        0.04981325        0.04603877
+   104655.48905        0.06901531        0.04527585
+   104697.35125        0.10919605        0.04546562
+   104739.23019        0.02337608        0.04336615
+   104781.12588        0.01015527        0.04649088
+   104823.03833        0.08135466        0.04065860
+   104864.96755       -0.01755956        0.04723561
+   104906.91353        0.07187607        0.04783834
+   104948.87630        0.05400946        0.04150790
+   104990.85585        0.12090323        0.03888628
+   105032.85219        0.04001125        0.04838017
+   105074.86533        0.10347291        0.04217334
+   105116.89528        0.13583570        0.04185031
+   105158.94204        0.04260225        0.04686110
+   105201.00561        0.06890426        0.04443417
+   105243.08601        0.11724221        0.03884670
+   105285.18325        0.07995868        0.04307432
+   105327.29732        0.00179096        0.04685484
+   105369.42824        0.07924901        0.04678522
+   105411.57601        0.08598694        0.04526360
+   105453.74064        0.09164633        0.03740985
+   105495.92214        0.13352095        0.04374112
+   105538.12051        0.11891725        0.04101165
+   105580.33576        0.01633620        0.04917730
+   105622.56789        0.01774227        0.04185211
+   105664.81692        0.04856882        0.04881458
+   105707.08284        0.00532867        0.05030002
+   105749.36568        0.05167527        0.04345505
+   105791.66542        0.10572704        0.04018607
+   105833.98209        0.08445121        0.03902178
+   105876.31568        0.09111259        0.03719197
+   105918.66621        0.18251045        0.04004429
+   105961.03368        0.07025580        0.04608964
+   106003.41809        0.09533400        0.03742628
+   106045.81946        0.01803266        0.05070761
+   106088.23778        0.06683687        0.04222798
+   106130.67308        0.07471272        0.04642125
+   106173.12535        0.05355696        0.04551206
+   106215.59460       -0.00140361        0.05182364
+   106258.08084        0.07763136        0.04495927
+   106300.58407        0.03106804        0.05176629
+   106343.10430        0.08373993        0.03719562
+   106385.64154        0.05239321        0.04405878
+   106428.19580        0.04389649        0.04374969
+   106470.76708        0.04833061        0.04406929
+   106513.35539        0.05891714        0.04658421
+   106555.96073        0.13614556        0.04460093
+   106598.58311        0.10409164        0.04098822
+   106641.22255        0.05485374        0.04661405
+   106683.87903       -0.01380340        0.04906492
+   106726.55259       -0.00180807        0.04399350
+   106769.24321        0.13012068        0.04650097
+   106811.95090        0.04013855        0.04415072
+   106854.67568        0.13875150        0.03631326
+   106897.41756        0.03875692        0.05159823
+   106940.17652        0.04246260        0.05514915
+   106982.95259        0.06852636        0.04763692
+   107025.74577        0.01505788        0.04897694
+   107068.55607       -0.01321366        0.04583484
+   107111.38349        0.06696705        0.04581961
+   107154.22805        0.08655359        0.04868964
+   107197.08974        0.07665887        0.04227176
+   107239.96858        0.09695542        0.04118950
+   107282.86456        0.03244594        0.03990172
+   107325.77771        0.04938514        0.04503086
+   107368.70802        0.09316536        0.03626556
+   107411.65550        0.10669874        0.04769516
+   107454.62016        0.11245519        0.03969593
+   107497.60201        0.06497207        0.04361056
+   107540.60105        0.06232047        0.04543735
+   107583.61729       -0.01974489        0.05592184
+   107626.65074        0.01865855        0.05246764
+   107669.70140        0.02556813        0.05097334
+   107712.76928       -0.00253731        0.04787046
+   107755.85439        0.07319540        0.04370376
+   107798.95673        0.05056527        0.04647401
+   107842.07631        0.01927057        0.04869385
+   107885.21314        0.05301023        0.04457765
+   107928.36723        0.01742605        0.04669612
+   107971.53858        0.06745240        0.03667370
+   108014.72719        0.17005897        0.04019985
+   108057.93308        0.06856455        0.04331954
+   108101.15626       -0.02394004        0.05529383
+   108144.39672        0.12251328        0.03761738
+   108187.65448        0.13585068        0.03843957
+   108230.92954        0.14054160        0.03877566
+   108274.22191        0.04210265        0.04635515
+   108317.53160        0.11748086        0.03515720
+   108360.85861        0.02284948        0.04369664
+   108404.20296        0.05398802        0.04539990
+   108447.56464       -0.01891674        0.03959553
+   108490.94366        0.07303279        0.04250309
+   108534.34004        0.08229390        0.04313825
+   108577.75378       -0.00261310        0.04930052
+   108621.18488        0.10816306        0.04259143
+   108664.63335        0.08511153        0.04585021
+   108708.09921       -0.02541919        0.04879606
+   108751.58244        0.02478219        0.05127153
+   108795.08308        0.06846984        0.04097517
+   108838.60111       -0.02839532        0.05118330
+   108882.13655        0.06823664        0.04580182
+   108925.68941       -0.09053411        0.05632336
+   108969.25968        0.03536868        0.04876362
+   109012.84739        0.03160364        0.04441481
+   109056.45252        0.11628845        0.04883535
+   109100.07511       -0.07777390        0.05776484
+   109143.71514        0.03115514        0.04924957
+   109187.37262        0.07473159        0.04721592
+   109231.04757        0.10146729        0.04644620
+   109274.73999        0.08538685        0.04333699
+   109318.44989        0.06086342        0.04677539
+   109362.17727        0.07089482        0.05742117
+   109405.92214        0.03348861        0.05196045
+   109449.68451        0.08014253        0.04785178
+   109493.46438        0.00280436        0.04841271
+   109537.26177        0.12715863        0.05419566
+   109581.07667        0.06851566        0.04493174
+   109624.90910        0.11219711        0.04244158
+   109668.75906        0.08184033        0.04993039
+   109712.62657       -0.02377372        0.04899882
+   109756.51162        0.02928756        0.04716946
+   109800.41422        0.06118418        0.04174991
+   109844.33439        0.09410607        0.04348294
+   109888.27212        0.08444724        0.04286010
+   109932.22743        0.07679982        0.04469539
+   109976.20032        0.08991452        0.04957880
+   110020.19080        0.08854456        0.04282075
+   110064.19888        0.02609080        0.04840234
+   110108.22456        0.05400668        0.04963697
+   110152.26785        0.06863420        0.04606865
+   110196.32876       -0.03674625        0.05677112
+   110240.40729        0.04445097        0.04894066
+   110284.50345        0.01853942        0.04967959
+   110328.61725        0.08600377        0.05077294
+   110372.74870        0.10214633        0.03824181
+   110416.89780        0.12450487        0.04429298
+   110461.06456        0.08291699        0.04208344
+   110505.24898        0.06909750        0.04135078
+   110549.45108        0.04445702        0.04894731
+   110593.67086        0.07975367        0.04865733
+   110637.90833        0.02211788        0.04367215
+   110682.16349        0.04548777        0.04499317
+   110726.43636        0.12117791        0.04452789
+   110770.72693        0.03633544        0.04472399
+   110815.03522        0.06071030        0.04142655
+   110859.36124        0.08366389        0.04737536
+   110903.70498        0.05436764        0.03870179
+   110948.06647        0.00001460        0.04997273
+   110992.44569        0.03410577        0.04750643
+   111036.84267       -0.00077844        0.05430456
+   111081.25741       -0.02473602        0.05343832
+   111125.68991       -0.02804129        0.04478567
+   111170.14019       -0.01245723        0.05239186
+   111214.60824        0.01334474        0.04497693
+   111259.09409        0.04465024        0.04911338
+   111303.59772        0.08560099        0.04179883
+   111348.11916        0.06264704        0.04814616
+   111392.65841       -0.04191379        0.06203570
+   111437.21547        0.06812850        0.04880364
+   111481.79036        0.12474666        0.04201005
+   111526.38308        0.04576294        0.05033732
+   111570.99363        0.04883851        0.04830748
+   111615.62203        0.03476066        0.04254573
+   111660.26828        0.15457805        0.04146925
+   111704.93238        0.05309776        0.04108715
+   111749.61436        0.02621591        0.05013452
+   111794.31420        0.15004631        0.04690036
+   111839.03193        0.12664144        0.03357370
+   111883.76754        0.07967608        0.05538778
+   111928.52105        0.03672938        0.05116090
+   111973.29246        0.07957158        0.04326287
+   112018.08177        0.13412177        0.04373895
+   112062.88900        0.06866755        0.04813352
+   112107.71416        0.10613701        0.05703922
+   112152.55725        0.07399322        0.04852385
+   112197.41827        0.04738066        0.05211675
+   112242.29724        0.14400319        0.03522073
+   112287.19416        0.00303699        0.05242863
+   112332.10903        0.12500721        0.04353742
+   112377.04188        0.10663374        0.04535354
+   112421.99269        0.07691663        0.05162799
+   112466.96149        0.07102744        0.05615950
+   112511.94827        0.10749128        0.04571827
+   112556.95305       -0.03767022        0.05818497
+   112601.97584        0.02639175        0.05683108
+   112647.01663        0.03793432        0.05283927
+   112692.07543       -0.00307816        0.05807473
+   112737.15226        0.15170955        0.04879455
+   112782.24712        0.06673322        0.04402919
+   112827.36002        0.12578845        0.04758287
+   112872.49097        0.06483986        0.04098945
+   112917.63996       -0.09855577        0.06124951
+   112962.80702        0.05567246        0.04947992
+   113007.99214       -0.03324506        0.05992504
+   113053.19534        0.04725985        0.05180632
+   113098.41662        0.10761471        0.04972478
+   113143.65598        0.11167416        0.04104003
+   113188.91345        0.09768441        0.04333400
+   113234.18901       -0.00448416        0.05169411
+   113279.48269        0.08808049        0.05126044
+   113324.79448        0.00719131        0.04675451
+   113370.12440        0.01793600        0.04730300
+   113415.47245        0.07070738        0.05520630
+   113460.83864        0.10587655        0.05441355
+   113506.22297        0.04995244        0.04885970
+   113551.62546       -0.07119612        0.06200495
+   113597.04611        0.03511637        0.05551142
+   113642.48493       -0.02571201        0.04985129
+   113687.94192        0.12797562        0.04457125
+   113733.41710       -0.00971157        0.05052604
+   113778.91047        0.04105178        0.05052915
+   113824.42203       -0.04755606        0.05340176
+   113869.95180        0.06508208        0.04903554
+   113915.49978       -0.04825740        0.05779066
+   113961.06598        0.03944046        0.04174245
+   114006.65041        0.08444329        0.04145839
+   114052.25307       -0.03450324        0.05592299
+   114097.87397       -0.00435246        0.05017584
+   114143.51312        0.08859559        0.04733453
+   114189.17052        0.07157011        0.03728154
+   114234.84619        0.03755708        0.05231381
+   114280.54013        0.12541492        0.04938470
+   114326.25235        0.03764518        0.05243652
+   114371.98285        0.09821109        0.03926044
+   114417.73164        0.07867386        0.04708167
+   114463.49873       -0.03304240        0.04642375
+   114509.28413        0.11410233        0.04657634
+   114555.08785        0.06349669        0.04666007
+   114600.90988       -0.01068573        0.05588445
+   114646.75025        0.06632304        0.04997052
+   114692.60895        0.07836035        0.04522054
+   114738.48599        0.12402109        0.03492414
+   114784.38138        0.02594706        0.05123295
+   114830.29514       -0.02102479        0.05169683
+   114876.22725        0.00323355        0.05582206
+   114922.17774        0.06699552        0.04235219
+   114968.14662        0.04318153        0.05315060
+   115014.13387       -0.01024354        0.05329365
+   115060.13953        0.09833980        0.04801918
+   115106.16358        0.11095080        0.04247437
+   115152.20605        0.06182445        0.04926788
+   115198.26693        0.14016962        0.04463029
+   115244.34624        0.14300704        0.04815947
+   115290.44398        0.07148729        0.04716582
+   115336.56015        0.02724993        0.05380550
+   115382.69478        0.14514471        0.04185367
+   115428.84786       -0.07582603        0.06215269
+   115475.01940        0.01251947        0.05617033
+   115521.20940       -0.00721288        0.05236521
+   115567.41789       -0.02555505        0.05713848
+   115613.64485        0.05992378        0.05325836
+   115659.89031        0.05419578        0.05301022
+   115706.15427        0.11431043        0.04376051
+   115752.43673       -0.02810526        0.05449141
+   115798.73770       -0.03831731        0.06210485
+   115845.05720        0.06266945        0.05652425
+   115891.39522        0.04862610        0.05294805
+   115937.75178       -0.03161254        0.05732991
+   115984.12688       -0.04333435        0.05678893
+   116030.52053        0.11995900        0.05102106
+   116076.93274        0.09763394        0.04292087
+   116123.36351        0.01956006        0.05158616
+   116169.81286        0.09199140        0.04261895
+   116216.28078        0.03038874        0.05811451
+   116262.76730        0.02061223        0.04522889
+   116309.27240        0.07370019        0.04862584
+   116355.79611        0.06791659        0.04834666
+   116402.33843        0.12669919        0.03276346
+   116448.89937        0.03064295        0.05860063
+   116495.47893        0.08813434        0.03430867
+   116542.07712        0.00795402        0.05171332
+   116588.69395        0.05425695        0.04443778
+   116635.32943       -0.09680192        0.06378074
+   116681.98356        0.00152463        0.07083073
+   116728.65635        0.11243164        0.04494518
+   116775.34781        0.03474069        0.05699207
+   116822.05795        0.05753969        0.04883630
+   116868.78678        0.09412365        0.05117480
+   116915.53429        0.02030420        0.05354871
+   116962.30050        0.04832259        0.05203485
+   117009.08542        0.09328482        0.04011793
+   117055.88906        0.14150825        0.05105263
+   117102.71141        0.01946694        0.06009679
+   117149.55250        0.09745077        0.03606849
+   117196.41232        0.09199557        0.05505393
+   117243.29088        0.08959825        0.05170576
+   117290.18820       -0.00153334        0.05641610
+   117337.10428        0.12716707        0.05408679
+   117384.03912        0.06008695        0.04246833
+   117430.99273        0.03115715        0.06709272
+   117477.96513        0.08060272        0.05500043
+   117524.95632        0.00730792        0.06050828
+   117571.96630        0.12415782        0.03876315
+   117618.99509       -0.04751398        0.06655658
+   117666.04268        0.07740998        0.05832388
+   117713.10910        0.06491937        0.05769829
+   117760.19434        0.00472900        0.05762919
+   117807.29842        0.05400457        0.06608556
+   117854.42134        0.05874499        0.05745990
+   117901.56311        0.02624606        0.06191161
+   117948.72374       -0.02779502        0.06214681
+   117995.90323        0.00369235        0.06374250
+   118043.10159        0.14546992        0.05248189
+   118090.31883       -0.02678044        0.05605542
+   118137.55495       -0.00524164        0.06042642
+   118184.80998        0.02211702        0.04853080
+   118232.08390       -0.00156686        0.05764916
+   118279.37673        0.01480150        0.05539007
+   118326.68848       -0.09261834        0.06532187
+   118374.01916       -0.01060247        0.05418732
+   118421.36877        0.07986324        0.05269210
+   118468.73732       -0.01546960        0.06389287
+   118516.12481       -0.02838157        0.06345829
+   118563.53126        0.13980290        0.04942906
+   118610.95667        0.06151652        0.05221160
+   118658.40106        0.08608308        0.04160618
+   118705.86442       -0.03800507        0.06069914
+   118753.34676        0.03488742        0.05825775
+   118800.84810        0.16670663        0.03862079
+   118848.36844        0.03235322        0.05491905
+   118895.90779        0.02584632        0.05467390
+   118943.46615       -0.02809303        0.05880285
+   118991.04354       -0.03203597        0.06211241
+   119038.63995        0.14409845        0.05094781
+   119086.25541        0.10450619        0.04841695
+   119133.88991        0.12490557        0.04993171
+   119181.54347        0.14824474        0.05550026
+   119229.21609        0.01180063        0.06210581
+   119276.90777       -0.07147384        0.07076908
+   119324.61853        0.09148144        0.05629635
+   119372.34838        0.02266035        0.05976266
+   119420.09732       -0.05445961        0.06913730
+   119467.86536       -0.01533849        0.06143623
+   119515.65251        0.10027269        0.04914966
+   119563.45877        0.07304134        0.04728332
+   119611.28415        0.03943965        0.06470068
+   119659.12866        0.02003323        0.05648203
+   119706.99232        0.02692337        0.05695225
+   119754.87511        0.02006777        0.05657942
+   119802.77706        0.05963800        0.04650783
+   119850.69817       -0.02924351        0.06121097
+   119898.63845        0.04077197        0.05792696
+   119946.59791        0.05861030        0.05516717
+   119994.57655        0.03393817        0.05760948
+   120042.57438        0.02303799        0.06075858
+   120090.59141        0.08932879        0.06095479
+   120138.62764       -0.00171472        0.06308936
+   120186.68310        0.00925561        0.06017559
+   120234.75777        0.16538999        0.04515584
+   120282.85167        0.01043195        0.05246793
+   120330.96481        0.07014132        0.05221623
+   120379.09720        0.12706905        0.04722990
+   120427.24884        0.04414883        0.06247631
+   120475.41974        0.09009003        0.06147424
+   120523.60991        0.11514605        0.05922328
+   120571.81935        0.04422976        0.06259084
+   120620.04808        0.10535914        0.05471239
+   120668.29610        0.04135734        0.05875863
+   120716.56341        0.02739849        0.05795729
+   120764.85004       -0.00873178        0.06339242
+   120813.15598       -0.01691418        0.06985935
+   120861.48124        0.07780087        0.05315862
+   120909.82583        0.06096098        0.04753953
+   120958.18977        0.08284679        0.06872737
+   121006.57304       -0.01470990        0.05596032
+   121054.97567        0.11808516        0.05191143
+   121103.39766        0.09293034        0.05472033
+   121151.83902        0.01247495        0.06565478
+   121200.29976        0.05531165        0.06808112
+   121248.77988       -0.02321760        0.06396245
+   121297.27939        0.01672370        0.06258328
+   121345.79830        0.05378988        0.05692938
+   121394.33662        0.18840499        0.05274909
+   121442.89435       -0.04186925        0.06687077
+   121491.47151        0.06942880        0.04907098
+   121540.06810       -0.00177837        0.06543160
+   121588.68413        0.08671839        0.05482028
+   121637.31960        0.06275252        0.06878942
+   121685.97453        0.12772426        0.04317657
+   121734.64892        0.17227655        0.06000034
+   121783.34278        0.01489311        0.04968309
+   121832.05611        0.04640083        0.05621126
+   121878.90652        0.08499566        0.06245843
diff --git a/Test/AutoTestData/TOPAZ_3007.mat b/Test/AutoTestData/UsageData/TOPAZ_3007.mat
similarity index 100%
rename from Test/AutoTestData/TOPAZ_3007.mat
rename to Test/AutoTestData/UsageData/TOPAZ_3007.mat
diff --git a/Test/AutoTestData/loadSassenaExample.h5 b/Test/AutoTestData/UsageData/loadSassenaExample.h5
similarity index 100%
rename from Test/AutoTestData/loadSassenaExample.h5
rename to Test/AutoTestData/UsageData/loadSassenaExample.h5