h5_attribs.c 7.75 KB
Newer Older
1
/*
gsell's avatar
gsell committed
2
  Copyright (c) 2006-2016, The Regents of the University of California,
3 4 5 6 7 8 9
  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.
*/

10
#include "h5core/h5_log.h"
gsell's avatar
gsell committed
11 12
#include "h5core/h5_file_attribs.h"
#include "h5core/h5_step_attribs.h"
13

gsell's avatar
gsell committed
14 15
#include "private/h5_hdf5.h"
#include "private/h5_attribs.h"
16 17

h5_err_t
18
h5_has_file_attrib (
19
	const h5_file_t f_,
20
	const char* const attrib_name
21 22 23
	) {
        h5_file_p f = (h5_file_p)f_;
	H5_CORE_API_ENTER (h5_err_t,
24 25
			   "f=%p, "
			   "attrib_name='%s'",
26
			   f,
27
			   attrib_name);
28
	CHECK_FILEHANDLE (f);
29
	TRY (ret_value = hdf5_attribute_exists(f->root_gid, attrib_name));
gsell's avatar
gsell committed
30
	H5_RETURN (ret_value);
31
}
32
	
33
h5_err_t
Gsell Achim's avatar
* C-API  
Gsell Achim committed
34
h5_has_iteration_attrib (
35
	const h5_file_t f_,
36
	const char* const attrib_name
37 38 39
	) {
        h5_file_p f = (h5_file_p)f_;
	H5_CORE_API_ENTER (h5_err_t,
40 41
			   "f=%p, "
			   "attrib_name='%s'",
42
			   f,
43
			   attrib_name);
Gsell Achim's avatar
* C-API  
Gsell Achim committed
44 45
	check_iteration_handle_is_valid (f);
	TRY (ret_value = hdf5_attribute_exists (f->iteration_gid, attrib_name));
gsell's avatar
gsell committed
46
	H5_RETURN (ret_value);
47 48 49 50 51 52 53 54 55 56
}

h5_ssize_t
h5_get_num_file_attribs (
	const h5_file_t f_                      /*!< handle to open file */
	) {
        h5_file_p f = (h5_file_p)f_;
	H5_CORE_API_ENTER (h5_ssize_t, "f=%p", f);
	CHECK_FILEHANDLE (f);
	TRY (ret_value = hdf5_get_num_attribute (f->root_gid));
gsell's avatar
gsell committed
57
	H5_RETURN (ret_value);
58 59 60
}

h5_ssize_t
Gsell Achim's avatar
* C-API  
Gsell Achim committed
61
h5_get_num_iteration_attribs (
62 63 64 65
	const h5_file_t f_                     	/*!< handle to open file */
	) {
        h5_file_p f = (h5_file_p)f_;
	H5_CORE_API_ENTER (h5_ssize_t, "f=%p", f);
Gsell Achim's avatar
* C-API  
Gsell Achim committed
66 67
	check_iteration_handle_is_valid (f);
	TRY (ret_value = hdf5_get_num_attribute (f->iteration_gid));
gsell's avatar
gsell committed
68
	H5_RETURN (ret_value);
69 70
}

71
h5_err_t
72 73 74
h5_get_file_attrib_info_by_idx (
	const h5_file_t f_,			/*!< handle to open file */
	const h5_size_t attrib_idx,		/*!< index of attribute */
gsell's avatar
gsell committed
75
	char* const attrib_name,		/*!< OUT: name of attribute */
76
	const h5_size_t len_attrib_name,	/*!< buffer length */
gsell's avatar
gsell committed
77 78
	h5_int64_t* const attrib_type,		/*!< OUT: H5 type of attribute */
	h5_size_t* const attrib_nelem		/*!< OUT: number of elements */
79 80 81 82
	) {
        h5_file_p f = (h5_file_p)f_;
	H5_CORE_API_ENTER (h5_err_t,
			   "f=%p, "
83 84
			   "attrib_idx=%llu, "
                           "attrib_name=%p, len_attrib_name=%llu, "
85 86
			   "attrib_type=%p, attrib_nelem=%p",
			   f,
87 88 89
			   (long long unsigned)attrib_idx,
			   attrib_name, (long long unsigned)len_attrib_name,
			   attrib_type, attrib_nelem);
90
	CHECK_FILEHANDLE (f);
91 92 93 94 95
	TRY (ret_value = h5priv_get_attrib_info_by_idx (
			f->root_gid,
			attrib_idx,
			attrib_name, len_attrib_name,
			attrib_type, attrib_nelem));
gsell's avatar
gsell committed
96
	H5_RETURN (ret_value);
97 98 99
}

h5_err_t
100 101
h5_get_file_attrib_info_by_name (
	const h5_file_t f_,			/*!< IN: handle to open file */
gsell's avatar
gsell committed
102
	const char* const attrib_name,		/*!< IN: name of attribute */
103 104 105 106 107 108
	h5_int64_t* attrib_type,		/*!< OUT: H5 type of attribute */
	h5_size_t* attrib_nelem			/*!< OUT: number of elements */
	) {
        h5_file_p f = (h5_file_p)f_;
	H5_CORE_API_ENTER (h5_err_t,
			   "f=%p, "
109
			   "attrib_name=%s, "
110 111
			   "attrib_type=%p, attrib_nelem=%p",
			   f,
112
			   attrib_name,
113
			   attrib_type, attrib_nelem);
114
	CHECK_FILEHANDLE (f);
115 116 117
	TRY (ret_value = h5priv_get_attrib_info_by_name (
		     f->root_gid,
		     attrib_name,
118
		     attrib_type, attrib_nelem));
gsell's avatar
gsell committed
119
	H5_RETURN (ret_value);
120 121
}

122
h5_err_t
Gsell Achim's avatar
* C-API  
Gsell Achim committed
123
h5_get_iteration_attrib_info_by_idx (
124
	const h5_file_t f_,			/*!< handle to open file */
125
	const h5_size_t attrib_idx,		/*!< index of attribute */
126
	char* attrib_name,			/*!< OUT: name of attribute */
127
	const h5_size_t len_attrib_name,	/*!< buffer length */
128 129 130 131 132 133
	h5_int64_t* attrib_type,		/*!< OUT: H5 type of attribute */
	h5_size_t* attrib_nelem			/*!< OUT: number of elements */
	) {
        h5_file_p f = (h5_file_p)f_;
	H5_CORE_API_ENTER (h5_err_t,
			   "f=%p, "
134
			   "attrib_idx=%llu, "
135
			   "attrib_name=%p, len_attrib_name=%llu, "
136 137
			   "attrib_type=%p, attrib_nelem=%p",
			   f,
138 139
			   (long long unsigned)attrib_idx,
			   attrib_name, (long long unsigned)len_attrib_name,
140
			   attrib_type, attrib_nelem);
Gsell Achim's avatar
* C-API  
Gsell Achim committed
141
	check_iteration_handle_is_valid (f);
142
	TRY (ret_value = h5priv_get_attrib_info_by_idx (
Gsell Achim's avatar
* C-API  
Gsell Achim committed
143
		     f->iteration_gid,
144 145
		     attrib_idx,
		     attrib_name, len_attrib_name,
146
		     attrib_type, attrib_nelem));
gsell's avatar
gsell committed
147
	H5_RETURN (ret_value);
148 149 150
}

h5_err_t
Gsell Achim's avatar
* C-API  
Gsell Achim committed
151
h5_get_iteration_attrib_info_by_name (
152
	const h5_file_t f_,			/*!< handle to open file */
gsell's avatar
gsell committed
153 154 155
	const char* const attrib_name,		/*!< OUT: name of attribute */
	h5_int64_t* const attrib_type,		/*!< OUT: H5 type of attribute */
	h5_size_t* const attrib_nelem		/*!< OUT: number of elements */
156 157 158 159
	) {
        h5_file_p f = (h5_file_p)f_;
	H5_CORE_API_ENTER (h5_err_t,
			   "f=%p, "
160
			   "attrib_name=%p, "
161 162 163
			   "attrib_type=%p, attrib_nelem=%p",
			   f,
			   attrib_name,
164
			   attrib_type, attrib_nelem);
Gsell Achim's avatar
* C-API  
Gsell Achim committed
165
	check_iteration_handle_is_valid (f);
166
	TRY (ret_value = h5priv_get_attrib_info_by_name (
Gsell Achim's avatar
* C-API  
Gsell Achim committed
167
		     f->iteration_gid,
168
		     attrib_name,
169
		     attrib_type, attrib_nelem));
gsell's avatar
gsell committed
170
	H5_RETURN (ret_value);
171 172
}

173 174 175 176
h5_err_t
h5_read_file_attrib (
	const h5_file_t f_,
	const char* const attrib_name,
gsell's avatar
gsell committed
177 178
	const h5_types_t attrib_type,
	void* const attrib_value
179 180 181
	) {
        h5_file_p f = (h5_file_p)f_;
	H5_CORE_API_ENTER (h5_err_t,
gsell's avatar
gsell committed
182
			   "f=%p, attrib_name='%s', attrib_type=%lld, "
183 184 185
			   "attrib_value=%p",
			   f,
			   attrib_name,
gsell's avatar
gsell committed
186
			   (long long int)attrib_type,
187 188
			   attrib_value);
	CHECK_FILEHANDLE (f);
189 190 191 192 193
	TRY (ret_value = h5priv_read_attrib (
		     f->root_gid,
		     attrib_name,
		     attrib_type,
		     attrib_value));
gsell's avatar
gsell committed
194
	H5_RETURN (ret_value);
195 196 197
}

h5_err_t
Gsell Achim's avatar
* C-API  
Gsell Achim committed
198
h5_read_iteration_attrib (
199
	const h5_file_t f_,
gsell's avatar
gsell committed
200 201 202
	const char* const attrib_name,
	const h5_types_t attrib_type,
	void* const attrib_value
203 204 205
	) {
        h5_file_p f = (h5_file_p)f_;
	H5_CORE_API_ENTER (h5_err_t,
gsell's avatar
gsell committed
206
			   "f=%p, attrib_name='%s', attrib_type=%lld, "
207 208 209
			   "attrib_value=%p",
			   f,
			   attrib_name,
gsell's avatar
gsell committed
210
			   (long long int)attrib_type,
211
			   attrib_value);
Gsell Achim's avatar
* C-API  
Gsell Achim committed
212
	check_iteration_is_readable (f);
213 214
	
	TRY (ret_value = h5priv_read_attrib (
Gsell Achim's avatar
* C-API  
Gsell Achim committed
215
		     f->iteration_gid,
216 217 218
		     attrib_name,
		     attrib_type,
		     attrib_value));
gsell's avatar
gsell committed
219
	H5_RETURN (ret_value);
220
}
221

222 223 224
h5_err_t
h5_write_file_attrib (
	const h5_file_t f_,
gsell's avatar
gsell committed
225 226 227
	const char* const attrib_name,
	const h5_types_t attrib_type,
	const void* const attrib_value,
gsell's avatar
gsell committed
228
	const h5_size_t attrib_nelem
229 230
	) {
        h5_file_p f = (h5_file_p)f_;
231
	H5_CORE_API_ENTER (h5_err_t,
gsell's avatar
gsell committed
232
			   "f=%p, attrib_name='%s', attrib_type=%lld, "
gsell's avatar
gsell committed
233
			   "attrib_value=%p, attrib_nelem=%lld",
234 235
			   f,
			   attrib_name,
gsell's avatar
gsell committed
236
			   (long long int)attrib_type,
237
			   attrib_value,
gsell's avatar
gsell committed
238
			   (long long)attrib_nelem);
239
	CHECK_FILEHANDLE (f);
240
	CHECK_WRITABLE_MODE (f);
241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256
	if (is_appendonly (f)) {
		TRY (h5priv_append_attrib (
			     f->root_gid,
			     attrib_name,
			     attrib_type,
			     attrib_value,
			     attrib_nelem));
	} else {
		TRY (h5priv_write_attrib (
			     f->root_gid,
			     attrib_name,
			     attrib_type,
			     attrib_value,
			     attrib_nelem));
	}
	H5_RETURN (H5_SUCCESS);
257 258
}

259
h5_err_t
Gsell Achim's avatar
* C-API  
Gsell Achim committed
260
h5_write_iteration_attrib (
261
	const h5_file_t f_,
gsell's avatar
gsell committed
262 263 264 265
	const char* const attrib_name,
	const h5_types_t attrib_type,
	const void* const attrib_value,
	const h5_size_t attrib_nelem
266 267
	) {
        h5_file_p f = (h5_file_p)f_;
268
	H5_CORE_API_ENTER (h5_err_t,
gsell's avatar
gsell committed
269
			   "f=%p, attrib_name='%s', attrib_type=%lld, "
gsell's avatar
gsell committed
270
			   "attrib_value=%p, attrib_nelem=%lld",
271 272
			   f,
			   attrib_name,
gsell's avatar
gsell committed
273
			   (long long int)attrib_type,
274
			   attrib_value,
gsell's avatar
gsell committed
275
			   (long long)attrib_nelem);
Gsell Achim's avatar
* C-API  
Gsell Achim committed
276
	check_iteration_is_writable (f);
277 278
	if (is_appendonly (f)) {
		TRY (h5priv_append_attrib (
Gsell Achim's avatar
* C-API  
Gsell Achim committed
279
			     f->iteration_gid,
280 281 282 283 284 285
			     attrib_name,
			     attrib_type,
			     attrib_value,
			     attrib_nelem));
	} else {
		TRY (h5priv_write_attrib (
Gsell Achim's avatar
* C-API  
Gsell Achim committed
286
			     f->iteration_gid,
287 288 289 290 291 292
			     attrib_name,
			     attrib_type,
			     attrib_value,
			     attrib_nelem));
	}
	H5_RETURN (H5_SUCCESS);
293
}