cuikME.c
Go to the documentation of this file.
1 #include "world.h"
2 #include "parameters.h"
3 
4 #include "defines.h"
5 #include "error.h"
6 #include "filename.h"
7 #include "dynamics.h"
8 #include "samples.h"
9 
10 #include <stdlib.h>
11 
56 int main(int argc, char **arg)
57 {
58  TAtlasBase world; /* The set of mechanism and obstacles. */
59  Tparameters parameters; /* Parameters used in the Cuik process. */
60 
61  Tfilename fparam;
62  Tfilename ftraj;
63  Tfilename fme;
64 
65  FILE *fout;
66 
67  unsigned int i;
68  double t,pe,ke;
69 
70  /* input path */
71  unsigned int nvs,ns;
72  double **path;
73  double **action;
74  unsigned int da;
75  double *time;
76 
77  TDynamicSpace dynamicSpace;
78  TJacobian sJ;
79 
80  if (argc>=2)
81  {
82  /*Init parameters*/
83  CreateFileName(NULL,arg[1],NULL,PARAM_EXT,&fparam);
84  InitParametersFromFile(GetFileFullName(&fparam),&parameters);
85  fprintf(stderr,"Reading parameters from : %s\n",GetFileFullName(&fparam));
86 
87  if (GetParameter(CT_DYNAMICS,&parameters)<0.5)
88  Error("CuikME only works on problems with dynamics");
89 
90  /*Read the world from file*/
91  CS_WD_INIT(&parameters,arg[1],&world);
92 
93  if (ON_CUIKSYSTEM(&world))
94  Error("cuikME can not operate on cuiksystems (only on worlds)");
95 
96  if (argc>2)
97  CreateFileName(NULL,arg[2],NULL,SOL_EXT,&ftraj);
98  else
99  CreateFileName(NULL,arg[1],"_traj",SOL_EXT,&ftraj);
100 
101  if (LoadTrajectory(&ftraj,&nvs,&ns,&path,&da,&action,&time))
102  {
103  if (argc>2)
104  CreateFileName(NULL,arg[2],NULL,ENERGY_EXT,&fme);
105  else
106  CreateFileName(NULL,arg[1],NULL,ENERGY_EXT,&fme);
107 
108  fprintf(stderr,"Writing energy file : %s\n",GetFileFullName(&fme));
109 
110  fout=fopen(GetFileFullName(&fme),"w");
111  if (!fout)
112  Error("Output file for energies can not be opened");
113 
114  /* Initialize the dynamic space */
115  CS_WD_GET_SIMP_JACOBIAN(&parameters,&sJ,&world);
116  InitDynamicSpace(&parameters,FALSE,&sJ,&world,&dynamicSpace);
117 
118  t=0;
119  for(i=0;i<ns;i++)
120  {
121  t+=time[i];
122  MechEnergy(&parameters,path[i],&pe,&ke,&dynamicSpace);
123  fprintf(fout,"%f %.12f %.12f %.12f\n",t,pe,ke,pe+ke);
124  }
125 
126  fclose(fout);
127 
128  DeleteJacobian(&sJ);
129  DeleteDynamicSpace(&dynamicSpace);
130  DeleteTrajectory(ns,path,action,time);
131  }
132  else
133  Error("Could not read the input trajectory file");
134 
135 
136  DeleteParameters(&parameters);
137  CS_WD_DELETE(&world);
138 
139  DeleteFileName(&fparam);
140  DeleteFileName(&ftraj);
141  DeleteFileName(&fme);
142  }
143  else
144  {
145  fprintf(stderr," Wrong number of parameters.\n");
146  fprintf(stderr," Use:\n");
147  fprintf(stderr," cuikME <base filename> [<path file>]\n");
148  fprintf(stderr," where <base filename> is used for the parameters, world, and path files.\n");
149  fprintf(stderr," <path file> [optional] is the file with the path.\n");
150  }
151  return(EXIT_SUCCESS);
152 }
153