/[MITgcm]/MITgcm_contrib/SOSE/BoxAdj/code_ad/ctrl_init_obcs_variables.F
ViewVC logotype

Annotation of /MITgcm_contrib/SOSE/BoxAdj/code_ad/ctrl_init_obcs_variables.F

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


Revision 1.6 - (hide annotations) (download)
Fri Mar 18 19:02:39 2011 UTC (14 years, 9 months ago) by mmazloff
Branch: MAIN
Changes since 1.5: +0 -4 lines
again

1 mmazloff 1.1 C
2 mmazloff 1.4 C $Header: /u/gcmpack/MITgcm/pkg/ctrl/ctrl_init_obcs_variables.F,v 1.6 2004/12/04 17:12:00 heimbach Exp $
3     C $Name: checkpoint57a_pre $
4 mmazloff 1.1
5     #include "CTRL_CPPOPTIONS.h"
6    
7     subroutine ctrl_init_obcs_variables( mythid )
8    
9     c ==================================================================
10     c SUBROUTINE ctrl_init_obcs_variables
11     c ==================================================================
12     c
13     c o Set parts of the vector of control variables and initialize the
14     c rest to zero.
15     c
16     c started: heimbach@mit.edu 25-Mar-2002
17     c
18     c ==================================================================
19     c SUBROUTINE ctrl_init_obcs_variables
20     c ==================================================================
21    
22     implicit none
23    
24     c == global variables ==
25    
26     #include "EEPARAMS.h"
27     #include "SIZE.h"
28     #include "PARAMS.h"
29     #include "GRID.h"
30    
31     #include "ctrl.h"
32     #ifdef ALLOW_OBCS_CONTROL
33     # include "OBCS.h"
34     #endif
35    
36     c == routine arguments ==
37    
38     integer mythid
39    
40     c == local variables ==
41    
42     integer bi,bj
43     integer i,j,k
44     integer itlo,ithi
45     integer jtlo,jthi
46     integer jmin,jmax
47     integer imin,imax
48     integer ntmp
49     integer ivarindex
50     integer iobcs
51    
52     c == end of interface ==
53    
54     jtlo = mybylo(mythid)
55     jthi = mybyhi(mythid)
56     itlo = mybxlo(mythid)
57     ithi = mybxhi(mythid)
58     jmin = 1-oly
59     jmax = sny+oly
60     imin = 1-olx
61     imax = snx+olx
62    
63     #ifdef ALLOW_OBCSN_CONTROL
64     do iobcs = 1, nobcs
65     do bj = jtlo,jthi
66     do bi = itlo,ithi
67     do k = 1,nr
68     do i = imin,imax
69     xx_obcsn0(i,k,bi,bj,iobcs) = 0. _d 0
70     xx_obcsn1(i,k,bi,bj,iobcs) = 0. _d 0
71     enddo
72     enddo
73     enddo
74     enddo
75     enddo
76     #endif
77    
78     #ifdef ALLOW_OBCSS_CONTROL
79     do iobcs = 1, nobcs
80     do bj = jtlo,jthi
81     do bi = itlo,ithi
82     do k = 1,nr
83     do i = imin,imax
84     xx_obcss0(i,k,bi,bj,iobcs) = 0. _d 0
85     xx_obcss1(i,k,bi,bj,iobcs) = 0. _d 0
86     enddo
87     enddo
88     enddo
89     enddo
90     enddo
91     #endif
92    
93     #ifdef ALLOW_OBCSW_CONTROL
94     do iobcs = 1, nobcs
95     do bj = jtlo,jthi
96     do bi = itlo,ithi
97     do k = 1,nr
98     do j = jmin,jmax
99     xx_obcsw0(j,k,bi,bj,iobcs) = 0. _d 0
100     xx_obcsw1(j,k,bi,bj,iobcs) = 0. _d 0
101     enddo
102     enddo
103     enddo
104     enddo
105     enddo
106     #endif
107    
108     #ifdef ALLOW_OBCSE_CONTROL
109     do iobcs = 1, nobcs
110     do bj = jtlo,jthi
111     do bi = itlo,ithi
112     do k = 1,nr
113     do j = jmin,jmax
114     xx_obcse0(j,k,bi,bj,iobcs) = 0. _d 0
115     xx_obcse1(j,k,bi,bj,iobcs) = 0. _d 0
116     enddo
117     enddo
118     enddo
119     enddo
120     enddo
121     #endif
122    
123     #ifdef ALLOW_OBCS_CONTROL
124     cih Get matrices for reconstruction from barotropic-barclinic modes
125     CMM have not put in a good way to use/not use modes -- better to have
126     c runtime option (e.g. defining filename=baro_invmodes.bin)
127     c for now hardcode with ECCO_CPPOPTION
128     #ifndef ALLOW_OBCS_CONTROL_MODES
129     CMM if this is not defined then don't use modes
130     c let z and k space be equal
131     do k = 1,nr
132     do j = 1,nr
133     do i = 1,nr
134     modesv(i,j,k) = 1. _d 0
135     enddo
136     enddo
137     enddo
138     #else
139     CMM -- i want to use mdsreadvector but cannot as it assumes some
140     c grid info and will increment record accordingly
141     c so for now use this -- it works -- and fix in future....
142 mmazloff 1.4 c should fix rel too - not universal!
143 mmazloff 1.1 open(117, file='baro_invmodes.bin', access='direct',
144     & recl=2*WORDLENGTH*Nr*Nr, status='old')
145 mmazloff 1.2 do j = 1,Nr
146 mmazloff 1.3 read(117,rec=j) ((modesv(k,i,j), k=1,Nr), i=1,Nr)
147 mmazloff 1.1 end do
148     #endif
149     CMM AND HERE IS README PART OF CODE:
150     CMM modesv should be orthonormal modes -- ideally solution of
151     c planetary vertical mode equation using model mean dRho/dz
152     c modesv is nr X nr X nr
153     c dim one is z-space
154     c dim two is mode space
155     c dim three is the total depth for which this set of modes applies
156     c so for example modesv(:,2,nr) will be the second mode
157     c in z-space for the full model depth
158     c It is important to note that the modes must be orthogonal
159     c when weighted by dz!
160     c i.e. if f_i(z) = mode i, sum_j(f_i(z_j)*f_j(z_j)*dz_j = delta_ij
161     c first mode should also be constant in depth...barotropic
162     c here is matlab code to ensure modes are orthonormal
163     c ________________________________________________________
164     C for k = 2:NZ;
165     C iz = 1:k;% iz = vector of depth levels
166     C NZ-k % print out a progress number
167 mmazloff 1.4 C % have to weight by dz! Make a vector of fractional dz
168 mmazloff 1.1 C zwt = DRF(iz)/sum(DRF(iz),1);
169     C %ensure first mode is barotropic (constant in depth)
170     C avm1=sum(modesv(iz,1,k).*zwt,1);
171     C modesv(iz,1,k)=avm1;
172     C %make all modes orthogonal weighted by delta z
173     C % use gram-schmidt leaving first one the same
174     C for mds = 1:k-1
175     C R = sum((modesv(iz,mds,k).^2).*zwt,1);
176 mmazloff 1.4 C R2 =(transpose(modesv(iz,mds,k).*zwt))*modesv(iz,mds+1:k,k)/R;
177 mmazloff 1.1 C modesv(iz,mds+1:k,k) = modesv(iz,mds+1:k,k) - ...
178     C modesv(iz,mds,k)*R2;
179     C end
180     C %All now orthognal, now normalize
181     C for mds = 1:k
182     C R = sqrt(sum((modesv(iz,mds,k).^2).*zwt,1));
183     C if R < 1e-8
184 mmazloff 1.5 C fprintf('Small R for mds = %2i and k = %2i\n',mds,k);
185 mmazloff 1.1 C R = inf;
186     C end
187     C modesv(iz,mds,k) = modesv(iz,mds,k)./R;
188     C end
189     C end;% end of loop over depth level k
190     C fid = fopen('baro_invmodes.bin','w','b');
191     C fwrite(fid,modesv,'single');%or double depending on control prec
192     C fclose(fid)
193     C if 1 %plot first 5 modes for deepest case
194     C figure
195     C clf;plot(modesv(:,[1:5],NZ),RC(:));
196     C end
197     C if 1 % test orthogonality
198     C % do whole matrix (need to include dz!)
199     C k = NZ;
200 mmazloff 1.4 C cmm=(transpose(squeeze(modesv(iz,iz,k)).*repmat(zwt,[1 k])))* ...
201 mmazloff 1.1 C squeeze(modesv(iz,iz,k));
202     C figure;imagesc(cmm);colorbar
203     C end
204     C save baro_invmodes modesv
205     c ________________________________________________________
206    
207     #endif
208    
209    
210     return
211     end
212    
213    
214    

  ViewVC Help
Powered by ViewVC 1.1.22