From help-request at octave dot org Tue Dec 14 08:37:25 2004 Subject: Re: writing integer with fwrite From: "John W. Eaton" To: Reiner dot Suikat at dlr dot de cc: help at octave dot org Date: Tue, 14 Dec 2004 09:38:27 -0500 On 14-Dec-2004, David Bateman wrote: | According to Reiner dot Suikat at dlr dot de (on 12/14/04): | > Hello and thanks for the quick answer, | > | > But it doesn't solve the problem. | > The statement: | > cnt=fwrite(fid, bytes,'uint32') | > Returns cnt=2, so it uses two uint32 values to store the one variable, | > in Matlab it returns cnt=1, converting the value bytes to a | > 32bit-Integer before writing. I need it to store as a 4byte value when | > using uint32. | > Any ideas? | > I am using the precompiled windows version 2.150 from sourceforge. | > Is this perhaps a known bug? | | Use the uint32 from the latest versions of octave (2.1.64 for example) | and cast as uint32 before calling fwrite | | cnt=fwrite(fid, uint32(bytes), 'uint32') It seems that with 2.1.64 the explicit type conversion is not necessary: octave:1> fid = fopen ("x.out", "w"); octave:2> cnt = fwrite (fid, pi, "ulong") cnt = 1 octave:3> cnt = fwrite (fid, pi, "uint32") cnt = 1 octave:4> fclose (fid); octave:5> fid = fopen ("x.out", "r"); octave:6> fread (fid, 1, "ulong") ans = 3 octave:7> fread (fid, 1, "uint32") ans = 3 This is on an x86 system running Debian. BTW, the 2.1.50 snapshot was made almost 1-1/2 years ago. You should really try a later version. 2.1.64 is the current "testing" or "recommended" version. jwe ------------------------------------------------------------- Octave is freely available under the terms of the GNU GPL. Octave's home on the web: http://www.octave.org How to fund new projects: http://www.octave.org/funding.html Subscription information: http://www.octave.org/archive.html -------------------------------------------------------------