#!/usr/local/bin/perl                                                         
'di';                                                                         
'ig00';                                                                       
#                                                                             
#  Function:      Report size of objects in SCVDR data files                  
#  Organization:  MIT Center for Space Research                               
#  Author:        Peter G. Ford <pgf@space.mit.edu>                           
#  Date:          Wed Dec  7 23:11:39 EST 1994                                
#                                                                             
                                                                              
$verbose = shift(@ARGV) if $ARGV[0] eq '-v';                                  
                                                                              
@ARGV = ('-') unless $ARGV >= 0;                                              
                                                                              
for (@ARGV) {                                                                 
  /^-$/ || open(STDIN, $_) || die "$_: $!\n";                                 
  binmode(STDIN);                                                             
  &ScanFile($_);                                                              
  close(STDIN);                                                               
}                                                                             
                                                                              
sub PrintTitle {                                                              
  print "--Keywords--  ---Header----  ---------Data----------    Total\n";    
  print "Length Lines  Offset Length  Offset   Length Records     Size\n";    
  undef($verbose);                                                            
}                                                                             
                                                                              
sub ScanFile {                                                                
  local($file,$off,$off0,$nrec,$nbyte,$sw) = shift;                           
                                                                              
  read(STDIN,$_,20) == 20 || die "$file: $!\n";                               
  /^CCSD1Z0000010*(\d+)$/ || printf STDERR "$file: bad SFDU: $_\n";           
                                                                              
  while (1) {                                                                 
    $off = tell(STDIN);                                                       
    read(STDIN,$_,20) == 20 || die "$file: $!\n";                             
    if (/^NJPL1K00KL000*(\d+)$/) {                                            
      read(STDIN,$_,$1) == $1 || die "$file: $!\n";                           
      &PrintTitle if $verbose;                                                
      printf "%6d %5d", $1+20, 0+split(/\r\n/);                               
      ($off0,$nrec,$nbyte,$sw) = ($off+$1+20,0,0,1);                          
    } elsif (/^CCSD1R0000030*(\d+)$/) {                                       
      read(STDIN,$_,$1) == $1 || die "$file: $!\n";                           
      last if /^DELIMITER=EMARKER/;                                           
      ($off0,$nrec,$nbyte,$sw) = ($off+$1+20,0,0,0);                          
    } elsif (/^NJPL1I(\d{6})0*(\d+)$/) {                                      
      read(STDIN,$_,$2) == $2 || die "$file: $!\n";                           
      $nrec++;                                                                
      $nbyte += 20+$2;                                                        
      last if $1 == 4;                                                        
      printf " %7d %6d", $off, $nbyte if $sw;                                 
    } else {                                                                  
      die "$file $_ unknown\n";                                               
    }                                                                         
  }                                                                           
                                                                              
  printf " %7d %6d %7d %8d %7d", $off0, $nbyte, 0, 0, 0 if $sw;               
  printf " %7d %8d %7d", $off0, $nbyte, $nrec unless $sw;                     
  $file =~ s|^.*/([^/]+)$|\1|;                                                
  printf " %8d  %s\n", (stat(STDIN))[7], $file;                               
}                                                                             
                                                                              
.00;                                                                          
                                                                              
'di                                                                           
.nr nl 0-1                                                                    
.nr % 0                                                                       
'; __END__                                                                    
.\" --------------------------------------------------------------------      
.TH scvdrscn.pl 1 "12/01/94" "CSR scvdrscn.pl 1.1" "Perl Script"              
.\" --------------------------------------------------------------------      
.SH NAME                                                                      
scvdrscn.pl \- report contents of Magellan SCVDR data files                   
.\" --------------------------------------------------------------------      
.SH SYNOPSIS                                                                  
.B scvdrscn.pl                                                                
[\c                                                                           
.BR \-v ]                                                                     
.RI [ file                                                                    
.RI [ file                                                                    
\&...]]                                                                       
.\" --------------------------------------------------------------------      
.SH DESCRIPTION                                                               
This                                                                          
.IR perl (1)                                                                  
script reads one or more Magellan SCVDR data files and reports their          
contents to the standard output. If none is specified,                        
.I scvdrscn.pl                                                                
reads a single file from the standard input stream.                           
.\" --------------------------------------------------------------------      
.SH OPTIONS                                                                   
.TP 8                                                                         
.B \-v                                                                        
prefix the list with a 2-line header.                                         
.\" --------------------------------------------------------------------      
.SH EXAMPLE                                                                   
SCVDR data files consist of three sections: a keyword label, followed         
by a fixed-length binary header, followed by a varying-length data            
section. For instance, the following command lists all orbit 376 files        
on the SCVDRCD volume mounted on                                              
.IR /cdrom .                                                                  
.LP                                                                           
.RS 0                                                                         
.nf                                                                           
$ scvdrscn.pl -v /cdrom/*/*00376.1                                            
--Keywords--\0\0---Header----\c                                               
\0\0---------Data----------\0\0\0\0Total                                      
Length\0Lines\0\0Offset\0Length\c                                             
\0\0Offset\0\0\0Length\0Records\0\0\0Length                                   
\0\0\0374\0\0\0\014\0\0\0\0\0394\0\0\0\0\072\0\0\0\0\0558\c                   
\0\0\0786388\0\0\0\0\0712\0\0\0812500\0\0anf00376.1                           
\0\0\0374\0\0\0\014\0\0\0\0\0394\0\0\0\0\092\0\0\0\0\0574\c                   
\0\0\0630720\0\0\0\02628\0\0\0650000\0\0edf00376.1                            
\0\0\0308\0\0\0\011\0\0\0\0\0328\0\0\0\0\044\0\0\0\0\0458\c                   
\0\04837288\0\0\0\0\0168\0\04842500\0\0gmf00376.1                             
\0\0\0372\0\0\0\014\0\0\0\0\0392\0\0\0\0\072\0\0\0\0\0550\c                   
\0\0\0150944\0\0\0\0\0712\0\0\0162500\0\0nff00376.1                           
\0\0\0350\0\0\0\013\0\0\0\0\0370\0\0\0\0280\0\0\0\0\0\0\00\c                  
\0\0\0\0\0\0\0\00\0\0\0\0\0\0\00\0\0\0\032500\0\0ohf00376.1                   
\0\0\0374\0\0\0\014\0\0\0\0\0394\0\0\0\0\060\0\0\0\0\0542\c                   
\0\0\0587296\0\0\0\0\0609\0\0\0617500\0\0oif00376.1                           
\0\0\0374\0\0\0\014\0\0\0\0\0394\0\0\0\0\060\0\0\0\0\0542\c                   
\0\07940104\0\0\0\07343\0\07962500\0\0sif00376.1                              
.RE                                                                           
.LP                                                                           
Lengths and offsets are in bytes and offsets are relative to the start        
of the file (byte 0). The keyword section is counted in lines,                
delimited by CR/LF pairs. Binary records in the data section are of           
varying length and are delimited by standard CCSD Type/Length/Value           
labels.                                                                       
.LP                                                                           
Orbit header files (OHF) omit the data section. The remaining file            
types also contain short delimiter sections before and after the data         
section.  All files are padded with '^' characters to a multiple of           
32500 bytes.                                                                  
.\"                                                                           
--------------------------------------------------------------------          
.SH FILES                                                                     
.ta \w'gmf\fInnnnn.v\fPnn'u                                                   
anf\fInnnnn.v\fP	Altimetry Inversion File                                     
.br                                                                           
edf\fInnnnn.v\fP	Emissivity File                                              
.br                                                                           
nff\fInnnnn.v\fP	Altimetry Inversion Fit File                                 
.br                                                                           
ohf\fInnnnn.v\fP	Orbit Header File                                            
.br                                                                           
oif\fInnnnn.v\fP	Oblique Sinusoidal Image File                                
.br                                                                           
sif\fInnnnn.v\fP	Sinusoidal Image File                                        
.\" --------------------------------------------------------------------      
.SH AUTHOR                                                                    
Peter G. Ford, MIT Center for Space Research <pgf@space.mit.edu>, with        
acknowledgements to Daniel Smith <dls@netcom.com> for figuring out how        
to let perl and troff/nroff coexist peacefully in the same file.              
.\" --------------------------------------------------------------------      
.SH SEE ALSO                                                                  
Simpson, R.A., M.J. Maurer, and E. Holmann,                                   
.I                                                                            
Stanford Magellan Data Processing System,                                     
in process.                                                                   
.LP                                                                           
.BR SU-MGN-SCVDR ,                                                            
.I                                                                            
Surface Characteristics Vector Data Record Software Interface                 
.IR Specification ,                                                           
Simpson, R.A., Twicken, J.D., and Maurer, M.J.,                               
Center for Radar Astronomy, Stanford University, v 1.0,                       
October 1, 1992.  Copies of this document exist in the                        
.I document                                                                   
directory of all SCVDRCD volumes, in ASCII text as                            
.I scvdr.txt                                                                  
and in PostScript as                                                          
.IR scvdr.ps .                                                                
.\" --------------------------------------------------------------------      
