#!/bin/csh -f

#set WINEDLLPATH="/users/rsg/phek/tools/wine/lib/wine:/users/rsg/phek/tools/wine/lib/"
set buoy="E1"

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

if ($buoy == "E1") then
	set cal_num="050"
else if ($buoy == "L4") then
	set cal_num="052"
else 
	echo "Unknown buoy, exiting ..."
	exit(1)
endif

set DISPLAY=0
set the_path="/users/rsg/observatory/buoy/pml/$buoy"
set cal_path="$the_path/cal/$cal_num/"
set data_in_path=$indir
set data_out_path="$the_path/data/output/"

set cal_file_list = (`awk '$1!~/^#/{print $1;}' $cal_path/ref.txt`)
set input_file_list = (`ls -1 $data_in_path/$filename`)
foreach cal_file ($cal_file_list) 
	set cal_id = (`awk -vid=$cal_file '$1==id&&$1!~/^#/{print $2}' $cal_path/ref.txt`)
	foreach input_file ($input_file_list)
		set base_input_file=`basename $input_file`
		set input_date=`echo $base_input_file | cut -c1-7`
		#/usr/bin/wine /users/rsg/observatory/.wine/drive_c/Program\ Files/Satlantic/SatCon/SatCon.exe "Z:/$data_in_path/$base_input_file" "Z:/$data_out_path/${buoy}_${input_date}_${cal_id}.dat" "Z:/$cal_path/$cal_file" "-ci" "-t" "-b65535" "-OverWrite=yes" "-EW=y"
		/usr/bin/wine /users/rsg/observatory/.wine/drive_c/Program\ Files/Satlantic/SatCon/SatCon.exe "Z:/$data_in_path/$base_input_file" "Z:/$data_out_path/${buoy}_${input_date}_${cal_id}.dat" "Z:/$cal_path/$cal_file" "-ci" "-t" "-b65535" "-OverWrite=yes" "-EW=y"
	end
end
exit(0)
