#!/bin/sh #------------------------------------------------------------- # standard HYSPLIT distribution clustering program # 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 cluster model simulation variables # TCLUS list of endpts files clustered # TNOCLUS list of endpts files not clustered # [cluster number; number trajs/cluster; traj YR, MO, DA, HR] # CLUSTER list of clusters and component trajs for each cluster step # DELPCT list of percent change in TSV by step # CLUSTERno as CLUSTER but for trajs not clustered # CMESSAGE diagnostic output from clustering program tdur=48 # hours to cluster along trajectory eint=1 # endpoint interval to use (hours) skip=1 # skip trajectory interval proj=0 # 0=auto 1=polar 2=Lambert 3=Merc 4=CylEqu # set trajectory color scheme for trajplot let ii=1 kol="" while [ $ii -le $nc ]; do kol="$kol$ii" ii=`expr $ii + 1` done # create clustering control file echo $tdur > CCONTROL echo $eint >> CCONTROL echo $skip >> CCONTROL echo ${OUT}/${SUB}/ >> CCONTROL echo $proj >> CCONTROL # do clustering (uses INFILE) rm -f TCLUS TNOCLUS CLUSTER DELPCT CLUSTERno CMESSAGE $MDL/cluster 1>/dev/null 2>/dev/null if [ ! -f CLUSTER -o ! -f DELPCT ]; then echo "ERROR - cluster failed" exit fi echo "Clustering stop: `date`" #---------------------------------------------------- # generate list of trajs in each cluster number <= nc # important that file name ends with _$nc for trajplot # this file used in other post-processing applications rm -f CLUSLIST_${nc} $MDL/cluslist -iCLUSTER -n${nc} -oCLUSLIST_${nc} 1>/dev/null 2>/dev/null if [ ! -s CLUSLIST_${nc} ]; then echo "ERROR - cluslist failed" exit fi #---------------------------------------------------- # 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 if [ -s $tmout ]; then 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 meantraj1.html open meantraj1.html else echo "ERROR - trajplot" exit fi fi # cleanup rm -f INFILE rm -f CCONTROL rm -f TCLUS TNOCLUS CLUSTERno CMESSAGE rm -f CLUSTRAJ?_? rm -f MEAN.LIST Cmean.tdump C?mean.tdump rm -f LABELS.CFG rm -f CLUSLIST_${nc} rm -f CLUSTER rm -f DELPCT