示例#1
0
int 
iter_bson(const bson_t *bson, ERL_NIF_TERM *out, decode_state *ds) 
{
    vec_term_t vec;
    bson_iter_t iter;
    int ret = 0;

    vec_init(&vec);
    ds->vec = &vec;

    if(!bson_iter_init(&iter, bson)) {
        goto finish;
    }
    if(bson_iter_visit_all(&iter, &decode_visitors, ds) || 
            iter.err_off) {
        goto finish;
    }
    if(!make_document(ds->env, ds->vec, out, ds->return_maps)) {
        goto finish;
    }
    ret = 1;

finish:
    vec_deinit(&vec);
    ds->vec = NULL;
    return ret;
}
示例#2
0
ssize_t			tokenize(const char *string,
				 struct s_vec *queue)
{
  size_t		i;
  size_t		len;
  struct s_token	*token;

  assert(string != NULL);
  assert(queue != NULL);
  if (vec_init(queue, 0, &free_token_queue) == -1)
    return (-1);
  len = strlen(string);
  i = 0;
  while (i < len)
    {
      if (string[i] == ' ' || string[i] == '\t')
	{
	  ++i;
	  continue;
	}
      if (token_new(&token) != 0 || token_init(token) != 0)
	return (-1);
      if (!call_tokenizers(string, queue, token, &i))
	i += 1;
    }
  return (queue->size);
}
示例#3
0
文件: vec.c 项目: FredFoonly/poe
struct vec_t* vec_alloc(int capacity, size_t element_size)
{
  TRACE_ENTER;
  struct vec_t* v = calloc(1, sizeof(struct vec_t));
  vec_init(v, element_size, capacity);
  TRACE_RETURN(v);
}
int test() {
	vector * vec = (vector *) malloc(sizeof(struct vector));
	vec_init(vec, 50);
	int i;

	for (i = 0; i < 14; i++) {
		vec_push(vec, i * 4 + 2);
	}

	vec_set(vec, 0, 1);
	printf("capacity = %zd, %zd\n", vec->capacity, vec->size);
	vec_set(vec, 39, 1);
	printf("capacity = %zd, %zd\n", vec->capacity, vec->size);
	vec_set(vec, 19, 2);
	printf("capacity = %zd, %zd\n", vec->capacity, vec->size);
	vec_set(vec, 45, 2);
	printf("capacity = %zd, %zd\n", vec->capacity, vec->size);

	printf("vec[3] = %d\n", vec_get(vec, 3));
	printf("vec[6] = %d\n", vec_get(vec, 6));
	printf("vec[666] = %d\n", vec_get(vec, 666));

	for (size_t i = 0; i < vec->size; i++) {
		printf("vec[%zd] = %d\n", i, vec->data[i]);
	}

	vec_free(vec);

	return 0;
}
示例#5
0
double kat_mul(const kat_matrix_t *a, const vm_t *b, vm_t **c,
		char flag /* unused */) {

	double start_time;
	double end_time;

	switch (b->type) {
	case VEC:
		assert(a->_.w == b->h);
		vec_init((vec_t **) c, a->_.w);
		start_time = omp_get_wtime();
		mul_katnode_vec(a, (vec_t *) b, a->root, (vec_t *) *c);
		end_time = omp_get_wtime();
		break;
	case KAT:
		assert(a->_.w == b->w);
		assert(a->_.h == b->h);
		den_matrix_init((den_matrix_t **) c, a->_.w, b->w, 1);
		start_time = omp_get_wtime();
		kat_node_mul(a, (kat_matrix_t *) b, a->root, ((kat_matrix_t*) b)->root,
				(den_matrix_t *) *c);
		end_time = omp_get_wtime();
		break;
	default:
		fprintf(stderr, "Unknown matrix type: %d\n", b->type);
		exit(1);
		return 0.;
	}

	return end_time - start_time;
}
/**
* Main function
*
* @param argc
* @param argv
*/
int main(int argc, char **argv)
{
    // create PAPI routines
    PapiCounterList papi_routines;
    papi_routines.AddRoutine("matvec");

    // allocate arrays
    float a[ROWS][COLS];
    float b[COLS];
    float c[ROWS] = {0.0f};

    printf("Rows: %d\n", ROWS);
    printf("Cols: %d\n", COLS);
    printf("Runs: %d\n", RUNS);

    // initialize matrix & vector
    mat_init(ROWS, COLS, 1.0, a);
    vec_init(COLS, 3.0, b);

    // do the measurement
    papi_routines["matvec"].Start();
    for (unsigned i = 0; i < RUNS; i++)
        mat_vec_mul(ROWS, COLS, a, b, c);
    papi_routines["matvec"].Stop();

    // print results
    printf("Control sum: %f\n", vec_sum(ROWS, c));
    printf("\n");
    papi_routines.PrintScreen();

    return EXIT_SUCCESS;
}
示例#7
0
int main(void)
{
  int i, num_jobs;
  process_pool *pool;
  vec(job_t) cq;
  vec_init(&cq);

  num_jobs = 10000;
  for (i = 0; i < num_jobs; i++) {
    job_t jobs = {"Yhm, Forever!", i};
    vec_push(&cq, jobs);
  }

  printf("Master[%d] Runnig\n", getpid());


  process_pool_envinit();
  pool = process_pool_new(3);
  process_pool_start(pool);

  for (i= 0; i < num_jobs; i++) {
    process_pool_dispatch(pool, &cq.data[i]);
  }

  wait(NULL);

  vec_deinit(&cq);

  return 0;
}
示例#8
0
void KSKIPCR_Init(double *v1, double *v2, double *v3, double *v4, double *v5, double *v6, double *v7, double *v8, double *v9, int N, int kskip)
{
  vec_init(v1, 0.0, (2*kskip+1)*N);
  vec_init(v2, 0.0, (2*kskip+1)*N);
  vec_init(v3, 0.0, (2*kskip+1)*N);
  vec_init(v4, 0.0, (2*kskip+1)*N);
  vec_init(v5, 0.0, (2*kskip+1)*N);

  vec_init(v6, 0.0, N);
  vec_init(v7, 0.0, N);
  vec_init(v8, 0.0, N);
  vec_init(v9, 0.0, N);
}
/**
* Main function
*
* @param argc
* @param argv
*/
int main(int argc, char **argv)
{
    // allocate matrix
    float *A = (float*)_mm_malloc(ROWS * COLS * sizeof(float), 64);
    if(A == NULL)
    {
        fprintf(stderr, "_mm_malloc error !\n");
        return EXIT_FAILURE;
    }

    // allocate vectors
    float *B = (float*)_mm_malloc(COLS * sizeof(float), 64);
    if(A == NULL)
    {
        fprintf(stderr, "_mm_malloc error !\n");
        _mm_free(A);
        return EXIT_FAILURE;
    }

    float *C = (float*)_mm_malloc(ROWS * sizeof(float), 64);
    if(A == NULL)
    {
        fprintf(stderr, "_mm_malloc error !\n");
        _mm_free(A);
        _mm_free(B);
        return EXIT_FAILURE;
    }

    printf("Rows: %d\n", ROWS);
    printf("Cols: %d\n", COLS);
    printf("Runs: %d\n", RUNS);

    // initialize matrix & vector
    const double tstart = omp_get_wtime();

    mat_init(ROWS, COLS, 1.0, A);
    vec_init(COLS, 3.0, B);

    const double tinit = omp_get_wtime();
    // do the measurement
    for(unsigned i = 0; i < RUNS; i++)
    {
        mat_vec_mul(ROWS, COLS, A, B, C);
    }
    const double tcalc = omp_get_wtime();

    // print results
    printf("Control sum: %f\n", vec_sum(ROWS, C));
    printf("Time Initialization: %0.3f\n", tinit - tstart);
    printf("Time Calculation: %0.3f\n", tcalc - tinit);
    printf("Time Total: %0.3f\n", tcalc - tstart);

    // free memory
    _mm_free(A);
    _mm_free(B);
    _mm_free(C);

    return EXIT_SUCCESS;
}
示例#10
0
文件: vec.c 项目: FredFoonly/poe
void vec_initfrom(struct vec_t* dst, const struct vec_t* src)
{
  TRACE_ENTER;
  vec_init(dst, src->eltsize, src->cap);
  if (src->ct > 0)
    memmove(dst->elts, src->elts, src->ct*src->eltsize);
  dst->ct = src->ct;
  TRACE_EXIT;
}
示例#11
0
文件: ide.c 项目: jb55/vpl
/**
 *  IDE initialization
 */
void
vpl_ide_init(struct vpl_ide *ide) {
  ide->interact_state = VPL_NSTATE_IDLE;
  ide->active_hit_x = 0;
  ide->active_hit_y = 0;
  ide->active_node  = 0;
  ide->num_nodes    = 0;
  vec_init(&ide->vec_wires);
}
示例#12
0
文件: namevec.c 项目: Xeom/edil
void namevec_init(vec *v, namevec_item *items, size_t bytes)
{
    size_t n;
    n = bytes / sizeof(namevec_item);

    vec_init(v, sizeof(namevec_item));
    vec_ins(v, 0, n, items);
    vec_sort(v, namevec_cmp);
}
示例#13
0
int primelister(unsigned int primes) {
  // Init
  //unsigned long *primeArr = calloc(primes, sizeof(unsigned long)); primeArr[0] = 2;
  vec **arr = calloc(primes, sizeof(vec *));
  if (NULL == arr) {printf("Memory error!"); exit(0);}
  unsigned int pos = 1;
  arr[0] = vec_init(2llu);
  unsigned long long prevnum = 0llu, num = 1llu;

  //printf("%u, %u \n", pos, primes);
  
  printf("2, ");
  // Algorithm
  while (pos < primes) {
    prevnum = num;
    num = 1llu;
    for (int p = 0; arr[p] != NULL; ++p) {
      unsigned int exp = vec_getNextExp(arr[p]);
      num *= powll(arr[p]->prime, exp);
      //printf(" ..:: %llu^%u, thus num = %llu.\n", arr[p]->prime, exp, num);
    }
    if (1 == num) {
      // We found a new prime with value prevnum+1
      unsigned long long newPrime = prevnum + 1;
      //printf("this is what we have, prevnum:%llu . num:%llu . newPrime:%llu and %llu\n", prevnum, num, prevnum+1, newPrime);
      num = newPrime;
      arr[pos] = vec_init(newPrime);
      (void) vec_getNextExp(arr[pos]);
      ++pos;
      // Print new prime
      printf("%llu, ", newPrime);
    } //printf("prevnum: %llu, num; %llu - - \n", prevnum, num);
  }
  puts("");
  // Fin
  for (unsigned long i = 0; i < primes; ++i) {
    free(arr[i]->arr);
    free(arr[i]);
  }
  free(arr);
  return 0;
}
示例#14
0
END_TEST

START_TEST(test_vec_init)
{
    int i;
    vec3d p;
    vec_init(p);

    for (i = 0; i < 3; i++)
        fail_unless(is_empty(p[i]));
}
示例#15
0
struct atom *new_exprs(struct expr *arg)
{
    struct atom *atom;

    atom = chunkpool_malloc(s->atom_pool);
    atom->type = ATOM_TYPE_EXPRS;
    atom->u.exprs = chunkpool_malloc(s->vec_pool);
    vec_init(atom->u.exprs, sizeof(struct expr*));
    exprs_add(atom, arg);
    return atom;
}
示例#16
0
int main(int argc, char *argv[]) {
  vec *vector = vec_init(sizeof(int), 10);
  
  for (int x=0; x<66; x++) {
    if (!vec_push(vector, &x)) {
      printf("Error adding element");
      exit(-1);
    }
    printf("Adding %i to a vec of size %i\n", x, vector->elems);
  }
  for (int x=0; x < vector->elems; x++) {
    printf("%i, %d\n", x, *(int*)vec_get(vector, x));
  }
}
示例#17
0
double bsr_mul(const bsr_t *a, const vm_t *b, vm_t **c, char flag /* unused */) {

	switch (b->type) {
	case VEC:
		vec_init((vec_t **) c, a->_.w);
		return mul_bsr_vec(a, (vec_t *) b, (vec_t *) *c);
	case BSR:
		den_matrix_init((den_matrix_t **) c, a->_.w, b->h, 1);
		return mul_bsr_bsr(a, (bsr_t *) b, (den_matrix_t *) *c);
	default:
		fprintf(stderr, "Unknown matrix type: %d\n", b->type);
		exit(1);
		return 0.;
	}
}
示例#18
0
settings_t* settings_init()
{
	settings_t* rv = malloc(sizeof(settings_t));
	if (rv)
	{
		rv->start = 0;
		rv->stop = 0;
		rv->dir = 0;
		vec_init((void**)&rv->black_list, sizeof(char *), 0, 10);
		rv->report_type = report_type_txt;
		rv->use_orb_file = 1;
		rv->orb_file = 0;
	}
	return rv;
}
示例#19
0
文件: state.c 项目: ysm001/slim
Transition transition_make(State *s, lmn_interned_str rule_name)
{
  struct Transition *t = LMN_MALLOC(struct Transition);

  t->s    = s;
  t->id   = 0;
  t->cost = 0;
  vec_init(&t->rule_names, 4);
  vec_push(&t->rule_names, rule_name);
#ifdef PROFILE
  if (lmn_env.profile_level >= 3) {
    profile_add_space(PROFILE_SPACE__TRANS_OBJECT, transition_space(t));
  }
#endif
  return t;
}
示例#20
0
int main() {
	int n = 10, i;                   
	pvec v1;
	int* it = NULL;
	vec_init(&v1, sizeof(int), NULL );
	for(i = 0; i < 20; i++) {
		vec_push(v1, &i);                          
	    vec_debugi(v1);
	}                                        
	vec_debugi(v1);
	vec_release(v1);
	for(it = (int*)vec_begin(v); it != (int*)vec_end(); it++) {
		printf("%d ",*it); 
	}

	return 0;
}
示例#21
0
int InitializeMultiplexer(void)
{
	EpollHandle = epoll_create(4);

	if (EpollHandle == -1)
		return -1;

	vec_init(&events);

	// Default of 5 events, it will expand if we get more sockets
	vec_reserve(&events, 5);

	if (errno == ENOMEM)
		return -1;

	return 0;
}
示例#22
0
void script_bind_iup(script_t* script, int argc, char** argv)
{
	vec_init(&g_all_cb_data, sizeof(cb_data_t*));
	
	IupOpen(&argc, &argv);
	
	script_bind_extern(script, "iup_label", ext_iup_label);
	script_bind_extern(script, "iup_button", ext_iup_button);
	script_bind_extern(script, "iup_vbox", ext_iup_vbox);
	script_bind_extern(script, "iup_append", ext_iup_append);
	script_bind_extern(script, "iup_dialog", ext_iup_dialog);
	script_bind_extern(script, "iup_set_attribute", ext_iup_set_attribute);
	script_bind_extern(script, "iup_set_callback", ext_iup_set_callback);
	script_bind_extern(script, "iup_map", ext_iup_map);
	script_bind_extern(script, "iup_show_xy", ext_iup_show_xy);
	script_bind_extern(script, "iup_refresh", ext_iup_refresh);
	script_bind_extern(script, "iup_main_loop", ext_iup_main_loop);
	script_bind_extern(script, "iup_close", ext_iup_close);
}
示例#23
0
文件: gc.c 项目: 9thScientist/SO
int global_clean() {

	char aux_path[PATH_SIZE], aux[CHUNK_SIZE];
	vec_str_t files;
	int i;

	strncpy(aux_path, getenv("HOME"), PATH_SIZE);
	strncat(aux_path, DATA_PATH, PATH_SIZE);

	vec_init(&files);
	fill_vec(aux_path, aux, CHUNK_SIZE, &files);

	for (i = 0; i < files.length; i++) {

		if (!is_linked(files.data[i]))  
			unlink(files.data[i]);
	}

	return 0;
}
void update_dangling_pages(web *w, size_t origin_size) {
	vector *dangling_pages = malloc(sizeof(struct vector));
	vec_init(dangling_pages, w->dangling_pages->size);
	size_t i;
	int page_id;
	
	// check origin dangling pages
	for (i = 0; i < w->dangling_pages->size; ++i) {
		page_id = vec_get(w->dangling_pages, i);
		if (w->webnodes[page_id]->out_links_num == 0)
			vec_push(dangling_pages, page_id);
	}
	// check new added pages
	for (i = origin_size; i < w->size; ++i) {
		if (w->webnodes[i]->out_links_num == 0)
			vec_push(dangling_pages, i);
	}
	free(w->dangling_pages);
	w->dangling_pages = dangling_pages;
}
示例#25
0
static void ext_iup_vbox(script_t* script, vector_t* args)
{
	vector_t* array = &script_get_arg(args, 0)->array;
	vector_t handle_array;
	
	vec_init(&handle_array, sizeof(Ihandle*));
	vec_reserve(&handle_array, array->length + 1);
	
	for(int i = 0; i < array->length; ++i)
	{
		script_value_t* val = vec_get_value(array, i, script_value_t*);
		vec_push_back(&handle_array, &val->nat.value);
	}
	Ihandle* null_handle = NULL;
	vec_push_back(&handle_array, &null_handle); 
	
	Ihandle* vbox = IupVboxv((Ihandle**)handle_array.data);
	vec_destroy(&handle_array);
	
	script_push_native(script, vbox, NULL, iup_handle_free);
	script_return_top(script);
}
示例#26
0
static bool
decode_visit_array(const bson_iter_t *iter,
                   const char        *key,
                   const bson_t      *v_array,
                   void              *data)
{
    decode_state *ds = data;
    decode_state  cs;
    vec_term_t    vec;
    bson_iter_t   child;
    ERL_NIF_TERM  out;

    LOG("visit array: %s \r\n", key);

    if(ds->depth >= MAX_DEPTHS) {
        return true;
    }

    init_child_state(ds, &cs);
    cs.keys  = false;
    cs.depth = ds->depth + 1; 
    if(!bson_iter_init(&child, v_array)) {
        return true;
    }
    vec_init(&vec);
    cs.vec = &vec;

    if(bson_iter_visit_all(&child, &decode_visitors, &cs) ||
            child.err_off) {
        vec_deinit(&vec);
        return true;
    }
    out = enif_make_list_from_array(cs.env, cs.vec->data, cs.vec->length);
    vec_deinit(&vec);
    vec_push(ds->vec, out);

    return false;
}
示例#27
0
文件: split.c 项目: brendan-rius/12sh
int	string_split_str(const struct s_string *string,
			 const char *pattern,
			 struct s_vec *matches)
{
  char	*copy;
  char	*token;

  assert(string != NULL);
  assert(pattern != NULL);
  assert(matches != NULL);
  copy = string->_string;
  token = strsep(&copy, pattern);
  if (vec_init(matches, 0, &string_delete) == -1)
    return (-1);
  while (copy != NULL)
    {
      if (push_to_vec(matches, token) == -1)
	return (vec_empty(matches), -1);
      token = strsep(&copy, pattern);
    }
  if (push_to_vec(matches, token) == -1)
    return (vec_empty(matches), -1);
  return (0);
}
示例#28
0
int main(int argc, char *argv[])
{
    struct vector v;
    int i = 0;
    int *p;

    vec_init(&v, sizeof(int), 0, realloc);

    vec_push(&v, &i);
    i = 1;
    vec_push(&v, &i);

    vec_shrink(&v);
    vec_swap(&v, 0, 1);

    p = vec_get(&v, 0);
    assert(*p == 1);
    p = vec_get(&v, 1);
    assert(*p == 0);

    vec_destroy(&v);

    return 0;
}
示例#29
0
clock_t alu3(_fhe_int *into,_fhe_int *opcode,fhe_int_t carry,
		_fhe_int *op1, _fhe_int *op2,fhe_pk_t pk,fhe_sk_t sk)
{
	clock_t _clock;
	_fhe_int *or;
	_fhe_int *xor;
	_fhe_int *and;
	_fhe_int *add;
	_fhe_int *nopcode;
	fhe_int_t temp;
	fhe_int_t sel_or;
	fhe_int_t sel_xor;
	fhe_int_t sel_and;
	fhe_int_t sel_add;

	_clock=clock();

	nopcode=vec_init(2);
	for(int i=0;i<2;i++)
	{
		fhe_int_not(&nopcode[i],&opcode[i],pk);
	}

	or=vec_init(DATA_BITS);
	xor=vec_init(DATA_BITS);
	and=vec_init(DATA_BITS);
	add=vec_init(DATA_BITS+1);
	fhe_int_init(temp);
	fhe_int_init(sel_or);
	fhe_int_init(sel_xor);
	fhe_int_init(sel_and);
	fhe_int_init(sel_add);

	for(int i=0;i<DATA_BITS;i++)
		fhe_int_encrypt(&into[i],pk,0);

	fhe_int_and(sel_or,&nopcode[0],&nopcode[1],pk);
	fhe_int_and(sel_xor,&opcode[0],&nopcode[1],pk);
	fhe_int_and(sel_and,&nopcode[0],&opcode[1],pk);
	fhe_int_and(sel_add,&opcode[0],&opcode[1],pk);

	for(int i=0;i<DATA_BITS;i++)
	{
		fhe_int_xor(&xor[i],&op1[i],&op2[i],pk); //xor
		fhe_int_and(&and[i],&op1[i],&op2[i],pk); //and
		fhe_int_xor(&or[i],&xor[i],&and[i],pk);  //or

		fhe_int_xor(&add[i],&xor[i],carry,pk);   //rc-add
		fhe_int_and(temp,&xor[i],carry,pk);
		fhe_int_or(carry,temp,&and[i],pk);

		fhe_int_and(temp,&or[i],sel_or,pk);		 //select output
		fhe_int_xor(&into[i],&into[i],temp,pk);
		fhe_int_and(temp,&xor[i],sel_xor,pk);
		fhe_int_xor(&into[i],&into[i],temp,pk);
		fhe_int_and(temp,&and[i],sel_and,pk);
		fhe_int_xor(&into[i],&into[i],temp,pk);
		fhe_int_and(temp,&add[i],sel_add,pk);
		fhe_int_xor(&into[i],&into[i],temp,pk);
	}

	vec_clear(or,DATA_BITS);
	vec_clear(xor,DATA_BITS);
	vec_clear(and,DATA_BITS);
	vec_clear(add,DATA_BITS);
	fhe_int_clear(temp);
	fhe_int_clear(sel_or);
	fhe_int_clear(sel_xor);
	fhe_int_clear(sel_and);
	fhe_int_clear(sel_add);

	return clock()-_clock;
}
示例#30
0
文件: track.c 项目: yosefm/openptv
/*     track backwards */
double trackback_c (tracking_run *run_info, int step)
{
    int i, j, h, in_volume = 0;
    int philf[4][MAX_CANDS];
    int count1 = 0, count2 = 0, num_added = 0;
    int quali = 0;
    double angle, acc, dl;
    vec3d diff_pos, X[6];     /* 6 reference points used in the algorithm */
    vec2d n[4], v2[4];     // replaces xn,yn, x2[4], y2[4],
    double rr, Ymin = 0, Ymax = 0;
    double npart = 0, nlinks = 0;
    foundpix *w;

    sequence_par *seq_par;
    track_par *tpar;
    volume_par *vpar;
    control_par *cpar;
    framebuf *fb;
    Calibration **cal;

    /* Shortcuts to inside current frame */
    P *curr_path_inf, *ref_path_inf;

    /* shortcuts */
    cal = run_info->cal;
    seq_par = run_info->seq_par;
    tpar = run_info->tpar;
    vpar = run_info->vpar;
    cpar = run_info->cpar;

    fb = run_info->fb;

    /* Prime the buffer with first frames */
    for (step = seq_par->last; step > seq_par->last - 4; step--) {
        fb_read_frame_at_end(fb, step, 1);
        fb_next(fb);
    }
    fb_prev(fb);

    /* sequence loop */
    for (step = seq_par->last - 1; step > seq_par->first; step--) {
        printf ("Time step: %d, seqnr: %d:\n",
                step - seq_par->first, step);

        for (h = 0; h < fb->buf[1]->num_parts; h++) {
            curr_path_inf = &(fb->buf[1]->path_info[h]);

            /* We try to find link only if the forward search failed to. */
            if ((curr_path_inf->next < 0) || (curr_path_inf->prev != -1)) continue;

            for (j = 0; j < 6; j++) vec_init(X[j]);
            curr_path_inf->inlist = 0;

            /* 3D-position of current particle */
            vec_copy(X[1], curr_path_inf->x);

            /* use information from previous to locate new search position
               and to calculate values for search area */
            ref_path_inf = &(fb->buf[0]->path_info[curr_path_inf->next]);
            vec_copy(X[0], ref_path_inf->x);
            search_volume_center_moving(ref_path_inf->x, curr_path_inf->x, X[2]);
            
            for (j = 0; j < fb->num_cams; j++) {
                point_to_pixel (n[j], X[2], cal[j], cpar);
            }
            
            /* calculate searchquader and reprojection in image space */
            w = sorted_candidates_in_volume(X[2], n, fb->buf[2], run_info);
            
            if (w != NULL) {
                count2++;

                i = 0;
                while (w[i].ftnr != TR_UNUSED) {
                    ref_path_inf = &(fb->buf[2]->path_info[w[i].ftnr]);
                    vec_copy(X[3], ref_path_inf->x);

                    vec_subt(X[1], X[3], diff_pos);
                    if (pos3d_in_bounds(diff_pos, tpar)) {
                        angle_acc(X[1], X[2], X[3], &angle, &acc);

                        /* *********************check link *****************************/
                        if ((acc < tpar->dacc && angle < tpar->dangle) || \
                            (acc < tpar->dacc/10))
                        {
                            dl = (vec_diff_norm(X[1], X[3]) +
                                  vec_diff_norm(X[0], X[1]) )/2;
                            quali = w[i].freq;
                            rr = (dl/run_info->lmax + acc/tpar->dacc + \
                                angle/tpar->dangle)/quali;
                            register_link_candidate(curr_path_inf, rr, w[i].ftnr);
                        }
                    }
                    i++;
                }
            }

            free(w);

            /* if old wasn't found try to create new particle position from rest */
            if (tpar->add) {
                if ( curr_path_inf->inlist == 0) {
                    quali = assess_new_position(X[2], v2, philf, fb->buf[2], run_info);
                    if (quali>=2) {
                        //vec_copy(X[3], X[2]);
                        in_volume = 0;

                        point_position(v2, fb->num_cams, cpar->mm, cal, X[3]);

                        /* volume check */
                        if ( vpar->X_lay[0] < X[3][0] && X[3][0] < vpar->X_lay[1] &&
                             Ymin < X[3][1] && X[3][1] < Ymax &&
                             vpar->Zmin_lay[0] < X[3][2] && X[3][2] < vpar->Zmax_lay[1])
                        {in_volume = 1;}

                        vec_subt(X[1], X[3], diff_pos);
                        if (in_volume == 1 && pos3d_in_bounds(diff_pos, tpar)) {
                            angle_acc(X[1], X[2], X[3], &angle, &acc);

                            if ( (acc<tpar->dacc && angle<tpar->dangle) || \
                                 (acc<tpar->dacc/10) )
                            {
                                dl = (vec_diff_norm(X[1], X[3]) +
                                      vec_diff_norm(X[0], X[1]) )/2;
                                rr = (dl/run_info->lmax+acc/tpar->dacc + angle/tpar->dangle)/(quali);
                                register_link_candidate(curr_path_inf, rr, fb->buf[2]->num_parts);

                                add_particle(fb->buf[2], X[3], philf);
                            }
                        }
                        in_volume = 0;
                    }
                }
            }             /* end of if old wasn't found try to create new particle position from rest */
        }         /* end of h-loop */

        for (h = 0; h < fb->buf[1]->num_parts; h++) {
            curr_path_inf = &(fb->buf[1]->path_info[h]);

            if(curr_path_inf->inlist > 0 ) {
                sort(curr_path_inf->inlist, (float *)curr_path_inf->decis,
                     curr_path_inf->linkdecis);
            }
        }

        /* create links with decision check */
        count1 = 0; num_added = 0;
        for (h = 0; h < fb->buf[1]->num_parts; h++) {
            curr_path_inf = &(fb->buf[1]->path_info[h]);

            if (curr_path_inf->inlist > 0 ) {
                /* if old/new and unused prev == -1 and next == -2 link is created */
                ref_path_inf = &(fb->buf[2]->path_info[curr_path_inf->linkdecis[0]]);

                if ( ref_path_inf->prev == PREV_NONE && \
                     ref_path_inf->next == NEXT_NONE )
                {
                    curr_path_inf->finaldecis = curr_path_inf->decis[0];
                    curr_path_inf->prev = curr_path_inf->linkdecis[0];
                    fb->buf[2]->path_info[curr_path_inf->prev].next = h;
                    num_added++;
                }

                /* old which link to prev has to be checked */
                if ((ref_path_inf->prev != PREV_NONE) && \
                    (ref_path_inf->next == NEXT_NONE) )
                {
                    vec_copy(X[0], fb->buf[0]->path_info[curr_path_inf->next].x);
                    vec_copy(X[1], curr_path_inf->x);
                    vec_copy(X[3], ref_path_inf->x);
                    vec_copy(X[4], fb->buf[3]->path_info[ref_path_inf->prev].x);
                    for (j = 0; j < 3; j++)
                        X[5][j] = 0.5*(5.0*X[3][j] - 4.0*X[1][j] + X[0][j]);

                    angle_acc(X[3], X[4], X[5], &angle, &acc);

                    if ( (acc<tpar->dacc && angle<tpar->dangle) ||  (acc<tpar->dacc/10) ) {
                        curr_path_inf->finaldecis = curr_path_inf->decis[0];
                        curr_path_inf->prev = curr_path_inf->linkdecis[0];
                        fb->buf[2]->path_info[curr_path_inf->prev].next = h;
                        num_added++;
                    }
                }
            }

            if (curr_path_inf->prev != PREV_NONE ) count1++;
        }         /* end of creation of links with decision check */

        printf ("step: %d, curr: %d, next: %d, links: %d, lost: %d, add: %d",
                step, fb->buf[1]->num_parts, fb->buf[2]->num_parts, count1,
                fb->buf[1]->num_parts - count1, num_added);

        /* for the average of particles and links */
        npart = npart + fb->buf[1]->num_parts;
        nlinks = nlinks + count1;

        fb_next(fb);
        fb_write_frame_from_start(fb, step);
        if(step > seq_par->first + 2) { fb_read_frame_at_end(fb, step - 3, 1); }
    }     /* end of sequence loop */

    /* average of all steps */
    npart /= (seq_par->last - seq_par->first - 1);
    nlinks /= (seq_par->last - seq_par->first - 1);

    printf ("Average over sequence, particles: %5.1f, links: %5.1f, lost: %5.1f\n",
            npart, nlinks, npart-nlinks);

    fb_next(fb);
    fb_write_frame_from_start(fb, step);

    fb_free(fb);
    free(fb);
    free(tpar);

    return nlinks;
}