#!/bin/sh #------------------------------------------------------------- # Revised (version 2) clustering program for faster results # script to cluster trajectories for one year where # the endpoint files are named T{YYYY}{MM}{DD}{HH} #------------------------------------------------------------- # set default directory structure CWD=$PWD # starting directory for script MDL="$HOME/Hysplit/exec" # executables directory MAP="$HOME/Hysplit/graphics" # location of hysplit map background OUT="$HOME/Temp" # parent directory for results SUB="S001" # subdirectory with endpoint files SYR="1990" # start year to cluster nc=6 # final number of clusters echo "Clustering start: `date`" cd ${OUT}/${SUB} # add all trajectory file names rm -f INFILE ls T${SYR}?????? >INFILE # set trajectory color scheme for trajplot let ii=1 kol="" while [ $ii -le $nc ]; do kol="$kol$ii" ii=`expr $ii + 1` done # Faster Version 2 of clustering program $MDL/cluster2 -iINFILE -oCLUSLIST -n${nc} echo "Clustering stop: `date`" #---------------------------------------------------- # create a file list for trajectories in each cluster # named CLUSTRAJx_$nc where x=cluster number (1 to $nc) rm -f CLUSTRAJ?_? if $MDL/clusmem -iCLUSLIST_${nc} -oCLUSTRAJ 1>/dev/null 2>/dev/null; then run=0 rm -f MEAN.LIST Cmean.tdump C?mean.tdump while [ $run -lt $nc ]; do run=`expr $run + 1` # create plot of individual trajectories in cluster rm -f LABELS.CFG echo "'TITLE&','Trajectories in Cluster ${run} of ${nc}&'" >LABELS.CFG $MDL/trajplot +g1 -j${MAP}/arlmap -i+CLUSTRAJ${run}_${nc} -z80 \ -k${nc}:$kol -v4 1>/dev/null 2>/dev/null mv trajplot.html C${run}traj.html rm -f LABELS.CFG # compute mean trajectory for each cluster $MDL/trajmean -i+CLUSTRAJ${run}_${nc} -oC${run}mean.tdump \ 1>/dev/null 2>/dev/null if [ ! -s C${run}mean.tdump ]; then echo "ERROR - trajmean CLUSTRAJ${run}_${nc}" exit fi # add mean trajectory file name to file of file names echo "C${run}mean.tdump" >> MEAN.LIST done # merge the mean cluster trajectories into one file tmout=Cmean.tdump rm -f $tmout $MDL/merglist -i+MEAN.LIST -oCmean -ptdump 1>/dev/null 2>/dev/null if [ ! -s $tmout ]; then echo "ERROR - merglist MEAN.LIST" exit fi else echo "ERROR - clusmem" exit fi # compute/plot mean traj for each cluster # adjust title from loop variables rm -f LABELS.CFG echo "'TITLE&','Cluster Mean Trajectories for $SYR&'" >LABELS.CFG $MDL/trajplot +g1 -j${MAP}/arlmap -i$tmout -z80 -k${nc}:$kol -v4 \ 1>/dev/null 2>/dev/null if [ -s trajplot.html ]; then mv trajplot.html meantraj2.html open meantraj2.html else echo "ERROR - trajplot" exit fi # cleanup rm -f INFILE rm -f CLUSTRAJ?_? rm -f Cmean.tdump rm -f MEAN.LIST C?mean.tdump rm -f LABELS.CFG rm -f CLUSLIST_${nc}