All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
pxnorv.f
Go to the documentation of this file.
1 CDECK ID>, PXNORV.
2  SUBROUTINE pxnorv (ISIZ,VEC,VNOR,IERR)
3 *.*********************************************************
4 *. ------
5 *. PXNORV
6 *. ------
7 *. SOURCE: J.W.Gary
8 *. Normalize a vector of arbitrary length
9 *. Usage :
10 *.
11 *. INTEGER NDIM
12 *. PARAMETER (NDIM=1.or.more)
13 *. REAL VEC (NDIM.or.more)
14 *. REAL VNOR
15 *. INTEGER IERR,ISIZ
16 *.
17 *. ISIZ = 1.to.NDIM
18 *. CALL PXNORV (ISIZ,VEC,VNOR,IERR)
19 *.
20 *. INPUT : ISIZ The length of the vector
21 *. INPUT : VEC The vector
22 *. OUTPUT : VNOR The normalized vector
23 *. OUTPUT : IERR = 0 if all is OK ; = -1 otherwise
24 *.
25 *.*********************************************************
26  IMPLICIT NONE
27  INTEGER isiz,ix,ierr
28  REAL vec (*),vnor (*)
29  DOUBLE PRECISION ax,bx
30  ierr = 0
31  ax = 0.0
32  DO 120 ix = 1,isiz
33  ax = ax + vec(ix) * vec(ix)
34  120 CONTINUE
35  bx = dsqrt(ax)
36  IF (bx.NE.0.0) THEN
37  bx = 1.0 / bx
38  ELSE
39  ierr = -1
40  RETURN
41  END IF
42  DO 140 ix = 1,isiz
43  vnor(ix) = bx * vec(ix)
44  140 CONTINUE
45  RETURN
46  END
subroutine pxnorv(ISIZ, VEC, VNOR, IERR)
Definition: pxnorv.f:2