cuikmergeboxes.c
Go to the documentation of this file.
1 
2 #include "cuiksystem.h"
3 #include "parameters.h"
4 
5 #include "defines.h"
6 #include "error.h"
7 #include "filename.h"
8 
9 #include <string.h>
10 #include <stdlib.h>
11 #include <time.h>
12 #include <unistd.h>
13 
14 
61 int main(int argc, char **arg)
62 {
63  Tbox bin,bout;
64 
65  Tfilename fsol;
66 
67  unsigned int i,n;
68  FILE **fs,*fout;
69  int token;
70 
71  if (argc>2)
72  {
73  n=argc-2;
74  NEW(fs,n,FILE *);
75 
76  for(i=0;i<n;i++)
77  {
78  CreateFileName(NULL,arg[2+i],NULL,SOL_EXT,&fsol);
79  #if (_DEBUG>0)
80  printf("Reading sol file : %s\n",GetFileFullName(&fsol));
81  #endif
82  fs[i]=fopen(GetFileFullName(&fsol),"r");
83  if (!fs[i])
84  Error("Sol file does not exists in cuikmergeboxes");
85  DeleteFileName(&fsol);
86  }
87 
88  CreateFileName(NULL,arg[2],arg[1],SOL_EXT,&fsol);
89  fout=fopen(GetFileFullName(&fsol),"w");
90  if (!fout)
91  Error("Could not open the output file for the merged cuiksystem.");
92  #if (_DEBUG>0)
93  printf("Generating merged sol file : %s\n",GetFileFullName(&fsol));
94  #endif
95  DeleteFileName(&fsol);
96 
97  token=~EOF;
98  while(token!=EOF)
99  {
100  i=0;
101  while((i<n)&&(token!=EOF))
102  {
103  token=ReadBox(fs[i],&bin);
104  if (token!=EOF)
105  {
106  if (i==0)
107  CopyBox(&bout,&bin);
108  else
109  MergeBoxes(&bout,&bin,&bout);
110  DeleteBox(&bin);
111  i++;
112  }
113  }
114  if (i==n)
115  PrintBox(fout,&bout);
116  if (i>0)
117  DeleteBox(&bout);
118  }
119 
120  for(i=0;i<n;i++)
121  fclose(fs[i]);
122  fclose(fout);
123  }
124  else
125  {
126  fprintf(stderr," Wrong number of parameters.\n");
127  fprintf(stderr," Use:\n");
128  fprintf(stderr," cuikmergeboxes <suffx> <problem filenames>.sol \n");
129  fprintf(stderr," where <problem filenames> contains the kinematic equations to merge\n");
130  fprintf(stderr," (the '.cuik' extension is not required)\n");
131  }
132  return(EXIT_SUCCESS);
133 }
134 
int main(int argc, char **arg)
Main body of the cuikmergeboxes application.
#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
Definition of the Tfilename type and the associated functions.
void Error(const char *s)
General error function.
Definition: error.c:80
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
Definitions of constants and macros used in several parts of the cuik library.
void CopyBox(void *b_out, void *b_in)
Box copy operator.
Definition: box.c:160
Definition of the TCuikSystem type and the associated functions.
void CreateFileName(char *path, char *name, char *suffix, char *ext, Tfilename *fn)
Constructor.
Definition: filename.c:22
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
void DeleteBox(void *b)
Destructor.
Definition: box.c:1259
void MergeBoxes(Tbox *b1, Tbox *b2, Tbox *bout)
Concats two boxes.
Definition: box.c:171
void PrintBox(FILE *f, Tbox *b)
Prints a box.
Definition: box.c:1118
Definition of the Tparameters type and the associated functions.