Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions QtPMbrowser/pmbrowserwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -463,11 +463,11 @@ void PMbrowserWindow::exportSubTree(QTreeWidgetItem* item, const QString& path,
hkTreeNode* traceentry = v.value<hkTreeNode*>();
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);
Expand All @@ -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<char*>(&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<std::int32_t>(offset_end - offset_record - sizeof(PackedFileRecordHeader));
poutfile->seekp(offset_record);
poutfile->write(reinterpret_cast<char*>(&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";
Expand Down Expand Up @@ -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()));
Expand Down
18 changes: 14 additions & 4 deletions hekatoolslib/exportIBW.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<int32_t>(trdatapoints);
wh.nDim[0] = static_cast<int32_t>(trdatapoints);
Expand All @@ -142,6 +148,7 @@ namespace hkLib {
outfile.write(reinterpret_cast<char*>(&wh), numbytes_wh);
outfile.write(reinterpret_cast<char*>(target.get()), sizeof(double) * trdatapoints);
outfile.write(note.data(), note.size());
return err;
}

// Warning: this ist not recognize as a valid record by Igor!
Expand Down Expand Up @@ -170,8 +177,9 @@ namespace hkLib {
outfile.write(reinterpret_cast<char*>(&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;
Expand All @@ -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;
}

}
6 changes: 4 additions & 2 deletions hekatoolslib/exportIBW.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

}

Expand Down