diff --git a/QtPMbrowser/pmbrowserwindow.cpp b/QtPMbrowser/pmbrowserwindow.cpp index 2e5abbb..2deb102 100644 --- a/QtPMbrowser/pmbrowserwindow.cpp +++ b/QtPMbrowser/pmbrowserwindow.cpp @@ -463,11 +463,11 @@ void PMbrowserWindow::exportSubTree(QTreeWidgetItem* item, const QString& path, hkTreeNode* traceentry = v.value(); auto tracelabel = QString::fromStdString(formTraceName(*traceentry, indextrace)); QString wavename = prefix + QString("_%1_%2_%3_%4").arg(indexgroup).arg(indexseries).arg(indexsweep).arg(tracelabel); - ui->textEdit->append("exporting " + wavename); - ui->textEdit->update(); if (export_type == ExportType::Igor) { + auto wname = wavename.toStdString(); + unsigned err{0}; if (poutfile == nullptr) { // multi-file export QString filename = path + wavename + ".ibw"; std::ofstream outfile(filename.toStdString(), std::ios::out | std::ios::binary); @@ -476,20 +476,23 @@ void PMbrowserWindow::exportSubTree(QTreeWidgetItem* item, const QString& path, msg << "error opening file '" << filename.toStdString() << "' for writing: " << strerror(errno); throw std::runtime_error(msg.str()); } - ExportTrace(infile, *traceentry, outfile, wavename.toStdString()); + err = ExportTrace(infile, *traceentry, outfile, wname); } else { PackedFileRecordHeader pfrh{}; pfrh.recordType = kWaveRecord; size_t offset_record = poutfile->tellp(); poutfile->write(reinterpret_cast(&pfrh), sizeof(PackedFileRecordHeader)); - ExportTrace(infile, *traceentry, *poutfile, wavename.toStdString()); + err = ExportTrace(infile, *traceentry, *poutfile, wname); size_t offset_end = poutfile->tellp(); - pfrh.numDataBytes = int32_t(offset_end - offset_record - sizeof(PackedFileRecordHeader)); + pfrh.numDataBytes = static_cast(offset_end - offset_record - sizeof(PackedFileRecordHeader)); poutfile->seekp(offset_record); poutfile->write(reinterpret_cast(&pfrh), sizeof(PackedFileRecordHeader)); poutfile->seekp(offset_end); } + if(err & WARNFLAG_WNAMETRUNCATED){ + ui->textEdit->append("Warning: wavename truncated to " + QString::fromUtf8(wname)); + } } else if (export_type == ExportType::NPY) { QString filename = path + wavename + ".npy"; @@ -781,7 +784,10 @@ void PMbrowserWindow::on_actionExport_All_as_IBW_triggered() } ui->textEdit->append("exporting..."); try { - ExportAllTraces(infile, *datfile, path.toStdString(), prefix.toStdString()); + auto err = ExportAllTraces(infile, *datfile, path.toStdString(), prefix.toStdString()); + if(err & hkLib::WARNFLAG_WNAMETRUNCATED) { + ui->textEdit->append("wavename(s) truncated in export"); + } } catch (std::exception& e) { QString msg = QString("Error while exporting:\n%1").arg(QString(e.what())); diff --git a/hekatoolslib/exportIBW.cpp b/hekatoolslib/exportIBW.cpp index e201c69..23787f2 100644 --- a/hekatoolslib/exportIBW.cpp +++ b/hekatoolslib/exportIBW.cpp @@ -76,9 +76,10 @@ namespace hkLib { } - void ExportTrace(std::istream& datafile, hkTreeNode& TrRecord, std::ostream& outfile, const std::string& wavename) + unsigned ExportTrace(std::istream& datafile, hkTreeNode& TrRecord, std::ostream& outfile, std::string& wavename) { - assert(TrRecord.getLevel() == hkTreeNode::LevelTrace); + unsigned err{0}; + assert(TrRecord.getLevel() == hkTreeNode::LevelTrace); char dataformat = TrRecord.getChar(TrDataFormat); std::string xunit, yunit; @@ -123,6 +124,11 @@ namespace hkLib { bh.wfmSize = int32_t(numbytes_wh + sizeof(double) * trdatapoints); // we will calculate checksum later, all other entries in bh remain 0 wh.type = NT_FP64; + if(wavename.length()>MAX_WAVE_NAME5){ + err|=WARNFLAG_WNAMETRUNCATED; + // truncate front of wavename: + wavename = std::string("X") + wavename.substr(wavename.length() - MAX_WAVE_NAME5 +1); + } wavename.copy(wh.bname, MAX_WAVE_NAME5); wh.npnts = static_cast(trdatapoints); wh.nDim[0] = static_cast(trdatapoints); @@ -142,6 +148,7 @@ namespace hkLib { outfile.write(reinterpret_cast(&wh), numbytes_wh); outfile.write(reinterpret_cast(target.get()), sizeof(double) * trdatapoints); outfile.write(note.data(), note.size()); + return err; } // Warning: this ist not recognize as a valid record by Igor! @@ -170,8 +177,9 @@ namespace hkLib { outfile.write(reinterpret_cast(&pfhr), sizeof(PackedFileRecordHeader)); } - void ExportAllTraces(std::istream& datafile, DatFile& datf, const std::string& path, const std::string& prefix) + unsigned ExportAllTraces(std::istream& datafile, DatFile& datf, const std::string& path, const std::string& prefix) { + unsigned err{0}; int groupcount = 0; for (auto& group : datf.GetPulTree().GetRootNode().Children) { ++groupcount; @@ -189,11 +197,13 @@ namespace hkLib { wavename << formTraceName(trace, tracecount); std::string filename = path + wavename.str() + ".ibw"; std::ofstream outfile(filename, std::ios::binary | std::ios::out); - ExportTrace(datafile, trace, outfile, wavename.str()); + auto wname = wavename.str(); + err |= ExportTrace(datafile, trace, outfile, wname); } } } } + return err; } } diff --git a/hekatoolslib/exportIBW.h b/hekatoolslib/exportIBW.h index 6fb6442..514876c 100644 --- a/hekatoolslib/exportIBW.h +++ b/hekatoolslib/exportIBW.h @@ -54,10 +54,12 @@ namespace hkLib { kDataFolderEndRecord = 10, kPlatformRecord = 20; + constexpr unsigned WARNFLAG_WNAMETRUNCATED = 1; + void WriteIgorPlatformRecord(std::ostream& outfile); void WriteIgorProcedureRecord(std::ostream& outfile); - void ExportAllTraces(std::istream& datafile, DatFile& datf, const std::string& path, const std::string& prefix); - void ExportTrace(std::istream& datafile, hkTreeNode& TrRecord, std::ostream& outfile, const std::string& wavename); + unsigned ExportAllTraces(std::istream& datafile, DatFile& datf, const std::string& path, const std::string& prefix); + unsigned ExportTrace(std::istream& datafile, hkTreeNode& TrRecord, std::ostream& outfile, std::string& wavename); }