GRASS Programmer's Manual  6.5.svn(2014)-r66266
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
gis/debug.c
Go to the documentation of this file.
1 
17 #include <stdio.h>
18 #include <stdlib.h>
19 #include <string.h>
20 #include <stdarg.h>
21 #include <grass/gis.h>
22 #include <grass/glocale.h>
23 #include "G.h"
24 
25 
26 static int grass_debug_level = -1;
27 
28 
51 int G_debug(int level, const char *msg, ...)
52 {
53 #ifdef GDEBUG
54  char *lstr, *filen;
55  va_list ap;
56  FILE *fd;
57 
58  if (grass_debug_level < 0) {
59  lstr = G__getenv("DEBUG");
60 
61  if (lstr != NULL)
62  grass_debug_level = atoi(lstr);
63  else
64  grass_debug_level = 0;
65  }
66 
67  if (grass_debug_level >= level) {
68  va_start(ap, msg);
69 
70  filen = getenv("GRASS_DEBUG_FILE");
71  if (filen != NULL) {
72  fd = fopen(filen, "a");
73  if (!fd) {
74  G_warning(_("Cannot open debug file '%s'"), filen);
75  return 0;
76  }
77  }
78  else {
79  fd = stderr;
80  }
81 
82  fprintf(fd, "D%d/%d: ", level, grass_debug_level);
83  vfprintf(fd, msg, ap);
84  fprintf(fd, "\n");
85  fflush(fd);
86 
87  if (filen != NULL)
88  fclose(fd);
89 
90  va_end(ap);
91  }
92 #endif
93 
94  return 1;
95 }
96 
97 
108 int G_dump(int fd)
109 {
110  const struct fileinfo *fcb = &G__.fileinfo[fd];
111 
112  G_message("G_dump: memory allocated to G__");
113  G_message("Size of cell in fp maps = %d", G__.fp_nbytes);
114  G_message("type for writing floating maps = %d", G__.fp_type);
115  G_message("current window = %p", &G__.window);
116  G_message("Flag: window set? %d", G__.window_set);
117  G_message("File descriptor for automatic mask %d", G__.mask_fd);
118  G_message("Flag denoting automatic masking %d", G__.auto_mask);
119  G_message("CELL mask buffer %p", G__.mask_buf);
120  G_message("buffer for reading null rows %p", G__.null_buf);
121  G_message("Pre/post compressed data buffer %p", G__.compressed_buf);
122  G_message("sizeof compressed_buf %d", G__.compressed_buf_size);
123  G_message("work data buffer %p", G__.work_buf);
124  G_message("sizeof work_buf %d", G__.work_buf_size);
125  G_message("sizeof null_buf %d", G__.null_buf_size);
126  G_message("sizeof mask_buf %d", G__.mask_buf_size);
127  G_message("Histogram request %d", G__.want_histogram);
128 
129  G_message("G_dump: file #%d", fd);
130  G_message("open mode = %d", fcb->open_mode);
131  G_message("Cell header %p", &fcb->cellhd);
132  G_message("Table reclass %p", &fcb->reclass);
133  G_message("Cell stats %p", &fcb->statf);
134  G_message("Range structure %p", &fcb->range);
135  G_message("float Range structure %p", &fcb->fp_range);
136  G_message("want histogram? %d", fcb->want_histogram);
137  G_message("Automatic reclass flag %d", fcb->reclass_flag);
138  G_message("File row addresses %p", fcb->row_ptr);
139  G_message("Data to window col mapping %p", fcb->col_map);
140  G_message("Data to window row constants %f,%f", fcb->C1, fcb->C2);
141  G_message("Current data row in memory %d", fcb->cur_row);
142  G_message("Current null row in memory %d", fcb->null_cur_row);
143  G_message("nbytes per cell for current row %d", fcb->cur_nbytes);
144  G_message("Decompressed data buffer %s", fcb->data);
145  G_message("bytes per cell %d", fcb->nbytes);
146  G_message("type: int, float or double map %d", fcb->map_type);
147  G_message("Temporary name for NEW files %s", fcb->temp_name);
148  G_message("Temporary name for NEW NULL files %s", fcb->null_temp_name);
149  G_message("for existing raster maps %d", fcb->null_file_exists);
150  G_message("Name of open file %s", fcb->name);
151  G_message("Mapset of open file %s", fcb->mapset);
152  G_message("io error warning given %d", fcb->io_error);
153  G_message("xdr stream for reading fp %p", &fcb->xdrstream);
154  G_message("NULL_ROWS array[%d] = %p", NULL_ROWS_INMEM, fcb->NULL_ROWS);
155  G_message("data buffer for reading null rows %p", fcb->null_work_buf);
156  G_message("Minimum row null number in memory %d", fcb->min_null_row);
157  G_message("Quant ptr = %p", &fcb->quant);
158  G_message("G_dump: end");
159 
160  return 0;
161 }
int mask_fd
Definition: G.h:80
int want_histogram
Definition: G.h:92
int nbytes
Definition: G.h:58
int auto_mask
Definition: G.h:81
unsigned char * work_buf
Definition: G.h:87
int want_histogram
Definition: G.h:49
int null_buf_size
Definition: G.h:89
char * G__getenv(const char *name)
Get environment variable.
Definition: env.c:312
RASTER_MAP_TYPE map_type
Definition: G.h:59
char * null_buf
Definition: G.h:83
char * name
Definition: G.h:63
off_t * row_ptr
Definition: G.h:51
FILE * fd
Definition: g3dcolor.c:368
int io_error
Definition: G.h:65
int mask_buf_size
Definition: G.h:90
unsigned char * null_work_buf
Definition: G.h:68
char * temp_name
Definition: G.h:60
int compressed_buf_size
Definition: G.h:86
unsigned char * data
Definition: G.h:57
COLUMN_MAPPING * col_map
Definition: G.h:52
int G_dump(int fd)
Dumps status of various GIS parameters.
Definition: gis/debug.c:108
int work_buf_size
Definition: G.h:88
struct Range range
Definition: G.h:47
struct Reclass reclass
Definition: G.h:45
char * getenv()
struct Cell_head window
Definition: G.h:78
Definition: G.h:74
double C1
Definition: G.h:53
struct Cell_stats statf
Definition: G.h:46
void G_message(const char *msg,...)
Print a message to stderr.
Definition: lib/gis/error.c:74
char * mapset
Definition: G.h:64
int open_mode
Definition: G.h:43
int cur_row
Definition: G.h:54
int window_set
Definition: G.h:79
char * null_temp_name
Definition: G.h:61
int cur_nbytes
Definition: G.h:56
double C2
Definition: G.h:53
int null_file_exists
Definition: G.h:62
return NULL
Definition: dbfopen.c:1394
struct fileinfo * fileinfo
Definition: G.h:95
XDR xdrstream
Definition: G.h:66
tuple msg
Definition: wxnviz.py:32
G_warning("category support for [%s] in mapset [%s] %s", name, mapset, type)
unsigned char * compressed_buf
Definition: G.h:85
int fp_nbytes
Definition: G.h:76
struct Cell_head cellhd
Definition: G.h:44
int G_debug(int level, const char *msg,...)
Print debugging message.
Definition: gis/debug.c:51
int min_null_row
Definition: G.h:69
fclose(fd)
Definition: G.h:41
#define NULL_ROWS_INMEM
Definition: G.h:11
int null_cur_row
Definition: G.h:55
CELL * mask_buf
Definition: G.h:82
RASTER_MAP_TYPE fp_type
Definition: G.h:77
struct Quant quant
Definition: G.h:70
unsigned char * NULL_ROWS[NULL_ROWS_INMEM]
Definition: G.h:67
struct FPRange fp_range
Definition: G.h:48
int reclass_flag
Definition: G.h:50