Page 1 of 1

Importing a binary data file and manipulating it

Posted: Tue Aug 12, 2014 3:14 pm
by rgd
Hi,

I need to import binary data files each of which are up to 2 GB in size and manipulate the data it contains such as outputing chunks of the data to integer format to a CSV type file or maybe plotting the data directly from LiveCode. I have been learning C to do this kind of thing, but now I have stumbled across LiveCode I am desperately searching for a proper excuse to use it for this purpose :D

I was wondering what bitwise operations are available in LiveCode? Each data entry I have to extract is 2 bytes long, however at the beginning of the file there is information about the data which is composed of variable sized chunks of bits (not bytes) and this kind of information is also spread regularly throughout the data file. Ideally I would like to keep this information and possibly output it into a log file.

Any advice would be much appreciated!

Richard

Re: Importing a binary data file and manipulating it

Posted: Tue Aug 12, 2014 3:36 pm
by jmburnod
Hi Richard,
Welcome.
I'm not a specialist of this but I put an exemple I use with success.

Code: Select all

--•• get the w and h of a png file
function GetWidthHeightPngFile pPathIm --
   put empty into rGetWidthHeightPngFile
   open file pPathIm for binary read
     read from file pPathIm for 24
     put it into tData
     close file pPathIm
   if byte 13 to 16 of tData <> "IHDR" then -- "Invalid PNG format"
      return empty
      exit GetWidthHeightPngFile
     end if
     local tWidth, tHeight
     put binaryDecode("MM", byte 17 to 24 of tData, tWidth, tHeight)\
         into tNumConvertedVals
     if tNumConvertedVals <> 2 then -- Couldn't decode binary data 
      return empty
      exit GetWidthHeightPngFile
     end if
   put tWidth & "," & tHeight into rGetWidthHeightPngFile
   return rGetWidthHeightPngFile
end GetWidthHeightPngFile
Best regards
Jean-Marc

Re: Importing a binary data file and manipulating it

Posted: Tue Aug 12, 2014 3:47 pm
by WaltBrown
Richard, see the bitAnd, bitOr, bitXOr, and bitNot functions in the dictionary.

Re: Importing a binary data file and manipulating it

Posted: Tue Aug 12, 2014 4:52 pm
by dunbarx
Hi.

Read also about the "offset" function, the "wordOffset" function and the "itemDelimiter" property, as a start. You must also learn about "chunking", the ability to identify and manipulate text. Good luck. Write back with anything at all,

Craig Newman