/hdf-java/native/hdf5lib/h5sImp.c

# · C · 1239 lines · 916 code · 148 blank · 175 comment · 227 complexity · e17b834dc248aef68b09820fb16f6442 MD5 · raw file

  1. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  2. * Copyright by The HDF Group. *
  3. * Copyright by the Board of Trustees of the University of Illinois. *
  4. * All rights reserved. *
  5. * *
  6. * This file is part of HDF Java Products. The full HDF Java copyright *
  7. * notice, including terms governing use, modification, and redistribution, *
  8. * is contained in the file, COPYING. COPYING can be found at the root of *
  9. * the source code distribution tree. You can also access it online at *
  10. * http://www.hdfgroup.org/products/licenses.html. If you do not have *
  11. * access to the file, you may request a copy from help@hdfgroup.org. *
  12. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  13. /*
  14. * This code is the C-interface called by Java programs to access the
  15. * Dataspace Object API Functions of the HDF5 library.
  16. *
  17. * Each routine wraps a single HDF entry point, generally with the
  18. * analogous arguments and return codes.
  19. *
  20. * For details of the HDF libraries, see the HDF Documentation at:
  21. * http://hdfdfgroup.org/HDF5/doc/
  22. *
  23. */
  24. #ifdef __cplusplus
  25. extern "C" {
  26. #endif
  27. #include <jni.h>
  28. #include <stdlib.h>
  29. #include "hdf5.h"
  30. #include "h5jni.h"
  31. #include "h5sImp.h"
  32. /*
  33. * Class: ncsa_hdf_hdf5lib_H5
  34. * Method: H5Screate
  35. * Signature: (I)I
  36. */
  37. JNIEXPORT jint JNICALL Java_ncsa_hdf_hdf5lib_H5__1H5Screate(JNIEnv *env,
  38. jclass clss, jint type) {
  39. hid_t retVal = -1;
  40. retVal = H5Screate((H5S_class_t) type);
  41. if (retVal < 0)
  42. h5libraryError(env);
  43. return (jint) retVal;
  44. }
  45. /*
  46. * Class: ncsa_hdf_hdf5lib_H5
  47. * Method: H5Screate_simple
  48. * Signature: (I[J[J)I
  49. */
  50. JNIEXPORT jint JNICALL Java_ncsa_hdf_hdf5lib_H5__1H5Screate_1simple(
  51. JNIEnv *env, jclass clss, jint rank, jlongArray dims,
  52. jlongArray maxdims) {
  53. hid_t status;
  54. jlong *dimsP, *maxdimsP;
  55. jboolean isCopy;
  56. hsize_t *sa = NULL;
  57. hsize_t *msa = NULL;
  58. int i;
  59. int drank, mrank;
  60. hsize_t *lp;
  61. jlong *jlp;
  62. if (rank < 0) {
  63. h5badArgument(env, "H5Screate_simple: rank is invalid");
  64. return -1;
  65. }
  66. if (dims == NULL) {
  67. h5nullArgument(env, "H5Screate_simple: dims is NULL");
  68. return -1;
  69. }
  70. drank = (int) ENVPTR->GetArrayLength(ENVPAR dims);
  71. if (drank != rank) {
  72. h5badArgument(env, "H5Screate_simple: dims rank is invalid");
  73. return -1;
  74. }
  75. if(maxdims != NULL) {
  76. mrank = (int) ENVPTR->GetArrayLength(ENVPAR maxdims);
  77. if (mrank != rank) {
  78. h5badArgument(env, "H5Screate_simple: maxdims rank is invalid");
  79. return -1;
  80. }
  81. }
  82. dimsP = ENVPTR->GetLongArrayElements(ENVPAR dims, &isCopy);
  83. if (dimsP == NULL) {
  84. h5JNIFatalError(env, "H5Screate_simple: dims not pinned");
  85. return -1;
  86. }
  87. sa = lp = (hsize_t *)malloc(rank * sizeof(hsize_t));
  88. if (sa == NULL) {
  89. ENVPTR->ReleaseLongArrayElements(ENVPAR dims,dimsP,JNI_ABORT);
  90. h5JNIFatalError(env, "H5Screate_simple: dims not converted to hsize_t");
  91. return -1;
  92. }
  93. jlp = (jlong *)dimsP;
  94. for (i = 0; i < rank; i++) {
  95. *lp = (hsize_t)*jlp;
  96. lp++;
  97. jlp++;
  98. }
  99. if (maxdims == NULL) {
  100. maxdimsP = NULL;
  101. msa = (hsize_t *)maxdimsP;
  102. }
  103. else {
  104. maxdimsP = ENVPTR->GetLongArrayElements(ENVPAR maxdims,&isCopy);
  105. if (maxdimsP == NULL) {
  106. ENVPTR->ReleaseLongArrayElements(ENVPAR dims,dimsP,JNI_ABORT);
  107. free (sa);
  108. h5JNIFatalError(env, "H5Screate_simple: maxdims not pinned");
  109. return -1;
  110. }
  111. msa = lp = (hsize_t *)malloc(rank * sizeof(hsize_t));
  112. if (msa == NULL) {
  113. ENVPTR->ReleaseLongArrayElements(ENVPAR dims,dimsP,JNI_ABORT);
  114. ENVPTR->ReleaseLongArrayElements(ENVPAR maxdims,maxdimsP,JNI_ABORT);
  115. free (sa);
  116. h5JNIFatalError(env, "H5Screate_simple: dims not converted to hsize_t");
  117. return -1;
  118. }
  119. jlp = (jlong *)maxdimsP;
  120. for (i = 0; i < mrank; i++) {
  121. *lp = (hsize_t)*jlp;
  122. lp++;
  123. jlp++;
  124. }
  125. }
  126. status = H5Screate_simple(rank, (const hsize_t *)sa, (const hsize_t *)msa);
  127. if (maxdimsP != NULL) {
  128. ENVPTR->ReleaseLongArrayElements(ENVPAR maxdims,maxdimsP,JNI_ABORT);
  129. if (msa)
  130. free (msa);
  131. }
  132. ENVPTR->ReleaseLongArrayElements(ENVPAR dims,dimsP,0);
  133. if (sa)
  134. free (sa);
  135. if (status < 0)
  136. h5libraryError(env);
  137. return (jint)status;
  138. }
  139. /*
  140. * Class: ncsa_hdf_hdf5lib_H5
  141. * Method: H5Scopy
  142. * Signature: (I)I
  143. */
  144. JNIEXPORT jint JNICALL Java_ncsa_hdf_hdf5lib_H5__1H5Scopy(JNIEnv *env,
  145. jclass clss, jint space_id) {
  146. hid_t retVal = -1;
  147. retVal = H5Scopy(space_id);
  148. if (retVal < 0)
  149. h5libraryError(env);
  150. return (jint) retVal;
  151. }
  152. #ifdef notdef
  153. // 10/28/99 -- added code to copy the array -- this is not used,
  154. // but serves as a reminder in case we try to implement this in
  155. // the future....
  156. /*
  157. * Note: the argument coord is actually long coord[][], which has been
  158. * flattened by the caller.
  159. */
  160. /*
  161. * Class: ncsa_hdf_hdf5lib_H5
  162. * Method: H5Sselect_elements
  163. * Signature: (III[J)I
  164. */
  165. JNIEXPORT jint JNICALL Java_ncsa_hdf_hdf5lib_H5_H5Sselect_1elements
  166. (JNIEnv *env, jclass clss, jint space_id, jint op, jint num_elemn, jlongArray coord)
  167. {
  168. herr_t status;
  169. jint i;
  170. jlong *P;
  171. jboolean isCopy;
  172. hssize_t *sa;
  173. int rank;
  174. if (coord == NULL) {
  175. h5nullArgument( env, "H5Sselect_elements: coord is NULL");
  176. return -1;
  177. }
  178. P = ENVPTR->GetLongArrayElements(ENVPAR env,coord,&isCopy);
  179. if (P == NULL) {
  180. h5JNIFatalError(env, "H5Sselect_elements: coord not pinned");
  181. return -1;
  182. }
  183. sa = (hssize_t *)malloc( num_elems * 2 * sizeof(hssize_t));
  184. if (sa == NULL) {
  185. ENVPTR->ReleaseLongArrayElements(ENVPAR env,coord,P,JNI_ABORT);
  186. h5JNIFatalError(env, "H5Sselect_elements: coord array not converted to hssize_t");
  187. return -1;
  188. }
  189. for (i= 0; i < (num_elsms * 2); i++) {
  190. sa[i] = P[i];
  191. }
  192. status = H5Sselect_elements (space_id, (H5S_seloper_t)op, num_elemn, (const hssize_t **)&sa);
  193. ENVPTR->ReleaseLongArrayElements(ENVPAR env, coord, P, 0);
  194. free(sa);
  195. if (status < 0)
  196. h5libraryError(env);
  197. return (jint)status;
  198. }
  199. #endif
  200. /*
  201. * Class: ncsa_hdf_hdf5lib_H5
  202. * Method: H5Sselect_elements
  203. * Signature: (III[B)I
  204. */
  205. JNIEXPORT jint JNICALL Java_ncsa_hdf_hdf5lib_H5_H5Sselect_1elements(
  206. JNIEnv *env, jclass clss, jint space_id, jint op, jint num_elemn,
  207. jbyteArray coord) {
  208. int ii;
  209. hsize_t *lp = NULL;
  210. hsize_t *llp;
  211. jlong *jlp;
  212. herr_t status;
  213. jbyte *P;
  214. jboolean isCopy;
  215. jsize size;
  216. int nlongs;
  217. if (coord == NULL) {
  218. h5nullArgument(env, "H5Sselect_elements: coord is NULL");
  219. return -1;
  220. }
  221. P = ENVPTR->GetByteArrayElements(ENVPAR coord, &isCopy);
  222. if (P == NULL) {
  223. h5JNIFatalError(env, "H5Sselect_elements: coord not pinned");
  224. return -1;
  225. }
  226. size = (int) ENVPTR->GetArrayLength(ENVPAR coord);
  227. nlongs = size / sizeof(jlong);
  228. lp = (hsize_t *)malloc(nlongs * sizeof(hsize_t));
  229. jlp = (jlong *)P;
  230. llp = lp;
  231. for (ii = 0; ii < nlongs; ii++) {
  232. *lp = (hsize_t)*jlp;
  233. lp++;
  234. jlp++;
  235. }
  236. status = H5Sselect_elements (space_id, (H5S_seloper_t)op, num_elemn, (const hsize_t *)llp);
  237. ENVPTR->ReleaseByteArrayElements(ENVPAR coord, P, 0);
  238. if (llp) free (llp);
  239. if (status < 0)
  240. h5libraryError(env);
  241. return (jint)status;
  242. }
  243. /*
  244. * Class: ncsa_hdf_hdf5lib_H5
  245. * Method: H5Sselect_all
  246. * Signature: (I)I
  247. */
  248. JNIEXPORT jint JNICALL Java_ncsa_hdf_hdf5lib_H5_H5Sselect_1all(JNIEnv *env,
  249. jclass clss, jint space_id) {
  250. herr_t retVal = -1;
  251. retVal = H5Sselect_all(space_id);
  252. if (retVal < 0)
  253. h5libraryError(env);
  254. return (jint) retVal;
  255. }
  256. /*
  257. * Class: ncsa_hdf_hdf5lib_H5
  258. * Method: H5Sselect_none
  259. * Signature: (I)I
  260. */
  261. JNIEXPORT jint JNICALL Java_ncsa_hdf_hdf5lib_H5_H5Sselect_1none(JNIEnv *env,
  262. jclass clss, jint space_id) {
  263. herr_t retVal = -1;
  264. retVal = H5Sselect_none(space_id);
  265. if (retVal < 0)
  266. h5libraryError(env);
  267. return (jint) retVal;
  268. }
  269. /*
  270. * Class: ncsa_hdf_hdf5lib_H5
  271. * Method: H5Sselect_valid
  272. * Signature: (I)Z
  273. */
  274. JNIEXPORT jboolean JNICALL Java_ncsa_hdf_hdf5lib_H5_H5Sselect_1valid(
  275. JNIEnv *env, jclass clss, jint space_id) {
  276. htri_t bval;
  277. bval = H5Sselect_valid(space_id);
  278. if (bval > 0) {
  279. return JNI_TRUE;
  280. }
  281. else if (bval == 0) {
  282. return JNI_FALSE;
  283. }
  284. else {
  285. h5libraryError(env);
  286. return JNI_FALSE;
  287. }
  288. }
  289. /*
  290. * Class: ncsa_hdf_hdf5lib_H5
  291. * Method: H5Sget_simple_extent_npoints
  292. * Signature: (I)J
  293. */
  294. JNIEXPORT jlong JNICALL Java_ncsa_hdf_hdf5lib_H5_H5Sget_1simple_1extent_1npoints(
  295. JNIEnv *env, jclass clss, jint space_id) {
  296. hssize_t retVal = -1;
  297. retVal = H5Sget_simple_extent_npoints(space_id);
  298. if (retVal < 0)
  299. h5libraryError(env);
  300. return (jlong) retVal;
  301. }
  302. /*
  303. * Class: ncsa_hdf_hdf5lib_H5
  304. * Method: H5Sget_select_npoints
  305. * Signature: (I)J
  306. */
  307. JNIEXPORT jlong JNICALL Java_ncsa_hdf_hdf5lib_H5_H5Sget_1select_1npoints(
  308. JNIEnv *env, jclass clss, jint space_id) {
  309. hssize_t retVal = -1;
  310. retVal = H5Sget_select_npoints(space_id);
  311. if (retVal < 0)
  312. h5libraryError(env);
  313. return (jlong) retVal;
  314. }
  315. /*
  316. * Class: ncsa_hdf_hdf5lib_H5
  317. * Method: H5Sget_select_type
  318. * Signature: (I)I
  319. */
  320. JNIEXPORT jint JNICALL Java_ncsa_hdf_hdf5lib_H5_H5Sget_1select_1type(
  321. JNIEnv *env, jclass clss, jint space_id) {
  322. int retVal = -1;
  323. retVal = H5Sget_select_type(space_id);
  324. if (retVal < 0)
  325. h5libraryError(env);
  326. return (jint) retVal;
  327. }
  328. /*
  329. * Class: ncsa_hdf_hdf5lib_H5
  330. * Method: H5Sget_simple_extent_ndims
  331. * Signature: (I)I
  332. */
  333. JNIEXPORT jint JNICALL Java_ncsa_hdf_hdf5lib_H5_H5Sget_1simple_1extent_1ndims(
  334. JNIEnv *env, jclass clss, jint space_id) {
  335. int retVal = -1;
  336. retVal = H5Sget_simple_extent_ndims(space_id);
  337. if (retVal < 0)
  338. h5libraryError(env);
  339. return (jint) retVal;
  340. }
  341. /*
  342. * Class: ncsa_hdf_hdf5lib_H5
  343. * Method: H5Sget_simple_extent_dims
  344. * Signature: (I[J[J)I
  345. */
  346. JNIEXPORT jint JNICALL Java_ncsa_hdf_hdf5lib_H5_H5Sget_1simple_1extent_1dims(
  347. JNIEnv *env, jclass clss, jint space_id, jlongArray dims,
  348. jlongArray maxdims) {
  349. int status;
  350. jlong *dimsP, *maxdimsP;
  351. jboolean isCopy;
  352. hsize_t *sa;
  353. hsize_t *msa;
  354. int i;
  355. int rank = -1;
  356. int mrank;
  357. if (dims == NULL) {
  358. dimsP = NULL;
  359. sa = (hsize_t *)dimsP;
  360. }
  361. else {
  362. dimsP = ENVPTR->GetLongArrayElements(ENVPAR dims, &isCopy);
  363. if (dimsP == NULL) {
  364. h5JNIFatalError(env, "H5Pget_simple_extent_dims: dims not pinned");
  365. return -1;
  366. }
  367. rank = (int) ENVPTR->GetArrayLength(ENVPAR dims);
  368. sa = (hsize_t *)malloc( rank * sizeof(hsize_t));
  369. if (sa == NULL) {
  370. ENVPTR->ReleaseLongArrayElements(ENVPAR dims,dimsP,JNI_ABORT);
  371. h5JNIFatalError(env,"H5Sget_simple_extent_dims: dims not converted to hsize_t");
  372. return -1;
  373. }
  374. }
  375. if (maxdims == NULL) {
  376. maxdimsP = NULL;
  377. msa = (hsize_t *)maxdimsP;
  378. }
  379. else {
  380. maxdimsP = ENVPTR->GetLongArrayElements(ENVPAR maxdims,&isCopy);
  381. if (maxdimsP == NULL) {
  382. if (dimsP != NULL) {
  383. ENVPTR->ReleaseLongArrayElements(ENVPAR dims,dimsP,JNI_ABORT);
  384. free(sa);
  385. }
  386. h5JNIFatalError(env, "H5Pget_simple_extent_dims: maxdims not pinned");
  387. return -1;
  388. }
  389. mrank = (int) ENVPTR->GetArrayLength(ENVPAR maxdims);
  390. if(rank < 0)
  391. rank = mrank;
  392. else if(mrank != rank) {
  393. if (dimsP != NULL) {
  394. ENVPTR->ReleaseLongArrayElements(ENVPAR dims,dimsP,JNI_ABORT);
  395. free(sa);
  396. }
  397. ENVPTR->ReleaseLongArrayElements(ENVPAR maxdims,maxdimsP,JNI_ABORT);
  398. h5JNIFatalError(env, "H5Sget_simple_extent_dims: maxdims rank not same as dims");
  399. return -1;
  400. }
  401. msa = (hsize_t *)malloc( rank * sizeof(hsize_t));
  402. if (msa == NULL) {
  403. if (dimsP != NULL) {
  404. ENVPTR->ReleaseLongArrayElements(ENVPAR dims,dimsP,JNI_ABORT);
  405. free(sa);
  406. }
  407. ENVPTR->ReleaseLongArrayElements(ENVPAR maxdims,maxdimsP,JNI_ABORT);
  408. h5JNIFatalError(env, "H5Sget_simple_extent_dims: maxdims not converted to hsize_t");
  409. return -1;
  410. }
  411. }
  412. status = H5Sget_simple_extent_dims(space_id, (hsize_t *)sa, (hsize_t *)msa);
  413. if (status < 0) {
  414. if (dimsP != NULL) {
  415. ENVPTR->ReleaseLongArrayElements(ENVPAR dims,dimsP,JNI_ABORT);
  416. free(sa);
  417. }
  418. if (maxdimsP != NULL) {
  419. ENVPTR->ReleaseLongArrayElements(ENVPAR maxdims,maxdimsP,JNI_ABORT);
  420. free(msa);
  421. }
  422. h5libraryError(env);
  423. return -1;
  424. }
  425. if (dimsP != NULL) {
  426. for (i = 0; i < rank; i++) {
  427. dimsP[i] = sa[i];
  428. }
  429. free(sa);
  430. ENVPTR->ReleaseLongArrayElements(ENVPAR dims,dimsP,0);
  431. }
  432. if (maxdimsP != NULL) {
  433. for (i = 0; i < rank; i++) {
  434. maxdimsP[i] = msa[i];
  435. }
  436. free(msa);
  437. ENVPTR->ReleaseLongArrayElements(ENVPAR maxdims,maxdimsP,0);
  438. }
  439. return (jint)status;
  440. }
  441. /*
  442. * Class: ncsa_hdf_hdf5lib_H5
  443. * Method: H5Sget_simple_extent_type
  444. * Signature: (I)I
  445. */
  446. JNIEXPORT jint JNICALL Java_ncsa_hdf_hdf5lib_H5_H5Sget_1simple_1extent_1type(
  447. JNIEnv *env, jclass clss, jint space_id) {
  448. H5S_class_t retVal = H5S_NO_CLASS;
  449. if (space_id < 0)
  450. h5libraryError(env);
  451. retVal = H5Sget_simple_extent_type(space_id);
  452. return (jint) retVal;
  453. }
  454. /*
  455. * Class: ncsa_hdf_hdf5lib_H5
  456. * Method: H5Sset_extent_simple
  457. * Signature: (II[J[J)I
  458. */
  459. JNIEXPORT jint JNICALL Java_ncsa_hdf_hdf5lib_H5_H5Sset_1extent_1simple(
  460. JNIEnv *env, jclass clss, jint space_id, jint rank, jlongArray dims,
  461. jlongArray maxdims) {
  462. herr_t status;
  463. jlong *dimsP, *maxdimsP;
  464. jboolean isCopy;
  465. hsize_t *sa;
  466. hsize_t *msa;
  467. int i;
  468. int drank, mrank;
  469. hsize_t *lp;
  470. jlong *jlp;
  471. if (dims == NULL) {
  472. h5nullArgument(env, "H5Sset_simple_extent: dims is NULL");
  473. return -1;
  474. }
  475. drank = (int) ENVPTR->GetArrayLength(ENVPAR dims);
  476. if (drank != rank) {
  477. h5badArgument(env, "H5Screate_simple: dims rank is invalid");
  478. return -1;
  479. }
  480. if(maxdims != NULL) {
  481. mrank = (int) ENVPTR->GetArrayLength(ENVPAR maxdims);
  482. if (mrank != rank) {
  483. h5badArgument(env, "H5Screate_simple: maxdims rank is invalid");
  484. return -1;
  485. }
  486. }
  487. dimsP = ENVPTR->GetLongArrayElements(ENVPAR dims, &isCopy);
  488. if (dimsP == NULL) {
  489. h5JNIFatalError(env, "H5Pset_simple_extent: dims not pinned");
  490. return -1;
  491. }
  492. sa = lp = (hsize_t *)malloc(rank * sizeof(hsize_t));
  493. if (sa == NULL) {
  494. ENVPTR->ReleaseLongArrayElements(ENVPAR dims,dimsP,JNI_ABORT);
  495. h5JNIFatalError(env,"H5Sset_simple_extent: dims not converted to hsize_t");
  496. return -1;
  497. }
  498. jlp = (jlong *)dimsP;
  499. for (i = 0; i < rank; i++) {
  500. *lp = (hsize_t)*jlp;
  501. lp++;
  502. jlp++;
  503. }
  504. if (maxdims == NULL) {
  505. maxdimsP = NULL;
  506. msa = (hsize_t *)maxdimsP;
  507. }
  508. else {
  509. maxdimsP = ENVPTR->GetLongArrayElements(ENVPAR maxdims,&isCopy);
  510. if (maxdimsP == NULL) {
  511. ENVPTR->ReleaseLongArrayElements(ENVPAR dims,dimsP,JNI_ABORT);
  512. h5JNIFatalError(env, "H5Pset_simple_extent: maxdims not pinned");
  513. return -1;
  514. }
  515. msa = lp = (hsize_t *)malloc(rank * sizeof(hsize_t));
  516. if (msa == NULL) {
  517. ENVPTR->ReleaseLongArrayElements(ENVPAR dims,dimsP,JNI_ABORT);
  518. ENVPTR->ReleaseLongArrayElements(ENVPAR maxdims,maxdimsP,JNI_ABORT);
  519. free (sa);
  520. h5JNIFatalError(env, "H5Sset_simple_extent: maxdims not converted to hsize_t");
  521. return -1;
  522. }
  523. jlp = (jlong *)maxdimsP;
  524. for (i = 0; i < rank; i++) {
  525. *lp = (hsize_t)*jlp;
  526. lp++;
  527. jlp++;
  528. }
  529. }
  530. status = H5Sset_extent_simple(space_id, rank, (hsize_t *)sa, (hsize_t *)msa);
  531. ENVPTR->ReleaseLongArrayElements(ENVPAR dims,dimsP,JNI_ABORT);
  532. free (sa);
  533. if (maxdimsP != NULL) {
  534. ENVPTR->ReleaseLongArrayElements(ENVPAR maxdims,maxdimsP,JNI_ABORT);
  535. free (msa);
  536. }
  537. if (status < 0)
  538. h5libraryError(env);
  539. return (jint)status;
  540. }
  541. /*
  542. * Class: ncsa_hdf_hdf5lib_H5
  543. * Method: H5Sis_simple
  544. * Signature: (I)Z
  545. */
  546. JNIEXPORT jboolean JNICALL Java_ncsa_hdf_hdf5lib_H5_H5Sis_1simple(JNIEnv *env,
  547. jclass clss, jint space_id) {
  548. htri_t bval;
  549. bval = H5Sis_simple(space_id);
  550. if (bval > 0) {
  551. return JNI_TRUE;
  552. }
  553. else if (bval == 0) {
  554. return JNI_FALSE;
  555. }
  556. else {
  557. h5libraryError(env);
  558. return JNI_FALSE;
  559. }
  560. }
  561. /*
  562. * Class: ncsa_hdf_hdf5lib_H5
  563. * Method: H5Soffset_simple
  564. * Signature: (I[B)I
  565. */
  566. JNIEXPORT jint JNICALL Java_ncsa_hdf_hdf5lib_H5_H5Soffset_1simple(JNIEnv *env,
  567. jclass clss, jint space_id, jbyteArray offset) {
  568. herr_t status;
  569. jbyte *P = NULL;
  570. jboolean isCopy;
  571. hssize_t *sa;
  572. int rank;
  573. int i;
  574. hssize_t *lp;
  575. jlong *jlp;
  576. if (offset != NULL) {
  577. P = ENVPTR->GetByteArrayElements(ENVPAR offset, &isCopy);
  578. if (P == NULL) {
  579. h5JNIFatalError(env, "H5Soffset_simple: offset not pinned");
  580. return -1;
  581. }
  582. i = (int) ENVPTR->GetArrayLength(ENVPAR offset);
  583. rank = i / sizeof(jlong);
  584. sa = lp = (hssize_t *)malloc(rank * sizeof(hssize_t));
  585. if (sa == NULL) {
  586. ENVPTR->ReleaseByteArrayElements(ENVPAR offset,P,JNI_ABORT);
  587. h5JNIFatalError(env,"H5Soffset_simple: offset not converted to hssize_t");
  588. return -1;
  589. }
  590. jlp = (jlong *)P;
  591. for (i = 0; i < rank; i++) {
  592. *lp = (hssize_t)*jlp;
  593. lp++;
  594. jlp++;
  595. }
  596. }
  597. else {
  598. P = NULL;
  599. sa = (hssize_t *)P;
  600. }
  601. status = H5Soffset_simple(space_id, sa);
  602. if (P != NULL) {
  603. ENVPTR->ReleaseByteArrayElements(ENVPAR offset,P,JNI_ABORT);
  604. free(sa);
  605. }
  606. if (status < 0)
  607. h5libraryError(env);
  608. return (jint)status;
  609. }
  610. /*
  611. * Class: ncsa_hdf_hdf5lib_H5
  612. * Method: H5Sextent_copy
  613. * Signature: (II)I
  614. */
  615. JNIEXPORT jint JNICALL Java_ncsa_hdf_hdf5lib_H5_H5Sextent_1copy(JNIEnv *env,
  616. jclass clss, jint space_id, jint src_id) {
  617. herr_t retVal = -1;
  618. retVal = H5Sextent_copy(space_id, src_id);
  619. if (retVal < 0)
  620. h5libraryError(env);
  621. return (jint) retVal;
  622. }
  623. /*
  624. * Class: ncsa_hdf_hdf5lib_H5
  625. * Method: H5Sextent_equal
  626. * Signature: (II)Z
  627. */
  628. JNIEXPORT jboolean JNICALL Java_ncsa_hdf_hdf5lib_H5_H5Sextent_1equal
  629. (JNIEnv *env, jclass clss, jint space_id, jint src_id) {
  630. htri_t bval;
  631. bval = H5Sextent_equal(space_id, src_id);
  632. if (bval > 0) {
  633. return JNI_TRUE;
  634. }
  635. else if (bval == 0) {
  636. return JNI_FALSE;
  637. }
  638. else {
  639. h5libraryError(env);
  640. return JNI_FALSE;
  641. }
  642. }
  643. /*
  644. * Class: ncsa_hdf_hdf5lib_H5
  645. * Method: H5Sset_extent_none
  646. * Signature: (I)I
  647. */
  648. JNIEXPORT jint JNICALL Java_ncsa_hdf_hdf5lib_H5_H5Sset_1extent_1none(
  649. JNIEnv *env, jclass clss, jint space_id) {
  650. herr_t retVal = -1;
  651. retVal = H5Sset_extent_none(space_id);
  652. if (retVal < 0)
  653. h5libraryError(env);
  654. return (jint) retVal;
  655. }
  656. /*
  657. * Class: ncsa_hdf_hdf5lib_H5
  658. * Method: H5Sselect_hyperslab
  659. * Signature: (II[J[J[J[J)I
  660. */
  661. JNIEXPORT jint JNICALL Java_ncsa_hdf_hdf5lib_H5_H5Sselect_1hyperslab(
  662. JNIEnv *env, jclass clss, jint space_id, jint op, jlongArray start,
  663. jlongArray stride, jlongArray count, jlongArray block) {
  664. herr_t status;
  665. jlong *startP, *strideP, *countP, *blockP;
  666. jboolean isCopy;
  667. hsize_t *strt;
  668. hsize_t *strd;
  669. hsize_t *cnt;
  670. hsize_t *blk;
  671. int rank;
  672. int i;
  673. hsize_t *lp;
  674. jlong *jlp;
  675. if (start == NULL) {
  676. h5nullArgument(env, "H5Sselect_hyperslab: start is NULL");
  677. return -1;
  678. }
  679. if (count == NULL) {
  680. h5nullArgument(env, "H5Sselect_hyperslab: count is NULL");
  681. return -1;
  682. }
  683. rank = (int) ENVPTR->GetArrayLength(ENVPAR start);
  684. if (rank != ENVPTR->GetArrayLength(ENVPAR count)) {
  685. h5badArgument(env,
  686. "H5Sselect_hyperslab: count and start have different rank!");
  687. return -1;
  688. }
  689. startP = ENVPTR->GetLongArrayElements(ENVPAR start, &isCopy);
  690. if (startP == NULL) {
  691. h5JNIFatalError(env, "H5Sselect_hyperslab: start not pinned");
  692. return -1;
  693. }
  694. strt = lp = (hsize_t *)malloc(rank * sizeof(hsize_t));
  695. if (strt == NULL) {
  696. ENVPTR->ReleaseLongArrayElements(ENVPAR start,startP,JNI_ABORT);
  697. h5JNIFatalError(env,"H5Sselect_hyperslab: start not converted to hsize_t");
  698. return -1;
  699. }
  700. jlp = (jlong *)startP;
  701. for (i = 0; i < rank; i++) {
  702. *lp = (hsize_t)*jlp;
  703. lp++;
  704. jlp++;
  705. }
  706. countP = ENVPTR->GetLongArrayElements(ENVPAR count,&isCopy);
  707. if (countP == NULL) {
  708. ENVPTR->ReleaseLongArrayElements(ENVPAR start, startP,JNI_ABORT);
  709. free(strt);
  710. h5JNIFatalError(env, "H5Sselect_hyperslab: count not pinned");
  711. return -1;
  712. }
  713. cnt = lp = (hsize_t *)malloc(rank * sizeof(hsize_t));
  714. if (cnt == NULL) {
  715. ENVPTR->ReleaseLongArrayElements(ENVPAR start, startP,JNI_ABORT);
  716. ENVPTR->ReleaseLongArrayElements(ENVPAR count, countP,JNI_ABORT);
  717. free(strt);
  718. h5JNIFatalError(env, "H5Sselect_hyperslab: count not converted to hsize_t");
  719. return -1;
  720. }
  721. jlp = (jlong *)countP;
  722. for (i = 0; i < rank; i++) {
  723. *lp = (hsize_t)*jlp;
  724. lp++;
  725. jlp++;
  726. }
  727. if (stride == NULL) {
  728. strideP = NULL;
  729. strd = (hsize_t *)strideP;
  730. }
  731. else {
  732. strideP = ENVPTR->GetLongArrayElements(ENVPAR stride,&isCopy);
  733. if (strideP == NULL) {
  734. ENVPTR->ReleaseLongArrayElements(ENVPAR count, countP,JNI_ABORT);
  735. ENVPTR->ReleaseLongArrayElements(ENVPAR start, startP,JNI_ABORT);
  736. free(cnt); free(strt);
  737. h5badArgument( env, "H5Sselect_hyperslab: stride not pinned");
  738. return -1;
  739. }
  740. strd = lp = (hsize_t *)malloc(rank * sizeof(hsize_t));
  741. if (strd == NULL) {
  742. ENVPTR->ReleaseLongArrayElements(ENVPAR count, countP,JNI_ABORT);
  743. ENVPTR->ReleaseLongArrayElements(ENVPAR start, startP,JNI_ABORT);
  744. ENVPTR->ReleaseLongArrayElements(ENVPAR stride, strideP,JNI_ABORT);
  745. free(cnt); free(strt);
  746. h5JNIFatalError(env, "H5Sselect_hyperslab: stride not converted to hsize_t");
  747. return -1;
  748. }
  749. jlp = (jlong *)strideP;
  750. for (i = 0; i < rank; i++) {
  751. *lp = (hsize_t)*jlp;
  752. lp++;
  753. jlp++;
  754. }
  755. }
  756. if (block == NULL) {
  757. blockP = NULL;
  758. blk = (hsize_t *)blockP;
  759. }
  760. else {
  761. blockP = ENVPTR->GetLongArrayElements(ENVPAR block,&isCopy);
  762. if (blockP == NULL) {
  763. ENVPTR->ReleaseLongArrayElements(ENVPAR stride, strideP,JNI_ABORT);
  764. ENVPTR->ReleaseLongArrayElements(ENVPAR count, countP,JNI_ABORT);
  765. ENVPTR->ReleaseLongArrayElements(ENVPAR start, startP,JNI_ABORT);
  766. free(cnt); free(strt);
  767. if (strd != NULL) { free(strd); }
  768. h5JNIFatalError(env, "H5Sselect_hyperslab: block not pinned");
  769. return -1;
  770. }
  771. blk = lp = (hsize_t *)malloc(rank * sizeof(hsize_t));
  772. if (blk == NULL) {
  773. ENVPTR->ReleaseLongArrayElements(ENVPAR stride, strideP,JNI_ABORT);
  774. ENVPTR->ReleaseLongArrayElements(ENVPAR count, countP,JNI_ABORT);
  775. ENVPTR->ReleaseLongArrayElements(ENVPAR start, startP,JNI_ABORT);
  776. ENVPTR->ReleaseLongArrayElements(ENVPAR block, blockP,JNI_ABORT);
  777. free(cnt); free(strt);
  778. if (strd != NULL) { free(strd); }
  779. h5JNIFatalError(env, "H5Sget_simple_extent: block not converted to hsize_t");
  780. return -1;
  781. }
  782. jlp = (jlong *)blockP;
  783. for (i = 0; i < rank; i++) {
  784. *lp = (hsize_t)*jlp;
  785. lp++;
  786. jlp++;
  787. }
  788. }
  789. status = H5Sselect_hyperslab (space_id, (H5S_seloper_t)op, (const hsize_t *)strt, (const hsize_t *)strd, (const hsize_t *)cnt, (const hsize_t *)blk);
  790. ENVPTR->ReleaseLongArrayElements(ENVPAR start, startP,0);
  791. ENVPTR->ReleaseLongArrayElements(ENVPAR count, countP,0);
  792. free(strt);
  793. free(cnt);
  794. if (strideP != NULL) {
  795. ENVPTR->ReleaseLongArrayElements(ENVPAR stride, strideP,0);
  796. free(strd);
  797. }
  798. if (blockP != NULL) {
  799. ENVPTR->ReleaseLongArrayElements(ENVPAR block, blockP,0);
  800. free(blk);
  801. }
  802. if (status < 0)
  803. h5libraryError(env);
  804. return (jint)status;
  805. }
  806. /*
  807. * Class: ncsa_hdf_hdf5lib_H5
  808. * Method: H5Sclose
  809. * Signature: (I)I
  810. */
  811. JNIEXPORT jint JNICALL Java_ncsa_hdf_hdf5lib_H5__1H5Sclose(JNIEnv *env,
  812. jclass clss, jint space_id) {
  813. herr_t retVal = -1;
  814. retVal = H5Sclose(space_id);
  815. if (retVal < 0) {
  816. h5libraryError(env);
  817. }
  818. return (jint) retVal;
  819. }
  820. /*
  821. * Class: ncsa_hdf_hdf5lib_H5
  822. * Method: H5Sget_select_hyper_nblocks
  823. * Signature: (I)J
  824. */
  825. JNIEXPORT jlong JNICALL Java_ncsa_hdf_hdf5lib_H5_H5Sget_1select_1hyper_1nblocks(
  826. JNIEnv *env, jclass clss, jint spaceid) {
  827. hssize_t status;
  828. status = H5Sget_select_hyper_nblocks((hid_t) spaceid);
  829. if (status < 0)
  830. h5libraryError(env);
  831. return (jlong) status;
  832. }
  833. /*
  834. * Class: ncsa_hdf_hdf5lib_H5
  835. * Method: H5Sget_select_elem_npoints
  836. * Signature: (I)J
  837. */
  838. JNIEXPORT jlong JNICALL Java_ncsa_hdf_hdf5lib_H5_H5Sget_1select_1elem_1npoints(
  839. JNIEnv *env, jclass clss, jint spaceid) {
  840. hssize_t status;
  841. status = H5Sget_select_elem_npoints((hid_t) spaceid);
  842. if (status < 0)
  843. h5libraryError(env);
  844. return (jlong) status;
  845. }
  846. /*
  847. * Class: ncsa_hdf_hdf5lib_H5
  848. * Method: H5Sget_select_hyper_blocklist
  849. * Signature: (IJJ[J)I
  850. */
  851. JNIEXPORT jint JNICALL Java_ncsa_hdf_hdf5lib_H5_H5Sget_1select_1hyper_1blocklist(
  852. JNIEnv *env, jclass clss, jint spaceid, jlong startblock,
  853. jlong numblocks, jlongArray buf) {
  854. herr_t status;
  855. jlong *bufP;
  856. jboolean isCopy;
  857. hsize_t *ba;
  858. int i;
  859. int rank;
  860. long st;
  861. long nb;
  862. st = (long) startblock;
  863. nb = (long) numblocks;
  864. if (buf == NULL) {
  865. h5nullArgument(env, "H5Sget_select_hyper_blocklist: buf is NULL");
  866. return -1;
  867. }
  868. rank = H5Sget_simple_extent_ndims(spaceid);
  869. if(rank <= 0) rank = 1;
  870. if (ENVPTR->GetArrayLength(ENVPAR buf) < (numblocks * rank)) {
  871. h5badArgument(env, "H5Sget_select_hyper_blocklist: buf input array too small");
  872. return -1;
  873. }
  874. bufP = ENVPTR->GetLongArrayElements(ENVPAR buf, &isCopy);
  875. if (bufP == NULL) {
  876. h5JNIFatalError( env, "H5Sget_select_hyper_blocklist: buf not pinned");
  877. return -1;
  878. }
  879. ba = (hsize_t *)malloc( nb * 2 * (long)rank * sizeof(hsize_t));
  880. if (ba == NULL) {
  881. ENVPTR->ReleaseLongArrayElements(ENVPAR buf, bufP,JNI_ABORT);
  882. h5JNIFatalError(env, "H5Screate-simple: buffer not converted to hsize_t");
  883. return -1;
  884. }
  885. status = H5Sget_select_hyper_blocklist((hid_t)spaceid, (hsize_t)st,
  886. (hsize_t)nb, (hsize_t *)ba);
  887. if (status < 0) {
  888. ENVPTR->ReleaseLongArrayElements(ENVPAR buf, bufP, JNI_ABORT);
  889. free (ba);
  890. h5libraryError(env);
  891. return -1;
  892. }
  893. for (i = 0; i < (numblocks*2*rank); i++) {
  894. bufP[i] = ba[i];
  895. }
  896. free (ba);
  897. ENVPTR->ReleaseLongArrayElements(ENVPAR buf, bufP, 0);
  898. return (jint)status;
  899. }
  900. /*
  901. * Class: ncsa_hdf_hdf5lib_H5
  902. * Method: H5Sget_select_elem_pointlist
  903. * Signature: (IJJ[J)I
  904. */
  905. JNIEXPORT jint JNICALL Java_ncsa_hdf_hdf5lib_H5_H5Sget_1select_1elem_1pointlist(
  906. JNIEnv *env, jclass clss, jint spaceid, jlong startpoint,
  907. jlong numpoints, jlongArray buf) {
  908. herr_t status;
  909. jlong *bufP;
  910. jboolean isCopy;
  911. hsize_t *ba;
  912. int i;
  913. int rank;
  914. if (buf == NULL) {
  915. h5nullArgument(env, "H5Sget_select_elem_pointlist: buf is NULL");
  916. return -1;
  917. }
  918. rank = H5Sget_simple_extent_ndims(spaceid);
  919. if(rank <= 0) rank = 1;
  920. if (ENVPTR->GetArrayLength(ENVPAR buf) < (numpoints * rank)) {
  921. h5badArgument(env, "H5Sget_select_elem_pointlist: buf input array too small");
  922. return -1;
  923. }
  924. bufP = ENVPTR->GetLongArrayElements(ENVPAR buf, &isCopy);
  925. if (bufP == NULL) {
  926. h5JNIFatalError( env, "H5Sget_select_elem_pointlist: buf not pinned");
  927. return -1;
  928. }
  929. ba = (hsize_t *)malloc( ((long)numpoints * (long)rank) * sizeof(hsize_t));
  930. if (ba == NULL) {
  931. ENVPTR->ReleaseLongArrayElements(ENVPAR buf,bufP,JNI_ABORT);
  932. h5JNIFatalError(env,"H5Sget_select_elem_pointlist: buf not converted to hsize_t");
  933. return -1;
  934. }
  935. status = H5Sget_select_elem_pointlist((hid_t)spaceid, (hsize_t)startpoint,
  936. (hsize_t)numpoints, (hsize_t *)ba);
  937. if (status < 0) {
  938. free (ba);
  939. ENVPTR->ReleaseLongArrayElements(ENVPAR buf,bufP,JNI_ABORT);
  940. h5libraryError(env);
  941. return -1;
  942. }
  943. for (i = 0; i < (numpoints*rank); i++) {
  944. bufP[i] = ba[i];
  945. }
  946. free (ba) ;
  947. ENVPTR->ReleaseLongArrayElements(ENVPAR buf,bufP,0);
  948. return (jint)status;
  949. }
  950. /*
  951. * Class: ncsa_hdf_hdf5lib_H5
  952. * Method: H5Sget_select_bounds
  953. * Signature: (I[J[J)I
  954. */
  955. JNIEXPORT jint JNICALL Java_ncsa_hdf_hdf5lib_H5_H5Sget_1select_1bounds(
  956. JNIEnv *env, jclass clss, jint spaceid, jlongArray start,
  957. jlongArray end) {
  958. herr_t status;
  959. jlong *startP, *endP;
  960. jboolean isCopy;
  961. hsize_t *strt;
  962. hsize_t *en;
  963. int rank;
  964. int i;
  965. if (start == NULL) {
  966. h5nullArgument(env, "H5Sget_select_bounds: start is NULL");
  967. return -1;
  968. }
  969. if (end == NULL) {
  970. h5nullArgument(env, "H5Sget_select_bounds: end is NULL");
  971. return -1;
  972. }
  973. startP = ENVPTR->GetLongArrayElements(ENVPAR start, &isCopy);
  974. if (startP == NULL) {
  975. h5JNIFatalError( env, "H5Sget_select_bounds: start not pinned");
  976. return -1;
  977. }
  978. rank = (int)ENVPTR->GetArrayLength(ENVPAR start);
  979. strt = (hsize_t *)malloc( rank * sizeof(hsize_t));
  980. if (strt == NULL) {
  981. ENVPTR->ReleaseLongArrayElements(ENVPAR start,startP,JNI_ABORT);
  982. h5JNIFatalError(env,"H5Sget_select_bounds: start not converted to hsize_t");
  983. return -1;
  984. }
  985. endP = ENVPTR->GetLongArrayElements(ENVPAR end,&isCopy);
  986. if (endP == NULL) {
  987. ENVPTR->ReleaseLongArrayElements(ENVPAR start,startP,JNI_ABORT);
  988. free(strt);
  989. h5JNIFatalError( env, "H5Sget_select_bounds: end not pinned");
  990. return -1;
  991. }
  992. en = (hsize_t *)malloc( rank * sizeof(hsize_t));
  993. if (en == NULL) {
  994. ENVPTR->ReleaseLongArrayElements(ENVPAR end,endP,JNI_ABORT);
  995. ENVPTR->ReleaseLongArrayElements(ENVPAR start,startP,JNI_ABORT);
  996. free(strt);
  997. h5JNIFatalError(env, "H5Sget_simple_extent: dims not converted to hsize_t");
  998. return -1;
  999. }
  1000. status = H5Sget_select_bounds((hid_t) spaceid, (hsize_t *)strt, (hsize_t *)en);
  1001. if (status < 0) {
  1002. ENVPTR->ReleaseLongArrayElements(ENVPAR start,startP,JNI_ABORT);
  1003. ENVPTR->ReleaseLongArrayElements(ENVPAR end,endP,JNI_ABORT);
  1004. free(strt);
  1005. free(en);
  1006. h5libraryError(env);
  1007. return -1;
  1008. }
  1009. for (i = 0; i < rank; i++) {
  1010. startP[i] = strt[i];
  1011. endP[i] = en[i];
  1012. }
  1013. ENVPTR->ReleaseLongArrayElements(ENVPAR start,startP,0);
  1014. ENVPTR->ReleaseLongArrayElements(ENVPAR end,endP,0);
  1015. free(strt);
  1016. free(en);
  1017. return (jint)status;
  1018. }
  1019. /*
  1020. * Class: ncsa_hdf_hdf5lib_H5
  1021. * Method: H5Sencode
  1022. * Signature: (I)[B
  1023. */
  1024. JNIEXPORT jbyteArray JNICALL Java_ncsa_hdf_hdf5lib_H5_H5Sencode
  1025. (JNIEnv *env, jclass cls, jint obj_id)
  1026. {
  1027. herr_t status = -1;
  1028. unsigned char *bufPtr;
  1029. size_t buf_size = 0;
  1030. jbyteArray returnedArray = NULL;
  1031. if (obj_id < 0) {
  1032. h5badArgument(env, "H5Sencode: invalid argument");
  1033. return NULL;
  1034. }
  1035. status = H5Sencode(obj_id, NULL, &buf_size);
  1036. if (status < 0) {
  1037. h5libraryError(env);
  1038. return NULL;
  1039. }
  1040. if (buf_size < 0) {
  1041. h5badArgument( env, "H5Sencode: buf_size < 0");
  1042. return NULL;
  1043. }
  1044. bufPtr = (unsigned char*)calloc((size_t)1, buf_size);
  1045. if (bufPtr == NULL) {
  1046. h5outOfMemory( env, "H5Sencode: calloc failed");
  1047. return NULL;
  1048. }
  1049. status = H5Sencode((hid_t)obj_id, bufPtr, &buf_size);
  1050. if (status < 0) {
  1051. free(bufPtr);
  1052. h5libraryError(env);
  1053. return NULL;
  1054. }
  1055. returnedArray = ENVPTR->NewByteArray(ENVPAR buf_size);
  1056. ENVPTR->SetByteArrayRegion(ENVPAR returnedArray, 0, buf_size, (jbyte *)bufPtr);
  1057. free(bufPtr);
  1058. return returnedArray;
  1059. }
  1060. /*
  1061. * Class: ncsa_hdf_hdf5lib_H5
  1062. * Method: H5Sdecode
  1063. * Signature: ([B)I
  1064. */
  1065. JNIEXPORT jint JNICALL Java_ncsa_hdf_hdf5lib_H5_H5Sdecode
  1066. (JNIEnv *env, jclass cls, jbyteArray buf)
  1067. {
  1068. hid_t sid = -1;
  1069. jbyte *bufP;
  1070. jboolean isCopy;
  1071. if (buf == NULL) {
  1072. h5nullArgument(env, "H5Sdecode: buf is NULL");
  1073. return -1;
  1074. }
  1075. bufP = ENVPTR->GetByteArrayElements(ENVPAR buf, &isCopy);
  1076. if (bufP == NULL) {
  1077. h5JNIFatalError( env, "H5Sdecode: buf not pinned");
  1078. return -1;
  1079. }
  1080. sid = H5Sdecode(bufP);
  1081. if (sid < 0) {
  1082. ENVPTR->ReleaseByteArrayElements(ENVPAR buf, bufP, JNI_ABORT);
  1083. h5libraryError(env);
  1084. return -1;
  1085. }
  1086. ENVPTR->ReleaseByteArrayElements(ENVPAR buf, bufP, 0);
  1087. return (jint)sid;
  1088. }
  1089. #ifdef __cplusplus
  1090. }
  1091. #endif