home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / libs / vopl / glvopl.lha / glvopl / src / adjustscale.c next >
Encoding:
C/C++ Source or Header  |  1993-01-18  |  1.1 KB  |  76 lines

  1.  
  2. #include "vopl.h"
  3.  
  4. /*
  5.  *    adjustscale
  6.  *
  7.  *    Adjust the scaling for the specified axis according to the
  8.  *    values in the array x.
  9.  */
  10. void
  11. adjustscale(x, n, axis)
  12.     float        x[];
  13.     int        n;
  14.     char        axis;
  15. {
  16.     int        i, nticks;
  17.     float        min, max, a, b, c, d, div;
  18.     axisdata    *ax;
  19.  
  20.     switch (axis) {
  21.     case 'x':
  22.     case 'X':
  23.         ax = &plotdev.axes[XIND];
  24.         break;
  25.     case 'y':
  26.     case 'Y':
  27.         ax = &plotdev.axes[YIND];
  28.         break;
  29.     case 'z':
  30.     case 'Z':
  31.         ax = &plotdev.axes[ZIND];
  32.         break;
  33.     default:
  34.         vopl_error("Unknown axis in adjust scale");
  35.     }
  36.  
  37.     nticks = ax->nticks;
  38.     min = ax->min;
  39.     max = ax->max;
  40.     ax->scaleset = 1;
  41.  
  42.     /*
  43.      * Find min and max of array x.
  44.      */
  45.  
  46.     a = BLOODYBIG;
  47.     b = -BLOODYBIG;
  48.     for (i = 0; i < n; i += plotdev.arrayind) {
  49.         a = MIN(a, x[i]);
  50.         b = MAX(b, x[i]);
  51.     }
  52.  
  53.     if (a < min || b > max) {    /* We only do this if we have to */
  54.  
  55.         if (a < min) 
  56.             min = a;
  57.  
  58.         if (b > max)
  59.             max = b;
  60.  
  61.         if (!nticks)
  62.             nticks = 5;
  63.  
  64.         if (ax->scaling == LOGARITHMIC)
  65.             logscale(min, max, nticks, &a, &b, &div);
  66.         else if (plotdev.forceticks) 
  67.             linscale2(min, max, nticks, &a, &b, &div);
  68.         else
  69.             linscale1(min, max, 5, &a, &b, &div);
  70.  
  71.         ax->min = a;
  72.         ax->max = b;
  73.         ax->div = div;
  74.     }
  75. }
  76.