Oceanografische gereedschapset
De algoritmen en constanten zijn voorgeschreven door de UNESCO.
International Equation of State (IES 80) as described in Fofonoff, JGR, Vol 90 No. C2, pp 3332-3342, March 20, 1985
Program Density (input,output); {Maart/September 1995 Henk Goudappel} {worden UNITS CTD_NIOZ} Uses Crt,Turbo3; {hoop ik..} Label Start,Einde; Var Conductiviteit,Pressure,CRatio, Salt,Temperature,lattitude,reference : Real; Antwoord : Char; Function Salinity(CRatio,Temperature,Pressure:Real):Real; Var A : Array [27..51] of Real; y : Real; Begin A[27] := 0.0080 ; A[28] := -0.1692 ; A[29] := 25.3851 ; A[30] := 14.0941 ; A[31] := -7.0261 ; A[32] := 2.7081 ; A[33] := 2.070e-4 ; A[34] := -6.370e-8 ; A[35] := 3.989e-12 ; A[36] := 3.426e-2 ; A[37] := 4.464e-4 ; A[38] := 4.215e-1 ; A[39] := -3.107e-3 ; A[40] := 0.6766097 ; A[41] := 2.00564e-2 ; A[42] := 1.104259e-4; A[43] := -6.9698e-7 ; A[44] := 1.0031e-9 ; A[45] := 0.0005 ; A[46] := -0.0056 ; A[47] := -0.0066 ; A[48] := -0.0375 ; A[49] := 0.0636 ; A[50] := -0.0144 ; A[51] := 0.0162 ; y := CRatio/((1+(Pressure*(A[33]+ A[34]*Pressure+ A[35]*Pressure*Pressure))/ (1+A[36]*Temperature+ A[37]*Temperature*Temperature+ (A[38]+ A[39]*Temperature)*CRatio))* (A[40]+ A[41]*Temperature+ A[42]*Temperature*Temperature+ A[43]*Temperature*Temperature*Temperature+ A[44]*Temperature*Temperature*Temperature*Temperature)); Salinity := A[27]+ A[28]*SqRt(y)+ A[29]*y+ A[30]*SqRt(y)*y+ A[31]*y*y+ A[32]*SqRt(y)*y*y+ (Temperature-15)*( A[45]+ A[46]*SqRt(y)+ A[47]*y+ A[48]*SqRt(y)*y+ A[49]*y*y+ A[50]*SqRt(y)*y*y)/ (1+(A[51]*(Temperature-15))); end; {Function Salinity} Function Dens(Salt,Temperature,Pressure:Real):Real; Var A : Array[0..5] of Real; B,E : Array[0..4] of Real; C,G,I,K,M : Array[0..2] of Real; F,H : Array[0..3] of Real; D,J : Real; Begin A[0] := 0.999842594e3; A[1] := 6.793952e-2 ; A[2] := -9.095290e-3 ; A[3] := 1.001685e-4 ; A[4] := -1.120083e-6 ; A[5] := 6.536332e-9 ; B[0] := 8.24493e-1 ; B[1] := -4.0899e-3 ; B[2] := 7.6438e-5 ; B[3] := -8.2467e-7 ; B[4] := 5.3875e-9 ; C[0] := -5.72466e-3 ; C[1] := 1.0227e-4 ; C[2] := -1.6546e-6 ; D := 4.8314e-4 ; E[0] := 1.965221e4 ; E[1] := 1.484206e2 ; E[2] := -2.327105 ; E[3] := 1.360477e-2 ; E[4] := -5.155288e-5 ; F[0] := 5.4676e1 ; F[1] := -0.603459 ; F[2] := 1.09987e-2 ; F[3] := -6.1670e-5 ; G[0] := 7.944e-2 ; G[1] := 1.6483e-2 ; G[2] := -5.3009e-4 ; H[0] := 3.239908 ; H[1] := 1.43713e-3 ; H[2] := 1.16092e-4 ; H[3] := -5.77905e-7 ; I[0] := 2.2838e-3 ; I[1] := -1.0981e-5 ; I[2] := -1.6078e-6 ; J := 1.91075e-4 ; K[0] := 8.50935e-5 ; K[1] := -6.12293e-6 ; K[2] := 5.2787e-8 ; M[0] := -9.9348e-7 ; M[1] := 2.0816e-8 ; M[2] := 9.1697e-10 ; Dens := (((A[0]+ A[1]*Temperature+ A[2]*Temperature*Temperature+ A[3]*Temperature*Temperature*Temperature+ A[4]*Temperature*Temperature*Temperature*Temperature+ A[5]*Temperature*Temperature*Temperature*Temperature*Temperature)+ (B[0]+ B[1]*Temperature+ B[2]*Temperature*Temperature+ B[3]*Temperature*Temperature*Temperature+ B[4]*Temperature*Temperature*Temperature*Temperature)*Salt)+ ((C[0]+ C[1]*Temperature+ C[2]*Temperature*Temperature)* SqRt(Salt)*Salt+D*Salt*Salt))/(1-(Pressure)/ (((E[0]+ E[1]*Temperature+ E[2]*Temperature*Temperature+ E[3]*Temperature*Temperature*Temperature+ E[4]*Temperature*Temperature*Temperature*Temperature)+ (F[0]+ F[1]*Temperature+ F[2]*Temperature*Temperature+ F[3]*Temperature*Temperature*Temperature)*Salt)+ ((G[0]+ G[1]*Temperature+ G[2]*Temperature*Temperature)*SqRt(Salt)*Salt)+ ((H[0]+ H[1]*Temperature+ H[2]*Temperature*Temperature+ H[3]*Temperature*Temperature*Temperature)+ (I[0]+ I[1]*Temperature+ I[2]*Temperature*Temperature)*Salt+J*SqRt(Salt)*Salt)*Pressure+ ((K[0]+ K[1]*Temperature+ K[2]*Temperature*Temperature)+ (M[0]+ M[1]*Temperature+ M[2]*Temperature*Temperature)*Salt)*Pressure*Pressure)); end; {Function Dens} Function Soundspeed(Salt,Temperature,Pressure:Real):Real; Var A,C : array[0..32] of Real; B,D : array[0..11] of Real; sr,dd,bb,aa,cc : Real; Begin C[0] := 1402.388; C[1] := 5.03711; C[2] := -5.80852e-2; C[3] := 3.3420e-4; C[4] := -1.47800e-6; C[5] := 3.1464e-9; C[10]:= 0.153563; C[11]:= 6.8982e-4; C[12]:= -8.1788e-6; C[13]:= 1.3621e-7; C[14]:= -6.1185e-10; C[20]:= 3.1260e-5; C[21]:= -1.7107e-6; C[22]:= 2.5974e-8; C[23]:= -2.5335e-10; C[24]:= 1.0405e-12; C[30]:= -9.7729e-9; C[31]:= 3.8504e-10; C[32]:= -2.3643e-12; A[0] := 1.389; A[1] := -1.262e-2; A[2] := 7.164e-5; A[3] := 2.006e-6; A[4] := -3.21e-8; A[10]:= 9.4742e-5; A[11]:= -1.2580e-5; A[12]:= -6.4885e-8; A[13]:= 1.0507e-8; A[14]:= -2.0122e-10; A[20]:= -3.9064e-7; A[21]:= 9.1041e-9; A[22]:= -1.6002e-10; A[23]:= 7.988e-12; A[30]:= 1.100e-10; A[31]:= 6.649e-12; A[32]:= -3.389e-13; B[0] := -1.922e-2; B[1] := -4.42e-5; B[10]:= 7.3637e-5; B[11]:= 1.7945e-7; D[0] := 1.727e-3; D[10]:= -7.9836e-6; Soundspeed := ((((C[32]*Temperature+C[31])*Temperature+C[30])*Pressure+ ((((C[24]*Temperature+C[23])*Temperature+C[22])*Temperature+C[21])*Temperature+C[20]))*Pressure+ ((((C[14]*Temperature+C[13])*Temperature+C[12])*Temperature+C[11])*Temperature+C[10]))*Pressure+ (((((C[5]*Temperature+C[4])*Temperature+C[3])*Temperature+C[2])*Temperature+C[1])*Temperature+C[0])+ (((((A[32]*Temperature+A[31])*Temperature+A[30])*Pressure+ (((A[23]*Temperature+A[22])*Temperature+A[21])*Temperature+A[20]))*Pressure+ ((((A[14]*Temperature+A[13])*Temperature+A[12])*Temperature+A[11])*Temperature+A[10]))*Pressure+ ((((A[4]*Temperature+A[3])*Temperature+A[2])*Temperature+A[1])*Temperature+A[0])+ (B[0]+B[1]*Temperature+(B[10]+B[11]*Temperature)*Pressure)* (SqRt(abs(Salt)))+ (D[0]+D[10]*Pressure)*Salt)*Salt; end; Function Depth(Pressure,Lattitude:Real):Real; Var C,g : array[1..4] of Real; lc : Real; Begin Pressure := Pressure*10 ; C[1] := 9.72659 ; C[2] := -2.2512e-5; C[3] := 2.279e-10; C[4] := -1.82e-15 ; g[1] := 5.2788e-3; g[2] := 2.36e-5 ; g[3] := 1.092e-6 ; g[4] := 9.780318 ; lc := 57.29578 ; Depth := ((((C[4]*Pressure+C[3])*Pressure+C[2])*Pressure+C[1])*Pressure)/ (g[4]*(1+(g[1]+g[2]*(sqr(sin(lattitude/lc))))* (sqr(sin(lattitude/lc))))+g[3]*Pressure); end; Function Freezing_Point(Salt,Pressure:Real):Real; Var A : array[0..2] of Real; B : Real; Begin A[0] := -0.0575 ; A[1] := 1.710523e-3; A[2] := -2.154996e-4; B := -7.53e-4 ; Freezing_Point := (A[0]+A[1]*SqRt(Abs(Salt))+A[2]*Salt)*Salt+B*Pressure; end; Function Adiabatic_lapse_rate(Salt,Temperature,Pressure:real):real; Var A,B,C,D,E : array[0..3] of Real; Begin A[0] := 3.5803e-5 ; A[1] := 8.5258e-6 ; A[2] := -6.8360e-8 ; A[3] := 6.6228e-10; B[0] := 1.8932e-6 ; B[1] := -4.2393e-8 ; C[0] := 1.8741e-8 ; C[1] := -6.7795e-10; C[2] := 8.7330e-12; C[3] := -5.4481e-14; D[0] := -1.1351e-10; D[1] := 2.7759e-12; E[0] := -4.6206e-13; E[1] := 1.8676e-14; E[2] := -2.1687e-16; Adiabatic_lapse_rate := (((E[2]*Temperature+E[1])*Temperature+E[0])*Pressure+ ((D[1]*Temperature+D[0])*(Salt-35)+ ((C[3]*Temperature+C[2])*Temperature+C[1])*Temperature+C[0]))*Pressure+ (B[1]*Temperature+B[0])*(Salt-35)+ ((A[3]*Temperature+A[2])*Temperature+A[1])*Temperature+A[0]; end; Function Specific_Heat(Salt,Temperature,Pressure:Real):Real; Var A,AA,B,BB,C,CC,D,E,F,H : array[0..4] of Real; G,J,Cp,Delta2_Cp,Delta1_Cp : Real; Begin A[0] := -7.643575 ; A[1] := 0.1072763 ; A[2] := -1.38385e-3; B[0] := 0.1770383 ; B[1] := -4.07718e-3; B[2] := 5.148e-5 ; C[0] := 4217.4 ; C[1] := -3.720283 ; C[2] := 0.1412855 ; C[3] := -2.654387e-3; C[4] := 2.093236e-5; AA[0] := -4.9592e-1; AA[1] := 1.45747e-2; AA[2] := -3.13885e-4; AA[3] := 2.0357e-6; AA[4] := 1.7168e-8; BB[0] := 2.4931e-4; BB[1] := -1.08645e-5; BB[2] := 2.87533e-7; BB[3] := -4.0027e-9; BB[4] := 2.2956e-11; CC[0] := -5.422e-8 ; CC[1] := 2.6380e-9; CC[2] := -6.5637e-11; CC[3] := 6.136e-13; D[0] := 4.9247e-3 ; D[1] := -1.28315e-4; D[2] := 9.802e-7 ; D[3] := 2.5941e-8 ; D[4] := -2.9179e-10; E[0] := -1.2331e-4 ; E[1] := -1.517e-6 ; E[2] := 3.122e-8 ; F[0] := -2.9558e-6 ; F[1] := 1.17054e-7; F[2] := -2.3905e-9 ; F[3] := 1.8448e-11; G := 9.971e-8 ; H[0] := 5.540e-10 ; H[1] := -1.7682e-11; H[2] := 3.513e-13 ; J := -1.4300e-12; Specific_Heat := ((C[0]+ C[1]*Temperature+ C[2]*Temperature*Temperature+ C[3]*Temperature*Temperature*Temperature+ C[4]*Temperature*Temperature*Temperature*Temperature)+ ((A[0]+A[1]*Temperature+A[2]*Temperature*Temperature)*Salt)+ ((B[0]+B[1]*Temperature+B[2]*Temperature*Temperature)*SqRt(Salt)*Salt))+ ((AA[0]+ AA[1]*Temperature+ AA[2]*Temperature*Temperature+ AA[3]*Temperature*Temperature*Temperature+ AA[4]*Temperature*Temperature*Temperature*Temperature)*Pressure+ ((BB[0]+ BB[1]*Temperature+ BB[2]*Temperature*Temperature+ BB[3]*Temperature*Temperature*Temperature+ BB[4]*Temperature*Temperature*Temperature*Temperature)*Pressure*Pressure)+ ((CC[0]+ CC[1]*Temperature+ CC[2]*Temperature*Temperature+ CC[3]*Temperature*Temperature*Temperature)*Pressure*Pressure*Pressure))+ (((((D[0]+ D[1]*Temperature+ D[2]*Temperature*Temperature+ D[3]*Temperature*Temperature*Temperature+ D[4]*Temperature*Temperature*Temperature*Temperature)*Salt)+ ((E[0]+ E[1]*Temperature+ E[2]*Temperature*Temperature+ E[3]*Temperature*Temperature*Temperature)*(SqRt(Salt)*Salt)))*Pressure)+ ((((F[0]+ F[1]*Temperature+ F[2]*Temperature*Temperature+ F[3]*Temperature*Temperature*Temperature)*Salt)+ (G*(SqRt(Salt)*Salt)))*Pressure*Pressure)+ ((((H[0]+ H[1]*Temperature+ H[2]*Temperature*Temperature)*Salt)+ (J*Temperature*(SqRt(Salt)*Salt)))*Pressure*Pressure*Pressure)); end; {Function Potential_Temperature(Salt,Temperature,Pressure,Reference:Real):Real; Var Begin end;} Procedure Signon; Begin GoToXY(5,10); Write('Program Density calculates the Density and other properties of seawater '); GoToXY(5,12); Write(' Variabeles are: Temperature, Pressure and Lattitude '); GoToXY(5,13); Write(' and either Salinity, Conductivity or ConductivityRatio. '); GoToXY(5,11); Write(' Version 1.0 March 1995 Henk Goudappel NIOZ Texel '); end; Procedure UitvoerScherm; Begin WriteLn('Temperature : ', Temperature:10:4, ' øC'); WriteLn('Pressure : ', Pressure*10:10:4, ' DBar'); WriteLn('Density : ', Dens(Salt,Temperature,Pressure):10:4, ' kg/m^3'); WriteLn('é : ', Dens(Salt,Temperature,Pressure)-1000:10:4,' kg/m^3'); WriteLn('Specific Volume : ', (1/Dens(Salt,Temperature,Pressure)*1000):10:4, ' l/kg'); WriteLn('Specific Heat : ', Specific_heat(Salt,Temperature,Pressure):10:4, ' J/kg/øC'); WriteLn('Soundspeed : ', Soundspeed(Salt,Temperature,Pressure):10:4, ' m/s'); WriteLn('Depth : ', Depth(Pressure,lattitude):10:4, ' m'); WriteLn('Freezingpoint : ', Freezing_point(Salt,Pressure):10:4, ' øC'); WriteLn('Adiabatic lapse rate : ', Adiabatic_lapse_rate(Salt,Temperature,Pressure):10:6,' øC/dbar'); end; Procedure Invoerscherm; Begin Temperature := 40; { Write('Enter Temperature (øC) : '); ReadLn(Temperature); } { Write('Enter Pressure (Bar) : '); ReadLn(Pressure); } Pressure := 1000; { Write('Enter Lattitude : '); ReadLn(Lattitude); } Lattitude := 30; {Degrees} end; { MAIN } Begin ClrScr; Signon; Start: GoToXY(28,20); Write('to continue ');Read(Kbd,antwoord); if (IoResult <> 0) then Goto Start; ClrScr; GoToXY(18,10); WriteLn('[C]onductivity,[R]atio,[S]alinity,[Q]uit'); Read(Kbd,Antwoord); if (IoResult <> 0) then Goto Start; ClrScr; Case Antwoord of 'C','c' : Begin Write('Enter Conductivity : '); ReadLn(Conductiviteit); CRatio := Conductiviteit/42.914 ; Invoerscherm; ClrScr; Salinity(CRatio,Temperature,Pressure); Salt := Salinity(CRatio,Temperature,Pressure); WriteLn('Salinity : ', Salt:10:4,' o/oo'); UitvoerScherm; GoTo Start; end; 'R','r' : Begin Write('Enter ConductivityRatio : '); ReadLn(CRatio); Invoerscherm; ClrScr; Salt := Salinity(CRatio,Temperature,Pressure); WriteLn('Salinity : ', Salt:10:4,' o/oo'); UitvoerScherm; GoTo Start; end; 'S','s' : Begin Write('Enter Salinity (o/oo) : '); ReadLn(Salt); Invoerscherm; ClrScr; WriteLn('Salinity : ', Salt:10:4,' o/oo'); Uitvoerscherm; GoTo Start; end; 'Q','q' : Begin GoToXY(30,10); WriteLn('Quit [y/N] ?'); Read(Kbd,Antwoord); if (IoResult <> 0) then GoTo Start; Case Antwoord of 'Y','y','j','J': GoTo Einde; Else GoTo Start; end; {case} end; Else GoTo Start; end; {case} Einde: end. Function Pot_Temp((Salt,Temperature,Pressure:real):real; { PRESS -> PRESSURE IN DECIBARS TEMP -> TEMPERATURE IN CELSIUS DEGREES S -> SALINITY PSS 78 RP -> REFERENCE PRESSURE IN DECIBARS (0.0 FOR THE QUANTITY THETA) POTEMP <- POTENTIAL TEMPERATURE (DEG C) REAL PRESS,TEMP,S,RP,POTEMP } VAR I,J,N : INTEGER; DP,P,Q,R1,R2,R3,R4,R5,S1,T,X :REAL; begin S1 := Salt-35.0; P := PRESSure ; T := TEMPerature ; DP := RP - P ; N := FIX(ABS(DP)/1000.) + 1 ; DP := DP/FLOAT(N) DO 10 I:=1,N DO 20 J=1,4 R1 = ((-2.1687E-16*T+1.8676E-14)*T-4.6206E-13)*P R2 = (2.7759E-12*T-1.1351E-10)*S1 R3 = ((-5.4481E-14*T+8.733E-12)*T-6.7795E-10)*T R4 = (R1+(R2+R3+1.8741E-8))*P+(-4.2393E-8*T+1.8932E-6)*S1 R5 = R4+((6.6228E-10*T-6.836E-8)*T+8.5258E-6)*T+3.5803E-5 X = DP*R5 GO TO (100,200,300,400),J 100 CONTINUE T = T+.5*X Q = X P = P + .5*DP GO TO 20 200 CONTINUE T = T + .29298322*(X-Q) Q = .58578644*X + .121320344*Q GO TO 20 300 CONTINUE T = T + 1.707106781*(X-Q) Q = 3.414213562*X - 4.121320344*Q P = P + .5*DP GO TO 20 400 CONTINUE T = T + (X-2.0*Q)/6.0 20 CONTINUE 10 CONTINUE POTEMP = T RETURN END POTMP END
Er is ook een JavaScript van
var depth,p,t,c,s,d,sp,cp; var binaryLimit = 1000; var lat = 30.0; function initializeVars() { document.state.depth.value = 0.0; document.state.p.value = 0.0; document.state.t.value = 15.0; document.state.c.value = 4.29140; document.state.s.value = 35.00; document.state.d.value = 1025.97; document.state.sp.value = 1506.7; document.state.cp.value = 3989.8; document.state.tf.value = -1.922; document.state.lr.value = 0.150544; document.state.pt.value = 15.0; document.state.depthb.checked = false; document.state.pb.checked = true; document.state.tb.checked = true; document.state.cb.checked = true; document.state.sb.checked = false; document.state.db.checked = false; } function changeSelDepth() { document.state.pb.checked = !document.state.depthb.checked; } function changeSelPress() { document.state.depthb.checked = !document.state.pb.checked; } function changeSelection() { if ( !check2of4buttons() ) return; if ( document.state.tb.checked ) { changeTemperature(); } else if ( document.state.cb.checked ) { changeConductivity(); } else if ( document.state.sb.checked ) { changeSalinity(); } } function check2of4buttons() { var i = 0; if ( document.state.tb.checked == true ) ++i; if ( document.state.cb.checked == true ) ++i; if ( document.state.sb.checked == true ) ++i; if ( document.state.db.checked == true ) ++i; return ( i == 2 ); } function checkVars() { if ( typeof depth != 'number' ) depth = eval(document.state.depth.value); if ( typeof p != 'number' ) p = eval(document.state.p.value); if ( typeof t != 'number' ) t = eval(document.state.t.value); if ( typeof c != 'number' ) c = eval(document.state.c.value); if ( typeof s != 'number' ) s = eval(document.state.s.value); if ( typeof d != 'number' ) d = eval(document.state.d.value); } // // These functions are called when a parameter is changed to recompute the display // function changeDepth() { checkVars(); depth = eval(document.state.depth.value); document.state.depthb.checked = true; document.state.pb.checked = false; pressure_depth(); changeDepthPressure(); } function changePressure() { checkVars(); p = eval(document.state.p.value); document.state.p.value = p; document.state.depthb.checked = false; document.state.pb.checked = true; depth_p(); changeDepthPressure(); } function changeDepthPressure() { if ( document.state.tb.checked ) changeTemperature(); else if ( document.state.cb.checked ) changeConductivity(); else if ( document.state.sb.checked ) changeSalinity(); computeOthers(); } function changeTemperature() { checkVars(); t = eval(document.state.t.value); document.state.t.value = t; document.state.tb.checked = true; if( !check2of4buttons() ) { window.alert('Exactly two of the bottom 4 buttons must be selected.'); return; } if ( document.state.cb.checked ) { salinity_ctp(); density_stp(); } else if ( document.state.sb.checked ) { conductivity_stp(); density_stp(); } else if ( document.state.db.checked ) { salinity_dtp(); conductivity_stp(); } computeOthers(); } function changeConductivity() { checkVars(); c = eval(document.state.c.value); document.state.c.value = c; document.state.cb.checked = true; if( !check2of4buttons() ) { window.alert('Exactly two of the bottom 4 buttons must be selected.'); return; } if ( document.state.tb.checked ) { salinity_ctp(); density_stp(); } else if ( document.state.sb.checked ) { temperature_csp(); density_stp(); } else if ( document.state.db.checked ) { tempSalt_dcp(); } computeOthers(); } function changeSalinity() { checkVars(); s = eval(document.state.s.value); document.state.s.value = s; document.state.sb.checked = true; if( !check2of4buttons() ) { window.alert('Exactly two of the bottom 4 buttons must be selected.'); return; } if ( document.state.tb.checked ) { conductivity_stp(); density_stp(); } else if ( document.state.cb.checked ) { temperature_csp(); density_stp(); } else if ( document.state.db.checked ) { temperature_dsp(); conductivity_stp(); } computeOthers(); } function changeDensity() { checkVars(); d = eval(document.state.d.value); document.state.d.value = d; document.state.db.checked = true; if( !check2of4buttons() ) { window.alert('Exactly two of the bottom 4 buttons must be selected.'); return; } if ( document.state.tb.checked ) { salinity_dtp(); conductivity_stp(); } else if ( document.state.cb.checked ) { tempSalt_dcp(); } else if ( document.state.sb.checked ) { temperature_dsp(); conductivity_stp(); } computeOthers(); } // // These functions are called to compute one parameter from the others // function round(x,n) { var scl = 1; if ( typeof x != 'number' ) return x; for(i=n;i;--i) scl *= 10.0; return Math.round( scl * x ) / scl; } function depth_p() { var slat = Math.sin(30*3.14159265/180.0); var c1 = 5.92e-3 + 5.25e-3 * slat * slat; var c2 = 2.21e-6; depth = ((1-c1) - c2 * p) * p; document.state.depth.value = round(depth,3); } function pressure_depth() { var slat = Math.sin(30*3.14159265/180.0); var c1 = 5.92e-3 + 5.25e-3 * slat * slat; var c2 = 2.21e-6; p = ((1-c1)-Math.sqrt((1-c1)*(1-c1)-4*c2*depth)) / (2*c2) document.state.p.value = round(p,4); } function conductivity_stp() { c = conductivity(s,t,p); document.state.c.value = round(c,6); } function density_stp() { d = density(s,t,p); document.state.d.value = round(d,6); } function salinity_ctp() { s = salinity(c,t,p); document.state.s.value = round(s,6); } function salinity_dtp() { s = salinityd(d,t,p); document.state.s.value = round(s,6); } function temperature_dsp() { t = temperatureds(d,s,p); document.state.t.value = round(t,6); } function temperature_csp() { t = temperaturecs(c,s,p); document.state.t.value = round(t,6); } function tempSalt_dcp() { tempSaltdc(d,c,p); document.state.t.value = round(t,6); document.state.s.value = round(s,6); } function computeOthers() { sp = soundSpeed(s,t,p/10); document.state.sp.value = round(sp,1); cp = specificHeat(s,t,p/10); document.state.cp.value = round(cp,1); tf = freezingPoint(s,p); document.state.tf.value = round(tf,3); lr = 1000 * adiabaticLapseRate(s,t,p); document.state.lr.value = round(lr,6); pt = potentialTemperature(s,t,p); document.state.pt.value = round(pt,5); } // // These functions are called in the computation of parameters // // Compute temp and salinity from density, conductivity and pressure function tempSaltdc(d,c,p) { var tlo = 0.0; var thi = 100.0; var err = 1.0; var dNew; var i = 0; while( (Math.abs(err) > 0.00001) && (i < binaryLimit) ) { t = (thi+tlo) / 2.0; s = salinity(c,t,p) dNew = density(s,t,p); err = (dNew-d) / d; if (err < 0.0) thi = t; else tlo = t; ++i; } if ( i >= binaryLimit ) { t = Number.NaN; s = Number.NaN; } } // Compute temperature from conductivity, salinity and pressure function temperaturecs(c,s,p) { var tmp; var tlo = 0.0; var thi = 100.0; var err = 1.0; var sNew; var i = 0; while( (Math.abs(err) > 0.00001) && (i < binaryLimit) ) { tmp = (thi+tlo) / 2.0; sNew = salinity(c,tmp,p); err = (sNew-s) / s; if (err < 0.0) thi = tmp; else tlo = tmp; ++i; } if ( i >= binaryLimit ) return Number.NaN; else return tmp; } // Compute temperature from density, salinity and pressure function temperatureds(d,s,p) { var tmp; var tlo = 0.0; var thi = 100.0; var err = 1.0; var dNew; var i = 0; while( (Math.abs(err) > 0.00001) && (i < binaryLimit) ) { tmp = (thi+tlo) / 2.0; dNew = density(s,tmp,p); err = (dNew-d) / d; if (err < 0.0) thi = tmp; else tlo = tmp; ++i; } if ( i >= binaryLimit ) return Number.NaN; else return tmp; } // Compute salinity (psu) from density, temperature and pressure function salinityd(d,t,p) { var sal; var slo = 0.0; var shi = 100.0; var err = 1.0; var dNew; var i = 0; while( (Math.abs(err) > 0.00001) && (i < binaryLimit) ) { sal = (shi+slo) / 2.0; dNew = density(sal,t,p); err = (dNew-d) / d; if (err > 0.0) shi = sal; else slo = sal; ++i; } if ( i >= binaryLimit ) return Number.NaN; else return sal; } // Compute salinity (psu) from conductivity, temperature and pressure function salinity(c,t,p) { var R,rt,Rp,Rt,A,B,C,sal; R = c / 4.29140; rt = 0.6766097 + t * ( 0.0200564 + t * ( 1.104259e-04 + t * ( -6.9698e-07 + t * 1.0031e-09 ) ) ); A = 0.4215 - 0.003107 * t; B = 1 + t * ( 0.03426 + t * 0.0004464 ); C = p * ( 2.07e-5 + p * ( -6.37e-10 + p * 3.989e-15 ) ); Rp = 1 + C / ( B + A * R ); Rt = R / rt / Rp; sal = s_Rt(t,Rt); return sal; } function s_Rt(t,Rt) { var Rt5,t15,dels,sal; Rt5 = Math.sqrt( Rt ); t15 = t - 15; dels = t15 / ( 1 + 0.0162 * t15 ); sal = ( 14.0941 + dels * -0.0375 ) + Rt5 * ( ( -7.0261 + dels * 0.0636 ) + Rt5 * ( ( 2.7081 + dels * -0.0144 ) ) ); sal = ( 0.008 + dels * 0.0005 ) + Rt5 * ( ( -0.1692 + dels * -0.0056 ) + Rt5 * ( ( 25.3851 + dels * -0.0066 ) + Rt5 * sal ) ); return sal; } // Compute conductivity from salinity, temperature and pressure function conductivity(s,t,p) { var R,Rt,rt,A,B,C; var Rtlo = 0.0; var Rthi = 10.0; var err = 1.0; var sNew; var i = 0; if( s < 0.01 ) return 0.0; while( (Math.abs(err) > 0.00001) && (i < binaryLimit) ) { Rt = (Rthi+Rtlo) / 2.0; sNew = s_Rt(t,Rt); err = (sNew-s) / s; if (err > 0.0) Rthi = Rt; else Rtlo = Rt; ++i; } if ( i >= binaryLimit ) return Number.NaN; rt = 0.6766097 + t * ( 0.0200564 + t * ( 1.104259e-04 + t * ( -6.9698e-07 + t * 1.0031e-09 ) ) ); A = 0.4215 - 0.003107 * t; B = 1 + t * ( 0.03426 + t * 0.0004464 ); C = p * ( 2.07e-5 + p * ( -6.37e-10 + p * 3.989e-15 ) ); R = ( Math.sqrt( (A*rt*Rt-B)*(A*rt*Rt-B) + 4*rt*Rt*A*(B+C) ) + (A*rt*Rt-B) ) / (2*A); return R * 4.29140; } // Compute density at the surface from salinity and temperature function density0(s,t) { var A,B,C,D,dens0; A = 1.001685e-04 + t * ( -1.120083e-06 + t * 6.536332e-09 ); A = 999.842594 + t * ( 6.793952e-02 + t * ( -9.095290e-03 + t * A ) ); B = 7.6438e-05 + t * ( -8.2467e-07 + t * 5.3875e-09 ); B = 0.824493 + t * ( -4.0899e-03 + t * B ); C = -5.72466e-03 + t * ( 1.0227e-04 - t * 1.6546e-06 ); D = 4.8314e-04; dens0 = A + s * ( B + C * Math.sqrt(s) + D * s ); return dens0; } // Compute density from salinity, temperature and pressure function density(s,t,p) { var d0,d,K,E,F,G,H,I,J,M,N,t2,t3,t4,s1p5,pb t2 = t * t; t3 = t2 * t; t4 = t3 * t; d0 = density0(s,t); E = 19652.21 + 148.4206 * t - 2.327105 * t2 + 1.360477e-2 * t3 - 5.155288e-5 * t4; F = 54.6746 - 0.603459 * t + 1.09987e-2 * t2 - 6.1670e-5 * t3; G = 7.944e-2 + 1.6483e-2 * t - 5.3009e-4 * t2; H = 3.239908 + 1.43713e-3 * t + 1.16092e-4 * t2 - 5.77905e-7 * t3; I = 2.2838e-3 - 1.0981e-5 * t - 1.6078e-6 * t2; J = 1.91075e-4; M = 8.50935e-5 - 6.12293e-6 * t + 5.2787e-8 * t2; N = -9.9348e-7 + 2.0816e-8 * t + 9.1697e-10 * t2; s1p5 = s * Math.sqrt(s); pb = p/10; K = (E + F*s + G*s1p5) + (H + I*s + J*s1p5) * pb + (M + N*s) * pb * pb; d = d0 / (1 - pb/K); return d; } // Compute speed of sound (m/s) from salinity (psu), temperature (deg C) and pressure (bar) function soundSpeed(s,t,p) { var sr,D,b1,b0,B,a3,a2,a1,a0,A,c3,c2,c1,c0,C sr = Math.sqrt(s); D = 1.727e-3 - 7.9836e-6 * p; b1 = 7.3637e-5 + 1.7945e-7 * t; b0 = -1.922e-2 - 4.42e-5 * t; B = b0 + b1 * p; a3 = (-3.389e-13 * t + 6.649e-12) * t + 1.100e-10; a2 = ((7.988e-12 * t - 1.6002e-10) * t + 9.1041e-9) * t - 3.9064e-7; a1 = (((-2.0122e-10 * t + 1.0507e-8) * t - 6.4885e-8) * t - 1.2580e-5) * t + 9.4742e-5; a0 = (((-3.21e-8 * t + 2.006e-6) * t + 7.164e-5) * t -1.262e-2) * t + 1.389; A = ((a3 * p + a2) * p + a1) * p + a0; c3 = (-2.3643e-12 * t + 3.8504e-10) * t - 9.7729e-9; c2 = (((1.0405e-12 * t -2.5335e-10) * t + 2.5974e-8) * t - 1.7107e-6) * t + 3.1260e-5; c1 = (((-6.1185e-10 * t + 1.3621e-7) * t - 8.1788e-6) * t + 6.8982e-4) * t + 0.153563; c0 = ((((3.1464e-9 * t - 1.47800e-6) * t + 3.3420e-4) * t - 5.80852e-2) * t + 5.03711) * t + 1402.388; C = ((c3 * p + c2) * p + c1) * p + c0; return (C + (A + B * sr + D * s) * s); } // Compute specific heat (J/kg/deg C) from salinity (psu), temperature (deg C) and pressure (bar) function specificHeat(s,t,p) { var sr,a,b,c,cp0,cp1,cp2,cpsw sr = Math.sqrt(s); // specific heat cp0 for p=0 a = (-1.38385e-3 * t + 0.1072763 ) * t - 7.643575; b = (5.148e-5 * t - 4.07718e-3) * t + 0.1770383; c = (((2.093236e-5 * t - 2.654387e-3) * t + 0.1412855) * t - 3.720283) * t + 4217.4; cp0 = (b*sr+a)*s+c; // cp1 pressure and temperature terms for s=0 a = (((1.7168e-8 * t + 2.0357e-6) * t - 3.13885e-4) * t + 1.45747e-2) * t - 0.49592; b = (((2.2956e-11 * t - 4.0027e-9) * t + 2.87533e-7) * t - 1.08645e-5) * t + 2.4931e-4; c = ((6.136e-13 * t - 6.5637e-11) * t + 2.6380e-9) * t - 5.422e-8; cp1 = ((c*p+b)*p+a)*p; // cp2 pressure and temperature terms for s > 0 a = (((-2.9179e-10 * t + 2.5941e-8) * t + 9.802e-7) * t - 1.28315e-4) * t + 4.9247e-3; b = (3.122e-8 * t - 1.517e-6) * t - 1.2331e-4; a = (a+b*sr)*s; b = ((1.8448e-11 * t - 2.3905e-9) * t + 1.17054e-7) * t - 2.9558e-6; b = (b + 9.971e-8 * sr) * s; c = (3.513e-13 * t - 1.7682e-11) * t + 5.540e-10; c = (c - 1.4300e-12 * t * sr) * s; cp2 = ((c*p+b)*p+a)*p; cpsw = cp0 + cp1 + cp2; return cpsw; } // Compute freezing point of water (deg C) from salinity (psu) and pressure (dBar) function freezingPoint(s,p) { var tf; var sr = Math.sqrt(s); tf = (-0.0575 + 1.710523e-3 * sr - 2.154996e-4 * s) * s - 7.53e-4 * p; return tf; } // Compute adiabatic lapse rate (deg C/dBar) from salinity (psu), temperature (deg C) and pressure (dBar) function adiabaticLapseRate(s,t,p) { var ds,atg; ds = s - 35.0; atg = ((-2.1687e-16 * t + 1.8676e-14) * t - 4.6206e-13) * p * p; atg = atg + (2.7759e-12 * t - 1.1351e-10 ) * ds * p; atg = atg + (((-5.4481e-14 * t + 8.7330e-12) * t - 6.7795e-10) * t + 1.8741e-8) * p; atg = atg + (-4.2393e-8 * t + 1.8932e-6 ) * ds; atg = atg + ((6.6228e-10 * t - 6.8360e-8) * t + 8.5258e-6) * t + 3.5803e-5; return atg; } // Compute potential temperature (deg C) from salinity (psu), temperature (deg C) and pressure (dBar) function potentialTemperature(s,t0,p0) { var p,t,h,xk,q,theta p = p0; t = t0; h = 0 - p; xk = h * adiabaticLapseRate(s,t,p); t = t + 0.5 * xk; q = xk; p = p + 0.5 * h; xk = h * adiabaticLapseRate(s,t,p); t = t + 0.29289322 *(xk-q); q = 0.58578644 * xk + 0.121320344 * q; xk = h * adiabaticLapseRate(s,t,p); t = t + 1.707106781 *(xk-q); q = 3.414213562 * xk - 4.121320344 * q; p = p + 0.5 * h; xk = h * adiabaticLapseRate(s,t,p); theta = t + (xk-2.0*q)/6.0; return theta; }