cuiksamples2rgroups.c
Go to the documentation of this file.
1 #include "defines.h"
2 #include "filename.h"
3 #include "world.h"
4 
5 #include <stdlib.h>
6 
89 int main(int argc, char **arg)
90 {
91  if (argc>1)
92  {
93  Tparameters parameters;
94  Tworld world;
95 
96  Tfilename fparam;
97  Tfilename fsamples;
98  Tfilename fworld;
99  Tfilename frgroups;
100 
101  boolean nv;
102  double *sample;
103 
104  char *fn;
105  FILE *fs;
106 
107  unsigned int i,r;
108  boolean end;
109  int token;
110 
111  FILE *fout;
112 
113  /* Init parameters */
114  CreateFileName(NULL,arg[1],NULL,PARAM_EXT,&fparam);
115  fprintf(stderr,"Reading parameters : %s\n",GetFileFullName(&fparam));
116 
117  InitParametersFromFile(GetFileFullName(&fparam),&parameters);
118 
119  /* Read the problem file */
120  CreateFileName(NULL,arg[1],NULL,WORLD_EXT,&fworld);
121  fprintf(stderr,"Reading world file : %s\n",GetFileFullName(&fworld));
122  InitWorldFromFile(&parameters,&fworld,&world);
123 
124  if (!IsMechanismInWorldAllSpheres(&world))
125  Warning("The world is not sphere-only");
126 
127  /* Open the file from where to read the samples */
128  r=(unsigned int)(GetParameter(CT_REPRESENTATION,&parameters));
129  if (r==REP_JOINTS)
130  CreateFileName(NULL,arg[1],NULL,JOINTS_EXT,&fsamples);
131  else
132  CreateFileName(NULL,arg[1],NULL,LINKS_EXT,&fsamples);
133 
134  fprintf(stderr,"Reading one sample from : %s\n",GetFileFullName(&fsamples));
135 
136  fs=fopen(GetFileFullName(&fsamples),"r");
137 
138  if (!fs)
139  Error("Could not open the file to read the samples");
140 
141  if (argc>2)
142  fn=arg[2];
143  else
144  fn=arg[1];
145 
146  /* Open the file where to store the bio-information */
147  CreateFileName(NULL,fn,NULL,RGROUPS_EXT,&frgroups);
148  fprintf(stderr,"Writing rigid groups to : %s\n",GetFileFullName(&frgroups));
149 
150  /* Allocate space for the sample/dof */
151  nv=GetWorldNumSystemVariables(&world);
152  NEW(sample,nv,double);
153 
154  /* Read one sample from the file of samples */
155  fout=fopen(GetFileFullName(&frgroups),"w");
156  if (!fout)
157  Error("Could not open the file to store the rigid groups");
158 
159  end=FALSE;
160  do {
161  for(i=0;((!end)&&(i<nv));i++)
162  {
163  token=fscanf(fs,"%lf",&(sample[i]));
164  if ((token==EOF)||(token==0))
165  end=TRUE;
166  }
167  /* If the sample could be read correctly, save the atom positions */
168  if (!end)
169  WorldStoreRigidGroups(&parameters,fout,sample,&world);
170  } while (!end);
171 
172  fclose(fout);
173 
174  /* Close the input file */
175  fclose(fs);
176 
177  /* Release memeory */
178  free(sample);
179  DeleteWorld(&world);
180  DeleteParameters(&parameters);
181 
182  DeleteFileName(&fparam);
183  DeleteFileName(&fworld);
184  DeleteFileName(&fsamples);
185  DeleteFileName(&frgroups);
186 
187  return(EXIT_SUCCESS);
188  }
189  else
190  {
191  fprintf(stderr,"Use:\n");
192  fprintf(stderr," cuiksamples2rgroups <problem_name> <out_name>\n");
193  fprintf(stderr," <problem_name> the prefix to define the world,\n");
194  fprintf(stderr," .params and .samples files.\n");
195  fprintf(stderr," <out_name> [optional] The output atom file.\n");
196 
197  return(EXIT_FAILURE);
198  }
199 }
#define REP_JOINTS
One of the possible values of the REPRESENTATION parameter.
Definition: parameters.h:60
#define FALSE
FALSE.
Definition: boolean.h:30
void WorldStoreRigidGroups(Tparameters *pr, FILE *f, double *pt, Tworld *w)
Generates a file with the atoms grouped in rigid clusters.
Definition: world.c:2318
#define NEW(_var, _n, _type)
Allocates memory space.
Definition: defines.h:385
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.
Definition of the Tfilename type and the associated functions.
#define TRUE
TRUE.
Definition: boolean.h:21
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:2158
#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
void DeleteFileName(Tfilename *fn)
Destructor.
Definition: filename.c:205
boolean IsMechanismInWorldAllSpheres(Tworld *w)
TRUE if the mechanisms in the world is based on spheres.
Definition: world.c:1432
Definitions of constants and macros used in several parts of the cuik library.
void Warning(const char *s)
General warning function.
Definition: error.c:116
A table of parameters.
void CreateFileName(char *path, char *name, char *suffix, char *ext, Tfilename *fn)
Constructor.
Definition: filename.c:22
int main(int argc, char **arg)
Main body of the cuiksamples2rgroups application.
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 CT_REPRESENTATION
Representation.
Definition: parameters.h:215
#define WORLD_EXT
File extension for problem files.
Definition: filename.h:161
#define JOINTS_EXT
File extension for files with samples represented by the joint values.
Definition: filename.h:187
void DeleteParameters(Tparameters *p)
Destructor.
Definition: parameters.c:295
double GetParameter(unsigned int n, Tparameters *p)
Gets the value for a particular parameter.
Definition: parameters.c:93
#define LINKS_EXT
File extension for files with samples represented by the link poses.
Definition: filename.h:180
#define RGROUPS_EXT
File extension for atom rigid groups.
Definition: filename.h:94