Changeset 32578 for grass/trunk/raster/r.mapcalc
- Timestamp:
- Aug 6, 2008, 10:48:43 AM (16 years ago)
- Location:
- grass/trunk/raster/r.mapcalc
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
grass/trunk/raster/r.mapcalc/evaluate.c
r32526 r32578 270 270 expression *e = l->exp; 271 271 const char *var; 272 273 if (e->type != expr_type_binding) 274 G_fatal_error("internal error: execute: invalid type: %d", 275 e->type); 276 277 var = e->data.bind.var; 278 279 if (!overwrite && check_output_map(var)) 280 G_fatal_error(_("output map <%s> exists"), var); 281 } 282 283 for (l = ee; l; l = l->next) { 284 expression *e = l->exp; 285 const char *var; 272 286 expression *val; 273 287 -
grass/trunk/raster/r.mapcalc/globals.h
r32526 r32578 6 6 extern volatile int floating_point_exception_occurred; 7 7 extern int overflow_occurred; 8 extern int overwrite; 8 9 9 10 extern int current_depth, current_row; -
grass/trunk/raster/r.mapcalc/main.c
r32526 r32578 27 27 28 28 int overflow_occurred; 29 int overwrite; 29 30 30 31 volatile int floating_point_exception; 31 32 volatile int floating_point_exception_occurred; 32 33 /****************************************************************************/34 35 static const char help_text[] =36 "r.mapcalc - Raster map layer data calculator\n"37 "\n"38 "usage: r.mapcalc '<map>=<expression>'\n"39 "\n"40 "r.mapcalc performs arithmetic on raster map layers.\n"41 "\n"42 "New raster map layers can be created which are arithmetic expressions\n"43 "involving existing raster map layers, integer or floating point constants,\n"44 "and functions.\n" "\n" "For more information use 'g.manual r.mapcalc'\n";45 33 46 34 /****************************************************************************/ … … 91 79 /****************************************************************************/ 92 80 93 static const char *join(int argc, char **argv)81 static expr_list *parse_file(const char *filename) 94 82 { 95 int size = 0; 96 char *buf; 97 int i; 83 expr_list *res; 84 FILE *fp; 98 85 99 for (i = 0; i < argc; i++)100 size += strlen(argv[i]) + 1;86 if (strcmp(filename, "-") == 0) 87 return parse_stream(stdin); 101 88 102 buf = G_malloc(size); 103 *buf = '\0'; 104 for (i = 0; i < argc; i++) { 105 if (i) 106 strcat(buf, " "); 107 strcat(buf, argv[i]); 108 } 89 fp = fopen(filename, "r"); 90 if (!fp) 91 G_fatal_error(_("unable to open input file <%s>"), filename); 109 92 110 return buf; 93 res = parse_stream(fp); 94 95 fclose(fp); 96 97 return res; 111 98 } 112 99 … … 115 102 int main(int argc, char **argv) 116 103 { 104 struct GModule *module; 105 struct Option *expr, *file; 117 106 int all_ok; 118 int overwrite;119 107 120 108 G_gisinit(argv[0]); 121 109 122 if (argc > 1 && (strcmp(argv[1], "help") == 0 || 123 strcmp(argv[1], "--help") == 0)) { 124 fputs(help_text, stderr); 125 return EXIT_SUCCESS; 110 module = G_define_module(); 111 module->keywords = _("raster"); 112 module->description = _("Raster map calculator."); 113 module->overwrite = 1; 114 115 expr = G_define_option(); 116 expr->key = "expression"; 117 expr->type = TYPE_STRING; 118 expr->required = NO; 119 expr->description = _("Expression to evaluate"); 120 121 file = G_define_standard_option(G_OPT_F_INPUT); 122 file->required = NO; 123 file->description = _("File containing expression to evaluate"); 124 125 if (argc == 1) 126 { 127 char **p = G_malloc(3 * sizeof(char *)); 128 p[0] = argv[0]; 129 p[1] = G_store("input=-"); 130 p[2] = NULL; 131 argv = p; 132 argc = 2; 126 133 } 127 134 128 result = (argc >= 2) 129 ? parse_string(join(argc - 1, argv + 1)) 130 : parse_stream(stdin); 135 if (G_parser(argc, argv)) 136 exit(EXIT_FAILURE); 137 138 overwrite = module->overwrite; 139 140 if (expr->answer) 141 result = parse_string(expr->answer); 142 else if (file->answer) 143 result = parse_file(file->answer); 144 else 145 result = parse_stream(stdin); 131 146 132 147 if (!result) 133 return EXIT_FAILURE; 134 135 overwrite = G_check_overwrite(argc, argv); 136 148 G_fatal_error(_("parse error")); 137 149 138 150 pre_exec(); -
grass/trunk/raster/r.mapcalc/map.c
r32526 r32578 499 499 /****************************************************************************/ 500 500 501 int check_output_map(const char *name) 502 { 503 return !!G_find_cell2(name, G_mapset()); 504 } 505 501 506 int open_output_map(const char *name, int res_type) 502 507 { -
grass/trunk/raster/r.mapcalc/map3.c
r32526 r32578 567 567 /****************************************************************************/ 568 568 569 int check_output_map(const char *name) 570 { 571 return !!G_find_grid3(name, G_mapset()); 572 } 573 569 574 int open_output_map(const char *name, int res_type) 570 575 { -
grass/trunk/raster/r.mapcalc/mapcalc.h
r32526 r32578 50 50 extern void close_maps(void); 51 51 52 extern int check_output_map(const char *name); 52 53 extern int open_output_map(const char *name, int res_type); 53 54 extern void put_map_row(int fd, void *buf, int res_type);
Note:
See TracChangeset
for help on using the changeset viewer.
