GRASS 8 Programmer's Manual  8.5.0dev(2025)-c070206eb1
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 int I_get_target(const char *group, char *location, char *mapset)
22 {
23  FILE *fd;
24  int ok;
25 
26  *location = *mapset = 0;
28  fd = I_fopen_group_file_old(group, "TARGET");
30  if (fd == NULL)
31  return 0;
32 
33  ok = (fscanf(fd, "%s %s", location, mapset) == 2);
34  fclose(fd);
35  if (!ok) {
36  *location = *mapset = 0;
37  G_warning(_("Unable to read target file for group [%s]"), group);
38  }
39 
40  return ok;
41 }
42 
43 /*!
44  * \brief write target information
45  *
46  * Writes the target <b>location</b> and <b>mapset</b> to
47  * the TARGET file for the specified <b>group.</b> Returns 1 if successful; 0
48  * otherwise (but no error messages are printed).
49  * This routine is used by <i>i.target</i> and probably should not be used by
50  * other programs.
51  * <b>Note.</b> This routine does <b>not</b> validate the target
52  * information.
53  *
54  * \param group
55  * \param location
56  * \param mapset
57  * \return int
58  */
59 int I_put_target(const char *group, const char *location, const char *mapset)
60 {
61  FILE *fd;
62 
63  fd = I_fopen_group_file_new(group, "TARGET");
64  if (fd == NULL)
65  return 0;
66 
67  fprintf(fd, "%s\n%s\n", location, mapset);
68  fclose(fd);
69 
70  return 1;
71 }
#define NULL
Definition: ccmath.h:32
void G_warning(const char *,...) __attribute__((format(printf
void int G_suppress_warnings(int)
Suppress printing a warning message to stderr.
Definition: gis/error.c:222
FILE * I_fopen_group_file_new(const char *, const char *)
Definition: fopen.c:69
FILE * I_fopen_group_file_old(const char *, const char *)
Open group file for reading.
Definition: fopen.c:102
#define _(str)
Definition: glocale.h:10
int I_get_target(const char *group, char *location, char *mapset)
read target information
Definition: target.c:21
int I_put_target(const char *group, const char *location, const char *mapset)
write target information
Definition: target.c:59