ARTS 2.5.10 (git: 2f1c442c)
logic.cc File Reference

Logical functions. More...

#include "logic.h"
#include <algorithm>
#include <cmath>
#include <limits>
#include <stdexcept>
#include "sorting.h"

Go to the source code of this file.

Macros

#define precision   0.

Functions

bool is_bool (const Index &x)
Checks if a variable equals 0 or 1.

bool is_multiple (const Index &x, const Index &y)
Checks if an integer is a multiple of another integer.

bool is_size (ConstVectorView x, const Index &n)
Verifies that the size of x is l.

bool is_size (ConstMatrixView x, const Index &r, const Index &c)
Verifies that the size of x is r by c.

bool is_size (ConstTensor3View x, const Index &p, const Index &r, const Index &c)
Verifies that the size of x is [p,r,c].

bool is_size (ConstTensor4View x, const Index &b, const Index &p, const Index &r, const Index &c)
Verifies that the size of x is [b,p,r,c].

bool is_size (ConstTensor5View x, const Index &s, const Index &b, const Index &p, const Index &r, const Index &c)
Verifies that the size of x is [s,b,p,r,c].

bool is_size (ConstTensor6View x, const Index &v, const Index &s, const Index &b, const Index &p, const Index &r, const Index &c)
Verifies that the size of x is [v,s,b,p,r,c].

bool is_size (ConstTensor7View x, const Index &l, const Index &v, const Index &s, const Index &b, const Index &p, const Index &r, const Index &c)
Verifies that the size of x is [l,v,s,b,p,r,c].

bool is_sorted (ConstVectorView x)
Checks if a vector is sorted in ascending order.

bool is_increasing (ConstVectorView x)
Checks if a vector is sorted and strictly increasing.

bool is_increasing (const ArrayOfIndex &x)
Checks if an ArrayOfIndex is sorted and strictly increasing.

bool is_decreasing (ConstVectorView x)
Checks if a vector is sorted in reversed order and is strictly decreasing.

bool is_unique (const ArrayOfIndex &x)
Checks if an ArrayOfIndex is unique, i.e., has no duplicate values.

bool is_singular (ConstMatrixView A)
Checks if a square matrix is singular.

bool is_diagonal (ConstMatrixView A)
Checks if a square matrix is diagonal.

bool is_same_within_epsilon (const Numeric &a, const Numeric &b, const Numeric &epsilon)
Check, if two numbers agree within a given epsilon.

bool is_lon_cyclic (ConstVectorView grid, const Numeric &epsilon)
Check if the given longitude grid is cyclic.

bool is_regularly_increasing_within_epsilon (ConstVectorView x, const Numeric epsilon)

Detailed Description

Logical functions.

Date
Fri May 3 19:02:36 2002

All functions here have return type bool. They all check whether some condition is fullfilled and return true if that is the case.

These functions are intended to be used either inside "if" statements or inside "ARTS_ASSERT" statements.

The condition should have a simple and intuitive meaning!

Definition in file logic.cc.

◆ precision

 #define precision   0.

Definition at line 46 of file logic.cc.

◆ is_bool()

 bool is_bool ( const Index & x )

Checks if a variable equals 0 or 1.

Returns
True if the variable is 0 or 1. Otherwise false.
Parameters
 x A variable of type Index.

Definition at line 53 of file logic.cc.

Referenced by chk_if_bool().

◆ is_decreasing()

 bool is_decreasing ( ConstVectorView x )

Checks if a vector is sorted in reversed order and is strictly decreasing.

Duplicated values are not allowed.

Returns
True if strictly decreasing, otherwise false.
Parameters
 x A vector.

Definition at line 255 of file logic.cc.

References ConstVectorView::nelem().

◆ is_diagonal()

 bool is_diagonal ( ConstMatrixView A )

Checks if a square matrix is diagonal.

If one off diagonal element is nonzero the function returns false.

Due to numerical inaccuracies the values can deviate from 0. The value for the precision is defined in the file logic.cc.

Returns
True if matrix is diagonal.
Parameters
 A A square matrix.

Definition at line 326 of file logic.cc.

References ARTS_ASSERT, ConstMatrixView::ncols(), ConstMatrixView::nrows(), and precision.

◆ is_increasing() [1/2]

 bool is_increasing ( const ArrayOfIndex & x )

Checks if an ArrayOfIndex is sorted and strictly increasing.

Duplicated values are not allowed. Clone of the similar funciton for vectors.

Returns
True if strictly increasing, otherwise false.
Parameters
 x An ArrayOfIndex.
Date
2007-05-18

Definition at line 239 of file logic.cc.

References Array< base >::nelem().

◆ is_increasing() [2/2]

 bool is_increasing ( ConstVectorView x )

Checks if a vector is sorted and strictly increasing.

Duplicated values are not allowed.

Returns
True if strictly increasing, otherwise false.
Parameters
 x A vector.

Definition at line 218 of file logic.cc.

References ConstVectorView::nelem().

◆ is_lon_cyclic()

 bool is_lon_cyclic ( ConstVectorView grid, const Numeric & epsilon )

Check if the given longitude grid is cyclic.

Checks whether the grid spans 0 to 360 degrees.

Parameters
 grid Longitude grid. epsilon The epsilon of the required agreement.
Returns
True if the grid is cyclic.

Definition at line 369 of file logic.cc.

References is_same_within_epsilon(), and ConstVectorView::nelem().

Referenced by chk_atm_field(), GriddedFieldLatLonRegrid(), and plevel_slope_3d().

◆ is_multiple()

 bool is_multiple ( const Index & x, const Index & y )

Checks if an integer is a multiple of another integer.

The function returns true if y * n = x, where n is an integer.

The choice of y = 0 is not allowed.

Returns
True if x is a multiple of y.
Parameters
 x Nominator of the integer division. y Denominator of the integer division.
Date
2002-08-11

Definition at line 68 of file logic.cc.

References ARTS_ASSERT.

Referenced by integer_div().

◆ is_regularly_increasing_within_epsilon()

 bool is_regularly_increasing_within_epsilon ( ConstVectorView x, const Numeric epsilon = 1e-8 )

Checks if the vector is increasing with a regular interval

The check is abs((x[i] - x[i-1]) - (x[1] - x[0])) < epsilon

Parameters
 [in] x A vector [in] epsilon A comparison

Definition at line 374 of file logic.cc.

References ConstVectorView::size().

◆ is_same_within_epsilon()

 bool is_same_within_epsilon ( const Numeric & a, const Numeric & b, const Numeric & epsilon )

Check, if two numbers agree within a given epsilon.

This logical function verifies if two numbers are the same for the desired number of digits. The comparison statement comes from Oliver: ( abs(a-b) <= epsilon * max(a,b) )

Modified to make sure that negative numbers are also treated correctly.

The variable epsilon gives the number of digits used for the comparison. (epsilon = 0.0001 for a comparison up to the 5th digit)

Parameters
 a A number. b Another number. epsilon The epsilon of the required agreement.
Returns
True if the two numbers are the same.

Definition at line 354 of file logic.cc.

References a, abs(), b, and max().

◆ is_singular()

 bool is_singular ( ConstMatrixView A )

Checks if a square matrix is singular.

If one row of a matrix has only 0 values the matrix is singular.

Due to numerical inaccuracies the values can deviate from 0. The value for the precision is defined in the file logic.cc.

Returns
True if matrix is singular.
Parameters
 A A square matrix.

Definition at line 298 of file logic.cc.

References ARTS_ASSERT, ConstMatrixView::ncols(), ConstMatrixView::nrows(), and precision.

Referenced by cloud_ppath_update1D_planeparallel(), cloud_RT_no_background(), and ext2trans().

◆ is_size() [1/7]

 bool is_size ( ConstMatrixView x, const Index & r, const Index & c )

Verifies that the size of x is r by c.

Parameters
 x The Matrix to check. r The desired number of rows. c The desired number of columns.
Returns
True if the size of x is r x c.

Definition at line 91 of file logic.cc.

References c, ConstMatrixView::ncols(), and ConstMatrixView::nrows().

◆ is_size() [2/7]

 bool is_size ( ConstTensor3View x, const Index & p, const Index & r, const Index & c )

Verifies that the size of x is [p,r,c].

Parameters
 x The Tensor to check. p The desired number of pages. r The desired number of rows. c The desired number of columns.
Returns
True if the size of x is correct.

Definition at line 103 of file logic.cc.

◆ is_size() [3/7]

 bool is_size ( ConstTensor4View x, const Index & b, const Index & p, const Index & r, const Index & c )

Verifies that the size of x is [b,p,r,c].

Parameters
 x The Tensor to check. b The desired number of books. p The desired number of pages. r The desired number of rows. c The desired number of columns.
Returns
True if the size of x is correct.

Definition at line 119 of file logic.cc.

◆ is_size() [4/7]

 bool is_size ( ConstTensor5View x, const Index & s, const Index & b, const Index & p, const Index & r, const Index & c )

Verifies that the size of x is [s,b,p,r,c].

Parameters
 x The Tensor to check. s The desired number of shelves. b The desired number of books. p The desired number of pages. r The desired number of rows. c The desired number of columns.
Returns
True if the size of x is correct.

Definition at line 138 of file logic.cc.

◆ is_size() [5/7]

 bool is_size ( ConstTensor6View x, const Index & v, const Index & s, const Index & b, const Index & p, const Index & r, const Index & c )

Verifies that the size of x is [v,s,b,p,r,c].

Parameters
 x The Tensor to check. v The desired number of vitrines. s The desired number of shelves. b The desired number of books. p The desired number of pages. r The desired number of rows. c The desired number of columns.
Returns
True if the size of x is correct.

Definition at line 159 of file logic.cc.

◆ is_size() [6/7]

 bool is_size ( ConstTensor7View x, const Index & l, const Index & v, const Index & s, const Index & b, const Index & p, const Index & r, const Index & c )

Verifies that the size of x is [l,v,s,b,p,r,c].

Parameters
 x The Tensor to check. l The desired number of libraries. v The desired number of vitrines. s The desired number of shelves. b The desired number of books. p The desired number of pages. r The desired number of rows. c The desired number of columns.
Returns
True if the size of x is correct.

Definition at line 182 of file logic.cc.

◆ is_size() [7/7]

 bool is_size ( ConstVectorView x, const Index & n )

Verifies that the size of x is l.

This function is supposed to be used together with ARTS_ASSERT like this: ARTS_ASSERT(is_size(x,l))

Parameters
 x The Vector to check. n The desired length.
Returns
True if the size of x is l.

Definition at line 82 of file logic.cc.

References ConstVectorView::nelem().

◆ is_sorted()

 bool is_sorted ( ConstVectorView x )

Checks if a vector is sorted in ascending order.

Duplicated values are allowed.

Parameters
 x A vector.
Returns
True if sorted.

Definition at line 202 of file logic.cc.

References ConstVectorView::nelem().

◆ is_unique()

 bool is_unique ( const ArrayOfIndex & x )

Checks if an ArrayOfIndex is unique, i.e., has no duplicate values.

This only returns true if the array does not contain any duplicate values.

Returns
True if unique, otherwise false.
Parameters
 x An ArrayOfIndex.
Date
2008-08-24

Definition at line 277 of file logic.cc.

References Array< base >::nelem().