コード例 #1
0
void HMMObserver::printHelp() {
	log_i(
			"Transition Chunker\n"
			"Kevin Weekly\n"
			"\n"
			"\t-csvin  : Input CSV file\n"
			"\t-csvout : Output CSV file\n"
			"\t-outprec :Output precision\n"
			"\t-statesout : Perform state detection and output\n"
			);
	AbstractProgram::printHelp();
}
コード例 #2
0
ファイル: main.c プロジェクト: nfcp/EasyLogger
/**
 * EasyLogger demo
 */
void test_elog(void) {
    while(true) {
        /* test log output for all level */
        log_a("Hello EasyLogger!");
        log_e("Hello EasyLogger!");
        log_w("Hello EasyLogger!");
        log_i("Hello EasyLogger!");
        log_d("Hello EasyLogger!");
        log_v("Hello EasyLogger!");
//        elog_raw("Hello EasyLogger!");
        sleep(5);
    }
}
コード例 #3
0
ファイル: gl_utils.c プロジェクト: cmatsuoka/open-greedy
int push_gl_srv_buffer(struct gl_buffer *gl_buffer)
{
	struct gl_srv_buffer *self =
		b6_cast_of(gl_buffer, struct gl_srv_buffer, gl_buffer);
	float *p, *q;
	static const unsigned long int min_size = 32768;
	unsigned long int v_size = b6_array_memsize(&gl_buffer->v);
	unsigned long int t_size = b6_array_memsize(&gl_buffer->t);
	unsigned long int size = v_size + t_size;
	unsigned long int len = b6_array_length(&gl_buffer->t);
	unsigned long int max = gl_buffer->t.capacity;
	const float *v = b6_array_get(&gl_buffer->v, 0);
	const float *t = b6_array_get(&gl_buffer->t, 0);
	if (size < v_size || size < t_size) {
		log_e("integer overflow");
		return -2;
	}
	if (size < min_size)
		size = min_size;
	if (size > self->size) {
		log_i("allocating %u bytes", size);
		self->size = size;
		if (self->id) {
			maybe_unbind_gl_buffer(self->id);
			destroy_gl_buffer(self->id);
		}
		create_gl_buffer(&self->id);
		maybe_bind_gl_buffer(self->id);
		alloc_gl_buffer(size);
	}
	log_i("pushing %u/%u vertices", len, max);
	p = map_gl_buffer();
	q = p + max * 2;
	while (len--) { *p++ = *t++; *p++ = *t++; *q++ = *v++; *q++ = *v++; }
	unmap_gl_buffer();
	glTexCoordPointer(2, GL_FLOAT, 0, NULL);
	glVertexPointer(2, GL_FLOAT, 0, ((float*)NULL) + max * 2);
	return 0;
}
コード例 #4
0
ファイル: easylogger.c プロジェクト: 1847123212/EasyFlash
/**
 * Elog demo
 */
static void test_elog(void) {
    /* output all saved log from flash */
    elog_flash_output_all();
    /* test log output for all level */
    log_a("Hello EasyLogger!");
    log_e("Hello EasyLogger!");
    log_w("Hello EasyLogger!");
    log_i("Hello EasyLogger!");
    log_d("Hello EasyLogger!");
    log_v("Hello EasyLogger!");
    elog_raw("Hello EasyLogger!");
    /* trigger assert. Now will run elog_user_assert_hook. All log information will save to flash. */
    ELOG_ASSERT(0);
}
コード例 #5
0
ファイル: profile.cpp プロジェクト: Snodig/Nagios
void rpnoc::Profile::newProfile( void )
{
	ProfileNameDialog oProfileDialog;
	oProfileDialog.exec();

	QString oFilename = oProfileDialog.getFilename();
	QString oTempUser = getUser();
	QString oFile( "profiles/" + oTempUser + "/" + oFilename + ".xml" );
	writeXml( oFile, &profileList );
	profileList.append( oFilename + ".xml" );
	log_i( "New profile Created '" + oFile + "'." );

	showProfiles();
}
コード例 #6
0
ファイル: profile.cpp プロジェクト: Snodig/Nagios
void rpnoc::Profile::deleteProfile( void )
{
	QVariant oTemp = model->data( listView->currentIndex(), 0 );
	model->removeRows( listView->currentIndex().row(), 1 );

	QString oTempUser = getUser();
	QString oFilename = oTemp.toString();
	
	QFile oFile;
	oFile.remove( "profiles/" + oTempUser + "/" + oFilename );
	log_i( "Removed profile 'profiles/" + oTempUser + "/" + oFilename + "'." ); 

	profileList.removeOne( oFilename );
}
コード例 #7
0
ファイル: nynn_ipc.hpp プロジェクト: iieplatform/nynn_mm
	Lockop(int semid,int slot )throw(nynn_exception_t):semid(semid),slot(slot)
	{

		struct seminfo si;
		if (semctl(0,0,IPC_INFO,&si)==-1)throw_nynn_exception(errno,NULL);
		int semmsl=si.semmsl;
		int semopm=si.semopm;
		log_i("semmsl=%d",semmsl);
		log_i("semopm=%d",semopm);
		

		struct semid_ds ds;
		if (semctl(semid,0,IPC_STAT,&ds)!=0)throw_nynn_exception(errno,NULL);

		if (slot>=ds.sem_nsems)throw_nynn_exception(EINVAL,NULL);

		struct sembuf sop;
		sop.sem_op=-1;
		sop.sem_num=slot;
		sop.sem_flg=SEM_UNDO;
		
		if (semop(semid,&sop,1)!=0)throw_nynn_exception(errno,NULL);
	}
コード例 #8
0
ファイル: testqset.c プロジェクト: xelda1988/qhull
void testSetappendSet(int numInts, int *intarray, int checkEvery)
{
    setT *ints=qh_setnew(1);
    setT *ints2;
    int i,j,k;

    qh_fprintf(stderr, 8016, "\n\nTesting qh_setappend_set 0..%d. Test", numInts-1);
    for(j=0; j<numInts; j++){
        if(log_i(ints, "j", j, numInts, numInts)){
            for(i= qh_setsize(ints); i<j; i++){
                qh_setappend(&ints, intarray+i);
            }
            if(checkEvery==1){
                checkSetContents("qh_setappend", ints, j, 0, -1, -1);
            }
            ints2= qh_setnew(j==0 ? 0 : j-1);  /* One less than needed */
            for(i= 0; i<=j && i<=20; i++){  /* otherwise too slow */
                if(log_i(ints, "", i, numInts, numInts)){
                    for(k= qh_setsize(ints2); k<i; k++){
                        qh_setappend(&ints2, intarray+k);
                    }
                    if(checkEvery==1){
                        checkSetContents("qh_setappend 2", ints2, i, 0, -1, -1);
                    }
                    qh_setappend_set(&ints, ints2);
                    checkSetContents("qh_setappend_set", ints, i+j, 0, (j==0 ? -1 : 0), -1);
                    qh_settruncate(ints, j);
                    if(checkEvery==1){
                        checkSetContents("qh_settruncate", ints, j, 0, -1, -1);
                    }
                }
            }
            qh_setfree(&ints2);
        }
    }
    qh_setfree(&ints);
}/*testSetappendSet*/
コード例 #9
0
ファイル: app_config.c プロジェクト: DrMcCoy/contiki-inga
/*----------------------------------------------------------------------------*/
int8_t
app_config_init()
{
  // initialize struct to zero
  memset(&system_config, 0, sizeof (app_config_t));

  // first try loading form micro SD if someone was so kind to insert one
  if ((sysflag_get(SYS_SD_MOUNTED)) && (_app_config_load_microSD() == 0)) {
    return 0;
  }

  // load from internal memory
  if (_app_config_load_internal() == 0) {
    log_i("Loaded config from internal data\n");
    return 0;
  }

  // we had no success in loading, lets use boring defaults as fallback
  log_w("Loading from internal data failed\n");
  _app_config_load_defaults();
  log_i("Defaults loaded\n");

  return 1;
}
コード例 #10
0
ファイル: cli_framework.cpp プロジェクト: iieplatform/nynn_mm
int main(int argc,char**argv)
{

	string text_ip=argv[1];
	string text_port=argv[2];

	int loop=parse_int(argv[3],1<<10);
	zmq::context_t ctx;
	zmq::socket_t sock(ctx,ZMQ_REQ);
	string serv_endpoint="tcp://"+text_ip+":"+text_port;

	sock.connect(serv_endpoint.c_str());
	log_i("connected to %s",serv_endpoint.c_str());
	prot::Requester req(sock);

<<<<<<< HEAD
コード例 #11
0
ファイル: level.c プロジェクト: cmatsuoka/open-greedy
static void recover_ghosts_den(struct level *self, struct layout *layout)
{
	int xs, ys, xd, yd;
	struct level_iterator iter;
	struct place *closest_place = NULL;
	unsigned int distance, min_distance = LEVEL_WIDTH + LEVEL_HEIGHT;
	if (!self->ghosts_home)
		return;
	place_location(self, self->ghosts_home, &xs, &ys);
	if (is_place_clear(layout, xs, ys))
		return;
	log_i("recovering from non-accessible ghosts den.");
	initialize_level_iterator(&iter, self);
	while (level_iterator_has_next(&iter)) {
		struct place *place = level_iterator_next(&iter);
		place_location(self, place, &xd, &yd);
		distance = (xs > xd ? xs - xd : xd - xs) +
			(ys > yd ? ys - yd : yd - ys);
		if (distance && distance < min_distance) {
			closest_place = place;
			min_distance = distance;
		}
	}
	if (!closest_place) {
		log_e("could not find the closest place to ghost den.");
		return;
	}
	if (min_distance > ghost_den_recovery_radius) {
		log_w("could not find a place close enough to ghost den "
		      "(%u > %u).", min_distance, ghost_den_recovery_radius);
		return;
	}
	place_location(self, closest_place, &xd, &yd);
	while (--min_distance) {
		if (xs < xd)
			xs += 1;
		else if (xs > xd)
			xs -= 1;
		else if (ys < yd)
			ys += 1;
		else if (ys > yd)
			ys -= 1;
		__get_place(self, xs, ys)->item = clone_empty(self->items);
	}
}
コード例 #12
0
ファイル: elog_flash.c プロジェクト: HackLinux/EasyLogger
/**
 * Read and output log which saved in flash.
 *
 * @param index index for saved log.
 *        Minimum index is 0.
 *        Maximum index is log used flash total size - 1.
 * @param size
 */
void elog_flash_outout(size_t index, size_t size) {
    /* 128 bytes buffer */
    uint32_t buf[32] = { 0 };
    size_t log_total_size = ef_log_get_used_size();
    size_t buf_szie = sizeof(buf);
    size_t read_size = 0, read_overage_size = 0;

    if (index + size > log_total_size) {
        log_i("The output position and size is out of bound. The max size is %d.", log_total_size);
        return;
    }

    /* must be call this function after initialize OK */
    ELOG_ASSERT(init_ok);
    /* lock flash log buffer */
    log_buf_lock();
    /* Output all flash saved log. It will use filter */
    while (true) {
        if (index + read_size + buf_szie < log_total_size) {
            ef_log_read(index + read_size, buf, buf_szie);
            elog_flash_port_output((const char*)buf, buf_szie);
            read_size += buf_szie;
        } else {
            /* flash read is word alignment */
            if ((log_total_size - index - read_size) % 4 == 0) {
                read_overage_size = 0;
            } else {
                read_overage_size = 4 - ((log_total_size - index - read_size) % 4);
            }
            ef_log_read(index + read_size - read_overage_size, buf,
                    log_total_size - index - read_size + read_overage_size);
            elog_flash_port_output((const char*) buf + read_overage_size,
                    log_total_size - index - read_size);
            /* output newline sign */
            elog_flash_port_output(ELOG_NEWLINE_SIGN, strlen(ELOG_NEWLINE_SIGN));
            break;
        }
    }
    /* unlock flash log buffer */
    log_buf_unlock();
}
コード例 #13
0
ファイル: app_config.c プロジェクト: DrMcCoy/contiki-inga
/*----------------------------------------------------------------------------*/
static int8_t
_app_config_load_internal()
{
#if APP_CONF_STORE_EEPROM
  log_i("Loading config from EEPROM...\n");
  eeprom_read_block(&system_config, &ee_system_config, sizeof (system_config));
  // check if data is valid
  if (system_config._check_sequence != CHECK_SEQUENCE) {
    log_e("Loading config from EEPROM failed.\n");
    return -1;
  }

  // debug output
  print_config();

  // reconfigure sensors
  configure_sensors();

  return 0;
#endif
}
コード例 #14
0
ファイル: testqset.c プロジェクト: xelda1988/qhull
void testSetappendSettruncate(int numInts, int *intarray, int checkEvery)
{
    setT *ints= qh_setnew(4);
    int i, isCheck;

    qh_fprintf(stderr, 8002, "\n\nTesting qh_setappend 0..%d.  Test", numInts-1);
    for(i= 0; i<numInts; i++){
        isCheck= log_i(ints, "i", i, numInts, checkEvery);
        qh_setappend(&ints, intarray+i);
        if(isCheck){
            checkSetContents("qh_setappend", ints, i+1, 0, -1, -1);
        }
    }

    qh_fprintf(stderr, 8014, "\n\nTesting qh_settruncate %d and 0.  Test", numInts/2);
    if(numInts>=2){
        isCheck= log_i(ints, "n", numInts/2, numInts, checkEvery);
        qh_settruncate(ints, numInts/2);
        checkSetContents("qh_settruncate by half", ints, numInts/2, 0, -1, -1);
    }
    isCheck= log_i(ints, "n", 0, numInts, checkEvery);
    qh_settruncate(ints, 0);
    checkSetContents("qh_settruncate", ints, 0, -1, -1, -1);

    qh_fprintf(stderr, 8003, "\n\nTesting qh_setappend2ndlast 0,0..%d.  Test 0", numInts-1);
    qh_setfree(&ints);
    ints= qh_setnew(4);
    qh_setappend(&ints, intarray+0);
    for(i= 0; i<numInts; i++){
        isCheck= log_i(ints, "i", i, numInts, checkEvery);
        qh_setappend2ndlast(&ints, intarray+i);
        if(isCheck){
            checkSetContents("qh_setappend2ndlast", ints, i+2, 0, 0, -1);
        }
    }
    qh_fprintf(stderr, 8015, "\n\nTesting SETtruncate_ %d and 0.  Test", numInts/2);
    if(numInts>=2){
        isCheck= log_i(ints, "n", numInts/2, numInts, checkEvery);
        SETtruncate_(ints, numInts/2);
        checkSetContents("SETtruncate_ by half", ints, numInts/2, 0, -1, -1);
    }
    isCheck= log_i(ints, "n", 0, numInts, checkEvery);
    SETtruncate_(ints, 0);
    checkSetContents("SETtruncate_", ints, 0, -1, -1, -1);

    qh_setfree(&ints);
}/*testSetappendSettruncate*/
コード例 #15
0
ファイル: dijkstra.c プロジェクト: pgrz/porr
void update_mind ( int mv, int connected[vertex_count], int ohd[vertex_count][vertex_count], int mind[vertex_count])
{
    int i;

    log_d(tid, "Updating mind");

    for ( i = my_first; i <= my_last; i++ )
    {
        if ( !connected[i] )
        {
            if ( ohd[mv][i] < INT_MAX )
            {
                if ( mind[mv] + ohd[mv][i] < mind[i] )
                {
                    log_i(tid, "Updating mind[%d] from %d to %d", i, mind[i], mind[mv] + ohd[mv][i]);
                    mind[i] = mind[mv] + ohd[mv][i];
                }
            }
        }
    }
    return;
}
コード例 #16
0
ファイル: testqset.c プロジェクト: xelda1988/qhull
void testSettemp(int numInts, int *intarray, int checkEvery)
{
    setT *ints= NULL;
    setT *ints2= NULL;
    setT *ints3= NULL;
    int i,j;

    qh_fprintf(stderr, 8021, "\n\nTesting qh_settemp* 0..%d. Test", numInts-1);
    for(j=0; j<numInts; j++){
        if(log_i(ints, "j", j, numInts, checkEvery)){
            if(j<20){
                for(i=0; i<j; i++){
                    ints2= qh_settemp(j);
                }
                qh_settempfree_all();
            }
            for(i= qh_setsize(ints); i<j; i++){  /* Test i<j to test the empty set */
                qh_setappend(&ints, intarray+i);
            }
            ints2= qh_settemp(j);
            if(j>0){
                qh_settemppush(ints);
                ints3= qh_settemppop();
                if(ints!=ints3){
                    qh_fprintf(stderr, 6343, "qh_settemppop: didn't pop the push\n");
                    error_count++;
                }
            }
            qh_settempfree(&ints2);
        }
    }
    qh_setfreelong(&ints);
    if(ints){
        qh_setfree(&ints); /* Was quick memory */
    }
}/*testSettemp*/
コード例 #17
0
ファイル: cache.c プロジェクト: armink/EasyDataManager
/**
 * This function will initialize cache model.
 *
 * @param cache the cache pointer
 * @param name the cache name
 * @param maxThreadNum the cache use max threads number in thread pool
 * @param threadStackSize the thread stack size in thread pool
 *
 * @return error code
 */
CacheErrCode initCache(pCache const cache, const char* name, uint8_t maxThreadNum,
        uint32_t threadStackSize) {
    CacheErrCode errorCode = CACHE_NO_ERR;

    if ((name == NULL) || (strlen(name) > CACHE_NAME_MAX)) {
        log_i("the name of %s can not be create for list", name);
        errorCode = CACHE_NAME_ERROR;
    } else {
        strcpy(cache->name, name);
    }
    cache->has = hasData;
    cache->add = addData;
    cache->del = delData;
    cache->get = getValue;
    cache->set = setValue;
    cache->getSize = getSize;
    cache->dataHead = NULL;
    cache->dataTail = NULL;
    /* initialize the thread pool */
    cache->pool = (pThreadPool) malloc(sizeof(ThreadPool));
    assert(cache->pool != NULL);
    initThreadPool(cache->pool, "cache", maxThreadNum, threadStackSize);
    return errorCode;
}
コード例 #18
0
ファイル: elog_flash.c プロジェクト: HackLinux/EasyLogger
/**
 * clean all log which in flash and ram buffer
 */
void elog_flash_clean(void) {
    EfErrCode clean_result = EF_NO_ERR;

    /* must be call this function after initialize OK */
    ELOG_ASSERT(init_ok);
    /* lock flash log buffer */
    log_buf_lock();
    /* clean all log which in flash */
    clean_result = ef_log_clean();

#ifdef ELOG_FLASH_USING_BUF_MODE
    /* reset position */
    cur_buf_size = 0;
#endif

    /* unlock flash log buffer */
    log_buf_unlock();

    if(clean_result == EF_NO_ERR) {
        log_i("All logs which in flash is clean OK.");
    } else {
        log_e("Clean logs which in flash has an error!");
    }
}
コード例 #19
0
ファイル: testqset.c プロジェクト: xelda1988/qhull
void testSetlastEtc(int numInts, int *intarray, int checkEvery)
{
    setT *ints= NULL;
    setT *ints2= NULL;
    int i,j,prepend;

    qh_fprintf(stderr, 8020, "\n\nTesting qh_setlast, qh_setnew_delnthsorted, qh_setunique, and qh_setzero 0..%d. Test", numInts-1);
    for(j=0; j<numInts; j++){
        if(log_i(ints, "j", j, numInts, checkEvery)){
            for(i= qh_setsize(ints); i<j; i++){  /* Test i<j to test the empty set */
                if(!qh_setunique(&ints, intarray+i)){
                    qh_fprintf(stderr, 6340, "qh_setunique: not able to append next element %d\n", i);
                    error_count++;
                }
                if(checkEvery==1){
                    checkSetContents("qh_setunique", ints, i+1, 0, -1, -1);
                }
                if(qh_setunique(&ints, intarray+i)){
                    qh_fprintf(stderr, 6341, "qh_setunique: appended next element twice %d\n", i);
                    error_count++;
                }
                if(qh_setunique(&ints, intarray+i/2)){
                    qh_fprintf(stderr, 6346, "qh_setunique: appended middle element twice %d/2\n", i);
                    error_count++;
                }
            }
            checkSetContents("qh_setunique 2", ints, j, 0, -1, -1);
            if(j==0 && NULL!=qh_setlast(ints)){
                qh_fprintf(stderr, 6339, "qh_setlast: returned last element of empty set\n");
                error_count++;
            }
            if(j>0){
                if(intarray+j-1!=qh_setlast(ints)){
                    qh_fprintf(stderr, 6338, "qh_setlast: wrong last element\n");
                    error_count++;
                }
                prepend= (j<100 ? j/4 : 0);
                ints2= qh_setnew_delnthsorted(ints, qh_setsize(ints), j/2, prepend);
                if(qh_setsize(ints2)!=j+prepend-1){
                    qh_fprintf(stderr, 6345, "qh_setnew_delnthsorted: Expecting %d elements, got %d\n", j+prepend-1, qh_setsize(ints2));
                    error_count++;
                }
                /* Define prepended elements.  Otherwise qh_setdelnthsorted may fail */
                for(i= 0; i<prepend; i++){
                    void **p= &SETelem_(ints2, i);
                    *p= intarray+0;
                }
                for(i= 0; i<prepend; i++){
                    qh_setdelnthsorted(ints2, 0);  /* delete undefined prefix */
                }
                checkSetContents("qh_setnew_delnthsorted", ints2, j-1, 0, j/2+1, -1);
                if(j>2){
                    qh_setzero(ints2, j/2, j-1);  /* max size may be j-1 */
                    if(qh_setsize(ints2)!=j-1){
                        qh_fprintf(stderr, 6342, "qh_setzero: Expecting %d elements, got %d\n", j, qh_setsize(ints2));
                        error_count++;
                    }
                    qh_setcompact(ints2);
                    checkSetContents("qh_setzero", ints2, j/2, 0, -1, -1);
                }
            }
            qh_setfree(&ints2);
        }
    }
    qh_setfreelong(&ints);
    if(ints){
        qh_setfree(&ints); /* Was quick memory */
    }
}/*testSetlastEtc*/
コード例 #20
0
ファイル: testqset.c プロジェクト: xelda1988/qhull
void testSetequalInEtc(int numInts, int *intarray, int checkEvery)
{
    setT *ints= NULL;
    setT *ints2= NULL;
    setT *ints3= NULL;
    int i,j,n;

    qh_fprintf(stderr, 8019, "\n\nTesting qh_setequal*, qh_setin*, qh_setdel, qh_setdelnth, and qh_setlarger 0..%d. Test", numInts-1);
    for(j=0; j<numInts; j++){
        if(log_i(ints, "j", j, numInts, checkEvery)){
            n= qh_setsize(ints);
            qh_setlarger(&ints);
            checkSetContents("qh_setlarger", ints, n, 0, -1, -1);
            for(i= qh_setsize(ints); i<j; i++){  /* Test i<j to test the empty set */
                qh_setappend(&ints, intarray+i);
            }
            checkSetContents("qh_setappend", ints, j, 0, -1, -1);
            if(!qh_setequal(ints, ints)){
                qh_fprintf(stderr, 6300, "testSetequalInEtc: set not equal to itself at length %d\n", j);
                error_count++;
            }
            if(j==0 && !qh_setequal(ints, ints2)){
                qh_fprintf(stderr, 6323, "testSetequalInEtc: empty set not equal to null set\n");
                error_count++;
            }
            if(j>0){
                if(qh_setequal(ints, ints2)){
                    qh_fprintf(stderr, 6324, "testSetequalInEtc: non-empty set equal to empty set\n", j);
                    error_count++;
                }
                qh_setfree(&ints3);
                ints3= qh_setcopy(ints, 0);
                checkSetContents("qh_setreplace", ints3, j, 0, -1, -1);
                qh_setreplace(ints3, intarray+j/2, intarray+j/2+1);
                if(j==1){
                    checkSetContents("qh_setreplace 2", ints3, j, j/2+1, -1, -1);
                }else if(j==2){
                    checkSetContents("qh_setreplace 3", ints3, j, 0, j/2+1, -1);
                }else{
                    checkSetContents("qh_setreplace 3", ints3, j, 0, j/2+1, j/2+1);
                }
                if(qh_setequal(ints, ints3)){
                    qh_fprintf(stderr, 6325, "testSetequalInEtc: modified set equal to original set at %d/2\n", j);
                    error_count++;
                }
                if(!qh_setequal_except(ints, intarray+j/2, ints3, intarray+j/2+1)){
                    qh_fprintf(stderr, 6326, "qh_setequal_except: modified set not equal to original set except modified\n", j);
                    error_count++;
                }
                if(qh_setequal_except(ints, intarray+j/2, ints3, intarray)){
                    qh_fprintf(stderr, 6327, "qh_setequal_except: modified set equal to original set with wrong excepts\n", j);
                    error_count++;
                }
                if(!qh_setequal_skip(ints, j/2, ints3, j/2)){
                    qh_fprintf(stderr, 6328, "qh_setequal_skip: modified set not equal to original set except modified\n", j);
                    error_count++;
                }
                if(j>2 && qh_setequal_skip(ints, j/2, ints3, 0)){
                    qh_fprintf(stderr, 6329, "qh_setequal_skip: modified set equal to original set with wrong excepts\n", j);
                    error_count++;
                }
                if(intarray+j/2+1!=qh_setdel(ints3, intarray+j/2+1)){
                    qh_fprintf(stderr, 6330, "qh_setdel: failed to find added element\n", j);
                    error_count++;
                }
                checkSetContents("qh_setdel", ints3, j-1, 0, j-1, (j==1 ? -1 : j/2+1));  /* swaps last element with deleted element */
                if(j>3){
                    qh_setdelnth(ints3, j/2); /* Delete at the same location as the original replace, for only one out-of-order element */
                    checkSetContents("qh_setdelnth", ints3, j-2, 0, j-2, (j==2 ? -1 : j/2+1));
                }
                if(qh_setin(ints3, intarray+j/2)){
                    qh_fprintf(stderr, 6331, "qh_setin: found deleted element\n");
                    error_count++;
                }
                if(j>4 && !qh_setin(ints3, intarray+1)){
                    qh_fprintf(stderr, 6332, "qh_setin: did not find second element\n");
                    error_count++;
                }
                if(j>4 && !qh_setin(ints3, intarray+j-2)){
                    qh_fprintf(stderr, 6333, "qh_setin: did not find last element\n");
                    error_count++;
                }
                if(-1!=qh_setindex(ints2, intarray)){
                    qh_fprintf(stderr, 6334, "qh_setindex: found element in empty set\n");
                    error_count++;
                }
                if(-1!=qh_setindex(ints3, intarray+j/2)){
                    qh_fprintf(stderr, 6335, "qh_setindex: found deleted element in set\n");
                    error_count++;
                }
                if(0!=qh_setindex(ints, intarray)){
                    qh_fprintf(stderr, 6336, "qh_setindex: did not find first in set\n");
                    error_count++;
                }
                if(j-1!=qh_setindex(ints, intarray+j-1)){
                    qh_fprintf(stderr, 6337, "qh_setindex: did not find last in set\n");
                    error_count++;
                }
            }
            qh_setfree(&ints2);
        }
    }
    qh_setfree(&ints3);
    qh_setfreelong(&ints);
    if(ints){
        qh_setfree(&ints); /* Was quick memory */
    }
}/*testSetequalInEtc*/
コード例 #21
0
void HMMObserver::start() {
	vector<vector<TimeSeries *> *> chunk_bins;
	vector<double> current_means;
	vector<double> current_ns;
	vector<double> current_variance;
	vector<TimeSeries *> chunks;

	TimeSeries * inputTS = NULL;
	if (use_csv) {
		inputTS = CSVLoader::loadTSfromCSV(csvin_fname);
	} else {
		log_e("No input source defined. Stop.");
		return;
	}

#define NUM_STEPS 5
	TimeSeries * inputRaw = inputTS->copy();

	TRANS_DETECTOR.setParams(0.05,60);
	double NEW_BIN_THRESH = 1.2;

	log_prog(1,NUM_STEPS,"Detect Transitions","");
	EventSeries<TransitionEvent> * es = TRANS_DETECTOR.detect(inputTS);

	log_i("%d Transitions found\n",es->events.size());
	if ( es->events.size() <= 1 ) {
		log_i("Not enough transitions to do anything useful");
		log_prog(NUM_STEPS,NUM_STEPS,"Early abort","No data");
		error = 1;
		return;
	}

	// STEP Ia : SEPARATE INTO CHUNKS
	log_prog(2,NUM_STEPS,"Separate Time Chunks","");
	chunks.push_back(inputTS->selectTime(inputTS->t[0],es->events[0].t));
	for ( size_t c = 0; c < es->events.size() - 1; c++) {
		chunks.push_back(inputTS->selectTime(es->events[c].t,es->events[c+1].t));
	}
	chunks.push_back(inputTS->selectTime(es->events[es->events.size()-1].t,inputTS->t[inputTS->t.size()-1]));

	if (csvout_fname.size() > 0) {
		TimeSeries * tsout = new TimeSeries();
		tsout->metadata.push_back(" Data separated into chunks via the transition detector");
		for (size_t c = 0; c < chunks.size(); c++) {
			tsout->insertPointAtEnd(chunks[c]->t[0],chunks[c]->mean());
		}
		CSVLoader::writeTStoCSV(csvout_fname,tsout,outprec);
		delete tsout;
	}


	if (statesin_fname.size() > 0 ) {
		// STEP Ib : ORDER CHUNKS BY SIZE
		log_prog(3,NUM_STEPS,"Order by Size","");
		sort(chunks.begin(), chunks.end(), cmp_by_timeseries_length);

		// STEP Ic : CATAGORIZE CHUNKS BY MEANS

		// start with biggest chunk in first bin
		chunk_bins.push_back(new vector<TimeSeries *>);
		chunk_bins[0]->push_back(chunks[0]);
		current_means.push_back(chunks[0]->mean());

		for ( int c = 1; c < chunks.size(); c++ ) {
			log_prog(4,NUM_STEPS,"Categorize by Means","%.2f%%",(100.0*c/chunks.size()));
			double chmean = chunks[c]->mean();

			// find the "closest" bin
			int minmean = 0;
			for ( int d = 1; d < chunk_bins.size(); d++ ) {
				if ( fabs(chmean - current_means[d]) < fabs(chmean - current_means[minmean]) ) {
					minmean = d;
				}
			}
			// if closest bin is too far off, create a new bin
			if ( current_means[minmean] / chmean > NEW_BIN_THRESH || chmean / current_means[minmean] > NEW_BIN_THRESH ) {
				chunk_bins.push_back(new vector<TimeSeries *>);
				chunk_bins.back()->push_back(chunks[c]);
				current_means.push_back(chmean);
			} else { // add to bin and update mean
				current_means[minmean] = (current_means[minmean] * chunk_bins[minmean]->size() + chmean) / (chunk_bins[minmean]->size() + 1);
				chunk_bins[minmean]->push_back(chunks[c]);
			}
		}

		for ( int c = 0; c < chunk_bins.size(); c++ ) {
			int varn = 0;
			double varsum = 0;
			double meansum = 0;
			for (int d = 0; d < chunk_bins[c]->size(); d++ ) {
				varn += chunk_bins[c]->at(d)->t.size();
			}
			current_ns.push_back(varn);
			// recalculate means
			for ( int d = 0; d < chunk_bins[c]->size(); d++ ) {
				meansum += chunk_bins[c]->at(d)->sum();
			}
			meansum = current_means[c] = meansum/varn;

			for (int d = 0; d < chunk_bins[c]->size(); d++ ) {
				varn += chunk_bins[c]->at(d)->t.size();
				for ( int e = 0; e < chunk_bins[c]->at(d)->t.size(); e++) {
					double tsq = chunk_bins[c]->at(d)->v[e] - meansum;
					varsum += tsq * tsq;
				}
			}
			current_variance.push_back(varsum / varn);
		}

		for ( int c = 0; c < chunk_bins.size(); c++ ) {
			log_i("Cluster %2d : Mean %10.2f  Variance %10.2f",c,current_means[c],current_variance[c]);
			for ( int d = 0; d < chunk_bins[c]->size(); d++) {
				log_i("\tChunk %3d: t:%10.2f mean:%10.2f",d,chunk_bins[c]->at(d)->t.front() - inputTS->t.front(),chunk_bins[c]->at(d)->mean());
			}
		}

		log_prog(5,NUM_STEPS,"Writing Output","");
		ofstream fout(statesin_fname.c_str());
		fout.precision(outprec);
		if ( !fout.is_open() ) {
			log_e("Cannot open file %s for writing: %s",statesin_fname.c_str(),strerror(errno));
			exit(2);
		}

		fout << "# Describes states and their statistical measurements"<<endl;
		fout<< "# State, sample size, Mean, Variance"<<endl;
		for ( int c = 0; c < chunk_bins.size(); c++ ){
			fout << c << "," << current_ns[c] << "," << current_means[c] << "," << current_variance[c] << endl;
		}
		fout.close();
	}



	cleanup:
	// cleanup
	while(!chunk_bins.empty()) delete chunk_bins.back(), chunk_bins.pop_back();
	while(!chunks.empty()) delete chunks.back(), chunks.pop_back();
	delete es;
	delete inputTS;
	delete inputRaw;

	log_i("Done.");
}
コード例 #22
0
ファイル: dijkstra.c プロジェクト: pgrz/porr
int *dijkstra_distance ( int ohd[vertex_count][vertex_count] )
{
    int *connected;
    int i;
    int my_min[2];
    int all_min[2];
    int *mind, *commonmind;
    int nth;
    int rc;

    connected = ( int * ) malloc ( vertex_count * sizeof ( int ) );

    connected[0] = 1;
    for ( i = 1; i < vertex_count; i++ )
    {
        connected[i] = 0;
    }

    mind = ( int * ) malloc ( vertex_count * sizeof ( int ) );
    commonmind = ( int * ) malloc ( vertex_count * sizeof ( int ) );

    for ( i = 0; i < vertex_count; i++ )
    {
        mind[i] = ohd[0][i];
    }

    my_first =   (   tid       * vertex_count ) / ntasks;
    my_last  =   ( ( tid + 1 ) * vertex_count ) / ntasks - 1;

    log_d(tid, "First=%d  Last=%d", my_first, my_last );

    for ( i = 1; i < vertex_count; i++ )
    {
        my_min[0] = INT_MAX;
        my_min[1] = -1;

        find_nearest ( mind, connected, my_min );

        if(MPI_Allreduce(my_min, all_min, 1, MPI_2INT, MPI_MINLOC, MPI_COMM_WORLD) != MPI_SUCCESS)
        {
            log_e(tid, "MPI_Allreduce failed!");
        }

        tid == 0 ? log_i(tid, "Common minimal node %d with distance %d", all_min[1], all_min[0]) : 0 ;

        if ( all_min[1] != -1 )
        {
            tid == 0 ? log_d(tid, "Connecting node %d", all_min[1]) : 0 ;

            connected[all_min[1]] = 1;
            update_mind ( all_min[1], connected, ohd, mind);
        }
        
        if(MPI_Allreduce(mind, commonmind, vertex_count, MPI_INT, MPI_MIN, MPI_COMM_WORLD) != MPI_SUCCESS)
        {
            log_e(tid, "MPI_Allreduce failed!");
        }

        for ( i = 0; i < vertex_count; i++ )
        {
            mind[i] = commonmind[i];
        }
    }

    free ( connected );
    free ( mind );

    return commonmind;
}
コード例 #23
0
ファイル: monitor_i2c.c プロジェクト: AlexandreN7/Liqui_lense
void monitor_i2c_Test(void)
{
  cmd_status_t result;
  int i;
  int j;
  sample_t* pData;

  monitor_i2c_Init();

  testCfg.clockrate = 100000;
  testCfg.bytesToCapture = 1000;
  circbuff_Init(&testBuffer, 0x20000000, testCfg.bytesToCapture * SAMPLE_SIZE);

  result = monitor_i2c_Configure(&testBuffer, &testCfg);
  if (result != CMD_STATUS_OK)
  {
    log_i("Failed to configure I2C monitor. Error code %d. Entering infinite loop...\r\n", result);
    while(1);
  }

  log_i("Starting I2C monitor...\r\n");
  j = 1;
  while (j--)
  {
    result = monitor_i2c_Start();
    if (result != CMD_STATUS_OK)
    {
      log_i("Failed to configure I2C monitor. Error code %d. Entering infinite loop...\r\n", result);
      break;
    }

    log_i("Got I2C data...\r\n");
    log_i("Timestamp  Data  Status  Extra\r\n");
    log_i("---------  ----  ------  -----\r\n");
    pData = (sample_t*)testBuffer.data;
    for (i = 0; i < testCfg.bytesToCapture; i++)
    {
      switch (pData[i].data)
      {
        case 0xc0:
        case 0xac:
          log_i("%9u  0x%02x   0x%02x   W:%02xh\r\n", pData[i].timestamp, pData[i].data, pData[i].status, pData[i].data>>1);
          break;

        case 0xc1:
        case 0xad:
          log_i("%9u  0x%02x   0x%02x   R:%02xh\r\n", pData[i].timestamp, pData[i].data, pData[i].status, pData[i].data>>1);
          break;

        default:
          log_i("%9u  0x%02x   0x%02x\r\n", pData[i].timestamp, pData[i].data, pData[i].status);
          break;
      }
      TIM_Waitms(2);// to prevent lost printouts
    }
  }
  if (j==0)
  {
    log_i("Done sampling, entering infinite loop...\r\n");
  }
  while(1);
}
コード例 #24
0
ファイル: shader.c プロジェクト: jtheoof/bina
unsigned int
shader_create_program(program_type_e type)
{
    GLuint vs = 0;
    GLuint fs = 0;
    GLuint program = glCreateProgram();
    GLint link_status;
    GLint length = 0;

    switch(type) {
      case PROGRAM_BACKGROUND:
        vs = shader_create_shader(GL_VERTEX_SHADER, background_vshader_g);
        fs = shader_create_shader(GL_FRAGMENT_SHADER, simpletex_fshader_g);
        break;
      case PROGRAM_CHARACTER:
        vs = shader_create_shader(GL_VERTEX_SHADER, character_vshader_g);
        fs = shader_create_shader(GL_FRAGMENT_SHADER, simpletex_fshader_g);
        break;
      default:
        log_e("program type: %d is not implemented", type);
        goto error;
    }

    if (!vs || !fs) {
        goto error;
    }

    if (program) {
        glAttachShader(program, vs);
        glAttachShader(program, fs);
        glLinkProgram(program);
        link_status = GL_FALSE;
        glGetProgramiv(program, GL_LINK_STATUS, &link_status);
        if (link_status != GL_TRUE) {
            length = 0;
            glGetProgramiv(program, GL_INFO_LOG_LENGTH, &length);
            if (length) {
                char* buf = (char*) malloc(length);
                if (buf) {
                    glGetProgramInfoLog(program, length, NULL, buf);
                    log_e("Could not link program: %s\n", buf);
                    free(buf);
                }
            }
            goto error;
        }
    } else {
        goto error;
    }

    GL_CHECK(glDeleteShader, vs);
    GL_CHECK(glDeleteShader, fs);

    log_i("Created program: %d", program);

    return program;

error:
    log_e("Could not create program: %d", type);

    glDeleteShader(vs);
    glDeleteShader(fs);
    glDeleteProgram(program);

    return 0;
}
コード例 #25
0
ファイル: debug.cpp プロジェクト: celeron55/buildat
void log_current_backtrace(const ss_ &title)
{
	log_i(MODULE, "Backtrace logging not implemented on Windows");
}