[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: PSPP-BUG: About http://pspp.benpfaff.org/conversion.html
From: |
Ben Pfaff |
Subject: |
Re: PSPP-BUG: About http://pspp.benpfaff.org/conversion.html |
Date: |
Thu, 29 Jul 2010 15:43:37 -0700 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/23.2 (gnu/linux) |
Jack Burris <address@hidden> writes:
> However, I noticed you have a web application that takes a .SAV to text:
>
> http://pspp.benpfaff.org/conversion.html
>
> I'm wondering if it might be possible to take a look at the code for
> this? The main problem has been getting a good file specification on
> the .POR, .DTA, and .SAV formats. My thinking is perhaps I can suss
> some of this out from the code others have used to parse these files
> into other formats.
We have detailed specifications for both .por and .sav formats.
The most recent can be found here:
http://pspp.benpfaff.org/~blp/pspp-master/20100729040501/dev-guide/html_node/Portable-File-Format.html#Portable-File-Format
http://pspp.benpfaff.org/~blp/pspp-master/20100729040501/dev-guide/html_node/System-File-Format.html#System-File-Format
The code for the web application is just the following, although
you have to have the PSPP Perl extension installed on the
system. The Perl extension is packaged as part of PSPP, which
you can download from various places, e.g. see
http://www.gnu.org/software/pspp/get.html
--8<--------------------------cut here-------------------------->8--
#! /usr/bin/perl
use strict;
use warnings;
use CGI;
use PSPP;
use Digest::MD5;
$CGI::POST_MAX = 10 * 1024 * 1024; # max 10 MB posts
my $q = new CGI;
if ($q->param('file')) {
my $temp = $q->upload ('file');
my $ctx = Digest::MD5->new;
$ctx->addfile ($temp);
my $digest = $ctx->hexdigest;
my $file = "/home/www-pspp/input/$digest.sav";
seek ($temp, 0, 0);
open (FILE, '>', $file);
my $s;
while (sysread ($temp, $s, 4096)) {
syswrite (FILE, $s);
}
close FILE;
my $reader = PSPP::Reader->open ($file);
my $dict = $reader->get_dict ();
print "Content-type: text/plain\r\n\r\n";
while (my @case = $reader->get_next_case ()) {
my @values;
for (my $i = 0; $i < $dict->get_var_cnt (); $i++) {
push (@values, PSPP::format_value ($case[$i], $dict->get_var ($i)));
}
print join (',', @values), "\n";
}
}
--
A bicycle is one of the world's beautiful machines, beautiful machines
are art, and art is civilisation, good living, and balm to the soul.
--Elisa Francesca Roselli