IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jan 15, 2008, 6:04:08 PM (19 years ago)
Author:
eugene
Message:

convert to Jones (creative commons) version of fft

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Ohana/src/opihi/cmd.data/fft1d.c

    r7917 r16094  
    33int fft1d (int argc, char **argv) {
    44 
    5   int i, Npix, ZeroImaginary;
    6   float *t1, *t2, *temp;
     5  int Npix, Nbit, ZeroImaginary;
    76  Vector *Ire, *Iim, *Ore, *Oim;
    87
     
    1918  }   
    2019  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?)
    2422  Npix = Ire[0].Nelements;
    2523  if (!ZeroImaginary && (Npix != Iim[0].Nelements)) {
     
    2725    return (FALSE);
    2826  }
    29 
    30   if (!IsBinary (Npix)) {
     27  if (!IsBinary (Npix, &Nbit)) {
    3128    gprint (GP_ERR, "Npix is not a binary number!\n");
    3229    return (FALSE);
    3330  }
    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);
    5231
     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
    5337  Ore[0].Nelements = Npix;
    5438  Oim[0].Nelements = Npix;
     
    5640  REALLOCATE (Oim[0].elements, float, Npix);
    5741 
    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));
    6350  }   
    64  
    65   free (temp);
     51
     52  fft (Ore[0].elements, Oim[0].elements, Npix, Nbit);
    6653 
    6754  return (TRUE);
    6855}
    69 
    70  
Note: See TracChangeset for help on using the changeset viewer.