toa.h
1 //-*-C++-*-
2 /***************************************************************************
3  *
4  * Copyright (C) 1999 by Willem van Straten
5  * Licensed under the Academic Free License version 2.1
6  *
7  ***************************************************************************/
8 
9 // psrchive/Util/tempo/toa.h
10 
11 #ifndef __TOA_H
12 #define __TOA_H
13 
14 #include <vector>
15 #include <string>
16 
17 #include "residual.h"
18 #include "MJD.h"
19 #include "Estimate.h"
20 
21 namespace Tempo {
22 
23  class toaInfo;
24 
25  // //////////////////////////////////////////////////////////////////////////
26  //
27  // toa - class that encapsulates TEMPO data format
28  //
29  // //////////////////////////////////////////////////////////////////////////
30 
32  class toa
33  {
34 
35  public:
36 
37  static const float UNSET;
38 
40  enum Format
41  {
42  Unspecified,
43  Comment,
44  Princeton,
45  Parkes,
46  ITOA,
47  Psrclock,
48  Command,
49  Tempo2
50  };
51 
52  enum State
53  {
54  Undefined = -2, // point will never be plotted or used
55  Deleted = -1, // point will not be plotted unless an undelete happens
56  Hidden = 0, // point is temporarily outside of viewing region
57  Normal = 1, // point is in viewing region and plotted
58  Selected = 2 // like Normal, but highlighted selection
59  };
60 
61  static bool verbose;
62 
63  protected:
64 
65  // Fundamental TOA LINE as described here:
66  // http://pulsar.princeton.edu/tempo/ref_man_sections/toa.txt
67 
68  double frequency; // Observing frequency (MHz)
69  MJD arrival; // TOA
70  float error; // TOA uncertainty in microseconds
71  float reduced_chisq; // The reduced chisq of the TOA estimator
72 
73  std::string telescope; // Observatory code
74  unsigned channel; // Corresponding channel
75  unsigned subint; // Corresponding subint
76  double phase_shift; // Phase shift
77 
78  // Parkes Format specific
79 
80  float phs; // Phase offset (fraction of P0, added to TOA)
81 
82  // Princeton and ITOA Format specfic
83 
84  float dmc; // DM correction (pc cm^-3)
85 
86  // ITOA Format specific
87 
88  char observatory[2]; // Observatory (two-letter code)
89 
90  // Psrclock / Rhythm extras
91 
92  std::string auxinfo; /* text passed to context specific data */
93 
94  // Information about the parent archive
95 
96  float ston;
97  float pa;
98  float bw;
99  float dur;
100  float dm;
101  Estimate<float> flux;
102 
103  bool phase_info;
104 
105  // one of the available formats on loading
106 
107  Format format;
108  State state;
109 
110  public:
111 
112  // residual for this toa as calculated by tempo
113  residual resid;
114 
115  // colour index for use with pgplot
116  int ci;
117 
118  // dot index for use with pgplot
119  int di;
120 
121  // Basic constructors and destructors
122  toa (Format fmt = Psrclock);
123  virtual ~toa () { destroy(); };
124 
125  // copy constructor
126  toa (const toa & in_toa);
127  toa& operator = (const toa & in_toa);
128 
129  // construct from an open file
130  toa (FILE* instream);
131 
132  // construct from a string
133  toa (char* indata);
134 
135  // methods for setting/getting things (may eventually check validity)
136  void set_format (Format fmt) { format = fmt; };
137  void set_StoN (float sn) { ston = sn; };
138  void set_pa (float p) { pa = p; };
139  void set_bw (float b) { bw = b; };
140  void set_dur (float d) { dur = d; };
141  void set_dm (float d) { dm = d; };
142  void set_state (State st) { state = st; };
143 
144  void set_frequency (double freq) { frequency = freq; };
145  void set_arrival (MJD arrived) { arrival = arrived; };
146  void set_error (float err) { error = err; };
147  void set_reduced_chisq (float x) { reduced_chisq = x; }
148  void set_flux (Estimate<float> x) { flux = x; }
149 
150  void set_telescope (const std::string& telcode);
151  void set_auxilliary_text (const std::string& text) { auxinfo = text; };
152  void set_channel (unsigned chan) { channel = chan; };
153  void set_subint (unsigned sub) { subint = sub; };
154  void set_phase_shift (double shift) { phase_shift = shift; };
155  void set_phase_info (bool info) { phase_info = info; };
156 
157  Format get_format () const { return format; };
158  float get_StoN () const { return ston; };
159  float get_pa () const { return pa; };
160  float get_bw () const { return bw; };
161  float get_dur () const { return dur; };
162  float get_dm () const { return dm; };
163  State get_state () const { return state; };
164 
165  double get_frequency () const { return frequency; };
166  MJD get_arrival () const { return arrival; };
167  float get_error () const { return error; };
168  float get_reduced_chisq () const { return reduced_chisq; }
169  Estimate<float> get_flux () const { return flux; }
170 
171  std::string get_telescope () const { return telescope; };
172  std::string get_auxilliary_text () const { return auxinfo; };
173  double get_phase_shift () const { return phase_shift; };
174  unsigned get_channel () const { return channel; };
175  unsigned get_subint () const { return subint; };
176 
177 
178  // loading and unloading to/from file and string
179  int load (FILE* instream);
180  int load (const char* instring);
181  int unload (FILE* outstream, Format fmt = Unspecified) const;
182  int unload (char* outstring, Format fmt = Unspecified) const;
183 
184  int parkes_parse (const char* instring);
185  int parkes_out (char* outstring) const;
186  int Parkes_load (const char* instring);
187  int Parkes_unload (FILE* outstream) const;
188  int Parkes_unload (char* outstring) const;
189 
190  int Princeton_load (const char* instring);
191  int Princeton_unload (FILE* outstream) const;
192  int Princeton_unload (char* outstring) const;
193 
194  int Psrclock_load (const char* instring);
195  int Psrclock_unload (FILE* outstream) const;
196  int Psrclock_unload (char* outstring) const;
197 
198  std::string Psrclock_unload () const;
199 
200  int Command_load (const char* instring);
201  int Command_unload (FILE* outstream) const;
202  int Command_unload (char* outstring) const;
203 
204  int Comment_unload (FILE* outstream) const;
205  int Comment_unload (char* outstring) const;
206 
207  // -----------
208 
209  int Tempo2_unload (FILE* outstream) const;
210  int Tempo2_unload (char* outstring) const;
211 
212  int Tempo_unload (FILE* outstream) const;
213  int Tempo_unload (char* outstring) const;
214 
215  // comparison operators
216  friend int operator < (const toa& t1, const toa& t2)
217  { return (t1.arrival < t2.arrival); };
218 
219  // operations on vectors of toas
220  static int load (const char* filename, std::vector<toa>* toas);
221  static int load (FILE* instream, std::vector<toa>* toas);
222 
223  static int unload (const char* filename, const std::vector<toa>& toas,
224  Format fmt = Unspecified);
225  static int unload (FILE* outstream, const std::vector<toa>& toas,
226  Format fmt = Unspecified);
227 
228  private:
229  // low-level stuff
230  void init();
231  void destroy();
232  bool valid();
233 
234  static void sizebuf (size_t length);
235  static char* buffer;
236  static size_t bufsz;
237  static char datestr [25];
238  };
239 
240  std::ostream& operator << (std::ostream&, toa::Format format);
241  std::istream& operator >> (std::istream&, toa::Format& format);
242 
243 }
244 
245 #endif
246 
247 
248 
Interface to Tempo.
Definition: fit.C:21
A convenient exception handling class.
Definition: Error.h:54
char code(const std::string &telescope_name)
Convert a telescope name to a single-character tempo code.
Definition: tempo++.C:167
const Observatory * observatory(const std::string &telescope_name)
Return the Observatory data given the telescope name.
Definition: Observatory.C:130
void shift(unsigned npts, float *arr, double shift)
Use the Fourier transform to cyclically shift the elements in array.
Definition: shift.C:16
Describes a pulse Time of Arrival (TOA)
Definition: toa.h:37
Format
TOA output format.
Definition: toa.h:45
const std::string get_message() const
Get the error message.
Definition: Error.C:133
Class for representing modified Julian dates with high precision.
Definition: MJD.h:27
std::string get_old_code() const
Get the "old-style" telescope ID code.
Definition: T2Observatory.C:58
Implements Predictor class for Tempo.
Definition: polyco.h:202
Pulsar::Phase phase(const MJD &t) const
Return the phase, given the epoch.
Definition: polyco.h:248
Stores a pointer to a CommandParser sub-class and one of its methods.
Definition: CommandParser.h:200

Generated using doxygen 1.8.17