;+
; Project     : SOHO - CDS     
;                   
; Name        : TP_UPDATE_PIX
;               
; Purpose     : Updates pixel values from wavelengths
;               
; Explanation : In case the wavelength calibration has been updated since
;               the technical planning structure was created, this routine
;               can be called to plug into the tp_obs.line_w structure the
;               latest correspondence between wavelength and pixel position.
;               
; Use         : tp_update_pix, tp_obs
;    
; Inputs      : tp_obs  - the standard internal mk_raster structure
;               
; Opt. Inputs : None
;               
; Outputs     : None
;               
; 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, 30-Mar-95
;               
; Modified    : 
;
; Version     : Version 1, 30-Mar-95
;-            

pro tp_update_pix, tp_obs

;
;  for each line which has valid data, adjust the pixels
;
n = where(tp_obs.line_w.lam gt 0.0)

;
;  if no lines then quit now
;
if n(0) eq -1 then return

;
;  loop through lines
;

for i=0,n_elements(n)-1 do begin
   lam = tp_obs.line_w(n(i)).lam * tp_obs.line_w(n(i)).order
   if tp_obs.raster_p.detector eq 'N' then begin
      b = which_nis_band(lam)
      if b le 0 then return
      b = 'N'+string(b,form='(i1)')
   endif else begin
      b = which_gis_band(lam)
      if b le 0 then return
      b = 'G'+string(b,form='(i1)')
   endelse
;
;  calculate new pixels and apply offsets
;

   temp = wave2pix(b,lam)  
   off = tp_obs.line_w(n(i)).x_pos - temp
   tp_obs.line_w(n(i)).x_pos = tp_obs.line_w(n(i)).x_pos - off
   tp_obs.line_w(n(i)).left  = tp_obs.line_w(n(i)).left  - off
   tp_obs.line_w(n(i)).right = tp_obs.line_w(n(i)).right - off
endfor

end
