Newsgroups: comp.lang.apl
Path: watmath!watserv1!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!uunet.ca!geac!itcyyz!yrloc!hui
From: hui@yrloc.ipsa.reuter.COM (Roger Hui)
Subject: Re: Need an APLI386 function for importing/exporting ASCII matrices..
Message-ID: <1992May24.052124.4563@yrloc.ipsa.reuter.COM>
Organization: Iverson Software Inc.
References: <2A1D325A.7052@noiro.acs.uci.edu>
Date: Sun, 24 May 92 05:21:24 GMT


Jeff Stern writes:
> ... I'm using Iverson APLI386 and I need a function to automatically read
> in an ASCII matrix from a DOS file and automatically put it into a
> variable.  (And another to export back.) ...
 
See Chapter 11 of "APL Systems Manual" re the DOSX interface.  From the 
information contained therein one might write the following utilities:
 
    del z is aread omega;dosx
[1]  comment Read file omega.
[2]   lev 710 quad svo 'dosx'
[3]   lev dosxset 'openro ',omega
[4]   z is dosxset 'read 0,32767,2'
    del
 
    del z is alpha awrite omega;dosx
[1]  comment Write text alpha to brand new file omega.
[2]   lev 710 quad svo 'dosx'
[3]   lev dosxset 'create ',omega
[4]   z is dosxset 'write 0,1;',alpha
    del
 
    del z is dosxset omega;t
[1]  comment Set 'dosx', check return code, and return result.
[2]   dosx is omega
[3]   z is 6 drop t is dosx
[4]   ('dosx error ',thorn 2 take t) quad signal
                       500+quad fi(2 times ~'00' match 2 take t) take t
    del
 
Examples:
      'Cogito, ergo sum.' awrite 'd:\root\stem\foo.x'
      t is aread 'd:\root\stem\foo.x'
 
These functions read and write strings, so a numeric matrix must be converted 
into a string first (using thorn), and conversely after being read a string 
must be converted into a numeric matrix (using execute or quad fi).
 
Spelling:  There is no space between "quad" and the word immediately to
its right.  "lev" is Ctrl x on the default keyboard; "match" is Alt 5;
"thorn" is Ctrl n.
 
-------------
A solution in J of a similar problem was previously posted to this news 
group in article <1992Feb1.054042.5696@yrloc.ipsa.reuter.COM>:
 
The verb 3!:1 (internal representation) and its inverse 3!:2, when composed
with 1!:1 (read) and 1!:2 (write), do as you ask for numeric and literal
arrays.  Thus:
 
   ir    =. 3!:1
   ri    =. 3!:2
   read  =. 1!:1
   write =. 1!:2
   atf   =. ir@[ write ]
   aff   =. ri@read
 
   a =. o.i.3 4       NB. A table of pi's
   a atf <'asdf'      NB. write array a to file 'asdf'
   aff <'asdf'        NB. read an array from file 'asdf'
   3+aff <'asdf'      NB. as above, but add 3 to it

------------------------------------
Roger Hui, Iverson Software Inc., 33 Major Street, Toronto, Ontario  M5S 2K9
Phone: (416) 925 6096;  Fax: (416) 488 7559
