1 AT_BANNER([BEGIN DATA])
3 # BEGIN DATA can run as a command in itself, or it can appear as part
4 # of the first procedure. First, test it after a procedure.
5 AT_SETUP([BEGIN DATA as part of a procedure])
6 AT_DATA([begin-data.sps], [dnl
7 TITLE 'Test BEGIN DATA ... END DATA'.
19 AT_CHECK([pspp -O format=csv begin-data.sps], [0], [dnl
20 Title: Test BEGIN DATA ... END DATA
22 Table: Reading 1 record from INLINE.
23 Variable,Record,Columns,Format
37 # Also test BEGIN DATA as an independent command.
38 AT_SETUP([BEGIN DATA as an independent command])
39 AT_DATA([begin-data.sps], [dnl
50 AT_CHECK([pspp -O format=csv begin-data.sps], [0], [dnl
51 Table: Reading 1 record from INLINE.
52 Variable,Record,Columns,Format
66 m4_define([DATA_READER_BINARY],
67 [AT_SETUP([read and write files with $1])
69 AT_DATA([input.txt], [dnl
80 AT_DATA([make-binary.pl], [dnl
84 # ASCII to EBCDIC translation table
85 our ($ascii2ebcdic) = ""
86 . "\x00\x01\x02\x03\x37\x2d\x2e\x2f"
87 . "\x16\x05\x25\x0b\x0c\x0d\x0e\x0f"
88 . "\x10\x11\x12\x13\x3c\x3d\x32\x26"
89 . "\x18\x19\x3f\x27\x1c\x1d\x1e\x1f"
90 . "\x40\x5a\x7f\x7b\x5b\x6c\x50\x7d"
91 . "\x4d\x5d\x5c\x4e\x6b\x60\x4b\x61"
92 . "\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7"
93 . "\xf8\xf9\x7a\x5e\x4c\x7e\x6e\x6f"
94 . "\x7c\xc1\xc2\xc3\xc4\xc5\xc6\xc7"
95 . "\xc8\xc9\xd1\xd2\xd3\xd4\xd5\xd6"
96 . "\xd7\xd8\xd9\xe2\xe3\xe4\xe5\xe6"
97 . "\xe7\xe8\xe9\xad\xe0\xbd\x9a\x6d"
98 . "\x79\x81\x82\x83\x84\x85\x86\x87"
99 . "\x88\x89\x91\x92\x93\x94\x95\x96"
100 . "\x97\x98\x99\xa2\xa3\xa4\xa5\xa6"
101 . "\xa7\xa8\xa9\xc0\x4f\xd0\x5f\x07"
102 . "\x20\x21\x22\x23\x24\x15\x06\x17"
103 . "\x28\x29\x2a\x2b\x2c\x09\x0a\x1b"
104 . "\x30\x31\x1a\x33\x34\x35\x36\x08"
105 . "\x38\x39\x3a\x3b\x04\x14\x3e\xe1"
106 . "\x41\x42\x43\x44\x45\x46\x47\x48"
107 . "\x49\x51\x52\x53\x54\x55\x56\x57"
108 . "\x58\x59\x62\x63\x64\x65\x66\x67"
109 . "\x68\x69\x70\x71\x72\x73\x74\x75"
110 . "\x76\x77\x78\x80\x8a\x8b\x8c\x8d"
111 . "\x8e\x8f\x90\x6a\x9b\x9c\x9d\x9e"
112 . "\x9f\xa0\xaa\xab\xac\x4a\xae\xaf"
113 . "\xb0\xb1\xb2\xb3\xb4\xb5\xb6\xb7"
114 . "\xb8\xb9\xba\xbb\xbc\xa1\xbe\xbf"
115 . "\xca\xcb\xcc\xcd\xce\xcf\xda\xdb"
116 . "\xdc\xdd\xde\xdf\xea\xeb\xec\xed"
117 . "\xee\xef\xfa\xfb\xfc\xfd\xfe\xff";
118 length ($ascii2ebcdic) == 256 || die;
120 open (INPUT, '<', 'input.txt') or die "input.txt: open: $!\n";
121 my (@data) = <INPUT> or die;
122 close (INPUT) or die;
123 chomp $_ foreach @data;
132 foreach (split (//)) {
133 $s .= substr ($ascii2ebcdic, ord, 1);
140 return $a < $b ? $a : $b
145 my ($n) = min (int (rand (5)) + 1, scalar (@records));
146 my (@r) = splice (@records, 0, $n);
148 $len += length foreach @r;
149 print pack ("n xx", $len + 4);
154 AT_CHECK([$PERL make-binary.pl < input.txt > input.bin])
155 AT_DATA([data-reader.sps], [dnl
156 FILE HANDLE input/NAME='input.bin'/$1.
157 DATA LIST FIXED FILE=input NOTABLE
158 /1 start 1-10 (ADATE)
163 * Output the data to a new file in the same format.
164 FILE HANDLE OUTPUT/NAME='output.bin'/$1.
165 COMPUTE count=count + 1.
166 PRINT OUTFILE=output/start end count.
169 AT_CHECK([pspp -O format=csv data-reader.sps], [0], [dnl
172 07/22/2007,10/06/2007,321
173 07/14/1789,08/26/1789,4
174 01/01/1972,12/31/1999,682
176 AT_CHECK([test -s output.bin])
177 AT_DATA([data-reader-2.sps], [dnl
178 * Re-read the new data and list it, to verify that it was written correctly.
179 FILE HANDLE OUTPUT/NAME='output.bin'/$1.
180 DATA LIST FIXED FILE=output NOTABLE/
186 AT_CHECK([pspp -O format=csv data-reader-2.sps], [0], [dnl
189 07/22/2007,10/06/2007,322
190 07/14/1789,08/26/1789,5
191 01/01/1972,12/31/1999,683
195 DATA_READER_BINARY([MODE=BINARY],
197 my ($reclen) = pack ("V", length);
198 print $reclen, $_, $reclen;
201 DATA_READER_BINARY([MODE=360 /RECFORM=FIXED /LRECL=32],
204 my ($out) = substr ($_, 0, $lrecl);
205 $out .= ' ' x ($lrecl - length ($out));
206 length ($out) == 32 or die;
209 [AT_CHECK([supports_encodings EBCDIC-US])])
211 DATA_READER_BINARY([MODE=360 /RECFORM=VARIABLE],
213 push (@records, pack ("n xx", length ($_) + 4) . a2e ($_));
216 [AT_CHECK([supports_encodings EBCDIC-US])])
218 DATA_READER_BINARY([MODE=360 /RECFORM=SPANNED],
219 [[for my $line (@data) {
223 my ($n) = min (int (rand (5)), length);
224 push (@r, substr ($_, 0, $n, ''));
226 foreach my $i (0...$#r) {
227 my $scc = ($#r == 0 ? 0
232 pack ("nCx", length ($r[$i]) + 4, $scc) . a2e ($r[$i]));
236 [AT_CHECK([supports_encodings EBCDIC-US])])