Avantes USB spectrometers are supplied with a Windows binary which generates one ROH and one RCM file when the user clicks "Save experiment". In the version of 6.0, the ROH file contains a header of 22 four-byte floats, then the spectrum as a float array and a footer of 3 floats. The first and last pixel numbers are specified in the header and determine the (length+1) of the spectral data. In the tested files, the length is (2032-211-1)=1820 pixels, but Kaitai determines this automatically anyway.
The wavelength calibration is stored as a polynomial with coefficients of 'wlintercept', 'wlx1', ... 'wlx4', the argument of which is the (pixel number + 1), as found out by comparing with the original Avantes converted data files. There is no intensity calibration saved, but it is recommended to do it in your program - the CCD in the spectrometer is so uneven that one should prepare exact pixel-to-pixel calibration curves to get reasonable spectral results.
The rest of the header floats is not known to the author. Note that the newer version of Avantes software has a different format, see also https://www.mathworks.com/matlabcentral/fileexchange/37103-avantes-to-matlab
The RCM file contains the user-specified comment, so it may be useful for automatic conversion of data. You may wish to divide the spectra by the integration time before comparing them.
Written and tested by Filip Dominec, 2017-2018
This page hosts a formal specification of Avantes USB spectrometer ROH file 6.0 using Kaitai Struct. This specification can be automatically translated into a variety of programming languages to get a parsing library.
All parsing code for C++11/STL generated by Kaitai Struct depends on the C++/STL runtime library. You have to install it before you can parse data.
For C++, the easiest way is to clone the runtime library sources and build them along with your project.
Using Kaitai Struct in C++/STL usually consists of 3 steps.
std::istream
). One can open local file for that, or use existing std::string
or char*
buffer.
#include <fstream>
std::ifstream is("path/to/local/file.roh", std::ifstream::binary);
#include <sstream>
std::istringstream is(str);
#include <sstream>
const char buf[] = { ... };
std::string str(buf, sizeof buf);
std::istringstream is(str);
#include "kaitai/kaitaistream.h"
kaitai::kstream ks(&is);
avantes_roh60_t data(&ks);
After that, one can get various attributes from the structure by invoking getter methods like:
data.unknown1() // => get unknown1
#pragma once
// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild
#include "kaitai/kaitaistruct.h"
#include <stdint.h>
#include <memory>
#include <vector>
#if KAITAI_STRUCT_VERSION < 9000L
#error "Incompatible Kaitai Struct C++/STL API: version 0.9 or later is required"
#endif
/**
* Avantes USB spectrometers are supplied with a Windows binary which
* generates one ROH and one RCM file when the user clicks "Save
* experiment". In the version of 6.0, the ROH file contains a header
* of 22 four-byte floats, then the spectrum as a float array and a
* footer of 3 floats. The first and last pixel numbers are specified in the
* header and determine the (length+1) of the spectral data. In the tested
* files, the length is (2032-211-1)=1820 pixels, but Kaitai determines this
* automatically anyway.
*
* The wavelength calibration is stored as a polynomial with coefficients
* of 'wlintercept', 'wlx1', ... 'wlx4', the argument of which is the
* (pixel number + 1), as found out by comparing with the original
* Avantes converted data files. There is no intensity calibration saved,
* but it is recommended to do it in your program - the CCD in the spectrometer
* is so uneven that one should prepare exact pixel-to-pixel calibration curves
* to get reasonable spectral results.
*
* The rest of the header floats is not known to the author. Note that the
* newer version of Avantes software has a different format, see also
* <https://www.mathworks.com/matlabcentral/fileexchange/37103-avantes-to-matlab>
*
* The RCM file contains the user-specified comment, so it may be useful
* for automatic conversion of data. You may wish to divide the spectra by
* the integration time before comparing them.
*
* Written and tested by Filip Dominec, 2017-2018
*/
class avantes_roh60_t : public kaitai::kstruct {
public:
avantes_roh60_t(kaitai::kstream* p__io, kaitai::kstruct* p__parent = nullptr, avantes_roh60_t* p__root = nullptr);
private:
void _read();
void _clean_up();
public:
~avantes_roh60_t();
private:
float m_unknown1;
float m_wlintercept;
float m_wlx1;
float m_wlx2;
float m_wlx3;
float m_wlx4;
std::unique_ptr<std::vector<float>> m_unknown2;
float m_ipixfirst;
float m_ipixlast;
std::unique_ptr<std::vector<float>> m_unknown3;
std::unique_ptr<std::vector<float>> m_spectrum;
float m_integration_ms;
float m_averaging;
float m_pixel_smoothing;
avantes_roh60_t* m__root;
kaitai::kstruct* m__parent;
public:
float unknown1() const { return m_unknown1; }
float wlintercept() const { return m_wlintercept; }
float wlx1() const { return m_wlx1; }
float wlx2() const { return m_wlx2; }
float wlx3() const { return m_wlx3; }
float wlx4() const { return m_wlx4; }
std::vector<float>* unknown2() const { return m_unknown2.get(); }
float ipixfirst() const { return m_ipixfirst; }
float ipixlast() const { return m_ipixlast; }
std::vector<float>* unknown3() const { return m_unknown3.get(); }
std::vector<float>* spectrum() const { return m_spectrum.get(); }
float integration_ms() const { return m_integration_ms; }
float averaging() const { return m_averaging; }
float pixel_smoothing() const { return m_pixel_smoothing; }
avantes_roh60_t* _root() const { return m__root; }
kaitai::kstruct* _parent() const { return m__parent; }
};
// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild
#include "avantes_roh60.h"
avantes_roh60_t::avantes_roh60_t(kaitai::kstream* p__io, kaitai::kstruct* p__parent, avantes_roh60_t* p__root) : kaitai::kstruct(p__io) {
m__parent = p__parent;
m__root = this;
m_unknown2 = nullptr;
m_unknown3 = nullptr;
m_spectrum = nullptr;
_read();
}
void avantes_roh60_t::_read() {
m_unknown1 = m__io->read_f4le();
m_wlintercept = m__io->read_f4le();
m_wlx1 = m__io->read_f4le();
m_wlx2 = m__io->read_f4le();
m_wlx3 = m__io->read_f4le();
m_wlx4 = m__io->read_f4le();
m_unknown2 = std::unique_ptr<std::vector<float>>(new std::vector<float>());
const int l_unknown2 = 9;
for (int i = 0; i < l_unknown2; i++) {
m_unknown2->push_back(std::move(m__io->read_f4le()));
}
m_ipixfirst = m__io->read_f4le();
m_ipixlast = m__io->read_f4le();
m_unknown3 = std::unique_ptr<std::vector<float>>(new std::vector<float>());
const int l_unknown3 = 4;
for (int i = 0; i < l_unknown3; i++) {
m_unknown3->push_back(std::move(m__io->read_f4le()));
}
m_spectrum = std::unique_ptr<std::vector<float>>(new std::vector<float>());
const int l_spectrum = ((static_cast<int>(ipixlast()) - static_cast<int>(ipixfirst())) - 1);
for (int i = 0; i < l_spectrum; i++) {
m_spectrum->push_back(std::move(m__io->read_f4le()));
}
m_integration_ms = m__io->read_f4le();
m_averaging = m__io->read_f4le();
m_pixel_smoothing = m__io->read_f4le();
}
avantes_roh60_t::~avantes_roh60_t() {
_clean_up();
}
void avantes_roh60_t::_clean_up() {
}