00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040 #include <iostream>
00041
00042 using namespace std ;
00043
00044 #include <stdlib.h>
00045 #include <assert.h>
00046
00047 #include <cpgplot.h>
00048
00049 #include "plot.h"
00050
00051
00052 namespace Plotid {
00053 const int nfig_max = 100 ;
00054 int fig_id[nfig_max] ;
00055 }
00056
00057
00058
00059 void plot_init() {
00060 using namespace Plotid ;
00061
00062 static bool never_called = true ;
00063
00064 if (never_called) {
00065 for (int i=0; i<nfig_max; i++) {
00066 fig_id[i] = 0 ;
00067 }
00068 never_called = false ;
00069 }
00070
00071 }
00072
00073
00074
00075 void plot_open(int nfig, double ymin, double ymax, const char* title,
00076 const char* label_y, const char* device) {
00077 using namespace Plotid ;
00078
00079 assert( fig_id[nfig] == 0 ) ;
00080
00081 if (device == 0x0) device = "?" ;
00082
00083 fig_id[nfig] = cpgopen(device) ;
00084
00085 if ( fig_id[nfig] <= 0 ) {
00086 cerr << "plot_profile: problem in opening PGPLOT display !\n" ;
00087 abort() ;
00088 }
00089
00090 cpgask(0) ;
00091
00092 cpgsch(1.3) ;
00093
00094 cpgslw(4) ;
00095
00096 cpgscf(2) ;
00097
00098 cpgsls(1) ;
00099
00100
00101 cpgenv(-1., 1., float(ymin), float(ymax), 0, 0 ) ;
00102
00103
00104 if (label_y == 0x0) label_y = "y" ;
00105 if (title == 0x0) title = " " ;
00106 cpglab("x", label_y, title) ;
00107
00108 }
00109
00110
00111
00112
00113
00114 void plot_close(int nfig) {
00115
00116 using namespace Plotid ;
00117 plot_init() ;
00118
00119 if ( (nfig < 0) || (nfig >= nfig_max) ) {
00120 cerr << "plot_close : figure index out of range ! \n" ;
00121 cerr << " nfig = " << nfig << " while range = 0, "
00122 << nfig_max-1 << endl ;
00123 abort() ;
00124 }
00125
00126 if (fig_id[nfig] != 0) {
00127 cpgslct( fig_id[nfig] ) ;
00128 cpgclos() ;
00129 fig_id[nfig] = 0 ;
00130 }
00131
00132 }
00133
00134
00135
00136 void plot_close_all() {
00137
00138 using namespace Plotid ;
00139 plot_init() ;
00140
00141 for (int nfig = 0; nfig < nfig_max; nfig++) {
00142 if (fig_id[nfig] != 0) {
00143 cpgslct( fig_id[nfig] ) ;
00144 cpgclos() ;
00145 fig_id[nfig] = 0 ;
00146 }
00147 }
00148 }
00149
00150
00151
00152 void plot_profile(const double* yy, int nx, int color, int style,
00153 int nfig, double ymin, double ymax, const char* title,
00154 const char* label_y, const char* device) {
00155
00156 using namespace Plotid ;
00157 plot_init() ;
00158
00159
00160
00161 float* yyf = new float[nx] ;
00162 for (int i=0; i<nx; i++) {
00163 yyf[i] = yy[i] ;
00164 }
00165
00166
00167
00168 float xmin = -1. ;
00169 float xmax = 1. ;
00170 float* xx = new float[nx] ;
00171 float hx = (xmax-xmin)/float(nx-1) ;
00172 for(int i=0; i<nx; i++) {
00173 xx[i] = xmin + i * hx ;
00174 }
00175
00176
00177
00178
00179
00180
00181 if ( (nfig < 0) || (nfig >= nfig_max) ) {
00182 cerr << "plot_profile : graph index out of range ! \n" ;
00183 cerr << " nfig = " << nfig << " while range = 0, "
00184 << nfig_max-1 << endl ;
00185 abort() ;
00186 }
00187
00188 if (fig_id[nfig] == 0) {
00189
00190 plot_open(nfig, ymin, ymax, title, label_y, device ) ;
00191
00192 }
00193 else {
00194
00195 cpgslct( fig_id[nfig] ) ;
00196 }
00197
00198
00199 cpgsci(color) ;
00200 cpgsls(style) ;
00201 cpgline(nx, xx, yyf) ;
00202
00203 delete [] xx ;
00204 delete [] yyf ;
00205
00206 }
00207
00208
00209
00210 void plot_point(double x, double y, int color, int nfig, double ymin,
00211 double ymax, const char* title, const char* label_y, const char* device) {
00212
00213 using namespace Plotid ;
00214 plot_init() ;
00215
00216 if ( (nfig < 0) || (nfig >= nfig_max) ) {
00217 cerr << "plot_point : figure index out of range ! \n" ;
00218 cerr << " nfig = " << nfig << " while range = 0, "
00219 << nfig_max-1 << endl ;
00220 abort() ;
00221 }
00222
00223 if (fig_id[nfig] == 0) {
00224
00225 plot_open(nfig, ymin, ymax, title, label_y, device ) ;
00226
00227 }
00228 else {
00229
00230 cpgslct( fig_id[nfig] ) ;
00231 }
00232
00233 cpgsci(color) ;
00234
00235 cpgpt1(float(x), float(y), 24) ;
00236
00237 }
00238
00239
00240
00241 void plot_point_set(int np, const double* xx, const double* yy, int color,
00242 int nfig, double ymin, double ymax, const char* title,
00243 const char* label_y, const char* device) {
00244
00245 using namespace Plotid ;
00246 plot_init() ;
00247
00248 if ( (nfig < 0) || (nfig >= nfig_max) ) {
00249 cerr << "plot_point : figure index out of range ! \n" ;
00250 cerr << " nfig = " << nfig << " while range = 0, "
00251 << nfig_max-1 << endl ;
00252 abort() ;
00253 }
00254
00255 if (fig_id[nfig] == 0) {
00256
00257 plot_open(nfig, ymin, ymax, title, label_y, device ) ;
00258
00259 }
00260 else {
00261
00262 cpgslct( fig_id[nfig] ) ;
00263 }
00264
00265 cpgsci(color) ;
00266
00267 float* x1 = new float[np] ;
00268 float* y1 = new float[np] ;
00269
00270 for (int i=0; i<np; i++) {
00271 x1[i] = xx[i] ;
00272 y1[i] = yy[i] ;
00273 }
00274 cpgpt(np, x1, y1, 24) ;
00275
00276 delete [] x1 ;
00277 delete [] y1 ;
00278 }