;---------------------------------------------------------------------------
; Document name: DECOMP_R.PRO
; Created by:    Dietmar Germerott, MPAE Lindau, August 14, 1998
;
; Last Modified: Mon Aug 24 16:56:22 1998 (GERMEROTT@linsu1.mpae.gwdg.de)
;---------------------------------------------------------------------------
;

PRO decomp_r, filespec, outpath=outpath, noreverse=noreverse
   
;+
; PROJECT:
;       SOHO - SUMER
;
; NAME:
;       DECOMP_R
;
; PURPOSE: 
;       
;
; CATEGORY:
;       
; 
; EXPLANATION:
;       
; SYNTAX: 
;       decomp_r, 
;
; EXAMPLES:
;       
; INPUTS:
;       
;
; OPTIONAL INPUTS: 
;       None.
;
; OUTPUTS:
;       None.
;
; OPTIONAL OUTPUTS:
;       None.
;
; KEYWORDS: 
;       None.
;
; COMMON:
;       None.
;
; RESTRICTIONS: 
;       None.
;
; SIDE EFFECTS:
;       None.
;
; HISTORY:
;       Version 1, August 14, 1998, Dietmar Germerott, MPAE Lindau. Written
;         based on decomp_r by Udo Schuehle
; CONTACT:
;       Dietmar Germerott, MPAE Lindau (Dietmar Germerott@linmpi.mpg.de)
;-
;
   ON_ERROR, 2


; decompression of images compressed with Method_5 
; and reverse of all images in a directory <<<<
   
;---------------------------------------------------------------------------
;  look for files by filespec
;---------------------------------------------------------------------------

   f$ = findfile(filespec, count=fnum)
   PRINT,fnum,' File to process'
   
   FOR i=0, fnum-1 DO BEGIN

      RESTORE, f$(i)
      
      break_file, f$(i), dir_log, dir_t, filnam, ext_t
      decomp5, image_data, header_data, image
      
;---------------------------------------------------------------------------
;  Reverse is for FITS file orientation of Lambda
;---------------------------------------------------------------------------
      
      IF NOT KEYWORD_SET(noreverse) THEN image = reverse(image)
      
      IF KEYWORD_SET(outpath) THEN outdir = outpath ELSE $ 
         outdir = concat_dir(dir_log,dir_t)
      
      outnam = concat_dir(outdir,filnam+'d_r'+ext_t)
      PRINT, ' saving file ',i,' ',outnam
;     PRINT, STRMID(f$(i), 17, 12)+'d_r.rst'
;if max(image) le 255 then image=byte(image)
      SAVE, file=outnam,header_data, image, /XDR

   ENDFOR
END

;---------------------------------------------------------------------------
; End of 'DECOMP_R.PRO'.
;---------------------------------------------------------------------------
