1 | ;+ |
---|
2 | ; |
---|
3 | ; @file_comments |
---|
4 | ; Allows to project a 3d field following a depth array. |
---|
5 | ; |
---|
6 | ; @categories |
---|
7 | ; Without loop |
---|
8 | ; |
---|
9 | ; @param ARRAYIN {type=3d array} |
---|
10 | ; It is a 3d array whose 3rd dimension must be equal to jpk |
---|
11 | ; |
---|
12 | ; @param DEPTHIN {type=2d array} |
---|
13 | ; It is a 2d array indicating for each point n, at which depth to project |
---|
14 | ; |
---|
15 | ; @returns |
---|
16 | ; A 2d array which is the projection of the 3d array following depths indicated by depthin |
---|
17 | ; |
---|
18 | ; @uses |
---|
19 | ; common.pro |
---|
20 | ; |
---|
21 | ; @restrictions |
---|
22 | ; points at !values.f_nan impossible calculation. Land points masked at valmask. |
---|
23 | ; |
---|
24 | ; @examples |
---|
25 | ; we build a possible depths array |
---|
26 | ; IDL> a=gdept[jpk-1]/(1.*jpi*jpj)*findgen(jpi,jpj) |
---|
27 | ; We build an array to project on these depths. For the test, |
---|
28 | ; we build a 3d array whose each vector following z is the depth. |
---|
29 | ; IDL> arraytest=replicate(1,jpi*jpj)#gdept |
---|
30 | ; IDL> arraytest=reform(arraytest,jpi,jpj,jpk, /over) |
---|
31 | ; We test the projection of the depth array on the depth... |
---|
32 | ; IDL> plt, 1e6*(a-projectondepth(arraytest,a)),/nocontour |
---|
33 | ; ->null field at 1e-6 pres |
---|
34 | ; |
---|
35 | ; verification projecting the temperature of 20°C for example... |
---|
36 | ; |
---|
37 | ; @history |
---|
38 | ; Sebastien Masson (smasson\@lodyc.jussieu.fr) |
---|
39 | ; 15/6/2000 |
---|
40 | ; |
---|
41 | ; @version |
---|
42 | ; $Id$ |
---|
43 | ; |
---|
44 | ;- |
---|
45 | ; |
---|
46 | FUNCTION projectondepth, arrayin, depthin |
---|
47 | ; |
---|
48 | compile_opt idl2, strictarrsubs |
---|
49 | ; |
---|
50 | tempsun = systime(1) ; To key_performance |
---|
51 | @common |
---|
52 | ;------------------------------------------------------------ |
---|
53 | depth = litchamp(depthin) |
---|
54 | array = litchamp(arrayin) |
---|
55 | ; Small verifications |
---|
56 | tailledepth = size(depth) |
---|
57 | taillearray = size(array) |
---|
58 | if tailledepth[0] NE 2 THEN return, report('Depth array must have 2 dimensions') |
---|
59 | if taillearray[0] NE 3 THEN return, report('Array in must have 3 dimensions') |
---|
60 | ; verification of the coherence between array's size and the domain |
---|
61 | grille, mask, -1, -1, -1,nx,ny,nz,firstx,firsty,firstz,lastx,lasty,lastz |
---|
62 | case 1 of |
---|
63 | tailledepth[1] eq jpi and tailledepth[2] eq jpj:depth=depth[firstx:lastx, firsty:lasty] |
---|
64 | tailledepth[1] eq nx and tailledepth[2] eq ny: |
---|
65 | else:return, report('Probleme d''adequation entre les tailles du domaine et celle du tableau de profondeur') |
---|
66 | endcase |
---|
67 | case 1 OF |
---|
68 | taillearray[3] NE jpk:return, report('2d array must have its 3d dimension equal to jpk') |
---|
69 | taillearray[1] eq jpi and taillearray[2] eq jpj:array=array[firstx:lastx, firsty:lasty, *] |
---|
70 | taillearray[1] eq nx and taillearray[2] eq ny: |
---|
71 | else:return, report('Probleme d''adequation entre les tailles du domaine et celle du tableau de profondeur') |
---|
72 | endcase |
---|
73 | ; |
---|
74 | ; c''est parti |
---|
75 | ; |
---|
76 | flevel = depth2floatlevel(depth) |
---|
77 | ; we delete points at !values.f_nan |
---|
78 | notanumber = where(finite(flevel, /nan) EQ 1) |
---|
79 | if notanumber[0] NE -1 then flevel[notanumber] = 0 |
---|
80 | ; we sill (delete land points at valmask for example) |
---|
81 | flevel = 0 > flevel < (jpk-1) |
---|
82 | ; |
---|
83 | indexup = level2index(floor(flevel)) |
---|
84 | indexlow = nx*ny+indexup |
---|
85 | out = where(indexlow GE nx*ny*jpk-1) |
---|
86 | if out[0] NE -1 then indexlow[out] = indexlow[out]-nx*ny |
---|
87 | ; |
---|
88 | weight = flevel-floor(flevel) |
---|
89 | res = array[indexup] |
---|
90 | res = res+weight*(array[indexlow]-res) |
---|
91 | ; |
---|
92 | ; We put back points at !values.f_nan |
---|
93 | if notanumber[0] NE -1 then res[notanumber] = !values.f_nan |
---|
94 | if out[0] NE -1 then res[out] = !values.f_nan |
---|
95 | ; We mask land points at valmask |
---|
96 | if n_elements(valmask) EQ 0 then valmask = 1e20 |
---|
97 | terre = where((temporary(mask))[*, *, 0] EQ 0) |
---|
98 | if terre[0] NE -1 then res[terre] = valmask |
---|
99 | ;------------------------------------------------------------ |
---|
100 | if keyword_set(key_performance) THEN print, 'temps projectondepth', systime(1)-tempsun |
---|
101 | return, res |
---|
102 | end |
---|