/[MITgcm]/MITgcm/pkg/ctrl/ctrl_init.F
ViewVC logotype

Annotation of /MITgcm/pkg/ctrl/ctrl_init.F

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.1 - (hide annotations) (download)
Sun Mar 25 22:33:55 2001 UTC (23 years, 2 months ago) by heimbach
Branch: MAIN
CVS Tags: checkpoint40pre1, checkpoint38, c37_adj, checkpoint39
Modifications and additions to enable automatic differentiation.
Detailed info's in doc/notes_c37_adj.txt

1 heimbach 1.1 C $Header: /u/gcmpack/development/heimbach/div/c34_adj/pkg/ctrl/ctrl_init.F,v 1.1.1.1 2001/02/13 17:55:14 heimbach Exp $
2    
3     #include "CTRL_CPPOPTIONS.h"
4    
5    
6     subroutine ctrl_Init(
7     I mythid
8     & )
9    
10     c ==================================================================
11     c SUBROUTINE ctrl_Init
12     c ==================================================================
13     c
14     c o Set parts of the vector of control variables and initialize the
15     c rest to zero.
16     c
17     c The vector of control variables is initialized here. The
18     c temperature and salinity contributions are read from file.
19     c Subsequently, the latter are dimensionalized and the tile
20     c edges are updated.
21     c
22     c started: Christian Eckert eckert@mit.edu 30-Jun-1999
23     c
24     c changed: Christian Eckert eckert@mit.edu 23-Feb-2000
25     c - Restructured the code in order to create a package
26     c for the MITgcmUV.
27     c
28     c Patrick Heimbach heimbach@mit.edu 30-May-2000
29     c - diffsec was falsely declared.
30     c
31     c Patrick Heimbach heimbach@mit.edu 06-Jun-2000
32     c - Transferred some filename declarations
33     c from ctrl_pack/ctrl_unpack to here
34     c - Transferred mask-per-tile to here
35     c - computation of control vector length here
36     c
37     c Patrick Heimbach heimbach@mit.edu 16-Jun-2000
38     c - Added call to ctrl_pack
39     c - Alternatively: transfer writing of scale files to
40     c ctrl_unpack
41     c
42     c ==================================================================
43     c SUBROUTINE ctrl_Init
44     c ==================================================================
45    
46     implicit none
47    
48     c == global variables ==
49    
50     #include "EEPARAMS.h"
51     #include "SIZE.h"
52     #include "PARAMS.h"
53     #include "GRID.h"
54     #include "ctrl.h"
55    
56     c == routine arguments ==
57    
58     integer mythid
59    
60     c == local variables ==
61    
62     integer bi,bj
63     integer i,j,k
64     integer itlo,ithi
65     integer jtlo,jthi
66     integer jmin,jmax
67     integer imin,imax
68     integer ntmp
69    
70     integer il
71     integer errio
72     integer startrec
73     integer endrec
74    
75     character*(max_len_prec) record
76     character*(max_len_mbuf) msgbuf
77    
78     c == external ==
79    
80     integer ilnblnk
81     external ilnblnk
82    
83     c == end of interface ==
84    
85     c-- Read the namelist input.
86     namelist /ctrl_nml/
87     & xx_theta_file,
88     & xx_salt_file,
89     & xx_tauu_file,
90     & xx_tauv_file,
91     & xx_sflux_file,
92     & xx_hflux_file,
93     & xx_sss_file,
94     & xx_sst_file,
95     & xx_diffkr_file,
96     & xx_kapgm_file
97    
98     namelist /ctrl_packnames/
99     & yadmark, expId,
100     & ctrlname, costname, scalname, maskname, metaname
101    
102     jtlo = mybylo(mythid)
103     jthi = mybyhi(mythid)
104     itlo = mybxlo(mythid)
105     ithi = mybxhi(mythid)
106     jmin = 1-oly
107     jmax = sny+oly
108     imin = 1-olx
109     imax = snx+olx
110    
111     _BEGIN_MASTER( myThid )
112    
113     c-- Set default values.
114     xx_theta_file = ' '
115     xx_salt_file = ' '
116     xx_tauu_file = ' '
117     xx_tauv_file = ' '
118     xx_sflux_file = ' '
119     xx_hflux_file = ' '
120     xx_sss_file = ' '
121     xx_sst_file = ' '
122     xx_diffkr_file = ' '
123     xx_kapgm_file = ' '
124     yadmark = 'ad'
125     expId = ' '
126     ctrlname = ' '
127     costname = ' '
128     scalname = ' '
129     maskname = ' '
130     metaname = ' '
131    
132     c-- Check versions.
133    
134     open(unit=scrunit1,status='scratch')
135    
136     c-- Next, read the ecco data file.
137     open(unit = modeldataunit,file = 'data.ctrl',
138     & status = 'old', iostat = errio)
139     if ( errio .lt. 0 ) then
140     stop ' stopped in ctrl_init'
141     endif
142    
143     do while ( .true. )
144     read(modeldataunit, fmt='(a)', end=1001) record
145     il = max(ilnblnk(record),1)
146     if ( record(1:1) .ne. commentcharacter )
147     & write(unit=scrunit1, fmt='(a)') record(:il)
148     enddo
149     1001 continue
150     close( modeldataunit )
151    
152     rewind( scrunit1 )
153     read(unit = scrunit1, nml = ctrl_nml)
154     read(unit = scrunit1, nml = ctrl_packnames)
155     close( scrunit1 )
156    
157     c-- Set default values.
158     do i = 1,maxcvars
159     ncvarindex(i) = -1
160     ncvarrecs(i) = 0
161     ncvarxmax(i) = 0
162     ncvarymax(i) = 0
163     ncvarnrmax(i) = 0
164     ncvargrd(i) = '?'
165     enddo
166    
167     write(msgbuf,'(a)') ' '
168     call print_message( msgbuf, standardmessageunit,
169     & SQUEEZE_RIGHT , mythid)
170     write(msgbuf,'(a)')
171     & ' ctrl_init: Initializing temperature and salinity'
172     call print_message( msgbuf, standardmessageunit,
173     & SQUEEZE_RIGHT , mythid)
174     write(msgbuf,'(a)')
175     & ' part of the control vector.'
176     call print_message( msgbuf, standardmessageunit,
177     & SQUEEZE_RIGHT , mythid)
178     write(msgbuf,'(a,a)')
179     & ' The initial surface fluxes are set',
180     & ' to zero.'
181     call print_message( msgbuf, standardmessageunit,
182     & SQUEEZE_RIGHT , mythid)
183     write(msgbuf,'(a)') ' '
184     call print_message( msgbuf, standardmessageunit,
185     & SQUEEZE_RIGHT , mythid)
186     _END_MASTER( mythid )
187    
188     _BARRIER
189    
190     c-- =====================
191     c-- Initial state fields.
192     c-- =====================
193    
194     #ifdef ALLOW_THETA0_CONTROL
195     _BEGIN_MASTER( mythid )
196     ncvarindex(1) = 101
197     ncvarrecs(1) = 1
198     ncvarxmax(1) = snx
199     ncvarymax(1) = sny
200     ncvarnrmax(1) = nr
201     ncvargrd(1) = 'c'
202     _END_MASTER( mythid )
203     #endif /* ALLOW_THETA0_CONTROL */
204    
205     #ifdef ALLOW_SALT0_CONTROL
206     _BEGIN_MASTER( mythid )
207     ncvarindex(2) = 102
208     ncvarrecs(2) = 1
209     ncvarxmax(2) = snx
210     ncvarymax(2) = sny
211     ncvarnrmax(2) = nr
212     ncvargrd(2) = 'c'
213     _END_MASTER( mythid )
214     #endif /* ALLOW_SALT0_CONTROL */
215    
216     #ifdef ALLOW_HFLUX0_CONTROL
217     _BEGIN_MASTER( mythid )
218     ncvarindex(3) = 103
219     ncvarrecs(3) = 1
220     ncvarxmax(3) = snx
221     ncvarymax(3) = sny
222     ncvarnrmax(3) = 1
223     ncvargrd(3) = 'c'
224     _END_MASTER( mythid )
225     #endif /* ALLOW_HFLUX0_CONTROL */
226    
227     #ifdef ALLOW_SFLUX0_CONTROL
228     _BEGIN_MASTER( mythid )
229     ncvarindex(4) = 104
230     ncvarrecs(4) = 1
231     ncvarxmax(4) = snx
232     ncvarymax(4) = sny
233     ncvarnrmax(4) = 1
234     ncvargrd(4) = 'c'
235     _END_MASTER( mythid )
236     #endif /* ALLOW_SFLUX0_CONTROL */
237    
238     #ifdef ALLOW_TAUU0_CONTROL
239     _BEGIN_MASTER( mythid )
240     ncvarindex(5) = 105
241     ncvarrecs(5) = 1
242     ncvarxmax(5) = snx
243     ncvarymax(5) = sny
244     ncvarnrmax(5) = 1
245     ncvargrd(5) = 'w'
246     _END_MASTER( mythid )
247     #endif /* ALLOW_TAUU0_CONTROL */
248    
249     #ifdef ALLOW_TAUV0_CONTROL
250     _BEGIN_MASTER( mythid )
251     ncvarindex(6) = 106
252     ncvarrecs(6) = 1
253     ncvarxmax(6) = snx
254     ncvarymax(6) = sny
255     ncvarnrmax(6) = 1
256     ncvargrd(6) = 's'
257     _END_MASTER( mythid )
258     #endif /* ALLOW_TAUV0_CONTROL */
259    
260     #ifdef ALLOW_SST0_CONTROL
261     _BEGIN_MASTER( mythid )
262     ncvarindex(7) = 107
263     ncvarrecs(7) = 1
264     ncvarxmax(7) = snx
265     ncvarymax(7) = sny
266     ncvarnrmax(7) = 1
267     ncvargrd(7) = 'c'
268     _END_MASTER( mythid )
269     #endif /* ALLOW_SST0_CONTROL */
270    
271     #ifdef ALLOW_SSS0_CONTROL
272     _BEGIN_MASTER( mythid )
273     ncvarindex(8) = 108
274     ncvarrecs(8) = 1
275     ncvarxmax(8) = snx
276     ncvarymax(8) = sny
277     ncvarnrmax(8) = 1
278     ncvargrd(8) = 'c'
279     _END_MASTER( mythid )
280     #endif /* ALLOW_SSS0_CONTROL */
281    
282     c-- Determine the number of wet points in each tile:
283     c-- maskc, masks, and maskw.
284    
285     c-- Set loop ranges.
286     jmin = 1
287     jmax = sny
288     imin = 1
289     imax = snx
290    
291     c-- Initialise the counters.
292     do bj = jtlo,jthi
293     do bi = itlo,ithi
294     do k = 1,nr
295     nwetctile(bi,bj,k) = 0
296     nwetstile(bi,bj,k) = 0
297     nwetwtile(bi,bj,k) = 0
298     enddo
299     enddo
300     enddo
301    
302     c-- Count wet points on each tile.
303     do bj = jtlo,jthi
304     do bi = itlo,ithi
305     do k = 1,nr
306     do j = jmin,jmax
307     do i = imin,imax
308     c-- Center mask.
309     if (hFacC(i,j,k,bi,bj) .ne. 0.) then
310     nwetctile(bi,bj,k) = nwetctile(bi,bj,k) + 1
311     endif
312     c-- South mask.
313     if (maskS(i,j,k,bi,bj) .eq. 1.) then
314     nwetstile(bi,bj,k) = nwetstile(bi,bj,k) + 1
315     endif
316     c-- West mask.
317     if (maskW(i,j,k,bi,bj) .eq. 1.) then
318     nwetwtile(bi,bj,k) = nwetwtile(bi,bj,k) + 1
319     endif
320     enddo
321     enddo
322     enddo
323     enddo
324     enddo
325    
326    
327     _BEGIN_MASTER( mythid )
328     c-- Determine the total number of control variables.
329     nvartype = 0
330     nvarlength = 0
331     do i = 1,maxcvars
332     if ( ncvarindex(i) .ne. -1 ) then
333     nvartype = nvartype + 1
334     do bj = jtlo,jthi
335     do bi = itlo,ithi
336     if ( ncvargrd(i) .eq. 'c' ) then
337     do k = 1,ncvarnrmax(i)
338     nvarlength = nvarlength +
339     & ncvarrecs(i)*nwetctile(bi,bj,k)
340     enddo
341     else if ( ncvargrd(i) .eq. 's' ) then
342     do k = 1,ncvarnrmax(i)
343     nvarlength = nvarlength +
344     & ncvarrecs(i)*nwetstile(bi,bj,k)
345     enddo
346     else if ( ncvargrd(i) .eq. 'w' ) then
347     do k = 1,ncvarnrmax(i)
348     nvarlength = nvarlength +
349     & ncvarrecs(i)*nwetwtile(bi,bj,k)
350     enddo
351     else
352     print*,'ctrl_init: invalid grid location'
353     print*,' control variable = ',ncvarindex(i)
354     print*,' grid location = ',ncvargrd(i)
355     stop ' ... stopped in ctrl_init'
356     endif
357     enddo
358     enddo
359     endif
360     enddo
361    
362     c
363     c Summation of wet point counters
364     c
365     CALL GLOBAL_SUM_INT( nvarlength, myThid )
366     ntmp=0
367     do bj=1,nSy
368     do bi=1,nSx
369     ntmp=ntmp+nWetcTile(bi,bj,k)
370     enddo
371     enddo
372     CALL GLOBAL_SUM_INT( ntmp, myThid )
373     nWetcTile(1,1,k)=ntmp
374     ntmp=0
375     do bj=1,nSy
376     do bi=1,nSx
377     ntmp=ntmp+nWetsTile(bi,bj,k)
378     enddo
379     enddo
380     CALL GLOBAL_SUM_INT( ntmp, myThid )
381     nWetsTile(1,1,k)=ntmp
382     ntmp=0
383     do bj=1,nSy
384     do bi=1,nSx
385     ntmp=ntmp+nWetwTile(bi,bj,k)
386     enddo
387     enddo
388     CALL GLOBAL_SUM_INT( ntmp, myThid )
389     nWetwTile(1,1,k)=ntmp
390    
391     print*, 'ctrl_init: no. of control variables: ', nvartype
392     print*, 'ctrl_init: control vector length: ', nvarlength
393     _END_MASTER( mythid )
394    
395     _BARRIER
396    
397     return
398     end
399    

  ViewVC Help
Powered by ViewVC 1.1.22