~ubuntu-branches/ubuntu/vivid/grass/vivid-proposed

« back to all changes in this revision

Viewing changes to lib/gis/timestamp.c

  • Committer: Package Import Robot
  • Author(s): Bas Couwenberg
  • Date: 2015-02-20 23:12:08 UTC
  • mfrom: (8.2.6 experimental)
  • Revision ID: package-import@ubuntu.com-20150220231208-1u6qvqm84v430b10
Tags: 7.0.0-1~exp1
* New upstream release.
* Update python-ctypes-ternary.patch to use if/else instead of and/or.
* Drop check4dev patch, rely on upstream check.
* Add build dependency on libpq-dev to grass-dev for libpq-fe.h.
* Drop patches applied upstream, refresh remaining patches.
* Update symlinks for images switched from jpg to png.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 *
3
 
 * provides DateTime functions for timestamp management:
4
 
 *
5
 
 * Authors: Michael Shapiro & Bill Brown, CERL
6
 
 *          grid3 functions by Michael Pelizzari, LMCO
7
 
 *
8
 
 * G_init_timestamp()
9
 
 * G_set_timestamp()
10
 
 * G_set_timestamp_range()
11
 
 * G_format_timestamp()
12
 
 * G_scan_timestamp()
13
 
 * G_get_timestamps()
14
 
 * G_read_raster_timestamp()
15
 
 * G_remove_raster_timestamp()
16
 
 * G_read_vector_timestamp()
17
 
 * G_remove_vector_timestamp()
18
 
 * G_read_grid3_timestamp()
19
 
 * G_remove_grid3_timestamp()
20
 
 * G_write_raster_timestamp()
21
 
 * G_write_vector_timestamp()
22
 
 * G_write_grid3_timestamp()
23
 
 *
24
 
 * COPYRIGHT:    (C) 2000 by the GRASS Development Team
25
 
 *
26
 
 *               This program is free software under the GNU General Public
27
 
 *               License (>=v2). Read the file COPYING that comes with GRASS
28
 
 *               for details.
29
 
 *
 
1
/*!
 
2
 * \file lib/gis/timestamp.c
 
3
 *
 
4
 * \brief GIS Library - Timestamp management
 
5
 *
 
6
 * Provides DateTime functions for timestamp management.
30
7
 *
31
8
 * The timestamp values must use the format as described in the GRASS
32
9
 * datetime library. The source tree for this library should have a
89
66
 * 3 months 15 days
90
67
 * 3 years 10 days
91
68
 *
92
 
 *
 
69
 * (C) 2001-2009 by the GRASS Development Team
 
70
 *
 
71
 * This program is free software under the GNU General Public License
 
72
 * (>=v2). Read the file COPYING that comes with GRASS for details.
 
73
 *
 
74
 * \author Michael Shapiro & Bill Brown, CERL
 
75
 * \author raster3d functions by Michael Pelizzari, LMCO
 
76
 * \author Soeren Gebbert, vector timestamp implementation update
93
77
 */
94
78
 
95
79
#include <string.h>
 
80
#include <unistd.h>    
96
81
#include <grass/gis.h>
 
82
#include <grass/vect/dig_defines.h>
97
83
#include <grass/glocale.h>
98
84
 
 
85
#define RAST_MISC "cell_misc"
 
86
#define GRID3     "grid3"
 
87
 
 
88
/*!
 
89
  \brief Initialize timestamp structure
 
90
 
 
91
  \param ts pointer to TimeStamp structure
 
92
*/
99
93
void G_init_timestamp(struct TimeStamp *ts)
100
94
{
101
95
    ts->count = 0;
102
96
}
103
97
 
 
98
/*!
 
99
  \brief Set timestamp (single)
 
100
 
 
101
  \param ts pointer to TimeStamp structure
 
102
  \param dt pointer to DateTime structure (date/time to be set)
 
103
*/
104
104
void G_set_timestamp(struct TimeStamp *ts, const DateTime * dt)
105
105
{
106
106
    datetime_copy(&ts->dt[0], dt);
107
107
    ts->count = 1;
108
108
}
109
109
 
 
110
/*!
 
111
  \brief Set timestamp (range)
 
112
 
 
113
  \param ts pointer to TimeStamp structure
 
114
  \param dt1,dt2 pointer to DateTime structures
 
115
*/
110
116
void G_set_timestamp_range(struct TimeStamp *ts,
111
117
                           const DateTime * dt1, const DateTime * dt2)
112
118
{
115
121
    ts->count = 2;
116
122
}
117
123
 
 
124
/*!
 
125
  \brief Read timestamp
 
126
 
 
127
  \param fd file descriptor
 
128
  \param[out] ts pointer to TimeStamp structure
 
129
 
 
130
  \return -2 EOF
 
131
  \return -1 on error
 
132
  \return 0 on success
 
133
*/
118
134
int G__read_timestamp(FILE * fd, struct TimeStamp *ts)
119
135
{
120
136
    char buf[1024];
128
144
    return -2;                  /* nothing in the file */
129
145
}
130
146
 
131
 
 
132
147
/*!
133
 
 * \brief output TimeStamp structure to a file as a formatted string
134
 
 *
135
 
 * A handy fd might be "stdout".
136
 
 *
137
 
 * Returns:
138
 
 *  0 on success
139
 
 * -1 error
140
 
 *
141
 
 *  \param fd    file descriptor
142
 
 *  \param ts    TimeStamp struct
143
 
 *  \return int  exit value
144
 
 */
145
 
int G__write_timestamp(FILE * fd, const struct TimeStamp *ts)
 
148
  \brief Output TimeStamp structure to a file as a formatted string
 
149
 
 
150
  A handy fd might be "stdout".
 
151
  
 
152
  \param[in,out] fd file descriptor
 
153
  \param ts pointer to TimeStamp structure
 
154
 
 
155
  \return 0 on success
 
156
  \return -1 on error
 
157
*/
 
158
int G_write_timestamp(FILE * fd, const struct TimeStamp *ts)
146
159
{
147
160
    char buf[1024];
148
161
 
152
165
    return 0;
153
166
}
154
167
 
155
 
 
156
168
/*!
157
 
 * \brief Create text string from TimeStamp structure
158
 
 *
159
 
 * Fills string *buf with info from TimeStamp structure *ts in a pretty
160
 
 * way. The TimeStamp struct is defined in gis.h and populated with e.g.
161
 
 * G_read_raster_timestamp().
162
 
 *
163
 
 * Returns:
164
 
 *  1 on success
165
 
 * -1 error
166
 
 *
167
 
 *  \param ts    TimeStamp structure containing time info
168
 
 *  \param buf   string to receive formatted timestamp
169
 
 *  \return int  exit value
170
 
 */
 
169
  \brief Create text string from TimeStamp structure
 
170
  
 
171
  Fills string *buf with info from TimeStamp structure *ts in a
 
172
  pretty way. The TimeStamp struct is defined in gis.h and populated
 
173
  with e.g. G_read_raster_timestamp().
 
174
  
 
175
  \param ts    TimeStamp structure containing time info
 
176
  \param buf   string to receive formatted timestamp
 
177
 
 
178
  \return 1 on success
 
179
  \return -1 error
 
180
*/
171
181
int G_format_timestamp(const struct TimeStamp *ts, char *buf)
172
182
{
173
183
    char temp1[128], temp2[128];
189
199
    return 1;
190
200
}
191
201
 
192
 
 
193
202
/*!
194
 
 * \brief Fill a TimeStamp structure from a datetime string
195
 
 *
196
 
 * Populate a TimeStamp structure (defined in gis.h) from a text string.
197
 
 * Checks to make sure text string is in valid GRASS datetime format.
198
 
 *
199
 
 * Returns:
200
 
 * 1 on success
201
 
 * -1 error
202
 
 *
203
 
 *  \param ts   TimeStamp structure to be populated
204
 
 *  \param buf  String containing formatted time info
205
 
 *  \return int exit code
206
 
 */
 
203
  \brief Fill a TimeStamp structure from a datetime string
 
204
  
 
205
  Populate a TimeStamp structure (defined in gis.h) from a text
 
206
  string. Checks to make sure text string is in valid GRASS datetime
 
207
  format.
 
208
  
 
209
  \param ts   TimeStamp structure to be populated
 
210
  \param buf  string containing formatted time info
 
211
  
 
212
  \return 1 on success
 
213
  \return -1 error
 
214
*/
207
215
int G_scan_timestamp(struct TimeStamp *ts, const char *buf)
208
216
{
209
217
    char temp[1024], *t;
232
240
    return 1;
233
241
}
234
242
 
235
 
 
236
243
/*!
237
 
 * \brief copy TimeStamp into [two] Datetimes structs
238
 
 *
239
 
 * Use to copy the TimeStamp information into Datetimes, as the members of
240
 
 * struct TimeStamp shouldn't be accessed directly.
241
 
 *
242
 
 * count=0  means no datetimes were copied
243
 
 * count=1  means 1 datetime was copied into dt1
244
 
 * count=2  means 2 datetimes were copied
245
 
 *
246
 
 *  \param ts     source TimeStamp structure
247
 
 *  \param dt1    first DateTime struct to be filled
248
 
 *  \param dt2    second DateTime struct to be filled
249
 
 *  \param count  return code
250
 
 *  \return int   always 0
251
 
 */
252
 
int G_get_timestamps(const struct TimeStamp *ts,
253
 
                     DateTime * dt1, DateTime * dt2, int *count)
 
244
  \brief Copy TimeStamp into [two] Datetimes structs
 
245
  
 
246
  Use to copy the TimeStamp information into Datetimes, as the members
 
247
  of struct TimeStamp shouldn't be accessed directly.
 
248
 
 
249
   - count=0  means no datetimes were copied
 
250
   - count=1  means 1 datetime was copied into dt1
 
251
   - count=2  means 2 datetimes were copied
 
252
   
 
253
   \param ts     source TimeStamp structure
 
254
   \param[out] dt1    first DateTime struct to be filled
 
255
   \param[out] dt2    second DateTime struct to be filled
 
256
   \param[out] count  return code
 
257
*/
 
258
void G_get_timestamps(const struct TimeStamp *ts,
 
259
                      DateTime * dt1, DateTime * dt2, int *count)
254
260
{
255
261
    *count = 0;
256
262
    if (ts->count > 0) {
261
267
        datetime_copy(dt2, &ts->dt[1]);
262
268
        *count = 2;
263
269
    }
264
 
 
265
 
    return 0;
266
270
}
267
271
 
268
 
 
269
 
/* write timestamp file
270
 
 * 1 ok
271
 
 * -1 error - can't create timestamp file
272
 
 * -2 error - invalid datetime in ts
273
 
 */
 
272
/*!
 
273
  \brief Write timestamp file
 
274
 
 
275
  \param maptype map type
 
276
  \param dir directory
 
277
  \param name map name
 
278
  \param ts pointer to TimeStamp
 
279
 
 
280
  \return 1 on success
 
281
  \return -1 error - can't create timestamp file
 
282
  \return -2 error - invalid datetime in ts
 
283
*/
274
284
static int write_timestamp(const char *maptype, const char *dir,
275
285
                           const char *name, const struct TimeStamp *ts)
276
286
{
279
289
 
280
290
    fd = G_fopen_new_misc(dir, "timestamp", name);
281
291
    if (fd == NULL) {
282
 
        G_warning(_("Can't create timestamp file for %s map %s in mapset %s"),
 
292
        G_warning(_("Unable to create timestamp file for %s map <%s@%s>"),
283
293
                  maptype, name, G_mapset());
284
294
        return -1;
285
295
    }
286
296
 
287
 
    stat = G__write_timestamp(fd, ts);
 
297
    stat = G_write_timestamp(fd, ts);
288
298
    fclose(fd);
289
299
    if (stat == 0)
290
300
        return 1;
291
 
    G_warning(_("Invalid timestamp specified for %s map %s in mapset %s"),
 
301
    G_warning(_("Invalid timestamp specified for %s map <%s@%s>"),
292
302
              maptype, name, G_mapset());
293
303
    return -2;
294
304
}
295
305
 
296
 
/* read timestamp file
297
 
 * 0 no timestamp file
298
 
 * 1 ok
299
 
 * -1 error - can't open timestamp file
300
 
 * -2 error - invalid datetime values in timestamp file
301
 
 */
 
306
/*!
 
307
  \brief Read timestamp file
 
308
 
 
309
  \param maptype map type
 
310
  \param dir directory
 
311
  \param name map name
 
312
  \param mapset mapset name
 
313
  \param ts pointer to TimeStamp
 
314
  
 
315
  \return 0 no timestamp file
 
316
  \return 1 on success
 
317
  \return -1 error - can't open timestamp file
 
318
  \return -2 error - invalid datetime values in timestamp file
 
319
*/
302
320
static int read_timestamp(const char *maptype, const char *dir,
303
321
                          const char *name, const char *mapset,
304
322
                          struct TimeStamp *ts)
310
328
        return 0;
311
329
    fd = G_fopen_old_misc(dir, "timestamp", name, mapset);
312
330
    if (fd == NULL) {
313
 
        G_warning(_("Can't open timestamp file for %s map %s in mapset %s"),
 
331
        G_warning(_("Unable to open timestamp file for %s map <%s@%s>"),
314
332
                  maptype, name, mapset);
315
333
        return -1;
316
334
    }
319
337
    fclose(fd);
320
338
    if (stat == 0)
321
339
        return 1;
322
 
    G_warning(_("Invalid timestamp file for %s map %s in mapset %s"),
 
340
    G_warning(_("Invalid timestamp file for %s map <%s@%s>"),
323
341
              maptype, name, mapset);
324
342
    return -2;
325
343
}
326
344
 
327
 
#define RAST_MISC "cell_misc"
328
 
#define VECT_MISC "dig_misc"
329
 
#define GRID3     "grid3"
330
 
 
331
 
 
332
 
/*!
333
 
 * \brief Read timestamp from raster map
334
 
 *
335
 
 * Returns:
336
 
 * 1 on success
337
 
 * 0 or negative on error.
338
 
 *
339
 
 *  \param name map name
340
 
 *  \param mapset mapset the map lives in
341
 
 *  \param ts TimeStamp struct to populate
342
 
 *  \return int
343
 
 */
 
345
/*!
 
346
  \brief Check if timestamp for raster map exists
 
347
  
 
348
  \param name map name
 
349
  \param mapset mapset name
 
350
 
 
351
  \return 1 on success
 
352
  \return 0 no timestamp present
 
353
*/
 
354
int G_has_raster_timestamp(const char *name, const char *mapset)
 
355
{
 
356
    if (!G_find_file2_misc(RAST_MISC, "timestamp", name, mapset))
 
357
        return 0;
 
358
 
 
359
    return 1;
 
360
}
 
361
 
 
362
/*!
 
363
  \brief Read timestamp from raster map
 
364
  
 
365
  \param name map name
 
366
  \param mapset mapset the map lives in
 
367
  \param[out] ts TimeStamp struct to populate
 
368
 
 
369
  \return 1 on success
 
370
  \return 0 or negative on error
 
371
*/
344
372
int G_read_raster_timestamp(const char *name, const char *mapset,
345
373
                            struct TimeStamp *ts)
346
374
{
347
375
    return read_timestamp("raster", RAST_MISC, name, mapset, ts);
348
376
}
349
377
 
350
 
 
351
378
/*!
352
 
 * \brief 
353
 
 *
354
 
 * Only timestamp files in current mapset can be removed
355
 
 * Returns:
356
 
 * 0  if no file
357
 
 * 1  if successful
358
 
 * -1  on fail
359
 
 *
360
 
 *  \param name
361
 
 *  \return int
 
379
  \brief Write timestamp of raster map
 
380
 
 
381
  \param name map name
 
382
  \param[out] ts TimeStamp struct to populate
 
383
  
 
384
  \return 1 on success
 
385
  \return -1 error - can't create timestamp file
 
386
  \return -2 error - invalid datetime in ts
 
387
 
362
388
 */
 
389
int G_write_raster_timestamp(const char *name, const struct TimeStamp *ts)
 
390
{
 
391
    return write_timestamp("raster", RAST_MISC, name, ts);
 
392
}
 
393
 
 
394
/*!
 
395
  \brief Remove timestamp from raster map
 
396
  
 
397
  Only timestamp files in current mapset can be removed.
 
398
 
 
399
  \param name map name
 
400
 
 
401
  \return 0 if no file
 
402
  \return 1 on success
 
403
  \return -1 on error
 
404
*/
363
405
int G_remove_raster_timestamp(const char *name)
364
406
{
365
407
    return G_remove_misc(RAST_MISC, "timestamp", name);
366
408
}
367
409
 
368
 
 
369
 
 
370
 
/*!
371
 
 * \brief Read vector timestamp
372
 
 *
373
 
 * Is this used anymore with the new GRASS 6 vector engine???
374
 
 *
375
 
 * Returns 1 on success.  0 or negative on error.
376
 
 *
377
 
 *  \param name
378
 
 *  \param mapset
379
 
 *  \param ts
380
 
 *  \return int
381
 
 */
382
 
int G_read_vector_timestamp(const char *name, const char *mapset,
383
 
                            struct TimeStamp *ts)
384
 
{
385
 
    return read_timestamp("vector", VECT_MISC, name, mapset, ts);
386
 
}
387
 
 
388
 
 
389
 
 
390
 
/*!
391
 
 * \brief 
392
 
 *
393
 
 * Is this used anymore with the new GRASS 6 vector engine???
394
 
 *
395
 
 * Only timestamp files in current mapset can be removed
396
 
 * Returns:
397
 
 * 0  if no file
398
 
 * 1  if successful
399
 
 * -1  on fail
400
 
 *
401
 
 *  \param name
402
 
 *  \return int
403
 
 */
404
 
int G_remove_vector_timestamp(const char *name)
405
 
{
406
 
    return G_remove_misc(VECT_MISC, "timestamp", name);
407
 
}
408
 
 
409
 
 
410
 
/*!
411
 
 * \brief read grid3 timestamp
412
 
 *
413
 
 * Returns 1 on success. 0 or
414
 
 * negative on error.
415
 
 *
416
 
 *  \param name
417
 
 *  \param mapset
418
 
 *  \param ts
419
 
 *  \return int
420
 
 */
421
 
int G_read_grid3_timestamp(const char *name, const char *mapset,
 
410
/*!
 
411
  \brief Check if timestamp for vector map exists
 
412
  
 
413
  \param name map name
 
414
  \param layer The layer names, in case of NULL, layer one is assumed
 
415
  \param mapset mapset name
 
416
 
 
417
  \return 1 on success
 
418
  \return 0 no timestamp present
 
419
*/
 
420
int G_has_vector_timestamp(const char *name, const char *layer, const char *mapset)
 
421
{
 
422
    char dir[GPATH_MAX];
 
423
    char path[GPATH_MAX + GNAME_MAX];
 
424
    char ele[GNAME_MAX];
 
425
 
 
426
    if(layer != NULL)
 
427
        G_snprintf(ele, GNAME_MAX, "%s_%s", GV_TIMESTAMP_ELEMENT, layer);
 
428
    else
 
429
        G_snprintf(ele, GNAME_MAX, "%s_1", GV_TIMESTAMP_ELEMENT);
 
430
 
 
431
    G_snprintf(dir, GPATH_MAX, "%s/%s", GV_DIRECTORY, name);
 
432
    G_file_name(path, dir, ele, mapset);
 
433
 
 
434
    G_debug(1, "Check for timestamp <%s>", path);
 
435
 
 
436
    if (access(path, R_OK) != 0)
 
437
        return 0;
 
438
 
 
439
    return 1;
 
440
}
 
441
 
 
442
/*!
 
443
  \brief Read timestamp from vector map
 
444
  
 
445
  \param name map name
 
446
  \param layer The layer names, in case of NULL, layer one is assumed
 
447
  \param mapset mapset name
 
448
  \param[out] ts TimeStamp struct to populate
 
449
 
 
450
  \return 1 on success
 
451
  \return 0 no timestamp present
 
452
  \return -1 Unable to open file 
 
453
  \return -2 invalid time stamp
 
454
*/
 
455
int G_read_vector_timestamp(const char *name, const char *layer, 
 
456
                            const char *mapset, struct TimeStamp *ts)
 
457
{
 
458
    FILE *fd;
 
459
    int stat;
 
460
    char dir[GPATH_MAX];
 
461
    char ele[GNAME_MAX];
 
462
 
 
463
    /* In case no timestamp file is present return 0 */
 
464
    if (G_has_vector_timestamp(name, layer, mapset) != 1)
 
465
        return 0;
 
466
 
 
467
    if(layer != NULL)
 
468
        G_snprintf(ele, GNAME_MAX, "%s_%s", GV_TIMESTAMP_ELEMENT, layer);
 
469
    else
 
470
        G_snprintf(ele, GNAME_MAX, "%s_1", GV_TIMESTAMP_ELEMENT);
 
471
 
 
472
    G_snprintf(dir, GPATH_MAX, "%s/%s", GV_DIRECTORY, name);
 
473
 
 
474
    G_debug(1, "Read timestamp <%s/%s>", dir, ele);
 
475
 
 
476
    fd = G_fopen_old(dir, ele, mapset);
 
477
    
 
478
    if (fd == NULL) {
 
479
        G_warning(_("Unable to open timestamp file for vector map <%s@%s>"),
 
480
                  name, G_mapset());
 
481
        return -1;
 
482
    }
 
483
 
 
484
    stat = G__read_timestamp(fd, ts);
 
485
    fclose(fd);
 
486
    if (stat == 0)
 
487
        return 1;
 
488
    G_warning(_("Invalid timestamp file for vector map <%s@%s>"),
 
489
                name, mapset);
 
490
    return -2;
 
491
}
 
492
 
 
493
/*!
 
494
  \brief Write timestamp of vector map
 
495
 
 
496
  \param name map name
 
497
  \param layer The layer names, in case of NULL, layer one is assumed
 
498
  \param[out] ts TimeStamp struct to populate
 
499
  
 
500
  \return 1 on success
 
501
  \return -1 error - can't create timestamp file
 
502
  \return -2 error - invalid datetime in ts
 
503
 
 
504
 */
 
505
int G_write_vector_timestamp(const char *name, const char *layer, const struct TimeStamp *ts)
 
506
{
 
507
    FILE *fd;
 
508
    int stat;
 
509
    char dir[GPATH_MAX];
 
510
    char ele[GNAME_MAX];
 
511
 
 
512
    if(layer != NULL)
 
513
        G_snprintf(ele, GNAME_MAX, "%s_%s", GV_TIMESTAMP_ELEMENT, layer);
 
514
    else
 
515
        G_snprintf(ele, GNAME_MAX, "%s_1", GV_TIMESTAMP_ELEMENT);
 
516
 
 
517
    G_snprintf(dir, GPATH_MAX, "%s/%s", GV_DIRECTORY, name);
 
518
 
 
519
    G_debug(1, "Write timestamp <%s/%s>", dir, ele);
 
520
 
 
521
    fd = G_fopen_new(dir, ele);
 
522
    
 
523
    if (fd == NULL) {
 
524
        G_warning(_("Unable to create timestamp file for vector map <%s@%s>"),
 
525
                  name, G_mapset());
 
526
        return -1;
 
527
    }
 
528
 
 
529
    stat = G_write_timestamp(fd, ts);
 
530
    fclose(fd);
 
531
    if (stat == 0)
 
532
        return 1;
 
533
    G_warning(_("Invalid timestamp specified for vector map <%s@%s>"),
 
534
              name, G_mapset());
 
535
    return -2;
 
536
}
 
537
 
 
538
/*!
 
539
  \brief Remove timestamp from vector map
 
540
  
 
541
  Only timestamp files in current mapset can be removed.
 
542
 
 
543
  \param name map name
 
544
  \param layer The layer names, in case of NULL, layer one is assumed
 
545
 
 
546
  \return 0 if no file
 
547
  \return 1 on success
 
548
  \return -1 on failure
 
549
*/
 
550
int G_remove_vector_timestamp(const char *name, const char *layer)
 
551
{
 
552
    char dir[GPATH_MAX];
 
553
    char ele[GNAME_MAX];
 
554
 
 
555
    if(layer)
 
556
        G_snprintf(ele, GNAME_MAX, "%s_%s", GV_TIMESTAMP_ELEMENT, layer);
 
557
    else
 
558
        G_snprintf(ele, GNAME_MAX, "%s_1", GV_TIMESTAMP_ELEMENT);
 
559
 
 
560
    G_snprintf(dir, GPATH_MAX, "%s/%s", GV_DIRECTORY, name);
 
561
    return G_remove(dir, ele);
 
562
}
 
563
 
 
564
/*!
 
565
  \brief Check if timestamp for 3D raster map exists
 
566
  
 
567
  \param name map name
 
568
  \param mapset mapset name
 
569
 
 
570
  \return 1 on success
 
571
  \return 0 no timestamp present
 
572
*/
 
573
int G_has_raster3d_timestamp(const char *name, const char *mapset)
 
574
{
 
575
    if (!G_find_file2_misc(GRID3, "timestamp", name, mapset))
 
576
        return 0;
 
577
 
 
578
    return 1;
 
579
}
 
580
 
 
581
/*!
 
582
  \brief Read timestamp from 3D raster map
 
583
  
 
584
  \param name map name
 
585
  \param mapset mapset name
 
586
  \param[out] ts TimeStamp struct to populate
 
587
 
 
588
  \return 1 on success
 
589
  \return 0 or negative on error
 
590
*/
 
591
int G_read_raster3d_timestamp(const char *name, const char *mapset,
422
592
                           struct TimeStamp *ts)
423
593
{
424
 
    return read_timestamp("grid3", GRID3, name, mapset, ts);
 
594
    return read_timestamp("raster3d", GRID3, name, mapset, ts);
425
595
}
426
596
 
427
 
 
428
597
/*!
429
 
 * \brief remove grid3 timestamp
430
 
 *
431
 
 * Only timestamp files in current mapset can be removed
432
 
 * Returns:
433
 
 * 0  if no file
434
 
 * 1  if successful
435
 
 * -1  on fail
436
 
 *
437
 
 *  \param name
438
 
 *  \return int
 
598
  \brief Write timestamp of 3D raster map
 
599
 
 
600
  \param name map name
 
601
  \param[out] ts TimeStamp struct to populate
 
602
  
 
603
  \return 1 on success
 
604
  \return -1 error - can't create timestamp file
 
605
  \return -2 error - invalid datetime in ts
 
606
 
439
607
 */
440
 
int G_remove_grid3_timestamp(const char *name)
 
608
int G_write_raster3d_timestamp(const char *name, const struct TimeStamp *ts)
 
609
{
 
610
    return write_timestamp("raster3d", GRID3, name, ts);
 
611
}
 
612
 
 
613
/*!
 
614
  \brief Remove timestamp from 3D raster map
 
615
  
 
616
  Only timestamp files in current mapset can be removed.
 
617
 
 
618
  \param name map name
 
619
 
 
620
  \return 0 if no file
 
621
  \return 1 on success
 
622
  \return -1 on failure
 
623
*/
 
624
int G_remove_raster3d_timestamp(const char *name)
441
625
{
442
626
    return G_remove_misc(GRID3, "timestamp", name);
443
627
}
444
628
 
445
 
 
446
 
 
447
 
/*!
448
 
 * \brief 
449
 
 *
450
 
 * Returns:
451
 
 * 1 on success.
452
 
 * -1 error - can't create timestamp file
453
 
 * -2 error - invalid datetime in ts
454
 
 *
455
 
 *  \param name
456
 
 *  \param ts
457
 
 *  \return int
458
 
 */
459
 
int G_write_raster_timestamp(const char *name, const struct TimeStamp *ts)
460
 
{
461
 
    return write_timestamp("raster", RAST_MISC, name, ts);
462
 
}
463
 
 
464
 
 
465
 
 
466
 
/*!
467
 
 * \brief 
468
 
 *
469
 
 * Returns:
470
 
 * 1 on success.
471
 
 * -1 error - can't create timestamp file
472
 
 * -2 error - invalid datetime in ts
473
 
 *
474
 
 *  \param name
475
 
 *  \param ts
476
 
 *  \return int
477
 
 */
478
 
int G_write_vector_timestamp(const char *name, const struct TimeStamp *ts)
479
 
{
480
 
    return write_timestamp("vector", VECT_MISC, name, ts);
481
 
}
482
 
 
483
 
 
484
 
/*!
485
 
 * \brief write grid3 timestamp
486
 
 *
487
 
 * Returns:
488
 
 * 1 on success.
489
 
 * -1 error - can't create timestamp file
490
 
 * -2 error - invalid datetime in ts
491
 
 *
492
 
 *  \param name
493
 
 *  \param ts
494
 
 *  \return int
495
 
 */
496
 
int G_write_grid3_timestamp(const char *name, const struct TimeStamp *ts)
497
 
{
498
 
    return write_timestamp("grid3", GRID3, name, ts);
499
 
}