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
/
vgmclose
/
vgmclose.c
< prev
next >
Wrap
C/C++ Source or Header
|
1992-07-26
|
8KB
|
340 lines
/*
* Khoros: $Id$
*/
#if !defined(lint) && !defined(SABER)
static char rcsid[] = "Khoros: $Id$";
#endif
/*
* $Log$
*/
/*
*----------------------------------------------------------------------
*
* Copyright 1992, University of New Mexico. All rights reserved.
* Permission to copy and modify this software and its documen-
* tation only for internal use in your organization is hereby
* granted, provided that this notice is retained thereon and
* on all copies. UNM makes no representations as to the sui-
* tability and operability of this software for any purpose.
* It is provided "as is" without express or implied warranty.
*
* UNM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FIT-
* NESS. IN NO EVENT SHALL UNM BE LIABLE FOR ANY SPECIAL,
* INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY OTHER DAMAGES WHAT-
* SOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
* ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PER-
* FORMANCE OF THIS SOFTWARE.
*
* No other rights, including, for example, the right to redis-
* tribute this software and its documentation or the right to
* prepare derivative works, are granted unless specifically
* provided in a separate license agreement.
*---------------------------------------------------------------------
*/
#include "unmcopyright.h" /* Copyright 1992 by UNM */
/*>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
>>>>
>>>> File Name: vgmclose.c
>>>>
>>>> Program Name: vgmclose
>>>>
>>>> Program Desc:
>>>>
>>>> Close a greyscale image X, by a structuring element B.
>>>>
>>>>
>>>> Author: Pascal ADAM and Greg DONOHOE
>>>>
>>>> Date Last Updated: Thu Jul 23 16:18:15 1992
>>>>
>>>> Routines: main- the main program for vgmclose
>>>> gw_usage - gives usage of the program
>>>> gw_args - gets arguments of program from command line
>>>>
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
#include "vgmclose.h"
/****************************************************************
*
* Routine Name: main program for vgmclose
*
* Input:
* -i input image
* -k input kernel
* -o output image
*
*
*
*
*
****************************************************************/
main(argc, argv)
int argc;
char *argv[];
{
/* -main_variable_list */
struct xvimage *image, *kernel,*readimage();
/* -main_variable_list_end */
program = VStrcpy(argv[0]);
ac = argc;
av = argv;
khoros_init();
gw_get_args();
/* -main_before_lib_call */
if (check_args()) exit(1);
READINPUT (image, kernel);
CHECKINPUT (program, image, kernel);
/* -main_before_lib_call_end */
/* -main_library_call */
if(! lvgmclose(image,kernel))
{
(void) fprintf(stderr, "vgmclose: lvgmclose Failed\n");
exit(1);
}
/* -main_library_call_end */
/* -main_after_lib_call */
writeimage(vgmclose->o_file,image);
/* -main_after_lib_call_end */
khoros_close();
}
/****************************************************************
*
* Routine Name: gw_usage
*
*
* Purpose: prints out the usage for vgmclose
*
* Input: none
*
* Output: none
*
* Written By: automatically generated by ghostwriter
*
****************************************************************/
gw_usage()
{
fprintf(stderr, "vgmclose :\n");
fprintf(stderr, "\t\n");
fprintf(stderr, "\tClose a greyscale image X, by a structuring element B.\n");
fprintf(stderr, "\t\n");
fprintf(stderr, "\t\n");
/* -usage_additions */
/* -usage_additions_end */
fprintf(stderr,"\t-i input image (infile)\n");
fprintf(stderr,"\t-k input kernel (infile)\n");
fprintf(stderr,"\t-o output image (outfile)\n");
fprintf(stderr, "\n");
fprintf(stderr, "\n");
fprintf(stderr, " \n");
fprintf(stderr, "\n");
fprintf(stderr, "\t[-V] Gives the version for vgmclose\n");
fprintf(stderr, "\t[-U] Gives the usage for vgmclose\n");
fprintf(stderr, "\t[-P] Prompts for command line options\n");
fprintf(stderr, "\t[-A [file1]] Creates the answer file called vgmclose.ans or file1 \n");
fprintf(stderr, "\t[-a [file1]] Uses vgmclose.ans or file1 as the answer file \n\n\n");
}
/****************************************************************
*
* Routine Name: gw_getargs
*
*
* Purpose: gets arguments off command line for vgmclose
*
* Input: none
*
* Output: none
*
* Written By: automatically generated by ghostwriter
*
****************************************************************/
gw_get_args()
{
char *i_pstr =
"\nEnter: (i) input image \n {infile}: ";
char *k_pstr =
"\nEnter: (k) input kernel \n {infile}: ";
char *o_pstr =
"\nEnter: (o) output image \n {outfile}: ";
char answer_file[512], temp[512];
int fid = -1,
error, query, ok, count;
int prompt_flag = FALSE;
/*
* print version if necessary
*/
vgparml(fid, "-V", "noprompt", &query, 0, 0, &error);
if (error == 0)
{
printf ("\n%s: %s: Version %d.%d\n\n",
"vgmclose", RELEASE_NAME, RELEASE_MAJOR, RELEASE_MINOR);
exit(1);
}
/*
* print usage if necessary
*/
vgparml(fid, "-U", "noprompt", &query, 0, 0, &error);
if (error == 0)
{
gw_usage();
exit(1);
}
/*
* see if interactive prompting is desired
*/
vgparml(fid, "-P", "noprompt", &query, 0, 0, &error);
if (error == 0)
prompt_flag = TRUE;
/*
* see if answer file is to be used
*/
vgparms(fid, "-a", "noprompt", answer_file, 0, 0, &error);
if (error == 0)
{
if (VStrlen(answer_file) == 0)
sprintf(answer_file, "vgmclose.ans");
while (fid < 0)
{
if ((fid = open(answer_file, O_RDONLY, 0666))== -1)
{
fprintf(stderr, "vgmclose: can't open answer file \"%s\"",
answer_file);
fprintf(stderr, "please re-enter: ");
(void) gets(answer_file);
if (VStrlen(answer_file) == 0)
sprintf(answer_file, "vgmclose.ans");
}
}
}
/*
* allocate the vgmclose structure
*/
vgmclose = (vgmclose_struct *)
calloc((unsigned)1, (unsigned) sizeof (vgmclose_struct));
/*
* get required arguments for vgmclose
*/
if (prompt_flag == TRUE)
fprintf(stderr,"\nRequired Arguments:\n\n");
if (!(vgmclose->i_flag = vget_infile(fid, prompt_flag,
"-i", i_pstr, &(vgmclose->i_file))
))
{
if (prompt_flag == TRUE)
{
while(!(vgmclose->i_flag))
{
fprintf(stderr, "\t\ti is required, please re-enter: \n");
vgmclose->i_flag = vget_infile(fid, prompt_flag,
"-i", i_pstr, &(vgmclose->i_file))
;
}
}
else
{
fprintf(stderr, "Error: '-i' is a required argument\n");
gw_usage();
exit(1);
}
}
if (!(vgmclose->k_flag = vget_infile(fid, prompt_flag,
"-k", k_pstr, &(vgmclose->k_file))
))
{
if (prompt_flag == TRUE)
{
while(!(vgmclose->k_flag))
{
fprintf(stderr, "\t\tk is required, please re-enter: \n");
vgmclose->k_flag = vget_infile(fid, prompt_flag,
"-k", k_pstr, &(vgmclose->k_file))
;
}
}
else
{
fprintf(stderr, "Error: '-k' is a required argument\n");
gw_usage();
exit(1);
}
}
if (!(vgmclose->o_flag = vget_outfile(fid, prompt_flag,
"-o", o_pstr, &(vgmclose->o_file))
))
{
if (prompt_flag == TRUE)
{
while(!(vgmclose->o_flag))
{
fprintf(stderr, "\t\to is required, please re-enter: \n");
vgmclose->o_flag = vget_outfile(fid, prompt_flag,
"-o", o_pstr, &(vgmclose->o_file))
;
}
}
else
{
fprintf(stderr, "Error: '-o' is a required argument\n");
gw_usage();
exit(1);
}
}
}