Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //bruker_read.cpp
- //This code is based upon the libraries released by Dr Kirk Marat from the University of Manitoba
- //ftp://davinci.chem.umanitoba.ca/pub/marat/SpinWorks/source_library/
- //I want to thank Dr Marat for making these libraries available.
- //Pascal Fricke, August 2010
- //fricke@studserv.uni-leipzig.de
- #include "bruker_read.h"
- #include "data_par.h"
- #include <QString>
- #include <QStringList>
- #include <QTextStream>
- #include <QDataStream>
- #include <QDebug>
- #include <QFile>
- #include <QVector>
- #include <QByteArray>
- #include <iostream>
- //get parameters from parfile (usually acqus) by parsing it line by line
- bool bruker_read::get_par(QString parfile, data_par& p)
- {
- QString instring; // string used for reading lines of input file
- QStringList token; // StringList for storing seperate parts of line after splitting
- QFile file(parfile); //access to file
- if (!file.open(QIODevice::ReadOnly)) { //access is read only
- std::cerr << "Cannot open parameter file: " << qPrintable (file.errorString()) << std::endl;
- }
- QTextStream in(&file); //text stream object "in"
- while (!in.atEnd()) { //stop loop at end of file
- instring = in.readLine(); //put read lines into QString "instring"
- if (instring.length() > 3)
- {
- token = instring.split(" ", QString::SkipEmptyParts); //splits after the " ", empty lines are skipped
- //if (token.at(0) == "##END") break;
- if (token.at(0) == "##$SFO1=") //transmitter frequency
- {
- p.sfo1 = token.at(1).toDouble();
- }
- if (token.at(0) == "##$SFO2=") //decoupler frequency
- {
- p.sfo2 = token.at(1).toDouble();
- }
- if (token.at(0) == "##$SFO3=") //second decoupler frequency
- {
- p.sfo3 = token.at(1).toDouble();
- }
- if (token.at(0) == "##$SW=") //spectral width (ppm)
- {
- p.sw = token.at(1).toDouble();
- }
- if (token.at(0) == "##$SF=") //frequency of 0 ppm
- {
- p.sf = token.at(1).toDouble();
- }
- if (token.at(0) == "##$GB=") //GB-factor
- {
- p.gb = token.at(1).toDouble();
- }
- if (token.at(0) == "##$LB=") //line broadening
- {
- p.lb = token.at(1).toDouble();
- }
- if (token.at(0) == "##$TD=") //acquired points (real+imaginary)
- {
- p.td = token.at(1).toInt();
- }
- if (token.at(0) == "##$DECIM=") //DSP decimation factor
- {
- p.decim = token.at(1).toInt();
- }
- if (token.at(0) == "##$DSPFVS=") //DSP firmware version
- {
- p.dspfvs = token.at(1).toInt();
- }
- if (token.at(0) == "##$GRPDLY=") //DSP group delay
- {
- p.grpdly = token.at(1).toDouble();
- }
- if (token.at(0) == "##$SI=") //transform size (complex)
- {
- p.si = token.at(1).toInt();
- }
- if (token.at(0) == "##$BYTORDA=") //byte order
- {
- p.bytorda = token.at(1).toInt();
- }
- if (token.at(0) == "##$AQ_mod=") //acquisition mode
- {
- p.aq_mod = token.at(1).toInt();
- }
- if (token.at(0) == "##$DIGMOD=") //filter type
- {
- p.digmod = token.at(1).toInt();
- }
- if (token.at(0) == "##$NS=") //number of scans
- {
- p.ns = token.at(1).toInt();
- }
- if (token.at(0) == "##$PULPROG=") //pulse program
- {
- p.pulprog = token.at(1);
- }
- if (token.at(0) == "##$NUC1=") //observed nucleus
- {
- p.nuc1 = token.at(1);
- }
- if (token.at(0) == "##$INTSRUM=") //instrument name
- {
- p.instrum = token.at(1);
- }
- if (token.at(0) == "##$WDW=") //window function type
- {
- p.wdw = token.at(1).toInt();
- }
- if (token.at(0) == "##$PH_mod=") //phasing type
- {
- p.ph_mod = token.at(1).toInt();
- }
- if (token.at(0) == "##$PHC0=") //zero order phase
- {
- p.phc0 = token.at(1).toDouble();
- }
- if (token.at(0) == "##$PHC1=") //first order phase
- {
- p.phc1 = token.at(1).toDouble();
- }
- if (token.at(0) == "##$SSB=") //sine bell shift
- {
- p.ssb = token.at(1).toInt();
- }
- if (token.at(0) == "##$MC2=") //F1 detection mode
- {
- p.mc2 = token.at(1).toInt();
- }
- }
- }
- //set acquisition mode of experiment
- if (p.aq_mod == 2) p.aq_mode = p.AQ_MODE_SEQ(); //sequential acquisition mode
- if (p.aq_mod == 1 || p.aq_mod == 3) p.aq_mode = p.AQ_MODE_SIM(); //simultaneous or DQD
- if (p.decim > 1) p.aq_mode = p.AQ_MODE_DSP(); //simultaneous DSP
- return true;
- };
- //funtion for reading raw fid file input into byte array
- bool bruker_read::get_fid(QString fidfile, data_par& p)
- {
- QFile file(fidfile); //access to file
- if (!file.open(QIODevice::ReadOnly)) {
- std::cerr << "Cannot open fid file: " << qPrintable (file.errorString()) << std::endl;
- return false;
- }
- QDataStream in(&file); //binary data input stream
- p.fid.resize(p.td); //resize fid byte array to actual td size
- p.fid.fill(0); //initialize (necessary?)
- //BYTORDA defines whether byte order is big oder little endian
- if (p.bytorda == 1) in.setByteOrder(QDataStream::BigEndian); //set byte order to Big Endian
- if (p.bytorda == 0) in.setByteOrder(QDataStream::LittleEndian); //set byte order to Little Endian
- for (qint32 i=0; i<p.td; i++) //fid file contains TD times a 4 byte integer
- {
- in >> p.fid[i]; //load the datastream into the fid array, consisting of 32 bit signed integers (4 byte)
- }
- return true;
- }
- //currently function not needed, is done by endian-aware bitsToInt function
- void bruker_read::rev_bytes(char* array, qint32 index)
- {
- char byte0, byte1, byte2, byte3;
- byte0 = array[index];
- byte1 = array[index+1];
- byte2 = array[index+2];
- byte3 = array[index+3];
- array[index] = byte3;
- array[index+1] = byte2;
- array[index+2] = byte1;
- array[index+3] = byte0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement