cuiksilhouette.c
Go to the documentation of this file.
1 
2 #include "cuiksystem.h"
3 
4 #include "parameters.h"
5 #include "filename.h"
6 #include "defines.h"
7 #include "error.h"
8 #include "box_list.h"
9 #include "random.h"
10 
11 #include "cp.h"
12 
13 #include <stdlib.h>
14 
128 int main(int argc, char **arg)
129 {
130  TCuikSystem cuiksystem; /* The set of equations */
131  Tparameters parameters; /* Parameters used in the Cuik process */
132  Tbox binit;
133  Tcp *cp;
134  Tlist cps;
135  unsigned int ncp;
136  Tfilename fparam;
137  Tfilename fcuik;
138  Tfilename fout;
139  FILE *f_out;
140 
141  if (argc>1)
142  {
143  randomReset();
144 
145  /*Read the parameters*/
146  CreateFileName(NULL,arg[1],NULL,PARAM_EXT,&fparam);
147  InitParametersFromFile(GetFileFullName(&fparam),&parameters);
148 
149  /*Init the CuikSystem*/
150  CreateFileName(NULL,arg[1],NULL,CUIK_EXT,&fcuik);
151  InitCuikSystemFromFile(&parameters,GetFileFullName(&fcuik),&cuiksystem);
152 
153  /*Start the output file (where the output boxes will be stored)*/
154  CreateFileName(NULL,arg[1],"_sil",SOL_EXT,&fout);
155  f_out=fopen(GetFileFullName(&fout),"w");
156  if (!f_out)
157  Error("Could not open main output file");
158 
159  /*Create a fake critical point with an empty box to bootstratp the process*/
160  InitBox(1,NULL,&binit);
161  NEW(cp,1,Tcp);
162  NewCP(0,&binit,cp);
163  DeleteBox(&binit);
164 
165  /*Add the first critical point to the list*/
166  InitList(sizeof(Tcp *),&cps);
167  AddFirstElement(&cp,&cps);
168  ncp=0; /*This is a counter of the number of control points processed*/
169 
170  /*Process all critical points in the list (when processin new
171  critical points are generated) */
172  while(!ListEmpty(&cps))
173  {
174  ExtractFirst(&cp,&cps);
175 
176  DealWithCP(f_out,ncp,&parameters,&cuiksystem,&cps,cp);
177  ncp++;
178 
179  DeleteCP(cp);
180  free(cp);
181  }
182 
183  fclose(f_out);
184 
185  DeleteFileName(&fout);
186  DeleteFileName(&fcuik);
187  DeleteFileName(&fparam);
188  }
189  else
190  {
191  fprintf(stderr," Wrong number of parameters.\n");
192  fprintf(stderr," Use:\n");
193  fprintf(stderr," cuiksilhouette <problem filename>.cuik \n");
194  fprintf(stderr," where <problem filename> contains the kinematic equations\n");
195  fprintf(stderr," (the '.cuik' extension is not required)\n");
196  }
197 
198  return(EXIT_SUCCESS);
199 }
200 
#define NEW(_var, _n, _type)
Allocates memory space.
Definition: defines.h:385
void DealWithCP(FILE *f_out, unsigned int n, Tparameters *p, TCuikSystem *cs, Tlist *cps, Tcp *cp)
Processes a critical point.
Definition: cp.c:309
Data structure to hold the information about the name of a file.
Definition: filename.h:271
void randomReset()
Resets the random seed.
Definition: random.c:18
Definition of the Tfilename type and the associated functions.
void InitBox(unsigned int dim, Tinterval *is, Tbox *b)
Initializes a box.
Definition: box.c:23
void Error(const char *s)
General error function.
Definition: error.c:80
#define PARAM_EXT
File extension for parameter files.
Definition: filename.h:132
#define CUIK_EXT
File extension for equation files.
Definition: filename.h:71
void DeleteCP(Tcp *cp)
Destructor.
Definition: cp.c:388
Collection of methods to work on Tlist of boxes.
Error and warning functions.
void DeleteFileName(Tfilename *fn)
Destructor.
Definition: filename.c:205
Definitions of constants and macros used in several parts of the cuik library.
A generic list.
Definition: list.h:46
boolean ListEmpty(Tlist *list)
Checks if a list is empty.
Definition: list.c:188
void InitCuikSystemFromFile(Tparameters *p, char *filename, TCuikSystem *cs)
Constructor from a file.
void NewCP(unsigned int l, Tbox *b, Tcp *cp)
Constructor.
Definition: cp.c:278
A table of parameters.
Definition of the TCuikSystem type and the associated functions.
void CreateFileName(char *path, char *name, char *suffix, char *ext, Tfilename *fn)
Constructor.
Definition: filename.c:22
void ExtractFirst(void *Info, Tlist *list)
Extracts the first element from the list.
Definition: list.c:212
void InitParametersFromFile(char *file, Tparameters *p)
Constructor from a file.
Definition: parameters.c:51
int main(int argc, char **arg)
Main body of the cuiksilhouette application.
Critical point structure.
Definition: cp.h:57
char * GetFileFullName(Tfilename *fn)
Gets the file full name (paht+name+extension).
Definition: filename.c:151
#define SOL_EXT
File extension for solution files.
Definition: filename.h:138
A box.
Definition: box.h:83
A cuiksystem, i.e., a set of variables and equations defining a position analysis problem...
Definition: cuiksystem.h:181
Definition of the Tcp type and the associated functions.
void DeleteBox(void *b)
Destructor.
Definition: box.c:1283
void AddFirstElement(void *Info, Tlist *list)
Adds an element at the head of the list.
Definition: list.c:196
Definition of basic randomization functions.
void InitList(unsigned int ele_size, Tlist *list)
Constructor.
Definition: list.c:135
Definition of the Tparameters type and the associated functions.