GRASS GIS 7 Programmer's Manual  7.9.dev(2021)-e5379bbd7
fopen.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 /******************************************************
8 * I_fopen_group_file_new()
9 * I_fopen_group_file_append()
10 * I_fopen_group_file_old()
11 *
12 * fopen new group files in the current mapset
13 * fopen old group files anywhere
14 *******************************************************/
15 
16 FILE *fopen_group_file_old(const char *group, const char *mapset, const char *file)
17 {
18  FILE *fd;
19 
20  if (mapset == NULL || *mapset == 0)
21  mapset = G_mapset();
22 
23  /* find file first */
24  if (!I_find_group_file2(group, mapset, file)) {
25  G_warning(_("Unable to find file [%s] of group [%s in %s]"),
26  file, group, mapset);
27 
28  return ((FILE *) NULL);
29  }
30 
31  fd = G_fopen_old_misc("group", file, group, mapset);
32  if (!fd)
33  G_warning(_("Unable to open file [%s] of group [%s in %s]"),
34  file, group, mapset);
35 
36  return fd;
37 }
38 
39 
40 FILE *fopen_subgroup_file_old(const char *group,
41  const char *subgroup, const char *mapset,
42  const char *file)
43 {
44  FILE *fd;
45  char element[GNAME_MAX * 2];
46 
47  if (mapset == NULL || *mapset == 0)
48  mapset = G_mapset();
49 
50  /* find file first */
51  if (!I_find_subgroup_file2(group, subgroup, mapset, file)) {
52  G_warning(_("Unable to find file [%s] for subgroup [%s] of group [%s in %s]"),
53  file, subgroup, group, mapset);
54 
55  return ((FILE *) NULL);
56  }
57 
58  /* get subgroup element name */
59  sprintf(element, "subgroup/%s/%s", subgroup, file);
60 
61  fd = G_fopen_old_misc("group", element, group, mapset);
62  if (!fd)
63  G_warning(_("Unable to open file [%s] for subgroup [%s] of group [%s in %s]"),
64  file, subgroup, group, mapset);
65 
66  return fd;
67 }
68 
69 
70 FILE *I_fopen_group_file_new(const char *group, const char *file)
71 {
72  FILE *fd;
73 
74  fd = G_fopen_new_misc("group", file, group);
75  if (!fd)
76  G_warning(_("Unable to create file [%s] of group [%s in %s]"),
77  file, group, G_mapset());
78 
79  return fd;
80 }
81 
82 
83 FILE *I_fopen_group_file_append(const char *group, const char *file)
84 {
85  FILE *fd;
86 
87  fd = G_fopen_append_misc("group", file, group);
88  if (!fd)
89  G_warning(_("Unable to open file [%s] of group [%s in %s]"),
90  file, group, G_mapset());
91 
92  return fd;
93 }
94 
95 
96 /*!
97  * \brief Open group file for reading
98  *
99  * Internally uses G_fopen_old_misc
100  *
101  * \param group
102  * \param file
103  * \return FILE *
104  */
105 FILE *I_fopen_group_file_old(const char *group, const char *file)
106 {
107  return fopen_group_file_old(group, NULL, file);
108 }
109 
110 
111 /*!
112  * \brief Open group file for reading
113  *
114  * Internally uses G_fopen_old_misc
115  *
116  * \param group
117  * \param mapset
118  * \param file
119  * \return FILE *
120  */
121 FILE *I_fopen_group_file_old2(const char *group, const char *mapset, const char *file)
122 {
123  return fopen_group_file_old(group, mapset, file);
124 }
125 
126 
127 FILE *I_fopen_subgroup_file_new(const char *group,
128  const char *subgroup, const char *file)
129 {
130  FILE *fd;
131  char element[GNAME_MAX * 2];
132 
133  /* create subgroup directory */
134  sprintf(element, "%s/subgroup/%s", group, subgroup);
135  G__make_mapset_element_misc("group", element);
136 
137  /* get subgroup element name */
138  sprintf(element, "subgroup/%s/%s", subgroup, file);
139 
140  fd = G_fopen_new_misc("group", element, group);
141  if (!fd)
142  G_warning(_("Unable to create file [%s] for subgroup [%s] of group [%s in %s]"),
143  file, subgroup, group, G_mapset());
144 
145  return fd;
146 }
147 
148 
149 FILE *I_fopen_subgroup_file_append(const char *group,
150  const char *subgroup, const char *file)
151 {
152  FILE *fd;
153  char element[GNAME_MAX * 2];
154 
155  /* create subgroup directory */
156  sprintf(element, "%s/subgroup/%s", group, subgroup);
157  G__make_mapset_element_misc("group", element);
158 
159  /* get subgroup element name */
160  sprintf(element, "subgroup/%s/%s", subgroup, file);
161 
162  fd = G_fopen_append_misc("group", element, group);
163  if (!fd)
164  G_warning(_("Unable to open file [%s] for subgroup [%s] of group [%s in %s]"),
165  file, subgroup, group, G_mapset());
166 
167  return fd;
168 }
169 
170 
171 FILE *I_fopen_subgroup_file_old(const char *group,
172  const char *subgroup, const char *file)
173 {
174  return fopen_subgroup_file_old(group, subgroup, NULL, file);
175 }
176 
177 FILE *I_fopen_subgroup_file_old2(const char *group,
178  const char *subgroup, const char *mapset,
179  const char *file)
180 {
181  return fopen_subgroup_file_old(group, subgroup, mapset, file);
182 }
FILE * G_fopen_append_misc(const char *, const char *, const char *)
Definition: open_misc.c:222
FILE * I_fopen_subgroup_file_append(const char *group, const char *subgroup, const char *file)
Definition: fopen.c:149
FILE * fopen_group_file_old(const char *group, const char *mapset, const char *file)
Definition: fopen.c:16
FILE * I_fopen_group_file_append(const char *group, const char *file)
Definition: fopen.c:83
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
int I_find_subgroup_file2(const char *, const char *, const char *, const char *)
Searches for a subgroup file in the specified mapset.
Definition: imagery/find.c:160
int I_find_group_file2(const char *, const char *, const char *)
Searches for a group file in the specified mapset.
Definition: imagery/find.c:70
Definition: lidar.h:86
FILE * I_fopen_subgroup_file_old(const char *group, const char *subgroup, const char *file)
Definition: fopen.c:171
FILE * G_fopen_old_misc(const char *, const char *, const char *, const char *)
open a database file for reading
Definition: open_misc.c:210
FILE * I_fopen_subgroup_file_new(const char *group, const char *subgroup, const char *file)
Definition: fopen.c:127
FILE * I_fopen_group_file_old(const char *group, const char *file)
Open group file for reading.
Definition: fopen.c:105
FILE * I_fopen_group_file_new(const char *group, const char *file)
Definition: fopen.c:70
FILE * I_fopen_group_file_old2(const char *group, const char *mapset, const char *file)
Open group file for reading.
Definition: fopen.c:121
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:167
void G_warning(const char *,...) __attribute__((format(printf
#define file
FILE * I_fopen_subgroup_file_old2(const char *group, const char *subgroup, const char *mapset, const char *file)
Definition: fopen.c:177
#define _(str)
Definition: glocale.h:10
FILE * fopen_subgroup_file_old(const char *group, const char *subgroup, const char *mapset, const char *file)
Definition: fopen.c:40