Main Page   Data Structures   File List   Data Fields   Globals  

control.c

Go to the documentation of this file.
00001 #include        <stdio.h>
00002 #include            <malloc.h>
00003 #include            <tcl.h>
00004 #include        "sadie.h"
00005 
00006 /*
00007 ##########################################
00008 # control.c -
00009 #   File from the SADIE library.  Updated for use on UNIX and
00010 #   in tclSadie.
00011 #
00012 # RCS: $Id: control.c,v 2.4 2000/08/08 22:54:32 giri Exp $ 
00013 # 
00014 # Digital Image Analysis Lab
00015 # Dept. of Electrical and Computer Engineering
00016 # University of Arizona
00017 ##########################################
00018 */
00019 
00020 
00021 /* RCS Indentification information */
00022 static char rcsid[] = "$Id: control.c,v 2.4 2000/08/08 22:54:32 giri Exp $";
00023 
00024 
00025 
00026 
00027 /* Added 4/2/97 by S.Conner */
00028 extern char *msg_ptr;
00029 extern Tcl_Interp* MainTclInterp;
00030 
00031 
00032 char *functions[T_END][2]  =  { { "",           ""              },
00033                                 { "BILTOBSQ",   "biltobsq.c"    },
00034                                 { "BSQTOBIL",   "bsqtobil.c"    },
00035                                 { "CHECKER",    "checker.c"     },
00036                                 { "CHECKIMG",   "control.c"     },
00037                                 { "CHIRP",      "chirp.c"       },
00038                                 { "CLUSTER",    "cluster.c"     },
00039                                 { "COM2REAL",   "com2real.c"    },
00040                                 { "COMBINE",    "combine.c"     },
00041                                 { "COMPARE",    "compare.c"     },
00042                                 { "CONTNORM",   "contnorm.c"    },
00043                                 { "CONTOUR",    "contour.c"     },
00044                                 { "COVAR",      "covar.c"       },
00045                                 { "CSPLINE",    "geomwarp.c"    },
00046                                 { "DECORSTR",   "decorstr.c"    },
00047                                 { "DESTRIPE",   "destripe.c"    },
00048                                 { "DISK2IMG",   "disk2img.c"    },
00049                                 { "DSPL2IMG",   "dspl2img.c"    },
00050                                 { "DUPL",       "dupl.c"        },
00051                                 { "EDGE",       "edge.c"        },
00052                                 { "EIGEN",      "eigen.c"       },
00053                                 { "EXPAND",     "expand.c"      },
00054                                 { "FCONVL",     "fconvl.c"      },
00055                                 { "FFT1D",      "fft2d.c"       },
00056                                 { "FFT2D",      "fft2d.c"       },
00057                                 { "FHT1D",      "fht2d.c"       },
00058                                 { "FHT2D",      "fht2d.c"       },
00059                                 { "FILTER",     "filter.c"      },
00060                                 { "FINI",       "control.c"     },
00061                                 { "FLTBOX",     "filter.c"      },
00062                                 { "FLTCONE",    "filter.c"      },
00063                                 { "FLTCYL",     "filter.c"      },
00064                                 { "FLTEXP",     "filter.c"      },
00065                                 { "FLTGAUSS",   "filter.c"      },
00066                                 { "FUNCTION",   "function.c"    },
00067                                 { "GEOMCOEF",   "geomcoef.c"    },
00068                                 { "GEOMWARP",   "geomwarp.c"    },
00069                                 { "GETMEM",     "control.c"     },
00070                                 { "GRADIENT",   "gradient.c"    },
00071                                 { "GRAYSCAL",   "grayscal.c"    },
00072                                 { "GRID",       "grid.c"        },
00073                                 { "HELP",       "control.c"     },
00074                                 { "HISTEQ",     "histeq.c"      },
00075                                 { "HISTOGRM",   "histogrm.c"    },
00076                                 { "HMOSAIC",    "hmosaic.c"     },
00077                                 { "HSVTORGB",   "hsvtorgb.c"    },
00078                                 { "IMG2DISK",   "img2disk.c"    },
00079                                 { "IMG2DSPL",   "img2dspl.c"    },
00080                                 { "IMG2EPSF",   "img2epsf.c"    },
00081                                 { "IMG2PICT",   "img2pict.c"    },
00082                                 { "IMG2TAPE",   "img2tape.c"    },
00083                                 { "IMG2TEXT",   "img2text.c"    },
00084                                 { "IMG2TIFF",   "img2tiff.c"    },
00085                                 { "IMG2VECT",   "img2vect.c"    },
00086                                 { "INFO",       "info.c"        },
00087                                 { "INIT",       "control.c"     },
00088                                 { "INSERT",     "insert.c"      },
00089                                 { "MATRIX_INVERT","matrix_invert.c"},
00090                                 { "LABEL",      "label.c"       },
00091                                 { "LVLSLICE",   "lvlslice.c"    },
00092                                 { "MAIN",       ""              },
00093                                 { "MATCH",      "match.c"       },
00094                                 { "MAXLIKE",    "maxlike.c"     },
00095                                 { "MEDIAN",     "median.c"      },
00096                                 { "MESSAGE",    "control.c"     },
00097                                 { "MOSAIC",     "mosaic.c"      },
00098                                 { "MINDIST",    "mindist.c"     },
00099                                 { "PACK",       "control.c"     },
00100                                 { "PCT",        "pct.c"         },
00101                                 { "PICT2IMG",   "pict2img.c"    },
00102                                 { "PIXLDUMP",   "pixldump.c"    },
00103                                 { "PLOT",       "plot.c"        },
00104                                 { "PROGRESS",   "control.c"     },
00105                                 { "PSPECT",     "pspect.c"      },
00106                                 { "PSPECT1D",   "pspect.c"      },
00107                                 { "RANDOM",     "random.c"      },
00108                                 { "RANGE",      "control.c"     },
00109                                 { "REAL2COM",   "real2com.c"    },
00110                                 { "REFINE",     "refine.c"      },
00111                                 { "RELIEF",     "relief.c"      },
00112                                 { "RELIMG",     "control.c"     },
00113                                 { "RELMEM",     "control.c"     },
00114                                 { "RESAMPL",    "resampl.c"     },
00115                                 { "RGBTOHSV",   "rgbtohsv.c"    },
00116                                 { "RMSDIFF",    "rmsdiff.c"     },
00117                                 { "ROISTATS",   "roistats.c"    },
00118                                 { "ROTATE",     "rotate.c"      },
00119                                 { "SCATTER",    "scatter.c"     },
00120                                 { "SCONVL",     "sconvl.c"      },
00121                                 { "SEGMENT",    "segment.c"     },
00122                                 { "SIGMAP",     "sigmap.c"      },
00123                                 { "SINESTAR",   "sinestar.c"    },
00124                                 { "SINEWAVE",   "sinewave.c"    },
00125                                 { "STATS",      "stats.c"       },
00126                                 { "STRETCH",    "stretch.c"     },
00127                                 { "SUBSAMPL",   "subsampl.c"    },
00128                                 { "SWAP",       "control.c"     },
00129                                 { "TAPE2IMG",   "tape2img.c"    },
00130                                 { "TEST",       ""              },
00131                                 { "TFINVERT",   "stretch.c"     },
00132                                 { "TFLINEAR",   "stretch.c"     },
00133                                 { "TFLOG",      "stretch.c"     },
00134                                 { "TFPLT",      "stretch.c"     },
00135                                 { "TFQUANT",    "stretch.c"     },
00136                                 { "TFROOT",     "stretch.c"     },
00137                                 { "TFSAT",      "stretch.c"     },
00138                                 { "TFSCALE",    "stretch.c"     },
00139                                 { "TFSQUARE",   "stretch.c"     },
00140                                 { "TFTABLE",    "stretch.c"     },
00141                                 { "TFTHRESH",   "stretch.c"     },
00142                                 { "TIFF2IMG",   "tiff2img.c"    },
00143                                 { "TIMING",     "control.c"     },
00144                                 { "TRNSFORM",   "trnsform.c"    },
00145                                 { "UNPACK",     "control.c"     },
00146                                 { "VECT2IMG",   "vect2img.c"    },
00147                                 { "VMOSAIC",    "vmosaic.c"     },
00148                                 { "VSTRETCH",   "vstretch.c"    },
00149                                 { "WINDOW",     "window.c"      },
00150                                 { "WTFCAVG",    "window.c"      },
00151                                 { "WTFDIVER",   "window.c"      },
00152                                 { "WTFMAJ",     "window.c"      },
00153                                 { "WTFMAX",     "window.c"      },
00154                                 { "WTFMIN",     "window.c"      },
00155                                 { "WTFVAR",     "window.c"      } };
00156 
00157 
00158 
00159 
00160 typedef struct _list {                  /* Data structure for tracking images */
00161     IMAGE        *image;
00162     struct _list *next;
00163 } list;
00164 
00165 short    ABORT = FALSE;                 /* Added by SBA, 11-02-90 */
00166 
00167 static short  i = 0, w = 0, e = 0;        /* Message counts */
00168 
00169 static short  top = 0;                    /* Number of functions on the stack */
00170 
00171 static short  stack[T_END];               /* Stack of function calls */
00172 
00173 static long calls[T_END];               /* Number of calls per function */
00174 
00175 static long actms[T_END];               /* Accumulated times per function */
00176 
00177 static FILE *sys = NULL;                /* Pointer to system log-file */
00178 
00179 static list *img = NULL;                /* List of allocated images */
00180 
00181 #ifdef WINNT
00182 int rint(double value) {
00183   int result;
00184 
00185   if (value > 0.0) {
00186     result = (int)(value + 0.5);
00187   } else {
00188     result = (int)(value - 0.5);
00189   }
00190 }
00191 #endif
00192 
00193 /*-Copyright Information------------------------------------------------------*/
00194 /* Copyright (c) 1988 by the University of Arizona Digital Image Analysis Lab */
00195 /*----------------------------------------------------------------------------*/
00196 /*-General Information--------------------------------------------------------*/
00197 /*                                                                            */
00198 /*   This function initializes a SADIE program and must be called before      */
00199 /*   any other SADIE function. If desired, global system variables must       */
00200 /*   be set before this function is called.                                   */
00201 /*                                                                            */
00202 /*----------------------------------------------------------------------------*/
00203 /*-Interface Information------------------------------------------------------*/
00204 char *SLOG = NULL;      /*  I   Name of the system log-file.                  */
00205 short  NAMES = ON;       /*  I   Switch, giving amount of log-file output:     */
00206                         /*      ON    -   function names are listed.          */
00207                         /*      OFF   -   function names are suppressed.      */
00208 short  TIMES = OFF;       /*  I   Switch, giving status of timing facility:     */
00209                         /*      ON    -   timing enabled.                     */
00210                         /*      OFF   -   timing disabled.                    */
00211 short  LINES = OFF;       /*  I   Switch, giving status of progress indicator:  */
00212                         /*      ON    -   progress indicator enabled.         */
00213                         /*      OFF   -   progress indicator disabled.        */
00214 void INIT ()
00215 /*----------------------------------------------------------------------------*/
00216 {   char msg[SLEN];
00217 
00218     /* open log-file */
00219     if (SLOG == NULL  ||  (sys=fopen(SLOG,"w+")) == NULL) {
00220         sys = stdout;
00221     }
00222 
00223     TIMING(T_MAIN);
00224     if (TIMES) TIMING(T_INIT);
00225 
00226     if (NAMES) {
00227         MESSAGE('I',"INIT");
00228         MESSAGE('I',"");
00229     }
00230     MESSAGE('I',LOCALE);
00231     MESSAGE('I',SYSTEM);
00232     MESSAGE('I',"");
00233     sprintf(msg," %.*s",strlen(ctime(actms))-1,ctime(actms));
00234     MESSAGE('I',msg);
00235 
00236     the_end:
00237     if (TIMES) TIMING(T_EXIT);
00238 }
00239 
00240 /*-Copyright Information------------------------------------------------------*/
00241 /* Copyright (c) 1988 by the University of Arizona Digital Image Analysis Lab */
00242 /*----------------------------------------------------------------------------*/
00243 /*-General Information--------------------------------------------------------*/
00244 /*                                                                            */
00245 /*   This function terminates a SADIE program.                                */
00246 /*                                                                            */
00247 /*----------------------------------------------------------------------------*/
00248 /*-Interface Information------------------------------------------------------*/
00249 void FINI ()
00250 /*----------------------------------------------------------------------------*/
00251 {   char msg[SLEN];
00252 
00253     if (TIMES) TIMING(T_FINI);
00254     if (NAMES) {
00255         MESSAGE('I',"");
00256         MESSAGE('I',"FINI");
00257     }
00258 
00259     /* release all remaining images */
00260     while (img) RELMEM(img->image);
00261 
00262     /* output termination status */
00263     if (e || w) {
00264         sprintf(msg," SADIE terminated with %d warning(s) and %d error(s).",w,e);
00265     } else {
00266         sprintf(msg," SADIE completed successfully.");
00267     }
00268     MESSAGE('I',"");
00269     MESSAGE('I',msg);
00270 
00271     the_end:
00272     if (TIMES) TIMING(T_EXIT);
00273     TIMING(T_EXIT);
00274 
00275     if (sys != NULL  &&  sys != stdout) {
00276         fclose(sys);
00277     }
00278 }
00279 
00280 /*-Copyright Information------------------------------------------------------*/
00281 /* Copyright (c) 1988 by the University of Arizona Digital Image Analysis Lab */
00282 /*----------------------------------------------------------------------------*/
00283 /*-General Information--------------------------------------------------------*/
00284 /*                                                                            */
00285 /*   This low-level function handles the output for all SADIE functions,      */
00286 /*   with the exception of image display.                                     */
00287 /*                                                                            */
00288 /*----------------------------------------------------------------------------*/
00289 /*-Interface Information------------------------------------------------------*/
00290 void MESSAGE (
00291 char option,    /*  I   Switch, indicating the type of output:                */
00292                 /*      'I'   -   Informational message.                      */
00293                 /*      'W'   -   Warning.                                    */
00294                 /*      'E'   -   Error.                                      */
00295 char *msg      /*  I   Pointer to an array[*] of characters, containing      */
00296                 /*      one line of output (without terminating '\n').        */
00297 /*----------------------------------------------------------------------------*/
00298 ) {
00299 
00300 /* Modified 4/2/97 by S.Conner */
00301 
00302     if (TIMES) TIMING(T_MESSAGE);
00303 
00304     /* update error counts and output message to log-file */
00305     switch (option) {
00306     case 'E':
00307         e += 1;
00308         /* fprintf(sys,"%c:   %s\n",option,msg); */
00309         sprintf(msg_ptr,"tk_dialog .dlg \"Warning\" \"%s\" warning 0 OK",msg);
00310         Tcl_GlobalEval(MainTclInterp, msg_ptr);
00311         
00312         sprintf(msg_ptr,"set SadieVar(message) \"%c:   %s\"",option,msg);
00313         break;
00314     case 'W':
00315         w += 1;
00316         /* fprintf(sys,"%c:   %s\n",option,msg); */
00317         sprintf(msg_ptr,"set SadieVar(message) \"%c:   %s\"",option,msg);
00318         break;
00319     case 'I':
00320         i += 1;
00321         /* fprintf(sys,"%c:   %s\n",option,msg); */
00322         sprintf(msg_ptr,"set SadieVar(message) \"%c:   %s\"",option,msg);
00323         break;
00324     default:
00325         /* fprintf(sys,"%s",msg); */
00326         sprintf(msg_ptr,"set SadieVar(message) \"%s\"",msg);
00327         break;
00328     }
00329 
00330     the_end:
00331 
00332     Tcl_GlobalEval(MainTclInterp, msg_ptr);
00333 
00334     if (TIMES) TIMING(T_EXIT);
00335 }
00336 
00337 /*-Copyright Information------------------------------------------------------*/
00338 /* Copyright (c) 1988 by the University of Arizona Digital Image Analysis Lab */
00339 /*----------------------------------------------------------------------------*/
00340 /*-General Information--------------------------------------------------------*/
00341 /*                                                                            */
00342 /*   This low-level function provides a timing facility for SADIE.            */
00343 /*                                                                            */
00344 /*----------------------------------------------------------------------------*/
00345 /*-Interface Information------------------------------------------------------*/
00346 void TIMING (option)
00347 T_TIME option;     /*  I   Switch, indicating the calling function.              */
00348 /*----------------------------------------------------------------------------*/
00349 {   register short i;
00350     char msg[SLEN];
00351     long cur_time=time(NULL);
00352 
00353     /* update time-keeping */
00354     actms[stack[top]] += cur_time;
00355     stack[option ? calls[option]++,++top : top--] = option;
00356     actms[stack[top]] -= cur_time;
00357 
00358     /* output statistics */
00359     if (top == 0  &&  TIMES == ON) {
00360         TIMES = OFF;
00361         if (NAMES) {
00362             MESSAGE('I',"");
00363             MESSAGE('I',"TIMING");
00364         }
00365         MESSAGE('I',"");
00366         MESSAGE('I'," Function  # of calls      Elapsed time    Time in %");
00367         MESSAGE('I',"");
00368         for (i=1; i<T_END; i++) {
00369             if (calls[i]) {
00370                 sprintf(msg," %-8s%8ld            %02ld:%02ld:%02ld%13.1f",functions[i][0],calls[i],actms[i]/3600L,actms[i]/60L-60L*(actms[i]/3600L),actms[i]%60L,(actms[0] ? -(double)actms[i]/(double)actms[0]*100.0:0.0));
00371                 MESSAGE('I',msg);
00372             }
00373         }
00374     }
00375 }
00376  
00377 /*-Copyright Information------------------------------------------------------*/
00378 /* Copyright (c) 1989 by the University of Arizona Digital Image Analysis Lab */
00379 /*----------------------------------------------------------------------------*/
00380 /*-General Information--------------------------------------------------------*/
00381 /*                                                                            */
00382 /*   This low-level function provides a progress indicator for SADIE.         */
00383 /*                                                                            */
00384 /*----------------------------------------------------------------------------*/
00385 /*-Interface Information------------------------------------------------------*/
00386 short PROGRESS (pct)
00387 double pct;     /*  I   Percentage of work completed (0.0 <= pct <= 1.0).     */
00388 /*----------------------------------------------------------------------------*/
00389 {
00390     if (TIMES) TIMING(T_PROGRESS);
00391 
00392     /* output percentage */
00393     fprintf(stderr,"%3d%%\b\b\b\b",(int)(100.0*pct));
00394     fflush(stderr);
00395 
00396     the_end:
00397     if (TIMES) TIMING(T_EXIT);
00398     return(TRUE);
00399 }
00400  
00401 /*-Copyright Information------------------------------------------------------*/
00402 /* Copyright (c) 1988 by the University of Arizona Digital Image Analysis Lab */
00403 /*----------------------------------------------------------------------------*/
00404 /*-Programmer Information-----------------------------------------------------*/
00405 /*                                                                            */
00406 /*   The number and size of images that may be allocated from a program is    */
00407 /*   system-dependent. However, this code will work on any system without     */
00408 /*   modifications.                                                           */
00409 /*                                                                            */
00410 /*----------------------------------------------------------------------------*/
00411 /*-General Information--------------------------------------------------------*/
00412 /*                                                                            */
00413 /*   This low-level function allocates memory for a new image, and            */
00414 /*   initializes its data structure.                                          */
00415 /*                                                                            */
00416 /*----------------------------------------------------------------------------*/
00417 /*-Interface Information------------------------------------------------------*/
00418 void GETMEM (
00419 short   nbnd,     /*  I   Number of bands.                                      */
00420 short   nlin,     /*  I   Number of lines.                                      */
00421 short   npix,     /*  I   Number of pixels/line.                                */
00422 IMAGE **out    /*  O   Address of a pointer to the image being allocated.    */
00423 /*----------------------------------------------------------------------------*/
00424 ) {   register short i, j;
00425     long total;
00426     BYTE *ptr=NULL;
00427     list *link=NULL;
00428 
00429     if (TIMES) TIMING(T_GETMEM);
00430 
00431     /* allocate space for image data structure, image data and list entry */
00432     total = sizeof(IMAGE) + nbnd*sizeof(PIXEL **) + nbnd*nlin*sizeof(PIXEL *) + nbnd*nlin*npix*sizeof(PIXEL) + sizeof(list);
00433     if (total < 0L) {
00434         MESSAGE('E'," Memory request failed.");
00435         goto the_end;
00436     }
00437     if (!(ptr=(BYTE *)malloc(total*sizeof(BYTE)))) {
00438         MESSAGE('E'," Memory request failed.");
00439         goto the_end;
00440     }
00441 
00442     /* assign (DEFAULT) values */
00443     *out = (IMAGE *)ptr;
00444     (*out)->nbnd = nbnd;
00445     (*out)->nlin = nlin;
00446     (*out)->npix = npix;
00447     (*out)->nbit = SBIT;
00448 /*  (*out)->gmin = undefined;  */
00449 /*  (*out)->gmax = undefined;  */
00450     for (i=0; i<TLEN; (*out)->text[i++]='\0');
00451     (*out)->regions = NULL;
00452     (*out)->data = (PIXEL ***)(ptr + sizeof(IMAGE));
00453 
00454     /* initialize pointers */
00455     for (i=0; i<nbnd; i++) {
00456         (*out)->data[i] = (PIXEL **)(ptr + sizeof(IMAGE) + nbnd*sizeof(PIXEL **) + i*nlin*sizeof(PIXEL *));
00457         for (j=0; j<nlin; j++) {
00458             (*out)->data[i][j] = (PIXEL *)(ptr + sizeof(IMAGE) + nbnd*sizeof(PIXEL **) + nbnd*nlin*sizeof(PIXEL *) + (j*nbnd+i)*npix*sizeof(PIXEL));
00459         }
00460     }
00461 
00462     /* put new entry on the list */
00463     link        = (list *)(ptr + total - sizeof(list));
00464     link->image = *out;
00465     link->next  = img;
00466     img         = link;
00467 
00468     the_end:
00469     if (TIMES) TIMING(T_EXIT);
00470 }
00471 
00472 /*-Copyright Information------------------------------------------------------*/
00473 /* Copyright (c) 1988 by the University of Arizona Digital Image Analysis Lab */
00474 /*----------------------------------------------------------------------------*/
00475 /*-General Information--------------------------------------------------------*/
00476 /*                                                                            */
00477 /*   This function releases an image to free memory space.                    */
00478 /*                                                                            */
00479 /*----------------------------------------------------------------------------*/
00480 /*-Interface Information------------------------------------------------------*/
00481 void RELIMG (out)
00482 IMAGE **out;    /* I/O  Address of the pointer to the image to be released.   */
00483 /*----------------------------------------------------------------------------*/
00484 {
00485     if (TIMES) TIMING(T_RELIMG);
00486     if (NAMES) {
00487         MESSAGE('I',"");
00488         MESSAGE('I',"RELIMG");
00489     }
00490 
00491     /* check input */
00492     if (!CHECKIMG(*out)) {
00493         MESSAGE('E'," RELIMG: Can't identify image.");
00494         goto the_end;
00495     }
00496 
00497     /* release image */
00498     RELMEM(*out);
00499     *out = NULL;
00500 
00501     the_end:
00502     if (TIMES) TIMING(T_EXIT);
00503 }
00504  
00505 /*-Copyright Information------------------------------------------------------*/
00506 /* Copyright (c) 1988 by the University of Arizona Digital Image Analysis Lab */
00507 /*----------------------------------------------------------------------------*/
00508 /*-General Information--------------------------------------------------------*/
00509 /*                                                                            */
00510 /*   This low-level function releases an image and frees its data structure.  */
00511 /*                                                                            */
00512 /*----------------------------------------------------------------------------*/
00513 /*-Interface Information------------------------------------------------------*/
00514 void RELMEM (in)
00515 IMAGE *in;      /*  I   Pointer to the image to be released.                  */
00516 /*----------------------------------------------------------------------------*/
00517 {   register list *ptr;
00518     ROIPtr r;
00519 
00520     if (TIMES) TIMING(T_RELMEM);
00521 
00522     /* take image off the list */
00523     if (img->image == in) {
00524         img = img->next;
00525     } else {
00526         for (ptr=img; ptr->next->image!=in; ptr=ptr->next);
00527         ptr->next = ptr->next->next;
00528     }
00529 
00530     /* free allocated space */
00531     while ((r = in->regions) != NULL) {
00532       in->regions = r->next;
00533       free(r->name);
00534       r->name = NULL;
00535       
00536       free(r->zero);
00537       r->zero = NULL;
00538       
00539       free(r->gmin);
00540       r->gmin = NULL;
00541       
00542       free(r->gmax);
00543       r->gmax = NULL;
00544 
00545       free(r->mean);
00546       r->mean = NULL;
00547       
00548       free(r->dev);
00549       r->dev = NULL;
00550       
00551       free(r->cov);
00552       r->cov = NULL;
00553       
00554       free(r->cor);
00555       r->cor = NULL;
00556       
00557       free(r);
00558       r = NULL;
00559     }
00560     free(in);
00561     in = NULL;
00562     
00563     the_end:
00564     if (TIMES) TIMING(T_EXIT);
00565 }
00566  
00567 /*-Copyright Information------------------------------------------------------*/
00568 /* Copyright (c) 1988 by the University of Arizona Digital Image Analysis Lab */
00569 /*----------------------------------------------------------------------------*/
00570 /*-General Information--------------------------------------------------------*/
00571 /*                                                                            */
00572 /*   This low-level function determines whether or not an IMAGE pointer       */
00573 /*   points to an image that was properly created by SADIE.                   */
00574 /*                                                                            */
00575 /*----------------------------------------------------------------------------*/
00576 /*-Interface Information------------------------------------------------------*/
00577 short CHECKIMG (in)
00578 IMAGE *in;      /*  I   Pointer to the image to be checked.                   */
00579 /*----------------------------------------------------------------------------*/
00580 {   list *ptr;
00581 
00582     if (TIMES) TIMING(T_CHECKIMG);
00583 
00584     /* check to see if image is on the list */
00585     for (ptr=img; ptr!=NULL && ptr->image!=in; ptr=ptr->next);
00586 
00587     the_end:
00588     if (TIMES) TIMING(T_EXIT);
00589     return(ptr!=NULL);
00590 }
00591 
00592 /*-Copyright Information------------------------------------------------------*/
00593 /* Copyright (c) 1988 by the University of Arizona Digital Image Analysis Lab */
00594 /*----------------------------------------------------------------------------*/
00595 /*-General Information--------------------------------------------------------*/
00596 /*                                                                            */
00597 /*   This low-level function finds the maximum and minimum graylevels         */
00598 /*   in an image.                                                             */
00599 /*                                                                            */
00600 /*----------------------------------------------------------------------------*/
00601 /*-Interface Information------------------------------------------------------*/
00602 void RANGE (in)
00603 IMAGE *in;      /*  I   Pointer to the input image.                           */
00604 /*----------------------------------------------------------------------------*/
00605 {   register PIXEL *p1, *p2, *p3, *gmin, *gmax;
00606 
00607     if (TIMES) TIMING(T_RANGE);
00608 
00609     /* find minimum and maximum */
00610     if (((long)in->nbnd*(long)in->nlin*(long)in->npix)%2L == 0) {
00611         p1 = &in->data[0][0][0];
00612         p2 = &in->data[0][0][1];
00613     } else {
00614         p1 = &in->data[0][0][1];
00615         p2 = &in->data[0][0][2];
00616     }
00617     p3 = &(in->data[in->nbnd-1][in->nlin-1][in->npix-1]);
00618     for (gmin=gmax=(&in->data[0][0][0]); p1<p3; p1+=2,p2+=2) {
00619         if (*p1 < *p2) {
00620             if (*p1 < *gmin) gmin = p1;
00621             if (*p2 > *gmax) gmax = p2;
00622         } else {
00623             if (*p2 < *gmin) gmin = p2;
00624             if (*p1 > *gmax) gmax = p1;
00625         }
00626     }
00627     in->gmin = *gmin;
00628     in->gmax = *gmax;
00629 
00630     if (TIMES) TIMING(T_EXIT);
00631 }
00632 
00633 /*-Copyright Information------------------------------------------------------*/
00634 /* Copyright (c) 1995 by the University of Arizona Digital Image Analysis Lab */
00635 /*----------------------------------------------------------------------------*/
00636 /*-General Information--------------------------------------------------------*/
00637 /*                                                                            */
00638 /*   This low-level function swaps the bytes in a 2-byte word.                */
00639 /*                                                                            */
00640 /*----------------------------------------------------------------------------*/
00641 /*-Interface Information------------------------------------------------------*/
00642 short SWAP (
00643 unsigned char *cptr  /*  I  Pointer to the first byte of a 2-byte word.       */
00644 /*----------------------------------------------------------------------------*/
00645 ) { unsigned char cval[2];
00646 
00647     if (TIMES) TIMING(T_SWAP);
00648 
00649     cval[0] = cptr[1];
00650     cval[1] = cptr[0];
00651 
00652     the_end:
00653     if (TIMES) TIMING(T_EXIT);
00654 
00655     return(*(short *)cval);
00656 }
00657  
00658 /*-Copyright Information------------------------------------------------------*/
00659 /* Copyright (c) 1989 by the University of Arizona Digital Image Analysis Lab */
00660 /*----------------------------------------------------------------------------*/
00661 /*-General Information--------------------------------------------------------*/
00662 /*                                                                            */
00663 /*   This low-level function packs an array of pixels from PIXEL              */
00664 /*   representation to "nbit" bits per pixel.                                 */
00665 /*                                                                            */
00666 /*----------------------------------------------------------------------------*/
00667 /*-Interface Information------------------------------------------------------*/
00668 void PACK (
00669 short nbit,     /*  I   Number of bits/pixel.                                 */
00670 long  npix,     /*  I   Number of pixels in the array.                        */
00671 PIXEL *line     /* I/O  Pointer to an array[npix] of pixels.                  */
00672 /*----------------------------------------------------------------------------*/
00673 ) {   register BYTE *pckd=(BYTE *)line;
00674     register long i, j, k, l, m;
00675     unsigned long lpix;
00676 
00677     if (TIMES) TIMING(T_PACK);
00678 
00679     /* pack to nbit bits per pixel, in place */
00680     for (i=0,j=(-1),l=m=SBPB; i<npix; i++) {
00681         for (lpix=(unsigned long)line[i],k=nbit; k>0; m=k,k-=l) {
00682             l = m < l ? l-m : ((pckd[++j]=0),SBPB);
00683             pckd[j] |= lpix  <<  SBPB*sizeof(lpix) - k  >>  SBPB*sizeof(lpix) - l;
00684         }
00685     }
00686 
00687     the_end:
00688     if (TIMES) TIMING(T_EXIT);
00689 }
00690  
00691 /*-Copyright Information------------------------------------------------------*/
00692 /* Copyright (c) 1989 by the University of Arizona Digital Image Analysis Lab */
00693 /*----------------------------------------------------------------------------*/
00694 /*-General Information--------------------------------------------------------*/
00695 /*                                                                            */
00696 /*   This low-level function unpacks an array of pixels from "nbit"           */
00697 /*   bits per pixel to PIXEL representation.                                  */
00698 /*                                                                            */
00699 /*----------------------------------------------------------------------------*/
00700 /*-Interface Information------------------------------------------------------*/
00701 void UNPACK (
00702 short nbit,     /*  I   Number of bits/pixel.                                 */
00703 long  npix,     /*  I   Number of pixels in the array.                        */
00704 PIXEL *line     /* I/O  Pointer to an array[npix] of pixels.                  */
00705 /*----------------------------------------------------------------------------*/
00706 ) {   register BYTE *pckd=(BYTE *)line;
00707     register long i, j, k, l, m;
00708     unsigned long lpix, mask=(unsigned long)~0 >> sizeof(lpix)*SBPB-nbit;
00709 
00710     if (TIMES) TIMING(T_UNPACK);
00711 
00712     /* unpack from nbit bits per pixel, in place */
00713     for (i=npix-1,j=(long)ceil((double)(npix*nbit)/(double)SBPB)-1,l=(npix*nbit)%SBPB?(npix*nbit)%SBPB:SBPB,m=0; i>=0; line[i--]=(PIXEL)(lpix&mask)) {
00714         for (lpix=0,k=nbit; k>0; m=k,k-=l) {
00715             l = m < l ? l-m : (--j,SBPB);
00716             lpix |= (unsigned long)pckd[j] >> SBPB-l << nbit-k;
00717         }
00718     }
00719 
00720     the_end:
00721     if (TIMES) TIMING(T_EXIT);
00722 }
00723 
00724 /*-Copyright Information------------------------------------------------------*/
00725 /* Copyright (c) 1988 by the University of Arizona Digital Image Analysis Lab */
00726 /*----------------------------------------------------------------------------*/
00727 /*-General Information--------------------------------------------------------*/
00728 /*                                                                            */
00729 /*   This low-level function extracts documentation from SADIE source code.   */
00730 /*                                                                            */
00731 /*----------------------------------------------------------------------------*/
00732 /*-Interface Information------------------------------------------------------*/
00733 void HELP (function,options)
00734 T_TIME  function;/*  I   Switch, indicating the desired function.              */
00735 char *options;  /*  I   is any combination of the following (as a string):    */
00736                 /*      'B'     Background Information will be listed.        */
00737                 /*      'C'     Copyright Information will be listed.         */
00738                 /*      'G'     General Information will be listed.           */
00739                 /*      'I'     Interface Information will be listed.         */
00740                 /*      'P'     Programmer Information will be listed.        */
00741 /*----------------------------------------------------------------------------*/
00742 {   register short i, j, k;
00743     char msg[SLEN], fname[SLEN];
00744     long last[SLEN], temp;
00745     FILE *fp;
00746 
00747     if (TIMES) TIMING(T_HELP);
00748 
00749     /* check input */
00750     if (T_EXIT > function  ||  strlen(functions[function][1]) == 0  ||  function > T_END) {
00751         MESSAGE('E'," Can't find documentation.");
00752         goto the_end;
00753     }
00754 
00755     /* open documentation file */
00756     sprintf(fname,"%s%s",DIR,functions[function][1]);
00757     if (!(fp=fopen(fname,"r"))) {
00758         sprintf(msg," Can't open file %s.",fname);
00759         MESSAGE('E',msg);
00760         goto the_end;
00761     }
00762 
00763     /* search file for requested documentation */
00764     for (i=0; i<strlen(options); i++) {
00765         last[i] = -1L;
00766     }
00767     for (i=1; fgets(msg,SLEN,fp); i++) {
00768         if (strncmp(msg,BEGIN,strlen(BEGIN)) == 0) {
00769             for (j=0; j<strlen(options); j++) {
00770                 if (msg[CODE] == options[j]) {
00771                     if (last[j] > -1L) {
00772                         for (k=0; k<strlen(options); k++) {
00773                             last[k] = -1L;
00774                         }
00775                     }
00776                     last[j] = ftell(fp) - (long)strlen(msg);
00777                 }
00778             }
00779         }
00780         for (j=0; j<=strlen(msg)-strlen(functions[function][0]); j++) {
00781             if (strncmp(msg+j,functions[function][0],strlen(functions[function][0])) == 0  &&  msg[j+strlen(functions[function][0])] == ' ') goto sort;
00782         }
00783     }
00784 
00785     sort: /* output */
00786     for (i=0; i<strlen(options); i++) {
00787         for (j=i+1; j<strlen(options); j++) {
00788             if (last[i] > last[j]) {
00789                 temp = last[i];
00790                 last[i] = last[j];
00791                 last[j] = temp;
00792             }
00793         }
00794     }
00795 
00796     /* output documentation */
00797     for (i=0; i<strlen(options); i++) {
00798         if (last[i] > -1L) {
00799             fseek(fp,last[i],0);
00800             fgets(msg,SLEN,fp);
00801             do {
00802                 MESSAGE(' ',msg);
00803                 fgets(msg,SLEN,fp);
00804             } while (strncmp(msg,END,strlen(END)));
00805             MESSAGE(' ',msg);
00806         }
00807     }
00808 
00809     /* close documentation file */
00810     if (fclose(fp)) {
00811         sprintf(msg," Can't close file %s.",fname);
00812         MESSAGE('W',msg);
00813     }
00814 
00815     the_end:
00816     if (TIMES) TIMING(T_EXIT);
00817 }

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