Gracious Monks, I'm writing a simple utility to convert 3D vertex information from one file format to another. While reading and parsing the file information I can't seem to figure out why I'm getting very wierd information. For example in a variable that acts as a flag and it's values could be 0-2 it comes in as an arbitrary number in the billions.

Since the file structure is documented as a series of C structs, I tried writing the utility in C which yielded worse results than Perl. At least with Perl I get about 1/4 of the fields back with correct information. Any help or guidance in the right direction would be most appreciated. Here's the code and header structure I'm working with:
*----------- C Code --------------*
struct block1 { char version[64]; char comments[128]; char dummy[8]; long img_param_flag; long img_data_type; float invalid_point; long arr_width; long arr_height; long db_length; long scale; float iscale; float jscale; long trns_matrix_f; double trns_matrix[16]; long img_color; long clr_blk_length; long cam_pos_f; float cam_x; float cam_y; float cam_z; } *blk1;

*----------- Perl Code --------------*
use strict; use Dumpvalue; use POSIX; sub dump_ref { my $ref = shift; my $dumper = new Dumpvalue; print "Content-Type:text/html\n\n"; print "<pre>"; $dumper->dumpValues($ref); print "</pre>"; exit; } # read in the 3D info. # use unpack to parse the structure my ($block1, $block2); open(FP, "<./file.pf") || die("Error opening file: $!\n"); binmode(FP); read(FP, $block1, 512); # 512 byte binary c structure # Note that the longs are in Network order my @block1_info = unpack("a64a128a8NNfNNNNffNd16NNNfffN30",$block1); dump_ref(\@block1_info); exit;
*UPDATE* Apparently the only one coming in erroneous (in Perl) is the transformation matrix... the array of 16 doubles. I'm getting numbers like "3.03865194161742e-319" and when I apply them to the data I get numbers even smaller. Indices 13-28 is what I'm referring to... it's a 4 X 4 transformation matrix for conversion to another coordinate system. Here's a dump of the info I'm getting back:
0 ARRAY(0x80d54b0) 0 "PIF Format v2.0" 1 "" 2 "" 3 0 4 1 5 0 6 149 7 78 8 139464 9 0 10 0 11 0 12 2 13 '3.03865194161742e-319' 14 0 15 0 16 0 17 0 18 0 19 '3.04497598188419e-319' 20 0 21 0 22 '3.03865194161742e-319' 23 0 24 0 25 0 26 0 27 0 28 '3.03865194161742e-319' 29 1 30 11622 31 1 32 0 33 0 34 0 35 0 36 0 37 0 38 0 39 0 40 0 41 0 42 0 43 0 44 0 45 0 46 0 47 0 48 0 49 0 50 0 51 0 52 0 53 0 54 0 55 0 56 0 57 0 58 0 59 0 60 0 61 0 62 0 63 0 64 0

~hb

In reply to C Struct Data Problem by heroin_bob

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.