예제 #1
0
파일: vf_deband.c 프로젝트: 0day-ci/FFmpeg
static int deband_16_c(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
{
    DebandContext *s = ctx->priv;
    ThreadData *td = arg;
    AVFrame *in = td->in;
    AVFrame *out = td->out;
    int x, y, p;

    for (p = 0; p < s->nb_components; p++) {
        const uint16_t *src_ptr = (const uint16_t *)in->data[p];
        uint16_t *dst_ptr = (uint16_t *)out->data[p];
        const int dst_linesize = out->linesize[p] / 2;
        const int src_linesize = in->linesize[p] / 2;
        const int thr = s->thr[p];
        const int start = (s->planeheight[p] *  jobnr   ) / nb_jobs;
        const int end   = (s->planeheight[p] * (jobnr+1)) / nb_jobs;
        const int w = s->planewidth[p] - 1;
        const int h = s->planeheight[p] - 1;

        for (y = start; y < end; y++) {
            const int pos = y * s->planeheight[0];

            for (x = 0; x < s->planewidth[p]; x++) {
                const int x_pos = s->x_pos[pos + x];
                const int y_pos = s->y_pos[pos + x];
                const int ref0 = src_ptr[av_clip(y +  y_pos, 0, h) * src_linesize + av_clip(x +  x_pos, 0, w)];
                const int ref1 = src_ptr[av_clip(y + -y_pos, 0, h) * src_linesize + av_clip(x +  x_pos, 0, w)];
                const int ref2 = src_ptr[av_clip(y + -y_pos, 0, h) * src_linesize + av_clip(x + -x_pos, 0, w)];
                const int ref3 = src_ptr[av_clip(y +  y_pos, 0, h) * src_linesize + av_clip(x + -x_pos, 0, w)];
                const int src0 = src_ptr[y * src_linesize + x];

                if (s->blur) {
                    const int avg = get_avg(ref0, ref1, ref2, ref3);
                    const int diff = FFABS(src0 - avg);

                    dst_ptr[y * dst_linesize + x] = diff < thr ? avg : src0;
                } else {
                    dst_ptr[y * dst_linesize + x] = (FFABS(src0 - ref0) < thr) &&
                                                    (FFABS(src0 - ref1) < thr) &&
                                                    (FFABS(src0 - ref2) < thr) &&
                                                    (FFABS(src0 - ref3) < thr) ? get_avg(ref0, ref1, ref2, ref3) : src0;
                }
            }
        }
    }

    return 0;
}
예제 #2
0
static pa_cvolume* set_balance(pa_cvolume *v, const pa_channel_map *map, float new_balance,
                               bool (*on_l)(pa_channel_position_t), bool (*on_r)(pa_channel_position_t)) {

    pa_volume_t left, nleft, right, nright, m;
    unsigned c;

    get_avg(map, v, &left, &right, on_l, on_r);

    m = PA_MAX(left, right);

    if (new_balance <= 0) {
        nright = (new_balance + 1.0f) * m;
        nleft = m;
    } else {
        nleft = (1.0f - new_balance) * m;
        nright = m;
    }

    for (c = 0; c < map->channels; c++) {
        if (on_l(map->map[c])) {
            if (left == 0)
                v->values[c] = nleft;
            else
                v->values[c] = (pa_volume_t) PA_CLAMP_VOLUME(((uint64_t) v->values[c] * (uint64_t) nleft) / (uint64_t) left);
        } else if (on_r(map->map[c])) {
            if (right == 0)
                v->values[c] = nright;
            else
                v->values[c] = (pa_volume_t) PA_CLAMP_VOLUME(((uint64_t) v->values[c] * (uint64_t) nright) / (uint64_t) right);
        }
    }

    return v;
}
예제 #3
0
float pa_cvolume_get_balance(const pa_cvolume *v, const pa_channel_map *map) {
    pa_volume_t left, right;

    pa_assert(v);
    pa_assert(map);

    pa_return_val_if_fail(pa_cvolume_compatible_with_channel_map(v, map), 0.0f);

    if (!pa_channel_map_can_balance(map))
        return 0.0f;

    get_avg(map, v, &left, &right, on_left, on_right);

    if (left == right)
        return 0.0f;

    /*   1.0,  0.0  =>  -1.0
         0.0,  1.0  =>   1.0
         0.0,  0.0  =>   0.0
         0.5,  0.5  =>   0.0
         1.0,  0.5  =>  -0.5
         1.0,  0.25 => -0.75
         0.75, 0.25 => -0.66
         0.5,  0.25 => -0.5   */

    if (left > right)
        return -1.0f + ((float) right / (float) left);
    else
        return 1.0f - ((float) left / (float) right);
}
/*
  Compute the standard deviation of the set of measurements <data>.
*/
double get_std(double data[], int32_t no_values)
{
   int32_t i;
   double sum_, mean;
   mean = get_avg(data, no_values);
   sum_ = 0;
   for (i=0; i<no_values; i++) sum_ += pow(data[i]-mean, 2.);
   return sqrt(sum_ / (double)(no_values-1));
}
예제 #5
0
/*
 * Do a single performance test, of one type of operation.
 *
 * @param h
 *   hash table to run test on
 * @param func
 *   function to call (add, delete or lookup function)
 * @param avg_occupancy
 *   The average number of entries in each bucket of the hash table
 * @param invalid_pos_count
 *   The amount of errors (e.g. due to a full bucket).
 * @return
 *   The average number of ticks per hash function call. A negative number
 *   signifies failure.
 */
static double
run_single_tbl_perf_test(const struct rte_hash *h, hash_operation func,
		const struct tbl_perf_test_params *params, double *avg_occupancy,
		uint32_t *invalid_pos_count)
{
	uint64_t begin, end, ticks = 0;
	uint8_t *key = NULL;
	uint32_t *bucket_occupancies = NULL;
	uint32_t num_buckets, i, j;
	int32_t pos;

	/* Initialise */
	num_buckets = params->entries / params->bucket_entries;
	key = (uint8_t *) rte_zmalloc("hash key",
			params->key_len * sizeof(uint8_t), 16);
	if (key == NULL)
		return -1;

	bucket_occupancies = (uint32_t *) rte_zmalloc("bucket occupancies",
			num_buckets * sizeof(uint32_t), 16);
	if (bucket_occupancies == NULL) {
		rte_free(key);
		return -1;
	}

	ticks = 0;
	*invalid_pos_count = 0;

	for (i = 0; i < params->num_iterations; i++) {
		/* Prepare inputs for the current iteration */
		for (j = 0; j < params->key_len; j++)
			key[j] = (uint8_t) rte_rand();

		/* Perform operation, and measure time it takes */
		begin = rte_rdtsc();
		pos = func(h, key);
		end = rte_rdtsc();
		ticks += end - begin;

		/* Other work per iteration */
		if (pos < 0)
			*invalid_pos_count += 1;
		else
			bucket_occupancies[pos / params->bucket_entries]++;
	}
	*avg_occupancy = get_avg(bucket_occupancies, num_buckets);

	rte_free(bucket_occupancies);
	rte_free(key);

	return (double)ticks / params->num_iterations;
}
예제 #6
0
float pa_cvolume_get_lfe_balance(const pa_cvolume *v, const pa_channel_map *map) {
    pa_volume_t hfe, lfe;

    pa_assert(v);
    pa_assert(map);

    pa_return_val_if_fail(pa_cvolume_compatible_with_channel_map(v, map), 0.0f);

    if (!pa_channel_map_can_lfe_balance(map))
        return 0.0f;

    get_avg(map, v, &hfe, &lfe, on_hfe, on_lfe);

    if (hfe == lfe)
        return 0.0f;

    if (hfe > lfe)
        return -1.0f + ((float) lfe / (float) hfe);
    else
        return 1.0f - ((float) hfe / (float) lfe);
}
예제 #7
0
float pa_cvolume_get_fade(const pa_cvolume *v, const pa_channel_map *map) {
    pa_volume_t rear, front;

    pa_assert(v);
    pa_assert(map);

    pa_return_val_if_fail(pa_cvolume_compatible_with_channel_map(v, map), 0.0f);

    if (!pa_channel_map_can_fade(map))
        return 0.0f;

    get_avg(map, v, &rear, &front, on_rear, on_front);

    if (front == rear)
        return 0.0f;

    if (rear > front)
        return -1.0f + ((float) front / (float) rear);
    else
        return 1.0f - ((float) rear / (float) front);
}
예제 #8
0
파일: mwrite.c 프로젝트: taysom/tau
int main (int argc, char *argv[])
{
	u8		*buf;
	int		fd;
	ssize_t		written;
	size_t		toWrite;
	unsigned	i;
	unsigned	bufsize;
	unsigned	n;
	u64		size;
	u64		rest;
	u64		l;

	Option.file_size = 8ULL * GIBI;
	Option.iterations = 1;
	Option.loops = 1;
	punyopt(argc, argv, myopt, "b:");
	n = Option.iterations;
	bufsize = 1 << Bufsize_log2;
	buf = emalloc(bufsize);
	size = Option.file_size;

	buf = emalloc(bufsize);
	for (i = 0; i < bufsize; ++i) {
		buf[i] = random();
	}
	for (l = 0; l < Option.loops; l++) {
		startTimer();
		for (i = 0; i < n; i++) {
			/* Because eCryptfs has to decrypt a page before
			 * overwriting it, recreating the file on each
			 * iteration gives a more realistic value.
			 */
			fd = open(Option.file,
				O_RDWR | O_CREAT | O_TRUNC, 0666);
			if (fd == -1) fatal("open %s:", Option.file);
			for (rest = size; rest; rest -= written) {
				if (rest > bufsize) {
					toWrite = bufsize;
				} else {
					toWrite = rest;
				}
				written = write(fd, buf, toWrite);
				if (written != toWrite) {
					if (written == -1) {
						perror("write");
						exit(1);
					}
					fprintf(stderr,
						"toWrite=%lu != written=%ld\n",
						(unint)toWrite, (snint)written);
					exit(1);
				}
				/* Make next buffer unique */
				buf[urand(bufsize)] = random();
			}
			fsync(fd);
			close(fd);
		}
		stopTimer();
		printf("size=%lld n=%d ", size, n);
		prTimer();

		printf("\t%6.4g MiB/s",
			(double)(n * size) / get_avg() / MEBI);

		printf("\n");
	}
	unlink(Option.file);
	return 0;
}
예제 #9
0
파일: mrow.c 프로젝트: soc-lip6/gecos
int main(int argc, char **argv)
{
	int i=0;
	setsignals();
#ifdef RCU_SIGNAL
	rcu_init();
#endif
	setup_test(argc, argv);
	printf("nbthreads %lu nbupdaters %lu nbbuckets %lu perbucket-pbnodes %lu nbtest %d nbreaders %d nbcores %d"
#ifdef POPULATE
			" POPULATE"
#endif
			"\n", 
			nbthreads, nbupdaters, nbbuckets, pbnodes, NB_TEST, nbreaders, get_nbcores());

	for(; i < ITERATION; i++)
		test(i);

	double rops = get_avg(&trd_ops[0],ITERATION);
	double wops = get_avg(&twr_ops[0],ITERATION);
	printf("read ops per micsec = %g\n", rops);
	printf("write ops per micsec = %g\n", wops);
	printf("write/read = %g\n", wops/rops);

	printf("nbmallocs = %g\n", get_avg(&run_mallocs[0],ITERATION));
	printf("nbretry = %g\n", get_avg(&run_retry[0],ITERATION));
	printf("nbrelink = %g\n", get_avg(&run_relink[0],ITERATION));
	printf("nbreprev = %g\n", get_avg(&run_reprev[0],ITERATION));
	printf("nbblockeds = %g\n", get_avg(&run_blockeds[0],ITERATION));

	printf("sucess_search = %g on %g\n", get_avg(&run_sea[0],ITERATION), get_avg(&thd_ops[nbupdaters], nbreaders) );
	printf("sucess_insert = %g on %g\n", get_avg(&run_ins[0],ITERATION), get_avg(&thd_ops[0], nbupdaters)/2);
	printf("sucess_delete = %g on %g\n", get_avg(&run_del[0],ITERATION), get_avg(&thd_ops[0], nbupdaters)/2);
	
	printf("\n");

	printf("avg_max_read = %gus\n", get_max(&run_avg_rd[0],ITERATION));
	printf("avg_avg_read = %gus\n", get_avg(&run_avg_rd[0],ITERATION));
	printf("avg_min_read = %gus\n", get_min(&run_avg_rd[0],ITERATION));
	
	printf("\n");

	printf("avg_max_write = %gus\n", get_max(&run_avg_wr[0],ITERATION));
	printf("avg_avg_write = %gus\n", get_avg(&run_avg_wr[0],ITERATION));
	printf("avg_min_write = %gus\n", get_min(&run_avg_wr[0],ITERATION));

	printf("\n");

	printf("max_read = %gus\n", get_max(&run_max_rd[0],ITERATION));
	printf("min_read = %gus\n", get_min(&run_min_rd[0],ITERATION));
	
	printf("\n");

	printf("max_write = %gus\n", get_max(&run_max_wr[0],ITERATION));
	printf("min_write = %gus\n", get_min(&run_min_wr[0],ITERATION));

	//printf("cpu time = %gus\n", get_avg(&run_cput[0],ITERATION));//FIXME

	return 0;
}
예제 #10
0
파일: mrow.c 프로젝트: soc-lip6/gecos
int test(int iteration)
{
	long i;
	pthread_attr_t attr;
	pthread_t thread[nbthreads];

	hash_init();
	init_allocator();
	pthread_attr_init(&attr);
	done = 0;
	go = 0;
	ready = 0;
	memory_barrier();


	//printf("loop %d is started\n", iteration);
	//printf("thread !!%d\n",thread);
	
	for(i=0; i< nbthreads; i++)
	{
		set_affinity(i);
		//printf("thread = %d ...", i);
		if(pthread_create(&thread[i], &attr, run, (void*)i))
		{
			perror("creat");
		}
		//printf("thread = %d created\n", i);
	}

	while(ready != nbthreads) memory_barrier();
	go = 1;
	memory_barrier();

	void* res;
	for(i=(nbthreads-1); i >= 0; i--)
	{
		pthread_join(thread[i], &res);
		if(i == nbupdaters)
		{
			done = 1;//Stop the writers!
			memory_barrier();
		}
	}

	//printf("Done!\n", i);

	unsigned nbcores = get_nbcores();
	unsigned mtc = nbcores < nbreaders ? nbcores : nbreaders;

	run_avg_rd[iteration] = get_avg(&avg_time[nbupdaters], nbreaders);
	run_avg_wr[iteration] = get_avg(&avg_time[0], nbupdaters);

	run_max_rd[iteration] = get_max(&avg_time[nbupdaters], nbreaders);
	run_max_wr[iteration] = get_max(&avg_time[0], nbupdaters);

	run_min_rd[iteration] = get_min(&avg_time[nbupdaters], nbreaders);
	run_min_wr[iteration] = get_min(&avg_time[0], nbupdaters);

	run_retry[iteration] = get_sum(&thd_retry[nbupdaters], nbreaders);
	run_relink[iteration] = get_sum(&thd_relink[nbupdaters], nbreaders);
	run_reprev[iteration] = get_sum(&thd_reprev[nbupdaters], nbreaders);

	run_cput[iteration] = get_cpu_work(&thd_time[nbupdaters], nbreaders, mtc)/NB_TEST;

	run_mallocs[iteration] = get_sum(&thd_mallocs[0], nbupdaters);
	run_blockeds[iteration] = get_sum(&thd_blockeds[0], nbupdaters);

	run_sea[iteration] = get_avg(&suc_sea[nbupdaters], nbreaders);
	run_del[iteration] = get_avg(&suc_del[0], nbupdaters);
	run_ins[iteration] = get_avg(&suc_ins[0], nbupdaters);

	//printf("avg = %gus\n", run_avg_rd[iteration]);
	//printf("first reader %gus\n", thd_time[nbupdaters]);
	double time = get_avg(&thd_time[nbupdaters], nbreaders);
	trd_ops[iteration] = get_avg(&thd_ops[nbupdaters], nbreaders)/time;
	twr_ops[iteration] = get_avg(&thd_ops[0], nbupdaters)/time;

	//hash_delete();
	//delete_allocator();
}
/*!

*/
void Reptation_method::runWithVariables(Properties_manager & prop, 
                                  System * sys, 
                                  Wavefunction_data * wfdata,
                                  Pseudopotential * psp,
                                  ostream & output)
{


  
  allocateIntermediateVariables(sys, wfdata);
  

  
  prop.setSize(wf->nfunc(), nblock, nstep, 1, 
               sys, wfdata);
  prop.initializeLog(average_var);

  Properties_manager prop_center;
  string logfile, label_temp;
  prop.getLog(logfile, label_temp);
  label_temp+="_cen";
  prop_center.setLog(logfile, label_temp);
  
  prop_center.setSize(wf->nfunc(), nblock, nstep, 1, sys, 
                      wfdata);
  prop_center.initializeLog(average_var);


  cout.precision(10);
  output.precision(10);

  Sample_point * center_samp(NULL);
  sys->generateSample(center_samp);
  
    Reptile_point pt;
  
  Array1 <Reptile> reptiles;
  int nreptile=1;
  if(!readcheck(readconfig,reptiles)) { 
    Array1 <Config_save_point> configs;
    generate_sample(sample,wf,wfdata,guidewf,nreptile,configs);
    reptiles.Resize(nreptile);
    for(int r=0; r< nreptile; r++) { 
      reptiles[r].direction=1;
      configs(r).restorePos(sample);
      wf->notify(all_electrons_move,0);
      wf->updateLap(wfdata,sample);
      for(int i=0; i< reptile_length; i++) {
        doublevar main_diffusion;
        slither(1,reptiles[r].reptile, mygather,pt,main_diffusion);
        reptiles[r].reptile.push_back(pt);
      }
    }
  }
  nreptile=reptiles.GetDim(0);

  //assert(reptile.size()==reptile_length);
  //Branch limiting variables
  //we start off with no limiting, and establish the parameters after the
  //first block.  This seems to be reasonably stable, since it's mostly
  //to keep the reptile from getting stuck.
  eref=0;
  energy_cutoff=1e16;

  //--------begin averaging..
  
  Array3 <doublevar> derivatives_block(nblock, sys->nIons(), 3);
  for(int block=0; block< nblock; block++) {

    //clock_t block_start_time=clock();
    doublevar avg_age=0;
    doublevar max_age=0;

    doublevar main_diff=0;
    double ntry=0, naccept=0;
    double nbounce=0;


    for(int r=0; r< nreptile; r++) { 
      Reptile & curr_reptile=reptiles[r];
      //Control variable that will be set to one when 
      //we change direction, which signals to recalculate
      //the wave function
      int recalc=1;
      
    for(int step=0; step< nstep; step++) {
      psp->randomize();
      if(recalc) { 
        if(curr_reptile.direction==1) 
          curr_reptile.reptile[reptile_length-1].restorePos(sample);
        else
          curr_reptile.reptile[0].restorePos(sample);          
      }
      doublevar main_diffusion;
      doublevar accept=slither(curr_reptile.direction, curr_reptile.reptile,mygather, pt,
                               main_diffusion);
      ntry++;
      if(accept+rng.ulec() > 1.0) {
        recalc=0;
        naccept++;
        main_diff+=main_diffusion;
        if(curr_reptile.direction==1) {
          curr_reptile.reptile.pop_front();
          curr_reptile.reptile.push_back(pt);
        }
        else {
          curr_reptile.reptile.pop_back();
          curr_reptile.reptile[0].branching=pt.branching;
          curr_reptile.reptile.push_front(pt);
        }
      }
      else {
        recalc=1;
        curr_reptile.direction*=-1;
        nbounce++;
      }

      for(deque<Reptile_point>::iterator i=curr_reptile.reptile.begin();
          i!=curr_reptile.reptile.end(); i++) {
        i->age++;
        avg_age+=i->age/reptile_length;
        if(i->age > max_age) max_age=i->age;
      }
      
      Properties_point avgpt;
      get_avg(curr_reptile.reptile, avgpt);
      avgpt.parent=0; avgpt.nchildren=1; //just one walker
      avgpt.children(0)=0;
      prop.insertPoint(step, 0, avgpt);
      
      int cpt=reptile_length/2+1;      
      Properties_point centpt;
      get_center_avg(curr_reptile.reptile, centpt);
      centpt.parent=0; centpt.nchildren=1;
      centpt.children(0)=0;
      
      prop_center.insertPoint(step, 0, centpt);
      
      curr_reptile.reptile[cpt].restorePos(center_samp);

      for(int i=0; i< densplt.GetDim(0); i++) 
        densplt(i)->accumulate(center_samp,1.0);
      
      
      if(center_trace != "" 
         && (block*nstep+step)%trace_wait==0) {
        ofstream checkfile(center_trace.c_str(), ios::app);
        if(!checkfile)error("Couldn't open ", center_trace);
        checkfile << "SAMPLE_POINT { \n";
        write_config(checkfile, sample);
        checkfile << "}\n\n";
      }
      
      
    }   //step
    } //reptile

    prop.endBlock();
    prop_center.endBlock();
    double ntot=parallel_sum(nstep);

    Properties_block lastblock;
    prop.getLastBlock(lastblock);
    eref=lastblock.avg(Properties_types::total_energy,0);
    energy_cutoff=10*sqrt(lastblock.var(Properties_types::total_energy,0));
    
    
    nbounce=parallel_sum(nbounce);
    naccept=parallel_sum(naccept);
    ntry=parallel_sum(ntry);
    avg_age=parallel_sum(avg_age);

    for(int i=0; i< densplt.GetDim(0); i++) 
      densplt(i)->write();

    storecheck(reptiles, storeconfig);
    main_diff=parallel_sum(main_diff);
    if(output) {
      output << "****Block " << block 
             << " acceptance " << naccept/ntry 
             << "  average steps before bounce " << ntot/nbounce
             << endl;
      output << "average age " << avg_age/ntot 
             << "   max age " << max_age <<  endl;
      output << "eref " << eref << " cutoff " << energy_cutoff << endl;
      output << "Green's function sampler:" << endl;
      sampler->showStats(output);
      prop.printBlockSummary(output);
      output << "Center averaging: " << endl;
      prop_center.printBlockSummary(output);
    }
    sampler->resetStats();

    //clock_t block_end_time=clock();
    
    //cout << mpi_info.node << ":CPU block time " 
    //// << double(block_end_time-block_start_time)/double(CLOCKS_PER_SEC)
    // << endl;

  }   //block


  if(output) {
    output << "############## Reptation Done ################\n";
    output << "End averages " << endl;
    prop.printSummary(output,average_var);
    output << "Center averages " << endl;
    prop_center.printSummary(output,average_var);


    //Print out a PDB file with one of the reptiles, for visualization purposes
    if(print_pdb) { 
      ofstream pdbout("rmc.pdb");
      pdbout.precision(3);
      pdbout << "REMARK    4 Mode COMPLIES WITH FORMAT V. 2.0\n";
      int nelectrons=sample->electronSize();

      int counter=1;
      string name="H";
      for(int e=0; e<nelectrons; e++) {
        for(deque<Reptile_point>::iterator i=reptiles[0].reptile.begin();
            i!=reptiles[0].reptile.end(); i++) {
          pdbout<<"ATOM"<<setw(7)<< counter <<" " <<name<<"   UNK     1"
            <<setw(12)<< i->electronpos[e][0]
            <<setw(8)<< i->electronpos[e][1]
            <<setw(8)<< i->electronpos[e][2]
            << "  1.00  0.00\n";
          counter++;
        }
      }
      int nions=sys->nIons();
      Array1 <doublevar> ionpos(3);
      vector <string> atomnames;
      sys->getAtomicLabels(atomnames);
      for(int i=0; i< nions; i++) {
        sys->getIonPos(i,ionpos);
        pdbout<<"ATOM"<<setw(7)<< counter <<" " <<atomnames[i]<<"   UNK     1"
          <<setw(12)<< ionpos[0]
          <<setw(8)<< ionpos[1]
          <<setw(8)<< ionpos[2]
          << "  1.00  0.00\n";
      }



      counter=1;
      for(int e=0; e<nelectrons; e++) {
        for(deque<Reptile_point>::iterator i=reptiles[0].reptile.begin();
            i!=reptiles[0].reptile.end(); i++) {
          if(i != reptiles[0].reptile.begin()) { 
            pdbout << "CONECT" << setw(5) << counter << setw(5) << counter-1 << endl;
          }
          counter++;
        }
      }
    
    }
    //------------Done PDB file

  }


  delete center_samp;
  wfdata->clearObserver();
  deallocateIntermediateVariables();
}
예제 #12
0
파일: main.c 프로젝트: NikolovV/C-Language
int main()
{
    int arr_1[] = {1, 2, 3, 4, 5};
    int arr_2[] = {6, 7, 8};
    int lenght_1 = LENGHT_ARRAY(arr_1);
    int lenght_2 = LENGHT_ARRAY(arr_2);

    int min = get_min(arr_1, lenght_1);
    printf("min = %d\n", min);
    int min_2 = get_min(arr_2, lenght_2);
    printf("min_2 = %d\n", min_2);

    int max = get_max(arr_1, lenght_1);
    printf("max = %d\n", max);
    int max_2 = get_max(arr_2, lenght_2);
    printf("max_2 = %d\n", max_2);

    double average = get_avg(arr_1, lenght_1);
    printf("average = %f\n", average);
    double average_2 = get_avg(arr_2, lenght_2);
    printf("average_2 = %f\n", average_2);

    int sum = get_sum(arr_1, lenght_1);
    printf("sum = %d\n", sum);
    int sum_2 = get_sum(arr_2, lenght_2);
    printf("sum_2 = %d\n", sum_2);

    bool isContain = arr_contains(arr_1, lenght_1, 5);
    printf("isContain 5 = %d\n", isContain);
    bool isContain_2 = arr_contains(arr_2, lenght_2, 5);
    printf("isContain_2 5 = %d\n", isContain_2);
    
    int *arrMerge;
    arrMerge = arr_merge(arr_1, arr_2, lenght_1, lenght_2);
    int i;
    printf("Merged: ");
    for (i = 0; i < (lenght_1 + lenght_2); i++)
    {
        printf("%d ", arrMerge[i]);
    }
    printf("\n");
    
    free(arrMerge);
    
    printf("Clearing... \n");
    arr_clear(arr_1, lenght_1);
    for (i = 0; i < lenght_1; i++)
    {
        printf("%d ", arr_1[i]);
    }
    printf("\n");
        
    arr_clear(arr_2, lenght_2);
    for (i = 0; i < lenght_2; i++)
    {
        printf("%d ", arr_2[i]);
    }
    
    
    return (EXIT_SUCCESS);
}
예제 #13
0
파일: uread.c 프로젝트: taysom/tau
int main (int argc, char *argv[])
{
	u8		*buf;
	int		fd;
	ssize_t		haveRead;
	size_t		toRead;
	unsigned	i;
	unsigned	bufsize;
	unsigned	n;
	u64		size;
	u64		rest;
	u64		l;

	drop_caches();
	Option.file_size = 0;
	Option.iterations = 1;
	Option.loops = 1;
	punyopt(argc, argv, myopt, "b:");
	n = Option.iterations;
	bufsize = 1 << Bufsize_log2;
	buf = emalloc(bufsize);
	size = Option.file_size;
	if (!size) {
		size = memtotal() / FRACTION_OF_MEMORY;
	}
	if (Hog_memory) {
		hog_leave_memory(size / FRACTION_OF_FILE_SIZE);
	}
	fd = open(Option.file, O_RDWR | O_CREAT | O_TRUNC, 0666);
	fill_file(fd, size);
	for (l = 0; l < Option.loops; l++) {
		startTimer();
		for (i = 0; i < n; ++i) {
			for (rest = size; rest; rest -= haveRead) {
				if (rest > bufsize) {
					toRead = bufsize;
				} else {
					toRead = rest;
				}
				haveRead = read(fd, buf, toRead);
				if (haveRead != toRead) {
					if (haveRead == -1) {
						perror("read");
						exit(1);
					}
					fprintf(stderr,
						"toRead=%llu != haveRead=%lld\n",
						(u64)toRead, (s64)haveRead);
					exit(1);
				}
			}
			lseek(fd, 0, 0);
		}
		stopTimer();
		printf("size=%lld n=%d ", size, n);
		prTimer();

		printf("\t%6.4g MiB/s\n",
			(double)(n * size) / get_avg() / MEBI);
	}
	close(fd);
	unlink(Option.file);
	return 0;
}
예제 #14
0
 /***********************************
  * MAIN
  * *********************************/
int main(int argc, char *argv[]){

	Connection connection;
	write_error_ptr = &write_error;  //initialize the function pointer to write error
	
	//parse arguments	
	if(argc == 4){
		//first argument is always name of program or empty string
		connection.planebone_ip=argv[1];
		connection.port_number_server_to_planebone=atoi(argv[2]);	
		connection.port_number_planebone_to_server=atoi(argv[3]);
	}else{
			printf("wrong parameters: planebone ip - send port number - receive port number\n");
			exit(EXIT_FAILURE);		
	}
		
	pthread_t thread_server_to_planebone;

	//create a second thread which executes server_to_planebone
	if(pthread_create(&thread_server_to_planebone, NULL, server_to_planebone,&connection)) {
		error_write(FILENAME,"error creating lisa thread");
		exit(EXIT_FAILURE);
	}	
	
	/*-------------------------START OF FIRST THREAD: PLANEBONE TO SERVER------------------------*/
	
	static UDP udp_server;
	uint8_t input_stream[MAX_INPUT_STREAM_SIZE];
	timeval tv_now;

	UDP_err_handler(openUDPServerSocket(&udp_server,connection.port_number_planebone_to_server,UDP_SOCKET_TIMEOUT),write_error_ptr);
	
	//init the data decode pointers
	init_decoding();
	
	/*
	 * WHAT WE EXPECT:
	 * IMU_ACCEL_RAW 204
	 * IMU_GYRO_RAW 203
	 * IMU_MAG_RAW 205
	 * BARO_RAW 221
	 * GPS_INT 155
	 * AIRSPEED_ETS 57
	 * SYSMON 33
	 * UART_ERROR 208
	 * ACTUATORS_received 105
	 * */
	 
	int IMU_ACCEL_RAW_received=0;
	int IMU_GYRO_RAW_received=0;	
	int IMU_MAG_RAW_received=0;
	int BARO_RAW_received=0;
	int GPS_INT_received=0;
	int AIRSPEED_received=0;
	int SVINFO_received=0;
	int SYSMON_received=0;
	int UART_ERROR_received=0;
	int ACTUATORS_received=0;
	int NMEA_IIMWV_received = 0;
	int NMEA_WIXDR_received = 0;
	int err;
	
	#if ANALYZE
		Analyze an_imu_accel_raw_freq,an_imu_accel_raw_lat;
		int an_imu_accel_freq_done=0,an_imu_accel_lat_done=0;
		init_analyze(&an_imu_accel_raw_freq,2000);
		init_analyze(&an_imu_accel_raw_lat,2000);

		Analyze an_imu_gyro_raw_freq,an_imu_gyro_raw_lat;
		int an_imu_gyro_freq_done=0,an_imu_gyro_lat_done=0;
		init_analyze(&an_imu_gyro_raw_freq,2000);
		init_analyze(&an_imu_gyro_raw_lat,2000);
		
		Analyze an_imu_mag_raw_freq,an_imu_mag_raw_lat;
		int an_imu_mag_freq_done=0,an_imu_mag_lat_done=0;
		init_analyze(&an_imu_mag_raw_freq,2000);
		init_analyze(&an_imu_mag_raw_lat,2000);
		
		Analyze an_baro_raw_freq,an_baro_raw_lat;
		int an_baro_raw_freq_done=0,an_baro_raw_lat_done=0;
		init_analyze(&an_baro_raw_freq,2000);
		init_analyze(&an_baro_raw_lat,2000);
		
		Analyze an_gps_int_freq,an_gps_int_lat;
		int an_gps_int_freq_done=0,an_gps_int_lat_done=0;
		init_analyze(&an_gps_int_freq,40);
		init_analyze(&an_gps_int_lat,40);
		
		Analyze an_airspeed_ets_freq,an_airspeed_ets_lat;
		int an_airspeed_ets_freq_done=0,an_airspeed_ets_lat_done=0;
		init_analyze(&an_airspeed_ets_freq,100);
		init_analyze(&an_airspeed_ets_lat,100);
		
		Analyze an_actuators_freq,an_actuators_lat;
		int an_actuators_freq_done=0,an_actuators_lat_done=0;
		init_analyze(&an_actuators_freq,500);
		init_analyze(&an_actuators_lat,500);
		
		Analyze an_UART_errors_freq,an_UART_errors_lat;
		int an_UART_errors_freq_done=0,an_UART_errors_lat_done=0;
		init_analyze(&an_UART_errors_freq,50);
		init_analyze(&an_UART_errors_lat,50);
		
		Analyze an_sys_mon_freq,an_sys_mon_lat;
		int an_sys_mon_freq_done=0,an_sys_mon_lat_done=0;
		init_analyze(&an_sys_mon_freq,50);
		init_analyze(&an_sys_mon_lat,50);

	#endif


	int recv_len;
	size_t data_len = sizeof(input_stream);

	while (1){
		// err = receiveUDPServerData(&udp_server,(void *)&input_stream, sizeof(input_stream)); //blocking !!!
		//1. retreive UDP data form planebone from ethernet port.
		err = receiveUDPServerData(&udp_server,(void *)&input_stream, data_len, &recv_len); //blocking !!!

		if (recv_len != 30) {
			printf("Wrong number of bytes in received UDP packet!\n");
                	printf("Expected 30 bytes, Received %d bytes!\n", recv_len);
                	err = UDP_ERR_RECV;
		}

		UDP_err_handler(err,write_error_ptr); 
	
		if(err == UDP_ERR_NONE){
			gettimeofday(&tv_now,NULL); //timestamp from receiving to calculate latency
			
			#if DEBUG > 0
			
				printf("message raw: ");
				int i;
				for(i=0;i<input_stream[1];i++){
						printf("%d ",input_stream[i]);
				}
				printf("\n");
				
				printf("start hex: %x\n", input_stream[0]);
				printf("length: %d\n", input_stream[1]);
				printf("send id: %d\n", input_stream[2]);
				printf("message id: %d\n", input_stream[3]);
				printf("checksum1: %d\n", input_stream[input_stream[1]-2]);
				printf("checksum2: %d\n", input_stream[input_stream[1]-1]);
				// printf("%d", input_stream[3]);
				printf("\n");
			
			#endif
			
			//2. decode data 		
			int err  = data_decode(input_stream);
			DEC_err_handler(err,write_error_ptr);
	
			if(err==DEC_ERR_NONE){ 
			
				switch_read_write(); //only switch read write if data decoding was succesfull
				Data* data = get_read_pointer();

				if(input_stream[3]==IMU_GYRO_RAW){
					IMU_GYRO_RAW_received=1;
				}else if(input_stream[3]==IMU_ACCEL_RAW){
					IMU_ACCEL_RAW_received=1;
				}else if(input_stream[3]==IMU_MAG_RAW){
					IMU_MAG_RAW_received=1;
				}else if(input_stream[3]==BARO_RAW){
					BARO_RAW_received=1;
				}else if(input_stream[3]==GPS_INT){
					GPS_INT_received=1;
				}else if(input_stream[3]==AIRSPEED_ETS){
					AIRSPEED_received=1;
				}else if(input_stream[3]==SVINFO){
					SVINFO_received=1;
				}else if(input_stream[3]==SYSMON){
					SYSMON_received=1;
				}else if(input_stream[3]==UART_ERRORS){
					UART_ERROR_received=1;
				}else if(input_stream[3]==ACTUATORS){
					ACTUATORS_received=1;
				}else if(input_stream[3]==NMEA_IIMWV_ID){
					NMEA_IIMWV_received=1;
				}else if(input_stream[3]==NMEA_WIXDR_ID){
					NMEA_WIXDR_received=1;
				}
				
				/*printf("IMU_GYRO_RAW_received %d\n",IMU_GYRO_RAW_received);
				printf("IMU_ACCEL_RAW_received %d\n",IMU_ACCEL_RAW_received);
				printf("IMU_MAG_RAW_received %d\n",IMU_MAG_RAW_received);
				printf("BARO_RAW_received %d\n",BARO_RAW_received);
				printf("GPS_INT_received %d\n",GPS_INT_received);			
				printf("AIRSPEED_received %d\n",AIRSPEED_received);			
				printf("SVINFO_received %d\n",SVINFO_received);	
				printf("SYSMON_received %d\n",SYSMON_received);	
				printf("UART_ERROR_received %d\n",UART_ERROR_received);	
				printf("ACTUATORS_received %d\n",ACTUATORS_received);
				printf("NMEA_IIMWV_received %d\n",NMEA_IIMWV_received);	
				printf("NMEA_WIXDR_received %d\n",NMEA_WIXDR_received);	
				printf("\n");*/

				if(input_stream[3]==BARO_RAW){
					#if ANALYZE
						if(calculate_frequency(&an_baro_raw_freq,data->lisa_plane.baro_raw.tv)==1){
							an_baro_raw_freq_done=1;
						}

						if(calculate_latency(&an_baro_raw_lat,data->lisa_plane.baro_raw.tv,tv_now)==1){
							an_baro_raw_lat_done=1;
						}
					#endif
					/*int i;
					printf("Baro_raw content:");	
					print_mem((void *)&data->lisa_plane.baro_raw,sizeof(Baro_raw));
	
					printf("abs %d\n",data->lisa_plane.baro_raw.abs);
					printf("diff %d\n",data->lisa_plane.baro_raw.diff);	
					
									 
					printf("\n\n\n");*/
				}
				
				if(input_stream[3]==IMU_GYRO_RAW){
					
					#if ANALYZE
						if(calculate_frequency(&an_imu_gyro_raw_freq,data->lisa_plane.imu_gyro_raw.tv)==1){
							an_imu_gyro_freq_done=1;
						}
						

						if(calculate_latency(&an_imu_gyro_raw_lat,data->lisa_plane.imu_gyro_raw.tv,tv_now)==1){
							an_imu_gyro_lat_done=1;
						}
					#endif
					
				/*	int i;
					printf("Imu_gyro_raw content:");
					print_mem((void *)&data->lisa_plane.imu_gyro_raw,sizeof(Imu_gyro_raw));
				
					printf("\n");
					printf("gp %d\n",data->lisa_plane.imu_gyro_raw.gp);
					printf("gq %d\n",data->lisa_plane.imu_gyro_raw.gq);
					printf("gr %d\n",data->lisa_plane.imu_gyro_raw.gr);
					
					print_latency(data->lisa_plane.imu_gyro_raw.tv);
				 
					printf("\n\n\n");*/

				}
				
				if(input_stream[3]==IMU_ACCEL_RAW){
					
					#if ANALYZE
						if(calculate_frequency(&an_imu_accel_raw_freq,data->lisa_plane.imu_accel_raw.tv)==1){
							an_imu_accel_freq_done=1;
						}
						

						if(calculate_latency(&an_imu_accel_raw_lat,data->lisa_plane.imu_accel_raw.tv,tv_now)==1){
							an_imu_accel_lat_done=1;
						}
					#endif
					
					
					/*int i;
					printf("Imu_accel_raw content:");
					print_mem((void *)&data->lisa_plane.imu_accel_raw,sizeof(Imu_accel_raw));


					printf("\n");
					printf("ax %d\n",data->lisa_plane.imu_accel_raw.ax);
					printf("ay %d\n",data->lisa_plane.imu_accel_raw.ay);
					printf("az %d\n",data->lisa_plane.imu_accel_raw.az);
					printf("\n");
					
			 
					printf("\n\n\n");*/

				}
				
				if(input_stream[3]==IMU_MAG_RAW){
					
					#if ANALYZE
						if(calculate_frequency(&an_imu_mag_raw_freq,data->lisa_plane.imu_mag_raw.tv)==1){
							an_imu_mag_freq_done=1;
						}

						if(calculate_latency(&an_imu_mag_raw_lat,data->lisa_plane.imu_mag_raw.tv,tv_now)==1){
							an_imu_mag_lat_done=1;
						}
					#endif
						

				}
				
				if(input_stream[3]==AIRSPEED_ETS){
					
					#if ANALYZE
						if(calculate_frequency(&an_airspeed_ets_freq,data->lisa_plane.airspeed_ets.tv)==1){
							an_airspeed_ets_freq_done=1;
						}

						if(calculate_latency(&an_airspeed_ets_lat,data->lisa_plane.airspeed_ets.tv,tv_now)==1){
							an_airspeed_ets_lat_done=1;
						}
					#endif
					
					/*int i;
					printf("airspeed content:");
					print_mem((void *)&data->lisa_plane.airspeed_ets,sizeof(Airspeed_ets));
					
					char temp[64];
					timestamp_to_timeString(data->lisa_plane.airspeed_ets.tv,temp);
					printf("send time %s\n",temp);

					printf("adc %d\n",data->lisa_plane.airspeed_ets.adc);
					printf("offset %d\n",data->lisa_plane.airspeed_ets.offset);
					printf("scaled %f\n",data->lisa_plane.airspeed_ets.scaled);*/
				}
				
				
				if(input_stream[3]==GPS_INT){
					#if ANALYZE
						if(calculate_frequency(&an_gps_int_freq,data->lisa_plane.gps_int.tv)==1){
							an_gps_int_freq_done=1;
						}

						if(calculate_latency(&an_gps_int_lat,data->lisa_plane.gps_int.tv,tv_now)==1){
							an_gps_int_lat_done=1;
						}
					#endif
				
					/*int i;
					printf("Gps_int_message content:");
					print_mem((void *)&data->lisa_plane.gps_int,sizeof(Gps_int));

					printf("\n");
					printf("ecef_x %d\n",data->lisa_plane.gps_int.ecef_x);
					printf("ecef_y %d\n",data->lisa_plane.gps_int.ecef_y);
					printf("ecef_z %d\n",data->lisa_plane.gps_int.ecef_z);
					printf("lat %d\n",data->lisa_plane.gps_int.lat);
					printf("lon %d\n",data->lisa_plane.gps_int.lon);
					printf("alt %d\n",data->lisa_plane.gps_int.alt);
					printf("hmsl %d\n",data->lisa_plane.gps_int.hmsl);
					printf("ecef_xd %d\n",data->lisa_plane.gps_int.ecef_xd);
					printf("ecef_yd %d\n",data->lisa_plane.gps_int.ecef_yd);
					printf("ecef_zd %d\n",data->lisa_plane.gps_int.ecef_zd);
					printf("pacc %d\n",data->lisa_plane.gps_int.pacc);
					printf("sacc %d\n",data->lisa_plane.gps_int.sacc);
					printf("tow %d\n",data->lisa_plane.gps_int.tow);
					printf("pdop %d\n",data->lisa_plane.gps_int.pdop);
					printf("numsv %d\n",data->lisa_plane.gps_int.numsv);
					printf("fix %d\n",data->lisa_plane.gps_int.fix);
					print_latency(data->lisa_plane.gps_int.tv);*/

					
				}
				
		
				if(input_stream[3]==SYSMON){
					
					#if ANALYZE
						if(calculate_frequency(&an_sys_mon_freq,data->lisa_plane.sys_mon.tv)==1){
							an_sys_mon_freq_done=1;
						}

						if(calculate_latency(&an_sys_mon_lat,data->lisa_plane.sys_mon.tv,tv_now)==1){
							an_sys_mon_lat_done=1;
						}
					#endif	
					
				/*	int i;
					printf("sysmon content:");
					print_mem((void *)&data->lisa_plane.sys_mon,sizeof(Sys_mon));

					printf("\n");
					printf("periodic_time %d\n",data->lisa_plane.sys_mon.periodic_time);
					printf("periodic_cycle %d\n",data->lisa_plane.sys_mon.periodic_cycle);
					printf("periodic_cycle_min %d\n",data->lisa_plane.sys_mon.periodic_cycle_min);
					printf("periodic_cycle_max %d\n",data->lisa_plane.sys_mon.periodic_cycle_max);
					printf("event_number %d\n",data->lisa_plane.sys_mon.event_number);
					printf("cpu_load %d\n",data->lisa_plane.sys_mon.cpu_load);
					print_latency(data->lisa_plane.sys_mon.tv);*/

				}
			if(input_stream[3]==UART_ERRORS){
				
				#if ANALYZE
					if(calculate_frequency(&an_UART_errors_freq,data->lisa_plane.uart_errors.tv)==1){
						an_UART_errors_freq_done=1;
					}

					if(calculate_latency(&an_UART_errors_lat,data->lisa_plane.uart_errors.tv,tv_now)==1){
						an_UART_errors_lat_done=1;
					}
				#endif
				/*	int i;
					printf("uart error content:");
					print_mem((void *)&data->lisa_plane.uart_errors,sizeof(UART_errors));

					printf("overrun_cnt %d\n",data->lisa_plane.uart_errors.overrun_cnt);
					printf("noise_err_cnt %d\n",data->lisa_plane.uart_errors.noise_err_cnt);
					printf("framing_err_cnt %d\n",data->lisa_plane.uart_errors.framing_err_cnt);
					printf("bus_number %d\n",data->lisa_plane.uart_errors.bus_number);
					print_latency(data->lisa_plane.uart_errors.tv);*/

				}
				if(input_stream[3]==ACTUATORS){
					#if ANALYZE
						if(calculate_frequency(&an_actuators_freq,data->lisa_plane.actuators.tv)==1){
							an_actuators_freq_done=1;
						}

						if(calculate_latency(&an_actuators_lat,data->lisa_plane.actuators.tv,tv_now)==1){
							an_actuators_lat_done=1;
						}
					#endif
					
					/*int i;
					printf("actuators content:");
					print_mem((void *)&data->lisa_plane.actuators,sizeof(Actuators));

					printf("arr_length %d\n",data->lisa_plane.actuators.arr_length);
					for(i=0;i<data->lisa_plane.actuators.arr_length;i++){
						printf("servo_%d %d\n",i,data->lisa_plane.actuators.values[i]);
					}
					print_latency(data->lisa_plane.actuators.tv);*/

				}
				
				if(input_stream[3]==BEAGLE_ERROR){
					//printf("beagle bone error content:");
					//print_mem((void *)&data->bone_plane.error,sizeof(Beagle_error));
										
					switch(data->bone_plane.error.library){
						case UDP_L:
							UDP_err_handler(data->bone_plane.error.error_code,write_error_ptr);
						break;
						case UART_L:
							UART_err_handler(data->bone_plane.error.error_code,write_error_ptr);
						break;
						case DECODE_L:
							DEC_err_handler(data->bone_plane.error.error_code,write_error_ptr);
						break;
						case LOG_L:
							LOG_err_handler(data->bone_plane.error.error_code,write_error_ptr);
						break;
					}
				}
				
				if(input_stream[3]==NMEA_IIMWV_ID){
					
					printf("NMEA_IIMWV_ID content:");
					print_mem((void *)&data->bone_wind.nmea_iimmwv,sizeof(NMEA_IIMWV));

					printf("wind angle %lf\n",data->bone_wind.nmea_iimmwv.wind_angle);
					printf("relative %c\n",data->bone_wind.nmea_iimmwv.relative);
					printf("wind speed %lf\n",data->bone_wind.nmea_iimmwv.wind_speed);
					printf("wind speed unit %c\n",data->bone_wind.nmea_iimmwv.wind_speed_unit);
					printf("status %c\n",data->bone_wind.nmea_iimmwv.status);
					char temp[64];
					timestamp_to_timeString16(data->bone_wind.nmea_iimmwv.tv,temp);
					printf("send time: %s\n",temp);
					printf("\n");

				}
				
				if(input_stream[3]==NMEA_WIXDR_ID){
					
					printf("NMEA_WIXDR_ID content:");
					print_mem((void *)&data->bone_wind.nmea_wixdr,sizeof(NMEA_WIXDR));
					
					printf("Temperature %lf\n",data->bone_wind.nmea_wixdr.temperature);
					printf("unit %c\n",data->bone_wind.nmea_wixdr.unit);
					char temp[64];
					timestamp_to_timeString16(data->bone_wind.nmea_wixdr.tv,temp);
					printf("send time: %s\n",temp);
					printf("\n");
				}
				
				if(input_stream[3]==LINE_ANGLE_ID){
					// Send a character (to gpio of arduino)
					// to stop the arduino-timer
					/*
					FILE *myFile;
					myFile = fopen("/dev/ttyUSB0", "w");
					fputs ("a", myFile);
					fclose (myFile);
					*/
					

					printf("LINE_ANGLE_ID content:");
					print_mem((void *)&data->bone_arm.line_angle,sizeof(LINE_ANGLE));
					
					printf("Azimuth %i\n",data->bone_arm.line_angle.azimuth_raw);
					printf("Elevation %i\n",data->bone_arm.line_angle.elevation_raw);
					// printf("unit %c\n",data->bone_wind.nmea_wixdr.unit);
					//char temp[64];
					//timestamp_to_timeString16(data->bone_arm.line_angle.tv,temp);
					//printf("send time: %s\n",temp);
					printf("\n");
				}
									
			}else{
					printf("UNKNOW PACKAGE with id %d\n",input_stream[3]);
					exit(1);
			}
		}
		#if ANALYZE
			if(an_imu_accel_freq_done==1 && 
					an_imu_accel_lat_done==1 && 
					an_imu_gyro_freq_done==1 && 
					an_imu_gyro_lat_done==1 && 
					an_imu_mag_freq_done==1 && 
					an_imu_mag_lat_done==1 && 
					an_baro_raw_lat_done==1 && 
					an_baro_raw_freq_done==1 && 
					an_airspeed_ets_lat_done==1 && 
					an_airspeed_ets_freq_done==1 && 
					an_actuators_lat_done==1 && 
					an_actuators_freq_done==1 && 
					an_UART_errors_lat_done==1 && 
					an_UART_errors_freq_done==1 && 
					an_sys_mon_lat_done==1 && 
					an_sys_mon_freq_done==1)
			{
				printf("ANALYZE RESULTS - IMU_ACCEL_RAW:\n");
				printf("avg period:\t %0.4f ms\n",(get_avg(&an_imu_accel_raw_freq)));
				printf("avg freq:\t %0.4f hz\n",1/(get_avg(&an_imu_accel_raw_freq))*1e3);
				printf("avg latency\t %0.4f ms\n",get_avg(&an_imu_accel_raw_lat));
				printf("\n");
				dump_buffer_to_file(&an_imu_accel_raw_freq,"analyze/imu_accel_raw_per.csv");
				dump_buffer_to_file(&an_imu_accel_raw_lat,"analyze/imu_accel_raw_lat.csv");
				destroy_analyze(&an_imu_accel_raw_freq);
				destroy_analyze(&an_imu_accel_raw_lat);
				
				printf("ANALYZE RESULTS - IMU_GYRO_RAW:\n");
				printf("avg period:\t %0.4f ms\n",(get_avg(&an_imu_gyro_raw_freq)));
				printf("avg freq:\t %0.4f hz\n",1/(get_avg(&an_imu_gyro_raw_freq))*1e3);
				printf("avg latency\t %0.4f ms\n",get_avg(&an_imu_gyro_raw_lat));
				printf("\n");
				dump_buffer_to_file(&an_imu_gyro_raw_freq,"analyze/imu_gyro_raw_per.csv");
				dump_buffer_to_file(&an_imu_gyro_raw_lat,"analyze/imu_gyro_raw_lat.csv");
				destroy_analyze(&an_imu_gyro_raw_freq);
				destroy_analyze(&an_imu_gyro_raw_lat);
				
				printf("ANALYZE RESULTS - IMU_MAG_RAW:\n");
				printf("avg period:\t %0.4f ms\n",(get_avg(&an_imu_mag_raw_freq)));
				printf("avg freq:\t %0.4f hz\n",1/(get_avg(&an_imu_mag_raw_freq))*1e3);
				printf("avg latency\t %0.4f ms\n",get_avg(&an_imu_mag_raw_lat));
				printf("\n");
				dump_buffer_to_file(&an_imu_mag_raw_freq,"analyze/imu_mag_raw_per.csv");
				dump_buffer_to_file(&an_imu_mag_raw_lat,"analyze/imu_mag_raw_lat.csv");
				destroy_analyze(&an_imu_mag_raw_freq);
				destroy_analyze(&an_imu_mag_raw_lat);
				
				printf("ANALYZE RESULTS - BARO_RAW:\n");
				printf("avg period:\t %0.4f ms\n",(get_avg(&an_baro_raw_freq)));
				printf("avg freq:\t %0.4f hz\n",1/(get_avg(&an_baro_raw_freq))*1e3);
				printf("avg latency\t %0.4f ms\n",get_avg(&an_baro_raw_lat));
				printf("\n");
				dump_buffer_to_file(&an_baro_raw_freq,"analyze/baro_raw_per.csv");
				dump_buffer_to_file(&an_baro_raw_lat,"analyze/baro_raw_lat.csv");
				destroy_analyze(&an_baro_raw_freq);
				destroy_analyze(&an_baro_raw_lat);
				
				printf("ANALYZE RESULTS - GPS_INT:\n");
				printf("avg period:\t %0.4f ms\n",get_avg(&an_gps_int_freq));
				printf("avg freq:\t %0.4f hz\n",1/(get_avg(&an_gps_int_freq))*1e3);
				printf("avg latency\t %0.4f ms\n",get_avg(&an_gps_int_lat));
				printf("\n");
				dump_buffer_to_file(&an_gps_int_freq,"analyze/gps_int_per.csv");
				dump_buffer_to_file(&an_gps_int_lat,"analyze/gps_int_lat.csv");
				destroy_analyze(&an_gps_int_freq);
				destroy_analyze(&an_gps_int_lat);
				
				printf("ANALYZE RESULTS - AIRSPEED_ETS:\n");
				printf("avg period:\t %0.4f ms\n",get_avg(&an_airspeed_ets_freq));
				printf("avg freq:\t %0.4f hz\n",1/(get_avg(&an_airspeed_ets_freq))*1e3);
				printf("avg latency\t %0.4f ms\n",get_avg(&an_airspeed_ets_lat));
				printf("\n");
				dump_buffer_to_file(&an_airspeed_ets_freq,"analyze/airspeed_ets_per.csv");
				dump_buffer_to_file(&an_airspeed_ets_lat,"analyze/airspeed_ets_lat.csv");
				destroy_analyze(&an_airspeed_ets_freq);
				destroy_analyze(&an_airspeed_ets_lat);
				
				printf("ANALYZE RESULTS - ACTUATORS:\n");
				printf("avg period:\t %0.4f ms\n",get_avg(&an_actuators_freq));
				printf("avg freq:\t %0.4f hz\n",1/(get_avg(&an_actuators_freq))*1e3);
				printf("avg latency\t %0.4f ms\n",get_avg(&an_actuators_lat));
				printf("\n");
				dump_buffer_to_file(&an_actuators_freq,"analyze/actuators_per.csv");
				dump_buffer_to_file(&an_actuators_lat,"analyze/actuators_lat.csv");
				destroy_analyze(&an_actuators_freq);
				destroy_analyze(&an_actuators_lat);
				
				printf("ANALYZE RESULTS - UART_ERRORS:\n");
				printf("avg period:\t %0.4f ms\n",get_avg(&an_UART_errors_freq));
				printf("avg freq:\t %0.4f hz\n",1/(get_avg(&an_UART_errors_freq))*1e3);
				printf("avg latency\t %0.4f ms\n",get_avg(&an_UART_errors_lat));
				printf("\n");
				dump_buffer_to_file(&an_UART_errors_freq,"analyze/UART_errors_per.csv");
				dump_buffer_to_file(&an_UART_errors_lat,"analyze/UART_errors_lat.csv");
				destroy_analyze(&an_UART_errors_freq);
				destroy_analyze(&an_UART_errors_lat);
			
				printf("ANALYZE RESULTS - SYS_MON:\n");
				printf("avg period:\t %0.4f ms\n",get_avg(&an_sys_mon_freq));
				printf("avg freq:\t %0.4f hz\n",1/(get_avg(&an_sys_mon_freq))*1e3);
				printf("avg latency\t %0.4f ms\n",get_avg(&an_sys_mon_lat));
				printf("\n");
				dump_buffer_to_file(&an_sys_mon_freq,"analyze/sys_mon_per.csv");
				dump_buffer_to_file(&an_sys_mon_lat,"analyze/sys_mon_lat.csv");
				destroy_analyze(&an_sys_mon_freq);
				destroy_analyze(&an_sys_mon_lat);

				exit(1);
			}
		#endif
		
	}
	
	UDP_err_handler(closeUDPServerSocket(&udp_server),write_error_ptr);

	/*------------------------END OF FIRST THREAD------------------------*/

	//wait for the second thread to finish
	if(pthread_join(thread_server_to_planebone, NULL)) {
		error_write(FILENAME,"error joining thread_lisa_to_pc");
		exit(EXIT_FAILURE);
	}

	return 0;
}