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 
void First(Titerator *i)
Moves an iterator to the first position of its associated list.
Definition: list.c:356
int main(int argc, char **arg)
Main body of the cuikunsimplify application.
Data structure to hold the information about the name of a file.
Definition: filename.h:248
void DeleteCuikSystem(TCuikSystem *cs)
Destructor.
Definition: cuiksystem.c:5113
unsigned int GetCSSystemVars(boolean **sv, TCuikSystem *cs)
Identifies the system variables.
Definition: cuiksystem.c:2614
Definition of the Tfilename type and the associated functions.
void RegenerateOriginalBox(Tparameters *p, Tbox *boxS, Tbox *boxO, TCuikSystem *cs)
Generates a box in the original cuiksystem from a box of the simplified one.
Definition: cuiksystem.c:4701
void Error(const char *s)
General error function.
Definition: error.c:80
#define PARAM_EXT
File extension for parameter files.
Definition: filename.h:131
#define CUIK_EXT
File extension for equation files.
Definition: filename.h:70
boolean ReadListOfBoxes(char *filename, Tlist *l)
Reads a list of boxes from a file.
Definition: box_list.c:286
Collection of methods to work on Tlist of boxes.
Error and warning functions.
void DeleteFileName(Tfilename *fn)
Destructor.
Definition: filename.c:205
void DeleteListOfBoxes(Tlist *l)
Destructor.
Definition: box_list.c:353
boolean EndOfList(Titerator *i)
Checks if an iterator is pointing at the end of the list.
Definition: list.c:445
Definitions of constants and macros used in several parts of the cuik library.
A generic list.
Definition: list.h:46
void InitIterator(Titerator *i, Tlist *list)
Constructor.
Definition: list.c:284
void InitCuikSystemFromFile(Tparameters *p, char *filename, TCuikSystem *cs)
Constructor from a file.
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 InitParametersFromFile(char *file, Tparameters *p)
Constructor from a file.
Definition: parameters.c:51
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:137
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
void * GetCurrent(Titerator *i)
Gets the element pointed by the iterator.
Definition: list.c:299
void DeleteParameters(Tparameters *p)
Destructor.
Definition: parameters.c:295
void DeleteBox(void *b)
Destructor.
Definition: box.c:1259
void PrintBoxSubset(FILE *f, boolean *used, char **varNames, Tbox *b)
Prints a (sub-)box.
Definition: box.c:1138
#define SOL_WITH_DUMMIES_EXT
File extension for solution files with dummies.
Definition: filename.h:143
List iterator.
Definition: list.h:61
Definition of the Tparameters type and the associated functions.
boolean Advance(Titerator *i)
Moves an iterator to the next position of its associated list.
Definition: list.c:373