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