home *** CD-ROM | disk | FTP | other *** search
/ Photo CD Demo 1 / Demo.bin / hdf / unix / hdf3_2r2 / src / dfconv.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-10-29  |  91.3 KB  |  2,983 lines

  1. /***************************************************************************
  2. *
  3. *
  4. *                         NCSA HDF version 3.2r2
  5. *                            October 30, 1992
  6. *
  7. * NCSA HDF Version 3.2 source code and documentation are in the public
  8. * domain.  Specifically, we give to the public domain all rights for future
  9. * licensing of the source code, all resale rights, and all publishing rights.
  10. *
  11. * We ask, but do not require, that the following message be included in all
  12. * derived works:
  13. *
  14. * Portions developed at the National Center for Supercomputing Applications at
  15. * the University of Illinois at Urbana-Champaign, in collaboration with the
  16. * Information Technology Institute of Singapore.
  17. *
  18. * THE UNIVERSITY OF ILLINOIS GIVES NO WARRANTY, EXPRESSED OR IMPLIED, FOR THE
  19. * SOFTWARE AND/OR DOCUMENTATION PROVIDED, INCLUDING, WITHOUT LIMITATION,
  20. * WARRANTY OF MERCHANTABILITY AND WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE
  21. *
  22. ****************************************************************************
  23. */
  24.  
  25. #ifdef RCSID
  26. static char RcsId[] = "@(#)$Revision: 1.2 $";
  27. #endif
  28. /*
  29. $Header: /hdf/hdf/v3.2r2/src/RCS/dfconv.c,v 1.2 1992/10/12 18:11:51 koziol beta koziol $
  30.  
  31. $Log: dfconv.c,v $
  32.  * Revision 1.2  1992/10/12  18:11:51  koziol
  33.  * Updated for v3.2r2 release
  34.  *
  35.  * Revision 1.1  1992/08/25  21:40:44  koziol
  36.  * Initial revision
  37.  *
  38. */
  39. /************************************************************************/
  40. /* DFCONV.C                                                             */
  41. /************************************************************************/
  42.  
  43. /*------------------------------------------------------------------
  44.  File:  dfconv.c
  45.  
  46.  Purpose:
  47.     Routines to support conversion to and from HDF format
  48.  
  49.  Invokes:
  50.     
  51.  PRIVATE conversion functions:
  52.     DFKnb1b - -  Native mode for 8 bit integers
  53.     DFKnb2b -  Native mode for 16 bit integers
  54.     DFKnb4b -  Native mode for 32 bit integers and floats 
  55.     DFKnb8b -  Native mode for 64 bit floats 
  56.     DFKsb2b -  Byte swapping for 16 bit integers
  57.     DFKsb4b -  Byte swapping for 32 bit integers
  58.     DFKsb8b -  Byte swapping for 64 bit floats 
  59.     DFKui2i -  Unicos routine for importing 16 bit unsigned integers
  60.     DFKui2s -  Unicos routine for importing 16 bit signed integers
  61.     DFKuo2i -  Unicos routine for exporting 16 bit integers
  62.     DFKui4i -  Unicos routine for importing unsigned 32bit integers
  63.     DFKui4s -  Unicos routine for importing signed 32bit integers
  64.     DFKuo4i -  Unicos routine for exporting 4 byte integers (both)
  65.     DFKui4f -  Unicos routine for importing 32 bit floats   
  66.     DFKuo4f -  Unicos routine for exporting 32 bit floats  
  67.     DFKui8f -  Unicos routine for importing 64 bit floats 
  68.     DFKuo64f - Unicos routine for exporting 64 bit floats
  69.     DFKvi4f -  VMS routine for importing 32 bit floats
  70.     DFKvo4f -  VMS routine for exporting 32 bit floats
  71.     DFKvi8f -  VMS routine for importing 64 bit floats
  72.     DFKvo8f -  VMS routine for exporting 64 bit floats
  73.  
  74.  Other PUBLIC functions:
  75.     DFKmachineNTsize - Determine size in machine, given number type
  76.     DFKhdfNTsize     - Determine size in HDF format, given number type
  77.     DFKsetNT         - Set number type for future conversion calls
  78.     DFKsetcustom    - Template for user to setup custom conversion 
  79.                       routines
  80.     DFKisnative     - Checks whether number type is native mode
  81.     DFconvert       - provide compatibility with 3.0 routines
  82.  
  83.  Private functions:
  84.     DFKInoset    - Indicate that DFKsetNT hasn't been called
  85.  
  86.  Remarks:
  87.  
  88.  *------------------------------------------------------------------*/
  89.  
  90. #if defined(__STDC__) && !defined(PROTOTYPE)
  91. #define PROTOTYPE
  92. #endif /* Assert prototype defined */
  93.  
  94. /*****************************************************************************/
  95. /*                                                                           */
  96. /*    All the routines in this file marked as PRIVATE have been marked so    */
  97. /*  for a reason.  *ANY* of these routines may or may nor be supported in    */
  98. /*  the next version of HDF (4.00).  Furthurmore, the names, paramters, or   */
  99. /*  functionality is *NOT* guaranteed to remain the same.                    */
  100. /*    The *ONLY* guarantee possible is that DFKnumin(), and DFKnumout()      */
  101. /*  will not change.  They are *NOT* guaranteed to be implemented in the     */
  102. /*  next version of HDF as function pointers.  They are guaranteed to take   */
  103. /*  the same arguments and produce the same results.                         */
  104. /*    If your programs call any routines in this file except for             */
  105. /*  DFKnumin(), DFKnumout, and/or DFKsetntype(), your code may not work      */
  106. /*  with future versions of HDF and your code will *NOT* be portable.        */
  107. /*                                                                           */
  108. /*****************************************************************************/
  109.  
  110.  
  111. #include <ctype.h>
  112. #define DFKMASTER  /* Define this for the prototypes for DFKnumin/out */
  113. #include "hdf.h"
  114. #include "herr.h"
  115.  
  116. /*****************************************************************************/
  117. /* CONSTANT DEFINITIONS                                                      */
  118. /* These will eventually be incorporated into dfi.h                          */
  119. /*****************************************************************************/
  120. #if !defined(VMS) && !defined(PC) && !defined(MIPSEL) && !defined(CONVEXNATIVE)
  121. #     if !defined(UNICOS)
  122. #          define UI8_IN     DFKnb1b    /* Unsigned Integer, 8 bits */
  123. #          define UI8_OUT    DFKnb1b
  124. #          define SI16_IN    DFKnb2b    /* S = Signed */
  125. #          define SI16_OUT   DFKnb2b  
  126. #          define UI16_IN    DFKnb2b
  127. #          define UI16_OUT   DFKnb2b
  128. #          define SI32_IN    DFKnb4b
  129. #          define SI32_OUT   DFKnb4b
  130. #          define UI32_IN    DFKnb4b
  131. #          define UI32_OUT   DFKnb4b
  132. #          define F32_IN     DFKnb4b    /* Float, 32 bits */
  133. #          define F32_OUT    DFKnb4b
  134. #          define F64_IN     DFKnb8b
  135. #          define F64_OUT    DFKnb8b
  136. #          define NUI8_IN    DFKnb1b    /* Native Unsigned Integer, 8 bits */
  137. #          define NUI8_OUT   DFKnb1b
  138. #          define NSI16_IN   DFKnb2b
  139. #          define NSI16_OUT  DFKnb2b
  140. #          define NUI16_IN   DFKnb2b
  141. #          define NUI16_OUT  DFKnb2b
  142. #          define NSI32_IN   DFKnb4b
  143. #          define NSI32_OUT  DFKnb4b
  144. #          define NUI32_IN   DFKnb4b
  145. #          define NUI32_OUT  DFKnb4b
  146. #          define NF32_IN    DFKnb4b
  147. #          define NF32_OUT   DFKnb4b
  148. #          define NF64_IN    DFKnb8b
  149. #          define NF64_OUT   DFKnb8b
  150. #     else
  151. #          define UI8_IN     DFKnb1b
  152. #          define UI8_OUT    DFKnb1b
  153. #          define SI16_IN    DFKui2s
  154. #          define SI16_OUT   DFKuo2i
  155. #          define UI16_IN    DFKui2i
  156. #          define UI16_OUT   DFKuo2i
  157. #          define SI32_IN    DFKui4s
  158. #          define SI32_OUT   DFKuo4i
  159. #          define UI32_IN    DFKui4i
  160. #          define UI32_OUT   DFKuo4i
  161. #          define F32_IN     DFKui4f
  162. #          define F32_OUT    DFKuo4f
  163. #          define F64_IN     DFKui8f
  164. #          define F64_OUT    DFKuo8f
  165. #          define NUI8_IN    DFKnb1b
  166. #          define NUI8_OUT   DFKnb1b
  167. #          define NSI16_OUT  DFKnb8b
  168. #          define NSI16_IN   DFKnb8b
  169. #          define NUI16_IN   DFKnb8b
  170. #          define NUI16_OUT  DFKnb8b
  171. #          define NSI32_IN   DFKnb8b
  172. #          define NSI32_OUT  DFKnb8b
  173. #          define NUI32_IN   DFKnb8b
  174. #          define NUI32_OUT  DFKnb8b
  175. #          define NF32_IN    DFKnb8b
  176. #          define NF32_OUT   DFKnb8b
  177. #          define NF64_IN    DFKnb8b
  178. #          define NF64_OUT   DFKnb8b
  179. #     endif /* !UNICOS */
  180. #else   /*  must be VMS || PC || MIPSEL || CONVEXNAVTIVE */
  181. #     define UI8_IN     DFKnb1b
  182. #     define UI8_OUT    DFKnb1b
  183. #  if !defined(CONVEXNATIVE)
  184. #     define SI16_IN    DFKsb2b  /* The s in DFKsb2b is for swap */
  185. #     define SI16_OUT   DFKsb2b
  186. #     define UI16_IN    DFKsb2b
  187. #     define UI16_OUT   DFKsb2b
  188. #     define SI32_IN    DFKsb4b
  189. #     define SI32_OUT   DFKsb4b
  190. #     define UI32_IN    DFKsb4b
  191. #     define UI32_OUT   DFKsb4b
  192. #     if defined(VMS)
  193. #          define F32_IN     DFKvi4f
  194. #          define F32_OUT    DFKvo4f
  195. #          define F64_IN     DFKvi8f
  196. #          define F64_OUT    DFKvo8f
  197. #     else  /* !VMS */
  198. #          define F32_IN     DFKsb4b
  199. #          define F32_OUT    DFKsb4b
  200. #          define F64_IN     DFKsb8b
  201. #          define F64_OUT    DFKsb8b
  202. #     endif /* VMS */
  203. #  else /* CONVEXNATIVE */
  204. #     define SI16_IN    DFKnb2b
  205. #     define SI16_OUT   DFKnb2b
  206. #     define UI16_IN    DFKnb2b
  207. #     define UI16_OUT   DFKnb2b
  208. #     define SI32_IN    DFKnb4b
  209. #     define SI32_OUT   DFKnb4b
  210. #     define UI32_IN    DFKnb4b
  211. #     define UI32_OUT   DFKnb4b
  212. #     define F32_IN     DFKci4f    /* CONVEX stuff */
  213. #     define F32_OUT    DFKco4f
  214. #     define F64_IN     DFKci8f
  215. #     define F64_OUT    DFKco8f
  216. #  endif /* !CONVEXNATIVE */
  217. #     define NUI8_IN    DFKnb1b
  218. #     define NUI8_OUT   DFKnb1b
  219. #     define NSI16_IN   DFKnb2b
  220. #     define NSI16_OUT  DFKnb2b
  221. #     define NUI16_IN   DFKnb2b
  222. #     define NUI16_OUT  DFKnb2b
  223. #     define NSI32_IN   DFKnb4b
  224. #     define NSI32_OUT  DFKnb4b
  225. #     define NUI32_IN   DFKnb4b
  226. #     define NUI32_OUT  DFKnb4b
  227. #     define NF32_IN    DFKnb4b
  228. #     define NF32_OUT   DFKnb4b
  229. #     define NF64_IN    DFKnb8b
  230. #     define NF64_OUT   DFKnb8b
  231. #     define BYTE_SWAPPER
  232. #endif /* !VMS && !PC && !MIPSEL && !CONVEXNATIVE */
  233.  
  234.  
  235. /*****************************************************************************/
  236. /* STRUCTURE DEFINTIONS                                                      */
  237. /*****************************************************************************/
  238. union fpx
  239. {
  240.      float f;
  241.      long  l;
  242. };
  243.  
  244. union float_uint_uchar {
  245.     float32 f;
  246.     int32 i;
  247.     unsigned char c[4];
  248. };
  249.  
  250. /*
  251. **  Static function prototypes
  252. */
  253. static int DFKInoset
  254.     PROTO((VOIDP source, VOIDP dest, uint32 num_elm,uint32 source_stride,
  255.             uint32 dest_stride));
  256.  
  257. /*
  258. **  Conversion Routine Pointer Definitions
  259. */
  260. int (*DFKnumin)
  261.         PROTO((VOIDP source, VOIDP dest, uint32 num_elm,
  262.                 uint32 source_stride, uint32 dest_stride)) = DFKInoset;
  263. int (*DFKnumout)
  264.         PROTO((VOIDP source, VOIDP dest, uint32 num_elm,
  265.                 uint32 source_stride, uint32 dest_stride)) = DFKInoset;
  266.  
  267. /*****************************************************************************/
  268. /* NATIVE MODE NUMBER "CONVERSION" ROUTINES                                  */
  269. /*****************************************************************************/
  270.  
  271. /************************************************************/
  272. /* DFKnb1b()                                                */
  273. /*   Native mode for 1 byte data items                      */
  274. /************************************************************/
  275. #ifdef PROTOTYPE
  276. PRIVATE int DFKnb1b(VOIDP s, VOIDP d, uint32 num_elm, uint32 source_stride,
  277.            uint32 dest_stride)
  278. #else
  279. PRIVATE int DFKnb1b(s, d, num_elm, source_stride, dest_stride)
  280. VOIDP s, d;
  281. uint32 num_elm, source_stride, dest_stride;
  282. #endif /* PROTOTYPE */
  283. {
  284.   int fast_processing = 0;
  285.   int in_place = 0;
  286.   register uint32 i;
  287.   uint8 * source = (uint8*)s;
  288.   uint8 * dest = (uint8*)d;
  289.   char *FUNC="DFKnb1b";
  290.  
  291.   HEclear();
  292.  
  293.   if(num_elm == 0){
  294.     HERROR(DFE_BADCONV);
  295.     return FAIL;
  296.   }
  297.  
  298.   /* Determine if faster array processing is appropriate */
  299.   if((source_stride == 0 && dest_stride == 0) ||
  300.      (source_stride == 1 && dest_stride == 1))
  301.     fast_processing = 1;
  302.  
  303.   /* Determine if the conversion should be inplace */
  304.   if(source == dest)
  305.     in_place = 1;
  306.  
  307.   if(fast_processing) {
  308.     if(!in_place) {
  309.       DFmovmem(source, dest, num_elm);
  310.       return 0;
  311.     }
  312.     else
  313.       return 0;                         /* Nothing to do */
  314.   } 
  315.   else
  316.     for(i = 0; i < num_elm; i++) {
  317.       dest[0] = source[0];
  318.       dest += dest_stride;
  319.       source += source_stride;
  320.     }
  321.   
  322.   return 0;
  323. }
  324.  
  325. #if !defined(UNICOS)  /* UNICOS does not need these routines */
  326.  
  327. /************************************************************/
  328. /* DFKnb2b()                                                */
  329. /* -->Native mode for 2 byte data items                     */
  330. /************************************************************/
  331. #ifdef PROTOTYPE
  332. PRIVATE int DFKnb2b(VOIDP s, VOIDP d, uint32 num_elm, uint32 source_stride,
  333.            uint32 dest_stride)
  334. #else
  335. PRIVATE int DFKnb2b(s, d, num_elm, source_stride, dest_stride)
  336. VOIDP s, d;
  337. uint32 num_elm, source_stride, dest_stride;
  338. #endif /* PROTOTYPE */
  339. {
  340.   int fast_processing = 0;              /* Default is not fast processing */
  341.   int in_place = 0;                     /* Inplace must be detected */
  342.   register uint32 i;            
  343.   uint8 buf[2];                          /* Inplace processing buffer */
  344.   uint8 * source = (uint8*)s;
  345.   uint8 * dest = (uint8*)d;
  346.   char *FUNC="DFKnb2b";
  347.  
  348.   HEclear();
  349.  
  350.   if(num_elm == 0){
  351.     HERROR(DFE_BADCONV);
  352.     return FAIL;
  353.   }
  354.  
  355.   /* Determine if faster array processing is appropriate */
  356.   if((source_stride == 0 && dest_stride == 0) ||
  357.      (source_stride == 2 && dest_stride == 2))
  358.     fast_processing = 1;
  359.  
  360.   /* Determine if the conversion should be inplace */
  361.   if(source == dest)
  362.     in_place = 1;
  363.  
  364.   if(fast_processing) 
  365.     if(!in_place) {
  366.       DFmovmem(source, dest, num_elm*2);
  367.       return 0;
  368.     }
  369.     else {    /* Nothing to do */
  370.       return 0;
  371.     }
  372.   
  373.   /* Generic stride processing */
  374.   if(!in_place)
  375.     for(i = 0; i < num_elm; i++) {
  376.       dest[0] = source[0];
  377.       dest[1] = source[1];
  378.       dest += dest_stride;
  379.       source += source_stride;
  380.     }
  381.   else
  382.     for(i = 0; i < num_elm; i++) {
  383.       buf[0] = source[0];
  384.       buf[1] = source[1];
  385.       dest[0] = buf[0];
  386.       dest[1] = buf[1];
  387.       dest += dest_stride;
  388.       source += source_stride;
  389.     }
  390.     
  391.   return 0;
  392. }
  393.  
  394. /************************************************************/
  395. /* DFKnb4b()                                                */
  396. /* -->Native mode for 4 byte items                          */
  397. /************************************************************/
  398. #ifdef PROTOTYPE
  399. PRIVATE int DFKnb4b(VOIDP s, VOIDP d, uint32 num_elm,
  400.            uint32 source_stride, uint32 dest_stride)
  401. #else
  402. PRIVATE int DFKnb4b(s, d, num_elm, source_stride, dest_stride)
  403. uint8 * s, * d;
  404. uint32 num_elm, source_stride, dest_stride;
  405. #endif /* PROTOTYPE */
  406. {
  407.   int fast_processing = 0;              /* Default is not fast processing */
  408.   int in_place = 0;                     /* Inplace must be detected */
  409.   register uint32 i;            
  410.   uint8 buf[4];                          /* Inplace processing buffer */
  411.   uint8 * source = (uint8*)s;
  412.   uint8 * dest = (uint8*)d;
  413.   char *FUNC="DFKnb4b";
  414.  
  415.   HEclear();
  416.  
  417.   if(num_elm == 0){
  418.     HERROR(DFE_BADCONV);
  419.     return FAIL;
  420.   }
  421.  
  422.   /* Determine if faster array processing is appropriate */
  423.   if((source_stride == 0 && dest_stride == 0) ||
  424.      (source_stride == 4 && dest_stride == 4))
  425.     fast_processing = 1;
  426.  
  427.   /* Determine if the conversion should be inplace */
  428.   if(source == dest)
  429.     in_place = 1;
  430.  
  431.   if(fast_processing) 
  432.     if(!in_place) {
  433.       DFmovmem(source, dest, num_elm*4);
  434.       return 0;
  435.     }
  436.     else {  /* Nothing to do */
  437.       return 0;
  438.     }
  439.  
  440.   /* Generic stride processing */
  441.   if(!in_place)
  442.     for(i = 0; i < num_elm; i++) {
  443.       dest[0] = source[0];
  444.       dest[1] = source[1];
  445.       dest[2] = source[2];
  446.       dest[3] = source[3];
  447.       dest += dest_stride;
  448.       source += source_stride;
  449.     }
  450.   else
  451.     for(i = 0; i < num_elm; i++) {
  452.       buf[0] = source[0];
  453.       buf[1] = source[1];
  454.       buf[2] = source[2];
  455.       buf[3] = source[3];
  456.       dest[0] = buf[0];
  457.       dest[1] = buf[1];
  458.       dest[2] = buf[2];
  459.       dest[3] = buf[3];
  460.       dest += dest_stride;
  461.       source += source_stride;
  462.     }
  463.     
  464.   return 0;
  465. }
  466.  
  467. #endif /* UNICOS */
  468.  
  469. /************************************************************/
  470. /* DFKnb8b()                                                */
  471. /* -->Native mode for 8 byte items                          */
  472. /************************************************************/
  473. #ifdef PROTOTYPE
  474. PRIVATE int DFKnb8b(VOIDP s, VOIDP d, uint32 num_elm,
  475.            uint32 source_stride, uint32 dest_stride)
  476. #else
  477. PRIVATE int DFKnb8b(source, dest, num_elm, source_stride, dest_stride)
  478. uint8 * source, * dest;
  479. uint32 num_elm, source_stride, dest_stride;
  480. #endif /* PROTOTYPE */
  481. {
  482.   int fast_processing = 0;              /* Default is not fast processing */
  483.   int in_place = 0;                     /* Inplace must be detected */
  484.   register uint32 i;            
  485.   uint8 buf[8];                          /* Inplace processing buffer */
  486. #ifdef PROTOTYPE
  487.   uint8 * source = (uint8*)s;
  488.   uint8 * dest = (uint8*)d;
  489. #endif /* PROTOTYPE */
  490.  
  491.     char *FUNC="DFKnb8b";
  492.  
  493.     HEclear();
  494.  
  495.   if(num_elm == 0){
  496.     HERROR(DFE_BADCONV);
  497.     return FAIL;
  498.   }
  499.  
  500.   /* Determine if faster array processing is appropriate */
  501.   if((source_stride == 0 && dest_stride == 0) ||
  502.      (source_stride == 8 && dest_stride == 8))
  503.     fast_processing = 1;
  504.  
  505.   /* Determine if the conversion should be inplace */
  506.   if(source == dest)
  507.     in_place = 1;
  508.  
  509.   if(fast_processing) 
  510.     if(!in_place) {
  511.       DFmovmem(source, dest, num_elm*8);
  512.       return 0;
  513.     }
  514.     else {  
  515.       return 0;     /* No work to do ! */
  516.       }
  517.  
  518.   /* Generic stride processing */
  519.   if(!in_place)
  520.     for(i = 0; i < num_elm; i++) {
  521.       dest[0] = source[0];
  522.       dest[1] = source[1];
  523.       dest[2] = source[2];
  524.       dest[3] = source[3];
  525.       dest[4] = source[4];
  526.       dest[5] = source[5];
  527.       dest[6] = source[6];
  528.       dest[7] = source[7];
  529.       dest += dest_stride;
  530.       source += source_stride;
  531.     }
  532.   else
  533.     for(i = 0; i < num_elm; i++) {
  534.       buf[0] = source[0];
  535.       buf[1] = source[1];
  536.       buf[2] = source[2];
  537.       buf[3] = source[3];
  538.       buf[4] = source[4];
  539.       buf[5] = source[5];
  540.       buf[6] = source[6];
  541.       buf[7] = source[7];
  542.       dest[0] = buf[0];
  543.       dest[1] = buf[1];
  544.       dest[2] = buf[2];
  545.       dest[3] = buf[3];
  546.       dest[4] = buf[4];
  547.       dest[5] = buf[5];
  548.       dest[6] = buf[6];
  549.       dest[7] = buf[7];
  550.       dest += dest_stride;
  551.       source += source_stride;
  552.     }
  553.     
  554.   return 0;
  555. }
  556.  
  557.  
  558. /*****************************************************************************/
  559. /* NUMBER CONVERSION ROUTINES FOR BYTE SWAPPING                              */
  560. /*****************************************************************************/
  561.  
  562. #ifdef BYTE_SWAPPER
  563.  
  564. /************************************************************/
  565. /* DFKsb2b()                                                */
  566. /* -->Byte swapping for 2 byte data items                   */
  567. /************************************************************/
  568. #ifdef PROTOTYPE
  569. PRIVATE int DFKsb2b(VOIDP s, VOIDP d, uint32 num_elm, uint32 source_stride,
  570.            uint32 dest_stride)
  571. #else
  572. PRIVATE int DFKsb2b(source, dest, num_elm, source_stride, dest_stride)
  573. uint8 * source, * dest;
  574. uint32 num_elm, source_stride, dest_stride;
  575. #endif /* PROTOTYPE */
  576. {
  577.   int fast_processing = 0;              /* Default is not fast processing */
  578.   int in_place = 0;                     /* Inplace must be detected */
  579.   register uint32 i;            
  580.   uint8 buf[2];                          /* Inplace processing buffer */
  581. #ifdef PROTOTYPE
  582.   uint8 * source = (uint8*)s;
  583.   uint8 * dest = (uint8*)d;
  584. #endif /* PROTOTYPE */
  585.   char *FUNC="DFKsb2b";
  586.  
  587.   HEclear();
  588.  
  589.   if(num_elm == 0){                          /* No elements is an error. */
  590.     HERROR(DFE_BADCONV);
  591.     return FAIL;
  592.   }
  593.  
  594.   /* Determine if faster array processing is appropriate */
  595.   if(source_stride == 0 && dest_stride == 0)
  596.     fast_processing = 1;
  597.  
  598.   /* Determine if the conversion should be inplace */
  599.   if(source == dest)
  600.     in_place = 1;
  601.  
  602.   if(fast_processing) 
  603.     if(!in_place) {
  604.       for(i = 0; i < num_elm; i++) {
  605.         dest[0] = source[1];
  606.         dest[1] = source[0];
  607.         dest += 2;
  608.         source += 2;
  609.       }
  610.       return 0;
  611.     }
  612.     else { 
  613.       for(i = 0; i < num_elm; i++) {
  614.         buf[0] = source[1];
  615.         buf[1] = source[0];
  616.         dest[0] = buf[0];
  617.         dest[1] = buf[1];
  618.         dest += 2;
  619.         source += 2;
  620.       }
  621.       return 0;
  622.     }
  623.   
  624.   /* Generic stride processing */
  625.   if(!in_place)
  626.     for(i = 0; i < num_elm; i++) {
  627.       dest[0] = source[1];
  628.       dest[1] = source[0];
  629.       dest += dest_stride;
  630.       source += source_stride;
  631.     }
  632.   else
  633.     for(i = 0; i < num_elm; i++) {
  634.       buf[0] = source[1];
  635.       buf[1] = source[0];
  636.       dest[0] = buf[0];
  637.       dest[1] = buf[1];
  638.       dest += dest_stride;
  639.       source += source_stride;
  640.     }
  641.   return 0;
  642. }
  643.  
  644. /************************************************************/
  645. /* DFKsb4b()                                                */
  646. /* -->Byte swapping for 4 byte data items                   */
  647. /************************************************************/
  648. #ifdef PROTOTYPE
  649. PRIVATE int DFKsb4b(VOIDP s, VOIDP d, uint32 num_elm, uint32 source_stride,
  650.            uint32 dest_stride)
  651. #else
  652. PRIVATE int DFKsb4b(source, dest, num_elm, source_stride, dest_stride)
  653. uint8 * source, * dest;
  654. uint32 num_elm, source_stride, dest_stride;
  655. #endif /* PROTOTYPE */
  656. {
  657.   int fast_processing = 0;              /* Default is not fast processing */
  658.   int in_place = 0;                     /* Inplace must be detected */
  659.   register uint32 i;            
  660.   uint8 buf[4];                          /* Inplace processing buffer */
  661. #ifdef PROTOTYPE
  662.   uint8 * source = (uint8*)s;
  663.   uint8 * dest = (uint8*)d;
  664. #endif /* PROTOTYPE */
  665.   char *FUNC="DFKsb4b";
  666.  
  667.   HEclear();
  668.  
  669.   if(num_elm == 0){                         /* No elements is an error. */
  670.     HERROR(DFE_BADCONV);
  671.     return FAIL;
  672.   }
  673.  
  674.   /* Determine if faster array processing is appropriate */
  675.   if(source_stride == 0 && dest_stride == 0)
  676.     fast_processing = 1;
  677.  
  678.   /* Determine if the conversion should be inplace */
  679.   if(source == dest)
  680.     in_place = 1;
  681.  
  682.   if(fast_processing) 
  683.     if(!in_place) {
  684.       for(i = 0; i < num_elm; i++) {
  685.         dest[0] = source[3];
  686.         dest[1] = source[2];
  687.         dest[2] = source[1];
  688.         dest[3] = source[0];
  689.         dest += 4;
  690.         source += 4;
  691.       }
  692.       return 0;
  693.     }
  694.     else {
  695.       for(i = 0; i < num_elm; i++) {
  696.         buf[0] = source[3];
  697.         buf[1] = source[2];
  698.         buf[2] = source[1];
  699.         buf[3] = source[0];
  700.         dest[0] = buf[0];
  701.         dest[1] = buf[1];
  702.         dest[2] = buf[2];
  703.         dest[3] = buf[3];
  704.         dest += 4;
  705.         source += 4;
  706.       }
  707.       return 0;
  708.     }
  709.   
  710.   /* Generic stride processing */
  711.   if(!in_place)
  712.     for(i = 0; i < num_elm; i++) {
  713.       dest[0] = source[3];
  714.       dest[1] = source[2];
  715.       dest[2] = source[1];
  716.       dest[3] = source[0];
  717.       dest += dest_stride;
  718.       source += source_stride;
  719.     }
  720.   else
  721.     for(i = 0; i < num_elm; i++) {
  722.       buf[0] = source[3];
  723.       buf[1] = source[2];
  724.       buf[2] = source[1];
  725.       buf[3] = source[0];
  726.       dest[0] = buf[0];
  727.       dest[1] = buf[1];
  728.       dest[2] = buf[2];
  729.       dest[3] = buf[3];
  730.       dest += dest_stride;
  731.       source += source_stride;
  732.     }
  733.   return 0;
  734. }
  735.  
  736. /************************************************************/
  737. /* DFKsb8b()                                                */
  738. /* -->Byte swapping for 8 byte data items                   */
  739. /************************************************************/
  740. #ifdef PROTOTYPE
  741. PRIVATE int DFKsb8b(VOIDP s, VOIDP d, uint32 num_elm, uint32 source_stride,
  742.            uint32 dest_stride)
  743. #else
  744. PRIVATE int DFKsb8b(source, dest, num_elm, source_stride, dest_stride)
  745. uint8 * source, * dest;
  746. uint32 num_elm, source_stride, dest_stride;
  747. #endif /* PROTOTYPE */
  748. {
  749.   int fast_processing = 0;              /* Default is not fast processing */
  750.   int in_place = 0;                     /* Inplace must be detected */
  751.   register uint32 i;            
  752.   uint8 buf[8];                          /* Inplace processing buffer */
  753. #ifdef PROTOTYPE
  754.   uint8 * source = (uint8*)s;
  755.   uint8 * dest = (uint8*)d;
  756. #endif /* PROTOTYPE */
  757.     char *FUNC="DFKsb8b";
  758.  
  759.     HEclear();
  760.  
  761.   if(num_elm == 0){                         /* No elements is an error. */
  762.     HERROR(DFE_BADCONV);
  763.     return FAIL;
  764.   }
  765.  
  766.   /* Determine if faster array processing is appropriate */
  767.   if(source_stride == 0 && dest_stride == 0)
  768.     fast_processing = 1;
  769.  
  770.   /* Determine if the conversion should be inplace */
  771.   if(source == dest)
  772.     in_place = 1;
  773.  
  774.   if(fast_processing) 
  775.     if(!in_place) {
  776.       for(i = 0; i < num_elm; i++) {
  777.         dest[0] = source[7];
  778.         dest[1] = source[6];
  779.         dest[2] = source[5];
  780.         dest[3] = source[4];
  781.         dest[4] = source[3];
  782.         dest[5] = source[2];
  783.         dest[6] = source[1];
  784.         dest[7] = source[0];
  785.         dest += 8;
  786.         source += 8;
  787.       }
  788.       return 0;
  789.     }
  790.     else {
  791.       for(i = 0; i < num_elm; i++) {
  792.         buf[0] = source[7];
  793.         buf[1] = source[6];
  794.         buf[2] = source[5];
  795.         buf[3] = source[4];
  796.         buf[4] = source[3];
  797.         buf[5] = source[2];
  798.         buf[6] = source[1];
  799.         buf[7] = source[0];
  800.         dest[0] = buf[0];
  801.         dest[1] = buf[1];
  802.         dest[2] = buf[2];
  803.         dest[3] = buf[3];
  804.         dest[4] = buf[4];
  805.         dest[5] = buf[5];
  806.         dest[6] = buf[6];
  807.         dest[7] = buf[7];
  808.         dest += 8;
  809.         source += 8;
  810.       }
  811.       return 0;
  812.     }
  813.   
  814.   /* Generic stride processing */
  815.   if(!in_place)
  816.     for(i = 0; i < num_elm; i++) {
  817.       dest[0] = source[7];
  818.       dest[1] = source[6];
  819.       dest[2] = source[5];
  820.       dest[3] = source[4];
  821.       dest[4] = source[3];
  822.       dest[5] = source[2];
  823.       dest[6] = source[1];
  824.       dest[7] = source[0];
  825.       dest += dest_stride;
  826.       source += source_stride;
  827.     }
  828.   else
  829.     for(i = 0; i < num_elm; i++) {
  830.       buf[0] = source[7];
  831.       buf[1] = source[6];
  832.       buf[2] = source[5];
  833.       buf[3] = source[4];
  834.       buf[4] = source[3];
  835.       buf[5] = source[2];
  836.       buf[6] = source[1];
  837.       buf[7] = source[0];
  838.       dest[0] = buf[0];
  839.       dest[1] = buf[1];
  840.       dest[2] = buf[2];
  841.       dest[3] = buf[3];
  842.       dest[4] = buf[4];
  843.       dest[5] = buf[5];
  844.       dest[6] = buf[6];
  845.       dest[7] = buf[7];
  846.       dest += dest_stride;
  847.       source += source_stride;
  848.     }
  849.  
  850.   return 0;
  851. }
  852.  
  853. #endif /* BYTE_SWAPPER */
  854.  
  855. /*****************************************************************************/
  856. /* NUMBER CONVERSION ROUTINES FOR THE UNICOS OPERATING SYSTEM                */
  857. /* Parameter dest_stride is used because source buffer and dest buffer will  */
  858. /* be different sizes for all data types except char.                        */
  859. /*****************************************************************************/
  860.  
  861. /*****************************************************************************/
  862. /*                                                                           */
  863. /*   For all you CRAY lovers out there, I just thought I would tell you      */
  864. /* how my routines work.  If you know of a better, or more efficient         */
  865. /* method for converting any of these, please tell me.                       */
  866. /*                                                                           */
  867. /*   Mark Straka provided the routine to convert the 32 bit and 64 bit       */
  868. /* Cray floats into the IEEE format and back.  In the previous release of    */
  869. /* HDF, his routines were incorporated from Fortran source.  In this         */
  870. /* release, the original C source has been incorporated.  Please note,       */
  871. /* the Public Domain notice included at the top of this file pertains to     */
  872. /* these routines as well.                                                   */
  873. /*                                                                           */
  874. /*****************************************************************************/
  875.  
  876. #if defined(UNICOS)
  877.  
  878. /************************************************************/
  879. /* DFKui2i()                                                */
  880. /* -->Unicos routine for importing 2 byte data items        */ 
  881. /* (**) This routine converts two byte IEEE to eight byte   */
  882. /*      Cray little endian integer.                         */
  883. /************************************************************/
  884. #ifdef PROTOTYPE
  885. PRIVATE int DFKui2i(VOIDP s, VOIDP d, uint32 num_elm, uint32 source_stride,
  886.            uint32 dest_stride)
  887. #else
  888. PRIVATE int DFKui2i(source, dest, num_elm, source_stride, dest_stride)
  889. uint8 * source, * dest;
  890. uint32 num_elm, source_stride, dest_stride;
  891. #endif /* PROTOTYPE */
  892. {
  893.   register uint32 i;
  894.   int fast_processing=0;
  895. #ifdef PROTOTYPE
  896.   uint8 * source = (uint8*)s;
  897.   uint8 * dest = (uint8*)d;
  898. #endif /* PROTOTYPE */
  899.   long * lptr_dest = (long*)dest;
  900.   char *FUNC="DFKui2i";
  901.  
  902.   HEclear();
  903.  
  904.   if(source == dest || num_elm == 0) {  /* Inplace conversions not permitted */
  905.     HERROR(DFE_BADCONV);                /* No elements is an error */
  906.     return FAIL;
  907.   }
  908.  
  909.   /* Find out if it is OK to use faster array processing */
  910.   if(source_stride == 0 && dest_stride == 0) 
  911.       fast_processing = 1;            
  912.  
  913.   if(fast_processing) {
  914.     for(i = 0; i < num_elm; i++) {
  915.       lptr_dest[0] = 0x0000000000000000;
  916.       dest[6] = source[0];
  917.       dest[7] = source[1];
  918.       source += 2;
  919.       lptr_dest++;
  920.       dest = (uint8*)lptr_dest;
  921.     }
  922.   }
  923.   else { /* Generic stride processing */
  924.     for(i = 0; i < num_elm; i++) {
  925.       dest[0] = 0x00;
  926.       dest[1] = 0x00;
  927.       dest[2] = 0x00;
  928.       dest[3] = 0x00;
  929.       dest[4] = 0x00;
  930.       dest[5] = 0x00;
  931.       dest[6] = source[0];
  932.       dest[7] = source[1];
  933.       source += source_stride;
  934.       dest += dest_stride;
  935.     }
  936.   }
  937.   return 0;
  938. }
  939.  
  940. /************************************************************/
  941. /* DFKui2s()                                                */
  942. /* -->Unicos routine for importing 2 byte signed ints       */
  943. /* (**) This routine converts two byte IEEE to eight byte   */
  944. /*      Cray.                                               */
  945. /************************************************************/
  946. #ifdef PROTOTYPE
  947. PRIVATE int DFKui2s(VOIDP s, VOIDP d, uint32 num_elm, uint32 source_stride,
  948.            uint32 dest_stride)
  949. #else
  950. PRIVATE int DFKui2s(source, dest, num_elm, source_stride, dest_stride)
  951. uint8 * source, * dest;
  952. uint32 num_elm, source_stride, dest_stride;
  953. #endif /* PROTOTYPE */
  954. {
  955.   register uint32 i;
  956.   int fast_processing=0;
  957. #ifdef PROTOTYPE
  958.   uint8 * source = (uint8*)s;
  959.   uint8 * dest = (uint8*)d;
  960. #endif /* PROTOTYPE */
  961.   long * lptr_dest = (long*)dest;
  962.   char *FUNC="DFKui2s";
  963.  
  964.   HEclear();
  965.  
  966.   if(source == dest || num_elm == 0) {  /* Inplace conversions  not permitted */
  967.     HERROR(DFE_BADCONV);                /* No elements to convert is an error */
  968.     return FAIL;
  969.   }
  970.  
  971.   /* Find out if it is OK to use faster array processing */
  972.   if(source_stride == 0 && dest_stride == 0) 
  973.       fast_processing = 1;            
  974.  
  975.   if(fast_processing) {
  976.     for(i = 0; i < num_elm; i++) {
  977.       if((source[0] & 0x80))           /* Can't forget to extend sign */
  978.     lptr_dest[0] = 0xffffffffffffffff;
  979.       else
  980.     lptr_dest[0] = 0x0000000000000000;
  981.       dest[6] = source[0];
  982.       dest[7] = source[1];
  983.       source += 2;
  984.       lptr_dest++;
  985.       dest = (uint8*)lptr_dest;
  986.     }
  987.   }
  988.   else { /* Generic stride processing */
  989.     for(i = 0; i < num_elm; i++) {
  990.       if((source[0] & 0x80)) {          /* Can't forget to extend sign */
  991.     dest[0] = 0xff;
  992.     dest[1] = 0xff;
  993.     dest[2] = 0xff;
  994.     dest[3] = 0xff;
  995.     dest[4] = 0xff;
  996.     dest[5] = 0xff;
  997.       }
  998.       else {
  999.     dest[0] = 0x00;
  1000.     dest[1] = 0x00;
  1001.     dest[2] = 0x00;
  1002.     dest[3] = 0x00;
  1003.     dest[4] = 0x00;
  1004.     dest[5] = 0x00;
  1005.       }
  1006.       dest[6] = source[0];
  1007.       dest[7] = source[1];
  1008.       source += source_stride;
  1009.       dest += dest_stride;
  1010.     }
  1011.   }
  1012.   return 0;
  1013. }
  1014.  
  1015. /************************************************************/
  1016. /* DFKuo2i()                                                */
  1017. /* -->Unicos routine for exporting 2 byte data items        */ 
  1018. /************************************************************/
  1019. #ifdef PROTOTYPE
  1020. PRIVATE int DFKuo2i(VOIDP s, VOIDP d, uint32 num_elm, uint32 source_stride,
  1021.            uint32 dest_stride)
  1022. #else
  1023. PRIVATE int DFKuo2i(source, dest, num_elm, source_stride, dest_stride)
  1024. uint8 * source, * dest;
  1025. uint32 num_elm, source_stride, dest_stride;
  1026. #endif /* PROTOTYPE */
  1027. {
  1028.   register uint32 i;
  1029.   int fast_processing=0;
  1030. #ifdef PROTOTYPE
  1031.   uint8 * source = (uint8*)s;
  1032.   uint8 * dest = (uint8*)d;
  1033. #endif /* PROTOTYPE */
  1034.     char *FUNC="DFKuo2i";
  1035.  
  1036.     HEclear();
  1037.  
  1038.   if(source == dest || num_elm == 0) {  /* Inplace conversions  not permitted */
  1039.     HERROR(DFE_BADCONV);                /* No elements to convert is an error */
  1040.     return FAIL;
  1041.   }
  1042.  
  1043.   /* Find out if it is OK to use faster array processing */
  1044.   if(source_stride == 0 && dest_stride == 0)
  1045.       fast_processing = 1;            
  1046.  
  1047.   if(fast_processing) {
  1048.     for(i = 0; i < num_elm; i++) {
  1049.       dest[0] = source[6];
  1050.       dest[1] = source[7];
  1051.       dest += 2;
  1052.       source += 8;
  1053.     }
  1054.   }
  1055.   else { /* Generic Stride processing */
  1056.     for(i = 0; i < num_elm; i++){
  1057.       dest[0] = source[6];
  1058.       dest[1] = source[7];
  1059.       source += source_stride;
  1060.       dest += dest_stride;
  1061.     }
  1062.   }
  1063.   return 0;
  1064. }
  1065.  
  1066. /************************************************************/
  1067. /* DFKui4i()                                                */
  1068. /* -->Unicos routine for importing 4 byte unsigned ints     */
  1069. /************************************************************/
  1070. #ifdef PROTOTYPE
  1071. PRIVATE int DFKui4i(VOIDP s, VOIDP d, uint32 num_elm, uint32 source_stride,
  1072.            uint32 dest_stride)
  1073. #else
  1074. PRIVATE int DFKui4i(source, dest, num_elm, source_stride, dest_stride)
  1075. uint8 * source, * dest;
  1076. uint32 num_elm, source_stride, dest_stride;
  1077. #endif /* PROTOTYPE */
  1078. {
  1079.   int fast_processing=0;
  1080.   register uint32 i;
  1081. #ifdef PROTOTYPE
  1082.   uint8 * source = (uint8*)s;
  1083.   uint8 * dest = (uint8*)d;
  1084. #endif /* PROTOTYPE */
  1085.   long * lptr_dest = (long*)dest;
  1086.   char *FUNC="DFKui4i";
  1087.  
  1088.   HEclear();
  1089.  
  1090.   if(source == dest || num_elm == 0) {  /* Inplace conversions  not permitted */
  1091.     HERROR(DFE_BADCONV);                /* No elements to convert is an error */
  1092.     return FAIL;
  1093.   }
  1094.  
  1095.   if(source_stride == 0 && dest_stride == 0) {
  1096.     fast_processing = 1;
  1097.   }
  1098.   
  1099.   if(fast_processing)
  1100.     for(i = 0; i < num_elm; i++) {
  1101.       lptr_dest[0] = 0;
  1102.       dest[4] = source[0];
  1103.       dest[5] = source[1];
  1104.       dest[6] = source[2];
  1105.       dest[7] = source[3];
  1106.       source += 4;
  1107.       lptr_dest ++;
  1108.       dest = (uint8 *)lptr_dest;
  1109.     }
  1110.   else 
  1111.     for(i = 0; i < num_elm; i++) {
  1112.       dest[0] = 0;
  1113.       dest[1] = 0;
  1114.       dest[2] = 0;
  1115.       dest[3] = 0;
  1116.       dest[4] = source[0];
  1117.       dest[5] = source[1];
  1118.       dest[6] = source[2];
  1119.       dest[7] = source[3];
  1120.       dest += dest_stride;
  1121.       source += source_stride;
  1122.     }
  1123.   return 0;
  1124. }
  1125.  
  1126. /************************************************************/
  1127. /* DFKui4s()                                                */
  1128. /* -->Unicos routine for importing 4 signed ints            */ 
  1129. /************************************************************/
  1130. #ifdef PROTOTYPE
  1131. PRIVATE int DFKui4s(VOIDP s, VOIDP d, uint32 num_elm, uint32 source_stride,
  1132.            uint32 dest_stride)
  1133. #else
  1134. PRIVATE int DFKui4s(source, dest, num_elm, source_stride, dest_stride)
  1135. uint8 * source, * dest;
  1136. uint32 num_elm, source_stride, dest_stride;
  1137. #endif /* PROTOTYPE */
  1138. {
  1139.   int fast_processing=0;
  1140.   register uint32 i;
  1141. #ifdef PROTOTYPE
  1142.   uint8 * source = (uint8*)s;
  1143.   uint8 * dest = (uint8*)d;
  1144. #endif /* PROTOTYPE */
  1145.   long * lptr_dest = (long*)dest;
  1146.   char *FUNC="DFKui4s";
  1147.  
  1148.   HEclear();
  1149.  
  1150.   if(source == dest || num_elm == 0) {  /* Inplace conversions  not permitted */
  1151.     HERROR(DFE_BADCONV);                /* No elements to convert is an error */
  1152.     return FAIL;
  1153.   }
  1154.  
  1155.   if(source_stride == 0 && dest_stride == 0) {
  1156.     fast_processing = 1;
  1157.   }
  1158.   
  1159.   if(fast_processing)
  1160.     for(i = 0; i < num_elm; i++) {
  1161.       if((source[0] & 0x80))            /* Can't forget to sign extend */
  1162.     lptr_dest[0] = 0xffffffffffffffff;
  1163.       else
  1164.     lptr_dest[0] = 0x0000000000000000;
  1165.       dest[4] = source[0];
  1166.       dest[5] = source[1];
  1167.       dest[6] = source[2];
  1168.       dest[7] = source[3];
  1169.       source += 4;
  1170.       lptr_dest ++;
  1171.       dest = (uint8 *)lptr_dest;
  1172.     }
  1173.   else 
  1174.     for(i = 0; i < num_elm; i++) {
  1175.       if((source[0] & 0x80)) {          /* Can't forget to sign extend */
  1176.     dest[0] = 0xff;
  1177.     dest[1] = 0xff;
  1178.     dest[2] = 0xff;
  1179.     dest[3] = 0xff;
  1180.       }
  1181.       else {
  1182.     dest[0] = 0;
  1183.     dest[1] = 0;
  1184.     dest[2] = 0;
  1185.     dest[3] = 0;
  1186.       }
  1187.       dest[4] = source[0];
  1188.       dest[5] = source[1];
  1189.       dest[6] = source[2];
  1190.       dest[7] = source[3];
  1191.       dest += dest_stride;
  1192.       source += source_stride;
  1193.     }
  1194.   return 0;
  1195. }
  1196.  
  1197. /************************************************************/
  1198. /* DFKuo4i()                                                */
  1199. /* -->Unicos routine for exporting 4 byte data items        */ 
  1200. /************************************************************/
  1201.  
  1202. #ifdef PROTOTYPE
  1203. PRIVATE int DFKuo4i(VOIDP s, VOIDP d, uint32 num_elm, uint32 source_stride,
  1204.            uint32 dest_stride)
  1205. #else
  1206. PRIVATE int DFKuo4i(source, dest, num_elm, source_stride, dest_stride)
  1207. uint8 * source, * dest;
  1208. uint32 num_elm, source_stride, dest_stride;
  1209. #endif /* PROTOTYPE */
  1210. {
  1211.   int fast_processing=0;
  1212.   register uint32 i;
  1213. #ifdef PROTOTYPE
  1214.   uint8 * source = (uint8*)s;
  1215.   uint8 * dest = (uint8*)d;
  1216. #endif /* PROTOTYPE */
  1217.   char *FUNC="DFKuo4i";
  1218.  
  1219.   HEclear();
  1220.  
  1221.   if(source == dest || num_elm == 0) {  /* Inplace conversions  not permitted */
  1222.     HERROR(DFE_BADCONV);                /* No elements to convert is an error */
  1223.     return FAIL;
  1224.   }
  1225.  
  1226.   if(source_stride == 0 && dest_stride == 0) {
  1227.     fast_processing = 1;
  1228.   }
  1229.   
  1230.   if(fast_processing)
  1231.     for(i = 0; i < num_elm; i++) {
  1232.       dest[0] = source[4];
  1233.       dest[1] = source[5];
  1234.       dest[2] = source[6];
  1235.       dest[3] = source[7];
  1236.       dest += 4;
  1237.       source += 8;
  1238.     }
  1239.   else 
  1240.     for(i = 0; i < num_elm; i++) {
  1241.       dest[0] = source[4];
  1242.       dest[1] = source[5];
  1243.       dest[2] = source[6];
  1244.       dest[3] = source[7];
  1245.       dest += dest_stride;
  1246.       source += source_stride;
  1247.     }
  1248.   return 0;
  1249. }
  1250.  
  1251. #define UI4_MASKA 0x8000000000000000
  1252. #define UI4_MASKB 0x7f80000000000000
  1253. #define UI4_MASKC 0x007fffff00000000
  1254. #define UI4_MASKD 0x0000800000000000
  1255.  
  1256. /************************************************************/
  1257. /* DFKui4f()                                                */
  1258. /* -->Unicos routine for importing 32 bit floats            */
  1259. /************************************************************/
  1260.  
  1261. /************************************************************
  1262.  
  1263.                      <<<< WARNING >>>>
  1264.  
  1265.     The nature of converting between 64 bit floating point
  1266.   numbers and 32 bit floating point numbers LOSES PRECISION.
  1267.   Taking a number in 64bit cray format, converting to IEEE
  1268.   (internal HDF format) and back will round the number at
  1269.   about the 7th decimal place.
  1270.  
  1271.  ************************************************************/
  1272.  
  1273. #ifdef PROTOTYPE
  1274. PRIVATE int DFKui4f(VOIDP s, VOIDP d, uint32 num_elm, uint32 source_stride,
  1275.            uint32 dest_stride)
  1276. #else
  1277. PRIVATE int DFKui4f(source, dest, num_elm, source_stride, dest_stride)
  1278. uint8 * source;
  1279. uint8 * dest;
  1280. uint32 num_elm;
  1281. uint32 source_stride;
  1282. uint32 dest_stride;
  1283. #endif /* PROTOTYPE */
  1284. {
  1285.   int fast_processing = 0;              /* By default not array processed */
  1286.   int odd_man_out = 0;                  /* By default there are even num_elm */
  1287.   register int i,j;
  1288.   long buf1;                            /* This is a temporary stride buf */
  1289.   long buf2;                            /* This is a temporary stride buf */
  1290.   uint8 * dud1 = (uint8*)&buf1;         /* Dummy pointer to buf1 for strides */
  1291.   uint8 * dud2 = (uint8*)&buf2;         /* Dummy pointer to buf2 for strides */
  1292. #ifdef PROTOTYPE
  1293.   uint8 * source = (uint8*)s;            /* Cray does not like certain   */
  1294.   uint8 * dest = (uint8*)d;              /* void and void* constructions */
  1295. #endif /* PROTOTYPE */
  1296.   long * lptr_src = (long*)source;
  1297.   long * lptr_dest = (long*)dest;
  1298.   char *FUNC="DFKui4f";
  1299.  
  1300.   HEclear();
  1301.  
  1302.   /* Check for conversion errors */
  1303.   if(source == dest || num_elm == 0) { /* Inplace conversions not permitted */
  1304.     HERROR(DFE_BADCONV);               /* under UNICOS */
  1305.     return FAIL;                       /* No elements convert is an error   */
  1306.   }
  1307.  
  1308.   /* Find out if it is OK to use faster array processing */
  1309.   if(source_stride == 0 && dest_stride == 0) {
  1310.       fast_processing = 1;            
  1311.     if((num_elm % 2))                   /* If this is true, we have odd num */
  1312.       odd_man_out = 1;
  1313.   }
  1314.  
  1315.   if(fast_processing) {
  1316.     num_elm = num_elm / 2;
  1317.     for(i = 0; i < num_elm; i++) {
  1318.       if(*(float*)lptr_src != 0) {
  1319.     *lptr_dest = (((*lptr_src & UI4_MASKA) |
  1320.                ((*lptr_src & UI4_MASKB) >> 7) +
  1321.                (16258 << 48)) |     
  1322.               (((*lptr_src & UI4_MASKC) >> 8) | (UI4_MASKD)));
  1323.     if(((*lptr_src & 0xffffffff00000000) << 1)== 0)
  1324.       *lptr_dest = 0;
  1325.       }
  1326.       else
  1327.     *lptr_dest = *lptr_src;
  1328.       lptr_dest++;
  1329.       if(*(float*)lptr_src != 0) {
  1330.     *lptr_dest = ((((((*lptr_src << 32) & UI4_MASKA)) |
  1331.             (((*lptr_src <<32) & UI4_MASKB) >> 7) +
  1332.             (16258 << 48)) |     
  1333.                ((((*lptr_src << 32) & UI4_MASKC) >> 8) |(UI4_MASKD))));
  1334.     if(((*lptr_src & 0x00000000ffffffff) << 33)== 0)
  1335.       *lptr_dest = 0;
  1336.       }
  1337.       else
  1338.     *lptr_dest = *lptr_src;
  1339.       lptr_src++;
  1340.       lptr_dest++;
  1341.     }
  1342.     if(odd_man_out){
  1343.       if(((float*)lptr_src)[0] != 0) {
  1344.     lptr_dest[0] = ((((lptr_src[0]) & UI4_MASKA) |
  1345.                (((lptr_src[0]) & UI4_MASKB) >> 7) + (16258 << 48)) |
  1346.               ((((lptr_src[0]) & UI4_MASKC) >> 8) | (UI4_MASKD)));
  1347.     if(((lptr_src[0] & 0xffffffff00000000) << 1)== 0)
  1348.       lptr_dest[0] = 0;
  1349.       }
  1350.       else
  1351.     *lptr_dest = *lptr_src;
  1352.     }
  1353.   }
  1354.   else { /* We end up here if we are doing stride based processing */
  1355.     buf1 = 0;
  1356.     for(i = 0; i < num_elm; i++) {
  1357.       dud1[0] = source[0];               /* Loop would be less efficient */
  1358.       dud1[1] = source[1];
  1359.       dud1[2] = source[2];
  1360.       dud1[3] = source[3];
  1361.  
  1362.       if((float)buf1 != 0) {
  1363.     buf2 = (((buf1 & UI4_MASKA) |
  1364.                ((buf1 & UI4_MASKB) >> 7) +
  1365.                (16258 << 48)) |     
  1366.               (((buf1 & UI4_MASKC) >> 8) | (UI4_MASKD)));
  1367.     if((buf1 << 1)== 0)
  1368.       buf2 = 0;
  1369.       }
  1370.       else
  1371.     buf2 = buf1;
  1372.  
  1373.       dest[0] = dud2[0];            /* Loop would be less efficient */
  1374.       dest[1] = dud2[1];
  1375.       dest[2] = dud2[2];
  1376.       dest[3] = dud2[3];
  1377.       dest[4] = dud2[4];
  1378.       dest[5] = dud2[5];
  1379.       dest[6] = dud2[6];
  1380.       dest[7] = dud2[7];
  1381.  
  1382.       source += source_stride;
  1383.       dest += dest_stride;
  1384.     }
  1385.   }
  1386.   return;
  1387. }
  1388.  
  1389.  
  1390. #define UO4_MASKA (0x8000000000000000)
  1391. #define UO4_MASKB (0x7fff000000000000)
  1392. #define UO4_MASKC (0x00007fffff000000)
  1393. #define UO4_MASKD (0x0000000000800000)
  1394.  
  1395. /************************************************************/
  1396. /* DFKuo4f()                                                */
  1397. /* -->Unicos routine for exporting 32 bit floats            */
  1398. /************************************************************/
  1399.  
  1400. /************************************************************
  1401.  
  1402.                      <<<< WARNING >>>>
  1403.  
  1404.     The nature of converting between 64 bit floating point
  1405.   numbers and 32 bit floating point numbers LOSES PRECISION.
  1406.   Taking a number in 64bit cray format, converting to IEEE
  1407.   (internal HDF format) and back will round the number at
  1408.   about the 7th decimal place.
  1409.  
  1410.  ************************************************************/
  1411.  
  1412. #ifdef PROTOTYPE
  1413. PRIVATE int DFKuo4f(VOIDP s, VOIDP d, uint32 num_elm, uint32 source_stride,
  1414.            uint32 dest_stride)
  1415. #else
  1416. PRIVATE int DFKuo4f(source, dest, num_elm, source_stride, dest_stride)
  1417. uint8 * source, * dest;
  1418. uint32 num_elm, source_stride, dest_stride;
  1419. #endif /* PROTOTYPE */
  1420. {
  1421.   int fast_processing = 0;              /* By default not array processed */
  1422.   int odd_man_out = 0;                  /* By default there are even num_elm */
  1423.   register int i,j;
  1424.   long buf1;                            /* This is a temporary stride buf */
  1425.   long buf2;                            /* This is a temporary stride buf */
  1426.   uint8 * dud1 = (uint8*)&buf1;         /* Dummy pointer to buf1 for strides */
  1427.   uint8 * dud2 = (uint8*)&buf2;         /* Dummy pointer to buf2 for strides */
  1428. #ifdef PROTOTYPE
  1429.   uint8 * source = (uint8*)s;           /* Cray does not like certain   */
  1430.   uint8 * dest = (uint8*)d;             /* void and void* constructions */
  1431. #endif /* PROTOTYPE */
  1432.   long * lptr_src = (long*)source;
  1433.   long * lptr_dest = (long*)dest;
  1434.   char *FUNC="DFKuo4f";
  1435.  
  1436.   HEclear();
  1437.  
  1438.   /* Check for conversion errors */
  1439.   if(source == dest || num_elm == 0) { /* Inplace conversions not permitted */
  1440.     HERROR(DFE_BADCONV);               /* under UNICOS */
  1441.     return FAIL;                       /* No elements convert is an error   */
  1442.   }
  1443.  
  1444.   /* Find out if it is OK to use faster array processing */
  1445.   if(source_stride == 0 && dest_stride == 0) {
  1446.       fast_processing = 1;            
  1447.     if((num_elm % 2))                   /* If this is true, we have odd num */
  1448.       odd_man_out = 1;
  1449.   }
  1450.  
  1451.   if(fast_processing) {
  1452.     for(i = 0; i < (int)(num_elm/2); i++) {
  1453.       buf1 = lptr_src[0];
  1454.       buf2 = lptr_src[1];
  1455.       if(buf1 != 0) 
  1456.     buf1 = (((buf1 & UO4_MASKA) | 
  1457.          ((((buf1 & UO4_MASKB) >> 48) - 16258) << 55)) +
  1458.         (((buf1 & UO4_MASKC) + 
  1459.           ((buf1 & UO4_MASKD) << 1)) << 8));
  1460.       else
  1461.     buf1 = 0;
  1462.       if(buf2 != 0) 
  1463.     buf2 = ((((buf2 & UO4_MASKA) | 
  1464.           ((((buf2 & UO4_MASKB) >> 48) - 16258) << 55)) +
  1465.          (((buf2 & UO4_MASKC) + 
  1466.            ((buf2 & UO4_MASKD) << 1)) << 8)) >> 32);
  1467.       else
  1468.         buf2 = 0;
  1469.       lptr_dest[0] = ((buf1 & 0xffffffff00000000) | 
  1470.               (buf2 & 0x00000000ffffffff));
  1471.       lptr_src ++;
  1472.       lptr_src ++;
  1473.       lptr_dest ++;
  1474.     }
  1475.     if(odd_man_out){
  1476.       if(lptr_src[0] != 0)
  1477.     lptr_dest[0] = (((lptr_src[0] & UO4_MASKA) | 
  1478.                ((((lptr_src[0] & UO4_MASKB) >> 48) - 16258) << 55)) +
  1479.               (((lptr_src[0] & UO4_MASKC) + 
  1480.             ((lptr_src[0] & UO4_MASKD) << 1)) << 8));
  1481.       else
  1482.     lptr_dest[0] = 0;
  1483.     }
  1484.   }
  1485.   else { /* We end up here if we are doing stride based processing */
  1486.     buf1 = 0;
  1487.     for(i = 0; i < num_elm; i++) {
  1488.       dud1[0] = source[0];               /* Loop would be less efficient */
  1489.       dud1[1] = source[1];
  1490.       dud1[2] = source[2];
  1491.       dud1[3] = source[3];
  1492.       dud1[4] = source[4];
  1493.       dud1[5] = source[5];
  1494.       dud1[6] = source[6];
  1495.       dud1[7] = source[7];
  1496.       
  1497.       if((float)buf1 != 0) 
  1498.     buf2 = (((buf1 & UO4_MASKA) | 
  1499.          ((((buf1 & UO4_MASKB) >> 48) -16258) << 55)) +
  1500.         (((buf1 & UO4_MASKC) + ((buf1 & UO4_MASKD) << 1)) << 8));
  1501.       else
  1502.     buf2 = buf1;
  1503.  
  1504.       dest[0] = dud2[0];            /* Loop would be less efficient */
  1505.       dest[1] = dud2[1];
  1506.       dest[2] = dud2[2];
  1507.       dest[3] = dud2[3];
  1508.  
  1509.       source += source_stride;
  1510.       dest += dest_stride;
  1511.     }
  1512.   }
  1513.   return;
  1514. }
  1515.  
  1516. #define UI8_MASKA 0x8000000000000000
  1517. #define UI8_MASKB 0x7ff0000000000000
  1518. #define UI8_MASKC 0x000fffffffffffff
  1519. #define UI8_MASKD 0x0000000000000008
  1520. #define UI8_MASKE 0x0000800000000000
  1521.  
  1522. /************************************************************/
  1523. /* DFKui8f()                                                */
  1524. /* -->Unicos routine for importing 64 bit floats            */
  1525. /************************************************************/
  1526.  
  1527. #ifdef PROTOTYPE
  1528. PRIVATE int DFKui8f(VOIDP s, VOIDP d, uint32 num_elm, uint32 source_stride,
  1529.            uint32 dest_stride)
  1530. #else
  1531. PRIVATE int DFKui8f(source, dest, num_elm, source_stride, dest_stride)
  1532. uint8 * source, * dest;
  1533. uint32 num_elm, source_stride, dest_stride;
  1534. #endif /* PROTOTYPE */
  1535. {
  1536.   int fast_processing = 0;              /* By default not array processed */
  1537.   register int i,j;
  1538.   long buf;                             /* This is a temporary stride buf */
  1539.   uint8 * dud = (uint8*)&buf;           /* Dummy pointer to buf1 for strides */
  1540. #ifdef PROTOTYPE
  1541.   uint8 * source = (uint8*)s;           /* Cray does not like certain   */
  1542.   uint8 * dest = (uint8*)d;             /* void and void* constructions */
  1543. #endif /* PROTOTYPE*/
  1544.   long * lptr_src = (long*)source;
  1545.   long * lptr_dest = (long*)dest;
  1546.   char *FUNC="DFKui8f";
  1547.  
  1548.   HEclear();
  1549.  
  1550.   /* Check for conversion errors */
  1551.   if(source == dest || num_elm == 0) { /* Inplace conversions not permitted */
  1552.     HERROR(DFE_BADCONV);               /* under UNICOS */
  1553.     return FAIL;                       /* No elements convert is an error   */
  1554.   }
  1555.  
  1556.   /* Find out if it is OK to use faster array processing */
  1557.   if(source_stride == 0 && dest_stride == 0) 
  1558.     fast_processing = 1;            
  1559.  
  1560.   if(fast_processing)
  1561.     for(i = 0; i < num_elm; i ++) {
  1562.       if (lptr_src[0] != 0) {
  1563.     lptr_dest[0] = (((lptr_src[0] & UI8_MASKA) |
  1564.              ((lptr_src[0] & UI8_MASKB) >> 4) + (15362 << 48)) |
  1565.             ((((lptr_src[0] & UI8_MASKC) + 
  1566.                ((lptr_src[0] & UI8_MASKD) << 1)) >> 5) | 
  1567.              (UI8_MASKE)) );
  1568.     if ((lptr_dest[0] << 1) == 0) 
  1569.       lptr_dest[0] = 0;
  1570.       }
  1571.       else 
  1572.     lptr_dest[0] = 0;
  1573.       lptr_src++;
  1574.       lptr_dest++;
  1575.     }
  1576.   else 
  1577.     for(i = 0; i < num_elm; i ++) {
  1578.       dud[0] = source[0];
  1579.       dud[1] = source[1];
  1580.       dud[2] = source[2];
  1581.       dud[3] = source[3];
  1582.       dud[4] = source[4];
  1583.       dud[5] = source[5];
  1584.       dud[6] = source[6];
  1585.       dud[7] = source[7];
  1586.  
  1587.       if (buf != 0) {
  1588.     buf = (((buf & UI8_MASKA) | ((buf & UI8_MASKB) >> 4) + (15362 << 48)) |
  1589.            ((((buf & UI8_MASKC) + ((buf & UI8_MASKD) << 1)) >> 5) | 
  1590.         (UI8_MASKE)) );
  1591.     if ((buf << 1) == 0) 
  1592.       buf = 0;
  1593.       }
  1594.       else 
  1595.     buf = 0;
  1596.  
  1597.       dest[0] = dud[0];
  1598.       dest[1] = dud[1];
  1599.       dest[2] = dud[2];
  1600.       dest[3] = dud[3];
  1601.       dest[4] = dud[4];
  1602.       dest[5] = dud[5];
  1603.       dest[6] = dud[6];
  1604.       dest[7] = dud[7];
  1605.  
  1606.       source += source_stride;
  1607.       dest += dest_stride;
  1608.     }
  1609.   return;
  1610. }
  1611.  
  1612. #define UO8_MASKA 0x8000000000000000
  1613. #define UO8_MASKB 0x7fff000000000000
  1614. #define UO8_MASKC 0x00007fffffffffff
  1615.  
  1616. /************************************************************/
  1617. /* DFKuo64f()                                               */
  1618. /* -->Unicos routine for exporting 64 bit floats            */
  1619. /************************************************************/
  1620.  
  1621. #ifdef PROTOTYPE
  1622. PRIVATE int DFKuo8f(VOIDP s, VOIDP d, uint32 num_elm, uint32 source_stride,
  1623.            uint32 dest_stride)
  1624. #else
  1625. PRIVATE int DFKuo8f(source, dest, num_elm, source_stride, dest_stride)
  1626. uint8 * source, * dest;
  1627. uint32 num_elm, source_stride, dest_stride;
  1628. #endif /* PROTOTYPE */
  1629. {
  1630.   int fast_processing = 0;              /* By default not array processed */
  1631.   int odd_man_out = 0;                  /* By default there are even num_elm */
  1632.   register int i,j;
  1633.   long buf;                             /* This is a temporary stride buf */
  1634.   uint8 * dud = (uint8*)&buf;           /* Dummy pointer to buf1 for strides */
  1635. #ifdef PROTOTYPE
  1636.   uint8 * source = (uint8*)s;           /* Cray does not like certain   */
  1637.   uint8 * dest = (uint8*)d;             /* void and void* constructions */
  1638. #endif /* PROTOTYPE */
  1639.   long * lptr_src = (long*)source;
  1640.   long * lptr_dest = (long*)dest;
  1641.   char *FUNC="DFKuo8f";
  1642.  
  1643.   HEclear();
  1644.  
  1645.   /* Check for conversion errors */
  1646.   if(source == dest || num_elm == 0) { /* Inplace conversions not permitted */
  1647.     HERROR(DFE_BADCONV);               /* under UNICOS */
  1648.     return FAIL;                       /* No elements convert is an error   */
  1649.   }
  1650.  
  1651.   /* Find out if it is OK to use faster array processing */
  1652.   if(source_stride == 0 && dest_stride == 0)
  1653.       fast_processing = 1;            
  1654.  
  1655.   if(fast_processing)
  1656.     for(i = 0; i < num_elm; i ++) {
  1657.       if (lptr_src[0] != 0) 
  1658.     lptr_dest[0] = (((lptr_src[0] & UO8_MASKA) |
  1659.              (((((lptr_src[0] & UO8_MASKB) >> 48) - 15362) << 53) >> 1)) +
  1660.             ((lptr_src[0] & UO8_MASKC) << 5));
  1661.       else 
  1662.     lptr_dest[0] = 0;
  1663.       lptr_src++;
  1664.       lptr_dest++;
  1665.     }
  1666.   else 
  1667.     for(i = 0; i < num_elm; i ++) {
  1668.       dud[0] = source[0];
  1669.       dud[1] = source[1];
  1670.       dud[2] = source[2];
  1671.       dud[3] = source[3];
  1672.       dud[4] = source[4];
  1673.       dud[5] = source[5];
  1674.       dud[6] = source[6];
  1675.       dud[7] = source[7];
  1676.  
  1677.       if (buf != 0) {
  1678.     buf = (((buf & UO8_MASKA) |                             /* sign bit */
  1679.         (((((buf & UO8_MASKB) >> 48) - 15362) << 53) >> 1)) |   /* exp */
  1680.            ((buf & UO8_MASKC) << 5));                       /* mantissa */
  1681.       }
  1682.       else 
  1683.     buf = 0;
  1684.  
  1685.       dest[0] = dud[0];
  1686.       dest[1] = dud[1];
  1687.       dest[2] = dud[2];
  1688.       dest[3] = dud[3];
  1689.       dest[4] = dud[4];
  1690.       dest[5] = dud[5];
  1691.       dest[6] = dud[6];
  1692.       dest[7] = dud[7];
  1693.  
  1694.       source += source_stride;
  1695.       dest += dest_stride;
  1696.     }
  1697.   return;
  1698. }
  1699.  
  1700. #endif /* UNICOS */
  1701.  
  1702. #if defined(VMS)
  1703.  
  1704. /************************************************************/
  1705. /* NUMBER CONVERSION ROUTINES FOR VAX ARCHITECTURES         */
  1706. /* Most of the VAX number types can be handled with the     */
  1707. /* generic byte swapping routines.  Only the floating point */
  1708. /* conversion routines need to be customized.               */
  1709. /************************************************************/
  1710.  
  1711. /************************************************************/
  1712. /* DFKvi4f()                                                */
  1713. /* --> Import routine for 4 byte VAX floats                 */
  1714. /************************************************************/
  1715. #ifdef PROTOTYPE
  1716. PRIVATE int DFKvi4f(VOIDP s, VOIDP d, uint32 num_elm, uint32 source_stride,
  1717.            uint32 dest_stride)
  1718. #else
  1719. PRIVATE int DFKvi4f(source, dest, num_elm, source_stride, dest_stride)
  1720. uint8 * source, * dest;
  1721. uint32 num_elm, source_stride, dest_stride;
  1722. #endif /* PROTOTYPE */
  1723. {
  1724.   int in_place = 0;                     /* Inplace must be detected */
  1725.   register uint32 i;            
  1726.   uint8 buf[4];                          /* Inplace processing buffer */
  1727. #ifdef PROTOTYPE
  1728.   uint8 * source = (uint8*)s;
  1729.   uint8 * dest = (uint8*)d;
  1730. #endif /* PROTOTYPE */
  1731.   char *FUNC="DFKvi4f";
  1732.   uint8 exp;
  1733.  
  1734.   HEclear();
  1735.  
  1736.   if(source == dest)
  1737.       in_place = TRUE;
  1738.  
  1739.   if(num_elm == 0 || in_place){   /* No elements is an error as is in place. */
  1740.     HERROR(DFE_BADCONV);
  1741.     return FAIL;
  1742.   }
  1743.  
  1744.   if(source_stride == 0 && dest_stride == 0)
  1745.       source_stride = dest_stride = 4;
  1746.  
  1747.   for(i = 0; i < num_elm; i++) {
  1748.  
  1749.       /* extract exponent */
  1750.       exp = (source[0] << 1) | (source[1] >> 7); 
  1751.       if (exp) {       
  1752.           /* 
  1753.            * non-zero exponent 
  1754.            */
  1755.  
  1756.           /* copy mantissa, last bit of exponent */
  1757.           dest[0] = source[1];
  1758.           dest[2] = source[3];
  1759.           dest[3] = source[2];
  1760.           if (exp < 254) 
  1761.               /* normal value */
  1762.               dest[1] = source[0] + (uint8)1;   /* actually adds two to exp */
  1763.           else {                              
  1764.               /* infinity or NaN */
  1765.               if (exp == 254)                      /* unrepresentable - OFL */
  1766.                   /* set mant = 0 for overflow */
  1767.                   dest[0] = dest[1] = dest[2] = dest[3] = 0;
  1768.               dest[0] &= 0x7f;              /* set last bit of exp to 0 */
  1769.               dest[1] = 0x80;               /* sign=1 exp=0 -> OFL or NaN */
  1770.           }
  1771.       }
  1772.       else if (source[1] & 0x60) {               /* denormalized value */
  1773.           register int shft;
  1774.           
  1775.           shft = (source[1] & 0x40) ? 1 : 2;  /* shift needed to normalize */
  1776.           /* shift mantissa */
  1777.           /* note last bit of exp set to 1 implicitly */
  1778.           dest[0] = (uint8)(source[1] << shft) 
  1779.               | (uint8)(source[2] >> (8-shft));
  1780.           dest[3] = (uint8)(source[2] << shft) 
  1781.               | (uint8)(source[3] >> (8-shft));
  1782.           dest[2] = (uint8)(source[3] << shft);
  1783.           dest[1] = (uint8)(source[0] & 0x80);    /* sign */
  1784.           if (shft==1) {                          /* set exp to 2 */
  1785.             dest[1] |= 0x01;
  1786.             dest[0] &= 0x7f;                  /* set LSB of exp to 0 */
  1787.           }
  1788.       }
  1789.       else dest[0] = dest[1] = dest[2] = dest[3] = 0;
  1790.       
  1791.       source += source_stride;
  1792.       dest   += dest_stride;
  1793.   }
  1794.  
  1795.  
  1796.   return 0;
  1797.  
  1798. #ifdef DFKIT
  1799.     for (i=0; i<size; i++)
  1800.       {
  1801.           /* extract exponent */
  1802.           exp = (uint8)(in[i].c[0] << 1) | (uint8)(in[i].c[1] >> 7); 
  1803.           if (exp) {                                  /* non-zero exponent */
  1804.               /* copy mantissa, last bit of exponent */
  1805.               out[i].c[0] = in[i].c[1];
  1806.               out[i].c[2] = in[i].c[3];
  1807.               out[i].c[3] = in[i].c[2];
  1808.               if (exp<254)                        /* normal value */
  1809.                   out[i].c[1] = in[i].c[0] + (uint8)1;   /* adds two to exp */
  1810.               else {                           /* infinity or NaN */
  1811.                   if (exp==254)                /* unrepresentable - OFL */
  1812.                       out[i].i = 0;            /* set mant=0 for overflow */
  1813.                   out[i].c[0] &= 0x7f;         /* set last bit of exp to 0 */
  1814.                   out[i].c[1] = 0x80;          /* sign=1 exp=0 -> OFL or NaN */
  1815.               }
  1816.           }
  1817.           else if (in[i].c[1] & 0x60) {        /* denormalized value */
  1818.               register int shft;
  1819.     
  1820.               /* shift needed to normalize */
  1821.               shft = (in[i].c[1] & 0x40) ? 1 : 2;  
  1822.  
  1823.               /* shift mantissa */
  1824.               /* note last bit of exp set to 1 implicitly */
  1825.               out[i].c[0] = (uint8)(in[i].c[1] << shft) 
  1826.                   | (uint8)(in[i].c[2] >> (8-shft));
  1827.               out[i].c[3] = (uint8)(in[i].c[2] << shft) 
  1828.                   | (uint8)(in[i].c[3] >> (8-shft));
  1829.               out[i].c[2] = (uint8)(in[i].c[3] << shft);
  1830.               out[i].c[1] = (uint8)(in[i].c[0] & 0x80);          /* sign */
  1831.               if (shft==1) {                        /* set exp to 2 */
  1832.                   out[i].c[1] |= 0x01;
  1833.                   out[i].c[0] &= 0x7f;              /* set LSB of exp to 0 */
  1834.               }
  1835.           }
  1836.           else out[i].i = 0;                        /* zero */
  1837.       }
  1838.     return(0);
  1839. #endif /* DFKIT */
  1840.  
  1841. }
  1842.  
  1843. /************************************************************/
  1844. /* DFKvo4f()                                                */
  1845. /* --> Export routine for 4 byte VAX floats                 */
  1846. /************************************************************/
  1847. #ifdef PROTOTYPE 
  1848. PRIVATE int DFKvo4f(VOIDP s, VOIDP d, uint32 num_elm, uint32 source_stride,
  1849.            uint32 dest_stride)
  1850. #else
  1851. PRIVATE int DFKvo4f(source, dest, num_elm, source_stride, dest_stride)
  1852. uint8 * source, * dest;
  1853. uint32 num_elm, source_stride, dest_stride;
  1854. #endif /* PROTOTYPE */
  1855. {
  1856.   int in_place = 0;                     /* Inplace must be detected */
  1857.   register uint32 i;            
  1858.   uint8 buf[4];                          /* Inplace processing buffer */
  1859. #ifdef PROTOTYPE
  1860.   uint8 * source = (uint8*)s;
  1861.   uint8 * dest = (uint8*)d;
  1862. #endif /* PROTOTYPE */
  1863.   char *FUNC="DFKvo4f";
  1864.   intn  exp;
  1865.  
  1866.   HEclear();
  1867.  
  1868.   if(source == dest) 
  1869.       in_place = TRUE;
  1870.  
  1871.   if(num_elm == 0 || in_place){  /* No elements is an error as is in place*/
  1872.     HERROR(DFE_BADCONV);
  1873.     return FAIL;
  1874.   }
  1875.  
  1876.   if(source_stride == 0 && dest_stride == 0)
  1877.       source_stride = dest_stride = 4;
  1878.  
  1879.   for(i = 0; i < num_elm; i++) {
  1880.       
  1881.       /* extract exponent */
  1882.       exp = (source[1] << 1) | (source[0] >> 7); 
  1883.  
  1884.       if(!exp && !source[1]) {
  1885.           /* 
  1886.            * zero value 
  1887.            */
  1888.           dest[0] = dest[1] = dest[2] = dest[3] = 0;
  1889.       }
  1890.       else if(exp > 2) {
  1891.           /*
  1892.            * Normal value
  1893.            */
  1894.  
  1895.           dest[0] = source[1] - (uint8)1; /* subtracts 2 from exponent */
  1896.           /* copy mantissa, LSB of exponent */
  1897.           dest[1] = source[0];
  1898.           dest[2] = source[3];
  1899.           dest[3] = source[2];
  1900.  
  1901.       }
  1902.       else if(exp) {
  1903.           register intn shft;
  1904.           /* 
  1905.            * denormalized number 
  1906.            */
  1907.  
  1908.           /* keep sign, zero exponent */
  1909.           dest[0] = source[1] & 0x80;
  1910.  
  1911.           shft = 3 - exp;
  1912.  
  1913.           /* shift original mant by 1 or 2 to get denormalized mant */
  1914.           /* prefix mantissa with '1'b or '01'b as appropriate */
  1915.           dest[1] = (uint8)((source[0] & 0x7f) >> shft) 
  1916.               | (uint8)(0x10 << exp);
  1917.           dest[2] = (uint8)(source[0] << (8-shft)) 
  1918.               | (uint8)(source[3] >> shft);
  1919.           dest[3] = (uint8)(source[3] << (8-shft)) 
  1920.               | (uint8)(source[2] >> shft);  
  1921.       }
  1922.       else {
  1923.           /* 
  1924.            * sign=1 -> infinity or NaN 
  1925.            */
  1926.           
  1927.           dest[0] = 0xff;                /* set exp to 255 */
  1928.           /* copy mantissa */
  1929.           dest[1] = source[0] | (uint8)0x80;  /* LSB of exp = 1 */
  1930.           dest[2] = source[3];
  1931.           dest[3] = source[2];
  1932.       }
  1933.       
  1934.       source += source_stride;
  1935.       dest   += dest_stride;
  1936.   }
  1937.   
  1938.   return 0;
  1939.  
  1940. #ifdef DFKIT
  1941.    uint8 exp;
  1942.     int i;
  1943.  
  1944.     for (i=0; i<size; i++) {
  1945.         /* extract exponent */
  1946.         exp = (uint8)(in[i].c[1] << 1) | (uint8)(in[i].c[0] >> 7);  
  1947.         if (!exp && !in[i].c[1]) out[i].i = 0;        /* zero value */
  1948.         else if (exp>2) {                               /* normal value */
  1949.             out[i].c[0] = in[i].c[1] - (uint8)1; /* subtracts 2 from expent */
  1950.             /* copy mantissa, LSB of exponent */
  1951.             out[i].c[1] = in[i].c[0];
  1952.             out[i].c[2] = in[i].c[3];
  1953.             out[i].c[3] = in[i].c[2];
  1954.         }
  1955.         else if (exp) {                          /* denormalized number */
  1956.             register int shft;
  1957.  
  1958.             /* keep sign, zero exponent */
  1959.             out[i].c[0] = in[i].c[1] & (uint8)0x80; 
  1960.             shft = 3 - exp;
  1961.             /* shift original mant by 1 or 2 to get denormalized mant */
  1962.             /* prefix mantissa with '1'b or '01'b as appropriate */
  1963.             out[i].c[1] = (uint8)((in[i].c[0] & 0x7f) >> shft) 
  1964.                 | (uint8)(0x10 << exp);
  1965.             out[i].c[2] = (uint8)(in[i].c[0] << (8-shft)) 
  1966.                 | (uint8)(in[i].c[3] >> shft);
  1967.             out[i].c[3] = (uint8)(in[i].c[3] << (8-shft)) 
  1968.                 | (uint8)(in[i].c[2] >> shft);
  1969.         }
  1970.         else {                                 /* sign=1 -> infinity or NaN */
  1971.             out[i].c[0] = 0xff;                /* set exp to 255 */
  1972.                 /* copy mantissa */
  1973.             out[i].c[1] = in[i].c[0] | (uint8)0x80;  /* LSB of exp = 1 */
  1974.             out[i].c[2] = in[i].c[3];
  1975.             out[i].c[3] = in[i].c[2];
  1976.         }
  1977.     }
  1978.     return(0);
  1979.  
  1980. #endif /* DFKIT */
  1981.  
  1982. }
  1983.  
  1984. /*
  1985.  * Define structures to encode and decode Vax numbers
  1986.  * The following code is based on the methods of reading / writing
  1987.  *  doubles from Vaxen developed by Sun Microsystems as part of
  1988.  *  the XDR library.
  1989.  */
  1990.  
  1991. /* How an IEEE double looks */
  1992. struct  ieee_double {
  1993.     unsigned int   mantissa1 : 20;
  1994.     unsigned int   exp       : 11;
  1995.     unsigned int   sign      : 1;
  1996.     unsigned int   mantissa2 : 32;
  1997. };
  1998.  
  1999. /* How a Vax double looks */
  2000. struct  vax_double {
  2001.     unsigned int    mantissa1 : 7;
  2002.     unsigned int    exp       : 8;
  2003.     unsigned int    sign      : 1;
  2004.     unsigned int    mantissa2 : 16;
  2005.     unsigned int    mantissa3 : 16;
  2006.     unsigned int    mantissa4 : 16;
  2007. };
  2008.  
  2009. #define VAX_DBL_BIAS   0x81
  2010. #define IEEE_DBL_BIAS  0x3ff
  2011. #define MASK(nbits)    ((1 << nbits) - 1)
  2012.  
  2013. struct dbl_limits {
  2014.     struct vax_double  vaxx;
  2015.     struct ieee_double ieee;
  2016. };
  2017.  
  2018. static struct dbl_limits dbl_lim[2] = {
  2019.     {{ 0x7f,  0xff, 0x0, 0xffff, 0xffff, 0xfff},  /* Max Vax */
  2020.      { 0x0,  0x7ff, 0x0, 0x0 }},                  /* Max IEEE */
  2021.     {{ 0x0, 0x0, 0x0, 0x0, 0x0, 0x0},             /* Min Vax */
  2022.      { 0x0, 0x0, 0x0, 0x0 }}                      /* Min IEEE */
  2023. };
  2024.  
  2025. /************************************************************/
  2026. /* DFKvi8f()                                                */
  2027. /* --> Import routine for 8 byte VAX floats                 */
  2028. /************************************************************/
  2029. #ifdef PROTOTYPE
  2030. PRIVATE int DFKvi8f(VOIDP s, VOIDP d, uint32 num_elm, uint32 source_stride,
  2031.            uint32 dest_stride)
  2032. #else
  2033. PRIVATE int DFKvi8f(source, dest, num_elm, source_stride, dest_stride)
  2034. uint8 * source, * dest;
  2035. uint32 num_elm, source_stride, dest_stride;
  2036. #endif /* PROTOTYPE */
  2037. {
  2038.   int in_place = 0;                     /* Inplace must be detected */
  2039.   register uint32 i;            
  2040.   uint8 buf[4];                          /* Inplace processing buffer */
  2041. #ifdef PROTOTYPE
  2042.   uint8 * source = (uint8*)s;
  2043.   uint8 * dest = (uint8*)d;
  2044. #endif /* PROTOTYPE */
  2045.   char *FUNC="DFKvi8f";
  2046.   intn exp;
  2047.  
  2048.   struct ieee_double *id;
  2049.   struct vax_double  *vd;
  2050.   intn found, j;
  2051.  
  2052.   HEclear();
  2053.  
  2054.   if(source == dest)
  2055.       in_place = TRUE;
  2056.  
  2057.   if(num_elm == 0 || in_place){   /* No elements is an error as is in place. */
  2058.     HERROR(DFE_BADCONV);
  2059.     return FAIL;
  2060.   }
  2061.   
  2062.   if(source_stride == 0 && dest_stride == 0)
  2063.       source_stride = dest_stride = 8;
  2064.  
  2065.   for(i = 0; i < num_elm; i++) {
  2066.  
  2067.       id = (struct ieee_double *) source;
  2068.       vd = (struct vax_double *)  dest;
  2069.       
  2070.       found = FALSE;
  2071.       
  2072.       for(j = 0; j < 2; j++) {
  2073.           if((id->mantissa2 == dbl_lim[j].ieee.mantissa2) &&
  2074.              (id->mantissa1 == dbl_lim[j].ieee.mantissa1) &&
  2075.              (id->exp == dbl_lim[j].vaxx.exp)) {
  2076.               *vd = dbl_lim[j].vaxx;
  2077.               found = TRUE;
  2078.               break;
  2079.           }
  2080.       }
  2081.  
  2082.       if(!found) {
  2083.           vd->exp = id->exp - IEEE_DBL_BIAS + VAX_DBL_BIAS;
  2084.           vd->mantissa1 = id->mantissa1 >> 13;
  2085.           vd->mantissa2 = ((id->mantissa1 & MASK(13)) << 3) |
  2086.               (id->mantissa2 >> 29);
  2087.           vd->mantissa3 = id->mantissa2 >> 13;
  2088.           vd->mantissa4 = id->mantissa2 << 3;
  2089.       }
  2090.  
  2091.       vd->sign = id->sign;
  2092.  
  2093.       source += source_stride;
  2094.       dest   += dest_stride;
  2095.   }
  2096.  
  2097.   return 0;
  2098. }
  2099.  
  2100. /************************************************************/
  2101. /* DFKvo8f()                                                */
  2102. /* --> Export routine for 8 byte VAX floats                 */
  2103. /************************************************************/
  2104. #ifdef PROTOTYPE
  2105. PRIVATE int DFKvo8f(VOIDP s, VOIDP d, uint32 num_elm, uint32 source_stride,
  2106.            uint32 dest_stride)
  2107. #else
  2108. PRIVATE int DFKvo8f(source, dest, num_elm, source_stride, dest_stride)
  2109. uint8 * source, * dest;
  2110. uint32 num_elm, source_stride, dest_stride;
  2111. #endif /* PROTOTYPE */
  2112. {
  2113.   int in_place = 0;                     /* Inplace must be detected */
  2114.   register uint32 i;            
  2115.   uint8 buf[4];                          /* Inplace processing buffer */
  2116. #ifdef PROTOTYPE
  2117.   uint8 * source = (uint8*)s;
  2118.   uint8 * dest = (uint8*)d;
  2119. #endif /* PROTOTYPE */
  2120.   char *FUNC="DFKvo8f";
  2121.   intn exp;
  2122.  
  2123.   struct ieee_double *id;
  2124.   struct vax_double  *vd;
  2125.   intn found, j;
  2126.  
  2127.   HEclear();
  2128.  
  2129.   if(source == dest)
  2130.       in_place = TRUE;
  2131.  
  2132.   if(num_elm == 0 || in_place){   /* No elements is an error as is in place. */
  2133.     HERROR(DFE_BADCONV);
  2134.     return FAIL;
  2135.   }
  2136.  
  2137.   if(source_stride == 0 && dest_stride == 0)
  2138.       source_stride = dest_stride = 8;
  2139.  
  2140.   for(i = 0; i < num_elm; i++) {
  2141.  
  2142.       id = (struct ieee_double *) dest;
  2143.       vd = (struct vax_double *)  source;
  2144.       
  2145.       found = FALSE;
  2146.  
  2147.       for(j = 0; j < 2; j++) {
  2148.           if((vd->mantissa4 == dbl_lim[j].vaxx.mantissa4) &&
  2149.              (vd->mantissa3 == dbl_lim[j].vaxx.mantissa3) &&
  2150.              (vd->mantissa2 == dbl_lim[j].vaxx.mantissa2) &&
  2151.              (vd->mantissa1 == dbl_lim[j].vaxx.mantissa1) &&
  2152.              (vd->exp == dbl_lim[j].vaxx.exp)) {
  2153.               *id = dbl_lim[j].ieee;
  2154.               found = TRUE;
  2155.               break;
  2156.           }
  2157.       }
  2158.  
  2159.       if(!found) {
  2160.           id->exp = vd->exp - VAX_DBL_BIAS + IEEE_DBL_BIAS;
  2161.           id->mantissa1 = (vd->mantissa1 << 13) | (vd->mantissa2 >> 3);
  2162.           id->mantissa2 = ((vd->mantissa2 & MASK(3)) << 29) |
  2163.               (vd->mantissa3 << 13) |
  2164.                   ((vd->mantissa4>> 3) & MASK(13));
  2165.       }
  2166.       
  2167.       id->sign = vd->sign;
  2168.  
  2169.       source += source_stride;
  2170.       dest   += dest_stride;
  2171.   }
  2172.  
  2173.   return 0;
  2174. }
  2175. #endif /* VMS */
  2176.  
  2177. #ifdef CONVEXNATIVE
  2178.  
  2179. /****************************************************************
  2180.  * NUMBER CONVERSION ROUTINES FOR CONVEX ARCHITECTURES          *
  2181.  * Most of the CONVEX number types can be handled with the      *
  2182.  * generic routines.  Only the floating point                   *
  2183.  * conversion routines need to be customized.                   *
  2184.  * Routines written by J.W. de Bruijn,                          *
  2185.  * DELPHI project, Laboratory of Seismics and Acoustics,        *
  2186.  * Delft University of Technology.                              *
  2187.  * Based on the VAX <-> IEEE routines from NCSA.                *
  2188.  ****************************************************************/
  2189.  
  2190. /************************************************************/
  2191. /* DFKci4f()                                                */
  2192. /* --> Import routine for 4 byte CONVEX floats              */
  2193. /************************************************************/
  2194. #ifdef PROTOTYPE
  2195. PRIVATE int DFKci4f(VOIDP s, VOIDP d, uint32 num_elm, uint32 source_stride,
  2196.            uint32 dest_stride)
  2197. #else
  2198. PRIVATE int DFKci4f(source, dest, num_elm, source_stride, dest_stride)
  2199. uint8 * source, * dest;
  2200. uint32 num_elm, source_stride, dest_stride;
  2201. #endif /* PROTOTYPE */
  2202. {
  2203.   int in_place = 0;                     /* Inplace must be detected */
  2204.   register uint32 i;            
  2205.   uint8 buf[4];                          /* Inplace processing buffer */
  2206. #ifdef PROTOTYPE
  2207.   uint8 * source = (uint8*)s;
  2208.   uint8 * dest = (uint8*)d;
  2209. #endif /* PROTOTYPE */
  2210.   char *FUNC="DFKci4f";
  2211.   uint8 exp;
  2212.  
  2213.   HEclear();
  2214.  
  2215.   if(source == dest)
  2216.       in_place = TRUE;
  2217.  
  2218.   if(num_elm == 0 || in_place){   /* No elements is an error as is in place. */
  2219.     HERROR(DFE_BADCONV);
  2220.     return FAIL;
  2221.   }
  2222.  
  2223.   if(source_stride == 0 && dest_stride == 0)
  2224.       source_stride = dest_stride = 4;
  2225.  
  2226.   for(i = 0; i < num_elm; i++) {
  2227.  
  2228.       /* extract exponent */
  2229.       exp = (uint8)(source[0] << 1) | (uint8)(source[1] >> 7); 
  2230.       if (exp) {       
  2231.           /* 
  2232.            * non-zero exponent 
  2233.            */
  2234.  
  2235.           /* copy mantissa, last bit of exponent */
  2236.           dest[1] = source[1];
  2237.           dest[3] = source[3];
  2238.           dest[2] = source[2];
  2239.           if (exp < 254) 
  2240.               /* normal value */
  2241.               dest[0] = source[0] + (uint8)1;   /* actually adds two to exp */
  2242.           else {                              
  2243.               /* infinity or NaN */
  2244.               if (exp == 254)                      /* unrepresentable - OFL */
  2245.                   /* set mant = 0 for overflow */
  2246.                   dest[0] = dest[1] = dest[2] = dest[3] = 0;
  2247.               dest[1] &= 0x7f;              /* set last bit of exp to 0 */
  2248.               dest[0] = 0x80;               /* sign=1 exp=0 -> OFL or NaN */
  2249.           }
  2250.       }
  2251.       else if (source[1] & 0x60) {               /* denormalized value */
  2252.           register int shft;
  2253.           
  2254.           shft = (source[1] & 0x40) ? 1 : 2;  /* shift needed to normalize */
  2255.           /* shift mantissa */
  2256.           /* note last bit of exp set to 1 implicitly */
  2257.           dest[1] = (uint8)(source[1] << shft) | (uint8)(source[2] >> (8-shft));
  2258.           dest[2] = (uint8)(source[2] << shft) | (uint8)(source[3] >> (8-shft));
  2259.           dest[3] = (uint8)(source[3] << shft);
  2260.           dest[0] = (uint8)(source[0] & 0x80);    /* sign */
  2261.           if (shft==1) {                          /* set exp to 2 */
  2262.             dest[0] |= 0x01;
  2263.             dest[1] &= 0x7f;                  /* set LSB of exp to 0 */
  2264.           }
  2265.       }
  2266.       else dest[0] = dest[1] = dest[2] = dest[3] = 0;
  2267.       
  2268.       source += source_stride;
  2269.       dest   += dest_stride;
  2270.   }
  2271.  
  2272.   return 0;
  2273.  
  2274. }
  2275.  
  2276. /************************************************************/
  2277. /* DFKco4f()                                                */
  2278. /* --> Export routine for 4 byte CONVEX floats              */
  2279. /************************************************************/
  2280. #ifdef PROTOTYPE 
  2281. PRIVATE int DFKco4f(VOIDP s, VOIDP d, uint32 num_elm, uint32 source_stride,
  2282.            uint32 dest_stride)
  2283. #else
  2284. PRIVATE int DFKco4f(source, dest, num_elm, source_stride, dest_stride)
  2285. uint8 * source, * dest;
  2286. uint32 num_elm, source_stride, dest_stride;
  2287. #endif /* PROTOTYPE */
  2288. {
  2289.   int in_place = 0;                     /* Inplace must be detected */
  2290.   register uint32 i;            
  2291.   uint8 buf[4];                          /* Inplace processing buffer */
  2292. #ifdef PROTOTYPE
  2293.   uint8 * source = (uint8*)s;
  2294.   uint8 * dest = (uint8*)d;
  2295. #endif /* PROTOTYPE */
  2296.   char *FUNC="DFKco4f";
  2297.   intn  exp;
  2298.  
  2299.   HEclear();
  2300.  
  2301.   if(source == dest) 
  2302.       in_place = TRUE;
  2303.  
  2304.   if(num_elm == 0 || in_place){  /* No elements is an error as is in place*/
  2305.     HERROR(DFE_BADCONV);
  2306.     return FAIL;
  2307.   }
  2308.  
  2309.   if(source_stride == 0 && dest_stride == 0)
  2310.       source_stride = dest_stride = 4;
  2311.  
  2312.   for(i = 0; i < num_elm; i++) {
  2313.       
  2314.       /* extract exponent */
  2315.       exp = (source[0] << 1) | (source[1] >> 7); 
  2316.  
  2317.       if(!exp && !source[0]) {
  2318.           /* 
  2319.            * zero value 
  2320.            */
  2321.           dest[0] = dest[1] = dest[2] = dest[3] = 0;
  2322.       }
  2323.       else if(exp > 2) {
  2324.           /*
  2325.            * Normal value
  2326.            */
  2327.  
  2328.           dest[0] = source[0] - (uint8)1; /* subtracts 2 from exponent */
  2329.           /* copy mantissa, LSB of exponent */
  2330.           dest[1] = source[1];
  2331.           dest[2] = source[2];
  2332.           dest[3] = source[3];
  2333.  
  2334.       }
  2335.       else if(exp) {
  2336.           register intn shft;
  2337.           /* 
  2338.            * denormalized number 
  2339.            */
  2340.  
  2341.           /* keep sign, zero exponent */
  2342.           dest[0] = source[0] & 0x80;
  2343.  
  2344.           shft = 3 - exp;
  2345.  
  2346.           /* shift original mant by 1 or 2 to get denormalized mant */
  2347.           /* prefix mantissa with '1'b or '01'b as appropriate */
  2348.           dest[1] = (uint8)((source[1] & 0x7f) >> shft) | (uint8)(0x10 << exp);
  2349.           dest[2] = (uint8)(source[1] << (8-shft)) | (uint8)(source[2] >> shft);
  2350.           dest[3] = (uint8)(source[2] << (8-shft)) | (uint8)(source[3] >> shft);  
  2351.       }
  2352.       else {
  2353.           /* 
  2354.            * sign=1 -> infinity or NaN 
  2355.            */
  2356.           
  2357.           dest[0] = 0xff;                /* set exp to 255 */
  2358.           /* copy mantissa */
  2359.           dest[1] = source[1] | (uint8)0x80;  /* LSB of exp = 1 */
  2360.           dest[2] = source[2];
  2361.           dest[3] = source[3];
  2362.       }
  2363.       
  2364.       source += source_stride;
  2365.       dest   += dest_stride;
  2366.   }
  2367.   
  2368.   return 0;
  2369.  
  2370. }
  2371.  
  2372. /************************************************************/
  2373. /* DFKci8f()                                                */
  2374. /* --> Import routine for 8 byte CONVEX floats              */
  2375. /************************************************************/
  2376. #ifdef PROTOTYPE
  2377. PRIVATE int DFKci8f(VOIDP s, VOIDP d, uint32 num_elm, uint32 source_stride,
  2378.            uint32 dest_stride)
  2379. #else
  2380. PRIVATE int DFKci8f(source, dest, num_elm, source_stride, dest_stride)
  2381. uint8 * source, * dest;
  2382. uint32 num_elm, source_stride, dest_stride;
  2383. #endif /* PROTOTYPE */
  2384. {
  2385.   int in_place = 0;                     /* Inplace must be detected */
  2386.   register uint32 i;            
  2387.   uint8 buf[8];                          /* Inplace processing buffer */
  2388. #ifdef PROTOTYPE
  2389.   uint8 * source = (uint8*)s;
  2390.   uint8 * dest = (uint8*)d;
  2391. #endif /* PROTOTYPE */
  2392.   char *FUNC="DFKci8f";
  2393.   intn exp;
  2394.  
  2395.   HEclear();
  2396.  
  2397.   if(source == dest)
  2398.       in_place = TRUE;
  2399.  
  2400.   if(num_elm == 0 || in_place){   /* No elements is an error as is in place. */
  2401.     HERROR(DFE_BADCONV);
  2402.     return FAIL;
  2403.   }
  2404.  
  2405.   if(source_stride == 0 && dest_stride == 0)
  2406.       source_stride = dest_stride = 8;
  2407.  
  2408.   for(i = 0; i < num_elm; i++) {
  2409.  
  2410.       /* extract exponent */
  2411.       exp = (source[0] << 1) | (source[1] >> 4); 
  2412.       if (exp) {       
  2413.           /* 
  2414.            * non-zero exponent 
  2415.            */
  2416.  
  2417.           /* copy mantissa, sign and first bits of exponent */
  2418.           dest[2] = source[2];
  2419.           dest[3] = source[3];
  2420.           dest[4] = source[4];
  2421.           dest[5] = source[5];
  2422.           dest[6] = source[6];
  2423.           dest[7] = source[7];
  2424.           dest[0] = source[0];
  2425.           if (exp < 2046) {
  2426.               /* normal value */
  2427.           dest[1] = source[1] + 0x20;    /* add two to exp */
  2428.           if (dest[1] < 0x20) dest[0] += 1;    /* carry */
  2429.       }
  2430.           else {                              
  2431.               /* infinity or NaN */
  2432.               if (exp == 2046)                      /* unrepresentable - OFL */
  2433.                   /* set mant = 0 for overflow */
  2434.                   dest[0] = dest[1] = dest[2] = dest[3] = 0;
  2435.               dest[0] = 0x80;               /* sign=1 exp=0 -> OFL or NaN */
  2436.               dest[1] &= 0x0f;              /* set last bit of exp to 0 */
  2437.           }
  2438.       }
  2439.       else if (source[1] & 0x0C) {               /* denormalized value */
  2440.           register int shft;
  2441.           
  2442.           shft = (source[1] & 0x08) ? 1 : 2;  /* shift needed to normalize */
  2443.           /* shift mantissa */
  2444.           /* note last bit of exp set to 1 implicitly */
  2445.           dest[1] = (uint8)(source[1] << shft) | (uint8)(source[2] >> (8-shft));
  2446.           dest[2] = (uint8)(source[2] << shft) | (uint8)(source[3] >> (8-shft));
  2447.           dest[3] = (uint8)(source[3] << shft) | (uint8)(source[4] >> (8-shft));
  2448.           dest[4] = (uint8)(source[4] << shft) | (uint8)(source[5] >> (8-shft));
  2449.           dest[5] = (uint8)(source[5] << shft) | (uint8)(source[6] >> (8-shft));
  2450.           dest[6] = (uint8)(source[6] << shft) | (uint8)(source[7] >> (8-shft));
  2451.           dest[7] = (uint8)(source[7] << shft);
  2452.           dest[0] = (uint8)(source[0] & 0x80);    /* sign */
  2453.           if (shft==1) {                          /* set exp to 2 */
  2454.             dest[1] |= 0x20;                  /* set LSB of exp to 0 */
  2455.           }
  2456.       }
  2457.       else {
  2458.           dest[0] = dest[1] = dest[2] = dest[3] = 0;
  2459.           dest[4] = dest[5] = dest[6] = dest[7] = 0;
  2460.       }
  2461.       
  2462.       source += source_stride;
  2463.       dest   += dest_stride;
  2464.   }
  2465.  
  2466.  
  2467.   return 0;
  2468.  
  2469. }
  2470.  
  2471. /************************************************************/
  2472. /* DFKco8f()                                                */
  2473. /* --> Export routine for 8 byte CONVEX floats              */
  2474. /************************************************************/
  2475. #ifdef PROTOTYPE 
  2476. PRIVATE int DFKco8f(VOIDP s, VOIDP d, uint32 num_elm, uint32 source_stride,
  2477.            uint32 dest_stride)
  2478. #else
  2479. PRIVATE int DFKco8f(source, dest, num_elm, source_stride, dest_stride)
  2480. uint8 * source, * dest;
  2481. uint32 num_elm, source_stride, dest_stride;
  2482. #endif /* PROTOTYPE */
  2483. {
  2484.   int in_place = 0;                     /* Inplace must be detected */
  2485.   register uint32 i;            
  2486.   uint8 buf[8];                          /* Inplace processing buffer */
  2487. #ifdef PROTOTYPE
  2488.   uint8 * source = (uint8*)s;
  2489.   uint8 * dest = (uint8*)d;
  2490. #endif /* PROTOTYPE */
  2491.   char *FUNC="DFKco8f";
  2492.   intn  exp;
  2493.  
  2494.   HEclear();
  2495.  
  2496.   if(source == dest) 
  2497.       in_place = TRUE;
  2498.  
  2499.   if(num_elm == 0 || in_place){  /* No elements is an error as is in place*/
  2500.     HERROR(DFE_BADCONV);
  2501.     return FAIL;
  2502.   }
  2503.  
  2504.   if(source_stride == 0 && dest_stride == 0)
  2505.       source_stride = dest_stride = 8;
  2506.  
  2507.   for(i = 0; i < num_elm; i++) {
  2508.       
  2509.       /* extract exponent */
  2510.       exp = (source[0] << 1) | (source[1] >> 4); 
  2511.  
  2512.       if(!exp && !source[0]) {
  2513.           /* 
  2514.            * zero value 
  2515.            */
  2516.           dest[0] = dest[1] = dest[2] = dest[3] = 0;
  2517.           dest[4] = dest[5] = dest[6] = dest[7] = 0;
  2518.       }
  2519.       else if(exp > 2) {
  2520.           /*
  2521.            * Normal value
  2522.            */
  2523.           /* copy sign, MSBs of exponent */
  2524.           dest[0] = source[0];
  2525.       dest[1] = source[1] - 0x20;    /* subtracts 2 from exponent */
  2526.           /* copy mantissa */
  2527.           dest[2] = source[2];
  2528.           dest[3] = source[3];
  2529.           dest[4] = source[4];
  2530.           dest[5] = source[5];
  2531.           dest[6] = source[6];
  2532.           dest[7] = source[7];
  2533.       }
  2534.       else if(exp) {
  2535.           register intn shft;
  2536.           /* 
  2537.            * denormalized number 
  2538.            */
  2539.  
  2540.           /* keep sign, zero exponent */
  2541.           dest[0] = source[0] & 0x80;
  2542.  
  2543.           shft = 3 - exp;
  2544.  
  2545.           /* shift original mant by 1 or 2 to get denormalized mant */
  2546.           /* prefix mantissa with '1'b or '01'b as appropriate */
  2547.           dest[1] = (uint8)((source[1] & 0x0f) >> shft) | (uint8)(0x02 << exp);
  2548.           dest[2] = (uint8)(source[1] << (8-shft)) | (uint8)(source[2] >> shft);
  2549.           dest[3] = (uint8)(source[2] << (8-shft)) | (uint8)(source[3] >> shft);  
  2550.           dest[4] = (uint8)(source[3] << (8-shft)) | (uint8)(source[4] >> shft);  
  2551.           dest[5] = (uint8)(source[4] << (8-shft)) | (uint8)(source[5] >> shft);  
  2552.           dest[6] = (uint8)(source[5] << (8-shft)) | (uint8)(source[6] >> shft);  
  2553.           dest[7] = (uint8)(source[6] << (8-shft)) | (uint8)(source[7] >> shft);  
  2554.       }
  2555.       else {
  2556.           /* 
  2557.            * sign=1 -> infinity or NaN 
  2558.            */
  2559.           
  2560.           dest[0] = 0xff;                /* set exp to 255 */
  2561.           /* copy mantissa */
  2562.           dest[1] = source[1] | (uint8)0xF0;  /* LSBs of exp = 1 */
  2563.           dest[2] = source[2];
  2564.           dest[3] = source[3];
  2565.           dest[4] = source[4];
  2566.           dest[5] = source[5];
  2567.           dest[6] = source[6];
  2568.           dest[7] = source[7];
  2569.       }
  2570.       
  2571.       source += source_stride;
  2572.       dest   += dest_stride;
  2573.   }
  2574.   
  2575.   return 0;
  2576.  
  2577. }
  2578. #endif  /* CONVEXNATIVE */
  2579.  
  2580. /************************************************************
  2581.  * If the programmer forgot to call DFKsetntype, then let
  2582.  * them know about it.
  2583.  * Should this be PUBLIC or PRIVATE
  2584.  ************************************************************/
  2585. #ifdef PROTOTYPE
  2586. PRIVATE int DFKInoset(VOIDP source, VOIDP dest, uint32 num_elm, 
  2587.     uint32 source_stride, uint32 dest_stride)
  2588. #else
  2589. PRIVATE int DFKInoset(source, dest, num_elm, source_stride, dest_stride)
  2590. uint8 * source, * dest;
  2591. uint32 num_elm, source_stride, dest_stride;
  2592. #endif /* PROTOTYPE */
  2593. {
  2594.   char *FUNC="DFKInoset";
  2595.  
  2596.   HEclear();
  2597.  
  2598.     /* shut the compiler up about not using the arguments */
  2599.     source=source;
  2600.     dest=dest;
  2601.     num_elm=num_elm;
  2602.     source_stride=source_stride;
  2603.     dest_stride=dest_stride;
  2604.  
  2605.   /* If this is causing a problem for you, call DFKsetntype */
  2606.   HERROR(DFE_BADCONV);
  2607.   return FAIL;
  2608. }
  2609.  
  2610.  
  2611. /*****************************************************************************
  2612.  * Routines that depend on the above information
  2613.  *****************************************************************************/
  2614.  
  2615. PRIVATE int32 g_ntype = DFNT_NONE;   /* Holds current number type. */
  2616.                                     /* Initially not set.         */
  2617.  
  2618. /************************************************************ 
  2619. * DFKqueryNT()
  2620. *   Determine the current conversion settings 
  2621.  ************************************************************/
  2622. PUBLIC
  2623. #ifdef PROTOTYPE
  2624. int32 DFKqueryNT(void) 
  2625. #else
  2626. int32 DFKqueryNT()
  2627. #endif /* PROTOTYPE */
  2628. {
  2629.   return g_ntype;
  2630. }
  2631.  
  2632. /************************************************************
  2633.  * DFKNTsize()
  2634.  *   Determine the size, given the number type
  2635.  ************************************************************/
  2636. PUBLIC
  2637. #ifdef PROTOTYPE
  2638. int DFKNTsize(int32 number_type)
  2639. #else
  2640. DFKNTsize(number_type)
  2641. int number_type;
  2642. #endif /* PROTOTYPE */
  2643. {
  2644.     char *FUNC="DFKNTsize";
  2645.  
  2646.     switch ((int32) number_type)  {
  2647.             case DFNT_NUCHAR:    return(SIZE_NUCHAR);
  2648.             case DFNT_NCHAR:    return(SIZE_NCHAR);
  2649.             case DFNT_NINT8:    return(SIZE_NINT8);
  2650.             case DFNT_NUINT8:   return(SIZE_NUINT8);
  2651.  
  2652.             case DFNT_NINT16:    return(SIZE_NINT16);
  2653.             case DFNT_NUINT16:  return(SIZE_NUINT16);
  2654.  
  2655.             case DFNT_NINT32:   return(SIZE_NINT32);
  2656.             case DFNT_NUINT32:  return(SIZE_NUINT32);
  2657.  
  2658.             case DFNT_NFLOAT32: return(SIZE_NFLOAT32);
  2659.  
  2660.             case DFNT_NFLOAT64: return(SIZE_NFLOAT64);
  2661.  
  2662.             case DFNT_UCHAR:    return(SIZE_UCHAR);
  2663.             case DFNT_CHAR:     return(SIZE_CHAR);
  2664.             case DFNT_INT8:     return(SIZE_INT8);
  2665.             case DFNT_UINT8:    return(SIZE_UINT8);
  2666.  
  2667.             case DFNT_INT16:    return(SIZE_INT16);
  2668.             case DFNT_UINT16:   return(SIZE_UINT16);
  2669.  
  2670.             case DFNT_INT32:    return(SIZE_INT32);
  2671.             case DFNT_UINT32:   return(SIZE_UINT32);
  2672.  
  2673.             case DFNT_FLOAT32:  return(SIZE_FLOAT32);
  2674.  
  2675.             case DFNT_FLOAT64:  return(SIZE_FLOAT64);
  2676.  
  2677.             default: break;
  2678.       }    /* switch    */
  2679.           /* hdf default format   */
  2680.   return FAIL;
  2681. }
  2682.  
  2683. /************************************************************
  2684.  * DFKsetNT()
  2685.  *   Set the number type for future conversion calls
  2686.  ************************************************************/
  2687. PUBLIC
  2688. #ifdef PROTOTYPE
  2689. intn DFKsetNT(int32 ntype)
  2690. #else
  2691. intn DFKsetNT(ntype)
  2692. int32 ntype;
  2693. #endif /* PROTOTYPE */
  2694. {
  2695.   char *FUNC="DFKsetNT";
  2696.  
  2697.   HEclear();
  2698.  
  2699.   g_ntype = ntype;
  2700.  
  2701.   switch(ntype) {
  2702.     case DFNT_CHAR8:
  2703.     case DFNT_UCHAR8:
  2704.     case DFNT_INT8:    
  2705.     case DFNT_UINT8:   DFKnumin  = UI8_IN;
  2706.                        DFKnumout = UI8_OUT;
  2707.                        return 0;
  2708.     case DFNT_INT16:   DFKnumin  = SI16_IN;
  2709.                        DFKnumout = SI16_OUT;
  2710.                        return 0;
  2711.     case DFNT_UINT16:  DFKnumin  = UI16_IN;
  2712.                        DFKnumout = UI16_OUT;
  2713.                        return 0;
  2714.     case DFNT_INT32:   DFKnumin  = SI32_IN;
  2715.                        DFKnumout = SI32_OUT;
  2716.                        return 0;
  2717.     case DFNT_UINT32:  DFKnumin  = UI32_IN;
  2718.                        DFKnumout = UI32_OUT;
  2719.                        return 0;
  2720.     case DFNT_FLOAT32: DFKnumin  = F32_IN;
  2721.                        DFKnumout = F32_OUT;
  2722.                        return 0;
  2723.     case DFNT_FLOAT64: DFKnumin  = F64_IN;
  2724.                        DFKnumout = F64_OUT;
  2725.                        return 0;
  2726.  
  2727.     /* 
  2728.      * NATIVE MODE 'CONVERSIONS'
  2729.      */
  2730.     case DFNT_NCHAR: 
  2731.     case DFNT_NINT8:
  2732.     case DFNT_NUCHAR:
  2733.     case DFNT_NUINT8:   DFKnumin  = NUI8_IN;
  2734.                         DFKnumout = NUI8_OUT;
  2735.                         return 0;
  2736.     case DFNT_NINT16:   DFKnumin  = NSI16_IN;
  2737.                         DFKnumout = NSI16_OUT;
  2738.                         return 0;
  2739.     case DFNT_NUINT16:  DFKnumin  = NUI16_IN;
  2740.                         DFKnumout = NUI16_OUT;
  2741.                         return 0;
  2742.     case DFNT_NINT32:   DFKnumin  = NSI32_IN;
  2743.                         DFKnumout = NSI32_OUT;
  2744.                         return 0;
  2745.     case DFNT_NUINT32:  DFKnumin  = NUI32_IN;
  2746.                         DFKnumout = NUI32_OUT;
  2747.                         return 0;
  2748.     case DFNT_NFLOAT32: DFKnumin  = NF32_IN;
  2749.                         DFKnumout = NF32_OUT;
  2750.                         return 0;
  2751.     case DFNT_NFLOAT64: DFKnumin  = NF64_IN;
  2752.                         DFKnumout = NF64_OUT;
  2753.                         return 0;
  2754.  
  2755. /* No conversion routines are specified for DFNT_custom.  User must provide. */
  2756. /* Users should call DFCV_SetCustomIn() and DFCV_SetCustomOut() if they      */
  2757. /* choose to use DFNT_CUSTOM.  Users should provide their own method to      */
  2758. /* distinguish between multiple 'custom' conversion routines.  HDF only      */
  2759. /* knows such routines as type 'DFNT_CUSTOM'.                                */
  2760.  
  2761.     case DFNT_CUSTOM:  g_ntype = DFNT_CUSTOM;
  2762.                        return 0;
  2763.     default:           HERROR(DFE_BADCONV);
  2764.                        return FAIL;
  2765.   }
  2766. }
  2767.  
  2768.  
  2769. /*****************************************************************************
  2770.  * The following routine provides an easy method for the user to setup custom
  2771.  * conversion routines....
  2772.  *****************************************************************************/
  2773. PUBLIC
  2774. #ifdef PROTOTYPE
  2775. int DFKsetcustom(
  2776.   int (*DFKcustin)(VOIDP source, VOIDP dest, uint32 num_elm,
  2777.            uint32 source_stride, uint32 dest_stride), 
  2778.   int (*DFKcustout)(VOIDP source, VOIDP dest, uint32 num_elm, 
  2779.             uint32 source_stride, uint32 dest_stride)
  2780. )
  2781. #else
  2782. DFKsetcustom(DFKcustout, DFKcustin)
  2783. int (*DFKcustin)();
  2784. int (*DFKcustout)();
  2785. #endif /* PROTOTYPE */
  2786. {
  2787.   DFKnumin = DFKcustin;
  2788.   DFKnumout = DFKcustout;
  2789.   DFKsetNT(DFNT_CUSTOM);   /* Keep HDF from getting confused */
  2790.   return 0;
  2791.  
  2792.  
  2793. /*------------------------------------------------------------------
  2794.  * Name:    DFKisnativeNT
  2795.  * Purpose: Determine whether number type is native mode
  2796.  * Inputs:  numbertype: number type
  2797.  * Returns: 1 if true, 0 if false
  2798.  * Users:   DFSDgetslice
  2799.  * Method:  Checks to see if the "native mode" bit is set
  2800.  * Remarks:
  2801.  *------------------------------------------------------------------*/
  2802.  
  2803. #if defined PROTOTYPE
  2804. int32 DFKisnativeNT(int32 numbertype)
  2805. #else
  2806. int32 DFKisnativeNT(numbertype)
  2807. int32 numbertype;
  2808. #endif /* PROTOTYPE */
  2809. {
  2810.     return ((DFNT_NATIVE & numbertype)>0 ? 1 : 0 );
  2811. }
  2812.  
  2813. /************************************************************
  2814.  * DFconvert()
  2815.  *
  2816.  * This routine is called by HDF version 3.0 compatibility
  2817.  * routines.  It serves as a jump point to the new version 4.0
  2818.  * comversion functions.  DFconvert() CANNOT be used by Vdata
  2819.  * applications because it assumes a stride of 1 (for
  2820.  * compatibility). Vdata routines should call DFnum_in() and 
  2821.  * DFKnumout() (depending on which translation is needed)
  2822.  *
  2823.  * uint8 * source    location where the data is stored
  2824.  * uint8 * dest      location to put the converted data
  2825.  * int  * ntype       the overall number type of the data, ie DFNT_FLOAT...
  2826.  * int  * sourcetype  the specific type of the source data, ie DFNTF_IEEE...
  2827.  * int  * desttype    the specifid type of the converted data, ie DFNTF_VAX...
  2828.  * int  * size        the number (total) of BYTES to convert
  2829.  ************************************************************/
  2830. #if defined PROTOTYPE
  2831. int DFconvert(uint8 *source,uint8 *dest,int ntype,int sourcetype,int desttype,
  2832.         int32 size)
  2833. #else
  2834. int DFconvert(source, dest, ntype, sourcetype, desttype, size)
  2835. uint8 * source, * dest; 
  2836. int ntype, sourcetype, desttype;
  2837. int32 size;
  2838. #endif /* PROTOTYPE */
  2839.   register int32 num_elm;
  2840.   char *FUNC="DFconvert";
  2841.  
  2842.   HEclear();
  2843.  
  2844.   if(DFKsetNT(ntype) == FAIL) {
  2845.     HERROR(DFE_BADCONV);
  2846.     return FAIL;
  2847.   }
  2848.  
  2849.   if(sourcetype == desttype) { 
  2850.     DFmovmem(source, dest, size);
  2851.     return 0;
  2852.   }
  2853.  
  2854.   num_elm = size / 4;
  2855.  
  2856. /* Check to see if they want to covert numbers in from the disk */
  2857.   if(sourcetype == DFNTF_IEEE && (desttype == DFNTF_VAX || 
  2858.                   desttype == DFNTF_CRAY || 
  2859.                   desttype == DFNTF_PC      ) )
  2860.     return (DFKnumin)((VOIDP)source, (VOIDP)dest, num_elm, 0, 0);
  2861.  
  2862. /* Check to see if they want to convert numbers out to disk */
  2863.   if(desttype == DFNTF_IEEE && (sourcetype == DFNTF_VAX || 
  2864.                 sourcetype == DFNTF_CRAY || 
  2865.                 sourcetype == DFNTF_PC     ) )
  2866.     return DFKnumout((VOIDP)source, (VOIDP)dest, num_elm, 0, 0);
  2867.  
  2868. /* Return an error because they did not specify valid translation codes */
  2869.   HERROR(DFE_BADCONV);
  2870.   return FAIL;
  2871. }
  2872.  
  2873. /*------------------------------------------------------------------
  2874.  * Name:    DFKgetPNSC
  2875.  * Purpose: Get PlatformNumberSubclass for a given number type
  2876.  * Inputs:  numtype: number type to get subclass for
  2877.  *          machinetype: machine-type code
  2878.  * Returns: PlatformNumberSubclass on success, FAIL on failure with
  2879.  *          error set
  2880.  * Users:   DFSDgetslice
  2881.  * Method:  Checks NT_TYPES to determine whether it is a char, int, or
  2882.  *          float, then looks in corresponding field of machine type
  2883.  *          (DFMT) to get the class.
  2884.  * Remarks:
  2885.  *------------------------------------------------------------------*/
  2886.  
  2887. #if defined(PROTOTYPE)
  2888. int8 DFKgetPNSC(int32 numbertype, int32 machinetype)
  2889. #else
  2890. int8 DFKgetPNSC(numbertype, machinetype)
  2891. int32 numbertype, machinetype;
  2892. #endif /* PROTOTYPE */
  2893. {
  2894.     switch (numbertype) {
  2895.         case DFNT_FLOAT32:
  2896.         case DFNT_FLOAT64:
  2897.         case DFNT_FLOAT128: return (int8)((machinetype>>8) & 0x0f);
  2898.  
  2899.         case DFNT_INT8:
  2900.         case DFNT_UINT8:
  2901.         case DFNT_INT16:
  2902.         case DFNT_UINT16:
  2903.         case DFNT_INT32:
  2904.         case DFNT_UINT32:
  2905.         case DFNT_INT64:
  2906.         case DFNT_UINT64:
  2907.         case DFNT_INT128:
  2908.         case DFNT_UINT128: return (int8)((machinetype>>4) & 0x0f);
  2909.  
  2910.         case DFNT_CHAR8:
  2911.         case DFNT_UCHAR8:
  2912.         case DFNT_CHAR16:
  2913.         case DFNT_UCHAR16: return (int8)(machinetype & 0x0f);
  2914.  
  2915.  
  2916.         case DFNT_NFLOAT32:
  2917.         case DFNT_NFLOAT64:
  2918.         case DFNT_NFLOAT128: return (int8)((machinetype>>8) & 0x0f);
  2919.  
  2920.         case DFNT_NINT8:
  2921.         case DFNT_NUINT8:
  2922.         case DFNT_NINT16:
  2923.         case DFNT_NUINT16:
  2924.         case DFNT_NINT32:
  2925.         case DFNT_NUINT32:
  2926.         case DFNT_NINT64:
  2927.         case DFNT_NUINT64:
  2928.         case DFNT_NINT128:
  2929.         case DFNT_NUINT128: return (int8)((machinetype>>4) & 0x0f);
  2930.  
  2931.         case DFNT_NCHAR8:
  2932.         case DFNT_NUCHAR8:
  2933.         case DFNT_NCHAR16:
  2934.         case DFNT_NUCHAR16: return (int8)(machinetype & 0x0f);
  2935.         default: return FAIL;
  2936.     }
  2937. }
  2938.  
  2939. /*----------------------------------------------------------------------------
  2940. * Name:    DFKconvert
  2941. * Purpose: set number type and do the convert
  2942. * Inputs:  source -- location where the data is stored
  2943. *       dest -- location to put the converted data
  2944. *       ntype -- the current number type
  2945. *       num_elm -- number of elements to be converted
  2946. *       access -- DFACC_READ for numin, DFACC_WRITE for numout
  2947. *       source_stride, dest_stride -- strides in source and destination
  2948. * Returns: 0 -- succeed; FAIL -- failure
  2949. * Users:   DFSDgetsdg, DFSDputsdg, DFSDIgetslice, DFSDIgetslice
  2950. * Method:  Calls DFKsetNT, then call DFnumin or DFnumout
  2951. *---------------------------------------------------------------------------*/
  2952.  
  2953. #if defined PROTOTYPE
  2954. int32 DFKconvert(uint8 *source, uint8 *dest, int32 ntype, int32 num_elm,
  2955.           int16 access, int32 source_stride, int32 dest_stride)
  2956. #else
  2957. int32 DFKconvert(source, dest, ntype, num_elm, access, source_stride,
  2958.          dest_stride)
  2959. uint8 *source, *dest;
  2960. int32 ntype, num_elm, source_stride, dest_stride;
  2961. int16 access;
  2962. #endif
  2963.  
  2964. {
  2965.     int ret;
  2966.  
  2967.     DFKsetNT(ntype);
  2968.     if (access == DFACC_READ) 
  2969.         ret = DFKnumin((VOIDP)source, (VOIDP)dest, num_elm, source_stride,
  2970.                dest_stride);
  2971.     else ret = DFKnumout((VOIDP)source, (VOIDP)dest, num_elm, source_stride, 
  2972.              dest_stride);
  2973.     return(ret);
  2974. }
  2975.  
  2976. /*****************************************************************************
  2977.  * Miscellaneous Other Conversion Routines
  2978.  *****************************************************************************/
  2979.  
  2980.  
  2981.