Added support for reading Gnumeric spreadsheet files.
[pspp-builds.git] / doc / files.texi
1 @node System and Portable Files
2 @chapter System Files and Portable Files
3
4 The commands in this chapter read, write, and examine system files and
5 portable files.
6
7 @menu
8 * APPLY DICTIONARY::            Apply system file dictionary to active file.
9 * EXPORT::                      Write to a portable file.
10 * GET::                         Read from a system file.
11 * GET DATA::                    Read from foreign files.
12 * IMPORT::                      Read from a portable file.
13 * MATCH FILES::                 Merge system files.
14 * SAVE::                        Write to a system file.
15 * SYSFILE INFO::                Display system file dictionary.
16 * XEXPORT::                     Write to a portable file, as a transformation.
17 * XSAVE::                       Write to a system file, as a transformation.
18 @end menu
19
20 @node APPLY DICTIONARY
21 @section APPLY DICTIONARY
22 @vindex APPLY DICTIONARY
23
24 @display
25 APPLY DICTIONARY FROM=@{'file-name',file_handle@}.
26 @end display
27
28 @cmd{APPLY DICTIONARY} applies the variable labels, value labels,
29 and missing values taken from a file to corresponding
30 variables in the active file.  In some cases it also updates the
31 weighting variable.
32
33 Specify a system file, portable file, or scratch file with a file name
34 string or as a file handle (@pxref{File Handles}).  The dictionary in the
35 file will be read, but it will not replace the active file dictionary.
36 The file's data will not be read.
37
38 Only variables with names that exist in both the active file and the
39 system file are considered.  Variables with the same name but different
40 types (numeric, string) will cause an error message.  Otherwise, the
41 system file variables' attributes will replace those in their matching
42 active file variables, as described below.
43
44 If a system file variable has a variable label, then it will replace the
45 active file variable's variable label.  If the system file variable does
46 not have a variable label, then the active file variable's variable
47 label, if any, will be retained.
48
49 If the active file variable is numeric or short string, then value
50 labels and missing values, if any, will be copied to the active file
51 variable.  If the system file variable does not have value labels or
52 missing values, then those in the active file variable, if any, will not
53 be disturbed.
54
55 Finally, weighting of the active file is updated (@pxref{WEIGHT}).  If
56 the active file has a weighting variable, and the system file does not,
57 or if the weighting variable in the system file does not exist in the
58 active file, then the active file weighting variable, if any, is
59 retained.  Otherwise, the weighting variable in the system file becomes
60 the active file weighting variable.
61
62 @cmd{APPLY DICTIONARY} takes effect immediately.  It does not read the
63 active
64 file.  The system file is not modified.
65
66 @node EXPORT
67 @section EXPORT
68 @vindex EXPORT
69
70 @display
71 EXPORT
72         /OUTFILE='file-name'
73         /UNSELECTED=@{RETAIN,DELETE@}
74         /DIGITS=n
75         /DROP=var_list
76         /KEEP=var_list
77         /RENAME=(src_names=target_names)@dots{}
78         /TYPE=@{COMM,TAPE@}
79         /MAP
80 @end display
81
82 The @cmd{EXPORT} procedure writes the active file dictionary and data to a
83 specified portable file or scratch file.
84
85 By default, cases excluded with FILTER are written to the
86 file.  These can be excluded by specifying DELETE on the UNSELECTED
87 subcommand.  Specifying RETAIN makes the default explicit.
88
89 Portable files express real numbers in base 30.  Integers are always
90 expressed to the maximum precision needed to make them exact.
91 Non-integers are, by default, expressed to the machine's maximum
92 natural precision (approximately 15 decimal digits on many machines).
93 If many numbers require this many digits, the portable file may
94 significantly increase in size.  As an alternative, the DIGITS
95 subcommand may be used to specify the number of decimal digits of
96 precision to write.  DIGITS applies only to non-integers.
97
98 The OUTFILE subcommand, which is the only required subcommand, specifies
99 the portable file or scratch file to be written as a file name string or
100 a file handle (@pxref{File Handles}).
101
102 DROP, KEEP, and RENAME follow the same format as the SAVE procedure
103 (@pxref{SAVE}).
104
105 The TYPE subcommand specifies the character set for use in the
106 portable file.  Its value is currently not used.
107
108 The MAP subcommand is currently ignored.
109
110 @cmd{EXPORT} is a procedure.  It causes the active file to be read.
111
112 @node GET
113 @section GET
114 @vindex GET
115
116 @display
117 GET
118         /FILE=@{'file-name',file_handle@}
119         /DROP=var_list
120         /KEEP=var_list
121         /RENAME=(src_names=target_names)@dots{}
122 @end display
123
124 @cmd{GET} clears the current dictionary and active file and
125 replaces them with the dictionary and data from a specified file.
126
127 The FILE subcommand is the only required subcommand.  Specify the system
128 file, portable file, or scratch file to be read as a string file name or
129 a file handle (@pxref{File Handles}).
130
131 By default, all the variables in a file are read.  The DROP
132 subcommand can be used to specify a list of variables that are not to be
133 read.  By contrast, the KEEP subcommand can be used to specify variable
134 that are to be read, with all other variables not read.
135
136 Normally variables in a file retain the names that they were
137 saved under.  Use the RENAME subcommand to change these names.  Specify,
138 within parentheses, a list of variable names followed by an equals sign
139 (@samp{=}) and the names that they should be renamed to.  Multiple
140 parenthesized groups of variable names can be included on a single
141 RENAME subcommand.  Variables' names may be swapped using a RENAME
142 subcommand of the form @samp{/RENAME=(A B=B A)}.
143
144 Alternate syntax for the RENAME subcommand allows the parentheses to be
145 eliminated.  When this is done, only a single variable may be renamed at
146 once.  For instance, @samp{/RENAME=A=B}.  This alternate syntax is
147 deprecated.
148
149 DROP, KEEP, and RENAME are executed in left-to-right order.  
150 Each may be present any number of times.  @cmd{GET} never modifies a
151 file on disk.  Only the active file read from the file
152 is affected by these subcommands.
153
154 @cmd{GET} does not cause the data to be read, only the dictionary.  The data
155 is read later, when a procedure is executed.
156
157 Use of @cmd{GET} to read a portable file or scratch file is a PSPP
158 extension.
159
160 @node GET DATA
161 @section GET DATA
162 @vindex GET DATA
163
164 @display
165 GET DATA /TYPE=gnm
166         /FILE=@{'file-name'@}
167         
168         /SHEET=@{NAME 'sheet-name', INDEX n@}
169         /CELLRANGE=@{RANGE 'range', FULL@}
170         /READNAMES=@{ON, OFF@}
171         /ASSUMEDVARWIDTH=n.
172 @end display
173
174 The @cmd{GET DATA} command is used to read files and other data sources 
175 created by other applications. 
176 When this command is executed, the current dictionary and active file are
177 replaced  with variables and data read from the specified source.
178 The TYPE subcommand is mandatory and determines the type of the file or source to read.
179 Currently @samp{gnm} is the only supported type.
180
181 @cindex Gnumeric
182 @cindex spreadsheet files
183 The @samp{gnm} type is used to read spreadsheet files created by 
184 Gnumeric (@url{http://gnumeric.org}).
185 With this type, the FILE subcommand must be used, to specify the
186 spreadsheet file to read.  
187 All other subcommands are optional.
188 The format of each variable is determined by the format of the spreadsheet 
189 cell containing the first datum for the variable.
190 If this cell is of string (text) format, then the width of the variable is
191 determined from the length of the string it contains, unless the 
192 ASSUMEDVARWIDTH subcommand is given.
193
194 The SHEET subcommand specifies the sheet within the spreadsheet file to read.
195 There are two forms of the SHEET subcommand.
196 In the first form,
197 @samp{/SHEET=name @var{sheet-name}}, the string @var{sheet-name} is the
198 name of the sheet to read.
199 In the second form, @samp{/SHEET=index @var{idx}}, @var{idx} is a
200 integer which is the index of the sheet to read.
201 The first sheet has the index 1.
202 If the SHEET subcommand is omitted, then the command will read the
203 first sheet in the file.
204
205 The CELLRANGE subcommand specifies the range of cells within the sheet to read.
206 If the subcommand is given as @samp{/CELLRANGE=FULL}, then the entire
207 sheet  is read.
208 To read only part of a sheet, use the form 
209 @samp{/CELLRANGE=range '@var{top-left-cell}:@var{bottom-right-cell}'}.
210 For example, the subcommand @samp{/CELLRANGE=range 'C3:P19'} reads 
211 columns C--P, and rows 3--19 inclusive.
212 If no CELLRANGE subcommand is given, then the entire sheet is read.
213
214 If @samp{/READNAMES=ON} is specified, then the contents of cells of
215 the first row are used as the names of the variables in which to store
216 the data from subsequent rows. 
217 If the READNAMES command is omitted, or if @samp{/READNAMES=OFF} is
218 used, then the variables  receive automatically assigned names.
219
220 The ASSUMEDVARWIDTH subcommand specifies the maximum width of string
221 variables read  from the file.
222 If omitted, the default value is determined from the length of the 
223 string in the first spreadsheet cell for each variable.
224
225
226 @node IMPORT
227 @section IMPORT
228 @vindex IMPORT
229
230 @display
231 IMPORT
232         /FILE='file-name'
233         /TYPE=@{COMM,TAPE@}
234         /DROP=var_list
235         /KEEP=var_list
236         /RENAME=(src_names=target_names)@dots{}
237 @end display
238
239 The @cmd{IMPORT} transformation clears the active file dictionary and
240 data and
241 replaces them with a dictionary and data from a system, portable file,
242 or scratch file.
243
244 The FILE subcommand, which is the only required subcommand, specifies
245 the portable file to be read as a file name string or a file handle
246 (@pxref{File Handles}).
247
248 The TYPE subcommand is currently not used.
249
250 DROP, KEEP, and RENAME follow the syntax used by @cmd{GET} (@pxref{GET}).
251
252 @cmd{IMPORT} does not cause the data to be read, only the dictionary.  The
253 data is read later, when a procedure is executed.
254
255 Use of @cmd{IMPORT} to read a system file or scratch file is a PSPP
256 extension.
257
258 @node MATCH FILES
259 @section MATCH FILES
260 @vindex MATCH FILES
261
262 @display
263 MATCH FILES
264         /@{FILE,TABLE@}=@{*,'file-name'@}
265         /RENAME=(src_names=target_names)@dots{}
266         /IN=var_name
267
268         /BY=var_list
269         /DROP=var_list
270         /KEEP=var_list
271         /FIRST=var_name
272         /LAST=var_name
273         /MAP
274 @end display
275
276 @cmd{MATCH FILES} merges one or more system, portable, or scratch files,
277 optionally
278 including the active file.  Cases with the same values for BY
279 variables are combined into a single case.  Cases with different
280 values are output in order.  Thus, multiple sorted files are
281 combined into a single sorted file based on the value of the BY
282 variables.  The results of the merge become the new active file.
283
284 Specify FILE with a system, portable, or scratch file as a file name
285 string or file handle
286 (@pxref{File Handles}), or with an asterisk (@samp{*}) to
287 indicate the current active file.  The files specified on FILE are
288 merged together based on the BY variables, or combined case-by-case if
289 BY is not specified.
290
291 Specify TABLE with a file to use it as a @dfn{table
292 lookup file}.  Cases in table lookup files are not used up after
293 they've been used once.  This means that data in table lookup files can
294 correspond to any number of cases in FILE files.  Table lookup files
295 correspond to lookup tables in traditional relational database systems.
296 If a table lookup file contains more than one case with a given set of
297 BY variables, only the first case is used.
298
299 Any number of FILE and TABLE subcommands may be specified.
300 Ordinarily, at least two FILE subcommands, or one FILE and at least
301 one TABLE, should be specified.  Each instance of FILE or TABLE can be
302 followed by any sequence of RENAME subcommands.  These have the same
303 form and meaning as the corresponding subcommands of @cmd{GET}
304 (@pxref{GET}), but apply only to variables in the given file.
305
306 Each FILE or TABLE may optionally be followed by an IN subcommand,
307 which creates a numeric variable with the specified name and format
308 F1.0.  The IN variable takes value 1 in a case if the given file
309 contributed a row to the merged file, 0 otherwise.  The DROP, KEEP,
310 and RENAME subcommands do not affect IN variables.
311
312 When more than one FILE or TABLE contains a variable with a given
313 name, those variables must all have the same type (numeric or string)
314 and, for string variables, the same width.  This rules applies to
315 variable names after renaming with RENAME; thus, RENAME can be used to
316 resolve conflicts.
317
318 FILE and TABLE must be specified at the beginning of the command, with
319 any RENAME or IN specifications immediately after the corresponding
320 FILE or TABLE.  These subcommands are followed by BY, DROP, KEEP,
321 FIRST, LAST, and MAP.
322
323 The BY subcommand specifies a list of variables that are used to match
324 cases from each of the files.  When TABLE or IN is used, BY is
325 required; otherwise, it is optional.  When BY is specified, all the
326 files named on FILE and TABLE subcommands must be sorted in ascending
327 order of the BY variables.  Variables belonging to files that are not
328 present for the current case are set to the system-missing value for
329 numeric variables or spaces for string variables.
330
331 The DROP and KEEP subcommands allow variables to be dropped from or
332 reordered within the new active file.  These subcommands have the same
333 form and meaning as the corresponding subcommands of @cmd{GET}
334 (@pxref{GET}).  They apply to the new active file as a whole, not to
335 individual input files.  The variable names specified on DROP and KEEP
336 are those after any renaming with RENAME.
337
338 The optional FIRST and LAST subcommands name variables that @cmd{MATCH
339 FILES} adds to the active file.  The new variables are numeric with
340 print and write format F1.0.  The value of the FIRST variable is 1 in
341 the first case with a given set of values for the BY variables, and 0
342 in other cases.  Similarly, the LAST variable is 1 in the last case
343 with a given of BY values, and 0 in other cases.
344
345 @cmd{MATCH FILES} may not be specified following @cmd{TEMPORARY}
346 (@pxref{TEMPORARY}) if the active file is used as an input source.
347
348 Use of portable or scratch files on @cmd{MATCH FILES} is a PSPP
349 extension.
350
351 @node SAVE
352 @section SAVE
353 @vindex SAVE
354
355 @display
356 SAVE
357         /OUTFILE=@{'file-name',file_handle@}
358         /UNSELECTED=@{RETAIN,DELETE@}
359         /@{COMPRESSED,UNCOMPRESSED@}
360         /PERMISSIONS=@{WRITEABLE,READONLY@}
361         /DROP=var_list
362         /KEEP=var_list
363         /VERSION=version
364         /RENAME=(src_names=target_names)@dots{}
365         /NAMES
366         /MAP
367 @end display
368
369 The @cmd{SAVE} procedure causes the dictionary and data in the active
370 file to
371 be written to a system file or scratch file.
372
373 OUTFILE is the only required subcommand.  Specify the system file or
374 scratch file to be written as a string file name or a file handle
375 (@pxref{File Handles}).
376
377 By default, cases excluded with FILTER are written to the system file.
378 These can be excluded by specifying DELETE on the UNSELECTED
379 subcommand.  Specifying RETAIN makes the default explicit.
380
381 The COMPRESS and UNCOMPRESS subcommand determine whether the saved
382 system file is compressed.  By default, system files are compressed.
383 This default can be changed with the SET command (@pxref{SET}).
384
385 The PERMISSIONS subcommand specifies permissions for the new system
386 file.  WRITEABLE, the default, creates the file with read and write
387 permission.  READONLY creates the file for read-only access.
388
389 By default, all the variables in the active file dictionary are written
390 to the system file.  The DROP subcommand can be used to specify a list
391 of variables not to be written.  In contrast, KEEP specifies variables
392 to be written, with all variables not specified not written.
393
394 Normally variables are saved to a system file under the same names they
395 have in the active file.  Use the RENAME subcommand to change these names.
396 Specify, within parentheses, a list of variable names followed by an
397 equals sign (@samp{=}) and the names that they should be renamed to.
398 Multiple parenthesized groups of variable names can be included on a
399 single RENAME subcommand.  Variables' names may be swapped using a
400 RENAME subcommand of the form @samp{/RENAME=(A B=B A)}.
401
402 Alternate syntax for the RENAME subcommand allows the parentheses to be
403 eliminated.  When this is done, only a single variable may be renamed at
404 once.  For instance, @samp{/RENAME=A=B}.  This alternate syntax is
405 deprecated.
406
407 DROP, KEEP, and RENAME are performed in left-to-right order.  They
408 each may be present any number of times.  @cmd{SAVE} never modifies
409 the active file.  DROP, KEEP, and RENAME only affect the system file
410 written to disk.
411
412 The VERSION subcommand specifies the version of the file format. Valid
413 versions are 2 and 3.  The default version is 3.  In version 2 system
414 files, variable names longer than 8 bytes will be truncated.  The two
415 versions are otherwise identical.
416
417 The NAMES and MAP subcommands are currently ignored.
418
419 @cmd{SAVE} causes the data to be read.  It is a procedure.
420
421 @node SYSFILE INFO
422 @section SYSFILE INFO
423 @vindex SYSFILE INFO
424
425 @display 
426 SYSFILE INFO FILE='file-name'.
427 @end display
428
429 @cmd{SYSFILE INFO} reads the dictionary in a system file and
430 displays the information in its dictionary.
431
432 Specify a file name or file handle.  @cmd{SYSFILE INFO} reads that file as
433 a system file and displays information on its dictionary.
434
435 @cmd{SYSFILE INFO} does not affect the current active file.
436
437 @node XEXPORT
438 @section XEXPORT
439 @vindex XEXPORT
440
441 @display
442 EXPORT
443         /OUTFILE='file-name'
444         /DIGITS=n
445         /DROP=var_list
446         /KEEP=var_list
447         /RENAME=(src_names=target_names)@dots{}
448         /TYPE=@{COMM,TAPE@}
449         /MAP
450 @end display
451
452 The @cmd{EXPORT} transformation writes the active file dictionary and
453 data to a specified portable file.
454
455 This transformation is a PSPP extension.
456
457 It is similar to the @cmd{EXPORT} procedure, with two differences:
458
459 @itemize
460 @item
461 @cmd{XEXPORT} is a transformation, not a procedure.  It is executed when
462 the data is read by a procedure or procedure-like command.
463
464 @item
465 @cmd{XEXPORT} does not support the UNSELECTED subcommand.
466 @end itemize
467
468 @xref{EXPORT}, for more information.
469
470 @node XSAVE
471 @section XSAVE
472 @vindex XSAVE
473
474 @display
475 XSAVE
476         /OUTFILE='file-name'
477         /@{COMPRESSED,UNCOMPRESSED@}
478         /PERMISSIONS=@{WRITEABLE,READONLY@}
479         /DROP=var_list
480         /KEEP=var_list
481         /VERSION=version
482         /RENAME=(src_names=target_names)@dots{}
483         /NAMES
484         /MAP
485 @end display
486
487 The @cmd{XSAVE} transformation writes the active file dictionary and
488 data to a system file or scratch file.  It is similar to the @cmd{SAVE}
489 procedure, with two differences:
490
491 @itemize
492 @item
493 @cmd{XSAVE} is a transformation, not a procedure.  It is executed when
494 the data is read by a procedure or procedure-like command.
495
496 @item
497 @cmd{XSAVE} does not support the UNSELECTED subcommand.
498 @end itemize
499
500 @xref{SAVE}, for more information.
501 @setfilename ignored