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
00020 short PLOT (
00021 PIXEL **data,
00022 short narray,
00023 short npix,
00024 char *minxlbl,
00025 char *maxxlbl,
00026 short option
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
00046 tclstr = &commandstr[0];
00047
00048 if (TIMES) TIMING(T_PLOT);
00049 if (NAMES) {
00050 MESSAGE('I',"");
00051 MESSAGE('I',"PLOT");
00052 MESSAGE('I',"");
00053 sprintf(msg," Number of arrays: %d",narray);
00054 MESSAGE('I',msg);
00055 sprintf(msg," Number of pixels: %d",npix);
00056 MESSAGE('I',msg);
00057 if (option == UNIT) {
00058 MESSAGE('I'," Ordinate range is \\[-1,+1\\]");
00059 } else if (option == NORM) {
00060 MESSAGE('I'," Normalized ordinate");
00061 } else if (option == LOG) {
00062 MESSAGE('I'," Logarithmic ordinate");
00063 }
00064 MESSAGE('I'," ...............");
00065 }
00066
00067
00068 if (option != UNIT && option != NORM && option != LOG) {
00069 MESSAGE('E'," Option must be one of UNIT, NORM, or LOG.");
00070 goto the_end;
00071 }
00072
00073
00074 if (option == UNIT) {
00075 gmin = (PIXEL)-1;
00076 gmax = (PIXEL) 1;
00077 } else {
00078 gmax = gmin = data[0][0];
00079 for (j=0; j<narray; j++) {
00080 line = data[j];
00081 for (i=0; i<npix; i++) {
00082 gmin = min(gmin,line[i]);
00083 gmax = max(gmax,line[i]);
00084 }
00085 }
00086 if (option == LOG) {
00087 if (gmin < (PIXEL)0) {
00088 MESSAGE('E'," Graylevel values must be greater than or equal to zero for logarithmic ordinate.");
00089 goto the_end;
00090 }
00091 gmin = (PIXEL)log10((double)gmin+1.0);
00092 gmax = (PIXEL)log10((double)gmax+1.0);
00093 }
00094 }
00095
00096
00097 minval = (int) gmin;
00098 maxval = (int) gmax;
00099 range = maxval - minval;
00100
00101
00102
00103 sprintf(plotname, ".sessionlog.canvas");
00104
00105 position = Tcl_ObjGetVar2(interp,Tcl_NewStringObj("SadieVar",-1),Tcl_NewStringObj("sessionlog,pos",-1),TCL_GLOBAL_ONLY);
00106 if (Tcl_GetIntFromObj(interp, position, &yoffset) != TCL_OK) {
00107 Tcl_BackgroundError(interp);
00108 goto the_end;
00109 }
00110
00111 yoffset += 15;
00112
00113 for (j=0; j<narray; j++) {
00114 line = data[j];
00115 xoffset = (j * (npix + 100));
00116
00117
00118 if (narray == 1 || j > 2) {
00119 sprintf(fillcolor, "black");
00120 } else if (j == 0) {
00121 sprintf(fillcolor, "red");
00122 }
00123 else if (j == 1) {
00124 sprintf(fillcolor, "green");
00125 }
00126 else {
00127 sprintf(fillcolor, "blue");
00128 }
00129
00130
00131
00132
00133
00134 sprintf(tclstr, "%s create line %d %d %d %d -arrow none -fill black -width 1.5", plotname, (60 + xoffset), (10+yoffset), (60+xoffset), (116+yoffset));
00135 if( Tcl_Eval(interp, tclstr) != TCL_OK ) {
00136 return TCL_ERROR;
00137 }
00138
00139 sprintf(tclstr, "%s create line %d %d %d %d -arrow none -fill black -width 1.5", plotname, (55+xoffset), (111+yoffset), (61+npix+xoffset), (111+yoffset));
00140 if( Tcl_Eval(interp, tclstr) != TCL_OK ) {
00141 return TCL_ERROR;
00142 }
00143
00144 sprintf(tclstr, "%s create line %d %d %d %d -arrow none -fill black -width 1.5", plotname, (55+xoffset), (10+yoffset), (60+xoffset), (10+yoffset));
00145 if( Tcl_Eval(interp, tclstr) != TCL_OK ) {
00146 return TCL_ERROR;
00147 }
00148
00149 for (i=1; (i*16) < npix; i++) {
00150 if ((i%2) == 0) {
00151 sprintf(tclstr, "%s create line %d %d %d %d -arrow none -fill black -width 1.5", plotname, (61+(16*i)+xoffset), (111+yoffset), (61+(16*i)+xoffset), (116+yoffset));
00152 if( Tcl_Eval(interp, tclstr) != TCL_OK ) {
00153 return TCL_ERROR;
00154 }
00155 }
00156 else {
00157 sprintf(tclstr, "%s create line %d %d %d %d -arrow none -fill black -width 1.5", plotname, (61+(16*i)+xoffset), (111+yoffset), (61+(16*i)+xoffset), (114+yoffset));
00158 if( Tcl_Eval(interp, tclstr) != TCL_OK ) {
00159 return TCL_ERROR;
00160 }
00161 }
00162 }
00163
00164 sprintf(tclstr, "%s create text %d %d -anchor e -fill black -text \"%d\"", plotname, (53+xoffset), (10+yoffset), maxval);
00165 if( Tcl_Eval(interp, tclstr) != TCL_OK ) {
00166 return TCL_ERROR;
00167 }
00168
00169 sprintf(tclstr, "%s create text %d %d -anchor e -fill black -text \"%d\"", plotname, (53+xoffset), (111+yoffset), minval);
00170 if( Tcl_Eval(interp, tclstr) != TCL_OK ) {
00171 return TCL_ERROR;
00172 }
00173
00174 sprintf(tclstr, "%s create text %d %d -anchor n -fill black -text \"%s\"", plotname, (60+xoffset), (118+yoffset), minxlbl);
00175 if( Tcl_Eval(interp, tclstr) != TCL_OK ) {
00176 return TCL_ERROR;
00177 }
00178
00179 sprintf(tclstr, "%s create text %d %d -anchor n -fill black -text \"%s\"", plotname, (61+npix+xoffset), (118+yoffset), maxxlbl);
00180 if( Tcl_Eval(interp, tclstr) != TCL_OK ) {
00181 return TCL_ERROR;
00182 }
00183
00184
00185
00186
00187
00188 for (i=0; i<npix; i++) {
00189 tempval = (int)line[i];
00190 xpos = (i + 61);
00191 delta = tempval - minval;
00192
00193 if (option == UNIT) {
00194 height = max(0,min(rnd(83.3*(double)delta/(double)range),100));
00195 } else if (option == NORM) {
00196 height = rnd(100.0*(double)delta/(double)range);
00197 } else {
00198 height = rnd(100.0*(log10((double)line[i]+1.0)-(double)gmin)/(gmax-gmin));
00199 }
00200
00201 minypos = 15;
00202 maxypos = (minypos + height);
00203
00204 sprintf(tclstr, "%s create line %d %d %d %d -arrow none -fill %s", plotname, (xpos+xoffset), yoffset+(125-maxypos), (xpos+xoffset), yoffset+(125-minypos),fillcolor);
00205 if( Tcl_Eval(interp, tclstr) != TCL_OK ) {
00206 MESSAGE('E'," Error drawing plot data!");
00207 return TCL_ERROR;
00208 }
00209 }
00210
00211 }
00212
00213 sprintf(tclstr, "update_sessionlog_view");
00214 if( Tcl_Eval(interp, tclstr) != TCL_OK ) {
00215 MESSAGE('E'," Error when moving to bottom of sessionlog!");
00216 return TCL_ERROR;
00217 }
00218
00219 yoffset += 140;
00220 Tcl_ObjSetVar2(interp,Tcl_NewStringObj("SadieVar",-1),Tcl_NewStringObj("sessionlog,pos",-1),Tcl_NewIntObj(yoffset),TCL_GLOBAL_ONLY);
00221
00222
00223 the_end:
00224 if (TIMES) TIMING(T_EXIT);
00225 }
00226
00227
00228
00229
00230
00231
00232
00233
00234