Main Page   Data Structures   File List   Data Fields   Globals  

tclSadie.c

Go to the documentation of this file.
00001 /*
00002 ##########################################
00003 # tclSadie.c.in -
00004 #   Template for creating tclSadie.c, the main tclSadie program
00005 #   file.  tclSadie.c calls tcl and tk libraries and sets up
00006 #   commands for calling SADIE functions through tcl.
00007 #
00008 # RCS: $Id: tclSadie.c,v 2.5 1999/09/11 03:36:14 gopalan Exp $ 
00009 #
00010 # Digital Image Analysis Lab
00011 # Dept. of Electrical and Computer Engineering
00012 # University of Arizona
00013 ##########################################
00014 */
00015 
00016 #include <stdio.h>
00017 #include <tcl.h>
00018 #include <tk.h>
00019 #include "sadie.h"
00020 
00021 
00022 /* RCS Indentification information */
00023 static char rcsid[] = "$Id: tclSadie.c,v 2.5 1999/09/11 03:36:14 gopalan Exp $";
00024 
00025 
00026 static int FLAG=0;
00027 static int DIRECTORY=1;
00028 static int CMDFILE=2;
00029 
00030 static int libhomeset=0;
00031 static char libhome[200];
00032 static int nogui=0;
00033 static char cmdfile[200];
00034 static int cmdfileset=0;
00035 static char *ProgName;
00036 
00037 
00038 
00039 /*-------------------------------------------------------------*/
00040 /* Global Sadie variables that must be set from within Tcl/Tk  */
00041 /*-------------------------------------------------------------*/
00042 short   nlev;
00043 short   csize;
00044 double  weight;
00045 double  *count;
00046 PIXEL   gain;
00047 PIXEL   bias;
00048 PIXEL   gmin;
00049 PIXEL   gmax;
00050 PIXEL   thresh;
00051 PIXEL   gbrk[2][4];
00052 PIXEL   *table;
00053 /* -------------------------------------------------------------------------- */
00054 
00055 
00056 
00057 
00058 char* msg_ptr;
00059 Tcl_Interp* MainTclInterp;
00060 
00061 
00062 int Sadie_FileIO_Init(Tcl_Interp *interp);
00063 int Sadie_General_Init(Tcl_Interp *interp);
00064 int Sadie_Plot_Init(Tcl_Interp *interp);
00065 int Sadie_NewFunctions_Init(Tcl_Interp *interp);
00066 int Sadie_Contrast_Init(Tcl_Interp *interp);
00067 int Sadie_Filter_Init(Tcl_Interp *interp);
00068 int Sadie_Geometry_Init(Tcl_Interp *interp);
00069 int Sadie_Multi_Init(Tcl_Interp *interp);
00070 int Sadie_Classify_Init(Tcl_Interp *interp);
00071 int Sadie_Tools_Init(Tcl_Interp *interp);
00072 int Sadie_Image_Init(Tcl_Interp *interp);
00073 
00074 int Sadie_Proto_Init(Tcl_Interp *interp);
00075 
00076 
00077 
00078 /*-Copyright Information------------------------------------------------------*/
00079 /* Copyright (c) 1999 by the University of Arizona Digital Image Analysis Lab */
00080 /*----------------------------------------------------------------------------*/
00081 /*-General Information--------------------------------------------------------*/
00082 /*                                                                            */
00083 /*   This function displays the command line options for use when invoking    */
00084 /*   tclSadie.                                                                */
00085 /*                                                                            */
00086 /*----------------------------------------------------------------------------*/
00087 /*-Interface Information------------------------------------------------------*/
00088 void usage(void) {
00089         fprintf(stderr, "\nUsage: %s [options]\n",ProgName);
00090         fprintf(stderr, "Options:\n");
00091         fprintf(stderr, "\t-d <tclSadie library directory>\n");
00092         fprintf(stderr, "\t-f <command script file>\n");
00093         fprintf(stderr, "\t-nogui\trun tclSadie without a graphical interface\n");
00094         fprintf(stderr, "\t-h\tprint this message\n");
00095         fprintf(stderr, "\n");
00096 }
00097 
00098 /*-Copyright Information------------------------------------------------------*/
00099 /* Copyright (c) 1999 by the University of Arizona Digital Image Analysis Lab */
00100 /*----------------------------------------------------------------------------*/
00101 /*-General Information--------------------------------------------------------*/
00102 /*                                                                            */
00103 /*   This function checks to see if a file exists.                            */
00104 /*                                                                            */
00105 /*----------------------------------------------------------------------------*/
00106 /*-Interface Information------------------------------------------------------*/
00107 int verifyfile (
00108 Tcl_Interp* interp, /*  I  The Tcl/Tk command interpreter.                    */
00109 char* name          /*  I  The name of the file.                              */
00110 ) {
00111     Tcl_Obj *cmds=NULL;
00112     char tempstr[250];
00113     int result;
00114     
00115     sprintf(tempstr,"file exists %s",name);
00116     cmds = Tcl_NewStringObj(tempstr,-1);
00117     Tcl_EvalObj(interp,cmds);
00118     Tcl_GetIntFromObj(interp, Tcl_GetObjResult(interp), &result);
00119     
00120     return result;
00121 }
00122 
00123 /*-Copyright Information------------------------------------------------------*/
00124 /* Copyright (c) 1999 by the University of Arizona Digital Image Analysis Lab */
00125 /*----------------------------------------------------------------------------*/
00126 /*-General Information--------------------------------------------------------*/
00127 /*                                                                            */
00128 /*   This function checks to see if the environment variable TCLSADIE_HOME    */
00129 /*   contains the location of the .tcl files needed by tclSadie.              */
00130 /*                                                                            */
00131 /*----------------------------------------------------------------------------*/
00132 /*-Interface Information------------------------------------------------------*/
00133 int setlibdir_env (Tcl_Interp* interp) {
00134     Tcl_Obj *cmds=NULL;
00135     char *libdir=NULL;
00136     int result;
00137 
00138     /* Verify that the environment variable TCLSADIE_HOME exists */
00139     cmds = Tcl_NewStringObj("global env; info exists env(TCLSADIE_HOME)",-1);
00140     Tcl_EvalObj(interp,cmds);
00141     Tcl_GetIntFromObj(interp, Tcl_GetObjResult(interp), &result);
00142 
00143     /* Read the environment variable TCLSADIE_HOME */
00144     if (result) {
00145         cmds = Tcl_NewStringObj("global env; set env(TCLSADIE_HOME)",-1);
00146         Tcl_EvalObj(interp,cmds);
00147         libdir = Tcl_GetStringFromObj(Tcl_GetObjResult(interp), NULL);
00148         sprintf(libhome,"%s",libdir);
00149     }
00150     
00151     return result;
00152 }
00153 
00154 /*-Copyright Information------------------------------------------------------*/
00155 /* Copyright (c) 1999 by the University of Arizona Digital Image Analysis Lab */
00156 /*----------------------------------------------------------------------------*/
00157 /*-General Information--------------------------------------------------------*/
00158 /*                                                                            */
00159 /*   This function computes the default location of the .tcl files needed by  */
00160 /*   tclSadie, based on the location of the executable.                       */
00161 /*                                                                            */
00162 /*----------------------------------------------------------------------------*/
00163 /*-Interface Information------------------------------------------------------*/
00164 int setlibdir_default (Tcl_Interp* interp) {
00165     Tcl_Obj *cmds=NULL;
00166     char *libdirroot=NULL;
00167     int result;
00168     
00169     /* Read the environment variable TCLSADIE_HOME */
00170     cmds = Tcl_NewStringObj("file dirname [info nameofexecutable]",-1);
00171     Tcl_EvalObj(interp,cmds);
00172     libdirroot = Tcl_GetStringFromObj(Tcl_GetObjResult(interp), NULL);
00173     sprintf(libhome,"%s/../lib/tclSadie",libdirroot);
00174     
00175     return 1;
00176 }
00177 
00178 
00179 /*-Copyright Information------------------------------------------------------*/
00180 /* Copyright (c) 1999 by the University of Arizona Digital Image Analysis Lab */
00181 /*----------------------------------------------------------------------------*/
00182 /*-General Information--------------------------------------------------------*/
00183 /*                                                                            */
00184 /*   This function determines the location of the .tcl library files needed   */
00185 /*   by tclSadie.                                                             */
00186 /*                                                                            */
00187 /*----------------------------------------------------------------------------*/
00188 /*-Interface Information------------------------------------------------------*/
00189 void setlibdir (Tcl_Interp* interp) {
00190     char testfile[250];
00191     Tcl_Obj *cmds=NULL;
00192 
00193     /*
00194      * First check if the library directory was supplied
00195      * on the command line.
00196      */
00197     if (!libhomeset) {
00198         /* Check if the environment variable TCLSADIE_HOME exists */
00199         if (!setlibdir_env(interp)) {
00200             /* Finally, as a last resort, try a default location */
00201             setlibdir_default(interp);
00202         }
00203     }
00204 
00205     /* Verify that tclSadie_main.tcl can be found in the library directory */
00206     sprintf(testfile,"%s/tclSadie_main.tcl",libhome);
00207     if (verifyfile(interp,testfile)) {
00208         Tcl_SetVar2(interp, "SadieVar", "libdir", libhome, TCL_GLOBAL_ONLY);
00209         cmds = Tcl_NewStringObj("global SadieVar auto_path; lappend auto_path $SadieVar(libdir)",-1);
00210         Tcl_EvalObj(interp,cmds);
00211     } else {
00212         fprintf(stderr, "\nERROR: tclSadie library directory: %s is not valid!\n",libhome);
00213         fprintf(stderr, "       \tYou can indicate the location of the library by using the\n");
00214         fprintf(stderr, "       \tenvironment variable TCLSADIE_HOME or the command line option -d.\n");
00215         usage();
00216         exit(0);
00217     }
00218 }
00219 
00220 /*-Copyright Information------------------------------------------------------*/
00221 /* Copyright (c) 1999 by the University of Arizona Digital Image Analysis Lab */
00222 /*----------------------------------------------------------------------------*/
00223 /*-General Information--------------------------------------------------------*/
00224 /*                                                                            */
00225 /*   This function initializes the Tcl/Tk command interpreter used by         */
00226 /*   tclSadie.                                                                */
00227 /*                                                                            */
00228 /*----------------------------------------------------------------------------*/
00229 /*-Interface Information------------------------------------------------------*/
00230 int Tcl_AppInit (
00231 Tcl_Interp *interp /*  I   Pointer to the command interpreter.                */
00232 ) {
00233   int status;
00234   Tcl_Obj *cmds=NULL;
00235   
00236   msg_ptr = (char *) Tcl_Alloc(1024);
00237   
00238   
00239   MainTclInterp = interp;
00240 
00241   status = Tcl_Init(interp);
00242   
00243   if (status != TCL_OK) {
00244     return TCL_ERROR;
00245   }
00246   
00247   /* Initialize Tk values. */
00248   status = Tk_Init(interp);
00249   
00250   if (status != TCL_OK) {
00251     return TCL_ERROR;
00252   }
00253   
00254 
00255   /*
00256    * Call the init procedures for included packages.  Each call should
00257    * look like this:
00258    *
00259    * if (Mod_Init(interp) == TCL_ERROR) {
00260    *     return TCL_ERROR;
00261    * }
00262    *
00263    * where "Mod" is the name of the module.
00264    */
00265 
00266 
00267   if (Sadie_FileIO_Init(interp) == TCL_ERROR) {
00268       return TCL_ERROR;
00269   }
00270   if (Sadie_General_Init(interp) == TCL_ERROR) {
00271       return TCL_ERROR;
00272   }
00273   if (Sadie_Plot_Init(interp) == TCL_ERROR) {
00274       return TCL_ERROR;
00275   }
00276   if (Sadie_NewFunctions_Init(interp) == TCL_ERROR) {
00277       return TCL_ERROR;
00278   }
00279   if (Sadie_Contrast_Init(interp) == TCL_ERROR) {
00280       return TCL_ERROR;
00281   }
00282   if (Sadie_Filter_Init(interp) == TCL_ERROR) {
00283       return TCL_ERROR;
00284   }
00285   if (Sadie_Geometry_Init(interp) == TCL_ERROR) {
00286       return TCL_ERROR;
00287   }
00288   if (Sadie_Multi_Init(interp) == TCL_ERROR) {
00289       return TCL_ERROR;
00290   }
00291   if (Sadie_Classify_Init(interp) == TCL_ERROR) {
00292       return TCL_ERROR;
00293   }
00294   if (Sadie_Tools_Init(interp) == TCL_ERROR) {
00295       return TCL_ERROR;
00296   }
00297   if (Sadie_Image_Init(interp) == TCL_ERROR) {
00298     return TCL_ERROR;
00299   }
00300 
00301   /* Find the location of the library files */
00302   setlibdir(interp);
00303   printf("Initializing tclSadie with TCLSADIE_HOME=%s\n",libhome);
00304 
00305   
00306 
00307 
00308   /* Initialize the sadie program */
00309   if (Tcl_Eval(interp, "tclSadie_main_init") == TCL_ERROR) {
00310     return TCL_ERROR;
00311   }
00312   Tk_MainLoop();
00313 
00314   return TCL_OK;
00315 }
00316 
00317 
00318 
00319 
00320 /*-Copyright Information------------------------------------------------------*/
00321 /* Copyright (c) 1999 by the University of Arizona Digital Image Analysis Lab */
00322 /*----------------------------------------------------------------------------*/
00323 /*-General Information--------------------------------------------------------*/
00324 /*                                                                            */
00325 /*   This function parses command line arguements and spawns the Tcl/Tk       */
00326 /*   command interpreter used by tclSadie.                                    */
00327 /*                                                                            */
00328 /*----------------------------------------------------------------------------*/
00329 /*-Interface Information------------------------------------------------------*/
00330 int main(int argc, char** argv)
00331 {
00332     int i;
00333     int state=FLAG;
00334     
00335     /* Parse Command Line */
00336     
00337     ProgName = argv[0];
00338     
00339     for (i=1; i<argc; i++) {
00340         char *arg = argv[i];
00341 
00342         if (state==FLAG  &&  *arg=='-') {
00343             switch (arg[1]) {
00344             case 'n' :
00345                 /* Do not use a gui interface */
00346                 nogui=1;
00347                 break;
00348             case 'd' :
00349                 /* The next arg should be a directory */
00350                 state = DIRECTORY;
00351                 break;
00352             case 'f' :
00353                 /* The next arg should be a file */
00354                 state = CMDFILE;
00355                 break;
00356             default:
00357                 usage();
00358                 exit(0);
00359                 break;
00360             }
00361         } else if (state == DIRECTORY  && *arg!='-') {
00362             sprintf(libhome,"%s",arg);
00363             libhomeset = 1;
00364             state = FLAG;
00365         } else if (state == CMDFILE  &&  *arg!='-') {
00366             sprintf(cmdfile,"%s",arg);
00367             cmdfileset = 1;
00368             state = FLAG;
00369         } else {
00370             usage();
00371             exit(0);
00372         }
00373     }
00374     
00375     
00376     if (nogui && !cmdfileset) {
00377         fprintf(stderr, "\nERROR: Attempting to run tclSadie with no gui without a command file!\n");
00378         usage();
00379         exit(0);
00380     } else if (state != FLAG) {
00381         fprintf(stderr, "\nERROR: Expecting parameter after: %s\n",argv[i-1]);
00382         usage();
00383         exit(0);        
00384     }   
00385     
00386     
00387     /* Start TK interpreter without passing in command line options */
00388     Tk_Main(1, argv, Tcl_AppInit);
00389 
00390     return 0;
00391 }
00392 
00393 
00394 

Generated on Wed Apr 9 08:56:15 2003 for TREES by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002