cuikunsimplify.c
Go to the documentation of this file.
1 
2 #include "cuiksystem.h"
3 #include "parameters.h"
4 
5 #include "defines.h"
6 #include "error.h"
7 #include "box_list.h"
8 #include "filename.h"
9 
10 #include <string.h>
11 #include <stdlib.h>
12 #include <time.h>
13 
94 int main(int argc, char **arg)
95 {
96  TCuikSystem cuiksystem; /* The set of equations */
97  Tparameters parameters; /* Parameters used in the Cuik process */
98 
99  Tlist solutions; /* The list with the simplified solutions. */
100  Titerator it; /* Iterator on the solution list */
101  Tbox boxO; /* Space where to recompose the un-simplified box. */
102 
103  Tfilename fcuik;
104  Tfilename fsol;
105  Tfilename fsolsimp;
106  Tfilename fparam;
107 
108  boolean *systemVars;
109 
110  FILE *fs;
111 
112  if (argc>2)
113  {
114  /*Init parameters*/
115  CreateFileName(NULL,arg[1],NULL,PARAM_EXT,&fparam);
116  fprintf(stderr,"Reading parameter file: %s\n",GetFileFullName(&fparam));
117  InitParametersFromFile(GetFileFullName(&fparam),&parameters);
118 
119  /*Read the problem from file*/
120  CreateFileName(NULL,arg[1],NULL,CUIK_EXT,&fcuik);
121  fprintf(stderr,"Reading equation file : %s\n",GetFileFullName(&fcuik));
122  InitCuikSystemFromFile(&parameters,GetFileFullName(&fcuik),&cuiksystem);
123  GetCSSystemVars(&systemVars,&cuiksystem);
124 
125  /*Read the simplified boxes*/
126  CreateFileName(NULL,arg[2],NULL,SOL_WITH_DUMMIES_EXT,&fsolsimp);
127  fprintf(stderr,"Reading boxes file : %s\n",GetFileFullName(&fsolsimp));
128  if (!ReadListOfBoxes(GetFileFullName(&fsolsimp),&(solutions)))
129  Error("Solution file can not be opened");
130 
131 
132  /*Save the un-simplified boxes*/
133  CreateFileName(NULL,arg[1],NULL,SOL_EXT,&fsol);
134  fprintf(stderr,"Writting boxes file : %s\n",GetFileFullName(&fsol));
135  fs=fopen(GetFileFullName(&fsol),"w");
136  if (!fs)
137  Error("Could not open the output file for the un-simplified boxes.");
138 
139 
140 
141  InitIterator(&it,&solutions);
142  First(&it);
143  while(!EndOfList(&it))
144  {
145  RegenerateOriginalBox(&parameters,(Tbox *)GetCurrent(&it),&boxO,&cuiksystem);
146  PrintBoxSubset(fs,systemVars,NULL,&boxO);
147  DeleteBox(&boxO);
148  Advance(&it);
149  }
150  fclose(fs);
151 
152  /*Remove the allocated objects*/
153  DeleteListOfBoxes(&solutions);
154  DeleteParameters(&parameters);
155  DeleteCuikSystem(&cuiksystem);
156 
157  DeleteFileName(&fparam);
158  DeleteFileName(&fcuik);
159  DeleteFileName(&fsol);
160  DeleteFileName(&fsolsimp);
161  free(systemVars);
162  }
163  else
164  {
165  fprintf(stderr," Wrong number of parameters.\n");
166  fprintf(stderr," Use:\n");
167  fprintf(stderr," cuikunsimplify <problem filename>.cuik <solution filename>.sol\n");
168  fprintf(stderr," where <problem filename> contains the original kinematic equations\n");
169  fprintf(stderr," <solution filename> contains the solutions for the simplified system\n");
170  fprintf(stderr," (the '.cuik' and '.sol' extensions are not required)\n");
171  }
172  return(EXIT_SUCCESS);
173 }
174