ex14c.c

Go to the documentation of this file.
00001 
00002 #include "stack-c.h"
00003 
00004 /*******************************************
00005  * simple example with sparse matrix 
00006  * Display of a 
00007  *******************************************/
00008 
00009 int F2C(ext14ca)(it,m,n,nel,mnel,icol,ar,ai)
00010      int *n,*m,*it,*nel,*mnel,*icol;
00011      double *ar,*ai;
00012 { 
00013   int i,iof = 0, j;
00014   for ( i = 0; i < *m ; i++) 
00015     {
00016       sciprint("Row %d, %d non zero elements\r\n",i+1,mnel[i]);
00017       for ( j = 0; j < mnel[i]; j++) 
00018         {
00019           if (*it == 1) 
00020               sciprint("(%d,%d) -> %f +i%f\r\n",i+1,icol[iof+j],
00021                        ar[iof+j],ai[iof+j]);
00022           else 
00023               sciprint("(%d,%d) -> %f \r\n",i+1,icol[iof+j],
00024                        ar[iof+j]);
00025         }
00026       iof += mnel[i];
00027     }
00028   return(0);
00029 }
00030 
00031 /*******************************************
00032  * simple example with sparse matrix 
00033  * 2*a copied into b 
00034  *******************************************/
00035 
00036 int F2C(ext14cb)(it1,m1,n1,nel1,mnel1,icol1,ar1,ai1,
00037                  it2,m2,n2,nel2,mnel2,icol2,ar2,ai2)
00038      int *n1,*m1,*it1,*nel1,*mnel1,*icol1;
00039      double *ar1,*ai1;
00040      int *it2,*m2,*n2,*nel2,*mnel2,*icol2;
00041      double *ar2,*ai2;
00042 {
00043   int i,iof = 0, j;
00044   for ( i = 0; i < *m1 ; i++) 
00045     {
00046       for ( j = 0; j < mnel1[i]; j++) 
00047         {
00048           if (*it1 == 1) 
00049             {
00050               ai2[iof+j] = 2*ai1[iof+j];
00051             }
00052           ar2[iof+j] = 2*ar1[iof+j];
00053         }
00054       iof += mnel1[i];
00055     }
00056   for ( i = 0 ; i < *m1 ; i++ ) 
00057     mnel2[i]= mnel1[i];
00058   for ( i = 0 ; i < *nel1 ; i++) 
00059     icol2[i] = icol1[i] ;
00060   return(0);
00061 }
00062 
00063 /*******************************************
00064  * same as ext14ca but ar and ai are integers 
00065  *******************************************/
00066 
00067 int F2C(ext14cc)(it,m,n,nel,mnel,icol,ar,ai)
00068      int *n,*m,*it,*nel,*mnel,*icol;
00069      int *ar,*ai;
00070 { 
00071   int i,iof = 0, j;
00072   for ( i = 0; i < *m ; i++) 
00073     {
00074       sciprint("Row %d, %d non zero elements\r\n",i+1,mnel[i]);
00075       for ( j = 0; j < mnel[i]; j++) 
00076         {
00077           if (*it == 1) 
00078               sciprint("(%d,%d) -> %d +i%d\r\n",i+1,icol[iof+j],
00079                        ar[iof+j],ai[iof+j]);
00080           else 
00081               sciprint("(%d,%d) -> %d \r\n",i+1,icol[iof+j],
00082                        ar[iof+j]);
00083         }
00084       iof += mnel[i];
00085     }
00086   return(0);
00087 }
00088 
00089 
00090 /*******************************************
00091  * same as ext14cb but ar2 and ai2 are integers 
00092  * 
00093  *******************************************/
00094 
00095 
00096 int F2C(ext14cd)(it1,m1,n1,nel1,mnel1,icol1,ar1,ai1,
00097                  it2,m2,n2,nel2,mnel2,icol2,ar2,ai2)
00098      int *n1,*m1,*it1,*nel1,*mnel1,*icol1;
00099      double *ar1,*ai1;
00100      int *it2,*m2,*n2,*nel2,*mnel2,*icol2;
00101      int *ar2,*ai2;
00102 {
00103   int i,iof = 0, j;
00104   for ( i = 0; i < *m1 ; i++) 
00105     {
00106       for ( j = 0; j < mnel1[i]; j++) 
00107         {
00108           if (*it1 == 1) 
00109             {
00110               ai2[iof+j] = 2*ai1[iof+j];
00111             }
00112           ar2[iof+j] = 2*ar1[iof+j];
00113         }
00114       iof += mnel1[i];
00115     }
00116   for ( i = 0 ; i < *m1 ; i++ ) 
00117     mnel2[i]= mnel1[i];
00118   for ( i = 0 ; i < *nel1 ; i++) 
00119     icol2[i] = icol1[i] ;
00120   return(0);
00121 }
00122 
00123 
00124 
00125 
00126 /*******************************************
00127  * Test for intersci with external sparse (spt10 in ex14fi.desc) 
00128  * 
00129  * a Sparse structure is defined in stack-c.h which can be used 
00130  * for storing external Sparse matrices which can be 
00131  * copied back to scilab sparse matrices ( by csparsef ) 
00132  * 
00133  * if x is a Sparse object 
00134  *     x.m : number of rows of x 
00135  *     x,n : number of columns of x 
00136  *     x.nel : number of non zero elements in x 
00137  *     x.it : 0 or 1 i.e. real or complex matrix 
00138  *     x.mnel[i],i=0,m-1 number of non zero elements in line i+1
00139  *
00140  *     x.icol[j],j=0,nel-1 : column of (j+1)th non zero element of the matrix 
00141  *                           ( stored by rows ) 
00142  *     x.xr[j],  .....     : real value of the (j+1)th non zero element 
00143  *     x.xi[j],  .....     : if x.it ==1 imaginary value of the (j+1)th 
00144  *                                       non zero element 
00145  *
00146  * NewSparse can be used to allocate a new Sparse object 
00147  *
00148  * The Scilab internal coding is very similar 
00149  * and the following function copies a Scilab Sparse (it,m,n,nel,mnel,icol,ar,ai) 
00150  * into an allocated Sparse object 
00151  * and return the allocated Sparse and its dimensions 
00152  *
00153  *
00154  * the routine C2F(csparsef) (file routines/intersci/sparse.c) 
00155  * is used for back converstion from Sparse to Scilab sparse and 
00156  * and the Sparse object is freed in csparsef 
00157  *
00158  *******************************************/
00159 
00160 #include "../../routines/intersci/libinter.h"
00161 
00162 int F2C(ext14ce)(it,m,n,nel,mnel,icol,ar,ai,x,mx,nx,nelx,itx,err)
00163      int *n,*m,*it,*nel,*mnel,*icol;
00164      double *ar,*ai;
00165      SciSparse **x;
00166      int *mx,*nx,*nelx,*itx;
00167      int *err;
00168 { 
00169   int i,iof = 0, j;
00170   *x = NewSparse(it,m,n,nel);
00171   if ( *x == (SciSparse *) 0) 
00172     {
00173       sciprint("No more space\r\n");
00174       *err = 1;return;
00175     }
00176   *mx = *m ;
00177   *nx = *n ; 
00178   *nelx = *nel;
00179   *itx = *it;
00180   *err=0;
00181   for ( i = 0; i < *m ; i++) 
00182     {
00183       for ( j = 0; j < mnel[i]; j++) 
00184         {
00185           if (*it == 1) 
00186             {
00187               (*x)->I[iof+j] = 2*ai[iof+j];
00188             }
00189           (*x)->R[iof+j] = 2*ar[iof+j];
00190         }
00191       iof += mnel[i];
00192     }
00193   for ( i = 0 ; i < *m ; i++ ) 
00194     (*x)->mnel[i]= mnel[i];
00195   for ( i = 0 ; i < *nel ; i++) 
00196     (*x)->icol[i] = icol[i] ;
00197   return(0);
00198 }
00199 
00200 

Generated on Sun Mar 4 15:03:57 2007 for Scilab [trunk] by  doxygen 1.5.1