r3_find.c 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*
  2. * find_3dcell (cell)
  3. *
  4. * Find the a 3dcell in the current mapset
  5. **************************************************************/
  6. #include <grass/gis.h>
  7. #include <grass/raster3d.h>
  8. int g3_find_dsp_file(cell, file, mset)
  9. char *cell, *mset;
  10. char *file;
  11. {
  12. char element[100], name[GNAME_MAX], mapset[GMAPSET_MAX],
  13. tofind[GNAME_MAX];
  14. if (file == NULL || *file == 0)
  15. return 0;
  16. strcpy(tofind, file);
  17. if (G_name_is_fully_qualified(cell, name, mapset))
  18. sprintf(element, "grid3/%s/dsp", name);
  19. else
  20. sprintf(element, "grid3/%s/dsp", cell);
  21. return G_find_file(element, tofind, mset) != NULL;
  22. }
  23. /* return NULL on error: otherwise returns dspout */
  24. char *check_get_any_dspname(dspf, g3f, mset)
  25. char *dspf, *g3f, *mset;
  26. {
  27. char element[200], question[200];
  28. static char dspout[200];
  29. if (!G_find_raster3d(g3f, "")) {
  30. fprintf(stderr, "3D raster map <%s> not found", g3f);
  31. return (NULL);
  32. }
  33. if (mset) { /* otherwise must be reading only */
  34. if (g3_find_dsp_file(g3f, dspf, mset)) { /* already exists */
  35. sprintf(question, "\n** %s exists. ok to overwrite? ", dspf);
  36. if (!G_yes(question, 0)) {
  37. if (NULL == G_ask_any("", dspout, element, "display", 1))
  38. return (NULL);
  39. return (dspout);
  40. }
  41. /* or else just print a warning & use it as is */
  42. }
  43. }
  44. strcpy(dspout, dspf);
  45. return (dspout);
  46. }