1 #include "mrilib.h"
2
main(int argc,char * argv[])3 int main( int argc , char *argv[] )
4 {
5 MRI_IMAGE *inim , *outim ;
6 float *inar , *outar ;
7 int nxin , nxout , ny ;
8 int iarg=1 , jj , nup , do_one=0 ;
9
10 if( argc < 3 || strcmp(argv[1],"-help") == 0 ){
11 printf("Program 1dUpsample:\n"
12 "Upsamples a 1D time series (along the column direction)\n"
13 "to a finer time grid.\n"
14 "Usage: 1dUpsample [options] n fred.1D > ethel.1D\n"
15 "\n"
16 "Where 'n' is the upsample factor (integer from 2..32)\n"
17 "\n"
18 "NOTES:\n"
19 "------\n"
20 "* Interpolation is done with 7th order polynomials.\n"
21 " (Why 7? It's a nice number, and the code already existed.)\n"
22 "* The only option is '-1' or '-one', to use 1st order\n"
23 " polynomials instead (i.e., linear interpolation).\n"
24 "* Output is written to stdout.\n"
25 "* If you want to interpolate along the row direction,\n"
26 " transpose before input, then transpose the output.\n"
27 "* Example:\n"
28 " 1dUpsample 5 '1D: 4 5 4 3 4' | 1dplot -stdin -dx 0.2 \n"
29 "* If the input has M time points, the output will\n"
30 " have n*M time points. The last n-1 of them\n"
31 " will be past the end of the original time series.\n"
32 "* This program is a quick hack for Gang Chen.\n"
33 " Where are my Twizzlers?\n"
34 "\n") ;
35 exit(0) ;
36 }
37
38 if( argv[iarg][0] == '-' ){ do_one = 1 ; iarg++ ; } /* very cheap */
39
40 nup = (int)strtod(argv[iarg++],NULL) ;
41 if( nup < 2 || nup > 32 )
42 ERROR_exit("1dUpsample 'n' parameter = %d is out of range 2..32",nup) ;
43
44 inim = mri_read_1D(argv[iarg]) ;
45 if( inim == NULL )
46 ERROR_exit("1dUpsample can't read file '%s'",argv[iarg]) ;
47 if( inim->nx < 2 ) {
48 if( inim->ny > 1 )
49 ERROR_exit("1dUpsample file '%s' has bad dims %dx%d,"
50 " consider tranpose", argv[iarg], inim->nx, inim->ny) ;
51 else
52 ERROR_exit("1dUpsample file '%s' has small dims %dx%d",
53 argv[iarg], inim->nx, inim->ny) ;
54 }
55
56 nxin = inim->nx ; ny = inim->ny ; inar = MRI_FLOAT_PTR(inim) ;
57 nxout = nxin * nup ;
58 outim = mri_new( nxout , ny , MRI_float ) ;
59 outar = MRI_FLOAT_PTR(outim) ;
60
61 for( jj=0 ; jj < ny ; jj++ ){
62 if( do_one )
63 upsample_1( nup , nxin , inar + nxin*jj , outar + nxout*jj ) ;
64 else
65 upsample_7( nup , nxin , inar + nxin*jj , outar + nxout*jj ) ;
66 }
67
68 mri_write_1D( "-" , outim ) ;
69 exit(0) ;
70 }
71