Path: news.mathworks.com!newsfeed-00.mathworks.com!newsfeed2.dallas1.level3.net!news.level3.com!postnews.google.com!q1g2000prb.googlegroups.com!not-for-mail
From: NZTideMan <mulgor@gmail.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Writing Binary file to reduce file size
Date: Thu, 24 Jul 2008 02:02:14 -0700 (PDT)
Organization: http://groups.google.com
Lines: 34
Message-ID: <b48fba98-32b8-48bf-9a01-0433ee3fab0a@q1g2000prb.googlegroups.com>
References: <g62e8r$i37$1@fred.mathworks.com> <muy4p6j89c6.fsf@G99-Boettcher.llan.ll.mit.edu> 
NNTP-Posting-Host: 202.78.152.105
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
X-Trace: posting.google.com 1216890134 18691 127.0.0.1 (24 Jul 2008 09:02:14 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: Thu, 24 Jul 2008 09:02:14 +0000 (UTC)
Complaints-To: groups-abuse@google.com
Injection-Info: q1g2000prb.googlegroups.com; posting-host=202.78.152.105; 
User-Agent: G2/1.0
X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Maxthon; 
Xref: news.mathworks.com comp.soft-sys.matlab:481457



On Jul 24, 7:17=A0pm, Rune Allnor <all...@tele.ntnu.no> wrote:
> On 24 Jul, 07:09, "Pete sherer" <t...@abg.com> wrote:
>
> > I think what I want to do is to write a binary file such
> > that I can use other programs besides matlab to read the file. =A0
> > I just need an example how to write and read it, at least
> > from Matlab workspace. =A0Finally I will use other
> > applications to read the data file. =A0
> > I think this is a common example, but I can't seem to find
> > the solution.
>
> The trick is to use FREAD and FWRITE. If you want to read data
> from a file known to contain one 100 x 200 array of doubles,
> you do something like
>
> fid =3D fopen('myfile.dat');
> A=3Dfread(fid,[100,200],'double');
> fclose(fid);
>
> and similar when you write bac to file.
>
> Just be aware of somewhat awkward issues with file formats
> (rows-first or column-first storage) and binary numerical
> formats (big-endian or little-endian formats).
>
> Rune

IMHO, using fread and fwrite when you want to maybe read the data in
using a different program is not advisable.  I've been there and done
that and everytime, reading the binary files on a different platform
or in a different program was a problem.
That's why I suggested netCDF.   Files written in netCDF on a Cray for
example can be read on a PC or Mac in Matlab, Fortran, C, or
whatever.  It is totally portable.