#!/bin/csh -f
#
# mapmetric - map a metric value into a mnemonic, if possible
#
# Some metrics (like Pattern, DISK_SORT, etc), have mnemonic names
# that are more meaningful than the number used as a code.  Each line
# of input is expected to be a single value of the given metric type;
# if there is a map known for this metric, the corresponding name is
# output; otherwise the original value is output. 
#   Maps are stored in the Map/ subdirectory of the run/bin
# directory, and are simple files with the name for value i-1 on line i.
#
set usage='usage: ... | mapmetric metricname | ... '
#
# Part of
#              The STARFISH Parallel file-system simulator
#        (Simulation Tool for Advanced Research in File Systems)
# 
#                               David Kotz
#                           Dartmouth College
#                              Version 3.0
#                              January 1996
#                          dfk@cs.dartmouth.edu

source environset

if ($#argv != 1) then
	echo "$usage"
	exit 1
endif

echo Warning: do not use mapmetric on sim files from pre-LU starfish > /dev/tty

set metric=$1
set mapfile=`runbin`/Map/$metric

if (-r $mapfile) then
    set map=(`cat $mapfile`)
    # pass stdin through the following awk script
    gawk 'BEGIN { split("'"$map"'", map, " "); }\
	{ print map[$1+1] }'

else

    # no map file; just pass right on through
    cat

endif
