history.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /**********************************************************************
  2. *
  3. * Rast3d_read_history (name, mapset, hist)
  4. * char *name name of map
  5. * char *mapset mapset that map belongs to
  6. * struct History *hist structure to hold history info
  7. *
  8. * Reads the history information associated with map layer "map"
  9. * in mapset "mapset" into the structure "hist".
  10. *
  11. * returns: 0 if successful
  12. * -1 on fail
  13. *
  14. * note: a warning message is printed if the file is incorrect
  15. *
  16. **********************************************************************
  17. *
  18. * Rast3d_write_history (name, hist)
  19. * char *name name of map
  20. * struct History *hist structure holding history info
  21. *
  22. * Writes the history information associated with map layer "map"
  23. * into current from the structure "hist".
  24. *
  25. * returns: 0 if successful
  26. * -1 on fail
  27. **********************************************************************/
  28. #include <string.h>
  29. #include <stdio.h>
  30. #include <stdlib.h>
  31. #include <grass/glocale.h>
  32. #include "raster3d_intern.h"
  33. #include <grass/raster.h>
  34. /*simple error message */
  35. void SimpleErrorMessage(FILE * fd, const char *name, const char *mapset)
  36. {
  37. if (fd != NULL)
  38. fclose(fd);
  39. G_warning(_("can't get history information for [%s] in mapset [%s]"),
  40. name, mapset);
  41. return;
  42. }
  43. /*!
  44. * \brief read raster3d History file
  45. *
  46. * This routine reads the History file for
  47. * the raster3d file <b>name</b> in <b>mapset</b> into the <b>History</b>
  48. * structure.
  49. * A diagnostic message is printed and -1 is returned if there is an error
  50. * reading the History file. Otherwise, 0 is returned.
  51. * A warning message is printed if the file is incorrect.
  52. *
  53. * \param name
  54. * \param mapset
  55. * \param history
  56. * \return int
  57. */
  58. int Rast3d_read_history(const char *name, const char *mapset, struct History *hist)
  59. {
  60. FILE *fp;
  61. G_zero(hist, sizeof(struct History));
  62. fp = G_fopen_old_misc(RASTER3D_DIRECTORY, RASTER3D_HISTORY_ELEMENT, name, mapset);
  63. if (!fp)
  64. return -2;
  65. if (Rast__read_history(hist, fp) == 0)
  66. return 0;
  67. SimpleErrorMessage(fp, name, mapset);
  68. return -1;
  69. }
  70. /*!
  71. * \brief write raster3d History file
  72. *
  73. * This routine writes the History file for the raster3d file
  74. * <b>name</b> in the current mapset from the <b>History</b> structure.
  75. * A diagnostic message is printed and -1 is returned if there is an error
  76. * writing the History file. Otherwise, 0 is returned.
  77. * <b>Note.</b> The <b>history</b> structure should first be initialized
  78. * using <i>Rast_short_history.</i>
  79. *
  80. * \param name
  81. * \param history
  82. * \return int
  83. */
  84. int Rast3d_write_history(const char *name, struct History *hist)
  85. /* This function is adapted from Rast_write_history */
  86. {
  87. FILE *fp = G_fopen_new_misc(RASTER3D_DIRECTORY, RASTER3D_HISTORY_ELEMENT, name);
  88. if (!fp)
  89. return -1;
  90. Rast__write_history(hist, fp);
  91. return 0;
  92. }