Esempio n. 1
0
int main_vecov(int c, char *v[])
{
	if (c == 2) if_help_is_requested_print_it_and_exit_the_program(v[1]);
	char *filename_out = pick_option(&c, &v, "o", "-");
	if (c < 3) {
		fprintf(stderr,
		"usage:\n\t%s {sum|min|max|avg|weisz} [v1 ...] [-o out]\n", *v);
		//          0  1                          2  3
		return EXIT_FAILURE;
	}
	int n = c - 2;
	char *operation_name = v[1];
	void (*f)(float*,float*,int,int) = NULL;
	if (0 == strcmp(operation_name, "sum"))   f = float_sum;
	if (0 == strcmp(operation_name, "mul"))   f = float_mul;
	if (0 == strcmp(operation_name, "prod"))  f = float_mul;
	if (0 == strcmp(operation_name, "cprod")) f = float_cprod;
	if (0 == strcmp(operation_name, "cmul"))  f = float_cprod;
	if (0 == strcmp(operation_name, "avg"))   f = float_avg;
	if (0 == strcmp(operation_name, "min"))   f = float_min;
	if (0 == strcmp(operation_name, "max"))   f = float_max;
	if (0 == strcmp(operation_name, "med"))   f = float_med;
	if (0 == strcmp(operation_name, "medi"))   f = float_med;
	if (0 == strcmp(operation_name, "modc"))   f = float_modc;
	if (0 == strcmp(operation_name, "weisz"))   f = float_weisz;
	//if (0 == strcmp(operation_name, "medv"))   f = float_medv;
	//if (0 == strcmp(operation_name, "rnd"))   f = float_pick;
	//if (0 == strcmp(operation_name, "first")) f = float_first;
	if (!f) fail("unrecognized operation \"%s\"", operation_name);
	float *x[n];
	int w[n], h[n], pd[n];
	for (int i = 0; i < n; i++)
		x[i] = iio_read_image_float_vec(v[i+2], w + i, h + i, pd + i);
	for (int i = 0; i < n; i++) {
		if (w[i] != *w || h[i] != *h || pd[i] != *pd)
			fail("%dth image sizes mismatch\n", i);
	}
	int out_pd = *pd;
	float (*y) = xmalloc(*w * *h * out_pd * sizeof*y);
#ifdef _OPENMP
#pragma omp parallel for
#endif
	for (int i = 0; i < *w * *h; i++) {
		float tmp[n][*pd];
		int ngood = 0;
		for (int j = 0; j < n; j++)
			if (isgood(x[j]+i**pd, *pd)) {
				for (int k = 0; k < *pd; k++)
					tmp[ngood][k] = x[j][i**pd+k];
				ngood += 1;
			}
		f(y + i**pd, tmp[0], *pd, ngood);
	}
	iio_write_image_float_vec(filename_out, y, *w, *h, *pd);
	free(y);
	for (int i = 0; i < n; i++)
		free(x[i]);
	return EXIT_SUCCESS;
}
Esempio n. 2
0
int main(int c, char *v[])
{
	int gpar = atoi(pick_option(&c, &v, "g", "1"));
	if (c < 4) {
		fprintf(stderr,
		"usage:\n\t%s {sum|min|max|avg|mul|med] [v1 ...] > out\n", *v);
		//          0  1                          2  3
		return EXIT_FAILURE;
	}
	int n = c - 2;
	char *operation_name = v[1];
	float (*f)(float *,int) = NULL;
	if (0 == strcmp(operation_name, "sum"))   f = float_sum;
	if (0 == strcmp(operation_name, "mul"))   f = float_mul;
	if (0 == strcmp(operation_name, "prod"))  f = float_mul;
	if (0 == strcmp(operation_name, "avg"))   f = float_avg;
	if (0 == strcmp(operation_name, "min"))   f = float_min;
	if (0 == strcmp(operation_name, "max"))   f = float_max;
	if (0 == strcmp(operation_name, "med"))   f = float_med;
	if (0 == strcmp(operation_name, "mod"))   f = float_mod;
	if (0 == strcmp(operation_name, "cnt"))   f = float_cnt;
	if (0 == strcmp(operation_name, "medi"))   f = float_med;
	if (0 == strcmp(operation_name, "medv"))   f = float_medv;
	if (0 == strcmp(operation_name, "rnd"))   f = float_pick;
	if (0 == strcmp(operation_name, "first")) f = float_first;
	if (*operation_name == 'q') {
		float p = atof(1 + operation_name);
		f = float_percentile;
		f(&p, -1);
	}
	if (!f) fail("unrecognized operation \"%s\"", operation_name);
	bool (*isgood)(float) = NULL;
	if (0 == gpar) isgood = isgood_finite;
	if (1 == gpar) isgood = isgood_numeric;
	if (2 == gpar) isgood = isgood_always;
	if (!isgood) fail("unrecognized goodness %d", gpar);
	float *x[n];
	int w[n], h[n];
	for (int i = 0; i < n; i++)
		x[i] = iio_read_image_float(v[i+2], w + i, h + i);
	for (int i = 0; i < n; i++) {
		if (w[i] != *w || h[i] != *h)
			fail("%dth image size mismatch\n", i);
	}
	float (*y) = xmalloc(*w * *h * sizeof*y);
	for (int i = 0; i < *w * *h; i++)
	{
		float tmp[n];
		int ngood = 0;
		for (int j = 0; j < n; j++)
			if (isgood(x[j][i]))
				tmp[ngood++] = x[j][i];
		y[i] = f(tmp, ngood);
	}
	iio_save_image_float("-", y, *w, *h);
	return EXIT_SUCCESS;
}
Esempio n. 3
0
int TSolver::checkout()
{int i;
 int SL=strlen(S);
 for (i=0;i<SL;i++)
   if (!isgood(S[i]))
     {seterr(E_FN);
      return 0;
     }
 return 1;
}
Esempio n. 4
0
long double TSolver::solvepolstp(const long double step)         //solves polish record
{if (S==NULL || !strlen(S)) seterr(E_VOID);
 if (!converted || !poled) seterr(E_EXPR);
 if (Err!=E_NO)
   {free(S);
    return 0;
   }
 char n[20]="";
 int sl=strlen(S);
 int i,j=0;
 long double r;

 nst_clear;
 if (!good)
   {for (i=0;i<sl;i++)
      if (!isgood(S[i]))
	{Err=E_FN;
	 return 0;
	}
    good=1;
   }
 for (i=0;i<sl;i++)
   {if (S[i]!=' ')
      {if (isnumc(S[i]) || (S[i]=='-' && S[i+1]!=' ')) {n[j++]=S[i];continue;}
       else
	 {switch (argcnt(S[i]))
	    {case 0: npush(gcalc(S[i],0,0,step));continue;
	     case 1: nst_end=gcalc(S[i],nst_end,0,step);continue;
	     case 2: r=gcalc(S[i],nst_end,npop(),step);
		     nst_end=r;
		     continue;
	     }
	  if (Err!=E_NO) return 0;
	 }
      }
    else
      if (strcmp(n,""))
	{n[j]='\0';
	 npush(_atold(n));
	 strcpy(n,"");
	 j=0;
	}
   }
 return R=npop();
}
Esempio n. 5
0
int main(int c, char *v[])
{
	if (c < 4) {
		fprintf(stderr,
		"usage:\n\t%s {sum|min|max|avg|mul|med] [v1 ...] > out\n", *v);
		//          0  1                          2  3
		return EXIT_FAILURE;
	}
	int n = c - 2;
	char *operation_name = v[1];
	float (*f)(float *,int) = NULL;
	if (0 == strcmp(operation_name, "sum"))   f = float_sum;
	if (0 == strcmp(operation_name, "mul"))   f = float_mul;
	if (0 == strcmp(operation_name, "prod"))  f = float_mul;
	if (0 == strcmp(operation_name, "avg"))   f = float_avg;
	if (0 == strcmp(operation_name, "min"))   f = float_min;
	if (0 == strcmp(operation_name, "max"))   f = float_max;
	if (0 == strcmp(operation_name, "med"))   f = float_med;
	if (0 == strcmp(operation_name, "mod"))   f = float_mod;
	if (0 == strcmp(operation_name, "medi"))   f = float_med;
	if (0 == strcmp(operation_name, "medv"))   f = float_medv;
	if (0 == strcmp(operation_name, "rnd"))   f = float_pick;
	if (0 == strcmp(operation_name, "first")) f = float_first;
	if (!f) fail("unrecognized operation \"%s\"", operation_name);
	float *x[n];
	int w[n], h[n];
	for (int i = 0; i < n; i++)
		x[i] = iio_read_image_float(v[i+2], w + i, h + i);
	for (int i = 0; i < n; i++) {
		if (w[i] != *w || h[i] != *h)
			fail("%dth image size mismatch\n", i);
	}
	float (*y) = xmalloc(*w * *h * sizeof*y);
	for (int i = 0; i < *w * *h; i++)
	{
		float tmp[n];
		int ngood = 0;
		for (int j = 0; j < n; j++)
			if (isgood(x[j][i]))
				tmp[ngood++] = x[j][i];
		y[i] = f(tmp, ngood);
	}
	iio_save_image_float("-", y, *w, *h);
	return EXIT_SUCCESS;
}
Esempio n. 6
0
int main() {
	// get number of elements
	bool ischanged;

	printme();

	do { 
		ischanged = false;
		// check array for inconsistent elements;
		for( unsigned int i=0; i < nelems - 1; i++) {
			if ( isgood(i, i+1) ) { 
				swap(i, i+1);
				ischanged = true;
			}
		}
		// print the array
		printme();
	} while(ischanged);

	return 0;
}