/CBFlib-0.9.2.3/examples/changtestcompression.c

# · C · 682 lines · 618 code · 54 blank · 10 comment · 153 complexity · c6dfea4af1f87386ab9c52a32022cfa2 MD5 · raw file

  1. /*
  2. * testcompression.c - test compression schemes
  3. */
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include <limits.h>
  7. #include <math.h>
  8. #include <float.h>
  9. #include "cbf.h"
  10. #ifdef CBF_USE_LONG_LONG
  11. #ifndef LLONG_MAX
  12. #define LLONG_MAX (1ll << (sizeof(long long) * CHAR_BIT - 1))
  13. #define ULLONG_MAX (~0ll)
  14. #endif
  15. #endif
  16. #define NSTEPS 5
  17. double urand()
  18. {
  19. return rand() * 1.0 / RAND_MAX;
  20. }
  21. #define DATAUC 0
  22. #define DATASC 1
  23. #define DATAUS 2
  24. #define DATASS 3
  25. #define DATAUI 4
  26. #define DATASI 5
  27. #define DATAUL 6
  28. #define DATASL 7
  29. #define DATAULL 8
  30. #define DATASLL 9
  31. #define DATAF 10
  32. #define DATAD 11
  33. /*
  34. * Create images where spots are separated by a uniform distribution of mean
  35. * distance of NSTEPS/2 and have height uniformly distributed over (positive
  36. * part of) data range
  37. */
  38. size_t createtestimage(void **data, int type, int nelem)
  39. {
  40. unsigned char *ucdata;
  41. signed char *scdata;
  42. unsigned short *usdata;
  43. signed short *ssdata;
  44. unsigned int *uidata;
  45. signed int *sidata;
  46. unsigned long *uldata;
  47. signed long *sldata;
  48. CBF_ull_type *ulldata;
  49. CBF_sll_type *slldata;
  50. float *fdata;
  51. double *ddata;
  52. int i = 0;
  53. size_t elsize = 0;
  54. switch (type) {
  55. case DATAUC: /* unsigned char */
  56. ucdata = (unsigned char *)calloc(nelem, 1);
  57. elsize = sizeof(char);
  58. while (i < nelem) {
  59. ucdata[i] = urand() * UCHAR_MAX;
  60. i += 1 + urand() * NSTEPS;
  61. }
  62. *data = ucdata;
  63. break;
  64. case DATASC: /* signed char */
  65. scdata = (signed char *)calloc(nelem, 1);
  66. elsize = sizeof(char);
  67. while (i < nelem) {
  68. scdata[i] = urand() * SCHAR_MAX;
  69. i += 1 + urand() * NSTEPS;
  70. }
  71. *data = scdata;
  72. break;
  73. case DATAUS: /* unsigned short */
  74. usdata = (unsigned short *)calloc(nelem, sizeof(short));
  75. elsize = sizeof(short);
  76. while (i < nelem) {
  77. usdata[i] = urand() * USHRT_MAX;
  78. i += 1 + urand() * NSTEPS;
  79. }
  80. *data = usdata;
  81. break;
  82. case DATASS: /* signed short */
  83. ssdata = (signed short *)calloc(nelem, sizeof(short));
  84. elsize = sizeof(short);
  85. while (i < nelem) {
  86. ssdata[i] = urand() * SHRT_MAX;
  87. i += 1 + urand() * NSTEPS;
  88. }
  89. *data = ssdata;
  90. break;
  91. case DATAUI: /* unsigned int */
  92. uidata = (unsigned int *)calloc(nelem, sizeof(int));
  93. elsize = sizeof(int);
  94. while (i < nelem) {
  95. uidata[i] = urand() * UINT_MAX;
  96. i += 1 + urand() * NSTEPS;
  97. }
  98. *data = uidata;
  99. break;
  100. case DATASI: /* signed int */
  101. sidata = (signed int *)calloc(nelem, sizeof(int));
  102. elsize = sizeof(int);
  103. while (i < nelem) {
  104. sidata[i] = urand() * INT_MAX;
  105. i += 1 + urand() * NSTEPS;
  106. }
  107. *data = sidata;
  108. break;
  109. case DATAUL: /* unsigned long */
  110. uldata = (unsigned long *)calloc(nelem, sizeof(long));
  111. elsize = sizeof(long);
  112. while (i < nelem) {
  113. uldata[i] = urand() * ULONG_MAX;
  114. i += 1 + urand() * NSTEPS;
  115. }
  116. *data = uldata;
  117. break;
  118. case DATASL: /* signed long */
  119. sldata = (signed long *)calloc(nelem, sizeof(long));
  120. elsize = sizeof(long);
  121. while (i < nelem) {
  122. sldata[i] = urand() * LONG_MAX;
  123. i += 1 + urand() * NSTEPS;
  124. }
  125. *data = sldata;
  126. break;
  127. #ifdef CBF_USE_LONG_LONG
  128. case DATAULL: /* unsigned long long */
  129. ulldata = (unsigned long long *)calloc(nelem, sizeof(long long));
  130. elsize = sizeof(long long);
  131. while (i < nelem) {
  132. ulldata[i] = urand() * ULLONG_MAX;
  133. i += 1 + urand() * NSTEPS;
  134. }
  135. *data = ulldata;
  136. break;
  137. case DATASLL: /* signed long long */
  138. slldata = (signed long long *)calloc(nelem, sizeof(long long));
  139. elsize = sizeof(long long);
  140. while (i < nelem) {
  141. slldata[i] = urand() * LLONG_MAX;
  142. i += 1 + urand() * NSTEPS;
  143. }
  144. *data = slldata;
  145. break;
  146. #else
  147. case DATAULL: /* unsigned long long as an array */
  148. ulldata = (CBF_ull_type *)calloc(nelem, sizeof(CBF_ull_type));
  149. elsize = sizeof(CBF_ull_type);
  150. while (i < nelem) {
  151. ulldata[i].el0 = urand() * INT_MAX;
  152. ulldata[i].el1 = urand() * INT_MAX;
  153. #if CBF_ULL_INTS == 4
  154. ulldata[i].el2 = urand() * INT_MAX;
  155. ulldata[i].el3 = urand() * INT_MAX;
  156. #endif
  157. i += 1 + urand() * NSTEPS;
  158. }
  159. *data = ulldata;
  160. break;
  161. case DATASLL: /* signed long long */
  162. slldata = (CBF_sll_type *)calloc(nelem, sizeof(CBF_sll_type));
  163. elsize = sizeof(CBF_sll_type);
  164. while (i < nelem) {
  165. slldata[i].el0 = urand() * INT_MAX;
  166. slldata[i].el1 = urand() * INT_MAX;
  167. #if CBF_ULL_INTS == 4
  168. slldata[i].el2 = urand() * INT_MAX;
  169. slldata[i].el3 = urand() * INT_MAX;
  170. #endif
  171. i += 1 + urand() * NSTEPS;
  172. }
  173. *data = slldata;
  174. break;
  175. #endif
  176. case DATAF: /* float */
  177. fdata = (float *)calloc(nelem, sizeof(float));
  178. elsize = sizeof(float);
  179. while (i < nelem) {
  180. fdata[i] = urand() * INT_MAX;
  181. i += 1 + urand() * NSTEPS;
  182. }
  183. *data = fdata;
  184. break;
  185. case DATAD: /* double */
  186. ddata = (double *)calloc(nelem, sizeof(double));
  187. elsize = sizeof(double);
  188. while (i < nelem) {
  189. ddata[i] = urand() * INT_MAX;
  190. i += 1 + urand() * NSTEPS;
  191. }
  192. *data = ddata;
  193. break;
  194. default:
  195. fprintf(stderr, "Unknown type number\n");
  196. }
  197. return elsize;
  198. }
  199. int createtestfile(const char *fn, int isreal, int rows, int columns,
  200. int compression, void *data, size_t elsize, int elsigned)
  201. {
  202. int status;
  203. cbf_handle ch;
  204. FILE *f;
  205. status = cbf_make_handle(&ch);
  206. if (status) printf("make_handle (%d)\n", status);
  207. status = cbf_new_datablock (ch, "image_1");
  208. if (status) printf("new_datablock (%d)\n", status);
  209. status = cbf_new_category(ch, "array_data");
  210. if (status) printf("new_category (%d)\n", status);
  211. status = cbf_new_column(ch, "array_id");
  212. if (status) printf("new_column (%d)\n", status);
  213. status = cbf_set_value(ch, "image_1");
  214. if (status) printf("set_value (%d)\n", status);
  215. status = cbf_new_column(ch, "binary_id");
  216. if (status) printf("new_column (%d)\n", status);
  217. status = cbf_set_integervalue(ch, 1);
  218. if (status) printf("set_integervalue (%d)\n", status);
  219. status = cbf_new_column(ch, "data");
  220. if (status) printf("new_column (%d)\n", status);
  221. if (isreal) {
  222. status = cbf_set_realarray_wdims(ch, compression, 1, data, elsize,
  223. rows * columns, "little_endian", columns, rows, 0, 0);
  224. if (status) printf("set_realarray_wdims (%d)\n", status);
  225. } else {
  226. status = cbf_set_integerarray_wdims(ch, compression, 1, data, elsize,
  227. elsigned, rows * columns, "little_endian", columns, rows, 0, 0);
  228. if (status) printf("set_integerarray_wdims (%d)\n", status);
  229. }
  230. if (status) return status;
  231. f = fopen(fn, "wb");
  232. status = cbf_write_widefile(ch, f, 1, CBF, MIME_HEADERS | MSG_DIGEST, 0);
  233. if (status) printf("write_widefile (%d)\n", status);
  234. status = cbf_free_handle(ch);
  235. if (status) printf("free_handle (%d)\n", status);
  236. return status;
  237. }
  238. size_t readtestimage(const char *fn, void **data, size_t *size, int *sign)
  239. {
  240. cbf_handle ch;
  241. int status;
  242. FILE *f;
  243. unsigned int cifcomp = 0;
  244. int bid = 0, els = 0, elu = 0;
  245. int minel = 0, maxel = 0, isre = 0;
  246. size_t elsize = 0, elnum = 0;
  247. size_t dim1 = 0, dim2 = 0, dim3 = 0, pad = 0;
  248. const char *byteorder = NULL;
  249. int isreal;
  250. int id;
  251. size_t rsize = 0;
  252. status = cbf_make_handle(&ch);
  253. if (status) printf("make_handle (%d)\n", status);
  254. f = fopen(fn, "rb");
  255. status = cbf_read_widefile(ch, f, MSG_DIGEST);
  256. if (status) printf("read_widefile (%d)\n", status);
  257. status = cbf_rewind_datablock(ch);
  258. if (status) printf("rewind_db (%d)\n", status);
  259. status = cbf_find_category(ch, "array_data");
  260. if (status) printf("find_cat (%d)\n", status);
  261. status = cbf_find_tag(ch, "_array_data.data");
  262. if (status) printf("find_tag (%d)\n", status);
  263. status = cbf_rewind_row(ch);
  264. if (status) printf("rewind_row (%d)\n", status);
  265. status = cbf_get_arrayparameters_wdims(ch, &cifcomp, &bid, &elsize,
  266. &els, &elu, &elnum,
  267. &minel, &maxel, &isre,
  268. &byteorder, &dim1, &dim2, &dim3, &pad);
  269. if (status) printf("get_aparams (%d) = %d, %d, %ld, %d, %d,\n",
  270. status, cifcomp, bid, (long)elsize, els, elu);
  271. if (status) printf(" %ld, %d, %d, %d, %s,\n", (long)elnum, minel, maxel, isre,
  272. (byteorder == NULL) ? "null" : byteorder);
  273. if (status) printf(" %ld, %ld, %ld, %ld\n", (long)dim1, (long)dim2, (long)dim3, (long)pad);
  274. isreal = (isre == 1);
  275. if (isreal) {
  276. if (elsize == sizeof(float) || elsize == sizeof(double)) {
  277. void *rdata = malloc(elsize * elnum);
  278. status = cbf_get_realarray(ch, &id, rdata, elsize, elnum, &rsize);
  279. if (status) printf("get_realarray (%d)\n", status);
  280. *data = rdata;
  281. } else {
  282. fprintf(stderr, "Size of element (%ld) does not match any real types\n", (long)elsize);
  283. }
  284. } else {
  285. if (els && elu) {
  286. fprintf(stderr, "Both signed and unsigned flags have been set!\n");
  287. return rsize;
  288. }
  289. if (elsize == sizeof(char) || elsize == sizeof(short) ||
  290. elsize == sizeof(int) || elsize == sizeof(long)
  291. #ifdef CBF_USE_LONG_LONG
  292. || elsize == sizeof(long long)
  293. #else
  294. || elsize == sizeof(CBF_sll_type)
  295. #endif
  296. ) {
  297. void *idata = malloc(elsize * elnum);
  298. status = cbf_get_integerarray(ch, &id, idata, elsize, els, elnum, &rsize);
  299. if (status) printf("get_integerarray (%d)\n", status);
  300. *data = idata;
  301. } else {
  302. fprintf(stderr, "Size of element (%ld) does not match any integer types\n", (long)elsize);
  303. }
  304. }
  305. status = cbf_free_handle(ch);
  306. if (status) printf("free_handle (%d)\n", status);
  307. *sign = els;
  308. *size = elsize;
  309. if (rsize != elnum) printf("Read %ld elements\n", (long)rsize);
  310. return rsize;
  311. }
  312. void checkdata(int type, int nelem, void *data, void *idata)
  313. {
  314. unsigned char *ucdata, *ucidata;
  315. signed char *scdata, *scidata;
  316. unsigned short *usdata, *usidata;
  317. signed short *ssdata, *ssidata;
  318. unsigned int *uidata, *uiidata;
  319. signed int *sidata, *siidata;
  320. unsigned long *uldata, *ulidata;
  321. signed long *sldata, *slidata;
  322. #ifdef CBF_USE_LONG_LONG
  323. unsigned long long *ulldata, *ullidata;
  324. signed long long *slldata, *sllidata;
  325. #else
  326. CBF_ull_type *ulldata, *ullidata;
  327. CBF_sll_type *slldata, *sllidata;
  328. #endif
  329. float *fdata, *fidata;
  330. double *ddata, *didata;
  331. int i = 0;
  332. switch (type) {
  333. case DATAUC: /* unsigned char */
  334. ucdata = (unsigned char *)data;
  335. ucidata = (unsigned char *)idata;
  336. while (i < nelem) {
  337. if (ucdata[i] != ucidata[i]) {
  338. fprintf(stderr, "UC element %d did not match (%d != %d)\n", i, ucdata[i], ucidata[i]);
  339. fprintf(stderr, "Previous UC elements are (%x %x)\n", ucdata[i-1], ucidata[i-1]);
  340. fprintf(stderr, "Previous UC elements are ~(%x %x)\n", ~ucdata[i-1], ~ucidata[i-1]);
  341. return;
  342. }
  343. i++;
  344. }
  345. break;
  346. case DATASC: /* signed char */
  347. scdata = (signed char *)data;
  348. scidata = (signed char *)idata;
  349. while (i < nelem) {
  350. if (scdata[i] != scidata[i]) {
  351. fprintf(stderr, "SC element %d did not match (%d != %d)\n", i, scdata[i], scidata[i]);
  352. fprintf(stderr, "Previous SC elements are (%x %x)\n", scdata[i-1], scidata[i-1]);
  353. fprintf(stderr, "Previous SC elements are ~(%x %x)\n", ~scdata[i-1], ~scidata[i-1]);
  354. return;
  355. }
  356. i++;
  357. }
  358. break;
  359. case DATAUS: /* unsigned short */
  360. usdata = (unsigned short *)data;
  361. usidata = (unsigned short *)idata;
  362. while (i < nelem) {
  363. if (usdata[i] != usidata[i]) {
  364. fprintf(stderr, "US element %d did not match (%d != %d)\n", i, usdata[i], usidata[i]);
  365. return;
  366. }
  367. i++;
  368. }
  369. break;
  370. case DATASS: /* signed short */
  371. ssdata = (signed short *)data;
  372. ssidata = (signed short *)idata;
  373. while (i < nelem) {
  374. if (ssdata[i] != ssidata[i]) {
  375. fprintf(stderr, "SS element %d did not match (%d != %d)\n", i, ssdata[i], ssidata[i]);
  376. return;
  377. }
  378. i++;
  379. }
  380. break;
  381. case DATAUI: /* unsigned int */
  382. uidata = (unsigned int *)data;
  383. uiidata = (unsigned int *)idata;
  384. while (i < nelem) {
  385. if (uidata[i] != uiidata[i]) {
  386. fprintf(stderr, "UI element %d did not match (%d != %d)\n", i, uidata[i], uiidata[i]);
  387. return;
  388. }
  389. i++;
  390. }
  391. break;
  392. case DATASI: /* signed int */
  393. sidata = (signed int *)data;
  394. siidata = (signed int *)idata;
  395. while (i < nelem) {
  396. if (sidata[i] != siidata[i]) {
  397. fprintf(stderr, "SI element %d did not match (%d != %d)\n", i, sidata[i], siidata[i]);
  398. return;
  399. }
  400. i++;
  401. }
  402. break;
  403. case DATAUL: /* unsigned long */
  404. uldata = (unsigned long *)data;
  405. ulidata = (unsigned long *)idata;
  406. while (i < nelem) {
  407. if (uldata[i] != ulidata[i]) {
  408. fprintf(stderr, "UL element %d did not match (%ld != %ld)\n", i, uldata[i], ulidata[i]);
  409. return;
  410. }
  411. i++;
  412. }
  413. break;
  414. case DATASL: /* signed long */
  415. sldata = (signed long *)data;
  416. slidata = (signed long *)idata;
  417. while (i < nelem) {
  418. if (sldata[i] != slidata[i]) {
  419. fprintf(stderr, "SL element %d did not match (%ld != %ld)\n", i, sldata[i], slidata[i]);
  420. return;
  421. }
  422. i++;
  423. }
  424. break;
  425. #ifdef CBF_USE_LONG_LONG
  426. case DATAULL: /* unsigned long long */
  427. ulldata = (unsigned long long *)data;
  428. ullidata = (unsigned long long *)idata;
  429. while (i < nelem) {
  430. if (ulldata[i] != ullidata[i]) {
  431. fprintf(stderr, "ULL element %d did not match (%lld != %lld)\n", i, ulldata[i], ullidata[i]);
  432. return;
  433. }
  434. i++;
  435. }
  436. break;
  437. case DATASLL: /* signed long long */
  438. slldata = (signed long long *)data;
  439. sllidata = (signed long long *)idata;
  440. while (i < nelem) {
  441. if (slldata[i] != sllidata[i]) {
  442. fprintf(stderr, "SLL element %d did not match (%lld != %lld)\n", i, slldata[i], sllidata[i]);
  443. return;
  444. }
  445. i++;
  446. }
  447. break;
  448. #else
  449. case DATAULL: /* unsigned long long */
  450. ulldata = (CBF_ull_type *)data;
  451. ullidata = (CBF_ull_type *)idata;
  452. while (i < nelem) {
  453. #if CBF_ULL_INTS == 2
  454. if (ulldata[i].el0 != ullidata[i].el0
  455. || ulldata[i].el1 != ullidata[i].el1) {
  456. fprintf(stderr, "ULL element %d did not match (%x %x != %x %x)\n",
  457. i, ulldata[i].el1,ulldata[i].el0,
  458. ullidata[i].el1,ullidata[i].el0);
  459. return;
  460. }
  461. #else
  462. if (ulldata[i].el0 != ullidata[i].el0
  463. || ulldata[i].el1 != ullidata[i].el1
  464. || ulldata[i].el2 != ullidata[i].el2
  465. || ulldata[i].el3 != ullidata[i].el3) {
  466. fprintf(stderr, "ULL element %d did not match (%x %x %x %x != %x %x %x %x)\n",
  467. i, ulldata[i].el3,ulldata[i].el2,ulldata[i].el1,ulldata[i].el0,
  468. ullidata[i].el3,ullidata[i].el2,ullidata[i].el1,ullidata[i].el0);
  469. return;
  470. }
  471. #endif
  472. i++;
  473. }
  474. break;
  475. case DATASLL: /* signed long long */
  476. slldata = (CBF_sll_type *)data;
  477. sllidata = (CBF_sll_type *)idata;
  478. while (i < nelem) {
  479. #if CBF_SLL_INTS == 2
  480. if (slldata[i].el0 != sllidata[i].el0
  481. || slldata[i].el1 != sllidata[i].el1) {
  482. fprintf(stderr, "SLL element %d did not match (%x %x != %x %x)\n",
  483. i, slldata[i].el1,slldata[i].el0,
  484. sllidata[i].el1,sllidata[i].el0);
  485. return;
  486. }
  487. #else
  488. if (slldata[i].el0 != sllidata[i].el0
  489. || slldata[i].el1 != sllidata[i].el1
  490. || slldata[i].el2 != sllidata[i].el2
  491. || slldata[i].el3 != sllidata[i].el3) {
  492. fprintf(stderr, "ULL element %d did not match (%x %x %x %x != %x %x %x %x)\n",
  493. i, ulldata[i].el3,ulldata[i].el2,ulldata[i].el1,ulldata[i].el0,
  494. ullidata[i].el3,ullidata[i].el2,ullidata[i].el1,ullidata[i].el0);
  495. return;
  496. }
  497. #endif
  498. i++;
  499. }
  500. break;
  501. #endif
  502. case DATAF: /* float */
  503. fdata = (float *)data;
  504. fidata = (float *)idata;
  505. while (i < nelem) {
  506. if (fabs(fdata[i] - fidata[i]) > FLT_MIN) {
  507. fprintf(stderr, "F element %d did not match (%g != %g)\n", i, fdata[i], fidata[i]);
  508. return;
  509. }
  510. i++;
  511. }
  512. break;
  513. case DATAD: /* double */
  514. ddata = (double *)data;
  515. didata = (double *)idata;
  516. while (i < nelem) {
  517. if (fabs(ddata[i] - didata[i]) > DBL_MIN) {
  518. fprintf(stderr, "D element %d did not match (%g != %g)\n", i, ddata[i], didata[i]);
  519. return;
  520. }
  521. i++;
  522. }
  523. break;
  524. }
  525. }
  526. void testinteger(const char *fn, int rows, int cols, int type, int comp)
  527. {
  528. void *data, *idata;
  529. size_t elsize;
  530. size_t nelem = rows*cols;
  531. size_t isize;
  532. int isign;
  533. elsize = createtestimage(&data, type, nelem);
  534. if (elsize == 0) {
  535. fprintf(stderr, "Could not create test image\n");
  536. return;
  537. }
  538. if (createtestfile(fn, 0, rows, cols, comp, data, elsize, type & 1) != 0) {
  539. fprintf(stderr, "Could not create test file\n");
  540. return;
  541. }
  542. if (readtestimage(fn, &idata, &isize, &isign) != nelem) {
  543. fprintf(stderr, "Did not read %ld elements\n", (long) nelem);
  544. }
  545. if (isize != elsize)
  546. fprintf(stderr, "Size of elements does not match (%ld != %ld)\n", (long)elsize, (long)isize);
  547. if (isign != (type & 1))
  548. fprintf(stderr, "Sign of elements does not match (%d != %d)\n", type & 1, isign);
  549. checkdata(type, nelem, data, idata);
  550. free(data);
  551. free(idata);
  552. }
  553. void testreal(const char *fn, int rows, int cols, int type, int comp)
  554. {
  555. void *data, *idata;
  556. size_t elsize;
  557. size_t nelem = rows*cols;
  558. size_t isize;
  559. int isign;
  560. elsize = createtestimage(&data, type, nelem);
  561. if (elsize == 0) {
  562. fprintf(stderr, "Could not create test image\n");
  563. return;
  564. }
  565. if (createtestfile(fn, 1, rows, cols, comp, data, elsize, 1) != 0) {
  566. fprintf(stderr, "Could not create test file\n");
  567. return;
  568. }
  569. if (readtestimage(fn, &idata, &isize, &isign) != nelem) {
  570. fprintf(stderr, "Did not read %ld elements\n", (long) nelem);
  571. }
  572. if (isize != elsize)
  573. fprintf(stderr, "Size of elements does not match (%ld != %ld)\n", (long)elsize, (long)isize);
  574. checkdata(type, nelem, data, idata);
  575. free(data);
  576. free(idata);
  577. }
  578. void testall(const char *fn)
  579. {
  580. int rows = 512;
  581. int cols = 10;
  582. int c, t;
  583. int comp[] = { CBF_NONE,
  584. /* CBF_PREDICTOR, not implemented! */
  585. CBF_BYTE_OFFSET,
  586. CBF_PACKED_V2,
  587. CBF_CANONICAL
  588. };
  589. char * compstr[] = { "CBF_NONE",
  590. /* "CBF_PREDICTOR", */
  591. "CBF_BYTE_OFFSET",
  592. "CBF_PACKED_V2",
  593. "CBF_CANONICAL"
  594. };
  595. char * datastr[] = { "unsigned char",
  596. "signed char", "unsigned short", "signed short",
  597. "unsigned int", "signed int", "unsigned long",
  598. "signed long",
  599. #ifdef CBF_USE_LONG_LONG
  600. "unsigned long long", "signed long long",
  601. #else
  602. "CBF_ull_type", "CBF_sll_type",
  603. #endif
  604. "float", "double"
  605. };
  606. for (c = 0; c < 4; c++) {
  607. printf("Testing compression scheme %d, %d %s\n", c, comp[c], compstr[c]);
  608. for (t = 0; t < DATAF; t++) {
  609. printf(" with data type %d, %s\n", t, datastr[t]);
  610. testinteger(fn, rows, cols, t, comp[c]);
  611. }
  612. printf(" with data type %d, %s\n", DATAF, datastr[DATAF]);
  613. testreal(fn, rows, cols, DATAF, comp[c]);
  614. printf(" with data type %d, %s\n", DATAD, datastr[DATAD]);
  615. testreal(fn, rows, cols, DATAD, comp[c]);
  616. }
  617. }
  618. int main(int argc, char **argv)
  619. {
  620. char *fn;
  621. if (argc < 2)
  622. fn = "CTC.cbf";
  623. else
  624. fn = argv[1];
  625. printf("Saving to %s\n", fn);
  626. testall(fn);
  627. return 0;
  628. }