#include "scicos_block.h"
#include <math.h>
#include <stdlib.h>
#include <stdio.h>
#include <memory.h>

void dsslti4(scicos_block *block,int flag)
{
  int un=1,lb,lc,ld;
  int nz=block->nz;
  double* z=block->z;
  double* rpar=block->rpar;
  double* y=block->outptr[0];
  double* u=block->inptr[0];
  int* outsz=block->outsz;
  int* insz=block->insz;
  double *w;
  
  lb=nz*nz;
  
  if (flag ==1 || flag ==6){
    lc=lb+nz*insz[0];
    ld=lc+nz*outsz[0];
    dmmul(&rpar[lc],outsz,z,&nz,y,outsz,outsz,&nz,&un);
    dmmul1(&rpar[ld],outsz,u,insz,y,outsz,outsz,insz,&un);
  }
  else if (flag ==2){
    if ((w=(double*)malloc(sizeof(double)*nz)) == NULL) return;    
    memcpy(w,z,nz*sizeof(double));
    dmmul(&rpar[0],&nz,w,&nz,z,&nz,&nz,&nz,&un);
    dmmul1(&rpar[lb],&nz,u,insz,z,&nz,&nz,insz,&un);
    free(w);
  }
}



