Main Page   Data Structures   File List   Data Fields   Globals  

img2text.c

Go to the documentation of this file.
00001 #include        <stdio.h>
00002 #include        "sadie.h"
00003 
00004 /*-Copyright Information------------------------------------------------------*/
00005 /* Copyright (c) 1988 by the University of Arizona Digital Image Analysis Lab */
00006 /*----------------------------------------------------------------------------*/
00007 /*-General Information--------------------------------------------------------*/
00008 /*                                                                            */
00009 /*   This function writes the SADIE pixel values from main memory to disk     */
00010 /*   as text.                                                                 */
00011 /*                                                                            */
00012 /*----------------------------------------------------------------------------*/
00013 /*-Interface Information------------------------------------------------------*/
00014 void IMG2TEXT (
00015 IMAGE  *in,     /*  I   Pointer to the image.                                 */
00016 char   *name    /*  I   String, containing the name of the disk file.         */
00017 /*----------------------------------------------------------------------------*/
00018 ) {
00019     register int i, j, k;
00020     char msg[SLEN];
00021     FILE *fp=NULL;
00022 
00023     if (TIMES) TIMING(T_IMG2TEXT);
00024 
00025     /* check input */
00026 
00027     if (!CHECKIMG(in)) {
00028         MESSAGE('E'," Can't identify image.");
00029         goto the_end;
00030     }
00031 
00032     if (NAMES) {
00033         MESSAGE('I',"");
00034         MESSAGE('I',"IMG2TEXT");
00035         MESSAGE('I',"");
00036         sprintf(msg," Input image:               %s",in->text);
00037         MESSAGE('I',msg);
00038         sprintf(msg," Output disk file:          %s",name);
00039         MESSAGE('I',msg);
00040         sprintf(msg," Output format:             ASCII Text");
00041         MESSAGE('I',msg);
00042         MESSAGE('I'," ...............");
00043     }
00044 
00045     /* open image file */
00046     if (!(fp = fopen(name,"w"))) {
00047         sprintf(msg," Can't open file %s.",name);
00048         MESSAGE('E',msg);
00049         goto the_end;
00050     }
00051 
00052     for(i = 0; i < in->nbnd; i++)
00053         for(j = 0; j < in->nlin; j++) {
00054             for(k = 0; k < in->npix; k++)
00055                 fprintf(fp, "%.4f ", in->data[i][j][k]);
00056             fprintf(fp, "\n");
00057         }
00058 
00059 
00060     /* close image file */
00061     the_end:
00062 
00063     if (fp) {
00064         if (fclose(fp)) {
00065             sprintf(msg," Can't close file %s.",name);
00066             MESSAGE('W',msg);
00067         }
00068     }
00069 
00070     if (TIMES) TIMING(T_EXIT);
00071 }

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