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

  1. /*
  2.  * hippowrapsUP.cc -- Graphics end for Hippo histogramming package.
  3.  * $Id: hippoplotUP.c,v 3.2 1992/01/28 15:50:43 rensing Rel $
  4.  *
  5.  * Copyright (C)  1991  The Board of Trustees of The Leland Stanford
  6.  * Junior University.  All Rights Reserved.
  7.  *
  8.  * Provides the equivalent of:
  9.  * hippowraps.psw - histogramming package postscript wraps. 
  10.  *      by william shipley, at SLAC, august 1990
  11.  *    
  12.  *      modified/maintained by mike gravina.
  13.  *
  14.  * updated to match new psw - Apr 30, 1991 Paul Rensing
  15.  */
  16.  
  17.  
  18. #include <stdio.h>
  19. #include <stdlib.h>
  20. #include <string.h>
  21. #include <math.h>
  22. #include <ctype.h>
  23. #include "hippoplotUP.h"
  24.  
  25. const char hippoplotUP_c_rcsid[] = "$Id: hippoplotUP.c,v 3.2 1992/01/28 15:50:43 rensing Rel $";
  26. const char hippoplotUP_h_rcsid[] = HIPPOPLOTUP_H_RCSID;
  27.  
  28.  
  29.  
  30. #define WIND_SIZE 3120   /* for 4014 terminal */
  31. #define TICKHEIGHT 40
  32. #define LABELPAD 10
  33.  
  34. static struct {
  35.      float xScale;
  36.      float yScale;
  37.      float xMarg;
  38.      float yMarg;
  39.      float xOrig;
  40.      float yOrig;
  41.      float xMax;
  42.      float yMax;
  43. } data, window;
  44.  
  45.  
  46. #define XData(x) ( (int) (((x)-data.xOrig)*data.xScale)+data.xMarg )
  47. #define YData(y) ( (int) (((y)-data.yOrig)*data.yScale)+data.yMarg )
  48.  
  49. #define XWind(x) ( (int) ((((x)-window.xOrig)*window.xScale)+window.xMarg) )
  50. #define YWind(y) ( (int) ((((y)-window.yOrig)*window.yScale)+window.yMarg) )
  51.  
  52. static FILE *outfile = stdout;
  53. static FILE stdout_save;
  54.  
  55.  
  56. int initDrvr_UP( FILE *file )
  57. {
  58.      outfile = file;
  59.      
  60.      return 0;
  61. }
  62.  
  63.  
  64. int initPlot_UP( rectangle *draw, rectangle *margin, rectangle *user)
  65. {
  66.      if (outfile != stdout)
  67.      {
  68.       memcpy(&stdout_save,stdout,sizeof(FILE));
  69.       memcpy(stdout,outfile,sizeof(FILE));
  70.      }
  71.      
  72.       
  73.      openpl();
  74.      
  75.      space(0,0,WIND_SIZE,WIND_SIZE);
  76.      erase();
  77.      
  78.      window.xScale = WIND_SIZE/draw->size.width;
  79.      window.yScale = WIND_SIZE/draw->size.height;
  80.      window.xMarg = 0.0;
  81.      window.yMarg = 0.0;
  82.      window.xOrig = 0.0;
  83.      window.yOrig = 0.0;
  84.      window.xMax = draw->size.width;
  85.      window.yMax = draw->size.height;
  86.           
  87.      data.xScale = margin->size.width/
  88.       user->size.width*window.xScale;
  89.      data.yScale = margin->size.height/
  90.       user->size.height*window.yScale;
  91.      data.xMarg = margin->origin.x*window.xScale;
  92.      data.yMarg = margin->origin.y*window.yScale;
  93.      data.xOrig = user->origin.x;
  94.      data.yOrig = user->origin.y;
  95.      data.xMax = user->origin.x + user->size.width;
  96.      data.yMax = user->origin.y + user->size.height;
  97.  
  98.      return 0;
  99. }
  100.  
  101. int endPlot_UP(void )
  102. {
  103.      if (outfile != stdout)
  104.      {
  105.       memcpy(stdout,&stdout_save,sizeof(FILE));
  106.      }
  107.      
  108.      return 0;
  109. }
  110.  
  111.  
  112. /*
  113.  * Put text at the specified point
  114.  */
  115. int drawText_UP(char *message, float x, float y, float fontSize,
  116.         float rotation, char xAlign, char yAlign )
  117. {
  118.      int x1 = XWind(x);
  119.      int y1 = YWind(y);
  120.      
  121.      move( x1, y1 );
  122.      
  123.      /*     fontsize( (int) (fontSize*0.62) );*/
  124.      
  125.      if (isupper(xAlign)) xAlign = tolower(xAlign);
  126.      if (isupper(yAlign)) yAlign = tolower(yAlign);
  127.      
  128.      rotate(x1,x1,(int)rotation);    /* first 2 args are junk */
  129.      
  130.      alabel(xAlign,yAlign,message);
  131.      
  132.      rotate(x1,x1,0);
  133.      
  134.      return 0;
  135. }
  136.  
  137.  
  138. int drawXTicks_UP(float *x, int nticks, float tickWidth, int side )
  139. {
  140.      int i;
  141.      int tickw = tickWidth*window.xScale;
  142.      int ticklow;
  143.      int x2;
  144.      
  145.      if (side == 0) 
  146.       ticklow = data.yMarg;
  147.      else
  148.       ticklow = YData(data.yMax) - tickw;
  149.      
  150.      for (i=0; i<nticks; i++)
  151.      {
  152.       x2 = XData(x[i]);
  153.       line(x2, ticklow, x2, ticklow+tickw);
  154.      }
  155.      
  156.      return 0;
  157. }
  158.  
  159.  
  160. int drawYTicks_UP( float *y, int nt, float tickwidth, int side )
  161. {
  162.      int i;
  163.      int tickw = tickwidth*window.xScale;
  164.      int ticklow;
  165.      int y1;
  166.  
  167.      if (side == 0)
  168.       ticklow = data.xMarg;
  169.      else
  170.       ticklow = XData(data.xMax)-tickw;
  171.      
  172.      for (i=0; i<nt; i++)
  173.      {
  174.       y1 = YData(y[i]);
  175.       line(ticklow, y1, ticklow+tickw, y1);
  176.      }
  177.      
  178.      return 0;
  179. }
  180.  
  181. int drawMag_UP( float x, float y, int mag, float fontSize )
  182. {
  183.      char str[10];
  184.      
  185.      move( XWind(x), YWind(y) );
  186.      sprintf(str,"x10^%d",mag);
  187.      alabel('l','b',str);
  188.      
  189.      return 0;
  190. }
  191.  
  192.  
  193. int drawPoints_UP(float *xy, int npts, int symbol, float ptsize)
  194. {
  195.      int i;
  196.      int x1, y1;
  197.      int sz;
  198.      
  199.      sz = ptsize*window.xScale;
  200.      
  201.      if (sz > 0)
  202.      {
  203.       for (i=0; i<npts; i++) 
  204.       {
  205.            x1 = XData(*xy++);
  206.            y1 = YData(*xy++);
  207.            circle( x1, y1, sz/2 );
  208.       }
  209.      }
  210.      else
  211.      {
  212.       for (i=0; i<npts; i++) 
  213.       {
  214.            x1 = XData(*xy++);
  215.            y1 = YData(*xy++);
  216.            point( x1, y1 );
  217.       }
  218.      }
  219.      
  220.      return 0;
  221. }
  222.  
  223.  
  224. int drawLine_UP(float *xy, int npts, linestyle_t ls)
  225. {
  226.      int i;
  227.      int x,y;
  228.      
  229.      switch (ls)
  230.      {
  231.      default:
  232.      case SOLID:
  233.       linemod("solid");
  234.       break;
  235.      case DASH:
  236.       linemod("longdashed");
  237.       break;
  238.      case DOT:
  239.       linemod("dotted");
  240.       break;
  241.      case DOTDASH:
  242.       linemod("dotdashed");
  243.       break;
  244.      }
  245.      
  246.      x = XData(*xy++);
  247.      y = YData(*xy++);
  248.      move(x, y );
  249.      
  250.      for ( i=1; i<npts; i++) 
  251.      {    
  252.       x = XData(*xy++);
  253.       y = YData(*xy++);
  254.       cont(x, y );
  255.       
  256.      }
  257.      
  258.      return 0;
  259. }
  260.  
  261.  
  262. int drawYError_UP(float *xy, float *err, int npts)
  263. {
  264. #define CAPWIDTH 10.0
  265.      float halfCapWidth = CAPWIDTH/2.0 / data.xScale;
  266.      int i;
  267.      int y1,y2,x1;
  268.      
  269.      for ( i=0; i<npts; i++) 
  270.      {
  271.       x1 = XData(*xy++);
  272.       xy++;
  273.       
  274.       y1 = YData(*err++);
  275.       y2 = YData(*err++);
  276.       
  277.       line( x1, y1, x1, y2 );
  278.       line( x1-halfCapWidth, y1, (x1+halfCapWidth), y1 );
  279.       line( (x1-halfCapWidth), y2, (x1+halfCapWidth), y2 );
  280.      }
  281.      
  282.      return 0;
  283. }
  284.  
  285. int drawXError_UP(float *xy, float *err, int npts)
  286. {
  287.      float halfCapWidth = CAPWIDTH/2.0 / data.yScale;
  288.      int i;
  289.      int y1,x2,x1;
  290.      
  291.      for ( i=0; i<npts; i++) 
  292.      {
  293.       xy++;
  294.       y1 = XData(*xy++);
  295.       
  296.       x1 = YData(*err++);
  297.       x2 = YData(*err++);
  298.       
  299.       line( x1, y1, x2, y1 );
  300.       line( x1, (y1-halfCapWidth), x1, (y1+halfCapWidth) );
  301.       line( x2, (y1+halfCapWidth), x2, (y1+halfCapWidth) );
  302.      }
  303.      
  304.      return 0;
  305. }
  306.  
  307.  
  308. int drawColor2D_UP(display disp)
  309. {
  310.      move(WIND_SIZE/2.0,WIND_SIZE/2.0);
  311.      alabel('c','c',"GrayScales Not Implemented");
  312.      return 0;
  313. }
  314.  
  315. int drawLego2D_UP(display disp)
  316. {
  317.      move(WIND_SIZE/2.0,WIND_SIZE/2.0);
  318.      alabel('c','c',"2D Lego Not Implemented");
  319.      return 0;
  320. }
  321.