If you are not sure about the exact format of the file (e.g. the file's values may have been written as separate writing operations by a FORTRAN program), we recommend to use the standard read command with as integer.
set mylist to (read alias "path:to:the:data:file" for 256 as integer)
This reads the file as 4-bytes integers: paddings display as zeros. Here we read 256/4 = 64 numbers, which return as an AppleScript list into mylist. Use read [...] from to start reading at a given offset in the file. (To open the dictionary for read, select the term and press ⇧⌘F.)
Still with the AppleScript's standard read command, you can read different block sizes, and you can read various numerical formats, including the single-precision and double-precision binary formats.
-
read 1 byte into a character
- read f
-
read 2 bytes as an integer
- read f as small integer
-
read 4 bytes as an integer
- read f as integer
-
read 8 bytes as an integer
- read f as double integer
-
read 4 bytes as a real (binary single-precision)
- read f as small real
-
read 8 bytes as a real (binary double-precision)
- read f as real
|