00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include <tcl.h>
00015 #include <tk.h>
00016 #include "sadie.h"
00017
00018
00019
00020 static char rcsid[] = "$Id: Sadie_General.c,v 2.1 1999/01/14 15:37:32 conner Exp $";
00021
00022
00023
00024 int Sadie_General_CloseCmd(ClientData client_data, Tcl_Interp* interp, int argc, char *argv[])
00025 {
00026 int imgaddr;
00027 IMAGE *theimg;
00028 char msg[SLEN];
00029
00030 if( argc <= 1 ) {
00031 sprintf(msg, "Usage: Sadie_General_Close image_address");
00032 Tcl_SetResult(interp, msg, TCL_VOLATILE);
00033 return TCL_ERROR;
00034 }
00035
00036 sscanf(argv[1], "%x", &imgaddr);
00037 theimg = (IMAGE *) imgaddr;
00038
00039
00040 RELIMG(&theimg);
00041
00042 return TCL_OK;
00043 }
00044
00045
00046 int Sadie_General_InitializeProgCmd(ClientData client_data, Tcl_Interp* interp, int argc, char *argv[])
00047 {
00048 INIT();
00049
00050 return TCL_OK;
00051 }
00052
00053
00054 int Sadie_General_FinishProgCmd(ClientData client_data, Tcl_Interp* interp, int argc, char *argv[])
00055 {
00056 FINI();
00057
00058 return TCL_OK;
00059 }
00060
00061
00062
00063 int Sadie_General_WidthCmd(ClientData client_data, Tcl_Interp* interp, int argc, char *argv[])
00064 {
00065 int imgaddr;
00066 IMAGE *theimg;
00067 char msg[SLEN];
00068
00069 if( argc <= 1 ) {
00070 sprintf(msg, "Usage: Sadie_General_Width image_address");
00071 Tcl_SetResult(interp, msg, TCL_VOLATILE);
00072 return TCL_ERROR;
00073 }
00074
00075 sscanf(argv[1], "%x", &imgaddr);
00076 theimg = (IMAGE *) imgaddr;
00077
00078 if (!CHECKIMG(theimg)) {
00079 Tcl_AppendResult(interp, "couldn't identify SADIE image from input string.", NULL);
00080 return TCL_ERROR;
00081 }
00082
00083 sprintf(msg, "%d", (int) floor((double)theimg->npix));
00084 Tcl_SetResult(interp, msg, TCL_VOLATILE);
00085
00086
00087 return TCL_OK;
00088 }
00089
00090
00091
00092 int Sadie_General_HeightCmd(ClientData client_data, Tcl_Interp* interp, int argc, char *argv[])
00093 {
00094 int imgaddr;
00095 IMAGE *theimg;
00096 char msg[SLEN];
00097
00098 if( argc <= 1 ) {
00099 sprintf(msg, "Usage: Sadie_General_Height image_address");
00100 Tcl_SetResult(interp, msg, TCL_VOLATILE);
00101 return TCL_ERROR;
00102 }
00103
00104 sscanf(argv[1], "%x", &imgaddr);
00105 theimg = (IMAGE *) imgaddr;
00106
00107 if (!CHECKIMG(theimg)) {
00108 Tcl_AppendResult(interp, "couldn't identify SADIE image from input string.", NULL);
00109 return TCL_ERROR;
00110 }
00111
00112 sprintf(msg, "%d", (int) floor((double)theimg->nlin));
00113 Tcl_SetResult(interp, msg, TCL_VOLATILE);
00114
00115
00116 return TCL_OK;
00117 }
00118
00119
00120
00121
00122 int Sadie_General_GminCmd(ClientData client_data, Tcl_Interp* interp, int argc, char *argv[])
00123 {
00124 int imgaddr;
00125 IMAGE *theimg;
00126 char msg[SLEN];
00127
00128 if( argc <= 1 ) {
00129 sprintf(msg, "Usage: Sadie_General_Gmin image_address");
00130 Tcl_SetResult(interp, msg, TCL_VOLATILE);
00131 return TCL_ERROR;
00132 }
00133
00134 sscanf(argv[1], "%x", &imgaddr);
00135 theimg = (IMAGE *) imgaddr;
00136
00137 if (!CHECKIMG(theimg)) {
00138 Tcl_AppendResult(interp, "couldn't identify SADIE image from input string.", NULL);
00139 return TCL_ERROR;
00140 }
00141
00142 RANGE(theimg);
00143
00144 sprintf(msg, "%d", (int) floor((double)theimg->gmin));
00145 Tcl_SetResult(interp, msg, TCL_VOLATILE);
00146
00147
00148 return TCL_OK;
00149 }
00150
00151
00152
00153 int Sadie_General_GmaxCmd(ClientData client_data, Tcl_Interp* interp, int argc, char *argv[])
00154 {
00155 int imgaddr;
00156 IMAGE *theimg;
00157 char msg[SLEN];
00158
00159 if( argc <= 1 ) {
00160 sprintf(msg, "Usage: Sadie_General_Gmax image_address");
00161 Tcl_SetResult(interp, msg, TCL_VOLATILE);
00162 return TCL_ERROR;
00163 }
00164
00165 sscanf(argv[1], "%x", &imgaddr);
00166 theimg = (IMAGE *) imgaddr;
00167
00168 if (!CHECKIMG(theimg)) {
00169 Tcl_AppendResult(interp, "couldn't identify SADIE image from input string.", NULL);
00170 return TCL_ERROR;
00171 }
00172
00173 RANGE(theimg);
00174
00175 sprintf(msg, "%d", (int) floor((double)theimg->gmax));
00176 Tcl_SetResult(interp, msg, TCL_VOLATILE);
00177
00178
00179 return TCL_OK;
00180 }
00181
00182
00183
00184 int Sadie_General_GetNumBandsCmd(ClientData client_data, Tcl_Interp* interp, int argc, char *argv[])
00185 {
00186 int inimgaddr;
00187 int number;
00188 IMAGE *inimg;
00189 char msg[SLEN];
00190
00191 if( argc <= 1 ) {
00192 return TCL_ERROR;
00193 }
00194
00195
00196 sscanf(argv[1], "%x", &inimgaddr);
00197 inimg = (IMAGE *) inimgaddr;
00198
00199 number = inimg->nbnd;
00200
00201 sprintf(msg, "%d", number);
00202 Tcl_SetResult(interp, msg, TCL_VOLATILE);
00203
00204 return TCL_OK;
00205
00206 }
00207
00208
00209
00210
00211 int Sadie_General_GetPixelCmd(ClientData client_data, Tcl_Interp* interp, int argc, char *argv[])
00212 {
00213 int imgaddr;
00214 int xval, yval;
00215 double rval, gval, bval;
00216 IMAGE *theimg;
00217 char msg[SLEN];
00218
00219 if( argc <= 3 ) {
00220 sprintf(msg, "Usage: Sadie_General_GetPixel image_address xcoord ycoord");
00221 Tcl_SetResult(interp, msg, TCL_VOLATILE);
00222 return TCL_ERROR;
00223 }
00224
00225 sscanf(argv[1], "%x", &imgaddr);
00226 theimg = (IMAGE *) imgaddr;
00227
00228 if( Tcl_GetInt (interp, argv[2], &xval) != TCL_OK ) {
00229 return TCL_ERROR;
00230 }
00231
00232 if( Tcl_GetInt (interp, argv[3], &yval) != TCL_OK ) {
00233 return TCL_ERROR;
00234 }
00235
00236
00237 if (!CHECKIMG(theimg)) {
00238 Tcl_AppendResult(interp, "couldn't identify SADIE image from input string.", NULL);
00239 return TCL_ERROR;
00240 }
00241
00242 if (theimg->nbnd == 3) {
00243 rval = (double) theimg->data[0][yval][xval];
00244 gval = (double) theimg->data[1][yval][xval];
00245 bval = (double) theimg->data[2][yval][xval];
00246 }
00247 else {
00248 rval = (double) theimg->data[0][yval][xval];
00249 gval = rval;
00250 bval = rval;
00251 }
00252
00253 sprintf(msg, "%.4e %.4e %.4e", rval, gval, bval );
00254 Tcl_SetResult(interp, msg, TCL_VOLATILE);
00255
00256
00257 return TCL_OK;
00258 }
00259
00260 int Sadie_General_SetNameCmd(ClientData client_data, Tcl_Interp* interp, int argc, char *argv[])
00261 {
00262 int imgaddr;
00263 IMAGE *theimg;
00264 char msg[SLEN];
00265
00266 if( argc <= 2 ) {
00267 sprintf(msg, "Usage: Sadie_General_SetName image_address name");
00268 Tcl_SetResult(interp, msg, TCL_VOLATILE);
00269 return TCL_ERROR;
00270 }
00271
00272 sscanf(argv[1], "%x", &imgaddr);
00273 theimg = (IMAGE *) imgaddr;
00274
00275 if (!CHECKIMG(theimg)) {
00276 Tcl_AppendResult(interp, "couldn't identify SADIE image from input string.", NULL);
00277 return TCL_ERROR;
00278 } else {
00279 sprintf(theimg->text, "%s", argv[2]);
00280 }
00281
00282 return TCL_OK;
00283 }
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293 int Sadie_General_Init(Tcl_Interp *interp) {
00294 Tcl_CreateCommand(interp, "Sadie_General_Close", Sadie_General_CloseCmd,
00295 (ClientData) NULL, NULL);
00296 Tcl_CreateCommand(interp, "Sadie_General_InitializeProg", Sadie_General_InitializeProgCmd,
00297 (ClientData) NULL, NULL);
00298 Tcl_CreateCommand(interp, "Sadie_General_FinishProg", Sadie_General_FinishProgCmd,
00299 (ClientData) NULL, NULL);
00300 Tcl_CreateCommand(interp, "Sadie_General_Width", Sadie_General_WidthCmd,
00301 (ClientData) NULL, NULL);
00302 Tcl_CreateCommand(interp, "Sadie_General_Height", Sadie_General_HeightCmd,
00303 (ClientData) NULL, NULL);
00304 Tcl_CreateCommand(interp, "Sadie_General_Gmin", Sadie_General_GminCmd,
00305 (ClientData) NULL, NULL);
00306 Tcl_CreateCommand(interp, "Sadie_General_Gmax", Sadie_General_GmaxCmd,
00307 (ClientData) NULL, NULL);
00308 Tcl_CreateCommand(interp, "Sadie_General_GetNumBands", Sadie_General_GetNumBandsCmd,
00309 (ClientData) NULL, NULL);
00310 Tcl_CreateCommand(interp, "Sadie_General_GetPixel", Sadie_General_GetPixelCmd,
00311 (ClientData) NULL, NULL);
00312 Tcl_CreateCommand(interp, "Sadie_General_SetName", Sadie_General_SetNameCmd,
00313 (ClientData) NULL, NULL);
00314
00315 return TCL_OK;
00316 }
00317