Mercurial > hg > minc-tools
changeset 1623:8c3fa53243a2
*** empty log message ***
author | baghdadi <baghdadi> |
---|---|
date | Fri, 09 Jan 2004 18:50:04 +0000 |
parents | 25d944d7007f |
children | 5f7662ae7a55 |
files | libsrc2/Makefile libsrc2/dimension.c libsrc2/m2util.c libsrc2/minc2_private.h libsrc2/volume.c |
diffstat | 5 files changed, 73 insertions(+), 24 deletions(-) [+] |
line wrap: on
line diff
--- a/libsrc2/Makefile +++ b/libsrc2/Makefile @@ -12,7 +12,7 @@ hyper.o \ label.o \ slice.o \ - valid.o + valid.o LIBS = -lminc -lnetcdf -lhdf5 -lm @@ -49,11 +49,13 @@ convert-test: $(convert-test-objs) gcc $(LDFLAGS) -Wall -g -o convert-test $(convert-test-objs) $(LIBS) - convert-test.o: convert.c minc2.h minc2_private.h gcc -DM2_TEST $(CPPFLAGS) -Wall -g -c -o convert-test.o convert.c +convert.o: convert.c minc2.h minc2_private.h + gcc $(CPPFLAGS) -Wall -g -c -o convert.o convert.c # slice.c + slice-test-objs = slice-test.o libminc2.a slice-test: $(slice-test-objs) @@ -65,8 +67,10 @@ slice.o: slice.c minc2.h minc2_private.h gcc $(CPPFLAGS) -Wall -g -c -o slice.o slice.c # hyper.c + hyper-test-objs = hyper-test.o libminc2.a + hyper-test: $(hyper-test-objs) gcc $(LDFLAGS) -Wall -g -o hyper-test $(hyper-test-objs) $(LIBS) @@ -89,6 +93,7 @@ gcc $(CPPFLAGS) -Wall -g -c -o dimension.o dimension.c # grpattr.c + grpattr-test-objs = grpattr-test.o libminc2.a grpattr-test: $(grpattr-test-objs) @@ -101,6 +106,7 @@ gcc $(CPPFLAGS) -Wall -g -c -o grpattr.o grpattr.c # datatype.c + datatype-test-objs = datatype-test.o libminc2.a datatype-test: $(datatype-test-objs) @@ -109,15 +115,23 @@ datatype-test.o: datatype.c minc2.h minc2_private.h gcc -DM2_TEST $(CPPFLAGS) -Wall -g -c -o datatype-test.o datatype.c +datatype.o: datatype.c minc2.h minc2_private.h + gcc $(CPPFLAGS) -Wall -g -c -o datatype.o datatype.c + # label.c + label-test-objs = label-test.o libminc2.a + label-test: $(label-test-objs) gcc $(LDFLAGS) -Wall -g -o label-test $(label-test-objs) $(LIBS) label-test.o: label.c minc2.h minc2_private.h gcc -DM2_TEST $(CPPFLAGS) -Wall -g -c -o label-test.o label.c +label.o: label.c minc2.h minc2_private.h + gcc $(CPPFLAGS) -Wall -g -c -o label.o label.c + # volprops.c volprops-test-objs = volprops-test.o libminc2.a @@ -130,8 +144,10 @@ volprops.o: volprops.c minc2.h minc2_private.h gcc $(CPPFLAGS) -Wall -g -c -o volprops.o volprops.c + valid-test-objs = valid-test.o libminc2.a + valid-test: $(valid-test-objs) gcc $(LDFLAGS) -Wall -g -o valid-test $(valid-test-objs) $(LIBS) @@ -145,7 +161,7 @@ gcc $(CPPFLAGS) -Wall -g -c -o volume.o volume.c m2util.o: m2util.c minc2.h minc2_private.h - gcc $(CPPFLAGS) -Wall -g -c -o m2util.o m2util.c -lm + gcc $(CPPFLAGS) -Wall -g -c -o m2util.o m2util.c -lm -lhdf5 free.o: free.c minc2.h minc2_private.h gcc $(CPPFLAGS) -Wall -g -c -o free.o free.c
--- a/libsrc2/dimension.c +++ b/libsrc2/dimension.c @@ -256,13 +256,13 @@ return (MI_ERROR); } free(dim_ptr->name); - if (dim_ptr->offsets != NULL) { + //if (dim_ptr->offsets != NULL) { free(dim_ptr->offsets); - } + //} free(dim_ptr->units); - if (dim_ptr->widths !=NULL) { + //if (dim_ptr->widths !=NULL) { free(dim_ptr->widths); - } + // } free(dim_ptr); return (MI_NOERROR); @@ -1220,11 +1220,11 @@ TESTRPT("failed", r); } printf( " N is %d \n", n); - r= miopen_volume("test.h5",MI2_OPEN_READ ,&vol1); + r= miopen_volume("test.h5",MI2_OPEN_READ ,&vol); if (r < 0) { TESTRPT("failed", r); } - r = miclose_volume(vol1); + r = miclose_volume(vol); if (r < 0) { TESTRPT("failed", r); }
--- a/libsrc2/m2util.c +++ b/libsrc2/m2util.c @@ -255,23 +255,26 @@ if (hdf_file < 0) { return (MI_ERROR); } - + /* Search through the path, descending into each group encountered. */ hdf_loc = midescend_path(hdf_file, path); if (hdf_loc < 0) { return (MI_ERROR); } - + hdf_attr = H5Aopen_name(hdf_loc, name); if (hdf_attr < 0) { return (MI_ERROR); } - + switch (data_type) { case MI_TYPE_INT: hdf_type = H5Tcopy(H5T_NATIVE_INT); break; + case MI_TYPE_UINT: + hdf_type = H5Tcopy(H5T_NATIVE_ULONG); + break; case MI_TYPE_FLOAT: hdf_type = H5Tcopy(H5T_NATIVE_FLOAT); break;
--- a/libsrc2/minc2_private.h +++ b/libsrc2/minc2_private.h @@ -33,7 +33,7 @@ /** The fixed path to the full-resolution image data. */ -#define MI_FULLIMAGE_PATH MI_ROOT_PATH "/image/0" +//#define MI_FULLIMAGE_PATH MI_ROOT_PATH "/image/0" /** Standard linear transform, a 4x4 matrix. */
--- a/libsrc2/volume.c +++ b/libsrc2/volume.c @@ -41,6 +41,7 @@ hid_t dataspace_id = -1; hsize_t hdf_count; char *name; + char dimorder[128]; int size; hsize_t hdf_chunk_size[MI2_MAX_BLOCK_EDGES]; @@ -48,6 +49,7 @@ volprops *props_handle; miinit(); + dimorder[0] = '\0'; /* Set string to empty */ if (filename == NULL || number_of_dimensions <=0 || dimensions == NULL || create_props == NULL) { @@ -135,22 +137,31 @@ } } - /* Try opening IMAGE dataset i.e. /minc-2.0/image/0/image or CREATE ONE! + /* Try creating IMAGE dataset i.e. /minc-2.0/image/0/image */ dimage_id = H5Dcreate(grp_fullimage_id, MI_DIMAGE_PATH, hdf_type, dataspace_id, hdf_plist); if (dimage_id < 0) { return (MI_ERROR); } - - /* Try opening DIMENSIONS GROUP i.e. /minc-2.0/dimensions or CREATE ONE! + /* Create the dimorder attribute, ordered comma-separated + list of dimension names. */ + + /* Try creating DIMENSIONS GROUP i.e. /minc-2.0/dimensions + */ grp_dimensions_id = H5Gcreate(grp_root_id, MI_FULLDIMENSIONS_PATH , 0); if (grp_dimensions_id < 0) { return (MI_ERROR); } for (i=0; i < number_of_dimensions ; i++) { + /* Create the dimorder string, ordered comma-separated + list of dimension names. + */ + strcat(dimorder, dimensions[i]->name); + strcat(dimorder, ","); + /* First create the dataspace required to create a dimension variable (dataset) */ @@ -332,6 +343,21 @@ H5Aclose(hdf_attr); } + + /* Create image attribute "dimorder" */ + hdf_type = H5Tcopy(H5T_C_S1); + H5Tset_size(hdf_type, MI2_CHAR_LENGTH); + dataspace_id = H5Screate(H5S_SCALAR); + /* Create attribute. */ + hdf_attr = H5Acreate(dimage_id, "dimorder", hdf_type, dataspace_id, H5P_DEFAULT); + if (hdf_attr < 0) { + return (MI_ERROR); + } + /* Write data to the attribute. */ + H5Awrite(hdf_attr, hdf_type, &dimorder); + /* Close attribute. */ + H5Aclose(hdf_attr); + /* "mitype_to_hdftype" returns a copy of the datatype, so the returned value must be explicitly freed with a call to H5Tclose(). Close all Groups and Datset. @@ -551,6 +577,7 @@ int r; r = miget_attribute(volume, path, "attr", MI_TYPE_INT, 1, &hdim->attr); if (r < 0) { + printf(" in wrong place \n"); /* Use the default, regularly sampled. */ hdim->attr = MI_DIMATTR_REGULARLY_SAMPLED; } @@ -564,7 +591,7 @@ hdim->class = MI_DIMCLASS_SPATIAL; } } - r = miget_attribute(volume, path, "length", MI_TYPE_INT, 1, &hdim->length); + r = miget_attribute(volume, path, "length", MI_TYPE_UINT, 1, &hdim->length); if (r < 0) { fprintf(stderr, "Can't get length\n"); } @@ -609,7 +636,7 @@ volumehandle *handle; int hdf_mode; char dimorder[128]; - int i; + int i,r; char *p1, *p2; miinit(); @@ -634,7 +661,7 @@ handle->hdf_id = file_id; handle->mode = mode; - + /* GET THE DIMENSION COUNT */ handle->number_of_dims = _miget_file_dimension_count(file_id); @@ -643,9 +670,12 @@ */ handle->dim_handles = (midimhandle_t *)malloc(handle->number_of_dims * sizeof(midimhandle_t)); - miget_attribute(handle, "/minc-2.0/image/0/image", "dimorder", + r = miget_attribute(handle, "/minc-2.0/image/0/image", "dimorder", MI_TYPE_STRING, sizeof(dimorder), dimorder); - + if ( r < 0) { + return (MI_ERROR); + } + printf( " dimorder is %s\n", dimorder); p1 = dimorder; for (i = 0; i < handle->number_of_dims; i++) { @@ -656,7 +686,7 @@ _miget_file_dimension(handle, p1, &handle->dim_handles[i]); p1 = p2 + 1; } - + /* SEE IF SLICE SCALING IS ENABLED */ handle->has_slice_scaling = FALSE; @@ -676,7 +706,7 @@ } H5Dclose(dset_id); /* Close the dataset handle */ } - + /* Read the current settings for valid-range */ miread_valid_range(handle, &handle->valid_max, &handle->valid_min); @@ -703,7 +733,7 @@ free(volume->dim_handles); free(volume->dim_indices); if (volume->create_props != NULL) { - mifree_volume_props(volume->create_props); + mifree_volume_props(volume->create_props); } free(volume);