1 dnl PSPP - a program for statistical analysis.
2 dnl Copyright (C) 2017 Free Software Foundation, Inc.
4 dnl This program is free software: you can redistribute it and/or modify
5 dnl it under the terms of the GNU General Public License as published by
6 dnl the Free Software Foundation, either version 3 of the License, or
7 dnl (at your option) any later version.
9 dnl This program is distributed in the hope that it will be useful,
10 dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
11 dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 dnl GNU General Public License for more details.
14 dnl You should have received a copy of the GNU General Public License
15 dnl along with this program. If not, see <http://www.gnu.org/licenses/>.
17 AT_BANNER([BEGIN DATA])
19 # BEGIN DATA can run as a command in itself, or it can appear as part
20 # of the first procedure. First, test it after a procedure.
21 AT_SETUP([BEGIN DATA as part of a procedure])
22 AT_DATA([begin-data.sps], [dnl
23 TITLE 'Test BEGIN DATA ... END DATA'.
35 AT_CHECK([pspp -O format=csv begin-data.sps], [0], [dnl
36 Table: Reading 1 record from INLINE.
37 Variable,Record,Columns,Format
51 # Also test BEGIN DATA as an independent command.
52 AT_SETUP([BEGIN DATA as an independent command])
53 AT_DATA([begin-data.sps], [dnl
64 AT_CHECK([pspp -O format=csv begin-data.sps], [0], [dnl
65 Table: Reading 1 record from INLINE.
66 Variable,Record,Columns,Format
80 m4_define([DATA_READER_BINARY],
81 [AT_SETUP([read and write files with $1])
83 AT_DATA([input.txt], [dnl
94 AT_DATA([make-binary.pl], [dnl
98 # ASCII to EBCDIC translation table
99 our ($ascii2ebcdic) = ""
100 . "\x00\x01\x02\x03\x37\x2d\x2e\x2f"
101 . "\x16\x05\x25\x0b\x0c\x0d\x0e\x0f"
102 . "\x10\x11\x12\x13\x3c\x3d\x32\x26"
103 . "\x18\x19\x3f\x27\x1c\x1d\x1e\x1f"
104 . "\x40\x5a\x7f\x7b\x5b\x6c\x50\x7d"
105 . "\x4d\x5d\x5c\x4e\x6b\x60\x4b\x61"
106 . "\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7"
107 . "\xf8\xf9\x7a\x5e\x4c\x7e\x6e\x6f"
108 . "\x7c\xc1\xc2\xc3\xc4\xc5\xc6\xc7"
109 . "\xc8\xc9\xd1\xd2\xd3\xd4\xd5\xd6"
110 . "\xd7\xd8\xd9\xe2\xe3\xe4\xe5\xe6"
111 . "\xe7\xe8\xe9\xad\xe0\xbd\x9a\x6d"
112 . "\x79\x81\x82\x83\x84\x85\x86\x87"
113 . "\x88\x89\x91\x92\x93\x94\x95\x96"
114 . "\x97\x98\x99\xa2\xa3\xa4\xa5\xa6"
115 . "\xa7\xa8\xa9\xc0\x4f\xd0\x5f\x07"
116 . "\x20\x21\x22\x23\x24\x15\x06\x17"
117 . "\x28\x29\x2a\x2b\x2c\x09\x0a\x1b"
118 . "\x30\x31\x1a\x33\x34\x35\x36\x08"
119 . "\x38\x39\x3a\x3b\x04\x14\x3e\xe1"
120 . "\x41\x42\x43\x44\x45\x46\x47\x48"
121 . "\x49\x51\x52\x53\x54\x55\x56\x57"
122 . "\x58\x59\x62\x63\x64\x65\x66\x67"
123 . "\x68\x69\x70\x71\x72\x73\x74\x75"
124 . "\x76\x77\x78\x80\x8a\x8b\x8c\x8d"
125 . "\x8e\x8f\x90\x6a\x9b\x9c\x9d\x9e"
126 . "\x9f\xa0\xaa\xab\xac\x4a\xae\xaf"
127 . "\xb0\xb1\xb2\xb3\xb4\xb5\xb6\xb7"
128 . "\xb8\xb9\xba\xbb\xbc\xa1\xbe\xbf"
129 . "\xca\xcb\xcc\xcd\xce\xcf\xda\xdb"
130 . "\xdc\xdd\xde\xdf\xea\xeb\xec\xed"
131 . "\xee\xef\xfa\xfb\xfc\xfd\xfe\xff";
132 length ($ascii2ebcdic) == 256 || die;
134 open (INPUT, '<', 'input.txt') or die "input.txt: open: $!\n";
135 my (@data) = <INPUT> or die;
136 close (INPUT) or die;
137 chomp $_ foreach @data;
146 foreach (split (//)) {
147 $s .= substr ($ascii2ebcdic, ord, 1);
154 return $a < $b ? $a : $b
159 my ($n) = min (int (rand (5)) + 1, scalar (@records));
160 my (@r) = splice (@records, 0, $n);
162 $len += length foreach @r;
163 print pack ("n xx", $len + 4);
168 AT_CHECK([$PERL make-binary.pl < input.txt > input.bin])
169 AT_DATA([data-reader.sps], [dnl
170 FILE HANDLE input/NAME='input.bin'/$1.
171 DATA LIST FIXED FILE=input NOTABLE
172 /1 start 1-10 (ADATE)
177 * Output the data to a new file in the same format.
178 FILE HANDLE OUTPUT/NAME='output.bin'/$1.
179 COMPUTE count=count + 1.
180 PRINT OUTFILE=output/start end count.
183 AT_CHECK([pspp -O format=csv data-reader.sps], [0], [dnl
186 07/22/2007,10/06/2007,321
187 07/14/1789,08/26/1789,4
188 01/01/1972,12/31/1999,682
190 AT_CHECK([test -s output.bin])
191 AT_DATA([data-reader-2.sps], [dnl
192 * Re-read the new data and list it, to verify that it was written correctly.
193 FILE HANDLE OUTPUT/NAME='output.bin'/$1.
194 DATA LIST FIXED FILE=output NOTABLE/
200 AT_CHECK([pspp -O format=csv data-reader-2.sps], [0], [dnl
203 07/22/2007,10/06/2007,322
204 07/14/1789,08/26/1789,5
205 01/01/1972,12/31/1999,683
209 DATA_READER_BINARY([MODE=BINARY],
211 my ($reclen) = pack ("V", length);
212 print $reclen, $_, $reclen;
215 DATA_READER_BINARY([MODE=360 /RECFORM=FIXED /LRECL=32],
218 my ($out) = substr ($_, 0, $lrecl);
219 $out .= ' ' x ($lrecl - length ($out));
220 length ($out) == 32 or die;
223 [AT_CHECK([i18n-test supports_encodings EBCDIC-US])])
225 DATA_READER_BINARY([MODE=360 /RECFORM=VARIABLE],
227 push (@records, pack ("n xx", length ($_) + 4) . a2e ($_));
230 [AT_CHECK([i18n-test supports_encodings EBCDIC-US])])
232 DATA_READER_BINARY([MODE=360 /RECFORM=SPANNED],
233 [[for my $line (@data) {
237 my ($n) = min (int (rand (5)), length);
238 push (@r, substr ($_, 0, $n, ''));
240 foreach my $i (0...$#r) {
241 my $scc = ($#r == 0 ? 0
246 pack ("nCx", length ($r[$i]) + 4, $scc) . a2e ($r[$i]));
250 [AT_CHECK([i18n-test supports_encodings EBCDIC-US])])