cuikaddjacobian.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 
102 int main(int argc, char **arg)
103 {
104  Tparameters parameters; /* Parameters */
105  TCuikSystem cuik; /* The cuiksystem to enrich with the Jacobian equations*/
106 
107  Tfilename fparam;
108  Tfilename fcuik;
109  Tfilename fcuikOut;
110 
111  FILE *f;
112  boolean *selectedVars;
113  unsigned int i,nv,vID;
114 
115  if (argc>1)
116  {
117  /*Init parameters*/
118  CreateFileName(NULL,arg[1],NULL,PARAM_EXT,&fparam);
119  #if (_DEBUG>0)
120  printf("Reading parameter file : %s\n",GetFileFullName(&fparam));
121  #endif
122  InitParametersFromFile(GetFileFullName(&fparam),&parameters);
123 
124  /*Init cuik*/
125  CreateFileName(NULL,arg[1],NULL,CUIK_EXT,&fcuik);
126  #if (_DEBUG>0)
127  printf("Reading .cuik file : %s\n",GetFileFullName(&fcuik));
128  #endif
129  /*Read the cuik file*/
130  InitCuikSystemFromFile(&parameters,GetFileFullName(&fcuik),&cuik);
131 
132  /*determine the variables*/
133  nv=GetCSNumVariables(&cuik);
134 
135  if (argc>2)
136  {
137  NEW(selectedVars,nv,boolean);
138  /*in principle all variables are to be used in the Jacobian*/
139  for(i=0;i<nv;i++)
140  selectedVars[i]=TRUE;
141  /*but we exclude those given by the user*/
142  for(i=2;i<(unsigned int)argc;i++)
143  {
144  vID=GetCSVariableID(arg[i],&cuik);
145  if (vID==NO_UINT)
146  fprintf(stderr,"ERROR: Variable %s is not included in the cuiksystem\n",arg[i]);
147  else
148  {
149  fprintf(stderr," Focusing on variable : %s (%u)\n",arg[i],vID);
150  selectedVars[vID]=FALSE;
151  }
152  }
153  }
154  else
155  selectedVars=NULL;
156 
157  /*Add singularity equations*/
158  AddJacobianEquations(&parameters,selectedVars,&cuik);
159 
160  /*Print resulting extended cuiksystem*/
161  CreateFileName(NULL,arg[1],"_J",CUIK_EXT,&fcuikOut);
162 
163  f=fopen(GetFileFullName(&fcuikOut),"w");
164  if (!f)
165  Error("Could not open output file in cuikaddjacobian");
166  #if (_DEBUG>0)
167  printf("Generating the _J.cuik file: %s\n",GetFileFullName(&fcuikOut));
168  #endif
169  PrintCuikSystem(&parameters,f,&cuik);
170  fclose(f);
171 
172  /* link the parameter/joints/links files */
173  LinkFileNameWithExtension(arg[1],PARAM_EXT ,&fcuikOut);
174  LinkFileNameWithExtension(arg[1],JOINTS_EXT,&fcuikOut);
175  LinkFileNameWithExtension(arg[1],LINKS_EXT ,&fcuikOut);
176 
177  /* Delete the data structures */
178  if (selectedVars!=NULL)
179  free(selectedVars);
180  DeleteCuikSystem(&cuik);
181  DeleteParameters(&parameters);
182 
183  /* Delete the file names */
184  DeleteFileName(&fparam);
185  DeleteFileName(&fcuik);
186  DeleteFileName(&fcuikOut);
187  }
188  else
189  {
190  fprintf(stderr," Wrong number of parameters.\n");
191  fprintf(stderr," Use:\n");
192  fprintf(stderr," cuikaddjacobian <problem name> <varname1> <varname2> ...\n");
193  fprintf(stderr," where \n");
194  fprintf(stderr," <problem name> is the cuik file resulting from cuiksingequations\n");
195  fprintf(stderr," <varnames> is the list of variables of interest\n");
196  }
197 
198  return(EXIT_SUCCESS);
199 }
200