1 |
C $Header: /u/gcmpack/MITgcm/pkg/ctrl/ctrl_get_gen.F,v 1.13 2007/06/19 03:42:30 gforget Exp $ |
2 |
C $Name: $ |
3 |
|
4 |
#include "CTRL_CPPOPTIONS.h" |
5 |
|
6 |
|
7 |
subroutine ctrl_get_gen( |
8 |
I xx_gen_file, xx_genstartdate, xx_genperiod, |
9 |
I genmask, genfld, xx_gen0, xx_gen1, xx_gen_dummy, |
10 |
I xx_gen_remo_intercept, xx_gen_remo_slope, |
11 |
I mytime, myiter, mythid |
12 |
& ) |
13 |
|
14 |
c ================================================================== |
15 |
c SUBROUTINE ctrl_get_gen |
16 |
c ================================================================== |
17 |
c |
18 |
c o new generic routine for reading time dependent control variables |
19 |
c heimbach@mit.edu 12-Jun-2003 |
20 |
c |
21 |
c ================================================================== |
22 |
c SUBROUTINE ctrl_get_gen |
23 |
c ================================================================== |
24 |
|
25 |
implicit none |
26 |
|
27 |
c == global variables == |
28 |
|
29 |
#include "EEPARAMS.h" |
30 |
#include "SIZE.h" |
31 |
#include "PARAMS.h" |
32 |
#include "GRID.h" |
33 |
|
34 |
#include "ctrl.h" |
35 |
#include "ctrl_dummy.h" |
36 |
#include "optim.h" |
37 |
#ifdef ALLOW_EXF |
38 |
# include "EXF_FIELDS.h" |
39 |
#endif |
40 |
|
41 |
c == routine arguments == |
42 |
|
43 |
character*(80) fnamegeneric |
44 |
character*(MAX_LEN_FNAM) xx_gen_file |
45 |
integer xx_genstartdate(4) |
46 |
_RL xx_genperiod |
47 |
_RL genmask(1-olx:snx+olx,1-oly:sny+oly,nr,nsx,nsy) |
48 |
_RL genfld(1-olx:snx+olx,1-oly:sny+oly,nsx,nsy) |
49 |
_RL xx_gen0(1-olx:snx+olx,1-oly:sny+oly,nsx,nsy) |
50 |
_RL xx_gen1(1-olx:snx+olx,1-oly:sny+oly,nsx,nsy) |
51 |
_RL xx_gen_dummy |
52 |
_RL xx_gen_remo_intercept |
53 |
_RL xx_gen_remo_slope |
54 |
|
55 |
_RL mytime |
56 |
integer myiter |
57 |
integer mythid |
58 |
|
59 |
c == local variables == |
60 |
|
61 |
#ifdef ALLOW_EXF |
62 |
|
63 |
integer bi,bj |
64 |
integer i,j,k |
65 |
integer itlo,ithi |
66 |
integer jtlo,jthi |
67 |
integer jmin,jmax |
68 |
integer imin,imax |
69 |
integer ilgen |
70 |
|
71 |
_RL gensign |
72 |
_RL genfac |
73 |
logical doCtrlUpdate |
74 |
logical genfirst |
75 |
logical genchanged |
76 |
integer gencount0 |
77 |
integer gencount1 |
78 |
|
79 |
logical doglobalread |
80 |
logical ladinit |
81 |
|
82 |
character*(80) fnamegen |
83 |
|
84 |
c == external functions == |
85 |
|
86 |
integer ilnblnk |
87 |
external ilnblnk |
88 |
|
89 |
|
90 |
c == end of interface == |
91 |
|
92 |
jtlo = mybylo(mythid) |
93 |
jthi = mybyhi(mythid) |
94 |
itlo = mybxlo(mythid) |
95 |
ithi = mybxhi(mythid) |
96 |
jmin = 1-oly |
97 |
jmax = sny+oly |
98 |
imin = 1-olx |
99 |
imax = snx+olx |
100 |
|
101 |
c-- Now, read the control vector. |
102 |
doglobalread = .false. |
103 |
ladinit = .false. |
104 |
|
105 |
if (optimcycle .ge. 0) then |
106 |
ilgen=ilnblnk( xx_gen_file ) |
107 |
write(fnamegen(1:80),'(2a,i10.10)') |
108 |
& xx_gen_file(1:ilgen), '.', optimcycle |
109 |
endif |
110 |
|
111 |
# ifdef ALLOW_CAL |
112 |
if ( xx_genperiod .EQ. 0 ) then |
113 |
c record numbers are assumed 1 to 12 corresponding to |
114 |
c Jan. through Dec. |
115 |
call cal_GetMonthsRec( |
116 |
O genfac, genfirst, genchanged, |
117 |
O gencount0, gencount1, |
118 |
I mytime, myiter, mythid |
119 |
& ) |
120 |
else |
121 |
c-- Get the counters, flags, and the interpolation factor. |
122 |
call ctrl_get_gen_rec( |
123 |
I xx_genstartdate, xx_genperiod, |
124 |
O genfac, genfirst, genchanged, |
125 |
O gencount0,gencount1, |
126 |
I mytime, myiter, mythid ) |
127 |
endif |
128 |
# else |
129 |
c-- Get the counters, flags, and the interpolation factor. |
130 |
call ctrl_get_gen_rec( |
131 |
I xx_genstartdate, xx_genperiod, |
132 |
O genfac, genfirst, genchanged, |
133 |
O gencount0,gencount1, |
134 |
I mytime, myiter, mythid ) |
135 |
# endif |
136 |
|
137 |
if ( genfirst ) then |
138 |
call active_read_xy( fnamegen, xx_gen1, gencount0, |
139 |
& doglobalread, ladinit, optimcycle, |
140 |
& mythid, xx_gen_dummy ) |
141 |
#ifdef ALLOW_CTRL_SMOOTH |
142 |
if ( xx_gen_file .EQ. xx_tauu_file .OR. |
143 |
& xx_gen_file .EQ. xx_tauv_file ) |
144 |
& call ctrl_smooth(xx_gen1,genmask) |
145 |
#endif |
146 |
#ifdef ALLOW_SMOOTH_CORREL2D |
147 |
call smooth_correl2D(xx_gen1,genmask,1,mythid) |
148 |
call smooth_correl2Dw(xx_gen1,genmask,xx_gen_file,mythid) |
149 |
write(fnamegeneric(1:80),'(2a,i10.10)') |
150 |
& xx_gen_file(1:ilgen),'.effective.',optimcycle |
151 |
call mdswritefield(fnamegeneric,ctrlprec,.FALSE.,'RL', |
152 |
& 1, xx_gen1, gencount0, optimcycle, mythid) |
153 |
#endif |
154 |
endif |
155 |
|
156 |
if (( genfirst ) .or. ( genchanged )) then |
157 |
call exf_SwapFFields( xx_gen0, xx_gen1, mythid ) |
158 |
|
159 |
call active_read_xy( fnamegen, xx_gen1 , gencount1, |
160 |
& doglobalread, ladinit, optimcycle, |
161 |
& mythid, xx_gen_dummy ) |
162 |
#ifdef ALLOW_CTRL_SMOOTH |
163 |
if ( xx_gen_file .EQ. xx_tauu_file .OR. |
164 |
& xx_gen_file .EQ. xx_tauv_file ) |
165 |
& call ctrl_smooth(xx_gen1,genmask) |
166 |
#endif |
167 |
#ifdef ALLOW_SMOOTH_CORREL2D |
168 |
call smooth_correl2D(xx_gen1,genmask,1,mythid) |
169 |
call smooth_correl2Dw(xx_gen1,genmask,xx_gen_file,mythid) |
170 |
write(fnamegeneric(1:80),'(2a,i10.10)') |
171 |
& xx_gen_file(1:ilgen),'.effective.',optimcycle |
172 |
call mdswritefield(fnamegeneric,ctrlprec,.FALSE.,'RL', |
173 |
& 1, xx_gen1, gencount1, optimcycle, mythid) |
174 |
#endif |
175 |
endif |
176 |
|
177 |
c-- Add control to model variable. |
178 |
cph( |
179 |
cph this flag ported from the SIO code |
180 |
cph Initial wind stress adjustments are too vigorous. |
181 |
if ( gencount0 .LE. 2 .AND. |
182 |
& ( xx_gen_file .EQ. xx_tauu_file .OR. |
183 |
& xx_gen_file .EQ. xx_tauv_file ) .AND. |
184 |
& ( xx_genperiod .NE. 0 ) ) then |
185 |
doCtrlUpdate = .FALSE. |
186 |
else |
187 |
doCtrlUpdate = .TRUE. |
188 |
endif |
189 |
if ( xx_gen_file .EQ. xx_tauu_file .OR. |
190 |
& xx_gen_file .EQ. xx_tauv_file ) then |
191 |
gensign = -1. |
192 |
else |
193 |
gensign = 1. |
194 |
endif |
195 |
c |
196 |
cph since the above is ECCO specific, we undo it here: |
197 |
cph doCtrlUpdate = .TRUE. |
198 |
c |
199 |
if ( doCtrlUpdate ) then |
200 |
cph) |
201 |
do bj = jtlo,jthi |
202 |
do bi = itlo,ithi |
203 |
c-- Calculate mask for tracer cells (0 => land, 1 => water). |
204 |
k = 1 |
205 |
do j = 1,sny |
206 |
do i = 1,snx |
207 |
genfld(i,j,bi,bj) = genfld (i,j,bi,bj) |
208 |
& + gensign*genfac *xx_gen0(i,j,bi,bj) |
209 |
& + gensign*(1. _d 0 - genfac)*xx_gen1(i,j,bi,bj) |
210 |
genfld(i,j,bi,bj) = |
211 |
& genmask(i,j,k,bi,bj)*( genfld (i,j,bi,bj) - |
212 |
& ( xx_gen_remo_intercept + |
213 |
& xx_gen_remo_slope*(mytime-starttime) ) ) |
214 |
enddo |
215 |
enddo |
216 |
enddo |
217 |
enddo |
218 |
cph( |
219 |
endif |
220 |
cph) |
221 |
|
222 |
#endif /* ALLOW_EXF */ |
223 |
|
224 |
end |
225 |
|