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

The CuikSuite Project

cuiksimplify.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 "filename.h"
00008 
00009 #include <string.h>
00010 #include <stdlib.h>
00011 #include <time.h>
00012 #include <unistd.h>
00013 
00014 
00051 int main(int argc, char **arg)
00052 {
00053   TCuikSystem cuiksystem;  /* The set of equations */
00054   Tparameters parameters;  /* Parameters used in the Cuik process */
00055 
00056   Tfilename fcuik;
00057   Tfilename fcuiksimp;
00058   Tfilename fparam;
00059   Tfilename fparamsimp;
00060   
00061   FILE *fs;
00062   
00063   if (argc>1)
00064     {
00065      
00066       /*Init parameters*/
00067       CreateFileName(NULL,arg[1],NULL,PARAM_EXT,&fparam);
00068       InitParametersFromFile(GetFileFullName(&fparam),&parameters);
00069 
00070       /*keep equations in the original form*/
00071       ChangeParameter(CT_DUMMIFY,0,&parameters);
00072 
00073       /*Read the problem from file*/
00074       CreateFileName(NULL,arg[1],NULL,CUIK_EXT,&fcuik);
00075       InitCuikSystemFromFile(&parameters,GetFileFullName(&fcuik),&cuiksystem);
00076 
00077       /*Save the simplified system (with a header with the human readable 
00078         simplification)*/
00079       CreateFileName(NULL,arg[1],"_simp",CUIK_EXT,&fcuiksimp);
00080       fs=fopen(GetFileFullName(&fcuiksimp),"w");
00081       if (!fs)
00082         Error("Could not open the output file for the simplified cuiksystem.");
00083       PrintCuikSystemWithSimplification(&parameters,fs,&cuiksystem);
00084       fclose(fs);
00085 
00086       /*symlink the parameter file*/
00087       CreateFileName(NULL,arg[1],"_simp",PARAM_EXT,&fparamsimp);
00088       symlink(GetFileFullName(&fparam),GetFileFullName(&fparamsimp));
00089 
00090       /*Remove the allocated objects*/
00091       DeleteParameters(&parameters);
00092       DeleteCuikSystem(&cuiksystem);
00093 
00094       DeleteFileName(&fparam);
00095       DeleteFileName(&fparamsimp);
00096       DeleteFileName(&fcuik);
00097       DeleteFileName(&fcuiksimp);
00098 
00099     }
00100  else
00101    {
00102      fprintf(stderr,"  Wrong number of parameters.\n");
00103      fprintf(stderr,"  Use:\n");   
00104      fprintf(stderr,"      cuiksimplify <problem filename>.cuik \n");
00105      fprintf(stderr,"  where <problem filename> contains the kinematic equations\n");
00106      fprintf(stderr,"    (the '.cuik' extension is not required)\n");
00107    }
00108   return(EXIT_SUCCESS);
00109 }
00110