param.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. #include <string.h>
  2. #include <grass/gis.h>
  3. #include <grass/glocale.h>
  4. #include "raster3d_intern.h"
  5. /*----------------------------------------------------------------------------*/
  6. typedef struct
  7. {
  8. struct Option *type;
  9. struct Option *precision;
  10. struct Option *compression;
  11. struct Option *dimension;
  12. struct Option *cache;
  13. } Rast3d_paramType;
  14. /*----------------------------------------------------------------------------*/
  15. static Rast3d_paramType *param;
  16. /*!
  17. * \brief
  18. *
  19. * Initializes a parameter
  20. * structure for the subset of command line arguments which lets the user
  21. * overwrite the default properties of the new file. Applications are
  22. * encouraged to use this function in order to provide a uniform style. The
  23. * command line arguments provided are the <em>type</em> of the cell values, the
  24. * <em>precision</em>, the properties of the <em>compression</em>, and the dimension
  25. * of the tiles (<em>tiledimension</em>). Every of these values defaults to the
  26. * value described in RASTER3D Defaults.
  27. * This function has to be used in conjunction with
  28. * Rast3d_getStandard3dInputParams() (cf.{g3d:G3d.getStandard3dInputParams}).
  29. *
  30. * \return void
  31. */
  32. void Rast3d_set_standard3d_input_params()
  33. {
  34. param = Rast3d_malloc(sizeof(Rast3d_paramType));
  35. param->type = G_define_standard_option(G_OPT_R3_TYPE);
  36. param->precision = G_define_standard_option(G_OPT_R3_PRECISION);
  37. param->compression = G_define_standard_option(G_OPT_R3_COMPRESSION);
  38. param->dimension = G_define_standard_option(G_OPT_R3_TILE_DIMENSION);
  39. }
  40. /*----------------------------------------------------------------------------*/
  41. int Rast3d_get_standard3d_params(int *useTypeDefault, int *type,
  42. int *useCompressionDefault, int *doCompression,
  43. int *usePrecisionDefault, int *precision,
  44. int *useDimensionDefault, int *tileX, int *tileY,
  45. int *tileZ)
  46. {
  47. *useTypeDefault = *useCompressionDefault = 0;
  48. *usePrecisionDefault = *useDimensionDefault = 0;
  49. Rast3d_init_defaults();
  50. if (strcmp(param->type->answer, "double") == 0)
  51. *type = DCELL_TYPE;
  52. else if (strcmp(param->type->answer, "float") == 0)
  53. *type = FCELL_TYPE;
  54. else {
  55. *type = Rast3d_get_file_type();
  56. *useTypeDefault = 1;
  57. }
  58. Rast3d_get_compression_mode(doCompression, precision);
  59. if (strcmp(param->precision->answer, "default") != 0) {
  60. if (strcmp(param->precision->answer, "max") == 0)
  61. *precision = -1;
  62. else if ((sscanf(param->precision->answer, "%d", precision) != 1) ||
  63. (*precision < 0)) {
  64. Rast3d_error(_("Rast3d_get_standard3d_params: precision value invalid"));
  65. return 0;
  66. }
  67. }
  68. else
  69. *usePrecisionDefault = 1;
  70. if (strcmp(param->compression->answer, "default") != 0) {
  71. if (strcmp(param->compression->answer, "zip") == 0)
  72. *doCompression = RASTER3D_COMPRESSION;
  73. else
  74. *doCompression = RASTER3D_NO_COMPRESSION;
  75. } else {
  76. *useCompressionDefault = 1;
  77. }
  78. Rast3d_get_tile_dimension(tileX, tileY, tileZ);
  79. if (strcmp(param->dimension->answer, "default") != 0) {
  80. if (sscanf(param->dimension->answer, "%dx%dx%d",
  81. tileX, tileY, tileZ) != 3) {
  82. Rast3d_error(_("Rast3d_get_standard3d_params: tile dimension value invalid"));
  83. return 0;
  84. }
  85. }
  86. else
  87. *useDimensionDefault = 1;
  88. Rast3d_free(param);
  89. return 1;
  90. }
  91. /*----------------------------------------------------------------------------*/
  92. static struct Option *windowParam = NULL;
  93. void Rast3d_set_window_params(void)
  94. {
  95. windowParam = G_define_option();
  96. windowParam->key = "region3";
  97. windowParam->type = TYPE_STRING;
  98. windowParam->required = NO;
  99. windowParam->multiple = NO;
  100. windowParam->answer = NULL;
  101. windowParam->description = _("Window replacing the default");
  102. }
  103. /*----------------------------------------------------------------------------*/
  104. char *Rast3d_get_window_params(void)
  105. {
  106. if (windowParam == NULL)
  107. return NULL;
  108. if (windowParam->answer == NULL)
  109. return NULL;
  110. if (strcmp(windowParam->answer, RASTER3D_WINDOW_ELEMENT) == 0)
  111. return G_store(RASTER3D_WINDOW_ELEMENT);
  112. return G_store(windowParam->answer);
  113. }