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 
64  Tfilename faxes;
65  Tfilename fsols;
66  Tfilename fparam;
67  Tfilename fworld;
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  CreateFileName(NULL,arg[1],NULL,WORLD_EXT,&fworld);
76  fprintf(stderr,"Reading world file : %s\n",GetFileFullName(&fworld));
77  InitWorldFromFile(&parameters,&fworld,&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,"Writting 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  PrintWorldAxes(&parameters,fout,&box,&world);
96  DeleteBox(&box);
97  }
98  } while(token!=EOF);
99 
100  fclose(fin);
101  fclose(fout);
102 
103  DeleteFileName(&faxes);
104  DeleteFileName(&fsols);
105  DeleteFileName(&fworld);
106  DeleteFileName(&fparam);
107 
108  DeleteWorld(&world);
109  DeleteParameters(&parameters);
110  }
111  else
112  {
113  fprintf(stdout," Wrong number of parameters.\n");
114  fprintf(stdout," Use:\n");
115  fprintf(stdout," cuikworldaxes <world>.world <solutions>.sol\n");
116  fprintf(stdout," Where:\n");
117  fprintf(stdout," <world>: File describing the problem\n");
118  fprintf(stdout," <solutions>: Solutions for which to extract the axes.\n");
119  fprintf(stdout," File extensions are not required\n");
120  }
121 
122  return(EXIT_SUCCESS);
123 }
Data structure to hold the information about the name of a file.
Definition: filename.h:248
void InitWorldFromFile(Tparameters *p, Tfilename *f, Tworld *w)
Constructor.
void PrintWorldAxes(Tparameters *pr, FILE *f, Tbox *b, Tworld *w)
Prints the axes of the mechanism.
Definition: world.c:2455
void Error(const char *s)
General error function.
Definition: error.c:80
#define PARAM_EXT
File extension for parameter files.
Definition: filename.h:131
All the necessary information to generate equations for mechanisms.
Definition: world.h:124
Definition of the Tworld type and the associated functions.
void DeleteWorld(Tworld *w)
Destructor.
Definition: world.c:2792
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:1172
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:137
A box.
Definition: box.h:83
#define WORLD_EXT
File extension for problem files.
Definition: filename.h:161
void DeleteParameters(Tparameters *p)
Destructor.
Definition: parameters.c:295
void DeleteBox(void *b)
Destructor.
Definition: box.c:1259
#define AXES_EXT
File extension for the mechanism axes.
Definition: filename.h:149
int main(int argc, char **arg)
Main body of the cuikworldaxes application.
Definition: cuikworldaxes.c:53