import cds.image.*;
import java.io.*;
import java.util.*;

/**
 * Simple class to test the CDS image package.
 * Usage: java ImageDemo x.fits.H
 *
 * @version 1.0 22 jun 00 Creation
 * @author P.Fernique [CDS]
 */
public class ImageDemo {
      
   // To read fits header
   static void readFitsHeader(DataInputStream dis) throws Exception {
      byte [] line = new byte[80];
      do {
         dis.readFully(line);
      } while(line[0]!='E' || line[1]!='N' || line[2]!='D' || line[3]!=' ');
   }
   
   // The main method to test it
   static public void main(String [] arg) {
       
   
      try {
         // Open the first arg as a file
         DataInputStream dis = new DataInputStream( new FileInputStream(arg[0]));
         
         // read the FITS header
         System.out.println("Reading Fits header...");
         readFitsHeader(dis);
         
         // Parse the file
         System.out.println("Uncompressing...");
         byte [] pixels=Hdecomp.decomp( (InputStream)dis );
         System.out.println("I've uncompressed "+pixels.length+" bytes");
                  
      } catch( Exception e ) {
         System.err.println("There is a problem: "+e);
         e.printStackTrace();
      }
   }
}


