summaryrefslogtreecommitdiffstats
path: root/src/H5Tconv.c
blob: ff612ba0f27aa0f7cf9d412612a0089e9ea395f2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
/*
 * Copyright (C) 1998 Spizella Software
 *                    All rights reserved.
 *
 * Programmer:  Robb Matzke <robb@arborea.spizella.com>
 *              Tuesday, January 13, 1998
 *
 * Purpose:     Data type conversions.
 */
#define H5T_PACKAGE             /*suppress error about including H5Tpkg   */

#include <H5Aprivate.h>
#include <H5Eprivate.h>
#include <H5MMprivate.h>
#include <H5Tpkg.h>

/* Interface initialization */
static intn interface_initialize_g = FALSE;
#define INTERFACE_INIT NULL

/*-------------------------------------------------------------------------
 * Function:    H5T_conv_noop
 *
 * Purpose:     The no-op conversion.  The library knows about this
 *              conversion without it being registered.
 *
 * Return:      Success:        SUCCEED
 *
 *              Failure:        never fails
 *
 * Programmer:  Robb Matzke
 *              Wednesday, January 14, 1998
 *
 * Modifications:
 *
 *-------------------------------------------------------------------------
 */
herr_t
H5T_conv_noop(hid_t src_id, hid_t dst_id, size_t nelmts,
              void *buf, const void *background)
{
    FUNC_ENTER(H5T_conv_noop, FAIL);
    FUNC_LEAVE(SUCCEED);
}

/*-------------------------------------------------------------------------
 * Function:    H5T_conv_order
 *
 * Purpose:     Convert one type to another when byte order is the only
 *              difference.
 *
 * Note:        This is a soft conversion function.
 *
 * Return:      Success:        SUCCEED
 *
 *              Failure:        FAIL
 *
 * Programmer:  Robb Matzke
 *              Tuesday, January 13, 1998
 *
 * Modifications:
 *
 *-------------------------------------------------------------------------
 */
herr_t
H5T_conv_order(hid_t src_id, hid_t dst_id, size_t nelmts,
               void *_buf, const void *background)
{
    uint8                  *buf = (uint8 *) _buf;
    uint8                   tmp;
    H5T_t                  *src = NULL;
    H5T_t                  *dst = NULL;
    intn                    i, j, md;

    FUNC_ENTER(H5T_conv_order, FAIL);

    /* Check args */
    if (H5_DATATYPE != H5A_group(src_id) ||
        NULL == (src = H5A_object(src_id)) ||
        H5_DATATYPE != H5A_group(dst_id) ||
        NULL == (dst = H5A_object(dst_id))) {
        HRETURN_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a data type");
    }
    if (background) {
        HRETURN_ERROR(H5E_ARGS, H5E_UNSUPPORTED, FAIL,
                      "background values not supported in this conv path");
    }

    if (!buf) {
        /* Capability query */
        if (src->size != dst->size ||
            0 != src->u.atomic.offset ||
            0 != dst->u.atomic.offset ||
            !((H5T_ORDER_BE == src->u.atomic.order &&
               H5T_ORDER_LE == dst->u.atomic.order) ||
              (H5T_ORDER_LE == src->u.atomic.order &&
               H5T_ORDER_BE == dst->u.atomic.order))) {
            HRETURN_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, FAIL,
                          "conversion not supported");
        }
        switch (src->type) {
        case H5T_INTEGER:
            /* nothing to check */
            break;

        case H5T_FLOAT:
            if (src->u.atomic.u.f.sign != dst->u.atomic.u.f.sign ||
                src->u.atomic.u.f.epos != dst->u.atomic.u.f.epos ||
                src->u.atomic.u.f.esize != dst->u.atomic.u.f.esize ||
                src->u.atomic.u.f.ebias != dst->u.atomic.u.f.ebias ||
                src->u.atomic.u.f.mpos != dst->u.atomic.u.f.mpos ||
                src->u.atomic.u.f.msize != dst->u.atomic.u.f.msize ||
                src->u.atomic.u.f.norm != dst->u.atomic.u.f.norm ||
                src->u.atomic.u.f.pad != dst->u.atomic.u.f.pad) {
                HRETURN_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, FAIL,
                              "conversion not supported");
            }
            break;

        default:
            HRETURN_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, FAIL,
                          "conversion not supported");
        }
        HRETURN(SUCCEED);
    }
    /* The conversion */
    md = src->size / 2;
    for (i = 0; i < nelmts; i++, buf += src->size) {
        for (j = 0; j < md; j++) {
            tmp = buf[j];
            buf[j] = buf[src->size - (j + 1)];
            buf[src->size - (j + 1)] = tmp;
        }
    }

    FUNC_LEAVE(SUCCEED);
}

/*-------------------------------------------------------------------------
 * Function:	H5T_conv_struct
 *
 * Purpose:	Converts between compound data types.  This is a soft
 *		conversion function.  The algorithm is basically:
 *
 * 		For I=1..NUM_MEMBERS do
 *		  If sizeof detination type <= sizeof source type then
 *		    Convert member to destination type;
 *		  Move member as far left as possible;
 *		  
 *		For I=NUM_MEMBERS..1 do
 *		  If not destination type then
 *		    Convert member to destination type;
 *		  Move member to correct position in BACKGROUND
 *
 * 		Copy BACKGROUND to BUF
 *
 * Return:	Success:	SUCCEED
 *
 *		Failure:	FAIL
 *
 * Programmer:	Robb Matzke
 *              Thursday, January 22, 1998
 *
 * Modifications:
 *
 *-------------------------------------------------------------------------
 */
herr_t
H5T_conv_struct(hid_t src_id, hid_t dst_id, size_t nelmts,
		void *_buf, const void *background)
{
    uint8	*buf = (uint8 *)_buf;	/*cast for pointer arithmetic	*/
    H5T_t	*src = NULL;		/*source data type		*/
    H5T_t	*dst = NULL;		/*destination data type		*/
    intn	*dst2src_map = NULL;	/*maps dst member to src member	*/
    intn	i;
    
    FUNC_ENTER (H5T_conv_struct, FAIL);

    /* Check args */
    if (H5_DATATYPE != H5A_group(src_id) ||
        NULL == (src = H5A_object(src_id)) ||
        H5_DATATYPE != H5A_group(dst_id) ||
        NULL == (dst = H5A_object(dst_id))) {
        HRETURN_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a data type");
    }
    if (background) {
        HRETURN_ERROR(H5E_ARGS, H5E_UNSUPPORTED, FAIL,
                      "background values not supported in this conv path");
    }

    /* Capability query? */
    if (!buf) {
	assert (H5T_COMPOUND==src->type);
	assert (H5T_COMPOUND==dst->type);
	HRETURN (SUCCEED);
    }

    /*
     * Build a mapping from destination member number to source member number
     */
    H5T_sort_by_offset (src);
    H5T_sort_by_offset (dst);
    dst2src_map = H5MM_xmalloc (dst->u.compnd.nmembs * sizeof(intn));
    for (i=0; i<src->u.compnd.nmembs; i++) {
    }



    /*
     * For each source member which will be present in the destination,
     * convert the member to the destination type unless it is larger than
     * the source type.  Then move the member to the left-most unoccupied
     * position in the buffer.  This makes the data point as small as
     * possible with all the free space on the right side.
     */
    for (i=0; i<src->u.compnd.nmembs; i++) {
    }


    /*
     * For each source member which will be present in the destination,
     * convert the member to the destination type if it is larger than the
     * source type (that is, has not been converted yet).  Then copy the
     * member to the destination offset in the background buffer.
     */
    for (i=src->u.compnd.nmembs-1; i>=0; --i) {
    }

    
    /*
     * Copy the background buffer back into the in-place conversion buffer.
     */
    HDmemcpy (buf, background, dst->size);








    
    HRETURN_ERROR (H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, "not implemented yet");
    FUNC_LEAVE (SUCCEED);
}