#! /bin/tcsh -f

heainit
sasinit

set working_directory = /share/data/GIO/EXTRAS_analysis3XMM
set obs_list = obs_list.txt
set repository = $working_directory/REPOSITORY

#Writing REPOSITORY folder
if ( -r $repository ) then
   echo "OK REPOSITORY folder"
else
   echo "MAKE REPOSITORY folder"
   mkdir $repository
   chmod 755 $repository  
endif

echo " ---- START SUBMIT JOB ROUTINE ----"

set O = 1
foreach obs_job (`cat $working_directory/$obs_list`)
   echo "Submitting observation number:  $obs_job"
      set wp4_directory = $working_directory/results/$obs_job/WP4products
      echo "done"
      #Submit job
      qsub -V -j y -o ${PWD}/log_$obs_job.log -N OBS_$obs_job script_job.csh $obs_job $working_directory $wp4_directory $repository
   set O = ` expr $O + 1`
end
echo " ---- END SUBMIT JOB ROUTINE ----"
