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