Skip to content

Commit

Permalink
Load Algorithm now compatible with custom separators
Browse files Browse the repository at this point in the history
The Save Algorithm had always been able to define a custom spearator, but ht eLoad algorithm wouldn't recognise them.

Custom separator code now added to both algorithm and custom dialog.

Refs #7732
  • Loading branch information
keithnbrown committed Oct 21, 2013
1 parent abf05e0 commit 2c48d3a
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 13 deletions.
38 changes: 34 additions & 4 deletions Code/Mantid/Framework/DataHandling/src/LoadAscii2.cpp
Expand Up @@ -428,7 +428,6 @@ namespace Mantid
return (!std::isdigit(line.at(0)) && line.at(0) != m_comment.at(0));
}


/**
* Split the data into columns based on the input separator
* @param[out] columns :: A reference to a list to store the column data
Expand Down Expand Up @@ -487,7 +486,7 @@ namespace Mantid
"",Direction::Output), "The name of the workspace that will be created, filled with the read-in data and stored in the [[Analysis Data Service]].");

std::string spacers[6][6] = { {"Automatic", ",\t:; "}, {"CSV", ","},
{"Tab", "\t"}, {"Space", " "}, {"Colon", ":"}, {"SemiColon", ";"} };
{"Tab", "\t"}, {"Space", " "}, {"Colon", ":"}, {"SemiColon", ";"}, {"UserDefined", "UserDefined"} };
// For the ListValidator
std::vector<std::string> sepOptions;
for( size_t i = 0; i < 5; ++i )
Expand All @@ -498,7 +497,9 @@ namespace Mantid
}
declareProperty("Separator", "Automatic", boost::make_shared<StringListValidator>(sepOptions),
"The separator between data columns in the data file. The possible values are \"CSV\", \"Tab\", "
"\"Space\", \"SemiColon\", or \"Colon\" (default: Automatic selection).");
"\"Space\", \"SemiColon\", \"Colon\" or a user defined value. (default: Automatic selection from comma, tab, space, semicolon or colon.).");
declareProperty(new PropertyWithValue<std::string>("CustomSeparator", "", Direction::Input),
"If present, will override any specified choice given to Separator.");
declareProperty("CommentIndicator", "#", "Character(s) found front of comment lines. Cannot contain numeric characters");

std::vector<std::string> units = UnitFactory::Instance().getKeys();
Expand All @@ -525,9 +526,38 @@ namespace Mantid

std::string sepOption = getProperty("Separator");
m_columnSep = m_separatorIndex[sepOption];
m_comment = getProperty("CommentIndicator");

std::string choice = getPropertyValue("Separator");
std::string custom = getPropertyValue("CustomSeparator");
std::string sep;
// If the custom separator property is not empty, then we use that under any circumstance.
if(custom != "")
{
sep = custom;
}
// Else if the separator drop down choice is not UserDefined then we use that.
else if(choice != "UserDefined")
{
std::map<std::string, std::string>::iterator it = m_separatorIndex.find(choice);
sep = it->second;
}
// If we still have nothing, then we are forced to use a default.
if(sep.empty())
{
g_log.notice() << "\"UserDefined\" has been selected, but no custom separator has been entered. Using default instead.";
sep = ",";
}
m_columnSep = sep;

boost::regex test("[^0-9]+", boost::regex::perl);

if (!boost::regex_match(m_columnSep.begin(), m_columnSep.end(), test))
{
throw std::runtime_error("Separators cannot contain numeric characters");
}

m_comment = getProperty("CommentIndicator");

if (!boost::regex_match(m_comment.begin(), m_comment.end(), test))
{
throw std::runtime_error("Comment markers cannot contain numeric characters");
Expand Down
Expand Up @@ -71,7 +71,8 @@ protected slots:
QLineEdit *m_lineFilename;
QLineEdit *m_lineOutputWorkspace;
QLineEdit *m_lineCommentIndicator;
QComboBox *m_separatorBox;
QLineEdit *m_lineCustomSeparator;
QComboBox *m_separatorBox;

};

Expand Down
31 changes: 23 additions & 8 deletions Code/Mantid/MantidQt/CustomDialogs/src/LoadAsciiDialog.cpp
Expand Up @@ -56,19 +56,34 @@ namespace MantidQt

if (getAlgorithm()->version() == 2)
{
label = new QLabel(tr("CustomSeparator"));
m_lineCustomSeparator = new QLineEdit;
label->setBuddy(m_lineCustomSeparator);
paramsLayout->addWidget(label,3,0);
paramsLayout->addWidget(m_lineCustomSeparator,3,1);
tie(m_lineCustomSeparator, "CustomSeparator", paramsLayout);

label = new QLabel(tr("CommentIndicator"));
m_lineCommentIndicator = new QLineEdit;
label->setBuddy(m_lineCommentIndicator);
paramsLayout->addWidget(label,3,0);
paramsLayout->addWidget(m_lineCommentIndicator,3,1);
paramsLayout->addWidget(label,4,0);
paramsLayout->addWidget(m_lineCommentIndicator,4,1);
tie(m_lineCommentIndicator, "CommentIndicator", paramsLayout);
}

QComboBox *unitBox = new QComboBox;
fillAndSetComboBox("Unit",unitBox );
paramsLayout->addWidget(new QLabel("Unit"),4,0);
paramsLayout->addWidget(unitBox ,4,1);
tie(unitBox ,"Unit",paramsLayout);
QComboBox *unitBox = new QComboBox;
fillAndSetComboBox("Unit",unitBox );
paramsLayout->addWidget(new QLabel("Unit"),5,0);
paramsLayout->addWidget(unitBox ,5,1);
tie(unitBox ,"Unit",paramsLayout);
}
else
{
QComboBox *unitBox = new QComboBox;
fillAndSetComboBox("Unit",unitBox );
paramsLayout->addWidget(new QLabel("Unit"),3,0);
paramsLayout->addWidget(unitBox ,3,1);
tie(unitBox ,"Unit",paramsLayout);
}

QVBoxLayout *mainLayout = new QVBoxLayout;

Expand Down

0 comments on commit 2c48d3a

Please sign in to comment.