00001 #include <stdio.h>
00002 #include <string.h>
00003 #include <tcl.h>
00004 #include <tk.h>
00005 #include "sadie.h"
00006
00007 extern Tcl_Interp *MainTclInterp;
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 short
00020 PLOT (PIXEL ** data,
00021 short narray,
00022 short npix,
00023 char *minxlbl,
00024 char *maxxlbl,
00025 short option
00026
00027
00028
00029
00030 )
00031 {
00032 Tcl_Interp *interp = MainTclInterp;
00033 Tcl_Obj *position = NULL;
00034 register int i, j;
00035 char msg[SLEN];
00036 PIXEL gmin, gmax;
00037 int minval, maxval, range, tempval, xpos, delta, height, xoffset, yoffset;
00038 int minypos, maxypos;
00039 char plotname[30];
00040 char commandstr[200];
00041 char *tclstr;
00042 char fillcolor[20];
00043 PIXEL *line = NULL;
00044
00045 tclstr = &commandstr[0];
00046
00047 if (TIMES)
00048 TIMING (T_PLOT);
00049 if (NAMES)
00050 {
00051 MESSAGE ('I', "");
00052 MESSAGE ('I', "PLOT");
00053 MESSAGE ('I', "");
00054 sprintf (msg, " Number of arrays: %d", narray);
00055 MESSAGE ('I', msg);
00056 sprintf (msg, " Number of pixels: %d", npix);
00057 MESSAGE ('I', msg);
00058 if (option == UNIT)
00059 {
00060 MESSAGE ('I', " Ordinate range is \\[-1,+1\\]");
00061 }
00062 else if (option == NORM)
00063 {
00064 MESSAGE ('I', " Normalized ordinate");
00065 }
00066 else if (option == LOG)
00067 {
00068 MESSAGE ('I', " Logarithmic ordinate");
00069 }
00070 MESSAGE ('I', " ...............");
00071 }
00072
00073
00074 if (option != UNIT && option != NORM && option != LOG)
00075 {
00076 MESSAGE ('E', " Option must be one of UNIT, NORM, or LOG.");
00077 goto the_end;
00078 }
00079
00080
00081 if (option == UNIT)
00082 {
00083 gmin = (PIXEL) - 1;
00084 gmax = (PIXEL) 1;
00085 }
00086 else
00087 {
00088 gmax = gmin = data[0][0];
00089 for (j = 0; j < narray; j++)
00090 {
00091 line = data[j];
00092 for (i = 0; i < npix; i++)
00093 {
00094 gmin = min (gmin, line[i]);
00095 gmax = max (gmax, line[i]);
00096 }
00097 }
00098 if (option == LOG)
00099 {
00100 if (gmin < (PIXEL) 0)
00101 {
00102 MESSAGE ('E',
00103 " Graylevel values must be greater than or equal to zero for logarithmic ordinate.");
00104 goto the_end;
00105 }
00106 gmin = (PIXEL) log10 ((double) gmin + 1.0);
00107 gmax = (PIXEL) log10 ((double) gmax + 1.0);
00108 }
00109 }
00110
00111 minval = (int) gmin;
00112 maxval = (int) gmax;
00113 range = maxval - minval;
00114
00115
00116 sprintf (plotname, ".sessionlog.canvas");
00117
00118 position =
00119 Tcl_ObjGetVar2 (interp, Tcl_NewStringObj ("SadieVar", -1),
00120 Tcl_NewStringObj ("sessionlog,pos", -1), TCL_GLOBAL_ONLY);
00121 if (Tcl_GetIntFromObj (interp, position, &yoffset) != TCL_OK)
00122 {
00123 Tcl_BackgroundError (interp);
00124 goto the_end;
00125 }
00126
00127 yoffset += 15;
00128
00129 for (j = 0; j < narray; j++)
00130 {
00131 line = data[j];
00132 xoffset = (j * (npix + 100));
00133
00134
00135 if (narray == 1 || j > 2)
00136 {
00137 sprintf (fillcolor, "black");
00138 }
00139 else if (j == 0)
00140 {
00141 sprintf (fillcolor, "red");
00142 }
00143 else if (j == 1)
00144 {
00145 sprintf (fillcolor, "green");
00146 }
00147 else
00148 {
00149 sprintf (fillcolor, "blue");
00150 }
00151
00152
00153 sprintf (tclstr,
00154 "%s create line %d %d %d %d -arrow none -fill black -width 1.5",
00155 plotname, (60 + xoffset), (10 + yoffset), (60 + xoffset),
00156 (116 + yoffset));
00157 if (Tcl_Eval (interp, tclstr) != TCL_OK)
00158 {
00159 return TCL_ERROR;
00160 }
00161
00162 sprintf (tclstr,
00163 "%s create line %d %d %d %d -arrow none -fill black -width 1.5",
00164 plotname, (55 + xoffset), (111 + yoffset),
00165 (61 + npix + xoffset), (111 + yoffset));
00166 if (Tcl_Eval (interp, tclstr) != TCL_OK)
00167 {
00168 return TCL_ERROR;
00169 }
00170
00171 sprintf (tclstr,
00172 "%s create line %d %d %d %d -arrow none -fill black -width 1.5",
00173 plotname, (55 + xoffset), (10 + yoffset), (60 + xoffset),
00174 (10 + yoffset));
00175 if (Tcl_Eval (interp, tclstr) != TCL_OK)
00176 {
00177 return TCL_ERROR;
00178 }
00179
00180 for (i = 1; (i * 16) < npix; i++)
00181 {
00182 if ((i % 2) == 0)
00183 {
00184 sprintf (tclstr,
00185 "%s create line %d %d %d %d -arrow none -fill black -width 1.5",
00186 plotname, (61 + (16 * i) + xoffset), (111 + yoffset),
00187 (61 + (16 * i) + xoffset), (116 + yoffset));
00188 if (Tcl_Eval (interp, tclstr) != TCL_OK)
00189 {
00190 return TCL_ERROR;
00191 }
00192 }
00193 else
00194 {
00195 sprintf (tclstr,
00196 "%s create line %d %d %d %d -arrow none -fill black -width 1.5",
00197 plotname, (61 + (16 * i) + xoffset), (111 + yoffset),
00198 (61 + (16 * i) + xoffset), (114 + yoffset));
00199 if (Tcl_Eval (interp, tclstr) != TCL_OK)
00200 {
00201 return TCL_ERROR;
00202 }
00203 }
00204 }
00205
00206 sprintf (tclstr,
00207 "%s create text %d %d -anchor e -fill black -text \"%d\"",
00208 plotname, (53 + xoffset), (10 + yoffset), maxval);
00209 if (Tcl_Eval (interp, tclstr) != TCL_OK)
00210 {
00211 return TCL_ERROR;
00212 }
00213
00214 sprintf (tclstr,
00215 "%s create text %d %d -anchor e -fill black -text \"%d\"",
00216 plotname, (53 + xoffset), (111 + yoffset), minval);
00217 if (Tcl_Eval (interp, tclstr) != TCL_OK)
00218 {
00219 return TCL_ERROR;
00220 }
00221
00222 sprintf (tclstr,
00223 "%s create text %d %d -anchor n -fill black -text \"%s\"",
00224 plotname, (60 + xoffset), (118 + yoffset), minxlbl);
00225 if (Tcl_Eval (interp, tclstr) != TCL_OK)
00226 {
00227 return TCL_ERROR;
00228 }
00229
00230 sprintf (tclstr,
00231 "%s create text %d %d -anchor n -fill black -text \"%s\"",
00232 plotname, (61 + npix + xoffset), (118 + yoffset), maxxlbl);
00233 if (Tcl_Eval (interp, tclstr) != TCL_OK)
00234 {
00235 return TCL_ERROR;
00236 }
00237
00238
00239 for (i = 0; i < npix; i++)
00240 {
00241 tempval = (int) line[i];
00242 xpos = (i + 61);
00243 delta = tempval - minval;
00244
00245 if (option == UNIT)
00246 {
00247 height =
00248 max (0,
00249 min (rnd (83.3 * (double) delta / (double) range), 100));
00250 }
00251 else if (option == NORM)
00252 {
00253 height = rnd (100.0 * (double) delta / (double) range);
00254 }
00255 else
00256 {
00257 height =
00258 rnd (100.0 *
00259 (log10 ((double) line[i] + 1.0) -
00260 (double) gmin) / (gmax - gmin));
00261 }
00262
00263 minypos = 15;
00264 maxypos = (minypos + height);
00265
00266 sprintf (tclstr, "%s create line %d %d %d %d -arrow none -fill %s",
00267 plotname, (xpos + xoffset), yoffset + (125 - maxypos),
00268 (xpos + xoffset), yoffset + (125 - minypos), fillcolor);
00269 if (Tcl_Eval (interp, tclstr) != TCL_OK)
00270 {
00271 MESSAGE ('E', " Error drawing plot data!");
00272 return TCL_ERROR;
00273 }
00274 }
00275
00276 }
00277
00278 sprintf (tclstr, "update_sessionlog_view");
00279 if (Tcl_Eval (interp, tclstr) != TCL_OK)
00280 {
00281 MESSAGE ('E', " Error when moving to bottom of sessionlog!");
00282 return TCL_ERROR;
00283 }
00284
00285 yoffset += 140;
00286 Tcl_ObjSetVar2 (interp, Tcl_NewStringObj ("SadieVar", -1),
00287 Tcl_NewStringObj ("sessionlog,pos", -1),
00288 Tcl_NewIntObj (yoffset), TCL_GLOBAL_ONLY);
00289
00290 the_end:
00291 if (TIMES)
00292 TIMING (T_EXIT);
00293 }