1 |
afe |
1.1 |
program driver |
2 |
|
|
|
3 |
|
|
c*** This subroutine calculates analysis errors using greg's |
4 |
|
|
c*** ensemble square root filter, or the traditional ensemble |
5 |
|
|
c*** kalman filter. |
6 |
|
|
c*** |
7 |
|
|
c*** Written by: Jim Hansen |
8 |
|
|
c*** Last modified: Nov 27, 2002 |
9 |
|
|
|
10 |
|
|
implicit none |
11 |
|
|
|
12 |
|
|
integer i, j, k, n, ijim, ijuli, isteps, nens, ics |
13 |
|
|
integer nx, ny, nz, nf, nnx, nny, nnz, mobs |
14 |
|
|
#include "parameters.h" |
15 |
|
|
integer iobsloc(mobs) |
16 |
|
|
real*8 y(n), dydx(n), yobs(mobs), ytmp(n) |
17 |
|
|
real*8 pert(n), H(mobs,n), R(mobs), yobsfull(n) |
18 |
|
|
real*8 xens(n,nens), par(n), var(n), ave(n) |
19 |
|
|
real*8 var_obs, eps, dt, x |
20 |
|
|
real*8 obserr, analerr, distsub |
21 |
|
|
real*8 bcup, bcdown, bcin, bcout |
22 |
|
|
|
23 |
|
|
common /boundary/ bcup,bcdown,bcin,bcout |
24 |
|
|
common /dim/ nnx,nny,nnz |
25 |
|
|
|
26 |
|
|
external derivsL953d |
27 |
|
|
|
28 |
|
|
c*** open some output files |
29 |
|
|
open(unit=2,file='test.dat',status='unknown') |
30 |
|
|
open(unit=3,file='fields.dat',status='unknown') |
31 |
|
|
|
32 |
|
|
c*** initialisations |
33 |
|
|
eps=0.2 ! obs error variance |
34 |
|
|
isteps=1 ! number of steps per obs cycle |
35 |
|
|
dt=0.05 ! integration stepsize |
36 |
|
|
do i=1,n |
37 |
|
|
par(i)=8. ! forcing magnitude |
38 |
|
|
enddo |
39 |
|
|
bcup=5. ! boundary conditions |
40 |
|
|
bcdown=5. |
41 |
|
|
bcin=5. |
42 |
|
|
bcout=5. |
43 |
|
|
nnx=nx |
44 |
|
|
nny=ny |
45 |
|
|
nnz=nz |
46 |
|
|
|
47 |
|
|
c*** specify observation locations |
48 |
|
|
do i=1,mobs |
49 |
|
|
iobsloc(i)=i |
50 |
|
|
enddo |
51 |
|
|
do i=1,mobs |
52 |
|
|
do j=1,n |
53 |
|
|
H(i,j)=0. |
54 |
|
|
enddo |
55 |
|
|
enddo |
56 |
|
|
do i=1,mobs |
57 |
|
|
H(i,iobsloc(i))=1. |
58 |
|
|
enddo |
59 |
|
|
|
60 |
|
|
c*** define obs variance |
61 |
|
|
var_obs=eps**2 |
62 |
|
|
do i=1,mobs |
63 |
|
|
R(i)=var_obs |
64 |
|
|
enddo |
65 |
|
|
|
66 |
|
|
c*** make up some initial conditions |
67 |
|
|
call random2(pert,n) |
68 |
|
|
do i=1,n |
69 |
|
|
y(i)=par(1)*pert(i) |
70 |
|
|
enddo |
71 |
|
|
|
72 |
|
|
c*** remove transient |
73 |
|
|
do i=1,2**14 |
74 |
|
|
call stepit(x,y,dydx,par,dt,n,isteps,derivsL953d) |
75 |
|
|
enddo |
76 |
|
|
|
77 |
|
|
c*** define an observation about truth |
78 |
|
|
call random2(pert,n) |
79 |
|
|
do i=1,n |
80 |
|
|
yobsfull(i)=y(i)+eps*pert(i) |
81 |
|
|
enddo |
82 |
|
|
|
83 |
|
|
c*** generate an nens member ensemble of initial conditions. |
84 |
|
|
do i=1,nens |
85 |
|
|
call random2(pert,n) |
86 |
|
|
do j=1,n |
87 |
|
|
xens(j,i)=yobsfull(j)+eps*pert(j) |
88 |
|
|
enddo |
89 |
|
|
enddo |
90 |
|
|
|
91 |
|
|
c*** loop over initial conditions |
92 |
|
|
do ijim=1,ics |
93 |
|
|
|
94 |
|
|
c*** step truth forward |
95 |
|
|
call stepit(x,y,dydx,par,dt,n,isteps,derivsL953d) |
96 |
|
|
|
97 |
|
|
c*** define an observation about truth |
98 |
|
|
call random2(pert,n) |
99 |
|
|
do k=1,n |
100 |
|
|
yobsfull(k)=y(k)+eps*pert(k) |
101 |
|
|
enddo |
102 |
|
|
do k=1,mobs |
103 |
|
|
yobs(k)=yobsfull(iobsloc(k)) |
104 |
|
|
enddo |
105 |
|
|
|
106 |
|
|
c*** step ensemble forward |
107 |
|
|
do ijuli=1,nens |
108 |
|
|
do k=1,n |
109 |
|
|
ytmp(k)=xens(k,ijuli) |
110 |
|
|
enddo |
111 |
|
|
call stepit(x,ytmp,dydx,par,dt,n,isteps,derivsL953d) |
112 |
|
|
do k=1,n |
113 |
|
|
xens(k,ijuli)=ytmp(k) |
114 |
|
|
enddo |
115 |
|
|
enddo |
116 |
|
|
|
117 |
|
|
c*** call the filter |
118 |
|
|
c call EnSRF3dO(xens,yobs,H,n,mobs,R,nens,nx,ny,nz) |
119 |
|
|
call EnKF(xens,yobs,H,n,mobs,R,nens) |
120 |
|
|
|
121 |
|
|
c*** get ensemble mean and variance |
122 |
|
|
call ranmean2(xens,ave,n,nens) |
123 |
|
|
call ranvar(xens,ave,n,nens,var) |
124 |
|
|
|
125 |
|
|
c*** calculate obs and anal err |
126 |
|
|
obserr=distsub(y,yobsfull,n) |
127 |
|
|
analerr=distsub(y,ave,n) |
128 |
|
|
write(6,*) "\tOBSERR\t", "\tANALERR" |
129 |
|
|
write(6,*) obserr, analerr |
130 |
|
|
write(2,*) ijim, obserr, analerr |
131 |
|
|
write(3,'(250f18.10)') (ave(i), i=1,n) |
132 |
|
|
|
133 |
|
|
call flush() |
134 |
|
|
|
135 |
|
|
enddo |
136 |
|
|
|
137 |
|
|
return |
138 |
|
|
end |