GRASS Programmer's Manual  6.4.2(2012)
fopen.c
Go to the documentation of this file.
00001 #include <stdio.h>
00002 #include <grass/gis.h>
00003 #include <grass/imagery.h>
00004 #include <grass/glocale.h>
00005 
00006 
00007 /******************************************************
00008 * I_fopen_group_file_new()
00009 * I_fopen_group_file_append()
00010 * I_fopen_group_file_old()
00011 *
00012 * fopen new group files in the current mapset
00013 * fopen old group files anywhere
00014 *******************************************************/
00015 
00016 
00017 FILE *I_fopen_group_file_new(const char *group, const char *file)
00018 {
00019     FILE *fd;
00020 
00021     fd = G_fopen_new_misc("group", file, group);
00022     if (!fd)
00023         G_warning(_("Unable to create file [%s] of group [%s in %s]"),
00024                   file, group, G_mapset());
00025 
00026     return fd;
00027 }
00028 
00029 
00030 FILE *I_fopen_group_file_append(const char *group, const char *file)
00031 {
00032     FILE *fd;
00033 
00034     fd = G_fopen_append_misc("group", file, group);
00035     if (!fd)
00036         G_warning(_("Unable to open file [%s] of group [%s in %s]"),
00037                   file, group, G_mapset());
00038 
00039     return fd;
00040 }
00041 
00042 
00043 FILE *I_fopen_group_file_old(const char *group, const char *file)
00044 {
00045     FILE *fd;
00046 
00047     /* find file first */
00048     if (!I_find_group_file(group, file)) {
00049         G_warning(_("Unable to find file [%s] of group [%s in %s]"),
00050                   file, group, G_mapset());
00051 
00052         return ((FILE *) NULL);
00053     }
00054 
00055     fd = G_fopen_old_misc("group", file, group, G_mapset());
00056     if (!fd)
00057         G_warning(_("Unable to open file [%s] of group [%s in %s]"),
00058                   file, group, G_mapset());
00059 
00060     return fd;
00061 }
00062 
00063 
00064 FILE *I_fopen_subgroup_file_new(const char *group,
00065                                 const char *subgroup, const char *file)
00066 {
00067     FILE *fd;
00068     char element[GNAME_MAX * 2];
00069 
00070     /* create subgroup directory */
00071     sprintf(element, "%s/subgroup/%s", group, subgroup);
00072     G__make_mapset_element_misc("group", element);
00073 
00074     /* get subgroup element name */
00075     sprintf(element, "subgroup/%s/%s", subgroup, file);
00076 
00077     fd = G_fopen_new_misc("group", element, group);
00078     if (!fd)
00079         G_warning(_("Unable to create file [%s] for subgroup [%s] of group [%s in %s]"),
00080                   file, subgroup, group, G_mapset());
00081 
00082     return fd;
00083 }
00084 
00085 
00086 FILE *I_fopen_subgroup_file_append(const char *group,
00087                                    const char *subgroup, const char *file)
00088 {
00089     FILE *fd;
00090     char element[GNAME_MAX * 2];
00091 
00092     /* create subgroup directory */
00093     sprintf(element, "%s/subgroup/%s", group, subgroup);
00094     G__make_mapset_element_misc("group", element);
00095 
00096     /* get subgroup element name */
00097     sprintf(element, "subgroup/%s/%s", subgroup, file);
00098 
00099     fd = G_fopen_append_misc("group", element, group);
00100     if (!fd)
00101         G_warning(_("Unable to open file [%s] for subgroup [%s] of group [%s in %s]"),
00102                   file, subgroup, group, G_mapset());
00103 
00104     return fd;
00105 }
00106 
00107 
00108 FILE *I_fopen_subgroup_file_old(const char *group,
00109                                 const char *subgroup, const char *file)
00110 {
00111     FILE *fd;
00112     char element[GNAME_MAX * 2];
00113 
00114     /* find file first */
00115     if (!I_find_subgroup_file(group, subgroup, file)) {
00116         G_warning(_("Unable to find file [%s] for subgroup [%s] of group [%s in %s]"),
00117                   file, subgroup, group, G_mapset());
00118 
00119         return ((FILE *) NULL);
00120     }
00121 
00122     /* get subgroup element name */
00123     sprintf(element, "subgroup/%s/%s", subgroup, file);
00124 
00125     fd = G_fopen_old_misc("group", element, group, G_mapset());
00126     if (!fd)
00127         G_warning(_("Unable to open file [%s] for subgroup [%s] of group [%s in %s]"),
00128                   file, subgroup, group, G_mapset());
00129 
00130     return fd;
00131 }
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines