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
201
202
203
204
205
|
/*
* Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
* Copyright (C) Bruno Pincon
*
* This file must be used under the terms of the CeCILL.
* This source file is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at
* http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
*/
/* PURPOSE
* interface code for some interpolation / approximation
* routines
*/
/*--------------------------------------------------------------------------*/
#include <math.h>
#include <string.h>
#include "interpolation.h"
#include "stack-c.h"
#include "getfastcode.h"
#include "Scierror.h"
#include "localization.h"
/*--------------------------------------------------------------------------*/
int good_order(double x[], int n)
{
/* test if x[i-1] < x[i] */
static int first = 1;
int i;
static double inf;
if ( first )
{
inf = 1.0 / (double) (first - first) ;
first = 0;
}
if (fabs(x[0]) == inf || x[n - 1] == inf)
{
return ( 0 );
}
for ( i = 1 ; i < n ; i++ )
if ( ! (x[i - 1] < x[i]) ) /* form of this test for detecting nan ... */
{
return ( 0 );
}
return ( 1 );
}
/*--------------------------------------------------------------------------*/
/*
* Routines spéciales :
* récupérer une hypermatrice réelle
* récupérer une string scilab sans convertion
* comparer une string scilab et une C string classique
* (elles ne modifient pas les variables correspondantes
* ce qui est fondamental pour que cette interface soit
* passée par référence).
*/
/*--------------------------------------------------------------------------*/
int get_rhs_real_hmat(int num, RealHyperMat *H)
{
int il, il1, il2, il3,/* it, */lw;
lw = num + Top - Rhs;
il = iadr(*Lstk( lw ));
if ( *istk(il) < 0 )
{
il = iadr(*istk(il + 1));
}
if ( *istk(il) != 17 )
{
goto err;
}
else if ( *istk(il + 1) != 3 ) /* a hm mlist must have 3 fields */
{
goto err;
}
/* get the pointers for the 3 fields */
il1 = sadr(il + 6);
il2 = il1 + *istk(il + 3) - 1;
il3 = il1 + *istk(il + 4) - 1;
il1 = iadr(il1);
il2 = iadr(il2);
il3 = iadr(il3);
/* test if the first field is a matrix string with 3 components
* and that the first is "hm" (ie 17 22 in scilab char code)
*/
if ( (*istk(il1) != sci_strings) | ((*istk(il1 + 1)) * (*istk(il1 + 2)) != 3) )
{
goto err;
}
else if ( *istk(il1 + 5) - 1 != 2 ) /* 1 str must have 2 chars */
{
goto err;
}
else if ( *istk(il1 + 8) != 17 || *istk(il1 + 9) != 22 )
{
goto err;
}
/* get the 2d field */
if ( (*istk(il2) != 8) | (*istk(il2 + 3) != 4) )
{
goto err;
}
H->dimsize = (*istk(il2 + 1)) * (*istk(il2 + 2));
H->dims = istk(il2 + 4);
/* get the 3d field */
if ( !( *istk(il3) == 1 && *istk(il3 + 3) == 0) )
{
goto err;
}
H->size = (*istk(il3 + 1)) * (*istk(il3 + 2));
H->R = stk(sadr(il3 + 4));
/* needed for Jpc stuff (putlhsvar) */
Nbvars = Max(Nbvars, num);
C2F(intersci).ntypes[num - 1] = '$';
C2F(intersci).iwhere[num - 1] = *Lstk(lw);
C2F(intersci).lad[num - 1] = 0; /* a voir ? */
return 1;
err:
Scierror(999, _("Wrong type for input argument #%d: Real hypermatrix expected.\n"), num);
return 0;
}
/*--------------------------------------------------------------------------*/
int get_rhs_scalar_string(int num, int *length, int **tabchar)
{
int il, lw;
lw = num + Top - Rhs;
il = iadr(*Lstk( lw ));
if ( *istk(il) < 0 )
{
il = iadr(*istk(il + 1));
}
if ( ! ( *istk(il) == sci_strings && (*istk(il + 1)) * (*istk(il + 2)) == 1 ) )
{
/* we look for a scalar string */
Scierror(999, _("Wrong type for input argument #%d: String expected.\n"), num);
return 0;
}
*length = *istk(il + 5) - 1;
*tabchar = istk(il + 6);
Nbvars = Max(Nbvars, num);
C2F(intersci).ntypes[num - 1] = '$';
C2F(intersci).iwhere[num - 1] = *Lstk(lw);
C2F(intersci).lad[num - 1] = 0;
return 1;
}
/*--------------------------------------------------------------------------*/
static int equal_scistring_and_string(int length, int *scistr, char *str)
{
/* compare a scistring with a classic C string */
int i = 0, res = 0;
if ( (int)strlen(str) != length )
{
return 0;
}
res = 1;
i = 0;
while (res && i < length)
{
res = (scistr[i] == convertAsciiCodeToScilabCode(str[i]));
i++;
}
return (res);
}
/*--------------------------------------------------------------------------*/
int get_type(TableType *Tab, int dim_table, int *scistr, int strlength)
{
int i = 0, found = 0;
while ( !found && i < dim_table )
{
found = equal_scistring_and_string(strlength, scistr, Tab[i].str_type);
i++;
}
if ( found )
{
return ( Tab[i - 1].type );
}
else
{
return ( UNDEFINED );
}
}
/*--------------------------------------------------------------------------*/
|