TPC5 File Format
From Elsys Wiki - Help and Recources for TranAX and TraNET DAQ
Revision as of 15:19, 26 September 2017 by Rbertschi (talk | contribs) (Created page with "Category:TranAX Category:API TranAX is saving trace date, spectral data and TabPages in the [http://www.hdfgroup.org/HDF5/index.html| HDF5 file format]. Depending on...")
TranAX is saving trace date, spectral data and TabPages in the HDF5 file format. Depending on the data type the file extention is *.tpc5, *.tps5 or *.tpd.
The HDF5 file format was developed at the University of Illinois. The HDF5 specifications and the libraries source codes are open.
C++ Reading Example
#include "stdafx.h"
#include <iostream>
#include <fstream>
using std::cout;
using std::endl;
using std::ofstream;
#include <string>
#include "H5Cpp.h" // Using the C++ High Level API
using namespace H5;
int _tmain(int argc, _TCHAR* argv[])
{
unsigned int const BLOCK_SIZE = 256 * 1024;
try {
H5File file("Example.tpc5", H5F_ACC_RDONLY);
// Read out channel settings for the first channel
// Use HDFView for further analysis of the file structure of your file
// Digital marker signals are a part of the binaray measurement values.
// For separating digital from analog values the following two
// bit maskes are needet (is the same for all channel of one board)
Group g1 = file.openGroup("/measurements/00000001/channels/00000001");
Attribute ch1_analogmask = g1.openAttribute("analogMask");
unsigned int analogmask_ch1;
ch1_analogmask.read(PredType::NATIVE_INT, &analogmask_ch1);
ch1_analogmask.close();
Attribute ch1_markermask = g1.openAttribute("markerMask");
unsigned int markermask_ch1;
ch1_markermask.read(PredType::NATIVE_INT, &markermask_ch1);
ch1_markermask.close();
// Measurement values are stored as they are comming from the A / D converter.
// For getting voltage values or scaled physical values the corresponding
// convertion values must be read out. (could be different for each channel)
Attribute ch1_binToVoltFactor = g1.openAttribute("binToVoltFactor");
Attribute ch1_binToVoltConstant = g1.openAttribute("binToVoltConstant");
float binToVoltFactor_ch1, binToVoltConstant_ch1;
ch1_binToVoltFactor.read(PredType::NATIVE_FLOAT, &binToVoltFactor_ch1);
ch1_binToVoltConstant.read(PredType::NATIVE_FLOAT, &binToVoltConstant_ch1);
ch1_binToVoltFactor.close();
ch1_binToVoltConstant.close();
// Conversion factor for scaling to physical values
Attribute ch1_voltToPhysicalFactor = g1.openAttribute("voltToPhysicalFactor");
Attribute ch1_voltToPhysicalConstant = g1.openAttribute("voltToPhysicalConstant");
float voltToPhysicalFactor_ch1, voltToPhysicalConstant_ch1;
ch1_voltToPhysicalFactor.read(PredType::NATIVE_FLOAT, &voltToPhysicalFactor_ch1);
ch1_voltToPhysicalConstant.read(PredType::NATIVE_FLOAT, &voltToPhysicalConstant_ch1);
ch1_voltToPhysicalFactor.close();
ch1_voltToPhysicalConstant.close();
// Read out the data from the first channel, first block
DataSet dataset_ch1_block1 = file.openDataSet("/measurements/00000001/channels/00000001/blocks/00000001/raw");
int* rawData = new int[BLOCK_SIZE];
dataset_ch1_block1.read(rawData, PredType::NATIVE_INT);
dataset_ch1_block1.close();
// Mask out the digital marker bits
int* analogData = new int[BLOCK_SIZE];
int* markerData = new int[BLOCK_SIZE];
float* voltageData = new float[BLOCK_SIZE];
float* physicalData = new float[BLOCK_SIZE];
// Output Text file
ofstream myfile;
myfile.open("example.txt");
for (int i = 0; i < BLOCK_SIZE; i++){
analogData[i] = rawData[i] & analogmask_ch1;
markerData[i] = rawData[i] & markermask_ch1;
// Scale Data to voltage and/or physical data
voltageData[i] = ((float)analogData[i] * binToVoltFactor_ch1) + binToVoltConstant_ch1;
physicalData[i] = (voltageData[i] * voltToPhysicalFactor_ch1) + voltToPhysicalConstant_ch1;
// Log Data
myfile << physicalData[i] << endl;
}
myfile.close();
g1.close();
file.close();
delete rawData;
delete analogData;
delete markerData;
delete voltageData;
delete physicalData;
}
catch (AttributeIException error)
{
error.printError();
return -1;
}
catch (...){}
return 0;
}