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 frgroups;
99 
100  boolean nv;
101  double *sample;
102 
103  char *fn;
104  FILE *fs;
105 
106  unsigned int i,r;
107  boolean end;
108  int token;
109 
110  FILE *fout;
111 
112  /* Init parameters */
113  CreateFileName(NULL,arg[1],NULL,PARAM_EXT,&fparam);
114  fprintf(stderr,"Reading parameters : %s\n",GetFileFullName(&fparam));
115 
116  InitParametersFromFile(GetFileFullName(&fparam),&parameters);
117 
118  /* Read the problem file */
119  InitWorldFromFile(&parameters,TRUE,arg[1],&world);
120 
121  if (!IsMechanismInWorldAllSpheres(&world))
122  Warning("The world is not sphere-only");
123 
124  /* Open the file from where to read the samples */
125  r=(unsigned int)(GetParameter(CT_REPRESENTATION,&parameters));
126  if (r==REP_JOINTS)
127  CreateFileName(NULL,arg[1],NULL,JOINTS_EXT,&fsamples);
128  else
129  CreateFileName(NULL,arg[1],NULL,LINKS_EXT,&fsamples);
130 
131  fprintf(stderr,"Reading one sample from : %s\n",GetFileFullName(&fsamples));
132 
133  fs=fopen(GetFileFullName(&fsamples),"r");
134 
135  if (!fs)
136  Error("Could not open the file to read the samples");
137 
138  if (argc>2)
139  fn=arg[2];
140  else
141  fn=arg[1];
142 
143  /* Open the file where to store the bio-information */
144  CreateFileName(NULL,fn,NULL,RGROUPS_EXT,&frgroups);
145  fprintf(stderr,"Writing rigid groups to : %s\n",GetFileFullName(&frgroups));
146 
147  /* Allocate space for the sample/dof */
148  nv=GetWorldNumSystemVariables(&world);
149  NEW(sample,nv,double);
150 
151  /* Read one sample from the file of samples */
152  fout=fopen(GetFileFullName(&frgroups),"w");
153  if (!fout)
154  Error("Could not open the file to store the rigid groups");
155 
156  end=FALSE;
157  do {
158  for(i=0;((!end)&&(i<nv));i++)
159  {
160  token=fscanf(fs,"%lf",&(sample[i]));
161  if ((token==EOF)||(token==0))
162  end=TRUE;
163  }
164  /* If the sample could be read correctly, save the atom positions */
165  if (!end)
166  WorldStoreRigidGroups(&parameters,fout,sample,&world);
167  } while (!end);
168 
169  fclose(fout);
170 
171  /* Close the input file */
172  fclose(fs);
173 
174  /* Release memeory */
175  free(sample);
176  DeleteWorld(&world);
177  DeleteParameters(&parameters);
178 
179  DeleteFileName(&fparam);
180  DeleteFileName(&fsamples);
181  DeleteFileName(&frgroups);
182 
183  return(EXIT_SUCCESS);
184  }
185  else
186  {
187  fprintf(stderr,"Use:\n");
188  fprintf(stderr," cuiksamples2rgroups <problem_name> <out_name>\n");
189  fprintf(stderr," <problem_name> the prefix to define the world,\n");
190  fprintf(stderr," .params and .samples files.\n");
191  fprintf(stderr," <out_name> [optional] The output atom file.\n");
192 
193  return(EXIT_FAILURE);
194  }
195 }
#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:3511
#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:271
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: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
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:1827
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
boolean InitWorldFromFile(Tparameters *p, boolean error, char *fn, Tworld *w)
Constructor.
#define JOINTS_EXT
File extension for files with samples represented by the joint values.
Definition: filename.h:188
void DeleteParameters(Tparameters *p)
Destructor.
Definition: parameters.c:294
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:181
#define RGROUPS_EXT
File extension for atom rigid groups.
Definition: filename.h:95