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

The CuikSuite Project

cuikplot.c

Go to the documentation of this file.
00001 #include "boolean.h"
00002 #include "plot.h"
00003 #include "box.h"
00004 #include "defines.h"
00005 #include "filename.h"
00006 
00007 #include <stdlib.h> 
00008 #include <stdio.h>
00009 #include <string.h>
00010 #include <math.h>
00011 
00012 
00044 int main(int argc, char **arg)
00045 {
00046   Tbox box;
00047   Tplot plot;
00048   int token;
00049   FILE *PSin; 
00050   Tinterval *x,*y;
00051   unsigned int dim_x,dim_y;
00052   double min_x,max_x,min_y,max_y;
00053   unsigned int nb;
00054   char nx[10]; /*name for the axis to be ploted*/
00055   char ny[10];
00056   Tfilename fsols,fplot;
00057 
00058   if (argc<5)
00059     {
00060       fprintf(stderr,"Use:\n");
00061       fprintf(stderr,"  cuikplot <filename> dimx dimy <plotname>\n");
00062       fprintf(stderr,"    <filename> the input .sol file\n");
00063       fprintf(stderr,"    dimx dimy the two dimensions to be plotted (numbered from 1)\n");
00064       fprintf(stderr,"    <plotname> the output .fig file\n");
00065     }
00066   else
00067     {
00068       CreateFileName(NULL,arg[1],NULL,SOL_EXT,&fsols);
00069       
00070       /*Parse the input parameters*/
00071 
00072       PSin=fopen(GetFileFullName(&fsols),"r");
00073       if (!PSin)
00074         Error("Input file can not be opened");
00075 
00076       dim_x=(unsigned int)atoi(arg[2]);
00077       dim_y=(unsigned int)atoi(arg[3]);
00078 
00079       /*Check if the dimensions are right*/
00080       if ((dim_x==0)||(dim_y==0))
00081         Error("Dimensions are numbered from 1\n");
00082 
00083       if (dim_x==dim_y)
00084         Error("Plotting dimensions must be different\n");
00085 
00086       dim_x=dim_x-1;
00087       dim_y=dim_y-1;
00088 
00089       CreateFileName(NULL,arg[4],NULL,PLOT2D_EXT,&fplot);
00090       InitPlot(GetFileFullName(&fplot),&plot);
00091     
00092       SetOrigin(0.0,0.0,&plot);
00093 
00094       sprintf(nx,"V%u",dim_x);
00095       sprintf(ny,"V%u",dim_y);
00096       PlotAxis(nx,-3,3,ny,-3,3,0.5,&plot);
00097 
00098       nb=1;
00099       do {
00100         token=ReadBox(PSin,&box);
00101         
00102         if (token!=EOF)
00103           {
00104             /*Get the interval of the box in the projection dimentions*/
00105             x=GetBoxInterval(dim_x,&box);
00106             y=GetBoxInterval(dim_y,&box);
00107             
00108             /*and get the extreme of the intervals*/
00109             min_x=LowerLimit(x);
00110             max_x=UpperLimit(x);
00111             
00112             min_y=LowerLimit(y);
00113             max_y=UpperLimit(y);
00114             
00115             PlotRectangle(min_x,max_y,max_x,min_y,&plot);
00116             
00117             nb++;
00118 
00119             DeleteBox(&box);
00120           }
00121       } while(token!=EOF);
00122 
00123       DeleteFileName(&fplot);
00124       DeleteFileName(&fsols);
00125       ClosePlot(&plot);
00126       fclose(PSin);
00127     }
00128   return(EXIT_SUCCESS);
00129 }
00130