.roh file format: Perl parsing library

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://kr.mathworks.com/examples/matlab/community/20341-reading-spectra-from-avantes-binary-files-demonstration

The RCM file contains the user-specified comment, so it may be useful for automatic conversion of data.

Written and tested by Filip Dominec, 2017

File extension

roh

KS implementation details

License: CC0-1.0

This page hosts a formal specification of .roh file format using Kaitai Struct. This specification can be automatically translated into a variety of programming languages to get a parsing library.

Perl source code to parse .roh file format

AvantesRoh60.pm

# This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild

use strict;
use warnings;
use IO::KaitaiStruct 0.007_000;

########################################################################
package AvantesRoh60;

our @ISA = 'IO::KaitaiStruct::Struct';

sub from_file {
    my ($class, $filename) = @_;
    my $fd;

    open($fd, '<', $filename) or return undef;
    binmode($fd);
    return new($class, IO::KaitaiStruct::Stream->new($fd));
}

sub new {
    my ($class, $_io, $_parent, $_root) = @_;
    my $self = IO::KaitaiStruct::Struct->new($_io);

    bless $self, $class;
    $self->{_parent} = $_parent;
    $self->{_root} = $_root || $self;;

    $self->_read();

    return $self;
}

sub _read {
    my ($self) = @_;

    $self->{unknown1} = $self->{_io}->read_f4le();
    $self->{wlintercept} = $self->{_io}->read_f4le();
    $self->{wlx1} = $self->{_io}->read_f4le();
    $self->{wlx2} = $self->{_io}->read_f4le();
    $self->{wlx3} = $self->{_io}->read_f4le();
    $self->{wlx4} = $self->{_io}->read_f4le();
    $self->{unknown2} = ();
    my $n_unknown2 = 9;
    for (my $i = 0; $i < $n_unknown2; $i++) {
        $self->{unknown2}[$i] = $self->{_io}->read_f4le();
    }
    $self->{ipixfirst} = $self->{_io}->read_f4le();
    $self->{ipixlast} = $self->{_io}->read_f4le();
    $self->{unknown3} = ();
    my $n_unknown3 = 4;
    for (my $i = 0; $i < $n_unknown3; $i++) {
        $self->{unknown3}[$i] = $self->{_io}->read_f4le();
    }
    $self->{spectrum} = ();
    my $n_spectrum = ((int($self->ipixlast()) - int($self->ipixfirst())) - 1);
    for (my $i = 0; $i < $n_spectrum; $i++) {
        $self->{spectrum}[$i] = $self->{_io}->read_f4le();
    }
    $self->{unknown4} = ();
    my $n_unknown4 = 3;
    for (my $i = 0; $i < $n_unknown4; $i++) {
        $self->{unknown4}[$i] = $self->{_io}->read_f4le();
    }
}

sub unknown1 {
    my ($self) = @_;
    return $self->{unknown1};
}

sub wlintercept {
    my ($self) = @_;
    return $self->{wlintercept};
}

sub wlx1 {
    my ($self) = @_;
    return $self->{wlx1};
}

sub wlx2 {
    my ($self) = @_;
    return $self->{wlx2};
}

sub wlx3 {
    my ($self) = @_;
    return $self->{wlx3};
}

sub wlx4 {
    my ($self) = @_;
    return $self->{wlx4};
}

sub unknown2 {
    my ($self) = @_;
    return $self->{unknown2};
}

sub ipixfirst {
    my ($self) = @_;
    return $self->{ipixfirst};
}

sub ipixlast {
    my ($self) = @_;
    return $self->{ipixlast};
}

sub unknown3 {
    my ($self) = @_;
    return $self->{unknown3};
}

sub spectrum {
    my ($self) = @_;
    return $self->{spectrum};
}

sub unknown4 {
    my ($self) = @_;
    return $self->{unknown4};
}

1;