cuikworldaxes.c
Go to the documentation of this file.
1 #include "world.h"
2 #include "error.h"
3 
4 
53 int main(int argc, char **arg)
54 {
55 
56  if (argc>2)
57  {
58  Tworld world;
59  Tparameters parameters;
60 
61  Tbox box;
62  int token;
63  unsigned int nvs;
64 
65  Tfilename faxes;
66  Tfilename fsols;
67  Tfilename fparam;
68 
69  FILE *fin,*fout;
70 
71  CreateFileName(NULL,arg[1],NULL,PARAM_EXT,&fparam);
72  fprintf(stderr,"Reading parameter file : %s\n",GetFileFullName(&fparam));
73  InitParametersFromFile(GetFileFullName(&fparam),&parameters);
74 
75  InitWorldFromFile(&parameters,TRUE,arg[1],&world);
76 
77  nvs=GetWorldNumSystemVariables(&world);
78 
79  CreateFileName(NULL,arg[2],NULL,SOL_EXT,&fsols);
80  fprintf(stderr,"Reading solution file : %s\n",GetFileFullName(&fsols));
81  fin=fopen(GetFileFullName(&fsols),"r");
82  if (!fin)
83  Error("The file with the solution boxes can not be opened");
84 
85  CreateFileName(NULL,arg[2],NULL,AXES_EXT,&faxes);
86  fprintf(stderr,"Writing axes file : %s\n",GetFileFullName(&faxes));
87  fout=fopen(GetFileFullName(&faxes),"w");
88  if (!fout)
89  Error("The file for the axes can not be opened");
90 
91  do {
92  token=ReadBox(fin,&box);
93  if (token!=EOF)
94  {
95  if (nvs>GetBoxNIntervals(&box))
96  Error("Box size missmatch");
97  PrintWorldAxes(&parameters,fout,&box,&world);
98  DeleteBox(&box);
99  }
100  } while(token!=EOF);
101 
102  fclose(fin);
103  fclose(fout);
104 
105  DeleteFileName(&faxes);
106  DeleteFileName(&fsols);
107  DeleteFileName(&fparam);
108 
109  DeleteWorld(&world);
110  DeleteParameters(&parameters);
111  }
112  else
113  {
114  fprintf(stdout," Wrong number of parameters.\n");
115  fprintf(stdout," Use:\n");
116  fprintf(stdout," cuikworldaxes <world>.world <solutions>.sol\n");
117  fprintf(stdout," Where:\n");
118  fprintf(stdout," <world>: File describing the problem\n");
119  fprintf(stdout," <solutions>: Solutions for which to extract the axes.\n");
120  fprintf(stdout," File extensions are not required\n");
121  }
122 
123  return(EXIT_SUCCESS);
124 }
Data structure to hold the information about the name of a file.
Definition: filename.h:271
#define TRUE
TRUE.
Definition: boolean.h:21
void PrintWorldAxes(Tparameters *pr, FILE *f, Tbox *b, Tworld *w)
Prints the axes of the mechanism.
Definition: world.c:3637
void Error(const char *s)
General error function.
Definition: error.c:80
unsigned int GetWorldNumSystemVariables(Tworld *w)
Number of system variables in the kinematic subsystem.
Definition: world.c:3297
#define PARAM_EXT
File extension for parameter files.
Definition: filename.h:132
All the necessary information to generate equations for mechanisms.
Definition: world.h:229
Definition of the Tworld type and the associated functions.
void DeleteWorld(Tworld *w)
Destructor.
Definition: world.c:3952
unsigned int GetBoxNIntervals(Tbox *b)
Box dimensionality.
Definition: box.c:1016
Error and warning functions.
void DeleteFileName(Tfilename *fn)
Destructor.
Definition: filename.c:205
int ReadBox(FILE *f, Tbox *b)
Reads a box from a file.
Definition: box.c:1196
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
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
boolean InitWorldFromFile(Tparameters *p, boolean error, char *fn, Tworld *w)
Constructor.
A box.
Definition: box.h:83
void DeleteParameters(Tparameters *p)
Destructor.
Definition: parameters.c:294
void DeleteBox(void *b)
Destructor.
Definition: box.c:1283
#define AXES_EXT
File extension for the mechanism axes.
Definition: filename.h:150
int main(int argc, char **arg)
Main body of the cuikworldaxes application.
Definition: cuikworldaxes.c:53