source: trunk/tools/density_binning/binning_neutral_and_co/bin_velocity_New.pro @ 161

Last change on this file since 161 was 161, checked in by pinsard, 15 years ago

conversion from IDL help header syntax to IDLDOC 2. header syntax

File size: 6.7 KB
Line 
1FUNCTION bin_velocity_New, dens, sigma_values, x1, UU = uu, VV = vv, TT = tt
2;
3@common
4;
5; test the stability of dens and correct it if necessary
6; ------------------------------------------------------
7   dens=npc(dens)
8;
9; compute the density profile at U or V point if necessary
10; --------------------------------------------------------   
11   IF keyword_set(uu) THEN BEGIN
12      density = boundperio(umask()*(dens+shift(dens, -1, 0, 0))/2, /uu, /orca2, /pscal)
13      xmask = umask()
14   ENDIF
15   IF keyword_set(vv) THEN BEGIN
16      density = boundperio(vmask()*(dens+shift(dens, 0, -1, 0))/2, /vv, /orca2, /pscal)
17      xmask = vmask()
18   ENDIF
19      IF keyword_set(tt) THEN BEGIN
20      density = dens
21      xmask = tmask
22   ENDIF
23;
24; initializations
25      s_s = sigma_values        ; density range over which we bin
26      N_s = n_elements(s_s)     ; number of density levels
27      N_z = jpk                 ; number of z levels
28;   Profiles along z level ( suffixe _z)
29      c1_z = fltarr(N_z)        ; profil du contenu vertical de x
30      s_z = fltarr(N_z)         ; profil de la densite
31; vertical coordinate: in z-coord only
32      z_zt = gdept              ; profondeur au point T  (k=0 -> 5m)
33                                ; z_zw = gdepw (old)       
34      z_zw=shift(gdepw,-1)      ;                     W  (k=0 -> 10m)
35      z_zw(jpk-1)=gdepw(jpk-1) 
36     
37; s or partial step case:
38      ioMESH   = iodir+'meshes'
39      fich_msh = 'mesh_mask_NDV1.nc'
40      z3d_zt     = read_ncdf('e3v_ps',0,/timestep,iodir=ioMESH,/nostruct,/tout,filename=fich_msh)
41      z3d_zt(where(z3d_zt eq 1.e20))=500.
42      z3d_zw = total(z3d_zt,3,/cumulative)      ;  W  (k=0 -> 10m)
43      z3d_zt = (shift(z3d_zw,0,0,1)+z3d_zw)*0.5
44      z3d_zt(*,*,0) = z3d_zw(*,*,0)*0.5         ; T  (k=0 -> 5m)
45     
46;   Profiles along density level (suffixe _s)
47      z_s  = fltarr(N_s+1)
48      c1_s = fltarr(N_s+1)
49      x1_s = fltarr(N_s+1)
50;   x1 binned on density (output array)
51      x1_bin = fltarr(jpi, jpj, N_s+1)
52;
53; vertical content of x1 (ensure  the integrale conservation)
54      x1_content = fltarr(jpi, jpj, jpk)
55      x1_content(*, *, 0) = e3t(0) * x1(*, *, 0) * xmask(*,*,0)
56      FOR k = 1, jpk-1 DO x1_content(*, *, k) = x1_content(*, *, k-1) $
57                                              + e3t(k) * x1(*, *, k) * xmask(*,*,k)
58;
59;  Loop over the horizontal domain 2D
60;
61   FOR i = 0, (jpi-1) DO BEGIN
62      FOR j = 0, (jpj-1) DO BEGIN
63     
64; depth at T and W points
65         z_zt(*) = z3d_zt(i,j,*)
66         z_zw(*) = z3d_zw(i,j,*)
67     
68;
69;  Indices des points T dans l ocean
70;
71         i_ocean = where(xmask(i, j, *) EQ 1)
72         z_s = z_s*0.
73         c1_s = c1_s*0.
74         x1_s = x1_s*0.
75         IF (i_ocean[0] NE -1) THEN BEGIN ; on n'entre que si il y a des points ocean
76 
77            s_z(*) = density(i, j, *)
78            c1_z(*) = x1_content(i, j, *)
79; critere supplementaire a imposer sur le profil pour eviter les cas
80; pathologiques en attendant d'ecrire une vraie commande d'extraction
81; de progils stritement croissant. Il s'agit donc d'un test adhoc.
82            IF s_z(0) LT s_z(i_ocean(n_elements(i_ocean)-1)) THEN BEGIN
83;------------------------------------------------------------------------
84; controle si le profil est bien strictement croissant (pour l'instant
85; inutilisŽ (avis aux amateurs)
86;
87;            ds = (shift(s_z, -1)-s_z)(i_ocean(0:n_elements(i_ocean)-2))
88;            ds(0) = 0
89;            ind = where(ds LT 0.)
90;            croissant =  ind(0) EQ -1
91;------------------------------------------------------------------------
92            i_bottom = i_ocean(n_elements(i_ocean)-1)
93            z_s(N_s) = z_zw(i_bottom)
94            c1_s(N_s) = x1_content(i, j, jpk-1)
95           
96; extraction d'un sous profil strictement croissant
97            mini = min(s_z(i_ocean))
98            maxi = max(s_z(i_ocean))           
99            i_min = where(s_z(i_ocean) EQ mini)
100            i_max = where(s_z(i_ocean) EQ maxi)
101;   on prend le plus grand des indices min
102;         et le plus petit des indices max
103  ;gr          i_min = i_min(n_elements(i_min)-1)
104  ;gr          i_max = i_max[0]
105             i_min = i_min[0]
106             i_max = i_max(n_elements(i_min)-1)
107;            IF i_max GE jpk-1 THEN print, i, j, i_max
108;            IF i_min LE 1 THEN print, i, j, i_min
109           
110; Si la valeur du niveau (s_s) est plus faible que la densite de surface,
111; l isopycne est mise en surface (z_s=0)
112;
113            ind = where(s_s LT s_z(i_min))
114            IF ind[0] NE -1 THEN BEGIN          &$
115               z_s(ind) = 0                     &$
116               c1_s(ind) = 0                    &$
117            ENDIF
118; Si la valeur du niveau (s_s) est plus elevee que la densite du fond,
119; l isopycne est mise au fond (z_s=z_zw(i_bottom))
120;
121            ind = where(s_s GT s_z(i_max))
122            IF ind[0] NE -1 THEN BEGIN          &$
123               z_s(ind) = z_s(N_s)              &$
124               c1_s(ind) = c1_s(N_s)            &$
125            ENDIF
126;
127     ds =(shift(s_z, -1)-s_z)(i_ocean(0:n_elements(i_ocean)-2))
128     ind_c = where(ds LT 0.)     
129;     croissant =  ind_c(0) EQ -1
130;     IF ( i_min GT i_max ) then begin
131;     print, 'bug ',i_min, i_max,'  en i,j=', i,j
132;     endif
133     IF ( ind_c(0) NE -1 ) then begin 
134           print, 'bug   en i,j=', i,j,'  ind_c = ', ind_c
135           stop
136     endif
137;     IF ( i_min LE i_max ) then begin
138       IF ( ind_c(0) EQ -1 ) then begin
139            ind = where( (s_s GE s_z(i_min)) AND (s_s LT s_z(i_max)) )
140            IF ind[0] NE -1 THEN BEGIN
141               IF ( n_elements(ind) NE 1 ) THEN BEGIN
142               
143                   i_profil = i_ocean(i_min:i_max)
144                   z_s(ind) = interpol(z_zt(i_profil), s_z(i_profil), s_s(ind))
145               
146;
147; j'utilise la fonction spline pour interpoler le contenu
148;
149                   c1_s(ind) = spline(z_zw(i_profil), c1_z(i_profil), z_s(ind), 1)
150;
151; l'interpolation lineaire marche aussi. Elle donne des resultats differents. Elle
152; me semble moins propre. Je la donne en remarque.
153;
154;                  c_s(ind+1) = interpol(c_z(i_profil), z_zw(i_profil), z_s(ind+1))
155;
156; Remarque : on ne divise pas par l'epaisseur de la couche
157               ENDIF
158               ; cas pathologique (tout dans 1 gamme de densite)
159               IF ( n_elements(ind) EQ 1 ) THEN BEGIN
160 ;                  print, 'one density bin   en i,j=', i,j,'  ind = ', ind
161                   c1_s(ind) = c1_z(jpk-1)
162               ENDIF
163;
164                   x1_s(ind[0]-1) = (c1_s(ind[0])-c1_s(ind[0]-1));/(z_s(ind+1)-z_s(ind))
165                   x1_s(ind) = (c1_s(ind+1)-c1_s(ind));/(z_s(ind+1)-z_s(ind))
166;                   x1_s(ind[0]-1) = (c1_s(ind[0])-c1_s(ind[0]-1))/(z_s(ind+1)-z_s(ind))
167;                   x1_s(ind) = (c1_s(ind+1)-c1_s(ind))/(z_s(ind+1)-z_s(ind))
168            ENDIF
169     endif
170         ENDIF
171         ENDIF
172         x1_bin(i, j, *) = x1_s
173         
174      ENDFOR
175   ENDFOR
176   
177   return, x1_bin
178END
Note: See TracBrowser for help on using the repository browser.