r3.timestamp.main.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /****************************************************************************
  2. *
  3. * MODULE: r3.timestamp
  4. * AUTHOR(S): Michael Pelizzari <michael.pelizzari lmco.com>
  5. * (original contributor)
  6. * Glynn Clements <glynn gclements.plus.com> Markus Neteler <neteler itc.it>
  7. * PURPOSE: Stamps grid3 files with date and time.
  8. * COPYRIGHT: (C) 2001-2006 by the GRASS Development Team
  9. *
  10. * This program is free software under the GNU General Public
  11. * License (>=v2). Read the file COPYING that comes with GRASS
  12. * for details.
  13. *
  14. *****************************************************************************/
  15. /* based on r.timestamp by Michael Shapiro and v.timestamp by Markus Neteler:
  16. *
  17. * Stamps grid3 files with date and time. This main.c is linked to functions
  18. * currently residing in lib/gis/timestamp.c
  19. *
  20. */
  21. #include <stdio.h>
  22. #include <stdlib.h>
  23. #include <string.h>
  24. #include <grass/gis.h>
  25. #include <grass/G3d.h>
  26. #include <grass/glocale.h>
  27. int main(int argc, char *argv[])
  28. {
  29. struct Option *map, *date;
  30. struct TimeStamp ts;
  31. char *name;
  32. char *mapset;
  33. int modify;
  34. struct GModule *module;
  35. G_gisinit(argv[0]);
  36. module = G_define_module();
  37. module->keywords = _("raster3d, voxel");
  38. module->description =
  39. _("Print/add/remove a timestamp for a 3D raster map");
  40. map = G_define_option();
  41. map->key = "map";
  42. map->required = YES;
  43. map->type = TYPE_STRING;
  44. map->gisprompt = "old,grid3,3d raster";
  45. map->description = _("Input grid3 filename");
  46. date = G_define_option();
  47. date->key = "date";
  48. date->key_desc = "timestamp";
  49. date->required = NO;
  50. date->type = TYPE_STRING;
  51. date->description = _("Datetime, datetime1/datetime2, or none");
  52. if (G_parser(argc, argv))
  53. exit(EXIT_FAILURE);
  54. name = map->answer;
  55. modify = date->answer != NULL;
  56. if (modify)
  57. mapset = G_find_grid3(name, G_mapset());
  58. else
  59. mapset = G_find_grid3(name, "");
  60. if (mapset == NULL) {
  61. G_fatal_error(_("Grid3 <%s> not found %s"), name,
  62. modify ? "in current mapset" : "");
  63. exit(EXIT_FAILURE);
  64. }
  65. if (!modify) {
  66. if (G_read_grid3_timestamp(name, mapset, &ts) == 1) {
  67. G__write_timestamp(stdout, &ts);
  68. exit(EXIT_SUCCESS);
  69. }
  70. else
  71. exit(EXIT_FAILURE);
  72. }
  73. if (strcmp(date->answer, "none") == 0) {
  74. G_remove_grid3_timestamp(name);
  75. exit(EXIT_SUCCESS);
  76. }
  77. G_scan_timestamp(&ts, date->answer);
  78. G_write_grid3_timestamp(name, &ts);
  79. exit(EXIT_SUCCESS);
  80. }