Advertisement
Guest User

bruker_read.cpp

a guest
Aug 4th, 2010
397
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 6.95 KB | None | 0 0
  1. //bruker_read.cpp
  2.  
  3. //This code is based upon the libraries released by Dr Kirk Marat from the University of Manitoba
  4. //ftp://davinci.chem.umanitoba.ca/pub/marat/SpinWorks/source_library/
  5.  
  6. //I want to thank Dr Marat for making these libraries available.
  7.  
  8. //Pascal Fricke, August 2010
  9. //fricke@studserv.uni-leipzig.de
  10.  
  11. #include "bruker_read.h"
  12. #include "data_par.h"
  13. #include <QString>
  14. #include <QStringList>
  15. #include <QTextStream>
  16. #include <QDataStream>
  17. #include <QDebug>
  18. #include <QFile>
  19. #include <QVector>
  20. #include <QByteArray>
  21. #include <iostream>
  22.  
  23. //get parameters from parfile (usually acqus) by parsing it line by line
  24. bool bruker_read::get_par(QString parfile, data_par& p)
  25. {
  26.     QString instring;       // string used for reading lines of input file
  27.     QStringList token;      // StringList for storing seperate parts of line after splitting
  28.     QFile file(parfile);    //access to file
  29.  
  30.  
  31.     if (!file.open(QIODevice::ReadOnly)) {      //access is read only
  32.         std::cerr << "Cannot open parameter file: " << qPrintable (file.errorString()) << std::endl;
  33.     }
  34.  
  35.  
  36.     QTextStream in(&file);                      //text stream object "in"
  37.     while (!in.atEnd()) {                       //stop loop at end of file
  38.         instring = in.readLine();               //put read lines into QString "instring"
  39.         if (instring.length() > 3)
  40.         {
  41.             token = instring.split(" ", QString::SkipEmptyParts); //splits after the " ", empty lines are skipped
  42.             //if (token.at(0) == "##END") break;
  43.  
  44.             if (token.at(0) == "##$SFO1=")      //transmitter frequency
  45.             {
  46.                 p.sfo1 = token.at(1).toDouble();
  47.             }
  48.  
  49.             if (token.at(0) == "##$SFO2=")      //decoupler frequency
  50.             {
  51.                 p.sfo2 = token.at(1).toDouble();
  52.             }
  53.             if (token.at(0) == "##$SFO3=")      //second decoupler frequency
  54.             {
  55.                 p.sfo3 = token.at(1).toDouble();
  56.             }
  57.             if (token.at(0) == "##$SW=")      //spectral width (ppm)
  58.             {
  59.                 p.sw = token.at(1).toDouble();
  60.             }
  61.             if (token.at(0) == "##$SF=")      //frequency of 0 ppm
  62.             {
  63.                 p.sf = token.at(1).toDouble();
  64.             }
  65.             if (token.at(0) == "##$GB=")      //GB-factor
  66.             {
  67.                 p.gb = token.at(1).toDouble();
  68.             }
  69.             if (token.at(0) == "##$LB=")      //line broadening
  70.             {
  71.                 p.lb = token.at(1).toDouble();
  72.             }
  73.             if (token.at(0) == "##$TD=")      //acquired points (real+imaginary)
  74.             {
  75.                 p.td = token.at(1).toInt();
  76.             }
  77.             if (token.at(0) == "##$DECIM=")      //DSP decimation factor
  78.             {
  79.                 p.decim = token.at(1).toInt();
  80.             }
  81.             if (token.at(0) == "##$DSPFVS=")      //DSP firmware version
  82.             {
  83.                 p.dspfvs = token.at(1).toInt();
  84.             }
  85.             if (token.at(0) == "##$GRPDLY=")      //DSP group delay
  86.             {
  87.                 p.grpdly = token.at(1).toDouble();
  88.             }
  89.             if (token.at(0) == "##$SI=")      //transform size (complex)
  90.             {
  91.                 p.si = token.at(1).toInt();
  92.             }
  93.             if (token.at(0) == "##$BYTORDA=")      //byte order
  94.             {
  95.                 p.bytorda = token.at(1).toInt();
  96.             }
  97.             if (token.at(0) == "##$AQ_mod=")      //acquisition mode
  98.             {
  99.                 p.aq_mod = token.at(1).toInt();
  100.             }
  101.             if (token.at(0) == "##$DIGMOD=")      //filter type
  102.             {
  103.                 p.digmod = token.at(1).toInt();
  104.             }
  105.             if (token.at(0) == "##$NS=")      //number of scans
  106.             {
  107.                 p.ns = token.at(1).toInt();
  108.             }
  109.             if (token.at(0) == "##$PULPROG=")      //pulse program
  110.             {
  111.                 p.pulprog = token.at(1);
  112.             }
  113.             if (token.at(0) == "##$NUC1=")      //observed nucleus
  114.             {
  115.                 p.nuc1 = token.at(1);
  116.             }
  117.             if (token.at(0) == "##$INTSRUM=")      //instrument name
  118.             {
  119.                 p.instrum = token.at(1);
  120.             }
  121.             if (token.at(0) == "##$WDW=")      //window function type
  122.             {
  123.                 p.wdw = token.at(1).toInt();
  124.             }
  125.             if (token.at(0) == "##$PH_mod=")      //phasing type
  126.             {
  127.                 p.ph_mod = token.at(1).toInt();
  128.             }
  129.             if (token.at(0) == "##$PHC0=")      //zero order phase
  130.             {
  131.                 p.phc0 = token.at(1).toDouble();
  132.             }
  133.             if (token.at(0) == "##$PHC1=")      //first order phase
  134.             {
  135.                 p.phc1 = token.at(1).toDouble();
  136.             }
  137.             if (token.at(0) == "##$SSB=")      //sine bell shift
  138.             {
  139.                 p.ssb = token.at(1).toInt();
  140.             }
  141.             if (token.at(0) == "##$MC2=")      //F1 detection mode
  142.             {
  143.                 p.mc2 = token.at(1).toInt();
  144.             }
  145.  
  146.         }
  147.  
  148.  
  149.  
  150.  
  151.     }
  152.  
  153.     //set acquisition mode of experiment
  154.     if (p.aq_mod == 2) p.aq_mode = p.AQ_MODE_SEQ();                     //sequential acquisition mode
  155.     if (p.aq_mod == 1 || p.aq_mod == 3) p.aq_mode = p.AQ_MODE_SIM();    //simultaneous or DQD
  156.     if (p.decim > 1) p.aq_mode = p.AQ_MODE_DSP();                       //simultaneous DSP
  157.     return true;
  158. };
  159.  
  160.  
  161. //funtion for reading raw fid file input into byte array
  162. bool bruker_read::get_fid(QString fidfile, data_par& p)
  163. {
  164.     QFile file(fidfile);            //access to file
  165.     if (!file.open(QIODevice::ReadOnly)) {
  166.         std::cerr << "Cannot open fid file: " << qPrintable (file.errorString()) << std::endl;
  167.         return false;
  168.  
  169.     }
  170.     QDataStream in(&file);          //binary data input stream
  171.  
  172.     p.fid.resize(p.td);             //resize fid byte array to actual td size
  173.     p.fid.fill(0);                  //initialize (necessary?)
  174.  
  175.  
  176.     //BYTORDA defines whether byte order is big oder little endian
  177.     if (p.bytorda == 1) in.setByteOrder(QDataStream::BigEndian);    //set byte order to Big Endian
  178.     if (p.bytorda == 0) in.setByteOrder(QDataStream::LittleEndian); //set byte order to Little Endian
  179.  
  180.     for (qint32 i=0; i<p.td; i++)       //fid file contains TD times a 4 byte integer
  181.     {
  182.         in >> p.fid[i];                 //load the datastream into the fid array, consisting of 32 bit signed integers (4 byte)
  183.  
  184.     }
  185.  
  186.  
  187.  
  188.     return true;
  189. }
  190.  
  191. //currently function not needed, is done by endian-aware bitsToInt function
  192. void bruker_read::rev_bytes(char* array, qint32 index)
  193. {
  194.     char byte0, byte1, byte2, byte3;
  195.     byte0 = array[index];
  196.     byte1 = array[index+1];
  197.     byte2 = array[index+2];
  198.     byte3 = array[index+3];
  199.  
  200.     array[index] = byte3;
  201.     array[index+1] = byte2;
  202.     array[index+2] = byte1;
  203.     array[index+3] = byte0;
  204. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement