2 // implementation of the "Dg" tcl command
6 * Revision 1.3 1996/01/17 18:31:36 newhall
7 * changes due to new visiLib
9 * Revision 1.2 1995/11/08 21:45:56 tamches
10 * specialized s.t. only the implementation of the "Dg" tcl command is here
12 * Revision 1.1 1995/11/04 00:44:11 tamches
13 * First version of new table visi
17 #include <stdlib.h> // exit()
24 #include "tableVisiTcl.h"
26 #include "visi/h/visualization.h"
36 #define NUMRESOURCES 7
38 #define RESOURCENAME 9
39 #define STARTSTREAM 10
47 #define FIRSTBUCKET 18
55 static struct cmdTabEntry Dg_Cmds[] = {
56 {"aggregate", AGGREGATE, 2},
57 {"binwidth", BINWIDTH, 0},
58 {"firstbucket", FIRSTBUCKET, 2},
59 {"foldmethod", FOLDMETHOD, 2},
60 {"lastbucket", LASTBUCKET, 2},
61 {"metricname", METRICNAME, 1},
62 {"metricunits", METRICUNITS, 1},
63 {"numbins", NUMBINS, 0},
64 {"nummetrics", NUMMETRICS, 0},
65 {"numresources", NUMRESOURCES, 0},
66 {"phase", DEFINEPHASE, 3},
67 {"resourcename", RESOURCENAME, 1},
68 {"start", STARTSTREAM, 2},
69 {"stop", STOPSTREAM, 2},
71 {"valid", DGVALID, 2},
72 {"enabled", DGENABLED, 2},
77 int findCommand(Tcl_Interp *interp,
82 sprintf(interp->result, "USAGE: Dg <option> [args...]\n");
86 for (cmdTabEntry *C = Dg_Cmds; C->cmdname!=NULL; C++) {
87 if (strcmp(argv[0], C->cmdname) == 0) {
88 if (argc-1 == C->numargs)
89 return C->index; // successful parsing
91 sprintf(interp->result,
92 "%s: wrong number of args (%d). Should be %d\n",
93 argv[0], argc-1, C->numargs);
98 sprintf(interp->result, "unknown option (%s)\n", argv[0]);
102 int Dg_TclCommand(ClientData, Tcl_Interp *interp,
103 int argc, char *argv[]) {
104 // entrypoint to the tcl "Dg" command we've installed
105 // all the sprintf()'s are rather slow...
107 // parse the arguments, using global vrble Dg_Cmds[] to tell what's what.
108 int cmdDex = findCommand(interp, argc-1, argv+1);
109 if (cmdDex == CMDERROR)
112 int m, r, buck; // metric number, resource number, bucket number
118 sprintf(interp->result,"%g", visi_AverageValue(m,r));
122 sprintf(interp->result, "%g", visi_BucketWidth());
128 sprintf(interp->result,"%d", visi_FirstValidBucket(m,r));
134 sprintf(interp->result,"%d", visi_LastBucketFilled(m,r));
139 sprintf(interp->result, "%s", visi_MetricName(m));
144 sprintf(interp->result, "%s", visi_MetricUnits(m));
148 sprintf(interp->result, "%d", visi_NumBuckets());
152 sprintf(interp->result, "%d", visi_NumMetrics());
156 sprintf(interp->result, "%d", visi_NumResources());
160 visi_DefinePhase(-1.0,NULL);
165 sprintf(interp->result, "%s", visi_ResourceName(r));
169 visi_GetMetsRes(argv[2], atoi(argv[3]), 0); // 0-->histogram (1-->scalar)
176 visi_StopMetRes(m, r);
182 sprintf(interp->result,"%g", visi_SumValue(m,r));
188 sprintf(interp->result, "%d", visi_Valid(m,r));
194 sprintf(interp->result, "%d", visi_Enabled(m,r));
200 buck = atoi(argv[4]);
201 sprintf(interp->result,"%g", visi_DataValue(m,r,buck));
205 sprintf(interp->result, "Internal error (func findCommand)\n");
209 int Dg2_Init(Tcl_Interp *interp) {
210 Tcl_CreateCommand(interp, "Dg", Dg_TclCommand,
211 (ClientData *) NULL,(Tcl_CmdDeleteProc *) NULL);