From: Bruce L. Lambert, Ph.D.
Subject: reading and writing to/from binary streams
Date: 
Message-ID: <568dek$4lcc@piglet.cc.uic.edu>
Hi everyone,

I've got some big data files (mostly integers and floating point numbers,
but lots of them) and, for the sake of 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
#
# Reads the SVDPACKC lav2 binary output file of singular vectors
# (Uses zero-based indexing for output)
#
#    Usage:   check outFile
#

$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."

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

-bruce