source: trunk/SRC/ToBeReviewed/CALCULS/depth2level.pro @ 163

Last change on this file since 163 was 163, checked in by navarro, 18 years ago

header improvements : type of parameters and keywords, default values, spell checking + idldoc assistant (IDL online_help)

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 4.5 KB
Line 
1;------------------------------------------------------------
2;------------------------------------------------------------
3;------------------------------------------------------------
4;+
5;
6; @file_comments
7; Allows to pass from a 2d depth array to a corresponding 2d level array.
8;
9; @categories
10; Without loop
11;
12; @param TAB {type=2d array}
13; 2d depth array (or a structure respecting litchamp critrions)
14;
15; @keyword UPPER
16; (activated by default) We select the level just above the depth
17;
18; @keyword LOWER
19; We select the level just below the depth
20;
21; @keyword CLOSER
22; We select the depth's closer level
23;
24; @keyword NOMASK
25; To do not mask land points
26;
27; @returns
28; It is a 2d array containing level's values.
29;
30; @uses
31; common.pro
32;
33; @restrictions
34; For depths out of gdep's values, the value !values.f_nan is sent back.
35; if the depth is superior to this one of the bottom, we send back jpk-1 in
36; the upper case, and !values.f_nan in the lower case.
37;
38; @history
39; Sebastien Masson (smasson\@lodyc.jussieu.fr)
40;                       17/6/1999
41;                       15/6/2000 accepte !values.f_nan
42;
43; @version
44; $Id$
45;-
46;------------------------------------------------------------
47;------------------------------------------------------------
48;------------------------------------------------------------
49FUNCTION depth2level, tab, LOWER = lower, UPPER = upper, CLOSER = closer $
50                      , NOMASK = nomask, _extra = ex
51;
52  compile_opt idl2, strictarrsubs
53;
54   tempsun = systime(1)         ; for key_performance
55@common
56;------------------------------------------------------------
57   upper = 1
58   if keyword_set(lower) THEN upper = 0
59;------------------------------------------------------------
60; Reading of the input field and recuperation of the used subdomain's size
61;------------------------------------------------------------
62   in = litchamp(tab)
63   grille,mask,-1,-1,gdep,nx,ny,nz,firstx,firsty,firstz,lastx,lasty,lastz
64;---------------------------------------------------------------
65; Verification of the coherence between array's size and the defined by domdef domain
66;---------------------------------------------------------------
67   IF ny EQ 1 THEN in = reform(in, nx, ny, /over)
68   taille = size(in)
69   if taille[0] NE 2 then return, report('le champ en entree doit contenir un tableau 2d')
70   case 1 of
71      taille[1] eq jpi and taille[2] eq jpj:in=in[firstx:lastx, firsty:lasty]
72      taille[1] eq  nx and taille[2] eq  ny:
73      else:return, report('Probleme d''adequation entre les tailles du domaine et celle du champ.')
74   endcase
75;------------------------------------------------------------
76;------------------------------------------------------------
77;------------------------------------------------------------
78; delete points at !values.f_nan
79   notanumber = where(finite(in, /nan) EQ 1)
80   if notanumber[0] NE -1 then in[notanumber] = 0
81;------------------------------------------------------------
82; We transform the 2d deth value in a 2d array of levels corresponding to depthes
83;------------------------------------------------------------
84; We go on array who have the size of 3d arrays
85   prof=replicate(1,nx*ny)#gdep[firstz:lastz]
86   in = in[*]#replicate(1, nz)
87;
88   mask01 = (prof[*] LT in[*])
89   mask01 = reform(mask01, nx, ny, nz)
90   levels = total(mask01, 3)
91   notvalid = where(levels EQ nz)
92   if keyword_set(upper) then begin
93      levels = levels-1
94      notvalid = where(levels EQ -1)
95   ENDIF ELSE notvalid = where(levels EQ nz)
96   IF notvalid[0] NE -1 THEN levels[notvalid] = !values.f_nan
97
98; If closer is activated
99   if keyword_set(closer) then begin
100      test = [ [[litchamp(tab)-level2depth(levels)]] $
101               , [[level2depth( (levels+1)<(jpk-1) )-litchamp(tab)]] ]
102      test = test[*, *, 0]-test[*, *, 1]
103      changer = where(test GE 0)
104      if changer[0] NE -1 then levels[changer] = (levels[changer]+1) < (jpk-1)
105   endif
106;------------------------------------------------------------
107; We put back points at !values.f_nan
108   if notanumber[0] NE -1 then levels[notanumber] = !values.f_nan
109; We mask land points at valmask
110   if NOT keyword_set(nomask) then begin
111      if n_elements(valmask) EQ 0 then valmask = 1e20
112      terre = where(mask[*, *, 0] EQ 0)
113      if terre[0] NE -1 then levels[terre] = valmask
114   endif
115;------------------------------------------------------------
116;------------------------------------------------------------
117;------------------------------------------------------------
118   if keyword_set(key_performance) THEN print, 'temps depth2level', systime(1)-tempsun
119   return, levels
120end
Note: See TracBrowser for help on using the repository browser.