예제 #1
0
파일: calcpos.c 프로젝트: jarmoruuth/tools
/**********************************************************************
 *
 *	set_pos
 *
 * Sets nullable, firstpos and lastpos in whole tree.
 */
static bool set_pos(void)
{
	REG1 int	i;
	REG2 node_t*	tnode = rbuf.tree;
	
	for (i = 0; i <= rbuf.root; i++, tnode++) {
		nullable(tnode);
		if ((tnode->firstpos = calloc(rbuf.setsize, 1)) == NULL)
			return FALSE;
		firstpos(i, tnode);
		if ((tnode->lastpos = calloc(rbuf.setsize, 1)) == NULL)
			return FALSE;
		lastpos(i, tnode);
	}
	return TRUE;
}
예제 #2
0
  void
  OPStructureImaging::printImage()
  {
    for (const shared_ptr<IDRange>& prange : Sim->topology[id]->getMolecules())
      {
	std::vector<Vector  > atomDescription;

	Vector  lastpos(Sim->particles[*prange->begin()].getPosition());
      
	Vector  masspos(0,0,0);

	double sysMass(0.0);

	Vector  sumrij(0,0,0);
      
	for (const size_t& pid : *prange)
	  {
	    //This is all to make sure we walk along the structure
	    const Particle& part(Sim->particles[pid]);
	    Vector  rij = part.getPosition() - lastpos;
	    lastpos = part.getPosition();
	    Sim->BCs->applyBC(rij);
	  
	    sumrij += rij;
	  
	    double pmass = Sim->species(part)->getMass(pid);
	    sysMass += pmass;
	    masspos += sumrij * pmass;
	  
	    atomDescription.push_back(sumrij);
	  }
      
	masspos /= sysMass;

	for (Vector & rijpos : atomDescription)
	  rijpos -= masspos;

	//We use a trick to not copy the vector, just swap it over
	imagelist.push_back(std::vector<Vector  >());
	std::swap(imagelist.back(), atomDescription);
      }
  }
예제 #3
0
파일: test_tools.c 프로젝트: sdague/miau
int
main(
    )
{
	/* upcase() && lowcase() */
	{
	char foo[64];
	
	sprintf(foo, "foobar");
	printf("Before case-conversion: '%s'\n", foo);
	upcase(foo);
	printf("After upcase: '%s'\n", foo);
	lowcase(foo);
	printf("After lowcase: '%s'\n", foo);

	sprintf(foo, "unicode öä ¹²³");
	printf("Before case-conversion: '%s'\n", foo);
	upcase(foo);
	printf("After upcase: '%s'\n", foo);
	lowcase(foo);
	printf("After lowcase: '%s'\n", foo);
	}

	/* randname() */
	{
	char foo[64];
	int i, j;

#define LEN	8
	for (i = 0; i < 2; i++) {
		switch (i) {
			case 0:
				sprintf(foo, "user");
				break;
			case 1:
				sprintf(foo, "username");
				break;
		}
		printf("randname: starting with '%s' (len = %d)\n", foo, LEN);
		for (j = 0; j < LEN * 2; j++) {
			randname(foo, LEN, '#');
			printf("round %02d: '%s'\n", j, foo);
		}
	}
	printf("Generating random stuff:\n");
	for (i = 0; i < 4; i++) {
		foo[0] = '\0';
		randname(foo, LEN, '#');
		printf("round %d: '%s'\n", i, foo);
	}
	}

	/* pos() && lastpos() */
	{
	char foo[64];
	
	sprintf(foo, "There is no greater power in the universe than "
			"the need for freedom.");
	printf("String: '%s'\n", foo);
	printf("First occurance of 'o' is at %d\n", pos(foo, 'o'));
	printf("Last occurance of 'o' is at %d\n", lastpos(foo, 'o'));
	}
	
	/* nextword() && lastword() */
	{
	char foo[64];
	char *ptr;

	sprintf(foo, "There is no greater power in the universe than "
			"the need for freedom.");
	printf("Words (after the first one):\n");
	ptr = nextword(foo);
	while (ptr != NULL) {
		printf("'%s'\n", ptr);
		ptr = nextword(ptr);
	}
	printf("Last word: '%s'\n", lastword(foo));
	}

	/* get_short_localtime() && get_timestamp() */
	{
	time_t t;
	t = rand();
	printf("Some timestamps:\n");
	printf("Localtime: '%s'\n", get_short_localtime());
	printf("Long: '%s'\n", get_timestamp(NULL, TIMESTAMP_LONG));
	printf("Short: '%s'\n", get_timestamp(NULL, TIMESTAMP_SHORT));
	printf("Abritary: '%s'\n", get_timestamp(&t, TIMESTAMP_LONG));
	}
	

	return 0;
}