source: trunk/SRC/ToBeReviewed/CALCULS/hdyn.pro @ 224

Last change on this file since 224 was 224, checked in by pinsard, 17 years ago

improvements/corrections of some *.pro headers

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 6.4 KB
Line 
1;------------------------------------------------------------
2;------------------------------------------------------------
3;------------------------------------------------------------
4;+
5;
6; @file_comments
7; Calculate the height by rapport to a reference state for a depth reference.
8; See keywords for different possibilities. By default, the state reference
9; is rho=1020 and the depth reference is gdepw[ka] with ka the first W level
10; directly above 1000 m.
11;
12; @categories
13; Calculation
14;
15; @param TABSN {in}{required}
16; array representing the salinity
17;
18; @param TABTN {in}{required}
19; array representing the temperature. Has the same size than SN.
20;
21; @keyword GILL
22; We activate this key if we want to calculate the dynamic height
23; like in the GILL page 215, which means by rapport to a reference state which
24; vary in depth and which is determined by a reference temperature tref at 0°C
25; and a reference salinity sref at 35 psu.
26;
27; @keyword LEVEL
28; It is the same reference level to take. This level is defined like
29; that gdepw[level] is the reference depth
30;
31; @keyword SREF
32; Give a value to this keyword to change the reference salinity used in the
33; calculation when GILL is activated.
34;
35; @keyword TREF
36; Give a value to this keyword to change the reference temperature used in the
37; calculation when GILL is activated.
38;
39; @keyword PROFREF
40; Give a depth to this keyword which will be considered as the reference depth
41; (in this case, LEVEL has not any effect). the calculation will be effectuated
42; until this depth effecting an interpolation between the the last W level above
43; PROFREF and PROFREF.
44;
45; @keyword SURFACE_LEVEL {default=0}
46; It is the level where we wan to calculate the dynamic height.
47;
48; @returns
49; An array of the same size of sn and tn representing the dynamic height calculated
50; from a reference depth nd by rapport to a reference state.
51;
52; @uses
53; common.pro
54;
55; @restrictions
56; Points for which we can not calculate the dynamic height (whose the batymetry
57; is less deep than the reference depth) are put at the value !values.f_nan
58;
59; @restrictions
60; approximation: The pressure in decibars is equal to the depth in meters
61; (the pressure increase of 1 bar every 10 m)
62;
63; @history
64; Sebastien Masson (smasson\@lodyc.jussieu.fr)
65;
66; @version
67; $Id$
68;
69;-
70;------------------------------------------------------------
71;------------------------------------------------------------
72;------------------------------------------------------------
73FUNCTION hdyn, tabsn, tabtn, TREF = tref, SREF = sref, PROFREF = profref, LEVEL = level, GILL = gill, SURFACE_LEVEL = surface_level
74;
75  compile_opt idl2, strictarrsubs
76;
77   tempsun = systime(1)         ; for key_performance
78@common
79
80   if NOT keyword_set(surface_level) then surface_level = 0
81; useful if GILL is activated
82   if NOT keyword_set(tref) then tref = 0.
83   if NOT keyword_set(sref) then sref = 35.
84; If needed, we determinate the reference depth and the W level situated directly above.
85   if keyword_set(profref) then begin
86      rien = where(gdepw LE profref, level)
87      level = level-1
88      za = gdepw[level]
89   ENDIF ELSE BEGIN
90      if NOT keyword_set(level) then BEGIN
91         rien = where(gdepw LE 1000., level)
92         level = level-1
93      ENDIF
94      profref = gdepw[level]
95      za = profref
96   ENDELSE
97   tailles = size(tabsn)
98   taillet = size(tabtn)
99   if total(tailles[0:tailles[0]] NE taillet[0:taillet[0]]) NE 0 then $
100    return,  report('arrays sn and tn must have the same size')
101   if tailles[3] NE jpk then return, report('vertical dimension of sn and tn arrarrays must be equal to jpk')
102   nx = nxt
103   ny = nyt
104   case (size(tabsn))[0] OF
105      3:BEGIN
106         case 1 of
107            tailles[1] eq jpi and tailles[2] eq jpj: BEGIN
108               sn = tabsn[firstxt:lastxt, firstyt:lastyt, *]
109               tn = tabtn[firstxt:lastxt, firstyt:lastyt, *]
110            end
111            tailles[1] eq  nx and tailles[2] eq  ny:BEGIN
112               sn = tabsn
113               tn = tabtn
114            end
115            else:return, report('Probleme d''adequation entre les tailles du domaine et de la boite.')
116         ENDCASE
117         if keyword_set(gill) then $
118          rhonref = rhon(replicate(sref,nx, ny, jpk),replicate(tref,nx, ny, jpk), /insitu) $
119         ELSE rhonref = 1020.
120         vol=(rhonref-rhon(sn,tn, /insitu))/rhonref
121         e33d = replicate(1, nx*ny)#e3t
122         e33d = reform(e33d, nx, ny, jpk, /over)
123         terre = where(tmask[firstxt:lastxt, firstyt:lastyt, *] EQ 0)
124         if terre[0] NE -1 then vol[terre] = !values.f_nan
125         case level of
126            0:hdyn =100.*(profref-gdepw[0])*vol[*, *, 0]
127            1:hdyn =100.*(vol*e33d)[*, *, 0]+(profref-gdepw[1])*vol[*, *, 1]
128            ELSE:hdyn =100.*total( (vol*e33d)[*, *, surface_level: level-1], 3) $
129             +(profref-gdepw[level])*vol[*, *, level]
130         endcase
131      END
132      4:BEGIN
133         case 1 of
134            tailles[1] eq jpi and tailles[2] eq jpj AND tailles[4] EQ jpt: BEGIN
135               sn = tabsn[firstxt:lastxt, firstyt:lastyt, *, *]
136               tn = tabtn[firstxt:lastxt, firstyt:lastyt, *, *]
137            end
138            tailles[1] eq  nx and tailles[2] eq  ny AND tailles[4] EQ jpt:BEGIN
139               sn = tabsn
140               tn = tabtn
141            end
142            else:return, report('Probleme d''adequation entre les tailles du domaine et de la boite.')
143         endcase
144         if keyword_set(gill) then $
145          rhonref = rhon(replicate(sref,nx, ny, jpk, jpt),replicate(tref,nx, ny, jpk, jpt), /insitu) $
146         ELSE rhonref = 1020.
147         vol=(rhonref-rhon(sn,tn, /insitu))/rhonref
148         e33d = replicate(1, nx*ny)#e3t
149         e33d = e33d[*]#replicate(1, jpt)
150         e33d = reform(e33d, nx, ny, jpk, jpt, /over)
151         mask = tmask[firstxt:lastxt, firstyt:lastyt, *]
152         mask = mask[*]#replicate(1, jpt)
153         terre = where(mask EQ 0)
154         if terre[0] NE -1 then vol[terre] = !values.f_nan
155         case level of
156            0:hdyn =100.*(profref-gdepw[0])*vol[*, *, 0, *]
157            1:hdyn =100.*(vol*e33d)[*, *, 0, *]+(profref-gdepw[1])*vol[*, *, 1, *]
158            ELSE:hdyn =100.*total( (vol*e33d)[*, *, surface_level: level-1, *], 3) $
159             +(profref-gdepw[level])*vol[*, *, level, *]
160         endcase
161      END
162      ELSE: return,  report('not implemented')
163   ENDCASE
164   varunit = 'cm'
165   varname = 'Dynamic Height (href='+strtrim(round(profref), 1)+'m)'
166   IF keyword_set(key_performance) THEN print, 'temps hdyn', systime(1)-tempsun
167
168   return, hdyn
169end
Note: See TracBrowser for help on using the repository browser.