cuikplot.c
Go to the documentation of this file.
1 #include "boolean.h"
2 #include "plot.h"
3 #include "box.h"
4 #include "defines.h"
5 #include "filename.h"
6 
7 #include <stdlib.h>
8 #include <stdio.h>
9 #include <string.h>
10 #include <math.h>
11 
12 
61 int main(int argc, char **arg)
62 {
63  Tbox box;
64  Tplot plot;
65  int token;
66  FILE *PSin;
67  Tinterval *x,*y;
68  unsigned int dim_x,dim_y;
69  double min_x,max_x,min_y,max_y;
70  unsigned int nb;
71  char nx[10]; /*name for the axis to be ploted*/
72  char ny[10];
73  Tfilename fsols,fplot;
74 
75  if (argc<5)
76  {
77  fprintf(stderr,"Use:\n");
78  fprintf(stderr," cuikplot <filename> dimx dimy <plotname>\n");
79  fprintf(stderr," <filename> the input .sol file\n");
80  fprintf(stderr," dimx dimy the two dimensions to be plotted (numbered from 1)\n");
81  fprintf(stderr," <plotname> the output .fig file\n");
82  }
83  else
84  {
85  CreateFileName(NULL,arg[1],NULL,SOL_EXT,&fsols);
86 
87  /*Parse the input parameters*/
88 
89  PSin=fopen(GetFileFullName(&fsols),"r");
90  if (!PSin)
91  Error("Input file can not be opened");
92 
93  dim_x=(unsigned int)atoi(arg[2]);
94  dim_y=(unsigned int)atoi(arg[3]);
95 
96  /*Check if the dimensions are right*/
97  if ((dim_x==0)||(dim_y==0))
98  Error("Dimensions are numbered from 1\n");
99 
100  if (dim_x==dim_y)
101  Error("Plotting dimensions must be different\n");
102 
103  dim_x=dim_x-1;
104  dim_y=dim_y-1;
105 
106  CreateFileName(NULL,arg[4],NULL,PLOT2D_EXT,&fplot);
107  InitPlot(GetFileFullName(&fplot),&plot);
108 
109  SetOrigin(0.0,0.0,&plot);
110 
111  sprintf(nx,"V%u",dim_x);
112  sprintf(ny,"V%u",dim_y);
113  PlotAxis(nx,-3,3,ny,-3,3,0.5,&plot);
114 
115  nb=1;
116  do {
117  token=ReadBox(PSin,&box);
118 
119  if (token!=EOF)
120  {
121  /*Get the interval of the box in the projection dimentions*/
122  x=GetBoxInterval(dim_x,&box);
123  y=GetBoxInterval(dim_y,&box);
124 
125  /*and get the extreme of the intervals*/
126  min_x=LowerLimit(x);
127  max_x=UpperLimit(x);
128 
129  min_y=LowerLimit(y);
130  max_y=UpperLimit(y);
131 
132  PlotRectangle(min_x,max_y,max_x,min_y,&plot);
133 
134  nb++;
135 
136  DeleteBox(&box);
137  }
138  } while(token!=EOF);
139 
140  DeleteFileName(&fplot);
141  DeleteFileName(&fsols);
142  ClosePlot(&plot);
143  fclose(PSin);
144  }
145  return(EXIT_SUCCESS);
146 }
147 
Definition of the boolean type.
Tinterval * GetBoxInterval(unsigned int n, Tbox *b)
Returns a pointer to one of the intervals defining the box.
Definition: box.c:270
Data structure to hold the information about the name of a file.
Definition: filename.h:248
void InitPlot(const char *name, Tplot *p)
Constructor.
Definition: plot.c:60
A 2D plot.
Definition: plot.h:51
void SetOrigin(double offset_x, double offset_y, Tplot *p)
Changes the current origin of the plot.
Definition: plot.c:116
Definition of the Tfilename type and the associated functions.
void Error(const char *s)
General error function.
Definition: error.c:80
#define PLOT2D_EXT
File extension for 2D plot files.
Definition: filename.h:173
void DeleteFileName(Tfilename *fn)
Destructor.
Definition: filename.c:205
int ReadBox(FILE *f, Tbox *b)
Reads a box from a file.
Definition: box.c:1172
double LowerLimit(Tinterval *i)
Gets the lower limit.
Definition: interval.c:79
Definition of the Tbox type and the associated functions.
Definitions of constants and macros used in several parts of the cuik library.
Module to generate 2d plots.
void CreateFileName(char *path, char *name, char *suffix, char *ext, Tfilename *fn)
Constructor.
Definition: filename.c:22
double UpperLimit(Tinterval *i)
Gets the uppser limit.
Definition: interval.c:87
void ClosePlot(Tplot *p)
Destructor.
Definition: plot.c:275
int main(int argc, char **arg)
Main body of the cuikplot application.
Definition: cuikplot.c:61
char * GetFileFullName(Tfilename *fn)
Gets the file full name (paht+name+extension).
Definition: filename.c:151
void PlotAxis(const char *nx, double min_x, double max_x, const char *ny, double min_y, double max_y, double step, Tplot *p)
Plots a X-Y axis.
Definition: plot.c:247
#define SOL_EXT
File extension for solution files.
Definition: filename.h:137
A box.
Definition: box.h:83
void PlotRectangle(double x_left, double y_sup, double x_right, double y_inf, Tplot *p)
Plots a rectangle.
Definition: plot.c:165
void DeleteBox(void *b)
Destructor.
Definition: box.c:1259
Defines a interval.
Definition: interval.h:33