cuiksols2samples.c
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"
8 
9 
10 #include <stdio.h>
11 
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;
79 
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);
86 
87  if (argc>2)
88  fn=arg[2];
89  else
90  fn=arg[1];
91 
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");
97 
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");
107 
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);
114 
115  DeleteSample(&s);
116  DeleteBox(&box);
117  }
118  } while(token!=EOF);
119 
120  fclose(fout);
121 
122  DeleteFileName(&fsols);
123  DeleteFileName(&fsamples);
124  DeleteFileName(&fparam);
125 
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>.links or <sol_name>.dof is used (depending on the problem parameters).\n");
135  }
136 
137  return(EXIT_SUCCESS);
138 }