#!/bin/csh -f
#source $GPS_HOME_DIR/etc/defaults
set sta_info_dir = `get_proc_defaults  STA_INFO_DIR`
set sta_info_dir_abs = `get_proc_defaults  STA_INFO_DIR abs`
set dir = "$GPS_HOME_DIR/igs_info"
set date = `gpsdate -today -o num`
set make_abs_pcenter = 0

cd $dir

set atx_current = `ls  igs0[58]*.atx|sort -r|head -1`
#set atx_current = `ls  igs05*.atx|grep -v plus |sort -r|head -1`

cd $dir/old

#/usr/bin/wget -Nq ftp://www.ngs.noaa.gov/pub/pnt6/ant_info.003
#/usr/bin/wget -Nq ftp://igscb.jpl.nasa.gov/pub/station/general/igs_01.pcv

/usr/bin/wget -Nq "ftp://igscb.jpl.nasa.gov/pub/station/general/igs0?_*.atx"

/usr/bin/wget -Nq "http://www.ngs.noaa.gov/ANTCAL/images/ant_info.abs"

/usr/bin/wget -Nq ftp://igscb.jpl.nasa.gov/pub/station/general/rcvr_ant.tab

/usr/bin/wget -Nq ftp://igscb.jpl.nasa.gov/pub/station/general/antenna.gra

set mail = "$dir/old/mail.$$"
\rm mail.* >& /dev/null
set atx_new = `ls  igs0[58]*.atx|sort -r|head -1`
#set atx_new = `ls |grep plus |sort -r|head -1`
set ar_info = ""
if ( $atx_current != $atx_new  ) then
     set make_abs_pcenter = 1
     \cp $atx_new $dir
     set ar_info = "$ar_info $atx_new"
     echo "Old atx file: $atx_current" >> $mail
     echo "New atx file: $atx_new" >> $mail
     diff $atx_current $atx_new  >> $mail
endif

foreach f ( ant_info.abs rcvr_ant.tab antenna.gra )
  if ( `diff $f ../$f |wc -l` ) then
         set ar_info = "$ar_info $f"
         echo "New $f file" >> $mail
         diff $f ../$f >> $mail 
         mv ../$f $f.$date
         mv $f ..        
         #if ( $f == "ant_info.003" || $f == "igs_01.pcv"   ) then
         #if ( $f == "ant_info.abs" ) then
         #  set make_abs_pcenter = 1
         #endif
  endif
end


if ( $make_abs_pcenter ) then
      cd $dir
      \rm $atx_current >& /dev/null
      cat extras.atx >> $atx_new
      cat zero.atx >> $atx_new
      echo $atx_new
      cd $sta_info_dir_abs
      #mk_pcenter_and_nml >> $mail
      #mk_sat_nml >> $mail
      mk_sat_grn_nml $dir/$atx_new >> $mail 
endif

if ( `echo $ar_info|wc -w` ) then
cat $mail | mail -s "[Processing]: New Antenna/Receiver Info: $ar_info " $USER@geology.cwu.edu
endif
\rm $mail >& /dev/null
