#!/bin/csh

set list = ($*)

if (-f /tmp/tlist.$user) then
   /bin/rm /tmp/tlist.$user
   echo "removed old /tmp/tlist.$user "
endif

foreach file ($list)
set dist = `/usr/local/sac/bin/sac ../codes/getsacdist.m $file | awk '{if ($1=="dist") print $3}'`
#set dist = `/usr/local/sac/bin/sac ../codes/getsacaz.m $file | awk '{if ($1=="dist") print $3}'`
echo $file $dist 
echo $file $dist >> /tmp/tlist.$user
end
sort -n -k2 /tmp/tlist.$user | awk '{if (NR==1) printf "r %s ", $1; else if (NR%10==1) printf "r more %s ", $1; else if (NR%10==0) printf "%s \n", $1; else printf "%s ", $1}' > olist.m
echo "created ordered list olist.m"
