SigPack - the C++ signal processing library
 
Loading...
Searching...
No Matches
parser.cpp

Input

test.par

% Test parameter file
N = 150
my_text = "Hello"
pi_val=3.14151926
%un_def = 1
x = [0.25 ,0.5 ,0.25]
y = [0.25+0.1i ;0.5-1i ;0.25+0.3i]
A = [1,2,3;4,5,6;7,8,9;10, 11 ,12]
B = [0+1j,2-3i,3;4,5i,6+1i;7,8i,9;10, 11+3i ,12]

Output

SigPack: Parameter Z not found!
Setting default
1
2
3
4
my_text= Hello
N= 150
pi_val= 3.14152
x=
0.2500 0.5000 0.2500
y=
(+2.500e-01,+1.000e-01)
(+5.000e-01,-1.000e+00)
(+2.500e-01,+3.000e-01)
A=
1.0000 2.0000 3.0000
4.0000 5.0000 6.0000
7.0000 8.0000 9.0000
10.0000 11.0000 12.0000
B=
(+0.000e+00,+1.000e+00) (+2.000e+00,-3.000e+00)
(+3.000e+00,+0.000e+00)
(+4.000e+00,+0.000e+00) (+0.000e+00,+5.000e+00)
(+6.000e+00,+1.000e+00)
(+7.000e+00,+0.000e+00) (+0.000e+00,+8.000e+00)
(+9.000e+00,+0.000e+00)
(+1.000e+01,+0.000e+00) (+1.100e+01,+3.000e+00)
(+1.200e+01,+0.000e+00)
Z=
1
2
3
4

Source

#include "sigpack.h"
using namespace arma;
using namespace sp;
int main()
{
// Set defaults
rowvec def_vec = randu<rowvec>( 10 );
cx_vec def_vec_cx = randu<cx_vec>( 10 );
mat def_mat = randu<mat>( 5, 5 );
cx_mat def_matx = randu<cx_mat>( 5, 5 );
Col<int> def_vec_int;
def_vec_int << 1 << 2 << 3 << 4;
// Create parser
parser testpar( "test.par" );
rowvec x = testpar.getRow( "x", def_vec ); // Row vector
cx_vec y = testpar.getCxCol( "y", def_vec_cx ); // Col vector complex
mat A = testpar.getMat( "A", def_mat ); // Mat
cx_mat B = testpar.getCxMat( "B", def_matx ); // Mat complex
std::string my_text = testpar.getString( "my_text", "DEFAULT" ); // String
int N = testpar.getParam<int>( "N", 125000 ); // Int
double pi_val = testpar.getParam<double>( "pi_val", 3.1 ); // Double
Col<int> Z = testpar.getCol( "Z", def_vec_int ); // Col integer - false test
std::cout << "my_text= " << my_text << std::endl;
std::cout << "N= " << N << std::endl;
std::cout << "pi_val= " << pi_val << std::endl;
std::cout << "x= \n" << x << std::endl;
std::cout << "y= \n" << y << std::endl;
std::cout << "A= \n" << A << std::endl;
std::cout << "B= \n" << B << std::endl;
std::cout << "Z= \n" << Z << std::endl;
return 0;
}
int main()
A parser class.
Definition parser.h:21
std::string getString(const std::string key, const std::string def_val)
String type get function.
Definition parser.h:188
arma::Mat< T > getMat(const std::string key, const arma::Mat< T > def_val)
Mat type get function.
Definition parser.h:312
arma::cx_vec getCxCol(const std::string key, const arma::cx_vec def_val)
cx_vec type get function.
Definition parser.h:232
arma::Col< T > getCol(const std::string key, const arma::Col< T > def_val)
Col type get function.
Definition parser.h:204
arma::Row< T > getRow(const std::string key, const arma::Row< T > def_val)
Row type get function.
Definition parser.h:258
T getParam(const std::string key, const T def_val)
Generic type get function.
Definition parser.h:168
arma::cx_mat getCxMat(const std::string key, const arma::cx_mat def_val)
cx_mat type get function.
Definition parser.h:353
Definition base.h:8