;------------------------------------------------------------ ;------------------------------------------------------------ ;------------------------------------------------------------ ;+ ; ; @file_comments ; Allows to pass from a 2d depth array to a corresponding 2d level array. ; ; @categories ; Without loop ; ; @param TAB ; 2d depth array (or a structure respecting litchamp critrions) ; ; @keyword UPPER ; (activated by default) We select the level just above the depth ; ; @keyword LOWER ; We select the level just below the depth ; ; @keyword CLOSER ; We select the depth's closer level ; ; @keyword NOMASK ; To do not mask land points ; ; @returns ; It is a 2d array containing level's values. ; ; @uses ; common.pro ; ; @restrictions ; For depthes out of gdep's values, the value !values.f_nan is sent back. ; if the depth is superior to this one of the bottom, we send back jpk-1 in ; the upper case, and !values.f_nan in the lower case. ; ; @history ; Sebastien Masson (smasson@lodyc.jussieu.fr) ; 17/6/1999 ; 15/6/2000 accepte !values.f_nan ; ; @version ; $Id$ ;- ;------------------------------------------------------------ ;------------------------------------------------------------ ;------------------------------------------------------------ FUNCTION depth2level, tab, LOWER = lower, UPPER = upper, CLOSER = closer $ , NOMASK = nomask, _extra = ex ; compile_opt idl2, strictarrsubs ; tempsun = systime(1) ; for key_performance @common ;------------------------------------------------------------ upper = 1 if keyword_set(lower) THEN upper = 0 ;------------------------------------------------------------ ; Reading of the input field and recuperation of the used subdomain's size ;------------------------------------------------------------ in = 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 defined by domdef domain ;--------------------------------------------------------------- IF ny EQ 1 THEN in = reform(in, nx, ny, /over) taille = size(in) if taille[0] NE 2 then return, report('le champ en entree doit contenir un tableau 2d') case 1 of taille[1] eq jpi and taille[2] eq jpj:in=in[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 ;------------------------------------------------------------ ;------------------------------------------------------------ ;------------------------------------------------------------ ; delete points at !values.f_nan notanumber = where(finite(in, /nan) EQ 1) if notanumber[0] NE -1 then in[notanumber] = 0 ;------------------------------------------------------------ ; We transform the 2d deth value in a 2d array of levels corresponding to depthes ;------------------------------------------------------------ ; We go on array who have the size of 3d arrays prof=replicate(1,nx*ny)#gdep[firstz:lastz] in = in[*]#replicate(1, nz) ; mask01 = (prof[*] LT in[*]) mask01 = reform(mask01, nx, ny, nz) levels = total(mask01, 3) notvalid = where(levels EQ nz) if keyword_set(upper) then begin levels = levels-1 notvalid = where(levels EQ -1) ENDIF ELSE notvalid = where(levels EQ nz) IF notvalid[0] NE -1 THEN levels[notvalid] = !values.f_nan ; If closer is activated if keyword_set(closer) then begin test = [ [[litchamp(tab)-level2depth(levels)]] $ , [[level2depth( (levels+1)<(jpk-1) )-litchamp(tab)]] ] test = test[*, *, 0]-test[*, *, 1] changer = where(test GE 0) if changer[0] NE -1 then levels[changer] = (levels[changer]+1) < (jpk-1) endif ;------------------------------------------------------------ ; We put back points at !values.f_nan if notanumber[0] NE -1 then levels[notanumber] = !values.f_nan ; We mask land points at valmask 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 levels[terre] = valmask endif ;------------------------------------------------------------ ;------------------------------------------------------------ ;------------------------------------------------------------ if keyword_set(key_performance) THEN print, 'temps depth2level', systime(1)-tempsun return, levels end