Universal read_data function



The use of the string processing functions from
van Nek's stringproc.lisp allows construction of
a "Universal" read_data function which not only
doesn't care about line endings, but doesn't care
whether data separators are spaces or commas,
and can handle fractions, decimals, floating point
and strings as data items.

demo follows:
------------------------
Maxima 5.24.0 http://maxima.sourceforge.net
using Lisp GNU Common Lisp (GCL) GCL 2.6.8 (a.k.a. GCL)
Distributed under the GNU Public License. See the file COPYING.
Dedicated to the memory of William Schelter.
The function bug_report() provides bug reporting information.
                                  2011-05-25


(%i1) display2d:false$
(%i2) load(read_data);
(%o2) "c:/work2/read_data.mac"

(%i3) fundef (read_data);

(%o3) read_data(%filename):=block([%s,%r,%l],
                if not file_search(%filename)
                    then (disp(" file not found "),return(false)),
                %s:openr(%filename),%r:[],
                while (%l:readline(%s)) # false do
                      %r:cons(map(parse_string,split(ssubst(" 
",",",%l))),%r),
                close(%s),reverse(%r))

(%i4) printfile ("mydata.dat")$

1 2/3 3.4 2.3e9 "Abc"

"Def" , -3/4 , 6 , -4.8e-7 , 5.5

7/13 "Ghi" 8 3.3e4 -7.3

4,-3/9,"Jkl",44.6,9.9e-6

(%i5) read_data ("mydata.dat");

(%o5)   [ [1,2/3,3.4,2.3E+9,"Abc"], 
["Def",-3/4,6,-4.7999999999999996E-7,5.5],
       [7/13,"Ghi",8,33000.0,-7.3], 
[4,-1/3,"Jkl",44.6,9.9000000000000001E-6] ]

----------------------------------------------------------
Ted Woollett