cuikmerge.c
Go to the documentation of this file.
1 
2 #include "cuiksystem.h"
3 #include "parameters.h"
4 
5 #include "defines.h"
6 #include "error.h"
7 #include "filename.h"
8 
9 #include <string.h>
10 #include <stdlib.h>
11 #include <time.h>
12 #include <unistd.h>
13 
14 
65 int main(int argc, char **arg)
66 {
67  TCuikSystem cuiksystem; /* The set of equations */
68  Tparameters parameters; /* Parameters used in the Cuik process */
69 
70  Tfilename fcuikIn;
71  Tfilename fcuikAdded;
72  Tfilename fcuikOut;
73  Tfilename fparam;
74 
75  int i;
76  FILE *fs;
77 
78  if (argc>2)
79  {
80  /*Init parameters*/
81  CreateFileName(NULL,arg[2],NULL,PARAM_EXT,&fparam);
82  #if (_DEBUG>0)
83  printf("Reading parameter file : %s\n",GetFileFullName(&fparam));
84  #endif
85  InitParametersFromFile(GetFileFullName(&fparam),&parameters);
86 
87  /* keep equations in the original form */
88  ChangeParameter(CT_DUMMIFY,0,&parameters);
89 
90  /* avoid the generation of velocity equations (if not present in the input file) */
91  ChangeParameter(CT_DYNAMICS,0,&parameters);
92 
93  /*Read the problem from file*/
94  CreateFileName(NULL,arg[2],NULL,CUIK_EXT,&fcuikIn);
95  #if (_DEBUG>0)
96  printf("Reading cuik file : %s\n",GetFileFullName(&fcuikIn));
97  #endif
98  InitCuikSystemFromFile(&parameters,GetFileFullName(&fcuikIn),&cuiksystem);
99 
100  for(i=3;i<argc;i++)
101  {
102  /*Read the problem from file*/
103  CreateFileName(NULL,arg[i],NULL,CUIK_EXT,&fcuikAdded);
104  #if (_DEBUG>0)
105  printf("Reading cuik file : %s\n",GetFileFullName(&fcuikAdded));
106  #endif
107  AddCuikSystemFromFile(&parameters,FALSE,NULL,GetFileFullName(&fcuikAdded),&cuiksystem);
108 
109  DeleteFileName(&fcuikAdded);
110  }
111 
112  /*Save the final cuiksystem */
113  CreateFileName(NULL,arg[2],arg[1],CUIK_EXT,&fcuikOut);
114  fs=fopen(GetFileFullName(&fcuikOut),"w");
115  if (!fs)
116  Error("Could not open the output file for the merged cuiksystem.");
117  #if (_DEBUG>0)
118  printf("Generating merged cuik file : %s\n",GetFileFullName(&fcuikOut));
119  #endif
120  PrintCuikSystem(&parameters,fs,&cuiksystem);
121  fclose(fs);
122 
123  /* link the parameter files (after the merge joints/links are no longer valid,
124  use cuikmerge boxes to address this issue) */
125  LinkFileNameWithExtension(arg[2],PARAM_EXT ,&fcuikOut);
126 
127  /*Remove the allocated objects*/
128  DeleteParameters(&parameters);
129  DeleteCuikSystem(&cuiksystem);
130 
131  DeleteFileName(&fparam);
132  DeleteFileName(&fcuikIn);
133  DeleteFileName(&fcuikOut);
134  }
135  else
136  {
137  fprintf(stderr," Wrong number of parameters.\n");
138  fprintf(stderr," Use:\n");
139  fprintf(stderr," cuikmerge <suffx> <problem filenames>.cuik \n");
140  fprintf(stderr," where <problem filenames> contains the kinematic equations to merge\n");
141  fprintf(stderr," (the '.cuik' extension is not required)\n");
142  }
143  return(EXIT_SUCCESS);
144 }
145