### /u/sy/beebe/courses/ieee/timops.awk, Mon Feb 11 08:15:03 2002
### Edit by Nelson H. F. Beebe <beebe@math.utah.edu>
### ====================================================================
### Convert the output results of timops.c recorded in timops.raw to
### a compact table, with one line per machine.
###
### Usage:
###	awk -f timops.awk timops.raw >outfile
###
### [11-Feb-2002]
### ====================================================================

BEGIN			{ initialize() }

/^Machine:/		{ report(); new_machine(); new_entry(); Machine = get_value($0); next }
/^CPU:/			{ CPU = get_value($0); next }
/^MHz:/			{ MHz = get_value($0); next }
/^Compiler:/		{ Compiler = get_value($0); next }
/^Time *=/		{ next }
/^sizeof/		{ report(); new_entry(); Sizeof = $3; next }
/^t_ufl_to_subnormal/	{ T_ufl_to_subnormal = $5; next  }
/^t_ufl_to_zero/	{ T_ufl_to_zero = $5; next  }
/^t_overflow/		{ T_overflow = $5; next  }
/^t_NaN/		{ T_NaN = $5; next  }
/^t_Inf/		{ T_Inf = $5; next  }

END			{ report(); close(Sort_Pipe); hrule() }

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

function get_value(s)
{
    sub("^[^:]*:","",s)
    return (trim(s))
}

function hrule()
{
    printf("-----------------------------------------------------------------------------------------------\n")
}


function initialize()
{
    # CPU MHz Compiler Sizeof T_ufl_to_subnormal T_ufl_to_zero T_overflow T_NaN T_Infxo
    FORMAT = "%-31s\t%7s\t%7s\t%7s\t%7s\t%7s\t%7s\t%7s\t%7s\n"
    hrule()
    printf(FORMAT, "CPU", "MHz", "Cmpiler", "fp_size", \
	   "ufl->", "ufl->", "ofl->", "NaN", "Inf")
    printf(FORMAT, "", "", "", "", "subnorm", "zero", "Inf", "", "")
    hrule()
    ## Sort_Pipe = "sort -t'\t' -k4n -k1"
    Sort_Pipe = "sort"
}


function new_entry()
{
    Sizeof             = 0
    T_ufl_to_subnormal = "-n/a-"
    T_ufl_to_zero      = "-n/a-"
    T_overflow         = "-n/a-"
    T_NaN              = "-n/a-"
    T_Inf              = "-n/a-"
}

function new_machine()
{
    Machine            = ""
    CPU                = ""
    MHz                = ""
    Compiler           = ""
}

function report()
{
    if ((Machine != "") && \
	(CPU != "") && \
	(MHz != "") && \
	(Compiler != "") && \
	(Sizeof != 0))
    {
	printf(FORMAT, CPU, MHz, Compiler, Sizeof, T_ufl_to_subnormal, \
	       T_ufl_to_zero, T_overflow, T_NaN, T_Inf) | Sort_Pipe
    }
}


function trim(s)
{
    gsub(/^[ \t]+/,"",s)
    gsub(/[ \t]+$/,"",s)
    return (s)
}
