#!/bin/bash
PATH=/home/pengxy/perl5/bin:/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/home/pengxy/.local/bin:/home/pengxy/bin:/vega2/rhbin
export PATH
find -name 'p*_?.fits' > fname.dat
sort fname.dat >fname1.dat
touch nohead.dat

cat fname1.dat| while read filename1
do
#echo ${filename1:2:16}
filename2=${filename1:2:12}
filename3=${filename1:2:11}
if [  -f  '/line15/line9/uband_exchange/pengxy/scamp/basshead/''n'${filename2}'.head' ]

then
cp '/line15/line9/uband_exchange/pengxy/scamp/basshead/'n${filename2}.head  ./${filename2}.head 

cp ${filename2}.head   ${filename2}_od.head     
cp ${filename2}.head   ${filename2}.wht.head

echo ${filename2}'.head' >d.dat
#python buaddfzhead.py
#find -name ${filename2}'_?.fits'  >> rehead.dat 
missfits ${filename2}'.fits' # ${filename2}'.head'
missfits ${filename2}'_od.fits'
missfits ${filename2}'.wht.fits'

else
echo ${filename2}'.head'  ,'is not here'
echo ${filename2}'.head  is not exist' >>nohead.dat
echo ${filename2}'.head  is not exist' >>/line16/MzLS_NAOC/needhead.dat
#cp '../ahead/'${filename3}'.head' .
fi
#rm ${filename2}".fits"
rm ${filename2}*_0.fits
rm ${filename2}*.back
rm n*.head

done






