GRASS GIS 8 Programmer's Manual  8.2.2dev(2023)-3d2c704037
target.c
Go to the documentation of this file.
1 #include <stdio.h>
2 #include <grass/gis.h>
3 #include <grass/imagery.h>
4 #include <grass/glocale.h>
5 
6 /*!
7  * \brief read target information
8  *
9  * Reads the target <b>location</b> and <b>mapset</b>
10  * from the TARGET file for the specified group. Returns 1 if successful; 0
11  * otherwise (and prints a diagnostic error). This routine is used by
12  * <i>g.gui.gcp</i> and <i>i.rectify</i> and probably should not be used by
13  * other programs.
14  * <b>Note.</b> This routine does <b>not</b> validate the target information.
15  *
16  * \param group
17  * \param location
18  * \param mapset
19  * \return int
20  */
21 
22 int I_get_target(const char *group, char *location, char *mapset)
23 {
24  FILE *fd;
25  int ok;
26 
27  *location = *mapset = 0;
29  fd = I_fopen_group_file_old(group, "TARGET");
31  if (fd == NULL)
32  return 0;
33 
34  ok = (fscanf(fd, "%s %s", location, mapset) == 2);
35  fclose(fd);
36  if (!ok) {
37  *location = *mapset = 0;
38  G_warning(_("Unable to read target file for group [%s]"), group);
39  }
40 
41  return ok;
42 }
43 
44 
45 /*!
46  * \brief write target information
47  *
48  * Writes the target <b>location</b> and <b>mapset</b> to
49  * the TARGET file for the specified <b>group.</b> Returns 1 if successful; 0
50  * otherwise (but no error messages are printed).
51  * This routine is used by <i>i.target</i> and probably should not be used by
52  * other programs.
53  * <b>Note.</b> This routine does <b>not</b> validate the target
54  * information.
55  *
56  * \param group
57  * \param location
58  * \param mapset
59  * \return int
60  */
61 
62 int I_put_target(const char *group, const char *location, const char *mapset)
63 {
64  FILE *fd;
65 
66  fd = I_fopen_group_file_new(group, "TARGET");
67  if (fd == NULL)
68  return 0;
69 
70  fprintf(fd, "%s\n%s\n", location, mapset);
71  fclose(fd);
72 
73  return 1;
74 }
FILE * I_fopen_group_file_old(const char *, const char *)
Open group file for reading.
Definition: fopen.c:105
#define NULL
Definition: ccmath.h:32
int I_put_target(const char *group, const char *location, const char *mapset)
write target information
Definition: target.c:62
int I_get_target(const char *group, char *location, char *mapset)
read target information
Definition: target.c:22
void int G_suppress_warnings(int)
Suppress printing a warning message to stderr.
Definition: gis/error.c:223
FILE * I_fopen_group_file_new(const char *, const char *)
Definition: fopen.c:70
void G_warning(const char *,...) __attribute__((format(printf
#define _(str)
Definition: glocale.h:10