;+
; Project     : SOHO - CDS     
;                   
; Name        : TP_GET_DESC()
;               
; Purpose     : Composes raster, variation and window descriptions.
;               
; Explanation : Composes a meaningful description for the raster, its variation
;               and the data extraction windows from the information currently
;               in the planning structure.
;               
; Use         : tp_get_desc, tp_obs
;    
; Inputs      : tp_obs - the structure variable.
;               zone   - the current source type
;               
; Opt. Inputs : None
;               
; Outputs     : Descriptions are updated in the structure.
;               
; Opt. Outputs: None
;               
; Keywords    : None
;
; Calls       : None
;
; Common      : None
;               
; Restrictions: None
;               
; Side effects: None
;               
; Category    : Technical, planning
;               
; Prev. Hist. : None
;
; Written     : C D Pike, RAL, 21-Mar-95
;               
; Modified    : Add zone parameter.                              CDP, 24-Mar-95
;               Add number of lines to DEW descr.                CDP, 3-Apr-95
;               Add raster coverage to variation descriptor
;               and make only slit size in fundamental descriptor.
;                                                                CDP, 21-Apr-95
;               Limit desc to 50 chars max. and rework fundamental desc.
;                                                                CDP, 18-May-95
;               Add Line list and dw IDs to variation desc.      CDP, 23-May-95
;               Fix area calculation in raster description.      CDP, 29-Jun-95
;               Add GIS filaments to zone types.                 CDP, 7-Sep-95
;               Handle increased description length of 65 chars. CDP, 17-Oct-95
;               Do not count detached flag windows in window description.
;                                                                CDP, 07-Nov-95
;               Add chksum to datawin description.               CDP, 15-Nov-95
;               Fix label in data windows description.           CDP, 12-Dec-95
;               Cut out area in fundamental description.         CDP, 23-Jan-96
;               Add curr_lheight parameter in call.              CDP, 10-Apr-96
;               Add LL_ID to datawin description.                CDP, 17-Oct-96
;               Add comp_opt to v_descriptor for comp mode 8     CDP, 04-Mar-98
;               Added extra uniqueness for datawin desc.         CDP, 18-May-98
;               Allow negative zones.                            CDP, 04-May-99
;
; Version     : Version 18, 04-May-99
;-            

pro tp_get_desc, t, zone, flag_state, curr_lheight

;
;  slit width/height
;
sw = [2,4,8,2,4,90]
sh = [2,4,51,240,240,240]

;
;  zone types
;
zone_type = ['','CORONA','LIMB','CORONAL HOLE','QUIET','ACTIVE','FLARE',$
             'GIS_FIL1_NEG','GIS_FIL1_POS','GIS_FIL2_NEG','GIS_FIL2_POS']

;
;  make up the FUNDAMENTAL RASTER description
;              ==================
;
w = ((t.raster_p.nx-1) * t.raster_p.xstep) + sw(t.raster_p.slit_num-1)
if t.raster_p.detector eq 'N' then begin
   h = sh(t.raster_p.slit_num-1) < curr_lheight
   if h eq 0 then h = sh(t.raster_p.slit_num-1)
endif else begin
   h = ((t.raster_p.ny-1) * t.raster_p.ystep) + sh(t.raster_p.slit_num-1)
endelse
;desc = 'Area'+fmt_vect([w,h],del='x')
desc = ''

;
;  add the slit 
;

desc = desc +'Slit'+$
             fmt_vect([sw(t.raster_p.slit_num-1),sh(t.raster_p.slit_num-1)],$
              delim='x')

;
;  add the mirror/slit posns and step size
;
if t.raster_p.detector eq 'N' then begin
   ns = fmt_vect([string(t.raster_p.nx),'-'])
   ss = fmt_vect([string(t.raster_p.xstep),'-'])
endif else begin
   ns = fmt_vect([string(t.raster_p.nx),string(t.raster_p.ny)])
   ss = fmt_vect([t.raster_p.xstep,t.raster_p.ystep])
endelse  
desc = desc + ',Posns'+ns+'@'+ss+' steps'


;
;  load completed raster description
;
t.raster_p.ras_desc = strmid(desc,0,64)




;
;  now the RASTER VARIATION description
;          ================
;
desc = fmt_vect([w,h],del='x')+' arcsec, '

if fix(t.raster_v.exptime) ne t.raster_v.exptime then f='(f6.1)' else f='(i5)'
desc = desc+strtrim(string(t.raster_v.exptime,form=f)+'s',2)

if zone gt 100 then zzz = zone-100 else zzz=zone
desc = desc + ' <' + zone_type(abs(zzz))+'>'
desc = strpad(desc,26,/after)

desc = desc + '  Comp. '
if t.raster_v.comp_id eq 3 or t.raster_v.comp_id eq 8 then begin
   desc = desc + fmt_vect([t.raster_v.comp_id,t.raster_v.comp_opt])
endif else begin
   desc = desc + string(t.raster_v.comp_id,form='(i1)')
endelse

if t.raster_v.comp_id eq 6 then begin
   if t.raster_v.vds_orient eq 0 then desc = desc + 'r' else desc = desc + 'c'
endif

desc = desc + ' IDs-' + fmt_vect([t.raster_v.ll_id,t.raster_v.dw_id])

t.raster_v.rv_desc = strmid(desc,0,64)
desc = ''

;
;  make the DATA EXTRACTION WINDOW description
;           ======================

;
;  check each detector
;
if t.raster_p.detector eq 'N' then begin
;
;  Full CCD?
;
   n = where(t.data_win2.win_def(2) eq 1024 and $
             t.data_win2.win_def(3) eq 1024)
   if n(0) ge 0 then begin
      t.data_win.dw_desc = 'All CCD'
      return
   endif

;
;  any background windows?
   desc = ''
   b = max(where(t.data_win2.win_name eq 'Background'))
   if b ge 0 then desc = 'Background, '

;
;  individual extraction windows?
;
   n = where(t.data_win2.win_def(2) eq 1024)
   if n(0) ge 0 then begin
      desc = desc + 'All NIS'
      n1 = where(t.data_win2(n).win_def(1) gt 511)
      if n1(0) ge 0 then desc = desc + '1'
      n2 = where(t.data_win2(n).win_def(1) lt 511)
      if n2(0) ge 0 then begin
         if n1(0) ge 0 then desc = desc+',2' else desc=desc+'2'
      endif
   endif
endif else begin
   n = where(t.data_win2.win_def(2) eq 2048)
   if n(0) ge 0 then begin
      n1 = where(t.data_win2(n).win_def(0) eq 0)
      n2 = where(t.data_win2(n).win_def(0) eq 2048)
      n3 = where(t.data_win2(n).win_def(0) eq 4096)
      n4 = where(t.data_win2(n).win_def(0) eq 6144)
      if max([n1,n2,n3,n4]) ge 0 then begin
         desc = desc + 'GIS Band'
         bands = ''
         if n1(0) ge 0 then bands = bands+'1'
         if n2(0) ge 0 then bands = bands+'2'
         if n3(0) ge 0 then bands = bands+'3'
         if n4(0) ge 0 then bands = bands+'4'
         desc = desc + bands + ' '
      endif
   endif
endelse


;
;  individual lines
;

nl = 0
if t.raster_p.detector eq 'N' then begin
   if flag_state eq 1 then begin
      n = where(t.data_win2.win_name ne 'Background' and $
                t.data_win2.win_name ne ' ' and $            
                t.data_win2.win_def(2) ne 1024)
      if n(0) ge 0 then nl = t.line_list.n_lines
   endif else begin
      n = where(t.data_win2.win_name ne 'Background' and $
                t.data_win2.win_name ne ' ' and $            
                t.data_win2.win_def(2) ne 1024 and $
                t.data_win2.win_flag ne 1)
      if n(0) ge 0 then nl = n_elements(n)
   endelse
   if nl gt 0 then begin
      desc = desc + ' ' + string(nl,form='(i2)') + ' lines. '
      desc = desc + '{'+strtrim(string(t.data_win.ll_id),2)+'} '
      desc = desc + ' dex = '+ fmt_vect([t.data_win2(n(0)).win_def(2),$
                              t.data_win2(n(0)).win_def(3)])+' pixels'
   endif
endif else begin
   if flag_state eq 1 then begin
      n = where(t.data_win2.win_name ne 'Background' and $
                t.data_win2.win_name ne ' ' and  $           
                t.data_win2.win_def(2) ne 2048)
      if n(0) ge 0 then nl = t.line_list.n_lines
   endif else begin
      n = where(t.data_win2.win_name ne 'Background' and $
                t.data_win2.win_name ne ' ' and  $           
                t.data_win2.win_def(2) ne 2048 and $
                t.data_win2.win_flag ne 1)
      if n(0) ge 0 then nl = n_elements(n)
   endelse
   if nl gt 0 then begin
      desc = desc + ' ' + string(nl,form='(i2)') + ' lines. '
      desc = desc + '{'+strtrim(string(t.data_win.ll_id),2)+'} '
      desc = desc + ' dex = '+ fmt_vect([t.data_win2(n(0)).win_def(2),$
                              t.data_win2(n(0)).win_def(3)])+' pixels'
   endif
endelse
;
;  add chksum for extra uniqueness
;
chksum = total(t.data_win2.win_def)
if nl gt 0 then begin
   for ii = 0,nl-1 do chksum = chksum + t.data_win2(ii).win_def(0)*ii
endif
chksum = long(chksum)
desc = desc + $
             ' <'+strtrim(string(chksum,form='(i7)'),2)+'>'

t.data_win.dw_desc = strmid(desc,0,64)

end
