LORENE
des_vect.C
1 /*
2  * Basic routine for plotting a vector field.
3  *
4  */
5 
6 /*
7  * Copyright (c) 2000-2001 Eric Gourgoulhon
8  *
9  * This file is part of LORENE.
10  *
11  * LORENE is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 2 of the License, or
14  * (at your option) any later version.
15  *
16  * LORENE is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with LORENE; if not, write to the Free Software
23  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24  *
25  */
26 
27 
28 
29 
30 /*
31  * $Id: des_vect.C,v 1.6 2016/12/05 16:18:07 j_novak Exp $
32  * $Log: des_vect.C,v $
33  * Revision 1.6 2016/12/05 16:18:07 j_novak
34  * Suppression of some global variables (file names, loch, ...) to prevent redefinitions
35  *
36  * Revision 1.5 2014/10/13 08:53:23 j_novak
37  * Lorene classes and functions now belong to the namespace Lorene.
38  *
39  * Revision 1.4 2014/10/06 15:16:05 j_novak
40  * Modified #include directives to use c++ syntax.
41  *
42  * Revision 1.3 2008/08/19 06:42:00 j_novak
43  * Minor modifications to avoid warnings with gcc 4.3. Most of them concern
44  * cast-type operations, and constant strings that must be defined as const char*
45  *
46  * Revision 1.2 2002/10/16 14:36:58 j_novak
47  * Reorganization of #include instructions of standard C++, in order to
48  * use experimental version 3 of gcc.
49  *
50  * Revision 1.1.1.1 2001/11/20 15:19:29 e_gourgoulhon
51  * LORENE
52  *
53  * Revision 2.0 2000/03/01 16:12:02 eric
54  * *** empty log message ***
55  *
56  *
57  * $Header: /cvsroot/Lorene/C++/Source/Non_class_members/Graphics/des_vect.C,v 1.6 2016/12/05 16:18:07 j_novak Exp $
58  *
59  */
60 
61 
62 
63 // C++ headers:
64 #include"headcpp.h"
65 
66 // C headers:
67 #include <cmath>
68 
69 // PGPLOT headers:
70 #include <cpgplot.h>
71 
72 namespace Lorene {
73 //******************************************************************************
74 
75 void des_vect(float* vvx, float* vvy, int nx, int ny, float xmin, float xmax,
76  float ymin, float ymax, double scale, double sizefl,
77  const char* nomx, const char* nomy, const char* title, const char* device,
78  int newgraph, int nxpage, int nypage) {
79 
80 
81 
82  // Array defining the grid for pgvect_
83  // -----------------------------------
84  float hx = (xmax - xmin)/float(nx-1) ;
85  float hy = (ymax - ymin)/float(ny-1) ;
86 
87  float tr[6] ;
88  tr[0] = xmin - hx ;
89  tr[1] = hx ;
90  tr[2] = 0 ;
91  tr[3] = ymin - hy ;
92  tr[4] = 0 ;
93  tr[5] = hy ;
94 
95 
96  // Determination de la taille des fleches representant les vecteurs:
97  // -----------------------------------------------------------------
98 
99  if (scale < 0) { // si scale >= 0, on garde la valeur de
100  // scale donnee en argument
101  double norme_max = 0 ;
102  for(int ix = 0; ix < nx; ix++) {
103  for(int iy = 0; iy < ny; iy++) {
104  double xxx = sqrt( vvx[iy*nx+ix]*vvx[iy*nx+ix] +
105  vvy[iy*nx+ix]*vvy[iy*nx+ix] ) ;
106  norme_max = (xxx > norme_max) ? xxx : norme_max ;
107  }
108  }
109 
110  if (norme_max < 1.e-14) {
111  scale = 1 ;
112  }
113  else{
114  double pas_max = (hx > hy) ? hx : hy ;
115  scale = fabs(scale) * pas_max / norme_max ;
116  }
117  cout << "des_vect: norme_max = " << norme_max << endl ;
118  cout << "des_vect: scale = " << scale << endl ;
119  }
120 
121 
122  // Graphics display
123  // ----------------
124 
125  if ( (newgraph == 1) || (newgraph == 3) ) {
126 
127  if (device == 0x0) device = "?" ;
128 
129  int ier = cpgbeg(0, device, nxpage, nypage) ;
130  if (ier != 1) {
131  cout << "des_vect: problem in opening PGPLOT display !" << endl ;
132  }
133 
134  }
135 
136  // Taille des caracteres:
137  float size = float(1.3) ;
138  cpgsch(size) ;
139 
140  // Epaisseur des traits:
141  int lepais = 1 ;
142  cpgslw(lepais) ;
143 
144  // Fonte axes: caracteres romains:
145  cpgscf(2) ;
146 
147  // Cadre de la figure
148  cpgenv(xmin, xmax, ymin, ymax, 1, 0 ) ;
149  cpglab(nomx,nomy,title) ;
150 
151 
152 
153  float sizefl1 = float(sizefl) ;
154  cpgsch(sizefl1) ; // controle la taille des extremites des fleches
155 
156  float blank = 0 ;
157  float scale1 = float(scale) ;
158  int nc = 1 ;
159 
160  cpgvect(vvx, vvy, nx, ny, 1, nx, 1, ny, scale1, nc, tr, blank) ;
161 
162  cpgsch(size) ; // restauration
163 
164 
165 
166  // Closing the graphical output
167  // ----------------------------
168 
169  if ( (newgraph == 2) || (newgraph == 3) ) {
170  cpgend() ;
171  }
172 
173 
174 }
175 }
Cmp sqrt(const Cmp &)
Square root.
Definition: cmp_math.C:223
Lorene prototypes.
Definition: app_hor.h:67
void des_vect(float *vvx, float *vvy, int nx, int ny, float xmin, float xmax, float ymin, float ymax, double scale, double sizefl, const char *nomx, const char *nomy, const char *title, const char *device, int newgraph, int nxpage, int nypage)
Basic routine for plotting vector field.
Definition: des_vect.C:75