From: dully
Subject: import x,y data table ?
Date: 
Message-ID: <a2os0v$jnp$1@news1.kornet.net>
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

From: Siegfried Gonzi
Subject: Re: import x,y data table ?
Date: 
Message-ID: <3C511E51.507E50EB@kfunigraz.ac.at>
dully wrote:

> 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 :below cols :do
                       (setf (aref array i j) (read infile nil)))))
array)

;;C://Wissenschaft//KrigingAeronet//Avignon//avignon01_season1.5.tx
From: Thomas A. Russ
Subject: Re: import x,y data table ?
Date: 
Message-ID: <ymipu3yxihe.fsf@sevak.isi.edu>
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

> (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)))


-- 
Thomas A. Russ,  USC/Information Sciences Institute          ···@isi.edu    
From: Siegfried Gonzi
Subject: Re: import x,y data table ?
Date: 
Message-ID: <3C528E5B.9065223F@kfunigraz.ac.at>
"Thomas A. Russ" wrote:

> 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
From: Thomas A. Russ
Subject: Re: import x,y data table ?
Date: 
Message-ID: <ymiofjexppm.fsf@sevak.isi.edu>
Siegfried Gonzi <···············@kfunigraz.ac.at> writes:

> 
> "Thomas A. Russ" wrote:
> 
> > 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.

> But thank you for your tips.

You're welcome.

> 
> 
> S. Gonzi
> 

-- 
Thomas A. Russ,  USC/Information Sciences Institute          ···@isi.edu    
From: Dr. Edmund Weitz
Subject: Re: import x,y data table ?
Date: 
Message-ID: <m3ofjigqwr.fsf@bird.agharta.de>
Siegfried Gonzi <···············@kfunigraz.ac.at> writes:

> 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.
From: synthespian
Subject: Re: import x,y data table ? [xlisp-stat]
Date: 
Message-ID: <3C53979A.4070809@uol.com.br>
Siegfried Gonzi wrote:

> dully wrote:
> 
> 
>> 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
···········@uol.com.br
From: synthespian
Subject: Re: import x,y data table ? [xlisp-stat]
Date: 
Message-ID: <3C539AE9.9050703@uol.com.br>
synthespian wrote:

> Siegfried Gonzi wrote:
> 
>> dully wrote:
>> 
>> 
>>> 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
> ···········@uol.com.br

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
From: Siegfried Gonzi
Subject: Re: import x,y data table ? [xlisp-stat]
Date: 
Message-ID: <3C53E240.9297196@kfunigraz.ac.at>
synthespian wrote:

> 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
From: David Hanley
Subject: Re: import x,y data table ?
Date: 
Message-ID: <281e82b2.0201260826.26fe0c66@posting.google.com>
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