Skip to content

Commit

Permalink
Modernize to use [] for access (#896)
Browse files Browse the repository at this point in the history
  • Loading branch information
riclarsson authored Dec 16, 2024
2 parents 2e1377f + a1243c2 commit e75a69c
Show file tree
Hide file tree
Showing 116 changed files with 2,049 additions and 1,991 deletions.
2 changes: 0 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,6 @@ endif ()
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

add_compile_definitions(MDSPAN_USE_PAREN_OPERATOR=1)

enable_testing ()

list (APPEND CMAKE_MODULE_PATH "${ARTS_SOURCE_DIR}/cmake/modules")
Expand Down
4 changes: 2 additions & 2 deletions src/core/absorption/cia.cc
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ void cia_interpolation(VectorView result,
if (T_order == 0) {
// No temperature interpolation in this case, just a frequency interpolation.
result_active =
reinterp(cia_data.data(joker, 0), interpweights(f_lag), f_lag);
reinterp(cia_data.data[joker, 0], interpweights(f_lag), f_lag);
} else {
// Temperature and frequency interpolation.
const auto Tnew = matpack::matpack_constant_data<Numeric, 1>{temperature};
Expand Down Expand Up @@ -495,7 +495,7 @@ void CIARecord::AppendDataset(const Vector& freq,
dataset.grid<1>() = temp_t;
dataset.gridname<1>() = "Temperature";

for (Index t = 0; t < temp.nelem(); t++) dataset.data(joker, t) = cia[t];
for (Index t = 0; t < temp.nelem(); t++) dataset.data[joker, t] = cia[t];
mdata.push_back(dataset);
}

Expand Down
2 changes: 1 addition & 1 deletion src/core/absorption/xsec_fit.cc
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ void XsecRecord::CalcXsec(VectorView xsec,
const Numeric pressure,
const Numeric temperature) const {
for (Index i = 0; i < xsec.nelem(); i++) {
const ConstVectorView coeffs = mfitcoeffs[dataset].data(i, joker);
const ConstVectorView coeffs = mfitcoeffs[dataset].data[i, joker];
xsec[i] = coeffs[P00] + coeffs[P10] * temperature + coeffs[P01] * pressure +
coeffs[P20] * temperature * temperature;
}
Expand Down
10 changes: 5 additions & 5 deletions src/core/atm/atm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,7 @@ Vector vec_interp(const GriddedField3 &v,

const Index n = alt.size();

if (d1 and d2 and d3) return Vector(n, v.data(0, 0, 0));
if (d1 and d2 and d3) return Vector(n, v.data[0, 0, 0]);
if (d1 and d2)
return tvec_interp<0, 0, 1>(
v.data, v.grid<0>(), v.grid<1>(), v.grid<2>(), alt, lat, lon);
Expand Down Expand Up @@ -928,7 +928,7 @@ std::array<std::pair<Index, Numeric>, 8> flat_weight_(const GriddedField3 &gf3,
for (Index j = 0; j < la.size(); j++) {
for (Index k = 0; k < lo.size(); k++, ++m) {
out[m] = {{(al.pos + i) * NN + (la.pos + j) * N + lo.pos + k},
x(i, j, k)};
x[i, j, k]};
}
}
}
Expand Down Expand Up @@ -1227,7 +1227,7 @@ AtmField Atm::atm_from_profile(const std::span<const Point> &atm,
for (auto &key : atm.front().keys()) {
for (Size i = 0; i < atm.size(); i++) {
// Add from ending
gf3.data(N - 1 - i, 0, 0) = atm[i][key];
gf3.data[N - 1 - i, 0, 0] = atm[i][key];
}

gf3.data_name = std::format("{}", key);
Expand All @@ -1238,7 +1238,7 @@ AtmField Atm::atm_from_profile(const std::span<const Point> &atm,
for (auto &key : atm.front().keys()) {
for (Size i = 0; i < atm.size(); i++) {
// Add from beginning
gf3.data(i, 0, 0) = atm[i][key];
gf3.data[i, 0, 0] = atm[i][key];
}

gf3.data_name = std::format("{}", key);
Expand Down Expand Up @@ -1385,7 +1385,7 @@ Longitude must be within -180 to 180 degrees.
for (Index j = 0; j < nlat; j++) {
for (Index k = 0; k < nlon; k++) {
try {
gf3(i, j, k) = atm_data.at(alt[i], lat[j], lon[k]);
gf3[i, j, k] = atm_data.at(alt[i], lat[j], lon[k]);
} catch (std::exception &e) {
#pragma omp critical
if (error.empty()) error = e.what();
Expand Down
64 changes: 32 additions & 32 deletions src/core/check_input.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1463,7 +1463,7 @@ void chk_atm_field(const String& x_name,
for (Index ip = 0; ip < npages; ip++) {
for (Index ir = 0; ir < nrows; ir++) {
for (Index ic = 0; ic < ncols; ic++) {
ARTS_USER_ERROR_IF(std::isnan(x(ip, ir, ic)),
ARTS_USER_ERROR_IF(std::isnan(x[ip, ir, ic]),
"The variable *",
x_name,
"* contains one or ",
Expand All @@ -1481,18 +1481,18 @@ void chk_atm_field(const String& x_name,
for (Index ir = 0; ir < nrows; ir++) {
ARTS_USER_ERROR_IF(
!is_same_within_epsilon(
x(ip, ir, ic), x(ip, ir, 0), 4 * DBL_EPSILON),
x[ip, ir, ic], x[ip, ir, 0], 4 * DBL_EPSILON),
"The variable *",
x_name,
"* covers 360 ",
"degrees in the longitude direction, but the field ",
"seems to deviate between first and last longitude ",
"point. The field must be \"cyclic\".\n",
"Difference: ",
x(ip, ir, ic) - x(ip, ir, 0),
x[ip, ir, ic] - x[ip, ir, 0],
"\n",
"Epsilon : ",
4 * DBL_EPSILON * std::max(x(ip, ir, ic), x(ip, ir, 0)))
4 * DBL_EPSILON * std::max(x[ip, ir, ic], x[ip, ir, 0]))
}
}
}
Expand All @@ -1505,7 +1505,7 @@ void chk_atm_field(const String& x_name,
for (Index ic = 1; ic < ncols; ic++) {
ARTS_USER_ERROR_IF(
!is_same_within_epsilon(
x(ip, 0, ic), x(ip, 0, ic - 1), 2 * DBL_EPSILON),
x[ip, 0, ic], x[ip, 0, ic - 1], 2 * DBL_EPSILON),
"The variable *",
x_name,
"* covers the South\n",
Expand All @@ -1527,7 +1527,7 @@ void chk_atm_field(const String& x_name,
for (Index ic = 1; ic < ncols; ic++) {
ARTS_USER_ERROR_IF(
!is_same_within_epsilon(
x(ip, ir, ic), x(ip, ir, ic - 1), 2 * DBL_EPSILON),
x[ip, ir, ic], x[ip, ir, ic - 1], 2 * DBL_EPSILON),
"The variable *",
x_name,
"* covers the North\n",
Expand Down Expand Up @@ -1616,7 +1616,7 @@ void chk_atm_field(const String& x_name,
for (Index ip = 0; ip < npages; ip++) {
for (Index ir = 0; ir < nrows; ir++) {
for (Index ic = 0; ic < ncols; ic++) {
ARTS_USER_ERROR_IF(std::isnan(x(ib, ip, ir, ic)),
ARTS_USER_ERROR_IF(std::isnan(x[ib, ip, ir, ic]),
"The variable *",
x_name,
"* contains one or ",
Expand All @@ -1637,7 +1637,7 @@ void chk_atm_field(const String& x_name,
for (Index ir = 0; ir < nrows; ir++) {
ARTS_USER_ERROR_IF(
!is_same_within_epsilon(
x(is, ip, ir, ic), x(is, ip, ir, 0), 2 * DBL_EPSILON),
x[is, ip, ir, ic], x[is, ip, ir, 0], 2 * DBL_EPSILON),
"The variable *",
x_name,
"* covers 360 ",
Expand All @@ -1658,7 +1658,7 @@ void chk_atm_field(const String& x_name,
for (Index ic = 1; ic < ncols; ic++) {
ARTS_USER_ERROR_IF(
!is_same_within_epsilon(
x(is, ip, 0, ic), x(is, ip, 0, ic - 1), 2 * DBL_EPSILON),
x[is, ip, 0, ic], x[is, ip, 0, ic - 1], 2 * DBL_EPSILON),
"The variable *",
x_name,
"* covers the South ",
Expand All @@ -1679,7 +1679,7 @@ void chk_atm_field(const String& x_name,
for (Index ic = 1; ic < ncols; ic++) {
ARTS_USER_ERROR_IF(
!is_same_within_epsilon(
x(is, ip, ir, ic), x(is, ip, ir, ic - 1), 2 * DBL_EPSILON),
x[is, ip, ir, ic], x[is, ip, ir, ic - 1], 2 * DBL_EPSILON),
"The variable *",
x_name,
"* covers the North ",
Expand Down Expand Up @@ -1785,9 +1785,9 @@ void chk_atm_vecfield_lat90(const String& x1_name,
Numeric vec1, vec2;
for (Index ip = 0; ip < npages; ip++) {
for (Index ic = 1; ic < ncols; ic++) {
vec1 = x1(ip, 0, ic) * x1(ip, 0, ic) + x2(ip, 0, ic) * x2(ip, 0, ic);
vec2 = x1(ip, 0, ic - 1) * x1(ip, 0, ic - 1) +
x2(ip, 0, ic - 1) * x2(ip, 0, ic - 1);
vec1 = x1[ip, 0, ic] * x1[ip, 0, ic] + x2[ip, 0, ic] * x2[ip, 0, ic];
vec2 = x1[ip, 0, ic - 1] * x1[ip, 0, ic - 1] +
x2[ip, 0, ic - 1] * x2[ip, 0, ic - 1];
ARTS_USER_ERROR_IF(
fabs(vec1 / vec2 - 1.) > th,
"The variables *",
Expand Down Expand Up @@ -1821,9 +1821,9 @@ void chk_atm_vecfield_lat90(const String& x1_name,
for (Index ip = 0; ip < npages; ip++) {
for (Index ic = 1; ic < ncols; ic++) {
vec1 =
x1(ip, ir, ic) * x1(ip, ir, ic) + x2(ip, ir, ic) * x2(ip, ir, ic);
vec2 = x1(ip, ir, ic - 1) * x1(ip, ir, ic - 1) +
x2(ip, ir, ic - 1) * x2(ip, ir, ic - 1);
x1[ip, ir, ic] * x1[ip, ir, ic] + x2[ip, ir, ic] * x2[ip, ir, ic];
vec2 = x1[ip, ir, ic - 1] * x1[ip, ir, ic - 1] +
x2[ip, ir, ic - 1] * x2[ip, ir, ic - 1];
ARTS_USER_ERROR_IF(
fabs(vec1 / vec2 - 1.) > th,
"The variables *",
Expand Down Expand Up @@ -1898,7 +1898,7 @@ void chk_atm_surface(const String& x_name,
const Index ic = ncols - 1;
for (Index ir = 0; ir < nrows; ir++) {
ARTS_USER_ERROR_IF(
!is_same_within_epsilon(x(ir, ic), x(ir, 0), 2 * DBL_EPSILON),
!is_same_within_epsilon(x[ir, ic], x[ir, 0], 2 * DBL_EPSILON),
"The variable *",
x_name,
"* covers 360 ",
Expand All @@ -1912,7 +1912,7 @@ void chk_atm_surface(const String& x_name,
if (lat_grid[0] == -90) {
for (Index ic = 1; ic < ncols; ic++) {
ARTS_USER_ERROR_IF(
!is_same_within_epsilon(x(0, ic), x(0, ic - 1), 2 * DBL_EPSILON),
!is_same_within_epsilon(x[0, ic], x[0, ic - 1], 2 * DBL_EPSILON),
"The variable *",
x_name,
"* covers the South ",
Expand All @@ -1926,7 +1926,7 @@ void chk_atm_surface(const String& x_name,
const Index ir = nrows - 1;
for (Index ic = 1; ic < ncols; ic++) {
ARTS_USER_ERROR_IF(
!is_same_within_epsilon(x(ir, ic), x(ir, ic - 1), 2 * DBL_EPSILON),
!is_same_within_epsilon(x[ir, ic], x[ir, ic - 1], 2 * DBL_EPSILON),
"The variable *",
x_name,
"* covers the North ",
Expand Down Expand Up @@ -1983,7 +1983,7 @@ void chk_sensor_pos(const String& name, ConstMatrixView sensor_pos) {
ARTS_USER_ERROR_IF(
sensor_pos.nrows() == 0, "*", name, "*must have at least one row.");
for (Index i = 0; i < sensor_pos.nrows(); i++) {
ARTS_USER_ERROR_IF(sensor_pos(i, 1) < -90 || sensor_pos(i, 1) > 90,
ARTS_USER_ERROR_IF((sensor_pos[i, 1] < -90 || sensor_pos[i, 1] > 90),
"Unvalid latitude in *",
name,
"*.\n",
Expand All @@ -1993,8 +1993,8 @@ void chk_sensor_pos(const String& name, ConstMatrixView sensor_pos) {
"(",
i,
",1) is ",
sensor_pos(i, 1));
ARTS_USER_ERROR_IF(sensor_pos(i, 2) < -180 || sensor_pos(i, 1) >= 180,
sensor_pos[i, 1]);
ARTS_USER_ERROR_IF((sensor_pos[i, 2] < -180 || sensor_pos[i, 1] >= 180),
"Unvalid longitude in *",
name,
"*.\n",
Expand All @@ -2004,7 +2004,7 @@ void chk_sensor_pos(const String& name, ConstMatrixView sensor_pos) {
"(",
i,
",2) is ",
sensor_pos(i, 2));
sensor_pos[i, 2]);
}
}

Expand All @@ -2014,7 +2014,7 @@ void chk_sensor_los(const String& name, ConstMatrixView sensor_los) {
ARTS_USER_ERROR_IF(
sensor_los.nrows() == 0, "*", name, "* must have at least one row.");
for (Index i = 0; i < sensor_los.nrows(); i++) {
ARTS_USER_ERROR_IF(sensor_los(i, 0) < 0 || sensor_los(i, 0) > 180,
ARTS_USER_ERROR_IF((sensor_los[i, 0] < 0 || sensor_los[i, 0] > 180),
"Unvalid zenith angle in *",
name,
"*.\n",
Expand All @@ -2024,8 +2024,8 @@ void chk_sensor_los(const String& name, ConstMatrixView sensor_los) {
"(",
i,
",0) is ",
sensor_los(i, 0));
ARTS_USER_ERROR_IF(sensor_los(i, 1) < -180 || sensor_los(i, 1) > 180,
sensor_los[i, 0]);
ARTS_USER_ERROR_IF((sensor_los[i, 1] < -180 || sensor_los[i, 1] > 180),
"Unvalid azimuth angle in *",
name,
"*.\n",
Expand All @@ -2035,7 +2035,7 @@ void chk_sensor_los(const String& name, ConstMatrixView sensor_los) {
"(",
i,
",1) is ",
sensor_los(i, 1));
sensor_los[i, 1]);
}
}

Expand Down Expand Up @@ -2153,10 +2153,10 @@ void chk_met_mm_backend(const Matrix& mmb) {
ARTS_USER_ERROR_IF(mmb.ncols() != 4, "*met_mm_backend* must have 4 columns.");

for (Index ch = 0; ch < mmb.nrows(); ch++) {
Numeric lo = mmb(ch, 0);
Numeric offset1 = mmb(ch, 1);
Numeric offset2 = mmb(ch, 2);
Numeric bandwidth = mmb(ch, 3);
Numeric lo = mmb[ch, 0];
Numeric offset1 = mmb[ch, 1];
Numeric offset2 = mmb[ch, 2];
Numeric bandwidth = mmb[ch, 3];

// Negative LO
ARTS_USER_ERROR_IF(lo < 0.,
Expand All @@ -2166,7 +2166,7 @@ void chk_met_mm_backend(const Matrix& mmb) {
ch,
" in *met_mm_backend*.\n",
"Center frequency is negative: ",
mmb(ch, 0),
mmb[ch, 0],
" Hz")

// Negative offsets
Expand Down
6 changes: 3 additions & 3 deletions src/core/cloudbox.cc
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ void chk_pnd_field_raw_only_in_cloudbox(
for (p_i = 0; p_i < pnd_field_raw[n].data.npages(); p_i++) {
for (lat_i = 0; lat_i < pnd_field_raw[n].data.nrows(); lat_i++) {
for (lon_i = 0; lon_i < pnd_field_raw[n].data.ncols(); lon_i++) {
v = pnd_field_raw[n].data(p_i, lat_i, lon_i);
v = pnd_field_raw[n].data[p_i, lat_i, lon_i];
if (v != 0) {
// Verify pressure is between cloudbox limits
p = pnd_field_raw[n].grid<0>()[p_i];
Expand Down Expand Up @@ -499,8 +499,8 @@ void chk_scat_species_field(bool& empty_flag,
for (Index j = 0; j < scat_species_field.npages(); j++) {
for (Index k = 0; k < scat_species_field.nrows(); k++) {
for (Index l = 0; l < scat_species_field.ncols(); l++) {
if (scat_species_field(j, k, l) != 0.0 &&
!std::isnan(scat_species_field(j, k, l)))
if (scat_species_field[j, k, l] != 0.0 &&
!std::isnan(scat_species_field[j, k, l]))
empty_flag = true;
// if ( scat_species_field(j,k,l) != 0.0 ) empty_flag = true;
}
Expand Down
Loading

0 comments on commit e75a69c

Please sign in to comment.