[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Efficient I/O for 24-bit integer?
From: |
reiner |
Subject: |
Efficient I/O for 24-bit integer? |
Date: |
Tue, 07 Jun 2005 14:27:09 +0200 |
Hello,
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. I have come up with the following:
read:
[sig, cnt] = fread(fid, [3, siz], 'uchar');
sig0 = sig(1,:) + 256*sig(2,:) + 65536*sig(3,:);
index = find(sig0 > 8388608);
sig0(index) = sig0(index)-16777216;
sig = sig0/8388608;
write:
sig0 = sig*8388608;
index = find(sig0 < 0);
sig0(index) = 16777216+sig0(index);
s3=floor(sig0./65536);
r=rem(sig0,66536);
s2=floor(r./256);
s1=rem(r,256);
sig=[s1 s2 s3];
fwrite(fid, sig', 'uchar');
Can this be done more efficiently? The files I read contain rather large arrays
and I would like it to work faster.
Thanks for any ideas you might have.
Reiner Suikat
-------------------------------------------------------------
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
-------------------------------------------------------------
- Efficient I/O for 24-bit integer?,
reiner <=