[2] | 1 | ;------------------------------------------------------------ |
---|
| 2 | ;------------------------------------------------------------ |
---|
| 3 | ;------------------------------------------------------------ |
---|
| 4 | ;+ |
---|
| 5 | ; NAME: depth2level |
---|
| 6 | ; |
---|
| 7 | ; PURPOSE: permet de passer d''un tableau 2d de profondeur au tableau |
---|
| 8 | ; 2d correspondant de niveaux. |
---|
| 9 | ; |
---|
| 10 | ; CATEGORY: SANS BOUCLE |
---|
| 11 | ; |
---|
| 12 | ; CALLING SEQUENCE: res=depth2level(depth2d) |
---|
| 13 | ; |
---|
| 14 | ; INPUTS: depth2d tableau 2d de profondeur (ou une structure repondant |
---|
| 15 | ; aux criteres de litchamp) |
---|
| 16 | ; |
---|
| 17 | ; KEYWORD PARAMETERS: |
---|
| 18 | ; |
---|
| 19 | ; /UPPER: (active par defaut) on selectionne le niveau |
---|
| 20 | ; directement au dessus de la profondeur |
---|
| 21 | ; |
---|
| 22 | ; /LOWER: on selectionne le niveau directement au dessous de la |
---|
| 23 | ; profondeur |
---|
| 24 | ; |
---|
| 25 | ; /CLOSER: on selectionne le niveau le plus proche de la |
---|
| 26 | ; profondeur |
---|
| 27 | ; |
---|
| 28 | ; /NOMASK: pour ne pas masquer les points terres |
---|
| 29 | ; |
---|
| 30 | ; OUTPUTS: un tableau 2d contenant les valeurs des niveaux. |
---|
| 31 | ; |
---|
| 32 | ; COMMON BLOCKS:common.pro |
---|
| 33 | ; |
---|
| 34 | ; SIDE EFFECTS:pour les profondeurs hors des valeurs de gdep, la |
---|
| 35 | ; valeur !values.f_nan est retournee. |
---|
| 36 | ; Si la profondeur est superieur a celle du fond, on retourne |
---|
| 37 | ; jpk-1dans le cas upper, et !values.f_nan ds le cas lower. |
---|
| 38 | ; |
---|
| 39 | ; RESTRICTIONS: |
---|
| 40 | ; |
---|
| 41 | ; EXAMPLE: |
---|
| 42 | ; |
---|
| 43 | ; MODIFICATION HISTORY: Sebastien Masson (smasson@lodyc.jussieu.fr) |
---|
| 44 | ; 17/6/1999 |
---|
| 45 | ; 15/6/2000 accepte !values.f_nan |
---|
| 46 | ;- |
---|
| 47 | ;------------------------------------------------------------ |
---|
| 48 | ;------------------------------------------------------------ |
---|
| 49 | ;------------------------------------------------------------ |
---|
| 50 | FUNCTION depth2level, tab, LOWER = lower, UPPER = upper, CLOSER = closer $ |
---|
| 51 | , NOMASK = nomask, _extra = ex |
---|
| 52 | tempsun = systime(1) ; pour key_performance |
---|
| 53 | @common |
---|
| 54 | ;------------------------------------------------------------ |
---|
| 55 | upper = 1 |
---|
| 56 | if keyword_set(lower) THEN upper = 0 |
---|
| 57 | ;------------------------------------------------------------ |
---|
| 58 | ; lecture du champ d''entree et recuperation de la taille du sous |
---|
| 59 | ; domaine utilise |
---|
| 60 | ;------------------------------------------------------------ |
---|
| 61 | in = litchamp(tab) |
---|
[25] | 62 | grille,mask,-1,-1,gdep,nx,ny,nz,firstx,firsty,firstz,lastx,lasty,lastz |
---|
[2] | 63 | ;--------------------------------------------------------------- |
---|
| 64 | ; verification de la coherence entre la taille du tableau et le domaine definit par domdef |
---|
| 65 | ;--------------------------------------------------------------- |
---|
| 66 | IF ny EQ 1 THEN in = reform(in, nx, ny, /over) |
---|
| 67 | taille = size(in) |
---|
| 68 | if taille[0] NE 2 then return, report('le champ en entree doit contenir un tableau 2d') |
---|
| 69 | case 1 of |
---|
[25] | 70 | taille[1] eq jpi and taille[2] eq jpj:in=in[firstx:lastx, firsty:lasty] |
---|
[2] | 71 | taille[1] eq nx and taille[2] eq ny: |
---|
| 72 | else:return, report('Probleme d''adequation entre les tailles du domaine et celle du champ.') |
---|
| 73 | endcase |
---|
| 74 | ;------------------------------------------------------------ |
---|
| 75 | ;------------------------------------------------------------ |
---|
| 76 | ;------------------------------------------------------------ |
---|
| 77 | ; vire les points a !values.f_nan |
---|
| 78 | notanumber = where(finite(in, /nan) EQ 1) |
---|
| 79 | if notanumber[0] NE -1 then in[notanumber] = 0 |
---|
| 80 | ;------------------------------------------------------------ |
---|
| 81 | ; on transforme le tableau 2d de profondeur en tableau 2d de niveaux |
---|
| 82 | ; correspondant aux profondeurs |
---|
| 83 | ;------------------------------------------------------------ |
---|
| 84 | ; on passe en tableaux qui ont la taille des tableaux 3d |
---|
[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 | |
---|
| 98 | ; si closer est active |
---|
| 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 | ;------------------------------------------------------------ |
---|
| 107 | ; on replace les points a !values.f_nan |
---|
| 108 | if notanumber[0] NE -1 then levels[notanumber] = !values.f_nan |
---|
| 109 | ; on masque les points terres a valmask |
---|
| 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 |
---|
| 120 | end |
---|