[GRASS-SVN] r73632 - in grass/trunk: include/defs lib/imagery

svn_grass at osgeo.org svn_grass at osgeo.org
Wed Oct 31 04:48:02 PDT 2018


Author: marisn
Date: 2018-10-31 04:48:02 -0700 (Wed, 31 Oct 2018)
New Revision: 73632

Modified:
   grass/trunk/include/defs/imagery.h
   grass/trunk/lib/imagery/find.c
   grass/trunk/lib/imagery/fopen.c
   grass/trunk/lib/imagery/group.c
   grass/trunk/lib/imagery/list_subgp.c
   grass/trunk/lib/imagery/ref.c
Log:
Imagery: Add mapset aware functions to allow group file reading from other mapsets.


Modified: grass/trunk/include/defs/imagery.h
===================================================================
--- grass/trunk/include/defs/imagery.h	2018-10-31 11:07:34 UTC (rev 73631)
+++ grass/trunk/include/defs/imagery.h	2018-10-31 11:48:02 UTC (rev 73632)
@@ -18,9 +18,13 @@
 
 /* find.c */
 int I_find_group(const char *);
+int I_find_group2(const char *, const char *);
 int I_find_group_file(const char *, const char *);
+int I_find_group_file2(const char *, const char *, const char *);
 int I_find_subgroup(const char *, const char *);
+int I_find_subgroup2(const char *, const char *, const char *);
 int I_find_subgroup_file(const char *, const char *, const char *);
+int I_find_subgroup_file2(const char *, const char *, const char *, const char *);
 int I_find_signature_file(const char *, const char *, const char *, const char *);
 
 /* fopen.c */
@@ -27,9 +31,11 @@
 FILE *I_fopen_group_file_new(const char *, const char *);
 FILE *I_fopen_group_file_append(const char *, const char *);
 FILE *I_fopen_group_file_old(const char *, const char *);
+FILE *I_fopen_group_file_old2(const char *, const char *, const char *);
 FILE *I_fopen_subgroup_file_new(const char *, const char *, const char *);
 FILE *I_fopen_subgroup_file_append(const char *, const char *, const char *);
 FILE *I_fopen_subgroup_file_old(const char *, const char *, const char *);
+FILE *I_fopen_subgroup_file_old2(const char *, const char *, const char *, const char *);
 
 /* georef.c */
 int I_compute_georef_equations(struct Control_Points *, double *, double *,
@@ -48,7 +54,9 @@
 int I_get_subgroup(const char *, char *);
 int I_put_subgroup(const char *, const char *);
 int I_get_group_ref(const char *, struct Ref *);
+int I_get_group_ref2(const char *, const char *, struct Ref *);
 int I_get_subgroup_ref(const char *, const char *, struct Ref *);
+int I_get_subgroup_ref2(const char *, const char *, const char *, struct Ref *);
 int I_init_ref_color_nums(struct Ref *);
 int I_put_group_ref(const char *, const struct Ref *);
 int I_put_subgroup_ref(const char *, const char *, const struct Ref *);
@@ -94,6 +102,7 @@
 
 /* list_subgp.c */
 char ** I_list_subgroups(const char *, int *);
+char ** I_list_subgroups2(const char *, const char *, int *);
 int I_list_subgroup(const char *, const char *, const struct Ref *, FILE *);
 int I_list_subgroup_simple(const struct Ref *, FILE *);
 
@@ -109,8 +118,10 @@
 /* ref.c */
 FILE *I_fopen_group_ref_new(const char *);
 FILE *I_fopen_group_ref_old(const char *);
+FILE *I_fopen_group_ref_old2(const char *, const char *);
 FILE *I_fopen_subgroup_ref_new(const char *, const char *);
 FILE *I_fopen_subgroup_ref_old(const char *, const char *);
+FILE *I_fopen_subgroup_ref_old2(const char *, const char *, const char *);
 
 /* iscatt_structs.c */
 void I_sc_init_cats(struct scCats *, int, int);

Modified: grass/trunk/lib/imagery/find.c
===================================================================
--- grass/trunk/lib/imagery/find.c	2018-10-31 11:07:34 UTC (rev 73631)
+++ grass/trunk/lib/imagery/find.c	2018-10-31 11:48:02 UTC (rev 73632)
@@ -13,9 +13,10 @@
  *
  * Returns 1 if the
  * specified <b>group</b> exists in the current mapset; 0 otherwise.
+ * Use I_find_group2 to search in all or a specific mapset.
  *
  *  \param group
- *  \return int
+ *  \return int 1 if group was found, 0 otherwise
  */
 
 int I_find_group(const char *group)
@@ -26,6 +27,29 @@
     return G_find_file2("group", group, G_mapset()) != NULL;
 }
 
+/*!
+ * \brief Does the group exists?
+ *
+ *  Finds a group in specified mapset or any mapset if mapset is not set.
+ *  Internally uses G_find_file2().
+ *
+ *  \param group
+ *  \param mapset
+ *  \return int 1 if group was found, 0 otherwise
+ */
+
+int I_find_group2(const char *group, const char *mapset)
+{
+    return G_find_file2("group", group, mapset) != NULL;
+}
+
+/*!
+ * \brief Searches for a group file in the current mapset
+ * 
+ * \param group
+ * \param file
+ * \return int 1 if file was found, 0 otherwise
+ */
 int I_find_group_file(const char *group, const char *file)
 {
     if (!I_find_group(group))
@@ -36,6 +60,30 @@
     return G_find_file2_misc("group", file, group, G_mapset()) != NULL;
 }
 
+/*!
+ * \brief Searches for a group file in the specified mapset
+ * 
+ * \param group
+ * \param file
+ * \return int 1 if file was found, 0 otherwise
+ */
+int I_find_group_file2(const char *group, const char *mapset, const char *file)
+{
+    if (!I_find_group2(group, mapset))
+        return 0;
+    if (file == NULL || *file == 0)
+        return 0;
+
+    return G_find_file2_misc("group", file, group, mapset) != NULL;
+}
+
+/*!
+ * \brief Searches for a subgroup in the current mapset
+ * 
+ * \param group
+ * \param subgroup
+ * \return int 1 if subgroup was found, 0 otherwise
+ */
 int I_find_subgroup(const char *group, const char *subgroup)
 {
     char element[GNAME_MAX];
@@ -51,6 +99,37 @@
     return G_find_file2_misc("group", element, group, G_mapset()) != NULL;
 }
 
+/*!
+ * \brief Searches for a subgroup in specified mapset or any mapset if mapset is not set
+ * 
+ * \param group
+ * \param subgroup
+ * \param mapset
+ * \return int 1 if subrgoup was found, 0 otherwise
+ */
+int I_find_subgroup2(const char *group, const char *subgroup, const char *mapset)
+{
+    char element[GNAME_MAX];
+
+    if (!I_find_group2(group, mapset))
+        return 0;
+    if (subgroup == NULL || *subgroup == 0)
+        return 0;
+
+    sprintf(element, "subgroup%c%s", HOST_DIRSEP, subgroup);
+    G_debug(5, "I_find_subgroup2() element: %s", element);
+
+    return G_find_file2_misc("group", element, group, mapset) != NULL;
+}
+
+/*!
+ * \brief Searches for a subgroup file in the current mapset
+ * 
+ * \param group
+ * \param subgroup
+ * \param file
+ * \return int 1 if file was found, 0 otherwise
+ */
 int I_find_subgroup_file(const char *group, const char *subgroup,
                          const char *file)
 {
@@ -70,6 +149,33 @@
 }
 
 /*!
+ * \brief Searches for a subgroup file in the specified mapset
+ * 
+ * \param group
+ * \param subgroup
+ * \param mapset
+ * \param file
+ * \return int 1 if file was found, 0 otherwise
+ */
+int I_find_subgroup_file2(const char *group, const char *subgroup,
+                         const char *mapset, const char *file)
+{
+    char element[GNAME_MAX * 2];
+
+    if (!I_find_group2(group, mapset))
+        return 0;
+    if (subgroup == NULL || *subgroup == 0)
+        return 0;
+    if (file == NULL || *file == 0)
+        return 0;
+
+    sprintf(element, "subgroup%c%s%c%s", HOST_DIRSEP, subgroup, HOST_DIRSEP, file);
+    G_debug(5, "I_find_subgroup_file2() element: %s", element);
+
+    return G_find_file2_misc("group", element, group, mapset) != NULL;
+}
+
+/*!
  * \brief does signature file exists?
  *
  * Returns 1 if the

Modified: grass/trunk/lib/imagery/fopen.c
===================================================================
--- grass/trunk/lib/imagery/fopen.c	2018-10-31 11:07:34 UTC (rev 73631)
+++ grass/trunk/lib/imagery/fopen.c	2018-10-31 11:48:02 UTC (rev 73632)
@@ -13,7 +13,60 @@
 * fopen old group files anywhere
 *******************************************************/
 
+FILE *fopen_group_file_old(const char *group, const char *mapset, const char *file)
+{
+    FILE *fd;
+    
+    if (mapset == NULL || *mapset == 0)
+        mapset = G_mapset();
 
+    /* find file first */
+    if (!I_find_group_file2(group, mapset, file)) {
+	G_warning(_("Unable to find file [%s] of group [%s in %s]"),
+		  file, group, mapset);
+
+	return ((FILE *) NULL);
+    }
+
+    fd = G_fopen_old_misc("group", file, group, mapset);
+    if (!fd)
+	G_warning(_("Unable to open file [%s] of group [%s in %s]"),
+		  file, group, mapset);
+
+    return fd;
+}
+
+
+FILE *fopen_subgroup_file_old(const char *group,
+				const char *subgroup, const char *mapset,
+                const char *file)
+{
+    FILE *fd;
+    char element[GNAME_MAX * 2];
+    
+    if (mapset == NULL || *mapset == 0)
+        mapset = G_mapset();
+
+    /* find file first */
+    if (!I_find_subgroup_file2(group, subgroup, mapset, file)) {
+	G_warning(_("Unable to find file [%s] for subgroup [%s] of group [%s in %s]"),
+		  file, subgroup, group, mapset);
+
+	return ((FILE *) NULL);
+    }
+
+    /* get subgroup element name */
+    sprintf(element, "subgroup/%s/%s", subgroup, file);
+
+    fd = G_fopen_old_misc("group", element, group, mapset);
+    if (!fd)
+	G_warning(_("Unable to open file [%s] for subgroup [%s] of group [%s in %s]"),
+		  file, subgroup, group, mapset);
+
+    return fd;
+}
+
+
 FILE *I_fopen_group_file_new(const char *group, const char *file)
 {
     FILE *fd;
@@ -40,24 +93,34 @@
 }
 
 
+/*!
+ * \brief Open group file for reading
+ * 
+ * Internally uses G_fopen_old_misc
+ * 
+ * \param group
+ * \param file
+ * \return FILE *
+ */
 FILE *I_fopen_group_file_old(const char *group, const char *file)
 {
-    FILE *fd;
+    return fopen_group_file_old(group, NULL, file);
+}
 
-    /* find file first */
-    if (!I_find_group_file(group, file)) {
-	G_warning(_("Unable to find file [%s] of group [%s in %s]"),
-		  file, group, G_mapset());
 
-	return ((FILE *) NULL);
-    }
-
-    fd = G_fopen_old_misc("group", file, group, G_mapset());
-    if (!fd)
-	G_warning(_("Unable to open file [%s] of group [%s in %s]"),
-		  file, group, G_mapset());
-
-    return fd;
+/*!
+ * \brief Open group file for reading
+ * 
+ * Internally uses G_fopen_old_misc
+ * 
+ * \param group
+ * \param mapset
+ * \param file
+ * \return FILE *
+ */
+FILE *I_fopen_group_file_old2(const char *group, const char *mapset, const char *file)
+{
+    return fopen_group_file_old(group, mapset, file);
 }
 
 
@@ -108,24 +171,12 @@
 FILE *I_fopen_subgroup_file_old(const char *group,
 				const char *subgroup, const char *file)
 {
-    FILE *fd;
-    char element[GNAME_MAX * 2];
+    return fopen_subgroup_file_old(group, subgroup, NULL, file);
+}
 
-    /* find file first */
-    if (!I_find_subgroup_file(group, subgroup, file)) {
-	G_warning(_("Unable to find file [%s] for subgroup [%s] of group [%s in %s]"),
-		  file, subgroup, group, G_mapset());
-
-	return ((FILE *) NULL);
-    }
-
-    /* get subgroup element name */
-    sprintf(element, "subgroup/%s/%s", subgroup, file);
-
-    fd = G_fopen_old_misc("group", element, group, G_mapset());
-    if (!fd)
-	G_warning(_("Unable to open file [%s] for subgroup [%s] of group [%s in %s]"),
-		  file, subgroup, group, G_mapset());
-
-    return fd;
+FILE *I_fopen_subgroup_file_old2(const char *group,
+				const char *subgroup, const char *mapset,
+                const char *file)
+{
+    return fopen_subgroup_file_old(group, subgroup, mapset, file);
 }

Modified: grass/trunk/lib/imagery/group.c
===================================================================
--- grass/trunk/lib/imagery/group.c	2018-10-31 11:07:34 UTC (rev 73631)
+++ grass/trunk/lib/imagery/group.c	2018-10-31 11:48:02 UTC (rev 73632)
@@ -30,7 +30,7 @@
 #include <stdlib.h>
 #include <grass/imagery.h>
 
-static int get_ref(const char *, const char *, struct Ref *);
+static int get_ref(const char *, const char *, const char *, struct Ref *);
 static int set_color(const char *, const char *, const char *, struct Ref *);
 static int put_ref(const char *, const char *, const struct Ref *);
 
@@ -113,11 +113,30 @@
 
 int I_get_group_ref(const char *group, struct Ref *ref)
 {
-    return get_ref(group, "", ref);
+    return get_ref(group, "", NULL, ref);
 }
 
 
 /*!
+ * \brief read group REF file
+ *
+ * Reads the contents of the REF file for the specified <b>group</b> into
+ * the <b>ref</b> structure.
+ * Returns 1 if successful; 0 otherwise (but no error messages are printed).
+ *
+ *  \param group
+ *  \param mapset
+ *  \param ref
+ *  \return int
+ */
+
+int I_get_group_ref2(const char *group, const char *mapset, struct Ref *ref)
+{
+    return get_ref(group, "", mapset, ref);
+}
+
+
+/*!
  * \brief read subgroup REF file
  *
  * Reads the contents of the REF file for the
@@ -134,11 +153,34 @@
 int I_get_subgroup_ref(const char *group,
 		       const char *subgroup, struct Ref *ref)
 {
-    return get_ref(group, subgroup, ref);
+    return get_ref(group, subgroup, NULL, ref);
 }
 
-static int get_ref(const char *group, const char *subgroup, struct Ref *ref)
+
+/*!
+ * \brief read subgroup REF file
+ *
+ * Reads the contents of the REF file for the
+ * specified <b>subgroup</b> of the specified <b>group</b> into the
+ * <b>ref</b> structure.
+ * Returns 1 if successful; 0 otherwise (but no error messages are printed).
+ *
+ *  \param group
+ *  \param subgroup
+ *  \param mapset
+ *  \param ref
+ *  \return int
+ */
+int I_get_subgroup_ref2(const char *group,
+		       const char *subgroup, const char *mapset,
+               struct Ref *ref)
 {
+    return get_ref(group, subgroup, mapset, ref);
+}
+
+
+static int get_ref(const char *group, const char *subgroup, const char *gmapset, struct Ref *ref)
+{
     int n;
     char buf[1024];
     char name[INAME_LEN], mapset[INAME_LEN];
@@ -146,12 +188,15 @@
     FILE *fd;
 
     I_init_group_ref(ref);
+    
+    if (gmapset == NULL || *gmapset == 0)
+        gmapset = G_mapset();
 
     G_suppress_warnings(1);
     if (*subgroup == 0)
-	fd = I_fopen_group_ref_old(group);
+	fd = I_fopen_group_ref_old2(group, gmapset);
     else
-	fd = I_fopen_subgroup_ref_old(group, subgroup);
+	fd = I_fopen_subgroup_ref_old2(group, subgroup, gmapset);
     G_suppress_warnings(0);
     if (!fd)
 	return 0;

Modified: grass/trunk/lib/imagery/list_subgp.c
===================================================================
--- grass/trunk/lib/imagery/list_subgp.c	2018-10-31 11:07:34 UTC (rev 73631)
+++ grass/trunk/lib/imagery/list_subgp.c	2018-10-31 11:48:02 UTC (rev 73632)
@@ -15,15 +15,7 @@
 #include <grass/imagery.h>
 #include <grass/glocale.h>
 
-/*!
- * \brief Get list of subgroups which a group contatins.
- *  
- * \param group group name
- * \param[out] subgs_num number of subgroups which the group contains
- * \return array of subgroup names
- */
-
-char **I_list_subgroups(const char *group, int *subgs_num)
+char **list_subgroups(char *group, const char *mapset, int *subgs_num)
 {
     /* Unlike I_list_subgroup and I_list_subgroup_simple this function 
        returns array of subgroup names, it does not use fprintf. 
@@ -32,15 +24,13 @@
     char **subgs;
     char path[GPATH_MAX];
     char buf[GPATH_MAX];
-    const char *mapset;
     struct stat sb;
 
     *subgs_num = 0;
 
-    if (I_find_group(group) == 0)
+    if (I_find_group2(group, mapset) == 0)
 	return NULL;
 
-    mapset = G_mapset();
     sprintf(buf, "group/%s/subgroup", group);
     G_file_name(path, buf, "", mapset);
 
@@ -52,6 +42,34 @@
 }
 
 /*!
+ * \brief Get list of subgroups which a group contatins.
+ *  
+ * \param group group name
+ * \param[out] subgs_num number of subgroups which the group contains
+ * \return array of subgroup names
+ */
+
+char **I_list_subgroups(const char *group, int *subgs_num)
+{
+    
+    return list_subgroups(group, G_mapset(), subgs_num);
+}
+
+/*!
+ * \brief Get list of subgroups which a group contatins.
+ *  
+ * \param group group name
+ * \param mapset mapset name
+ * \param[out] subgs_num number of subgroups which the group contains
+ * \return array of subgroup names
+ */
+
+char **I_list_subgroups2(const char *group, const char *mapset, int *subgs_num)
+{
+    return list_subgroups(group, mapset, subgs_num);
+}
+
+/*!
  * \brief Prints maps in a subgroup (fancy version)
  *
  * \param group group name

Modified: grass/trunk/lib/imagery/ref.c
===================================================================
--- grass/trunk/lib/imagery/ref.c	2018-10-31 11:07:34 UTC (rev 73631)
+++ grass/trunk/lib/imagery/ref.c	2018-10-31 11:48:02 UTC (rev 73632)
@@ -32,6 +32,11 @@
     return I_fopen_group_file_old(group, "REF");
 }
 
+FILE *I_fopen_group_ref_old2(const char *group, const char *mapset)
+{
+    return I_fopen_group_file_old2(group, mapset, "REF");
+}
+
 /*
    FILE *
    I_fopen_group_ref_append (
@@ -53,3 +58,12 @@
     fd = I_fopen_subgroup_file_old(group, subgroup, "REF");
     return fd;
 }
+
+FILE *I_fopen_subgroup_ref_old2(const char *group, const char *subgroup, const char *mapset)
+{
+    FILE *fd;
+
+    fd = I_fopen_subgroup_file_old2(group, subgroup, mapset, "REF");
+    return fd;
+}
+



More information about the grass-commit mailing list