#include #include "iohelp.h" #include "plotting.h" // ********************************************************************* // useful global variables const double symbol_size=0.6; int line_thickness=1,Rplot_type; double xmin,xmax,ymin,ymax; double x_major_tick_spacing,y_major_tick_spacing; int x_minor_tick_num,y_minor_tick_num; charString title,subtitle,xlabel,ylabel; plot_labels label_strings(1); int Nchannels; Svector channel_match,channel_label; ifstream in; ofstream html_out; xy_curves goldstone; xy_curves zero_line(1); // ******************************************************************************** void plot_label::assign(const charString& label_string, double xloc, double yloc) { label=label_string; label_xloc=xloc; label_yloc=yloc; } // ********************************************************************* plot_labels::plot_labels() {n=0;} plot_labels::plot_labels(int dim) {n=dim; if (dim<1){ cerr << "negative or zero dimension in plot_labels"<0){ m=new plot_label[n]; if (!m){ cerr << " problem allocating memory"<0) delete [] ++m;} void plot_labels::assign(int index, const charString& label_string, double xloc, double yloc) { if ((index>=1)&&(index<=n)){ m[index].assign(label_string,xloc,yloc); } else{ cerr << " bad index; no assignment made in plot_labels"<0) delete [] ++m; n=dim; if (n>0){ m=new plot_label[n]; if (!m){ cerr << " problem allocating memory"<=1)&&(i<=n)) ? m[i] : (cerr << "plot_labels out of bounds"<next=NULL; head->R_value=R; head->Rinv_value=Rinv; head->mean_value=ans; head->stdev_value=err; tail=head; } else{ tail->next=new node; tail=tail->next; tail->R_value=R; tail->Rinv_value=Rinv; tail->mean_value=ans; tail->stdev_value=err; tail->next=NULL; } } void delete_nodes() { if (head==NULL) return; node *pnode=head; node *pnext=head->next; while (pnext != NULL){ delete pnode; pnode=pnext; pnext=pnext->next; } head=NULL; tail=NULL; } // **************************************************************** // Rplot_type: 1 => x-axis is R, 0 => x-axis is 1/R int xydy_curve::setup_from_stream(ifstream& in, const charString& channel_string, int Rplot_type, int type_of_line, int color_of_line, int thickness_of_line, int type_of_symbol, int color_of_symbol, int fill_of_symbol, double size_of_symbol, const charString& label_string, double xloc_of_label, int yloc_of_label ) { const int maxlinelength=132; static char ff[maxlinelength]; Svector tokens; int flag; double Rvalue,Rinvvalue,ans,err; in.clear(); // in case eof reached in.seekg(0,ios::beg); // go back to beginning of file flag=Npoints=0; // first, search sequentially through file to find start // of relevant channel while (!flag){ in.getline(ff,maxlinelength); get_tokens(ff,tokens); if (tokens.dim()==5){ if (tokens(4).locate(channel_string)>=0) flag=1; } if (in.eof()){ //cerr << " could not find requested channel"<mean_value; dyvals(flag)=pnode->stdev_value; if (Rplot_type) xvals(flag)=pnode->R_value; else xvals(flag)=pnode->Rinv_value; pnode=pnode->next; } delete_nodes(); line_color=color_of_line; line_type=type_of_line; line_thickness=thickness_of_line; symbol_type=type_of_symbol; symbol_color=color_of_symbol; symbol_fill=fill_of_symbol; symbol_size=size_of_symbol; label=label_string; horizontal_label_loc=xloc_of_label; vertical_label_loc=yloc_of_label; return 0; } void xydy_curve::setup(int number_of_points, double *xvalues, double *yvalues, double *dyvalues, int type_of_line, int color_of_line, int thickness_of_line, int type_of_symbol, int color_of_symbol, int fill_of_symbol, double size_of_symbol, const charString& label_string, double xloc_of_label, int yloc_of_label ) { int i; Npoints=number_of_points; xvals.reset(Npoints); yvals.reset(Npoints); dyvals.reset(Npoints); for (i=1;i<=Npoints;i++){ xvals(i)=xvalues[i-1]; yvals(i)=yvalues[i-1]; dyvals(i)=dyvalues[i-1]; } line_color=color_of_line; line_type=type_of_line; line_thickness=thickness_of_line; symbol_type=type_of_symbol; symbol_color=color_of_symbol; symbol_fill=fill_of_symbol; symbol_size=size_of_symbol; label=label_string; horizontal_label_loc=xloc_of_label; vertical_label_loc=yloc_of_label; } void xydy_curve::wipeout() { Npoints=0; xvals(); yvals(); dyvals(); label=""; horizontal_label_loc=0.5; vertical_label_loc=0; } // ****************************************************************** xydy_curves::xydy_curves() {n=0;} xydy_curves::xydy_curves(int dim) {n=dim; if (dim<1){ cerr << "negative or zero dimension in xydy_curves"<0){ m=new xydy_curve[n]; if (!m){ cerr << " problem allocating memory"<0) delete [] ++m;} int xydy_curves::setup_from_stream(int index, ifstream& in, const charString& channel_string, int Rplot_type, int type_of_line, int color_of_line, int thickness_of_line, int type_of_symbol, int color_of_symbol, int fill_of_symbol, double size_of_symbol, const charString& label_string, double xloc_of_label, int yloc_of_label ) { if ((index>=1)&&(index<=n)){ return m[index].setup_from_stream(in,channel_string,Rplot_type, type_of_line,color_of_line, thickness_of_line,type_of_symbol, color_of_symbol,fill_of_symbol, size_of_symbol,label_string, xloc_of_label,yloc_of_label); } else{ cerr << " bad index; no assignment made in xydy_curves"<=1)&&(index<=n)){ m[index].setup(number_of_points, xvalues,yvalues, dyvalues,type_of_line,color_of_line, thickness_of_line,type_of_symbol, color_of_symbol,fill_of_symbol, size_of_symbol,label_string, xloc_of_label,yloc_of_label); } else{ cerr << " bad index; no assignment made in xydy_curves"<0) delete [] ++m; n=dim; if (n>0){ m=new xydy_curve[n]; if (!m){ cerr << " problem allocating memory"<=1)&&(i<=n)) ? m[i] : (cerr << "xydy_curves out of bounds"<0){ m=new xy_curve[n]; if (!m){ cerr << " problem allocating memory"<0) delete [] ++m;} void xy_curves::setup(int index, int number_of_points, double *xvalues, double *yvalues, int type_of_line, int color_of_line, int thickness_of_line, int type_of_symbol, int color_of_symbol, int fill_of_symbol, double size_of_symbol, const charString& label_string, double xloc_of_label, int yloc_of_label) { if ((index>=1)&&(index<=n)){ m[index].setup(number_of_points,xvalues,yvalues, type_of_line,color_of_line, thickness_of_line,type_of_symbol, color_of_symbol,fill_of_symbol, size_of_symbol,label_string, xloc_of_label,yloc_of_label); } else{ cerr << " bad index; no assignment made in xy_curves"<0) delete [] ++m; n=dim; if (n>0){ m=new xy_curve[n]; if (!m){ cerr << " problem allocating memory"<=1)&&(i<=n)) ? m[i] : (cerr << "xy_curves out of bounds"< left of smallest-x point // xloc_of_label > 1 => right of largest-x point // 0 < xloc_of_label < 1 => fractional distance between // smallest and largest x-values // // VERTICAL SPECIFICATION // // yloc_of_label > 0 => above the curve // yloc_of_label = 0 => on the curve // yloc_of_label < 0 => below the curve // void compute_label_location(const dvector& xvals, const dvector& yvals, const dvector& dyvals, double horizontal_label_loc, int vertical_label_loc, double xmin, double xmax, double ymin, double ymax, double& x_pos, double& y_pos) { int Npoints,Nerror,i; double xstart,xstop,dy,dx; Npoints=xvals.dim(); Nerror=dyvals.dim(); if ((horizontal_label_loc<=0.0)||(Npoints<2)){ // put label to left of smallest-x point x_pos=xmax; y_pos=ymax; for (i=1;i<=Npoints;i++){ if ((xvals(i)=xmin)){ x_pos=xvals(i); y_pos=yvals(i); } } x_pos-=0.05*(xmax-xmin); if (vertical_label_loc>0) y_pos+=0.06*(ymax-ymin); else if (vertical_label_loc<0) y_pos-=0.06*(ymax-ymin); } else if (horizontal_label_loc>=1.0){ // put label to right of largest-x point x_pos=xmin; y_pos=ymin; for (i=1;i<=Npoints;i++){ if ((xvals(i)>x_pos)&&(xvals(i)<=xmax)){ x_pos=xvals(i); y_pos=yvals(i); } } x_pos+=0.05*(xmax-xmin); if (vertical_label_loc>0) y_pos+=0.06*(ymax-ymin); else if (vertical_label_loc<0) y_pos-=0.06*(ymax-ymin); } else{ // put label fractional distance horizontal between smallest xstart=xmax; xstop=xmin; // and largest-x values for (i=1;i<=Npoints;i++){ if ((xvals(i)=xmin)) xstart=xvals(i); if ((xvals(i)>xstop)&&(xvals(i)<=xmax)) xstop=xvals(i); } x_pos=xstart+(xstop-xstart)*horizontal_label_loc; int k1=0,k2=0; double x1=xmin,x2=xmax,y1=ymin,y2=ymax; for (i=1;i<=Npoints;i++){ if ((xvals(i)x1)){ x1=xvals(i); y1=yvals(i); k1=i;} if ((xvals(i)>x_pos)&&(xvals(i)dyvals(k2))?dyvals(k1):dyvals(k2)); double r1=1.0/(xmax-xmin), r2=1.0/(ymax-ymin); double dh,dhmax=0.0,h=0.07+dy*r2; if (vertical_label_loc<0) h=-h; y_pos+=(ymax-ymin)*h; for (i=1;i<=Npoints;i++){ dx=r1*(xvals(i)-x_pos); dy=fabs(r2*(yvals(i)-y_pos)); if ((dx*dx+dy*dy)dhmax) dhmax=dh; } } if (vertical_label_loc<0) dhmax=-dhmax; y_pos+=dhmax*(ymax-ymin); } } void compute_label_location(const dvector& xvals, const dvector& yvals, double horizontal_label_loc, int vertical_label_loc, double xmin, double xmax, double ymin, double ymax, double& x_pos, double& y_pos) { dvector dyvals; compute_label_location(xvals,yvals,dyvals,horizontal_label_loc,vertical_label_loc, xmin,xmax,ymin,ymax,x_pos,y_pos); } // ***************************************************************** // // This procedure produces a plot // // ******************************************************************* void produce_plot(const charString& filename, const charString& title, const charString& subtitle, const charString& xlabel, const charString& ylabel, double xmin, double xmax, double ymin, double ymax, double x_major_tick_spacing, int x_minor_tick_num, double y_major_tick_spacing, int y_minor_tick_num, const xydy_curves& xydy_results, const xy_curves& xy_curves_to_plot, const plot_labels& label_strings) { int i,j; charString str; double x_pos,y_pos; // do some checks if ((xmax<=xmin)||(ymax<=ymin)){ cerr << "ERROR in produce_plot: problem with plotting limits"<=0){ str=str.right_relax_substring('/');} str=str+".gif"; html_out << "



" <=0){ str=str.right_relax_substring('/');} str=str+".gif"; html_out << "



" <=0){ str=str.right_relax_substring('/');} str=str+".gif"; html_out << "



" <=0){ str=str.right_relax_substring('/');} str=str+".gif"; html_out << "



" <"<"< Plots"<"<"<"<"<"<"<

"<"<"<"<"<"<"<=0){ str=str.right_relax_substring('/');} str=str+".gif"; html_out << "



" <