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 char des_vect_C[] = "$Header: /cvsroot/Lorene/C++/Source/Non_class_members/Graphics/des_vect.C,v 1.5 2014/10/13 08:53:23 j_novak Exp $" ;
29 
30 /*
31  * $Id: des_vect.C,v 1.5 2014/10/13 08:53:23 j_novak Exp $
32  * $Log: des_vect.C,v $
33  * Revision 1.5 2014/10/13 08:53:23 j_novak
34  * Lorene classes and functions now belong to the namespace Lorene.
35  *
36  * Revision 1.4 2014/10/06 15:16:05 j_novak
37  * Modified #include directives to use c++ syntax.
38  *
39  * Revision 1.3 2008/08/19 06:42:00 j_novak
40  * Minor modifications to avoid warnings with gcc 4.3. Most of them concern
41  * cast-type operations, and constant strings that must be defined as const char*
42  *
43  * Revision 1.2 2002/10/16 14:36:58 j_novak
44  * Reorganization of #include instructions of standard C++, in order to
45  * use experimental version 3 of gcc.
46  *
47  * Revision 1.1.1.1 2001/11/20 15:19:29 e_gourgoulhon
48  * LORENE
49  *
50  * Revision 2.0 2000/03/01 16:12:02 eric
51  * *** empty log message ***
52  *
53  *
54  * $Header: /cvsroot/Lorene/C++/Source/Non_class_members/Graphics/des_vect.C,v 1.5 2014/10/13 08:53:23 j_novak Exp $
55  *
56  */
57 
58 
59 
60 // C++ headers:
61 #include"headcpp.h"
62 
63 // C headers:
64 #include <cmath>
65 
66 // PGPLOT headers:
67 #include <cpgplot.h>
68 
69 namespace Lorene {
70 //******************************************************************************
71 
72 void des_vect(float* vvx, float* vvy, int nx, int ny, float xmin, float xmax,
73  float ymin, float ymax, double scale, double sizefl,
74  const char* nomx, const char* nomy, const char* title, const char* device,
75  int newgraph, int nxpage, int nypage) {
76 
77 
78 
79  // Array defining the grid for pgvect_
80  // -----------------------------------
81  float hx = (xmax - xmin)/float(nx-1) ;
82  float hy = (ymax - ymin)/float(ny-1) ;
83 
84  float tr[6] ;
85  tr[0] = xmin - hx ;
86  tr[1] = hx ;
87  tr[2] = 0 ;
88  tr[3] = ymin - hy ;
89  tr[4] = 0 ;
90  tr[5] = hy ;
91 
92 
93  // Determination de la taille des fleches representant les vecteurs:
94  // -----------------------------------------------------------------
95 
96  if (scale < 0) { // si scale >= 0, on garde la valeur de
97  // scale donnee en argument
98  double norme_max = 0 ;
99  for(int ix = 0; ix < nx; ix++) {
100  for(int iy = 0; iy < ny; iy++) {
101  double xxx = sqrt( vvx[iy*nx+ix]*vvx[iy*nx+ix] +
102  vvy[iy*nx+ix]*vvy[iy*nx+ix] ) ;
103  norme_max = (xxx > norme_max) ? xxx : norme_max ;
104  }
105  }
106 
107  if (norme_max < 1.e-14) {
108  scale = 1 ;
109  }
110  else{
111  double pas_max = (hx > hy) ? hx : hy ;
112  scale = fabs(scale) * pas_max / norme_max ;
113  }
114  cout << "des_vect: norme_max = " << norme_max << endl ;
115  cout << "des_vect: scale = " << scale << endl ;
116  }
117 
118 
119  // Graphics display
120  // ----------------
121 
122  if ( (newgraph == 1) || (newgraph == 3) ) {
123 
124  if (device == 0x0) device = "?" ;
125 
126  int ier = cpgbeg(0, device, nxpage, nypage) ;
127  if (ier != 1) {
128  cout << "des_vect: problem in opening PGPLOT display !" << endl ;
129  }
130 
131  }
132 
133  // Taille des caracteres:
134  float size = float(1.3) ;
135  cpgsch(size) ;
136 
137  // Epaisseur des traits:
138  int lepais = 1 ;
139  cpgslw(lepais) ;
140 
141  // Fonte axes: caracteres romains:
142  cpgscf(2) ;
143 
144  // Cadre de la figure
145  cpgenv(xmin, xmax, ymin, ymax, 1, 0 ) ;
146  cpglab(nomx,nomy,title) ;
147 
148 
149 
150  float sizefl1 = float(sizefl) ;
151  cpgsch(sizefl1) ; // controle la taille des extremites des fleches
152 
153  float blank = 0 ;
154  float scale1 = float(scale) ;
155  int nc = 1 ;
156 
157  cpgvect(vvx, vvy, nx, ny, 1, nx, 1, ny, scale1, nc, tr, blank) ;
158 
159  cpgsch(size) ; // restauration
160 
161 
162 
163  // Closing the graphical output
164  // ----------------------------
165 
166  if ( (newgraph == 2) || (newgraph == 3) ) {
167  cpgend() ;
168  }
169 
170 
171 }
172 }
Cmp sqrt(const Cmp &)
Square root.
Definition: cmp_math.C:220
Lorene prototypes.
Definition: app_hor.h:64
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:72