displ FMSAfileno 2 zs+
imdel tmp0,tmp1,mask,FMSAfilenob.fits
fit1d FMSAfileno tmp0 fit axis=1 inter- function=legendre order=1 high_reject=3 low_reject=3 niterate=5 grow=0
imfunc tmp0 tmp0 abs
imarith tmp0 / 10 tmp0
imrepl tmp0 1. lower=INDEF upper=1
imfunc tmp0 tmp0 sqrt
imarith FMSAfileno / tmp0 tmp0
fit1d tmp0 tmp0 difference axis=1 inter- function=spline3 order=20 high_reject=3 low_reject=3 niterate=5 grow=0
median tmp0 tmp1 3 3
imarith tmp0 - tmp1 tmp1
imfunc tmp1 tmp1 abs
imrepl tmp1 6500. upper=INDEF lower=6500.
!rm tmp.tbl tmp1.tbl
imhist tmp1 z1=-0.05 z2=6500.05 binwidt=0.1 nbins=65001 hist_type=cumulative listout+ > tmp.tbl
!../thresh tmp.tbl 30000 tmp1 > tmp1.tbl
cl < tmp1.tbl
imstati tmp1 lower=INDEF upper=0.5
convolve tmp1 tmp1 "0. 0.2 0.; 0.2 0.2 0.2; 0. 0.2 0."
imrepl tmp1 0. lower=INDEF upper=0.9
imcopy tmp1 mask.fits
displ mask 1 zs- zr- z1=1 z2=0
imstati mask lower=INDEF upper=0.5
!../fixbadpix FMSAfileno.fits FMSAfilenob.fits
imarith FMSAfileno_bpm.fits * mask.fits FMSAfileno_bpm.fits
displ FMSAfilenob 3 zs+
