Index:src/csh/FIASCO 22c22 < echo '$Id: FIASCO,v 1.9 1998/04/17 20:42:52 welling Exp $'\ --- > echo '$Id: FIASCO,v 1.10 1998/07/07 23:35:01 welling Exp $'\ 29c29 < setenv FIASCO_PATCHLVL 0 --- > setenv FIASCO_PATCHLVL 1 Index:src/libmri/mri_delete_chunk.c 35c35 < chunk[0] == '\0'; --- > chunk[0] = '\0'; Index:src/csh/epi.defaults.csh 17c17 < echo '#$Id: epi.defaults.csh,v 1.12 1998/04/22 23:51:01 welling Exp $' --- > echo '#$Id: epi.defaults.csh,v 1.14 1998/07/07 23:19:06 welling Exp $' 89c89 < # ts.partialk.csh --- > # epi.partialk.csh 330,331c330 < @ F_UPTSQR = $F_UPPERT * $F_UPPERT < setenv F_UPPERF $F_UPTSQR --- > setenv F_UPPERF 36 Index:src/csh/epi.local.csh 17c17 < # $Id: epi.local.csh,v 1.4 1998/04/17 20:34:08 welling Exp $ --- > # $Id: epi.local.csh,v 1.5 1998/07/07 23:18:58 welling Exp $ 42,43c42 < @ F_UPTSQR = $F_UPPERT * $F_UPPERT < setenv F_UPPERF $F_UPTSQR --- > setenv F_UPPERF 36 Index:src/csh/epi_brain.defaults.csh 17c17 < echo '#$Id: epi_brain.defaults.csh,v 1.13 1998/05/08 21:54:26 welling Exp $' --- > echo '#$Id: epi_brain.defaults.csh,v 1.14 1998/07/07 23:18:52 welling Exp $' 336,337c336 < @ F_UPTSQR = $F_UPPERT * $F_UPPERT < setenv F_UPPERF $F_UPTSQR --- > setenv F_UPPERF 36 Index:src/csh/epi_brain.local.csh 17c17 < # $Id: epi_brain.local.csh,v 1.4 1997/12/17 23:47:30 welling Exp $ --- > # $Id: epi_brain.local.csh,v 1.5 1998/07/07 23:18:45 welling Exp $ 42,43c42 < @ F_UPTSQR = $F_UPPERT * $F_UPPERT < setenv F_UPPERF $F_UPTSQR --- > setenv F_UPPERF 36 Index:src/csh/ts.defaults.csh 17c17 < echo '#$Id: ts.defaults.csh,v 1.13 1998/03/06 01:02:04 welling Exp $' --- > echo '#$Id: ts.defaults.csh,v 1.14 1998/07/07 23:18:37 welling Exp $' 364,365c364 < @ F_UPTSQR = $F_UPPERT * $F_UPPERT < setenv F_UPPERF $F_UPTSQR --- > setenv F_UPPERF 36 Index:src/csh/ts.local.csh 17c17 < # $Id: ts.local.csh,v 1.5 1997/12/18 00:00:38 welling Exp $ --- > # $Id: ts.local.csh,v 1.6 1998/07/07 23:18:29 welling Exp $ 45,46c45 < @ F_UPTSQR = $F_UPPERT * $F_UPPERT < setenv F_UPPERF $F_UPTSQR --- > setenv F_UPPERF 36 Index:src/csh/ts_brain.defaults.csh 17c17 < echo '#$Id: ts_brain.defaults.csh,v 1.2 1998/05/08 21:54:57 welling Exp $' --- > echo '#$Id: ts_brain.defaults.csh,v 1.3 1998/07/07 23:18:20 welling Exp $' 368,369c368 < @ F_UPTSQR = $F_UPPERT * $F_UPPERT < setenv F_UPPERF $F_UPTSQR --- > setenv F_UPPERF 36 Index:src/csh/ts_brain.local.csh 17c17 < # $Id: ts_brain.local.csh,v 1.1 1998/04/17 20:41:54 welling Exp $ --- > # $Id: ts_brain.local.csh,v 1.2 1998/07/07 23:18:14 welling Exp $ 45,46c45 < @ F_UPTSQR = $F_UPPERT * $F_UPPERT < setenv F_UPPERF $F_UPTSQR --- > setenv F_UPPERF 36 Index:src/csh/spiral.defaults.csh 17c17 < echo '$Id: spiral.defaults.csh,v 1.7 1998/03/06 00:57:03 welling Exp $' --- > echo '$Id: spiral.defaults.csh,v 1.8 1998/07/07 23:18:07 welling Exp $' 259,260c259 < @ F_UPTSQR = $F_UPPERT * $F_UPPERT < setenv F_UPPERF $F_UPTSQR --- > setenv F_UPPERF 36 Index:src/csh/spiral.local.csh 17c17 < #$Id: spiral.local.csh,v 1.5 1997/11/26 00:50:25 welling Exp $ --- > #$Id: spiral.local.csh,v 1.6 1998/07/07 23:17:56 welling Exp $ 41,42c41 < @ F_UPTSQR = $F_UPPERT * $F_UPPERT < setenv F_UPPERF $F_UPTSQR --- > setenv F_UPPERF 36 Index:src/csh/spiral_brain.defaults.csh 17c17 < echo '$Id: spiral_brain.defaults.csh,v 1.8 1998/05/29 21:54:26 welling Exp $' --- > echo '$Id: spiral_brain.defaults.csh,v 1.9 1998/07/07 23:17:39 welling Exp $' 262,263c262 < @ F_UPTSQR = $F_UPPERT * $F_UPPERT < setenv F_UPPERF $F_UPTSQR --- > setenv F_UPPERF 36 Index:src/csh/spiral_brain.local.csh 17c17 < #$Id: spiral_brain.local.csh,v 1.5 1997/12/17 23:47:10 welling Exp $ --- > #$Id: spiral_brain.local.csh,v 1.6 1998/07/07 23:17:31 welling Exp $ 41,42c41 < @ F_UPTSQR = $F_UPPERT * $F_UPPERT < setenv F_UPPERF $F_UPTSQR --- > setenv F_UPPERF 36 Index:src/csh/makeps.csh 17c17 < echo '#$Id: makeps.csh,v 1.7 1997/11/25 21:31:56 welling Exp $' --- > echo '#$Id: makeps.csh,v 1.8 1998/07/07 23:24:48 welling Exp $' 81,82d80 < @ fmap_bound = $F_UPPERF < @ fmap_lbound = - $fmap_bound 91c89 < -lowthresh $fmap_lbound -highthresh $fmap_bound \ --- > -lowthresh $0.0 -highthresh $F_UPPERF \ 95c93 < setenv F_PS_TITLE2 "$j cutoff $fmap_bound" --- > setenv F_PS_TITLE2 "$j cutoff $F_UPPERF" Index:src/csh/epi.partialk.csh 17c17 < echo '$Id: epi.partialk.csh,v 1.1 1998/04/17 20:49:05 welling Exp $' --- > echo '$Id: epi.partialk.csh,v 1.2 1998/07/07 23:47:45 welling Exp $' 21c21,22 < partialk -reverse $F_PARTIALK_REVERSE -dim 64 \ --- > @ newdim = 2 * $F_CLIP1_YCENTER > partialk -reverse $F_PARTIALK_REVERSE -dim $newdim \ Index:src/csh/ts.partialk.csh 17c17 < echo '$Id: ts.partialk.csh,v 1.2 1998/03/06 01:03:45 welling Exp $' --- > echo '$Id: ts.partialk.csh,v 1.3 1998/07/07 23:48:31 welling Exp $' 21c21,22 < partialk -reverse $F_PARTIALK_REVERSE -dim 128 \ --- > @ newdim = 2 * $F_CLIP1_YCENTER > partialk -reverse $F_PARTIALK_REVERSE -dim $newdim \ Index:src/mri_util/Makefile 12c12,13 < $(CB)/mri_rpn_math $(CB)/mri_splus_filter $(CB)/mri_subset --- > $(CB)/mri_rpn_math $(CB)/mri_splus_filter $(CB)/mri_subset \ > $(CB)/mri_interp 14c15 < PKG_LIBS = -lfmri -lmri -lpar -lbio -lacct -lmisc -lcrg -lm --- > PKG_LIBS = -lfmri -lmri -lpar -lbio -lacct -lmisc -lcrg -lm 19,20c20,22 < splus_binary_pipes.c mri_subset.c < HFILES= slave_splus.h --- > splus_binary_pipes.c mri_subset.c \ > mri_interp.c > HFILES= slave_splus.h 23c25 < mri_subset_help.help --- > mri_subset_help.help mri_interp_help.help 41a44,53 > $(SINGLE_HELP_LD) > > $O/mri_interp.o: mri_interp.c > $(CC_RULE) > > $O/mri_interp_help.o: mri_interp_help.help > $(HELP_RULE) > > $(CB)/mri_interp: $O/mri_interp.o \ > $O/mri_interp_help.o $(LIBFILES) Index:src/csh/epi.ireg.csh 18c18 < echo '#$Id: epi.ireg.csh,v 1.1 1997/07/01 21:43:02 welling Exp $' --- > echo '#$Id: epi.ireg.csh,v 1.2 1998/07/08 00:01:21 welling Exp $' 20c20 < -dataout $2.dat -parameters par/$F_PARSM_PARMS --- > -dataout .dat -parameters par/$F_PARSM_PARMS Index:src/csh/ts.ireg.csh 18c18 < echo '#$Id: ts.ireg.csh,v 1.1 1997/07/30 23:58:32 welling Exp $' --- > echo '#$Id: ts.ireg.csh,v 1.2 1998/07/08 00:00:54 welling Exp $' 20c20 < -dataout $2.dat -parameters par/$F_PARSM_PARMS --- > -dataout .dat -parameters par/$F_PARSM_PARMS *** /home/STUPID/fiasco/Fiasco4.1/src/mri_util/mri_interp.c Wed Jul 8 15:27:09 1998 --- src/mri_util/mri_interp.c Tue Jul 7 14:39:33 1998 *************** *** 0 **** --- 1,422 ---- + /************************************************************ + * * + * mri_interp.c * + * * + * Permission is hereby granted to any individual or * + * institution for use, copying, or redistribution of * + * this code and associated documentation, provided * + * that such code and documentation are not sold for * + * profit and the following copyright notice is retained * + * in the code and documentation: * + * Copyright (c) 1997 Department of Statistics, * + * Carnegie Mellon University * + * * + * Original programming by Joel Welling, 5/98 * + ************************************************************/ + /************************************************************* + + DESCRIPTION OF MRI_INTERP + + *Usage + + mri_interp takes a pgh MRI dataset of any type, and outputs + a dataset of the same type containing interpolated data. + The interpolated data spans the range of one of the dimensions + of the input data, but has a different extent than that of + the input dimension. The interpolation operation acts on all + chunks in the dataset. + + mri_interp -d dim -e extent [-l | -c] [-v] infile outfile + + -d dim (where dim is a single character) specifies the dimension + to be interpolated. Valid values are + one character long; case is ignored. + -e extent specifies the output extent of that dimension. + -l specifies linear interpolation + -c specifies constant interpolation based on the nearest input + point. -l and -c are mutually exclusive; -l is the default. + -v sets verbose output + infile specifies the input dataset + outfile specifies the output dataset + + Chunks not containing the selected dimension are copied verbatim. + All chunks containing the given dimension will be interpolated. + Note that this can give confusing results if the extents of the + dimension vary between chunks! + + **************************************************************/ + + #include + #include + #include + #include + #include "mri.h" + #include "fmri.h" + #include "misc.h" + #include "stdcrg.h" + + #define KEYBUF_SIZE 512 + + static char rcsid[] = "$Id: mri_interp.c,v 1.2 1998/07/07 18:39:33 welling Exp $"; + + static MRI_Dataset *Input = NULL, *Output = NULL; + static char selected_dim[512]= ""; + static int new_extent; + static int data_changed= 0; + static char* progname; + static int const_flag= 0; + static int verbose_flag= 0; + + static void safe_copy(char* str1, char* str2) { + strncpy(str1, str2, KEYBUF_SIZE); + str1[KEYBUF_SIZE-1]= '\0'; + } + + static void safe_concat(char* str1, char* str2) { + strncat(str1, str2, (KEYBUF_SIZE-strlen(str1))-1); + } + + static int get_chunk_type(MRI_Dataset* ds, char* chunk) + { + char key_buf[KEYBUF_SIZE]; + + safe_copy(key_buf,chunk); + safe_concat(key_buf,".datatype"); + if (mri_has(ds, key_buf)) { + char* type_name= mri_get_string(ds, key_buf); + if (!strcmp(type_name,"uint8")) return MRI_UNSIGNED_CHAR; + else if (!strcmp(type_name,"int16")) return MRI_SHORT; + else if (!strcmp(type_name,"int32")) return MRI_INT; + else if (!strcmp(type_name,"float32")) return MRI_FLOAT; + else if (!strcmp(type_name,"float64")) return MRI_DOUBLE; + else Abort("%s: unknown data type for key %s!\n",progname,key_buf); + } + else Abort("%s: missing tag %s!\n",progname,key_buf); + + return 0; /* not reached */ + } + + static int safe_get_extent(MRI_Dataset* ds, char* chunk, char* dim) + { + char key_buf[KEYBUF_SIZE]; + char dim_buf[4]; + dim_buf[0]= *dim; + dim_buf[1]= '\0'; + safe_copy(key_buf,chunk); + safe_concat(key_buf,".extent."); + safe_concat(key_buf,dim_buf); + if (mri_has(Input,key_buf)) return mri_get_int(Input,key_buf); + else Abort("%s: input missing tag %s!\n",progname,key_buf); + return 0; /* not reached */ + } + + static void calc_sizes(char* this_chunk, char* dimstr, + int* fast_blocksize_out, int* slow_blocksize_out ) { + /* This routine will fail if selected_dim is not in dimstr! */ + int fast_blocksize; + int slow_blocksize; + char* this_dim; + + fast_blocksize= 1; + + this_dim= dimstr; + while (*this_dim != *selected_dim) + fast_blocksize *= safe_get_extent(Input,this_chunk,this_dim++); + + this_dim++; /* step over selected dim */ + + slow_blocksize= 1; + while (*this_dim) + slow_blocksize *= safe_get_extent(Input, this_chunk, this_dim++); + + *fast_blocksize_out= fast_blocksize; + *slow_blocksize_out= slow_blocksize; + } + + static void type_interp( void* out_out, void* low_in, void* high_in, + float shift, int n, int type ) + { + int i; + + switch (type) { + + case MRI_UNSIGNED_CHAR: { + unsigned char* low= low_in; + unsigned char* high= high_in; + unsigned char* out= out_out; + for (i=0; i %d at %d\n", + ratio, fast_blksize, selected_extent, in_offset, + new_extent, out_offset); + for (i=0; i %d at %d\n", + ratio, fast_blksize, selected_extent, in_offset, + new_extent, out_offset); + low_chunk= mri_get_chunk(Input, this_chunk, fast_blksize, + in_offset, type); + high_chunk= mri_get_chunk(Input, this_chunk, fast_blksize, + in_offset + fast_blksize, type); + for (i=0; i=1.0) { + /* Load a new row */ + shift -= 1.0; + in_offset += fast_blksize; + low_chunk= high_chunk; + if (i!=(new_extent-1)) /* very last row is on boundary */ + high_chunk= mri_get_chunk(Input, this_chunk, fast_blksize, + in_offset + fast_blksize, type); + } + type_interp( obuf, low_chunk, high_chunk, shift, fast_blksize, type ); + mri_set_chunk(Output, this_chunk, fast_blksize, out_offset, type, + obuf); + out_offset += fast_blksize; + shift += ratio; + } + } + in_framestart += fast_blksize*selected_extent; + } + free(obuf); + } + + static void interp_chunk(char* this_chunk) { + char key_buf[KEYBUF_SIZE]; + char* dimstr; + int selected_extent; + + if (verbose_flag) fprintf(stderr,"interpolating chunk <%s>\n",this_chunk); + safe_copy(key_buf, this_chunk); + safe_concat(key_buf, ".dimensions"); + if (mri_has(Input,key_buf)) { + dimstr= mri_get_string(Input,key_buf); + if (verbose_flag) fprintf(stderr,"dimstr %s\n",dimstr); + if (strchr(dimstr,*selected_dim)) { + safe_copy(key_buf, this_chunk); + safe_concat(key_buf, ".extent."); + safe_concat(key_buf, selected_dim); + if (mri_has(Input,key_buf)) + selected_extent= mri_get_int(Input,key_buf); + else Abort("%s: input missing tag %s!\n",progname,key_buf); + if (verbose_flag) + fprintf(stderr,"selected dim extent on input %d\n",selected_extent); + if (new_extent != selected_extent) { + int fast_blksize; + int slow_blksize; + + data_changed= 1; + mri_set_int(Output, key_buf, new_extent); + calc_sizes(this_chunk, dimstr, &fast_blksize, &slow_blksize); + transfer_data(this_chunk, fast_blksize, slow_blksize, + selected_extent, new_extent); + } + } + else { + /* Chunk copied correctly in initial dataset copy */ + } + } + } + + main( argc, argv ) + int argc; + char **argv; + { + + char infile[512], outfile[512]; + char* this_key; + char this_chunk[KEYBUF_SIZE]; + + progname= argv[0]; + + /* Print version number */ + Message( "# %s\n", rcsid ); + + /* Check to see if help was requested */ + if( ( argc > 1 ) && !strcmp( argv[1], "-help" ) ) + { + if( argc == 2 ) + Help( "selecttopic" ); + else + Help( argv[2] ); + } + + /*** Parse command line ***/ + + cl_scan( argc, argv ); + + /* Get filenames */ + if (!cl_get("d", "%option %s[t]",selected_dim)) { + fprintf(stderr,"%s: dimension to be interpolated not given.\n",argv[0]); + Help("usage"); + exit(-1); + } + if (strlen(selected_dim)>1) { + fprintf(stderr,"%s: Selected dim name must be 1 char long.\n",argv[0]); + Help("usage"); + exit(-1); + } + *selected_dim= tolower(*selected_dim); + if (!cl_get("e", "%option %d",&new_extent)) { + fprintf(stderr,"%s: new extent not given.\n",argv[0]); + Help("usage"); + exit(-1); + } + if (!cl_get("", "%s", infile)) { + fprintf(stderr,"%s: Input file name not given.\n",argv[0]); + Help( "usage" ); + exit(-1); + } + if (!cl_get("", "%s", outfile)) { + fprintf(stderr,"%s: Output file name not given.\n",argv[0]); + Help( "usage" ); + exit(-1); + } + if (cl_present("l")) { + if (!cl_present("c")) const_flag= 0; + else { + fprintf(stderr,"%s: -l and -c flags are mutually exclusive.\n",argv[0]); + Help( "usage" ); + exit(-1); + } + } + else { + if (cl_present("c")) const_flag= 1; + else const_flag= 0; + } + verbose_flag= cl_present("v"); + if (cl_cleanup_check()) { + int i; + fprintf(stderr,"%s: invalid argument in command line:\n ",argv[0]); + for (i=0; i=KEYBUF_SIZE) + Abort("%s: key too long!\n",argv[0]); + if (!strchr(this_key,'.')) { + strncpy(this_chunk, this_key, KEYBUF_SIZE); + this_chunk[KEYBUF_SIZE-1]= '\0'; + interp_chunk(this_chunk); + } + } + + /* Write and close data-sets */ + mri_close_dataset( Input ); + mri_close_dataset( Output ); + + Message( "# Interpolation complete.\n" ); + if (!data_changed) + Message("# Warning: input and output datasets identical!\n"); + + return 0; + } + *** /home/STUPID/fiasco/Fiasco4.1/src/mri_util/mri_interp_help.help Wed Jul 8 15:27:16 1998 --- src/mri_util/mri_interp_help.help Tue Jul 7 14:39:49 1998 *************** *** 0 **** --- 1,26 ---- + *Usage + + mri_interp takes a pgh MRI dataset of any type, and outputs + a dataset of the same type containing interpolated data. + The interpolated data spans the range of one of the dimensions + of the input data, but has a different extent than that of + the input dimension. The interpolation operation acts on all + chunks in the dataset. + + mri_interp -d dim -e extent [-l | -c] [-v] infile outfile + + -d dim (where dim is a single character) specifies the dimension + to be interpolated. Valid values are one character long; case + is ignored. + -e extent specifies the output extent of that dimension. + -l specifies linear interpolation + -c specifies constant interpolation based on the nearest input + point. -l and -c are mutually exclusive; -l is the default. + -v sets verbose output + infile specifies the input dataset + outfile specifies the output dataset + + Chunks not containing the selected dimension are copied verbatim. + All chunks containing the given dimension will be interpolated. + Note that this can give confusing results if the extents of the + dimension vary between chunks!