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

Convert number in 64 bit integer #44

Closed
Smurf81 opened this issue Apr 5, 2017 · 4 comments
Closed

Convert number in 64 bit integer #44

Smurf81 opened this issue Apr 5, 2017 · 4 comments

Comments

@Smurf81
Copy link

Smurf81 commented Apr 5, 2017

Hello,
i need to convert a javascript timestamp to HDF5 64 bit integer but i can't find a solution.
i tried this :
var buffer = Buffer.alloc(8); var now = new Date().getTime(); buffer.write(now.toString()); buffer.type=H5Type.H5T_STD_I64LE; h5lt.makeDataset(ContexteOptm.id,'DateMAJContexteOptm',buffer)
but instead of 1491403310065 i have 3689345520468833329
Anyone have an idea ?

Thanks a lot

@Smurf81
Copy link
Author

Smurf81 commented Apr 5, 2017

sorry i find the solution

@Smurf81 Smurf81 closed this as completed Apr 5, 2017
@rimmartin
Copy link
Collaborator

javascript does not have all 64 bits; the number is internally stored as a double which truncates the bits

I have a wrapper for Int64 for the id's but it doesn't really appear on the javascript side

What is the now object?

Is it a scalar you want to store or a table or dataset of many timestamps?

@Smurf81
Copy link
Author

Smurf81 commented Apr 5, 2017

a dataset, i finally found a solution like this
`const int64 = Date.now() // 1456909977176 (00 00 01 53 36 9a 06 58)
const b = new Buffer(8)
const MAX_UINT32 = 0xFFFFFFFF

// write
const big = ~~(int64 / MAX_UINT32)
const low = (int64 % MAX_UINT32) - big

b.writeUInt32BE(big, 0) // 00 00 01 53 00 00 00 00
b.writeUInt32BE(low, 4) // 00 00 01 53 36 9a 06 58
b.type=H5Type.H5T_STD_I64BE;`

My object is not a 64 bit integer in javascript but it's stored in 64bit integer in HDF5 file

I have another question : is it possible to add Attributes to a Dataset ?

@rimmartin
Copy link
Collaborator

property value pairs get written as attributes. To write them after the dataset exists I'm forgetting and will look into it.

For getting them without opening the dataset there is the getDatasetAttributes on groups and file.

https://hdf-ni.github.io/hdf5.node/tut/attributes-tutorial.html

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