GRASS GIS 7 Programmer's Manual  7.5.svn(2018)-r72729
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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:149
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 *name, const char *mapset, char *xname, char *xmapset)
Returns unqualified map name (without @ mapset)
Definition: nme_in_mps.c:134
FILE * G_fopen_old_misc(const char *dir, const char *element, const char *name, const char *mapset)
open a database file for reading
Definition: open_misc.c:210
#define NULL
Definition: ccmath.h:32
fd
Definition: d/range.c:69
Definition: lidar.h:89
#define GPATH_MAX
Definition: gis.h:151
int G__make_mapset_element_misc(const char *dir, const char *name)
Create misc element in the current mapset.
Definition: mapset_msc.c:112
#define GNAME_MAX
Definition: gis.h:148
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
FILE * G_fopen_new_misc(const char *dir, const char *element, const char *name)
open a new database file
Definition: open_misc.c:182
#define _(str)
Definition: glocale.h:13
int G_name_is_fully_qualified(const char *fullname, char *name, char *mapset)
Check if map name is fully qualified (map @ mapset)
Definition: nme_in_mps.c:36
const char * G_mapset(void)
Get current mapset name.
Definition: gis/mapset.c:33
const char * name
Definition: named_colr.c:7
void G_warning(const char *msg,...)
Print a warning message to stderr.
Definition: gis/error.c:204