main.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /****************************************************************************
  2. *
  3. * MODULE: r.timestamp
  4. * AUTHOR(S): Michael Shapiro, CERL (original contributor)
  5. * Markus Neteler <neteler itc.it>, Roberto Flor <flor itc.it>,
  6. * Glynn Clements <glynn gclements.plus.com>,
  7. * Hamish Bowman <hamish_b yahoo.com>, Jan-Oliver Wagner <jan intevation.de>
  8. * PURPOSE:
  9. * COPYRIGHT: (C) 1999-2006, 2010 by the GRASS Development Team
  10. *
  11. * This program is free software under the GNU General Public
  12. * License (>=v2). Read the file COPYING that comes with GRASS
  13. * for details.
  14. *
  15. *****************************************************************************/
  16. #include <stdlib.h>
  17. #include <stdio.h>
  18. #include <string.h>
  19. #include <grass/gis.h>
  20. #include <grass/glocale.h>
  21. int main(int argc, char *argv[])
  22. {
  23. struct GModule *module;
  24. struct Option *map, *date;
  25. struct TimeStamp ts;
  26. char *name;
  27. const char *mapset;
  28. int modify;
  29. G_gisinit(argv[0]);
  30. module = G_define_module();
  31. G_add_keyword(_("raster"));
  32. G_add_keyword(_("metadata"));
  33. G_add_keyword(_("timestamp"));
  34. G_add_keyword(_("time"));
  35. module->label = _("Modifies a timestamp for a raster map.");
  36. module->description = _("Print/add/remove a timestamp for a raster map.");
  37. map = G_define_standard_option(G_OPT_R_MAP);
  38. date = G_define_option();
  39. date->key = "date";
  40. date->key_desc = "timestamp";
  41. date->required = NO;
  42. date->type = TYPE_STRING;
  43. date->label = _("Datetime, datetime1/datetime2, or 'none' to remove");
  44. date->description = _("Format: '15 jan 1994' (absolute) or '2 years' (relative)");
  45. if (G_parser(argc, argv))
  46. exit(EXIT_FAILURE);
  47. name = map->answer;
  48. modify = date->answer != NULL;
  49. if (modify)
  50. mapset = G_find_raster(name, G_mapset());
  51. else
  52. mapset = G_find_raster(name, "");
  53. if (mapset == NULL) {
  54. G_fatal_error(_("Raster map <%s> not found %s"), name,
  55. modify ? "in current mapset" : "");
  56. exit(EXIT_FAILURE);
  57. }
  58. if (!modify) {
  59. if (G_read_raster_timestamp(name, "", &ts) == 1) {
  60. G_write_timestamp(stdout, &ts);
  61. exit(EXIT_SUCCESS);
  62. }
  63. else
  64. exit(EXIT_FAILURE);
  65. }
  66. if (strcmp(date->answer, "none") == 0) {
  67. G_remove_raster_timestamp(name);
  68. exit(EXIT_SUCCESS);
  69. }
  70. if(G_scan_timestamp(&ts, date->answer) != 1)
  71. G_fatal_error("Timestamp format is invalid");
  72. G_write_raster_timestamp(name, &ts);
  73. exit(EXIT_SUCCESS);
  74. }