-
Notifications
You must be signed in to change notification settings - Fork 2
/
matio.hdf5.dll.pas
577 lines (518 loc) · 24.3 KB
/
matio.hdf5.dll.pas
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
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
unit matio.hdf5.dll;
////////////////////////////////////////////////////////////////////////////////
//
// Author: Jaap Baak
// https://github.com/transportmodelling/matio
//
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
interface
////////////////////////////////////////////////////////////////////////////////
Uses
SysUtils, Windows, matio;
Type
THdf5Dll = Class
private
DllHandle: THandle;
FH5P_CLS_GROUP_CREATE_ID,FH5P_CLS_DATASET_CREATE_ID,
FH5T_C_S1,FH5T_NATIVE_INT,FH5T_NATIVE_FLOAT,FH5T_NATIVE_DOUBLE: Int64;
FH5open: Function: Integer; cdecl;
FH5Fcreate: Function(FileName: PAnsiChar; Flags: UInt32; fcpl_id: Int64; fapl_id : Int64): Int64; cdecl;
FH5Fopen: Function(filename: PAnsiChar; flags: UInt32; access_plist: Int64): Int64; cdecl;
FH5Oopen: Function(FileId: Int64; Name: PAnsiChar; lapl_id: Int64): Int64; cdecl;
FH5Literate: Function(grp_id: Int64; idx_type: Integer; order: Integer; idx: PInt64; op: Pointer; op_data: Pointer): Integer; cdecl;
FH5Tcopy: Function(TypeId: Int64): Int64; cdecl;
FH5Tget_class: Function(type_id: Int64): Integer; cdecl;
FH5Tget_size: Function(type_id: Int64): UInt64; cdecl;
FH5Tset_size: Function(TypeId: Int64; Size: UInt32): Integer; cdecl;
FH5Tset_strpad: Function(TypeId: Int64; StrType: Integer): Integer; cdecl;
FH5Screate: Function(ClassType: Integer): Int64; cdecl;
FH5Screate_simple: Function(Rank: Integer; Dims: PUInt64; MaxDims: PUInt64): Int64; cdecl;
FH5Sselect_hyperslab: Function(SpaceId: Int64; op: Integer; start: PUInt64; _stride: PUInt64;
count: PUInt64; _block: PUInt64): Integer; cdecl;
FH5Sget_select_bounds: Function(spaceid: Int64; start: Pointer; end_: Pointer): Integer; cdecl;
FH5Acreate2: Function(ObjId: Int64; AttributeName: PAnsiChar; TypeId: Int64;
SpaceId: Int64; acpl_id: Int64; aapl_id: Int64): Int64; cdecl;
FH5Aopen_by_name: Function(ObjId: Int64; obj_name: PAnsiChar; attr_name: PAnsiChar; aapl_id: Int64; lapl_id: Int64): Int64; cdecl;
FH5Aget_type: Function(attr_id: Int64): Int64; cdecl;
FH5Aget_space: Function(attr_id: Int64): Int64; cdecl;
FH5Aget_storage_size: Function(attr_id: Int64): UInt64; cdecl;
FH5Aread: Function(attr_id: Int64; type_id: Int64; Buf: Pointer): Integer; cdecl;
FH5Pcreate: Function(cls_id: Int64): Int64; cdecl;
FH5Pget_link_creation_order: Function(plist_id: Int64; crt_order_flags: PUInt32): Integer; cdecl;
FH5Pset_link_creation_order: Function(plist_id: Int64; crt_order_flags: UInt32): Integer; cdecl;
FH5Pset_chunk: Function(plist_id: Int64; ndims: Integer; dim: PUInt64): Integer; cdecl;
FH5Pset_deflate: Function(plist_id: Int64; aggression: UInt32): Integer; cdecl;
FH5Pset_fill_value: Function(plist_id: Int64; type_id: Int64; value: Pointer): Integer; cdecl;
FH5Gcreate2: Function(loc_id: Int64; Name: PAnsiChar; lcpl_id: Int64; gcpl_id: Int64; gapl_id: Int64): Int64; cdecl;
FH5Gopen2: Function(loc_id: Int64; Name: PAnsiChar; gapl_id: Int64): Int64; cdecl;
FH5Gget_create_plist: Function(group_id: Int64): Int64; cdecl;
FH5Gclose: Function(group_id: Int64): Integer; cdecl;
FH5Awrite: Function(AttributeId: Int64; TypeId: Int64; Buf: Pointer): Integer; cdecl;
FH5Dcreate2: Function(loc_id: Int64; name: PAnsiChar; type_id: Int64; space_id: Int64;
lcpl_id: Int64; dcpl_id: Int64; dapl_id: Int64): Int64; cdecl;
FH5Dopen2: Function(file_id: Int64; name: PAnsiChar; dapl_id: Int64): Int64; cdecl;
FH5Dget_type: Function(dset_id: Int64): Int64; cdecl;
FH5Dget_space: Function(dset_id: Int64): Int64; cdecl;
FH5Dread: Function(dset_id: Int64; mem_type_id: Int64; mem_space_id: Int64; file_space_id: Int64; plist_id: Int64; buf: Pointer): Integer; cdecl;
FH5Dwrite: Function(dset_id: Int64; mem_type_id: Int64; mem_space_id: Int64;
file_space_id: Int64; plist_id: Int64; buf: Pointer): Integer; cdecl;
FH5Dclose: Function(dset_id: Int64): Integer; cdecl;
FH5Aclose: Function(AttributeId: Int64): Integer; cdecl;
FH5Sclose: Function(SpaceId: Int64): Integer; cdecl;
FH5Tclose: Function(TypeId: Int64): Integer; cdecl;
FH5Oclose: Function(ObjectId: Int64): Integer; cdecl;
FH5Pclose: Function(Listid: Int64): Integer; cdecl;
FH5Fclose: Function(FileId: Int64): Integer; cdecl;
FH5close: Function: Integer; cdecl;
Function GetDllMethod(MethodName: String): Pointer;
public
Constructor Create(const DllPath: string);
// Dll methods
Procedure H5open;
Function H5Fcreate(FileName: AnsiString; Flags: UInt32; fcpl_id: Int64; fapl_id : Int64): Int64;
Function H5Fopen(FileName: AnsiString; flags: UInt32; access_plist: Int64): Int64;
Function H5Oopen(FileId: Int64; Name: AnsiString; lapl_id: Int64): Int64;
Function H5Literate(grp_id: Int64; idx_type: Integer; order: Integer; idx: PInt64; op: Pointer; op_data: Pointer): Integer;
Function H5Tcopy(TypeId: Int64): Int64;
Function H5Tget_class(type_id: Int64): Integer;
Function H5Tget_size(type_id: Int64): UInt64;
Procedure H5Tset_size(TypeId: Int64; Size: UInt32);
Procedure H5Tset_strpad(TypeId: Int64; StrType: Integer);
Function H5Screate(ClassType: Integer): Int64;
Function H5Screate_simple(Rank: Integer; Dims: PUInt64): Int64;
Procedure H5Sselect_hyperslab(SpaceId: Int64; op: Integer; const start,stride,count,block);
Function H5Acreate2(FileId: Int64; AttributeName: AnsiString; TypeId: Int64;
SpaceId: Int64; acpl_id: Int64; aapl_id: Int64): Int64;
Function H5Aopen_by_name(ObjId: Int64; obj_name,attr_name: AnsiString; aapl_id: Int64; lapl_id: Int64): Int64;
Function H5Aget_type(attr_id: Int64): Int64;
Function H5Aget_space(attr_id: Int64): Int64;
Function H5Aget_storage_size(attr_id: Int64): UInt64;
Procedure H5Aread(attr_id: Int64; type_id: Int64; Buf: Pointer);
Function H5Pcreate(cls_id: Int64): Int64;
Function H5Pget_link_creation_order(plist_id: Int64): UInt32;
Procedure H5Pset_link_creation_order(plist_id: Int64; crt_order_flags: UInt32);
Procedure H5Pset_chunk(plist_id: Int64; ndims: Integer; dim: PUInt64);
Procedure H5Pset_deflate(plist_id: Int64; aggression: UInt32);
Procedure H5Pset_fill_value(plist_id: Int64; type_id: Int64; value: Pointer);
Function H5Gcreate2(loc_id: Int64; Name: AnsiString; lcpl_id: Int64; gcpl_id: Int64; gapl_id: Int64): Int64;
Function H5Gopen2(loc_id: Int64; Name: AnsiString; gapl_id: Int64): Int64;
Function H5Gget_create_plist(group_id: Int64): Int64;
Function H5Gclose(group_id: Int64): Integer;
Procedure H5Awrite(AttributeId: Int64; TypeId: Int64; Buf: Pointer);
Function H5Dcreate2(loc_id: Int64; name: AnsiString; type_id: Int64; space_id: Int64;
lcpl_id: Int64; dcpl_id: Int64; dapl_id: Int64): Int64;
Function H5Dopen2(file_id: Int64; name: AnsiString; dapl_id: Int64): Int64;
Function H5Dget_type(dset_id: Int64): Int64;
Function H5Dget_space(dset_id: Int64): Int64;
Procedure H5Dread(dset_id: Int64; mem_type_id: Int64; mem_space_id: Int64;
file_space_id: Int64; plist_id: Int64; buf: Pointer);
Procedure H5Dwrite(dset_id: Int64; mem_type_id: Int64; mem_space_id: Int64;
file_space_id: Int64; plist_id: Int64; buf: Pointer);
Procedure H5Dclose(dset_id: Int64);
Procedure H5Aclose(AttributeId: Int64);
Procedure H5Sclose(SpaceId: Int64);
Procedure H5Tclose(TypeId: Int64);
Procedure H5Oclose(ObjectId: Int64);
Procedure H5Pclose(ListId: Int64);
Procedure H5Fclose(FileId: Int64);
Procedure H5close;
// Hdf5 utilities
Procedure CreateStringAttribute(ObjId: Int64; ObjectName,AttributeName,AttributeValue: AnsiString);
Procedure CreateIntAttribute(ObjId: Int64; ObjectName,AttributeName: AnsiString; const Data: Integer);
Procedure CreateIntArrayAttribute(ObjId: Int64; ObjectName,AttributeName: AnsiString; const ArrayData: array of Integer);
Procedure ReadStringAttribute(ObjId: Int64; ObjectName,AttributeName: AnsiString; var AttributeValue: AnsiString);
Procedure ReadIntArrayAttribute(ObjId: Int64; ObjectName,AttributeName: AnsiString; var ArrayData: array of Integer);
Destructor Destroy; override;
public
Const
H5P_DEFAULT = 0;
H5_ITER_INC = 0;
H5_ITER_DEC = 1;
H5F_ACC_RDONLY = 0;
H5F_ACC_TRUNC = 2;
H5P_CRT_ORDER_TRACKED = 1;
H5_INDEX_NAME = 0;
H5_INDEX_CRT_ORDER = 1;
H5S_SELECT_SET = 0;
H5T_STR_NULLTERM = 0;
H5S_SCALAR = 0;
H5T_FLOAT = 1;
Property H5T_C_S1: Int64 read FH5T_C_S1;
Property H5P_CLS_GROUP_CREATE_ID: Int64 read FH5P_CLS_GROUP_CREATE_ID;
Property H5P_CLS_DATASET_CREATE_ID: Int64 read FH5P_CLS_DATASET_CREATE_ID;
Property H5T_NATIVE_INT: Int64 read FH5T_NATIVE_INT;
Property H5T_NATIVE_FLOAT: Int64 read FH5T_NATIVE_FLOAT;
Property H5T_NATIVE_DOUBLE: Int64 read FH5T_NATIVE_DOUBLE;
end;
Var
Hdf5Dll: THdf5Dll = nil;
////////////////////////////////////////////////////////////////////////////////
implementation
////////////////////////////////////////////////////////////////////////////////
Constructor THdf5Dll.Create(const DllPath: string);
begin
inherited Create;
DllHandle := SafeLoadLibrary(DllPath);
if DllHandle <> 0 then
begin
// Load Hdf5 dll
FH5open := GetDllMethod('H5open');
FH5Fcreate := GetDllMethod('H5Fcreate');
FH5Fopen := GetDllMethod('H5Fopen');
FH5Oopen := GetDllMethod('H5Oopen');
FH5Literate := GetDllMethod('H5Literate1');
FH5Tcopy := GetDllMethod('H5Tcopy');
FH5Tget_class := GetDllMethod('H5Tget_class');
FH5Tget_size := GetDllMethod('H5Tget_size');
FH5Tset_size := GetDllMethod('H5Tset_size');
FH5Tset_strpad := GetDllMethod('H5Tset_strpad');
FH5Screate := GetDllMethod('H5Screate');
FH5Screate_simple := GetDllMethod('H5Screate_simple');
FH5Sselect_hyperslab := GetDllMethod('H5Sselect_hyperslab');
FH5Sget_select_bounds := GetDllMethod('H5Sget_select_bounds');
FH5Acreate2 := GetDllMethod('H5Acreate2');
FH5Aopen_by_name := GetDllMethod('H5Aopen_by_name');
FH5Aget_type := GetDllMethod('H5Aget_type');
FH5Aget_space := GetDllMethod('H5Aget_space');
FH5Aget_storage_size := GetDllMethod('H5Aget_storage_size');
FH5Aread := GetDllMethod('H5Aread');
FH5Pcreate := GetDllMethod('H5Pcreate');
FH5Pget_link_creation_order := GetDllMethod('H5Pget_link_creation_order');
FH5Pset_link_creation_order := GetDllMethod('H5Pset_link_creation_order');
FH5Pset_chunk := GetDllMethod('H5Pset_chunk');
FH5Pset_deflate := GetDllMethod('H5Pset_deflate');
FH5Pset_fill_value := GetDllMethod('H5Pset_fill_value');
FH5Gcreate2 := GetDllMethod('H5Gcreate2');
FH5Gopen2 := GetDllMethod('H5Gopen2');
FH5Gget_create_plist := GetDllMethod('H5Gget_create_plist');
FH5Gclose := GetDllMethod('H5Gclose');
FH5Awrite := GetDllMethod('H5Awrite');
FH5Dcreate2 := GetDllMethod('H5Dcreate2');
FH5Dopen2 := GetDllMethod('H5Dopen2');
FH5Dget_type := GetDllMethod('H5Dget_type');
FH5Dget_space := GetDllMethod('H5Dget_space');
FH5Dread := GetDllMethod('H5Dread');
FH5Dwrite := GetDllMethod('H5Dwrite');
FH5Dclose := GetDllMethod('H5Dclose');
FH5Aclose:= GetDllMethod('H5Aclose');
FH5Sclose := GetDllMethod('H5Sclose');
FH5Tclose := GetDllMethod('H5Tclose');
FH5Oclose := GetDllMethod('H5Oclose');
FH5Fclose := GetDllMethod('H5Fclose');
FH5Pclose := GetDllMethod('H5Pclose');
FH5close := GetDllMethod('H5close');
// Set constants
H5open;
FH5T_C_S1 := PInt64(GetDllMethod('H5T_C_S1_g'))^;
if FH5T_C_S1 < 0 then raise Exception.Create('Error getting H5T_C_S1');
FH5P_CLS_GROUP_CREATE_ID := PInt64(GetDllMethod('H5P_CLS_GROUP_CREATE_ID_g'))^;
if FH5P_CLS_GROUP_CREATE_ID < 0 then raise Exception.Create('Error getting H5P_CLS_GROUP_CREATE_ID');
FH5P_CLS_DATASET_CREATE_ID := PInt64(GetDllMethod('H5P_CLS_DATASET_CREATE_ID_g'))^;
if FH5P_CLS_DATASET_CREATE_ID < 0 then raise Exception.Create('Error getting H5P_CLS_DATASET_CREATE_ID');
FH5T_NATIVE_INT := PInt64(GetDllMethod('H5T_NATIVE_INT_g'))^;
if FH5T_NATIVE_INT < 0 then raise Exception.Create('Error getting H5T_NATIVE_INT');
FH5T_NATIVE_FLOAT := PInt64(GetDllMethod('H5T_NATIVE_FLOAT_g'))^;
if FH5T_NATIVE_FLOAT < 0 then raise Exception.Create('Error getting H5T_NATIVE_FLOAT');
FH5T_NATIVE_DOUBLE := PInt64(GetDllMethod('H5T_NATIVE_DOUBLE_g'))^;
if FH5T_NATIVE_DOUBLE < 0 then raise Exception.Create('Error getting H5T_NATIVE_DOUBLE');
end else
raise Exception.Create('Cannot load hdf5-dll');
end;
Function THdf5Dll.GetDllMethod(MethodName: String): Pointer;
begin
Result := GetProcAddress(DllHandle,PChar(MethodName));
if Result = nil then raise Exception.Create('Cannot load dll method ' + MethodName);
end;
Procedure THdf5Dll.H5open;
begin
if FH5Open < 0 then raise Exception.Create('Error calling H5open')
end;
Function THdf5Dll.H5Fcreate(FileName: AnsiString; Flags: UInt32; fcpl_id: Int64; fapl_id : Int64): Int64;
begin
Result := FH5Fcreate(PAnsiChar(FileName),Flags,fcpl_id,fapl_id);
if Result < 0 then raise Exception.Create('Error calling H5Fcreate')
end;
Function THdf5Dll.H5Fopen(FileName: AnsiString; flags: UInt32; access_plist: Int64): Int64;
begin
Result := FH5Fopen(PAnsiChar(FileName),flags,access_plist);
if Result < 0 then raise Exception.Create('Error calling H5Fopen')
end;
Function THdf5Dll.H5Oopen(FileId: Int64; Name: AnsiString; lapl_id: Int64): Int64;
begin
Result := FH5Oopen(FileId,PAnsiChar(Name),lapl_id);
if Result < 0 then raise Exception.Create('Error calling H5Oopen')
end;
Function THdf5Dll.H5Literate(grp_id: Int64; idx_type: Integer; order: Integer; idx: PInt64; op: Pointer; op_data: Pointer): Integer;
begin
Result := FH5Literate(grp_id,idx_type,order,idx,op,op_data);
if Result < 0 then raise Exception.Create('Error calling H5Literate')
end;
Function THdf5Dll.H5Tcopy(TypeId: Int64): Int64;
begin
Result := FH5Tcopy(TypeId);
if Result < 0 then raise Exception.Create('Error calling H5Tcopy')
end;
Function THdf5Dll.H5Tget_class(type_id: Int64): Integer;
begin
Result := FH5Tget_class(type_id);
if Result < 0 then raise Exception.Create('Error calling H5Tget_class')
end;
Function THdf5Dll.H5Tget_size(type_id: Int64): UInt64;
begin
Result := FH5Tget_size(type_id);
if Result < 0 then raise Exception.Create('Error calling H5Tget_size')
end;
Procedure THdf5Dll.H5Tset_size(TypeId: Int64; Size: UInt32);
begin
if FH5Tset_size(TypeId,Size) < 0 then raise Exception.Create('Error calling H5Tset_size')
end;
Procedure THdf5Dll.H5Tset_strpad(TypeId: Int64; StrType: Integer);
begin
if FH5Tset_strpad(TypeId,StrType) < 0 then raise Exception.Create('Error calling H5Tset_strpad')
end;
Function THdf5Dll.H5Screate(ClassType: Integer): Int64;
begin
Result := FH5Screate(ClassType);
if Result < 0 then raise Exception.Create('Error calling H5Screate')
end;
Function THdf5Dll.H5Screate_simple(Rank: Integer; Dims: PUInt64): Int64;
begin
Result := FH5Screate_simple(Rank,Dims,nil);
if Result < 0 then raise Exception.Create('Error calling H5Screate_simple')
end;
Procedure THdf5Dll.H5Sselect_hyperslab(SpaceId: Int64; op: Integer; const start,stride,count,block);
begin
if FH5Sselect_hyperslab(SpaceId,op,@start,@stride,@count,@block) < 0 then
raise Exception.Create('Error calling H5Sselect_hyperslab')
end;
Function THdf5Dll.H5Acreate2(FileId: Int64; AttributeName: AnsiString; TypeId: Int64;
SpaceId: Int64; acpl_id: Int64; aapl_id: Int64): Int64;
begin
Result := FH5Acreate2(FileId,PAnsiChar(AttributeName),TypeId,SpaceId,acpl_id,aapl_id);
if Result < 0 then raise Exception.Create('Error calling H5Acreate2')
end;
Function THdf5Dll.H5Aopen_by_name(ObjId: Int64; obj_name,attr_name: AnsiString; aapl_id: Int64; lapl_id: Int64): Int64;
begin
Result := FH5Aopen_by_name(ObjId,PAnsiChar(obj_name),PAnsiChar(attr_name),aapl_id,lapl_id);
if Result < 0 then raise Exception.Create('Error calling H5Aopen_by_name')
end;
Function THdf5Dll.H5Aget_type(attr_id: Int64): Int64;
begin
Result := FH5Aget_type(attr_id);
if Result < 0 then raise Exception.Create('Error calling H5Aget_type')
end;
Function THdf5Dll.H5Aget_space(attr_id: Int64): Int64;
begin
Result := FH5Aget_space(attr_id);
if Result < 0 then raise Exception.Create('Error calling H5Aget_space')
end;
Function THdf5Dll.H5Aget_storage_size(attr_id: Int64): UInt64;
begin
Result := FH5Aget_storage_size(attr_id);
end;
Procedure THdf5Dll.H5Aread(attr_id: Int64; type_id: Int64; Buf: Pointer);
begin
if FH5Aread(attr_id,type_id,Buf) < 0 then
raise Exception.Create('Error calling H5Aread')
end;
Function THdf5Dll.H5Pcreate(cls_id: Int64): Int64;
begin
Result := FH5Pcreate(cls_id);
if Result < 0 then raise Exception.Create('Error calling H5Pcreate')
end;
Function THdf5Dll.H5Pget_link_creation_order(plist_id: Int64): UInt32;
begin
if FH5Pget_link_creation_order(plist_id,@Result) < 0 then
raise Exception.Create('Error calling H5Pget_link_creation_order')
end;
Procedure THdf5Dll.H5Pset_link_creation_order(plist_id: Int64; crt_order_flags: UInt32);
begin
if FH5Pset_link_creation_order(plist_id,crt_order_flags) < 0 then
raise Exception.Create('Error calling H5Pset_link_creation_order')
end;
Procedure THdf5Dll.H5Pset_chunk(plist_id: Int64; ndims: Integer; dim: PUInt64);
begin
if FH5Pset_chunk(plist_id,ndims,dim) < 0 then raise Exception.Create('Error calling H5Pset_chunk')
end;
Procedure THdf5Dll.H5Pset_deflate(plist_id: Int64; aggression: UInt32);
begin
if FH5Pset_deflate(plist_id,aggression) < 0 then raise Exception.Create('Error calling H5Pset_deflate')
end;
Procedure THdf5Dll.H5Pset_fill_value(plist_id: Int64; type_id: Int64; value: Pointer);
begin
if FH5Pset_fill_value(plist_id,type_id,value) < 0 then raise Exception.Create('Error calling H5Pset_fill_value')
end;
Function THdf5Dll.H5Gcreate2(loc_id: Int64; Name: AnsiString; lcpl_id: Int64; gcpl_id: Int64; gapl_id: Int64): Int64;
begin
Result := FH5Gcreate2(loc_id,PAnsiChar(Name),lcpl_id,gcpl_id,gapl_id);
if Result < 0 then raise Exception.Create('Error calling H5Gcreate2')
end;
Function THdf5Dll.H5Gopen2(loc_id: Int64; Name: ANSIString; gapl_id: Int64): Int64;
begin
Result := FH5Gopen2(loc_id,PAnsiChar(Name),gapl_id);
if Result < 0 then raise Exception.Create('Error calling H5Gopen2')
end;
Function THdf5Dll.H5Gget_create_plist(group_id: Int64): Int64;
begin
Result := FH5Gget_create_plist(group_id);
if Result < 0 then raise Exception.Create('Error calling H5Gget_create_plist')
end;
Function THdf5Dll.H5Gclose(group_id: Int64): Integer;
begin
Result := FH5Gclose(group_id);
if Result < 0 then raise Exception.Create('Error calling H5Gclose')
end;
Procedure THdf5Dll.H5Awrite(AttributeId: Int64; TypeId: Int64; Buf: Pointer);
begin
if FH5Awrite(AttributeId,TypeId,Buf) < 0 then raise Exception.Create('Error calling H5Awrite')
end;
Function THdf5Dll.H5Dcreate2(loc_id: Int64; name: AnsiString; type_id: Int64; space_id: Int64;
lcpl_id: Int64; dcpl_id: Int64; dapl_id: Int64): Int64;
begin
Result := FH5Dcreate2(loc_id,PAnsiChar(name),type_id,space_id,lcpl_id,dcpl_id,dapl_id);
if Result < 0 then raise Exception.Create('Error calling H5Dcreate2')
end;
Function THdf5Dll.H5Dopen2(file_id: Int64; name: Ansistring; dapl_id: Int64): Int64;
begin
Result := FH5Dopen2(file_id,PAnsiChar(name),dapl_id);
if Result < 0 then raise Exception.Create('Error calling H5Dopen2')
end;
Function THdf5Dll.H5Dget_type(dset_id: Int64): Int64;
begin
Result := FH5Dget_type(dset_id);
if Result < 0 then raise Exception.Create('Error calling H5Dget_type')
end;
Function THdf5Dll.H5Dget_space(dset_id: Int64): Int64;
begin
Result := FH5Dget_space(dset_id);
if Result < 0 then raise Exception.Create('Error calling H5Dget_space')
end;
Procedure THdf5Dll.H5Dread(dset_id: Int64; mem_type_id: Int64; mem_space_id: Int64;
file_space_id: Int64; plist_id: Int64; buf: Pointer);
begin
if FH5Dread(dset_id,mem_type_id,mem_space_id,file_space_id,plist_id,buf) < 0 then
raise Exception.Create('Error calling H5Dread')
end;
Procedure THdf5Dll.H5Dwrite(dset_id: Int64; mem_type_id: Int64; mem_space_id: Int64;
file_space_id: Int64; plist_id: Int64; buf: Pointer);
begin
if FH5Dwrite(dset_id,mem_type_id,mem_space_id,file_space_id,plist_id,buf) < 0 then
raise Exception.Create('Error calling H5Dwrite')
end;
Procedure THdf5Dll.H5Dclose(dset_id: Int64);
begin
if FH5Dclose(dset_id) < 0 then raise Exception.Create('Error calling H5Dclose')
end;
Procedure THdf5Dll.H5Aclose(AttributeId: Int64);
begin
if FH5Aclose(AttributeId) < 0 then raise Exception.Create('Error calling H5Aclose')
end;
Procedure THdf5Dll.H5Sclose(SpaceId: Int64);
begin
if FH5Sclose(SpaceId) < 0 then raise Exception.Create('Error calling H5Sclose')
end;
Procedure THdf5Dll.H5Tclose(TypeId: Int64);
begin
if FH5Tclose(TypeId) < 0 then raise Exception.Create('Error calling H5Tclose')
end;
Procedure THdf5Dll.H5Oclose(ObjectId: Int64);
begin
if FH5Oclose(ObjectId) < 0 then raise Exception.Create('Error calling H5Oclose')
end;
Procedure THdf5Dll.H5Pclose(ListId: Int64);
begin
if FH5Pclose(ListId) < 0 then raise Exception.Create('Error calling H5Pclose')
end;
Procedure THdf5Dll.H5Fclose(FileId: Int64);
begin
if FH5Fclose(FileId) < 0 then raise Exception.Create('Error calling H5Fclose')
end;
Procedure THdf5Dll.H5close;
begin
if FH5close < 0 then raise Exception.Create('Error calling H5close')
end;
Procedure THdf5Dll.CreateStringAttribute(ObjId: Int64; ObjectName,AttributeName,AttributeValue: AnsiString);
Var
AttributeSize: UInt32;
ObjectId,TypeId,SpaceId,AttributeId: Int64;
begin
AttributeSize := Length(AttributeValue) + 1;
ObjectId := H5Oopen(ObjId,ObjectName,H5P_DEFAULT);
TypeId := H5Tcopy(H5T_C_S1);
H5Tset_size(TypeId,AttributeSize);
H5Tset_strpad(TypeId,H5T_STR_NULLTERM);
SpaceId := H5Screate(H5S_SCALAR);
AttributeId := H5Acreate2(ObjId,AttributeName,TypeId,SpaceId,H5P_DEFAULT,H5P_DEFAULT);
H5Awrite(AttributeId,TypeId,pAnsiChar(AttributeValue));
H5Aclose(AttributeId);
H5Sclose(SpaceId);
H5Tclose(TypeId);
H5Oclose(ObjectId);
end;
Procedure THdf5Dll.CreateIntAttribute(ObjId: Int64; ObjectName,AttributeName: AnsiString; const Data: Integer);
Var
ObjectId,SpaceId,AttributeId: Int64;
begin
ObjectId := H5Oopen(ObjId,ObjectName,H5P_DEFAULT);
SpaceId := H5Screate(H5S_SCALAR);
AttributeId := H5Acreate2(ObjId,AttributeName,H5T_NATIVE_INT,SpaceId,H5P_DEFAULT,H5P_DEFAULT);
H5Awrite(AttributeId,H5T_NATIVE_INT,@Data);
H5Aclose(AttributeId);
H5Sclose(SpaceId);
H5Oclose(ObjectId);
end;
Procedure THdf5Dll.CreateIntArrayAttribute(ObjId: Int64; ObjectName,AttributeName: AnsiString; const ArrayData: array of Integer);
Var
Len: UInt64;
ObjectId,SpaceId,AttributeId: Int64;
begin
Len := Length(ArrayData);
ObjectId := H5Oopen(ObjId,ObjectName,H5P_DEFAULT);
SpaceId := H5Screate_simple(1,@Len);
AttributeId := H5Acreate2(ObjId,AttributeName,H5T_NATIVE_INT,SpaceId,H5P_DEFAULT,H5P_DEFAULT);
H5Awrite(AttributeId,H5T_NATIVE_INT,@ArrayData[0]);
H5Aclose(AttributeId);
H5Sclose(SpaceId);
H5Oclose(ObjectId);
end;
Procedure THdf5Dll.ReadStringAttribute(ObjId: Int64; ObjectName,AttributeName: AnsiString; var AttributeValue: AnsiString);
var
AttributeId,TypeId,SpaceId: Int64;
AttributeSize: UInt64;
begin
AttributeID := H5Aopen_by_name(ObjID,ObjectName,AttributeName,H5P_DEFAULT,H5P_DEFAULT);
TypeID := H5Aget_type(AttributeId);
SpaceId := H5Aget_space(AttributeID);
AttributeSize := H5Aget_storage_size(AttributeId);
SetLength(AttributeValue, AttributeSize+1);
H5Aread(AttributeId,TypeId,pAnsiChar(AttributeValue));
H5Aclose(AttributeId);
H5Tclose(TypeId);
H5Sclose(SpaceId);
end;
Procedure THdf5Dll.ReadIntArrayAttribute(ObjId: Int64; ObjectName,AttributeName: AnsiString; var ArrayData: array of Integer);
Var
AttributeId,SpaceId: Int64;
begin
AttributeId := H5Aopen_by_name(ObjID,ObjectName,AttributeName,H5P_DEFAULT,H5P_DEFAULT);
SpaceId := H5Aget_space(AttributeID);
H5Aread(AttributeId,H5T_NATIVE_INT,@ArrayData[0]);
H5Aclose(AttributeId);
H5Sclose(SpaceId);
end;
Destructor THdf5Dll.Destroy;
begin
if DllHandle <> 0 then
begin
H5Close;
FreeLibrary(DllHandle);
end;
inherited Destroy;
end;
Initialization
var DllPath := ExtractFileDir(Paramstr(0)) + '\hdf5.dll';
if FileExists(DllPath) then Hdf5Dll := THdf5Dll.Create(DllPath);
Finalization
Hdf5Dll.Free;
end.