+/*
+ * Compute the optimum format string and the scaling
+ * for the tick drawing on a chart axis
+ * Input: lower: the lowest tick
+ * interval:the interval between the ticks
+ * nticks: the number of tick intervals (bins) on the axis
+ * Return: fs: format string for printf to print the tick value
+ * scale: scaling factor for the tick value
+ * The format string has to be freed after usage.
+ * An example format string and scalefactor:
+ * Non Scientific: "%.3lf", scale=1.00
+ * Scientific: "%.2lfe3", scale = 0.001
+ * Usage example:
+ * fs = chart_get_ticks_format(-0.7,0.1,8,&scale);
+ * printf(fs,value*scale);
+ * free(fs);
+ */
+char *
+chart_get_ticks_format (const double lower, const double interval,
+ const unsigned int nticks, double *scale)
+{
+ double logmax = log10(fmax(fabs(lower + (nticks+1)*interval),fabs(lower)));
+ double logintv = log10(interval);
+ int logshift = 0;
+ char *format_string = NULL;
+ int nrdecs = 0;