#!/bin/csh

cd /moe/r0/rhart/machines/archive

set dtgs = `ls -1 */* | tail -500`
set dtg0 = `echo $dtgs[1] | cut -d"/" -f2`
set year = `echo $dtg0|  cut -c1-4`
set month = `echo $dtg0 |  cut -c5-6`
set day = `echo $dtg0 |  cut -c7-8`
set hr = `echo $dtg0 |  cut -c9-10`
set min = `echo $dtg0 |  cut -c11-12`
set mons = "JAN FEB MAR APR MAY JUN JUL AUG SEP OCT NOV DEC"
set month2 = `echo $mons | cut -d" " -f${month}`
set gdtg = "${hr}:${min}Z${day}${month2}${year}"

set machines = "moe bart homer marge barney frink maggie ned ralph abe itchy scratchy apu patti selma burns smithers eliassen sawyer seaclutter scorpio otto maude rod todd maxpower milhouse snowball2 blueberry pclamm nelson"
foreach machine ($machines)
   rm -f data.txt
   foreach dtg ($dtgs)
#      set data = `grep ">${machine}<" $dtg | cut -d">" -f35 | cut -d"<" -f1`
       set data = `grep ">${machine}<" $dtg | cut -d"G" -f2- | cut -d">" -f13 | cut -d"<" -f1`
       if ($data == "") then
                set data = "-999"
       endif
       echo $data >> data.txt
   end
   ./a.out
cat << EOF_CAT > test.ctl
dset ^data.grads
undef -999
title gfs.t00z.pgrb2f03
ydef 1 linear -90 0.5
xdef 1 linear 0 0.5
tdef 500 linear $gdtg 3MN
zdef 1 linear 1000 5
vars 1   
load 1 99 load
ENDVARS
EOF_CAT
echo $machine | grads  -clb "run plot.gs"
end
