Go to the documentation of this file.
1 #include "filename.h"
2 #include "box_list.h"
3 #include "sample.h"
4 #include "error.h"
5 #include "defines.h"
6 #include "parameters.h"
7 #include "link.h"
10 #include <stdio.h>
69 int main(int argc, char **arg)
70 {
71  Tparameters parameters;
72  Tfilename fparam,fsols,fsamples;
73  Tbox box;
74  FILE *fin,*fout;
75  Tsample s;
76  int token;
77  unsigned int rep;
78  char *fn;
80  if (argc>1)
81  {
82  /*Init parameters*/
83  CreateFileName(NULL,arg[1],NULL,PARAM_EXT,&fparam);
84  fprintf(stderr,"Reading parameters : %s\n",GetFileFullName(&fparam));
85  InitParametersFromFile(GetFileFullName(&fparam),&parameters);
87  if (argc>2)
88  fn=arg[2];
89  else
90  fn=arg[1];
92  CreateFileName(NULL,fn,NULL,SOL_EXT,&fsols);
93  fprintf(stderr,"Reading boxes file : %s\n",GetFileFullName(&fsols));
94  fin=fopen(GetFileFullName(&fsols),"r");
95  if (!fin)
96  Error("Input file with boxes can not be opened");
98  rep=(unsigned int)(GetParameter(CT_REPRESENTATION,&parameters));
99  if (rep==REP_JOINTS)
100  CreateFileName(NULL,fn,NULL,JOINTS_EXT,&fsamples);
101  else
102  CreateFileName(NULL,fn,NULL,LINKS_EXT,&fsamples);
103  fprintf(stderr,"Writing samples file : %s\n",GetFileFullName(&fsamples));
104  fout=fopen(GetFileFullName(&fsamples),"w");
105  if (!fout)
106  Error("Output file for samples can not be opened");
108  do {
109  token=ReadBox(fin,&box);
110  if (token!=EOF)
111  {
112  InitSampleFromBox(NO_UINT,NULL,&box,NO_UINT,&s);
113  PrintSample(fout,&s);
115  DeleteSample(&s);
116  DeleteBox(&box);
117  }
118  } while(token!=EOF);
120  fclose(fout);
122  DeleteFileName(&fsols);
123  DeleteFileName(&fsamples);
124  DeleteFileName(&fparam);
126  DeleteParameters(&parameters);
127  }
128  else
129  {
130  fprintf(stderr,"Use:\n");
131  fprintf(stderr," cuiksols2samples <sols_name> <samples_name> \n");
132  fprintf(stderr," <sols_name> the input .sol file.\n");
133  fprintf(stderr," <samples_name> [optional] the output file for the samples.\n");
134  fprintf(stderr," If not given <sol_nam>.samples is used.\n");
135  }
137  return(EXIT_SUCCESS);
138 }
A sample.
Definition: sample.h:38
#define REP_JOINTS
One of the possible values of the REPRESENTATION parameter.
Definition: parameters.h:60
Data structure to hold the information about the name of a file.
Definition: filename.h:248
void DeleteSample(void *s)
Definition: sample.c:164
int main(int argc, char **arg)
Main body of the cuiksols2samples application.
Definition of the Tfilename type and the associated functions.
void Error(const char *s)
General error function.
Definition: error.c:80
#define PARAM_EXT
File extension for parameter files.
Definition: filename.h:131
Collection of methods to work on Tlist of boxes.
Error and warning functions.
void DeleteFileName(Tfilename *fn)
Definition: filename.c:205
int ReadBox(FILE *f, Tbox *b)
Reads a box from a file.
Definition: box.c:1172
void InitSampleFromBox(unsigned int sID, boolean *systemVar, Tbox *b, unsigned int boxID, Tsample *s)
Definition: sample.c:29
void PrintSample(FILE *f, Tsample *s)
Prints a sample.
Definition: sample.c:126
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)
Definition: filename.c:22
void InitParametersFromFile(char *file, Tparameters *p)
Constructor from a file.
Definition: parameters.c:51
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:137
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:187
#define NO_UINT
Used to denote an identifier that has not been initialized.
Definition: defines.h:435
Definition of the Tsample type and the associated functions.
void DeleteParameters(Tparameters *p)
Definition: parameters.c:295
void DeleteBox(void *b)
Definition: box.c:1259
double GetParameter(unsigned int n, Tparameters *p)
Gets the value for a particular parameter.
Definition: parameters.c:93
Definition of the Tparameters type and the associated functions.
#define LINKS_EXT
File extension for files with samples represented by the link poses.
Definition: filename.h:180