예제 #1
0
파일: main.cpp 프로젝트: CCJY/coliru
int main()
{
    const std::string str = "mnopqr" ;
    const char cstr[] = "uvwxyz" ;
    
    std::cout << maxv( 233, 23.8, 1200LL, 675243LL, 'A', 123456, short(32) ) << '\n'
              << maxv( str, cstr, "abcdef", std::string( 5, '!' ) ) << '\n' ;
              
    static_assert( std::is_same< std::string, decltype( maxv( str, cstr ) ) >::value , "unexpected" ) ;
}
예제 #2
0
int main(int argc, char** argv) {
	if (argc < 2) {
		printf("Usage: lensview <lens file>\n");
		exit (-1);
	}

	if (!lsystem.Load(argv[1])) {
		printf("Cannot open the lens file: %s.\n", argv[1]);
		exit(-1);
	}
	lvZoom = lvHeight / lsystem.maxAperture() / 3;
	lvZoom = maxv(1, lvZoom);

	glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA);
    glutInitWindowSize(lvWidth, lvHeight);
    glutCreateWindow("lensview");
    glutDisplayFunc(lvDisplay);
    glutMotionFunc(lvMotion);
    glutMouseFunc(lvClick);
    glutKeyboardFunc(lvKey);
	glutReshapeFunc(lvResize);
    glutIdleFunc(NULL);

	glMatrixMode(GL_MODELVIEW);  glLoadIdentity();
    glMatrixMode(GL_PROJECTION); glLoadIdentity();	
	glClearColor(BGR, BGG, BGB, 1);
	
	glutMainLoop();
	return (0);
}
예제 #3
0
int main()
{
	vector<double> price;
	vector<double> weight;
	double temp;
	double sum = 0;

	cout << "Please enter a number of weights followed by the corresponding price per weight unit for that weight.\nWeight: ";

	for (int i = 0; cin >> temp; ++i)
	{
		if (i % 2 == 1)
		{
			price.push_back(temp);
			cout << "\nWeight or ';' to exit: ";
		}
		else if (i % 2 == 0)
		{
			weight.push_back(temp);
			cout << "\nPrice: ";
		}
		else cerr << "Error";
	}

	if (price.size() != weight.size())
		cerr << "Error, vectors not the same size.";

	for (int i = 0; i < price.size(); ++i)
		sum += price[i] * weight[i];

	cout << "The total cost is " << sum << ".\n";
	cout << "The largest weight is " << maxv(weight) << ".\n";
}
예제 #4
0
// Center mesh around origin.
// Fit mesh in box from (-1, -1, -1) to (1, 1, 1)
void Mesh::Normalize()  
{
	float min[3], max[3], Scale;

	setMinMax(min, max);

	Vec3 minv(min);
	Vec3 maxv(max);

	Vec3 dimv = maxv - minv;
	
	if (dimv.x >= dimv.y && dimv.x >= dimv.z) Scale = 2.0f/dimv.x;
	else if (dimv.y >= dimv.x && dimv.y >= dimv.z) Scale = 2.0f/dimv.y;
	else Scale = 2.0f/dimv.z;

	Vec3 transv = minv + maxv;

	transv *= 0.5f;

	for (unsigned int i = 0; i < _vlist.size(); ++i)
	{
		_vlist[i].getXYZ() -= transv;
		_vlist[i].getXYZ() *= Scale;
	}
}
예제 #5
0
파일: trash.c 프로젝트: Acknex/TUST
TrashCollector *trash_create ( int items_max, TrashRemover *remove_function )
{
	TrashCollector *trash = sys_malloc(sizeof(TrashCollector));
	trash->first = NULL;
	trash->top = maxv(items_max,1);
	trash->count = 0;
	trash->delete_function = remove_function;
	return trash;
}
예제 #6
0
int     dbtsolve(int m, double *y)
{
        int i;
        int k, row, consistent=TRUE;
        double beta, *dwork;
        double eps;

	double starttime, endtime;

	starttime = (double) clock();

	MALLOC( dwork, m, double );

        if (rank < m) eps = EPSSOL * maxv(y,m);
	for (i=0; i<m; i++) dwork[i] = y[i];
	for (i=0; i<m; i++) y[icolperm[i]] = dwork[i];

        /*------------------------------------------------------+
        |               -T                                      |
        |       y  <-  U  y                                    */

        for (i=0; i<rank; i++) {
                beta = y[i]/diag[i];
                for (k=0; k<degUt[i]; k++) {
			row = Ut[i][k].i;
                        y[row] -= Ut[i][k].d * beta;
                }
                y[i] = beta;
        }
        for (i=m-1; i>=rank; i--) {
                if ( ABS( y[i] ) > eps ) consistent = FALSE;
                y[i] = 0.0;
        }

        /*------------------------------------------------------+
        |               -T                                      |
        |       y  <-  L  y                                    */

        for (i=rank-1; i>=0; i--) {
                beta = y[i];
                for (k=0; k<degLt[i]; k++) {
                        row = Lt[i][k].i;
                        y[row] -= Lt[i][k].d * beta;
                }
        }

	for (i=0; i<m; i++) dwork[i] = y[i];
	for (i=0; i<m; i++) y[rowperm[i]] = dwork[i];

	FREE( dwork );

	endtime = (double) clock();
	cumtime += endtime - starttime;

        return consistent;
}
int main() try {
	cout << maxv(numbers) << endl;
}
// Error processing
catch (runtime_error& e) {
	cerr << e.what() << "\n";
}
catch (...) {
	cerr << "Unknown exception\n";
} 
예제 #8
0
void Mesh::normalize_coords() {
  vec3 maxv(1, 1, 1);
  for (const auto& v : vertices) {
    maxv = glm::max(maxv, glm::abs(v.Position));
  }
  float normalizer = 1 / (std::max(maxv.x, std::max(maxv.y, maxv.z)));
  for (auto& v : vertices) {
    v.Position = v.Position * normalizer;
  }
}
예제 #9
0
void ebHandsBgFly ()
{
	if (isEbWarghostAlive())
	{
		var handRadius = 500;
		
		snd_play(g_sndSparkle, 100, 0);

		ENTITY* hands [2];
		hands[0] = ent_create("warhand.mdl", vector(-handRadius, 500, 400), ebHandFlyL);
		hands[1] = ent_create("warhand.mdl", vector(handRadius, 500, 400), ebHandFlyR);	
	
		var t = maxv(g_facTimeEbHandsFlyMin, g_facTimeEbHandsFly * (5 + random(5))) * 16;
		
		snd_play(g_sndHandFlyBoth, 100, 0);
		
		while (t > 0)
		{
			t -= time_step;
			wait(1);
		}
		
		g_facTimeEbHandsFly *= g_facTimeEbHandsFlyDec;
		
		ebSndAttack();
		
		int i;
		var m = (1 + random(2)) * 16;
		for (i = 0; i < 2; i++)
		{
			(hands[i])->skill1 = 1;
			(hands[i])->skill2 = m;
		}
		
		while (m > 0)
		{
			m -= time_step;
			wait(1);
		}
		
		snd_play(g_sndSparkle, 100, 0);
		
		wait(-0.5);
		
		VECTOR v;
		vec_set(&v, player->x);
		v.z += 400;
		
		ent_create("warhand.mdl", &v, ebHandWatchSelect);
	}
	
	ptr_remove(my);
}
예제 #10
0
파일: level.c 프로젝트: MasterQ32/SQEditor
function ent_setminmax(ENTITY *ent)
{
	VECTOR pos;
	vec_set(&ent->max_x, vector(-9999999, -9999999, -9999999));
	vec_set(&ent->min_x, vector(9999999, 9999999, 9999999));
	int i;
	CONTACT c;
	for(i = 1; i <= ent_status(ent, 0); i++)
	{
		VECTOR pos;
		ent_getvertex(ent, &c, i);
		pos.x = c.v->x;
		pos.y = c.v->z;
		pos.z = c.v->y;
		//vec_mul(&pos, &ent->scale_x);
		
		ent->max_x = maxv(pos.x, ent->max_x);
		ent->max_y = maxv(pos.y, ent->max_y);
		ent->max_z = maxv(pos.z, ent->max_z);
		ent->min_x = minv(pos.x, ent->min_x);
		ent->min_y = minv(pos.y, ent->min_y);
		ent->min_z = minv(pos.z, ent->min_z);
	}
}
예제 #11
0
int main(int argc, char** argv) {
	if (argc < 2) {
		//printf("Usage: lensview <lens file>\n");
		//exit (-1);
		//argv[1] = ".\\lenses\\dgauss.50mm.dat";
		argv[1] = ".\\lenses\\fisheye.10mm.dat";
		//argv[1] = ".\\lenses\\telephoto.250mm.dat";
		//argv[1] = ".\\lenses\\wide.22mm.dat";
	}


	if (!lsystem.Load(argv[1])) {
		printf("Cannot open the lens file: %s.\n", argv[1]);
		exit(-1);
	}

    printf("1\n");
	lvZoom = lvHeight / lsystem.maxAperture() / 3;
	lvZoom = maxv(1, lvZoom);
    printf("2\n");
	glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA);
    glutInitWindowSize(lvWidth, lvHeight);
    glutCreateWindow("lensview");
    glutDisplayFunc(lvDisplay);
    glutMotionFunc(lvMotion);
    glutMouseFunc(lvClick);
    glutKeyboardFunc(lvKey);
	glutReshapeFunc(lvResize);
    glutIdleFunc(NULL);

	glMatrixMode(GL_MODELVIEW);  glLoadIdentity();
    glMatrixMode(GL_PROJECTION); glLoadIdentity();	
	glClearColor(BGR, BGG, BGB, 1);

    printf("3\n");
	glLineWidth(1);
    printf("4\n");
	lsystem.findIntrinsics();
    printf("5\n");
    lsystem.refocus(zDist, -1);
    printf("6\n");
	glutMainLoop();
	return (0);
}
예제 #12
0
파일: platform.c 프로젝트: Acknex/Ackmania
// uses: durability, speed
action breaking_platform()
{
	ENTITY* ent = ent_create("platform_crumble.wmb", &my->x, NULL); //f**k it
	ent_preload(ent); //f**k it
	set(ent, INVISIBLE | PASSABLE); //f**k it
	
	set(my, is_platform);
	my->event = breaking_platform_evt;
	my->emask |= (ENABLE_IMPACT); 
	if (my->durability <= 0) my->durability = 0.5;
	if (my->speed <= 0)      my->speed = 2;
	
	while(!is(my, is_touched))
	{
		wait (1);
	}

	ent_playsound(me, sndPlatformCrumble, 1000);
	set(me, INVISIBLE | PASSABLE); //f**k it
	reset(ent, INVISIBLE | PASSABLE); //f**k it
	//ent_morph(me, "platform_crumble.wmb");
	wait (-(my->durability));

	ent->speed = my->speed; //f**k it
	ptr_remove(me); //f**k it
	me = ent; //f**k it
	//move downwards
	VECTOR vecSpeed;
	my->alpha = 100;
	set(my, TRANSLUCENT | PASSABLE);
	while(my->alpha != 0)
	{
		vec_set(&vecSpeed, vector(0,0, -(my->speed) * time_step));
		c_move(me, nullvector, &vecSpeed, IGNORE_MODELS | IGNORE_SPRITES | IGNORE_WORLD | IGNORE_PASSABLE | IGNORE_PASSENTS | IGNORE_MAPS);
		my->alpha = maxv(my->alpha - (my->speed * time_step * 0.5), 0);
		wait (1);
	}

	ptr_remove(me);
}
예제 #13
0
function dialog_say(int dialog)
{
	if(dialogEntries[dialog].initialized == NULL) return;
	proc_kill(4);
	
	var soundID = -1;
	if(dialogEntries[dialog].sound != NULL)
	{
		soundID = snd_play(dialogEntries[dialog].sound, 100, 0);
	}
	set(dialogText, SHOW);
	(dialogText->pstring)[0] = dialogEntries[dialog].text;
	dialogText->alpha = 0;
	var timer = 32;
	while(timer > 0 || snd_playing(soundID))
	{
		dialogText->pos_x = 0.5 * screen_size.x;
		dialogText->pos_y = screen_size.y - 64;
		
		if(timer > 8)
		{
			dialogText->alpha = minv(100, dialogText->alpha + 12 * time_step);
		}
		else
		{
			dialogText->alpha = maxv(0, dialogText->alpha - 12 * time_step);
		}
		
		if(!snd_playing(soundID))
			timer -= time_step;
		
		wait(1);
	}
	reset(dialogText, SHOW);
	dialogText->alpha = 0;
}
예제 #14
0
void OccluderComponent::setVertices(const Vec3* begin, U count, U stride)
{
	ANKI_ASSERT(begin);
	ANKI_ASSERT(count > 0 && (count % 3) == 0);
	ANKI_ASSERT(stride >= sizeof(Vec3));

	m_begin = begin;
	m_count = count;
	m_stride = stride;

	Vec3 minv(MAX_F32), maxv(MIN_F32);
	while(count--)
	{
		const Vec3& v = *reinterpret_cast<const Vec3*>(reinterpret_cast<const U8*>(begin) + stride * count);
		for(U i = 0; i < 3; ++i)
		{
			minv[i] = min(minv[i], v[i]);
			maxv[i] = max(maxv[i], v[i]);
		}
	}

	m_aabb.setMin(minv.xyz0());
	m_aabb.setMax(maxv.xyz0());
}
예제 #15
0
Vector2D Vector2D::clampv(const Vector2D & a, const Vector2D & a_min, const Vector2D & a_max) { return minv(maxv(a, a_min), a_max); }
예제 #16
0
/*! \brief
 * Function that does the analysis for a single frame.
 *
 * It is called once for each frame.
 */
static int analyze_frame(t_topology *top, t_trxframe *fr, t_pbc *pbc,
              int nr, gmx_ana_selection_t *sel[], void *data)
{
    t_analysisdata      *d = (t_analysisdata *)data;
    t_electrostatics    dat;
    
    /* Print the current frame number to the xvg file */
    if (d->fp) {
        fprintf(d->fp, "%10i ", d->framen);
    }
    
    /* Index the pqr file to the frame number */
    std::string pqrname(d->pqr);
    pqrname = pqrname.substr(0,pqrname.size()-4);
    std::stringstream pqr;
    pqr << pqrname << d->framen << ".pqr";
    FILE *pqrout;
    if ( d->dopqr ) {
        pqrout = ffopen(pqr.str().c_str(), "w");
        if ( pqrout == NULL ) {
            gmx_fatal(FARGS, "\nFailed to open output file, '%s'\n",pqrout);
        }
    }
    
    /* Get the bond vector and bond midpoint */
    rvec bondvector, midpoint;
    rvec_sub(fr->x[d->a2],fr->x[d->a1],bondvector);
    double bondlength = pow( iprod(bondvector,bondvector), 0.5);
    for (int i=0; i<3; i++){
        midpoint[i] = fr->x[d->a1][i] + 0.5 * bondvector[i];
    }
    
    /* 
     * Defined axes based on the nitrile bond vector
     * The z-axis is the bond axis
     * The y-axis is from solving y0 = -(z1*y1+z2*y2)/z0, where (y1,y2)=(z2,-z0), then normalizing
     * The x-axis is the cross product of the y-axis with the z-axis
     */
    double zvec[3] = { bondvector[0] / bondlength, bondvector[1] / bondlength, bondvector[2] / bondlength };
    double yvec[3] = { 1, 1, 1 };
    if (zvec[0] != 0 ) {
        yvec[0] = -(zvec[1]*yvec[1]+zvec[2]*yvec[2]) / zvec[0] ; }
    else if (zvec[1] != 0 ) {
        yvec[1] = -(zvec[0]*yvec[0]+zvec[2]*yvec[2]) / zvec[1] ; }
    else if (zvec[2] != 0 ) {
        yvec[2] = -(zvec[0]*yvec[0]+zvec[1]*yvec[1]) / zvec[2] ; }
    else {
        std::cerr << "\nERROR! Bond length is 0!  This cannoy be correct!\n";
        std::cerr << "BondVEC: " << bondvector[0] << " " << bondvector[1] << " " << bondvector[2] << std::endl;
        std::cerr << "ZVEC: " << zvec[0] << " " << zvec[1] << " " << zvec[2] << std::endl;
    }
    /* Normalize */
    double ylen = pow(dot(yvec,yvec),0.5);
    for (int i=0; i<3;i++) {
        yvec[i] = yvec[i]/ylen;
    }
    double xvec[3];
    cross(yvec,zvec,xvec);
    double xlen = pow(dot(xvec,xvec),0.5);
    for (int i=0; i<3;i++) {
        xvec[i] = xvec[i]/xlen;
    }
    
    /* Find the points that are Cho group-sites for calculating the potential */
    std::vector<std::vector<double> > each_point;
    int nsites = 0;
    if (d->site_ndx.size() > 0) {
        /* 
         * There are 8 sites from -a1, 8 sites from -a2, 1 site along the bond vector
         * and 1 site for each atom in site_ndx
         */
        nsites = d->site_ndx.size() + 17;
        int n = 0;
        each_point = std::vector<std::vector<double> > (nsites, std::vector<double> (3,0));
        //std::vector<std::vector<double> > each_point(nsites,std::vector<double> (3,0));
        /* Assign coordinates for the atoms in site_ndx */
        for (int i=0; i<(int)d->site_ndx.size(); i++) {
            for (int j=0; j<3; j++) {
                each_point[n][j] = fr->x[d->site_ndx[i]][j];
            }
            n++;
        }
        /* Assign coordinate for the site along the bond vector */
        for (int i=0; i<3; i++) {
            each_point[n][i] = fr->x[d->a2][i] + bondvector[i] / bondlength * d->ring_dist;
        }
        n++;
        /* 8 points around -a1 */
        ring_points( fr->x[d->a1], &xvec[0], &yvec[0], &zvec[0], d->ring_dist, each_point,n);
        /* 8 points around -a2 */
        ring_points( fr->x[d->a2], &xvec[0], &yvec[0], &zvec[0], d->ring_dist, each_point,n);
        std::vector<double> minv(3,10);
        std::vector<double> maxv(3,-10);
    }
    
    /* Find the dummy atom points */
    /* midpoint xyz vectors */
    double pzcomp[3], nzcomp[3], pycomp[3], nycomp[3], pxcomp[3], nxcomp[3];
    /* -a1 xyz vectors */
    double pzcomp1[3], nzcomp1[3], pycomp1[3], nycomp1[3], pxcomp1[3], nxcomp1[3];
    /* -a2 xyz vectors */
    double pzcomp2[3], nzcomp2[3], pycomp2[3], nycomp2[3], pxcomp2[3], nxcomp2[3];

    for (int i=0; i<3; i++) {
        /* midpoint xyz vectors */
        pzcomp[i] = midpoint[i] + zvec[i] * d->delta;
        nzcomp[i] = midpoint[i] - zvec[i] * d->delta;
        pycomp[i] = midpoint[i] + yvec[i] * d->delta;
        nycomp[i] = midpoint[i] - yvec[i] * d->delta;
        pxcomp[i] = midpoint[i] + xvec[i] * d->delta;
        nxcomp[i] = midpoint[i] - xvec[i] * d->delta;
        /* -a1 xyz vectors */
        pzcomp1[i] = fr->x[d->a1][i] + zvec[i] * d->delta;
        nzcomp1[i] = fr->x[d->a1][i] - zvec[i] * d->delta;
        pycomp1[i] = fr->x[d->a1][i] + yvec[i] * d->delta;
        nycomp1[i] = fr->x[d->a1][i] - yvec[i] * d->delta;
        pxcomp1[i] = fr->x[d->a1][i] + xvec[i] * d->delta;
        nxcomp1[i] = fr->x[d->a1][i] - xvec[i] * d->delta;
        /* -a2 xyz vectors */
        pzcomp2[i] = fr->x[d->a2][i] + zvec[i] * d->delta;
        nzcomp2[i] = fr->x[d->a2][i] - zvec[i] * d->delta;
        pycomp2[i] = fr->x[d->a2][i] + yvec[i] * d->delta;
        nycomp2[i] = fr->x[d->a2][i] - yvec[i] * d->delta;
        pxcomp2[i] = fr->x[d->a2][i] + xvec[i] * d->delta;
        nxcomp2[i] = fr->x[d->a2][i] - xvec[i] * d->delta;
    }

    /* Write all the dummy atoms to the pqr file */
    if ( d->dopqr ) {
        write_dummy_atom( pqrout, nzcomp, "MIDz" );
        write_dummy_atom( pqrout, pzcomp, "MIDz" );
        write_dummy_atom( pqrout, nycomp, "MIDy" );
        write_dummy_atom( pqrout, pycomp, "MIDy" );
        write_dummy_atom( pqrout, nxcomp, "MIDx" );
        write_dummy_atom( pqrout, pxcomp, "MIDx" );
    
        write_dummy_atom( pqrout, nzcomp1, (std::string)*top->atoms.atomname[d->a1]+"z" );
        write_dummy_atom( pqrout, pzcomp1, (std::string)*top->atoms.atomname[d->a1]+"z" );
        write_dummy_atom( pqrout, nycomp1, (std::string)*top->atoms.atomname[d->a1]+"y" );
        write_dummy_atom( pqrout, pycomp1, (std::string)*top->atoms.atomname[d->a1]+"y" );
        write_dummy_atom( pqrout, nxcomp1, (std::string)*top->atoms.atomname[d->a1]+"x" );
        write_dummy_atom( pqrout, pxcomp1, (std::string)*top->atoms.atomname[d->a1]+"x" );
    
        write_dummy_atom( pqrout, nzcomp2, (std::string)*top->atoms.atomname[d->a2]+"z" );
        write_dummy_atom( pqrout, pzcomp2, (std::string)*top->atoms.atomname[d->a2]+"z" );
        write_dummy_atom( pqrout, nycomp2, (std::string)*top->atoms.atomname[d->a2]+"y" );
        write_dummy_atom( pqrout, pycomp2, (std::string)*top->atoms.atomname[d->a2]+"y" );
        write_dummy_atom( pqrout, nxcomp2, (std::string)*top->atoms.atomname[d->a2]+"x" );
        write_dummy_atom( pqrout, pxcomp2, (std::string)*top->atoms.atomname[d->a2]+"x" );
    
        if (d->site_ndx.size() > 0) {
            for (int i=0; i<nsites; i++) {
                std::stringstream key;
                key << "p" << i;
                write_dummy_atom( pqrout, &each_point[i][0], key.str());
            }
        }
    }
    
    /* Initialize all the electrostatics, since they are the result of summing parts */
    int nexclude = d->exclude_ndx.size();
    dat.field_proj_total = 0.0f;
    dat.field_proj_each_exclude = std::vector<double> (nexclude,0.0f);
    dat.field_each_exclude = std::vector<std::vector<double> > (nexclude, std::vector<double> (3,0));
    dat.field_proj_exclude = 0.0f;
    for (int i=0; i<3; i++){
        dat.field_exclude[i] = 0.0f;
        dat.field_mid[i] = 0.0f;
        dat.field_a1[i] = 0.0f;
        dat.field_a2[i] = 0.0f;
    }
    dat.protein_site = std::vector<double> (nsites, 0.0f);
    dat.water_site = std::vector<double> (nsites, 0.0f);
    
    int g = 0;
    int nresidues = top->atoms.atom[sel[g]->g->index[sel[g]->p.nr]].resind;
    std::vector<float> field_per_residue (nresidues,0.0f);
    
    int nwater=0;
    /* Loop through everything */
    for (int g = 0; g < nr; ++g) { // for each group
        if (g > 1) {
            fprintf(stderr,"\nWarning: More than 1 group was specified.  Cowardly ignoring all additional groups\n");
            break;
        }
        for (int i = 0; i < sel[g]->p.nr; ++i) { // for each atom in the group
            int atom_ndx = sel[g]->g->index[i]; // how we get to the atom index
            /* Get .dat parameters and write the atom to the .pqr file */
            int resid = top->atoms.atom[atom_ndx].resind;
            double charge = top->atoms.atom[atom_ndx].q;
            char *atomname = *top->atoms.atomname[atom_ndx];
            char *resname = *top->atoms.resinfo[resid].name;
            double radius = -1;
            int namber = d->amber.size();
            for (int j=0; j<namber; j++) {
                if (d->bVerbose) {
                    fprintf(stderr, "\nTrying to match: %s %s to %s (%d/%d)", resname, *top->atoms.atomtype[atom_ndx], d->amber[j].ambername, j, namber);
                }
                if ( strncmp(*top->atoms.atomtype[atom_ndx], d->amber[j].ambername, strlen(*top->atoms.atomtype[atom_ndx])+1) == 0 ) {
                    radius = d->amber[j].radius;
                    if (d->bVerbose) {
                        fprintf(stderr,"\nMatched %s on %s to %s! (%d/%d)",resname, *top->atoms.atomtype[atom_ndx], d->amber[j].ambername, j, namber);
                    }
                    break;
                }
            }
            if (radius < 0) {
                fprintf(stderr,"\nError: Frame %d, could not match %s %s %s %i\n",d->framen, atomname, resname, *top->atoms.atomtype[atom_ndx],i+1);
                std::exit(1);
            }
            if ( d->dopqr ) {
                fprintf(pqrout,"ATOM %6i %4s %4s %5i %11.3f %7.3f %7.3f %7.4f %7.3f\n",atom_ndx+1,atomname,resname,resid+1,fr->x[atom_ndx][XX]*10,fr->x[atom_ndx][YY]*10,fr->x[atom_ndx][ZZ]*10,charge,radius);
            }
            /* Do the field calculations now */
            bool keepAtom = true;
            std::vector<double> anatom (3,0.0f);
            calculate_field(midpoint, atom_ndx, *top, *fr, &anatom[0], 1);
            for (int j=0; j<nexclude; j++) {
                if (atom_ndx == d->exclude_ndx[j]) {
                    keepAtom = false;
                    break;
                }
            }
            if (keepAtom) {
                field_per_residue[resid] += d->rpdie * project_field(bondvector,&anatom[0]);
            }
            for (int j=0; j<3; j++) {
                dat.field_mid[j] += anatom[j];
            }
            /* Get the field due to each excluded atom */
            keepAtom = true;
            for (int j=0; j<nexclude ; j++) {
                if (atom_ndx == d->exclude_ndx[j]) {
                    calculate_field(midpoint, d->exclude_ndx[j], *top, *fr, &dat.field_each_exclude[j][0], 1);
                    keepAtom = false;
                    break;
                }
            }
            if (keepAtom) {
                calculate_field(midpoint, atom_ndx, *top, *fr, dat.field_exclude, 1);
                calculate_field(fr->x[d->a1], atom_ndx, *top, *fr, dat.field_a1, 1);
                calculate_field(fr->x[d->a2], atom_ndx, *top, *fr, dat.field_a2, 1);
            }
            //d->field_per_residue[resid] += d->rpdie * project_field(
            /* Do the potential calculations now */
            /* We want to exclude atoms at the sites */
            /* We are also going to exclude atoms in the exclude group */
            if ((int)d->site_ndx.size() > 0) {
                if (keepAtom) {
                    for (int j=0; j<(int)d->site_ndx.size(); j++) {
                        if (atom_ndx == d->site_ndx[j] ) {
                            keepAtom = false;
                            break;
                        }
                    }
                }
                if (keepAtom) {
                    if (strncmp("SOL", resname, sizeof(resname)+1) == 0 ||
                        strncmp("HOH", resname, sizeof(resname)+1) == 0 ) {
                        for (int j=0; j<nsites; j++) {
                            double r = calculate_r( &each_point[j][0], atom_ndx, *top, *fr);
                            dat.water_site[j] += calculate_potential( r, atom_ndx, *top, *fr);
                        }
                        nwater++;
                    }
                    else {
                        for (int j=0; j<nsites; j++) {
                            double r = calculate_r( &each_point[j][0], atom_ndx, *top, *fr);
                            dat.protein_site[j] += calculate_potential( r, atom_ndx, *top, *fr);
                        }
                    }
                }
            }
        }
    }
    
    /* Write all output to xvg file */
    if (d->fp) {
        fprintf(d->fp, "%.6e ", d->rpdie * project_field(bondvector, dat.field_mid));
        for (int i=0; i<nexclude; i++) {
            fprintf(d->fp, "%.6e ", d->rpdie * project_field(bondvector, &dat.field_each_exclude[i][0]));
        }
        fprintf(d->fp, "%.6e ", d->rpdie * project_field(bondvector, dat.field_exclude));

        fprintf(d->fp, "%.6e ", d->rpdie * project_field(xvec,dat.field_exclude));
        fprintf(d->fp, "%.6e ", d->rpdie * project_field(yvec,dat.field_exclude));
        fprintf(d->fp, "%.6e ", d->rpdie * project_field(zvec,dat.field_exclude));

        fprintf(d->fp, "%.6e ", d->rpdie * project_field(xvec,dat.field_a1));
        fprintf(d->fp, "%.6e ", d->rpdie * project_field(yvec,dat.field_a1));
        fprintf(d->fp, "%.6e ", d->rpdie * project_field(zvec,dat.field_a1));
        
        fprintf(d->fp, "%.6e ", d->rpdie * project_field(xvec,dat.field_a2));
        fprintf(d->fp, "%.6e ", d->rpdie * project_field(yvec,dat.field_a2));
        fprintf(d->fp, "%.6e ", d->rpdie * project_field(zvec,dat.field_a2));
        
        if ((int)d->site_ndx.size() > 0) {
            for (int i=0; i<nsites; i++) {
                fprintf(d->fp, "%.6e %.6e ", d->rpdie * dat.protein_site[i], d->rpdie * dat.water_site[i]);
            }
        }
        fprintf(d->fp, "\n");
    }

    /* close the pqr file */
    if ( d->dopqr ) {
        fclose(pqrout);
    }
    
    /* Print the current frame number to the xvg file */
    if (d->fpr) {
        fprintf(d->fpr, "%10i ", d->framen);
        for (int i=0;i<nresidues;i++) {
            fprintf(d->fpr,"%12.6e ",field_per_residue[i]);
        }
        fprintf(d->fpr,"\n");
    }

    
    /* increment the frame number */
    d->framen++;
    /* We need to return 0 to tell that everything went OK */
    return 0;
}
예제 #17
0
GraphData * ProcWave2Data(QString fname)
{
    SPTK_SETTINGS * sptk_settings = SettingsDialog::getSPTKsettings();

    QFile file(fname);
    file.open(QIODevice::ReadOnly);
    WaveFile * waveFile = waveOpenHFile(file.handle());
    qDebug() << "waveOpenFile" << LOG_DATA;

    int size = littleEndianBytesToUInt32(waveFile->dataChunk->chunkDataSize);
    qDebug() << "chunkDataSize" << LOG_DATA;
    short int bits = littleEndianBytesToUInt16(waveFile->formatChunk->significantBitsPerSample);
    qDebug() << "significantBitsPerSample" << LOG_DATA;

    vector wave = sptk_v2v(waveFile->dataChunk->waveformData, size, bits);
    qDebug() << "wave" << LOG_DATA;

    vector frame = sptk_frame(wave, sptk_settings->frame);
    qDebug() << "frame" << LOG_DATA;

    vector intensive = vector_intensive(frame, sptk_settings->frame->leng, sptk_settings->frame->shift);
    qDebug() << "intensive" << LOG_DATA;

    vector window = sptk_window(frame, sptk_settings->window);
    qDebug() << "window" << LOG_DATA;

    vector lpc = sptk_lpc(frame, sptk_settings->lpc);
    qDebug() << "lpc" << LOG_DATA;

    vector spec = sptk_spec(lpc, sptk_settings->spec);
    qDebug() << "spec " << maxv(spec) << LOG_DATA;

    vector spec_proc;
    if (sptk_settings->spec->proc == 0){
        spec_proc = vector_pow_log(spec, sptk_settings->spec->factor, sptk_settings->spec->min);
        qDebug() << "spec_log" << LOG_DATA;
    } else if (sptk_settings->spec->proc == 1){
        spec_proc = vector_pow_exp(spec, sptk_settings->spec->factor, sptk_settings->spec->min);
        qDebug() << "spec_exp" << LOG_DATA;
    }
    qDebug() << "spec_proc " << maxv(spec_proc) << LOG_DATA;

    vector pitch = processZeros(sptk_pitch_spec(wave, sptk_settings->pitch, intensive.x));
    qDebug() << "pitch" << LOG_DATA;

    vector mask = getFileMask(waveFile, wave, pitch.x);
    qDebug() << "mask" << LOG_DATA;

    vector pitch_cutted = processZeros(vector_cut_by_mask(pitch, mask));
    qDebug() << "pitch_cutted" << LOG_DATA;
    double pitch_min = getv(pitch_cutted, minv(pitch_cutted));
    double pitch_max = getv(pitch_cutted, maxv(pitch_cutted));

    vector intensive_cutted = vector_cut_by_mask(intensive, mask);
    qDebug() << "intensive_cutted" << LOG_DATA;

    vector inverted_mask = vector_invert_mask(mask);
    qDebug() << "inverted_mask" << LOG_DATA;

    vector pitch_interpolate = vector_interpolate_by_mask(
                pitch_cutted,
                inverted_mask,
                0,
                sptk_settings->plotF0->interpolation_type
                );
    qDebug() << "pitch_interpolate" << LOG_DATA;

    vector intensive_interpolate = vector_interpolate_by_mask(
                intensive_cutted,
                inverted_mask,
                0,
                sptk_settings->plotEnergy->interpolation_type
                );
    qDebug() << "intensive_interpolate" << LOG_DATA;

    vector pitch_mid = vector_smooth_mid(pitch_interpolate, sptk_settings->plotF0->frame);
    qDebug() << "pitch_mid" << LOG_DATA;

    vector intensive_mid = vector_smooth_lin(intensive_interpolate, sptk_settings->plotEnergy->frame);
    qDebug() << "intensive_mid" << LOG_DATA;

    vector norm_wave = normalizev(wave, 0.0, 1.0);

    MaskData md_p = getLabelsFromFile(waveFile, MARK_PRE_NUCLEUS);
    MaskData md_n = getLabelsFromFile(waveFile, MARK_NUCLEUS);
    MaskData md_t = getLabelsFromFile(waveFile, MARK_POST_NUCLEUS);

    vector p_mask = readMaskFromFile(waveFile, wave.x, MARK_PRE_NUCLEUS);
    qDebug() << "p_mask" << LOG_DATA;

    vector n_mask = readMaskFromFile(waveFile, wave.x, MARK_NUCLEUS);
    qDebug() << "n_mask" << LOG_DATA;

    vector t_mask = readMaskFromFile(waveFile, wave.x, MARK_POST_NUCLEUS);
    qDebug() << "t_mask" << LOG_DATA;

    vector p_wave = zero_to_nan(vector_cut_by_mask(norm_wave, p_mask));
    qDebug() << "p_mask" << LOG_DATA;

    vector n_wave = zero_to_nan(vector_cut_by_mask(norm_wave, n_mask));
    qDebug() << "n_mask" << LOG_DATA;

    vector t_wave = zero_to_nan(vector_cut_by_mask(norm_wave, t_mask));
    qDebug() << "t_mask" << LOG_DATA;

    vector pnt_mask = onesv(norm_wave.x);
    for (int i=0; i<p_mask.x && i<n_mask.x && i<t_mask.x && i<norm_wave.x; i++) {
        if (getv(p_mask, i) == 1 || getv(n_mask, i) == 1 || getv(t_mask, i) == 1)
        {
            setv(pnt_mask, i, 0);
        } else {
            setv(pnt_mask, i, 1);
        }
    }

    vector display_wave = zero_to_nan(vector_cut_by_mask(norm_wave, pnt_mask));

    freev(frame);
    freev(window);
    freev(lpc);
    freev(pitch_cutted);
    freev(intensive_cutted);
    freev(inverted_mask);
    freev(pitch_interpolate);
    freev(intensive_interpolate);
    freev(wave);
    qDebug() << "freev" << LOG_DATA;

    file.close();
    waveCloseFile(waveFile);
    qDebug() << "waveCloseFile" << LOG_DATA;

    GraphData * data = new GraphData();

    data->d_full_wave = norm_wave;
    data->d_wave = display_wave;
    data->d_p_wave = p_wave;
    data->d_n_wave = n_wave;
    data->d_t_wave = t_wave;
    data->d_pitch_original = pitch;
    data->d_pitch = pitch_mid;
    data->pitch_max = pitch_max;
    data->pitch_min = pitch_min;
    data->d_intensive_original = intensive;
    data->d_intensive = intensive_mid;
    data->d_spec_proc = spec_proc;
    data->d_spec = spec;
    data->d_mask = mask;
    data->p_mask = p_mask;
    data->n_mask = n_mask;
    data->t_mask = t_mask;
    data->pnt_mask = pnt_mask;

    data->md_p = md_p;
    data->md_t = md_t;
    data->md_n = md_n;

    return data;
}
예제 #18
0
void max_control ()
{
	maxLimit = maxv ( minLimit, maxLimit );
	nSlider = minv ( maxLimit, nSlider );
}
예제 #19
0
파일: game.c 프로젝트: Acknex/Wichtelwald
void startGame()
{
	reset_hints();
	endMenu();
	wait(1);
	level_load("mainLevel.wmb");
//	level_load("menuLevel2.wmb");
//wait(1); // wait until last_error becomes valid
	on_esc = NULL;
	gameCameraInit();
	startIngameGUI();
	playMusicGameDay();
	startSnow();
	
	// Start a new day
	dayOrNight = DAY;
	dayTime = 28800;
	
	hut_restart();
	item_restart();
	show_dayhint();

	set(mtl_model, PASS_SOLID);
	random_seed(8);
	
	VECTOR tempVector;
	int i;
	for(i = 0; i < 100; i++)
	{
		vec_set(tempVector, vector(random(6400)-3200, random(6400)-3200, 0));
		if(vec_length(tempVector) < 800)
		{
			i--;
			continue;
		}
		
		tempVector.z = 5000;
		tempVector.z -= c_trace(tempVector, vector(tempVector.x, tempVector.y, -5000), SCAN_TEXTURE|IGNORE_PASSABLE|IGNORE_FLAG2);
		if(hit.nz < 0.5)
		{
			i--;
			continue;
		}
		
//		ENTITY *tree = ent_create("pine_3.mdl", tempVector, 0);
		ENTITY *tree = ent_create("pine_3_reduced.mdl", tempVector, 0);
		set(tree, PASSABLE|SHADOW);
		vec_scale(tree.scale_x, random(0.5) + 0.5);
		tree.pan = random(360);
		tree->emask &= ~DYNAMIC;
		
	}
	
	random_seed(0);
	pssm_run(4);
wait(1); // f*****g wait(1) seems to fix something which breaks everything

	var sunlightFactor = 0;
	var dayCounter = 0;
	while(isGameOver < 2)
	{
		if (isGameOver == 0)
		{
			updateGui();
			goblin_loop();
			item_spawn_loop();
			
			dayTime += DAY_TIME_SPEED * time_step * 1;
			if(dayTime >= 86400)
			{
				dayTime -= 86400;
				dayCounter += 1;
				
				goblinSpawnDelay = maxv(16.0*3.0-dayCounter*2, 1);
			}
			
			hours = integer(dayTime/60.0/60.0);
			minutes = (integer(dayTime)-hours*60.0*60.0)/60.0;
			
			sunlightFactor = sinv((dayTime-28800.0)/(60.0*60.0*12.0)*180.0);
			
			// Day start
			if(dayTime >= 28800 && dayOrNight == NIGHT && dayTime < 72000)
			{
				dayOrNight = 3;
				fadeWithBlack(startDay);
			}
			
			// Day
			if(sunlightFactor > 0.0)
			{
				sun_light = sunlightFactor*60;
			}
			
			// Night start
			if(dayTime >= 72000 && dayOrNight == DAY)
			{
				dayOrNight = 3;
				fadeWithBlack(startNight);
			}
			
			// Night
			if(sunlightFactor <= 0.0)
			{
				sun_light = -sunlightFactor*30;
			}
			
			sun_angle.pan = (dayTime-28800.0)/(60.0*60.0*12.0)*180.0;
			sun_angle.tilt = abs(ang(asinv(sunlightFactor)))*70.0/180.0+10.0;
			
			d3d_fogcolor1.red = sun_light*255.0/100.0;
			d3d_fogcolor1.green = sun_light*255.0/100.0;
			d3d_fogcolor1.blue = sun_light*255.0/100.0;
		}
		
		/*if (key_l) {
			while(key_l) wait(1);
			shake();
		}*/
		
		
		if (key_esc) {
			while(key_esc) wait(1);
			break;
		}
		wait(1);
	}
	isGameOver = 0;	
	backToMenu();
}
예제 #20
0
void ebHandWatch ()
{
	updateHandChopped(my);
	
	ebDoSparkle(my, 2000);
	snd_play(g_sndSparkle, 100, 0);
	
	set(my, PASSABLE);
	my->ambient = 75;
	
	var moveAnim = 10;
	
	var t = maxv(g_facTimeEbHandWatchMin, g_facTimeEbHandWatch * (5 + random(3))) * 16;
	
	vec_scale(my->scale_x, g_handScale);
	
	var ground, height;
	var heightSub = 32;
	
	g_ebHand = my;
	
	snd_play(g_sndHandFly, 100, 0);
	
	// move with player
	set(player, FLAG2);
	while (t > 0)
	{
		VECTOR vecBoneGround, vecTraceStart, vecTraceEnd;
		vec_for_bone(&vecBoneGround, my, "ground");
		
		vec_set(&vecTraceStart, my->x);
		vecTraceStart.y = vecBoneGround.y;
		
		vec_set(&vecTraceEnd, &vecTraceStart);
		vecTraceEnd.z -= 2000;
		
		height = player->z + 250;
		
		if (c_trace(&vecTraceStart, &vecTraceEnd, IGNORE_ME | USE_POLYGON | IGNORE_FLAG2 ) > 0)
		{
			ground = hit.z;
			height = ground + (my->z - vecBoneGround.z);
		}
		
		VECTOR v;
		vec_set(&v, player->x);
		v.z = height;
		
		vec_lerp(my->x, my->x, &v, 0.25 * time_step);
		
		ent_animate(my, "idleH", 50 + sin(total_ticks * moveAnim) * 50, ANM_CYCLE);
		
		t -= time_step;
		
		doHandChopBlood(my);
		
		wait(1);
	}
	
	g_facTimeEbHandWatch *= g_facTimeEbHandWatchDec;
	
	reset(player, FLAG2);
	
	// drop
	
	g_handDropping = true;
	
	g_ebHand->skill1 = 1; // joints = on
	g_ebHand->skill2 = 1; // joints death = on
	
	g_playerDontScanFlag2 = true;
	g_playerNoYou = true;
	
	ebCreateHandJoints(g_ebHand);
	
	set(player, ZNEAR);
	
	t = 0;
	
	BOOL bSndHandDrop = true;
	while (t < 100)
	{
		VECTOR vecBoneGround;
		vec_for_bone(&vecBoneGround, g_ebHand, "ground");
		height = ground + (g_ebHand->z - vecBoneGround.z) - heightSub;
		
		VECTOR v;
		vec_set(&v, g_ebHand->x);
		v.z = height;
		
		vec_lerp(g_ebHand->x, g_ebHand->x, &v, 0.25 * time_step);
		
		t = clamp(t + 5 * time_step, 0, 100);
		ent_animate(g_ebHand, "drop", t, 0);

		doHandChopBlood(my);
		
		if (t > 90 && bSndHandDrop)
		{
			bSndHandDrop = false;
			snd_play(g_sndHandDrop, 100, 0);
		}
		
		wait(1);
	}
	
	g_handDropping = false;
	
	g_ebHand->skill2 = 0; // joints death = off
	
	t = maxv(g_facTimeEbHandDroppedMin, g_facTimeEbHandDropped * (3+random(2)) * 16);
	
	g_fingerChopped = false;
	
	// wait	
	while (t > 0 && !g_fingerChopped)
	{
		ent_animate(g_ebHand, "down", (total_ticks * 4), ANM_CYCLE);
		t -= time_step;
		
		doHandChopBlood(my);
		
		wait(1);
	}
	
	g_facTimeEbHandDropped *= g_facTimeEbHandDroppedDec;
	
	snd_play(g_sndHandUp, 100, 0);
	
	reset(player, ZNEAR);
	
	g_ebHand->skill1 = 0;
	
	// up
	while (t < 100)
	{
		VECTOR vecBoneGround;
		vec_for_bone(&vecBoneGround, g_ebHand, "ground");
		height = ground + (g_ebHand->z - vecBoneGround.z) - heightSub;
		
		VECTOR v;
		vec_set(&v, g_ebHand->x);
		v.z = height;
		
		vec_lerp(g_ebHand->x, g_ebHand->x, &v, 0.25 * time_step);
		
		t = clamp(t + 2 * time_step, 0, 100);
		ent_animate(g_ebHand, "up", t, 0);		
		
		doHandChopBlood(my);
		
		wait(1);
	}
	
	g_playerDontScanFlag2 = false;
	g_playerNoYou = false;
	
	t = 1.5 * 16;
	
	snd_play(g_sndHandBliss, 100, 0);
	
	// go away
	while (t > 0)
	{
		t -= time_step;
		g_ebHand->z += 10 * time_step;
		g_ebHand->y -= 20 * time_step;
		g_ebHand->roll += 5 * time_step;
		
		doHandChopBlood(my);
		
		wait(1);
	}

	set(g_ebHand, INVISIBLE);
	ebDoSparkle(g_ebHand, 2000);
	snd_play(g_sndSparkle, 100, 0);

	wait(1);
	
	ent_create(NULL, nullvector, ebHandsBgFly);
	ptr_remove(g_ebHand);
}
예제 #21
0
파일: main.cpp 프로젝트: CCJY/coliru
typename std::common_type<FIRST,REST...>::type maxv( FIRST&& first, REST&&... rest )
{ return maxv( first, maxv( std::forward<REST>(rest)... ) ) ; }
예제 #22
0
int     dbsolve(int m, double *y)
{
        int i;
        int k, row, consistent=TRUE;
        double beta, *dwork;
        double eps;

	double starttime, endtime;

	starttime = (double) clock();

	MALLOC( dwork, m, double );

        if (rank < m) eps = EPSSOL * maxv(y,m);
	for (i=0; i<m; i++) dwork[i] = y[i];
	for (i=0; i<m; i++) y[irowperm[i]] = dwork[i];

        /*------------------------------------------------------+
        |               -1                                      |
        |       y  <-  L  y                                    */

        for (i=0; i<rank; i++) {
                beta = y[i];
                for (k=0; k<degL[i]; k++) {
                        row = L[i][k].i;
                        y[row] -= L[i][k].d * beta;
                }
        }

        /*------------------------------------------------------+
	|                                       -1              |
        | Set aside sparse intermediate vector L  P a  for      |
	|                                            j          |
        | refactorization routine.                             */

	if ( newcol == NULL) MALLOC(  newcol, m, double );
	if (inewcol == NULL) MALLOC( inewcol, m, int );

	nnewcol = 0;
	for (i=0; i<m; i++) {
	    if ( ABS(y[i]) > EPS ) {
	        newcol [nnewcol] = y[i];
	        inewcol[nnewcol] = i;
	        nnewcol++;
	    }
	}

        /*------------------------------------------------------+
        |               -1                                      |
        |       y  <-  U  y                                    */

        for (i=m-1; i>=rank; i--) {
                if ( ABS( y[i] ) > eps ) consistent = FALSE;
                y[i] = 0.0;
        }
        for (i=rank-1; i>=0; i--) {
                beta = y[i]/diag[i];
                for (k=0; k<degU[i]; k++) {
			row = U[i][k].i;
                        y[row] -= U[i][k].d * beta;
                }
                y[i] = beta;
        }

	for (i=0; i<m; i++) dwork[i] = y[i];
	for (i=0; i<m; i++) y[colperm[i]] = dwork[i];

	FREE( dwork );

	endtime = (double) clock();
	cumtime += endtime - starttime;

        return consistent;
}
예제 #23
0
SimpleGraphData * SimpleProcWave2Data(QString fname, bool keepWaveData)
{
    qDebug() << "::SimpleProcWave2Data" << LOG_DATA;
    SPTK_SETTINGS * sptk_settings = SettingsDialog::getSPTKsettings();

    SimpleGraphData * data = new SimpleGraphData();
    data->b_pitch = 0;
    data->b_pitch_log = 0;
    data->b_pitch_derivative = 0;
    data->b_intensive = 0;
    data->b_intensive_cutted = 0;
    data->b_intensive_norm = 0;
    data->b_intensive_smooth = 0;
    data->b_derivative_intensive_norm = 0;
    data->b_spec = 0;
    data->b_cepstrum = 0;
    data->b_pitch_norm = 0;

    QFile file(fname);
    qDebug() << "::SimpleProcWave2Data QFile" << fname << LOG_DATA;
    file.open(QIODevice::ReadOnly);
    qDebug() << "::SimpleProcWave2Data file.open " << file.isOpen() << LOG_DATA;
    WaveFile * waveFile = waveOpenHFile(file.handle());
    qDebug() << "::SimpleProcWave2Data waveOpenFile" << LOG_DATA;
    data->file_data = waveFile;

    int size = littleEndianBytesToUInt32(waveFile->dataChunk->chunkDataSize);
    qDebug() << "::SimpleProcWave2Data chunkDataSize " << size << LOG_DATA;
    short int bits = littleEndianBytesToUInt16(waveFile->formatChunk->significantBitsPerSample);
    qDebug() << "::SimpleProcWave2Data significantBitsPerSample " << bits << LOG_DATA;

    double seconds = 1.0 * size / RECORD_FREQ / bits * CHAR_BIT;
    qDebug() << "::SimpleProcWave2Data seconds=" << seconds << LOG_DATA;
    data->seconds = seconds;

    vector wave = sptk_v2v(waveFile->dataChunk->waveformData, size, bits);
    qDebug() << "::SimpleProcWave2Data wave" << LOG_DATA;

    vector norm_wave = normalizev(wave, 0.0, 1.0);
    qDebug() << "::SimpleProcWave2Data norm_wave" << LOG_DATA;
    data->d_full_wave = norm_wave;

    vector frame = sptk_frame(wave, sptk_settings->frame);
    qDebug() << "::SimpleProcWave2Data frame" << LOG_DATA;

    vector intensive = vector_intensive(wave, sptk_settings->frame->leng, sptk_settings->frame->shift);
    qDebug() << "::SimpleProcWave2Data intensive" << LOG_DATA;
    data->d_intensive_original = intensive;

    vector window = sptk_window(frame, sptk_settings->window);
    qDebug() << "::SimpleProcWave2Data window" << LOG_DATA;

    vector lpc = sptk_lpc(frame, sptk_settings->lpc);
    qDebug() << "::SimpleProcWave2Data lpc " << lpc.x << LOG_DATA;

    vector lpc2c = sptk_lpc2c(lpc, sptk_settings->lpc);
    qDebug() << "::SimpleProcWave2Data lpc2c " << lpc2c.x;
    data->d_cepstrum = lpc2c;
    data->b_cepstrum = 1;

    vector spec = sptk_spec(lpc, sptk_settings->spec);
    qDebug() << "::SimpleProcWave2Data spec " << maxv(spec) << LOG_DATA;
    data->d_spec = spec;
    data->b_spec = 1;

    vector spec_proc;
    if (sptk_settings->spec->proc == 0){
        spec_proc = vector_pow_log(spec, sptk_settings->spec->factor, sptk_settings->spec->min);
        qDebug() << "::SimpleProcWave2Data spec_log" << LOG_DATA;
    } else if (sptk_settings->spec->proc == 1){
        spec_proc = vector_pow_exp(spec, sptk_settings->spec->factor, sptk_settings->spec->min);
        qDebug() << "::SimpleProcWave2Data spec_exp" << LOG_DATA;
    }
    qDebug() << "::SimpleProcWave2Data spec_proc " << maxv(spec_proc) << LOG_DATA;
    data->d_spec_proc = spec_proc;

    vector smooth_wave = vector_smooth_lin(wave, sptk_settings->dp->smooth_frame);

    vector pitch = processZeros(sptk_pitch_spec(smooth_wave, sptk_settings->pitch, intensive.x));
    qDebug() << "::SimpleProcWave2Data pitch" << LOG_DATA;
    data->d_pitch_original = pitch;

    int otype = sptk_settings->pitch->OTYPE;
    sptk_settings->pitch->OTYPE = 2;
    vector pitch_log = sptk_pitch_spec(smooth_wave, sptk_settings->pitch, intensive.x);
    sptk_settings->pitch->OTYPE = otype;
    vector pitch_log_norm = normalizev(pitch_log, MASK_MIN, MASK_MAX);
    qDebug() << "::SimpleProcWave2Data pitch_log" << LOG_DATA;
    data->d_pitch_log = pitch_log_norm;
    data->b_pitch_log = 1;

    data->d_intensive = data_get_intensive(data);

    data->d_intensive_norm = data_get_intensive_norm(data);

    vector file_mask;
    WaveFile * procFile = waveFile;
    if (sptk_settings->dp->auto_marking)
    {
        procFile = selectMarkoutAlgorithm(data);
    }
    file_mask = getFileMask(procFile, wave, pitch.x);
    data->md_p = getLabelsFromFile(procFile, MARK_PRE_NUCLEUS);
    data->md_n = getLabelsFromFile(procFile, MARK_NUCLEUS);
    data->md_t = getLabelsFromFile(procFile, MARK_POST_NUCLEUS);
    if (sptk_settings->dp->auto_marking)
    {
        waveCloseFile(procFile);
    }
    qDebug() << "::SimpleProcWave2Data file_mask" << LOG_DATA;

    vector mask_and = vector_mask_and(pitch_log_norm, file_mask);
    vector mask = vector_smooth_mid(mask_and, 10);
    qDebug() << "::SimpleProcWave2Data mask" << LOG_DATA;
    data->d_mask = mask;

    vector inverted_mask = vector_invert_mask(mask);
    qDebug() << "::SimpleProcWave2Data inverted_mask" << LOG_DATA;

    vector pitch_interpolate = vector_interpolate_by_mask(
                pitch,
                inverted_mask,
                0,
                sptk_settings->plotF0->interpolation_type
                );
    qDebug() << "::SimpleProcWave2Data pitch_interpolate" << LOG_DATA;

    vector pitch_mid = vector_smooth_mid(pitch_interpolate, sptk_settings->plotF0->frame);
    qDebug() << "::SimpleProcWave2Data pitch_mid" << LOG_DATA;
    data->d_pitch = pitch_mid;
    data->b_pitch = 1;

    data->d_derivative_intensive_norm = data_get_intensive_derivative(data);

    freev(frame);
    freev(window);
    freev(lpc);
    freev(wave);
    freev(pitch_interpolate);
    freev(inverted_mask);
    freev(smooth_wave);
    freev(pitch_log);
    freev(file_mask);
    freev(mask_and);
    qDebug() << "::SimpleProcWave2Data freev" << LOG_DATA;

    file.close();
    qDebug() << "::SimpleProcWave2Data file.close" << LOG_DATA;

    if (keepWaveData)
    {
        waveFile->file = NULL;
    } else {
        data->file_data = NULL;
        waveCloseFile(waveFile);
        qDebug() << "::SimpleProcWave2Data waveCloseFile" << LOG_DATA;
    }

    return data;
}
예제 #24
0
int NRSOLUTION::subCalculate(PFCalPara para)
{
	if (IsInit == 0 || IsInit != pNet->m_ChangeCode)
	{
		InitPFlow();
	}
	int i, flag;
	MAXITER = para.MaxIter;
	MAXPERR = para.BusPMaxErr;
	MAXQERR = para.BusQMaxErr;
	sprintf(ErrorMessage[0], "    迭代次数  有功误差     无功误差  不收敛节点数");//打印信息
	sprintf(ErrorMessage[1], "      ITER      DPMAX        DQMAX    NoConverge");//打印信息
	cpGetErrorInfo()->PrintWarning(-1, 2);

	//迭代计算
	int tIter, tNConverge;
	for (tIter = 1; tIter <= MAXITER; tIter++)
	{
		flag = 1;
		flag = pNet->BeforeIterCal(tIter);
		if (flag != 1)
		{
			break;
		}

		FormJacobi();

		tNConverge = 0;// !节点电压误差>Tolerance 的节点个数
		double tMaxPerr, tMaxQerr, tPerr, tQerr;
		tMaxPerr = 0.0;
		tMaxQerr = 0.0;
		for (i = 0; i<NRSBusTotal; i++)
		{
			tPerr = fabs(RightP[i]);
			tQerr = fabs(RightQ[i]);
			tMaxPerr = maxv(tMaxPerr, tPerr);
			tMaxQerr = maxv(tMaxQerr, tQerr);
			if (tPerr>MAXPERR || tQerr > MAXQERR)
			{
				tNConverge++;
			}
		}
		sprintf(ErrorMessage[0], "      %3d%13.5f%13.5f%10d", tIter, tMaxPerr, tMaxQerr, tNConverge);//打印信息
		cpGetErrorInfo()->PrintWarning(-1, 1);
		flag = m_Solver->LinearEquationCal(RightP, RightQ);
		if (flag != 1)break;
		int i;
		for (i = 0; i < NRSBusTotal; i++)//Nodal voltage and angle adjustments
		{
			Volt[i] = (1 + RightQ[i])*Volt[i];
			Sita[i] += RightP[i];
		}
		//判断是否收敛
		if (tIter >= para.MinIter && tNConverge == 0)//首先根据各母线分析是否收敛
		{
			UpdatePQ();
			sprintf(ErrorMessage[0], "    =================潮流收敛=================");//打印信息
			cpGetErrorInfo()->PrintWarning(-1, 1);
			return 1;
		}
	}
	sprintf(ErrorMessage[0], "    XXXXXXXXXXXXXXXXX潮流不收敛XXXXXXXXXXXXXXXXX");//打印信息
	cpGetErrorInfo()->PrintWarning(-1, 1);
	return 0;
}
예제 #25
0
// Scale object boundings to [-5,5]
void DXFRenderer::NormalizeEntities()
{
    // calculate current min and max boundings of object
    DXFVector minv(10e20f, 10e20f, 10e20f);
    DXFVector maxv(-10e20f, -10e20f, -10e20f);
    for (DXFEntityList::compatibility_iterator node = m_entities.GetFirst(); node; node = node->GetNext())
    {
        DXFEntity *p = node->GetData();
        if (p->type == DXFEntity::Line)
        {
            DXFLine *line = (DXFLine *)p;
            const DXFVector *v[2] = { &line->v0, &line->v1 };
            for (int i = 0; i < 2; ++i)
            {
                minv.x = mymin(v[i]->x, minv.x);
                minv.y = mymin(v[i]->y, minv.y);
                minv.z = mymin(v[i]->z, minv.z);
                maxv.x = mymax(v[i]->x, maxv.x);
                maxv.y = mymax(v[i]->y, maxv.y);
                maxv.z = mymax(v[i]->z, maxv.z);
            }
        } else if (p->type == DXFEntity::Face)
        {
            DXFFace *face = (DXFFace *)p;
            const DXFVector *v[4] = { &face->v0, &face->v1, &face->v2, &face->v3 };
            for (int i = 0; i < 4; ++i)
            {
                minv.x = mymin(v[i]->x, minv.x);
                minv.y = mymin(v[i]->y, minv.y);
                minv.z = mymin(v[i]->z, minv.z);
                maxv.x = mymax(v[i]->x, maxv.x);
                maxv.y = mymax(v[i]->y, maxv.y);
                maxv.z = mymax(v[i]->z, maxv.z);
            }
       }
    }

    // rescale object down to [-5,5]
    DXFVector span(maxv.x - minv.x, maxv.y - minv.y, maxv.z - minv.z);
    float factor = mymin(mymin(10.0f / span.x, 10.0f / span.y), 10.0f / span.z);
    for (DXFEntityList::compatibility_iterator node2 = m_entities.GetFirst(); node2; node2 = node2->GetNext())
    {
        DXFEntity *p = node2->GetData();
        if (p->type == DXFEntity::Line)
        {
            DXFLine *line = (DXFLine *)p;
            DXFVector *v[2] = { &line->v0, &line->v1 };
            for (int i = 0; i < 2; ++i)
            {
                v[i]->x -= minv.x + span.x/2; v[i]->x *= factor;
                v[i]->y -= minv.y + span.y/2; v[i]->y *= factor;
                v[i]->z -= minv.z + span.z/2; v[i]->z *= factor;
            }
        } else if (p->type == DXFEntity::Face)
        {
            DXFFace *face = (DXFFace *)p;
            DXFVector *v[4] = { &face->v0, &face->v1, &face->v2, &face->v3 };
            for (int i = 0; i < 4; ++i)
            {
                v[i]->x -= minv.x + span.x/2; v[i]->x *= factor;
                v[i]->y -= minv.y + span.y/2; v[i]->y *= factor;
                v[i]->z -= minv.z + span.z/2; v[i]->z *= factor;
            }
       }
    }
}
예제 #26
0
void sc_lights_initSun(SC_SCREEN* screen)
{
	if(sun_color.red == 0 && sun_color.green == 0 && sun_color.blue == 0) return;
	
	//create materials
	screen.materials.sun = mtl_create();
	if(screen.settings.lights.sunShadows == 0) effect_load(screen.materials.sun, sc_lights_sMaterialSun);
	else effect_load(screen.materials.sun, sc_lights_sMaterialSunShadow);
	screen.materials.sun.skin1 = screen.renderTargets.gBuffer[SC_GBUFFER_NORMALS_AND_DEPTH]; //point to gBuffer: normals and depth
	//screen.materials.sun.skin2 = ObjData.light.projMap; //projection map
	//screen.materials.sun.skin3 = ObjData.light.shadowMap; //shadowmap
	screen.materials.sun.skin4 = screen.renderTargets.gBuffer[SC_GBUFFER_MATERIAL_DATA]; //point to gBuffer: brdf data
	screen.materials.sun.SC_SKILL = screen;
	set(screen.materials.sun, ENABLE_VIEW);
	screen.materials.sun.event = sc_lights_MaterialEventSun;
	
	//setup views
	screen.views.sun = view_create(-997);
	set(screen.views.sun, PROCESS_TARGET);
	set(screen.views.sun, UNTOUCHABLE);
	set(screen.views.sun, NOSHADOW);
	reset(screen.views.sun, AUDIBLE);
	set(screen.views.sun, NOPARTICLE);
	set(screen.views.sun, NOSKY);
	set(screen.views.sun, CHILD);
	set(screen.views.sun, NOFLAG1);
	screen.views.sun.size_x = screen.views.main.size_x;
	screen.views.sun.size_y = screen.views.main.size_y;
	screen.views.sun.material = screen.materials.sun;
	screen.views.sun.bmap = screen.renderTargets.full0;
	
	
	#ifndef SC_A7
		//PSSM SHADOWS
		if(screen.settings.lights.sunShadows == 1)
		{
			sun_angle.roll = 1.1*maxv(vec_length(level_ent->max_x),vec_length(level_ent->min_x));
			//screen.renderTargets.sunShadowDepth = bmap_createblack(screen.settings.lights.sunShadowResolution, screen.settings.lights.sunShadowResolution, 12222);
			//screen.materials.sun.skin3 = screen.renderTargets.sunShadowDepth;
			
			int i = 0;
			for(i=0; i<screen.settings.lights.sunPssmSplits; i++)
			{	
				
				screen.views.sunShadowDepth[i] = view_create(-800);
				
				#ifndef SC_A7
					screen.views.sunShadowDepth[i].bg = pixel_for_vec(COLOR_WHITE,0,8888);
				#endif
				screen.views.sunShadowDepth[i].lod = shadow_lod;
				
				/*
				//set shadowview flags
				set(screen.views.sunShadowDepth[i], SHOW);
				reset(screen.views.sunShadowDepth[i], AUDIBLE);
				set(screen.views.sunShadowDepth[i], UNTOUCHABLE);
				set(screen.views.sunShadowDepth[i], NOSHADOW);
				set(screen.views.sunShadowDepth[i], SHADOW);
				set(screen.views.sunShadowDepth[i], NOPARTICLE);
				set(screen.views.sunShadowDepth[i], ISOMETRIC);
				//set(screen.views.sunShadowDepth[i], CULL_CW);
				#ifdef SC_USE_NOFLAG1
					set(screen.views.sunShadowDepth[i], NOFLAG1);
				#endif
				*/
				screen.views.sunShadowDepth[i]->flags |= SHOW|UNTOUCHABLE|NOSHADOW|NOPARTICLE|NOLOD|NOSKY|ISOMETRIC|SHADOW|NOFLAG1;
				
				
				//create rendertarget
				screen.renderTargets.sunShadowDepth[i] = bmap_createblack(screen.settings.lights.sunShadowResolution, screen.settings.lights.sunShadowResolution, 14);
				
				/*
				//BLUR SHADOWMAP (ESM SHADOWS ONLY)
				if(i < screen.settings.lights.sunPssmBlurSplits)
				{
					//assign rendertarget
					//screen.views.sunShadowDepth[i].bmap = screen.renderTargets.sunShadowDepth[i];
					screen.views.sunShadowDepth[i].bmap = bmap_createblack(screen.settings.lights.sunShadowResolution, screen.settings.lights.sunShadowResolution, 14);
					
					//blur light depthmap
					VIEW* blurView = view_create(-799);
					blurView.size_x = screen.settings.lights.sunShadowResolution;
					blurView.size_y = screen.settings.lights.sunShadowResolution;
					set(blurView, CHILD);
					set(blurView, PROCESS_TARGET);
					screen.views.sunShadowDepth[i].stage = blurView;
					blurView.bmap = screen.renderTargets.sunShadowDepth[i];
					blurView.material = mtl_create();
					effect_load(blurView.material, sc_lights_sMaterialShadowmapBlur);
					//blurView.material.skill1 = floatv((float)(2.25-i)/(float)screen.settings.lights.sunShadowResolution);
					if(i==0) blurView.material.skill1 = floatv((float)(1.5)/(float)screen.settings.lights.sunShadowResolution);
					if(i==1) blurView.material.skill1 = floatv((float)(0.75)/(float)screen.settings.lights.sunShadowResolution);
					if(i==2) blurView.material.skill1 = floatv((float)(0.25)/(float)screen.settings.lights.sunShadowResolution);
					if(i==3) blurView.material.skill1 = floatv((float)(0.125)/(float)screen.settings.lights.sunShadowResolution);
					//
				}
				else
				{
					screen.views.sunShadowDepth[i].bmap = screen.renderTargets.sunShadowDepth[i];
				}
				*/
				screen.views.sunShadowDepth[i].bmap = screen.renderTargets.sunShadowDepth[i];
				
				//create material
				screen.views.sunShadowDepth[i].material = mtl_create();
				
				switch(i){
					case 0:
					effect_load(screen.views.sunShadowDepth[i].material,sc_lights_sMaterialShadowmapSplit1);
					break;
					case 1:
					effect_load(screen.views.sunShadowDepth[i].material,sc_lights_sMaterialShadowmapSplit2);
					break;
					case 2:
					effect_load(screen.views.sunShadowDepth[i].material,sc_lights_sMaterialShadowmapSplit3);
					break;
					case 3:
					effect_load(screen.views.sunShadowDepth[i].material,sc_lights_sMaterialShadowmapSplit4);
					break;
					default:
					break;
				}
				
				//pass number of splits to sun shader
				screen.materials.sun.skill13 = floatv(screen.settings.lights.sunPssmSplits);
				
			}
			
			if(sc_materials_zbuffer!=NULL){ bmap_purge(sc_materials_zbuffer); ptr_remove(sc_materials_zbuffer); sc_materials_zbuffer=NULL; }
			sc_materials_zbuffer=bmap_createblack(maxv(screen_size.x,screen.settings.lights.sunShadowResolution),maxv(screen_size.y,screen.settings.lights.sunShadowResolution),32);
			bmap_zbuffer(sc_materials_zbuffer);
			
			
			
			
			
			
			//add shadow edge masking + expanding to accelerate pcf shadows
			//setup views
			screen.views.sunEdge = view_create(-997);
			set(screen.views.sunEdge, PROCESS_TARGET);
			set(screen.views.sunEdge, UNTOUCHABLE);
			set(screen.views.sunEdge, NOSHADOW);
			reset(screen.views.sunEdge, AUDIBLE);
			set(screen.views.sunEdge, NOPARTICLE);
			set(screen.views.sunEdge, NOSKY);
			set(screen.views.sunEdge, CHILD|NOFLAG1);
			screen.views.sunEdge.size_x = screen.views.main.size_x/4;
			screen.views.sunEdge.size_y = screen.views.main.size_y/4;
			screen.views.sunEdge.bmap = screen.renderTargets.quarter0;//bmap_createblack(screen.views.main.size_x/4, screen.views.main.size_y/4, 32);//screen.renderTargets.quarter0;
			screen.views.sunEdge.material = mtl_create();
			effect_load(screen.views.sunEdge.material, sc_lights_sMaterialSunShadowEdge);
			screen.views.sunEdge.material.skin1 = screen.renderTargets.gBuffer[SC_GBUFFER_NORMALS_AND_DEPTH];
			
			screen.views.sunEdge.material.skill8 = floatv(screen.views.main.clip_far);
			screen.views.sunEdge.material.skill13 = floatv(screen.settings.lights.sunPssmSplits);
			LPD3DXEFFECT fx = screen.views.sunEdge->material->d3deffect;
			if(fx) {
				fx->SetInt("shadowmapSize", (screen.settings.lights.sunShadowResolution) );
				fx->SetFloat("shadowBias", (screen.settings.lights.sunShadowBias) );
			}
			set(screen.views.sunEdge.material, ENABLE_VIEW);
			screen.views.sunEdge.material.event = sc_lights_MaterialEventSun;
			
			
			//expander
			screen.views.sunExpand = view_create(-997);
			set(screen.views.sunExpand, PROCESS_TARGET);
			set(screen.views.sunExpand, UNTOUCHABLE);
			set(screen.views.sunExpand, NOSHADOW);
			reset(screen.views.sunExpand, AUDIBLE);
			set(screen.views.sunExpand, NOPARTICLE);
			set(screen.views.sunExpand, NOSKY);
			set(screen.views.sunExpand, CHILD|NOFLAG1);
			screen.views.sunExpand.size_x = screen.views.main.size_x/8;
			screen.views.sunExpand.size_y = screen.views.main.size_y/8;
			screen.views.sunExpand.bmap = screen.renderTargets.eighth0;//bmap_createblack(screen.views.main.size_x/8, screen.views.main.size_y/8, 32);//screen.renderTargets.quarter0;
			screen.views.sunExpand.material = mtl_create();
			effect_load(screen.views.sunExpand.material, sc_lights_sMaterialSunShadowExpand);
			screen.views.sunExpand.material.skin1 = screen.renderTargets.quarter0;
			set(screen.views.sunExpand.material, ENABLE_VIEW);
			screen.views.sunExpand.material.event = sc_lights_MaterialEventSun;
			
			//shadow
			screen.views.sunShadow = view_create(-997);
			set(screen.views.sunShadow, PROCESS_TARGET);
			set(screen.views.sunShadow, UNTOUCHABLE);
			set(screen.views.sunShadow, NOSHADOW);
			reset(screen.views.sunShadow, AUDIBLE);
			set(screen.views.sunShadow, NOPARTICLE);
			set(screen.views.sunShadow, NOSKY);
			set(screen.views.sunShadow, CHILD|NOFLAG1);
			screen.views.sunShadow.size_x = screen.views.main.size_x;
			screen.views.sunShadow.size_y = screen.views.main.size_y;
			screen.views.sunShadow.bmap = screen.renderTargets.full1;//bmap_createblack(screen.views.main.size_x/4, screen.views.main.size_y/4, 32);//screen.renderTargets.quarter0;
			screen.views.sunShadow.material = mtl_create();
			effect_load(screen.views.sunShadow.material, sc_lights_sMaterialSunShadowCreate);
			screen.views.sunShadow.material.skin1 = screen.renderTargets.gBuffer[SC_GBUFFER_NORMALS_AND_DEPTH];
			screen.views.sunShadow.material.skin2 = screen.renderTargets.eighth0;
			
			screen.views.sunShadow.material.skill4 = floatv(screen.views.sunShadowDepth[0].clip_far);
			screen.views.sunShadow.material.skill8 = floatv(screen.views.main.clip_far);
			screen.views.sunShadow.material.skill13 = floatv(screen.settings.lights.sunPssmSplits);
			LPD3DXEFFECT fx = screen.views.sunShadow->material->d3deffect;
			if(fx) {
				fx->SetInt("shadowmapSize", (screen.settings.lights.sunShadowResolution) );
				fx->SetFloat("shadowBias", (screen.settings.lights.sunShadowBias) );
			}
			set(screen.views.sunShadow.material, ENABLE_VIEW);
			screen.views.sunShadow.material.event = sc_lights_MaterialEventSun;
			
			//set stages
			screen.views.sunEdge.stage = screen.views.sunExpand;
			screen.views.sunExpand.stage = screen.views.sunShadow;	
			screen.views.sunShadow.stage = screen.views.sun;
			
		}
	#endif
	//------------
	
	
	
	
	//apply sun to camera
	VIEW* view_last;
	view_last = screen.views.gBuffer;
	while(view_last.stage != NULL)
	{
		view_last = view_last.stage;
	}
	
	#ifndef SC_A7 //PSSM SHADOWS are supported
		if(screen.settings.lights.sunShadows == 1)
		{
			view_last.stage = screen.views.sunEdge;
		}
		else
		{
			view_last.stage = screen.views.sun;
		}
		#else
		view_last.stage = screen.views.sun;
	#endif
	
}
예제 #27
0
void test3(){
  SimplePrng p;
  int i;
  Int v;
  double d1;
  double *ptr1, *ptr2;
  int inrange = 0;
  Int range1(5000);
  Int range2(9000);
  Int maxv(-1);
  int res1, res2;
  Int tmpint;

  for (int j=1; j < TEST3_NOPS; ++j){
    // insert elements
    for (i = 0; i < TEST3_NINSERT; ++i){
      v = Int(p.next() % TEST3_RANGE);
      if (maxv.val < v.val) maxv = v;
      if (range1.val <= v.val && v.val <= range2.val)
        ++inrange; // count number to be deleted
      test3_sl.insert(v, (double)v.val);
      //test3_sl.insert(&v, new double(v));
    }

    // copy skiplist
    SkipList<Int,double> sl2(test3_sl);

    Int todel;
    int n1, n2;
    // delete elements
    for (i = 0; i < TEST3_NDELETE; ++i){
      todel = Int(p.next() % TEST3_RANGE);
      n1 = 0;
      while (!test3_sl.lookupRemove(todel,0, d1)){
        assert((int)d1 == todel.val);
        ++n1;
      }
      n2 = sl2.delRange(todel, 1, todel, 1, 0, 0);
      assert(n1 == n2);
    }

    // check elements
    for (i=0; i < TEST3_RANGE; ++i){
      tmpint.val = i;
      res1 = test3_sl.lookup(tmpint, ptr1);
      res2 = sl2.lookup(tmpint, ptr2);
      assert (res1==res2);
      if (res1==0) assert(*ptr1==*ptr2);
    }
    SkipListNode<Int,double> *it1, *it2;
    it1 = test3_sl.getFirst();
    it2 = sl2.getFirst();
    while (it1 != test3_sl.getLast()){
      assert(it2 != test3_sl.getLast());
      assert(it1->key.val == it2->key.val);
      assert(it1->value == it2->value);
      it1 = test3_sl.getNext(it1);
      it2 = test3_sl.getNext(it2);
    }
    assert(it2 == sl2.getLast());

    // clear lists
    test3_sl.clear(0, 0);
    sl2.clear(0, 0);
  }
}
예제 #28
0
int     bsolve(
	int m, 
	double *sy,
	int *iy,
	int *pny
)
{
        int i, j, jr, ny=*pny;
        int k, row, row2, consistent=TRUE;
        double beta;
        double eps;

	static double *y=NULL, *yy=NULL;
	static int    *tag=NULL;
	static int  currtag=1;

	double starttime, endtime;

	starttime = (double) clock();

	if (   y  == NULL) CALLOC(   y, m,   double);
	if (  yy  == NULL) CALLOC(  yy, m,   double);
	if ( tag  == NULL) CALLOC( tag, m,   int);

	if ( newcol == NULL) MALLOC(  newcol, m, double );
	if (inewcol == NULL) MALLOC( inewcol, m, int );

	for (k=0; k<ny; k++) {
	    i = irowperm[iy[k]];
	    y[i] = sy[k];
	    tag[i] = currtag;
	    addtree(i);
	}

        if (rank < m) eps = EPSSOL * maxv(sy,ny);

        /*------------------------------------------------------+
        |               -1                                      |
        |       y  <-  L  y                                    */

        for (i=getfirst(); i < rank && i != -1; i=getnext()) {
                beta = y[i];
                for (k=0; k<degL[i]; k++) {
                        row = L[i][k].i;
			if (tag[row] != currtag) {
			    y[row] = 0.0;
			    tag[row] = currtag;
			    addtree(row);
			}
                        y[row] -= L[i][k].d * beta;
                }
        }

        /*------------------------------------------------------+
        | Apply refactorization row operations.                */

	for (jr=0; jr<nr; jr++) {

            /*--------------------------------------------------+
            | Gather sparse vector.                            */

	    k=0;
            for (j=col_outs[jr]; j<=imaxs[jr]; j++) {
		if (tag[j] == currtag) {
		    sy[k] = y[j];
		    iy[k] =   j;
		    k++;
		    tag[j]--;
		    deltree(j); 
		}
	    }
	    ny = k;

            /*--------------------------------------------------+
            | Scatter and permute.                             */

	    for (k=0; k<ny; k++) {
		i = iperm[jr][iy[k]];
		y[i] = sy[k];
		tag[i] = currtag;
		addtree(i);
	    }

            /*--------------------------------------------------+
            | Apply row operations.                            */

	    row = rows[jr];
	    for (k=0; k<ngauss[jr]; k++) {
		row2 = row_list[jr][k];
		if (tag[row] != currtag) {
		    y[row] = 0.0;
		    tag[row] = currtag;
		    addtree(row);
		}
		if (tag[row2] == currtag) {
		    y[row] -= gauss[jr][k] * y[row2];
		}
	    }

	}

        /*------------------------------------------------------+
	|                                       -1              |
        | Set aside sparse intermediate vector L  P a  for      |
	|                                            j          |
        | refactorization routine.                             */

	nnewcol = 0;
	for (i=getfirst(); i != -1; i=getnext()) {
	    if ( ABS(y[i]) > EPS ) {
	        newcol [nnewcol] = y[i];
	        inewcol[nnewcol] = i;
	        nnewcol++;
	    }
	}

        /*------------------------------------------------------+
        |               -1                                      |
        |       y  <-  U  y                                    */

        for (i=getlast(); i >= rank && i != -1; i=getprev()) {
                if ( ABS( y[i] ) > eps ) consistent = FALSE;
                y[i] = 0.0;
        }
        for ( ; i>=0; i=getprev()) {
                beta = y[i]/diag[i];
                for (k=0; k<degU[i]; k++) {
			row = U[i][k].i;
			if (tag[row] != currtag) {
			    y[row] = 0.0;
			    tag[row] = currtag;
			    addtree(row);
			}
			y[row] -= U[i][k].d * beta;
                }
                y[i] = beta;
        }

	ny = 0;
	for (i=getfirst(); i != -1; i=getnext()) {
	    if ( ABS(y[i]) > EPS ) {
	        sy[ny] = y[i];
	        iy[ny] = colperm[i];
	        ny++;
	    }
	}
	*pny = ny;

	currtag++;
	killtree();

	endtime = (double) clock();
	cumtime += endtime - starttime;

        return consistent;
}