1 |
C $Header: /u/gcmpack/MITgcm/pkg/ecco/cost_generic.F,v 1.26 2014/10/07 14:45:53 gforget Exp $ |
2 |
C $Name: $ |
3 |
|
4 |
#include "ECCO_OPTIONS.h" |
5 |
|
6 |
C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----| |
7 |
CBOP |
8 |
C !ROUTINE: cost_generic |
9 |
C !INTERFACE: |
10 |
subroutine cost_generic( |
11 |
& nnzbar, localbarfile, localbar, dummy, |
12 |
& nnzobs, localobsfile, mult_local, |
13 |
& nrecloc, nrecobs, |
14 |
& localstartdate, localperiod, |
15 |
& ylocmask, localweight, |
16 |
& spminloc, spmaxloc, spzeroloc, |
17 |
& preproc, preproc_c, preproc_i, preproc_r, |
18 |
& posproc, posproc_c, posproc_i, posproc_r, |
19 |
& outlev, outname, |
20 |
& objf_local, num_local, |
21 |
& myiter, mytime, mythid ) |
22 |
|
23 |
C !DESCRIPTION: \bv |
24 |
C Generic routine for evaluating time-dependent |
25 |
c cost function contribution |
26 |
C \ev |
27 |
|
28 |
C !USES: |
29 |
implicit none |
30 |
|
31 |
c == global variables == |
32 |
|
33 |
#include "EEPARAMS.h" |
34 |
#include "SIZE.h" |
35 |
#include "PARAMS.h" |
36 |
#include "GRID.h" |
37 |
#ifdef ALLOW_CAL |
38 |
# include "cal.h" |
39 |
#endif |
40 |
#ifdef ALLOW_ECCO |
41 |
# include "ecco.h" |
42 |
#endif |
43 |
#ifdef ALLOW_SEAICE |
44 |
# include "SEAICE_COST.h" |
45 |
#endif |
46 |
|
47 |
c == routine arguments == |
48 |
|
49 |
integer myiter |
50 |
integer mythid |
51 |
integer nnzbar, nnzobs |
52 |
integer nrecloc, nrecobs |
53 |
integer localstartdate(4) |
54 |
integer outlev |
55 |
integer preproc_i(NGENPPROC) |
56 |
integer posproc_i(NGENPPROC) |
57 |
|
58 |
_RL objf_local(nsx,nsy) |
59 |
_RL num_local(nsx,nsy) |
60 |
_RL localbar (1-olx:snx+olx,1-oly:sny+oly,nnzbar,nsx,nsy) |
61 |
_RL localweight(1-olx:snx+olx,1-oly:sny+oly,nnzobs,nsx,nsy) |
62 |
_RL dummy |
63 |
_RL mult_local |
64 |
_RL mytime |
65 |
_RL localperiod |
66 |
_RL spminloc |
67 |
_RL spmaxloc |
68 |
_RL spzeroloc |
69 |
_RL preproc_r(NGENPPROC) |
70 |
_RL posproc_r(NGENPPROC) |
71 |
|
72 |
character*(1) ylocmask |
73 |
character*(MAX_LEN_FNAM) localbarfile |
74 |
character*(MAX_LEN_FNAM) localobsfile |
75 |
character*(MAX_LEN_FNAM) preproc(NGENPPROC) |
76 |
character*(MAX_LEN_FNAM) preproc_c(NGENPPROC) |
77 |
character*(MAX_LEN_FNAM) posproc(NGENPPROC) |
78 |
character*(MAX_LEN_FNAM) posproc_c(NGENPPROC) |
79 |
character*(MAX_LEN_FNAM) outname |
80 |
|
81 |
#ifdef ALLOW_ECCO |
82 |
|
83 |
c == local variables == |
84 |
|
85 |
integer bi,bj |
86 |
integer itlo,ithi |
87 |
integer jtlo,jthi |
88 |
integer irec |
89 |
integer il |
90 |
integer localrec, obsrec |
91 |
|
92 |
_RL localmask (1-olx:snx+olx,1-oly:sny+oly,nr,nsx,nsy) |
93 |
_RL localobs (1-olx:snx+olx,1-oly:sny+oly,nnzobs,nsx,nsy) |
94 |
_RL localdif (1-olx:snx+olx,1-oly:sny+oly,nnzobs,nsx,nsy) |
95 |
_RL difmask (1-olx:snx+olx,1-oly:sny+oly,nnzobs,nsx,nsy) |
96 |
|
97 |
character*(128) fname1, fname2, fname3 |
98 |
|
99 |
logical exst |
100 |
|
101 |
c == external functions == |
102 |
|
103 |
integer ilnblnk |
104 |
external ilnblnk |
105 |
|
106 |
CEOP |
107 |
|
108 |
jtlo = mybylo(mythid) |
109 |
jthi = mybyhi(mythid) |
110 |
itlo = mybxlo(mythid) |
111 |
ithi = mybxhi(mythid) |
112 |
|
113 |
c-- Initialise local variables. |
114 |
|
115 |
do bj = jtlo,jthi |
116 |
do bi = itlo,ithi |
117 |
objf_local(bi,bj) = 0. _d 0 |
118 |
num_local(bi,bj) = 0. _d 0 |
119 |
enddo |
120 |
enddo |
121 |
call ecco_zero(localobs,nnzobs,zeroRL,myThid) |
122 |
call ecco_zero(localdif,nnzobs,zeroRL,myThid) |
123 |
call ecco_zero(difmask,nnzobs,zeroRL,myThid) |
124 |
|
125 |
c-- Assign mask |
126 |
if ( ylocmask .EQ. 'C' .OR. ylocmask .EQ. 'c' ) then |
127 |
call ecco_cprsrl(maskC,nr,localmask,nr,myThid) |
128 |
elseif ( ylocmask .EQ. 'S' .OR. ylocmask .EQ. 's' ) then |
129 |
call ecco_cprsrl(maskS,nr,localmask,nr,myThid) |
130 |
elseif ( ylocmask .EQ. 'W' .OR. ylocmask .EQ. 'w' ) then |
131 |
call ecco_cprsrl(maskW,nr,localmask,nr,myThid) |
132 |
else |
133 |
STOP 'cost_generic: wrong ylocmask' |
134 |
endif |
135 |
|
136 |
c-- reset nrecloc, if needed, according to preproc |
137 |
if ( preproc(1) .EQ. 'climmon') nrecloc=MIN(nrecloc,12) |
138 |
|
139 |
if ( .NOT. ( localobsfile.EQ.' ' ) ) then |
140 |
|
141 |
c-- loop over obsfile records |
142 |
do irec = 1, nrecloc |
143 |
|
144 |
c-- determine records and file names |
145 |
exst=.FALSE. |
146 |
call cost_gencal(localbarfile, localobsfile, |
147 |
& irec, localstartdate, localperiod, fname1, |
148 |
& fname2, localrec, obsrec, exst, mythid ) |
149 |
|
150 |
c-- load model average and observed average |
151 |
call cost_genread( fname1, localbar, irec, nnzbar, |
152 |
& preproc, dummy, mythid ) |
153 |
|
154 |
call ecco_zero(localobs,nnzobs,spzeroloc,myThid) |
155 |
if ( (localrec .GT. 0).AND.(obsrec .GT. 0).AND.(exst) ) |
156 |
& call mdsreadfield( fname2, cost_iprec, cost_yftype, nnzobs, |
157 |
& localobs, localrec, mythid ) |
158 |
|
159 |
c-- Compute masked model-data difference |
160 |
call ecco_diffmsk( localbar, nnzbar, localobs, nnzobs, |
161 |
& localmask, spminloc, spmaxloc, spzeroloc, |
162 |
& localdif, difmask, myThid ) |
163 |
|
164 |
#ifdef ALLOW_SMOOTH |
165 |
if ( (useSMOOTH).AND.(posproc(1).EQ.'smooth') ) |
166 |
& call smooth_hetero2d(localdif,maskc, |
167 |
& posproc_c(1),posproc_i(1),mythid) |
168 |
#endif |
169 |
|
170 |
c-- Compute normalized model-obs cost function |
171 |
call ecco_addcost( |
172 |
I localdif, localweight, difmask, nnzobs, |
173 |
I objf_local, num_local, |
174 |
I myThid |
175 |
& ) |
176 |
|
177 |
c-- output model-data difference to disk |
178 |
if ( outlev.GT.0 ) then |
179 |
il=ilnblnk(outname) |
180 |
write(fname3(1:128),'(2a)') 'misfit_', outname(1:il) |
181 |
if ( nnzobs.EQ.1 ) CALL |
182 |
& WRITE_REC_XY_RL( fname3, localdif,irec, eccoiter, mythid ) |
183 |
if ( nnzobs.EQ.nr ) CALL |
184 |
& WRITE_REC_XYZ_RL( fname3, localdif,irec, eccoiter, mythid ) |
185 |
endif |
186 |
|
187 |
enddo |
188 |
c-- End of loop over obsfile records. |
189 |
|
190 |
endif |
191 |
|
192 |
#endif /* ALLOW_ECCO */ |
193 |
|
194 |
end |