#! /bin/csh -f # Last edited on 2008-05-03 14:30:39 by stolfi set PROG_NAME = "$0" set PROG_DESC = "plots the number of messages in mail folders per month and type." set PROG_HELP = ( \ ''"${PROG_NAME}"' \\' \ '\n {OUTDIR} {INIMONTH} {FINMONTH} {TYPE1} {TYPE2} {TYPE3}\\' \ '\n [ -help ] [ -info ]' \ ) set PROG_INFO = ( \ 'NAME' \ '\n '"${PROG_NAME}"' - '"${PROG_DESC}"'.' \ '\n' \ '\nSYNOPSIS' \ '\n '"${PROG_HELP}"'' \ '\n' \ '\nDESCRIPTION' \ '\n Reads the files "{OUTDIR}/froms/{TYPE}.cts" where {TYPE} is "{TYPE1}",' \ '\n "{TYPE2}", and "{TYPE3}". Each line of each input file' \ '\n should have the format "{COUNT} {MONTH}" where {COUNT} is an' \ '\n integer and {MONTH} is a year-month number in the format' \ '\n "{YYYY}-{MM}". Writes a PNG image file called' \ '\n' \ '\n "{OUTDIR}/{INIMONTH}--{FINMONTH}-mail-per-month.png",' \ '\n' \ '\n containing a bar plot of the message counts in the four categories.' \ '\n' \ '\n The arguments {INIMONTH} and {FINMONTH} too must have the' \ '\n format "{YYYY}-{MM}".' \ '\n' \ '\nSEE ALSO' \ '\n find-all-sources(1)' \ '\nAUTHOR' \ '\n Created 2008-05-02 by Jorge Stolfi, Unicamp' \ ) # ---------------------------------------------------------------------- # INTERNAL OPTIONS # ---------------------------------------------------------------------- # COMMAND LINE PARSING # Parse command line switches (keyword parameters): while ( ( $#argv > 0 ) && ( "/$1" =~ /-* ) ) if ( ( $#argv >= 1 ) && ( "/$1" == "/-help" ) ) then shift; printf "usage:\n ${PROG_HELP}\n"; exit 0 else if ( ( $#argv >= 1 ) && ( "/$1" == "/-info" ) ) then shift; printf "${PROG_INFO}"; exit 0 else echo "unknown option $1"; printf "usage:\n ${PROG_HELP}\n"; exit 1 endif end # Parse remaining command line arguments (positional parameters): if ( $#argv != 6 ) then printf "usage:\n ${PROG_HELP}\n"; exit 1 endif set outdir = "$1"; shift set inimonth = "$1"; shift set finmonth = "$1"; shift set type1 = "$1"; shift set type2 = "$1"; shift set type3 = "$1"; shift set msgperiod = "${inimonth}--${finmonth}" # The plot's X range must be wider than the given month range, because of labels: set lomonth = `gawk -v mo="${inimonth}" 'BEGIN{ gsub(/-[0-9][0-9]$/,"",mo); printf "%04d-09", mo-1 }'` set himonth = `gawk -v mo="${finmonth}" 'BEGIN{ gsub(/-[0-9][0-9]$/,"",mo); printf "%04d-03", mo+1 }'` echo "xrange = [${lomonth}:${himonth}]" # Exclude data points outside the given month range: foreach tp ( ${type1} ${type2} ${type3} ) echo "=== ${tp} =======================" cat ${outdir}/froms/${tp}.cts \ | gawk -v ini="${inimonth}" -v fin="${finmonth}" \ ' // { mo=$2; if ((mo >= ini) && (mo <= fin)) print $2, $1; } ' \ | sort -k1,1 \ > /tmp/${tp}.cts cat /tmp/${tp}.cts end # Create the plot image: gnuplot <