GRASS Programmer's Manual  6.5.svn(2014)-r66266
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
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 
17 FILE *I_fopen_group_file_new(const char *group, const char *file)
18 {
19  FILE *fd;
20 
21  fd = G_fopen_new_misc("group", file, group);
22  if (!fd)
23  G_warning(_("Unable to create file [%s] of group [%s in %s]"),
24  file, group, G_mapset());
25 
26  return fd;
27 }
28 
29 
30 FILE *I_fopen_group_file_append(const char *group, const char *file)
31 {
32  FILE *fd;
33 
34  fd = G_fopen_append_misc("group", file, group);
35  if (!fd)
36  G_warning(_("Unable to open file [%s] of group [%s in %s]"),
37  file, group, G_mapset());
38 
39  return fd;
40 }
41 
42 
43 FILE *I_fopen_group_file_old(const char *group, const char *file)
44 {
45  FILE *fd;
46 
47  /* find file first */
48  if (!I_find_group_file(group, file)) {
49  G_warning(_("Unable to find file [%s] of group [%s in %s]"),
50  file, group, G_mapset());
51 
52  return ((FILE *) NULL);
53  }
54 
55  fd = G_fopen_old_misc("group", file, group, G_mapset());
56  if (!fd)
57  G_warning(_("Unable to open file [%s] of group [%s in %s]"),
58  file, group, G_mapset());
59 
60  return fd;
61 }
62 
63 
64 FILE *I_fopen_subgroup_file_new(const char *group,
65  const char *subgroup, const char *file)
66 {
67  FILE *fd;
68  char element[GNAME_MAX * 2];
69 
70  /* create subgroup directory */
71  sprintf(element, "%s/subgroup/%s", group, subgroup);
72  G__make_mapset_element_misc("group", element);
73 
74  /* get subgroup element name */
75  sprintf(element, "subgroup/%s/%s", subgroup, file);
76 
77  fd = G_fopen_new_misc("group", element, group);
78  if (!fd)
79  G_warning(_("Unable to create file [%s] for subgroup [%s] of group [%s in %s]"),
80  file, subgroup, group, G_mapset());
81 
82  return fd;
83 }
84 
85 
86 FILE *I_fopen_subgroup_file_append(const char *group,
87  const char *subgroup, const char *file)
88 {
89  FILE *fd;
90  char element[GNAME_MAX * 2];
91 
92  /* create subgroup directory */
93  sprintf(element, "%s/subgroup/%s", group, subgroup);
94  G__make_mapset_element_misc("group", element);
95 
96  /* get subgroup element name */
97  sprintf(element, "subgroup/%s/%s", subgroup, file);
98 
99  fd = G_fopen_append_misc("group", element, group);
100  if (!fd)
101  G_warning(_("Unable to open file [%s] for subgroup [%s] of group [%s in %s]"),
102  file, subgroup, group, G_mapset());
103 
104  return fd;
105 }
106 
107 
108 FILE *I_fopen_subgroup_file_old(const char *group,
109  const char *subgroup, const char *file)
110 {
111  FILE *fd;
112  char element[GNAME_MAX * 2];
113 
114  /* find file first */
115  if (!I_find_subgroup_file(group, subgroup, file)) {
116  G_warning(_("Unable to find file [%s] for subgroup [%s] of group [%s in %s]"),
117  file, subgroup, group, G_mapset());
118 
119  return ((FILE *) NULL);
120  }
121 
122  /* get subgroup element name */
123  sprintf(element, "subgroup/%s/%s", subgroup, file);
124 
125  fd = G_fopen_old_misc("group", element, group, G_mapset());
126  if (!fd)
127  G_warning(_("Unable to open file [%s] for subgroup [%s] of group [%s in %s]"),
128  file, subgroup, group, G_mapset());
129 
130  return fd;
131 }
char * G_mapset(void)
current mapset name
Definition: mapset.c:31
sprintf(buf2,"%s", G3D_CATS_ELEMENT)
FILE * I_fopen_subgroup_file_append(const char *group, const char *subgroup, const char *file)
Definition: fopen.c:86
FILE * fd
Definition: g3dcolor.c:368
FILE * I_fopen_group_file_append(const char *group, const char *file)
Definition: fopen.c:30
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:200
FILE * G_fopen_append_misc(const char *dir, const char *element, const char *name)
Definition: open_misc.c:212
FILE * I_fopen_subgroup_file_old(const char *group, const char *subgroup, const char *file)
Definition: fopen.c:108
FILE * I_fopen_subgroup_file_new(const char *group, const char *subgroup, const char *file)
Definition: fopen.c:64
FILE * I_fopen_group_file_old(const char *group, const char *file)
Definition: fopen.c:43
FILE * I_fopen_group_file_new(const char *group, const char *file)
Definition: fopen.c:17
int I_find_group_file(const char *group, const char *file)
Definition: imagery/find.c:29
int G__make_mapset_element_misc(const char *dir, const char *name)
Create misc element in the current mapset.
Definition: mapset_msc.c:82
return NULL
Definition: dbfopen.c:1394
G_warning("category support for [%s] in mapset [%s] %s", name, mapset, type)
#define file
FILE * G_fopen_new_misc(const char *dir, const char *element, const char *name)
open a new database file
Definition: open_misc.c:172
int I_find_subgroup_file(const char *group, const char *subgroup, const char *file)
Definition: imagery/find.c:53