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 }