Xmipp  v3.23.11-Nereus
args.h
Go to the documentation of this file.
1 /***************************************************************************
2 *
3 * Authors: Carlos Oscar S. Sorzano (coss@cnb.csic.es)
4 *
5 * Unidad de Bioinformatica of Centro Nacional de Biotecnologia , CSIC
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
20 * 02111-1307 USA
21 *
22 * All comments concerning this program package may be sent to the
23 * e-mail address 'xmipp@cnb.csic.es'
24 ***************************************************************************/
25 
26 #ifndef CORE_ARGS_H
27 #define CORE_ARGS_H
28 
29 #include "xmipp_strings.h"
30 #include "xmipp_error.h"
31 
32 template <typename T>
33 class Matrix1D;
34 
103 template <typename T>
104 void readFloatList(const char* str,
105  int N, std::vector< T >& v)
106 {
107  T valueF;
108  char* token;
109 
110  token = firstToken(str);
111  for (int i = 0; i < N; i++)
112  {
113  if (token == NULL)
114  REPORT_ERROR(ERR_VALUE_INCORRECT, "Cannot convert string into a list of numbers");
115 
116  valueF = (T) textToFloat(token);
117  v.push_back(valueF);
118 
119  if (i != N - 1)
120  token = nextToken();
121  }
122 }
123 
126 template <typename T>
127 void readFloatList(const std::string& str,
128  size_t& i,
129  int N,
130  std::vector< T >& v)
131 {
132  T valueF;
133  std::string token;
134 
135  token = nextToken(str, i);
136  for (int j = 0; j < N; j++)
137  {
138  if (token == "")
139  REPORT_ERROR(ERR_VALUE_INCORRECT, "Cannot convert string into list of floats");
140  valueF = (T) textToFloat(token.c_str());
141  v.push_back(valueF);
142 
143  if (j != N - 1)
144  token = nextToken(str, i);
145  }
146 }
147 
150 template <typename T>
151 void readFloatList(const char* str,
152  int N,
153  Matrix1D< T >& v,
155  std::string errmsg = "Error reading floating list",
156  int exit = 0)
157 {
158  T valueF;
159  char* token;
160 
161  token = firstToken(str);
162  for (int i = 0; i < N; i++)
163  {
164  if (token == NULL)
165  {
166  // CO: Should not report other error than the required one
167  // std::cout << "Read float list: Number of true parameters doesn't coincide\n";
168  REPORT_ERROR(_errno, errmsg);
169  }
170 
171  try
172  {
173  valueF = (T) textToFloat(token);
174  }
175  catch (XmippError)
176  {
177  REPORT_ERROR(_errno, errmsg);
178  }
179 
180  v(i) = valueF;
181  if (i != N - 1)
182  token = nextToken();
183  }
184 }
186 
219 const char* getParameter(int argc,
220  const char** argv,
221  const char* param,
222  const char* option = NULL);
223 
231 bool getTwoDoubleParams(int argc,
232  const char** argv,
233  const char* param,
234  double& v1,
235  double& v2,
236  double v1_def,
237  double v2_def);
238 
246 bool getThreeDoubleParams(int argc,
247  const char** argv,
248  const char* param,
249  double& v1,
250  double& v2,
251  double& v3,
252  double v1_def,
253  double v2_def,
254  double v3_def);
255 
272 bool checkParameter(int argc, const char** argv, const char* param);
273 
297 int paremeterPosition(int argc, const char** argv, const char* param);
298 
304 int numComponents(const std::string& str);
305 
323  const char** argv,
324  const char* param,
325  int dim = 2);
326 
331 Matrix1D<double> getVectorParameter(FILE *fh, const char *param, int dim=2);
332 
368 void generateCommandLine(const std::string& command_line,
369  int& argcp,
370  char**& argvp,
371  char*& copy);
372 
381 bool generateCommandLine(FILE* fh,
382  const char* param,
383  int& argcp,
384  char**& argvp,
385  char*& copy);
386 
406 std::string getParameter(FILE* fh,
407  const char* param,
408  int skip = 0,
409  const char* option = NULL);
410 
418 bool checkParameter(FILE* fh, const char* param);
420 
421 #endif
Matrix1D< double > getVectorParameter(int argc, const char **argv, const char *param, int dim=2)
Definition: args.cpp:138
bool checkParameter(int argc, const char **argv, const char *param)
Definition: args.cpp:97
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
void readFloatList(const char *str, int N, std::vector< T > &v)
Definition: args.h:104
ErrorType
Definition: xmipp_error.h:109
int paremeterPosition(int argc, const char **argv, const char *param)
Definition: args.cpp:111
#define i
int numComponents(const std::string &str)
Definition: args.cpp:125
double v1
const char * getParameter(int argc, const char **argv, const char *param, const char *option=NULL)
Definition: args.cpp:30
float textToFloat(const char *str)
bool getThreeDoubleParams(int argc, const char **argv, const char *param, double &v1, double &v2, double &v3, double v1_def, double v2_def, double v3_def)
Definition: args.cpp:70
#define j
struct _parameter * param
Definition: ctf.h:38
bool getTwoDoubleParams(int argc, const char **argv, const char *param, double &v1, double &v2, double v1_def, double v2_def)
Definition: args.cpp:46
char * firstToken(const char *str)
String nextToken(const String &str, size_t &i)
Incorrect value received.
Definition: xmipp_error.h:195
void generateCommandLine(const std::string &command_line, int &argcp, char **&argvp, char *&copy)
Definition: args.cpp:238