Update copyright statements and change license to LGPL
[alexxy/gromacs.git] / src / gmxlib / gmx_lapack / dlanst.c
1 /*
2  * This file is part of the GROMACS molecular simulation package.
3  *
4  * Copyright (c) 2012, by the GROMACS development team, led by
5  * David van der Spoel, Berk Hess, Erik Lindahl, and including many
6  * others, as listed in the AUTHORS file in the top-level source
7  * directory and at http://www.gromacs.org.
8  *
9  * GROMACS is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public License
11  * as published by the Free Software Foundation; either version 2.1
12  * of the License, or (at your option) any later version.
13  *
14  * GROMACS is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with GROMACS; if not, see
21  * http://www.gnu.org/licenses, or write to the Free Software Foundation,
22  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
23  *
24  * If you want to redistribute modifications to GROMACS, please
25  * consider that scientific software is very special. Version
26  * control is crucial - bugs must be traceable. We will be happy to
27  * consider code for inclusion in the official distribution, but
28  * derived work must not be called official GROMACS. Details are found
29  * in the README & COPYING files - if they are missing, get the
30  * official version at http://www.gromacs.org.
31  *
32  * To help us fund GROMACS development, we humbly ask that you cite
33  * the research papers on the package. Check out http://www.gromacs.org.
34  */
35 #include <math.h>
36 #include <ctype.h>
37 #include "gmx_lapack.h"
38
39
40 double
41 F77_FUNC(dlanst,DLANST)(const char *norm,
42         int *n,
43         double *d,
44         double *e)
45 {
46   const char ch=toupper(*norm);
47   double dtemp,max,val,scale,sum;
48   int i,j;
49
50
51   if(*n<=0)
52     return 0.0;
53   
54   switch(ch) {
55   case 'M':
56     max = fabs(d[*n-1]);
57       for(i=0;i<(*n-1);i++) {
58         dtemp = fabs(d[i]);
59         if(dtemp>max)
60           max = dtemp;
61         dtemp = fabs(e[i]);
62         if(dtemp>max)
63           max = dtemp;
64       }
65     val = max;
66     break;
67     
68   case 'O':
69   case '1':
70   case 'I':
71
72     if(*n==1)
73       val = fabs(d[0]);
74     else {
75       max = fabs(d[0]) + fabs(e[0]);
76       dtemp = fabs(e[*n-2]) + fabs(d[*n-1]);
77       if(dtemp>max)
78         max = dtemp;
79       for(i=1;i<(*n-1);i++) {
80         dtemp = fabs(d[i]) + fabs(e[i]) + fabs(e[i-1]);
81         if(dtemp>max)
82           max = dtemp;
83       }
84       val = max;
85     }
86     break;
87
88   case 'F':
89   case 'E':
90     scale = 0.0;
91     sum   = 1.0;
92     i = *n-1;
93     j = 1;
94     if(*n>1) {
95       F77_FUNC(dlassq,DLASSQ)(&i,e,&j,&scale,&sum);
96       sum *= 2;
97     }
98     F77_FUNC(dlassq,DLASSQ)(n,d,&j,&scale,&sum);
99     val = scale * sqrt(sum);
100     break;
101     
102   default:
103     val = 0.0;
104     break;
105   }
106   return val;
107 }