Advertisement
Guest User

bruker_read.cpp

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