Shape.h
1 //-*-C++-*-
2 /***************************************************************************
3  *
4  * Copyright (C) 2002 by Willem van Straten
5  * Licensed under the Academic Free License version 2.1
6  *
7  ***************************************************************************/
8 
9 // dspsr/Signal/General/dsp/Shape.h
10 
11 #ifndef __Shape_h
12 #define __Shape_h
13 
14 #include "OwnStream.h"
15 
16 #ifdef ACTIVATE_MPI
17 #include <mpi.h>
18 #endif
19 
20 namespace dsp {
21 
23  class Shape : public OwnStream {
24 
25  public:
26  static bool verbose;
27 
29  Shape ();
31  virtual ~Shape ();
33  Shape (const Shape&);
35  const Shape& operator = (const Shape&);
36 
38  virtual void resize (unsigned npol, unsigned nchan,
39  unsigned ndat, unsigned ndim);
40 
42  unsigned get_npol() const { return npol; }
43 
45  unsigned get_nchan() const { return nchan; }
46 
48  unsigned get_ndat() const { return ndat; }
49 
51  unsigned get_ndim() const { return ndim; }
52 
54  virtual bool matches (const Shape* shape);
55 
57  void scrunch_to (unsigned ndat);
58 
60  void rotate (int npt);
61 
63  void zero ();
64 
66  void zero_dimensions ();
67 
69  void borrow (const Shape&, unsigned ichan=0);
70 
72  const Shape& operator /= (float factor);
73 
75  const Shape& operator *= (float factor);
76 
78  const Shape& operator += (const Shape&);
79 
81  float* get_datptr (unsigned ichan, unsigned ipol) {
82  return buffer + offset * ipol + ndat*ndim * ichan;
83  }
84 
86  const float* get_datptr (unsigned ichan, unsigned ipol) const {
87  return buffer + offset * ipol + ndat*ndim * ichan;
88  }
89 
90  protected:
91 
93  float* buffer;
94 
96  unsigned bufsize;
97 
99  unsigned offset;
100 
102  unsigned npol;
103 
105  unsigned nchan;
106 
108  unsigned ndat;
109 
111  unsigned ndim;
112 
114  bool borrowed;
115 
116  void init ();
117  void size_dataspace ();
118  void destroy ();
119 
120 #if PGPLOT
121  void plot (float centre, float width, const char* label,
122  bool swap=false, int dimension=0, bool one_poln=false);
123 #endif
124 
125  };
126 
127 }
128 
129 // these are declared outside of the namespace, to simplify their
130 // use in the stdmpi templates
131 #ifdef ACTIVATE_MPI
132 int mpiPack_size (const dsp::Shape&,
133  MPI_Comm comm, int* size);
134 int mpiPack (const dsp::Shape&, void* outbuf,
135  int outcount, int* position, MPI_Comm comm);
136 int mpiUnpack (void* inbuf, int insize, int* position,
137  dsp::Shape*, MPI_Comm comm);
138 #endif
139 
140 #endif // #ifndef __Shape_h
virtual ~Shape()
Destructor.
Definition: Shape.C:39
Contains all Baseband Data Reduction Library classes.
Definition: ASCIIObservation.h:17
unsigned ndim
Dimension of each datum.
Definition: Shape.h:121
const Shape & operator/=(float factor)
Divide each point by factor.
Definition: Shape.C:72
float * get_datptr(unsigned ichan, unsigned ipol)
Provide access to the data for the specified polarization.
Definition: Shape.h:91
void rotate(int npt)
Rotate data so that Shape[i] = Shape[i+npt].
Definition: Shape.C:222
unsigned bufsize
Size of the data buffer.
Definition: Shape.h:106
unsigned offset
Offset between datum from each polarization.
Definition: Shape.h:109
Shape()
Default constructor.
Definition: Shape.C:34
unsigned npol
Number of polarizations.
Definition: Shape.h:112
unsigned nchan
Number of frequency divisions (channels)
Definition: Shape.h:115
unsigned get_npol() const
Get the number of polarizations.
Definition: Shape.h:52
const Shape & operator+=(const Shape &)
Add another Shape to this one.
Definition: Shape.C:89
void scrunch_to(unsigned ndat)
Scrunch each dimension to a new ndat.
Definition: Shape.C:178
const Shape & operator*=(float factor)
Multiply each point by factor.
Definition: Shape.C:77
void zero()
Set all values to zero.
Definition: Shape.C:273
unsigned get_ndat() const
Get the number of datum in each of the nchan*npol divisions.
Definition: Shape.h:58
virtual bool matches(const Shape *shape)
Returns true if the npol, nchan, and ndat dimensions match.
Definition: Shape.C:150
void borrow(const Shape &, unsigned ichan=0)
Borrow the data from the specified channel of another Shape.
Definition: Shape.C:158
unsigned get_nchan() const
Get the number of frequency channels.
Definition: Shape.h:55
virtual void resize(unsigned npol, unsigned nchan, unsigned ndat, unsigned ndim)
Set the dimensions of the data.
Definition: Shape.C:117
Base class of objects that Shape data in the time or frequency domain.
Definition: Shape.h:28
unsigned get_ndim() const
Get the dimension of each datum (e.g. 2=complex 8=Jones)
Definition: Shape.h:61
const Shape & operator=(const Shape &)
Assignment operator.
Definition: Shape.C:51
unsigned ndat
Number of datum in each of the npol*nchan divisions.
Definition: Shape.h:118
void zero_dimensions()
Set all dimnensions to zero; allocated memory unaffected.
Definition: Shape.C:268
bool borrowed
Flag that data are borrowed from another Shape.
Definition: Shape.h:124
float * buffer
Data points.
Definition: Shape.h:103

Generated using doxygen 1.8.17