|
Thanks to KevinADC for the suggestions. This has helped get on the right track. So far I've just experimented with extracting values out of single file headers. I've successfully read strings from within the mixed header, but so far have not successfully recovered usable floating point binary values. The documentation of the header shows that at a certain offset, a series of 4 byte "float" (as implemented by MS C++, I think) are to be found. When I try to read as follows, all I get is zeros in the PRINT output. I've succesfully read these values using Delphi (where I read into a variable of type SINGLE, which is a 4 byte floating point type in Delphi. Using Delphi's FloatToString function), where I see the number as expected. So am I doing this wrong in Perl, or does Perl not implement floating point numbers the same way as MS C++ and Delphi do? I admit to being baffled by Perl's inate conversion between numbers and strings, it's lack of "strong typing", and the apparent lack of explict conversion functions to force a certain format. (This is why I put the %e format string in the output.) It's not obvious to me how perl would know that the 4 bytes is in fact a float, that needs to be represented appropriately. Below is a snippet that shows my results.
[code] # reading header of .ABF file, which is a binary file that has a header of over 6 kbyte, that is a mix of # numeric and char strings, created by a commercial program coded in C++. A particular floating point 4 byte # value resides ar offset of 4704 bytes. I try to read it by using sysseek() to set the file pointer to the offset, # then sysread() to read 4 bytes.
sysopen (thefile,'c:\testabf1.abf',0) or die('sysopen failed'); # 0=read only binmode (thefile); $b=sysseek(thefile,4704,0); $a=sysread (thefile,$fragment,4);
# try to force output of a formatted floating point printf ("$a bytes read from offset $b: value extracted is %e\n",$fragment);
# or just let Perl try to figure out what I want to print print ("$a bytes read from offset $b: value extracted is $fragment");
[resulting output] 4 bytes read from offset 4704: value extracted is 0.000000e+000 4 bytes read from offset 4704: value extracted is
# note value of 0.0 in the first case, and just a blank in the second
[\code]
|