// file: filter/filt_apply_0.cc
//

// isip include files
//
#include "filter.h"
#include "filter_constants.h"

// method: apply_cc
//
// arguments:
//  float_8 data: (input/output) data to operate upon in-place
//  int_4 num_samp: (input) number of samples of input data
//  int_4 num_chan: (input) number of samples of input data
//
// return: a logical_1 indicating status
//
logical_1 Filter::apply_cc(float_8* data_a, int_4 num_samp_a,
			   int_4 num_chan_a) {

  if (width_d < 2) {
    error_handler_cc((char_1*)"apply_cc",
		     (char_1*)"filter function not properly set");
    return ISIP_FALSE;
  }
  
  if ((data_a == (float_8*)NULL) || (num_samp_a < 1)) {
    error_handler_cc((char_1*)"apply_cc",
		     (char_1*)"invalid signal data");
    return ISIP_FALSE;
  }

  if ((num_samp_a > width_d) && (debug_level_d > ISIP_DEBUG_NONE)) {
    fprintf(stdout,"Filter::apply_cc: Warning: data larger than filter\n");
  }
  
  for (int_4 chan = 0; chan < num_chan_a; chan++) {
    for (int_4 i = 0; i < num_samp_a; i++) {
      if (i < width_d) {
	data_a[i*num_chan_a + chan] *= data_d[i];
      }
      else {
	data_a[i*num_chan_a + chan] = (float_8)0;
      }
    }
  }
  
  // exit gracefully
  //
  return ISIP_TRUE;
}
