• Main Page
  • Related Pages
  • Data Structures
  • Files
  • File List
  • Globals

debug.c

Go to the documentation of this file.
00001 
00017 #include <stdio.h>
00018 #include <stdlib.h>
00019 #include <string.h>
00020 #include <stdarg.h>
00021 #include <grass/gis.h>
00022 #include <grass/glocale.h>
00023 #include "G.h"
00024 
00025 
00026 static int grass_debug_level = -1;
00027 
00028 
00051 int G_debug(int level, const char *msg, ...)
00052 {
00053 #ifdef GDEBUG
00054     char *lstr, *filen;
00055     va_list ap;
00056     FILE *fd;
00057 
00058     if (grass_debug_level < 0) {
00059         lstr = G__getenv("DEBUG");
00060 
00061         if (lstr != NULL)
00062             grass_debug_level = atoi(lstr);
00063         else
00064             grass_debug_level = 0;
00065     }
00066 
00067     if (grass_debug_level >= level) {
00068         va_start(ap, msg);
00069 
00070         filen = getenv("GRASS_DEBUG_FILE");
00071         if (filen != NULL) {
00072             fd = fopen(filen, "a");
00073             if (!fd) {
00074                 G_warning(_("Cannot open debug file '%s'"), filen);
00075                 return 0;
00076             }
00077         }
00078         else {
00079             fd = stderr;
00080         }
00081 
00082         fprintf(fd, "D%d/%d: ", level, grass_debug_level);
00083         vfprintf(fd, msg, ap);
00084         fprintf(fd, "\n");
00085         fflush(fd);
00086 
00087         if (filen != NULL)
00088             fclose(fd);
00089 
00090         va_end(ap);
00091     }
00092 #endif
00093 
00094     return 1;
00095 }
00096 
00097 
00108 int G_dump(int fd)
00109 {
00110     const struct fileinfo *fcb = &G__.fileinfo[fd];
00111 
00112     G_message("G_dump: memory allocated to G__");
00113     G_message("Size of cell in fp maps = %d", G__.fp_nbytes);
00114     G_message("type for writing floating maps = %d", G__.fp_type);
00115     G_message("current window = %p", &G__.window);
00116     G_message("Flag: window set? %d", G__.window_set);
00117     G_message("File descriptor for automatic mask %d", G__.mask_fd);
00118     G_message("Flag denoting automatic masking %d", G__.auto_mask);
00119     G_message("CELL mask buffer %p", G__.mask_buf);
00120     G_message("buffer for reading null rows %p", G__.null_buf);
00121     G_message("Pre/post compressed data buffer %p", G__.compressed_buf);
00122     G_message("sizeof compressed_buf %d", G__.compressed_buf_size);
00123     G_message("work data buffer %p", G__.work_buf);
00124     G_message("sizeof work_buf %d", G__.work_buf_size);
00125     G_message("sizeof null_buf %d", G__.null_buf_size);
00126     G_message("sizeof mask_buf %d", G__.mask_buf_size);
00127     G_message("Histogram request %d", G__.want_histogram);
00128 
00129     G_message("G_dump: file #%d", fd);
00130     G_message("open mode = %d", fcb->open_mode);
00131     G_message("Cell header %p", &fcb->cellhd);
00132     G_message("Table reclass %p", &fcb->reclass);
00133     G_message("Cell stats %p", &fcb->statf);
00134     G_message("Range structure %p", &fcb->range);
00135     G_message("float Range structure %p", &fcb->fp_range);
00136     G_message("want histogram?  %d", fcb->want_histogram);
00137     G_message("Automatic reclass flag %d", fcb->reclass_flag);
00138     G_message("File row addresses %p", fcb->row_ptr);
00139     G_message("Data to window col mapping %p", fcb->col_map);
00140     G_message("Data to window row constants %f,%f", fcb->C1, fcb->C2);
00141     G_message("Current data row in memory %d", fcb->cur_row);
00142     G_message("Current null row in memory %d", fcb->null_cur_row);
00143     G_message("nbytes per cell for current row %d", fcb->cur_nbytes);
00144     G_message("Decompressed data buffer %s", fcb->data);
00145     G_message("bytes per cell %d", fcb->nbytes);
00146     G_message("type: int, float or double map %d", fcb->map_type);
00147     G_message("Temporary name for NEW files %s", fcb->temp_name);
00148     G_message("Temporary name for NEW NULL files %s", fcb->null_temp_name);
00149     G_message("for existing raster maps %d", fcb->null_file_exists);
00150     G_message("Name of open file %s", fcb->name);
00151     G_message("Mapset of open file %s", fcb->mapset);
00152     G_message("io error warning given %d", fcb->io_error);
00153     G_message("xdr stream for reading fp %p", &fcb->xdrstream);
00154     G_message("NULL_ROWS array[%d] = %p", NULL_ROWS_INMEM, fcb->NULL_ROWS);
00155     G_message("data buffer for reading null rows %p", fcb->null_work_buf);
00156     G_message("Minimum row null number in memory %d", fcb->min_null_row);
00157     G_message("Quant ptr = %p", &fcb->quant);
00158     G_message("G_dump: end");
00159 
00160     return 0;
00161 }

Generated on Wed Oct 13 2010 12:09:29 for GRASS Programmer's Manual by  doxygen 1.7.1