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

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

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


Revision 1.3 - (hide annotations) (download)
Mon Aug 13 18:10:26 2001 UTC (22 years, 9 months ago) by heimbach
Branch: MAIN
CVS Tags: checkpoint40pre7, checkpoint40pre6, checkpoint40pre9, checkpoint40pre8, checkpoint42, checkpoint40, checkpoint41
Changes since 1.2: +189 -1 lines
Included diffkr, kapgm to set of control variables.

1 heimbach 1.3 C $Header: /u/gcmpack/models/MITgcmUV/pkg/ctrl/ctrl_pack.F,v 1.2 2001/07/13 13:40:17 heimbach Exp $
2 heimbach 1.1
3     #include "CTRL_CPPOPTIONS.h"
4    
5    
6     subroutine ctrl_pack(
7     I myiter,
8     I mytime,
9     I mythid
10     & )
11    
12     c ==================================================================
13     c SUBROUTINE ctrl_pack
14     c ==================================================================
15     c
16     c o Compress the control vector such that only ocean points are
17     c written to file.
18     c
19     c started: Christian Eckert eckert@mit.edu 10-Mar=2000
20     c
21     c changed: Patrick Heimbach heimbach@mit.edu 06-Jun-2000
22     c - Transferred some filename declarations
23     c from here to namelist in ctrl_init
24     c
25     c Patrick Heimbach heimbach@mit.edu 16-Jun-2000
26     c - single file name convention with or without
27     c ALLOW_ECCO_OPTIMIZATION
28     c
29     c
30     c ==================================================================
31     c SUBROUTINE ctrl_pack
32     c ==================================================================
33    
34     implicit none
35    
36     c == global variables ==
37    
38     #include "EEPARAMS.h"
39     #include "SIZE.h"
40     #include "PARAMS.h"
41     #include "GRID.h"
42    
43     #include "ctrl.h"
44     #include "cost.h"
45 heimbach 1.2 #include "optim.h"
46 heimbach 1.1
47     c == routine arguments ==
48    
49     integer myiter
50     _RL mytime
51     integer mythid
52    
53     c == local variables ==
54    
55     integer bi,bj
56     integer ip,jp
57     integer i,j,k
58     integer ii
59     integer il
60     integer irec
61     integer itlo,ithi
62     integer jtlo,jthi
63     integer jmin,jmax
64     integer imin,imax
65    
66     logical doglobalread
67     logical ladinit
68     integer cbuffindex
69    
70     integer cunit
71     _RL cbuff( snx*nsx*npx*sny*nsy*npy )
72     _RL globfld3d( snx,nsx,npx,sny,nsy,npy,nr )
73     _RL globfld2d( snx,nsx,npx,sny,nsy,npy )
74     _RL globmsk( snx,nsx,npx,sny,nsy,npy,nr )
75     _RL tmpvar
76    
77     character*(128) cfile
78     character*( 80) fname
79    
80     integer prec
81    
82     c == external ==
83    
84     integer ilnblnk
85     external ilnblnk
86    
87     c == end of interface ==
88    
89     prec = precFloat64
90     tmpvar = -9999. _d 0
91    
92     jtlo = 1
93     jthi = nsy
94     itlo = 1
95     ithi = nsx
96     jmin = 1
97     jmax = sny
98     imin = 1
99     imax = snx
100    
101     c-- Tiled files are used.
102     doglobalread = .false.
103    
104     c-- Initialise adjoint variables on active files.
105     ladinit = .false.
106    
107     c
108     c-- Only the master thread will do I/O.
109     _BEGIN_MASTER( mythid )
110    
111     c-- read global mask file
112     call MDSREADFIELD_3D_GL( "hFacC",
113     & prec, 'RL', Nr, globmsk,
114     & 1, mythid)
115    
116    
117     c >>> Write control vector <<<
118    
119     call mdsfindunit( cunit, mythid )
120     write(cfile(1:128),'(2a,i4.4)')
121     & ctrlname(1:9),'.opt',
122     & optimcycle
123    
124     open( cunit, file = cfile,
125     & status = 'unknown',
126     & form = 'unformatted',
127     & access = 'sequential' )
128    
129     c-- Header information.
130    
131     write(cunit) nvartype
132     write(cunit) nvarlength
133     write(cunit) expId
134     write(cunit) optimCycle
135     write(cunit) tmpvar
136     write(cunit) 1
137     write(cunit) 1
138     write(cunit) 1
139     write(cunit) 1
140     write(cunit) (nWetcTile(1,1,k), k=1,nr)
141     write(cunit) (nWetsTile(1,1,k), k=1,nr)
142     write(cunit) (nWetwTile(1,1,k), k=1,nr)
143     write(cunit) (ncvarindex(i), i=1,maxcvars)
144     write(cunit) (ncvarrecs(i), i=1,maxcvars)
145     write(cunit) (nx, i=1,maxcvars)
146     write(cunit) (ny, i=1,maxcvars)
147     write(cunit) (ncvarnrmax(i), i=1,maxcvars)
148     write(cunit) (ncvargrd(i), i=1,maxcvars)
149     write(cunit)
150    
151     #ifdef ALLOW_THETA0_CONTROL
152    
153     il=ilnblnk( xx_theta_file)
154     write(fname(1:80),'(80a)') ' '
155     write(fname(1:80),'(2a,i10.10)')
156     & xx_theta_file(1:il),'.',optimcycle
157     call MDSREADFIELD_3D_GL( fname,
158     & prec, 'RL', Nr, globfld3d,
159     & 1, mythid)
160    
161     write(cunit) ncvarindex(1)
162     write(cunit) 1
163     write(cunit) 1
164     do k = 1,nr
165     cbuffindex = 0
166     do jp = 1,nPy
167     do bj = jtlo,jthi
168     do j = jmin,jmax
169     do ip = 1,nPx
170     do bi = itlo,ithi
171     do i = imin,imax
172     if (globmsk(i,bi,ip,j,bj,jp,k) .ne. 0. ) then
173     cbuffindex = cbuffindex + 1
174     #ifdef ALLOW_NONDIMENSIONAL_CONTROL_IO
175     cbuff(cbuffindex) = globfld3d(i,bi,ip,j,bj,jp,k)
176     & * sqrt(wtheta(k,bi,bj))
177     #else
178     cbuff(cbuffindex) = globfld3d(i,bi,ip,j,bj,jp,k)
179     #endif
180     endif
181     enddo
182     enddo
183     enddo
184     enddo
185     enddo
186     enddo
187     c --> check cbuffindex.
188     if ( cbuffindex .gt. 0) then
189     write(cunit) cbuffindex
190     write(cunit) k
191     write(cunit) (cbuff(ii), ii=1,cbuffindex)
192     endif
193     enddo
194    
195     #endif
196    
197     #ifdef ALLOW_SALT0_CONTROL
198    
199     il=ilnblnk( xx_salt_file)
200     write(fname(1:80),'(80a)') ' '
201     write(fname(1:80),'(2a,i10.10)')
202     & xx_salt_file(1:il),'.',optimcycle
203     call MDSREADFIELD_3D_GL( fname,
204     & prec, 'RL', Nr, globfld3d,
205     & 1, mythid)
206    
207     write(cunit) ncvarindex(2)
208     write(cunit) 1
209     write(cunit) 1
210     do k = 1,nr
211     cbuffindex = 0
212     do jp = 1,nPy
213     do bj = jtlo,jthi
214     do j = jmin,jmax
215     do ip = 1,nPx
216     do bi = itlo,ithi
217     do i = imin,imax
218     if (globmsk(i,bi,ip,j,bj,jp,k) .ne. 0. ) then
219     cbuffindex = cbuffindex + 1
220     #ifdef ALLOW_NONDIMENSIONAL_CONTROL_IO
221     cbuff(cbuffindex) = globfld3d(i,bi,ip,j,bj,jp,k)
222     & * sqrt(wsalt(k,bi,bj))
223     #else
224     cbuff(cbuffindex) = globfld3d(i,bi,ip,j,bj,jp,k)
225     #endif
226     endif
227     enddo
228     enddo
229     enddo
230     enddo
231     enddo
232     enddo
233     c --> check cbuffindex.
234     if ( cbuffindex .gt. 0) then
235     write(cunit) cbuffindex
236     write(cunit) k
237     write(cunit) (cbuff(ii), ii=1,cbuffindex)
238     endif
239     enddo
240    
241     #endif
242    
243 heimbach 1.2 #ifdef ALLOW_TR10_CONTROL
244    
245     il=ilnblnk( xx_tr1_file)
246     write(fname(1:80),'(80a)') ' '
247     write(fname(1:80),'(2a,i10.10)')
248     & xx_tr1_file(1:il),'.',optimcycle
249     call MDSREADFIELD_3D_GL( fname,
250     & prec, 'RL', Nr, globfld3d,
251     & 1, mythid)
252    
253     write(cunit) ncvarindex(9)
254     write(cunit) 1
255     write(cunit) 1
256     do k = 1,nr
257     cbuffindex = 0
258     do jp = 1,nPy
259     do bj = jtlo,jthi
260     do j = jmin,jmax
261     do ip = 1,nPx
262     do bi = itlo,ithi
263     do i = imin,imax
264     if (globmsk(i,bi,ip,j,bj,jp,k) .ne. 0. ) then
265     cbuffindex = cbuffindex + 1
266     #ifdef ALLOW_NONDIMENSIONAL_CONTROL_IO
267     cbuff(cbuffindex) = globfld3d(i,bi,ip,j,bj,jp,k)
268     cph & * sqrt(wtr1(k,bi,bj))
269     #else
270     cbuff(cbuffindex) = globfld3d(i,bi,ip,j,bj,jp,k)
271     #endif
272     endif
273     enddo
274     enddo
275     enddo
276     enddo
277     enddo
278     enddo
279     c --> check cbuffindex.
280     if ( cbuffindex .gt. 0) then
281     write(cunit) cbuffindex
282     write(cunit) k
283     write(cunit) (cbuff(ii), ii=1,cbuffindex)
284     endif
285     enddo
286    
287     #endif
288    
289 heimbach 1.1 #ifdef ALLOW_HFLUX0_CONTROL
290    
291     il=ilnblnk( xx_hflux_file)
292     write(fname(1:80),'(80a)') ' '
293     write(fname(1:80),'(2a,i10.10)')
294     & xx_hflux_file(1:il),'.',optimcycle
295     #ifdef ALLOW_NONDIMENSIONAL_CONTROL_IO
296     call MDSREADFIELD_2D_GL( "whflux",
297     & prec, 'RL', 1,
298     & globfld2d,
299     & 1, mythid)
300     #endif
301     call MDSREADFIELD_2D_GL( fname,
302     & prec, 'RL', 1,
303     & globfld3d(1,1,1,1,1,1,1),
304     & 1, mythid)
305    
306     write(cunit) ncvarindex(3)
307     write(cunit) 1
308     write(cunit) 1
309     k = 1
310     cbuffindex = 0
311     do jp = 1,nPy
312     do bj = jtlo,jthi
313     do j = jmin,jmax
314     do ip = 1,nPx
315     do bi = itlo,ithi
316     do i = imin,imax
317     if (globmsk(i,bi,ip,j,bj,jp,k) .ne. 0. ) then
318     cbuffindex = cbuffindex + 1
319     #ifdef ALLOW_NONDIMENSIONAL_CONTROL_IO
320     cbuff(cbuffindex) = globfld3d(i,bi,ip,j,bj,jp,k)
321     & * sqrt(globfld2d(i,bi,ip,j,bj,jp))
322     #else
323     cbuff(cbuffindex) = globfld3d(i,bi,ip,j,bj,jp,k)
324     #endif
325     endif
326     enddo
327     enddo
328     enddo
329     enddo
330     enddo
331     enddo
332     c --> check cbuffindex.
333     if ( cbuffindex .gt. 0) then
334     write(cunit) cbuffindex
335     write(cunit) k
336     write(cunit) (cbuff(ii), ii=1,cbuffindex)
337     endif
338    
339     #endif
340    
341     #ifdef ALLOW_SFLUX0_CONTROL
342    
343     il=ilnblnk( xx_sflux_file)
344     write(fname(1:80),'(80a)') ' '
345     write(fname(1:80),'(2a,i10.10)')
346     & xx_sflux_file(1:il),'.',optimcycle
347     #ifdef ALLOW_NONDIMENSIONAL_CONTROL_IO
348     call MDSREADFIELD_2D_GL( "wsflux",
349     & prec, 'RL', 1,
350     & globfld2d,
351     & 1, mythid)
352     #endif
353     call MDSREADFIELD_2D_GL( fname,
354     & prec, 'RL', 1,
355     & globfld3d(1,1,1,1,1,1,1),
356     & 1, mythid)
357    
358     write(cunit) ncvarindex(4)
359     write(cunit) 1
360     write(cunit) 1
361     k = 1
362     cbuffindex = 0
363     do jp = 1,nPy
364     do bj = jtlo,jthi
365     do j = jmin,jmax
366     do ip = 1,nPx
367     do bi = itlo,ithi
368     do i = imin,imax
369     if (globmsk(i,bi,ip,j,bj,jp,k) .ne. 0. ) then
370     cbuffindex = cbuffindex + 1
371     #ifdef ALLOW_NONDIMENSIONAL_CONTROL_IO
372     cbuff(cbuffindex) = globfld3d(i,bi,ip,j,bj,jp,k)
373     & * sqrt(globfld2d(i,bi,ip,j,bj,jp))
374     #else
375     cbuff(cbuffindex) = globfld3d(i,bi,ip,j,bj,jp,k)
376     #endif
377     endif
378     enddo
379     enddo
380     enddo
381     enddo
382     enddo
383     enddo
384     c --> check cbuffindex.
385     if ( cbuffindex .gt. 0) then
386     write(cunit) cbuffindex
387     write(cunit) k
388     write(cunit) (cbuff(ii), ii=1,cbuffindex)
389     endif
390    
391     #endif
392    
393     #ifdef ALLOW_TAUU0_CONTROL
394    
395     il=ilnblnk( xx_tauu_file)
396     write(fname(1:80),'(80a)') ' '
397     write(fname(1:80),'(2a,i10.10)')
398     & xx_tauu_file(1:il),'.',optimcycle
399     #ifdef ALLOW_NONDIMENSIONAL_CONTROL_IO
400     call MDSREADFIELD_2D_GL( "wtauu",
401     & prec, 'RL', 1,
402     & globfld2d,
403     & 1, mythid)
404     #endif
405     call MDSREADFIELD_2D_GL( fname,
406     & prec, 'RL', 1,
407     & globfld3d(1,1,1,1,1,1,1),
408     & 1, mythid)
409    
410     write(cunit) ncvarindex(5)
411     write(cunit) 1
412     write(cunit) 1
413     k = 1
414     cbuffindex = 0
415     do jp = 1,nPy
416     do bj = jtlo,jthi
417     do j = jmin,jmax
418     do ip = 1,nPx
419     do bi = itlo,ithi
420     do i = imin,imax
421     if (globmsk(i,bi,ip,j,bj,jp,k) .ne. 0. ) then
422     cbuffindex = cbuffindex + 1
423     #ifdef ALLOW_NONDIMENSIONAL_CONTROL_IO
424     cbuff(cbuffindex) = globfld3d(i,bi,ip,j,bj,jp,k)
425     & * sqrt(globfld2d(i,bi,ip,j,bj,jp))
426     #else
427     cbuff(cbuffindex) = globfld3d(i,bi,ip,j,bj,jp,k)
428     #endif
429     endif
430     enddo
431     enddo
432     enddo
433     enddo
434     enddo
435     enddo
436     c --> check cbuffindex.
437     if ( cbuffindex .gt. 0) then
438     write(cunit) cbuffindex
439     write(cunit) k
440     write(cunit) (cbuff(ii), ii=1,cbuffindex)
441     endif
442    
443     #endif
444    
445     #ifdef ALLOW_TAUV0_CONTROL
446    
447     il=ilnblnk( xx_tauv_file)
448     write(fname(1:80),'(80a)') ' '
449     write(fname(1:80),'(2a,i10.10)')
450     & xx_tauv_file(1:il),'.',optimcycle
451     #ifdef ALLOW_NONDIMENSIONAL_CONTROL_IO
452     call MDSREADFIELD_2D_GL( "wtauv",
453     & prec, 'RL', 1,
454     & globfld2d,
455     & 1, mythid)
456     #endif
457     call MDSREADFIELD_2D_GL( fname,
458     & prec, 'RL', 1,
459     & globfld3d(1,1,1,1,1,1,1),
460     & 1, mythid)
461    
462     write(cunit) ncvarindex(6)
463     write(cunit) 1
464     write(cunit) 1
465     k = 1
466     cbuffindex = 0
467     do jp = 1,nPy
468     do bj = jtlo,jthi
469     do j = jmin,jmax
470     do ip = 1,nPx
471     do bi = itlo,ithi
472     do i = imin,imax
473     if (globmsk(i,bi,ip,j,bj,jp,k) .ne. 0. ) then
474     cbuffindex = cbuffindex + 1
475     #ifdef ALLOW_NONDIMENSIONAL_CONTROL_IO
476     cbuff(cbuffindex) = globfld3d(i,bi,ip,j,bj,jp,k)
477     & * sqrt(globfld2d(i,bi,ip,j,bj,jp))
478     #else
479     cbuff(cbuffindex) = globfld3d(i,bi,ip,j,bj,jp,k)
480     #endif
481     endif
482     enddo
483     enddo
484     enddo
485     enddo
486     enddo
487     enddo
488     c --> check cbuffindex.
489     if ( cbuffindex .gt. 0) then
490     write(cunit) cbuffindex
491     write(cunit) k
492     write(cunit) (cbuff(ii), ii=1,cbuffindex)
493     endif
494    
495     #endif
496    
497     #ifdef ALLOW_SST0_CONTROL
498    
499     il=ilnblnk( xx_sst_file)
500     write(fname(1:80),'(80a)') ' '
501     write(fname(1:80),'(2a,i10.10)')
502     & xx_sst_file(1:il),'.',optimcycle
503     #ifdef ALLOW_NONDIMENSIONAL_CONTROL_IO
504     call MDSREADFIELD_2D_GL( "wsst",
505     & prec, 'RL', 1,
506     & globfld2d,
507     & 1, mythid)
508     #endif
509     call MDSREADFIELD_2D_GL( fname,
510     & prec, 'RL', 1,
511     & globfld3d(1,1,1,1,1,1,1),
512     & 1, mythid)
513    
514     write(cunit) ncvarindex(7)
515     write(cunit) 1
516     write(cunit) 1
517     k = 1
518     cbuffindex = 0
519     do jp = 1,nPy
520     do bj = jtlo,jthi
521     do j = jmin,jmax
522     do ip = 1,nPx
523     do bi = itlo,ithi
524     do i = imin,imax
525     if (globmsk(i,bi,ip,j,bj,jp,k) .ne. 0. ) then
526     cbuffindex = cbuffindex + 1
527     #ifdef ALLOW_NONDIMENSIONAL_CONTROL_IO
528     cbuff(cbuffindex) = globfld3d(i,bi,ip,j,bj,jp,k)
529     & * sqrt(globfld2d(i,bi,ip,j,bj,jp))
530     #else
531     cbuff(cbuffindex) = globfld3d(i,bi,ip,j,bj,jp,k)
532     #endif
533     endif
534     enddo
535     enddo
536     enddo
537     enddo
538     enddo
539     enddo
540     c --> check cbuffindex.
541     if ( cbuffindex .gt. 0) then
542     write(cunit) cbuffindex
543     write(cunit) k
544     write(cunit) (cbuff(ii), ii=1,cbuffindex)
545     endif
546    
547     #endif
548    
549     #ifdef ALLOW_SSS0_CONTROL
550    
551     il=ilnblnk( xx_sss_file)
552     write(fname(1:80),'(80a)') ' '
553     write(fname(1:80),'(2a,i10.10)')
554     & xx_sss_file(1:il),'.',optimcycle
555     #ifdef ALLOW_NONDIMENSIONAL_CONTROL_IO
556     call MDSREADFIELD_2D_GL( "wsss",
557     & prec, 'RL', 1,
558     & globfld2d,
559     & 1, mythid)
560     #endif
561     call MDSREADFIELD_2D_GL( fname,
562     & prec, 'RL', 1,
563     & globfld3d(1,1,1,1,1,1,1),
564     & 1, mythid)
565    
566     write(cunit) ncvarindex(8)
567     write(cunit) 1
568     write(cunit) 1
569     k = 1
570     cbuffindex = 0
571     do jp = 1,nPy
572     do bj = jtlo,jthi
573     do j = jmin,jmax
574     do ip = 1,nPx
575     do bi = itlo,ithi
576     do i = imin,imax
577     if (globmsk(i,bi,ip,j,bj,jp,k) .ne. 0. ) then
578     cbuffindex = cbuffindex + 1
579     #ifdef ALLOW_NONDIMENSIONAL_CONTROL_IO
580     cbuff(cbuffindex) = globfld3d(i,bi,ip,j,bj,jp,k)
581     & * sqrt(globfld2d(i,bi,ip,j,bj,jp))
582     #else
583     cbuff(cbuffindex) = globfld3d(i,bi,ip,j,bj,jp,k)
584     #endif
585     endif
586     enddo
587     enddo
588     enddo
589     enddo
590     enddo
591     enddo
592     c --> check cbuffindex.
593     if ( cbuffindex .gt. 0) then
594     write(cunit) cbuffindex
595     write(cunit) k
596     write(cunit) (cbuff(ii), ii=1,cbuffindex)
597     endif
598    
599     #endif
600    
601 heimbach 1.3 #ifdef ALLOW_DIFFKR_CONTROL
602    
603     il=ilnblnk( xx_diffkr_file)
604     write(fname(1:80),'(80a)') ' '
605     write(fname(1:80),'(2a,i10.10)')
606     & xx_diffkr_file(1:il),'.',optimcycle
607     call MDSREADFIELD_3D_GL( fname,
608     & prec, 'RL', Nr, globfld3d,
609     & 1, mythid)
610    
611     write(cunit) ncvarindex(15)
612     write(cunit) 1
613     write(cunit) 1
614     do k = 1,nr
615     cbuffindex = 0
616     do jp = 1,nPy
617     do bj = jtlo,jthi
618     do j = jmin,jmax
619     do ip = 1,nPx
620     do bi = itlo,ithi
621     do i = imin,imax
622     if (globmsk(i,bi,ip,j,bj,jp,k) .ne. 0. ) then
623     cbuffindex = cbuffindex + 1
624     #ifdef ALLOW_NONDIMENSIONAL_CONTROL_IO
625     cbuff(cbuffindex) = globfld3d(i,bi,ip,j,bj,jp,k)
626     cph & * sqrt(wdiffkr(k,bi,bj))
627     #else
628     cbuff(cbuffindex) = globfld3d(i,bi,ip,j,bj,jp,k)
629     #endif
630     endif
631     enddo
632     enddo
633     enddo
634     enddo
635     enddo
636     enddo
637     c --> check cbuffindex.
638     if ( cbuffindex .gt. 0) then
639     write(cunit) cbuffindex
640     write(cunit) k
641     write(cunit) (cbuff(ii), ii=1,cbuffindex)
642     endif
643     enddo
644    
645     #endif
646    
647     #ifdef ALLOW_KAPGM_CONTROL
648    
649     il=ilnblnk( xx_kapgm_file)
650     write(fname(1:80),'(80a)') ' '
651     write(fname(1:80),'(2a,i10.10)')
652     & xx_kapgm_file(1:il),'.',optimcycle
653     call MDSREADFIELD_3D_GL( fname,
654     & prec, 'RL', Nr, globfld3d,
655     & 1, mythid)
656    
657     write(cunit) ncvarindex(16)
658     write(cunit) 1
659     write(cunit) 1
660     do k = 1,nr
661     cbuffindex = 0
662     do jp = 1,nPy
663     do bj = jtlo,jthi
664     do j = jmin,jmax
665     do ip = 1,nPx
666     do bi = itlo,ithi
667     do i = imin,imax
668     if (globmsk(i,bi,ip,j,bj,jp,k) .ne. 0. ) then
669     cbuffindex = cbuffindex + 1
670     #ifdef ALLOW_NONDIMENSIONAL_CONTROL_IO
671     cbuff(cbuffindex) = globfld3d(i,bi,ip,j,bj,jp,k)
672     cph & * sqrt(wkapgm(k,bi,bj))
673     #else
674     cbuff(cbuffindex) = globfld3d(i,bi,ip,j,bj,jp,k)
675     #endif
676     endif
677     enddo
678     enddo
679     enddo
680     enddo
681     enddo
682     enddo
683     c --> check cbuffindex.
684     if ( cbuffindex .gt. 0) then
685     write(cunit) cbuffindex
686     write(cunit) k
687     write(cunit) (cbuff(ii), ii=1,cbuffindex)
688     endif
689     enddo
690    
691     #endif
692 heimbach 1.1
693     close ( cunit )
694    
695     _END_MASTER( mythid )
696    
697     c======================================================================
698    
699     c-- read global mask file
700     call MDSREADFIELD_3D_GL( "hFacC",
701     & prec, 'RL', Nr, globmsk,
702     & 1, mythid)
703    
704     c >>> Write gradient vector <<<
705    
706     call mdsfindunit( cunit, mythid )
707     write(cfile(1:128),'(2a,i4.4)')
708     & costname(1:9),'.opt',
709     & optimcycle
710    
711     open( cunit, file = cfile,
712     & status = 'unknown',
713     & form = 'unformatted',
714     & access = 'sequential' )
715    
716     c-- Header information.
717     write(cunit) nvartype
718     write(cunit) nvarlength
719     write(cunit) expId
720     write(cunit) optimCycle
721     write(cunit) fc
722     write(cunit) 1
723     write(cunit) 1
724     write(cunit) 1
725     write(cunit) 1
726     write(cunit) (nWetcTile(1,1,k), k=1,nr)
727     write(cunit) (nWetsTile(1,1,k), k=1,nr)
728     write(cunit) (nWetwTile(1,1,k), k=1,nr)
729     write(cunit) (ncvarindex(i), i=1,maxcvars)
730     write(cunit) (ncvarrecs(i), i=1,maxcvars)
731     write(cunit) (nx, i=1,maxcvars)
732     write(cunit) (ny, i=1,maxcvars)
733     write(cunit) (ncvarnrmax(i), i=1,maxcvars)
734     write(cunit) (ncvargrd(i), i=1,maxcvars)
735     write(cunit)
736    
737     #ifdef ALLOW_THETA0_CONTROL
738    
739     il=ilnblnk( xx_theta_file)
740     write(fname(1:80),'(80a)') ' '
741     write(fname(1:80),'(3a,i10.10)')
742     & yadmark,xx_theta_file(1:il),'.',optimcycle
743    
744     call MDSREADFIELD_3D_GL( fname,
745     & prec, 'RL', Nr,
746     & globfld3d,
747     & 1, mythid)
748    
749     write(cunit) ncvarindex(1)
750     write(cunit) 1
751     write(cunit) 1
752     do k = 1,nr
753     cbuffindex = 0
754     do jp = 1,nPy
755     do bj = jtlo,jthi
756     do j = jmin,jmax
757     do ip = 1,nPx
758     do bi = itlo,ithi
759     do i = imin,imax
760     if (globmsk(i,bi,ip,j,bj,jp,k) .ne. 0. ) then
761     cbuffindex = cbuffindex + 1
762     #ifdef ALLOW_NONDIMENSIONAL_CONTROL_IO
763     cbuff(cbuffindex) = globfld3d(i,bi,ip,j,bj,jp,k)
764     & * sqrt(wtheta(k,bi,bj))
765     #else
766     cbuff(cbuffindex) = globfld3d(i,bi,ip,j,bj,jp,k)
767     #endif
768     endif
769     enddo
770     enddo
771     enddo
772     enddo
773     enddo
774     enddo
775     c --> check cbuffindex.
776     if ( cbuffindex .gt. 0) then
777     write(cunit) cbuffindex
778     write(cunit) k
779     write(cunit) (cbuff(ii), ii=1,cbuffindex)
780     endif
781     enddo
782    
783     #endif
784    
785     #ifdef ALLOW_SALT0_CONTROL
786    
787     il=ilnblnk( xx_salt_file)
788     write(fname(1:80),'(80a)') ' '
789     write(fname(1:80),'(3a,i10.10)')
790     & yadmark,xx_salt_file(1:il),'.',optimcycle
791    
792     call MDSREADFIELD_3D_GL( fname,
793     & prec, 'RL', Nr,
794     & globfld3d,
795     & 1, mythid)
796    
797     write(cunit) ncvarindex(2)
798     write(cunit) 1
799     write(cunit) 1
800     do k = 1,nr
801     cbuffindex = 0
802     do jp = 1,nPy
803     do bj = jtlo,jthi
804     do j = jmin,jmax
805     do ip = 1,nPx
806     do bi = itlo,ithi
807     do i = imin,imax
808     if (globmsk(i,bi,ip,j,bj,jp,k) .ne. 0. ) then
809     cbuffindex = cbuffindex + 1
810     #ifdef ALLOW_NONDIMENSIONAL_CONTROL_IO
811     cbuff(cbuffindex) = globfld3d(i,bi,ip,j,bj,jp,k)
812     & * sqrt(wsalt(k,bi,bj))
813     #else
814     cbuff(cbuffindex) = globfld3d(i,bi,ip,j,bj,jp,k)
815     #endif
816     endif
817     enddo
818     enddo
819     enddo
820     enddo
821     enddo
822     enddo
823     c --> check cbuffindex.
824     if ( cbuffindex .gt. 0) then
825     write(cunit) cbuffindex
826     write(cunit) k
827     write(cunit) (cbuff(ii), ii=1,cbuffindex)
828     endif
829     enddo
830    
831     #endif
832    
833 heimbach 1.2 #ifdef ALLOW_TR10_CONTROL
834    
835     il=ilnblnk( xx_tr1_file)
836     write(fname(1:80),'(80a)') ' '
837     write(fname(1:80),'(3a,i10.10)')
838     & yadmark,xx_tr1_file(1:il),'.',optimcycle
839    
840     call MDSREADFIELD_3D_GL( fname,
841     & prec, 'RL', Nr,
842     & globfld3d,
843     & 1, mythid)
844    
845     write(cunit) ncvarindex(9)
846     write(cunit) 1
847     write(cunit) 1
848     do k = 1,nr
849     cbuffindex = 0
850     do jp = 1,nPy
851     do bj = jtlo,jthi
852     do j = jmin,jmax
853     do ip = 1,nPx
854     do bi = itlo,ithi
855     do i = imin,imax
856     if (globmsk(i,bi,ip,j,bj,jp,k) .ne. 0. ) then
857     cbuffindex = cbuffindex + 1
858     #ifdef ALLOW_NONDIMENSIONAL_CONTROL_IO
859     cbuff(cbuffindex) = globfld3d(i,bi,ip,j,bj,jp,k)
860     cph & * sqrt(wtr1(k,bi,bj))
861     #else
862     cbuff(cbuffindex) = globfld3d(i,bi,ip,j,bj,jp,k)
863     #endif
864     endif
865     enddo
866     enddo
867     enddo
868     enddo
869     enddo
870     enddo
871     c --> check cbuffindex.
872     if ( cbuffindex .gt. 0) then
873     write(cunit) cbuffindex
874     write(cunit) k
875     write(cunit) (cbuff(ii), ii=1,cbuffindex)
876     endif
877     enddo
878    
879     #endif
880 heimbach 1.1
881     #ifdef ALLOW_HFLUX0_CONTROL
882    
883     il=ilnblnk( xx_hflux_file)
884     write(fname(1:80),'(80a)') ' '
885     write(fname(1:80),'(3a,i10.10)')
886     & yadmark,xx_hflux_file(1:il),'.',optimcycle
887     #ifdef ALLOW_NONDIMENSIONAL_CONTROL_IO
888     call MDSREADFIELD_2D_GL( "whflux",
889     & prec, 'RL', 1,
890     & globfld2d,
891     & 1, mythid)
892     #endif
893     call MDSREADFIELD_2D_GL( fname,
894     & prec, 'RL', 1,
895     & globfld3d(1,1,1,1,1,1,1),
896     & 1, mythid)
897    
898     write(cunit) ncvarindex(3)
899     write(cunit) 1
900     write(cunit) 1
901     k = 1
902     cbuffindex = 0
903     do jp = 1,nPy
904     do bj = jtlo,jthi
905     do j = jmin,jmax
906     do ip = 1,nPx
907     do bi = itlo,ithi
908     do i = imin,imax
909     if (globmsk(i,bi,ip,j,bj,jp,k) .ne. 0. ) then
910     cbuffindex = cbuffindex + 1
911     #ifdef ALLOW_NONDIMENSIONAL_CONTROL_IO
912     cbuff(cbuffindex) = globfld3d(i,bi,ip,j,bj,jp,k)
913     & * sqrt(globfld2d(i,bi,ip,j,bj,jp))
914     #else
915     cbuff(cbuffindex) = globfld3d(i,bi,ip,j,bj,jp,k)
916     #endif
917     endif
918     enddo
919     enddo
920     enddo
921     enddo
922     enddo
923     enddo
924     c --> check cbuffindex.
925     if ( cbuffindex .gt. 0) then
926     write(cunit) cbuffindex
927     write(cunit) k
928     write(cunit) (cbuff(ii), ii=1,cbuffindex)
929     endif
930    
931     #endif
932    
933     #ifdef ALLOW_SFLUX0_CONTROL
934    
935     il=ilnblnk( xx_sflux_file)
936     write(fname(1:80),'(80a)') ' '
937     write(fname(1:80),'(3a,i10.10)')
938     & yadmark,xx_sflux_file(1:il),'.',optimcycle
939     #ifdef ALLOW_NONDIMENSIONAL_CONTROL_IO
940     call MDSREADFIELD_2D_GL( "wsflux",
941     & prec, 'RL', 1,
942     & globfld2d,
943     & 1, mythid)
944     #endif
945     call MDSREADFIELD_2D_GL( fname,
946     & prec, 'RL', 1,
947     & globfld3d(1,1,1,1,1,1,1),
948     & 1, mythid)
949    
950     write(cunit) ncvarindex(4)
951     write(cunit) 1
952     write(cunit) 1
953     k = 1
954     cbuffindex = 0
955     do jp = 1,nPy
956     do bj = jtlo,jthi
957     do j = jmin,jmax
958     do ip = 1,nPx
959     do bi = itlo,ithi
960     do i = imin,imax
961     if (globmsk(i,bi,ip,j,bj,jp,k) .ne. 0. ) then
962     cbuffindex = cbuffindex + 1
963     #ifdef ALLOW_NONDIMENSIONAL_CONTROL_IO
964     cbuff(cbuffindex) = globfld3d(i,bi,ip,j,bj,jp,k)
965     & * sqrt(globfld2d(i,bi,ip,j,bj,jp))
966     #else
967     cbuff(cbuffindex) = globfld3d(i,bi,ip,j,bj,jp,k)
968     #endif
969     endif
970     enddo
971     enddo
972     enddo
973     enddo
974     enddo
975     enddo
976     c --> check cbuffindex.
977     if ( cbuffindex .gt. 0) then
978     write(cunit) cbuffindex
979     write(cunit) k
980     write(cunit) (cbuff(ii), ii=1,cbuffindex)
981     endif
982    
983     #endif
984    
985     #ifdef ALLOW_TAUU0_CONTROL
986    
987     il=ilnblnk( xx_tauu_file)
988     write(fname(1:80),'(80a)') ' '
989     write(fname(1:80),'(3a,i10.10)')
990     & yadmark,xx_tauu_file(1:il),'.',optimcycle
991     #ifdef ALLOW_NONDIMENSIONAL_CONTROL_IO
992     call MDSREADFIELD_2D_GL( "wtauu",
993     & prec, 'RL', 1,
994     & globfld2d,
995     & 1, mythid)
996     #endif
997     call MDSREADFIELD_2D_GL( fname,
998     & prec, 'RL', 1,
999     & globfld3d(1,1,1,1,1,1,1),
1000     & 1, mythid)
1001    
1002     write(cunit) ncvarindex(5)
1003     write(cunit) 1
1004     write(cunit) 1
1005     k = 1
1006     cbuffindex = 0
1007     do jp = 1,nPy
1008     do bj = jtlo,jthi
1009     do j = jmin,jmax
1010     do ip = 1,nPx
1011     do bi = itlo,ithi
1012     do i = imin,imax
1013     if (globmsk(i,bi,ip,j,bj,jp,k) .ne. 0. ) then
1014     cbuffindex = cbuffindex + 1
1015     #ifdef ALLOW_NONDIMENSIONAL_CONTROL_IO
1016     cbuff(cbuffindex) = globfld3d(i,bi,ip,j,bj,jp,k)
1017     & * sqrt(globfld2d(i,bi,ip,j,bj,jp))
1018     #else
1019     cbuff(cbuffindex) = globfld3d(i,bi,ip,j,bj,jp,k)
1020     #endif
1021     endif
1022     enddo
1023     enddo
1024     enddo
1025     enddo
1026     enddo
1027     enddo
1028     c --> check cbuffindex.
1029     if ( cbuffindex .gt. 0) then
1030     write(cunit) cbuffindex
1031     write(cunit) k
1032     write(cunit) (cbuff(ii), ii=1,cbuffindex)
1033     endif
1034    
1035     #endif
1036    
1037     #ifdef ALLOW_TAUV0_CONTROL
1038    
1039     il=ilnblnk( xx_tauv_file)
1040     write(fname(1:80),'(80a)') ' '
1041     write(fname(1:80),'(3a,i10.10)')
1042     & yadmark,xx_tauv_file(1:il),'.',optimcycle
1043     #ifdef ALLOW_NONDIMENSIONAL_CONTROL_IO
1044     call MDSREADFIELD_2D_GL( "wtauv",
1045     & prec, 'RL', 1,
1046     & globfld2d,
1047     & 1, mythid)
1048     #endif
1049     call MDSREADFIELD_2D_GL( fname,
1050     & prec, 'RL', 1,
1051     & globfld3d(1,1,1,1,1,1,1),
1052     & 1, mythid)
1053    
1054     write(cunit) ncvarindex(6)
1055     write(cunit) 1
1056     write(cunit) 1
1057     k = 1
1058     cbuffindex = 0
1059     do jp = 1,nPy
1060     do bj = jtlo,jthi
1061     do j = jmin,jmax
1062     do ip = 1,nPx
1063     do bi = itlo,ithi
1064     do i = imin,imax
1065     if (globmsk(i,bi,ip,j,bj,jp,k) .ne. 0. ) then
1066     cbuffindex = cbuffindex + 1
1067     #ifdef ALLOW_NONDIMENSIONAL_CONTROL_IO
1068     cbuff(cbuffindex) = globfld3d(i,bi,ip,j,bj,jp,k)
1069     & * sqrt(globfld2d(i,bi,ip,j,bj,jp))
1070     #else
1071     cbuff(cbuffindex) = globfld3d(i,bi,ip,j,bj,jp,k)
1072     #endif
1073     endif
1074     enddo
1075     enddo
1076     enddo
1077     enddo
1078     enddo
1079     enddo
1080     c --> check cbuffindex.
1081     if ( cbuffindex .gt. 0) then
1082     write(cunit) cbuffindex
1083     write(cunit) k
1084     write(cunit) (cbuff(ii), ii=1,cbuffindex)
1085     endif
1086    
1087     #endif
1088    
1089     #ifdef ALLOW_SST0_CONTROL
1090    
1091     il=ilnblnk( xx_sst_file)
1092     write(fname(1:80),'(80a)') ' '
1093     write(fname(1:80),'(3a,i10.10)')
1094     & yadmark,xx_sst_file(1:il),'.',optimcycle
1095     #ifdef ALLOW_NONDIMENSIONAL_CONTROL_IO
1096     call MDSREADFIELD_2D_GL( "wsst",
1097     & prec, 'RL', 1,
1098     & globfld2d,
1099     & 1, mythid)
1100     #endif
1101     call MDSREADFIELD_2D_GL( fname,
1102     & prec, 'RL', 1,
1103     & globfld3d(1,1,1,1,1,1,1),
1104     & 1, mythid)
1105    
1106     write(cunit) ncvarindex(7)
1107     write(cunit) 1
1108     write(cunit) 1
1109     k = 1
1110     cbuffindex = 0
1111     do jp = 1,nPy
1112     do bj = jtlo,jthi
1113     do j = jmin,jmax
1114     do ip = 1,nPx
1115     do bi = itlo,ithi
1116     do i = imin,imax
1117     if (globmsk(i,bi,ip,j,bj,jp,k) .ne. 0. ) then
1118     cbuffindex = cbuffindex + 1
1119     #ifdef ALLOW_NONDIMENSIONAL_CONTROL_IO
1120     cbuff(cbuffindex) = globfld3d(i,bi,ip,j,bj,jp,k)
1121     & * sqrt(globfld2d(i,bi,ip,j,bj,jp))
1122     #else
1123     cbuff(cbuffindex) = globfld3d(i,bi,ip,j,bj,jp,k)
1124     #endif
1125     endif
1126     enddo
1127     enddo
1128     enddo
1129     enddo
1130     enddo
1131     enddo
1132     c --> check cbuffindex.
1133     if ( cbuffindex .gt. 0) then
1134     write(cunit) cbuffindex
1135     write(cunit) k
1136     write(cunit) (cbuff(ii), ii=1,cbuffindex)
1137     endif
1138    
1139     #endif
1140    
1141     #ifdef ALLOW_SSS0_CONTROL
1142    
1143     il=ilnblnk( xx_sss_file)
1144     write(fname(1:80),'(80a)') ' '
1145     write(fname(1:80),'(3a,i10.10)')
1146     & yadmark,xx_sss_file(1:il),'.',optimcycle
1147     #ifdef ALLOW_NONDIMENSIONAL_CONTROL_IO
1148     call MDSREADFIELD_2D_GL( "wsss",
1149     & prec, 'RL', 1,
1150     & globfld2d,
1151     & 1, mythid)
1152     #endif
1153     call MDSREADFIELD_2D_GL( fname,
1154     & prec, 'RL', 1,
1155     & globfld3d(1,1,1,1,1,1,1),
1156     & 1, mythid)
1157    
1158     write(cunit) ncvarindex(8)
1159     write(cunit) 1
1160     write(cunit) 1
1161     k = 1
1162     cbuffindex = 0
1163     do jp = 1,nPy
1164     do bj = jtlo,jthi
1165     do j = jmin,jmax
1166     do ip = 1,nPx
1167     do bi = itlo,ithi
1168     do i = imin,imax
1169     if (globmsk(i,bi,ip,j,bj,jp,k) .ne. 0. ) then
1170     cbuffindex = cbuffindex + 1
1171     #ifdef ALLOW_NONDIMENSIONAL_CONTROL_IO
1172     cbuff(cbuffindex) = globfld3d(i,bi,ip,j,bj,jp,k)
1173     & * sqrt(globfld2d(i,bi,ip,j,bj,jp))
1174     #else
1175     cbuff(cbuffindex) = globfld3d(i,bi,ip,j,bj,jp,k)
1176     #endif
1177     endif
1178     enddo
1179     enddo
1180     enddo
1181     enddo
1182     enddo
1183     enddo
1184     c --> check cbuffindex.
1185     if ( cbuffindex .gt. 0) then
1186     write(cunit) cbuffindex
1187     write(cunit) k
1188     write(cunit) (cbuff(ii), ii=1,cbuffindex)
1189     endif
1190    
1191     #endif
1192 heimbach 1.3
1193     #ifdef ALLOW_DIFFKR_CONTROL
1194    
1195     il=ilnblnk( xx_diffkr_file)
1196     write(fname(1:80),'(80a)') ' '
1197     write(fname(1:80),'(3a,i10.10)')
1198     & yadmark,xx_diffkr_file(1:il),'.',optimcycle
1199    
1200     call MDSREADFIELD_3D_GL( fname,
1201     & prec, 'RL', Nr,
1202     & globfld3d,
1203     & 1, mythid)
1204    
1205     write(cunit) ncvarindex(9)
1206     write(cunit) 1
1207     write(cunit) 1
1208     do k = 1,nr
1209     cbuffindex = 0
1210     do jp = 1,nPy
1211     do bj = jtlo,jthi
1212     do j = jmin,jmax
1213     do ip = 1,nPx
1214     do bi = itlo,ithi
1215     do i = imin,imax
1216     if (globmsk(i,bi,ip,j,bj,jp,k) .ne. 0. ) then
1217     cbuffindex = cbuffindex + 1
1218     #ifdef ALLOW_NONDIMENSIONAL_CONTROL_IO
1219     cbuff(cbuffindex) = globfld3d(i,bi,ip,j,bj,jp,k)
1220     cph & * sqrt(wdiffkr(k,bi,bj))
1221     #else
1222     cbuff(cbuffindex) = globfld3d(i,bi,ip,j,bj,jp,k)
1223     #endif
1224     endif
1225     enddo
1226     enddo
1227     enddo
1228     enddo
1229     enddo
1230     enddo
1231     c --> check cbuffindex.
1232     if ( cbuffindex .gt. 0) then
1233     write(cunit) cbuffindex
1234     write(cunit) k
1235     write(cunit) (cbuff(ii), ii=1,cbuffindex)
1236     endif
1237     enddo
1238    
1239     #endif
1240    
1241     #ifdef ALLOW_KAPGM_CONTROL
1242    
1243     il=ilnblnk( xx_kapgm_file)
1244     write(fname(1:80),'(80a)') ' '
1245     write(fname(1:80),'(3a,i10.10)')
1246     & yadmark,xx_kapgm_file(1:il),'.',optimcycle
1247    
1248     call MDSREADFIELD_3D_GL( fname,
1249     & prec, 'RL', Nr,
1250     & globfld3d,
1251     & 1, mythid)
1252    
1253     write(cunit) ncvarindex(9)
1254     write(cunit) 1
1255     write(cunit) 1
1256     do k = 1,nr
1257     cbuffindex = 0
1258     do jp = 1,nPy
1259     do bj = jtlo,jthi
1260     do j = jmin,jmax
1261     do ip = 1,nPx
1262     do bi = itlo,ithi
1263     do i = imin,imax
1264     if (globmsk(i,bi,ip,j,bj,jp,k) .ne. 0. ) then
1265     cbuffindex = cbuffindex + 1
1266     #ifdef ALLOW_NONDIMENSIONAL_CONTROL_IO
1267     cbuff(cbuffindex) = globfld3d(i,bi,ip,j,bj,jp,k)
1268     cph & * sqrt(wkapgm(k,bi,bj))
1269     #else
1270     cbuff(cbuffindex) = globfld3d(i,bi,ip,j,bj,jp,k)
1271     #endif
1272     endif
1273     enddo
1274     enddo
1275     enddo
1276     enddo
1277     enddo
1278     enddo
1279     c --> check cbuffindex.
1280     if ( cbuffindex .gt. 0) then
1281     write(cunit) cbuffindex
1282     write(cunit) k
1283     write(cunit) (cbuff(ii), ii=1,cbuffindex)
1284     endif
1285     enddo
1286    
1287     #endif
1288    
1289 heimbach 1.1
1290     close ( cunit )
1291    
1292     return
1293     end
1294    

  ViewVC Help
Powered by ViewVC 1.1.22