Fourier library: Operations in the Fourier domain
fcommand.cc
Go to the documentation of this file.
1 
35 #define TF_FCOMMAND_CC_VERSION \
36  "TF_FCOMMAND_CC V1.0 "
37 
38 #include <fourier/fcommand.h>
39 #include <fstream>
40 #include <string>
41 #include <sstream>
42 #include <fourier/error.h>
43 
44 using std::cout;
45 using std::endl;
46 
47 namespace fourier {
48 
49  void FilterCommands::FilterCommands::help(std::ostream& os,
50  const bool& verbose)
51  {
52  os << "filter library commands:" << endl;
53  os << "rem any comment (ignored)" << endl;
54  os << "# any comment (ignored)" << endl;
55  os << "dif differentiate" << endl;
56  os << "int integrate" << endl;
57  os << "lp2 in h second order low-pass" << endl;
58  os << "hp2 in h second order high-pass" << endl;
59  os << "lpb in ord "
60  << "Butterworth low-pass of order ord" << endl;
61  os << "hpb in ord "
62  << "Butterworth high-pass of order ord" << endl;
63  os << "fac factor mutiply by factor" << endl;
64  os << "mod normal "
65  << "switch back to normal filters (default)" << endl;
66  os << "mod inverse switch to inverse filters" << endl;
67  os << "mod period "
68  << "switch to specification by period (default)" << endl;
69  os << "mod frequency switch to specification by frequency " << endl;
70  os << "end terminate file reading" << endl;
71  os << endl;
72  os << "\"in\" specifies the filter freqeuncy. It is either given" << endl;
73  os << "as a frequency (Hz) or as a period (s) depending on the" << endl;
74  os << "selected mode." << endl;
75  if (verbose)
76  {
77  os << endl;
78  os << TF_FCOMMAND_H_VERSION << endl;
79  os << TF_FILTERS_H_VERSION << endl;
80  os << TF_POLESNZEROES_H_VERSION << endl;
81  }
82  }
83 
84  /*----------------------------------------------------------------------*/
85 
86  void FilterCommands::read(const char* filename, const bool& verbose)
87  {
88  std::ifstream ifs(filename);
89  read(ifs, verbose);
90  }
91 
92  /*----------------------------------------------------------------------*/
93 
94  void FilterCommands::read(std::istream& is, const bool& verbose)
95  {
96  bool hot=is.good();
97  std::string line;
98  while(hot)
99  {
100  std::getline(is, line);
101  hot=command(line.c_str(), verbose) && is.good();
102  }
103  }
104 
105  /*----------------------------------------------------------------------*/
106 
107  bool FilterCommands::command(const char* command, const bool& verbose)
108  {
109  if (verbose) cout << " set filter: " << command << endl;
110  bool result=true;
111  std::string cmd(command);
112  std::istringstream cmdline(cmd);
113  std::string token;
114  cmdline >> token;
115  double par, h;
116  int ord;
117  if (token.find("rem")!=std::string::npos)
118  { } else if (token.find("#")!=std::string::npos)
119  { } else if (token.find("dif") != std::string::npos)
120  { setdif();
121  } else if (token.find("int") != std::string::npos)
122  { setint();
123  } else if (token.find("lp2") != std::string::npos)
124  { cmdline >> par >> h; setlp2(par, h);
125  } else if (token.find("lpb") != std::string::npos)
126  { cmdline >> par >> ord; setlpb(par, ord);
127  } else if (token.find("hp2") != std::string::npos)
128  { cmdline >> par >> h; sethp2(par, h);
129  } else if (token.find("hpb") != std::string::npos)
130  { cmdline >> par >> ord; sethpb(par, ord);
131  } else if (token.find("fac") != std::string::npos)
132  { cmdline >> par; numfactor(par);
133  } else if (token.find("mod") != std::string::npos)
134  {
135  cmdline >> token;
136  if (token.find("frequency")!=std::string::npos)
137  { setfreqmod();
138  } else if (token.find("period")!=std::string::npos)
139  { setpermod();
140  } else if (token.find("normal")!=std::string::npos)
141  { setnormal();
142  } else if (token.find("inverse")!=std::string::npos)
143  { setinverse();
144  } else
145  { FOURIER_abort("ERROR (FilterCommands): illegal mode!"); }
146  } else if (token.find("end") != std::string::npos)
147  { result=false;
148  } else
149  { FOURIER_abort("ERROR (FilterCommands): illegal command!"); }
150  return(result);
151  }
152 
153 } // namespace fourier
154 
155 /* ----- END OF fcommand.cc ----- */
void setint()
Definition: filters.cc:58
#define TF_FCOMMAND_H_VERSION
Definition: fcommand.h:39
void setlpb(const Tcvalue &par, const int &ord)
Definition: filters.cc:88
void setdif()
Definition: filters.cc:66
void sethp2(const Tcvalue &par, const double &h)
Definition: filters.cc:102
void numfactor(const Tcvalue &factor)
Definition: polesnzeroes.cc:72
evaluate filter commands (prototypes)
error handling for libfourier (prototypes)
void setlp2(const Tcvalue &par, const double &h)
Definition: filters.cc:115
#define FOURIER_abort(M)
Abort and give a message.
Definition: error.h:149
Definition: error.cc:44
#define TF_FILTERS_H_VERSION
Definition: filters.h:41
void setpermod()
Definition: filters.h:61
#define TF_POLESNZEROES_H_VERSION
Definition: polesnzeroes.h:38
bool command(const char *command, const bool &verbose=false)
Definition: fcommand.cc:107
void read(std::istream &is, const bool &verbose=false)
Definition: fcommand.cc:94
void setfreqmod()
Definition: filters.h:60
void sethpb(const Tcvalue &par, const int &ord)
Definition: filters.cc:74