00001 #include "stack-c.h"
00002 #include "../../elementaries_functions/includes/elementaries_functions.h"
00003
00004 #define CHAR(x) (cstk(x))
00005 #define INT(x) (istk(x))
00006 #define DOUBLE(x) ( stk(x))
00007 #define CMPLX(x) (zstk(x))
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 static integer c1 = 1;
00023 static integer c41 = 41;
00024 static integer c39 = 39;
00025 static integer c17 = 17;
00026 static integer c44 = 44;
00027 static integer c_n1 = -1;
00028 static double c_b46 = 0.;
00029
00030 extern int C2F(intmfull)(integer *id), C2F(intmspget)(integer *id);
00031 extern int C2F(basout)(), C2F(intmsparse)(integer *id);
00032
00033 static int wmspful(integer *ma, integer *na, double *ar, double *ai, integer *nela, integer *inda, double *rr, double *ri);
00034 static int dmspful(integer *ma, integer *na, double *a, integer *nela, integer *inda, double *r__);
00035
00036 extern int C2F(dspt)();
00037 extern int C2F(wspt)();
00038 extern int C2F(unsfdcopy)();
00039 extern int C2F(icopy)();
00040 extern int C2F(error)();
00041 extern int C2F(dset)();
00042 extern int C2F(int2db)();
00043 extern int empty(void);
00044
00045 int C2F(intmsparse)(integer *id)
00046 {
00047
00048 integer I1;
00049
00050 static integer tops;
00051 static integer I, l, m, n;
00052 static integer ia, il, it, lr, lw, ilc, nel, ilr, iat, irc, lat, top0;
00053 static integer kkk;
00054
00055 if( Rhs==2) {
00056 return empty();
00057 }
00058 --id;
00059
00060 Rhs = Max(0,Rhs);
00061 top0 = Top + 1 - Rhs;
00062 tops = Top;
00063
00064 lw = C2F(vstk).lstk[Top];
00065 if (Lhs != 1) {
00066 C2F(error)(&c41);
00067 return 0;
00068 }
00069 if (Rhs != 1) {
00070 C2F(error)(&c39);
00071 return 0;
00072 }
00073 il = C2F(vstk).lstk[Top-1] + C2F(vstk).lstk[Top-1] - 1;
00074 if (*istk(il) == 5) {
00075 nel = *istk(il + 4);
00076 m = *istk(il+1);
00077 n = *istk(il + 2);
00078 it = *istk(il + 3);
00079 ilr = il + 5;
00080 ilc = ilr + m;
00081 I1 = ilr + m + nel;
00082 l = I1 / 2 + 1;
00083
00084 ia = lw + lw - 1;
00085 iat = ia + m + 1;
00086 irc = iat + n + 1;
00087 I1 = irc + n + nel;
00088 lat = I1 / 2 + 1;
00089 lw = lat + nel * (it + 1);
00090 Err = lw - C2F(vstk).lstk[Bot-1];
00091 if (Err > 0) {
00092 C2F(error)(&c17);
00093 return 0;
00094 }
00095 *istk(ia) = 1;
00096 I1 = m;
00097 for (I = 1; I <= I1; ++I) {
00098 *istk(ia + I) = *istk(ia + I - 1) + *istk(ilr + I - 1);
00099 }
00100 if (it == 0) {
00101 C2F(dspt)(&m, &n, stk(l), &nel, istk(ilr), istk(ia
00102 ), stk(lat), istk(iat), istk(irc));
00103 } else {
00104 C2F(wspt)(&m, &n, stk(l), stk(l + nel), &
00105 nel, istk(ilr), istk(ia), stk(lat),
00106 stk(lat + nel), istk(iat), istk(irc));
00107 }
00108 *istk(il ) = 7;
00109 I1 = ilr + n + 1 + nel;
00110 lr = I1 / 2 + 1;
00111 I1 = n + 1;
00112
00113
00114
00115 for (kkk=0; kkk<I1; ++kkk) *istk(ilr+kkk)=*istk(iat+kkk)-1;
00116 for (kkk=0; kkk<nel; ++kkk) *istk(ilr+n+1+kkk)=*istk(irc+n+kkk)-1;
00117 I1 = nel * (it + 1);
00118 C2F(unsfdcopy)(&I1, stk(lat ), &c1, stk(lr ), &
00119 c1);
00120 C2F(vstk).lstk[Top] = lr + nel * (it + 1);
00121 } else if (*istk(il ) == 7) {
00122 } else {
00123 C2F(error)(&c44);
00124 return 0;
00125 }
00126 return 0;
00127 }
00128
00129 int empty(void)
00130 {
00131 int m,n;int k;
00132 int m1,n1,p1;
00133 int m2,n2,p2;
00134 int NZMAX=1;int jc=5;int ir;
00135 int *header;double *value;
00136 GetRhsVar(1,"d",&m1,&n1,&p1);
00137 GetRhsVar(2,"d",&m2,&n2,&p2);
00138 m= (int) *stk(p1);
00139 n= (int) *stk(p2);
00140 CreateData(3, (6+n+1)*sizeof(int)+sizeof(double));
00141 header = (int *) GetData(3); value= (double *) header;
00142 header[0]=7;
00143 header[1]=m;header[2]=n;header[3]=0;
00144 header[4]=NZMAX;header[jc]=0;
00145 ir=jc+n+1;
00146 for (k=0; k<n; ++k) header[jc+k+1]=0;
00147 header[ir]=0;
00148 value[(5+header[2]+header[4])/2 + 1] = 0.0;
00149 LhsVar(1)=3;
00150 PutLhsVar();
00151 return 1;
00152 }
00153
00154
00155
00156
00157
00158 int C2F(intmspget)(integer *id)
00159 {
00160 integer I1, I2, I3;
00161
00162
00163 static integer ilrs;
00164 static integer ityp, j, l, m, n;
00165 static integer j1_;
00166 static integer nc, il, it, lv, lw;
00167 static double tv;
00168 static integer ilc, nel, nelmax, ilr, lij, ilv, top0, kkk;
00169
00170
00171 --id;
00172
00173
00174 Rhs = Max(0,Rhs);
00175 top0 = Top + 1 - Rhs;
00176 lw = C2F(vstk).lstk[Top];
00177 if (Rhs != 1) {
00178 C2F(error)(&c39);
00179 return 0;
00180 }
00181 if (Lhs > 3) {
00182 C2F(error)(&c41);
00183 return 0;
00184 }
00185 il = C2F(vstk).lstk[Top -1] + C2F(vstk).lstk[Top -1] - 1;
00186 ityp = *istk(il );
00187 nelmax = *istk(il + 4);
00188 m = *istk(il+1);
00189 n = *istk(il + 2);
00190 it = *istk(il + 3);
00191 ilr = il + 5;
00192 nel = *istk(ilr + n);
00193
00194 ilc = ilr + n + 1;
00195 I1 = ilc + nelmax;
00196 l = I1 / 2 + 1;
00197 if (nel == 0) {
00198 *istk(il ) = 1;
00199 *istk(il+1) = 0;
00200 *istk(il + 2) = 0;
00201 *istk(il + 3) = 0;
00202 I1 = il + 4;
00203 C2F(vstk).lstk[Top] = I1 / 2 + 1;
00204 if (Lhs >= 2) {
00205 ++Top;
00206 il = C2F(vstk).lstk[Top -1] + C2F(vstk).lstk[Top -1] -
00207 1;
00208 *istk(il ) = 1;
00209 *istk(il+1) = 0;
00210 *istk(il + 2) = 0;
00211 *istk(il + 3) = 0;
00212 I1 = il + 4;
00213 C2F(vstk).lstk[Top] = I1 / 2 + 1;
00214 }
00215 if (Lhs == 3) {
00216 ++Top;
00217 il = C2F(vstk).lstk[Top -1] + C2F(vstk).lstk[Top -1] - 1;
00218 *istk(il ) = 1;
00219 *istk(il+1) = 1;
00220 *istk(il + 2) = 2;
00221 *istk(il + 3) = 0;
00222 I1 = il + 4;
00223 l = I1 / 2 + 1;
00224 *stk(l ) = (double) m;
00225 *stk(l+1) = (double) n;
00226 C2F(vstk).lstk[Top] = l + 2;
00227 }
00228 return 0;
00229 }
00230 I1 = il + 4;
00231 lij = I1 / 2 + 1;
00232 I1 = lij + (nel << 1);
00233 ilv = I1 + I1 - 1;
00234 I1 = ilv + 4;
00235 lv = I1 / 2 + 1;
00236 I2 = lw, I3 = lv + nel * (it + 1);
00237 I1 = Max(I2,I3);
00238 ilrs = I1 + I1 - 1;
00239 I1 = ilrs + n + 1 + nel;
00240 lw = I1 / 2 + 1;
00241 Err = lw - C2F(vstk).lstk[Bot -1];
00242 if (Err > 0) {
00243 C2F(error)(&c17);
00244 return 0;
00245 }
00246 I1 = n + nel + 1;
00247
00248 for (kkk=0; kkk<I1; ++kkk) *istk(ilrs+kkk)=*istk(ilr+kkk)+1;
00249
00250
00251
00252 if (l >= lv) {
00253 I1 = nel * (it + 1);
00254
00255
00256
00257
00258
00259
00260 C2F(unsfdcopy)(&I1, stk(l ), &c1, stk(lv ), &c1);
00261 } else {
00262 I1 = nel * (it + 1);
00263
00264
00265
00266
00267
00268
00269 C2F(unsfdcopy)(&I1, stk(l ), &c_n1, stk(lv ), &c_n1);
00270 }
00271
00272 C2F(int2db)(&nel, istk(ilrs + n+1), &c1, stk(lij), &c1);
00273 for (j = 1; j <= n; ++j) {
00274 nc = *istk(ilrs + j ) - *istk(ilrs + j - 1);
00275 j1_ = *istk(ilrs + j - 1) -1;
00276 tv = (double) j;
00277 C2F(dset)(&nc, &tv, stk(lij + nel + j1_ ), &c1);
00278 }
00279
00280
00281 *istk(il ) = 1;
00282 *istk(il+1) = nel;
00283 *istk(il + 2) = 2;
00284 *istk(il + 3) = 0;
00285 C2F(vstk).lstk[Top] = lij + (nel << 1);
00286 if (Lhs >= 2) {
00287
00288 ++Top;
00289 il = C2F(vstk).lstk[Top -1] + C2F(vstk).lstk[Top -1] - 1;
00290 *istk(il ) = 1;
00291 *istk(il+1) = nel;
00292 *istk(il + 2) = 1;
00293 *istk(il + 3) = it;
00294 C2F(vstk).lstk[Top] = lv + nel * (it + 1);
00295 }
00296 if (Lhs == 3) {
00297
00298 ++Top;
00299 il = C2F(vstk).lstk[Top -1] + C2F(vstk).lstk[Top -1] - 1;
00300 *istk(il ) = 1;
00301 *istk(il+1) = 1;
00302 *istk(il + 2) = 2;
00303 *istk(il + 3) = 0;
00304 I1 = il + 4;
00305 l = I1 / 2 + 1;
00306 *stk(l ) = (double) m;
00307 *stk(l+1) = (double) n;
00308 C2F(vstk).lstk[Top] = l + 2;
00309 }
00310 return 0;
00311 }
00312
00313
00314
00315
00316
00317 int C2F(intmfull)(integer *id)
00318 {
00319 integer I1, I2, I3;
00320
00321
00322 static integer l, m, n;
00323 static integer il, it, ls, lw, ilc, nel, ilr, ils, kkk;
00324 static integer top0;
00325
00326
00327 --id;
00328
00329
00330 Rhs = Max(0,Rhs);
00331 top0 = Top + 1 - Rhs;
00332 lw = C2F(vstk).lstk[Top];
00333 if (Rhs != 1) {
00334 C2F(error)(&c39);
00335 return 0;
00336 }
00337 if (Lhs != 1) {
00338 C2F(error)(&c41);
00339 return 0;
00340 }
00341 il = C2F(vstk).lstk[Top -1] + C2F(vstk).lstk[Top -1] - 1;
00342 nel = *istk(il + 4);
00343 m = *istk(il+1);
00344 n = *istk(il + 2);
00345 it = *istk(il + 3);
00346 ilr = il + 5;
00347 ilc = ilr + n + 1;
00348 I1 = ilc + nel;
00349 l = I1 / 2 + 1;
00350 I1 = il + 4;
00351
00352 I3 = I1 / 2 + 1 + m * n * (it + 1);
00353 I2 = Max(I3,lw);
00354 ils = I2 + I2 - 1;
00355 I1 = ils + n + 1 + nel;
00356 ls = I1 / 2 + 1;
00357 lw = ls + nel * (it + 1);
00358 Err = lw - C2F(vstk).lstk[Bot-1];
00359 if (Err > 0) {
00360 C2F(error)(&c17);
00361 return 0;
00362 }
00363 I1 = n + 1 + nel;
00364
00365 for (kkk=0; kkk<I1; ++kkk) *istk(ils+kkk)=*istk(ilr+kkk)+1;
00366
00367 I1 = nel * (it + 1);
00368 C2F(unsfdcopy)(&I1, stk(l ), &c1, stk(ls ), &c1);
00369 *istk(il ) = 1;
00370 I1 = il + 4;
00371 l = I1 / 2 + 1;
00372 if (it == 0) {
00373 dmspful(&m, &n, stk(ls ), &nel, istk(ils ), stk(l ));
00374 } else {
00375 wmspful(&m, &n, stk(ls ), stk(ls + nel ), &nel,istk(ils ),
00376 stk(l ), stk(l + m *n ));
00377 }
00378 C2F(vstk).lstk[Top] = l + m * n * (it + 1);
00379 return 0;
00380 }
00381
00382 static int dmspful(integer *ma, integer *na, double *a, integer *nela, integer *inda, double *rr)
00383 {
00384 integer I1, I2;
00385 static integer I, j, k, ii, nj;
00386
00387 I1 = *ma * *na;
00388 C2F(dset)(&I1, &c_b46,rr, &c1);
00389 k = 0;
00390 I1 = *na;
00391 for (j = 1; j <= I1; ++j) {
00392 nj = inda[j] - inda[j-1];
00393 if (nj > 0) {
00394 I2 = nj;
00395 for (ii = 1; ii <= I2; ++ii) {
00396 I = inda[*na + k + ii];
00397 rr[I + (j - 1) * *ma -1 ] = a[k + ii -1];
00398 }
00399 k += nj;
00400 }
00401 }
00402 return 0;
00403 }
00404
00405 static int wmspful(integer *ma, integer *na, double *ar, double *ai, integer *nela, integer *inda, double *rr, double *ri)
00406 {
00407 integer I1, I2;
00408 static integer I, j, k, ii, nj;
00409
00410 I1 = *ma * *na;
00411 C2F(dset)(&I1, &c_b46, rr, &c1);
00412 I1 = *ma * *na;
00413 C2F(dset)(&I1, &c_b46, ri, &c1);
00414 k = 0;
00415 I1 = *na;
00416 for (j = 1; j <= I1; ++j) {
00417 nj = inda[j] - inda[j-1];
00418 if (nj > 0) {
00419 I2 = nj;
00420 for (ii = 1; ii <= I2; ++ii) {
00421 I = inda[*na + k + ii];
00422 rr[I + (j - 1) * *ma -1] = ar[k + ii -1];
00423 ri[I + (j - 1) * *ma -1] = ai[k + ii -1];
00424 }
00425 k += nj;
00426 }
00427 }
00428 return 0;
00429 }
00430
00431