r3.timestamp.main.c 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. G_add_keyword(_("raster3d"));
  38. G_add_keyword(_("voxel"));
  39. module->description =
  40. _("Print/add/remove a timestamp for a 3D raster map");
  41. map = G_define_option();
  42. map->key = "map";
  43. map->required = YES;
  44. map->type = TYPE_STRING;
  45. map->gisprompt = "old,grid3,3d raster";
  46. map->description = _("Input grid3 filename");
  47. date = G_define_option();
  48. date->key = "date";
  49. date->key_desc = "timestamp";
  50. date->required = NO;
  51. date->type = TYPE_STRING;
  52. date->description = _("Datetime, datetime1/datetime2, or none");
  53. if (G_parser(argc, argv))
  54. exit(EXIT_FAILURE);
  55. name = map->answer;
  56. modify = date->answer != NULL;
  57. if (modify)
  58. mapset = G_find_grid3(name, G_mapset());
  59. else
  60. mapset = G_find_grid3(name, "");
  61. if (mapset == NULL) {
  62. G_fatal_error(_("Grid3 <%s> not found %s"), name,
  63. modify ? "in current mapset" : "");
  64. exit(EXIT_FAILURE);
  65. }
  66. if (!modify) {
  67. if (G_read_grid3_timestamp(name, mapset, &ts) == 1) {
  68. G__write_timestamp(stdout, &ts);
  69. exit(EXIT_SUCCESS);
  70. }
  71. else
  72. exit(EXIT_FAILURE);
  73. }
  74. if (strcmp(date->answer, "none") == 0) {
  75. G_remove_grid3_timestamp(name);
  76. exit(EXIT_SUCCESS);
  77. }
  78. G_scan_timestamp(&ts, date->answer);
  79. G_write_grid3_timestamp(name, &ts);
  80. exit(EXIT_SUCCESS);
  81. }