00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include "plplotP.h"
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 void
00038 pldtik(PLFLT vmin, PLFLT vmax, PLFLT *tick, PLINT *nsubt, PLBOOL ld)
00039 {
00040 PLFLT t1, t2, tick_reasonable;
00041 PLINT np, ns;
00042 PLFLT factor;
00043
00044
00045 if (ld) {
00046
00047 pldtfac(vmin, vmax, &factor, NULL);
00048
00049 *tick = *tick / factor;
00050 vmin = vmin / factor;
00051 vmax = vmax / factor;
00052 }
00053
00054
00055
00056 t1 = (PLFLT) log10(ABS(vmax - vmin));
00057 np = (PLINT) floor(t1);
00058 t1 = t1 - np;
00059
00060
00061
00062 if (t1 > 0.7781512503) {
00063 t2 = 2.0;
00064 ns = 4;
00065 }
00066 else if (t1 > 0.4771212549) {
00067 t2 = 1.0;
00068 ns = 5;
00069 }
00070 else if (t1 > 0.1760912591) {
00071 t2 = 5.0;
00072 ns = 5;
00073 np = np - 1;
00074 }
00075 else {
00076 t2 = 2.0;
00077 ns = 4;
00078 np = np - 1;
00079 }
00080
00081
00082
00083 tick_reasonable = t2 * pow(10.0, (double) np);
00084 if (*tick == 0) {
00085 *tick = t2 * pow(10.0, (double) np);
00086 }
00087 else {
00088 *tick = ABS(*tick);
00089 if(*tick < 1.e-4*tick_reasonable) {
00090 plexit("pldtik: magnitude of specified tick spacing is much too small");
00091 return;
00092 }
00093 }
00094 if (*nsubt == 0)
00095 *nsubt = ns;
00096
00097 *nsubt = ABS(*nsubt);
00098
00099 if (ld) {
00100 *tick = *tick*factor;
00101 }
00102 }
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113 void
00114 pldtfac(PLFLT vmin, PLFLT vmax, PLFLT *factor, PLFLT *start) {
00115 PLFLT diff;
00116 PLINT year, month, day, hour, min;
00117 PLFLT sec;
00118
00119 diff = vmax - vmin;
00120
00121 if (start != NULL) {
00122 plbtime(&year, &month, &day, &hour, &min, &sec, vmin);
00123 }
00124
00125 if (diff < 3.0*60.0) {
00126
00127 *factor = 1.0;
00128 if (start != NULL) {
00129 sec = 0.;
00130 plctime(year, month, day, hour, min, sec, start);
00131 }
00132 }
00133 else if (diff < 3.0*60.0*60.0) {
00134
00135 *factor = 60.0;
00136 if (start != NULL) {
00137 sec = 0.;
00138 min = 0;
00139 plctime(year, month, day, hour, min, sec, start);
00140 }
00141 }
00142 else if (diff < 3.0*60.0*60.0*24.0) {
00143
00144 *factor = 60.0*60.0;
00145 if (start != NULL) {
00146 sec = 0.;
00147 min = 0;
00148 hour = 0;
00149 plctime(year, month, day, hour, min, sec, start);
00150 }
00151 }
00152 else if (diff < 3.0*60.0*60.0*24.0*7.0) {
00153
00154 *factor = 60.0*60.0*24.0;
00155 if (start != NULL) {
00156 sec = 0.;
00157 min = 0;
00158 hour = 0;
00159 plctime(year, month, day, hour, min, sec, start);
00160 }
00161 }
00162 else if (diff < 3.0*60.0*60.0*24.0*365) {
00163
00164 *factor = 60.0*60.0*24.0*7.0;
00165 if (start != NULL) {
00166 sec = 0.;
00167 min = 0;
00168 hour = 0;
00169 plctime(year, month, day, hour, min, sec, start);
00170 }
00171 }
00172 else {
00173
00174 *factor = 60.0*60.0*24.0*365.25;
00175 if (start != NULL) {
00176 sec = 0.;
00177 min = 0;
00178 hour = 0;
00179 day = 0;
00180 month = 0;
00181 plctime(year, month, day, hour, min, sec, start);
00182 }
00183 }
00184
00185 }
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226 #define MIN_FLTDIG 3
00227 #define MAX_FIXDIG_POS 6
00228 #define MAX_FIXDIG_NEG 4
00229 #define DIGMAX_DEF 5
00230
00231 void
00232 pldprec(PLFLT vmin, PLFLT vmax, PLFLT tick, PLINT lf,
00233 PLINT *mode, PLINT *prec, PLINT digmax, PLINT *scale)
00234 {
00235 PLFLT chosen, notchosen, vmod, t0;
00236 PLINT msd, notmsd, np, digmin, digfix;
00237
00238 *mode = 0;
00239 *scale = 0;
00240
00241 if (digmax == 0)
00242 digmax = DIGMAX_DEF;
00243
00244
00245 chosen = (ABS(vmax) >= ABS(vmin))? vmax: vmin;
00246 notchosen = (ABS(vmax) >= ABS(vmin))? vmin: vmax;
00247
00248
00249 if(ABS(chosen) > 0.) {
00250 vmod = ABS(chosen);
00251 t0 = (PLFLT) log10(vmod);
00252 msd = (PLINT) floor(t0);
00253 }
00254 else {
00255
00256 vmod = 1.;
00257 t0 = (PLFLT) log10(vmod);
00258 msd = (PLINT) floor(t0);
00259 }
00260
00261 if(ABS(notchosen) > 0.)
00262 notmsd = (PLINT) floor( (PLFLT) log10(ABS(notchosen)));
00263 else
00264 notmsd = msd;
00265
00266
00267
00268 if (msd >= 0) {
00269
00270 digmin = msd + 1;
00271 digfix = MAX_FIXDIG_POS;
00272 if (digmax > 0)
00273 digfix = MIN(digmax, MAX_FIXDIG_POS);
00274 }
00275 else {
00276
00277 digmin = -msd + 2;
00278 digfix = MAX_FIXDIG_NEG;
00279 if (digmax > 0)
00280 digfix = MIN(digmax, MAX_FIXDIG_NEG);
00281 }
00282
00283
00284
00285
00286
00287
00288
00289 if(chosen < 0.||(notchosen < 0. && (notmsd == msd || msd <= 0)))
00290 digmin = digmin + 1;
00291
00292 if (digmin > digfix && !lf) {
00293 *mode = 1;
00294 *scale = msd;
00295 }
00296
00297
00298
00299
00300 np = (PLINT) floor(log10(ABS(tick)));
00301
00302 if (*mode != 0)
00303 *prec = msd - np;
00304 else
00305 *prec = MAX(-np, 0);
00306
00307
00308
00309
00310
00311 if (*mode == 0 && digmax > 0 && !lf) {
00312 if (t0 < 0.0) {
00313 if (digmax - 2 - *prec < 0) {
00314 *mode = 1;
00315 *scale = msd;
00316 }
00317 }
00318 else
00319 *prec = MAX(MIN(*prec, digmax - msd - 1), 0);
00320 }
00321 if (*mode != 0) {
00322 *prec = msd - np;
00323 *prec = MAX(MIN(*prec, MAX(digmax-1, MIN_FLTDIG)), 0);
00324 }
00325 }