cuikerror.c
Go to the documentation of this file.
1 #include "box.h"
2 #include "random.h"
3 #include "defines.h"
4 #include "filename.h"
5 #include "chart.h"
6 
7 #include <stdlib.h>
8 
55 int main(int argc, char **arg)
56 {
57  if (argc>1)
58  {
59  Tparameters parameters;
60  TAtlasBase wcs;
61 
62  Tfilename fparam;
63  Tfilename fsamples;
64  FILE *fs;
65  char *solName;
66 
67  unsigned int i,nv;
68  double *s;
69 
70  boolean end;
71  int token;
72 
73  unsigned int rep;
74  unsigned int ns;
75  double *fullS;
76 
77  unsigned int ms;
78  double me,e;
79 
80  /*Init parameters*/
81  CreateFileName(NULL,arg[1],NULL,PARAM_EXT,&fparam);
82  fprintf(stderr,"Reading parameters : %s\n",GetFileFullName(&fparam));
83  InitParametersFromFile(GetFileFullName(&fparam),&parameters);
84 
85  /* Read the problem file (cuik or world) */
86  CS_WD_INIT(&parameters,arg[1],&wcs);
88 
89  NEW(s,nv,double);
90 
91  /* Open the the sample file */
92  if (argc>2)
93  solName=arg[2];
94  else
95  solName=arg[1];
96  rep=(unsigned int)(GetParameter(CT_REPRESENTATION,&parameters));
97  if (rep==REP_JOINTS)
98  CreateFileName(NULL,solName,NULL,JOINTS_EXT,&fsamples);
99  else
100  CreateFileName(NULL,solName,NULL,LINKS_EXT,&fsamples);
101  fprintf(stderr,"Reading samples from : %s\n",GetFileFullName(&fsamples));
102  fs=fopen(GetFileFullName(&fsamples),"r");
103  if (!fs)
104  Error("Could not open the file with the samples");
105 
106  end=FALSE;
107  ns=1;
108  me=0.0;
109  do {
110  token=fscanf(fs,"%lf",&(s[0]));
111  if ((token==EOF)||(token==0))
112  end=TRUE;
113  else
114  {
115  for(i=1;i<nv;i++)
116  {
117  if (fscanf(fs,"%lf",&(s)[i])==EOF)
118  Error("Not enough values in the sample");
119  }
120  CS_WD_REGENERATE_SOLUTION_POINT(&parameters,s,&fullS,&wcs);
121  e=CS_WD_ERROR_IN_EQUATIONS(&parameters,fullS,&wcs);
122  if (me<e)
123  {
124  me=e;
125  ms=ns;
126  }
127  fprintf(stderr," Error %u: %.16f\n",ns,e);
128  free(fullS);
129  ns++;
130  }
131  } while (!end);
132 
133  fprintf(stderr,"\n Maximum error %u: %.16f\n",ms,me);
134 
135  free(s);
136  fclose(fs);
137  DeleteFileName(&fsamples);
138 
139  CS_WD_DELETE(&wcs);
140  DeleteParameters(&parameters);
141 
142  DeleteFileName(&fparam);
143  }
144  else
145  {
146  fprintf(stderr,"Use:\n");
147  fprintf(stderr," cuikerror <problem_name> [<sol_file>]\n");
148  fprintf(stderr," <problem_name> the name from which to define the .world,\n");
149  fprintf(stderr," <sol_name> [optional] file with the the solution points\n");
150  }
151 
152  return(EXIT_SUCCESS);
153 }