~ubuntu-branches/ubuntu/quantal/xdmf/quantal

« back to all changes in this revision

Viewing changes to Utilities/hdf5/H5Tconv.c

  • Committer: Bazaar Package Importer
  • Author(s): Alastair McKinstry
  • Date: 2011-07-09 10:33:32 UTC
  • Revision ID: james.westby@ubuntu.com-20110709103332-2w36cerw7215fzoe
Tags: upstream-2.1.dfsg.1
ImportĀ upstreamĀ versionĀ 2.1.dfsg.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 
2
 * Copyright by the Board of Trustees of the University of Illinois.         *
 
3
 * All rights reserved.                                                      *
 
4
 *                                                                           *
 
5
 * This file is part of HDF5.  The full HDF5 copyright notice, including     *
 
6
 * terms governing use, modification, and redistribution, is contained in    *
 
7
 * the files COPYING and Copyright.html.  COPYING can be found at the root   *
 
8
 * of the source code distribution tree; Copyright.html can be found at the  *
 
9
 * root level of an installed copy of the electronic HDF5 document set and   *
 
10
 * is linked from the top-level documents page.  It can also be found at     *
 
11
 * http://hdf.ncsa.uiuc.edu/HDF5/doc/Copyright.html.  If you do not have     *
 
12
 * access to either file, you may request a copy from hdfhelp@ncsa.uiuc.edu. *
 
13
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
 
14
 
 
15
/*
 
16
 * Module Info:  Data type conversions for the H5T interface.
 
17
 */
 
18
 
 
19
#define H5T_PACKAGE    /*suppress error about including H5Tpkg       */
 
20
 
 
21
 
 
22
#include "H5private.h"    /*generic functions        */
 
23
#include "H5Eprivate.h"    /*error handling        */
 
24
#include "H5FLprivate.h"  /*Free Lists                            */
 
25
#include "H5Iprivate.h"    /*ID functions             */
 
26
#include "H5MMprivate.h"  /*memory management        */
 
27
#include "H5Pprivate.h"    /* Property Lists        */
 
28
#include "H5Tpkg.h"    /*data-type functions        */
 
29
 
 
30
/* Conversion data for H5T_conv_struct() */
 
31
typedef struct H5T_conv_struct_t {
 
32
    int  *src2dst;    /*mapping from src to dst member num */
 
33
    hid_t  *src_memb_id;    /*source member type ID's       */
 
34
    hid_t  *dst_memb_id;    /*destination member type ID's       */
 
35
    H5T_path_t  **memb_path;    /*conversion path for each member    */
 
36
} H5T_conv_struct_t;
 
37
 
 
38
/* Conversion data for H5T_conv_enum() */
 
39
typedef struct H5T_enum_struct_t {
 
40
    int  base;      /*lowest `in' value         */
 
41
    int  length;      /*num elements in arrays       */
 
42
    int  *src2dst;    /*map from src to dst index       */
 
43
} H5T_enum_struct_t;
 
44
 
 
45
/* Conversion data for the hardware conversion functions */
 
46
typedef struct H5T_conv_hw_t {
 
47
    size_t  s_aligned;    /*number source elements aligned     */
 
48
    size_t  d_aligned;    /*number destination elements aligned*/
 
49
} H5T_conv_hw_t;
 
50
 
 
51
/* Declare a free list to manage pieces of vlen data */
 
52
H5FL_BLK_DEFINE_STATIC(vlen_seq);
 
53
 
 
54
/* Declare a free list to manage pieces of array data */
 
55
H5FL_BLK_DEFINE_STATIC(array_seq);
 
56
 
 
57
/*
 
58
 * These macros are for the bodies of functions that convert buffers of one
 
59
 * atomic type to another using hardware.
 
60
 *
 
61
 * They all start with `H5T_CONV_' and end with two letters that represent the
 
62
 * source and destination types, respectively. The letters `s' and `S' refer to
 
63
 * signed integers while the letters `u' and `U' refer to unsigned integers, and
 
64
 * the letters `f' and `F' refer to floating-point values.
 
65
 *
 
66
 * The letter which is capitalized indicates that the corresponding type
 
67
 * (source or destination) is at least as large as the other type.
 
68
 *
 
69
 * Certain conversions may experience overflow conditions which arise when the
 
70
 * source value has a magnitude that cannot be represented by the destination
 
71
 * type.
 
72
 *
 
73
 * Suffix  Description
 
74
 * ------  -----------
 
75
 * sS:    Signed integers to signed integers where the destination is
 
76
 *    at least as wide as the source.   This case cannot generate
 
77
 *    overflows.
 
78
 *
 
79
 * sU:    Signed integers to unsigned integers where the destination is
 
80
 *    at least as wide as the source.   This case experiences
 
81
 *    overflows when the source value is negative.
 
82
 *
 
83
 * uS:    Unsigned integers to signed integers where the destination is
 
84
 *    at least as wide as the source.   This case can experience
 
85
 *    overflows when the source and destination are the same size.
 
86
 *
 
87
 * uU:    Unsigned integers to unsigned integers where the destination
 
88
 *    is at least as wide as the source.  Overflows are not
 
89
 *    possible in this case.
 
90
 *
 
91
 * Ss:    Signed integers to signed integers where the source is at
 
92
 *    least as large as the destination.  Overflows can occur when
 
93
 *    the destination is narrower than the source.
 
94
 *
 
95
 * Su:    Signed integers to unsigned integers where the source is at
 
96
 *    least as large as the destination.  Overflows occur when the
 
97
 *    source value is negative and can also occur if the
 
98
 *    destination is narrower than the source.
 
99
 *
 
100
 * Us:    Unsigned integers to signed integers where the source is at
 
101
 *    least as large as the destination.  Overflows can occur for
 
102
 *    all sizes.
 
103
 *
 
104
 * Uu:    Unsigned integers to unsigned integers where the source is at
 
105
 *    least as large as the destination. Overflows can occur if the
 
106
 *    destination is narrower than the source.
 
107
 *
 
108
 * su:    Conversion from signed integers to unsigned integers where
 
109
 *    the source and destination are the same size. Overflow occurs
 
110
 *    when the source value is negative.
 
111
 *
 
112
 * us:    Conversion from unsigned integers to signed integers where
 
113
 *    the source and destination are the same size.  Overflow
 
114
 *    occurs when the source magnitude is too large for the
 
115
 *    destination.
 
116
 *
 
117
 * fF:    Floating-point values to floating-point values where the
 
118
 *              destination is at least as wide as the source.   This case
 
119
 *              cannot generate overflows.
 
120
 *
 
121
 * Ff:    Floating-point values to floating-point values the source is at
 
122
 *    least as large as the destination.  Overflows can occur when
 
123
 *    the destination is narrower than the source.
 
124
 *
 
125
 * The macros take a subset of these arguments in the order listed here:
 
126
 *
 
127
 * CDATA:  A pointer to the H5T_cdata_t structure that was passed to the
 
128
 *    conversion function.
 
129
 *
 
130
 * STYPE:  The hid_t value for the source data type.
 
131
 *
 
132
 * DTYPE:  The hid_t value for the destination data type.
 
133
 *
 
134
 * BUF:    A pointer to the conversion buffer.
 
135
 *
 
136
 * NELMTS:  The number of values to be converted.
 
137
 *
 
138
 * ST:    The C name for source data type (e.g., int)
 
139
 *
 
140
 * DT:    The C name for the destination data type (e.g., signed char)
 
141
 *
 
142
 * D_MIN:  The minimum possible destination value.   For unsigned
 
143
 *    destination types this should be zero.  For signed
 
144
 *    destination types it's a negative value with a magnitude that
 
145
 *    is usually one greater than D_MAX.  Source values which are
 
146
 *    smaller than D_MIN generate overflows.
 
147
 *
 
148
 * D_MAX:  The maximum possible destination value. Source values which
 
149
 *    are larger than D_MAX generate overflows.
 
150
 *
 
151
 * The macros are implemented with a generic programming technique, similar
 
152
 * to templates in C++.  The macro which defines the "core" part of the
 
153
 * conversion (which actually moves the data from the source to the destination)
 
154
 * is invoked inside the H5T_CONV "template" macro by "gluing" it together,
 
155
 * which allows the core conversion macro to be invoked as necessary.
 
156
 *
 
157
 * "Core" macros come in two flavors: one which calls the exception handling
 
158
 * routine and one which doesn't (the "_NOEX" variant).  The presence of the
 
159
 * exception handling routine is detected before the loop over the values and
 
160
 * the appropriate core routine loop is executed.
 
161
 *
 
162
 * The generic "core" macros are: (others are specific to particular conversion)
 
163
 *
 
164
 * Suffix  Description
 
165
 * ------  -----------
 
166
 * xX:    Generic Conversion where the destination is at least as
 
167
 *              wide as the source.  This case cannot generate overflows.
 
168
 *
 
169
 * Xx:    Generic signed conversion where the source is at least as large
 
170
 *              as the destination.  Overflows can occur when the destination is
 
171
 *              narrower than the source.
 
172
 *
 
173
 * Ux:    Generic conversion for the `Us', `Uu' & `us' cases
 
174
 *    Overflow occurs when the source magnitude is too large for the
 
175
 *    destination.
 
176
 *
 
177
 */
 
178
#define H5T_CONV_xX_CORE(S,D,ST,DT,D_MIN,D_MAX) {            \
 
179
    *((DT*)D) = (DT)(*((ST*)S));                \
 
180
}
 
181
#define H5T_CONV_xX_NOEX_CORE(S,D,ST,DT,D_MIN,D_MAX) {            \
 
182
    *((DT*)D) = (DT)(*((ST*)S));                \
 
183
}
 
184
 
 
185
/* Added a condition branch(else if (*((ST*)S) == (DT)(D_MAX))) which seems redundant.
 
186
 * It handles a special situation when the source is "float" and assigned the value
 
187
 * of "INT_MAX".  A compiler may do roundup making this value "INT_MAX+1".  However,
 
188
 * when do comparison "if (*((ST*)S) > (DT)(D_MAX))", the compiler may consider them
 
189
 * equal. In this case, do not return exception but make sure the maximum is assigned
 
190
 * to the destination. SLU - 2005/06/29
 
191
 */
 
192
#define H5T_CONV_Xx_CORE(S,D,ST,DT,D_MIN,D_MAX) {            \
 
193
    if (*((ST*)S) > (DT)(D_MAX)) {                \
 
194
        if ((H5T_overflow_g)(src_id, dst_id, S, D)<0)            \
 
195
            *((DT*)D) = (D_MAX);                \
 
196
    } else if (*((ST*)S) == (DT)(D_MAX)) {                                    \
 
197
        *((DT*)D) = (D_MAX);                                    \
 
198
    } else if (*((ST*)S) < (DT)(D_MIN)) {                    \
 
199
        if ((H5T_overflow_g)(src_id, dst_id, S, D)<0)            \
 
200
            *((DT*)D) = (D_MIN);                \
 
201
    } else                      \
 
202
        *((DT*)D) = (DT)(*((ST*)S));                \
 
203
}
 
204
#define H5T_CONV_Xx_NOEX_CORE(S,D,ST,DT,D_MIN,D_MAX) {            \
 
205
    if (*((ST*)S) > (DT)(D_MAX)) {                \
 
206
        *((DT*)D) = (D_MAX);                  \
 
207
    } else if (*((ST*)S) == (DT)(D_MAX)) {                                    \
 
208
        *((DT*)D) = (D_MAX);                                    \
 
209
    } else if (*((ST*)S) < (DT)(D_MIN)) {                    \
 
210
        *((DT*)D) = (D_MIN);                  \
 
211
    } else                      \
 
212
        *((DT*)D) = (DT)(*((ST*)S));                \
 
213
}
 
214
 
 
215
#define H5T_CONV_Ux_CORE(S,D,ST,DT,D_MIN,D_MAX) {            \
 
216
    if (*((ST*)S) > (DT)(D_MAX)) {                      \
 
217
        if ((H5T_overflow_g)(src_id, dst_id, S, D)<0)            \
 
218
            *((DT*)D) = (D_MAX);                \
 
219
    } else                      \
 
220
        *((DT*)D) = (DT)(*((ST*)S));                \
 
221
}
 
222
#define H5T_CONV_Ux_NOEX_CORE(S,D,ST,DT,D_MIN,D_MAX) {            \
 
223
    if (*((ST*)S) > (DT)(D_MAX)) {                      \
 
224
        *((DT*)D) = (D_MAX);                  \
 
225
    } else                      \
 
226
        *((DT*)D) = (DT)(*((ST*)S));                \
 
227
}
 
228
 
 
229
#define H5T_CONV_sS(STYPE,DTYPE,ST,DT,D_MIN,D_MAX) {            \
 
230
    assert(sizeof(ST)<=sizeof(DT));                \
 
231
    H5T_CONV(H5T_CONV_xX, long_long, STYPE, DTYPE, ST, DT, D_MIN, D_MAX)      \
 
232
}
 
233
 
 
234
#define H5T_CONV_sU_CORE(S,D,ST,DT,D_MIN,D_MAX) {            \
 
235
    if (*((ST*)S)<0) {                    \
 
236
        if (!H5T_overflow_g || (H5T_overflow_g)(src_id, dst_id, S, D)<0)      \
 
237
            *((DT*)D) = 0;                  \
 
238
    } else                      \
 
239
        *((DT*)D) = (DT)(*((ST*)S));                \
 
240
}
 
241
#define H5T_CONV_sU_NOEX_CORE(S,D,ST,DT,D_MIN,D_MAX) {            \
 
242
    if (*((ST*)S)<0) {                    \
 
243
        *((DT*)D) = 0;                    \
 
244
    } else                      \
 
245
        *((DT*)D) = (DT)(*((ST*)S));                \
 
246
}
 
247
 
 
248
#define H5T_CONV_sU(STYPE,DTYPE,ST,DT,D_MIN,D_MAX) {            \
 
249
    assert(sizeof(ST)<=sizeof(DT));                \
 
250
    H5T_CONV(H5T_CONV_sU, long_long, STYPE, DTYPE, ST, DT, D_MIN, D_MAX)      \
 
251
}
 
252
 
 
253
#define H5T_CONV_uS_CORE(S,D,ST,DT,D_MIN,D_MAX) {            \
 
254
    if (sizeof(ST)==sizeof(DT) && *((ST*)S) > (DT)(D_MAX)) {          \
 
255
        if (!H5T_overflow_g || (H5T_overflow_g)(src_id, dst_id, S, D)<0)      \
 
256
            *((DT*)D) = (D_MAX);                \
 
257
    } else                      \
 
258
        *((DT*)D) = (DT)(*((ST*)S));                \
 
259
}
 
260
#define H5T_CONV_uS_NOEX_CORE(S,D,ST,DT,D_MIN,D_MAX) {            \
 
261
    if (sizeof(ST)==sizeof(DT) && *((ST*)S) > (DT)(D_MAX)) {          \
 
262
        *((DT*)D) = (D_MAX);                  \
 
263
    } else                      \
 
264
        *((DT*)D) = (DT)(*((ST*)S));                \
 
265
}
 
266
 
 
267
#define H5T_CONV_uS(STYPE,DTYPE,ST,DT,D_MIN,D_MAX) {            \
 
268
    assert(sizeof(ST)<=sizeof(DT));                \
 
269
    H5T_CONV(H5T_CONV_uS, long_long, STYPE, DTYPE, ST, DT, D_MIN, D_MAX)      \
 
270
}
 
271
 
 
272
#define H5T_CONV_uU(STYPE,DTYPE,ST,DT,D_MIN,D_MAX) {            \
 
273
    assert(sizeof(ST)<=sizeof(DT));                \
 
274
    H5T_CONV(H5T_CONV_xX, long_long, STYPE, DTYPE, ST, DT, D_MIN, D_MAX)      \
 
275
}
 
276
 
 
277
#define H5T_CONV_Ss(STYPE,DTYPE,ST,DT,D_MIN,D_MAX) {            \
 
278
    assert(sizeof(ST)>=sizeof(DT));                \
 
279
    H5T_CONV(H5T_CONV_Xx, long_long, STYPE, DTYPE, ST, DT, D_MIN, D_MAX)      \
 
280
}
 
281
 
 
282
#define H5T_CONV_Su_CORE(S,D,ST,DT,D_MIN,D_MAX) {            \
 
283
    if (*((ST*)S) < 0) {                  \
 
284
        if (!H5T_overflow_g || (H5T_overflow_g)(src_id, dst_id, S, D)<0)      \
 
285
            *((DT*)D) = 0;                  \
 
286
    } else if (sizeof(ST)>sizeof(DT) && *((ST*)S)>(ST)(D_MAX)) {        \
 
287
        /*sign vs. unsign ok in previous line*/              \
 
288
        if (!H5T_overflow_g || (H5T_overflow_g)(src_id, dst_id, S, D)<0)      \
 
289
            *((DT*)D) = (D_MAX);                \
 
290
    } else                      \
 
291
        *((DT*)D) = (DT)(*((ST*)S));                \
 
292
}
 
293
#define H5T_CONV_Su_NOEX_CORE(S,D,ST,DT,D_MIN,D_MAX) {            \
 
294
    if (*((ST*)S) < 0) {                  \
 
295
        *((DT*)D) = 0;                    \
 
296
    } else if (sizeof(ST)>sizeof(DT) && *((ST*)S)>(ST)(D_MAX)) {        \
 
297
        /*sign vs. unsign ok in previous line*/              \
 
298
        *((DT*)D) = (D_MAX);                  \
 
299
    } else                      \
 
300
        *((DT*)D) = (DT)(*((ST*)S));                \
 
301
}
 
302
 
 
303
#define H5T_CONV_Su(STYPE,DTYPE,ST,DT,D_MIN,D_MAX) {            \
 
304
    assert(sizeof(ST)>=sizeof(DT));                \
 
305
    H5T_CONV(H5T_CONV_Su, long_long, STYPE, DTYPE, ST, DT, D_MIN, D_MAX)      \
 
306
}
 
307
 
 
308
#define H5T_CONV_Us(STYPE,DTYPE,ST,DT,D_MIN,D_MAX) {            \
 
309
    assert(sizeof(ST)>=sizeof(DT));                \
 
310
    H5T_CONV(H5T_CONV_Ux, long_long, STYPE, DTYPE, ST, DT, D_MIN, D_MAX)      \
 
311
}
 
312
 
 
313
#define H5T_CONV_Uu(STYPE,DTYPE,ST,DT,D_MIN,D_MAX) {            \
 
314
    assert(sizeof(ST)>=sizeof(DT));                \
 
315
    H5T_CONV(H5T_CONV_Ux, long_long, STYPE, DTYPE, ST, DT, D_MIN, D_MAX)      \
 
316
}
 
317
 
 
318
#define H5T_CONV_su_CORE(S,D,ST,DT,D_MIN,D_MAX) {            \
 
319
    /* Assumes memory format of unsigned & signed integers is same */        \
 
320
    if (*((ST*)S)<0) {                    \
 
321
        if (!H5T_overflow_g || (H5T_overflow_g)(src_id, dst_id, S, D)<0)      \
 
322
            *((DT*)D) = 0;                  \
 
323
    } else                      \
 
324
        *((DT*)D) = (DT)(*((ST*)S));                \
 
325
}
 
326
#define H5T_CONV_su_NOEX_CORE(S,D,ST,DT,D_MIN,D_MAX) {            \
 
327
    /* Assumes memory format of unsigned & signed integers is same */        \
 
328
    if (*((ST*)S)<0) {                    \
 
329
        *((DT*)D) = 0;                    \
 
330
    } else                      \
 
331
        *((DT*)D) = (DT)(*((ST*)S));                \
 
332
}
 
333
 
 
334
#define H5T_CONV_su(STYPE,DTYPE,ST,DT,D_MIN,D_MAX) {            \
 
335
    assert(sizeof(ST)==sizeof(DT));                \
 
336
    H5T_CONV(H5T_CONV_su, long_long, STYPE, DTYPE, ST, DT, D_MIN, D_MAX)      \
 
337
}
 
338
 
 
339
#define H5T_CONV_us_CORE(S,D,ST,DT,D_MIN,D_MAX) {            \
 
340
    /* Assumes memory format of unsigned & signed integers is same */        \
 
341
    if (*((ST*)S) > (DT)(D_MAX)) {                \
 
342
        if (!H5T_overflow_g || (H5T_overflow_g)(src_id, dst_id, S, D)<0)      \
 
343
            *((DT*)D) = (D_MAX);                \
 
344
    } else                      \
 
345
        *((DT*)D) = (DT)(*((ST*)S));                \
 
346
}
 
347
#define H5T_CONV_us_NOEX_CORE(S,D,ST,DT,D_MIN,D_MAX) {            \
 
348
    /* Assumes memory format of unsigned & signed integers is same */        \
 
349
    if (*((ST*)S) > (DT)(D_MAX)) {                \
 
350
        *((DT*)D) = (D_MAX);                  \
 
351
    } else                      \
 
352
        *((DT*)D) = (DT)(*((ST*)S));                \
 
353
}
 
354
 
 
355
#define H5T_CONV_us(STYPE,DTYPE,ST,DT,D_MIN,D_MAX) {            \
 
356
    assert(sizeof(ST)==sizeof(DT));                \
 
357
    H5T_CONV(H5T_CONV_us, long_long, STYPE, DTYPE, ST, DT, D_MIN, D_MAX)      \
 
358
}
 
359
 
 
360
#define H5T_CONV_fF(STYPE,DTYPE,ST,DT,D_MIN,D_MAX) {            \
 
361
    assert(sizeof(ST)<=sizeof(DT));                \
 
362
    H5T_CONV(H5T_CONV_xX, double, STYPE, DTYPE, ST, DT, D_MIN, D_MAX)        \
 
363
}
 
364
 
 
365
/* Same as H5T_CONV_Xx_CORE, except that instead of using D_MAX and D_MIN
 
366
 * when an overflow occurs, use the 'float' infinity values.
 
367
 */
 
368
#define H5T_CONV_Ff_CORE(S,D,ST,DT,D_MIN,D_MAX) {            \
 
369
    if (*((ST*)S) > (DT)(D_MAX)) {                \
 
370
        if (!H5T_overflow_g || (H5T_overflow_g)(src_id, dst_id, S, D)<0)      \
 
371
            *((DT*)D) = (H5T_NATIVE_FLOAT_POS_INF_g);            \
 
372
    } else if (*((ST*)S) < (DT)(D_MIN)) {              \
 
373
        if (!H5T_overflow_g || (H5T_overflow_g)(src_id, dst_id, S, D)<0)      \
 
374
            *((DT*)D) = (H5T_NATIVE_FLOAT_NEG_INF_g);            \
 
375
    } else                      \
 
376
        *((DT*)D) = (DT)(*((ST*)S));                \
 
377
}
 
378
#define H5T_CONV_Ff_NOEX_CORE(S,D,ST,DT,D_MIN,D_MAX) {            \
 
379
    if (*((ST*)S) > (DT)(D_MAX)) {                \
 
380
        *((DT*)D) = (H5T_NATIVE_FLOAT_POS_INF_g);            \
 
381
    } else if (*((ST*)S) < (DT)(D_MIN)) {              \
 
382
        *((DT*)D) = (H5T_NATIVE_FLOAT_NEG_INF_g);            \
 
383
    } else                      \
 
384
        *((DT*)D) = (DT)(*((ST*)S));                \
 
385
}
 
386
 
 
387
#define H5T_CONV_Ff(STYPE,DTYPE,ST,DT,D_MIN,D_MAX) {            \
 
388
    assert(sizeof(ST)>=sizeof(DT));                \
 
389
    H5T_CONV(H5T_CONV_Ff, double, STYPE, DTYPE, ST, DT, D_MIN, D_MAX)        \
 
390
}
 
391
 
 
392
/* The main part of every integer hardware conversion macro */
 
393
#define H5T_CONV(GUTS,ATYPE,STYPE,DTYPE,ST,DT,D_MIN,D_MAX) {          \
 
394
    size_t  elmtno;      /*element number    */    \
 
395
    uint8_t  *src, *s;    /*source buffer      */    \
 
396
    uint8_t  *dst, *d;    /*destination buffer    */    \
 
397
    H5T_t  *st, *dt;    /*data type descriptors    */    \
 
398
    ATYPE  aligned;    /*aligned type      */    \
 
399
    hbool_t  s_mv, d_mv;    /*move data to align it?  */    \
 
400
    ssize_t  s_stride, d_stride;  /*src and dst strides    */    \
 
401
    size_t      safe;                   /* How many elements are safe to process in each pass */ \
 
402
                        \
 
403
    switch (cdata->command) {                  \
 
404
    case H5T_CONV_INIT:                    \
 
405
  /* Sanity check and initialize statistics */            \
 
406
  cdata->need_bkg = H5T_BKG_NO;                \
 
407
  if (NULL==(st=H5I_object(src_id)) || NULL==(dt=H5I_object(dst_id)))   \
 
408
      HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL,          \
 
409
        "unable to dereference datatype object ID")        \
 
410
  if (st->shared->size!=sizeof(ST) || dt->shared->size!=sizeof(DT))     \
 
411
      HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL,          \
 
412
        "disagreement about datatype size")          \
 
413
  CI_ALLOC_PRIV                                                        \
 
414
  break;                      \
 
415
                        \
 
416
    case H5T_CONV_FREE:                    \
 
417
  /* Print and free statistics */                \
 
418
  CI_PRINT_STATS(STYPE,DTYPE);                \
 
419
  CI_FREE_PRIV                                                        \
 
420
  break;                      \
 
421
                        \
 
422
    case H5T_CONV_CONV:                    \
 
423
  /* Initialize source & destination strides */            \
 
424
  if (buf_stride) {                  \
 
425
            assert(buf_stride>=sizeof(ST));              \
 
426
            assert(buf_stride>=sizeof(DT));              \
 
427
            H5_CHECK_OVERFLOW(buf_stride,size_t,ssize_t);                     \
 
428
      s_stride = d_stride = (ssize_t)buf_stride;            \
 
429
  } else {                    \
 
430
            s_stride = sizeof(ST);                \
 
431
            d_stride = sizeof(DT);                \
 
432
        }                      \
 
433
                        \
 
434
  /* Is alignment required for source or dest? */            \
 
435
  s_mv = H5T_NATIVE_##STYPE##_ALIGN_g>1 &&            \
 
436
               ((size_t)buf%H5T_NATIVE_##STYPE##_ALIGN_g ||          \
 
437
     /* Cray */ ((size_t)((ST*)buf)!=(size_t)buf) ||            \
 
438
    s_stride%H5T_NATIVE_##STYPE##_ALIGN_g);            \
 
439
  d_mv = H5T_NATIVE_##DTYPE##_ALIGN_g>1 &&            \
 
440
               ((size_t)buf%H5T_NATIVE_##DTYPE##_ALIGN_g ||          \
 
441
     /* Cray */ ((size_t)((DT*)buf)!=(size_t)buf) ||            \
 
442
                d_stride%H5T_NATIVE_##DTYPE##_ALIGN_g);            \
 
443
  CI_INC_SRC(s_mv)                  \
 
444
  CI_INC_DST(d_mv)                  \
 
445
                        \
 
446
        /* The outer loop of the type conversion macro, controlling which */  \
 
447
        /* direction the buffer is walked */              \
 
448
        while (nelmts>0) {                  \
 
449
            /* Check if we need to go backwards through the buffer */        \
 
450
            if(d_stride>s_stride) {                \
 
451
                /* Compute the number of "safe" destination elements at */    \
 
452
                /* the end of the buffer (Those which don't overlap with */   \
 
453
                /* any source elements at the beginning of the buffer) */     \
 
454
                safe=nelmts-(((nelmts*s_stride)+(d_stride-1))/d_stride);      \
 
455
                        \
 
456
                /* If we're down to the last few elements, just wrap up */    \
 
457
                /* with a "real" reverse copy */            \
 
458
                if(safe<2) {                  \
 
459
                    src = (uint8_t*)buf+(nelmts-1)*s_stride;          \
 
460
                    dst = (uint8_t*)buf+(nelmts-1)*d_stride;          \
 
461
                    s_stride = -s_stride;              \
 
462
                    d_stride = -d_stride;              \
 
463
                        \
 
464
                    safe=nelmts;                \
 
465
                } /* end if */                  \
 
466
                else {                    \
 
467
                    src = (uint8_t*)buf+(nelmts-safe)*s_stride;          \
 
468
                    dst = (uint8_t*)buf+(nelmts-safe)*d_stride;          \
 
469
                } /* end else */                \
 
470
            } /* end if */                  \
 
471
            else {                    \
 
472
                /* Single forward pass over all data */            \
 
473
                src = dst = buf;                \
 
474
                safe=nelmts;                  \
 
475
            } /* end else */                  \
 
476
                        \
 
477
            /* Perform loop over elements to convert */            \
 
478
            if (s_mv && d_mv) {                  \
 
479
                /* Alignment is required for both source and dest */        \
 
480
                s = (uint8_t*)&aligned;                \
 
481
                H5T_CONV_LOOP_OUTER(PRE_SALIGN,PRE_DALIGN,POST_SALIGN,POST_DALIGN,GUTS,s,d,ST,DT,D_MIN,D_MAX) \
 
482
            } else if(s_mv) {                  \
 
483
                /* Alignment is required only for source */          \
 
484
                s = (uint8_t*)&aligned;                \
 
485
                H5T_CONV_LOOP_OUTER(PRE_SALIGN,PRE_DNOALIGN,POST_SALIGN,POST_DNOALIGN,GUTS,s,dst,ST,DT,D_MIN,D_MAX) \
 
486
            } else if(d_mv) {                  \
 
487
                /* Alignment is required only for destination */        \
 
488
                H5T_CONV_LOOP_OUTER(PRE_SNOALIGN,PRE_DALIGN,POST_SNOALIGN,POST_DALIGN,GUTS,src,d,ST,DT,D_MIN,D_MAX) \
 
489
            } else {                    \
 
490
                /* Alignment is not required for both source and destination */ \
 
491
                H5T_CONV_LOOP_OUTER(PRE_SNOALIGN,PRE_DNOALIGN,POST_SNOALIGN,POST_DNOALIGN,GUTS,src,dst,ST,DT,D_MIN,D_MAX) \
 
492
            }                             \
 
493
                        \
 
494
            /* Decrement number of elements left to convert */          \
 
495
            nelmts-=safe;                  \
 
496
        } /* end while */                  \
 
497
        break;                      \
 
498
                        \
 
499
    default:                      \
 
500
  HGOTO_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, FAIL,          \
 
501
          "unknown conversion command");            \
 
502
    }                        \
 
503
}
 
504
 
 
505
/* Macro defining action on source data which needs to be aligned (before main action) */
 
506
#define H5T_CONV_LOOP_PRE_SALIGN(ST) {                \
 
507
    HDmemcpy(&aligned, src, sizeof(ST));              \
 
508
}
 
509
 
 
510
/* Macro defining action on source data which doesn't need to be aligned (before main action) */
 
511
#define H5T_CONV_LOOP_PRE_SNOALIGN(ST) {              \
 
512
}
 
513
 
 
514
/* Macro defining action on destination data which needs to be aligned (before main action) */
 
515
#define H5T_CONV_LOOP_PRE_DALIGN(DT) {                \
 
516
    d = (uint8_t*)&aligned;                  \
 
517
}
 
518
 
 
519
/* Macro defining action on destination data which doesn't need to be aligned (before main action) */
 
520
#define H5T_CONV_LOOP_PRE_DNOALIGN(DT) {              \
 
521
}
 
522
 
 
523
/* Macro defining action on source data which needs to be aligned (after main action) */
 
524
#define H5T_CONV_LOOP_POST_SALIGN(ST) {                \
 
525
}
 
526
 
 
527
/* Macro defining action on source data which doesn't need to be aligned (after main action) */
 
528
#define H5T_CONV_LOOP_POST_SNOALIGN(ST) {              \
 
529
}
 
530
 
 
531
/* Macro defining action on destination data which needs to be aligned (after main action) */
 
532
#define H5T_CONV_LOOP_POST_DALIGN(DT) {                \
 
533
    HDmemcpy(dst, &aligned, sizeof(DT));              \
 
534
}
 
535
 
 
536
/* Macro defining action on destination data which doesn't need to be aligned (after main action) */
 
537
#define H5T_CONV_LOOP_POST_DNOALIGN(DT) {              \
 
538
}
 
539
 
 
540
/* The outer wrapper for the type conversion loop, to check for an exception handling routine */
 
541
#define H5T_CONV_LOOP_OUTER(PRE_SALIGN_GUTS,PRE_DALIGN_GUTS,POST_SALIGN_GUTS,POST_DALIGN_GUTS,GUTS,S,D,ST,DT,D_MIN,D_MAX) \
 
542
    if(H5T_overflow_g) {                                                      \
 
543
        H5T_CONV_LOOP(PRE_SALIGN_GUTS,PRE_DALIGN_GUTS,POST_SALIGN_GUTS,POST_DALIGN_GUTS,GUTS,S,D,ST,DT,D_MIN,D_MAX) \
 
544
    }                                                                         \
 
545
    else {                                                                    \
 
546
        H5T_CONV_LOOP(PRE_SALIGN_GUTS,PRE_DALIGN_GUTS,POST_SALIGN_GUTS,POST_DALIGN_GUTS,H5_GLUE(GUTS,_NOEX),S,D,ST,DT,D_MIN,D_MAX) \
 
547
    }
 
548
 
 
549
/* The inner loop of the type conversion macro, actually converting the elements */
 
550
#define H5T_CONV_LOOP(PRE_SALIGN_GUTS,PRE_DALIGN_GUTS,POST_SALIGN_GUTS,POST_DALIGN_GUTS,GUTS,S,D,ST,DT,D_MIN,D_MAX) \
 
551
    for (elmtno=0; elmtno<safe; elmtno++) {              \
 
552
        /* Handle source pre-alignment */              \
 
553
        H5_GLUE(H5T_CONV_LOOP_,PRE_SALIGN_GUTS)(ST)            \
 
554
                        \
 
555
        /* Handle destination pre-alignment */              \
 
556
        H5_GLUE(H5T_CONV_LOOP_,PRE_DALIGN_GUTS)(DT)            \
 
557
                        \
 
558
        /* ... user-defined stuff here -- the conversion ... */          \
 
559
        H5_GLUE(GUTS,_CORE)(S,D,ST,DT,D_MIN,D_MAX)            \
 
560
                        \
 
561
        /* Handle source post-alignment */              \
 
562
        H5_GLUE(H5T_CONV_LOOP_,POST_SALIGN_GUTS)(ST)            \
 
563
                        \
 
564
        /* Handle destination post-alignment */              \
 
565
        H5_GLUE(H5T_CONV_LOOP_,POST_DALIGN_GUTS)(DT)            \
 
566
                        \
 
567
        /* Advance pointers */                  \
 
568
        src += s_stride;                  \
 
569
        dst += d_stride;                  \
 
570
    }
 
571
 
 
572
 
 
573
#ifdef H5T_DEBUG
 
574
 
 
575
/* Print alignment statistics */
 
576
#   define CI_PRINT_STATS(STYPE,DTYPE) {              \
 
577
    if (H5DEBUG(T) && ((H5T_conv_hw_t *)cdata->priv)->s_aligned) {              \
 
578
  HDfprintf(H5DEBUG(T),                  \
 
579
      "      %Hu src elements aligned on %lu-byte boundaries\n",  \
 
580
      ((H5T_conv_hw_t *)cdata->priv)->s_aligned,        \
 
581
      (unsigned long)H5T_NATIVE_##STYPE##_ALIGN_g);          \
 
582
    }                        \
 
583
    if (H5DEBUG(T) && ((H5T_conv_hw_t *)cdata->priv)->d_aligned) {              \
 
584
  HDfprintf(H5DEBUG(T),                  \
 
585
      "      %Hu dst elements aligned on %lu-byte boundaries\n",  \
 
586
      ((H5T_conv_hw_t *)cdata->priv)->d_aligned,        \
 
587
      (unsigned long)H5T_NATIVE_##DTYPE##_ALIGN_g);          \
 
588
    }                        \
 
589
}
 
590
 
 
591
/* Allocate private alignment structure for atomic types */
 
592
#   define CI_ALLOC_PRIV \
 
593
  if (NULL==(cdata->priv=H5MM_calloc(sizeof(H5T_conv_hw_t)))) {        \
 
594
      HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL,          \
 
595
        "memory allocation failed");            \
 
596
  }
 
597
 
 
598
/* Free private alignment structure for atomic types */
 
599
#   define CI_FREE_PRIV                                 \
 
600
    if(cdata->priv!=NULL)                               \
 
601
        cdata->priv = H5MM_xfree(cdata->priv);
 
602
 
 
603
/* Increment source alignment counter */
 
604
#   define CI_INC_SRC(s)   if (s) ((H5T_conv_hw_t *)cdata->priv)->s_aligned += nelmts;
 
605
 
 
606
/* Increment destination alignment counter */
 
607
#   define CI_INC_DST(d)   if (d) ((H5T_conv_hw_t *)cdata->priv)->d_aligned += nelmts;
 
608
#else /* H5T_DEBUG */
 
609
#   define CI_PRINT_STATS(STYPE,DTYPE) /*void*/
 
610
#   define CI_ALLOC_PRIV cdata->priv=NULL;
 
611
#   define CI_FREE_PRIV  /* void */
 
612
#   define CI_INC_SRC(s) /* void */
 
613
#   define CI_INC_DST(d) /* void */
 
614
#endif /* H5T_DEBUG */
 
615
 
 
616
/* Swap two elements (I & J) of an array using a temporary variable */
 
617
#define H5_SWAP_BYTES(ARRAY,I,J) {uint8_t _tmp; _tmp=ARRAY[I]; ARRAY[I]=ARRAY[J]; ARRAY[J]=_tmp;}
 
618
 
 
619
/* Minimum size of variable-length conversion buffer */
 
620
#define H5T_VLEN_MIN_CONF_BUF_SIZE      4096
 
621
 
 
622
 
 
623
/*-------------------------------------------------------------------------
 
624
 * Function:  H5T_conv_noop
 
625
 *
 
626
 * Purpose:  The no-op conversion.  The library knows about this
 
627
 *    conversion without it being registered.
 
628
 *
 
629
 * Return:   Non-negative on success/Negative on failure
 
630
 *
 
631
 * Programmer:  Robb Matzke
 
632
 *    Wednesday, January 14, 1998
 
633
 *
 
634
 * Modifications:
 
635
 *
 
636
 *-------------------------------------------------------------------------
 
637
 */
 
638
herr_t
 
639
H5T_conv_noop(hid_t UNUSED src_id, hid_t UNUSED dst_id, H5T_cdata_t *cdata,
 
640
        size_t UNUSED nelmts, size_t UNUSED buf_stride,
 
641
              size_t UNUSED bkg_stride, void UNUSED *buf,
 
642
        void UNUSED *background, hid_t UNUSED dxpl_id)
 
643
{
 
644
    herr_t      ret_value=SUCCEED;       /* Return value */
 
645
 
 
646
    FUNC_ENTER_NOAPI(H5T_conv_noop, FAIL);
 
647
 
 
648
    switch (cdata->command) {
 
649
        case H5T_CONV_INIT:
 
650
            cdata->need_bkg = H5T_BKG_NO;
 
651
            break;
 
652
 
 
653
        case H5T_CONV_CONV:
 
654
            /* Nothing to convert */
 
655
            break;
 
656
 
 
657
        case H5T_CONV_FREE:
 
658
            break;
 
659
 
 
660
        default:
 
661
            HGOTO_ERROR (H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, "unknown conversion command");
 
662
    }
 
663
 
 
664
done:
 
665
    FUNC_LEAVE_NOAPI(ret_value);
 
666
}
 
667
 
 
668
 
 
669
/*-------------------------------------------------------------------------
 
670
 * Function:  H5T_conv_order_opt
 
671
 *
 
672
 * Purpose:  Convert one type to another when byte order is the only
 
673
 *    difference. This is the optimized version of H5T_conv_order()
 
674
 *              for a handful of different sizes.
 
675
 *
 
676
 * Note:  This is a soft conversion function.
 
677
 *
 
678
 * Return:  Non-negative on success/Negative on failure
 
679
 *
 
680
 * Programmer:  Robb Matzke
 
681
 *    Friday, January 25, 2002
 
682
 *
 
683
 * Modifications:
 
684
 *
 
685
 *-------------------------------------------------------------------------
 
686
 */
 
687
herr_t
 
688
H5T_conv_order_opt(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
 
689
                   size_t nelmts, size_t buf_stride,
 
690
                   size_t UNUSED bkg_stride, void *_buf,
 
691
                   void UNUSED *background, hid_t UNUSED dxpl_id)
 
692
{
 
693
    uint8_t  *buf = (uint8_t*)_buf;
 
694
    H5T_t  *src = NULL;
 
695
    H5T_t  *dst = NULL;
 
696
    size_t      i;
 
697
    herr_t      ret_value=SUCCEED;       /* Return value */
 
698
 
 
699
    FUNC_ENTER_NOAPI(H5T_conv_order_opt, FAIL);
 
700
 
 
701
    switch (cdata->command) {
 
702
    case H5T_CONV_INIT:
 
703
  /* Capability query */
 
704
  if (NULL == (src = H5I_object(src_id)) ||
 
705
                NULL == (dst = H5I_object(dst_id)))
 
706
      HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a data type");
 
707
  if (src->shared->size != dst->shared->size ||
 
708
                0 != src->shared->u.atomic.offset ||
 
709
                0 != dst->shared->u.atomic.offset ||
 
710
                !((H5T_ORDER_BE == src->shared->u.atomic.order &&
 
711
                   H5T_ORDER_LE == dst->shared->u.atomic.order) ||
 
712
                  (H5T_ORDER_LE == src->shared->u.atomic.order &&
 
713
                   H5T_ORDER_BE == dst->shared->u.atomic.order)))
 
714
      HGOTO_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, "conversion not supported");
 
715
        if (src->shared->size!=1 && src->shared->size!=2 && src->shared->size!=4 &&
 
716
                src->shared->size!=8 && src->shared->size!=16)
 
717
            HGOTO_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, "conversion not supported");
 
718
  switch (src->shared->type) {
 
719
            case H5T_INTEGER:
 
720
            case H5T_BITFIELD:
 
721
                /* nothing to check */
 
722
                break;
 
723
 
 
724
            case H5T_FLOAT:
 
725
                if (src->shared->u.atomic.u.f.sign != dst->shared->u.atomic.u.f.sign ||
 
726
                        src->shared->u.atomic.u.f.epos != dst->shared->u.atomic.u.f.epos ||
 
727
                        src->shared->u.atomic.u.f.esize != dst->shared->u.atomic.u.f.esize ||
 
728
                        src->shared->u.atomic.u.f.ebias != dst->shared->u.atomic.u.f.ebias ||
 
729
                        src->shared->u.atomic.u.f.mpos != dst->shared->u.atomic.u.f.mpos ||
 
730
                        src->shared->u.atomic.u.f.msize != dst->shared->u.atomic.u.f.msize ||
 
731
                        src->shared->u.atomic.u.f.norm != dst->shared->u.atomic.u.f.norm ||
 
732
                        src->shared->u.atomic.u.f.pad != dst->shared->u.atomic.u.f.pad)
 
733
                    HGOTO_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, "conversion not supported");
 
734
                break;
 
735
 
 
736
            default:
 
737
                HGOTO_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, "conversion not supported");
 
738
  }
 
739
  cdata->need_bkg = H5T_BKG_NO;
 
740
  break;
 
741
 
 
742
    case H5T_CONV_CONV:
 
743
  /* The conversion */
 
744
  if (NULL == (src = H5I_object(src_id)) ||
 
745
                NULL == (dst = H5I_object(dst_id)))
 
746
      HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a data type");
 
747
 
 
748
        buf_stride = buf_stride ? buf_stride : src->shared->size;
 
749
        switch (src->shared->size) {
 
750
        case 1:
 
751
            /*no-op*/
 
752
            break;
 
753
        case 2:
 
754
            for (/*void*/; nelmts>=20; nelmts-=20) {
 
755
                H5_SWAP_BYTES(buf, 0,   1); /*  0 */
 
756
                buf += buf_stride;
 
757
                H5_SWAP_BYTES(buf, 0,   1); /*  1 */
 
758
                buf += buf_stride;
 
759
                H5_SWAP_BYTES(buf, 0,   1); /*  2 */
 
760
                buf += buf_stride;
 
761
                H5_SWAP_BYTES(buf, 0,   1); /*  3 */
 
762
                buf += buf_stride;
 
763
                H5_SWAP_BYTES(buf, 0,   1); /*  4 */
 
764
                buf += buf_stride;
 
765
                H5_SWAP_BYTES(buf, 0,   1); /*  5 */
 
766
                buf += buf_stride;
 
767
                H5_SWAP_BYTES(buf, 0,   1); /*  6 */
 
768
                buf += buf_stride;
 
769
                H5_SWAP_BYTES(buf, 0,   1); /*  7 */
 
770
                buf += buf_stride;
 
771
                H5_SWAP_BYTES(buf, 0,   1); /*  8 */
 
772
                buf += buf_stride;
 
773
                H5_SWAP_BYTES(buf, 0,   1); /*  9 */
 
774
                buf += buf_stride;
 
775
                H5_SWAP_BYTES(buf, 0,   1); /* 10 */
 
776
                buf += buf_stride;
 
777
                H5_SWAP_BYTES(buf, 0,   1); /* 11 */
 
778
                buf += buf_stride;
 
779
                H5_SWAP_BYTES(buf, 0,   1); /* 12 */
 
780
                buf += buf_stride;
 
781
                H5_SWAP_BYTES(buf, 0,   1); /* 13 */
 
782
                buf += buf_stride;
 
783
                H5_SWAP_BYTES(buf, 0,   1); /* 14 */
 
784
                buf += buf_stride;
 
785
                H5_SWAP_BYTES(buf, 0,   1); /* 15 */
 
786
                buf += buf_stride;
 
787
                H5_SWAP_BYTES(buf, 0,   1); /* 16 */
 
788
                buf += buf_stride;
 
789
                H5_SWAP_BYTES(buf, 0,   1); /* 17 */
 
790
                buf += buf_stride;
 
791
                H5_SWAP_BYTES(buf, 0,   1); /* 18 */
 
792
                buf += buf_stride;
 
793
                H5_SWAP_BYTES(buf, 0,   1); /* 19 */
 
794
                buf += buf_stride;
 
795
            }
 
796
            for (i=0; i<nelmts; i++, buf+=buf_stride) {
 
797
                H5_SWAP_BYTES(buf, 0, 1);
 
798
            }
 
799
            break;
 
800
        case 4:
 
801
            for (/*void*/; nelmts>=20; nelmts-=20) {
 
802
                H5_SWAP_BYTES(buf,  0,  3); /*  0 */
 
803
                H5_SWAP_BYTES(buf,  1,  2);
 
804
                buf += buf_stride;
 
805
                H5_SWAP_BYTES(buf,  0,  3); /*  1 */
 
806
                H5_SWAP_BYTES(buf,  1,  2);
 
807
                buf += buf_stride;
 
808
                H5_SWAP_BYTES(buf,  0,  3); /*  2 */
 
809
                H5_SWAP_BYTES(buf,  1,  2);
 
810
                buf += buf_stride;
 
811
                H5_SWAP_BYTES(buf,  0,  3); /*  3 */
 
812
                H5_SWAP_BYTES(buf,  1,  2);
 
813
                buf += buf_stride;
 
814
                H5_SWAP_BYTES(buf,  0,  3); /*  4 */
 
815
                H5_SWAP_BYTES(buf,  1,  2);
 
816
                buf += buf_stride;
 
817
                H5_SWAP_BYTES(buf,  0,  3); /*  5 */
 
818
                H5_SWAP_BYTES(buf,  1,  2);
 
819
                buf += buf_stride;
 
820
                H5_SWAP_BYTES(buf,  0,  3); /*  6 */
 
821
                H5_SWAP_BYTES(buf,  1,  2);
 
822
                buf += buf_stride;
 
823
                H5_SWAP_BYTES(buf,  0,  3); /*  7 */
 
824
                H5_SWAP_BYTES(buf,  1,  2);
 
825
                buf += buf_stride;
 
826
                H5_SWAP_BYTES(buf,  0,  3); /*  8 */
 
827
                H5_SWAP_BYTES(buf,  1,  2);
 
828
                buf += buf_stride;
 
829
                H5_SWAP_BYTES(buf,  0,  3); /*  9 */
 
830
                H5_SWAP_BYTES(buf,  1,  2);
 
831
                buf += buf_stride;
 
832
                H5_SWAP_BYTES(buf,  0,  3); /* 10 */
 
833
                H5_SWAP_BYTES(buf,  1,  2);
 
834
                buf += buf_stride;
 
835
                H5_SWAP_BYTES(buf,  0,  3); /* 11 */
 
836
                H5_SWAP_BYTES(buf,  1,  2);
 
837
                buf += buf_stride;
 
838
                H5_SWAP_BYTES(buf,  0,  3); /* 12 */
 
839
                H5_SWAP_BYTES(buf,  1,  2);
 
840
                buf += buf_stride;
 
841
                H5_SWAP_BYTES(buf,  0,  3); /* 13 */
 
842
                H5_SWAP_BYTES(buf,  1,  2);
 
843
                buf += buf_stride;
 
844
                H5_SWAP_BYTES(buf,  0,  3); /* 14 */
 
845
                H5_SWAP_BYTES(buf,  1,  2);
 
846
                buf += buf_stride;
 
847
                H5_SWAP_BYTES(buf,  0,  3); /* 15 */
 
848
                H5_SWAP_BYTES(buf,  1,  2);
 
849
                buf += buf_stride;
 
850
                H5_SWAP_BYTES(buf,  0,  3); /* 16 */
 
851
                H5_SWAP_BYTES(buf,  1,  2);
 
852
                buf += buf_stride;
 
853
                H5_SWAP_BYTES(buf,  0,  3); /* 17 */
 
854
                H5_SWAP_BYTES(buf,  1,  2);
 
855
                buf += buf_stride;
 
856
                H5_SWAP_BYTES(buf,  0,  3); /* 18 */
 
857
                H5_SWAP_BYTES(buf,  1,  2);
 
858
                buf += buf_stride;
 
859
                H5_SWAP_BYTES(buf,  0,  3); /* 19 */
 
860
                H5_SWAP_BYTES(buf,  1,  2);
 
861
                buf += buf_stride;
 
862
            }
 
863
            for (i=0; i<nelmts; i++, buf+=buf_stride) {
 
864
                H5_SWAP_BYTES(buf, 0, 3);
 
865
                H5_SWAP_BYTES(buf, 1, 2);
 
866
            }
 
867
            break;
 
868
        case 8:
 
869
            for (/*void*/; nelmts>=10; nelmts-=10) {
 
870
                H5_SWAP_BYTES(buf,  0,  7); /*  0 */
 
871
                H5_SWAP_BYTES(buf,  1,  6);
 
872
                H5_SWAP_BYTES(buf,  2,  5);
 
873
                H5_SWAP_BYTES(buf,  3,  4);
 
874
                buf += buf_stride;
 
875
                H5_SWAP_BYTES(buf,  0,  7); /*  1 */
 
876
                H5_SWAP_BYTES(buf,  1,  6);
 
877
                H5_SWAP_BYTES(buf,  2,  5);
 
878
                H5_SWAP_BYTES(buf,  3,  4);
 
879
                buf += buf_stride;
 
880
                H5_SWAP_BYTES(buf,  0,  7); /*  2 */
 
881
                H5_SWAP_BYTES(buf,  1,  6);
 
882
                H5_SWAP_BYTES(buf,  2,  5);
 
883
                H5_SWAP_BYTES(buf,  3,  4);
 
884
                buf += buf_stride;
 
885
                H5_SWAP_BYTES(buf,  0,  7); /*  3 */
 
886
                H5_SWAP_BYTES(buf,  1,  6);
 
887
                H5_SWAP_BYTES(buf,  2,  5);
 
888
                H5_SWAP_BYTES(buf,  3,  4);
 
889
                buf += buf_stride;
 
890
                H5_SWAP_BYTES(buf,  0,  7); /*  4 */
 
891
                H5_SWAP_BYTES(buf,  1,  6);
 
892
                H5_SWAP_BYTES(buf,  2,  5);
 
893
                H5_SWAP_BYTES(buf,  3,  4);
 
894
                buf += buf_stride;
 
895
                H5_SWAP_BYTES(buf,  0,  7); /*  5 */
 
896
                H5_SWAP_BYTES(buf,  1,  6);
 
897
                H5_SWAP_BYTES(buf,  2,  5);
 
898
                H5_SWAP_BYTES(buf,  3,  4);
 
899
                buf += buf_stride;
 
900
                H5_SWAP_BYTES(buf,  0,  7); /*  6 */
 
901
                H5_SWAP_BYTES(buf,  1,  6);
 
902
                H5_SWAP_BYTES(buf,  2,  5);
 
903
                H5_SWAP_BYTES(buf,  3,  4);
 
904
                buf += buf_stride;
 
905
                H5_SWAP_BYTES(buf,  0,  7); /*  7 */
 
906
                H5_SWAP_BYTES(buf,  1,  6);
 
907
                H5_SWAP_BYTES(buf,  2,  5);
 
908
                H5_SWAP_BYTES(buf,  3,  4);
 
909
                buf += buf_stride;
 
910
                H5_SWAP_BYTES(buf,  0,  7); /*  8 */
 
911
                H5_SWAP_BYTES(buf,  1,  6);
 
912
                H5_SWAP_BYTES(buf,  2,  5);
 
913
                H5_SWAP_BYTES(buf,  3,  4);
 
914
                buf += buf_stride;
 
915
                H5_SWAP_BYTES(buf,  0,  7); /*  9 */
 
916
                H5_SWAP_BYTES(buf,  1,  6);
 
917
                H5_SWAP_BYTES(buf,  2,  5);
 
918
                H5_SWAP_BYTES(buf,  3,  4);
 
919
                buf += buf_stride;
 
920
            }
 
921
            for (i=0; i<nelmts; i++, buf+=buf_stride) {
 
922
                H5_SWAP_BYTES(buf, 0, 7);
 
923
                H5_SWAP_BYTES(buf, 1, 6);
 
924
                H5_SWAP_BYTES(buf, 2, 5);
 
925
                H5_SWAP_BYTES(buf, 3, 4);
 
926
            }
 
927
            break;
 
928
        case 16:
 
929
            for (/*void*/; nelmts>=10; nelmts-=10) {
 
930
                H5_SWAP_BYTES(buf,   0,  15); /*  0 */
 
931
                H5_SWAP_BYTES(buf,   1,  14);
 
932
                H5_SWAP_BYTES(buf,   2,  13);
 
933
                H5_SWAP_BYTES(buf,   3,  12);
 
934
                H5_SWAP_BYTES(buf,   4,  11);
 
935
                H5_SWAP_BYTES(buf,   5,  10);
 
936
                H5_SWAP_BYTES(buf,   6,   9);
 
937
                H5_SWAP_BYTES(buf,   7,   8);
 
938
                buf += buf_stride;
 
939
                H5_SWAP_BYTES(buf,   0,  15); /*  1 */
 
940
                H5_SWAP_BYTES(buf,   1,  14);
 
941
                H5_SWAP_BYTES(buf,   2,  13);
 
942
                H5_SWAP_BYTES(buf,   3,  12);
 
943
                H5_SWAP_BYTES(buf,   4,  11);
 
944
                H5_SWAP_BYTES(buf,   5,  10);
 
945
                H5_SWAP_BYTES(buf,   6,   9);
 
946
                H5_SWAP_BYTES(buf,   7,   8);
 
947
                buf += buf_stride;
 
948
                H5_SWAP_BYTES(buf,   0,  15); /*  2 */
 
949
                H5_SWAP_BYTES(buf,   1,  14);
 
950
                H5_SWAP_BYTES(buf,   2,  13);
 
951
                H5_SWAP_BYTES(buf,   3,  12);
 
952
                H5_SWAP_BYTES(buf,   4,  11);
 
953
                H5_SWAP_BYTES(buf,   5,  10);
 
954
                H5_SWAP_BYTES(buf,   6,   9);
 
955
                H5_SWAP_BYTES(buf,   7,   8);
 
956
                buf += buf_stride;
 
957
                H5_SWAP_BYTES(buf,   0,  15); /*  3 */
 
958
                H5_SWAP_BYTES(buf,   1,  14);
 
959
                H5_SWAP_BYTES(buf,   2,  13);
 
960
                H5_SWAP_BYTES(buf,   3,  12);
 
961
                H5_SWAP_BYTES(buf,   4,  11);
 
962
                H5_SWAP_BYTES(buf,   5,  10);
 
963
                H5_SWAP_BYTES(buf,   6,   9);
 
964
                H5_SWAP_BYTES(buf,   7,   8);
 
965
                buf += buf_stride;
 
966
                H5_SWAP_BYTES(buf,   0,  15); /*  4 */
 
967
                H5_SWAP_BYTES(buf,   1,  14);
 
968
                H5_SWAP_BYTES(buf,   2,  13);
 
969
                H5_SWAP_BYTES(buf,   3,  12);
 
970
                H5_SWAP_BYTES(buf,   4,  11);
 
971
                H5_SWAP_BYTES(buf,   5,  10);
 
972
                H5_SWAP_BYTES(buf,   6,   9);
 
973
                H5_SWAP_BYTES(buf,   7,   8);
 
974
                buf += buf_stride;
 
975
                H5_SWAP_BYTES(buf,   0,  15); /*  5 */
 
976
                H5_SWAP_BYTES(buf,   1,  14);
 
977
                H5_SWAP_BYTES(buf,   2,  13);
 
978
                H5_SWAP_BYTES(buf,   3,  12);
 
979
                H5_SWAP_BYTES(buf,   4,  11);
 
980
                H5_SWAP_BYTES(buf,   5,  10);
 
981
                H5_SWAP_BYTES(buf,   6,   9);
 
982
                H5_SWAP_BYTES(buf,   7,   8);
 
983
                buf += buf_stride;
 
984
                H5_SWAP_BYTES(buf,   0,  15); /*  6 */
 
985
                H5_SWAP_BYTES(buf,   1,  14);
 
986
                H5_SWAP_BYTES(buf,   2,  13);
 
987
                H5_SWAP_BYTES(buf,   3,  12);
 
988
                H5_SWAP_BYTES(buf,   4,  11);
 
989
                H5_SWAP_BYTES(buf,   5,  10);
 
990
                H5_SWAP_BYTES(buf,   6,   9);
 
991
                H5_SWAP_BYTES(buf,   7,   8);
 
992
                buf += buf_stride;
 
993
                H5_SWAP_BYTES(buf,   0,  15); /*  7 */
 
994
                H5_SWAP_BYTES(buf,   1,  14);
 
995
                H5_SWAP_BYTES(buf,   2,  13);
 
996
                H5_SWAP_BYTES(buf,   3,  12);
 
997
                H5_SWAP_BYTES(buf,   4,  11);
 
998
                H5_SWAP_BYTES(buf,   5,  10);
 
999
                H5_SWAP_BYTES(buf,   6,   9);
 
1000
                H5_SWAP_BYTES(buf,   7,   8);
 
1001
                buf += buf_stride;
 
1002
                H5_SWAP_BYTES(buf,   0,  15); /*  8 */
 
1003
                H5_SWAP_BYTES(buf,   1,  14);
 
1004
                H5_SWAP_BYTES(buf,   2,  13);
 
1005
                H5_SWAP_BYTES(buf,   3,  12);
 
1006
                H5_SWAP_BYTES(buf,   4,  11);
 
1007
                H5_SWAP_BYTES(buf,   5,  10);
 
1008
                H5_SWAP_BYTES(buf,   6,   9);
 
1009
                H5_SWAP_BYTES(buf,   7,   8);
 
1010
                buf += buf_stride;
 
1011
                H5_SWAP_BYTES(buf,   0,  15); /*  9 */
 
1012
                H5_SWAP_BYTES(buf,   1,  14);
 
1013
                H5_SWAP_BYTES(buf,   2,  13);
 
1014
                H5_SWAP_BYTES(buf,   3,  12);
 
1015
                H5_SWAP_BYTES(buf,   4,  11);
 
1016
                H5_SWAP_BYTES(buf,   5,  10);
 
1017
                H5_SWAP_BYTES(buf,   6,   9);
 
1018
                H5_SWAP_BYTES(buf,   7,   8);
 
1019
                buf += buf_stride;
 
1020
            }
 
1021
            for (i=0; i<nelmts; i++, buf+=buf_stride) {
 
1022
                H5_SWAP_BYTES(buf, 0, 15);
 
1023
                H5_SWAP_BYTES(buf, 1, 14);
 
1024
                H5_SWAP_BYTES(buf, 2, 13);
 
1025
                H5_SWAP_BYTES(buf, 3, 12);
 
1026
                H5_SWAP_BYTES(buf, 4, 11);
 
1027
                H5_SWAP_BYTES(buf, 5, 10);
 
1028
                H5_SWAP_BYTES(buf, 6,  9);
 
1029
                H5_SWAP_BYTES(buf, 7,  8);
 
1030
            }
 
1031
            break;
 
1032
        }
 
1033
        break;
 
1034
 
 
1035
    case H5T_CONV_FREE:
 
1036
  /* Free private data */
 
1037
  break;
 
1038
 
 
1039
    default:
 
1040
  HGOTO_ERROR (H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, "unknown conversion command");
 
1041
    }
 
1042
 
 
1043
done:
 
1044
    FUNC_LEAVE_NOAPI(ret_value);
 
1045
}
 
1046
 
 
1047
 
 
1048
/*-------------------------------------------------------------------------
 
1049
 * Function:  H5T_conv_order
 
1050
 *
 
1051
 * Purpose:  Convert one type to another when byte order is the only
 
1052
 *    difference.
 
1053
 *
 
1054
 * Note:  This is a soft conversion function.
 
1055
 *
 
1056
 * Return:  Non-negative on success/Negative on failure
 
1057
 *
 
1058
 * Programmer:  Robb Matzke
 
1059
 *    Tuesday, January 13, 1998
 
1060
 *
 
1061
 * Modifications:
 
1062
 *    Robb Matzke, 1999-06-16
 
1063
 *    Added the `stride' argument. If its value is non-zero then we
 
1064
 *    stride through memory converting one value at each location;
 
1065
 *    otherwise we assume that the values should be packed.
 
1066
 *
 
1067
 *     Robb Matzke, 1999-06-16
 
1068
 *    Added support for bitfields.
 
1069
 *-------------------------------------------------------------------------
 
1070
 */
 
1071
herr_t
 
1072
H5T_conv_order(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, size_t nelmts,
 
1073
         size_t buf_stride, size_t UNUSED bkg_stride, void *_buf,
 
1074
               void UNUSED *background, hid_t UNUSED dxpl_id)
 
1075
{
 
1076
    uint8_t  *buf = (uint8_t*)_buf;
 
1077
    H5T_t  *src = NULL;
 
1078
    H5T_t  *dst = NULL;
 
1079
    size_t  i;
 
1080
    size_t  j, md;
 
1081
    herr_t      ret_value=SUCCEED;       /* Return value */
 
1082
 
 
1083
    FUNC_ENTER_NOAPI(H5T_conv_order, FAIL);
 
1084
 
 
1085
    switch (cdata->command) {
 
1086
    case H5T_CONV_INIT:
 
1087
  /* Capability query */
 
1088
  if (NULL == (src = H5I_object(src_id)) ||
 
1089
                NULL == (dst = H5I_object(dst_id)))
 
1090
      HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a data type");
 
1091
  if (src->shared->size != dst->shared->size || 0 != src->shared->u.atomic.offset ||
 
1092
                0 != dst->shared->u.atomic.offset ||
 
1093
                !((H5T_ORDER_BE == src->shared->u.atomic.order &&
 
1094
                   H5T_ORDER_LE == dst->shared->u.atomic.order) ||
 
1095
                  (H5T_ORDER_LE == src->shared->u.atomic.order &&
 
1096
                   H5T_ORDER_BE == dst->shared->u.atomic.order)))
 
1097
      HGOTO_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, "conversion not supported");
 
1098
  switch (src->shared->type) {
 
1099
            case H5T_INTEGER:
 
1100
            case H5T_BITFIELD:
 
1101
                /* nothing to check */
 
1102
                break;
 
1103
 
 
1104
            case H5T_FLOAT:
 
1105
                if (src->shared->u.atomic.u.f.sign != dst->shared->u.atomic.u.f.sign ||
 
1106
                        src->shared->u.atomic.u.f.epos != dst->shared->u.atomic.u.f.epos ||
 
1107
                        src->shared->u.atomic.u.f.esize != dst->shared->u.atomic.u.f.esize ||
 
1108
                        src->shared->u.atomic.u.f.ebias != dst->shared->u.atomic.u.f.ebias ||
 
1109
                        src->shared->u.atomic.u.f.mpos != dst->shared->u.atomic.u.f.mpos ||
 
1110
                        src->shared->u.atomic.u.f.msize != dst->shared->u.atomic.u.f.msize ||
 
1111
                        src->shared->u.atomic.u.f.norm != dst->shared->u.atomic.u.f.norm ||
 
1112
                        src->shared->u.atomic.u.f.pad != dst->shared->u.atomic.u.f.pad) {
 
1113
                    HGOTO_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, "conversion not supported");
 
1114
                }
 
1115
                break;
 
1116
 
 
1117
            default:
 
1118
                HGOTO_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, "conversion not supported");
 
1119
  }
 
1120
  cdata->need_bkg = H5T_BKG_NO;
 
1121
  break;
 
1122
 
 
1123
    case H5T_CONV_CONV:
 
1124
  /* The conversion */
 
1125
  if (NULL == (src = H5I_object(src_id)) ||
 
1126
                NULL == (dst = H5I_object(dst_id)))
 
1127
      HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a data type");
 
1128
 
 
1129
        buf_stride = buf_stride ? buf_stride : src->shared->size;
 
1130
        md = src->shared->size / 2;
 
1131
        for (i=0; i<nelmts; i++, buf+=buf_stride) {
 
1132
            for (j=0; j<md; j++)
 
1133
                H5_SWAP_BYTES(buf, j, src->shared->size-(j+1));
 
1134
        }
 
1135
        break;
 
1136
 
 
1137
    case H5T_CONV_FREE:
 
1138
  /* Free private data */
 
1139
  break;
 
1140
 
 
1141
    default:
 
1142
  HGOTO_ERROR (H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, "unknown conversion command");
 
1143
    }
 
1144
 
 
1145
done:
 
1146
    FUNC_LEAVE_NOAPI(ret_value);
 
1147
}
 
1148
 
 
1149
 
 
1150
/*-------------------------------------------------------------------------
 
1151
 * Function:  H5T_conv_b_b
 
1152
 *
 
1153
 * Purpose:  Convert from one bitfield to any other bitfield.
 
1154
 *
 
1155
 * Return:  Non-negative on success/Negative on failure
 
1156
 *
 
1157
 * Programmer:  Robb Matzke
 
1158
 *    Thursday, May 20, 1999
 
1159
 *
 
1160
 * Modifications:
 
1161
 *    Robb Matzke, 1999-06-16
 
1162
 *    Added support for non-zero strides. If BUF_STRIDE is non-zero
 
1163
 *    then convert one value at each memory location advancing
 
1164
 *    BUF_STRIDE bytes each time; otherwise assume both source and
 
1165
 *    destination values are packed.
 
1166
 *-------------------------------------------------------------------------
 
1167
 */
 
1168
herr_t
 
1169
H5T_conv_b_b(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, size_t nelmts,
 
1170
       size_t buf_stride, size_t UNUSED bkg_stride, void *_buf,
 
1171
             void UNUSED *background, hid_t UNUSED dxpl_id)
 
1172
{
 
1173
    uint8_t  *buf = (uint8_t*)_buf;
 
1174
    H5T_t  *src=NULL, *dst=NULL;  /*source and dest data types  */
 
1175
    int  direction;    /*direction of traversal  */
 
1176
    size_t  elmtno;      /*element number    */
 
1177
    size_t  olap;      /*num overlapping elements  */
 
1178
    size_t  half_size;    /*1/2 of total size for swapping*/
 
1179
    uint8_t  *s, *sp, *d, *dp;  /*source and dest traversal ptrs*/
 
1180
    uint8_t  dbuf[256];    /*temp destination buffer  */
 
1181
    size_t  msb_pad_offset;    /*offset for dest MSB padding  */
 
1182
    size_t  i;
 
1183
    herr_t      ret_value=SUCCEED;      /* Return value */
 
1184
 
 
1185
    FUNC_ENTER_NOAPI(H5T_conv_b_b, FAIL);
 
1186
 
 
1187
    switch(cdata->command) {
 
1188
        case H5T_CONV_INIT:
 
1189
            /* Capability query */
 
1190
            if (NULL == (src = H5I_object(src_id)) ||
 
1191
                    NULL == (dst = H5I_object(dst_id)))
 
1192
                HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a data type");
 
1193
            if (H5T_ORDER_LE!=src->shared->u.atomic.order &&
 
1194
                    H5T_ORDER_BE!=src->shared->u.atomic.order)
 
1195
                HGOTO_ERROR (H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, "unsupported byte order");
 
1196
            if (H5T_ORDER_LE!=dst->shared->u.atomic.order &&
 
1197
                    H5T_ORDER_BE!=dst->shared->u.atomic.order)
 
1198
                HGOTO_ERROR (H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, "unsupported byte order");
 
1199
            cdata->need_bkg = H5T_BKG_NO;
 
1200
            break;
 
1201
 
 
1202
        case H5T_CONV_FREE:
 
1203
            break;
 
1204
 
 
1205
        case H5T_CONV_CONV:
 
1206
            /* Get the data types */
 
1207
            if (NULL==(src=H5I_object(src_id)) ||
 
1208
                    NULL==(dst=H5I_object(dst_id)))
 
1209
                HGOTO_ERROR (H5E_ARGS, H5E_BADTYPE, FAIL, "not a data type");
 
1210
 
 
1211
            /*
 
1212
             * Do we process the values from beginning to end or vice versa? Also,
 
1213
             * how many of the elements have the source and destination areas
 
1214
             * overlapping?
 
1215
             */
 
1216
            if (src->shared->size==dst->shared->size || buf_stride) {
 
1217
                sp = dp = (uint8_t*)buf;
 
1218
                direction = 1;
 
1219
                olap = nelmts;
 
1220
            } else if (src->shared->size>=dst->shared->size) {
 
1221
                double olap_d = HDceil((double)(dst->shared->size)/
 
1222
                                       (double)(src->shared->size-dst->shared->size));
 
1223
 
 
1224
                olap = (size_t)olap_d;
 
1225
                sp = dp = (uint8_t*)buf;
 
1226
                direction = 1;
 
1227
            } else {
 
1228
                double olap_d = HDceil((double)(src->shared->size)/
 
1229
                                       (double)(dst->shared->size-src->shared->size));
 
1230
                olap = (size_t)olap_d;
 
1231
                sp = (uint8_t*)buf + (nelmts-1) * src->shared->size;
 
1232
                dp = (uint8_t*)buf + (nelmts-1) * dst->shared->size;
 
1233
                direction = -1;
 
1234
            }
 
1235
 
 
1236
            /* The conversion loop */
 
1237
            for (elmtno=0; elmtno<nelmts; elmtno++) {
 
1238
 
 
1239
                /*
 
1240
                 * If the source and destination buffers overlap then use a
 
1241
                 * temporary buffer for the destination.
 
1242
                 */
 
1243
                if (direction>0) {
 
1244
                    s = sp;
 
1245
                    d = elmtno<olap ? dbuf : dp;
 
1246
                } else {
 
1247
                    s = sp;
 
1248
                    d = elmtno+olap >= nelmts ? dbuf : dp;
 
1249
                }
 
1250
#ifndef NDEBUG
 
1251
                /* I don't quite trust the overlap calculations yet --rpm */
 
1252
                if (d==dbuf) {
 
1253
                    assert ((dp>=sp && dp<sp+src->shared->size) ||
 
1254
                            (sp>=dp && sp<dp+dst->shared->size));
 
1255
                } else {
 
1256
                    assert ((dp<sp && dp+dst->shared->size<=sp) ||
 
1257
                            (sp<dp && sp+src->shared->size<=dp));
 
1258
                }
 
1259
#endif
 
1260
 
 
1261
                /*
 
1262
                 * Put the data in little endian order so our loops aren't so
 
1263
                 * complicated.  We'll do all the conversion stuff assuming
 
1264
                 * little endian and then we'll fix the order at the end.
 
1265
                 */
 
1266
                if (H5T_ORDER_BE==src->shared->u.atomic.order) {
 
1267
                    half_size = src->shared->size/2;
 
1268
                    for (i=0; i<half_size; i++) {
 
1269
                        uint8_t tmp = s[src->shared->size-(i+1)];
 
1270
                        s[src->shared->size-(i+1)] = s[i];
 
1271
                        s[i] = tmp;
 
1272
                    }
 
1273
                }
 
1274
 
 
1275
                /*
 
1276
                 * Copy the significant part of the value. If the source is larger
 
1277
                 * than the destination then invoke the overflow function or copy
 
1278
                 * as many bits as possible. Zero extra bits in the destination.
 
1279
                 */
 
1280
                if (src->shared->u.atomic.prec>dst->shared->u.atomic.prec) {
 
1281
                    if (!H5T_overflow_g ||
 
1282
                        (H5T_overflow_g)(src_id, dst_id, s, d)<0) {
 
1283
                        H5T_bit_copy(d, dst->shared->u.atomic.offset,
 
1284
                                     s, src->shared->u.atomic.offset, dst->shared->u.atomic.prec);
 
1285
                    }
 
1286
                } else {
 
1287
                    H5T_bit_copy(d, dst->shared->u.atomic.offset,
 
1288
                                 s, src->shared->u.atomic.offset,
 
1289
                                 src->shared->u.atomic.prec);
 
1290
                    H5T_bit_set(d, dst->shared->u.atomic.offset+src->shared->u.atomic.prec,
 
1291
                                dst->shared->u.atomic.prec-src->shared->u.atomic.prec, FALSE);
 
1292
                }
 
1293
 
 
1294
                /*
 
1295
                 * Fill the destination padding areas.
 
1296
                 */
 
1297
                switch (dst->shared->u.atomic.lsb_pad) {
 
1298
                    case H5T_PAD_ZERO:
 
1299
                        H5T_bit_set(d, 0, dst->shared->u.atomic.offset, FALSE);
 
1300
                        break;
 
1301
                    case H5T_PAD_ONE:
 
1302
                        H5T_bit_set(d, 0, dst->shared->u.atomic.offset, TRUE);
 
1303
                        break;
 
1304
                    default:
 
1305
                        HGOTO_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, "unsupported LSB padding");
 
1306
                }
 
1307
                msb_pad_offset = dst->shared->u.atomic.offset + dst->shared->u.atomic.prec;
 
1308
                switch (dst->shared->u.atomic.msb_pad) {
 
1309
                    case H5T_PAD_ZERO:
 
1310
                        H5T_bit_set(d, msb_pad_offset, 8*dst->shared->size-msb_pad_offset,
 
1311
                                    FALSE);
 
1312
                        break;
 
1313
                    case H5T_PAD_ONE:
 
1314
                        H5T_bit_set(d, msb_pad_offset, 8*dst->shared->size-msb_pad_offset,
 
1315
                                    TRUE);
 
1316
                        break;
 
1317
                    default:
 
1318
                        HGOTO_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, "unsupported MSB padding");
 
1319
                }
 
1320
 
 
1321
                /*
 
1322
                 * Put the destination in the correct byte order.  See note at
 
1323
                 * beginning of loop.
 
1324
                 */
 
1325
                if (H5T_ORDER_BE==dst->shared->u.atomic.order) {
 
1326
                    half_size = dst->shared->size/2;
 
1327
                    for (i=0; i<half_size; i++) {
 
1328
                        uint8_t tmp = d[dst->shared->size-(i+1)];
 
1329
                        d[dst->shared->size-(i+1)] = d[i];
 
1330
                        d[i] = tmp;
 
1331
                    }
 
1332
                }
 
1333
 
 
1334
                /*
 
1335
                 * If we had used a temporary buffer for the destination then we
 
1336
                 * should copy the value to the true destination buffer.
 
1337
                 */
 
1338
                if (d==dbuf) HDmemcpy (dp, d, dst->shared->size);
 
1339
                if (buf_stride) {
 
1340
                    sp += direction * buf_stride;
 
1341
                    dp += direction * buf_stride;
 
1342
                } else {
 
1343
                    sp += direction * src->shared->size;
 
1344
                    dp += direction * dst->shared->size;
 
1345
                }
 
1346
            }
 
1347
 
 
1348
            break;
 
1349
 
 
1350
        default:
 
1351
            HGOTO_ERROR (H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, "unknown conversion command");
 
1352
    }
 
1353
 
 
1354
done:
 
1355
    FUNC_LEAVE_NOAPI(ret_value);
 
1356
}
 
1357
 
 
1358
 
 
1359
/*-------------------------------------------------------------------------
 
1360
 * Function:  H5T_conv_struct_init
 
1361
 *
 
1362
 * Purpose:  Initialize the `priv' field of `cdata' with conversion
 
1363
 *    information that is relatively constant.  If `priv' is
 
1364
 *    already initialized then the member conversion functions
 
1365
 *    are recalculated.
 
1366
 *
 
1367
 *    Priv fields are indexed by source member number or
 
1368
 *    destination member number depending on whether the field
 
1369
 *    contains information about the source data type or the
 
1370
 *    destination data type (fields that contains the same
 
1371
 *    information for both source and destination are indexed by
 
1372
 *    source member number).  The src2dst[] priv array maps source
 
1373
 *    member numbers to destination member numbers, but if the
 
1374
 *    source member doesn't have a corresponding destination member
 
1375
 *    then the src2dst[i]=-1.
 
1376
 *
 
1377
 * Return:  Non-negative on success/Negative on failure
 
1378
 *
 
1379
 * Programmer:  Robb Matzke
 
1380
 *    Monday, January 26, 1998
 
1381
 *
 
1382
 * Modifications:
 
1383
 *
 
1384
 *-------------------------------------------------------------------------
 
1385
 */
 
1386
static herr_t
 
1387
H5T_conv_struct_init (H5T_t *src, H5T_t *dst, H5T_cdata_t *cdata, hid_t dxpl_id)
 
1388
{
 
1389
    H5T_conv_struct_t  *priv = (H5T_conv_struct_t*)(cdata->priv);
 
1390
    int    *src2dst = NULL;
 
1391
    unsigned    i, j;
 
1392
    H5T_t    *type = NULL;
 
1393
    hid_t    tid;
 
1394
    herr_t      ret_value=SUCCEED;       /* Return value */
 
1395
 
 
1396
    FUNC_ENTER_NOAPI_NOINIT(H5T_conv_struct_init);
 
1397
 
 
1398
    if (!priv) {
 
1399
        /*
 
1400
         * Allocate private data structure and arrays.
 
1401
         */
 
1402
        if (NULL==(priv=cdata->priv=H5MM_calloc(sizeof(H5T_conv_struct_t))) ||
 
1403
                NULL==(priv->src2dst=H5MM_malloc(src->shared->u.compnd.nmembs *
 
1404
                                 sizeof(int))) ||
 
1405
                NULL==(priv->src_memb_id=H5MM_malloc(src->shared->u.compnd.nmembs *
 
1406
                                    sizeof(hid_t))) ||
 
1407
                NULL==(priv->dst_memb_id=H5MM_malloc(dst->shared->u.compnd.nmembs *
 
1408
                                    sizeof(hid_t))))
 
1409
            HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed");
 
1410
        src2dst = priv->src2dst;
 
1411
 
 
1412
        /*
 
1413
         * Insure that members are sorted.
 
1414
         */
 
1415
        H5T_sort_value(src, NULL);
 
1416
        H5T_sort_value(dst, NULL);
 
1417
 
 
1418
        /*
 
1419
         * Build a mapping from source member number to destination member
 
1420
         * number. If some source member is not a destination member then that
 
1421
         * mapping element will be negative.  Also create atoms for each
 
1422
         * source and destination member data type so we can look up the
 
1423
         * member data type conversion functions later.
 
1424
         */
 
1425
        for (i=0; i<src->shared->u.compnd.nmembs; i++) {
 
1426
            src2dst[i] = -1;
 
1427
            for (j=0; j<dst->shared->u.compnd.nmembs; j++) {
 
1428
                if (!HDstrcmp (src->shared->u.compnd.memb[i].name,
 
1429
                       dst->shared->u.compnd.memb[j].name)) {
 
1430
                    src2dst[i] = j;
 
1431
                    break;
 
1432
                }
 
1433
            }
 
1434
            if (src2dst[i]>=0) {
 
1435
                type = H5T_copy (src->shared->u.compnd.memb[i].type, H5T_COPY_ALL);
 
1436
                tid = H5I_register (H5I_DATATYPE, type);
 
1437
                assert (tid>=0);
 
1438
                priv->src_memb_id[i] = tid;
 
1439
 
 
1440
                type = H5T_copy (dst->shared->u.compnd.memb[src2dst[i]].type,
 
1441
                     H5T_COPY_ALL);
 
1442
                tid = H5I_register (H5I_DATATYPE, type);
 
1443
                assert (tid>=0);
 
1444
                priv->dst_memb_id[src2dst[i]] = tid;
 
1445
            }
 
1446
        }
 
1447
    }
 
1448
    else {
 
1449
        /* Restore sorted conditions for the datatypes */
 
1450
        /* (Required for the src2dst array to be valid) */
 
1451
        H5T_sort_value(src, NULL);
 
1452
        H5T_sort_value(dst, NULL);
 
1453
    } /* end else */
 
1454
 
 
1455
    /*
 
1456
     * (Re)build the cache of member conversion functions and pointers to
 
1457
     * their cdata entries.
 
1458
     */
 
1459
    src2dst = priv->src2dst;
 
1460
    H5MM_xfree(priv->memb_path);
 
1461
    if (NULL==(priv->memb_path=H5MM_malloc(src->shared->u.compnd.nmembs *
 
1462
             sizeof(H5T_path_t*))))
 
1463
        HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed");
 
1464
 
 
1465
    for (i=0; i<src->shared->u.compnd.nmembs; i++) {
 
1466
        if (src2dst[i]>=0) {
 
1467
            H5T_path_t *tpath = H5T_path_find(src->shared->u.compnd.memb[i].type,
 
1468
                      dst->shared->u.compnd.memb[src2dst[i]].type, NULL, NULL, dxpl_id);
 
1469
 
 
1470
            if (NULL==(priv->memb_path[i] = tpath)) {
 
1471
                H5MM_xfree(priv->src2dst);
 
1472
                H5MM_xfree(priv->src_memb_id);
 
1473
                H5MM_xfree(priv->dst_memb_id);
 
1474
                H5MM_xfree(priv->memb_path);
 
1475
                cdata->priv = priv = H5MM_xfree (priv);
 
1476
                HGOTO_ERROR (H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, "unable to convert member data type");
 
1477
            }
 
1478
        }
 
1479
    }
 
1480
 
 
1481
    /* Check if we need a background buffer */
 
1482
    if (H5T_detect_class(src,H5T_COMPOUND)==TRUE || H5T_detect_class(dst,H5T_COMPOUND)==TRUE)
 
1483
        cdata->need_bkg = H5T_BKG_YES;
 
1484
 
 
1485
    cdata->recalc = FALSE;
 
1486
 
 
1487
done:
 
1488
    FUNC_LEAVE_NOAPI(ret_value);
 
1489
}
 
1490
 
 
1491
 
 
1492
/*-------------------------------------------------------------------------
 
1493
 * Function:  H5T_conv_struct
 
1494
 *
 
1495
 * Purpose:  Converts between compound data types.  This is a soft
 
1496
 *    conversion function.  The algorithm is basically:
 
1497
 *
 
1498
 *     For each element do
 
1499
 *      For I=1..NELMTS do
 
1500
 *        If sizeof detination type <= sizeof source type then
 
1501
 *          Convert member to destination type;
 
1502
 *        Move member as far left as possible;
 
1503
 *
 
1504
 *      For I=NELMTS..1 do
 
1505
 *        If not destination type then
 
1506
 *          Convert member to destination type;
 
1507
 *        Move member to correct position in BKG
 
1508
 *
 
1509
 *      Copy BKG to BUF
 
1510
 *
 
1511
 * Return:  Non-negative on success/Negative on failure
 
1512
 *
 
1513
 * Programmer:  Robb Matzke
 
1514
 *    Thursday, January 22, 1998
 
1515
 *
 
1516
 * Modifications:
 
1517
 *    Robb Matzke, 1999-06-16
 
1518
 *              Added support for non-zero strides. If BUF_STRIDE is
 
1519
 *              non-zero then convert one value at each memory location
 
1520
 *              advancing BUF_STRIDE bytes each time; otherwise assume
 
1521
 *              both source and destination values are packed.
 
1522
 *
 
1523
 *              Robb Matzke, 2000-05-17
 
1524
 *              Added the BKG_STRIDE argument to fix a design bug. If
 
1525
 *              BUF_STRIDE and BKG_STRIDE are both non-zero then each
 
1526
 *              data element converted will be placed temporarily at a
 
1527
 *              multiple of BKG_STRIDE in the BKG buffer; otherwise the
 
1528
 *              BKG buffer is assumed to be a packed array of destination
 
1529
 *              datatype.
 
1530
 *-------------------------------------------------------------------------
 
1531
 */
 
1532
herr_t
 
1533
H5T_conv_struct(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, size_t nelmts,
 
1534
    size_t buf_stride, size_t bkg_stride, void *_buf, void *_bkg,
 
1535
                hid_t dxpl_id)
 
1536
{
 
1537
    uint8_t  *buf = (uint8_t *)_buf;  /*cast for pointer arithmetic  */
 
1538
    uint8_t  *bkg = (uint8_t *)_bkg;  /*background pointer arithmetic  */
 
1539
    uint8_t     *xbuf=buf, *xbkg=bkg;   /*temp pointers into buf and bkg*/
 
1540
    H5T_t  *src = NULL;    /*source data type    */
 
1541
    H5T_t  *dst = NULL;    /*destination data type    */
 
1542
    int  *src2dst = NULL;  /*maps src member to dst member  */
 
1543
    H5T_cmemb_t  *src_memb = NULL;  /*source struct member descript.*/
 
1544
    H5T_cmemb_t  *dst_memb = NULL;  /*destination struct memb desc.  */
 
1545
    size_t  offset;      /*byte offset wrt struct  */
 
1546
    size_t  src_delta;      /*source stride  */
 
1547
    size_t  elmtno;
 
1548
    unsigned  u;    /*counters      */
 
1549
    int  i;      /*counters      */
 
1550
    H5T_conv_struct_t *priv = (H5T_conv_struct_t *)(cdata->priv);
 
1551
    herr_t      ret_value=SUCCEED;       /* Return value */
 
1552
 
 
1553
    FUNC_ENTER_NOAPI(H5T_conv_struct, FAIL);
 
1554
 
 
1555
    switch (cdata->command) {
 
1556
        case H5T_CONV_INIT:
 
1557
            /*
 
1558
             * First, determine if this conversion function applies to the
 
1559
             * conversion path SRC_ID-->DST_ID.  If not, return failure;
 
1560
             * otherwise initialize the `priv' field of `cdata' with information
 
1561
             * that remains (almost) constant for this conversion path.
 
1562
             */
 
1563
            if (NULL == (src = H5I_object(src_id)) ||
 
1564
                    NULL == (dst = H5I_object(dst_id)))
 
1565
                HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a data type");
 
1566
            assert (H5T_COMPOUND==src->shared->type);
 
1567
            assert (H5T_COMPOUND==dst->shared->type);
 
1568
 
 
1569
            if (H5T_conv_struct_init (src, dst, cdata, dxpl_id)<0)
 
1570
                HGOTO_ERROR (H5E_DATATYPE, H5E_CANTINIT, FAIL, "unable to initialize conversion data");
 
1571
            break;
 
1572
 
 
1573
        case H5T_CONV_FREE:
 
1574
            /*
 
1575
             * Free the private conversion data.
 
1576
             */
 
1577
            H5MM_xfree(priv->src2dst);
 
1578
            H5MM_xfree(priv->src_memb_id);
 
1579
            H5MM_xfree(priv->dst_memb_id);
 
1580
            H5MM_xfree(priv->memb_path);
 
1581
            cdata->priv = priv = H5MM_xfree (priv);
 
1582
            break;
 
1583
 
 
1584
        case H5T_CONV_CONV:
 
1585
            /*
 
1586
             * Conversion.
 
1587
             */
 
1588
            if (NULL == (src = H5I_object(src_id)) ||
 
1589
                    NULL == (dst = H5I_object(dst_id)))
 
1590
                HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a data type");
 
1591
            assert (priv);
 
1592
            assert (bkg && cdata->need_bkg);
 
1593
 
 
1594
            if (cdata->recalc && H5T_conv_struct_init (src, dst, cdata, dxpl_id)<0)
 
1595
                HGOTO_ERROR (H5E_DATATYPE, H5E_CANTINIT, FAIL, "unable to initialize conversion data");
 
1596
 
 
1597
            /*
 
1598
             * Insure that members are sorted.
 
1599
             */
 
1600
            H5T_sort_value(src, NULL);
 
1601
            H5T_sort_value(dst, NULL);
 
1602
            src2dst = priv->src2dst;
 
1603
 
 
1604
            /*
 
1605
             * Direction of conversion and striding through background.
 
1606
             */
 
1607
            if (buf_stride) {
 
1608
                src_delta = buf_stride;
 
1609
            if (!bkg_stride)
 
1610
                bkg_stride = dst->shared->size;
 
1611
            } else if (dst->shared->size <= src->shared->size) {
 
1612
                src_delta = src->shared->size;
 
1613
            bkg_stride = dst->shared->size;
 
1614
            } else {
 
1615
                src_delta = -(int)src->shared->size; /*overflow shouldn't be possible*/
 
1616
                bkg_stride = -(int)dst->shared->size; /*overflow shouldn't be possible*/
 
1617
                xbuf += (nelmts-1) * src->shared->size;
 
1618
                xbkg += (nelmts-1) * dst->shared->size;
 
1619
            }
 
1620
 
 
1621
            /* Conversion loop... */
 
1622
            for (elmtno=0; elmtno<nelmts; elmtno++) {
 
1623
                /*
 
1624
                 * For each source member which will be present in the
 
1625
                 * destination, convert the member to the destination type unless
 
1626
                 * it is larger than the source type.  Then move the member to the
 
1627
                 * left-most unoccupied position in the buffer.  This makes the
 
1628
                 * data point as small as possible with all the free space on the
 
1629
                 * right side.
 
1630
                 */
 
1631
                for (u=0, offset=0; u<src->shared->u.compnd.nmembs; u++) {
 
1632
                    if (src2dst[u]<0) continue; /*subsetting*/
 
1633
                    src_memb = src->shared->u.compnd.memb + u;
 
1634
                    dst_memb = dst->shared->u.compnd.memb + src2dst[u];
 
1635
 
 
1636
                    if (dst_memb->size <= src_memb->size) {
 
1637
                        if (H5T_convert(priv->memb_path[u], priv->src_memb_id[u],
 
1638
                                priv->dst_memb_id[src2dst[u]],
 
1639
                                1, 0, 0, /*no striding (packed array)*/
 
1640
                                xbuf+src_memb->offset, xbkg+dst_memb->offset,
 
1641
                                dxpl_id)<0)
 
1642
                            HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "unable to convert compound data type member");
 
1643
                        HDmemmove (xbuf+offset, xbuf+src_memb->offset,
 
1644
                                   dst_memb->size);
 
1645
                        offset += dst_memb->size;
 
1646
                    } else {
 
1647
                        HDmemmove (xbuf+offset, xbuf+src_memb->offset,
 
1648
                                   src_memb->size);
 
1649
                        offset += src_memb->size;
 
1650
                    }
 
1651
                }
 
1652
 
 
1653
                /*
 
1654
                 * For each source member which will be present in the
 
1655
                 * destination, convert the member to the destination type if it
 
1656
                 * is larger than the source type (that is, has not been converted
 
1657
                 * yet).  Then copy the member to the destination offset in the
 
1658
                 * background buffer.
 
1659
                 */
 
1660
                for (i=src->shared->u.compnd.nmembs-1; i>=0; --i) {
 
1661
                    if (src2dst[i]<0) continue; /*subsetting*/
 
1662
                    src_memb = src->shared->u.compnd.memb + i;
 
1663
                    dst_memb = dst->shared->u.compnd.memb + src2dst[i];
 
1664
 
 
1665
                    if (dst_memb->size > src_memb->size) {
 
1666
                        offset -= src_memb->size;
 
1667
                        if (H5T_convert(priv->memb_path[i],
 
1668
                                    priv->src_memb_id[i], priv->dst_memb_id[src2dst[i]],
 
1669
                                    1, 0, 0, /*no striding (packed array)*/
 
1670
                                    xbuf+offset, xbkg+dst_memb->offset,
 
1671
                                    dxpl_id)<0)
 
1672
                            HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "unable to convert compound data type member");
 
1673
                    } else {
 
1674
                        offset -= dst_memb->size;
 
1675
                    }
 
1676
                    HDmemmove (xbkg+dst_memb->offset, xbuf+offset, dst_memb->size);
 
1677
                }
 
1678
                assert (0==offset);
 
1679
 
 
1680
                /*
 
1681
                 * Update pointers
 
1682
                 */
 
1683
                xbuf += src_delta;
 
1684
                xbkg += bkg_stride;
 
1685
            }
 
1686
 
 
1687
        /* If the bkg_stride was set to -(dst->shared->size), make it positive now */
 
1688
        if(buf_stride==0 && dst->shared->size>src->shared->size)
 
1689
            bkg_stride=dst->shared->size;
 
1690
 
 
1691
            /*
 
1692
             * Copy the background buffer back into the in-place conversion
 
1693
             * buffer.
 
1694
             */
 
1695
            for (xbuf=buf, xbkg=bkg, elmtno=0; elmtno<nelmts; elmtno++) {
 
1696
                HDmemmove(xbuf, xbkg, dst->shared->size);
 
1697
                xbuf += buf_stride ? buf_stride : dst->shared->size;
 
1698
                xbkg += bkg_stride;
 
1699
            }
 
1700
            break;
 
1701
 
 
1702
        default:
 
1703
            /* Some other command we don't know about yet.*/
 
1704
            HGOTO_ERROR (H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, "unknown conversion command");
 
1705
    }
 
1706
 
 
1707
done:
 
1708
    FUNC_LEAVE_NOAPI(ret_value);
 
1709
}
 
1710
 
 
1711
 
 
1712
/*-------------------------------------------------------------------------
 
1713
 * Function:  H5T_conv_struct_opt
 
1714
 *
 
1715
 * Purpose:  Converts between compound data types in a manner more
 
1716
 *    efficient than the general-purpose H5T_conv_struct()
 
1717
 *    function.  This function isn't applicable if the destination
 
1718
 *    is larger than the source type. This is a soft conversion
 
1719
 *    function.  The algorithm is basically:
 
1720
 *
 
1721
 *     For each member of the struct
 
1722
 *      If sizeof detination type <= sizeof source type then
 
1723
 *        Convert member to destination type for all elements
 
1724
 *        Move memb to BKG buffer for all elements
 
1725
 *      Else
 
1726
 *        Move member as far left as possible for all elements
 
1727
 *
 
1728
 *    For each member of the struct (in reverse order)
 
1729
 *      If not destination type then
 
1730
 *        Convert member to destination type for all elements
 
1731
 *        Move member to correct position in BKG for all elements
 
1732
 *
 
1733
 *    Copy BKG to BUF for all elements
 
1734
 *
 
1735
 * Return:  Non-negative on success/Negative on failure
 
1736
 *
 
1737
 * Programmer:  Robb Matzke
 
1738
 *    Thursday, January 22, 1998
 
1739
 *
 
1740
 * Modifications:
 
1741
 *    Robb Matzke, 1999-06-16
 
1742
 *              Added support for non-zero strides. If BUF_STRIDE is
 
1743
 *              non-zero then convert one value at each memory location
 
1744
 *              advancing BUF_STRIDE bytes each time; otherwise assume both
 
1745
 *              source and destination values are packed.
 
1746
 *
 
1747
 *     Robb Matzke, 1999-06-16
 
1748
 *    If the source and destination data structs are the same size
 
1749
 *    then we can convert on a field-by-field basis instead of an
 
1750
 *    element by element basis. In other words, for all struct
 
1751
 *    elements being converted by this function call, first convert
 
1752
 *    all of the field1's, then all field2's, etc. This can
 
1753
 *    drastically reduce the number of calls to H5T_convert() and
 
1754
 *    thereby eliminate most of the conversion constant overhead.
 
1755
 *
 
1756
 *              Robb Matzke, 2000-05-17
 
1757
 *              Added the BKG_STRIDE argument to fix a design bug. If
 
1758
 *              BUF_STRIDE and BKG_STRIDE are both non-zero then each
 
1759
 *              data element converted will be placed temporarily at a
 
1760
 *              multiple of BKG_STRIDE in the BKG buffer; otherwise the
 
1761
 *              BKG buffer is assumed to be a packed array of destination
 
1762
 *              datatype.
 
1763
 *-------------------------------------------------------------------------
 
1764
 */
 
1765
herr_t
 
1766
H5T_conv_struct_opt(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
 
1767
    size_t nelmts, size_t buf_stride, size_t bkg_stride, void *_buf,
 
1768
    void *_bkg, hid_t dxpl_id)
 
1769
{
 
1770
    uint8_t  *buf = (uint8_t *)_buf;  /*cast for pointer arithmetic  */
 
1771
    uint8_t  *bkg = (uint8_t *)_bkg;  /*background pointer arithmetic  */
 
1772
    uint8_t  *xbuf = NULL;    /*temporary pointer into `buf'  */
 
1773
    uint8_t  *xbkg = NULL;    /*temporary pointer into `bkg'  */
 
1774
    H5T_t  *src = NULL;    /*source data type    */
 
1775
    H5T_t  *dst = NULL;    /*destination data type    */
 
1776
    int  *src2dst = NULL;  /*maps src member to dst member  */
 
1777
    H5T_cmemb_t  *src_memb = NULL;  /*source struct member descript.*/
 
1778
    H5T_cmemb_t  *dst_memb = NULL;  /*destination struct memb desc.  */
 
1779
    size_t  offset;      /*byte offset wrt struct  */
 
1780
    size_t  elmtno;      /*element counter    */
 
1781
    unsigned  u;      /*counters      */
 
1782
    int  i;          /*counters      */
 
1783
    H5T_conv_struct_t *priv = NULL;  /*private data      */
 
1784
    herr_t      ret_value=SUCCEED;       /* Return value */
 
1785
 
 
1786
    FUNC_ENTER_NOAPI(H5T_conv_struct_opt, FAIL);
 
1787
 
 
1788
    switch (cdata->command) {
 
1789
        case H5T_CONV_INIT:
 
1790
            /*
 
1791
             * First, determine if this conversion function applies to the
 
1792
             * conversion path SRC_ID-->DST_ID.  If not, return failure;
 
1793
             * otherwise initialize the `priv' field of `cdata' with information
 
1794
             * that remains (almost) constant for this conversion path.
 
1795
             */
 
1796
            if (NULL == (src = H5I_object(src_id)) ||
 
1797
                    NULL == (dst = H5I_object(dst_id)))
 
1798
                HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a data type");
 
1799
            assert (H5T_COMPOUND==src->shared->type);
 
1800
            assert (H5T_COMPOUND==dst->shared->type);
 
1801
 
 
1802
            /* Initialize data which is relatively constant */
 
1803
            if (H5T_conv_struct_init (src, dst, cdata, dxpl_id)<0)
 
1804
                HGOTO_ERROR (H5E_DATATYPE, H5E_CANTINIT, FAIL, "unable to initialize conversion data");
 
1805
            priv = (H5T_conv_struct_t *)(cdata->priv);
 
1806
            src2dst = priv->src2dst;
 
1807
 
 
1808
            /*
 
1809
             * If the destination type is not larger than the source type then
 
1810
             * this conversion function is guaranteed to work (provided all
 
1811
             * members can be converted also). Otherwise the determination is
 
1812
             * quite a bit more complicated. Essentially we have to make sure
 
1813
             * that there is always room in the source buffer to do the
 
1814
             * conversion of a member in place. This is basically the same pair
 
1815
             * of loops as in the actual conversion except it checks that there
 
1816
             * is room for each conversion instead of actually doing anything.
 
1817
             */
 
1818
            if (dst->shared->size > src->shared->size) {
 
1819
                for (u=0, offset=0; u<src->shared->u.compnd.nmembs; u++) {
 
1820
                    if (src2dst[u]<0)
 
1821
                        continue;
 
1822
                    src_memb = src->shared->u.compnd.memb + u;
 
1823
                    dst_memb = dst->shared->u.compnd.memb + src2dst[u];
 
1824
                    if (dst_memb->size > src_memb->size)
 
1825
                        offset += src_memb->size;
 
1826
                }
 
1827
                for (i=src->shared->u.compnd.nmembs-1; i>=0; --i) {
 
1828
                    if (src2dst[i]<0)
 
1829
                        continue;
 
1830
                    src_memb = src->shared->u.compnd.memb + i;
 
1831
                    dst_memb = dst->shared->u.compnd.memb + src2dst[i];
 
1832
                    if (dst_memb->size > src_memb->size) {
 
1833
                        offset -= src_memb->size;
 
1834
                        if (dst_memb->size > src->shared->size-offset) {
 
1835
                            H5MM_xfree(priv->src2dst);
 
1836
                            H5MM_xfree(priv->src_memb_id);
 
1837
                            H5MM_xfree(priv->dst_memb_id);
 
1838
                            H5MM_xfree(priv->memb_path);
 
1839
                            cdata->priv = priv = H5MM_xfree (priv);
 
1840
                            HGOTO_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, "convertion is unsupported by this function");
 
1841
                        }
 
1842
                    }
 
1843
                }
 
1844
            }
 
1845
            break;
 
1846
 
 
1847
        case H5T_CONV_FREE:
 
1848
            /*
 
1849
             * Free the private conversion data.
 
1850
             */
 
1851
            priv = (H5T_conv_struct_t *)(cdata->priv);
 
1852
            H5MM_xfree(priv->src2dst);
 
1853
            H5MM_xfree(priv->src_memb_id);
 
1854
            H5MM_xfree(priv->dst_memb_id);
 
1855
            H5MM_xfree(priv->memb_path);
 
1856
            cdata->priv = priv = H5MM_xfree (priv);
 
1857
            break;
 
1858
 
 
1859
        case H5T_CONV_CONV:
 
1860
            /*
 
1861
             * Conversion.
 
1862
             */
 
1863
            if (NULL == (src = H5I_object(src_id)) ||
 
1864
                    NULL == (dst = H5I_object(dst_id)))
 
1865
                HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a data type");
 
1866
 
 
1867
            /* Update cached data if necessary */
 
1868
            if (cdata->recalc && H5T_conv_struct_init (src, dst, cdata, dxpl_id)<0)
 
1869
                HGOTO_ERROR (H5E_DATATYPE, H5E_CANTINIT, FAIL, "unable to initialize conversion data");
 
1870
            priv = (H5T_conv_struct_t *)(cdata->priv);
 
1871
            src2dst = priv->src2dst;
 
1872
            assert(priv);
 
1873
            assert(bkg && cdata->need_bkg);
 
1874
 
 
1875
            /*
 
1876
             * Insure that members are sorted.
 
1877
             */
 
1878
            H5T_sort_value(src, NULL);
 
1879
            H5T_sort_value(dst, NULL);
 
1880
 
 
1881
            /*
 
1882
             * Calculate strides. If BUF_STRIDE is non-zero then convert one
 
1883
             * data element at every BUF_STRIDE bytes through the main buffer
 
1884
             * (BUF), leaving the result of each conversion at the same
 
1885
             * location; otherwise assume the source and destination data are
 
1886
             * packed tightly based on src->shared->size and dst->shared->size.  Also, if
 
1887
             * BUF_STRIDE and BKG_STRIDE are both non-zero then place
 
1888
             * background data into the BKG buffer at multiples of BKG_STRIDE;
 
1889
             * otherwise assume BKG buffer is the packed destination datatype.
 
1890
             */
 
1891
            if (!buf_stride || !bkg_stride) bkg_stride = dst->shared->size;
 
1892
 
 
1893
            /*
 
1894
             * For each member where the destination is not larger than the
 
1895
             * source, stride through all the elements converting only that member
 
1896
             * in each element and then copying the element to its final
 
1897
             * destination in the bkg buffer. Otherwise move the element as far
 
1898
             * left as possible in the buffer.
 
1899
             */
 
1900
            for (u=0, offset=0; u<src->shared->u.compnd.nmembs; u++) {
 
1901
                if (src2dst[u]<0) continue; /*subsetting*/
 
1902
                src_memb = src->shared->u.compnd.memb + u;
 
1903
                dst_memb = dst->shared->u.compnd.memb + src2dst[u];
 
1904
 
 
1905
                if (dst_memb->size <= src_memb->size) {
 
1906
                    xbuf = buf + src_memb->offset;
 
1907
                    xbkg = bkg + dst_memb->offset;
 
1908
                    if (H5T_convert(priv->memb_path[u],
 
1909
                            priv->src_memb_id[u],
 
1910
                            priv->dst_memb_id[src2dst[u]], nelmts,
 
1911
                            buf_stride ? buf_stride : src->shared->size,
 
1912
                            bkg_stride, xbuf, xbkg,
 
1913
                            dxpl_id)<0)
 
1914
                        HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "unable to convert compound data type member");
 
1915
                    for (elmtno=0; elmtno<nelmts; elmtno++) {
 
1916
                        HDmemmove(xbkg, xbuf, dst_memb->size);
 
1917
                        xbuf += buf_stride ? buf_stride : src->shared->size;
 
1918
                        xbkg += bkg_stride;
 
1919
                    }
 
1920
                } else {
 
1921
                    for (xbuf=buf, elmtno=0; elmtno<nelmts; elmtno++) {
 
1922
                        HDmemmove(xbuf+offset, xbuf+src_memb->offset,
 
1923
                                              src_memb->size);
 
1924
                        xbuf += buf_stride ? buf_stride : src->shared->size;
 
1925
                    }
 
1926
                    offset += src_memb->size;
 
1927
                }
 
1928
            }
 
1929
 
 
1930
            /*
 
1931
             * Work from right to left, converting those members that weren't
 
1932
             * converted in the previous loop (those members where the destination
 
1933
             * is larger than the source) and them to their final position in the
 
1934
             * bkg buffer.
 
1935
             */
 
1936
            for (i=src->shared->u.compnd.nmembs-1; i>=0; --i) {
 
1937
                if (src2dst[i]<0)
 
1938
                    continue;
 
1939
                src_memb = src->shared->u.compnd.memb + i;
 
1940
                dst_memb = dst->shared->u.compnd.memb + src2dst[i];
 
1941
 
 
1942
                if (dst_memb->size > src_memb->size) {
 
1943
                    offset -= src_memb->size;
 
1944
                    xbuf = buf + offset;
 
1945
                    xbkg = bkg + dst_memb->offset;
 
1946
                    if (H5T_convert(priv->memb_path[i],
 
1947
                                    priv->src_memb_id[i],
 
1948
                                    priv->dst_memb_id[src2dst[i]], nelmts,
 
1949
                                    buf_stride ? buf_stride : src->shared->size,
 
1950
                                    bkg_stride, xbuf, xbkg,
 
1951
                                    dxpl_id)<0)
 
1952
                        HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "unable to convert compound data type member");
 
1953
                    for (elmtno=0; elmtno<nelmts; elmtno++) {
 
1954
                        HDmemmove(xbkg, xbuf, dst_memb->size);
 
1955
                        xbuf += buf_stride ? buf_stride : src->shared->size;
 
1956
                        xbkg += bkg_stride;
 
1957
                    }
 
1958
                }
 
1959
            }
 
1960
 
 
1961
            /* Move background buffer into result buffer */
 
1962
            for (xbuf=buf, xbkg=bkg, elmtno=0; elmtno<nelmts; elmtno++) {
 
1963
                HDmemmove(xbuf, xbkg, dst->shared->size);
 
1964
                xbuf += buf_stride ? buf_stride : dst->shared->size;
 
1965
                xbkg += bkg_stride;
 
1966
            }
 
1967
            break;
 
1968
 
 
1969
        default:
 
1970
            /* Some other command we don't know about yet.*/
 
1971
            HGOTO_ERROR (H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, "unknown conversion command");
 
1972
    }
 
1973
 
 
1974
done:
 
1975
    FUNC_LEAVE_NOAPI(ret_value);
 
1976
}
 
1977
 
 
1978
 
 
1979
/*-------------------------------------------------------------------------
 
1980
 * Function:  H5T_conv_enum_init
 
1981
 *
 
1982
 * Purpose:  Initialize information for H5T_conv_enum().
 
1983
 *
 
1984
 * Return:  Success:  Non-negative
 
1985
 *
 
1986
 *    Failure:  Negative
 
1987
 *
 
1988
 * Programmer:  Robb Matzke
 
1989
 *              Monday, January  4, 1999
 
1990
 *
 
1991
 * Modifications:
 
1992
 *
 
1993
 *-------------------------------------------------------------------------
 
1994
 */
 
1995
static herr_t
 
1996
H5T_conv_enum_init(H5T_t *src, H5T_t *dst, H5T_cdata_t *cdata)
 
1997
{
 
1998
    H5T_enum_struct_t  *priv=NULL;  /*private conversion data  */
 
1999
    int    n;    /*src value cast as native int  */
 
2000
    int    domain[2];  /*min and max source values  */
 
2001
    int    *map=NULL;  /*map from src value to dst idx  */
 
2002
    unsigned  length;    /*nelmts in map array    */
 
2003
    unsigned  i, j;    /*counters      */
 
2004
    herr_t      ret_value=SUCCEED;       /* Return value */
 
2005
 
 
2006
    FUNC_ENTER_NOAPI_NOINIT(H5T_conv_enum_init);
 
2007
 
 
2008
    cdata->need_bkg = H5T_BKG_NO;
 
2009
    if (NULL==(priv=cdata->priv=H5MM_calloc(sizeof(*priv))))
 
2010
  HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed");
 
2011
    if (0==src->shared->u.enumer.nmembs)
 
2012
  HGOTO_DONE(SUCCEED);
 
2013
 
 
2014
    /*
 
2015
     * Check that the source symbol names are a subset of the destination
 
2016
     * symbol names and build a map from source member index to destination
 
2017
     * member index.
 
2018
     */
 
2019
    H5T_sort_name(src, NULL);
 
2020
    H5T_sort_name(dst, NULL);
 
2021
    if (NULL==(priv->src2dst=H5MM_malloc(src->shared->u.enumer.nmembs*sizeof(int))))
 
2022
  HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed");;
 
2023
    for (i=0, j=0;
 
2024
             i<src->shared->u.enumer.nmembs && j<dst->shared->u.enumer.nmembs;
 
2025
             i++, j++) {
 
2026
  while (j<dst->shared->u.enumer.nmembs &&
 
2027
         HDstrcmp(src->shared->u.enumer.name[i], dst->shared->u.enumer.name[j]))
 
2028
            j++;
 
2029
  if (j>=dst->shared->u.enumer.nmembs)
 
2030
      HGOTO_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, "source type is not a subset of destination type");
 
2031
  priv->src2dst[i] = j;
 
2032
    }
 
2033
 
 
2034
    /*
 
2035
     * The conversion function will use an O(log N) lookup method for each
 
2036
     * value converted. However, if all of the following constraints are met
 
2037
     * then we can build a perfect hash table and use an O(1) lookup method.
 
2038
     *
 
2039
     *    A: The source data type size matches one of our native data type
 
2040
     *       sizes.
 
2041
     *
 
2042
     *    B: After casting the source value bit pattern to a native type
 
2043
     *       the size of the range of values is less than 20% larger than
 
2044
     *       the number of values.
 
2045
     *
 
2046
     * If this special case is met then we use the source bit pattern cast as
 
2047
     * a native integer type as an index into the `val2dst'. The values of
 
2048
     * that array are the index numbers in the destination type or negative
 
2049
     * if the entry is unused.
 
2050
     */
 
2051
    if (1==src->shared->size || sizeof(short)==src->shared->size || sizeof(int)==src->shared->size) {
 
2052
  for (i=0; i<src->shared->u.enumer.nmembs; i++) {
 
2053
      if (1==src->shared->size) {
 
2054
    n = *((signed char*)(src->shared->u.enumer.value+i));
 
2055
      } else if (sizeof(short)==src->shared->size) {
 
2056
    n = *((short*)(src->shared->u.enumer.value+i*src->shared->size));
 
2057
      } else {
 
2058
    n = *((int*)(src->shared->u.enumer.value+i*src->shared->size));
 
2059
      }
 
2060
      if (0==i) {
 
2061
    domain[0] = domain[1] = n;
 
2062
      } else {
 
2063
    domain[0] = MIN(domain[0], n);
 
2064
    domain[1] = MAX(domain[1], n);
 
2065
      }
 
2066
  }
 
2067
 
 
2068
  length = (domain[1]-domain[0])+1;
 
2069
  if (src->shared->u.enumer.nmembs<2 ||
 
2070
      (double)length/src->shared->u.enumer.nmembs<1.2) {
 
2071
      priv->base = domain[0];
 
2072
      priv->length = length;
 
2073
      if (NULL==(map=H5MM_malloc(length*sizeof(int))))
 
2074
    HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed");
 
2075
      for (i=0; i<length; i++)
 
2076
                map[i] = -1; /*entry unused*/
 
2077
      for (i=0; i<src->shared->u.enumer.nmembs; i++) {
 
2078
    if (1==src->shared->size) {
 
2079
        n = *((signed char*)(src->shared->u.enumer.value+i));
 
2080
    } else if (sizeof(short)==src->shared->size) {
 
2081
        n = *((short*)(src->shared->u.enumer.value+i*src->shared->size));
 
2082
    } else {
 
2083
        n = *((int*)(src->shared->u.enumer.value+i*src->shared->size));
 
2084
    }
 
2085
    n -= priv->base;
 
2086
    assert(n>=0 && n<priv->length);
 
2087
    assert(map[n]<0);
 
2088
    map[n] = priv->src2dst[i];
 
2089
      }
 
2090
 
 
2091
      /*
 
2092
       * Replace original src2dst array with our new one. The original
 
2093
       * was indexed by source member number while the new one is
 
2094
       * indexed by source values.
 
2095
       */
 
2096
      H5MM_xfree(priv->src2dst);
 
2097
      priv->src2dst = map;
 
2098
      HGOTO_DONE(SUCCEED);
 
2099
  }
 
2100
    }
 
2101
 
 
2102
    /* Sort source type by value and adjust src2dst[] appropriately */
 
2103
    H5T_sort_value(src, priv->src2dst);
 
2104
 
 
2105
done:
 
2106
    if (ret_value<0 && priv) {
 
2107
  H5MM_xfree(priv->src2dst);
 
2108
  H5MM_xfree(priv);
 
2109
  cdata->priv = NULL;
 
2110
    }
 
2111
    FUNC_LEAVE_NOAPI(ret_value);
 
2112
}
 
2113
 
 
2114
 
 
2115
/*-------------------------------------------------------------------------
 
2116
 * Function:  H5T_conv_enum
 
2117
 *
 
2118
 * Purpose:  Converts one type of enumerated data to another.
 
2119
 *
 
2120
 * Return:  Success:  Non-negative
 
2121
 *
 
2122
 *    Failure:  negative
 
2123
 *
 
2124
 * Programmer:  Robb Matzke
 
2125
 *              Monday, January  4, 1999
 
2126
 *
 
2127
 * Modifications:
 
2128
 *    Robb Matzke, 1999-06-16
 
2129
 *    Added support for non-zero strides. If BUF_STRIDE is non-zero
 
2130
 *    then convert one value at each memory location advancing
 
2131
 *    BUF_STRIDE bytes each time; otherwise assume both source and
 
2132
 *    destination values are packed.
 
2133
 *-------------------------------------------------------------------------
 
2134
 */
 
2135
herr_t
 
2136
H5T_conv_enum(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, size_t nelmts,
 
2137
        size_t buf_stride, size_t UNUSED bkg_stride, void *_buf,
 
2138
              void UNUSED *bkg, hid_t UNUSED dxpl_id)
 
2139
{
 
2140
    uint8_t  *buf = (uint8_t*)_buf;  /*cast for pointer arithmetic  */
 
2141
    H5T_t  *src=NULL, *dst=NULL;  /*src and dst data types  */
 
2142
    uint8_t  *s=NULL, *d=NULL;  /*src and dst BUF pointers  */
 
2143
    int  src_delta, dst_delta;  /*conversion strides    */
 
2144
    int  n;      /*src value cast as native int  */
 
2145
    size_t  i;      /*counters      */
 
2146
    H5T_enum_struct_t *priv = (H5T_enum_struct_t*)(cdata->priv);
 
2147
    herr_t      ret_value=SUCCEED;      /* Return value                 */
 
2148
 
 
2149
    FUNC_ENTER_NOAPI(H5T_conv_enum, FAIL);
 
2150
 
 
2151
    switch (cdata->command) {
 
2152
        case H5T_CONV_INIT:
 
2153
            /*
 
2154
             * Determine if this conversion function applies to the conversion
 
2155
             * path SRC_ID->DST_ID.  If not return failure; otherwise initialize
 
2156
             * the `priv' field of `cdata' with information about the underlying
 
2157
             * integer conversion.
 
2158
             */
 
2159
            if (NULL == (src = H5I_object(src_id)) ||
 
2160
                    NULL == (dst = H5I_object(dst_id)))
 
2161
                HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a data type");
 
2162
            assert (H5T_ENUM==src->shared->type);
 
2163
            assert (H5T_ENUM==dst->shared->type);
 
2164
            if (H5T_conv_enum_init(src, dst, cdata)<0)
 
2165
                HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "unable to initialize private data");
 
2166
            break;
 
2167
 
 
2168
        case H5T_CONV_FREE:
 
2169
#ifdef H5T_DEBUG
 
2170
            if (H5DEBUG(T)) {
 
2171
                fprintf(H5DEBUG(T), "      Using %s mapping function%s\n",
 
2172
                        priv->length?"O(1)":"O(log N)",
 
2173
                        priv->length?"":", where N is the number of enum members");
 
2174
            }
 
2175
#endif
 
2176
            if (priv) {
 
2177
                H5MM_xfree(priv->src2dst);
 
2178
                H5MM_xfree(priv);
 
2179
            }
 
2180
            cdata->priv = NULL;
 
2181
            break;
 
2182
 
 
2183
        case H5T_CONV_CONV:
 
2184
            if (NULL == (src = H5I_object(src_id)) ||
 
2185
                    NULL == (dst = H5I_object(dst_id)))
 
2186
                HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a data type");
 
2187
            assert (H5T_ENUM==src->shared->type);
 
2188
            assert (H5T_ENUM==dst->shared->type);
 
2189
 
 
2190
            /* priv->src2dst map was computed for certain sort keys. Make sure those same
 
2191
             * sort keys are used here during conversion. See H5T_conv_enum_init(). But
 
2192
             * we actually don't care about the source type's order when doing the O(1)
 
2193
             * conversion algorithm, which is turned on by non-zero priv->length */
 
2194
            H5T_sort_name(dst, NULL);
 
2195
            if (!priv->length) H5T_sort_value(src, NULL);
 
2196
 
 
2197
            /*
 
2198
             * Direction of conversion.
 
2199
             */
 
2200
            if (buf_stride) {
 
2201
                src_delta = dst_delta = (int)buf_stride;
 
2202
                s = d = buf;
 
2203
            } else if (dst->shared->size <= src->shared->size) {
 
2204
                src_delta = (int)src->shared->size; /*overflow shouldn't be possible*/
 
2205
                dst_delta = (int)dst->shared->size; /*overflow shouldn't be possible*/
 
2206
                s = d = buf;
 
2207
            } else {
 
2208
                src_delta = -(int)src->shared->size; /*overflow shouldn't be possible*/
 
2209
                dst_delta = -(int)dst->shared->size; /*overflow shouldn't be possible*/
 
2210
                s = buf + (nelmts-1) * src->shared->size;
 
2211
                d = buf + (nelmts-1) * dst->shared->size;
 
2212
            }
 
2213
 
 
2214
            for (i=0; i<nelmts; i++, s+=src_delta, d+=dst_delta) {
 
2215
                if (priv->length) {
 
2216
                    /* Use O(1) lookup */
 
2217
                    if (1==src->shared->size) {
 
2218
                        n = *((signed char*)s);
 
2219
                    } else if (sizeof(short)==src->shared->size) {
 
2220
                        n = *((short*)s);
 
2221
                    } else {
 
2222
                        n = *((int*)s);
 
2223
                    }
 
2224
                    n -= priv->base;
 
2225
                    if (n<0 || n>=priv->length || priv->src2dst[n]<0) {
 
2226
                        if (!H5T_overflow_g ||
 
2227
                            (H5T_overflow_g)(src_id, dst_id, s, d)<0) {
 
2228
                            HDmemset(d, 0xff, dst->shared->size);
 
2229
                        }
 
2230
                    } else {
 
2231
                        HDmemcpy(d,
 
2232
                                 dst->shared->u.enumer.value+priv->src2dst[n]*dst->shared->size,
 
2233
                                 dst->shared->size);
 
2234
                    }
 
2235
                } else {
 
2236
                    /* Use O(log N) lookup */
 
2237
                    int lt = 0;
 
2238
                    int rt = src->shared->u.enumer.nmembs;
 
2239
                    int md, cmp;
 
2240
                    while (lt<rt) {
 
2241
                        md = (lt+rt)/2;
 
2242
                        cmp = HDmemcmp(s, src->shared->u.enumer.value+md*src->shared->size,
 
2243
                                       src->shared->size);
 
2244
                        if (cmp<0) {
 
2245
                            rt = md;
 
2246
                        } else if (cmp>0) {
 
2247
                            lt = md+1;
 
2248
                        } else {
 
2249
                            break;
 
2250
                        }
 
2251
                    }
 
2252
                    if (lt>=rt) {
 
2253
                        if (!H5T_overflow_g ||
 
2254
                            (H5T_overflow_g)(src_id, dst_id, s, d)<0) {
 
2255
                            HDmemset(d, 0xff, dst->shared->size);
 
2256
                        }
 
2257
                    } else {
 
2258
                        HDmemcpy(d,
 
2259
                                 dst->shared->u.enumer.value+priv->src2dst[md]*dst->shared->size,
 
2260
                                 dst->shared->size);
 
2261
                    }
 
2262
                }
 
2263
            }
 
2264
            break;
 
2265
 
 
2266
        default:
 
2267
            /* Some other command we don't know about yet.*/
 
2268
            HGOTO_ERROR (H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, "unknown conversion command");
 
2269
    }
 
2270
 
 
2271
done:
 
2272
    FUNC_LEAVE_NOAPI(ret_value);
 
2273
}
 
2274
 
 
2275
 
 
2276
/*-------------------------------------------------------------------------
 
2277
 * Function:  H5T_conv_vlen
 
2278
 *
 
2279
 * Purpose:  Converts between VL data types in memory and on disk.
 
2280
 *    This is a soft conversion function.  The algorithm is
 
2281
 *    basically:
 
2282
 *
 
2283
 *        For every VL struct in the main buffer:
 
2284
 *      1. Allocate space for temporary dst VL data (reuse buffer
 
2285
 *         if possible)
 
2286
 *                2. Copy VL data from src buffer into dst buffer
 
2287
 *                3. Convert VL data into dst representation
 
2288
 *                4. Allocate buffer in dst heap
 
2289
 *      5. Free heap objects storing old data
 
2290
 *                6. Write dst VL data into dst heap
 
2291
 *                7. Store (heap ID or pointer) and length in main dst buffer
 
2292
 *
 
2293
 * Return:  Non-negative on success/Negative on failure
 
2294
 *
 
2295
 * Programmer:  Quincey Koziol
 
2296
 *    Wednesday, May 26, 1999
 
2297
 *
 
2298
 * Modifications:
 
2299
 *
 
2300
 *    Quincey Koziol, 2 July, 1999
 
2301
 *    Enabled support for non-zero strides. If BUF_STRIDE is non-zero
 
2302
 *    then convert one value at each memory location advancing
 
2303
 *    BUF_STRIDE bytes each time; otherwise assume both source and
 
2304
 *    destination values are packed.
 
2305
 *
 
2306
 *    Raymond Lu, 26 June, 2002
 
2307
 *    Background buffer is used for freeing heap objects storing
 
2308
 *     old data.  At this moment, it only frees the first level of
 
2309
 *    VL datatype.  It doesn't handle nested VL datatypes.
 
2310
 *
 
2311
 *-------------------------------------------------------------------------
 
2312
 */
 
2313
herr_t
 
2314
H5T_conv_vlen(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, size_t nelmts,
 
2315
        size_t buf_stride, size_t bkg_stride, void *buf,
 
2316
              void *bkg, hid_t dxpl_id)
 
2317
{
 
2318
    H5T_vlen_alloc_info_t _vl_alloc_info;       /* VL allocation info buffer */
 
2319
    H5T_vlen_alloc_info_t *vl_alloc_info=&_vl_alloc_info;   /* VL allocation info */
 
2320
    H5T_path_t  *tpath;      /* Type conversion path         */
 
2321
    hbool_t     noop_conv=FALSE;        /* Flag to indicate a noop conversion */
 
2322
    hbool_t     write_to_file=FALSE;    /* Flag to indicate writing to file */
 
2323
    hbool_t     parent_is_vlen;         /* Flag to indicate parent is vlen datatyp */
 
2324
    hid_t     tsrc_id = -1, tdst_id = -1;/*temporary type atoms       */
 
2325
    H5T_t  *src = NULL;    /*source data type         */
 
2326
    H5T_t  *dst = NULL;    /*destination data type         */
 
2327
    H5HG_t  bg_hobjid, parent_hobjid;
 
2328
    uint8_t  *s;            /*source buffer      */
 
2329
    uint8_t  *d;            /*destination buffer    */
 
2330
    uint8_t  *b;            /*background buffer    */
 
2331
    ssize_t  s_stride, d_stride;  /*src and dst strides    */
 
2332
    ssize_t  b_stride;          /*bkg stride      */
 
2333
    size_t      safe;                   /*how many elements are safe to process in each pass */
 
2334
    ssize_t   seq_len;                /*the number of elements in the current sequence*/
 
2335
    size_t  bg_seq_len=0;
 
2336
    size_t  src_base_size, dst_base_size;/*source & destination base size*/
 
2337
    void  *conv_buf=NULL;       /*temporary conversion buffer        */
 
2338
    size_t  conv_buf_size=0;    /*size of conversion buffer in bytes */
 
2339
    void  *tmp_buf=NULL;       /*temporary background buffer        */
 
2340
    size_t  tmp_buf_size=0;          /*size of temporary bkg buffer       */
 
2341
    hbool_t     nested=FALSE;           /*flag of nested VL case             */
 
2342
    size_t  elmtno;      /*element number counter       */
 
2343
    herr_t      ret_value=SUCCEED;       /* Return value */
 
2344
 
 
2345
    FUNC_ENTER_NOAPI(H5T_conv_vlen, FAIL);
 
2346
 
 
2347
    switch (cdata->command) {
 
2348
        case H5T_CONV_INIT:
 
2349
            /*
 
2350
             * First, determine if this conversion function applies to the
 
2351
             * conversion path SRC_ID-->DST_ID.  If not, return failure;
 
2352
             * otherwise initialize the `priv' field of `cdata' with
 
2353
             * information that remains (almost) constant for this
 
2354
             * conversion path.
 
2355
             */
 
2356
            if (NULL == (src = H5I_object(src_id)) ||
 
2357
                    NULL == (dst = H5I_object(dst_id)))
 
2358
                HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a data type");
 
2359
            assert (H5T_VLEN==src->shared->type);
 
2360
            assert (H5T_VLEN==dst->shared->type);
 
2361
 
 
2362
            /* Variable-length types don't need a background buffer */
 
2363
            cdata->need_bkg = H5T_BKG_NO;
 
2364
 
 
2365
            break;
 
2366
 
 
2367
        case H5T_CONV_FREE:
 
2368
            /* QAK - Nothing to do currently */
 
2369
            break;
 
2370
 
 
2371
        case H5T_CONV_CONV:
 
2372
            /*
 
2373
             * Conversion.
 
2374
             */
 
2375
            if (NULL == (src = H5I_object(src_id)) ||
 
2376
                    NULL == (dst = H5I_object(dst_id)))
 
2377
                HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a data type");
 
2378
 
 
2379
            /* Initialize source & destination strides */
 
2380
            if (buf_stride) {
 
2381
                assert(buf_stride>=src->shared->size);
 
2382
                assert(buf_stride>=dst->shared->size);
 
2383
                H5_CHECK_OVERFLOW(buf_stride,size_t,ssize_t);
 
2384
                s_stride = d_stride = (ssize_t)buf_stride;
 
2385
            } else {
 
2386
                H5_CHECK_OVERFLOW(src->shared->size,size_t,ssize_t);
 
2387
                H5_CHECK_OVERFLOW(dst->shared->size,size_t,ssize_t);
 
2388
                s_stride = (ssize_t)src->shared->size;
 
2389
                d_stride = (ssize_t)dst->shared->size;
 
2390
            }
 
2391
            if(bkg) {
 
2392
                if(bkg_stride) {
 
2393
                    H5_CHECK_OVERFLOW(bkg_stride,size_t,ssize_t);
 
2394
                    b_stride=(ssize_t)bkg_stride;
 
2395
                } /* end if */
 
2396
                else
 
2397
                    b_stride=d_stride;
 
2398
            } /* end if */
 
2399
            else
 
2400
                b_stride=0;
 
2401
 
 
2402
            /* Get the size of the base types in src & dst */
 
2403
            src_base_size=H5T_get_size(src->shared->parent);
 
2404
            dst_base_size=H5T_get_size(dst->shared->parent);
 
2405
 
 
2406
            /* Set up conversion path for base elements */
 
2407
            if (NULL==(tpath=H5T_path_find(src->shared->parent, dst->shared->parent, NULL, NULL, dxpl_id))) {
 
2408
                HGOTO_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, "unable to convert between src and dest datatypes");
 
2409
            } else if (!H5T_path_noop(tpath)) {
 
2410
                if ((tsrc_id = H5I_register(H5I_DATATYPE, H5T_copy(src->shared->parent, H5T_COPY_ALL)))<0 ||
 
2411
                        (tdst_id = H5I_register(H5I_DATATYPE, H5T_copy(dst->shared->parent, H5T_COPY_ALL)))<0)
 
2412
                    HGOTO_ERROR(H5E_DATASET, H5E_CANTREGISTER, FAIL, "unable to register types for conversion");
 
2413
            } else
 
2414
                noop_conv=TRUE;
 
2415
 
 
2416
            /* Check if we need a temporary buffer for this conversion */
 
2417
            parent_is_vlen=H5T_detect_class(dst->shared->parent,H5T_VLEN);
 
2418
            if(tpath->cdata.need_bkg || parent_is_vlen) {
 
2419
                /* Set up initial background buffer */
 
2420
                tmp_buf_size=MAX(src_base_size,dst_base_size);
 
2421
                if ((tmp_buf=H5FL_BLK_MALLOC(vlen_seq,tmp_buf_size))==NULL)
 
2422
                    HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed for type conversion");
 
2423
            } /* end if */
 
2424
 
 
2425
            /* Get the allocation info */
 
2426
            if(H5T_vlen_get_alloc_info(dxpl_id,&vl_alloc_info)<0)
 
2427
                HGOTO_ERROR(H5E_DATATYPE, H5E_CANTGET, FAIL, "unable to retrieve VL allocation info");
 
2428
 
 
2429
            /* Set flags to indicate we are writing to or reading from the file */
 
2430
            if(dst->shared->u.vlen.f!=NULL)
 
2431
                write_to_file=TRUE;
 
2432
 
 
2433
            /* Set the flag for nested VL case */
 
2434
            if(write_to_file && parent_is_vlen && bkg!=NULL)
 
2435
                nested=1;
 
2436
 
 
2437
            /* The outer loop of the type conversion macro, controlling which */
 
2438
            /* direction the buffer is walked */
 
2439
            while (nelmts>0) {
 
2440
                /* Check if we need to go backwards through the buffer */
 
2441
                if(d_stride>s_stride) {
 
2442
                    /* Compute the number of "safe" destination elements at */
 
2443
                    /* the end of the buffer (Those which don't overlap with */
 
2444
                    /* any source elements at the beginning of the buffer) */
 
2445
                    safe=nelmts-(((nelmts*s_stride)+(d_stride-1))/d_stride);
 
2446
 
 
2447
                    /* If we're down to the last few elements, just wrap up */
 
2448
                    /* with a "real" reverse copy */
 
2449
                    if(safe<2) {
 
2450
                        s = (uint8_t*)buf+(nelmts-1)*s_stride;
 
2451
                        d = (uint8_t*)buf+(nelmts-1)*d_stride;
 
2452
                        b = (uint8_t*)bkg+(nelmts-1)*b_stride;
 
2453
                        s_stride = -s_stride;
 
2454
                        d_stride = -d_stride;
 
2455
                        b_stride = -b_stride;
 
2456
 
 
2457
                        safe=nelmts;
 
2458
                    } /* end if */
 
2459
                    else {
 
2460
                        s = (uint8_t*)buf+(nelmts-safe)*s_stride;
 
2461
                        d = (uint8_t*)buf+(nelmts-safe)*d_stride;
 
2462
                        b = (uint8_t*)bkg+(nelmts-safe)*b_stride;
 
2463
                    } /* end else */
 
2464
                } /* end if */
 
2465
                else {
 
2466
                    /* Single forward pass over all data */
 
2467
                    s = d = buf;
 
2468
                    b = bkg;
 
2469
                    safe=nelmts;
 
2470
                } /* end else */
 
2471
 
 
2472
                for (elmtno=0; elmtno<safe; elmtno++) {
 
2473
                    /* Check for "nil" source sequence */
 
2474
                    if((*(src->shared->u.vlen.isnull))(src->shared->u.vlen.f,s)) {
 
2475
                        /* Write "nil" sequence to destination location */
 
2476
                        if((*(dst->shared->u.vlen.setnull))(dst->shared->u.vlen.f,dxpl_id,d,b)<0)
 
2477
                            HGOTO_ERROR(H5E_DATATYPE, H5E_WRITEERROR, FAIL, "can't set VL data to 'nil'");
 
2478
                    } /* end if */
 
2479
                    else {
 
2480
                        /* Get length of element sequences */
 
2481
                        if((seq_len=(*(src->shared->u.vlen.getlen))(s))<0)
 
2482
                            HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "incorrect length");
 
2483
 
 
2484
                        /* If we are reading from memory and there is no conversion, just get the pointer to sequence */
 
2485
                        if(write_to_file && noop_conv) {
 
2486
                            /* Get direct pointer to sequence */
 
2487
                            if((conv_buf=(*(src->shared->u.vlen.getptr))(s))==NULL)
 
2488
                                HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid source pointer");
 
2489
                        } /* end if */
 
2490
                        else {
 
2491
                            size_t  src_size, dst_size;     /*source & destination total size in bytes*/
 
2492
 
 
2493
                            src_size=seq_len*src_base_size;
 
2494
                            dst_size=seq_len*dst_base_size;
 
2495
 
 
2496
                            /* Check if conversion buffer is large enough, resize if
 
2497
                             * necessary */
 
2498
                            if(conv_buf_size<MAX(src_size,dst_size)) {
 
2499
                                /* Only allocate conversion buffer in H5T_VLEN_MIN_CONF_BUF_SIZE increments */
 
2500
                                conv_buf_size=((MAX(src_size,dst_size)/H5T_VLEN_MIN_CONF_BUF_SIZE)+1)*H5T_VLEN_MIN_CONF_BUF_SIZE;
 
2501
                                if((conv_buf=H5FL_BLK_REALLOC(vlen_seq,conv_buf, conv_buf_size))==NULL)
 
2502
                                    HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed for type conversion");
 
2503
                            } /* end if */
 
2504
 
 
2505
                            /* Read in VL sequence */
 
2506
                            if((*(src->shared->u.vlen.read))(src->shared->u.vlen.f,dxpl_id,s,conv_buf,src_size)<0)
 
2507
                                HGOTO_ERROR(H5E_DATATYPE, H5E_READERROR, FAIL, "can't read VL data");
 
2508
                        } /* end else */
 
2509
 
 
2510
                        if(!noop_conv) {
 
2511
                            /* Check if temporary buffer is large enough, resize if necessary */
 
2512
                            /* (Chain off the conversion buffer size) */
 
2513
                            if(tmp_buf && tmp_buf_size<conv_buf_size) {
 
2514
                                /* Set up initial background buffer */
 
2515
                                tmp_buf_size=conv_buf_size;
 
2516
                                if((tmp_buf=H5FL_BLK_REALLOC(vlen_seq,tmp_buf,tmp_buf_size))==NULL)
 
2517
                                    HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed for type conversion");
 
2518
                            } /* end if */
 
2519
 
 
2520
                            /* If we are writing and there is a nested VL type, read
 
2521
                             * the sequence into the background buffer */
 
2522
                            if(nested) {
 
2523
                                uint8_t *tmp=b;
 
2524
                                UINT32DECODE(tmp, bg_seq_len);
 
2525
 
 
2526
                                if(bg_seq_len>0) {
 
2527
                                    if(tmp_buf_size<(bg_seq_len*MAX(src_base_size, dst_base_size))) {
 
2528
                                        tmp_buf_size=(bg_seq_len*MAX(src_base_size, dst_base_size));
 
2529
                                        if((tmp_buf=H5FL_BLK_REALLOC(vlen_seq,tmp_buf, tmp_buf_size))==NULL)
 
2530
                                            HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed for type conversion");
 
2531
                                    }
 
2532
                                    H5F_addr_decode(dst->shared->u.vlen.f, (const uint8_t **)&tmp, &(bg_hobjid.addr));
 
2533
                                    INT32DECODE(tmp, bg_hobjid.idx);
 
2534
                                    if(H5HG_read(dst->shared->u.vlen.f,dxpl_id,&bg_hobjid,tmp_buf)==NULL)
 
2535
                                        HGOTO_ERROR (H5E_DATATYPE, H5E_READERROR, FAIL, "can't read VL sequence into background buffer");
 
2536
                                } /* end if */
 
2537
 
 
2538
                                /* If the sequence gets shorter, pad out the original sequence with zeros */
 
2539
                                H5_CHECK_OVERFLOW(bg_seq_len,size_t,ssize_t);
 
2540
                                if((ssize_t)bg_seq_len<seq_len) {
 
2541
                                    HDmemset((uint8_t *)tmp_buf+dst_base_size*bg_seq_len,0,(seq_len-bg_seq_len)*dst_base_size);
 
2542
                                } /* end if */
 
2543
                            } /* end if */
 
2544
 
 
2545
                            /* Convert VL sequence */
 
2546
                            H5_CHECK_OVERFLOW(seq_len,ssize_t,size_t);
 
2547
                            if (H5T_convert(tpath, tsrc_id, tdst_id, (size_t)seq_len, 0, 0, conv_buf, tmp_buf, dxpl_id)<0)
 
2548
                                HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "datatype conversion failed");
 
2549
                        } /* end if */
 
2550
 
 
2551
                        /* Write sequence to destination location */
 
2552
                        if((*(dst->shared->u.vlen.write))(dst->shared->u.vlen.f,dxpl_id,vl_alloc_info,d,conv_buf, b, (size_t)seq_len, dst_base_size)<0)
 
2553
                            HGOTO_ERROR(H5E_DATATYPE, H5E_WRITEERROR, FAIL, "can't write VL data");
 
2554
 
 
2555
                        if(!noop_conv) {
 
2556
                            /* For nested VL case, free leftover heap objects from the deeper level if the length of new data elements is shorter than the old data elements.*/
 
2557
                            H5_CHECK_OVERFLOW(bg_seq_len,size_t,ssize_t);
 
2558
                            if(nested && seq_len<(ssize_t)bg_seq_len) {
 
2559
                                size_t parent_seq_len;
 
2560
                                size_t     u;
 
2561
 
 
2562
                                uint8_t *tmp_p=tmp_buf;
 
2563
                                tmp_p += seq_len*dst_base_size;
 
2564
                                for(u=0; u<(bg_seq_len-seq_len); u++) {
 
2565
                                    UINT32DECODE(tmp_p, parent_seq_len);
 
2566
                                    if(parent_seq_len>0) {
 
2567
                                        H5F_addr_decode(dst->shared->u.vlen.f, (const uint8_t **)&tmp_p, &(parent_hobjid.addr));
 
2568
                                        INT32DECODE(tmp_p, parent_hobjid.idx);
 
2569
                                        if(H5HG_remove(dst->shared->u.vlen.f, dxpl_id,&parent_hobjid)<0)
 
2570
                                            HGOTO_ERROR(H5E_DATATYPE, H5E_WRITEERROR, FAIL, "Unable to remove heap object");
 
2571
                                    }
 
2572
                                }
 
2573
                            } /* end if */
 
2574
                        } /* end if */
 
2575
                    } /* end else */
 
2576
 
 
2577
                    /* Advance pointers */
 
2578
                    s += s_stride;
 
2579
                    d += d_stride;
 
2580
                    b += b_stride;
 
2581
                } /* end for */
 
2582
 
 
2583
                /* Decrement number of elements left to convert */
 
2584
                nelmts-=safe;
 
2585
            } /* end while */
 
2586
 
 
2587
            /* Release the temporary datatype IDs used */
 
2588
            if (tsrc_id >= 0)
 
2589
                H5I_dec_ref(tsrc_id);
 
2590
            if (tdst_id >= 0)
 
2591
                H5I_dec_ref(tdst_id);
 
2592
            break;
 
2593
 
 
2594
        default:    /* Some other command we don't know about yet.*/
 
2595
            HGOTO_ERROR (H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, "unknown conversion command");
 
2596
    }   /* end switch */
 
2597
 
 
2598
done:
 
2599
    /* If the conversion buffer doesn't need to be freed, reset its pointer */
 
2600
    if(write_to_file && noop_conv)
 
2601
        conv_buf=NULL;
 
2602
    /* Release the conversion buffer (always allocated, except on errors) */
 
2603
    if(conv_buf!=NULL)
 
2604
        H5FL_BLK_FREE(vlen_seq,conv_buf);
 
2605
    /* Release the background buffer, if we have one */
 
2606
    if(tmp_buf!=NULL)
 
2607
        H5FL_BLK_FREE(vlen_seq,tmp_buf);
 
2608
 
 
2609
    FUNC_LEAVE_NOAPI(ret_value);
 
2610
}
 
2611
 
 
2612
 
 
2613
/*-------------------------------------------------------------------------
 
2614
 * Function:  H5T_conv_array
 
2615
 *
 
2616
 * Purpose:  Converts between array data types in memory and on disk.
 
2617
 *    This is a soft conversion function.
 
2618
 *
 
2619
 * Return:  Non-negative on success/Negative on failure
 
2620
 *
 
2621
 * Programmer:  Quincey Koziol
 
2622
 *    Monday, November 6, 2000
 
2623
 *
 
2624
 * Modifications:
 
2625
 *
 
2626
 *-------------------------------------------------------------------------
 
2627
 */
 
2628
herr_t
 
2629
H5T_conv_array(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, size_t nelmts,
 
2630
        size_t buf_stride, size_t bkg_stride, void *_buf,
 
2631
              void UNUSED *_bkg, hid_t dxpl_id)
 
2632
{
 
2633
    H5T_path_t  *tpath;            /* Type conversion path         */
 
2634
    hid_t       tsrc_id = -1, tdst_id = -1;/*temporary type atoms       */
 
2635
    H5T_t  *src = NULL;          /*source data type         */
 
2636
    H5T_t  *dst = NULL;          /*destination data type         */
 
2637
    uint8_t  *sp, *dp;          /*source and dest traversal ptrs     */
 
2638
    size_t  src_delta, dst_delta;  /*source & destination stride       */
 
2639
    int          direction;    /*direction of traversal       */
 
2640
    size_t  elmtno;      /*element number counter       */
 
2641
    int         i;                      /* local index variable */
 
2642
    void  *bkg_buf=NULL;       /*temporary background buffer        */
 
2643
    size_t  bkg_buf_size=0;          /*size of background buffer in bytes */
 
2644
    herr_t      ret_value=SUCCEED;       /* Return value */
 
2645
 
 
2646
    FUNC_ENTER_NOAPI(H5T_conv_array, FAIL);
 
2647
 
 
2648
    switch (cdata->command) {
 
2649
        case H5T_CONV_INIT:
 
2650
            /*
 
2651
             * First, determine if this conversion function applies to the
 
2652
             * conversion path SRC_ID-->DST_ID.  If not, return failure;
 
2653
             * otherwise initialize the `priv' field of `cdata' with
 
2654
             * information that remains (almost) constant for this
 
2655
             * conversion path.
 
2656
             */
 
2657
            if (NULL == (src = H5I_object(src_id)) ||
 
2658
                    NULL == (dst = H5I_object(dst_id)))
 
2659
                HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a data type");
 
2660
            assert (H5T_ARRAY==src->shared->type);
 
2661
            assert (H5T_ARRAY==dst->shared->type);
 
2662
 
 
2663
            /* Check the number and sizes of the dimensions */
 
2664
            if(src->shared->u.array.ndims!=dst->shared->u.array.ndims)
 
2665
                HGOTO_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, "array datatypes do not have the same number of dimensions");
 
2666
            for(i=0; i<src->shared->u.array.ndims; i++)
 
2667
                if(src->shared->u.array.dim[i]!=dst->shared->u.array.dim[i])
 
2668
                    HGOTO_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, "array datatypes do not have the same sizes of dimensions");
 
2669
#ifdef LATER
 
2670
            for(i=0; i<src->shared->u.array.ndims; i++)
 
2671
                if(src->shared->u.array.perm[i]!=dst->shared->u.array.perm[i])
 
2672
                    HGOTO_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, "array datatypes do not have the same dimension permutations");
 
2673
#endif /* LATER */
 
2674
 
 
2675
            /* Array datatypes don't need a background buffer */
 
2676
            cdata->need_bkg = H5T_BKG_NO;
 
2677
 
 
2678
            break;
 
2679
 
 
2680
        case H5T_CONV_FREE:
 
2681
            /* QAK - Nothing to do currently */
 
2682
            break;
 
2683
 
 
2684
        case H5T_CONV_CONV:
 
2685
            /*
 
2686
             * Conversion.
 
2687
             */
 
2688
            if (NULL == (src = H5I_object(src_id)) ||
 
2689
                    NULL == (dst = H5I_object(dst_id)))
 
2690
                HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a data type");
 
2691
 
 
2692
            /*
 
2693
             * Do we process the values from beginning to end or vice
 
2694
             * versa? Also, how many of the elements have the source and
 
2695
             * destination areas overlapping?
 
2696
             */
 
2697
            if (src->shared->size>=dst->shared->size || buf_stride>0) {
 
2698
                sp = dp = (uint8_t*)_buf;
 
2699
                direction = 1;
 
2700
            } else {
 
2701
                sp = (uint8_t*)_buf + (nelmts-1) *
 
2702
                     (buf_stride ? buf_stride : src->shared->size);
 
2703
                dp = (uint8_t*)_buf + (nelmts-1) *
 
2704
                     (buf_stride ? buf_stride : dst->shared->size);
 
2705
                direction = -1;
 
2706
            }
 
2707
 
 
2708
            /*
 
2709
             * Direction & size of buffer traversal.
 
2710
             */
 
2711
            src_delta = direction * (buf_stride ? buf_stride : src->shared->size);
 
2712
            dst_delta = direction * (buf_stride ? buf_stride : dst->shared->size);
 
2713
 
 
2714
            /* Set up conversion path for base elements */
 
2715
            if (NULL==(tpath=H5T_path_find(src->shared->parent, dst->shared->parent, NULL, NULL, dxpl_id))) {
 
2716
                HGOTO_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, "unable to convert between src and dest datatypes");
 
2717
            } else if (!H5T_path_noop(tpath)) {
 
2718
                if ((tsrc_id = H5I_register(H5I_DATATYPE, H5T_copy(src->shared->parent, H5T_COPY_ALL)))<0 ||
 
2719
                        (tdst_id = H5I_register(H5I_DATATYPE, H5T_copy(dst->shared->parent, H5T_COPY_ALL)))<0)
 
2720
                    HGOTO_ERROR(H5E_DATASET, H5E_CANTREGISTER, FAIL, "unable to register types for conversion");
 
2721
            }
 
2722
 
 
2723
            /* Check if we need a background buffer for this conversion */
 
2724
            if(tpath->cdata.need_bkg) {
 
2725
                /* Allocate background buffer */
 
2726
                bkg_buf_size=src->shared->u.array.nelem*MAX(src->shared->size,dst->shared->size);
 
2727
                if ((bkg_buf=H5FL_BLK_CALLOC(array_seq,bkg_buf_size))==NULL)
 
2728
                    HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed for type conversion");
 
2729
            } /* end if */
 
2730
 
 
2731
            /* Perform the actual conversion */
 
2732
            for (elmtno=0; elmtno<nelmts; elmtno++) {
 
2733
                /* Copy the source array into the correct location for the destination */
 
2734
                HDmemmove(dp, sp, src->shared->size);
 
2735
 
 
2736
                /* Convert array */
 
2737
                if (H5T_convert(tpath, tsrc_id, tdst_id, src->shared->u.array.nelem, 0, bkg_stride, dp, bkg_buf, dxpl_id)<0)
 
2738
                    HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "datatype conversion failed");
 
2739
 
 
2740
                /* Advance the source & destination pointers */
 
2741
                sp += src_delta;
 
2742
                dp += dst_delta;
 
2743
            }
 
2744
 
 
2745
            /* Release the background buffer, if we have one */
 
2746
            if(bkg_buf!=NULL)
 
2747
                H5FL_BLK_FREE(array_seq,bkg_buf);
 
2748
 
 
2749
            /* Release the temporary datatype IDs used */
 
2750
            if (tsrc_id >= 0)
 
2751
                H5I_dec_ref(tsrc_id);
 
2752
            if (tdst_id >= 0)
 
2753
                H5I_dec_ref(tdst_id);
 
2754
            break;
 
2755
 
 
2756
        default:    /* Some other command we don't know about yet.*/
 
2757
            HGOTO_ERROR (H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, "unknown conversion command");
 
2758
    }   /* end switch */
 
2759
 
 
2760
done:
 
2761
    FUNC_LEAVE_NOAPI(ret_value);
 
2762
}   /* end H5T_conv_array() */
 
2763
 
 
2764
 
 
2765
/*-------------------------------------------------------------------------
 
2766
 * Function:  H5T_conv_i_i
 
2767
 *
 
2768
 * Purpose:  Convert one integer type to another.  This is the catch-all
 
2769
 *    function for integer conversions and is probably not
 
2770
 *    particularly fast.
 
2771
 *
 
2772
 * Return:  Non-negative on success/Negative on failure
 
2773
 *
 
2774
 * Programmer:  Robb Matzke
 
2775
 *    Wednesday, June 10, 1998
 
2776
 *
 
2777
 * Modifications:
 
2778
 *    Robb Matzke, 7 Jul 1998
 
2779
 *    Added overflow handling.
 
2780
 *
 
2781
 *    Robb Matzke, 1999-06-16
 
2782
 *    Added support for non-zero strides. If BUF_STRIDE is non-zero
 
2783
 *    then convert one value at each memory location advancing
 
2784
 *    BUF_STRIDE bytes each time; otherwise assume both source and
 
2785
 *    destination values are packed.
 
2786
 *-------------------------------------------------------------------------
 
2787
 */
 
2788
herr_t
 
2789
H5T_conv_i_i (hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, size_t nelmts,
 
2790
        size_t buf_stride, size_t UNUSED bkg_stride, void *buf,
 
2791
              void UNUSED *bkg, hid_t UNUSED dxpl_id)
 
2792
{
 
2793
    H5T_t  *src = NULL;    /*source data type    */
 
2794
    H5T_t  *dst = NULL;    /*destination data type    */
 
2795
    int    direction;    /*direction of traversal  */
 
2796
    size_t  elmtno;      /*element number    */
 
2797
    size_t  half_size;    /*half the type size    */
 
2798
    size_t  olap;      /*num overlapping elements  */
 
2799
    uint8_t  *s, *sp, *d, *dp;  /*source and dest traversal ptrs*/
 
2800
    uint8_t  dbuf[64];    /*temp destination buffer  */
 
2801
    size_t  first;
 
2802
    ssize_t  sfirst;      /*a signed version of `first'  */
 
2803
    size_t  i;                      /*Local index variables         */
 
2804
    herr_t      ret_value=SUCCEED;       /* Return value */
 
2805
 
 
2806
    FUNC_ENTER_NOAPI(H5T_conv_i_i, FAIL);
 
2807
 
 
2808
    switch (cdata->command) {
 
2809
        case H5T_CONV_INIT:
 
2810
            if (NULL==(src=H5I_object(src_id)) ||
 
2811
                    NULL==(dst=H5I_object(dst_id)))
 
2812
                HGOTO_ERROR (H5E_ARGS, H5E_BADTYPE, FAIL, "not a data type");
 
2813
            if (H5T_ORDER_LE!=src->shared->u.atomic.order &&
 
2814
                    H5T_ORDER_BE!=src->shared->u.atomic.order)
 
2815
                HGOTO_ERROR (H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, "unsupported byte order");
 
2816
            if (H5T_ORDER_LE!=dst->shared->u.atomic.order &&
 
2817
                    H5T_ORDER_BE!=dst->shared->u.atomic.order)
 
2818
                HGOTO_ERROR (H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, "unsupported byte order");
 
2819
            if (dst->shared->size>sizeof dbuf)
 
2820
                HGOTO_ERROR (H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, "destination size is too large");
 
2821
            cdata->need_bkg = H5T_BKG_NO;
 
2822
            break;
 
2823
 
 
2824
        case H5T_CONV_FREE:
 
2825
            break;
 
2826
 
 
2827
        case H5T_CONV_CONV:
 
2828
            /* Get the data types */
 
2829
            if (NULL==(src=H5I_object(src_id)) ||
 
2830
                    NULL==(dst=H5I_object(dst_id)))
 
2831
                HGOTO_ERROR (H5E_ARGS, H5E_BADTYPE, FAIL, "not a data type");
 
2832
 
 
2833
            /*
 
2834
             * Do we process the values from beginning to end or vice versa? Also,
 
2835
             * how many of the elements have the source and destination areas
 
2836
             * overlapping?
 
2837
             */
 
2838
            if (src->shared->size==dst->shared->size || buf_stride) {
 
2839
                sp = dp = (uint8_t*)buf;
 
2840
                direction = 1;
 
2841
                olap = nelmts;
 
2842
            } else if (src->shared->size>=dst->shared->size) {
 
2843
                double olap_d = HDceil((double)(dst->shared->size)/
 
2844
                                       (double)(src->shared->size-dst->shared->size));
 
2845
 
 
2846
                olap = (size_t)olap_d;
 
2847
                sp = dp = (uint8_t*)buf;
 
2848
                direction = 1;
 
2849
            } else {
 
2850
                double olap_d = HDceil((double)(src->shared->size)/
 
2851
                                       (double)(dst->shared->size-src->shared->size));
 
2852
                olap = (size_t)olap_d;
 
2853
                sp = (uint8_t*)buf + (nelmts-1) * src->shared->size;
 
2854
                dp = (uint8_t*)buf + (nelmts-1) * dst->shared->size;
 
2855
                direction = -1;
 
2856
            }
 
2857
 
 
2858
            /* The conversion loop */
 
2859
            for (elmtno=0; elmtno<nelmts; elmtno++) {
 
2860
 
 
2861
                /*
 
2862
                 * If the source and destination buffers overlap then use a
 
2863
                 * temporary buffer for the destination.
 
2864
                 */
 
2865
                if (direction>0) {
 
2866
                    s = sp;
 
2867
                    d = elmtno<olap ? dbuf : dp;
 
2868
                } else {
 
2869
                    s = sp;
 
2870
                    d = elmtno+olap >= nelmts ? dbuf : dp;
 
2871
                }
 
2872
#ifndef NDEBUG
 
2873
                /* I don't quite trust the overlap calculations yet --rpm */
 
2874
                if (d==dbuf) {
 
2875
                    assert ((dp>=sp && dp<sp+src->shared->size) || (sp>=dp && sp<dp+dst->shared->size));
 
2876
                } else {
 
2877
                    assert ((dp<sp && dp+dst->shared->size<=sp) || (sp<dp && sp+src->shared->size<=dp));
 
2878
                }
 
2879
#endif
 
2880
 
 
2881
                /*
 
2882
                 * Put the data in little endian order so our loops aren't so
 
2883
                 * complicated.  We'll do all the conversion stuff assuming
 
2884
                 * little endian and then we'll fix the order at the end.
 
2885
                 */
 
2886
                if (H5T_ORDER_BE==src->shared->u.atomic.order) {
 
2887
                    half_size = src->shared->size/2;
 
2888
                    for (i=0; i<half_size; i++) {
 
2889
                        uint8_t tmp = s[src->shared->size-(i+1)];
 
2890
                        s[src->shared->size-(i+1)] = s[i];
 
2891
                        s[i] = tmp;
 
2892
                    }
 
2893
                }
 
2894
 
 
2895
                /*
 
2896
                 * What is the bit number for the msb bit of S which is set? The
 
2897
                 * bit number is relative to the significant part of the number.
 
2898
                 */
 
2899
                sfirst = H5T_bit_find (s, src->shared->u.atomic.offset, src->shared->u.atomic.prec,
 
2900
                                       H5T_BIT_MSB, TRUE);
 
2901
                first = (size_t)sfirst;
 
2902
 
 
2903
                if (sfirst<0) {
 
2904
                    /*
 
2905
                     * The source has no bits set and must therefore be zero.
 
2906
                     * Set the destination to zero.
 
2907
                     */
 
2908
                    H5T_bit_set (d, dst->shared->u.atomic.offset, dst->shared->u.atomic.prec, FALSE);
 
2909
 
 
2910
                } else if (H5T_SGN_NONE==src->shared->u.atomic.u.i.sign &&
 
2911
                           H5T_SGN_NONE==dst->shared->u.atomic.u.i.sign) {
 
2912
                    /*
 
2913
                     * Source and destination are both unsigned, but if the
 
2914
                     * source has more precision bits than the destination then
 
2915
                     * it's possible to overflow.  When overflow occurs the
 
2916
                     * destination will be set to the maximum possible value.
 
2917
                     */
 
2918
                    if (src->shared->u.atomic.prec <= dst->shared->u.atomic.prec) {
 
2919
                        H5T_bit_copy (d, dst->shared->u.atomic.offset, s, src->shared->u.atomic.offset,
 
2920
                              src->shared->u.atomic.prec);
 
2921
                        H5T_bit_set (d, dst->shared->u.atomic.offset+src->shared->u.atomic.prec,
 
2922
                             dst->shared->u.atomic.prec-src->shared->u.atomic.prec, FALSE);
 
2923
                    } else if (first>=dst->shared->u.atomic.prec) {
 
2924
                        /*overflow*/
 
2925
                        if (!H5T_overflow_g || (H5T_overflow_g)(src_id, dst_id, s, d)<0) {
 
2926
                            H5T_bit_set (d, dst->shared->u.atomic.offset, dst->shared->u.atomic.prec, TRUE);
 
2927
                        }
 
2928
                    } else {
 
2929
                        H5T_bit_copy (d, dst->shared->u.atomic.offset, s, src->shared->u.atomic.offset,
 
2930
                              dst->shared->u.atomic.prec);
 
2931
                    }
 
2932
 
 
2933
                } else if (H5T_SGN_2==src->shared->u.atomic.u.i.sign &&
 
2934
                           H5T_SGN_NONE==dst->shared->u.atomic.u.i.sign) {
 
2935
                    /*
 
2936
                     * If the source is signed and the destination isn't then we
 
2937
                     * can have overflow if the source contains more bits than
 
2938
                     * the destination (destination is set to the maximum
 
2939
                     * possible value) or overflow if the source is negative
 
2940
                     * (destination is set to zero).
 
2941
                     */
 
2942
                    if (first+1 == src->shared->u.atomic.prec) {
 
2943
                        /*overflow*/
 
2944
                        if (!H5T_overflow_g || (H5T_overflow_g)(src_id, dst_id, s, d)<0) {
 
2945
                            H5T_bit_set (d, dst->shared->u.atomic.offset, dst->shared->u.atomic.prec, FALSE);
 
2946
                        }
 
2947
                    } else if (src->shared->u.atomic.prec < dst->shared->u.atomic.prec) {
 
2948
                        H5T_bit_copy (d, dst->shared->u.atomic.offset, s, src->shared->u.atomic.offset,
 
2949
                              src->shared->u.atomic.prec-1);
 
2950
                        H5T_bit_set (d, dst->shared->u.atomic.offset+src->shared->u.atomic.prec-1,
 
2951
                             (dst->shared->u.atomic.prec-src->shared->u.atomic.prec)+1, FALSE);
 
2952
                    } else if (first>=dst->shared->u.atomic.prec) {
 
2953
                        /*overflow*/
 
2954
                        if (!H5T_overflow_g || (H5T_overflow_g)(src_id, dst_id, s, d)<0) {
 
2955
                            H5T_bit_set (d, dst->shared->u.atomic.offset, dst->shared->u.atomic.prec, TRUE);
 
2956
                        }
 
2957
                    } else {
 
2958
                        H5T_bit_copy (d, dst->shared->u.atomic.offset, s, src->shared->u.atomic.offset,
 
2959
                              dst->shared->u.atomic.prec);
 
2960
                    }
 
2961
 
 
2962
                } else if (H5T_SGN_NONE==src->shared->u.atomic.u.i.sign &&
 
2963
                           H5T_SGN_2==dst->shared->u.atomic.u.i.sign) {
 
2964
                    /*
 
2965
                     * If the source is not signed but the destination is then
 
2966
                     * overflow can occur in which case the destination is set to
 
2967
                     * the largest possible value (all bits set except the msb).
 
2968
                     */
 
2969
                    if (first+1 >= dst->shared->u.atomic.prec) {
 
2970
                        /*overflow*/
 
2971
                        if (!H5T_overflow_g || (H5T_overflow_g)(src_id, dst_id, s, d)<0) {
 
2972
                            H5T_bit_set (d, dst->shared->u.atomic.offset, dst->shared->u.atomic.prec-1, TRUE);
 
2973
                            H5T_bit_set (d, (dst->shared->u.atomic.offset + dst->shared->u.atomic.prec-1), 1, FALSE);
 
2974
                        }
 
2975
                    } else if (src->shared->u.atomic.prec<dst->shared->u.atomic.prec) {
 
2976
                        H5T_bit_copy (d, dst->shared->u.atomic.offset, s, src->shared->u.atomic.offset,
 
2977
                              src->shared->u.atomic.prec);
 
2978
                        H5T_bit_set (d, dst->shared->u.atomic.offset+src->shared->u.atomic.prec,
 
2979
                             dst->shared->u.atomic.prec-src->shared->u.atomic.prec, FALSE);
 
2980
                    } else {
 
2981
                        H5T_bit_copy (d, dst->shared->u.atomic.offset, s, src->shared->u.atomic.offset,
 
2982
                              dst->shared->u.atomic.prec);
 
2983
                    }
 
2984
                } else if (first+1 == src->shared->u.atomic.prec) {
 
2985
                    /*
 
2986
                     * Both the source and the destination are signed and the
 
2987
                     * source value is negative.  We could experience overflow
 
2988
                     * if the destination isn't wide enough in which case the
 
2989
                     * destination is set to a negative number with the largest
 
2990
                     * possible magnitude.
 
2991
                     */
 
2992
                    ssize_t sfz = H5T_bit_find (s, src->shared->u.atomic.offset,
 
2993
                                    src->shared->u.atomic.prec-1, H5T_BIT_MSB, FALSE);
 
2994
                    size_t fz = (size_t)sfz;
 
2995
 
 
2996
                    if (sfz>=0 && fz+1>=dst->shared->u.atomic.prec) {
 
2997
                        /*overflow*/
 
2998
                        if (!H5T_overflow_g || (H5T_overflow_g)(src_id, dst_id, s, d)<0) {
 
2999
                            H5T_bit_set (d, dst->shared->u.atomic.offset, dst->shared->u.atomic.prec-1, FALSE);
 
3000
                            H5T_bit_set (d, (dst->shared->u.atomic.offset + dst->shared->u.atomic.prec-1), 1, TRUE);
 
3001
                        }
 
3002
                    } else if (src->shared->u.atomic.prec<dst->shared->u.atomic.prec) {
 
3003
                        H5T_bit_copy (d, dst->shared->u.atomic.offset, s, src->shared->u.atomic.offset, src->shared->u.atomic.prec);
 
3004
                        H5T_bit_set (d, dst->shared->u.atomic.offset+src->shared->u.atomic.prec, dst->shared->u.atomic.prec-src->shared->u.atomic.prec, TRUE);
 
3005
                    } else {
 
3006
                        H5T_bit_copy (d, dst->shared->u.atomic.offset, s, src->shared->u.atomic.offset, dst->shared->u.atomic.prec);
 
3007
                    }
 
3008
 
 
3009
                } else {
 
3010
                    /*
 
3011
                     * Source and destination are both signed but the source
 
3012
                     * value is positive.  We could have an overflow in which
 
3013
                     * case the destination is set to the largest possible
 
3014
                     * positive value.
 
3015
                     */
 
3016
                    if (first+1>=dst->shared->u.atomic.prec) {
 
3017
                        /*overflow*/
 
3018
                        if (!H5T_overflow_g || (H5T_overflow_g)(src_id, dst_id, s, d)<0) {
 
3019
                            H5T_bit_set (d, dst->shared->u.atomic.offset, dst->shared->u.atomic.prec-1, TRUE);
 
3020
                            H5T_bit_set (d, (dst->shared->u.atomic.offset + dst->shared->u.atomic.prec-1), 1, FALSE);
 
3021
                        }
 
3022
                    } else if (src->shared->u.atomic.prec<dst->shared->u.atomic.prec) {
 
3023
                        H5T_bit_copy (d, dst->shared->u.atomic.offset, s, src->shared->u.atomic.offset,
 
3024
                              src->shared->u.atomic.prec);
 
3025
                        H5T_bit_set (d, dst->shared->u.atomic.offset+src->shared->u.atomic.prec,
 
3026
                             dst->shared->u.atomic.prec-src->shared->u.atomic.prec, FALSE);
 
3027
                    } else {
 
3028
                        H5T_bit_copy (d, dst->shared->u.atomic.offset, s, src->shared->u.atomic.offset,
 
3029
                              dst->shared->u.atomic.prec);
 
3030
                    }
 
3031
                }
 
3032
 
 
3033
                /*
 
3034
                 * Set padding areas in destination.
 
3035
                 */
 
3036
                if (dst->shared->u.atomic.offset>0) {
 
3037
                    assert (H5T_PAD_ZERO==dst->shared->u.atomic.lsb_pad || H5T_PAD_ONE==dst->shared->u.atomic.lsb_pad);
 
3038
                    H5T_bit_set (d, 0, dst->shared->u.atomic.offset, (hbool_t)(H5T_PAD_ONE==dst->shared->u.atomic.lsb_pad));
 
3039
                }
 
3040
                if (dst->shared->u.atomic.offset+dst->shared->u.atomic.prec!=8*dst->shared->size) {
 
3041
                    assert (H5T_PAD_ZERO==dst->shared->u.atomic.msb_pad || H5T_PAD_ONE==dst->shared->u.atomic.msb_pad);
 
3042
                    H5T_bit_set (d, dst->shared->u.atomic.offset+dst->shared->u.atomic.prec,
 
3043
                                 8*dst->shared->size - (dst->shared->u.atomic.offset+ dst->shared->u.atomic.prec),
 
3044
                                 (hbool_t)(H5T_PAD_ONE==dst->shared->u.atomic.msb_pad));
 
3045
                }
 
3046
 
 
3047
                /*
 
3048
                 * Put the destination in the correct byte order.  See note at
 
3049
                 * beginning of loop.
 
3050
                 */
 
3051
                if (H5T_ORDER_BE==dst->shared->u.atomic.order) {
 
3052
                    half_size = dst->shared->size/2;
 
3053
                    for (i=0; i<half_size; i++) {
 
3054
                        uint8_t tmp = d[dst->shared->size-(i+1)];
 
3055
                        d[dst->shared->size-(i+1)] = d[i];
 
3056
                        d[i] = tmp;
 
3057
                    }
 
3058
                }
 
3059
 
 
3060
                /*
 
3061
                 * If we had used a temporary buffer for the destination then we
 
3062
                 * should copy the value to the true destination buffer.
 
3063
                 */
 
3064
                if (d==dbuf)
 
3065
                    HDmemcpy (dp, d, dst->shared->size);
 
3066
                if (buf_stride) {
 
3067
                    sp += direction * buf_stride;
 
3068
                    dp += direction * buf_stride;
 
3069
                } else {
 
3070
                    sp += direction * src->shared->size;
 
3071
                    dp += direction * dst->shared->size;
 
3072
                }
 
3073
            }
 
3074
 
 
3075
            break;
 
3076
 
 
3077
        default:
 
3078
            HGOTO_ERROR (H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, "unknown conversion command");
 
3079
    }
 
3080
 
 
3081
done:
 
3082
    FUNC_LEAVE_NOAPI(ret_value);
 
3083
}
 
3084
 
 
3085
 
 
3086
/*-------------------------------------------------------------------------
 
3087
 * Function:  H5T_conv_f_f
 
3088
 *
 
3089
 * Purpose:  Convert one floating point type to another.  This is a catch
 
3090
 *    all for floating point conversions and is probably not
 
3091
 *    particularly fast!
 
3092
 *
 
3093
 * Return:  Non-negative on success/Negative on failure
 
3094
 *
 
3095
 * Programmer:  Robb Matzke
 
3096
 *    Tuesday, June 23, 1998
 
3097
 *
 
3098
 * Modifications:
 
3099
 *    Robb Matzke, 7 Jul 1998
 
3100
 *    Added overflow handling.
 
3101
 *
 
3102
 *    Robb Matzke, 1999-06-16
 
3103
 *    Added support for non-zero strides. If BUF_STRIDE is non-zero
 
3104
 *    then convert one value at each memory location advancing
 
3105
 *    BUF_STRIDE bytes each time; otherwise assume both source and
 
3106
 *    destination values are packed.
 
3107
 *
 
3108
 *              Robb Matzke, 2001-02-02
 
3109
 *              Oops, forgot to increment the exponent when rounding the
 
3110
 *              significand resulted in a carry. Thanks to Guillaume Colin
 
3111
 *              de Verdiere for finding this one!
 
3112
 *-------------------------------------------------------------------------
 
3113
 */
 
3114
herr_t
 
3115
H5T_conv_f_f (hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, size_t nelmts,
 
3116
    size_t buf_stride, size_t UNUSED bkg_stride, void *buf, void UNUSED *bkg,
 
3117
    hid_t UNUSED dxpl_id)
 
3118
{
 
3119
    /* Traversal-related variables */
 
3120
    H5T_t  *src_p;      /*source data type    */
 
3121
    H5T_t  *dst_p;      /*destination data type    */
 
3122
    H5T_atomic_t src;      /*atomic source info    */
 
3123
    H5T_atomic_t dst;      /*atomic destination info  */
 
3124
    int  direction;            /*forward or backward traversal  */
 
3125
    hbool_t     denormalized=FALSE;     /*is either source or destination denormalized?*/
 
3126
    size_t  elmtno;      /*element number    */
 
3127
    size_t  half_size;    /*half the type size    */
 
3128
    size_t  olap;      /*num overlapping elements  */
 
3129
    ssize_t  bitno=-1;    /*bit number      */
 
3130
    uint8_t  *s, *sp, *d, *dp;  /*source and dest traversal ptrs*/
 
3131
    uint8_t  dbuf[64];    /*temp destination buffer  */
 
3132
 
 
3133
    /* Conversion-related variables */
 
3134
    hssize_t  expo;      /*exponent      */
 
3135
    hssize_t  expo_max;    /*maximum possible dst exponent  */
 
3136
    size_t  msize=0;    /*useful size of mantissa in src*/
 
3137
    size_t  mpos;      /*offset to useful mant is src  */
 
3138
    size_t  mrsh;      /*amount to right shift mantissa*/
 
3139
    hbool_t  carry=0;    /*carry after rounding mantissa  */
 
3140
    size_t  i;      /*miscellaneous counters  */
 
3141
    size_t  implied;    /*destination implied bits  */
 
3142
    herr_t      ret_value=SUCCEED;      /*return value                 */
 
3143
 
 
3144
    FUNC_ENTER_NOAPI(H5T_conv_f_f, FAIL);
 
3145
 
 
3146
    switch (cdata->command) {
 
3147
        case H5T_CONV_INIT:
 
3148
            if (NULL==(src_p=H5I_object(src_id)) ||
 
3149
                    NULL==(dst_p=H5I_object(dst_id)))
 
3150
                HGOTO_ERROR (H5E_ARGS, H5E_BADTYPE, FAIL, "not a data type");
 
3151
            src = src_p->shared->u.atomic;
 
3152
            dst = dst_p->shared->u.atomic;
 
3153
            if (H5T_ORDER_LE!=src.order && H5T_ORDER_BE!=src.order)
 
3154
                HGOTO_ERROR (H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, "unsupported byte order");
 
3155
            if (H5T_ORDER_LE!=dst.order && H5T_ORDER_BE!=dst.order)
 
3156
                HGOTO_ERROR (H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, "unsupported byte order");
 
3157
            if (dst_p->shared->size>sizeof(dbuf))
 
3158
                HGOTO_ERROR (H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, "destination size is too large");
 
3159
            if (8*sizeof(expo)-1<src.u.f.esize || 8*sizeof(expo)-1<dst.u.f.esize)
 
3160
                HGOTO_ERROR (H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, "exponent field is too large");
 
3161
            cdata->need_bkg = H5T_BKG_NO;
 
3162
            break;
 
3163
 
 
3164
        case H5T_CONV_FREE:
 
3165
            break;
 
3166
 
 
3167
        case H5T_CONV_CONV:
 
3168
            /* Get the data types */
 
3169
            if (NULL==(src_p=H5I_object(src_id)) ||
 
3170
                    NULL==(dst_p=H5I_object(dst_id)))
 
3171
                HGOTO_ERROR (H5E_ARGS, H5E_BADTYPE, FAIL, "not a data type");
 
3172
            src = src_p->shared->u.atomic;
 
3173
            dst = dst_p->shared->u.atomic;
 
3174
            expo_max = ((hssize_t)1 << dst.u.f.esize) - 1;
 
3175
 
 
3176
            /*
 
3177
             * Do we process the values from beginning to end or vice versa? Also,
 
3178
             * how many of the elements have the source and destination areas
 
3179
             * overlapping?
 
3180
             */
 
3181
            if (src_p->shared->size==dst_p->shared->size || buf_stride) {
 
3182
                sp = dp = (uint8_t*)buf;
 
3183
                direction = 1;
 
3184
                olap = nelmts;
 
3185
            } else if (src_p->shared->size>=dst_p->shared->size) {
 
3186
                double olap_d = HDceil((double)(dst_p->shared->size)/
 
3187
                                       (double)(src_p->shared->size-dst_p->shared->size));
 
3188
                olap = (size_t)olap_d;
 
3189
                sp = dp = (uint8_t*)buf;
 
3190
                direction = 1;
 
3191
            } else {
 
3192
                double olap_d = HDceil((double)(src_p->shared->size)/
 
3193
                                       (double)(dst_p->shared->size-src_p->shared->size));
 
3194
                olap = (size_t)olap_d;
 
3195
                sp = (uint8_t*)buf + (nelmts-1) * src_p->shared->size;
 
3196
                dp = (uint8_t*)buf + (nelmts-1) * dst_p->shared->size;
 
3197
                direction = -1;
 
3198
            }
 
3199
 
 
3200
            /* The conversion loop */
 
3201
            for (elmtno=0; elmtno<nelmts; elmtno++) {
 
3202
                /*
 
3203
                 * If the source and destination buffers overlap then use a
 
3204
                 * temporary buffer for the destination.
 
3205
                 */
 
3206
                if (direction>0) {
 
3207
                    s = sp;
 
3208
                    d = elmtno<olap ? dbuf : dp;
 
3209
                } else {
 
3210
                    s = sp;
 
3211
                    d = elmtno+olap >= nelmts ? dbuf : dp;
 
3212
                }
 
3213
#ifndef NDEBUG
 
3214
                /* I don't quite trust the overlap calculations yet --rpm */
 
3215
                if (d==dbuf) {
 
3216
                    assert ((dp>=sp && dp<sp+src_p->shared->size) ||
 
3217
                            (sp>=dp && sp<dp+dst_p->shared->size));
 
3218
                } else {
 
3219
                    assert ((dp<sp && dp+dst_p->shared->size<=sp) ||
 
3220
                            (sp<dp && sp+src_p->shared->size<=dp));
 
3221
                }
 
3222
#endif
 
3223
 
 
3224
                /*
 
3225
                 * Put the data in little endian order so our loops aren't so
 
3226
                 * complicated.  We'll do all the conversion stuff assuming
 
3227
                 * little endian and then we'll fix the order at the end.
 
3228
                 */
 
3229
                if (H5T_ORDER_BE==src.order) {
 
3230
                    half_size = src_p->shared->size/2;
 
3231
                    for (i=0; i<half_size; i++) {
 
3232
                        uint8_t tmp = s[src_p->shared->size-(i+1)];
 
3233
                        s[src_p->shared->size-(i+1)] = s[i];
 
3234
                        s[i] = tmp;
 
3235
                    }
 
3236
                }
 
3237
 
 
3238
                /*
 
3239
                 * Check for special cases: +0, -0, +Inf, -Inf, NaN
 
3240
                 */
 
3241
                if (H5T_bit_find (s, src.u.f.mpos, src.u.f.msize,
 
3242
                                  H5T_BIT_LSB, TRUE)<0) {
 
3243
                    if (H5T_bit_find (s, src.u.f.epos, src.u.f.esize,
 
3244
                                      H5T_BIT_LSB, TRUE)<0) {
 
3245
                        /* +0 or -0 */
 
3246
                        H5T_bit_copy (d, dst.u.f.sign, s, src.u.f.sign, 1);
 
3247
                        H5T_bit_set (d, dst.u.f.epos, dst.u.f.esize, FALSE);
 
3248
                        H5T_bit_set (d, dst.u.f.mpos, dst.u.f.msize, FALSE);
 
3249
                        goto padding;
 
3250
                    } else if (H5T_bit_find (s, src.u.f.epos, src.u.f.esize,
 
3251
                                             H5T_BIT_LSB, FALSE)<0) {
 
3252
                        /* +Inf or -Inf */
 
3253
                        H5T_bit_copy (d, dst.u.f.sign, s, src.u.f.sign, 1);
 
3254
                        H5T_bit_set (d, dst.u.f.epos, dst.u.f.esize, TRUE);
 
3255
                        H5T_bit_set (d, dst.u.f.mpos, dst.u.f.msize, FALSE);
 
3256
                        /*If the destination no implied mantissa bit, we'll need to set
 
3257
                         *the 1st bit of mantissa to 1.  The Intel-Linux long double is
 
3258
                         *this case.*/
 
3259
                        if (H5T_NORM_NONE==dst.u.f.norm)
 
3260
                            H5T_bit_set (d, dst.u.f.mpos+dst.u.f.msize-1, 1, TRUE);
 
3261
                        goto padding;
 
3262
                    }
 
3263
                } else if (H5T_NORM_NONE==src.u.f.norm && H5T_bit_find (s, src.u.f.mpos, src.u.f.msize-1,
 
3264
                                  H5T_BIT_LSB, TRUE)<0 && H5T_bit_find (s, src.u.f.epos, src.u.f.esize,
 
3265
                                  H5T_BIT_LSB, FALSE)<0) {
 
3266
                    /*This is a special case for the source of no implied mantissa bit.
 
3267
                     *If the exponent bits are all 1s and only the 1st bit of mantissa
 
3268
                     *is set to 1.  It's infinity. The Intel-Linux "long double" is this case.*/
 
3269
                    /* +Inf or -Inf */
 
3270
                    H5T_bit_copy (d, dst.u.f.sign, s, src.u.f.sign, 1);
 
3271
                    H5T_bit_set (d, dst.u.f.epos, dst.u.f.esize, TRUE);
 
3272
                    H5T_bit_set (d, dst.u.f.mpos, dst.u.f.msize, FALSE);
 
3273
                    /*If the destination no implied mantissa bit, we'll need to set
 
3274
                     *the 1st bit of mantissa to 1.*/
 
3275
                    if (H5T_NORM_NONE==dst.u.f.norm)
 
3276
                        H5T_bit_set (d, dst.u.f.mpos+dst.u.f.msize-1, 1, TRUE);
 
3277
                    goto padding;
 
3278
                } else if (H5T_bit_find (s, src.u.f.epos, src.u.f.esize,
 
3279
                                         H5T_BIT_LSB, FALSE)<0) {
 
3280
                    /*
 
3281
                     * NaN. There are many NaN values, so we just set all bits of
 
3282
                     * the significand.
 
3283
                     */
 
3284
                    H5T_bit_copy (d, dst.u.f.sign, s, src.u.f.sign, 1);
 
3285
                    H5T_bit_set (d, dst.u.f.epos, dst.u.f.esize, TRUE);
 
3286
                    H5T_bit_set(d, dst.u.f.mpos, dst.u.f.msize, TRUE);
 
3287
                    goto padding;
 
3288
                }
 
3289
 
 
3290
                /*
 
3291
                 * Get the exponent as an unsigned quantity from the section of
 
3292
                 * the source bit field where it's located.  Don't worry about
 
3293
                 * the exponent bias yet.
 
3294
                 */
 
3295
                expo = H5T_bit_get_d(s, src.u.f.epos, src.u.f.esize);
 
3296
 
 
3297
                if(expo==0)
 
3298
                    denormalized=TRUE;
 
3299
 
 
3300
                /*
 
3301
                 * Set markers for the source mantissa, excluding the leading `1'
 
3302
                 * (might be implied).
 
3303
                 */
 
3304
                implied = 1;
 
3305
                mpos = src.u.f.mpos;
 
3306
                mrsh = 0;
 
3307
                if (0==expo || H5T_NORM_NONE==src.u.f.norm) {
 
3308
                    if ((bitno=H5T_bit_find(s, src.u.f.mpos, src.u.f.msize,
 
3309
                                            H5T_BIT_MSB, TRUE))>0) {
 
3310
                        msize = bitno;
 
3311
                    } else if (0==bitno) {
 
3312
                        msize = 1;
 
3313
                        H5T_bit_set(s, src.u.f.mpos, 1, FALSE);
 
3314
                    }
 
3315
                } else if (H5T_NORM_IMPLIED==src.u.f.norm) {
 
3316
                    msize = src.u.f.msize;
 
3317
                } else {
 
3318
                    assert("normalization method not implemented yet" && 0);
 
3319
                    HDabort();
 
3320
                }
 
3321
 
 
3322
                /*
 
3323
                 * The sign for the destination is the same as the sign for the
 
3324
                 * source in all cases.
 
3325
                 */
 
3326
                H5T_bit_copy (d, dst.u.f.sign, s, src.u.f.sign, 1);
 
3327
 
 
3328
                /*
 
3329
                 * Calculate the true source exponent by adjusting according to
 
3330
                 * the source exponent bias.
 
3331
                 */
 
3332
                if (0==expo || H5T_NORM_NONE==src.u.f.norm) {
 
3333
                    assert(bitno>=0);
 
3334
                    expo -= (src.u.f.ebias-1) + (src.u.f.msize-bitno);
 
3335
                } else if (H5T_NORM_IMPLIED==src.u.f.norm) {
 
3336
                    expo -= src.u.f.ebias;
 
3337
                } else {
 
3338
                    assert("normalization method not implemented yet" && 0);
 
3339
                    HDabort();
 
3340
                }
 
3341
 
 
3342
                /*
 
3343
                 * If the destination is not normalized then right shift the
 
3344
                 * mantissa by one.
 
3345
                 */
 
3346
                if (H5T_NORM_NONE==dst.u.f.norm)
 
3347
                    mrsh++;
 
3348
 
 
3349
                /*
 
3350
                 * Calculate the destination exponent by adding the destination
 
3351
                 * bias and clipping by the minimum and maximum possible
 
3352
                 * destination exponent values.
 
3353
                 */
 
3354
                expo += dst.u.f.ebias;
 
3355
                if (expo < -(hssize_t)(dst.u.f.msize)) {
 
3356
                    /* The exponent is way too small.  Result is zero. */
 
3357
                    expo = 0;
 
3358
                    H5T_bit_set(d, dst.u.f.mpos, dst.u.f.msize, FALSE);
 
3359
                    msize = 0;
 
3360
                } else if (expo<=0) {
 
3361
                    /*
 
3362
                     * The exponent is too small to fit in the exponent field,
 
3363
                     * but by shifting the mantissa to the right we can
 
3364
                     * accomodate that value.  The mantissa of course is no
 
3365
                     * longer normalized.
 
3366
                     */
 
3367
                    H5_ASSIGN_OVERFLOW(mrsh,(mrsh+1-expo),hssize_t,size_t);
 
3368
                    expo = 0;
 
3369
                    denormalized=TRUE;
 
3370
                } else if (expo>=expo_max) {
 
3371
                    /*
 
3372
                     * The exponent is too large to fit in the available region
 
3373
                     * or it results in the maximum possible value.   Use positive
 
3374
                     * or negative infinity instead unless the application
 
3375
                     * specifies something else.  Before calling the overflow
 
3376
                     * handler make sure the source buffer we hand it is in the
 
3377
                     * original byte order.
 
3378
                     */
 
3379
                    if (H5T_overflow_g) {
 
3380
                        uint8_t over_src[256];
 
3381
                        assert(src_p->shared->size<=sizeof over_src);
 
3382
                        if (H5T_ORDER_BE==src.order) {
 
3383
                            for (i=0; i<src_p->shared->size; i++) {
 
3384
                                over_src[src_p->shared->size-(i+1)] = s[i];
 
3385
                            }
 
3386
                        } else {
 
3387
                            for (i=0; i<src_p->shared->size; i++) {
 
3388
                                over_src[i] = s[i];
 
3389
                            }
 
3390
                        }
 
3391
                        if ((H5T_overflow_g)(src_id, dst_id, over_src, d)>=0) {
 
3392
                            goto next;
 
3393
                        }
 
3394
                    }
 
3395
                    expo = expo_max;
 
3396
                    H5T_bit_set(d, dst.u.f.mpos, dst.u.f.msize, FALSE);
 
3397
                    msize = 0;
 
3398
                }
 
3399
 
 
3400
                /*
 
3401
                 * If the destination mantissa is smaller than the source
 
3402
                 * mantissa then round the source mantissa.   Rounding may cause a
 
3403
                 * carry in which case the exponent has to be re-evaluated for
 
3404
                 * overflow.  That is, if `carry' is clear then the implied
 
3405
                 * mantissa bit is `1', else it is `10' binary.
 
3406
                 */
 
3407
                if (msize>0 && mrsh<=dst.u.f.msize && mrsh+msize>dst.u.f.msize) {
 
3408
                    bitno = (ssize_t)(mrsh+msize - dst.u.f.msize);
 
3409
                    assert(bitno>=0 && (size_t)bitno<=msize);
 
3410
                    /*If the 1st bit being cut off is set and source isn't denormalized.*/
 
3411
                    if(H5T_bit_get_d(s, mpos+bitno-1, 1) && !denormalized) {
 
3412
                        /*Don't do rounding if exponent is 111...110 and mantissa is 111...11.
 
3413
                         *To do rounding and increment exponent in this case will create an infinity value.*/
 
3414
                        if((H5T_bit_find(s, mpos+bitno, msize-bitno, H5T_BIT_LSB, FALSE)>=0 || expo<expo_max-1)) {
 
3415
                            carry = H5T_bit_inc(s, mpos+bitno-1, 1+msize-bitno);
 
3416
                            if (carry)
 
3417
                                implied = 2;
 
3418
                        }
 
3419
                    } else if(H5T_bit_get_d(s, mpos+bitno-1, 1) && denormalized)
 
3420
                        /*For either source or destination, denormalized value doesn't increment carry.*/
 
3421
                        H5T_bit_inc(s, mpos+bitno-1, 1+msize-bitno);
 
3422
                }
 
3423
                else
 
3424
                    carry=0;
 
3425
 
 
3426
                /*
 
3427
                 * Write the mantissa to the destination
 
3428
                 */
 
3429
                if (mrsh>dst.u.f.msize+1) {
 
3430
                    H5T_bit_set(d, dst.u.f.mpos, dst.u.f.msize, FALSE);
 
3431
                } else if (mrsh==dst.u.f.msize+1) {
 
3432
                    H5T_bit_set(d, dst.u.f.mpos+1, dst.u.f.msize-1, FALSE);
 
3433
                    H5T_bit_set(d, dst.u.f.mpos, 1, TRUE);
 
3434
                } else if (mrsh==dst.u.f.msize) {
 
3435
                    H5T_bit_set(d, dst.u.f.mpos, dst.u.f.msize, FALSE);
 
3436
                    H5T_bit_set_d(d, dst.u.f.mpos, MIN(2, dst.u.f.msize), (hsize_t)implied);
 
3437
                } else {
 
3438
                    if (mrsh>0) {
 
3439
                        H5T_bit_set(d, dst.u.f.mpos+dst.u.f.msize-mrsh, mrsh,
 
3440
                                    FALSE);
 
3441
                        H5T_bit_set_d(d, dst.u.f.mpos+dst.u.f.msize-mrsh, 2,
 
3442
                                      (hsize_t)implied);
 
3443
                    }
 
3444
                    if (mrsh+msize>=dst.u.f.msize) {
 
3445
                        H5T_bit_copy(d, dst.u.f.mpos,
 
3446
                                     s, (mpos+msize+mrsh-dst.u.f.msize),
 
3447
                                     dst.u.f.msize-mrsh);
 
3448
                    } else {
 
3449
                        H5T_bit_copy(d, dst.u.f.mpos+dst.u.f.msize-(mrsh+msize),
 
3450
                                     s, mpos, msize);
 
3451
                        H5T_bit_set(d, dst.u.f.mpos, dst.u.f.msize-(mrsh+msize),
 
3452
                                    FALSE);
 
3453
                    }
 
3454
                }
 
3455
 
 
3456
                /* Write the exponent */
 
3457
                if (carry) {
 
3458
                    expo++;
 
3459
                    if (expo>=expo_max) {
 
3460
                        /*
 
3461
                         * The exponent is too large to fit in the available
 
3462
                         * region or it results in the maximum possible value.
 
3463
                         * Use positive or negative infinity instead unless the
 
3464
                         * application specifies something else.  Before
 
3465
                         * calling the overflow handler make sure the source
 
3466
                         * buffer we hand it is in the original byte order.
 
3467
                         */
 
3468
                        if (H5T_overflow_g) {
 
3469
                            uint8_t over_src[256];
 
3470
                            assert(src_p->shared->size<=sizeof over_src);
 
3471
                            if (H5T_ORDER_BE==src.order) {
 
3472
                                for (i=0; i<src_p->shared->size; i++)
 
3473
                                    over_src[src_p->shared->size-(i+1)] = s[i];
 
3474
                            } else {
 
3475
                                for (i=0; i<src_p->shared->size; i++)
 
3476
                                    over_src[i] = s[i];
 
3477
                            }
 
3478
                            if ((H5T_overflow_g)(src_id, dst_id, over_src, d)>=0)
 
3479
                                goto next;
 
3480
                        }
 
3481
                        expo = expo_max;
 
3482
                        H5T_bit_set(d, dst.u.f.mpos, dst.u.f.msize, FALSE);
 
3483
                    }
 
3484
                }
 
3485
                /*reset CARRY*/
 
3486
                carry = 0;
 
3487
 
 
3488
                H5_CHECK_OVERFLOW(expo,hssize_t,hsize_t);
 
3489
                H5T_bit_set_d(d, dst.u.f.epos, dst.u.f.esize, (hsize_t)expo);
 
3490
 
 
3491
            padding:
 
3492
                /*
 
3493
                 * Set external padding areas
 
3494
                 */
 
3495
                if (dst.offset>0) {
 
3496
                    assert (H5T_PAD_ZERO==dst.lsb_pad || H5T_PAD_ONE==dst.lsb_pad);
 
3497
                    H5T_bit_set (d, 0, dst.offset, (hbool_t)(H5T_PAD_ONE==dst.lsb_pad));
 
3498
                }
 
3499
                if (dst.offset+dst.prec!=8*dst_p->shared->size) {
 
3500
                    assert (H5T_PAD_ZERO==dst.msb_pad || H5T_PAD_ONE==dst.msb_pad);
 
3501
                    H5T_bit_set (d, dst.offset+dst.prec, 8*dst_p->shared->size - (dst.offset+dst.prec),
 
3502
                         (hbool_t)(H5T_PAD_ONE==dst.msb_pad));
 
3503
                }
 
3504
 
 
3505
                /*
 
3506
                 * Put the destination in the correct byte order.  See note at
 
3507
                 * beginning of loop.
 
3508
                 */
 
3509
                if (H5T_ORDER_BE==dst.order) {
 
3510
                    half_size = dst_p->shared->size/2;
 
3511
                    for (i=0; i<half_size; i++) {
 
3512
                        uint8_t tmp = d[dst_p->shared->size-(i+1)];
 
3513
                        d[dst_p->shared->size-(i+1)] = d[i];
 
3514
                        d[i] = tmp;
 
3515
                    }
 
3516
                }
 
3517
 
 
3518
                /*
 
3519
                 * If we had used a temporary buffer for the destination then we
 
3520
                 * should copy the value to the true destination buffer.
 
3521
                 */
 
3522
            next:
 
3523
                if (d==dbuf)
 
3524
                    HDmemcpy (dp, d, dst_p->shared->size);
 
3525
                if (buf_stride) {
 
3526
                    sp += direction * buf_stride;
 
3527
                    dp += direction * buf_stride;
 
3528
                } else {
 
3529
                    sp += direction * src_p->shared->size;
 
3530
                    dp += direction * dst_p->shared->size;
 
3531
                }
 
3532
            }
 
3533
 
 
3534
            break;
 
3535
 
 
3536
        default:
 
3537
            HGOTO_ERROR (H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, "unknown conversion command");
 
3538
    }
 
3539
 
 
3540
done:
 
3541
    FUNC_LEAVE_NOAPI(ret_value);
 
3542
}
 
3543
 
 
3544
 
 
3545
/*-------------------------------------------------------------------------
 
3546
 * Function:  H5T_conv_s_s
 
3547
 *
 
3548
 * Purpose:  Convert one fixed-length string type to another.
 
3549
 *
 
3550
 * Return:  Non-negative on success/Negative on failure
 
3551
 *
 
3552
 * Programmer:  Robb Matzke
 
3553
 *    Friday, August  7, 1998
 
3554
 *
 
3555
 * Modifications:
 
3556
 *    Robb Matzke, 1999-06-16
 
3557
 *    Added support for non-zero strides. If BUF_STRIDE is non-zero
 
3558
 *    then convert one value at each memory location advancing
 
3559
 *    BUF_STRIDE bytes each time; otherwise assume both source and
 
3560
 *    destination values are packed.
 
3561
 *-------------------------------------------------------------------------
 
3562
 */
 
3563
herr_t
 
3564
H5T_conv_s_s (hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, size_t nelmts,
 
3565
        size_t buf_stride, size_t UNUSED bkg_stride, void *buf,
 
3566
              void UNUSED *bkg, hid_t UNUSED dxpl_id)
 
3567
{
 
3568
    H5T_t  *src=NULL;    /*source data type    */
 
3569
    H5T_t  *dst=NULL;    /*destination data type    */
 
3570
    int  direction;    /*direction of traversal  */
 
3571
    size_t  elmtno;      /*element number    */
 
3572
    size_t  olap;      /*num overlapping elements  */
 
3573
    size_t  nchars=0;    /*number of characters copied  */
 
3574
    uint8_t  *s, *sp, *d, *dp;  /*src and dst traversal pointers*/
 
3575
    uint8_t  *dbuf=NULL;    /*temp buf for overlap convers.  */
 
3576
    herr_t      ret_value=SUCCEED;       /* Return value */
 
3577
 
 
3578
    FUNC_ENTER_NOAPI(H5T_conv_s_s, FAIL);
 
3579
 
 
3580
    switch (cdata->command) {
 
3581
        case H5T_CONV_INIT:
 
3582
            if (NULL==(src=H5I_object(src_id)) ||
 
3583
                    NULL==(dst=H5I_object(dst_id)))
 
3584
                HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a data type");
 
3585
            if (8*src->shared->size != src->shared->u.atomic.prec || 8*dst->shared->size != dst->shared->u.atomic.prec)
 
3586
                HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "bad precision");
 
3587
            if (0 != src->shared->u.atomic.offset || 0 != dst->shared->u.atomic.offset)
 
3588
                HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "bad offset");
 
3589
            if (H5T_CSET_ASCII != src->shared->u.atomic.u.s.cset || H5T_CSET_ASCII != dst->shared->u.atomic.u.s.cset)
 
3590
                HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "bad character set");
 
3591
            if (src->shared->u.atomic.u.s.pad<0 || src->shared->u.atomic.u.s.pad>=H5T_NPAD ||
 
3592
                    dst->shared->u.atomic.u.s.pad<0 || dst->shared->u.atomic.u.s.pad>=H5T_NPAD)
 
3593
                HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "bad character padding");
 
3594
            cdata->need_bkg = H5T_BKG_NO;
 
3595
            break;
 
3596
 
 
3597
        case H5T_CONV_FREE:
 
3598
            break;
 
3599
 
 
3600
        case H5T_CONV_CONV:
 
3601
            /* Get the data types */
 
3602
            if (NULL==(src=H5I_object(src_id)) ||
 
3603
                    NULL==(dst=H5I_object(dst_id)))
 
3604
                HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a data type");
 
3605
 
 
3606
            /*
 
3607
             * Do we process the values from beginning to end or vice versa? Also,
 
3608
             * how many of the elements have the source and destination areas
 
3609
             * overlapping?
 
3610
             */
 
3611
            if (src->shared->size==dst->shared->size || buf_stride) {
 
3612
                /*
 
3613
                 * When the source and destination are the same size we can do
 
3614
                 * all the conversions in place.
 
3615
                 */
 
3616
                sp = dp = (uint8_t*)buf;
 
3617
                direction = 1;
 
3618
                olap = 0;
 
3619
            } else if (src->shared->size>=dst->shared->size) {
 
3620
                double olapd = HDceil((double)(dst->shared->size)/
 
3621
                          (double)(src->shared->size-dst->shared->size));
 
3622
                olap = (size_t)olapd;
 
3623
                sp = dp = (uint8_t*)buf;
 
3624
                direction = 1;
 
3625
            } else {
 
3626
                double olapd = HDceil((double)(src->shared->size)/
 
3627
                          (double)(dst->shared->size-src->shared->size));
 
3628
                olap = (size_t)olapd;
 
3629
                sp = (uint8_t*)buf + (nelmts-1) * src->shared->size;
 
3630
                dp = (uint8_t*)buf + (nelmts-1) * dst->shared->size;
 
3631
                direction = -1;
 
3632
            }
 
3633
 
 
3634
            /* Allocate the overlap buffer */
 
3635
            if (NULL==(dbuf=H5MM_malloc(dst->shared->size)))
 
3636
                HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed for string conversion");
 
3637
 
 
3638
            /* The conversion loop. */
 
3639
            for (elmtno=0; elmtno<nelmts; elmtno++) {
 
3640
 
 
3641
                /*
 
3642
                 * If the source and destination buffers overlap then use a
 
3643
                 * temporary buffer for the destination.
 
3644
                 */
 
3645
                if (direction>0) {
 
3646
                    s = sp;
 
3647
                    d = elmtno<olap ? dbuf : dp;
 
3648
                } else {
 
3649
                    s = sp;
 
3650
                    d = elmtno+olap >= nelmts ? dbuf : dp;
 
3651
                }
 
3652
#ifndef NDEBUG
 
3653
                /* I don't quite trust the overlap calculations yet --rpm */
 
3654
                if (src->shared->size==dst->shared->size || buf_stride) {
 
3655
                    assert(s==d);
 
3656
                } else if (d==dbuf) {
 
3657
                    assert((dp>=sp && dp<sp+src->shared->size) ||
 
3658
                       (sp>=dp && sp<dp+dst->shared->size));
 
3659
                } else {
 
3660
                    assert((dp<sp && dp+dst->shared->size<=sp) ||
 
3661
                       (sp<dp && sp+src->shared->size<=dp));
 
3662
                }
 
3663
#endif
 
3664
 
 
3665
                /* Copy characters from source to destination */
 
3666
                switch (src->shared->u.atomic.u.s.pad) {
 
3667
                    case H5T_STR_NULLTERM:
 
3668
                        for (nchars=0;
 
3669
                             nchars<dst->shared->size && nchars<src->shared->size && s[nchars];
 
3670
                             nchars++) {
 
3671
                            d[nchars] = s[nchars];
 
3672
                        }
 
3673
                        break;
 
3674
 
 
3675
                    case H5T_STR_NULLPAD:
 
3676
                        for (nchars=0;
 
3677
                             nchars<dst->shared->size && nchars<src->shared->size && s[nchars];
 
3678
                             nchars++) {
 
3679
                            d[nchars] = s[nchars];
 
3680
                        }
 
3681
                        break;
 
3682
 
 
3683
                    case H5T_STR_SPACEPAD:
 
3684
                        nchars = src->shared->size;
 
3685
                        while (nchars>0 && ' '==s[nchars-1])
 
3686
                            --nchars;
 
3687
                        nchars = MIN(dst->shared->size, nchars);
 
3688
                        HDmemcpy(d, s, nchars);
 
3689
                        break;
 
3690
 
 
3691
                    case H5T_STR_RESERVED_3:
 
3692
                    case H5T_STR_RESERVED_4:
 
3693
                    case H5T_STR_RESERVED_5:
 
3694
                    case H5T_STR_RESERVED_6:
 
3695
                    case H5T_STR_RESERVED_7:
 
3696
                    case H5T_STR_RESERVED_8:
 
3697
                    case H5T_STR_RESERVED_9:
 
3698
                    case H5T_STR_RESERVED_10:
 
3699
                    case H5T_STR_RESERVED_11:
 
3700
                    case H5T_STR_RESERVED_12:
 
3701
                    case H5T_STR_RESERVED_13:
 
3702
                    case H5T_STR_RESERVED_14:
 
3703
                    case H5T_STR_RESERVED_15:
 
3704
                    case H5T_STR_ERROR:
 
3705
                        HGOTO_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, "source string padding method not supported");
 
3706
                }
 
3707
 
 
3708
                /* Terminate or pad the destination */
 
3709
                switch (dst->shared->u.atomic.u.s.pad) {
 
3710
                    case H5T_STR_NULLTERM:
 
3711
                        while (nchars<dst->shared->size)
 
3712
                            d[nchars++] = '\0';
 
3713
                        d[dst->shared->size-1] = '\0';
 
3714
                        break;
 
3715
 
 
3716
                    case H5T_STR_NULLPAD:
 
3717
                        while (nchars<dst->shared->size)
 
3718
                            d[nchars++] = '\0';
 
3719
                        break;
 
3720
 
 
3721
                    case H5T_STR_SPACEPAD:
 
3722
                        while (nchars<dst->shared->size)
 
3723
                            d[nchars++] = ' ';
 
3724
                        break;
 
3725
 
 
3726
                    case H5T_STR_RESERVED_3:
 
3727
                    case H5T_STR_RESERVED_4:
 
3728
                    case H5T_STR_RESERVED_5:
 
3729
                    case H5T_STR_RESERVED_6:
 
3730
                    case H5T_STR_RESERVED_7:
 
3731
                    case H5T_STR_RESERVED_8:
 
3732
                    case H5T_STR_RESERVED_9:
 
3733
                    case H5T_STR_RESERVED_10:
 
3734
                    case H5T_STR_RESERVED_11:
 
3735
                    case H5T_STR_RESERVED_12:
 
3736
                    case H5T_STR_RESERVED_13:
 
3737
                    case H5T_STR_RESERVED_14:
 
3738
                    case H5T_STR_RESERVED_15:
 
3739
                    case H5T_STR_ERROR:
 
3740
                        HGOTO_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, "destination string padding method not supported");
 
3741
                }
 
3742
 
 
3743
                /*
 
3744
                 * If we used a temporary buffer for the destination then we
 
3745
                 * should copy the value to the true destination buffer.
 
3746
                 */
 
3747
                if (d==dbuf)
 
3748
                    HDmemcpy(dp, d, dst->shared->size);
 
3749
                if (buf_stride) {
 
3750
                    sp += direction * buf_stride;
 
3751
                    dp += direction * buf_stride;
 
3752
                } else {
 
3753
                    sp += direction * src->shared->size;
 
3754
                    dp += direction * dst->shared->size;
 
3755
                }
 
3756
            }
 
3757
            break;
 
3758
 
 
3759
        default:
 
3760
            HGOTO_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, "unknown converson command");
 
3761
    }
 
3762
 
 
3763
done:
 
3764
    H5MM_xfree(dbuf);
 
3765
    FUNC_LEAVE_NOAPI(ret_value);
 
3766
}
 
3767
 
 
3768
 
 
3769
/*-------------------------------------------------------------------------
 
3770
 * Function:  H5T_conv_schar_uchar
 
3771
 *
 
3772
 * Purpose:  Converts `signed char' to `unsigned char'
 
3773
 *
 
3774
 * Return:  Success:  non-negative
 
3775
 *
 
3776
 *    Failure:  negative
 
3777
 *
 
3778
 * Programmer:  Robb Matzke
 
3779
 *    Monday, November 16, 1998
 
3780
 *
 
3781
 * Modifications:
 
3782
 *
 
3783
 *-------------------------------------------------------------------------
 
3784
 */
 
3785
herr_t
 
3786
H5T_conv_schar_uchar(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
 
3787
         size_t nelmts, size_t buf_stride,
 
3788
                     size_t UNUSED bkg_stride, void *buf, void UNUSED *bkg,
 
3789
                     hid_t UNUSED dxpl_id)
 
3790
{
 
3791
    herr_t      ret_value=SUCCEED;       /* Return value */
 
3792
 
 
3793
    FUNC_ENTER_NOAPI(H5T_conv_schar_uchar, FAIL);
 
3794
 
 
3795
    H5T_CONV_su(SCHAR, UCHAR, signed char, unsigned char, -, -);
 
3796
 
 
3797
done:
 
3798
    FUNC_LEAVE_NOAPI(ret_value);
 
3799
}
 
3800
 
 
3801
 
 
3802
/*-------------------------------------------------------------------------
 
3803
 * Function:  H5T_conv_uchar_schar
 
3804
 *
 
3805
 * Purpose:  Converts `unsigned char' to `signed char'
 
3806
 *
 
3807
 * Return:  Success:  non-negative
 
3808
 *
 
3809
 *    Failure:  negative
 
3810
 *
 
3811
 * Programmer:  Robb Matzke
 
3812
 *    Monday, November 16, 1998
 
3813
 *
 
3814
 * Modifications:
 
3815
 *
 
3816
 *-------------------------------------------------------------------------
 
3817
 */
 
3818
herr_t
 
3819
H5T_conv_uchar_schar(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
 
3820
         size_t nelmts, size_t buf_stride,
 
3821
                     size_t UNUSED bkg_stride, void *buf, void UNUSED *bkg,
 
3822
                     hid_t UNUSED dxpl_id)
 
3823
{
 
3824
    herr_t      ret_value=SUCCEED;       /* Return value */
 
3825
 
 
3826
    FUNC_ENTER_NOAPI(H5T_conv_uchar_schar, FAIL);
 
3827
 
 
3828
    H5T_CONV_us(UCHAR, SCHAR, unsigned char, signed char, -, SCHAR_MAX);
 
3829
 
 
3830
done:
 
3831
    FUNC_LEAVE_NOAPI(ret_value);
 
3832
}
 
3833
 
 
3834
 
 
3835
/*-------------------------------------------------------------------------
 
3836
 * Function:  H5T_conv_schar_short
 
3837
 *
 
3838
 * Purpose:  Converts `signed char' to `short'
 
3839
 *
 
3840
 * Return:  Success:  Non-negative
 
3841
 *
 
3842
 *    Failure:  Negative
 
3843
 *
 
3844
 * Programmer:  Robb Matzke
 
3845
 *    Friday, November 13, 1998
 
3846
 *
 
3847
 * Modifications:
 
3848
 *
 
3849
 *-------------------------------------------------------------------------
 
3850
 */
 
3851
herr_t
 
3852
H5T_conv_schar_short(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
 
3853
         size_t nelmts, size_t buf_stride,
 
3854
                     size_t UNUSED bkg_stride, void *buf, void UNUSED *bkg,
 
3855
                     hid_t UNUSED dxpl_id)
 
3856
{
 
3857
    herr_t      ret_value=SUCCEED;       /* Return value */
 
3858
 
 
3859
    FUNC_ENTER_NOAPI(H5T_conv_schar_short, FAIL);
 
3860
 
 
3861
    H5T_CONV_sS(SCHAR, SHORT, signed char, short, -, -);
 
3862
 
 
3863
done:
 
3864
    FUNC_LEAVE_NOAPI(ret_value);
 
3865
}
 
3866
 
 
3867
 
 
3868
/*-------------------------------------------------------------------------
 
3869
 * Function:  H5T_conv_schar_ushort
 
3870
 *
 
3871
 * Purpose:  Converts `signed char' to `unsigned short'
 
3872
 *
 
3873
 * Return:  Success:  Non-negative
 
3874
 *
 
3875
 *    Failure:  Negative
 
3876
 *
 
3877
 * Programmer:  Robb Matzke
 
3878
 *    Friday, November 13, 1998
 
3879
 *
 
3880
 * Modifications:
 
3881
 *
 
3882
 *-------------------------------------------------------------------------
 
3883
 */
 
3884
herr_t
 
3885
H5T_conv_schar_ushort(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
 
3886
          size_t nelmts, size_t buf_stride,
 
3887
                      size_t UNUSED bkg_stride, void *buf, void UNUSED *bkg,
 
3888
                      hid_t UNUSED dxpl_id)
 
3889
{
 
3890
    herr_t      ret_value=SUCCEED;       /* Return value */
 
3891
 
 
3892
    FUNC_ENTER_NOAPI(H5T_conv_schar_ushort, FAIL);
 
3893
 
 
3894
    H5T_CONV_sU(SCHAR, USHORT, signed char, unsigned short, -, -);
 
3895
 
 
3896
done:
 
3897
    FUNC_LEAVE_NOAPI(ret_value);
 
3898
}
 
3899
 
 
3900
 
 
3901
/*-------------------------------------------------------------------------
 
3902
 * Function:  H5T_conv_uchar_short
 
3903
 *
 
3904
 * Purpose:  Converts `unsigned char' to `short'
 
3905
 *
 
3906
 * Return:  Success:  non-negative
 
3907
 *
 
3908
 *    Failure:  negative
 
3909
 *
 
3910
 * Programmer:  Robb Matzke
 
3911
 *    Friday, November 13, 1998
 
3912
 *
 
3913
 * Modifications:
 
3914
 *
 
3915
 *-------------------------------------------------------------------------
 
3916
 */
 
3917
herr_t
 
3918
H5T_conv_uchar_short(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
 
3919
         size_t nelmts, size_t buf_stride,
 
3920
                     size_t UNUSED bkg_stride, void *buf, void UNUSED *bkg,
 
3921
                     hid_t UNUSED dxpl_id)
 
3922
{
 
3923
    herr_t      ret_value=SUCCEED;       /* Return value */
 
3924
 
 
3925
    FUNC_ENTER_NOAPI(H5T_conv_uchar_short, FAIL);
 
3926
 
 
3927
    H5T_CONV_uS(UCHAR, SHORT, unsigned char, short, -, SHRT_MAX);
 
3928
 
 
3929
done:
 
3930
    FUNC_LEAVE_NOAPI(ret_value);
 
3931
}
 
3932
 
 
3933
 
 
3934
/*-------------------------------------------------------------------------
 
3935
 * Function:  H5T_conv_uchar_ushort
 
3936
 *
 
3937
 * Purpose:  Converts `unsigned char' to `unsigned short'
 
3938
 *
 
3939
 * Return:  Success:  non-negative
 
3940
 *
 
3941
 *    Failure:  negative
 
3942
 *
 
3943
 * Programmer:  Robb Matzke
 
3944
 *    Friday, November 13, 1998
 
3945
 *
 
3946
 * Modifications:
 
3947
 *
 
3948
 *-------------------------------------------------------------------------
 
3949
 */
 
3950
herr_t
 
3951
H5T_conv_uchar_ushort(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
 
3952
          size_t nelmts, size_t buf_stride,
 
3953
                      size_t UNUSED bkg_stride, void *buf, void UNUSED *bkg,
 
3954
                      hid_t UNUSED dxpl_id)
 
3955
{
 
3956
    herr_t      ret_value=SUCCEED;       /* Return value */
 
3957
 
 
3958
    FUNC_ENTER_NOAPI(H5T_conv_uchar_ushort, FAIL);
 
3959
 
 
3960
    H5T_CONV_uU(UCHAR, USHORT, unsigned char, unsigned short, -, -);
 
3961
 
 
3962
done:
 
3963
    FUNC_LEAVE_NOAPI(ret_value);
 
3964
}
 
3965
 
 
3966
 
 
3967
/*-------------------------------------------------------------------------
 
3968
 * Function:  H5T_conv_schar_int
 
3969
 *
 
3970
 * Purpose:  Converts `signed char' to `int'
 
3971
 *
 
3972
 * Return:  Success:  Non-negative
 
3973
 *
 
3974
 *    Failure:  Negative
 
3975
 *
 
3976
 * Programmer:  Robb Matzke
 
3977
 *    Friday, November 13, 1998
 
3978
 *
 
3979
 * Modifications:
 
3980
 *
 
3981
 *-------------------------------------------------------------------------
 
3982
 */
 
3983
herr_t
 
3984
H5T_conv_schar_int(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
 
3985
       size_t nelmts, size_t buf_stride, size_t UNUSED bkg_stride,
 
3986
                   void *buf, void UNUSED *bkg, hid_t UNUSED dxpl_id)
 
3987
{
 
3988
    herr_t      ret_value=SUCCEED;       /* Return value */
 
3989
 
 
3990
    FUNC_ENTER_NOAPI(H5T_conv_schar_int, FAIL);
 
3991
 
 
3992
    H5T_CONV_sS(SCHAR, INT, signed char, int, -, -);
 
3993
 
 
3994
done:
 
3995
    FUNC_LEAVE_NOAPI(ret_value);
 
3996
}
 
3997
 
 
3998
 
 
3999
/*-------------------------------------------------------------------------
 
4000
 * Function:  H5T_conv_schar_uint
 
4001
 *
 
4002
 * Purpose:  Converts `signed char' to `unsigned int'
 
4003
 *
 
4004
 * Return:  Success:  Non-negative
 
4005
 *
 
4006
 *    Failure:  Negative
 
4007
 *
 
4008
 * Programmer:  Robb Matzke
 
4009
 *    Friday, November 13, 1998
 
4010
 *
 
4011
 * Modifications:
 
4012
 *
 
4013
 *-------------------------------------------------------------------------
 
4014
 */
 
4015
herr_t
 
4016
H5T_conv_schar_uint(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
 
4017
        size_t nelmts, size_t buf_stride, size_t UNUSED bkg_stride,
 
4018
                    void *buf, void UNUSED *bkg, hid_t UNUSED dxpl_id)
 
4019
{
 
4020
    herr_t      ret_value=SUCCEED;       /* Return value */
 
4021
 
 
4022
    FUNC_ENTER_NOAPI(H5T_conv_schar_uint, FAIL);
 
4023
 
 
4024
    H5T_CONV_sU(SCHAR, UINT, signed char, unsigned, -, -);
 
4025
 
 
4026
done:
 
4027
    FUNC_LEAVE_NOAPI(ret_value);
 
4028
}
 
4029
 
 
4030
 
 
4031
/*-------------------------------------------------------------------------
 
4032
 * Function:  H5T_conv_uchar_int
 
4033
 *
 
4034
 * Purpose:  Converts `unsigned char' to `int'
 
4035
 *
 
4036
 * Return:  Success:  Non-negative
 
4037
 *
 
4038
 *    Failure:  Negative
 
4039
 *
 
4040
 * Programmer:  Robb Matzke
 
4041
 *    Friday, November 13, 1998
 
4042
 *
 
4043
 * Modifications:
 
4044
 *
 
4045
 *-------------------------------------------------------------------------
 
4046
 */
 
4047
herr_t
 
4048
H5T_conv_uchar_int(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
 
4049
       size_t nelmts, size_t buf_stride, size_t UNUSED bkg_stride,
 
4050
                   void *buf, void UNUSED *bkg, hid_t UNUSED dxpl_id)
 
4051
{
 
4052
    herr_t      ret_value=SUCCEED;       /* Return value */
 
4053
 
 
4054
    FUNC_ENTER_NOAPI(H5T_conv_uchar_int, FAIL);
 
4055
 
 
4056
    H5T_CONV_uS(UCHAR, INT, unsigned char, int, -, INT_MAX);
 
4057
 
 
4058
done:
 
4059
    FUNC_LEAVE_NOAPI(ret_value);
 
4060
}
 
4061
 
 
4062
 
 
4063
/*-------------------------------------------------------------------------
 
4064
 * Function:  H5T_conv_uchar_uint
 
4065
 *
 
4066
 * Purpose:  Converts `unsigned char' to `unsigned int'
 
4067
 *
 
4068
 * Return:  Success:  Non-negative
 
4069
 *
 
4070
 *    Failure:  Negative
 
4071
 *
 
4072
 * Programmer:  Robb Matzke
 
4073
 *    Friday, November 13, 1998
 
4074
 *
 
4075
 * Modifications:
 
4076
 *
 
4077
 *-------------------------------------------------------------------------
 
4078
 */
 
4079
herr_t
 
4080
H5T_conv_uchar_uint(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
 
4081
        size_t nelmts, size_t buf_stride, size_t UNUSED bkg_stride,
 
4082
                    void *buf, void UNUSED *bkg, hid_t UNUSED dxpl_id)
 
4083
{
 
4084
    herr_t      ret_value=SUCCEED;       /* Return value */
 
4085
 
 
4086
    FUNC_ENTER_NOAPI(H5T_conv_uchar_uint, FAIL);
 
4087
 
 
4088
    H5T_CONV_uU(UCHAR, UINT, unsigned char, unsigned, -, -);
 
4089
 
 
4090
done:
 
4091
    FUNC_LEAVE_NOAPI(ret_value);
 
4092
}
 
4093
 
 
4094
 
 
4095
/*-------------------------------------------------------------------------
 
4096
 * Function:  H5T_conv_schar_long
 
4097
 *
 
4098
 * Purpose:  Converts `signed char' to `long'
 
4099
 *
 
4100
 * Return:  Success:  Non-negative
 
4101
 *
 
4102
 *    Failure:  Negative
 
4103
 *
 
4104
 * Programmer:  Robb Matzke
 
4105
 *    Friday, November 13, 1998
 
4106
 *
 
4107
 * Modifications:
 
4108
 *
 
4109
 *-------------------------------------------------------------------------
 
4110
 */
 
4111
herr_t
 
4112
H5T_conv_schar_long(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
 
4113
        size_t nelmts, size_t buf_stride, size_t UNUSED bkg_stride,
 
4114
                    void *buf, void UNUSED *bkg, hid_t UNUSED dxpl_id)
 
4115
{
 
4116
    herr_t      ret_value=SUCCEED;       /* Return value */
 
4117
 
 
4118
    FUNC_ENTER_NOAPI(H5T_conv_schar_long, FAIL);
 
4119
 
 
4120
    H5T_CONV_sS(SCHAR, LONG, signed char, long, -, -);
 
4121
 
 
4122
done:
 
4123
    FUNC_LEAVE_NOAPI(ret_value);
 
4124
}
 
4125
 
 
4126
 
 
4127
/*-------------------------------------------------------------------------
 
4128
 * Function:  H5T_conv_schar_ulong
 
4129
 *
 
4130
 * Purpose:  Converts `signed char' to `unsigned long'
 
4131
 *
 
4132
 * Return:  Success:  Non-negative
 
4133
 *
 
4134
 *    Failure:  Negative
 
4135
 *
 
4136
 * Programmer:  Robb Matzke
 
4137
 *    Friday, November 13, 1998
 
4138
 *
 
4139
 * Modifications:
 
4140
 *
 
4141
 *-------------------------------------------------------------------------
 
4142
 */
 
4143
herr_t
 
4144
H5T_conv_schar_ulong(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
 
4145
         size_t nelmts, size_t buf_stride,
 
4146
                     size_t UNUSED bkg_stride, void *buf, void UNUSED *bkg,
 
4147
         hid_t UNUSED dxpl_id)
 
4148
{
 
4149
    herr_t      ret_value=SUCCEED;       /* Return value */
 
4150
 
 
4151
    FUNC_ENTER_NOAPI(H5T_conv_schar_ulong, FAIL);
 
4152
 
 
4153
    H5T_CONV_sU(SCHAR, ULONG, signed char, unsigned long, -, -);
 
4154
 
 
4155
done:
 
4156
    FUNC_LEAVE_NOAPI(ret_value);
 
4157
}
 
4158
 
 
4159
 
 
4160
/*-------------------------------------------------------------------------
 
4161
 * Function:  H5T_conv_uchar_long
 
4162
 *
 
4163
 * Purpose:  Converts `unsigned char' to `long'
 
4164
 *
 
4165
 * Return:  Success:  Non-negative
 
4166
 *
 
4167
 *    Failure:  Negative
 
4168
 *
 
4169
 * Programmer:  Robb Matzke
 
4170
 *    Friday, November 13, 1998
 
4171
 *
 
4172
 * Modifications:
 
4173
 *
 
4174
 *-------------------------------------------------------------------------
 
4175
 */
 
4176
herr_t
 
4177
H5T_conv_uchar_long(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
 
4178
        size_t nelmts, size_t buf_stride, size_t UNUSED bkg_stride,
 
4179
                    void *buf, void UNUSED *bkg, hid_t UNUSED dxpl_id)
 
4180
{
 
4181
    herr_t      ret_value=SUCCEED;       /* Return value */
 
4182
 
 
4183
    FUNC_ENTER_NOAPI(H5T_conv_uchar_long, FAIL);
 
4184
 
 
4185
    H5T_CONV_uS(UCHAR, LONG, unsigned char, long, -, LONG_MAX);
 
4186
 
 
4187
done:
 
4188
    FUNC_LEAVE_NOAPI(ret_value);
 
4189
}
 
4190
 
 
4191
 
 
4192
/*-------------------------------------------------------------------------
 
4193
 * Function:  H5T_conv_uchar_ulong
 
4194
 *
 
4195
 * Purpose:  Converts `unsigned char' to `unsigned long'
 
4196
 *
 
4197
 * Return:  Success:  Non-negative
 
4198
 *
 
4199
 *    Failure:  Negative
 
4200
 *
 
4201
 * Programmer:  Robb Matzke
 
4202
 *    Friday, November 13, 1998
 
4203
 *
 
4204
 * Modifications:
 
4205
 *
 
4206
 *-------------------------------------------------------------------------
 
4207
 */
 
4208
herr_t
 
4209
H5T_conv_uchar_ulong(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
 
4210
         size_t nelmts, size_t buf_stride,
 
4211
                     size_t UNUSED bkg_stride, void *buf, void UNUSED *bkg,
 
4212
         hid_t UNUSED dxpl_id)
 
4213
{
 
4214
    herr_t      ret_value=SUCCEED;       /* Return value */
 
4215
 
 
4216
    FUNC_ENTER_NOAPI(H5T_conv_uchar_ulong, FAIL);
 
4217
 
 
4218
    H5T_CONV_uU(UCHAR, ULONG, unsigned char, unsigned long, -, -);
 
4219
 
 
4220
done:
 
4221
    FUNC_LEAVE_NOAPI(ret_value);
 
4222
}
 
4223
 
 
4224
 
 
4225
/*-------------------------------------------------------------------------
 
4226
 * Function:  H5T_conv_schar_llong
 
4227
 *
 
4228
 * Purpose:  Converts `signed char' to `long_long'
 
4229
 *
 
4230
 * Return:  Success:  Non-negative
 
4231
 *
 
4232
 *    Failure:  Negative
 
4233
 *
 
4234
 * Programmer:  Robb Matzke
 
4235
 *    Friday, November 13, 1998
 
4236
 *
 
4237
 * Modifications:
 
4238
 *
 
4239
 *-------------------------------------------------------------------------
 
4240
 */
 
4241
herr_t
 
4242
H5T_conv_schar_llong(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
 
4243
         size_t nelmts, size_t buf_stride,
 
4244
                     size_t UNUSED bkg_stride, void *buf, void UNUSED *bkg,
 
4245
         hid_t UNUSED dxpl_id)
 
4246
{
 
4247
    herr_t      ret_value=SUCCEED;       /* Return value */
 
4248
 
 
4249
    FUNC_ENTER_NOAPI(H5T_conv_schar_llong, FAIL);
 
4250
 
 
4251
    H5T_CONV_sS(SCHAR, LLONG, signed char, long_long, -, -);
 
4252
 
 
4253
done:
 
4254
    FUNC_LEAVE_NOAPI(ret_value);
 
4255
}
 
4256
 
 
4257
 
 
4258
/*-------------------------------------------------------------------------
 
4259
 * Function:  H5T_conv_schar_ullong
 
4260
 *
 
4261
 * Purpose:  Converts `signed char' to `unsigned long_long'
 
4262
 *
 
4263
 * Return:  Success:  Non-negative
 
4264
 *
 
4265
 *    Failure:  Negative
 
4266
 *
 
4267
 * Programmer:  Robb Matzke
 
4268
 *    Friday, November 13, 1998
 
4269
 *
 
4270
 * Modifications:
 
4271
 *
 
4272
 *-------------------------------------------------------------------------
 
4273
 */
 
4274
herr_t
 
4275
H5T_conv_schar_ullong(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
 
4276
          size_t nelmts, size_t buf_stride,
 
4277
                      size_t UNUSED bkg_stride, void *buf, void UNUSED *bkg,
 
4278
                      hid_t UNUSED dxpl_id)
 
4279
{
 
4280
    herr_t      ret_value=SUCCEED;       /* Return value */
 
4281
 
 
4282
    FUNC_ENTER_NOAPI(H5T_conv_schar_ullong, FAIL);
 
4283
 
 
4284
    H5T_CONV_sU(SCHAR, ULLONG, signed char, unsigned long_long, -, -);
 
4285
 
 
4286
done:
 
4287
    FUNC_LEAVE_NOAPI(ret_value);
 
4288
}
 
4289
 
 
4290
 
 
4291
/*-------------------------------------------------------------------------
 
4292
 * Function:  H5T_conv_uchar_llong
 
4293
 *
 
4294
 * Purpose:  Converts `unsigned char' to `long_long'
 
4295
 *
 
4296
 * Return:  Success:  Non-negative
 
4297
 *
 
4298
 *    Failure:  Negative
 
4299
 *
 
4300
 * Programmer:  Robb Matzke
 
4301
 *    Friday, November 13, 1998
 
4302
 *
 
4303
 * Modifications:
 
4304
 *
 
4305
 *-------------------------------------------------------------------------
 
4306
 */
 
4307
herr_t
 
4308
H5T_conv_uchar_llong(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
 
4309
         size_t nelmts, size_t buf_stride,
 
4310
                     size_t UNUSED bkg_stride, void *buf, void UNUSED *bkg,
 
4311
         hid_t UNUSED dxpl_id)
 
4312
{
 
4313
    herr_t      ret_value=SUCCEED;       /* Return value */
 
4314
 
 
4315
    FUNC_ENTER_NOAPI(H5T_conv_uchar_llong, FAIL);
 
4316
 
 
4317
    H5T_CONV_uS(UCHAR, LLONG, unsigned char, long_long, -, LLONG_MAX);
 
4318
 
 
4319
done:
 
4320
    FUNC_LEAVE_NOAPI(ret_value);
 
4321
}
 
4322
 
 
4323
 
 
4324
/*-------------------------------------------------------------------------
 
4325
 * Function:  H5T_conv_uchar_ullong
 
4326
 *
 
4327
 * Purpose:  Converts `unsigned char' to `unsigned long_long'
 
4328
 *
 
4329
 * Return:  Success:  Non-negative
 
4330
 *
 
4331
 *    Failure:  Negative
 
4332
 *
 
4333
 * Programmer:  Robb Matzke
 
4334
 *    Friday, November 13, 1998
 
4335
 *
 
4336
 * Modifications:
 
4337
 *
 
4338
 *-------------------------------------------------------------------------
 
4339
 */
 
4340
herr_t
 
4341
H5T_conv_uchar_ullong(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
 
4342
          size_t nelmts, size_t buf_stride,
 
4343
                      size_t UNUSED bkg_stride, void *buf, void UNUSED *bkg,
 
4344
                      hid_t UNUSED dxpl_id)
 
4345
{
 
4346
    herr_t      ret_value=SUCCEED;       /* Return value */
 
4347
 
 
4348
    FUNC_ENTER_NOAPI(H5T_conv_uchar_ullong, FAIL);
 
4349
 
 
4350
    H5T_CONV_uU(UCHAR, ULLONG, unsigned char, unsigned long_long, -, -);
 
4351
 
 
4352
done:
 
4353
    FUNC_LEAVE_NOAPI(ret_value);
 
4354
}
 
4355
 
 
4356
 
 
4357
/*-------------------------------------------------------------------------
 
4358
 * Function:  H5T_conv_short_schar
 
4359
 *
 
4360
 * Purpose:  Converts `short' to `signed char'
 
4361
 *
 
4362
 * Return:  Success:  non-negative
 
4363
 *
 
4364
 *    Failure:  negative
 
4365
 *
 
4366
 * Programmer:  Robb Matzke
 
4367
 *    Friday, November 13, 1998
 
4368
 *
 
4369
 * Modifications:
 
4370
 *
 
4371
 *-------------------------------------------------------------------------
 
4372
 */
 
4373
herr_t
 
4374
H5T_conv_short_schar(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
 
4375
         size_t nelmts, size_t buf_stride,
 
4376
                     size_t UNUSED bkg_stride, void *buf, void UNUSED *bkg,
 
4377
         hid_t UNUSED dxpl_id)
 
4378
{
 
4379
    herr_t      ret_value=SUCCEED;       /* Return value */
 
4380
 
 
4381
    FUNC_ENTER_NOAPI(H5T_conv_short_schar, FAIL);
 
4382
 
 
4383
    H5T_CONV_Ss(SHORT, SCHAR, short, signed char, SCHAR_MIN, SCHAR_MAX);
 
4384
 
 
4385
done:
 
4386
    FUNC_LEAVE_NOAPI(ret_value);
 
4387
}
 
4388
 
 
4389
 
 
4390
/*-------------------------------------------------------------------------
 
4391
 * Function:  H5T_conv_short_uchar
 
4392
 *
 
4393
 * Purpose:  Converts `short' to `unsigned char'
 
4394
 *
 
4395
 * Return:  Success:  non-negative
 
4396
 *
 
4397
 *    Failure:  negative
 
4398
 *
 
4399
 * Programmer:  Robb Matzke
 
4400
 *    Friday, November 13, 1998
 
4401
 *
 
4402
 * Modifications:
 
4403
 *
 
4404
 *-------------------------------------------------------------------------
 
4405
 */
 
4406
herr_t
 
4407
H5T_conv_short_uchar(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
 
4408
         size_t nelmts, size_t buf_stride,
 
4409
                     size_t UNUSED bkg_stride, void *buf, void UNUSED *bkg,
 
4410
         hid_t UNUSED dxpl_id)
 
4411
{
 
4412
    herr_t      ret_value=SUCCEED;       /* Return value */
 
4413
 
 
4414
    FUNC_ENTER_NOAPI(H5T_conv_short_uchar, FAIL);
 
4415
 
 
4416
    H5T_CONV_Su(SHORT, UCHAR, short, unsigned char, -, UCHAR_MAX);
 
4417
 
 
4418
done:
 
4419
    FUNC_LEAVE_NOAPI(ret_value);
 
4420
}
 
4421
 
 
4422
 
 
4423
/*-------------------------------------------------------------------------
 
4424
 * Function:  H5T_conv_ushort_schar
 
4425
 *
 
4426
 * Purpose:  Converts `unsigned short' to `signed char'
 
4427
 *
 
4428
 * Return:  Success:  non-negative
 
4429
 *
 
4430
 *    Failure:  negative
 
4431
 *
 
4432
 * Programmer:  Robb Matzke
 
4433
 *    Friday, November 13, 1998
 
4434
 *
 
4435
 * Modifications:
 
4436
 *
 
4437
 *-------------------------------------------------------------------------
 
4438
 */
 
4439
herr_t
 
4440
H5T_conv_ushort_schar(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
 
4441
          size_t nelmts, size_t buf_stride,
 
4442
                      size_t UNUSED bkg_stride, void *buf, void UNUSED *bkg,
 
4443
                      hid_t UNUSED dxpl_id)
 
4444
{
 
4445
    herr_t      ret_value=SUCCEED;       /* Return value */
 
4446
 
 
4447
    FUNC_ENTER_NOAPI(H5T_conv_ushort_schar, FAIL);
 
4448
 
 
4449
    H5T_CONV_Us(USHORT, SCHAR, unsigned short, signed char, -, SCHAR_MAX);
 
4450
 
 
4451
done:
 
4452
    FUNC_LEAVE_NOAPI(ret_value);
 
4453
}
 
4454
 
 
4455
 
 
4456
/*-------------------------------------------------------------------------
 
4457
 * Function:  H5T_conv_ushort_uchar
 
4458
 *
 
4459
 * Purpose:  Converts `unsigned short' to `unsigned char'
 
4460
 *
 
4461
 * Return:  Success:  non-negative
 
4462
 *
 
4463
 *    Failure:  negative
 
4464
 *
 
4465
 * Programmer:  Robb Matzke
 
4466
 *    Friday, November 13, 1998
 
4467
 *
 
4468
 * Modifications:
 
4469
 *
 
4470
 *-------------------------------------------------------------------------
 
4471
 */
 
4472
herr_t
 
4473
H5T_conv_ushort_uchar(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
 
4474
          size_t nelmts, size_t buf_stride,
 
4475
                      size_t UNUSED bkg_stride, void *buf, void UNUSED *bkg,
 
4476
                      hid_t UNUSED dxpl_id)
 
4477
{
 
4478
    herr_t      ret_value=SUCCEED;       /* Return value */
 
4479
 
 
4480
    FUNC_ENTER_NOAPI(H5T_conv_ushort_uchar, FAIL);
 
4481
 
 
4482
    H5T_CONV_Uu(USHORT, UCHAR, unsigned short, unsigned char, -, UCHAR_MAX);
 
4483
 
 
4484
done:
 
4485
    FUNC_LEAVE_NOAPI(ret_value);
 
4486
}
 
4487
 
 
4488
 
 
4489
/*-------------------------------------------------------------------------
 
4490
 * Function:  H5T_conv_short_ushort
 
4491
 *
 
4492
 * Purpose:  Converts `short' to `unsigned short'
 
4493
 *
 
4494
 * Return:  Success:  non-negative
 
4495
 *
 
4496
 *    Failure:  negative
 
4497
 *
 
4498
 * Programmer:  Robb Matzke
 
4499
 *    Monday, November 16, 1998
 
4500
 *
 
4501
 * Modifications:
 
4502
 *
 
4503
 *-------------------------------------------------------------------------
 
4504
 */
 
4505
herr_t
 
4506
H5T_conv_short_ushort(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
 
4507
          size_t nelmts, size_t buf_stride,
 
4508
                      size_t UNUSED bkg_stride, void *buf, void UNUSED *bkg,
 
4509
                      hid_t UNUSED dxpl_id)
 
4510
{
 
4511
    herr_t      ret_value=SUCCEED;       /* Return value */
 
4512
 
 
4513
    FUNC_ENTER_NOAPI(H5T_conv_short_ushort, FAIL);
 
4514
 
 
4515
    H5T_CONV_su(SHORT, USHORT, short, unsigned short, -, -);
 
4516
 
 
4517
done:
 
4518
    FUNC_LEAVE_NOAPI(ret_value);
 
4519
}
 
4520
 
 
4521
 
 
4522
/*-------------------------------------------------------------------------
 
4523
 * Function:  H5T_conv_ushort_short
 
4524
 *
 
4525
 * Purpose:  Converts `unsigned short' to `short'
 
4526
 *
 
4527
 * Return:  Success:  non-negative
 
4528
 *
 
4529
 *    Failure:  negative
 
4530
 *
 
4531
 * Programmer:  Robb Matzke
 
4532
 *    Monday, November 16, 1998
 
4533
 *
 
4534
 * Modifications:
 
4535
 *
 
4536
 *-------------------------------------------------------------------------
 
4537
 */
 
4538
herr_t
 
4539
H5T_conv_ushort_short(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
 
4540
          size_t nelmts, size_t buf_stride,
 
4541
                      size_t UNUSED bkg_stride, void *buf, void UNUSED *bkg,
 
4542
                      hid_t UNUSED dxpl_id)
 
4543
{
 
4544
    herr_t      ret_value=SUCCEED;       /* Return value */
 
4545
 
 
4546
    FUNC_ENTER_NOAPI(H5T_conv_ushort_short, FAIL);
 
4547
 
 
4548
    H5T_CONV_us(USHORT, SHORT, unsigned short, short, -, SHRT_MAX);
 
4549
 
 
4550
done:
 
4551
    FUNC_LEAVE_NOAPI(ret_value);
 
4552
}
 
4553
 
 
4554
 
 
4555
/*-------------------------------------------------------------------------
 
4556
 * Function:  H5T_conv_short_int
 
4557
 *
 
4558
 * Purpose:  Converts `short' to `int'
 
4559
 *
 
4560
 * Return:  Success:  non-negative
 
4561
 *
 
4562
 *    Failure:  negative
 
4563
 *
 
4564
 * Programmer:  Robb Matzke
 
4565
 *    Friday, November 13, 1998
 
4566
 *
 
4567
 * Modifications:
 
4568
 *
 
4569
 *-------------------------------------------------------------------------
 
4570
 */
 
4571
herr_t
 
4572
H5T_conv_short_int(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
 
4573
       size_t nelmts, size_t buf_stride,
 
4574
                   size_t UNUSED bkg_stride, void *buf, void UNUSED *bkg,
 
4575
       hid_t UNUSED dxpl_id)
 
4576
{
 
4577
    herr_t      ret_value=SUCCEED;       /* Return value */
 
4578
 
 
4579
    FUNC_ENTER_NOAPI(H5T_conv_short_int, FAIL);
 
4580
 
 
4581
    H5T_CONV_sS(SHORT, INT, short, int, -, -);
 
4582
 
 
4583
done:
 
4584
    FUNC_LEAVE_NOAPI(ret_value);
 
4585
}
 
4586
 
 
4587
 
 
4588
/*-------------------------------------------------------------------------
 
4589
 * Function:  H5T_conv_short_uint
 
4590
 *
 
4591
 * Purpose:  Converts `short' to `unsigned int'
 
4592
 *
 
4593
 * Return:  Success:  Non-negative
 
4594
 *
 
4595
 *    Failure:  Negative
 
4596
 *
 
4597
 * Programmer:  Robb Matzke
 
4598
 *    Friday, November 13, 1998
 
4599
 *
 
4600
 * Modifications:
 
4601
 *
 
4602
 *-------------------------------------------------------------------------
 
4603
 */
 
4604
herr_t
 
4605
H5T_conv_short_uint(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
 
4606
        size_t nelmts, size_t buf_stride,
 
4607
                    size_t UNUSED bkg_stride, void *buf, void UNUSED *bkg,
 
4608
        hid_t UNUSED dxpl_id)
 
4609
{
 
4610
    herr_t      ret_value=SUCCEED;       /* Return value */
 
4611
 
 
4612
    FUNC_ENTER_NOAPI(H5T_conv_short_uint, FAIL);
 
4613
 
 
4614
    H5T_CONV_sU(SHORT, UINT, short, unsigned, -, -);
 
4615
 
 
4616
done:
 
4617
    FUNC_LEAVE_NOAPI(ret_value);
 
4618
}
 
4619
 
 
4620
 
 
4621
/*-------------------------------------------------------------------------
 
4622
 * Function:  H5T_conv_ushort_int
 
4623
 *
 
4624
 * Purpose:  Converts `unsigned short' to `int'
 
4625
 *
 
4626
 * Return:  Success:  Non-negative
 
4627
 *
 
4628
 *    Failure:  Negative
 
4629
 *
 
4630
 * Programmer:  Robb Matzke
 
4631
 *    Friday, November 13, 1998
 
4632
 *
 
4633
 * Modifications:
 
4634
 *
 
4635
 *-------------------------------------------------------------------------
 
4636
 */
 
4637
herr_t
 
4638
H5T_conv_ushort_int(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
 
4639
        size_t nelmts, size_t buf_stride,
 
4640
                    size_t UNUSED bkg_stride, void *buf, void UNUSED *bkg,
 
4641
        hid_t UNUSED dxpl_id)
 
4642
{
 
4643
    herr_t      ret_value=SUCCEED;       /* Return value */
 
4644
 
 
4645
    FUNC_ENTER_NOAPI(H5T_conv_ushort_int, FAIL);
 
4646
 
 
4647
    H5T_CONV_uS(USHORT, INT, unsigned short, int, -, INT_MAX);
 
4648
 
 
4649
done:
 
4650
    FUNC_LEAVE_NOAPI(ret_value);
 
4651
}
 
4652
 
 
4653
 
 
4654
/*-------------------------------------------------------------------------
 
4655
 * Function:  H5T_conv_ushort_uint
 
4656
 *
 
4657
 * Purpose:  Converts `unsigned short' to `unsigned int'
 
4658
 *
 
4659
 * Return:  Success:  non-negative
 
4660
 *
 
4661
 *    Failure:  negative
 
4662
 *
 
4663
 * Programmer:  Robb Matzke
 
4664
 *    Friday, November 13, 1998
 
4665
 *
 
4666
 * Modifications:
 
4667
 *
 
4668
 *-------------------------------------------------------------------------
 
4669
 */
 
4670
herr_t
 
4671
H5T_conv_ushort_uint(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
 
4672
         size_t nelmts, size_t buf_stride,
 
4673
                     size_t UNUSED bkg_stride, void *buf, void UNUSED *bkg,
 
4674
         hid_t UNUSED dxpl_id)
 
4675
{
 
4676
    herr_t      ret_value=SUCCEED;       /* Return value */
 
4677
 
 
4678
    FUNC_ENTER_NOAPI(H5T_conv_ushort_uint, FAIL);
 
4679
 
 
4680
    H5T_CONV_uU(USHORT, UINT, unsigned short, unsigned, -, -);
 
4681
 
 
4682
done:
 
4683
    FUNC_LEAVE_NOAPI(ret_value);
 
4684
}
 
4685
 
 
4686
 
 
4687
/*-------------------------------------------------------------------------
 
4688
 * Function:  H5T_conv_short_long
 
4689
 *
 
4690
 * Purpose:  Converts `short' to `long'
 
4691
 *
 
4692
 * Return:  Success:  non-negative
 
4693
 *
 
4694
 *    Failure:  negative
 
4695
 *
 
4696
 * Programmer:  Robb Matzke
 
4697
 *    Friday, November 13, 1998
 
4698
 *
 
4699
 * Modifications:
 
4700
 *
 
4701
 *-------------------------------------------------------------------------
 
4702
 */
 
4703
herr_t
 
4704
H5T_conv_short_long(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
 
4705
        size_t nelmts, size_t buf_stride,
 
4706
                    size_t UNUSED bkg_stride, void *buf, void UNUSED *bkg,
 
4707
        hid_t UNUSED dxpl_id)
 
4708
{
 
4709
    herr_t      ret_value=SUCCEED;       /* Return value */
 
4710
 
 
4711
    FUNC_ENTER_NOAPI(H5T_conv_short_long, FAIL);
 
4712
 
 
4713
    H5T_CONV_sS(SHORT, LONG, short, long, -, -);
 
4714
 
 
4715
done:
 
4716
    FUNC_LEAVE_NOAPI(ret_value);
 
4717
}
 
4718
 
 
4719
 
 
4720
/*-------------------------------------------------------------------------
 
4721
 * Function:  H5T_conv_short_ulong
 
4722
 *
 
4723
 * Purpose:  Converts `short' to `unsigned long'
 
4724
 *
 
4725
 * Return:  Success:  Non-negative
 
4726
 *
 
4727
 *    Failure:  Negative
 
4728
 *
 
4729
 * Programmer:  Robb Matzke
 
4730
 *    Friday, November 13, 1998
 
4731
 *
 
4732
 * Modifications:
 
4733
 *
 
4734
 *-------------------------------------------------------------------------
 
4735
 */
 
4736
herr_t
 
4737
H5T_conv_short_ulong(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
 
4738
         size_t nelmts, size_t buf_stride,
 
4739
                     size_t UNUSED bkg_stride, void *buf, void UNUSED *bkg,
 
4740
         hid_t UNUSED dxpl_id)
 
4741
{
 
4742
    herr_t      ret_value=SUCCEED;       /* Return value */
 
4743
 
 
4744
    FUNC_ENTER_NOAPI(H5T_conv_short_ulong, FAIL);
 
4745
 
 
4746
    H5T_CONV_sU(SHORT, ULONG, short, unsigned long, -, -);
 
4747
 
 
4748
done:
 
4749
    FUNC_LEAVE_NOAPI(ret_value);
 
4750
}
 
4751
 
 
4752
 
 
4753
/*-------------------------------------------------------------------------
 
4754
 * Function:  H5T_conv_ushort_long
 
4755
 *
 
4756
 * Purpose:  Converts `unsigned short' to `long'
 
4757
 *
 
4758
 * Return:  Success:  Non-negative
 
4759
 *
 
4760
 *    Failure:  Negative
 
4761
 *
 
4762
 * Programmer:  Robb Matzke
 
4763
 *    Friday, November 13, 1998
 
4764
 *
 
4765
 * Modifications:
 
4766
 *
 
4767
 *-------------------------------------------------------------------------
 
4768
 */
 
4769
herr_t
 
4770
H5T_conv_ushort_long(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
 
4771
         size_t nelmts, size_t buf_stride,
 
4772
                     size_t UNUSED bkg_stride, void *buf, void UNUSED *bkg,
 
4773
         hid_t UNUSED dxpl_id)
 
4774
{
 
4775
    herr_t      ret_value=SUCCEED;       /* Return value */
 
4776
 
 
4777
    FUNC_ENTER_NOAPI(H5T_conv_ushort_long, FAIL);
 
4778
 
 
4779
    H5T_CONV_uS(USHORT, LONG, unsigned short, long, -, LONG_MAX);
 
4780
 
 
4781
done:
 
4782
    FUNC_LEAVE_NOAPI(ret_value);
 
4783
}
 
4784
 
 
4785
 
 
4786
/*-------------------------------------------------------------------------
 
4787
 * Function:  H5T_conv_ushort_ulong
 
4788
 *
 
4789
 * Purpose:  Converts `unsigned short' to `unsigned long'
 
4790
 *
 
4791
 * Return:  Success:  non-negative
 
4792
 *
 
4793
 *    Failure:  negative
 
4794
 *
 
4795
 * Programmer:  Robb Matzke
 
4796
 *    Friday, November 13, 1998
 
4797
 *
 
4798
 * Modifications:
 
4799
 *
 
4800
 *-------------------------------------------------------------------------
 
4801
 */
 
4802
herr_t
 
4803
H5T_conv_ushort_ulong(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
 
4804
          size_t nelmts, size_t buf_stride,
 
4805
                      size_t UNUSED bkg_stride, void *buf, void UNUSED *bkg,
 
4806
                      hid_t UNUSED dxpl_id)
 
4807
{
 
4808
    herr_t      ret_value=SUCCEED;       /* Return value */
 
4809
 
 
4810
    FUNC_ENTER_NOAPI(H5T_conv_ushort_ulong, FAIL);
 
4811
 
 
4812
    H5T_CONV_uU(USHORT, ULONG, unsigned short, unsigned long, -, -);
 
4813
 
 
4814
done:
 
4815
    FUNC_LEAVE_NOAPI(ret_value);
 
4816
}
 
4817
 
 
4818
 
 
4819
/*-------------------------------------------------------------------------
 
4820
 * Function:  H5T_conv_short_llong
 
4821
 *
 
4822
 * Purpose:  Converts `short' to `long_long'
 
4823
 *
 
4824
 * Return:  Success:  Non-negative
 
4825
 *
 
4826
 *    Failure:  Negative
 
4827
 *
 
4828
 * Programmer:  Robb Matzke
 
4829
 *    Friday, November 13, 1998
 
4830
 *
 
4831
 * Modifications:
 
4832
 *
 
4833
 *-------------------------------------------------------------------------
 
4834
 */
 
4835
herr_t
 
4836
H5T_conv_short_llong(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
 
4837
         size_t nelmts, size_t buf_stride,
 
4838
                     size_t UNUSED bkg_stride, void *buf, void UNUSED *bkg,
 
4839
         hid_t UNUSED dxpl_id)
 
4840
{
 
4841
    herr_t      ret_value=SUCCEED;       /* Return value */
 
4842
 
 
4843
    FUNC_ENTER_NOAPI(H5T_conv_short_llong, FAIL);
 
4844
 
 
4845
    H5T_CONV_sS(SHORT, LLONG, short, long_long, -, -);
 
4846
 
 
4847
done:
 
4848
    FUNC_LEAVE_NOAPI(ret_value);
 
4849
}
 
4850
 
 
4851
 
 
4852
/*-------------------------------------------------------------------------
 
4853
 * Function:  H5T_conv_short_ullong
 
4854
 *
 
4855
 * Purpose:  Converts `short' to `unsigned long_long'
 
4856
 *
 
4857
 * Return:  Success:  Non-negative
 
4858
 *
 
4859
 *    Failure:  Negative
 
4860
 *
 
4861
 * Programmer:  Robb Matzke
 
4862
 *    Friday, November 13, 1998
 
4863
 *
 
4864
 * Modifications:
 
4865
 *
 
4866
 *-------------------------------------------------------------------------
 
4867
 */
 
4868
herr_t
 
4869
H5T_conv_short_ullong(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
 
4870
          size_t nelmts, size_t buf_stride,
 
4871
                      size_t UNUSED bkg_stride, void *buf, void UNUSED *bkg,
 
4872
                      hid_t UNUSED dxpl_id)
 
4873
{
 
4874
    herr_t      ret_value=SUCCEED;       /* Return value */
 
4875
 
 
4876
    FUNC_ENTER_NOAPI(H5T_conv_short_ullong, FAIL);
 
4877
 
 
4878
    H5T_CONV_sU(SHORT, ULLONG, short, unsigned long_long, -, -);
 
4879
 
 
4880
done:
 
4881
    FUNC_LEAVE_NOAPI(ret_value);
 
4882
}
 
4883
 
 
4884
 
 
4885
/*-------------------------------------------------------------------------
 
4886
 * Function:  H5T_conv_ushort_llong
 
4887
 *
 
4888
 * Purpose:  Converts `unsigned short' to `long_long'
 
4889
 *
 
4890
 * Return:  Success:  Non-negative
 
4891
 *
 
4892
 *    Failure:  Negative
 
4893
 *
 
4894
 * Programmer:  Robb Matzke
 
4895
 *    Friday, November 13, 1998
 
4896
 *
 
4897
 * Modifications:
 
4898
 *
 
4899
 *-------------------------------------------------------------------------
 
4900
 */
 
4901
herr_t
 
4902
H5T_conv_ushort_llong(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
 
4903
          size_t nelmts, size_t buf_stride,
 
4904
                      size_t UNUSED bkg_stride, void *buf, void UNUSED *bkg,
 
4905
                      hid_t UNUSED dxpl_id)
 
4906
{
 
4907
    herr_t      ret_value=SUCCEED;       /* Return value */
 
4908
 
 
4909
    FUNC_ENTER_NOAPI(H5T_conv_ushort_llong, FAIL);
 
4910
 
 
4911
    H5T_CONV_uS(USHORT, LLONG, unsigned short, long_long, -, LLONG_MAX);
 
4912
 
 
4913
done:
 
4914
    FUNC_LEAVE_NOAPI(ret_value);
 
4915
}
 
4916
 
 
4917
 
 
4918
/*-------------------------------------------------------------------------
 
4919
 * Function:  H5T_conv_ushort_ullong
 
4920
 *
 
4921
 * Purpose:  Converts `unsigned short' to `unsigned long_long'
 
4922
 *
 
4923
 * Return:  Success:  Non-negative
 
4924
 *
 
4925
 *    Failure:  Negative
 
4926
 *
 
4927
 * Programmer:  Robb Matzke
 
4928
 *    Friday, November 13, 1998
 
4929
 *
 
4930
 * Modifications:
 
4931
 *
 
4932
 *-------------------------------------------------------------------------
 
4933
 */
 
4934
herr_t
 
4935
H5T_conv_ushort_ullong(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
 
4936
           size_t nelmts, size_t buf_stride,
 
4937
                       size_t UNUSED bkg_stride, void *buf, void UNUSED *bkg,
 
4938
                       hid_t UNUSED dxpl_id)
 
4939
{
 
4940
    herr_t      ret_value=SUCCEED;       /* Return value */
 
4941
 
 
4942
    FUNC_ENTER_NOAPI(H5T_conv_ushort_ullong, FAIL);
 
4943
 
 
4944
    H5T_CONV_uU(USHORT, ULLONG, unsigned short, unsigned long_long, -, -);
 
4945
 
 
4946
done:
 
4947
    FUNC_LEAVE_NOAPI(ret_value);
 
4948
}
 
4949
 
 
4950
 
 
4951
/*-------------------------------------------------------------------------
 
4952
 * Function:  H5T_conv_int_schar
 
4953
 *
 
4954
 * Purpose:  Converts `int' to `signed char'
 
4955
 *
 
4956
 * Return:  Success:  non-negative
 
4957
 *
 
4958
 *    Failure:  negative
 
4959
 *
 
4960
 * Programmer:  Robb Matzke
 
4961
 *    Friday, November 13, 1998
 
4962
 *
 
4963
 * Modifications:
 
4964
 *
 
4965
 *-------------------------------------------------------------------------
 
4966
 */
 
4967
herr_t
 
4968
H5T_conv_int_schar(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
 
4969
       size_t nelmts, size_t buf_stride,
 
4970
                   size_t UNUSED bkg_stride, void *buf, void UNUSED *bkg,
 
4971
       hid_t UNUSED dxpl_id)
 
4972
{
 
4973
    herr_t      ret_value=SUCCEED;       /* Return value */
 
4974
 
 
4975
    FUNC_ENTER_NOAPI(H5T_conv_int_schar, FAIL);
 
4976
 
 
4977
    H5T_CONV_Ss(INT, SCHAR, int, signed char, SCHAR_MIN, SCHAR_MAX);
 
4978
 
 
4979
done:
 
4980
    FUNC_LEAVE_NOAPI(ret_value);
 
4981
}
 
4982
 
 
4983
 
 
4984
/*-------------------------------------------------------------------------
 
4985
 * Function:  H5T_conv_int_uchar
 
4986
 *
 
4987
 * Purpose:  Converts `int' to `unsigned char'
 
4988
 *
 
4989
 * Return:  Success:  non-negative
 
4990
 *
 
4991
 *    Failure:  negative
 
4992
 *
 
4993
 * Programmer:  Robb Matzke
 
4994
 *    Friday, November 13, 1998
 
4995
 *
 
4996
 * Modifications:
 
4997
 *
 
4998
 *-------------------------------------------------------------------------
 
4999
 */
 
5000
herr_t
 
5001
H5T_conv_int_uchar(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
 
5002
       size_t nelmts, size_t buf_stride,
 
5003
                   size_t UNUSED bkg_stride, void *buf, void UNUSED *bkg,
 
5004
       hid_t UNUSED dxpl_id)
 
5005
{
 
5006
    herr_t      ret_value=SUCCEED;       /* Return value */
 
5007
 
 
5008
    FUNC_ENTER_NOAPI(H5T_conv_int_uchar, FAIL);
 
5009
 
 
5010
    H5T_CONV_Su(INT, UCHAR, int, unsigned char, -, UCHAR_MAX);
 
5011
 
 
5012
done:
 
5013
    FUNC_LEAVE_NOAPI(ret_value);
 
5014
}
 
5015
 
 
5016
 
 
5017
/*-------------------------------------------------------------------------
 
5018
 * Function:  H5T_conv_uint_schar
 
5019
 *
 
5020
 * Purpose:  Converts `unsigned int' to `signed char'
 
5021
 *
 
5022
 * Return:  Success:  non-negative
 
5023
 *
 
5024
 *    Failure:  negative
 
5025
 *
 
5026
 * Programmer:  Robb Matzke
 
5027
 *    Friday, November 13, 1998
 
5028
 *
 
5029
 * Modifications:
 
5030
 *
 
5031
 *-------------------------------------------------------------------------
 
5032
 */
 
5033
herr_t
 
5034
H5T_conv_uint_schar(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
 
5035
        size_t nelmts, size_t buf_stride,
 
5036
                    size_t UNUSED bkg_stride, void *buf, void UNUSED *bkg,
 
5037
        hid_t UNUSED dxpl_id)
 
5038
{
 
5039
    herr_t      ret_value=SUCCEED;       /* Return value */
 
5040
 
 
5041
    FUNC_ENTER_NOAPI(H5T_conv_uint_schar, FAIL);
 
5042
 
 
5043
    H5T_CONV_Us(UINT, SCHAR, unsigned, signed char, -, SCHAR_MAX);
 
5044
 
 
5045
done:
 
5046
    FUNC_LEAVE_NOAPI(ret_value);
 
5047
}
 
5048
 
 
5049
 
 
5050
/*-------------------------------------------------------------------------
 
5051
 * Function:  H5T_conv_uint_uchar
 
5052
 *
 
5053
 * Purpose:  Converts `unsigned int' to `unsigned char'
 
5054
 *
 
5055
 * Return:  Success:  non-negative
 
5056
 *
 
5057
 *    Failure:  negative
 
5058
 *
 
5059
 * Programmer:  Robb Matzke
 
5060
 *    Friday, November 13, 1998
 
5061
 *
 
5062
 * Modifications:
 
5063
 *
 
5064
 *-------------------------------------------------------------------------
 
5065
 */
 
5066
herr_t
 
5067
H5T_conv_uint_uchar(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
 
5068
        size_t nelmts, size_t buf_stride,
 
5069
                    size_t UNUSED bkg_stride, void *buf, void UNUSED *bkg,
 
5070
        hid_t UNUSED dxpl_id)
 
5071
{
 
5072
    herr_t      ret_value=SUCCEED;       /* Return value */
 
5073
 
 
5074
    FUNC_ENTER_NOAPI(H5T_conv_uint_uchar, FAIL);
 
5075
 
 
5076
    H5T_CONV_Uu(UINT, UCHAR, unsigned, unsigned char, -, UCHAR_MAX);
 
5077
 
 
5078
done:
 
5079
    FUNC_LEAVE_NOAPI(ret_value);
 
5080
}
 
5081
 
 
5082
 
 
5083
/*-------------------------------------------------------------------------
 
5084
 * Function:  H5T_conv_int_short
 
5085
 *
 
5086
 * Purpose:  Converts `int' to `short'
 
5087
 *
 
5088
 * Return:  Success:  non-negative
 
5089
 *
 
5090
 *    Failure:  negative
 
5091
 *
 
5092
 * Programmer:  Robb Matzke
 
5093
 *    Friday, November 13, 1998
 
5094
 *
 
5095
 * Modifications:
 
5096
 *
 
5097
 *-------------------------------------------------------------------------
 
5098
 */
 
5099
herr_t
 
5100
H5T_conv_int_short(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
 
5101
       size_t nelmts, size_t buf_stride,
 
5102
                   size_t UNUSED bkg_stride, void *buf, void UNUSED *bkg,
 
5103
       hid_t UNUSED dxpl_id)
 
5104
{
 
5105
    herr_t      ret_value=SUCCEED;       /* Return value */
 
5106
 
 
5107
    FUNC_ENTER_NOAPI(H5T_conv_int_short, FAIL);
 
5108
 
 
5109
    H5T_CONV_Ss(INT, SHORT, int, short, SHRT_MIN, SHRT_MAX);
 
5110
 
 
5111
done:
 
5112
    FUNC_LEAVE_NOAPI(ret_value);
 
5113
}
 
5114
 
 
5115
 
 
5116
/*-------------------------------------------------------------------------
 
5117
 * Function:  H5T_conv_int_ushort
 
5118
 *
 
5119
 * Purpose:  Converts `int' to `unsigned short'
 
5120
 *
 
5121
 * Return:  Success:  non-negative
 
5122
 *
 
5123
 *    Failure:  negative
 
5124
 *
 
5125
 * Programmer:  Robb Matzke
 
5126
 *    Friday, November 13, 1998
 
5127
 *
 
5128
 * Modifications:
 
5129
 *
 
5130
 *-------------------------------------------------------------------------
 
5131
 */
 
5132
herr_t
 
5133
H5T_conv_int_ushort(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
 
5134
        size_t nelmts, size_t buf_stride,
 
5135
                    size_t UNUSED bkg_stride, void *buf, void UNUSED *bkg,
 
5136
        hid_t UNUSED dxpl_id)
 
5137
{
 
5138
    herr_t      ret_value=SUCCEED;       /* Return value */
 
5139
 
 
5140
    FUNC_ENTER_NOAPI(H5T_conv_int_ushort, FAIL);
 
5141
 
 
5142
    H5T_CONV_Su(INT, USHORT, int, unsigned short, -, USHRT_MAX);
 
5143
 
 
5144
done:
 
5145
    FUNC_LEAVE_NOAPI(ret_value);
 
5146
}
 
5147
 
 
5148
 
 
5149
/*-------------------------------------------------------------------------
 
5150
 * Function:  H5T_conv_uint_short
 
5151
 *
 
5152
 * Purpose:  Converts `unsigned int' to `short'
 
5153
 *
 
5154
 * Return:  Success:  non-negative
 
5155
 *
 
5156
 *    Failure:  negative
 
5157
 *
 
5158
 * Programmer:  Robb Matzke
 
5159
 *    Friday, November 13, 1998
 
5160
 *
 
5161
 * Modifications:
 
5162
 *
 
5163
 *-------------------------------------------------------------------------
 
5164
 */
 
5165
herr_t
 
5166
H5T_conv_uint_short(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
 
5167
        size_t nelmts, size_t buf_stride,
 
5168
                    size_t UNUSED bkg_stride, void *buf, void UNUSED *bkg,
 
5169
        hid_t UNUSED dxpl_id)
 
5170
{
 
5171
    herr_t      ret_value=SUCCEED;       /* Return value */
 
5172
 
 
5173
    FUNC_ENTER_NOAPI(H5T_conv_uint_short, FAIL);
 
5174
 
 
5175
    H5T_CONV_Us(UINT, SHORT, unsigned, short, -, SHRT_MAX);
 
5176
 
 
5177
done:
 
5178
    FUNC_LEAVE_NOAPI(ret_value);
 
5179
}
 
5180
 
 
5181
 
 
5182
/*-------------------------------------------------------------------------
 
5183
 * Function:  H5T_conv_uint_ushort
 
5184
 *
 
5185
 * Purpose:  Converts `unsigned int' to `unsigned short'
 
5186
 *
 
5187
 * Return:  Success:  non-negative
 
5188
 *
 
5189
 *    Failure:  negative
 
5190
 *
 
5191
 * Programmer:  Robb Matzke
 
5192
 *    Friday, November 13, 1998
 
5193
 *
 
5194
 * Modifications:
 
5195
 *
 
5196
 *-------------------------------------------------------------------------
 
5197
 */
 
5198
herr_t
 
5199
H5T_conv_uint_ushort(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
 
5200
         size_t nelmts, size_t buf_stride,
 
5201
                     size_t UNUSED bkg_stride, void *buf, void UNUSED *bkg,
 
5202
         hid_t UNUSED dxpl_id)
 
5203
{
 
5204
    herr_t      ret_value=SUCCEED;       /* Return value */
 
5205
 
 
5206
    FUNC_ENTER_NOAPI(H5T_conv_uint_ushort, FAIL);
 
5207
 
 
5208
    H5T_CONV_Uu(UINT, USHORT, unsigned, unsigned short, -, USHRT_MAX);
 
5209
 
 
5210
done:
 
5211
    FUNC_LEAVE_NOAPI(ret_value);
 
5212
}
 
5213
 
 
5214
 
 
5215
/*-------------------------------------------------------------------------
 
5216
 * Function:  H5T_conv_int_uint
 
5217
 *
 
5218
 * Purpose:  Converts `int' to `unsigned int'
 
5219
 *
 
5220
 * Return:  Success:  non-negative
 
5221
 *
 
5222
 *    Failure:  negative
 
5223
 *
 
5224
 * Programmer:  Robb Matzke
 
5225
 *    Monday, November 16, 1998
 
5226
 *
 
5227
 * Modifications:
 
5228
 *
 
5229
 *-------------------------------------------------------------------------
 
5230
 */
 
5231
herr_t
 
5232
H5T_conv_int_uint(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
 
5233
      size_t nelmts, size_t buf_stride, size_t UNUSED bkg_stride,
 
5234
                  void *buf, void UNUSED *bkg, hid_t UNUSED dxpl_id)
 
5235
{
 
5236
    herr_t      ret_value=SUCCEED;       /* Return value */
 
5237
 
 
5238
    FUNC_ENTER_NOAPI(H5T_conv_int_uint, FAIL);
 
5239
 
 
5240
    H5T_CONV_su(INT, UINT, int, unsigned, -, -);
 
5241
 
 
5242
done:
 
5243
    FUNC_LEAVE_NOAPI(ret_value);
 
5244
}
 
5245
 
 
5246
 
 
5247
/*-------------------------------------------------------------------------
 
5248
 * Function:  H5T_conv_uint_int
 
5249
 *
 
5250
 * Purpose:  Converts `unsigned int' to `int'
 
5251
 *
 
5252
 * Return:  Success:  non-negative
 
5253
 *
 
5254
 *    Failure:  negative
 
5255
 *
 
5256
 * Programmer:  Robb Matzke
 
5257
 *    Monday, November 16, 1998
 
5258
 *
 
5259
 * Modifications:
 
5260
 *
 
5261
 *-------------------------------------------------------------------------
 
5262
 */
 
5263
herr_t
 
5264
H5T_conv_uint_int(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
 
5265
      size_t nelmts, size_t buf_stride, size_t UNUSED bkg_stride,
 
5266
                  void *buf, void UNUSED *bkg, hid_t UNUSED dxpl_id)
 
5267
{
 
5268
    herr_t      ret_value=SUCCEED;       /* Return value */
 
5269
 
 
5270
    FUNC_ENTER_NOAPI(H5T_conv_uint_int, FAIL);
 
5271
 
 
5272
    H5T_CONV_us(UINT, INT, unsigned, int, -, INT_MAX);
 
5273
 
 
5274
done:
 
5275
    FUNC_LEAVE_NOAPI(ret_value);
 
5276
}
 
5277
 
 
5278
 
 
5279
/*-------------------------------------------------------------------------
 
5280
 * Function:  H5T_conv_int_long
 
5281
 *
 
5282
 * Purpose:  Converts `int' to `long'
 
5283
 *
 
5284
 * Return:  Success:  non-negative
 
5285
 *
 
5286
 *    Failure:  negative
 
5287
 *
 
5288
 * Programmer:  Robb Matzke
 
5289
 *    Friday, November 13, 1998
 
5290
 *
 
5291
 * Modifications:
 
5292
 *
 
5293
 *-------------------------------------------------------------------------
 
5294
 */
 
5295
herr_t
 
5296
H5T_conv_int_long(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
 
5297
      size_t nelmts, size_t buf_stride, size_t UNUSED bkg_stride,
 
5298
                  void *buf, void UNUSED *bkg, hid_t UNUSED dxpl_id)
 
5299
{
 
5300
    herr_t      ret_value=SUCCEED;       /* Return value */
 
5301
 
 
5302
    FUNC_ENTER_NOAPI(H5T_conv_int_long, FAIL);
 
5303
 
 
5304
    H5T_CONV_sS(INT, LONG, int, long, -, -);
 
5305
 
 
5306
done:
 
5307
    FUNC_LEAVE_NOAPI(ret_value);
 
5308
}
 
5309
 
 
5310
 
 
5311
/*-------------------------------------------------------------------------
 
5312
 * Function:  H5T_conv_int_ulong
 
5313
 *
 
5314
 * Purpose:  Converts `int' to `unsigned long'
 
5315
 *
 
5316
 * Return:  Success:  Non-negative
 
5317
 *
 
5318
 *    Failure:  Negative
 
5319
 *
 
5320
 * Programmer:  Robb Matzke
 
5321
 *    Friday, November 13, 1998
 
5322
 *
 
5323
 * Modifications:
 
5324
 *
 
5325
 *-------------------------------------------------------------------------
 
5326
 */
 
5327
herr_t
 
5328
H5T_conv_int_ulong(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
 
5329
       size_t nelmts, size_t buf_stride, size_t UNUSED bkg_stride,
 
5330
                   void *buf, void UNUSED *bkg, hid_t UNUSED dxpl_id)
 
5331
{
 
5332
    herr_t      ret_value=SUCCEED;       /* Return value */
 
5333
 
 
5334
    FUNC_ENTER_NOAPI(H5T_conv_int_ulong, FAIL);
 
5335
 
 
5336
    H5T_CONV_sU(INT, LONG, int, unsigned long, -, -);
 
5337
 
 
5338
done:
 
5339
    FUNC_LEAVE_NOAPI(ret_value);
 
5340
}
 
5341
 
 
5342
 
 
5343
/*-------------------------------------------------------------------------
 
5344
 * Function:  H5T_conv_uint_long
 
5345
 *
 
5346
 * Purpose:  Converts `unsigned int' to `long'
 
5347
 *
 
5348
 * Return:  Success:  Non-negative
 
5349
 *
 
5350
 *    Failure:  Negative
 
5351
 *
 
5352
 * Programmer:  Robb Matzke
 
5353
 *    Friday, November 13, 1998
 
5354
 *
 
5355
 * Modifications:
 
5356
 *
 
5357
 *-------------------------------------------------------------------------
 
5358
 */
 
5359
herr_t
 
5360
H5T_conv_uint_long(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
 
5361
       size_t nelmts, size_t buf_stride, size_t UNUSED bkg_stride,
 
5362
                   void *buf, void UNUSED *bkg, hid_t UNUSED dxpl_id)
 
5363
{
 
5364
    herr_t      ret_value=SUCCEED;       /* Return value */
 
5365
 
 
5366
    FUNC_ENTER_NOAPI(H5T_conv_uint_long, FAIL);
 
5367
 
 
5368
    H5T_CONV_uS(UINT, LONG, unsigned, long, -, LONG_MAX);
 
5369
 
 
5370
done:
 
5371
    FUNC_LEAVE_NOAPI(ret_value);
 
5372
}
 
5373
 
 
5374
 
 
5375
/*-------------------------------------------------------------------------
 
5376
 * Function:  H5T_conv_uint_ulong
 
5377
 *
 
5378
 * Purpose:  Converts `unsigned int' to `unsigned long'
 
5379
 *
 
5380
 * Return:  Success:  non-negative
 
5381
 *
 
5382
 *    Failure:  negative
 
5383
 *
 
5384
 * Programmer:  Robb Matzke
 
5385
 *    Friday, November 13, 1998
 
5386
 *
 
5387
 * Modifications:
 
5388
 *
 
5389
 *-------------------------------------------------------------------------
 
5390
 */
 
5391
herr_t
 
5392
H5T_conv_uint_ulong(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
 
5393
        size_t nelmts, size_t buf_stride, size_t UNUSED bkg_stride,
 
5394
                    void *buf, void UNUSED *bkg, hid_t UNUSED dxpl_id)
 
5395
{
 
5396
    herr_t      ret_value=SUCCEED;       /* Return value */
 
5397
 
 
5398
    FUNC_ENTER_NOAPI(H5T_conv_uint_ulong, FAIL);
 
5399
 
 
5400
    H5T_CONV_uU(UINT, ULONG, unsigned, unsigned long, -, -);
 
5401
 
 
5402
done:
 
5403
    FUNC_LEAVE_NOAPI(ret_value);
 
5404
}
 
5405
 
 
5406
 
 
5407
/*-------------------------------------------------------------------------
 
5408
 * Function:  H5T_conv_int_llong
 
5409
 *
 
5410
 * Purpose:  Converts `int' to `long_long'
 
5411
 *
 
5412
 * Return:  Success:  Non-negative
 
5413
 *
 
5414
 *    Failure:  Negative
 
5415
 *
 
5416
 * Programmer:  Robb Matzke
 
5417
 *    Friday, November 13, 1998
 
5418
 *
 
5419
 * Modifications:
 
5420
 *
 
5421
 *-------------------------------------------------------------------------
 
5422
 */
 
5423
herr_t
 
5424
H5T_conv_int_llong(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
 
5425
       size_t nelmts, size_t buf_stride, size_t UNUSED bkg_stride,
 
5426
                   void *buf, void UNUSED *bkg, hid_t UNUSED dxpl_id)
 
5427
{
 
5428
    herr_t      ret_value=SUCCEED;       /* Return value */
 
5429
 
 
5430
    FUNC_ENTER_NOAPI(H5T_conv_int_llong, FAIL);
 
5431
 
 
5432
    H5T_CONV_sS(INT, LLONG, int, long_long, -, -);
 
5433
 
 
5434
done:
 
5435
    FUNC_LEAVE_NOAPI(ret_value);
 
5436
}
 
5437
 
 
5438
 
 
5439
/*-------------------------------------------------------------------------
 
5440
 * Function:  H5T_conv_int_ullong
 
5441
 *
 
5442
 * Purpose:  Converts `int' to `unsigned long_long'
 
5443
 *
 
5444
 * Return:  Success:  Non-negative
 
5445
 *
 
5446
 *    Failure:  Negative
 
5447
 *
 
5448
 * Programmer:  Robb Matzke
 
5449
 *    Friday, November 13, 1998
 
5450
 *
 
5451
 * Modifications:
 
5452
 *
 
5453
 *-------------------------------------------------------------------------
 
5454
 */
 
5455
herr_t
 
5456
H5T_conv_int_ullong(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
 
5457
        size_t nelmts, size_t buf_stride, size_t UNUSED bkg_stride,
 
5458
                    void *buf, void UNUSED *bkg, hid_t UNUSED dxpl_id)
 
5459
{
 
5460
    herr_t      ret_value=SUCCEED;       /* Return value */
 
5461
 
 
5462
    FUNC_ENTER_NOAPI(H5T_conv_int_ullong, FAIL);
 
5463
 
 
5464
    H5T_CONV_sU(INT, ULLONG, int, unsigned long_long, -, -);
 
5465
 
 
5466
done:
 
5467
    FUNC_LEAVE_NOAPI(ret_value);
 
5468
}
 
5469
 
 
5470
 
 
5471
/*-------------------------------------------------------------------------
 
5472
 * Function:  H5T_conv_uint_llong
 
5473
 *
 
5474
 * Purpose:  Converts `unsigned int' to `long_long'
 
5475
 *
 
5476
 * Return:  Success:  Non-negative
 
5477
 *
 
5478
 *    Failure:  Negative
 
5479
 *
 
5480
 * Programmer:  Robb Matzke
 
5481
 *    Friday, November 13, 1998
 
5482
 *
 
5483
 * Modifications:
 
5484
 *
 
5485
 *-------------------------------------------------------------------------
 
5486
 */
 
5487
herr_t
 
5488
H5T_conv_uint_llong(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
 
5489
        size_t nelmts, size_t buf_stride, size_t UNUSED bkg_stride,
 
5490
                    void *buf, void UNUSED *bkg, hid_t UNUSED dxpl_id)
 
5491
{
 
5492
    herr_t      ret_value=SUCCEED;       /* Return value */
 
5493
 
 
5494
    FUNC_ENTER_NOAPI(H5T_conv_uint_llong, FAIL);
 
5495
 
 
5496
    H5T_CONV_uS(UINT, LLONG, unsigned, long_long, -, LLONG_MAX);
 
5497
 
 
5498
done:
 
5499
    FUNC_LEAVE_NOAPI(ret_value);
 
5500
}
 
5501
 
 
5502
 
 
5503
/*-------------------------------------------------------------------------
 
5504
 * Function:  H5T_conv_uint_ullong
 
5505
 *
 
5506
 * Purpose:  Converts `unsigned int' to `unsigned long_long'
 
5507
 *
 
5508
 * Return:  Success:  Non-negative
 
5509
 *
 
5510
 *    Failure:  Negative
 
5511
 *
 
5512
 * Programmer:  Robb Matzke
 
5513
 *    Friday, November 13, 1998
 
5514
 *
 
5515
 * Modifications:
 
5516
 *
 
5517
 *-------------------------------------------------------------------------
 
5518
 */
 
5519
herr_t
 
5520
H5T_conv_uint_ullong(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
 
5521
         size_t nelmts, size_t buf_stride,
 
5522
                     size_t UNUSED bkg_stride, void *buf, void UNUSED *bkg,
 
5523
         hid_t UNUSED dxpl_id)
 
5524
{
 
5525
    herr_t      ret_value=SUCCEED;       /* Return value */
 
5526
 
 
5527
    FUNC_ENTER_NOAPI(H5T_conv_uint_ullong, FAIL);
 
5528
 
 
5529
    H5T_CONV_uU(UINT, ULLONG, unsigned, unsigned long_long, -, -);
 
5530
 
 
5531
done:
 
5532
    FUNC_LEAVE_NOAPI(ret_value);
 
5533
}
 
5534
 
 
5535
 
 
5536
/*-------------------------------------------------------------------------
 
5537
 * Function:  H5T_conv_long_schar
 
5538
 *
 
5539
 * Purpose:  Converts `long' to `signed char'
 
5540
 *
 
5541
 * Return:  Success:  non-negative
 
5542
 *
 
5543
 *    Failure:  negative
 
5544
 *
 
5545
 * Programmer:  Robb Matzke
 
5546
 *    Friday, November 13, 1998
 
5547
 *
 
5548
 * Modifications:
 
5549
 *
 
5550
 *-------------------------------------------------------------------------
 
5551
 */
 
5552
herr_t
 
5553
H5T_conv_long_schar(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
 
5554
        size_t nelmts, size_t buf_stride, size_t UNUSED bkg_stride,
 
5555
                    void *buf, void UNUSED *bkg, hid_t UNUSED dxpl_id)
 
5556
{
 
5557
    herr_t      ret_value=SUCCEED;       /* Return value */
 
5558
 
 
5559
    FUNC_ENTER_NOAPI(H5T_conv_long_schar, FAIL);
 
5560
 
 
5561
    H5T_CONV_Ss(LONG, SCHAR, long, signed char, SCHAR_MIN, SCHAR_MAX);
 
5562
 
 
5563
done:
 
5564
    FUNC_LEAVE_NOAPI(ret_value);
 
5565
}
 
5566
 
 
5567
 
 
5568
/*-------------------------------------------------------------------------
 
5569
 * Function:  H5T_conv_long_uchar
 
5570
 *
 
5571
 * Purpose:  Converts `long' to `unsigned char'
 
5572
 *
 
5573
 * Return:  Success:  non-negative
 
5574
 *
 
5575
 *    Failure:  negative
 
5576
 *
 
5577
 * Programmer:  Robb Matzke
 
5578
 *    Friday, November 13, 1998
 
5579
 *
 
5580
 * Modifications:
 
5581
 *
 
5582
 *-------------------------------------------------------------------------
 
5583
 */
 
5584
herr_t
 
5585
H5T_conv_long_uchar(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
 
5586
        size_t nelmts, size_t buf_stride, size_t UNUSED bkg_stride,
 
5587
                    void *buf, void UNUSED *bkg, hid_t UNUSED dxpl_id)
 
5588
{
 
5589
    herr_t      ret_value=SUCCEED;       /* Return value */
 
5590
 
 
5591
    FUNC_ENTER_NOAPI(H5T_conv_long_uchar, FAIL);
 
5592
 
 
5593
    H5T_CONV_Su(LONG, UCHAR, long, unsigned char, -, UCHAR_MAX);
 
5594
 
 
5595
done:
 
5596
    FUNC_LEAVE_NOAPI(ret_value);
 
5597
}
 
5598
 
 
5599
 
 
5600
/*-------------------------------------------------------------------------
 
5601
 * Function:  H5T_conv_ulong_schar
 
5602
 *
 
5603
 * Purpose:  Converts `unsigned long' to `signed char'
 
5604
 *
 
5605
 * Return:  Success:  non-negative
 
5606
 *
 
5607
 *    Failure:  negative
 
5608
 *
 
5609
 * Programmer:  Robb Matzke
 
5610
 *    Friday, November 13, 1998
 
5611
 *
 
5612
 * Modifications:
 
5613
 *
 
5614
 *-------------------------------------------------------------------------
 
5615
 */
 
5616
herr_t
 
5617
H5T_conv_ulong_schar(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
 
5618
         size_t nelmts, size_t buf_stride,
 
5619
                     size_t UNUSED bkg_stride, void *buf, void UNUSED *bkg,
 
5620
         hid_t UNUSED dxpl_id)
 
5621
{
 
5622
    herr_t      ret_value=SUCCEED;       /* Return value */
 
5623
 
 
5624
    FUNC_ENTER_NOAPI(H5T_conv_ulong_schar, FAIL);
 
5625
 
 
5626
    H5T_CONV_Us(ULONG, SCHAR, unsigned long, signed char, -, SCHAR_MAX);
 
5627
 
 
5628
done:
 
5629
    FUNC_LEAVE_NOAPI(ret_value);
 
5630
}
 
5631
 
 
5632
 
 
5633
/*-------------------------------------------------------------------------
 
5634
 * Function:  H5T_conv_ulong_uchar
 
5635
 *
 
5636
 * Purpose:  Converts `unsigned long' to `unsigned char'
 
5637
 *
 
5638
 * Return:  Success:  non-negative
 
5639
 *
 
5640
 *    Failure:  negative
 
5641
 *
 
5642
 * Programmer:  Robb Matzke
 
5643
 *    Friday, November 13, 1998
 
5644
 *
 
5645
 * Modifications:
 
5646
 *
 
5647
 *-------------------------------------------------------------------------
 
5648
 */
 
5649
herr_t
 
5650
H5T_conv_ulong_uchar(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
 
5651
         size_t nelmts, size_t buf_stride,
 
5652
                     size_t UNUSED bkg_stride, void *buf, void UNUSED *bkg,
 
5653
         hid_t UNUSED dxpl_id)
 
5654
{
 
5655
    herr_t      ret_value=SUCCEED;       /* Return value */
 
5656
 
 
5657
    FUNC_ENTER_NOAPI(H5T_conv_ulong_uchar, FAIL);
 
5658
 
 
5659
    H5T_CONV_Uu(ULONG, UCHAR, unsigned long, unsigned char, -, UCHAR_MAX);
 
5660
 
 
5661
done:
 
5662
    FUNC_LEAVE_NOAPI(ret_value);
 
5663
}
 
5664
 
 
5665
 
 
5666
/*-------------------------------------------------------------------------
 
5667
 * Function:  H5T_conv_long_short
 
5668
 *
 
5669
 * Purpose:  Converts `long' to `short'
 
5670
 *
 
5671
 * Return:  Success:  non-negative
 
5672
 *
 
5673
 *    Failure:  negative
 
5674
 *
 
5675
 * Programmer:  Robb Matzke
 
5676
 *    Friday, November 13, 1998
 
5677
 *
 
5678
 * Modifications:
 
5679
 *
 
5680
 *-------------------------------------------------------------------------
 
5681
 */
 
5682
herr_t
 
5683
H5T_conv_long_short(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
 
5684
        size_t nelmts, size_t buf_stride, size_t UNUSED bkg_stride,
 
5685
                    void *buf, void UNUSED *bkg, hid_t UNUSED dxpl_id)
 
5686
{
 
5687
    herr_t      ret_value=SUCCEED;       /* Return value */
 
5688
 
 
5689
    FUNC_ENTER_NOAPI(H5T_conv_long_short, FAIL);
 
5690
 
 
5691
    H5T_CONV_Ss(LONG, SHORT, long, short, SHRT_MIN, SHRT_MAX);
 
5692
 
 
5693
done:
 
5694
    FUNC_LEAVE_NOAPI(ret_value);
 
5695
}
 
5696
 
 
5697
 
 
5698
/*-------------------------------------------------------------------------
 
5699
 * Function:  H5T_conv_long_ushort
 
5700
 *
 
5701
 * Purpose:  Converts `long' to `unsigned short'
 
5702
 *
 
5703
 * Return:  Success:  non-negative
 
5704
 *
 
5705
 *    Failure:  negative
 
5706
 *
 
5707
 * Programmer:  Robb Matzke
 
5708
 *    Friday, November 13, 1998
 
5709
 *
 
5710
 * Modifications:
 
5711
 *
 
5712
 *-------------------------------------------------------------------------
 
5713
 */
 
5714
herr_t
 
5715
H5T_conv_long_ushort(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
 
5716
         size_t nelmts, size_t buf_stride,
 
5717
                     size_t UNUSED bkg_stride, void *buf, void UNUSED *bkg,
 
5718
         hid_t UNUSED dxpl_id)
 
5719
{
 
5720
    herr_t      ret_value=SUCCEED;       /* Return value */
 
5721
 
 
5722
    FUNC_ENTER_NOAPI(H5T_conv_long_ushort, FAIL);
 
5723
 
 
5724
    H5T_CONV_Su(LONG, USHORT, long, unsigned short, -, USHRT_MAX);
 
5725
 
 
5726
done:
 
5727
    FUNC_LEAVE_NOAPI(ret_value);
 
5728
}
 
5729
 
 
5730
 
 
5731
/*-------------------------------------------------------------------------
 
5732
 * Function:  H5T_conv_ulong_short
 
5733
 *
 
5734
 * Purpose:  Converts `unsigned long' to `short'
 
5735
 *
 
5736
 * Return:  Success:  non-negative
 
5737
 *
 
5738
 *    Failure:  negative
 
5739
 *
 
5740
 * Programmer:  Robb Matzke
 
5741
 *    Friday, November 13, 1998
 
5742
 *
 
5743
 * Modifications:
 
5744
 *
 
5745
 *-------------------------------------------------------------------------
 
5746
 */
 
5747
herr_t
 
5748
H5T_conv_ulong_short(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
 
5749
        size_t nelmts, size_t buf_stride, size_t UNUSED bkg_stride,
 
5750
                     void *buf, void UNUSED *bkg, hid_t UNUSED dxpl_id)
 
5751
{
 
5752
    herr_t      ret_value=SUCCEED;       /* Return value */
 
5753
 
 
5754
    FUNC_ENTER_NOAPI(H5T_conv_ulong_short, FAIL);
 
5755
 
 
5756
    H5T_CONV_Us(ULONG, SHORT, unsigned long, short, -, SHRT_MAX);
 
5757
 
 
5758
done:
 
5759
    FUNC_LEAVE_NOAPI(ret_value);
 
5760
}
 
5761
 
 
5762
 
 
5763
/*-------------------------------------------------------------------------
 
5764
 * Function:  H5T_conv_ulong_ushort
 
5765
 *
 
5766
 * Purpose:  Converts `unsigned long' to `unsigned short'
 
5767
 *
 
5768
 * Return:  Success:  non-negative
 
5769
 *
 
5770
 *    Failure:  negative
 
5771
 *
 
5772
 * Programmer:  Robb Matzke
 
5773
 *    Friday, November 13, 1998
 
5774
 *
 
5775
 * Modifications:
 
5776
 *
 
5777
 *-------------------------------------------------------------------------
 
5778
 */
 
5779
herr_t
 
5780
H5T_conv_ulong_ushort(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
 
5781
          size_t nelmts, size_t buf_stride,
 
5782
                      size_t UNUSED bkg_stride, void *buf, void UNUSED *bkg,
 
5783
                      hid_t UNUSED dxpl_id)
 
5784
{
 
5785
    herr_t      ret_value=SUCCEED;       /* Return value */
 
5786
 
 
5787
    FUNC_ENTER_NOAPI(H5T_conv_ulong_ushort, FAIL);
 
5788
 
 
5789
    H5T_CONV_Uu(ULONG, USHORT, unsigned long, unsigned short, -, USHRT_MAX);
 
5790
 
 
5791
done:
 
5792
    FUNC_LEAVE_NOAPI(ret_value);
 
5793
}
 
5794
 
 
5795
 
 
5796
/*-------------------------------------------------------------------------
 
5797
 * Function:  H5T_conv_long_int
 
5798
 *
 
5799
 * Purpose:  Converts `long' to `int'
 
5800
 *
 
5801
 * Return:  Success:  non-negative
 
5802
 *
 
5803
 *    Failure:  negative
 
5804
 *
 
5805
 * Programmer:  Robb Matzke
 
5806
 *    Friday, November 13, 1998
 
5807
 *
 
5808
 * Modifications:
 
5809
 *
 
5810
 *-------------------------------------------------------------------------
 
5811
 */
 
5812
herr_t
 
5813
H5T_conv_long_int(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
 
5814
      size_t nelmts, size_t buf_stride, size_t UNUSED bkg_stride,
 
5815
                  void *buf, void UNUSED *bkg, hid_t UNUSED dxpl_id)
 
5816
{
 
5817
    herr_t      ret_value=SUCCEED;       /* Return value */
 
5818
 
 
5819
    FUNC_ENTER_NOAPI(H5T_conv_long_int, FAIL);
 
5820
 
 
5821
    H5T_CONV_Ss(LONG, INT, long, int, INT_MIN, INT_MAX);
 
5822
 
 
5823
done:
 
5824
    FUNC_LEAVE_NOAPI(ret_value);
 
5825
}
 
5826
 
 
5827
 
 
5828
/*-------------------------------------------------------------------------
 
5829
 * Function:  H5T_conv_long_uint
 
5830
 *
 
5831
 * Purpose:  Converts `long' to `unsigned int'
 
5832
 *
 
5833
 * Return:  Success:  non-negative
 
5834
 *
 
5835
 *    Failure:  negative
 
5836
 *
 
5837
 * Programmer:  Robb Matzke
 
5838
 *    Friday, November 13, 1998
 
5839
 *
 
5840
 * Modifications:
 
5841
 *
 
5842
 *-------------------------------------------------------------------------
 
5843
 */
 
5844
herr_t
 
5845
H5T_conv_long_uint(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
 
5846
       size_t nelmts, size_t buf_stride, size_t UNUSED bkg_stride,
 
5847
                   void *buf, void UNUSED *bkg, hid_t UNUSED dxpl_id)
 
5848
{
 
5849
    herr_t      ret_value=SUCCEED;       /* Return value */
 
5850
 
 
5851
    FUNC_ENTER_NOAPI(H5T_conv_long_uint, FAIL);
 
5852
 
 
5853
    H5T_CONV_Su(LONG, UINT, long, unsigned, -, UINT_MAX);
 
5854
 
 
5855
done:
 
5856
    FUNC_LEAVE_NOAPI(ret_value);
 
5857
}
 
5858
 
 
5859
 
 
5860
/*-------------------------------------------------------------------------
 
5861
 * Function:  H5T_conv_ulong_int
 
5862
 *
 
5863
 * Purpose:  Converts `unsigned long' to `int'
 
5864
 *
 
5865
 * Return:  Success:  non-negative
 
5866
 *
 
5867
 *    Failure:  negative
 
5868
 *
 
5869
 * Programmer:  Robb Matzke
 
5870
 *    Friday, November 13, 1998
 
5871
 *
 
5872
 * Modifications:
 
5873
 *
 
5874
 *-------------------------------------------------------------------------
 
5875
 */
 
5876
herr_t
 
5877
H5T_conv_ulong_int(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
 
5878
       size_t nelmts, size_t buf_stride, size_t UNUSED bkg_stride,
 
5879
                   void *buf, void UNUSED *bkg, hid_t UNUSED dxpl_id)
 
5880
{
 
5881
    herr_t      ret_value=SUCCEED;       /* Return value */
 
5882
 
 
5883
    FUNC_ENTER_NOAPI(H5T_conv_ulong_int, FAIL);
 
5884
 
 
5885
    H5T_CONV_Us(ULONG, INT, unsigned long, int, -, INT_MAX);
 
5886
 
 
5887
done:
 
5888
    FUNC_LEAVE_NOAPI(ret_value);
 
5889
}
 
5890
 
 
5891
 
 
5892
/*-------------------------------------------------------------------------
 
5893
 * Function:  H5T_conv_ulong_uint
 
5894
 *
 
5895
 * Purpose:  Converts `unsigned long' to `unsigned int'
 
5896
 *
 
5897
 * Return:  Success:  non-negative
 
5898
 *
 
5899
 *    Failure:  negative
 
5900
 *
 
5901
 * Programmer:  Robb Matzke
 
5902
 *    Friday, November 13, 1998
 
5903
 *
 
5904
 * Modifications:
 
5905
 *
 
5906
 *-------------------------------------------------------------------------
 
5907
 */
 
5908
herr_t
 
5909
H5T_conv_ulong_uint(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
 
5910
        size_t nelmts, size_t buf_stride, size_t UNUSED bkg_stride,
 
5911
                    void *buf, void UNUSED *bkg, hid_t UNUSED dxpl_id)
 
5912
{
 
5913
    herr_t      ret_value=SUCCEED;       /* Return value */
 
5914
 
 
5915
    FUNC_ENTER_NOAPI(H5T_conv_ulong_uint, FAIL);
 
5916
 
 
5917
    H5T_CONV_Uu(ULONG, UINT, unsigned long, unsigned, -, UINT_MAX);
 
5918
 
 
5919
done:
 
5920
    FUNC_LEAVE_NOAPI(ret_value);
 
5921
}
 
5922
 
 
5923
 
 
5924
/*-------------------------------------------------------------------------
 
5925
 * Function:  H5T_conv_long_ulong
 
5926
 *
 
5927
 * Purpose:  Converts `long' to `unsigned long'
 
5928
 *
 
5929
 * Return:  Success:  non-negative
 
5930
 *
 
5931
 *    Failure:  negative
 
5932
 *
 
5933
 * Programmer:  Robb Matzke
 
5934
 *    Monday, November 16, 1998
 
5935
 *
 
5936
 * Modifications:
 
5937
 *
 
5938
 *-------------------------------------------------------------------------
 
5939
 */
 
5940
herr_t
 
5941
H5T_conv_long_ulong(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
 
5942
        size_t nelmts, size_t buf_stride, size_t UNUSED bkg_stride,
 
5943
                    void *buf, void UNUSED *bkg, hid_t UNUSED dxpl_id)
 
5944
{
 
5945
    herr_t      ret_value=SUCCEED;       /* Return value */
 
5946
 
 
5947
    FUNC_ENTER_NOAPI(H5T_conv_long_ulong, FAIL);
 
5948
 
 
5949
    H5T_CONV_su(LONG, ULONG, long, unsigned long, -, -);
 
5950
 
 
5951
done:
 
5952
    FUNC_LEAVE_NOAPI(ret_value);
 
5953
}
 
5954
 
 
5955
 
 
5956
/*-------------------------------------------------------------------------
 
5957
 * Function:  H5T_conv_ulong_long
 
5958
 *
 
5959
 * Purpose:  Converts `unsigned long' to `long'
 
5960
 *
 
5961
 * Return:  Success:  non-negative
 
5962
 *
 
5963
 *    Failure:  negative
 
5964
 *
 
5965
 * Programmer:  Robb Matzke
 
5966
 *    Monday, November 16, 1998
 
5967
 *
 
5968
 * Modifications:
 
5969
 *
 
5970
 *-------------------------------------------------------------------------
 
5971
 */
 
5972
herr_t
 
5973
H5T_conv_ulong_long(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
 
5974
        size_t nelmts, size_t buf_stride, size_t UNUSED bkg_stride,
 
5975
                    void *buf, void UNUSED *bkg, hid_t UNUSED dxpl_id)
 
5976
{
 
5977
    herr_t      ret_value=SUCCEED;       /* Return value */
 
5978
 
 
5979
    FUNC_ENTER_NOAPI(H5T_conv_ulong_long, FAIL);
 
5980
 
 
5981
    H5T_CONV_us(ULONG, LONG, unsigned long, long, -, LONG_MAX);
 
5982
 
 
5983
done:
 
5984
    FUNC_LEAVE_NOAPI(ret_value);
 
5985
}
 
5986
 
 
5987
 
 
5988
/*-------------------------------------------------------------------------
 
5989
 * Function:  H5T_conv_long_llong
 
5990
 *
 
5991
 * Purpose:  Converts `long' to `long_long'
 
5992
 *
 
5993
 * Return:  Success:  Non-negative
 
5994
 *
 
5995
 *    Failure:  Negative
 
5996
 *
 
5997
 * Programmer:  Robb Matzke
 
5998
 *    Friday, November 13, 1998
 
5999
 *
 
6000
 * Modifications:
 
6001
 *
 
6002
 *-------------------------------------------------------------------------
 
6003
 */
 
6004
herr_t
 
6005
H5T_conv_long_llong(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
 
6006
        size_t nelmts, size_t buf_stride, size_t UNUSED bkg_stride,
 
6007
                    void *buf, void UNUSED *bkg, hid_t UNUSED dxpl_id)
 
6008
{
 
6009
    herr_t      ret_value=SUCCEED;       /* Return value */
 
6010
 
 
6011
    FUNC_ENTER_NOAPI(H5T_conv_long_llong, FAIL);
 
6012
 
 
6013
    H5T_CONV_sS(LONG, LLONG, long, long_long, -, -);
 
6014
 
 
6015
done:
 
6016
    FUNC_LEAVE_NOAPI(ret_value);
 
6017
}
 
6018
 
 
6019
 
 
6020
/*-------------------------------------------------------------------------
 
6021
 * Function:  H5T_conv_long_ullong
 
6022
 *
 
6023
 * Purpose:  Converts `long' to `unsigned long_long'
 
6024
 *
 
6025
 * Return:  Success:  Non-negative
 
6026
 *
 
6027
 *    Failure:  Negative
 
6028
 *
 
6029
 * Programmer:  Robb Matzke
 
6030
 *    Friday, November 13, 1998
 
6031
 *
 
6032
 * Modifications:
 
6033
 *
 
6034
 *-------------------------------------------------------------------------
 
6035
 */
 
6036
herr_t
 
6037
H5T_conv_long_ullong(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
 
6038
         size_t nelmts, size_t buf_stride,
 
6039
                     size_t UNUSED bkg_stride, void *buf, void UNUSED *bkg,
 
6040
         hid_t UNUSED dxpl_id)
 
6041
{
 
6042
    herr_t      ret_value=SUCCEED;       /* Return value */
 
6043
 
 
6044
    FUNC_ENTER_NOAPI(H5T_conv_long_ullong, FAIL);
 
6045
 
 
6046
    H5T_CONV_sU(LONG, ULLONG, long, unsigned long_long, -, -);
 
6047
 
 
6048
done:
 
6049
    FUNC_LEAVE_NOAPI(ret_value);
 
6050
}
 
6051
 
 
6052
 
 
6053
/*-------------------------------------------------------------------------
 
6054
 * Function:  H5T_conv_ulong_llong
 
6055
 *
 
6056
 * Purpose:  Converts `unsigned long' to `long_long'
 
6057
 *
 
6058
 * Return:  Success:  Non-negative
 
6059
 *
 
6060
 *    Failure:  Negative
 
6061
 *
 
6062
 * Programmer:  Robb Matzke
 
6063
 *    Friday, November 13, 1998
 
6064
 *
 
6065
 * Modifications:
 
6066
 *
 
6067
 *-------------------------------------------------------------------------
 
6068
 */
 
6069
herr_t
 
6070
H5T_conv_ulong_llong(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
 
6071
         size_t nelmts, size_t buf_stride,
 
6072
                     size_t UNUSED bkg_stride, void *buf, void UNUSED *bkg,
 
6073
         hid_t UNUSED dxpl_id)
 
6074
{
 
6075
    herr_t      ret_value=SUCCEED;       /* Return value */
 
6076
 
 
6077
    FUNC_ENTER_NOAPI(H5T_conv_ulong_llong, FAIL);
 
6078
 
 
6079
    H5T_CONV_uS(ULONG, LLONG, unsigned long, long_long, -, LLONG_MAX);
 
6080
 
 
6081
done:
 
6082
    FUNC_LEAVE_NOAPI(ret_value);
 
6083
}
 
6084
 
 
6085
 
 
6086
/*-------------------------------------------------------------------------
 
6087
 * Function:  H5T_conv_ulong_ullong
 
6088
 *
 
6089
 * Purpose:  Converts `unsigned long' to `unsigned long_long'
 
6090
 *
 
6091
 * Return:  Success:  Non-negative
 
6092
 *
 
6093
 *    Failure:  Negative
 
6094
 *
 
6095
 * Programmer:  Robb Matzke
 
6096
 *    Friday, November 13, 1998
 
6097
 *
 
6098
 * Modifications:
 
6099
 *
 
6100
 *-------------------------------------------------------------------------
 
6101
 */
 
6102
herr_t
 
6103
H5T_conv_ulong_ullong(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
 
6104
          size_t nelmts, size_t buf_stride,
 
6105
                      size_t UNUSED bkg_stride, void *buf, void UNUSED *bkg,
 
6106
                      hid_t UNUSED dxpl_id)
 
6107
{
 
6108
    herr_t      ret_value=SUCCEED;       /* Return value */
 
6109
 
 
6110
    FUNC_ENTER_NOAPI(H5T_conv_ulong_ullong, FAIL);
 
6111
 
 
6112
    H5T_CONV_uU(ULONG, ULLONG, unsigned long, unsigned long_long, -, -);
 
6113
 
 
6114
done:
 
6115
    FUNC_LEAVE_NOAPI(ret_value);
 
6116
}
 
6117
 
 
6118
 
 
6119
/*-------------------------------------------------------------------------
 
6120
 * Function:  H5T_conv_llong_schar
 
6121
 *
 
6122
 * Purpose:  Converts `long_long' to `signed char'
 
6123
 *
 
6124
 * Return:  Success:  Non-negative
 
6125
 *
 
6126
 *    Failure:  Negative
 
6127
 *
 
6128
 * Programmer:  Robb Matzke
 
6129
 *    Friday, November 13, 1998
 
6130
 *
 
6131
 * Modifications:
 
6132
 *
 
6133
 *-------------------------------------------------------------------------
 
6134
 */
 
6135
herr_t
 
6136
H5T_conv_llong_schar(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
 
6137
         size_t nelmts, size_t buf_stride,
 
6138
                     size_t UNUSED bkg_stride, void *buf, void UNUSED *bkg,
 
6139
         hid_t UNUSED dxpl_id)
 
6140
{
 
6141
    herr_t      ret_value=SUCCEED;       /* Return value */
 
6142
 
 
6143
    FUNC_ENTER_NOAPI(H5T_conv_llong_schar, FAIL);
 
6144
 
 
6145
    H5T_CONV_Ss(LLONG, SCHAR, long_long, signed char, SCHAR_MIN, SCHAR_MAX);
 
6146
 
 
6147
done:
 
6148
    FUNC_LEAVE_NOAPI(ret_value);
 
6149
}
 
6150
 
 
6151
 
 
6152
/*-------------------------------------------------------------------------
 
6153
 * Function:  H5T_conv_llong_uchar
 
6154
 *
 
6155
 * Purpose:  Converts `long_long' to `unsigned char'
 
6156
 *
 
6157
 * Return:  Success:  Non-negative
 
6158
 *
 
6159
 *    Failure:  Negative
 
6160
 *
 
6161
 * Programmer:  Robb Matzke
 
6162
 *    Friday, November 13, 1998
 
6163
 *
 
6164
 * Modifications:
 
6165
 *
 
6166
 *-------------------------------------------------------------------------
 
6167
 */
 
6168
herr_t
 
6169
H5T_conv_llong_uchar(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
 
6170
         size_t nelmts, size_t buf_stride,
 
6171
                     size_t UNUSED bkg_stride, void *buf, void UNUSED *bkg,
 
6172
         hid_t UNUSED dxpl_id)
 
6173
{
 
6174
    herr_t      ret_value=SUCCEED;       /* Return value */
 
6175
 
 
6176
    FUNC_ENTER_NOAPI(H5T_conv_llong_uchar, FAIL);
 
6177
 
 
6178
    H5T_CONV_Su(LLONG, UCHAR, long_long, unsigned char, -, UCHAR_MAX);
 
6179
 
 
6180
done:
 
6181
    FUNC_LEAVE_NOAPI(ret_value);
 
6182
}
 
6183
 
 
6184
 
 
6185
/*-------------------------------------------------------------------------
 
6186
 * Function:  H5T_conv_ullong_schar
 
6187
 *
 
6188
 * Purpose:  Converts `unsigned long_long' to `signed char'
 
6189
 *
 
6190
 * Return:  Success:  Non-negative
 
6191
 *
 
6192
 *    Failure:  Negative
 
6193
 *
 
6194
 * Programmer:  Robb Matzke
 
6195
 *    Friday, November 13, 1998
 
6196
 *
 
6197
 * Modifications:
 
6198
 *
 
6199
 *-------------------------------------------------------------------------
 
6200
 */
 
6201
herr_t
 
6202
H5T_conv_ullong_schar(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
 
6203
          size_t nelmts, size_t buf_stride,
 
6204
                      size_t UNUSED bkg_stride, void *buf, void UNUSED *bkg,
 
6205
                      hid_t UNUSED dxpl_id)
 
6206
{
 
6207
    herr_t      ret_value=SUCCEED;       /* Return value */
 
6208
 
 
6209
    FUNC_ENTER_NOAPI(H5T_conv_ullong_schar, FAIL);
 
6210
 
 
6211
    H5T_CONV_Us(ULLONG, SCHAR, unsigned long_long, signed char, -, SCHAR_MAX);
 
6212
 
 
6213
done:
 
6214
    FUNC_LEAVE_NOAPI(ret_value);
 
6215
}
 
6216
 
 
6217
 
 
6218
/*-------------------------------------------------------------------------
 
6219
 * Function:  H5T_conv_ullong_uchar
 
6220
 *
 
6221
 * Purpose:  Converts `unsigned long_long' to `unsigned char'
 
6222
 *
 
6223
 * Return:  Success:  Non-negative
 
6224
 *
 
6225
 *    Failure:  Negative
 
6226
 *
 
6227
 * Programmer:  Robb Matzke
 
6228
 *    Friday, November 13, 1998
 
6229
 *
 
6230
 * Modifications:
 
6231
 *
 
6232
 *-------------------------------------------------------------------------
 
6233
 */
 
6234
herr_t
 
6235
H5T_conv_ullong_uchar(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
 
6236
                      size_t nelmts, size_t buf_stride,
 
6237
                      size_t UNUSED bkg_stride, void *buf, void UNUSED *bkg,
 
6238
                      hid_t UNUSED dxpl_id)
 
6239
{
 
6240
    herr_t      ret_value=SUCCEED;       /* Return value */
 
6241
 
 
6242
    FUNC_ENTER_NOAPI(H5T_conv_ullong_uchar, FAIL);
 
6243
 
 
6244
    H5T_CONV_Uu(ULLONG, UCHAR, unsigned long_long, unsigned char, -, UCHAR_MAX);
 
6245
 
 
6246
done:
 
6247
    FUNC_LEAVE_NOAPI(ret_value);
 
6248
}
 
6249
 
 
6250
 
 
6251
/*-------------------------------------------------------------------------
 
6252
 * Function:  H5T_conv_llong_short
 
6253
 *
 
6254
 * Purpose:  Converts `long_long' to `short'
 
6255
 *
 
6256
 * Return:  Success:  Non-negative
 
6257
 *
 
6258
 *    Failure:  Negative
 
6259
 *
 
6260
 * Programmer:  Robb Matzke
 
6261
 *    Friday, November 13, 1998
 
6262
 *
 
6263
 * Modifications:
 
6264
 *
 
6265
 *-------------------------------------------------------------------------
 
6266
 */
 
6267
herr_t
 
6268
H5T_conv_llong_short(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
 
6269
         size_t nelmts, size_t buf_stride,
 
6270
                     size_t UNUSED bkg_stride, void *buf, void UNUSED *bkg,
 
6271
         hid_t UNUSED dxpl_id)
 
6272
{
 
6273
    herr_t      ret_value=SUCCEED;       /* Return value */
 
6274
 
 
6275
    FUNC_ENTER_NOAPI(H5T_conv_llong_short, FAIL);
 
6276
 
 
6277
    H5T_CONV_Ss(LLONG, SHORT, long_long, short, SHRT_MIN, SHRT_MAX);
 
6278
 
 
6279
done:
 
6280
    FUNC_LEAVE_NOAPI(ret_value);
 
6281
}
 
6282
 
 
6283
 
 
6284
/*-------------------------------------------------------------------------
 
6285
 * Function:  H5T_conv_llong_ushort
 
6286
 *
 
6287
 * Purpose:  Converts `long_long' to `unsigned short'
 
6288
 *
 
6289
 * Return:  Success:  Non-negative
 
6290
 *
 
6291
 *    Failure:  Negative
 
6292
 *
 
6293
 * Programmer:  Robb Matzke
 
6294
 *    Friday, November 13, 1998
 
6295
 *
 
6296
 * Modifications:
 
6297
 *
 
6298
 *-------------------------------------------------------------------------
 
6299
 */
 
6300
herr_t
 
6301
H5T_conv_llong_ushort(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
 
6302
          size_t nelmts, size_t buf_stride,
 
6303
                      size_t UNUSED bkg_stride, void *buf, void UNUSED *bkg,
 
6304
                      hid_t UNUSED dxpl_id)
 
6305
{
 
6306
    herr_t      ret_value=SUCCEED;       /* Return value */
 
6307
 
 
6308
    FUNC_ENTER_NOAPI(H5T_conv_llong_ushort, FAIL);
 
6309
 
 
6310
    H5T_CONV_Su(LLONG, USHORT, long_long, unsigned short, -, USHRT_MAX);
 
6311
 
 
6312
done:
 
6313
    FUNC_LEAVE_NOAPI(ret_value);
 
6314
}
 
6315
 
 
6316
 
 
6317
/*-------------------------------------------------------------------------
 
6318
 * Function:  H5T_conv_ullong_short
 
6319
 *
 
6320
 * Purpose:  Converts `unsigned long_long' to `short'
 
6321
 *
 
6322
 * Return:  Success:  Non-negative
 
6323
 *
 
6324
 *    Failure:  Negative
 
6325
 *
 
6326
 * Programmer:  Robb Matzke
 
6327
 *    Friday, November 13, 1998
 
6328
 *
 
6329
 * Modifications:
 
6330
 *
 
6331
 *-------------------------------------------------------------------------
 
6332
 */
 
6333
herr_t
 
6334
H5T_conv_ullong_short(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
 
6335
          size_t nelmts, size_t buf_stride,
 
6336
                      size_t UNUSED bkg_stride, void *buf, void UNUSED *bkg,
 
6337
                      hid_t UNUSED dxpl_id)
 
6338
{
 
6339
    herr_t      ret_value=SUCCEED;       /* Return value */
 
6340
 
 
6341
    FUNC_ENTER_NOAPI(H5T_conv_ullong_short, FAIL);
 
6342
 
 
6343
    H5T_CONV_Us(ULLONG, SHORT, unsigned long_long, short, -, SHRT_MAX);
 
6344
 
 
6345
done:
 
6346
    FUNC_LEAVE_NOAPI(ret_value);
 
6347
}
 
6348
 
 
6349
 
 
6350
/*-------------------------------------------------------------------------
 
6351
 * Function:  H5T_conv_ullong_ushort
 
6352
 *
 
6353
 * Purpose:  Converts `unsigned long_long' to `unsigned short'
 
6354
 *
 
6355
 * Return:  Success:  Non-negative
 
6356
 *
 
6357
 *    Failure:  Negative
 
6358
 *
 
6359
 * Programmer:  Robb Matzke
 
6360
 *    Friday, November 13, 1998
 
6361
 *
 
6362
 * Modifications:
 
6363
 *
 
6364
 *-------------------------------------------------------------------------
 
6365
 */
 
6366
herr_t
 
6367
H5T_conv_ullong_ushort(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
 
6368
           size_t nelmts, size_t buf_stride,
 
6369
                       size_t UNUSED bkg_stride, void *buf, void UNUSED *bkg,
 
6370
                       hid_t UNUSED dxpl_id)
 
6371
{
 
6372
    herr_t      ret_value=SUCCEED;       /* Return value */
 
6373
 
 
6374
    FUNC_ENTER_NOAPI(H5T_conv_ullong_ushort, FAIL);
 
6375
 
 
6376
    H5T_CONV_Uu(ULLONG, USHORT, unsigned long_long, unsigned short, -, USHRT_MAX);
 
6377
 
 
6378
done:
 
6379
    FUNC_LEAVE_NOAPI(ret_value);
 
6380
}
 
6381
 
 
6382
 
 
6383
/*-------------------------------------------------------------------------
 
6384
 * Function:  H5T_conv_llong_int
 
6385
 *
 
6386
 * Purpose:  Converts `long_long' to `int'
 
6387
 *
 
6388
 * Return:  Success:  Non-negative
 
6389
 *
 
6390
 *    Failure:  Negative
 
6391
 *
 
6392
 * Programmer:  Robb Matzke
 
6393
 *    Friday, November 13, 1998
 
6394
 *
 
6395
 * Modifications:
 
6396
 *
 
6397
 *-------------------------------------------------------------------------
 
6398
 */
 
6399
herr_t
 
6400
H5T_conv_llong_int(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
 
6401
       size_t nelmts, size_t buf_stride, size_t UNUSED bkg_stride,
 
6402
                   void *buf, void UNUSED *bkg, hid_t UNUSED dxpl_id)
 
6403
{
 
6404
    herr_t      ret_value=SUCCEED;       /* Return value */
 
6405
 
 
6406
    FUNC_ENTER_NOAPI(H5T_conv_llong_int, FAIL);
 
6407
 
 
6408
    H5T_CONV_Ss(LLONG, INT, long_long, int, INT_MIN, INT_MAX);
 
6409
 
 
6410
done:
 
6411
    FUNC_LEAVE_NOAPI(ret_value);
 
6412
}
 
6413
 
 
6414
 
 
6415
/*-------------------------------------------------------------------------
 
6416
 * Function:  H5T_conv_llong_uint
 
6417
 *
 
6418
 * Purpose:  Converts `long_long' to `unsigned int'
 
6419
 *
 
6420
 * Return:  Success:  Non-negative
 
6421
 *
 
6422
 *    Failure:  Negative
 
6423
 *
 
6424
 * Programmer:  Robb Matzke
 
6425
 *    Friday, November 13, 1998
 
6426
 *
 
6427
 * Modifications:
 
6428
 *
 
6429
 *-------------------------------------------------------------------------
 
6430
 */
 
6431
herr_t
 
6432
H5T_conv_llong_uint(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
 
6433
        size_t nelmts, size_t buf_stride, size_t UNUSED bkg_stride,
 
6434
                    void *buf, void UNUSED *bkg, hid_t UNUSED dxpl_id)
 
6435
{
 
6436
    herr_t      ret_value=SUCCEED;       /* Return value */
 
6437
 
 
6438
    FUNC_ENTER_NOAPI(H5T_conv_llong_uint, FAIL);
 
6439
 
 
6440
    H5T_CONV_Su(LLONG, UINT, long_long, unsigned, -, UINT_MAX);
 
6441
 
 
6442
done:
 
6443
    FUNC_LEAVE_NOAPI(ret_value);
 
6444
}
 
6445
 
 
6446
 
 
6447
/*-------------------------------------------------------------------------
 
6448
 * Function:  H5T_conv_ullong_int
 
6449
 *
 
6450
 * Purpose:  Converts `unsigned long_long' to `int'
 
6451
 *
 
6452
 * Return:  Success:  Non-negative
 
6453
 *
 
6454
 *    Failure:  Negative
 
6455
 *
 
6456
 * Programmer:  Robb Matzke
 
6457
 *    Friday, November 13, 1998
 
6458
 *
 
6459
 * Modifications:
 
6460
 *
 
6461
 *-------------------------------------------------------------------------
 
6462
 */
 
6463
herr_t
 
6464
H5T_conv_ullong_int(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
 
6465
        size_t nelmts, size_t buf_stride, size_t UNUSED bkg_stride,
 
6466
                    void *buf, void UNUSED *bkg, hid_t UNUSED dxpl_id)
 
6467
{
 
6468
    herr_t      ret_value=SUCCEED;       /* Return value */
 
6469
 
 
6470
    FUNC_ENTER_NOAPI(H5T_conv_ullong_int, FAIL);
 
6471
 
 
6472
    H5T_CONV_Us(ULLONG, INT, unsigned long_long, int, -, INT_MAX);
 
6473
 
 
6474
done:
 
6475
    FUNC_LEAVE_NOAPI(ret_value);
 
6476
}
 
6477
 
 
6478
 
 
6479
/*-------------------------------------------------------------------------
 
6480
 * Function:  H5T_conv_ullong_uint
 
6481
 *
 
6482
 * Purpose:  Converts `unsigned long_long' to `unsigned int'
 
6483
 *
 
6484
 * Return:  Success:  Non-negative
 
6485
 *
 
6486
 *    Failure:  Negative
 
6487
 *
 
6488
 * Programmer:  Robb Matzke
 
6489
 *    Friday, November 13, 1998
 
6490
 *
 
6491
 * Modifications:
 
6492
 *
 
6493
 *-------------------------------------------------------------------------
 
6494
 */
 
6495
herr_t
 
6496
H5T_conv_ullong_uint(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
 
6497
         size_t nelmts, size_t buf_stride,
 
6498
                     size_t UNUSED bkg_stride, void *buf, void UNUSED *bkg,
 
6499
         hid_t UNUSED dxpl_id)
 
6500
{
 
6501
    herr_t      ret_value=SUCCEED;       /* Return value */
 
6502
 
 
6503
    FUNC_ENTER_NOAPI(H5T_conv_ullong_uint, FAIL);
 
6504
 
 
6505
    H5T_CONV_Uu(ULLONG, UINT, unsigned long_long, unsigned, -, UINT_MAX);
 
6506
 
 
6507
done:
 
6508
    FUNC_LEAVE_NOAPI(ret_value);
 
6509
}
 
6510
 
 
6511
 
 
6512
/*-------------------------------------------------------------------------
 
6513
 * Function:  H5T_conv_llong_long
 
6514
 *
 
6515
 * Purpose:  Converts `long_long' to `long'
 
6516
 *
 
6517
 * Return:  Success:  Non-negative
 
6518
 *
 
6519
 *    Failure:  Negative
 
6520
 *
 
6521
 * Programmer:  Robb Matzke
 
6522
 *    Friday, November 13, 1998
 
6523
 *
 
6524
 * Modifications:
 
6525
 *
 
6526
 *-------------------------------------------------------------------------
 
6527
 */
 
6528
herr_t
 
6529
H5T_conv_llong_long(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
 
6530
        size_t nelmts, size_t buf_stride, size_t UNUSED bkg_stride,
 
6531
                    void *buf, void UNUSED *bkg, hid_t UNUSED dxpl_id)
 
6532
{
 
6533
    herr_t      ret_value=SUCCEED;       /* Return value */
 
6534
 
 
6535
    FUNC_ENTER_NOAPI(H5T_conv_llong_long, FAIL);
 
6536
 
 
6537
    H5T_CONV_Ss(LLONG, LONG, long_long, long, LONG_MIN, LONG_MAX);
 
6538
 
 
6539
done:
 
6540
    FUNC_LEAVE_NOAPI(ret_value);
 
6541
}
 
6542
 
 
6543
 
 
6544
/*-------------------------------------------------------------------------
 
6545
 * Function:  H5T_conv_llong_ulong
 
6546
 *
 
6547
 * Purpose:  Converts `long_long' to `unsigned long'
 
6548
 *
 
6549
 * Return:  Success:  Non-negative
 
6550
 *
 
6551
 *    Failure:  Negative
 
6552
 *
 
6553
 * Programmer:  Robb Matzke
 
6554
 *    Friday, November 13, 1998
 
6555
 *
 
6556
 * Modifications:
 
6557
 *
 
6558
 *-------------------------------------------------------------------------
 
6559
 */
 
6560
herr_t
 
6561
H5T_conv_llong_ulong(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
 
6562
         size_t nelmts, size_t buf_stride,
 
6563
                     size_t UNUSED bkg_stride, void *buf, void UNUSED *bkg,
 
6564
         hid_t UNUSED dxpl_id)
 
6565
{
 
6566
    herr_t      ret_value=SUCCEED;       /* Return value */
 
6567
 
 
6568
    FUNC_ENTER_NOAPI(H5T_conv_llong_ulong, FAIL);
 
6569
 
 
6570
    H5T_CONV_Su(LLONG, ULONG, long_long, unsigned long, -, ULONG_MAX);
 
6571
 
 
6572
done:
 
6573
    FUNC_LEAVE_NOAPI(ret_value);
 
6574
}
 
6575
 
 
6576
 
 
6577
/*-------------------------------------------------------------------------
 
6578
 * Function:  H5T_conv_ullong_long
 
6579
 *
 
6580
 * Purpose:  Converts `unsigned long_long' to `long'
 
6581
 *
 
6582
 * Return:  Success:  Non-negative
 
6583
 *
 
6584
 *    Failure:  Negative
 
6585
 *
 
6586
 * Programmer:  Robb Matzke
 
6587
 *    Friday, November 13, 1998
 
6588
 *
 
6589
 * Modifications:
 
6590
 *
 
6591
 *-------------------------------------------------------------------------
 
6592
 */
 
6593
herr_t
 
6594
H5T_conv_ullong_long(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
 
6595
         size_t nelmts, size_t buf_stride,
 
6596
                     size_t UNUSED bkg_stride, void *buf, void UNUSED *bkg,
 
6597
         hid_t UNUSED dxpl_id)
 
6598
{
 
6599
    herr_t      ret_value=SUCCEED;       /* Return value */
 
6600
 
 
6601
    FUNC_ENTER_NOAPI(H5T_conv_ullong_long, FAIL);
 
6602
 
 
6603
    H5T_CONV_Us(ULLONG, LONG, unsigned long_long, long, -, LONG_MAX);
 
6604
 
 
6605
done:
 
6606
    FUNC_LEAVE_NOAPI(ret_value);
 
6607
}
 
6608
 
 
6609
 
 
6610
/*-------------------------------------------------------------------------
 
6611
 * Function:  H5T_conv_ullong_ulong
 
6612
 *
 
6613
 * Purpose:  Converts `unsigned long_long' to `unsigned long'
 
6614
 *
 
6615
 * Return:  Success:  Non-negative
 
6616
 *
 
6617
 *    Failure:  Negative
 
6618
 *
 
6619
 * Programmer:  Robb Matzke
 
6620
 *    Friday, November 13, 1998
 
6621
 *
 
6622
 * Modifications:
 
6623
 *
 
6624
 *-------------------------------------------------------------------------
 
6625
 */
 
6626
herr_t
 
6627
H5T_conv_ullong_ulong(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
 
6628
          size_t nelmts, size_t buf_stride,
 
6629
                      size_t UNUSED bkg_stride, void *buf, void UNUSED *bkg,
 
6630
                      hid_t UNUSED dxpl_id)
 
6631
{
 
6632
    herr_t      ret_value=SUCCEED;       /* Return value */
 
6633
 
 
6634
    FUNC_ENTER_NOAPI(H5T_conv_ullong_ulong, FAIL);
 
6635
 
 
6636
    H5T_CONV_Uu(ULLONG, ULONG, unsigned long_long, unsigned long, -, ULONG_MAX);
 
6637
 
 
6638
done:
 
6639
    FUNC_LEAVE_NOAPI(ret_value);
 
6640
}
 
6641
 
 
6642
 
 
6643
/*-------------------------------------------------------------------------
 
6644
 * Function:  H5T_conv_llong_ullong
 
6645
 *
 
6646
 * Purpose:  Converts `long_long' to `unsigned long_long'
 
6647
 *
 
6648
 * Return:  Success:  non-negative
 
6649
 *
 
6650
 *    Failure:  negative
 
6651
 *
 
6652
 * Programmer:  Robb Matzke
 
6653
 *    Monday, November 16, 1998
 
6654
 *
 
6655
 * Modifications:
 
6656
 *
 
6657
 *-------------------------------------------------------------------------
 
6658
 */
 
6659
herr_t
 
6660
H5T_conv_llong_ullong(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
 
6661
          size_t nelmts, size_t buf_stride,
 
6662
                      size_t UNUSED bkg_stride, void *buf, void UNUSED *bkg,
 
6663
                      hid_t UNUSED dxpl_id)
 
6664
{
 
6665
    herr_t      ret_value=SUCCEED;       /* Return value */
 
6666
 
 
6667
    FUNC_ENTER_NOAPI(H5T_conv_llong_ullong, FAIL);
 
6668
 
 
6669
    H5T_CONV_su(LLONG, ULLONG, long_long, unsigned long_long, -, -);
 
6670
 
 
6671
done:
 
6672
    FUNC_LEAVE_NOAPI(ret_value);
 
6673
}
 
6674
 
 
6675
 
 
6676
/*-------------------------------------------------------------------------
 
6677
 * Function:  H5T_conv_ullong_llong
 
6678
 *
 
6679
 * Purpose:  Converts `unsigned long_long' to `long_long'
 
6680
 *
 
6681
 * Return:  Success:  non-negative
 
6682
 *
 
6683
 *    Failure:  negative
 
6684
 *
 
6685
 * Programmer:  Robb Matzke
 
6686
 *    Monday, November 16, 1998
 
6687
 *
 
6688
 * Modifications:
 
6689
 *
 
6690
 *-------------------------------------------------------------------------
 
6691
 */
 
6692
herr_t
 
6693
H5T_conv_ullong_llong(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
 
6694
          size_t nelmts, size_t buf_stride,
 
6695
                      size_t UNUSED bkg_stride, void *buf, void UNUSED *bkg,
 
6696
                      hid_t UNUSED dxpl_id)
 
6697
{
 
6698
    herr_t      ret_value=SUCCEED;       /* Return value */
 
6699
 
 
6700
    FUNC_ENTER_NOAPI(H5T_conv_ullong_llong, FAIL);
 
6701
 
 
6702
    H5T_CONV_us(ULLONG, LLONG, unsigned long_long, long_long, -, LLONG_MAX);
 
6703
 
 
6704
done:
 
6705
    FUNC_LEAVE_NOAPI(ret_value);
 
6706
}
 
6707
 
 
6708
 
 
6709
/*-------------------------------------------------------------------------
 
6710
 * Function:  H5T_conv_float_double
 
6711
 *
 
6712
 * Purpose:  Convert native `float' to native `double' using hardware.
 
6713
 *    This is a fast special case.
 
6714
 *
 
6715
 * Return:  Non-negative on success/Negative on failure
 
6716
 *
 
6717
 * Programmer:  Robb Matzke
 
6718
 *    Tuesday, June 23, 1998
 
6719
 *
 
6720
 * Modifications:
 
6721
 *    Robb Matzke, 1999-06-16
 
6722
 *    Added support for non-zero strides. If BUF_STRIDE is non-zero
 
6723
 *    then convert one value at each memory location advancing
 
6724
 *    BUF_STRIDE bytes each time; otherwise assume both source and
 
6725
 *    destination values are packed.
 
6726
 *-------------------------------------------------------------------------
 
6727
 */
 
6728
herr_t
 
6729
H5T_conv_float_double (hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
 
6730
           size_t nelmts, size_t buf_stride,
 
6731
                       size_t UNUSED bkg_stride, void *buf, void UNUSED *bkg,
 
6732
                       hid_t UNUSED dxpl_id)
 
6733
{
 
6734
    herr_t      ret_value=SUCCEED;       /* Return value */
 
6735
 
 
6736
    FUNC_ENTER_NOAPI(H5T_conv_float_double, FAIL);
 
6737
 
 
6738
    H5T_CONV_fF(FLOAT, DOUBLE, float, double, -, -);
 
6739
 
 
6740
done:
 
6741
    FUNC_LEAVE_NOAPI(ret_value);
 
6742
}
 
6743
 
 
6744
 
 
6745
/*-------------------------------------------------------------------------
 
6746
 * Function:  H5T_conv_double_float
 
6747
 *
 
6748
 * Purpose:  Convert native `double' to native `float' using hardware.
 
6749
 *    This is a fast special case.
 
6750
 *
 
6751
 * Return:  Non-negative on success/Negative on failure
 
6752
 *
 
6753
 * Programmer:  Robb Matzke
 
6754
 *    Tuesday, June 23, 1998
 
6755
 *
 
6756
 * Modifications:
 
6757
 *    Robb Matzke, 7 Jul 1998
 
6758
 *    Added overflow handling.
 
6759
 *
 
6760
 *    Robb Matzke, 1999-06-16
 
6761
 *    Added support for non-zero strides. If BUF_STRIDE is non-zero
 
6762
 *    then convert one value at each memory location advancing
 
6763
 *    BUF_STRIDE bytes each time; otherwise assume both source and
 
6764
 *    destination values are packed.
 
6765
 *-------------------------------------------------------------------------
 
6766
 */
 
6767
herr_t
 
6768
H5T_conv_double_float (hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
 
6769
           size_t nelmts, size_t buf_stride,
 
6770
                       size_t UNUSED bkg_stride, void *buf, void UNUSED *bkg,
 
6771
                       hid_t UNUSED dxpl_id)
 
6772
{
 
6773
    herr_t      ret_value=SUCCEED;       /* Return value */
 
6774
 
 
6775
    FUNC_ENTER_NOAPI(H5T_conv_double_float, FAIL);
 
6776
 
 
6777
    H5T_CONV_Ff(DOUBLE, FLOAT, double, float, -FLT_MAX, FLT_MAX);
 
6778
 
 
6779
done:
 
6780
    FUNC_LEAVE_NOAPI(ret_value);
 
6781
}
 
6782
 
 
6783
 
 
6784
/*-------------------------------------------------------------------------
 
6785
 * Function:  H5T_conv_i32le_f64le
 
6786
 *
 
6787
 * Purpose:  Converts 4-byte little-endian integers (signed or unsigned)
 
6788
 *    to 8-byte litte-endian IEEE floating point.
 
6789
 *
 
6790
 * Return:  Non-negative on success/Negative on failure
 
6791
 *
 
6792
 *
 
6793
 * Programmer:  Robb Matzke
 
6794
 *    Wednesday, June 10, 1998
 
6795
 *
 
6796
 * Modifications:
 
6797
 *    Robb Matzke, 1999-06-16
 
6798
 *    Added support for non-zero strides. If BUF_STRIDE is non-zero
 
6799
 *    then convert one value at each memory location advancing
 
6800
 *    BUF_STRIDE bytes each time; otherwise assume both source and
 
6801
 *    destination values are packed.
 
6802
 *-------------------------------------------------------------------------
 
6803
 */
 
6804
herr_t
 
6805
H5T_conv_i32le_f64le (hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
 
6806
          size_t nelmts, size_t buf_stride,
 
6807
                      size_t UNUSED bkg_stride, void *buf, void UNUSED *bkg,
 
6808
                      hid_t UNUSED dxpl_id)
 
6809
{
 
6810
    uint8_t  *s=NULL, *d=NULL;  /*src and dst buf pointers  */
 
6811
    uint8_t  tmp[8];      /*temporary destination buffer  */
 
6812
    H5T_t  *src = NULL;    /*source data type    */
 
6813
    size_t  elmtno;      /*element counter    */
 
6814
    unsigned  sign;      /*sign bit      */
 
6815
    unsigned  cin, cout;    /*carry in/out      */
 
6816
    unsigned  mbits=0;    /*mantissa bits      */
 
6817
    unsigned  exponent;    /*exponent      */
 
6818
    int  i;      /*counter      */
 
6819
    herr_t      ret_value=SUCCEED;       /* Return value */
 
6820
 
 
6821
    FUNC_ENTER_NOAPI(H5T_conv_i32le_f64le, FAIL);
 
6822
 
 
6823
    switch (cdata->command) {
 
6824
        case H5T_CONV_INIT:
 
6825
            assert (sizeof(int)>=4);
 
6826
            cdata->need_bkg = H5T_BKG_NO;
 
6827
            break;
 
6828
 
 
6829
        case H5T_CONV_FREE:
 
6830
            /* Free private data */
 
6831
            break;
 
6832
 
 
6833
        case H5T_CONV_CONV:
 
6834
            /* The conversion */
 
6835
            if (NULL==(src=H5I_object(src_id)) ||
 
6836
                    NULL==H5I_object(dst_id))
 
6837
                HGOTO_ERROR (H5E_ARGS, H5E_BADTYPE, FAIL, "not a data type");
 
6838
 
 
6839
            s = (uint8_t*)buf + (buf_stride?buf_stride:4)*(nelmts-1);
 
6840
            d = (uint8_t*)buf + (buf_stride?buf_stride:8)*(nelmts-1);
 
6841
            for (elmtno=0; elmtno<nelmts; elmtno++) {
 
6842
 
 
6843
                /*
 
6844
                 * If this is the last element to convert (that is, the first
 
6845
                 * element of the buffer) then the source and destination areas
 
6846
                 * overlap so we need to use a temp buf for the destination.
 
6847
                 */
 
6848
                if ((void*)s==buf)
 
6849
                    d = tmp;
 
6850
 
 
6851
                /* Convert the integer to a sign and magnitude */
 
6852
                switch (src->shared->u.atomic.u.i.sign) {
 
6853
                    case H5T_SGN_NONE:
 
6854
                        sign = 0;
 
6855
                        break;
 
6856
 
 
6857
                    case H5T_SGN_2:
 
6858
                        if (s[3] & 0x80) {
 
6859
                            sign = 1;
 
6860
                            for (i=0,cin=1; i<4; i++,cin=cout) {
 
6861
                                s[i] = ~s[i];
 
6862
                                cout = ((unsigned)(s[i])+cin > 0xff) ? 1 : 0;
 
6863
                                s[i] += cin;
 
6864
                            }
 
6865
                        } else {
 
6866
                            sign = 0;
 
6867
                        }
 
6868
                        break;
 
6869
 
 
6870
                    default:
 
6871
                        HGOTO_ERROR (H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, "unsupported integer sign method");
 
6872
                }
 
6873
 
 
6874
                /*
 
6875
                 * Where is the most significant bit that is set?  We could do
 
6876
                 * this in a loop, but testing it this way might be faster.
 
6877
                 */
 
6878
                if (s[3]) {
 
6879
                    if (s[3] & 0x80) mbits = 32;
 
6880
                    else if (s[3] & 0x40) mbits = 31;
 
6881
                    else if (s[3] & 0x20) mbits = 30;
 
6882
                    else if (s[3] & 0x10) mbits = 29;
 
6883
                    else if (s[3] & 0x08) mbits = 28;
 
6884
                    else if (s[3] & 0x04) mbits = 27;
 
6885
                    else if (s[3] & 0x02) mbits = 26;
 
6886
                    else if (s[3] & 0x01) mbits = 25;
 
6887
                } else if (s[2]) {
 
6888
                    if (s[2] & 0x80) mbits = 24;
 
6889
                    else if (s[2] & 0x40) mbits = 23;
 
6890
                    else if (s[2] & 0x20) mbits = 22;
 
6891
                    else if (s[2] & 0x10) mbits = 21;
 
6892
                    else if (s[2] & 0x08) mbits = 20;
 
6893
                    else if (s[2] & 0x04) mbits = 19;
 
6894
                    else if (s[2] & 0x02) mbits = 18;
 
6895
                    else if (s[2] & 0x01) mbits = 17;
 
6896
                } else if (s[1]) {
 
6897
                    if (s[1] & 0x80) mbits = 16;
 
6898
                    else if (s[1] & 0x40) mbits = 15;
 
6899
                    else if (s[1] & 0x20) mbits = 14;
 
6900
                    else if (s[1] & 0x10) mbits = 13;
 
6901
                    else if (s[1] & 0x08) mbits = 12;
 
6902
                    else if (s[1] & 0x04) mbits = 11;
 
6903
                    else if (s[1] & 0x02) mbits = 10;
 
6904
                    else if (s[1] & 0x01) mbits =  9;
 
6905
                } else if (s[0]) {
 
6906
                    if (s[0] & 0x80) mbits = 8;
 
6907
                    else if (s[0] & 0x40) mbits =  7;
 
6908
                    else if (s[0] & 0x20) mbits =  6;
 
6909
                    else if (s[0] & 0x10) mbits =  5;
 
6910
                    else if (s[0] & 0x08) mbits =  4;
 
6911
                    else if (s[0] & 0x04) mbits =  3;
 
6912
                    else if (s[0] & 0x02) mbits =  2;
 
6913
                    else if (s[0] & 0x01) mbits =  1;
 
6914
                } else {
 
6915
                    /*zero*/
 
6916
                    d[7] = d[6] = d[5] = d[4] = d[3] = d[2] = d[1] = d[0] = 0;
 
6917
                    continue;
 
6918
                }
 
6919
 
 
6920
                /*
 
6921
                 * The sign and exponent.
 
6922
                 */
 
6923
                exponent = (mbits - 1) + 1023;
 
6924
                d[7] = (sign<<7) | ((exponent>>4) & 0x7f);
 
6925
                d[6] = (exponent & 0x0f) << 4;
 
6926
 
 
6927
                /*
 
6928
                 * The mantissa.
 
6929
                 */
 
6930
                switch (mbits) {
 
6931
                    case 32:
 
6932
                        d[5] = d[4] = d[3] = d[1] = d[0] = 0;
 
6933
                        break;
 
6934
 
 
6935
                    case 31:
 
6936
                        d[6] |=   0x0f   & (s[3]>>2);
 
6937
                        d[5] = (s[3]<<6) | (s[2]>>2);
 
6938
                        d[4] = (s[2]<<6) | (s[1]>>2);
 
6939
                        d[3] = (s[1]<<6) | (s[0]>>2);
 
6940
                        d[2] = (s[0]<<6);
 
6941
                        d[1] = d[0] = 0;
 
6942
                        break;
 
6943
 
 
6944
                    case 30:
 
6945
                        d[6] |=   0x0f   & (s[3]>>1);
 
6946
                        d[5] = (s[3]<<7) | (s[2]>>1);
 
6947
                        d[4] = (s[2]<<7) | (s[1]>>1);
 
6948
                        d[3] = (s[1]<<7) | (s[0]>>1);
 
6949
                        d[2] = (s[0]<<7);
 
6950
                        d[1] = d[0] = 0;
 
6951
                        break;
 
6952
 
 
6953
                    case 29:
 
6954
                        d[6] |=   0x0f   & s[3];
 
6955
                        d[5] = s[2];
 
6956
                        d[4] = s[1];
 
6957
                        d[3] = s[0];
 
6958
                        d[2] = d[1] = d[0] = 0;
 
6959
                        break;
 
6960
 
 
6961
                    case 28:
 
6962
                        d[6] |= ((s[3]<<1) | (s[2]>>7)) & 0x0f;
 
6963
                        d[5] =   (s[2]<<1) | (s[1]>>7);
 
6964
                        d[4] =   (s[1]<<1) | (s[0]>>7);
 
6965
                        d[3] =   (s[0]<<1);
 
6966
                        d[2] = d[1] = d[0] = 0;
 
6967
                        break;
 
6968
 
 
6969
                    case 27:
 
6970
                        d[6] |= ((s[3]<<2) | (s[2]>>6)) & 0x0f;
 
6971
                        d[5] =   (s[2]<<2) | (s[1]>>6);
 
6972
                        d[4] =   (s[1]<<2) | (s[0]>>6);
 
6973
                        d[3] =   (s[0]<<2);
 
6974
                        d[2] = d[1] = d[0] = 0;
 
6975
                        break;
 
6976
 
 
6977
                    case 26:
 
6978
                        d[6] |= ((s[3]<<3) | (s[2]>>5)) & 0x0f;
 
6979
                        d[5] =   (s[2]<<3) | (s[1]>>5);
 
6980
                        d[4] =   (s[1]<<3) | (s[0]>>5);
 
6981
                        d[3] =   (s[0]<<3);
 
6982
                        d[2] = d[1] = d[0] = 0;
 
6983
                        break;
 
6984
 
 
6985
                    case 25:
 
6986
                        d[6] |=    0x0f   & (s[2]>>4);
 
6987
                        d[5] = (s[2]<<4) | (s[1]>>4);
 
6988
                        d[4] = (s[1]<<4) | (s[0]>>4);
 
6989
                        d[3] = (s[0]<<4);
 
6990
                        d[2] = d[1] = d[0] = 0;
 
6991
                        break;
 
6992
 
 
6993
                    case 24:
 
6994
                        d[6] |=    0x0f   & (s[2]>>3);
 
6995
                        d[5] = (s[2]<<5) | (s[1]>>3);
 
6996
                        d[4] = (s[1]<<5) | (s[0]>>3);
 
6997
                        d[3] = (s[0]<<5);
 
6998
                        d[2] = d[1] = d[0] = 0;
 
6999
                        break;
 
7000
 
 
7001
                    case 23:
 
7002
                        d[6] |=    0x0f   & (s[2]>>2);
 
7003
                        d[5] = (s[2]<<6) | (s[1]>>2);
 
7004
                        d[4] = (s[1]<<6) | (s[0]>>2);
 
7005
                        d[3] = (s[0]<<6);
 
7006
                        d[2] = d[1] = d[0] = 0;
 
7007
                        break;
 
7008
 
 
7009
                    case 22:
 
7010
                        d[6] |=    0x0f   & (s[2]>>1);
 
7011
                        d[5] = (s[2]<<7) | (s[1]>>1);
 
7012
                        d[4] = (s[1]<<7) | (s[0]>>1);
 
7013
                        d[3] = (s[0]<<7);
 
7014
                        d[2] = d[1] = d[0] = 0;
 
7015
                        break;
 
7016
 
 
7017
                    case 21:
 
7018
                        d[6] |= 0x0f & s[2];
 
7019
                        d[5] = s[1];
 
7020
                        d[4] = s[0];
 
7021
                        d[3] = d[2] = d[1] = d[0] = 0;
 
7022
                        break;
 
7023
 
 
7024
                    case 20:
 
7025
                        d[6] |= ((s[2]<<1) | (s[1]>>7)) & 0x0f;
 
7026
                        d[5] =   (s[1]<<1) | (s[0]>>7);
 
7027
                        d[4] =   (s[0]<<1);
 
7028
                        d[3] = d[2] = d[1] = d[0] = 0;
 
7029
                        break;
 
7030
 
 
7031
                    case 19:
 
7032
                        d[6] |= ((s[2]<<2) | (s[1]>>6)) & 0x0f;
 
7033
                        d[5] =   (s[1]<<2) | (s[0]>>6);
 
7034
                        d[4] =   (s[0]<<2);
 
7035
                        d[3] = d[2] = d[1] = d[0] = 0;
 
7036
                        break;
 
7037
 
 
7038
                    case 18:
 
7039
                        d[6] |= ((s[2]<<3) | (s[1]>>5)) & 0x0f;
 
7040
                        d[5] =   (s[1]<<3) | (s[0]>>5);
 
7041
                        d[4] =   (s[0]<<3);
 
7042
                        d[3] = d[2] = d[1] = d[0] = 0;
 
7043
                        break;
 
7044
 
 
7045
                    case 17:
 
7046
                        d[6] |=    0x0f   & (s[1]>>4);
 
7047
                        d[5] = (s[1]<<4) | (s[0]>>4);
 
7048
                        d[4] = (s[0]<<4);
 
7049
                        d[3] = d[2] = d[1] = d[0] = 0;
 
7050
                        break;
 
7051
 
 
7052
                    case 16:
 
7053
                        d[6] |=    0x0f   & (s[1]>>3);
 
7054
                        d[5] = (s[1]<<5) | (s[0]>>3);
 
7055
                        d[4] = (s[0]<<5);
 
7056
                        d[3] = d[2] = d[1] = d[0] = 0;
 
7057
                        break;
 
7058
 
 
7059
                    case 15:
 
7060
                        d[6] |=    0x0f   & (s[1]>>2);
 
7061
                        d[5] = (s[1]<<6) | (s[0]>>2);
 
7062
                        d[4] = (s[0]<<6);
 
7063
                        d[3] = d[2] = d[1] = d[0] = 0;
 
7064
                        break;
 
7065
 
 
7066
                    case 14:
 
7067
                        d[6] |=    0x0f   & (s[1]>>1);
 
7068
                        d[5] = (s[1]<<7) | (s[0]>>1);
 
7069
                        d[4] = (s[0]<<7);
 
7070
                        d[3] = d[2] = d[1] = d[0] = 0;
 
7071
                        break;
 
7072
 
 
7073
                    case 13:
 
7074
                        d[6] |= 0x0f & s[1];
 
7075
                        d[5] = s[0];
 
7076
                        d[4] = d[3] = d[2] = d[1] = d[0] = 0;
 
7077
                        break;
 
7078
 
 
7079
                    case 12:
 
7080
                        d[6] |= ((s[1]<<1) | (s[0]>>7)) & 0x0f;
 
7081
                        d[5] =   (s[0]<<1);
 
7082
                        d[4] = d[3] = d[2] = d[1] = d[0] = 0;
 
7083
                        break;
 
7084
 
 
7085
                    case 11:
 
7086
                        d[6] |= ((s[1]<<2) | (s[0]>>6)) & 0x0f;
 
7087
                        d[5] =   (s[0]<<2);
 
7088
                        d[4] = d[3] = d[2] = d[1] = d[0] = 0;
 
7089
                        break;
 
7090
 
 
7091
                    case 10:
 
7092
                        d[6] |= ((s[1]<<3) | (s[0]>>5)) & 0x0f;
 
7093
                        d[5] =   (s[0]<<3);
 
7094
                        d[4] = d[3] = d[2] = d[1] = d[0] = 0;
 
7095
                        break;
 
7096
 
 
7097
                    case 9:
 
7098
                        d[6] |=    0x0f   & (s[0]>>4);
 
7099
                        d[5] = (s[0]<<4);
 
7100
                        d[4] = d[3] = d[2] = d[1] = d[0] = 0;
 
7101
                        break;
 
7102
 
 
7103
                    case 8:
 
7104
                        d[6] |=    0x0f   & (s[0]>>3);
 
7105
                        d[5] = (s[0]<<5);
 
7106
                        d[4] = d[3] = d[2] = d[1] = d[0] = 0;
 
7107
                        break;
 
7108
 
 
7109
                    case 7:
 
7110
                        d[6] |=    0x0f   & (s[0]>>2);
 
7111
                        d[5] = (s[0]<<6);
 
7112
                        d[4] = d[3] = d[2] = d[1] = d[0] = 0;
 
7113
                        break;
 
7114
 
 
7115
                    case 6:
 
7116
                        d[6] |=    0x0f   & (s[0]>>1);
 
7117
                        d[5] = (s[0]<<7);
 
7118
                        d[4] = d[3] = d[2] = d[1] = d[0] = 0;
 
7119
                        break;
 
7120
 
 
7121
                    case 5:
 
7122
                        d[6] |= 0x0f & s[0];
 
7123
                        d[5] = d[4] = d[3] = d[2] = d[1] = d[0] = 0;
 
7124
                        break;
 
7125
 
 
7126
                    case 4:
 
7127
                        d[6] |= (s[0]<<1) & 0x0f;
 
7128
                        d[5] = d[4] = d[3] = d[2] = d[1] = d[0] = 0;
 
7129
                        break;
 
7130
 
 
7131
                    case 3:
 
7132
                        d[6] |= (s[0]<<2) & 0x0f;
 
7133
                        d[5] = d[4] = d[3] = d[2] = d[1] = d[0] = 0;
 
7134
                        break;
 
7135
 
 
7136
                    case 2:
 
7137
                        d[6] |= (s[0]<<3) & 0x0f;
 
7138
                        d[5] = d[4] = d[3] = d[2] = d[1] = d[0] = 0;
 
7139
                        break;
 
7140
 
 
7141
                    case 1:
 
7142
                        d[5] = d[4] = d[3] = d[2] = d[1] = d[0] = 0;
 
7143
                        break;
 
7144
                }
 
7145
 
 
7146
                /*
 
7147
                 * Copy temp buffer to the destination.  This only happens for
 
7148
                 * the first value in the array, the last value processed. See
 
7149
                 * beginning of loop.
 
7150
                 */
 
7151
                if (d==tmp)
 
7152
                    HDmemcpy (s, d, 8);
 
7153
 
 
7154
                /* Advance pointers */
 
7155
                if (buf_stride) {
 
7156
                    s -= buf_stride;
 
7157
                    d -= buf_stride;
 
7158
                } else {
 
7159
                    s -= 4;
 
7160
                    d -= 8;
 
7161
                }
 
7162
            }
 
7163
            break;
 
7164
 
 
7165
        default:
 
7166
            /* Some other command we don't know about yet.*/
 
7167
            HGOTO_ERROR (H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, "unknown conversion command");
 
7168
    }
 
7169
 
 
7170
done:
 
7171
    FUNC_LEAVE_NOAPI(ret_value);
 
7172
}