Exemple #1
0
/*********************************************************************
*名    称:Writecmd()
*功    能:写指令到LCD1602,指令数据占一个字节
*入口参数:cmd:待写入的指令
*出口参数:无
*********************************************************************/
void LCD1602::wcmd(uint8_t cmd)
{                          
	while(bz())
	{
		;
	}

	d7->mode(OUTPUT_PP);
	rs->reset();
	rw->reset();
	en->reset();
	
	d0->write(cmd&0x01);
	d1->write(cmd&0x02);
	d2->write(cmd&0x04);
	d3->write(cmd&0x08);
	d4->write(cmd&0x10);
	d5->write(cmd&0x20);
	d6->write(cmd&0x40);
	d7->write(cmd&0x80);
//如果硬件连接时顺序的建议使用以下方式
//	DATAOUT &= 0XFF00;
//	DATAOUT |= cmd;


	lcd_delay(delay_times);
	en->set();
	lcd_delay(delay_times);
	en->reset();
	lcd_delay(delay_times);
}	
Exemple #2
0
void ShapeMaker::cubicToRec( const Point& a, const Point& b, const Point& c, const Point& d, double k, int iteration ) {
	Point s = intersectLines( a, b, c, d );
	double dx = (a.x+d.x+s.x*4-(b.x+c.x)*3)*.125;
	double dy = (a.y+d.y+s.y*4-(b.y+c.y)*3)*.125;
	Bezier bz( a, b, c, d );
	Bezier b0, b1;
	if( dx*dx + dy*dy > k && iteration<10 ) {
//		fprintf(stderr,"[%03i] split: %f\n", iteration, dx*dx + dy*dy);
		bezierSplit( bz, &b0, &b1 );
		// recurse
		iteration++;
		cubicToRec( a,    b0.p1, b0.p2, b0.p3, k, iteration );
		//lineTo( b0.p3.x, b0.p3.y );
		
		cubicToRec( b1.p0, b1.p1, b1.p2, d,    k, iteration );
		//lineTo( b1.p1.x, b1.p1.y );
		//lineTo( b1.p2.x, b1.p2.y );
		//lineTo( d.x, d.y );
	} else {
//		fprintf(stderr,"#### %i %i %i %i\n", (int)s.x, (int)s.y, (int)d.x, (int)d.y );
		//lineTo( (int)s.x, (int)s.y );
		//lineTo( (int)d.x, (int)d.y );
		curveTo( s.x, s.y, d.x, d.y );
	}
}
Exemple #3
0
static void bnz()
{
	  if(ZF==0)
	  {
		    ZF=1;
		    bz();
		    ZF=0;
	  }
}
Exemple #4
0
int
mongodb_insert_key(bot_t * bot, char *db, char *key, char *value,
		   char *fmt, ...)
{
	bson b;
	mongo_cursor cursor;
	va_list ap;
	char buf[1024], *buf_ptr = "NULL";

	if (!db || !key || !value) {
		return -1;
	}

	debug(bot, "mongodb_insert_key: Entered\n");

	if (fmt) {
		bz(buf);
		va_start(ap, fmt);
		vsnprintf_buf(buf, fmt, ap);
		va_end(ap);
		buf_ptr = buf;
	}

	bson_init(&b);
	bson_append_string(&b, "key", key);
	bson_finish(&b);
	mongo_cursor_init(&cursor, &gi->mongo_conn, db);
	mongo_cursor_set_query(&cursor, &b);

	if (mongo_cursor_next(&cursor) == MONGO_OK) {
		debug(bot, "mongodb_insert_key: Key already exist\n");
		bson_destroy(&b);
		mongo_cursor_destroy(&cursor);
		return -1;
	}

	bson_init(&b);
	bson_append_string(&b, "key", key);
	bson_append_string(&b, "value", value);
	bson_append_string(&b, "comment", buf_ptr);

	bson_finish(&b);

	mongo_insert(&gi->mongo_conn, db, &b);

	bson_destroy(&b);
	mongo_cursor_destroy(&cursor);

	return 0;
}
Exemple #5
0
int bot_unix_fini(void)
{

	bz(global_info.fd_unix_path);

	safe_event_del(&global_info.ev_unix);

	if (global_info.fd_unix)
		safe_close(global_info.fd_unix);

	global_info.fd_unix = 0;

	bz2(global_info.ev_unix);

	return 0;
}
Exemple #6
0
char *shake1_get_sym(FILE * fp, off_t * offsets, int num)
{
	off_t off;
	static char buf[1024];

	if (!fp || !offsets || num < 0)
		return NULL;

	bz(buf);

	off = offsets[num];

	fseek(fp, off, SEEK_SET);
	fgets(buf, sizeof(buf) - 1, fp);
	_strstrip_nl(buf);
	charcat_safe(buf, ' ', sizeof(buf) - 1);

	return buf;
}
Exemple #7
0
void test_bz_should_return_1(void){
	int error;	
	
	Instruction inst = { .mnemonic = BZ, .name = "bz" };
	Bytecode code = {.instruction = &inst, .operand1 = 0xf12, .operand2 = -1, .operand3 = -1, .absoluteAddress = 0};
	
	FSR[code.operand1] = 1;
	
	bz(&code);
	TEST_ASSERT_EQUAL(1, bz(&code));
}

void test_bz_should_return_operand1(void){
	int error;	
	
	Instruction inst = { .mnemonic = BZ, .name = "bz" };
	Bytecode code = {.instruction = &inst, .operand1 = 0xf12, .operand2 = -1, .operand3 = -1, .absoluteAddress = 0};
	
	FSR[code.operand1] = 0;
	
	Try{
		bz(&code);
	}Catch(error){
		TEST_ASSERT_EQUAL(1, ERR_INVALID_OPERAND);
	}

	TEST_ASSERT_EQUAL(code.operand1, bz(&code));
}

void test_bz_should_throw_exception(void){
	int error;	
	
	Instruction inst = { .mnemonic = BZ, .name = "bz" };
	Bytecode code = {.instruction = &inst, .operand1 = -1, .operand2 = -1, .operand3 = -1, .absoluteAddress = 0};
	
	FSR[code.operand1] = 0;
	
	Try{
		bz(&code);
	}Catch(error){
		TEST_ASSERT_EQUAL(1, ERR_INVALID_OPERAND);
	}
	
	Try{
		bz(&code);
	}Catch(error){
		TEST_ASSERT_EQUAL(1, ERR_INVALID_OPERAND);
	}
	
}
Exemple #8
0
void Bazmek::nahodne() {
  if (rand() % 2) {
    druh = CIVKA;
    hodnota = float(rand() % 200 + 1) * float(rand() % 200 + 1) * 1000;
  } else {
    druh = KONDENZATOR;
    hodnota = float(rand() % 200 + 1) * float(rand() % 200 + 1) / 1000;
  }

  zapojeni = (Zapojeni)(rand() % 2);
  umisteni = (Zapojeni)(rand() % 2);
  b.clear();

  if (rand() % 6 > 4) {
    Bazmek bz(hodnota, druh, umisteni);
    bz.zapojeni = zapojeni;
    b.push_back(bz);
    while (rand() % 3) {
      bz.nahodne();
      b.push_back(bz);
    }
  }
}
Exemple #9
0
char *bit_vec_to_str(bit_vector_t * bv)
{
	int i, j, bit;
	char *str = NULL, buf[MAX_BUF_SZ + 1];
	unsigned char byte;

	if (!bv)
		return NULL;

	bz(buf);

	for (i = 0; i < bv->sz; i++) {
		byte = bv->vec[i];
		for (j = 0; j < 8; j++) {
			bit = bit_extract_bit_char(byte, j);
			strlcatfmt_buf(buf, "%i", bit);
		}
	}

	if (_sNULL(buf) != NULL)
		str = strdup(buf);

	return str;
}
Exemple #10
0
int bot_unix_fd_send(bot_t * bot, int fd, bot_gmod_elm_t * gmod)
{
	char tag[132];
	char cmsg_buf[sizeof(struct cmsghdr) + sizeof(long)];
	struct sockaddr_un un;
	struct cmsghdr *cmsg;
	struct msghdr msg;
	struct iovec iov[2];
	int sock;

	int op;

	if (!bot)
		return -1;

	debug(NULL, "bot_unix_fd_send: Entered: %s\n", gi->fd_unix_path);

	if (!_sNULL(global_info.fd_unix_path) || fd < 0)
		return -1;

	bz2(un);
	strlcpy_buf(un.sun_path, global_info.fd_unix_path);

	un.sun_family = AF_UNIX;

	sock = socket(AF_UNIX, SOCK_STREAM, 0);
	if (sock < 0) {
		perror("socket ");
		return -1;
	}

	if (connect(sock, (struct sockaddr *)&un, sizeof(un)) < 0) {
		perror("connect ");
		goto cleanup;
	}

	op = BOT_UNIX_OP_FDPASS;
	iov[0].iov_len = sizeof(int);
	iov[0].iov_base = &op;

	bz(tag);
	snprintf_buf(tag, "%s,%i", bot->tag, bot->ID);

	if (gmod) {
		if (_sNULL(gmod->trigger_ext)) {
			strlcatfmt_buf(tag, ",%s", gmod->trigger_ext);
		}
	}

	iov[1].iov_len = sizeof(tag);
	iov[1].iov_base = tag;

	msg.msg_name = 0;
	msg.msg_namelen = 0;
	msg.msg_control = cmsg_buf;
	msg.msg_controllen = sizeof cmsg_buf;
	msg.msg_iov = (struct iovec *)&iov;
	msg.msg_iovlen = 2;
	msg.msg_flags = 0;

	cmsg = (struct cmsghdr *)cmsg_buf;
	cmsg->cmsg_level = SOL_SOCKET;
	cmsg->cmsg_type = SCM_RIGHTS;
	msg.msg_controllen = cmsg->cmsg_len =
	    sizeof(struct cmsghdr) + sizeof(long);
	*(int *)((void *)cmsg + sizeof(struct cmsghdr)) = fd;

	sleep(1);

	if (sendmsg(sock, &msg, 0) < 0) {
		perror("sendmsg ");
		goto cleanup;
	}

	safe_close(sock);
	return 0;

 cleanup:
	if (sock)
		safe_close(sock);

	return -1;
}
Exemple #11
0
unsigned long msequenceServer::next_pro(const bool _f)
{
/*
 * exit on completion	
 */
	if(done())
		return 0;
/*
 * start the reading process, if it hasn't been started	
 */
	if(!started())	{
		if(!start())	{
			m_bDone = true;
			m_bError = true;
			m_strStatus += "Server would not start.\r\n";
			return 0;
		}
	}
/*
 * initialized the time	
 */
	double dStart = clock();
	unsigned long iLength = 0;
	msequence seqTemp;
	register char cValue = '\0';
	char *pValue = NULL;
	char *pEol = NULL;
	m_pCol->clear();
	unsigned long lLength = 0;
	seqTemp.m_strDes = " ";
	seqTemp.m_strSeq = " ";
	size_t tS = 0;
	while(!feof(m_pInput) && iLength < m_tColMax)	{
/*
 * store the description in a temporary msequence object, obtained in the previous read	
 */
		tS = fread(&lLength,4,1,m_pInput);
		if(feof(m_pInput))	{
			break;
		}
#ifdef OSX
		lLength = mac_rev(lLength);
#endif
		tS = fread(m_pLine,lLength,1,m_pInput);
		if(feof(m_pInput))	{
			break;
		}
		if(_f)
			m_pCol->m_vASequences[iLength].m_strDes = m_pLine;
		tS = fread(&lLength,4,1,m_pInput);
#ifdef OSX
		lLength = mac_rev(lLength);
#endif
		tS = fread(m_pLine,lLength,1,m_pInput);
		if(feof(m_pInput))	{
			break;
		}
		if(_f)	{
			bz(m_pLine);
			m_pCol->m_vASequences[iLength].m_strSeq = m_pLine;
			m_pCol->m_vASequences[iLength].m_siPath = (short int)(m_vstrPaths.size() - 1);
		}
		m_pCol->m_vASequences[iLength].m_mapMods.clear();
		m_pCol->m_tLength++;
		iLength++;
	}
/*
 * if the current sequence list file is finished, close it and get the next one, otherwise finish	
 */
	if(feof(m_pInput))	{
		if(m_dstrFasta.empty())	{
			finish();
		}
		else	{
			fclose(m_pInput);
			start();
		}
	}
/*
 * store the time required to load the msequencecontainer	
 */
	m_dTime += (double)(clock() - dStart);
	return iLength;
}
Exemple #12
0
/*
 * refill the msequencecontainer object with the next set of sequences and descriptions	
 */
unsigned long msequenceServer::next(const bool _f)
{
/*
 * exit on completion	
 */
	if(done())
		return 0;
/*
 * start the reading process, if it hasn't been started	
 */
	if(!started())	{
		if(!start())	{
			m_bDone = true;
			m_bError = true;
			m_strStatus += "Server would not start.\r\n";
			return 0;
		}
	}
	if(m_lFileType == XBANG)
		return next_pro(_f);
	if(!_f)
		return next_l();
/*
 * initialized the time	
 */
	double dStart = clock();
	unsigned long iLength = 0;
	msequence seqTemp;
	char cValue = '\0';
	char *pValue = NULL;
	char *pEol = NULL;
	m_pCol->clear();
	while(!feof(m_pInput) && iLength < m_pCol->m_tMax)	{
/*
 * store the description in a temporary msequence object, obtained in the previous read	
 */
		m_pCol->m_vASequences[iLength].m_strDes = m_strFirst;
/*
 * strip whitespace characters from the sequence line
 */
		pValue = m_pLine;
		fgets(pValue,m_lSize,m_pInput);
/*
 * clear the sequence in a temporary msequence object	
 */
		while(pValue[0] != '>' && !feof(m_pInput))	{
/*
 * store initial sequence line, and repeat until the next description line is encountered	
 */
			pValue += strlen(pValue);
			pValue--;
			if(pValue > m_pLine)	{
				while(pValue > m_pLine && isspace(*pValue))	{
					pValue--;
				}
				if(!isspace(*pValue) && *pValue != '\0')	{
					pValue++;
					*pValue = '\0';
				}
			}
			fgets(pValue,m_lSize,m_pInput);
		}
		cValue = *pValue;
		*pValue = '\0';
		bz(m_pLine);
		m_pCol->m_vASequences[iLength].m_strSeq = m_pLine;
		m_pCol->m_vASequences[iLength].m_siPath = (short int)(m_vstrPaths.size() - 1);
		*pValue = cValue;
/*
 *	store the next description line
 */
		if(pValue[0] == '>')	{
			if(strchr(pValue,0x01))	{
				pEol = strchr(pValue,0x01);
				*pEol = '\0';
			}
			else	{
				pEol = pValue + strlen(pValue) - 1;
				while(pEol > pValue && isspace(*pEol))	{
					*pEol = '\0';
					pEol--;
				}
			}
			pEol = strchr(pValue,'\r');
			if(pEol)	{
				*pEol = '\0';
			}
			pEol = strchr(pValue,'\n');
			if(pEol)	{
				*pEol = '\0';
			}
			m_strFirst = pValue + 1;
		}
		m_pCol->m_tLength++;
		iLength++;
	}
/*
 * if the current sequence list file is finished, close it and get the next one, otherwise finish	
 */
	if(feof(m_pInput))	{
		if(m_dstrFasta.empty())	{
			finish();
		}
		else	{
			fclose(m_pInput);
			start();
		}
	}
/*
 * store the time required to load the msequencecontainer	
 */
	m_dTime += (double)(clock() - dStart);
	return iLength;
}
Exemple #13
0
int32 MCF::verifyAll(const char* tempPath)
{
	if (!tempPath)
	{
		printf("Temp path is null.\n");
		return 3;
	}

	if (!m_sHeader->isValid())
	{
		printf("Mcf header is invalid.\n");
		return 1;
	}

	uint32 count = 0;
	for (size_t x=0; x<m_pFileList.size(); x++)
	{
		if (!m_pFileList[x]->isSaved())
			continue;

		count++;
	}

	if (count == 0)
	{
		printf("No files in the mcf are saved.\n");
		return 2;
	}

	UTIL::FS::FileHandle fh(getFile(), UTIL::FS::FILE_READ);

	uint32 badCount = 0;
	bool placeholder = false;

	for (size_t x=0; x<m_pFileList.size(); x++)
	{
		if (!m_pFileList[x]->isSaved())
			continue;

		try
		{
			m_pFileList[x]->verifyMcf(fh, placeholder);
		}
		catch (gcException &e)
		{
			printf("%s", gcString("{0}: Failed to verify Mcf with file: {1}\n", m_pFileList[x]->getName(), e).c_str());
			badCount++;
			continue;
		}

		if (!m_pFileList[x]->isComplete())
		{
			printf("%s", gcString("{0}: Failed mcf verify\n", m_pFileList[x]->getName()).c_str());
			badCount++;
			continue;
		}

		gcString t("{0}{1}{2}", tempPath?tempPath:".", DIRS_STR, m_pFileList[x]->getFullPath());
		UTIL::FS::Path path(t, "", true);
		UTIL::FS::recMakeFolder(path);

		UTIL::MISC::Buffer buff(10*1024);

		try
		{
			UTIL::FS::FileHandle file(path, UTIL::FS::FILE_WRITE);
			fh.seek(m_pFileList[x]->getOffSet());
#ifdef WIN32
			size_t size = 0;
#endif
			if (m_pFileList[x]->isCompressed())
			{
				uint64 done = m_pFileList[x]->getCSize();
				UTIL::MISC::BZ2Worker bz(UTIL::MISC::BZ2_DECOMPRESS);

				fh.read(done, [&bz, &file](const unsigned char* buff, uint32 size) -> bool
				{
					UTIL::FS::FileHandle* pFile = &file;

					bz.write((const char*)buff, size, [pFile](const unsigned char* tbuff, uint32 tsize) -> bool
					{
						pFile->write((const char*)tbuff, tsize);
						return false;
					});

					return false;
				});

				bz.end([&file](const unsigned char* tbuff, uint32 tsize) -> bool
				{
					file.write((const char*)tbuff, tsize);
					return false;
				});
			}
			else
			{
				uint64 done = m_pFileList[x]->getSize();

				fh.read(done, [&file](const unsigned char* buff, uint32 size) -> bool
				{
					file.write((const char*)buff, size);
					return false;
				});
			}
		}
		catch (gcException &e)
		{
			printf("%s", gcString("{0}: Failed to save file: {1}\n", m_pFileList[x]->getName(), e).c_str());
			badCount++;

			UTIL::FS::delFile(path);
			continue;
		}

		m_pFileList[x]->setDir(tempPath);
		m_pFileList[x]->verifyFile();
		m_pFileList[x]->setDir("");

		if (!m_pFileList[x]->isComplete())
		{
			printf("%s", gcString("{0}: Failed file verify\n", m_pFileList[x]->getName()).c_str());
			badCount++;
		}

		UTIL::FS::delFile(path);
	}

	UTIL::FS::delEmptyFolders(tempPath);

	return (int32)badCount*-1;
}
Exemple #14
0
int Ray::intersectsBox(const Vector3D &a, const Vector3D &b, Vector3D &in, Vector3D &out) const
{
    Vector3D ax(b.x(), a.y(), a.z()); // a décalé en x
    Vector3D az(a.x(), a.y(), b.z()); // a décalé en z
    Vector3D bx(a.x(), b.y(), b.z()); // b décalé en x
    Vector3D bz(b.x(), b.y(), a.z()); // b décalé en z
    if(origine.x() > a.x() && origine.x() < b.x() && origine.y() > a.y() && origine.y() < b.y() && origine.z() > a.z() && origine.z() < b.z())
    {
        in=origine;

        if(intersects(a, az, ax, out)){ // Intersection du plan a az ax
            if(out.x() >= a.x() && out.x() <= b.x() && out.z() >= a.z() && out.z() <= b.z()){ // In da box
                return 1;
            }
        }
        if(intersects(a, az, bx, out)) { // Intersection du plan a az bx
            if(out.y() >= a.y() && out.y() <= b.y() && out.z() >= a.z() && out.z() <= b.z()){ // In da box
                return 1;
            }
        }
        if(intersects(a, ax, bz, out)){ // Intersection du plan a ax bz
            if(out.x() >= a.x() && out.x() <= b.x() && out.y() >= a.y() && out.y() <= b.y()){ // In da box
                return 1;
            }
        }
        if(intersects(b, bx, bz, out)){ // Intersection du plan b bx bz
            if(out.x() >= a.x() && out.x() <= b.x() && out.z() >= a.z() && out.z() <= b.z()){ // In da box
                return 1;
            }
        }
        if(intersects(b, bx, az, out)){ // Intersection du plan b bx az
            if(out.x() >= a.x() && out.x() <= b.x() && out.y() >= a.y() && out.y() <= b.y()){ // In da box
                return 1;
            }
        }
        if(intersects(b, bz, ax, out)){ // Intersection du plan b bz ax
            if(out.y() >= a.y() && out.y() <= b.y() && out.z() >= a.z() && out.z() <= b.z()){ // In da box
                return 1;
            }
        }

    }
    else { // Origine hors de la boite
        int resu=0;

        Vector3D aaxaz;
        Vector3D aazbx;
        Vector3D aaxbz;
        Vector3D bbxbz;
        Vector3D bbxaz;
        Vector3D bbzax;

        bool ifaaxaz = intersects(a, ax, az, aaxaz);
        bool ifaazbx = intersects(a, az, bx, aazbx);
        bool ifaaxbz = intersects(a, ax, bz, aaxbz);
        bool ifbbxbz = intersects(b, bx, bz, bbxbz);
        bool ifbbxaz = intersects(b, bx, az, bbxaz);
        bool ifbbzax = intersects(b, bz, ax, bbzax);

        if(ifaaxaz&&resu<2){ // Intersection sur le plan a ax az et pas encore deux points d'entrée/sortie
            if(aaxaz.x() >= a.x() && aaxaz.x() <= b.x() && aaxaz.z() >= a.z() && aaxaz.z() <= b.z()){ // In da box
                if(resu==0){
                    in=aaxaz;
                    ++resu;
                }
                else{
                    if(resu==1&&aaxaz.distanceToPoint(in)>0.001){
                        out=aaxaz;
                        ++resu;
                    }
                }
            }
        }
        if(ifaazbx&&resu<2){ // Intersection sur le plan a az bx et pas encore deux points d'entrée/sortie
            if(aazbx.y() >= a.y() && aazbx.y() <= b.y() && aazbx.z() >= a.z() && aazbx.z() <= b.z()){ // In da box
                if(resu==0){
                    in=aazbx;
                    ++resu;
                }
                else{
                    if(resu==1&&aazbx.distanceToPoint(in)>0.001){
                        out=aazbx;
                        ++resu;
                    }
                }
            }
        }
        if(ifaaxbz&&resu<2){ // Intersection sur le plan a ax bz et pas encore deux points d'entrée/sortie
            if(aaxbz.x() >= a.x() && aaxbz.x() <= b.x() && aaxbz.y() >= a.y() && aaxbz.y() <= b.y()){ // In da box
                if(resu==0){
                    in=aaxbz;
                    ++resu;
                }
                else{
                    if(resu==1&&aaxbz.distanceToPoint(in)>0.001){
                        out=aaxbz;
                        ++resu;
                    }
                }
            }
        }
        if(ifbbxbz&&resu<2){ // Intersection sur le plan b bx bz et pas encore deux points d'entrée/sortie
            if(bbxbz.x() >= a.x() && bbxbz.x() <= b.x() && bbxbz.z() >= a.z() && bbxbz.z() <= b.z()){ // In da box
                if(resu==0){
                    in=bbxbz;
                    ++resu;
                }
                else{
                    if(resu==1&&bbxbz.distanceToPoint(in)>0.001){
                        out=bbxbz;
                        ++resu;
                    }
                }
            }
        }
        if(ifbbxaz&&resu<2){ // Intersection sur le plan b bx az et pas encore deux points d'entrée/sortie
            if(bbxaz.x() >= a.x() && bbxaz.x() <= b.x() && bbxaz.y() >= a.y() && bbxaz.y() <= b.y()){ // In da box
                if(resu==0){
                    in=bbxaz;
                    ++resu;
                }
                else{
                    if(resu==1&&bbxaz.distanceToPoint(in)>0.001){
                        out=bbxaz;
                        ++resu;
                    }
                }
            }
        }
        if(ifbbzax&&resu<2){ // Intersection sur le plan b bz ax et pas encore deux points d'entrée/sortie
            if(bbzax.y() >= a.y() && bbzax.y() <= b.y() && bbzax.z() >= a.z() && bbzax.z() <= b.z()){ // In da box
                if(resu==0){
                    in=bbzax;
                    ++resu;
                }
                else{
                    if(resu==1&&bbzax.distanceToPoint(in)>0.001){
                        out=bbzax;
                        ++resu;
                    }
                }
            }
        }

        if(resu < 2) // Passe hors de la boite ou sur une arrête
        {
            return 0;
        }

        if(origine.distanceToPointSquared(in) > origine.distanceToPointSquared(out)) // Inversion si les deux points trouvés ne l'ont pas été dans le bon ordre
        {
            Vector3D tmp = in;
            in = out;
            out = tmp;
        }

        return 2;

    }
}
Exemple #15
0
  void System::Problem_generate_IC(const int param)
  {
    if (thisIndex == 0)
    {
      CkPrintf(" ********* Cloud capture ************* \n");
      CkPrintf(" **** MAGNETISATION=%g     \n", MAGNETISATION);
      CkPrintf(" **** H/R          =%g     \n", HoR  );
      CkPrintf(" **** GRAVITY_MASS= %g     \n", GM);
      CkPrintf(" **** GRAVITY_EPS=  %g     \n", GM_EPS);
      CkPrintf(" ---  \n");	
    }

    gamma_gas  = 1.0;
    courant_no = 0.8;

    t_global  = 0;
    iteration = 0;

    const real xcl = XCL;
    const real ycl = YCL;

    const real vx_cl = VX0/VUNIT;
    const real vy_cl = VY0/VUNIT;

    const real vorb  = std::sqrt(sqr(vx_cl) + sqr(vy_cl));
    const real Rinit = std::sqrt(sqr(xcl)   + sqr(ycl)  );

    const real tinfall = Rinit/vorb;

    const real dcl = (DCLOUD/DUNIT);
    const real cs2 = get_cs2(vec3(xcl, ycl, 0.0)); //TCLOUD*Tunit/sqr(vunit);

    if (thisIndex == 0)
    {
      CkPrintf("Ro= %g pc, x= %g  y= %g; vx= %g vy= %g vt= %g  tinfall= %g Myr [%g]\n",
          Rinit,
          xcl, ycl,
          vx_cl, vy_cl,
          vorb,
          tinfall * TIMEUNIT, tinfall);
    }


    for (int i = 0; i < local_n; i++) 
    {
      const Particle &pi = ptcl_list[i];

      const vec3 &pos = pi.get_pos();

      if (pos.abs() < BND_RADIUS || pos.abs() > RoutBND)
        mesh_pnts[i].boundary = MeshPoint::DIOD;
      else  
        mesh_pnts[i].boundary = MeshPoint::NO_BOUNDARY;

      const real Rdist = (pos - vec3(xcl, ycl, 0.0)).abs();
      const real inv_beta = MAGNETISATION;

      real dens = dcl;
      real pres = dcl * cs2;
      real b0   = std::sqrt(2.0*pres * inv_beta);

      real bx(0), by(0), bz(0);

#if 0
      bx = by = b0/sqrt(2.0);
#else
      bx = by = bz = b0/sqrt(3.0);
#endif

      real vx(vx_cl), vy(vy_cl), vz(0.0);

      real scalar = 1.0;
      if (Rdist > RCLOUD)
      {
        dens = DENSvac/DUNIT;
        const real csig = std::sqrt(get_cs2(pos));
        vx = (1 - 2.0*drand48()) * csig;
        vy = (1 - 2.0*drand48()) * csig;
        vz = (1 - 2.0*drand48()) * csig;
        scalar = -1.0;
      }
      Fluid m;

      m[Fluid::DENS] = dens;
      m[Fluid::ETHM] = get_cs2(pos)*dens;
      m[Fluid::VELX] = vx;
      m[Fluid::VELY] = vy;
      m[Fluid::VELZ] = vz;
      m[Fluid::BX  ] = bx;
      m[Fluid::BY  ] = by;
      m[Fluid::BZ  ] = bz;
      m[Fluid::PSI ] = 0.0;
      m[Fluid::ENTR] = 1.0;

      Wrec_list[i] = Fluid_rec(m);

      mesh_pnts[i].idx  = thisIndex*1000000 + i+1;

    }
  }
Exemple #16
0
char *bin_op_run(bot_t * bot, char *prog, char *options, char *input,
		 dlist_t * dlist_node)
{
	pid_t pid = 0;
	char buf[MAX_BUF_SZ + 1];
	char *path = NULL;
	char *str = NULL, *ptr = NULL;

	dlist_t *dl_data = NULL, *dptr_data = NULL;
	memdup_t *mem = NULL;

	int argc = 0;
	char **argv = NULL;

	int pipefds1[2], pipefds2[2];

	int n = 0, i = 0;

	debug(NULL, "bin_op_run: Entered: %s %s %s\n", prog, options, input);

	if (!bot || !_sNULL(prog))
		return NULL;

	if (!str_apply_is(prog, isprog))
		return NULL;

	if (!_sNULL(options))
		options = "";
	path =
	    str_unite_static("%s/mods/mod_bin_files/%s %s", gi->confdir, prog,
			     options);
	argv = tokenize_str2argv(path, &argc, 0);
	if (!argv)
		return NULL;

	for (i = 0; i < argc; i++) {
		debug(NULL, "bin_op_run: %i. %s\n", i, argv[i]);
	}

	clean_environ();

	if (pipe(pipefds1) < 0)
		goto cleanup;
	if (pipe(pipefds2) < 0)
		goto cleanup;

	pid = bot_fork_clean(bot);
	if (pid < 0)
		goto cleanup;

	if (!pid) {
		pid = getpid();

		close(0);
		close(1);
		close(2);

		close(pipefds2[0]);
		dup2(pipefds2[1], 1);
		dup2(pipefds2[1], 2);
		close(pipefds1[1]);
		close(0);
		dup2(pipefds1[0], 0);

		execve(argv[0], argv, environ);
		bot_fork_clean_exit(bot);
		return 0;
	} else {
		close(pipefds1[0]);
		close(pipefds2[1]);
		while (1) {
			bz(buf);
			n = read(pipefds2[0], buf, sizeof(buf) - 1);
			if (n <= 0)
				break;

			dlist_Dinsert_after(&dl_data, memdup(buf, n));
		}
	}

	bz(bot->txt_data_in);

	strzero_bot(bot->txt_data_in);
	strlcat_bot(bot->txt_data_in, bot->txt_data_out);

	bot->txt_data_in_sz = strlen(bot->txt_data_in);

	dlist_fornext(dl_data, dptr_data) {
		if (!dptr_data)
			break;
		mem = (memdup_t *) dlist_data(dptr_data);
		if (!mem)
			continue;
//memcpy_bot(bot->txt_data_in, mem->data, mem->len);
		strlcat_bot(bot->txt_data_in, mem->data);
		bot->txt_data_in_sz += mem->len;
	}

	if (dlist_node) {

		dlist_fornext(dlist_next(dlist_node), dptr_data) {
			ptr = (char *)dlist_data(dptr_data);
			charcat_bot(bot->txt_data_in, '|');
			strlcat_bot(bot->txt_data_in, ptr);
			bot->txt_data_in_sz += strlen(ptr) + 1;
		}
	}