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

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

typo and links in header in some pro files

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