<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">#!/bin/csh -f
#setenv NCS_SHUTUP
#source ~panorama/panorama/config/setup
#unsetenv NCS_SETUP
alias julian /users/rsg/panorama/panorama.svn/bin/julian

curl -s --form-string "token=a5in7r91skp2tbjp9u1d2eqmw6x4dp" --form-string "user=u1EipWnXCFXLosRgpwHcz1yBF9joup" --form-string "message=`hostname` is the guilty machine!" https://api.pushover.net/1/messages.json

umask 002

#set buoys = (L4 E1)
set buoys = (L4)
set RAME = "rame"
set CLONE = "192.171.162.92"
set user = root
set web = "rsg-web-project-sites.npm.ac.uk"
set webuser = rsgadmin
set FORCE_CLONE = 1 
set NOCAM = 0
set AMOS_flag = 0

set datestamp = `date --utc`

set test = `ssh -p 22 -o ConnectTimeout=10 -l $user $RAME ls`
set alive = $status
set bindir = /users/rsg/observatory/buoy/pml/bin

if ($alive != 0 || $FORCE_CLONE) then 
   echo "Rame Head not reachable" $datestamp &gt; /tmp/ancillary_data.txt
   #petwa 2012-08-29, Comment out the email for the moment. Revert when Rame back. No need to check this in as if gets reverted
   #                  we do not care.
   #echo "Rame Head not reachable" | mail -s "Rame Head" tjsm@pml.ac.uk, petwa@pml.ac.uk, jrfi@pml.ac.uk
   echo "Using PML CLONE machine directly" &gt;&gt; /tmp/ancillary_data.txt
   rsync -auv ${user}@${CLONE}:/root/download /users/rsg/observatory/buoy/pml
   #rsync -auv /users/rsg/observatory/buoy/pml/download ${webuser}@${web}:/home/rsgadmin/westernchannelobservatory.org.uk/data/buoy
   #exit(-1)
else
   echo "Rame Head Alive" $datestamp &gt; /tmp/ancillary_data.txt
   # now do the rsync of the AIS information
   # remove files older than 7 days old
   #set oldAIS = `find /users/rsg/observatory/buoy/pml/AIS/output -name \*.a\?\? -ctime +7`
   #if ($#oldAIS != 0) then 
   #   /bin/rm $oldAIS
   #endif
   #rsync -av ${user}@${RAME}:/root/ramehead/AIS/output /users/rsg/observatory/buoy/pml/AIS
   rsync -auv -e "ssh -p 225" ${user}@${RAME}:/root/download /users/rsg/observatory/buoy/pml 
   
   # download the ozone data
   #rsync -auv ${user}@${RAME}:/root/ramehead/ozone/output/ /users/rsg/observatory/rame/ozone

   # extra temporary download of the clone machine 
   #rsync -auv ${user}@${CLONE}:/root/download /users/rsg/observatory/buoy/pml
   #rsync -auv /users/rsg/observatory/buoy/pml/download ${webuser}@${web}:/home/rsgadmin/westernchannelobservatory.org.uk/data/buoy
endif

# now put the latest stuff on the web
/bin/rm -rf /tmp/buoy*.txt

foreach buoy($buoys)
   echo "Processing: $buoy"

#   if ($buoy == "E1") then
#      set files = `ls /users/rsg/observatory/buoy/pml/download/{$buoy}/*/*.txt`
#   else
      set files = `ls /users/rsg/observatory/buoy/pml/download/{$buoy}/*/20?????F.txt`
#   endif

   foreach file($files)
      set year = `echo $file:t:r | cut -c1-4`
      set julian = `echo $file:t:r | cut -c5-7`
      # met data
      cat $file | grep MPB | sed -e 's/MPB/'$julian'/g' | gawk '/\./{print $1+$2/24,$3,$4,$5,$6,$7}' &gt;&gt; /tmp/buoy_met_{$buoy}_all.txt
      # WQM data
      cat $file | grep WQM | sed -e 's/WQM/'$julian'/g' | gawk '/\./{print $1+$2/24,$3,$4,$5,$6,$7}' &gt;&gt; /tmp/buoy_wqm_{$buoy}.txt
      # CDM data
      cat $file | grep CDM | sed -e 's/CDM/'$julian'/g' | gawk '/\./{print $1+$2/24,$3}' &gt;&gt; /tmp/buoy_cdm_{$buoy}.txt
      # Nitrate data
      # correction only holds for 2009 data
      #cat $file | grep NLF | sed -e 's/NLF/'$julian'/g' | gawk '/\./{print $1+$2/24,$3+($1+$2/24)*0.053828 + 3.873}' &gt;&gt; /tmp/buoy_nlf_{$buoy}.txt
      #cat $file | grep LF | sed -e 's/NLF/'$julian'/g' | sed -e 's/SLF/'$julian'/g' | gawk '/\./{print $1+$2/24,$3}' &gt;&gt; /tmp/buoy_nlf_{$buoy}.txt
      cat $file | grep LC | sed -e 's/NLC/'$julian'/g' | sed -e 's/SLF/'$julian'/g' | gawk '/\./{print $1+$2/24,$3}' &gt;&gt; /tmp/buoy_nlf_{$buoy}.txt
      # pH data
      cat $file | grep PHL | sed -e 's/PHL/'$julian'/g' | gawk '/\./{print $1+$2/24,$3}' &gt;&gt; /tmp/buoy_pH_{$buoy}.txt
   end

   # only the last 7 days for the met data
   set mfiles = `ls /users/rsg/observatory/buoy/pml/download/{$buoy}/*/20?????F.txt | tail -6`
   set lmfile = `ls /users/rsg/observatory/buoy/pml/download/{$buoy}/???????/*.txt | tail -1`
   set lmfiles = `echo $mfiles $lmfile`
   
   # need to remove the previous versions of the 7day files
   
   foreach file($lmfiles)
      set year = `echo $file:t:r | cut -c1-4`
      set julian = `echo $file:t:r | cut -c5-7`
      # met data
      cat $file | grep MPB | sed -e 's/MPB/'"${year} ${julian}"'/g' | gawk '/\./{printf("%04d.%d.%02d %7.2f %5.2f %5.2f %6.2f %6.2f\n",$1,$2,$3,$4,$5,$6,$7,$8)}' &gt;&gt; /tmp/buoy_met_{$buoy}.txt
      #cat $file | grep MPB | sed -e 's/MPB/'$julian'/g' | gawk '/\./{print $1+$2/24,$3,$4,$5,$6,$7}' &gt;&gt; /tmp/buoy_met_{$buoy}.txt
      cat $file | grep GPS | sed -e 's/GPS/'$julian'/g' | gawk '/\./{print $1+$2/24,$3,$4}' &gt;&gt; /tmp/buoy_gps_{$buoy}.txt
      # WQM data
      cat $file | grep WQM | sed -e 's/WQM/'"${year} ${julian}"'/g' | gawk '/\./{printf("%04d.%d.%02d %5.2f %5.2f %6.2f %4.2f %4.2f\n", $1,$2,$3,$4,$5,$6,$7,$8)}' &gt;&gt; /tmp/buoy_wqm_{$buoy}_last7.txt
      # NLF data
      cat $file | grep NLC | sed -e 's/NLC/'"${year} ${julian}"'/g' | gawk '/\./{printf("%04d.%d.%02d %5.2f\n", $1,$2,$3,$4)}' &gt;&gt; /tmp/buoy_nlf_{$buoy}_last7.txt
      # CDM data
      cat $file | grep CDM | sed -e 's/CDM/'"${year} ${julian}"'/g' | gawk '/\./{printf("%04d.%d.%02d %5.2f\n", $1,$2,$3,$4)}' &gt;&gt; /tmp/buoy_cdm_{$buoy}_last7.txt
      # PAR data
      # create dummy entries either end of the observing period
      echo "${year}.${julian}.05 0.0" &gt;&gt; /tmp/buoy_par_{$buoy}.txt
      cat $file | grep PAR | sed -e 's/PAR/'"${year} ${julian}"'/g' | gawk '/\./{printf("%04d.%d.%02d %6.2f\n",$1,$2,$3,$4)}' &gt;&gt; /tmp/buoy_par_{$buoy}.txt
      if ($file != $lmfile) then 
         echo "${year}.${julian}.21 0.0" &gt;&gt; /tmp/buoy_par_{$buoy}.txt
      endif
   end

   #look for Rame Head met files
   set rame_files = `find /users/rsg/observatory/metstation/data/ramehead/buoy_fmt -name \*.dat -ctime -6 -size +0k`

   if ($#rame_files != 0) then 
      /bin/rm /tmp/buoy_rame_cmp.txt
      # get the files into the correct order (not done via find command)
      set rame_files = `ls -1 $rame_files | tail -7`
      echo $rame_files
      cat $rame_files &gt; /tmp/buoy_rame_cmp.txt 
   endif
   
   /usr/bin/gnuplot ${bindir}/gnuplot/plot_nitrate_{$buoy}
   /usr/bin/gnuplot ${bindir}/gnuplot/plot_oxygen_fluor_{$buoy}
   /usr/bin/gnuplot ${bindir}/gnuplot/plot_temp_hum_{$buoy}
   /usr/bin/gnuplot ${bindir}/gnuplot/plot_temp_sal_{$buoy}
   /usr/bin/gnuplot ${bindir}/gnuplot/plot_wind_{$buoy}
   /usr/bin/gnuplot ${bindir}/gnuplot/plot_pressure_{$buoy}
   
   # added in here the last 7 days plot for the web (comment out to revert)
   /usr/bin/gnuplot ${bindir}/gnuplot/plot_nitrate_{$buoy}_last7days
   /usr/bin/gnuplot ${bindir}/gnuplot/plot_oxygen_fluor_{$buoy}_last7days
   /usr/bin/gnuplot ${bindir}/gnuplot/plot_temp_sal_{$buoy}_last7days

   # execute the AMOS download and processing script
   if ($buoy == "L4") then 
      echo "Downloading AMOS data from L4 buoy"
      $bindir/get_iridium_amos_data.csh
   endif

   if ($#rame_files != 0 &amp;&amp; $buoy == "L4") then
      /usr/bin/gnuplot ${bindir}/gnuplot/plot_pressure_{$buoy}_rame
      /usr/bin/gnuplot ${bindir}/gnuplot/plot_temp_hum_{$buoy}_rame
      /usr/bin/gnuplot ${bindir}/gnuplot/plot_wind_{$buoy}_rame
   endif
   
   # addition of the SPN1 global and diffuse plot
   if ($buoy == "L4") then 
      set SPN_files = `find /users/rsg/observatory/buoy/pml/download/{$buoy}/*/*SPN1.dat -ctime -1 -size +0k`
      if ($#SPN_files != 0) then
         set SPN_file = `ls -1 $SPN_files | tail -1`
         echo $SPN_file
         cat $SPN_file | sed 's/S//' | sed 's/\,//' &gt; /tmp/tmp_spn1.dat
         /usr/bin/gnuplot ${bindir}/gnuplot/plot_SPN1
         set m_SPN_files = `find /users/rsg/observatory/buoy/pml/download/{$buoy}/*/*SPN1.dat -mtime -6`
         if ($#m_SPN_files &gt; 0) then 
            cat $m_SPN_files | awk 'BEGIN {FS=","; NF == 5}; {print $0}' | sed 's/S//' | sed 's/\,//' &gt; /tmp/tmp_spn1_last7days.dat
            /usr/bin/gnuplot ${bindir}/gnuplot/plot_SPN1_last7days
         endif
      endif
      
   endif
       
   # camera images
   if ($NOCAM) then
      /usr/bin/scp /users/rsg/observatory/buoy/pml/bin/images/nocam_{$buoy}.jpg /users/rsg/observatory/buoy/pml/download/{$buoy}/latest_cam.jpg 
   else
      set latest_cam = `ls /users/rsg/observatory/buoy/pml/download/${buoy}/*/*.jpg | tail -1`
      set short_fname = `echo $latest_cam:t:r | cut -c1-10`
      set year = `echo $short_fname | cut -c1-2`
      set month = `echo $short_fname | cut -c3-4`
      set day = `echo $short_fname | cut -c5-6`
      set hour = `echo $short_fname | cut -c7-8`
      set min = `echo $short_fname | cut -c9-10`
      set sfname = `echo \""20$year/$month/$day $hour":"$min"\"`
      #set sfname = `echo \""$short_fname"\"`
      echo "convert -font helvetica -fill yellow -pointsize 12 -draw 'text 150,190 ${sfname}' $latest_cam latest_cam.jpg" &gt; /tmp/cam_label.sh
      chmod u+x /tmp/cam_label.sh
      /tmp/cam_label.sh
      #/usr/bin/scp latest_cam.jpg ${webuser}@${web}:/home/rsgadmin/westernchannelobservatory.org.uk/data/buoy/download/{$buoy}
      /usr/bin/scp latest_cam.jpg /users/rsg/observatory/buoy/pml/download/{$buoy}
   endif
   
   # voltages
   set latest_volts = `ls /users/rsg/observatory/buoy/pml/download/${buoy}/*/*.sta | tail -1`
   echo "==================================================" &gt;&gt; /tmp/ancillary_data.txt
   echo "Buoy ID" $buoy &gt;&gt; /tmp/ancillary_data.txt

   # camera image
   set latest_files = `ls [a-z]*.png`
   #/usr/bin/scp $latest_files ${webuser}@${web}:/home/rsgadmin/westernchannelobservatory.org.uk/data/buoy/download/{$buoy}
   /usr/bin/scp $latest_files /users/rsg/observatory/buoy/pml/download/{$buoy}
   
   # create a text file with the latest snippet of data
   set latest_file = `ls /users/rsg/observatory/buoy/pml/download/{$buoy}/???????/*.txt | tail -1`
   set latest_met = `cat $latest_file | grep MPB | gawk '/\./{print $3,$6,$7,$5,$4,$2}' | tail -1`
   set latest_wqm = `cat $latest_file | grep WQM | gawk '/\./{print $3,$4}' | tail -1`
   set latest_gps = `cat $latest_file | grep GPS | gawk '/\./{print $3,$4}' | tail -1`
   echo "Latest GPS $#latest_gps"
   #if ($#latest_gps == 0) then
      # get latest GPS from AMOS if available
      if ($buoy == "L4") then
         set lat = `cat /users/rsg/observatory/buoy/pml/download/{$buoy}/AMOS/buoy_GPS_L4_all.txt | tail -1 | awk 'BEGIN {FS = ","; RS = "\n"} {print $3}'`
         set lon = `cat /users/rsg/observatory/buoy/pml/download/{$buoy}/AMOS/buoy_GPS_L4_all.txt | tail -1 | awk 'BEGIN {FS = ","; RS = "\n"} {print $4}'`

         set lat_degs = `echo $lat | cut -c1-2`
         set lat_decimal_mins = `echo $lat | cut -c3- | awk -v latdegs=$lat_degs '{if (latdegs &gt; 0.){printf("%6.3f\n", latdegs+$1*60./100.)}}'`
         set lon_degs = `echo $lon | cut -c1-2`
         set lon_decimal_mins = `echo $lon | cut -c3- | awk -v londegs=$lon_degs '{if (londegs &lt; 0.){printf("%6.3f\n", londegs-$1*60./100.)}}'`  
         
         #set latest_gps = `cat /users/rsg/observatory/buoy/pml/download/{$buoy}/AMOS/buoy_GPS_L4_all.txt | tail -1 | awk 'BEGIN {FS = ","; RS = "\n"} {print $3,$4}'`
         set latest_gps = `echo $lat_decimal_mins $lon_decimal_mins`

         set latest_met = `cat /users/rsg/observatory/buoy/pml/download/{$buoy}/AMOS/buoy_met_L4_all_AMOS.txt | tail -1 | awk 'BEGIN {FS = ","; RS = "\n"} {if ($8 &gt; 270.){print $7,$8+90.-360.,$9,$6,$5,$2/100.} else {print $7,$8+90.,$9,$6,$5,$2/100.}}'`
         set latest_AMOS = `ls /users/rsg/observatory/buoy/pml/download/{$buoy}/AMOS/????????/*A.txt | tail -1`
         set latest_AMOS_yyyy = `echo $latest_AMOS:t:r | cut -c1-4`
         set latest_AMOS_mm = `echo $latest_AMOS:t:r | cut -c5-6`
         set latest_AMOS_dd = `echo $latest_AMOS:t:r | cut -c7-8`
         set delim_date = `echo $latest_AMOS_dd $latest_AMOS_mm $latest_AMOS_yyyy`
         set AMOS_flag = 1
      endif
      if ($#latest_gps == 0) then 
         set latest_gps = "-10.0 -10.0"
      endif
   #endif
   set latest_par = `cat $latest_file | grep PAR | gawk '/\./{print $3}' | tail -1`
   
   # only need to distinguish beteen oxygen sensors for 2009 data
   #if ($buoy == "E1") then 
      set oxy_fl_turb = `cat $latest_file | grep WQM | gawk '/\./{print $5/100.,$6,$7}' | tail -1`
   #else
   #   set oxy_fl_turb = `cat $latest_file | grep WQM | gawk '/\./{print $5/2.23916,$6,$7}' | tail -1`
   #endif
   set latest_jjj = `echo $latest_file:t:r | cut -c5-7`
   set latest_yyyy = `echo $latest_file:t:r | cut -c1-4`
   set date = `julian -zeros $latest_jjj $latest_yyyy`
   if ($AMOS_flag == 0) then 
      set delim_date = `echo $date[1] $date[2] $date[3]`
   endif
   #echo $latest_met $latest_wqm $delim_date $oxy_fl_turb $latest_gps &gt; /tmp/buoy_latest.txt
   echo $latest_met $latest_wqm $delim_date $oxy_fl_turb $latest_gps $latest_par &gt; /tmp/buoy_latest.txt
   
   echo "Lat Lon:" $latest_gps &gt;&gt; /tmp/ancillary_data.txt
   echo "Latest Voltages" &gt;&gt; /tmp/ancillary_data.txt
   cat $latest_volts &gt;&gt; /tmp/ancillary_data.txt
   echo "Latest Files" &gt;&gt; /tmp/ancillary_data.txt
   ls -l /users/rsg/observatory/buoy/pml/download/${buoy}/*/*F.txt | tail -7 | gawk '{print $5,$6,$7,$8,$9}' &gt;&gt; /tmp/ancillary_data.txt
   ls -l /users/rsg/observatory/buoy/pml/download/${buoy}/*/*.txt | tail -1 | gawk '{print $5,$6,$7,$8,$9}' &gt;&gt; /tmp/ancillary_data.txt
   echo "Latest AIS positions from Rame Head" &gt;&gt; /tmp/ancillary_data.txt
   
   if ($buoy == "E1") then
      set MMSI = 992351026
      echo "Position should be: 50.043 -4.375" &gt;&gt; /tmp/ancillary_data.txt
   else
      set MMSI = 992351025
      echo "Position should be: 50.250 -4.217" &gt;&gt; /tmp/ancillary_data.txt
   endif
   
   pushd /users/rsg/observatory/buoy/pml/AIS/output
   grep $MMSI *.asc | tail -72 | tac &gt;&gt; /tmp/ancillary_data.txt
   popd
   
   #/usr/bin/scp /tmp/buoy_latest.txt ${webuser}@${web}:/home/rsgadmin/westernchannelobservatory.org.uk/data/buoy/download/{$buoy} 
   #/usr/bin/scp /tmp/buoy_met_{$buoy}_all.txt /tmp/buoy_wqm_{$buoy}.txt /tmp/buoy_nlf_{$buoy}.txt /tmp/buoy_cdm_{$buoy}.txt ${webuser}@${web}:/home/rsgadmin/westernchannelobservatory.org.uk/data/buoy/download/{$buoy}
   #/usr/bin/scp /tmp/ancillary_data.txt ${webuser}@${web}:/home/rsgadmin/westernchannelobservatory.org.uk/data/buoy/download

   # join together the WQM and pH sensor data
   /usr/bin/join /tmp/buoy_wqm_{$buoy}.txt /tmp/buoy_pH_{$buoy}.txt &gt; /tmp/buoy_wqm_pH_{$buoy}.txt

   /usr/bin/scp /tmp/buoy_latest.txt /users/rsg/observatory/buoy/pml/download/{$buoy} 
   /usr/bin/scp /tmp/buoy_met_{$buoy}_all.txt /tmp/buoy_wqm_{$buoy}.txt /tmp/buoy_nlf_{$buoy}.txt /tmp/buoy_cdm_{$buoy}.txt /tmp/buoy_wqm_pH_{$buoy}.txt /users/rsg/observatory/buoy/pml/download/{$buoy}
   /usr/bin/scp /tmp/ancillary_data.txt /users/rsg/observatory/buoy/pml/download

   /bin/rm -rf *.png 
   
   # push the latest buoy file to the EuroHAB ftp site
   set latest_eurohabftp = `ls /users/rsg/observatory/buoy/pml/download/${buoy}/*/*F.txt | tail -1`
   /bin/curl -T ${latest_eurohabftp} ftp://ts204bf:irreflechis-osez-deridez@eftp.ifremer.fr/eurohab/PML/buoy/NRT/daily/
   
   # put the summary files on the EuroHAB ftp site
   set latest_eurohab_summ = `ls /tmp/buoy_{met_L4_AMOS,wqm_pH_L4}.txt`
   foreach file($latest_eurohab_summ)
      /bin/curl -T $file ftp://ts204bf:irreflechis-osez-deridez@eftp.ifremer.fr/eurohab/PML/buoy/NRT/summary/
   end


end

exit(0)

</pre></body></html>