home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 2 / FFMCD02.bin / new / misc / sci / cp / source / tik.c < prev   
Encoding:
C/C++ Source or Header  |  1993-12-21  |  1.7 KB  |  72 lines

  1.  
  2. /* If tick == 0, this works out a "nice" interval, so that there */
  3. /* are between 3 and 7.5 major tick intervals in the input range */
  4. /* "vmin" to "vmax". Using this value for the tick interval or   */
  5. /* supplied value, it also computes "prec" which specifies       */
  6. /* the number of places that should be written after the decimal */
  7. /* point. The recommended number of subticks is returned in      */
  8. /* "nsubt" unless the routine is entered with a non-zero value   */
  9. /* of "nsubt". The output variable "mode" is set to 0 if         */
  10. /* labels are to be written in floating-point format, or to 1 if */
  11. /* they are to be written in fixed-point format.                 */
  12. /* THIS CODE WAS ADAPTED FROM PLPLOT.LIB                         */
  13.  
  14. #include <math.h>
  15. #include <exec/types.h>
  16.  
  17. void tik(double vmin, double vmax, double *tick, WORD *nsubt, BOOL *mode, WORD *prec)
  18. {
  19.  
  20. double t1, t2, vmod;
  21. LONG msd, np, ns;
  22.  
  23.       t1 = fabs(vmin);
  24.       t2 = fabs(vmax);
  25.  
  26.       vmod = max(t1,t2);
  27.  
  28.       *mode = 0;
  29.  
  30.       if (vmod <= 1e-2 || vmod >= 1e3) *mode = 1;
  31.  
  32.       t1 = (double)log10(vmod);
  33.       msd = (LONG)t1;
  34.  
  35.       t1 = (double)log10(fabs(vmax-vmin));
  36.       np = (LONG)t1;
  37.       t1 -= np;
  38.  
  39.       if (t1 > 0.7781512503)
  40.         {
  41.           t2 = 2.0 ;
  42.           ns = 4;
  43.         }
  44.       else if (t1 > 0.4771212549)
  45.         {
  46.           t2 = 1.0 ;
  47.           ns = 5;
  48.         }
  49.       else if (t1 > 0.1760912591)
  50.         {
  51.           t2 = 5.0;
  52.           ns = 5;
  53.           np--;
  54.         }
  55.       else
  56.         {
  57.           t2 = 1.0;
  58.           ns = 4;
  59.           np--;
  60.         }
  61.  
  62.       *tick = t2 * pow(10.0,(double)np);
  63.  
  64.       if (vmin > vmax) *tick = -*tick;
  65.  
  66.       if (*nsubt == 0) *nsubt = ns;
  67.  
  68.       if (*mode != 0)
  69.         *prec = msd - np;
  70.       else
  71.         *prec = max(-np,0);
  72. }
  73.