#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

#include <dbDefs.h>
#include <registryFunction.h>
#include <subRecord.h>
#include <aSubRecord.h>
#include <epicsExport.h>

int CwavDebug;

static long CwavInit(aSubRecord *precord)
{

  if (CwavDebug)
    printf("Record %s called CwavInit(%p)\n",
           precord->name, (void*) precord);
  return 0;
}

static long CwavProcess(aSubRecord *precord)
{
        unsigned long i,j1;
        long  anord,bnord;
long *cin; epicsFloat32 *ain,*bin;
epicsFloat32 *p_ch1;
ain = (epicsFloat32 *)precord->a; /* new wave */ cin = (long*)precord->c; /* new wave nord */
anord = cin[0]; bin = (epicsFloat32 *)precord->b; /* old record */ bnord = precord->neb;
p_ch1 = (epicsFloat32 *)precord->vala; j1=10000-anord; if ((j1<0)||(j1>10000)) j1= 0;
/*printf("j1 = %ld\n",j1); */
for (i=0;i<j1;i++){ p_ch1[i]=bin[i+anord]; }
for (i=j1;i<10000;i++){ p_ch1[i]=ain[i-j1]; } precord->neva = 10000; return 0L;
}epicsExportAddress(int, CwavDebug); epicsRegisterFunction(CwavInit); epicsRegisterFunction(CwavProcess);