#!/bin/csh -f

wget http://www.swpc.noaa.gov/ftpdir/latest/dayind.txt

set datadate=`grep "^:Solar_Radio_Flux:" dayind.txt | cut -d ":" -f3`

set yr=`echo $datadate | cut -c 1-4`
set mn=`echo $datadate | cut -c 6-8`
set dy=`echo $datadate | cut -c 10-11`

set date_string=`date -d "$mn $dy $yr" +%Y%m%d`

set a=`grep "^ 1415" dayind.txt | cut -c 10-`

@ i=1
@ sum=0
while ($i <= 7)
    if ($a[$i] > 0) then
    @ sum = $sum + $a[$i]
    endif
    @ i++
end

set flux=`echo "scale=1;$sum/4" | bc`
echo $date_string $flux

rm dayind.txt

exit
