next up previous contents index
Next: 6 Documentation and manual Up: XITE Programmer's Manual Previous: 4 Standardized command line   Contents   Index


5 Example of a main program

A typical main program in XITE, with the ingredients from the above sections Reading and writing BIFF images and Standardized command line user interface, will look something like this (an excerpt from crossSection.c in the XITE source directory arithmetic).

/*P:crossSection*

________________________________________________________________

                crossSection
________________________________________________________________

Name:           crossSection - Find cross sections, row or column of image

Syntax:         crossSection [<option>...] <inimage> <outimage>

Description:    'crossSection' reads a BIFF image and finds a cross-section,
                row or column.

Options:        &-M
                cross-section maximum (default)

                &-n num
                pick row or column number 'num'

                &-t title
                Title of output image

                &-s scale
                Scale curve height relative to image height (default is 1.0,
                which means that the curve peak will touch the top edge of the
                image).

See also:       profile(1), crossSection(3)

Return value:   2 => Illegal arguments.

Author:         Svein Bøe

Id:             crossSection.c,v 1.20 1995/01/17 14:38:52 svein Exp
________________________________________________________________

*/

#include <xite/includes.h>
#include <xite/message.h>
#include <xite/biff.h>
#include <xite/readarg.h>

#ifdef MAIN

#ifndef FUNCPROTO
int main(argc, argv)
int argc;
char **argv;
#else /* FUNCPROTO */
int main(int argc, char **argv)
#endif /* FUNCPROTO */
{
  int maxi, num;
  char *title, *outFile, *options;
  double scale;

  Iset_message(1);
  Iset_abort(1);
  InitMessage(&argc, argv, xite_app_std_usage_text(
    "Usage: %s [<option>...] <inimage> <outimage>\n\
       where <option> is chosen from\n\
         -M          : Cross-section maximum (default) \n\
         -n <num>    : Pick row or column number <no> \n\
         -t <title>  : Title of output image\n\
         -s <scale>  : Scale curve height relative to image height\n"));  

  /* Standard behaviour when no arguments or options. */
  if (argc == 1) Usage(1, NULL);

  /* Save the command line arguments (other than the standard XITE help options). */
  options = argvOptions(argc, argv);

  /* Process options. */
  maxi   = read_bswitch(&argc, argv, "-M");
  num    = read_iswitch(&argc, argv, "-n", -1);
  title  = read_switch(&argc,  argv, "-t", 1, "");
  scale  = read_dswitch(&argc, argv, "-s", 1.0);

  /* Check number of arguments. */
  if (argc != 3) Usage(2, "Illegal number of arguments.\n");

  /* Read input image argument */
  img     = Iread_image(argv[1]);
  outFile = argv[2];

  /* Create IMAGE out_img and process */

  /* Copy text field (image history) from input image to output image. */
  Icopy_text(img, out_img);

  /* Append description of current processing to image history. */
  Ihistory(out_img, argv[0], options);

  /* Write result to file */
  Iwrite_image(out_img, outFile);
  
  return(0);
}

#endif



Svein Bøe 2004-09-30