;+
;
; @file_comments
; Allows to pass from a 2d level array to a 2d depth array corresponding to
; these levels
;
; @categories
; Without loop
;
; @param TAB {in}{required}{type=2d array}
; 2d level array of sill levels (or a structure respecting litchamp
; criterions)
;
; @keyword NOMASK
; To do not mask land points.
;
; @returns
; 2d array containing depths
;
; @uses
; common
;
; @history
; Sebastien Masson (smasson\@lodyc.jussieu.fr)
; 17/6/1999
; 14/6/2000 accepte !values.f_nan
;
; @version
; $Id$
;
;-
FUNCTION level2depth, tab, NOMASK=nomask
;
compile_opt idl2, strictarrsubs
;
tempsun = systime(1) ; To key_performance
@common
;------------------------------------------------------------
; Reading of the input field and recovery of the used subdomain's size
;------------------------------------------------------------
niveaux = litchamp(tab)
grille,mask, -1, -1,gdep,nx,ny,nz,firstx,firsty,firstz,lastx,lasty,lastz
;---------------------------------------------------------------
; verification of the coherence between array's size and the domain defined
; by domdef
;---------------------------------------------------------------
taille = size(niveaux)
if taille[0] NE 2 then return, report('input field must be a 2d array')
case 1 of
taille[1] eq jpi and taille[2] eq jpj:niveaux=niveaux[firstx:lastx, firsty:lasty]
taille[1] eq nx and taille[2] eq ny:
else:return, report('Probleme d''adequation entre les tailles du domaine et celle du champ.')
endcase
;---------------------------------------------------------------
wherenan = where(finite(niveaux, /nan) EQ 1)
if wherenan[0] NE -1 then niveaux[wherenan] = 0
niveaux = 0 > niveaux < (jpk-1)
;---------------------------------------------------------------
gdep = replicate(1, nx*ny)#gdep
niveaux = lindgen(nx*ny)+(nx*ny)*niveaux
gdep = reform(gdep[niveaux], nx, ny)
;
if wherenan[0] NE -1 then gdep[wherenan] = !values.f_nan
if NOT keyword_set(nomask) then begin
if n_elements(valmask) EQ 0 then valmask = 1e20
terre = where(mask[*, *, 0] EQ 0)
if terre[0] NE -1 then gdep[terre] = valmask
endif
;
if keyword_set(key_performance) THEN print, 'temps level2depth', systime(1)-tempsun
return, gdep
end