Converting Bruker FID file into ASCII file




Home and Applets > FAQ > About NMR > About File Conversion > Bruker FID to ASCII

*** Outline ***

  1. Converting Bruker FID file into ASCII file
  2. AU program for TopSpin
  3. AU program for XWINNMR

(1) Converting Bruker FID file into ASCII file

If digmod is used during FID acquisition, always convert data to analog with convdta command after the experiment.

Several methods are available for converting Bruker FID file into ASCII file. Open Bruker FID file with

  1. GSim program. After opening an FID file, select Edit->Data menu entry. GSim builds a spreadsheet form for selection of the real and the imaginary parts of the FID data.
     
  2. Dmfit program, (1) choose the real FID then save it as ASCII file; (2) choose the imaginary FID then save it as ASCII file. Each file is a two-series file: the left-hand series is the acquisition time and the right-hand series is the FID.
     
  3. Bruker 1D data processing program WINNMR then save it as ASCII file which is a one-series file: the top part is the real FID and the bottom part is the imaginary FID. These two parts are separated by the word imaginary.
     
  4. Bruker TopSpin program and convert it to ASCII file with the following first AU program. The converted file has two series of data: the left-hand one is a series of point number and the right-hand one is the FID data whose top half is the real FID and the bottom half is the imaginary FID.
     
  5. Bruker XWINNMR program and convert it to ASCII file with the following second AU program. The converted file has two series of data: the left-hand one is a series of point number and the right-hand one is the FID data whose top half is the real FID and the bottom half is the imaginary FID.
     
  6. Save Bruker file as JCAMP-DX format.

(2) AU program for TopSpin

/*** ^^A -*-C++-*- **********************************************/
/*      convfid2ascppm      03.03.2005                          */
/****************************************************************/
/*      Short Description :                                     */
/*      AU program to convert an fid data file into an ascii    */
/*      table containing point number and intensity values.     */
/****************************************************************/
/*      Keywords :                                              */
/*      ascii fid conversion                                    */
/****************************************************************/
/*      Description/Usage :                                     */
/*      AU program to convert an fid data file into an ascii    */
/*      table containing point number and intensity values.     */
/*      The output file is stored in the same directory as the  */
/*      fid. It can be used for calculations in spread-sheet    */
/*      programs or other third-party software.                 */
/****************************************************************/
/*      Author(s) :                                             */
/*      Name            : Clemens Anklin, Mike Engelhardt       */
/*      Organisation    : Bruker BioSpin                        */
/*      Email           : cga@bruker.com, eng@bruker.de         */
/****************************************************************/
/*      Name            Date    Modification:                   */
/*      eng             050303  created from convbin2asc        */
/****************************************************************/
/*
$Id: convfid2asc,v 1.3 2006/01/10 13:23:16 wem Exp $
*/

char infile[PATH_MAX], outfile[PATH_MAX], *inbuf1;
int parmode, td, i, fdin, bytorda, dtypa;
size_t bytetoread = sizeof(int);
int bytesread;
FILE *fpout;

FETCHPARS("PARMODE",&parmode)
if (parmode != 0)
{
  Proc_err(DEF_ERR_OPT, "convfid2asc only works on 1D data.");
  ABORT
}

FETCHPARS("DTYPA",&dtypa)
if (dtypa != 0 && dtypa != 2)
{
  Proc_err(DEF_ERR_OPT, "convfid2asc only works on integer or double data.");
  ABORT
}

if (dtypa == 2)
  bytetoread = sizeof(double);

FETCHPARS("BYTORDA",&bytorda)
FETCHPARS("TD",&td)
bytetoread *= td;

(void)sprintf(infile,"%s/data/%s/nmr/%s/%d/fid",
              disk,user,name,expno);

(void)sprintf(outfile,"%s/data/%s/nmr/%s/%d/asciippm-fid.txt",
              disk,user,name,expno);

if ((inbuf1 = malloc(bytetoread)) == 0)
{
  Proc_err(DEF_ERR_OPT,"Not enough memory for file buffer.");
  ABORT
}

if ((fdin = open(infile,O_RDONLY)) == -1)
{
  Perror(DEF_ERR_OPT,infile);
  ABORT
}

bytesread = read(fdin,inbuf1,bytetoread);

if (bytesread < 0)
{
  Perror(DEF_ERR_OPT,infile);
  close(fdin);
  ABORT
}

close(fdin);

if ((size_t)bytesread != bytetoread)
{
  Proc_err(DEF_ERR_OPT,"%s read off file limits.",infile);
  ABORT
}

if ((fpout = fopen(outfile,"wt")) == 0)
{
  Proc_err(DEF_ERR_OPT,"Cannot open %s for writing.",outfile);
  ABORT
}

if (dtypa == 0)
{
  int* inbufint1 = (int*)inbuf1;

  local_swap4(inbuf1,bytetoread,bytorda);

  for (i=0; i<td/2; i++)
    fprintf(fpout, "%i, %d\n", i+1, inbufint1[2*i]);
  for (i=0; i<td/2; i++)
    fprintf(fpout, "%i, %d\n", i+1+td/2, inbufint1[2*i+1]);
}
else
{
  double* inbufd = (double*)inbuf1;

  local_swap8(inbuf1,bytetoread,bytorda);

  for (i=0; i<td/2; i++)
    fprintf(fpout, "%i, %f\n", i+1, inbufd[2*i]);
  for (i=0; i<td/2; i++)
    fprintf(fpout, "%i, %f\n", i+1+td/2, inbufd[2*i+1]);
}

fclose(fpout);
free(inbuf1);

QUIT

(3) AU program for XWINNMR

/****************************************************************/
/*      convfid2ascppm      03.03.2005                          */
/****************************************************************/
/*      Short Description :                                     */
/*      AU program to convert an fid data file into an ascii    */
/*      table containing point number and intensity values.     */
/****************************************************************/
/*      Keywords :                                              */
/*      ascii fid conversion                                    */
/****************************************************************/
/*      Description/Usage :                                     */
/*      AU program to convert an fid data file into an ascii    */
/*      table containing point number and intensity values.     */
/*      The output file is stored in the same directory as the  */
/*      fid. It can be used for calculations in spread-sheet    */
/*      programs or other third-party software.                 */
/****************************************************************/
/*      Author(s) :                                             */
/*      Name        : Clemens Anklin, Mike Engelhardt           */
/*      Organisation: Bruker BioSpin                            */
/*      Email       : cga@bruker.com, eng@bruker.de             */
/****************************************************************/
/*      Name            Date    Modification:                   */
/*      eng             050303  created from convbin2asc        */
/****************************************************************/
/*
$Id: convfid2asc,v 1.1 2005/03/14 10:48:00 eng Exp $
*/

#include <fcntl.h>

char infile[PATH_MAX], outfile[PATH_MAX], *inbuf1;
int *inbufint1, parmode, td, i, fpin, intens, bytorda;
unsigned bytetoread;
FILE *fpout;

GETCURDATA

FETCHPARS("PARMODE",&parmode);
if (parmode != 0)
{
  Proc_err(DEF_ERR_OPT, "convfid2asc only works for 1D data.");
  ABORT
}

FETCHPARS("BYTORDA",&bytorda);
FETCHPARS("TD",&td);
bytetoread = td*sizeof(int);

(void)sprintf(infile,"%s/data/%s/nmr/%s/%d/fid",
disk,user,name,expno);

(void)sprintf(outfile,"%s/data/%s/nmr/%s/%d/asciippm-fid.txt",
disk,user,name,expno);

if ( (fpin=open(infile,O_RDONLY)) == (-1) )
{
  Perror(DEF_ERR_OPT,infile);
  ABORT
}
if ( (fpout=fopen(outfile,"wb")) == NULL)
{
  Perror(DEF_ERR_OPT,outfile);
  ABORT;
}

if ( (inbuf1 = calloc (bytetoread,sizeof(char*))) == NULL)
{
  Perror(DEF_ERR_OPT,infile);
  close (fpin);
  fclose (fpout);
  ABORT
}
if ( (i = read (fpin,inbuf1,bytetoread)) != bytetoread )
{
  Perror(DEF_ERR_OPT,infile);
  fclose (fpout);
  close (fpin);
  ABORT
}
close(fpin);
local_swap4(inbuf1,bytetoread,bytorda);

inbufint1 = (int *)inbuf1;

for (i=0; i<td/2; i++)
  {
  intens=inbufint1[2*i];
  fprintf(fpout, "%i, %d\n", i+1, intens);
  }

for (i=0; i<td/2; i++)
  {
  intens=inbufint1[2*i+1];
  fprintf(fpout, "%i, %d\n", i+1+td/2, intens);
  }

fclose(fpout);

QUIT

 
[Contact me] - Last updated August 30, 2012
Copyright 2002- pascal-man.com. All rights reserved.