PageRenderTime 61ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/other/netcdf_write_matrix/src/libsrc/ncx_cray.c

http://github.com/jbeezley/wrf-fire
C | 3843 lines | 3091 code | 645 blank | 107 comment | 652 complexity | 29175625b85311a04b375e239698f8a5 MD5 | raw file
Possible License(s): AGPL-1.0

Large files files are truncated, but you can click here to view the full file

  1. /*
  2. * Copyright 1996, University Corporation for Atmospheric Research
  3. * See netcdf/COPYRIGHT file for copying and redistribution conditions.
  4. *
  5. */
  6. /* $Id: ncx_cray.c,v 1.60 2004/09/30 18:47:12 russ Exp $ */
  7. #ifndef _CRAY
  8. #error "ncx_cray.c is a cray specific implementation"
  9. #endif
  10. /*
  11. * An external data representation interface.
  12. */
  13. /*
  14. * TODO: Fix "off diagonal" functions (ncx_{put,get}[n]_t1_t2() s.t. t1 != t2)
  15. * to be use IEG functions when diagonals are.
  16. *
  17. * Whine to cray about IEG function limiting behavior.
  18. */
  19. #include <string.h>
  20. #include <limits.h>
  21. /* alias poorly named limits.h macros */
  22. #define SHORT_MAX SHRT_MAX
  23. #define SHORT_MIN SHRT_MIN
  24. #define USHORT_MAX USHRT_MAX
  25. #include <float.h>
  26. #include <assert.h>
  27. #include "ncx.h"
  28. /**/
  29. #if USE_IEG
  30. #define C_SIZE_T size_t
  31. extern int
  32. CRAY2IEG(
  33. const int *typep,
  34. const C_SIZE_T *nump,
  35. word *foreignp,
  36. const int *bitoffp,
  37. const void *local,
  38. const int *stride
  39. );
  40. extern int
  41. IEG2CRAY(
  42. const int *typep,
  43. const C_SIZE_T *nump,
  44. const word *foreignp,
  45. const int *bitoffp,
  46. void *local,
  47. const int *stride
  48. );
  49. static const int Zero = 0;
  50. static const C_SIZE_T One = 1;
  51. static const int ThirtyTwo = 32;
  52. static const int UnitStride = 1;
  53. static const int Cray2_I32 = 1; /* 32 bit two complement */
  54. static const int Cray2_F32 = 2; /* IEEE single precision */
  55. static const int Cray2_I16 = 7; /* 16 bit twos complement */
  56. static const int Cray2_F64 = 8; /* CRAY float to IEEE double */
  57. #define SHORT_USE_IEG 1
  58. #define INT_USE_IEG 1
  59. #define FLOAT_USE_IEG 1
  60. #define DOUBLE_USE_IEG 1
  61. #if _CRAY1
  62. /*
  63. * Return the number of bits "into" a word that (void *) is.
  64. * N.B. This is based on the CRAY1 (PVP) address structure,
  65. * which puts the address within a word in the leftmost 3 bits
  66. * of the address.
  67. */
  68. static size_t
  69. bitoff(const void *vp)
  70. {
  71. const size_t bitoffset = ((size_t)vp >> (64 - 6)) & 0x3f;
  72. return bitoffset;
  73. }
  74. # else
  75. #error "Don't use IEG2CRAY, CRAY2IEG except on CRAY1 (MPP) platforms"
  76. #define bitoff(vp) ((size_t)(vp) % 64) /* N.B. Assumes 64 bit word */
  77. # endif /* _CRAY1 */
  78. #endif /* USE_IEG */
  79. #if _CRAY1
  80. /*
  81. * Return the number of bytes "into" a word that (void *) is.
  82. * N.B. This is based on the CRAY1 (PVP) address structure,
  83. * which puts the address within a word in the leftmost 3 bits
  84. * of the address.
  85. */
  86. static size_t
  87. byteoff(const void *vp)
  88. {
  89. const size_t byteoffset = ((size_t)vp >> (64 - 3)) & 0x7;
  90. return byteoffset;
  91. }
  92. #else
  93. #define byteoff(vp) ((size_t)(vp) % 8) /* N.B. Assumes 64 bit word */
  94. #endif /* _CRAY1 */
  95. /*
  96. * Return the number of bytes until the next "word" boundary
  97. */
  98. static size_t
  99. word_align(const void *vp)
  100. {
  101. const size_t rem = byteoff(vp);
  102. if(rem == 0)
  103. return 0;
  104. return sizeof(word) - rem;
  105. }
  106. static const char nada[X_ALIGN] = {0, 0, 0, 0};
  107. /*
  108. * Primitive numeric conversion functions.
  109. */
  110. /* x_schar */
  111. /* We don't implement and x_schar primitives. */
  112. /* x_short */
  113. typedef short ix_short;
  114. #define SIZEOF_IX_SHORT SIZEOF_SHORT
  115. #define IX_SHORT_MAX SHORT_MAX
  116. static void
  117. cget_short_short(const void *xp, short *ip, int which)
  118. {
  119. const long *wp = xp;
  120. switch(which) {
  121. case 0:
  122. *ip = (short)(*wp >> 48);
  123. break;
  124. case 1:
  125. *ip = (short)((*wp >> 32) & 0xffff);
  126. break;
  127. case 2:
  128. *ip = (short)((*wp >> 16) & 0xffff);
  129. break;
  130. case 3:
  131. *ip = (short)(*wp & 0xffff);
  132. break;
  133. }
  134. if(*ip & 0x8000)
  135. {
  136. /* extern is negative */
  137. *ip |= (~(0xffff));
  138. }
  139. }
  140. #define get_ix_short(xp, ip) cget_short_short((xp), (ip), byteoff(xp)/X_SIZEOF_SHORT)
  141. static int
  142. cput_short_short(void *xp, const short *ip, int which)
  143. {
  144. word *wp = xp;
  145. switch(which) {
  146. case 0:
  147. *wp = (*ip << 48)
  148. | (*wp & 0x0000ffffffffffff);
  149. break;
  150. case 1:
  151. *wp = ((*ip << 32) & 0x0000ffff00000000)
  152. | (*wp & 0xffff0000ffffffff);
  153. break;
  154. case 2:
  155. *wp = ((*ip << 16) & 0x00000000ffff0000)
  156. | (*wp & 0xffffffff0000ffff);
  157. break;
  158. case 3:
  159. *wp = (*ip & 0x000000000000ffff)
  160. | (*wp & 0xffffffffffff0000);
  161. break;
  162. }
  163. if(*ip > X_SHORT_MAX || *ip < X_SHORT_MIN)
  164. return NC_ERANGE;
  165. return ENOERR;
  166. }
  167. int
  168. ncx_get_short_schar(const void *xp, schar *ip)
  169. {
  170. ix_short xx;
  171. get_ix_short(xp, &xx);
  172. *ip = xx;
  173. if(xx > SCHAR_MAX || xx < SCHAR_MIN)
  174. return NC_ERANGE;
  175. return ENOERR;
  176. }
  177. int
  178. ncx_get_short_uchar(const void *xp, uchar *ip)
  179. {
  180. ix_short xx;
  181. get_ix_short(xp, &xx);
  182. *ip = xx;
  183. if(xx > UCHAR_MAX || xx < 0)
  184. return NC_ERANGE;
  185. return ENOERR;
  186. }
  187. int
  188. ncx_get_short_short(const void *xp, short *ip)
  189. {
  190. get_ix_short(xp, ip);
  191. return ENOERR;
  192. }
  193. int
  194. ncx_get_short_int(const void *xp, int *ip)
  195. {
  196. ix_short xx;
  197. get_ix_short(xp, &xx);
  198. *ip = xx;
  199. return ENOERR;
  200. }
  201. int
  202. ncx_get_short_long(const void *xp, long *ip)
  203. {
  204. ix_short xx;
  205. get_ix_short(xp, &xx);
  206. *ip = xx;
  207. return ENOERR;
  208. }
  209. int
  210. ncx_get_short_float(const void *xp, float *ip)
  211. {
  212. ix_short xx;
  213. get_ix_short(xp, &xx);
  214. *ip = xx;
  215. return ENOERR;
  216. }
  217. int
  218. ncx_get_short_double(const void *xp, double *ip)
  219. {
  220. ix_short xx;
  221. get_ix_short(xp, &xx);
  222. *ip = xx;
  223. return ENOERR;
  224. }
  225. int
  226. ncx_put_short_schar(void *xp, const schar *ip)
  227. {
  228. uchar *cp = xp;
  229. if(*ip & 0x80)
  230. *cp++ = 0xff;
  231. else
  232. *cp++ = 0;
  233. *cp = (uchar)*ip;
  234. return ENOERR;
  235. }
  236. int
  237. ncx_put_short_uchar(void *xp, const uchar *ip)
  238. {
  239. uchar *cp = xp;
  240. *cp++ = 0;
  241. *cp = *ip;
  242. return ENOERR;
  243. }
  244. int
  245. ncx_put_short_short(void *xp, const short *ip)
  246. {
  247. return cput_short_short(xp, ip, byteoff(xp)/X_SIZEOF_SHORT);
  248. }
  249. int
  250. ncx_put_short_int(void *xp, const int *ip)
  251. {
  252. ix_short xx = (ix_short)*ip;
  253. return cput_short_short(xp, &xx, byteoff(xp)/X_SIZEOF_SHORT);
  254. }
  255. int
  256. ncx_put_short_long(void *xp, const long *ip)
  257. {
  258. ix_short xx = (ix_short)*ip;
  259. return cput_short_short(xp, &xx, byteoff(xp)/X_SIZEOF_SHORT);
  260. }
  261. int
  262. ncx_put_short_float(void *xp, const float *ip)
  263. {
  264. ix_short xx = (ix_short)*ip;
  265. const int status = cput_short_short(xp, &xx, byteoff(xp)/X_SIZEOF_SHORT);
  266. if(status != ENOERR)
  267. return status;
  268. if(*ip > X_SHORT_MAX || *ip < X_SHORT_MIN)
  269. return NC_ERANGE;
  270. return ENOERR;
  271. }
  272. int
  273. ncx_put_short_double(void *xp, const double *ip)
  274. {
  275. ix_short xx = (ix_short)*ip;
  276. const int status = cput_short_short(xp, &xx, byteoff(xp)/X_SIZEOF_SHORT);
  277. if(status != ENOERR)
  278. return status;
  279. if(*ip > X_SHORT_MAX || *ip < X_SHORT_MIN)
  280. return NC_ERANGE;
  281. return ENOERR;
  282. }
  283. /* x_int */
  284. typedef int ix_int;
  285. #define SIZEOF_IX_INT SIZEOF_INT
  286. #define IX_INT_MAX INT_MAX
  287. static void
  288. cget_int_int(const void *xp, int *ip, int which)
  289. {
  290. const long *wp = xp;
  291. if(which == 0)
  292. {
  293. *ip = (int)(*wp >> 32);
  294. }
  295. else
  296. {
  297. *ip = (int)(*wp & 0xffffffff);
  298. }
  299. if(*ip & 0x80000000)
  300. {
  301. /* extern is negative */
  302. *ip |= (~(0xffffffff));
  303. }
  304. }
  305. #define get_ix_int(xp, ip) cget_int_int((xp), (ip), byteoff(xp))
  306. static int
  307. cput_int_int(void *xp, const int *ip, int which)
  308. {
  309. word *wp = xp;
  310. if(which == 0)
  311. {
  312. *wp = (*ip << 32) | (*wp & 0xffffffff);
  313. }
  314. else
  315. {
  316. *wp = (*wp & ~0xffffffff) | (*ip & 0xffffffff);
  317. }
  318. if(*ip > X_INT_MAX || *ip < X_INT_MIN)
  319. return NC_ERANGE;
  320. return ENOERR;
  321. }
  322. #define put_ix_int(xp, ip) cput_int_int((xp), (ip), byteoff(xp))
  323. int
  324. ncx_get_int_schar(const void *xp, schar *ip)
  325. {
  326. ix_int xx;
  327. get_ix_int(xp, &xx);
  328. *ip = xx;
  329. if(xx > SCHAR_MAX || xx < SCHAR_MIN)
  330. return NC_ERANGE;
  331. return ENOERR;
  332. }
  333. int
  334. ncx_get_int_uchar(const void *xp, uchar *ip)
  335. {
  336. ix_int xx;
  337. get_ix_int(xp, &xx);
  338. *ip = xx;
  339. if(xx > UCHAR_MAX || xx < 0)
  340. return NC_ERANGE;
  341. return ENOERR;
  342. }
  343. int
  344. ncx_get_int_short(const void *xp, short *ip)
  345. {
  346. ix_int xx;
  347. get_ix_int(xp, &xx);
  348. *ip = xx;
  349. if(xx > SHORT_MAX || xx < SHORT_MIN)
  350. return NC_ERANGE;
  351. return ENOERR;
  352. }
  353. int
  354. ncx_get_int_int(const void *xp, int *ip)
  355. {
  356. ix_int xx;
  357. get_ix_int(xp, &xx);
  358. *ip = xx;
  359. return ENOERR;
  360. }
  361. static void
  362. cget_int_long(const void *xp, long *ip, int which)
  363. {
  364. const long *wp = xp;
  365. if(which == 0)
  366. {
  367. *ip = (int)(*wp >> 32);
  368. }
  369. else
  370. {
  371. *ip = (int)(*wp & 0xffffffff);
  372. }
  373. if(*ip & 0x80000000)
  374. {
  375. /* extern is negative */
  376. *ip |= (~(0xffffffff));
  377. }
  378. }
  379. int
  380. ncx_get_int_long(const void *xp, long *ip)
  381. {
  382. cget_int_long(xp, ip, byteoff(xp));
  383. return ENOERR;
  384. }
  385. int
  386. ncx_get_int_float(const void *xp, float *ip)
  387. {
  388. ix_int xx;
  389. get_ix_int(xp, &xx);
  390. *ip = xx;
  391. if(xx > FLT_MAX || xx < (-FLT_MAX))
  392. return NC_ERANGE;
  393. return ENOERR;
  394. }
  395. int
  396. ncx_get_int_double(const void *xp, double *ip)
  397. {
  398. ix_int xx;
  399. get_ix_int(xp, &xx);
  400. *ip = xx;
  401. return ENOERR;
  402. }
  403. int
  404. ncx_put_int_schar(void *xp, const schar *ip)
  405. {
  406. uchar *cp = xp;
  407. if(*ip & 0x80)
  408. {
  409. *cp++ = 0xff;
  410. *cp++ = 0xff;
  411. *cp++ = 0xff;
  412. }
  413. else
  414. {
  415. *cp++ = 0x00;
  416. *cp++ = 0x00;
  417. *cp++ = 0x00;
  418. }
  419. *cp = (uchar)*ip;
  420. return ENOERR;
  421. }
  422. int
  423. ncx_put_int_uchar(void *xp, const uchar *ip)
  424. {
  425. uchar *cp = xp;
  426. *cp++ = 0x00;
  427. *cp++ = 0x00;
  428. *cp++ = 0x00;
  429. *cp = *ip;
  430. return ENOERR;
  431. }
  432. int
  433. ncx_put_int_short(void *xp, const short *ip)
  434. {
  435. ix_int xx = (ix_int)(*ip);
  436. return put_ix_int(xp, &xx);
  437. }
  438. int
  439. ncx_put_int_int(void *xp, const int *ip)
  440. {
  441. return put_ix_int(xp, ip);
  442. }
  443. static int
  444. cput_int_long(void *xp, const long *ip, int which)
  445. {
  446. long *wp = xp;
  447. if(which == 0)
  448. {
  449. *wp = (*ip << 32) | (*wp & 0xffffffff);
  450. }
  451. else
  452. {
  453. *wp = (*wp & ~0xffffffff) | (*ip & 0xffffffff);
  454. }
  455. if(*ip > X_INT_MAX || *ip < X_INT_MIN)
  456. return NC_ERANGE;
  457. return ENOERR;
  458. }
  459. int
  460. ncx_put_int_long(void *xp, const long *ip)
  461. {
  462. return cput_int_long(xp, ip, byteoff(xp));
  463. }
  464. int
  465. ncx_put_int_float(void *xp, const float *ip)
  466. {
  467. ix_int xx = (ix_int)(*ip);
  468. const int status = put_ix_int(xp, &xx);
  469. if(status != ENOERR)
  470. return status;
  471. if(*ip > (double)X_INT_MAX || *ip < (double)X_INT_MIN)
  472. return NC_ERANGE;
  473. return ENOERR;
  474. }
  475. int
  476. ncx_put_int_double(void *xp, const double *ip)
  477. {
  478. ix_int xx = (ix_int)(*ip);
  479. const int status = put_ix_int(xp, &xx);
  480. if(status != ENOERR)
  481. return status;
  482. if(*ip > X_INT_MAX || *ip < X_INT_MIN)
  483. return NC_ERANGE;
  484. return ENOERR;
  485. }
  486. /* x_float */
  487. #if defined(NO_IEEE_FLOAT)
  488. struct cray_single {
  489. unsigned int sign : 1;
  490. unsigned int exp :15;
  491. unsigned int mant :48;
  492. };
  493. typedef struct cray_single cray_single;
  494. static const int cs_ieis_bias = 0x4000 - 0x7f;
  495. static const int cs_id_bias = 0x4000 - 0x3ff;
  496. #endif
  497. struct ieee_single_hi {
  498. unsigned int sign : 1;
  499. unsigned int exp : 8;
  500. unsigned int mant :23;
  501. unsigned int pad :32;
  502. };
  503. typedef struct ieee_single_hi ieee_single_hi;
  504. struct ieee_single_lo {
  505. unsigned int pad :32;
  506. unsigned int sign : 1;
  507. unsigned int exp : 8;
  508. unsigned int mant :23;
  509. };
  510. typedef struct ieee_single_lo ieee_single_lo;
  511. static const int ieee_single_bias = 0x7f;
  512. struct ieee_double {
  513. unsigned int sign : 1;
  514. unsigned int exp :11;
  515. unsigned int mant :52;
  516. };
  517. typedef struct ieee_double ieee_double;
  518. static const int ieee_double_bias = 0x3ff;
  519. #if FLOAT_USE_IEG
  520. static void
  521. get_ix_float(const void *xp, float *ip)
  522. {
  523. const int bo = bitoff(xp);
  524. (void) IEG2CRAY(&Cray2_F32, &One, (word *)xp, &bo, ip, &UnitStride);
  525. }
  526. static int
  527. put_ix_float(void *xp, const float *ip)
  528. {
  529. const int bo = bitoff(xp);
  530. int status = CRAY2IEG(&Cray2_F32, &One, (word *)xp, &bo, ip, &UnitStride);
  531. if(status != 0)
  532. status = NC_ERANGE;
  533. /* else, status == 0 == ENOERR */
  534. return status;
  535. }
  536. #else
  537. /* !FLOAT_USE_IEG */
  538. #if defined(NO_IEEE_FLOAT)
  539. static void
  540. cget_float_float(const void *xp, float *ip, int which)
  541. {
  542. if(which == 0)
  543. {
  544. const ieee_single_hi *isp = (const ieee_single_hi *) xp;
  545. cray_single *csp = (cray_single *) ip;
  546. if(isp->exp == 0)
  547. {
  548. /* ieee subnormal */
  549. *ip = (double)isp->mant;
  550. if(isp->mant != 0)
  551. {
  552. csp->exp -= (ieee_single_bias + 22);
  553. }
  554. }
  555. else
  556. {
  557. csp->exp = isp->exp + cs_ieis_bias + 1;
  558. csp->mant = isp->mant << (48 - 1 - 23);
  559. csp->mant |= (1 << (48 - 1));
  560. }
  561. csp->sign = isp->sign;
  562. }
  563. else
  564. {
  565. const ieee_single_lo *isp = (const ieee_single_lo *) xp;
  566. cray_single *csp = (cray_single *) ip;
  567. if(isp->exp == 0)
  568. {
  569. /* ieee subnormal */
  570. *ip = (double)isp->mant;
  571. if(isp->mant != 0)
  572. {
  573. csp->exp -= (ieee_single_bias + 22);
  574. }
  575. }
  576. else
  577. {
  578. csp->exp = isp->exp + cs_ieis_bias + 1;
  579. csp->mant = isp->mant << (48 - 1 - 23);
  580. csp->mant |= (1 << (48 - 1));
  581. }
  582. csp->sign = isp->sign;
  583. }
  584. }
  585. static int
  586. cput_float_float(void *xp, const float *ip, int which)
  587. {
  588. int status = ENOERR;
  589. if(which == 0)
  590. {
  591. ieee_single_hi *isp = (ieee_single_hi*)xp;
  592. const cray_single *csp = (const cray_single *) ip;
  593. int ieee_exp = csp->exp - cs_ieis_bias -1;
  594. isp->sign = csp->sign;
  595. if(ieee_exp >= 0xff
  596. || *ip > X_FLOAT_MAX || *ip < X_FLOAT_MIN)
  597. {
  598. /* NC_ERANGE => ieee Inf */
  599. isp->exp = 0xff;
  600. isp->mant = 0x0;
  601. return NC_ERANGE;
  602. }
  603. /* else */
  604. if(ieee_exp > 0)
  605. {
  606. /* normal ieee representation */
  607. isp->exp = ieee_exp;
  608. /* assumes cray rep is in normal form */
  609. /* assert(csp->mant & 0x800000000000); */
  610. isp->mant = (((csp->mant << 1) &
  611. 0xffffffffffff) >> (48 - 23));
  612. }
  613. else if(ieee_exp > -23)
  614. {
  615. /* ieee subnormal, right */
  616. const int rshift = (48 - 23 - ieee_exp);
  617. isp->mant = csp->mant >> rshift;
  618. isp->exp = 0;
  619. }
  620. else
  621. {
  622. /* smaller than ieee can represent */
  623. isp->exp = 0;
  624. isp->mant = 0;
  625. }
  626. }
  627. else
  628. {
  629. ieee_single_lo *isp = (ieee_single_lo*)xp;
  630. const cray_single *csp = (const cray_single *) ip;
  631. int ieee_exp = csp->exp - cs_ieis_bias -1;
  632. isp->sign = csp->sign;
  633. if(ieee_exp >= 0xff
  634. || *ip > X_FLOAT_MAX || *ip < X_FLOAT_MIN)
  635. {
  636. /* NC_ERANGE => ieee Inf */
  637. isp->exp = 0xff;
  638. isp->mant = 0x0;
  639. return NC_ERANGE;
  640. }
  641. /* else */
  642. if(ieee_exp > 0)
  643. {
  644. /* normal ieee representation */
  645. isp->exp = ieee_exp;
  646. /* assumes cray rep is in normal form */
  647. /* assert(csp->mant & 0x800000000000); */
  648. isp->mant = (((csp->mant << 1) &
  649. 0xffffffffffff) >> (48 - 23));
  650. }
  651. else if(ieee_exp > -23)
  652. {
  653. /* ieee subnormal, right */
  654. const int rshift = (48 - 23 - ieee_exp);
  655. isp->mant = csp->mant >> rshift;
  656. isp->exp = 0;
  657. }
  658. else
  659. {
  660. /* smaller than ieee can represent */
  661. isp->exp = 0;
  662. isp->mant = 0;
  663. }
  664. }
  665. return ENOERR;
  666. }
  667. #define get_ix_float(xp, ip) cget_float_float((xp), (ip), byteoff(xp))
  668. #define put_ix_float(xp, ip) cput_float_float((xp), (ip), byteoff(xp))
  669. #else
  670. /* IEEE Cray with only doubles */
  671. static void
  672. cget_float_float(const void *xp, float *ip, int which)
  673. {
  674. ieee_double *idp = (ieee_double *) ip;
  675. if(which == 0)
  676. {
  677. const ieee_single_hi *isp = (const ieee_single_hi *) xp;
  678. if(isp->exp == 0 && isp->mant == 0)
  679. {
  680. idp->exp = 0;
  681. idp->mant = 0;
  682. }
  683. else
  684. {
  685. idp->exp = isp->exp + (ieee_double_bias - ieee_single_bias);
  686. idp->mant = isp->mant << (52 - 23);
  687. }
  688. idp->sign = isp->sign;
  689. }
  690. else
  691. {
  692. const ieee_single_lo *isp = (const ieee_single_lo *) xp;
  693. if(isp->exp == 0 && isp->mant == 0)
  694. {
  695. idp->exp = 0;
  696. idp->mant = 0;
  697. }
  698. else
  699. {
  700. idp->exp = isp->exp + (ieee_double_bias - ieee_single_bias);
  701. idp->mant = isp->mant << (52 - 23);
  702. }
  703. idp->sign = isp->sign;
  704. }
  705. }
  706. static int
  707. cput_float_float(void *xp, const float *ip, int which)
  708. {
  709. const ieee_double *idp = (const ieee_double *) ip;
  710. if(which == 0)
  711. {
  712. ieee_single_hi *isp = (ieee_single_hi*)xp;
  713. if(idp->exp > (ieee_double_bias - ieee_single_bias))
  714. isp->exp = idp->exp - (ieee_double_bias - ieee_single_bias);
  715. else
  716. isp->exp = 0;
  717. isp->mant = idp->mant >> (52 - 23);
  718. isp->sign = idp->sign;
  719. }
  720. else
  721. {
  722. ieee_single_lo *isp = (ieee_single_lo*)xp;
  723. if(idp->exp > (ieee_double_bias - ieee_single_bias))
  724. isp->exp = idp->exp - (ieee_double_bias - ieee_single_bias);
  725. else
  726. isp->exp = 0;
  727. isp->mant = idp->mant >> (52 - 23);
  728. isp->sign = idp->sign;
  729. }
  730. if(*ip > X_FLOAT_MAX || *ip < X_FLOAT_MIN)
  731. return NC_ERANGE;
  732. return ENOERR;
  733. }
  734. #define get_ix_float(xp, ip) cget_float_float((xp), (ip), byteoff(xp))
  735. #define put_ix_float(xp, ip) cput_float_float((xp), (ip), byteoff(xp))
  736. #endif /* NO_IEEE_FLOAT */
  737. #endif /* FLOAT_USE_IEG */
  738. int
  739. ncx_get_float_schar(const void *xp, schar *ip)
  740. {
  741. float xx;
  742. get_ix_float(xp, &xx);
  743. *ip = (schar) xx;
  744. if(xx > SCHAR_MAX || xx < SCHAR_MIN)
  745. return NC_ERANGE;
  746. return ENOERR;
  747. }
  748. int
  749. ncx_get_float_uchar(const void *xp, uchar *ip)
  750. {
  751. float xx;
  752. get_ix_float(xp, &xx);
  753. *ip = (uchar) xx;
  754. if(xx > UCHAR_MAX || xx < 0)
  755. return NC_ERANGE;
  756. return ENOERR;
  757. }
  758. int
  759. ncx_get_float_short(const void *xp, short *ip)
  760. {
  761. float xx;
  762. get_ix_float(xp, &xx);
  763. *ip = (short) xx;
  764. if(xx > SHORT_MAX || xx < SHORT_MIN)
  765. return NC_ERANGE;
  766. return ENOERR;
  767. }
  768. int
  769. ncx_get_float_int(const void *xp, int *ip)
  770. {
  771. float xx;
  772. get_ix_float(xp, &xx);
  773. *ip = (int) xx;
  774. if(xx > (double)INT_MAX || xx < (double)INT_MIN)
  775. return NC_ERANGE;
  776. return ENOERR;
  777. }
  778. int
  779. ncx_get_float_long(const void *xp, long *ip)
  780. {
  781. float xx;
  782. get_ix_float(xp, &xx);
  783. *ip = (long) xx;
  784. if(xx > LONG_MAX || xx < LONG_MIN)
  785. return NC_ERANGE;
  786. return ENOERR;
  787. }
  788. int
  789. ncx_get_float_float(const void *xp, float *ip)
  790. {
  791. get_ix_float(xp, ip);
  792. return ENOERR;
  793. }
  794. int
  795. ncx_get_float_double(const void *xp, double *ip)
  796. {
  797. #if SIZEOF_FLOAT == SIZEOF_DOUBLE && FLT_MANT_DIG == DBL_MANT_DIG
  798. return ncx_get_float_float(xp, (float *)ip);
  799. #else
  800. float xx;
  801. get_ix_float(xp, &xx);
  802. *ip = xx;
  803. return ENOERR;
  804. #endif
  805. }
  806. int
  807. ncx_put_float_schar(void *xp, const schar *ip)
  808. {
  809. float xx = (float) *ip;
  810. return put_ix_float(xp, &xx);
  811. }
  812. int
  813. ncx_put_float_uchar(void *xp, const uchar *ip)
  814. {
  815. float xx = (float) *ip;
  816. return put_ix_float(xp, &xx);
  817. }
  818. int
  819. ncx_put_float_short(void *xp, const short *ip)
  820. {
  821. float xx = (float) *ip;
  822. return put_ix_float(xp, &xx);
  823. }
  824. int
  825. ncx_put_float_int(void *xp, const int *ip)
  826. {
  827. float xx = (float) *ip;
  828. return put_ix_float(xp, &xx);
  829. }
  830. int
  831. ncx_put_float_long(void *xp, const long *ip)
  832. {
  833. float xx = (float) *ip;
  834. return put_ix_float(xp, &xx);
  835. }
  836. int
  837. ncx_put_float_float(void *xp, const float *ip)
  838. {
  839. return put_ix_float(xp, ip);
  840. }
  841. int
  842. ncx_put_float_double(void *xp, const double *ip)
  843. {
  844. #if SIZEOF_FLOAT == SIZEOF_DOUBLE && FLT_MANT_DIG == DBL_MANT_DIG
  845. return put_ix_float(xp, (float *)ip);
  846. #else
  847. float xx = (float) *ip;
  848. int status = put_ix_float(xp, &xx);
  849. if(*ip > X_FLOAT_MAX || *ip < X_FLOAT_MIN)
  850. return NC_ERANGE;
  851. return status;
  852. #endif
  853. }
  854. /* x_double */
  855. #if X_SIZEOF_DOUBLE == SIZEOF_DOUBLE && !defined(NO_IEEE_FLOAT)
  856. static void
  857. get_ix_double(const void *xp, double *ip)
  858. {
  859. (void) memcpy(ip, xp, sizeof(double));
  860. }
  861. static int
  862. put_ix_double(void *xp, const double *ip)
  863. {
  864. (void) memcpy(xp, ip, X_SIZEOF_DOUBLE);
  865. return ENOERR;
  866. }
  867. #else
  868. static void
  869. cget_double_double(const void *xp, double *ip)
  870. {
  871. const ieee_double *idp = (const ieee_double *) xp;
  872. cray_single *csp = (cray_single *) ip;
  873. if(idp->exp == 0)
  874. {
  875. /* ieee subnormal */
  876. *ip = (double)idp->mant;
  877. if(idp->mant != 0)
  878. {
  879. csp->exp -= (ieee_double_bias + 51);
  880. }
  881. }
  882. else
  883. {
  884. csp->exp = idp->exp + cs_id_bias + 1;
  885. csp->mant = idp->mant >> (52 - 48 + 1);
  886. csp->mant |= (1 << (48 - 1));
  887. }
  888. csp->sign = idp->sign;
  889. }
  890. static int
  891. cput_double_double(void *xp, const double *ip)
  892. {
  893. ieee_double *idp = (ieee_double *) xp;
  894. const cray_single *csp = (const cray_single *) ip;
  895. int ieee_exp = csp->exp - cs_id_bias -1;
  896. idp->sign = csp->sign;
  897. if(ieee_exp >= 0x7ff)
  898. {
  899. /* NC_ERANGE => ieee Inf */
  900. idp->exp = 0x7ff;
  901. idp->mant = 0x0;
  902. return NC_ERANGE;
  903. }
  904. /* else */
  905. if(ieee_exp > 0)
  906. {
  907. /* normal ieee representation */
  908. idp->exp = ieee_exp;
  909. /* assumes cray rep is in normal form */
  910. assert(csp->mant & 0x800000000000);
  911. idp->mant = (((csp->mant << 1) &
  912. 0xffffffffffff) << (52 - 48));
  913. }
  914. else if(ieee_exp >= (-(52 -48)))
  915. {
  916. /* ieee subnormal, left */
  917. const int lshift = (52 - 48) + ieee_exp;
  918. idp->mant = csp->mant << lshift;
  919. idp->exp = 0;
  920. }
  921. else if(ieee_exp >= -52)
  922. {
  923. /* ieee subnormal, right */
  924. const int rshift = (- (52 - 48) - ieee_exp);
  925. idp->mant = csp->mant >> rshift;
  926. idp->exp = 0;
  927. }
  928. else
  929. {
  930. /* smaller than ieee can represent */
  931. idp->exp = 0;
  932. idp->mant = 0;
  933. }
  934. return ENOERR;
  935. }
  936. #define get_ix_double(xp, ip) cget_double_double((xp), (ip))
  937. #define put_ix_double(xp, ip) cput_double_double((xp), (ip))
  938. #endif /* NO_IEEE_FLOAT */
  939. int
  940. ncx_get_double_schar(const void *xp, schar *ip)
  941. {
  942. double xx;
  943. get_ix_double(xp, &xx);
  944. *ip = (schar) xx;
  945. if(xx > SCHAR_MAX || xx < SCHAR_MIN)
  946. return NC_ERANGE;
  947. return ENOERR;
  948. }
  949. int
  950. ncx_get_double_uchar(const void *xp, uchar *ip)
  951. {
  952. double xx;
  953. get_ix_double(xp, &xx);
  954. *ip = (uchar) xx;
  955. if(xx > UCHAR_MAX || xx < 0)
  956. return NC_ERANGE;
  957. return ENOERR;
  958. }
  959. int
  960. ncx_get_double_short(const void *xp, short *ip)
  961. {
  962. double xx;
  963. get_ix_double(xp, &xx);
  964. *ip = (short) xx;
  965. if(xx > SHORT_MAX || xx < SHORT_MIN)
  966. return NC_ERANGE;
  967. return ENOERR;
  968. }
  969. int
  970. ncx_get_double_int(const void *xp, int *ip)
  971. {
  972. double xx;
  973. get_ix_double(xp, &xx);
  974. *ip = (int) xx;
  975. if(xx > INT_MAX || xx < INT_MIN)
  976. return NC_ERANGE;
  977. return ENOERR;
  978. }
  979. int
  980. ncx_get_double_long(const void *xp, long *ip)
  981. {
  982. double xx;
  983. get_ix_double(xp, &xx);
  984. *ip = (long) xx;
  985. if(xx > LONG_MAX || xx < LONG_MIN)
  986. return NC_ERANGE;
  987. return ENOERR;
  988. }
  989. int
  990. ncx_get_double_float(const void *xp, float *ip)
  991. {
  992. #if SIZEOF_FLOAT == SIZEOF_DOUBLE && FLT_MANT_DIG == DBL_MANT_DIG
  993. get_ix_double(xp, (double *)ip);
  994. return ENOERR;
  995. #else
  996. double xx;
  997. get_ix_double(xp, &xx);
  998. if(xx > FLT_MAX || xx < (-FLT_MAX))
  999. {
  1000. *ip = FLT_MAX;
  1001. return NC_ERANGE;
  1002. }
  1003. if(xx < (-FLT_MAX))
  1004. {
  1005. *ip = (-FLT_MAX);
  1006. return NC_ERANGE;
  1007. }
  1008. *ip = (float) xx;
  1009. return ENOERR;
  1010. #endif
  1011. }
  1012. int
  1013. ncx_get_double_double(const void *xp, double *ip)
  1014. {
  1015. get_ix_double(xp, ip);
  1016. return ENOERR;
  1017. }
  1018. int
  1019. ncx_put_double_schar(void *xp, const schar *ip)
  1020. {
  1021. double xx = (double) *ip;
  1022. put_ix_double(xp, &xx);
  1023. return ENOERR;
  1024. }
  1025. int
  1026. ncx_put_double_uchar(void *xp, const uchar *ip)
  1027. {
  1028. double xx = (double) *ip;
  1029. put_ix_double(xp, &xx);
  1030. return ENOERR;
  1031. }
  1032. int
  1033. ncx_put_double_short(void *xp, const short *ip)
  1034. {
  1035. double xx = (double) *ip;
  1036. put_ix_double(xp, &xx);
  1037. return ENOERR;
  1038. }
  1039. int
  1040. ncx_put_double_int(void *xp, const int *ip)
  1041. {
  1042. double xx = (double) *ip;
  1043. put_ix_double(xp, &xx);
  1044. return ENOERR;
  1045. }
  1046. int
  1047. ncx_put_double_long(void *xp, const long *ip)
  1048. {
  1049. double xx = (double) *ip;
  1050. put_ix_double(xp, &xx);
  1051. /* TODO: Deal with big guys */
  1052. return ENOERR;
  1053. }
  1054. int
  1055. ncx_put_double_float(void *xp, const float *ip)
  1056. {
  1057. #if SIZEOF_FLOAT == SIZEOF_DOUBLE && FLT_MANT_DIG == DBL_MANT_DIG
  1058. put_ix_double(xp, (double *)ip);
  1059. return ENOERR;
  1060. #else
  1061. double xx = (double) *ip;
  1062. return put_ix_double(xp, &xx);
  1063. #endif
  1064. }
  1065. int
  1066. ncx_put_double_double(void *xp, const double *ip)
  1067. {
  1068. #if !defined(NO_IEEE_FLOAT)
  1069. put_ix_double(xp, ip);
  1070. return ENOERR;
  1071. #else
  1072. return put_ix_double(xp, ip);
  1073. #endif
  1074. }
  1075. /* x_size_t */
  1076. int
  1077. ncx_put_size_t(void **xpp, const size_t *ulp)
  1078. {
  1079. /* similar to put_ix_int() */
  1080. uchar *cp = *xpp;
  1081. assert(*ulp <= X_SIZE_MAX);
  1082. *cp++ = (uchar)((*ulp) >> 24);
  1083. *cp++ = (uchar)(((*ulp) & 0x00ff0000) >> 16);
  1084. *cp++ = (uchar)(((*ulp) & 0x0000ff00) >> 8);
  1085. *cp = (uchar)((*ulp) & 0x000000ff);
  1086. *xpp = (void *)((char *)(*xpp) + X_SIZEOF_SIZE_T);
  1087. return ENOERR;
  1088. }
  1089. int
  1090. ncx_get_size_t(const void **xpp, size_t *ulp)
  1091. {
  1092. /* similar to get_ix_int */
  1093. const uchar *cp = *xpp;
  1094. assert((*cp & 0x80) == 0); /* sizes limited to 2^31 -1 in netcdf */
  1095. *ulp = *cp++ << 24;
  1096. *ulp |= (*cp++ << 16);
  1097. *ulp |= (*cp++ << 8);
  1098. *ulp |= *cp;
  1099. *xpp = (const void *)((const char *)(*xpp) + X_SIZEOF_SIZE_T);
  1100. return ENOERR;
  1101. }
  1102. /* x_off_t */
  1103. int
  1104. ncx_put_off_t(void **xpp, const off_t *lp)
  1105. {
  1106. /* similar to put_ix_int() */
  1107. uchar *cp = *xpp;
  1108. /* No negative offsets stored in netcdf */
  1109. assert(*lp >= 0 && *lp <= X_OFF_MAX);
  1110. *cp++ = (uchar)((*lp) >> 24);
  1111. *cp++ = (uchar)(((*lp) & 0x00ff0000) >> 16);
  1112. *cp++ = (uchar)(((*lp) & 0x0000ff00) >> 8);
  1113. *cp = (uchar)((*lp) & 0x000000ff);
  1114. *xpp = (void *)((char *)(*xpp) + X_SIZEOF_OFF_T);
  1115. return ENOERR;
  1116. }
  1117. int
  1118. ncx_get_off_t(const void **xpp, off_t *lp)
  1119. {
  1120. /* similar to get_ix_int() */
  1121. const uchar *cp = *xpp;
  1122. assert((*cp & 0x80) == 0); /* No negative offsets stored in netcdf */
  1123. *lp = *cp++ << 24;
  1124. *lp |= (*cp++ << 16);
  1125. *lp |= (*cp++ << 8);
  1126. *lp |= *cp;
  1127. *xpp = (const void *)((const char *)(*xpp) + X_SIZEOF_OFF_T);
  1128. return ENOERR;
  1129. }
  1130. /*
  1131. * Aggregate numeric conversion functions.
  1132. */
  1133. /* schar */
  1134. int
  1135. ncx_getn_schar_schar(const void **xpp, size_t nelems, schar *tp)
  1136. {
  1137. (void) memcpy(tp, *xpp, nelems);
  1138. *xpp = (void *)((char *)(*xpp) + nelems);
  1139. return ENOERR;
  1140. }
  1141. int
  1142. ncx_getn_schar_uchar(const void **xpp, size_t nelems, uchar *tp)
  1143. {
  1144. (void) memcpy(tp, *xpp, nelems);
  1145. *xpp = (void *)((char *)(*xpp) + nelems);
  1146. return ENOERR;
  1147. }
  1148. int
  1149. ncx_getn_schar_short(const void **xpp, size_t nelems, short *tp)
  1150. {
  1151. schar *xp = (schar *)(*xpp);
  1152. while(nelems-- != 0)
  1153. {
  1154. *tp++ = *xp++;
  1155. }
  1156. *xpp = (const void *)xp;
  1157. return ENOERR;
  1158. }
  1159. int
  1160. ncx_getn_schar_int(const void **xpp, size_t nelems, int *tp)
  1161. {
  1162. schar *xp = (schar *)(*xpp);
  1163. while(nelems-- != 0)
  1164. {
  1165. *tp++ = *xp++;
  1166. }
  1167. *xpp = (const void *)xp;
  1168. return ENOERR;
  1169. }
  1170. int
  1171. ncx_getn_schar_long(const void **xpp, size_t nelems, long *tp)
  1172. {
  1173. schar *xp = (schar *)(*xpp);
  1174. while(nelems-- != 0)
  1175. {
  1176. *tp++ = *xp++;
  1177. }
  1178. *xpp = (const void *)xp;
  1179. return ENOERR;
  1180. }
  1181. int
  1182. ncx_getn_schar_float(const void **xpp, size_t nelems, float *tp)
  1183. {
  1184. schar *xp = (schar *)(*xpp);
  1185. while(nelems-- != 0)
  1186. {
  1187. *tp++ = *xp++;
  1188. }
  1189. *xpp = (const void *)xp;
  1190. return ENOERR;
  1191. }
  1192. int
  1193. ncx_getn_schar_double(const void **xpp, size_t nelems, double *tp)
  1194. {
  1195. schar *xp = (schar *)(*xpp);
  1196. while(nelems-- != 0)
  1197. {
  1198. *tp++ = *xp++;
  1199. }
  1200. *xpp = (const void *)xp;
  1201. return ENOERR;
  1202. }
  1203. int
  1204. ncx_pad_getn_schar_schar(const void **xpp, size_t nelems, schar *tp)
  1205. {
  1206. size_t rndup = nelems % X_ALIGN;
  1207. if(rndup)
  1208. rndup = X_ALIGN - rndup;
  1209. (void) memcpy(tp, *xpp, nelems);
  1210. *xpp = (void *)((char *)(*xpp) + nelems + rndup);
  1211. return ENOERR;
  1212. }
  1213. int
  1214. ncx_pad_getn_schar_uchar(const void **xpp, size_t nelems, uchar *tp)
  1215. {
  1216. size_t rndup = nelems % X_ALIGN;
  1217. if(rndup)
  1218. rndup = X_ALIGN - rndup;
  1219. (void) memcpy(tp, *xpp, nelems);
  1220. *xpp = (void *)((char *)(*xpp) + nelems + rndup);
  1221. return ENOERR;
  1222. }
  1223. int
  1224. ncx_pad_getn_schar_short(const void **xpp, size_t nelems, short *tp)
  1225. {
  1226. size_t rndup = nelems % X_ALIGN;
  1227. schar *xp = (schar *)(*xpp);
  1228. if(rndup)
  1229. rndup = X_ALIGN - rndup;
  1230. while(nelems-- != 0)
  1231. {
  1232. *tp++ = *xp++;
  1233. }
  1234. *xpp = (void *)(xp + rndup);
  1235. return ENOERR;
  1236. }
  1237. int
  1238. ncx_pad_getn_schar_int(const void **xpp, size_t nelems, int *tp)
  1239. {
  1240. size_t rndup = nelems % X_ALIGN;
  1241. schar *xp = (schar *)(*xpp);
  1242. if(rndup)
  1243. rndup = X_ALIGN - rndup;
  1244. while(nelems-- != 0)
  1245. {
  1246. *tp++ = *xp++;
  1247. }
  1248. *xpp = (void *)(xp + rndup);
  1249. return ENOERR;
  1250. }
  1251. int
  1252. ncx_pad_getn_schar_long(const void **xpp, size_t nelems, long *tp)
  1253. {
  1254. size_t rndup = nelems % X_ALIGN;
  1255. schar *xp = (schar *)(*xpp);
  1256. if(rndup)
  1257. rndup = X_ALIGN - rndup;
  1258. while(nelems-- != 0)
  1259. {
  1260. *tp++ = *xp++;
  1261. }
  1262. *xpp = (void *)(xp + rndup);
  1263. return ENOERR;
  1264. }
  1265. int
  1266. ncx_pad_getn_schar_float(const void **xpp, size_t nelems, float *tp)
  1267. {
  1268. size_t rndup = nelems % X_ALIGN;
  1269. schar *xp = (schar *)(*xpp);
  1270. if(rndup)
  1271. rndup = X_ALIGN - rndup;
  1272. while(nelems-- != 0)
  1273. {
  1274. *tp++ = *xp++;
  1275. }
  1276. *xpp = (void *)(xp + rndup);
  1277. return ENOERR;
  1278. }
  1279. int
  1280. ncx_pad_getn_schar_double(const void **xpp, size_t nelems, double *tp)
  1281. {
  1282. size_t rndup = nelems % X_ALIGN;
  1283. schar *xp = (schar *)(*xpp);
  1284. if(rndup)
  1285. rndup = X_ALIGN - rndup;
  1286. while(nelems-- != 0)
  1287. {
  1288. *tp++ = *xp++;
  1289. }
  1290. *xpp = (void *)(xp + rndup);
  1291. return ENOERR;
  1292. }
  1293. int
  1294. ncx_putn_schar_schar(void **xpp, size_t nelems, const schar *tp)
  1295. {
  1296. (void) memcpy(*xpp, tp, nelems);
  1297. *xpp = (void *)((char *)(*xpp) + nelems);
  1298. return ENOERR;
  1299. }
  1300. int
  1301. ncx_putn_schar_uchar(void **xpp, size_t nelems, const uchar *tp)
  1302. {
  1303. (void) memcpy(*xpp, tp, nelems);
  1304. *xpp = (void *)((char *)(*xpp) + nelems);
  1305. return ENOERR;
  1306. }
  1307. int
  1308. ncx_putn_schar_short(void **xpp, size_t nelems, const short *tp)
  1309. {
  1310. int status = ENOERR;
  1311. schar *xp = (schar *)(*xpp);
  1312. while(nelems-- != 0)
  1313. {
  1314. if(*tp > X_SCHAR_MAX || *tp < X_SCHAR_MIN)
  1315. status = NC_ERANGE;
  1316. *xp++ = (schar) *tp++;
  1317. }
  1318. *xpp = (void *)xp;
  1319. return status;
  1320. }
  1321. int
  1322. ncx_putn_schar_int(void **xpp, size_t nelems, const int *tp)
  1323. {
  1324. int status = ENOERR;
  1325. schar *xp = (schar *)(*xpp);
  1326. while(nelems-- != 0)
  1327. {
  1328. if(*tp > X_SCHAR_MAX || *tp < X_SCHAR_MIN)
  1329. status = NC_ERANGE;
  1330. *xp++ = (schar) *tp++;
  1331. }
  1332. *xpp = (void *)xp;
  1333. return status;
  1334. }
  1335. int
  1336. ncx_putn_schar_long(void **xpp, size_t nelems, const long *tp)
  1337. {
  1338. int status = ENOERR;
  1339. schar *xp = (schar *)(*xpp);
  1340. while(nelems-- != 0)
  1341. {
  1342. if(*tp > X_SCHAR_MAX || *tp < X_SCHAR_MIN)
  1343. status = NC_ERANGE;
  1344. *xp++ = (schar) *tp++;
  1345. }
  1346. *xpp = (void *)xp;
  1347. return status;
  1348. }
  1349. int
  1350. ncx_putn_schar_float(void **xpp, size_t nelems, const float *tp)
  1351. {
  1352. int status = ENOERR;
  1353. schar *xp = (schar *)(*xpp);
  1354. while(nelems-- != 0)
  1355. {
  1356. if(*tp > X_SCHAR_MAX || *tp < X_SCHAR_MIN)
  1357. status = NC_ERANGE;
  1358. *xp++ = (schar) *tp++;
  1359. }
  1360. *xpp = (void *)xp;
  1361. return status;
  1362. }
  1363. int
  1364. ncx_putn_schar_double(void **xpp, size_t nelems, const double *tp)
  1365. {
  1366. int status = ENOERR;
  1367. schar *xp = (schar *)(*xpp);
  1368. while(nelems-- != 0)
  1369. {
  1370. if(*tp > X_SCHAR_MAX || *tp < X_SCHAR_MIN)
  1371. status = NC_ERANGE;
  1372. *xp++ = (schar) *tp++;
  1373. }
  1374. *xpp = (void *)xp;
  1375. return status;
  1376. }
  1377. int
  1378. ncx_pad_putn_schar_schar(void **xpp, size_t nelems, const schar *tp)
  1379. {
  1380. size_t rndup = nelems % X_ALIGN;
  1381. if(rndup)
  1382. rndup = X_ALIGN - rndup;
  1383. (void) memcpy(*xpp, tp, nelems);
  1384. *xpp = (void *)((char *)(*xpp) + nelems);
  1385. if(rndup)
  1386. {
  1387. (void) memcpy(*xpp, nada, rndup);
  1388. *xpp = (void *)((char *)(*xpp) + rndup);
  1389. }
  1390. return ENOERR;
  1391. }
  1392. int
  1393. ncx_pad_putn_schar_uchar(void **xpp, size_t nelems, const uchar *tp)
  1394. {
  1395. size_t rndup = nelems % X_ALIGN;
  1396. if(rndup)
  1397. rndup = X_ALIGN - rndup;
  1398. (void) memcpy(*xpp, tp, nelems);
  1399. *xpp = (void *)((char *)(*xpp) + nelems);
  1400. if(rndup)
  1401. {
  1402. (void) memcpy(*xpp, nada, rndup);
  1403. *xpp = (void *)((char *)(*xpp) + rndup);
  1404. }
  1405. return ENOERR;
  1406. }
  1407. int
  1408. ncx_pad_putn_schar_short(void **xpp, size_t nelems, const short *tp)
  1409. {
  1410. int status = ENOERR;
  1411. size_t rndup = nelems % X_ALIGN;
  1412. schar *xp = (schar *)(*xpp);
  1413. if(rndup)
  1414. rndup = X_ALIGN - rndup;
  1415. while(nelems-- != 0)
  1416. {
  1417. /* N.B. schar as signed */
  1418. if(*tp > X_SCHAR_MAX || *tp < X_SCHAR_MIN)
  1419. status = NC_ERANGE;
  1420. *xp++ = (schar) *tp++;
  1421. }
  1422. if(rndup)
  1423. {
  1424. (void) memcpy(xp, nada, rndup);
  1425. xp += rndup;
  1426. }
  1427. *xpp = (void *)xp;
  1428. return status;
  1429. }
  1430. int
  1431. ncx_pad_putn_schar_int(void **xpp, size_t nelems, const int *tp)
  1432. {
  1433. int status = ENOERR;
  1434. size_t rndup = nelems % X_ALIGN;
  1435. schar *xp = (schar *)(*xpp);
  1436. if(rndup)
  1437. rndup = X_ALIGN - rndup;
  1438. while(nelems-- != 0)
  1439. {
  1440. /* N.B. schar as signed */
  1441. if(*tp > X_SCHAR_MAX || *tp < X_SCHAR_MIN)
  1442. status = NC_ERANGE;
  1443. *xp++ = (schar) *tp++;
  1444. }
  1445. if(rndup)
  1446. {
  1447. (void) memcpy(xp, nada, rndup);
  1448. xp += rndup;
  1449. }
  1450. *xpp = (void *)xp;
  1451. return status;
  1452. }
  1453. int
  1454. ncx_pad_putn_schar_long(void **xpp, size_t nelems, const long *tp)
  1455. {
  1456. int status = ENOERR;
  1457. size_t rndup = nelems % X_ALIGN;
  1458. schar *xp = (schar *)(*xpp);
  1459. if(rndup)
  1460. rndup = X_ALIGN - rndup;
  1461. while(nelems-- != 0)
  1462. {
  1463. /* N.B. schar as signed */
  1464. if(*tp > X_SCHAR_MAX || *tp < X_SCHAR_MIN)
  1465. status = NC_ERANGE;
  1466. *xp++ = (schar) *tp++;
  1467. }
  1468. if(rndup)
  1469. {
  1470. (void) memcpy(xp, nada, rndup);
  1471. xp += rndup;
  1472. }
  1473. *xpp = (void *)xp;
  1474. return status;
  1475. }
  1476. int
  1477. ncx_pad_putn_schar_float(void **xpp, size_t nelems, const float *tp)
  1478. {
  1479. int status = ENOERR;
  1480. size_t rndup = nelems % X_ALIGN;
  1481. schar *xp = (schar *)(*xpp);
  1482. if(rndup)
  1483. rndup = X_ALIGN - rndup;
  1484. while(nelems-- != 0)
  1485. {
  1486. /* N.B. schar as signed */
  1487. if(*tp > X_SCHAR_MAX || *tp < X_SCHAR_MIN)
  1488. status = NC_ERANGE;
  1489. *xp++ = (schar) *tp++;
  1490. }
  1491. if(rndup)
  1492. {
  1493. (void) memcpy(xp, nada, rndup);
  1494. xp += rndup;
  1495. }
  1496. *xpp = (void *)xp;
  1497. return status;
  1498. }
  1499. int
  1500. ncx_pad_putn_schar_double(void **xpp, size_t nelems, const double *tp)
  1501. {
  1502. int status = ENOERR;
  1503. size_t rndup = nelems % X_ALIGN;
  1504. schar *xp = (schar *)(*xpp);
  1505. if(rndup)
  1506. rndup = X_ALIGN - rndup;
  1507. while(nelems-- != 0)
  1508. {
  1509. /* N.B. schar as signed */
  1510. if(*tp > X_SCHAR_MAX || *tp < X_SCHAR_MIN)
  1511. status = NC_ERANGE;
  1512. *xp++ = (schar) *tp++;
  1513. }
  1514. if(rndup)
  1515. {
  1516. (void) memcpy(xp, nada, rndup);
  1517. xp += rndup;
  1518. }
  1519. *xpp = (void *)xp;
  1520. return status;
  1521. }
  1522. /* short */
  1523. int
  1524. ncx_getn_short_schar(const void **xpp, size_t nelems, schar *tp)
  1525. {
  1526. const char *xp = *xpp;
  1527. int status = ENOERR;
  1528. for( ; nelems != 0; nelems--, xp += X_SIZEOF_SHORT, tp++)
  1529. {
  1530. const int lstatus = ncx_get_short_schar(xp, tp);
  1531. if(lstatus != ENOERR)
  1532. status = lstatus;
  1533. }
  1534. *xpp = (const void *)xp;
  1535. return status;
  1536. }
  1537. int
  1538. ncx_getn_short_uchar(const void **xpp, size_t nelems, uchar *tp)
  1539. {
  1540. const char *xp = *xpp;
  1541. int status = ENOERR;
  1542. for( ; nelems != 0; nelems--, xp += X_SIZEOF_SHORT, tp++)
  1543. {
  1544. const int lstatus = ncx_get_short_uchar(xp, tp);
  1545. if(lstatus != ENOERR)
  1546. status = lstatus;
  1547. }
  1548. *xpp = (const void *)xp;
  1549. return status;
  1550. }
  1551. #if SHORT_USE_IEG
  1552. int
  1553. ncx_getn_short_short(const void **xpp, size_t nelems, short *tp)
  1554. {
  1555. if(nelems > 0)
  1556. {
  1557. const int bo = bitoff(*xpp);
  1558. const word *wp = *xpp;
  1559. int ierr;
  1560. *xpp = ((const char *) (*xpp) + nelems * X_SIZEOF_SHORT);
  1561. ierr = IEG2CRAY(&Cray2_I16, &nelems, wp,
  1562. &bo, tp, &UnitStride);
  1563. assert(ierr >= 0);
  1564. if(ierr > 0)
  1565. return NC_ERANGE;
  1566. }
  1567. return ENOERR;
  1568. }
  1569. #else
  1570. int
  1571. ncx_getn_short_short(const void **xpp, const size_t nelems, short *tp)
  1572. {
  1573. if(nelems > 0)
  1574. {
  1575. const word *wp = *xpp;
  1576. const short *const last = &tp[nelems -1];
  1577. const int rem = word_align(*xpp)/X_SIZEOF_SHORT;
  1578. *xpp = ((const char *) (*xpp) + nelems * X_SIZEOF_SHORT);
  1579. switch(rem) {
  1580. case 3:
  1581. *tp = (short)((*wp >> 32) & 0xffff);
  1582. if(*tp & 0x8000)
  1583. *tp |= (~(0xffff));
  1584. if(tp == last)
  1585. return ENOERR;
  1586. tp++;
  1587. /*FALLTHRU*/
  1588. case 2:
  1589. *tp = (short)((*wp >> 16) & 0xffff);
  1590. if(*tp & 0x8000)
  1591. *tp |= (~(0xffff));
  1592. if(tp == last)
  1593. return ENOERR;
  1594. tp++;
  1595. /*FALLTHRU*/
  1596. case 1:
  1597. *tp = (short)(*wp & 0xffff);
  1598. if(*tp & 0x8000)
  1599. *tp |= (~(0xffff));
  1600. if(tp == last)
  1601. return ENOERR;
  1602. tp++;
  1603. wp++; /* Note Bene */
  1604. /*FALLTHRU*/
  1605. }
  1606. assert((nelems - rem) != 0);
  1607. {
  1608. const int nwords = ((nelems - rem) * X_SIZEOF_SHORT)
  1609. / sizeof(word);
  1610. const word *const endw = &wp[nwords];
  1611. #pragma _CRI ivdep
  1612. for( ; wp < endw; wp++)
  1613. {
  1614. *tp = (short)(*wp >> 48);
  1615. if(*tp & 0x8000)
  1616. *tp |= (~(0xffff));
  1617. tp++;
  1618. *tp = (short)((*wp >> 32) & 0xffff);
  1619. if(*tp & 0x8000)
  1620. *tp |= (~(0xffff));
  1621. tp++;
  1622. *tp = (short)((*wp >> 16) & 0xffff);
  1623. if(*tp & 0x8000)
  1624. *tp |= (~(0xffff));
  1625. tp++;
  1626. *tp = (short)(*wp & 0xffff);
  1627. if(*tp & 0x8000)
  1628. *tp |= (~(0xffff));
  1629. tp++;
  1630. }
  1631. }
  1632. if(tp <= last)
  1633. {
  1634. *tp = (short)(*wp >> 48);
  1635. if(*tp & 0x8000)
  1636. *tp |= (~(0xffff));
  1637. tp++;
  1638. }
  1639. if(tp <= last)
  1640. {
  1641. *tp = (short)((*wp >> 32) & 0xffff);
  1642. if(*tp & 0x8000)
  1643. *tp |= (~(0xffff));
  1644. tp++;
  1645. }
  1646. if(tp <= last)
  1647. {
  1648. *tp = (short)((*wp >> 16) & 0xffff);
  1649. if(*tp & 0x8000)
  1650. *tp |= (~(0xffff));
  1651. tp++;
  1652. }
  1653. }
  1654. return ENOERR;
  1655. }
  1656. #endif
  1657. int
  1658. ncx_getn_short_int(const void **xpp, size_t nelems, int *tp)
  1659. {
  1660. const char *xp = *xpp;
  1661. int status = ENOERR;
  1662. for( ; nelems != 0; nelems--, xp += X_SIZEOF_SHORT, tp++)
  1663. {
  1664. const int lstatus = ncx_get_short_int(xp, tp);
  1665. if(lstatus != ENOERR)
  1666. status = lstatus;
  1667. }
  1668. *xpp = (const void *)xp;
  1669. return status;
  1670. }
  1671. int
  1672. ncx_getn_short_long(const void **xpp, size_t nelems, long *tp)
  1673. {
  1674. const char *xp = *xpp;
  1675. int status = ENOERR;
  1676. for( ; nelems != 0; nelems--, xp += X_SIZEOF_SHORT, tp++)
  1677. {
  1678. const int lstatus = ncx_get_short_long(xp, tp);
  1679. if(lstatus != ENOERR)
  1680. status = lstatus;
  1681. }
  1682. *xpp = (const void *)xp;
  1683. return status;
  1684. }
  1685. int
  1686. ncx_getn_short_float(const void **xpp, size_t nelems, float *tp)
  1687. {
  1688. const char *xp = *xpp;
  1689. int status = ENOERR;
  1690. for( ; nelems != 0; nelems--, xp += X_SIZEOF_SHORT, tp++)
  1691. {
  1692. const int lstatus = ncx_get_short_float(xp, tp);
  1693. if(lstatus != ENOERR)
  1694. status = lstatus;
  1695. }
  1696. *xpp = (const void *)xp;
  1697. return status;
  1698. }
  1699. int
  1700. ncx_getn_short_double(const void **xpp, size_t nelems, double *tp)
  1701. {
  1702. const char *xp = *xpp;
  1703. int status = ENOERR;
  1704. for( ; nelems != 0; nelems--, xp += X_SIZEOF_SHORT, tp++)
  1705. {
  1706. const int lstatus = ncx_get_short_double(xp, tp);
  1707. if(lstatus != ENOERR)
  1708. status = lstatus;
  1709. }
  1710. *xpp = (const void *)xp;
  1711. return status;
  1712. }
  1713. int
  1714. ncx_pad_getn_short_schar(const void **xpp, size_t nelems, schar *tp)
  1715. {
  1716. const size_t rndup = nelems % 2;
  1717. const char *xp = *xpp;
  1718. int status = ENOERR;
  1719. for( ; nelems != 0; nelems--, xp += X_SIZEOF_SHORT, tp++)
  1720. {
  1721. const int lstatus = ncx_get_short_schar(xp, tp);
  1722. if(lstatus != ENOERR)
  1723. status = lstatus;
  1724. }
  1725. if(rndup != 0)
  1726. xp += X_SIZEOF_SHORT;
  1727. *xpp = (void *)xp;
  1728. return status;
  1729. }
  1730. int
  1731. ncx_pad_getn_short_uchar(const void **xpp, size_t nelems, uchar *tp)
  1732. {
  1733. const size_t rndup = nelems % 2;
  1734. const char *xp = *xpp;
  1735. int status = ENOERR;
  1736. for( ; nelems != 0; nelems--, xp += X_SIZEOF_SHORT, tp++)
  1737. {
  1738. const int lstatus = ncx_get_short_uchar(xp, tp);
  1739. if(lstatus != ENOERR)
  1740. status = lstatus;
  1741. }
  1742. if(rndup != 0)
  1743. xp += X_SIZEOF_SHORT;
  1744. *xpp = (void *)xp;
  1745. return status;
  1746. }
  1747. int
  1748. ncx_pad_getn_short_short(const void **xpp, size_t nelems, short *tp)
  1749. {
  1750. const size_t rndup = nelems % 2;
  1751. const int status = ncx_getn_short_short(xpp, nelems, tp);
  1752. if(rndup != 0)
  1753. {
  1754. *xpp = ((char *) (*xpp) + X_SIZEOF_SHORT);
  1755. }
  1756. return status;
  1757. }
  1758. int
  1759. ncx_pad_getn_short_int(const void **xpp, size_t nelems, int *tp)
  1760. {
  1761. const size_t rndup = nelems % 2;
  1762. const char *xp = *xpp;
  1763. int status = ENOERR;
  1764. for( ; nelems != 0; nelems--, xp += X_SIZEOF_SHORT, tp++)
  1765. {
  1766. const int lstatus = ncx_get_short_int(xp, tp);
  1767. if(lstatus != ENOERR)
  1768. status = lstatus;
  1769. }
  1770. if(rndup != 0)
  1771. xp += X_SIZEOF_SHORT;
  1772. *xpp = (void *)xp;
  1773. return status;
  1774. }
  1775. int
  1776. ncx_pad_getn_short_long(const void **xpp, size_t nelems, long *tp)
  1777. {
  1778. const size_t rndup = nelems % 2;
  1779. const char *xp = *xpp;
  1780. int status = ENOERR;
  1781. for( ; nelems != 0; nelems--, xp += X_SIZEOF_SHORT, tp++)
  1782. {
  1783. const int lstatus = ncx_get_short_long(xp, tp);
  1784. if(lstatus != ENOERR)
  1785. status = lstatus;
  1786. }
  1787. if(rndup != 0)
  1788. xp += X_SIZEOF_SHORT;
  1789. *xpp = (void *)xp;
  1790. return status;
  1791. }
  1792. int
  1793. ncx_pad_getn_short_float(const void **xpp, size_t nelems, float *tp)
  1794. {
  1795. const size_t rndup = nelems % 2;
  1796. const char *xp = *xpp;
  1797. int status = ENOERR;
  1798. for( ; nelems != 0; nelems--, xp += X_SIZEOF_SHORT, tp++)
  1799. {
  1800. const int lstatus = ncx_get_short_float(xp, tp);
  1801. if(lstatus != ENOERR)
  1802. status = lstatus;
  1803. }
  1804. if(rndup != 0)
  1805. xp += X_SIZEOF_SHORT;
  1806. *xpp = (void *)xp;
  1807. return status;
  1808. }
  1809. int
  1810. ncx_pad_getn_short_double(const void **xpp, size_t nelems, double *tp)
  1811. {
  1812. const size_t rndup = nelems % 2;
  1813. const char *xp = *xpp;
  1814. int status = ENOERR;
  1815. for( ; nelems != 0; nelems--, xp += X_SIZEOF_SHORT, tp++)
  1816. {
  1817. const int lstatus = ncx_get_short_double(xp, tp);
  1818. if(lstatus != ENOERR)
  1819. status = lstatus;
  1820. }
  1821. if(rndup != 0)
  1822. xp += X_SIZEOF_SHORT;
  1823. *xpp = (void *)xp;
  1824. return status;
  1825. }
  1826. int
  1827. ncx_putn_short_schar(void **xpp, size_t nelems, const schar *tp)
  1828. {
  1829. char *xp = *xpp;
  1830. int status = ENOERR;
  1831. for( ; nelems != 0; nelems--, xp += X_SIZEOF_SHORT, tp++)
  1832. {
  1833. const int lstatus = ncx_put_short_schar(xp, tp);
  1834. if(lstatus != ENOERR)
  1835. status = lstatus;
  1836. }
  1837. *xpp = (void *)xp;
  1838. return status;
  1839. }
  1840. int
  1841. ncx_putn_short_uchar(void **xpp, size_t nelems, const uchar *tp)
  1842. {
  1843. char *xp = *xpp;
  1844. int status = ENOERR;
  1845. for( ; nelems != 0; nelems--, xp += X_SIZEOF_SHORT, tp++)
  1846. {
  1847. const int lstatus = ncx_put_short_uchar(xp, tp);
  1848. if(lstatus != ENOERR)
  1849. status = lstatus;
  1850. }
  1851. *xpp = (void *)xp;
  1852. return status;
  1853. }
  1854. #if SHORT_USE_IEG
  1855. int
  1856. ncx_putn_short_short(void **xpp, size_t nelems, const short *tp)
  1857. {
  1858. if(nelems > 0)
  1859. {
  1860. word *wp = *xpp;
  1861. const int bo = bitoff(*xpp);
  1862. int ierr;
  1863. *xpp = ((char *) (*xpp) + nelems * X_SIZEOF_SHORT);
  1864. ierr = CRAY2IEG(&Cray2_I16, &nelems, wp,
  1865. &bo, tp, &UnitStride);
  1866. assert(ierr >= 0);
  1867. if(ierr > 0)
  1868. return NC_ERANGE;
  1869. }
  1870. return ENOERR;
  1871. }
  1872. #else
  1873. int
  1874. ncx_putn_short_short(void **xpp, const size_t nelems, const short *tp)
  1875. {
  1876. int status = ENOERR;
  1877. if(nelems == 0)
  1878. return status;
  1879. {
  1880. word *wp = *xpp;
  1881. const short *const last = &tp[nelems -1];
  1882. const int rem = word_align(*xpp)/X_SIZEOF_SHORT;
  1883. *xpp = ((char *) (*xpp) + nelems * X_SIZEOF_SHORT);
  1884. switch(rem) {
  1885. case 3:
  1886. *wp = ((*tp << 32) & 0x0000ffff00000000)
  1887. | (*wp & 0xffff0000ffffffff);
  1888. if(*tp > X_SHORT_MAX || *tp < X_SHORT_MIN)
  1889. status = NC_ERANGE;
  1890. if(tp == last)
  1891. return status;
  1892. tp++;
  1893. /*FALLTHRU*/
  1894. case 2:
  1895. *wp = ((*tp << 16) & 0x00000000ffff0000)
  1896. | (*wp & 0xffffffff0000ffff);
  1897. if(*tp > X_SHORT_MAX || *tp < X_SHORT_MIN)
  1898. status = NC_ERANGE;
  1899. if(tp == last)
  1900. return status;
  1901. tp++;
  1902. /*FALLTHRU*/
  1903. case 1:
  1904. *wp = (*tp & 0x000000000000ffff)
  1905. | (*wp & 0xffffffffffff0000);
  1906. if(*tp > X_SHORT_MAX || *tp < X_SHORT_MIN)
  1907. status = NC_ERANGE;
  1908. if(tp == last)
  1909. return status;
  1910. tp++;
  1911. wp++; /* Note Bene */
  1912. /*FALLTHRU*/
  1913. }
  1914. assert((nelems - rem) != 0);
  1915. {
  1916. const int nwords = ((nelems - rem) * X_SIZEOF_SHORT)
  1917. / sizeof(word);
  1918. const word *const endw = &wp[nwords];
  1919. #pragma _CRI ivdep
  1920. for( ; wp < endw; wp++)
  1921. {
  1922. *wp = (*tp << 48)
  1923. | ((*(tp +1) << 32) & 0x0000ffff00000000)
  1924. | ((*(tp +2) << 16) & 0x00000000ffff0000)
  1925. | ((*(tp +3) ) & 0x000000000000ffff);
  1926. { int ii = 0;
  1927. for(; ii < 4; ii++, tp++)
  1928. if(*tp > X_SHORT_MAX || *tp < X_SHORT_MIN)
  1929. status = NC_ERANGE;
  1930. }
  1931. }
  1932. }
  1933. if(tp <= last)
  1934. {
  1935. *wp = (*tp << 48)
  1936. | (*wp & 0x0000ffffffffffff);
  1937. if(*tp > X_SHORT_MAX || *tp < X_SHORT_MIN)
  1938. status = NC_ERANGE;
  1939. tp++;
  1940. }
  1941. if(tp <= last)
  1942. {
  1943. *wp = ((*tp << 32) & 0x0000ffff00000000)
  1944. | (*wp & 0xffff0000ffffffff);
  1945. if(*tp > X_SHORT_MAX || *tp < X_SHORT_MIN)
  1946. status = NC_ERANGE;
  1947. tp++;
  1948. }
  1949. if(tp <= last)
  1950. {
  1951. *wp = ((*tp << 16) & 0x00000000ffff0000)
  1952. | (*wp & 0xffffffff0000ffff);
  1953. if(*tp > X_SHORT_MAX || *tp < X_SHORT_MIN)
  1954. status = NC_ERANGE;
  1955. }
  1956. return status;
  1957. }
  1958. }
  1959. #endif
  1960. int
  1961. ncx_putn_short_int(void **xpp, size_t nelems, const int *tp)
  1962. {
  1963. char *xp = *xpp;
  1964. int status = ENOERR;
  1965. for( ; nelems != 0; nelems--, xp += X_SIZEOF_SHORT, tp++)
  1966. {
  1967. const int lstatus = ncx_put_short_int(xp, tp);
  1968. if(lstatus != ENOERR)
  1969. status = lstatus;
  1970. }
  1971. *xpp = (void *)xp;
  1972. return status;
  1973. }
  1974. int
  1975. ncx_putn_short_long(void **xpp, size_t nelems, const long *tp)
  1976. {
  1977. char *xp = *xpp;
  1978. int status = ENOERR;
  1979. for( ; nelems != 0; nelems--, xp += X_SIZEOF_SHORT, tp++)
  1980. {
  1981. const int lstatus = ncx_put_short_long(xp, tp);
  1982. if(lstatus != ENOERR)
  1983. status = lstatus;
  1984. }
  1985. *xpp = (void *)xp;
  1986. return status;
  1987. }
  1988. int
  1989. ncx_putn_short_float(void **xpp, size_t nelems, const float *tp)
  1990. {
  1991. char *xp = *xpp;
  1992. int status = ENOERR;
  1993. for( ; nelems != 0; nelems--, xp += X_SIZEOF_SHORT, tp++)
  1994. {
  1995. const int lstatus = ncx_put_short_float(xp, tp);
  1996. if(lstatus != ENOERR)
  1997. status = lstatus;
  1998. }
  1999. *xpp = (void *)xp;
  2000. return status;
  2001. }
  2002. int
  2003. ncx_putn_short_double(void **xpp, size_t nelems, const double *tp)
  2004. {
  2005. char *xp = *xpp;
  2006. int status = ENOERR;
  2007. for( ; nelems != 0; nelems--, xp += X_SIZEOF_SHORT, tp++)
  2008. {
  2009. const int lstatus = ncx_put_short_double(xp, tp);
  2010. if(lstatus != ENOERR)
  2011. status = lstatus;
  2012. }
  2013. *xpp = (void *)xp;
  2014. return status;
  2015. }
  2016. int
  2017. ncx_pad_putn_short_schar(void **xpp, size_t nelems, const schar *tp)
  2018. {
  2019. const size_t rndup = nelems % 2;
  2020. char *xp = *xpp;
  2021. int status = ENOERR;
  2022. for( ; nelems != 0; nelems--, xp += X_SIZEOF_SHORT, tp++)
  2023. {
  2024. const int lstatus = ncx_put_short_schar(xp, tp);
  2025. if(lstatus != ENOERR)
  2026. status = lstatus;
  2027. }
  2028. if(rndup != 0)
  2029. {
  2030. (void) memcpy(xp, nada, X_SIZEOF_SHORT);
  2031. xp += X_SIZEOF_SHORT;
  2032. }
  2033. *xpp = (void *)xp;
  2034. return status;
  2035. }
  2036. int
  2037. ncx_pad_putn_short_uchar(void **xpp, size_t nelems, const uchar *tp)
  2038. {
  2039. const size_t rndup = nelems % 2;
  2040. char *xp = *xpp;
  2041. int status = ENOERR;
  2042. for( ; nelems != 0; nelems--, xp += X_SIZEOF_SHORT, tp++)
  2043. {
  2044. const int lstatus = ncx_put_short_uchar(xp, tp);
  2045. if(lstatus != ENOERR)
  2046. status = lstatus;
  2047. }
  2048. if(rndup != 0)
  2049. {
  2050. (void) memcpy(xp, nada, X_SIZEOF_SHORT);
  2051. xp += X_SIZEOF_SHORT;
  2052. }
  2053. *xpp = (void *)xp;
  2054. return status;
  2055. }
  2056. int
  2057. ncx_pad_putn_short_short(void **xpp, size_t nelems, const short *tp)
  2058. {
  2059. const size_t rndup = nelems % 2;
  2060. const int status = ncx_putn_short_short(xpp, nelems, tp);
  2061. if(rndup != 0)
  2062. {
  2063. *xpp = ((char *) (*xpp) + X_SIZEOF_SHORT);
  2064. }
  2065. return status;
  2066. }
  2067. int
  2068. ncx_pad_putn_short_int(void **xpp, size_t nelems, const int *tp)
  2069. {
  2070. const size_t rndup = nelems % 2;
  2071. char *xp = *xpp;
  2072. int status = ENOERR;
  2073. for( ; nelems != 0; nelems--, xp += X_SIZEOF_SHORT, tp++)
  2074. {
  2075. const int lstatus = ncx_put_short_int(xp, tp);
  2076. if(lstatus != ENOERR)
  2077. status = lstatus;
  2078. }
  2079. if(rndup != 0)
  2080. {
  2081. (void) memcpy(xp, nada, X_SIZEOF_SHORT);
  2082. xp += X_SIZEOF_SHORT;
  2083. }
  2084. *xpp = (void *)xp;
  2085. return status;
  2086. }
  2087. int
  2088. ncx_pad_putn_short_long(void **xpp, size_t nelems, const long *tp)
  2089. {
  2090. const size_t rndup = nelems % 2;
  2091. char *xp = *xpp;
  2092. int status = ENOERR;
  2093. for( ; nelems != 0; nelems--, xp += X_SIZEOF_SHORT, tp++)
  2094. {
  2095. const int lstatus = ncx_put_short_long(xp, tp);
  2096. if(lstatus != ENOERR)
  2097. status = lstatus;
  2098. }
  2099. if(rndup != 0)
  2100. {
  2101. (void) memcpy(xp, nada, X_SIZEOF_SHORT);
  2102. xp += X_SIZEOF_SHORT;
  2103. }
  2104. *xpp = (void *)xp;
  2105. return status;
  2106. }
  2107. int
  2108. ncx_pad_putn_short_float(void **xpp, size_t nelems, const float *tp)
  2109. {
  2110. const size_t rndup = nelems % 2;
  2111. char *xp = *xpp;
  2112. int status = ENOERR;
  2113. for( ; nelems != 0; nelems--, xp += X_SIZEOF_SHORT, tp++)
  2114. {
  2115. const int lstatus = ncx_put_short_float(xp, tp);
  2116. if(lstatus != ENOERR)
  2117. status = lstatus;
  2118. }
  2119. if(rndup != 0)
  2120. {
  2121. (void) memcpy(xp, nada, X_SIZEOF_SHORT);
  2122. xp += X_SIZEOF_SHORT;
  2123. }
  2124. *xpp = (void *)xp;
  2125. return status;
  2126. }
  2127. int
  2128. ncx_pad_putn_short_double(void **xpp, size_t nelems, const double *tp)
  2129. {
  2130. const size_t rndup = nelems % 2;
  2131. char *xp = *xpp;
  2132. int status = ENOERR;
  2133. for( ; nelems != 0; nelems--, xp += X_SIZEOF_SHORT, tp++)
  2134. {
  2135. const int lstatus = ncx_put_short_double(xp, tp);
  2136. if(lstatus != ENOERR)
  2137. status = lstatus;
  2138. }
  2139. if(rndup != 0)
  2140. {
  2141. (void) memcpy(xp, nada, X_SIZEOF_SHORT);
  2142. xp += X_SIZEOF_SHORT;
  2143. }
  2144. *xpp = (void *)xp;
  2145. return status;
  2146. }
  2147. /* int */
  2148. int
  2149. ncx_getn_int_schar(const void **xpp, size_t nelems, schar *tp)
  2150. {
  2151. const char *xp = *xpp;
  2152. int status = ENOERR;
  2153. for( ; nelems != 0; nelems--, xp += X_SIZEOF_INT, tp++)
  2154. {
  2155. const int lstatus = ncx_get_int_schar(xp, tp);
  2156. if(lstatus != ENOERR)
  2157. status = lstatus;
  2158. }
  2159. *xpp = (const void *)xp;
  2160. return status;
  2161. }
  2162. int
  2163. ncx_getn_int_uchar(const void **xpp, size_t nelems, uchar *tp)
  2164. {
  2165. const char *xp = *xpp;
  2166. int status = ENOERR;
  2167. for( ; nelems != 0; nelems--, xp += X_SIZEOF_INT, tp++)
  2168. {
  2169. const int lstatus = ncx_get_int_uchar(xp, tp);
  2170. if(lstatus != ENOERR)
  2171. status = lstatus;
  2172. }
  2173. *xpp = (const void *)xp;
  2174. return status;
  2175. }
  2176. int
  2177. ncx_getn_int_short(const void **xpp, size_t nelems, short *tp)
  2178. {
  2179. const char *xp = *xpp;
  2180. int status = ENOERR;
  2181. for( ; nelems != 0; nelems--, xp += X_SIZEOF_INT, tp++)
  2182. {
  2183. const int lstatus = ncx_get_int_short(xp, tp);
  2184. if(lstatus != ENOERR)
  2185. status = lstatus;
  2186. }
  2187. *xpp = (const void *)xp;
  2188. return status;
  2189. }
  2190. #if INT_USE_IEG
  2191. int
  2192. ncx_getn_int_int(const void **xpp, size_t nelems, int *tp)
  2193. {
  2194. if(nelems > 0)
  2195. {
  2196. const int bo = bitoff(*xpp);
  2197. const word *wp = *xpp;
  2198. int ierr;
  2199. *xpp = ((const char *) (*xpp) + nelems * X_SIZEOF_INT);
  2200. ierr = IEG2CRAY(&Cray2_I32, &nelems, wp,
  2201. &bo, tp, &UnitStride);
  2202. assert(ierr >= 0);
  2203. if(ierr > 0)
  2204. return NC_ERANGE;
  2205. }
  2206. return ENOERR;
  2207. }
  2208. #else
  2209. int
  2210. ncx_getn_int_int(const void **xpp, size_t nelems, int *tp)
  2211. {
  2212. const int bo = byteoff(*xpp);
  2213. if(nelems == 0)
  2214. return ENOERR;
  2215. if(bo != 0)
  2216. {
  2217. cget_int_int(*xpp, tp, bo);
  2218. *xpp = ((char *) (*xpp) + X_SIZEOF_INT);
  2219. nelems--;
  2220. if(nelems == 0)
  2221. return ENOERR;
  2222. tp++;
  2223. }
  2224. assert(byteoff(*xpp) == 0);
  2225. {
  2226. const int nwords = (nelems * X_SIZEOF_INT)/sizeof(word);
  2227. const word *wp = *xpp;
  2228. const word *const end = &wp[nwords];
  2229. #pragma _CRI ivdep
  2230. for( ; wp < end; wp++, tp += 2)
  2231. {
  2232. cget_int_int(wp, tp, 0);
  2233. cget_int_int(wp, tp + 1, 1);
  2234. }
  2235. *xpp = ((char *) (*xpp) + nwords * sizeof(word));
  2236. nelems -= (nwords * sizeof(word)/X_SIZEOF_INT);
  2237. if(nelems != 0)
  2238. {
  2239. cget_int_int(wp, tp, 0);
  2240. *xpp = ((char *) (*xpp) + X_SIZEOF_INT);
  2241. }
  2242. }
  2243. return ENOERR;
  2244. }
  2245. #endif
  2246. int
  2247. ncx_getn_int_long(const void **xpp, size_t nelems, long *tp)
  2248. {
  2249. const int bo = byteoff(*xpp);
  2250. if(nelems == 0)
  2251. return ENOERR;
  2252. if(bo != 0)
  2253. {
  2254. cget_int_long(*xpp, tp, bo);
  2255. *xpp = ((char *) (*xpp) + X_SIZEOF_INT);
  2256. nelems--;
  2257. if(nelems == 0)
  2258. return ENOERR;
  2259. tp++;
  2260. }
  2261. assert(byteoff(*xpp) == 0);
  2262. {
  2263. const int nwords = (nelems * X_SIZEOF_INT)/sizeof(word);
  2264. const word *wp = *xpp;
  2265. const word *const end = &wp[nwords];
  2266. #pragma _CRI ivdep
  2267. for( ; wp < end; wp++, tp += 2)
  2268. {
  2269. cget_int_long(wp, tp, 0);
  2270. cget_int_long(wp, tp + 1, 1);
  2271. }
  2272. *xpp = ((char *) (*xpp) + nwords * sizeof(word));
  2273. nelems -= (nwords * sizeof(word)/X_SIZEOF_INT);
  2274. if(nelems != 0)
  2275. {
  2276. cget_int_long(wp, tp, 0);
  2277. *xpp = ((char *) (*xpp) + X_SIZEOF_INT);
  2278. }
  2279. }
  2280. return ENOERR;
  2281. }
  2282. int
  2283. ncx_getn_int_float(const void **xpp, size_t nelems, float *tp)
  2284. {
  2285. const char *xp = *xpp;
  2286. int status = ENOERR;
  2287. for( ; nelems != 0; nelems--, xp += X_SIZEOF_INT, tp++)
  2288. {
  2289. const int lstatus = ncx_get_int_float(xp, tp);
  2290. if(lstatus != ENOERR)
  2291. status = lstatus;
  2292. }
  2293. *xpp = (const void *)xp;
  2294. return status;
  2295. }
  2296. int
  2297. ncx_getn_int_double(const void **xpp, size_t nelems, double *tp)
  2298. {
  2299. const char *xp = *xpp;
  2300. int status = ENOERR;
  2301. for( ; nelems != 0; nelems--, xp += X_SIZEOF_INT, tp++)
  2302. {
  2303. const int lstatus = ncx_get_int_double(xp, tp);
  2304. if(lstatus != ENOERR)
  2305. status = lstatus;
  2306. }
  2307. *xpp = (const void *)xp;
  2308. return status;
  2309. }
  2310. int
  2311. ncx_putn_int_schar(void **xpp, size_t nelems, const schar *tp)
  2312. {
  2313. char *xp = *xpp;
  2314. int status = ENOERR;
  2315. for( ; nelems != 0; nelems--, xp += X_SIZEOF_INT, tp++)
  2316. {
  2317. const int lstatus = ncx_put_int_schar(xp, tp);
  2318. if(lstatus != ENOERR)
  2319. status = lstatus;
  2320. }
  2321. *xpp = (void *)xp;
  2322. return status;
  2323. }
  2324. int
  2325. ncx_putn_int_uchar(void **xpp, size_t nelems, const uchar *tp)
  2326. {
  2327. char *xp = *xpp;
  2328. int status = ENOERR;
  2329. for( ; nelems != 0; nelems--, xp += X_SIZEOF_INT, tp++)
  2330. {
  2331. const int lstatus = ncx_put_int_uchar(xp, tp);
  2332. if(lstatus != ENOERR)
  2333. status = lstatus;
  2334. }
  2335. *xpp = (void *)xp;
  2336. return status;
  2337. }
  2338. int
  2339. ncx_putn_int_short(void **xpp, size_t nelems, const short *tp)
  2340. {
  2341. char *xp = *xpp;
  2342. int status = ENOERR;
  2343. for( ; nelems != 0; nelems--, xp += X_SIZEOF_INT, tp++)
  2344. {
  2345. const int lstatus = ncx_put_int_short

Large files files are truncated, but you can click here to view the full file