Interpreter.h
1 /***************************************************************************
2  *
3  * Copyright (C) 2006 by Willem van Straten
4  * Licensed under the Academic Free License version 2.1
5  *
6  ***************************************************************************/
7 
8 #ifndef __Pulsar_Interpreter_h
9 #define __Pulsar_Interpreter_h
10 
11 #include "CommandParser.h"
12 #include "TextInterface.h"
13 #include "Reference.h"
14 #include "tostring.h"
15 
16 #include <map>
17 #include <stack>
18 
19 namespace Pulsar {
20 
21  class Archive;
22  class Weight;
23  class ScatteredPowerCorrection;
24  class ImageCorrection;
25 
27 
52  class Interpreter : public CommandParser {
53 
54  public:
55 
56  enum Status { Good, Warn, Fail, TestFailed, CommandFailed, Undefined };
57 
59  Interpreter ();
60 
62  Interpreter (int &argc, char** &argv);
63 
65  ~Interpreter ();
66 
68  bool evaluate (const std::string& expression);
69 
71  void set (Archive* data);
72 
74  Archive* get ();
75 
77  bool has () const;
78 
80  void setmap (const std::string& name, Archive* data);
81 
83  Archive* getmap (const std::string& name, bool throw_exception = true);
84 
86  Status get_status () const { return status; }
87 
89  void set_reply (bool f) { reply = f; }
90 
92  std::string get_report (const std::string& args);
93 
95  std::string load (const std::string& args);
96 
98  std::string unload (const std::string& args);
99 
101  std::string push (const std::string& args);
102 
104  std::string pop (const std::string& args);
105 
107  std::string set (const std::string& args);
108 
110  std::string get (const std::string& args);
111 
113  std::string remove (const std::string& args);
114 
116  std::string clone (const std::string& args);
117 
119  std::string convert (const std::string& args);
120 
122  std::string extract (const std::string& args);
123 
125  std::string echo (const std::string& args);
126 
128  std::string edit (const std::string& args);
129 
131 
132  std::string system (const std::string& args);
133 
135 
136  std::string test (const std::string& args);
137 
139  std::string config (const std::string& args);
140 
142  std::string append (const std::string& args);
143 
145  std::string freq_append (const std::string& args);
146 
148  std::string shuffle (const std::string& args);
149 
151  std::string fscrunch (const std::string& args);
152 
154  std::string tscrunch (const std::string& args);
155 
157  std::string pscrunch (const std::string& args);
158 
160  std::string state (const std::string& args);
161 
163  std::string invint (const std::string& args);
164 
166  std::string bscrunch (const std::string& args);
167 
169  std::string fold (const std::string& args);
170 
172  std::string centre (const std::string& args);
173 
175  std::string dedisperse (const std::string& args);
176 
178  std::string defaraday (const std::string& args);
179 
181  std::string weight (const std::string& args);
182 
184  std::string scale (const std::string& args);
185 
187  std::string offset (const std::string& args);
188 
190  std::string rotate (const std::string& args);
191 
193  std::string dynspec (const std::string& args);
194 
196  std::string correct_instrument (const std::string& args);
197 
199  std::string scattered_power_correct (const std::string& args);
200 
202  std::string image_correct (const std::string& args);
203 
205  std::string screen_dump (const std::string& args);
206 
208  std::string toggle_clobber (const std::string& args);
209 
211  std::string toggle_evaluate (const std::string& args);
212 
214  class Extension;
215 
217  void import (Extension*);
218 
220  void import (Extension*,
221  const std::string& command,
222  const std::string& help);
223 
226 
227  protected:
228 
230  std::stack< Reference::To<Archive> > theStack;
231 
233  std::map< std::string, Reference::To<Archive> > theMap;
234 
237 
239  bool inplace;
240 
242  bool clobber;
243 
244  // commands that request expansion will have arguments evaluated
245  bool evaluation_enabled;
246 
248  bool stopwatch;
249 
251  bool reply;
252 
254  Status status;
255 
257  std::string unload_extension;
258 
260  std::string unload_path;
261 
263  std::vector<std::string> setup (const std::string& args, bool expand=true);
264 
266  std::string response (Status status, const std::string& text = "");
267 
269  Status get_status (const Error& error);
270 
272  std::string response (const Error& error);
273 
275  template<typename T> T setup (const std::string& args);
276 
278  template<typename T> T setup (const std::string& args, T default_value);
279 
282 
283  private:
284 
285  void init ();
286 
288  std::string evaluate_expression;
289 
291  Reference::To<TextInterface::Parser> current_interface;
292 
295 
297  Reference::To<ImageCorrection> img_algorithm;
298 
299  };
300 
301 }
302 
303 template<typename T>
304 T Pulsar::Interpreter::setup (const std::string& args)
305 {
306  std::vector<std::string> arguments = setup (args);
307  if (arguments.size() != 1)
308  throw Error (InvalidParam, "Pulsar::Interpreter::setup",
309  "invalid number of parameters");
310 
311  return fromstring<T> (arguments[0]);
312 }
313 
314 template<typename T>
315 T Pulsar::Interpreter::setup (const std::string& args, T default_value)
316 {
317  std::vector<std::string> arguments = setup (args);
318  if (arguments.size() > 1)
319  throw Error (InvalidParam, "Pulsar::Interpreter::setup",
320  "invalid number of parameters");
321  if (arguments.size())
322  return fromstring<T> (arguments[0]);
323  else
324  return default_value;
325 }
326 
327 // standard shell constructor defined in More/Polarimetry/standard_shell.C
328 Pulsar::Interpreter* standard_shell ();
329 
330 #endif
void bscrunch(Container *, const ScrunchFactor &)
Integrate phase bins.
Definition: ScrunchFactor.h:116
std::string append(const std::string &args)
append one archive to another
Definition: Interpreter.C:988
void set_flux_method(Flux *flux)
Set the flux computation method.
Definition: DynamicSpectrum.C:62
std::string remove(const std::string &args)
remove the named archive from the map
Definition: Interpreter.C:727
void set_throw(bool flag)
bool inplace
operate on data "in place", otherwise make a copy
Definition: Interpreter.h:244
Interpreter()
default constructor
Definition: Interpreter.C:318
void run(const std::string &)
Archive * get()
get the current Archive
Definition: Interpreter.C:463
std::string test(const std::string &args)
test a boolean expression
Definition: Interpreter.C:944
std::string weight(const std::string &args)
weight each profile according to the named scheme
Definition: Interpreter.C:1363
void convert_state(Signal::State state)
Convert data to the specified state.
Definition: Archive_convert_state.C:14
std::string config(const std::string &args)
edit the configuration parameters
Definition: Interpreter.C:961
std::string load(const std::string &args)
load an archive from disk to top of stack and optionally the map
Definition: Interpreter.C:507
void append(Archive *into, const Archive *from)
Copy the data in 'from' to 'into'.
Definition: Append.C:85
void tscrunch(Container *, const ScrunchFactor &)
Integrate sub-integrations.
Definition: ScrunchFactor.h:109
std::string invint(const std::string &args)
form the Stokes invariant interval profile
Definition: Interpreter.C:1143
Sets the weight of each Integration according to its duration.
Definition: DurationWeight.h:24
std::string fold(const std::string &args)
fold an archive in the stack
Definition: Interpreter.C:1124
void init(Archive *into)
Initialize an archive for appending.
Definition: FrequencyAppend.C:172
std::string push(const std::string &args)
push a clone of the current stack top onto the stack
Definition: Interpreter.C:639
void set_Archive(const Archive *_arch)
Set the Archive to use.
Definition: DynamicSpectrum.C:43
TextInterface::Parser * get_interface()
get the interface to the current archive
Definition: Interpreter.C:835
std::string unload_extension
the extension with with Archives will be unloaded
Definition: Interpreter.h:262
std::string unload_path
the path to which Archives will be unloaded
Definition: Interpreter.h:265
std::string pop(const std::string &args)
pop the top of the stack
Definition: Interpreter.C:668
bool allow_infinite_frequency
allow dedispersion or Faraday rotation correction to infinite frequency
Definition: Interpreter.h:230
Algorithms that combine Integration data.
Definition: FrequencyAppend.h:28
Provides access to transposed Archive data.
Definition: Transposer.h:32
bool clobber
allow the user to overwrite existing named archive
Definition: Interpreter.h:247
std::string bscrunch(const std::string &args)
bin scrunch an archive in the stack
Definition: Interpreter.C:1107
static void agent_report()
Report on the status of the plugins.
Definition: Archive.C:120
ErrorCode get_code() const
The primary interface to pulsar observational data.
Definition: Archive.h:45
Corrects dispersive delays.
Definition: Dispersion.h:33
void set_reference_frequency(double MHz)
Set the reference frequency in MHz.
Definition: ColdPlasma.h:203
void set_dim(unsigned idim, Signal::Dimension dim)
Set the specified dimension.
Definition: Transposer.C:34
std::string shuffle(const std::string &args)
randomly rearrange sub-integrations
Definition: Interpreter.C:1034
void import(Extension *)
Import the Extension.
Definition: Interpreter.C:335
std::string echo(const std::string &args)
evaluate any expressions and print result
Definition: Interpreter.C:846
Manages a combined scrunch factor or target dimension.
Definition: ScrunchFactor.h:25
Reference::To< Weight > weight_policy
The current weighting scheme.
Definition: Interpreter.h:286
void set_reference_wavelength(double metres)
Set the reference wavelength in metres.
Definition: ColdPlasma.h:215
void fscrunch(Container *, const ScrunchFactor &)
Integrate frequency channels.
Definition: ScrunchFactor.h:102
Estimates phase shift using the flux "centre of mass".
Definition: FluxCentroid.h:25
std::string toggle_clobber(const std::string &args)
toggle the clober flag
Definition: Interpreter.C:1545
virtual Signal::State get_state() const =0
Get the state of the profile data.
std::string centre(const std::string &args)
centre an archive in the stack
Definition: Interpreter.C:1189
Corrects the power scattered due to 2-bit quantization.
Definition: ScatteredPowerCorrection.h:33
void execute(Archive *)
Apply the current correction to all sub-integrations in an archive.
Definition: FaradayRotation.C:66
std::string edit(const std::string &args)
edit the current archive
Definition: Interpreter.C:866
void set_reply(bool f)
set to false to disable the 'ok' reply
Definition: Interpreter.h:94
Estimates phase shift using the weighted mean sine and cosine of phase.
Definition: MeanPhase.h:25
std::string unload(const std::string &args)
write an archive from either the top of the stack or the map
Definition: Interpreter.C:526
Sets the weight of each Profile according to its S/N squared.
Definition: StandardSNRWeight.h:26
std::string defaraday(const std::string &args)
correct for faraday rotation
Definition: Interpreter.C:1262
std::string scale(const std::string &args)
scale each profile by the specified value
Definition: Interpreter.C:1411
std::string clone(const std::string &args)
clone the current archive
Definition: Interpreter.C:746
Computes dynamic spectrum (flux vs time/freq) of an Archive.
Definition: DynamicSpectrum.h:27
Status status
status flag (pass/fail)
Definition: Interpreter.h:259
std::string system(const std::string &args)
execute a shell command
Definition: Interpreter.C:914
void get_amps(std::vector< float > &amps) const
Returns amplitude data; ordered according to the specified dimension.
Definition: Transposer.C:78
Sets the weight of each Profile according to its S/N squared.
Definition: SNRWeight.h:24
std::string correct_instrument(const std::string &args)
correct for parallactic angle effects
void set_measure(double measure)
Set the correction measure.
Definition: ColdPlasma.h:227
std::string pscrunch(const std::string &args)
poln scrunch an archive in the stack
Definition: Interpreter.C:1093
void compute()
Compute dynamic spectrum.
Definition: DynamicSpectrum.C:101
std::string freq_append(const std::string &args)
append one archive to another in frequency direction
Definition: Interpreter.C:1003
std::vector< std::string > setup(const std::string &args, bool expand=true)
All methods should call this method to parse the arguments.
Definition: Interpreter.C:370
std::map< std::string, Reference::To< Archive > > theMap
the Archive map
Definition: Interpreter.h:238
std::string dynspec(const std::string &args)
compute dynamic spectrum of archive on stack
Definition: Interpreter.C:1466
void execute(Archive *)
Apply the current correction to all sub-integrations in an archive.
Definition: Dispersion.C:82
Corrects band-reversed signal due to poor image rejection.
Definition: ImageCorrection.h:29
std::string toggle_evaluate(const std::string &args)
toggle the evaluate flag
Definition: Interpreter.C:1563
std::string get_report(const std::string &args)
get plugin information
Definition: Interpreter.C:360
std::string tscrunch(const std::string &args)
time scrunch an archive in the stack
Definition: Interpreter.C:1073
std::string convert(const std::string &args)
convert the current archive or a named archive to a different class
Definition: Interpreter.C:766
std::string response(Status status, const std::string &text="")
All methods should return via the response methods.
Definition: Interpreter.C:401
std::string extract(const std::string &args)
extract part of the current archive
Definition: Interpreter.C:793
bool evaluate(const std::string &expression)
Evaluate a boolean expression.
Definition: Interpreter.C:894
std::string offset(const std::string &args)
offset each profile by the specified value
Definition: Interpreter.C:1432
bool stopwatch
time various operations
Definition: Interpreter.h:253
Archive * getmap(const std::string &name, bool throw_exception=true)
get the named Archive
Definition: Interpreter.C:492
Algorithms that estimate the phase shift from a single pulse profile.
Definition: ProfileShiftEstimator.h:25
Status get_status() const
get the status after the last command
Definition: Interpreter.h:91
Computes average flux of a Profile by fitting to a standard.
Definition: StandardFlux.h:26
bool has() const
return true if there is a current Archive
Definition: Interpreter.C:475
std::string rotate(const std::string &args)
rotate each profile by the specified value
Definition: Interpreter.C:1456
bool reply
reply to each command
Definition: Interpreter.h:256
const std::string get_message() const
void set(Archive *data)
set the current Archive
Definition: Interpreter.C:441
Defines the PSRCHIVE library.
Definition: CalSource.h:17
std::string dedisperse(const std::string &args)
dedisperse an archive in the stack
Definition: Interpreter.C:1229
std::string fscrunch(const std::string &args)
frequency scrunch an archive in the stack
Definition: Interpreter.C:1052
std::string image_correct(const std::string &args)
apply image pulse correction
Definition: Interpreter.C:1322
~Interpreter()
destructor
Definition: Interpreter.C:330
std::string screen_dump(const std::string &args)
dump the raw data points to the screen
Definition: Interpreter.C:1580
Corrects Faraday rotation.
Definition: FaradayRotation.h:37
void unload(const std::string &filename, const std::string &command="")
Unload the results to a file.
Definition: DynamicSpectrum.C:135
std::string scattered_power_correct(const std::string &args)
apply scattered power corrections
Definition: Interpreter.C:1295
std::stack< Reference::To< Archive > > theStack
the Archive stack
Definition: Interpreter.h:235
std::string state(const std::string &args)
convert the state of the data
Definition: Interpreter.C:1161
Pulsar data processing command language interpreter.
Definition: Interpreter.h:57
void setmap(const std::string &name, Archive *data)
set the named Archive
Definition: Interpreter.C:480
int get_return_value() const

Generated using doxygen 1.8.17