interpolation.c

Go to the documentation of this file.
00001 /*-----------------------------------------------------------------------------------*/
00002 /*  
00003  *  PURPOSE
00004  *     interface code for some interpolation / approximation
00005  *     routines
00006  *
00007  *  AUTHOR
00008  *     Bruno Pincon
00009  */
00010 /*-----------------------------------------------------------------------------------*/
00011 #include <math.h>
00012 #include <string.h>
00013 #include "interpolation.h"
00014 #include "stack-c.h"
00015 /*-----------------------------------------------------------------------------------*/
00016 extern integer C2F(getfastcode)(unsigned char *c, unsigned long c_len);
00017 /*-----------------------------------------------------------------------------------*/
00018 int good_order(double x[], int n)
00019 {
00020   /*  test if x[i-1] < x[i] */
00021   static int first = 1;
00022   int i;
00023   static double inf;
00024 
00025   if ( first ) { inf = 1.0 / (double) (first - first) ; first = 0; }
00026 
00027   if (fabs(x[0]) == inf  ||  x[n-1] == inf)
00028     return ( 0 );
00029 
00030   for ( i = 1 ; i < n ; i++ ) 
00031     if ( ! (x[i-1] < x[i]) )   /* form of this test for detecting nan ... */ 
00032       return ( 0 );
00033 
00034   return ( 1 );
00035 }
00036 /*-----------------------------------------------------------------------------------*/
00037 /*
00038  *  Routines spéciales : 
00039  *      récupérer une hypermatrice réelle
00040  *      récupérer une string scilab sans convertion
00041  *      comparer une string scilab et une C string classique
00042  *  (elles ne modifient pas les variables correspondantes
00043  *   ce qui est fondamental pour que cette interface soit
00044  *   passée par référence).
00045  */
00046 /*-----------------------------------------------------------------------------------*/
00047 int get_rhs_real_hmat(int num, RealHyperMat *H)
00048 {
00049   int il, il1, il2, il3,/* it, */lw;
00050 
00051   lw = num + Top - Rhs;
00052   il = iadr(*Lstk( lw )); 
00053   if ( *istk(il) < 0 )
00054     il = iadr(*istk(il+1));
00055           
00056   if ( *istk(il) != 17 )
00057     goto err;
00058   else if ( *istk(il+1) != 3 )  /* a hm mlist must have 3 fields */
00059     goto err;
00060 
00061   /*  get the pointers for the 3 fields */
00062   il1 = sadr(il+6);
00063   il2 = il1 + *istk(il+3) - 1;
00064   il3 = il1 + *istk(il+4) - 1;
00065   il1 = iadr(il1); il2 = iadr(il2); il3 = iadr(il3);
00066 
00067   /*  test if the first field is a matrix string with 3 components
00068    *  and that the first is "hm" (ie 17 22  in scilab char code)
00069    */
00070   if ( (*istk(il1) != 10)  |  ((*istk(il1+1))*(*istk(il1+2)) != 3)  )
00071     goto err;
00072   else if ( *istk(il1+5)-1 != 2 )  /* 1 str must have 2 chars */
00073     goto err;
00074   else if ( *istk(il1+8) != 17  || *istk(il1+9) != 22 )
00075     goto err;
00076 
00077   /*  get the 2d field */
00078   if ( (*istk(il2) != 8)  |  (*istk(il2+3) != 4) )
00079     goto err;
00080   H->dimsize = (*istk(il2+1))*(*istk(il2+2));
00081   H->dims = istk(il2+4);
00082 
00083   /*  get the 3d field */
00084   if ( !( *istk(il3) == 1 && *istk(il3+3)==0) )
00085     goto err;;
00086 
00087   H->size = (*istk(il3+1))*(*istk(il3+2));
00088   H->R = stk(sadr(il3+4));
00089 
00090   /* needed for Jpc stuff (putlhsvar) */
00091   Nbvars = Max(Nbvars,num);
00092   C2F(intersci).ntypes[num-1] = '$';
00093   C2F(intersci).iwhere[num-1] = *Lstk(lw);
00094   C2F(intersci).lad[num-1] = 0;  /* a voir ? */
00095   return 1;
00096 
00097  err:
00098   Scierror(999,"Argument %d is not a real hypermatrix\r\n", num);
00099   return 0;
00100 }
00101 /*-----------------------------------------------------------------------------------*/
00102 int get_rhs_scalar_string(int num, int *length, int **tabchar)
00103 {
00104   int il, lw;
00105 
00106   lw = num + Top - Rhs;
00107   il = iadr(*Lstk( lw )); 
00108   if ( *istk(il) < 0 )
00109     il = iadr(*istk(il+1));
00110           
00111   if ( ! ( *istk(il) == 10  &&  (*istk(il+1))*(*istk(il+2)) == 1 ) ) 
00112     {
00113       /* we look for a scalar string */
00114       Scierror(999,"Argument %d is not a scalar string\r\n", num);
00115       return 0;
00116     }
00117   *length = *istk(il+5)-1;
00118   *tabchar = istk(il+6);
00119 
00120   Nbvars = Max(Nbvars,num);
00121   C2F(intersci).ntypes[num-1] = '$';
00122   C2F(intersci).iwhere[num-1] = *Lstk(lw);
00123   C2F(intersci).lad[num-1] = 0;
00124   return 1;
00125 }
00126 /*-----------------------------------------------------------------------------------*/
00127 int equal_scistring_and_string(int length, int *scistr,  char *str)
00128 {
00129   /* compare a scistring with a classic C string */
00130   int i, res;
00131   
00132   if ( strlen(str) != length )
00133     return 0;
00134 
00135   res = 1; i = 0;
00136   while (res && i < length)
00137     {
00138       res = (scistr[i] == (int)C2F(getfastcode)(str+i,1L));
00139       i++;
00140     }
00141   return (res);
00142 }
00143 /*-----------------------------------------------------------------------------------*/
00144 int get_type(TableType *Tab, int dim_table, int *scistr, int strlength)
00145 {
00146   int i = 0, found = 0;
00147   while ( !found  &&  i < dim_table )
00148     {
00149       found =  equal_scistring_and_string(strlength, scistr, Tab[i].str_type);
00150       i++;
00151     } 
00152   if ( found )
00153     return ( Tab[i-1].type );
00154   else
00155     return ( UNDEFINED );
00156 } 
00157 /*-----------------------------------------------------------------------------------*/
00158 
00159 
00160 
00161 
00162 
00163 
00164 

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