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

Last change on this file was 495, checked in by pinsard, 10 years ago

fix thanks to coding rules; typo; dupe empty lines; trailing blanks

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 6.1 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; <pro>common</pro>
51;
52; @restrictions
53; Points for which we can not calculate the dynamic height (whose the
54; bathymetry is less deep than the reference depth) are put at the
55; value !values.f_nan
56;
57; @restrictions
58; approximation: The pressure in decibars is equal to the depth in meters
59; (the pressure increase of 1 bar every 10 m)
60;
61; @history
62; Sebastien Masson (smasson\@lodyc.jussieu.fr)
63;
64; @version
65; $Id$
66;
67;-
68FUNCTION hdyn, tabsn, tabtn, TREF=tref, SREF=sref $
69             , PROFREF=profref, LEVEL=level, GILL=gill $
70             , SURFACE_LEVEL=surface_level
71;
72  compile_opt idl2, strictarrsubs
73;
74   tempsun = systime(1)         ; for key_performance
75@common
76
77   if NOT keyword_set(surface_level) then surface_level = 0
78; useful if GILL is activated
79   if NOT keyword_set(tref) then tref = 0.
80   if NOT keyword_set(sref) then sref = 35.
81; If needed, we determinate the reference depth and the W level situated directly above.
82   if keyword_set(profref) then begin
83      rien = where(gdepw LE profref, level)
84      level = level-1
85      za = gdepw[level]
86   ENDIF ELSE BEGIN
87      if NOT keyword_set(level) then BEGIN
88         rien = where(gdepw LE 1000., level)
89         level = level-1
90      ENDIF
91      profref = gdepw[level]
92      za = profref
93   ENDELSE
94   tailles = size(tabsn)
95   taillet = size(tabtn)
96   if total(tailles[0:tailles[0]] NE taillet[0:taillet[0]]) NE 0 then $
97    return,  report('arrays sn and tn must have the same size')
98   if tailles[3] NE jpk then return, report('vertical dimension of sn and tn arrays must be equal to jpk')
99   nx = nxt
100   ny = nyt
101   case (size(tabsn))[0] OF
102      3:BEGIN
103         case 1 of
104            tailles[1] eq jpi and tailles[2] eq jpj: BEGIN
105               sn = tabsn[firstxt:lastxt, firstyt:lastyt, *]
106               tn = tabtn[firstxt:lastxt, firstyt:lastyt, *]
107            end
108            tailles[1] eq  nx and tailles[2] eq  ny:BEGIN
109               sn = tabsn
110               tn = tabtn
111            end
112            else:return, report('Probleme d''adequation entre les tailles du domaine et de la boite.')
113         ENDCASE
114         if keyword_set(gill) then $
115          rhonref = rhon(replicate(sref,nx, ny, jpk),replicate(tref,nx, ny, jpk), /insitu) $
116         ELSE rhonref = 1020.
117         vol=(rhonref-rhon(sn,tn, /insitu))/rhonref
118         e33d = replicate(1, nx*ny)#e3t
119         e33d = reform(e33d, nx, ny, jpk, /over)
120         terre = where(tmask[firstxt:lastxt, firstyt:lastyt, *] EQ 0)
121         if terre[0] NE -1 then vol[terre] = !values.f_nan
122         case level of
123            0:hdyn =100.*(profref-gdepw[0])*vol[*, *, 0]
124            1:hdyn =100.*(vol*e33d)[*, *, 0]+(profref-gdepw[1])*vol[*, *, 1]
125            ELSE:hdyn =100.*total( (vol*e33d)[*, *, surface_level: level-1], 3) $
126             +(profref-gdepw[level])*vol[*, *, level]
127         endcase
128      END
129      4:BEGIN
130         case 1 of
131            tailles[1] eq jpi and tailles[2] eq jpj AND tailles[4] EQ jpt: BEGIN
132               sn = tabsn[firstxt:lastxt, firstyt:lastyt, *, *]
133               tn = tabtn[firstxt:lastxt, firstyt:lastyt, *, *]
134            end
135            tailles[1] eq  nx and tailles[2] eq  ny AND tailles[4] EQ jpt:BEGIN
136               sn = tabsn
137               tn = tabtn
138            end
139            else:return, report('Probleme d''adequation entre les tailles du domaine et de la boite.')
140         endcase
141         if keyword_set(gill) then $
142          rhonref = rhon(replicate(sref,nx, ny, jpk, jpt),replicate(tref,nx, ny, jpk, jpt), /insitu) $
143         ELSE rhonref = 1020.
144         vol=(rhonref-rhon(sn,tn, /insitu))/rhonref
145         e33d = replicate(1, nx*ny)#e3t
146         e33d = e33d[*]#replicate(1, jpt)
147         e33d = reform(e33d, nx, ny, jpk, jpt, /over)
148         mask = tmask[firstxt:lastxt, firstyt:lastyt, *]
149         mask = mask[*]#replicate(1, jpt)
150         terre = where(mask EQ 0)
151         if terre[0] NE -1 then vol[terre] = !values.f_nan
152         case level of
153            0:hdyn =100.*(profref-gdepw[0])*vol[*, *, 0, *]
154            1:hdyn =100.*(vol*e33d)[*, *, 0, *]+(profref-gdepw[1])*vol[*, *, 1, *]
155            ELSE:hdyn =100.*total( (vol*e33d)[*, *, surface_level: level-1, *], 3) $
156             +(profref-gdepw[level])*vol[*, *, level, *]
157         endcase
158      END
159      ELSE: return,  report('not implemented')
160   ENDCASE
161   varunit = 'cm'
162   varname = 'Dynamic Height (href='+strtrim(round(profref), 1)+'m)'
163   IF keyword_set(key_performance) THEN print, 'temps hdyn', systime(1)-tempsun
164
165   return, hdyn
166end
Note: See TracBrowser for help on using the repository browser.