cuikatan2.c
Go to the documentation of this file.
1 
2 #include "box.h"
3 
4 #include "defines.h"
5 #include "filename.h"
6 
7 #include <string.h>
8 
9 
62 int main(int argc, char **arg)
63 {
64  FILE *fileIn,*fileOut;
65  Tbox boxIn,boxOut;
66  Tinterval iAtan2;
67  unsigned int *map,*dimSin,*dimCos,nIn,nOut;
68  unsigned int k,l,t,na,nbox;
69  int token;
70  Tfilename fIn,fOut;
71  boolean found;
72 
73  if ((argc<4)||((argc%2)==0))
74  {
75  fprintf(stderr,"Use:\n");
76  fprintf(stderr," cuikatan2 <input_file> <dim_sin_1> <dim_cos_1> ... <dim_sin_n> <dim_cos_n> <output_file>\n");
77  fprintf(stderr," <input_file> the input .sol file\n");
78  fprintf(stderr," <dim_sin_i> <dim_cos_i> the sin/cos dimensions (numbered from 1)\n");
79  fprintf(stderr," <output_file> the .sol file to be generated\n");
80  }
81  else
82  {
83  CreateFileName(NULL,arg[1],NULL,SOL_EXT,&fIn);
84  CreateFileName(NULL,arg[argc-1],NULL,SOL_EXT,&fOut);
85 
86  fileIn=fopen(GetFileFullName(&fIn),"r");
87  if (!fileIn)
88  Error("Input file can not be opened");
89 
90  fileOut=fopen(GetFileFullName(&fOut),"w");
91  if (!fileOut)
92  Error("Output file can not be opened");
93 
94 
95  na=(argc-3)/2;
96  NEW(dimSin,na,unsigned int);
97  NEW(dimCos,na,unsigned int);
98 
99  for(k=0;k<na;k++)
100  {
101  dimSin[k]=(unsigned int)atoi(arg[2+2*k])-1;
102  dimCos[k]=(unsigned int)atoi(arg[3+2*k])-1;
103  }
104 
105  nbox=0;
106  do {
107  token=ReadBox(fileIn,&boxIn);
108  if (token!=EOF)
109  {
110  if (nbox==0)
111  {
112  nIn=GetBoxNIntervals(&boxIn);
113 
114  nOut=nIn-na;
115 
116  NEW(map,nOut-na,unsigned int);
117  l=0;
118  for(k=0;k<nIn;k++)
119  {
120  found=FALSE;
121  t=0;
122  while((!found)&&(t<na))
123  {
124  found=((k==dimSin[t])||(k==dimCos[t]));
125  t++;
126  }
127  if (!found)
128  {
129  map[l]=k;
130  l++;
131  }
132  }
133  }
134 
135  InitBox(nOut,NULL,&boxOut);
136  for(k=0;k<nOut-na;k++)
137  SetBoxInterval(k,GetBoxInterval(map[k],&boxIn),&boxOut);
138 
139  for(k=0;k<na;k++)
140  {
141  IntervalAtan2(GetBoxInterval(dimSin[k],&boxIn),
142  GetBoxInterval(dimCos[k],&boxIn),
143  &iAtan2);
144  SetBoxInterval(nOut-na+k,&iAtan2,&boxOut);
145  DeleteInterval(&iAtan2);
146  }
147 
148  PrintBox(fileOut,&boxOut);
149 
150  DeleteBox(&boxIn);
151  DeleteBox(&boxOut);
152 
153  nbox++;
154  }
155  } while (token!=EOF);
156 
157 
158  fclose(fileIn);
159  fclose(fileOut);
160 
161 
162  if (nbox>0)
163  free(map);
164  free(dimSin);
165  free(dimCos);
166 
167  DeleteFileName(&fIn);
168  DeleteFileName(&fOut);
169 
170  }
171  return(EXIT_SUCCESS);
172 }
Tinterval * GetBoxInterval(unsigned int n, Tbox *b)
Returns a pointer to one of the intervals defining the box.
Definition: box.c:270
#define FALSE
FALSE.
Definition: boolean.h:30
#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 SetBoxInterval(unsigned int n, Tinterval *is, Tbox *b)
Replaces a particular interval in a box.
Definition: box.c:259
Definition of the Tfilename type and the associated functions.
void InitBox(unsigned int dim, Tinterval *is, Tbox *b)
Initializes a box.
Definition: box.c:23
void Error(const char *s)
General error function.
Definition: error.c:80
unsigned int GetBoxNIntervals(Tbox *b)
Box dimensionality.
Definition: box.c:992
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
Definition of the Tbox type and the associated functions.
Definitions of constants and macros used in several parts of the cuik library.
void IntervalAtan2(Tinterval *is, Tinterval *ic, Tinterval *i_out)
Interval atan2.
Definition: interval.c:952
void DeleteInterval(Tinterval *i)
Destructor.
Definition: interval.c:1016
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 cuikatan2 application.
Definition: cuikatan2.c:62
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 PrintBox(FILE *f, Tbox *b)
Prints a box.
Definition: box.c:1118
Defines a interval.
Definition: interval.h:33