[GRASS-SVN] r32719 - in grass/trunk/raster: r.his r.out.mpeg
r.support
svn_grass at osgeo.org
svn_grass at osgeo.org
Tue Aug 12 06:12:02 EDT 2008
Author: glynn
Date: 2008-08-12 06:12:02 -0400 (Tue, 12 Aug 2008)
New Revision: 32719
Modified:
grass/trunk/raster/r.his/main.c
grass/trunk/raster/r.out.mpeg/main.c
grass/trunk/raster/r.support/check.c
grass/trunk/raster/r.support/front.c
grass/trunk/raster/r.support/histo.c
grass/trunk/raster/r.support/local_proto.h
Log:
Don't use explicit mapsets unnecessarily
Modified: grass/trunk/raster/r.his/main.c
===================================================================
--- grass/trunk/raster/r.his/main.c 2008-08-12 10:08:56 UTC (rev 32718)
+++ grass/trunk/raster/r.his/main.c 2008-08-12 10:12:02 UTC (rev 32719)
@@ -29,7 +29,6 @@
unsigned char *sat_n, *sat_r;
unsigned char *dummy;
CELL *r_array, *g_array, *b_array;
- char *mapset;
char *name_h, *name_i, *name_s;
int intensity;
int saturation;
@@ -122,12 +121,8 @@
/* Get name of layer to be used for hue */
name_h = opt_h->answer;
- mapset = G_find_cell2(name_h, "");
- if (mapset == NULL)
- G_fatal_error(_("Raster map <%s> not found"), opt_h->answer);
-
/* Make sure map is available */
- if ((hue_file = G_open_cell_old(name_h, mapset)) == -1)
+ if ((hue_file = G_open_cell_old(name_h, "")) == -1)
G_fatal_error(_("Unable to open raster map <%s>"), name_h);
hue_r = G_malloc(window.cols);
@@ -138,7 +133,7 @@
dummy = G_malloc(window.cols);
/* Reading color lookup table */
- if (G_read_colors(name_h, mapset, &hue_colors) == -1)
+ if (G_read_colors(name_h, "", &hue_colors) == -1)
G_fatal_error(_("Color file for <%s> not available"), name_h);
int_used = 0;
@@ -146,23 +141,17 @@
if (opt_i->answer != NULL) {
/* Get name of layer to be used for intensity */
name_i = opt_i->answer;
- mapset = G_find_cell2(name_i, "");
- if (mapset != NULL) {
- int_used = 1;
- /* Make sure map is available */
- if ((int_file = G_open_cell_old(name_i, mapset)) == -1)
- G_fatal_error(_("Unable to open raster map <%s>"), name_i);
+ int_used = 1;
+ /* Make sure map is available */
+ if ((int_file = G_open_cell_old(name_i, "")) == -1)
+ G_fatal_error(_("Unable to open raster map <%s>"), name_i);
- int_r = G_malloc(window.cols);
- int_n = G_malloc(window.cols);
+ int_r = G_malloc(window.cols);
+ int_n = G_malloc(window.cols);
- /* Reading color lookup table */
- if (G_read_colors(name_i, mapset, &int_colors) == -1)
- G_fatal_error(_("Color file for <%s> not available"), name_i);
- }
- else
- G_fatal_error(_("Raster map <%s> not found"), name_i);
-
+ /* Reading color lookup table */
+ if (G_read_colors(name_i, "", &int_colors) == -1)
+ G_fatal_error(_("Color file for <%s> not available"), name_i);
}
sat_used = 0;
@@ -170,24 +159,18 @@
if (opt_s->answer != NULL) {
/* Get name of layer to be used for saturation */
name_s = opt_s->answer;
- mapset = G_find_cell2(name_s, "");
- if (mapset != NULL) {
sat_used = 1;
/* Make sure map is available */
- if ((sat_file = G_open_cell_old(name_s, mapset)) == -1)
+ if ((sat_file = G_open_cell_old(name_s, "")) == -1)
G_fatal_error(_("Unable to open raster map <%s>"), name_s);
sat_r = G_malloc(window.cols);
sat_n = G_malloc(window.cols);
/* Reading color lookup table */
- if (G_read_colors(name_s, mapset, &sat_colors) == -1)
+ if (G_read_colors(name_s, "", &sat_colors) == -1)
G_fatal_error(_("Color file for <%s> not available"), name_s);
- }
- else
- G_fatal_error(_("Raster map <%s> not found"), name_s);
-
}
r_used = 0;
Modified: grass/trunk/raster/r.out.mpeg/main.c
===================================================================
--- grass/trunk/raster/r.out.mpeg/main.c 2008-08-12 10:08:56 UTC (rev 32718)
+++ grass/trunk/raster/r.out.mpeg/main.c 2008-08-12 10:12:02 UTC (rev 32719)
@@ -157,12 +157,12 @@
void *voidc;
int rtype;
register int i, rowoff, row, col, vxoff, vyoff, offset;
- int cnt, ret, fd, size, tsiz, coff;
+ int cnt, fd, size, tsiz, coff;
int vnum;
int y_rows, y_cols;
char *pr, *pg, *pb;
unsigned char *tr, *tg, *tb, *tset;
- char *mpfilename, *mapset, name[BUFSIZ];
+ char *mpfilename, *name;
char cmd[1000], *yfiles[MAXIMAGES];
struct Colors colors;
@@ -208,36 +208,24 @@
vyoff = vnum > 1 ? vrows + 2 * BORDER_W : BORDER_W;
}
- strcpy(name, vfiles[vnum][cnt]);
+ name = vfiles[vnum][cnt];
if (!quiet)
G_message("\r%s <%s>", _("Reading file"), name);
- mapset = G_find_cell2(name, "");
- if (mapset == NULL)
+ fd = G_open_cell_old(name, "");
+ if (fd < 0)
G_fatal_error(_("Raster map <%s> not found"), name);
- fd = G_open_cell_old(name, mapset);
- if (fd < 0)
- exit(EXIT_FAILURE);
+ if (G_read_colors(name, "", &colors) < 0)
+ G_fatal_error(_("Unable to read color table for <%s>"), name);
- ret = G_read_colors(name, mapset, &colors);
- if (ret < 0)
- exit(EXIT_FAILURE);
-
rtype = G_get_raster_map_type(fd);
- if (rtype == CELL_TYPE)
- voidc = G_allocate_c_raster_buf();
- else if (rtype == FCELL_TYPE)
- voidc = G_allocate_f_raster_buf();
- else if (rtype == DCELL_TYPE)
- voidc = G_allocate_d_raster_buf();
- else
- exit(EXIT_FAILURE);
+ voidc = G_allocate_raster_buf(rtype);
for (row = 0; row < vrows; row++) {
if (G_get_raster_row(fd, voidc,
(int)(row / vscale), rtype) < 0)
- exit(EXIT_FAILURE);
+ G_fatal_error(_("Error reading row <%d>"), row);
rowoff = (vyoff + row) * ncols;
G_lookup_raster_colors(voidc, tr, tg, tb,
@@ -321,7 +309,7 @@
static char **gee_wildfiles(char *wildarg, char *element, int *num)
{
int n, cnt = 0;
- char path[1000], *mapset, cmd[1000], buf[512];
+ char path[GPATH_MAX], *mapset, cmd[GPATH_MAX], buf[512];
char *p, *tfile;
static char *newfiles[MAXIMAGES];
FILE *tf;
Modified: grass/trunk/raster/r.support/check.c
===================================================================
--- grass/trunk/raster/r.support/check.c 2008-08-12 10:08:56 UTC (rev 32718)
+++ grass/trunk/raster/r.support/check.c 2008-08-12 10:12:02 UTC (rev 32719)
@@ -9,7 +9,7 @@
*
* RETURN: EXIT_SUCCESS / EXIT_FAILURE
*/
-int check_stats(const char *name, const char *mapset)
+int check_stats(const char *name)
{
RASTER_MAP_TYPE data_type;
struct Histogram histogram;
@@ -20,12 +20,12 @@
int cats_ok;
int max;
- data_type = G_raster_map_type(name, mapset);
+ data_type = G_raster_map_type(name, "");
G_message(_("\n Updating statistics for [%s]"), name);
- if (!do_histogram(name, mapset))
+ if (!do_histogram(name))
return EXIT_SUCCESS;
- if (G_read_histogram(name, mapset, &histogram) <= 0)
+ if (G_read_histogram(name, "", &histogram) <= 0)
return EXIT_SUCCESS;
/* Init histogram range */
@@ -51,7 +51,7 @@
G_write_fp_range(name, &fprange);
/* Get category status and max */
- cats_ok = (G_read_cats(name, mapset, &cats) >= 0);
+ cats_ok = (G_read_cats(name, "", &cats) >= 0);
max = (data_type == CELL_TYPE ? range.max : fprange.max);
/* Further category checks */
Modified: grass/trunk/raster/r.support/front.c
===================================================================
--- grass/trunk/raster/r.support/front.c 2008-08-12 10:08:56 UTC (rev 32718)
+++ grass/trunk/raster/r.support/front.c 2008-08-12 10:12:02 UTC (rev 32719)
@@ -44,7 +44,7 @@
struct Flag *stats_flag, *null_flag, *del_flag;
int cellhd_ok; /* Is cell header OK? */
int is_reclass; /* Is raster reclass? */
- char *infile, *cmapset;
+ char *infile;
char title[MAX_TITLE_LEN + 1], datasrc[RECORD_LEN + 1];
struct History hist;
@@ -143,12 +143,11 @@
/* Make sure raster exists and set mapset */
infile = raster->answer;
mapset = G_find_cell2(infile, G_mapset()); /* current mapset only for editing */
- if (mapset == NULL)
- G_fatal_error(_("Raster map <%s> not found in current mapset"),
- infile);
+ if (!mapset || strcmp(mapset, G_mapset()) != 0)
+ G_fatal_error(_("Raster map <%s> not found in current mapset"), infile);
- cellhd_ok = (G_get_cellhd(raster->answer, mapset, &cellhd) >= 0);
- is_reclass = (G_is_reclass(raster->answer, mapset, rname, rmapset) > 0);
+ cellhd_ok = (G_get_cellhd(raster->answer, "", &cellhd) >= 0);
+ is_reclass = (G_is_reclass(raster->answer, "", rname, rmapset) > 0);
if (title_opt->answer) {
strncpy(title, title_opt->answer, MAX_TITLE_LEN);
@@ -165,7 +164,7 @@
if (!fp)
G_fatal_error(_("Unable to open output file <%s>"), save_opt->answer);
- G_read_history(raster->answer, mapset, &hist);
+ G_read_history(raster->answer, "", &hist);
for (i = 0; i < hist.edlinecnt; i++)
fprintf(fp, "%s\n", hist.edhist[i]);
@@ -180,7 +179,7 @@
if (!fp)
G_fatal_error(_("Unable to open input file <%s>"), load_opt->answer);
- G_read_history(raster->answer, mapset, &hist);
+ G_read_history(raster->answer, "", &hist);
for (i = 0; ; i++) {
if (i >= MAXEDLINES) {
@@ -199,7 +198,7 @@
}
if (history_opt->answer) {
- G_read_history(raster->answer, mapset, &hist);
+ G_read_history(raster->answer, "", &hist);
if (hist.edlinecnt >= MAXEDLINES)
G_fatal_error(_("Not enough room in history file"));
@@ -246,7 +245,7 @@
G_write_raster_vdatum(raster->answer, vdatum_opt->answer);
if (datasrc1_opt->answer || datasrc2_opt->answer || datadesc_opt->answer) {
- G_read_history(raster->answer, mapset, &hist);
+ G_read_history(raster->answer, "", &hist);
if (datasrc1_opt->answer) {
strncpy(datasrc, datasrc1_opt->answer, RECORD_LEN);
@@ -281,16 +280,12 @@
int fd;
struct Categories cats;
- cmapset = G_find_cell2(map_opt->answer, "");
- if (cmapset == NULL)
- G_fatal_error(_("Raster map <%s> not found"), map_opt->answer);
-
- if ((fd = G_open_cell_old(infile, mapset)) < 0)
+ if ((fd = G_open_cell_old(infile, "")) < 0)
G_fatal_error(_("Unable to open raster map <%s>"), infile);
G_init_cats((CELL) 0, "", &cats);
- if (0 > G_read_cats(map_opt->answer, cmapset, &cats))
- G_fatal_error(_("Unable to read category file of raster map <%s@%s>"),
- map_opt->answer, cmapset);
+ if (G_read_cats(map_opt->answer, "", &cats) < 0)
+ G_fatal_error(_("Unable to read category file of raster map <%s>"),
+ map_opt->answer);
if (G_write_cats(infile, &cats) >= 0)
G_message(_("cats table for [%s] set to %s"), infile,
@@ -308,7 +303,7 @@
/* Check the histogram and range */
if (stats_flag->answer)
- check_stats(raster->answer, mapset);
+ check_stats(raster->answer);
/* null file */
if (null_flag->answer) {
@@ -354,7 +349,7 @@
G_message(_("Removing null file for [%s]...\n"), raster->answer);
null_fd = G_open_new_misc("cell_misc", "null", raster->answer);
- G__file_name_misc(path, "cell_misc", "null", raster->answer, mapset);
+ G__file_name_misc(path, "cell_misc", "null", raster->answer, G_mapset());
unlink(path);
close(null_fd);
Modified: grass/trunk/raster/r.support/histo.c
===================================================================
--- grass/trunk/raster/r.support/histo.c 2008-08-12 10:08:56 UTC (rev 32718)
+++ grass/trunk/raster/r.support/histo.c 2008-08-12 10:12:02 UTC (rev 32719)
@@ -1,13 +1,14 @@
#include <stdlib.h>
#include <grass/gis.h>
+#include <grass/glocale.h>
+#include "local_proto.h"
-
/*
* do_histogram() - Creates histogram for CELL
*
* RETURN: EXIT_SUCCESS / EXIT_FAILURE
*/
-int do_histogram(const char *name, const char *mapset)
+int do_histogram(const char *name)
{
CELL *cell;
struct Cell_head cellhd;
@@ -16,12 +17,12 @@
int row;
int fd;
- if (G_get_cellhd(name, mapset, &cellhd) < 0)
- return EXIT_FAILURE;
+ if (G_get_cellhd(name, "", &cellhd) < 0)
+ G_fatal_error(_("Unable to read header for <%s>"), name);
G_set_window(&cellhd);
- if ((fd = G_open_cell_old(name, mapset)) < 0)
- return EXIT_FAILURE;
+ if ((fd = G_open_cell_old(name, "")) < 0)
+ G_fatal_error(_("Unable to open <%s>"), name);
nrows = G_window_rows();
ncols = G_window_cols();
Modified: grass/trunk/raster/r.support/local_proto.h
===================================================================
--- grass/trunk/raster/r.support/local_proto.h 2008-08-12 10:08:56 UTC (rev 32718)
+++ grass/trunk/raster/r.support/local_proto.h 2008-08-12 10:12:02 UTC (rev 32719)
@@ -1,5 +1,5 @@
/* check.c */
-int check_stats(const char *, const char *);
+int check_stats(const char *);
/* histo.c */
-int do_histogram(const char *, const char *);
+int do_histogram(const char *);
More information about the grass-commit
mailing list