close_nat.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*!
  2. \file lib/vector/Vlib/close_nat.c
  3. \brief Vector library - Close map (native format)
  4. Higher level functions for reading/writing/manipulating vectors.
  5. (C) 2001-2009, 2013 by the GRASS Development Team
  6. This program is free software under the GNU General Public License
  7. (>=v2). Read the file COPYING that comes with GRASS for details.
  8. \author Original author CERL, probably Dave Gerdes or Mike Higgins.
  9. \author Update to GRASS 5.7 Radim Blazek and David D. Gray.
  10. */
  11. #include <stdlib.h>
  12. #include <grass/vector.h>
  13. #include "local_proto.h"
  14. /*!
  15. \brief Close vector map
  16. \param Map vector map to be closed
  17. \return 0 on success
  18. \return non-zero on error
  19. */
  20. int V1_close_nat(struct Map_info *Map)
  21. {
  22. struct Coor_info CInfo;
  23. G_debug(1, "V1_close_nat(): name = %s mapset= %s", Map->name,
  24. Map->mapset);
  25. if (!VECT_OPEN(Map))
  26. return 1;
  27. if (Map->mode == GV_MODE_WRITE || Map->mode == GV_MODE_RW) {
  28. Vect_coor_info(Map, &CInfo);
  29. Map->head.size = CInfo.size;
  30. dig__write_head(Map);
  31. Vect__write_head(Map);
  32. Vect_write_dblinks(Map);
  33. }
  34. /* close coor file */
  35. fclose(Map->dig_fp.file);
  36. dig_file_free(&(Map->dig_fp));
  37. /* delete temporary map ? */
  38. if (Map->temporary) {
  39. if (getenv("GRASS_VECTOR_TEMPORARY") == NULL) {
  40. G_debug(1, "V1_close_nat(): temporary map <%s> TO BE DELETED", Map->name);
  41. Vect__delete(Map->name, TRUE);
  42. }
  43. else {
  44. G_debug(1, "V1_close_nat(): temporary map <%s> IS NOT DELETED", Map->name);
  45. }
  46. }
  47. return 0;
  48. }