Viewing contents of file '../idllib/uit/pro/compress.pro'
pro compress,name, OUTSIZE = outsize, OUTNAME = outname, BOXAVE = boxave
;+
; NAME:
;   COMPRESS
; PURPOSE:
;   Create a compressed image on disk.   Combines the function of 
;       STRD, HREBIN, and STWRT.
; CALLING SEQUENCE: 
;   compress, name, OUTSIZE = outsize, [ OUTNAME = , BOXAVE = ]
; INPUTS:
;   name - scalar string giving the name of the SDAS file containing the
;          big image.
; OPTIONAL KEYWORD INPUT:
;   OUTSIZE - two element vector giving the size of the output image to be
;         created.    The default output size is 512 by 512.
;   OUTNAME - scalar string giving the name of the output image file
;             If not supplied, the default is created by
;               (1) Using the first 7 letters of the input file name
;               (2) Appending a 'G' for geomed images, and a 'Q13'
;                   for QUICK13 images
;               (3) Appending a 'C' (for compressed image)
;   BOXAVE -  if this keyword is set and non-zero then the compress image is
;             created using the BOXAVE function rather than the REBIN function.
;             BOXAVE always computes intermediate steps using REAL*4 
;             arithmetic and so is much slower, but should be used when
;             photometric accuracy is needed.
; EXAMPLE:
;    A 2048 x 2048 UIT image 'FUV0537Q13E' exists on the default directory.
;    Create a 512 x 512 compressed image named FUV0537Q13C
;
;              IDL> COMPRESS, 'FUV0537Q13E'
; SIDE EFFECTS:
;    A new SDAS image file is created on disk
; REVISION HISTORY
;     Written   W. Landsman           October 1991
;     Fixed up for non-UIT images    W. Landsman         February, 1991
;-
On_error,2

if N_params() EQ 0 then begin
     print,'Syntax: compress, name, [OUTSIZE = , OUTNAME = ]
     return
endif

test = findfile(name+'.hhh',count=n)
if n EQ 0 then message,'Unable to find '+spec_dir(name)

if not keyword_set( OUTSIZE ) then outsize = [ 512, 512]

strd,im,h,name

if keyword_set(BOXAVE) then begin
        in_size = sxpar( h, 'NAXIS1') 
        box = in_size / outsize(0) 
        hboxave, im, h, box

endif else hrebin, im, h, OUT = outsize

fdecomp,name,disk,dir,fname,ext
telescop = sxpar(h,'TELESCOP')
if  !ERR EQ -1 then telescop = ' '
if telescop EQ 'UIT' then outname = strmid(fname,0,7) else outname = fname

geom = sxpar(h,'GEOMPROG')
if !ERR NE -1 then outname = outname + 'G'

strm = sxpar(h,'BDRSTREM')
if !ERR EQ -1 then strm = ''
if strm EQ 'QUICK13' then outname = outname + 'Q13C' else $
                          outname = outname + 'C'

; By not calling SXOPEN and SXWRITE, one seems to avoid virtual
; memory problems on VMS machines

if !VERSION.OS NE "vms" then outname = strlowcase(outname)
message,'Writing output image '+strupcase(outname),/INF
sxhwrite,outname,h

close,1
openw,1,outname + '.hhd',512,/NONE
a = assoc(1,im)
a(0) = im
close,1
return
end