[ismrmrd] 12/177: starting to work on the file stuff
Ghislain Vaillant
ghisvail-guest at moszumanska.debian.org
Wed Jan 14 20:01:56 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 dca3a79c5f76d0118c8da1103a210d106e5f2e3e
Author: Souheil Inati <souheil.inati at nih.gov>
Date: Fri Jul 25 22:23:00 2014 -0400
starting to work on the file stuff
---
ismrmrd.h | 13 +++-
ismrmrd.hpp | 3 +
ismrmrd_dataset.c | 189 +++++++++++++++++++++++++++++++++++++++++++++++++++
ismrmrd_dataset.h | 46 +++++++++----
tests/c/basic_test.c | 26 ++++++-
5 files changed, 261 insertions(+), 16 deletions(-)
diff --git a/ismrmrd.h b/ismrmrd.h
index 7aa04b6..ea46c09 100644
--- a/ismrmrd.h
+++ b/ismrmrd.h
@@ -46,7 +46,6 @@ extern "C" {
/**
* Constants
- *
*/
enum ISMRMRD_Constants {
ISMRMRD_VERSION = 1,
@@ -57,6 +56,15 @@ enum ISMRMRD_Constants {
ISMRMRD_NDARRAY_MAXDIM = 7
};
+
+/**
+ * Constants
+ */
+enum ISMRMRD_ErrorCodes {
+ ISMRMRD_NOERROR,
+ ISMRMRD_FILEERROR
+};
+
/**
* Data Types
*/
@@ -263,6 +271,9 @@ size_t ismrmrd_size_of_image_data(const ISMRMRD_Image *im);
/* NDArrays */
/************/
+/**
+ * A simple N dimensional array
+ */
typedef struct ISMRMRD_NDArray {
uint16_t version; /**< First unsigned int indicates the version */
uint16_t data_type; /**< e.g. unsigned short, float, complex float, etc. */
diff --git a/ismrmrd.hpp b/ismrmrd.hpp
index ce73635..182aa06 100644
--- a/ismrmrd.hpp
+++ b/ismrmrd.hpp
@@ -2,6 +2,9 @@
// ISMRMRD C++ Interface
//
+// TODO:
+// - exports for all the classes
+
#include "ismrmrd.h"
#pragma once
diff --git a/ismrmrd_dataset.c b/ismrmrd_dataset.c
new file mode 100644
index 0000000..38af869
--- /dev/null
+++ b/ismrmrd_dataset.c
@@ -0,0 +1,189 @@
+#include <hdf5.h>
+#include "ismrmrd_dataset.h"
+
+#include <stdio.h>
+
+#ifdef __cplusplus
+namespace ISMRMRD {
+extern "C" {
+#endif
+
+void ismrmrd_init_dataset(ISMRMRD_Dataset *dset) {
+ dset->filename = NULL;
+ dset->groupname = NULL;
+ dset->fileid = 0;
+ dset->datasetid = 0;
+}
+
+int ismrmrd_open_dataset(ISMRMRD_Dataset *dset, const bool create_if_needed) {
+ hid_t fileid, filetype, memtype, space, daset;
+ herr_t status;
+
+ /* Check if the file exists and is an HDF5 File */
+ status = H5Fis_hdf5(dset->filename);
+
+ if (status > 0) {
+ /* Positive value for exists and is HDF5 */
+ /* Open it in readwrite mode */
+ fileid = H5Fopen(dset->filename, H5F_ACC_RDWR, H5P_DEFAULT);
+ if (fileid > 0) {
+ dset->fileid = fileid;
+ }
+ else {
+ /* Error creating file */
+ // TODO raise error
+ return ISMRMRD_FILEERROR;
+ }
+ }
+ else if (status == 0) {
+ /* Zero value for exists and is NOT HDF5 */
+ //TODO raise error
+ return ISMRMRD_FILEERROR;
+ }
+ else {
+ /* Negative value for does NOT exist or other error */
+ if (create_if_needed == false) {
+ // TODO raise error
+ return ISMRMRD_FILEERROR;
+ }
+ else {
+ /* Create a new file using the default properties. */
+ /* this will be readwrite */
+ fileid = H5Fcreate(dset->filename, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
+ if (fileid > 0) {
+ dset->fileid = fileid;
+ }
+ else {
+ /* Error creating file */
+ // TODO raise error
+ return ISMRMRD_FILEERROR;
+ }
+ }
+ }
+
+ return ISMRMRD_NOERROR;
+};
+
+int ismrmrd_close_dataset(ISMRMRD_Dataset *dset) {
+
+ herr_t status;
+
+ /* Check for a valide fileid before trying to close the file */
+ if (dset->fileid > 0) {
+ status = H5Fclose (dset->fileid);
+ dset->fileid = 0;
+ }
+ return ISMRMRD_NOERROR;
+};
+
+int ismrmrd_write_xml_header(const ISMRMRD_Dataset *dset, const char *xml) {
+ return ISMRMRD_NOERROR;
+};
+
+int ismrmrd_read_xml_header(const ISMRMRD_Dataset *dset, char *xml) {
+ return ISMRMRD_NOERROR;
+};
+
+int ismrmrd_append_acquisition(const ISMRMRD_Dataset *dset, const ISMRMRD_Acquisition *a) {
+ return ISMRMRD_NOERROR;
+};
+
+int ismrmrd_read_acquisition(const ISMRMRD_Dataset *dset, unsigned long index, ISMRMRD_Acquisition *a) {
+ return ISMRMRD_NOERROR;
+};
+
+unsigned long ismrmrd_get_number_of_acquisitions(const ISMRMRD_Dataset *dset) {
+ return ISMRMRD_NOERROR;
+};
+
+int ismrmrd_append_image(const ISMRMRD_Dataset *dset, const char *varname,
+ const int block_mode, const ISMRMRD_Image *im) {
+ return ISMRMRD_NOERROR;
+};
+
+int ismrmrd_read_image(const ISMRMRD_Dataset *dset, const char *varname,
+ const unsigned long index, ISMRMRD_Image *im) {
+ return ISMRMRD_NOERROR;
+};
+
+int ismrmrd_get_number_of_images(const ISMRMRD_Dataset *dset, const char *varname) {
+ return ISMRMRD_NOERROR;
+};
+
+int ismrmrd_append_array(const ISMRMRD_Dataset *dset, const char *varname,
+ const int block_mode, const ISMRMRD_NDArray *arr) {
+ return ISMRMRD_NOERROR;
+};
+
+int ismrmrd_read_array(const ISMRMRD_Dataset *dataset, const char *varname,
+ const unsigned long index, ISMRMRD_NDArray *arr) {
+ return ISMRMRD_NOERROR;
+};
+
+int ismrmrd_get_number_of_arrays(const ISMRMRD_Dataset *dset, const char *varname) {
+ return ISMRMRD_NOERROR;
+};
+
+
+#ifdef __cplusplus
+} /* extern "C" */
+} /* ISMRMRD namespace */
+#endif
+
+
+
+#ifdef YOMAMA
+xml_header_path_ = groupname_ + std::string("/xml");
+data_path_ = groupname_ + std::string("/data");
+
+hid_t t;
+
+t = this->type_container_.get_type<float>();
+std::cout << "Type for float: " << t << std::endl;
+
+t = this->type_container_.get_type<double>();
+std::cout << "Type for double: " << t << std::endl;
+
+t = this->type_container_.get_type<std::complex<float> >();
+std::cout << "Type for complex float: " << t << std::endl;
+
+t = this->type_container_.get_type<std::complex<double> >();
+std::cout << "Type for complex double: " << t << std::endl;
+
+t = this->type_container_.get_type<EncodingCounters>();
+std::cout << "Type for EncodingCounters: " << t << std::endl;
+
+t = this->type_container_.get_type<AcquisitionHeader>();
+std::cout << "Type for AcquisitionHeader: " << t << std::endl;
+
+t = this->type_container_.get_type<AcquisitionHeader_with_data>();
+std::cout << "Type for AcquisitionHeader_with_data: " << t << std::endl;
+
+t = this->type_container_.get_type<ImageHeader>();
+std::cout << "Type for ImageHeader: " << t << std::endl;
+
+t = this->type_container_.get_type<ImageHeader_with_data<float> >();
+std::cout << "Type for ImageHeader_with_data<float>: " << t << std::endl;
+
+t = this->type_container_.get_type<ImageHeader_with_data<double> >();
+std::cout << "Type for ImageHeader_with_data<double>: " << t << std::endl;
+
+t = this->type_container_.get_type<ImageHeader_with_data<unsigned short> >();
+std::cout << "Type for ImageHeader_with_data<unsigned short>: " << t << std::endl;
+
+t = this->type_container_.get_type<ImageHeader_with_data<ccomplex_t> >();
+std::cout << "Type for ImageHeader_with_data<ccomplex_t>: " << t << std::endl;
+
+t = this->type_container_.get_type<ImageHeader_with_data<cdouble_complex_t> >();
+std::cout << "Type for ImageHeader_with_data<cdouble_complex_t>: " << t << std::endl;
+
+t = this->type_container_.get_type<ImageHeader_with_data<std::complex<float> > >();
+std::cout << "Type for ImageHeader_with_data< std::complex<float> >: " << t << std::endl;
+
+t = this->type_container_.get_type<ImageHeader_with_data<std::complex<double> > >();
+std::cout << "Type for ImageHeader_with_data< std::complex<double> >: " << t << std::endl;
+
+t = this->type_container_.get_type<std::string>();
+std::cout << "Type for std::string: " << t << std::endl;
+
+#endif
diff --git a/ismrmrd_dataset.h b/ismrmrd_dataset.h
index 8a46640..57c3cd1 100644
--- a/ismrmrd_dataset.h
+++ b/ismrmrd_dataset.h
@@ -5,7 +5,6 @@
#define ISMRMRD_DATASET_H
#include "ismrmrd.h"
-#include <hdf5.h>
#ifdef __cplusplus
namespace ISMRMRD {
@@ -19,7 +18,7 @@ enum ISMRMRD_BlockModes {
ISMRMRD_BLOCKMODE_ARRAY,
ISMRMRD_BLOCKMODE_BLOBS
};
-
+
/**
* Interface for accessing an ISMRMRD Data Set stored on disk in HDF5 format.
*
@@ -30,16 +29,23 @@ enum ISMRMRD_BlockModes {
*
*/
typedef struct ISMRMRD_Dataset {
- char *filename_;
- char *groupname_;
- int dataset_;
+ char *filename;
+ char *groupname;
+ int fileid;
+ int datasetid;
} ISMRMRD_Dataset;
/**
+ * Initializes an ISMRMRD dataset structure
+ *
+ */
+void ismrmrd_init_dataset(ISMRMRD_Dataset *dset);
+
+/**
* Opens an ISMRMRD dataset.
*
*/
-int ismrmrd_open_dataset(ISMRMRD_Dataset *dset);
+int ismrmrd_open_dataset(ISMRMRD_Dataset *dset, const bool create_if_neded);
/**
* Closes all references to the underlying HDF5 file.
@@ -57,15 +63,18 @@ int ismrmrd_write_xml_header(const ISMRMRD_Dataset *dset, const char *xml);
/**
* Reads the XML configuration header from the dataset.
+ *
+ * @warning There is no check of whether the string is a valid XML document at this point.
+ *
*/
int ismrmrd_read_xml_header(const ISMRMRD_Dataset *dset, char *xml);
/**
* Appends and NMR/MRI acquisition to the dataset.
*
- * Please consult @See Acquisition struct for details.
+ * Please consult @See ISMRMRD_Acquisition struct for details.
*/
-int ismrmrd_append_acquisition(const ISMRMRD_Dataset *dset, const Acquisition *a);
+int ismrmrd_append_acquisition(const ISMRMRD_Dataset *dset, const ISMRMRD_Acquisition *a);
/**
* Reads the acquisition with the specified index from the dataset.
@@ -80,7 +89,7 @@ unsigned long ismrmrd_get_number_of_acquisitions(const ISMRMRD_Dataset *dset);
/**
* Appends an Image to the variable named varname in the dataset.
*
- * Please consult @See Image struct for details.
+ * Please consult @See ISMRMRD_Image struct for details.
*
* Images can be stored in one of two ways. In either case headers and attribute strings are stored
* separatey for each of image. This allows for easy viewing and reading in other applications.
@@ -93,14 +102,19 @@ unsigned long ismrmrd_get_number_of_acquisitions(const ISMRMRD_Dataset *dset);
*
*/
int ismrmrd_append_image(const ISMRMRD_Dataset *dset, const char *varname,
- const int blockmode, const *Image);
+ const int block_mode, const ISMRMRD_Image *im);
/**
* Reads an image stored with appendImage.
* The index indicates which image to read from the variable named varname.
*/
int ismrmrd_read_image(const ISMRMRD_Dataset *dset, const char *varname,
- const unsigned long index, Image *im);
+ const unsigned long index, ISMRMRD_Image *im);
+
+/**
+ * Return the number of images in the variable varname in the dataset.
+ */
+int ismrmrd_get_number_of_images(const ISMRMRD_Dataset *dset, const char *varname);
/**
* Appends an NDArray to the variable named varname in the dataset.
@@ -117,14 +131,20 @@ int ismrmrd_read_image(const ISMRMRD_Dataset *dset, const char *varname,
*
*/
int ismrmrd_append_array(const ISMRMRD_Dataset *dset, const char *varname,
- const int blockmode, const ISMRMRD_NDArray *arr);
+ const int block_mode, const ISMRMRD_NDArray *arr);
/**
- * Reads a multi-dimensional array from the data file.
+ * Reads an array from the data file.
*/
int ismrmrd_read_array(const ISMRMRD_Dataset *dataset, const char *varname,
const unsigned long index, ISMRMRD_NDArray *arr);
+/**
+ * Return the number of arrays in the variable varname in the dataset.
+ */
+int ismrmrd_get_number_of_arrays(const ISMRMRD_Dataset *dset, const char *varname);
+
+
#ifdef __cplusplus
} /* extern "C" */
} /* ISMRMRD namespace */
diff --git a/tests/c/basic_test.c b/tests/c/basic_test.c
index 7f7bd3e..030c46b 100644
--- a/tests/c/basic_test.c
+++ b/tests/c/basic_test.c
@@ -1,5 +1,8 @@
#include <stdio.h>
-#include <ismrmrd.h>
+#include "ismrmrd.h"
+#include "ismrmrd_dataset.h"
+
+#include <hdf5.h>
int main(void)
{
@@ -18,7 +21,6 @@ int main(void)
printf("Flags: %llu\n", acq.head.flags);
printf("ACQ_FIRST_IN_SLICE: %d\n", ismrmrd_is_flag_set(acq.head.flags, ISMRMRD_ACQ_FIRST_IN_SLICE));
-
// Image im;
//initImage(&im);
//printf("Image Version: %d\n", im.head.version);
@@ -28,5 +30,25 @@ int main(void)
//printf("Array ndim: %d\n", arr.ndim);
//printf("Array dim[0]: %d\n", arr.dims[0]);
+ ISMRMRD_Dataset dataset;
+ ismrmrd_init_dataset(&dataset);
+ dataset.filename = "test.h5";
+
+ int status;
+ status = ismrmrd_open_dataset(&dataset, true);
+ printf("Status from open: %d\n", status);
+ printf("File_id: %d\n", dataset.fileid);
+
+ status = H5Fis_hdf5(dataset.filename);
+ printf("Status from H5is_hdf5: %d\n", status);
+
+ status = ismrmrd_close_dataset(&dataset);
+ printf("File_id: %d\n", dataset.fileid);
+ printf("File close status: %d\n", status);
+
+ //const char *filename="test.h5";
+ //const char *datasetname="Today";
+ //const char *xmlstring = "This is the end my friend.";
+
return 0;
}
--
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