#!/bin/csh -f
# Module: process_storx.csh
# Author: Tim Smyth
# Date: 25/9/2008
#
# Script to call the IDL routine that processes the storx data
#
setenv NCS_SHUTUP
source ~panorama/panorama/config/setup
unsetenv NCS_SETUP
umask 002


set dataroot = "/users/rsg/observatory/buoy/pml"

if $#argv != 1 then
   echo "USAGE: storx_conv.csh <E1|L4>" 
   exit(1)
else
   set buoy="$argv[1]"
endif

if ($buoy == "E1") then
   set datadir = "$dataroot/$buoy/data/input/today"
else if ($buoy == "L4") then
   set datadir = "$dataroot/$buoy/data/input/today"
else 
   echo "Unknown buoy, exiting ..."
   exit(1)
endif

set procdir = "$dataroot/$buoy/data/input/processed"
set outdirroot = "$dataroot/$buoy/data/output"

# Look in the today directory for files to be processed
foreach files($datadir/*.{RAW,raw})
   set filename = `echo $files:t`
   set year = `echo $filename | cut -c1-4`
   set julday = `echo $filename | cut -c5-7`
   echo $filename
   set command = "read_storx, filename='$filename', buoyid='$buoy', indir='$datadir'"
   echo "$command" | sh -cf "$IDL_DIR/bin/idl | idl_filter "
   # now move the input file into the processed directory
   /bin/mv $files $procdir
   # move the products into the output directory with yyyy/jjj format
   mkdir -p $outdirroot/$year/$julday
   /bin/mv $outdirroot/${buoy}_${year}${julday}*.dat $outdirroot/$year/$julday
end

exit(0)


