### Dome Flat ###
imdel tmp1,tmp2
imcomb Flat_OFF1,Flat_OFF2,Flat_OFF3 tmp2
imarith CAL_ON - tmp2 irs1_ar_MODE.fits
imcomb Flat_ON1,Flat_ON2,Flat_ON3,Flat_ON4,Flat_ON5,Flat_ON6 tmp1
imarith tmp1 - tmp2 irs1_flat_MODE.fits
imcopy irs1_flat_MODE.fits irs1_cont_MODE.fits
#"irs1_cont_MODE.fits" is the fixed name.
!sed -e 's/BAND/MODE/g' ../redscr0s > tmpscr
cl < tmpscr
!sed -e 's/FMSAfileno/irs1_flat_MODE/g' ../redscr1s | sed -e 's/BAND/MODE/g' | sed -e 's/SHIFT/0/g' > tmpscr
cl < tmpscr

imdel tmp1,tmp2
imcomb Flat_OFF1,Flat_OFF2,Flat_OFF3 tmp2
imarith CAL_ON - tmp2 irs2_ar_MODE.fits
imcomb Flat_ON1,Flat_ON2,Flat_ON3,Flat_ON4,Flat_ON5,Flat_ON6 tmp1
imarith tmp1 - tmp2 irs2_flat_MODE.fits
imcopy irs2_flat_MODE.fits irs2_cont_MODE.fits
#"irs2_cont_MODE.fits" is the fixed name.
!sed -e 's/BAND/MODE/g' ../redscr0s_ | sed -e 's/#4#//g' | sed -e 's/#rmstripe3/rmstripe3/g' > tmpscr
cl < tmpscr
!sed -e 's/FMSAfileno/irs2_flat_MODE/g' ../redscr1s_ | sed -e 's/#4#//g' | sed -e 's/BAND/MODE/g' | sed -e 's/SHIFT/0/g' | sed -e 's/#rmstripe3/rmstripe3/g' > tmpscr
cl < tmpscr

### CAL Lamp ###
!sed -e 's/FMSAfileno/irs1_ar_MODE/g' ../redscr1s | sed -e 's/BAND/MODE/g' | sed -e 's/SHIFT/0/g' > tmpscr
cl < tmpscr
imdel tmp1
median irs1_ar_MODEa tmp1.fits 1 21 boundar=reflect
imdel check,irs1_ar_MODEw.fits
!../wlmap tmp1.fits irs1_ar_MODEw.fits ../ThAr.dat 0.001 1.371 0.470 -0.028 0.004
#js: 0.001 1.011 0.121 -0.001 0.000
#jl: 0.001 1.238 0.118 -0.001 0.000
#hs: 0.001 1.502 0.111 -0.002 0.000
#hl: 0.001 1.713 0.105 -0.002 -0.001
displ tmp1 1 zs+
displ check 2 zs- zr+
#Compair these two images (read data / model) to make sure the conversion is not failed.
displ irs1_ar_MODEw 3 zs- zr+
#The image gives the wavelength at each pixel.

!sed -e 's/FMSAfileno/irs2_ar_MODE/g' ../redscr1s_ | sed -e 's/#4#//g' | sed -e 's/BAND/MODE/g' | sed -e 's/SHIFT/0/g' | sed -e 's/#rmstripe3/rmstripe3/g' > tmpscr
cl < tmpscr
imdel tmp1
median irs2_ar_MODEa tmp1.fits 1 21 boundar=reflect
imdel check,irs2_ar_MODEw.fits
!../wlmap tmp1.fits irs2_ar_MODEw.fits ../ThAr.dat 0.001 1.371 0.475 -0.033 0.008
displ tmp1 1 zs+
displ check 2 zs- zr+
#Compair these two images (read data / model) to make sure the conversion is not failed.
displ irs2_ar_MODEw 3 zs- zr+
#The image gives the wavelength at each pixel.
