debug.c

Go to the documentation of this file.
00001 #include <stdio.h>
00002 #include <stdlib.h>
00003 #include <string.h>
00004 #include <stdarg.h>
00005 #include <grass/gis.h>
00006 #include "G.h"
00007 #include <grass/glocale.h>
00008 
00009 
00027 static int grass_debug_level = -1;
00028 
00029 int G_debug (int level, char *msg,...)
00030 {
00031 #ifdef GDEBUG
00032     char    *lstr, *filen;
00033     va_list ap;
00034     FILE    *fd;
00035    
00036     if (grass_debug_level < 0) {
00037         lstr = G__getenv( "DEBUG" );
00038 
00039         if ( lstr != NULL )
00040             grass_debug_level = atoi ( lstr );
00041         else
00042             grass_debug_level = 0;
00043     }
00044         
00045     if ( grass_debug_level >= level ) {
00046         va_start(ap, msg);
00047 
00048         filen =  getenv("GRASS_DEBUG_FILE"); 
00049         if ( filen != NULL ) {
00050             fd = fopen (filen,"a");
00051             if ( !fd ) {
00052                 G_warning ( _("Cannot open debug file '%s'"), filen);
00053                 return 0;
00054             }
00055         } else {
00056             fd = stderr;
00057         }
00058         
00059         fprintf (fd, "D%d/%d: ", level, grass_debug_level);
00060         vfprintf (fd, msg, ap);
00061         fprintf (fd, "\n");
00062         fflush (fd);
00063         
00064         if ( filen != NULL ) fclose ( fd );
00065         
00066         va_end(ap);
00067     }
00068 #endif
00069 
00070     return 1;
00071 }
00072 
00073 
00085 int G_dump(int fd)
00086 {
00087     struct fileinfo *fcb = &G__.fileinfo[fd];
00088 
00089     G_message(_("G_dump: memory allocated to G__"));
00090     G_message(_("Size of cell in fp maps = %d"), G__.fp_nbytes);
00091     G_message(_("type for writing floating maps = %d"), G__.fp_type);
00092     G_message(_("current window = %p"), &G__.window);
00093     G_message(_("Flag: window set? %d"), G__.window_set);
00094     G_message(_("File descriptor for automatic mask %d"), G__.mask_fd);
00095     G_message(_("Flag denoting automatic masking %d"), G__.auto_mask); 
00096     G_message(_("CELL mask buffer %p"), G__.mask_buf);
00097     G_message(_("buffer for reading null rows %p"), G__.null_buf);
00098     G_message(_("Pre/post compressed data buffer %p"), G__.compressed_buf);
00099     G_message(_("sizeof compressed_buf %d"), G__.compressed_buf_size);
00100     G_message(_("work data buffer %p"), G__.work_buf);
00101     G_message(_("sizeof work_buf %d"), G__.work_buf_size);
00102     G_message(_("sizeof null_buf %d"), G__.null_buf_size);
00103     G_message(_("sizeof mask_buf %d"), G__.mask_buf_size);
00104     G_message(_("Histogram request %d"), G__.want_histogram);
00105 
00106     G_message(_("G_dump: file #%d"), fd);
00107     G_message(_("open mode = %d"), fcb->open_mode);
00108     G_message(_("Cell header %p"),&fcb->cellhd);
00109     G_message(_("Table reclass %p"), &fcb->reclass);
00110     G_message(_("Cell stats %p"), &fcb->statf);
00111     G_message(_("Range structure %p"), &fcb->range);
00112     G_message(_("float Range structure %p"), &fcb->fp_range);
00113     G_message(_("want histogram?  %d"), fcb->want_histogram);
00114     G_message(_("Automatic reclass flag %d"), fcb->reclass_flag);
00115     G_message(_("File row addresses %p"), fcb->row_ptr);
00116     G_message(_("Data to window col mapping %p"), fcb->col_map);
00117     G_message(_("Data to window row constants %f,%f"), fcb->C1,fcb->C2);
00118     G_message(_("Current data row in memory %d"), fcb->cur_row);
00119     G_message(_("Current null row in memory %d"), fcb->null_cur_row);
00120     G_message(_("nbytes per cell for current row %d"), fcb->cur_nbytes);
00121     G_message(_("Decompressed data buffer %s"), fcb->data);
00122     G_message(_("bytes per cell %d"), fcb->nbytes);
00123     G_message(_("type: int, float or double map %d"), fcb->map_type);
00124     G_message(_("Temporary name for NEW files %s"), fcb->temp_name);
00125     G_message(_("Temporary name for NEW NULL files %s"), fcb->null_temp_name);
00126     G_message(_("for existing raster maps %d"), fcb->null_file_exists);
00127     G_message(_("Name of open file %s"), fcb->name);
00128     G_message(_("Mapset of open file %s"), fcb->mapset);
00129     G_message(_("io error warning given %d"), fcb->io_error);
00130     G_message(_("xdr stream for reading fp %p"), &fcb->xdrstream);
00131     G_message(_("NULL_ROWS array[%d] = %p"), NULL_ROWS_INMEM, fcb->NULL_ROWS);
00132     G_message(_("data buffer for reading null rows %p"), fcb->null_work_buf);
00133     G_message(_("Minimum row null row number in memory %d"), fcb->min_null_row);
00134     G_message(_("Quant ptr = %p"), &fcb->quant);
00135     G_message(_("G_dump: end"));
00136 
00137     return 0;
00138 }

Generated on Fri Nov 21 11:02:17 2008 for GRASS by  doxygen 1.5.1