11 #ifndef __Pulsar_NonlinearlySpaced_h
12 #define __Pulsar_NonlinearlySpaced_h
14 #include "Pulsar/Divided.h"
22 class Integrate<C>::NonlinearlySpaced :
public Integrate<C>::Divided
26 void initialize (Integrate*, C*);
29 unsigned get_nrange () {
return stop_indeces.size(); }
31 void get_range (
unsigned irange,
unsigned& start,
unsigned& stop);
34 virtual double get_value (
const C*,
unsigned ielement) = 0;
39 std::vector<unsigned> stop_indeces;
49 unsigned container_size = this->get_size( container );
52 unsigned output_elements = 0;
54 this->divide (container_size, output_elements, spacing);
56 DEBUG(
"NonlinearlySpaced::initialize container_size=" << container_size <<
" output_elements=" << output_elements);
58 if (output_elements == 0)
61 stop_indeces.resize (output_elements);
62 stop_indeces[output_elements-1] = container_size;
64 if (output_elements == 1)
67 double value_0 = get_value (container, 0);
68 double value_range = get_value (container, container_size - 1) - value_0;
69 double value_step = value_range / output_elements;
71 DEBUG(
"NonlinearlySpaced::initialize value_0=" << value_0 <<
" value_range=" << value_range);
73 unsigned ielement = 0;
75 for (
unsigned irange=0; irange+1 < output_elements; irange++)
77 double stop_value = value_0 + (irange+1) * value_step;
79 DEBUG(
"NonlinearlySpaced::initialize stop_value[" << irange <<
"]=" << stop_value);
84 while (ielement < container_size)
86 double value = get_value (container, ielement);
87 double diff = std::fabs( value - stop_value );
89 DEBUG(
"NonlinearlySpaced::initialize value[" << ielement <<
"]=" << value <<
" diff=" << diff);
93 else if (diff > min_diff)
102 DEBUG(
"NonlinearlySpaced::initialize stop_index[" << irange <<
"]=" << ielement);
104 stop_indeces[irange] = ielement;
113 if (irange >= stop_indeces.size())
114 throw Error (InvalidParam,
115 "Pulsar::Integrate::Divide::NonlinearlySpaced::get_range",
116 "irange=%u >= output_elements=%u", irange, stop_indeces.size());
119 start = stop_indeces[irange-1];
123 stop = stop_indeces[irange];