DOKK / manpages / debian 11 / libmseed-doc / ms_ratapprox.3.en
MS_GENFACTMULT(3) Library Functions Manual MS_GENFACTMULT(3)

ms_genfactmult - Generate SEED sample rate factor and multiplier

#include <libmseed.h>
int  ms_genfactmult ( double samprate, int16_t *factor,
                      int16_t *multiplier );
int  ms_ratapprox ( double real, int *num, int *den,
                    int maxval, double precision );

ms_genfactmult generates an appropriate SEED sample rate factor and multiplier pair from a double precision sample rate. If samprate is positive it is expected to represent a rate in samples/second, if negative is is expected to represent a period in seconds/sample.

Non-integer sample rates and periods are supported between 32767.0 and 1/32767.0. An error will be returned for non-integer rates and periods outside this range.

Integer sample rates and periods are supported between 1 and the maximum possible value (32767 * 32767). Values from 1 to 32767 are represented directly. Values larger than 32767 are factored and represented exactly when possible and approximated otherwise, with the discrepency becoming larger as the values reach the maximum possible value.

The factor and multiplier are int16_t because that is the integer size needed for the fixed section of the SEED data header.

ms_ratapprox finds an approximate rational number for a real through continued fraction expansion. Given a double precision real the routine tries to find a rational in numerator (num) and denominator (den) form whose absolute values are not larger than maxval while trying to reach a specified precision.

ms_genfactmult returns 0 on success and -1 when value is outside of the supported range or error.

ms_ratapprox returns the number of iterations performed.

Chad Trabant
IRIS Data Management Center
2016/10/07 Libmseed API