From 2c956f0fb658cec6c927c1ce31c9ad89a8b1026b Mon Sep 17 00:00:00 2001 From: "Joachim Wuttke (laptop)" <j.wuttke@fz-juelich.de> Date: Wed, 11 Mar 2009 11:44:14 +0100 Subject: [PATCH] more info when points out of range --- src/dualplot.cpp | 56 ++++++++++++++++++++++++------------------------ src/dualplot.h | 3 ++- src/edif.cpp | 3 ++- 3 files changed, 32 insertions(+), 30 deletions(-) diff --git a/src/dualplot.cpp b/src/dualplot.cpp index 72c0449d..b350efd5 100644 --- a/src/dualplot.cpp +++ b/src/dualplot.cpp @@ -437,20 +437,18 @@ void NPlot::Box() ps_accu.push_back( "\n%% modeDD\nplotbefore\n" ); } -void NPlot::Line(const int lstyle, - const vector<double> x, const vector<double> y, - const vector<double>* z, - const string xco, const string yco) +void NPlot::Line( const int lstyle, + const vector<double> x, const vector<double> y, + const vector<double>* z, + const string xco, const string yco, + const string info ) { - double *xp, *yp; uint np=0, nxl=0, nxh=0, nyl=0, nyh=0; uint n=x.size(); - if (n!=y.size()) { - printf("PROG ERR NPLot::Line x.size<>y.size\n"); - return; - } - xp = (double *) malloc(sizeof(double)*n); - yp = (double *) malloc(sizeof(double)*n); + if (n!=y.size()) + throw string( "PROG ERR NPLot::Line x.size<>y.size" ); + vector<double> xp, yp; + for (uint i=0; i<n; i++) { if(!X.force && !X.R.contained(x[i])) { if (x[i]<=X.R.inf) nxl++; @@ -462,19 +460,26 @@ void NPlot::Line(const int lstyle, if (y[i]>=Y.R.sup) nyh++; continue; } - if(np==maxpoints && np<n) { + if( np==maxpoints && np<n) { printf("reached maxpoints at %g\n", x[i]); } - xp[np] = x[i]; - yp[np] = y[i]; - np++; - if(np>maxpoints) i += maxpoints; + xp.push_back( x[i] ); + yp.push_back( y[i] ); + np = xp.size(); + if( np > maxpoints ) // continue in large steps + i += maxpoints; } - if (np==0) { - printf("no points in data range:\n" - "of %d points are\n %d left and %d right of the x range," - "\n %d below and %d above of the y range\n", - n, nxl, nxh, nyl, nyh); + if ( np==0 ) { + printf( "%s : all %d points outside plot range:\n", + info.c_str(), n ); + if( nxl ) + printf( " %d points < xmin\n", nxl ); + if( nxh ) + printf( " %d points > xmax\n", nxh ); + if( nyl ) + printf( " %d points < ymin\n", nyl ); + if( nyh ) + printf( " %d points > ymax\n", nyh ); return; } @@ -489,10 +494,8 @@ void NPlot::Line(const int lstyle, if (lstyle<0) gp_fnames += " with lines"; FILE *gp_fd; - if (!(gp_fd = fopen(gp_fnam, "w"))) { - printf( "cannot save gnuplot data to %s", gp_fnam ); - return; - } + if (!(gp_fd = fopen(gp_fnam, "w"))) + throw string("cannot save gnuplot data to ") + gp_fnam; for (uint i=0; i<np; i++) fprintf(gp_fd, "%20.12g %20.12g\n", xp[i], yp[i]); fclose(gp_fd); @@ -527,9 +530,6 @@ void NPlot::Line(const int lstyle, i==0 ? 'i' : i==np-1 ? 'f' : ' ', xp[i], yp[i] ); ps_accu.push_back( outlin ); } - - free(xp); - free(yp); } void NPlot::Doc (vector<string> lDoc) diff --git a/src/dualplot.h b/src/dualplot.h index b08f7c67..9d8fc943 100644 --- a/src/dualplot.h +++ b/src/dualplot.h @@ -66,7 +66,8 @@ namespace NPlot { // additional declarations in dualplot.cpp void Line( const int lstyle, const vector<double> x, const vector<double> y, const vector<double>* z, - const string xco, const string yco ); + const string xco, const string yco, + const string info ); void Doc (vector<string> lDoc); void Save( bool full_outfile ); void Dialog(void); diff --git a/src/edif.cpp b/src/edif.cpp index 3b8d41d4..7ce89e78 100644 --- a/src/edif.cpp +++ b/src/edif.cpp @@ -1008,7 +1008,8 @@ void NEdif::Plot( bool add ) } else throw string( "PROGRAM ERROR plot invalid *e" ); NPlot::Line( lstyle, s->x, s->y, e->Z(j), - e->P()->xco.str(), e->P()->yco.str() ); + e->P()->xco.str(), e->P()->yco.str(), + "file "+strg(k)+" scan "+strg(j) ); } NPlot::Doc( e->P()->lDoc ); if( fc ) -- GitLab