GRASS 8 Programmer's Manual 8.6.0dev(2026)-6050dcdd58
Loading...
Searching...
No Matches
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 */
37void 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 hist
60 * \return int
61 */
62int Rast3d_read_history(const char *name, const char *mapset,
63 struct History *hist)
64{
65 FILE *fp;
66
67 G_zero(hist, sizeof(struct History));
68
70 mapset);
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 * \brief write raster3d History file
83 *
84 * This routine writes the History file for the raster3d file
85 * <b>name</b> in the current mapset from the <b>History</b> structure.
86 * A diagnostic message is printed and -1 is returned if there is an error
87 * writing the History file. Otherwise, 0 is returned.
88 * <b>Note.</b> The <b>history</b> structure should first be initialized
89 * using <i>Rast_short_history.</i>
90 *
91 * \param name
92 * \param history
93 * \return int
94 */
95int Rast3d_write_history(const char *name, struct History *hist)
96/* This function is adapted from Rast_write_history */
97{
98 FILE *fp =
100 if (!fp)
101 return -1;
102
103 Rast__write_history(hist, fp);
104 return 0;
105}
#define NULL
Definition ccmath.h:32
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
FILE * G_fopen_old_misc(const char *, const char *, const char *, const char *)
open a database misc file for reading
Definition open_misc.c:210
FILE * G_fopen_new_misc(const char *, const char *, const char *)
open a new database misc file
Definition open_misc.c:183
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