Institut de Robòtica i Informàtica Industrial
KRD Group

The CuikSuite Project

cuikatan2.c

Go to the documentation of this file.
00001 
00002 #include "box.h"
00003 
00004 #include "defines.h"
00005 #include "filename.h"
00006 
00007 #include <string.h>
00008 
00009 
00043 int main(int argc, char **arg)
00044 {
00045   FILE *fileIn,*fileOut;
00046   Tbox boxIn,boxOut;
00047   Tinterval iAtan2;
00048   unsigned int *map,*dimSin,*dimCos,nIn,nOut;
00049   unsigned int k,l,t,na,nbox;
00050   int token;
00051   Tfilename fIn,fOut;
00052   boolean found;
00053 
00054   if ((argc<4)||((argc%2)==0))
00055     {
00056       fprintf(stderr,"Use:\n");
00057       fprintf(stderr,"  cuikatan2 <input_file> <dim_sin_1> <dim_cos_1> ... <dim_sin_n> <dim_cos_n>  <output_file>\n");
00058       fprintf(stderr,"    <input_file> the input .sol file\n");
00059       fprintf(stderr,"    <dim_sin_i> <dim_cos_i> the sin/cos dimensions (numbered from 1)\n");
00060       fprintf(stderr,"    <output_file> the .sol file to be generated\n");
00061     }
00062   else
00063     {
00064       
00065 
00066       CreateFileName(NULL,arg[1],NULL,SOL_EXT,&fIn);
00067       CreateFileName(NULL,arg[argc-1],NULL,SOL_EXT,&fOut);
00068   
00069       fileIn=fopen(GetFileFullName(&fIn),"r");
00070       if (!fileIn)
00071         Error("Input file can not be opened");
00072 
00073       fileOut=fopen(GetFileFullName(&fOut),"w");
00074       if (!fileOut)
00075         Error("Output file can not be opened");
00076 
00077 
00078       na=(argc-3)/2;
00079       NEW(dimSin,na,unsigned int);
00080       NEW(dimCos,na,unsigned int);
00081       
00082       for(k=0;k<na;k++)
00083         {
00084           dimSin[k]=(unsigned int)atoi(arg[2+2*k])-1;
00085           dimCos[k]=(unsigned int)atoi(arg[3+2*k])-1;
00086         }
00087 
00088       nbox=0;
00089       do {
00090         token=ReadBox(fileIn,&boxIn);
00091         if (token!=EOF)
00092           {
00093             if (nbox==0)
00094               {
00095                 nIn=GetBoxNIntervals(&boxIn);
00096 
00097                 nOut=nIn-na;
00098 
00099                 NEW(map,nOut-na,unsigned int);
00100                 l=0;
00101                 for(k=0;k<nIn;k++)
00102                   {
00103                     found=FALSE;
00104                     t=0;
00105                     while((!found)&&(t<na))
00106                       {
00107                         found=((k==dimSin[t])||(k==dimCos[t]));
00108                         t++;
00109                       }
00110                     if (!found)
00111                       {
00112                         map[l]=k;
00113                         l++;
00114                       }
00115                   }
00116               }
00117 
00118             InitBox(nOut,NULL,&boxOut);
00119             for(k=0;k<nOut;k++)
00120               SetBoxInterval(k,GetBoxInterval(map[k],&boxIn),&boxOut);
00121             
00122             for(k=0;k<na;k++)
00123               {
00124                 IntervalAtan2(GetBoxInterval(dimSin[k],&boxIn),
00125                               GetBoxInterval(dimCos[k],&boxIn),
00126                               &iAtan2);
00127                 SetBoxInterval(nOut-na+k,&iAtan2,&boxOut);
00128                 DeleteInterval(&iAtan2);
00129               }
00130 
00131             PrintBox(fileOut,&boxOut);
00132 
00133             DeleteBox(&boxIn);
00134             DeleteBox(&boxOut);
00135 
00136             nbox++;
00137           }     
00138       } while (token!=EOF);
00139       
00140 
00141       fclose(fileIn);
00142       fclose(fileOut);
00143 
00144 
00145       if (nbox>0)
00146         free(map);
00147       free(dimSin);
00148       free(dimCos);
00149 
00150       DeleteFileName(&fIn);
00151       DeleteFileName(&fOut);
00152       
00153     }
00154   return(EXIT_SUCCESS);
00155 }