#! /bin/sh -
#SCRIPT TO SORT C4 FILE 
file=$1
work=`pwd`
if [ "$1" = "" ]
   then
    echo 'Inputs ready to run'
    echo ' '
    ls *c4
    echo ' '
    echo -n 'Choose one of the above (without .c4 extention!): '
    read file
fi                          
if [ -f $file.c4 ]; then
   echo 'Using existing C4 file:'  $file.c4
   else
   echo 'Input file :' $file.c4 ' does not exist'
   exit
fi

   # SORT C4 FILE

   cd ../util/x4toc4
   rm C4.DAT C4.SRT 2>/dev/null
   ln  -sf $work/$file.c4 C4.DAT
   # RUN c4sort TO SORT C4 DATA   
   cd ../c4sort
   ./c4sort
   cd $work
   mv ../util/x4toc4/C4.SRT $file.c4
   if [ -s $file.c4 ]; then
      echo 'EXFOR data in computational format are stored in :'$file.c4
      else
      echo 'File with EXFOR data in computational format is EMPTY'
   fi

exit
