3f351b23b267005bf1d618b732d0b9127fa63420
[pspp-builds.git] / doc / portable-file-format.texi
1 @node Portable File Format, Data File Format, Configuration, Top
2 @appendix Portable File Format
3
4 These days, most computers use the same internal data formats for
5 integer and floating-point data, if one ignores little differences like
6 big- versus little-endian byte ordering.  However, occasionally it is
7 necessary to exchange data between systems with incompatible data
8 formats.  This is what portable files are designed to do.
9
10 @strong{Please note:} Although all of the following information is
11 correct, as far as the author has been able to ascertain, it is gleaned
12 from examination of ASCII-formatted portable files only, so some of it
13 may be incorrect in the general case.
14
15 @menu
16 * Portable File Characters::    
17 * Portable File Structure::     
18 * Portable File Header::        
19 * Version and Date Info Record::  
20 * Identification Records::      
21 * Variable Count Record::       
22 * Case Weight Variable Record::  
23 * Variable Records::            
24 * Value Label Records::         
25 * Portable File Data::          
26 @end menu
27
28 @node Portable File Characters, Portable File Structure, Portable File Format, Portable File Format
29 @section Portable File Characters
30
31 Portable files are arranged as a series of lines of exactly 80
32 characters each.  Each line is terminated by a carriage-return,
33 line-feed sequence ``new-lines'').  New-lines are only used to avoid
34 line length limits imposed by some OSes; they are not meaningful.
35
36 The file must be terminated with a @samp{Z} character.  In addition, if
37 the final line in the file does not have exactly 80 characters, then it
38 is padded on the right with @samp{Z} characters.  (The file contents may
39 be in any character set; the file contains a description of its own
40 character set, as explained in the next section.  Therefore, the
41 @samp{Z} character is not necessarily an ASCII @samp{Z}.)
42
43 For the rest of the description of the portable file format, new-lines
44 and the trailing @samp{Z}s will be ignored, as if they did not exist,
45 because they are not an important part of understanding the file
46 contents.
47
48 @node Portable File Structure, Portable File Header, Portable File Characters, Portable File Format
49 @section Portable File Structure
50
51 Every portable file consists of the following records, in sequence:
52
53 @itemize @bullet
54
55 @item
56 File header.
57
58 @item
59 Version and date info.
60
61 @item
62 Product identification.
63
64 @item
65 Subproduct identification (optional).
66
67 @item
68 Variable count.
69
70 @item
71 Case weight variable (optional).
72
73 @item
74 Variables.  Each variable record may optionally be followed by a
75 missing value record and a variable label record.
76
77 @item
78 Value labels (optional).
79
80 @item
81 Data.
82 @end itemize
83
84 Most records are identified by a single-character tag code.  The file
85 header and version info record do not have a tag.
86
87 Other than these single-character codes, there are three types of fields
88 in a portable file: floating-point, integer, and string.  Floating-point
89 fields have the following format:
90
91 @itemize @bullet
92
93 @item
94 Zero or more leading spaces.
95
96 @item
97 Optional asterisk (@samp{*}), which indicates a missing value.  The
98 asterisk must be followed by a single character, generally a period
99 (@samp{.}), but it appears that other characters may also be possible.
100 This completes the specification of a missing value.
101
102 @item
103 Optional minus sign (@samp{-}) to indicate a negative number.
104
105 @item
106 A whole number, consisting of one or more base-30 digits: @samp{0}
107 through @samp{9} plus capital letters @samp{A} through @samp{T}.
108
109 @item
110 Optional fraction, consisting of a radix point (@samp{.}) followed by
111 one or more base-30 digits.
112
113 @item
114 Optional exponent, consisting of a plus or minus sign (@samp{+} or
115 @samp{-}) followed by one or more base-30 digits.
116
117 @item
118 A forward slash (@samp{/}).
119 @end itemize
120
121 Integer fields take a form identical to floating-point fields, but they
122 may not contain a fraction.
123
124 String fields take the form of a integer field having value @var{n},
125 followed by exactly @var{n} characters, which are the string content.
126
127 @node Portable File Header, Version and Date Info Record, Portable File Structure, Portable File Format
128 @section Portable File Header
129
130 Every portable file begins with a 464-byte header, consisting of a
131 200-byte collection of vanity splash strings, followed by a 256-byte
132 character set translation table, followed by an 8-byte tag string.
133
134 The 200-byte segment is divided into five 40-byte sections, each of
135 which represents the string @code{@var{charset} SPSS PORT FILE} in a
136 different character set encoding, where @var{charset} is the name of
137 the character set used in the file, e.g.@: @code{ASCII} or
138 @code{EBCDIC}.  Each string is padded on the right with spaces in its
139 respective character set.
140
141 It appears that these strings exist only to inform those who might view
142 the file on a screen, and that they are not parsed by SPSS products.
143 Thus, they can be safely ignored.  For those interested, the strings are
144 supposed to be in the following character sets, in the specified order:
145 EBCDIC, 7-bit ASCII, CDC 6-bit ASCII, 6-bit ASCII, Honeywell 6-bit
146 ASCII.
147
148 The 256-byte segment describes a mapping from the character set used in
149 the portable file to an arbitrary character set having characters at the
150 following positions:
151
152 @table @asis
153 @item 0--60
154
155 Control characters.  Not important enough to describe in full here.
156
157 @item 61--63
158
159 Reserved.
160
161 @item 64--73
162
163 Digits @samp{0} through @samp{9}.
164
165 @item 74--99
166
167 Capital letters @samp{A} through @samp{Z}. 
168
169 @item 100--125
170
171 Lowercase letters @samp{a} through @samp{z}.
172
173 @item 126
174
175 Space.
176
177 @item 127--130
178
179 Symbols @code{.<(+}
180
181 @item 131
182
183 Solid vertical pipe.
184
185 @item 132--142
186
187 Symbols @code{&[]!$*);^-/}
188
189 @item 143
190
191 Broken vertical pipe.
192
193 @item 144--150
194
195 Symbols @code{,%_>}?@code{`:}   @c @code{?} is an inverted question mark
196
197 @item 151
198
199 British pound symbol.
200
201 @item 152--155
202
203 Symbols @code{@@'="}.
204
205 @item 156
206
207 Less than or equal symbol.
208
209 @item 157
210
211 Empty box.
212
213 @item 158
214
215 Plus or minus.
216
217 @item 159
218
219 Filled box.
220
221 @item 160
222
223 Degree symbol.
224
225 @item 161
226
227 Dagger.
228
229 @item 162
230
231 Symbol @samp{~}.
232
233 @item 163
234
235 En dash.
236
237 @item 164
238
239 Lower left corner box draw.
240
241 @item 165
242
243 Upper left corner box draw.
244
245 @item 166
246
247 Greater than or equal symbol.
248
249 @item 167--176
250
251 Superscript @samp{0} through @samp{9}.
252
253 @item 177
254
255 Lower right corner box draw.
256
257 @item 178
258
259 Upper right corner box draw.
260
261 @item 179
262
263 Not equal symbol.
264
265 @item 180
266
267 Em dash.
268
269 @item 181
270
271 Superscript @samp{(}.
272
273 @item 182
274
275 Superscript @samp{)}.
276
277 @item 183
278
279 Horizontal dagger (?).
280
281 @item 184--186
282
283 Symbols @samp{@{@}\}.
284 @item 187
285
286 Cents symbol.
287
288 @item 188
289
290 Centered dot, or bullet.
291
292 @item 189--255
293
294 Reserved.
295 @end table
296
297 Symbols that are not defined in a particular character set are set to
298 the same value as symbol 64; i.e., to @samp{0}.
299
300 The 8-byte tag string consists of the exact characters @code{SPSSPORT}
301 in the portable file's character set, which can be used to verify that
302 the file is indeed a portable file.
303
304 @node Version and Date Info Record, Identification Records, Portable File Header, Portable File Format
305 @section Version and Date Info Record
306
307 This record does not have a tag code.  It has the following structure:
308
309 @itemize @bullet
310 @item
311 A single character identifying the file format version.  The letter A
312 represents version 0, and so on.
313
314 @item
315 An 8-character string field giving the file creation date in the format
316 YYYYMMDD.
317
318 @item
319 A 6-character string field giving the file creation time in the format
320 HHMMSS.
321 @end itemize
322
323 @node Identification Records, Variable Count Record, Version and Date Info Record, Portable File Format
324 @section Identification Records
325
326 The product identification record has tag code @samp{1}.  It consists of
327 a single string field giving the name of the product that wrote the
328 portable file.
329
330 The subproduct identification record has tag code @samp{3}.  It
331 consists of a single string field giving additional information on the
332 product that wrote the portable file.
333
334 @node Variable Count Record, Case Weight Variable Record, Identification Records, Portable File Format
335 @section Variable Count Record
336
337 The variable count record has tag code @samp{4}.  It consists of two
338 integer fields.  The first contains the number of variables in the file
339 dictionary.  The purpose of the second is unknown; it contains the value
340 161 in all portable files examined so far.
341
342 @node Case Weight Variable Record, Variable Records, Variable Count Record, Portable File Format
343 @section Case Weight Variable Record
344
345 The case weight variable record is optional.  If it is present, it
346 indicates the variable used for weighting cases; if it is absent,
347 cases are unweighted.  It has tag code @samp{6}.  It consists of a
348 single string field that names the weighting variable.
349
350 @node Variable Records, Value Label Records, Case Weight Variable Record, Portable File Format
351 @section Variable Records
352
353 Each variable record represents a single variable.  Variable records
354 have tag code @samp{7}.  They have the following structure:
355
356 @itemize @bullet
357
358 @item
359 Width (integer).  This is 0 for a numeric variable, and a number between 1
360 and 255 for a string variable.
361
362 @item
363 Name (string).  1--8 characters long.  Must be in all capitals.
364
365 @item
366 Print format.  This is a set of three integer fields:
367
368 @itemize @minus
369
370 @item
371 Format type (@pxref{Variable Record}).
372
373 @item
374 Format width.  1--40.
375
376 @item
377 Number of decimal places.  1--40.
378 @end itemize
379
380 @item
381 Write format.  Same structure as the print format described above.
382 @end itemize
383
384 Each variable record can optionally be followed by a missing value
385 record, which has tag code @samp{8}.  A missing value record has one
386 field, the missing value itself (a floating-point or string, as
387 appropriate).  Up to three of these missing value records can be used.
388
389 There is also a record for missing value ranges, which has tag code
390 @samp{B}.  It is followed by two fields representing the range, which
391 are floating-point or string as appropriate.  If a missing value range
392 is present, it may be followed by a single missing value record.
393
394 Tag codes @samp{9} and @samp{A} represent @code{LO THRU @var{x}} and
395 @code{@var{x} THRU HI} ranges, respectively.  Each is followed by a
396 single field representing @var{x}.  If one of the ranges is present, it
397 may be followed by a single missing value record.
398
399 In addition, each variable record can optionally be followed by a
400 variable label record, which has tag code @samp{C}.  A variable label
401 record has one field, the variable label itself (string).
402
403 @node Value Label Records, Portable File Data, Variable Records, Portable File Format
404 @section Value Label Records
405
406 Value label records have tag code @samp{D}.  They have the following
407 format:
408
409 @itemize @bullet
410 @item
411 Variable count (integer).
412
413 @item
414 List of variables (strings).  The variable count specifies the number in
415 the list.  Variables are specified by their names.  All variables must
416 be of the same type (numeric or string).
417
418 @item
419 Label count (integer).
420
421 @item
422 List of (value, label) tuples.  The label count specifies the number of
423 tuples.  Each tuple consists of a value, which is numeric or string as
424 appropriate to the variables, followed by a label (string).
425 @end itemize
426
427 @node Portable File Data,  , Value Label Records, Portable File Format
428 @section Portable File Data
429
430 The data record has tag code @samp{F}.  There is only one tag for all
431 the data; thus, all the data must follow the dictionary.  The data is
432 terminated by the end-of-file marker @samp{Z}, which is not valid as the
433 beginning of a data element.
434
435 Data elements are output in the same order as the variable records
436 describing them.  String variables are output as string fields, and
437 numeric variables are output as floating-point fields.
438 @setfilename ignored