jbgraph 32.2 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022
#!/bin/sh

# THIS SCRIPT IS A "WRAPPER" FOR: gnuplot
#
# - The data used is in "gnuplot" format to compare and contrast
# - information for analysis in the Judy project.  Circa:  05/12/2000.

# Author:  Bob Gobeille,  # Original functionality.
#          Jer/ Eberhard, # Ongoing maintenance, added functionality.

 RCS_SCRIPT='
# @(#) $Revision: 2.24 $ $Source: /judy/src/apps/benchmark/jbgraph $
'


# SET VERBOSE TO QUIET, SILENT (DEFAULT):
#
# - then find out if verbose mode is to be set.

    OPT_v="${OPT_v:--q}"		# Set verbose off, (default).
    v='eval #'				# Set verbose off, (quiet).

    VERBOSE="`echo ${*} | tr ' ' '\012' | grep -- -v`"
    if [ "${VERBOSE}" = "-v" ]; then	# -v verbose mode on.
	OPT_v="${VERBOSE}"		# Will be "-v".
        v=""				# Set verbose on.
    fi
    unset VERBOSE			# Unset after last use.


# CREATE NAMESPACE:
#
# - Set names of OUTPUT and WORK directories and files.

    C="`basename ${0:-jbgraph}`"	# Command name of this script.
    C_PATH="${0}"			# Called via this path.
    C_rc=".${C}.rc"			# .rc file, local or ${HOME}.
    OUTPUT_DIR=./tmp/`echo ${C} | tr "[a-z]" "[A-Z]"` # output name in caps

    mkdir -p ${OUTPUT_DIR}              # Create output directory.
    if [ ! -d "${OUTPUT_DIR}" ]; then   # Ensure dir exists.
        echo "${C}.${0}:  ERROR, unable to:  mkdir -p ${OUTPUT_DIR}"
        exit 3
    fi


# UNCOMMENT THE DATE_TIME FORMAT YOU WANT TO USE:

    #DATE_TIME="`date +%y%m`"		# Monthly    Date/Time stamp.
    #DATE_TIME="`date +%y%m%d`"		# Daily      Date/Time stamp.
    DATE_TIME="`date +%y%m%d.%H%M`"	# HourMinute Date/Time stamp.

    COMMAND="${OUTPUT_DIR}/${DATE_TIME}" # Output filename date/time stamp.
    WORK1="${COMMAND}.WORK1.$$"		# Work file 1.
    WORK2="${COMMAND}.WORK2.$$"		# Work file 2.
    WORK3="${COMMAND}.WORK3.$$"		# Work file 3.
    WORK4="${COMMAND}.WORK4.$$"		# Work file 4.


# CREATE AND DISPLAY SCRIPT DEFAULTS AND INFO:

    export GNU_CMDFILE="${GNU_CMDFILE:-$COMMAND.GNU_CMDFILE}" # GNU_CMDFILE name
    ${v}touch ${COMMAND}                    # Ensure the output file exists.
    # Produce sample monitor and print commands.
    INFO="`echo \"${C}:  follow output, or print by:
    rerun by executing the first commented line in:
      ${GNU_CMDFILE}
    head -1 ${GNU_CMDFILE} # or
    tail -f ${COMMAND} # tail and follow log file or
    tail    ${COMMAND} # tail log file or print:
    fold -80 ${COMMAND} |
      pr -f -l66 -h${COMMAND} |
      remsh jerslash -l jer lp -odouble -o2\"`"
    if [ "${OPT_v}" = "-v" ]; then	# -v verbose mode.
        echo "${INFO}"
    fi


# DEFINE DEFAULTS, CONSTANTS, VARIABLES:
#
# - 80 Column line---------------------------------------------------01234567890

# Break line:  BL is 70 columns of "-".

    BL="----------------------------------------------------------------------"

    EXT_OPT="${EXT_OPT:-}"		# Allow external option setting.

# GNU_GEOMETRY default:  
# - Note, this will respect an environment variable, which could be set as:
# - export OPT_JBGRAPH_geometry="600x450+20+20" # 4x3 aspect ratio.

    OPT_JBGRAPH_geometry="${OPT_JBGRAPH_geometry:-1000x750+20+20}"
    GNU_GEOMETRY_DEF="1000x750+20+20"	# 4x3 aspect ratio, default.
    GNU_GEOMETRY="-geometry ${OPT_JBGRAPH_geometry:-$GNU_GEOMETRY_DEF}"

# GNU_PSFILE name, (default):

    GNU_PSFILE="${OPT_JBGRAPH_psfile:-$COMMAND.GNU_PSFILE}" 

    LP_DEV_DEF="${LP_DEV:-pastel}"	# Printer device (default).
    LP_OPT_DEF="${LP_OPT:--olandscape}"	# Printer options (default).

# PLOT AXIS NAMES:

    XLABEL="${XLABEL:-Population}"	# Set default.
    YLABEL_MALLOC="${YLABEL:-Bytes}"	# Set default.
    YLABEL_TIME="${YLABEL:-USec/index}" # Set default.
    YLABEL="${YLABEL:-$YLABEL_TIME}"	# Set default.

# ARRAY OF COLUMN NAMES:
#
# - Add column names here (from benchutils.c).
# - These are the column names displayed on "gnuplot".

    CHA[0]="CHA=COLUMN HEADINGS ARRAY"
    CHA[1]="index number"
    CHA[2]="insert time per index"
    CHA[3]="dT/dI insert"
    CHA[4]="retrieve time per index"
    CHA[5]="dT/dI retrieve"
    CHA[6]="bytes used"
    CHA[8]="bytes free"
    CHA[9]="bytes alloced"
    CHA[7]="dM/dI change in memory per index"
    CHA[10]="leaf count"
    CHA[11]="leaf average size"
    CHA[12]="leaf memory used per index"
    CHA[13]="branch count"
    CHA[14]="branch average size"
    CHA[15]="branch memory used per index"
    CHA[16]=""
    CHA[17]=""
    CHA[18]=""
    CHA[19]=""
    CHA[21]=""
    CHA[22]=""
    CHA[23]=""
    CHA[24]=""
    CHA[25]=""
    CHA[26]=""
    CHA[27]=""
    CHA[28]=""
    CHA[29]=""
    CHA[30]=""
    CHA[31]=""
    CHA[32]=""
    CHA[33]=""
    CHA[34]=""
    CHA[35]=""
    CHA[36]=""
    CHA[37]=""
    CHA[38]=""
    CHA[39]=""
    CHA[40]=""
    CHA[41]=""
    CHA[42]=""
    CHA[43]=""
    CHA[44]=""
    CHA[45]=""
    CHA[46]=""
    CHA[47]=""
    CHA[48]=""
    CHA[49]=""
    CHA[50]=""

    CMN="0"				# Column number for CHA data.

#
# SET DEFAULT OPTIONS:
#

    OPT_E="-E"				# -E use embedded options
    OPT_L="-L"				# -L set logscale axis
    OPT_L_xaxis="x"			# -L set logscale x axis
    OPT_L_yaxis="y"			# -L set logscale y axis
    OPT_H="-H"				# -H default column headings.


# M A I N:   MAIN PROGRAM:
# 
# - Begin main script, functions first.

{

FUNCTION__getopt()			# Use function getopt.
{
# PARSE THE COMMAND LINE FOR OPTIONS, USING GETOPT:
#
# - define USAGE message.
# - use getopts.
# Note:  FUNCTION__getopt is run twice, in order to support:
#        FUNCTION_TITLE_COLHEAD()	# Set Column headings from file.

    ${v}echo "${C}.${0}:  beginning at `date`"	# beginning of function

    USAGE="${C} [ -E -G -H -I -M -S -V -i -l -m -q -r -u -v ]
	[ -C GNU_CMDFILE ]
	[ -D LP_DEV ]
	[ -L axis ]
	[ -N not option ] (turn off option), Example:  -NL
	[ -P GNU_PSFILE ]
	[ -c COLUMN_NUMBER ]
	[ -d differential_type ]
	[ -g GNU_GEOMETRY ]
	[ -o LP_OPT ]
	[ -x xRANGE ]
	[ -y yRANGE ]

    ${C}:  wrapper for gnuplot

    -c plot column number.  This is useful to plot by column number.
    -i plot insert; default if no other plots selected.      CMN=2
    -r plot retrievals; default if no other plots selected.  CMN=4
    -I plot memory used / index.                             CMN=12
    -m plot memory malloced.                                 CMN=9
    -M plot memory used and free.                            CMN=8
    -l plot leaf data.                                       CMN=11
    -d plot derivative data.  Useful with -i, -r, -m.  CMN=2,4,9

    -x xRANGE, scale range;  example:  -x [1000:5000] or -x1000:5000
    -y yRANGE, scale range;  example:  -y [1M:10M]    or -y1M:10M
	 1[kK] = 1,000; 1[mM] = 1,000,000; 1[gG] = 1,000,000,000.

    -n number plot descriptions; Use column numbers before the description.
    -L set logscale axis; default,
	Example:  Turn off logscale with -NL, then turn on, on only one axis:
	  \"-NL -Lx\" or \"-NL -Ly\", Turn off both with -NL
    -G grid lines on.
    -H default column headings.
    -g geometry description.
	 default=\"${GNU_GEOMETRY_DEF}\", # 4x3 aspect ratio.

    -E use embedded options, default, Turn off with -NE. 
      Sets TITLE, COLHEAD, GETOPT from the FIRST data file encountered.
      Example:  embedded options in the data file begin in column 1:
      # TITLE This is the title to pass to gnuplot
      # COLHEAD 1 This is the heading for column 1.
      # XLABEL This is the x-axis label
      # YLABEL This is the y-axis label
      # GETOPT -c2 -c3 -G	# These are the options to use.

    -p print the plot.
    -o LP_OPT printer option(s);  default \"${LP_OPT_DEF}\".
	 Example:  \"-ootray2\" will print on clear slides, emits \"-otray2\"
	 Example:  \"-on2\" will print two copies, emits \"-n2\"
    -D LP_DEV printer device;  default \"${LP_DEV_DEF}\".

    -C GNU_CMDFILE name;  default is generated and removed: 
         ${OUTPUT_DIR}/{DATE_TIME}.GNU_CMDFILE
	 Useful to do your own gnuplot command editing and debugging.
    -P GNU_PSFILE name.  default is generated and removed:
         ${OUTPUT_DIR}/{DATE_TIME}.GNU_PSFILE
    -S Save files.
	 Generated and working file names are deleted unless -S or -C is on.
	 User provided file names are not deleted in any case (-C, -P).

    -q quiet mode, verbose mode off;  default.
    -v verbose mode on.

    -V vi the plot file.
       quit using \"q\"

    -N not option;  Turn specified option off.  Example:  -NL
         Note, -N is not available for all options.
    -NL Turn off:  -L set logscale axis; default
    -NH Turn off:  -H default column headings.

    -u Usage message.

    Sample usage:
    ${C} -i  -f data/datafile	# -i is the same as -c1.
    ${C} -c1 -f data/datafile	# -i is the same as -c1.

     "

    ${v}echo "${C}.${0}:  OPTIONS=${*}"

# Parse options, using getopt:
#
# - "a" option, no parameter; "b:" indicates a parameter.
# - Order of options is "man 5 ascii".

    getopt_PARM="?C:D:EGIL:MN:P:SVc:d:g:ilmno:prsuvx:y:"
    set -- `getopt ${getopt_PARM} $*`	# Place options in argc/argv.
    if [ "${?}" != "0" ]; then		# If getopt returns an errror.
        ${v}echo "${C}.${0}:  \${?}=${?}, USAGE message from return code."
        echo "${USAGE}"
	exit 1
    fi

    while [ ${#} -gt 0 ]		# while there are options...
    do					# ( for vi parenthesis matching
        ${v}echo "${C}.${0}:  parsing option \"${1}\", then \"${2}\""
        case ${1} in

        -C)
	    OPT_C="${1}"
            OPT_C_PARM="${2}"		# GNU_CMDFILE name.
            ${v}echo "${C}.${0}:  OPT_C=${OPT_C}, # -C GNU_CMDFILE name."
	    ${v}echo "${C}.${0}:  OPT_C_PARM=${OPT_C_PARM}, # GNU_CMDFILE name."
            export GNU_CMDFILE="${OPT_C_PARM}"
	    MSG="# GNU_CMDFILE name."
	    ${v}echo "${C}.${0}:  GNU_CMDFILE=${GNU_CMDFILE}, ${MSG}"
            shift
            ;;				# ( for vi parenthesis matching

        -D)
	    OPT_D="${1}"
            OPT_D_PARM="${2}"		# LP_DEV name.
            ${v}echo "${C}.${0}:  OPT_D=${OPT_D}, # -D LP_DEV printer device."
	    #${v}echo "${C}.${0}:  OPT_D_PARM=${OPT_D_PARM}, # LP_DEV name."
            LP_DEV="${OPT_D_PARM}"
	    ${v}echo "${C}.${0}:  LP_DEV=${LP_DEV}, # LP_DEV name."
            shift
            ;;				# ( for vi parenthesis matching

        -E)
	    OPT_E="${1}"
	    ${v}echo "${C}.${0}:  OPT_E=${OPT_E}, # -E use embedded options"
            ;;				# ( for vi parenthesis matching

        -G)
	    OPT_G="${1}"
	    ${v}echo "${C}.${0}:  OPT_G=${OPT_G}, # -G grid lines on."
            ;;				# ( for vi parenthesis matching

        -H)
	    OPT_H="${1}"
	    ${v}echo "${C}.${0}:  OPT_H=${OPT_H}, # -H default column headings."
            ;;				# ( for vi parenthesis matching

        -I)
	    OPT_I="${1}"
	    ${v}echo "${C}.${0}:  OPT_I=${OPT_I}, # -I Memory used / index."
	    CMN="12"
	    COL[$CMN]="${CMN}"
	    ${v}echo "${C}.${0}:  COL[$CMN]=${COL[$CMN]}"
            ;;				# ( for vi parenthesis matching

        -L)
	    OPT_L="${1}"
	    ${v}echo "${C}.${0}:  OPT_L=${OPT_L}, -L set logscale axis"
            OPT_L_PARM="${2}"		# axis name, x or y
	    if [ ${OPT_L_PARM} = "x" ]; then
		OPT_L_xaxis="${OPT_L_PARM}"
	    elif [ ${OPT_L_PARM} = "y" ]; then
		OPT_L_yaxis="${OPT_L_PARM}"
	    else
		MSG="must be either \"x\" or \"y\" axis.  exit 5"
                echo "${C}.${0}:  ERROR, OPT_L_PARM=${OPT_L_PARM} ${MSG}"
	        exit 5
	    fi
	    OPT_NL=""			# -L turn off -NL.
            shift
            ;;				# ( for vi parenthesis matching

        -M)
	    OPT_M="${1}"
	    ${v}echo "${C}.${0}:  OPT_M=${OPT_M}, # -M Memory used and free."
	    CMN="8"
	    COL[$CMN]="${CMN}"
	    ${v}echo "${C}.${0}:  COL[$CMN]=${COL[$CMN]}"
            ;;				# ( for vi parenthesis matching

        -N)
	    OPT_N="${1}"
            OPT_N_PARM="${2}"		# LP_DEV name.
            ${v}echo "${C}.${0}:  OPT_N=${OPT_N}, #  -N not option"
	    ${v}echo "${C}.${0}:  OPT_N_PARM=${OPT_N_PARM}, # Turn option off."
	    if   [ "${OPT_N_PARM}" = "E" ]; then
	        OPT_E=""		# -E use embedded options
	        OPT_NE="-NE"		# -NE turn off -E.
	    elif [ "${OPT_N_PARM}" = "L" ]; then
		OPT_L=""		# -L set logscale axis
		OPT_L_xaxis=""
		OPT_L_yaxis=""
	        OPT_NL="-NL"		# -NL turn off -L.
	    elif [ "${OPT_N_PARM}" = "G" ]; then
	        OPT_G=""		# -G grid lines on.
	        OPT_NG="-NG"		# -NG turn off -G.
	    elif [ "${OPT_N_PARM}" = "H" ]; then
	        OPT_H=""		# -H default column headings.
	        OPT_NH="-NH"		# -NH turn off -H.
	    fi
            shift
            ;;				# ( for vi parenthesis matching

        -P)
	    OPT_P="${1}"
            OPT_P_PARM="${2}"		# GNU_PSFILE name.
	    ${v}echo "${C}.${0}:  OPT_P=${OPT_P}, # -P GNU_PSFILE name."
	    #${v}echo "${C}.${0}:  OPT_P_PARM=${OPT_P_PARM}, # GNU_PSFILE name."
            GNU_PSFILE="${OPT_P_PARM}"
	    ${v}echo "${C}.${0}:  GNU_PSFILE=${GNU_PSFILE}, # GNU_PSFILE name."
            shift
            ;;				# ( for vi parenthesis matching

        -S)
	    OPT_S="${1}"
	    ${v}echo "${C}.${0}:  OPT_S=${OPT_S}, # -S save files."
            ;;				# ( for vi parenthesis matching

        -V)
	    OPT_V="${1}"
	    ${v}echo "${C}.${0}:  OPT_V=${OPT_V}, # -V vi the plot file."
            ;;				# ( for vi parenthesis matching

        -c)
	    OPT_c="${1}"
            OPT_c_PARM="${2}"		# COLUMN_NUMBER.
            ${v}echo "${C}.${0}:  OPT_c=${OPT_c}, # -c plot column number."
	    ${v}echo "${C}.${0}:  OPT_c_PARM=${OPT_c_PARM}, # COLUMN_NUMBER."
	    if [ ${OPT_c_PARM} -ge ${#CHA[*]} ] ||
	       [ ${OPT_c_PARM} -le 0 ]; then
		MSG="must be greater than 0 and less than ${#CHA[*]}. exit 6"
                echo "${C}.${0}:  ERROR, OPT_c_PARM=${OPT_c_PARM} ${MSG}"
	        exit 6
	    fi
	    CMN="${OPT_c_PARM}"
	    COL[$CMN]="${CMN}"
	    ${v}echo "${C}.${0}:  COL[$CMN]=${COL[$CMN]}"
            shift
            ;;				# ( for vi parenthesis matching

        -d)
	    OPT_d="${1}"
            OPT_d_PARM="${2}"		# DERIVATIVE_TYPE
	    ${v}echo "${C}.${0}:  OPT_d=${OPT_d}, # -d plot derivative type."
	    ${v}echo "${C}.${0}:  OPT_d_PARM=${OPT_d_PARM}, # DERIVITIVE_TYPE"
	    if [ "${OPT_d_PARM}" = "i" ]; then
		OPT_di="${OPT_d_PARM}"
		CMN="3"
	    elif [ "${OPT_d_PARM}" = "m" ]; then
		OPT_dm="${OPT_d_PARM}"
		CMN="7"
	    elif [ "${OPT_d_PARM}" = "r" ]; then
		OPT_dr="${OPT_d_PARM}"
		CMN="5"
            else
                echo "${C}.${0}:  ERROR, ${OPT_d_PARM} must be one of i, m, r."
	    fi
	    COL[$CMN]="${CMN}"
	    ${v}echo "${C}.${0}:  COL[$CMN]=${COL[$CMN]}"
            shift
            ;;				# ( for vi parenthesis matching

        -g)
	    OPT_g="${1}"
            OPT_g_PARM="${2}"		# Option parameter
            ${v}echo "${C}.${0}:  OPT_g=${OPT_g}, # -g geometry description."
	    ${v}echo "${C}.${0}:  OPT_g_PARM=${OPT_g_PARM}, # window geometry"
            GNU_GEOMETRY="-geometry ${OPT_g_PARM}" # Environment geometry.
	    MSG="# window geometry"
	    ${v}echo "${C}.${0}:  GNU_GEOMETRY=${GNU_GEOMETRY}, ${MSG}"
            shift
            ;;				# ( for vi parenthesis matching

        -i)
	    OPT_i="${1}"
	    ${v}echo "${C}.${0}:  OPT_i=${OPT_i}, # -i plot insert."
	    CMN="2"
	    COL[$CMN]="${CMN}"
	    ${v}echo "${C}.${0}:  COL[$CMN]=${COL[$CMN]}"
            ;;				# ( for vi parenthesis matching

        -l)
	    OPT_l="${1}"
	    ${v}echo "${C}.${0}:  OPT_l=${OPT_l}, # -l plot leaf data."
	    CMN="10"
	    COL[$CMN]="${CMN}"
	    ${v}echo "${C}.${0}:  COL[$CMN]=${COL[$CMN]}"
	    CMN="11"
	    COL[$CMN]="${CMN}"
	    ${v}echo "${C}.${0}:  COL[$CMN]=${COL[$CMN]}"
            ;;				# ( for vi parenthesis matching

        -m)
	    OPT_m="${1}"
	    ${v}echo "${C}.${0}:  OPT_m=${OPT_m}, # -m plot memory malloced."
	    CMN="9"
	    COL[$CMN]="${CMN}"
	    ${v}echo "${C}.${0}:  COL[$CMN]=${COL[$CMN]}"
            ;;				# ( for vi parenthesis matching

        -n)
	    OPT_n="${1}"
	    MSG="# -n number plot descriptions."
	    ${v}echo "${C}.${0}:  OPT_n=${OPT_n}, ${MSG}"
            ;;				# ( for vi parenthesis matching

        -o)
	    OPT_o="${1}"
            OPT_o_PARM="${2}"		# Option parameter
	    MSG="# -o LP_OPT printer option(s)."
	    ${v}echo "${C}.${0}:  OPT_o=${OPT_o}, ${MSG}"
	    MSG="# -o LP_OPT printer option(s)."
	    ${v}echo "${C}.${0}:  OPT_o_PARM=${OPT_o_PARM}, ${MSG}"
	    # Check for duplicates, only add to LP_OPT if not a duplicate.
	    LP_SET="`echo ${LP_OPT} | adjust -m1 | grep -- -${OPT_o_PARM}`"
	    if [ "${LP_SET}" != "-${OPT_o_PARM}" ];
	    then
	        LP_OPT="${LP_OPT} -${OPT_o_PARM}"
	    fi
	    unset LP_SET
	    ${v}echo "${C}.${0}:  LP_OPT=${LP_OPT}, # LP_OPT printer option(s)."
	    shift
            ;;				# ( for vi parenthesis matching

        -p)
	    OPT_p="${1}"
	    ${v}echo "${C}.${0}:  OPT_p=${OPT_p}, # -p print the plot."
            ;;				# ( for vi parenthesis matching

        -q)
	    OPT_v="${1}"
            v='eval #'			# Set verbose off (quiet).
	    ${v}echo "${C}.${0}:  OPT_v=${OPT_v}, # -q quiet mode."
            ;;				# ( for vi parenthesis matching

        -r)
	    OPT_r="${1}"
	    ${v}echo "${C}.${0}:  OPT_r=${OPT_r}, # -r plot retrieve."
	    CMN="4"
	    COL[$CMN]="${CMN}"
	    ${v}echo "${C}.${0}:  COL[$CMN]=${COL[$CMN]}"
            ;;				# ( for vi parenthesis matching

        -v)
	    OPT_v="${1}"
            v=""			# Set verbose on.	
	    ${v}echo "${C}.${0}:  OPT_v=${OPT_v}, # -v verbose mode."
	    ${v}echo
            ;;				# ( for vi parenthesis matching

        -x)
	    OPT_x="${1}"
            OPT_x_PARM="${2}"		# Option parameter
            ${v}echo "${C}.${0}:  OPT_x=${OPT_x}, # -x xRANGE, scale range."
	    #${v}echo "${C}.${0}:  OPT_x_PARM=${OPT_x_PARM}, # parameter desc."
	    xRANGE="${OPT_x_PARM}"
	    ${v}echo "${C}.${0}:  xRANGE=${xRANGE}, # parameter desc."
            shift
            ;;				# ( for vi parenthesis matching

        -y)
	    OPT_y="${1}"
            OPT_y_PARM="${2}"		# Option parameter
            ${v}echo "${C}.${0}:  OPT_y=${OPT_y}, # -y yRANGE, scale range."
	    #${v}echo "${C}.${0}:  OPT_y_PARM=${OPT_y_PARM}, # parameter desc."
	    yRANGE="${OPT_y_PARM}"
	    ${v}echo "${C}.${0}:  yRANGE=${yRANGE}, # parameter desc."
            shift
            ;;				# ( for vi parenthesis matching

	-u)
	    OPT_u="-u"
	    ${v}echo "${C}.${0}:  OPT_u=${OPT_u}, # -u Usage message."
            echo "${USAGE}"
	    exit 4
            ;;				# ( for vi parenthesis matching

        -a)
	    OPT_a="${1}"
	    ${v}echo "${C}.${0}:  OPT_a=${OPT_a}, # -a Option description."
            ;;				# ( for vi parenthesis matching

        -b)
	    OPT_b="${1}"
            OPT_b_PARM="${2}"		# Option parameter
            ${v}echo "${C}.${0}:  OPT_b=${OPT_b}, # -b Option description."
	    ${v}echo "${C}.${0}:  OPT_b_PARM=${OPT_b_PARM}, # parameter desc."
            shift
            ;;				# ( for vi parenthesis matching

        --)
	    shift			# Remove the "--".
            break
            ;;				# ( for vi parenthesis matching

 	*)
            echo "${C}.${0}:  Option not understood. \"${1}\""
            echo "USAGE message follows:  "
            echo "${USAGE}"             # USAGE message
            exit 2
            ;;

        esac
	shift
    done

# The rest of the command line parameters are files:

    # If FILES is already set, leave it alone, else set it.
    # This is necessary due running getopt twice, to support parameters
    # embedded in the data files.
    if [ "${FILES}" = "" ]; then
        FILES="${FILES} ${*}" 		# May result in a blank, " ".
       if [ "${FILES}" = " " ]; then    # If blank, " ", make it empty.
	   FILES=""			# Make FILES empty again.
       fi
        ${v}echo "${C}.${0}:  FILES=${FILES}"
    fi

# Set default options, if no applicable plot options were set.
    COL_CTR="${#COL[*]}"		# Columns were turned on.
    ${v}echo "COL_CTR=${COL_CTR}, COL=${COL[*]}"

    if [ "${COL_CTR}" = "0" ]; then		# Option not set
	${v}echo "${C}.${0}:  Setting default options."
	FUNCTION__getopt -c2 -c4	# Set default, if no options set.
    fi
    if [ "${OPT_C}" = "-C" ] ||		# If -C or -P, ensure -S.
       [ "${OPT_P}" = "-P" ]; then
	if [ "${OPT_S}" != "-S" ]; then
        FUNCTION__getopt -S		# -S save files.
        fi
    fi

# Save a shar copy of this script, if -S and -v are both on.
# Turned off, may be useful later.

#    if [ ! -z "${OPT_S}" ] &&		# -S save files.
#       [ "${OPT_v}" = "-v" ]; then	# -v verbose mode.
#            ${v}echo "${C}.${0}:  start of shar of script"
#	    shar -b ${C_PATH} >>${COMMAND}.shar
#            ${v}echo "${C}.${0}:  end   of shar of script\n"
#    fi

    ${v}echo "${C}.${0}:  completed at `date`\n"	# end of function
} # FUNCTION__getopt()			# Use function getopt.

FUNCTION_gnuplot_init()			# Initialize gnuplot command file.
{
# INITIALIZE GNU_CMDFILE
#
# - Pass options to gnuplot.
# - Some options for gnuplot are set here (logscale, autoscale).

    ${v}echo "${C}.${0}:  beginning at `date`"	# beginning of function
  {
    echo "# ${C_PATH} ${*}"
    echo "# gnuplot ${GNU_GEOMETRY} ${GNU_CMDFILE}"
    if [ "${OPT_L}" = "-L" ]; then	# -L set logscale axis
        echo "set logscale ${OPT_L_xaxis}${OPT_L_yaxis}"
    fi
    echo "set autoscale xy"
    echo "set data style lines"
    if [ ! -z "${OPT_G}" ]; then	# Turn on grids.
        echo "set grid"
    fi

# Naming convention... build some kind of TITLE name, if none given.

    TITLE="${TITLE:-JUDY BENCHMARK:  $CMD_LINE }" # Set default.

    echo "set title  \"${TITLE}\"  0,0 "
    if [ "${xRANGE}" != "" ]; then
        echo "set xrange `FUNCTION_units ${xRANGE}`"
	XLABEL="${XLABEL} ${xRANGE}"
    fi
    if [ "${yRANGE}" != "" ]; then
        echo "set yrange `FUNCTION_units ${yRANGE}`"
	YLABEL="${YLABEL} ${yRANGE}"
    fi
    echo "set xlabel \"${XLABEL}\" 0,0"
    echo "set ylabel \"${YLABEL}\" 0,0"
    echo "set label \"${XLOG}\" at  1,1"
  } >> ${GNU_CMDFILE}

    ${v}echo "${C}.${0}:  completed at `date`\n"	# end of function
} # FUNCTION_gnuplot_init()		# Initialize gnuplot command file.

FUNCTION_gnuplot_plot()			# Plot these files.
{
# FORMAT THE PLOT AND REPLOT COMMANDS
# 
# - output to GNU_CMDFILE.

    ${v}echo "${C}.${0}:  beginning at `date`"	# beginning of function
    ${v}echo "${C}.${0}:  FILES=${*}"

    Fgp_PARM="${*}"			# Save what was passed in.
    Fgp_FILES=""			# Initialize list of good files.
    for i in ${Fgp_PARM}
    do
        if [ -r "$i" ]; then		# Check that files are readable.
            Fgp_FILES="${Fgp_FILES} ${i}" # Extend the list of good files.
	else
            echo "${C}.${0}:  WARNING:  file: ${i} cannot be read, ignored."
        fi
    done

    let j=1
    while [ ${j} -lt ${#CHA[*]} ]	# For each type of plot.
    do
        for i in ${Fgp_FILES}		# For each file.
        do
	    CMN="${COL[$j]}"
            if [ ! -z "${CMN}" ]; then
	      {
		MSG="`basename ${i}`"
		if [ "${OPT_H}" = "-H" ]; then
		    echo "${FIRST}plot \"${i}\" using 1:${CMN} t \"${CHA[${CMN}]} ${MSG}\""
		elif [ "${OPT_NH}" = "-NH" ]; then
		    echo "${FIRST}plot \"${i}\" using 1:${CMN} t \"${MSG}\""
		fi
	      } >> ${GNU_CMDFILE}
                FIRST="re"
            fi
        done
        let j=j+1
    done

# A bug in gnuplot sometimes prevents all replots from appearing.
# This particularly happens when xrange is used.
# Doing an extra replot will plot everything.
    echo replot >> ${GNU_CMDFILE}

    ${v}echo "${C}.${0}:  completed at `date`\n"	# end of function
} # FUNCTION_gnuplot_plot()			# Plot these files.

FUNCTION_gnuplot_display()			# Plots the datapoints.
{
# DISPLAY PLOT TO SCREEN:

    ${v}echo "${C}.${0}:  beginning at `date`"	# beginning of function

    if [ "${OPT_V}" = "-V" ]; then
        echo "hpterm -e vi -c \"vi ${GNU_CMDFILE} \""
        hpterm -e vi -cvi ${GNU_CMDFILE} &
    fi

    if [ "${OPT_v}" = "-v" ]; then	# -v verbose mode.
        echo "${C}.${0}:  executing command:  "; echo "\n\
        gnuplot ${GNU_GEOMETRY} ${GNU_CMDFILE}"
    fi

# Add additional parameters as necessary to setup for printing:
    if [ "${OPT_p}" = "-p" ]; then
      {
        echo set terminal postscript landscape color
        echo set output \"${GNU_PSFILE}\"
        echo replot
      } >> ${GNU_CMDFILE}
    fi  

    LINE=""				# External response
    while [ "${LINE}" != "q" ]
    do
        gnuplot ${GNU_GEOMETRY} ${GNU_CMDFILE}
        LINE="q"			# Setup for quit.
        if [ "${OPT_V}" = "-V" ]; then
	    echo "Pause: press return to vi again, \"q\" to quit ${C}"
	    read -r LINE
        fi
    done

    ${v}echo "${C}.${0}:  completed at `date`\n"	# end of function
} # FUNCTION_gnuplot_display()		# Plots the datapoints.

FUNCTION_gnuplot_print()		# -p print the plot.
{
#
# PRINT THE PLOT.
#
# - uses gnuplot command "replot".

    ${v}echo "${C}.${0}:  beginning at `date`"	# beginning of function
    ${v}echo "${C}.${0}:  OPT_p=${OPT_p}, # -p print the plot."
    ${v}echo "${C}.${0}:  OPT_P=${OPT_P}, # GNU_PSFILE name."
    GNU_PSFILE="${GNU_PSFILE:-$GNU_PSFILE_DEF}"
    ${v}echo "${C}.${0}:  GNU_PSFILE=${GNU_PSFILE}, # GNU_PSFILE name."

    LP_DEV_PARM="-d ${LP_DEV:-$LP_DEV_DEF}" # Printer device parameter.
    LP_OPT_PARM="${LP_OPT:-$LP_OPT_DEF}"    # Printer option parameters.

    echo "${C}.${0}: executing command:  "; echo "\n\
    echo lp ${LP_DEV_PARM} ${LP_OPT_PARM} ${GNU_PSFILE}"

    lp ${LP_DEV_PARM} ${LP_OPT_PARM} ${GNU_PSFILE}

    ${v}echo "${C}.${0}:  completed at `date`\n"	# end of function
} # FUNCTION_gnuplot_print()		# Print the plot.

FUNCTION_TITLE_COLHEAD()			# Set Column headings from file.
{
#
# Parse the TITLE and COLUMN HEADINGS (CHA) from the data, if available.
# Also parse other settable parameters, if available.
#

    ${v}echo "${C}.${0}:  beginning at `date`"	# beginning of function
    FTC_FILES="${*}"			# Local list of file names.
    ${v}echo "${C}.${0}:  FTC_FILES=${FTC_FILES}"

    # Choose the first readable file.
    unset FTC_FILE			# Hold the first readable filename.
    for F in ${FTC_FILES} /dev/null	# /dev/null ensures there is a file.
    do
	if [ -r "${F}" ] &&		# Is this file readable?
	   [ "${FTC_FILE}" = "" ]; then # We do not have one yet?
	    FTC_FILE="${F}"		# Hold the first readable filename.
	fi
    done

    # If FTC_FILE got set, use it to find TITLE, COLHEAD, XLABEL, YLABEL, et.al.
    if [ "${FTC_FILE}" != "" ]; then	# Use this file.
	# Grab the FIRST TITLE line (head -1) and use it.
	TITLE="`grep '^# *TITLE' ${FTC_FILE} | head -1 |
	  sed -e 's/^# *TITLE *//g'`"
        ${v}echo "${C}.${0}:  TITLE=${TITLE}"

	# Grab the FIRST XLABEL line (head -1) and use it.
	XLABEL="`grep '^# *XLABEL' ${FTC_FILE} | head -1 |
	  sed -e 's/^# *XLABEL *//g'`"
        ${v}echo "${C}.${0}:  XLABEL=${XLABEL}"

	# Grab the FIRST YLABEL line (head -1) and use it.
	YLABEL="`grep '^# *YLABEL' ${FTC_FILE} | head -1 |
	  sed -e 's/^# *YLABEL *//g'`"
        ${v}echo "${C}.${0}:  YLABEL=${YLABEL}"

	# Find each COLHEAD, and put it in the correct CHA[INDEX].
        let i=0
        while [ ${i} -lt ${#CHA[*]} ]	# For each COLHEAD
        do
	    # Grab one COLHEAD line at a time, put it into CHA[].
	      # Note, "@" not allowed in COLHEAD string.
	    LINE="`grep \"^#.*COLHEAD\" ${FTC_FILE} |	# Find COLHEAD.
	      sed -e 's/^#.*COLHEAD*//g' \
		  -e 's/^ *//g' \
		  -e 's/@//g' | # Remove COLHEAD.
	      expand | sed -e 's/^0*//g' | # Remove leading zeros.
	      grep ^${i} |		# Find a line matching ${i}.
	      head -1 `"		# Make sure there is only 1.

	    # Grab the INDEX number, could do numeric check if problems.
	    INDEX="`echo ${LINE} | cut -d\" \" -f1`" # field 1 is number.

	    # If INDEX is not empty, save this COLHEAD.
	    if [ "${INDEX}" != "" ]; then
	        # Grab the rest of the line and save it into CHA.
	        REMAINDER="`echo ${LINE} | sed -e \"s@^${INDEX} *@@g\"`"
	        CHA[${INDEX}]="${REMAINDER}"
                ${v}echo "${C}.${0}:  CHA[${INDEX}]=\"${CHA[${INDEX}]}\""
	    fi

	    let i=i+1
        done

	# GETOPT, pull in options to be set for this data.
	GETOPT="`grep '^# *GETOPT' ${FTC_FILE} | head -1 |
	  sed -e 's/^# *GETOPT *//g'`"
	if [ "${GETOPT}" != "" ]; then
            FUNCTION__getopt ${GETOPT}		# Parse the options.
	fi
	unset GETOPT

    fi

    ${v}echo "${C}.${0}:  completed at `date`\n"	# end of function
} # FUNCTION_TITLE_COLHEAD()		# Set Column headings from file.

FUNCTION_n()				# -n number plot descriptions.
{
# ADD COLUMN NUMBER TO EACH ELEMENT IN CHA:
#
# - This is done for comparing plots, and/or debugging.

    ${v}echo "${C}.${0}:  beginning at `date`"	# beginning of function
    ${v}echo "${C}.${0}:  OPT_n=${OPT_n}, # -n number plot descriptions"

    let i=0
    while [ ${i} -lt ${#CHA[*]} ]
    do
       CHA[${i}]="${i} ${CHA[${i}]}"
       ${v}echo "${C}.${0}:  CHA[${i}]=\"${CHA[${i}]}\""
       let i=i+1
    done
    ${v}echo "${C}.${0}:  completed at `date`\n"	# end of function
} # FUNCTION_n()			# -n number plot descriptions.

FUNCTION_units()			# Resolve units.
{
#
# Expand units of the form 1K to 1000, 1M to 1000000, et.al.
# Used to format the gnuplot parameters xRANGE and yRANGE.
# gnuplot data format:  "set xrange [1:1000000]"
#

    Fu_IN="${1}"			# Units in.
    echo "["${Fu_IN}"]" |
      sed -e "s/[kK]/000/g"	      | # 1,000
      sed -e "s/[mM]/000000/g"	      | # 1,000,000
      sed -e "s/[gG]/000000000/g"     | # 1,000,000,000
      sed -e "s/^\[\[/\["/g	      | # Ensure single leading bracket.
      sed -e "s/\]\]$/\]"/g	        # Ensure single trailing bracket.
}

FUNCTION_a()				# -a Option description.
{
#
# Replace with description of this function.
#

    ${v}echo "${C}.${0}:  beginning at `date`"	# beginning of function
    ${v}echo "${C}.${0}:  OPT_a=${OPT_a}, # -a Option description."
    ${v}echo "${C}.${0}:  completed at `date`\n"	# end of function
} #

FUNCTION_b()				# -b Option description.
{
#
# Replace with description of this function.
#

    ${v}echo "${C}.${0}:  beginning at `date`"	# beginning of function
    ${v}echo "${C}.${0}:  OPT_b=${OPT_b}, # -b Option description."
    MSG="# -b   Parameter description."
    ${v}echo "${C}.${0}:  OPT_b_PARM=${OPT_b_PARM}, ${MSG}"

    if [ -r "${OPT_b_PARM}" ]; then	# Ensure this is a file.
        echo ${OPT_b_PARM} |
          while read -r FILE; do
            ${v}echo "${C}.${0}:  FILE=${FILE}"
          done
    else				# Or use elif (form of elseif).
        ${v}echo "${C}.${0}:  ERROR, ${OPT_b_PARM} is not a readable file."
    fi

    ${v}echo "${C}.${0}:  completed at `date`\n"	# end of function
} #


#
# MAIN:  Main driver, main processing occurs here.
#


    ${v}echo "\n${C}:  beginning at `date`" # page overflow with each start.

    CMD_LINE="${0} ${*}"		# Save command called and options.

    FUNCTION__getopt ${*}		# Parse the options.

    if [   -z "${OPT_NE}" ] &&		# Not E is not turned on and E is...
       [ ! -z "${OPT_E}" ]; then	# -E use embedded options
        FUNCTION_TITLE_COLHEAD ${FILES}	# Set Column headings from file.
    fi

    FUNCTION__getopt ${*} >/dev/null 2>&1 # Parse the options.

    type banner >/dev/null 2>&1		# Check if banner exists.
    RC="${?}"				# Save return code.
    if [ "${RC}" = "0" ]; then		# if RC=0, banner exists.
        ${v}banner ${C}
    fi

    ${v}echo "${C}:  RCS_SCRIPT=${RCS_SCRIPT}"
    ${v}echo "${C}:  PWD=${PWD}"

    if [ ! -z "${OPT_n}" ]; then
        FUNCTION_n			# -n number plot descriptions.
    fi

    # If GNU_CMDFILE exists, use it, do not create it.
    if [ ! -f ${GNU_CMDFILE} ]; then	# ! -f = if this is not a file.
	if [ "${FILES}" = "" ]; then	# If no files available
	    MSG="and GNU_CMDFILE is not a file  exit 7"
	    echo "${C}:  ERROR:  no FILES to plot!  ${MSG}"
	    exit 7
	    break
	fi
        FUNCTION_gnuplot_init ${*}	# Initialize gnuplot command file.

        FUNCTION_gnuplot_plot ${FILES}	# Plot these files.

        echo pause -1 \'Pause: press return to continue.\' >> ${GNU_CMDFILE}
        echo				# Place blank line in log file.
    fi

    FUNCTION_gnuplot_display		# Plots the datapoints.


    if [ ! -z "${OPT_p}" ]; then
        FUNCTION_gnuplot_print		# -p print the plot.
    fi


# REMOVE FILES, CLEANUP:
#
# Remove the working files and filenames, unless "-S" is on.

    if [ "${OPT_S}" = "-S" ]; then		# -S save files.
        echo "${C}: saving  ${COMMAND}"
        echo "${C}: saving  ${GNU_CMDFILE}"
        if [ "${OPT_p}" = "-p" ]; then
           echo "${C}: saving  ${GNU_PSFILE}"
        fi
    else
        rm -f ${COMMAND}		# Remove generated log file.
        rm -f ${GNU_CMDFILE}	        # Remove generated command file.
        rm -f ${GNU_PSFILE}		# Remove generated .ps file.
    fi

    rm -fr ${COMMAND}.WORK*.$$		# Remove generated work files.

    ${v}echo "${C}:  completed at `date`\n^L"

# Message if -v (verbose):

    if [ "${OPT_v}" = "-v" ]; then	# -v verbose mode.
        echo "${INFO}"
    fi

# DONE:
#
# - If a log file needs to be kept, uncomment the corresponding ():

} 2>&1 | tee -a ${COMMAND}		# Use during testing.
#) >>${COMMAND} 2>&1 &			# Use for production.