<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">#!/bin/csh
# Module: get_iridium_amos_data.csh
# Author: James Fishwick &amp; Tim Smyth
# Date: 07/07/2022
# Version: 1.1
#
# Script to download the AMOS data from the L4 buoy

# THIS SCRIPT HAS BEEN UPDATED 2023-08-02 TO REFLECT NEW PATHS FOR DATA - jpe #

alias julian /users/rsg/panorama/panorama.svn/bin/julian

echo "================================="
echo "Running get_iridium_amos_data.csh"
date 
set execdir = /users/rsg/observatory/buoy/pml/bin
#set downloaddir = /users/rsg/observatory/buoy/pml/download/L4_2G/AMOS/clone
set downloaddir = /data/datasets/Buoys/L4/AMOS/clone/
#set finaldir = /users/rsg/observatory/buoy/pml/download/L4_2G/AMOS
set finaldir = /data/datasets/Buoys/L4/AMOS/
#set oldfinaldir = /users/rsg/observatory/buoy/pml/download/L4
set oldfinaldir = /data/datasets/Buoys/L4/download/
set base = 144
set HH = `date --utc +%k`
@ base = $base + $HH

# Get the AMOS buoy messages from Sharepoint
# and rclone into a safe directory
/bin/rclone sync --update --verbose --transfers 30 --checkers 8 --contimeout 60s --timeout 300s --retries 3 --low-level-retries 10 --stats 1s "sharepoint-WCO:/General/Data/L4/Buoy/AMOS" $downloaddir 

# Move the files into day specific directories
set sbdfiles = `glob $downloaddir/*.sbd`
# Move the files into day specific directories
foreach infile ( `find $downloaddir -name \*.sbd ` )
   /bin/mv $infile $finaldir
end

# Only loop over the sbd files if there are any to process
if ($#sbdfiles &gt; 0) then 
   foreach file($finaldir/*.sbd)
      #echo $file 
      set datename = `cat $file | sed -e 's/\,/\ /g' | tr '\n' '\t' | awk '{print $2, $3}'`
      set yy = `echo $datename | cut -c5-6`
      set mm = `echo $datename | cut -c3-4`
      set dd = `echo $datename | cut -c1-2`
      set hh = `echo $datename | cut -c8-9`
      set mi = `echo $datename | cut -c10-11`
      set yyyy = `echo 20$yy`

      set nchar = `echo $yyyy$mm$dd | wc -m`
      /bin/mkdir -p $finaldir/$yyyy$mm$dd
      set stem = `echo $file:t:r | cut -c1-15`
      /bin/mv $file $finaldir/$yyyy$mm$dd
      # move to the created directory to find files of different types
      pushd $finaldir/$yyyy$mm$dd &gt; /dev/null

      # atmospheric files (A.txt for final version)
      # remove previous versions of the file
      /bin/rm ${yyyy}${mm}${dd}A.txt
      set fs_atm = `ls *.sbd`
      foreach f_atm($fs_atm)
         dos2unix -q $f_atm
         cat $f_atm | tr '\n' ',' | tr -s "\*" "," &gt;&gt; ${yyyy}${mm}${dd}A.txt
         echo "" &gt;&gt; ${yyyy}${mm}${dd}A.txt
      end 
      popd &gt; /dev/null
   end
endif

# delete everything on the Sharepoint Drive older than 1 day
/bin/rclone delete --min-age 1d "sharepoint-WCO:/General/Data/L4/Buoy/AMOS"

# make long files for all the parameters
# Met files - this is more consistent with the current output from the E1 buoy
echo "Creating time-series met files"
cat $finaldir/????????/*A.txt | awk 'BEGIN {FS = ","; RS = "\n"} \
    {if ($1 ~ /2/ &amp;&amp; $5 &lt;= 504600 &amp;&amp; NF &gt;= 13) \
    {printf "$W5M5A,%02d%02d%02d,%04d05,5206001e45259026,1,L4_Buoy,%2.4fN,%1.4fW,%3.1f,%2.2f,%2.1f,-9.99,%3.1f,%4.2f,-9.99,%2.1f,-9.99,-9.99,-9.99,-9.99,02A\n",\
    substr($2,5,2),substr($2,3,2),substr($2,1,2),$3,$5/10000,-$6/10000,$11/100,$10/10,$12/10,$7/10,$8/10,$9/100}}' \
    &gt; $finaldir/buoy_met_L4_all_AMOS.txt
 
# GPS information
echo "Creating time-series GPS files"
# find if there are new files
set newatm = `find $finaldir -name \*A.txt -mmin -120`
echo $#newatm

cat $finaldir/????????/*A.txt | awk 'BEGIN {FS = ","; RS = "\n"} {if ($1 ~ /2/) \
   {printf "%02d%02d%02d %04d05 %2.4fN %1.4fW\n",substr($2,5,2),substr($2,3,2),substr($2,1,2),$3,$5/10000,-$6/10000}}' \
    &gt; $finaldir/buoy_GPS_L4_all.txt

echo "Creating last ${base} hours plot (Met)"
cat $finaldir/buoy_met_L4_all_AMOS.txt | tail -${base} | awk 'BEGIN {FS=","} {print $2$3,$9,$10,$11,$12,$13,$14,$15,$16}' &gt; /tmp/buoy_met_L4.txt

# Final data for table on web
echo "Creating short table file"
set short_metdata = `cat $finaldir/buoy_met_L4_all_AMOS.txt | tail -1 | awk 'BEGIN {FS = ","; RS = "\n"} {print $16,$10,$9,$10,$13,substr($3,1,2)}'`
set short_GPS = `cat $finaldir/buoy_GPS_L4_all.txt | tail -1 | sed 's/N//g' | sed 's/W//g' | awk '{print $3,-$4}'`
set last_date = `cat $finaldir/buoy_met_L4_all_AMOS.txt | tail -1 | awk 'BEGIN {FS = ","; RS = "\n"} {print $2}'`
set yy = `echo $last_date | cut -c1-2`
set yyyy = `echo "20"$yy`
set mm = `echo $last_date | cut -c3-4`
set dd = `echo $last_date | cut -c5-6`
set short_metdata_waves = "-9.99 -9.99 -9.99 -999"
set short_temp_sal = `echo "-9.99 -9.99"`
set short_oxy_chl_turb = "-9.99 -9.99 -9.99"
set short_PAR = "-9.99"

# extract the latest temperature (and salinity) from CR6 file
set short_temp_sal = `cat /tmp/buoy_latest_CR6.txt | awk '{print $7,$8}'`
set short_metdata_waves = `cat /tmp/buoy_latest_CR6.txt | awk '{print $18,$19,$20,$21}'`

echo "Creating short table file"
echo $short_metdata $short_temp_sal $dd $mm $yyyy $short_oxy_chl_turb $short_GPS $short_PAR $short_metdata_waves &gt; $oldfinaldir/buoy_latest_AMOS.txt

echo "Creating plots for the web"
pwd
/usr/bin/gnuplot /users/rsg/observatory/buoy/pml/bin/gnuplot/plot_temp_hum_ODAS51_L4
/usr/bin/gnuplot /users/rsg/observatory/buoy/pml/bin/gnuplot/plot_pressure_ODAS51_L4
/usr/bin/gnuplot /users/rsg/observatory/buoy/pml/bin/gnuplot/plot_wind_ODAS51_L4

#set latest_files = `/bin/ls [a-z]*_AMOS.png`
#/bin/mv -v $latest_files $oldfinaldir

/bin/scp /tmp/temp_hum_AMOS.png $oldfinaldir
/bin/scp /tmp/pressure_AMOS.png $oldfinaldir
/bin/scp /tmp/wind_AMOS.png $oldfinaldir

# Making AMOS the default (until can rely on CR6 data)
/bin/scp /tmp/temp_hum_AMOS.png $oldfinaldir/temp_hum.png
/bin/scp /tmp/pressure_AMOS.png $oldfinaldir/pressure.png
/bin/scp /tmp/wind_AMOS.png $oldfinaldir/wind.png
/bin/scp $oldfinaldir/buoy_latest_AMOS.txt $oldfinaldir/buoy_latest.txt


exit(0)


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