// file: $PDSP/class/fourier_transform/v3.0/ft_ditf_2.cc
//

// isip include files
//
#include "fourier_transform.h"
#include "fourier_transform_constants.h"

// method: ditf_init_cc
//
// arguments:
//   int_4 order_a: (input) new order
//
// return: a logical_1 value indicating status
//
// creates lookup tables for sine and cosine terms. note that space is
// allocated in this method only when the order changes. also all temporary
// space is allocated here.
//
logical_1 Fourier_transform::ditf_init_cc(int_4 order_a) {

  // if the order is the same as the previous call, we are done
  //
  if (ditf_last_order_d == order_a) {
    return ISIP_TRUE;
  }

  // assign the order
  //
  N_d = order_a;
  ditf_last_order_d = N_d;

  // declare local variables
  //
  int_4 i;
  float_8 phi = 0;
  float_8 wn = (float_8)(ISIP_TWOPI/N_d);
  
  // allocate space the lookup values
  //
  ditf_wr_d = new float_8[N_d];
  ditf_wi_d = new float_8[N_d];
  
  for (i = 0; i < N_d; ++i) {
    phi = wn*(i);
    ditf_wr_d[i]=cos(phi);
    ditf_wi_d[i]=sin(phi);
  } 
  
  // allocate memory for the temporary workspace used
  //
  ditf_temp_d = new float_8[N_d];
  ditf_trans_factor_indices_d = new int_4[N_d];
  ditf_indices_d = new int_4[N_d >> 1];  

  // exit gracefully
  //
  return ISIP_TRUE;
}
