covfn.f 1.28 KB
Newer Older
agebhard's avatar
agebhard committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
      DOUBLE PRECISION FUNCTION COVFN(COVTYPE,COVPAR,LAG)
      INTEGER COVTYPE
      DOUBLE PRECISION COVPAR(*),LAG
c     implementation of covariance functions
      IF (LAG.LT.0) THEN
         WRITE(*,*) "negative lag"
         COVFN=-1
         RETURN
      END IF
      IF (COVTYPE.EQ.1) THEN
c     exponential
         IF (LAG.GT.0) THEN
            COVFN=COVPAR(2)*EXP(-LAG/COVPAR(3))
         ELSE
            COVFN=COVPAR(1)+COVPAR(2)
         END IF
      ELSE IF (COVTYPE.EQ.2) THEN
c     gaussian
         IF (LAG.GT.0) THEN
            COVFN=COVPAR(2)*EXP(-(LAG*LAG/(COVPAR(3)*COVPAR(3))))
         ELSE
            COVFN=COVPAR(1)+COVPAR(2)
         END IF
      ELSE IF (COVTYPE.EQ.3) THEN
c     spherical
         IF (LAG.GT.COVPAR(3)) THEN
            COVFN=0
         ELSE IF (LAG.GT.0) THEN
            COVFN=COVPAR(2)*(1-1.5*LAG/COVPAR(3)+
     .                       0.5*LAG**3/COVPAR(3)**3)
         ELSE
            COVFN=COVPAR(1)+COVPAR(2)
         END IF
      ELSE IF (COVTYPE.EQ.4) THEN
c     linear
         IF (LAG.GT.0) THEN
            COVFN=COVPAR(2)*EXP(-LAG/COVPAR(3))
         ELSE
            COVFN=COVPAR(1)+COVPAR(2)
         END IF
      ELSE
         WRITE(*,*) "unknown covariance funtion"
         COVFN=-1
         RETURN
      END IF
      RETURN
      END