help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Efficient I/O for 24-bit integer?


From: Quentin Spencer
Subject: Re: Efficient I/O for 24-bit integer?
Date: Thu, 16 Jun 2005 09:00:25 -0500
User-agent: Mozilla Thunderbird 1.0.2-1.3.3 (X11/20050513)

Johan Kullstam wrote:

>address@hidden writes:
>  
>
>>perhaps someone on the list has a good idea for this. I am in need
>>for an efficient method to read and write large arrays of 24-bit
>>signed integer values to and from binary files.
>>    
>>
>
>Two options:
>1) Write C++ .oct files to read and write the array(s).
>2) Make a pair of translator programs which convert the 24-bit array
>to something more amenable to octave such as double-float or 32-bit
>integer.  I would choose the double format since that's what octave
>will convert the others into anyway.  (You can squeeze it into a
>single-float since the 23 bit mantissa carries an implied 1 at the
>front.)  The translator could be written in C, C++, fortran, &c.
>
>Given a working C/C++ compiler and mkoctfile, option 1) is actually
>not too hard.
>  
>

I once implemented option (2) a long time ago when disk space was more
expensive than it is now. If I find the files, I'll send them to the
list. If you don't want to write code in C, it seems that you could use
fread to read in all the data as single bytes, and then reassemble the
bytes into 24-bit numbers using something like this:

FID = fopen("file","r");
bytedata = fread(FID,"uchar");
fclose(FID);
data = bitshift(bytedata(1:3:end),16) + bitshift(bytedata(2:3:end),8) +
bytedata(3:3:end);

You may have to modify the last line depending on the endianness of the
data in the file, but I think the concept should work. I don't know
whether it would be faster than other alternatives, but I think it
should be reasonably fast. I haven't thought about how you would write
data, but I think something similar would work using bitand and bitshift.

-Quentin



-------------------------------------------------------------
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
-------------------------------------------------------------



reply via email to

[Prev in Thread] Current Thread [Next in Thread]