コード例 #1
0
ファイル: rndblk_m.c プロジェクト: ASP1234/Scilabv5.5.2
/*--------------------------------------------------------------------------*/
SCICOS_BLOCKS_IMPEXP void rndblk_m(scicos_block *block, int flag)
{
    double *y = NULL;
    double *rpar = NULL;
    double *z = NULL;
    int *ipar = NULL;
    int ny = 0, my = 0, i = 0, iy = 0;
    double sr = 0., si = 0., tl = 0;

    my = GetOutPortRows(block, 1);
    ny = GetOutPortCols(block, 1);
    ipar = GetIparPtrs(block);
    rpar = GetRparPtrs(block);
    y = GetRealOutPortPtrs(block, 1);
    z = GetDstate(block);

    if (flag == 2 || flag == 4)
    {
        if (ipar[0] == 0)
        {
            iy = (int)z[0];
            for (i = 0; i < my * ny; i++)
            {
                *(z + i + 1) = C2F(urand)(&iy);
            }
        }
        else
        {
            iy = (int)z[0];
            for (i = 0; i < my * ny; i++)
            {
                do
                {
                    sr = 2.0 * C2F(urand)(&iy) - 1.0;
                    si = 2.0 * C2F(urand)(&iy) - 1.0;
                    tl = sr * sr + si * si;
                }
                while (tl > 1.0);
                z[i + 1] = sr * (sqrt(-2.0 * log(tl) / tl));
            }
        }
        *(z) = iy;
    }

    if (flag == 1 || flag == 6)
    {
        for (i = 0; i < my * ny; i++)
        {
            *(y + i) = *(rpar + i) + (*(rpar + i + my * ny)) * (*(z + i + 1));
        }
    }
}
コード例 #2
0
ファイル: gainblk_ui16e.c プロジェクト: rossdrummond/scilab
/*--------------------------------------------------------------------------*/ 
SCICOS_BLOCKS_IMPEXP void gainblk_ui16e(scicos_block *block,int flag)
{
 if ((flag==1)|(flag==6)){
  int i = 0,j = 0,l = 0,ji = 0,jl = 0,il = 0;
  unsigned short *u = NULL,*y = NULL;
  int mu = 0,ny = 0,my = 0,mo = 0,no = 0;
  unsigned short *opar = NULL;
  double k = 0.,D = 0.,C = 0.;

  mo=GetOparSize(block,1,1);
  no=GetOparSize(block,1,2);
  mu=GetInPortRows(block,1);
  my=GetOutPortRows(block,1);
  ny=GetOutPortCols(block,1);
  u=Getuint16InPortPtrs(block,1);
  y=Getuint16OutPortPtrs(block,1);
  opar=Getuint16OparPtrs(block,1);

  k=pow(2,16);
  if (mo*no==1){
    for (i=0;i<ny*mu;++i){
     D=(double)(opar[0])*(double)(u[i]);
     if ((D>=k)|( D<0))
	{sciprint(_("overflow error"));
	 set_block_error(-4);
	 return;}
     else y[i]=(unsigned short)D;
    }
  }else{
     for (l=0;l<ny;l++)
	 {for (j=0;j<my;j++)
	      {D=0;
			 jl=j+l*my;
	       for (i=0;i<mu;i++)
		   {ji=j+i*my;
		    
		    il=i+l*mu;
		    C=(double)(opar[ji])*(double)(u[il]);
		    D=D + C;}
		    if ((D>=k)|( D<0))
			{sciprint(_("overflow error"));
			 set_block_error(-4);
			 return;}
		    else y[jl]=(unsigned short)D;
		  }
	     }
  }
 }
}
コード例 #3
0
ファイル: gainblk_i16n.c プロジェクト: rossdrummond/scilab
/*--------------------------------------------------------------------------*/ 
SCICOS_BLOCKS_IMPEXP void gainblk_i16n(scicos_block *block,int flag)
{
 if ((flag==1)|(flag==6)){
  int i = 0,j = 0,l = 0,ji = 0,jl = 0,il = 0;
  short *u = NULL,*y = NULL;
  int mu = 0,ny = 0,my = 0,mo = 0,no = 0;
  short *opar = NULL;
  double k = 0.,D = 0.,C = 0.,t = 0.;

  mo=GetOparSize(block,1,1);
  no=GetOparSize(block,1,2);
  mu=GetInPortRows(block,1);
  my=GetOutPortRows(block,1);
  ny=GetOutPortCols(block,1);
  u=Getint16InPortPtrs(block,1);
  y=Getint16OutPortPtrs(block,1);
  opar=Getint16OparPtrs(block,1);
  k=pow(2,16);
  if (mo*no==1){
    for (i=0;i<ny*mu;++i){
     D=(double)(opar[0])*(double)(u[i]);
     t=D-(double)((int)(D/(k)))*((k));
     if ((t>=k/2)|(-(t)>=k/2))
	 {if (t>=0) (t)=(-((k/2))+fabs(t-(double)((int)((t)/((k/2))))*((k/2))));
	  else (t)=-(-((k/2))+fabs(t-(double)((int)((t)/((k/2))))*((k/2))));}
     y[i]=(short)t;
    }
  }else{
     for (l=0;l<ny;l++)
	 {for (j=0;j<my;j++)
	      {D=0;
	       jl=j+l*my;
	       for (i=0;i<mu;i++)
		   {ji=j+i*my;
		    
		    il=i+l*mu;
		    C=(double)(opar[ji])*(double)(u[il]);
		    D=D + C;}
		    t=D-(double)((int)(D/(k)))*((k));
		    if ((t>=k/2)|(-(t)>=k/2))
		       {if (t>=0) (t)=(-((k/2))+fabs(t-(double)((int)((t)/((k/2))))*((k/2))));
			else (t)=-(-((k/2))+fabs(t-(double)((int)((t)/((k/2))))*((k/2))));}
		    y[jl]=(short)t;
		  }
	     }
  }
 }
}
コード例 #4
0
ファイル: matz_abs.c プロジェクト: ASP1234/Scilabv5.5.2
/*--------------------------------------------------------------------------*/
SCICOS_BLOCKS_IMPEXP void matz_abs(scicos_block *block, int flag)
{
    int i = 0;
    int mu = GetOutPortRows(block, 1);
    int nu = GetOutPortCols(block, 1);

    double *u1r = GetRealInPortPtrs(block, 1);
    double *u1i = GetImagInPortPtrs(block, 1);
    double *y1 = GetRealOutPortPtrs(block, 1);
    double *y2 = GetRealOutPortPtrs(block, 2);

    for (i = 0; i < mu * nu; i++)
    {
        *(y1 + i) = pow((pow(*(u1r + i), 2) + pow(*(u1i + i), 2)), 0.5);
        *(y2 + i) = atan2(*(u1i + i), *(u1r + i));
    }
}
コード例 #5
0
ファイル: matz_conj.c プロジェクト: rossdrummond/scilab
/*--------------------------------------------------------------------------*/ 
SCICOS_BLOCKS_IMPEXP void matz_conj(scicos_block *block,int flag)
{

	int i = 0;
	int mu = GetOutPortRows(block,1);
	int nu = GetOutPortCols(block,1);
	double *u1r = GetRealInPortPtrs(block,1);
	double *u1i = GetImagInPortPtrs(block,1);
	double *yr = GetRealOutPortPtrs(block,1);
	double *yi = GetImagOutPortPtrs(block,1);

	for (i=0;i<mu*nu;i++) 
	{
		*(yr+i)=*(u1r+i);
		*(yi+i)=-(*(u1i+i));
	}
}
コード例 #6
0
ファイル: matz_reimc.c プロジェクト: rossdrummond/scilab
/*--------------------------------------------------------------------------*/ 
SCICOS_BLOCKS_IMPEXP void matz_reimc(scicos_block *block,int flag)
{
	int i = 0;

	int mu = GetOutPortRows(block,1);
	int nu = GetOutPortCols(block,1);
	double *u1 = GetRealInPortPtrs(block,1);
	double *u2 = GetRealInPortPtrs(block,2);
	double *y1r = GetRealOutPortPtrs(block,1);
	double *y1i = GetImagOutPortPtrs(block,1);

	for (i=0;i<mu*nu;i++) 
	{
		*(y1r+i)=*(u1+i);
		*(y1i+i)=*(u2+i);
	}
}
コード例 #7
0
ファイル: gainblk_i32s.c プロジェクト: rossdrummond/scilab
/*--------------------------------------------------------------------------*/ 
SCICOS_BLOCKS_IMPEXP void gainblk_i32s(scicos_block *block,int flag)
{
 if ((flag==1)|(flag==6)){
  int i = 0,j = 0,l = 0,ji = 0,jl = 0,il = 0;
  long *u = NULL,*y = NULL;
  int mu = 0,ny = 0,my = 0,mo = 0,no = 0;
  long *opar = NULL;
  double k = 0.,D = 0.,C = 0.;

  mo=GetOparSize(block,1,1);
  no=GetOparSize(block,1,2);
  mu=GetInPortRows(block,1);
  my=GetOutPortRows(block,1);
  ny=GetOutPortCols(block,1);
  u=Getint32InPortPtrs(block,1);
  y=Getint32OutPortPtrs(block,1);
  opar=Getint32OparPtrs(block,1);

  k=pow(2,32)/2;
  if (mo*no==1){
    for (i=0;i<ny*mu;++i){
     D=(double)(opar[0])*(double)(u[i]);
     if (D>=k)  D=k-1;
     else if (D<-k) D=-k;
     y[i]=(long)D;
    }
  }else{
     for (l=0;l<ny;l++)
	 {for (j=0;j<my;j++)
	      {D=0;
	       jl=j+l*my;
	       for (i=0;i<mu;i++)
		   {ji=j+i*my;
		    
		    il=i+l*mu;
		    C=(double)(opar[ji])*(double)(u[il]);
		    D=D + C;}
		    if (D>=k)  D=k-1;
		    else if (D<-k) D=-k;
		    y[jl]=(long)D;
		  }
	     }
  }
 }
}
コード例 #8
0
/*--------------------------------------------------------------------------*/
SCICOS_BLOCKS_IMPEXP void matbyscal_e(scicos_block *block, int flag)
{
    if (flag == 1)
    {
        int i = 0;
        double v = 0.;
        int ut = GetInType(block, 1);
        int mu = GetOutPortRows(block, 1);
        int nu = GetOutPortCols(block, 1);
        double *rpar = GetRparPtrs(block);

        switch (ut)
        {
            case SCSINT32_N :
            {

                long *u1 = Getint32InPortPtrs(block, 1);
                long *u2 = Getint32InPortPtrs(block, 2);
                long *y1 = Getint32OutPortPtrs(block, 1);
                for (i = 0; i < mu * nu; i++)
                {
                    v = (double)u1[i] * (double)u2[0];
                    if ((v < rpar[0]) | (v > rpar[1]))
                    {
                        sciprint(_("overflow error"));
                        set_block_error(-4);
                        return;
                    }
                    else
                    {
                        y1[i] = (long)v;
                    }
                }
                break;
            }

            case SCSINT16_N :
            {

                short *u1 = Getint16InPortPtrs(block, 1);
                short *u2 = Getint16InPortPtrs(block, 2);
                short *y1 = Getint16OutPortPtrs(block, 1);
                for (i = 0; i < mu * nu; i++)
                {
                    v = (double)u1[i] * (double)u2[0];
                    if ((v < rpar[0]) | (v > rpar[1]))
                    {
                        sciprint(_("overflow error"));
                        set_block_error(-4);
                        return;
                    }
                    else
                    {
                        y1[i] = (short)v;
                    }
                }
                break;
            }

            case SCSINT8_N :
            {

                char *u1 = Getint8InPortPtrs(block, 1);
                char *u2 = Getint8InPortPtrs(block, 2);
                char *y1 = Getint8OutPortPtrs(block, 1);
                for (i = 0; i < mu * nu; i++)
                {
                    v = (double)u1[i] * (double)u2[0];
                    if ((v < rpar[0]) | (v > rpar[1]))
                    {
                        sciprint(_("overflow error"));
                        set_block_error(-4);
                        return;
                    }
                    else
                    {
                        y1[i] = (char)v;
                    }
                }
                break;
            }

            case SCSUINT32_N :
            {

                unsigned long *u1 = Getuint32InPortPtrs(block, 1);
                unsigned long *u2 = Getuint32InPortPtrs(block, 2);
                unsigned long *y1 = Getuint32OutPortPtrs(block, 1);
                for (i = 0; i < mu * nu; i++)
                {
                    v = (double)u1[i] * (double)u2[0];
                    if ((v < rpar[0]) | (v > rpar[1]))
                    {
                        sciprint(_("overflow error"));
                        set_block_error(-4);
                        return;
                    }
                    else
                    {
                        y1[i] = (unsigned long)v;
                    }
                }
                break;
            }

            case SCSUINT16_N :
            {

                unsigned short *u1 = Getuint16InPortPtrs(block, 1);
                unsigned short *u2 = Getuint16InPortPtrs(block, 2);
                unsigned short *y1 = Getuint16OutPortPtrs(block, 1);
                for (i = 0; i < mu * nu; i++)
                {
                    v = (double)u1[i] * (double)u2[0];
                    if ((v < rpar[0]) | (v > rpar[1]))
                    {
                        sciprint(_("overflow error"));
                        set_block_error(-4);
                        return;
                    }
                    else
                    {
                        y1[i] = (unsigned short)v;
                    }
                }
                break;
            }

            case SCSUINT8_N :
            {

                unsigned char *u1 = Getuint8InPortPtrs(block, 1);
                unsigned char *u2 = Getuint8InPortPtrs(block, 2);
                unsigned char *y1 = Getuint8OutPortPtrs(block, 1);
                for (i = 0; i < mu * nu; i++)
                {
                    v = (double)u1[i] * (double)u2[0];
                    if ((v < rpar[0]) | (v > rpar[1]))
                    {
                        sciprint(_("overflow error"));
                        set_block_error(-4);
                        return;
                    }
                    else
                    {
                        y1[i] = (unsigned char)v;
                    }
                }
                break;
            }

            default :
            {
                set_block_error(-4);
                return;
            }
        }
    }

}
コード例 #9
0
ファイル: matmul2_m.c プロジェクト: rossdrummond/scilab
/*--------------------------------------------------------------------------*/ 
SCICOS_BLOCKS_IMPEXP void matmul2_m(scicos_block *block,int flag)
{
	if (flag==1){
		int i = 0;
		int ut=GetInType(block,1);
		int mu=GetOutPortRows(block,1);
		int nu=GetOutPortCols(block,1);
		switch (ut)
		{
		case SCSREAL_N :{
			
			double *u1=GetRealInPortPtrs(block,1);
			double *u2=GetRealInPortPtrs(block,2);
			double *y1=GetRealOutPortPtrs(block,1);
			matmul2(y1,u1,u2,mu,nu);
			break;}

		case SCSINT32_N :{
			long *u1=Getint32InPortPtrs(block,1);
			long *u2=Getint32InPortPtrs(block,2);
			long *y1=Getint32OutPortPtrs(block,1);
			matmul2(y1,u1,u2,mu,nu);
			break;}

		case SCSINT16_N :{
			
			short *u1=Getint16InPortPtrs(block,1);
			short *u2=Getint16InPortPtrs(block,2);
			short *y1=Getint16OutPortPtrs(block,1);
			matmul2(y1,u1,u2,mu,nu);
			break;}

		case SCSINT8_N :{
			
			char *u1=Getint8InPortPtrs(block,1);
			char *u2=Getint8InPortPtrs(block,2);
			char *y1=Getint8OutPortPtrs(block,1);
			matmul2(y1,u1,u2,mu,nu);
			break;}

		case SCSUINT32_N :{
			
			unsigned long *u1=Getuint32InPortPtrs(block,1);
			unsigned long *u2=Getuint32InPortPtrs(block,2);
			unsigned long *y1=Getuint32OutPortPtrs(block,1);
			matmul2(y1,u1,u2,mu,nu);
			break;}

		case SCSUINT16_N :{
			
			unsigned short *u1=Getuint16InPortPtrs(block,1);
			unsigned short *u2=Getuint16InPortPtrs(block,2);
			unsigned short *y1=Getuint16OutPortPtrs(block,1);
			matmul2(y1,u1,u2,mu,nu);
			break;}

		case SCSUINT8_N :{
			
			unsigned char *u1=Getuint8InPortPtrs(block,1);
			unsigned char *u2=Getuint8InPortPtrs(block,2);
			unsigned char *y1=Getuint8OutPortPtrs(block,1);
			matmul2(y1,u1,u2,mu,nu);
			break;}

		case SCSCOMPLEX_N :{
			double *u1r=GetRealInPortPtrs(block,1);
			double *u2r=GetRealInPortPtrs(block,2);
			double *y1r=GetRealOutPortPtrs(block,1);
			double *u1i=GetImagInPortPtrs(block,1);
			double *u2i=GetImagInPortPtrs(block,2);
			double *y1i=GetImagOutPortPtrs(block,1);
			for (i=0;i<mu*nu;i++) 
			{y1r[i]=(u1r[i]*u2r[i])-(u1i[i]*u2i[i]);
			y1i[i]=(u1r[i]*u2i[i])+(u1i[i]*u2r[i]);}
			break;}

		default :{
			set_block_error(-4); 
			return;} 
		} 
	}

}
コード例 #10
0
ファイル: matmul2_e.c プロジェクト: rfabbri/scilab
/*--------------------------------------------------------------------------*/
SCICOS_BLOCKS_IMPEXP void matmul2_e(scicos_block *block, int flag)
{
    if (flag == 1)
    {
        int i = 0;
        double v = 0.;
        int ut = GetInType(block, 1);
        int mu = GetOutPortRows(block, 1);
        int nu = GetOutPortCols(block, 1);
        double *rpar = GetRparPtrs(block);

        switch (ut)
        {
            case SCSINT32_N :
            {

                SCSINT32_COP *u1 = Getint32InPortPtrs(block, 1);
                SCSINT32_COP *u2 = Getint32InPortPtrs(block, 2);
                SCSINT32_COP *y1 = Getint32OutPortPtrs(block, 1);
                for (i = 0; i < mu * nu; i++)
                {
                    v = (double)u1[i] * (double)u2[i];
                    if ((v < rpar[0]) | (v > rpar[1]))
                    {
                        sciprint(_("overflow error"));
                        set_block_error(-4);
                        return;
                    }
                    else
                    {
                        y1[i] = (SCSUINT32_COP)v;
                    }
                }
                break;
            }

            case SCSINT16_N :
            {

                SCSINT16_COP *u1 = Getint16InPortPtrs(block, 1);
                SCSINT16_COP *u2 = Getint16InPortPtrs(block, 2);
                SCSINT16_COP *y1 = Getint16OutPortPtrs(block, 1);
                for (i = 0; i < mu * nu; i++)
                {
                    v = (double)u1[i] * (double)u2[i];
                    if ((v < rpar[0]) | (v > rpar[1]))
                    {
                        sciprint(_("overflow error"));
                        set_block_error(-4);
                        return;
                    }
                    else
                    {
                        y1[i] = (SCSINT16_COP)v;
                    }
                }
                break;
            }

            case SCSINT8_N :
            {

                SCSINT8_COP *u1 = Getint8InPortPtrs(block, 1);
                SCSINT8_COP *u2 = Getint8InPortPtrs(block, 2);
                SCSINT8_COP *y1 = Getint8OutPortPtrs(block, 1);
                for (i = 0; i < mu * nu; i++)
                {
                    v = (double)u1[i] * (double)u2[i];
                    if ((v < rpar[0]) | (v > rpar[1]))
                    {
                        sciprint(_("overflow error"));
                        set_block_error(-4);
                        return;
                    }
                    else
                    {
                        y1[i] = (SCSINT8_COP)v;
                    }
                }
                break;
            }

            case SCSUINT32_N :
            {

                SCSUINT32_COP *u1 = Getuint32InPortPtrs(block, 1);
                SCSUINT32_COP *u2 = Getuint32InPortPtrs(block, 2);
                SCSUINT32_COP *y1 = Getuint32OutPortPtrs(block, 1);
                for (i = 0; i < mu * nu; i++)
                {
                    v = (double)u1[i] * (double)u2[i];
                    if ((v < rpar[0]) | (v > rpar[1]))
                    {
                        sciprint(_("overflow error"));
                        set_block_error(-4);
                        return;
                    }
                    else
                    {
                        y1[i] = (SCSUINT32_COP)v;
                    }
                }
                break;
            }

            case SCSUINT16_N :
            {

                SCSUINT16_COP *u1 = Getuint16InPortPtrs(block, 1);
                SCSUINT16_COP *u2 = Getuint16InPortPtrs(block, 2);
                SCSUINT16_COP *y1 = Getuint16OutPortPtrs(block, 1);
                for (i = 0; i < mu * nu; i++)
                {
                    v = (double)u1[i] * (double)u2[i];
                    if ((v < rpar[0]) | (v > rpar[1]))
                    {
                        sciprint(_("overflow error"));
                        set_block_error(-4);
                        return;
                    }
                    else
                    {
                        y1[i] = (SCSUINT16_COP)v;
                    }
                }
                break;
            }

            case SCSUINT8_N :
            {

                SCSUINT8_COP *u1 = Getuint8InPortPtrs(block, 1);
                SCSUINT8_COP *u2 = Getuint8InPortPtrs(block, 2);
                SCSUINT8_COP *y1 = Getuint8OutPortPtrs(block, 1);
                for (i = 0; i < mu * nu; i++)
                {
                    v = (double)u1[i] * (double)u2[i];
                    if ((v < rpar[0]) | (v > rpar[1]))
                    {
                        sciprint(_("overflow error"));
                        set_block_error(-4);
                        return;
                    }
                    else
                    {
                        y1[i] = (SCSUINT8_COP)v;
                    }
                }
                break;
            }

            default :
            {
                set_block_error(-4);
                return;
            }
        }
    }
}
コード例 #11
0
ファイル: matz_bksl.c プロジェクト: rossdrummond/scilab
/*--------------------------------------------------------------------------*/ 
SCICOS_BLOCKS_IMPEXP void matz_bksl(scicos_block *block,int flag)
{
	double *u1r = NULL,*u1i = NULL;
	double *u2r = NULL,*u2i = NULL;
	double *yr = NULL,*yi = NULL;
	int mu = 0,vu = 0,wu = 0;
	int nu1 = 0;
	int nu2 = 0;
	int info = 0;
	int i = 0,j = 0,l = 0,lw = 0,lu = 0,rw = 0,ij = 0,k = 0;
	mat_bksl_struct *ptr = NULL;
	double rcond = 0., ANORM = 0., EPS = 0.;

	vu =GetOutPortRows(block,1);
	wu =GetOutPortCols(block,1);
	mu =GetInPortRows(block,1);
	nu1 =GetInPortCols(block,1);
	nu2 =GetInPortCols(block,2);
	u1r=GetRealInPortPtrs(block,1);
	u1i=GetImagInPortPtrs(block,1);
	u2r=GetRealInPortPtrs(block,2);
	u2i=GetImagInPortPtrs(block,2);
	yr=GetRealOutPortPtrs(block,1);
	yi=GetImagOutPortPtrs(block,1);
	l=Max(mu,nu1);
	lw=Max(2*Min(mu,nu1),nu1+1);
	lu=Max(lw,Min(mu,nu1)+nu2);
	lw=Max(2*nu1,Min(mu,nu1)+lu);
	rw=2*nu1;

	/*init : initialization*/
	if (flag==4)
	{
		if((*(block->work)=(mat_bksl_struct*) scicos_malloc(sizeof(mat_bksl_struct)))==NULL)
		{
			set_block_error(-16);
			return;
		}
		ptr=*(block->work);
		if((ptr->ipiv=(int*) scicos_malloc(sizeof(int)*nu1))==NULL)
		{
			set_block_error(-16);
			scicos_free(ptr);
			return;
		}
		if((ptr->rank=(int*) scicos_malloc(sizeof(int)))==NULL)
		{
			set_block_error(-16);
			scicos_free(ptr->ipiv);
			scicos_free(ptr);
			return;
		}
		if((ptr->jpvt=(int*) scicos_malloc(sizeof(int)*nu1))==NULL)
		{
			set_block_error(-16);
			scicos_free(ptr->rank);
			scicos_free(ptr->ipiv);
			scicos_free(ptr);
			return;
		}
		if((ptr->iwork=(double*) scicos_malloc(sizeof(double)*2*nu1))==NULL)
		{set_block_error(-16);
		scicos_free(ptr->jpvt);
		scicos_free(ptr->rank);
		scicos_free(ptr->ipiv);
		scicos_free(ptr);
		return;
		}
		if((ptr->dwork=(double*) scicos_malloc(sizeof(double)*2*lw))==NULL)
		{
			set_block_error(-16);
			scicos_free(ptr->iwork);
			scicos_free(ptr->jpvt);
			scicos_free(ptr->rank);
			scicos_free(ptr->ipiv);
			scicos_free(ptr);
			return;
		}
		if((ptr->IN1F=(double*) scicos_malloc(sizeof(double)*(2*mu*nu1)))==NULL)
		{
			set_block_error(-16);
			scicos_free(ptr->dwork);
			scicos_free(ptr->iwork);
			scicos_free(ptr->jpvt);
			scicos_free(ptr->rank);
			scicos_free(ptr->ipiv);
			scicos_free(ptr);
			return;
		}
		if((ptr->IN1=(double*) scicos_malloc(sizeof(double)*(2*mu*nu1)))==NULL)
		{
			set_block_error(-16);
			scicos_free(ptr->IN1F);
			scicos_free(ptr->dwork);
			scicos_free(ptr->iwork);
			scicos_free(ptr->jpvt);
			scicos_free(ptr->rank);
			scicos_free(ptr->ipiv);
			scicos_free(ptr);
			return;
		}
		if((ptr->IN2X=(double*) scicos_malloc(sizeof(double)*(2*l*nu2)))==NULL)
		{
			set_block_error(-16);
			scicos_free(ptr->IN1);
			scicos_free(ptr->IN1F);
			scicos_free(ptr->dwork);
			scicos_free(ptr->iwork);
			scicos_free(ptr->jpvt);
			scicos_free(ptr->rank);
			scicos_free(ptr->ipiv);
			scicos_free(ptr);
			return;
		}
		if((ptr->IN2=(double*) scicos_malloc(sizeof(double)*(2*mu*nu2)))==NULL)
		{
			set_block_error(-16);
			scicos_free(ptr->IN2);
			scicos_free(ptr->IN1);
			scicos_free(ptr->IN1F);
			scicos_free(ptr->dwork);
			scicos_free(ptr->iwork);
			scicos_free(ptr->jpvt);
			scicos_free(ptr->rank);
			scicos_free(ptr->ipiv);
			scicos_free(ptr);
			return;
		}
	}

	/* Terminaison */
	else if (flag==5)
	{
		ptr=*(block->work);
		if((ptr->IN2)!=NULL)
		{
			scicos_free(ptr->ipiv);
			scicos_free(ptr->rank);
			scicos_free(ptr->jpvt);
			scicos_free(ptr->iwork);
			scicos_free(ptr->IN1F);
			scicos_free(ptr->IN1);
			scicos_free(ptr->IN2X);
			scicos_free(ptr->IN2);
			scicos_free(ptr->dwork);
			scicos_free(ptr);
			return;
		}
	}

	else
	{
		ptr=*(block->work);
		for (i=0;i<(mu*nu1);i++)   
		{
			ptr->IN1[2*i]=u1r[i];
			ptr->IN1[2*i+1]=u1i[i];
		}
		for (i=0;i<(mu*nu2);i++)   
		{
			ptr->IN2[2*i]=u2r[i];
			ptr->IN2[2*i+1]=u2i[i];
		}
		EPS=C2F(dlamch)("e",1L);
		ANORM=C2F(zlange)("1",&mu,&nu1,ptr->IN1,&mu,ptr->dwork);
		if (mu==nu1)
		{
			C2F(zlacpy)("F",&mu,&nu1,ptr->IN1,&mu,ptr->IN1F,&mu);
			C2F(zgetrf)(&nu1,&nu1,ptr->IN1F,&nu1,ptr->ipiv,&info);
			rcond=0;
			if (info==0)
			{
				C2F(zgecon)("1",&nu1,ptr->IN1F,&nu1,&ANORM,&rcond,ptr->dwork,ptr->iwork,&info);
				if (rcond>pow(EPS,0.5))
				{
					C2F(zgetrs)("N",&nu1,&nu2,ptr->IN1F,&nu1,ptr->ipiv,ptr->IN2,&nu1,&info);
					for (i=0;i<(mu*nu2);i++)
					{*(yr+i)=*(ptr->IN2+2*i);
					*(yi+i)=*(ptr->IN2+(2*i)+1);}
					return;
				}
			}
		}
		rcond=pow(EPS,0.5);
		for (i=0;i<nu1;i++)    *(ptr->jpvt+i)=0;
		C2F(zlacpy)("F",&mu,&nu2,ptr->IN2,&mu,ptr->IN2X,&l);
		C2F(zgelsy1)(&mu,&nu1,&nu2,ptr->IN1,&mu,ptr->IN2X,&l,ptr->jpvt,&rcond,ptr->rank,ptr->dwork,&lw,ptr->iwork,&info);
		if (info!=0)
		{
			if (flag!=6)
			{
				set_block_error(-7);
				return;
			}
		}
		k=0;
		for(j=0;j<wu;j++)
		{
			for(i=0;i<vu;i++)
			{
				ij=i+j*l;
				*(yr+k)=*(ptr->IN2X+2*ij);
				*(yi+k)=*(ptr->IN2X+(2*ij)+1);
				k++;
			}
		}
	}
}
コード例 #12
0
ファイル: mswitch.c プロジェクト: rossdrummond/scilab
/*--------------------------------------------------------------------------*/ 
SCICOS_BLOCKS_IMPEXP void  mswitch(scicos_block *block,int flag)
{
	if ((flag==1)||(flag==6))
	{
		int i = 0,j = 0,nin = 0,so = 0,my = 0,ny = 0;
		int mu = 0,nu = 0;
		int *ipar = NULL;
		double *u1 = NULL;
		void *uj = NULL;    
		void *y = NULL;
		
		y = GetOutPortPtrs(block,1);
		so = GetSizeOfOut(block,1);
		my = GetOutPortRows(block,1);
		ny = GetOutPortCols(block,1);
		u1 = GetRealInPortPtrs(block,1);
		ipar = GetIparPtrs(block);
		nin = GetNin(block);
		i = *(ipar+1);
		if (i==0) 
		{
			if (*u1>0) 
			{
				j=(int)floor(*u1);
			}
			else
			{
				j=(int)ceil(*u1);
			}
		}
		else if (i==1) 
		{
			if (*u1>0) 
			{
				j=(int)floor(*u1+.5);
			}
			else
			{
				j=(int)ceil(*u1-.5);
			}
		}
		else if (i==2) 
		{
			j=(int)ceil(*u1);
		}
		else if (i==3) 
		{
			j=(int)floor(*u1);
		}
		j=j+1-*ipar;
		j=Max(j,1);
		if (nin==2) 
		{
			mu=GetInPortRows(block,2);
			nu=GetInPortCols(block,2);
			uj=GetInPortPtrs(block,2);
			j=Min(j,mu*nu);
			memcpy(y,(char *)uj+(j-1)*my*ny*so,my*ny*so);
		}
		else
		{
			j=Min(j,nin-1);
			uj=GetInPortPtrs(block,j+1);
			memcpy(y,uj,my*ny*so);
		}
	}
}