fread bug in octave 3.8.0?

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

fread bug in octave 3.8.0?

Petri Piila
Dear All,

Is there possibly a bug related to function fread in octave 3.8.0 or is this just octave os x problem (I’m running on 10.9 Maverics).

Demonstration :

First I save a matrix with fwrite and the try to read it with fread.

a = ones(4,4);
f = fopen(“frtest”,”wb”);
count = fwrite(f,a,”double”);
fclose(f);

Now count is 16 as expected.

f = fopen(“frtest”,”rb”);
[b,count] = fread(f,[1,Inf],”double");
fclose(f);

This works in 3.6.4 but now gives count = 128 and size(b) = [1 17]. First sixteen values are right and the last one is zero. Now count seems to be in bytes as 128/8 = 16

If I force count to 16 by using [1,16] or [4,4] instead of [1,Inf] I get count = 128 as before  and matrix b is of size 16 or 4,4.

So, is it intentional that count in fread is now in bytes and why the extra zero in result if I use Inf which used to be handy if I don’t know the size beforehand?

Regards,
Petri Piila

_______________________________________________
Help-octave mailing list
[hidden email]
https://mailman.cae.wisc.edu/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: fread bug in octave 3.8.0?

Mike Miller
On Mon, Jan 13, 2014 at 12:05:01 +0200, Petri Piila wrote:

> Dear All,
>
> Is there possibly a bug related to function fread in octave 3.8.0 or is this just octave os x problem (I’m running on 10.9 Maverics).
>
> Demonstration :
>
> First I save a matrix with fwrite and the try to read it with fread.
>
> a = ones(4,4);
> f = fopen(“frtest”,”wb”);
> count = fwrite(f,a,”double”);
> fclose(f);
>
> Now count is 16 as expected.
>
> f = fopen(“frtest”,”rb”);
> [b,count] = fread(f,[1,Inf],”double");
> fclose(f);
>
> This works in 3.6.4 but now gives count = 128 and size(b) = [1 17]. First sixteen values are right and the last one is zero. Now count seems to be in bytes as 128/8 = 16
>
> If I force count to 16 by using [1,16] or [4,4] instead of [1,Inf] I get count = 128 as before  and matrix b is of size 16 or 4,4.
>
> So, is it intentional that count in fread is now in bytes and why the extra zero in result if I use Inf which used to be handy if I don’t know the size beforehand?

Yes, this bug has apparently been reported and fixed, see

  https://savannah.gnu.org/bugs/?41091

--
mike
_______________________________________________
Help-octave mailing list
[hidden email]
https://mailman.cae.wisc.edu/listinfo/help-octave