Debian Codegraph @

test/jbgraph

raw
1 #!/bin/sh
2
3 # THIS SCRIPT IS A "WRAPPER" FOR: gnuplot
4 #
5 # - The data used is in "gnuplot" format to compare and contrast
6 # - information for analysis in the Judy project. Circa: 05/12/2000.
7
8 # Author: Bob Gobeille, # Original functionality.
9 # Jer/ Eberhard, # Ongoing maintenance, added functionality.
10
11 RCS_SCRIPT='
12 # @(#) $Revision: 2.24 $ $Source: /judy/src/apps/benchmark/jbgraph $
13 '
14
15
16 # SET VERBOSE TO QUIET, SILENT (DEFAULT):
17 #
18 # - then find out if verbose mode is to be set.
19
20 OPT_v="${OPT_v:--q}" # Set verbose off, (default).
21 v='eval #' # Set verbose off, (quiet).
22
23 VERBOSE="`echo ${*} | tr ' ' '\012' | grep -- -v`"
24 if [ "${VERBOSE}" = "-v" ]; then # -v verbose mode on.
25 OPT_v="${VERBOSE}" # Will be "-v".
26 v="" # Set verbose on.
27 fi
28 unset VERBOSE # Unset after last use.
29
30
31 # CREATE NAMESPACE:
32 #
33 # - Set names of OUTPUT and WORK directories and files.
34
35 C="`basename ${0:-jbgraph}`" # Command name of this script.
36 C_PATH="${0}" # Called via this path.
37 C_rc=".${C}.rc" # .rc file, local or ${HOME}.
38 OUTPUT_DIR=./tmp/`echo ${C} | tr "[a-z]" "[A-Z]"` # output name in caps
39
40 mkdir -p ${OUTPUT_DIR} # Create output directory.
41 if [ ! -d "${OUTPUT_DIR}" ]; then # Ensure dir exists.
42 echo "${C}.${0}: ERROR, unable to: mkdir -p ${OUTPUT_DIR}"
43 exit 3
44 fi
45
46
47 # UNCOMMENT THE DATE_TIME FORMAT YOU WANT TO USE:
48
49 #DATE_TIME="`date +%y%m`" # Monthly Date/Time stamp.
50 #DATE_TIME="`date +%y%m%d`" # Daily Date/Time stamp.
51 DATE_TIME="`date +%y%m%d.%H%M`" # HourMinute Date/Time stamp.
52
53 COMMAND="${OUTPUT_DIR}/${DATE_TIME}" # Output filename date/time stamp.
54 WORK1="${COMMAND}.WORK1.$$" # Work file 1.
55 WORK2="${COMMAND}.WORK2.$$" # Work file 2.
56 WORK3="${COMMAND}.WORK3.$$" # Work file 3.
57 WORK4="${COMMAND}.WORK4.$$" # Work file 4.
58
59
60 # CREATE AND DISPLAY SCRIPT DEFAULTS AND INFO:
61
62 export GNU_CMDFILE="${GNU_CMDFILE:-$COMMAND.GNU_CMDFILE}" # GNU_CMDFILE name
63 ${v}touch ${COMMAND} # Ensure the output file exists.
64 # Produce sample monitor and print commands.
65 INFO="`echo \"${C}: follow output, or print by:
66 rerun by executing the first commented line in:
67 ${GNU_CMDFILE}
68 head -1 ${GNU_CMDFILE} # or
69 tail -f ${COMMAND} # tail and follow log file or
70 tail ${COMMAND} # tail log file or print:
71 fold -80 ${COMMAND} |
72 pr -f -l66 -h${COMMAND} |
73 remsh jerslash -l jer lp -odouble -o2\"`"
74 if [ "${OPT_v}" = "-v" ]; then # -v verbose mode.
75 echo "${INFO}"
76 fi
77
78
79 # DEFINE DEFAULTS, CONSTANTS, VARIABLES:
80 #
81 # - 80 Column line---------------------------------------------------01234567890
82
83 # Break line: BL is 70 columns of "-".
84
85 BL="----------------------------------------------------------------------"
86
87 EXT_OPT="${EXT_OPT:-}" # Allow external option setting.
88
89 # GNU_GEOMETRY default:
90 # - Note, this will respect an environment variable, which could be set as:
91 # - export OPT_JBGRAPH_geometry="600x450+20+20" # 4x3 aspect ratio.
92
93 OPT_JBGRAPH_geometry="${OPT_JBGRAPH_geometry:-1000x750+20+20}"
94 GNU_GEOMETRY_DEF="1000x750+20+20" # 4x3 aspect ratio, default.
95 GNU_GEOMETRY="-geometry ${OPT_JBGRAPH_geometry:-$GNU_GEOMETRY_DEF}"
96
97 # GNU_PSFILE name, (default):
98
99 GNU_PSFILE="${OPT_JBGRAPH_psfile:-$COMMAND.GNU_PSFILE}"
100
101 LP_DEV_DEF="${LP_DEV:-pastel}" # Printer device (default).
102 LP_OPT_DEF="${LP_OPT:--olandscape}" # Printer options (default).
103
104 # PLOT AXIS NAMES:
105
106 XLABEL="${XLABEL:-Population}" # Set default.
107 YLABEL_MALLOC="${YLABEL:-Bytes}" # Set default.
108 YLABEL_TIME="${YLABEL:-USec/index}" # Set default.
109 YLABEL="${YLABEL:-$YLABEL_TIME}" # Set default.
110
111 # ARRAY OF COLUMN NAMES:
112 #
113 # - Add column names here (from benchutils.c).
114 # - These are the column names displayed on "gnuplot".
115
116 CHA[0]="CHA=COLUMN HEADINGS ARRAY"
117 CHA[1]="index number"
118 CHA[2]="insert time per index"
119 CHA[3]="dT/dI insert"
120 CHA[4]="retrieve time per index"
121 CHA[5]="dT/dI retrieve"
122 CHA[6]="bytes used"
123 CHA[8]="bytes free"
124 CHA[9]="bytes alloced"
125 CHA[7]="dM/dI change in memory per index"
126 CHA[10]="leaf count"
127 CHA[11]="leaf average size"
128 CHA[12]="leaf memory used per index"
129 CHA[13]="branch count"
130 CHA[14]="branch average size"
131 CHA[15]="branch memory used per index"
132 CHA[16]=""
133 CHA[17]=""
134 CHA[18]=""
135 CHA[19]=""
136 CHA[21]=""
137 CHA[22]=""
138 CHA[23]=""
139 CHA[24]=""
140 CHA[25]=""
141 CHA[26]=""
142 CHA[27]=""
143 CHA[28]=""
144 CHA[29]=""
145 CHA[30]=""
146 CHA[31]=""
147 CHA[32]=""
148 CHA[33]=""
149 CHA[34]=""
150 CHA[35]=""
151 CHA[36]=""
152 CHA[37]=""
153 CHA[38]=""
154 CHA[39]=""
155 CHA[40]=""
156 CHA[41]=""
157 CHA[42]=""
158 CHA[43]=""
159 CHA[44]=""
160 CHA[45]=""
161 CHA[46]=""
162 CHA[47]=""
163 CHA[48]=""
164 CHA[49]=""
165 CHA[50]=""
166
167 CMN="0" # Column number for CHA data.
168
169 #
170 # SET DEFAULT OPTIONS:
171 #
172
173 OPT_E="-E" # -E use embedded options
174 OPT_L="-L" # -L set logscale axis
175 OPT_L_xaxis="x" # -L set logscale x axis
176 OPT_L_yaxis="y" # -L set logscale y axis
177 OPT_H="-H" # -H default column headings.
178
179
180 # M A I N: MAIN PROGRAM:
181 #
182 # - Begin main script, functions first.
183
184 {
185
186 FUNCTION__getopt() # Use function getopt.
187 {
188 # PARSE THE COMMAND LINE FOR OPTIONS, USING GETOPT:
189 #
190 # - define USAGE message.
191 # - use getopts.
192 # Note: FUNCTION__getopt is run twice, in order to support:
193 # FUNCTION_TITLE_COLHEAD() # Set Column headings from file.
194
195 ${v}echo "${C}.${0}: beginning at `date`" # beginning of function
196
197 USAGE="${C} [ -E -G -H -I -M -S -V -i -l -m -q -r -u -v ]
198 [ -C GNU_CMDFILE ]
199 [ -D LP_DEV ]
200 [ -L axis ]
201 [ -N not option ] (turn off option), Example: -NL
202 [ -P GNU_PSFILE ]
203 [ -c COLUMN_NUMBER ]
204 [ -d differential_type ]
205 [ -g GNU_GEOMETRY ]
206 [ -o LP_OPT ]
207 [ -x xRANGE ]
208 [ -y yRANGE ]
209
210 ${C}: wrapper for gnuplot
211
212 -c plot column number. This is useful to plot by column number.
213 -i plot insert; default if no other plots selected. CMN=2
214 -r plot retrievals; default if no other plots selected. CMN=4
215 -I plot memory used / index. CMN=12
216 -m plot memory malloced. CMN=9
217 -M plot memory used and free. CMN=8
218 -l plot leaf data. CMN=11
219 -d plot derivative data. Useful with -i, -r, -m. CMN=2,4,9
220
221 -x xRANGE, scale range; example: -x [1000:5000] or -x1000:5000
222 -y yRANGE, scale range; example: -y [1M:10M] or -y1M:10M
223 1[kK] = 1,000; 1[mM] = 1,000,000; 1[gG] = 1,000,000,000.
224
225 -n number plot descriptions; Use column numbers before the description.
226 -L set logscale axis; default,
227 Example: Turn off logscale with -NL, then turn on, on only one axis:
228 \"-NL -Lx\" or \"-NL -Ly\", Turn off both with -NL
229 -G grid lines on.
230 -H default column headings.
231 -g geometry description.
232 default=\"${GNU_GEOMETRY_DEF}\", # 4x3 aspect ratio.
233
234 -E use embedded options, default, Turn off with -NE.
235 Sets TITLE, COLHEAD, GETOPT from the FIRST data file encountered.
236 Example: embedded options in the data file begin in column 1:
237 # TITLE This is the title to pass to gnuplot
238 # COLHEAD 1 This is the heading for column 1.
239 # XLABEL This is the x-axis label
240 # YLABEL This is the y-axis label
241 # GETOPT -c2 -c3 -G # These are the options to use.
242
243 -p print the plot.
244 -o LP_OPT printer option(s); default \"${LP_OPT_DEF}\".
245 Example: \"-ootray2\" will print on clear slides, emits \"-otray2\"
246 Example: \"-on2\" will print two copies, emits \"-n2\"
247 -D LP_DEV printer device; default \"${LP_DEV_DEF}\".
248
249 -C GNU_CMDFILE name; default is generated and removed:
250 ${OUTPUT_DIR}/{DATE_TIME}.GNU_CMDFILE
251 Useful to do your own gnuplot command editing and debugging.
252 -P GNU_PSFILE name. default is generated and removed:
253 ${OUTPUT_DIR}/{DATE_TIME}.GNU_PSFILE
254 -S Save files.
255 Generated and working file names are deleted unless -S or -C is on.
256 User provided file names are not deleted in any case (-C, -P).
257
258 -q quiet mode, verbose mode off; default.
259 -v verbose mode on.
260
261 -V vi the plot file.
262 quit using \"q\"
263
264 -N not option; Turn specified option off. Example: -NL
265 Note, -N is not available for all options.
266 -NL Turn off: -L set logscale axis; default
267 -NH Turn off: -H default column headings.
268
269 -u Usage message.
270
271 Sample usage:
272 ${C} -i -f data/datafile # -i is the same as -c1.
273 ${C} -c1 -f data/datafile # -i is the same as -c1.
274
275 "
276
277 ${v}echo "${C}.${0}: OPTIONS=${*}"
278
279 # Parse options, using getopt:
280 #
281 # - "a" option, no parameter; "b:" indicates a parameter.
282 # - Order of options is "man 5 ascii".
283
284 getopt_PARM="?C:D:EGIL:MN:P:SVc:d:g:ilmno:prsuvx:y:"
285 set -- `getopt ${getopt_PARM} $*` # Place options in argc/argv.
286 if [ "${?}" != "0" ]; then # If getopt returns an errror.
287 ${v}echo "${C}.${0}: \${?}=${?}, USAGE message from return code."
288 echo "${USAGE}"
289 exit 1
290 fi
291
292 while [ ${#} -gt 0 ] # while there are options...
293 do # ( for vi parenthesis matching
294 ${v}echo "${C}.${0}: parsing option \"${1}\", then \"${2}\""
295 case ${1} in
296
297 -C)
298 OPT_C="${1}"
299 OPT_C_PARM="${2}" # GNU_CMDFILE name.
300 ${v}echo "${C}.${0}: OPT_C=${OPT_C}, # -C GNU_CMDFILE name."
301 ${v}echo "${C}.${0}: OPT_C_PARM=${OPT_C_PARM}, # GNU_CMDFILE name."
302 export GNU_CMDFILE="${OPT_C_PARM}"
303 MSG="# GNU_CMDFILE name."
304 ${v}echo "${C}.${0}: GNU_CMDFILE=${GNU_CMDFILE}, ${MSG}"
305 shift
306 ;; # ( for vi parenthesis matching
307
308 -D)
309 OPT_D="${1}"
310 OPT_D_PARM="${2}" # LP_DEV name.
311 ${v}echo "${C}.${0}: OPT_D=${OPT_D}, # -D LP_DEV printer device."
312 #${v}echo "${C}.${0}: OPT_D_PARM=${OPT_D_PARM}, # LP_DEV name."
313 LP_DEV="${OPT_D_PARM}"
314 ${v}echo "${C}.${0}: LP_DEV=${LP_DEV}, # LP_DEV name."
315 shift
316 ;; # ( for vi parenthesis matching
317
318 -E)
319 OPT_E="${1}"
320 ${v}echo "${C}.${0}: OPT_E=${OPT_E}, # -E use embedded options"
321 ;; # ( for vi parenthesis matching
322
323 -G)
324 OPT_G="${1}"
325 ${v}echo "${C}.${0}: OPT_G=${OPT_G}, # -G grid lines on."
326 ;; # ( for vi parenthesis matching
327
328 -H)
329 OPT_H="${1}"
330 ${v}echo "${C}.${0}: OPT_H=${OPT_H}, # -H default column headings."
331 ;; # ( for vi parenthesis matching
332
333 -I)
334 OPT_I="${1}"
335 ${v}echo "${C}.${0}: OPT_I=${OPT_I}, # -I Memory used / index."
336 CMN="12"
337 COL[$CMN]="${CMN}"
338 ${v}echo "${C}.${0}: COL[$CMN]=${COL[$CMN]}"
339 ;; # ( for vi parenthesis matching
340
341 -L)
342 OPT_L="${1}"
343 ${v}echo "${C}.${0}: OPT_L=${OPT_L}, -L set logscale axis"
344 OPT_L_PARM="${2}" # axis name, x or y
345 if [ ${OPT_L_PARM} = "x" ]; then
346 OPT_L_xaxis="${OPT_L_PARM}"
347 elif [ ${OPT_L_PARM} = "y" ]; then
348 OPT_L_yaxis="${OPT_L_PARM}"
349 else
350 MSG="must be either \"x\" or \"y\" axis. exit 5"
351 echo "${C}.${0}: ERROR, OPT_L_PARM=${OPT_L_PARM} ${MSG}"
352 exit 5
353 fi
354 OPT_NL="" # -L turn off -NL.
355 shift
356 ;; # ( for vi parenthesis matching
357
358 -M)
359 OPT_M="${1}"
360 ${v}echo "${C}.${0}: OPT_M=${OPT_M}, # -M Memory used and free."
361 CMN="8"
362 COL[$CMN]="${CMN}"
363 ${v}echo "${C}.${0}: COL[$CMN]=${COL[$CMN]}"
364 ;; # ( for vi parenthesis matching
365
366 -N)
367 OPT_N="${1}"
368 OPT_N_PARM="${2}" # LP_DEV name.
369 ${v}echo "${C}.${0}: OPT_N=${OPT_N}, # -N not option"
370 ${v}echo "${C}.${0}: OPT_N_PARM=${OPT_N_PARM}, # Turn option off."
371 if [ "${OPT_N_PARM}" = "E" ]; then
372 OPT_E="" # -E use embedded options
373 OPT_NE="-NE" # -NE turn off -E.
374 elif [ "${OPT_N_PARM}" = "L" ]; then
375 OPT_L="" # -L set logscale axis
376 OPT_L_xaxis=""
377 OPT_L_yaxis=""
378 OPT_NL="-NL" # -NL turn off -L.
379 elif [ "${OPT_N_PARM}" = "G" ]; then
380 OPT_G="" # -G grid lines on.
381 OPT_NG="-NG" # -NG turn off -G.
382 elif [ "${OPT_N_PARM}" = "H" ]; then
383 OPT_H="" # -H default column headings.
384 OPT_NH="-NH" # -NH turn off -H.
385 fi
386 shift
387 ;; # ( for vi parenthesis matching
388
389 -P)
390 OPT_P="${1}"
391 OPT_P_PARM="${2}" # GNU_PSFILE name.
392 ${v}echo "${C}.${0}: OPT_P=${OPT_P}, # -P GNU_PSFILE name."
393 #${v}echo "${C}.${0}: OPT_P_PARM=${OPT_P_PARM}, # GNU_PSFILE name."
394 GNU_PSFILE="${OPT_P_PARM}"
395 ${v}echo "${C}.${0}: GNU_PSFILE=${GNU_PSFILE}, # GNU_PSFILE name."
396 shift
397 ;; # ( for vi parenthesis matching
398
399 -S)
400 OPT_S="${1}"
401 ${v}echo "${C}.${0}: OPT_S=${OPT_S}, # -S save files."
402 ;; # ( for vi parenthesis matching
403
404 -V)
405 OPT_V="${1}"
406 ${v}echo "${C}.${0}: OPT_V=${OPT_V}, # -V vi the plot file."
407 ;; # ( for vi parenthesis matching
408
409 -c)
410 OPT_c="${1}"
411 OPT_c_PARM="${2}" # COLUMN_NUMBER.
412 ${v}echo "${C}.${0}: OPT_c=${OPT_c}, # -c plot column number."
413 ${v}echo "${C}.${0}: OPT_c_PARM=${OPT_c_PARM}, # COLUMN_NUMBER."
414 if [ ${OPT_c_PARM} -ge ${#CHA[*]} ] ||
415 [ ${OPT_c_PARM} -le 0 ]; then
416 MSG="must be greater than 0 and less than ${#CHA[*]}. exit 6"
417 echo "${C}.${0}: ERROR, OPT_c_PARM=${OPT_c_PARM} ${MSG}"
418 exit 6
419 fi
420 CMN="${OPT_c_PARM}"
421 COL[$CMN]="${CMN}"
422 ${v}echo "${C}.${0}: COL[$CMN]=${COL[$CMN]}"
423 shift
424 ;; # ( for vi parenthesis matching
425
426 -d)
427 OPT_d="${1}"
428 OPT_d_PARM="${2}" # DERIVATIVE_TYPE
429 ${v}echo "${C}.${0}: OPT_d=${OPT_d}, # -d plot derivative type."
430 ${v}echo "${C}.${0}: OPT_d_PARM=${OPT_d_PARM}, # DERIVITIVE_TYPE"
431 if [ "${OPT_d_PARM}" = "i" ]; then
432 OPT_di="${OPT_d_PARM}"
433 CMN="3"
434 elif [ "${OPT_d_PARM}" = "m" ]; then
435 OPT_dm="${OPT_d_PARM}"
436 CMN="7"
437 elif [ "${OPT_d_PARM}" = "r" ]; then
438 OPT_dr="${OPT_d_PARM}"
439 CMN="5"
440 else
441 echo "${C}.${0}: ERROR, ${OPT_d_PARM} must be one of i, m, r."
442 fi
443 COL[$CMN]="${CMN}"
444 ${v}echo "${C}.${0}: COL[$CMN]=${COL[$CMN]}"
445 shift
446 ;; # ( for vi parenthesis matching
447
448 -g)
449 OPT_g="${1}"
450 OPT_g_PARM="${2}" # Option parameter
451 ${v}echo "${C}.${0}: OPT_g=${OPT_g}, # -g geometry description."
452 ${v}echo "${C}.${0}: OPT_g_PARM=${OPT_g_PARM}, # window geometry"
453 GNU_GEOMETRY="-geometry ${OPT_g_PARM}" # Environment geometry.
454 MSG="# window geometry"
455 ${v}echo "${C}.${0}: GNU_GEOMETRY=${GNU_GEOMETRY}, ${MSG}"
456 shift
457 ;; # ( for vi parenthesis matching
458
459 -i)
460 OPT_i="${1}"
461 ${v}echo "${C}.${0}: OPT_i=${OPT_i}, # -i plot insert."
462 CMN="2"
463 COL[$CMN]="${CMN}"
464 ${v}echo "${C}.${0}: COL[$CMN]=${COL[$CMN]}"
465 ;; # ( for vi parenthesis matching
466
467 -l)
468 OPT_l="${1}"
469 ${v}echo "${C}.${0}: OPT_l=${OPT_l}, # -l plot leaf data."
470 CMN="10"
471 COL[$CMN]="${CMN}"
472 ${v}echo "${C}.${0}: COL[$CMN]=${COL[$CMN]}"
473 CMN="11"
474 COL[$CMN]="${CMN}"
475 ${v}echo "${C}.${0}: COL[$CMN]=${COL[$CMN]}"
476 ;; # ( for vi parenthesis matching
477
478 -m)
479 OPT_m="${1}"
480 ${v}echo "${C}.${0}: OPT_m=${OPT_m}, # -m plot memory malloced."
481 CMN="9"
482 COL[$CMN]="${CMN}"
483 ${v}echo "${C}.${0}: COL[$CMN]=${COL[$CMN]}"
484 ;; # ( for vi parenthesis matching
485
486 -n)
487 OPT_n="${1}"
488 MSG="# -n number plot descriptions."
489 ${v}echo "${C}.${0}: OPT_n=${OPT_n}, ${MSG}"
490 ;; # ( for vi parenthesis matching
491
492 -o)
493 OPT_o="${1}"
494 OPT_o_PARM="${2}" # Option parameter
495 MSG="# -o LP_OPT printer option(s)."
496 ${v}echo "${C}.${0}: OPT_o=${OPT_o}, ${MSG}"
497 MSG="# -o LP_OPT printer option(s)."
498 ${v}echo "${C}.${0}: OPT_o_PARM=${OPT_o_PARM}, ${MSG}"
499 # Check for duplicates, only add to LP_OPT if not a duplicate.
500 LP_SET="`echo ${LP_OPT} | adjust -m1 | grep -- -${OPT_o_PARM}`"
501 if [ "${LP_SET}" != "-${OPT_o_PARM}" ];
502 then
503 LP_OPT="${LP_OPT} -${OPT_o_PARM}"
504 fi
505 unset LP_SET
506 ${v}echo "${C}.${0}: LP_OPT=${LP_OPT}, # LP_OPT printer option(s)."
507 shift
508 ;; # ( for vi parenthesis matching
509
510 -p)
511 OPT_p="${1}"
512 ${v}echo "${C}.${0}: OPT_p=${OPT_p}, # -p print the plot."
513 ;; # ( for vi parenthesis matching
514
515 -q)
516 OPT_v="${1}"
517 v='eval #' # Set verbose off (quiet).
518 ${v}echo "${C}.${0}: OPT_v=${OPT_v}, # -q quiet mode."
519 ;; # ( for vi parenthesis matching
520
521 -r)
522 OPT_r="${1}"
523 ${v}echo "${C}.${0}: OPT_r=${OPT_r}, # -r plot retrieve."
524 CMN="4"
525 COL[$CMN]="${CMN}"
526 ${v}echo "${C}.${0}: COL[$CMN]=${COL[$CMN]}"
527 ;; # ( for vi parenthesis matching
528
529 -v)
530 OPT_v="${1}"
531 v="" # Set verbose on.
532 ${v}echo "${C}.${0}: OPT_v=${OPT_v}, # -v verbose mode."
533 ${v}echo
534 ;; # ( for vi parenthesis matching
535
536 -x)
537 OPT_x="${1}"
538 OPT_x_PARM="${2}" # Option parameter
539 ${v}echo "${C}.${0}: OPT_x=${OPT_x}, # -x xRANGE, scale range."
540 #${v}echo "${C}.${0}: OPT_x_PARM=${OPT_x_PARM}, # parameter desc."
541 xRANGE="${OPT_x_PARM}"
542 ${v}echo "${C}.${0}: xRANGE=${xRANGE}, # parameter desc."
543 shift
544 ;; # ( for vi parenthesis matching
545
546 -y)
547 OPT_y="${1}"
548 OPT_y_PARM="${2}" # Option parameter
549 ${v}echo "${C}.${0}: OPT_y=${OPT_y}, # -y yRANGE, scale range."
550 #${v}echo "${C}.${0}: OPT_y_PARM=${OPT_y_PARM}, # parameter desc."
551 yRANGE="${OPT_y_PARM}"
552 ${v}echo "${C}.${0}: yRANGE=${yRANGE}, # parameter desc."
553 shift
554 ;; # ( for vi parenthesis matching
555
556 -u)
557 OPT_u="-u"
558 ${v}echo "${C}.${0}: OPT_u=${OPT_u}, # -u Usage message."
559 echo "${USAGE}"
560 exit 4
561 ;; # ( for vi parenthesis matching
562
563 -a)
564 OPT_a="${1}"
565 ${v}echo "${C}.${0}: OPT_a=${OPT_a}, # -a Option description."
566 ;; # ( for vi parenthesis matching
567
568 -b)
569 OPT_b="${1}"
570 OPT_b_PARM="${2}" # Option parameter
571 ${v}echo "${C}.${0}: OPT_b=${OPT_b}, # -b Option description."
572 ${v}echo "${C}.${0}: OPT_b_PARM=${OPT_b_PARM}, # parameter desc."
573 shift
574 ;; # ( for vi parenthesis matching
575
576 --)
577 shift # Remove the "--".
578 break
579 ;; # ( for vi parenthesis matching
580
581 *)
582 echo "${C}.${0}: Option not understood. \"${1}\""
583 echo "USAGE message follows: "
584 echo "${USAGE}" # USAGE message
585 exit 2
586 ;;
587
588 esac
589 shift
590 done
591
592 # The rest of the command line parameters are files:
593
594 # If FILES is already set, leave it alone, else set it.
595 # This is necessary due running getopt twice, to support parameters
596 # embedded in the data files.
597 if [ "${FILES}" = "" ]; then
598 FILES="${FILES} ${*}" # May result in a blank, " ".
599 if [ "${FILES}" = " " ]; then # If blank, " ", make it empty.
600 FILES="" # Make FILES empty again.
601 fi
602 ${v}echo "${C}.${0}: FILES=${FILES}"
603 fi
604
605 # Set default options, if no applicable plot options were set.
606 COL_CTR="${#COL[*]}" # Columns were turned on.
607 ${v}echo "COL_CTR=${COL_CTR}, COL=${COL[*]}"
608
609 if [ "${COL_CTR}" = "0" ]; then # Option not set
610 ${v}echo "${C}.${0}: Setting default options."
611 FUNCTION__getopt -c2 -c4 # Set default, if no options set.
612 fi
613 if [ "${OPT_C}" = "-C" ] || # If -C or -P, ensure -S.
614 [ "${OPT_P}" = "-P" ]; then
615 if [ "${OPT_S}" != "-S" ]; then
616 FUNCTION__getopt -S # -S save files.
617 fi
618 fi
619
620 # Save a shar copy of this script, if -S and -v are both on.
621 # Turned off, may be useful later.
622
623 # if [ ! -z "${OPT_S}" ] && # -S save files.
624 # [ "${OPT_v}" = "-v" ]; then # -v verbose mode.
625 # ${v}echo "${C}.${0}: start of shar of script"
626 # shar -b ${C_PATH} >>${COMMAND}.shar
627 # ${v}echo "${C}.${0}: end of shar of script\n"
628 # fi
629
630 ${v}echo "${C}.${0}: completed at `date`\n" # end of function
631 } # FUNCTION__getopt() # Use function getopt.
632
633 FUNCTION_gnuplot_init() # Initialize gnuplot command file.
634 {
635 # INITIALIZE GNU_CMDFILE
636 #
637 # - Pass options to gnuplot.
638 # - Some options for gnuplot are set here (logscale, autoscale).
639
640 ${v}echo "${C}.${0}: beginning at `date`" # beginning of function
641 {
642 echo "# ${C_PATH} ${*}"
643 echo "# gnuplot ${GNU_GEOMETRY} ${GNU_CMDFILE}"
644 if [ "${OPT_L}" = "-L" ]; then # -L set logscale axis
645 echo "set logscale ${OPT_L_xaxis}${OPT_L_yaxis}"
646 fi
647 echo "set autoscale xy"
648 echo "set data style lines"
649 if [ ! -z "${OPT_G}" ]; then # Turn on grids.
650 echo "set grid"
651 fi
652
653 # Naming convention... build some kind of TITLE name, if none given.
654
655 TITLE="${TITLE:-JUDY BENCHMARK: $CMD_LINE }" # Set default.
656
657 echo "set title \"${TITLE}\" 0,0 "
658 if [ "${xRANGE}" != "" ]; then
659 echo "set xrange `FUNCTION_units ${xRANGE}`"
660 XLABEL="${XLABEL} ${xRANGE}"
661 fi
662 if [ "${yRANGE}" != "" ]; then
663 echo "set yrange `FUNCTION_units ${yRANGE}`"
664 YLABEL="${YLABEL} ${yRANGE}"
665 fi
666 echo "set xlabel \"${XLABEL}\" 0,0"
667 echo "set ylabel \"${YLABEL}\" 0,0"
668 echo "set label \"${XLOG}\" at 1,1"
669 } >> ${GNU_CMDFILE}
670
671 ${v}echo "${C}.${0}: completed at `date`\n" # end of function
672 } # FUNCTION_gnuplot_init() # Initialize gnuplot command file.
673
674 FUNCTION_gnuplot_plot() # Plot these files.
675 {
676 # FORMAT THE PLOT AND REPLOT COMMANDS
677 #
678 # - output to GNU_CMDFILE.
679
680 ${v}echo "${C}.${0}: beginning at `date`" # beginning of function
681 ${v}echo "${C}.${0}: FILES=${*}"
682
683 Fgp_PARM="${*}" # Save what was passed in.
684 Fgp_FILES="" # Initialize list of good files.
685 for i in ${Fgp_PARM}
686 do
687 if [ -r "$i" ]; then # Check that files are readable.
688 Fgp_FILES="${Fgp_FILES} ${i}" # Extend the list of good files.
689 else
690 echo "${C}.${0}: WARNING: file: ${i} cannot be read, ignored."
691 fi
692 done
693
694 let j=1
695 while [ ${j} -lt ${#CHA[*]} ] # For each type of plot.
696 do
697 for i in ${Fgp_FILES} # For each file.
698 do
699 CMN="${COL[$j]}"
700 if [ ! -z "${CMN}" ]; then
701 {
702 MSG="`basename ${i}`"
703 if [ "${OPT_H}" = "-H" ]; then
704 echo "${FIRST}plot \"${i}\" using 1:${CMN} t \"${CHA[${CMN}]} ${MSG}\""
705 elif [ "${OPT_NH}" = "-NH" ]; then
706 echo "${FIRST}plot \"${i}\" using 1:${CMN} t \"${MSG}\""
707 fi
708 } >> ${GNU_CMDFILE}
709 FIRST="re"
710 fi
711 done
712 let j=j+1
713 done
714
715 # A bug in gnuplot sometimes prevents all replots from appearing.
716 # This particularly happens when xrange is used.
717 # Doing an extra replot will plot everything.
718 echo replot >> ${GNU_CMDFILE}
719
720 ${v}echo "${C}.${0}: completed at `date`\n" # end of function
721 } # FUNCTION_gnuplot_plot() # Plot these files.
722
723 FUNCTION_gnuplot_display() # Plots the datapoints.
724 {
725 # DISPLAY PLOT TO SCREEN:
726
727 ${v}echo "${C}.${0}: beginning at `date`" # beginning of function
728
729 if [ "${OPT_V}" = "-V" ]; then
730 echo "hpterm -e vi -c \"vi ${GNU_CMDFILE} \""
731 hpterm -e vi -cvi ${GNU_CMDFILE} &
732 fi
733
734 if [ "${OPT_v}" = "-v" ]; then # -v verbose mode.
735 echo "${C}.${0}: executing command: "; echo "\n\
736 gnuplot ${GNU_GEOMETRY} ${GNU_CMDFILE}"
737 fi
738
739 # Add additional parameters as necessary to setup for printing:
740 if [ "${OPT_p}" = "-p" ]; then
741 {
742 echo set terminal postscript landscape color
743 echo set output \"${GNU_PSFILE}\"
744 echo replot
745 } >> ${GNU_CMDFILE}
746 fi
747
748 LINE="" # External response
749 while [ "${LINE}" != "q" ]
750 do
751 gnuplot ${GNU_GEOMETRY} ${GNU_CMDFILE}
752 LINE="q" # Setup for quit.
753 if [ "${OPT_V}" = "-V" ]; then
754 echo "Pause: press return to vi again, \"q\" to quit ${C}"
755 read -r LINE
756 fi
757 done
758
759 ${v}echo "${C}.${0}: completed at `date`\n" # end of function
760 } # FUNCTION_gnuplot_display() # Plots the datapoints.
761
762 FUNCTION_gnuplot_print() # -p print the plot.
763 {
764 #
765 # PRINT THE PLOT.
766 #
767 # - uses gnuplot command "replot".
768
769 ${v}echo "${C}.${0}: beginning at `date`" # beginning of function
770 ${v}echo "${C}.${0}: OPT_p=${OPT_p}, # -p print the plot."
771 ${v}echo "${C}.${0}: OPT_P=${OPT_P}, # GNU_PSFILE name."
772 GNU_PSFILE="${GNU_PSFILE:-$GNU_PSFILE_DEF}"
773 ${v}echo "${C}.${0}: GNU_PSFILE=${GNU_PSFILE}, # GNU_PSFILE name."
774
775 LP_DEV_PARM="-d ${LP_DEV:-$LP_DEV_DEF}" # Printer device parameter.
776 LP_OPT_PARM="${LP_OPT:-$LP_OPT_DEF}" # Printer option parameters.
777
778 echo "${C}.${0}: executing command: "; echo "\n\
779 echo lp ${LP_DEV_PARM} ${LP_OPT_PARM} ${GNU_PSFILE}"
780
781 lp ${LP_DEV_PARM} ${LP_OPT_PARM} ${GNU_PSFILE}
782
783 ${v}echo "${C}.${0}: completed at `date`\n" # end of function
784 } # FUNCTION_gnuplot_print() # Print the plot.
785
786 FUNCTION_TITLE_COLHEAD() # Set Column headings from file.
787 {
788 #
789 # Parse the TITLE and COLUMN HEADINGS (CHA) from the data, if available.
790 # Also parse other settable parameters, if available.
791 #
792
793 ${v}echo "${C}.${0}: beginning at `date`" # beginning of function
794 FTC_FILES="${*}" # Local list of file names.
795 ${v}echo "${C}.${0}: FTC_FILES=${FTC_FILES}"
796
797 # Choose the first readable file.
798 unset FTC_FILE # Hold the first readable filename.
799 for F in ${FTC_FILES} /dev/null # /dev/null ensures there is a file.
800 do
801 if [ -r "${F}" ] && # Is this file readable?
802 [ "${FTC_FILE}" = "" ]; then # We do not have one yet?
803 FTC_FILE="${F}" # Hold the first readable filename.
804 fi
805 done
806
807 # If FTC_FILE got set, use it to find TITLE, COLHEAD, XLABEL, YLABEL, et.al.
808 if [ "${FTC_FILE}" != "" ]; then # Use this file.
809 # Grab the FIRST TITLE line (head -1) and use it.
810 TITLE="`grep '^# *TITLE' ${FTC_FILE} | head -1 |
811 sed -e 's/^# *TITLE *//g'`"
812 ${v}echo "${C}.${0}: TITLE=${TITLE}"
813
814 # Grab the FIRST XLABEL line (head -1) and use it.
815 XLABEL="`grep '^# *XLABEL' ${FTC_FILE} | head -1 |
816 sed -e 's/^# *XLABEL *//g'`"
817 ${v}echo "${C}.${0}: XLABEL=${XLABEL}"
818
819 # Grab the FIRST YLABEL line (head -1) and use it.
820 YLABEL="`grep '^# *YLABEL' ${FTC_FILE} | head -1 |
821 sed -e 's/^# *YLABEL *//g'`"
822 ${v}echo "${C}.${0}: YLABEL=${YLABEL}"
823
824 # Find each COLHEAD, and put it in the correct CHA[INDEX].
825 let i=0
826 while [ ${i} -lt ${#CHA[*]} ] # For each COLHEAD
827 do
828 # Grab one COLHEAD line at a time, put it into CHA[].
829 # Note, "@" not allowed in COLHEAD string.
830 LINE="`grep \"^#.*COLHEAD\" ${FTC_FILE} | # Find COLHEAD.
831 sed -e 's/^#.*COLHEAD*//g' \
832 -e 's/^ *//g' \
833 -e 's/@//g' | # Remove COLHEAD.
834 expand | sed -e 's/^0*//g' | # Remove leading zeros.
835 grep ^${i} | # Find a line matching ${i}.
836 head -1 `" # Make sure there is only 1.
837
838 # Grab the INDEX number, could do numeric check if problems.
839 INDEX="`echo ${LINE} | cut -d\" \" -f1`" # field 1 is number.
840
841 # If INDEX is not empty, save this COLHEAD.
842 if [ "${INDEX}" != "" ]; then
843 # Grab the rest of the line and save it into CHA.
844 REMAINDER="`echo ${LINE} | sed -e \"s@^${INDEX} *@@g\"`"
845 CHA[${INDEX}]="${REMAINDER}"
846 ${v}echo "${C}.${0}: CHA[${INDEX}]=\"${CHA[${INDEX}]}\""
847 fi
848
849 let i=i+1
850 done
851
852 # GETOPT, pull in options to be set for this data.
853 GETOPT="`grep '^# *GETOPT' ${FTC_FILE} | head -1 |
854 sed -e 's/^# *GETOPT *//g'`"
855 if [ "${GETOPT}" != "" ]; then
856 FUNCTION__getopt ${GETOPT} # Parse the options.
857 fi
858 unset GETOPT
859
860 fi
861
862 ${v}echo "${C}.${0}: completed at `date`\n" # end of function
863 } # FUNCTION_TITLE_COLHEAD() # Set Column headings from file.
864
865 FUNCTION_n() # -n number plot descriptions.
866 {
867 # ADD COLUMN NUMBER TO EACH ELEMENT IN CHA:
868 #
869 # - This is done for comparing plots, and/or debugging.
870
871 ${v}echo "${C}.${0}: beginning at `date`" # beginning of function
872 ${v}echo "${C}.${0}: OPT_n=${OPT_n}, # -n number plot descriptions"
873
874 let i=0
875 while [ ${i} -lt ${#CHA[*]} ]
876 do
877 CHA[${i}]="${i} ${CHA[${i}]}"
878 ${v}echo "${C}.${0}: CHA[${i}]=\"${CHA[${i}]}\""
879 let i=i+1
880 done
881 ${v}echo "${C}.${0}: completed at `date`\n" # end of function
882 } # FUNCTION_n() # -n number plot descriptions.
883
884 FUNCTION_units() # Resolve units.
885 {
886 #
887 # Expand units of the form 1K to 1000, 1M to 1000000, et.al.
888 # Used to format the gnuplot parameters xRANGE and yRANGE.
889 # gnuplot data format: "set xrange [1:1000000]"
890 #
891
892 Fu_IN="${1}" # Units in.
893 echo "["${Fu_IN}"]" |
894 sed -e "s/[kK]/000/g" | # 1,000
895 sed -e "s/[mM]/000000/g" | # 1,000,000
896 sed -e "s/[gG]/000000000/g" | # 1,000,000,000
897 sed -e "s/^\[\[/\["/g | # Ensure single leading bracket.
898 sed -e "s/\]\]$/\]"/g # Ensure single trailing bracket.
899 }
900
901 FUNCTION_a() # -a Option description.
902 {
903 #
904 # Replace with description of this function.
905 #
906
907 ${v}echo "${C}.${0}: beginning at `date`" # beginning of function
908 ${v}echo "${C}.${0}: OPT_a=${OPT_a}, # -a Option description."
909 ${v}echo "${C}.${0}: completed at `date`\n" # end of function
910 } #
911
912 FUNCTION_b() # -b Option description.
913 {
914 #
915 # Replace with description of this function.
916 #
917
918 ${v}echo "${C}.${0}: beginning at `date`" # beginning of function
919 ${v}echo "${C}.${0}: OPT_b=${OPT_b}, # -b Option description."
920 MSG="# -b Parameter description."
921 ${v}echo "${C}.${0}: OPT_b_PARM=${OPT_b_PARM}, ${MSG}"
922
923 if [ -r "${OPT_b_PARM}" ]; then # Ensure this is a file.
924 echo ${OPT_b_PARM} |
925 while read -r FILE; do
926 ${v}echo "${C}.${0}: FILE=${FILE}"
927 done
928 else # Or use elif (form of elseif).
929 ${v}echo "${C}.${0}: ERROR, ${OPT_b_PARM} is not a readable file."
930 fi
931
932 ${v}echo "${C}.${0}: completed at `date`\n" # end of function
933 } #
934
935
936 #
937 # MAIN: Main driver, main processing occurs here.
938 #
939
940
941 ${v}echo " \n${C}: beginning at `date`" # page overflow with each start.
942
943 CMD_LINE="${0} ${*}" # Save command called and options.
944
945 FUNCTION__getopt ${*} # Parse the options.
946
947 if [ -z "${OPT_NE}" ] && # Not E is not turned on and E is...
948 [ ! -z "${OPT_E}" ]; then # -E use embedded options
949 FUNCTION_TITLE_COLHEAD ${FILES} # Set Column headings from file.
950 fi
951
952 FUNCTION__getopt ${*} >/dev/null 2>&1 # Parse the options.
953
954 type banner >/dev/null 2>&1 # Check if banner exists.
955 RC="${?}" # Save return code.
956 if [ "${RC}" = "0" ]; then # if RC=0, banner exists.
957 ${v}banner ${C}
958 fi
959
960 ${v}echo "${C}: RCS_SCRIPT=${RCS_SCRIPT}"
961 ${v}echo "${C}: PWD=${PWD}"
962
963 if [ ! -z "${OPT_n}" ]; then
964 FUNCTION_n # -n number plot descriptions.
965 fi
966
967 # If GNU_CMDFILE exists, use it, do not create it.
968 if [ ! -f ${GNU_CMDFILE} ]; then # ! -f = if this is not a file.
969 if [ "${FILES}" = "" ]; then # If no files available
970 MSG="and GNU_CMDFILE is not a file exit 7"
971 echo "${C}: ERROR: no FILES to plot! ${MSG}"
972 exit 7
973 break
974 fi
975 FUNCTION_gnuplot_init ${*} # Initialize gnuplot command file.
976
977 FUNCTION_gnuplot_plot ${FILES} # Plot these files.
978
979 echo pause -1 \'Pause: press return to continue.\' >> ${GNU_CMDFILE}
980 echo # Place blank line in log file.
981 fi
982
983 FUNCTION_gnuplot_display # Plots the datapoints.
984
985
986 if [ ! -z "${OPT_p}" ]; then
987 FUNCTION_gnuplot_print # -p print the plot.
988 fi
989
990
991 # REMOVE FILES, CLEANUP:
992 #
993 # Remove the working files and filenames, unless "-S" is on.
994
995 if [ "${OPT_S}" = "-S" ]; then # -S save files.
996 echo "${C}: saving ${COMMAND}"
997 echo "${C}: saving ${GNU_CMDFILE}"
998 if [ "${OPT_p}" = "-p" ]; then
999 echo "${C}: saving ${GNU_PSFILE}"
1000 fi
1001 else
1002 rm -f ${COMMAND} # Remove generated log file.
1003 rm -f ${GNU_CMDFILE} # Remove generated command file.
1004 rm -f ${GNU_PSFILE} # Remove generated .ps file.
1005 fi
1006
1007 rm -fr ${COMMAND}.WORK*.$$ # Remove generated work files.
1008
1009 ${v}echo "${C}: completed at `date`\n^L"
1010
1011 # Message if -v (verbose):
1012
1013 if [ "${OPT_v}" = "-v" ]; then # -v verbose mode.
1014 echo "${INFO}"
1015 fi
1016
1017 # DONE:
1018 #
1019 # - If a log file needs to be kept, uncomment the corresponding ():
1020
1021 } 2>&1 | tee -a ${COMMAND} # Use during testing.
1022 #) >>${COMMAND} 2>&1 & # Use for production.