r3_find.c 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /*
  2. * find_3dcell (cell)
  3. *
  4. * Find the a 3dcell in the current mapset
  5. **************************************************************/
  6. #include <string.h>
  7. #include <grass/gis.h>
  8. #include <grass/raster3d.h>
  9. int g3_find_dsp_file(const char *cell, const char *file, const char *mset)
  10. {
  11. char element[GNAME_MAX+10], name[GNAME_MAX], mapset[GMAPSET_MAX],
  12. tofind[GNAME_MAX];
  13. if (file == NULL || *file == 0)
  14. return 0;
  15. strcpy(tofind, file);
  16. if (G_name_is_fully_qualified(cell, name, mapset))
  17. sprintf(element, "grid3/%s/dsp", name);
  18. else
  19. sprintf(element, "grid3/%s/dsp", cell);
  20. return G_find_file(element, tofind, mset) != NULL;
  21. }
  22. /* return NULL on error: otherwise returns dspout */
  23. const char *check_get_any_dspname(const char *dspf, const char *g3f, const char *mset)
  24. {
  25. if (!G_find_raster3d(g3f, ""))
  26. G_fatal_error("3D raster map <%s> not found", g3f);
  27. if (mset) { /* otherwise must be reading only */
  28. if (g3_find_dsp_file(g3f, dspf, mset)) { /* already exists */
  29. /* the parser should handle the overwrite check */
  30. }
  31. }
  32. return dspf;
  33. }