nec2++ 2.1.1
BaseInput.h
1/*
2 Copyright (C) 2004 Timothy C.A. Molteno
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17*/
18#pragma once
19
20#include "math_util.h"
21
22#include <fstream>
23#include <sstream>
24
25nec_float diff(nec_float a, nec_float b)
26{
27 if (a == b)
28 return 0;
29 if ((a < 1e-8) && (b < 1e-8))
30 return 0;
31
32 nec_float sub = a - b;
33 nec_float sum = a + b;
34
35 nec_float ret = sub*sub;
36 if ((a != 0) && (b != 0))
37 ret /= sum*sum;
38 ret = sqrt(ret);
39 if (ret > 1e-2)
40 {
41 cout << " diff(" << a << "," << b << ") = " << ret << endl;
42 }
43 return ret;
44}
45
46nec_float diff(nec_complex a, nec_complex b)
47{
48 if (a == b)
49 return 0;
50 if ((abs(a) < 1e-8) && (abs(b) < 1e-8))
51 return 0;
52
53 nec_float ret = norm(a - b);
54 nec_float sum = norm(a + b);
55
56 if (sum != 0)
57 ret /= sum;
58
59 ret = sqrt(ret);
60 if (ret > 1e-2)
61 {
62 stringstream ss;
63 cout << " diff(" << a << "," << b << ") = " << ret << endl;
64 }
65 return ret;
66}
67
69{
70public:
71 BaseInput(const std::string& filename)
72 : m_filename(filename),
73 m_stream(filename.c_str())
74 {
75 }
76
77private:
78 char linec[512];
79
80
81protected:
82
83 std::string m_filename;
84 std::ifstream m_stream;
85
86 string readline()
87 {
88 m_stream.getline(&linec[0],512);
89 return string(&linec[0]);
90 }
91
92 double read_sci(std::istream& is)
93 {
94 double x;
95 is.setf(ios_base::skipws);
96 is >> x;
97 return x;
98 }
99
100 double read_fixed(std::istream& is)
101 {
102 double x;
103 is.setf(ios_base::skipws);
104 is >> x;
105 return x;
106 }
107};
Definition BaseInput.h:69