src/oceanbox.cpp
//------------------------------------------------------------------------------
/*! \brief          Is box C oscillating?
 *  \param[in] lookback     Window size to look back into the past
 *  \param[in] maxamp       Max amplitude (% of box size) allowed
 *  \param[in] maxflips     Max flips (direction reversals) allowed
 *  \returns                bool indicating whether box C is oscillating recently
 *  \details                How do we identify is the box is oscillating? Count how many
 *  sign flips there are in the deltas (C(t)-C(t-1)) of a certain magnitude.
 */
\brief          Is box C oscillating.
\ brief Is box C oscillating .
bool oceanbox::oscillating( const unsigned lookback, const double maxamp, const int maxflips ) const {
#define sgn( x ) ( x > 0 ) - ( x < 0 )
    if( carbonHistory.size() < lookback ) return false;
    const double currentC = carbon.value( U_PGC );
    double minC = currentC, maxC = currentC;
    double lastdelta = currentC - carbonHistory[ 0 ];
    int flipcount = 0;
    for ( unsigned i=0; i<lookback-1; i++ )  {
        double delta = carbonHistory[ i ]-carbonHistory[ i+1 ];
        flipcount += ( sgn( lastdelta ) != sgn( delta ) );
        lastdelta = delta;
        minC = min( minC, carbonHistory[ i ] );
        maxC = max( maxC, carbonHistory[ i ] );
    }
    return flipcount>maxflips && ( maxC-minC )/currentC*100 > maxamp;
}
bool oceanbox :: oscillating ( const unsigned lookback , const double maxamp , const int maxflips ) const { #define sgn ( x )  ( x > 0 ) - ( x < 0 ) if ( carbonHistory . size ( ) < lookback ) return false ; const double currentC = carbon . value ( U_PGC ) ; double minC = currentC , maxC = currentC ; double lastdelta = currentC - carbonHistory [ 0 ] ; int flipcount = 0 ; for ( unsigned i = 0 ; i < lookback - 1 ; i ++ ) { double delta = carbonHistory [ i ] - carbonHistory [ i + 1 ] ; flipcount += ( sgn ( lastdelta ) != sgn ( delta ) ) ; lastdelta = delta ; minC = min ( minC , carbonHistory [ i ] ) ; maxC = max ( maxC , carbonHistory [ i ] ) ; } return flipcount > maxflips && ( maxC - minC ) / currentC * 100 > maxamp ; }
\brief          Is box C oscillating?
\ brief Is box C oscillating?