r3.timestamp.main.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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 raster3d 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 raster3d 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/raster3d.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. const 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_standard_option(G_OPT_R3_MAP);
  42. date = G_define_option();
  43. date->key = "date";
  44. date->key_desc = "timestamp";
  45. date->required = NO;
  46. date->type = TYPE_STRING;
  47. date->description = _("Datetime, datetime1/datetime2, or none");
  48. if (G_parser(argc, argv))
  49. exit(EXIT_FAILURE);
  50. name = map->answer;
  51. modify = date->answer != NULL;
  52. if (modify)
  53. mapset = G_find_raster3d(name, G_mapset());
  54. else
  55. mapset = G_find_raster3d(name, "");
  56. if (mapset == NULL) {
  57. G_fatal_error(_("3D raster map <%s> not found"), name);
  58. exit(EXIT_FAILURE);
  59. }
  60. if (!modify) {
  61. if (G_read_raster3d_timestamp(name, mapset, &ts) == 1) {
  62. G__write_timestamp(stdout, &ts);
  63. exit(EXIT_SUCCESS);
  64. }
  65. else
  66. exit(EXIT_FAILURE);
  67. }
  68. if (strcmp(date->answer, "none") == 0) {
  69. G_remove_raster3d_timestamp(name);
  70. exit(EXIT_SUCCESS);
  71. }
  72. if(G_scan_timestamp(&ts, date->answer) != 1)
  73. G_fatal_error(_("Timestamp format is invalid"));
  74. G_write_raster3d_timestamp(name, &ts);
  75. exit(EXIT_SUCCESS);
  76. }