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
19namespace Pulsar {
20
21 class Archive;
22 class Weight;
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
240
243
244 // commands that request expansion will have arguments evaluated
245 bool evaluation_enabled;
246
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
303template<typename T>
304T 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
314template<typename T>
315T 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
328Pulsar::Interpreter* standard_shell ();
329
330#endif
Interpreter()
default constructor
Definition Interpreter.C:318
The primary interface to pulsar observational data.
Definition Archive.h:46
Corrects band-reversed signal due to poor image rejection.
Definition ImageCorrection.h:24
Pulsar data processing command language interpreter.
Definition Interpreter.h:52
Interpreter()
default constructor
Definition Interpreter.C:318
std::string fscrunch(const std::string &args)
frequency scrunch an archive in the stack
Definition Interpreter.C:1052
std::string load(const std::string &args)
load an archive from disk to top of stack and optionally the map
Definition Interpreter.C:507
Archive * get()
get the current Archive
Definition Interpreter.C:463
std::string fold(const std::string &args)
fold an archive in the stack
Definition Interpreter.C:1124
std::string pop(const std::string &args)
pop the top of the stack
Definition Interpreter.C:668
Status get_status() const
get the status after the last command
Definition Interpreter.h:86
std::string screen_dump(const std::string &args)
dump the raw data points to the screen
Definition Interpreter.C:1580
std::string unload_path
the path to which Archives will be unloaded
Definition Interpreter.h:260
std::string response(Status status, const std::string &text="")
All methods should return via the response methods.
Definition Interpreter.C:401
std::string image_correct(const std::string &args)
apply image pulse correction
Definition Interpreter.C:1322
std::string scale(const std::string &args)
scale each profile by the specified value
Definition Interpreter.C:1411
Reference::To< Weight > weight_policy
The current weighting scheme.
Definition Interpreter.h:281
std::string rotate(const std::string &args)
rotate each profile by the specified value
Definition Interpreter.C:1456
void set_reply(bool f)
set to false to disable the 'ok' reply
Definition Interpreter.h:89
std::string offset(const std::string &args)
offset each profile by the specified value
Definition Interpreter.C:1432
std::string push(const std::string &args)
push a clone of the current stack top onto the stack
Definition Interpreter.C:639
void setmap(const std::string &name, Archive *data)
set the named Archive
Definition Interpreter.C:480
std::string append(const std::string &args)
append one archive to another
Definition Interpreter.C:988
std::string echo(const std::string &args)
evaluate any expressions and print result
Definition Interpreter.C:846
std::string config(const std::string &args)
edit the configuration parameters
Definition Interpreter.C:961
void void bool allow_infinite_frequency
Import the Extension.
Definition Interpreter.h:225
std::string remove(const std::string &args)
remove the named archive from the map
Definition Interpreter.C:727
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
Status status
status flag (pass/fail)
Definition Interpreter.h:254
std::string edit(const std::string &args)
edit the current archive
Definition Interpreter.C:866
std::string state(const std::string &args)
convert the state of the data
Definition Interpreter.C:1161
bool clobber
allow the user to overwrite existing named archive
Definition Interpreter.h:242
bool reply
reply to each command
Definition Interpreter.h:251
std::string clone(const std::string &args)
clone the current archive
Definition Interpreter.C:746
bool inplace
operate on data "in place", otherwise make a copy
Definition Interpreter.h:239
std::string toggle_clobber(const std::string &args)
toggle the clober flag
Definition Interpreter.C:1545
std::map< std::string, Reference::To< Archive > > theMap
the Archive map
Definition Interpreter.h:233
bool evaluate(const std::string &expression)
Evaluate a boolean expression.
Definition Interpreter.C:894
std::string pscrunch(const std::string &args)
poln scrunch an archive in the stack
Definition Interpreter.C:1093
std::string bscrunch(const std::string &args)
bin scrunch an archive in the stack
Definition Interpreter.C:1107
std::string invint(const std::string &args)
form the Stokes invariant interval profile
Definition Interpreter.C:1143
TextInterface::Parser * get_interface()
get the interface to the current archive
Definition Interpreter.C:835
std::string unload(const std::string &args)
write an archive from either the top of the stack or the map
Definition Interpreter.C:526
std::string dynspec(const std::string &args)
compute dynamic spectrum of archive on stack
Definition Interpreter.C:1466
std::stack< Reference::To< Archive > > theStack
the Archive stack
Definition Interpreter.h:230
std::string scattered_power_correct(const std::string &args)
apply scattered power corrections
Definition Interpreter.C:1295
std::string get_report(const std::string &args)
get plugin information
Definition Interpreter.C:360
bool stopwatch
time various operations
Definition Interpreter.h:248
Archive * getmap(const std::string &name, bool throw_exception=true)
get the named Archive
Definition Interpreter.C:492
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 test(const std::string &args)
test a boolean expression
Definition Interpreter.C:944
std::string correct_instrument(const std::string &args)
correct for parallactic angle effects
void set(Archive *data)
set the current Archive
Definition Interpreter.C:441
std::string system(const std::string &args)
execute a shell command
Definition Interpreter.C:914
std::string weight(const std::string &args)
weight each profile according to the named scheme
Definition Interpreter.C:1363
std::string extract(const std::string &args)
extract part of the current archive
Definition Interpreter.C:793
bool has() const
return true if there is a current Archive
Definition Interpreter.C:475
std::string defaraday(const std::string &args)
correct for faraday rotation
Definition Interpreter.C:1262
std::string toggle_evaluate(const std::string &args)
toggle the evaluate flag
Definition Interpreter.C:1563
std::string centre(const std::string &args)
centre an archive in the stack
Definition Interpreter.C:1189
std::string tscrunch(const std::string &args)
time scrunch an archive in the stack
Definition Interpreter.C:1073
~Interpreter()
destructor
Definition Interpreter.C:330
std::string unload_extension
the extension with with Archives will be unloaded
Definition Interpreter.h:257
std::string shuffle(const std::string &args)
randomly rearrange sub-integrations
Definition Interpreter.C:1034
std::string freq_append(const std::string &args)
append one archive to another in frequency direction
Definition Interpreter.C:1003
std::string dedisperse(const std::string &args)
dedisperse an archive in the stack
Definition Interpreter.C:1229
Corrects the power scattered due to 2-bit quantization.
Definition ScatteredPowerCorrection.h:28
Algorithms that set the weights of all Profiles in an Archive.
Definition Weight.h:24
Defines the PSRCHIVE library.
Definition CalSource.h:17

Generated using doxygen 1.14.0