| 1 |
/* |
| 2 |
* Definition of elementary graphical functions |
| 3 |
*/ |
| 4 |
|
| 5 |
/* |
| 6 |
* Copyright (c) 2005 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 |
* $Id: plot.C,v 1.3 2014/10/06 15:09:48 j_novak Exp $ |
| 28 |
* $Log: plot.C,v $ |
| 29 |
* Revision 1.3 2014/10/06 15:09:48 j_novak |
| 30 |
* Modified #include directives to use c++ syntax. |
| 31 |
* |
| 32 |
* Revision 1.2 2005/11/14 14:12:10 e_gourgoulhon |
| 33 |
* Added include <assert.h> |
| 34 |
* |
| 35 |
* Revision 1.1 2005/11/14 01:57:00 e_gourgoulhon |
| 36 |
* First version |
| 37 |
* |
| 38 |
* |
| 39 |
* $Header: /cvsroot/Lorene/School05/Monday/plot.C,v 1.3 2014/10/06 15:09:48 j_novak Exp $ |
| 40 |
* |
| 41 |
*/ |
| 42 |
|
| 43 |
#include <iostream> |
| 44 |
|
| 45 |
using namespace std ; |
| 46 |
|
| 47 |
#include <cstdlib> |
| 48 |
#include <cassert> |
| 49 |
|
| 50 |
#include <cpgplot.h> |
| 51 |
|
| 52 |
#include "plot.h" |
| 53 |
|
| 54 |
|
| 55 |
namespace Plotid { |
| 56 |
const int nfig_max = 100 ; |
| 57 |
int fig_id[nfig_max] ; |
| 58 |
} |
| 59 |
|
| 60 |
//=========================================================================== |
| 61 |
|
| 62 |
void plot_init() { |
| 63 |
using namespace Plotid ; |
| 64 |
|
| 65 |
static bool never_called = true ; |
| 66 |
|
| 67 |
if (never_called) { |
| 68 |
for (int i=0; i<nfig_max; i++) { |
| 69 |
fig_id[i] = 0 ; |
| 70 |
} |
| 71 |
never_called = false ; |
| 72 |
} |
| 73 |
|
| 74 |
} |
| 75 |
|
| 76 |
//=========================================================================== |
| 77 |
|
| 78 |
void plot_open(int nfig, double ymin, double ymax, const char* title, |
| 79 |
const char* label_y, const char* device) { |
| 80 |
using namespace Plotid ; |
| 81 |
|
| 82 |
assert( fig_id[nfig] == 0 ) ; |
| 83 |
|
| 84 |
if (device == 0x0) device = "?" ; |
| 85 |
|
| 86 |
fig_id[nfig] = cpgopen(device) ; |
| 87 |
|
| 88 |
if ( fig_id[nfig] <= 0 ) { |
| 89 |
cerr << "plot_profile: problem in opening PGPLOT display !\n" ; |
| 90 |
abort() ; |
| 91 |
} |
| 92 |
|
| 93 |
cpgask(0) ; // Disables the ``Type RETURN for next page:'' prompt |
| 94 |
|
| 95 |
cpgsch(1.3) ; // Character size |
| 96 |
|
| 97 |
cpgslw(4) ; // Line width |
| 98 |
|
| 99 |
cpgscf(2) ; // Axis fonts = Roman |
| 100 |
|
| 101 |
cpgsls(1) ; // Continous lines |
| 102 |
|
| 103 |
// Sets the window : |
| 104 |
cpgenv(-1., 1., float(ymin), float(ymax), 0, 0 ) ; |
| 105 |
|
| 106 |
// Title and labels |
| 107 |
if (label_y == 0x0) label_y = "y" ; |
| 108 |
if (title == 0x0) title = " " ; |
| 109 |
cpglab("x", label_y, title) ; |
| 110 |
|
| 111 |
} |
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
//=========================================================================== |
| 116 |
|
| 117 |
void plot_close(int nfig) { |
| 118 |
|
| 119 |
using namespace Plotid ; |
| 120 |
plot_init() ; |
| 121 |
|
| 122 |
if ( (nfig < 0) || (nfig >= nfig_max) ) { |
| 123 |
cerr << "plot_close : figure index out of range ! \n" ; |
| 124 |
cerr << " nfig = " << nfig << " while range = 0, " |
| 125 |
<< nfig_max-1 << endl ; |
| 126 |
abort() ; |
| 127 |
} |
| 128 |
|
| 129 |
if (fig_id[nfig] != 0) { |
| 130 |
cpgslct( fig_id[nfig] ) ; // selects the appropriate device |
| 131 |
cpgclos() ; |
| 132 |
fig_id[nfig] = 0 ; |
| 133 |
} |
| 134 |
|
| 135 |
} |
| 136 |
|
| 137 |
//=========================================================================== |
| 138 |
|
| 139 |
void plot_close_all() { |
| 140 |
|
| 141 |
using namespace Plotid ; |
| 142 |
plot_init() ; |
| 143 |
|
| 144 |
for (int nfig = 0; nfig < nfig_max; nfig++) { |
| 145 |
if (fig_id[nfig] != 0) { |
| 146 |
cpgslct( fig_id[nfig] ) ; // selects the appropriate device |
| 147 |
cpgclos() ; |
| 148 |
fig_id[nfig] = 0 ; |
| 149 |
} |
| 150 |
} |
| 151 |
} |
| 152 |
|
| 153 |
//=========================================================================== |
| 154 |
|
| 155 |
void plot_profile(const double* yy, int nx, int color, int style, |
| 156 |
int nfig, double ymin, double ymax, const char* title, |
| 157 |
const char* label_y, const char* device) { |
| 158 |
|
| 159 |
using namespace Plotid ; |
| 160 |
plot_init() ; |
| 161 |
|
| 162 |
// Conversion double -> float |
| 163 |
// -------------------------- |
| 164 |
float* yyf = new float[nx] ; |
| 165 |
for (int i=0; i<nx; i++) { |
| 166 |
yyf[i] = yy[i] ; |
| 167 |
} |
| 168 |
|
| 169 |
// Points abscisses : |
| 170 |
// ---------------- |
| 171 |
float xmin = -1. ; |
| 172 |
float xmax = 1. ; |
| 173 |
float* xx = new float[nx] ; |
| 174 |
float hx = (xmax-xmin)/float(nx-1) ; |
| 175 |
for(int i=0; i<nx; i++) { |
| 176 |
xx[i] = xmin + i * hx ; |
| 177 |
} |
| 178 |
|
| 179 |
// Graphics display |
| 180 |
// ---------------- |
| 181 |
|
| 182 |
// Opening of the device |
| 183 |
|
| 184 |
if ( (nfig < 0) || (nfig >= nfig_max) ) { |
| 185 |
cerr << "plot_profile : graph index out of range ! \n" ; |
| 186 |
cerr << " nfig = " << nfig << " while range = 0, " |
| 187 |
<< nfig_max-1 << endl ; |
| 188 |
abort() ; |
| 189 |
} |
| 190 |
|
| 191 |
if (fig_id[nfig] == 0) { // opening is required |
| 192 |
|
| 193 |
plot_open(nfig, ymin, ymax, title, label_y, device ) ; |
| 194 |
|
| 195 |
} |
| 196 |
else { // the graphic device has been opened previously |
| 197 |
|
| 198 |
cpgslct( fig_id[nfig] ) ; // selects the appropriate device |
| 199 |
} |
| 200 |
|
| 201 |
// Drawing of the curve |
| 202 |
cpgsci(color) ; |
| 203 |
cpgsls(style) ; |
| 204 |
cpgline(nx, xx, yyf) ; |
| 205 |
|
| 206 |
delete [] xx ; |
| 207 |
delete [] yyf ; |
| 208 |
|
| 209 |
} |
| 210 |
|
| 211 |
//=========================================================================== |
| 212 |
|
| 213 |
void plot_point(double x, double y, int color, int nfig, double ymin, |
| 214 |
double ymax, const char* title, const char* label_y, const char* device) { |
| 215 |
|
| 216 |
using namespace Plotid ; |
| 217 |
plot_init() ; |
| 218 |
|
| 219 |
if ( (nfig < 0) || (nfig >= nfig_max) ) { |
| 220 |
cerr << "plot_point : figure index out of range ! \n" ; |
| 221 |
cerr << " nfig = " << nfig << " while range = 0, " |
| 222 |
<< nfig_max-1 << endl ; |
| 223 |
abort() ; |
| 224 |
} |
| 225 |
|
| 226 |
if (fig_id[nfig] == 0) { // opening is required |
| 227 |
|
| 228 |
plot_open(nfig, ymin, ymax, title, label_y, device ) ; |
| 229 |
|
| 230 |
} |
| 231 |
else { // the graphic device has been opened previously |
| 232 |
|
| 233 |
cpgslct( fig_id[nfig] ) ; // selects the appropriate device |
| 234 |
} |
| 235 |
|
| 236 |
cpgsci(color) ; |
| 237 |
|
| 238 |
cpgpt1(float(x), float(y), 24) ; |
| 239 |
|
| 240 |
} |
| 241 |
|
| 242 |
//=========================================================================== |
| 243 |
|
| 244 |
void plot_point_set(int np, const double* xx, const double* yy, int color, |
| 245 |
int nfig, double ymin, double ymax, const char* title, |
| 246 |
const char* label_y, const char* device) { |
| 247 |
|
| 248 |
using namespace Plotid ; |
| 249 |
plot_init() ; |
| 250 |
|
| 251 |
if ( (nfig < 0) || (nfig >= nfig_max) ) { |
| 252 |
cerr << "plot_point : figure index out of range ! \n" ; |
| 253 |
cerr << " nfig = " << nfig << " while range = 0, " |
| 254 |
<< nfig_max-1 << endl ; |
| 255 |
abort() ; |
| 256 |
} |
| 257 |
|
| 258 |
if (fig_id[nfig] == 0) { // opening is required |
| 259 |
|
| 260 |
plot_open(nfig, ymin, ymax, title, label_y, device ) ; |
| 261 |
|
| 262 |
} |
| 263 |
else { // the graphic device has been opened previously |
| 264 |
|
| 265 |
cpgslct( fig_id[nfig] ) ; // selects the appropriate device |
| 266 |
} |
| 267 |
|
| 268 |
cpgsci(color) ; |
| 269 |
|
| 270 |
float* x1 = new float[np] ; |
| 271 |
float* y1 = new float[np] ; |
| 272 |
|
| 273 |
for (int i=0; i<np; i++) { |
| 274 |
x1[i] = xx[i] ; |
| 275 |
y1[i] = yy[i] ; |
| 276 |
} |
| 277 |
cpgpt(np, x1, y1, 24) ; |
| 278 |
|
| 279 |
delete [] x1 ; |
| 280 |
delete [] y1 ; |
| 281 |
} |