예제 #1
0
static long process(compressRecord *prec)
{
    long	status=0;
    long	nelements = 0;
    int		alg = prec->alg;

    prec->pact = TRUE;
    if(!dbIsLinkConnected(&prec->inp)
    || dbGetNelements(&prec->inp,&nelements)
    || nelements<=0) {
	recGblSetSevr(prec,LINK_ALARM,INVALID_ALARM);
    } else {
	if(!prec->wptr || nelements!=prec->inpn) {
            if(prec->wptr) {
                free(prec->wptr);
                reset(prec);
            }
	    prec->wptr = (double *)dbCalloc(nelements,sizeof(double));
	    prec->inpn = nelements;
	}
	status = dbGetLink(&prec->inp,DBF_DOUBLE,prec->wptr,0,&nelements);
	if(status || nelements<=0) {
            recGblSetSevr(prec,LINK_ALARM,INVALID_ALARM);
	    status = 0;
	} else {
	    if(alg==compressALG_Average) {
		status = array_average(prec,prec->wptr,nelements);
	    } else if(alg==compressALG_Circular_Buffer) {
		(void)put_value(prec,prec->wptr,nelements);
		status = 0;
	    } else if(nelements>1) {
		status = compress_array(prec,prec->wptr,nelements);
	    }else if(nelements==1){
		status = compress_scalar(prec,prec->wptr);
	    }else status=1;
	}
    }
    /* check event list */
    if(status!=1) {
		prec->udf=FALSE;
		recGblGetTimeStamp(prec);
		monitor(prec);
		/* process the forward scan link record */
		recGblFwdLink(prec);
    }
    prec->pact=FALSE;
    return(0);
}
예제 #2
0
static long init_record(struct RECORDTYPE *precord, int pass)
{
  RECORDTYPE	*self = (RECORDTYPE *)precord;
  long	status;
  DBLINK *plink;

  if (pass == 0){
    if(self->nelm <= 0) self->nelm=1;
    if(self->nelm == 1) {
      self->nord = 1;
    } else {
      self->nord = 0;
    }
    self->bptr = (double *)calloc(self->nelm, sizeof(double));
    if (self->bptr == NULL ){
      self->pact=TRUE;
      /* errlogPrintf("aRaw:(array select) cannot allocate buffer area.");*/
      self->nord = 0;
      if (self->bptr != NULL) free(self->bptr);
      return (-1);
    }
    return(0);
  }

  /* AveDev Record  is a pure soft record */
  plink = &(self->inp);
  if(plink->type == CONSTANT){
    self->bptr = (double *) calloc(1,sizeof(double));
    self->nord = 1;
    recGblInitConstantLink(plink, DBF_DOUBLE, self->bptr);
  }
  else{
    status=dbGetNelements(plink, (signed long *)&self->nord);
    if (self->nord> self->nelm){
      self->nord = self->nelm;
    }
  }
    return(0);
}