Add support for value labels on 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 not 0.  It has
293 the same number of elements as the absolute value of
294 @code{n_missing_values}.  For discrete missing values, each element
295 represents one missing value.  When a range is present, the first
296 element denotes the minimum value in the range, and the second element
297 denotes the maximum value in the range.  When a range plus a value are
298 present, the third element denotes the additional discrete missing
299 value.  HIGHEST and LOWEST are indicated as described in the chapter
300 introduction.
301 @end table
302
303 The @code{print} and @code{write} members of sysfile_variable are output
304 formats coded into @code{int32} types.  The least-significant byte
305 of the @code{int32} represents the number of decimal places, and the
306 next two bytes in order of increasing significance represent field width
307 and format type, respectively.  The most-significant byte is not
308 used and should be set to zero.
309
310 Format types are defined as follows:
311
312 @quotation
313 @multitable {Value} {@code{DATETIME}}
314 @headitem Value
315 @tab Meaning
316 @item 0
317 @tab Not used.
318 @item 1
319 @tab @code{A}
320 @item 2
321 @tab @code{AHEX}
322 @item 3
323 @tab @code{COMMA}
324 @item 4
325 @tab @code{DOLLAR}
326 @item 5
327 @tab @code{F}
328 @item 6
329 @tab @code{IB}
330 @item 7
331 @tab @code{PIBHEX}
332 @item 8
333 @tab @code{P}
334 @item 9
335 @tab @code{PIB}
336 @item 10
337 @tab @code{PK}
338 @item 11
339 @tab @code{RB}
340 @item 12
341 @tab @code{RBHEX}
342 @item 13
343 @tab Not used.
344 @item 14
345 @tab Not used.
346 @item 15
347 @tab @code{Z}
348 @item 16
349 @tab @code{N}
350 @item 17
351 @tab @code{E}
352 @item 18
353 @tab Not used.
354 @item 19
355 @tab Not used.
356 @item 20
357 @tab @code{DATE}
358 @item 21
359 @tab @code{TIME}
360 @item 22
361 @tab @code{DATETIME}
362 @item 23
363 @tab @code{ADATE}
364 @item 24
365 @tab @code{JDATE}
366 @item 25
367 @tab @code{DTIME}
368 @item 26
369 @tab @code{WKDAY}
370 @item 27
371 @tab @code{MONTH}
372 @item 28
373 @tab @code{MOYR}
374 @item 29
375 @tab @code{QYR}
376 @item 30
377 @tab @code{WKYR}
378 @item 31
379 @tab @code{PCT}
380 @item 32
381 @tab @code{DOT}
382 @item 33
383 @tab @code{CCA}
384 @item 34
385 @tab @code{CCB}
386 @item 35
387 @tab @code{CCC}
388 @item 36
389 @tab @code{CCD}
390 @item 37
391 @tab @code{CCE}
392 @item 38
393 @tab @code{EDATE}
394 @item 39
395 @tab @code{SDATE}
396 @end multitable
397 @end quotation
398
399 @node Value Labels Records
400 @section Value Labels Records
401
402 The value label records documented in this section are used for
403 numeric and short string variables only.  Long string variables may
404 have value labels, but their value labels are recorded using a
405 different record type (@pxref{Long String Value Labels Record}).
406
407 The value label record has the following format:
408
409 @example
410 int32               rec_type;
411 int32               label_count;
412
413 /* @r{Repeated @code{label_cnt} times}. */
414 char                value[8];
415 char                label_len;
416 char                label[];
417 @end example
418
419 @table @code
420 @item int32 rec_type;
421 Record type.  Always set to 3.
422
423 @item int32 label_count;
424 Number of value labels present in this record.
425 @end table
426
427 The remaining fields are repeated @code{count} times.  Each
428 repetition specifies one value label.
429
430 @table @code
431 @item char value[8];
432 A numeric value or a short string value padded as necessary to 8 bytes
433 in length.  Its type and width cannot be determined until the
434 following value label variables record (see below) is read.
435
436 @item char label_len;
437 The label's length, in bytes.
438
439 @item char label[];
440 @code{label_len} bytes of the actual label, followed by up to 7 bytes
441 of padding to bring @code{label} and @code{label_len} together to a
442 multiple of 8 bytes in length.
443 @end table
444
445 The value label record is always immediately followed by a value label
446 variables record with the following format:
447
448 @example
449 int32               rec_type;
450 int32               var_count;
451 int32               vars[];
452 @end example
453
454 @table @code
455 @item int32 rec_type;
456 Record type.  Always set to 4.
457
458 @item int32 var_count;
459 Number of variables that the associated value labels from the value
460 label record are to be applied.
461
462 @item int32 vars[];
463 A list of dictionary indexes of variables to which to apply the value
464 labels (@pxref{Dictionary Index}).  There are @code{var_count}
465 elements.
466
467 String variables wider than 8 bytes may not be specified in this list.
468 @end table
469
470 @node Document Record
471 @section Document Record
472
473 The document record, if present, has the following format:
474
475 @example
476 int32               rec_type;
477 int32               n_lines;
478 char                lines[][80];
479 @end example
480
481 @table @code
482 @item int32 rec_type;
483 Record type.  Always set to 6.
484
485 @item int32 n_lines;
486 Number of lines of documents present.
487
488 @item char lines[][80];
489 Document lines.  The number of elements is defined by @code{n_lines}.
490 Lines shorter than 80 characters are padded on the right with spaces.
491 @end table
492
493 @node Machine Integer Info Record
494 @section Machine Integer Info Record
495
496 The integer info record, if present, has the following format:
497
498 @example
499 /* @r{Header.} */
500 int32               rec_type;
501 int32               subtype;
502 int32               size;
503 int32               count;
504
505 /* @r{Data.} */
506 int32               version_major;
507 int32               version_minor;
508 int32               version_revision;
509 int32               machine_code;
510 int32               floating_point_rep;
511 int32               compression_code;
512 int32               endianness;
513 int32               character_code;
514 @end example
515
516 @table @code
517 @item int32 rec_type;
518 Record type.  Always set to 7.
519
520 @item int32 subtype;
521 Record subtype.  Always set to 3.
522
523 @item int32 size;
524 Size of each piece of data in the data part, in bytes.  Always set to 4.
525
526 @item int32 count;
527 Number of pieces of data in the data part.  Always set to 8.
528
529 @item int32 version_major;
530 PSPP major version number.  In version @var{x}.@var{y}.@var{z}, this
531 is @var{x}.
532
533 @item int32 version_minor;
534 PSPP minor version number.  In version @var{x}.@var{y}.@var{z}, this
535 is @var{y}.
536
537 @item int32 version_revision;
538 PSPP version revision number.  In version @var{x}.@var{y}.@var{z},
539 this is @var{z}.
540
541 @item int32 machine_code;
542 Machine code.  PSPP always set this field to value to -1, but other
543 values may appear.
544
545 @item int32 floating_point_rep;
546 Floating point representation code.  For IEEE 754 systems this is 1.
547 IBM 370 sets this to 2, and DEC VAX E to 3.
548
549 @item int32 compression_code;
550 Compression code.  Always set to 1.
551
552 @item int32 endianness;
553 Machine endianness.  1 indicates big-endian, 2 indicates little-endian.
554
555 @item int32 character_code;
556 @anchor{character-code}
557 Character code.  1 indicates EBCDIC, 2 indicates 7-bit ASCII, 3
558 indicates 8-bit ASCII, 4 indicates DEC Kanji.
559 Windows code page numbers are also valid.
560
561 Experience has shown that in many files, this field is ignored or incorrect.
562 For a more reliable indication of the file's character encoding
563 see @ref{Character Encoding Record}.
564 @end table
565
566 @node Machine Floating-Point Info Record
567 @section Machine Floating-Point Info Record
568
569 The floating-point info record, if present, has the following format:
570
571 @example
572 /* @r{Header.} */
573 int32               rec_type;
574 int32               subtype;
575 int32               size;
576 int32               count;
577
578 /* @r{Data.} */
579 flt64               sysmis;
580 flt64               highest;
581 flt64               lowest;
582 @end example
583
584 @table @code
585 @item int32 rec_type;
586 Record type.  Always set to 7.
587
588 @item int32 subtype;
589 Record subtype.  Always set to 4.
590
591 @item int32 size;
592 Size of each piece of data in the data part, in bytes.  Always set to 8.
593
594 @item int32 count;
595 Number of pieces of data in the data part.  Always set to 3.
596
597 @item flt64 sysmis;
598 The system missing value.
599
600 @item flt64 highest;
601 The value used for HIGHEST in missing values.
602
603 @item flt64 lowest;
604 The value used for LOWEST in missing values.
605 @end table
606
607 @node Variable Display Parameter Record
608 @section Variable Display Parameter Record
609
610 The variable display parameter record, if present, has the following
611 format:
612
613 @example
614 /* @r{Header.} */
615 int32               rec_type;
616 int32               subtype;
617 int32               size;
618 int32               count;
619
620 /* @r{Repeated @code{count} times}. */
621 int32               measure;
622 int32               width;           /* @r{Not always present.} */
623 int32               alignment;
624 @end example
625
626 @table @code
627 @item int32 rec_type;
628 Record type.  Always set to 7.
629
630 @item int32 subtype;
631 Record subtype.  Always set to 11.
632
633 @item int32 size;
634 The size of @code{int32}.  Always set to 4.
635
636 @item int32 count;
637 The number of sets of variable display parameters (ordinarily the
638 number of variables in the dictionary), times 2 or 3.
639 @end table
640
641 The remaining members are repeated @code{count} times, in the same
642 order as the variable records.  No element corresponds to variable
643 records that continue long string variables.  The meanings of these
644 members are as follows:
645
646 @table @code
647 @item int32 measure;
648 The measurement type of the variable:
649 @table @asis
650 @item 1
651 Nominal Scale
652 @item 2
653 Ordinal Scale
654 @item 3
655 Continuous Scale
656 @end table
657
658 SPSS 14 sometimes writes a @code{measure} of 0.  PSPP interprets this
659 as nominal scale.
660
661 @item int32 width;
662 The width of the display column for the variable in characters.
663
664 This field is present if @var{count} is 3 times the number of
665 variables in the dictionary.  It is omitted if @var{count} is 2 times
666 the number of variables.
667
668 @item int32 alignment;
669 The alignment of the variable for display purposes:
670
671 @table @asis
672 @item 0
673 Left aligned
674 @item 1
675 Right aligned
676 @item 2
677 Centre aligned
678 @end table
679 @end table
680
681 @node Long Variable Names Record
682 @section Long Variable Names Record
683
684 If present, the long variable names record has the following format:
685
686 @example
687 /* @r{Header.} */
688 int32               rec_type;
689 int32               subtype;
690 int32               size;
691 int32               count;
692
693 /* @r{Exactly @code{count} bytes of data.} */
694 char                var_name_pairs[];
695 @end example
696
697 @table @code
698 @item int32 rec_type;
699 Record type.  Always set to 7.
700
701 @item int32 subtype;
702 Record subtype.  Always set to 13.
703
704 @item int32 size;
705 The size of each element in the @code{var_name_pairs} member. Always set to 1.
706
707 @item int32 count;
708 The total number of bytes in @code{var_name_pairs}.
709
710 @item char var_name_pairs[];
711 A list of @var{key}--@var{value} tuples, where @var{key} is the name
712 of a variable, and @var{value} is its long variable name.
713 The @var{key} field is at most 8 bytes long and must match the
714 name of a variable which appears in the variable record (@pxref{Variable
715 Record}).
716 The @var{value} field is at most 64 bytes long.
717 The @var{key} and @var{value} fields are separated by a @samp{=} byte.
718 Each tuple is separated by a byte whose value is 09.  There is no
719 trailing separator following the last tuple.
720 The total length is @code{count} bytes.
721 @end table
722
723 @node Very Long String Record
724 @section Very Long String Record
725
726 Old versions of SPSS limited string variables to a width of 255 bytes.
727 For backward compatibility with these older versions, the system file
728 format represents a string longer than 255 bytes, called a @dfn{very
729 long string}, as a collection of strings no longer than 255 bytes
730 each.  The strings concatenated to make a very long string are called
731 its @dfn{segments}; for consistency, variables other than very long
732 strings are considered to have a single segment.
733
734 A very long string with a width of @var{w} has @var{n} =
735 (@var{w} + 251) / 252 segments, that is, one segment for every
736 252 bytes of width, rounding up.  It would be logical, then, for each
737 of the segments except the last to have a width of 252 and the last
738 segment to have the remainder, but this is not the case.  In fact,
739 each segment except the last has a width of 255 bytes.  The last
740 segment has width @var{w} - (@var{n} - 1) * 252; some versions
741 of SPSS make it slightly wider, but not wide enough to make the last
742 segment require another 8 bytes of data.
743
744 Data is packed tightly into segments of a very long string, 255 bytes
745 per segment.  Because 255 bytes of segment data are allocated for
746 every 252 bytes of the very long string's width (approximately), some
747 unused space is left over at the end of the allocated segments.  Data
748 in unused space is ignored.
749
750 Example: Consider a very long string of width 20,000.  Such a very
751 long string has 20,000 / 252 = 80 (rounding up) segments.  The first
752 79 segments have width 255; the last segment has width 20,000 - 79 *
753 252 = 92 or slightly wider (up to 96 bytes, the next multiple of 8).
754 The very long string's data is actually stored in the 19,890 bytes in
755 the first 78 segments, plus the first 110 bytes of the 79th segment
756 (19,890 + 110 = 20,000).  The remaining 145 bytes of the 79th segment
757 and all 92 bytes of the 80th segment are unused.
758
759 The very long string record explains how to stitch together segments
760 to obtain very long string data.  For each of the very long string
761 variables in the dictionary, it specifies the name of its first
762 segment's variable and the very long string variable's actual width.
763 The remaining segments immediately follow the named variable in the
764 system file's dictionary.
765
766 The very long string record, which is present only if the system file
767 contains very long string variables, has the following format:
768
769 @example
770 /* @r{Header.} */
771 int32               rec_type;
772 int32               subtype;
773 int32               size;
774 int32               count;
775
776 /* @r{Exactly @code{count} bytes of data.} */
777 char                string_lengths[];
778 @end example
779
780 @table @code
781 @item int32 rec_type;
782 Record type.  Always set to 7.
783
784 @item int32 subtype;
785 Record subtype.  Always set to 14.
786
787 @item int32 size;
788 The size of each element in the @code{string_lengths} member. Always set to 1.
789
790 @item int32 count;
791 The total number of bytes in @code{string_lengths}.
792
793 @item char string_lengths[];
794 A list of @var{key}--@var{value} tuples, where @var{key} is the name
795 of a variable, and @var{value} is its length.
796 The @var{key} field is at most 8 bytes long and must match the
797 name of a variable which appears in the variable record (@pxref{Variable
798 Record}).
799 The @var{value} field is exactly 5 bytes long. It is a zero-padded,
800 ASCII-encoded string that is the length of the variable.
801 The @var{key} and @var{value} fields are separated by a @samp{=} byte.
802 Tuples are delimited by a two-byte sequence @{00, 09@}.
803 After the last tuple, there may be a single byte 00, or @{00, 09@}.
804 The total length is @code{count} bytes.
805 @end table
806
807 @node Character Encoding Record
808 @section Character Encoding Record
809
810 This record, if present, indicates the character encoding for string data,
811 long variable names, variable labels, value labels and other strings in the
812 file.
813
814 @example
815 /* @r{Header.} */
816 int32               rec_type;
817 int32               subtype;
818 int32               size;
819 int32               count;
820
821 /* @r{Exactly @code{count} bytes of data.} */
822 char                encoding[];
823 @end example
824
825 @table @code
826 @item int32 rec_type;
827 Record type.  Always set to 7.
828
829 @item int32 subtype;
830 Record subtype.  Always set to 20.
831
832 @item int32 size;
833 The size of each element in the @code{encoding} member. Always set to 1.
834
835 @item int32 count;
836 The total number of bytes in @code{encoding}.
837
838 @item char encoding[];
839 The name of the character encoding.  Normally this will be an official IANA characterset name or alias.
840 See @url{http://www.iana.org/assignments/character-sets}.
841 @end table
842
843 This record is not present in files generated by older software.
844 See also @ref{character-code}.
845
846 @node Long String Value Labels Record
847 @section Long String Value Labels Record
848
849 This record, if present, specifies value labels for long string
850 variables.
851
852 @example
853 /* @r{Header.} */
854 int32               rec_type;
855 int32               subtype;
856 int32               size;
857 int32               count;
858
859 /* @r{Repeated up to exactly @code{count} bytes.} */
860 int32               var_name_len;
861 char                var_name[];
862 int32               var_width;
863 int32               n_labels;
864 long_string_label   labels[];
865 @end example
866
867 @table @code
868 @item int32 rec_type;
869 Record type.  Always set to 7.
870
871 @item int32 subtype;
872 Record subtype.  Always set to 21.
873
874 @item int32 size;
875 Always set to 1.
876
877 @item int32 count;
878 The number of bytes following the header until the next header.
879
880 @item int32 var_name_len;
881 @itemx char var_name[];
882 The number of bytes in the name of the variable that has long string
883 value labels, plus the variable name itself, which consists of exactly
884 @code{var_name_len} bytes.  The variable name is not padded to any
885 particular boundary, nor is it null-terminated.
886
887 @item int32 var_width;
888 The width of the variable, in bytes, which will be between 9 and
889 32767.
890
891 @item int32 n_labels;
892 @itemx long_string_label labels[];
893 The long string labels themselves.  The @code{labels} array contains
894 exactly @code{n_labels} elements, each of which has the following
895 substructure:
896
897 @example
898 int32               value_len;
899 char                value[];
900 int32               label_len;
901 char                label[];
902 @end example
903
904 @table @code
905 @item int32 value_len;
906 @itemx char value[];
907 The string value being labeled.  @code{value_len} is the number of
908 bytes in @code{value}; it is equal to @code{var_width}.  The
909 @code{value} array is not padded or null-terminated.
910
911 @item int32 label_len;
912 @itemx char label[];
913 The label for the string value.  @code{label_len}, which must be
914 between 0 and 120, is the number of bytes in @code{label}.  The
915 @code{label} array is not padded or null-terminated.
916 @end table
917 @end table
918
919 @node Data File and Variable Attributes Records
920 @section Data File and Variable Attributes Records
921
922 The data file and variable attributes records represent custom
923 attributes for the system file or for individual variables in the
924 system file, as defined on the DATAFILE ATTRIBUTE (@pxref{DATAFILE
925 ATTRIBUTE,,,pspp, PSPP Users Guide}) and VARIABLE ATTRIBUTE commands
926 (@pxref{VARIABLE ATTRIBUTE,,,pspp, PSPP Users Guide}), respectively.
927
928 @example
929 /* @r{Header.} */
930 int32               rec_type;
931 int32               subtype;
932 int32               size;
933 int32               count;
934
935 /* @r{Exactly @code{count} bytes of data.} */
936 char                attributes[];
937 @end example
938
939 @table @code
940 @item int32 rec_type;
941 Record type.  Always set to 7.
942
943 @item int32 subtype;
944 Record subtype.  Always set to 17 for a data file attribute record or
945 to 18 for a variable attributes record.
946
947 @item int32 size;
948 The size of each element in the @code{attributes} member. Always set to 1.
949
950 @item int32 count;
951 The total number of bytes in @code{attributes}.
952
953 @item char attributes[];
954 The attributes, in a text-based format.
955
956 In record type 17, this field contains a single attribute set.  An
957 attribute set is a sequence of one or more attributes concatenated
958 together.  Each attribute consists of a name, which has the same
959 syntax as a variable name, followed by, inside parentheses, a sequence
960 of one or more values.  Each value consists of a string enclosed in
961 single quotes (@code{'}) followed by a line feed (byte 0x0a).  A value
962 may contain single quote characters, which are not themselves escaped
963 or quoted or required to be present in pairs.  There is no apparent
964 way to embed a line feed in a value.  There is no distinction between
965 an attribute with a single value and an attribute array with one
966 element.
967
968 In record type 18, this field contains a sequence of one or more
969 variable attribute sets.  If more than one variable attribute set is
970 present, each one after the first is delimited from the previous by
971 @code{/}.  Each variable attribute set consists of a variable name,
972 followed by @code{:}, followed by an attribute set with the same
973 syntax as on record type 17.
974
975 The total length is @code{count} bytes.
976 @end table
977
978 @subheading Example
979
980 A system file produced with the following VARIABLE ATTRIBUTE commands
981 in effect:
982
983 @example
984 VARIABLE ATTRIBUTE VARIABLES=dummy ATTRIBUTE=fred[1]('23') fred[2]('34').
985 VARIABLE ATTRIBUTE VARIABLES=dummy ATTRIBUTE=bert('123').
986 @end example
987
988 @noindent
989 will contain a variable attribute record with the following contents:
990
991 @example
992 00000000  07 00 00 00 12 00 00 00  01 00 00 00 22 00 00 00  |............"...|
993 00000010  64 75 6d 6d 79 3a 66 72  65 64 28 27 32 33 27 0a  |dummy:fred('23'.|
994 00000020  27 33 34 27 0a 29 62 65  72 74 28 27 31 32 33 27  |'34'.)bert('123'|
995 00000030  0a 29                                             |.)              |
996 @end example
997
998 @node Miscellaneous Informational Records
999 @section Miscellaneous Informational Records
1000
1001 Some specific types of miscellaneous informational records are
1002 documented here, but others are known to exist.  PSPP ignores unknown
1003 miscellaneous informational records when reading system files.
1004
1005 @example
1006 /* @r{Header.} */
1007 int32               rec_type;
1008 int32               subtype;
1009 int32               size;
1010 int32               count;
1011
1012 /* @r{Exactly @code{size * count} bytes of data.} */
1013 char                data[];
1014 @end example
1015
1016 @table @code
1017 @item int32 rec_type;
1018 Record type.  Always set to 7.
1019
1020 @item int32 subtype;
1021 Record subtype.  May take any value.  According to Aapi
1022 H@"am@"al@"ainen, value 5 indicates a set of grouped variables and 6
1023 indicates date info (probably related to USE).
1024
1025 @item int32 size;
1026 Size of each piece of data in the data part.  Should have the value 1,
1027 4, or 8, for @code{char}, @code{int32}, and @code{flt64} format data,
1028 respectively.
1029
1030 @item int32 count;
1031 Number of pieces of data in the data part.
1032
1033 @item char data[];
1034 Arbitrary data.  There must be @code{size} times @code{count} bytes of
1035 data.
1036 @end table
1037
1038 @node Dictionary Termination Record
1039 @section Dictionary Termination Record
1040
1041 The dictionary termination record separates all other records from the
1042 data records.
1043
1044 @example
1045 int32               rec_type;
1046 int32               filler;
1047 @end example
1048
1049 @table @code
1050 @item int32 rec_type;
1051 Record type.  Always set to 999.
1052
1053 @item int32 filler;
1054 Ignored padding.  Should be set to 0.
1055 @end table
1056
1057 @node Data Record
1058 @section Data Record
1059
1060 Data records must follow all other records in the system file.  There must
1061 be at least one data record in every system file.
1062
1063 The format of data records varies depending on whether the data is
1064 compressed.  Regardless, the data is arranged in a series of 8-byte
1065 elements.
1066
1067 When data is not compressed,
1068 each element corresponds to
1069 the variable declared in the respective variable record (@pxref{Variable
1070 Record}).  Numeric values are given in @code{flt64} format; string
1071 values are literal characters string, padded on the right when
1072 necessary to fill out 8-byte units.
1073
1074 Compressed data is arranged in the following manner: the first 8 bytes
1075 in the data section is divided into a series of 1-byte command
1076 codes.  These codes have meanings as described below:
1077
1078 @table @asis
1079 @item 0
1080 Ignored.  If the program writing the system file accumulates compressed
1081 data in blocks of fixed length, 0 bytes can be used to pad out extra
1082 bytes remaining at the end of a fixed-size block.
1083
1084 @item 1 through 251
1085 A number with
1086 value @var{code} - @var{bias}, where
1087 @var{code} is the value of the compression code and @var{bias} is the
1088 variable @code{bias} from the file header.  For example,
1089 code 105 with bias 100.0 (the normal value) indicates a numeric variable
1090 of value 5.
1091
1092 @item 252
1093 End of file.  This code may or may not appear at the end of the data
1094 stream.  PSPP always outputs this code but its use is not required.
1095
1096 @item 253
1097 A numeric or string value that is not
1098 compressible.  The value is stored in the 8 bytes following the
1099 current block of command bytes.  If this value appears twice in a block
1100 of command bytes, then it indicates the second group of 8 bytes following the
1101 command bytes, and so on.
1102
1103 @item 254
1104 An 8-byte string value that is all spaces.
1105
1106 @item 255
1107 The system-missing value.
1108 @end table
1109
1110 When the end of the an 8-byte group of command bytes is reached, any
1111 blocks of non-compressible values indicated by code 253 are skipped,
1112 and the next element of command bytes is read and interpreted, until
1113 the end of the file or a code with value 252 is reached.
1114 @setfilename ignored