I am trying to unpack a variable containing a string received from a spectrum analyzer:
#42404?û¢-+Ä¢-VÄ¢-oÆ¢-8æ¢-bÉ¢-ôÿ¢-+Ä¢-?Ö¢-sÉ¢-ÜÖ¢-¦ö¢-=Æ¢-8æ¢-uô¢-=Æ¢-\Å¢-uô¢-?ü¢-}¦¢-=Æ¢-)…
The format is real 32 which uses four bytes to store each value. The number #42404 represents 4 extra bytes present and 2404/4 = 601 points collected. The data starts after #42404. Now when I receive this into a string variable,
$lp = ibqry($ud,":TRAC:DATA? TRACE1;*WAI;");
I am not sure how to convert this into an array of numbers :(… Should I use something like the followin?
@dec = unpack("d", $lp);
I know this is not working, because I am not getting the right values and the number of data points for sure is not 601…
First, you have to strip the
#42404off and hope none of the following binary data happens to be an ASCII number.I’m not sure what format “Real 32” is, but I’m going to guess that it’s a single precision floating point which is 32 bits long. Looking at the pack docs.
dis “double precision float”, that’s 64 bits. So I’d tryfwhich is “single precision”.Whether your data is big or little endian is a problem.
dandfuse your computer’s native endianness. You may have to force endianness using the>and<modifiers.