Main Page   Data Structures   File List   Data Fields   Globals  

img2ascii.c

Go to the documentation of this file.
00001 #include "sadie.h"
00002 #include "proto.h"
00003 
00004 /*----------------------------------------------------------------------------*/
00005 /*-General Information--------------------------------------------------------*/
00006 /*                                                                            */
00007 /*   This function prints an image in ascii form to the session log.  The     */
00008 /*   image must consists of DNs in the range from 0-255.  All DNs will be     */
00009 /*   printed in integer form.                                                 */
00010 /*----------------------------------------------------------------------------*/
00011 /*-Interface Information------------------------------------------------------*/
00012 void IMG2ASCII (
00013 IMAGE  *in     /*  I   Pointer to the input image.                           */
00014 /*----------------------------------------------------------------------------*/
00015 ) { register short i, j, k;
00016     char msg[SLEN];
00017     int value;
00018 
00019     /* if (TIMES) TIMING(T_IMG2ASCII); */
00020     if (NAMES) {
00021         MESSAGE('I',"");
00022         MESSAGE('I',"IMG2ASCII");
00023         MESSAGE('I',"");
00024         sprintf(msg," Input image:                       %s",in->text);
00025         MESSAGE('I',msg);
00026         MESSAGE('I'," ...............");
00027     }
00028 
00029     /* check input */
00030     if (!CHECKIMG(in)) {
00031         MESSAGE('E'," Can't identify image.");
00032         goto the_end;
00033     }
00034     
00035     /* Find the min and max values in the image */
00036     RANGE(in);
00037     
00038     /* Verify that the input image is valid */
00039     if (in->nbnd > 1) {
00040         MESSAGE('E'," Input image must be single band!");
00041         goto the_end;
00042     }
00043 //    if (in->npix > 50) {
00044 //        MESSAGE('E'," Input image must be no wider than 50 pixels!");
00045 //        goto the_end;
00046 //    }
00047     if (in->gmin < 0.0  ||  999.0 < in->gmax) {
00048         MESSAGE('E'," Input image must have integer DNs in the range 0-999!");
00049         goto the_end;
00050     }
00051 
00052     /* build ascii image */
00053 
00054     if (in->npix <= 50) {
00055         for (j=0; j<in->nlin; j++) {
00056             for (k=i=0,msg[i++]=' '; k<in->npix; k++,i=strlen(msg)) {
00057                 value = (int) rnd((double)(in->data[0][j][k]));
00058                 sprintf(msg+i,"%4d",value);
00059             }
00060             MESSAGE('I',msg);
00061         }
00062     } else {
00063         for (j=0; j<in->nlin; j++) {
00064             for (k=0; k<in->npix; k++) {
00065                 value = (int) rnd((double)(in->data[0][j][k]));
00066                 printf("%4d",value);
00067             }
00068             printf("\n");
00069         }
00070     }
00071 
00072         
00073     the_end:
00074     /* if (TIMES) TIMING(T_EXIT); */
00075 }

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