diff --git a/src/SplineAkima.cc b/src/SplineAkima.cc index 42cc6e6..910b9db 100644 --- a/src/SplineAkima.cc +++ b/src/SplineAkima.cc @@ -74,20 +74,20 @@ namespace Splines { void Akima_build( - real_type const * X, - real_type const * Y, - real_type * Yp, - integer npts + real_type const X[], + real_type const Y[], + real_type Yp[], + integer npts ) { if ( npts == 2 ) { // solo 2 punti, niente da fare Yp[0] = Yp[1] = (Y[1]-Y[0])/(X[1]-X[0]); } else { Malloc_real mem("Akima_build"); - real_type * m = mem.malloc( size_t(npts+3) ); + real_type * m{ mem.malloc( size_t(npts+3) ) }; // calcolo slopes (npts-1) intervals + 4 - for ( size_t i = 1; i < size_t(npts); ++i ) + for ( size_t i{1}; i < size_t(npts); ++i ) m[i+1] = (Y[i]-Y[i-1])/(X[i]-X[i-1]); // extra slope at the boundary @@ -97,8 +97,8 @@ namespace Splines { m[size_t(npts+2)] = 2*m[size_t(npts+1)]-m[size_t(npts)]; // minimum delta slope - real_type epsi = 0; - for ( size_t i = 0; i < size_t(npts+2); ++i ) { + real_type epsi{0}; + for ( size_t i{0}; i < size_t(npts+2); ++i ) { real_type dm = std::abs(m[i+1]-m[i]); if ( dm > epsi ) epsi = dm; } @@ -106,7 +106,7 @@ namespace Splines { // 0 1 2 3 4---- n-1 n n+1 n+2 // + + + + + - for ( size_t i = 0; i < size_t(npts); ++i ) + for ( size_t i{0}; i < size_t(npts); ++i ) Yp[i] = akima_one( epsi, m[i], m[i+1], m[i+2], m[i+3] ); } } @@ -117,14 +117,14 @@ namespace Splines { void AkimaSpline::build() { - string msg = fmt::format("AkimaSpline[{}]::build():", m_name ); + string msg{ fmt::format("AkimaSpline[{}]::build():", m_name ) }; UTILS_ASSERT( m_npts > 1, "{} npts = {} not enought points\n", msg, m_npts ); Utils::check_NaN( m_X, (msg+" X ").c_str(), m_npts, __LINE__, __FILE__ ); Utils::check_NaN( m_Y, (msg+" Y ").c_str(), m_npts, __LINE__, __FILE__ ); - integer ibegin = 0; - integer iend = 0; + integer ibegin{0}; + integer iend{0}; do { // cerca intervallo monotono strettamente crescente while ( ++iend < m_npts && m_X[iend-1] < m_X[iend] ) {} @@ -149,17 +149,17 @@ namespace Splines { // gc["ydata"] // */ - string where = fmt::format("AkimaSpline[{}]::setup():", m_name ); - GenericContainer const & gc_x = gc("xdata",where.c_str()); - GenericContainer const & gc_y = gc("ydata",where.c_str()); + string where{ fmt::format("AkimaSpline[{}]::setup():", m_name ) }; + GenericContainer const & gc_x{ gc("xdata",where.c_str()) }; + GenericContainer const & gc_y{ gc("ydata",where.c_str()) }; vec_real_type x, y; { - std::string ff = fmt::format( "{}, field `xdata'", where ); + std::string ff{ fmt::format( "{}, field `xdata'", where ) }; gc_x.copyto_vec_real( x, ff.c_str() ); } { - std::string ff = fmt::format( "{}, field `ydata'", where ); + std::string ff{ fmt::format( "{}, field `ydata'", where ) }; gc_y.copyto_vec_real( y, ff.c_str() ); } this->build( x, y ); diff --git a/src/SplineAkima2D.cc b/src/SplineAkima2D.cc index a61b6df..3e882ad 100644 --- a/src/SplineAkima2D.cc +++ b/src/SplineAkima2D.cc @@ -113,10 +113,10 @@ namespace Splines { real_type volatility_factor = dz0*dz0 + dz1*dz1 + dz2*dz2 + dz3*dz3; // epsi value used to decide whether or not // the volatility factor is essentially zero. - real_type epsi = (z0*z0+z1*z1+z2*z2+z3*z3)*1.0E-12; + real_type epsi{ (z0*z0+z1*z1+z2*z2+z3*z3)*1.0E-12 }; // Accumulates the weighted primary estimates and their weights. if ( volatility_factor > epsi ) { // finite weight. - real_type WT = 1.0/ (volatility_factor*SXX); + real_type WT{ 1.0/ (volatility_factor*SXX) }; RF[1] += WT*primary_estimate; RF[0] += WT; } else { // infinite weight. @@ -146,22 +146,22 @@ namespace Splines { real_type by0[4], by1[4], CY1A[4], CY2A[4], CY3A[4], SYA[4], SYYA[4]; - real_type X0 = X[4]; - real_type Y0 = Y[4]; - real_type Z00 = Z[4][4]; + real_type X0{ X[4] }; + real_type Y0{ Y[4] }; + real_type Z00{ Z[4][4] }; // Initial setting - real_type DXF[2] = {0,0}; - real_type DXI[2] = {0,0}; - real_type DYF[2] = {0,0}; - real_type DYI[2] = {0,0}; - real_type DXYF[2] = {0,0}; - real_type DXYI[2] = {0,0}; - - for ( integer k = 0; k < 4; ++k ) { - int j1 = 4 + stencil[0][k]; - int j2 = 4 + stencil[1][k]; - int j3 = 4 + stencil[2][k]; + real_type DXF[2]{0,0}; + real_type DXI[2]{0,0}; + real_type DYF[2]{0,0}; + real_type DYI[2]{0,0}; + real_type DXYF[2]{0,0}; + real_type DXYI[2]{0,0}; + + for ( integer k{0}; k < 4; ++k ) { + integer j1{ 4 + stencil[0][k] }; + integer j2{ 4 + stencil[1][k] }; + integer j3{ 4 + stencil[2][k] }; if ( j1 >= int(jmin) && j3 <= int(jmax) ) estimate( Z00, Z[4][j1], Z[4][j2], Z[4][j3], @@ -171,19 +171,19 @@ namespace Splines { ); } - for ( integer kx = 0; kx < 4; ++kx ) { + for ( integer kx{0}; kx < 4; ++kx ) { int i1 = 4 + stencil[0][kx]; int i2 = 4 + stencil[1][kx]; int i3 = 4 + stencil[2][kx]; if ( i1 < int(imin) || i3 > int(imax) ) continue; - real_type X1 = X[i1] - X0; - real_type X2 = X[i2] - X0; - real_type X3 = X[i3] - X0; - real_type Z10 = Z[i1][4]; - real_type Z20 = Z[i2][4]; - real_type Z30 = Z[i3][4]; + real_type X1{ X[i1] - X0 }; + real_type X2{ X[i2] - X0 }; + real_type X3{ X[i3] - X0 }; + real_type Z10{ Z[i1][4] }; + real_type Z20{ Z[i2][4] }; + real_type Z30{ Z[i3][4] }; real_type CX1, CX2, CX3, SX, SXX, B00X, B10; estimate( Z00, Z10, Z20, Z30, @@ -193,22 +193,22 @@ namespace Splines { B00X, B10, DXF, DXI ); - for ( int ky = 0; ky < 4; ++ky ) { - int j1 = 4 + stencil[0][ky]; - int j2 = 4 + stencil[1][ky]; - int j3 = 4 + stencil[2][ky]; + for ( int ky{0}; ky < 4; ++ky ) { + integer j1{ 4 + stencil[0][ky] }; + integer j2{ 4 + stencil[1][ky] }; + integer j3{ 4 + stencil[2][ky] }; if ( j1 < int(jmin) || j3 > int(jmax) ) continue; - real_type Y1 = Y[j1] - Y0; - real_type Y2 = Y[j2] - Y0; - real_type Y3 = Y[j3] - Y0; - real_type CY1 = CY1A[ky]; - real_type CY2 = CY2A[ky]; - real_type CY3 = CY3A[ky]; - real_type SY = SYA[ky]; - real_type SYY = SYYA[ky]; - real_type B00Y = by0[ky]; - real_type B01 = by1[ky]; + real_type Y1 { Y[j1] - Y0 }; + real_type Y2 { Y[j2] - Y0 }; + real_type Y3 { Y[j3] - Y0 }; + real_type CY1 { CY1A[ky] }; + real_type CY2 { CY2A[ky] }; + real_type CY3 { CY3A[ky] }; + real_type SY { SYA[ky] }; + real_type SYY { SYYA[ky] }; + real_type B00Y{ by0[ky] }; + real_type B01 { by1[ky] }; real_type Z01 = Z[4][j1], Z02 = Z[4][j2], Z03 = Z[4][j3]; real_type Z11 = Z[i1][j1], Z12 = Z[i1][j2], Z13 = Z[i1][j3]; @@ -295,7 +295,7 @@ namespace Splines { void Akima2Dspline::make_spline() { - size_t nn = size_t( m_nx*m_ny ); + size_t nn{ size_t( m_nx*m_ny ) }; m_mem_bicubic.reallocate( 3*nn ); m_DX = m_mem_bicubic( nn ); m_DY = m_mem_bicubic( nn ); @@ -307,26 +307,26 @@ namespace Splines { real_type x_loc[9], y_loc[9], z_loc[9][9]; - for ( size_t i0 = 0; i0 < size_t(m_nx); ++i0 ) { + for ( size_t i0{0}; i0 < size_t(m_nx); ++i0 ) { size_t imin = 4 > i0 ? 4-i0 : 0; size_t imax = size_t(m_nx) < 5+i0 ? 3+(size_t(m_nx)-i0) : 8; - for ( size_t i = imin; i <= imax; ++i ) x_loc[i] = m_X[i+i0-4]-m_X[i0]; + for ( size_t i{imin}; i <= imax; ++i ) x_loc[i] = m_X[i+i0-4]-m_X[i0]; - for ( size_t j0 = 0; j0 < size_t(m_ny); ++j0 ) { + for ( size_t j0{0}; j0 < size_t(m_ny); ++j0 ) { size_t jmin = 4 > j0 ? 4-j0 : 0; size_t jmax = size_t(m_ny) < 5+j0 ? 3+(size_t(m_ny)-j0) : 8; - for ( size_t j = jmin; j <= jmax; ++j ) y_loc[j] = m_Y[j+j0-4]-m_Y[j0]; + for ( size_t j{jmin}; j <= jmax; ++j ) y_loc[j] = m_Y[j+j0-4]-m_Y[j0]; - for ( size_t i = imin; i <= imax; ++i ) - for ( size_t j = jmin; j <= jmax; ++j ) + for ( size_t i{imin}; i <= imax; ++i ) + for ( size_t j{jmin}; j <= jmax; ++j ) z_loc[i][j] = m_Z[size_t(ipos_C(integer(i+i0-4), integer(j+j0-4), m_ny))]; // if not enough points, extrapolate - size_t iadd = 0, jadd = 0; + size_t iadd{0}, jadd{0}; if ( imax < 3+imin ) { x_loc[imin-1] = 2*x_loc[imin] - x_loc[imax]; x_loc[imax+1] = 2*x_loc[imax] - x_loc[imin]; @@ -344,7 +344,7 @@ namespace Splines { real_type x0 = x_loc[imin]; real_type x1 = x_loc[imin+1]; real_type x2 = x_loc[imax]; - for ( size_t j = jmin; j <= jmax; ++j ) { + for ( size_t j{jmin}; j <= jmax; ++j ) { real_type z0 = z_loc[imin][j]; real_type z1 = z_loc[imin+1][j]; real_type z2 = z_loc[imax][j]; diff --git a/src/SplineBessel.cc b/src/SplineBessel.cc index 66d5ae9..b054f30 100644 --- a/src/SplineBessel.cc +++ b/src/SplineBessel.cc @@ -48,19 +48,19 @@ namespace Splines { void Bessel_build( - real_type const * X, - real_type const * Y, - real_type * Yp, - integer npts + real_type const X[], + real_type const Y[], + real_type Yp[], + integer npts ) { - size_t n = size_t(npts > 0 ? npts-1 : 0); + size_t n{ size_t(npts > 0 ? npts-1 : 0) }; Malloc_real mem("Bessel_build"); - real_type * m = mem.malloc( size_t(n+1) ); + real_type * m{ mem.malloc( size_t(n+1) ) }; // calcolo slopes - for ( size_t i = 0; i < n; ++i ) + for ( size_t i{0}; i < n; ++i ) m[i] = (Y[i+1]-Y[i])/(X[i+1]-X[i]); if ( npts == 2 ) { // caso speciale 2 soli punti @@ -69,7 +69,7 @@ namespace Splines { } else { - for ( size_t i = 1; i < n; ++i ) { + for ( size_t i{1}; i < n; ++i ) { real_type DL = X[i] - X[i-1]; real_type DR = X[i+1] - X[i]; Yp[i] = (DR*m[i-1]+DL*m[i])/((DL+DR)); @@ -86,7 +86,7 @@ namespace Splines { void BesselSpline::build() { - string msg = fmt::format("BesselSpline[{}]::build():", m_name ); + string msg{ fmt::format("BesselSpline[{}]::build():", m_name ) }; UTILS_ASSERT( m_npts > 1, "{} npts = {} not enought points\n", @@ -94,8 +94,8 @@ namespace Splines { ); Utils::check_NaN( m_X, (msg+" X").c_str(), m_npts, __LINE__, __FILE__ ); Utils::check_NaN( m_Y, (msg+" Y").c_str(), m_npts, __LINE__, __FILE__ ); - integer ibegin = 0; - integer iend = 0; + integer ibegin{0}; + integer iend{0}; do { // cerca intervallo monotono strettamente crescente while ( ++iend < m_npts && m_X[iend-1] < m_X[iend] ) {} @@ -118,17 +118,17 @@ namespace Splines { // gc["ydata"] // */ - string where = fmt::format("BesselSpline[{}]::setup( gc ):", m_name ); - GenericContainer const & gc_x = gc("xdata",where.c_str()); - GenericContainer const & gc_y = gc("ydata",where.c_str()); + string where{ fmt::format("BesselSpline[{}]::setup( gc ):", m_name ) }; + GenericContainer const & gc_x{ gc("xdata",where.c_str()) }; + GenericContainer const & gc_y{ gc("ydata",where.c_str()) }; vec_real_type x, y; { - std::string ff = fmt::format( "{}, field `xdata'", where ); + std::string ff{ fmt::format( "{}, field `xdata'", where ) }; gc_x.copyto_vec_real ( x, ff.c_str() ); } { - std::string ff = fmt::format( "{}, field `ydata'", where ); + std::string ff{ fmt::format( "{}, field `ydata'", where ) }; gc_y.copyto_vec_real ( y, ff.c_str() ); } this->build( x, y ); diff --git a/src/SplineBiCubic.cc b/src/SplineBiCubic.cc index c6b6f31..8972411 100644 --- a/src/SplineBiCubic.cc +++ b/src/SplineBiCubic.cc @@ -39,7 +39,7 @@ namespace Splines { void BiCubicSpline::make_spline() { - size_t nn = size_t(m_nx*m_ny); + size_t nn{ size_t(m_nx*m_ny) }; m_mem_bicubic.reallocate( 3*nn ); m_DX = m_mem_bicubic( nn ); m_DY = m_mem_bicubic( nn ); @@ -47,14 +47,14 @@ namespace Splines { // calcolo derivate PchipSpline sp; - for ( integer j = 0; j < m_ny; ++j ) { + for ( integer j{0}; j < m_ny; ++j ) { sp.build( m_X, 1, &m_Z[size_t(this->ipos_C(0,j))], m_ny, m_nx ); - for ( integer i = 0; i < m_nx; ++i ) + for ( integer i{0}; i < m_nx; ++i ) m_DX[size_t(this->ipos_C(i,j))] = sp.yp_node(i); } - for ( integer i = 0; i < m_nx; ++i ) { + for ( integer i{0}; i < m_nx; ++i ) { sp.build( m_Y, 1, &m_Z[size_t(this->ipos_C(i,0))], 1, m_ny ); - for ( integer j = 0; j < m_ny; ++j ) + for ( integer j{0}; j < m_ny; ++j ) m_DY[size_t(this->ipos_C(i,j))] = sp.yp_node(j); } std::fill_n( m_DXY, nn, 0 ); @@ -65,8 +65,8 @@ namespace Splines { void BiCubicSpline::write_to_stream( ostream_type & s ) const { fmt::print( "Nx = {} Ny = {}\n", m_nx, m_ny ); - for ( integer i = 1; i < m_nx; ++i ) { - for ( integer j = 1; j < m_ny; ++j ) { + for ( integer i{1}; i < m_nx; ++i ) { + for ( integer j{1}; j < m_ny; ++j ) { size_t i00 = size_t(this->ipos_C(i-1,j-1)); size_t i10 = size_t(this->ipos_C(i,j-1)); size_t i01 = size_t(this->ipos_C(i-1,j)); diff --git a/src/SplineBiQuintic.cc b/src/SplineBiQuintic.cc index 390d25a..7544a95 100644 --- a/src/SplineBiQuintic.cc +++ b/src/SplineBiQuintic.cc @@ -40,7 +40,7 @@ namespace Splines { void BiQuinticSpline::make_spline() { - size_t dim = size_t( m_nx*m_ny ); + size_t dim{ size_t( m_nx*m_ny ) }; mem.reallocate( 8*dim ); m_DX = mem( dim ); m_DY = mem( dim ); @@ -54,24 +54,24 @@ namespace Splines { // calcolo derivate QuinticSpline sp, sp1; // - for ( integer j = 0; j < m_ny; ++j ) { + for ( integer j{0}; j < m_ny; ++j ) { sp.build( m_X, 1, &m_Z[size_t(this->ipos_C(0,j))], m_ny, m_nx ); - for ( integer i = 0; i < m_nx; ++i ) { + for ( integer i{0}; i < m_nx; ++i ) { size_t ij = size_t(this->ipos_C(i,j)); m_DX[ij] = sp.yp_node(i); m_DXX[ij] = sp.ypp_node(i); } } - for ( integer i = 0; i < m_nx; ++i ) { + for ( integer i{0}; i < m_nx; ++i ) { sp.build( m_Y, 1, &m_Z[size_t(this->ipos_C(i,0))], 1, m_ny ); - for ( integer j = 0; j < m_ny; ++j ) { + for ( integer j{0}; j < m_ny; ++j ) { size_t ij = size_t(this->ipos_C(i,j)); m_DY[ij] = sp.yp_node(j); m_DYY[ij] = sp.ypp_node(j); } } // interpolate derivative - for ( integer i = 0; i < m_nx; ++i ) { + for ( integer i{0}; i < m_nx; ++i ) { sp.build( m_Y, 1, &m_DX[size_t(this->ipos_C(i,0))], 1, m_ny ); sp1.build( m_Y, 1, &m_DXX[size_t(this->ipos_C(i,0))], 1, m_ny ); for ( integer j = 0; j < m_ny; ++j ) { @@ -83,7 +83,7 @@ namespace Splines { } } // interpolate derivative again - for ( integer j = 0; j < m_ny; ++j ) { + for ( integer j{0}; j < m_ny; ++j ) { sp.build( m_X, 1, &m_DY[size_t(this->ipos_C(0,j))], m_ny, m_nx ); sp1.build( m_X, 1, &m_DYY[size_t(this->ipos_C(0,j))], m_ny, m_nx ); for ( integer i = 0; i < m_nx; ++i ) { @@ -105,8 +105,8 @@ namespace Splines { void BiQuinticSpline::write_to_stream( ostream_type & s ) const { fmt::print( s, "Nx = {} Ny = {}\n", m_nx, m_ny ); - for ( integer i = 1; i < m_nx; ++i ) { - for ( integer j = 1; j < m_ny; ++j ) { + for ( integer i{1}; i < m_nx; ++i ) { + for ( integer j{1}; j < m_ny; ++j ) { size_t i00 = size_t(this->ipos_C(i-1,j-1)); size_t i10 = size_t(this->ipos_C(i,j-1)); size_t i01 = size_t(this->ipos_C(i-1,j)); diff --git a/src/SplineBilinear.cc b/src/SplineBilinear.cc index b9a242a..a140b34 100644 --- a/src/SplineBilinear.cc +++ b/src/SplineBilinear.cc @@ -121,8 +121,8 @@ namespace Splines { void BilinearSpline::write_to_stream( ostream_type & s ) const { fmt::print( s, "Nx = {} Ny = {}\n", m_nx, m_ny ); - for ( integer i = 1; i < m_nx; ++i ) { - for ( integer j = 1; j < m_ny; ++j ) { + for ( integer i{1}; i < m_nx; ++i ) { + for ( integer j{1}; j < m_ny; ++j ) { size_t i00 = size_t(this->ipos_C(i-1,j-1)); size_t i10 = size_t(this->ipos_C(i,j-1)); size_t i01 = size_t(this->ipos_C(i-1,j)); diff --git a/src/SplineConstant.cc b/src/SplineConstant.cc index fc32e34..e123f9a 100644 --- a/src/SplineConstant.cc +++ b/src/SplineConstant.cc @@ -42,7 +42,7 @@ namespace Splines { real_type *& p_x, real_type *& p_y ) { - if ( !m_external_alloc ) m_baseValue.free(); + if ( !m_external_alloc ) m_mem_constant.free(); m_npts = 0; m_npts_reserved = n; m_external_alloc = true; @@ -57,11 +57,11 @@ namespace Splines { if ( m_external_alloc && n <= m_npts_reserved ) { // nothing to do!, already allocated } else { - m_baseValue.reallocate( size_t(2*n) ); + m_mem_constant.reallocate( size_t(2*n) ); m_npts_reserved = n; m_external_alloc = false; - m_X = m_baseValue( size_t(n) ); - m_Y = m_baseValue( size_t(n) ); + m_X = m_mem_constant( size_t(n) ); + m_Y = m_mem_constant( size_t(n) ); } init_last_interval(); m_npts = 0; @@ -89,8 +89,8 @@ namespace Splines { void ConstantSpline::build( - real_type const * x, integer incx, - real_type const * y, integer incy, + real_type const x[], integer incx, + real_type const y[], integer incy, integer n ) { reserve( n ); @@ -104,7 +104,7 @@ namespace Splines { void ConstantSpline::clear() { - if ( !m_external_alloc ) m_baseValue.free(); + if ( !m_external_alloc ) m_mem_constant.free(); m_npts = m_npts_reserved = 0; m_external_alloc = false; m_X = m_Y = nullptr; @@ -114,8 +114,8 @@ namespace Splines { void ConstantSpline::write_to_stream( ostream_type & s ) const { - size_t nseg = size_t(m_npts > 0 ? m_npts - 1 : 0); - for ( size_t i = 0; i < nseg; ++i ) + size_t nseg{ size_t(m_npts > 0 ? m_npts - 1 : 0) }; + for ( size_t i{0}; i < nseg; ++i ) fmt::print( s, "segment N. {:4} X:[{},{}] Y:{}\n", i, m_X[i], m_X[i+1], m_Y[i] @@ -130,7 +130,7 @@ namespace Splines { real_type nodes[], bool ) const { - size_t nseg = size_t(m_npts > 0 ? m_npts - 1 : 0); + size_t nseg{ size_t(m_npts > 0 ? m_npts - 1 : 0) }; std::copy_n( m_X, m_npts, nodes ); std::copy_n( m_Y, nseg, cfs ); return 1; @@ -154,17 +154,17 @@ namespace Splines { // gc["ydata"] // */ - string where = fmt::format("ConstantSpline[{}]::setup( gc ):", m_name ); - GenericContainer const & gc_x = gc("xdata",where.c_str()); - GenericContainer const & gc_y = gc("ydata",where.c_str()); + string where{ fmt::format("ConstantSpline[{}]::setup( gc ):", m_name ) }; + GenericContainer const & gc_x{ gc("xdata",where.c_str()) }; + GenericContainer const & gc_y{ gc("ydata",where.c_str()) }; vec_real_type x, y; { - std::string ff = fmt::format( "{}, field `xdata'", where ); + std::string ff{ fmt::format( "{}, field `xdata'", where ) }; gc_x.copyto_vec_real ( x, ff.c_str() ); } { - std::string ff = fmt::format( "{}, field `ydata'", where ); + std::string ff{ fmt::format( "{}, field `ydata'", where ) }; gc_y.copyto_vec_real ( y, ff.c_str() ); } this->build( x, y ); @@ -188,7 +188,7 @@ namespace Splines { i_min_pos = i_max_pos = 0; x_min_pos = x_max_pos = m_X[0]; y_min = y_max = m_Y[0]; - for ( integer i = 1; i < m_npts-1; ++i ) { + for ( integer i{1}; i < m_npts-1; ++i ) { real_type const & P1 = m_Y[i]; if ( P1 > y_max ) { y_max = P1; @@ -223,7 +223,7 @@ namespace Splines { m_npts > 0, "ConstantSpline[{}]::y_min_max() empty spline!", m_name ); // find max min along the nodes - for ( integer i = 1; i < m_npts-1; ++i ) { + for ( integer i{1}; i < m_npts-1; ++i ) { real_type const & P0 = m_Y[i-1]; real_type const & P1 = m_Y[i]; real_type const & P2 = m_Y[i+1]; diff --git a/src/SplineCubic.cc b/src/SplineCubic.cc index 212851f..34d4bf5 100644 --- a/src/SplineCubic.cc +++ b/src/SplineCubic.cc @@ -277,8 +277,8 @@ namespace Splines { CubicSpline_BC bcn ) { - size_t n = size_t(npts > 0 ? npts-1 : 0); - real_type * Z = Ypp; + size_t n{ size_t(npts > 0 ? npts-1 : 0) }; + real_type * Z{ Ypp }; size_t i; for ( i = 1; i < n; ++i ) { @@ -291,7 +291,7 @@ namespace Splines { Z[i] = 6 * ( (Y[i+1]-Y[i])/HR - (Y[i]-Y[i-1])/HL ) / HH; } - real_type UU = 0, LL = 0; + real_type UU{0}, LL{0}; switch ( bc0 ) { case CubicSpline_BC::EXTRAPOLATE: @@ -434,12 +434,12 @@ namespace Splines { void CubicSpline_build( - real_type const * X, - real_type const * Y, - real_type * Yp, - integer npts, - CubicSpline_BC bc0, - CubicSpline_BC bcn + real_type const X[], + real_type const Y[], + real_type Yp[], + integer npts, + CubicSpline_BC bc0, + CubicSpline_BC bcn ) { Malloc_real mem("CubicSpline_build"); mem.allocate( size_t(4*npts) ); @@ -456,7 +456,7 @@ namespace Splines { void CubicSpline::build() { - string msg = fmt::format("CubicSpline[{}]::build():", m_name ); + string msg{ fmt::format("CubicSpline[{}]::build():", m_name ) }; UTILS_ASSERT( m_npts > 1, "{} npts = {} not enought points\n", @@ -464,8 +464,8 @@ namespace Splines { ); Utils::check_NaN( m_X, (msg+" X").c_str(), m_npts, __LINE__, __FILE__ ); Utils::check_NaN( m_Y, (msg+" Y").c_str(), m_npts, __LINE__, __FILE__ ); - integer ibegin = 0; - integer iend = 0; + integer ibegin{0}; + integer iend{0}; do { // cerca intervallo monotono strettamente crescente while ( ++iend < m_npts && m_X[iend-1] < m_X[iend] ) {} @@ -514,21 +514,21 @@ namespace Splines { // gc["ydata"] // */ - string where = fmt::format("CubicSpline[{}]::setup( gc ):", m_name ); - GenericContainer const & gc_x = gc("xdata",where.c_str()); - GenericContainer const & gc_y = gc("ydata",where.c_str()); + string where{ fmt::format("CubicSpline[{}]::setup( gc ):", m_name ) }; + GenericContainer const & gc_x{ gc("xdata",where.c_str()) }; + GenericContainer const & gc_y{ gc("ydata",where.c_str()) }; vec_real_type x, y; { - std::string ff = fmt::format( "{}, field `xdata'", where ); + std::string ff{ fmt::format( "{}, field `xdata'", where ) }; gc_x.copyto_vec_real ( x, ff.c_str() ); } { - std::string ff = fmt::format( "{}, field `ydata'", where ); + std::string ff{ fmt::format( "{}, field `ydata'", where ) }; gc_y.copyto_vec_real ( y, ff.c_str() ); } if ( gc.exists("bc_begin") ) { - std::string const & bc = gc.get_map_string("bc_begin",where.c_str()); + std::string const & bc{ gc.get_map_string("bc_begin",where.c_str()) }; if ( bc == "extrapolate" ) m_bc0 = CubicSpline_BC::EXTRAPOLATE; else if ( bc == "natural" ) m_bc0 = CubicSpline_BC::NATURAL; else if ( bc == "parabolic" ) m_bc0 = CubicSpline_BC::PARABOLIC_RUNOUT; @@ -543,7 +543,7 @@ namespace Splines { } if ( gc.exists("bc_end") ) { - std::string const & bc = gc.get_map_string("bc_end",where.c_str()); + std::string const & bc{ gc.get_map_string("bc_end",where.c_str()) }; if ( bc == "extrapolate" ) m_bcn = CubicSpline_BC::EXTRAPOLATE; else if ( bc == "natural" ) m_bcn = CubicSpline_BC::NATURAL; else if ( bc == "parabolic" ) m_bcn = CubicSpline_BC::PARABOLIC_RUNOUT; diff --git a/src/SplineCubicBase.cc b/src/SplineCubicBase.cc index a0ef1a3..e42545a 100644 --- a/src/SplineCubicBase.cc +++ b/src/SplineCubicBase.cc @@ -38,13 +38,13 @@ namespace Splines { void CubicSplineBase::build( - real_type const * x, integer incx, - real_type const * y, integer incy, - real_type const * yp, integer incyp, + real_type const x[], integer incx, + real_type const y[], integer incy, + real_type const yp[], integer incyp, integer n ) { this->reserve( n ); - for ( size_t i = 0; i < size_t(n); ++i ) { + for ( size_t i{0}; i < size_t(n); ++i ) { m_X[i] = x[i*size_t(incx)]; m_Y[i] = y[i*size_t(incy)]; m_Yp[i] = yp[i*size_t(incyp)]; @@ -60,7 +60,7 @@ namespace Splines { vector const & y, vector const & yp ) { - integer N = integer(x.size()); + integer N{ integer(x.size()) }; if ( N > integer(y.size()) ) N = integer(y.size()); if ( N > integer(yp.size()) ) N = integer(yp.size()); this->build ( @@ -75,7 +75,7 @@ namespace Splines { void CubicSplineBase::clear() { - if ( !m_external_alloc ) m_baseValue.free(); + if ( !m_external_alloc ) m_mem_cubic.free(); m_npts = m_npts_reserved = 0; m_external_alloc = false; m_X = m_Y = m_Yp = nullptr; @@ -89,10 +89,10 @@ namespace Splines { // nothing to do!, already allocated } else { m_npts_reserved = n; - m_baseValue.reallocate( size_t(3*n) ); - m_X = m_baseValue( size_t(n) ); - m_Y = m_baseValue( size_t(n) ); - m_Yp = m_baseValue( size_t(n) ); + m_mem_cubic.reallocate( size_t(3*n) ); + m_X = m_mem_cubic( size_t(n) ); + m_Y = m_mem_cubic( size_t(n) ); + m_Yp = m_mem_cubic( size_t(n) ); m_external_alloc = false; } init_last_interval(); diff --git a/src/SplineHermite.cc b/src/SplineHermite.cc index cced2ab..abdfb3b 100644 --- a/src/SplineHermite.cc +++ b/src/SplineHermite.cc @@ -45,7 +45,7 @@ namespace Splines { void Hermite3( real_type x, real_type H, real_type base[4] ) { - real_type X = x/H; + real_type X{x/H}; base[1] = X*X*(3-2*X); base[0] = 1-base[1]; base[2] = x*(X*(X-2)+1); @@ -56,7 +56,7 @@ namespace Splines { void Hermite3_D( real_type x, real_type H, real_type base_D[4] ) { - real_type X = x/H; + real_type X{x/H}; base_D[0] = 6.0*X*(X-1.0)/H; base_D[1] = -base_D[0]; base_D[2] = ((3*X-4)*X+1); @@ -67,7 +67,7 @@ namespace Splines { void Hermite3_DD( real_type x, real_type H, real_type base_DD[4] ) { - real_type X = x/H; + real_type X{x/H}; base_DD[0] = (12*X-6)/(H*H); base_DD[1] = -base_DD[0]; base_DD[2] = (6*X-4)/H; @@ -258,8 +258,8 @@ namespace Splines { void HermiteSpline::build( - real_type const *, integer, - real_type const *, integer, + real_type const [], integer, + real_type const [], integer, integer ) { UTILS_ERROR( @@ -285,22 +285,22 @@ namespace Splines { // gc["ydata"] // */ - string where = fmt::format("HermiteSpline[{}]::setup( gc ):", m_name ); - GenericContainer const & gc_x = gc("xdata",where.c_str()); - GenericContainer const & gc_y = gc("ydata",where.c_str()); - GenericContainer const & gc_yp = gc("ypdata",where.c_str()); + string where{ fmt::format("HermiteSpline[{}]::setup( gc ):", m_name ) }; + GenericContainer const & gc_x{ gc("xdata",where.c_str()) }; + GenericContainer const & gc_y{ gc("ydata",where.c_str()) }; + GenericContainer const & gc_yp{ gc("ypdata",where.c_str()) }; vec_real_type x, y, yp; { - std::string ff = fmt::format( "{}, field `xdata'", where ); + std::string ff{ fmt::format( "{}, field `xdata'", where ) }; gc_x.copyto_vec_real( x, ff.c_str() ); } { - std::string ff = fmt::format( "{}, field `ydata'", where ); + std::string ff{ fmt::format( "{}, field `ydata'", where ) }; gc_y.copyto_vec_real( y, ff.c_str() ); } { - std::string ff = fmt::format( "{}, field `ypdata'", where ); + std::string ff{ fmt::format( "{}, field `ypdata'", where ) }; gc_yp.copyto_vec_real( yp, ff.c_str() ); } this->build( x, y, yp ); diff --git a/src/SplineLinear.cc b/src/SplineLinear.cc index eef6019..a4cbf15 100644 --- a/src/SplineLinear.cc +++ b/src/SplineLinear.cc @@ -78,7 +78,7 @@ namespace Splines { real_type *& p_x, real_type *& p_y ) { - if ( !m_external_alloc ) m_baseValue.free(); + if ( !m_external_alloc ) m_mem_linear.free(); m_npts = 0; m_npts_reserved = n; m_external_alloc = true; @@ -93,11 +93,11 @@ namespace Splines { if ( m_external_alloc && n <= m_npts_reserved ) { // nothing to do!, already allocated } else { - m_baseValue.reallocate( size_t(2*n) ); + m_mem_linear.reallocate( size_t(2*n) ); m_npts_reserved = n; m_external_alloc = false; - m_X = m_baseValue( size_t(n) ); - m_Y = m_baseValue( size_t(n) ); + m_X = m_mem_linear( size_t(n) ); + m_Y = m_mem_linear( size_t(n) ); } init_last_interval(); m_npts = 0; @@ -107,7 +107,7 @@ namespace Splines { void LinearSpline::clear() { - if ( !m_external_alloc ) m_baseValue.free(); + if ( !m_external_alloc ) m_mem_linear.free(); m_npts = m_npts_reserved = 0; m_external_alloc = false; m_X = m_Y = nullptr; @@ -117,7 +117,7 @@ namespace Splines { void LinearSpline::write_to_stream( ostream_type & s ) const { - integer nseg = m_npts > 0 ? m_npts - 1 : 0; + integer nseg{ m_npts > 0 ? m_npts - 1 : 0 }; for ( integer i{0}; i < nseg; ++i ) fmt::print( s, "segment N.{:4} X:[{},{}] Y:[{},{}] slope: {}\n", @@ -167,17 +167,17 @@ namespace Splines { // gc["ydata"] // */ - string where = fmt::format("LinearSpline[{}]::setup( gc ):", m_name ); - GenericContainer const & gc_x = gc("xdata",where.c_str()); - GenericContainer const & gc_y = gc("ydata",where.c_str()); + string where{ fmt::format("LinearSpline[{}]::setup( gc ):", m_name ) }; + GenericContainer const & gc_x{ gc("xdata",where.c_str()) }; + GenericContainer const & gc_y{ gc("ydata",where.c_str()) }; vec_real_type x, y; { - std::string ff = fmt::format( "{}, field `xdata'", where ); + std::string ff{ fmt::format( "{}, field `xdata'", where ) }; gc_x.copyto_vec_real ( x, ff.c_str() ); } { - std::string ff = fmt::format( "{}, field `ydata'", where ); + std::string ff{ fmt::format( "{}, field `ydata'", where ) }; gc_y.copyto_vec_real ( y, ff.c_str() ); } this->build( x, y ); @@ -232,7 +232,7 @@ namespace Splines { y_max.clear(); UTILS_ASSERT( m_npts > 0, "LinearSpline[{}]::y_min_max() empty spline!", m_name ); // find max min along the nodes - for ( integer i = 1; i < m_npts-1; ++i ) { + for ( integer i{1}; i < m_npts-1; ++i ) { real_type const & P0 = m_Y[i-1]; real_type const & P1 = m_Y[i]; real_type const & P2 = m_Y[i+1]; diff --git a/src/SplinePchip.cc b/src/SplinePchip.cc index 1503e60..5c5acae 100644 --- a/src/SplinePchip.cc +++ b/src/SplinePchip.cc @@ -72,7 +72,7 @@ namespace Splines { inline real_type max_abs( real_type a, real_type b ) { - real_type res = std::abs(a); + real_type res{ std::abs(a) }; if ( res < std::abs(b) ) res = std::abs(b); return res; } @@ -83,7 +83,7 @@ namespace Splines { inline real_type min_abs( real_type a, real_type b ) { - real_type res = std::abs(a); + real_type res{ std::abs(a) }; if ( res > std::abs(b) ) res = std::abs(b); return res; } @@ -101,8 +101,8 @@ namespace Splines { inline int signTest( real_type const a, real_type const b ) { - int sa = 0; - int sb = 0; + int sa{0}; + int sb{0}; if ( a > 0 ) sa = 1; else if ( a < 0 ) sa = -1; if ( b > 0 ) sb = 1; @@ -124,26 +124,26 @@ namespace Splines { //! void Pchip_build( - real_type const * X, - real_type const * Y, - real_type * Yp, - integer npts + real_type const X[], + real_type const Y[], + real_type Yp[], + integer npts ) { - size_t n = npts > 0 ? size_t( npts - 1 ) : 0; + size_t n{ npts > 0 ? size_t( npts - 1 ) : 0 }; //integer ierr = 0; // function definition is ok, go on. - real_type h1 = X[1] - X[0]; - real_type del1 = (Y[1]-Y[0])/h1; + real_type h1{ X[1] - X[0] }; + real_type del1{ (Y[1]-Y[0])/h1 }; //real_type dsave = del1; // special case n=2 -- use linear interpolation. if ( n == 1 ) { Yp[0] = Yp[1] = del1; return; } - real_type h2 = X[2] - X[1]; - real_type del2 = (Y[2]-Y[1])/h2; + real_type h2{ X[2] - X[1] }; + real_type del2{ (Y[2]-Y[1])/h2 }; // Set Yp[0] via non-centered three-point formula, adjusted to be shape-preserving. real_type hsum = h1 + h2; @@ -160,7 +160,7 @@ namespace Splines { } // loop through interior points. - for ( size_t i = 1; i < n; ++i ) { + for ( size_t i{1}; i < n; ++i ) { if ( i > 1 ) { h1 = h2; h2 = X[i+1] - X[i]; @@ -210,10 +210,10 @@ namespace Splines { static // non usata per ora void Pchip_build_new( - real_type const * X, - real_type const * Y, - real_type * Yp, - integer npts + real_type const X[], + real_type const Y[], + real_type Yp[], + integer npts ) { first_derivative_build( X, Y, Yp, npts ); @@ -221,7 +221,7 @@ namespace Splines { size_t n = npts > 0 ? size_t( npts - 1 ) : 0; // loop through interior points. - for ( size_t i = 1; i < n ; ++i ) { + for ( size_t i{1}; i < n ; ++i ) { real_type hL = X[i+0] - X[i-1]; real_type hR = X[i+1] - X[i+0]; @@ -254,7 +254,7 @@ namespace Splines { void PchipSpline::build() { - string msg = fmt::format("PchipSpline[{}]::build():", m_name ); + string msg{ fmt::format("PchipSpline[{}]::build():", m_name ) }; UTILS_ASSERT( m_npts > 1, "{} npts = {} not enought points\n", @@ -291,17 +291,17 @@ namespace Splines { // gc["ydata"] // */ - string where = fmt::format("PchipSpline[{}]::setup( gc ):", m_name ); - GenericContainer const & gc_x = gc("xdata",where.c_str()); - GenericContainer const & gc_y = gc("ydata",where.c_str()); + string where{ fmt::format("PchipSpline[{}]::setup( gc ):", m_name ) }; + GenericContainer const & gc_x{ gc("xdata",where.c_str()) }; + GenericContainer const & gc_y{ gc("ydata",where.c_str()) }; vec_real_type x, y; { - std::string ff = fmt::format( "{}, field `xdata'", where ); + std::string ff{ fmt::format( "{}, field `xdata'", where ) }; gc_x.copyto_vec_real ( x, ff.c_str() ); } { - std::string ff = fmt::format( "{}, field `ydata'", where ); + std::string ff{ fmt::format( "{}, field `ydata'", where ) }; gc_y.copyto_vec_real ( y, ff.c_str() ); } this->build( x, y ); diff --git a/src/SplineQuintic.cc b/src/SplineQuintic.cc index e2e13d1..2a21279 100644 --- a/src/SplineQuintic.cc +++ b/src/SplineQuintic.cc @@ -55,15 +55,15 @@ namespace Splines { static void QuinticSpline_Yppp_continuous( - real_type const * X, - real_type const * Y, - real_type const * Yp, - real_type * Ypp, - integer npts, - bool setbc + real_type const X[], + real_type const Y[], + real_type const Yp[], + real_type Ypp[], + integer npts, + bool setbc ) { - size_t n = size_t(npts > 0 ? npts-1 : 0); + size_t n{ size_t(npts > 0 ? npts-1 : 0) }; Malloc_real mem("QuinticSpline_Yppp_continuous"); mem.allocate( size_t(3*(n+1)) ); @@ -133,14 +133,14 @@ namespace Splines { static void QuinticSpline_Ypp_build( - real_type const * X, - real_type const * Y, - real_type const * Yp, - real_type * Ypp, - integer npts + real_type const X[], + real_type const Y[], + real_type const Yp[], + real_type Ypp[], + integer npts ) { - size_t n = size_t(npts > 0 ? npts-1 : 0); + size_t n{ size_t(npts > 0 ? npts-1 : 0) }; if ( n == 1 ) { Ypp[0] = Ypp[1] = 0; return; } @@ -207,16 +207,16 @@ namespace Splines { void Quintic_build( QuinticSpline_sub_type q_sub_type, - real_type const * X, - real_type const * Y, - real_type * Yp, - real_type * Ypp, - integer npts + real_type const X[], + real_type const Y[], + real_type Yp[], + real_type Ypp[], + integer npts ) { switch ( q_sub_type ) { case QuinticSpline_sub_type::CUBIC: { - size_t n = size_t(npts > 0 ? npts-1 : 0); + size_t n{ size_t(npts > 0 ? npts-1 : 0) }; Malloc_real mem("QuinticSpline_Yppp_continuous"); mem.allocate( size_t(3*(n+1)) ); @@ -251,7 +251,7 @@ namespace Splines { void QuinticSpline::build() { - string msg = fmt::format("QuinticSpline[{}]::build():", m_name ); + string msg{ fmt::format("QuinticSpline[{}]::build():", m_name ) }; UTILS_ASSERT( m_npts > 1, "{} npts = {} not enought points\n", @@ -259,8 +259,8 @@ namespace Splines { ); Utils::check_NaN( m_X, (msg+" X").c_str(), m_npts, __LINE__, __FILE__ ); Utils::check_NaN( m_Y, (msg+" Y").c_str(), m_npts, __LINE__, __FILE__ ); - integer ibegin = 0; - integer iend = 0; + integer ibegin{0}; + integer iend{0}; do { // cerca intervallo monotono strettamente crescente while ( ++iend < m_npts && m_X[iend-1] < m_X[iend] ) {} @@ -289,21 +289,21 @@ namespace Splines { // gc["ydata"] // */ - string where = fmt::format("QuinticSpline[{}]::setup( gc ):", m_name ); - GenericContainer const & gc_x = gc("xdata",where.c_str()); - GenericContainer const & gc_y = gc("ydata",where.c_str()); + string where{ fmt::format("QuinticSpline[{}]::setup( gc ):", m_name ) }; + GenericContainer const & gc_x{ gc("xdata",where.c_str()) }; + GenericContainer const & gc_y{ gc("ydata",where.c_str()) }; vec_real_type x, y; { - std::string ff = fmt::format( "{}, field `xdata'", where ); + std::string ff{ fmt::format( "{}, field `xdata'", where ) }; gc_x.copyto_vec_real ( x, ff.c_str() ); } { - std::string ff = fmt::format( "{}, field `ydata'", where ); + std::string ff{ fmt::format( "{}, field `ydata'", where ) }; gc_y.copyto_vec_real ( y, ff.c_str() ); } if ( gc.exists("spline_sub_type") ) { - std::string const & st = gc.get_map_string("spline_sub_type",where.c_str()); + std::string const & st{ gc.get_map_string("spline_sub_type",where.c_str()) }; if ( st == "cubic" ) m_q_sub_type = QuinticSpline_sub_type::CUBIC; else if ( st == "pchip" ) m_q_sub_type = QuinticSpline_sub_type::PCHIP; else if ( st == "akima" ) m_q_sub_type = QuinticSpline_sub_type::AKIMA; diff --git a/src/SplineQuinticBase.cc b/src/SplineQuinticBase.cc index 29eaff7..fb25c55 100644 --- a/src/SplineQuinticBase.cc +++ b/src/SplineQuinticBase.cc @@ -45,7 +45,7 @@ namespace Splines { real_type * & p_Yp, real_type * & p_Ypp ) { - if ( !m_external_alloc ) m_baseValue.free(); + if ( !m_external_alloc ) m_base_quintic.free(); m_npts = 0; m_npts_reserved = n; m_external_alloc = true; @@ -62,13 +62,13 @@ namespace Splines { if ( m_external_alloc && n <= m_npts_reserved ) { // nothing to do!, already allocated } else { - m_baseValue.reallocate( size_t(4*n) ); + m_base_quintic.reallocate( size_t(4*n) ); m_npts_reserved = n; m_external_alloc = false; - m_X = m_baseValue( size_t(n) ); - m_Y = m_baseValue( size_t(n) ); - m_Yp = m_baseValue( size_t(n) ); - m_Ypp = m_baseValue( size_t(n) ); + m_X = m_base_quintic( size_t(n) ); + m_Y = m_base_quintic( size_t(n) ); + m_Yp = m_base_quintic( size_t(n) ); + m_Ypp = m_base_quintic( size_t(n) ); } init_last_interval(); m_npts = 0; @@ -78,7 +78,7 @@ namespace Splines { void QuinticSplineBase::clear() { - if ( !m_external_alloc ) m_baseValue.free(); + if ( !m_external_alloc ) m_base_quintic.free(); m_npts = m_npts_reserved = 0; m_external_alloc = false; m_X = m_Y = m_Yp = m_Ypp = nullptr; @@ -296,8 +296,8 @@ namespace Splines { void QuinticSplineBase::write_to_stream( ostream_type & s ) const { - size_t nseg = size_t(m_npts > 0 ? m_npts - 1 : 0); - for ( size_t i = 0; i < nseg; ++i ) + size_t nseg{ size_t(m_npts > 0 ? m_npts - 1 : 0) }; + for ( size_t i{0}; i < nseg; ++i ) fmt::print( s, "segment N.{:4} X:[{},{}] Y:[{},{}] Yp:[{},{}] Ypp:[{},{}] slope: {}\n", i, @@ -328,7 +328,7 @@ namespace Splines { x_min_pos = x_max_pos = m_X[0]; y_min = y_max = m_Y[0]; PolynomialRoots::Quartic q; - for ( integer i = 1; i < m_npts; ++i ) { + for ( integer i{1}; i < m_npts; ++i ) { real_type const & X0 = m_X[i-1]; real_type const & X1 = m_X[i]; real_type const & P0 = m_Y[i-1]; @@ -365,7 +365,7 @@ namespace Splines { vector & x_max_pos, vector & y_max ) const { - real_type epsi = 1e-8; + real_type epsi{1e-8}; i_min_pos.clear(); i_max_pos.clear(); x_min_pos.clear(); @@ -388,7 +388,7 @@ namespace Splines { i_max_pos.push_back(0); } PolynomialRoots::Quartic q; - for ( integer i = 1; i < m_npts; ++i ) { + for ( integer i{1}; i < m_npts; ++i ) { real_type const & X0 = m_X[i-1]; real_type const & X1 = m_X[i]; real_type const & P0 = m_Y[i-1]; @@ -403,7 +403,7 @@ namespace Splines { q.setup( 5*A, 4*B, 3*C, 2*D, E ); real_type r[4]; integer nr = q.getRootsInOpenRange( 0, H, r ); - for ( integer j = 0; j < nr; ++j ) { + for ( integer j{0}; j < nr; ++j ) { real_type rr = r[j]; real_type yy = (((((A*rr)+B)*rr+C)*rr+D)*rr+E)*rr+F; real_type ddy = (((20*A*rr)+12*B)*rr+6*C)*rr+2*D; diff --git a/src/SplineSet.cc b/src/SplineSet.cc index 1f24c79..b09209d 100644 --- a/src/SplineSet.cc +++ b/src/SplineSet.cc @@ -77,10 +77,10 @@ namespace Splines { //! spline constructor SplineSet::SplineSet( string const & name ) : m_name(name) - , m_baseValue(name+"_values") - , m_basePointer(name+"_pointers") - , m_baseSplines(name+"_Splines") - , m_baseInt(name+"_is_monotone") + , m_mem( fmt::format( "SplineSet[{}]::m_mem", name ) ) + , m_mem_p( fmt::format( "SplineSet[{}]::m_mem_p", name ) ) + , m_mem_splines( fmt::format( "SplineSet[{}]::m_mem_splines", name ) ) + , m_mem_int( fmt::format( "SplineSet[{}]::m_mem_int", name ) ) { } @@ -88,8 +88,10 @@ namespace Splines { //! spline destructor SplineSet::~SplineSet() { - m_baseValue.free(); - m_basePointer.free(); + m_mem.free(); + m_mem_p.free(); + m_mem_splines.free(); + m_mem_int.free(); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -132,9 +134,9 @@ namespace Splines { string SplineSet::name_list() const { - string tmp = "[ "; + string tmp{"[ "}; for ( integer i{0}; i < m_nspl; ++i ) - tmp += "'" + m_splines[i]->name() + "' "; + tmp += fmt::format( "'{}' ", m_splines[i]->name() ); tmp += "]"; return tmp; } @@ -169,7 +171,7 @@ namespace Splines { SplineSet::dump_table( ostream_type & stream, integer num_points ) const { Malloc_real mem("SplineSet::dump_table"); mem.allocate( size_t(m_nspl) ); - real_type * vals = mem( size_t(m_nspl) ); + real_type * vals{mem( size_t(m_nspl) )}; stream << 's'; for ( integer i{0}; i < m_nspl; ++i ) stream << '\t' << header(i); stream << '\n'; @@ -186,7 +188,7 @@ namespace Splines { // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - integer - SplineSet::get_position( char const * hdr ) const { + SplineSet::get_position( char const hdr[] ) const { integer pos{ m_header_to_position.search(hdr) }; UTILS_ASSERT( pos >= 0 && pos < m_nspl, @@ -201,13 +203,13 @@ namespace Splines { void SplineSet::build( - integer nspl, - integer npts, - char const ** headers, - SplineType1D const * stype, - real_type const * data_X, - real_type const ** data_Y, - real_type const ** data_Yp + integer nspl, + integer npts, + char const * headers[], + SplineType1D const stype[], + real_type const data_X[], + real_type const * data_Y[], + real_type const * data_Yp[] ) { string msg{ fmt::format("SplineSet[{}]::build(...):", m_name ) }; UTILS_ASSERT( @@ -221,11 +223,8 @@ namespace Splines { m_nspl = nspl; m_npts = npts; // allocate memory - m_baseSplines.reallocate( size_t(m_nspl) ); - m_splines = reinterpret_cast(m_baseSplines( size_t(m_nspl) )); - - m_baseInt.reallocate( size_t(m_nspl) ); - m_is_monotone = m_baseInt( size_t(m_nspl) ); + m_splines = reinterpret_cast(m_mem_splines.realloc( size_t(m_nspl) )); + m_is_monotone = m_mem_int.realloc( size_t(m_nspl) ); m_header_to_position.clear(); @@ -254,22 +253,22 @@ namespace Splines { } } - m_baseValue.reallocate( size_t(mem + 2*nspl) ); - m_basePointer.reallocate( size_t(3*nspl) ); + m_mem.reallocate( size_t(mem + 2*nspl) ); + m_mem_p.reallocate( size_t(3*nspl) ); - m_Y = m_basePointer ( size_t(m_nspl) ); - m_Yp = m_basePointer ( size_t(m_nspl) ); - m_Ypp = m_basePointer ( size_t(m_nspl) ); - m_X = m_baseValue ( size_t(m_npts) ); - m_Ymin = m_baseValue ( size_t(m_nspl) ); - m_Ymax = m_baseValue ( size_t(m_nspl) ); + m_Y = m_mem_p ( size_t(m_nspl) ); + m_Yp = m_mem_p ( size_t(m_nspl) ); + m_Ypp = m_mem_p ( size_t(m_nspl) ); + m_X = m_mem ( size_t(m_npts) ); + m_Ymin = m_mem ( size_t(m_nspl) ); + m_Ymax = m_mem ( size_t(m_nspl) ); std::copy_n( data_X, npts, m_X ); for ( size_t spl{0}; spl < size_t(nspl); ++spl ) { - real_type * & pY = m_Y[spl]; - real_type * & pYp = m_Yp[spl]; - real_type * & pYpp = m_Ypp[spl]; - pY = m_baseValue(size_t(m_npts)); + real_type * & pY{ m_Y[spl] }; + real_type * & pYp{ m_Yp[spl] }; + real_type * & pYpp{ m_Ypp[spl] }; + pY = m_mem(size_t(m_npts)); std::copy_n( data_Y[spl], npts, pY ); if ( stype[spl] == SplineType1D::CONSTANT ) { m_Ymin[spl] = *std::min_element( pY, pY+npts-1 ); @@ -281,13 +280,13 @@ namespace Splines { pYpp = pYp = nullptr; switch ( stype[size_t(spl)] ) { case SplineType1D::QUINTIC: - pYpp = m_baseValue( size_t(m_npts) ); + pYpp = m_mem( size_t(m_npts) ); case SplineType1D::CUBIC: case SplineType1D::AKIMA: case SplineType1D::BESSEL: case SplineType1D::PCHIP: case SplineType1D::HERMITE: - pYp = m_baseValue( size_t(m_npts) ); + pYp = m_mem( size_t(m_npts) ); if ( stype[spl] == SplineType1D::HERMITE ) { UTILS_ASSERT( data_Yp != nullptr && data_Yp[spl] != nullptr, @@ -305,7 +304,7 @@ namespace Splines { break; } string h{ headers[spl] }; - Spline * & s = m_splines[spl]; + Spline * & s{ m_splines[spl] }; m_is_monotone[spl] = -1; switch (stype[size_t(spl)]) { @@ -391,8 +390,8 @@ namespace Splines { m_header_to_position.insert( s->name(), integer(spl) ); } - m_baseValue . must_be_empty( "SplineSet::build, baseValue" ); - m_basePointer . must_be_empty( "SplineSet::build, basePointer" ); + m_mem.must_be_empty( "SplineSet::build, baseValue" ); + m_mem_p.must_be_empty( "SplineSet::build, basePointer" ); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -656,9 +655,9 @@ namespace Splines { real_type SplineSet::eval2_D( - real_type zeta, - char const * indep, - char const * name + real_type zeta, + char const indep[], + char const name[] ) const { return this->eval2_D( zeta, this->get_position(indep), this->get_position(name) @@ -717,9 +716,9 @@ namespace Splines { real_type SplineSet::eval2_DD( - real_type zeta, - char const * indep, - char const * name + real_type zeta, + char const indep[], + char const name[] ) const { return this->eval2_DD( zeta, this->get_position(indep), this->get_position(name) @@ -781,9 +780,9 @@ namespace Splines { real_type SplineSet::eval2_DDD( - real_type zeta, - char const * indep, - char const * name + real_type zeta, + char const indep[], + char const name[] ) const { return this->eval2_DDD( zeta, this->get_position(indep), this->get_position(name) diff --git a/src/SplineVec.cc b/src/SplineVec.cc index 23d2c74..420f334 100644 --- a/src/SplineVec.cc +++ b/src/SplineVec.cc @@ -40,15 +40,8 @@ namespace Splines { //! spline constructor SplineVec::SplineVec( string const & name ) : m_name(name) - , m_baseValue(name+"_values") - , m_basePointer(name+"_pointers") - , m_dim(0) - , m_npts(0) - , m_curve_is_closed(false) - , m_curve_can_extend(true) - , m_X(nullptr) - , m_Y(nullptr) - , m_Yp(nullptr) + , m_mem( fmt::format( "SplineVec[{}]::m_mem", name ) ) + , m_mem_p( fmt::format( "SplineVec[{}]::m_mem_p", name ) ) { init_last_interval(); } @@ -57,14 +50,14 @@ namespace Splines { //! spline destructor SplineVec::~SplineVec() { - m_baseValue.free(); - m_basePointer.free(); + m_mem.free(); + m_mem_p.free(); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void - SplineVec::search( real_type x, std::pair & res) const { + SplineVec::search( real_type x, std::pair & res ) const { UTILS_ASSERT( m_npts > 0, "in SplineVec[{}]::search(...), npts == 0!", m_name ); #ifdef SPLINES_USE_THREADS bool ok{true}; @@ -137,20 +130,20 @@ namespace Splines { m_dim = dim; m_npts = npts; - m_baseValue.reallocate( size_t((2*dim+1)*npts) ); - m_basePointer.reallocate( size_t(2*dim) ); + m_mem.reallocate( size_t((2*dim+1)*npts) ); + m_mem_p.reallocate( size_t(2*dim) ); - m_Y = m_basePointer(size_t(m_dim)); - m_Yp = m_basePointer(size_t(m_dim)); - m_X = m_baseValue(size_t(m_npts)); + m_Y = m_mem_p(size_t(m_dim)); + m_Yp = m_mem_p(size_t(m_dim)); + m_X = m_mem(size_t(m_npts)); - for ( size_t spl = 0; spl < size_t(m_dim); ++spl ) { - m_Y[size_t(spl)] = m_baseValue(size_t(m_npts)); - m_Yp[size_t(spl)] = m_baseValue(size_t(m_npts)); + for ( size_t spl{0}; spl < size_t(m_dim); ++spl ) { + m_Y[spl] = m_mem(size_t(m_npts)); + m_Yp[spl] = m_mem(size_t(m_npts)); } - m_baseValue . must_be_empty( "SplineVec::build, baseValue" ); - m_basePointer . must_be_empty( "SplineVec::build, basePointer" ); + m_mem.must_be_empty( "SplineVec::build, baseValue" ); + m_mem_p.must_be_empty( "SplineVec::build, basePointer" ); } @@ -158,12 +151,12 @@ namespace Splines { void SplineVec::setup( - integer dim, - integer npts, - real_type const ** Y + integer dim, + integer npts, + real_type const * Y[] ) { allocate( dim, npts ); - for ( size_t spl = 0; spl < size_t(m_dim); ++spl ) + for ( size_t spl{0}; spl < size_t(m_dim); ++spl ) std::copy_n( Y[spl], m_npts, m_Y[spl] ); } @@ -171,14 +164,14 @@ namespace Splines { void SplineVec::setup( - integer dim, - integer npts, - real_type const * Y, - integer ldY + integer dim, + integer npts, + real_type const Y[], + integer ldY ) { allocate( dim, npts ); - for ( size_t spl = 0; spl < size_t(m_dim); ++spl ) - for ( size_t j = 0; j < size_t(m_npts); ++j ) + for ( size_t spl{0}; spl < size_t(m_dim); ++spl ) + for ( size_t j{0}; j < size_t(m_npts); ++j ) m_Y[spl][j] = Y[spl+j*size_t(ldY)]; } @@ -192,28 +185,28 @@ namespace Splines { // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void SplineVec::computeChords() { - size_t nn = size_t(m_npts-1); + size_t nn{ size_t(m_npts-1) }; switch ( m_dim ) { case 2: - for ( size_t j = 0; j < nn; ++j ) { - real_type dx = m_Y[0][j+1] - m_Y[0][j]; - real_type dy = m_Y[1][j+1] - m_Y[1][j]; + for ( size_t j{0}; j < nn; ++j ) { + real_type dx{ m_Y[0][j+1] - m_Y[0][j] }; + real_type dy{ m_Y[1][j+1] - m_Y[1][j] }; m_X[j] = hypot( dx, dy ); } break; case 3: - for ( size_t j = 0; j < nn; ++j ) { - real_type dx = m_Y[0][j+1] - m_Y[0][j]; - real_type dy = m_Y[1][j+1] - m_Y[1][j]; - real_type dz = m_Y[2][j+1] - m_Y[2][j]; + for ( size_t j{0}; j < nn; ++j ) { + real_type dx{ m_Y[0][j+1] - m_Y[0][j] }; + real_type dy{ m_Y[1][j+1] - m_Y[1][j] }; + real_type dz{ m_Y[2][j+1] - m_Y[2][j] }; m_X[j] = hypot( dx, hypot( dy, dz ) ); } break; default: - for ( size_t j = 0; j < nn; ++j ) { - real_type l = 0; - for ( size_t k = 0; k < size_t(m_dim); ++k ) { - real_type d = m_Y[k][j+1] - m_Y[k][j]; + for ( size_t j{0}; j < nn; ++j ) { + real_type l{0}; + for ( size_t k{0}; k < size_t(m_dim); ++k ) { + real_type d{ m_Y[k][j+1] - m_Y[k][j] }; l += d*d; } m_X[j] = sqrt(l); @@ -226,14 +219,14 @@ namespace Splines { void SplineVec::setKnotsChordLength() { computeChords(); - size_t nn = size_t(m_npts-1); - real_type acc = 0; - for ( size_t j = 0; j <= nn; ++j ) { - real_type l = m_X[j]; + size_t nn{ size_t(m_npts-1) }; + real_type acc{0}; + for ( size_t j{0}; j <= nn; ++j ) { + real_type l{ m_X[j] }; m_X[j] = acc; acc += l; } - for ( size_t j = 1; j < nn; ++j ) m_X[j] /= acc; + for ( size_t j{1}; j < nn; ++j ) m_X[j] /= acc; m_X[nn] = 1; } @@ -242,10 +235,10 @@ namespace Splines { void SplineVec::setKnotsCentripetal() { computeChords(); - size_t nn = size_t(m_npts-1); - real_type acc = 0; - for ( size_t j = 0; j <= nn; ++j ) { - real_type l = sqrt(m_X[j]); + size_t nn{ size_t(m_npts-1) }; + real_type acc{0}; + for ( size_t j{0}; j <= nn; ++j ) { + real_type l{ sqrt(m_X[j]) }; m_X[j] = acc; acc += l; } @@ -255,16 +248,16 @@ namespace Splines { void SplineVec::CatmullRom() { - size_t n = size_t(m_npts-1); - size_t d = size_t(m_dim); + size_t n{ size_t(m_npts-1) }; + size_t d{ size_t(m_dim) }; real_type l1, l2, ll, a, b; - for ( size_t j = 1; j < n; ++j ) { + for ( size_t j{1}; j < n; ++j ) { l1 = m_X[j] - m_X[j-1]; l2 = m_X[j+1] - m_X[j]; ll = l1+l2; a = (l2/l1)/ll; b = (l1/l2)/ll; - for ( size_t k = 0; k < d; ++k ) + for ( size_t k{0}; k < d; ++k ) m_Yp[k][j] = a*( m_Y[k][j] - m_Y[k][j-1] ) + b*( m_Y[k][j+1] - m_Y[k][j] ); } @@ -274,7 +267,7 @@ namespace Splines { ll = l1+l2; a = ll/(l1*l2); b = (l1/l2)/ll; - for ( size_t k = 0; k < d; ++k ) + for ( size_t k{0}; k < d; ++k ) m_Yp[k][0] = a*( m_Y[k][1] - m_Y[k][0] ) - b*( m_Y[k][2] - m_Y[k][0] ); @@ -283,7 +276,7 @@ namespace Splines { ll = l1+l2; a = ll/(l1*l2); b = (l1/l2)/ll; - for ( size_t k = 0; k < d; ++k ) + for ( size_t k{0}; k < d; ++k ) m_Yp[k][n] = b*( m_Y[k][n-2] - m_Y[k][n] ) - a*( m_Y[k][n-1] - m_Y[k][n] ); @@ -355,7 +348,7 @@ namespace Splines { SplineVec::eval( real_type x, real_type vals[], - integer inc + integer inc ) const { std::pair res; this->search( x, res ); diff --git a/src/Splines.cc b/src/Splines.cc index d568c2e..f50fbdc 100644 --- a/src/Splines.cc +++ b/src/Splines.cc @@ -72,7 +72,7 @@ namespace Splines { ) { t[0] = 0; t[npts-1] = 1; - for ( integer k = 1; k < npts-1; ++k ) + for ( integer k{1}; k < npts-1; ++k ) t[k] = static_cast(k)/static_cast(npts); } @@ -80,24 +80,24 @@ namespace Splines { void chordal( - integer dim, - integer npts, - real_type const * pnts, - integer ld_pnts, - real_type * t + integer dim, + integer npts, + real_type const pnts[], + integer ld_pnts, + real_type t[] ) { t[0] = 0; - real_type const * p0 = pnts; - for ( integer k = 1; k < npts; ++k ) { - real_type const * p1 = p0 + ld_pnts; + real_type const * p0{pnts}; + for ( integer k{1}; k < npts; ++k ) { + real_type const * p1{p0 + ld_pnts}; real_type dst = 0; - for ( integer j = 0; j < dim; ++j ) { - real_type c = p1[j] - p0[j]; + for ( integer j{0}; j < dim; ++j ) { + real_type c{p1[j] - p0[j]}; dst += c*c; } t[k] = t[k-1] + sqrt(dst); } - for ( integer k = 1; k < npts-1; ++k ) t[k] /= t[npts-1]; + for ( integer k{1}; k < npts-1; ++k ) t[k] /= t[npts-1]; t[npts-1] = 1; } @@ -105,25 +105,25 @@ namespace Splines { void centripetal( - integer dim, - integer npts, - real_type const * pnts, - integer ld_pnts, - real_type alpha, - real_type * t + integer dim, + integer npts, + real_type const pnts[], + integer ld_pnts, + real_type alpha, + real_type t[] ) { t[0] = 0; - real_type const * p0 = pnts; - for ( integer k = 1; k < npts; ++k ) { - real_type const * p1 = p0 + ld_pnts; - real_type dst = 0; - for ( integer j = 0; j < dim; ++j ) { - real_type c = p1[j] - p0[j]; + real_type const * p0{pnts}; + for ( integer k{1}; k < npts; ++k ) { + real_type const * p1{p0 + ld_pnts}; + real_type dst{0}; + for ( integer j{0}; j < dim; ++j ) { + real_type c{p1[j] - p0[j]}; dst += c*c; } t[k] = t[k-1] + pow(dst,alpha/2); } - for ( integer k = 1; k < npts-1; ++k ) t[k] /= t[npts-1]; + for ( integer k{1}; k < npts-1; ++k ) t[k] /= t[npts-1]; t[npts-1] = 1; } @@ -133,33 +133,33 @@ namespace Splines { void universal( - integer dim, - integer npts, - real_type const * pnts, - integer ld_pnts, - real_type * t + integer dim, + integer npts, + real_type const pnts[], + integer ld_pnts, + real_type t[] ); // to be done // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void FoleyNielsen( - integer dim, - integer npts, - real_type const * pnts, - integer ld_pnts, - real_type * t + integer dim, + integer npts, + real_type const pnts[], + integer ld_pnts, + real_type t[] ); // to be done // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void FangHung( - integer dim, - integer npts, - real_type const * pnts, - integer ld_pnts, - real_type * t + integer dim, + integer npts, + real_type const pnts[], + integer ld_pnts, + real_type t[] ); // to be done #endif @@ -170,7 +170,7 @@ namespace Splines { SplineType1D string_to_splineType1D( std::string const & nin ) { - std::string n = nin; + std::string n{nin}; std::transform(n.begin(), n.end(), n.begin(), ::tolower); if ( n == "constant" ) return SplineType1D::CONSTANT; else if ( n == "linear" ) return SplineType1D::LINEAR; @@ -187,7 +187,7 @@ namespace Splines { SplineType2D string_to_splineType2D( std::string const & nin ) { - std::string n = nin; + std::string n{nin}; std::transform(n.begin(), n.end(), n.begin(), ::tolower); if ( n == "bilinear" ) return SplineType2D::BILINEAR; else if ( n == "bicubic" ) return SplineType2D::BICUBIC; @@ -337,19 +337,19 @@ namespace Splines { //! Check if cubic spline with this data is monotone, return -1 no, 0 yes, 1 strictly monotone integer checkCubicSplineMonotonicity( - real_type const * X, - real_type const * Y, - real_type const * Yp, - integer npts + real_type const X[], + real_type const Y[], + real_type const Yp[], + integer npts ) { // check monotonicity of data: (assuming X monotone) - integer flag = 1; - for ( size_t i = 1; i < size_t(npts); ++i ) { + integer flag{1}; + for ( size_t i{1}; i < size_t(npts); ++i ) { if ( Y[i-1] > Y[i] ) return -2; // non monotone data if ( Utils::is_zero(Y[i-1]-Y[i]) && X[i-1] < X[i] ) flag = 0; // non strict monotone } // pag 146 Methods of Shape-Preserving Spline Approximation, K - for ( size_t i = 1; i < size_t(npts); ++i ) { + for ( size_t i{1}; i < size_t(npts); ++i ) { if ( X[i] <= X[i-1] ) continue; // skip duplicate points real_type dd = (Y[i]-Y[i-1])/(X[i]-X[i-1]); real_type m0 = Yp[i-1]/dd; @@ -379,13 +379,13 @@ namespace Splines { void Spline::build( - real_type const * x, integer incx, - real_type const * y, integer incy, + real_type const x[], integer incx, + real_type const y[], integer incy, integer n ) { reserve( n ); - for ( integer i = 0; i < n; ++i ) m_X[i] = x[i*incx]; - for ( integer i = 0; i < n; ++i ) m_Y[i] = y[i*incy]; + for ( integer i{0}; i < n; ++i ) m_X[i] = x[i*incx]; + for ( integer i{0}; i < n; ++i ) m_Y[i] = y[i*incy]; m_npts = n; build(); } @@ -444,8 +444,8 @@ namespace Splines { void Spline::set_origin( real_type x0 ) { - real_type Tx = x0 - m_X[0]; - real_type *ix = m_X; + real_type Tx{x0 - m_X[0]}; + real_type * ix{m_X}; while ( ix < m_X+m_npts ) *ix++ += Tx; } @@ -471,9 +471,9 @@ namespace Splines { char const * header ) const { s << header << '\n'; - real_type dx = (x_max()-x_min())/nintervals; - for ( integer i = 0; i <= nintervals; ++i ) { - real_type x = x_min() + i*dx; + real_type dx{ (x_max()-x_min())/nintervals }; + for ( integer i{0}; i <= nintervals; ++i ) { + real_type x{ x_min() + i*dx }; fmt::print( s, "{}\t{}\n", x, this->eval(x) ); } } @@ -577,17 +577,17 @@ namespace Splines { // gc["ydata"] // */ - string where = fmt::format("Spline[{}]::setup( gc ):", m_name ); - GenericContainer const & gc_x = gc("xdata",where.c_str()); - GenericContainer const & gc_y = gc("ydata",where.c_str()); + string where{ fmt::format("Spline[{}]::setup( gc ):", m_name ) }; + GenericContainer const & gc_x{ gc("xdata",where.c_str()) }; + GenericContainer const & gc_y{ gc("ydata",where.c_str()) }; vec_real_type x, y; { - std::string ff = fmt::format( "{}, field `xdata'", where ); + std::string ff{ fmt::format( "{}, field `xdata'", where ) }; gc_x.copyto_vec_real( x, ff.c_str() ); } { - std::string ff = fmt::format( "{}, field `ydata'", where ); + std::string ff{ fmt::format( "{}, field `ydata'", where ) }; gc_y.copyto_vec_real ( y, ff.c_str() ); } build( x, y ); diff --git a/src/Splines.hh b/src/Splines.hh index f6bfb57..8007870 100644 --- a/src/Splines.hh +++ b/src/Splines.hh @@ -147,8 +147,8 @@ namespace Splines { real_type & C, real_type & D ) { - real_type H2 = H*H; - real_type P10 = P1-P0; + real_type H2{ H*H }; + real_type P10{ P1-P0 }; A = (DP0+DP1-2*P10/H)/H2; B = (3*P10/H-(2*DP0+DP1))/H; C = DP0; @@ -187,9 +187,9 @@ namespace Splines { real_type & E, real_type & F ) { - real_type h2 = h*h; - real_type h3 = h*h2; - real_type P10 = P1-P0; + real_type h2{ h*h }; + real_type h3{ h*h2 }; + real_type P10{ P1-P0 }; A = ( (DDP1-DDP0)/2+(6*P10/h-3*(DP0+DP1))/h)/h3; B = ( (1.5*DDP0-DDP1)+ ((8*DP0+7*DP1)-15*P10/h)/h )/h2; C = ( 0.5*DDP1-1.5*DDP0 + (10*P10/h -(6*DP0+4*DP1))/h )/h; @@ -254,11 +254,11 @@ namespace Splines { //! void uniform( - integer dim, - integer npts, - real_type const * pnts, - integer ld_pnts, - real_type * t + integer dim, + integer npts, + real_type const pnts[], + integer ld_pnts, + real_type t[] ); //! @@ -272,11 +272,11 @@ namespace Splines { //! void chordal( - integer dim, - integer npts, - real_type const * pnts, - integer ld_pnts, - real_type * t + integer dim, + integer npts, + real_type const pnts[], + integer ld_pnts, + real_type t[] ); //! @@ -291,12 +291,12 @@ namespace Splines { //! void centripetal( - integer dim, - integer npts, - real_type const * pnts, - integer ld_pnts, - real_type alpha, - real_type * t + integer dim, + integer npts, + real_type const pnts[], + integer ld_pnts, + real_type alpha, + real_type t[] ); //! @@ -310,11 +310,11 @@ namespace Splines { //! void universal( - integer dim, - integer npts, - real_type const * pnts, - integer ld_pnts, - real_type * t + integer dim, + integer npts, + real_type const pnts[], + integer ld_pnts, + real_type t[] ); //! @@ -328,11 +328,11 @@ namespace Splines { //! void FoleyNielsen( - integer dim, - integer npts, - real_type const * pnts, - integer ld_pnts, - real_type * t + integer dim, + integer npts, + real_type const pnts[], + integer ld_pnts, + real_type t[] ); //! @@ -346,11 +346,11 @@ namespace Splines { //! void FangHung( - integer dim, - integer npts, - real_type const * pnts, - integer ld_pnts, - real_type * t + integer dim, + integer npts, + real_type const pnts[], + integer ld_pnts, + real_type t[] ); /*\ @@ -494,7 +494,7 @@ namespace Splines { //! real_type y_min() const { - integer N = m_npts; + integer N{m_npts}; if ( type() == SplineType1D::CONSTANT ) --N; return *std::min_element(m_Y,m_Y+N); } @@ -504,7 +504,7 @@ namespace Splines { //! real_type y_max() const { - integer N = m_npts; + integer N{m_npts}; if ( type() == SplineType1D::CONSTANT ) --N; return *std::max_element(m_Y,m_Y+N); } @@ -595,8 +595,8 @@ namespace Splines { virtual void build( - real_type const * x, integer incx, - real_type const * y, integer incy, + real_type const x[], integer incx, + real_type const y[], integer incy, integer n ); @@ -610,9 +610,9 @@ namespace Splines { inline void build( - real_type const * x, - real_type const * y, - integer n + real_type const x[], + real_type const y[], + integer n ) { this->build( x, 1, y, 1, n ); } @@ -697,7 +697,7 @@ namespace Splines { dump( ostream_type & s, integer nintervals, - char const * header = "x\ty" + char const header[] = "x\ty" ) const; //! @@ -705,9 +705,9 @@ namespace Splines { //! void dump( - char const * fname, - integer nintervals, - char const * header = "x\ty" + char const fname[], + integer nintervals, + char const header[] = "x\ty" ) const { std::ofstream file(fname); this->dump( file, nintervals, header ); @@ -904,7 +904,7 @@ namespace Splines { //! class CubicSplineBase : public Spline { protected: - Malloc_real m_baseValue; + Malloc_real m_mem_cubic; real_type * m_Yp{nullptr}; bool m_external_alloc{false}; @@ -922,7 +922,7 @@ namespace Splines { //! CubicSplineBase( string const & name = "CubicSplineBase" ) : Spline(name) - , m_baseValue(name+"_memory") + , m_mem_cubic( fmt::format("CubicSplineBase[{}]::m_mem_cubic", name ) ) {} ~CubicSplineBase() override {} @@ -1018,9 +1018,9 @@ namespace Splines { //! void build( - real_type const * x, integer incx, - real_type const * y, integer incy, - real_type const * yp, integer incyp, + real_type const x[], integer incx, + real_type const y[], integer incy, + real_type const yp[], integer incyp, integer n ); @@ -1035,9 +1035,9 @@ namespace Splines { inline void build( - real_type const * x, - real_type const * y, - real_type const * yp, + real_type const x[], + real_type const y[], + real_type const yp[], integer n ) { this->build( x, 1, y, 1, yp, 1, n ); @@ -1161,10 +1161,10 @@ namespace Splines { void load_Z( - real_type const * z, - integer ldZ, - bool fortran_storage, - bool transposed + real_type const z[], + integer ldZ, + bool fortran_storage, + bool transposed ); public: @@ -1335,9 +1335,9 @@ namespace Splines { void build( - real_type const * x, integer incx, - real_type const * y, integer incy, - real_type const * z, integer ldZ, + real_type const x[], integer incx, + real_type const y[], integer incy, + real_type const z[], integer ldZ, integer nx, integer ny, bool fortran_storage = false, bool transposed = false @@ -1375,10 +1375,10 @@ namespace Splines { void build( - real_type const * z, - integer ldZ, - integer nx, - integer ny, + real_type const z[], + integer ldZ, + integer nx, + integer ny, bool fortran_storage = false, bool transposed = false ); diff --git a/src/Splines/SplineAkima.hxx b/src/Splines/SplineAkima.hxx index ef05cbd..b449c96 100644 --- a/src/Splines/SplineAkima.hxx +++ b/src/Splines/SplineAkima.hxx @@ -32,10 +32,10 @@ namespace Splines { void Akima_build( - real_type const * X, - real_type const * Y, - real_type * Yp, - integer npts + real_type const X[], + real_type const Y[], + real_type Yp[], + integer npts ); #endif diff --git a/src/Splines/SplineBiCubic.hxx b/src/Splines/SplineBiCubic.hxx index 666da93..6b719c5 100644 --- a/src/Splines/SplineBiCubic.hxx +++ b/src/Splines/SplineBiCubic.hxx @@ -52,9 +52,9 @@ namespace Splines { public: //! spline constructor - BiCubicSplineBase( string const & name = "Spline" ) + BiCubicSplineBase( string const & name = "BiCubicSplineBase" ) : SplineSurf( name ) - , m_mem_bicubic("BiCubicSplineBase") + , m_mem_bicubic( fmt::format("BiCubicSplineBase[{}]",name) ) {} ~BiCubicSplineBase() override {} @@ -119,7 +119,7 @@ namespace Splines { //! //! Spline constructor //! - BiCubicSpline( string const & name = "Spline" ) + BiCubicSpline( string const & name = "BiCubicSpline" ) : BiCubicSplineBase( name ) {} diff --git a/src/Splines/SplineBiQuintic.hxx b/src/Splines/SplineBiQuintic.hxx index caf13fc..844c16f 100644 --- a/src/Splines/SplineBiQuintic.hxx +++ b/src/Splines/SplineBiQuintic.hxx @@ -101,7 +101,7 @@ namespace Splines { public: //! spline constructor - BiQuinticSpline( string const & name = "Spline" ) + BiQuinticSpline( string const & name = "BiQuinticSpline" ) : BiQuinticSplineBase( name ) {} diff --git a/src/Splines/SplineBilinear.hxx b/src/Splines/SplineBilinear.hxx index 4102f5d..adadee3 100644 --- a/src/Splines/SplineBilinear.hxx +++ b/src/Splines/SplineBilinear.hxx @@ -43,7 +43,7 @@ namespace Splines { public: //! spline constructor - BilinearSpline( string const & name = "Spline" ) + BilinearSpline( string const & name = "BilinearSpline" ) : SplineSurf(name) {} diff --git a/src/Splines/SplineConstant.hxx b/src/Splines/SplineConstant.hxx index e20313e..3cd723f 100644 --- a/src/Splines/SplineConstant.hxx +++ b/src/Splines/SplineConstant.hxx @@ -30,7 +30,7 @@ namespace Splines { //! Picewise constants spline class class ConstantSpline : public Spline { - Malloc_real m_baseValue; + Malloc_real m_mem_constant; bool m_external_alloc{false}; public: @@ -41,7 +41,7 @@ namespace Splines { ConstantSpline( string const & name = "ConstantSpline" ) : Spline(name) - , m_baseValue(name+"_memory") + , m_mem_constant( fmt::format("ConstantSpline[{}]",name) ) {} ~ConstantSpline() override {} diff --git a/src/Splines/SplineLinear.hxx b/src/Splines/SplineLinear.hxx index 7a2c3fa..c2c069a 100644 --- a/src/Splines/SplineLinear.hxx +++ b/src/Splines/SplineLinear.hxx @@ -30,7 +30,7 @@ namespace Splines { //! Linear spline class class LinearSpline : public Spline { - Malloc_real m_baseValue; + Malloc_real m_mem_linear; bool m_external_alloc{false}; public: @@ -41,7 +41,7 @@ namespace Splines { LinearSpline( string const & name = "LinearSpline" ) : Spline(name) - , m_baseValue( name+"_memory" ) + , m_mem_linear( fmt::format( "LinearSpline[{}]", name ) ) { m_curve_extended_constant = true; // by default linear spline extend constant } diff --git a/src/Splines/SplineQuinticBase.hxx b/src/Splines/SplineQuinticBase.hxx index c623780..5b7addc 100644 --- a/src/Splines/SplineQuinticBase.hxx +++ b/src/Splines/SplineQuinticBase.hxx @@ -24,7 +24,6 @@ | | |_| | |_| | | | | | |_| | (__ ___) | |_) | | | | | | __/ |_) | (_| \__ \ __/ | \__\_\\__,_|_|_| |_|\__|_|\___|____/| .__/|_|_|_| |_|\___|____/ \__,_|___/\___| | |_| - | \*/ namespace Splines { @@ -34,7 +33,7 @@ namespace Splines { //! class QuinticSplineBase : public Spline { protected: - Malloc_real m_baseValue; + Malloc_real m_base_quintic; real_type * m_Yp{nullptr}; real_type * m_Ypp{nullptr}; bool m_external_alloc{false}; @@ -53,9 +52,9 @@ namespace Splines { //! //! Spline constructor //! - QuinticSplineBase( string const & name = "Spline" ) + QuinticSplineBase( string const & name = "QuinticSplineBase" ) : Spline(name) - , m_baseValue(name+"_memeory") + , m_base_quintic( fmt::format( "QuinticSplineBase[{}]", name ) ) {} ~QuinticSplineBase() override {} diff --git a/src/Splines/SplineSet.hxx b/src/Splines/SplineSet.hxx index d9aea5b..d1b12c6 100644 --- a/src/Splines/SplineSet.hxx +++ b/src/Splines/SplineSet.hxx @@ -58,10 +58,10 @@ namespace Splines { string const m_name; - Utils::Malloc m_baseValue; - Utils::Malloc m_basePointer; - Utils::Malloc m_baseSplines; - Utils::Malloc m_baseInt; + Utils::Malloc m_mem; + Utils::Malloc m_mem_p; + Utils::Malloc m_mem_splines; + Utils::Malloc m_mem_int; integer m_npts{0}; integer m_nspl{0}; @@ -189,7 +189,7 @@ namespace Splines { //! Return y-minumum spline value. //! real_type - y_min( char const * spl ) const { + y_min( char const spl[] ) const { integer idx{ this->get_position(spl) }; return m_Ymin[idx]; } @@ -198,7 +198,7 @@ namespace Splines { //! Return y-maximum spline value. //! real_type - y_max( char const * spl ) const { + y_max( char const spl[] ) const { integer idx{ this->get_position(spl) }; return m_Ymax[idx]; } @@ -217,7 +217,7 @@ namespace Splines { //! Return pointer to the `i`-th spline. //! Spline * - get_spline( char const * hdr ) const { + get_spline( char const hdr[] ) const { integer idx{ this->get_position(hdr) }; return m_splines[idx]; } @@ -339,7 +339,7 @@ namespace Splines { //! Evaluate spline `name` at `x`. //! real_type - eval( real_type x, char const * name ) const { + eval( real_type x, char const name[] ) const { Spline const * S{ this->get_spline(name) }; return S->eval(x); } @@ -348,7 +348,7 @@ namespace Splines { //! Evaluate spline `name` first derivative at `x`. //! real_type - eval_D( real_type x, char const * name ) const { + eval_D( real_type x, char const name[] ) const { Spline const * S{ this->get_spline(name) }; return S->D(x); } @@ -357,7 +357,7 @@ namespace Splines { //! Evaluate spline `name` second derivative at `x`. //! real_type - eval_DD( real_type x, char const * name ) const { + eval_DD( real_type x, char const name[] ) const { Spline const * S{ this->get_spline(name) }; return S->DD(x); } @@ -366,7 +366,7 @@ namespace Splines { //! Evaluate spline `name` third derivative at `x`. //! real_type - eval_DDD( real_type x, char const * name ) const { + eval_DDD( real_type x, char const name[] ) const { Spline const * S{ this->get_spline(name) }; return S->DDD(x); } @@ -375,7 +375,7 @@ namespace Splines { //! Evaluate spline `name` 4th derivative at `x`. //! real_type - eval_DDDD( real_type x, char const * name ) const { + eval_DDDD( real_type x, char const name[] ) const { Spline const * S{ this->get_spline(name) }; return S->DDDD(x); } @@ -384,7 +384,7 @@ namespace Splines { //! Evaluate spline `name` 5th derivative at `x`. //! real_type - eval_DDDDD( real_type x, char const * name ) const { + eval_DDDDD( real_type x, char const name[] ) const { Spline const * S{ this->get_spline(name) }; return S->DDDDD(x); } @@ -604,9 +604,9 @@ namespace Splines { //! real_type eval2( - real_type zeta, - char const * indep, - char const * name + real_type zeta, + char const indep[], + char const name[] ) const; //! @@ -615,9 +615,9 @@ namespace Splines { //! real_type eval2_D( - real_type zeta, - char const * indep, - char const * name + real_type zeta, + char const indep[], + char const name[] ) const; //! @@ -626,9 +626,9 @@ namespace Splines { //! real_type eval2_DD( - real_type zeta, - char const * indep, - char const * name + real_type zeta, + char const indep[], + char const name[] ) const; //! @@ -637,9 +637,9 @@ namespace Splines { //! real_type eval2_DDD( - real_type zeta, - char const * indep, - char const * name + real_type zeta, + char const indep[], + char const name[] ) const; ///@} @@ -800,7 +800,7 @@ namespace Splines { void eval2( real_type zeta, - char const * indep, + char const indep[], GenericContainer & vals ) const { this->eval2( zeta, this->get_position(indep), vals ); @@ -814,7 +814,7 @@ namespace Splines { void eval2( vec_real_type const & zetas, - char const * indep, + char const indep[], GenericContainer & vals ) const { this->eval2( zetas, this->get_position(indep), vals ); @@ -828,7 +828,7 @@ namespace Splines { void eval2( real_type zeta, - char const * indep, + char const indep[], vec_string_type const & columns, GenericContainer & vals ) const { @@ -843,7 +843,7 @@ namespace Splines { void eval2( vec_real_type const & zetas, - char const * indep, + char const indep[], vec_string_type const & columns, GenericContainer & vals ) const { @@ -964,7 +964,7 @@ namespace Splines { void eval2_D( real_type zeta, - char const * indep, + char const indep[], GenericContainer & vals ) const { this->eval2_D( zeta, this->get_position(indep), vals ); @@ -978,7 +978,7 @@ namespace Splines { void eval2_D( vec_real_type const & zetas, - char const * indep, + char const indep[], GenericContainer & vals ) const { this->eval2_D( zetas, this->get_position(indep), vals ); @@ -992,7 +992,7 @@ namespace Splines { void eval2_D( real_type zeta, - char const * indep, + char const indep[], vec_string_type const & columns, GenericContainer & vals ) const { @@ -1007,7 +1007,7 @@ namespace Splines { void eval2_D( vec_real_type const & zetas, - char const * indep, + char const indep[], vec_string_type const & columns, GenericContainer & vals ) const { @@ -1122,7 +1122,7 @@ namespace Splines { void eval2_DD( real_type zeta, - char const * indep, + char const indep[], GenericContainer & vals ) const { this->eval2_DD( zeta, this->get_position(indep), vals ); @@ -1136,7 +1136,7 @@ namespace Splines { void eval2_DD( vec_real_type const & zetas, - char const * indep, + char const indep[], GenericContainer & vals ) const { this->eval2_DD( zetas, this->get_position(indep), vals ); @@ -1150,7 +1150,7 @@ namespace Splines { void eval2_DD( real_type zeta, - char const * indep, + char const indep[], vec_string_type const & columns, GenericContainer & vals ) const { @@ -1164,8 +1164,8 @@ namespace Splines { //! void eval2_DD( - vec_real_type const & zetas, - char const * indep, + vec_real_type const & zetas, + char const indep[], vec_string_type const & columns, GenericContainer & vals ) const { @@ -1296,7 +1296,7 @@ namespace Splines { void eval2_DDD( vec_real_type const & zetas, - char const * indep, + char const indep[], GenericContainer & vals ) const { this->eval2_DDD( zetas, this->get_position(indep), vals ); @@ -1310,7 +1310,7 @@ namespace Splines { void eval2_DDD( real_type zeta, - char const * indep, + char const indep[], vec_string_type const & columns, GenericContainer & vals ) const { @@ -1324,8 +1324,8 @@ namespace Splines { //! void eval2_DDD( - vec_real_type const & zetas, - char const * indep, + vec_real_type const & zetas, + char const indep[], vec_string_type const & columns, GenericContainer & vals ) const { @@ -1351,13 +1351,13 @@ namespace Splines { //! void build( - integer nspl, - integer npts, - char const ** headers, - SplineType1D const * stype, - real_type const * X, - real_type const ** Y, - real_type const ** Yp = nullptr + integer nspl, + integer npts, + char const * headers[], + SplineType1D const stype[], + real_type const X[], + real_type const * Y[], + real_type const * Yp[] = nullptr ); void @@ -1370,12 +1370,9 @@ namespace Splines { ///@} //! Return spline type (as number) - SplineType1D - type() const - { return SplineType1D::SPLINE_SET; } + SplineType1D type() const { return SplineType1D::SPLINE_SET; } - string - info() const; + string info() const; void info( ostream_type & stream ) const diff --git a/src/Splines/SplineVec.hxx b/src/Splines/SplineVec.hxx index b715acb..3ece017 100644 --- a/src/Splines/SplineVec.hxx +++ b/src/Splines/SplineVec.hxx @@ -37,13 +37,13 @@ namespace Splines { string const m_name; - Utils::Malloc m_baseValue; - Utils::Malloc m_basePointer; + Utils::Malloc m_mem; + Utils::Malloc m_mem_p; - integer m_dim; - integer m_npts; - bool m_curve_is_closed; - bool m_curve_can_extend; + integer m_dim{0}; + integer m_npts{0}; + bool m_curve_is_closed{false}; + bool m_curve_can_extend{true}; real_type * m_X{nullptr}; real_type ** m_Y{nullptr}; diff --git a/src/Splines/Splines1D.hxx b/src/Splines/Splines1D.hxx index c4a0b9a..b1db732 100644 --- a/src/Splines/Splines1D.hxx +++ b/src/Splines/Splines1D.hxx @@ -33,14 +33,13 @@ namespace Splines { protected: std::string m_name; - Spline * m_pSpline{nullptr}; + public: + Spline1D( Spline1D const & ) = delete; Spline1D const & operator = ( Spline1D const & ) = delete; - public: - //! \name Constructors ///@{ @@ -141,8 +140,8 @@ namespace Splines { void build( SplineType1D tp, - real_type const * x, integer incx, - real_type const * y, integer incy, + real_type const x[], integer incx, + real_type const y[], integer incy, integer n ); @@ -156,10 +155,10 @@ namespace Splines { //! void build( - SplineType1D tp, - real_type const * x, - real_type const * y, - integer n + SplineType1D tp, + real_type const x[], + real_type const y[], + integer n ) { this->build( tp, x, 1, y, 1, n ); } @@ -222,16 +221,16 @@ namespace Splines { dump( ostream_type & s, integer nintervals, - char const * header = "x\ty" + char const header[] = "x\ty" ) const { m_pSpline->dump( s, nintervals, header ); } void dump( - char const * fname, - integer nintervals, - char const * header = "x\ty" + char const fname[], + integer nintervals, + char const header[] = "x\ty" ) const { m_pSpline->dump( fname, nintervals, header ); } diff --git a/src/Splines/Splines2D.hxx b/src/Splines/Splines2D.hxx index 1a92d26..68fb3a3 100644 --- a/src/Splines/Splines2D.hxx +++ b/src/Splines/Splines2D.hxx @@ -217,19 +217,17 @@ namespace Splines { void build( - SplineType2D tp, - real_type const * x, integer incx, - real_type const * y, integer incy, - real_type const * z, integer ldZ, - integer nx, - integer ny, - bool fortran_storage = false, - bool transposed = false + SplineType2D tp, + real_type const x[], integer incx, + real_type const y[], integer incy, + real_type const z[], integer ldZ, + integer nx, + integer ny, + bool fortran_storage = false, + bool transposed = false ) { new_spline( tp ); - m_spline_2D->build( - x, incx, y, incy, z, ldZ, nx, ny, fortran_storage, transposed - ); + m_spline_2D->build( x, incx, y, incy, z, ldZ, nx, ny, fortran_storage, transposed ); } //! @@ -273,13 +271,13 @@ namespace Splines { //! void build( - SplineType2D tp, - real_type const * z, - integer ldZ, - integer nx, - integer ny, - bool fortran_storage = false, - bool transposed = false + SplineType2D tp, + real_type const z[], + integer ldZ, + integer nx, + integer ny, + bool fortran_storage = false, + bool transposed = false ) { new_spline( tp ); m_spline_2D->build( z, ldZ, nx, ny, fortran_storage, transposed ); @@ -323,12 +321,7 @@ namespace Splines { //! using Akima algorithm to avoid obscillation //! void - setup( GenericContainer const & gc ) { - string where = fmt::format("Spline2D[{}]::setup( gc ):", m_name ); - string type = gc.get_map_string("spline_type",where.c_str()); - new_spline( string_to_splineType2D( type ) ); - m_spline_2D->setup( gc ); - } + setup( GenericContainer const & gc ); void build( GenericContainer const & gc ) diff --git a/src/Splines1D.cc b/src/Splines1D.cc index 6c02063..9798d95 100644 --- a/src/Splines1D.cc +++ b/src/Splines1D.cc @@ -49,8 +49,8 @@ namespace Splines { void Spline1D::build( SplineType1D tp, - real_type const * x, integer incx, - real_type const * y, integer incy, + real_type const x[], integer incx, + real_type const y[], integer incy, integer n ) { if ( m_pSpline != nullptr ) delete m_pSpline; @@ -92,8 +92,8 @@ namespace Splines { // gc["ydata"] // */ - string where = fmt::format("Spline1D[{}]::setup( gc ):", m_name ); - std::string const & spl_type = gc.get_map_string("spline_type",where.c_str()); + string where{ fmt::format("Spline1D[{}]::setup( gc ):", m_name ) }; + std::string const & spl_type{ gc.get_map_string("spline_type",where.c_str()) }; SplineType1D tp; if ( spl_type == "constant" ) { diff --git a/src/Splines2D.cc b/src/Splines2D.cc index 04049cb..48733c6 100644 --- a/src/Splines2D.cc +++ b/src/Splines2D.cc @@ -47,4 +47,12 @@ namespace Splines { } } + void + Spline2D::setup( GenericContainer const & gc ) { + string where{ fmt::format("Spline2D[{}]::setup( gc ):", m_name ) }; + string type{ gc.get_map_string("spline_type",where.c_str()) }; + new_spline( string_to_splineType2D( type ) ); + m_spline_2D->setup( gc ); + } + } diff --git a/src/SplinesBivariate.cc b/src/SplinesBivariate.cc index 2a0cccb..23301f0 100644 --- a/src/SplinesBivariate.cc +++ b/src/SplinesBivariate.cc @@ -61,10 +61,10 @@ namespace Splines { // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void SplineSurf::load_Z( - real_type const * z, - integer ldZ, - bool fortran_storage, - bool transposed + real_type const z[], + integer ldZ, + bool fortran_storage, + bool transposed ) { if ( transposed ) { if ( fortran_storage ) { @@ -140,13 +140,13 @@ namespace Splines { //! void SplineSurf::build( - real_type const * x, integer incx, - real_type const * y, integer incy, - real_type const * z, integer ldZ, - integer nx, - integer ny, - bool fortran_storage, - bool transposed + real_type const x[], integer incx, + real_type const y[], integer incy, + real_type const z[], integer ldZ, + integer nx, + integer ny, + bool fortran_storage, + bool transposed ) { m_nx = nx; m_ny = ny; @@ -184,12 +184,12 @@ namespace Splines { //! void SplineSurf::build( - real_type const * z, - integer ldZ, - integer nx, - integer ny, - bool fortran_storage, - bool transposed + real_type const z[], + integer ldZ, + integer nx, + integer ny, + bool fortran_storage, + bool transposed ) { m_nx = nx; m_ny = ny; diff --git a/src/SplinesCinterface.cc b/src/SplinesCinterface.cc index 1dd40bb..8fce8c5 100644 --- a/src/SplinesCinterface.cc +++ b/src/SplinesCinterface.cc @@ -63,8 +63,8 @@ extern "C" { int SPLINE_new( - char const * id, - char const * type + char const id[], + char const type[] ) { fmt::print( "SPLINE_new, id = {} type = {}\n", id, type ); MAP_SPLINE::iterator it = spline_stored.find(id); @@ -88,7 +88,7 @@ extern "C" { } int - SPLINE_select( char const * id ) { + SPLINE_select( char const id[] ) { MAP_SPLINE::iterator it = spline_stored.find(id); if ( it != spline_stored.end() ) { head = it->second; @@ -99,7 +99,7 @@ extern "C" { } int - SPLINE_delete( char const * id ) { + SPLINE_delete( char const id[] ) { MAP_SPLINE::iterator it = spline_stored.find(id); if ( it != spline_stored.end() ) { delete it->second; @@ -166,9 +166,9 @@ extern "C" { int SPLINE_build2( - double const * x, - double const * y, - int n + double const x[], + double const y[], + int n ) { if ( head != nullptr ) { head->build( x, y, n ); diff --git a/src/SplinesCinterface.h b/src/SplinesCinterface.h index 37d20b9..096dd2d 100644 --- a/src/SplinesCinterface.h +++ b/src/SplinesCinterface.h @@ -43,19 +43,19 @@ extern "C" { */ int SPLINE_new( - char const * id, - char const * type + char const id[], + char const type[] ); /*! * Select a `Spline` object `id` */ - int SPLINE_select( char const * id ); + int SPLINE_select( char const id[] ); /*! * Delete the `Spline` object `id` */ - int SPLINE_delete( char const * id ); + int SPLINE_delete( char const id[] ); /*! * Print the actual `Spline` @@ -70,7 +70,7 @@ extern "C" { /*! * Get pointer to the internal `Spline` object 'id' */ - void * SPLINE_mem_ptr( char const * id ); + void * SPLINE_mem_ptr( char const id[] ); /*! * Set actual pointed element of `Spline` to an empty spline. @@ -92,9 +92,9 @@ extern "C" { */ int SPLINE_build2( - double const * x, - double const * y, - int n + double const x[], + double const y[], + int n ); /*! diff --git a/src/SplinesUtils.cc b/src/SplinesUtils.cc index 7402f99..1024aa1 100644 --- a/src/SplinesUtils.cc +++ b/src/SplinesUtils.cc @@ -4,7 +4,7 @@ | | | , __ , __ | | /|/ \ /|/ \ | - | | __/ _ ,_ | __/ _ ,_ | + | | __/ _ ,_ | __/ _ ,_ | | | \|/ / | | | | \|/ / | | | | | |(__/|__/ |_/ \_/|/|(__/|__/ |_/ \_/|/ | | /| /| | @@ -395,13 +395,13 @@ namespace Splines { void first_derivative_build( - real_type const * X, - real_type const * Y, - real_type * Yp, - integer npts + real_type const X[], + real_type const Y[], + real_type Yp[], + integer npts ) { - size_t n = npts > 0 ? size_t( npts - 1 ) : 0; + size_t n{ npts > 0 ? size_t( npts - 1 ) : 0 }; // special case n=2 -- use linear interpolation. { @@ -436,7 +436,7 @@ namespace Splines { } // loop through interior points. - for ( size_t i = 2; i < n-1 ; ++i ) { + for ( size_t i{2}; i < n-1 ; ++i ) { real_type hLL = X[i-1] - X[i-2]; real_type hL = X[i+0] - X[i-1]; @@ -471,14 +471,14 @@ namespace Splines { void second_derivative_build( - real_type const * X, - real_type const * Y, - real_type const * Yp, - real_type * Ypp, - integer npts + real_type const X[], + real_type const Y[], + real_type const Yp[], + real_type Ypp[], + integer npts ) { - size_t n = npts > 0 ? size_t( npts - 1 ) : 0; + size_t n{ npts > 0 ? size_t( npts - 1 ) : 0 }; // special case n=2 -- use linear interpolation. switch ( npts ) { @@ -488,7 +488,7 @@ namespace Splines { } // loop through interior points. - for ( size_t i = 1; i < n ; ++i ) { + for ( size_t i{1}; i < n ; ++i ) { real_type hL = X[i+0] - X[i-1]; real_type hR = X[i+1] - X[i+0];