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

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

modification of some headers (+some corrections) to prepare usage of the new idldoc

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