Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reading string attribute from group returns weird results #28

Closed
fmanso opened this issue Jun 16, 2016 · 10 comments
Closed

Reading string attribute from group returns weird results #28

fmanso opened this issue Jun 16, 2016 · 10 comments

Comments

@fmanso
Copy link

fmanso commented Jun 16, 2016

Hello,

I am trying to read an string attribute and I am having two problems. The first one is that using the same file the string returned is not the same every run. The second one is related to charset, I think.

I attached a sample. The HDF5 file only have one group with attributes. The problem is the string attribute called 'name'. The code is this:

var HDF5 = require('hdf5');
var HDF5_GLOBALS = require('hdf5/lib/globals');
var hdf5 = HDF5.hdf5;
var h5lt = HDF5.h5lt;
var Access = HDF5_GLOBALS.Access;

var hdf5File = new hdf5.File("sample.h5", Access.ACC_RDONLY);
var hdf5Group = hdf5File.openGroup("neuron_layer_0");

hdf5Group.refresh();
console.dir(hdf5Group);
hdf5Group.refresh();
console.dir(hdf5Group);
hdf5Group.refresh();
console.dir(hdf5Group);

And the result is:
captura

HDFView show this properties on the group:
image

sample.zip

@rimmartin
Copy link
Collaborator

Thank you for the sample and presentation of problem. Will study it

@rimmartin
Copy link
Collaborator

It is a variable length string attribute; I'm adding support for it. Should get it over the weekend

@rimmartin
Copy link
Collaborator

rimmartin commented Jun 17, 2016

Beginning to read. Have to think how to keep the difference of the string type in javascript to be able retain type when flushing back to the h5.

And i see you have array of doubles also as an attribute. I'll add more support for attributes in general including when they are arrays

@fmanso
Copy link
Author

fmanso commented Jun 17, 2016

Great, thank you so much.

El vie., 17 jun. 2016 15:23, rimmartin notifications@github.com escribió:

Beginning to read. Have to think how to keep the difference of the string
type in javascript to be able retain type when flushing back to the h5.

Also i see you have array of doubles also as an attribute. I'll add more
support for attributes in general including when they are arrays


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
#28 (comment),
or mute the thread
https://github.com/notifications/unsubscribe/AApF0JfdCrAJNRoogFlYkfi9zb3UMwM3ks5qMp_HgaJpZM4I3Loo
.

@rimmartin
Copy link
Collaborator

For where the type needs to be preserved I'm putting in string objects when writing and returning string objects with the type.

reading

var hdf5Group = hdf5File.openGroup("neuron_layer_0");
hdf5Group.refresh();
var type=hdf5Group.name.type;
console.dir(hdf5Group.name);

where type will be "variable-length" and name is "mflayer"

For writing

var hdf5Group = hdf5File.openGroup("neuron_layer_0");
var name=new String("mflayer");
name.type="variable-length";
hdf5Group.name=name;

Hopefully a few more evenings

@fmanso
Copy link
Author

fmanso commented Jun 22, 2016

Looks nice, thanks !

@rimmartin
Copy link
Collaborator

There is now a test that creates an h5 with attributes similar to yours:
https://github.com/HDF-NI/hdf5.node/blob/master/test/test_attributes.js

mocha --harmony --require should --require co-mocha ./test/test_attributes.js #2> /dev/null

adding other changes and tests before publishing so you might want to clone from here. Especially if you have other as yet unsupported h5's.

@fmanso
Copy link
Author

fmanso commented Jun 25, 2016

Thanks. I will be able to try it on next monday, but I am not sure I am going to know how to build from cloned repo. Please tell me when it is available in npm. Thanks.

@fmanso
Copy link
Author

fmanso commented Jun 29, 2016

I managed to compile and test. It is working like a charm. Thank you !

@rimmartin
Copy link
Collaborator

Oh great! I'll publish after getting a few more types handled

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants