cuikxdot.c
Go to the documentation of this file.
1 #include "world.h"
2 #include "dynamics.h"
3 #include "error.h"
4 
5 #include <math.h>
6 
56 int main(int argc, char **arg)
57 {
58 
59  if (argc>2)
60  {
61  TAtlasBase w;
62  Tworld *world;
63  Tparameters parameters;
64 
65  TDynamicSpace ds;
66  double *u;
67  double *point,*spoint;
68  double *acc;
69  unsigned int sz,ns,j,n,k,ndof,nBoxes;
70  Tlist boxList;
71  Tbox *box;
72  Titerator i;
73  TJacobian sJ;
74 
75  FILE *fout;
76 
77  Tfilename facc;
78  Tfilename fsols;
79  Tfilename fparam;
80 
81  CreateFileName(NULL,arg[1],NULL,PARAM_EXT,&fparam);
82  fprintf(stderr,"Reading parameter file : %s\n",GetFileFullName(&fparam));
83  InitParametersFromFile(GetFileFullName(&fparam),&parameters);
84 
85  if (GetParameter(CT_DYNAMICS,&parameters)<0.5)
86  Error("cuikxdot requires the dynamics");
87 
88  ndof=GetParameter(CT_N_DOF,&parameters);
89  if (ndof%2)
90  Error("The degrees of freedom must be even");
91  ndof/=2;
92  if (argc-2<(int)ndof)
93  Error("Not enough input parameters to define an action");
94  NEW(u,ndof,double);
95  for(j=0;j<ndof;j++)
96  u[j]=atof(arg[j+2]);
97 
98  InitCSWDFromFile(&parameters,arg[1],&w);
99  world=GET_WORLD(&w);
100 
101  CS_WD_GET_SIMP_JACOBIAN(&parameters,&sJ,&w);
102  InitDynamicSpace(&parameters,FALSE,&sJ,&w,&ds);
103 
104  CreateFileName(NULL,arg[2],NULL,SOL_EXT,&fsols);
105  fprintf(stderr,"Reading solution file : %s\n",GetFileFullName(&fsols));
106  ReadListOfBoxes(GetFileFullName(&fsols),&boxList);
107  nBoxes=ListSize(&boxList);
108  if (nBoxes==0)
109  Error("Empty solution file");
110 
111  CreateFileName(NULL,arg[2],"_dot",SOL_EXT,&facc);
112  fprintf(stderr,"Writing acceleration file : %s\n",GetFileFullName(&facc));
113 
114  fout=fopen(GetFileFullName(&facc),"w");
115  if (!fout)
116  Error("Output file for accelerations can not be opened");
117 
118  /* Compute the energy for each conformation */
119  InitIterator(&i,&boxList);
120  First(&i);
121  k=0;
122  while(!EndOfList(&i))
123  {
124  box=(Tbox *)GetCurrent(&i);
125  if (k==0)
126  {
127  n=GetBoxNIntervals(box);
128  NEW(point,n,double);
129  NEW(acc,n,double); /* The size of acc is always less than n (less due to possible simplifications) */
130  }
131  GetBoxCenter(NULL,point,box);
132 
133  ns=WorldGenerateSimplifiedPointFromSystem(&parameters,point,&spoint,world);
134 
135  sz=Getxdot(&parameters,spoint,u,acc,&ds);
136 
137  if (ns!=sz)
138  Error("xdot size missmatch");
139 
140  PrintVector(fout,"",sz,acc);
141 
142  free(spoint);
143 
144  k++;
145  Advance(&i);
146  }
147 
148  fclose(fout);
149 
150  DeleteFileName(&fsols);
151  DeleteFileName(&facc);
152  DeleteFileName(&fparam);
153 
154  free(acc);
155  free(u);
156  free(point);
157  DeleteListOfBoxes(&boxList);
158  DeleteParameters(&parameters);
159 
160  DeleteFileName(&facc);
161  DeleteFileName(&fsols);
162  DeleteFileName(&fparam);
163 
164  DeleteDynamicSpace(&ds);
165  DeleteJacobian(&sJ);
166  CS_WD_DELETE(&w);
167  DeleteParameters(&parameters);
168  }
169  else
170  {
171  fprintf(stdout," Wrong number of parameters.\n");
172  fprintf(stdout," Use:\n");
173  fprintf(stdout," cuikxdot <world>.world <solutions>.sol <action>\n");
174  fprintf(stdout," Where:\n");
175  fprintf(stdout," <world>: File describing the problem\n");
176  fprintf(stdout," <solutions>: Solutions for which to extract the acceleratinos.\n");
177  fprintf(stdout," action: Action for which to compute the acceleration\n");
178  fprintf(stdout," File extensions are not required\n");
179  }
180 
181  return(EXIT_SUCCESS);
182 }