The approach in J is to read/write text files, then convert the strings (character vectors) and reshape as appropriate. For example:
x=: 1!:1 <'\junk\x' NB. read a text file $x NB. string of length 200 200 3!:0 x NB. type is 2 (literal) 2 y=: _2 (3!:4) x NB. convert to 4-byte integers $y NB. 50 of them 50 3!:0 y NB. type is 4 (integer) 4 +/y NB. can do arithmetic on it _922886641 z=: 25 2$y NB. reshape into 2-column matrix +/ z NB. sums of the 2 columns _2325095959 1402209318 z1=: _2 ]\ y NB. another way to make 2 column matrix $z1 25 2 +/z1 _2325095959 1402209318 ----- Original Message ----- From: emptist <[email protected]> Date: Thursday, August 20, 2009 21:19 Subject: [Jchat] [newbie]how to read binary formatted file To: [email protected] > > Hi, > > I just started to learn J and some kdb/q in the meantime (with a > Smalltalkbackground but not a programmer). 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). > > I've not finished reading yet but my quick going through the J > books for > about 13 hours doesn't give me a quick solution in J. I think it > might be > wise to ask for help here. (By the way, I was reading into 3 > o'clock this > morning, here in China, Remembering Ken Iverson, by Roger Hui ...) > > Thanks in advance for any advice. > > Best Regards, > > Emp ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
