void update_default_window(struct Cell_head *cellhd) { /* -------------------------------------------------------------------- */ /* Extend current window based on dataset. */ /* -------------------------------------------------------------------- */ struct Cell_head cur_wind; if (strcmp(G_mapset(), "PERMANENT") == 0) /* fixme: expand WIND and DEFAULT_WIND independently. (currently WIND gets forgotten and DEFAULT_WIND is expanded for both) */ G_get_default_window(&cur_wind); else G_get_window(&cur_wind); cur_wind.north = MAX(cur_wind.north, cellhd->north); cur_wind.south = MIN(cur_wind.south, cellhd->south); cur_wind.west = MIN(cur_wind.west, cellhd->west); cur_wind.east = MAX(cur_wind.east, cellhd->east); cur_wind.rows = (int)ceil((cur_wind.north - cur_wind.south) / cur_wind.ns_res); cur_wind.south = cur_wind.north - cur_wind.rows * cur_wind.ns_res; cur_wind.cols = (int)ceil((cur_wind.east - cur_wind.west) / cur_wind.ew_res); cur_wind.east = cur_wind.west + cur_wind.cols * cur_wind.ew_res; if (strcmp(G_mapset(), "PERMANENT") == 0) { G_put_element_window(&cur_wind, "", "DEFAULT_WIND"); G_message(_("Default region for this location updated")); } G_put_window(&cur_wind); G_message(_("Region for the current mapset updated")); }
int I_get_con_points(char *group, struct Ortho_Control_Points *cp) { FILE *fd; char msg[100]; int stat; fd = I_fopen_group_file_old(group, POINT_FILE); if (fd == NULL) { sprintf(msg, "unable to open control point (Z) file for group [%s in %s]", group, G_mapset()); G_warning(msg); G_sleep(4); return 0; } stat = I_read_con_points(fd, cp); fclose(fd); if (stat < 0) { sprintf(msg, "bad format in control point file for group [%s in %s]", group, G_mapset()); G_warning(msg); G_sleep(4); return 0; } return 1; }
int I_get_ref_points(char *groupname, struct Ortho_Photo_Points *cp) { FILE *fd; char msg[100]; int stat; /*fprintf (stderr, "Try to f_open_group_file_old \n"); */ fd = I_fopen_group_file_old(groupname, REF_POINT_FILE); if (fd == NULL) { sprintf(msg, "unable to open reference point file for group [%s in %s]", groupname, G_mapset()); G_warning(msg); return 0; } /*fprintf (stderr, "Try to read_ref_points \n"); */ stat = I_read_ref_points(fd, cp); fclose(fd); if (stat < 0) { sprintf(msg, "bad format in reference point file for group [%s in %s]", groupname, G_mapset()); G_warning(msg); return 0; } return 1; }
int read_range(void) { struct FPRange drange; struct Range range; CELL tmp_min, tmp_max; DCELL tmp_dmin, tmp_dmax; char buff[1024]; int i; /* read the fpranges and ranges of all input maps */ for (i = 0; i < noi; i++) { if (Rast_read_fp_range(name[i], G_mapset(), &drange) <= 0) { sprintf(buff, "Can't read f_range for map %s", name[i]); G_fatal_error("%s", buff); } Rast_get_fp_range_min_max(&drange, &tmp_dmin, &tmp_dmax); if (Rast_read_range(name[i], G_mapset(), &range) <= 0) { sprintf(buff, "Can't read range for map %s", name[i]); G_fatal_error("%s", buff); } Rast_get_range_min_max(&range, &tmp_min, &tmp_max); if (!i || tmp_max > old_max || Rast_is_c_null_value(&old_max)) old_max = tmp_max; if (!i || tmp_min < old_min || Rast_is_c_null_value(&old_min)) old_min = tmp_min; if (!i || tmp_dmax > old_dmax || Rast_is_d_null_value(&old_dmax)) old_dmax = tmp_dmax; if (!i || tmp_dmin < old_dmin || Rast_is_d_null_value(&old_dmin)) old_dmin = tmp_dmin; } /* for loop */ return 0; }
static void fft_colors(const char *name) { struct Colors colors; struct FPRange range; DCELL min, max; /* make a real component color table */ Rast_read_fp_range(name, G_mapset(), &range); Rast_get_fp_range_min_max(&range, &min, &max); Rast_make_grey_scale_fp_colors(&colors, min, max); Rast_write_colors(name, G_mapset(), &colors); }
/*! * \brief Write a line to a raster map metadata file * * Write (including overwrite) a string into a raster map's metadata file * found in in cell_misc/ in the current mapset. * * \param element metadata component filename * \param name * \param *str string containing data to be written */ static void misc_write_line(const char *elem, const char *name, const char *str) { FILE *fp; fp = G_fopen_new_misc("cell_misc", elem, name); if (!fp) G_fatal_error(_("Unable to create <%s> metadata file for raster map <%s@%s>"), elem, name, G_mapset()); fprintf(fp, "%s\n", str); if (fclose(fp) != 0) G_fatal_error(_("Error closing <%s> metadata file for raster map <%s@%s>"), elem, name, G_mapset()); }
int I_convert_con_points(char *group, struct Ortho_Control_Points *con_cp, struct Ortho_Control_Points *photo_cp, double E12[3], double N12[3]) { FILE *fd; char msg[100]; int i, stat, status; double e1, e2, n1, n2, z1, z2, e0, n0; fd = I_fopen_group_file_old(group, POINT_FILE); if (fd == NULL) { sprintf(msg, "unable to open control point (Z) file for group [%s in %s]", group, G_mapset()); G_warning(msg); G_sleep(4); return 0; } stat = I_read_con_points(fd, con_cp); fclose(fd); if (stat < 0) { sprintf(msg, "bad format in control point file for group [%s in %s]", group, G_mapset()); G_warning(msg); G_sleep(4); return 0; } /* convert to photo coordinates, given E12, N12 */ photo_cp->count = 0; for (i = 0; i < con_cp->count; i++) { status = con_cp->status[i]; e1 = con_cp->e1[i]; n1 = con_cp->n1[i]; z1 = con_cp->z1[i]; e2 = con_cp->e2[i]; n2 = con_cp->n2[i]; z2 = con_cp->z2[i]; I_georef(e1, n1, &e0, &n0, E12, N12); /* I_new_con_point (photo_cp, e0,n0,z1,e2,n2,z2,status); */ I_new_con_point(photo_cp, e0, n0, z1, e2, n2, z2, status); } return 1; }
int G_open_update (char *element,char *name) { int fd; fd = G__open (element, name, G_mapset(), 2); if (fd >= 0) lseek (fd, 0L, 2); return fd; }
int get_conz_points(void) { char msg[200]; /* struct Ortho_Control_Points cpz; */ if (!I_get_con_points(group.name, &group.control_points)) exit(0); sprintf(msg, _("Control Z Point file for group [%s] in [%s] \n \n"), group.name, G_mapset()); G_verbose_message(_("Computing equations...")); Compute_ortho_equation(); switch (group.con_equation_stat) { case -1: strcat(msg, _("Poorly placed Control Points!\n")); strcat(msg, _("Can not generate the transformation equation.\n")); strcat(msg, _("Run OPTION 7 of i.ortho.photo again!\n")); break; case 0: strcat(msg, _("No active Control Points!\n")); strcat(msg, _("Can not generate the transformation equation.\n")); strcat(msg, _("Run OPTION 7 of i.ortho.photo!\n")); break; default: return 1; } G_fatal_error("%s", msg); }
int get_ref_points(void) { char msg[200]; /* struct Ortho_Photo_Points cp; */ if (!I_get_ref_points(group.name, &group.photo_points)) exit(0); sprintf(msg, _("Reference Point file for group [%s] in [%s] \n \n"), group.name, G_mapset()); Compute_ref_equation(); switch (group.ref_equation_stat) { case -1: strcat(msg, _("Poorly placed Reference Points!\n")); strcat(msg, _("Can not generate the transformation equation.\n")); strcat(msg, _("Run OPTION 5 of i.ortho.photo again!\n")); break; case 0: strcat(msg, _("No active Reference Points!\n")); strcat(msg, _("Can not generate the transformation equation.\n")); strcat(msg, _("Run OPTION 5 of i.ortho.photo!\n")); break; default: return 1; } G_fatal_error("%s", msg); /* exit(1); shouldn't get here */ }
int G3d_maskOpenOld() { G3D_Region region; /* No Idea if this is correct return value */ if (G3d_maskMapExistsVar) return 1; G3d_maskMapExistsVar = G3d_maskFileExists(); if (!G3d_maskMapExistsVar) return 1; if ((G3d_maskMap = G3d_openCellOld(G3D_MASK_MAP, G_mapset(), G3D_DEFAULT_WINDOW, FCELL_TYPE, maskOpenOldCacheDefault)) == NULL) { G3d_error("G3d_maskOpenOld: cannot open mask"); return 0; } G3d_getRegionStructMap(G3d_maskMap, ®ion); G3d_setWindowMap(G3d_maskMap, ®ion); return 1; }
int G3d_maskFileExists() { char buf[200]; sprintf(buf, "%s/%s", G3D_DIRECTORY, G3D_MASK_MAP); return (G_find_file(buf, G3D_CELL_ELEMENT, G_mapset()) != NULL); }
int write_contrast_colors (char* raster) { struct Colors colors; struct Categories cats; FCOLORS fcolors[9]={ /* colors for positive openness */ {-2500, 0, 0, 50, NULL}, {-100, 0, 0, 56, NULL}, {-15, 0, 56, 128, NULL}, {-3, 0, 128, 255, NULL}, {0, 255, 255, 255, NULL}, {3, 255, 128, 0, NULL}, {15, 128, 56, 0, NULL}, {100, 56, 0, 0, NULL}, {2500, 50, 0, 0, NULL}}; int i; Rast_init_colors(&colors); for(i=0;i<8;++i) Rast_add_d_color_rule( &fcolors[i].cat, fcolors[i].r, fcolors[i].g, fcolors[i].b, &fcolors[i+1].cat, fcolors[i+1].r, fcolors[i+1].g, fcolors[i+1].b, &colors); Rast_write_colors(raster, G_mapset(), &colors); Rast_free_colors(&colors); /* Rast_init_cats("Forms", &cats); for(i=0;i<8;++i) Rast_set_cat(&ccolors[i].cat, &ccolors[i].cat, ccolors[i].label, &cats, CELL_TYPE); Rast_write_cats(raster, &cats); Rast_free_cats(&cats); */ return 0; }
/*! * \brief Write map layer color table * * The color table is written for the raster map <i>name</i> in the * specified <i>mapset</i> from the <i>colors</i> structure. * * If there is an error, -1 is returned. No diagnostic is * printed. Otherwise, 1 is returned. * * The <i>colors</i> structure must be created properly, i.e., * Rast_init_colors() to initialize the structure and Rast_add_c_color_rule() * to set the category colors. These routines are called by * higher level routines which read or create entire color tables, * such as Rast_read_colors() or Rast_make_ramp_colors(). * * <b>Note:</b> The calling sequence for this function deserves * special attention. The <i>mapset</i> parameter seems to imply that * it is possible to overwrite the color table for a raster map which * is in another mapset. However, this is not what actually * happens. It is very useful for users to create their own color * tables for raster maps in other mapsets, but without overwriting * other users' color tables for the same raster map. If <i>mapset</i> * is the current mapset, then the color file for <i>name</i> will be * overwritten by the new color table. But if <i>mapset</i> is not the * current mapset, then the color table is actually written in the * current mapset under the <tt>colr2</tt> element as: * <tt>colr2/mapset/name</tt>. * * The rules are written out using floating-point format, removing * trailing zeros (possibly producing integers). The flag marking the * colors as floating-point is <b>not</b> written. * * If the environment variable FORCE_GRASS3_COLORS is set (to anything at all) * then the output format is 3.0, even if the structure contains 4.0 rules. * This allows users to create 3.0 color files for export to sites which * don't yet have 4.0 * * \param name map name * \param mapset mapset name * \param colors pointer to structure Colors which holds color info * * \return void */ void Rast_write_colors(const char *name, const char *mapset, struct Colors *colors) { char element[512]; char xname[GNAME_MAX], xmapset[GMAPSET_MAX]; FILE *fd; if (G_name_is_fully_qualified(name, xname, xmapset)) { if (strcmp(xmapset, mapset) != 0) G_fatal_error(_("Qualified name <%s> doesn't match mapset <%s>"), name, mapset); name = xname; } /* * if mapset is current mapset, remove colr2 file (created by pre 3.0 grass) * and then write original color table * else write secondary color table */ sprintf(element, "colr2/%s", mapset); if (strcmp(mapset, G_mapset()) == 0) { G_remove(element, name); /* get rid of existing colr2, if any */ strcpy(element, "colr"); } if (!(fd = G_fopen_new(element, name))) G_fatal_error(_("Unable to create <%s> file for map <%s>"), element, name); Rast__write_colors(fd, colors); fclose(fd); }
/* Copy the colors from map named iname to the map named oname */ static void copy_colors(const char *iname, char *oname) { struct Colors colors; Rast_read_colors(iname, "", &colors); Rast_write_colors(oname, G_mapset(), &colors); }
/** \brief Open/Create new vector map. \param Map pointer to vector map \param name map name \param with_z 2D or 3D (unused?) \return 0 success \return -1 error */ int V1_open_new_nat(struct Map_info *Map, const char *name, int with_z) { char buf[1000]; struct stat info; G_debug(1, "V1_open_new_nat(): name = %s", name); sprintf(buf, "%s/%s", GRASS_VECT_DIRECTORY, name); /* Set the 'coor' file version */ Map->head.Version_Major = GV_COOR_VER_MAJOR; Map->head.Version_Minor = GV_COOR_VER_MINOR; Map->head.Back_Major = GV_COOR_EARLIEST_MAJOR; Map->head.Back_Minor = GV_COOR_EARLIEST_MINOR; /* TODO open better */ dig_file_init(&(Map->dig_fp)); Map->dig_fp.file = G_fopen_new(buf, GRASS_VECT_COOR_ELEMENT); if (Map->dig_fp.file == NULL) return (-1); fclose(Map->dig_fp.file); dig_file_init(&(Map->dig_fp)); Map->dig_fp.file = G_fopen_modify(buf, GRASS_VECT_COOR_ELEMENT); if (Map->dig_fp.file == NULL) return (-1); /* check to see if dig_plus file exists and if so, remove it */ G__file_name(name_buf, buf, GV_TOPO_ELEMENT, G_mapset()); if (stat(name_buf, &info) == 0) /* file exists? */ unlink(name_buf); G__file_name(name_buf, buf, GRASS_VECT_COOR_ELEMENT, G_mapset()); Map->head.size = 0; Map->head.head_size = GV_COOR_HEAD_SIZE; Vect__write_head(Map); /* set conversion matrices */ dig_init_portable(&(Map->head.port), dig__byte_order_out()); if (!(dig__write_head(Map))) return (-1); return 0; }
int G_read_colors(const char *name, const char *mapset, struct Colors *colors) { int fp; char buf[GNAME_MAX]; char *err; char xname[GNAME_MAX]; struct Range range; struct FPRange drange; CELL min, max; DCELL dmin, dmax; fp = G_raster_map_is_fp(name, mapset); G_init_colors(colors); strcpy(xname, name); mapset = G_find_cell(xname, mapset); name = xname; if (fp) G_mark_colors_as_fp(colors); /* first look for secondary color table in current mapset */ sprintf(buf, "colr2/%s", mapset); if (read_colors(buf, name, G_mapset(), colors) >= 0) return 1; /* now look for the regular color table */ switch (read_colors("colr", name, mapset, colors)) { case -2: if (!fp) { if (G_read_range(name, mapset, &range) >= 0) { G_get_range_min_max(&range, &min, &max); if (!G_is_c_null_value(&min) && !G_is_c_null_value(&max)) G_make_rainbow_colors(colors, min, max); return 0; } } else { if (G_read_fp_range(name, mapset, &drange) >= 0) { G_get_fp_range_min_max(&drange, &dmin, &dmax); if (!G_is_d_null_value(&dmin) && !G_is_d_null_value(&dmax)) G_make_rainbow_fp_colors(colors, dmin, dmax); return 0; } } err = "missing"; break; case -1: err = "invalid"; break; default: return 1; } G_warning(_("color support for [%s] in mapset [%s] %s"), name, mapset, err); return -1; }
/*! \brief Rewrite 'dbln' file Should be used by GRASS modules which update database tables, so that other applications know that tables were changed and can reload data. \param Map pointer to Map_info structure */ void Vect_set_db_updated(struct Map_info *Map) { if (strcmp(Map->mapset, G_mapset()) != 0 && G_strcasecmp(Map->mapset, "ogr") != 0) { G_fatal_error(_("Bug: attempt to update map which is not in current mapset")); } Vect_write_dblinks(Map); }
FILE *I_fopen_cam_file_old(char *camera) { FILE *fd; fd = G_fopen_old("camera", camera, G_mapset()); if (!fd) error(camera, "can't open ", ""); return fd; }
static void write_support_files(int xtile, int ytile, int overlap) { char name[GNAME_MAX]; struct Cell_head cellhd; char title[64]; struct History history; struct Colors colors; struct Categories cats; sprintf(name, "%s-%03d-%03d", parm.rastout->answer, ytile, xtile); Rast_get_cellhd(name, G_mapset(), &cellhd); cellhd.north = src_w.north - ytile * dst_w.rows * src_w.ns_res; cellhd.south = cellhd.north - (dst_w.rows + 2 * overlap) * src_w.ns_res; cellhd.west = src_w.west + xtile * dst_w.cols * src_w.ew_res; cellhd.east = cellhd.west + (dst_w.cols + 2 * overlap) * src_w.ew_res; Rast_put_cellhd(name, &cellhd); /* copy cats from source map */ if (Rast_read_cats(parm.rastin->answer, "", &cats) < 0) G_fatal_error(_("Unable to read cats for %s"), parm.rastin->answer); Rast_write_cats(name, &cats); /* record map metadata/history info */ G_debug(1, "Tile %d,%d of %s: writing %s", xtile, ytile, parm.rastin->answer, name); sprintf(title, "Tile %d,%d of %s", xtile, ytile, parm.rastin->answer); Rast_put_cell_title(name, title); Rast_short_history(name, "raster", &history); Rast_set_history(&history, HIST_DATSRC_1, parm.rastin->answer); Rast_command_history(&history); Rast_write_history(name, &history); /* copy color table from source map */ if (Rast_read_colors(parm.rastin->answer, "", &colors) < 0) G_fatal_error(_("Unable to read color table for %s"), parm.rastin->answer); if (map_type != CELL_TYPE) Rast_mark_colors_as_fp(&colors); Rast_write_colors(name, G_mapset(), &colors); }
/*! \brief Lowest level open routine. Opens the file <i>name</i> in <i>element</i> ("cell", etc.) in mapset <i>mapset</i> according to the i/o <i>mode</i>. - mode = 0 (read) will look for <i>name</i> in <i>mapset</i> and open the file for read only the file must exist - mode = 1 (write) will create an empty file <i>name</i> in the current mapset and open the file for write only <i>mapset</i> ignored - mode = 2 (read and write) will open a file in the current mapset for reading and writing creating a new file if necessary <i>mapset</i> ignored \param element database element name \param name map file name \param mapset mapset containing map <i>name</i> \param mode r/w mode 0=read, 1=write, 2=read/write \return open file descriptor (int) \return -1 could not open */ static int G__open(const char *element, const char *name, const char *mapset, int mode) { char path[GPATH_MAX]; char xname[GNAME_MAX], xmapset[GMAPSET_MAX]; G__check_gisinit(); /* READ */ if (mode == 0) { if (G_name_is_fully_qualified(name, xname, xmapset)) { if (*mapset && strcmp(xmapset, mapset) != 0) { G_warning(_("G__open(read): mapset <%s> doesn't match xmapset <%s>"), mapset, xmapset); return -1; } name = xname; mapset = xmapset; } else if (!mapset || !*mapset) mapset = G_find_file2(element, name, mapset); if (!mapset) return -1; G_file_name(path, element, name, mapset); return open(path, 0); } /* WRITE */ if (mode == 1 || mode == 2) { mapset = G_mapset(); if (G_name_is_fully_qualified(name, xname, xmapset)) { if (strcmp(xmapset, mapset) != 0) { G_warning(_("G__open(write): xmapset <%s> != G_mapset() <%s>"), xmapset, mapset); return -1; } name = xname; } if (*name && G_legal_filename(name) == -1) return -1; G_file_name(path, element, name, mapset); if (mode == 1 || access(path, 0) != 0) { G__make_mapset_element(element); close(open(path, O_WRONLY | O_CREAT | O_TRUNC, 0666)); } return open(path, mode); } return -1; }
FILE *I_fopen_group_file_old(const char *group, const char *file) { FILE *fd; /* find file first */ if (!I_find_group_file(group, file)) { G_warning(_("Unable to find file [%s] of group [%s in %s]"), file, group, G_mapset()); return ((FILE *) NULL); } fd = G_fopen_old_misc("group", file, group, G_mapset()); if (!fd) G_warning(_("Unable to open file [%s] of group [%s in %s]"), file, group, G_mapset()); return fd; }
int G_open_update_misc(const char *dir, const char *element, const char *name) { int fd; fd = G__open_misc(dir, element, name, G_mapset(), 2); if (fd >= 0) lseek(fd, 0L, SEEK_END); return fd; }
void Segment_named_outfile (char* map_name, char* mapset, int* map_fd, char* seg_name, int* seg_fd, SEGMENT* seg, int overwrite, int terse, int fract, RASTER_MAP_TYPE data_type) { int nrows; char* mapset_address; char message [64]; mapset_address = G_find_cell (map_name, G_mapset ()); strcpy (mapset, G_mapset ()); if (mapset_address != NULL) { if (!overwrite) { sprintf (message, "Raster map '%s' exists ", map_name); G_fatal_error ("%s",message); } else { if (!terse) fprintf (stdout, "\nOverwriting raster map '%s' \n", map_name); } } else { if (!terse) fprintf (stdout, "\nCreating raster map '%s' ", map_name); } if ((*map_fd = G_open_cell_new (map_name)) < 0) G_fatal_error ("Can't create output layer "); nrows = G_window_rows (); strcpy (seg_name, Create_segment_file (nrows, fract, data_type)); *seg_fd = open (seg_name, O_RDWR); if (*seg_fd < 0) G_fatal_error ("Can't open segment disk file "); segment_init (seg, *seg_fd, 4); }
static int error(char *camera, char *msga, char *msgb) { char buf[100]; sprintf(buf, "%s camera file [%s] in [%s %s] %s", msga, camera, G_location(), G_mapset(), msgb); G_warning("%s", buf); return 0; }
FILE *G_fopen_new(const char *element, const char *name) { int fd; fd = G__open(element, name, G_mapset(), 1); if (fd < 0) return (FILE *) 0; return fdopen(fd, "w"); }
/* Return the elev name from the block file ELEV returns 0 on fail, 1 on success */ int I_get_group_elev(char *group, char *elev, char *mapset_elev, char *tl, char *math_exp, char *units, char *nd) { char buf[IN_BUF]; FILE *fd; if (!I_find_group_elev_file(group)) { G_warning( _("Unable to find elevation file for group <%s> in mapset <%s>"), group, G_mapset()); return 0; } G_suppress_warnings(1); fd = I_fopen_group_elev_old(group); G_suppress_warnings(0); if (!fd) { G_warning( _("Unable to open elevation file for group <%s> in mapset <%s>"), group, G_mapset()); G_sleep(3); return 0; } fgets(buf, IN_BUF, fd); sscanf(buf, "elevation layer :%s\n", elev); fgets(buf, IN_BUF, fd); sscanf(buf, "mapset elevation:%s\n", mapset_elev); fgets(buf, IN_BUF, fd); sscanf(buf, "location :%s\n", tl); fgets(buf, IN_BUF, fd); sscanf(buf, "math expresion :%s\n", math_exp); fgets(buf, IN_BUF, fd); sscanf(buf, "units :%s\n", units); fgets(buf, IN_BUF, fd); sscanf(buf, "no data values :%s\n", nd); fclose(fd); return 1; }
static void write_cats(const char *element, const char *name, struct Categories *cats) { FILE *fd; int i, fp_map; char *descr; DCELL val1, val2; char str1[100], str2[100]; fd = G_fopen_new(element, name); if (!fd) G_fatal_error(_("Unable to open %s file for map <%s>"), element, name); /* write # cats - note # indicate 3.0 or later */ fprintf(fd, "# %ld categories\n", (long)cats->num); /* title */ fprintf(fd, "%s\n", cats->title != NULL ? cats->title : ""); /* write format and coefficients */ fprintf(fd, "%s\n", cats->fmt != NULL ? cats->fmt : ""); fprintf(fd, "%.2f %.2f %.2f %.2f\n", cats->m1, cats->a1, cats->m2, cats->a2); /* if the map is integer or if this is a vector map, sort labels */ if (strncmp(element, "dig", 3) == 0) fp_map = 0; else fp_map = Rast_map_is_fp(name, G_mapset()); if (!fp_map) Rast_sort_cats(cats); /* write the cat numbers:label */ for (i = 0; i < Rast_quant_nof_rules(&cats->q); i++) { descr = Rast_get_ith_d_cat(cats, i, &val1, &val2); if ((cats->fmt && cats->fmt[0]) || (descr && descr[0])) { if (val1 == val2) { sprintf(str1, "%.10f", val1); G_trim_decimal(str1); fprintf(fd, "%s:%s\n", str1, descr != NULL ? descr : ""); } else { sprintf(str1, "%.10f", val1); G_trim_decimal(str1); sprintf(str2, "%.10f", val2); G_trim_decimal(str2); fprintf(fd, "%s:%s:%s\n", str1, str2, descr != NULL ? descr : ""); } } } fclose(fd); }
/*! \brief Open a database file for update (r+ mode) The database file <i>name</i> under the <i>element</i> in the current mapset is opened for for writing. The UNIX fopen() routine, with "r+" append mode, is used to open the file. If the file does not exist, the NULL pointer is returned. Otherwise the file descriptor from the fopen() is returned. \param element database element name \param name map file name \return open file descriptor (FILE *) \return NULL */ FILE *G_fopen_modify(const char *element, const char *name) { int fd; fd = G__open(element, name, G_mapset(), 2); if (fd < 0) return (FILE *) 0; lseek(fd, 0L, SEEK_END); return fdopen(fd, "r+"); }
FILE *I_fopen_group_file_append(const char *group, const char *file) { FILE *fd; fd = G_fopen_append_misc("group", file, group); if (!fd) G_warning(_("Unable to open file [%s] of group [%s in %s]"), file, group, G_mapset()); return fd; }