User talk:Rswinkle
Contents: Description, Arguments, Usage, Examples, Related Functions Supported Under Version: >1.69 Current Davinci Version: 2.27 64-bit Safe: No
Description Unpack binary data from a file, given a template
Arguments and Return Values Arguments: A template string and a file name. Return Value: A davinci structure
Usage Syntax: unpack(template = STRING, filename = STRING [, start_pos = 0]) The unpack function reads binary data from the input file, interprets it according to the specified record template, and returns it in a davinci structure. The optional start_pos parameter specifies the bytes into the file to skip before decoding the file. The template is made up of column specifications of the form "A[n][*m]", where, "A" can be one of the following letters: Letter Meaning Allowable byte-sizes ("n") 'a' string 1+ 'I' signed msb int 1-4 'U' unsigned msb int 1-4 'i' signed lsb int 1-4 'u' unsigned lsb int 1-4 'r' lsb real 4, 8 'R' msb real 4, 8 'x' skip 1+ "n" is the size (in bytes), and "m" is the multiplicity, of repeat of "A[n]". If either "m" or "n" is not specified, it is assumed to be one. "*" is part of the syntax. For example, "i4*3" specifies an array of 3- 4-byte little-endian integers. Multiple column specifications are concatenated to form a template of a record. For example, "i4*3r8a5" specifies a 3-column record, with a 3-element array of 4-byte little-endian integers, followed by a little-endian double-float, followed by a character string of five characters. Gaps in the template can be specified using "x", e.g., "i4*3x10r8x5a5" specifies the same record structure as the previous example, except that the fields are non-contiguous. Every field in the record is placed in its own column within a davinci structure with generic names assigned in the form "col_n" or "col_n[m]". Multiplicity in strings gets split into multiple fields, since davinci text arrays cannot be 3-dimensional. Notes: Unpack resizes types if necessary because davinci only supports unsigned bytes and signed shorts and ints. It checks and possibly converts columns with the type on the left to the types on the right: signed bytes -> shorts (required conversion) unsigned shorts -> ints unsigned ints -> doubles (floats have inadequate precision)
Examples This example performs a lot of type upgrades and splits the string multiplicity as mentioned above. This file was used for testing which is why it uses every type in this sequence: signed byte, 2-byte unsigned lsb int, 3-byte signed lsb int, 4-byte unsigned lsb int, lsb float, lsb double skip 4 bytes, 2-byte unsigned msb int, 3-byte unsigned msb int, 4-byte unsigned msb int, msb float, msb double and of course the 3 6 character strings dv> a = unpack("Iu2i3u4r4r8x4U2U3U4R4R8a6*3", "strmulttest.dat", 0) struct, 14 elements col_0: 1x10x1 array of short, bsq format [20 bytes] col_1: 1x10x1 array of int, bsq format [40 bytes] col_2: 1x10x1 array of int, bsq format [40 bytes] col_3: 1x10x1 array of double, bsq format [80 bytes] col_4: 1x10x1 array of float, bsq format [40 bytes] col_5: 1x10x1 array of double, bsq format [80 bytes] col_6: 1x10x1 array of int, bsq format [40 bytes] col_7: 1x10x1 array of int, bsq format [40 bytes] col_8: 1x10x1 array of double, bsq format [80 bytes] col_9: 1x10x1 array of float, bsq format [40 bytes] col_10: 1x10x1 array of double, bsq format [80 bytes] col_11[0]: Text Buffer with 10 lines of text 1: hello0 2: hello0 3: hello0 4: hello0 5: hello0 6: hello0 7: hello0 8: hello0 9: hello0 10: hello0 col_11[1]: Text Buffer with 10 lines of text 1: hello1 2: hello1 3: hello1 4: hello1 5: hello1 6: hello1 7: hello1 8: hello1 9: hello1 10: hello1 col_11[2]: Text Buffer with 10 lines of text 1: hello2 2: hello2 3: hello2 4: hello2 5: hello2 6: hello2 7: hello2 8: hello2 9: hello2 10: hello2 |
DavinciWiki Mini-Nav Bar Contents
Contact Developers
All other topics
Recent Core Changes Modified On: |