Exemplo n.º 1
0
void lime_read_info(FILE **fin, lime_fileinfo *lime, char* binary_data) {
  LimeReader *limereader;
  char *lime_type,*lime_data;
  
  ASSERT((limereader = limeCreateReader(*fin)));
  
  lime->spin=4;
  lime->colour=3;
  
  while(limeReaderNextRecord(limereader) != LIME_EOF)
  {
    lime_type = limeReaderType(limereader);
    if(strcmp(lime_type, binary_data)==0)
    {
      break;
    }
    if(strcmp(lime_type,"ildg-format")==0)
    {
      lime->data_size = limeReaderBytes(limereader);
      lime_data = (char * )malloc(lime->data_size);
      limeReaderReadData((void *)lime_data,&(lime->data_size), limereader);
      sscanf(lime_getParam("<precision>",lime_data, lime->data_size, '<'),"%i",&(lime->precision));
      sscanf(lime_getParam("<lx>",lime_data, lime->data_size, '<'),"%i",&(lime->l[X]));
      sscanf(lime_getParam("<ly>",lime_data, lime->data_size, '<'),"%i",&(lime->l[Y]));
      sscanf(lime_getParam("<lz>",lime_data, lime->data_size, '<'),"%i",&(lime->l[Z]));
      sscanf(lime_getParam("<lt>",lime_data, lime->data_size, '<'),"%i",&(lime->l[T]));
      free(lime_data);
    }
    if(strcmp(lime_type,"etmc-source-format")==0 || strcmp(lime_type,"etmc-propagator-format")==0)
    {
      lime->data_size = limeReaderBytes(limereader);
      lime_data = (char * )malloc(lime->data_size);
      limeReaderReadData((void *)lime_data,&(lime->data_size), limereader);
      sscanf(lime_getParam("<precision>",lime_data, lime->data_size, '<'),"%i",&(lime->precision));
      sscanf(lime_getParam("<flavours>",lime_data, lime->data_size, '<'),"%i",&(lime->flavours));
      sscanf(lime_getParam("<lx>",lime_data, lime->data_size, '<'),"%i",&(lime->l[X]));
      sscanf(lime_getParam("<ly>",lime_data, lime->data_size, '<'),"%i",&(lime->l[Y]));
      sscanf(lime_getParam("<lz>",lime_data, lime->data_size, '<'),"%i",&(lime->l[Z]));
      sscanf(lime_getParam("<lt>",lime_data, lime->data_size, '<'),"%i",&(lime->l[T]));
      sscanf(lime_getParam("<spin>",lime_data, lime->data_size, '<'),"%i",&(lime->spin));
      sscanf(lime_getParam("<colour>",lime_data, lime->data_size, '<'),"%i",&(lime->colour));
      free(lime_data);
    }
    if(strcmp(lime_type,"xlf-info")==0)
    {
      lime->data_size = limeReaderBytes(limereader);
      lime_data = (char * )malloc(lime->data_size);
      limeReaderReadData((void *)lime_data,&(lime->data_size), limereader);
      sscanf(lime_getParam("plaquette =",lime_data, lime->data_size, '\n'),"%lf",&(lime->plaquette));
      free(lime_data);
    }
  }
  
  lime->data_size = limeReaderBytes(limereader);
  lime->offset = ftell(*fin);
  limeDestroyReader(limereader);
}
Exemplo n.º 2
0
  int ILDGReader::read(double *buffer, unsigned int size){
    _Message(DEBUG_VERB_LEVEL, "ILDG Reader...\n");
    //Read just as it is
    //order is (in, ex, sites)  
    n_uint64_t bytes_to_read = sizeof(double)*size;
    n_uint64_t read =  bytes_to_read;
    limeReaderReadData(buffer, &read, LimeR);

#ifndef BIG_ENDIAN_TYPE
    byte_swap(buffer, size);
#endif

    /* 
#ifdef DEBUG_VERB_LEVEL
    for (int i = 0; i < bytes_to_read; i++){
      std::cout << "buffer["<<i<<"] = "<< buffer[i] << "\n";
    }
#endif
    */  
  }
Exemplo n.º 3
0
void meson_ASCII_IO(char *filename, int rec_seek, int msg_seek)
{ 
    int i,j,k=0,l=0;
    char buf[MAXBUF];
    LimeReader *r;
    int status;
    twopt_mom *corr;
    n_uint64_t nbytes, bytes_left, bytes_to_copy, read_bytes;
    int rec, msg;
    char *lime_type;
    size_t bytes_pad;
    int MB_flag, ME_flag;
    FILE *fin=NULL;
  
    corr=malloc(NMOM_MAX*sizeof(twopt_mom));
  
    fin=fopen(filename,"r");
    error_root(fin == (FILE *)NULL,0,"meson_ASCII_IO [IOarchive.c]",
               "IOarchive: Unable to open file %s for reading\n", filename);
    /* Open LIME reader */
    r = limeCreateReader(fin);
    error_root(r == (LimeReader *)NULL,0,"meson_ASCII_IO [IOarchive.c]",
               "Unable to open LimeReader\n");
    /* Loop over records */
    rec = 0;
    msg = 0;
    while( (status = limeReaderNextRecord(r)) != LIME_EOF ){
    error_root(status != LIME_SUCCESS,0,"meson_ASCII_IO [IOarchive.c]",
             "IOarchive: limeReaderNextRecord returned status = %d\n",status);
    

    nbytes    = limeReaderBytes(r);
    lime_type = limeReaderType(r);
    bytes_pad = limeReaderPadBytes(r);
    MB_flag   = limeReaderMBFlag(r);
    ME_flag   = limeReaderMEFlag(r);

    /* Update message and record numbers */
    if(MB_flag == 1){
      msg++;
      rec = 0;
    }

    rec++;

    /* Skip to next record until target record is reached */
    if (msg != msg_seek || rec != rec_seek) continue;
    
    /* Buffered copy */
    bytes_left = nbytes;
    while(bytes_left > (n_uint64_t)0){
      bytes_to_copy = mino((n_uint64_t)(NMOM_MAX*sizeof(twopt_mom)),bytes_left);
      read_bytes = bytes_to_copy;
      error_root((int)read_bytes>MAXBUF,0,"meson_ASCII_IO [IOarchive.c]",
             "read_bytes exceeds MAXBUF");
      status = limeReaderReadData((void *)buf, &read_bytes, r);
      error_root(status<0 && status !=LIME_EOR,1,"meson_ASCII_IO [IOarchive.c]",
             "LIME read error occurred: status= %d", status);
      error_root(read_bytes != bytes_to_copy,1,"meson_ASCII_IO [IOarchive.c]",
             "Read error %lld bytes wanted,%lld read\n",
                (unsigned long long)nbytes, (unsigned long long)read_bytes);
    
      /* Print to stdout */
      corr=(twopt_mom*)buf;  
      l=0;
      for(i=0;i<NMOM_MAX;i++){
       for(j=0;j<TT;j++)
        {
            printf("%d %s %d %d %d %d %d %d %.16e %.16e\n",
  		k,lime_type,
		(*(corr+l)).musrc,
		(*(corr+l)).musnk,
		(*(corr+l)).p[0],
		(*(corr+l)).p[1],
		(*(corr+l)).p[2],
		j,
		(*(corr+l)).corr[j].re,
		(*(corr+l)).corr[j].im);
        }
       l++;
       k++;
      }
      bytes_left -= bytes_to_copy;
    }
    /* Quit at this record */
    break;
  }
  limeDestroyReader(r);
  fclose(fin);

}
Exemplo n.º 4
0
extern void import_cnfg_ildg(char *in)
{
   int my_rank,np[4],n,ie,tag,status,prec=0;
   int i,l,ix,iy,iz,it,ixx;
   n_uint64_t read_bytes,nbytes=0;
   double plaq1,eps;
   MPI_Status stat;
   LimeReader *reader=NULL;
   FILE *fin;
   char lime_type_target[100]="ildg-binary-data";
   char *lime_type;
   MPI_Comm_rank(MPI_COMM_WORLD,&my_rank);

   /* allocate IO-buffers */
   if (ubuf==NULL)
      alloc_ubuf_ildg(my_rank);

   error(pud[VOLUME/2][0]==NULL,1,"import_cnfg [archive_ildg.c]",
         "Double-precision gauge field is not allocated");
   ie=check_machine();   

   if (my_rank==0)
   {
     fin=fopen(in,"rb");
     error_root(fin==NULL,1,"import_cnfg  [archive_ildg.c]",
               	"Unable to open input file");
     reader=limeCreateReader(fin);
     error( reader == (LimeReader *)NULL ,1,"import_cnfg [archive_ildg.c]",
    		"Unable to open LimeReader");
     nbytes = (n_uint64_t)0;

     /* set the file-pointer to the beginning of the "ildg-binary-data" tag
      * in the LIME file */
     while( (status = limeReaderNextRecord(reader)) != LIME_EOF ){
       nbytes    = limeReaderBytes(reader);
       lime_type = limeReaderType(reader);
       error((status!=LIME_SUCCESS),1,"import_cnfg [archive_ildg.c]",
       	     "limeReaderNextRecord returned status %d and LIME_SUCCESS %d\n",
       status,LIME_SUCCESS);
       if (strcmp(lime_type,lime_type_target) != 0) continue;
        break;
     }
     /* Decide whether the gauge file is stored in single or
      * double precision format */
     if ((int)nbytes==8*VOLUME*NPROC*3*3*4*2){
       prec=8; 
       message("ILDG-file contains double precision gauge field\n");
     }
     else if ((int)nbytes==4*VOLUME*NPROC*3*3*4*2){
       prec=4; 
       message("ILDG-file contains single precision gauge field\n");
     }
     else
     error(1!=0,1,"import_cnfg [archive_ildg]",
		"Lattice geometry doesn't match size of gauge field %d %d\n");
   }
   /* Now read the gauge file in steps of 4 SU(3) matrices */
   for (it=0;it<N0;it++){
    for (iz=0;iz<N3;iz++){
     for (iy=0;iy<N2;iy++){
      for (ix=0;ix<N1;ix++){
	if(my_rank==0){
         if(prec==8){
          read_bytes = (n_uint64_t)(4*18*sizeof(double));
          status = limeReaderReadData((double *)vbuf,&read_bytes, reader);
	  bswap_double(4*18,(double *)(vbuf));/* ILDG always big endian */
         }
	 else if(prec==4){
          read_bytes = (n_uint64_t)(4*18*sizeof(float));
          status = limeReaderReadData((void *)vbuf_s,&read_bytes, reader);
	  bswap_float(4*18,(float *)(vbuf_s)); /* ILDG always big endian */
         for (i=0;i<4;i++)
	  su3_copy_singletodouble((vbuf_s+i),(vbuf+i));
         }
	}
        np[0]=it;
        np[1]=ix;
        np[2]=iy;
        np[3]=iz;
        n=ipr_global(np);
        MPI_Barrier(MPI_COMM_WORLD);
            if (n>0)
            {
               tag=mpi_tag();

               if (my_rank==0)
                  MPI_Send((double*)(vbuf),4*18,MPI_DOUBLE,n,tag,
                           MPI_COMM_WORLD);

               if (my_rank==n)
                  MPI_Recv((double*)(ubuf),4*18,MPI_DOUBLE,0,tag,
                           MPI_COMM_WORLD,&stat);
            }
            else if (my_rank==0)
               for (l=0;l<(4);l++)
                  ubuf[l]=vbuf[l];

            ixx = ((iy%L2)*L3 + (ix%L1)*L3*L2 + (it%L0)*L1*L2*L3);
            if (my_rank==n)
               set_links_ildg(ixx,iz);
      }
     }
    }
   }

   plaq1=plaq_sum_dble()/(double)(6*NPROC*VOLUME);
   message("Plaquette   %f\n",plaq1);
   message("Plaquette/3 %f\n",plaq1/3);
   message("Please check consistency of average plaquette by hand\n");
   eps=sqrt((double)(6*NPROC*VOLUME))*DBL_EPSILON;
}
Exemplo n.º 5
0
Arquivo: io.c Projeto: robfre21/tmLQCD
int read_lime_gauge_field_doubleprec(double * config, char * filename,
                                     const int T, const int LX, const int LY, const int LZ) {
    FILE * ifs;
    int t, x, y, z, status, p=0;
    n_uint64_t bytes;
    char * header_type;
    LimeReader * limereader;
    double tmp[72];
    int words_bigendian;

    words_bigendian = big_endian();
    ifs = fopen(filename, "r");
    if(ifs == (FILE *)NULL) {
        fprintf(stderr, "Could not open file %s\n Aborting...\n", filename);
        exit(500);
    }
    limereader = limeCreateReader( ifs );
    if( limereader == (LimeReader *)NULL ) {
        fprintf(stderr, "Unable to open LimeReader\n");
        exit(500);
    }
    while( (status = limeReaderNextRecord(limereader)) != LIME_EOF ) {
        if(status != LIME_SUCCESS ) {
            fprintf(stderr, "limeReaderNextRecord returned error with status = %d!\n", status);
            status = LIME_EOF;
            break;
        }
        header_type = limeReaderType(limereader);
        if(!strcmp("ildg-binary-data",header_type)) break;
    }
    if(status == LIME_EOF) {
        fprintf(stderr, "no ildg-binary-data record found in file %s\n",filename);
        limeDestroyReader(limereader);
        fclose(ifs);
        exit(-2);
    }
    bytes = limeReaderBytes(limereader);
    if((int)bytes != LX*LY*LZ*T*72*sizeof(double)) {
        fprintf(stderr, "Probably wrong lattice size or precision (bytes=%d) in file %s\n", (int)bytes, filename);
        fprintf(stderr, "Aborting...!\n");
        fflush( stdout );
        exit(501);
    }

    bytes = (n_uint64_t)72*sizeof(double);

    for(t = 0; t < T; t++) {
        for(z = 0; z < LZ; z++) {
            for(y = 0; y < LY; y++) {
                for(x = 0; x < LX; x++) {
                    p = (((t*LZ+z)*LY+y)*LX+x)*72;
                    if(!words_bigendian) {
                        status = limeReaderReadData(tmp, &bytes, limereader);
                        byte_swap_assign(&config[p], tmp, 72);
                    }
                    else {
                        status = limeReaderReadData(&config[p], &bytes, limereader);
                    }
                    if(status < 0 && status != LIME_EOR) {
                        fprintf(stderr, "LIME read error occured with status = %d while reading file %s!\n Aborting...\n",
                                status, filename);
                        exit(500);
                    }
                }
            }
        }
    }
    limeDestroyReader(limereader);
    fclose(ifs);
    return(0);
}
Exemplo n.º 6
0
int read_qdppp_scidac_binary_data(char *buff_out, long int buff_size, char *fin)
{

  char buf[MAXBUF];  /* auxilary buffer for using a buffer copy. Bytes first copied to buf then from buf to buff_out*/
  LimeReader *reader;
  int status;
  n_uint64_t nbytes, bytes_left, bytes_to_copy, read_bytes;
  int rec_seek,msg_seek;
  int rec, msg;
  char *lime_type;
  size_t bytes_pad;
  int MB_flag, ME_flag;

  int i;
  /* Open file */
  FILE *fp = fopen(fin, "r");
  if(fp == NULL) { 
    fprintf(stderr,"Unable to open file %s for reading\n", fin);
    return EXIT_FAILURE;
  }



  /* Open LIME reader */
  reader = limeCreateReader(fp);
  if( reader == (LimeReader *)NULL ) { 
    fprintf(stderr, "Unable to open LimeReader\n");
    return EXIT_FAILURE;
  }


  /* Loop over records */
  msg=0;
  rec=0; 
  while( (status = limeReaderNextRecord(reader)) != LIME_EOF ){
    
    if( status != LIME_SUCCESS ) { 
      fprintf(stderr, "limeReaderNextRecord returned status = %d\n", 
	      status);
      return EXIT_FAILURE;
    }

    nbytes    = limeReaderBytes(reader);
    lime_type = limeReaderType(reader);
    bytes_pad = limeReaderPadBytes(reader);
    MB_flag   = limeReaderMBFlag(reader);
    ME_flag   = limeReaderMEFlag(reader);

    /* Update message and record numbers */
    if(MB_flag == 1){
      msg++;
      rec = 0;
    }

    rec++;

#if 1
    printf("\n\n");
    printf("Type:           %s\n",   lime_type);
    printf("Data Length:    %ld\n",  nbytes);
    printf("Padding Length: %zd\n",   bytes_pad);
    printf("MB flag:        %d\n",   MB_flag);
    printf("ME flag:        %d\n",   ME_flag);
#endif


    /* Skip to next record until target record is reached */
    /*if (msg != msg_seek || rec != rec_seek) continue;*/
    if (strcmp(lime_type,"scidac-binary-data") != 0) continue;
    
    /*check that the data record has the expected number of byutes*/
    if(nbytes != buff_size)
    {
      fprintf(stderr,"Error, expecting %ld bytes but data has %ld bytes\n",buff_size,nbytes);
      return EXIT_FAILURE;
    }


    /* Buffered copy */
    
    bytes_left = nbytes;
    int bcopied=0;
    while(bytes_left > (n_uint64_t)0){
      bytes_to_copy = mino((n_uint64_t)MAXBUF,bytes_left);
      read_bytes = bytes_to_copy;
      status = limeReaderReadData((void *)buf, &read_bytes, reader);
    
      if( status < 0 && status != LIME_EOR ) { 
	fprintf(stderr, "LIME read error occurred: status= %d\n", status);
	exit(EXIT_FAILURE);
      }
      if (read_bytes != bytes_to_copy) {
	fprintf(stderr, "Read error %lld bytes wanted,%lld read\n", 
		(unsigned long long)nbytes, (unsigned long long)read_bytes);
	return EXIT_FAILURE;
      }
    
      /* copy to the output buffer */
      for(i=0; i<read_bytes; i++)
        buff_out[bcopied+i]=buf[i];

      bcopied += read_bytes;
      bytes_left -= bytes_to_copy;
    }

    /* Quit at this record */
    break;
  }

  limeDestroyReader(reader);
  DCAP(fclose)(fp);

  return EXIT_SUCCESS;
}   
Exemplo n.º 7
0
int read_binary_contraction_data_3d(double * const s, LimeReader * limereader, const int prec, const int N, DML_Checksum *ans) {
#ifdef MPI
  fprintf(stderr, "[read_binary_contraction_data_3d] No mpi version.\n");
  return(1);
#else
  int status=0, mu;
  n_uint64_t bytes, ix;
  double *tmp;
  DML_SiteRank rank;
  float *tmp2;
  int x, y, z;
  int words_bigendian = big_endian();
  unsigned int VOL3 = LX * LY * LZ;

  DML_checksum_init(ans);
  rank = (DML_SiteRank) 0;
 
  if( (tmp = (double*)malloc(2*N*sizeof(double))) == (double*)NULL ) {
    exit(500);
  }
  if( (tmp2 = (float*)malloc(2*N*sizeof(float))) == (float*)NULL ) {
    exit(501);
  }
 
 
  if(prec == 32) bytes = 2*N*sizeof(float);
  else bytes = 2*N*sizeof(double);
  for(x = 0; x < LX; x++){
  for(y = 0; y < LY; y++){
  for(z = 0; z < LZ; z++){
    ix = g_ipt[0][x][y][z];
    rank = (DML_SiteRank) (( LXstart + x)*(LY*g_nproc_y) + LYstart + y)*LZ + z;
    if(prec == 32) {
      status = limeReaderReadData(tmp2, &bytes, limereader);
      DML_checksum_accum(ans,rank,(char *) tmp2, bytes);	    
    }
    else {
      status = limeReaderReadData(tmp, &bytes, limereader);
      DML_checksum_accum(ans,rank,(char *) tmp, bytes);
    }
 
    for(mu=0; mu<N; mu++) {
      if(!words_bigendian) {
        if(prec == 32) {
          byte_swap_assign_single2double(s + _GWI(mu,ix,VOL3), (float*)(tmp2+2*mu), 2);
        } else {
          byte_swap_assign(s + _GWI(mu,ix,VOL3), (float*)(tmp+2*mu), 2);
        }
      } else {  // words_bigendian true
        if(prec == 32) {
          single2double(s + _GWI(mu,ix,VOL3), (float*)(tmp2+2*mu), 2);
        }
        else {
          s[_GWI(mu, ix,VOL3)  ] = tmp[2*mu  ];
          s[_GWI(mu, ix,VOL3)+1] = tmp[2*mu+1];
        }
      }
    }

    if(status < 0 && status != LIME_EOR) {
      return(-1);
    }
  }}}
  if(g_cart_id == 0) printf("\n# [read_binary_contraction_data] The final checksum is %#lx %#lx\n", (*ans).suma, (*ans).sumb);

  free(tmp2); free(tmp);
  return(0);
#endif
}
Exemplo n.º 8
0
// Read in the gaugefield, deprecated tmLqcd routine
void GaugeField::read_lime_gauge_field_doubleprec_timeslices(double *gaugefield,
                                                             const char *filename,
                                                             const ssize_t slice_i,
                                                             const ssize_t slice_f) {
  try {
    // const int slice_i = 0;
    // const int slice_f = Lt+1;

    FILE *ifs;
    ssize_t t, x, y, z;
    int status;
    n_uint64_t bytes;
    char *header_type;
    LimeReader *limereader;
    double tmp[72], tmp2[72];
    int words_bigendian;

    printf("reading gauge fields from files:\n");
    //    if(verbose){
    //      printf("reading gauge fields from files:\n");
    //    }
    //    else{
    //      printf("\treading gauge fields:\n");
    //    }

    words_bigendian = big_endian();
    ifs = fopen(filename, "r");
    if (ifs == (FILE *)NULL) {
      fprintf(stderr, "Could not open file %s\n Aborting...\n", filename);
      exit(500);
    }
    limereader = limeCreateReader(ifs);
    if (limereader == (LimeReader *)NULL) {
      throw std::runtime_error("Unable to open LimeReader!");
    }
    while ((status = limeReaderNextRecord(limereader)) != LIME_EOF) {
      if (status != LIME_SUCCESS) {
        fprintf(
            stderr, "limeReaderNextRecord returned error with status = %d!\n", status);
        status = LIME_EOF;
        break;
      }
      header_type = limeReaderType(limereader);
      if (strcmp("ildg-binary-data", header_type) == 0)
        break;
    }
    if (status == LIME_EOF) {
      fprintf(stderr, "no ildg-binary-data record found in file %s\n", filename);
      limeDestroyReader(limereader);
      fclose(ifs);
      exit(-2);
    }
    bytes = limeReaderBytes(limereader);
    if (bytes != (n_uint64_t)Lx * Ly * Lz * Lt * 72 * (n_uint64_t)sizeof(double)) {
      if (bytes != (n_uint64_t)Lx * Ly * Lz * Lt * 72 * (n_uint64_t)sizeof(double) / 2) {
        fprintf(stderr,
                "Probably wrong lattice size or precision (bytes=%lu) in file %s "
                "expected %lu\n",
                (n_uint64_t)bytes,
                filename,
                (n_uint64_t)Lx * Ly * Lz * Lt * 72 * (n_uint64_t)sizeof(double));
        fprintf(stderr, "Aborting...!\n");
        fflush(stdout);
        exit(501);
      } else {
        fclose(ifs);
        throw std::runtime_error("Single precision read!");
      }
    }

    bytes = (n_uint64_t)72 * sizeof(double);

    for (t = 0; t < Lt; t++) {
      for (z = 0; z < Lz; z++) {
        for (y = 0; y < Ly; y++) {
          for (x = 0; x < Lx; x++) {
            // check for endianess and reading in data
            // the pointer limereader is internally increased by bytes
            // in the limeReaderReadData function
            if (!words_bigendian) {
              status = limeReaderReadData(tmp, &bytes, limereader);
              byte_swap_assign(tmp2, tmp, 72);
            } else
              status = limeReaderReadData(tmp2, &bytes, limereader);
            // check if reading was successfull
            if (status < 0 && status != LIME_EOR) {
              fprintf(stderr,
                      "LIME read error occured with status = %d while reading file %s!\n "
                      "Aborting...\n",
                      status,
                      filename);
              exit(500);
            }

            // we just want to read in data in the specific range of timeslices
            // must be here because the limereader pointer must be increased
            // correctly
            // could be done with much more performance but might be tricky to
            // do correctly
            if (t < slice_i || t > slice_f)
              continue;

            // copy of link variables from tmp2 into config
            // ILDG has mu-order: x,y,z,t so it is changed here to: t,x,y,z !
            const ssize_t p =
                (ssize_t)(((t - slice_i) * Lx * Lz * Lz + x * Ly * Lz + y * Lz + z) *
                          72);  // position in config
            ssize_t k = 0;
            for (ssize_t mu = 1; mu <= 4; mu++) {  // mu=4 is for the shift of U_t
              ssize_t index;
              if (mu != 4)
                index = p + mu * 18;  // for U_x, U_y and U_z
              else
                index = p;  // U_t is copied into the beginning of
              // the (config+p) array

              for (ssize_t i = 0; i < 3; i++) {
                for (ssize_t j = 0; j < 3; j++) {
                  gaugefield[index + 6 * i + 2 * j] = tmp2[2 * k];
                  gaugefield[index + 6 * i + 2 * j + 1] = tmp2[2 * k + 1];
                  k++;
                }
              }

            }  // loop over mu ends here

          }  // loop over position space ends here
        }
      }
    }
    if (status < 0 && status != LIME_EOR) {
      fprintf(stderr,
              "LIME read error occured with status = %d while reading file %s!\n "
              "Aborting...\n",
              status,
              filename);
      exit(500);
    }
    limeDestroyReader(limereader);
    fclose(ifs);
    return;

  } catch (std::exception &e) {
    std::cout << e.what()
              << "in: ReadWrite::read_lime_gauge_field_doubleprec_timeslices\n";
    throw e;
  }
}
int main(int argc, char *argv[]) 
{
  char* data_buf;
  
  LimeReader *reader;
  FILE *fp;
  int status;
  n_uint64_t nbytes, read_bytes;
  int msg,rec,first;
  char *lime_type;
  size_t bytes_pad;
  int MB_flag, ME_flag;
  
  if( argc != 2 ) { 
    fprintf(stderr, "Usage: %s <lime_file>\n", argv[0]);
    return EXIT_FAILURE;
  }
  

  fp = DCAPL(fopen)(argv[1], "r");
  if(fp == (FILE *)NULL) { 
    fprintf(stderr,"Unable to open file %s for reading\n", argv[1]);
    return EXIT_FAILURE;
  }

  reader = limeCreateReader(fp);
  if( reader == (LimeReader *)NULL ) { 
    fprintf(stderr, "Unable to open LimeReader\n");
    return EXIT_FAILURE;
  }

  msg = 0; first = 1; rec = 0;
  while( (status = limeReaderNextRecord(reader)) != LIME_EOF ){
    
    if( status != LIME_SUCCESS ) { 
      fprintf(stderr, "limeReaderNextRecord returned status = %d\n", 
	      status);
      return EXIT_FAILURE;
    }

    nbytes    = limeReaderBytes(reader);
    lime_type = limeReaderType(reader);
    bytes_pad = limeReaderPadBytes(reader);
    MB_flag   = limeReaderMBFlag(reader);
    ME_flag   = limeReaderMEFlag(reader);
    
    if (MB_flag == 1 || first)
      {
	first = 0;
	rec = 0;
	msg++;
      }

    rec++;

    printf("\n\n");
    printf("Message:        %d\n", msg);
    printf("Record:         %d\n", rec);
    printf("Type:           %s\n", lime_type);
    printf("Data Length:    %llu\n", (unsigned long long)nbytes);
    printf("Padding Length: %lu\n", (unsigned long)bytes_pad);
    printf("MB flag:        %d\n", MB_flag);
    printf("ME flag:        %d\n", ME_flag);
    
    /* TO DO: Buffer the input */
    if(nbytes < MAX_BYTES){
      data_buf = (char *)malloc((size_t)nbytes+1);
      if( data_buf == (char *)NULL) { 
	fprintf(stderr, "Couldn't malloc data buf\n");
	return EXIT_FAILURE;
      }
      
      read_bytes = nbytes;
      status = limeReaderReadData((void *)data_buf, &read_bytes, reader);
      
      if( status < 0 ) { 
	if( status != LIME_EOR ) { 
	  fprintf(stderr, "LIME read error occurred: status= %d  %llu bytes wanted, %llu read\n", 
		  status, (unsigned long long)nbytes, 
		  (unsigned long long)read_bytes);
	  return EXIT_FAILURE;
	}
      }
      
      data_buf[nbytes]='\0';
      if(!all_ascii(data_buf, nbytes))
	printf("Data:           [Binary data]\n");
      else
	printf("Data:           \"%s\" \n", data_buf);
      
      free(data_buf);
    }
    else{
	printf("Data:           [Long record skipped]\n");
    }

  }

  limeDestroyReader(reader);
  DCAP(fclose)(fp);

  return EXIT_SUCCESS;

}