2 // implementation of the "Dg" tcl command
6 * Revision 1.4 1996/01/19 20:56:18 newhall
7 * changes due to visiLib interface changes
9 * Revision 1.3 1996/01/17 18:31:36 newhall
10 * changes due to new visiLib
12 * Revision 1.2 1995/11/08 21:45:56 tamches
13 * specialized s.t. only the implementation of the "Dg" tcl command is here
15 * Revision 1.1 1995/11/04 00:44:11 tamches
16 * First version of new table visi
20 #include <stdlib.h> // exit()
27 #include "tableVisiTcl.h"
29 #include "visi/h/visualization.h"
39 #define NUMRESOURCES 7
41 #define RESOURCENAME 9
42 #define STARTSTREAM 10
50 #define FIRSTBUCKET 18
58 static struct cmdTabEntry Dg_Cmds[] = {
59 {"aggregate", AGGREGATE, 2},
60 {"binwidth", BINWIDTH, 0},
61 {"firstbucket", FIRSTBUCKET, 2},
62 {"foldmethod", FOLDMETHOD, 2},
63 {"lastbucket", LASTBUCKET, 2},
64 {"metricname", METRICNAME, 1},
65 {"metricunits", METRICUNITS, 1},
66 {"numbins", NUMBINS, 0},
67 {"nummetrics", NUMMETRICS, 0},
68 {"numresources", NUMRESOURCES, 0},
69 {"phase", DEFINEPHASE, 3},
70 {"resourcename", RESOURCENAME, 1},
71 {"start", STARTSTREAM, 2},
72 {"stop", STOPSTREAM, 2},
74 {"valid", DGVALID, 2},
75 {"enabled", DGENABLED, 2},
80 int findCommand(Tcl_Interp *interp,
85 sprintf(interp->result, "USAGE: Dg <option> [args...]\n");
89 for (cmdTabEntry *C = Dg_Cmds; C->cmdname!=NULL; C++) {
90 if (strcmp(argv[0], C->cmdname) == 0) {
91 if (argc-1 == C->numargs)
92 return C->index; // successful parsing
94 sprintf(interp->result,
95 "%s: wrong number of args (%d). Should be %d\n",
96 argv[0], argc-1, C->numargs);
101 sprintf(interp->result, "unknown option (%s)\n", argv[0]);
105 int Dg_TclCommand(ClientData, Tcl_Interp *interp,
106 int argc, char *argv[]) {
107 // entrypoint to the tcl "Dg" command we've installed
108 // all the sprintf()'s are rather slow...
110 // parse the arguments, using global vrble Dg_Cmds[] to tell what's what.
111 int cmdDex = findCommand(interp, argc-1, argv+1);
112 if (cmdDex == CMDERROR)
115 int m, r, buck; // metric number, resource number, bucket number
121 sprintf(interp->result,"%g", visi_AverageValue(m,r));
125 sprintf(interp->result, "%g", visi_BucketWidth());
131 sprintf(interp->result,"%d", visi_FirstValidBucket(m,r));
137 sprintf(interp->result,"%d", visi_LastBucketFilled(m,r));
142 sprintf(interp->result, "%s", visi_MetricName(m));
147 sprintf(interp->result, "%s", visi_MetricUnits(m));
151 sprintf(interp->result, "%d", visi_NumBuckets());
155 sprintf(interp->result, "%d", visi_NumMetrics());
159 sprintf(interp->result, "%d", visi_NumResources());
163 visi_DefinePhase(NULL);
168 sprintf(interp->result, "%s", visi_ResourceName(r));
172 visi_GetMetsRes(argv[2], atoi(argv[3]));
178 visi_StopMetRes(m, r);
184 sprintf(interp->result,"%g", visi_SumValue(m,r));
190 sprintf(interp->result, "%d", visi_Valid(m,r));
196 sprintf(interp->result, "%d", visi_Enabled(m,r));
202 buck = atoi(argv[4]);
203 sprintf(interp->result,"%g", visi_DataValue(m,r,buck));
207 sprintf(interp->result, "Internal error (func findCommand)\n");
211 int Dg2_Init(Tcl_Interp *interp) {
212 Tcl_CreateCommand(interp, "Dg", Dg_TclCommand,
213 (ClientData *) NULL,(Tcl_CmdDeleteProc *) NULL);