Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8483653
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T20:09:53+00:00 2026-06-10T20:09:53+00:00

I am trying to read binary files generated on a Linux machine (OpenSuse 11.2,

  • 0

I am trying to read binary files generated on a Linux machine (OpenSuse 11.2, 64bit) on a Windows (xp 32bit) machine using the same c code, just compiled on the respective machines. On the windows machine I am using MinGW compiler.

I can read and write the files without error on the Linux machine however, when I try to read the files on a windows machine, the code seems to be failing on an end of file error.

specifically: feof(file)==16

Does anybody know what the problem might be? The bigger problem might be that fact that my C skills are not very strong…

I pulled some of the write code out (Well at least I think). Note: there is an option to write out ASCII files, however I prefer not to:

void write_node_data(void *nndes, void *x, void *y, void *z)
 {
   int tmpnndes;
   float *tempx, *tempy, *tempz;
   double *tempx64, *tempy64, *tempz64;
   long tmpnndes64, longcount, totnodes;

   strcpy(tmpname, "nodes   ");  

   if (iflag64)
      totnodes = tmpnndes64 = *((long *) nndes);
   else
      totnodes = tmpnndes = *((int *) nndes);

   if (rflag64)
     {
      tempx64 = (double *) malloc(sizeof(double) * totnodes);
      tempy64 = (double *) malloc(sizeof(double) * totnodes);
      tempz64 = (double *) malloc(sizeof(double) * totnodes);
     }
   else
     {
      tempx = (float*) malloc(sizeof(float) * totnodes);
      tempy = (float*) malloc(sizeof(float) * totnodes);
      tempz = (float*) malloc(sizeof(float) * totnodes);
     }
    if (rflag64)
      {
       for (longcount = 0; longcount < totnodes; longcount++)
     {
      tempx64[longcount] = *((double *) x + longcount);
          tempy64[longcount] = *((double *) y + longcount);
      tempz64[longcount] = *((double *) z + longcount);
         }
      }
    else
      {
       for (longcount = 0; longcount < totnodes; longcount++)
         {
          tempx[longcount] = *((float *) x + longcount); 
          tempy[longcount] = *((float *) y + longcount); 
          tempz[longcount] = *((float *) z + longcount);
     }
      }

   if (filetype == IEEE_F)
      fwrite(tmpname,sizeof(char),8,fp);
   else
      fprintf(fp,"nodes  "); 

   if (iflag64)
     {
      if (filetype == IEEE_F)
         fwrite(&tmpnndes64, INT64, 1, fp);
      else
         fprintf(fp,"%ld\n",tmpnndes64);
      n_nodes = tmpnndes64;
     }
   else
     {
      if (filetype == IEEE_F)
         fwrite(&tmpnndes, INT32, 1, fp);
      else
         fprintf(fp,"%d\n",tmpnndes);
      n_nodes = tmpnndes;
     }
   if (rflag64)
     {
      if (filetype == IEEE_F)
        {
         fwrite(tempx64, FLOAT64, n_nodes, fp);
         fwrite(tempy64, FLOAT64, n_nodes, fp);
         fwrite(tempz64, FLOAT64, n_nodes, fp);
        }
      else
        {
         write_ascii_double(n_nodes, tempx64);
         write_ascii_double(n_nodes, tempy64);
         write_ascii_double(n_nodes, tempz64);
        }
      free(tempx64), free(tempy64), free(tempz64);
     }
   else
     {
      if (filetype == IEEE_F)
        {
         fwrite(tempx, FLOAT32, n_nodes, fp);
         fwrite(tempy, FLOAT32, n_nodes, fp);
         fwrite(tempz, FLOAT32, n_nodes, fp);
        }
      else
        {
         write_ascii_float(n_nodes, tempx);
         write_ascii_float(n_nodes, tempy);
         write_ascii_float(n_nodes, tempz);
        }
      free(tempx), free(tempy), free(tempz);
     }
 }

And the reading code:

if (lstructuredflag == 0 || lstructuredflag == 2)
     {
      lxic = (double *)malloc((lnodes)*sizeof(double));
      lyic = (double *)malloc((lnodes)*sizeof(double));
      lzic = (double *)malloc((lnodes)*sizeof(double));
      if (lxic == NULL || lyic == NULL || lzic == NULL)
        {
         gmvrdmemerr();
         return;
        }
      if (ftype != ASCII)
        {
         if (ftype == IEEEI4R8 || ftype == IEEEI8R8)
           {
            tmpdouble = (double *)malloc((3*lnodes)*sizeof(double));
            if (tmpdouble == NULL)
              {
               gmvrdmemerr();
               return;
              }
            binread(tmpdouble,doublesize,DOUBLE,3*lnodes,gmvin);
            ioerrtst(gmvin);
            if (node_inp_type == 0)  /*  nodes type  */
              {
               for (i = 0; i < lnodes; i++)
                 {
                  lxic[i] = tmpdouble[i];
                  lyic[i] = tmpdouble[lnodes+i];
                  lzic[i] = tmpdouble[2*lnodes+i];
                 }
              }
            if (node_inp_type == 1)  /*  nodev type  */
              {
               for (i = 0; i < lnodes; i++)
                 {
                  lxic[i] = tmpdouble[3*i];
                  lyic[i] = tmpdouble[3*i+1];
                  lzic[i] = tmpdouble[3*i+2];
                 }
              }
            FREE(tmpdouble);
           }
         else
           {
            tmpfloat = (float *)malloc((3*lnodes)*sizeof(float));
            if (tmpfloat == NULL)
              {
               gmvrdmemerr();
               return;
              }
            binread(tmpfloat,floatsize,FLOAT,3*lnodes,gmvin);
            ioerrtst(gmvin);
            if (node_inp_type == 0)  /*  nodes type  */
              {
               for (i = 0; i < lnodes; i++)
                 {
                  lxic[i] = tmpfloat[i];
                  lyic[i] = tmpfloat[lnodes+i];
                  lzic[i] = tmpfloat[2*lnodes+i];
                 }
              }
            if (node_inp_type == 1)  /*  nodev type  */
              {
               for (i = 0; i < lnodes; i++)
                 {
                  lxic[i] = tmpfloat[3*i];
                  lyic[i] = tmpfloat[3*i+1];
                  lzic[i] = tmpfloat[3*i+2];
                 }
              }
            FREE(tmpfloat);
           }
        }
      if (ftype == ASCII)
        {
         tmpdouble = (double *)malloc((3*lnodes)*sizeof(double));
         if (tmpdouble == NULL)
              {
               gmvrdmemerr();
               return;
              }
         rdfloats(tmpdouble,3*lnodes,gmvin);
         if (node_inp_type == 0)  /*  nodes type  */
           {
            for (i = 0; i < lnodes; i++)
              {
               lxic[i] = tmpdouble[i];
               lyic[i] = tmpdouble[lnodes+i];
               lzic[i] = tmpdouble[2*lnodes+i];
              }
           }
         if (node_inp_type == 1)  /*  nodev type  */
           {
            for (i = 0; i < lnodes; i++)
              {
               lxic[i] = tmpdouble[3*i];
               lyic[i] = tmpdouble[3*i+1];
               lzic[i] = tmpdouble[3*i+2];
              }
           }
         FREE(tmpdouble);
        }
     }

the function Binread:

int binread(void* ptr, int size, int type, long nitems, FILE* stream)
{
  int ret_stat;

#ifdef CRAY

  float *floatptr, *floatbuf; 
  double *doubleptr, *doublebuf; 
  int tierr, ttype, tbitoff;
  char *charptr;
  int  *intptr, *intbuf;
  short *shortptr, *shortbuf;

   tbitoff = 0;  tierr = 0;
   ret_stat = 0;

   switch(type)
     {

      case CHAR:
        charptr = (char *)ptr;
        ret_stat = fread(charptr, size, nitems, stream);
        break;

      case SHORT:
        ttype = 7;
        shortbuf = (short *)malloc(size*nitems);
        shortptr = (short *)ptr;

        ret_stat = fread(shortbuf, size, nitems, stream);
        tierr = IEG2CRAY(&ttype, &nitems, shortbuf, &tbitoff, shortptr);
        free(shortbuf);
        break;

      case INT:
        ttype = 1;
        intptr = (int *)ptr;
        intbuf = (int *)malloc(size*nitems);

        ret_stat = fread(intbuf, size, nitems, stream);
        tierr = IEG2CRAY(&ttype, &nitems, intbuf, &tbitoff, intptr);
        free(intbuf);
        break;

      case FLOAT:
        ttype = 2;
        floatptr = (float *)ptr;
        floatbuf = (float *)malloc(size*nitems);

        ret_stat = fread(floatbuf, size, nitems, stream);
        tierr = IEG2CRAY(&ttype, &nitems, floatbuf, &tbitoff, floatptr);
        free(floatbuf);
        break;

      case DOUBLE:
        ttype = 3;
        doubleptr = (double *)ptr;
        doublebuf = (double *)malloc(size*nitems);

        ret_stat = fread(doublebuf, size, nitems, stream);
        tierr = IEG2CRAY(&ttype, &nitems, doublebuf, &tbitoff, doubleptr);
        free(doublebuf);
        break;

      case WORD:
        intptr = (int *)ptr;
        ret_stat = fread(intptr, size, nitems, stream);
        break;

      default:
        fprintf(stderr,"Error: Cannot match input datatype.\n");
        gmv_data.keyword = GMVERROR;
        return;
     }

     if(tierr != 0)
       {
        fprintf(stderr,"Error: Cannot convert IEEE data to CRAY\n");
        gmv_data.keyword = GMVERROR;
        return;
       }

     return ret_stat;

#else

   ret_stat = fread(ptr, size, nitems, stream);

   if (swapbytes_on && type != CHAR && type != WORD)
      swapbytes(ptr, size, nitems);

   return ret_stat;

#endif

}

Disclaimer: I did not write this code I am simply trying to use it.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T20:09:54+00:00Added an answer on June 10, 2026 at 8:09 pm

    Did you specify “b” to open the file in binary mode? Try using fopen(fname, "rb")

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using Python (3.1 or 2.6), I'm trying to read data from binary data files
I am trying to read binary data from sys.stdin using Python 2.7 on Windows
I'm trying to read the binary data from a binary file with the code
I am trying to read the number of line in a binary file using
I'm trying to store some binary data obtained from read() in my buffer using
I'm reading in binary files normally using: //What I use to read in the
I am trying to write a program that reads in binary files using C++.
I am trying to read in data stored in a custom binary file generated
I am trying to read multiple binary (365)files and do some calculations then read
Iam trying to read a binary file to memory and pass the starting address

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.