Institut de Robòtica i Informàtica Industrial
KRD Group

The CuikSuite Project

cuikunsimplify.c

Go to the documentation of this file.
00001 
00002 #include "cuiksystem.h"
00003 #include "parameters.h"
00004 
00005 #include "defines.h"
00006 #include "error.h"
00007 #include "box_list.h"
00008 #include "filename.h"
00009 
00010 #include <string.h>
00011 #include <stdlib.h>
00012 #include <time.h>
00013 
00073 int main(int argc, char **arg)
00074 {
00075   TCuikSystem cuiksystem;  /* The set of equations */
00076   Tparameters parameters;  /* Parameters used in the Cuik process */
00077 
00078   Tlist solutions;  /* The list with the simplified solutions. */ 
00079   Titerator it;     /* Iterator on the solution list */
00080   Tbox boxO;        /* Space where to recompose the un-simplified box. */ 
00081 
00082   Tfilename fcuik;
00083   Tfilename fsol;
00084   Tfilename fsolsimp;
00085   Tfilename fparam;
00086 
00087   boolean *systemVars;
00088   
00089   FILE *fs;
00090   
00091   if (argc>2)
00092     {
00093       /*Init parameters*/
00094       CreateFileName(NULL,arg[1],NULL,PARAM_EXT,&fparam);
00095       InitParametersFromFile(GetFileFullName(&fparam),&parameters);
00096 
00097       /*Read the problem from file*/
00098       CreateFileName(NULL,arg[1],NULL,CUIK_EXT,&fcuik);
00099       InitCuikSystemFromFile(&parameters,GetFileFullName(&fcuik),&cuiksystem);
00100       GetCSSystemVars(&systemVars,&cuiksystem);
00101 
00102       /*Read the simplified boxes*/
00103       CreateFileName(NULL,arg[2],NULL,SOL_EXT,&fsolsimp);
00104       if (!ReadListOfBoxes(GetFileFullName(&fsolsimp),&(solutions)))
00105         Error("Solution file can not be opened");
00106         
00107       
00108       /*Save the un-simplified boxes*/
00109       CreateFileName(NULL,arg[1],NULL,SOL_EXT,&fsol);
00110       fs=fopen(GetFileFullName(&fsol),"w");
00111       if (!fs)
00112         Error("Could not open the output file for the un-simplified boxes.");
00113       InitIterator(&it,&solutions);
00114       First(&it);
00115       while(!EndOfList(&it))
00116         {
00117           ReGenerateOriginalBox(&parameters,(Tbox *)GetCurrent(&it),&boxO,&cuiksystem);
00118           PrintBoxSubset(fs,systemVars,NULL,&boxO);
00119           DeleteBox(&boxO);
00120           Advance(&it);
00121         }
00122       fclose(fs);
00123       
00124       /*Remove the allocated objects*/
00125       DeleteListOfBoxes(&solutions);
00126       DeleteParameters(&parameters);
00127       DeleteCuikSystem(&cuiksystem);
00128 
00129       DeleteFileName(&fparam);
00130       DeleteFileName(&fcuik);
00131       DeleteFileName(&fsol);
00132       DeleteFileName(&fsolsimp);
00133       free(systemVars);
00134     }
00135  else
00136    {
00137      fprintf(stderr,"  Wrong number of parameters.\n");
00138      fprintf(stderr,"  Use:\n");   
00139      fprintf(stderr,"      cuikunsimplify <problem filename>.cuik  <solution filename>.sol\n");
00140      fprintf(stderr,"  where <problem filename> contains the original kinematic equations\n");
00141      fprintf(stderr,"        <solution filename> contains the solutions for the simplified system\n");
00142      fprintf(stderr,"    (the '.cuik' and '.sol' extensions are not required)\n");
00143    }
00144   return(EXIT_SUCCESS);
00145 }
00146