示例#1
0
void ec_laplace_encode(ec_enc * enc, int *value, unsigned fs, int decay)
{
	unsigned fl;
	int val = *value;
	fl = 0;
	if (val) {
		int s;
		int i;
		s = -(val < 0);
		val = (val + s) ^ s;
		fl = fs;
		fs = ec_laplace_get_freq1(fs, decay);
		/* Search the decaying part of the PDF. */
		for (i = 1; fs > 0 && i < val; i++) {
			fs *= 2;
			fl += fs + 2 * LAPLACE_MINP;
			fs = (fs * (int32_t) decay) >> 15;
		}
		/* Everything beyond that has probability LAPLACE_MINP. */
		if (!fs) {
			int di;
			int ndi_max;
			ndi_max =
			    (32768 - fl + LAPLACE_MINP - 1) >> LAPLACE_LOG_MINP;
			ndi_max = (ndi_max - s) >> 1;
			di = IMIN(val - i, ndi_max - 1);
			fl += (2 * di + 1 + s) * LAPLACE_MINP;
			fs = IMIN(LAPLACE_MINP, 32768 - fl);
			*value = (i + di + s) ^ s;
		} else {
示例#2
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;
}
示例#3
0
文件: analysis.c 项目: 0culus/ioq3
void run_analysis(TonalityAnalysisState *analysis, const CELTMode *celt_mode, const void *analysis_pcm,
                 int analysis_frame_size, int frame_size, int c1, int c2, int C, opus_int32 Fs,
                 int lsb_depth, downmix_func downmix, AnalysisInfo *analysis_info)
{
   int offset;
   int pcm_len;

   if (analysis_pcm != NULL)
   {
      /* Avoid overflow/wrap-around of the analysis buffer */
      analysis_frame_size = IMIN((DETECT_SIZE-5)*Fs/100, analysis_frame_size);

      pcm_len = analysis_frame_size - analysis->analysis_offset;
      offset = analysis->analysis_offset;
      do {
         tonality_analysis(analysis, NULL, celt_mode, analysis_pcm, IMIN(480, pcm_len), offset, c1, c2, C, lsb_depth, downmix);
         offset += 480;
         pcm_len -= 480;
      } while (pcm_len>0);
      analysis->analysis_offset = analysis_frame_size;

      analysis->analysis_offset -= frame_size;
   }

   analysis_info->valid = 0;
   tonality_get_info(analysis, analysis_info, frame_size);
}
示例#4
0
文件: smooth.c 项目: vvinuv/pymorph
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;
	};
    };
}
示例#5
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);
}
示例#6
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;
}
示例#7
0
void mpsqrt(unsigned char w[], unsigned char u[], unsigned char v[], int n,
	int m)
{
	void mplsh(unsigned char u[], int n);
	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);
	void mpsdv(unsigned char w[], unsigned char u[], int n, int iv, int *ir);
	int i,ir,j,mm;
	float fu,fv;
	unsigned char *r,*s;

	r=cvector(1,n<<1);
	s=cvector(1,n<<1);
	mm=IMIN(m,MF);
	fv=(float) v[mm];
	for (j=mm-1;j>=1;j--) {
		fv *= BI;
		fv += v[j];
	}
	fu=1.0/sqrt(fv);
	for (j=1;j<=n;j++) {
		i=(int) fu;
		u[j]=(unsigned char) i;
		fu=256.0*(fu-i);
	}
	for (;;) {
		mpmul(r,u,u,n,n);
		mplsh(r,n);
		mpmul(s,r,v,n,IMIN(m,n));
		mplsh(s,n);
		mpneg(s,n);
		s[1] -= 253;
		mpsdv(s,s,n,2,&ir);
		for (j=2;j<n;j++) {
			if (s[j]) {
				mpmul(r,s,u,n,n);
				mpmov(u,&r[1],n);
				break;
			}
		}
		if (j<n) continue;
		mpmul(r,u,v,n,IMIN(m,n));
		mpmov(w,&r[1],n);
		free_cvector(s,1,n<<1);
		free_cvector(r,1,n<<1);
		return;
	}
}
示例#8
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 */
示例#9
0
void  getm (int ci,struct edgemiginfo *edgem,struct edgemiginfo *sisem, struct edgemiginfo *oldedgem,struct edgemiginfo *oldsisem)
{
  int lastmigperiod;
//  int i, ii;

/*for (ii = 0;ii<2;ii++)
for (i=0;i<5;i++)
{
  checkptype[ii][i] = -100;
  checkrr[ii][i] = 0;
}  //8_30_10 */

  lastmigperiod = IMIN(edgem->e,lastperiodnumber-1);
  if ( sisem->edgeid == -1  /* sisem->mtall <= 0*/)  // no sister edge, or sister edge not in a period where migration can occur
  {
    assert(sisem->mtimeavail[0] == 0);
    edgem->mpall = mwork_single_edge (ci, edgem,oldedgem, lastmigperiod); 
  }
  else
  {
    assert (edgem->e == sisem->e);
    if (edgem->mtall <= 0)   // edge has no length in a period with migration,  so just do sister edge
    {
      assert(edgem->mtimeavail[0] == 0);
      sisem->mpall = mwork_single_edge (ci, sisem,oldsisem, lastmigperiod);
    }
    else
    {  // both edge and sis have length in periods with migration
      mwork_two_edges(ci, edgem, sisem,oldedgem, oldsisem, lastmigperiod, &edgem->mpall, &sisem->mpall);

    }
  }
}  //getm
/* ==========================================================================
   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);
}
示例#11
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;
  }
}
示例#12
0
int opus_decode(OpusDecoder *st, const unsigned char *data,
                opus_int32 len, opus_int16 *pcm, int frame_size, int decode_fec)
{
    VARDECL(float, out);
    int ret, i;
    int nb_samples;
    ALLOC_STACK;

    if(frame_size<=0)
    {
        RESTORE_STACK;
        return OPUS_BAD_ARG;
    }

    if (data != NULL && len > 0 && !decode_fec)
    {
        nb_samples = opus_decoder_get_nb_samples(st, data, len);
        if (nb_samples>0)
            frame_size = IMIN(frame_size, nb_samples);
        else
            return OPUS_INVALID_PACKET;
    }
    ALLOC(out, frame_size*st->channels, float);

    ret = opus_decode_native(st, data, len, out, frame_size, decode_fec, 0, NULL, 1);
    if (ret > 0)
    {
        for (i=0; i<ret*st->channels; i++)
            pcm[i] = FLOAT2INT16(out[i]);
    }
    RESTORE_STACK;
    return ret;
}
示例#13
0
文件: opus_sm.c 项目: jzombi/opus_sm
OpusSM* sm_init(int samplerate, int channels)
{
	OpusSM* sm = (OpusSM*)malloc(sizeof(OpusSM));
	sm->error = SM_OK;
	if (samplerate != SM_SUPPORTED_SAMPLERATE) {
		sm->error = SM_ERR_UNSUPPORTED_SAMPLERATE;
		sm->opus_enc = NULL;
		return sm;
	}
	/* application can be: (see opus_encoder_init() in src/opus_encoder.c)
	     OPUS_APPLICATION_VOIP
	     OPUS_APPLICATION_AUDIO
	     OPUS_APPLICATION_RESTRICTED_LOWDELAY */
	int error;
	sm->opus_enc = opus_encoder_create(samplerate, channels, OPUS_APPLICATION_VOIP, &error);
	if (error != 0) {
		sm->error = SM_ERR_OPUS_ENC_CREATE_FAILED;
		return sm;
	}

	sm->celt_enc = (CELTEncoder*)((char*)sm->opus_enc + sm->opus_enc->celt_enc_offset);
	celt_encoder_ctl(sm->celt_enc, CELT_GET_MODE(&sm->celt_mode));
	sm->lsb_depth = IMIN(16, sm->opus_enc->lsb_depth);
	sm->delay_compensation = 0;
	if (sm->opus_enc->application != OPUS_APPLICATION_RESTRICTED_LOWDELAY) sm->delay_compensation = sm->opus_enc->delay_compensation;
	return sm;
}
示例#14
0
 void savgol(double *c, int np, int nl, int nr, int ld, int m)  {
/*-------------------------------------------------------------------------------------------
 USES lubksb,ludcmp given below.
 Returns in c(np), in wrap-around order (see reference) consistent with the argument respns
 in routine convlv, a set of Savitzky-Golay filter coefficients. nl is the number of leftward
 (past) data points used, while nr is the number of rightward (future) data points, making
 the total number of data points used nl+nr+1. ld is the order of the derivative desired
 (e.g., ld = 0 for smoothed function). m is the order of the smoothing polynomial, also
 equal to the highest conserved moment; usual values are m = 2 or m = 4.
-------------------------------------------------------------------------------------------*/
int imj,ipj,j,k,kk,mm;
double d,fac,sum,**a,*b;

if (np < nl+nr+1 || nl < 0 || nr < 0 || ld > m || nl+nr < m)
	nrerror("bad args in savgol");

int *indx= intvector(1,m+1);
a=matrix(1,m+1,1,m+1);
b=vector(1,m+1);
for (ipj=0;ipj<=(m << 1);ipj++)
	{//Set up the normal equations of the desired least-squares fit
	sum=(ipj ? 0.0 : 1.0);
	for (k=1;k<=nr;k++)
		sum += pow((double)k,(double)ipj);
	for (k=1;k<=nl;k++)
		sum += pow((double)-k,(double)ipj);
	mm=IMIN(ipj,2*m-ipj);
	for (imj = -mm;imj<=mm;imj+=2)
		a[1+(ipj+imj)/2][1+(ipj-imj)/2]=sum;
	}

ludcmp(a, m+1, indx, &d); //Solve them: LU decomposition.

for (j=1;j<=m+1;j++)
	b[j]=0.0;

b[ld+1]=1.0; //Right-hand side vector is unit vector, depending on which derivative we want.

lubksb(a,m+1,indx,b); //Get one row of the inverse matrix.

for (kk=1;kk<=np;kk++)
	c[kk]=0.0; //Zero the output array (it may be bigger than number of coefficients).

for (k = -nl;k<=nr;k++)
	{
	sum=b[1];   //Each Savitzky-Golay coefficient is the dot product
				//of powers of an integer with the inverse matrix row.
	fac=1.0;
	for (mm=1;mm<=m;mm++)
		sum += b[mm+1]*(fac *= k);

	kk=((np-k) % np)+1; //Store in wrap-around order.
	c[kk]=sum;
	}

free_vector(b,1,m+1);
free_matrix(a,1,m+1,1,m+1);
free_intvector(indx,1,m+1);
}
示例#15
0
int IMIN_VECTOR(int v[], unsigned long l)
/* Find smallest value in v */
{
 unsigned long i;
 int m=v[0];
 for (i=1;i<l;i++) m=IMIN(m,v[i]);
 return(m);
}
示例#16
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;
}
示例#17
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;
}
示例#18
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);
}
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) {

	/* Check number of input arguments */
	if (nrhs != 4) {
		ERROR("Two input arguments are required.");
	}

	/* Check number of output arguments */
	if (nlhs > 2) {
		ERROR("Too many output arguments.");
    }

	DOUBLE *X = (DOUBLE*) mxGetData(prhs[0]);
	DOUBLE *rp = (DOUBLE*) mxGetData(prhs[1]);
	INT M = (INT) * (DOUBLE *) mxGetData(prhs[2]);
	INT N = (INT) * (DOUBLE *) mxGetData(prhs[3]);
//  INT M = (INT) mxGetM(prhs[0]);
//	INT N = (INT) mxGetN(prhs[0]);

	plhs[0] = mxCreateNumericMatrix(1, 1, MXPRECISION_CLASS, mxREAL);
	DOUBLE *obj = (DOUBLE *) mxGetData(plhs[0]);
	DOUBLE *deriv;
	INT derivFlag;

	if (nlhs == 2) {
		plhs[1] = mxCreateNumericMatrix(M * N, 1, MXPRECISION_CLASS, mxREAL);
		deriv = (DOUBLE *) mxGetData(plhs[1]);
		derivFlag = 1;
	} else {
		deriv = NULL;
		derivFlag = 0;
	}

	INT MN = IMIN(M, N);
	DOUBLE *svdVec = (DOUBLE *) MALLOC(1 * MN * sizeof(DOUBLE));
	DOUBLE *dataBuffer = (DOUBLE *) MALLOC(M * N * sizeof(DOUBLE));
	DOUBLE *derivVec = NULL;
	DOUBLE *vtMat = NULL;
	if (derivFlag == 1) {
		derivVec = (DOUBLE *) MALLOC(1 * MN * sizeof(DOUBLE));
		vtMat = (DOUBLE *) MALLOC(MN * N * sizeof(DOUBLE));
	}

	nuclear_approx_obj_grad(obj, deriv, X, rp, M, N, derivFlag, svdVec, vtMat, \
						dataBuffer, derivVec, NULL, 0);

	FREE(svdVec);
	FREE(dataBuffer);
	if (derivFlag == 1) {
		FREE(derivVec);
		FREE(vtMat);
	}
}
示例#20
0
文件: hxget.c 项目: rsanaie/hx
// (size < 0) means hxhold: head is left locked on exit.
//  Usual usage is: hxhold(), modify record, hxput().
int
hxget(HXFILE * hp, char *rp, int size)
{
    HXLOCAL	loc, *locp = &loc;
    int		leng, rpos, loops, junk;
    HXBUF       *bufp;
    char        *recp;

    if (!hp || !rp)
	return	HXERR_BAD_REQUEST;
    if (hxdebug > 1) {
        char    buf[25] = {};
        hx_save(hp, rp, size<0 ? -size-1 : size, buf, sizeof buf);
        DEBUG2("%s('%s...')", size < 0 ? "hold" : "get",
                                buf, size);
    }

    ENTER(locp, hp, rp, 1);
    if (size >= 0) {
       locp->mode = F_RDLCK;
        _hxlockset(locp, HEAD_LOCK);    // just lock head
    } else {
        _hxlockset(locp, HIGH_LOCK);    // lock head, +split if > head
        HOLD_HEAD(locp);
    }
    if (IS_MMAP(hp)) _hxremap(locp);

    leng	= 0;
    loops	= HX_MAX_CHAIN;
    bufp	= &locp->buf[0];
    bufp->next	= locp->head;

    do {
        if (!--loops)
    	    LEAVE(locp, HXERR_BAD_FILE);

        _hxload(locp, bufp, bufp->next);
        rpos = _hxfind(locp, bufp, locp->hash, rp, &junk);
    } while (rpos < 0 && bufp->next);

    if (rpos < 0)
    	LEAVE(locp, 0);

    recp = bufp->data + rpos;
    leng = RECLENG(recp);
    memcpy(rp, RECDATA(recp), IMIN(leng, size<0? -size-1 : size));

    LEAVE(locp, leng);
}
示例#21
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;
}
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) {

	/* Check number of input arguments */
	if (nrhs != 4) {
		ERROR("Four input arguments are required.");
    }

	/* Check number of output arguments */
	if (nlhs > 2) {
		ERROR("Too many output arguments.");
    }

	DOUBLE *Dc = (DOUBLE*) mxGetData(prhs[0]);
	INT rank = (INT) * (DOUBLE*) mxGetData(prhs[1]);
	INT M = (INT) * (DOUBLE*) mxGetData(prhs[2]);
	INT N = (INT) * (DOUBLE*) mxGetData(prhs[3]);

	INT K = (INT) mxGetN(prhs[0]);

	if ((INT) mxGetM(prhs[0]) != M * N) {
		ERROR("First dimension of Dc matrix does not match size of dictionary atoms.");
	} else if (rank > IMIN(M, N)) {
		ERROR("Input rank is larger than minimum dimension of signal matrix.");
	}

	plhs[0] = mxCreateNumericMatrix(M * N, K, MXPRECISION_CLASS, mxREAL);
	plhs[1] = mxCreateNumericMatrix(1, 1, MXPRECISION_CLASS, mxREAL);
	DOUBLE *Dcr = (DOUBLE *) mxGetData(plhs[0]);
	DOUBLE *norm = (DOUBLE *) mxGetData(plhs[1]);

	datacpy(Dcr, Dc, M * N * K);
//	INT MINMN = IMIN(M, N);
//	INT MAXMN = IMAX(M, N);
//	DOUBLE *sv = (DOUBLE *) MALLOC(MINMN * 1 * sizeof(DOUBLE));
//	DOUBLE *svecsmall = (DOUBLE *) MALLOC(MINMN * MINMN * sizeof(DOUBLE));
//	DOUBLE *sveclarge = (DOUBLE *) MALLOC(MAXMN * MINMN * sizeof(DOUBLE));
//	DOUBLE *normvec = (DOUBLE *) MALLOC(K * 1 * sizeof(DOUBLE));
//	INT lwork = 0;
//	matrix_dictionary_proximal(Dcr, norm, tau, M, N, K, sv, svecsmall, sveclarge, normvec, \
			NULL, lwork);

	matrix_dictionary_hard_thresholding_parallel(Dcr, norm, rank, M, N, K);

//	FREE(sv);
//	FREE(svecsmall);
//	FREE(sveclarge);
//	FREE(normvec);
}
示例#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;
}
示例#24
0
void MultiplyMat(register double *m1, register double *m2, register double *res, const int M1, const int N1, const int M2, const int N2) {
	int timesInner = IMIN( N1, M2 );
	int timesRows = M1;
	int timesCols = N2;
	double sum;

	int row, col, inner;
	for( row = 0; row < timesRows; row++ )
	{
		for( col = 0; col < timesCols; col++ )
		{
			sum = 0;
			for( inner = 0; inner < timesInner; inner++ )
			{
				sum += m1[row*N1 + inner] * m2[inner*N2 + col];
			}
			*(res++) = sum;
		}
	}
}
/* ==========================================================================
   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); */
}
示例#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;
		}
	}
}
示例#27
0
// TODO: need a "now" take it as an argument
void simple_soft_render(struct simple_soft_ctx *ctx, Pixbuf *out, int64_t now, int64_t tick0)
{
	ctx->m = (ctx->m+1)&0x1;

	if(tick0+(ctx->maxfrms*1000)/ctx->maxsrc_rate - now > 1000/ctx->maxsrc_rate) {
		maxsrc_update(ctx->maxsrc, ctx->prev_buf, ctx->nr_samp/2);
		ctx->maxfrms++;
	}

	if(!ctx->rational_julia) {
		ctx->map_func(ctx->map_surf[ctx->m], ctx->map_surf[(ctx->m+1)&0x1], ctx->im_w, ctx->im_h, ctx->pd);
		maxblend(ctx->map_surf[ctx->m], maxsrc_get(ctx->maxsrc), ctx->im_w, ctx->im_h);
	}

	if(ctx->rational_julia) {
		maxblend(ctx->map_surf[(ctx->m+1)&0x1], maxsrc_get(ctx->maxsrc), ctx->im_w, ctx->im_h);
		ctx->map_func(ctx->map_surf[ctx->m], ctx->map_surf[(ctx->m+1)&0x1], ctx->im_w, ctx->im_h, ctx->pd);
	}

	// rather than just audio clock
	if((now - ctx->lastpalstep)*256/1024 >= 1) { // want pallet switch to take ~2 seconds
		pal_ctx_step(ctx->pal_ctx, IMIN((now - ctx->lastpalstep)*256/1024, 32));
		ctx->lastpalstep = now;
	}

	pallet_blit_Pixbuf(out, ctx->map_surf[ctx->m], ctx->im_w, ctx->im_h, pal_ctx_get_active(ctx->pal_ctx));
	//pallet_blit_Pixbuf(out, maxsrc_get(ctx->maxsrc), ctx->im_w, ctx->im_h, pal_ctx_get_active(ctx->pal_ctx));

	int newbeat = beat_ctx_count(ctx->beat);
	if(newbeat != ctx->beats) pal_ctx_start_switch(ctx->pal_ctx, newbeat);

	if(newbeat != ctx->beats && now - ctx->last_beat_time > 1000) {
		ctx->last_beat_time = now;
		update_points(ctx->pd, (now - tick0), 1);
	} else update_points(ctx->pd, (now - tick0), 0);
	ctx->beats = newbeat;
}
示例#28
0
void
printautoctable (FILE * outto, int numautoc, struct autoc **ac, char **ac_str,
                 const char *printacstring/*, int step*/)
{
  int i, j;
  double **acvals;
  int numacprint;
  char numstr[20];

  /* 4/9/09  change output for stdout so it only does tables for L[P] and split times, not tmrcas 
   the total number of autoc tables for stdout will then be npops */
  //numacprint = (outto == stdout) ? IMIN (numautoc, IFSTDOUTMAXSHOW) : numautoc;
  if (strcmp (printacstring, "Population Assignment Autocorrelations and Effective Sample Size Estimates") == 0)
  {
    numacprint = (outto == stdout) ? IMIN (nloci, IFSTDOUTMAXSHOW) : numautoc;
  }
  else
  {
    numacprint = (outto == stdout) ? IMIN (numautoc, IFSTDOUTMAXSHOW) : numautoc;
  }
  acvals = orig2d_alloc2Ddouble (numacprint, AUTOCTERMS);
  fprintf (outto, "\n%s\n", printacstring);
  for (i = 0; i < (int) strlen (printacstring); i++)
    fprintf (outto, "-");
  fprintf (outto, "\n");
  fprintf (outto,
           "   # Steps Between Values and Autocorrelation Estimates \n");
  fprintf (outto, "\tSteps ");
  for (j = 0; j < numacprint; j++)
    fprintf (outto, "\t %s", ac_str[j]);
  fprintf (outto, "\n");
  for (i = 0; i < AUTOCTERMS; i++)
  {
    if (ac[0][i].cov.n > (AUTOCCUTOFF / AUTOCSTEPSCALAR))
    {
      if (((float) autoc_checkstep[i] * AUTOCSTEPSCALAR) > 1e4)
      {
        sprintf (&numstr[0], "%.1e",
                 (float) autoc_checkstep[i] * AUTOCSTEPSCALAR);
        fprintf (outto, "\t%s", shorten_e_num (&numstr[0]));
        //fprintf (outto, "\t%.1e", (float) autoc_checkstep[i]*AUTOCSTEPSCALAR);
      }
      else
      {
        fprintf (outto, "\t%d", autoc_checkstep[i] * AUTOCSTEPSCALAR);
      }
      for (j = 0; j < numacprint; j++)
      {
        acvals[j][i] = printautocvalue (outto, &ac[j][i]);
      }
      fprintf (outto, "\n");
    }
  }
  fprintf (outto, "\tESS");

/* integrate over autocorrelations values for values > 0.03 */

  for (j = 0; j < numacprint; j++)
    integrate_autoc (outto, ac[j], acvals[j]/*, step*/);
  fprintf (outto, "\n");
  orig2d_free2D ((void **) acvals, numacprint);
}                               //printautoctable
示例#29
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 */
示例#30
0
int _mossNRsvdcmp(register double **a, const int m, const int n, double w[], register double **v)
{
	int flag,i,its,j,jj,k,l,nm;
	double anorm,c,f,g,h,s,scale,x,y,z, rv11[n+1];
	
	register double *rv1 = rv11;
	g = scale = anorm = 0.0;
	for (i=1;i<=n;i++) {
		l=i+1;
		rv1[i]=scale*g;
		g=s=scale=0.0;
		if (i <= m) {
			for (k=i;k<=m;k++) scale += fabs(a[k][i]);
			if (scale) {
				for (k=i; k<=m; k++) {
					a[k][i] /= scale;
					s += a[k][i]*a[k][i];
				}
				f = a[i][i];
				g = -SIGN(sqrt(s), f);
				h=f*g-s;
				a[i][i]=f-g;
				for (j=l;j<=n;j++) {
					for (s=0.0,k=i;k<=m;k++) s += a[k][i]*a[k][j];
					f=s/h;
					for (k=i;k<=m;k++) a[k][j] += f*a[k][i];
				}
				for (k=i;k<=m;k++) a[k][i] *= scale;
			}
		}
		w[i]=scale *g;
		g=s=scale=0.0;
		if (i <= m && i != n) {
			for (k=l;k<=n;k++) scale += fabs(a[i][k]);
			if (scale) {
				for (k=l;k<=n;k++) {
					a[i][k] /= scale;
					s += a[i][k]*a[i][k];
				}
				f=a[i][l];
				g = -SIGN(sqrt(s),f);
				h=f*g-s;
				a[i][l]=f-g;
				for (k=l;k<=n;k++) rv1[k]=a[i][k]/h;
				for (j=l;j<=m;j++) {
					for (s=0.0,k=l;k<=n;k++) s += a[j][k]*a[i][k];
					for (k=l;k<=n;k++) a[j][k] += s*rv1[k];
				}
				for (k=l;k<=n;k++) a[i][k] *= scale;
			}
		}
		anorm=FMAX(anorm,(fabs(w[i])+fabs(rv1[i])));
	}

	for (i=n;i>=1;i--) {
		if (i < n) {
			if (g) {
				for (j=l;j<=n;j++) v[j][i]=(a[i][j]/a[i][l])/g;
				for (j=l;j<=n;j++) {
					for (s=0.0,k=l;k<=n;k++) s += a[i][k]*v[k][j];
					for (k=l;k<=n;k++) v[k][j] += s*v[k][i];
				}
			}
			for (j=l;j<=n;j++) v[i][j]=v[j][i]=0.0;
		}
		v[i][i]=1.0;
		g=rv1[i];
		l=i;
	}

	for (i = IMIN(m,n); i>=1; i--) {
		l=i+1;
		g=w[i];
		for (j=l;j<=n;j++) a[i][j]=0.0;
		if (g) {
			g=1.0/g;
			for (j=l;j<=n;j++) {
				for (s=0.0,k=l;k<=m;k++) s += a[k][i]*a[k][j];
				f = (s/a[i][i])*g;
				for (k=i;k<=m;k++) a[k][j] += f*a[k][i];
			}
			for (j=i;j<=m;j++) a[j][i] *= g;
		} else for (j=i;j<=m;j++) a[j][i]=0.0;
		++a[i][i];
	}

	for (k=n;k>=1;k--) {
		for (its=1;its<=30;its++) {
			flag=1;
			for (l=k;l>=1;l--) {
				nm=l-1;
				if ((double)(fabs(rv1[l])+anorm) == anorm) {
					flag=0;
					break;
				}
				if ((double)(fabs(w[nm])+anorm) == anorm) break;
			}
			if (flag) {
				c=0.0;
				s=1.0;
				for (i=l;i<=k;i++) {
					f=s*rv1[i];
					rv1[i]=c*rv1[i];
					if ((double)(fabs(f)+anorm) == anorm) break;
					g=w[i];
					h=PYTHAG(f,g);
					w[i]=h;
					h=1.0/h;
					c=g*h;
					s = -f*h;
					for (j=1;j<=m;j++) {
						y=a[j][nm];
						z=a[j][i];
						a[j][nm]=y*c+z*s;
						a[j][i]=z*c-y*s;
					}
				}
			}
			z=w[k];
			if (l == k) {
				if (z < 0.0) {
					w[k] = -z;
					for (j=1;j<=n;j++) v[j][k] = -v[j][k];
				}
				break;
			}
			if (its == 30) {
				//sprintf(err, "%s: no convergence in 30 svdcmp iterations", me);
				//biffAdd(MOSS, err);
				return 1;
			}
			x=w[l];
			nm=k-1;
			y=w[nm];
			g=rv1[nm];
			h=rv1[k];
			f=((y-z)*(y+z)+(g-h)*(g+h))/(2.0*h*y);
			g=PYTHAG(f,1.0);
			f=((x-z)*(x+z)+h*((y/(f+SIGN(g,f)))-h))/x;
			c=s=1.0;
			for (j=l;j<=nm;j++) {
				i=j+1;
				g=rv1[i];
				y=w[i];
				h=s*g;
				g=c*g;
				z=PYTHAG(f,h);
				rv1[j]=z;
				c=f/z;
				s=h/z;
				f=x*c+g*s;
				g = g*c-x*s;
				h=y*s;
				y *= c;
				for (jj=1;jj<=n;jj++) {
					x=v[jj][j];
					z=v[jj][i];
					v[jj][j]=x*c+z*s;
					v[jj][i]=z*c-x*s;
				}
				z=PYTHAG(f,h);
				w[j]=z;
				if (z) {
					z=1.0/z;
					c=f*z;
					s=h*z;
				}
				f=c*g+s*y;
				x=c*y-s*g;
				for (jj=1;jj<=m;jj++) {
					y=a[jj][j];
					z=a[jj][i];
					a[jj][j]=y*c+z*s;
					a[jj][i]=z*c-y*s;
				}
			}
			rv1[l]=0.0;
			rv1[k]=f;
			w[k]=x;
		}
	}

	//free(rv1);

	return 0;
}