ARTS  2.2.66
quantum.cc
Go to the documentation of this file.
1 /* Copyright (C) 2013
2  Oliver Lemke <olemke@core-dump.info>
3 
4  This program is free software; you can redistribute it and/or modify it
5  under the terms of the GNU General Public License as published by the
6  Free Software Foundation; either version 2, or (at your option) any
7  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,
17  USA. */
18 
25 #include "quantum.h"
26 
27 #include <stdexcept>
28 #include "mystring.h"
29 
30 
32 {
33  const QuantumContainer& qnumbers2 = qn.GetNumbers();
34 
35  bool match = true;
36 
37  QuantumContainer::const_iterator qnr1it = mqnumbers.begin();
38  QuantumContainer::const_iterator qnr2it;
39 
40  // Loop over all quantum numbers in mqnumbers and use their keys
41  // to find the corresponding numbers in qnumbers2
42  while (match && qnr1it != mqnumbers.end())
43  {
44  qnr2it = qnumbers2.find(qnr1it->first);
45 
46  // If one of the two numbers is undefined, it is considered as
47  // a match.
48  if (qnr2it != qnumbers2.end()
49  && !(qnr1it->second).isUndefined()
50  && !(qnr2it->second).isUndefined()
51  && qnr1it->second != qnr2it->second)
52  match = false;
53 
54  qnr1it++;
55  }
56 
57  return match;
58 }
59 
60 std::istream& operator>>(std::istream& is, QuantumNumbers& qn)
61 {
62  String name;
63  Rational r;
64 
65  is >> name >> r;
66 
67  // Define a helper macro to save some typing.
68 #define INPUT_QUANTUM(ID) \
69  if (name == #ID) qn.Set(QN_ ## ID, r)
70 
71  INPUT_QUANTUM(J);
72  else INPUT_QUANTUM(N);
73  else INPUT_QUANTUM(S);
74  else INPUT_QUANTUM(F);
75  else INPUT_QUANTUM(Omega);
76  else INPUT_QUANTUM(K1);
77  else INPUT_QUANTUM(K2);
78  else INPUT_QUANTUM(v1);
79  else INPUT_QUANTUM(v2);
80  else INPUT_QUANTUM(v3);
81  else
82  {
83  std::ostringstream os;
84  os << "Unknown quantum number: " << name << " (" << r << ").";
85  throw std::runtime_error(os.str());
86  }
87 
88 #undef INPUT_QUANTUM
89 
90  return is;
91 }
92 
93 std::ostream& operator<<(std::ostream& os, const QuantumNumbers& qn)
94 {
95  bool first = true;
96  // Define a helper macro to save some typing.
97 #define OUTPUT_QUANTUM(ID) \
98  if (!qn[QN_ ## ID].isUndefined()) \
99  { if (!first) os << " "; first = false; os << #ID << " " << qn[QN_ ## ID]; }
100 
101  OUTPUT_QUANTUM(J);
102  OUTPUT_QUANTUM(N);
103  OUTPUT_QUANTUM(S);
104  OUTPUT_QUANTUM(F);
105  OUTPUT_QUANTUM(Omega);
106  OUTPUT_QUANTUM(K1);
107  OUTPUT_QUANTUM(K2);
108  OUTPUT_QUANTUM(v1);
109  OUTPUT_QUANTUM(v2);
110  OUTPUT_QUANTUM(v3);
111 
112 #undef OUTPUT_QUANTUM
113 
114  return os;
115 }
116 
117 std::ostream& operator<<(std::ostream& os, const QuantumNumberRecord& qr)
118 {
119  os << "Upper: " << qr.Upper() << " ";
120  os << "Lower: " << qr.Lower();
121 
122  return os;
123 }
124 
QuantumNumbers
Container class for Quantum Numbers.
Definition: quantum.h:58
QuantumNumbers::GetNumbers
const QuantumContainer & GetNumbers() const
Definition: quantum.h:75
QuantumNumbers::QuantumContainer
std::map< Index, Rational > QuantumContainer
Definition: quantum.h:60
QuantumNumberRecord::Upper
Rational Upper(Index i) const
Get upper quantum number.
Definition: quantum.h:106
OUTPUT_QUANTUM
#define OUTPUT_QUANTUM(ID)
quantum.h
Classes to handle quantum numbers.
QuantumNumberRecord::Lower
Rational Lower(Index i) const
Get lower quantum number.
Definition: quantum.h:103
my_basic_string
The implementation for String, the ARTS string class.
Definition: mystring.h:64
operator<<
std::ostream & operator<<(std::ostream &os, const QuantumNumbers &qn)
Definition: quantum.cc:93
N
#define N
Definition: rng.cc:195
QuantumNumbers::mqnumbers
QuantumContainer mqnumbers
Definition: quantum.h:88
operator>>
std::istream & operator>>(std::istream &is, QuantumNumbers &qn)
Definition: quantum.cc:60
QuantumNumberRecord
Record containing upper and lower quantum numbers.
Definition: quantum.h:94
QuantumNumbers::Compare
bool Compare(const QuantumNumbers &qn) const
Compare Quantum Numbers.
Definition: quantum.cc:31
INPUT_QUANTUM
#define INPUT_QUANTUM(ID)
Rational
Definition: rational.h:35
mystring.h
This file contains the definition of String, the ARTS string class.