raster3dlib.dox 55 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725
  1. /*! \page raster3dlib GRASS 3D Raster Volume Library
  2. <!-- doxygenized from "GRASS 5 Programmer's Manual"
  3. by M. Neteler 5/2004, 8/2005
  4. -->
  5. <i>TODO: Update for this page for GRASS 7.</i>
  6. \tableofcontents
  7. \section raster3dlib_Overview Overview
  8. The 3D Raster Volume Library is used for the <tt>r3.*</tt> and vector
  9. volume tools. The library uses a tile cache based approach to store
  10. floating point values in abritrary order in a volume. The coordinate
  11. system of a volume is column and row compatible to the raster library
  12. and counts from the bottom to the top of the cube.
  13. \image html "r3_volume_layout.png" "The volume coordinate system and tile layout of the 3D Raster Library"
  14. \section Directory_Structure Directory Structure
  15. <P>
  16. The file format consists of a mapset element <EM>grid3</EM> which contains a
  17. directory for every map. The elements for each map are
  18. <P>
  19. \verbatim
  20. 3d region file
  21. color file (color)
  22. categories file (cats)
  23. range file (range)
  24. timestamp file /* not yet implemented */
  25. cell file (cell)
  26. header file (cellhd)
  27. a directory containing display files (dsp)
  28. \endverbatim
  29. <P>
  30. There is also a <EM>colr2</EM> mechanism provided. <EM>colr2</EM> color tables
  31. are stored in <EM>grid3/colr2/MAPSET/MAP</EM>.
  32. <P>
  33. Note: color, categories, and the range can be used in the same way as in <EM>2d</EM>
  34. GRASS with the exception of reading and writng. <EM>3d</EM> read and write
  35. functions have to be used for this purpose.
  36. \section Data_File_Format Data File Format
  37. <UL>
  38. <LI>Cell-values can be either double or float.
  39. </LI>
  40. <LI>Values are written in XDR-format.
  41. </LI>
  42. <LI>NULL-values are stored in an embedded fashion.
  43. </LI>
  44. <LI>The cell-values are organized in <EM>3d</EM>-tiles.
  45. </LI>
  46. <LI>The tile dimensions can be chosen when a new map is opened.
  47. </LI>
  48. <LI>Every tile of a map has the same dimension except those which overlap the
  49. region boundaries.
  50. </LI>
  51. <LI>Compression is used to store tiles.
  52. </LI>
  53. </UL>
  54. <P>
  55. The data file has the following format:
  56. <P>
  57. \verbatim
  58. xdr_int nofBytesLong;
  59. xdr_int nofBytesUsed;
  60. encoded_long indexOffset;
  61. compressed_tile[] tiles;
  62. compressed_encoded_long[] index;
  63. \endverbatim
  64. <P>
  65. \section Transportability_of_data_file Transportability of data file
  66. <P>
  67. All numbers stored in the data file are either XDR-encoded or encoded by some
  68. other method (for variables of type long only).
  69. <P>
  70. \section Tile_Data_NULL_values Tile Data NULL-values
  71. <P>
  72. RASTER3D uses the same functions as <EM>2d</EM> GRASS to set and test NULL-values. The
  73. storage in the file is different though. NULL-values are stored with a special
  74. bit-pattern if maximum precision is chosen. They are stored by adding an
  75. additional bit if the precision is smaller.
  76. <P>
  77. \section Tile_Data_Compression Tile Data Compression
  78. <P>
  79. There are three methods of compression provided. The compression
  80. methods can either be those defined by default, set by environment
  81. variables or explicitly set at run-time.
  82. \verbatim
  83. Precision
  84. RLE
  85. \endverbatim
  86. <P>
  87. Precision indicates how many of the mantissa bits should be stored on
  88. file. This number can be any value between 0 and 23 for floats and
  89. between 0 and 52 for doubles. Choosing a small precision is the most
  90. effective way to achieve good compression.
  91. <P>
  92. RLE takes advantage of possible repetitions of the
  93. exponents and the NULL-bit structure. Using RLE does not significantly
  94. increase the running time. If for some tile the non-RLEed version is
  95. smaller in size, RLE is not used for this tile.
  96. <P>
  97. The default and suggested setting is to use precision and RLE.
  98. <P>
  99. Additional compression is achieved by storing the extra NULL-bit in a
  100. separate bit-array. Using this scheme NULL-values need not actually be
  101. represented in the array of cell values. This array is stored together
  102. with the cell-values of the tile.
  103. \section Tile_Cache Tile Cache
  104. <P>
  105. Tiles can either be read and written directly or use an intermediate
  106. cache instead.
  107. <P>
  108. In non-cache mode the application should only use the functions
  109. <P>
  110. int Rast3d_readTile()
  111. <P>
  112. and
  113. <P>
  114. int Rast3d_writeTile()
  115. <P>
  116. to read and write tiles. The application can use one tile provided by the map
  117. structure as buffer. See <TT>Rast3d_getTilePtr()</TT>.
  118. <P>
  119. In cache mode the application can access cell-values directly by their
  120. coordinates. The corresponding functions are
  121. <P>
  122. int Rast3d_getValue()
  123. <P>
  124. and
  125. <P>
  126. int Rast3d_putValue()
  127. <P>
  128. and their corresponding typed versions.
  129. <BR>
  130. <P>
  131. If the map is new then in addition to the memory-cache a file-cache is provided.
  132. This allows the application to write the cell-values in any arbitrary order.
  133. Tiles are written (flushed) to the data-file either at closing time or if
  134. explicitly requested.
  135. <BR>
  136. <P>
  137. If the map is new <TT>Rast3d_getValue()</TT> can be used even if the tile which
  138. contains the cell has already been flushed to the data file. In this case the
  139. tile is simply read back into the memory-cache from the data file.
  140. <BR>
  141. <P>
  142. Explicitly flushing tiles can have the advantage that less disk space is
  143. occupied since tiles are stored in a uncompressed fashion in the file-cache.
  144. Flushing tiles explicitly can cause problems with accuracy though if precision
  145. is less than the maximum precision and an already flushed value is used for
  146. computations later in the program.
  147. <BR>
  148. <P>
  149. The type of the cell-values of the tiles in memory can be chosen independently
  150. of the type of the tiles in the file. Here, once again one has to consider
  151. possible problems arising from mixing different precisions.
  152. <BR>
  153. <P>
  154. As an example consider the case where the data is stored in the file with double
  155. precision and the tiles are stored in memory in single precision. Then using
  156. <TT>Rast3d_getValue()</TT> will actually return a double precision number whose precision
  157. is only 23 bits. It is therefore a good idea to use the types in the memory
  158. consistently.
  159. <BR>
  160. <P>
  161. \section Header_File Header File
  162. <P>
  163. The header file has the following format:
  164. <P>
  165. \verbatim
  166. Proj: 1
  167. Zone: 1
  168. North: 2.0000000000000
  169. South: 0.5000000000000
  170. East: 4.0000000000000
  171. West: 3.0000000000000
  172. Top: 6.0000000000000
  173. Bottom: 5.0000000000000
  174. nofRows: 30
  175. nofCols: 20
  176. nofDepths: 14
  177. e-w resol: 0.05
  178. n-s resol: 0.05
  179. t-b resol: 0.071428571
  180. TileDimensionX: 8
  181. TileDimensionY: 8
  182. TileDimensionZ: 8
  183. CellType: double
  184. useCompression: 1
  185. useRle: 1
  186. Precision: -1
  187. nofHeaderBytes: 12
  188. useXdr: 1
  189. hasIndex: 1
  190. Units: none
  191. VerticalUnits: 1
  192. \endverbatim
  193. <P>
  194. Except for the first 14 fields the entries of the header file should
  195. not be modified. The precision value -1 indicates that maximum
  196. precision is used.
  197. <BR>
  198. <P>
  199. Binary files not in RASTER3D format can be read by the library. The
  200. following actions have to be taken:
  201. <P>
  202. Make a new map directory in the <EM>grid3</EM> element of the mapset (say <EM>mymap</EM>).
  203. Copy the file into <EM>mymap/cell</EM> and generate a header file <EM>mymap/cellhd</EM>.
  204. <P>
  205. In the following example the relevant values of <EM>mymap/cellhd</EM> are shown:
  206. <P>
  207. \verbatim
  208. TileDimensionX: A
  209. TileDimensionY: B
  210. TileDimensionZ: C
  211. useCompression: 0
  212. useRle: 0
  213. Precision: -1
  214. nofHeaderBytes: X
  215. useXdr: 0
  216. hasIndex: 0
  217. \endverbatim
  218. <P>
  219. The values of <EM>A</EM>, <EM>B</EM>, and <EM>C</EM> have to be chosen
  220. according to one of the following patterns:
  221. <P>
  222. \verbatim
  223. A &gt;= 1, B == 1, C == 1, or
  224. A &gt;= nofRows, B &gt;= 1, C == 1, or
  225. A &gt;= nofRows, B &gt;= nofCols, C &gt;= 1.
  226. \endverbatim
  227. <P>
  228. A larger tile size reduces the number of tile-reads. If in the third pattern
  229. <EM>C</EM> is chosen larger than or equal to <EM>nofDepths</EM>, the entire region is
  230. considered one large tile.
  231. <P>
  232. The value <EM>nofHeaderBytes</EM> indicates the offset in the file to the first
  233. data entry.
  234. <P>
  235. For performance reasons it is a good idea to use function
  236. <TT>Rast3d_retile()</TT> before using the file in other applications.
  237. <P>
  238. \section Region_Structure Region Structure
  239. <P>
  240. \verbatim
  241. typedef struct{
  242. double north, south;
  243. double east, west;
  244. double top, bottom;
  245. int rows, cols, depths;/* data dimensions in cells */
  246. double ns_res, ew_res, tb_res;
  247. int proj; /* Projection (see gis.h) */
  248. int zone; /* Projection zone (see gis.h) */
  249. } RASTER3D_Region;
  250. \endverbatim
  251. <P>
  252. \section Windows Windows
  253. <P>
  254. Window capability similar to that of <EM>2d</EM> GRASS is provided (compare
  255. Region). Additional features are the window for the third dimension
  256. as well as the possibility to choose a different window for every map. The
  257. window can be specified at the time of opening an old map. It can be modified
  258. at any time later in the program. The resampling method can be the default
  259. nearest neighbor method as well as an application provided method.
  260. <BR>
  261. <P>
  262. The default <EM>3d</EM> window file is <EM>WIND3</EM> located in the mapset.
  263. Application programs should use <TT>Rast3d_useWindowParams()</TT> to allow the
  264. user to overwrite this default.
  265. <P>
  266. The window file has the following format:
  267. <P>
  268. \verbatim
  269. Proj: 1
  270. Zone: 1
  271. North: 2.0
  272. South: 0.5
  273. East: 4.0
  274. West: 3.0
  275. Top: 5.0
  276. Bottom: 6.0
  277. nofRows: 30
  278. nofCols: 20
  279. nofDepths: 14
  280. e-w resol: 0.05000000000000000
  281. n-s resol: 0.05000000000000000
  282. t-b resol: 0.07142857142857142
  283. \endverbatim
  284. <P>
  285. Note: after reading the window file the fields <EM>e-w</EM>, <EM>n-s</EM>, and <EM>t-b</EM>
  286. are recomputed internally.
  287. <P>
  288. A note about windows and caching. Caching is performed on the level of tiles
  289. read from the file. There is no caching performed on resampled data. This is
  290. different from <EM>2d</EM> GRASS since resampling for a specific value is
  291. performed every time it is being accessed.
  292. <P>
  293. \section Masks Masks
  294. <P>
  295. RASTER3D provides a mask for the <EM>3d</EM> region. The mask structure is
  296. automatically initialized at the time the first file is opened. The same
  297. structure is used for all the files. The default for every file is that the
  298. mask is turned off. If masking should be performed, the application program has
  299. to turn on masking explicitly. If masking is turned on for a file, the
  300. cell-values of a tile are automatically checked against the mask. Values which
  301. are masked out, are set to NULL.
  302. <P>
  303. Note: changing the status of masking after one or more tiles have already
  304. been read does not affect the tiles which are already stored in the cache.
  305. <P>
  306. Any arbitrary 3d raster map can be used as mask file: NULL-values are interpreted as
  307. <TT>"mask-out"</TT>, all other values are interpreted as <TT>"don't mask
  308. out"</TT>. Using <EM>r3.mask</EM> to convert a 3d raster map into a mask file instead of
  309. simply copying (or renaming) the directory will significantly reduce to amount
  310. of disk space and the access time for the mask.
  311. <P>
  312. \section Include_File Include File
  313. <P>
  314. Exported RASTER3D constants and structures can be found in <EM>G3d.h</EM>.
  315. <P>
  316. \section RASTER3D_Defaults RASTER3D Defaults
  317. <P>
  318. There are three methods to set default variables. First, the default can be set
  319. at compile time in <EM>g3ddefault.c</EM>. This value has lowest priority.
  320. <P>
  321. Second, the default can be set via an environment variable. Third, the value
  322. can be set explicitly set at run time. This value has highest priority.
  323. <P>
  324. There are also functions provided to query the value.
  325. <P>
  326. \section Cache_Mode Cache Mode
  327. <P>
  328. \subsection Limiting_the_maximum_cache_size Limiting the maximum cache size
  329. <P>
  330. The limit is specified in bytes. It is a limit on the size of cell-data stored
  331. in the cache and does not include the support structure.
  332. <P>
  333. Default RASTER3D_CACHE_SIZE_MAX_DEFAULT. This is currently set to 16meg and can
  334. be changed at compilation time of the library.
  335. <P>
  336. Environment variable RASTER3D_MAX_CACHE_SIZE.
  337. <P>
  338. void Rast3d_setCacheLimit(int nBytes)Set cache limit
  339. <P>
  340. int Rast3d_getCacheLimit(int nBytes)Get cache limit
  341. <P>
  342. \subsection Setting_the_cache_size Setting the cache size
  343. <P>
  344. This value specifies the number of tiles stored in the cache. It is the value
  345. used if at opening time of a map RASTER3D_USE_CACHE_DEFAULT is used for the cache
  346. mode. Any other value used at opening time will supersede the default value. A
  347. default value of 0 indicates that non-cache mode should be used by default.
  348. <P>
  349. Default RASTER3D_CACHE_SIZE_DEFAULT. This is currently set to 1000 and can be
  350. changed at compilation time of the library.
  351. <P>
  352. Environment variable RASTER3D_DEFAULT_CACHE_SIZE.
  353. <P>
  354. void Rast3d_setCacheSize(int nTiles)
  355. <P>
  356. int Rast3d_getCacheSize()
  357. <P>
  358. \section Compression Compression
  359. \subsection Toggling_compression_mode Toggling compression mode
  360. <P>
  361. This value specifies whether compression should be used while writing a new
  362. map. It does not have any effect on old maps.
  363. <P>
  364. Default RASTER3D_COMPRESSION_DEFAULT. This is set to RASTER3D_COMPRESSION. This
  365. default should not be changed.
  366. <P>
  367. Environment variables RASTER3D_USE_COMPRESSION and RASTER3D_NO_COMPRESSION.
  368. <P>
  369. See functions Rast3d_setCompressionMode() (cf.
  370. Section 22.3.2.3 ) and Rast3d_getCompressionMode() (cf. Section 22.3.2.3 ).
  371. <P>
  372. \subsection Toggling_RLE_compression Toggling RLE compression
  373. <P>
  374. This value specifies whether RLE compression should be used (in addition to
  375. precision).
  376. <P>
  377. Default RASTER3D_USE_RLE_DEFAULT. This is currently set to RASTER3D_USE_RLE and can
  378. be changed at compilation time of the library.
  379. <P>
  380. Environment variables RASTER3D_USE_RLE and RASTER3D_NO_RLE.
  381. <P>
  382. See functions Rast3d_setCompressionMode() (cf.
  383. Section 22.3.2.3) and Rast3d_getCompressionMode() (cf. Section 22.3.2.3).
  384. \section Setting_the_precision Setting the precision
  385. <P>
  386. This number specifies how many mantissa bits should be used when writing a cell
  387. value. The minimum value is 0. The maximum value is 23 or RASTER3D_MAX_PRECISION
  388. for type FCELL_TYPE, it is 52 or RASTER3D_MAX_PRECISION for type DCELL_TYPE.
  389. <P>
  390. Default RASTER3D_PRECISION_DEFAULT. This is set to RASTER3D_MAX_PRECISION. This
  391. default should not be changed.
  392. <P>
  393. Environment variables RASTER3D_PRECISION and RASTER3D_MAX_PRECISION.
  394. <P>
  395. void Rast3d_setCompressionMode(int doCompress, int doLzw, int doRle, int
  396. precision) <EM>doCompress</EM> should be one of RASTER3D_NO_COMPRESSION and
  397. RASTER3D_COMPRESSION, <EM>doRle</EM> should be either RASTER3D_NO_RLE or
  398. RASTER3D_USE_RLE, and <EM>precision</EM> should be either RASTER3D_MAX_PRECISION or
  399. a positive integer.
  400. <P>
  401. void Rast3d_getCompressionMode(int *doCompress, int *doLzw, int *doRle,
  402. int *precision)
  403. <P>
  404. \section Tiles Tiles
  405. \subsection Setting_the_tile_dimensions Setting the tile dimensions
  406. <P>
  407. The dimensions are specified in number of cell.
  408. <P>
  409. Defaults RASTER3D_TILE_X_DEFAULT, RASTER3D_TILE_Y_DEFAULT, and
  410. RASTER3D_TILE_Z_DEFAULT. These are currently set to 8 and can be changed at
  411. compilation time of the library.
  412. <P>
  413. Environment variables RASTER3D_TILE_DIMENSION_X, RASTER3D_TILE_DIMENSION_Y, and
  414. RASTER3D_TILE_DIMENSION_Z.
  415. <P>
  416. void Rast3d_setTileDimension(int tileX, int tileY, int tileZ)
  417. <P>
  418. void Rast3d_getTileDimension(int *tileX, int *tileY, int *tileZ)
  419. <P>
  420. \section Setting_the_tile_cell_value_type Setting the tile cell-value type
  421. <P>
  422. Specifies which type is used to write cell-values on file. This type can be
  423. chosen independently of the type used to store cell-values in memory.
  424. <P>
  425. Default RASTER3D_FILE_TYPE_DEFAULT. This is set to DCELL_TYPE. This default
  426. should not be changed.
  427. <P>
  428. Environment variables RASTER3D_WRITE_FLOAT and RASTER3D_WRITE_DOUBLE.
  429. <P>
  430. void Rast3d_setFileType(int type)
  431. <P>
  432. int Rast3d_getFileType(int type)
  433. <P>
  434. \section Setting_the_window Setting the window
  435. <P>
  436. The window is set from a <EM>3d</EM> window file.
  437. <P>
  438. The default <EM>3d</EM> window file is <EM>WIND3</EM> located in the current mapset.
  439. <P>
  440. Possible choices for <EM>3d</EM> window files are <EM>name</EM> which refers to a
  441. window file in the <EM>3d</EM> window database located at <EM>windows3d</EM> of the
  442. current mapset; or file names which are identified by a leading <EM><TT>"/"</TT></EM>
  443. or <EM><TT>"."</TT></EM>; or fully qualified
  444. names, i.e. <EM>file@mapset</EM> which refer to window files in the <EM>3d</EM> window
  445. database of mapset. Note, that names <EM>WIND3</EM> and <EM>WIND3@mapset</EM> do not
  446. specify the default window name in the (current)
  447. mapset but rather a window file in the window database of the (current) mapset.
  448. <P>
  449. Environment variable RASTER3D_DEFAULT_WINDOW3D.
  450. <P>
  451. See functions
  452. <P>
  453. <TT>Rast3d_useWindowParams()</TT>,
  454. <P>
  455. <TT>Rast3d_setWindow()</TT>, and
  456. <P>
  457. <TT>Rast3d_setWindowMap()</TT>.
  458. <P>
  459. \section Setting_the_Units Setting the Units
  460. The data untis of a map can be described using a string.
  461. The vertical units are defined in gis.h and can be spatial or temporal.
  462. <P>
  463. No environment variable.
  464. <P>
  465. \verbatim
  466. void Rast3d_set_unit (map, unit)
  467. RASTER3d_Map; /* the map */
  468. char *unit; /* The data unit description */
  469. void Rast3d_set_vertical_unit (map, unit)
  470. RASTER3d_Map; /* the map */
  471. char *unit; /* Use the standard from units.c in lib/gis */
  472. void Rast3d_set_vertical_unit2 (map, unit)
  473. RASTER3d_Map; /* the map */
  474. int unit; /* defined in gis.h */
  475. \endverbatim
  476. \section Error_Handling Error Handling: Setting the error function
  477. <P>
  478. This variable specifies the function which is invoked when an error
  479. (not a fatal error) occurs. For example setting the error function to
  480. <TT>Rast3d_fatalError</TT> simplifies debugging with dbx and also might show
  481. errors which are missed because the application does not check the
  482. return value.
  483. <P>
  484. Default <TT>Rast3d_skipError</TT>.
  485. <P>
  486. Environment variables RASTER3D_USE_FATAL_ERROR and RASTER3D_USE_PRINT_ERROR.
  487. <P>
  488. void Rast3d_setErrorFun(void (*fun)(char *))
  489. <P>
  490. The following 3 functions are possible choices for error functions.
  491. <P>
  492. void Rast3d_skipError(char (*msg)(char *)) This function ignores the
  493. error.
  494. <P>
  495. void Rast3d_printError(char (*msg)(char *)) This function prints the
  496. error message <EM>msg</EM> to <EM>stderr</EM> and returns.
  497. <P>
  498. void Rast3d_fatalError(char (*msg)(char *)) This function prints the
  499. error message <EM>msg</EM> to <EM>stderr</EM>, flushes <EM>stdout</EM>
  500. and <EM>stderr</EM>, and terminates the program with a segementation fault.
  501. <P>
  502. \section RASTER3D_Function_Index RASTER3D Function Index
  503. \subsection Opening_and_Closing_RASTER3D_Files Opening and Closing RASTER3D Files
  504. <P>
  505. void *Rast3d_openCellOld(char *name, char *mapset, RASTER3D_Region *window,
  506. int type, int cache)Opens existing g3d-file <EM>name</EM> in <EM>mapset</EM>.
  507. <P>
  508. Tiles are stored in memory with <EM>type</EM> which must be any of FCELL_TYPE,
  509. DCELL_TYPE, or RASTER3D_TILE_SAME_AS_FILE. <EM>cache</EM> specifies the
  510. cache-mode used and must be either RASTER3D_NO_CACHE, RASTER3D_USE_CACHE_DEFAULT,
  511. RASTER3D_USE_CACHE_X, RASTER3D_USE_CACHE_Y, RASTER3D_USE_CACHE_Z,
  512. RASTER3D_USE_CACHE_XY, RASTER3D_USE_CACHE_XZ, RASTER3D_USE_CACHE_YZ,
  513. RASTER3D_USE_CACHE_XYZ, the result of <TT>Rast3d_cacheSizeEncode()</TT> (cf.
  514. Section 22.4.6), or any positive integer which
  515. specifies the number of tiles buffered in the cache. <EM>window</EM> sets the
  516. window-region for the map. It is either a pointer to a window structure or
  517. RASTER3D_DEFAULT_WINDOW, which uses the window stored at initialization time or
  518. set via <TT>Rast3d_setWindow()</TT> (cf. Section 22.4.16).
  519. To modify the window for the map after it has already been opened use
  520. <TT>Rast3d_setWindowMap()</TT> (cf. Section 22.4.16).
  521. <P>
  522. Returns a pointer to the cell structure ... if successful, NULL ...
  523. otherwise.
  524. <P>
  525. void *Rast3d_openCellNew(char *name, int type, int cache, RASTER3D_Region
  526. *region)Opens new g3d-file with <EM>name</EM> in the current mapset. Tiles
  527. are stored in memory with <EM>type</EM> which must be one of FCELL_TYPE,
  528. DCELL_TYPE, or RASTER3D_TILE_SAME_AS_FILE. <EM>cache</EM> specifies the
  529. cache-mode used and must be either RASTER3D_NO_CACHE, RASTER3D_USE_CACHE_DEFAULT,
  530. RASTER3D_USE_CACHE_X, RASTER3D_USE_CACHE_Y, RASTER3D_USE_CACHE_Z,
  531. RASTER3D_USE_CACHE_XY, RASTER3D_USE_CACHE_XZ, RASTER3D_USE_CACHE_YZ,
  532. RASTER3D_USE_CACHE_XYZ, the result of <TT>Rast3d_cacheSizeEncode()</TT> (cf.
  533. Section 22.4.6), or any positive integer which
  534. specifies the number of tiles buffered in the cache. <EM>region</EM> specifies
  535. the 3d region.
  536. <P>
  537. Returns a pointer to the cell structure ... if successful,
  538. NULL ... otherwise.
  539. <P>
  540. void *Rast3d_openCellNewParam(char *name, int typeIntern, int cache,
  541. RASTER3D_Region *region, int type, int doLzw, int doRle, int precision, int tileX,
  542. int tileY, int tileZ)Opens new g3d-file with <EM>name</EM> in the current
  543. mapset. Tiles are stored in memory with <EM>typeIntern</EM> which must be one of
  544. FCELL_TYPE, DCELL_TYPE, or RASTER3D_TILE_SAME_AS_FILE. <EM>cache</EM> specifies
  545. the cache-mode used and must be either RASTER3D_NO_CACHE,
  546. RASTER3D_USE_CACHE_DEFAULT, RASTER3D_USE_CACHE_X, RASTER3D_USE_CACHE_Y,
  547. RASTER3D_USE_CACHE_Z, RASTER3D_USE_CACHE_XY, RASTER3D_USE_CACHE_XZ,
  548. RASTER3D_USE_CACHE_YZ, RASTER3D_USE_CACHE_XYZ, the result of
  549. <TT>Rast3d_cacheSizeEncode()</TT> (cf.
  550. Section 22.4.6), or any positive integer which
  551. specifies the number of tiles buffered in the cache. <EM>region</EM> specifies
  552. the 3d region.
  553. <P>
  554. In addition the properties of the new file have to be specified. It is
  555. assumed by default that compression is used. This function first sets the
  556. global default values to the specified values, and then restores the original
  557. global defaults. This function can be used in conjunction with
  558. <TT>Rast3d_setStandard3dInputParams()</TT> (cf.
  559. Section 22.4.18) and
  560. <TT>Rast3d_getStandard3dParams()</TT>.
  561. <P>
  562. Returns a pointer to the cell structure ... if successful, NULL ...
  563. otherwise.
  564. <P>
  565. int Rast3d_closeCell(void *map)Closes g3d-file. If <EM>map</EM> is new
  566. and cache-mode is used for <EM>map</EM> then every tile which is not flushed
  567. before closing is flushed.
  568. <P>
  569. Returns 1 ... if successful, 0 ... otherwise.
  570. <P>
  571. \subsection Reading_and_Writing_Tiles Reading and Writing Tiles
  572. <P>
  573. These functions read or write data directly to the file (after performing the
  574. appropriate compression) without going through the cache. In order to avoid
  575. unexpected side-effects the use of these functions in cache mode is
  576. discouraged.
  577. <P>
  578. int Rast3d_readTile(void *map, char *tileIndex, int tile, int type)
  579. Reads tile with index <EM>tileIndex</EM> into the <EM>tile</EM> buffer. The cells
  580. are stored with type <EM>type</EM> which must be one of FCELL_TYPE and
  581. DCELL_TYPE. If the tile with <EM>tileIndex</EM> is not stored on the file
  582. corresponding to <EM>map</EM>, and <EM>tileIndex</EM> is a valid index <EM>tile</EM>
  583. is filled with NULL-values.
  584. <P>
  585. Returns
  586. 1 ... if successful,
  587. 0 ... otherwise.
  588. <P>
  589. int Rast3d_readTileFloat(void *map, char *tileIndex, int tile)
  590. Is equivalent to Rast3d_readTile (map, tileIndex, tile, FCELL_TYPE).
  591. <P>
  592. int Rast3d_readTileDouble(void *map, char *tileIndex, int tile)
  593. Is equivalent to Rast3d_readTile (map, tileIndex, tile, DCELL_TYPE).
  594. <P>
  595. int Rast3d_writeTile(void *map, char *tileIndex, int tile, int type)
  596. Writes tile with index <EM>tileIndex</EM> to the file corresponding to <EM>map</EM>. It is assumed that the cells in <EM>tile</EM> are of <EM>type</EM> which
  597. must be one of FCELL_TYPE and DCELL_TYPE. The actual type used to write the
  598. tile depends on the type specified at the time when <EM>map</EM> is initialized.
  599. <P>
  600. A tile can only be written once. Subsequent attempts to write the same tile
  601. are ignored.
  602. <P>
  603. Returns
  604. 1 ... if successful,
  605. 2 ... if write request was ignored,
  606. 0 ... otherwise.
  607. <P>
  608. int Rast3d_writeTileFloat(void *map, char *tileIndex, int tile)
  609. Is equivalent to <TT>Rast3d_writeTile (map, tileIndex, tile, FCELL_TYPE).</TT>
  610. <P>
  611. int Rast3d_writeTileDouble(void *map, char *tileIndex, int tile)
  612. Is equivalent to <TT>Rast3d_writeTile (map, tileIndex, tile, DCELL_TYPE).</TT>
  613. <P>
  614. \subsection Reading_and_Writing_Cells Reading and Writing Cells
  615. <P>
  616. void Rast3d_getValue(void *map, int x, int y, int z, char *value, int
  617. type) Returns in <EM>*value</EM> the cell-value of the cell with
  618. window-coordinate <EM>(x, y, z)</EM>. The value returned is of <EM>type</EM>.
  619. <P>
  620. This function invokes a fatal error if an error occurs.
  621. <P>
  622. float Rast3d_getFloat(void *map, int x, int y, int z)Is equivalent to
  623. <TT>Rast3d_getValue (map, x, y, z, &amp;value, FCELL_TYPE);</TT> return value.
  624. <P>
  625. double Rast3d_getDouble(void *map, int x, int y, int z)Is equivalent
  626. to <TT>Rast3d_getValue (map, x, y, z, &amp;value, DCELL_TYPE);</TT> return value.
  627. <P>
  628. void Rast3d_getValueRegion(void *map, int x, int y, int z, char*value,
  629. int type) Returns in <EM>*value</EM> the cell-value of the cell with
  630. region-coordinate <EM>(x, y, z)</EM>. The value returned is of <EM>type</EM>.
  631. Here <EM>region</EM> means the coordinate in the cube of data in the file, i.e.
  632. ignoring geographic coordinates.
  633. <P>
  634. This function invokes a fatal error if an error occurs.
  635. <P>
  636. float Rast3d_getFloatRegion(void *map, int x, int y, int z)Is
  637. equivalent to <TT>Rast3d_getValueRegion (map, x, y, z, &amp;value, FCELL_TYPE);</TT>
  638. return value.
  639. <P>
  640. \code
  641. Rast3d_getDoubleRegion(map, x, y, z)
  642. \endcode
  643. is equivalent to
  644. \code
  645. Rast3d_getValueRegion(map, x, y, z, &amp;value, DCELL_TYPE)
  646. \endcode
  647. <P>
  648. int Rast3d_putValue(void *map, int x, int y, int z, char *value, int
  649. type)After converting <EM>*value</EM> of <EM>type</EM> into the type specified
  650. at the initialization time (i.e. <EM>typeIntern</EM>) this function writes the
  651. value into the tile buffer corresponding to cell-coordinate <EM>(x, y, z)</EM>.
  652. <P>
  653. Returns
  654. <P>
  655. 1 ... if successful,
  656. 0 ... otherwise.
  657. <P>
  658. int Rast3d_putFloat(void *map, int x, int y, int z, char *value)Is
  659. equivalent to Rast3d_putValue (map, x, y, z, &amp;value, FCELL_TYPE).
  660. <P>
  661. int Rast3d_putDouble(void *map, int x, int y, int z, char *value) Is
  662. equivalent to Rast3d_putValue (map, x, y, z, &amp;value, DCELL_TYPE).
  663. <P>
  664. \subsection Loading_and_Removing_TilesLoading and Removing Tiles
  665. <P>
  666. char *Rast3d_getTilePtr(void *map, int tileIndex) This function
  667. returns a pointer to a tile which contains the data for the tile with index
  668. <EM>tileIndex</EM>. The type of the data stored in the tile depends on the type
  669. specified at the initialization time of <EM>map</EM>. The functionality is
  670. different depending on whether <EM>map</EM> is old or new and depending on the
  671. cache-mode of <EM>map</EM>.
  672. <BR>
  673. <P>
  674. If <EM>map</EM> is old and the cache is not used the tile with <EM>tileIndex</EM>
  675. is read from file and stored in the buffer provided by the map structure.
  676. The pointer to this buffer is returned. If the buffer already contains the
  677. tile with <EM>tileIndex</EM> reading is skipped. Data which was stored in
  678. earlier calls to <TT>Rast3d_getTilePtr</TT> is destroyed. If the tile with
  679. <EM>tileIndex</EM> is not stored on the file corresponding to <EM>map</EM>, and
  680. <EM>tileIndex</EM> is a valid index the buffer is filled with NULL-values.
  681. <BR>
  682. <P>
  683. If <EM>map</EM> is old and the cache is used the tile with <EM>tileIndex</EM> is
  684. read from file and stored in one of the cache buffers. The pointer to buffer
  685. is returned. If no free cache buffer is available an unlocked cache-buffer
  686. is freed up and the new tile is stored in its place. If the tile with
  687. <EM>tileIndex</EM> is not stored on the file corresponding to <EM>map</EM>, and
  688. <EM>tileIndex</EM> is a valid index the buffer is filled with NULL-values. If one
  689. of the cache buffers already contains the tile with <EM>tileIndex</EM> reading
  690. is skipped and the pointer to this buffer is returned.
  691. <BR>
  692. <P>
  693. If <EM>map</EM> is new and the cache is not used the functionality is the same
  694. as if <EM>map</EM> is old and the cache is not used. If the tile with
  695. <EM>tileIndex</EM> is already stored on file, it is read into the buffer, if not,
  696. the cells are set to null-values. If the buffer corresponding to the pointer
  697. is used for writing, subsequent calls to <TT>Rast3d_getTilePtr</TT> may destroy the
  698. values already stored in the buffer. Use <TT>Rast3d_flushTile</TT> to write the buffer
  699. to the file before reusing it for a different index. The use of this buffer
  700. as write buffer is discouraged.
  701. <BR>
  702. <P>
  703. If <EM>map</EM> is new and the cache is used the functionality is the same as if
  704. <EM>map</EM> is old and the cache is used with the following exception. If
  705. <EM>tileIndex</EM> is a valid index and the tile with this index is not found in
  706. the cache and is not stored on the file corresponding to <EM>map</EM>, then the
  707. file cache is queried next. If the file-cache contains the tile it is loaded
  708. into the cache (memory-cache). Only if the file-cache does not contain the
  709. tile it is filled with NULL-values. Tile contents of buffers are never
  710. destroyed. If a cache buffer needs to be freed up, and the tile stored in the
  711. buffer has not been written to the file corresponding to <EM>map</EM> yet, the
  712. tile is copied into the file-cache.
  713. <BR>
  714. <P>
  715. Care has to be taken if this function is used in non-cache mode since it is
  716. implicitly invoked every time a read or write request is issued. The only
  717. I/O-functions for which it is safe to assume that they do not invoke
  718. <TT>Rast3d_getTilePtr</TT> are <TT>Rast3d_readTile()</TT> and
  719. <TT>Rast3d_writeTile()</TT> and their corresponding type-specific versions.
  720. <P>
  721. Returns
  722. a pointer to a buffer ... if successful,
  723. NULL ... otherwise.
  724. <P>
  725. int Rast3d_tileLoad(void *map, int tileIndex)
  726. Same functionality as <TT>Rast3d_getTilePtr()</TT> but does not return the
  727. pointer.
  728. <P>
  729. Returns
  730. 1 ... if successful,
  731. 0 ... otherwise.
  732. <P>
  733. int Rast3d_removeTile(void *map, inttileIndex) Removes a tile
  734. from memory-cache if tile is in memory-cache. For new maps the
  735. application does not know whether the tile is in the memory-cache or in
  736. the file-cache. Therefore, for new maps this function should be
  737. preceded by <TT>Rast3d_tileLoad()</TT>.
  738. <P>
  739. <EM>(Question: Is this a useful function?)</EM>
  740. <P>
  741. Returns 1 ... if successful, 0 ... otherwise.
  742. <P>
  743. \subsection Write_Functions_used_in_Cache_Mode Write Functions used in Cache Mode
  744. <P>
  745. int Rast3d_flushTile(void *map, int tileIndex) Writes the tile with
  746. <EM>tileIndex</EM> to the file corresponding to <EM>map</EM> and removes the tile
  747. from the cache (in non-cache mode the buffer provided by the map-structure is
  748. written).
  749. <P>
  750. If this tile has already been written before the write request is ignored.
  751. If the tile was never referred to before the invokation of Rast3d_flushTile, a
  752. tile filled with NULL-values is written.
  753. <P>
  754. Returns
  755. 1 ... if successful,
  756. 0 ... otherwise.
  757. <P>
  758. int Rast3d_flushTileCube(void *map, int xMin, int yMin, int zMin, int
  759. xMax, int yMax, int zMax) Writes the tiles with tile-coordinates
  760. contained in the axis-parallel cube with vertices <EM>(xMin, yMin, zMin)</EM>
  761. and <EM>(xMax, yMax, zMax</EM>). Tiles which are not stored in the cache are
  762. written as NULL-tiles. Write attempts for tiles which have already been
  763. written earlier are ignored.
  764. <P>
  765. Returns
  766. 1 ... if successful,
  767. 0 ... otherwise.
  768. <P>
  769. int Rast3d_flushTilesInCube(void *map, int xMin, int yMin, int
  770. zMin, int xMax, int yMax, int zMax) Writes those tiles for which
  771. <EM>every</EM> cell has coordinate contained in the axis-parallel cube
  772. defined by the vertices with cell-coordinates <EM>(xMin, yMin, zMin)</EM>
  773. and <EM>(xMax, yMax, zMax)</EM>.
  774. <P>
  775. Tiles which are not stored in the cache are written as NULL-tiles.
  776. Write attempts for tiles which have already been written earlier are
  777. ignored.
  778. <P>
  779. Returns
  780. 1 ... if successful,
  781. 0 ... otherwise.
  782. <P>
  783. \subsection Locking_and_Unlocking_Tiles_and_CyclesLocking and Unlocking Tiles, and Cycles
  784. <P>
  785. int Rast3d_lockTile(void *map, int tileIndex) Locks tile with <EM>tileIndex</EM> in cache.
  786. If after locking fewer than the minimum number of
  787. unlocked tiles are unlocked, the lock request is ignored.
  788. <P>
  789. Returns
  790. 1 ... if successful,
  791. -1 ... if request is ignored,
  792. 0 ... otherwise.
  793. <P>
  794. int Rast3d_unlockTile(void *map, int tileIndex)
  795. Unlocks tile with <EM>tileIndex</EM>.
  796. <P>
  797. Returns
  798. 1 ... if successful,
  799. 0 ... otherwise.
  800. <P>
  801. int Rast3d_unlockAll(void *map)
  802. Unlocks every tile in cache of <EM>map</EM>.
  803. <P>
  804. Returns
  805. 1 ... if successful,
  806. 0 ... otherwise.
  807. <P>
  808. void Rast3d_autolockOn(void *map)
  809. Turns autolock mode on.
  810. <P>
  811. void Rast3d_autolockOff(void *map)
  812. Turns autolock mode Off.
  813. <P>
  814. void Rast3d_minUnlocked(void *map, int minUnlocked) Sets the minimum
  815. number of unlocked tiles to <EM>minUnlocked</EM>. This function should be used
  816. in combination with <TT>Rast3d_unlockAll()</TT> in order to avoid situations where the
  817. new minimum is larger than the actual number of unlocked tiles.
  818. <P>
  819. <EM>minUnlocked</EM> must be one of RASTER3D_USE_CACHE_X, RASTER3D_USE_CACHE_Y,
  820. RASTER3D_USE_CACHE_Z, RASTER3D_USE_CACHE_XY, RASTER3D_USE_CACHE_XZ,
  821. RASTER3D_USE_CACHE_YZ, RASTER3D_USE_CACHE_XYZ, the result of Rast3d_cacheSizeEncode()
  822. (cf. Section 22.4.6), or any positive integer
  823. which explicitly specifies the number of tiles.
  824. <P>
  825. int Rast3d_beginCycle(void *map)
  826. Starts a new cycle.
  827. <P>
  828. Returns
  829. 1 ... if successful,
  830. 0 ... otherwise.
  831. <P>
  832. int Rast3d_endCycle(void *map)
  833. Ends a cycle.
  834. <P>
  835. Returns
  836. 1 ... if successful,
  837. 0 ... otherwise.
  838. <P>
  839. int Rast3d_cacheSizeEncode(int cacheCode, int n) Returns a number
  840. which encodes multiplicity <EM>n</EM> of <EM>cacheCode</EM>. This value can be used
  841. to specify the size of the cache.
  842. <P>
  843. If <EM>cacheCode</EM> is the size (in tiles) of the cache the function returns
  844. <EM>cacheCode * n</EM>.
  845. <P>
  846. If <EM>cacheCode</EM> is RASTER3D_USE_CACHE_DEFAULT the function returns
  847. RASTER3D_USE_CACHE_DEFAULT.
  848. <P>
  849. If <EM>cacheCode</EM> is RASTER3D_USE_CACHE_??? the function returns a value
  850. encoding RASTER3D_USE_CACHE_??? and <EM>n</EM>. Here RASTER3D_USE_CACHE_??? is one
  851. of RASTER3D_USE_CACHE_X, RASTER3D_USE_CACHE_Y, RASTER3D_USE_CACHE_Z,
  852. RASTER3D_USE_CACHE_XY, RASTER3D_USE_CACHE_XZ, RASTER3D_USE_CACHE_YZ, or
  853. RASTER3D_USE_CACHE_XYZ, where e.g. RASTER3D_USE_CACHE_X specifies that the cache
  854. should store as many tiles as there exist in one row along the x-axis of the
  855. tile cube, and RASTER3D_USE_CACHE_XY specifies that the cache should store as
  856. many tiles as there exist in one slice of the tile cube with constant Z
  857. coordinate.
  858. <P>
  859. \subsection Reading_Volumes Reading Volumes
  860. <P>
  861. int Rast3d_getVolume(void *map, double originNorth, double originWest,
  862. double originBottom, double vxNorth, double vxWest, double vxBottom, double
  863. vyNorth, double vyWest, double vyBottom, double vzNorth, double vzWest,
  864. double vzBottom, int nx, int ny, int nz, char *volumeBuf, int type)
  865. Resamples the cube defined by <EM>origin</EM> and the 3 vertices <EM>vx</EM>,
  866. <EM>vy</EM>, and <EM>vz</EM> which are incident to the 3 edges adjacent to
  867. <EM>origin</EM>. The resampled cube is stored in <EM>volumeBuf</EM> which is a cube
  868. with dimensions <EM>(nx, ny, nz)</EM>.
  869. <P>
  870. The method of sampling is nearest neighbor sampling.
  871. <P>
  872. The values stored are of <EM>type</EM>.
  873. <P>
  874. Returns 1 ... if successful, 0 ... otherwise.
  875. <P>
  876. int Rast3d_getAllignedVolume(void *map, double originNorth, double
  877. originWest, double originBottom, double lengthNorth, double lengthWest,
  878. double lengthBottom, int nx, int ny, int nz, char *volumeBuf, int type)
  879. Resamples the axis-parallel cube defined by <EM>origin</EM> and the lengths of
  880. the 3 edges adjacent to <EM>origin</EM>. The resampled cube is stored in
  881. <EM>volumeBuf</EM> which is a cube with dimensions <EM>(nx, ny, nz)</EM>. The method
  882. of sampling is nearest neighbor sampling. The values stored are of <EM>type</EM>.
  883. <P>
  884. Returns 1 ... if successful, 0 ... otherwise.
  885. <P>
  886. \subsection Allocating_and_Freeing_Memory Allocating and Freeing Memory
  887. <P>
  888. void *Rast3d_malloc(int nBytes)
  889. Same as <EM>malloc (nBytes)</EM>, except that in case of error
  890. <TT>Rast3d_error()</TT> is invoked.
  891. <P>
  892. Returns
  893. a pointer ... if successful,
  894. NULL ... otherwise.
  895. <P>
  896. void *Rast3d_realloc(void *ptr, int nBytes)
  897. Same as <EM>realloc (ptr, nBytes)</EM>, except that in case of error
  898. <TT>Rast3d_error()</TT> is invoked.
  899. <P>
  900. Returns
  901. a pointer ... if successful,
  902. NULL ... otherwise.
  903. <P>
  904. void Rast3d_free(void *ptr) Same as <EM>free (ptr)</EM>.
  905. <P>
  906. char *Rast3d_allocTilesType(void *map, int nofTiles, int type)
  907. Allocates a vector of <EM>nofTiles</EM> tiles with the same dimensions
  908. as the tiles of <EM>map</EM> and large enough to store cell-values of
  909. <EM>type</EM>.
  910. <P>
  911. Returns
  912. a pointer to the vector ... if successful,
  913. NULL ... otherwise.
  914. <P>
  915. \code
  916. Rast3d_allocTiles(map, nofTiles)
  917. \endcode
  918. is equivalent to
  919. \code
  920. Rast3d_allocTilesType(map, nofTiles, Rast3d_fileTypeMap(map)).
  921. \endcode
  922. <P>
  923. void Rast3d_freeTiles(char *tiles)
  924. Is equivalent to <TT>Rast3d_free (tiles);</TT>
  925. <P>
  926. \subsection RASTER3D_Null_Value_Support RASTER3D Null Value Support
  927. <P>
  928. void Rast3d_isNullValueNum(void *n, int type)
  929. Returns 1 if the value of <EM>*n</EM> is a NULL-value. Returns 0
  930. otherwise.
  931. <P>
  932. void Rast3d_setNullValue(void *c, int nofElts, int type)
  933. Fills the vector pointed to by <EM>c</EM> with <EM>nofElts</EM> NULL-values
  934. of <EM>type</EM>.
  935. <P>
  936. void Rast3d_setNullTileType(void *map, int tile, int type)
  937. Assumes that <EM>tile</EM> is a tile with the same dimensions as the
  938. tiles of <EM>map</EM>. Fills <EM>tile</EM> with NULL-values of
  939. <EM>type</EM>.
  940. <P>
  941. void Rast3d_setNullTile(void *map, int tile)
  942. Is equivalent to Rast3d_setNullTileType (map, tile, Rast3d_fileTypeMap (map)).
  943. <P>
  944. \subsection RASTER3D_Map_Header_Information RASTER3D Map Header Information
  945. <P>
  946. void Rast3d_getCoordsMap(void *map, int *rows, int *cols, int *depths)
  947. Returns the size of the region of <EM>map</EM> in cells.
  948. <P>
  949. void Rast3d_getRegionMap(void *map, int *north, int *south, int *east,
  950. int *west, int *top, int *bottom)Returns the size of the region.
  951. <P>
  952. void Rast3d_getRegionStructMap(void *map, RASTER3D_Region *region)
  953. Returns in <EM>region</EM> the region of <EM>map</EM>.
  954. <P>
  955. void Rast3d_getTileDimensionsMap(void *map, int *x, int *y, int *z)
  956. Returns the tile dimensions used for <EM>map</EM>.
  957. <P>
  958. void Rast3d_getNofTilesMap(void *map, int *nx, int *ny, int *nz)
  959. Returns the dimensions of the tile-cube used to tile the region of <EM>map</EM>.
  960. These numbers include partial tiles.
  961. <P>
  962. int Rast3d_tileTypeMap(void *map)
  963. Returns the type in which tiles of <EM>map</EM> are stored in memory.
  964. <P>
  965. int Rast3d_fileTypeMap(void *map)
  966. Returns the type with which tiles of <EM>map</EM> are stored on file.
  967. <P>
  968. int Rast3d_tilePrecisionMap(void *map)
  969. Returns the precision used to store <EM>map</EM>.
  970. <P>
  971. int Rast3d_tileUseCacheMap(void *map)
  972. Returns 1 if <EM>map</EM> uses cache, returns 0 otherwise.
  973. <P>
  974. void Rast3d_printHeader(void *map)
  975. Prints the header information of <EM>map</EM>.
  976. <P>
  977. \subsection RASTER3D_Tile_Math RASTER3D Tile Math
  978. <P>
  979. void Rast3d_tileIndex2tile(void *map, int tileIndex, int *xTile, int
  980. *yTile, int *zTile) Converts index <EM>tileIndex</EM> into tile-coordinates
  981. <EM>(xTile, yTile, zTile)</EM>.
  982. <P>
  983. int Rast3d_tile2tileIndex(void *map, int xTile, int yTile, int
  984. zTile) Returns tile-index corresponding to tile-coordinates <EM>(xTile,
  985. yTile, zTile)</EM>.
  986. <P>
  987. void Rast3d_coord2tileCoord(void *map, int x, int y, int z, int *xTile,
  988. int *yTile, int *zTile, int *xOffs, int *yOffs, int *zOffs) Converts
  989. cell-coordinates <EM>(x, y, z)</EM> into tile-coordinates <EM>(xTile, yTile,
  990. zTile)</EM> and the coordinate of the cell <EM>(xOffs, yOffs, zOffs)</EM> within
  991. the tile.
  992. <P>
  993. void Rast3d_tileCoordOrigin(void *map, int xTile, int yTile, int zTile,
  994. int *x, int *y, int *z) Computes the cell-coordinates <EM>(x, y, z)</EM>
  995. which correspond to the origin of the tile with tile-coordinates <EM>(xTile,
  996. yTile, zTile)</EM>.
  997. <P>
  998. void Rast3d_tileIndexOrigin(void *map, int tileIndex, int *x, int *y,
  999. int *z) Computes the cell-coordinates <EM>(x, y, z)</EM> which correspond to
  1000. the origin of the tile with <EM>tileIndex</EM>.
  1001. <P>
  1002. void Rast3d_coord2tileIndex(void *map, int x, int y, int z, int
  1003. *tileIndex, int *offset) Converts cell-coordinates <EM>(x, y, z)</EM> into
  1004. <EM>tileIndex</EM> and the <EM>offset</EM> of the cell within the tile.
  1005. <P>
  1006. int Rast3d_coordInRange(void *map, int x, int y, int z) Returns 1 if
  1007. cell-coordinate <EM>(x, y, z)</EM> is a coordinate inside the region. Returns 0
  1008. otherwise.
  1009. <P>
  1010. int Rast3d_tileInRange(void *map, int x, int y, int z) Returns 1 if
  1011. tile-coordinate <EM>(x, y, z)</EM> is a coordinate inside tile cube. Returns 0
  1012. otherwise.
  1013. <P>
  1014. int Rast3d_tileIndexInRange(void *map, int tileIndex)
  1015. Returns 1 if <EM>tileIndex</EM> is a valid index for <EM>map</EM>.
  1016. Returns 0 otherwise.
  1017. <P>
  1018. int Rast3d_isValidLocation(void *map, double north, double west, double
  1019. bottom) Returns 1 if region-coordinates <EM>(north, west, bottom)</EM> are
  1020. inside the region of <EM>map</EM>. Returns 0 otherwise.
  1021. <P>
  1022. void Rast3d_location2coord(void *map, double north, double west, double
  1023. bottom, int *x, *y, *z) Converts region-coordinates <EM>(north, west,
  1024. bottom)</EM> into cell-coordinates <EM>(x, y, z)</EM>.
  1025. <P>
  1026. int Rast3d_computeClippedTileDimensions(void *map, int tileIndex, int
  1027. *rows, int *cols, int *depths, int *xRedundant, int *yRedundant, int
  1028. *zRedundant) Computes the dimensions of the tile when clipped to fit the
  1029. region of <EM>map</EM>. The clipped dimensions are returned in <EM>rows</EM>,
  1030. <EM>cols</EM>, <EM>depths</EM>. The complement is returned in <EM>xRedundant</EM>,
  1031. <EM>yRedundant</EM>, and <EM>zRedundant</EM>. This function returns the number of
  1032. cells in the clipped tile.
  1033. <P>
  1034. \subsection RASTER3D_Range_Support RASTER3D Range Support
  1035. The map structure RASTER3D_Map provides storage for the range. The range of
  1036. a map is updated every time a cell is written to the file. When an old map is
  1037. opened the range is not automatically loaded. The application has to invoke
  1038. Rast3d_range_load() explicitly. Alternatively, an application can use
  1039. the Rast3d_read_range() function and FPRange structure to read the range.
  1040. Rast3d_range_min_max() is used to get the minimum and maximum values of the
  1041. map range into integer.
  1042. Rast3d_range_write() function stores the range in file and is invoked
  1043. automatically when a new map is closed.
  1044. In addition to these functions, the application can also use some of the
  1045. standard GRASS 2D raster functions to manipulate the floating point range. It
  1046. is preferred to use <tt>Rast3d_</tt> functions if possible and importantly it is
  1047. not possible to use functions for reading and writing.
  1048. \subsection RASTER3D_Color_Support RASTER3D Color Support
  1049. Applications can use the standard GRASS functions to work with colors,
  1050. e.g. Rast_get_d_color_range(). However, the file manipulations must be handled
  1051. using specialized raster 3D functions.
  1052. Rast3d_read_colors() function reads color file for a map into a Colors structure.
  1053. Rast3d_write_colors() function stores colors in color files for a map and
  1054. Rast3d_remove_color() function removes the color file.
  1055. \subsection RASTER3D_Categories_Support RASTER3D Categories Support
  1056. <P>
  1057. Applications can use the standard GRASS functions to work with categories,
  1058. except for the file manipulations.
  1059. <P>
  1060. Function Rast3d_read_cats() reads the categories file for map and
  1061. function Rast3d_write_cats() writes the
  1062. categories the Categories structure into the categories file for a map.
  1063. <P>
  1064. \subsection RASTER3D_History_Support RASTER3D History Support
  1065. <P>
  1066. Applications can use the standard GRASS functions to work with histories,
  1067. except for the file manipulations.
  1068. <P>
  1069. int Rast3d_readHistory(char *name, char *mapset, struct History *hist)
  1070. Reads the history file for map <EM>name</EM> in <EM>mapset</EM> and
  1071. stores the history in the <EM>hist</EM> structure. See <EM>G_read_history</EM>
  1072. (Raster_History_File) for details and return values.
  1073. <P>
  1074. int Rast3d_writeHistory(char *name, struct History *hist)
  1075. Writes the
  1076. history stored in the <EM>hist</EM> structure into the categories file for
  1077. map <EM>name</EM> in the current mapset. See <EM>G_write_history</EM>
  1078. (Raster_History_File) for details and return values.
  1079. <P>
  1080. \subsection RASTER3D_Mask_Support RASTER3D Mask Support
  1081. <P>
  1082. void Rast3d_maskOn(void *map) Turns on the mask for <EM>map</EM>. Do
  1083. not invoke this function after the first tile has been read since the result
  1084. might be inconsistent cell-values.
  1085. <P>
  1086. void Rast3d_maskOff(void *map) Turns off the mask for <EM>map</EM>.
  1087. This is the default. Do not invoke this function after the first tile has
  1088. been read since the result might be inconsistent cell-values.
  1089. <P>
  1090. int Rast3d_maskIsOn(void *map) Returns 1 if the mask for <EM>map</EM>
  1091. is turned on. Returns 0 otherwise.
  1092. <P>
  1093. int Rast3d_maskIsOff(void *map)
  1094. Returns 1 if the mask for <EM>map</EM> is turned off. Returns 0 otherwise.
  1095. <P>
  1096. The remaining functions in this section are for the explicit query of the mask
  1097. and the masking of individual cells or tiles. These functions are used in the
  1098. library and might have applications in situations where both the masked and
  1099. non-masked value of a cell has to be known.
  1100. <P>
  1101. int Rast3d_maskReopen(int cache)
  1102. This function should be used to adjust the cache size used for the
  1103. 3d-mask. First the open 3d-mask is closed and then opened again with
  1104. a cache size as specified with <EM>cache</EM>.
  1105. <P>
  1106. Returns
  1107. 1 ... if successful
  1108. 0 ... otherwise.
  1109. <P>
  1110. int Rast3d_maskFileExists() Returns 1 if the 3d mask file
  1111. exists.
  1112. <P>
  1113. int Rast3d_maskMapExists()
  1114. Returns 1 if the 3d mask is loaded.
  1115. <P>
  1116. char *Rast3d_maskFile()
  1117. Returns the name of the 3d mask file.
  1118. <P>
  1119. int Rast3d_isMasked(int x, int y, int z)
  1120. Returns 1 if the cell with cell-coordinates <EM>(x, y, z)</EM> is masked
  1121. out. Returns 0 otherwise.
  1122. <P>
  1123. void Rast3d_maskNum(int x, int y, int z, void *value, int type)
  1124. Replaces the value stored in <EM>value</EM> with the NULL-value if
  1125. <EM>Rast3d_isMasked (x, y, z)</EM> returns 1. Does nothing otherwise.
  1126. <EM>value</EM> is assumed to be of<EM>type</EM>.
  1127. <P>
  1128. void Rast3d_maskFloat(int x, int y, int z, float *value)
  1129. Same as <EM>Rast3d_maskNum (x, y, z, value, FCELL_TYPE)</EM>.
  1130. <P>
  1131. void Rast3d_maskDouble(int x, int y, int z, double *value)
  1132. Same as <EM>Rast3d_maskNum (x, y, z, value, DCELL_TYPE)</EM>.
  1133. <P>
  1134. void Rast3d_maskTile(void *map, int tileIndex, char *tile, int type)
  1135. Replaces the values stored in <EM>tile</EM> (with <EM>tileIndex</EM>) for
  1136. which <EM>Rast3d_isMasked</EM> returns 1 with NULL-values. Does not change
  1137. the remaining values. The values are assumed to be of <EM>type</EM>.
  1138. Whether replacement is performed or not only depends on location of the
  1139. cells of the tile and not on the status of the mask for <EM>map</EM>
  1140. (i.e. turned on or off).
  1141. <P>
  1142. \subsection RASTER3D_Window_Support RASTER3D Window Support
  1143. <P>
  1144. void Rast3d_setWindowMap(void *map, RASTER3D_Region *window)
  1145. Sets the window for <EM>map</EM> to <EM>window</EM>.
  1146. Can be used multiple times for the same map.
  1147. <P>
  1148. void Rast3d_setWindow(RASTER3D_Region *window)
  1149. Sets the default window used for every map opened later in the program.
  1150. Can be used multiple times in the same program.
  1151. <P>
  1152. void Rast3d_getWindow(RASTER3D_Region *window)
  1153. Stores the current default window in <EM>window</EM>.
  1154. <P>
  1155. void *Rast3d_windowPtr()
  1156. Returns a pointer to the current default window. This pointer should not be
  1157. (ab)used to modify the current window structure directly. It is
  1158. provided to pass a window pointer when opening a map.
  1159. <P>
  1160. int Rast3d_readWindow(RASTER3D_Region *window, char *windowName) Reads
  1161. <EM>window</EM> from the file specified by <EM>windowName</EM>. The name is
  1162. converted by the rules defined in window defaults. A NULL pointer indicates
  1163. the <EM>WIND3</EM> file in the current mapset.
  1164. <P>
  1165. Returns
  1166. 1 ... if successful
  1167. 0 ... otherwise.
  1168. <P>
  1169. int Rast3d_writeWindow(RASTER3D_Region *window, char *windowName)
  1170. Writes <EM>window</EM> to the file specified by <EM>windowName</EM>. The name
  1171. is converted by the rules defined in window defaults. A NULL pointer
  1172. indicates the <EM>WIND3</EM> file in the current mapset.
  1173. <P>
  1174. Returns
  1175. 1 ... if successful
  1176. 0 ... otherwise.
  1177. <P>
  1178. void Rast3d_useWindowParams()
  1179. Allows the window to be set at run-time via the <EM>region3</EM>
  1180. command line argument. This function has to be called before
  1181. <EM>G_parser()</EM>. See also
  1182. window defaults.
  1183. <P>
  1184. void Rast3d_setResamplingFun(void *map, void (*resampleFun)())
  1185. Sets the resampling function to be used by
  1186. Rast3d_getValue() (cf. Section 22.4.3). This function is defined
  1187. as follows:
  1188. <P>
  1189. void Rast3d_customResampleFun(void *map, int row, int col, int depth,
  1190. char *value, int type) <EM>row</EM>, <EM>col</EM>, and <EM>depth</EM> are in
  1191. region coordinates. The result is returned in <EM>value</EM> as <EM>type</EM> which
  1192. is one of FCELL_TYPE or DCELL_TYPE. Possible choices include
  1193. Rast3d_nearestNeighbor() (cf. Section22.4.16) and
  1194. Rast3d_getValueRegion() (cf. Section 22.4.3).
  1195. <P>
  1196. The default resampling function which uses nearest
  1197. neighbor resampling.
  1198. \code
  1199. Rast3d_nearestNeighbor(map, row, col, depth, value, type)
  1200. \endcode
  1201. <P>
  1202. void Rast3d_getResamplingFun(void *map, void (**resampleFun)())
  1203. Returns in <EM>resampleFun</EM> a pointer to the resampling function used by
  1204. <EM>map</EM>.
  1205. <P>
  1206. void Rast3d_getNearestNeighborFunPtr(void (**nnFunPtr)()) Returns
  1207. in <EM>nnFunPtr</EM> a pointer to Rast3d_nearestNeighbor() (cf.
  1208. Section&nbsp;<A HREF="#g3d:G3d.nearestNeighbor">22.4.16</A>).
  1209. <P>
  1210. \subsection RASTER3D_Region RASTER3D Region
  1211. <P>
  1212. void Rast3d_extract2dRegion(RASTER3D_Region *region3d, struct Cell_head
  1213. *region2d) Returns in <EM>region2d</EM> the <EM>2d</EM> portion of <EM>region3d</EM>.
  1214. <P>
  1215. void Rast3d_incorporate2dRegion(struct Cell_head *region2d, RASTER3D_Region
  1216. *region3d) Replaces the <EM>2d</EM> portion of <EM>region3d</EM> with the
  1217. values stored in <EM>region2d</EM>.
  1218. <P>
  1219. void Rast3d_adjustRegion(RASTER3D_Region *region)
  1220. Computes an adjusts the resolutions in the region structure from the region
  1221. boundaries and number of cells per dimension.
  1222. <P>
  1223. void Rast3d_adjustRegionRes(RASTER3D_Region *region)
  1224. Computes an adjusts the number of cells per dimension in the region
  1225. structure from the region boundaries and resolutions.
  1226. <P>
  1227. void Rast3d_regionCopy(RASTER3D_Region *regionDest, RASTER3D_Region *regionSrc)
  1228. Copies the values of <EM>regionSrc</EM> into <EM>regionDst</EM>.
  1229. (The unfortunate order of parameters was chosen in order to conform to the
  1230. order used in <EM>G_copy()</EM>).
  1231. <P>
  1232. void Rast3d_getRegionValue(void *map, double north, double east, double
  1233. top, char *value, int type) Returns in <EM>value</EM> the value of the <EM>map</EM>
  1234. which corresponds to region coordinates <EM>(north, east, top)</EM>. The
  1235. value is resampled using the resampling function specified for <EM>map</EM>. The
  1236. <EM>value</EM> is of <EM>type</EM>.
  1237. <P>
  1238. void Rast3d_readRegionMap(char *name, char *mapset, RASTER3D_Region *region)
  1239. Returns in <EM>region</EM> the region information for 3d cell <EM>name@mapset</EM>.
  1240. <P>
  1241. \subsection Miscellaneous_Functions Miscellaneous Functions
  1242. <P>
  1243. void Rast3d_g3dType2cellType(int g3dType) Returns the GRASS floating
  1244. point type which is equivalent to the RASTER3D type of <EM>g3dType</EM>.
  1245. <P>
  1246. void Rast3d_initDefaults() Initializes the default values described
  1247. in RASTER3D Defaults. Applications have to use this function only if they need to
  1248. query the default values before the first file (either old or new) has been
  1249. opened.
  1250. <P>
  1251. void Rast3d_setStandard3dInputParams()
  1252. Initializes a parameter
  1253. structure for the subset of command line arguments which lets the user
  1254. overwrite the default properties of the new file. Applications are
  1255. encouraged to use this function in order to provide a uniform style. The
  1256. command line arguments provided are the <EM>type</EM> of the cell values, the
  1257. <EM>precision</EM>, the properties of the <EM>compression</EM>, and the dimension
  1258. of the tiles (<EM>tiledimension</EM>). Every of these values defaults to the
  1259. value described in RASTER3D Defaults.
  1260. <P>
  1261. This function has to be used in conjunction with
  1262. Rast3d_getStandard3dInputParams() (cf.
  1263. Section 22.4.18).
  1264. <P>
  1265. int Rast3d_getStandard3dInputParams(int *useTypeDefault, *type, *useLzwDefault, *doLzw,
  1266. int *useRleDefault, *doRle, *usePrecisionDefault, *precision,
  1267. int *useDimensionDefault, *tileX, *tileY, *tileZ
  1268. Returns the properties of the new file as chosen by the user via command
  1269. line arguments. If the default is chosen the values of
  1270. <EM>useXxxxDefault</EM> is 1, it is 0 otherwise. In addition, the
  1271. corresponding parameters contain the default value if
  1272. <EM>useXxxxDefault</EM> is 1, or the value specified by the user if
  1273. <EM>useXxxxDefault</EM> is 0.
  1274. <P>
  1275. Function
  1276. Rast3d_setStandard3dInputParams() (cf. Section 22.4.18)
  1277. has to be used to initialize the internal parameter structure.
  1278. <P>
  1279. Returns
  1280. 1 ... if successful,
  1281. 0 ... otherwise.
  1282. <P>
  1283. int Rast3d_makeMapsetMapDirectory(char *mapName)
  1284. Creates the 3d mapset element for map <EM>mapName</EM>.
  1285. <P>
  1286. int Rast3d_filename(char *path, *elementName, *mapName, *mapset)
  1287. Returns in <EM>path</EM> the path for element <EM>elementName</EM> for map
  1288. <EM>mapName</EM> in <EM>mapset</EM>. Note, an error occurs if <EM>mapName</EM>
  1289. is fully qualified.
  1290. <P>
  1291. See TimeStamp_functions for a complete discussion of GRASS datetime
  1292. routines (reading, writing grid3d timestamps).
  1293. <P>
  1294. \section Sample_RASTER3D_Applications Sample RASTER3D Applications
  1295. <P>
  1296. These functions were implemented to test the library. They are not very
  1297. efficient but can be used as starting point for other
  1298. applications. Some of them might actually be useful. They are available from
  1299. GRASS 7 source code in lib/g3d/.
  1300. <P>
  1301. void Rast3d_retile(void *map, char *nameOut, int tileX, int tileY, int tileZ)
  1302. Makes a copy of <EM>map</EM> with name <EM>nameOut</EM> which has
  1303. tile dimensions <EM>tileX</EM>, <EM>tileY</EM>, <EM>tileZ</EM>.
  1304. <P>
  1305. The source code can be found in <EM>retile.c</EM>.
  1306. <P>
  1307. void Rast3d_changePrecision(void *map, int precision, char *nameOut)
  1308. Makes a copy of <EM>map</EM> with name <EM>nameOut</EM> which is
  1309. written with <EM>precision</EM>.
  1310. <P>
  1311. The source code can be found in <EM>changeprecision.c</EM>.
  1312. <P>
  1313. void Rast3d_changeType(void *map, char *nameOut)
  1314. Makes a copy of <EM>map</EM> with name <EM>nameOut</EM> in which the
  1315. cells are of type FCELL_TYPE if they are DCELL_TYPE in <EM>map</EM>,
  1316. and in DCELL_TYPE otherwise.
  1317. <P>
  1318. The source code can be found in <EM>changetype.c</EM>.
  1319. <P>
  1320. void Rast3d_compareFiles(char *f1, char *mapset1, char *f2, char *mapset2)
  1321. Compares the cell-values of file <EM>f1</EM> in mapset
  1322. <EM>mapset1</EM> and file <EM>f2</EM> in mapset <EM>mapset2</EM>.
  1323. The values are compared up to precision.
  1324. Terminates in error if the files don't match.
  1325. This function uses the more advanced features of the cache.
  1326. <P>
  1327. The source code can be found in <EM>filecompare.c</EM>.
  1328. <P>
  1329. void Rast3d_getBlock(void *map, int x0, int y0, int z0, int nx, int ny,
  1330. int nz, char *block, int type)
  1331. Copies the cells contained in the block (cube) with vertices
  1332. <EM>(x0, y0, z0)</EM> and <EM>(x0 + nx - 1, y0 + ny - 1, z0 + nz - 1)</EM>
  1333. into <EM>block</EM>. The cell-values in <EM>block</EM> are of <EM>type</EM>.
  1334. <P>
  1335. The source code can be found in <EM>getblock.c</EM>.
  1336. <P>
  1337. void Rast3d_writeAscii(void *map, char *fname)
  1338. Writes the cell-values of <EM>map</EM> in ascii format to file
  1339. <EM>fname</EM>. The values are organized by horizontal slices.
  1340. <P>
  1341. See \ref Compiling_and_Installing_GRASS_Modules for a complete
  1342. discussion of Makefiles.
  1343. Authors: Roman Waupotitsch and Michael Shapiro, Helena Mitasova,
  1344. Bill Brown, Lubos Mitas, Jaro Hofierka,
  1345. Minor modification, code cleanup and test suite by Soeren Gebbert
  1346. */