Skip to content

Commit

Permalink
Merge pull request #81 from usnistgov/datatype_metadata
Browse files Browse the repository at this point in the history
adding method to read metadata for committed Datatype
  • Loading branch information
bmaranville authored Aug 26, 2024
2 parents 3da96ac + 80b4852 commit 7b0932d
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 4 deletions.
5 changes: 4 additions & 1 deletion src/hdf5_hl.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,11 @@ export declare class ExternalLink {
constructor(filename: string, obj_path: string);
}
export declare class Datatype {
file_id: bigint;
path: string;
type: OBJECT_TYPE;
constructor();
constructor(file_id: bigint, path: string);
get metadata(): Metadata;
}
export declare class Reference {
ref_data: Uint8Array;
Expand Down
13 changes: 11 additions & 2 deletions src/hdf5_hl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -524,8 +524,17 @@ export class ExternalLink {
}

export class Datatype {
file_id: bigint;
path: string;
type: OBJECT_TYPE = OBJECT_TYPE.DATATYPE
constructor() {}
constructor(file_id: bigint, path: string) {
this.file_id = file_id;
this.path = path;
}

get metadata() {
return Module.get_datatype_metadata(this.file_id, this.path);
}
}

export class Reference {
Expand Down Expand Up @@ -736,7 +745,7 @@ export class Group extends HasAttrs {
return new ExternalLink(filename, obj_path);
}
else if (type === Module.H5G_TYPE) {
return new Datatype()
return new Datatype(this.file_id, fullpath);
}
// unknown type or object not found
return null
Expand Down
19 changes: 19 additions & 0 deletions src/hdf5_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,24 @@ val get_dtype_metadata(hid_t dtype)
return attr;
}

val get_datatype_metadata(hid_t loc_id, const std::string& dtype_name_string)
{
hid_t dtype_id;
herr_t status;
const char *dtype_name = dtype_name_string.c_str();

dtype_id = H5Topen2(loc_id, dtype_name, H5P_DEFAULT);
if (dtype_id < 0)
{
throw_error("error - name not defined!");
return val::null();
}
val metadata = get_dtype_metadata(dtype_id);

H5Tclose(dtype_id);
return metadata;
}

val get_abstractDS_metadata(hid_t dspace, hid_t dtype, hid_t dcpl)
{
val attr = get_dtype_metadata(dtype);
Expand Down Expand Up @@ -1282,6 +1300,7 @@ EMSCRIPTEN_BINDINGS(hdf5)
function("get_attribute_names", &get_attribute_names);
function("get_attribute_metadata", &get_attribute_metadata);
function("get_dataset_metadata", &get_dataset_metadata);
function("get_datatype_metadata", &get_datatype_metadata);
function("get_dataset_filters", &get_dataset_filters);
function("refresh_dataset", &refresh_dataset);
function("get_dataset_data", &get_dataset_data);
Expand Down
1 change: 1 addition & 0 deletions src/hdf5_util_helpers.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ export interface H5Module extends EmscriptenModule {
refresh_dataset(file_id: bigint, path: string): number;
resize_dataset(file_id: bigint, path: string, new_size: bigint[]): number;
get_dataset_metadata(file_id: bigint, path: string): Metadata;
get_datatype_metadata(file_id: bigint, path: string): Metadata;
get_dataset_filters(file_id: bigint, path: string): Filter[];
flush(file_id: bigint): number;
ccall: typeof ccall;
Expand Down
12 changes: 11 additions & 1 deletion test/datatype_test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,17 @@ async function datatype_test() {
await h5wasm.ready;
var f = new h5wasm.File('./test/array.h5', 'r');

assert.deepEqual(f.get('datatype/value'), new h5wasm.Datatype());
const datatype = f.get('datatype/value');
assert(datatype instanceof h5wasm.Datatype);
assert.deepEqual(datatype.metadata, {
signed: false,
type: 3,
cset: 0,
strpad: 1,
vlen: false,
littleEndian: false,
size: 10
});
}

export const tests = [
Expand Down

0 comments on commit 7b0932d

Please sign in to comment.