#!/bin/sh
#set verbose

# This script runs through a data set and extracts 
# raw tabular data for the web pages, then processes it a bit
# for same.

ARG=$1
DIR=`basename $1 .db`
WWW=~/WorkSpace/STREAM/MASTER/WebSite
AWK=awk
ECHO=/bin/echo

#echo "$0: argument is " $ARG 
#echo "$0: directory is " $DIR 
#echo "$0: www target is " $WWW 

# The files and their contents are:
#	Bandwidth	- name, ncpus, COPY, SCALE, ADD, TRIAD
#	MFLOPS		- name, ncpus, SCALE/16., ADD/24., TRIAD/12.
#	Balance		- name, ncpus, TRIAD, ncpus*clock*(ops/clock)/TRIAD

# Field Key:
# 1	name
# 2	ncpus
# 3	bytes/word
# 4	COPY
# 5	SCALE
# 6	ADD
# 7	TRIAD
# 8	Clock (MHz)
# 9	Peak FP Ops/clock
# 10	shared memory?
# 11	distributed memory?
# 12	Uniprocessor?
# 13	Other?
# 14	Experimental or assembly language results?
# 15    obsolete/old/superceded?
# 16    P (PC) / M (Mac) / N (other) / C (cluster)
# 17    date
# 18    link to html file containing original submission data

#=======================================================================

$ECHO "	Building Bandwidth Table"
rm -f $DIR/Bandwidth.tbl
$ECHO "STREAM Memory Bandwidth --- John D. McCalpin, mccalpin@cs.virginia.edu"	>>$DIR/Bandwidth.tbl
$ECHO -n "Revised to "						>>$DIR/Bandwidth.tbl
date								>>$DIR/Bandwidth.tbl
$ECHO ""								>>$DIR/Bandwidth.tbl
$ECHO "All results are in MB/s --- 1 MB=10^6 B, *not* 2^20 B"    >>$DIR/Bandwidth.tbl
$ECHO ""								>>$DIR/Bandwidth.tbl
$ECHO "--------------------------------------------------------------------------------------------" >>$DIR/Bandwidth.tbl
$ECHO "Sub. Date   Machine ID                      ncpus    COPY      SCALE        ADD      TRIAD" >>$DIR/Bandwidth.tbl
$ECHO "--------------------------------------------------------------------------------------------" >>$DIR/Bandwidth.tbl
# $AWK -F, '{printf("%-24s %5d %#8.1f %#8.1f %#8.1f %#8.1f <a href=\"../stream_mail/%s\">data</a>\n",$1,$2,$4,$5,$6,$7,$18)}' <$ARG >>$DIR/Bandwidth.tbl
$AWK -F, -f Bandwidth.awk  <$ARG >>$DIR/Bandwidth.tbl
$ECHO "--------------------------------------------------------------------------------------------" >>$DIR/Bandwidth.tbl
cat $DIR/.html_header $DIR/Bandwidth.tbl $DIR/.html_trailer >$DIR/Bandwidth.html
cp $DIR/Bandwidth.html $WWW/$DIR

#=======================================================================

$ECHO "	Building MFLOPS Table"
rm -f $DIR/MFLOPS.tbl
$ECHO "STREAM Memory MFLOPS --- John D. McCalpin, mccalpin@cs.virginia.edu"	>>$DIR/MFLOPS.tbl
$ECHO -n "Revised to "						>>$DIR/MFLOPS.tbl
date								>>$DIR/MFLOPS.tbl
$ECHO ""								>>$DIR/MFLOPS.tbl
$ECHO "All results are in MFLOPS --- 1 MFLOPS=10^6 FP OPS/sec"   >>$DIR/MFLOPS.tbl
$ECHO ""								>>$DIR/MFLOPS.tbl
$ECHO "----------------------------------------------------------------------------" >>$DIR/MFLOPS.tbl
$ECHO "Sub. Date   Machine ID                      ncpus  SCALE      ADD    TRIAD" >>$DIR/MFLOPS.tbl
$ECHO "----------------------------------------------------------------------------" >>$DIR/MFLOPS.tbl
#$AWK -F, '{printf("%-24s %5d %#8.1f %#8.1f %#8.1f\n",$1,$2,$5/16.,$6/24.,$7/12.)}' <$ARG >>$DIR/MFLOPS.tbl
$AWK -F, -f MFLOPS.awk <$ARG >>$DIR/MFLOPS.tbl
$ECHO "----------------------------------------------------------------------------" >>$DIR/MFLOPS.tbl
cat $DIR/.html_header $DIR/MFLOPS.tbl $DIR/.html_trailer >$DIR/MFLOPS.html
cp $DIR/MFLOPS.html $WWW/$DIR


#=======================================================================

$ECHO "	Building Balance Table"
rm -f $DIR/Balance.tbl
$ECHO "STREAM Machine Balance --- John D. McCalpin, mccalpin@cs.virginia.edu"	>>$DIR/Balance.tbl
$ECHO -n "Revised to "						>>$DIR/Balance.tbl
date								>>$DIR/Balance.tbl
$ECHO ""								>>$DIR/Balance.tbl
$ECHO "Balance is Peak MFLOPS divided by Triad Bandwidth in MW/s">>$DIR/Balance.tbl
$ECHO "------------------------------------------------------------------------------" >>$DIR/Balance.tbl
$ECHO "Submission  System                                   Peak       BW     Machine		" >>$DIR/Balance.tbl
$ECHO "Date        Machine ID                      ncpus   MFLOPS    (MW/s)   Balance		" >>$DIR/Balance.tbl
$ECHO "------------------------------------------------------------------------------" >>$DIR/Balance.tbl
#$AWK -F, '$8 > 0.0 && $9 > 0.0 && $7 > 0.0 {printf("%-24s %5d %#8.1f %#8.1f %#8.1f\n",$1,$2,$2*$8*$9,$7/$3,$2*$8*$9/($7/8.0))}' <$ARG >>$DIR/Balance.tbl
$AWK -F, -f Balance.awk <$ARG >>$DIR/Balance.tbl
$ECHO "------------------------------------------------------------------------------" >>$DIR/Balance.tbl
cat $DIR/.html_header $DIR/Balance.tbl $DIR/.html_trailer >$DIR/Balance.html
cp $DIR/Balance.html $WWW/$DIR

#==================================================================
