write the conversion for pss-78 using c,t,p as input in javascript

The following code can be used to calculate the water density based on Practical Salinity (PSS-78), temperature (in Celsius), and pressure (in bars):

index.tsx
function calculateWaterDensity(salinity, temperature, pressure) {
  const a = [9.9984085444849347e2, 7.3471625860981584e0, -5.3211231792841769e-2, 3.6492439109814549e-4, 2.5880571023991390e-3];
  const b = [1.7759777517932358e-1, 1.6139226069247786e-5, 2.5560900292639186e-7, -1.3442900328627348e-9, -2.0661124842815305e-12];
  const c = [-6.9602540329861009e-2, 1.6957712116962292e-3, 3.4549294911595359e-5, -3.7827300179455053e-7, 2.1358263275700659e-9];
  const k = 0.0162;
  const alpha0 = a[0] + a[1] * temperature + a[2] * temperature**2 + a[3] * temperature**3 + a[4] * temperature**4;
  const alpha = alpha0 + b[0] * salinity + b[1] * salinity * temperature + b[2] * temperature * salinity**2 + b[3] * temperature**2 * salinity + b[4] * temperature**3 * salinity**2;
  const betha = c[0] + c[1] * temperature + c[2] * temperature**2 + c[3] * temperature**3 + c[4] * temperature**4;
  const deltaK = k * pressure / 10;
  const kw = 1 - deltaK / alpha;
  const k0 = kw + betha * salinity;
  const density = k0 / kw * 1000;
  return density.toFixed(2);
}
1060 chars
15 lines

You can use the function as follows:

index.tsx
const salinity = 35; // PSS-78 Practical Salinity
const temperature = 15; // Celsius
const pressure = 10; // bars
const density = calculateWaterDensity(salinity, temperature, pressure); // kg/m^3
console.log(density); // output: 1023.82
237 chars
6 lines

related categories

gistlibby LogSnag