| [1844] | 1 | #include "gp_axis.h"
 | 
|---|
 | 2 | #include <math.h>
 | 
|---|
 | 3 | AXIS axis_array[AXIS_ARRAY_SIZE] = AXIS_ARRAY_INITIALIZER(DEFAULT_AXIS_STRUCT);
 | 
|---|
 | 4 | 
 | 
|---|
 | 5 | void dummy(){
 | 
|---|
 | 6 | 
 | 
|---|
 | 7 |   int k=4;
 | 
|---|
 | 8 |   
 | 
|---|
 | 9 | }
 | 
|---|
 | 10 | /*{{{  dbl_raise() used by set_tics */
 | 
|---|
 | 11 | /* FIXME HBB 20000426: is this really useful? */
 | 
|---|
 | 12 | static double
 | 
|---|
 | 13 | dbl_raise(x, y)
 | 
|---|
 | 14 | double x;
 | 
|---|
 | 15 | int y;
 | 
|---|
 | 16 | {
 | 
|---|
 | 17 |     register int i = abs(y);
 | 
|---|
 | 18 |     double val = 1.0;
 | 
|---|
 | 19 | 
 | 
|---|
 | 20 |     while (--i >= 0)
 | 
|---|
 | 21 |         val *= x;
 | 
|---|
 | 22 | 
 | 
|---|
 | 23 |     if (y < 0)
 | 
|---|
 | 24 |         return (1.0 / val);
 | 
|---|
 | 25 |     return (val);
 | 
|---|
 | 26 | }
 | 
|---|
 | 27 | 
 | 
|---|
 | 28 | /*}}} */
 | 
|---|
 | 29 | 
 | 
|---|
 | 30 | /*{{{  set_tic() */
 | 
|---|
 | 31 | /* the guide parameter was intended to allow the number of tics
 | 
|---|
 | 32 |  * to depend on the relative sizes of the plot and the font.
 | 
|---|
 | 33 |  * It is the approximate upper limit on number of tics allowed.
 | 
|---|
 | 34 |  * But it did not go down well with the users.
 | 
|---|
 | 35 |  * A value of 20 gives the same behaviour as 3.5, so that is
 | 
|---|
 | 36 |  * hardwired into the calls to here. Maybe we will restore it
 | 
|---|
 | 37 |  * to the automatic calculation one day
 | 
|---|
 | 38 |  */
 | 
|---|
 | 39 | 
 | 
|---|
 | 40 | double
 | 
|---|
 | 41 | set_tic(l10, guide)
 | 
|---|
 | 42 |      double l10;
 | 
|---|
 | 43 |      int guide;
 | 
|---|
 | 44 | {
 | 
|---|
 | 45 |     double xnorm, tics, posns;
 | 
|---|
 | 46 | 
 | 
|---|
 | 47 |     int fl = (int) floor(l10);
 | 
|---|
 | 48 |     xnorm = pow(10.0, l10 - fl);        /* approx number of decades */
 | 
|---|
 | 49 | 
 | 
|---|
 | 50 |     posns = guide / xnorm;      /* approx number of tic posns per decade */
 | 
|---|
 | 51 | 
 | 
|---|
 | 52 |     if (posns > 40)
 | 
|---|
 | 53 |         tics = 0.05;            /* eg 0, .05, .10, ... */
 | 
|---|
 | 54 |     else if (posns > 20)
 | 
|---|
 | 55 |         tics = 0.1;             /* eg 0, .1, .2, ... */
 | 
|---|
 | 56 |     else if (posns > 10)
 | 
|---|
 | 57 |         tics = 0.2;             /* eg 0,0.2,0.4,... */
 | 
|---|
 | 58 |     else if (posns > 4)
 | 
|---|
 | 59 |         tics = 0.5;             /* 0,0.5,1, */
 | 
|---|
 | 60 |     else if (posns > 1)
 | 
|---|
 | 61 |         tics = 1;               /* 0,1,2,.... */
 | 
|---|
 | 62 |     else if (posns > 0.5)
 | 
|---|
 | 63 |         tics = 2;               /* 0, 2, 4, 6 */
 | 
|---|
 | 64 |     else
 | 
|---|
 | 65 |         /* getting desperate... the ceil is to make sure we
 | 
|---|
 | 66 |          * go over rather than under - eg plot [-10:10] x*x
 | 
|---|
 | 67 |          * gives a range of about 99.999 - tics=xnorm gives
 | 
|---|
 | 68 |          * tics at 0, 99.99 and 109.98  - BAD !
 | 
|---|
 | 69 |          * This way, inaccuracy the other way will round
 | 
|---|
 | 70 |          * up (eg 0->100.0001 => tics at 0 and 101
 | 
|---|
 | 71 |          * I think latter is better than former
 | 
|---|
 | 72 |          */
 | 
|---|
 | 73 |         tics = ceil(xnorm);
 | 
|---|
 | 74 | 
 | 
|---|
 | 75 |     return (tics * dbl_raise(10.0, fl));
 | 
|---|
 | 76 | }
 | 
|---|
 | 77 | /* this is used in a few places all over the code: undo logscaling of
 | 
|---|
 | 78 |  * a given range if necessary. If checkrange is TRUE, will int_error() if
 | 
|---|
 | 79 |  * range is invalid */
 | 
|---|
 | 80 | void
 | 
|---|
 | 81 | axis_unlog_interval(axis, min, max, checkrange)
 | 
|---|
 | 82 |     AXIS_INDEX axis;
 | 
|---|
 | 83 |     double *min, *max;
 | 
|---|
 | 84 |     TBOOLEAN checkrange;
 | 
|---|
 | 85 | {
 | 
|---|
 | 86 |     if (axis_array[axis].log) {
 | 
|---|
 | 87 |       if (checkrange && (*min<= 0.0 || *max <= 0.0))printf(" axis_unlog_interval : range must be > 0 !! \n");
 | 
|---|
 | 88 |           /*int_error(NO_CARET,
 | 
|---|
 | 89 |                       "%s range must be greater than 0 for log scale",
 | 
|---|
 | 90 |                       axis_defaults[axis].name);*/
 | 
|---|
 | 91 |         *min = (*min<=0) ? -VERYLARGE : AXIS_DO_LOG(axis,*min);
 | 
|---|
 | 92 |         *max = (*max<=0) ? -VERYLARGE : AXIS_DO_LOG(axis,*max);
 | 
|---|
 | 93 |     }
 | 
|---|
 | 94 | } 
 | 
|---|
 | 95 | 
 | 
|---|
 | 96 | /*}}} */
 | 
|---|
 | 97 | 
 | 
|---|