File: save-translate.at

package info (click to toggle)
pspp 2.0.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 66,676 kB
  • sloc: ansic: 267,210; xml: 18,446; sh: 5,534; python: 2,881; makefile: 125; perl: 64
file content (366 lines) | stat: -rw-r--r-- 13,139 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
dnl PSPP - a program for statistical analysis.
dnl Copyright (C) 2017 Free Software Foundation, Inc.
dnl
dnl This program is free software: you can redistribute it and/or modify
dnl it under the terms of the GNU General Public License as published by
dnl the Free Software Foundation, either version 3 of the License, or
dnl (at your option) any later version.
dnl
dnl This program is distributed in the hope that it will be useful,
dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
dnl GNU General Public License for more details.
dnl
dnl You should have received a copy of the GNU General Public License
dnl along with this program.  If not, see <http://www.gnu.org/licenses/>.
dnl
AT_BANNER([SAVE TRANSLATE /TYPE=CSV])

m4_define([PREPARE_SAVE_TRANSLATE_CSV], [dnl
AT_KEYWORDS([SAVE TRANSLATE])
AT_DATA([data.txt], [dnl
0 '1 9:30:05' 1/2/2003 "25/8/1995 15:30:00" "'a,b,c'",0
, '-0 5:17' 10/31/2010 "9/4/2008 9:29:00" " xxx ",1
1.625,'0 12:00',,,xyzzy,1
])
AT_DATA([save-translate.pspp], [dnl
SET DECIMAL=DOT.
DATA LIST LIST NOTABLE FILE="data.txt"
    /number(F8.3) time(DTIME10) date(ADATE10) datetime(DATETIME20) string(A8)
     filter(F1.0).
MISSING VALUES number(0) time('0 12:00') string('xyzzy').
FILTER BY filter.
SAVE TRANSLATE OUTFILE="data.csv" /TYPE=m4_if([$2], [], [CSV], [$2])
    $1.
])
AT_CHECK([pspp -O format=csv save-translate.pspp], [0])
])

AT_SETUP([CSV output -- defaults])
PREPARE_SAVE_TRANSLATE_CSV
AT_CHECK([cat data.csv], [0], [dnl
0,33:30:05,01/02/2003,08/25/1995 15:30:00,"'a,b,c'",0
 ,-05:17:00,10/31/2010,04/09/2008 09:29:00, xxx,1
1.625,12:00:00, , ,xyzzy,1
])
AT_CLEANUP

AT_SETUP([CSV output -- recode missing, delete unselected])
PREPARE_SAVE_TRANSLATE_CSV([/MISSING=RECODE /UNSELECTED=DELETE])
AT_CHECK([cat data.csv], [0], [dnl
 ,-05:17:00,10/31/2010,04/09/2008 09:29:00, xxx,1
1.625, , , ,,1
])
AT_CLEANUP

AT_SETUP([CSV output -- var names, formats])
PREPARE_SAVE_TRANSLATE_CSV(
  [/FIELDNAMES /TEXTOPTIONS FORMAT=VARIABLE /UNSELECTED=RETAIN])
AT_CHECK([cat data.csv], [0], [dnl
number,time,date,datetime,string,filter
.000,1 09:30:05,01/02/2003,25-AUG-1995 15:30:00,"'a,b,c'",0
 ,-0 05:17,10/31/2010,09-APR-2008 09:29:00, xxx,1
1.625,0 12:00:00, , ,xyzzy,1
])
AT_CLEANUP

AT_SETUP([CSV output -- comma as decimal point])
PREPARE_SAVE_TRANSLATE_CSV([/FIELDNAMES /TEXTOPTIONS DECIMAL=COMMA])
AT_CHECK([cat data.csv], [0], [dnl
number;time;date;datetime;string;filter
0;33:30:05;01/02/2003;08/25/1995 15:30:00;'a,b,c';0
 ;-05:17:00;10/31/2010;04/09/2008 09:29:00; xxx;1
1,625;12:00:00; ; ;xyzzy;1
])
AT_CLEANUP

AT_SETUP([CSV output -- custom delimiter, qualifier])
PREPARE_SAVE_TRANSLATE_CSV(
  [/FIELDNAMES /TEXTOPTIONS DELIMITER=':' QUALIFIER="'"])
AT_CHECK([cat data.csv], [0], [dnl
number:time:date:datetime:string:filter
0:'33:30:05':01/02/2003:'08/25/1995 15:30:00':'''a,b,c''':0
 :'-05:17:00':10/31/2010:'04/09/2008 09:29:00': xxx:1
1.625:'12:00:00': : :xyzzy:1
])
AT_CLEANUP

AT_SETUP([CSV output -- KEEP, RENAME quoted])
PREPARE_SAVE_TRANSLATE_CSV(
  [/FIELDNAMES /KEEP=time string /RENAME string='long name with spaces' /UNSELECTED=DELETE])
AT_CHECK([cat data.csv], [0], [dnl
time,long name with spaces
-05:17:00, xxx
12:00:00,xyzzy
])
AT_CLEANUP


AT_SETUP([CSV output -- KEEP, RENAME multi quoted])
PREPARE_SAVE_TRANSLATE_CSV(
  [/FIELDNAMES
  /RENAME =
	number = "this one"
	time = "that one"
	date = "which one?"
	datetime = "another variable replacement"
	string="long name with spaces"
  /UNSELECTED=DELETE])
AT_CHECK([cat data.csv], [0], [dnl
this one,that one,which one?,another variable replacement,long name with spaces,filter
 ,-05:17:00,10/31/2010,04/09/2008 09:29:00, xxx,1
1.625,12:00:00, , ,xyzzy,1
])
AT_CLEANUP


AT_SETUP([CSV output -- KEEP, RENAME bad name ])
AT_KEYWORDS([SAVE TRANSLATE])
AT_DATA([bad.sps], [
data list notable list /Var1 Var2 Var3 Var4 Var5 *.
begin data
1 2 3 4 5
end data.

SAVE TRANSLATE
/OUTFILE="foo.csv"
  /TYPE=CSV
  /MAP
  /REPLACE
  /FIELDNAMES
  /Unselected=DELETE
   /RENAME =
        Var4 = Var5
        (Var1 Var2 = one Var3 )
        (Var3 = "The second")
  /CELLS=VALUES
.
])

AT_CHECK([pspp -O format=csv bad.sps], [1], [dnl
"bad.sps:15.9-17.29: error: SAVE TRANSLATE: Requested renaming duplicates variable name Var5.
   15 |         Var4 = Var5
      |         ^~~~~~~~~~~
   16 |         (Var1 Var2 = one Var3 )
      | -------------------------------
   17 |         (Var3 = ""The second"")
      | -----------------------------"
])


AT_CLEANUP



AT_BANNER([SAVE TRANSLATE /TYPE=TAB])

AT_SETUP([TAB output])
PREPARE_SAVE_TRANSLATE_CSV([/FIELDNAMES], [TAB])
AT_CHECK([cat data.csv], [0], [dnl
number	time	date	datetime	string	filter
0	33:30:05	01/02/2003	08/25/1995 15:30:00	'a,b,c'	0
 	-05:17:00	10/31/2010	04/09/2008 09:29:00	 xxx	1
1.625	12:00:00	 	 	xyzzy	1
])
AT_CLEANUP

AT_SETUP([SAVE TRANSLATE syntax errors])
: > xyzzy.csv
AT_DATA([save-translate.sps], [dnl
DATA LIST LIST NOTABLE /v1 to v10.
SAVE TRANSLATE **.
SAVE TRANSLATE/OUTFILE=**.
SAVE TRANSLATE/OUTFILE='xyzzy.txt'/OUTFILE='xyzzy.txt'.
SAVE TRANSLATE/TYPE=CSV/TYPE=**.
SAVE TRANSLATE/TYPE=**.
SAVE TRANSLATE/MISSING=**.
SAVE TRANSLATE/CELLS=**.
SAVE TRANSLATE/TEXTOPTIONS DELIMITER=**.
SAVE TRANSLATE/TEXTOPTIONS DELIMITER='ab'.
SAVE TRANSLATE/TEXTOPTIONS QUALIFIER=**.
SAVE TRANSLATE/TEXTOPTIONS QUALIFIER='ab'.
SAVE TRANSLATE/TEXTOPTIONS DECIMAL=**.
SAVE TRANSLATE/UNSELECTED=**.
SAVE TRANSLATE/ **.
SAVE TRANSLATE/OUTFILE='xyzzy.csv'.
SAVE TRANSLATE/TYPE=CSV.
SAVE TRANSLATE/OUTFILE='xyzzy.csv'/TYPE=CSV.
SAVE TRANSLATE/RENAME **.
SAVE TRANSLATE/RENAME v1**.
SAVE TRANSLATE/RENAME(v1**).
SAVE TRANSLATE/RENAME v1=.
SAVE TRANSLATE/RENAME v1=**.
SAVE TRANSLATE/RENAME v1 to v5=v6.
SAVE TRANSLATE/RENAME (v1=v2 v3).
SAVE TRANSLATE/RENAME (v1 v2=v3).
SAVE TRANSLATE/RENAME (v1=v3**.
SAVE TRANSLATE/RENAME v1=v5.
SAVE TRANSLATE/RENAME v1 v5=v5 v1.
SAVE TRANSLATE/RENAME(v1 v5=v5 v1).
SAVE TRANSLATE/RENAME(v1 to v10=v01 to v10).
SAVE TRANSLATE/RENAME=v1=v1.
SAVE TRANSLATE/DROP=ALL.
SAVE TRANSLATE/DROP=**.
SAVE TRANSLATE/KEEP=**.
SAVE TRANSLATE/OUTFILE='xyzzy.txt' **.
])
AT_CHECK([pspp -O format=csv save-translate.sps], [1], [dnl
"save-translate.sps:2.16-2.17: error: SAVE TRANSLATE: Syntax error expecting MAP, DROP, KEEP, or RENAME.
    2 | SAVE TRANSLATE **.
      |                ^~"

"save-translate.sps:3.24-3.25: error: SAVE TRANSLATE: Syntax error expecting a file name or handle name.
    3 | SAVE TRANSLATE/OUTFILE=**.
      |                        ^~"

"save-translate.sps:4.36-4.42: error: SAVE TRANSLATE: Subcommand OUTFILE may only be specified once.
    4 | SAVE TRANSLATE/OUTFILE='xyzzy.txt'/OUTFILE='xyzzy.txt'.
      |                                    ^~~~~~~"

"save-translate.sps:5.25-5.28: error: SAVE TRANSLATE: Subcommand TYPE may only be specified once.
    5 | SAVE TRANSLATE/TYPE=CSV/TYPE=**.
      |                         ^~~~"

"save-translate.sps:6.21-6.22: error: SAVE TRANSLATE: Syntax error expecting CSV or TAB.
    6 | SAVE TRANSLATE/TYPE=**.
      |                     ^~"

"save-translate.sps:7.24-7.25: error: SAVE TRANSLATE: Syntax error expecting IGNORE or RECODE.
    7 | SAVE TRANSLATE/MISSING=**.
      |                        ^~"

"save-translate.sps:8.22-8.23: error: SAVE TRANSLATE: Syntax error expecting VALUES or LABELS.
    8 | SAVE TRANSLATE/CELLS=**.
      |                      ^~"

"save-translate.sps:9.38-9.39: error: SAVE TRANSLATE: Syntax error expecting string.
    9 | SAVE TRANSLATE/TEXTOPTIONS DELIMITER=**.
      |                                      ^~"

"save-translate.sps:10.38-10.41: error: SAVE TRANSLATE: The DELIMITER string must contain exactly one character.
   10 | SAVE TRANSLATE/TEXTOPTIONS DELIMITER='ab'.
      |                                      ^~~~"

"save-translate.sps:11.38-11.39: error: SAVE TRANSLATE: Syntax error expecting string.
   11 | SAVE TRANSLATE/TEXTOPTIONS QUALIFIER=**.
      |                                      ^~"

"save-translate.sps:12.38-12.41: error: SAVE TRANSLATE: The QUALIFIER string must contain exactly one character.
   12 | SAVE TRANSLATE/TEXTOPTIONS QUALIFIER='ab'.
      |                                      ^~~~"

"save-translate.sps:13.36-13.37: error: SAVE TRANSLATE: Syntax error expecting DOT or COMMA.
   13 | SAVE TRANSLATE/TEXTOPTIONS DECIMAL=**.
      |                                    ^~"

"save-translate.sps:14.27-14.28: error: SAVE TRANSLATE: Syntax error expecting RETAIN or DELETE.
   14 | SAVE TRANSLATE/UNSELECTED=**.
      |                           ^~"

"save-translate.sps:15.17-15.18: error: SAVE TRANSLATE: Syntax error expecting MAP, DROP, KEEP, or RENAME.
   15 | SAVE TRANSLATE/ **.
      |                 ^~"

"save-translate.sps:16.1-16.35: error: SAVE TRANSLATE: Required subcommand TYPE was not specified.
   16 | SAVE TRANSLATE/OUTFILE='xyzzy.csv'.
      | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"

"save-translate.sps:17.1-17.24: error: SAVE TRANSLATE: Required subcommand OUTFILE was not specified.
   17 | SAVE TRANSLATE/TYPE=CSV.
      | ^~~~~~~~~~~~~~~~~~~~~~~~"

"save-translate.sps:18.16-18.34: error: SAVE TRANSLATE: Output file `xyzzy.csv' exists but REPLACE was not specified.
   18 | SAVE TRANSLATE/OUTFILE='xyzzy.csv'/TYPE=CSV.
      |                ^~~~~~~~~~~~~~~~~~~"

"save-translate.sps:19.23-19.24: error: SAVE TRANSLATE: Syntax error expecting variable name.
   19 | SAVE TRANSLATE/RENAME **.
      |                       ^~"

"save-translate.sps:20.25-20.26: error: SAVE TRANSLATE: Syntax error expecting `='.
   20 | SAVE TRANSLATE/RENAME v1**.
      |                         ^~"

"save-translate.sps:21.25-21.26: error: SAVE TRANSLATE: Syntax error expecting `='.
   21 | SAVE TRANSLATE/RENAME(v1**).
      |                         ^~"

"save-translate.sps:22.26: error: SAVE TRANSLATE: Syntax error expecting variable name.
   22 | SAVE TRANSLATE/RENAME v1=.
      |                          ^"

"save-translate.sps:23.26-23.27: error: SAVE TRANSLATE: Syntax error expecting variable name.
   23 | SAVE TRANSLATE/RENAME v1=**.
      |                          ^~"

save-translate.sps:24: error: SAVE TRANSLATE: Old and new variable counts do not match.

"save-translate.sps:24.23-24.30: note: SAVE TRANSLATE: There are 5 old variables.
   24 | SAVE TRANSLATE/RENAME v1 to v5=v6.
      |                       ^~~~~~~~"

"save-translate.sps:24.32-24.33: note: SAVE TRANSLATE: There is 1 new variable name.
   24 | SAVE TRANSLATE/RENAME v1 to v5=v6.
      |                                ^~"

save-translate.sps:25: error: SAVE TRANSLATE: Old and new variable counts do not match.

"save-translate.sps:25.24-25.25: note: SAVE TRANSLATE: There is 1 old variable.
   25 | SAVE TRANSLATE/RENAME (v1=v2 v3).
      |                        ^~"

"save-translate.sps:25.27-25.31: note: SAVE TRANSLATE: There are 2 new variable names.
   25 | SAVE TRANSLATE/RENAME (v1=v2 v3).
      |                           ^~~~~"

save-translate.sps:26: error: SAVE TRANSLATE: Old and new variable counts do not match.

"save-translate.sps:26.24-26.28: note: SAVE TRANSLATE: There are 2 old variables.
   26 | SAVE TRANSLATE/RENAME (v1 v2=v3).
      |                        ^~~~~"

"save-translate.sps:26.30-26.31: note: SAVE TRANSLATE: There is 1 new variable name.
   26 | SAVE TRANSLATE/RENAME (v1 v2=v3).
      |                              ^~"

"save-translate.sps:27.29-27.30: error: SAVE TRANSLATE: Syntax error expecting `)'.
   27 | SAVE TRANSLATE/RENAME (v1=v3**.
      |                             ^~"

"save-translate.sps:28.23-28.27: error: SAVE TRANSLATE: Requested renaming duplicates variable name v5.
   28 | SAVE TRANSLATE/RENAME v1=v5.
      |                       ^~~~~"

"save-translate.sps:29.26-29.27: error: SAVE TRANSLATE: Syntax error expecting `='.
   29 | SAVE TRANSLATE/RENAME v1 v5=v5 v1.
      |                          ^~"

"save-translate.sps:30.1-30.35: error: SAVE TRANSLATE: Required subcommand TYPE was not specified.
   30 | SAVE TRANSLATE/RENAME(v1 v5=v5 v1).
      | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"

"save-translate.sps:31.1-31.44: error: SAVE TRANSLATE: Required subcommand TYPE was not specified.
   31 | SAVE TRANSLATE/RENAME(v1 to v10=v01 to v10).
      | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"

"save-translate.sps:32.1-32.28: error: SAVE TRANSLATE: Required subcommand TYPE was not specified.
   32 | SAVE TRANSLATE/RENAME=v1=v1.
      | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~"

"save-translate.sps:33.16-33.23: error: SAVE TRANSLATE: Cannot DROP all variables from dictionary.
   33 | SAVE TRANSLATE/DROP=ALL.
      |                ^~~~~~~~"

"save-translate.sps:34.21-34.22: error: SAVE TRANSLATE: Syntax error expecting variable name.
   34 | SAVE TRANSLATE/DROP=**.
      |                     ^~"

"save-translate.sps:35.21-35.22: error: SAVE TRANSLATE: Syntax error expecting variable name.
   35 | SAVE TRANSLATE/KEEP=**.
      |                     ^~"

"save-translate.sps:36.36-36.37: error: SAVE TRANSLATE: Syntax error expecting `/'.
   36 | SAVE TRANSLATE/OUTFILE='xyzzy.txt' **.
      |                                    ^~"
])
AT_CLEANUP