home *** CD-ROM | disk | FTP | other *** search
/ Education Sampler 1992 [NeXTSTEP] / Education_1992_Sampler.iso / Programming / Source / HippoDraw / hippo / hippoprint.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-04-28  |  3.4 KB  |  146 lines

  1. /*
  2.  * hippoprint.c - line printer display for hippo package.
  3.  *
  4.  * Copyright (C)  1991  The Board of Trustees of The Leland Stanford
  5.  * Junior University.  All Rights Reserved.
  6.  *
  7.  * $Id: hippoprint.c,v 3.5 1992/04/10 22:48:36 rensing Rel $
  8.  *
  9.  * by jonas karlsson, at SLAC, August 1990
  10.  *  split up by Paul Rensing, Feb 28,1991
  11.  */
  12.  
  13.  
  14. #include <stdio.h>
  15. #include <stdlib.h>
  16. #include <math.h>
  17. #ifndef THINK_C
  18. #include <string.h>
  19. #endif
  20. #include "hippo.h"
  21. #include "hippoutil.h"
  22.  
  23. GLOB_QUAL const char hippoprint_c_rcsid[] = 
  24.      "$Id: hippoprint.c,v 3.5 1992/04/10 22:48:36 rensing Rel $";
  25.  
  26. #define SCREENWIDTH 50
  27. #define BININDEX(x, y, z, xs, ys) ((xs) * (ys) * (z) + (x) * (ys) + y)
  28.  
  29. static void print1D(display disp, FILE *file);
  30. static void print2D(display disp, FILE *file);
  31. static void print3D(display disp, FILE *file);
  32.  
  33. void h_fprint(display disp, FILE *file)
  34. {
  35.      if (h_bin(disp) != 0) return;
  36.      
  37.      switch (disp->dim) {
  38.      case 1:
  39.       print1D(disp, file);
  40.       break;
  41.      case 2:
  42.       print2D(disp, file);
  43.       break;
  44.      case 3:
  45.       print3D(disp, file);
  46.       break;
  47.      default:
  48.       break;
  49.      }
  50.      
  51.  
  52. }
  53.  
  54. static void print1D(display disp, FILE *file)
  55. {
  56.      int dim, i, j, nchar=0, bi;
  57.      float binedge, bw=0.0;
  58.      float ylow=0.0, range=0.0;
  59.      float csize;
  60.      int zeropt;
  61.      char string[80];
  62.      double d1,d2;
  63.      
  64.      dim = disp->binding.x;
  65.      
  66.      if (disp->title != NULL)
  67.       fprintf(file,"%s\n\n",
  68.           h_expandLabel( string, disp->title, 80, disp));
  69.      if (disp->xAxis.label != NULL) 
  70.       fprintf(file,"X Axis label \"%s\"\n",
  71.           h_expandLabel( string, disp->xAxis.label, 80, disp));
  72.      fprintf(file,"%d bins, from %f to %f\n\n", disp->bins.xAxis.nBins,
  73.         disp->xAxis.low, disp->xAxis.high);
  74.      
  75.      fprintf(file," bin        xlow    content\n");
  76.  
  77.      range = disp->bins.binMax - disp->bins.binMin;
  78.      if (range <= 0.0) range = 1.0;
  79.      ylow = disp->bins.binMin - 0.1*range;
  80.      csize = (float)SCREENWIDTH / (1.2*range);
  81.  
  82.      zeropt = -ylow*csize;
  83.      if (zeropt < 0) zeropt = 0;
  84.      
  85.      binedge = disp->xAxis.low;
  86.      bw = ((float) (disp->xAxis.high - disp->xAxis.low)) /
  87.       (float) disp->bins.xAxis.nBins;
  88.  
  89.      for (i = 0; i < disp->bins.xAxis.nBins; i++) {
  90.       bi = BININDEX(i, 0, 0, disp->bins.xAxis.nBins, 1);
  91.       
  92.       fprintf(file,"\n%4d:%11.4g%11.4g ", 
  93.           i, binedge, disp->bins.data[bi]);
  94.       binedge += bw;
  95.  
  96.       if (disp->bins.data[bi] >= 0) 
  97.       {
  98.            for (j = 0; j < zeropt; j++) {
  99.             putc(' ', file);    
  100.            }
  101.            nchar =  (disp->bins.data[bi] - ylow) * csize - zeropt;
  102.            for (j = 0; j < nchar; j++) {
  103.             putc('X', file);    
  104.            }
  105.            if (nchar <= 0) putc('|', file);
  106.       }
  107.       else 
  108.       {
  109.            nchar =  (disp->bins.data[bi] - ylow) * csize;
  110.            for (j = 0; j < nchar; j++) {
  111.             putc(' ', file);    
  112.            }
  113.            for (j = 0; j < zeropt - nchar; j++) {
  114.             putc('X', file);
  115.            }
  116.            if ((zeropt - nchar) <= 0) putc('|', file);
  117.       }
  118.      }
  119.      d1 = disp->bins.totals[0][0];
  120.      d2 = disp->bins.totals[2][0];
  121.      
  122.      fprintf(file,"\nunderflow:%g  overflow:%g\n",d1,d2);
  123. /*     
  124.          disp->bins.totals[0][0],
  125.          disp->bins.totals[2][0]);
  126.   */   
  127.      return;
  128. }
  129.  
  130.  
  131.  
  132. static void print2D(display disp, FILE *file)
  133. {
  134.      fprintf(file, "2D printer output is not yet implemented\n");
  135.      
  136.      return;
  137. }
  138.  
  139. static void print3D(display disp, FILE *file)
  140. {
  141.      fprintf(file, "3D printer output is not yet implemented\n");
  142.      
  143.      return;
  144. }
  145.  
  146.