cuikTWS.c
Go to the documentation of this file.
1 #include "parameters.h"
2 #include "defines.h"
3 #include "world.h"
4 #include "error.h"
5 #include "filename.h"
6 
7 #include <stdlib.h>
8 #include <string.h>
9 #include <unistd.h>
10 
79 int main(int argc, char **arg)
80 {
81  Tparameters parameters; /* Parameters */
82  Tworld world; /* Environemtn and mechanisms */
83  TCuikSystem cs; /* The cuiksystem to generate*/
84 
85  Tfilename fparam;
86  Tfilename fcuik;
87 
88  FILE *f;
89 
90  if (argc>2)
91  {
92  /*Init parameters*/
93  CreateFileName(NULL,arg[1],NULL,PARAM_EXT,&fparam);
94  #if (_DEBUG>0)
95  printf("Reading parameter file : %s\n",GetFileFullName(&fparam));
96  #endif
97  InitParametersFromFile(GetFileFullName(&fparam),&parameters);
98 
99  /*keep equations in the original form*/
100  ChangeParameter(CT_DUMMIFY,0,&parameters);
101 
102  /*Read the world file*/
103  InitWorldFromFile(&parameters,FALSE,TRUE,arg[1],&world);
104 
105  /*Add TWS equations*/
106  GenerateWorldTWSEquations(&parameters,arg[2],&cs,&world);
107 
108  /*Print resulting extended cuiksystem*/
109  CreateFileName(NULL,arg[1],"_TWS",CUIK_EXT,&fcuik);
110 
111  f=fopen(GetFileFullName(&fcuik),"w");
112  if (!f)
113  Error("Could not open output file in cuiksingequations");
114  #if (_DEBUG>0)
115  printf("Generating the _TWS.cuik file : %s\n",GetFileFullName(&fcuik));
116  #endif
117  PrintCuikSystemWithSimplification(&parameters,f,&cs);
118  fclose(f);
119 
120  /* link the parameter/joints/links files */
121  LinkFileNameWithExtension(arg[1],PARAM_EXT ,&fcuik);
122  LinkFileNameWithExtension(arg[1],JOINTS_EXT,&fcuik);
123  LinkFileNameWithExtension(arg[1],LINKS_EXT ,&fcuik);
124 
125  /* Delete the data structures */
126  DeleteCuikSystem(&cs);
127  DeleteParameters(&parameters);
128 
129  /* Delete the file names */
130  DeleteFileName(&fparam);
131  DeleteFileName(&fcuik);
132  }
133  else
134  {
135  fprintf(stderr," Wrong number of parameters.\n");
136  fprintf(stderr," Use:\n");
137  fprintf(stderr," cuikTWS <Sing> <problem name>\n");
138  fprintf(stderr," where \n");
139  fprintf(stderr," <problem name> is the world file from which to generate the equations\n");
140  fprintf(stderr," <Sing> It must be the name of the link to focus\n");
141  }
142 
143  return(EXIT_SUCCESS);
144 }
145