cuiksamples2sols.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 
69 int main(int argc, char **arg)
70 {
71  if (argc>1)
72  {
73  Tparameters parameters;
74  TAtlasBase wcs;
75 
76  Tfilename fparam;
77  Tfilename fsamples;
78  Tfilename fboxes;
79  FILE *fs,*fb;
80 
81  boolean *sv;
82  unsigned int i,nv,nvs;
83  double s;
84  Tbox b;
85  Tinterval r;
86 
87  double epsilon;
88 
89  boolean end;
90  int token;
91 
92  unsigned int rep;
93 
94  /*Init parameters*/
95  CreateFileName(NULL,arg[1],NULL,PARAM_EXT,&fparam);
96  fprintf(stderr,"Reading parameters : %s\n",GetFileFullName(&fparam));
97  InitParametersFromFile(GetFileFullName(&fparam),&parameters);
98 
99  epsilon=GetParameter(CT_EPSILON,&parameters);
100 
101  /* Read the problem file (cuik or world) */
102  InitCSWDFromFile(&parameters,arg[1],&wcs);
103  nv=CS_WD_GET_SYSTEM_VARS(&sv,&wcs);
104 
105  nvs=0;
106  for(i=0;i<nv;i++)
107  {
108  if (sv[i])
109  nvs++;
110  }
111  free(sv);
112 
113  /* Open the the sample file */
114  rep=(unsigned int)(GetParameter(CT_REPRESENTATION,&parameters));
115  if (rep==REP_JOINTS)
116  CreateFileName(NULL,arg[1],NULL,JOINTS_EXT,&fsamples);
117  else
118  CreateFileName(NULL,arg[1],NULL,LINKS_EXT,&fsamples);
119  fprintf(stderr,"Reading samples from : %s\n",GetFileFullName(&fsamples));
120  fs=fopen(GetFileFullName(&fsamples),"r");
121  if (!fs)
122  Error("Could not open the file with the samples");
123 
124  /* Create the box file */
125  if (argc>2)
126  CreateFileName(NULL,arg[2],NULL,SOL_EXT,&fboxes);
127  else
128  CreateFileName(NULL,arg[1],"_samples",SOL_EXT,&fboxes);
129  fprintf(stderr,"Writing solutions to : %s\n",GetFileFullName(&fboxes));
130  fb=fopen(GetFileFullName(&fboxes),"w");
131  if (!fb)
132  Error("Could no open the file to store the solutions");
133 
134  InitBox(nvs,NULL,&b);
135 
136  end=FALSE;
137  do {
138  token=fscanf(fs,"%lf",&s);
139  if ((token==EOF)||(token==0))
140  end=TRUE;
141  else
142  {
143  NewInterval(s-epsilon,s+epsilon,&r);
144  SetBoxInterval(0,&r,&b);
145 
146  for(i=1;i<nvs;i++)
147  {
148  if (fscanf(fs,"%lf",&s)==EOF)
149  Error("Not enough values in the sample");
150 
151  NewInterval(s-epsilon,s+epsilon,&r);
152  SetBoxInterval(i,&r,&b);
153  }
154  PrintBox(fb,&b);
155  }
156  } while (!end);
157 
158  DeleteBox(&b);
159 
160  fclose(fs);
161  DeleteFileName(&fsamples);
162 
163  fclose(fb);
164  DeleteFileName(&fboxes);
165 
166  CS_WD_DELETE(&wcs);
167  DeleteParameters(&parameters);
168 
169  DeleteFileName(&fparam);
170  }
171  else
172  {
173  fprintf(stderr,"Use:\n");
174  fprintf(stderr," cuiksamples2sols <problem_name> [<sol_file>]\n");
175  fprintf(stderr," <problem_name> the name from which to define the .world,\n");
176  fprintf(stderr," <sol_name> [optional] file where to store the solutions\n");
177  fprintf(stderr," if not given they are stored in <problem_name>_samples.sols\n");
178  }
179 
180  return(EXIT_SUCCESS);
181 }
#define REP_JOINTS
One of the possible values of the REPRESENTATION parameter.
Definition: parameters.h:60
int main(int argc, char **arg)
Main body of the cuiksamples2sols application.
#define CT_EPSILON
Numerical tolerance.
Definition: parameters.h:194
#define FALSE
FALSE.
Definition: boolean.h:30
Data structure to hold the information about the name of a file.
Definition: filename.h:271
void SetBoxInterval(unsigned int n, Tinterval *is, Tbox *b)
Replaces a particular interval in a box.
Definition: box.c:259
Definition of the Tfilename type and the associated functions.
#define TRUE
TRUE.
Definition: boolean.h:21
void InitBox(unsigned int dim, Tinterval *is, Tbox *b)
Initializes a box.
Definition: box.c:23
void Error(const char *s)
General error function.
Definition: error.c:80
#define PARAM_EXT
File extension for parameter files.
Definition: filename.h:132
#define CS_WD_DELETE(wcs)
Destructor of the equation structure.
Definition: wcs.h:592
void InitCSWDFromFile(Tparameters *pr, char *name, TAtlasBase *wcs)
Initializes a world or a CuikSystem structre.
Definition: chart.c:618
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.
#define CS_WD_GET_SYSTEM_VARS(sv, wcs)
Gets the system variables.
Definition: wcs.h:238
char * GetFileFullName(Tfilename *fn)
Gets the file full name (paht+name+extension).
Definition: filename.c:151
#define SOL_EXT
File extension for solution files.
Definition: filename.h:138
#define CT_REPRESENTATION
Representation.
Definition: parameters.h:215
A box.
Definition: box.h:83
#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
void DeleteBox(void *b)
Destructor.
Definition: box.c:1283
double GetParameter(unsigned int n, Tparameters *p)
Gets the value for a particular parameter.
Definition: parameters.c:93
void NewInterval(double lower, double upper, Tinterval *i)
Constructor.
Definition: interval.c:47
Definition of basic randomization functions.
void PrintBox(FILE *f, Tbox *b)
Prints a box.
Definition: box.c:1142
Defines a interval.
Definition: interval.h:33
#define LINKS_EXT
File extension for files with samples represented by the link poses.
Definition: filename.h:181