GRASS GIS 8 Programmer's Manual  8.4.0dev(2024)-f8115df121
raster3d/history.c
Go to the documentation of this file.
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 
29 #include <string.h>
30 #include <stdio.h>
31 #include <stdlib.h>
32 #include <grass/glocale.h>
33 #include "raster3d_intern.h"
34 #include <grass/raster.h>
35 
36 /*simple error message */
37 void SimpleErrorMessage(FILE *fd, const char *name, const char *mapset)
38 {
39  if (fd != NULL)
40  fclose(fd);
41 
42  G_warning(_("can't get history information for [%s] in mapset [%s]"), name,
43  mapset);
44  return;
45 }
46 
47 /*!
48  * \brief read raster3d History file
49  *
50  * This routine reads the History file for
51  * the raster3d file <b>name</b> in <b>mapset</b> into the <b>History</b>
52  * structure.
53  * A diagnostic message is printed and -1 is returned if there is an error
54  * reading the History file. Otherwise, 0 is returned.
55  * A warning message is printed if the file is incorrect.
56  *
57  * \param name
58  * \param mapset
59  * \param history
60  * \return int
61  */
62 
63 int Rast3d_read_history(const char *name, const char *mapset,
64  struct History *hist)
65 {
66  FILE *fp;
67 
68  G_zero(hist, sizeof(struct History));
69 
71  mapset);
72  if (!fp)
73  return -2;
74 
75  if (Rast__read_history(hist, fp) == 0)
76  return 0;
77 
78  SimpleErrorMessage(fp, name, mapset);
79  return -1;
80 }
81 
82 /*!
83  * \brief write raster3d History file
84  *
85  * This routine writes the History file for the raster3d file
86  * <b>name</b> in the current mapset from the <b>History</b> structure.
87  * A diagnostic message is printed and -1 is returned if there is an error
88  * writing the History file. Otherwise, 0 is returned.
89  * <b>Note.</b> The <b>history</b> structure should first be initialized
90  * using <i>Rast_short_history.</i>
91  *
92  * \param name
93  * \param history
94  * \return int
95  */
96 
97 int Rast3d_write_history(const char *name, struct History *hist)
98 /* This function is adapted from Rast_write_history */
99 {
100  FILE *fp =
102  if (!fp)
103  return -1;
104 
105  Rast__write_history(hist, fp);
106  return 0;
107 }
#define NULL
Definition: ccmath.h:32
void G_zero(void *, int)
Zero out a buffer, buf, of length i.
Definition: gis/zero.c:23
FILE * G_fopen_old_misc(const char *, const char *, const char *, const char *)
open a database misc file for reading
Definition: open_misc.c:205
void G_warning(const char *,...) __attribute__((format(printf
FILE * G_fopen_new_misc(const char *, const char *, const char *)
open a new database misc file
Definition: open_misc.c:178
void Rast__write_history(struct History *, FILE *)
int Rast__read_history(struct History *, FILE *)
#define _(str)
Definition: glocale.h:10
const char * name
Definition: named_colr.c:6
void SimpleErrorMessage(FILE *fd, const char *name, const char *mapset)
int Rast3d_read_history(const char *name, const char *mapset, struct History *hist)
read raster3d History file
int Rast3d_write_history(const char *name, struct History *hist)
write raster3d History file
#define RASTER3D_DIRECTORY
Definition: raster3d.h:31
#define RASTER3D_HISTORY_ELEMENT
Definition: raster3d.h:36
Raster history info (metadata)
Definition: raster.h:172