muMECH  1.0
mumechtest.cpp
Go to the documentation of this file.
1 //********************************************************************************************************
2 // code: ### ### ##### #### ## ##
3 // ## ## ######## ## ## ## ## ##
4 // ## ## ## ## ## ### ## ######
5 // ## ## ## ## ## ## ## ## ##
6 // ##### ## ## ##### #### ## ##
7 // ##
8 //
9 // name: mumechtest.h
10 // author(s): Ladislav Svoboda
11 // language: C, C++
12 // license: This program is free software; you can redistribute it and/or modify
13 // it under the terms of the GNU Lesser General Public License as published by
14 // the Free Software Foundation; either version 2 of the License, or
15 // (at your option) any later version.
16 //
17 // This program is distributed in the hope that it will be useful,
18 // but WITHOUT ANY WARRANTY; without even the implied warranty of
19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 // GNU Lesser General Public License for more details.
21 //
22 // You should have received a copy of the GNU Lesser General Public License
23 // along with this program; if not, write to the Free Software
24 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 //********************************************************************************************************
31 #include "types.h"
32 
33 #include <string.h>
34 #include "problem.h"
35 #include "tests.h"
36 #include "macros.h"
37 
38 #include "librw.h"
39 
40 
41 using namespace mumech;
42 
45  MBO_Tests_Verif, // verified tests
46  MBO_Tests_Tools, // tools
47 
48  MBO_Tests_Tom, // Tom's tests will be run
49  MBO_Tests_Termit, // Termit's tests will be run
50  MBO_Tests_Standa, // Standa's tests will be run
51  MBO_Tests_Honza, // Honza's tests will be run
52  MBO_Tests_Lukas, // Lukas's tests will be run
53  MBO_Tests_Vorel, // Vorlas'ojc tests will be run
54 
55  cMBO // count of ...
56 };
57 
58 void help (void);
59 bool parameters (int argc, char *argv[], bool MBO[]);
60 
61 
65 int main (int argc, char *argv[])
66 {
67  // version
68  if (AP_find_option (argc, argv, "--version"))
69  { fprintf (stdout, "%.2f\n", VERSION); return 0; }
70 
71  bool MBO[cMBO]; // array with main Boolean Options
72  memset(MBO, 0, cMBO*sizeof(bool));
73 
74  // detection of paramaters
75  if (parameters (argc, argv, MBO) == false)
76  help();
77 
78 
79  if (MBO[MBO_Tests_Verif]) tests_verified(); // verified tests
80  if (MBO[MBO_Tests_Tools]) tests_tools(); // tools
81 
82  if (MBO[MBO_Tests_Tom]) tests_tom(); // Tom's custom tests.
83  if (MBO[MBO_Tests_Termit]) tests_termit(); // Termit's custom tests.
84  if (MBO[MBO_Tests_Standa]) tests_standa(); // Standa's custom tests.
85  if (MBO[MBO_Tests_Honza]) tests_honza(); // Honza's custom tests.
86  if (MBO[MBO_Tests_Lukas]) tests_lukas(); // Lukas's custom tests.
87  if (MBO[MBO_Tests_Vorel]) tests_vorel(); // Vorlas's custom tests.
88 
89  return 0;
90 }
91 // *** END OF MAIN ***
92 
93 
95 void help (void)
96 {
97  fprintf (stdout,
98 " \n"
99 " ************ \n"
100 " MuMECH \n"
101 " ************ \n"
102 " An open source C++ library of analytical solutions \n"
103 " to micromechanical problems \n"
104 " Copyright (C) 2013-2014 Jan Novák \n"
105 " \n"
106 " SYNTAX mumech [--help|--version] \n"
107 " mumech -main_tests_* \n"
108 " \n"
109 " DESCRIPTION \n"
110 " \n"
111 " --help ... print this help \n"
112 " --version ... print this help \n"
113 " \n"
114 " -main_tests_verified \n"
115 " -main_tests_tools \n"
116 " \n"
117 " -main_tests_tom \n"
118 " -main_tests_termit \n"
119 " -main_tests_standa \n"
120 " -main_tests_honza \n"
121 " -main_tests_lukas \n"
122 " -main_tests_vorel \n"
123 " \n\n");
124 }
125 
126 
127 // *****************************************************************************************
128 // *** *** *** *** *** DETECTION OF PARAMETRES *** *** *** *** ***
129 // *****************************************************************************************
130 bool parameters (int argc, char *argv[], bool MBO[])
131 {
132  // ***
133  // *** HELP PARAMETER
134  // ***
135  if (argc==1 || AP_find_option (argc,argv,"--help")) return false;
136 
137  // ***
138  // *** find file with PARAMETERS
139  // ***
140  long cmdl_argc = 0;
141  if (long pos = AP_find_option (argc, argv, "-f")) {
142  FILE *par = _openFileN ("r", "File with options", argv[pos+1]);
143 
144  cmdl_argc = argc;
145  long file_argc = FP_number_of_words (par); rewind(par);
146 
147  if (file_argc) {
148  char **cmdl_argv = argv;
149  argv = new char*[cmdl_argc + file_argc];
150 
151  for (argc=0; argc<cmdl_argc; argc++)
152  argv[argc] = cmdl_argv[argc];
153 
154  for (; argc<cmdl_argc + file_argc; argc++) {
155  FP_skip_nonword (par);
157  if (!FP_skip_nonword (par)) break;
158  argv[argc] = new char[1023];
159  FP_scan_word (par, argv[argc]);
160  }
161  }
162  fclose (par);
163  }
164 
165 
167  printf ("Detection of command line parameters\n");
168 
170  char commpar1[1023]; commpar1[0] = '\0';
171  char commpar2[1023]; commpar2[0] = '\0';
172 
173  //double auxd;
174  //char auxs[1023];
175 
176  for (int i=1; i<argc; i++) {
177  if (!_STRCMP("-f", argv[i])) i++;
178  // ***
179  // *** tests
180  // ***
181  else if (!_STRCMP("-main_tests_verified", argv[i])) { MBO[MBO_Tests_Verif] = true; sprint_param (commpar1, argv+i, 1); }
182  else if (!_STRCMP("-main_tests_tools", argv[i])) { MBO[MBO_Tests_Tools] = true; sprint_param (commpar1, argv+i, 1); }
183  else if (!_STRCMP("-main_tests_tom", argv[i])) { MBO[MBO_Tests_Tom] = true; sprint_param (commpar1, argv+i, 1); }
184  else if (!_STRCMP("-main_tests_termit", argv[i])) { MBO[MBO_Tests_Termit] = true; sprint_param (commpar1, argv+i, 1); }
185  else if (!_STRCMP("-main_tests_standa", argv[i])) { MBO[MBO_Tests_Standa] = true; sprint_param (commpar1, argv+i, 1); }
186  else if (!_STRCMP("-main_tests_honza", argv[i])) { MBO[MBO_Tests_Honza] = true; sprint_param (commpar1, argv+i, 1); }
187  else if (!_STRCMP("-main_tests_lukas", argv[i])) { MBO[MBO_Tests_Lukas] = true; sprint_param (commpar1, argv+i, 1); }
188  else if (!_STRCMP("-main_tests_vorel", argv[i])) { MBO[MBO_Tests_Vorel] = true; sprint_param (commpar1, argv+i, 1); }
189 
190  // ***
191  // ***
192  // ***
193  //else if (!_STRCMP("-min_axes_diff", argv[i])) { Pd->set_semiaxes_min_difference(atof(argv[++i])); sprint_param (commpar2, argv+i, 2); if (Pd->give_semiaxes_min_difference() == _MIN_AXES_DIFF) _errorr2("Please, set the -min_axes_diff value different from %lf", _MIN_AXES_DIFF); } ///
194  //else if (!_STRCMP("-max_axes_diff", argv[i])) { Pd->set_semiaxes_max_difference(atof(argv[++i])); sprint_param (commpar2, argv+i, 2); if (Pd->give_semiaxes_max_difference() == _MAX_AXES_DIFF) _errorr2("Please, set the -max_axes_diff value different from %lf", _MAX_AXES_DIFF); } ///
195 
196  // unknown non-empty parameter
197  else if (argv[i][0] != '\0') _errorr2 ("unknown parameter \"%s\"", argv[i]);
198  }
199 
200  // ***
201  // *** PRINT OF PARAMETERS
202  // ***
203  fprintf (stdout,"Parameters: %s %s\n\n", commpar1, commpar2);
204 
205  // deallocation
206  if (cmdl_argc) {
207  for (int i=cmdl_argc; i<argc; i++)
208  delete [] argv[i];
209 
210  delete [] argv;
211  }
212 
213  return true;
214 }
void tests_lukas(void)
Definition: tests_lukas.cpp:37
file of various types and symbolic constant definitions
void FP_skip_line_commented(FILE *stream)
move file descriptor to the start of the new noncommented line, without checking of EOF ...
Definition: librw.cpp:156
void sprint_param(char *s, char *argv[], int n)
Definition: librw.cpp:782
#define _openFileN(_1, _2, _3)
Definition: gelib.h:182
Input / output function.
bool parameters(int argc, char *argv[], bool MBO[])
Definition: mumechtest.cpp:130
void tests_termit(void)
void tests_tools(void)
void help(void)
prints help / syntax
Definition: mumechtest.cpp:95
mainBoolOpt
ProbDesc Boolean Option.
Definition: mumechtest.cpp:44
The header file of usefull macros.
#define _errorr2(_1, _2)
Definition: gelib.h:154
long FP_number_of_words(FILE *stream)
count number of words (see isWordChar) in file
Definition: librw.cpp:319
#define _STRCMP
Definition: macros.h:57
void tests_standa(void)
long AP_find_option(int argc, char *argv[], const char *s)
*** *** *** *** ARGUMENTS PROCESSING *** *** *** *** terminology: tar -cz -f archiv.tgz archiv/ /// fce name | arguments /// fce name | options | parameters /// fce name | opt | opt | opt argum.
Definition: librw.cpp:108
#define VERSION
Definition: types.h:46
void tests_vorel(void)
Definition: tests_vorel.cpp:57
void tests_honza(void)
Definition: tests_honza.cpp:6
bool FP_skip_nonword(FILE *stream)
*** *** *** SKIPING *** *** *** skiping == shift stream pointer at the first char which is not ...
Definition: librw.cpp:363
void tests_tom(void)
Definition: tests_tom.cpp:6
int FP_scan_word(FILE *src, char *dest)
... word; return value is length of the word
Definition: librw.cpp:455
void tests_verified(void)
Class Problem.
int main(int argc, char *argv[])
*** *** *** *** MAIN *** *** *** ***
Definition: mumechtest.cpp:65