5 do 'pspp-vers.pl' || die "No version set";
9 PSPP - Perl extension to PSPP
17 PSPP:: provides an interface to the libraries used by pspp to create
27 XSLoader::load('PSPP', $PSPP::VERSION);
31 =head1 PROGRAMMER'S INTERFACE
33 The subroutines in this package return zero or unref on error.
34 When errors occur, a string describing the error is written
42 use constant { SYSMIS => -(POSIX::DBL_MAX),
43 PERL_EPOCH => 12219379200 # Number of seconds between
55 =head2 PSPP::Dict::new
57 Creates a new dictionary. This returned dictionary will be empty.
58 Returns undef on failure.
60 =head3 set_documents ($string)
62 Sets the documents (comments) to C<string>.
64 =head3 add_document ($string)
66 Appends C<string> to the documents.
68 =head3 clear_documents ()
70 Removes all documents.
72 =head3 set_weight ($var)
74 Sets the weighting variable to C<var>.
81 my $self = pxs_dict_new ();
82 bless ($self, $class);
90 Returns a variable from a dictionary
98 my $var = pxs_get_variable ($dict, $idx);
102 bless ($var, "PSPP::Var");
114 Contains constants used to denote variable format types.
115 The identifiers are the same as those used in pspp to denote formats.
116 For example C<PSPP::Fmt::F> defines floating point format, and
117 C<PSPP::Fmt::A> denotes string format.
121 # These must correspond to the values in src/data/format.h
167 =head3 new ($dict, $name, %input_fmt)
169 Creates and returns a new variable in the dictionary C<dict>. The
170 new variable will have the name C<name>.
171 The input format is set by the C<input_fmt> parameter
173 By default, the write and print formats are the same as the input format.
174 The write and print formats may be changed (See L</set_write_format>),
175 L</set_print_format>). The input format may not be changed after
176 the variable has been created.
177 If the variable cannot be created, undef is returned.
187 my $self = pxs_dict_create_var ($dict, $name, \%format);
190 bless ($self, $class);
197 =head3 set_label ($label)
199 Sets the variable label to C<label>.
206 =head3 set_write_format (%fmt)
208 Sets the write format to C<fmt>. <fmt> is a hash containing the keys:
214 A constant denoting the format type. See L</PSPP::Fmt>.
218 An integer denoting the number of decimal places for the format.
222 An integer denoting the number of width of the format.
226 On error the subroutine returns zero.
234 pxs_set_write_format ($var, \%format);
239 =head3 set_print_format (%fmt)
241 Sets the print format to C<fmt>.
242 On error the subroutine returns zero.
250 pxs_set_print_format ($var, \%format);
255 =head3 set_output_format (%fmt)
257 Sets the write and print formats to C<fmt>. This is the same as
258 calling set_write_format followed by set_print_format.
259 On error the subroutine returns zero.
264 sub set_output_format
268 pxs_set_output_format ($var, \%format);
273 =head3 clear_value_labels ()
275 Removes all value labels from the variable.
282 =head3 add_value_label ($key, $label)
284 Adds the value label C<label> to the variable for the value C<key>.
285 On error the subroutine returns zero.
287 =head3 add_value_labels (@array)
298 while ( @li = each %values )
300 if ( $var->add_value_label ($li[0], "$li[1]") )
311 =head3 set_value_labels ($key, $value)
313 C<Set_value_labels> is identical to calling L</clear_value_labels>
314 followed by L</add_value_labels>.
315 On error the subroutine returns zero.
323 $self->clear_value_labels () ;
324 $self->add_value_labels (%labels);
329 =head3 set_missing_values ($val1 [, $val2[, $val3] ])
331 Sets the missing values for the variable.
332 No more than three missing values may be specified.
337 package PSPP::Sysfile;
343 =head3 new ($filename, $dict [,%opts])
345 Creates a new system file from the dictionary C<dict>. The file will
346 be written to the file called C<filename>.
347 C<opt>, if specified, is a hash containing optional parameters for the
348 system file. Currently, the only supported parameter is
349 C<compress>. If C<compress> is non zero, then the system file written
350 will be in the compressed format.
351 On error, undef is returned.
354 =head3 append_case (@case)
356 Appends a case to the system file.
357 C<Case> is an array of scalars, each of which are the values of
358 the variables in the dictionary corresponding to the system file.
359 The special value C<PSPP::SYSMIS> may be used to indicate that a value
361 If the array contains less elements than variables in the dictionary,
362 remaining values will be set to system missing.
369 my $filename = shift;
373 my $self = pxs_create_sysfile ($filename, $dict, $opts);
377 bless ($self, $class);
386 Closes the system file.
388 This subroutine closes the system file and flushes it to disk. No
389 further cases may be written once the file has been closed.
390 The system file will be automatically closed when it goes out of scope.
394 package PSPP::Reader;
399 my $filename = shift;
401 my $self = pxs_open_sysfile ($filename);
405 bless ($self, $class);
415 my $dict = pxs_get_dict ($reader);
417 bless ($dict, "PSPP::Dict");
430 John Darrington, E<lt>john@darrington.wattle.id.auE<gt>
432 =head1 COPYRIGHT AND LICENSE
434 Copyright (C) 2007 by Free Software Foundation
436 This program is free software; you can redistribute it and/or
437 modify it under the terms of the GNU General Public License as
438 published by the Free Software Foundation; either version 2 of the
439 License, or (at your option) any later version.
441 This program is distributed in the hope that it will be useful, but
442 WITHOUT ANY WARRANTY; without even the implied warranty of
443 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
444 General Public License for more details.
446 You should have received a copy of the GNU General Public License
447 along with this program; if not, write to the Free Software
448 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA