Re:: Reading binary data.

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

Re:: Reading binary data.

Randall M. Brannan
> Date: Tue, 31 Jan 95 13:47:17 CST
> From: [hidden email] (Vinayak Dutt)
> Subject: Re: Reading binary data.
> To: [hidden email]
> Sender: [hidden email]
>                                                  
> # brannan writes:
> #I'm new to this list so please forgive me for asking a question which
> #may have already been covered.  Can Octave read a binary data file?
> # .....................stuff deleted
>
> vinayak replies:
>
>  i have used fopen() to open a binary file. fopen() should open any type of file,
> not just text file.
>
> you would require octave version 1.1 to read binary files though (using fread()).
>
>
>

  I'm using version 1.1.0.  I'm using the following 2 lines to read the
data:
fid=fopen(data_name,'r');
[data_array,count]=fread(fid,[collumns,rows],'float');
  I've tried replacing 'r' with 'rb', 'b', and 'br'.  Octave never
complains but, when it returns, count always equals zero and data_array
is always filled with NaN's.  This same file reads just fine when I
fopen it with MATLAB and fread it as 'float'.  Are there other arguments,
perhaps undocumented, I should be using with Octave?

                               R. Brannan


Reply | Threaded
Open this post in threaded view
|

Re:: Reading binary data.

Vinayak Dutt
#
#  I'm using version 1.1.0.  I'm using the following 2 lines to read the
#data:
#fid=fopen(data_name,'r');
#[data_array,count]=fread(fid,[collumns,rows],'float');
#  I've tried replacing 'r' with 'rb', 'b', and 'br'.  Octave never
#complains but, when it returns, count always equals zero and data_array
#is always filled with NaN's.  This same file reads just fine when I
#fopen it with MATLAB and fread it as 'float'.  Are there other arguments,
#perhaps undocumented, I should be using with Octave?
#

just check fid after fopen(), its is not null (0), then fopen() did succeed.

also, your usage is correct. i have written a function to read an image
format into octave which uses fread() in similar way.  i don't see any errors
what so ever. it reads correct number of elements and puts them in the
returned matrix.

by the way, i had compiled octave locally on SunOS4.1.3 with
gcc-2.6.0 and Sun F77-2.0.1.


--vinayak-
/*
 * vinayak dutt
 * graduate student, ultrasound research
 * mayo graduate school, rochester mn
 *
 * e-mail: [hidden email]
 *         [hidden email]
 *
 */
#include "disclaimer.h"