GRASS GIS 7 Programmer's Manual  7.9.dev(2021)-e5379bbd7
d/history.c
Go to the documentation of this file.
1 
2 /**********************************************************************
3  *
4  * Rast3d_read_history (name, mapset, hist)
5  * char *name name of map
6  * char *mapset mapset that map belongs to
7  * struct History *hist structure to hold history info
8  *
9  * Reads the history information associated with map layer "map"
10  * in mapset "mapset" into the structure "hist".
11  *
12  * returns: 0 if successful
13  * -1 on fail
14  *
15  * note: a warning message is printed if the file is incorrect
16  *
17  **********************************************************************
18  *
19  * Rast3d_write_history (name, hist)
20  * char *name name of map
21  * struct History *hist structure holding history info
22  *
23  * Writes the history information associated with map layer "map"
24  * into current from the structure "hist".
25  *
26  * returns: 0 if successful
27  * -1 on fail
28  **********************************************************************/
29 
30 #include <string.h>
31 #include <stdio.h>
32 #include <stdlib.h>
33 #include <grass/glocale.h>
34 #include "raster3d_intern.h"
35 #include <grass/raster.h>
36 
37 /*simple error message */
38 void SimpleErrorMessage(FILE * fd, const char *name, const char *mapset)
39 {
40  if (fd != NULL)
41  fclose(fd);
42 
43  G_warning(_("can't get history information for [%s] in mapset [%s]"),
44  name, mapset);
45  return;
46 }
47 
48 /*!
49  * \brief read raster3d History file
50  *
51  * This routine reads the History file for
52  * the raster3d file <b>name</b> in <b>mapset</b> into the <b>History</b>
53  * structure.
54  * A diagnostic message is printed and -1 is returned if there is an error
55  * reading the History file. Otherwise, 0 is returned.
56  * A warning message is printed if the file is incorrect.
57  *
58  * \param name
59  * \param mapset
60  * \param history
61  * \return int
62  */
63 
64 int Rast3d_read_history(const char *name, const char *mapset, struct History *hist)
65 {
66  FILE *fp;
67 
68  G_zero(hist, sizeof(struct History));
69 
71  if (!fp)
72  return -2;
73 
74  if (Rast__read_history(hist, fp) == 0)
75  return 0;
76 
77  SimpleErrorMessage(fp, name, mapset);
78  return -1;
79 }
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 {
101  if (!fp)
102  return -1;
103 
104  Rast__write_history(hist, fp);
105  return 0;
106 }
int Rast__read_history(struct History *, FILE *)
Definition: history.c:59
void SimpleErrorMessage(FILE *fd, const char *name, const char *mapset)
Definition: d/history.c:38
#define NULL
Definition: ccmath.h:32
void Rast__write_history(struct History *, FILE *)
Definition: history.c:128
FILE * G_fopen_old_misc(const char *, const char *, const char *, const char *)
open a database file for reading
Definition: open_misc.c:210
int Rast3d_write_history(const char *name, struct History *hist)
write raster3d History file
Definition: d/history.c:97
Raster history info (metadata)
Definition: raster.h:180
#define RASTER3D_DIRECTORY
Definition: raster3d.h:31
FILE * G_fopen_new_misc(const char *, const char *, const char *)
open a new database file
Definition: open_misc.c:182
void G_zero(void *, int)
Zero out a buffer, buf, of length i.
Definition: gis/zero.c:23
void G_warning(const char *,...) __attribute__((format(printf
#define RASTER3D_HISTORY_ELEMENT
Definition: raster3d.h:36
#define _(str)
Definition: glocale.h:10
int Rast3d_read_history(const char *name, const char *mapset, struct History *hist)
read raster3d History file
Definition: d/history.c:64
const char * name
Definition: named_colr.c:7