ex12c.c

Go to the documentation of this file.
00001 
00002 #include "../../routines/machine.h"
00003 
00004 /*******************************************
00005  * External type for intersci 
00006  * creating a new external type 
00007  * ccalc12 : the wrapped function which returns a handler 
00008  * to a dynamically allocated object 
00009  * ccalc12f : function for the wrapper which <<converts>> 
00010  *         Array to Scilab data 
00011  *******************************************/
00012 
00013 typedef struct array {
00014   int m,n;
00015   double *val;
00016 } Array ;
00017 
00018 C2F(ccalc12) ( a,m,n,err) 
00019      Array **a; int *m,*n,*err ;
00020 {
00021   int i;
00022   *a = ( Array *) malloc( sizeof(Array));
00023   if ( *a == (Array *) 0) 
00024     {
00025       *err=1;
00026       sciprint("No more space\r\n");
00027     }
00028   *m = (*a)->m = 1;
00029   *n = (*a)->n = 10;
00030   (*a)->val = (double *)  malloc( (unsigned) (*m)*(*n) *sizeof(double));
00031   if ( (*a)->val  == (double *) 0 ) 
00032     {
00033       *err=1;
00034       sciprint("No more space\r\n");
00035     }
00036   *err=0;
00037   for ( i= 0 ; i < (*m)*(*n) ; i++) (*a)->val[i] = i ;
00038 }
00039 
00040 
00041 C2F(ccalc12f)(n,ip,op) 
00042      int *n;
00043      Array **ip;
00044      double *op;
00045 {
00046   int i;
00047   if ( *n > 0 ) {
00048     for (i = 0; i < *n; i++)
00049       op[i]= (*ip)->val[i];
00050     free((char *)(*ip)->val);
00051     free((char *)(*ip));
00052   }
00053 }
00054 
00055 
00056 
00057 
00058 
00059 

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