H5Part_model.c 7.26 KB
Newer Older
1
/*
gsell's avatar
gsell committed
2
  Copyright (c) 2006-2015, The Regents of the University of California,
3 4 5 6 7 8 9 10
  through Lawrence Berkeley National Laboratory (subject to receipt of any
  required approvals from the U.S. Dept. of Energy) and the Paul Scherrer
  Institut (Switzerland).  All rights reserved.

  License: see file COPYING in top level of source distribution.
*/

#include "h5_private.h"
11
#include "h5core/h5_log.h"
12
#include "h5core/h5u_model.h"
gsell's avatar
gsell committed
13
#include "h5core/h5u_io.h"
14

gsell's avatar
gsell committed
15 16
#include "h5core/h5_syscall.h"

17
/*=============Setting and getting views================*/
18

gsell's avatar
gsell committed
19
#define h5pt_setnpoints FC_MANGLING (					\
20 21
                h5pt_setnpoints,                                        \
                H5PT_SETNPOINTS )
22
h5_int64_t
23
h5pt_setnpoints (
24
	const h5_int64_t* const fh,
Gsell Achim's avatar
* C-API  
Gsell Achim committed
25
	const h5_int64_t* const num_items
26 27 28
	) {
	h5_file_t f = h5_filehandlefor2c (fh);
	H5_API_ENTER (h5_int64_t,
29
                      "fh=%p, npoints=%lld",
Gsell Achim's avatar
* C-API  
Gsell Achim committed
30 31
                      (h5_file_p)f, (long long)*num_items);
	H5_API_RETURN (h5u_set_num_items (f, *num_items, 1));
32
}
33
                
gsell's avatar
gsell committed
34
#define h5pt_setnpoints_strided FC_MANGLING (				\
35 36
                        h5pt_setnpoints_strided,                        \
                        H5PT_SETNPOINTS_STRIDED )
37
h5_int64_t
38
h5pt_setnpoints_strided (
39
	const h5_int64_t* const fh,
Gsell Achim's avatar
* C-API  
Gsell Achim committed
40
	const h5_int64_t* const num_items,
41 42
        const h5_int64_t* const stride
	) {
43 44
	h5_file_t f = h5_filehandlefor2c (fh);
	H5_API_ENTER (h5_int64_t,
45
                      "fh=%p, npoints=%lld, stride=%lld",
Gsell Achim's avatar
* C-API  
Gsell Achim committed
46 47
                      (h5_file_p)f, (long long)*num_items, (long long)*stride);
	H5_API_RETURN (h5u_set_num_items (f, *num_items, *stride));
48 49
}

50

51

gsell's avatar
gsell committed
52
#define h5pt_setview FC_MANGLING (					\
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
                h5pt_setview,                                           \
                H5PT_SETVIEW )
h5_int64_t
h5pt_setview (
	const h5_int64_t* const fh,
	const h5_int64_t* const start,
	const h5_int64_t* const end
	) {
	h5_file_t f = h5_filehandlefor2c (fh);
	H5_API_ENTER (h5_int64_t,
                      "fh=%p, start=%lld, end=%lld",
                      (h5_file_p)f, (long long)*start, (long long)*end);
	H5_API_RETURN (h5u_set_view (f, (*start)-1, (*end)-1));
}

gsell's avatar
gsell committed
68
#define h5pt_setview_indices FC_MANGLING(				\
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
                h5pt_setview_indices,                                   \
                H5PT_SETVIEW_INDICES )
h5_int64_t
h5pt_setview_indices (
	const h5_int64_t* const fh,
	const h5_int64_t* const indices,
	const h5_int64_t* const nelem
	) {
	h5_file_t f = h5_filehandlefor2c (fh);
	H5_API_ENTER (h5_int64_t,
                      "fh=%p, indices=%p, nelem=%lld",
                      (h5_file_p)f, indices, (long long)*nelem);
        h5_size_t* findices;
        TRY (findices = h5_calloc (*nelem, sizeof (*indices)));
        for (size_t i = 0; i < *nelem; i++) 
                findices[i] = indices[i] - 1;
        TRY (h5u_set_view_indices (f, findices, *nelem));
        TRY (h5_free (findices));
	H5_API_RETURN (H5_SUCCESS);
}

gsell's avatar
gsell committed
90
#define h5pt_setcanonicalview FC_MANGLING (				\
91 92
		h5pt_setcanonicalview,					\
		H5PT_SETCANONICALVIEW)
93
h5_int64_t
94 95
h5pt_setcanonicalview (
	const h5_int64_t* const fh
96 97 98
	) {
	h5_file_t f = h5_filehandlefor2c (fh);
	H5_API_ENTER (h5_int64_t,
99 100 101
                      "fh=%p",
                      (h5_file_p)f);
	H5_API_RETURN (h5u_set_canonical_view (f));
102 103
}

104

gsell's avatar
gsell committed
105
#define h5pt_resetview FC_MANGLING (					\
106 107 108 109 110 111 112 113 114 115 116 117 118
                h5pt_resetview,                                         \
                H5PT_RESETVIEW )
h5_int64_t
h5pt_resetview (
	const h5_int64_t* const fh
	) {
	h5_file_t f = h5_filehandlefor2c (fh);
	H5_API_ENTER (h5_int64_t,
                      "fh=%p",
                      (h5_file_p)f);
	H5_API_RETURN (h5u_reset_view (f));
}

gsell's avatar
gsell committed
119
#define h5pt_hasview FC_MANGLING (					\
120 121 122 123 124 125 126 127 128 129 130 131 132
                h5pt_hasview,                                           \
                H5PT_HASVIEW )
h5_int64_t
h5pt_hasview (
	const h5_int64_t* const fh
	) {
	h5_file_t f = h5_filehandlefor2c (fh);
	H5_API_ENTER (h5_int64_t,
                      "fh=%p",
                      (h5_file_p)f);
	H5_API_RETURN (h5u_has_view (f));
}

gsell's avatar
gsell committed
133
#define h5pt_getview FC_MANGLING (					\
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
                h5pt_getview,                                           \
                H5PT_GETVIEW )
h5_int64_t
h5pt_getview (
	const h5_int64_t* const fh,
	h5_int64_t* const start,
	h5_int64_t* const end
	) {
	h5_file_t f = h5_filehandlefor2c (fh);
	H5_API_ENTER (h5_int64_t,
                      "fh=%p, start=%p, end=%p",
                      (h5_file_p)f, start, end);
        TRY (h5u_get_view (f, start, end));
        *start += 1;
        *end += 1;
        H5_API_RETURN (H5_SUCCESS);
}
151 152 153

/*==============Reading Data Characteristics============*/

gsell's avatar
gsell committed
154
#define h5pt_getndatasets FC_MANGLING (					\
155 156 157 158 159 160 161 162 163 164 165
                h5pt_getndatasets,                                      \
                H5PT_GETNDATASETS )
h5_int64_t
h5pt_getndatasets (
	const h5_int64_t* const fh
	) {
	h5_file_t f = h5_filehandlefor2c (fh);
	H5_API_ENTER (h5_int64_t, "fh=%p", (h5_file_p)f);
	H5_API_RETURN(h5u_get_num_datasets (f));
}

gsell's avatar
gsell committed
166
#define h5pt_getnpoints FC_MANGLING (					\
167 168 169 170 171 172 173 174
                h5pt_getnpoints,                                        \
                H5PT_GETNPOINTS )
h5_int64_t
h5pt_getnpoints (
	const h5_int64_t* const fh
	) {
	h5_file_t f = h5_filehandlefor2c (fh);
	H5_API_ENTER (h5_int64_t, "fh=%p", (h5_file_p)f);
Gsell Achim's avatar
* C-API  
Gsell Achim committed
175
	H5_API_RETURN (h5u_get_num_items (f));
176 177
}

gsell's avatar
gsell committed
178
#define h5pt_getdatasetname FC_MANGLING (				\
179 180 181 182 183 184 185 186 187 188 189 190 191
                h5pt_getdatasetname,                                    \
                H5PT_GETDATASETNAME )
h5_int64_t
h5pt_getdatasetname (
	const h5_int64_t* const fh,
	const h5_int64_t* index,
	char* name,
	const int l_name
	) {
	h5_file_t f = h5_filehandlefor2c (fh);
	H5_API_ENTER (h5_int64_t,
                      "fh=%p, index=%lld, name='%s', l_name=%d",
                      (h5_file_p)f, (long long)*index, name, l_name);
192
	h5_int64_t herr =  h5u_get_dataset_info_by_idx (
193 194 195 196 197
		f, *index - 1, name, l_name, NULL, NULL );
	h5_strc2for (name, l_name);
	H5_API_RETURN (herr);
}

gsell's avatar
gsell committed
198
#define h5pt_getdatasetinfo FC_MANGLING (	 \
199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219
                h5pt_getdatasetinfo,             \
                H5PT_GETDATASETINFO)
h5_int64_t
h5pt_getdatasetinfo (
	const h5_int64_t* const fh,
	const h5_int64_t* dataset_idx,
	char* dataset_name,
        h5_int64_t* dataset_type,
	h5_int64_t* dataset_nelem,
	const int l_dataset_name
        ) {
	h5_file_t f = h5_filehandlefor2c (fh);
	H5_API_ENTER (h5_int64_t,
		      "fh=%p, "
		      "dataset_idx=%lld, "
		      "dataset_name=%p, "
		      "dataset_type=%p, "
		      "dataset_nelem=%p",
		      (h5_file_p)f,
		      (long long)*dataset_idx,
		      dataset_name, dataset_type, dataset_nelem);
220
        h5_int64_t h5err = h5u_get_dataset_info_by_idx (
221 222 223 224 225 226 227 228 229 230 231
                f,
                *dataset_idx - 1,
                dataset_name, l_dataset_name,
                dataset_type,
                (h5_size_t*)dataset_nelem);
	h5_strc2for (dataset_name, l_dataset_name);
	H5_API_RETURN (h5err);
}

/*===================== misc =====================*/

gsell's avatar
gsell committed
232
#define h5pt_setchunksize FC_MANGLING (					\
233 234 235 236 237 238 239 240 241 242 243 244 245
                h5pt_setchunksize,					\
                H5PT_SETCHUNKSIZE )
h5_int64_t
h5pt_setchunksize (
	const h5_int64_t* const fh,
	const h5_int64_t* const size
	) {
	h5_file_t f = h5_filehandlefor2c (fh);
	H5_API_ENTER (h5_int64_t,
                      "fh=%p, size=%lld",
                      (h5_file_p)f, (long long)*size);
	H5_API_RETURN (h5u_set_chunk (f, *size));
}