1 /* Function: cellfile
2  **
3  ** This function is a slightly modified version of the p.map function.
4  ** Modified: Paul W. Carlson   April 1992
5  */
6 
7 #include <string.h>
8 #include <grass/raster.h>
9 #include "local_proto.h"
10 
read_cell(char * name,char * mapset)11 int read_cell(char *name, char *mapset)
12 {
13     /* full name can be "name@mapset in mapset" */
14     char fullname[GNAME_MAX + 2 * GMAPSET_MAX + 4];
15 
16     PS.do_colortable = 0;
17     if (PS.cell_fd >= 0) {
18 	Rast_close(PS.cell_fd);
19 	G_free(PS.cell_name);
20 	Rast_free_colors(&PS.colors);
21 	PS.cell_fd = -1;
22     }
23 
24     sprintf(fullname, "%s in %s", name, mapset);
25 
26     if (Rast_read_colors(name, mapset, &PS.colors) == -1) {
27 	error(fullname, "", "can't read color table");
28 	return 0;
29     }
30     Rast_get_c_color_range(&PS.min_color, &PS.max_color, &PS.colors);
31 
32     /* open raster map for reading */
33     PS.cell_fd = Rast_open_old(name, mapset);
34 
35     strcpy(PS.celltitle, Rast_get_cell_title(name, mapset));
36     G_strip(PS.celltitle);
37     if (PS.celltitle[0] == 0)
38 	sprintf(PS.celltitle, "(%s)", name);
39     PS.cell_name = G_store(name);
40     PS.cell_mapset = G_store(mapset);
41     PS.do_raster = 1;
42     return 1;
43 }
44