void create_test_file(void) { int r; double start_values[3]= {-6.96, -12.453, -9.48}; double separations[3]= {0.09,0.09,0.09}; midimhandle_t hdim[NDIMS]; mihandle_t hvol; unsigned short *buf = ( unsigned short *) malloc(CX * CY * CZ * sizeof(unsigned short)); int i; long count[NDIMS]; long start[NDIMS]; miboolean_t flag=1; double min = -1.0; double max = 1.0; r = micreate_dimension("zspace", MI_DIMCLASS_SPATIAL, MI_DIMATTR_REGULARLY_SAMPLED, CZ, &hdim[0]); r = micreate_dimension("yspace", MI_DIMCLASS_SPATIAL, MI_DIMATTR_REGULARLY_SAMPLED, CY, &hdim[1]); r = micreate_dimension("xspace", MI_DIMCLASS_SPATIAL, MI_DIMATTR_REGULARLY_SAMPLED, CX, &hdim[2]); r = miset_dimension_starts(hdim, NDIMS, start_values); r = miset_dimension_separations(hdim, NDIMS, separations); r = micreate_volume("hyperslab-test2.mnc", NDIMS, hdim, MI_TYPE_USHORT, MI_CLASS_REAL, NULL, &hvol); /* set slice scaling flag to true */ r = miset_slice_scaling_flag(hvol, flag); r = micreate_volume_image(hvol); for (i = 0; i < CZ*CY*CX; i++) { buf[i] = (unsigned short) i * 0.01; } start[0] = start[1] = start[2] = 0; count[0] = CZ; count[1] = CY; count[2] = CX; r = miset_voxel_value_hyperslab(hvol, MI_TYPE_USHORT, start, count, buf); /* Set random values to slice min and max for slice scaling*/ start[0] =start[1]=start[2]=0; for (i=0; i < CZ; i++) { start[0] = i; min += 0.1; max += 0.1; r = miset_slice_range(hvol,start, 3, max, min); } r = miclose_volume(hvol); }
int create_2D_image(void) { int r,i; midimhandle_t hdim[NDIMS-1]; mihandle_t hvol; short *buf = (short *)malloc(CX * CY * sizeof(short)); double *offsets = (double *)malloc(CX * sizeof(double)); double start_values[NDIMS-1]={-1.01, -2.02}; miboolean_t flag=0; long count[NDIMS-1]; long start[NDIMS-1]; r = micreate_dimension("xspace", MI_DIMCLASS_SPATIAL, MI_DIMATTR_NOT_REGULARLY_SAMPLED, CX, &hdim[0]); r = micreate_dimension("yspace", MI_DIMCLASS_USER, MI_DIMATTR_REGULARLY_SAMPLED, CY, &hdim[1]); for(i=0; i < CX; i++) { offsets[i] = (i * i) + 0.1; } r = miset_dimension_offsets(hdim[0], CX, 0, offsets); r = miset_dimension_separation(hdim[1], 0.06); r = miset_dimension_starts(hdim, NDIMS-1, start_values); r = micreate_volume("2D_image.mnc", NDIMS-1 , hdim, MI_TYPE_SHORT, MI_CLASS_REAL, NULL, &hvol); /* set slice scaling flag to true */ r = miset_slice_scaling_flag(hvol, flag); r = micreate_volume_image(hvol); for (i = 0; i < CX*CY; i++) { buf[i] = (short) i * 0.1; } start[0] = start[1] = 0; count[0] = CX; count[1] = CY; r = miset_voxel_value_hyperslab(hvol, MI_TYPE_SHORT, start, count, buf); r = miclose_volume(hvol); return r<0?1:0; }
int main(int argc, char **argv) { miclass_t myclass = MI_CLASS_REAL; mitype_t mytype = MI_TYPE_UNKNOWN; misize_t mysize = 0; char *myname = NULL; mihandle_t volume = NULL; /* Turn off automatic error reporting. */ H5Eset_auto2(H5E_DEFAULT, NULL, NULL); /* Check each file. */ while (--argc > 0) { ++argv; if (micreate_volume(*argv, 0, NULL, MI_TYPE_INT, 0, NULL, &volume) < 0) { /*type 0 is equivalent to H5T_INTEGER */ fprintf(stderr, "Error opening %s\n", *argv); } else { int i; /* Repeat many times to expose resource leakage problems, etc. */ for (i = 0; i < 25000; i++) { miget_data_type(volume, &mytype); miget_data_type_size(volume, &mysize); miget_data_class(volume, &myclass); miget_space_name(volume, &myname); mifree_name(myname); } miclose_volume(volume); printf("file: %s type %d size %lld class %d\n", *argv, mytype, mysize, myclass); } } return (0); }
static void create_test_file ( void ) { midimhandle_t hdim[NDIMS]; mihandle_t hvol; unsigned char *buf = malloc ( CZ * CX * CY * 3 ); int i; misize_t count[NDIMS]; misize_t start[NDIMS]; micreate_dimension ( "zspace", MI_DIMCLASS_SPATIAL, MI_DIMATTR_REGULARLY_SAMPLED, CZ, &hdim[0] ); micreate_dimension ( "yspace", MI_DIMCLASS_SPATIAL, MI_DIMATTR_REGULARLY_SAMPLED, CY, &hdim[1] ); micreate_dimension ( "xspace", MI_DIMCLASS_SPATIAL, MI_DIMATTR_REGULARLY_SAMPLED, CX, &hdim[2] ); micreate_dimension ( "vector_dimension", MI_DIMCLASS_RECORD, MI_DIMATTR_REGULARLY_SAMPLED, 3, &hdim[3] ); micreate_volume ( "example_vector2.mnc", NDIMS, hdim, MI_TYPE_BYTE, MI_CLASS_INT, NULL, &hvol ); micreate_volume_image ( hvol ); for ( i = 0; i < CZ * CY * CX * 3; i++ ) { buf[i] = ( unsigned char ) i; } start[0] = start[1] = start[2] = start[3] = 0; count[0] = CZ; count[1] = CY; count[2] = CX; count[3] = 3; miset_voxel_value_hyperslab ( hvol, MI_TYPE_BYTE, start, count, buf ); miclose_volume ( hvol ); }
int main(int argc, char *argv[]) { int r; const char **file_list = NULL; /* List of file names */ struct vff_attrs vffattrs; struct mnc_vars mnc2; char out_str[1024]; /* Big string for filename */ midimhandle_t hdim[MAX_VFF_DIMS]; mihandle_t hvol; double mnc_vrange[2]; /* MINC valid min/max */ int num_file_args; /* Number of files on command line */ string_t out_dir; /* Output directory */ int length; struct stat st; int ifile; int num_files; /* Total number of files */ int is_file=0; int is_list=0; int ival; char *extension; mnc2.mnc_srange[0]= -1; mnc2.mnc_srange[1]= -1; G.pname = argv[0]; /* get program name */ G.dirname = NULL; G.little_endian = 1; /*default is little endian unless otherwise*/ G.minc_history = time_stamp(argc, argv); /* Create minc history string */ if (ParseArgv(&argc, argv, argTable, 0) || argc < 2) { usage(); exit(EXIT_FAILURE); } if (G.dirname != NULL) { #if HAVE_DIRENT_H if (stat(G.dirname, &st) != 0 || !S_ISDIR(st.st_mode)) { fprintf(stderr,"Option -addattrs requires directory as argument!!!\n"); exit(EXIT_FAILURE); } #endif } if (G.List) { num_file_args = argc - 1; } else { strcpy(out_str, argv[1]); extension = strrchr(out_str, '.'); if (extension != NULL ) { extension++; if (strcmp(extension, "mnc") !=0) { usage(); exit(EXIT_FAILURE); } } if (argc == 3) { /* check if last argument is dir */ num_file_args = argc - 2; strcpy(out_dir, argv[argc - 1]); /* make sure path ends with slash */ length = strlen(out_dir); if (out_dir[length - 1] != '/') { out_dir[length++] = '/'; out_dir[length++] = '\0'; } if (stat(out_dir, &st) != 0 || !S_ISDIR(st.st_mode)) {/* assume filename */ is_file =1; } } else { //list of 2d files must check! num_file_args = argc - 2; is_list = 1; } } if (!is_file || G.List) { /* Get space for file lists */ /* Allocate the array of pointers used to implement the * list of filenames. */ file_list = malloc(1 * sizeof(char *)); CHKMEM(file_list); /* Go through the list of files, expanding directories where they * are encountered... */ num_files = 0; for (ifile = 1 ; ifile <= num_file_args; ifile++) { #if HAVE_DIRENT_H if (stat(argv[ifile + 1], &st) == 0 && S_ISDIR(st.st_mode)) { DIR *dp; struct dirent *np; char *tmp_str; length = strlen(argv[ifile + 1]); dp = opendir(argv[ifile + 1]); if (dp != NULL) { while ((np = readdir(dp)) != NULL) { /* Generate the full path to the file. */ tmp_str = malloc(length + strlen(np->d_name) + 2); strcpy(tmp_str, argv[ifile + 1]); if (tmp_str[length-1] != '/') { tmp_str[length] = '/'; tmp_str[length+1] = '\0'; } strcat(&tmp_str[length], np->d_name); if (stat(tmp_str, &st) == 0 && S_ISREG(st.st_mode)) { file_list = realloc(file_list, (num_files + 1) * sizeof(char *)); file_list[num_files++] = tmp_str; } else { free(tmp_str); } } closedir(dp); } else { fprintf(stderr, "Error opening directory '%s'\n", argv[ifile + 1]); } } else { file_list = realloc(file_list, (num_files + 1) * sizeof(char *)); file_list[num_files++] = strdup(argv[ifile + 1]); } #else file_list = realloc(file_list, (num_files + 1) * sizeof(char *)); file_list[num_files++] = strdup(argv[ifile + 1]); #endif } } if (G.List) { exit(EXIT_SUCCESS); } if (is_file) { read_3Dvff_file_header(argv[2],&mnc2,&vffattrs); } else { read_2Dvff_files_header(file_list,num_files,&mnc2,&vffattrs); } /* ok starting to create minc2.0 file assuming 3D must take care of 2D*/ r = micreate_dimension("zspace", MI_DIMCLASS_SPATIAL, MI_DIMATTR_REGULARLY_SAMPLED, mnc2.mnc_count[2], &hdim[0]); if (r != 0) { TESTRPT("failed create_dimension zspace", r); return (1); } r = micreate_dimension("yspace", MI_DIMCLASS_SPATIAL, MI_DIMATTR_REGULARLY_SAMPLED, mnc2.mnc_count[1], &hdim[1]); if (r != 0) { TESTRPT("failed create_dimension yspace", r); return (1); } r = micreate_dimension("xspace", MI_DIMCLASS_SPATIAL, MI_DIMATTR_REGULARLY_SAMPLED, mnc2.mnc_count[0], &hdim[2]); if (r != 0) { TESTRPT("failed create_dimension xspace", r); return (1); } r = miset_dimension_start(hdim[0], mnc2.mnc_starts[2]); if (r < 0) { TESTRPT("failed dimension start xspace", r); return (1); } r = miset_dimension_start(hdim[1], mnc2.mnc_starts[1]); if (r < 0) { TESTRPT("failed dimension start yspace", r); return (1); } /* create negative start for xspace to correct orientation */ r = miset_dimension_start(hdim[2], mnc2.mnc_starts[0] * -1); if (r < 0) { TESTRPT("failed dimension start zspace", r); return (1); } /* create negative spacing for zspace to correct orientation */ r = miset_dimension_separation(hdim[0], mnc2.mnc_steps[2] * -1); if (r < 0) { TESTRPT("failed dimension separation xspace", r); return (1); } /* create negative spacing for yspace to correct orientation */ r = miset_dimension_separation(hdim[1], mnc2.mnc_steps[1] * -1); if (r < 0) { TESTRPT("failed dimension separation yspace", r); return (1); } r = miset_dimension_separation(hdim[2], mnc2.mnc_steps[0]); if (r < 0) { TESTRPT("failed dimension separation zspace", r); return (1); } r = micreate_volume(out_str,MAX_VFF_DIMS, hdim, mnc2.mnc_type, MI_CLASS_REAL, NULL, &hvol); if (r != 0) { TESTRPT("error creating volume", r); return (1); } r = micreate_volume_image(hvol); if (r != 0) { TESTRPT("error creating volume", r); return (1); } // read image slice by slice if (is_file) { read_3Dvff_file_image(hvol, argv[2], mnc2, vffattrs, mnc_vrange); } else { read_2Dvff_files_image(hvol,file_list,num_files, mnc2, vffattrs, mnc_vrange); } miset_volume_valid_range(hvol,mnc_vrange[1], mnc_vrange[0]); if (mnc2.mnc_srange[0] == -1 || mnc2.mnc_srange[1] == -1) { /* min and max are not specified in the file voxel range is set same as real range */ mnc2.mnc_srange[0] = mnc_vrange[0]; mnc2.mnc_srange[1] = mnc_vrange[1]; } miset_volume_range(hvol,mnc2.mnc_srange[1], mnc2.mnc_srange[0]); if (is_file) { /* create minc history 3D */ strcat(vffattrs.cmd_line,G.minc_history); G.minc_history = vffattrs.cmd_line; /* attributes from vff file itself 3D case*/ add_vff_attribute_to_file(hvol,&vffattrs); } if (G.dirname != NULL) { /* attributes from external files 3D case*/ add_attributes_from_files(hvol); } else if (!is_file) { /* just afew attributes from 2D case */ ival = vffattrs.year; r = miset_attr_values(hvol, MI_TYPE_INT, "study", MIstart_year,1 , &ival); if (r < 0) { TESTRPT("failed to add date:year attribute", r); } ival = vffattrs.month; r = miset_attr_values(hvol, MI_TYPE_INT, "study", MIstart_month,1 , &ival); if (r < 0) { TESTRPT("failed to add date:month attribute", r); } ival = vffattrs.day; r = miset_attr_values(hvol, MI_TYPE_INT, "study", MIstart_day,1 , &ival); if (r < 0) { TESTRPT("failed to add date:day attribute", r); } } /* add history attribute */ r = miadd_history_attr(hvol,strlen(G.minc_history), G.minc_history); if (r < 0) { TESTRPT("error creating history", r); return (1); } if (file_list != NULL) { free_list(num_files, file_list); free(file_list); } miclose_volume(hvol); exit(EXIT_SUCCESS); }
int main(void) { mihandle_t vol; int r; midimhandle_t dim[NDIMS]; int n; misize_t coords[NDIMS]; misize_t count[NDIMS]; int i,j,k; double offset; unsigned int voxel; /* Write data one voxel at a time. */ for (i = 0; i < NDIMS; i++) { count[i] = 1; } r = micreate_dimension("time", MI_DIMCLASS_TIME, MI_DIMATTR_NOT_REGULARLY_SAMPLED, CT, &dim[0]); if (r < 0) { TESTRPT("failed", r); } for (i = 0; i < CT; i++) { offset = (i * i) + 100.0; r = miset_dimension_offsets(dim[0], 1, i, &offset); if (r < 0) { TESTRPT("failed", r); } } r = micreate_dimension("xspace",MI_DIMCLASS_SPATIAL, MI_DIMATTR_REGULARLY_SAMPLED, CX, &dim[1]); if (r < 0) { TESTRPT("failed", r); } r = miset_dimension_start(dim[1], XSTART); if (r < 0) { TESTRPT("failed", r); } r = miset_dimension_separation(dim[1], XSTEP); if (r < 0) { TESTRPT("failed", r); } r = micreate_dimension("yspace",MI_DIMCLASS_SPATIAL, MI_DIMATTR_REGULARLY_SAMPLED, CY, &dim[2]); if (r < 0) { TESTRPT("failed", r); } r = miset_dimension_start(dim[2], YSTART); if (r < 0) { TESTRPT("failed", r); } r = miset_dimension_separation(dim[2], YSTEP); if (r < 0) { TESTRPT("failed", r); } r = micreate_dimension("zspace",MI_DIMCLASS_SPATIAL, MI_DIMATTR_REGULARLY_SAMPLED, CZ, &dim[3]); if (r < 0) { TESTRPT("failed", r); } r = miset_dimension_start(dim[3], ZSTART); if (r < 0) { TESTRPT("failed", r); } r = miset_dimension_separation(dim[3], ZSTEP); if (r < 0) { TESTRPT("failed", r); } r = micreate_volume("tst-dim.mnc", NDIMS, dim, MI_TYPE_UINT, MI_CLASS_REAL, NULL, &vol); if (r < 0) { TESTRPT("failed", r); } r = micreate_volume_image(vol); if (r < 0) { TESTRPT("failed", r); } check_dims(vol, dim); for (i = 0; i < CX; i++) { for (j = 0; j < CY; j++) { for (k = 0; k < CZ; k++) { coords[0] = 0; coords[1] = i; coords[2] = j; coords[3] = k; voxel = (i*10000)+(j*100)+k; r = miset_voxel_value_hyperslab(vol, MI_TYPE_UINT, coords, count, &voxel); if (r < 0) { TESTRPT("Error writing voxel", r); } } } } r = miclose_volume(vol); if (r < 0) { TESTRPT("failed", r); } /***** 03-Aug-2004: Added two tests for bugs reported by Leila */ r = miopen_volume("tst-dim.mnc", MI2_OPEN_RDWR, &vol); if (r < 0) { TESTRPT("failed", r); } r = miget_volume_dimension_count(vol, MI_DIMCLASS_ANY, MI_DIMATTR_REGULARLY_SAMPLED, &n); if (r < 0) { TESTRPT("failed", r); } if (n != NDIMS - 1) { TESTRPT("wrong result", n); } r = miget_volume_dimension_count(vol, MI_DIMCLASS_ANY, MI_DIMATTR_NOT_REGULARLY_SAMPLED, &n); if (r < 0) { TESTRPT("failed", r); } if (n != 1) { TESTRPT("wrong result", n); } r = miclose_volume(vol); if (r < 0) { TESTRPT("failed", r); } /* Test #2 - verify that we don't print anything scary if a user * closes a volume prematurely. */ r = micreate_dimension("xspace",MI_DIMCLASS_SPATIAL, MI_DIMATTR_REGULARLY_SAMPLED, CX, &dim[0]); if (r < 0) { TESTRPT("failed", r); } r = micreate_dimension("yspace",MI_DIMCLASS_SPATIAL, MI_DIMATTR_REGULARLY_SAMPLED, CY, &dim[1]); if (r < 0) { TESTRPT("failed", r); } r = micreate_dimension("zspace",MI_DIMCLASS_SPATIAL, MI_DIMATTR_REGULARLY_SAMPLED, CZ, &dim[2]); if (r < 0) { TESTRPT("failed", r); } r = micreate_volume("tst-vol.mnc", 3, dim, MI_TYPE_SHORT, MI_CLASS_LABEL, NULL, &vol); if (r < 0) { TESTRPT("failed", r); } r = miclose_volume(vol); if (r < 0) { TESTRPT("failed", r); } /** End of tests added 03-Aug-2004 **/ 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); }
int main(int argc, char **argv) { mihandle_t vol; int r; midimhandle_t dim[NDIMS]; mivolumeprops_t props; int n; unsigned long coords[NDIMS]; unsigned long count[NDIMS]; int i,j,k; unsigned int voxel; printf("Creating volume...\n"); /* Write data one voxel at a time. */ for (i = 0; i < NDIMS; i++) { count[i] = 1; } r = minew_volume_props(&props); r = miset_props_compression_type(props, MI_COMPRESS_ZLIB); r = miset_props_zlib_compression(props, 3); r = miset_props_multi_resolution(props, 1, 3); if (r < 0) { TESTRPT("failed", r); } r = micreate_dimension("xspace",MI_DIMCLASS_SPATIAL,MI_DIMATTR_REGULARLY_SAMPLED, CX,&dim[0]); if (r < 0) { TESTRPT("failed", r); } r = micreate_dimension("yspace",MI_DIMCLASS_SPATIAL,MI_DIMATTR_REGULARLY_SAMPLED, CY, &dim[1]); if (r < 0) { TESTRPT("failed", r); } r = micreate_dimension("zspace",MI_DIMCLASS_SPATIAL,MI_DIMATTR_REGULARLY_SAMPLED, CZ,&dim[2]); if (r < 0) { TESTRPT("failed", r); } r = micreate_volume("tst-multi.mnc", NDIMS, dim, MI_TYPE_UINT, MI_CLASS_REAL,props,&vol); if (r < 0) { TESTRPT("failed", r); } r = miset_volume_valid_range(vol, CX*10000.0 + CY*100 + CZ, 0.0); r = micreate_volume_image(vol); if (r < 0) { TESTRPT("failed", r); } r = miget_volume_dimension_count(vol, MI_DIMCLASS_SPATIAL, MI_DIMATTR_ALL, &n); if (r < 0) { TESTRPT("failed", r); } printf("Writing data...\n"); for (i = 0; i < CX; i++) { for (j = 0; j < CY; j++) { for (k = 0; k < CZ; k++) { coords[0] = i; coords[1] = j; coords[2] = k; voxel = i*10000 + j*100 + k; r = miset_voxel_value_hyperslab(vol, MI_TYPE_UINT, coords, count, &voxel); if (r < 0) { TESTRPT("Error writing voxel", r); } } } } printf("Selecting half-size image\n"); r = miselect_resolution(vol, 1); if (r < 0) { TESTRPT("miselect_resolution failed", r); } /* OK, now try to read the lower-resolution hyperslab */ coords[0] = 0; coords[1] = 0; coords[2] = 0; count[0] = CX/2; count[1] = CY/2; count[2] = CZ/2; { unsigned int buffer[CX/2][CY/2][CZ/2]; r = miget_voxel_value_hyperslab(vol, MI_TYPE_UINT, coords, count, buffer); if (r < 0) { TESTRPT("failed", r); } } printf("Selecting quarter-size image\n"); r = miselect_resolution(vol, 2); if (r < 0) { TESTRPT("miselect_resolution failed", r); } /* OK, now try to read the lower-resolution hyperslab */ coords[0] = 0; coords[1] = 0; coords[2] = 0; count[0] = CX/4; count[1] = CY/4; count[2] = CZ/4; { unsigned int buffer[CX/4][CY/4][CZ/4]; r = miget_voxel_value_hyperslab(vol, MI_TYPE_UINT, coords, count, buffer); if (r < 0) { TESTRPT("failed", r); } } printf("Return to full resolution.\n"); r = miselect_resolution(vol, 0); /* Back to full resolution */ if (r < 0) { TESTRPT("miselect_resolution failed", r); } printf("Flush any remaining thumbnails.\n"); r = miflush_from_resolution(vol, 3); if (r < 0) { TESTRPT("failed", r); } r = miclose_volume(vol); if (r < 0) { TESTRPT("failed", 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); }
int main(void) { mihandle_t hvol; char *name; int result; midimhandle_t hdim[NDIMS]; misize_t coords[NDIMS]; misize_t count[NDIMS]; int i,j,k; struct test { int r; int g; int b; } voxel; /* Write data one voxel at a time. */ for (i = 0; i < NDIMS; i++) { count[i] = 1; } result = micreate_dimension("xspace", MI_DIMCLASS_SPATIAL, MI_DIMATTR_REGULARLY_SAMPLED, CX, &hdim[0]); result = micreate_dimension("yspace", MI_DIMCLASS_SPATIAL, MI_DIMATTR_REGULARLY_SAMPLED, CY, &hdim[1]); result = micreate_dimension("zspace", MI_DIMCLASS_SPATIAL, MI_DIMATTR_REGULARLY_SAMPLED, CZ, &hdim[2]); result = micreate_volume("tst-rec.mnc", NDIMS, hdim, MI_TYPE_UINT, MI_CLASS_UNIFORM_RECORD, NULL, &hvol); if (result < 0) { TESTRPT("Unable to create test file", result); } result = miset_record_field_name(hvol, 0, "Red"); if (result < 0) { TESTRPT("miset_record_field_name", result); } miset_record_field_name(hvol, 1, "Green"); miset_record_field_name(hvol, 2, "Blue"); miget_record_field_name(hvol, 1, &name); if (strcmp(name, "Green") != 0) { TESTRPT("Unexpected label for value 1", 0); } mifree_name(name); miget_record_field_name(hvol, 0, &name); if (strcmp(name, "Red") != 0) { TESTRPT("Unexpected label for value 0", 0); } mifree_name(name); miget_record_field_name(hvol, 2, &name); if (strcmp(name, "Blue") != 0) { TESTRPT("Unexpected label for value 2", 0); } mifree_name(name); result = micreate_volume_image(hvol); if (result < 0) { TESTRPT("micreate_volume_image failed", result); } for (i = 0; i < CX; i++) { for (j = 0; j < CY; j++) { for (k = 0; k < CZ; k++) { coords[0] = i; coords[1] = j; coords[2] = k; voxel.r = i; voxel.g = j; voxel.b = k; result = miset_voxel_value_hyperslab(hvol, MI_TYPE_UNKNOWN, coords, count, &voxel); if (result < 0) { TESTRPT("Error writing voxel", result); } } } } for (i = 0; i < CX; i++) { for (j = 0; j < CY; j++) { for (k = 0; k < CZ; k++) { coords[0] = i; coords[1] = j; coords[2] = k; result = miget_voxel_value_hyperslab(hvol, MI_TYPE_UNKNOWN, coords, count, &voxel); if (result < 0) { TESTRPT("Error reading voxel", result); } if (voxel.r != i || voxel.g != j || voxel.b != k) { TESTRPT("Data mismatch", 0); } } } } miclose_volume(hvol); 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); }
int create_4D_image(void) { int r; double start_values[NDIMS+1]={-6.96, -12.453, -9.48, 20.002}; double separations[NDIMS+1]={0.09,0.09,0.09, 1}; midimhandle_t hdim[NDIMS+1]; mihandle_t hvol; unsigned char *buf = (unsigned char *) malloc(CX * CU * CZ * CY * sizeof(unsigned char)); int i,j; long count[NDIMS+1]; long start[NDIMS+1]; miboolean_t flag=1; double min = -1.0; double max = 1.0; r = micreate_dimension("xspace", MI_DIMCLASS_SPATIAL, MI_DIMATTR_REGULARLY_SAMPLED, CX, &hdim[0]); r = micreate_dimension("user", MI_DIMCLASS_USER, MI_DIMATTR_REGULARLY_SAMPLED, CU, &hdim[1]); r = micreate_dimension("zspace", MI_DIMCLASS_SPATIAL, MI_DIMATTR_REGULARLY_SAMPLED, CZ, &hdim[2]); r = micreate_dimension("yspace", MI_DIMCLASS_SPATIAL, MI_DIMATTR_REGULARLY_SAMPLED, CY, &hdim[3]); r = miset_dimension_starts(hdim, NDIMS+1, start_values); r = miset_dimension_separations(hdim, NDIMS+1, separations); r = micreate_volume("4D_image.mnc", NDIMS+1, hdim, MI_TYPE_UBYTE, MI_CLASS_REAL, NULL, &hvol); /* set slice scaling flag to true */ r = miset_slice_scaling_flag(hvol, flag); r = micreate_volume_image(hvol); for (i = 0; i < CX*CU*CZ*CY; i++) { buf[i] = (unsigned char) i; } start[0] = start[1] = start[2] = start[3] = 0; count[0] = CX; count[1] = CU; count[2] = CZ; count[3] = CY; r = miset_voxel_value_hyperslab(hvol, MI_TYPE_UBYTE, start, count, buf); /* Set random values to slice min and max for slice scaling*/ start[0] =start[1]=start[2]=start[3]=0; for (i=0; i < CX; i++) { start[0] = i; for ( j=0; j < CU; j++) { start[1] = j; min += -0.1; max += 0.1; r = miset_slice_range(hvol,start,NDIMS+1 , max, min); } } r = miclose_volume(hvol); return r<0?1:0; }
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * Purpose: * * * * * */ SEXP write_volume(SEXP filename, SEXP nDimensions, SEXP dimLengths, SEXP dimStarts, SEXP dimSteps, SEXP volumeDataType, SEXP volumeRange, SEXP hSlab) { mihandle_t minc_volume; midimhandle_t dim[MI2_MAX_VAR_DIMS]; mivolumeprops_t volume_properties; int result; int ndx; int no_dimensions; int dim_lengths[MI2_MAX_VAR_DIMS]; double dim_starts[MI2_MAX_VAR_DIMS]; double dim_steps[MI2_MAX_VAR_DIMS]; double volume_range_min, volume_range_max; int volume_data_type; // pointer to the volume data double *hSlab_p; misize_t hSlab_start[MI2_MAX_VAR_DIMS]; misize_t hSlab_count[MI2_MAX_VAR_DIMS]; // start ... if ( R_DEBUG_mincIO ) Rprintf("write_volume: start ...\n"); /* init number of dimensions and their respective sizes ... yes, I could get this myself, but it's best set in the calling R code */ no_dimensions = INTEGER(nDimensions)[0]; volume_data_type = INTEGER(volumeDataType)[0]; volume_range_min = REAL(volumeRange)[0]; volume_range_max = REAL(volumeRange)[1]; // init volume data pointer hSlab_p = REAL(hSlab); // init lenghts, steps, and starts for (ndx=0; ndx < no_dimensions; ++ndx) { dim_lengths[ndx] = INTEGER(dimLengths)[ndx]; hSlab_count[ndx] = INTEGER(dimLengths)[ndx]; dim_starts[ndx] = REAL(dimStarts)[ndx]; dim_steps[ndx] = REAL(dimSteps)[ndx]; } // set the properties for the new output volume // ... no compression, no chunking, no multi-resolution, ... nothin fancy result = minew_volume_props(&volume_properties); if (result != MI_NOERROR) { error("write_volume:minew_volume_props: Error setting output volume properties: %s.\n", CHAR(STRING_ELT(filename, 0))); } result = miset_props_compression_type(volume_properties, MI_COMPRESS_NONE); if (result != MI_NOERROR) { error("write_volume:miset_props_compression_type: Error setting output volume properties: %s.\n", CHAR(STRING_ELT(filename, 0))); } result = miset_props_multi_resolution(volume_properties, FALSE, 1); if (result != MI_NOERROR) { error("write_volume:miset_props_multi_resolution: Error setting output volume properties: %s.\n", CHAR(STRING_ELT(filename, 0))); } /* create the 3 output dimensions in the order Z, Y, X, as the volume is stored in this order */ // z-dim result = micreate_dimension("zspace", MI_DIMCLASS_SPATIAL, MI_DIMATTR_REGULARLY_SAMPLED, dim_lengths[0], &dim[0]); // if (result != MI_NOERROR) { error("write_volume: Error initializing the dimension struct for %s dimension.\n", "zspace"); } // y-dim result = micreate_dimension("yspace", MI_DIMCLASS_SPATIAL, MI_DIMATTR_REGULARLY_SAMPLED, dim_lengths[1], &dim[1]); // if (result != MI_NOERROR) { error("write_volume: Error initializing the dimension struct for %s dimension.\n", "yspace"); } // x-dim result = micreate_dimension("xspace", MI_DIMCLASS_SPATIAL, MI_DIMATTR_REGULARLY_SAMPLED, dim_lengths[2], &dim[2]); // if (result != MI_NOERROR) { error("write_volume: Error initializing the dimension struct for %s dimension.\n", "xspace"); } // set the start values for each dimension result = miset_dimension_starts(dim, no_dimensions, dim_starts); if (result == MI_ERROR) { error("write_volume: Error setting dimension start values.\n"); } // set the step values for each dimension result = miset_dimension_separations(dim, no_dimensions, dim_steps); if (result == MI_ERROR) { error("write_volume: Error setting dimension step values.\n"); } // create the volume structure (no data yet, of course) result = micreate_volume(CHAR(STRING_ELT(filename, 0)), no_dimensions, dim, volume_data_type, MI_CLASS_REAL, volume_properties, &minc_volume); // if (result != MI_NOERROR) { error("write_volume: Error creating output volume structure: %s.\n", CHAR(STRING_ELT(filename, 0))); } // create the path to the image data result = micreate_volume_image(minc_volume); // if (result != MI_NOERROR) { error("write_volume: Error writing data to volume %s.\n", CHAR(STRING_ELT(filename, 0))); } // set valid and real ranges // ... 0xFFFF=65535=16-bits (unsigned) miset_volume_valid_range(minc_volume, 0x7FFF, 0); miset_volume_range(minc_volume, volume_range_max, volume_range_min); // write hyperslab (entire volume) hSlab_start[0] = hSlab_start[1] = hSlab_start[2] = 0; if ( R_DEBUG_mincIO ) Rprintf("hSlab_count [0..2] = %d, %d, %d\n", hSlab_count[0], hSlab_count[1], hSlab_count[2]); result = miset_real_value_hyperslab(minc_volume, MI_TYPE_DOUBLE, hSlab_start, hSlab_count, hSlab_p); if ( result != MI_NOERROR ) { error("Error in miset_real_value_hyperslab: %s.\n", CHAR(STRING_ELT(filename, 0))); } // free resources // // in the current version of minc (libsrc2/volume.c), these volume properties // as well as the dimension handles are already freed by the miclose_volume function. // //mifree_volume_props(volume_properties); // free the property list //for ( ndx=0; ndx<no_dimensions; ++ndx) { // free the dimhandles // mifree_dimension_handle(dim[ndx]); //} // close new volume result = miclose_volume(minc_volume); if (result != MI_NOERROR) { error("write_volume: Error closing newly created volume %s.\n", CHAR(STRING_ELT(filename, 0))); } // done, return NULL if ( R_DEBUG_mincIO ) Rprintf("write_volume: returning ...\n"); return(R_NilValue); }
int main(int argc, char **argv) { mihandle_t hvol; int r; mitype_t data_type; int length; static double tstarr[TESTARRAYSIZE] = { 1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8, 9.9, 10.10, 11.11 }; double dblarr[TESTARRAYSIZE]; float fltarr[TESTARRAYSIZE]; int intarr[TESTARRAYSIZE]; char valstr[128]; milisthandle_t hlist, h1list; char pathbuf[256]; char namebuf[256]; char pathbuf1[256]; int count=0; r = micreate_volume("tst-grpa.mnc", 0, NULL, MI_TYPE_UINT, MI_CLASS_INT, NULL, &hvol); if (r < 0) { TESTRPT("Unable to create test file", r); return (-1); } r = micreate_group(hvol, "/", "test1"); if (r < 0) { TESTRPT("micreate_group failed", r); } r = micreate_group(hvol, "/", "test2"); if (r < 0) { TESTRPT("micreate_group failed", r); } r = micreate_group(hvol, "/", "test3"); if (r < 0) { TESTRPT("micreate_group failed", r); } r = micreate_group(hvol, "/", "test4"); if (r < 0) { TESTRPT("micreate_group failed", r); } r = micreate_group(hvol, "/test2", "stuff2"); if (r < 0) { TESTRPT("micreate_group failed", r); } r = micreate_group(hvol, "/test1", "stuff"); if (r < 0) { TESTRPT("micreate_group failed", r); } r = micreate_group(hvol, "/test1", "otherstuff"); if (r < 0) { TESTRPT("micreate_group failed", r); } r = micreate_group(hvol, "/test1", "theotherstuff"); if (r < 0) { TESTRPT("micreate_group failed", r); } r = micreate_group(hvol, "/test1/theotherstuff", "thisstuff"); if (r < 0) { TESTRPT("micreate_group failed", r); } r = micreate_group(hvol, "/test1/stuff", "hello"); if (r < 0) { TESTRPT("micreate_group failed", r); } r = micreate_group(hvol, "/test1/stuff", "helloleila"); if (r < 0) { TESTRPT("micreate_group failed", r); } r = miset_attr_values(hvol, MI_TYPE_STRING, "/test1/stuff/hello", "animal", 8, "fruitbat"); if (r < 0) { TESTRPT("miset_attr_values failed", r); } r = miset_attr_values(hvol, MI_TYPE_STRING, "/test1/stuff", "objtype", 10, "automobile"); if (r < 0) { TESTRPT("miset_attr_values failed", r); } r = miset_attr_values(hvol, MI_TYPE_STRING, "/test3", "objtype", 10, "automobile"); if (r < 0) { TESTRPT("miset_attr_values failed", r); } r = miset_attr_values(hvol, MI_TYPE_STRING, "/test1/stuff", "objname", 10, "automobile"); if (r < 0) { TESTRPT("miset_attr_values failed", r); } r = miset_attr_values(hvol, MI_TYPE_DOUBLE, "/test2", "maxvals", TESTARRAYSIZE, tstarr); if (r < 0) { TESTRPT("miset_attr_values failed", r); } r = miget_attr_type(hvol, "/test1/stuff/hello", "animal", &data_type); if (r < 0) { TESTRPT("miget_attr_type failed", r); } r = miget_attr_length(hvol, "/test1/stuff/hello", "animal", &length); if (r < 0) { TESTRPT("miget_attr_length failed", r); } if (data_type != MI_TYPE_STRING) { TESTRPT("miget_attr_type failed", data_type); } if (length != 8) { TESTRPT("miget_attr_length failed", length); } r = midelete_group(hvol, "/test1/stuff", "goodbye"); if (r >= 0) { TESTRPT("midelete_group failed", r); } r = midelete_group(hvol, "/test1/stuff", "hello"); /* This should succeed. */ if (r < 0) { TESTRPT("midelete_group failed", r); } r = miget_attr_length(hvol, "/test1/stuff/hello", "animal", &length); /* This should fail since we deleted the group. */ if (r >= 0) { TESTRPT("miget_attr_length failed", r); } r = miget_attr_values(hvol, MI_TYPE_DOUBLE, "/test2", "maxvals", TESTARRAYSIZE, dblarr); if (r < 0) { TESTRPT("miget_attr_values failed", r); } for (r = 0; r < TESTARRAYSIZE; r++) { if (dblarr[r] != tstarr[r]) { TESTRPT("miget_attr_values mismatch", r); } } /* Get the values again in float rather than double format. */ r = miget_attr_values(hvol, MI_TYPE_FLOAT, "/test2", "maxvals", TESTARRAYSIZE, fltarr); if (r < 0) { TESTRPT("miget_attr_values failed", r); } for (r = 0; r < TESTARRAYSIZE; r++) { if (fltarr[r] != (float) tstarr[r]) { TESTRPT("miget_attr_values mismatch", r); fprintf(stderr, "fltarr[%d] = %f, tstarr[%d] = %f\n", r, fltarr[r], r, tstarr[r]); } } /* Get the values again in int rather than double format. */ r = miget_attr_values(hvol, MI_TYPE_INT, "/test2", "maxvals", TESTARRAYSIZE, intarr); if (r < 0) { TESTRPT("miget_attr_values failed", r); } for (r = 0; r < TESTARRAYSIZE; r++) { if (intarr[r] != (int) tstarr[r]) { TESTRPT("miget_attr_values mismatch", r); fprintf(stderr, "intarr[%d] = %d, tstarr[%d] = %d\n", r, intarr[r], r, (int) tstarr[r]); } } r = miget_attr_values(hvol, MI_TYPE_STRING, "/test1/stuff", "objtype", 128, valstr); if (r < 0) { TESTRPT("miget_attr_values failed", r); } if (strcmp(valstr, "automobile") != 0) { TESTRPT("miget_attr_values failed", 0); } r = miset_attr_values(hvol, MI_TYPE_STRING, "/test1/stuff", "objtype", 8, "bicycle"); if (r < 0) { TESTRPT("miset_attr_values failed on rewrite", r); } r = miget_attr_values(hvol, MI_TYPE_STRING, "/test1/stuff", "objtype", 128, valstr); if (r < 0) { TESTRPT("miget_attr_values failed", r); } if (strcmp(valstr, "bicycle") != 0) { TESTRPT("miget_attr_values failed", 0); } r = milist_start(hvol, "/", 1, &hlist); if (r == MI_NOERROR) { count++; while (milist_attr_next(hvol, hlist, pathbuf, sizeof(pathbuf), namebuf, sizeof(namebuf)) == MI_NOERROR) { printf(" %s %s\n", pathbuf, namebuf); } } milist_finish(hlist); printf("***************** \n"); r = milist_start(hvol, "/", 1, &h1list); if (r == MI_NOERROR) { while( milist_grp_next(h1list, pathbuf1, sizeof(pathbuf1)) == MI_NOERROR) { printf("%s \n", pathbuf1); } } milist_finish(h1list); miclose_volume(hvol); 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); }
/* writes a hyperslab to the output filename, creating the output voluem to be like the second filename passed in */ void write_minc2_volume(char **output, char **like_filename, int *start, int *count, double *max_range, double *min_range, double *slab) { mihandle_t hvol_like, hvol_new; midimhandle_t *dimensions_like, *dimensions_new; unsigned long tmp_count[3]; unsigned long tmp_start[3]; int i; /* allocate the dimension handles */ dimensions_like = malloc(sizeof(midimhandle_t) * 3); dimensions_new = malloc(sizeof(midimhandle_t) * 3); /* read the like volume */ if (miopen_volume(like_filename[0], MI2_OPEN_READ, &hvol_like) < 0 ) { error("Error opening volume: %s\n", like_filename[0]); } /* get dimensions */ if (miget_volume_dimensions( hvol_like, MI_DIMCLASS_SPATIAL, MI_DIMATTR_ALL, MI_DIMORDER_FILE, 3, dimensions_like ) < 0 ) { error("Error getting volume dimensions\n"); } /* copy the dimensions to the new file */ for (i=0; i < 3; i++) { if (micopy_dimension(dimensions_like[i], &dimensions_new[i]) < 0) { error ("Error copying dimension %d\n", i); } } /* create the new volume */ if ( micreate_volume(output[0], 3, dimensions_new, MI_TYPE_USHORT, MI_CLASS_REAL, NULL, &hvol_new) < 0 ) { error("Error creating volume %s\n", output[0]); } if (micreate_volume_image(hvol_new) < 0) { error("Error creating volume image\n"); } /* set valid and real range */ miset_volume_valid_range(hvol_new, 65535, 0); miset_volume_range(hvol_new, max_range[0], min_range[0]); Rprintf("Range: %f %f\n", max_range[0], min_range[0]); /* write the buffer */ for (i=0; i < 3; i++) { tmp_start[i] = (unsigned long) start[i]; tmp_count[i] = (unsigned long) count[i]; } if (miset_real_value_hyperslab(hvol_new, MI_TYPE_DOUBLE, (misize_t *) tmp_start, (misize_t *) tmp_count, slab) < 0) { error("Error writing buffer to volume\n"); } if (miclose_volume(hvol_like) < 0) { error("Error closing like volume\n"); } if (miclose_volume(hvol_new) < 0) { error("Error closing new volume\n"); } free(dimensions_new); free(dimensions_like); return; }
int main(void) { mihandle_t hvol; mihandle_t hvol1; int r; mitype_t data_type; size_t length; static double tstarr[TESTARRAYSIZE] = { 1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8, 9.9, 10.10, 11.11 }; double dblarr[TESTARRAYSIZE]; float fltarr[TESTARRAYSIZE]; int intarr[TESTARRAYSIZE]; char valstr[128]=""; float val1=12.5; float val2=34.5; milisthandle_t hlist, h1list; char pathbuf[256]=""; char namebuf[256]=""; char pathbuf1[1024]=""; int count=0; r = micreate_volume("tst-grpa.mnc", 0, NULL, MI_TYPE_UINT, MI_CLASS_REAL, NULL, &hvol); if (r < 0) { TESTRPT("Unable to create test file", r); return (-1); } r = micreate_volume("tst-grpb.mnc", 0, NULL, MI_TYPE_UINT, MI_CLASS_REAL, NULL, &hvol1); if (r < 0) { TESTRPT("Unable to create test file", r); return (-1); } r = micreate_group(hvol, "/", "test1"); if (r < 0) { TESTRPT("micreate_group failed", r); } r = micreate_group(hvol, "/", "test2"); if (r < 0) { TESTRPT("micreate_group failed", r); } r = micreate_group(hvol, "/", "test3"); if (r < 0) { TESTRPT("micreate_group failed", r); } r = micreate_group(hvol, "/", "test4"); if (r < 0) { TESTRPT("micreate_group failed", r); } r = micreate_group(hvol, "/test2", "stuff2"); if (r < 0) { TESTRPT("micreate_group failed", r); } r = micreate_group(hvol, "/test1", "stuff"); if (r < 0) { TESTRPT("micreate_group failed", r); } r = micreate_group(hvol, "/test1", "otherstuff"); if (r < 0) { TESTRPT("micreate_group failed", r); } r = micreate_group(hvol, "/test1", "theotherstuff"); if (r < 0) { TESTRPT("micreate_group failed", r); } r = micreate_group(hvol, "/test1/theotherstuff", "thisstuff"); if (r < 0) { TESTRPT("micreate_group failed", r); } r = micreate_group(hvol, "/test1/stuff", "hello"); if (r < 0) { TESTRPT("micreate_group failed", r); } r = micreate_group(hvol, "/test1/stuff", "helloleila"); if (r < 0) { TESTRPT("micreate_group failed", r); } r = miset_attr_values(hvol, MI_TYPE_STRING, "/test1/stuff/hello", "animal", 8, "fruitbat"); if (r < 0) { TESTRPT("miset_attr_values failed", r); } r = miset_attr_values(hvol, MI_TYPE_STRING, "/test1/stuff", "objtype", 10, "automobile"); if (r < 0) { TESTRPT("miset_attr_values failed", r); } r = miset_attr_values(hvol, MI_TYPE_STRING, "/test3", "objtype", 10, "automobile"); if (r < 0) { TESTRPT("miset_attr_values failed", r); } r = miset_attr_values(hvol, MI_TYPE_STRING, "/test1/stuff", "objname", 10, "automobile"); if (r < 0) { TESTRPT("miset_attr_values failed", r); } r = miset_attr_values(hvol, MI_TYPE_DOUBLE, "/test2", "maxvals", TESTARRAYSIZE, tstarr); if (r < 0) { TESTRPT("miset_attr_values failed", r); } r = miget_attr_type(hvol, "/test1/stuff/hello", "animal", &data_type); if (r < 0) { TESTRPT("miget_attr_type failed", r); } if (data_type != MI_TYPE_STRING) { TESTRPT("miget_attr_type failed", data_type); } r = miget_attr_length(hvol, "/test1/stuff/hello", "animal", &length); if (r < 0) { TESTRPT("miget_attr_length failed", r); } if (length != 8) { TESTRPT("miget_attr_length failed", (int)length); } r = midelete_group(hvol, "/test1/stuff", "goodbye"); if (r >= 0) { TESTRPT("midelete_group failed", r); } r = midelete_group(hvol, "/test1/stuff", "hello"); /* This should succeed. */ if (r < 0) { TESTRPT("midelete_group failed", r); } r = miget_attr_length(hvol, "/test1/stuff/hello", "animal", &length); /* This should fail since we deleted the group. */ if (r >= 0) { TESTRPT("miget_attr_length not failed", r); } r = miget_attr_values(hvol, MI_TYPE_DOUBLE, "/test2", "maxvals", TESTARRAYSIZE, dblarr); if (r < 0) { TESTRPT("miget_attr_values failed", r); } for (r = 0; r < TESTARRAYSIZE; r++) { if (dblarr[r] != tstarr[r]) { TESTRPT("miget_attr_values mismatch", r); } } /* Get the values again in float rather than double format. */ r = miget_attr_values(hvol, MI_TYPE_FLOAT, "/test2", "maxvals", TESTARRAYSIZE, fltarr); if (r < 0) { TESTRPT("miget_attr_values failed", r); } for (r = 0; r < TESTARRAYSIZE; r++) { if (fltarr[r] != (float) tstarr[r]) { TESTRPT("miget_attr_values mismatch", r); fprintf(stderr, "fltarr[%d] = %f, tstarr[%d] = %f\n", r, fltarr[r], r, tstarr[r]); } } /* Get the values again in int rather than double format. */ r = miget_attr_values(hvol, MI_TYPE_INT, "/test2", "maxvals", TESTARRAYSIZE, intarr); if (r < 0) { TESTRPT("miget_attr_values failed", r); } for (r = 0; r < TESTARRAYSIZE; r++) { if (intarr[r] != (int) tstarr[r]) { TESTRPT("miget_attr_values mismatch", r); fprintf(stderr, "intarr[%d] = %d, tstarr[%d] = %d\n", r, intarr[r], r, (int) tstarr[r]); } } r = miget_attr_values(hvol, MI_TYPE_STRING, "/test1/stuff", "objtype", 128, valstr); if (r < 0) { TESTRPT("miget_attr_values failed", r); } if (strcmp(valstr, "automobile") != 0) { TESTRPT("miget_attr_values failed", 0); fprintf(stderr,"Expected :\"%s\" read \"%s\"\n","automobile",valstr); } /* Get the values again but this time with only enough space for the result with null termination. */ memset(valstr, 0x55, sizeof(valstr)); r = miget_attr_values(hvol, MI_TYPE_STRING, "/test1/stuff", "objtype", 11, valstr); if (r < 0) { TESTRPT("miget_attr_values failed", r); } if (strcmp(valstr, "automobile") != 0) { TESTRPT("miget_attr_values failed", 0); } /* Get the values again but this time with only enough space for the result and without null termination. */ memset(valstr, 0x55, sizeof(valstr)); r = miget_attr_values(hvol, MI_TYPE_STRING, "/test1/stuff", "objtype", 10, valstr); if (r < 0) { TESTRPT("miget_attr_values failed", r); } if (valstr[9] != 'e') { TESTRPT("miget_attr_values failed", 0); } if (valstr[10] != 0x55) { TESTRPT("miget_attr_values failed", 0); } r = miset_attr_values(hvol, MI_TYPE_STRING, "/test1/stuff", "objtype", 8, "bicycle"); if (r < 0) { TESTRPT("miset_attr_values failed on rewrite", r); } r = miget_attr_values(hvol, MI_TYPE_STRING, "/test1/stuff", "objtype", 128, valstr); if (r < 0) { TESTRPT("miget_attr_values failed", r); } if (strcmp(valstr, "bicycle") != 0) { TESTRPT("miget_attr_values failed", 0); } r = miset_attr_values(hvol, MI_TYPE_FLOAT, "/OPT", "zoom",1, &val1); if (r < 0) { TESTRPT("miset_attr_values failed", r); } r = miset_attr_values(hvol, MI_TYPE_FLOAT, "/OPT", "binning",1, &val2); if (r < 0) { TESTRPT("miset_attr_values failed", r); } r = miset_attr_values(hvol, MI_TYPE_FLOAT, "/OPT", "gain",1, &val1); if (r < 0) { TESTRPT("miset_attr_values failed", r); } r = milist_start(hvol, "/", 0, &hlist); if (r == MI_NOERROR) { count++; while (milist_attr_next(hvol, hlist, pathbuf, sizeof(pathbuf), namebuf, sizeof(namebuf)) == MI_NOERROR) { printf(" %s %s\n", pathbuf, namebuf); } } else { TESTRPT("milist_start failed", r); } milist_finish(hlist); printf("copy all attributes in the provided path in the new volume\n"); if((r = micopy_attr(hvol,"/OPT",hvol1))<0) TESTRPT("micopy_attr failed", r); printf("***************** \n"); r = milist_start(hvol1, "/", 1, &h1list); if (r == MI_NOERROR) { while( milist_grp_next(h1list, pathbuf1, sizeof(pathbuf1)-1) == MI_NOERROR) { printf("%s \n", pathbuf1); } } else { TESTRPT("milist_start failed", r); } r = milist_finish(h1list); if(r<0) { TESTRPT("milist_finish failed", r); } r = miclose_volume(hvol1); if(r<0) { TESTRPT("miclose_volume failed", r); } r = miclose_volume(hvol); if(r<0) { TESTRPT("miclose_volume failed", 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); }