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

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

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

Initial import of Stark code.

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