home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / m / morpho.zip / morpho / src / vgmerode / vgmerode.c < prev    next >
C/C++ Source or Header  |  1992-07-26  |  8KB  |  340 lines

  1.  /*
  2.   * Khoros: $Id$
  3.   */
  4.  
  5. #if !defined(lint) && !defined(SABER)
  6. static char rcsid[] = "Khoros: $Id$";
  7. #endif
  8.  
  9.  /*
  10.   * $Log$
  11.   */
  12.  
  13. /*
  14.  *----------------------------------------------------------------------
  15.  *
  16.  * Copyright 1992, University of New Mexico.  All rights reserved.
  17.  * Permission to copy and modify this software and its documen-
  18.  * tation only for internal use in your organization is hereby
  19.  * granted, provided that this notice is retained thereon and
  20.  * on all copies.  UNM makes no representations as to the sui-
  21.  * tability and operability of this software for any purpose.
  22.  * It is provided "as is" without express or implied warranty.
  23.  * 
  24.  * UNM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  25.  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FIT-
  26.  * NESS.  IN NO EVENT SHALL UNM BE LIABLE FOR ANY SPECIAL,
  27.  * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY OTHER DAMAGES WHAT-
  28.  * SOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
  29.  * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
  30.  * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PER-
  31.  * FORMANCE OF THIS SOFTWARE.
  32.  * 
  33.  * No other rights, including, for example, the right to redis-
  34.  * tribute this software and its documentation or the right to
  35.  * prepare derivative works, are granted unless specifically
  36.  * provided in a separate license agreement.
  37.  *---------------------------------------------------------------------
  38.  */
  39.  
  40. #include "unmcopyright.h"        /* Copyright 1992 by UNM */
  41.  
  42. /*>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>  <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  43.  >>>>
  44.  >>>>         File Name: vgmerode.c
  45.  >>>>
  46.  >>>>      Program Name: vgmerode
  47.  >>>>
  48.  >>>>      Program Desc: 
  49.  >>>>    
  50.  >>>>    Erode a greyscale image X, by a structuring element B.
  51.  >>>>    
  52.  >>>>    
  53.  
  54.  >>>>            Author: Pascal ADAM and Greg DONOHOE
  55.  >>>>
  56.  >>>> Date Last Updated: Thu Jul 23 16:04:57 1992
  57.  >>>>
  58.  >>>>          Routines: main- the main program for vgmerode
  59.  >>>>          gw_usage - gives usage of the program
  60.  >>>>          gw_args  - gets arguments of program from command line
  61.  >>>>
  62.  >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>   <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
  63.  
  64.  
  65. #include "vgmerode.h"
  66.  
  67.  
  68. /****************************************************************
  69.  *
  70.  * Routine Name:  main program for vgmerode
  71.  *
  72.  *       Input:  
  73.  *          -i  input image 
  74.  *          -k  input kernel 
  75.  *          -o  output image 
  76.  *
  77.  *
  78.  *
  79.  *
  80.  *
  81.  ****************************************************************/
  82.  
  83.  
  84. main(argc, argv)
  85. int argc;
  86. char *argv[];
  87. {
  88.  
  89. /* -main_variable_list */
  90.     struct xvimage *image, *kernel,*readimage();
  91. /* -main_variable_list_end */
  92.  
  93.     program = VStrcpy(argv[0]);
  94.     ac = argc;
  95.     av = argv;
  96.  
  97.     khoros_init();
  98.  
  99.     gw_get_args();
  100.  
  101. /* -main_before_lib_call */
  102.     if (check_args()) exit(1);
  103.  
  104.     READINPUT (image, kernel);
  105.     CHECKINPUT (program, image, kernel);
  106.  
  107. /* -main_before_lib_call_end */
  108.  
  109. /* -main_library_call */
  110.     if(! lvgmerode(image,kernel))
  111.     {
  112.         (void) fprintf(stderr, "vgmerode: lvgmerode Failed\n");
  113.         exit(1);
  114.     }
  115. /* -main_library_call_end */
  116.  
  117. /* -main_after_lib_call */
  118.     writeimage(vgmerode->o_file,image);
  119. /* -main_after_lib_call_end */
  120.  
  121.  
  122.     khoros_close();
  123. }
  124.  
  125.  
  126. /****************************************************************
  127. *
  128. * Routine Name:  gw_usage 
  129. *
  130. *
  131. * Purpose:  prints out the usage for vgmerode 
  132. *
  133. * Input:  none 
  134. *
  135. * Output:  none 
  136. *
  137. * Written By:  automatically generated by ghostwriter
  138. *
  139. ****************************************************************/
  140.  
  141.  
  142. gw_usage()
  143. {
  144.     fprintf(stderr, "vgmerode :\n");
  145.     fprintf(stderr, "\t\n");
  146.     fprintf(stderr, "\tErode a greyscale image X, by a structuring element B.\n");
  147.     fprintf(stderr, "\t\n");
  148.     fprintf(stderr, "\t\n");
  149.  
  150. /* -usage_additions */
  151. /* -usage_additions_end */
  152.  
  153.     fprintf(stderr,"\t-i  input image  (infile)\n");
  154.     fprintf(stderr,"\t-k  input kernel  (infile)\n");
  155.     fprintf(stderr,"\t-o  output image  (outfile)\n");
  156.     fprintf(stderr, "\n");
  157.     fprintf(stderr, "\n");
  158.     fprintf(stderr, " \n");
  159.     fprintf(stderr, "\n");
  160.     fprintf(stderr, "\t[-V] Gives the version for vgmerode\n");
  161.     fprintf(stderr, "\t[-U] Gives the usage for vgmerode\n");
  162.     fprintf(stderr, "\t[-P] Prompts for command line options\n");
  163.     fprintf(stderr, "\t[-A [file1]] Creates the answer file called vgmerode.ans or file1 \n");
  164.     fprintf(stderr, "\t[-a [file1]] Uses vgmerode.ans or file1 as the answer file \n\n\n");
  165.  
  166. }
  167.  
  168.  
  169. /****************************************************************
  170. *
  171. * Routine Name:  gw_getargs 
  172. *
  173. *
  174. * Purpose:  gets arguments off command line for vgmerode
  175. *
  176. * Input:  none 
  177. *
  178. * Output:  none 
  179. *
  180. * Written By:  automatically generated by ghostwriter
  181. *
  182. ****************************************************************/
  183.  
  184.  
  185. gw_get_args()
  186. {
  187.  
  188. char    *i_pstr = 
  189.     "\nEnter: (i) input image \n        {infile}: "; 
  190. char    *k_pstr = 
  191.     "\nEnter: (k) input kernel \n        {infile}: "; 
  192. char    *o_pstr = 
  193.     "\nEnter: (o) output image \n        {outfile}: "; 
  194. char  answer_file[512], temp[512];
  195.  
  196.  
  197.  
  198. int    fid = -1,
  199.     error, query, ok, count;
  200.     int prompt_flag = FALSE;
  201.  
  202.     /*
  203.      * print version if necessary
  204.      */
  205.     vgparml(fid, "-V", "noprompt", &query, 0, 0, &error);
  206.     if (error == 0)
  207.     {
  208.         printf ("\n%s: %s: Version %d.%d\n\n",
  209.         "vgmerode", RELEASE_NAME, RELEASE_MAJOR, RELEASE_MINOR);
  210.         exit(1);
  211.     }
  212.  
  213.     /*
  214.      * print usage if necessary
  215.      */
  216.     vgparml(fid, "-U", "noprompt", &query, 0, 0, &error);
  217.     if (error == 0)
  218.     {
  219.         gw_usage();
  220.         exit(1);
  221.     }
  222.  
  223.     /*
  224.      * see if interactive prompting is desired
  225.      */
  226.     vgparml(fid, "-P", "noprompt", &query, 0, 0, &error);
  227.     if (error == 0)
  228.         prompt_flag = TRUE;
  229.  
  230.     /*
  231.      * see if answer file is to be used
  232.      */
  233.     vgparms(fid, "-a", "noprompt", answer_file, 0, 0, &error);
  234.     if (error == 0)
  235.     {
  236.          if (VStrlen(answer_file) == 0)
  237.         sprintf(answer_file, "vgmerode.ans");
  238.          while (fid < 0)
  239.          {
  240.         if ((fid = open(answer_file, O_RDONLY, 0666))== -1)
  241.         {
  242.             fprintf(stderr, "vgmerode: can't open answer file \"%s\"",
  243.                 answer_file); 
  244.             fprintf(stderr, "please re-enter: ");
  245.             (void) gets(answer_file);
  246.             if (VStrlen(answer_file) == 0)
  247.             sprintf(answer_file, "vgmerode.ans");
  248.         }
  249.  
  250.          }
  251.  
  252.     }
  253.  
  254.     /*
  255.      * allocate the vgmerode structure
  256.      */
  257.     vgmerode = (vgmerode_struct *) 
  258.            calloc((unsigned)1, (unsigned) sizeof (vgmerode_struct));
  259.  
  260.     /*
  261.      * get required arguments for vgmerode
  262.      */
  263.     if (prompt_flag == TRUE)
  264.         fprintf(stderr,"\nRequired Arguments:\n\n");
  265.  
  266.     if (!(vgmerode->i_flag = vget_infile(fid, prompt_flag,
  267.             "-i", i_pstr, &(vgmerode->i_file))
  268. ))
  269.     {
  270.         if (prompt_flag == TRUE)
  271.         {
  272.         while(!(vgmerode->i_flag))
  273.         {
  274.             fprintf(stderr, "\t\ti is required, please re-enter: \n");
  275.             vgmerode->i_flag = vget_infile(fid, prompt_flag,
  276.             "-i", i_pstr, &(vgmerode->i_file))
  277. ;
  278.  
  279.         }
  280.         }
  281.         else
  282.         {
  283.         fprintf(stderr, "Error: '-i' is a required argument\n");
  284.         gw_usage();
  285.         exit(1);
  286.         }
  287.     }
  288.  
  289.     if (!(vgmerode->k_flag = vget_infile(fid, prompt_flag,
  290.             "-k", k_pstr, &(vgmerode->k_file))
  291. ))
  292.     {
  293.         if (prompt_flag == TRUE)
  294.         {
  295.         while(!(vgmerode->k_flag))
  296.         {
  297.             fprintf(stderr, "\t\tk is required, please re-enter: \n");
  298.             vgmerode->k_flag = vget_infile(fid, prompt_flag,
  299.             "-k", k_pstr, &(vgmerode->k_file))
  300. ;
  301.  
  302.         }
  303.         }
  304.         else
  305.         {
  306.         fprintf(stderr, "Error: '-k' is a required argument\n");
  307.         gw_usage();
  308.         exit(1);
  309.         }
  310.     }
  311.  
  312.     if (!(vgmerode->o_flag = vget_outfile(fid, prompt_flag,
  313.             "-o", o_pstr, &(vgmerode->o_file))
  314. ))
  315.     {
  316.         if (prompt_flag == TRUE)
  317.         {
  318.         while(!(vgmerode->o_flag))
  319.         {
  320.             fprintf(stderr, "\t\to is required, please re-enter: \n");
  321.             vgmerode->o_flag = vget_outfile(fid, prompt_flag,
  322.             "-o", o_pstr, &(vgmerode->o_file))
  323. ;
  324.  
  325.         }
  326.         }
  327.         else
  328.         {
  329.         fprintf(stderr, "Error: '-o' is a required argument\n");
  330.         gw_usage();
  331.         exit(1);
  332.         }
  333.     }
  334.  
  335.  
  336. }
  337.  
  338.  
  339.  
  340.