main.c 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. module->label = _("Modifies a timestamp for a raster map.");
  35. module->description = _("Print/add/remove a timestamp for a raster map.");
  36. map = G_define_standard_option(G_OPT_R_MAP);
  37. date = G_define_option();
  38. date->key = "date";
  39. date->key_desc = "timestamp";
  40. date->required = NO;
  41. date->type = TYPE_STRING;
  42. date->label = _("Datetime, datetime1/datetime2, or 'none' to remove");
  43. date->description = _("Format: '15 jan 1994' (absolute) or '2 years' (relative)");
  44. if (G_parser(argc, argv))
  45. exit(EXIT_FAILURE);
  46. name = map->answer;
  47. modify = date->answer != NULL;
  48. if (modify)
  49. mapset = G_find_raster(name, G_mapset());
  50. else
  51. mapset = G_find_raster(name, "");
  52. if (mapset == NULL) {
  53. G_fatal_error(_("Raster map <%s> not found %s"), name,
  54. modify ? "in current mapset" : "");
  55. exit(EXIT_FAILURE);
  56. }
  57. if (!modify) {
  58. if (G_read_raster_timestamp(name, "", &ts) == 1) {
  59. G__write_timestamp(stdout, &ts);
  60. exit(EXIT_SUCCESS);
  61. }
  62. else
  63. exit(EXIT_FAILURE);
  64. }
  65. if (strcmp(date->answer, "none") == 0) {
  66. G_remove_raster_timestamp(name);
  67. exit(EXIT_SUCCESS);
  68. }
  69. if(G_scan_timestamp(&ts, date->answer) != 1)
  70. G_fatal_error("Timestamp format is invalid");
  71. G_write_raster_timestamp(name, &ts);
  72. exit(EXIT_SUCCESS);
  73. }