GRASS GIS 8 Programmer's Manual  8.5.0dev(2024)-36359e2344
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  * \brief write target information
46  *
47  * Writes the target <b>location</b> and <b>mapset</b> to
48  * the TARGET file for the specified <b>group.</b> Returns 1 if successful; 0
49  * otherwise (but no error messages are printed).
50  * This routine is used by <i>i.target</i> and probably should not be used by
51  * other programs.
52  * <b>Note.</b> This routine does <b>not</b> validate the target
53  * information.
54  *
55  * \param group
56  * \param location
57  * \param mapset
58  * \return int
59  */
60 
61 int I_put_target(const char *group, const char *location, const char *mapset)
62 {
63  FILE *fd;
64 
65  fd = I_fopen_group_file_new(group, "TARGET");
66  if (fd == NULL)
67  return 0;
68 
69  fprintf(fd, "%s\n%s\n", location, mapset);
70  fclose(fd);
71 
72  return 1;
73 }
#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:22
int I_put_target(const char *group, const char *location, const char *mapset)
write target information
Definition: target.c:61