Implement missing values for long string variables.
[pspp-builds.git] / doc / dev / system-file-format.texi
1 @node System File Format
2 @appendix System File Format
3
4 A system file encapsulates a set of cases and dictionary information
5 that describes how they may be interpreted.  This chapter describes
6 the format of a system file.
7
8 System files use three data types: 8-bit characters, 32-bit integers,
9 and 64-bit floating points, called here @code{char}, @code{int32}, and
10 @code{flt64}, respectively.  Data is not necessarily aligned on a word
11 or double-word boundary: the long variable name record (@pxref{Long
12 Variable Names Record}) and very long string records (@pxref{Very Long
13 String Record}) have arbitrary byte length and can therefore cause all
14 data coming after them in the file to be misaligned.
15
16 Integer data in system files may be big-endian or little-endian.  A
17 reader may detect the endianness of a system file by examining
18 @code{layout_code} in the file header record
19 (@pxref{layout_code,,@code{layout_code}}).
20
21 Floating-point data in system files may nominally be in IEEE 754, IBM,
22 or VAX formats.  A reader may detect the floating-point format in use
23 by examining @code{bias} in the file header record
24 (@pxref{bias,,@code{bias}}).
25
26 PSPP detects big-endian and little-endian integer formats in system
27 files and translates as necessary.  PSPP also detects the
28 floating-point format in use, as well as the endianness of IEEE 754
29 floating-point numbers, and translates as needed.  However, only IEEE
30 754 numbers with the same endianness as integer data in the same file
31 has actually been observed in system files, and it is likely that
32 other formats are obsolete or were never used.
33
34 The PSPP system-missing value is represented by the largest possible
35 negative number in the floating point format (@code{-DBL_MAX}).  Two
36 other values are important for use as missing values: @code{HIGHEST},
37 represented by the largest possible positive number (@code{DBL_MAX}),
38 and @code{LOWEST}, represented by the second-largest negative number
39 (in IEEE 754 format, @code{0xffeffffffffffffe}).
40
41 System files are divided into records, each of which begins with a
42 4-byte record type, usually regarded as an @code{int32}.
43
44 The records must appear in the following order:
45
46 @itemize @bullet
47 @item
48 File header record.
49
50 @item
51 Variable records.
52
53 @item
54 All pairs of value labels records and value label variables records,
55 if present.
56
57 @item
58 Document record, if present.
59
60 @item
61 Any of the following records, if present, in any order:
62
63 @itemize @minus
64 @item
65 Machine integer info record.
66
67 @item
68 Machine floating-point info record.
69
70 @item
71 Variable display parameter record.
72
73 @item
74 Long variable names record.
75
76 @item
77 Miscellaneous informational records.
78 @end itemize
79
80 @item
81 Dictionary termination record.
82
83 @item
84 Data record.
85 @end itemize
86
87 Each type of record is described separately below.
88
89 @menu
90 * File Header Record::
91 * Variable Record::
92 * Value Labels Records::
93 * Document Record::
94 * Machine Integer Info Record::
95 * Machine Floating-Point Info Record::
96 * Variable Display Parameter Record::
97 * Long Variable Names Record::
98 * Very Long String Record::
99 * Character Encoding Record::
100 * Long String Value Labels Record::
101 * Data File and Variable Attributes Records::
102 * Miscellaneous Informational Records::
103 * Dictionary Termination Record::
104 * Data Record::
105 @end menu
106
107 @node File Header Record
108 @section File Header Record
109
110 The file header is always the first record in the file.  It has the
111 following format:
112
113 @example
114 char                rec_type[4];
115 char                prod_name[60];
116 int32               layout_code;
117 int32               nominal_case_size;
118 int32               compressed;
119 int32               weight_index;
120 int32               ncases;
121 flt64               bias;
122 char                creation_date[9];
123 char                creation_time[8];
124 char                file_label[64];
125 char                padding[3];
126 @end example
127
128 @table @code
129 @item char rec_type[4];
130 Record type code, set to @samp{$FL2}.
131
132 @item char prod_name[60];
133 Product identification string.  This always begins with the characters
134 @samp{@@(#) SPSS DATA FILE}.  PSPP uses the remaining characters to
135 give its version and the operating system name; for example, @samp{GNU
136 pspp 0.1.4 - sparc-sun-solaris2.5.2}.  The string is truncated if it
137 would be longer than 60 characters; otherwise it is padded on the right
138 with spaces.
139
140 @anchor{layout_code}
141 @item int32 layout_code;
142 Normally set to 2, although a few system files have been spotted in
143 the wild with a value of 3 here.  PSPP use this value to determine the
144 file's integer endianness (@pxref{System File Format}).
145
146 @item int32 nominal_case_size;
147 Number of data elements per case.  This is the number of variables,
148 except that long string variables add extra data elements (one for every
149 8 characters after the first 8).  However, string variables do not
150 contribute to this value beyond the first 255 bytes.   Further, system
151 files written by some systems set this value to -1.  In general, it is
152 unsafe for systems reading system files to rely upon this value.
153
154 @item int32 compressed;
155 Set to 1 if the data in the file is compressed, 0 otherwise.
156
157 @item int32 weight_index;
158 If one of the variables in the data set is used as a weighting
159 variable, set to the dictionary index of that variable, plus 1
160 (@pxref{Dictionary Index}).  Otherwise, set to 0.
161
162 @item int32 ncases;
163 Set to the number of cases in the file if it is known, or -1 otherwise.
164
165 In the general case it is not possible to determine the number of cases
166 that will be output to a system file at the time that the header is
167 written.  The way that this is dealt with is by writing the entire
168 system file, including the header, then seeking back to the beginning of
169 the file and writing just the @code{ncases} field.  For `files' in which
170 this is not valid, the seek operation fails.  In this case,
171 @code{ncases} remains -1.
172
173 @anchor{bias}
174 @item flt64 bias;
175 Compression bias, ordinarily set to 100.  Only integers between
176 @code{1 - bias} and @code{251 - bias} can be compressed.
177
178 By assuming that its value is 100, PSPP uses @code{bias} to determine
179 the file's floating-point format and endianness (@pxref{System File
180 Format}).  If the compression bias is not 100, PSPP cannot auto-detect
181 the floating-point format and assumes that it is IEEE 754 format with
182 the same endianness as the system file's integers, which is correct
183 for all known system files.
184
185 @item char creation_date[9];
186 Date of creation of the system file, in @samp{dd mmm yy}
187 format, with the month as standard English abbreviations, using an
188 initial capital letter and following with lowercase.  If the date is not
189 available then this field is arbitrarily set to @samp{01 Jan 70}.
190
191 @item char creation_time[8];
192 Time of creation of the system file, in @samp{hh:mm:ss}
193 format and using 24-hour time.  If the time is not available then this
194 field is arbitrarily set to @samp{00:00:00}.
195
196 @item char file_label[64];
197 File label declared by the user, if any (@pxref{FILE LABEL,,,pspp,
198 PSPP Users Guide}).  Padded on the right with spaces.
199
200 @item char padding[3];
201 Ignored padding bytes to make the structure a multiple of 32 bits in
202 length.  Set to zeros.
203 @end table
204
205 @node Variable Record
206 @section Variable Record
207
208 There must be one variable record for each numeric variable and each
209 string variable with width 8 bytes or less.  String variables wider
210 than 8 bytes have one variable record for each 8 bytes, rounding up.
211 The first variable record for a long string specifies the variable's
212 correct dictionary information.  Subsequent variable records for a
213 long string are filled with dummy information: a type of -1, no
214 variable label or missing values, print and write formats that are
215 ignored, and an empty string as name.  A few system files have been
216 encountered that include a variable label on dummy variable records,
217 so readers should take care to parse dummy variable records in the
218 same way as other variable records.
219
220 @anchor{Dictionary Index}
221 The @dfn{dictionary index} of a variable is its offset in the set of
222 variable records, including dummy variable records for long string
223 variables.  The first variable record has a dictionary index of 0, the
224 second has a dictionary index of 1, and so on.
225
226 The system file format does not directly support string variables
227 wider than 255 bytes.  Such very long string variables are represented
228 by a number of narrower string variables.  @xref{Very Long String
229 Record}, for details.
230
231 @example
232 int32               rec_type;
233 int32               type;
234 int32               has_var_label;
235 int32               n_missing_values;
236 int32               print;
237 int32               write;
238 char                name[8];
239
240 /* @r{Present only if @code{has_var_label} is 1.} */
241 int32               label_len;
242 char                label[];
243
244 /* @r{Present only if @code{n_missing_values} is nonzero}. */
245 flt64               missing_values[];
246 @end example
247
248 @table @code
249 @item int32 rec_type;
250 Record type code.  Always set to 2.
251
252 @item int32 type;
253 Variable type code.  Set to 0 for a numeric variable.  For a short
254 string variable or the first part of a long string variable, this is set
255 to the width of the string.  For the second and subsequent parts of a
256 long string variable, set to -1, and the remaining fields in the
257 structure are ignored.
258
259 @item int32 has_var_label;
260 If this variable has a variable label, set to 1; otherwise, set to 0.
261
262 @item int32 n_missing_values;
263 If the variable has no missing values, set to 0.  If the variable has
264 one, two, or three discrete missing values, set to 1, 2, or 3,
265 respectively.  If the variable has a range for missing variables, set to
266 -2; if the variable has a range for missing variables plus a single
267 discrete value, set to -3.
268
269 @item int32 print;
270 Print format for this variable.  See below.
271
272 @item int32 write;
273 Write format for this variable.  See below.
274
275 @item char name[8];
276 Variable name.  The variable name must begin with a capital letter or
277 the at-sign (@samp{@@}).  Subsequent characters may also be digits, octothorpes
278 (@samp{#}), dollar signs (@samp{$}), underscores (@samp{_}), or full
279 stops (@samp{.}).  The variable name is padded on the right with spaces.
280
281 @item int32 label_len;
282 This field is present only if @code{has_var_label} is set to 1.  It is
283 set to the length, in characters, of the variable label, which must be a
284 number between 0 and 120.
285
286 @item char label[];
287 This field is present only if @code{has_var_label} is set to 1.  It has
288 length @code{label_len}, rounded up to the nearest multiple of 32 bits.
289 The first @code{label_len} characters are the variable's variable label.
290
291 @item flt64 missing_values[];
292 This field is present only if @code{n_missing_values} is nonzero.  It
293 has the same number of 8-byte elements as the absolute value of
294 @code{n_missing_values}.  Each element is interpreted as a number for
295 numeric variables (with HIGHEST and LOWEST indicated as described in
296 the chapter introduction).  For string variables of width less than 8
297 bytes, elements are right-padded with spaces; for string variables
298 wider than 8 bytes, only the first 8 bytes of each missing value are
299 specified, with the remainder implicitly all spaces.
300
301 For discrete missing values, each element represents one missing
302 value.  When a range is present, the first element denotes the minimum
303 value in the range, and the second element denotes the maximum value
304 in the range.  When a range plus a value are present, the third
305 element denotes the additional discrete missing value.
306 @end table
307
308 The @code{print} and @code{write} members of sysfile_variable are output
309 formats coded into @code{int32} types.  The least-significant byte
310 of the @code{int32} represents the number of decimal places, and the
311 next two bytes in order of increasing significance represent field width
312 and format type, respectively.  The most-significant byte is not
313 used and should be set to zero.
314
315 Format types are defined as follows:
316
317 @quotation
318 @multitable {Value} {@code{DATETIME}}
319 @headitem Value
320 @tab Meaning
321 @item 0
322 @tab Not used.
323 @item 1
324 @tab @code{A}
325 @item 2
326 @tab @code{AHEX}
327 @item 3
328 @tab @code{COMMA}
329 @item 4
330 @tab @code{DOLLAR}
331 @item 5
332 @tab @code{F}
333 @item 6
334 @tab @code{IB}
335 @item 7
336 @tab @code{PIBHEX}
337 @item 8
338 @tab @code{P}
339 @item 9
340 @tab @code{PIB}
341 @item 10
342 @tab @code{PK}
343 @item 11
344 @tab @code{RB}
345 @item 12
346 @tab @code{RBHEX}
347 @item 13
348 @tab Not used.
349 @item 14
350 @tab Not used.
351 @item 15
352 @tab @code{Z}
353 @item 16
354 @tab @code{N}
355 @item 17
356 @tab @code{E}
357 @item 18
358 @tab Not used.
359 @item 19
360 @tab Not used.
361 @item 20
362 @tab @code{DATE}
363 @item 21
364 @tab @code{TIME}
365 @item 22
366 @tab @code{DATETIME}
367 @item 23
368 @tab @code{ADATE}
369 @item 24
370 @tab @code{JDATE}
371 @item 25
372 @tab @code{DTIME}
373 @item 26
374 @tab @code{WKDAY}
375 @item 27
376 @tab @code{MONTH}
377 @item 28
378 @tab @code{MOYR}
379 @item 29
380 @tab @code{QYR}
381 @item 30
382 @tab @code{WKYR}
383 @item 31
384 @tab @code{PCT}
385 @item 32
386 @tab @code{DOT}
387 @item 33
388 @tab @code{CCA}
389 @item 34
390 @tab @code{CCB}
391 @item 35
392 @tab @code{CCC}
393 @item 36
394 @tab @code{CCD}
395 @item 37
396 @tab @code{CCE}
397 @item 38
398 @tab @code{EDATE}
399 @item 39
400 @tab @code{SDATE}
401 @end multitable
402 @end quotation
403
404 @node Value Labels Records
405 @section Value Labels Records
406
407 The value label records documented in this section are used for
408 numeric and short string variables only.  Long string variables may
409 have value labels, but their value labels are recorded using a
410 different record type (@pxref{Long String Value Labels Record}).
411
412 The value label record has the following format:
413
414 @example
415 int32               rec_type;
416 int32               label_count;
417
418 /* @r{Repeated @code{label_cnt} times}. */
419 char                value[8];
420 char                label_len;
421 char                label[];
422 @end example
423
424 @table @code
425 @item int32 rec_type;
426 Record type.  Always set to 3.
427
428 @item int32 label_count;
429 Number of value labels present in this record.
430 @end table
431
432 The remaining fields are repeated @code{count} times.  Each
433 repetition specifies one value label.
434
435 @table @code
436 @item char value[8];
437 A numeric value or a short string value padded as necessary to 8 bytes
438 in length.  Its type and width cannot be determined until the
439 following value label variables record (see below) is read.
440
441 @item char label_len;
442 The label's length, in bytes.
443
444 @item char label[];
445 @code{label_len} bytes of the actual label, followed by up to 7 bytes
446 of padding to bring @code{label} and @code{label_len} together to a
447 multiple of 8 bytes in length.
448 @end table
449
450 The value label record is always immediately followed by a value label
451 variables record with the following format:
452
453 @example
454 int32               rec_type;
455 int32               var_count;
456 int32               vars[];
457 @end example
458
459 @table @code
460 @item int32 rec_type;
461 Record type.  Always set to 4.
462
463 @item int32 var_count;
464 Number of variables that the associated value labels from the value
465 label record are to be applied.
466
467 @item int32 vars[];
468 A list of dictionary indexes of variables to which to apply the value
469 labels (@pxref{Dictionary Index}).  There are @code{var_count}
470 elements.
471
472 String variables wider than 8 bytes may not be specified in this list.
473 @end table
474
475 @node Document Record
476 @section Document Record
477
478 The document record, if present, has the following format:
479
480 @example
481 int32               rec_type;
482 int32               n_lines;
483 char                lines[][80];
484 @end example
485
486 @table @code
487 @item int32 rec_type;
488 Record type.  Always set to 6.
489
490 @item int32 n_lines;
491 Number of lines of documents present.
492
493 @item char lines[][80];
494 Document lines.  The number of elements is defined by @code{n_lines}.
495 Lines shorter than 80 characters are padded on the right with spaces.
496 @end table
497
498 @node Machine Integer Info Record
499 @section Machine Integer Info Record
500
501 The integer info record, if present, has the following format:
502
503 @example
504 /* @r{Header.} */
505 int32               rec_type;
506 int32               subtype;
507 int32               size;
508 int32               count;
509
510 /* @r{Data.} */
511 int32               version_major;
512 int32               version_minor;
513 int32               version_revision;
514 int32               machine_code;
515 int32               floating_point_rep;
516 int32               compression_code;
517 int32               endianness;
518 int32               character_code;
519 @end example
520
521 @table @code
522 @item int32 rec_type;
523 Record type.  Always set to 7.
524
525 @item int32 subtype;
526 Record subtype.  Always set to 3.
527
528 @item int32 size;
529 Size of each piece of data in the data part, in bytes.  Always set to 4.
530
531 @item int32 count;
532 Number of pieces of data in the data part.  Always set to 8.
533
534 @item int32 version_major;
535 PSPP major version number.  In version @var{x}.@var{y}.@var{z}, this
536 is @var{x}.
537
538 @item int32 version_minor;
539 PSPP minor version number.  In version @var{x}.@var{y}.@var{z}, this
540 is @var{y}.
541
542 @item int32 version_revision;
543 PSPP version revision number.  In version @var{x}.@var{y}.@var{z},
544 this is @var{z}.
545
546 @item int32 machine_code;
547 Machine code.  PSPP always set this field to value to -1, but other
548 values may appear.
549
550 @item int32 floating_point_rep;
551 Floating point representation code.  For IEEE 754 systems this is 1.
552 IBM 370 sets this to 2, and DEC VAX E to 3.
553
554 @item int32 compression_code;
555 Compression code.  Always set to 1.
556
557 @item int32 endianness;
558 Machine endianness.  1 indicates big-endian, 2 indicates little-endian.
559
560 @item int32 character_code;
561 @anchor{character-code}
562 Character code.  1 indicates EBCDIC, 2 indicates 7-bit ASCII, 3
563 indicates 8-bit ASCII, 4 indicates DEC Kanji.
564 Windows code page numbers are also valid.
565
566 Experience has shown that in many files, this field is ignored or incorrect.
567 For a more reliable indication of the file's character encoding
568 see @ref{Character Encoding Record}.
569 @end table
570
571 @node Machine Floating-Point Info Record
572 @section Machine Floating-Point Info Record
573
574 The floating-point info record, if present, has the following format:
575
576 @example
577 /* @r{Header.} */
578 int32               rec_type;
579 int32               subtype;
580 int32               size;
581 int32               count;
582
583 /* @r{Data.} */
584 flt64               sysmis;
585 flt64               highest;
586 flt64               lowest;
587 @end example
588
589 @table @code
590 @item int32 rec_type;
591 Record type.  Always set to 7.
592
593 @item int32 subtype;
594 Record subtype.  Always set to 4.
595
596 @item int32 size;
597 Size of each piece of data in the data part, in bytes.  Always set to 8.
598
599 @item int32 count;
600 Number of pieces of data in the data part.  Always set to 3.
601
602 @item flt64 sysmis;
603 The system missing value.
604
605 @item flt64 highest;
606 The value used for HIGHEST in missing values.
607
608 @item flt64 lowest;
609 The value used for LOWEST in missing values.
610 @end table
611
612 @node Variable Display Parameter Record
613 @section Variable Display Parameter Record
614
615 The variable display parameter record, if present, has the following
616 format:
617
618 @example
619 /* @r{Header.} */
620 int32               rec_type;
621 int32               subtype;
622 int32               size;
623 int32               count;
624
625 /* @r{Repeated @code{count} times}. */
626 int32               measure;
627 int32               width;           /* @r{Not always present.} */
628 int32               alignment;
629 @end example
630
631 @table @code
632 @item int32 rec_type;
633 Record type.  Always set to 7.
634
635 @item int32 subtype;
636 Record subtype.  Always set to 11.
637
638 @item int32 size;
639 The size of @code{int32}.  Always set to 4.
640
641 @item int32 count;
642 The number of sets of variable display parameters (ordinarily the
643 number of variables in the dictionary), times 2 or 3.
644 @end table
645
646 The remaining members are repeated @code{count} times, in the same
647 order as the variable records.  No element corresponds to variable
648 records that continue long string variables.  The meanings of these
649 members are as follows:
650
651 @table @code
652 @item int32 measure;
653 The measurement type of the variable:
654 @table @asis
655 @item 1
656 Nominal Scale
657 @item 2
658 Ordinal Scale
659 @item 3
660 Continuous Scale
661 @end table
662
663 SPSS 14 sometimes writes a @code{measure} of 0.  PSPP interprets this
664 as nominal scale.
665
666 @item int32 width;
667 The width of the display column for the variable in characters.
668
669 This field is present if @var{count} is 3 times the number of
670 variables in the dictionary.  It is omitted if @var{count} is 2 times
671 the number of variables.
672
673 @item int32 alignment;
674 The alignment of the variable for display purposes:
675
676 @table @asis
677 @item 0
678 Left aligned
679 @item 1
680 Right aligned
681 @item 2
682 Centre aligned
683 @end table
684 @end table
685
686 @node Long Variable Names Record
687 @section Long Variable Names Record
688
689 If present, the long variable names record has the following format:
690
691 @example
692 /* @r{Header.} */
693 int32               rec_type;
694 int32               subtype;
695 int32               size;
696 int32               count;
697
698 /* @r{Exactly @code{count} bytes of data.} */
699 char                var_name_pairs[];
700 @end example
701
702 @table @code
703 @item int32 rec_type;
704 Record type.  Always set to 7.
705
706 @item int32 subtype;
707 Record subtype.  Always set to 13.
708
709 @item int32 size;
710 The size of each element in the @code{var_name_pairs} member. Always set to 1.
711
712 @item int32 count;
713 The total number of bytes in @code{var_name_pairs}.
714
715 @item char var_name_pairs[];
716 A list of @var{key}--@var{value} tuples, where @var{key} is the name
717 of a variable, and @var{value} is its long variable name.
718 The @var{key} field is at most 8 bytes long and must match the
719 name of a variable which appears in the variable record (@pxref{Variable
720 Record}).
721 The @var{value} field is at most 64 bytes long.
722 The @var{key} and @var{value} fields are separated by a @samp{=} byte.
723 Each tuple is separated by a byte whose value is 09.  There is no
724 trailing separator following the last tuple.
725 The total length is @code{count} bytes.
726 @end table
727
728 @node Very Long String Record
729 @section Very Long String Record
730
731 Old versions of SPSS limited string variables to a width of 255 bytes.
732 For backward compatibility with these older versions, the system file
733 format represents a string longer than 255 bytes, called a @dfn{very
734 long string}, as a collection of strings no longer than 255 bytes
735 each.  The strings concatenated to make a very long string are called
736 its @dfn{segments}; for consistency, variables other than very long
737 strings are considered to have a single segment.
738
739 A very long string with a width of @var{w} has @var{n} =
740 (@var{w} + 251) / 252 segments, that is, one segment for every
741 252 bytes of width, rounding up.  It would be logical, then, for each
742 of the segments except the last to have a width of 252 and the last
743 segment to have the remainder, but this is not the case.  In fact,
744 each segment except the last has a width of 255 bytes.  The last
745 segment has width @var{w} - (@var{n} - 1) * 252; some versions
746 of SPSS make it slightly wider, but not wide enough to make the last
747 segment require another 8 bytes of data.
748
749 Data is packed tightly into segments of a very long string, 255 bytes
750 per segment.  Because 255 bytes of segment data are allocated for
751 every 252 bytes of the very long string's width (approximately), some
752 unused space is left over at the end of the allocated segments.  Data
753 in unused space is ignored.
754
755 Example: Consider a very long string of width 20,000.  Such a very
756 long string has 20,000 / 252 = 80 (rounding up) segments.  The first
757 79 segments have width 255; the last segment has width 20,000 - 79 *
758 252 = 92 or slightly wider (up to 96 bytes, the next multiple of 8).
759 The very long string's data is actually stored in the 19,890 bytes in
760 the first 78 segments, plus the first 110 bytes of the 79th segment
761 (19,890 + 110 = 20,000).  The remaining 145 bytes of the 79th segment
762 and all 92 bytes of the 80th segment are unused.
763
764 The very long string record explains how to stitch together segments
765 to obtain very long string data.  For each of the very long string
766 variables in the dictionary, it specifies the name of its first
767 segment's variable and the very long string variable's actual width.
768 The remaining segments immediately follow the named variable in the
769 system file's dictionary.
770
771 The very long string record, which is present only if the system file
772 contains very long string variables, has the following format:
773
774 @example
775 /* @r{Header.} */
776 int32               rec_type;
777 int32               subtype;
778 int32               size;
779 int32               count;
780
781 /* @r{Exactly @code{count} bytes of data.} */
782 char                string_lengths[];
783 @end example
784
785 @table @code
786 @item int32 rec_type;
787 Record type.  Always set to 7.
788
789 @item int32 subtype;
790 Record subtype.  Always set to 14.
791
792 @item int32 size;
793 The size of each element in the @code{string_lengths} member. Always set to 1.
794
795 @item int32 count;
796 The total number of bytes in @code{string_lengths}.
797
798 @item char string_lengths[];
799 A list of @var{key}--@var{value} tuples, where @var{key} is the name
800 of a variable, and @var{value} is its length.
801 The @var{key} field is at most 8 bytes long and must match the
802 name of a variable which appears in the variable record (@pxref{Variable
803 Record}).
804 The @var{value} field is exactly 5 bytes long. It is a zero-padded,
805 ASCII-encoded string that is the length of the variable.
806 The @var{key} and @var{value} fields are separated by a @samp{=} byte.
807 Tuples are delimited by a two-byte sequence @{00, 09@}.
808 After the last tuple, there may be a single byte 00, or @{00, 09@}.
809 The total length is @code{count} bytes.
810 @end table
811
812 @node Character Encoding Record
813 @section Character Encoding Record
814
815 This record, if present, indicates the character encoding for string data,
816 long variable names, variable labels, value labels and other strings in the
817 file.
818
819 @example
820 /* @r{Header.} */
821 int32               rec_type;
822 int32               subtype;
823 int32               size;
824 int32               count;
825
826 /* @r{Exactly @code{count} bytes of data.} */
827 char                encoding[];
828 @end example
829
830 @table @code
831 @item int32 rec_type;
832 Record type.  Always set to 7.
833
834 @item int32 subtype;
835 Record subtype.  Always set to 20.
836
837 @item int32 size;
838 The size of each element in the @code{encoding} member. Always set to 1.
839
840 @item int32 count;
841 The total number of bytes in @code{encoding}.
842
843 @item char encoding[];
844 The name of the character encoding.  Normally this will be an official IANA characterset name or alias.
845 See @url{http://www.iana.org/assignments/character-sets}.
846 @end table
847
848 This record is not present in files generated by older software.
849 See also @ref{character-code}.
850
851 @node Long String Value Labels Record
852 @section Long String Value Labels Record
853
854 This record, if present, specifies value labels for long string
855 variables.
856
857 @example
858 /* @r{Header.} */
859 int32               rec_type;
860 int32               subtype;
861 int32               size;
862 int32               count;
863
864 /* @r{Repeated up to exactly @code{count} bytes.} */
865 int32               var_name_len;
866 char                var_name[];
867 int32               var_width;
868 int32               n_labels;
869 long_string_label   labels[];
870 @end example
871
872 @table @code
873 @item int32 rec_type;
874 Record type.  Always set to 7.
875
876 @item int32 subtype;
877 Record subtype.  Always set to 21.
878
879 @item int32 size;
880 Always set to 1.
881
882 @item int32 count;
883 The number of bytes following the header until the next header.
884
885 @item int32 var_name_len;
886 @itemx char var_name[];
887 The number of bytes in the name of the variable that has long string
888 value labels, plus the variable name itself, which consists of exactly
889 @code{var_name_len} bytes.  The variable name is not padded to any
890 particular boundary, nor is it null-terminated.
891
892 @item int32 var_width;
893 The width of the variable, in bytes, which will be between 9 and
894 32767.
895
896 @item int32 n_labels;
897 @itemx long_string_label labels[];
898 The long string labels themselves.  The @code{labels} array contains
899 exactly @code{n_labels} elements, each of which has the following
900 substructure:
901
902 @example
903 int32               value_len;
904 char                value[];
905 int32               label_len;
906 char                label[];
907 @end example
908
909 @table @code
910 @item int32 value_len;
911 @itemx char value[];
912 The string value being labeled.  @code{value_len} is the number of
913 bytes in @code{value}; it is equal to @code{var_width}.  The
914 @code{value} array is not padded or null-terminated.
915
916 @item int32 label_len;
917 @itemx char label[];
918 The label for the string value.  @code{label_len}, which must be
919 between 0 and 120, is the number of bytes in @code{label}.  The
920 @code{label} array is not padded or null-terminated.
921 @end table
922 @end table
923
924 @node Data File and Variable Attributes Records
925 @section Data File and Variable Attributes Records
926
927 The data file and variable attributes records represent custom
928 attributes for the system file or for individual variables in the
929 system file, as defined on the DATAFILE ATTRIBUTE (@pxref{DATAFILE
930 ATTRIBUTE,,,pspp, PSPP Users Guide}) and VARIABLE ATTRIBUTE commands
931 (@pxref{VARIABLE ATTRIBUTE,,,pspp, PSPP Users Guide}), respectively.
932
933 @example
934 /* @r{Header.} */
935 int32               rec_type;
936 int32               subtype;
937 int32               size;
938 int32               count;
939
940 /* @r{Exactly @code{count} bytes of data.} */
941 char                attributes[];
942 @end example
943
944 @table @code
945 @item int32 rec_type;
946 Record type.  Always set to 7.
947
948 @item int32 subtype;
949 Record subtype.  Always set to 17 for a data file attribute record or
950 to 18 for a variable attributes record.
951
952 @item int32 size;
953 The size of each element in the @code{attributes} member. Always set to 1.
954
955 @item int32 count;
956 The total number of bytes in @code{attributes}.
957
958 @item char attributes[];
959 The attributes, in a text-based format.
960
961 In record type 17, this field contains a single attribute set.  An
962 attribute set is a sequence of one or more attributes concatenated
963 together.  Each attribute consists of a name, which has the same
964 syntax as a variable name, followed by, inside parentheses, a sequence
965 of one or more values.  Each value consists of a string enclosed in
966 single quotes (@code{'}) followed by a line feed (byte 0x0a).  A value
967 may contain single quote characters, which are not themselves escaped
968 or quoted or required to be present in pairs.  There is no apparent
969 way to embed a line feed in a value.  There is no distinction between
970 an attribute with a single value and an attribute array with one
971 element.
972
973 In record type 18, this field contains a sequence of one or more
974 variable attribute sets.  If more than one variable attribute set is
975 present, each one after the first is delimited from the previous by
976 @code{/}.  Each variable attribute set consists of a variable name,
977 followed by @code{:}, followed by an attribute set with the same
978 syntax as on record type 17.
979
980 The total length is @code{count} bytes.
981 @end table
982
983 @subheading Example
984
985 A system file produced with the following VARIABLE ATTRIBUTE commands
986 in effect:
987
988 @example
989 VARIABLE ATTRIBUTE VARIABLES=dummy ATTRIBUTE=fred[1]('23') fred[2]('34').
990 VARIABLE ATTRIBUTE VARIABLES=dummy ATTRIBUTE=bert('123').
991 @end example
992
993 @noindent
994 will contain a variable attribute record with the following contents:
995
996 @example
997 00000000  07 00 00 00 12 00 00 00  01 00 00 00 22 00 00 00  |............"...|
998 00000010  64 75 6d 6d 79 3a 66 72  65 64 28 27 32 33 27 0a  |dummy:fred('23'.|
999 00000020  27 33 34 27 0a 29 62 65  72 74 28 27 31 32 33 27  |'34'.)bert('123'|
1000 00000030  0a 29                                             |.)              |
1001 @end example
1002
1003 @node Miscellaneous Informational Records
1004 @section Miscellaneous Informational Records
1005
1006 Some specific types of miscellaneous informational records are
1007 documented here, but others are known to exist.  PSPP ignores unknown
1008 miscellaneous informational records when reading system files.
1009
1010 @example
1011 /* @r{Header.} */
1012 int32               rec_type;
1013 int32               subtype;
1014 int32               size;
1015 int32               count;
1016
1017 /* @r{Exactly @code{size * count} bytes of data.} */
1018 char                data[];
1019 @end example
1020
1021 @table @code
1022 @item int32 rec_type;
1023 Record type.  Always set to 7.
1024
1025 @item int32 subtype;
1026 Record subtype.  May take any value.  According to Aapi
1027 H@"am@"al@"ainen, value 5 indicates a set of grouped variables and 6
1028 indicates date info (probably related to USE).
1029
1030 @item int32 size;
1031 Size of each piece of data in the data part.  Should have the value 1,
1032 4, or 8, for @code{char}, @code{int32}, and @code{flt64} format data,
1033 respectively.
1034
1035 @item int32 count;
1036 Number of pieces of data in the data part.
1037
1038 @item char data[];
1039 Arbitrary data.  There must be @code{size} times @code{count} bytes of
1040 data.
1041 @end table
1042
1043 @node Dictionary Termination Record
1044 @section Dictionary Termination Record
1045
1046 The dictionary termination record separates all other records from the
1047 data records.
1048
1049 @example
1050 int32               rec_type;
1051 int32               filler;
1052 @end example
1053
1054 @table @code
1055 @item int32 rec_type;
1056 Record type.  Always set to 999.
1057
1058 @item int32 filler;
1059 Ignored padding.  Should be set to 0.
1060 @end table
1061
1062 @node Data Record
1063 @section Data Record
1064
1065 Data records must follow all other records in the system file.  There must
1066 be at least one data record in every system file.
1067
1068 The format of data records varies depending on whether the data is
1069 compressed.  Regardless, the data is arranged in a series of 8-byte
1070 elements.
1071
1072 When data is not compressed,
1073 each element corresponds to
1074 the variable declared in the respective variable record (@pxref{Variable
1075 Record}).  Numeric values are given in @code{flt64} format; string
1076 values are literal characters string, padded on the right when
1077 necessary to fill out 8-byte units.
1078
1079 Compressed data is arranged in the following manner: the first 8 bytes
1080 in the data section is divided into a series of 1-byte command
1081 codes.  These codes have meanings as described below:
1082
1083 @table @asis
1084 @item 0
1085 Ignored.  If the program writing the system file accumulates compressed
1086 data in blocks of fixed length, 0 bytes can be used to pad out extra
1087 bytes remaining at the end of a fixed-size block.
1088
1089 @item 1 through 251
1090 A number with
1091 value @var{code} - @var{bias}, where
1092 @var{code} is the value of the compression code and @var{bias} is the
1093 variable @code{bias} from the file header.  For example,
1094 code 105 with bias 100.0 (the normal value) indicates a numeric variable
1095 of value 5.
1096
1097 @item 252
1098 End of file.  This code may or may not appear at the end of the data
1099 stream.  PSPP always outputs this code but its use is not required.
1100
1101 @item 253
1102 A numeric or string value that is not
1103 compressible.  The value is stored in the 8 bytes following the
1104 current block of command bytes.  If this value appears twice in a block
1105 of command bytes, then it indicates the second group of 8 bytes following the
1106 command bytes, and so on.
1107
1108 @item 254
1109 An 8-byte string value that is all spaces.
1110
1111 @item 255
1112 The system-missing value.
1113 @end table
1114
1115 When the end of the an 8-byte group of command bytes is reached, any
1116 blocks of non-compressible values indicated by code 253 are skipped,
1117 and the next element of command bytes is read and interpreted, until
1118 the end of the file or a code with value 252 is reached.
1119 @setfilename ignored