/** Set value of a TimeSeriesProperty from input workspace * @brief AddSampleLog::setTimeSeriesData * @param run_obj * @param property_name * @param value_is_int */ void AddSampleLog::setTimeSeriesData(Run &run_obj, const std::string &property_name, bool value_is_int) { // get input and MatrixWorkspace_sptr data_ws = getProperty("TimeSeriesWorkspace"); int ws_index = getProperty("WorkspaceIndex"); if (ws_index < 0 || ws_index > static_cast<int>(data_ws->getNumberHistograms())) throw std::runtime_error("Input workspace index is out of range"); // get meta data bool epochtime(false); std::string timeunit; getMetaData(data_ws, epochtime, timeunit); bool is_second = timeunit == "Second"; // convert the data in workspace to time series property value std::vector<DateAndTime> time_vec = getTimes(data_ws, ws_index, epochtime, is_second, run_obj); if (value_is_int) { // integer property TimeSeriesProperty<int> *int_prop = dynamic_cast<TimeSeriesProperty<int> *>( run_obj.getProperty(property_name)); std::vector<int> value_vec = getIntValues(data_ws, ws_index); int_prop->addValues(time_vec, value_vec); } else { // double property TimeSeriesProperty<double> *int_prop = dynamic_cast<TimeSeriesProperty<double> *>( run_obj.getProperty(property_name)); std::vector<double> value_vec = getDblValues(data_ws, ws_index); int_prop->addValues(time_vec, value_vec); } return; }
int main() { //Declares all of the arrays that are to be used char inFileName[MAXFILENAMELENGTH]; char outFileName[MAXFILENAMELENGTH]; int fileContents[NUMINTSINFILE]; int addedContents[NUMINTSAFTERADDITION]; int subtractedContents[NUMINTSAFTERSUBTRACTION]; //Initializes the arrays to 0s initializeArray(addedContents, NUMINTSAFTERADDITION); initializeArray(fileContents, NUMINTSINFILE); initializeArray(subtractedContents, NUMINTSAFTERSUBTRACTION); //Declares the file streams to be used ifstream inFile; ofstream outFile; //Gets the input file name cout << "Please enter the file name to open: "; cin >> inFileName; //Gets the output file name cout << "Please enter the file name to write to: "; cin >> outFileName; //Reads in the values from the input file name to the input values array inFile.open(inFileName); if (!inFile.fail()) { cout << "Input file found." << endl; getIntValues(fileContents, NUMINTSINFILE, inFile); toScreen(fileContents, NUMINTSINFILE); } else { cout << "Input file not found. Ending program." << endl; return 1; } //Adds the values per instruction into another array addValues(fileContents, addedContents, NUMINTSINFILE, NUMINTSAFTERADDITION); //Subtracts the values per instruction into another array subtractValues(fileContents, subtractedContents, NUMINTSINFILE, NUMINTSAFTERSUBTRACTION); //Outputs the added and subtracted values to the output file name outFile.open(outFileName); if (!outFile.fail()) { cout << "Output file found." << endl; toScreen(addedContents, NUMINTSAFTERADDITION); toScreen(subtractedContents, NUMINTSAFTERSUBTRACTION); outFile << "Added values: " << endl; for (int i = 0; i < NUMINTSAFTERADDITION; i++) { outFile << addedContents[i] << " "; } outFile << "\nSubtracted values: " << endl; for (int i = 0; i < NUMINTSAFTERSUBTRACTION; i++) { outFile << subtractedContents[i] << " "; } } else { cout << "Output file not found. Ending program." << endl; return 1; } //Closes the file streams as to clean up system inFile.close(); outFile.close(); return 0; }