00001 #include "boolean.h"
00002 #include "plot3d.h"
00003 #include "box.h"
00004 #include "defines.h"
00005 #include "filename.h"
00006 #include "color.h"
00007
00008 #include <stdlib.h>
00009 #include <stdio.h>
00010 #include <string.h>
00011 #include <math.h>
00012
00047 int main(int argc, char **arg)
00048 {
00049 Tbox box;
00050 unsigned int nbox;
00051 int token;
00052 Tplot3d plot;
00053 FILE *PSin;
00054 Tinterval *x,*y,*z;
00055 unsigned int dim_x,dim_y,dim_z;
00056 double average_x,average_y,average_z;
00057 double min_x,max_x,min_y,max_y, min_z,max_z;
00058 double minSize;
00059 Tfilename fsols,fplot;
00060 Tcolor plotColor;
00061
00062 if (argc<7)
00063 {
00064 fprintf(stderr,"Use:\n");
00065 fprintf(stderr," cuikplot3d <filename> dimx dimy dimz min_size <plotname> \n");
00066 fprintf(stderr," <filename> the input .sol file\n");
00067 fprintf(stderr," dimx dimy dimz -> the three dimensions to be plotted (numbered from 1)\n");
00068 fprintf(stderr," min_size -> minimum size for the boxes\n");
00069 fprintf(stderr," <plotname> the output .cgl file\n");
00070 }
00071 else
00072 {
00073 CreateFileName(NULL,arg[1],NULL,SOL_EXT,&fsols);
00074
00075
00076
00077
00078 PSin=fopen(GetFileFullName(&fsols),"r");
00079 if (!PSin)
00080 Error("Input file can not be opened");
00081
00082
00083 dim_x=(unsigned int)atoi(arg[2]);
00084 dim_y=(unsigned int)atoi(arg[3]);
00085 dim_z=(unsigned int)atoi(arg[4]);
00086
00087
00088 if ((dim_x==0)||(dim_y==0)||(dim_z==0))
00089 Error("Dimensions are numbered from 1\n");
00090
00091 if ((dim_x==dim_y)||(dim_x==dim_z)||(dim_y==dim_z))
00092 Error("Plotting dimensions must be different\n");
00093
00094 dim_x=dim_x-1;
00095 dim_y=dim_y-1;
00096 dim_z=dim_z-1;
00097
00098
00099 average_x=0.0;
00100 average_y=0.0;
00101 average_z=0.0;
00102
00103 nbox=0;
00104 do {
00105 token=ReadBox(PSin,&box);
00106 if (token!=EOF)
00107 {
00108 average_x+=IntervalCenter(GetBoxInterval(dim_x,&box));
00109 average_y+=IntervalCenter(GetBoxInterval(dim_y,&box));
00110 average_z+=IntervalCenter(GetBoxInterval(dim_z,&box));
00111 nbox++;
00112 DeleteBox(&box);
00113 }
00114 } while (token!=EOF);
00115
00116 if (nbox>0)
00117 {
00118 average_x/=(double)nbox;
00119 average_y/=(double)nbox;
00120 average_z/=(double)nbox;
00121 }
00122 else
00123 {
00124 average_x=0.0;
00125 average_y=0.0;
00126 average_z=0.0;
00127 }
00128
00129
00130 fclose(PSin);
00131
00132 PSin=fopen(GetFileFullName(&fsols),"r");
00133
00134 average_x=0.0;
00135 average_y=0.0;
00136 average_z=0.0;
00137
00138
00139 minSize=(double)atof(arg[5]);
00140
00141
00142 CreateFileName(NULL,arg[6],NULL,PLOT3D_EXT,&fplot);
00143 InitPlot3d(GetFileFullName(&fplot),TRUE,argc,arg,&plot);
00144 DeleteFileName(&fplot);
00145
00146 NewColor(DCP3D_R,DCP3D_G,DCP3D_B,&plotColor);
00147 StartNew3dObject(&plotColor,&plot);
00148 DeleteColor(&plotColor);
00149
00150 do {
00151 token=ReadBox(PSin,&box);
00152 if (token!=EOF)
00153 {
00154
00155 x=GetBoxInterval(dim_x,&box);
00156 y=GetBoxInterval(dim_y,&box);
00157 z=GetBoxInterval(dim_z,&box);
00158
00159
00160 min_x=LowerLimit(x) ;
00161 max_x=UpperLimit(x) ;
00162
00163 min_y=LowerLimit(y) ;
00164 max_y=UpperLimit(y) ;
00165
00166 min_z=LowerLimit(z) ;
00167 max_z=UpperLimit(z) ;
00168
00169
00170 if (((max_x-min_x)<minSize)&&
00171 ((max_y-min_y)<minSize)&&
00172 ((max_z-min_z)<minSize))
00173 {
00174 double r;
00175
00176 r=minSize/2;
00177
00178 max_x+=r; min_x-=r;
00179 max_y+=r; min_y-=r;
00180 max_z+=r; min_z-=r;
00181 }
00182
00183
00184
00185 PlotBox3d(min_x-average_x,max_x-average_x,
00186 min_y-average_y,max_y-average_y,
00187 min_z-average_z,max_z-average_z,
00188 &plot);
00189
00190
00191
00192
00193 DeleteBox(&box);
00194 }
00195 } while (token!=EOF);
00196
00197 ClosePlot3d(FALSE,average_x,average_y,average_z,&plot);
00198
00199 DeleteFileName(&fsols);
00200 fclose(PSin);
00201 }
00202
00203 return(EXIT_SUCCESS);
00204 }