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

Last change on this file since 199 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
RevLine 
[2]1;------------------------------------------------------------
2;------------------------------------------------------------
3;------------------------------------------------------------
4;+
5;
[142]6; @file_comments
7; Allows to pass from a 2d depth array to a corresponding 2d level array.
[2]8;
[142]9; @categories
10; Without loop
[2]11;
[163]12; @param TAB {type=2d array}
[142]13; 2d depth array (or a structure respecting litchamp critrions)
[2]14;
[142]15; @keyword UPPER
16; (activated by default) We select the level just above the depth
[2]17;
[142]18; @keyword LOWER
19; We select the level just below the depth
[2]20;
[142]21; @keyword CLOSER
22; We select the depth's closer level
[2]23;
[142]24; @keyword NOMASK
25; To do not mask land points
[2]26;
[142]27; @returns
28; It is a 2d array containing level's values.
[2]29;
[142]30; @uses
31; common.pro
[2]32;
[142]33; @restrictions
[163]34; For depths out of gdep's values, the value !values.f_nan is sent back.
[142]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.
[2]37;
[142]38; @history
[157]39; Sebastien Masson (smasson\@lodyc.jussieu.fr)
[2]40;                       17/6/1999
41;                       15/6/2000 accepte !values.f_nan
[142]42;
43; @version
44; $Id$
[2]45;-
46;------------------------------------------------------------
47;------------------------------------------------------------
48;------------------------------------------------------------
49FUNCTION depth2level, tab, LOWER = lower, UPPER = upper, CLOSER = closer $
50                      , NOMASK = nomask, _extra = ex
[114]51;
52  compile_opt idl2, strictarrsubs
53;
[142]54   tempsun = systime(1)         ; for key_performance
[2]55@common
56;------------------------------------------------------------
57   upper = 1
58   if keyword_set(lower) THEN upper = 0
59;------------------------------------------------------------
[142]60; Reading of the input field and recuperation of the used subdomain's size
[2]61;------------------------------------------------------------
62   in = litchamp(tab)
[25]63   grille,mask,-1,-1,gdep,nx,ny,nz,firstx,firsty,firstz,lastx,lasty,lastz
[2]64;---------------------------------------------------------------
[142]65; Verification of the coherence between array's size and the defined by domdef domain
[2]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
[25]71      taille[1] eq jpi and taille[2] eq jpj:in=in[firstx:lastx, firsty:lasty]
[2]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;------------------------------------------------------------
[142]78; delete points at !values.f_nan
[2]79   notanumber = where(finite(in, /nan) EQ 1)
80   if notanumber[0] NE -1 then in[notanumber] = 0
81;------------------------------------------------------------
[142]82; We transform the 2d deth value in a 2d array of levels corresponding to depthes
[2]83;------------------------------------------------------------
[142]84; We go on array who have the size of 3d arrays
[25]85   prof=replicate(1,nx*ny)#gdep[firstz:lastz]
[2]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
[25]94      notvalid = where(levels EQ -1)
[2]95   ENDIF ELSE notvalid = where(levels EQ nz)
96   IF notvalid[0] NE -1 THEN levels[notvalid] = !values.f_nan
97
[142]98; If closer is activated
[2]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;------------------------------------------------------------
[142]107; We put back points at !values.f_nan
[2]108   if notanumber[0] NE -1 then levels[notanumber] = !values.f_nan
[142]109; We mask land points at valmask
[2]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.