GRASS GIS 7 Programmer's Manual  7.9.dev(2021)-515095365
sigsetfile.c
Go to the documentation of this file.
1 /*!
2  \file lib/imagery/sigsetfile.c
3 
4  \brief Imagery Library - Signature file functions (statistics for i.smap)
5 
6  (C) 2001-2011, 2013 by the GRASS Development Team
7 
8  This program is free software under the GNU General Public License
9  (>=v2). Read the file COPYING that comes with GRASS for details.
10 
11  \author USA CERL
12 */
13 
14 #include <string.h>
15 
16 #include <grass/gis.h>
17 #include <grass/imagery.h>
18 #include <grass/glocale.h>
19 
20 /*!
21  \brief Create new signiture file in given group/subgroup
22 
23  Note: Prints warning on error and returns NULL.
24 
25  \param group name of group
26  \param subgroup name of subgroup
27  \param name name of signiture file
28 
29  \return pointer to FILE
30  \return NULL on error
31 */
32 FILE *I_fopen_sigset_file_new(const char *group, const char *subgroup,
33  const char *name)
34 {
35  char element[GPATH_MAX];
36  char group_name[GNAME_MAX], mapset[GMAPSET_MAX];
37  FILE *fd;
38 
39  if (G_name_is_fully_qualified(group, group_name, mapset)) {
40  if (strcmp(mapset, G_mapset()) != 0)
41  G_warning(_("Unable to create signature file <%s> for subgroup <%s> "
42  "of group <%s> - <%s> is not current mapset"),
43  name, subgroup, group, mapset);
44  }
45  else {
46  strcpy(group_name, group);
47  }
48 
49  /* create sigset directory */
50  sprintf(element, "%s/subgroup/%s/sigset", group_name, subgroup);
51  G__make_mapset_element_misc("group", element);
52 
53  sprintf(element, "subgroup/%s/sigset/%s", subgroup, name);
54 
55  fd = G_fopen_new_misc("group", element, group_name);
56  if (fd == NULL)
57  G_warning(_("Unable to create signature file <%s> for subgroup <%s> "
58  "of group <%s>"),
59  name, subgroup, group);
60 
61  return fd;
62 }
63 
64 /*!
65  \brief Open existing signiture file
66 
67  \param group name of group (may be fully qualified)
68  \param subgroup name of subgroup
69  \param name name of signiture file
70 
71  \return pointer to FILE*
72  \return NULL on error
73 */
74 FILE *I_fopen_sigset_file_old(const char *group, const char *subgroup,
75  const char *name)
76 {
77  char element[GPATH_MAX];
78  char group_name[GNAME_MAX], group_mapset[GMAPSET_MAX];
79  FILE *fd;
80 
81  G_unqualified_name(group, NULL, group_name, group_mapset);
82  sprintf(element, "subgroup/%s/sigset/%s", subgroup, name);
83 
84  fd = G_fopen_old_misc("group", element, group_name, group_mapset);
85 
86  return fd;
87 }
#define GMAPSET_MAX
Definition: gis.h:165
FILE * I_fopen_sigset_file_old(const char *group, const char *subgroup, const char *name)
Open existing signiture file.
Definition: sigsetfile.c:74
int G_unqualified_name(const char *, const char *, char *, char *)
Returns unqualified map name (without @ mapset)
Definition: nme_in_mps.c:134
int G__make_mapset_element_misc(const char *, const char *)
Create misc element in the current mapset.
Definition: mapset_msc.c:112
#define NULL
Definition: ccmath.h:32
Definition: lidar.h:89
FILE * G_fopen_old_misc(const char *, const char *, const char *, const char *)
open a database file for reading
Definition: open_misc.c:210
#define GPATH_MAX
Definition: gis.h:167
FILE * G_fopen_new_misc(const char *, const char *, const char *)
open a new database file
Definition: open_misc.c:182
const char * G_mapset(void)
Get current mapset name.
Definition: gis/mapset.c:33
#define GNAME_MAX
Definition: gis.h:164
void G_warning(const char *,...) __attribute__((format(printf
FILE * I_fopen_sigset_file_new(const char *group, const char *subgroup, const char *name)
Create new signiture file in given group/subgroup.
Definition: sigsetfile.c:32
#define _(str)
Definition: glocale.h:10
const char * name
Definition: named_colr.c:7
int G_name_is_fully_qualified(const char *, char *, char *)
Check if map name is fully qualified (map @ mapset)
Definition: nme_in_mps.c:36