changeset 1927:0c7446f3f954

*** empty log message ***
author baghdadi <baghdadi>
date Thu, 23 Dec 2004 22:08:30 +0000
parents f17a2c8d0c75
children 5affd1d05125
files libsrc2/hyper.c libsrc2/test/vector_dimension-test.c libsrc2/volume.c
diffstat 3 files changed, 175 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/libsrc2/hyper.c
+++ b/libsrc2/hyper.c
@@ -99,7 +99,8 @@
      * their "raw" or native order:
      **/
     for (i = 0; i < ndims; i++) {
-        lengths[i] = lengths_perm[map[i]];
+      //lengths[i] = lengths_perm[map[i]];
+        lengths[map[i]] = lengths_perm[i];
     }
 
     /**
@@ -170,10 +171,12 @@
 
                 for (i = 0; i < ndims; i++) {
                     if (dir[i] < 0) {
-                        index[i] = lengths[i] - index_perm[map[i]] - 1;
+		      // index[i] = lengths[i] - index_perm[map[i]] - 1;
+		      index[map[i]] = lengths[i] - index_perm[i] - 1;
                     }
                     else {
-                        index[i] = index_perm[map[i]];
+		      //index[i] = index_perm[map[i]];
+		      index[map[i]] = index_perm[i];
                     }
                 }
 
@@ -285,7 +288,13 @@
     int n_different = 0;
     int file_i;
     int ndims = volume->number_of_dims;
+    int j;
 
+    for(j=0; j<ndims; j++)
+      {
+	hdf_count[j]=0;
+	hdf_start[j]=0;
+      }
     for (file_i = 0; file_i < ndims; file_i++) {
         midimhandle_t hdim;
         int user_i;
@@ -305,41 +314,49 @@
         }
 
         hdim = volume->dim_handles[file_i];
-
         switch (hdim->flipping_order) {
         case MI_FILE_ORDER:
-            hdf_start[file_i] = start[user_i];
+	  //hdf_start[file_i] = start[user_i];
+	    hdf_start[user_i] = start[file_i];
             dir[file_i] = 1;    /* Set direction positive */
             break;
 
         case MI_COUNTER_FILE_ORDER:
-            hdf_start[file_i] = hdim->length - start[user_i] - count[user_i];
+	  //hdf_start[file_i] = hdim->length - start[user_i] - count[user_i];
+	    hdf_start[user_i] = hdim->length - start[file_i] - count[file_i];
             dir[file_i] = -1;   /* Set direction negative */
             break;
             
         case MI_POSITIVE:
             if (hdim->step > 0) { /* Positive? */
-                hdf_start[file_i] = start[user_i]; /* Use raw file order. */
-                dir[file_i] = 1; /* Set direction positive */
+	      //hdf_start[file_i] = start[user_i]; /* Use raw file order. */
+	      hdf_start[user_i] = start[file_i];
+	      dir[file_i] = 1; /* Set direction positive */
             }
             else {
-                hdf_start[file_i] = hdim->length - start[user_i] - count[user_i];
-                dir[file_i] = -1; /* Set direction negative */
+	      //hdf_start[file_i] = hdim->length - start[user_i] - count[user_i];
+	      hdf_start[user_i] = hdim->length - start[file_i] - count[file_i];
+	      dir[file_i] = -1; /* Set direction negative */
             }
             break;
 
         case MI_NEGATIVE:
             if (hdim->step < 0) { /* Negative? */
-                hdf_start[file_i] = start[user_i]; /* Use raw file order */
-                dir[file_i] = 1; /* Set direction positive */
+	      //hdf_start[file_i] = start[user_i]; /* Use raw file order */
+	      hdf_start[user_i] = start[file_i];
+	      dir[file_i] = 1; /* Set direction positive */
             }
             else {
-                hdf_start[file_i] = hdim->length - start[user_i] - count[user_i];
-                dir[file_i] = -1; /* Set direction negative */
+	      //hdf_start[file_i] = hdim->length - start[user_i] - count[user_i];
+	      hdf_start[user_i] = hdim->length - start[file_i] - count[file_i];
+	      dir[file_i] = -1; /* Set direction negative */
             }
             break;
         }
-        hdf_count[file_i] = count[user_i];
+	
+	//hdf_count[file_i] = count[user_i];
+	hdf_count[user_i] = count[file_i];
+	
     }
     return (n_different);
 }
@@ -355,7 +372,7 @@
                    const unsigned long start[], 
                    const unsigned long count[],
                    void *buffer)
-{
+{   int j;
     hid_t dset_id = -1;
     hid_t mspc_id = -1;
     hid_t fspc_id = -1;
@@ -366,7 +383,8 @@
     int dir[MI2_MAX_VAR_DIMS];  /* Direction vector in file order */
     int ndims;
     int n_different = 0;
-
+   
+   
     /* Disallow write operations to anything but the highest resolution.
      */
     if (opcode == MIRW_OP_WRITE && volume->selected_resolution != 0) {
@@ -399,6 +417,7 @@
         mspc_id = H5Screate(H5S_SCALAR);
     }
     else {
+      
         n_different = mitranslate_hyperslab_origin(volume, 
                                                    start,
                                                    count,
@@ -411,7 +430,7 @@
             goto cleanup;
         }
     }
-
+    
     result = H5Sselect_hyperslab(fspc_id, H5S_SELECT_SET, hdf_start, NULL, 
                                  hdf_count, NULL);
     if (result < 0) {
@@ -423,16 +442,19 @@
                          buffer);
         /* Restructure the array after reading the data in file orientation.
          */
+
         if (n_different != 0) {
             restructure_array(ndims, buffer, count, H5Tget_size(type_id), 
                               volume->dim_indices, dir);
         }
     }
     else {
+
         volume->is_dirty = TRUE; /* Mark as modified. */
 
         /* Restructure array before writing to file.
          */
+	
         if (n_different != 0) {
             unsigned long icount[MI2_MAX_VAR_DIMS];
             int idir[MI2_MAX_VAR_DIMS];
@@ -445,9 +467,11 @@
                 idir[i] = dir[volume->dim_indices[i]];
                 imap[volume->dim_indices[i]] = i;
             }
+
             restructure_array(ndims, buffer, icount, H5Tget_size(type_id), 
                               imap, idir);
         }
+
         result = H5Dwrite(dset_id, type_id, mspc_id, fspc_id, H5P_DEFAULT, 
                           buffer);
     }
new file mode 100644
--- /dev/null
+++ b/libsrc2/test/vector_dimension-test.c
@@ -0,0 +1,129 @@
+#include <stdio.h>
+#include "minc2.h"
+
+#define TESTRPT(msg, val) (error_cnt++, fprintf(stderr, \
+     "Error reported on line #%d, %s: %d\n", \
+     __LINE__, msg, val))
+
+static int error_cnt = 0;
+
+#define CZ 41
+#define CY 410
+#define CX 530
+#define CT 8
+#define NDIMS 4
+
+int main(int argc, char **argv)
+{
+    mihandle_t vol;
+    int r;
+    midimhandle_t dim[NDIMS];
+    midimhandle_t copy_dim[NDIMS];
+    int n;
+    unsigned long coords[NDIMS];
+    unsigned long count[NDIMS];
+    int i,j,k;
+    double offset;
+    unsigned int voxel;
+    unsigned char * Atmp;
+    
+    midimclass_t dimension_class;
+    r =0;
+    Atmp = ( unsigned char *) malloc(CX * CY * CZ * sizeof(unsigned char));
+    r = miopen_volume(*++argv, MI2_OPEN_READ, &vol);
+    if (r < 0) {
+	TESTRPT("failed to open volume", r);
+    }
+    
+    r = miget_volume_dimensions(vol, MI_DIMCLASS_ANY, MI_DIMATTR_ALL,MI_DIMORDER_FILE , 4, dim);
+    if (r < 0) {
+      TESTRPT("failed to get dimensions", r);
+    }
+    r = miget_dimension_class(dim[0],&dimension_class);
+    if (r < 0) {
+      TESTRPT("failed to get dimensions", r);
+    }
+    printf(" class is %d \n", dimension_class);
+    r = miget_dimension_class(dim[1],&dimension_class);
+    if (r < 0) {
+      TESTRPT("failed to get dimensions", r);
+    }
+    printf(" class is %d \n", dimension_class);
+    r = miget_dimension_class(dim[2],&dimension_class);
+    if (r < 0) {
+      TESTRPT("failed to get dimensions", r);
+    }
+    printf(" class is %d \n", dimension_class);
+    r = miget_dimension_class(dim[3],&dimension_class);
+    if (r < 0) {
+      TESTRPT("failed to get dimensions", r);
+    }
+    printf(" class is %d \n", dimension_class);
+
+    /*
+    //coords[0]=coords[1]=coords[2]=coords[3]=0;
+    coords[0]=coords[1]=coords[2]=0;
+    coords[3]=2;
+    count[0]=41;
+    count[1]=410;
+    count[2]=530;
+    count[3]=1;
+    r = miget_voxel_value_hyperslab(vol, MI_TYPE_UBYTE, coords, count,Atmp);
+    for (j=0; j < 20; j++)
+      {
+	printf( " This is my data %u \n", Atmp[j]);
+      }
+    */
+    
+    miflipping_t flip;
+    miflipping_t sign;
+
+    r = miget_dimension_apparent_voxel_order(dim[3],&flip, &sign);
+     if (r < 0) {
+      TESTRPT("failed to get voxel order", r);
+    }
+    
+     printf(" voxel order is %d %d \n", flip, sign);
+    // Set the apparent dimension order 
+    
+    copy_dim[0] = dim[3];
+    copy_dim[1] = dim[0];
+    copy_dim[2] = dim[1];
+    copy_dim[3] = dim[2];
+
+    r = miset_apparent_dimension_order(vol, 4, copy_dim);
+    if (r < 0) {
+      TESTRPT("failed to set apparent order", r);
+    }
+    
+    coords[0]=2;  //vector-dimension
+    coords[1]=coords[2]=coords[3]=0;
+    
+    
+    count[0]=1; //must always be one
+    count[1]=41;
+    count[2]=410;
+    count[3]=530;
+
+    r = miget_voxel_value_hyperslab(vol, MI_TYPE_UBYTE, coords, count,Atmp);
+    for (j=0; j < 20; j++)
+      {
+	printf( " This is my data %u \n", Atmp[j]);
+      }
+   
+    if (r < 0) {
+      TESTRPT("failed to do hyperslb", r);
+    }
+    
+      
+    if (error_cnt != 0) {
+        fprintf(stderr, "%d error%s reported\n", 
+                error_cnt, (error_cnt == 1) ? "" : "s");
+    }
+    else {
+        fprintf(stderr, "No errors\n");
+    }
+    
+    return (error_cnt);
+}
+
--- a/libsrc2/volume.c
+++ b/libsrc2/volume.c
@@ -4,7 +4,6 @@
  *
  * Functions to create, open, and close MINC volume objects.
  ************************************************************************/
-#define _GNU_SOURCE 1
 #include <stdlib.h>
 #include <hdf5.h>
 #include <limits.h>
@@ -927,7 +926,10 @@
             if (!strcmp(dimname, "time")) {
                 hdim->class = MI_DIMCLASS_TIME;
             }
-            else {
+            else if (!strcmp(dimname, "vector_dimension")) {
+	      hdim->class = MI_DIMCLASS_RECORD;
+	    }
+	    else {
                 hdim->class =  MI_DIMCLASS_SPATIAL;
             }
         }