cuiksingequations.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 
86 int main(int argc, char **arg)
87 {
88  Tparameters parameters; /* Parameters */
89  Tworld world; /* Environemtn and mechanisms */
90  TCuikSystem cs; /* The cuiksystem to generate*/
91 
92  Tfilename fparam;
93  Tfilename fcuik;
94 
95  char *ln; /* link name */
96  char *pn; /* problem name */
97  FILE *f;
98 
99  if (argc>1)
100  {
101  if (argc>2)
102  {
103  ln=arg[1];
104  pn=arg[2];
105  }
106  else
107  {
108  ln=NULL;
109  pn=arg[1];
110  }
111 
112  /*Init parameters*/
113  CreateFileName(NULL,pn,NULL,PARAM_EXT,&fparam);
114  #if (_DEBUG>0)
115  printf("Reading parameter file : %s\n",GetFileFullName(&fparam));
116  #endif
117  InitParametersFromFile(GetFileFullName(&fparam),&parameters);
118 
119  /*Read the world file*/
120  InitWorldFromFile(&parameters,FALSE,TRUE,arg[1],&world);
121 
122  /*Add singularity equations*/
123  GenerateWorldSingularityEquations(&parameters,ln,&cs,&world);
124 
125  /*Print resulting extended cuiksystem*/
126  CreateFileName(NULL,pn,"_sing",CUIK_EXT,&fcuik);
127 
128  f=fopen(GetFileFullName(&fcuik),"w");
129  if (!f)
130  Error("Could not open output file in cuiksingequations");
131  #if (_DEBUG>0)
132  printf("Generating the _sin.cuik file: %s\n",GetFileFullName(&fcuik));
133  #endif
134  PrintCuikSystem(&parameters,f,&cs);
135  fclose(f);
136 
137  /* link the parameter/joints/links files */
138  LinkFileNameWithExtension(arg[1],PARAM_EXT ,&fcuik);
139  LinkFileNameWithExtension(arg[1],JOINTS_EXT,&fcuik);
140  LinkFileNameWithExtension(arg[1],LINKS_EXT ,&fcuik);
141 
142  /* Delete the data structures */
143  DeleteCuikSystem(&cs);
144  DeleteWorld(&world);
145  DeleteParameters(&parameters);
146 
147  /* Delete the file names */
148  DeleteFileName(&fparam);
149  DeleteFileName(&fcuik);
150  }
151  else
152  {
153  fprintf(stderr," Wrong number of parameters.\n");
154  fprintf(stderr," Use:\n");
155  fprintf(stderr," cuiksingequations <Sing> <problem name>\n");
156  fprintf(stderr," where \n");
157  fprintf(stderr," <Sing> [Optional] It must be the name of the link to focus\n");
158  fprintf(stderr," None for no particular link\n");
159  fprintf(stderr," <problem name> is the world file from which to generate the equations\n");
160  }
161 
162  return(EXIT_SUCCESS);
163 }
164