Re: proposal to include functions to read data from files
Subject: Re: proposal to include functions to read data from files
From: Robert Dodier
Date: Sat, 17 Jan 2004 16:20:09 -0800 (PST)
Hello,
Many thanks to Barton Willis for posting code for reading
and writing data in Maxima. I have coded another solution
which I would like you-all to consider. I was working towards
some different design goals, & so that's why I was inspired
to write some code.
This new code attempts to be liberal about what can be read
into Maxima, and doesn't attempt to manage open files. I hope
this code will prove to be flexible and useful.
In addition to a Lisp file for the read/write functions, I wrote
two test scripts and two data files for the scripts to work on.
The test scripts succeed when executed on my copy of Maxima
(Maxima cvs version of about 2003/11/28, clisp 2.31, linux 2.4.2).
You can find the files in question at: http://riso.sf.net/maxima
(just a handy place to park them).
I've appended the comment header from the Lisp code to this message.
I am willing to maintain the read/write code (whatever it turns
out to be) if you-all are willing to have me maintain it.
Doubtless there are many features which can be added.
regards,
Robert Dodier
comment header from read_write_data.lisp:
----------------------- >8 -----------------------
;; This file contains some functions to read and write data files.
;; Data files can contain integers, rationals, floats, complex,
;; and symbols. Symbols are translated to uppercase when read in,
;; thus ``foo'' in a data file is ``FOO'' in Maxima. The entire
;; file is read to construct one object, i.e., no partial reads.
;;
;; Read functions:
;; M: read_matrix(file_name, "sep_ch")$
;; read_hashed_array(file_name, A, "sep_ch")$
;; L: read_nested_list(file_name, "sep_ch")$
;; L: read_list(file_name, "sep_ch")$
;;
;; Write function:
;; write_data(X, file_name, "sep_ch")$
;;
;; Notes: (1) "sep_ch" is the character which separates items.
;; It is an optional argument for all read & write functions.
;; The default value is the space character.
;; For output, the separation character works as expected.
;; For input, the separation character is BROKEN:
;; I tried to use read-delimited-list and ran into problems.
;;
;; (2) read_matrix infers the size of the matrix from the input data.
;;
;; (3) read_hashed_array treats the first item on a line as a
;; hash key, and makes the remainder of the line into a list:
;; reading "567 12 17 32 55" is equivalent to A[567]: [12, 17, 32, 55]$
;; Lines need not have the same numbers of elements.
;;
;; (4) read_nested_list makes a list which has a sublist for each
;; line of input. Lines need not have the same numbers of elements.
;;
;; (5) read_list reads all input into a flat list.
;; read_list ignores end-of-line characters.
;;
;; (6) write_data figures out what kind of object is X and
;; hands it off to an appropriate function to write it out.
;;
;; (7) A flat list is written all on one line.
----------------------- 8< -----------------------
__________________________________
Do you Yahoo!?
Yahoo! Hotjobs: Enter the "Signing Bonus" Sweepstakes
http://hotjobs.sweepstakes.yahoo.com/signingbonus