Divided.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/Divided.h
10 
11 #ifndef __Pulsar_Divided_h
12 #define __Pulsar_Divided_h
13 
14 #include "Pulsar/Integrate.h"
15 
16 namespace Pulsar {
17 
18  template<class C>
19  class Integrate<C>::Divided : public Integrate<C>::RangePolicy {
20 
21  public:
22 
24  Divided ();
25 
27  void set_ndivide (unsigned ndivide);
28 
30  unsigned get_ndivide () const;
31 
33  void set_nintegrate (unsigned nintegrate);
34 
36  unsigned get_nintegrate () const;
37 
39  void divide (unsigned ndivide,
40  unsigned& nrange, unsigned& nintegrate) const;
41 
42  protected:
43 
45  virtual unsigned get_size (const C*) = 0;
46 
48  unsigned ndivide;
49 
51  unsigned nintegrate;
52 
53  };
54 
55 }
56 
58 template<class C>
60 {
61  ndivide = 0;
62  nintegrate = 0;
63 }
64 
66 template<class C>
67 void Pulsar::Integrate<C>::Divided::set_ndivide (unsigned _ndivide)
68 {
69  ndivide = _ndivide;
70  nintegrate = 0;
71 }
72 
74 template<class C>
76 {
77  return ndivide;
78 }
79 
81 template<class C>
82 void Pulsar::Integrate<C>::Divided::set_nintegrate (unsigned _nintegrate)
83 {
84  nintegrate = _nintegrate;
85  ndivide = 0;
86 }
87 
89 template<class C>
91 {
92  return nintegrate;
93 }
94 
95 template<class C>
96 void Pulsar::Integrate<C>::Divided::divide (unsigned input_ndivide,
97  unsigned& output_ndivide,
98  unsigned& output_nintegrate) const
99 {
100  output_ndivide = 1;
101  output_nintegrate = input_ndivide;
102 
103  if (ndivide)
104  {
105 
106 #if _DEBUG
107  std::cerr << "Pulsar::Integrate::Divided::divide ndivide=" << ndivide
108  << std::endl;
109 #endif
110 
111  // the number of output elements was specified
112  output_ndivide = ndivide;
113  // calculate the output_nintegrate
114  output_nintegrate = input_ndivide / output_ndivide;
115  if (input_ndivide % output_ndivide)
116  output_nintegrate ++;
117 
118  }
119  else if (nintegrate)
120  {
121 
122 #if _DEBUG
123  std::cerr << "Pulsar::Integrate::Divided::divide nintegrate="
124  << nintegrate << std::endl;
125 #endif
126 
127  // the number of elements to integrate was specified
128  output_nintegrate = nintegrate;
129  // calculate the number of output elements
130  output_ndivide = input_ndivide / output_nintegrate;
131  if (input_ndivide % output_nintegrate)
132  output_ndivide ++;
133 
134  }
135 
136 #if _DEBUG
137  std::cerr << "Pulsar::Integrate::Divided::divide into " << output_ndivide
138  << " ranges with " << output_nintegrate << " elements per range"
139  << std::endl;
140 #endif
141 }
142 
143 
144 #endif
Profile integration algorithms.
Definition: Integrate.h:41
Defines the PSRCHIVE library.
Definition: CalSource.h:17

Generated using doxygen 1.8.17