source: trunk/SRC/ToBeReviewed/CALCULS/rhon.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: 4.8 KB
Line 
1;+
2;
3; Calcul de la fonction d'etat (issue de eos.F)
4;
5; @categories
6;
7; @param SN
8;
9; @param TN
10;
11; @keyword INSITU
12;
13; @keyword SIGMA_N
14;
15; @returns
16;
17; @uses
18;
19; @restrictions
20;
21; @examples
22;
23; @history
24;
25; - Creation : 1997 / G. Roullet
26;
27; - adaptation pour les tableaux z,zt,xyz,xyzt  par seb.
28;
29; @version
30; $Id$
31;
32; @todo seb
33;
34;-
35FUNCTION rhon, sn, tn, INSITU=insitu, SIGMA_N=sigma_n
36;
37  compile_opt idl2, strictarrsubs
38;
39@common
40   tempsun = systime(1)         ; pour key_performance
41      sn = -1e5 > double(sn) < 1e5
42      tn = -1e5 > double(tn) < 1e5
43
44      IF keyword_set(sigma_n) then insitu = 1
45
46   taille = size(sn)
47   case taille[0] of
48      0:BEGIN                   ;z
49         zrhop=0d
50         jkmax = 1
51      END
52      1:BEGIN                   ;z
53         zrhop=dblarr(taille[1])
54         jkmax = taille[1]
55      END
56      2:BEGIN                   ;xy (jpt=1) ou zt
57         zrhop=dblarr(taille[1],taille[2])
58         if jpt EQ 1 then jkmax = 1 ELSE jkmax = taille[1]
59      END
60      3:BEGIN                   ;xyz (jpt=1) ou xyt
61         zrhop=dblarr(taille[1],taille[2],taille[3])
62         if jpt EQ 1 then jkmax = taille[3] ELSE jkmax = 1
63      END
64      4:BEGIN                   ;xyzt
65         zrhop=dblarr(taille[1],taille[2],taille[3],taille[4] )
66         jkmax = taille[3]
67      END
68   endcase
69
70   FOR jk = 0, jkmax-1 DO BEGIN
71
72      case taille[0] of
73         0:BEGIN                ;z
74            ztt = tn
75            zs = sn
76         END
77         1:BEGIN                ;z
78            ztt = tn[jk]
79            zs = sn[jk]
80         END
81         2:BEGIN                ;xy (jpt=1) ou zt
82            if jpt EQ 1 then begin
83               ztt = tn
84               zs = sn
85            ENDIF ELSE BEGIN
86               ztt = tn[jk, *]
87               zs = sn[jk, *]
88            ENDELSE
89         END
90         3:BEGIN                ;xyz (jpt=1) ou xyt
91            if jpt EQ 1 then begin
92               ztt = tn[*, *, jk]
93               zs = sn[*, *,jk]
94            endif ELSE BEGIN
95               ztt = tn
96               zs = sn
97            ENDELSE
98         END
99         4:BEGIN                ;xyzt
100            ztt = tn[*, *, jk, *]
101            zs = sn[*, *,jk, *]
102         END
103      endcase
104      if n_elements(sigma_n) NE 0 then zh = 1000.*sigma_n ELSE zh = gdept[jk]
105; ...   square root salinity
106      zsr= sqrt(abs(zs))
107; ...   compute density pure water at atm pressure
108      zr1=((((6.536332e-9*ztt-1.120083e-6)*ztt+1.001685e-4)*ztt-9.095290e-3)*ztt+6.793952e-2)*ztt+999.842594
109; ...   seawater density atm pressure
110      zr2= (((5.3875e-9*ztt-8.2467e-7)*ztt+7.6438e-5)*ztt-4.0899e-3)*ztt+0.824493
111      zr3= (-1.6546e-6*ztt+1.0227e-4)*ztt-5.72466e-3
112      zr4= 4.8314e-4
113;
114; ...   potential density (reference to the surface)
115      case taille[0] of
116         0: zrhop    = (zr4*zs + zr3*zsr + zr2)*zs + zr1
117         1: zrhop[jk]= (zr4*zs + zr3*zsr + zr2)*zs + zr1
118         2:BEGIN
119            if jpt EQ 1 then zrhop = (zr4*zs + zr3*zsr + zr2)*zs + zr1 $
120            ELSE zrhop[jk, *]= (zr4*zs + zr3*zsr + zr2)*zs + zr1
121         END
122         3:BEGIN
123            if jpt EQ 1 then zrhop[*, *,jk]= (zr4*zs + zr3*zsr + zr2)*zs + zr1 $
124             ELSE zrhop = (zr4*zs + zr3*zsr + zr2)*zs + zr1
125         END
126         4: zrhop[*, *,jk, *]= (zr4*zs + zr3*zsr + zr2)*zs + zr1
127      endcase
128
129      IF n_elements(insitu) EQ 1 THEN BEGIN
130; ...   add the compression terms
131         ze = (-3.508914e-8*ztt-1.248266e-8)*ztt-2.595994e-6
132         zbw= ( 1.296821e-6*ztt-5.782165e-9)*ztt+1.045941e-4
133         zb = zbw + ze * zs
134;
135         zd = -2.042967e-2
136         zc = (-7.267926e-5*ztt+2.598241e-3)*ztt+0.1571896
137         zaw = ((5.939910e-6*ztt+2.512549e-3)*ztt-0.1028859)*ztt -4.721788
138         za = ( zd*zsr + zc)*zs + zaw
139;
140         zb1= (-0.1909078*ztt+7.390729)*ztt-55.87545
141         za1= ((2.326469e-3*ztt+1.553190)*ztt-65.00517)*ztt+1044.077
142         zkw= (((-1.361629e-4*ztt-1.852732e-2)*ztt-30.41638)*ztt+2098.925)*ztt+190925.6
143         zk0= (zb1*zsr + za1)*zs + zkw
144;
145; ...   masked in situ density
146         case taille[0] of
147            0: zrhop = zrhop / (1.0-zh/(zk0-zh*(za-zh*zb)))
148            1: zrhop[jk] = zrhop[jk] / (1.0-zh/(zk0-zh*(za-zh*zb)))
149            2:BEGIN
150               if jpt EQ 1 then zrhop = zrhop / (1.0-zh/(zk0-zh*(za-zh*zb))) $
151               ELSE zrhop[jk, *] = zrhop[jk, *] / (1.0-zh/(zk0-zh*(za-zh*zb)))
152            END
153            3:BEGIN
154               if jpt EQ 1 then zrhop[*, *,jk] = zrhop[*, *,jk] / (1.0-zh/(zk0-zh*(za-zh*zb))) $
155               ELSE zrhop = zrhop / (1.0-zh/(zk0-zh*(za-zh*zb)))
156            END
157            4: zrhop[*, *,jk, *] = zrhop[*, *,jk, *] / (1.0-zh/(zk0-zh*(za-zh*zb)))
158         endcase
159
160      ENDIF
161   ENDFOR
162
163   terre = where(tn GE 1e6)
164   if terre[0] NE -1 then zrhop[terre] = valmask
165
166   if keyword_set(key_performance) THEN print, 'temps rhon', systime(1)-tempsun
167
168   return, zrhop
169END
Note: See TracBrowser for help on using the repository browser.