main.c 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. int modify;
  28. G_gisinit(argv[0]);
  29. module = G_define_module();
  30. G_add_keyword(_("raster"));
  31. G_add_keyword(_("metadata"));
  32. G_add_keyword(_("timestamp"));
  33. module->label = _("Modifies a timestamp for a raster map.");
  34. module->description = _("Print/add/remove a timestamp for a raster map.");
  35. map = G_define_standard_option(G_OPT_R_MAP);
  36. date = G_define_option();
  37. date->key = "date";
  38. date->key_desc = "timestamp";
  39. date->required = NO;
  40. date->type = TYPE_STRING;
  41. date->label = _("Datetime, datetime1/datetime2, or 'none' to remove");
  42. date->description = _("Format: '15 jan 1994' (absolute) or '2 years' (relative)");
  43. if (G_parser(argc, argv))
  44. exit(EXIT_FAILURE);
  45. name = map->answer;
  46. modify = date->answer != NULL;
  47. if (!modify) {
  48. if (G_read_raster_timestamp(name, "", &ts) == 1) {
  49. G__write_timestamp(stdout, &ts);
  50. exit(EXIT_SUCCESS);
  51. }
  52. else
  53. exit(EXIT_FAILURE);
  54. }
  55. if (strcmp(date->answer, "none") == 0) {
  56. G_remove_raster_timestamp(name);
  57. exit(EXIT_SUCCESS);
  58. }
  59. if (1 == G_scan_timestamp(&ts, date->answer)) {
  60. G_write_raster_timestamp(name, &ts);
  61. exit(EXIT_SUCCESS);
  62. }
  63. else
  64. G_fatal_error(_("Invalid timestamp"));
  65. exit(EXIT_SUCCESS);
  66. }