/*******************************************************/ /* Linux GNU C++ Compiler */ /* Name : fastpictex.cc */ /* Autor: Harald Stauss */ /*******************************************************/ #include #include #include #include #include #include #include "fastpictex.h" #ifdef DUMA #include #include "../../duma/duma.h" #include "../../duma/dumapp.h" #endif /* ----------------------------- */ /* Implementation der Funktionen */ /* ----------------------------- */ FASTPICTEX::FASTPICTEX() { /* Constructor */ width=6.0; height=6.0; // default 6x6 cm; nofseries=0; nofbar=0; linenoxmax=-1; xgrid=0; ygrid=0; noftline=0; series=(SERIES *)malloc(sizeof(SERIES)); need_errorbarmacros=0; xlabel =(char*)malloc(2*sizeof(char)); strcpy(xlabel, "\0"); ylabel =(char*)malloc(2*sizeof(char)); strcpy(ylabel, "\0"); heading=(char*)malloc(2*sizeof(char)); strcpy(heading, "\0"); nxticlabels=0; xticlabels=new char* [1]; nofrawpictex=0; rawpictex=(char **)malloc(sizeof(char *)); strcpy(plotsym[0], "$\\bullet$"); strcpy(plotsym[1], "$\\circ$"); strcpy(plotsym[2], "$\\diamond$"); strcpy(plotsym[3], "$\\star$"); strcpy(plotsym[4], "$\\ast$"); strcpy(plotsym[5], "$\\oplus$"); strcpy(plotsym[6], "$\\odot$"); strcpy(plotsym[7], "$\\oslash$"); strcpy(plotsym[8], "$\\otimes$"); strcpy(plotsym[9], "$\\times$"); strcpy(linesym[0], "\\setsolid"); strcpy(linesym[1], "\\setdots"); strcpy(linesym[2], "\\setdashes"); strcpy(linesym[3], "\\setdashpattern <3mm,1mm,1mm,1mm>"); strcpy(linesym[4], "\\setdashpattern <3mm,1mm,0.5mm,0.5mm,0.5mm,1mm>"); strcpy(linesym[5], "\\setsolid"); strcpy(linesym[6], "\\setdots"); strcpy(linesym[7], "\\setdashes"); strcpy(linesym[8], "\\setdashpattern <3mm,1mm,1mm,1mm>"); strcpy(linesym[9], "\\setdashpattern <3mm,1mm,0.5mm,0.5mm,0.5mm,1mm>"); } FASTPICTEX::~FASTPICTEX() { /* Destructor */ int i; unsigned long j; for (i=0; inofseries) { AddSeries(); } } token=fpt_command; token=strtok(NULL, WHITE_SPACE); if (!token) { series[ntype-1].type=0; } if (!strcmp(token, "xy")) { series[ntype-1].type=1; } else if (!strcmp(token, "line")) { series[ntype-1].type=2; } else if (!strcmp(token, "bar")) { series[ntype-1].type=3; nofbar++; } else { series[ntype-1].type=0; } } /* trendline */ else if (!strcmp(fpt_command, "tline")) { if (is_newcommand) { noftline++; if (noftline>nofseries) { AddSeries(); } } //series[noftline-1].tline=1; token=fpt_command; /* read one more token */ token=strtok(NULL, WHITE_SPACE); if (token) series[noftline-1].tline=atoi(token); /* read remaining tokens to go to end of line */ while (token) { token=strtok(NULL, WHITE_SPACE); } } /* legend */ else if (!strcmp(fpt_command, "legend")) { if (is_newcommand) { nlegend++; if (nlegend>nofseries) { AddSeries(); } } token=fpt_command; if (is_newcommand) { series[nlegend-1].legend=(char *)realloc(series[nlegend-1].legend, sizeof(char)); strcpy(series[nlegend-1].legend, ""); } else { series[nlegend-1].legend=(char *)realloc(series[nlegend-1].legend, (strlen(series[nlegend-1].legend)+2)*sizeof(char)); strcat(series[nlegend-1].legend, " "); } while (token) { token=strtok(NULL, WHITE_SPACE); if (token) { series[nlegend-1].legend=(char *)realloc(series[nlegend-1].legend, (strlen(series[nlegend-1].legend)+strlen(token)+2)*sizeof(char)); strcat(series[nlegend-1].legend, token); strcat(series[nlegend-1].legend, " "); } /* endif */ } /* endwhile */ series[nlegend-1].legend[strlen(series[nlegend-1].legend)-1]='\0'; } /* pictex commands */ else if (!strcmp(fpt_command, "pictex")) { token=fpt_command; if (is_newcommand) { nofrawpictex++; rawpictex=(char **)realloc(rawpictex, nofrawpictex*sizeof(char *)); rawpictex[nofrawpictex-1]=(char *)malloc(sizeof(char)); strcpy(rawpictex[nofrawpictex-1], ""); } else { rawpictex[nofrawpictex-1]=(char *)realloc(rawpictex[nofrawpictex-1], (strlen(rawpictex[nofrawpictex-1])+2)*sizeof(char)); strcat(rawpictex[nofrawpictex-1], " "); } while (token) { token=strtok(NULL, WHITE_SPACE); if (token) { rawpictex[nofrawpictex-1]=(char *)realloc(rawpictex[nofrawpictex-1], (strlen(rawpictex[nofrawpictex-1])+strlen(token)+2)*sizeof(char)); strcat(rawpictex[nofrawpictex-1], token); strcat(rawpictex[nofrawpictex-1], " "); } /* endif */ } /* endwhile */ rawpictex[nofrawpictex-1][strlen(rawpictex[nofrawpictex-1])-1]='\0'; } /* x coordinates */ else if (!strcmp(fpt_command, "x")) { if (is_newcommand) { ndata=0; nx++; if (nx>nofseries) { AddSeries(); } } token=fpt_command; while (token) { token=strtok(NULL, WHITE_SPACE); if (token) { if (ndata>=nallocdata) { nallocdata+=100; data=(float *)realloc(data, nallocdata*sizeof(float)); } /* endif */ data[ndata]=atof(token); ndata++; } /* endif */ } /* endwhile */ series[nx-1].nx=ndata; series[nx-1].x=(float *)realloc(series[nx-1].x, ndata*sizeof(float)); for (n=0; nnofseries) { AddSeries(); } } token=fpt_command; while (token) { token=strtok(NULL, WHITE_SPACE); if (token) { if (ndata>=nallocdata) { nallocdata+=100; data=(float *)realloc(data, nallocdata*sizeof(float)); } /* endif */ series[ny-1].sig=(char **)realloc(series[ny-1].sig, (ndata+1)*sizeof(char *)); series[ny-1].sig[ndata]=getsig(token); data[ndata]=atof(token); ndata++; } /* endif */ } /* endwhile */ series[ny-1].ny=ndata; series[ny-1].y=(float *)realloc(series[ny-1].y, ndata*sizeof(float)); for (n=0; nnofseries) { AddSeries(); } } token=fpt_command; while (token) { token=strtok(NULL, WHITE_SPACE); if (token) { if (ndata>=nallocdata) { nallocdata+=100; data=(float *)realloc(data, nallocdata*sizeof(float)); } /* endif */ data[ndata]=atof(token); ndata++; } /* endif */ } /* endwhile */ series[ndx-1].ndx=ndata; series[ndx-1].dx=(float *)realloc(series[ndx-1].dx, ndata*sizeof(float)); for (n=0; nnofseries) { AddSeries(); } } token=fpt_command; while (token) { token=strtok(NULL, WHITE_SPACE); if (token) { if (ndata>=nallocdata) { nallocdata+=100; data=(float *)realloc(data, nallocdata*sizeof(float)); } /* endif */ data[ndata]=atof(token); ndata++; } /* endif */ } /* endwhile */ series[ndy-1].ndy=ndata; series[ndy-1].dy=(float *)realloc(series[ndy-1].dy, ndata*sizeof(float)); for (n=0; n0 && (series[i].nx!=series[i].ny)) { series[i].nx=series[i].ny; series[i].x=(float *)realloc(series[i].x, series[i].nx*sizeof(float)); for (n=0; n0) { if (series[i].ny>j) {j=series[i].ny; linenoxmax=i;} series[i].nx=series[i].ny; series[i].x=(float *)realloc(series[i].x, series[i].nx*sizeof(float)); for (n=0; n0) { xlmin=1.0; xlmax=(float)nxticlabels; GetExtrema(1, xlmin, xlmax, &xmin, &xmax, &ymin, &ymax); xmin=1.0; xmax=(float)nxticlabels; scale(xmin-1, xmax+1, nxticlabels+2, &valmin, &step, &valmax); } /* number of x-tics depend on bar-graphs second */ else if (nofbar>0) { j=0; for (i=0; ij) j=series[i].nx; } scale(xmin-1, xmax+1, j+2, &valmin, &step, &valmax); } /* number of x-tics depend on line- and xy-series without x-values third */ else if (linenoxmax>=0) scale(xmin-1, xmax+1, series[linenoxmax].nx+2, &valmin, &step, &valmax); /* finally default */ else scale(xmin, xmax, N_XTICKS, &valmin, &step, &valmax); xstep=floor(step*10000.0+0.5)/10000.0; if (xmin>valmin) xmin=floor(valmin*10000.0+0.5)/10000.0; else xmin=floor((valmin-xstep)*10000.0+0.5)/10000.0; if (xmaxvalmin) ymin=floor(valmin*10000.0+0.5)/10000.0; else ymin=floor((valmin-ystep)*10000.0+0.5)/10000.0; if (ymax point at 0 0 \n"; pictex << "\\setplotarea x from " << xmin << " to " << xmax << ", y from " << ymin << " to " << ymax << " \n"; /* plot axis */ pictex << "% .......... axis ............ \n"; pictex << "\\axis bottom "; if (xlabel) pictex << "label {" << xlabel << "} "; pictex << "ticks "; if (xgrid) pictex << "andacross "; if (nxticlabels==0) { pictex << "numbered from " << xmin << " to " << xmax << " by " << xstep << " / \n"; } else { pictex << "withvalues {} "; for (n=0; n=xlmin && series[i].x[n]<=xlmax) { pictex << "\\put {" << plotsym[(int)fmod(nxy,10)] << "} at " << series[i].x[n] << " " << series[i].y[n] << " \n"; sx2+=(series[i].x[n]*series[i].x[n]); sy2+=(series[i].y[n]*series[i].y[n]); sxy+=(series[i].x[n]*series[i].y[n]); sx+=series[i].x[n]; sy+=series[i].y[n]; nreg++; if (series[i].ndx>n) { pictex << "\\putxerrorbar{" << series[i].x[n] << "}{" << series[i].y[n] << "}{" << series[i].dx[n] << "} \n"; } if (series[i].ndy>n) { pictex << "\\putyerrorbar{" << series[i].x[n] << "}{" << series[i].y[n] << "}{" << series[i].dy[n] << "} \n"; } /* plot significance signs */ if (series[i].sig[n]) { ypos=series[i].y[n]; if (series[i].ndy>n) ypos+=series[i].dy[n]; pictex << "\\put {" << series[i].sig[n] << "} [b] <0mm,0.5\\baselineskip> at " << series[i].x[n] << " " << ypos << "\n"; } } } /* calculate regression line */ if (nreg>2) { qx=sx2-(sx*sx/nreg); qy=sy2-(sy*sy/nreg); qxy=sxy-(sx*sy/nreg); r=qxy/sqrt(qx*qy); by=qxy/qx; bx=qxy/qy; ay=(sy-by*sx)/nreg; ax=(sx-bx*sy)/nreg; s2yx=(qy-(qxy*qxy/qx))/(nreg-2); s2xy=(qx-(qxy*qxy/qy))/(nreg-2); pwert=2.0*(1.0-prho(nreg, (nreg*nreg*nreg-nreg)*(1.0-fabs(r))/6.0, &is_fault)); series[i].m1=by; series[i].m2=bx; series[i].b=ay; series[i].nreg=nreg; if (pwert>1.0) pwert=1.0; if (pwert<0.0) pwert=0.0; /* plot regression line */ rxmin=xmin; rxmax=xmax; if (series[i].tline>0) { if (ymin>xmin*by+ay) rxmin=(ymin-ay)/by; if (ymaxxmax*by+ay) rxmax=(ymin-ay)/by; if (ymax2 */ else series[i].tline=0; /* clean up */ nxy++; break; case 2: // line graph; /* write lines */ pictex << "\\setlinear \n"; pictex << linesym[(int)fmod(nline,10)] << " \n"; is_first=1; for (n=0; n=xlmin && series[i].x[n]<=xlmax) { if (is_first) {pictex << "\\plot "; is_first=0;} pictex << series[i].x[n] << " " << series[i].y[n] << " "; } } pictex << "/ \n"; pictex << "\\setsolid \n"; for (n=0; n=xlmin && series[i].x[n]<=xlmax) { if (series[i].ndx>n) { pictex << "\\putxerrorbar{" << series[i].x[n] << "}{" << series[i].y[n] << "}{" << series[i].dx[n] << "} \n"; } if (series[i].ndy>n) { pictex << "\\putyerrorbar{" << series[i].x[n] << "}{" << series[i].y[n] << "}{" << series[i].dy[n] << "} \n"; } /* plot significance signs */ if (series[i].sig[n]) { ypos=series[i].y[n]; if (series[i].ndy>n) ypos+=series[i].dy[n]; pictex << "\\put {" << series[i].sig[n] << "} [b] <0mm,0.5\\baselineskip> at " << series[i].x[n] << " " << ypos << "\n"; } } } nline++; break; case 3: // bar graph; /* write bars */ if (nbar==0) { pictex << "\\shaderectanglesoff \n"; } if (nbar>0 && nbar \n"; } if (nbar!=0 && nbar==nofbar-1) { pictex << "\\shaderectanglesoff%\n"; pictex << "\\dimen0=\\linethickness%\n"; pictex << "%look here\n"; pictex << "\\setlength{\\linethickness}{" << (BARWIDTH*xunit)/(float)nofbar << "cm}%\n"; //pictex << "\\setlength{\\linethickness}{\\Xdistance{" << BARWIDTH/(float)nofbar << "}}%\n"; } if (nbar==0 || nbar=xlmin && series[i].x[n]<=xlmax) { pictex << "\\putrectangle corners at "; pictex << (series[i].x[n]-BARWIDTH/2.0)+(BARWIDTH*(float)nbar/(float)nofbar) << " " << ymin << " and "; pictex << (series[i].x[n]-BARWIDTH/2.0)+(BARWIDTH*(float)(nbar+1)/(float)nofbar) << " " << series[i].y[n] << " \n"; } } } if (nbar!=0 && nbar==nofbar-1) { for (n=0; n=xlmin && series[i].x[n]<=xlmax) { pictex << "\\putrule from " << (series[i].x[n]-BARWIDTH/2)+BARWIDTH/(float)(2*nofbar)+(BARWIDTH*(float)(nbar)/(float)nofbar) << " " << ymin << " to " << (series[i].x[n]-BARWIDTH/2)+BARWIDTH/(float)(2*nofbar)+(BARWIDTH*(float)(nbar)/(float)nofbar) << " " << series[i].y[n] << " \n"; } } pictex << "\\setlength{\\linethickness}{\\dimen0}%\n"; } for (n=0; n=xlmin && series[i].x[n]<=xlmax) { /* plot errorbars */ if (series[i].ndy>n) { pictex << "\\putyerrorbar{" << (series[i].x[n]-BARWIDTH/2)+BARWIDTH/(float)(2*nofbar)+(BARWIDTH*(float)(nbar)/(float)nofbar) << "}{" << series[i].y[n] << "}{" << series[i].dy[n] << "} \n"; } /* plot significance signs */ if (series[i].sig[n]) { ypos=series[i].y[n]; if (series[i].ndy>n) ypos+=series[i].dy[n]; pictex << "\\put {" << series[i].sig[n] << "} [b] <0mm,0.5\\baselineskip> at " << (series[i].x[n]-BARWIDTH/2)+BARWIDTH/(float)(2*nofbar)+(BARWIDTH*(float)(nbar)/(float)nofbar) << " " << ypos << "\n"; } } } nbar++; break; } /* endswitch */ } /* endfor */ /* legend */ is_valid=0; for (i=0; i0) || (series[i].type==1 && series[i].tline>0 && series[i].nreg>2)) is_valid=1; } if (is_valid) { pictex << "% .......... legends ............. \n"; j=0; nxy=0; nbar=0, nline=0; for (i=0; i0) || (series[i].type==1 && series[i].tline>0 && series[i].nreg>2)) { /* first symbols */ if (series[i].type==1) { /* xy */ if (series[i].tline>0 && series[i].nreg>2) { pictex << "\\put {" << plotsym[(int)fmod(nxy,10)] << "} [cc] <0.2cm,-" << 2.5*j+1 << "ex> at " << xmax << " " << ymax << "\n"; pictex << "\\setlinear \n"; pictex << linesym[(int)fmod(nxy,10)] << " \n"; pictex << "\\put {\\frame{\\hspace*{8mm}}} [lc] <0.4cm,-" << 2.5*j+1 << "ex> at " << xmax << " " << ymax << "\n"; } else pictex << "\\put {" << plotsym[(int)fmod(nxy,10)] << "} [cc] <0.8cm,-" << 2.5*j+1 << "ex> at " << xmax << " " << ymax << "\n"; } if (series[i].type==2) { /* line */ pictex << linesym[(int)fmod(nline,10)] << " \n"; pictex << "\\putrule <0.4cm,-" << 2.5*j+1 << "ex> from " << xmax << " " << ymax << " to " << xmax+0.8/xunit << " " << ymax << "\n"; } if (series[i].type==3) { /* bar */ if (nbar==0) { pictex << "\\shaderectanglesoff \n"; pictex << "\\putrectangle <5mm,-" << 2.5*j << "ex> corners at " << xmax << " " << ymax << " and " << xmax+0.6/xunit << " " << ymax-0.3/yunit << "\n"; } if (nbar>0 && nbar \n"; pictex << "\\putrectangle <5mm,-" << 2.5*j << "ex> corners at " << xmax << " " << ymax << " and " << xmax+0.6/xunit << " " << ymax-0.3/yunit << "\n"; } if (nbar!=0 && nbar==nofbar-1) { pictex << "\\shaderectanglesoff%\n"; pictex << "\\dimen0=\\linethickness%\n"; pictex << "\\setlength{\\linethickness}{6mm}%\n"; pictex << "\\putrule <8mm,-" << 2.5*j << "ex> from " << xmax << " " << ymax << " to " << xmax << " " << ymax-0.3/yunit << "\n"; pictex << "\\setlength{\\linethickness}{\\dimen0}%\n"; } } /* then labels */ pictex << "\\put {" << series[i].legend; if (series[i].type==1 && series[i].tline>0 && series[i].nreg>2) { if (strlen(series[i].legend)>0) pictex << ", n=" << series[i].nreg; else pictex << "n=" << series[i].nreg; } pictex << "} [lc] <1.4cm,-" << 2.5*j+1 << "ex> at " << xmax << " " << ymax << "\n"; j++; if (series[i].type==1 && series[i].tline==2 && series[i].nreg>2) { pictex << "\\put "; by=series[i].m1; ay=series[i].b; bx=series[i].m2; pictex.precision(3); if (ay>0) pictex << "{\\footnotesize $(y=" << by << "x+" << ay << ", r^2=" << by*bx << ")$}"; else pictex << "{\\footnotesize $(y=" << by << "x-" << (-1)*ay << ", r^2=" << by*bx << ")$}"; pictex.precision(6); pictex << " [lc] <1.4cm,-" << 2.5*j+1 << "ex> at " << xmax << " " << ymax << "\n"; j++; } } if (series[i].type==1) nxy++; if (series[i].type==2) nline++; if (series[i].type==3) nbar++; } /* endfor i */ } /* endif is_valid */ /* pictex commands */ if (nofrawpictex>0) pictex << "% .......... rawpictex ............. \n"; for (i=0; i0) { /* start values */ mxmin=FLT_MAX; mymin=FLT_MAX; mxmax=FLT_MIN; mymax=FLT_MIN; for (i=0; i=x1)) { if (series[i].ndx>n) { wert1=series[i].x[n]-series[i].dx[n]; wert2=series[i].x[n]+series[i].dx[n]; } else { wert1=series[i].x[n]; wert2=series[i].x[n]; } if (mxmin>wert1) mxmin=wert1; if (mxmaxn) { wert1=series[i].y[n]-series[i].dy[n]; wert2=series[i].y[n]+series[i].dy[n]; } else { wert1=series[i].y[n]; wert2=series[i].y[n]; } if (mymin>wert1) mymin=wert1; if (mymax