/*! * \brief Write raster range file (floating-point) * * Write the floating point range file <tt>f_range</tt>. This file is * written in binary using XDR format. If there is no defined min/max * in <em>range</em>, an empty <tt>f_range</tt> file is created. * * \param name map name * \param range pointer to FPRange which holds fp range info */ void Rast_write_fp_range(const char *name, const struct FPRange *range) { int fd; char xdr_buf[2][XDR_DOUBLE_NBYTES]; Rast_init(); fd = G_open_new_misc("cell_misc", "f_range", name); if (fd < 0) { G_remove_misc("cell_misc", "f_range", name); G_fatal_error(_("Unable to write range file for <%s>"), name); } /* if range hasn't been updated, write empty file meaning Nulls */ if (range->first_time) { close(fd); return; } G_xdr_put_double(xdr_buf[0], &range->min); G_xdr_put_double(xdr_buf[1], &range->max); if (write(fd, xdr_buf, sizeof(xdr_buf)) != sizeof(xdr_buf)) { G_remove_misc("cell_misc", "f_range", name); G_fatal_error(_("Unable to write range file for <%s>"), name); } close(fd); }
/*! * \brief Write raster range file * * This routine writes the range information for the raster map * <i>name</i> in the current mapset from the <i>range</i> structure. * A diagnostic message is printed and -1 is returned if there is an * error writing the range file. Otherwise, 0 is returned. * * This routine only writes 2 numbers (min,max) to the range * file, instead of the 4 (pmin,pmax,nmin,nmax) previously written. * If there is no defined min,max, an empty file is written. * * \param name map name * \param range pointer to Range structure which holds range info */ void Rast_write_range(const char *name, const struct Range *range) { FILE *fp; if (Rast_map_type(name, G_mapset()) != CELL_TYPE) { G_remove_misc("cell_misc", "range", name); /* remove the old file with this name */ G_fatal_error(_("Unable to write range file for <%s>"), name); } fp = G_fopen_new_misc("cell_misc", "range", name); if (!fp) { G_remove_misc("cell_misc", "range", name); /* remove the old file with this name */ G_fatal_error(_("Unable to write range file for <%s>"), name); } /* if range has been updated */ if (!range->first_time) fprintf(fp, "%ld %ld\n", (long)range->min, (long)range->max); fclose(fp); }
int Rast3d_remove_color(const char *name) /* adapted from G_remove_colr */ { return G_remove_misc(RASTER3D_DIRECTORY, RASTER3D_COLOR_ELEMENT, name); }
/*! \brief Remove floating-point range Note: For internal use only. \param name map name */ void Rast__remove_fp_range(const char *name) { G_remove_misc("cell_misc", "f_range", name); }
int main(int argc, char *argv[]) { int i, n, nlist; const char *mapset; struct GModule *module; struct Option **parm; char *from, *to; int result = EXIT_SUCCESS; G_gisinit(argv[0]); M_read_list(FALSE, &nlist); module = G_define_module(); G_add_keyword(_("general")); G_add_keyword(_("map management")); module->description = _("Copies available data files in the current mapset " "search path to the user's current mapset."); module->overwrite = 1; parm = (struct Option **) G_calloc(nlist, sizeof(struct Option *)); for (n = 0; n < nlist; n++) { parm[n] = M_define_option(n, _("copied"), NO); } if (G_parser(argc, argv)) exit(EXIT_FAILURE); for (n = 0; n < nlist; n++) { if (parm[n]->answers == NULL) continue; i = 0; while (parm[n]->answers[i]) { from = parm[n]->answers[i++]; to = parm[n]->answers[i++]; mapset = M_find(n, from, ""); if (!mapset) { G_warning(_("<%s> not found"), from); continue; } if (G_strcasecmp(mapset, G_mapset()) == 0 && G_strcasecmp(from, to) == 0) { G_warning(_("%s=%s,%s: files are the same, no copy required"), parm[n]->key, from, to); continue; } if (M_find(n, to, G_mapset()) && !(module->overwrite)) { G_warning(_("<%s> already exists. File not copied."), to); continue; } if (G_legal_filename(to) < 0) { G_warning(_("<%s> is an illegal file name"), to); continue; } if (M_do_copy(n, from, mapset, to) == 1) { result = EXIT_FAILURE; } G_remove_misc("cell_misc", "reclassed_to", to); } } exit(result); }