src/GamIO/XWinFid.cc
/* This function will read in a binary fid file from a Bruker 1D acqusition
   in XWinNMR.  Typically this is just done during construction of the class.
   However, it is convenient to have an empty class constructor which can be
   used in conjunction with read/write to perform the same feat.  The Bruker
   file "fid" contains values that are read in as re,im,re,im,...., each point
   stored as a 32-bit integer.  It is very important that we know the number 
   of points in an FID and the byte order used in storing the data.  This
   information must be supplied, either when calling the read function or when
   constructing objects of this class type.  Such information is usually stroed
   in corresponding ASCII parameter file, typically named acqu and acqus. Such
   details should be attended to in higher classes utilizing these functions.*/
This function will read in a binary fid file from a Bruker 1D acqusition
in XWinNMR.  Typically this is just done during construction of the class.
However, it is convenient to have an empty class constructor which can be
used in conjunction with read/write to perform the same feat.  The Bruker
file "fid" contains values that are read in as re,im,re,im,...., each point
stored as a 32-bit integer.  It is very important that we know the number
of points in an FID and the byte order used in storing the data.  This
information must be supplied, either when calling the read function or when
constructing objects of this class type.  Such information is usually stroed
in corresponding ASCII parameter file, typically named acqu and acqus. Such
details should be attended to in higher classes utilizing these functions.
This function will read in a binary fid file from a Bruker 1D acqusition in XWinNMR . Typically this is just done during construction of the class . However it is convenient to have an empty class constructor which can be used in conjunction with read / write to perform the same feat . The Bruker file " fid " contains values that are read in as re im re im .... each point stored as a 32 - bit integer . It is very important that we know the number of points in an FID and the byte order used in storing the data . This information must be supplied either when calling the read function or when constructing objects of this class type . Such information is usually stroed in corresponding ASCII parameter file typically named acqu and acqus . Such details should be attended to in higher classes utilizing these functions .
bool XWinFid::read(const string& name, bool byteord, int TD, int warn)
  {
  ffp.open(name.c_str(), ios::binary|ios::in);
  if(!ffp.good())			
    {
    if(warn)
      {
      XWinFiderror(28,1);		
      XWinFiderror(1,name,1);		
      if(warn>1) XWinFidfatality(29);	
      else       XWinFiderror(1,name);
      }
    return false;
    }
  ffname     = name;			
  fbigend    = WeRBigEnd();		
  fbyteordin = byteord;			
  ffp.seekp(0,ios::end);		
  ffsize = ffp.tellp();			
  ffp.seekp(0);				
  if(TD>0) ftotpts= TD;			
  else     ftotpts=ffsize/sizeof(int32_t);	
  SetPadding();				
  if(!CheckSize(1))			
    XWinFidfatality(46);		
  int swapon = 0;			
  if(fbigend != fbyteordin) swapon = 1;	
  fdata = row_vector(ftotpts/2);	
  int32_t ptre, ptim;			
  for(int i=0; i<ftotpts/2; i++)	
    {  
    ffp.read((char*)&ptre,sizeof(int32_t));
    ffp.read((char*)&ptim,sizeof(int32_t));
    if(swapon) {Swap(ptre); Swap(ptim);}
    fdata.put(complex(ptre,ptim),i);	
    }  
  ffp.close();				
  return true;				
  }
bool XWinFid :: read ( const string & name , bool byteord , int TD , int warn ) { ffp . open ( name . c_str ( ) , ios :: binary | ios :: in ) ; if ( ! ffp . good ( ) ) { if ( warn ) { XWinFiderror ( 28 , 1 ) ; XWinFiderror ( 1 , name , 1 ) ; if ( warn > 1 ) XWinFidfatality ( 29 ) ; else XWinFiderror ( 1 , name ) ; } return false ; } ffname = name ; fbigend = WeRBigEnd ( ) ; fbyteordin = byteord ; ffp . seekp ( 0 , ios :: end ) ; ffsize = ffp . tellp ( ) ; ffp . seekp ( 0 ) ; if ( TD > 0 ) ftotpts = TD ; else ftotpts = ffsize / sizeof ( int32_t ) ; SetPadding ( ) ; if ( ! CheckSize ( 1 ) ) XWinFidfatality ( 46 ) ; int swapon = 0 ; if ( fbigend != fbyteordin ) swapon = 1 ; fdata = row_vector ( ftotpts / 2 ) ; int32_t ptre , ptim ; for ( int i = 0 ; i < ftotpts / 2 ; i ++ ) { ffp . read ( ( char * ) & ptre , sizeof ( int32_t ) ) ; ffp . read ( ( char * ) & ptim , sizeof ( int32_t ) ) ; if ( swapon ) { Swap ( ptre ) ; Swap ( ptim ) ; } fdata . put ( complex ( ptre , ptim ) , i ) ; } ffp . close ( ) ; return true ; }
This function will read in a binary fid file from a Bruker 1D acqusition
in XWinNMR.
This function will read in a binary fid file from a Bruker 1D acqusition in XWinNMR .
// Insure Bruker File is O.K. //   Problems with filestream //   Problems with file //   Can't read a damn thing // Set the Bruker filename // Set output byte order (our arch) // Set input byte order (Bruker) // Go to the end of the file // See how many bytes are in the file // Set things back to the start // Set points per fid (re + im) // Set points per fid (re + im) // Set any padding for data boundary // Insure file size O.K. if open // for writing, TD too large else // Assume no byte swapping // Need to swap if mismatch // Array for fid data // These will be input values // Loop over fid points //   Read a (real) point //   Read a (imag) point //   Byte swap if needed //   Store point // Close the file // Return successfull