;+
; Contains the adjust_lin2 procedure
;
; :Author:
; Philippe Zarka
;
; :History:
; 2003/12/08: Created
;
; 2003/12/08: Last Edit
;-
;
;+
; Linear interpolation of bad pixels in a 1-D array.
; Bad pixels are replaced via linear interpolation of surrounding 2 pixels
; (immediate neighbours).
; Bad pixels at the beginning or end of the array are replaced by constant
; (first or last) values.
;
; :Params:
; x: in, required, type=sometype
; 1-D array of original data
; para: in, required, type=sometype
; weights identifying good (1) and bad (0) pixels in the original data
; xnet: out, required, type=sometype
; cleaned data, with bad pixels replaced by interpolated values
;-
pro ADJUST_LIN2, x, para, xnet
; Kharkov data : To be called for each frequency and "interpointing" sequence.
taille=n_elements(x)
xx=lindgen(taille)
xnet=x
test=where(para ne 0b) & ntest=n_elements(test)
if test(0) eq -1 then return
xnet(0:test(0))=xnet(test(0)) & para(0:test(0))=1b
xnet(test(ntest-1):*)=xnet(test(ntest-1)) & para(test(ntest-1):*)=1b
test=where(para eq 0b)
if test(0) eq -1 then return
; bad arrays are left to original values (Kharkov: bad interpointing sequences)
for i=test(0),test(n_elements(test)-1) do begin
if para(i) eq 0b then begin
if para(i-1) eq 0b then xnet(i)=result(i-a1) else begin
avant=max(where(para(0:i) eq 1b))
apres=min(where(para(i:*) eq 1b))+i
a1=max([0,avant]) & a2=min([apres,taille-1])
rien=polyfitw(xx(a1:a2),x(a1:a2),para(a1:a2),1,result)
xnet(i)=result(i-a1)
endelse
endif
endfor
return
end