/*
SUBROUTINE SCALE(FMN, FMX, N, VALMIN, STEP, VALMAX, IFAULT)
ALGORITHM AS 96 APPL. STATIST. (1976) VOL.25, NO.1
Given extreme values FMN, FMX, and the need for a scale with N
marks, calculates value for the lowest scale mark (VALMIN) and
step length (STEP) and highest scale mark (VALMAX).
*/
#include <math.h>
int scale(float fmn, float fmx, int n, float *valmin, float *step, float *valmax) {
/* Make first estimate of VALMIN */
x=0.5 * (1.0 +(fmax+fmin-range)/(*step));
j=(int)(x-bias);
if (x<0.0) j--;
*valmin=(*step)*(float)j;
/* Test if VALMIN could be zero */
if ((fmin >= 0.0) && (range >= fmax)) *valmin=0.0;
*valmax=(*valmin)+range;
/* Test if VALMAX could be zero */
if ((fmax > 0.0) || (range < (-1)*fmin)) return(ifault);
*valmax=0.0;
*valmin=(-1)*range;
return(ifault);
}