#include <vxWorks.h>
#include <string.h>
#include <types.h>
#include <math.h>
#include <time.h>
#include <stdlib.h>
#include <stdioLib.h>

#include <dbEvent.h>
#include <dbDefs.h>
#include <dbCommon.h>
#include <recSup.h>
#include <genSubRecord.h>

long scaler_rat_init( struct genSubRecord *pgsub )
{
  return( 0 );
}

long scaler_rat_proc( struct genSubRecord *pgsub )
{
/* BK this routine performs the scaler ratios  */
	long	*ptr[2];
	int	nelm, jchan;
/*	long	sum_arr[100];
	float	pos_arr[100];*/
	float	pos, sum;
	float *pos_out; /* ratio output */

	ptr[0]=  (long *)pgsub->a;	/* input arrays*/
	ptr[1]=  (long *)pgsub->b;  /* divide A by B */
        
	pos_out=  (float *)pgsub->vala;	/* output (1) A is for ratio of inputs, array of same length*/

	nelm= pgsub->noa;
	for(jchan=0; jchan < nelm; jchan++)
		{
			sum = *(ptr[1]++);
			pos = *(ptr[0]++);
			if( sum > 0 )
				pos = pos / sum;
			else
				pos = 0.;
			*pos_out++ = pos;
		}

  return(0);
}

