Skip to content

Commit 9e2b484

Browse files
authored
Merge pull request #1 from charlesneimog/master
Criar o omlib para funcionar com o OM-sharp
2 parents c9ee946 + 41a73c0 commit 9e2b484

File tree

7 files changed

+1235
-0
lines changed

7 files changed

+1235
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
.*
22
!/.gitignore
3+
*~
4+
*.html

OMio.omlib

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
(:om-lib
2+
3+
(:version 0.11)
4+
(:doc "Library to import/export different kind of data file types.")
5+
6+
(:author "José Henrique Padovani (2019)")
7+
8+
(:source-files
9+
"sources/package"
10+
"sources/xmls-sharp"
11+
"sources/omiocsv-sharp")
12+
13+
(:symbols
14+
(:packages
15+
(:package
16+
(:name "csv")
17+
(:functions csv-floats-in)))))
18+
19+

examples/csv/1. csv-floats-in.opat

Lines changed: 252 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,252 @@
1+
2+
(:patch
3+
(:name "1. csv-floats-in")
4+
(:doc "")
5+
(:info
6+
(:created "2021/06/16 10:02:10")
7+
(:modified "2021/06/16 10:02:49")
8+
(:by "om-sharp")
9+
(:version 1.03))
10+
(:window (:size (1458 927)) (:position (110 0)))
11+
(:grid nil)
12+
(:lock nil)
13+
(:boxes
14+
(:comment
15+
(:x 228)
16+
(:y 538)
17+
(:w 386)
18+
(:h 62)
19+
(:fgcolor (:color 0 0 0 1.0))
20+
(:bgcolor nil)
21+
(:border 0)
22+
(:roundness nil)
23+
(:text-font (:font (:face "Verdana") (:size 12) (:style :plain)))
24+
(:align nil)
25+
(:text
26+
"You can change the keyword :defaultformat to short-floats if you don't need long floats precision. (see documentation of the function)")
27+
(:id 0))
28+
(:box
29+
(:library "OMio")
30+
(:type :function)
31+
(:reference csv-floats-in)
32+
(:group-id nil)
33+
(:name "csv-floats-in")
34+
(:x 102)
35+
(:y 531)
36+
(:w 117)
37+
(:h 33)
38+
(:color nil)
39+
(:border nil)
40+
(:roundness nil)
41+
(:text-font nil)
42+
(:align nil)
43+
(:icon :left)
44+
(:lock nil)
45+
(:lambda nil)
46+
(:inputs
47+
(:input
48+
(:type :standard)
49+
(:name "FILENAME")
50+
(:value 5)
51+
(:reactive nil))
52+
(:input
53+
(:type :optional)
54+
(:name "rowsasstrings")
55+
(:value nil)
56+
(:reactive nil))
57+
(:input
58+
(:type :optional)
59+
(:name "colsasstrings")
60+
(:value nil)
61+
(:reactive nil))
62+
(:input
63+
(:type :optional)
64+
(:name "defaultformat")
65+
(:value long-float)
66+
(:reactive nil)))
67+
(:outputs (:output (:name "out") (:reactive nil)))
68+
(:id 1))
69+
(:box
70+
(:type :value)
71+
(:reference cons)
72+
(:group-id nil)
73+
(:name "aux 2")
74+
(:x 174)
75+
(:y 335)
76+
(:w 48)
77+
(:h 33)
78+
(:color
79+
(:color-or-nil
80+
(:color (:color 1.0S0 1.0S0 1.0S0 1.0))
81+
(:t-or-nil t)))
82+
(:border nil)
83+
(:roundness nil)
84+
(:text-font nil)
85+
(:align nil)
86+
(:lock nil)
87+
(:inputs)
88+
(:outputs (:output (:name "value") (:reactive nil)))
89+
(:value (:list 0 4))
90+
(:id 2))
91+
(:comment
92+
(:x 70)
93+
(:y 241)
94+
(:w 407)
95+
(:h 62)
96+
(:fgcolor (:color 0 0 0 1.0))
97+
(:bgcolor nil)
98+
(:border 0)
99+
(:roundness nil)
100+
(:text-font (:font (:face "Verdana") (:size 12) (:style :plain)))
101+
(:align nil)
102+
(:text
103+
"You can specify which rows should be read as strings instead of numbers (the header of the table, for example)")
104+
(:id 3))
105+
(:box
106+
(:type :value)
107+
(:reference cons)
108+
(:group-id nil)
109+
(:name "aux")
110+
(:x 26)
111+
(:y 244)
112+
(:w 37)
113+
(:h 33)
114+
(:color
115+
(:color-or-nil
116+
(:color (:color 1.0S0 1.0S0 1.0S0 1.0))
117+
(:t-or-nil t)))
118+
(:border nil)
119+
(:roundness nil)
120+
(:text-font nil)
121+
(:align nil)
122+
(:lock nil)
123+
(:inputs)
124+
(:outputs (:output (:name "value") (:reactive nil)))
125+
(:value (:list 0))
126+
(:id 4))
127+
(:box
128+
(:library "OMio")
129+
(:type :function)
130+
(:reference csv-floats-in)
131+
(:group-id nil)
132+
(:name "csv-floats-in")
133+
(:x 102)
134+
(:y 376)
135+
(:w 117)
136+
(:h 33)
137+
(:color nil)
138+
(:border nil)
139+
(:roundness nil)
140+
(:text-font nil)
141+
(:align nil)
142+
(:icon :left)
143+
(:lock nil)
144+
(:lambda nil)
145+
(:inputs
146+
(:input
147+
(:type :standard)
148+
(:name "FILENAME")
149+
(:value 5)
150+
(:reactive nil))
151+
(:input
152+
(:type :optional)
153+
(:name "rowsasstrings")
154+
(:value nil)
155+
(:reactive nil))
156+
(:input
157+
(:type :optional)
158+
(:name "colsasstrings")
159+
(:value nil)
160+
(:reactive nil)))
161+
(:outputs (:output (:name "out") (:reactive nil)))
162+
(:id 5))
163+
(:comment
164+
(:x 230)
165+
(:y 370)
166+
(:w 386)
167+
(:h 116)
168+
(:fgcolor (:color 0 0 0 1.0))
169+
(:bgcolor nil)
170+
(:border 0)
171+
(:roundness nil)
172+
(:text-font (:font (:face "Verdana") (:size 12) (:style :plain)))
173+
(:align nil)
174+
(:text
175+
"Likewise, you can specify which columns of the table should be read as strings instead of numbers. In this example, the entire first row will be read as a list of strings. From the second row onwards, the first and the fifth columns (nth 0 and 4) will also be read as strings.")
176+
(:id 6))
177+
(:comment
178+
(:x 178)
179+
(:y 103)
180+
(:w 375)
181+
(:h 44)
182+
(:fgcolor (:color 0 0 0 1.0))
183+
(:bgcolor nil)
184+
(:border 0)
185+
(:roundness nil)
186+
(:text-font (:font (:face "Verdana") (:size 12) (:style :plain)))
187+
(:align nil)
188+
(:text "2. Convert it to a list (csv table) of lists (csv rows)")
189+
(:id 7))
190+
(:comment
191+
(:x 188)
192+
(:y 28)
193+
(:w 375)
194+
(:h 26)
195+
(:fgcolor (:color 0 0 0 1.0))
196+
(:bgcolor nil)
197+
(:border 0)
198+
(:roundness nil)
199+
(:text-font (:font (:face "Verdana") (:size 12) (:style :plain)))
200+
(:align nil)
201+
(:text "1. Choose a valid .csv file ")
202+
(:id 8))
203+
(:box
204+
(:type :function)
205+
(:reference file-chooser)
206+
(:group-id nil)
207+
(:name "file-chooser")
208+
(:x 64)
209+
(:y 24)
210+
(:w 115)
211+
(:h 33)
212+
(:color nil)
213+
(:border nil)
214+
(:roundness nil)
215+
(:text-font nil)
216+
(:align nil)
217+
(:icon :left)
218+
(:lock nil)
219+
(:lambda nil)
220+
(:inputs)
221+
(:outputs (:output (:name "out") (:reactive nil)))
222+
(:id 9))
223+
(:box
224+
(:library "OMio")
225+
(:type :function)
226+
(:reference csv-floats-in)
227+
(:group-id nil)
228+
(:name "csv-floats-in")
229+
(:x 60)
230+
(:y 100)
231+
(:w 117)
232+
(:h 33)
233+
(:color nil)
234+
(:border nil)
235+
(:roundness nil)
236+
(:text-font nil)
237+
(:align nil)
238+
(:icon :left)
239+
(:lock nil)
240+
(:lambda nil)
241+
(:inputs
242+
(:input
243+
(:type :standard)
244+
(:name "FILENAME")
245+
(:value 5)
246+
(:reactive nil)))
247+
(:outputs (:output (:name "out") (:reactive nil)))
248+
(:id 10)))
249+
(:connections
250+
(:connection (:from (:box 2 :out 0)) (:to (:box 5 :in 2)))
251+
(:connection (:from (:box 4 :out 0)) (:to (:box 5 :in 1)))
252+
(:connection (:from (:box 9 :out 0)) (:to (:box 10 :in 0)))))

reference-pages/logo.png

52.4 KB
Loading

sources/omiocsv-sharp.lisp

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
; Warning: First, seting the package where the functions will be defined
2+
(in-package :om)
3+
4+
; Functions definition
5+
6+
; (om::defmethod! csv-floats-in ((filename pathname) &key (defaultformat 'long-float))
7+
; :initvals '(nil long-float)
8+
; :indoc '("<n>")
9+
; :icon 128
10+
; :doc
11+
; "reads csv file at \"filename\" and returns a list of lists of floats (that corresponds to therows of the csv file)\n\nKeyword :defaultformat can be either long-float/double-float (default) or float/short-float/single-float."
12+
; (with-open-file (stream filename)
13+
; (loop for line = (read-line stream nil)
14+
; for linecount from 0
15+
; while line
16+
; collect (loop for start = 0 then (1+ finish)
17+
; for finish = (position #\, line :start start)
18+
; for columncount from 0
19+
; collecting (parse-float (string-trim " " (subseq line start finish)) :default-format defaultformat)
20+
; until (null finish)))))
21+
22+
23+
(om::defmethod! csv-floats-in ((filename pathname) &optional (rowsasstrings nil) (colsasstrings nil) (defaultformat 'long-float))
24+
:initvals '(nil nil nil long-float)
25+
:indoc '("<n>")
26+
:icon '128
27+
:doc
28+
"reads csv file at \"filename\" and returns a list of lists of floats (that corresponds to therows of the csv file)\n\n
29+
Optional parameters rowsasstrings and colsasstrings can be nil or lists: they can be used to specify rows or columns of the original csv file that should not be read as float numbers.\n\n
30+
Keyword :defaultformat can be either long-float/double-float (default) or float/short-float/single-float."
31+
32+
(with-open-file (stream filename)
33+
(loop for line = (read-line stream nil)
34+
while line
35+
for linecount from 0
36+
collect
37+
(loop for start = 0 then (1+ finish)
38+
for columnnumber from 0
39+
for finish = (position #\, line :start start)
40+
collect
41+
(cond
42+
(colsasstrings ;;se colunas forem especificadas
43+
(if rowsasstrings ;; primeiro ve se é para printar toda a linha como string
44+
(if (position linecount rowsasstrings)(string-trim " " (subseq line start finish)) ;;linha como string
45+
(if (position columnnumber colsasstrings)(string-trim " " (subseq line start finish))(parse-float (string-trim " " (subseq line start finish)) :default-format defaultformat));; senão, ve se a coluna atual deve ser lida como string ou como numero
46+
)
47+
(if (position columnnumber colsasstrings)(string-trim " " (subseq line start finish))(parse-float (string-trim " " (subseq line start finish)) :default-format defaultformat))
48+
)
49+
)
50+
(rowsasstrings (if (position linecount rowsasstrings)(string-trim " " (subseq line start finish))(parse-float (string-trim " " (subseq line start finish)) :default-format defaultformat)))
51+
(t (parse-float (string-trim " " (subseq line start finish)) :default-format defaultformat)))
52+
until (null finish)))))

sources/package.lisp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
(defvar omio)
2+
(defpackage omio)

0 commit comments

Comments
 (0)