\section{/home/peifer/diffit/modules/parse\-Simit.cc File Reference}
\label{parseSimit_8cc}\index{/home/peifer/diffit/modules/parseSimit.cc@{/home/peifer/diffit/modules/parseSimit.cc}}
{\tt \#include $<$string.h$>$}\par
{\tt \#include $<$stdlib.h$>$}\par
{\tt \#include $<$stddef.h$>$}\par
{\tt \#include $<$iostream$>$}\par
{\tt \#include $<$fstream$>$}\par
{\tt \#include $<$getopt.h$>$}\par
{\tt \#include $<$math.h$>$}\par
{\tt \#include \char`\"{}../nr.h\char`\"{}}\par
{\tt \#include \char`\"{}../def.h\char`\"{}}\par
{\tt \#include \char`\"{}../model.h\char`\"{}}\par
\subsection*{Defines}
\begin{CompactItemize}
\item 
\#define {\bf MAXLENGTH}~1000
\end{CompactItemize}
\subsection*{Functions}
\begin{CompactItemize}
\item 
long {\bf get\_\-list} (long n, double $\ast$arg, char $\ast$string, char $\ast$desc)
\item 
{\bf Glob\-Exp} $\ast$ {\bf parseopts} (int argc, char $\ast$argv[$\,$], {\bf Glob} $\ast$globs, char $\ast$outstr)
\end{CompactItemize}
\subsection*{Variables}
\begin{CompactItemize}
\item 
char {\bf usage} [$\,$]
\end{CompactItemize}


\subsection{Define Documentation}
\index{parseSimit.cc@{parse\-Simit.cc}!MAXLENGTH@{MAXLENGTH}}
\index{MAXLENGTH@{MAXLENGTH}!parseSimit.cc@{parse\-Simit.cc}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}\#define MAXLENGTH~1000}\label{parseSimit_8cc_1dbd686f69551b83691025eaae058539}




Definition at line 13 of file parse\-Simit.cc.

\subsection{Function Documentation}
\index{parseSimit.cc@{parse\-Simit.cc}!get_list@{get\_\-list}}
\index{get_list@{get\_\-list}!parseSimit.cc@{parse\-Simit.cc}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}long get\_\-list (long {\em n}, double $\ast$ {\em arg}, char $\ast$ {\em string}, char $\ast$ {\em desc})}\label{parseSimit_8cc_3e400bee2443fb0a46657eb816659761}




Definition at line 37 of file parse\-Simit.cc.

\footnotesize\begin{verbatim}38 {
39   long k=1,l=0,ind=0;
40   char sep=',';
41   char *dum=new char[strlen(string)+1];
42   while(string[ind]!='\0')
43     {
44       if(k>n)
45         {
46           cerr << "Too many arguments in" << desc << "list." << endl;
47           exit(1);
48         }
49       dum[l]=string[ind];
50       
51       if(dum[l]==sep)
52         {
53           dum[l]='\0';
54           arg[k]=atof(dum);
55           l=0;
56           k++;
57           ind++;
58         }
59       else
60         {
61           ind++;
62           l++;
63         }
64     }
65   dum[l]='\0';
66   arg[k]=atof(dum);
67 
68   delete dum;
69   return(k);
70 } 
\end{verbatim}\normalsize 


\index{parseSimit.cc@{parse\-Simit.cc}!parseopts@{parseopts}}
\index{parseopts@{parseopts}!parseSimit.cc@{parse\-Simit.cc}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}{\bf Glob\-Exp}$\ast$ parseopts (int {\em argc}, char $\ast$ {\em argv}[$\,$], {\bf Glob} $\ast$ {\em globs}, char $\ast$ {\em outstr})}\label{parseSimit_8cc_f7cc992592a2b95c9c3dec59ccf66584}


Main module routine doing all the pasing. \begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em argc}]The number of command line arguments as passed by {\bf main}. \item[{\em $\ast$argv\mbox{[}$\,$\mbox{]}}]String of the arguments. \item[{\em $\ast$globs}]The structure {\bf Glob}{\rm (p.\,\pageref{structGlob})}. \item[{\em $\ast$outstr}]Depreciated, not used. \end{description}
\end{Desc}


Definition at line 73 of file parse\-Simit.cc.

References Glob::do\-P, Glob::dt, Glob::elastic, Glob::eps, Glob::epsilon, FALSE, Glob::gnu\-Fp, Glob::init\-Spline, Glob::integrator, ivector(), Glob::lambda, Glob::maxit, MAXLENGTH, Glob::maxstp, Glob::minimp, Glob::no\-Gnu, Glob::no\-Measurements, Glob::nowait, Glob::npar, Glob::nr\-Exp, Glob::reg, Glob::sig, Glob::stiff, TRUE, Glob::usesig, and Glob::wait.

\footnotesize\begin{verbatim}74 {
75   int longindex,opt;
76   int parlistSpecified=FALSE;
77   long k,l,nExp,sp;
78   char name[MAXLENGTH],line[MAXLENGTH];
79 
80   //option definition
81   static struct option longopts[]={
82     {"help", 0, 0,  'h'},
83     {"help", 0, 0,  '?'},
84     {"x0"  , 1, 0,   1 },
85     {"x1"  , 1, 0,   2 },
86     {"dt"  , 1, 0,   3 },
87     {"f"    ,1, 0,   4 },
88     {"p"    ,1, 0,   5 },
89     {"y0"   ,1, 0,   6 },
90     {"nobs" ,1, 0,   7 },
91     {"eps"  ,1, 0,   8 },
92     {"sig"  ,1, 0,   9 },
93     {"maxit",1, 0,  12 },
94     {"int"  ,1, 0,  15 },
95     {"maxstp",1,0,  17 },
96     {"spline",1,0,  21 },
97     {0, 0, 0, 0}
98   };
99   //initialise some global parameters in globs
100   globs->noGnu=FALSE;
101   globs->eps=1e-6;
102   globs->npar=NPARAMS;
103   globs->noMeasurements=FALSE;
104   globs->doP=ivector(1,globs->npar);
105   for(k=1;k<=globs->npar;k++)
106     globs->doP[k]=TRUE;
107   globs->maxit=1000;
108   globs->gnuFp=NULL;
109   globs->wait=FALSE;
110   globs->usesig=FALSE;
111   globs->integrator=1;
112   globs->stiff=TRUE;
113   globs->maxstp=5000;
114   globs->minimp=0.05;
115   globs->nowait=FALSE;
116   globs->elastic=1.;
117   globs->reg=FALSE;
118   globs->epsilon=1e-10;
119   globs->lambda=1e6;
120   globs->dt=0.1;
121   globs->sig=0.;
122   globs->nrExp=1;
123   globs->initSpline=TRUE;
124 
125   while ((opt=getopt_long_only(argc,argv,"h?",longopts,&longindex)) != -1)
126     {
127       switch(opt)
128         {
129         case 4:
130           parlistSpecified=TRUE;
131           strncpy(name,optarg,MAXLENGTH);
132           break;
133         }
134     }
135   optind=0;
136   
137   GlobExp *ex;
138   if(parlistSpecified==FALSE)
139     {
140       globs->nrExp=1;
141       ex=new GlobExp[globs->nrExp+1];  
142       //initialise some global parameters
143       ex[1].fitstart=0;
144       ex[1].fitend=1;
145       ex[1].nobs=NOBS;
146       ex[1].nvar=NEQNS;
147       ex[1].y0=NULL;
148       ex[1].par=dvector(1,NPARAMS);
149       for(k=1;k<=globs->npar;k++)
150         ex[1].par[k]=DefParameters[k-1];
151     }
152   else //if parlist specified
153     {
154       ifstream in;     
155       ofstream out;
156       char str[MAXLENGTH];
157 
158       in.open(name);
159 
160       if(!in)
161         {
162           cerr << "parameter list " << name << "  not found\n";
163           exit(1);
164         }
165       
166       //preprocessing of data list
167       globs->nrExp=1;
168       ex=new GlobExp[globs->nrExp+1];   
169       //initialise some global parameters
170       ex[1].fitstart=0;
171       ex[1].fitend=1;
172       ex[1].nobs=NOBS;
173       ex[1].nvar=NEQNS;
174       ex[1].par=dvector(1,NPARAMS);
175       for(k=1;k<=globs->npar;k++)
176         ex[1].par[k]=DefParameters[k-1];
177 
178       sprintf(str,"%s.%d",name,globs->nrExp);
179       out.open(str);
180       while(!in.eof())
181         {       
182           in.getline(str,MAXLENGTH,'\n');
183           if(str[0]!='#')
184             {
185               out << str << endl;
186             }
187         }
188       out.flush();
189       out.close();
190       in.close();
191       
192       long _argc;
193       char *_argv[MAXLENGTH];
194 
195       for(k=0;k<=MAXLENGTH;k++)
196         _argv[k]=(char *)malloc((size_t) (500*sizeof(char)));
197 
198       
199       ifstream inp;
200       
201       _argc=0;
202       sprintf(str,"%s.1",name);
203       inp.open(str);
204       
205       
206       while(!inp.eof())
207         {
208           inp >> _argv[_argc+1];
209           _argc++;
210         }
211       inp.close();
212       
213   
214       //PARSING LIST
215       optind=0;
216       while((opt=getopt_long_only(_argc,_argv,"h?",longopts,&longindex)) != -1)
217         {
218           switch(opt)
219             {
220             case 'h':
221               cout << usage << endl;
222               exit(1);
223               break;
224             case '?':
225               cerr << usage << endl;
226               exit(1);  
227               break;
228             case 1:
229               ex[1].fitstart=atof(optarg);
230               break;
231             case 2:
232               ex[1].fitend=atof(optarg);
233               break;
234             case 3:
235               globs->dt=fabs(atof(optarg));
236               break;
237             case 4:
238               break;
239             case 5:
240               get_list(globs->npar,ex[1].par,optarg," parameter ");
241               break;
242             case 6:
243               ex[1].y0=dvector(1,ex[1].nvar);
244               for(k=1;k<=ex[1].nvar;k++)
245                 ex[1].y0[k]=0.;
246               k=get_list(ex[1].nvar,ex[1].y0,optarg," initial values ");
247               if(k!=ex[1].nvar)
248                 {
249                   cerr << ex[1].nvar << " initial values required.\n";
250                   exit(1);
251                 }
252               break;
253             case 7:
254               ex[1].nobs=atol(optarg);
255               break;
256             case 8:
257               globs->eps=fabs(atof(optarg));
258               break;
259             case 9:
260               globs->sig=fabs(atof(optarg));
261               break;
262             case 11:
263               if(strlen(optarg)!=globs->npar)
264                 {
265                   cerr << strlen(optarg) << " parameter(s) specified instead of " <<  globs->npar << ".\n";
266                   exit(1);
267                 }
268               for(k=0;k < globs->npar;k++)
269                 {
270                   if(optarg[k]=='0')
271                     globs->doP[k+1]=FALSE;
272                   else
273                     globs->doP[k+1]=TRUE;
274                 }
275               break;
276             case 12:
277               globs->maxit=abs(atol(optarg));
278               break;
279             case 15:
280               globs->integrator=abs(atoi(optarg));
281               break;
282             case 17:
283               globs->maxstp=abs(atoi(optarg));
284               break;
285             case 21:
286               k=0;
287               l=1;
288               ex[1].splinesDefined=TRUE;
289               while(optarg[k]!='\0')
290                 {
291                   if(optarg[k]==',')
292                     l++;
293                   k++;
294                 }
295               if(l!=NSPLINES)
296                 {
297                   cerr << "Incompatible number of splines.\n";
298                   exit(1);
299                 }
300               ex[1].splineFile=new string[l+1];
301               l=1;
302               sp=0;
303               k=0;
304               while(optarg[k]!='\0')
305                 {
306                   if(optarg[k]==',')
307                     {
308                       line[sp]='\0';
309                       ex[1].splineFile[l]=(string)line;
310                       sp=0;
311                       l++;
312                     }
313                   else
314                     {
315                       line[sp]=optarg[k];
316                       sp++;
317                     }
318                   k++;
319                 }
320               line[sp]='\0';
321               ex[1].splineFile[l]=(string)line;
322               break;
323             default:
324               cerr << endl;
325               cerr << "Parsing command line options produced errors \n\n";
326               exit(1);
327             }
328         }
329       nExp=1;
330       //Parsing file name
331       if((_argc-optind)!=1)
332         {
333           cerr << "No/Too many datafile(s) specified for experiment " << nExp << " .  \n\n";
334           exit(1);
335         }
336       else
337         {
338           ex[nExp].fileName=new char[strlen(_argv[optind])+1];
339           strcpy(ex[nExp].fileName,_argv[optind]);
340         }
341       //checking if x0 < x1
342       if(ex[nExp].fitstart >= ex[nExp].fitend)
343         {
344           cerr << "x0 must be smaller than x1.\n";
345           exit(1);
346         } 
347       
348       sprintf(str,"rm -f %s.*",name);
349       system(str);
350     }
351 
352   optind=0;
353   
354   while((opt=getopt_long_only(argc,argv,"h?",longopts,&longindex)) != -1)
355     {
356       switch(opt)
357         {
358         case 'h':
359           cout << usage << endl;
360           exit(1);
361           break;
362         case '?':
363           cerr << usage << endl;
364           exit(1);      
365           break;
366         case 1:
367           ex[1].fitstart=atof(optarg);
368           break;
369         case 2:
370           ex[1].fitend=atof(optarg);
371           break;
372         case 3:
373           globs->dt=fabs(atof(optarg));
374           break;
375         case 4:
376           break;
377         case 5:
378           get_list(globs->npar,ex[1].par,optarg," parameter ");
379           break;
380         case 6:
381           ex[1].y0=dvector(1,ex[1].nvar);
382           for(k=1;k<=ex[1].nvar;k++)
383             ex[1].y0[k]=0.;
384           k=get_list(ex[1].nvar,ex[1].y0,optarg," initial values ");
385           if(k!=ex[1].nvar)
386             {
387               cerr << ex[1].nvar << " initial values required.\n";
388               exit(1);
389             }
390           break;
391         case 7:
392           ex[1].nobs=atol(optarg);
393           break;
394         case 8:
395           globs->eps=fabs(atof(optarg));
396           break;
397         case 9:
398           globs->sig=fabs(atof(optarg));
399           break;
400         case 11:
401           if(strlen(optarg)!=globs->npar)
402             {
403               cerr << strlen(optarg) << " parameter(s) specified instead of " <<  globs->npar << ".\n";
404               exit(1);
405             }
406           for(k=0;k < globs->npar;k++)
407             {
408               if(optarg[k]=='0')
409                 globs->doP[k+1]=FALSE;
410               else
411                 globs->doP[k+1]=TRUE;
412             }
413           break;
414         case 12:
415           globs->maxit=abs(atol(optarg));
416           break;
417         case 15:
418           globs->integrator=abs(atol(optarg));
419           break;
420         case 17:
421           globs->maxstp=abs(atoi(optarg));
422           break;
423         case 21:
424           k=0;
425           l=1;
426           ex[1].splinesDefined=TRUE;
427           while(optarg[k]!='\0')
428             {
429               if(optarg[k]==',')
430                 l++;
431               k++;
432             }
433           if(l!=NSPLINES)
434             {
435               cerr << "Incompatible number of splines.\n";
436               exit(1);
437             }
438           ex[1].splineFile=new string[l+1];
439           l=1;
440           sp=0;
441           k=0;
442           while(optarg[k]!='\0')
443             {
444               if(optarg[k]==',')
445                 {
446                   line[sp]='\0';
447                   ex[1].splineFile[l]=(string)line;
448                   sp=0;
449                   l++;
450                 }
451               else
452                 {
453                   line[sp]=optarg[k];
454                   sp++;
455                 }
456               k++;
457             }
458           line[sp]='\0';
459           ex[1].splineFile[l]=(string)line;
460           break;
461         default:
462           cerr << endl;
463           cerr << "Parsing command line options produced errors \n\n";
464           exit(1);
465         }
466     }
467   //checking if x0 < x1
468   if(ex[1].fitstart >= ex[1].fitend)
469     {
470       cerr << "x0 must be smaller than x1.\n";
471       exit(1);
472     }
473   
474   //Parsing file name for a single experiment
475   if((argc-optind)!=1 && parlistSpecified==FALSE)
476     {
477       cerr << "No/Too many datafile(s) specified.  \n\n";
478       exit(1);
479     }
480   else if(parlistSpecified==FALSE)
481     {
482       ex[1].fileName=new char[strlen(argv[optind])+1];
483       strcpy(ex[1].fileName,argv[optind]);
484     }
485 
486     
487   if(NSPLINES!=0)
488     {
489        if(ex[1].splinesDefined==FALSE)
490             {
491               cerr << "Please specify spline data.\n";
492               exit(1);
493             }
494     }
495   
496 
497   return(ex);
498 }
\end{verbatim}\normalsize 




\subsection{Variable Documentation}
\index{parseSimit.cc@{parse\-Simit.cc}!usage@{usage}}
\index{usage@{usage}!parseSimit.cc@{parse\-Simit.cc}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}char {\bf usage}[$\,$]}\label{parseSimit_8cc_c272052a23799ed4af95e9876ba00fac}


{\bf Initial value:}

\footnotesize\begin{verbatim}"\n\t --- simit : Simulating differential equations ---\n \
      simit, v 2.3 12/Apr./2006  Univ. of Freiburg, Author: Martin Peifer\n \n \
      SYNOPSIS \n \t simit [Options]  <File>\n\n \
      DESCRIPTION\n \
      \t -h -? -help \t help\n \
      \t -f <File> \t parameter file for simulation \n \
      \t -x0 <val> \t integration starts at time <val>\n \
      \t -x1 <val> \t integration stops at time <val>\n \
      \t -dt <val> \t integration step\n \
      \t -p <list> \t parameters, e.g. -p 0.5,2.3\n \
      \t -y0 <list> \t initial values, e.g. -y0 1,2\n \
      \t -nobs <num> \t number of observed quantities\n \
      \t -eps <val> \t integration accuracy\n \
      \t -sig <val> \t noise level\n \
      \t -int <num> \t integrator: 1-> Runge-Kutta (default)\n \
      \t            \t             2-> CVODES \n \
      \t            \t             3-> ODESSA \n \
      \t -maxstp \t maximal integration steps\n \
      \t -spline <list>  specifies spline data for non-autonomous ode's \n"
\end{verbatim}\normalsize 


Definition at line 17 of file parse\-Simit.cc.