main.c 2.6 KB

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