EvenlyWeighted.h
1 //-*-C++-*-
2 /***************************************************************************
3  *
4  * Copyright (C) 2007 by Willem van Straten
5  * Licensed under the Academic Free License version 2.1
6  *
7  ***************************************************************************/
8 
9 // psrchive/More/General/Pulsar/EvenlyWeighted.h
10 
11 #ifndef __Pulsar_EvenlyWeighted_h
12 #define __Pulsar_EvenlyWeighted_h
13 
14 #include "Pulsar/Divided.h"
15 #include "debug.h"
16 
17 namespace Pulsar {
18 
19  template<class C>
20  class Integrate<C>::EvenlyWeighted : public Integrate<C>::Divided
21  {
22 
24  void initialize (Integrate*, C*);
25 
27  unsigned get_nrange () { return stop_indeces.size(); }
28 
29  void get_range (unsigned irange, unsigned& start, unsigned& stop);
30 
32  virtual double get_weight (const C*, unsigned ielement) = 0;
33 
34  protected:
35 
37  std::vector<unsigned> stop_indeces;
38 
39  };
40 
41 }
42 
43 
44 template<class C>
46  C* container)
47 {
48  unsigned container_size = this->get_size( container );
49 
50  unsigned good_elements = 0;
51 
52  // count the number of good channels
53  for (unsigned ielement=0; ielement < container_size; ielement++)
54  if (get_weight(container,ielement) != 0)
55  good_elements ++;
56 
57  DEBUG("EvenlyWeighted::initialize good_elements=" << good_elements);
58 
59  // divide them up
60  unsigned output_elements = 0;
61  unsigned spacing = 0;
62  this->divide (good_elements, output_elements, spacing);
63 
64  stop_indeces.resize (output_elements);
65 
66  // and count off 'spacing' good channels per range
67  unsigned ielement = 0;
68  for (unsigned irange=0; irange < output_elements; irange++)
69  {
70  for (good_elements=0;
71  good_elements < spacing && ielement < container_size; ielement++)
72  if (get_weight(container,ielement) != 0)
73  good_elements ++;
74 
75  DEBUG(" stop[" << irange << "] = " << ielement);
76 
77  stop_indeces[irange] = ielement;
78 
79  }
80 
81 }
82 
83 template<class C>
85  unsigned& start,
86  unsigned& stop)
87 {
88  if (irange >= stop_indeces.size())
89  throw Error (InvalidParam,
90  "Pulsar::Integrate::Divide::EvenlyWeighted::get_range",
91  "irange=%u >= output_elements=%u", irange, stop_indeces.size());
92 
93  if (irange > 0)
94  start = stop_indeces[irange-1];
95  else
96  start = 0;
97 
98  stop = stop_indeces[irange];
99 }
100 
101 
102 
103 #endif
Profile integration algorithms.
Definition: Integrate.h:41
Defines the PSRCHIVE library.
Definition: CalSource.h:17

Generated using doxygen 1.8.17