UPP  V11.0.0
 All Data Structures Files Functions Pages
POLEAVG.f
1  SUBROUTINE poleavg(IM,JM,JSTA,JEND,SMALL,COSL,SPVAL,VAR)
2 ! This program averages scalor fields at pole points
3 ! 13-05-06 Shrinivas Moorthi : Added protection from divide by zero for icount
4  implicit none
5 
6 ! INCLUDE 'mpif.h'
7  INTEGER,intent(in) :: im,jm,jsta,jend
8  REAL,intent(in) :: small,spval
9  REAL,intent(in) :: cosl(im,jsta:jend)
10  REAL,intent(inout) :: var(im,jsta:jend)
11  INTEGER i,jj,icount
12  REAL work, tem
13 !
14  jj = 1
15  IF(jj>=jsta .and. jj<=jend)then
16  IF(cosl(1,jj) < small)then
17  work = 0.
18  icount = 0
19  DO i=1,im
20  IF(var(i,jj) /= spval)THEN
21  work = var(i,jj) + work
22  icount = icount + 1
23  END IF
24  END DO
25  if (icount > 0) then
26  tem = work/icount
27  DO i=1,im
28  var(i,jj) = tem
29  END DO
30  endif
31  END IF
32  END IF
33  jj = jm
34  IF(jj>=jsta .and. jj<=jend)then
35  IF(cosl(1,jj) < small)then
36  work = 0.
37  icount = 0
38  DO i=1,im
39  IF(var(i,jj) /= spval)THEN
40  work = var(i,jj) + work
41  icount = icount + 1
42  END IF
43  END DO
44  if (icount > 0) then
45  tem = work/icount
46  DO i=1,im
47  var(i,jj) = tem
48  END DO
49  endif
50  END IF
51  END IF
52  RETURN
53  END