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  /*Init parameters*/
78  CreateFileName(NULL,arg[1],NULL,PARAM_EXT,&fparam);
79  fprintf(stderr,"Reading parameters : %s\n",GetFileFullName(&fparam));
80  InitParametersFromFile(GetFileFullName(&fparam),&parameters);
81 
82  /* Read the problem file (cuik or world) */
83  CS_WD_INIT(&parameters,arg[1],&wcs);
85  NEW(s,nv,double);
86 
87  /* Open the the sample file */
88  if (argc>2)
89  solName=arg[2];
90  else
91  solName=arg[1];
92  rep=(unsigned int)(GetParameter(CT_REPRESENTATION,&parameters));
93  if (rep==REP_JOINTS)
94  CreateFileName(NULL,solName,NULL,JOINTS_EXT,&fsamples);
95  else
96  CreateFileName(NULL,solName,NULL,LINKS_EXT,&fsamples);
97  fprintf(stderr,"Reading samples from : %s\n",GetFileFullName(&fsamples));
98  fs=fopen(GetFileFullName(&fsamples),"r");
99  if (!fs)
100  Error("Could not open the file with the samples");
101 
102  end=FALSE;
103  ns=1;
104  do {
105  token=fscanf(fs,"%lf",&(s[0]));
106  if ((token==EOF)||(token==0))
107  end=TRUE;
108  else
109  {
110  for(i=1;i<nv;i++)
111  {
112  if (fscanf(fs,"%lf",&(s)[i])==EOF)
113  Error("Not enough values in the sample");
114  }
115  CS_WD_REGENERATE_SOLUTION_POINT(&parameters,s,&fullS,&wcs);
116  fprintf(stderr," Error %u: %.16f\n",ns,CS_WD_ERROR_IN_EQUATIONS(fullS,&wcs));
117  free(fullS);
118  ns++;
119  }
120  } while (!end);
121 
122  free(s);
123  fclose(fs);
124  DeleteFileName(&fsamples);
125 
126  CS_WD_DELETE(&wcs);
127  DeleteParameters(&parameters);
128 
129  DeleteFileName(&fparam);
130  }
131  else
132  {
133  fprintf(stderr,"Use:\n");
134  fprintf(stderr," cuikerror <problem_name> [<sol_file>]\n");
135  fprintf(stderr," <problem_name> the name from which to define the .world,\n");
136  fprintf(stderr," <sol_name> [optional] file with the the solution points\n");
137  }
138 
139  return(EXIT_SUCCESS);
140 }
#define REP_JOINTS
One of the possible values of the REPRESENTATION parameter.
Definition: parameters.h:60
#define FALSE
FALSE.
Definition: boolean.h:30
#define NEW(_var, _n, _type)
Allocates memory space.
Definition: defines.h:385
Data structure to hold the information about the name of a file.
Definition: filename.h:271
#define CS_WD_ERROR_IN_EQUATIONS(p, wcs)
Computes the error for a given point.
Definition: wcs.h:525
Definition of the Tfilename type and the associated functions.
#define TRUE
TRUE.
Definition: boolean.h:21
void Error(const char *s)
General error function.
Definition: error.c:80
#define PARAM_EXT
File extension for parameter files.
Definition: filename.h:132
int main(int argc, char **arg)
Main body of the cuikerror application.
Definition: cuikerror.c:55
#define CS_WD_DELETE(wcs)
Destructor of the equation structure.
Definition: wcs.h:592
void DeleteFileName(Tfilename *fn)
Destructor.
Definition: filename.c:205
Definition of the Tbox type and the associated functions.
Definitions of constants and macros used in several parts of the cuik library.
A table of parameters.
void CreateFileName(char *path, char *name, char *suffix, char *ext, Tfilename *fn)
Constructor.
Definition: filename.c:22
void InitParametersFromFile(char *file, Tparameters *p)
Constructor from a file.
Definition: parameters.c:51
Type defining the equations on which the atlas is defined.
Definition: wcs.h:30
Definition of a local chart on a manifold.
char * GetFileFullName(Tfilename *fn)
Gets the file full name (paht+name+extension).
Definition: filename.c:151
#define CT_REPRESENTATION
Representation.
Definition: parameters.h:215
#define JOINTS_EXT
File extension for files with samples represented by the joint values.
Definition: filename.h:188
void DeleteParameters(Tparameters *p)
Destructor.
Definition: parameters.c:294
#define CS_WD_INIT(pr, name, wcs)
Initializes the equations from a file.
Definition: wcs.h:89
double GetParameter(unsigned int n, Tparameters *p)
Gets the value for a particular parameter.
Definition: parameters.c:93
#define CS_WD_REGENERATE_SOLUTION_POINT(pr, p, r, wcs)
Compleates a solution point with the dummy variables.
Definition: wcs.h:480
#define CS_WD_GET_NUM_SYSTEM_VARS(wcs)
Gets the number of system variables.
Definition: wcs.h:264
Definition of basic randomization functions.
#define LINKS_EXT
File extension for files with samples represented by the link poses.
Definition: filename.h:181