Changeset 16094 for trunk/Ohana/src/opihi/cmd.data/fft1d.c
- Timestamp:
- Jan 15, 2008, 6:04:08 PM (19 years ago)
- File:
-
- 1 edited
-
trunk/Ohana/src/opihi/cmd.data/fft1d.c (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Ohana/src/opihi/cmd.data/fft1d.c
r7917 r16094 3 3 int fft1d (int argc, char **argv) { 4 4 5 int i, Npix, ZeroImaginary; 6 float *t1, *t2, *temp; 5 int Npix, Nbit, ZeroImaginary; 7 6 Vector *Ire, *Iim, *Ore, *Oim; 8 7 … … 19 18 } 20 19 if ((Ire = SelectVector (argv[1], OLDVECTOR, TRUE)) == NULL) return (FALSE); 21 if ((Ore = SelectVector (argv[4], ANYVECTOR, TRUE)) == NULL) return (FALSE); 22 if ((Oim = SelectVector (argv[5], ANYVECTOR, TRUE)) == NULL) return (FALSE); 23 20 21 // check the input data (match lengths? binary length?) 24 22 Npix = Ire[0].Nelements; 25 23 if (!ZeroImaginary && (Npix != Iim[0].Nelements)) { … … 27 25 return (FALSE); 28 26 } 29 30 if (!IsBinary (Npix)) { 27 if (!IsBinary (Npix, &Nbit)) { 31 28 gprint (GP_ERR, "Npix is not a binary number!\n"); 32 29 return (FALSE); 33 30 } 34 35 ALLOCATE (temp, float, 2*Npix);36 if (ZeroImaginary) {37 t1 = Ire[0].elements;38 for (i = 0; i < Npix; i++, t1++) {39 temp[2*i ] = *t1;40 temp[2*i+1] = 0;41 }42 } else {43 t1 = Ire[0].elements;44 t2 = Iim[0].elements;45 for (i = 0; i < Npix; i++, t1++, t2++) {46 temp[2*i ] = *t1;47 temp[2*i+1] = *t2;48 }49 }50 51 fft (temp, Npix, 1);52 31 32 // select or create the output vectors 33 if ((Ore = SelectVector (argv[4], ANYVECTOR, TRUE)) == NULL) return (FALSE); 34 if ((Oim = SelectVector (argv[5], ANYVECTOR, TRUE)) == NULL) return (FALSE); 35 36 // allocate sufficient output space 53 37 Ore[0].Nelements = Npix; 54 38 Oim[0].Nelements = Npix; … … 56 40 REALLOCATE (Oim[0].elements, float, Npix); 57 41 58 t1 = Ore[0].elements; 59 t2 = Oim[0].elements; 60 for (i = 0; i < Npix; i++, t1++, t2++) { 61 *t1 = temp[2*i ] / Npix; 62 *t2 = temp[2*i+1] / Npix; 42 // copy data to output vectors (fft is done in place) 43 memcpy (Ore[0].elements, Ire[0].elements, Npix*sizeof(float)); 44 45 // copy imaginary vector or create a zero vector 46 if (ZeroImaginary) { 47 memset (Oim[0].elements, 0, Npix*sizeof(float)); 48 } else { 49 memcpy (Oim[0].elements, Iim[0].elements, Npix*sizeof(float)); 63 50 } 64 65 f ree (temp);51 52 fft (Ore[0].elements, Oim[0].elements, Npix, Nbit); 66 53 67 54 return (TRUE); 68 55 } 69 70
Note:
See TracChangeset
for help on using the changeset viewer.
