Xref: utzoo comp.sys.mac.programmer:21645 comp.sys.mac.misc:8426 Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!wuarchive!zaphod.mps.ohio-state.edu!uakari.primate.wisc.edu!caen!math.lsa.umich.edu!sharkey!bnlux0!bnl.gov!wishart From: wishart@bnl.gov (Jim Wishart) Newsgroups: comp.sys.mac.programmer,comp.sys.mac.misc Subject: Re: Import Binary Date File from PC Message-ID: <2517@bnlux0.bnl.gov> Date: 12 Feb 91 17:03:47 GMT References: <21958@duke.cs.duke.edu> Sender: news@bnlux0.bnl.gov Organization: Brookhaven National Laboratory Lines: 29 In article <21958@duke.cs.duke.edu> fang@physics.phy.duke.edu (Fang Zhong) writes: > I use a PC to automate my experiment. I store my data on the PC > in binary format as: fwrite(&data, sizeof(float), 1,fp); > I can use: fread(&data, sizeof(float), 1, fp); > to read the data back on PC. I plot my data with Igor on Mac. However, > if I use the same line (deleted) > to read the data on Mac after the data has been imported via "default > translation" of Apple File Exchange, I get garbage. The same is true > when I generate binary data on Mac and read it back on PC. This problem > exits regardless which mode I use in AFE. The problem is that the byte order is opposite on Intel and Motorola microprocessors. On Intel machines the order is least significant to most significant byte, while Motorola is MSB->LSB. You must write your own translation routines to swap the bytes between formats. I did this in Fortran for a program ported from MS-DOS so that I could maintain file compatibility. I was reading mixed groups of reals, short integers and strings in large blocks and swapping the bytes in memory. When it came time to save, the bytes were swapped back to write in Intel format. I wrote one routine to swap bytes and another to swap words and applied them as necessary. Strings were not swapped, shorts were byte swapped, and longs were word and byte swapped. Jim Wishart wishart@bnl.gov Chemistry Department Brookhaven National Laboratory,Upton, NY 11973