static
Stree stree_remove(Stree s, Topform c)
{
  if (s == NULL)
    fatal_error("stree_remove, clause not found");
  else if (c->weight == s->weight) {
    clist_remove(c, s->clauses);
    if (clist_empty(s->clauses) && s->left == NULL && s->right == NULL) {
      clist_free(s->clauses);
      free_stree(s);
      return NULL;
    }
    else if (clist_empty(s->clauses))
      s->greatest_id = 0;
    else
      s->greatest_id = s->clauses->last->c->id;
  }
  else if (c->weight < s->weight)
    s->left = stree_remove(s->left, c);
  else
    s->right = stree_remove(s->right, c);

  {
    int a = s->left ? s->left->greatest_id : 0;
    int b = clist_empty(s->clauses) ? 0 : s->clauses->last->c->id;
    int c = s->right ? s->right->greatest_id : 0;
    int d = IMAX(b,c);
    s->greatest_id = IMAX(a,d);
  }
  s->n--;
  return s;
}  /* stree_remove */
Example #2
0
void smooth (float **in, float **out, long naxes[], float sigma, float radius)
{
    int i, j, k, l, xmin, ymin, xmax, ymax;
    float sumwt, sumflux, wt, rad;

    for (j=1; j <= naxes[2]; j++) {
	for (i=1; i <= naxes[1]; i++) {
	    xmin = IMAX (1, i - NINT(radius));
	    xmax = IMIN (i+NINT(radius), naxes[1]);
	    ymin = IMAX (1, j - NINT(radius));
	    ymax = IMIN (j+NINT(radius), naxes[2]);
	    sumwt = 0.;
	    sumflux = 0.;
	    for (l=ymin; l <= ymax; l++) {
		for (k=xmin; k <= xmax; k++) {
		    rad = sqrt((k-i)*(k-i)+(l-j)*(l-j));
		    if (rad <= radius) {
		        wt = exp (-rad*rad/2/sigma/sigma);
			sumwt += wt;
			sumflux += in[l][k] * wt;
		    };
		};	    
	    };
	    out[j][i] = sumflux / sumwt;
	};
    };
}
Example #3
0
/**
  \brief Add a node or an edge from an editable graph-object

  \param[in,out] ged The editable graph-object.
  \param[in] node First node
  \param[in] nnode Second node

  If \a node is different from \a nnode, then add the edge between \a node and \a nnode, and create node \a node and node \a
  nnode if they do not exists.  If \a node equals \a nnode, then add node \a node itself.

  \sa GMRFLib_ged_remove(), GMRFLib_ged_append_node(), GMRFLib_ged_append_graph()

*/
int GMRFLib_ged_add(GMRFLib_ged_tp * ged, int node, int nnode)
{
	/*
	 * add edge between node and nnode. add 'node' or 'nnode' to the set if not already present 
	 */
	if (node == nnode) {
		spmatrix_set(&(ged->Q), node, node, 1.0);
		/*
		 * workaround for internal ``bug'' in hash.c 
		 */
		spmatrix_value(&(ged->Q), node, node);
	} else {
		spmatrix_set(&(ged->Q), IMIN(node, nnode), IMAX(node, nnode), 1.0);
		spmatrix_set(&(ged->Q), node, node, 1.0);
		spmatrix_set(&(ged->Q), nnode, nnode, 1.0);
		/*
		 * workaround for internal ``bug'' in hash.c 
		 */
		spmatrix_value(&(ged->Q), IMIN(node, nnode), IMAX(node, nnode));
		spmatrix_value(&(ged->Q), node, node);
		spmatrix_value(&(ged->Q), nnode, nnode);
	}
	ged->max_node = IMAX(ged->max_node, IMAX(node, nnode));

	return GMRFLib_SUCCESS;
}
Example #4
0
void grab_pointer_position(int *src_x, int *src_y, int *width, int *height)
{
	int dest_x, dest_y;
	createWindow();
	removeTile();
	show_forever();
	show_toplevel();
	changeCursor(dpy, win);
	showWindow();
	window_main_loop(src_x, src_y, &dest_x, &dest_y);
	*width = IMAX(*src_x, dest_x) - IMIN(*src_x, dest_x);
	*height = IMAX(*src_y, dest_y) - IMIN(*src_y, dest_y);
}
Example #5
0
static void
fs_init (VisualFX * _this, PluginInfo * info)
{

  FSData *data;

  data = (FSData *) malloc (sizeof (FSData));

  data->fx_mode = FIREWORKS_FX;
  data->maxStars = 4096;
  data->stars = (Star *) malloc (data->maxStars * sizeof (Star));
  data->nbStars = 0;

  data->max_age_p = secure_i_param ("Fireworks Smallest Bombs");
  IVAL (data->max_age_p) = 80;
  IMIN (data->max_age_p) = 0;
  IMAX (data->max_age_p) = 100;
  ISTEP (data->max_age_p) = 1;

  data->min_age_p = secure_i_param ("Fireworks Largest Bombs");
  IVAL (data->min_age_p) = 99;
  IMIN (data->min_age_p) = 0;
  IMAX (data->min_age_p) = 100;
  ISTEP (data->min_age_p) = 1;

  data->nbStars_limit_p = secure_i_param ("Max Number of Particules");
  IVAL (data->nbStars_limit_p) = 512;
  IMIN (data->nbStars_limit_p) = 0;
  IMAX (data->nbStars_limit_p) = data->maxStars;
  ISTEP (data->nbStars_limit_p) = 64;

  data->fx_mode_p = secure_i_param ("FX Mode");
  IVAL (data->fx_mode_p) = data->fx_mode;
  IMIN (data->fx_mode_p) = 1;
  IMAX (data->fx_mode_p) = 3;
  ISTEP (data->fx_mode_p) = 1;

  data->nbStars_p = secure_f_feedback ("Number of Particules (% of Max)");

  data->params = plugin_parameters ("Particule System", 7);
  data->params.params[0] = &data->fx_mode_p;
  data->params.params[1] = &data->nbStars_limit_p;
  data->params.params[2] = 0;
  data->params.params[3] = &data->min_age_p;
  data->params.params[4] = &data->max_age_p;
  data->params.params[5] = 0;
  data->params.params[6] = &data->nbStars_p;

  _this->params = &data->params;
  _this->fx_data = (void *) data;
}
static
void greatest_check(Stree s)
{
  if (s == NULL)
    return;
  else {
    int a = s->left ? s->left->greatest_id : 0;
    int b = clist_empty(s->clauses) ? 0 : s->clauses->last->c->id;
    int c = s->right ? s->right->greatest_id : 0;
    int d = IMAX(b,c);
    int e = IMAX(a,d);
    if (e != s->greatest_id)
      fatal_error("greatest_check, stree corrupt");
  }
}  /* greatest_check */
Example #7
0
/* PUBLIC */
int arith_evaluate(Term t, BOOL *evaluated)
{
  if (!arith_term(t)) {
    *evaluated = FALSE;
    return 0;
  }

  if (VARIABLE(t))
    return VARNUM(t);
  else {
    int sn = SYMNUM(t);

    if (sn == Div_sn || sn == Mod_sn) {
      int d = arith_evaluate(ARG(t,1), evaluated);
      if (d == 0) {
	*evaluated = FALSE;
	return 0;
      }
      else if (sn == Div_sn)
	return arith_evaluate(ARG(t,0), evaluated) / d;
      else
	return modulo(arith_evaluate(ARG(t,0), evaluated), d);
    }

    else if (sn == Sum_sn)
      return arith_evaluate(ARG(t,0), evaluated) + arith_evaluate(ARG(t,1), evaluated);
    else if (sn == Prod_sn)
      return arith_evaluate(ARG(t,0), evaluated) * arith_evaluate(ARG(t,1), evaluated);
    else if (sn == Neg_sn)
      return -arith_evaluate(ARG(t,0), evaluated);
    else if (sn == Abs_sn)
      return abs(arith_evaluate(ARG(t,0), evaluated));
    else if (sn == Domain_size_sn)
      return Domain_size;
    else if (sn == Min_sn) {
      int a0 = arith_evaluate(ARG(t,0), evaluated);
      int a1 = arith_evaluate(ARG(t,1), evaluated);
      return IMIN(a0,a1);
    }
    else if (sn == Max_sn) {
      int a0 = arith_evaluate(ARG(t,0), evaluated);
      int a1 = arith_evaluate(ARG(t,1), evaluated);
      return IMAX(a0,a1);
    }
    else if (sn == Lt_sn)
      return arith_evaluate(ARG(t,0), evaluated) <  arith_evaluate(ARG(t,1), evaluated);
    else if (sn == Le_sn)
      return arith_evaluate(ARG(t,0), evaluated) <= arith_evaluate(ARG(t,1), evaluated);
    else if (sn == Gt_sn)
      return arith_evaluate(ARG(t,0), evaluated) >  arith_evaluate(ARG(t,1), evaluated);
    else if (sn == Ge_sn)
      return arith_evaluate(ARG(t,0), evaluated) >= arith_evaluate(ARG(t,1), evaluated);
    else if (sn == Eq_sn)
      return arith_evaluate(ARG(t,0), evaluated) == arith_evaluate(ARG(t,1), evaluated);
    else {
      fatal_error("arith_evaluate, operation not handled");
      return INT_MIN;
    }
  }
}  /* arith_evaluate */
/* PUBLIC */
void init_semantics(Plist interp_terms, Clock eval_clock,
		    char *type, int eval_limit, int eval_var_limit)
{
  Plist p;
  int max_domain_size = 0;
  
  for (p = interp_terms; p; p = p->next) {
    Interp a = compile_interp(p->v, FALSE);
    max_domain_size = IMAX(max_domain_size, interp_size(a));
    Compiled_interps = plist_prepend(Compiled_interps, a);
  }
  Compiled_interps = reverse_plist(Compiled_interps);
  if (str_ident(type, "false_in_all"))
    False_in_all = TRUE;
  else if (str_ident(type, "false_in_some"))
    False_in_all = FALSE;
  else
    fatal_error("init_semantics, bad type");
  if (eval_var_limit == -1)
    Eval_limit = eval_limit;
  else {
    Eval_limit = int_power(max_domain_size, eval_var_limit);
    printf("eval_limit reset to %d.\n", Eval_limit);
  }
  Eval_clock = eval_clock;
}  /* init_semantics */
Example #9
0
/******************************************************************************
 *  Function        : SetMode
 *  Description     : Set ECB/CBC mode for encryption/decryption
 *  Input           : N/A
 *  Return          : N/A
 *  Note            : N/A
 *  Globals Changed : N/A
 ******************************************************************************
 */
void SetMode(void)
{
  BYTE key;
  BYTE kbdbuf[18];
  
  memset(kbdbuf, 0, sizeof(kbdbuf));
  DispLineMW("ENC/DEC Mode:", MW_LINE1, MW_CLRDISP|MW_BIGFONT);
  DispLineMW("[ENTER] - ECB", MW_LINE3, MW_BIGFONT);
  DispLineMW("[CLEAR] - CBC", MW_LINE5, MW_BIGFONT);
  switch (key=APM_WaitKey(9000, 0)) {
    case MWKEY_ENTER:
      KDLL_SetOpMode(MODE_ECB, kbdbuf);
      AcceptBeep();
      break;
    case MWKEY_CLR:
      DispLineMW("Init Vector:", MW_LINE1, MW_CLRDISP|MW_BIGFONT);
      if (!APM_GetKbd(HEX_INPUT+ECHO+MW_LINE3+RIGHT_JUST, IMIN(16)+IMAX(16), kbdbuf))
        return;
      compress(&kbdbuf[1], &kbdbuf[1], 8);
      KDLL_SetOpMode(MODE_CBC, &kbdbuf[1]);
      AcceptBeep();
      break;
    default:
      break;
  }
}
/* ==========================================================================
   get_score 
   ========================================================================== */
float get_score(int w_x[],int w_y[],int nwhisker_points,TMatrix2D I_Conv)
{
  float **conv_dat;
  float score = 0;
  int min_x,max_x;
  int *yy, x;
  int ncols, nrows;

  conv_dat = Mat2D_getDataFloat(I_Conv);
  ncols = Mat2D_getnCols(I_Conv);
  nrows = Mat2D_getnRows(I_Conv);
  
  min_x = IMAX(w_x[0],0);
  max_x = IMIN(w_x[nwhisker_points-1],nrows-1);

  get_spline(w_x,w_y,nwhisker_points,min_x, max_x, &yy);
  
  for (x=min_x;x<=max_x;x++)
    if (yy[x]>=0 && yy[x]<ncols)
      score += conv_dat[x][yy[x]];
  
  free_ivector(yy,min_x,max_x);

  return(score);
}
Example #11
0
static void get_chunk_info (int ndata, int *nchunks, int *chunksize)
  {
  static const int chunksize_min=100;
  static const int nchunks_max=10;
  *chunksize = IMAX(chunksize_min,(ndata+nchunks_max-1)/nchunks_max);
  if ((*chunksize)&1) ++(*chunksize);
  *nchunks = (ndata+*chunksize-1) / *chunksize;
  }
Example #12
0
int IMAX_VECTOR(int v[], unsigned long l)
/* Find largest value in v */
{
 unsigned long i;
 int m=v[0];
 for (i=1;i<l;i++) m=IMAX(m,v[i]);
 return(m);
}
Example #13
0
void tonality_get_info(TonalityAnalysisState *tonal, AnalysisInfo *info_out, int len)
{
   int pos;
   int curr_lookahead;
   float psum;
   int i;

   pos = tonal->read_pos;
   curr_lookahead = tonal->write_pos-tonal->read_pos;
   if (curr_lookahead<0)
      curr_lookahead += DETECT_SIZE;

   /* On long frames, look at the second analysis window rather than the first. */
   if (len > tonal->Fs/50 && pos != tonal->write_pos)
   {
      pos++;
      if (pos==DETECT_SIZE)
         pos=0;
   }
   if (pos == tonal->write_pos)
      pos--;
   if (pos<0)
      pos = DETECT_SIZE-1;
   OPUS_COPY(info_out, &tonal->info[pos], 1);
   /* If possible, look ahead for a tone to compensate for the delay in the tone detector. */
   for (i=0;i<3;i++)
   {
      pos++;
      if (pos==DETECT_SIZE)
         pos = 0;
      if (pos == tonal->write_pos)
         break;
      info_out->tonality = MAX32(0, -.03f + MAX32(info_out->tonality, tonal->info[pos].tonality-.05f));
   }
   tonal->read_subframe += len/(tonal->Fs/400);
   while (tonal->read_subframe>=8)
   {
      tonal->read_subframe -= 8;
      tonal->read_pos++;
   }
   if (tonal->read_pos>=DETECT_SIZE)
      tonal->read_pos-=DETECT_SIZE;

   /* The -1 is to compensate for the delay in the features themselves. */
   curr_lookahead = IMAX(curr_lookahead-1, 0);

   psum=0;
   /* Summing the probability of transition patterns that involve music at
      time (DETECT_SIZE-curr_lookahead-1) */
   for (i=0;i<DETECT_SIZE-curr_lookahead;i++)
      psum += tonal->pmusic[i];
   for (;i<DETECT_SIZE;i++)
      psum += tonal->pspeech[i];
   psum = psum*tonal->music_confidence + (1-psum)*tonal->speech_confidence;
   /*printf("%f %f %f %f %f\n", psum, info_out->music_prob, info_out->vad_prob, info_out->activity_probability, info_out->tonality);*/

   info_out->music_prob = psum;
}
Example #14
0
BOOLEAN procesoConsultaSaldoImp(void){
	int costServ = 0;
	BYTE kbdbuff[10];
	BYTE tmpPan[20 + 1];
	//BYTE aux[10];

	memset(kbdbuff, 0x00, sizeof(kbdbuff));
	memset(tmpPan,  0x00, sizeof(tmpPan));
	//memset(aux, 0x00, sizeof(aux));

	costServ = RSP_DATA.dd_amount;
	DispClrBelowMW(MW_LINE2);
	DispLineMW( "Costo Servicio:", MW_LINE3, MW_LEFT|MW_SPFONT );
	//split(aux, gToken_80.costoServicio, 2);
	//costServ = atoi(aux);
	DispAmnt( costServ, MW_LINE3, MW_SPFONT );
	if( SiNo() != 2 ) {  // 2 = Press Enter
		return FALSE;
	}
	DispLineMW( "DESLICE LA TARJETA", MW_LINE4, MW_SMFONT|MW_CENTER|MW_CLRDISP );

	if( GetCard( FALSE, FALSE ) == FALSE ){
		LongBeep();
		DispLineMW( "CONSULTA DE SALDO", MW_LINE1, MW_CENTER|MW_REVERSE|MW_SMFONT|MW_CLRDISP );
		DispLineMW( "TRANSACCION CANCELADA", MW_LINE3, MW_CENTER );
		APM_WaitKey(200, 0);
		return FALSE;
	}
	do
	{
		DispLineMW( "CONSULTA DE SALDO", MW_LINE1, MW_CENTER|MW_REVERSE|MW_CLRDISP|MW_SMFONT );
		DispLineMW( "INGRESE LOS ULTIMOS", MW_LINE3, MW_CENTER|MW_SPFONT );
		DispLineMW( "CUATRO DIGITOS", MW_LINE4, MW_CENTER|MW_SPFONT );
		DispLineMW( "DE LA TARJETA", MW_LINE5, MW_CENTER|MW_SPFONT );

		memset(kbdbuff, 0x00, sizeof(kbdbuff));
		APM_SetCol(7); // Set Columna for TextBox
		if (!APM_GetKbd(NUMERIC_INPUT + MW_SMFONT + MW_LINE7, IMIN(4) + IMAX(4), kbdbuff)){
			return FALSE;
		}
		// Compara los ultimo 4 digitos del Pan
		memset( tmpPan, 0x00, sizeof(tmpPan) );
		split( tmpPan, INPUT.sb_pan, 10 );
		RTrim( tmpPan, 'F');
	} while (memcmp(&kbdbuff[1], &tmpPan[strlen(tmpPan) - 4], 4) != 0);

	DispLineMW( "CONSULTA DE SALDO", MW_LINE1, MW_CENTER|MW_REVERSE|MW_SMFONT|MW_CLRDISP );
	DispLineMW( "Costo Servicio:", MW_LINE3, MW_LEFT|MW_SPFONT );
	DispAmnt(costServ, MW_LINE3, MW_SPFONT);

	if( !getPinblock() )
		return FALSE;

	INPUT.dd_amount = costServ;	// El costo del servicio debe viajar en el campo 4 en la proxima transaccion
	sprintf(gAmount, "%012d", INPUT.dd_amount);

	return TRUE;
}
Example #15
0
/**
  \brief Remove a node or an edge from an editable graph-object

  \param[in,out] ged The editable graph-object.
  \param[in] node First node
  \param[in] nnode Second node

  If \a node is different from \a nnode, then remove the edge between \a node and \a nnode. If \a node equals \a nnode, then
  remove node \a node itself. Note that if node \a node is removed, then so are all edges where \a node is a part of. 

  \sa GMRFLib_ged_add(), GMRFLib_ged_append_graph(), GMRFLib_ged_append_node()

*/
int GMRFLib_ged_remove(GMRFLib_ged_tp * ged, int node, int nnode)
{
	/*
	 * mark the edge between node and nnode as 'removed', or the node itself if they're equal 
	 */
	spmatrix_set(&(ged->Q), IMIN(node, nnode), IMAX(node, nnode), 0.0);

	return GMRFLib_SUCCESS;
}
Example #16
0
void dftint(float (*func)(float), float a, float b, float w, float *cosint,
	float *sinint)
{
	void dftcor(float w, float delta, float a, float b, float endpts[],
		float *corre, float *corim, float *corfac);
	void polint(float xa[], float ya[], int n, float x, float *y, float *dy);
	void realft(float data[], unsigned long n, int isign);
	static int init=0;
	int j,nn;
	static float aold = -1.e30,bold = -1.e30,delta,(*funcold)(float);
	static float data[NDFT+1],endpts[9];
	float c,cdft,cerr,corfac,corim,corre,en,s;
	float sdft,serr,*cpol,*spol,*xpol;

	cpol=vector(1,MPOL);
	spol=vector(1,MPOL);
	xpol=vector(1,MPOL);
	if (init != 1 || a != aold || b != bold || func != funcold) {
		init=1;
		aold=a;
		bold=b;
		funcold=func;
		delta=(b-a)/M;
		for (j=1;j<=M+1;j++)
			data[j]=(*func)(a+(j-1)*delta);
		for (j=M+2;j<=NDFT;j++)
			data[j]=0.0;
		for (j=1;j<=4;j++) {
			endpts[j]=data[j];
			endpts[j+4]=data[M-3+j];
		}
		realft(data,NDFT,1);
		data[2]=0.0;
	}
	en=w*delta*NDFT/TWOPI+1.0;
	nn=IMIN(IMAX((int)(en-0.5*MPOL+1.0),1),NDFT/2-MPOL+1);
	for (j=1;j<=MPOL;j++,nn++) {
		cpol[j]=data[2*nn-1];
		spol[j]=data[2*nn];
		xpol[j]=nn;
	}
	polint(xpol,cpol,MPOL,en,&cdft,&cerr);
	polint(xpol,spol,MPOL,en,&sdft,&serr);
	dftcor(w,delta,a,b,endpts,&corre,&corim,&corfac);
	cdft *= corfac;
	sdft *= corfac;
	cdft += corre;
	sdft += corim;
	c=delta*cos(w*a);
	s=delta*sin(w*a);
	*cosint=c*cdft-s*sdft;
	*sinint=s*cdft+c*sdft;
	free_vector(cpol,1,MPOL);
	free_vector(spol,1,MPOL);
	free_vector(xpol,1,MPOL);
}
/* PUBLIC */
int max_clause_symbol_count(Plist p)
{
  if (p == NULL)
    return INT_MIN;
  else {
    int max_rest = max_clause_symbol_count(p->next);
    Topform c = p->v;
    return IMAX(clause_symbol_count(c->literals), max_rest);
  }
}  /* max_clause_symbol_count */
/* PUBLIC */
int most_literals(Plist clauses)
{
  int max = -1;
  Plist p;
  for (p = clauses; p; p = p->next) {
    Topform c = p->v;
    int n = number_of_literals(c->literals);
    max = IMAX(max,n);
  }
  return max;
}  /* most_literals */
/* PUBLIC */
int term_depth(Term t)
{
  if (VARIABLE(t) || CONSTANT(t))
    return 0;
  else {
    int i;
    int max = 0;
    for (i = 0; i < ARITY(t); i++) {
      int d = term_depth(ARG(t,i));
      max = IMAX(max,d);
    }
    return max+1;
  }
}  /* term_depth */
Example #20
0
// Internal use
static field_t * probe_create_metafield_ext(const probe_t * probe, const char * name, size_t depth)
{
    uint16_t src_port;

    // TODO to generalize to any metafield
    if (strcmp(name, "flow_id") != 0) return NULL;

    // TODO We've hardcoded the flow-id in the src_port and we only support the "flow_id" metafield
    // In IPv6, flow_id should be set thanks to probe_set_field
    // We substract 24000 to the port (see probe_set_metafield_ext)
    return probe_extract(probe, "src_port", &src_port) ?
        IMAX("flow_id", src_port - 24000) :
        NULL;
}
Example #21
0
void tonality_get_info(TonalityAnalysisState *tonal, AnalysisInfo *info_out, int len)
{
   int pos;
   int curr_lookahead;
   float psum;
   int i;

   pos = tonal->read_pos;
   curr_lookahead = tonal->write_pos-tonal->read_pos;
   if (curr_lookahead<0)
      curr_lookahead += DETECT_SIZE;

   if (len > 480 && pos != tonal->write_pos)
   {
      pos++;
      if (pos==DETECT_SIZE)
         pos=0;
   }
   if (pos == tonal->write_pos)
      pos--;
   if (pos<0)
      pos = DETECT_SIZE-1;
   OPUS_COPY(info_out, &tonal->info[pos], 1);
   tonal->read_subframe += len/120;
   while (tonal->read_subframe>=4)
   {
      tonal->read_subframe -= 4;
      tonal->read_pos++;
   }
   if (tonal->read_pos>=DETECT_SIZE)
      tonal->read_pos-=DETECT_SIZE;

   /* Compensate for the delay in the features themselves.
      FIXME: Need a better estimate the 10 I just made up */
   curr_lookahead = IMAX(curr_lookahead-10, 0);

   psum=0;
   /* Summing the probability of transition patterns that involve music at
      time (DETECT_SIZE-curr_lookahead-1) */
   for (i=0;i<DETECT_SIZE-curr_lookahead;i++)
      psum += tonal->pmusic[i];
   for (;i<DETECT_SIZE;i++)
      psum += tonal->pspeech[i];
   psum = psum*tonal->music_confidence + (1-psum)*tonal->speech_confidence;
   /*printf("%f %f %f\n", psum, info_out->music_prob, info_out->tonality);*/

   info_out->music_prob = psum;
}
Example #22
0
BOOLEAN procesoConsultaSaldoCNB(void){
  
  BYTE kbdbuff[10];
  BYTE tmpPan[20 + 1];
  //BYTE aux[10];

  memset(kbdbuff, 0x00, sizeof(kbdbuff));
  memset(tmpPan,  0x00, sizeof(tmpPan));
  //memset(aux, 0x00, sizeof(aux));

  
  DispClrBelowMW(MW_LINE2);
  DispLineMW( "CONSULTA SALDO CNB", MW_LINE1, MW_CENTER|MW_REVERSE|MW_CLRDISP|MW_SMFONT );
  DispLineMW( "DESLICE LA TARJETA", MW_LINE4, MW_SMFONT|MW_CENTER|MW_CLRDISP );

  if( GetCard( FALSE, FALSE ) == FALSE ){
    LongBeep();
    DispLineMW( "CONSULTA SALDO CNB", MW_LINE1, MW_CENTER|MW_REVERSE|MW_SMFONT|MW_CLRDISP );
    DispLineMW( "TRANSACCION CANCELADA", MW_LINE3, MW_CENTER );
    APM_WaitKey(200, 0);
    return FALSE;
  }
  do
  {
    DispLineMW( "CONSULTA SALDO CNB", MW_LINE1, MW_CENTER|MW_REVERSE|MW_CLRDISP|MW_SMFONT );
    DispLineMW( "INGRESE LOS ULTIMOS", MW_LINE3, MW_CENTER|MW_SPFONT );
    DispLineMW( "CUATRO DIGITOS", MW_LINE4, MW_CENTER|MW_SPFONT );
    DispLineMW( "DE LA TARJETA", MW_LINE5, MW_CENTER|MW_SPFONT );

    memset(kbdbuff, 0x00, sizeof(kbdbuff));
    APM_SetCol(7); // Set Columna for TextBox
    if (!APM_GetKbd(NUMERIC_INPUT + MW_SMFONT + MW_LINE7, IMIN(4) + IMAX(4), kbdbuff)){
      return FALSE;
    }
    // Compara los ultimo 4 digitos del Pan
    memset( tmpPan, 0x00, sizeof(tmpPan) );
    split( tmpPan, INPUT.sb_pan, 10 );
    RTrim( tmpPan, 'F');
  } while (memcmp(&kbdbuff[1], &tmpPan[strlen(tmpPan) - 4], 4) != 0);

  DispLineMW( "CONSULTA SALDO CNB", MW_LINE1, MW_CENTER|MW_REVERSE|MW_SMFONT|MW_CLRDISP );
  

  if( !getPinblock() )
    return FALSE;

   return TRUE;
}
Example #23
0
/******************************************************************************
 *  Function        : SetDhostIdx
 *  Description     : Reset terminal DUKPT init key
 *  Input           : N/A
 *  Return          : TRUE;           // key load ok
 *                    FALSE;          // key load failed
 *  Note            : N/A
 *  Globals Changed : N/A
 ******************************************************************************
 */
BOOLEAN SetDhostIdx(void)
{
  BYTE kbdbuf[4];
  
  kbdbuf[0] = 1;
  kbdbuf[1] = '0' + dhost_idx;
  while (1) {
    DispLineMW("DHost Idx(0-4):", MW_LINE5, MW_CLRDISP|MW_BIGFONT);
    if (!APM_GetKbd(NUMERIC_INPUT+ECHO+MW_LINE7+MW_BIGFONT+RIGHT_JUST, IMIN(1)+IMAX(1), kbdbuf))
      return FALSE;
    if (kbdbuf[1] < '5')
      break;
    else
      LongBeep();
  }
  dhost_idx = kbdbuf[1] - '0';
  return TRUE;
}
Example #24
0
static void
ApproximateConcaveDecomposition(cpVect *verts, int count, cpFloat tol, cpPolylineSet *set)
{
	int first;
	cpVect *hullVerts = alloca(count*sizeof(cpVect));
	int hullCount = cpConvexHull(count, verts, hullVerts, &first, 0.0);
	
	if(hullCount != count){
		struct Notch notch = DeepestNotch(count, verts, hullCount, hullVerts, first, tol);
		
		if(notch.d > tol){
			cpFloat steiner_it = FindSteiner(count, verts, notch);
			
			if(steiner_it >= 0.0){
				int steiner_i = (int)steiner_it;
				cpVect steiner = cpvlerp(verts[steiner_i], verts[Next(steiner_i, count)], steiner_it - steiner_i);
				
				// Vertex counts NOT including the steiner point.
				int sub1_count = (steiner_i - notch.i + count)%count + 1;
				int sub2_count = count - (steiner_i - notch.i + count)%count;
				cpVect *scratch = alloca((IMAX(sub1_count, sub2_count) + 1)*sizeof(cpVect));
				
				for(int i=0; i<sub1_count; i++) scratch[i] = verts[(notch.i + i)%count];
				scratch[sub1_count] = steiner;
				ApproximateConcaveDecomposition(scratch, sub1_count + 1, tol, set);
				
				for(int i=0; i<sub2_count; i++) scratch[i] = verts[(steiner_i + 1 + i)%count];
				scratch[sub2_count] = steiner;
				ApproximateConcaveDecomposition(scratch, sub2_count + 1, tol, set);
				
				return;
			}
		}
	}
	
	cpPolyline *hull = cpPolylineMake(hullCount + 1);
	
	memcpy(hull->verts, hullVerts, hullCount*sizeof(cpVect));
	hull->verts[hullCount] = hullVerts[0];
	hull->count = hullCount + 1;
	
	cpPolylineSetPush(set, hull);
}
/* ==========================================================================
   get_I_Conv

   Convulve I_Conv with oriented filter according to the whisker angle
   ========================================================================== */
void get_I_Conv(int *w0_x,int *w0_y,int nwhisker_points, 
		TMatrix2D image, int min_y, int max_y,
		TMatrix2D filters[], TMatrix2D *I_Conv_p)
{
  int i,x_val;
  int *yy;
  int *angle_vec;
  int spline_len;  
  int filt_size;
  int min_x, max_x;
  int nrows;

  nrows = Mat2D_getnRows(image);

  /* calculate spline of w0 */

  min_x = IMAX(w0_x[0],0);
  max_x = IMIN(w0_x[nwhisker_points-1],nrows-1);

  filt_size = (Mat2D_getnRows(filters[0])-1)/2;

  get_spline(w0_x,w0_y,nwhisker_points,min_x-COL_WIDTH, max_x+COL_WIDTH, &yy);
  get_angle_vec(yy,min_x,max_x,COL_WIDTH,&angle_vec);

    /* for (i=0;i<nwhisker_points;i++) */
    /*    mexPrintf("w0[%d]: %d %d\n",i,w0_x[i],w0_y[i]); */
    /* mexPrintf("\n"); */
    /* for (x_val=min_x;x_val<=max_x;x_val++) */
    /*     mexPrintf("spline[%d]: %d angle = %d\n",x_val,yy[x_val],angle_vec[x_val]); */
    /*   mexPrintf("\n"); */

  /* convolve each column of I_Conv with correct filter (according to angle) */

  convolve_image_by_angle(image,filters,filt_size,angle_vec,
			  min_x,max_x,min_y,max_y,I_Conv_p);

  free_ivector(yy,min_x-COL_WIDTH, max_x+COL_WIDTH);
  free_ivector(angle_vec,min_x,max_x);

 /*  Mat2D_display(*I_Conv_p); */
}
Example #26
0
void mpinv(unsigned char u[], unsigned char v[], int n, int m)
{
	void mpmov(unsigned char u[], unsigned char v[], int n);
	void mpmul(unsigned char w[], unsigned char u[], unsigned char v[], int n,
		int m);
	void mpneg(unsigned char u[], int n);
	unsigned char *rr,*s;
	int i,j,maxmn,mm;
	float fu,fv;

	maxmn=IMAX(n,m);
	rr=cvector(1,1+(maxmn<<1));
	s=cvector(1,maxmn);
	mm=IMIN(MF,m);
	fv=(float) v[mm];
	for (j=mm-1;j>=1;j--) {
		fv *= BI;
		fv += v[j];
	}
	fu=1.0/fv;
	for (j=1;j<=n;j++) {
		i=(int) fu;
		u[j]=(unsigned char) i;
		fu=256.0*(fu-i);
	}
	for (;;) {
		mpmul(rr,u,v,n,m);
		mpmov(s,&rr[1],n);
		mpneg(s,n);
		s[1] -= 254;
		mpmul(rr,s,u,n,n);
		mpmov(u,&rr[1],n);
		for (j=2;j<n;j++)
			if (s[j]) break;
		if (j==n) {
			free_cvector(s,1,maxmn);
			free_cvector(rr,1,1+(maxmn<<1));
			return;
		}
	}
}
Example #27
0
_rle_init (FILE *fp, int bit_depth)
#endif
{
  int init_bits;
  rle_out *rle;

  /* Initial length for compression codes, one bit longer than the minimum
     number of bits needed to represent the set of pixel values.  The
     IMAX() and the addition of 1 bit are "because of some algorithmic
     constraints". */
  init_bits = IMAX(bit_depth, 2) + 1;

  rle = (rle_out *)_pl_xmalloc(sizeof(rle_out));
  rle->ofile = fp;
#ifdef LIBPLOTTER
  rle->outstream = out;
#endif
  rle->obuf = 0;
  rle->obits = 0;
  rle->oblen = 0;
  rle->code_clear = 1 << (init_bits - 1); 	   /* 100..000 */
  rle->code_eof = rle->code_clear + 1;    	   /* 100..001 */
  rle->rl_basecode = rle->code_eof + 1;   	   /* 100..010 */
  rle->out_bump_init = (1 << (init_bits - 1)) - 1; /* 011..111 */
  /* for images with a lot of runs, making out_clear_init larger will
     give better compression. */ 
						   /* 011..110 */
  rle->out_clear_init = (init_bits <= 3) ? 9 : (rle->out_bump_init - 1);
  rle->out_bits_init = init_bits;
  rle->max_ocodes = (1 << GIFBITS) - ((1 << (rle->out_bits_init - 1)) + 3);

  _did_clear (rle);
  _output (rle, rle->code_clear);
  rle->rl_count = 0;

  return rle;
}
Example #28
0
void TDTOD(Word P, Word N, Word ***P2_, Word *P1_, Word *k_)
{
      Word **P2,Pp,i,pp,n,k,m,j,P1,I,l;

Step1: /* Allocate P2. At the end of the loop k is # of pf's in P. */
      P2 = (Word**)GETARRAY((N+1)*(sizeof(Word*)/sizeof(Word))); /* ASSUMES THIS / IS EXACT! */
      Pp = P; k = 0;
      for(i = 1; i <= N; i++) {
	ADV(Pp,&pp,&Pp);
	n = LENGTH(pp);
	k += n;

       /* Finds I, the largest index in pp. */
	for(I = 0; pp != NIL; pp = RED(pp))
	  I = IMAX(THIRD(LELTI(FIRST(pp),PO_LABEL)),I);

	P2[i] = (Word*)GETARRAY(I+1);
	P2[i][0] = n; }

Step2: /* Construct P1. */
      P1 = NIL; m = k - 1;
      Pp = NIL;
      for(i = N; i > 0; i--) { Pp = COMP(LELTI(P,i),Pp); }
      for(Pp = INV(Pp); Pp != NIL; Pp = RED(Pp)) {
	for(pp = CINV(FIRST(Pp)); pp != NIL; pp = RED(pp)) {
	  l = LELTI(FIRST(pp),PO_LABEL);
	  FIRST2(RED(l),&i,&j);
	  P2[i][j] = m--;
	  P1 = COMP(l,P1); } }

Return: /* Prepare to return. */
      *P2_ = P2;
      *P1_ = P1;
      *k_  = k;
      return;
}
Example #29
0
static void compute_allocation_table(CELTMode *mode, int res)
{
   int i, j, eband, nBark;
   celt_int32_t *allocVectors;
   celt_int16_t *allocVectorsS;
   celt_int16_t *allocEnergy;
   const int C = CHANNELS(mode);

   /* Find the number of critical bands supported by our sampling rate */
   for (nBark=1;nBark<BARK_BANDS;nBark++)
    if (bark_freq[nBark+1]*2 >= mode->Fs)
       break;

   mode->nbAllocVectors = BITALLOC_SIZE;
   allocVectors = celt_alloc(sizeof(celt_int32_t)*(BITALLOC_SIZE*mode->nbEBands));
   allocEnergy = celt_alloc(sizeof(celt_int16_t)*(mode->nbAllocVectors*(mode->nbEBands+1)));
   /* Compute per-codec-band allocation from per-critical-band matrix */
   for (i=0;i<BITALLOC_SIZE;i++)
   {
      eband = 0;
      for (j=0;j<nBark;j++)
      {
         int edge, low;
         celt_int32_t alloc;
         edge = mode->eBands[eband+1]*res;
         alloc = band_allocation[i*BARK_BANDS+j];
         alloc = alloc*C*mode->mdctSize/256;
         if (edge < bark_freq[j+1])
         {
            int num, den;
            num = alloc * (edge-bark_freq[j]);
            den = bark_freq[j+1]-bark_freq[j];
            low = (num+den/2)/den;
            allocVectors[i*mode->nbEBands+eband] += low;
            eband++;
            allocVectors[i*mode->nbEBands+eband] += alloc-low;
         } else {
            allocVectors[i*mode->nbEBands+eband] += alloc;
         }
      }
   }
   /* Compute fine energy resolution and update the pulse allocation table to subtract that */
   for (i=0;i<mode->nbAllocVectors;i++)
   {
      int sum = 0;
      for (j=0;j<mode->nbEBands;j++)
      {
         int ebits;
         int min_bits=0;
         if (allocVectors[i*mode->nbEBands+j] > 0)
            min_bits = 1;
         ebits = IMAX(min_bits , allocVectors[i*mode->nbEBands+j] / (C*(mode->eBands[j+1]-mode->eBands[j])));
         if (ebits>7)
            ebits=7;
         /* The bits used for fine allocation can't be used for pulses */
         /* However, we give two "free" bits to all modes to compensate for the fact that some energy
            resolution is needed regardless of the frame size. */
         if (ebits>1)
            allocVectors[i*mode->nbEBands+j] -= C*(ebits-2);
         if (allocVectors[i*mode->nbEBands+j] < 0)
            allocVectors[i*mode->nbEBands+j] = 0;
         sum += ebits;
         allocEnergy[i*(mode->nbEBands+1)+j] = ebits;
      }
      allocEnergy[i*(mode->nbEBands+1)+mode->nbEBands] = sum;
   }
   mode->energy_alloc = allocEnergy;
   allocVectorsS = celt_alloc(sizeof(celt_int16_t)*(BITALLOC_SIZE*mode->nbEBands));
   for(i=0;i<(BITALLOC_SIZE*mode->nbEBands);i++)
     allocVectorsS[i] = (celt_int16_t)allocVectors[i];
   mode->allocVectors = allocVectorsS;
}
Example #30
0
/* CR 110929.4 get rid of extraneous args in declaration  and remove several 
 * variables not being used */
int
swapchains (int swaptries)
{
  int ci, cj, i, swap0ok;
  double metropolishastingsterm;
  void *swapptr;
  int cjmin, cjrange;

#define  MINSWAP  0.1
#define  BETADJUST  1.414
#define  INCADJUST  1.414
#define  MINHEAT  0.0001
#define  MAXHEAT  0.2
#define  MAXINC  100
#define  MININC  0.1
#define  PAUSESWAP 1000
#define SWAPDIST 7
// 5/27/2010  removed HADAPT stuff

  for (i = 0, swap0ok = 0; i < swaptries; i++)
  {

    do
    {
      ci = (int) (uniform () * numchains);
    } while (ci < 0 || ci >= numchains);

    if (numchains < 2*SWAPDIST + 3)
    {
      cjmin = 0;
      cjrange = numchains;
    }
    else
    {
      cjmin = IMAX(0,ci-SWAPDIST);
      cjrange = IMIN(numchains, ci+SWAPDIST) -cjmin;
    }
    do
    {
      cj = cjmin + (int) (uniform () * cjrange);
    } while (cj == ci || cj < 0 || cj >= numchains);
    if (ci < cj)
    {
      swapcount[cj][ci]++;
    }
    else
    {
      swapcount[ci][cj]++;
    }
    metropolishastingsterm = swapweight (ci, cj);
    if (metropolishastingsterm >= 1.0
        || metropolishastingsterm > uniform ())

    {
      swapptr = C[ci];
      C[ci] = C[cj];
      C[cj] = static_cast<chain *> (swapptr);
      if (ci < cj)

      {
        swapcount[ci][cj]++;
      }
      else
      {
        swapcount[cj][ci]++;
      }
      if (ci == 0 || cj == 0)
        swap0ok |= 1;
    }
  }
  return swap0ok;
}                               /* swapchains */