LORENE
des_profile.C
1 /*
2  * Basic routine for drawing profiles.
3  */
4 
5 /*
6  * Copyright (c) 1999-2004 Eric Gourgoulhon
7  *
8  * This file is part of LORENE.
9  *
10  * LORENE is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * LORENE is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with LORENE; if not, write to the Free Software
22  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23  *
24  */
25 
26 
27 char des_profile_C[] = "$Header: /cvsroot/Lorene/C++/Source/Non_class_members/Graphics/des_profile.C,v 1.11 2014/10/13 08:53:22 j_novak Exp $" ;
28 
29 /*
30  * $Id: des_profile.C,v 1.11 2014/10/13 08:53:22 j_novak Exp $
31  * $Log: des_profile.C,v $
32  * Revision 1.11 2014/10/13 08:53:22 j_novak
33  * Lorene classes and functions now belong to the namespace Lorene.
34  *
35  * Revision 1.10 2014/10/06 15:16:05 j_novak
36  * Modified #include directives to use c++ syntax.
37  *
38  * Revision 1.9 2012/01/17 10:35:46 j_penner
39  * added point plot
40  *
41  * Revision 1.8 2008/08/19 06:42:00 j_novak
42  * Minor modifications to avoid warnings with gcc 4.3. Most of them concern
43  * cast-type operations, and constant strings that must be defined as const char*
44  *
45  * Revision 1.7 2005/03/25 19:56:28 e_gourgoulhon
46  * Added plot of domain boundaries (new arguments nbound and xbound).
47  *
48  * Revision 1.6 2004/02/17 22:19:22 e_gourgoulhon
49  * Changed prototype of des_profile_mult.
50  * Added version of des_profile_mult with arbitrary x sampling.
51  *
52  * Revision 1.5 2004/02/16 10:54:08 e_gourgoulhon
53  * Added #include <stdlib.h>.
54  *
55  * Revision 1.4 2004/02/15 21:56:49 e_gourgoulhon
56  * des_profile_mult: added call to cpgask(0).
57  *
58  * Revision 1.3 2004/02/12 16:21:57 e_gourgoulhon
59  * Added new function des_profile_mult.
60  *
61  * Revision 1.2 2002/10/16 14:36:57 j_novak
62  * Reorganization of #include instructions of standard C++, in order to
63  * use experimental version 3 of gcc.
64  *
65  * Revision 1.1.1.1 2001/11/20 15:19:29 e_gourgoulhon
66  * LORENE
67  *
68  * Revision 1.1 1999/12/09 16:38:41 eric
69  * Initial revision
70  *
71  *
72  * $Header: /cvsroot/Lorene/C++/Source/Non_class_members/Graphics/des_profile.C,v 1.11 2014/10/13 08:53:22 j_novak Exp $
73  *
74  */
75 
76 
77 // C++ headers:
78 #include"headcpp.h"
79 
80 // C headers:
81 #include <cstdlib>
82 #include <cmath>
83 #include <cpgplot.h>
84 
85 
86 namespace Lorene {
87 //******************************************************************************
88 // Single profile, single device, uniform sampling
89 //******************************************************************************
90 
91 void des_profile(const float* uutab, int nx, float xmin, float xmax,
92  const char* nomx, const char* nomy,
93  const char* title, const char* device,
94  int nbound, float* xbound) {
95 
96  // Search for the extremal values of the field :
97  // -------------------------------------------
98 
99  float uumin = uutab[0] ;
100  float uumax = uutab[0] ;
101  for (int i=1; i<nx; i++) {
102  uumin = (uutab[i] < uumin) ? uutab[i] : uumin ;
103  uumax = (uutab[i] > uumax) ? uutab[i] : uumax ;
104  }
105 
106  cout << " " << nomy << " : min, max : " << uumin << " " << uumax
107  << endl ;
108 
109  // Points abscisses :
110  // ----------------
111 
112  float* xx = new float[nx] ;
113  float hx = (xmax-xmin)/float(nx-1) ;
114  for(int i=0; i<nx; i++) {
115  xx[i] = xmin + float(i) * hx ;
116  }
117 
118  // Graphics display
119  // ----------------
120 
121  if (device == 0x0) {
122  device = "?" ;
123  }
124 
125  int ier = cpgbeg(0, device, 1, 1) ;
126  if (ier != 1) {
127  cout << "des_profile: problem in opening PGPLOT display !" << endl ;
128  }
129 
130  // Taille des caracteres:
131  float size = float(1.3) ;
132  cpgsch(size) ;
133 
134  // Epaisseur des traits:
135  int lepais = 1 ;
136  cpgslw(lepais) ;
137 
138  // Fonte axes: caracteres romains:
139  cpgscf(2) ;
140 
141  // Cadre de la figure
142  float uuamp = uumax - uumin ;
143  float uumin1 = uumin - float(0.05) * uuamp ;
144  float uumax1 = uumax + float(0.05) * uuamp ;
145  cpgenv(xmin, xmax, uumin1, uumax1, 0, 0 ) ;
146  cpglab(nomx,nomy,title) ;
147 
148  // Drawing of curve
149  cpgline(nx, xx, uutab) ;
150 
151 
152  // Plot of domain boundaries
153  // -------------------------
154 
155  if (nbound > 0) {
156  float xb[2] ;
157  float yb[2] ;
158  yb[0] = uumin1 ;
159  yb[1] = uumax1 ;
160  cpgsls(3) ; // lignes en trait mixte
161  cpgsci(3) ; // couleur verte
162  for (int i=0; i<nbound; i++) {
163  xb[0] = xbound[i] ;
164  xb[1] = xbound[i] ;
165  cpgline(2, xb, yb) ;
166  }
167  cpgsls(1) ; // retour aux lignes en trait plein
168  cpgsci(1) ; // couleur noire
169  }
170 
171  cpgend() ;
172 
173  delete [] xx ;
174 
175 }
176 
177 
178 
179 //******************************************************************************
180 // Multiple profiles, multiple device, uniform sampling
181 //******************************************************************************
182 
183 void des_profile_mult(const float* uutab, int nprof, int nx,
184  float xmin, float xmax, const char* nomx, const char* nomy,
185  const char* title, const int* line_style,
186  int ngraph, bool closeit, const char* device,
187  int nbound, float* xbound) {
188 
189  const int ngraph_max = 100 ;
190  static int graph_list[ngraph_max] ;
191  static bool first_call = true ;
192 
193  // First call operations
194  // ---------------------
195 
196  if (first_call) { // initialization of all the graphic devices to 0 :
197  for (int i=0; i<ngraph_max; i++) {
198  graph_list[i] = 0 ;
199  }
200  first_call = false ;
201  }
202 
203 
204  // Search for the extremal values of the field :
205  // -------------------------------------------
206 
207  int ntot = nprof * nx ;
208  float uumin = uutab[0] ;
209  float uumax = uutab[0] ;
210  for (int i=1; i<ntot; i++) {
211  if (uutab[i] < uumin) uumin = uutab[i] ;
212  if (uutab[i] > uumax) uumax = uutab[i] ;
213  }
214 
215  cout << " " << nomy << " : min, max : " << uumin << " " << uumax
216  << endl ;
217 
218  // Points abscisses :
219  // ----------------
220 
221  float* xx = new float[nx] ;
222  float hx = (xmax-xmin)/float(nx-1) ;
223  for(int i=0; i<nx; i++) {
224  xx[i] = xmin + float(i) * hx ;
225  }
226 
227  // Graphics display
228  // ----------------
229 
230  // Opening of the device
231 
232  if ( (ngraph < 0) || (ngraph >= ngraph_max) ) {
233  cerr << "des_profile_mult : graph index out of range ! \n" ;
234  cerr << " ngraph = " << ngraph << " while range = 0, "
235  << ngraph_max-1 << endl ;
236  abort() ;
237  }
238 
239  if (graph_list[ngraph] == 0) { // opening is required
240  // -------------------
241 
242  if (device == 0x0) device = "?" ;
243 
244  graph_list[ngraph] = cpgopen(device) ;
245 
246  if ( graph_list[ngraph] <= 0 ) {
247  cerr << "des_profile_mult: problem in opening PGPLOT display !\n" ;
248  abort() ;
249  }
250 
251  cpgask(0) ; // Disables the ``Type RETURN for next page:'' prompt
252 
253  }
254  else { // the graphic device has been opened previously
255 
256  cpgslct( graph_list[ngraph] ) ; // selects the appropriate device
257  }
258 
259  // Drawing
260  // -------
261 
262  // Taille des caracteres:
263  float size = float(1.3) ;
264  cpgsch(size) ;
265 
266  // Epaisseur des traits:
267  int lepais = 1 ;
268  cpgslw(lepais) ;
269 
270  // Fonte axes: caracteres romains:
271  cpgscf(2) ;
272 
273  // Cadre de la figure
274  float uuamp = uumax - uumin ;
275  float uumin1 = uumin - float(0.05) * uuamp ;
276  float uumax1 = uumax + float(0.05) * uuamp ;
277  cpgsls(1) ;
278  cpgenv(xmin, xmax, uumin1, uumax1, 0, 0 ) ;
279  cpglab(nomx,nomy,title) ;
280 
281 
282  for (int i=0; i<nprof; i++) {
283  const float* uudes = uutab + i*nx ;
284 
285  if (line_style == 0x0) cpgsls(i%5 + 1) ;
286  else cpgsls(line_style[i]) ;
287 
288  cpgline(nx, xx, uudes) ;
289  }
290 
291  // Plot of domain boundaries
292  // -------------------------
293 
294  if (nbound > 0) {
295  float xb[2] ;
296  float yb[2] ;
297  yb[0] = uumin1 ;
298  yb[1] = uumax1 ;
299  cpgsls(3) ; // lignes en trait mixte
300  cpgsci(3) ; // couleur verte
301  for (int i=0; i<nbound; i++) {
302  xb[0] = xbound[i] ;
303  xb[1] = xbound[i] ;
304  cpgline(2, xb, yb) ;
305  }
306  cpgsls(1) ; // retour aux lignes en trait plein
307  cpgsci(1) ; // couleur noire
308  }
309 
310 
311  if (closeit) {
312  cpgclos() ;
313  graph_list[ngraph] = 0 ;
314  }
315 
316  delete [] xx ;
317 
318 }
319 
320 
321 //******************************************************************************
322 // Single profile, single device, arbitrary sampling
323 //******************************************************************************
324 
325 void des_profile(const float* uutab, int nx, const float *xtab,
326  const char* nomx, const char* nomy,
327  const char* title, const char* device,
328  int nbound, float* xbound) {
329 
330  // Search for the extremal values of the field :
331  // -------------------------------------------
332 
333  float uumin = uutab[0] ;
334  float uumax = uutab[0] ;
335  float xmin = xtab[0] ;
336  float xmax = xtab[0] ;
337  for (int i=1; i<nx; i++) {
338  uumin = (uutab[i] < uumin) ? uutab[i] : uumin ;
339  uumax = (uutab[i] > uumax) ? uutab[i] : uumax ;
340  xmin = (xtab[i] < xmin) ? xtab[i] : xmin ;
341  xmax = (xtab[i] > xmax) ? xtab[i] : xmax ;
342  }
343 
344  cout << " " << nomy << " : min, max : " << uumin << " " << uumax << endl;
345  cout << " " << "domain: " << "min, max : " << xmin << " " << xmax << endl ;
346 
347  // Points abscisses :
348  // ----------------
349 /*
350  float* xx = new float[nx] ;
351  float hx = (xmax-xmin)/float(nx-1) ;
352  for(int i=0; i<nx; i++) {
353  xx[i] = xmin + float(i) * hx ;
354  }
355 */
356  // Graphics display
357  // ----------------
358 
359  if (device == 0x0) {
360  device = "?" ;
361  }
362 
363  int ier = cpgbeg(0, device, 1, 1) ;
364  if (ier != 1) {
365  cout << "des_profile: problem in opening PGPLOT display !" << endl ;
366  }
367 
368  // Taille des caracteres:
369  float size = float(1.3) ;
370  cpgsch(size) ;
371 
372  // Epaisseur des traits:
373  int lepais = 1 ;
374  cpgslw(lepais) ;
375 
376  // Fonte axes: caracteres romains:
377  cpgscf(2) ;
378 
379  // Cadre de la figure
380  float uuamp = uumax - uumin ;
381  float uumin1 = uumin - float(0.05) * uuamp ;
382  float uumax1 = uumax + float(0.05) * uuamp ;
383  cpgenv(xmin, xmax, uumin1, uumax1, 0, 0 ) ;
384  cpglab(nomx,nomy,title) ;
385 
386  // Drawing of curve
387  cpgline(nx, xtab, uutab) ;
388 
389 
390  // Plot of domain boundaries
391  // -------------------------
392 
393  if (nbound > 0) {
394  float xb[2] ;
395  float yb[2] ;
396  yb[0] = uumin1 ;
397  yb[1] = uumax1 ;
398  cpgsls(3) ; // lignes en trait mixte
399  cpgsci(3) ; // couleur verte
400  for (int i=0; i<nbound; i++) {
401  xb[0] = xbound[i] ;
402  xb[1] = xbound[i] ;
403  cpgline(2, xb, yb) ;
404  }
405  cpgsls(1) ; // retour aux lignes en trait plein
406  cpgsci(1) ; // couleur noire
407  }
408 
409  cpgend() ;
410 
411 }
412 
413 
414 
415 //******************************************************************************
416 // Multiple profiles, multiple device, arbitrary sampling
417 //******************************************************************************
418 
419 void des_profile_mult(const float* uutab, int nprof, int nx, const float* xtab,
420  const char* nomx, const char* nomy, const char* title,
421  const int* line_style, int ngraph, bool closeit,
422  const char* device, int nbound, float* xbound) {
423 
424  const int ngraph_max = 100 ;
425  static int graph_list[ngraph_max] ;
426  static bool first_call = true ;
427 
428  // First call operations
429  // ---------------------
430 
431  if (first_call) { // initialization of all the graphic devices to 0 :
432  for (int i=0; i<ngraph_max; i++) {
433  graph_list[i] = 0 ;
434  }
435  first_call = false ;
436  }
437 
438 
439  // Search for the extremal values of x and of the field :
440  // ----------------------------------------------------
441 
442  int ntot = nprof * nx ;
443  float uumin = uutab[0] ;
444  float uumax = uutab[0] ;
445  for (int i=1; i<ntot; i++) {
446  if (uutab[i] < uumin) uumin = uutab[i] ;
447  if (uutab[i] > uumax) uumax = uutab[i] ;
448  }
449 
450  float xmin = xtab[0] ;
451  float xmax = xtab[0] ;
452  for (int i=1; i<ntot; i++) {
453  if (xtab[i] < xmin) xmin = xtab[i] ;
454  if (xtab[i] > xmax) xmax = xtab[i] ;
455  }
456 
457  cout << " " << nomy << " : min, max : " << uumin << " " << uumax
458  << endl ;
459 
460 
461  // Graphics display
462  // ----------------
463 
464  // Opening of the device
465 
466  if ( (ngraph < 0) || (ngraph >= ngraph_max) ) {
467  cerr << "des_profile_mult : graph index out of range ! \n" ;
468  cerr << " ngraph = " << ngraph << " while range = 0, "
469  << ngraph_max-1 << endl ;
470  abort() ;
471  }
472 
473  if (graph_list[ngraph] == 0) { // opening is required
474  // -------------------
475 
476  if (device == 0x0) device = "?" ;
477 
478  graph_list[ngraph] = cpgopen(device) ;
479 
480  if ( graph_list[ngraph] <= 0 ) {
481  cerr << "des_profile_mult: problem in opening PGPLOT display !\n" ;
482  abort() ;
483  }
484 
485  cpgask(0) ; // Disables the ``Type RETURN for next page:'' prompt
486 
487  }
488  else { // the graphic device has been opened previously
489 
490  cpgslct( graph_list[ngraph] ) ; // selects the appropriate device
491  }
492 
493  // Drawing
494  // -------
495 
496  // Taille des caracteres:
497  float size = float(1.3) ;
498  cpgsch(size) ;
499 
500  // Epaisseur des traits:
501  int lepais = 1 ;
502  cpgslw(lepais) ;
503 
504  // Fonte axes: caracteres romains:
505  cpgscf(2) ;
506 
507  // Draw the figure
508  float uuamp = uumax - uumin ;
509  float uumin1 = uumin - float(0.05) * uuamp ;
510  float uumax1 = uumax + float(0.05) * uuamp ;
511  cpgsls(1) ;
512  cpgenv(xmin, xmax, uumin1, uumax1, 0, 0 ) ;
513  cpglab(nomx,nomy,title) ;
514 
515 
516  for (int i=0; i<nprof; i++) {
517  const float* uudes = uutab + i*nx ;
518  const float* xdes = xtab + i*nx ;
519 
520  if (line_style == 0x0) cpgsls(i%5 + 1) ;
521  else cpgsls(line_style[i]) ;
522 
523  cpgline(nx, xdes, uudes) ;
524  }
525 
526  // Plot of domain boundaries
527  // -------------------------
528 
529  if (nbound > 0) {
530  float xb[2] ;
531  float yb[2] ;
532  yb[0] = uumin1 ;
533  yb[1] = uumax1 ;
534  cpgsls(3) ; // lignes en trait mixte
535  cpgsci(3) ; // couleur verte
536  for (int i=0; i<nbound; i++) {
537  xb[0] = xbound[i] ;
538  xb[1] = xbound[i] ;
539  cpgline(2, xb, yb) ;
540  }
541  cpgsls(1) ; // retour aux lignes en trait plein
542  cpgsci(1) ; // couleur noire
543  }
544 
545  if (closeit) {
546  cpgclos() ;
547  graph_list[ngraph] = 0 ;
548  }
549 
550 }
551 
552 }
553 
Lorene prototypes.
Definition: app_hor.h:64
void des_profile(const float *uutab, int nx, float xmin, float xmax, const char *nomx, const char *nomy, const char *title, const char *device=0x0, int nbound=0, float *xbound=0x0)
Basic routine for drawing a single profile with uniform x sampling.
Definition: des_profile.C:91
void des_profile_mult(const float *uutab, int nprof, int nx, float xmin, float xmax, const char *nomx, const char *nomy, const char *title, const int *line_style, int ngraph, bool closeit, const char *device=0x0, int nbound=0, float *xbound=0x0)
Basic routine for drawing multiple profiles with uniform x sampling.
Definition: des_profile.C:183