#! /bin/tcsh -f

echo "*****************************"
echo "*  start esplinemap_LM.csh  *"
echo "*****************************"
date

cd $result_dir/
set det=$result_dir/$dir0/detection
set ExpDetectPrep = $result_dir/$dir0/detection/ExpDetectPrep
cd $det/
  
setenv SAS_ODF $data_dir/$dir0
setenv SAS_CCF $data_dir/$dir0/ccf.cif

if ($DET == 1 ) then
  set epic = "MOS1" 
  set b = 2
  foreach band (`cat $result_dir/$dir0/energy_band.txt | perl -ne 'print unless $.<2 '`)
    set bmin=`awk -F \; -v nr=$b '{ if (NR == nr) print $1}' $result_dir/$dir0/energy_band.txt`
    set bmax=`awk -F \; -v nr=$b '{ if (NR == nr) print $2}' $result_dir/$dir0/energy_band.txt`

   if (-e "$ExpDetectPrep"/ExpDetect_"$epic"_LE_noise_filtered_image_"$b".fits) then
    echo "#! /bin/tcsh -f" > $det/esplinemap_LM.csh

    echo "/usr/bin/time -p esplinemap imageset="$ExpDetectPrep"/ExpDetect_"$epic"_LE_noise_filtered_image_"$b".fits boxlistset="$det"/eboxlist_local.fits bkgimageset="$det"/"$dir0"_"$epic"_bkg_"$b".fits detmaskset="$det"/"$dir0"_"$epic"_detmask_"$b".fits withexpimage=yes withexpimage2=no expimageset="$ExpDetectPrep"/ExpDetect_"$epic"_LE_noise_filtered_exponovign_"$b".fits ooteventset="$ExpDetectPrep"/ExpDetectPrep_"$epic"_merged_event_list_"$b_tot".fits pimin=$bmin pimax=$bmax fitmethod=$fitmethod_l withdetmask=yes withcheese=yes withcheesemask=yes idband=$b scut=$scut_l mlmin=$mlmin_l nsplinenodes=$nsplinenodes_l excesssigma=3 nfitrun=$nfitrun_l withootset=true -w "$warn" -V "$verb"" >> $det/esplinemap_LM.csh

    source $det/esplinemap_LM.csh
    rm $det/esplinemap_LM.csh
    echo "OK: "$dir0"_"$epic"_bkg_"$b".fits done in energy band (eV) ["$bmin":"$bmax"]"
    mv cheese.fits "$ExpDetectPrep"/"$dir0"_"$epic"_cheese_"$b".fits
    mv cheesemask.fits "$ExpDetectPrep"/"$dir0"_"$epic"_maskcheese_"$b".fits
    if ( ! -e "$dir0"_"$epic"_bkg_"$b".fits ) then
      echo "ERROR $dir0 "$dir0"_"$epic"_bkg_"$b".fits does not exist"
      echo "ERROR $dir0 "$dir0"_"$epic"_bkg_"$b".fits does not exist FULLDET" >> $log_dir/messages.log
    endif
  set b = ` expr $b + 1`
  end
  echo "start to make the bkg map in the total energy band $b_tot"
  set bkg = `ls $det/"$dir0"_"$epic"_bkg_*.fits`
  echo "imweightadd imagesets=' "$bkg" ' outimageset="$det"/"$dir0"_"$epic"_bkg_"$b_tot".fits tempset="$ExpDetectPrep"/ExpDetectPrep-all-Generic_temporary.fits withweights=no -w "$warn" -V "$verb"" > $det/imweightadd.csh
  source $det/imweightadd.csh
  rm $det/imweightadd.csh
 endif
 set epic = "MOS2" 
  set b = 2
  foreach band (`cat $result_dir/$dir0/energy_band.txt | perl -ne 'print unless $.<2 '`)
    set bmin=`awk -F \; -v nr=$b '{ if (NR == nr) print $1}' $result_dir/$dir0/energy_band.txt`
    set bmax=`awk -F \; -v nr=$b '{ if (NR == nr) print $2}' $result_dir/$dir0/energy_band.txt`

   if (-e "$ExpDetectPrep"/ExpDetect_"$epic"_LE_noise_filtered_image_"$b".fits) then
    echo "#! /bin/tcsh -f" > $det/esplinemap_LM.csh

    echo "/usr/bin/time -p esplinemap imageset="$ExpDetectPrep"/ExpDetect_"$epic"_LE_noise_filtered_image_"$b".fits boxlistset="$det"/eboxlist_local.fits bkgimageset="$det"/"$dir0"_"$epic"_bkg_"$b".fits detmaskset="$det"/"$dir0"_"$epic"_detmask_"$b".fits withexpimage=yes withexpimage2=no expimageset="$ExpDetectPrep"/ExpDetect_"$epic"_LE_noise_filtered_exponovign_"$b".fits ooteventset="$ExpDetectPrep"/ExpDetectPrep_"$epic"_merged_event_list_"$b_tot".fits pimin=$bmin pimax=$bmax fitmethod=$fitmethod_l withdetmask=yes withcheese=yes withcheesemask=yes idband=$b scut=$scut_l mlmin=$mlmin_l nsplinenodes=$nsplinenodes_l excesssigma=3 nfitrun=$nfitrun_l withootset=true -w "$warn" -V "$verb"" >> $det/esplinemap_LM.csh

    source $det/esplinemap_LM.csh
    rm $det/esplinemap_LM.csh
    echo "OK: "$dir0"_"$epic"_bkg_"$b".fits done in energy band (eV) ["$bmin":"$bmax"]"
    mv cheese.fits "$ExpDetectPrep"/"$dir0"_"$epic"_cheese_"$b".fits
    mv cheesemask.fits "$ExpDetectPrep"/"$dir0"_"$epic"_maskcheese_"$b".fits
    if ( ! -e "$dir0"_"$epic"_bkg_"$b".fits ) then
      echo "ERROR $dir0 "$dir0"_"$epic"_bkg_"$b".fits does not exist"
      echo "ERROR $dir0 "$dir0"_"$epic"_bkg_"$b".fits does not exist FULLDET" >> $log_dir/messages.log
    endif
  set b = ` expr $b + 1`
  end
  echo "start to make the bkg map in the total energy band $b_tot"
  set bkg = `ls $det/"$dir0"_"$epic"_bkg_*.fits`
  echo "imweightadd imagesets=' "$bkg" ' outimageset="$det"/"$dir0"_"$epic"_bkg_"$b_tot".fits tempset="$ExpDetectPrep"/ExpDetectPrep-all-Generic_temporary.fits withweights=no -w "$warn" -V "$verb"" > $det/imweightadd.csh
  source $det/imweightadd.csh
  rm $det/imweightadd.csh
 endif
endif

if ($DET == 01 ) then
  set epic = "MOS1" 
  set b = 2
  foreach band (`cat $result_dir/$dir0/energy_band.txt | perl -ne 'print unless $.<2 '`)
    set bmin=`awk -F \; -v nr=$b '{ if (NR == nr) print $1}' $result_dir/$dir0/energy_band.txt`
    set bmax=`awk -F \; -v nr=$b '{ if (NR == nr) print $2}' $result_dir/$dir0/energy_band.txt`

   if (-e "$ExpDetectPrep"/ExpDetect_"$epic"_LE_noise_filtered_image_"$b".fits) then
    echo "#! /bin/tcsh -f" > $det/esplinemap_LM.csh

    echo "/usr/bin/time -p esplinemap imageset="$ExpDetectPrep"/ExpDetect_"$epic"_LE_noise_filtered_image_"$b".fits boxlistset="$det"/eboxlist_local.fits bkgimageset="$det"/"$dir0"_"$epic"_bkg_"$b".fits detmaskset="$det"/"$dir0"_"$epic"_detmask_"$b".fits withexpimage=yes withexpimage2=no expimageset="$ExpDetectPrep"/ExpDetect_"$epic"_LE_noise_filtered_exponovign_"$b".fits ooteventset="$ExpDetectPrep"/ExpDetectPrep_"$epic"_merged_event_list_"$b_tot".fits pimin=$bmin pimax=$bmax fitmethod=$fitmethod_l withdetmask=yes withcheese=yes withcheesemask=yes idband=$b scut=$scut_l mlmin=$mlmin_l nsplinenodes=$nsplinenodes_l excesssigma=3 nfitrun=$nfitrun_l withootset=true -w "$warn" -V "$verb"" >> $det/esplinemap_LM.csh

    source $det/esplinemap_LM.csh
    rm $det/esplinemap_LM.csh
    echo "OK: "$dir0"_"$epic"_bkg_"$b".fits done in energy band (eV) ["$bmin":"$bmax"]"
    mv cheese.fits "$ExpDetectPrep"/"$dir0"_"$epic"_cheese_"$b".fits
    mv cheesemask.fits "$ExpDetectPrep"/"$dir0"_"$epic"_maskcheese_"$b".fits
    if ( ! -e "$dir0"_"$epic"_bkg_"$b".fits ) then
      echo "ERROR $dir0 "$dir0"_"$epic"_bkg_"$b".fits does not exist"
      echo "ERROR $dir0 "$dir0"_"$epic"_bkg_"$b".fits does not exist FULLDET" >> $log_dir/messages.log
    endif
  set b = ` expr $b + 1`
  end
  echo "start to make the bkg map in the total energy band $b_tot"
  set bkg = `ls $det/"$dir0"_"$epic"_bkg_*.fits`
  echo "imweightadd imagesets=' "$bkg" ' outimageset="$det"/"$dir0"_"$epic"_bkg_"$b_tot".fits tempset="$ExpDetectPrep"/ExpDetectPrep-all-Generic_temporary.fits withweights=no -w "$warn" -V "$verb"" > $det/imweightadd.csh
  source $det/imweightadd.csh
  rm $det/imweightadd.csh
 endif
endif

if ( $DET == 02) then
  set epic = "MOS2" 
  set b = 2
  foreach band (`cat $result_dir/$dir0/energy_band.txt | perl -ne 'print unless $.<2 '`)
    set bmin=`awk -F \; -v nr=$b '{ if (NR == nr) print $1}' $result_dir/$dir0/energy_band.txt`
    set bmax=`awk -F \; -v nr=$b '{ if (NR == nr) print $2}' $result_dir/$dir0/energy_band.txt`

   if (-e "$ExpDetectPrep"/ExpDetect_"$epic"_LE_noise_filtered_image_"$b".fits) then
    echo "#! /bin/tcsh -f" > $det/esplinemap_LM.csh

    echo "/usr/bin/time -p esplinemap imageset="$ExpDetectPrep"/ExpDetect_"$epic"_LE_noise_filtered_image_"$b".fits boxlistset="$det"/eboxlist_local.fits bkgimageset="$det"/"$dir0"_"$epic"_bkg_"$b".fits detmaskset="$det"/"$dir0"_"$epic"_detmask_"$b".fits withexpimage=yes withexpimage2=no expimageset="$ExpDetectPrep"/ExpDetect_"$epic"_LE_noise_filtered_exponovign_"$b".fits ooteventset="$ExpDetectPrep"/ExpDetectPrep_"$epic"_merged_event_list_"$b_tot".fits pimin=$bmin pimax=$bmax fitmethod=$fitmethod_l withdetmask=yes withcheese=yes withcheesemask=yes idband=$b scut=$scut_l mlmin=$mlmin_l nsplinenodes=$nsplinenodes_l excesssigma=3 nfitrun=$nfitrun_l withootset=true -w "$warn" -V "$verb"" >> $det/esplinemap_LM.csh

    source $det/esplinemap_LM.csh
    rm $det/esplinemap_LM.csh
    echo "OK: "$dir0"_"$epic"_bkg_"$b".fits done in energy band (eV) ["$bmin":"$bmax"]"
    mv cheese.fits "$ExpDetectPrep"/"$dir0"_"$epic"_cheese_"$b".fits
    mv cheesemask.fits "$ExpDetectPrep"/"$dir0"_"$epic"_maskcheese_"$b".fits
    if ( ! -e "$dir0"_"$epic"_bkg_"$b".fits ) then
      echo "ERROR $dir0 "$dir0"_"$epic"_bkg_"$b".fits does not exist"
      echo "ERROR $dir0 "$dir0"_"$epic"_bkg_"$b".fits does not exist FULLDET" >> $log_dir/messages.log
    endif
  set b = ` expr $b + 1`
  end
  echo "start to make the bkg map in the total energy band $b_tot"
  set bkg = `ls $det/"$dir0"_"$epic"_bkg_*.fits`
  echo "imweightadd imagesets=' "$bkg" ' outimageset="$det"/"$dir0"_"$epic"_bkg_"$b_tot".fits tempset="$ExpDetectPrep"/ExpDetectPrep-all-Generic_temporary.fits withweights=no -w "$warn" -V "$verb"" > $det/imweightadd.csh
  source $det/imweightadd.csh
  rm $det/imweightadd.csh
 endif
endif

if ( $DET == 03) then
  set epic = "PN" 
  set b = 2
  foreach band (`cat $result_dir/$dir0/energy_band.txt | perl -ne 'print unless $.<2 '`)
    set bmin=`awk -F \; -v nr=$b '{ if (NR == nr) print $1}' $result_dir/$dir0/energy_band.txt`
    set bmax=`awk -F \; -v nr=$b '{ if (NR == nr) print $2}' $result_dir/$dir0/energy_band.txt`

   if (-e "$ExpDetectPrep"/ExpDetectPrep_"$epic"_merged_image_"$b".fits) then
    echo "#! /bin/tcsh -f" > $det/esplinemap_LM.csh

    echo "/usr/bin/time -p esplinemap imageset="$ExpDetectPrep"/ExpDetectPrep_"$epic"_merged_image_"$b".fits boxlistset="$det"/eboxlist_local.fits bkgimageset="$det"/"$dir0"_"$epic"_bkg_"$b".fits detmaskset="$det"/"$dir0"_"$epic"_detmask_"$b".fits withexpimage=yes withexpimage2=no expimageset="$ExpDetectPrep"/ExpDetectPrep_"$epic"_merged_exponovign_"$b".fits ooteventset="$ExpDetectPrep"/ExpDetectPrep_"$epic"_merged_event_list_"$b_tot".fits pimin=$bmin pimax=$bmax fitmethod=$fitmethod_l withdetmask=yes withcheese=yes withcheesemask=yes idband=$b scut=$scut_l mlmin=$mlmin_l nsplinenodes=$nsplinenodes_l excesssigma=3 nfitrun=$nfitrun_l withootset=true -w "$warn" -V "$verb"" >> $det/esplinemap_LM.csh

    source $det/esplinemap_LM.csh
    rm $det/esplinemap_LM.csh
    echo "OK: "$dir0"_"$epic"_bkg_"$b".fits done in energy band (eV) ["$bmin":"$bmax"]"
    mv cheese.fits "$ExpDetectPrep"/"$dir0"_"$epic"_cheese_"$b".fits
    mv cheesemask.fits "$ExpDetectPrep"/"$dir0"_"$epic"_maskcheese_"$b".fits
    if ( ! -e "$dir0"_"$epic"_bkg_"$b".fits ) then
      echo "ERROR $dir0 "$dir0"_"$epic"_bkg_"$b".fits does not exist"
      echo "ERROR $dir0 "$dir0"_"$epic"_bkg_"$b".fits does not exist FULLDET" >> $log_dir/messages.log
    endif
  set b = ` expr $b + 1`
  end
  echo "start to make the bkg map in the total energy band $b_tot"
  set bkg = `ls $det/"$dir0"_"$epic"_bkg_*.fits`
  echo "imweightadd imagesets=' "$bkg" ' outimageset="$det"/"$dir0"_"$epic"_bkg_"$b_tot".fits tempset="$ExpDetectPrep"/ExpDetectPrep-all-Generic_temporary.fits withweights=no -w "$warn" -V "$verb"" > $det/imweightadd.csh
  source $det/imweightadd.csh
  rm $det/imweightadd.csh
 endif
endif

if ($DET == 2 ) then
  set epic = "MOS1" 
  set b = 2
  foreach band (`cat $result_dir/$dir0/energy_band.txt | perl -ne 'print unless $.<2 '`)
    set bmin=`awk -F \; -v nr=$b '{ if (NR == nr) print $1}' $result_dir/$dir0/energy_band.txt`
    set bmax=`awk -F \; -v nr=$b '{ if (NR == nr) print $2}' $result_dir/$dir0/energy_band.txt`

   if (-e "$ExpDetectPrep"/ExpDetect_"$epic"_LE_noise_filtered_image_"$b".fits) then
    echo "#! /bin/tcsh -f" > $det/esplinemap_LM.csh

    echo "/usr/bin/time -p esplinemap imageset="$ExpDetectPrep"/ExpDetect_"$epic"_LE_noise_filtered_image_"$b".fits boxlistset="$det"/eboxlist_local.fits bkgimageset="$det"/"$dir0"_"$epic"_bkg_"$b".fits detmaskset="$det"/"$dir0"_"$epic"_detmask_"$b".fits withexpimage=yes withexpimage2=no expimageset="$ExpDetectPrep"/ExpDetect_"$epic"_LE_noise_filtered_exponovign_"$b".fits ooteventset="$ExpDetectPrep"/ExpDetectPrep_"$epic"_merged_event_list_"$b_tot".fits pimin=$bmin pimax=$bmax fitmethod=$fitmethod_l withdetmask=yes withcheese=yes withcheesemask=yes idband=$b scut=$scut_l mlmin=$mlmin_l nsplinenodes=$nsplinenodes_l excesssigma=3 nfitrun=$nfitrun_l withootset=true -w "$warn" -V "$verb"" >> $det/esplinemap_LM.csh

    source $det/esplinemap_LM.csh
    rm $det/esplinemap_LM.csh
    echo "OK: "$dir0"_"$epic"_bkg_"$b".fits done in energy band (eV) ["$bmin":"$bmax"]"
    mv cheese.fits "$ExpDetectPrep"/"$dir0"_"$epic"_cheese_"$b".fits
    mv cheesemask.fits "$ExpDetectPrep"/"$dir0"_"$epic"_maskcheese_"$b".fits
    if ( ! -e "$dir0"_"$epic"_bkg_"$b".fits ) then
      echo "ERROR $dir0 "$dir0"_"$epic"_bkg_"$b".fits does not exist"
      echo "ERROR $dir0 "$dir0"_"$epic"_bkg_"$b".fits does not exist FULLDET" >> $log_dir/messages.log
    endif
  set b = ` expr $b + 1`
  end
  echo "start to make the bkg map in the total energy band $b_tot"
  set bkg = `ls $det/"$dir0"_"$epic"_bkg_*.fits`
  echo "imweightadd imagesets=' "$bkg" ' outimageset="$det"/"$dir0"_"$epic"_bkg_"$b_tot".fits tempset="$ExpDetectPrep"/ExpDetectPrep-all-Generic_temporary.fits withweights=no -w "$warn" -V "$verb"" > $det/imweightadd.csh
  source $det/imweightadd.csh
  rm $det/imweightadd.csh
 endif
  set epic = "MOS2" 
  set b = 2
  foreach band (`cat $result_dir/$dir0/energy_band.txt | perl -ne 'print unless $.<2 '`)
    set bmin=`awk -F \; -v nr=$b '{ if (NR == nr) print $1}' $result_dir/$dir0/energy_band.txt`
    set bmax=`awk -F \; -v nr=$b '{ if (NR == nr) print $2}' $result_dir/$dir0/energy_band.txt`

   if (-e "$ExpDetectPrep"/ExpDetect_"$epic"_LE_noise_filtered_image_"$b".fits) then
    echo "#! /bin/tcsh -f" > $det/esplinemap_LM.csh

    echo "/usr/bin/time -p esplinemap imageset="$ExpDetectPrep"/ExpDetect_"$epic"_LE_noise_filtered_image_"$b".fits boxlistset="$det"/eboxlist_local.fits bkgimageset="$det"/"$dir0"_"$epic"_bkg_"$b".fits detmaskset="$det"/"$dir0"_"$epic"_detmask_"$b".fits withexpimage=yes withexpimage2=no expimageset="$ExpDetectPrep"/ExpDetect_"$epic"_LE_noise_filtered_exponovign_"$b".fits ooteventset="$ExpDetectPrep"/ExpDetectPrep_"$epic"_merged_event_list_"$b_tot".fits pimin=$bmin pimax=$bmax fitmethod=$fitmethod_l withdetmask=yes withcheese=yes withcheesemask=yes idband=$b scut=$scut_l mlmin=$mlmin_l nsplinenodes=$nsplinenodes_l excesssigma=3 nfitrun=$nfitrun_l withootset=true -w "$warn" -V "$verb"" >> $det/esplinemap_LM.csh

    source $det/esplinemap_LM.csh
    rm $det/esplinemap_LM.csh
    echo "OK: "$dir0"_"$epic"_bkg_"$b".fits done in energy band (eV) ["$bmin":"$bmax"]"
    mv cheese.fits "$ExpDetectPrep"/"$dir0"_"$epic"_cheese_"$b".fits
    mv cheesemask.fits "$ExpDetectPrep"/"$dir0"_"$epic"_maskcheese_"$b".fits
    if ( ! -e "$dir0"_"$epic"_bkg_"$b".fits ) then
      echo "ERROR $dir0 "$dir0"_"$epic"_bkg_"$b".fits does not exist"
      echo "ERROR $dir0 "$dir0"_"$epic"_bkg_"$b".fits does not exist FULLDET" >> $log_dir/messages.log
    endif
  set b = ` expr $b + 1`
  end
  echo "start to make the bkg map in the total energy band $b_tot"
  set bkg = `ls $det/"$dir0"_"$epic"_bkg_*.fits`
  echo "imweightadd imagesets=' "$bkg" ' outimageset="$det"/"$dir0"_"$epic"_bkg_"$b_tot".fits tempset="$ExpDetectPrep"/ExpDetectPrep-all-Generic_temporary.fits withweights=no -w "$warn" -V "$verb"" > $det/imweightadd.csh
  source $det/imweightadd.csh
  rm $det/imweightadd.csh
 endif
  set epic = "PN" 
  set b = 2
  foreach band (`cat $result_dir/$dir0/energy_band.txt | perl -ne 'print unless $.<2 '`)
    set bmin=`awk -F \; -v nr=$b '{ if (NR == nr) print $1}' $result_dir/$dir0/energy_band.txt`
    set bmax=`awk -F \; -v nr=$b '{ if (NR == nr) print $2}' $result_dir/$dir0/energy_band.txt`

   if (-e "$ExpDetectPrep"/ExpDetectPrep_"$epic"_merged_image_"$b".fits) then
    echo "#! /bin/tcsh -f" > $det/esplinemap_LM.csh

    echo "/usr/bin/time -p esplinemap imageset="$ExpDetectPrep"/ExpDetectPrep_"$epic"_merged_image_"$b".fits boxlistset="$det"/eboxlist_local.fits bkgimageset="$det"/"$dir0"_"$epic"_bkg_"$b".fits detmaskset="$det"/"$dir0"_"$epic"_detmask_"$b".fits withexpimage=yes withexpimage2=no expimageset="$ExpDetectPrep"/ExpDetectPrep_"$epic"_merged_exponovign_"$b".fits ooteventset="$ExpDetectPrep"/ExpDetectPrep_"$epic"_merged_event_list_"$b_tot".fits pimin=$bmin pimax=$bmax fitmethod=$fitmethod_l withdetmask=yes withcheese=yes withcheesemask=yes idband=$b scut=$scut_l mlmin=$mlmin_l nsplinenodes=$nsplinenodes_l excesssigma=3 nfitrun=$nfitrun_l withootset=true -w "$warn" -V "$verb"" >> $det/esplinemap_LM.csh

    source $det/esplinemap_LM.csh
    rm $det/esplinemap_LM.csh
    echo "OK: "$dir0"_"$epic"_bkg_"$b".fits done in energy band (eV) ["$bmin":"$bmax"]"
    mv cheese.fits "$ExpDetectPrep"/"$dir0"_"$epic"_cheese_"$b".fits
    mv cheesemask.fits "$ExpDetectPrep"/"$dir0"_"$epic"_maskcheese_"$b".fits
    if ( ! -e "$dir0"_"$epic"_bkg_"$b".fits ) then
      echo "ERROR $dir0 "$dir0"_"$epic"_bkg_"$b".fits does not exist"
      echo "ERROR $dir0 "$dir0"_"$epic"_bkg_"$b".fits does not exist FULLDET" >> $log_dir/messages.log
    endif
  set b = ` expr $b + 1`
  end
  echo "start to make the bkg map in the total energy band $b_tot"
  set bkg = `ls $det/"$dir0"_"$epic"_bkg_*.fits`
  echo "imweightadd imagesets=' "$bkg" ' outimageset="$det"/"$dir0"_"$epic"_bkg_"$b_tot".fits tempset="$ExpDetectPrep"/ExpDetectPrep-all-Generic_temporary.fits withweights=no -w "$warn" -V "$verb"" > $det/imweightadd.csh
  source $det/imweightadd.csh
  rm $det/imweightadd.csh
 endif
endif
cd $start_dir/

date
echo "stop esplinemap_LM.csh"
