SmacAlgorithm { public final float[] run(float[] sza, float[] saa, float[] vza, float[] vaa, float[] taup550, float[] uh2o, float[] uo3, float[] airPressure, boolean[] process, float invalid, float[] r_toa, float[] r_surfRecycle) { float[] r_return; double us, invUs, us2, uv, invUv, usTimesuv, invUsTimesUv; double dphi, Peq, m, s, cksi, ksiD; double taup, tautot, Res_6s; double uo2, uco2, uch4, uno2, uco; double to3, th2o, to2, tco2, tch4, tno2, tco; double ttetas, ttetav; double ray_phase, ray_ref, taurz, Res_ray; double aer_phase, aer_ref, Res_aer; double atm_ref, tg; double d, del, dp, e, f, ss; double q1, q2, q3; double c1, c2, cp1, cp2; double x, y, z; double aa1, aa2, aa3; double temp; if ((r_surfRecycle == null) || (r_surfRecycle.length != r_toa.length)) { r_return = new float[r_toa.length]; } else { r_return = r_surfRecycle; } int n; for (n = 0; n < r_toa.length; n++) { if (!process[n]) { r_return[n] = invalid; continue; } us = Math.cos(sza[n] * _cdr); invUs = 1.0 / us; us2 = us * us; uv = Math.cos(vza[n] * _cdr); invUv = 1.0 / uv; usTimesuv = us * uv; invUsTimesUv = 1.0 / usTimesuv; dphi = (saa[n] - vaa[n]) * _cdr; Peq = airPressure[n] * _invMaxPressure; m = invUs + invUv; taup = _A0taup + _A1taup * taup550[n]; uo2 = 1.0; if (_calcUo2) { uo2 = Math.pow(Peq, _po2); } uco2 = 1.0; if (_calcUco2) { uco2 = Math.pow(Peq, _pco2); } uch4 = 1.0; if (_calcUch4) { uch4 = Math.pow(Peq, _pch4); } uno2 = 1.0; if (_calcUno2) { uno2 = Math.pow(Peq, _pno2); } uco = 1.0; if (_calcUco) { uco = Math.pow(Peq, _pco); } to3 = 1.0; th2o = 1.0; to2 = 1.0; tco2 = 1.0; tch4 = 1.0; tno2 = 1.0; tco = 1.0; if ((uh2o[n] > 0.) || (uo3[n] > 0.)) { if (_calcTo3) { to3 = Math.exp(_ao3 * Math.pow((uo3[n] * m), _no3)); } if (_calcTh2o) { th2o = Math.exp(_ah2o * Math.pow((uh2o[n] * m), _nh2o)); } if (_calcTo2) { to2 = Math.exp(_ao2 * Math.pow((uo2 * m), _no2)); } if (_calcTco2) { tco2 = Math.exp(_aco2 * Math.pow((uco2 * m), _nco2)); } if (_calcTch4) { tch4 = Math.exp(_ach4 * Math.pow((uch4 * m), _nch4)); } if (_calcTno2) { tno2 = Math.exp(_ano2 * Math.pow((uno2 * m), _nno2)); } if (_calcTco) { tco = Math.exp(_aco * Math.pow((uco * m), _nco)); } } temp = _a2T * Peq + _a3T; ttetas = _a0T + _a1T * taup550[n] * invUs + temp / (1.0 + us); ttetav = _a0T + _a1T * taup550[n] * invUv + temp / (1.0 + uv); s = _a0s * Peq + _a3s + _a1s * taup550[n] + _a2s * taup550[n] * taup550[n]; cksi = -(usTimesuv + (Math.sqrt(1.0 - us2) * Math.sqrt(1.0 - uv * uv) * Math.cos(dphi))); if (cksi < -1) { cksi = -1.0; } ksiD = _crd * Math.acos(cksi); ray_phase = 0.7190443 * (1.0 + (cksi * cksi)) + 0.0412742; taurz = _taur * Peq; ray_ref = (taurz * ray_phase) * _oneQuarter * invUsTimesUv; temp = taurz * ray_phase * invUsTimesUv; Res_ray = _resr1 + _resr2 * temp + _resr3 * temp * temp; temp = ksiD * ksiD; aer_phase = _a0P + _a1P * ksiD + _a2P * temp + _a3P * temp * ksiD + _a4P * temp * temp; temp = 1.0 / (4.0 * (1.0 - _ak2 * us2)); e = -3.0 * us2 * _wo * temp; f = -_onemwo * 3.0 * _gc * us2 * _wo * temp; dp = e / (3.0 * us) + us * f; d = e + f; del = Math.exp(_ak * taup) * _onepb2 - Math.exp(-_ak * taup) * _onemb2; ss = us / (1.0 - _ak2 * us2); temp = 3.0 * us; q1 = 2.0 + temp + _onemwo * temp * _gc * (1.0 + 2.0 * us); q2 = 2.0 - temp - _onemwo * temp * _gc * (1.0 - 2.0 * us); q3 = q2 * Math.exp(-taup * invUs); temp = (_ww * ss) / del; c1 = temp * (q1 * Math.exp(_ak * taup) * _onepb + q3 * _onemb); c2 = -temp * (q1 * Math.exp(-_ak * taup) * _onemb + q3 * _onepb); cp1 = c1 * _pfac; cp2 = -c2 * _pfac; temp = _wo * 3.0 * _gc * uv; z = d - temp * dp + _wo * aer_phase * _oneQuarter; x = c1 - temp * cp1; y = c2 - temp * cp2; temp = _ak * uv; aa1 = uv / (1.0 + temp); aa2 = uv / (1.0 - temp); aa3 = usTimesuv / (us + uv); aer_ref = x * aa1 * (1.0 - Math.exp(-taup / aa1)); aer_ref += y * aa2 * (1.0 - Math.exp(-taup / aa2)); aer_ref += z * aa3 * (1.0 - Math.exp(-taup / aa3)); aer_ref *= invUsTimesUv; temp = taup * m * cksi; Res_aer = (_resa1 + _resa2 * temp + _resa3 * temp * temp) + _resa4 * temp * temp * temp; tautot = taup + taurz; temp = tautot * m * cksi; Res_6s = (_rest1 + _rest2 * temp + _rest3 * temp * temp) + _rest4 * temp * temp * temp; atm_ref = ray_ref - Res_ray + aer_ref - Res_aer + Res_6s; tg = th2o * to3 * to2 * tco2 * tch4 * tco * tno2; temp = r_toa[n] - (atm_ref * tg); temp = temp / ((tg * ttetas * ttetav) + (temp * s)); r_return[n] = (float) temp; } return r_return; }  final void setSensorCoefficients(SmacSensorCoefficients coeffs); final float[] run(float[] sza, float[] saa, float[] vza, float[] vaa,
                             float[] taup550, float[] uh2o, float[] uo3,
                             float[] airPressure, boolean[] process, float invalid, float[] r_toa,
                             float[] r_surfRecycle);  }
@Test public void testRun() { int n; SmacAlgorithm smac = new SmacAlgorithm(); float[] sza = new float[_vectorSize]; float[] saa = new float[_vectorSize]; float[] vza = new float[_vectorSize]; float[] vaa = new float[_vectorSize]; float[] taup550 = new float[_vectorSize]; float[] uh2o = new float[_vectorSize]; float[] uo3 = new float[_vectorSize]; float[] pressure = new float[_vectorSize]; float[] toa = new float[_vectorSize]; float[] t_surf = new float[_vectorSize]; boolean[] process = new boolean[_vectorSize]; float invalid = 0.f; for (n = 0; n < _vectorSize; n++) { sza[n] = _defSza; saa[n] = _defSaa; vza[n] = _defVza; vaa[n] = _defVaa; taup550[n] = _defTaup550; uh2o[n] = _defUh2o; uo3[n] = _defUo3; pressure[n] = _defPressure; toa[n] = _defToa; process[n] = true; } try { SensorCoefficientFile file = new SensorCoefficientFile(); String filePath = "../../src/org/esa/s3tbx/toolviews/smac/coefficients/"; for (n = 0; n < _referenceCoeffs.length; n++) { file.readFile(filePath + _referenceCoeffs[n]); smac.setSensorCoefficients(file); t_surf = smac.run(sza, saa, vza, vaa, taup550, uh2o, uo3, pressure, process, invalid, toa, t_surf); assertEquals(_referenceCoeffs[n], _reference[n], t_surf[0], 1e-7f); } for (n = 0; n < _vectorSize; n++) { process[n] = false; } file.readFile(filePath + _referenceCoeffs[0]); smac.setSensorCoefficients(file); t_surf = smac.run(sza, saa, vza, vaa, taup550, uh2o, uo3, pressure, process, invalid, toa, t_surf); assertEquals(invalid, t_surf[0], 1e-7f); } catch (IOException ignored) { } }