On 10/20/2010 5:19 AM, Ingo Schmid wrote:
>
> I'm reading imaging data that looks like the following:
>
> (header+2*x,y,z, ...)
>
> In other words, there is a line of complex data (two floats)
> preceded by a header (128 bytes long, 47 fields of different
> data type (bitmaps, ushort, long ...).
I suggest using PDL slicing ops to manipulate the
data by chunks, collect the headers, then unpack
them all at once. Here is an example session with
byte data of size [header(1byte)+3,3]. Note the
use of the get_dataref() method to access the header
as packed data so that unpack may be used.
pdl> open DD, ">data.raw"
pdl> $dat = pack "C*", 1,2,3,4,5,6,7,8,9,10,11,12
pdl> p length $dat
12
pdl> binmode DD
pdl> print DD $dat
pdl> close DD
pdl> $dpdl = readflex('data.raw', [ { Type=>'byte', NDims=>1, Dims=>[12] } ])
pdl> ?vars
PDL variables in package main::
Name Type Dimension Flow State Mem
----------------------------------------------------------------
$dpdl Byte D [12] P 0.01Kb
pdl> p $dpdl
[1 2 3 4 5 6 7 8 9 10 11 12]
pdl> reshape $dpdl, 4,3
pdl> p $dpdl
[
[ 1 2 3 4]
[ 5 6 7 8]
[ 9 10 11 12]
]
pdl> $dhdr = $dpdl((0))
pdl> p $dhdr
[1 5 9]
pdl> p $dhdr->get_dataref
SCALAR(0x2c3d380)
pdl> p unpack "C*", ${$dhdr->get_dataref}
1 5 9
Hope this helps,
Chris
_______________________________________________
Perldl mailing list
[email protected]
http://mailman.jach.hawaii.edu/mailman/listinfo/perldl