int main() { int cdf, cdf2; int img; int dim[MAX_VAR_DIMS]; int dim2[MAX_VAR_DIMS]; long start[MAX_VAR_DIMS]; long count[MAX_VAR_DIMS]; double image[256*256]; int i, j, k, ioff; char filename[256]; char filename2[256]; set_ncopts(NC_VERBOSE|NC_FATAL); snprintf(filename, sizeof(filename), "test_minc-%d.mnc", getpid()); snprintf(filename2, sizeof(filename2), "test_minc2-%d.mnc", getpid()); cdf=micreate(filename, NC_CLOBBER); count[2]=5; count[1]=3; count[0]=7; dim[2]=ncdimdef(cdf, MIzspace, count[2]); dim[1]=ncdimdef(cdf, MIxspace, count[1]); dim[0]=ncdimdef(cdf, MIyspace, count[0]); dim2[0]=ncdimdef(cdf, MItime, NC_UNLIMITED); dim2[1]=dim[0]; dim2[2]=dim[1]; img=ncvardef(cdf, MIimage, NC_SHORT, 3, dim); (void) ncvardef(cdf, "testvar", NC_FLOAT, 2, dim2); (void) miattputstr(cdf, img, MIsigntype, MI_SIGNED); for (j=0; j<count[0]; j++) { for (i=0; i<count[1]; i++) { ioff=(j*count[1]+i)*count[2]; for (k=0; k<count[2]; k++) image[ioff+k]=ioff+k+10; } } cdf2=micreate(filename2,NC_CLOBBER); (void) ncdimdef(cdf2, "junkdim", NC_UNLIMITED); (void) micopy_all_var_defs(cdf, cdf2, 1, &img); (void) ncendef(cdf2); (void) ncendef(cdf); (void) miset_coords(3,0L,start); (void) mivarput(cdf, img, start, count, NC_DOUBLE, NULL, image); (void) micopy_all_var_values(cdf, cdf2, 1, &img); (void) miclose(cdf2); (void) miclose(cdf); unlink(filename); unlink(filename2); return(0); }
/* ----------------------------- MNI Header ----------------------------------- @NAME : save_volume_info @INPUT : input_icvid - input file icvid (MI_ERROR means no input volume) outfile - output file name arg_string - string giving argument list volume_info - volume information @OUTPUT : (nothing) @RETURNS : icv of output file @DESCRIPTION: Routine to save a 3-D volume, copying information from an optional input file. @METHOD : @GLOBALS : @CALLS : @CREATED : August 22, 1993 (Peter Neelin) @MODIFIED : ---------------------------------------------------------------------------- */ static int save_volume_info(int input_icvid, char *outfile, char *arg_string, Volume_Info *volume_info) { int mincid, icvid, inmincid; /* Create output file */ mincid = micreate(outfile, NC_NOCLOBBER); /* Open the input file if it is provided */ inmincid = MI_ERROR; if (input_icvid != MI_ERROR) { (void) miicv_inqint(input_icvid, MI_ICV_CDFID, &inmincid); } /* Set up variables and put output file in data mode */ setup_variables(inmincid, mincid, volume_info, arg_string); /* Create an icv and set it up */ icvid = miicv_create(); setup_output_icv(icvid); /* Attach the icv to the file */ (void) miicv_attach(icvid, mincid, ncvarid(mincid, MIimage)); return icvid; }
int main(int argc, char **argv) { int cdf; int img, img2; int dim[MAX_VAR_DIMS]; long start[MAX_VAR_DIMS]; long count[MAX_VAR_DIMS]; double image[256*256]; int i, itype, jtype; int cflag = 0; char filename[256]; #if MINC2 if (argc == 2 && !strcmp(argv[1], "-2")) { cflag = MI2_CREATE_V2; } #endif /* MINC2 */ snprintf(filename, sizeof(filename), "test_minc_types-%d.mnc", getpid()); ncopts=NC_VERBOSE|NC_FATAL; for (itype=0; itype<ntypes; itype++) { for (jtype=0; jtype<ntypes; jtype++) { cdf=micreate(filename, NC_CLOBBER | cflag); count[2]=256; count[1]=20; count[0]=7; dim[2]=ncdimdef(cdf, MIzspace, count[2]); dim[1]=ncdimdef(cdf, MIxspace, count[1]); dim[0]=ncdimdef(cdf, MIyspace, count[0]); img=ncvardef(cdf, MIimage, types[itype].type, 1, dim); (void) miattputstr(cdf, img, MIsigntype, types[itype].sign); img2=ncvardef(cdf, "image2", types[jtype].type, 1, dim); (void) miattputstr(cdf, img2, MIsigntype, types[jtype].sign); image[0]=10.0; image[1]=2.0*(-FLT_MAX); image[2]=2.0*FLT_MAX; image[3]=3.2; image[4]=3.7; image[5]=(-3.2); image[6]=(-3.7); #if 0 for (j=0; j<count[0]; j++) { for (i=0; i<count[1]; i++) { ioff=(j*count[1]+i)*count[2]; for (k=0; k<count[2]; k++) image[ioff+k]=ioff+k+10; } } #endif (void) ncendef(cdf); (void) miset_coords(3,0L,start); (void) mivarput(cdf, img, start, count, NC_DOUBLE, NULL, image); (void) mivarget(cdf, img, start, count, types[jtype].type, types[jtype].sign, image); (void) mivarput(cdf, img2, start, count, types[jtype].type, types[jtype].sign, image); (void) mivarget(cdf, img2, start, count, NC_DOUBLE, NULL, image); (void) printf("Image 1 : %s %s\n",types[itype].sign, types[itype].ctype); (void) printf("Image 2 : %s %s\n",types[jtype].sign, types[jtype].ctype); for (i=0;i<count[0];i++) (void) printf(" image[%d] = %g\n",(int) i, image[i]); (void) miclose(cdf); } } unlink(filename); return(0); }
int main(int argc, char **argv) { int icv, cdfid, img, max, min, dimvar; static int dim[MAX_VAR_DIMS]; static struct { long len; char *name;} diminfo[] = { { 7, MIzspace }, { 9, MIyspace }, { 2, MIxspace } }; /* static struct { long len; char *name;} diminfo[]= {3, MIzspace, 4, MIyspace, 5, MIxspace}; */ static int numdims=sizeof(diminfo)/sizeof(diminfo[0]); static long coord[]={0,0,0}; static long count[]={3,4,5}; double dvalue; short int ivalue[]={ 111, 113, 115, 117, 119, 121, 123, 125, 127, 129, 131, 133, 135, 137, 139, 141, 143, 145, 147, 149, 211, 213, 215, 217, 219, 221, 223, 225, 227, 229, 231, 233, 235, 237, 239, 241, 243, 245, 247, 249, 311, 313, 315, 317, 319, 321, 323, 325, 327, 329, 331, 333, 335, 337, 339, 341, 343, 345, 347, 349 }; int i, j, k; int cflag = 0; #if MINC2 if (argc == 2 && !strcmp(argv[1], "-2")) { cflag = MI2_CREATE_V2; } #endif /* MINC2 */ icv=miicv_create(); miicv_setint(icv, MI_ICV_XDIM_DIR, MI_ICV_NEGATIVE); miicv_setint(icv, MI_ICV_YDIM_DIR, MI_ICV_NEGATIVE); miicv_setint(icv, MI_ICV_ZDIM_DIR, MI_ICV_NEGATIVE); miicv_setint(icv, MI_ICV_NUM_IMGDIMS, 3); miicv_setint(icv, MI_ICV_DIM_SIZE+0, 5); miicv_setint(icv, MI_ICV_DIM_SIZE+1, 4); miicv_setint(icv, MI_ICV_DIM_SIZE+2, 3); miicv_setint(icv, MI_ICV_DO_DIM_CONV, TRUE); miicv_setint(icv, MI_ICV_KEEP_ASPECT, FALSE); miicv_setint(icv, MI_ICV_DO_NORM, TRUE); cdfid=micreate("test.mnc", NC_CLOBBER | cflag); for (i=0; i<numdims; i++) { dim[i]=ncdimdef(cdfid, diminfo[i].name, diminfo[i].len); dimvar=micreate_std_variable(cdfid, diminfo[i].name, NC_DOUBLE, 0, &dim[i]); miattputdbl(cdfid, dimvar, MIstep, 0.8); miattputdbl(cdfid, dimvar, MIstart, 22.0); } img=micreate_std_variable(cdfid, MIimage, NC_SHORT, numdims, dim); max=micreate_std_variable(cdfid, MIimagemax, NC_DOUBLE, 1, dim); min=micreate_std_variable(cdfid, MIimagemin, NC_DOUBLE, 1, dim); ncendef(cdfid); for (i=0; i<diminfo[0].len; i++) { dvalue = 200; coord[0]=i; ncvarput1(cdfid, max, coord, &dvalue); dvalue = -dvalue; ncvarput1(cdfid, min, coord, &dvalue); } coord[0]=0; miicv_attach(icv, cdfid, img); miicv_inqdbl(icv, MI_ICV_ADIM_START, &dvalue); printf("adim start = %g", dvalue); miicv_inqdbl(icv, MI_ICV_ADIM_STEP, &dvalue); printf(", step = %g\n", dvalue); miicv_inqdbl(icv, MI_ICV_BDIM_START, &dvalue); printf("bdim start = %g", dvalue); miicv_inqdbl(icv, MI_ICV_BDIM_STEP, &dvalue); printf(", step = %g\n", dvalue); miicv_inqdbl(icv, MI_ICV_NORM_MAX, &dvalue); printf("norm : max = %g", dvalue); miicv_inqdbl(icv, MI_ICV_NORM_MIN, &dvalue); printf(", min = %g\n", dvalue); miicv_put(icv, coord, count, ivalue); miicv_get(icv, coord, count, ivalue); for (i=0; i<3; i++) { for (j=0; j<4; j++) { for (k=0; k<5; k++) { printf("%5d",ivalue[i*20+j*5+k]); } printf("\n"); } } miclose(cdfid); miicv_free(icv); return 0; }
int main(int argc, char **argv) { int icv, cdfid, img, max, min; static char *typenm[]={"short", "double"}; static char *boolnm[] = {"true", "false"}; static nc_type intypes[] = {NC_SHORT, NC_DOUBLE}; static int norms[] = {TRUE, FALSE}; static nc_type outtypes[] = {NC_SHORT, NC_DOUBLE}; static int maxpresent[] = {TRUE, FALSE}; static int valpresent[] = {TRUE, FALSE}; static int dim[MAX_VAR_DIMS]; static struct { long len; char *name;} diminfo[] = { { 3, MIzspace }, { 1, MIyspace }, { 1, MIxspace } }; static int numdims=sizeof(diminfo)/sizeof(diminfo[0]); static long coord[]={0,0,0}; static long count[]={1,1,1}; static double max_values[] = {0.4, 0.6, 0.8}; double dvalue; short int ivalue; int i, intype, inorm, outtype, imax, ival; int cflag = 0; char filename[256]; #if MINC2 if (argc == 2 && !strcmp(argv[1], "-2")) { cflag = MI2_CREATE_V2; } #endif /* MINC2 */ snprintf(filename, sizeof(filename), "test_icv_range-%d.mnc", getpid()); for (intype=0; intype<MAX_IN_TYPES; intype++) { for (inorm=0; inorm<MAX_NORM; inorm++) { icv=miicv_create(); miicv_setint(icv, MI_ICV_TYPE, intypes[intype]); miicv_setint(icv, MI_ICV_DO_NORM, norms[inorm]); miicv_setdbl(icv, MI_ICV_VALID_MAX, 20000.0); miicv_setdbl(icv, MI_ICV_VALID_MIN, 0.0); for (outtype=0; outtype<MAX_OUT_TYPES; outtype++) { for (imax=0; imax<MAX_MAX; imax++) { for (ival=0; ival<MAX_VAL; ival++) { printf( "in : %s, out : %s, norm : %s, imgmax : %s, valid : %s\n", typenm[intype], typenm[outtype], boolnm[inorm], boolnm[imax], boolnm[ival]); cdfid=micreate(filename, NC_CLOBBER | cflag); for (i=0; i<numdims; i++) dim[i]=ncdimdef(cdfid, diminfo[i].name, diminfo[i].len); img=micreate_std_variable(cdfid, MIimage, outtypes[outtype], numdims, dim); if (maxpresent[imax]) { max=micreate_std_variable(cdfid, MIimagemax, NC_DOUBLE, 1, dim); min=micreate_std_variable(cdfid, MIimagemin, NC_DOUBLE, 1, dim); } if (valpresent[ival]) { dvalue = 32000; ncattput(cdfid, img, MIvalid_max, NC_DOUBLE, 1, &dvalue); dvalue = 0; ncattput(cdfid, img, MIvalid_min, NC_DOUBLE, 1, &dvalue); } ncendef(cdfid); if (maxpresent[imax]) { for (i=0; i<3; i++) { dvalue = max_values[i]; coord[0]=i; ncvarput1(cdfid, max, coord, &dvalue); dvalue = -dvalue; ncvarput1(cdfid, min, coord, &dvalue); } coord[0]=0; } miicv_attach(icv, cdfid, img); if (intypes[intype]==NC_DOUBLE) { dvalue = 0.2; miicv_put(icv, coord, count, &dvalue); } else { ivalue = 12500; miicv_put(icv, coord, count, &ivalue); } dvalue = 0; mivarget1(cdfid, img, coord, NC_DOUBLE, MI_SIGNED, &dvalue); printf(" file value = %g\n", dvalue); if (intypes[intype]==NC_DOUBLE) { miicv_get(icv, coord, count, &dvalue); } else { miicv_get(icv, coord, count, &ivalue); dvalue=ivalue; } printf(" icv value = %g\n", dvalue); miclose(cdfid); } } } miicv_free(icv); } } unlink(filename); return 0; }
MNCAPI int minc_save_start(char *path, /* Path to the file */ int filetype, /* Date type as stored in the file */ long ct, /* Total length of time axis, in voxels */ long cz, /* Total length of Z axis, in voxels */ long cy, /* Total length of Y axis, in voxels */ long cx, /* Total length of X axis, in voxels */ double dt, /* Sample width along time axis, in seconds */ double dz, /* Sample width along Z axis, in mm */ double dy, /* Sample width along Y axis, in mm */ double dx, /* Sample width along X axis, in mm */ void *infoptr, /* Opaque file structure information */ const char *history) /* New history information */ { int fd; /* MINC file descriptor */ int dim_id[MI_S_NDIMS]; /* netCDF dimension ID array */ int var_ndims; /* Number of dimensions per variable */ int var_dims[MI_S_NDIMS]; /* Dimension ID's per variable */ int i, j; /* Generic loop counters */ int old_ncopts; /* For supressing fatal error messages */ struct file_info *p_file; /* For accessing the file structure */ struct var_info *p_var; struct att_info *p_att; int var_id; /* netCDF ID for variable */ char *signstr; nc_type nctype; old_ncopts =get_ncopts(); set_ncopts(0); fd = micreate(path, NC_CLOBBER); set_ncopts(old_ncopts); if (fd < 0) { return (MINC_STATUS_ERROR); } if (ct > 0) { dim_id[MI_S_T] = ncdimdef(fd, MItime, ct); micreate_std_variable(fd, MItime, NC_INT, 0, NULL); if (dt > 0.0) { miattputdbl(fd, ncvarid(fd, MItime), MIstep, dt); } } else { dim_id[MI_S_T] = -1; } if (cz > 0) { dim_id[MI_S_Z] = ncdimdef(fd, MIzspace, cz); micreate_std_variable(fd, MIzspace, NC_INT, 0, NULL); if (dz > 0.0) { miattputdbl(fd, ncvarid(fd, MIzspace), MIstep, dz); } } else { dim_id[MI_S_Z] = -1; } if (cy > 0) { dim_id[MI_S_Y] = ncdimdef(fd, MIyspace, cy); micreate_std_variable(fd, MIyspace, NC_INT, 0, NULL); if (dy > 0.0) { miattputdbl(fd, ncvarid(fd, MIyspace), MIstep, dy); } } else { return (MINC_STATUS_ERROR); /* Must define Y */ } if (cx > 0) { dim_id[MI_S_X] = ncdimdef(fd, MIxspace, cx); micreate_std_variable(fd, MIxspace, NC_INT, 0, NULL); if (dx > 0.0) { miattputdbl(fd, ncvarid(fd, MIxspace), MIstep, dx); } } else { return (MINC_STATUS_ERROR); /* Must define X */ } /* The var_dims[] array is the array of actual dimension ID's to * be used in defining the image variables. Here I set it up by * copying all valid dimension ID's from the dim_id[] array. */ var_ndims = 0; for (i = 0; i < MI_S_NDIMS; i++) { if (dim_id[i] >= 0) { var_dims[var_ndims] = dim_id[i]; var_ndims++; } } minc_simple_to_nc_type(filetype, &nctype, &signstr); /* Create the image variable with the standard * dimension order, and the same type as the template * file. */ micreate_std_variable(fd, MIimage, nctype, var_ndims, var_dims); micreate_std_variable(fd, MIimagemin, NC_DOUBLE, 1, var_dims); micreate_std_variable(fd, MIimagemax, NC_DOUBLE, 1, var_dims); /* Copy information from the infoptr to the output. */ if ((p_file = infoptr) != NULL) { old_ncopts =get_ncopts(); set_ncopts(0); for (i = 0; i < p_file->file_natts; i++) { p_att = &p_file->file_atts[i]; if (strcmp(p_att->att_name, "ident") != 0) { ncattput(fd, NC_GLOBAL, p_att->att_name, p_att->att_type, p_att->att_len, p_att->att_val); } } for (i = 0; i < p_file->file_nvars; i++) { p_var = &p_file->file_vars[i]; if ((var_id = ncvarid(fd, p_var->var_name)) < 0) { var_id = ncvardef(fd, p_var->var_name, p_var->var_type, p_var->var_ndims, p_var->var_dims); } for (j = 0; j < p_var->var_natts; j++) { p_att = &p_var->var_atts[j]; ncattput(fd, var_id, p_att->att_name, p_att->att_type, p_att->att_len, p_att->att_val); } } set_ncopts(old_ncopts); } miattputstr(fd, ncvarid(fd, MIimage), MIcomplete, MI_FALSE); miattputstr(fd, ncvarid(fd, MIimage), MIsigntype, signstr); miappend_history(fd, history); ncendef(fd); return fd; }
/* Test case 1 - file creation & definition. */ static int test1(struct testinfo *ip, struct dimdef *dims, int ndims) { int varid; int stat; int i; /* Test case #1 - file creation */ ip->name = micreate_tempfile(); if (ip->name == NULL) { FUNC_ERROR("micreate_tempfile\n"); } ip->fd = micreate(ip->name, NC_CLOBBER); if (ip->fd < 0) { FUNC_ERROR("micreate"); } /* Have to use ncdimdef() here since there is no MINC equivalent. Sigh. */ for (i = 0; i < ndims; i++) { /* Define the dimension */ ip->dim[i] = ncdimdef(ip->fd, dims[i].name, dims[i].length); if (ip->dim[i] < 0) { FUNC_ERROR("ncdimdef"); } /* Create the dimension variable. */ varid = micreate_std_variable(ip->fd, dims[i].name, NC_DOUBLE, 0, &ip->dim[i]); if (varid < 0) { FUNC_ERROR("micreate_std_variable"); } stat = miattputdbl(ip->fd, varid, MIstep, 0.8); if (stat < 0) { FUNC_ERROR("miattputdbl"); } stat = miattputdbl(ip->fd, varid, MIstart, 22.0); if (stat < 0) { FUNC_ERROR("miattputdbl"); } } /* Create the image-max variable. */ ip->maxid = micreate_std_variable(ip->fd, MIimagemax, NC_FLOAT, 0, NULL); if (ip->maxid < 0) { FUNC_ERROR("micreate_std_variable"); } /* Create the image-min variable. */ ip->minid = micreate_std_variable(ip->fd, MIimagemin, NC_FLOAT, 0, NULL); if (ip->minid < 0) { FUNC_ERROR("micreate_std_variable"); } ip->imgid = micreate_std_variable(ip->fd, MIimage, NC_INT, ndims, ip->dim); if (ip->imgid < 0) { FUNC_ERROR("micreate_std_variable"); } ip->test_group = ncvardef(ip->fd,(char*)"test",NC_INT,0,0);/* micreate_group_variable(ip->fd,(char*)"test");*/ if(ip->test_group<0) { FUNC_ERROR("micreate_group_variable"); } ip->large_attribute=calloc(ip->attribute_size,sizeof(char)); memset(ip->large_attribute,'X',ip->attribute_size-1); ip->test_attribute = ncattput(ip->fd, ip->test_group, "test", NC_CHAR, ip->attribute_size, ip->large_attribute); return (0); }
/* Test case 1 - file creation & definition. */ int test1(struct testinfo *ip, struct dimdef *dims, int ndims) { int fd2; int varid; int stat; int i; /* Test case #1 - file creation */ ip->name = micreate_tempfile(); if (ip->name == NULL) { FUNC_ERROR("micreate_tempfile\n"); } ip->fd = micreate(ip->name, NC_CLOBBER); if (ip->fd < 0) { FUNC_ERROR("micreate"); } /* Try to create another file of the same name - should fail. */ fd2 = micreate(ip->name, NC_NOCLOBBER); if (fd2 >= 0) { FUNC_ERROR("micreate"); } /* Try to open the file for write - should fail. */ /* VF: it doesn't fail! fd2 = miopen(ip->name, NC_WRITE); if (fd2 >= 0) { FUNC_ERROR("miopen"); } */ /* Have to use ncdimdef() here since there is no MINC equivalent. Sigh. */ for (i = 0; i < ndims; i++) { /* Define the dimension */ ip->dim[i] = ncdimdef(ip->fd, dims[i].name, dims[i].length); if (ip->dim[i] < 0) { FUNC_ERROR("ncdimdef"); } /* Create the dimension variable. */ varid = micreate_std_variable(ip->fd, dims[i].name, NC_DOUBLE, 0, &ip->dim[i]); if (varid < 0) { FUNC_ERROR("micreate_std_variable"); } stat = miattputdbl(ip->fd, varid, MIstep, 0.8); if (stat < 0) { FUNC_ERROR("miattputdbl"); } stat = miattputdbl(ip->fd, varid, MIstart, 22.0); if (stat < 0) { FUNC_ERROR("miattputdbl"); } } /* Try to create a bogus variable. This should trigger an error. */ varid = micreate_std_variable(ip->fd, "xyzzy", NC_DOUBLE, 0, NULL); if (varid >= 0) { FUNC_ERROR("micreate_std_variable"); } /* Create the image-max variable. */ ip->maxid = micreate_std_variable(ip->fd, MIimagemax, NC_FLOAT, 0, NULL); if (ip->maxid < 0) { FUNC_ERROR("micreate_std_variable"); } /* Create the image-min variable. */ ip->minid = micreate_std_variable(ip->fd, MIimagemin, NC_FLOAT, 0, NULL); if (ip->minid < 0) { FUNC_ERROR("micreate_std_variable"); } ip->imgid = micreate_std_variable(ip->fd, MIimage, NC_INT, ndims, ip->dim); if (ip->imgid < 0) { FUNC_ERROR("micreate_std_variable"); } return (0); }
int upet_to_minc(char *hdr_fname, char *img_fname, char *out_fname, char *prog_name) { char *line_ptr; char line_buf[1024]; char *val_ptr; int in_header; double dbl_tmp; int int_tmp; struct conversion_info ci; struct keywd_entry *ke_ptr; int is_known; char *argv_tmp[5]; char *out_history; ci.hdr_fp = fopen(hdr_fname, "r"); /* Text file */ if (ci.hdr_fp == NULL) { perror(hdr_fname); return (-1); } ci.img_fp = fopen(img_fname, "rb"); /* Binary file */ if (ci.img_fp == NULL) { perror(img_fname); return (-1); } ci.mnc_fd = micreate(out_fname, NC_NOCLOBBER); if (ci.mnc_fd < 0) { perror(out_fname); return (-1); } ci.frame_zero = -1; /* Initial frame is -1 until set. */ /* Define the basic MINC group variables. */ micreate_group_variable(ci.mnc_fd, MIstudy); micreate_group_variable(ci.mnc_fd, MIacquisition); micreate_group_variable(ci.mnc_fd, MIpatient); ncvardef(ci.mnc_fd, "micropet", NC_SHORT, 0, NULL); /* Fake the history here */ argv_tmp[0] = prog_name; argv_tmp[1] = VERSIONSTR; argv_tmp[2] = hdr_fname; argv_tmp[3] = img_fname; argv_tmp[4] = out_fname; out_history = time_stamp(5, argv_tmp); miattputstr(ci.mnc_fd, NC_GLOBAL, MIhistory, out_history); free(out_history); in_header = 1; ci.frame_nbytes = 1; ci.frame_nvoxels = 1; /* When we read voxels, we need COMBINED_SCALE_FACTOR() to have a sane * value for all modalities. Set defaults for these in case the modality * does not define one of these factors. For example, a CT (modality 2) * will not define isotope_branching_fraction or calibration_factor. */ ci.scale_factor = 1.0; ci.calibration_factor = 1.0; ci.isotope_branching_fraction = 1.0; /* Collect the headers */ while (fgets(line_buf, sizeof(line_buf), ci.hdr_fp) != NULL) { if (line_buf[0] == '#') /* */ continue; line_ptr = line_buf; while (!isspace(*line_ptr)) { line_ptr++; } *line_ptr++ = '\0'; val_ptr = line_ptr; while (*line_ptr != '\n' && *line_ptr != '\r' && *line_ptr != '\0') { line_ptr++; } *line_ptr = '\0'; is_known = 0; if (in_header) { if (*val_ptr != '\0') { /* Save the raw attribute into the file */ ncattput(ci.mnc_fd, ncvarid(ci.mnc_fd, "micropet"), line_buf, NC_CHAR, strlen(val_ptr), val_ptr); } for (ke_ptr = vol_atts; ke_ptr->upet_kwd != NULL; ke_ptr++) { if (!strcmp(ke_ptr->upet_kwd, line_buf)) { is_known = 1; if (ke_ptr->func != NULL) { (*ke_ptr->func)(&ci, val_ptr, ke_ptr->mnc_var, ke_ptr->mnc_att); } else if (ke_ptr->mnc_var != NULL && ke_ptr->mnc_att != NULL) { /* Interpret based upon type */ switch (ke_ptr->upet_type) { case UPET_TYPE_INT: int_tmp = atoi(val_ptr); miattputint(ci.mnc_fd, ncvarid(ci.mnc_fd, ke_ptr->mnc_var), ke_ptr->mnc_att, int_tmp); break; case UPET_TYPE_REAL: dbl_tmp = atof(val_ptr); miattputdbl(ci.mnc_fd, ncvarid(ci.mnc_fd, ke_ptr->mnc_var), ke_ptr->mnc_att, dbl_tmp); break; case UPET_TYPE_STR: miattputstr(ci.mnc_fd, ncvarid(ci.mnc_fd, ke_ptr->mnc_var), ke_ptr->mnc_att, val_ptr); break; } } break; } } } else { /* Not in the header any longer */ for (ke_ptr = frm_atts; ke_ptr->upet_kwd != NULL; ke_ptr++) { if (!strcmp(ke_ptr->upet_kwd, line_buf)) { is_known = 1; if (ke_ptr->func != NULL) { (*ke_ptr->func)(&ci, val_ptr, ke_ptr->mnc_var, ke_ptr->mnc_att); } break; } } } if (!is_known) { if (!strcmp(line_buf, "end_of_header")) { if (in_header) { in_header = 0; copy_init(&ci); } else { copy_frame(&ci); } } else { message(MSG_WARNING, "Unrecognized keyword %s\n", line_buf); } } } fclose(ci.hdr_fp); fclose(ci.img_fp); miclose(ci.mnc_fd); return (0); }