MCPcopy Create free account
hub / github.com/GenericMappingTools/gmt / gmtlib_log_array

Function gmtlib_log_array

src/gmt_support.c:15548–15616  ·  view source on GitHub ↗

! . */

Source from the content-addressed store, hash-verified

15546
15547/*! . */
15548unsigned int gmtlib_log_array (struct GMT_CTRL *GMT, double min, double max, double delta, double **array) {
15549 int64_t first, last, i, n, nticks;
15550 double *val = NULL, tvals[10];
15551
15552 /* Because min and max may be tiny values (e.g., 10^-20) we must do all calculations on the log10 (value) */
15553
15554 if (gmt_M_is_zero (delta))
15555 return (0);
15556 min = d_log10 (GMT, min);
15557 max = d_log10 (GMT, max);
15558 first = lrint (floor (min));
15559 last = lrint (ceil (max));
15560
15561 if (delta < 0) { /* Coarser than every magnitude */
15562 n = gmtlib_linear_array (GMT, min, max, fabs (delta), 0.0, array);
15563 for (i = 0; i < n; i++) (*array)[i] = pow (10.0, (*array)[i]);
15564 return ((unsigned int)n);
15565 }
15566
15567 tvals[0] = 0.0; /* Common to all */
15568 switch (lrint (fabs (delta))) {
15569 case 2: /* Annotate 1, 2, 5, 10 */
15570 tvals[1] = d_log10 (GMT, 2.0);
15571 tvals[2] = d_log10 (GMT, 5.0);
15572 tvals[3] = 1.0;
15573 nticks = 3;
15574 break;
15575 case 3: /* Annotate 1, 2, ..., 8, 9, 10 */
15576 nticks = 9;
15577 for (i = 1; i <= nticks; i++) tvals[i] = d_log10 (GMT, (double)(i + 1));
15578 break;
15579 default: /* Annotate just 1 and 10 */
15580 nticks = 1;
15581 tvals[1] = 1.0;
15582 }
15583
15584 /* Assign memory to array (may be a bit too much) */
15585 n = (last - first + 1) * nticks + 1;
15586 val = gmt_M_memory (GMT, NULL, n, double);
15587
15588 /* Find the first logarithm larger than min */
15589 i = 0;
15590 val[0] = (double) first;
15591 while (min - val[0] > GMT_CONV4_LIMIT && i < nticks) {
15592 i++;
15593 val[0] = first + tvals[i];
15594 }
15595
15596 /* Find the first logarithm larger than max */
15597 n = 0;
15598 while (val[n] - max < GMT_CONV4_LIMIT) {
15599 if (i >= nticks) {
15600 i -= nticks;
15601 first++;
15602 }
15603 i++; n++;
15604 val[n] = first + tvals[i];
15605 }

Callers 5

gmtplot_logx_gridFunction · 0.85
gmtplot_logy_gridFunction · 0.85
GMT_makecptFunction · 0.85
gmtlib_coordinate_arrayFunction · 0.85
gmt_create_arrayFunction · 0.85

Calls 1

gmtlib_linear_arrayFunction · 0.85

Tested by

no test coverage detected