[ismrmrd] 19/177: Can now read acquisition.
Ghislain Vaillant
ghisvail-guest at moszumanska.debian.org
Wed Jan 14 20:01:57 UTC 2015
This is an automated email from the git hooks/post-receive script.
ghisvail-guest pushed a commit to annotated tag v1.1.0.beta.1
in repository ismrmrd.
commit 3b1be25da8e3b91d4e592171fb10ec3a8209748e
Author: Souheil Inati <souheil.inati at nih.gov>
Date: Fri Aug 22 16:46:36 2014 -0400
Can now read acquisition.
---
examples/c/main.c | 20 ++++++++++++++--
ismrmrd_dataset.c | 68 ++++++++++++++++++++++++++++++++++++++++++++++++-------
2 files changed, 78 insertions(+), 10 deletions(-)
diff --git a/examples/c/main.c b/examples/c/main.c
index ccd48e0..9c91102 100644
--- a/examples/c/main.c
+++ b/examples/c/main.c
@@ -70,8 +70,24 @@ int main(void)
printf("Header: %s\n", xmlstring);
/* Get the number of acquisitions */
- printf("Number of Acquisitions: %lu\n", ismrmrd_get_number_of_acquisitions(&dataset2));
-
+ unsigned long nacq_read = ismrmrd_get_number_of_acquisitions(&dataset2);
+ printf("Number of Acquisitions: %lu\n", nacq_read);
+
+ /* read the next to last one */
+ ISMRMRD_Acquisition acq2;
+ unsigned long index = 0;
+ if (nacq_read>1) {
+ index = nacq_read - 1;
+ }
+ else {
+ index = 0;
+ }
+ printf("Acquisition index: %lu\n", index);
+ ismrmrd_read_acquisition(&dataset2, index, &acq2);
+ printf("Number of samples: %hu\n", acq2.head.number_of_samples);
+ printf("Flags: %llu\n", acq2.head.flags);
+ printf("Data[4]: %f, %f\n", creal(acq2.data[4]), cimag(acq2.data[4]));
+
/* Clean up */
free(xmlstring);
diff --git a/ismrmrd_dataset.c b/ismrmrd_dataset.c
index 154d5ad..90c42e8 100644
--- a/ismrmrd_dataset.c
+++ b/ismrmrd_dataset.c
@@ -435,7 +435,6 @@ int ismrmrd_append_acquisition(const ISMRMRD_Dataset *dset, const ISMRMRD_Acquis
hsize_t ext_dims[] = {1};
hsize_t offset[1] = {0};
herr_t h5status;
- int status;
/* The path to the acqusition data */
char *path = make_path(dset, "data");
@@ -452,7 +451,7 @@ int ismrmrd_append_acquisition(const ISMRMRD_Dataset *dset, const ISMRMRD_Acquis
h5status = H5Sget_simple_extent_dims(dataspace, dims, maxdims);
/* extend it by one */
dims[0] += 1;
- status = H5Dset_extent(dataset, dims);
+ h5status = H5Dset_extent(dataset, dims);
}
else {
/* create a new dataset for the data */
@@ -461,7 +460,7 @@ int ismrmrd_append_acquisition(const ISMRMRD_Dataset *dset, const ISMRMRD_Acquis
dataspace = H5Screate_simple(1, dims, maxdims);
props = H5Pcreate(H5P_DATASET_CREATE);
/* enable chunking so that the dataset is extensible */
- status = H5Pset_chunk (props, 1, chunk_dims);
+ h5status = H5Pset_chunk (props, 1, chunk_dims);
/* create */
dataset = H5Dcreate(dset->fileid, path, datatype, dataspace, H5P_DEFAULT, props, H5P_DEFAULT);
h5status = H5Pclose(props);
@@ -483,15 +482,71 @@ int ismrmrd_append_acquisition(const ISMRMRD_Dataset *dset, const ISMRMRD_Acquis
/* Write it */
h5status = H5Dwrite (dataset, datatype, memspace, filespace, H5P_DEFAULT, hdf5acq);
- fprintf(stderr,"Write status: %d\n", h5status);
+ /* TODO error check */
/* Clean up */
h5status = H5Tclose(datatype);
h5status = H5Sclose(dataspace);
+ h5status = H5Sclose(filespace);
+ h5status = H5Sclose(memspace);
h5status = H5Dclose(dataset);
+ free(path);
+
+ return ISMRMRD_NOERROR;
+};
+int ismrmrd_read_acquisition(const ISMRMRD_Dataset *dset, unsigned long index, ISMRMRD_Acquisition *acq) {
+ hid_t dataset, datatype, filespace, memspace;
+ hsize_t dims[1];
+ hsize_t offset[1];
+ hsize_t dimsr[1] = {1};
+ herr_t h5status;
+ HDF5_Acquisition hdf5acq;
+
+ /* The path to the acqusition data */
+ char *path = make_path(dset, "data");
- free(path);
+ /* Check the path, extend or create if needed */
+ if (link_exists(dset, path)) {
+ /* open */
+ dataset = H5Dopen(dset->fileid, path, H5P_DEFAULT);
+
+ /* The acquisition datatype */
+ datatype = get_hdf5type_acquisition();
+ /* TODO check that the dataset's datatype is correct */
+
+ filespace = H5Dget_space(dataset);
+ h5status = H5Sget_simple_extent_dims(filespace, dims, NULL);
+
+ if (index < dims[0]) {
+ offset[0] = index;
+ h5status = H5Sselect_hyperslab (filespace, H5S_SELECT_SET, offset, NULL, dimsr, NULL);
+ memspace = H5Screate_simple(1, dimsr, NULL);
+ h5status = H5Dread(dataset, datatype, memspace, filespace, H5P_DEFAULT, (void *) &hdf5acq);
+ memcpy(&acq->head, &hdf5acq.head, sizeof(ISMRMRD_AcquisitionHeader));
+ ismrmrd_make_consistent_acquisition(acq);
+ memcpy(acq->traj, hdf5acq.traj.p, ismrmrd_size_of_acquisition_traj(acq));
+ memcpy(acq->data, hdf5acq.data.p, ismrmrd_size_of_acquisition_data(acq));
+
+ /* clean up */
+ free(hdf5acq.traj.p);
+ free(hdf5acq.data.p);
+ h5status = H5Tclose(datatype);
+ h5status = H5Sclose(filespace);
+ h5status = H5Sclose(memspace);
+ h5status = H5Dclose(dataset);
+ }
+ else {
+ /* index out of range */
+ /* TODO throw an error */
+ return ISMRMRD_FILEERROR;
+ }
+ }
+ else {
+ /* No data */
+ /* TODO Throw error */
+ return ISMRMRD_FILEERROR;
+ }
return ISMRMRD_NOERROR;
};
@@ -499,9 +554,6 @@ int ismrmrd_append_acquisition(const ISMRMRD_Dataset *dset, const ISMRMRD_Acquis
/*****************************/
/* TODO Implement these ones */
/*****************************/
-int ismrmrd_read_acquisition(const ISMRMRD_Dataset *dset, unsigned long index, ISMRMRD_Acquisition *acq) {
- return ISMRMRD_NOERROR;
-};
int ismrmrd_append_image(const ISMRMRD_Dataset *dset, const char *varname,
const int block_mode, const ISMRMRD_Image *im) {
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/ismrmrd.git
More information about the debian-science-commits
mailing list