public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* fread help!
@ 2001-08-09 11:44 GI-HYEON PARK
  2001-08-09 11:51 ` friedman_hill ernest j
  0 siblings, 1 reply; 2+ messages in thread
From: GI-HYEON PARK @ 2001-08-09 11:44 UTC (permalink / raw)
  To: cygwin

Hi,

I am trying to read binary file in WIN ME and it does not read data
correctly.
I tried the same code in solaris and it works fine..

Does anybody know why C program in WIN ME reads data wrong?

Thanks..

Here is my code..

#include <stdio.h>
#include <stdlib.h>
#include "MATRIX.h"
#include "MATRIX.c"
#include "SetValue.h"
#include "SetValue.c"

int main(void)
{
	char data[200];
	int k,m;
	float **rin,**rout;
	FILE *fp;

	rout=M2D_alloc(400,480);
	rin=M2D_alloc(400,480);
	SetFloatValue(400, 480, rin, -9999.0);
	SetFloatValue(400, 480, rout, -9999.0);

	setmode(fp,'b');
	sprintf(data,"%s","00061_00.bin");

	fp=fopen(ddd,"rb");

	for(k=0;k<400;k++)
		fread( *(rin+k), sizeof (float), 480, fp);  // Is this not working
correctly in Win ME?
    	fclose(fp);

	for(k=0;k<400; k++){
		for(m=0;m<480;m++){
			printf("%8.2f\n",rin[k][m]);
		}
	}

	M2DFree(rin,400);
	M2DFree(rout,400);

}


--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: fread help!
  2001-08-09 11:44 fread help! GI-HYEON PARK
@ 2001-08-09 11:51 ` friedman_hill ernest j
  0 siblings, 0 replies; 2+ messages in thread
From: friedman_hill ernest j @ 2001-08-09 11:51 UTC (permalink / raw)
  To: gpark; +Cc: cygwin

Well, here's a guess: the binary file was created on a SPARC Solaris
machine, and you're reading it on a Wintel machine. SPARC processors
are "big-endian" and Intel processors are "little-endian." If that's
the case, then you need to byte-swap the values as you read them
in. See, for instance, the cookbook at
http://astronomy.swin.edu.au/pbourke/dataformats/pcbinary.html .

I think GI-HYEON PARK wrote:
[Charset iso-8859-1 unsupported, filtering to ASCII...]
> Hi,
> 
> I am trying to read binary file in WIN ME and it does not read data
> correctly.
> I tried the same code in solaris and it works fine..
> 
> Does anybody know why C program in WIN ME reads data wrong?



---------------------------------------------------------
Ernest Friedman-Hill  
Distributed Systems Research        Phone: (925) 294-2154
Sandia National Labs                FAX:   (925) 294-2234
Org. 8920, MS 9012                  ejfried@ca.sandia.gov
PO Box 969                  http://herzberg.ca.sandia.gov
Livermore, CA 94550

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2001-08-09 11:51 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-08-09 11:44 fread help! GI-HYEON PARK
2001-08-09 11:51 ` friedman_hill ernest j

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).