Hi, Sherlock
Thanks for your one liner showing the exciting magic of APL/J family. And
the first line of magic codes reads somewhat natural and charming at once
after having read steps in previous post by Roger. However, it turns back to
be difficult as soon as I am reading and trying on :)
So thank each of you for giving me such a happy day in my very beginning
playing with J. I hope I woould soon learn the beauty the language.
Best Regards,
Emp
Sherlock, Ric wrote:
>
>> From: emptist
>> In q I've learned to read a kind of binary
>> formatted historical price data file, which contains 8 4 byte int data
>> for each record, using:
>>
>> list: ("iiiiiiii";4 4 4 4 4 4 4 4) 1: `:path/filename
>>
>> and this will give me a list of data of the entire file. (For those not
>> familiar with q, 1: reads binary file, and i stands for int type in q,
>> while 4 means a field is 4 byte in size).
>
> Putting together the nicely broken down steps that Roger gave, a J
> translation of the above line of q is:
>
> _8]\ _2(3!:4) 1!:1 <'path/filename'
>
> If the fields in each record weren't all of the same type, then it would
> be more involved.
>
> Below is just an example of roundtripping a table of integers to binary
> file and back again.
>
> ]tst=: 5 8 ?...@$ 50 NB. Create 5 by 8 table of integers
> 46 5 29 2 4 39 10 7
> 10 44 46 28 13 18 1 42
> 28 10 40 12 31 16 10 14
> 14 21 13 3 26 26 25 27
> 18 48 42 41 49 47 49 9
>
> tstchar=: 2 (3!:4) ,tst NB. convert to sets of 4 bytes
> tstchar 1!:2 <jpath '~temp/my.bin' NB. write to file
>
> _8]\ _2 (3!:4) 1!:1 <jpath '~temp/my.bin' NB. read back integer table
> 46 5 29 2 4 39 10 7
> 10 44 46 28 13 18 1 42
> 28 10 40 12 31 16 10 14
> 14 21 13 3 26 26 25 27
> 18 48 42 41 49 47 49 9
>
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
>
>
--
View this message in context:
http://www.nabble.com/-newbie-how-to-read-binary-formatted-file-tp25073648s24193p25074849.html
Sent from the J Chat mailing list archive at Nabble.com.
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm