void AMTextStream::write(const AMMeasurementInfo &measurementInfo){ QTextStream::operator <<(measurementInfo.rank()); QTextStream::operator <<(separator_); QTextStream::operator <<(measurementInfo.name); QTextStream::operator <<(separator_); QTextStream::operator <<(measurementInfo.description); QTextStream::operator <<(separator_); QTextStream::operator <<(measurementInfo.units); QTextStream::operator <<(objectMarker_); if(measurementInfo.rank() > 0){ for(int x = 0; x < measurementInfo.rank(); x++){ AMAxisInfo oneAxisInfo = measurementInfo.axes.at(x); write(oneAxisInfo); } } QTextStream::operator <<(terminator_); }
bool SGM2013FastFileLoaderPlugin::load(AMScan *scan, const QString &userDataFolder, AMErrorMon *errorMonitor){ if(!scan) return false; // Clear the old scan axes to ensure we don't have any extras. scan->clearRawDataCompletely(); scan->rawData()->addScanAxis( AMAxisInfo("eV", 0, "Incident Energy", "eV") ); QFileInfo sourceFileInfo(scan->filePath()); if(sourceFileInfo.isRelative()) sourceFileInfo.setFile(userDataFolder + "/" + scan->filePath()); // open the file: QFile f(sourceFileInfo.filePath()); if(!f.open(QIODevice::ReadOnly)) { errorMonitor->exteriorReport(AMErrorReport(0, AMErrorReport::Serious, SGM2013FASTFILELOADERPLUGIN_CANNOT_OPEN_FILE, "SGM2013FastFileLoader parse error while loading scan data from file. Missing file.")); return false; } QTextStream fs(&f); QMap<int, QList<int> > measurementOrderByRank; // used in parsing the data file QString line; QStringList lp; QString versionString; int index; double dataValue; int insertionIndex = 0; bool informationSection = false; bool finishedHeader = false; while(!fs.atEnd()){ if(!finishedHeader) line = fs.readLine(); if(line == "Start Info") informationSection = true; else if(line.contains("Version: ")) versionString = line.remove("Version: "); else if(line == "End Info"){ informationSection = false; finishedHeader = true; line = ""; } else if(informationSection){ if(versionString == "SGM Generic Fast 0.1"){ if(!line.contains("Encoder Start Value:") && !line.contains("SpacingParam:") && !line.contains("C1Param:") && !line.contains("C2Param:") && !line.contains("SParam:") && !line.contains("ThetaParam:")){ lp = line.split("|!|!|"); index = lp.at(0).toInt(); if(index >= 0){ QString oneString = lp.at(1); AMTextStream measurementInfoStreamOut(&oneString); AMMeasurementInfo oneMeasurementInfo = AMMeasurementInfo(QString(), QString()); measurementInfoStreamOut.read(oneMeasurementInfo); if(measurementOrderByRank.contains(oneMeasurementInfo.rank())){ QList<int> thisRankList = measurementOrderByRank.value(oneMeasurementInfo.rank()); thisRankList.append(index); measurementOrderByRank.insert(oneMeasurementInfo.rank(), thisRankList); } else{ QList<int> newRankList; newRankList.append(index); measurementOrderByRank.insert(oneMeasurementInfo.rank(), newRankList); } scan->rawData()->addMeasurement(oneMeasurementInfo); } } } } else{ if(!fs.atEnd()){ fs >> dataValue; if(!fs.atEnd()){ scan->rawData()->beginInsertRows(1, -1); scan->rawData()->setAxisValue(0, insertionIndex, dataValue); // insert eV QList<int> rank0Measurements = measurementOrderByRank.value(0); for(int x = 0; x < rank0Measurements.count(); x++){ fs >> dataValue; scan->rawData()->setValue(AMnDIndex(insertionIndex), rank0Measurements.at(x), AMnDIndex(), dataValue); } scan->rawData()->endInsertRows(); insertionIndex++; } } }