Daniel (your name is Daniel, right?) -

Once upon a time I gave thought to processing just such a binary
header for some crazy file format. I managed to avoid doing that in
the end by coercing my program to output its data in a text format.

Your understanding of NDims and Dims is not quite correct. I will
attempt to provide a solution, which I hope gives you enough to figure
out what you're doing, but in general I recommend working with
pack/unpack for this process. The major limitation here is that
FlexRaw only knows types that PDL knows, and PDL does not know about
unsigned char types, among others. It's something that's probably not
hard to add, but amazingly it has never been done because the sorts of
people who use PDL---mostly scientists---haven't ever needed it. You
might be able to hack it by unpacking the dataref of the signed char
(called a 'byte' in PDL-speak, as you've already found) into an
unsigned char, but then you may as well just us pack/unpack directly.
If you're not working with the Version 3 of the Header format, it's
not a problem, but this solution is not generally extensible since not
all C data-types are supported.

First, you must name all of your data types thus:

* 8-bit types must be signed and are called 'byte'
* 16-bit integers can be called 'short' or 'ushort'
* 32-bit integers must be signed and are called 'long'
* 64-bit integers must be signed and are called 'longlong'
* 32-bit floats are called 'float'
* 64-bit floats are called 'double'

I got all of the information by reading the contents of PDL::Types
from my machine (yeah, it's not documented in POD, even though that
should be straight-forward... sorry). For everything you're reading
except the complex numbers, NDims will be 1. (For a matrix, NDims
would be 2, for example.) The Dims part will be 1 in the Header
section because you're always reading *a* float or *an* integer, etc.

--------%<--------
my $header = [
    # Header section for Version 4:
    { Type => 'long', NDims => 1, Dims => [1] },  # bDeletedSource (SInt32)
    { Type => 'long', NDims => 1, Dims => [1] },  # bOverrideSourceInfo (SInt32)
    { Type => 'float', NDims => 1, Dims => [1] },  # fStartFreqMHz (Float)
    { Type => 'float', NDims => 1, Dims => [1] },  # fRepFreqHz (Float)
    { Type => 'long', NDims => 1, Dims => [1] },  # bSweepUp (SInt32)
    { Type => 'long', NDims => 1, Dims => [1] },  # nDopplerCells (SInt32)
    { Type => 'long', NDims => 1, Dims => [1] },  # nRangeCells (SInt32)
    { Type => 'long', NDims => 1, Dims => [1] },  # nFirstRangeCell (SInt32)
    { Type => 'float', NDims => 1, Dims => [1] },  # fRangeCellDistKm (Float)
    { Type => 'long', NDims => 1, Dims => [1] },  # nV4Extent (SInt32)
    # Data section for nRangeCells = 1:
    { Type => 'float', NDims => 1, Dims => [512] }, #Antenna1 voltage sq amp
    { Type => 'float', NDims => 1, Dims => [512] }, #Antenna2 voltage sq amp
    { Type => 'float', NDims => 1, Dims => [512] }, #Antenna3 voltage sq amp
    { Type => 'float', NDims => 2, Dims => [2,512] }, #Ant1 x Ant2
    { Type => 'float', NDims => 2, Dims => [2,512] }, #Ant1 x Ant3
    { Type => 'float', NDims => 2, Dims => [2,512] }, #Ant2 x Ant3
];

my @header = readflex($file,$header);
-------->%--------

FlexRaw slurps. It only slurps. I've thought it might be fun to play
around with the code and make it so that it keeps track of its current
read location so that you could perform consecutive reads, but I don't
have the round tuits for that at the moment. If nRangeCells is not 1,
you could begin by forming a partial header with only the Header part,
thus obtaining nRangeCells. You would then push however many copies of
the Data section you need.

Hope that helps, and feel free to ask more questions!
David

_______________________________________________
Perldl mailing list
[email protected]
http://mailman.jach.hawaii.edu/mailman/listinfo/perldl

Reply via email to