The data is meteorological data (temperature in degrees K) on a 614 x 428 grid. I tried coding up a reader for this, but am getting nonsensical results. Here is the code:*** First record (4 byte integer) - byte size of record (4*N) (f77 header) (4 byte float) .. value 1 (4 byte float) .. value 2 ... (4 byte float) .. value N N = number of grid points in the field (4 byte integer) .. byte size of record (4*N) (f77 trailer) **** Second record (4 byte integer) - byte size of record (4*N) (f77 header) (4 byte float) .. value 1 (4 byte float) .. value 2 ... (4 byte float) .. value N N = number of grid points in the field (4 byte integer) .. byte size of record (4*N) (f77 trailer)
The results I get when I print out the first field are non-sensical (negative numbers, etc). I think the issue is that I'm not properly setting up my template and record length. Also, how do I find out what is "the native format of the machine"?my $out_file = "/dicast2-papp/DICAST/smg_data/" . $gfn . ".bin"; #path + to binary file my $template = "if262792i"; #binary layout (integer 262792 floats in +teger) as described in the format documentation above (not sure if th +is is correct) my $record_length = 4; #not sure what record_length is supposed to rep +resent (number of values in 1st record, or should it be length of var +iable [4 bytes]) my (@fields,$record); open (FH, $out_files ) || die "couldn't open $out_files\n"; until (eof(FH)) { my $val_of_read = read (FH, $record, $record_length) == $record_ +length or die "short read\n"; @fields = unpack ($template, $record); print "field = $fields[0]\n"; }
In reply to reading binary files with Perl by jpk1292000
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |