4
* $Id: tick60.c 685 2003-03-08 15:26:51Z travo $
6
* Implement base 60 ticks and labels for coordinate systems.
9
/* Copyright (c) 1996. The Regents of the University of California.
10
All rights reserved. */
14
/* Use sprintf function in labeling functions */
17
extern double ceil(double);
19
/* Here are the possible intervals for a base 60 scale.
20
The 720 interval is skipped if the 1800 was present, otherwise all
21
these intervals will be present in the tick hierarchy. */
23
static GpReal cutoffs[N_CUTS]= { 1800., 720., 360., 180., 90., 30., 10. };
25
int Base60Ticks(GpReal lo, GpReal hi, GpReal nMajor, GpReal nMinor,
26
GpReal *ticks, int nlevel[TICK_LEVELS])
27
/* Puts ticks at multiples of 30, failing if lo<-3600 or hi>+3600.
28
For ticks at multiples of 10 or less, the subdivisions are
29
identical to the default decimal tick scheme. */
31
GpReal finest= (hi-lo)/nMajor;
32
GpReal delta= cutoffs[0];
34
int i0, ntot, nlevs, phase, base, ndivs;
36
if (lo<-3600. || hi>3600. ||
37
finest<=cutoffs[N_CUTS-1] || finest>delta) return 1;
39
for (i0=0 ; i0<N_CUTS && finest<=cutoffs[i0] ; i0++) delta= cutoffs[i0];
40
tick0= ceil(lo/delta)*delta;
41
for (ntot=0 ; tick0<=hi ; ntot++,tick0+=delta) ticks[ntot]= tick0;
45
finest= (hi-lo)/nMinor;
47
/* perform base 60 part of subdivision */
48
for (; i0<N_CUTS && finest<=cutoffs[i0] ; i0++) {
50
i0++; /* skip 720 starting from 1800 */
51
if (finest>cutoffs[i0]) break;
54
ndivs= i0<5? 2 : 3; /* 90->30 and 30->10 are 3, others all 2 */
57
tick0= ceil(lo/delta);
58
phase= (int)(tick0-ceil(tick0/ndivs-.00001)*ndivs);
60
for ( ; tick0<=hi ; tick0+=delta,phase=(phase+1)%ndivs)
61
if (phase) ticks[ntot++]= tick0;
63
if (++nlevs>=TICK_LEVELS) return 0;
65
if (i0<N_CUTS || finest>5.) return 0;
67
/* perform base 10 part of subdivision if necessary */
71
for (; nlevs<TICK_LEVELS ; nlevs++) {
72
tick0= ceil(lo/delta);
73
phase= (int)(tick0-ceil(tick0/ndivs-.00001)*ndivs);
75
for ( ; tick0<=hi ; tick0+=delta,phase=(phase+1)%ndivs)
76
if (phase) ticks[ntot++]= tick0;
83
} else if (finest<=0.1*delta) {
93
if (finest>delta) break;
98
int DegreeLabels(char *label, GpReal value)
99
/* Prints (value+180)%360-180 instead of just value. */
103
if (value<-3600. || value>3600.) return 1;
104
dv= ceil(value-0.00001);
106
if (dv<value) dv= value-dv;
108
if (dv>0.00001) return 1;
109
if (!label) return 0;
111
if (val<=0) val+= 360;
112
sprintf(label, "%d", val-180);
116
int HourLabels(char *label, GpReal value)
117
/* Prints hh:mm (or mm:ss) for value 60*hh+mm (or 60*mm+ss). */
121
if (value<-3600. || value>3600.) return 1;
122
dv= ceil(value-0.00001);
124
if (neg) hh= (int)(-dv);
126
if (dv<value) dv= value-dv;
128
if (dv>0.00001) return 1;
129
if (!label) return 0;
132
sprintf(label, "%s%02d:%02d", (neg?"-":""), hh, mm);