headerinfo.c 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383
  1. #include <grass/raster3d.h>
  2. #include "raster3d_intern.h"
  3. /*---------------------------------------------------------------------------*/
  4. /*!
  5. * \brief
  6. *
  7. * Returns the size of the region of <em>map</em> in cells.
  8. *
  9. * \param map
  10. * \param rows
  11. * \param cols
  12. * \param depths
  13. * \return void
  14. */
  15. void Rast3d_get_coords_map(RASTER3D_Map * map, int *rows, int *cols, int *depths)
  16. {
  17. *rows = map->region.rows;
  18. *cols = map->region.cols;
  19. *depths = map->region.depths;
  20. }
  21. /*---------------------------------------------------------------------------*/
  22. void Rast3d_get_coords_map_window(RASTER3D_Map * map, int *rows, int *cols, int *depths)
  23. {
  24. *rows = map->window.rows;
  25. *cols = map->window.cols;
  26. *depths = map->window.depths;
  27. }
  28. /*---------------------------------------------------------------------------*/
  29. /*!
  30. * \brief
  31. *
  32. * Returns the dimensions of the tile-cube used to tile the region of <em>map</em>.
  33. * These numbers include partial tiles.
  34. *
  35. * \param map
  36. * \param nx
  37. * \param ny
  38. * \param nz
  39. * \return void
  40. */
  41. void Rast3d_get_nof_tiles_map(RASTER3D_Map * map, int *nx, int *ny, int *nz)
  42. {
  43. *nx = map->nx;
  44. *ny = map->ny;
  45. *nz = map->nz;
  46. }
  47. /*---------------------------------------------------------------------------*/
  48. /*!
  49. * \brief
  50. *
  51. * Returns the size of the region.
  52. *
  53. * \param map
  54. * \param north
  55. * \param south
  56. * \param east
  57. * \param west
  58. * \param top
  59. * \param bottom
  60. * \return void
  61. */
  62. void
  63. Rast3d_get_region_map(RASTER3D_Map * map, double *north, double *south, double *east,
  64. double *west, double *top, double *bottom)
  65. {
  66. *north = map->region.north;
  67. *south = map->region.south;
  68. *east = map->region.east;
  69. *west = map->region.west;
  70. *top = map->region.top;
  71. *bottom = map->region.bottom;
  72. }
  73. /*---------------------------------------------------------------------------*/
  74. void
  75. Rast3d_get_window_map(RASTER3D_Map * map, double *north, double *south, double *east,
  76. double *west, double *top, double *bottom)
  77. {
  78. *north = map->window.north;
  79. *south = map->window.south;
  80. *east = map->window.east;
  81. *west = map->window.west;
  82. *top = map->window.top;
  83. *bottom = map->window.bottom;
  84. }
  85. /*---------------------------------------------------------------------------*/
  86. /*!
  87. * \brief
  88. *
  89. * Returns in <em>region</em> the region of <em>map</em>.
  90. *
  91. * \param map
  92. * \param region
  93. * \return void
  94. */
  95. void Rast3d_get_region_struct_map(RASTER3D_Map * map, RASTER3D_Region * region)
  96. {
  97. Rast3d_region_copy(region, &(map->region));
  98. }
  99. /*---------------------------------------------------------------------------*/
  100. void Rast3d_getWindowStructMap(RASTER3D_Map * map, RASTER3D_Region * window)
  101. {
  102. Rast3d_region_copy(window, &(map->window));
  103. }
  104. /*---------------------------------------------------------------------------*/
  105. /*!
  106. * \brief
  107. *
  108. * Returns the tile dimensions used for <em>map</em>.
  109. *
  110. * \param map
  111. * \param x
  112. * \param y
  113. * \param z
  114. * \return void
  115. */
  116. void Rast3d_get_tile_dimensions_map(RASTER3D_Map * map, int *x, int *y, int *z)
  117. {
  118. *x = map->tileX;
  119. *y = map->tileY;
  120. *z = map->tileZ;
  121. }
  122. /*---------------------------------------------------------------------------*/
  123. /*!
  124. * \brief
  125. *
  126. * Returns the type in which tiles of <em>map</em> are stored in memory.
  127. *
  128. * \param map
  129. * \return int
  130. */
  131. int Rast3d_tile_type_map(RASTER3D_Map * map)
  132. {
  133. return map->typeIntern;
  134. }
  135. /*---------------------------------------------------------------------------*/
  136. /*!
  137. * \brief
  138. *
  139. * Set the data unit defintiong
  140. *
  141. * \param map
  142. * \param unit
  143. * \return void
  144. */
  145. void Rast3d_set_unit(RASTER3D_Map * map, const char *unit)
  146. {
  147. map->unit = G_store(unit);
  148. }
  149. /*---------------------------------------------------------------------------*/
  150. /*!
  151. * \brief
  152. *
  153. * set Vertical unit from integer value defined in gis.h (U_METERS, ...)
  154. *
  155. * \param map
  156. * \param unit
  157. * \return void
  158. */
  159. void Rast3d_set_vertical_unit2(RASTER3D_Map * map, int vertical_unit)
  160. {
  161. map->vertical_unit = vertical_unit;
  162. }
  163. /*---------------------------------------------------------------------------*/
  164. /*!
  165. * \brief
  166. *
  167. * set Vertical unit from string
  168. *
  169. * \param map
  170. * \param unit
  171. * \return void
  172. */
  173. void Rast3d_set_vertical_unit(RASTER3D_Map * map, const char *vertical_unit)
  174. {
  175. map->vertical_unit = G_units(vertical_unit);
  176. }
  177. /*---------------------------------------------------------------------------*/
  178. /*!
  179. * \brief
  180. *
  181. * Return the data unit definition of <em>map</em>.
  182. *
  183. * \param map
  184. * \return int
  185. */
  186. const char* Rast3d_get_unit(RASTER3D_Map * map)
  187. {
  188. return map->unit;
  189. }
  190. /*---------------------------------------------------------------------------*/
  191. /*!
  192. * \brief
  193. *
  194. * Returns the vertical unit of <em>map</em> as integer. Units are defined in gis.h.
  195. *
  196. * Vertical units may have temporal type
  197. *
  198. * \param map
  199. * \return int
  200. */
  201. int Rast3d_get_vertical_unit2(RASTER3D_Map * map)
  202. {
  203. return map->vertical_unit;
  204. }
  205. /*---------------------------------------------------------------------------*/
  206. /*!
  207. * \brief
  208. *
  209. * Return the name of the unit of <em>map</em>. Units are defined in gis.h.
  210. *
  211. * Vertical units may have temporal type
  212. *
  213. * \param map
  214. * \return int
  215. */
  216. const char* Rast3d_get_vertical_unit(RASTER3D_Map * map)
  217. {
  218. return G_get_units_name(map->vertical_unit, 1, 0);
  219. }
  220. /*---------------------------------------------------------------------------*/
  221. /*!
  222. * \brief
  223. *
  224. * Returns the type with which tiles of <em>map</em> are stored on file.
  225. *
  226. * \param map
  227. * \return int
  228. */
  229. int Rast3d_file_type_map(RASTER3D_Map * map)
  230. {
  231. return map->type;
  232. }
  233. /*---------------------------------------------------------------------------*/
  234. /*!
  235. * \brief
  236. *
  237. * Returns the precision used to store <em>map</em>.
  238. *
  239. * \param map
  240. * \return int
  241. */
  242. int Rast3d_tile_precision_map(RASTER3D_Map * map)
  243. {
  244. return map->precision;
  245. }
  246. /*---------------------------------------------------------------------------*/
  247. /*!
  248. * \brief
  249. *
  250. * Returns 1 if <em>map</em> uses cache, returns 0 otherwise.
  251. *
  252. * \param map
  253. * \return int
  254. */
  255. int Rast3d_tile_use_cache_map(RASTER3D_Map * map)
  256. {
  257. return map->useCache;
  258. }
  259. /*!
  260. * \brief
  261. *
  262. * Prints the header information of <em>map</em>.
  263. *
  264. * \param map
  265. * \return void
  266. */
  267. void Rast3d_print_header(RASTER3D_Map * map)
  268. {
  269. double rangeMin, rangeMax;
  270. printf("File %s open for %sing:\n", map->fileName,
  271. (map->operation == RASTER3D_WRITE_DATA ? "writing" :
  272. (map->operation == RASTER3D_READ_DATA ? "reading" : "unknown")));
  273. printf("Version %i\n", map->version);
  274. printf(" Fd = %d, Unit %s, Vertical Unit %s, Type: %s, ", map->data_fd,
  275. map->unit, G_get_units_name(map->vertical_unit, 1, 0),
  276. (map->type == FCELL_TYPE ? "float" :
  277. (map->type == DCELL_TYPE ? "double" : "unknown")));
  278. printf("Type intern: %s\n",
  279. (map->typeIntern == FCELL_TYPE ? "float" :
  280. (map->typeIntern == DCELL_TYPE ? "double" : "unknown")));
  281. if (map->compression == RASTER3D_NO_COMPRESSION)
  282. printf(" Compression: none\n");
  283. else {
  284. printf(" Compression:%s (%s%s) Precision: %s", (map->compression ? "on" : "off"),
  285. (map->useLzw ? " lzw," : ""), (map->useRle ? " rle," : ""),
  286. (map->precision == -1 ? "all bits used\n" : "using"));
  287. if (map->precision != -1)
  288. printf(" %d bits\n", map->precision);
  289. }
  290. if (!map->useCache)
  291. printf(" Cache: none\n");
  292. else {
  293. printf(" Cache: used%s\n",
  294. (map->operation == RASTER3D_WRITE_DATA ? ", File Cache used" : ""));
  295. }
  296. Rast3d_range_min_max(map, &rangeMin, &rangeMax);
  297. printf(" Region: (%f %f) (%f %f) (%f %f)\n",
  298. map->region.south, map->region.north, map->region.west,
  299. map->region.east, map->region.bottom, map->region.top);
  300. printf(" (cols %5d rows %5d depths %5d)\n", map->region.cols, map->region.rows,
  301. map->region.depths);
  302. printf(" Num tiles (X %5d Y %5d Z %5d)\n", map->nx, map->ny, map->nz);
  303. printf(" Tile size (X %5d Y %5d Z %5d)\n", map->tileX, map->tileY, map->tileZ);
  304. printf(" Range (");
  305. if (Rast3d_is_null_value_num(&rangeMin, DCELL_TYPE))
  306. printf("NULL, ");
  307. else
  308. printf("%f, ", (double)rangeMin);
  309. if (Rast3d_is_null_value_num(&rangeMax, DCELL_TYPE))
  310. printf("NULL)\n");
  311. else
  312. printf("%f)\n", (double)rangeMax);
  313. fflush(stdout);
  314. }