[GRASS-SVN] r50444 - in grass/trunk: include/defs lib/gis
vector/v.timestamp vector/v.timestamp/test_suite
svn_grass at osgeo.org
svn_grass at osgeo.org
Wed Jan 25 09:20:48 EST 2012
Author: huhabla
Date: 2012-01-25 06:20:48 -0800 (Wed, 25 Jan 2012)
New Revision: 50444
Modified:
grass/trunk/include/defs/gis.h
grass/trunk/lib/gis/timestamp.c
grass/trunk/vector/v.timestamp/main.c
grass/trunk/vector/v.timestamp/test_suite/test.v.timestamp.sh
Log:
Timestamp support for vector layers added.
Modified: grass/trunk/include/defs/gis.h
===================================================================
--- grass/trunk/include/defs/gis.h 2012-01-25 14:06:13 UTC (rev 50443)
+++ grass/trunk/include/defs/gis.h 2012-01-25 14:20:48 UTC (rev 50444)
@@ -624,10 +624,10 @@
int G_read_raster_timestamp(const char *, const char *, struct TimeStamp *);
int G_write_raster_timestamp(const char *, const struct TimeStamp *);
int G_remove_raster_timestamp(const char *);
-int G_has_vector_timestamp(const char *, const char *);
-int G_read_vector_timestamp(const char *, const char *, struct TimeStamp *);
-int G_write_vector_timestamp(const char *, const struct TimeStamp *);
-int G_remove_vector_timestamp(const char *);
+int G_has_vector_timestamp(const char *, const char *, const char *);
+int G_read_vector_timestamp(const char *, const char *, const char *, struct TimeStamp *);
+int G_write_vector_timestamp(const char *, const char *, const struct TimeStamp *);
+int G_remove_vector_timestamp(const char *, const char *);
int G_has_raster3d_timestamp(const char *, const char *);
int G_read_raster3d_timestamp(const char *, const char *, struct TimeStamp *);
int G_remove_raster3d_timestamp(const char *);
Modified: grass/trunk/lib/gis/timestamp.c
===================================================================
--- grass/trunk/lib/gis/timestamp.c 2012-01-25 14:06:13 UTC (rev 50443)
+++ grass/trunk/lib/gis/timestamp.c 2012-01-25 14:20:48 UTC (rev 50444)
@@ -411,19 +411,28 @@
\brief Check if timestamp for vector map exists
\param name map name
+ \param layer The layer names, in case of NULL, layer one is assumed
\param mapset mapset name
\return 1 on success
\return 0 no timestamp present
*/
-int G_has_vector_timestamp(const char *name, const char *mapset)
+int G_has_vector_timestamp(const char *name, const char *layer, const char *mapset)
{
char dir[GPATH_MAX];
char path[GPATH_MAX + GNAME_MAX];
+ char ele[GNAME_MAX];
+ if(layer != NULL)
+ G_snprintf(ele, GNAME_MAX, "%s_%s", GV_TIMESTAMP_ELEMENT, layer);
+ else
+ G_snprintf(ele, GNAME_MAX, "%s_1", GV_TIMESTAMP_ELEMENT);
+
G_snprintf(dir, GPATH_MAX, "%s/%s", GV_DIRECTORY, name);
- G_file_name(path, dir, GV_TIMESTAMP_ELEMENT, mapset);
+ G_file_name(path, dir, ele, mapset);
+ G_debug(1, "Check for timestamp <%s>", path);
+
if (access(path, R_OK) != 0)
return 0;
@@ -434,6 +443,7 @@
\brief Read timestamp from vector map
\param name map name
+ \param layer The layer names, in case of NULL, layer one is assumed
\param mapset mapset name
\param[out] ts TimeStamp struct to populate
@@ -442,19 +452,28 @@
\return -1 Unable to open file
\return -2 invalid time stamp
*/
-int G_read_vector_timestamp(const char *name, const char *mapset,
- struct TimeStamp *ts)
+int G_read_vector_timestamp(const char *name, const char *layer,
+ const char *mapset, struct TimeStamp *ts)
{
FILE *fd;
int stat;
char dir[GPATH_MAX];
+ char ele[GNAME_MAX];
/* In case no timestamp file is present return 0 */
- if (G_has_vector_timestamp(name, mapset) != 1)
+ if (G_has_vector_timestamp(name, layer, mapset) != 1)
return 0;
+ if(layer != NULL)
+ G_snprintf(ele, GNAME_MAX, "%s_%s", GV_TIMESTAMP_ELEMENT, layer);
+ else
+ G_snprintf(ele, GNAME_MAX, "%s_1", GV_TIMESTAMP_ELEMENT);
+
G_snprintf(dir, GPATH_MAX, "%s/%s", GV_DIRECTORY, name);
- fd = G_fopen_old(dir, GV_TIMESTAMP_ELEMENT, mapset);
+
+ G_debug(1, "Read timestamp <%s/%s>", dir, ele);
+
+ fd = G_fopen_old(dir, ele, mapset);
if (fd == NULL) {
G_warning(_("Unable to open timestamp file for vector map <%s@%s>"),
@@ -475,6 +494,7 @@
\brief Write timestamp of vector map
\param name map name
+ \param layer The layer names, in case of NULL, layer one is assumed
\param[out] ts TimeStamp struct to populate
\return 1 on success
@@ -482,15 +502,23 @@
\return -2 error - invalid datetime in ts
*/
-int G_write_vector_timestamp(const char *name, const struct TimeStamp *ts)
+int G_write_vector_timestamp(const char *name, const char *layer, const struct TimeStamp *ts)
{
FILE *fd;
int stat;
char dir[GPATH_MAX];
+ char ele[GNAME_MAX];
+ if(layer != NULL)
+ G_snprintf(ele, GNAME_MAX, "%s_%s", GV_TIMESTAMP_ELEMENT, layer);
+ else
+ G_snprintf(ele, GNAME_MAX, "%s_1", GV_TIMESTAMP_ELEMENT);
+
G_snprintf(dir, GPATH_MAX, "%s/%s", GV_DIRECTORY, name);
- fd = G_fopen_new(dir, GV_TIMESTAMP_ELEMENT);
+ G_debug(1, "Write timestamp <%s/%s>", dir, ele);
+
+ fd = G_fopen_new(dir, ele);
if (fd == NULL) {
G_warning(_("Unable to create timestamp file for vector map <%s@%s>"),
@@ -513,17 +541,24 @@
Only timestamp files in current mapset can be removed.
\param name map name
+ \param layer The layer names, in case of NULL, layer one is assumed
\return 0 if no file
\return 1 on success
\return -1 on failure
*/
-int G_remove_vector_timestamp(const char *name)
+int G_remove_vector_timestamp(const char *name, const char *layer)
{
char dir[GPATH_MAX];
+ char ele[GNAME_MAX];
+ if(layer)
+ G_snprintf(ele, GNAME_MAX, "%s_%s", GV_TIMESTAMP_ELEMENT, layer);
+ else
+ G_snprintf(ele, GNAME_MAX, "%s_1", GV_TIMESTAMP_ELEMENT);
+
G_snprintf(dir, GPATH_MAX, "%s/%s", GV_DIRECTORY, name);
- return G_remove(dir, GV_TIMESTAMP_ELEMENT);
+ return G_remove(dir, ele);
}
/*!
Modified: grass/trunk/vector/v.timestamp/main.c
===================================================================
--- grass/trunk/vector/v.timestamp/main.c 2012-01-25 14:06:13 UTC (rev 50443)
+++ grass/trunk/vector/v.timestamp/main.c 2012-01-25 14:20:48 UTC (rev 50444)
@@ -24,7 +24,7 @@
int main(int argc, char *argv[])
{
struct GModule *module;
- struct Option *map, *date;
+ struct Option *map, *layer, *date;
struct TimeStamp ts;
char *name;
const char *mapset;
@@ -40,6 +40,7 @@
module->description = _("Print/add/remove a timestamp for a vector map.");
map = G_define_standard_option(G_OPT_V_MAP);
+ layer = G_define_standard_option(G_OPT_V_FIELD);
date = G_define_option();
date->key = "date";
@@ -68,7 +69,7 @@
}
if (!modify) {
- if (G_read_vector_timestamp(name, "", &ts) == 1) {
+ if (G_read_vector_timestamp(name, layer->answer, "", &ts) == 1) {
G__write_timestamp(stdout, &ts);
exit(EXIT_SUCCESS);
}
@@ -76,14 +77,14 @@
exit(EXIT_FAILURE);
}
if (strcmp(date->answer, "none") == 0) {
- G_remove_vector_timestamp(name);
+ G_remove_vector_timestamp(name, layer->answer);
exit(EXIT_SUCCESS);
}
if(G_scan_timestamp(&ts, date->answer) != 1)
G_fatal_error("Timestamp format is invalid");
- G_write_vector_timestamp(name, &ts);
+ G_write_vector_timestamp(name, layer->answer, &ts);
exit(EXIT_SUCCESS);
}
Modified: grass/trunk/vector/v.timestamp/test_suite/test.v.timestamp.sh
===================================================================
--- grass/trunk/vector/v.timestamp/test_suite/test.v.timestamp.sh 2012-01-25 14:06:13 UTC (rev 50443)
+++ grass/trunk/vector/v.timestamp/test_suite/test.v.timestamp.sh 2012-01-25 14:20:48 UTC (rev 50444)
@@ -12,24 +12,30 @@
# The first @test uses several different absolute datum formats
v.timestamp map=map date=none
v.timestamp map=map
-v.timestamp map=map date="2003"
-v.timestamp map=map
-v.timestamp map=map date="Jul 2003"
-v.timestamp map=map
+v.timestamp map=map layer=1 date="2003"
+v.timestamp map=map layer=1
+v.timestamp map=map layer=2 date="Jul 2003"
+v.timestamp map=map layer=2
v.timestamp map=map date="14 Jul 2003"
v.timestamp map=map
v.timestamp map=map date="14 Jul 2003 10"
v.timestamp map=map
-v.timestamp map=map date="14 Jul 2003 10:30 +0700"
-v.timestamp map=map
-v.timestamp map=map date="14 Jul 2003 10:30:25"
-v.timestamp map=map
+v.timestamp map=map layer=3 date="14 Jul 2003 10:30 +0700"
+v.timestamp map=map layer=3
+v.timestamp map=map layer=4 date="14 Jul 2003 10:30:25"
+v.timestamp map=map layer=4
v.timestamp map=map date="14 Jul 2003 10:30:25 +0700 / 15 Jul 2003 11:35:12 +0700"
v.timestamp map=map
v.timestamp map=map date="14 Jul 2003 10:30:25 +0700 / 15 Jul 2003"
v.timestamp map=map
v.timestamp map=map date=none
+v.timestamp map=map layer=2 date=none
+v.timestamp map=map layer=3 date=none
+v.timestamp map=map layer=4 date=none
v.timestamp map=map
+v.timestamp map=map layer=2
+v.timestamp map=map layer=3
+v.timestamp map=map layer=4
# The second @test uses several different relative datum formats
v.timestamp map=map date=none
@@ -38,15 +44,19 @@
v.timestamp map=map
v.timestamp map=map date="2 years 3 months"
v.timestamp map=map
-v.timestamp map=map date="5 days"
-v.timestamp map=map
-v.timestamp map=map date="3 hours"
-v.timestamp map=map
+v.timestamp map=map layer=1 date="5 days"
+v.timestamp map=map layer=1
+v.timestamp map=map layer=2 date="3 hours"
+v.timestamp map=map layer=2
v.timestamp map=map date="5 minutes 30 seconds"
v.timestamp map=map
v.timestamp map=map date="2 years 2 months / 5 years 8 months"
+v.timestamp map=map date=none
+v.timestamp map=map layer=2 date=none
+v.timestamp map=map layer=3 date=none
v.timestamp map=map
-v.timestamp map=map date=none
+v.timestamp map=map layer=2
+v.timestamp map=map layer=3
# The third @test to check @failure with wrong time stamps
v.timestamp map=map date="2 years 3 months 8 days"
More information about the grass-commit
mailing list