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