Exemple #1
0
void corbetw2mat_paired(int nrow, int ncol, double **X, double **Y,
                        double *cor)
{
    int i, j, n;
    double temp;

    for(j=0; j<ncol; j++) {
        for(i=0; i<nrow; i++) {
            if(!R_FINITE(X[j][i]) || !R_FINITE(Y[j][i]))
                X[j][i] = Y[j][i] = NA_REAL;
        }
    }

    fscale(nrow, ncol, X);
    fscale(nrow, ncol, Y);

    for(j=0; j<ncol; j++) {
        temp=0.0;
        n=0;
        for(i=0; i<nrow; i++) {
            if(R_FINITE(X[j][i]) && R_FINITE(Y[j][i])) {
                temp += (X[j][i] * Y[j][i]);
                n++;
            }
        }
        if(n > 1) cor[j] = temp/(double)(n-1);
    }

}
Exemple #2
0
void corbetw2mat_unpaired_lr(int nrow, int ncolx, double **X,
                             int ncoly, double **Y,
                             double *cor, int *index)
{
    int i, jx, jy, n, theindex;
    double temp, themax;
    double *XX, *YY;

    XX = (double *)R_alloc(nrow, sizeof(double));
    YY = (double *)R_alloc(nrow, sizeof(double));

    for(jx=0; jx<ncolx; jx++) {
        theindex = NA_INTEGER;
        themax = -2.0;

        for(jy=0; jy<ncoly; jy++) {
            temp=0.0;
            n=0;

            memcpy(XX, X[jx], nrow*sizeof(double));
            memcpy(YY, Y[jy], nrow*sizeof(double));
            for(i=0; i<nrow; i++) {
                if(!R_FINITE(XX[i]) || !R_FINITE(YY[i]))
                    XX[i] = YY[i] = NA_REAL;
            }
            fscale(nrow, 1, &XX);
            fscale(nrow, 1, &YY);

            for(i=0; i<nrow; i++) {
                if(R_FINITE(XX[i])) {
                    temp += (XX[i] * YY[i]);
                    n++;
                }
            }
            if(n > 1) {
                temp /= (double)(n-1);
                if(temp > themax) {
                    themax = temp;
                    theindex = jy;
                }
            }

        } /* end loop over col of y */
        if(themax == -2 && theindex == NA_INTEGER) {
            cor[jx] = NA_REAL;
            index[jx] = NA_INTEGER;
        }
        else {
            cor[jx] = themax;
            index[jx] = theindex+1;
        }

    } /* end loop over col of x */
}
Exemple #3
0
static int
outl_lineto(
	FT_Vector *to,
	void *unused
)
{
	double tox, toy;

	tox = fscale((double)to->x); toy = fscale((double)to->y);

	fg_rlineto(curg, tox, toy);
	lastx = tox; lasty = toy;

	return 0;
}
Exemple #4
0
void corbetw2mat_unpaired_best(int nrow, int ncolx, double **X,
                               int ncoly, double **Y,
                               double *cor,
                               int *xindex, int *yindex,
                               int *numpairs, double corthresh)
{
    int i, jx, jy, n;
    double temp;
    double *XX, *YY;

    XX = (double *)R_alloc(nrow, sizeof(double));
    YY = (double *)R_alloc(nrow, sizeof(double));

    *numpairs = 0;
    for(jx=0; jx<ncolx; jx++) {
        for(jy=0; jy<ncoly; jy++) {
            temp=0.0;
            n=0;

            memcpy(XX, X[jx], nrow*sizeof(double));
            memcpy(YY, Y[jy], nrow*sizeof(double));
            for(i=0; i<nrow; i++) {
                if(!R_FINITE(XX[i]) || !R_FINITE(YY[i]))
                    XX[i] = YY[i] = NA_REAL;
            }
            fscale(nrow, 1, &XX);
            fscale(nrow, 1, &YY);

            for(i=0; i<nrow; i++) {
                if(R_FINITE(XX[i])) {
                    temp += (XX[i] * YY[i]);
                    n++;
                }
            }
            if(n > 1) {
                temp /= (double)(n-1);
                if(temp >= corthresh) {
                    cor[*numpairs] = temp;
                    xindex[*numpairs] = jx+1;
                    yindex[*numpairs] = jy+1;
                    (*numpairs)++;
                }
            }

        } /* end loop over col of y */
    } /* end loop over col of x */
}
Exemple #5
0
int main(int argc, char *argv[]) {
	if (argc != 3)
		return 1;
	double d1 = atof(argv[1]);
	int pow = atoi(argv[2]);

	printf("fscale(%f, %d) = %f\n", d1, pow, fscale(d1, pow));
	return 0;
}
Exemple #6
0
static int
outl_moveto(
	FT_Vector *to,
	void *unused
)
{
	double tox, toy;

	tox = fscale((double)to->x); toy = fscale((double)to->y);

	/* FreeType does not do explicit closepath() */
	if(curg->lastentry) {
		g_closepath(curg);
	}
	fg_rmoveto(curg, tox, toy);
	lastx = tox; lasty = toy;

	return 0;
}
Exemple #7
0
static int
outl_conicto(
	FT_Vector *control1,
	FT_Vector *to,
	void *unused
)
{
	double c1x, c1y, tox, toy;

	c1x = fscale((double)control1->x); c1y = fscale((double)control1->y);
	tox = fscale((double)to->x); toy = fscale((double)to->y);

	fg_rrcurveto(curg,
		(lastx + 2.0 * c1x) / 3.0, (lasty + 2.0 * c1y) / 3.0,
		(2.0 * c1x + tox) / 3.0, (2.0 * c1y + toy) / 3.0,
		tox, toy );
	lastx = tox; lasty = toy;

	return 0;
}
Exemple #8
0
void corbetw2mat_unpaired_all(int nrow, int ncolx, double **X,
                              int ncoly, double **Y,
                              double **Cor)
{
    int i, jx, jy, n;
    double temp;
    double *XX, *YY;

    XX = (double *)R_alloc(nrow, sizeof(double));
    YY = (double *)R_alloc(nrow, sizeof(double));

    for(jy=0; jy<ncoly; jy++) {
        for(jx=0; jx<ncolx; jx++) {
            temp=0.0;
            n=0;

            memcpy(XX, X[jx], nrow*sizeof(double));
            memcpy(YY, Y[jy], nrow*sizeof(double));
            for(i=0; i<nrow; i++) {
                if(!R_FINITE(XX[i]) || !R_FINITE(YY[i]))
                    XX[i] = YY[i] = NA_REAL;
            }
            fscale(nrow, 1, &XX);
            fscale(nrow, 1, &YY);

            for(i=0; i<nrow; i++) {
                if(R_FINITE(XX[i])) {
                    temp += (XX[i] * YY[i]);
                    n++;
                }
            }
            if(n > 1) Cor[jy][jx] = temp/(double)(n-1);
            else Cor[jy][jx] = NA_REAL;

        } /* end loop over col of y */
    } /* end loop over col of x */
}
Exemple #9
0
void corbetw2mat_self(int nrow, int ncol, double **X,
                      double **Cor)
{
    int i, j, k, n;
    double temp;
    double *XX, *YY;

    XX = (double *)R_alloc(nrow, sizeof(double));
    YY = (double *)R_alloc(nrow, sizeof(double));

    for(j=0; j<ncol-1; j++) {
        for(k=(j+1); k<ncol; k++) {
            temp=0.0;
            n=0;

            memcpy(XX, X[j], nrow*sizeof(double));
            memcpy(YY, X[k], nrow*sizeof(double));
            for(i=0; i<nrow; i++) {
                if(!R_FINITE(XX[i]) || !R_FINITE(YY[i]))
                    XX[i] = YY[i] = NA_REAL;
            }
            fscale(nrow, 1, &XX);
            fscale(nrow, 1, &YY);

            for(i=0; i<nrow; i++) {
                if(R_FINITE(XX[i])) {
                    temp += (XX[i] * YY[i]);
                    n++;
                }
            }
            if(n > 1) Cor[j][k] = temp/(double)(n-1);
            else Cor[j][k] = NA_REAL;
            Cor[k][j] = Cor[j][k];
        } /* end loop over col of x */
    } /* end loop over col of x */
}
Exemple #10
0
int ECandle::calcLightLevel(long startTime,long timeOut, int minLevel, int maxLevel)
/*
функция расчитывает и возвращает значение уровня света в данный момент времени
исходя из запомненного времени последнего события timeOfLastEvent
*/
{
	
#ifdef DEBUG_ECANDLE1
	Serial.print("calcLightLevel: startTime=");	
	Serial.print(startTime);
	Serial.print(", timeOut=");	
	Serial.print(timeOut);
	Serial.print(", minLevel");	
	Serial.print(minLevel);
	Serial.print(", maxLevel=");	
	Serial.print(maxLevel);
#endif	
	int tmp, res;
	int scale = 4;
	if ( minLevel < maxLevel ) { scale = -1 * scale;}; 
	tmp=map( millis(), startTime, startTime + timeOut, minLevel, maxLevel );
	if (minLevel<maxLevel) {
		tmp = constrain( tmp, minLevel, maxLevel );
	} else {
		tmp = constrain( tmp, maxLevel, minLevel );
	}
  //пересчитаем по плавающей логарифмической шкале
 //res = fscale(minLevel,maxLevel,minLevel,maxLevel,tmp,scale);
//	res=tmp;		
	res = fscale( startTime, startTime + timeOut, minLevel, maxLevel,
							millis(), scale ); 
//  Serial.println(res);

#ifdef DEBUG_ECANDLE1
	Serial.print(", res=");
	Serial.println( res );
#endif
	return res;
};
Exemple #11
0
static int
outl_cubicto(
	FT_Vector *control1,
	FT_Vector *control2,
	FT_Vector *to,
	void *unused
)
{
	double c1x, c1y, c2x, c2y, tox, toy;

	c1x = fscale((double)control1->x); c1y = fscale((double)control1->y);
	c2x = fscale((double)control2->x); c2y = fscale((double)control2->y);
	tox = fscale((double)to->x); toy = fscale((double)to->y);

	fg_rrcurveto(curg, c1x, c1y, c2x, c2y, tox, toy);
	lastx = tox; lasty = toy;

	return 0;
}