home *** CD-ROM | disk | FTP | other *** search
/ vis-ftp.cs.umass.edu / vis-ftp.cs.umass.edu.tar / vis-ftp.cs.umass.edu / pub / Software / universal_plane_file_format / format_plane.c < prev    next >
C/C++ Source or Header  |  1990-11-05  |  4KB  |  103 lines

  1. /* -*-c-mode-*- */
  2. /*------------------------------------------------------
  3.  *  FORMAT_PLANE.C - program that reads in a LLVS plane and formats (to 
  4.  *             stdout) a section of it.
  5.  *  Robert Heller Created on Mon Jul 10 11:16:09 1989
  6.  *  Last mod - 
  7.  *--------------------------------------------------------
  8.  *  Contents:
  9.  *--------------------------------------------------------
  10.  * (c) Copyright 1989 by The University of Massachusetts
  11.  *------------------------------------------------------*/
  12.  
  13. #include <stdio.h>
  14.  
  15. #include <llvs_per_plane.h>
  16.  
  17. main(argc,argv)
  18. int argc;
  19. char *argv[];
  20. {
  21.     LIMITS pl_lims;
  22.     PLANE *inpl;
  23.     PLANE_INFO *inpl_info;
  24.     char *assoc;
  25.     char *format;
  26.     char *infile;
  27.     register int iargc;
  28.     static char *default_formats[] = {"%01d", " %3d", " %5d", " %10d", " %10.3f"};
  29.     register int irow, icol, currow, curcol;
  30.     register float fpixel;
  31.     register int   ipixel;
  32.  
  33.     infile = NULL;
  34.     for (iargc = 1; iargc < argc; iargc++) {
  35.     if (*argv[iargc] != '-') {
  36.         if (infile != NULL) usage();
  37.         infile = argv[iargc];
  38.         }
  39.     }
  40.     if (infile == NULL) usage();
  41.     if (read_plane(&inpl,&inpl_info,&assoc,infile) < 0) {
  42.     perror(argv[0]);
  43.     exit(12);
  44.     }
  45.     pl_lims.level = inpl_info->level;
  46.     pl_lims.deltarow = 1;    
  47.     pl_lims.deltacol = 1;    
  48.     pl_lims.startrow = inpl_info->row_location;
  49.     pl_lims.startcol = inpl_info->column_location;
  50.     pl_lims.endrow   = inpl_info->row_location + inpl_info->row_dimension - 1;
  51.     pl_lims.endcol   = inpl_info->column_location + inpl_info->column_dimension - 1;
  52.     format = default_formats[inpl_info->datatype];
  53.     for (iargc = 1; iargc < argc; iargc++) {
  54.     if (*argv[iargc] != '-') continue;
  55.     if (strncmp(argv[iargc],"-start-row=",11) == 0)
  56.         pl_lims.startrow = atoi(argv[iargc]+11);
  57.     else if (strncmp(argv[iargc],"-start-col=",11) == 0)
  58.         pl_lims.startcol = atoi(argv[iargc]+11);
  59.     else if (strncmp(argv[iargc],"-end-row=",9) == 0)
  60.         pl_lims.endrow = atoi(argv[iargc]+9);
  61.     else if (strncmp(argv[iargc],"-end-col=",9) == 0)
  62.         pl_lims.endcol = atoi(argv[iargc]+9);
  63.     else if (strncmp(argv[iargc],"-format=",8) == 0)
  64.         format = argv[iargc]+8;
  65.     else {
  66.         fprintf(stderr,"format_plane: unknown option: %s\n",argv[iargc]);
  67.         usage();
  68.         }
  69.     }
  70.     printf("Plane file: %s\nAssoc List: %s\nStart (%d,%d), End (%d,%d)\n\n",
  71.        infile,assoc,pl_lims.startrow,pl_lims.startcol,pl_lims.endrow,
  72.        pl_lims.endcol);
  73.     for (currow = pl_lims.startrow; currow <= pl_lims.endrow; currow++) {
  74.     TRANSLEVEL(irow,currow,0,inpl_info->row_location);
  75.     for (curcol = pl_lims.startcol; curcol <= pl_lims.endcol; curcol++) {
  76.         TRANSLEVEL(icol,curcol,0,inpl_info->column_location);
  77.         if (inpl_info->datatype == LLVS_FLOAT) {
  78.         GET_PIXEL(fpixel,inpl_info->background.flonum,inpl,irow,icol,(*inpl_info));
  79.         printf(format,fpixel);
  80.         }
  81.         else {
  82.         GET_PIXEL(ipixel,inpl_info->background.fixnum,inpl,irow,icol,(*inpl_info));
  83.         printf(format,ipixel);
  84.         }
  85.         }
  86.     printf("\n");
  87.     }
  88.     }
  89.  
  90. static usage()
  91. {
  92.     fprintf(stderr,"SYNOPIS: format_plane <opts> plane_file <opts>\n");
  93.     fprintf(stderr,"This program prints out the numerical values in a LLVS plane\n");
  94.     fprintf(stderr,"on the standard output stream.\n\n");
  95.     fprintf(stderr,"Options are:\n");
  96.     fprintf(stderr,"-start-row=n\tRow to start printing\n");
  97.     fprintf(stderr,"-start-col=n\tColumn to start printing\n");
  98.     fprintf(stderr,"-end-row=n\tRow to end printing\n");
  99.     fprintf(stderr,"-end-col=n\tColumn to end printing\n");
  100.     fprintf(stderr,"-format=s\tFormat string to use for each pixel.\n\n");
  101.     exit(12);
  102.     }
  103.