91f3a38ca3af562e16e73000c2978f6a4d55619a
[alexxy/gromacs.git] / src / gmxlib / gmx_lapack / dlasdt.c
1 #include <math.h>
2 #include "gmx_lapack.h"
3
4 void
5 F77_FUNC(dlasdt,DLASDT)(int *n,
6         int *lvl,
7         int *nd,
8         int *inode,
9         int *ndiml,
10         int *ndimr,
11         int *msub)
12 {
13   int maxn = (*n > 1) ? *n : 1;
14   double temp;
15   int i,il,ir,llst,nlvl,ncrnt;
16
17   temp = log( ((double) maxn) / ((double)(*msub+1))) / log(2.0);
18   
19   *lvl = 1 + (int) temp;
20
21   i = *n / 2;
22   inode[0] = i + 1;
23   ndiml[0] = i;
24   ndimr[0] = *n - i - 1;
25   il = -1;
26   ir = 0;
27   llst = 1;
28
29   for(nlvl=1;nlvl<*lvl;nlvl++) {
30     for(i=0;i<llst;i++) {
31       il += 2;
32       ir += 2;
33       ncrnt = llst + i - 1;
34       ndiml[il] = ndiml[ncrnt] / 2;
35       ndimr[il] = ndiml[ncrnt] - ndiml[il] - 1;
36       inode[il] = inode[ncrnt] - ndimr[il] - 1;
37       ndiml[ir] = ndimr[ncrnt] / 2;
38       ndimr[ir] = ndimr[ncrnt] - ndiml[ir] - 1;
39       inode[ir] = inode[ncrnt] + ndiml[ir] + 1;
40     }
41     llst *= 2;
42   }
43   *nd = llst*2 - 1;
44   return;
45 }