[Nexus] How to access data
Tim Gruene
tgruene at gwdg.de
Mon Jun 16 14:39:06 BST 2014
Hi Tobias,
thanks a lot - your explanation fixed my understanding, and now it works
just fine.
(I personally don't like python and prefer a pure C[++]-solution.)
Regards,
Tim
On 06/13/2014 12:20 PM, Tobias.Richter at diamond.ac.uk wrote:
> Hi Tim,
>
> The simple version to read the data is NXgetdata which will read all of it. That may well run out of memory.
> With NXgetslab you can bite off chunks the size you can chew. Slab_start and Slab_size need to be of the same rank as the data.
> Slab_size tells the API how big the data volume is you want and Slab_start tells it where to get it from.
>
> For example: So if you want to read the 35st image out of a stack of 150, with a data shape like this: (150, 640, 480) You pick slab_start as (34,0,0) and slab_size as (1, 640,480).
>
> If I just needed to dump out the data somehow I'd use python/h5py or nexpy: http://nexpy.github.io/nexpy/ unless there was a particular other reason to use C. That may just be my preference though.
>
> Regards,
>
> Tobias
>
>
> -----Original Message-----
> From: NeXus [mailto:nexus-bounces at nexusformat.org] On Behalf Of Tim Gruene
> Sent: 12 June 2014 21:13
> To: nexus at nexusformat.org
> Subject: [Nexus] How to access data
>
> Dear all,
>
> I have a file in Nexus format (HDF v.5) and I would like to access the data at /run_466/tof_detector_1/single_events_time
> /run_466/tof_detector_1/single_events_x
> /run_466/tof_detector_1/single_events_y
>
> from a C or C++ program.
> So far I got stepwise into the groups so that
> NXopendata (myfile, (dir_tof1 + "/single_events_x").c_str()); returned NX_OK.
>
> At this point I don't know how to proceed. I looked at the online API documentation and the example file napi_test.c
>
> I assume for the 3x1.5 million numbers, the functionNXgetslab would be helpful. In napi_test.c the calls are:
> NXgetslab (fileid, data_buffer, slab_start, slab_size)
>
> the data_buffer is the memory block where the data get stored, I assume.
> It was allocated with
> NXmalloc ((void **) &data_buffer, NXrank, NXdims, NXtype)
>
> Question 1: does this allocate the memory for the entire data? If so, what if there is too much data for the RAM of my computer?
>
> I also don't understand the roles of slab_start and slab_size. In napi_test.c, these are two-dimensional arrays.
>
> Question 2: Is it correct that for my one-dimensional data "single_events_time" I require a one-dimesional
> int slab_start[1], slab_size[1];
> respectively?
>
> Question 3: I would think that NXgetslab reads data according to the rank of the data beginning at entries number slab_start[0], slab_start[1], ... and reads a total number of slab_size[0], slab_size[1], ... into memory at once. Is this correct?
>
> Question 4: Is there a simple way to access the one-dimensional data in single_events_time, single_events_x, and single_events_y?
> I used the DUMP command in the utility nxbrowse in order to create plain text files containing the data just to test my ideas, which work greatly. So all I need is a C-version of dumping the data out of the nexus-container.
>
> I greatly appreciate any help, maybe a link to a decent tutorial (for C or C++) on how to read nexus format. Many of the tutorials start with how to write nexus, which is confusing to me and something I don't need.
>
> Regards,
> Tim Gruene
> --
> Dr Tim Gruene
> Institut fuer anorganische Chemie
> Tammannstr. 4
> D-37077 Goettingen
>
> GPG Key ID = A46BEE1A
> _______________________________________________
> NeXus mailing list
> NeXus at nexusformat.org
> http://lists.nexusformat.org/mailman/listinfo/nexus
>
--
Dr Tim Gruene
Institut fuer anorganische Chemie
Tammannstr. 4
D-37077 Goettingen
GPG Key ID = A46BEE1A
More information about the NeXus
mailing list