1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200
  
     | 
    
      
#include "stack-c.h"
/*******************************************
 * simple example with sparse matrix 
 * Display of a 
 *******************************************/
int F2C(ext14ca)(it,m,n,nel,mnel,icol,ar,ai)
     int *n,*m,*it,*nel,*mnel,*icol;
     double *ar,*ai;
{ 
  int i,iof = 0, j;
  for ( i = 0; i < *m ; i++) 
    {
      sciprint("Row %d, %d non zero elements\r\n",i+1,mnel[i]);
      for ( j = 0; j < mnel[i]; j++) 
	{
	  if (*it == 1) 
	      sciprint("(%d,%d) -> %f +i%f\r\n",i+1,icol[iof+j],
		       ar[iof+j],ai[iof+j]);
	  else 
	      sciprint("(%d,%d) -> %f \r\n",i+1,icol[iof+j],
		       ar[iof+j]);
	}
      iof += mnel[i];
    }
  return(0);
}
/*******************************************
 * simple example with sparse matrix 
 * 2*a copied into b 
 *******************************************/
int F2C(ext14cb)(it1,m1,n1,nel1,mnel1,icol1,ar1,ai1,
		 it2,m2,n2,nel2,mnel2,icol2,ar2,ai2)
     int *n1,*m1,*it1,*nel1,*mnel1,*icol1;
     double *ar1,*ai1;
     int *it2,*m2,*n2,*nel2,*mnel2,*icol2;
     double *ar2,*ai2;
{
  int i,iof = 0, j;
  for ( i = 0; i < *m1 ; i++) 
    {
      for ( j = 0; j < mnel1[i]; j++) 
	{
	  if (*it1 == 1) 
	    {
	      ai2[iof+j] = 2*ai1[iof+j];
	    }
	  ar2[iof+j] = 2*ar1[iof+j];
	}
      iof += mnel1[i];
    }
  for ( i = 0 ; i < *m1 ; i++ ) 
    mnel2[i]= mnel1[i];
  for ( i = 0 ; i < *nel1 ; i++) 
    icol2[i] = icol1[i] ;
  return(0);
}
/*******************************************
 * same as ext14ca but ar and ai are integers 
 *******************************************/
int F2C(ext14cc)(it,m,n,nel,mnel,icol,ar,ai)
     int *n,*m,*it,*nel,*mnel,*icol;
     int *ar,*ai;
{ 
  int i,iof = 0, j;
  for ( i = 0; i < *m ; i++) 
    {
      sciprint("Row %d, %d non zero elements\r\n",i+1,mnel[i]);
      for ( j = 0; j < mnel[i]; j++) 
	{
	  if (*it == 1) 
	      sciprint("(%d,%d) -> %d +i%d\r\n",i+1,icol[iof+j],
		       ar[iof+j],ai[iof+j]);
	  else 
	      sciprint("(%d,%d) -> %d \r\n",i+1,icol[iof+j],
		       ar[iof+j]);
	}
      iof += mnel[i];
    }
  return(0);
}
/*******************************************
 * same as ext14cb but ar2 and ai2 are integers 
 * 
 *******************************************/
int F2C(ext14cd)(it1,m1,n1,nel1,mnel1,icol1,ar1,ai1,
		 it2,m2,n2,nel2,mnel2,icol2,ar2,ai2)
     int *n1,*m1,*it1,*nel1,*mnel1,*icol1;
     double *ar1,*ai1;
     int *it2,*m2,*n2,*nel2,*mnel2,*icol2;
     int *ar2,*ai2;
{
  int i,iof = 0, j;
  for ( i = 0; i < *m1 ; i++) 
    {
      for ( j = 0; j < mnel1[i]; j++) 
	{
	  if (*it1 == 1) 
	    {
	      ai2[iof+j] = 2*ai1[iof+j];
	    }
	  ar2[iof+j] = 2*ar1[iof+j];
	}
      iof += mnel1[i];
    }
  for ( i = 0 ; i < *m1 ; i++ ) 
    mnel2[i]= mnel1[i];
  for ( i = 0 ; i < *nel1 ; i++) 
    icol2[i] = icol1[i] ;
  return(0);
}
/*******************************************
 * Test for intersci with external sparse (spt10 in ex14fi.desc) 
 * 
 * sparse.h defines a Sparse structure which can be used 
 * for storing external Sparse matrices which can be 
 * copied back to scilab sparse matrices ( by csparsef ) 
 * 
 * if x is a Sparse object 
 *     x.m : number of rows of x 
 *     x,n : number of columns of x 
 *     x.nel : number of non zero elements in x 
 *     x.it : 0 or 1 i.e. real or complex matrix 
 *     x.mnel[i],i=0,m-1 number of non zero elements in line i+1
 *
 *     x.icol[j],j=0,nel-1 : column of (j+1)th non zero element of the matrix 
 *                           ( stored by rows ) 
 *     x.xr[j],  .....     : real value of the (j+1)th non zero element 
 *     x.xi[j],  .....     : if x.it ==1 imaginary value of the (j+1)th 
 *                                       non zero element 
 *
 * NewSparse can be used to allocate a new Sparse object 
 *
 * The Scilab internal coding is very similar 
 * and the following function copies a Scilab Sparse (it,m,n,nel,mnel,icol,ar,ai) 
 * into an allocated Sparse object 
 * and return the allocated Sparse and its dimensions 
 *
 *
 * the routine C2F(csparsef) (file routines/intersci/sparse.c) 
 * is used for back converstion from Sparse to Scilab sparse and 
 * and the Sparse object is freed in csparsef 
 *
 *******************************************/
#include "../../routines/intersci/sparse.h"
int F2C(ext14ce)(it,m,n,nel,mnel,icol,ar,ai,x,mx,nx,nelx,itx,err)
     int *n,*m,*it,*nel,*mnel,*icol;
     double *ar,*ai;
     SciSparse **x;
     int *mx,*nx,*nelx,*itx;
     int *err;
{ 
  int i,iof = 0, j;
  *x = NewSparse(it,m,n,nel);
  if ( *x == (SciSparse *) 0) 
    {
      sciprint("No more space\r\n");
      *err = 1;return;
    }
  *mx = *m ;
  *nx = *n ; 
  *nelx = *nel;
  *itx = *it;
  *err=0;
  for ( i = 0; i < *m ; i++) 
    {
      for ( j = 0; j < mnel[i]; j++) 
	{
	  if (*it == 1) 
	    {
	      (*x)->I[iof+j] = 2*ai[iof+j];
	    }
	  (*x)->R[iof+j] = 2*ar[iof+j];
	}
      iof += mnel[i];
    }
  for ( i = 0 ; i < *m ; i++ ) 
    (*x)->mnel[i]= mnel[i];
  for ( i = 0 ; i < *nel ; i++) 
    (*x)->icol[i] = icol[i] ;
  return(0);
}
 
     |