;+
; PROJECT
;           SOLARB EIS
;
; NAME
;           EIS_COMPRESSION
;
; PURPOSE
;           Calculate compressed raster volume
;
; INPUTS
;           raster - either an eis_raster or an eis_study_raster structure
;
; KEYWORDS
;           target - eg; "Quiet Sun", "Active Region"
; NOTES
;           This
;
; CATEGORY
;           EIS technical planning
;
; WRITTEN
;           John Rainne
;
; VERSION
;           V0.0 JAR Feb-2006
;           v0.1 JAR Jan-2007
;                Included raster input, instead of just volume.
;           v0.3 JAR 4-Apr-2007
;                Renamed DPCM
;           v0.4 JAR 1-May-2006
;                Use Matt Whillock's function to return the compression
;                factors. This way he keeps control of them - and can update
;                them as required.
;           v0.5 JAR 19-May-2008
;                Added TARGET keyword
;           v0.6 07-Nov-2011
;                Added "SILENT" keyword
;           v0.7 23-Aug-2012
;                Tidied up TARGET keyword input
;-
;______________________________________________________________________________
FUNCTION eis_compression , raster , target = target , silent = silent

str_name = TAG_NAMES(raster , /STRUCTURE_NAME)
CASE str_name OF
    'EIS_RASTER'       : BEGIN
                            v = DOUBLE(raster.volume)
                            c = raster.compression
                         END
    'EIS_STUDY_RASTER' : BEGIN
                            v = DOUBLE(raster.ra_volume)
                            c = raster.ra_compression
                         END
    ELSE               : stop
ENDCASE

;
; Get compression factor from...
;
;$SSW/hinode/eis/idl/spacecraft/decompression/eis_get_compression_factor.pro

IF (N_ELEMENTS(target) NE 1) THEN BEGIN
   print,'  + Target not identified!'
   target = 'quiet sun'
ENDIF ELSE BEGIN
   target = STRTRIM(STRLOWCASE(target),2)
ENDELSE

cf = eis_get_compression_factor(c , raster.slitIndex , $
                 target = target , silent = silent)

c_string  = STRCOMPRESS(FIX(c),/REMOVE_ALL)
cf_string = STRCOMPRESS(1./cf,/REMOVE_ALL)
;print,STRJOIN([c_string,' ',cf_string ,' ',target],/SINGLE)


v  = v * cf

RETURN , LONG64(v)

END
