Diploma Thesis Percolation Simulation
C++ Sourcecode Documentation

www.AndreasKrueger.de/thesis/code

Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

commandline Namespace Reference


Compounds

class  cline_par

Enumerations

enum  subprgs {
  NONE, FFC, FFS,
  NOC, OPT
}

Functions

int commandname_position (char *argv0)
void cout_tail (char *wholename, int start)
string commandname_wo_path (char *argv0)
void cout_command_endl (int argc, char *argv[])
void cout_command_wo_path (int argc, char *argv[])
void show_commandline (int argc, char *argv[])
subprgs subprg_name2enum (string name)
ostream & operator<< (ostream &os, subprgs s)
void show_commandline_options (char *argv0)
void out_subprgname (ostream &os, cline_par &p)
ostream & operator<< (ostream &os, cline_par p)
string get_first_word (char *parameters)
bool recognized_switch (int argc, char *argv[], cline_par &param)
bool percentage_ok (REAL percentage, REAL lower_N)
bool dimrange_ok (int dim1, int dim2)
bool Nrange_ok (REAL N1, NUMBER N2)
bool precision_ok (REAL prec)
bool atleast_ok (COUNTER a)
bool range_ok (cline_par p)
int enum2criterion (subprgs subprg)
int start_subprg (cline_par &p, clock_t &return_totaltime)

Variables

const char SLASH = '/'


Enumeration Type Documentation

enum commandline::subprgs
 

Enumeration values:
NONE 
FFC 
FFS 
NOC 
OPT 

Definition at line 75 of file commandline.h.

Referenced by enum2criterion(), operator<<(), and subprg_name2enum().

00076 {
00077         NONE,   
00078     FFC,
00079     FFS,
00080         NOC,
00081         OPT
00082 } ;


Function Documentation

bool atleast_ok COUNTER    a
 

Definition at line 248 of file commandline.h.

References COUNTER.

Referenced by range_ok().

00248 {return (a>=1); }

int commandname_position char *    argv0
 

Definition at line 16 of file commandline.h.

References SLASH.

Referenced by cout_command_wo_path().

00016                                      {
00017         int name_pos=0;
00018         char* path_plus_name=argv0;
00019         int ch;
00020         for (ch=0; path_plus_name[ch]!=0;ch++){
00021                 if (path_plus_name[ch]==SLASH) name_pos=ch+1;
00022         }
00023         return name_pos;
00024 }

string commandname_wo_path char *    argv0
 

Definition at line 33 of file commandline.h.

References SLASH.

Referenced by show_commandline_options().

00033                                        {
00034         int name_pos=0;
00035         char* path_plus_name=argv0;
00036         int ch;
00037         for (ch=0; path_plus_name[ch]!=0;ch++){
00038                 if (path_plus_name[ch]==SLASH) name_pos=ch+1;
00039         }
00040         string temp="";
00041         for (ch=name_pos; argv0[ch]!=0;ch++){
00042                 temp+=argv0[ch];
00043         }       
00044         return temp;
00045 }

void cout_command_endl int    argc,
char *    argv[]
 

Definition at line 48 of file commandline.h.

Referenced by show_commandline().

00048                                               {
00049         int i;
00050         for (i=0;i<argc;i++){
00051                 cout <<i<<": "<<argv[i]<<endl;
00052         }
00053 }

void cout_command_wo_path int    argc,
char *    argv[]
 

Definition at line 55 of file commandline.h.

References commandname_position(), and cout_tail().

Referenced by main(), and show_commandline().

00055                                                  {
00056         int name_pos=commandname_position(argv[0]);
00057         cout_tail(argv[0],name_pos);
00058         cout <<" ";
00059         int i;
00060         for (i=1;i<argc;i++){
00061                 cout <<argv[i]<<" ";
00062         }
00063 }

void cout_tail char *    wholename,
int    start
 

Definition at line 26 of file commandline.h.

Referenced by cout_command_wo_path().

00026                                            {
00027         int ch;
00028         for (ch=start; wholename[ch]!=0;ch++){
00029                 cout <<wholename[ch];
00030         }       
00031 }

bool dimrange_ok int    dim1,
int    dim2
 

Definition at line 245 of file commandline.h.

References MAXDIM.

Referenced by range_ok().

00245 {return (dim1<=dim2 && dim1>0 && dim2<=MAXDIM);}

int enum2criterion subprgs    subprg
 

Definition at line 279 of file commandline.h.

References FFC, FFS, NOC, and subprgs.

Referenced by start_subprg().

00279                                   {
00280         int criterion;
00281         switch (subprg) {
00282         case FFC:
00283                 criterion=1;
00284                 break;
00285         case FFS:
00286                 criterion=2;
00287                 break;
00288         case NOC:
00289                 criterion=3;
00290                 break;
00291         default:
00292                 cout<<"unknown sub-programm, sorry. (Please write to cpp__at__AndreasKrueger__dot__de)\n"<<endl;
00293                 return -1;
00294         }
00295         return criterion;
00296 }

string get_first_word char *    parameters
 

Definition at line 167 of file commandline.h.

Referenced by recognized_switch().

00167                                        {
00168         int i=0; string first_word="";
00169         bool foundend=false;
00170         while (!foundend && parameters[i]!='\0'){
00171                 if (parameters[i]!=' '){
00172                         first_word+=parameters[i];
00173                 }
00174                 else{
00175                         foundend=true;
00176                 }
00177                 i++;
00178         }
00179         return first_word;
00180 }

bool Nrange_ok REAL    N1,
NUMBER    N2
 

Definition at line 246 of file commandline.h.

References MAXNUMBER, NUMBER, and REAL.

Referenced by range_ok().

00246 { return (N1<=N2 && N1>=2 && N2<MAXNUMBER);}

ostream& operator<< ostream &    os,
cline_par    p
 

Definition at line 157 of file commandline.h.

References commandline::cline_par::at_least, commandline::cline_par::computername, commandline::cline_par::criterion, FFC, FFS, commandline::cline_par::fromdim, commandline::cline_par::fromN, NOC, OPT, out_subprgname(), commandline::cline_par::percentOfSpheres, commandline::cline_par::precision, commandline::cline_par::subprg, commandline::cline_par::todim, and commandline::cline_par::toN.

00157                                              {
00158         out_subprgname(os,p);
00159         if (p.subprg==NOC) os<<p.percentOfSpheres<<"%";
00160         if (p.subprg==FFC || p.subprg==FFS || p.subprg==NOC) {
00161            os <<" from "<<p.fromdim<<" to "<<p.todim<<" dim and N="<<p.fromN<<" to "<<p.toN;
00162            os <<" with target precision "<<p.precision*100<<"% and at least "<<p.at_least<<" runs.";
00163         }
00164         if (p.subprg==OPT)  os<<p.criterion<<" on computer "<<p.computername;
00165         return os;
00166 }

ostream& operator<< ostream &    os,
subprgs    s
 

Definition at line 91 of file commandline.h.

References FFC, FFS, NOC, OPT, and subprgs.

00091                                            {
00092         if (s==FFC) os<<"ffc";
00093         if (s==FFS) os<<"ffs";
00094         if (s==NOC) os<<"noc";
00095         if (s==OPT) os<<"opt";
00096         return os;
00097 }

void out_subprgname ostream &    os,
cline_par   p
 

Definition at line 135 of file commandline.h.

References FFC, FFS, NOC, OPT, and commandline::cline_par::subprg.

Referenced by operator<<().

00135                                               {
00136         switch (p.subprg) {
00137         case FFC:
00138                 os<<"find critical_fillingfactor";
00139                 break;
00140                 
00141         case FFS:
00142                 os<<"find saturating_fillingfactor";
00143                 break;
00144 
00145         case NOC:
00146                 os<<"find fillingfactor where number-of-clusters=";
00147                 break;
00148 
00149         case OPT:
00150                 os<<"find optimal number of cuts by checking wide range at " ;
00151                 break;
00152 
00153         default:
00154                 os<<"unknown subprogramm";
00155         }
00156 }

bool percentage_ok REAL    percentage,
REAL    lower_N
 

Definition at line 242 of file commandline.h.

References REAL.

Referenced by range_ok().

00242                                                   {
00243         REAL percent_step=100/lower_N;
00244         return (percentage>percent_step); }

bool precision_ok REAL    prec
 

Definition at line 247 of file commandline.h.

References REAL.

Referenced by range_ok().

00247 {return (prec>0 && prec <1);};

bool range_ok cline_par    p
 

Definition at line 250 of file commandline.h.

References commandline::cline_par::at_least, atleast_ok(), dimrange_ok(), FFC, FFS, commandline::cline_par::fromdim, commandline::cline_par::fromN, MAXDIM, MAXNUMBER, NOC, Nrange_ok(), percentage_ok(), commandline::cline_par::percentOfSpheres, commandline::cline_par::precision, precision_ok(), commandline::cline_par::subprg, commandline::cline_par::todim, and commandline::cline_par::toN.

Referenced by main().

00250                           {
00251         bool ok=true;
00252         if (p.subprg==NOC){
00253                 if (!percentage_ok(p.percentOfSpheres,p.fromN)) {
00254                         ok=false;
00255                         cerr<<"ERROR: percentage not in allowed range (must be > 100/from_N and <100)"<<endl;
00256                 }
00257         }
00258         if (p.subprg==FFC ||p.subprg==FFS ||p.subprg==NOC){
00259                 if (!dimrange_ok(p.fromdim, p.todim)) {
00260                         ok=false;
00261                         cerr<<"ERROR: dim not in allowed range (1 to "<<MAXDIM<<") or wrong order"<<endl;
00262                 }
00263                 if (!Nrange_ok(p.fromN, p.toN)) {
00264                         ok=false;
00265                         cerr<<"ERROR: N not in allowed range (2 to "<<MAXNUMBER<<") or wrong order"<<endl;
00266                 }
00267                 if (!precision_ok(p.precision)) {
00268                         ok=false;
00269                         cerr<<"ERROR: precision not in allowed range (must be >0 to 100%)"<<endl;
00270                 }
00271                 if (!atleast_ok(p.at_least)) {
00272                         ok=false;
00273                         cerr<<"ERROR: at_least-runs not in allowed range (must be >1)"<<endl;
00274                 }
00275         }
00276         return ok;
00277 }

bool recognized_switch int    argc,
char *    argv[],
cline_par   param
 

Definition at line 183 of file commandline.h.

References commandline::cline_par::at_least, commandline::cline_par::computername, commandline::cline_par::criterion, FFC, FFS, commandline::cline_par::fromdim, commandline::cline_par::fromN, get_first_word(), NOC, OPT, commandline::cline_par::percentOfSpheres, commandline::cline_par::precision, commandline::cline_par::subprg, subprg_name2enum(), commandline::cline_par::todim, and commandline::cline_par::toN.

Referenced by main().

00183                                                                 {
00184         bool recog=false;
00185         if (argc==1) {return recog;}
00186         string fw=get_first_word(argv[1]);
00187         param.subprg= subprg_name2enum(fw);
00188         
00189         switch (param.subprg)
00190         {
00191         case FFC: 
00192                 {
00193                 if (argc!=8) break;
00194                 param.fromdim=atoi(argv[2]);
00195                 param.todim=atoi(argv[3]);
00196                 param.fromN=atof(argv[4]);
00197                 param.toN=atoi(argv[5]);
00198                 param.precision=atof(argv[6])/100; // percent
00199                 param.at_least=atoi(argv[7]);
00200                 recog=true;
00201                 }
00202                 break;
00203         case FFS: 
00204                 {
00205                 if (argc!=8) break;
00206                 param.fromdim=atoi(argv[2]);
00207                 param.todim=atoi(argv[3]);
00208                 param.fromN=atof(argv[4]);
00209                 param.toN=atoi(argv[5]);
00210                 param.precision=atof(argv[6])/100; // percent
00211                 param.at_least=atoi(argv[7]);
00212                 recog=true;
00213                 }
00214                 break;
00215         case NOC: 
00216                 {
00217                 if (argc!=9) break;
00218                 param.percentOfSpheres=atof(argv[2]);
00219                 param.fromdim=atoi(argv[3]);
00220                 param.todim=atoi(argv[4]);
00221                 param.fromN=atof(argv[5]);
00222                 param.toN=atoi(argv[6]);
00223                 param.precision=atof(argv[7])/100; // percent precision
00224                 param.at_least=atoi(argv[8]);
00225                 recog=true;
00226                 }
00227                 break;
00228         case OPT:
00229                 {
00230                 if (argc!=4) break;
00231                 param.criterion=subprg_name2enum(string(argv[2]));
00232                 param.computername=string(argv[3]);
00233                 recog=true;
00234                 }
00235                 break;
00236         default: 
00237                 { }
00238         }
00239         return recog; // and parameters param, of course
00240 }

void show_commandline int    argc,
char *    argv[]
 

Definition at line 65 of file commandline.h.

References cout_command_endl(), and cout_command_wo_path().

00065                                                {
00066         cout <<"The whole commandline argv splits into -> "<<argc<<" <- parts:"<<endl;
00067         cout_command_endl(argc, argv);
00068         cout <<"minus the path, this gives:"<<endl;
00069         cout_command_wo_path(argc, argv);
00070         cout <<endl;
00071 }

void show_commandline_options char *    argv0
 

Definition at line 99 of file commandline.h.

References commandname_wo_path(), FILEHEAD2, MAXDIM, and MAXNUMBER.

Referenced by main().

00099                                           {
00100         cout<<"\n\nCommandline options:"<<endl;
00101         cout<<"--------------------"<<endl;
00102         cout<<"Please use these parameters:"<<endl;
00103         cout<<"0<percent<100\t\t= percent of number of spheres (for noc)"<<endl;
00104         cout<<"fromdim>0, todim<"<<MAXDIM+1<<"\t= dimensions intervall"<<endl;
00105         cout<<"fromN>1, toN<"<<MAXNUMBER+1<<"\t= intervall for spherenumber"<<endl;
00106         cout<<"0< precision <100\t= target precision wished in percent"<<endl;
00107         cout<<"0< minloops\t\t= at least so many averaging loops"<<endl;
00108         cout<<"for the following (at the moment only) three possible subprograms:"<<endl<<endl;
00109         cout<<"Find the critical fillingfactor (spanning cluster threshold)"<<endl;
00110         string name = commandname_wo_path(argv0);
00111         cout<<name<<" ffc fromdim todim fromN toN precision minloops"<<endl;
00112         cout<<"Find the saturating fillingfactor (all-spheres-in-one-cluster threshold)"<<endl;
00113         cout<<name<<" ffs fromdim todim fromN toN precision minloops"<<endl;
00114         cout<<"Find the fillingfactor where number-of-clusters=percent% * N"<<endl;
00115         cout<<name<<" noc percent fromdim todim fromN toN precision minloops"<<endl;
00116         cout<<"   (Optimized especially for percent=1 and percent=90)"<<endl;
00117         cout<<"Check a wide range of cuts for speed:"<<endl;
00118         cout<<name<<" opt ffs/ffc computername"<<endl;
00119 
00120         cout<<""<<endl;
00121         cout<<"N.B.: You have to create a data directory "<<FILEHEAD2<<endl<<endl;
00122 }

int start_subprg cline_par   p,
clock_t &    return_totaltime
 

Definition at line 298 of file commandline.h.

References commandline::cline_par::at_least, commandline::cline_par::computername, commandline::cline_par::criterion, optimize::cuts_test_average_time(), enum2criterion(), ff::find_ff_with_criterion_scanning_N_and_dim(), ff::fillingfactor_functions::fn, commandline::cline_par::fromdim, commandline::cline_par::fromN, ff::load_stepfunctions(), ff::fillingfactor_functions::name, NUMBER, OPT, commandline::cline_par::percentOfSpheres, commandline::cline_par::precision, REAL, commandline::cline_par::subprg, ff::fillingfactor_functions::theory, commandline::cline_par::todim, and commandline::cline_par::toN.

Referenced by main().

00298                                                          {
00299         return_totaltime=clock();
00300 
00301         ff::fillingfactor_functions stepfn[ff::N_STEPFN+1];     ff::load_stepfunctions(stepfn);
00302         
00303         int criterion;
00304 
00305         if (p.subprg==OPT){
00306                 criterion=enum2criterion(p.criterion);
00307                 optimize::cuts_test_average_time(criterion, 1, p.computername);
00308                 return 0;
00309         }
00310         
00311         criterion=enum2criterion(p.subprg);
00312         if (criterion==-1) {
00313                 return_totaltime=0;
00314                 return 1;
00315         }
00316 
00317         bool (* stepfn_criterion)(REAL, ff::arguments1&)        =stepfn[criterion].fn;
00318         REAL (* ff_guessed)(NUMBER,int,REAL)                            =stepfn[criterion].theory;
00319         string namecriterion                                                            =stepfn[criterion].name;
00320 
00321         REAL percentage=100;            // e.g. NOC90% -> where number-of-clusters=90% * N
00322                                                                 // here set to a dummy-value, if criterion=1 or 2
00323         if (criterion>2) {
00324                 percentage=p.percentOfSpheres;
00325                 char buffer[5]; sprintf(buffer, "", "");
00326                 if (percentage<10) sprintf(buffer, "%1.0f%c", percentage,'%');
00327                 else sprintf(buffer, "%2.0f%c", percentage,'%');
00328                 namecriterion+=buffer;
00329         }
00330 
00331         ff::find_ff_with_criterion_scanning_N_and_dim(stepfn_criterion, percentage/100, namecriterion, 
00332                                                                                           ff_guessed,
00333                                                                                           p.fromdim, p.todim, p.fromN, p.toN, 
00334                                                                                           p.precision, p.at_least);
00335         return_totaltime=clock()-return_totaltime;
00336         return 0;
00337 }

subprgs subprg_name2enum string    name
 

Definition at line 83 of file commandline.h.

References FFC, FFS, NOC, NONE, OPT, and subprgs.

Referenced by recognized_switch().

00083                                      {
00084         if (name=="ffc") return FFC;
00085         if (name=="ffs") return FFS;
00086         if (name=="noc") return NOC;
00087         if (name=="opt") return OPT;
00088         return NONE;
00089 }


Variable Documentation

const char commandline::SLASH = '/'
 

Definition at line 13 of file commandline.h.

Referenced by commandname_position(), and commandname_wo_path().




Diploma Thesis Sourcecode Documentation
check out the text and the executable binaries

www.AndreasKrueger.de/thesis/code