Importing a binary data file and manipulating it

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
rgd
Posts: 1
Joined: Tue Aug 12, 2014 3:02 pm

Importing a binary data file and manipulating it

Post by rgd » Tue Aug 12, 2014 3:14 pm

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

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2729
Joined: Sat Dec 22, 2007 5:35 pm
Contact:

Re: Importing a binary data file and manipulating it

Post by jmburnod » Tue Aug 12, 2014 3:36 pm

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
https://alternatic.ch

WaltBrown
Posts: 466
Joined: Mon May 11, 2009 9:12 pm

Re: Importing a binary data file and manipulating it

Post by WaltBrown » Tue Aug 12, 2014 3:47 pm

Richard, see the bitAnd, bitOr, bitXOr, and bitNot functions in the dictionary.
Walt Brown
Omnis traductor traditor

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10333
Joined: Wed May 06, 2009 2:28 pm

Re: Importing a binary data file and manipulating it

Post by dunbarx » Tue Aug 12, 2014 4:52 pm

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

Post Reply