cuikplotpath.c
Go to the documentation of this file.
1 
2 #include "world.h"
3 #include "parameters.h"
4 
5 #include "defines.h"
6 #include "error.h"
7 #include "filename.h"
8 #include "atlas.h"
9 #include "samples.h"
10 
11 #include <stdlib.h>
12 
68 int main(int argc, char **arg)
69 {
70  TAtlasBase world; /* The set of mechanism and obstacles. */
71  Tparameters parameters; /* Parameters used in the Cuik process. */
72 
73  unsigned int nx,ny,nz;
74  unsigned int nvs;
75 
76  unsigned int ns;
77  double **path;
78 
79  Tfilename fparam;
80  Tfilename fpath;
81 
82  //boolean smooth;
83 
84  if (argc>=5)
85  {
86  /*Init parameters*/
87  CreateFileName(NULL,arg[1],NULL,PARAM_EXT,&fparam);
88  InitParametersFromFile(GetFileFullName(&fparam),&parameters);
89  fprintf(stderr,"Reading parameters from : %s\n",GetFileFullName(&fparam));
90 
91  /*Read the world from file*/
92  CS_WD_INIT(&parameters,arg[1],&world);
93 
94  /* Validate the input projection dimensions */
95  nvs=CS_WD_GET_NUM_SYSTEM_VARS(&world);
96 
97  if (argc>5)
98  {
99  CreateFileName(NULL,arg[2],NULL,SOL_EXT,&fpath);
100 
101  nx=atoi(arg[3]);
102  ny=atoi(arg[4]);
103  nz=atoi(arg[5]);
104  }
105  else
106  {
107  CreateFileName(NULL,arg[1],"_path",SOL_EXT,&fpath);
108 
109  nx=atoi(arg[2]);
110  ny=atoi(arg[3]);
111  nz=atoi(arg[4]);
112  }
113 
114  if (nx>=nvs)
115  Error("First index out of range");
116  if (ny>=nvs)
117  Error("Second index out of range");
118  if (nz>=nvs)
119  Error("Third index out of range");
120 
121  /* Load the path */
122  if (LoadSamples(&fpath,&nvs,&ns,&path))
123  {
124  /*If the path was actually loaded*/
125  Tfilename fpathplot;
126  Tplot3d p3d;
127 
128  if (argc>5)
129  CreateFileName(NULL,arg[2],NULL,PLOT3D_EXT,&fpathplot);
130  else
131  CreateFileName(NULL,arg[1],"_path",PLOT3D_EXT,&fpathplot);
132 
133  /* Plot the path */
134  fprintf(stderr,"Generating path plot to : %s\n",GetFileFullName(&fpathplot));
135 
136  InitPlot3d(GetFileFullName(&fpathplot),FALSE,argc,arg,&p3d);
137 
138  PlotSamples(&parameters,&p3d,nx,ny,nz,ns,path);
139 
140  ClosePlot3d(FALSE,&p3d);
141 
142  DeleteFileName(&fpathplot);
143  DeleteSamples(ns,path);
144  }
145  else
146  Error("Can not read the file with the path");
147 
148  DeleteParameters(&parameters);
149  CS_WD_DELETE(&world);
150 
151  DeleteFileName(&fpath);
152  DeleteFileName(&fparam);
153  }
154  else
155  {
156  fprintf(stderr," Wrong number of parameters.\n");
157  fprintf(stderr," Use:\n");
158  fprintf(stderr," cuikplotpath <problem filename> [<path filename>] <xID> <yID> <zID>\n");
159  fprintf(stderr," where <problem filename> is the description of the problem.\n");
160  fprintf(stderr," <path filename> is the path to plot. If not given we use <problem filename>_path.sol\n");
161  fprintf(stderr," <xID> <yID> <zID> are the 3 projection dimensions.\n");
162  fprintf(stderr," (indices of system variables as those in the _path.sol file from 0)\n");
163  }
164  return(EXIT_SUCCESS);
165 }
166