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

Last change on this file since 370 was 370, checked in by pinsard, 16 years ago

improvemnts of headers (typo, links)

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