NCCOOS Trac Projects: Top | Web | Platforms | Processing | Viz | Sprints | Sandbox | (Wind)

root/gliderproc/trunk/MATLAB/opnml/MEXSRC/band.c

Revision 495 (checked in by cbc, 11 years ago)

Initial import of Stark code.

Line 
1 #include <stdio.h>
2 #include "opnml_mex5_allocs.c"
3 /*********  BANDMSOLVE SUBROUTINE   ******************/
4
5 void bandmsolve_c(int kkk, double **b, double *r, int neq, int hbw)
6 #define DZILCH (double)0.
7 {
8 /* Asymmetric band matrix equation solver
9    doctored to ignore 0's in the lu decomp step
10    
11    Input kkk = 0 ==>>  triangularize the band matrix b
12          kkk = 1 ==>>  solve for right side r, return solution in r
13 */
14    
15    int bw,i,ib,ihbp,j,jc,ji,jp,k;
16    int kc,ki,kk,kr,lim,mr,nn;
17    double c,sum,pivot;
18    
19 /* Compute BW */
20    bw=2*hbw+1;
21
22    ihbp=hbw+1; 
23    
24    if (kkk==0){
25
26 /* ---- Triangularize b using Doolittle Method ---- */
27       for (k=1;k<=neq-1;++k) {
28          pivot=b[ihbp-1][k-1];
29          kk=k+1;
30          kc=ihbp;
31          for (i=kk;i<=neq;++i){
32             --kc;
33             if(kc<=0)goto L10;
34             c=-b[kc-1][i-1]/pivot;
35             if (c==(float)0)goto L21;
36             b[kc-1][i-1]=c;
37             ki=kc+1;
38             lim=kc+hbw;
39             for (j=ki;j<=lim;++j){
40                jc=ihbp+j-kc;
41                b[j-1][i-1]+=c*b[jc-1][k-1];
42             }
43 L21:     ;
44          }
45 L10:    ;}
46    }
47    
48    else if (kkk==1){
49
50 /* ---- Modify load vector ---- */
51       nn=neq+1;
52       for (i=2;i<=neq;++i){
53          jc=ihbp-i+1;
54          ji=1;
55          if (jc<=0){
56             jc=1;
57             ji=i-ihbp+1;
58          }
59          sum=DZILCH;
60          for (j=jc;j<=hbw;++j){
61             sum+=b[j-1][i-1]*r[ji-1];
62             ++ji;
63          }
64          r[i-1]+=sum;
65       }
66
67 /* ---- Back Solution ---- */
68       r[neq-1]/=b[ihbp-1][neq-1];
69       for (ib=2;ib<=neq;++ib){
70          i=nn-ib;
71          jp=i;
72          kr=ihbp+1;
73          mr=IMIN(bw,hbw+ib);
74          sum=DZILCH;
75          for (j=kr;j<=mr;++j){
76             ++jp;
77             sum+=b[j-1][i-1]*r[jp-1];
78          }
79          r[i-1]=(r[i-1]-sum)/b[ihbp-1][i-1];
80       }
81    }
82    else{
83       fprintf(stderr,"Incorrect flag passed in 1st argument to bandmsolve.\n");
84       exit(0);
85    }
86 }
Note: See TracBrowser for help on using the browser.