[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 | ;- |
---|
| 43 | FUNCTION depth2level, tab, LOWER = lower, UPPER = upper, CLOSER = closer $ |
---|
[232] | 44 | , NOMASK = nomask, _EXTRA = ex |
---|
[114] | 45 | ; |
---|
| 46 | compile_opt idl2, strictarrsubs |
---|
| 47 | ; |
---|
[142] | 48 | tempsun = systime(1) ; for key_performance |
---|
[2] | 49 | @common |
---|
| 50 | ;------------------------------------------------------------ |
---|
| 51 | upper = 1 |
---|
| 52 | if keyword_set(lower) THEN upper = 0 |
---|
| 53 | ;------------------------------------------------------------ |
---|
[142] | 54 | ; Reading of the input field and recuperation of the used subdomain's size |
---|
[2] | 55 | ;------------------------------------------------------------ |
---|
| 56 | in = litchamp(tab) |
---|
[25] | 57 | grille,mask,-1,-1,gdep,nx,ny,nz,firstx,firsty,firstz,lastx,lasty,lastz |
---|
[2] | 58 | ;--------------------------------------------------------------- |
---|
[142] | 59 | ; Verification of the coherence between array's size and the defined by domdef domain |
---|
[2] | 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 |
---|
[25] | 65 | taille[1] eq jpi and taille[2] eq jpj:in=in[firstx:lastx, firsty:lasty] |
---|
[2] | 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 | ;------------------------------------------------------------ |
---|
[142] | 72 | ; delete points at !values.f_nan |
---|
[2] | 73 | notanumber = where(finite(in, /nan) EQ 1) |
---|
| 74 | if notanumber[0] NE -1 then in[notanumber] = 0 |
---|
| 75 | ;------------------------------------------------------------ |
---|
[226] | 76 | ; We transform the 2d depth value in a 2d array of levels corresponding to depths |
---|
[2] | 77 | ;------------------------------------------------------------ |
---|
[142] | 78 | ; We go on array who have the size of 3d arrays |
---|
[226] | 79 | prof=replicate(1,nx*ny)#gdep[firstz:lastz] |
---|
[2] | 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 |
---|
[25] | 88 | notvalid = where(levels EQ -1) |
---|
[2] | 89 | ENDIF ELSE notvalid = where(levels EQ nz) |
---|
| 90 | IF notvalid[0] NE -1 THEN levels[notvalid] = !values.f_nan |
---|
| 91 | |
---|
[142] | 92 | ; If closer is activated |
---|
[2] | 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 | ;------------------------------------------------------------ |
---|
[142] | 101 | ; We put back points at !values.f_nan |
---|
[2] | 102 | if notanumber[0] NE -1 then levels[notanumber] = !values.f_nan |
---|
[142] | 103 | ; We mask land points at valmask |
---|
[2] | 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 | ;------------------------------------------------------------ |
---|
[226] | 112 | if keyword_set(key_performance) THEN print, 'temps depth2level', systime(1)-tempsun |
---|
[2] | 113 | return, levels |
---|
| 114 | end |
---|