des_profile.C

00001 /*
00002  *  Basic routine for drawing profiles.
00003  */
00004 
00005 /*
00006  *   Copyright (c) 1999-2004 Eric Gourgoulhon
00007  *
00008  *   This file is part of LORENE.
00009  *
00010  *   LORENE is free software; you can redistribute it and/or modify
00011  *   it under the terms of the GNU General Public License as published by
00012  *   the Free Software Foundation; either version 2 of the License, or
00013  *   (at your option) any later version.
00014  *
00015  *   LORENE is distributed in the hope that it will be useful,
00016  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018  *   GNU General Public License for more details.
00019  *
00020  *   You should have received a copy of the GNU General Public License
00021  *   along with LORENE; if not, write to the Free Software
00022  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00023  *
00024  */
00025 
00026 
00027 char des_profile_C[] = "$Header: /cvsroot/Lorene/C++/Source/Non_class_members/Graphics/des_profile.C,v 1.9 2012/01/17 10:35:46 j_penner Exp $" ;
00028 
00029 /*
00030  * $Id: des_profile.C,v 1.9 2012/01/17 10:35:46 j_penner Exp $
00031  * $Log: des_profile.C,v $
00032  * Revision 1.9  2012/01/17 10:35:46  j_penner
00033  * added point plot
00034  *
00035  * Revision 1.8  2008/08/19 06:42:00  j_novak
00036  * Minor modifications to avoid warnings with gcc 4.3. Most of them concern
00037  * cast-type operations, and constant strings that must be defined as const char*
00038  *
00039  * Revision 1.7  2005/03/25 19:56:28  e_gourgoulhon
00040  * Added plot of domain boundaries (new arguments nbound and xbound).
00041  *
00042  * Revision 1.6  2004/02/17 22:19:22  e_gourgoulhon
00043  * Changed prototype of des_profile_mult.
00044  * Added version of des_profile_mult with arbitrary x sampling.
00045  *
00046  * Revision 1.5  2004/02/16 10:54:08  e_gourgoulhon
00047  * Added #include <stdlib.h>.
00048  *
00049  * Revision 1.4  2004/02/15 21:56:49  e_gourgoulhon
00050  * des_profile_mult: added call to cpgask(0).
00051  *
00052  * Revision 1.3  2004/02/12 16:21:57  e_gourgoulhon
00053  * Added new function des_profile_mult.
00054  *
00055  * Revision 1.2  2002/10/16 14:36:57  j_novak
00056  * Reorganization of #include instructions of standard C++, in order to
00057  * use experimental version 3 of gcc.
00058  *
00059  * Revision 1.1.1.1  2001/11/20 15:19:29  e_gourgoulhon
00060  * LORENE
00061  *
00062  * Revision 1.1  1999/12/09  16:38:41  eric
00063  * Initial revision
00064  *
00065  *
00066  * $Header: /cvsroot/Lorene/C++/Source/Non_class_members/Graphics/des_profile.C,v 1.9 2012/01/17 10:35:46 j_penner Exp $
00067  *
00068  */
00069 
00070 
00071 // C++ headers:
00072 #include"headcpp.h"
00073 
00074 // C headers:
00075 #include <stdlib.h>
00076 #include <math.h>
00077 #include <cpgplot.h>
00078 
00079 
00080 //******************************************************************************
00081 //      Single profile, single device, uniform sampling 
00082 //******************************************************************************
00083 
00084 void des_profile(const float* uutab, int nx, float xmin, float xmax, 
00085          const char* nomx, const char* nomy, 
00086                  const char* title, const char* device,
00087                  int nbound, float* xbound) {
00088          
00089     // Search for the extremal values of the field : 
00090     // -------------------------------------------
00091 
00092     float uumin = uutab[0] ;
00093     float uumax = uutab[0] ;
00094     for (int i=1; i<nx; i++) {
00095     uumin = (uutab[i] < uumin) ? uutab[i] : uumin ;
00096     uumax = (uutab[i] > uumax) ? uutab[i] : uumax ; 
00097     }
00098 
00099     cout << "  " << nomy << " : min, max : " << uumin << "   " << uumax 
00100          << endl ; 
00101 
00102     // Points abscisses : 
00103     // ----------------
00104     
00105     float* xx = new float[nx] ; 
00106     float hx = (xmax-xmin)/float(nx-1) ;
00107     for(int i=0; i<nx; i++) {
00108     xx[i] = xmin + float(i) * hx ; 
00109     }
00110          
00111     // Graphics display
00112     // ----------------
00113     
00114     if (device == 0x0) {
00115     device = "?" ; 
00116     }
00117     
00118     int ier = cpgbeg(0, device, 1, 1) ;
00119     if (ier != 1) {
00120     cout << "des_profile: problem in opening PGPLOT display !" << endl ;
00121     }
00122     
00123     // Taille des caracteres:
00124     float size = float(1.3) ;
00125     cpgsch(size) ;
00126     
00127     // Epaisseur des traits:
00128     int lepais = 1 ; 
00129     cpgslw(lepais) ;
00130     
00131     // Fonte axes: caracteres romains:
00132     cpgscf(2) ;
00133 
00134     // Cadre de la figure
00135     float uuamp = uumax - uumin ; 
00136     float uumin1 = uumin - float(0.05) * uuamp ; 
00137     float uumax1 = uumax + float(0.05) * uuamp ; 
00138     cpgenv(xmin, xmax, uumin1, uumax1, 0, 0 ) ; 
00139     cpglab(nomx,nomy,title) ;
00140     
00141     // Drawing of curve 
00142     cpgline(nx, xx, uutab) ; 
00143     
00144     
00145     // Plot of domain boundaries
00146     // -------------------------
00147     
00148     if (nbound > 0) {
00149         float xb[2] ; 
00150         float yb[2] ; 
00151         yb[0] = uumin1 ; 
00152         yb[1] = uumax1 ; 
00153         cpgsls(3) ;     // lignes en trait mixte
00154         cpgsci(3) ;     // couleur verte
00155         for (int i=0; i<nbound; i++) {
00156             xb[0] = xbound[i] ; 
00157             xb[1] = xbound[i] ; 
00158             cpgline(2, xb, yb) ; 
00159         }
00160         cpgsls(1) ;     // retour aux lignes en trait plein
00161         cpgsci(1) ;     // couleur noire
00162     }
00163 
00164     cpgend() ; 
00165     
00166     delete [] xx ; 
00167 
00168 }
00169 
00170 
00171 
00172 //******************************************************************************
00173 //      Multiple profiles, multiple device, uniform sampling 
00174 //******************************************************************************
00175 
00176 void des_profile_mult(const float* uutab, int nprof, int nx,
00177             float xmin, float xmax, const char* nomx, const char* nomy, 
00178         const char* title, const int* line_style, 
00179             int ngraph, bool closeit, const char* device,
00180             int nbound, float* xbound) {
00181 
00182     const int ngraph_max = 100 ; 
00183     static int graph_list[ngraph_max] ; 
00184     static bool first_call = true ; 
00185     
00186     // First call operations
00187     // ---------------------
00188         
00189     if (first_call) {       // initialization of all the graphic devices to 0 :
00190         for (int i=0; i<ngraph_max; i++) {
00191             graph_list[i] = 0 ; 
00192         } 
00193         first_call = false ; 
00194     }
00195                   
00196          
00197     // Search for the extremal values of the field : 
00198     // -------------------------------------------
00199 
00200     int ntot = nprof * nx ; 
00201     float uumin = uutab[0] ;
00202     float uumax = uutab[0] ;
00203     for (int i=1; i<ntot; i++) {
00204         if (uutab[i] < uumin) uumin = uutab[i] ;
00205         if (uutab[i] > uumax) uumax = uutab[i] ;
00206     }
00207 
00208     cout << "  " << nomy << " : min, max : " << uumin << "   " << uumax 
00209          << endl ; 
00210 
00211     // Points abscisses : 
00212     // ----------------
00213     
00214     float* xx = new float[nx] ; 
00215     float hx = (xmax-xmin)/float(nx-1) ;
00216     for(int i=0; i<nx; i++) {
00217     xx[i] = xmin + float(i) * hx ; 
00218     }
00219          
00220     // Graphics display
00221     // ----------------
00222     
00223     // Opening of the device
00224     
00225     if ( (ngraph < 0) || (ngraph >= ngraph_max) ) {
00226         cerr << "des_profile_mult : graph index out of range ! \n" ;
00227         cerr << " ngraph = " << ngraph << "  while range = 0, " 
00228             << ngraph_max-1 << endl ; 
00229         abort() ;
00230     }
00231     
00232     if (graph_list[ngraph] == 0) { // opening is required
00233                                    // -------------------
00234     
00235         if (device == 0x0) device = "?" ; 
00236    
00237         graph_list[ngraph] = cpgopen(device) ; 
00238         
00239         if ( graph_list[ngraph] <= 0 ) {
00240             cerr << "des_profile_mult: problem in opening PGPLOT display !\n" ;
00241             abort() ; 
00242         }
00243         
00244         cpgask(0) ;  // Disables the ``Type RETURN for next page:'' prompt
00245         
00246     }
00247     else {   // the graphic device has been opened previously   
00248 
00249         cpgslct( graph_list[ngraph] ) ; // selects the appropriate device
00250     }
00251     
00252     // Drawing
00253     // -------
00254      
00255     // Taille des caracteres:
00256     float size = float(1.3) ;
00257     cpgsch(size) ;
00258     
00259     // Epaisseur des traits:
00260     int lepais = 1 ; 
00261     cpgslw(lepais) ;
00262     
00263     // Fonte axes: caracteres romains:
00264     cpgscf(2) ;
00265 
00266     // Cadre de la figure
00267     float uuamp = uumax - uumin ; 
00268     float uumin1 = uumin - float(0.05) * uuamp ; 
00269     float uumax1 = uumax + float(0.05) * uuamp ; 
00270     cpgsls(1) ;  
00271     cpgenv(xmin, xmax, uumin1, uumax1, 0, 0 ) ; 
00272     cpglab(nomx,nomy,title) ;
00273      
00274     
00275     for (int i=0; i<nprof; i++) {
00276     const float* uudes = uutab + i*nx ;
00277         
00278         if (line_style == 0x0) cpgsls(i%5 + 1) ; 
00279         else cpgsls(line_style[i]) ;  
00280         
00281         cpgline(nx, xx, uudes) ; 
00282     }
00283     
00284     // Plot of domain boundaries
00285     // -------------------------
00286     
00287     if (nbound > 0) {
00288         float xb[2] ; 
00289         float yb[2] ; 
00290         yb[0] = uumin1 ; 
00291         yb[1] = uumax1 ; 
00292         cpgsls(3) ;     // lignes en trait mixte
00293         cpgsci(3) ;     // couleur verte
00294         for (int i=0; i<nbound; i++) {
00295             xb[0] = xbound[i] ; 
00296             xb[1] = xbound[i] ; 
00297             cpgline(2, xb, yb) ; 
00298         }
00299         cpgsls(1) ;     // retour aux lignes en trait plein
00300         cpgsci(1) ;     // couleur noire
00301     }
00302 
00303 
00304     if (closeit) {
00305         cpgclos() ; 
00306         graph_list[ngraph] = 0 ; 
00307     }
00308     
00309     delete [] xx ; 
00310 
00311 }
00312 
00313 
00314 //******************************************************************************
00315 //      Single profile, single device, arbitrary sampling 
00316 //******************************************************************************
00317 
00318 void des_profile(const float* uutab, int nx, const float *xtab, 
00319          const char* nomx, const char* nomy, 
00320                  const char* title, const char* device,
00321                  int nbound, float* xbound) {
00322          
00323     // Search for the extremal values of the field : 
00324     // -------------------------------------------
00325 
00326     float uumin = uutab[0] ;
00327     float uumax = uutab[0] ;
00328     float xmin = xtab[0] ;
00329     float xmax = xtab[0] ;
00330     for (int i=1; i<nx; i++) {
00331     uumin = (uutab[i] < uumin) ? uutab[i] : uumin ;
00332     uumax = (uutab[i] > uumax) ? uutab[i] : uumax ; 
00333     xmin = (xtab[i] < xmin) ? xtab[i] : xmin ;
00334     xmax = (xtab[i] > xmax) ? xtab[i] : xmax ;  
00335     }
00336 
00337     cout << "  " << nomy << " : min, max : " << uumin << "   " << uumax << endl;
00338     cout << "  " << "domain: " << "min, max : " << xmin << "   " << xmax << endl ; 
00339 
00340     // Points abscisses : 
00341     // ----------------
00342 /*    
00343     float* xx = new float[nx] ; 
00344     float hx = (xmax-xmin)/float(nx-1) ;
00345     for(int i=0; i<nx; i++) {
00346     xx[i] = xmin + float(i) * hx ; 
00347     }
00348 */         
00349     // Graphics display
00350     // ----------------
00351     
00352     if (device == 0x0) {
00353     device = "?" ; 
00354     }
00355     
00356     int ier = cpgbeg(0, device, 1, 1) ;
00357     if (ier != 1) {
00358     cout << "des_profile: problem in opening PGPLOT display !" << endl ;
00359     }
00360     
00361     // Taille des caracteres:
00362     float size = float(1.3) ;
00363     cpgsch(size) ;
00364     
00365     // Epaisseur des traits:
00366     int lepais = 1 ; 
00367     cpgslw(lepais) ;
00368     
00369     // Fonte axes: caracteres romains:
00370     cpgscf(2) ;
00371 
00372     // Cadre de la figure
00373     float uuamp = uumax - uumin ; 
00374     float uumin1 = uumin - float(0.05) * uuamp ; 
00375     float uumax1 = uumax + float(0.05) * uuamp ; 
00376     cpgenv(xmin, xmax, uumin1, uumax1, 0, 0 ) ; 
00377     cpglab(nomx,nomy,title) ;
00378     
00379     // Drawing of curve 
00380     cpgline(nx, xtab, uutab) ; 
00381     
00382     
00383     // Plot of domain boundaries
00384     // -------------------------
00385     
00386     if (nbound > 0) {
00387         float xb[2] ; 
00388         float yb[2] ; 
00389         yb[0] = uumin1 ; 
00390         yb[1] = uumax1 ; 
00391         cpgsls(3) ;     // lignes en trait mixte
00392         cpgsci(3) ;     // couleur verte
00393         for (int i=0; i<nbound; i++) {
00394             xb[0] = xbound[i] ; 
00395             xb[1] = xbound[i] ; 
00396             cpgline(2, xb, yb) ; 
00397         }
00398         cpgsls(1) ;     // retour aux lignes en trait plein
00399         cpgsci(1) ;     // couleur noire
00400     }
00401 
00402     cpgend() ; 
00403 
00404 }
00405 
00406 
00407 
00408 //******************************************************************************
00409 //      Multiple profiles, multiple device, arbitrary sampling 
00410 //******************************************************************************
00411 
00412 void des_profile_mult(const float* uutab, int nprof, int nx, const float* xtab, 
00413             const char* nomx, const char* nomy, const char* title, 
00414             const int* line_style, int ngraph, bool closeit,
00415             const char* device, int nbound, float* xbound) {
00416 
00417     const int ngraph_max = 100 ; 
00418     static int graph_list[ngraph_max] ; 
00419     static bool first_call = true ; 
00420     
00421     // First call operations
00422     // ---------------------
00423         
00424     if (first_call) {       // initialization of all the graphic devices to 0 :
00425         for (int i=0; i<ngraph_max; i++) {
00426             graph_list[i] = 0 ; 
00427         } 
00428         first_call = false ; 
00429     }
00430                   
00431          
00432     // Search for the extremal values of x and of the field : 
00433     // ----------------------------------------------------
00434 
00435     int ntot = nprof * nx ; 
00436     float uumin = uutab[0] ;
00437     float uumax = uutab[0] ;
00438     for (int i=1; i<ntot; i++) {
00439         if (uutab[i] < uumin) uumin = uutab[i] ;
00440         if (uutab[i] > uumax) uumax = uutab[i] ;
00441     }
00442 
00443     float xmin = xtab[0] ;
00444     float xmax = xtab[0] ;
00445     for (int i=1; i<ntot; i++) {
00446         if (xtab[i] < xmin) xmin = xtab[i] ;
00447         if (xtab[i] > xmax) xmax = xtab[i] ;
00448     }
00449 
00450     cout << "  " << nomy << " : min, max : " << uumin << "   " << uumax 
00451          << endl ; 
00452 
00453          
00454     // Graphics display
00455     // ----------------
00456     
00457     // Opening of the device
00458     
00459     if ( (ngraph < 0) || (ngraph >= ngraph_max) ) {
00460         cerr << "des_profile_mult : graph index out of range ! \n" ;
00461         cerr << " ngraph = " << ngraph << "  while range = 0, " 
00462             << ngraph_max-1 << endl ; 
00463         abort() ;
00464     }
00465     
00466     if (graph_list[ngraph] == 0) { // opening is required
00467                                    // -------------------
00468     
00469         if (device == 0x0) device = "?" ; 
00470    
00471         graph_list[ngraph] = cpgopen(device) ; 
00472         
00473         if ( graph_list[ngraph] <= 0 ) {
00474             cerr << "des_profile_mult: problem in opening PGPLOT display !\n" ;
00475             abort() ; 
00476         }
00477         
00478         cpgask(0) ;  // Disables the ``Type RETURN for next page:'' prompt
00479         
00480     }
00481     else {   // the graphic device has been opened previously   
00482 
00483         cpgslct( graph_list[ngraph] ) ; // selects the appropriate device
00484     }
00485     
00486     // Drawing
00487     // -------
00488      
00489     // Taille des caracteres:
00490     float size = float(1.3) ;
00491     cpgsch(size) ;
00492     
00493     // Epaisseur des traits:
00494     int lepais = 1 ; 
00495     cpgslw(lepais) ;
00496     
00497     // Fonte axes: caracteres romains:
00498     cpgscf(2) ;
00499 
00500     // Draw the figure
00501     float uuamp = uumax - uumin ; 
00502     float uumin1 = uumin - float(0.05) * uuamp ; 
00503     float uumax1 = uumax + float(0.05) * uuamp ; 
00504     cpgsls(1) ;  
00505     cpgenv(xmin, xmax, uumin1, uumax1, 0, 0 ) ; 
00506     cpglab(nomx,nomy,title) ;
00507      
00508     
00509     for (int i=0; i<nprof; i++) {
00510     const float* uudes = uutab + i*nx ;
00511     const float* xdes = xtab + i*nx ;
00512         
00513         if (line_style == 0x0) cpgsls(i%5 + 1) ; 
00514         else cpgsls(line_style[i]) ;  
00515         
00516         cpgline(nx, xdes, uudes) ; 
00517     }
00518     
00519     // Plot of domain boundaries
00520     // -------------------------
00521     
00522     if (nbound > 0) {
00523         float xb[2] ; 
00524         float yb[2] ; 
00525         yb[0] = uumin1 ; 
00526         yb[1] = uumax1 ; 
00527         cpgsls(3) ;     // lignes en trait mixte
00528         cpgsci(3) ;     // couleur verte
00529         for (int i=0; i<nbound; i++) {
00530             xb[0] = xbound[i] ; 
00531             xb[1] = xbound[i] ; 
00532             cpgline(2, xb, yb) ; 
00533         }
00534         cpgsls(1) ;     // retour aux lignes en trait plein
00535         cpgsci(1) ;     // couleur noire
00536     }
00537 
00538     if (closeit) {
00539         cpgclos() ; 
00540         graph_list[ngraph] = 0 ; 
00541     }
00542     
00543 }
00544 

Generated on Tue Feb 7 01:35:16 2012 for LORENE by  doxygen 1.4.6