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