#!/usr/local/bin/perl #open input file for reading #open(FIZZLE,"unzip -p /data/popdata/usa/census/1970/st23a4cp.zip |") #open(FIZZLE,"unzip -p /work/econ/nbrooks/outmove1.1.zip |") open(FIZZLE,"ST35B4CP") || die "Can't do it\n"; $debug=1; open(OUTPUT,"1970-4B-WI") || die "Can't open output file"; print "\n\n"; $foffset=0; $nblocks=0; $nrecs=0; while( ! eof(FIZZLE) ) { read(FIZZLE,$blklen,4); #grab the block size $blklen=unpack("S",$blklen); $blokread=4; while($blokread < $blklen){ $cumlen=0; read(FIZZLE,$reclen,6); ($reclen,$junk,$st_codes)=unpack("S3",$reclen); $a1=read(FIZZLE,$inbuf,$st_codes); $a2=read(FIZZLE,$bytepairs,($reclen-(6+$st_codes))); @byteary=unpack("C*",$bytepairs); $i=0; while( $i < $#byteary){ $nfill=$byteary[$i]; $rbyte=$byteary[$i+1]; $zerofill=$rbyte%2; $dbytes = $rbyte >> 1; ($data,$inbuf)=unpack("a$dbytes a*", $inbuf); if ($zerofill eq 1) { $fill= "\xf0" x $nfill ; } else { $fill = "\x40" x $nfill ; } $out=$data.$fill; $len=length($out); $cumlen=$len+$cumlen; print OUTPUT $data.$fill; $i=$i+2; } if ($cumlen lt 2040) { $cumlen=$cumlen+length($inbuf); print OUTPUT $inbuf; } if ($debug ==1) { print "blklen=".$blklen." ,reclen=".$reclen."\n"; } $blokread=$blokread+$reclen; ++$nrecs; } ++$nblocks; print "Read ".$nblocks." blocks and processed ".$nrecs." Records\n"; }