mntplot.cxx

Go to the documentation of this file.
00001 // @(#)root/minuit2:$Id: mntplot.cxx 20880 2007-11-19 11:23:41Z rdm $
00002 // Authors: M. Winkler, F. James, L. Moneta, A. Zsenei   2003-2005  
00003 
00004 /**********************************************************************
00005  *                                                                    *
00006  * Copyright (c) 2005 LCG ROOT Math team,  CERN/PH-SFT                *
00007  *                                                                    *
00008  **********************************************************************/
00009 
00010 /* mnplot.F -- translated by f2c (version 20010320).
00011    You must link the resulting object file with the libraries:
00012         -lf2c -lm   (in that order)
00013 */
00014 
00015 #include <math.h>
00016 #include <stdio.h>
00017 #include <string.h>
00018 
00019 namespace ROOT {
00020 
00021    namespace Minuit2 {
00022 
00023 
00024 void mnbins(double, double, int, double&, double&, int&, double&);
00025 
00026 void mnplot(double* xpt, double* ypt, char* chpt, int nxypt, int npagwd, int npagln) {
00027  //*-*-*-*Plots points in array xypt onto one page with labelled axes*-*-*-*-*
00028  //*-*    ===========================================================
00029  //*-*        NXYPT is the number of points to be plotted
00030  //*-*        XPT(I) = x-coord. of ith point
00031  //*-*        YPT(I) = y-coord. of ith point
00032  //*-*        CHPT(I) = character to be plotted at this position
00033  //*-*        the input point arrays XPT, YPT, CHPT are destroyed.
00034  //*-*
00035  //*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
00036 
00037 //      char cdot[]   = ".";
00038 //      char cslash[] = "/";
00039 
00040    /* Local variables */
00041    double xmin, ymin, xmax, ymax, savx, savy, yprt;
00042    double bwidx, bwidy, xbest, ybest, ax, ay, bx, by;
00043    double xvalus[12], any, dxx, dyy;
00044    int iten, i, j, k, maxnx, maxny, iquit, ni, linodd;
00045    int nxbest, nybest, km1, ibk, isp1, nx, ny, ks, ix;
00046    char ctemp[120];
00047    bool overpr;
00048    char cline[120];
00049    char chsav, chbest;
00050    
00051    /* Function Body */
00052    //*-*  Computing MIN
00053    maxnx = npagwd-20 < 100 ? npagwd-20 : 100;
00054    if (maxnx < 10) maxnx = 10;
00055    maxny = npagln;
00056    if (maxny < 10) maxny = 10;
00057    if (nxypt <= 1) return;
00058    xbest  = xpt[0];
00059    ybest  = ypt[0];
00060    chbest = chpt[0];
00061    //*-*-        order the points by decreasing y
00062    km1 = nxypt - 1;
00063    for (i = 1; i <= km1; ++i) {
00064       iquit = 0;
00065       ni    = nxypt - i;
00066       for (j = 1; j <= ni; ++j) {
00067          if (ypt[j-1] > ypt[j]) continue;
00068          savx     = xpt[j-1];
00069          xpt[j-1] = xpt[j];
00070          xpt[j]   = savx;
00071          savy     = ypt[j-1];
00072          ypt[j-1] = ypt[j];
00073          ypt[j]   = savy;
00074          chsav    = chpt[j-1];
00075          chpt[j-1]= chpt[j];
00076          chpt[j]  = chsav;
00077          iquit    = 1;
00078       }
00079       if (iquit == 0) break;
00080    }
00081    //*-*-        find extreme values
00082    xmax = xpt[0];
00083    xmin = xmax;
00084    for (i = 1; i <= nxypt; ++i) {
00085       if (xpt[i-1] > xmax) xmax = xpt[i-1];
00086       if (xpt[i-1] < xmin) xmin = xpt[i-1];
00087    }
00088    dxx   = (xmax - xmin)*.001;
00089    xmax += dxx;
00090    xmin -= dxx;
00091    mnbins(xmin, xmax, maxnx, xmin, xmax, nx, bwidx);
00092    ymax = ypt[0];
00093    ymin = ypt[nxypt-1];
00094    if (ymax == ymin) ymax = ymin + 1;
00095    dyy   = (ymax - ymin)*.001;
00096    ymax += dyy;
00097    ymin -= dyy;
00098    mnbins(ymin, ymax, maxny, ymin, ymax, ny, bwidy);
00099    any = (double) ny;
00100    //*-*-        if first point is blank, it is an 'origin'
00101    if (chbest == ' ') goto L50;
00102    xbest = (xmax + xmin)*.5;
00103    ybest = (ymax + ymin)*.5;
00104 L50:
00105       //*-*-        find Scale constants
00106       ax = 1 / bwidx;
00107    ay = 1 / bwidy;
00108    bx = -ax*xmin + 2;
00109    by = -ay*ymin - 2;
00110    //*-*-        convert points to grid positions
00111    for (i = 1; i <= nxypt; ++i) {
00112       xpt[i-1] = ax*xpt[i-1] + bx;
00113       ypt[i-1] = any - ay*ypt[i-1] - by;
00114    }
00115    nxbest = int((ax*xbest + bx));
00116    nybest = int((any - ay*ybest - by));
00117    //*-*-        print the points
00118    ny += 2;
00119    nx += 2;
00120    isp1 = 1;
00121    linodd = 1;
00122    overpr = false;
00123    for (i = 1; i <= ny; ++i) {
00124       for (ibk = 1; ibk <= nx; ++ibk) { cline[ibk-1] = ' '; }
00125       cline[nx] = '\0';
00126       cline[nx+1] = '\0';
00127       cline[0]        = '.';
00128       cline[nx-1]     = '.';
00129       cline[nxbest-1] = '.';
00130       if (i != 1 && i != nybest && i != ny) goto L320;
00131       for (j = 1; j <= nx; ++j) { cline[j-1] = '.'; }
00132 L320:
00133          yprt = ymax - double(i-1)*bwidy;
00134       if (isp1 > nxypt) goto L350;
00135       //*-*-        find the points to be plotted on this line
00136       for (k = isp1; k <= nxypt; ++k) {
00137          ks = int(ypt[k-1]);
00138          if (ks > i) goto L345;
00139          ix = int(xpt[k-1]);
00140          if (cline[ix-1] == '.')   goto L340;
00141          if (cline[ix-1] == ' ') goto L340;
00142          if (cline[ix-1] == chpt[k-1])   continue;
00143          overpr = true;
00144          //*-*-        OVERPR is true if one or more positions contains more than
00145          //*-*-           one point
00146          cline[ix-1] = '&';
00147          continue;
00148 L340:
00149             cline[ix-1] = chpt[k-1];
00150       }
00151       isp1 = nxypt + 1;
00152       goto L350;
00153 L345:
00154          isp1 = k;
00155 L350:
00156          if (linodd == 1 || i == ny) goto L380;
00157       linodd = 1;
00158       memcpy(ctemp, cline, 120);
00159       printf("                  %s",(const char*)ctemp);
00160       goto L400;
00161 L380:
00162          //     ctemp = cline;
00163          memcpy(ctemp, cline, 120);
00164       printf(" %14.7g ..%s",yprt,(const char*)ctemp);
00165       linodd = 0;
00166 L400:
00167          printf("\n");
00168    }
00169    //*-*-        print labels on x-axis every ten columns
00170    for (ibk = 1; ibk <= nx; ++ibk) {
00171       cline[ibk-1] = ' ';
00172       if (ibk % 10 == 1) cline[ibk-1] = '/';
00173    }
00174    printf("                  %s",cline);
00175    printf("\n");
00176    
00177    for (ibk = 1; ibk <= 12; ++ibk) {
00178       xvalus[ibk-1] = xmin + double(ibk-1)*10*bwidx;
00179    }
00180    printf("           ");
00181    iten = (nx + 9) / 10;
00182    for (ibk = 1; ibk <= iten; ++ibk) {
00183       printf(" %9.4g", xvalus[ibk-1]);
00184    }
00185    printf("\n");
00186    
00187    if (overpr) {
00188       char chmess[] = "   Overprint character is &";
00189       printf("                         ONE COLUMN=%13.7g%s",bwidx,(const char*)chmess);
00190    } else {
00191       char chmess[] = " ";
00192       printf("                         ONE COLUMN=%13.7g%s",bwidx,(const char*)chmess);
00193    }
00194    printf("\n");
00195    
00196 } /* mnplot_ */
00197 
00198    }  // namespace Minuit2
00199 
00200 }  // namespace ROOT

Generated on Tue Jul 5 14:37:10 2011 for ROOT_528-00b_version by  doxygen 1.5.1