source: trunk/SRC/ToBeReviewed/CALCULS/projectondepth.pro @ 163

Last change on this file since 163 was 163, checked in by navarro, 18 years ago

header improvements : type of parameters and keywords, default values, spell checking + idldoc assistant (IDL online_help)

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