Ejemplo n.º 1
0
QString AMOldScanParametersDictionary::parseKeywordStringAndOperate(const QString &inputString){
	operatingNow_ = true;
	QString parsedString = parseKeywordString(inputString);
	operateImplementation(parsedString);
	operatingNow_ = false;
	emit parsed(parsedString);
	return parsedString;
}
Ejemplo n.º 2
0
void AMExporterGeneralAscii::writeHeader()
{
	if(!option_->headerIncluded())
		return;

	QString headerText = parseKeywordString(option_->headerText());

	normalizeLineEndings(headerText);
	if(headerText.right(1) != "\n")
		headerText.append("\n");	// ensure ends in newline
	convertNormalizedLineEndingsTo(option_->newlineDelimiter(), headerText);

	QTextStream ts(file_);
	ts << headerText;
}
Ejemplo n.º 3
0
void AMExporterAthena::writeHeader()
{
    if(!option_->headerIncluded())
        return;

    QString headerText = parseKeywordString(option_->headerText());
    headerText.prepend("# ");

    normalizeLineEndings(headerText);
    if(headerText.right(1) != "\n")
        headerText.append("\n");	// ensure ends in newline
    convertNormalizedLineEndingsTo(option_->newlineDelimiter(), headerText);

    headerText.replace("\n", "\n# ");
    headerText.append("-------------------------------------\n"); // Athena header delimeter from the data.

    QTextStream ts(file_);
    ts << headerText;
}
Ejemplo n.º 4
0
QString AMExporterGeneralAscii::exportScan(const AMScan *scan, const QString &destinationFolderPath, const AMExporterOption *option, int autoIndex)
{
	setCurrentAutoIndex(autoIndex);
	setCurrentFilename(option->fileName());
	setDestinationFolderPath(destinationFolderPath);

	// prepare scan and option
	setCurrentScan(scan);
	option_ = qobject_cast<const AMExporterOptionGeneralAscii*>(option);
	if(!option_) {
		AMErrorMon::report(AMErrorReport(this, AMErrorReport::Alert, -2, "Invalid options specified for the General Ascii Exporter. Please report this bug to the Acquaman developers."));
		return QString();
	}



	// prepare data sources
	if(!prepareDataSources())
		return QString();


	// prepare export file
	mainFileName_ = parseKeywordString( destinationFolderPath % "/" % option->fileName() );
	qDebug() << "Wants to save as " << mainFileName_;

	if(!openFile(mainFileName_)) {
		AMErrorMon::report(AMErrorReport(this, AMErrorReport::Alert, -3, "Export failed: Could not open the file '" % mainFileName_ % "' for writing.  Check that you have permission to save files there, and that a file with that name doesn't already exists."));
		return QString();
	}


	writeHeader();
	writeMainTable();
	writeSeparateSections();
	if(option_->includeHigherDimensionSources() && !writeSeparateFiles(destinationFolderPath)) {
		file_->close();
		return QString();
	}

	file_->close();
	return mainFileName_;
}
Ejemplo n.º 5
0
void VESPERSExporterSMAK::writeMainTable()
{
	QTextStream ts(file_);

	// 1. Column header.
	if(option_->columnHeaderIncluded()) {

		ts << "# ";

		for(int c=0; c<mainTableDataSources_.count(); c++) {

			setCurrentDataSource(mainTableDataSources_.at(c));

			if(mainTableIncludeX_.at(c))
				ts << "H" << option_->columnDelimiter() << "V" << option_->columnDelimiter();

			ts << parseKeywordString(option_->columnHeader()) << option_->columnDelimiter();
		}
	}

	ts << option_->newlineDelimiter() << option_->columnHeaderDelimiter() << option_->newlineDelimiter();

	// 2. rows
	VESPERS2DScanConfiguration *config = qobject_cast<VESPERS2DScanConfiguration *>(const_cast<AMScanConfiguration *>(currentScan_->scanConfiguration()));
	if (!config)
		return;

	QString suffix;

	if (config->ccdDetector().testFlag(VESPERS::Roper))
		suffix = "spe";

	else if (config->ccdDetector().testFlag(VESPERS::Mar))
		suffix = "tif";

	else if (config->ccdDetector().testFlag(VESPERS::Pilatus))
		suffix = "tif";

	QString ccdFileName = config->ccdFileName();
	int yRange = yRange_ == -1 ? currentScan_->scanSize(1) : (yRange_-1);
	int xRange = currentScan_->scanSize(0);

	for(int y = 0; y < yRange; y++) {

		for (int x = 0; x < xRange; x++){

			// over rows within columns
			for(int c=0; c<mainTableDataSources_.count(); c++) {

				setCurrentDataSource(mainTableDataSources_.at(c));
				AMDataSource* ds = currentScan_->dataSourceAt(currentDataSourceIndex_);
				int precision = option_->exportPrecision(ds->name());

				// print x and y column?
				if(mainTableIncludeX_.at(c)) {

					ts << ds->axisValue(0,x).toString(precision);
					ts << option_->columnDelimiter();
					ts << ds->axisValue(1, y).toString(precision);
					ts << option_->columnDelimiter();
				}

				if(ds->name().contains("FileNumber"))
					ts << QString("%1_%2.%3").arg(ccdFileName).arg(int(ds->value(AMnDIndex(x, y)))-1).arg(suffix);	// The -1 is because the value stored here is the NEXT number in the scan.  Purely a nomenclature setup from the EPICS interface.

				else
					ts << ds->value(AMnDIndex(x, y)).toString(precision);

				ts << option_->columnDelimiter();
			}

			ts << option_->newlineDelimiter();
		}
	}

	if (yRange_ != -1 && xIndex_ != -1){

		for (int x = 0; x < xIndex_; x++){

			// over rows within columns
			for(int c=0; c<mainTableDataSources_.count(); c++) {

				setCurrentDataSource(mainTableDataSources_.at(c));
				AMDataSource* ds = currentScan_->dataSourceAt(currentDataSourceIndex_);
				int precision = option_->exportPrecision(ds->name());

				// print x and y column?
				if(mainTableIncludeX_.at(c)) {

					ts << ds->axisValue(0,x).toString(precision);
					ts << option_->columnDelimiter();
					ts << ds->axisValue(1, yRange_-1).toString(precision);
					ts << option_->columnDelimiter();
				}

				if(ds->name().contains("FileNumber"))
					ts << QString("%1_%2.%3").arg(ccdFileName).arg(int(ds->value(AMnDIndex(x, yRange_-1)))-1).arg(suffix);	// The -1 is because the value stored here is the NEXT number in the scan.  Purely a nomenclature setup from the EPICS interface.

				else
					ts << ds->value(AMnDIndex(x, yRange_-1)).toString(precision);

				ts << option_->columnDelimiter();
			}


			ts << option_->newlineDelimiter();
		}
	}


	ts << option_->newlineDelimiter();
}
Ejemplo n.º 6
0
bool AMExporter2DAscii::writeSeparateFiles(const QString &destinationFolderPath)
{
	if (option_->higherDimensionsInRows()){

		for (int s = 0, sSize = separateFileDataSources_.size(); s < sSize; s++) {

			setCurrentDataSource(separateFileDataSources_.at(s));	// sets currentDataSourceIndex_
			AMDataSource* source = currentScan_->dataSourceAt(currentDataSourceIndex_);

			QFile output;
			QString separateFileName = parseKeywordString( destinationFolderPath % "/" % option_->separateSectionFileName() );
			separateFileName = removeNonPrintableCharacters(separateFileName);

			if(!openFile(&output, separateFileName)) {
				AMErrorMon::report(AMErrorReport(this, AMErrorReport::Alert, -4, "Export failed (partially): You selected to create separate files for certain data sets. Could not open the file '" % separateFileName % "' for writing.  Check that you have permission to save files there, and that a file with that name doesn't already exists."));
				return false;
			}

			int spectraSize = source->size(2);
			QString columnDelimiter = option_->columnDelimiter();
			QString newLineDelimiter = option_->newlineDelimiter();
			QTextStream out(&output);
			int yRange = yRange_ == -1 ? currentScan_->scanSize(1) : (yRange_-1);
			int xRange = currentScan_->scanSize(0);

			for (int y = 0; y < yRange; y++){

				for (int x = 0; x < xRange; x++){

					QVector<double> data(spectraSize);
					source->values(AMnDIndex(x, y, 0), AMnDIndex(x, y, spectraSize-1), data.data());

					for (int i = 0; i < spectraSize; i++)
						out << data.at(i) << columnDelimiter;

					out << newLineDelimiter;
				}
			}

			if (yRange_ != -1 && xIndex_ != -1){

				for (int i = 0; i < xIndex_; i++){

					QVector<double> data(spectraSize);
					source->values(AMnDIndex(i, yRange_-1, 0), AMnDIndex(i, yRange_-1, spectraSize-1), data.data());

					for (int i = 0; i < spectraSize; i++)
						out << data.at(i) << columnDelimiter;

					out << newLineDelimiter;
				}

				out << newLineDelimiter;
			}

			output.close();
		}
	}

	else{

		for (int s = 0, sSize = separateFileDataSources_.size(); s < sSize; s++) {

			setCurrentDataSource(separateFileDataSources_.at(s));	// sets currentDataSourceIndex_
			AMDataSource* source = currentScan_->dataSourceAt(currentDataSourceIndex_);

			QFile output;
			QString separateFileName = parseKeywordString( destinationFolderPath % "/" % option_->separateSectionFileName() );
			separateFileName = removeNonPrintableCharacters(separateFileName);

			if(!openFile(&output, separateFileName)) {
				AMErrorMon::report(AMErrorReport(this, AMErrorReport::Alert, -4, "Export failed (partially): You selected to create separate files for certain data sets. Could not open the file '" % separateFileName % "' for writing.  Check that you have permission to save files there, and that a file with that name doesn't already exists."));
				return false;
			}

			int spectraSize = source->size(2);
			QString columnDelimiter = option_->columnDelimiter();
			QString newLineDelimiter = option_->newlineDelimiter();
			QTextStream out(&output);
			int yRange = yRange_ == -1 ? currentScan_->scanSize(1) : (yRange_-1);
			int xRange = currentScan_->scanSize(0);

			for (int i = 0; i < spectraSize; i++){

				for (int y = 0; y < yRange; y++)
					for (int x = 0; x < xRange; x++)
						out << double(source->value(AMnDIndex(x, y, i))) << columnDelimiter;

				if (yRange_ != -1 && xIndex_ != -1){

					for (int x = 0; x < xIndex_; x++)
						out << double(source->value(AMnDIndex(x, yRange_-1, i))) << columnDelimiter;
				}

				out << newLineDelimiter;
			}

			output.close();
		}
	}

	return true;
}
Ejemplo n.º 7
0
void AMExporter2DAscii::writeMainTable()
{
	QTextStream ts(file_);

	// 1. Column header.
	if(option_->columnHeaderIncluded()) {

		ts << "# ";

		for(int c=0; c<mainTableDataSources_.count(); c++) {

			setCurrentDataSource(mainTableDataSources_.at(c));

			if(mainTableIncludeX_.at(c))
				ts << currentScan_->rawData()->scanAxisAt(0).name << option_->columnDelimiter() << currentScan_->rawData()->scanAxisAt(1).name << option_->columnDelimiter();

			ts << parseKeywordString(option_->columnHeader()) << option_->columnDelimiter();
		}
	}

	ts << option_->newlineDelimiter() << option_->columnHeaderDelimiter() << option_->newlineDelimiter();

	// 2. rows
	int yRange = yRange_ == -1 ? currentScan_->scanSize(1) : (yRange_-1);
	int xRange = currentScan_->scanSize(0);

	for(int y = 0; y < yRange; y++) {

		for (int x = 0; x < xRange; x++){

			// over rows within columns
			for(int c=0; c<mainTableDataSources_.count(); c++) {
				setCurrentDataSource(mainTableDataSources_.at(c));
				AMDataSource* ds = currentScan_->dataSourceAt(currentDataSourceIndex_);

				// print x and y column?
				if(mainTableIncludeX_.at(c)) {

					ts << ds->axisValue(0, x).toString();
					ts << option_->columnDelimiter();
					ts << ds->axisValue(1, y).toString();
					ts << option_->columnDelimiter();
				}

				ts << ds->value(AMnDIndex(x, y)).toString();

				ts << option_->columnDelimiter();
			}

			ts << option_->newlineDelimiter();
		}
	}

	if (yRange_ != -1 && xIndex_ != -1){

		for (int i = 0; i < xIndex_; i++){

			// over rows within columns
			for(int c=0; c<mainTableDataSources_.count(); c++) {
				setCurrentDataSource(mainTableDataSources_.at(c));
				AMDataSource* ds = currentScan_->dataSourceAt(currentDataSourceIndex_);

				// print x and y column?
				if(mainTableIncludeX_.at(c)) {

					ts << ds->axisValue(0,i).toString();
					ts << option_->columnDelimiter();
					ts << ds->axisValue(1, yRange_-1).toString();
					ts << option_->columnDelimiter();
				}

				ts << ds->value(AMnDIndex(i, yRange_-1)).toString();

				ts << option_->columnDelimiter();
			}

			ts << option_->newlineDelimiter();
		}
	}

	ts << option_->newlineDelimiter();
}
Ejemplo n.º 8
0
bool AMExporterGeneralAscii::writeSeparateFiles(const QString& destinationFolderPath)
{
	for(int s=0; s<separateFileDataSources_.count(); s++) {

		setCurrentDataSource(separateFileDataSources_.at(s));	// sets currentDataSourceIndex_
		AMDataSource* ds = currentScan_->dataSourceAt(currentDataSourceIndex_);

		QFile file;
		QString separateFileName = parseKeywordString( destinationFolderPath % "/" % option_->separateSectionFileName() );

		if(!openFile(&file, separateFileName)) {
			AMErrorMon::report(AMErrorReport(this, AMErrorReport::Alert, -4, "Export failed (partially): You selected to create separate files for certain data sets. Could not open the file '" % separateFileName % "' for writing.  Check that you have permission to save files there, and that a file with that name doesn't already exists."));
			return false;
		}

		QTextStream ts(&file);

		// section header?
		if(option_->sectionHeaderIncluded()) {
			ts << parseKeywordString(option_->sectionHeader());
			ts << option_->newlineDelimiter();
		}

		// column header?
		if(option_->columnHeaderIncluded()) {
			// 1D data sources:
			if(ds->rank() == 0) {
				ts << parseKeywordString(option_->columnHeader()) << option_->columnDelimiter();
			}
			else if(ds->rank() == 1) {
				if(separateFileIncludeX_.at(s))
					ts << parseKeywordString(option_->columnHeader()) << ".X" << option_->columnDelimiter();
				ts << parseKeywordString(option_->columnHeader()) << option_->columnDelimiter();
			}
			else if(ds->rank() == 2) {	// 2D
				if(separateFileIncludeX_.at(s))
					ts << parseKeywordString(option_->columnHeader()) << ".X" << option_->columnDelimiter();
				// need a loop over the second axis columns
				for(int cc=0; cc<ds->size(1); cc++) {
					setCurrentColumnIndex(cc);
					ts << parseKeywordString(option_->columnHeader()) << "[" << ds->axisValue(1, cc).toString() << ds->axisInfoAt(1).units << "]" << option_->columnDelimiter();
				}
			}
			ts << option_->newlineDelimiter() << option_->columnHeaderDelimiter() << option_->newlineDelimiter();
		}

		// table
		switch(ds->rank()) {
		case 0:
			ts << ds->value(AMnDIndex()).toString() << option_->columnDelimiter() << option_->newlineDelimiter();
			break;
		case 1: {
			int maxTableRows = ds->size(0);
			for(int r=0; r<maxTableRows; r++) {
				if(separateFileIncludeX_.at(s)) {
					ts << ds->axisValue(0,r).toString() << option_->columnDelimiter();
				}
				ts << ds->value(r).toString() << option_->columnDelimiter() << option_->newlineDelimiter();
			}
		}
		break;
		case 2: {
			int maxTableRows = ds->size(0);
			for(int r=0; r<maxTableRows; r++) {
				if(separateFileIncludeX_.at(s))
					ts << ds->axisValue(0,r).toString() << option_->columnDelimiter();
				// need a loop over the second axis columns
				for(int cc=0; cc<ds->size(1); cc++) {
					ts << ds->value(AMnDIndex(r,cc)).toString() << option_->columnDelimiter();
				}
				ts << option_->newlineDelimiter();
			}
		}
		break;
		default:
			/// \todo Implement 3D
			break;
		}
	}

	return true;
}
Ejemplo n.º 9
0
void AMExporterGeneralAscii::writeSeparateSections()
{
	QTextStream ts(file_);

	for(int s=0; s<separateSectionDataSources_.count(); s++) {

		ts << option_->newlineDelimiter();

		setCurrentDataSource(separateSectionDataSources_.at(s));	// sets currentDataSourceIndex_
		AMDataSource* ds = currentScan_->dataSourceAt(currentDataSourceIndex_);

		// section header?
		if(option_->sectionHeaderIncluded()) {
			ts << parseKeywordString(option_->sectionHeader());
			ts << option_->newlineDelimiter();
		}

		// column header?
		if(option_->columnHeaderIncluded()) {
			// 1D data sources:
			if(ds->rank() == 0) {
				ts << parseKeywordString(option_->columnHeader()) << option_->columnDelimiter();
			}
			else if(ds->rank() == 1) {
				if(separateSectionIncludeX_.at(s))
					ts << parseKeywordString(option_->columnHeader()) << ".X" << option_->columnDelimiter();
				ts << parseKeywordString(option_->columnHeader()) << option_->columnDelimiter();
			}
			else if(ds->rank() == 2) {	// 2D
				if(separateSectionIncludeX_.at(s))
					ts << parseKeywordString(option_->columnHeader()) << ".X" << option_->columnDelimiter();
				// need a loop over the second axis columns
				for(int cc=0; cc<ds->size(1); cc++) {
					setCurrentColumnIndex(cc);
					ts << parseKeywordString(option_->columnHeader()) << "[" << ds->axisValue(1, cc).toString() << ds->axisInfoAt(1).units << "]" << option_->columnDelimiter();
				}
			}
			ts << option_->newlineDelimiter() << option_->columnHeaderDelimiter() << option_->newlineDelimiter();
		}

		// table
		switch(ds->rank()) {
		case 0:
			ts << ds->value(AMnDIndex()).toString() << option_->columnDelimiter() << option_->newlineDelimiter();
			break;
		case 1: {
			int maxTableRows = ds->size(0);
			for(int r=0; r<maxTableRows; r++) {
				if(separateSectionIncludeX_.at(s)) {
					ts << ds->axisValue(0,r).toString() << option_->columnDelimiter();
				}
				ts << ds->value(r).toString() << option_->columnDelimiter() << option_->newlineDelimiter();
			}
		}
		break;
		case 2: {
			int maxTableRows = ds->size(0);
			for(int r=0; r<maxTableRows; r++) {
				if(separateSectionIncludeX_.at(s))
					ts << ds->axisValue(0,r).toString() << option_->columnDelimiter();
				// need a loop over the second axis columns
				for(int cc=0; cc<ds->size(1); cc++) {
					ts << ds->value(AMnDIndex(r,cc)).toString() << option_->columnDelimiter();
				}
				ts << option_->newlineDelimiter();
			}
		}
		break;
		default:
			/// \todo Implement 3D
			break;
		}
	}
}
Ejemplo n.º 10
0
void AMExporterGeneralAscii::writeMainTable()
{
	QTextStream ts(file_);

	// 1. Column header.
	int maxTableRows = 0;
	if(option_->columnHeaderIncluded()) {
		for(int c=0; c<mainTableDataSources_.count(); c++) {
			setCurrentDataSource(mainTableDataSources_.at(c));
			AMDataSource* ds = currentScan_->dataSourceAt(currentDataSourceIndex_);

			if(ds->size(0) > maxTableRows)
				maxTableRows = ds->size(0); // convenient... lets figure this out while we're looping through anyway

			// 1D data sources:
			if(ds->rank() == 1) {
				if(mainTableIncludeX_.at(c))
					ts << parseKeywordString(option_->columnHeader()) << ".X" << option_->columnDelimiter();
				ts << parseKeywordString(option_->columnHeader()) << option_->columnDelimiter();
			}
			else {	// 2D
				if(mainTableIncludeX_.at(c))
					ts << parseKeywordString(option_->columnHeader()) << ".X" << option_->columnDelimiter();
				// need a loop over the second axis columns
				for(int cc=0; cc<ds->size(1); cc++) {
					setCurrentColumnIndex(cc);
					ts << parseKeywordString(option_->columnHeader()) << "[" << ds->axisValue(1, cc).toString() << ds->axisInfoAt(1).units << "]" << option_->columnDelimiter();
				}
			}
		}
		ts << option_->newlineDelimiter() << option_->columnHeaderDelimiter() << option_->newlineDelimiter();
	}


	// 2. rows
	for(int r=0; r<maxTableRows; r++) {

		// over rows within columns
		for(int c=0; c<mainTableDataSources_.count(); c++) {
			setCurrentDataSource(mainTableDataSources_.at(c));
			AMDataSource* ds = currentScan_->dataSourceAt(currentDataSourceIndex_);

			bool doPrint = (ds->size(0) > r);

			// print x column?
			if(mainTableIncludeX_.at(c)) {
				if(doPrint)
					ts << ds->axisValue(0,r).toString();
				ts << option_->columnDelimiter();
			}

			// 1D data sources:
			if(ds->rank() == 1) {
				if(doPrint)
					ts << ds->value(r).toString();
				ts << option_->columnDelimiter();
			}
			else if(ds->rank() == 2) {
				// need a loop over the second axis columns
				for(int cc=0; cc<ds->size(1); cc++) {
					if(doPrint)
						ts << ds->value(AMnDIndex(r,cc)).toString();
					ts << option_->columnDelimiter();
				}
			}
		}
		ts << option_->newlineDelimiter();
	}
}
Ejemplo n.º 11
0
void AMExporterGeneralAscii::writeSeparateSections()
{
	QTextStream ts(file_);

	if (option_->higherDimensionsInRows()){

		for(int s=0; s<separateSectionDataSources_.count(); s++) {

			ts << option_->newlineDelimiter();

			setCurrentDataSource(separateSectionDataSources_.at(s));	// sets currentDataSourceIndex_
			AMDataSource* ds = currentScan_->dataSourceAt(currentDataSourceIndex_);
			int precision = option_->exportPrecision(ds->name());

			// section header?
			if(option_->sectionHeaderIncluded()) {
				ts << parseKeywordString(option_->sectionHeader());
				ts << option_->newlineDelimiter();
			}

			// column header?
			if(option_->columnHeaderIncluded()) {
				// 1D data sources:
				if(ds->rank() == 0) {
					ts << parseKeywordString(option_->columnHeader()) << option_->columnDelimiter();
				}
				else if(ds->rank() == 1) {
					if(separateSectionIncludeX_.at(s))
						ts << parseKeywordString(option_->columnHeader()) << ".X" << option_->columnDelimiter();
					ts << parseKeywordString(option_->columnHeader()) << option_->columnDelimiter();
				}
				else if(ds->rank() == 2) {	// 2D
					if(separateSectionIncludeX_.at(s))
						ts << parseKeywordString(option_->columnHeader()) << ".X" << option_->columnDelimiter();
					// need a loop over the second axis columns
					for(int cc=0; cc<ds->size(1); cc++) {
						setCurrentColumnIndex(cc);
						ts << parseKeywordString(option_->columnHeader()) << "[" << ds->axisValue(1, cc).toString(precision) << ds->axisInfoAt(1).units << "]" << option_->columnDelimiter();
					}
				}
				ts << option_->newlineDelimiter() << option_->columnHeaderDelimiter() << option_->newlineDelimiter();
			}

			// table
			switch(ds->rank()) {
			case 0:
				ts << ds->value(AMnDIndex()).toString(precision) << option_->columnDelimiter() << option_->newlineDelimiter();
				break;
			case 1: {
				int maxTableRows = ds->size(0);
				for(int r=0; r<maxTableRows; r++) {
					if(separateSectionIncludeX_.at(s)) {
						ts << ds->axisValue(0,r).toString(precision) << option_->columnDelimiter();
					}
					ts << ds->value(r).toString(precision) << option_->columnDelimiter() << option_->newlineDelimiter();
				}
			}
				break;
			case 2: {
				int maxTableRows = ds->size(0);
				for(int r=0; r<maxTableRows; r++) {
					if(separateSectionIncludeX_.at(s))
						ts << ds->axisValue(0,r).toString(precision) << option_->columnDelimiter();
					// need a loop over the second axis columns
					for(int cc=0; cc<ds->size(1); cc++) {
						ts << ds->value(AMnDIndex(r,cc)).toString(precision) << option_->columnDelimiter();
					}
					ts << option_->newlineDelimiter();
				}
			}
				break;
			default:
				/// \todo Implement 3D
				break;
			}
		}
	}

	// For writing out in columns.  Essentially transposing the file.
	else{

		for(int s=0; s<separateSectionDataSources_.count(); s++) {

			setCurrentDataSource(separateSectionDataSources_.at(s));	// sets currentDataSourceIndex_
			AMDataSource* ds = currentScan_->dataSourceAt(currentDataSourceIndex_);
			int precision = option_->exportPrecision(ds->name());

			// section header?
			if(option_->sectionHeaderIncluded()) {
				ts << parseKeywordString(option_->sectionHeader());
				ts << option_->newlineDelimiter();
			}

			// If including the X values.
			if (separateSectionIncludeX_.at(s)){

				switch(ds->rank()){

				case 0:
					break;

				case 1:
				case 2:{

					ts << parseKeywordString(option_->columnHeader()) << ".X" << option_->columnDelimiter();

					int maxTableColumns = ds->size(0);

					for(int column = 0; column < maxTableColumns; column++)
						ts << ds->axisValue(0,column).toString(precision) << option_->columnDelimiter();

					ts << option_->newlineDelimiter();

					break;
				}

				default:
					/// \todo 3D.
					break;
				}
			}

			// Main table with column headers prefacing rows.
			switch (ds->rank()){

			case 0:{

				if(option_->columnHeaderIncluded())
					ts << parseKeywordString(option_->columnHeader()) << option_->columnDelimiter();

				ts << ds->value(AMnDIndex()).toString(precision) << option_->columnDelimiter() << option_->newlineDelimiter();

				break;
			}

			case 1:{

				if (option_->columnHeaderIncluded())
					ts << parseKeywordString(option_->columnHeader()) << option_->columnDelimiter();

				int maxTableColumns = ds->size(0);

				for(int column = 0; column < maxTableColumns; column++)
					ts << ds->value(column).toString(precision) << option_->columnDelimiter();

				ts << option_->newlineDelimiter();

				break;
			}

			case 2:{

				for (int cc = 0; cc < ds->size(1); cc++){

					if (option_->columnHeaderIncluded())
						ts << parseKeywordString(option_->columnHeader()) << "[" << ds->axisValue(1, cc).toString(precision) << ds->axisInfoAt(1).units << "]" << option_->columnDelimiter();

					int maxTableColumns = ds->size(0);

					for (int column = 0; column < maxTableColumns; column++)
						ts << ds->value(AMnDIndex(column, cc)).toString(precision) << option_->columnDelimiter();

					ts << option_->newlineDelimiter();
				}

				break;
			}

			default:
				/// \todo 3D
				break;
			}
		}
	}
}
Ejemplo n.º 12
0
void VESPERSExporter2DAscii::writeMainTable()
{
	QTextStream ts(file_);

	// 1. Column header.
	if(option_->columnHeaderIncluded()) {

		ts << "# ";

		for(int c=0; c<mainTableDataSources_.count(); c++) {

			setCurrentDataSource(mainTableDataSources_.at(c));

			if(mainTableIncludeX_.at(c))
				ts << currentScan_->rawData()->scanAxisAt(0).name << option_->columnDelimiter() << currentScan_->rawData()->scanAxisAt(1).name << option_->columnDelimiter();

			ts << parseKeywordString(option_->columnHeader()) << option_->columnDelimiter();
		}
	}

	ts << option_->newlineDelimiter() << option_->columnHeaderDelimiter() << option_->newlineDelimiter();

	// 2. rows
	VESPERS::CCDDetectors ccdDetector;
	QString ccdFileName = "";

	VESPERS2DScanConfiguration *configuration2D = qobject_cast<VESPERS2DScanConfiguration *>(const_cast<AMScanConfiguration *>(currentScan_->scanConfiguration()));
	VESPERSTimedLineScanConfiguration *timedConfiguration = qobject_cast<VESPERSTimedLineScanConfiguration *>(const_cast<AMScanConfiguration *>(currentScan_->scanConfiguration()));

	if (configuration2D){

		ccdDetector = configuration2D->ccdDetector();
		ccdFileName = configuration2D->ccdFileName();
	}

	else if (timedConfiguration){

		ccdDetector = timedConfiguration->ccdDetector();
		ccdFileName = timedConfiguration->ccdFileName();
	}

	else
		return;

	QString ccdString;

	// This will return -1 if it fails.  This means any checks inside this loop will always fail if the CCD was not included.
	int yRange = yRange_ == -1 ? currentScan_->scanSize(1) : (yRange_-1);
	int xRange = currentScan_->scanSize(0);


	if (ccdDetector.testFlag(VESPERS::Roper))
		ccdString = ccdFileName % "_%1.spe";

	else if (ccdDetector.testFlag(VESPERS::Mar))
		ccdString = ccdFileName % "_%1.tif";

	else if (ccdDetector.testFlag(VESPERS::Pilatus))
		ccdString = ccdFileName % "-%1.tif";
	else
		ccdString = "";

	for(int y = 0; y < yRange; y++) {

		for (int x = 0; x < xRange; x++){

			// over rows within columns
			for(int c=0; c<mainTableDataSources_.count(); c++) {
				setCurrentDataSource(mainTableDataSources_.at(c));
				AMDataSource* ds = currentScan_->dataSourceAt(currentDataSourceIndex_);
				int precision = option_->exportPrecision(ds->name());

				// print x and y column?
				if(mainTableIncludeX_.at(c)) {

					ts << ds->axisValue(0, x).toString(precision);
					ts << option_->columnDelimiter();
					ts << ds->axisValue(1, y).toString(precision);
					ts << option_->columnDelimiter();
				}

				if(ds->name().contains("FileNumber"))
					ts << QString(ccdString).arg(int(ds->value(AMnDIndex(x, y)))-1);	// The -1 is because the value stored here is the NEXT number in the scan.  Purely a nomenclature setup from the EPICS interface.
				else
					ts << ds->value(AMnDIndex(x, y)).toString(precision);

				ts << option_->columnDelimiter();
			}

			ts << option_->newlineDelimiter();
		}
	}

	if (yRange_ != -1 && xIndex_ != -1){

		for (int x = 0; x < xIndex_; x++){

			// over rows within columns
			for(int c=0; c<mainTableDataSources_.count(); c++) {

				setCurrentDataSource(mainTableDataSources_.at(c));
				AMDataSource* ds = currentScan_->dataSourceAt(currentDataSourceIndex_);
				int precision = option_->exportPrecision(ds->name());

				// print x and y column?
				if(mainTableIncludeX_.at(c)) {

					ts << ds->axisValue(0,x).toString(precision);
					ts << option_->columnDelimiter();
					ts << ds->axisValue(1, yRange_-1).toString(precision);
					ts << option_->columnDelimiter();
				}

				if(ds->name().contains("FileNumber"))
					ts << QString(ccdString).arg(int(ds->value(AMnDIndex(x, yRange_-1)))-1);	// The -1 is because the value stored here is the NEXT number in the scan.  Purely a nomenclature setup from the EPICS interface.

				else
					ts << ds->value(AMnDIndex(x, yRange_-1)).toString(precision);

				ts << option_->columnDelimiter();
			}


			ts << option_->newlineDelimiter();
		}
	}


	ts << option_->newlineDelimiter();
}