I am reading the binary created by the sensor. I have a problem reading a float with varying precision (32 or 64). I can read them in MATLAB (64-bit), but Qt (32-bit on Windows) gives the wrong values. I can read before dtmth (please edit the structure below). After that, I get the Inf value for baseline . Actually this value is 0 . As you can see, I changed the MSB (LittleEndian). If I save BigEndian, I get 0 for the baseline, but other values ββare wrong. My desktop is 64 bit.
I checked the number of bytes and they are correct. I think the problem is the accuracy of the machine.
QDataStream in(&file); in.setByteOrder(QDataStream::LittleEndian); params p; in >> p.filetype; in >> p.projectid; in >> p.datamin; in >> p.dtyear; in >> p.dtmth; in >> p.baseline; in >> p.startfrequ;
Where p is the structure defined as:
struct params { quint8 filetype; quint16 projectid; double datamin; quint16 dtyear; quint8 dtmth; float baseline; double startfrequ; };
I can read them in MATLAB. My matlab is a 64 bit version where I read data types as follows:
MATLAB: uint8 filetype; uint16 projectid; float64 datamin; uint16 dtyear; uint8 dtmth; float32 baseline; float64 startfrequ;
Let me know if I missed any details.
EDIT:
Reading file:
QString fileName = QFileDialog::getOpenFileName(this, tr("Open File"), QString(), tr("Raw Files (*.msr);;All files (*.*)")); if (!fileName.isEmpty()) { qDebug("Attempting to open file.."); QFile file(fileName); if (!file.open(QIODevice::ReadOnly)) { QMessageBox::critical(this, tr("Error"), tr("Could not open file")); return; } QDataStream in(&file);
Thank you very much in advance.
source share