import x,y data table ? 
Author Message
 import x,y data table ?

Hi

i wanna drawing from x,y data table file (data,dat or data.txt )

struchure of sample file

x         y

1     0.32584
2     0.43284
3     0.52584
4     0.63584
.
.

tool : acad2000

may i question

1. how about of open file method?
2. how about read x,y data from data file?
3. how about line drawing from point1 to point2

if you had sample program, send me

thank you



Mon, 12 Jul 2004 20:03:54 GMT  
 import x,y data table ?

Quote:

> Hi

> i wanna drawing from x,y data table file (data,dat or data.txt )

> struchure of sample file

> x         y

> 1     0.32584
> 2     0.43284
> 3     0.52584
> 4     0.63584
> .

Enclosed a version which I wrote in December 2001 (after completing a 2
hour Lisp tutorial). The code is maybe not very Lispish; but I am not a
programmer for my living (nor will I try to become one; I would invest
my time in more useful things) and do also not plan to invest the next
100 years in order to learn the complete set of CL.

The comments are in German (if you encounter problems, please drop me a
note).

If your file is of the following scheme:

header1
header2
12.23,334.455,2.334
2.34,23.34,23.33
...

then you can read in the array with the following function:

(defun read-in-array-del (datei &key (nHeader 0) (break-point "999")
(del ","))

datei... name of you file (and maybe directory)

nHeader...number of header lines which become skipped

break-point...in very large files it is often convenient to set a break
point

del...seperator of your values, e.g. ","  or ";" or ":" or....

or you file is of the following form:

header1
header2
12.23 334.455 2.334
2.34 23.34 23.33
...

then this function will help you:

(defun read-in-array-space (datei &key (nHeader 0) (break-point "999"))

S. Gonzi

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;; Zaehle die Zeilen in einem File
;;
;; Funktion: (count-lines dateiFile :nHeader 0 :break-point "999")
;; Parameter: dateiFile...File mit den Daten
;;            :nHeader...Anzahl der Kopfzeilen
;;            :break-point...Soll an einer bestimmten Stelle abgebrochen
werden?
;;
;; Ausgabe: Anzahl der Zeilen
;;
;; (C) Siegfried Gonzi 2002
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defun count-lines (datei &key (nHeader 0) (break-point "999"))
               (setq n 0)
               (setq next-line t)
               (with-open-file (infile datei)
                 (read-header-lines infile nHeader)
                 (loop while(not (eq next-line nil)) do
                       (setf next-line (read-line infile nil))
                       (if (equal next-line break-point)
                           (setf  next-line nil))
                       (setf n (+ n 1))))
n)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Ueberlese N Kopfzeilen in einem File
;;
;; Funktion: (read-header-lines dateiFile (nHeader 0))
;; Parameter: dateiFile...File
;;            nHeader (optional)...Anzahl der Kopfzeilen
;;
;; Ausgabe: Filepointer am Ende der Kopfzeile
;;
;; (C) Siegfried Gonzi 2001
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun read-header-lines (infile &optional (nHeader 0))
               (loop :for i :from 0 :below nHeader :do
                     (read-line infile nil)))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;; Lese eine Datei,welche folgendes Format besitzt:
;;
;;   Kopfzeile 1
;;   Kopfzeile 2
;;   Kopfzeile n
;;   12.23
;;   1.23
;;   ...
;;
;;   Funktion: (read-in-vector dateiFile :nHeader 0 :break-point "999" )

;;   Parameter:   dateiFile...Datei mit den Werten; Allegro CL
Konvention:
;;                         z.B.: C:/Wissenschaft/R/D/....
;;                :nHeader...Anzahl der Kopfzeilen, die berlesen werden

;;                :break-point...An welcher Stelle soll - ausser dem EOF
-
;;                               abgebrochen werden
;;
;;   Externe Funktionen:   count-lines, read-header-lines, make-vector
;;
;;   Ausgabe: Vektor, welcher die Werte in Spalten und Zeilen enthaelt
;;
;; (C) Siegfried Gonzi 2002
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defun read-in-vector (datei &key (nHeader 0) (break-point "999"))
               (setq lines (count-lines datei :nHeader nHeader
:break-point break-point))
               (setq dims (- lines 1))
               (setq vec (make-vector dims))
               (setq val 0)
               (with-open-file (infile datei)
                 (read-header-lines infile nHeader)
                 (loop :for i :from 0 :below dims :do
                       (setf (aref vec i) (read infile))))
vec)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Zaehle die Kolumnen in einem Datenstring:
;;
;;    12.23  12.23   23.34  2.34
;;
;; Funktion: (get-cols string)
;; Parameter: string...Datenstring in Kolumnform
;;
;; Ausgabe: Anzahl der Kolumnen (z.B.  3 im obigen Fall)
;;
;; (C) Siegfried Gonzi 2001
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun get-cols (string)
                (setq cols 0)
                (setq s-el t)
                (with-input-from-string (s string)
                  (loop while(not (equal s-el nil)) do
                        (setf s-el (read s nil))
                        (setf cols (1+ cols))))
(1- cols ))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Zaehle einen gewuenschten Character in einem String und liefere
;; deren Position
;;
;;   z.B.:  1.23,2.233,23.34,45.56
;;
;;     liefert eine Liste mit: (4 10 16)
;;
;; Funktion: (get-del-list numberString del)
;; Parameter: numberString...String welcher ausgewertet werden soll
;;            del...Begrenzer (z.B. ",")
;;
;; Ausgabe: Liste mit den Positionen
;;
;; (C) Siegfried Gonzi 2002
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun get-del-list (numberString del)
               (setq n (length numberString))
               (setq el 0)
               (setq el-list nil)
               (loop :for i :from 0 :below n :do
                     (setf el (aref numberString i))
                     (if (string= el del)
                         (setf el-list (append el-list (list i)))))
el-list)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;; Lese eine Datei,welche folgendes Format besitzt:
;;
;;   Kopfzeile 1
;;   Kopfzeile 2
;;   Kopfzeile n
;;   12.23,23.34,1.234,34.456,2.345,56.67,...
;;   1.23,233.44,3.45,2.34,45.5677,6.778,...
;;   ...
;;
;;   Funktion: (read-in-array-del dateiFile :nHeader 0 :break-point
"999" :del ",")
;;   Parameter:   dateiFile...Datei mit den Werten; Allegro CL
Konvention:
;;                         z.B.: C:/Wissenschaft/R/D/....
;;                :nHeader...Anzahl der Kopfzeilen, die berlesen werden

;;                :break-point...An welcher Stelle soll - ausser dem EOF
-
;;                               abgebrochen werden
;;                :del...Begrenzer (im obigen Beispiel ',')
;;   Externe Funktionen:   count-lines, read-header-lines, get-del-list,

;;
;;   Ausgabe: Array, welches die Werte in Spalten und Zeilen enthaelt
;;
;; (C) Siegfried Gonzi 2002
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defun read-in-array-del (datei &key (nHeader 0) (break-point "999")
(del ","))
               (setq rows (- (count-lines datei :nHeader nHeader
:break-point break-point) 1))
               (setq cols nil)
               (setq val nil)
               (setq next-line nil)
               (setq indx-list ())
                (with-open-file (infile datei)
                 (read-header-lines infile nHeader)
                 (loop :for i :from 0 :below rows :do
                       (setf next-line (read-line infile nil))
                       (setf indx-list (get-del-list next-line del))
                       (setf indx-list (append indx-list (list  (length
next-line))))
                       (if (< i 1)
                           (progn
                             (setf cols  (length indx-list))
                             (setf array (append (make-array (list rows
cols))))))
                       (setq indx-start 0)
                       (setq indx-end -1)
                       (loop :for j :from 0 :below cols :do
                             (setf indx-start (+ indx-end 1))
                             (setf indx-end (- (nth j indx-list) 0))
                             (with-input-from-string (s next-line :index
k :start indx-start :end indx-end)
                               (setf val (read s)))
                             (setf (aref array i j) val))))
array)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;; Lese eine Datei,welche folgendes Format besitzt:
;;
;;   Kopfzeile 1
;;   Kopfzeile 2
;;   Kopfzeile n
;;   12.23  23.34  1.234  34.456  2.345  56.67  ...
;;   1.23  233.44  3.45  2.34  45.5677  6.778  ...
;;   ...
;;
;;   Funktion: (read-in-array-space dateiFile :nHeader 0 :break-point
"999" )
;;   Parameter:   dateiFile...Datei mit den Werten; Allegro CL
Konvention:
;;                         z.B.: C:/Wissenschaft/R/D/....
;;                :nHeader...Anzahl der Kopfzeilen, die berlesen werden

;;                :break-point...An welcher Stelle soll - ausser dem EOF
-
;;                               abgebrochen werden
;;   Es wird vorausgesetzt, dass die Werte mit Tabulatoren getrennt sind

;;   Externe Funktionen:   count-lines, get-del-list, get-cols
;;
;;   Ausgabe: Array, welches die Werte in Spalten und Zeilen enthaelt
;;
;; (C) Siegfried Gonzi 2002
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defun read-in-array-space (datei &key (nHeader 0) (break-point "999"))
               (setq rows (- (count-lines datei :nHeader nHeader
:break-point break-point) 1))
               (setq cols nil)
               (setq val nil)
                (with-open-file (infile datei)
                  (read-header-lines infile nHeader)
                  (setf cols (get-cols (read-line infile nil))))
                (with-open-file (infile datei)
                 (read-header-lines infile nHeader)
                 (setq array (make-array (list rows cols)))
                   (loop :for i :from 0 :below rows  :do
                       (loop :for j :from 0
...

read more »



Tue, 13 Jul 2004 16:58:57 GMT  
 import x,y data table ?

Quote:

> but I am not a programmer for my living (nor will I try to become
> one; I would invest my time in more useful things)

I.e. you think that professional programmers (including most of the
people you communicate with in this newsgroup) are dumb-asses which
couldn't find anything useful to do in their live? Good to know...

Edi.



Wed, 14 Jul 2004 03:40:52 GMT  
 import x,y data table ?

I realize the caveats in your message, but there is one very important
change you should make in your code.  The various SETQ forms at the top
of your functions are treated as dynamically scoped, special variables
by Lisp.  This can be lead to various errors, since any of them with the
same name (such as N) will share storage among the individual routines.

You will need to introduce local variables with LET or LET* statements.
These can easily take the place of the assignments.  For example

Quote:
> (defun count-lines (datei &key (nHeader 0) (break-point "999"))
>                (setq n 0)
>                (setq next-line t)
>                (with-open-file (infile datei)
>                  (read-header-lines infile nHeader)
>                  (loop while(not (eq next-line nil)) do
>                        (setf next-line (read-line infile nil))
>                        (if (equal next-line break-point)
>                            (setf  next-line nil))
>                        (setf n (+ n 1))))
> n)

should look more like:

(defun count-lines (datei &key (nHeader 0) (break-point "999"))
  (let ((n 0)
        (next-line t))
     (with-open-file (infile datei)
        (read-header-lines infile nHeader)
        (loop while(not (eq next-line nil)) do
              (setf next-line (read-line infile nil))
              (if (equal next-line break-point)
                  (setf  next-line nil))
                  (setf n (+ n 1))))
      n))

Although you didn't ask for this, a more compact,
loop-oriented approach might look something like the following:

(defun count-lines (datei &key (nHeader 0) (break-point "999"))
 (with-open-file (infile datei)
   (read-header-lines infile nHeader)
   (loop for next-line = (read-line infile nil break-point)
         until (equal next-line break-point)
         count t)))

or else

(defun count-lines (datei &key (nHeader 0) (break-point "999"))
 (with-open-file (infile datei)
   (read-header-lines infile nHeader)
   (loop for next-line = (read-line infile nil break-point)
         as n upfrom 0
         until (equal next-line break-point)
         finally (return n))))

or cleverly

(defun count-lines (datei &key (nHeader 0) (break-point "999"))
 (with-open-file (infile datei)
   (read-header-lines infile nHeader)
   (loop until (equal (read-line infile nil break-point) break-point)
         count t)))

--



Wed, 14 Jul 2004 04:50:53 GMT  
 import x,y data table ?

Quote:

> I realize the caveats in your message, but there is one very important
> change you should make in your code.  The various SETQ forms at the top
> of your functions are treated as dynamically scoped, special variables
> by Lisp.  This can be lead to various errors, since any of them with the
> same name (such as N) will share storage among the individual routines.

As I said: I wrote the program after working through a tutorial. I had
written a same version in Clean before. Honestly speaking: I used "setq"
only for "syntactic sugar". I thought it will help me documenting my code:
"Look, here setq denotes the first occurence of that specific variable".

But thank you for your tips.

S. Gonzi



Wed, 14 Jul 2004 19:09:16 GMT  
 import x,y data table ?
Well, this looks like homework, so i won't do the whole thing.

Reading a file into a collection is very very easy, though:

(with-open-file (handle name)
  (loop for line = (read-line hadle nil nil) while line collect line))

That's it.  You can just replace that last use of 'line with something
that gets the x and y out of the string.  Bingo. Done.

dave



Thu, 15 Jul 2004 00:26:27 GMT  
 import x,y data table ?

Quote:


>> Hi

>> i wanna drawing from x,y data table file (data,dat or data.txt )

>> struchure of sample file

>> x         y

>> 1     0.32584
>> 2     0.43284
>> 3     0.52584
>> 4     0.63584
>> .

> Enclosed a version which I wrote in December 2001 (after completing a 2
> hour Lisp tutorial). The code is maybe not very Lispish; but I am not a
> programmer for my living (nor will I try to become one; I would invest
> my time in more useful things) and do also not plan to invest the next
> 100 years in order to learn the complete set of CL.

> The comments are in German (if you encounter problems, please drop me a
> note).

Mr. Gonzi-

How much of your code applies to xlisp-stat?
I'm asking this because I was trying to read a data set
with some 50 subjects and twenty-odd variables, in a comma separated
file, with the (read-data-columns file columns) but wasn't succesful.

TIA,
Henry



Thu, 15 Jul 2004 14:00:58 GMT  
 import x,y data table ?

Quote:



>>> Hi

>>> i wanna drawing from x,y data table file (data,dat or data.txt )

>>> struchure of sample file

>>> x         y

>>> 1     0.32584
>>> 2     0.43284
>>> 3     0.52584
>>> 4     0.63584
>>> .

>> Enclosed a version which I wrote in December 2001 (after completing a 2
>> hour Lisp tutorial). The code is maybe not very Lispish; but I am not a
>> programmer for my living (nor will I try to become one; I would invest
>> my time in more useful things) and do also not plan to invest the next
>> 100 years in order to learn the complete set of CL.

>> The comments are in German (if you encounter problems, please drop me a
>> note).

> Mr. Gonzi-

> How much of your code applies to xlisp-stat?
> I'm asking this because I was trying to read a data set
> with some 50 subjects and twenty-odd variables, in a comma separated
> file, with the (read-data-columns file columns) but wasn't succesful.

> TIA,
> Henry


Sorry for this suto-reply, but I forgot to add that I had already
stream-edited the file in order to substitute the commas for spaces, as
the Tierney doc would have it done.

Regs
Henry



Thu, 15 Jul 2004 14:15:05 GMT  
 import x,y data table ?

Quote:

> Mr. Gonzi-

> How much of your code applies to xlisp-stat?
> I'm asking this because I was trying to read a data set
> with some 50 subjects and twenty-odd variables, in a comma separated
> file, with the (read-data-columns file columns) but wasn't succesful.

I am aware of XLispStat and have got installed it; but I didn't get deeper
into XLispStat; I only saw that in XLispStat one can also read-in values from
a file (but what I saw only with the blank (" ")-seperator).

I have written a same version in Clean (if you like it, you can get it). I
once posted the same question on the comp.lang.ada mailinglist; a guy posted
a solution then; maybe this was not a good idea, because I saw that Ada is
not really my case.

I do not assume that a trained person in Lisp (as it is with the developer of
XLispStat) would make a "setq"-mistake.

If you want to do statistics you should dowload the R-language. There reading
in files is easy. Or you get fortran 90/95; there reading columnar data is a
matter of a few lines.

S. Gonzi



Thu, 15 Jul 2004 19:19:28 GMT  
 import x,y data table ?

Quote:


> > I realize the caveats in your message, but there is one very important
> > change you should make in your code.  The various SETQ forms at the top
> > of your functions are treated as dynamically scoped, special variables
> > by Lisp.  This can be lead to various errors, since any of them with the
> > same name (such as N) will share storage among the individual routines.

> As I said: I wrote the program after working through a tutorial. I had
> written a same version in Clean before. Honestly speaking: I used "setq"
> only for "syntactic sugar". I thought it will help me documenting my code:
> "Look, here setq denotes the first occurence of that specific variable".

Right, but that's really what LET and LET* are supposed to do.  They
really do introduce a new variable binding.

That was the key point of my post, but I sort of got carried away toward
the end.  I hope it didn't obscure the importance of using local
variables in your functions.

Quote:
> But thank you for your tips.

You're welcome.

Quote:

> S. Gonzi

--



Sat, 17 Jul 2004 03:03:49 GMT  
 
 [ 12 post ] 

 Relevant Pages 

1. Import Data With File Import

2. Converting data from TPS table to MS SQL 7 table getting wrong values

3. Importing Text Tables into Real DB

4. Importing ODBC Table - Missing Keys

5. Import Tables to dictionary

6. Importing MS SQL table into Clarion Dict.

7. importing MSQL table into CW5

8. importing paradox file/table definitions into a cw dictionary

9. Importing an Access table

10. Importing ACCESS 97 table definitions

11. MySQL Table import issue

12. Pervasive.SQL(SQL) Import Table Problems

 

 
Powered by phpBB® Forum Software