[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Reading from binary input streams??



Hi everyone,

I've got some big data files (mostly integers and floating point numbers,
but lots of them) and, for the sake of space efficiency, I'd like to store
them as binary rather than as ascii.

Unfortunately, as CLtL2 says, "common lisp currently specifies only a very
simple faciltiy for binary input [output]" known as read-byte or write-byte
respectively.

I have a binary file produced by Michael Berry's svdpack system for
singular value decomposition.

With Perl, one reads the data by saying:

#!/usr/local/bin/perl

$sizeofDouble =   8;
$sizeofLong   =   4;
$terms        = 374;
$docs         =  82;
$factors      =  10;

open(OUTFILE, "@ARGV[0]");

    print("\n\n\n");
    read(OUTFILE, $value, $sizeofLong);
    $value = unpack("l", $value);
    printf("Length of right s-vector:  %4d\n",  $value);
    read(OUTFILE, $value, $sizeofLong);
    $value = unpack("l", $value);
    printf("Krylov subspace dimension: %4d\n",  $value);
    read(OUTFILE, $value, $sizeofDouble);
    $value = unpack("d", $value);
    printf("Residual tolerance:       %g\n",  $value);

print("\n\n\n");
print("**************** Document Vectors **********************\n");
for($i = 0; $i < $docs; $i++) {
  print("\nDocument $i\n");

  for($j = 0; $j < $factors; $j++) {
    read(OUTFILE, $value, $sizeofDouble);
    $value = unpack("d", $value);

    printf("%4d %12.10f\n", $j, $value);
  }
}


but when I say

(with-open-file (istream "filename" :direction :input :element-type
  '(signed-byte 4)) (read-byte istream))

My system (CLISP) says "filename is not an integer file." I've tried
multiple values for i in (signed-byte i), but it still doesn't seem to work
the way the perl script does.

What do I do to read I this binary data? Thanks in advance.

-bruce


Bruce L. Lambert
Department of Pharmacy Administration
University of Illinois at Chicago
Phone:  (312) 996-2411
Fax:    (312) 996-3272
email:  lambertb@uic.edu