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

Last change on this file since 327 was 327, checked in by pinsard, 17 years ago

modification of headers : mainly blanks around = sign for keywords in declaration of function and pro

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