Main Page   Data Structures   File List   Data Fields   Globals  

tclSadie_proto.c

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

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