Skip to content

Commit

Permalink
Refs #6940 output vectors instead of a file
Browse files Browse the repository at this point in the history
  • Loading branch information
Vickie Lynch committed May 24, 2013
1 parent 877597b commit 8a64104
Showing 1 changed file with 24 additions and 7 deletions.
31 changes: 24 additions & 7 deletions Code/Mantid/Framework/MDEvents/src/SaveIsawQvector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,15 @@ namespace MDEvents
std::vector<std::string> exts;
exts.push_back(".bin");

declareProperty(new FileProperty("Filename", "", FileProperty::Save, exts),
"Path to an hkl file to save.");
declareProperty(new FileProperty("Filename", "", FileProperty::OptionalSave, exts),
"Optional path to an hkl file to save.");
declareProperty("RightHanded", true, "Save the Q-vector as k_f - k_i");
declareProperty("ISAWcoords", true, "Save the Q-vector with y gravitationally up and x pointing downstream");
std::vector<double>Qx_save,Qy_save,Qz_save;
declareProperty("Qx_vector", Qx_save, "The name of the vector in which to store the list of Qx", Direction::Output);
declareProperty("Qy_vector", Qy_save, "The name of the vector in which to store the list of Qy", Direction::Output);
declareProperty("Qz_vector", Qz_save, "The name of the vector in which to store the list of Qz", Direction::Output);

}

//----------------------------------------------------------------------------------------------
Expand All @@ -111,9 +116,13 @@ namespace MDEvents

// open the output file
std::string filename = getPropertyValue("Filename");
std::ofstream handle(filename.c_str(), std::ios::out | std::ios::binary);
if (!handle.is_open())
throw std::runtime_error("Failed to open file for writing");
std::ofstream handle;
if (!filename.empty())
{
handle.open(filename.c_str(), std::ios::out | std::ios::binary);
if (!handle.is_open())
throw std::runtime_error("Failed to open file for writing");
}
// set up a descripter of where we are going
this->initTargetWSDescr(wksp);

Expand Down Expand Up @@ -150,6 +159,7 @@ namespace MDEvents

// loop through the eventlists
float buffer[DIMS];
std::vector<double>Qx_save,Qy_save,Qz_save;
for (std::size_t i = 0; i < numSpectra; ++i)
{
// get a reference to the event list
Expand Down Expand Up @@ -179,14 +189,21 @@ namespace MDEvents
{
buffer[dim] = static_cast<float>(coord_signs[dim] * locCoord[coord_map[dim]]);
}
handle.write(reinterpret_cast<char*>(buffer), BUFF_SIZE);
Qx_save.push_back(static_cast<double>(buffer[0]));
Qy_save.push_back(static_cast<double>(buffer[1]));
Qz_save.push_back(static_cast<double>(buffer[2]));
if (!filename.empty()) handle.write(reinterpret_cast<char*>(buffer), BUFF_SIZE);
} // end of loop over events in list

prog.report();
} // end of loop over spectra
setProperty("Qx_vector", Qx_save);
setProperty("Qy_vector", Qy_save);
setProperty("Qz_vector", Qz_save);


// cleanup
handle.close();
if (!filename.empty())handle.close();
}

/**
Expand Down

0 comments on commit 8a64104

Please sign in to comment.