diff --git a/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/ForCE.ui b/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/ForCE.ui index eac8f64c0c279f8f5fd0924a7586460d27a57ff8..e25182719751f196ed8df0c8ec7a29081dea630a 100644 --- a/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/ForCE.ui +++ b/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/ForCE.ui @@ -6,8 +6,8 @@ <rect> <x>0</x> <y>0</y> - <width>722</width> - <height>192</height> + <width>761</width> + <height>222</height> </rect> </property> <property name="windowTitle"> @@ -105,40 +105,57 @@ </layout> </item> <item> - <layout class="QHBoxLayout" name="horizontalLayout_8"> - <item> - <layout class="QHBoxLayout" name="horizontalLayout_7"> - <item alignment="Qt::AlignHCenter"> - <widget class="QCheckBox" name="chkUseMap"> - <property name="sizePolicy"> - <sizepolicy hsizetype="Preferred" vsizetype="Fixed"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - <property name="text"> - <string>Use Map</string> - </property> - </widget> - </item> - </layout> + <layout class="QGridLayout" name="gridLayout"> + <item row="0" column="0"> + <widget class="QCheckBox" name="chkUseMap"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Preferred" vsizetype="Fixed"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>Use Map</string> + </property> + </widget> </item> - <item> - <layout class="QHBoxLayout" name="horizontalLayout_6"> - <item alignment="Qt::AlignHCenter"> - <widget class="QCheckBox" name="chkRejectZero"> - <property name="sizePolicy"> - <sizepolicy hsizetype="Preferred" vsizetype="Fixed"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - <property name="text"> - <string>Reject Zero</string> - </property> - </widget> - </item> - </layout> + <item row="0" column="1"> + <widget class="MantidQt::MantidWidgets::MWRunFiles" name="mwMapFile"> + <property name="enabled"> + <bool>false</bool> + </property> + <property name="sizePolicy"> + <sizepolicy hsizetype="Preferred" vsizetype="Fixed"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="label" stdset="0"> + <string>Map File:</string> + </property> + <property name="fileExtensions"> + <stringlist> + <string>.map</string> + </stringlist> + </property> + </widget> + </item> + </layout> + </item> + <item> + <layout class="QHBoxLayout" name="horizontalLayout_6"> + <item alignment="Qt::AlignLeft"> + <widget class="QCheckBox" name="chkRejectZero"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Preferred" vsizetype="Fixed"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>Reject Zero</string> + </property> + </widget> </item> </layout> </item> @@ -191,12 +208,36 @@ </spacer> </item> <item> - <widget class="QCheckBox" name="chkPlot"> + <widget class="QLabel" name="lblPlot"> <property name="text"> - <string>Plot Result</string> + <string>Plot Result: </string> </property> </widget> </item> + <item> + <widget class="QComboBox" name="cbPlot"> + <item> + <property name="text"> + <string>None</string> + </property> + </item> + <item> + <property name="text"> + <string>Spectrum</string> + </property> + </item> + <item> + <property name="text"> + <string>Contour</string> + </property> + </item> + <item> + <property name="text"> + <string>Both</string> + </property> + </item> + </widget> + </item> <item> <spacer name="horizontalSpacer_18"> <property name="orientation"> diff --git a/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/MolDyn.ui b/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/MolDyn.ui index ba7c848b911307cfb4380380d6baec3fd6d937b4..c2d09ee0ab92c07a1fc58ad0c8ca5ce2cd099291 100644 --- a/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/MolDyn.ui +++ b/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/MolDyn.ui @@ -6,8 +6,8 @@ <rect> <x>0</x> <y>0</y> - <width>629</width> - <height>160</height> + <width>673</width> + <height>155</height> </rect> </property> <property name="windowTitle"> @@ -102,12 +102,36 @@ </spacer> </item> <item> - <widget class="QCheckBox" name="chkPlot"> + <widget class="QLabel" name="lblPlot"> <property name="text"> - <string>Plot Result</string> + <string>Plot Result: </string> </property> </widget> </item> + <item> + <widget class="QComboBox" name="cbPlot"> + <item> + <property name="text"> + <string>None</string> + </property> + </item> + <item> + <property name="text"> + <string>Spectrum</string> + </property> + </item> + <item> + <property name="text"> + <string>Contour</string> + </property> + </item> + <item> + <property name="text"> + <string>Both</string> + </property> + </item> + </widget> + </item> <item> <spacer name="horizontalSpacer_18"> <property name="orientation"> diff --git a/Code/Mantid/MantidQt/CustomInterfaces/src/ForCE.cpp b/Code/Mantid/MantidQt/CustomInterfaces/src/ForCE.cpp index 5f7cfc0f7be0f2fdb14b407c1bc810c7f5889ec6..2c8331a466410d18ea955d38bfa9b17539dfdc67 100644 --- a/Code/Mantid/MantidQt/CustomInterfaces/src/ForCE.cpp +++ b/Code/Mantid/MantidQt/CustomInterfaces/src/ForCE.cpp @@ -18,6 +18,7 @@ namespace MantidQt connect(m_uiForm.cbInstrument, SIGNAL(instrumentSelectionChanged(const QString&)), this, SLOT(instrumentChanged(const QString&))); connect(m_uiForm.cbAnalyser, SIGNAL(currentIndexChanged(const QString&)), this, SLOT(analyserChanged(const QString&))); connect(m_uiForm.mwRun, SIGNAL(filesFound()), this, SLOT(handleFilesFound())); + connect(m_uiForm.chkUseMap, SIGNAL(toggled(bool)), m_uiForm.mwMapFile, SLOT(setEnabled(bool))); QString instrument = m_uiForm.cbInstrument->currentText(); instrumentChanged(instrument); @@ -34,7 +35,7 @@ namespace MantidQt QFileInfo finfo(filename); QString ext = finfo.extension().toLower(); - if(ext != "asc" && ext != "inx") //using ascii files + if(ext != "asc" && ext != "inx") { emit showMessageBox("File is not of expected type:\n File type must be .asc or .inx"); return false; @@ -51,7 +52,7 @@ namespace MantidQt { QString verbose("False"); QString plot("False"); - QString save("False"); + QString save("None"); QString useMap("False"); QString rejectZero("False"); @@ -65,12 +66,15 @@ namespace MantidQt QString reflection = m_uiForm.cbReflection->currentText(); if(m_uiForm.chkUseMap->isChecked()){ useMap ="True"; } + QString mapPath = m_uiForm.mwMapFile->getFirstFilename(); + if(m_uiForm.chkRejectZero->isChecked()){ rejectZero ="True"; } //output options if(m_uiForm.chkVerbose->isChecked()){ verbose = "True"; } - if(m_uiForm.chkPlot->isChecked()){ plot = "True"; } - if(m_uiForm.chkSave->isChecked()){ save ="True"; } + if(m_uiForm.chkSave->isChecked()){ save = "True"; } + plot = m_uiForm.cbPlot->currentText(); + QString pyFunc (""); if(ext == "asc") //using ascii files @@ -85,8 +89,8 @@ namespace MantidQt QString pyInput = "from IndirectForce import "+pyFunc+"\n"; - pyInput += pyFunc + "('"+instrument+"','"+filename+"','"+analyser+"','"+reflection+"',"+rejectZero+","+useMap+"" - ","+verbose+","+plot+","+save+")"; + pyInput += pyFunc + "('"+instrument+"','"+filename+"','"+analyser+"','"+reflection+"',"+rejectZero+","+useMap+",'"+mapPath+"'" + ","+verbose+",'"+plot+"',"+save+")"; runPythonScript(pyInput); } diff --git a/Code/Mantid/MantidQt/CustomInterfaces/src/MolDyn.cpp b/Code/Mantid/MantidQt/CustomInterfaces/src/MolDyn.cpp index 44f6800715fd7b9d4254317625406643933ed935..62f473120aba21cb09cd47823bb1530a7b2bf362 100644 --- a/Code/Mantid/MantidQt/CustomInterfaces/src/MolDyn.cpp +++ b/Code/Mantid/MantidQt/CustomInterfaces/src/MolDyn.cpp @@ -1,5 +1,8 @@ #include "MantidQtCustomInterfaces/MolDyn.h" +#include <QFileInfo> +#include <QString> + namespace MantidQt { namespace CustomInterfaces @@ -8,7 +11,6 @@ namespace MantidQt IndirectForeignTab(parent) { m_uiForm.setupUi(parent); - } /** @@ -18,6 +20,15 @@ namespace MantidQt */ bool MolDyn::validate() { + QString filename = m_uiForm.mwRun->getFirstFilename(); + QFileInfo finfo(filename); + QString ext = finfo.extension().toLower(); + + if(ext != "dat" && ext != "cdl") + { + emit showMessageBox("File is not of expected type:\n File type must be .dat or .cdl"); + return false; + } return true; } @@ -32,8 +43,32 @@ namespace MantidQt QString plot("False"); QString save("False"); + QString filename = m_uiForm.mwRun->getFirstFilename(); + QFileInfo finfo(filename); + QString ext = finfo.extension().toLower(); + + QString funcNames = m_uiForm.leFunctionNames->text(); + + //output options + if(m_uiForm.chkVerbose->isChecked()){ verbose = "True"; } + if(m_uiForm.chkSave->isChecked()){ save ="True"; } + plot = m_uiForm.cbPlot->currentText(); + + QString pyInput = - "from IndirectBayes import MolDynRun\n"; + "from MolDynTransfer import "; + + QString pyFunc(""); + if(ext == "dat") + { + pyFunc = "MolDynText"; + pyInput += pyFunc + "\n" + pyFunc + "('"+filename+"',"+verbose+",'"+plot+"',"+save+")"; + } + else if (ext == "cdl") + { + pyFunc = "MolDynImport"; + pyInput += pyFunc + "\n" + pyFunc + "('"+filename+"','"+funcNames+"',"+verbose+",'"+plot+"',"+save+")"; + } runPythonScript(pyInput); } diff --git a/Code/Mantid/instrument/IN13_Definition_xml b/Code/Mantid/instrument/IN13_Definition_xml new file mode 100644 index 0000000000000000000000000000000000000000..c71a274ab9f5ddbae2453832aa66881ba543f8ab --- /dev/null +++ b/Code/Mantid/instrument/IN13_Definition_xml @@ -0,0 +1,104 @@ +<?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 name="IN13" valid-from ="1900-01-31 23:59:59" + valid-to ="2100-01-31 23:59:59" + last-modified="2010-10-07 00:00:00"> +<!-- modified by FD 7/10/2010 --> + +<defaults> + <length unit="meter" /> + <angle unit="degree" /> + <reference-frame> + <along-beam axis="z" /> + <pointing-up axis="y" /> + <handedness val="right" /> + </reference-frame> + <offsets spherical="delta" /> +</defaults> + +<!-- LIST OF PHYSICAL COMPONENTS (which the instrument consists of) --> + +<!-- source and sample-position components --> + +<component type="moderator"> + <location z="-36.41" /> +</component> + +<type name="moderator" is="Source"> + <properties /> +</type> + +<component type="sample"> + <location z="0.0" /> +</component> + +<type name="sample" is="SamplePos"> + <cuboid id="shape"> + <left-front-bottom-point x="0.02" y="-0.02" z="0.0" /> + <left-front-top-point x="0.02" y="-0.02" z="0.02" /> + <left-back-bottom-point x="-0.02" y="-0.02" z="0.0" /> + <right-front-bottom-point x="0.02" y="0.02" z="0.0" /> + </cuboid> + <algebra val="shape" /> +</type> + +<!-- LIST OF DETECTORS AND MONITORS --> + +<!-- monitor components --> + + <component type="monitor1" idlist="monitor1"> + <location z="-0.335" /> + </component> + + <type name="monitor1" is="monitor"> + <percent-transparency val="99.9" /> + <cuboid id="shape"> + <left-front-bottom-point x="0.0125" y="-0.0125" z="0.0" /> + <left-front-top-point x="0.0125" y="-0.0125" z="0.005" /> + <left-back-bottom-point x="-0.0125" y="-0.0125" z="0.0" /> + <right-front-bottom-point x="0.0125" y="0.0125" z="0.0" /> + </cuboid> + <algebra val="shape" /> + </type> + + <idlist idname="monitor1"> + <id val="8" /> + </idlist> + +<!-- detector components --> + +<component type="CaF" idlist="CaF"> + <properties /> + <parameter name="Efixed"> <value val="16.45" /> </parameter> + <parameter name="efixed-val"> <value val="16.45" /></parameter> + <location /> +</component> + +<type name="CaF"> + <component type="pix1"> + <location r="1.45" t="27.07" p="0" name="S1" /> + <location r="1.45" t="29.70" p="0" name="S2" /> + <location r="1.45" t="32.32" p="0" name="S3" /> + <location r="1.45" t="34.95" p="0" name="S4" /> + <location r="1.45" t="37.58" p="0" name="S5" /> + <location r="1.45" t="40.21" p="0" name="S6" /> + <location r="1.45" t="42.83" p="0" name="S7" /> + </component> +</type> + +<idlist idname="CaF"> + <id start="1" end="7" /> +</idlist> + +<type name="pix1" is="detector"> + <cuboid id="app-shape"> + <left-front-bottom-point x="0.005" y="-0.1" z="0.0" /> + <left-front-top-point x="0.005" y="-0.1" z="0.0002" /> + <left-back-bottom-point x="-0.005" y="-0.1" z="0.0" /> + <right-front-bottom-point x="0.005" y="0.1" z="0.0" /> + </cuboid> + <algebra val="app-shape" /> +</type> + +</instrument> diff --git a/Code/Mantid/instrument/MolDyn_Definition.xml b/Code/Mantid/instrument/MolDyn_Definition.xml new file mode 100644 index 0000000000000000000000000000000000000000..cb970c936f67867e045ab2b2cf4dab50b832e9dc --- /dev/null +++ b/Code/Mantid/instrument/MolDyn_Definition.xml @@ -0,0 +1,105 @@ +<?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 name="MolDyn" valid-from ="1900-01-31 23:59:59" + valid-to ="2100-01-31 23:59:59" + last-modified="2010-10-07 00:00:00"> +<!-- modified by FD 7/10/2010 --> + +<defaults> + <length unit="meter" /> + <angle unit="degree" /> + <reference-frame> + <along-beam axis="z" /> + <pointing-up axis="y" /> + <handedness val="right" /> + </reference-frame> + <offsets spherical="delta" /> +</defaults> + +<!-- LIST OF PHYSICAL COMPONENTS (which the instrument consists of) --> + +<!-- source and sample-position components --> + +<component type="moderator"> + <location z="-36.41" /> +</component> + +<type name="moderator" is="Source"> + <properties /> +</type> + +<component type="sample"> + <location z="0.0" /> +</component> + +<type name="sample" is="SamplePos"> + <cuboid id="shape"> + <left-front-bottom-point x="0.02" y="-0.02" z="0.0" /> + <left-front-top-point x="0.02" y="-0.02" z="0.02" /> + <left-back-bottom-point x="-0.02" y="-0.02" z="0.0" /> + <right-front-bottom-point x="0.02" y="0.02" z="0.0" /> + </cuboid> + <algebra val="shape" /> +</type> + +<!-- LIST OF DETECTORS AND MONITORS --> + + +<!-- detector components --> + +<component type="simul" idlist="simul"> + <properties /> + <parameter name="Efixed"> <value val="2.08" /> </parameter> + <parameter name="efixed-val"> <value val="2.08" /></parameter> + <location /> +</component> + +<type name="simul"> + <component type="pix1"> + <location r="1.45" t="25.0" p="0" name="S1" /> + <location r="1.45" t="31.5" p="0" name="S2" /> + <location r="1.45" t="38.0" p="0" name="S3" /> + <location r="1.45" t="44.5" p="0" name="S4" /> + <location r="1.45" t="51.8" p="0" name="S5" /> + <location r="1.45" t="57.5" p="0" name="S6" /> + <location r="1.45" t="64.0" p="0" name="S7" /> + <location r="1.45" t="70.5" p="0" name="S8" /> + <location r="1.45" t="77.0" p="0" name="S9" /> + <location r="1.45" t="83.5" p="0" name="S10" /> + <location r="1.45" t="90.0" p="0" name="S11" /> + <location r="1.45" t="96.5" p="0" name="S12" /> + <location r="1.45" t="103.0" p="0" name="S13" /> + <location r="1.45" t="109.5" p="0" name="S14" /> + <location r="1.45" t="116.0" p="0" name="S15" /> + <location r="1.45" t="122.5" p="0" name="S16" /> + <location r="1.45" t="129.0" p="0" name="S17" /> + <location r="1.45" t="135.5" p="0" name="S18" /> + <location r="1.45" t="142.0" p="0" name="S19" /> + <location r="1.45" t="148.5" p="0" name="S20" /> + <location r="1.45" t="0.0" p="0" name="S21" /> + <location r="1.45" t="0.0" p="0" name="S22" /> + <location r="1.45" t="10.96" p="0" name="S23" /> + <location r="1.45" t="16.8" p="0" name="S24" /> + <location r="1.45" t="0.0" p="0" name="S25" /> + <location r="1.45" t="0.0" p="0" name="S26" /> + <location r="1.45" t="0.0" p="0" name="S27" /> + <location r="1.45" t="0.0" p="0" name="S28" /> + </component> +</type> + +<idlist idname="simul"> + <id start="1" end="28" /> +</idlist> + +<type name="pix1" is="detector"> + <cuboid id="app-shape"> + <left-front-bottom-point x="0.005" y="-0.1" z="0.0" /> + <left-front-top-point x="0.005" y="-0.1" z="0.0002" /> + <left-back-bottom-point x="-0.005" y="-0.1" z="0.0" /> + <right-front-bottom-point x="0.005" y="0.1" z="0.0" /> + </cuboid> + <algebra val="app-shape" /> +</type> + +</instrument> diff --git a/Code/Mantid/instrument/MolDyn_qmax_2_Parameters.xml b/Code/Mantid/instrument/MolDyn_qmax_2_Parameters.xml new file mode 100644 index 0000000000000000000000000000000000000000..c131aac36c6e4436858e0d130eccc8e6cce53ebf --- /dev/null +++ b/Code/Mantid/instrument/MolDyn_qmax_2_Parameters.xml @@ -0,0 +1,28 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<parameter-file instrument = "MolDyn" date = "2010-07-15T00:00:00"> + +<component-link name = "MolDyn"> + +<parameter name="analysis-type" type="string"> + <value val="spectroscopy" /> +</parameter> + +<parameter name="efixed-val"> + <value val="1.8450" /> +</parameter> + +<component-link name="simul"> +<parameter name="Efixed"> <value val="1.8450" /> </parameter> +</component-link> + +<parameter name="analyser" type="string"> + <value val="qmax" /> +</parameter> + +<parameter name="reflection" type="string"> + <value val="2" /> +</parameter> + +</component-link> + +</parameter-file> \ No newline at end of file diff --git a/Code/Mantid/instrument/MolDyn_qmax_4_Parameters.xml b/Code/Mantid/instrument/MolDyn_qmax_4_Parameters.xml new file mode 100644 index 0000000000000000000000000000000000000000..5bfedeb4eedc965972610c423568d7e9119bcee0 --- /dev/null +++ b/Code/Mantid/instrument/MolDyn_qmax_4_Parameters.xml @@ -0,0 +1,28 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<parameter-file instrument = "MolDyn" date = "2010-07-15T00:00:00"> + +<component-link name = "MolDyn"> + +<parameter name="analysis-type" type="string"> + <value val="spectroscopy" /> +</parameter> + +<parameter name="efixed-val"> + <value val="7.3812" /> +</parameter> + +<component-link name="simul"> +<parameter name="Efixed"> <value val="7.3812" /> </parameter> +</component-link> + +<parameter name="analyser" type="string"> + <value val="qmax" /> +</parameter> + +<parameter name="reflection" type="string"> + <value val="4" /> +</parameter> + +</component-link> + +</parameter-file> \ No newline at end of file diff --git a/Code/Mantid/scripts/Inelastic/IndirectForce.py b/Code/Mantid/scripts/Inelastic/IndirectForce.py index 3983d066b251c0e84653a420a84306027322acf4..de8e86123b6d8af19be849bd00296302ffbd2715 100644 --- a/Code/Mantid/scripts/Inelastic/IndirectForce.py +++ b/Code/Mantid/scripts/Inelastic/IndirectForce.py @@ -106,7 +106,7 @@ def getFilePath(run,ext,intr): fname = instr + "_" + run if path: - return asc, fname + return path, fname else: error = 'ERROR *** Could not find ' + ext + ' file' sys.exit(error) @@ -126,14 +126,15 @@ def loadFile(path): error = 'ERROR *** Could not load ' + path sys.exit(error) -def IbackStart(instr,run,ana,refl,rejectZ,useM,Verbose,Plot,Save): #Ascii start routine +def IbackStart(instr,run,ana,refl,rejectZ,useM,mapPath,Verbose,Plot,Save): #Ascii start routine StartTime('Iback') workdir = config['defaultsave.directory'] if Verbose: logger.notice('Reading file : ' + path) - asc, fname = getFilePath(run, '.asc', instr) + path, fname = getFilePath(run, '.asc', instr) + asc = loadFile(path) lasc = len(asc) # raw head @@ -246,7 +247,7 @@ def IbackStart(instr,run,ana,refl,rejectZ,useM,Verbose,Plot,Save): #Ascii s efixed = RunParas(ascWS,instr,run,title,Verbose) ChangeAngles(ascWS,instr,theta,Verbose) if useM: - map = ReadMap(instr,Verbose) + map = ReadMap(mapPath,Verbose) UseMap(ascWS,map,Verbose) if rejectZ: RejectZero(ascWS,tot,Verbose) @@ -279,11 +280,12 @@ def ReadInxGroup(asc,n,lgrp): # read ascii x,y,e npt = len(x) return Q,npt,x,y,e #values of x,y,e as lists -def InxStart(instr,run,ana,refl,rejectZ,useM,Verbose,Plot,Save): +def InxStart(instr,run,ana,refl,rejectZ,useM,mapPath,Verbose,Plot,Save): StartTime('Inx') workdir = config['defaultsave.directory'] - asc, fname = getFilePath(run, '.inx', instr) + path, fname = getFilePath(run, '.inx', instr) + asc = loadFile(path) lasc = len(asc) val = ExtractInt(asc[0]) @@ -336,7 +338,7 @@ def InxStart(instr,run,ana,refl,rejectZ,useM,Verbose,Plot,Save): theta.append(ang) ChangeAngles(ascWS,instr,theta,Verbose) if useM: - map = ReadMap(instr,Verbose) + map = ReadMap(mapPath,Verbose) UseMap(ascWS,map,Verbose) if rejectZ: RejectZero(ascWS,tot,Verbose) @@ -370,11 +372,10 @@ def RejectZero(inWS,tot,Verbose): if Verbose: logger.notice('** spectrum '+str(n+1)+' rejected') -def ReadMap(instr,Verbose): +def ReadMap(path,Verbose): workdir = config['defaultsave.directory'] - path = FileFinder.getFullPath(instr + "_map.asc") - asc, fname = loadFile(path) + asc = loadFile(path) lasc = len(asc) if Verbose: diff --git a/Code/Mantid/scripts/Inelastic/MolDynTransfer.py b/Code/Mantid/scripts/Inelastic/MolDynTransfer.py index 85e379b7eaee4b2ae7d37fa8397ed36a3bc62b46..0ecbc9942feb6bfe672a2344c359525c96db6f69 100644 --- a/Code/Mantid/scripts/Inelastic/MolDynTransfer.py +++ b/Code/Mantid/scripts/Inelastic/MolDynTransfer.py @@ -74,21 +74,38 @@ def MakeList(a,l1,l2): alist = asc.split(',') return alist -def MolDynImport(file,functions,Verbose,Plot,Save): #Ascii start routine +# Load an dat/cdl file +def loadFile(path): + try: + handle = open(path, 'r') + asc = [] + for line in handle: + line = line.rstrip() + asc.append(line) + handle.close() + + return asc + except: + error = 'ERROR *** Could not load ' + path + sys.exit(error) + +def MolDynImport(fname,functions,Verbose,Plot,Save): #Ascii start routine StartTime('MolDynImport') workdir = config['defaultsave.directory'] - filext = file + '.cdl' - path = os.path.join(workdir, filext) + + functions = functions.split(',') + + path = fname + base = os.path.basename(path) + fname = os.path.splitext(base)[0] + if Verbose: logger.notice('Functions : '+str(functions)) logger.notice('Reading file : ' + path) - handle = open(path, 'r') - asc = [] - for line in handle: - line = line.rstrip() - asc.append(line) - handle.close() + + asc = loadFile(path) lasc = len(asc) + # raw head nQ,nT,nF = FindDimensions(asc,Verbose) ldata = FindStarts(asc,'data:',0) @@ -145,11 +162,15 @@ def MolDynImport(file,functions,Verbose,Plot,Save): #Ascii start routine xEn = np.array(T) eZero = np.zeros(nT) xUnit = 'TOF' - if func[:3] == 'Sqw': + elif func[:3] == 'Sqw': nP = nF xEn = np.array(F) eZero = np.zeros(nF) xUnit = 'Energy' + else: + error = "ERROR *** Failed to parse function string" + func + sys.exit(error) + for n in range(0,nQ): for m in range(lstart,lasc): char = asc[m] @@ -186,7 +207,7 @@ def MolDynImport(file,functions,Verbose,Plot,Save): #Ascii start routine xDat = np.append(xDat,xEn) yDat = np.append(yDat,np.array(S)) eDat = np.append(eDat,eZero) - outWS = file+'_'+func + outWS = fname+'_'+func CreateWorkspace(OutputWorkspace=outWS, DataX=xDat, DataY=yDat, DataE=eDat, Nspec=nQ, UnitX=xUnit, VerticalAxisUnit='MomentumTransfer', VerticalAxisValues=Qaxis) if Save: @@ -210,20 +231,20 @@ def plotMolDyn(inWS,Plot): if (Plot == 'Contour' or Plot == 'Both'): cont_plot=mp.importMatrixWorkspace(inWS).plotGraph2D() -def MolDynText(file,Verbose,Plot,Save): #Ascii start routine +def MolDynText(fname,Verbose,Plot,Save): #Ascii start routine StartTime('MolDynAscii') workdir = config['defaultsave.directory'] - filext = file + '.dat' - path = os.path.join(workdir, filext) + + path = fname + base = os.path.basename(path) + fname = os.path.splitext(base)[0] + if Verbose: logger.notice('Reading file : ' + path) - handle = open(path, 'r') - asc = [] - for line in handle: - line = line.rstrip() - asc.append(line) - handle.close() + + asc = loadFile(path) lasc = len(asc) + val = SplitLine(asc[3]) Q = [] for n in range(1,len(val)): @@ -259,7 +280,7 @@ def MolDynText(file,Verbose,Plot,Save): #Ascii start routine xDat = np.append(xDat,xT) yDat = np.append(yDat,np.array(S)) eDat = np.append(eDat,eZero) - outWS = file + '_iqt' + outWS = fname + '_iqt' CreateWorkspace(OutputWorkspace=outWS, DataX=xDat, DataY=yDat, DataE=eDat, Nspec=nQ, UnitX='TOF') # Nspec=nQ, UnitX='TOF', VerticalAxisUnit='MomentumTransfer', VerticalAxisValues=Qaxis) @@ -271,7 +292,7 @@ def MolDynText(file,Verbose,Plot,Save): #Ascii start routine else: refl = '4' InstrParas(outWS,instr,ana,refl) - efixed = RunParas(outWS,instr,file,file,Verbose) + efixed = RunParas(outWS,instr,fname,fname,Verbose) if Verbose: logger.notice('Qmax = '+str(Qmax)+' ; efixed = '+str(efixed)) pi4 = 4.0*math.pi