ARTS  2.2.66
m_linemixing.cc
Go to the documentation of this file.
1 /* Copyright 2013, The ARTS Developers.
2  *
3  * This program is free software; you can redistribute it and/or modify it
4  * under the terms of the GNU General Public License as published by the
5  * Free Software Foundation; either version 2, or (at your option) any
6  * later version.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software Foundation,
15  * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16  */
17 
18 #include "arts.h"
19 #include "absorption.h"
20 #include "file.h"
21 #include "linemixingrecord.h"
22 
23 
24 /* Workspace method: Doxygen documentation will be auto-generated */
25 void line_mixing_dataInit(// WS Output:
26  ArrayOfArrayOfLineMixingRecord& line_mixing_data,
27  ArrayOfArrayOfIndex& line_mixing_data_lut,
28  // WS Input:
29  const ArrayOfArrayOfSpeciesTag& abs_species,
30  // Verbosity object:
31  const Verbosity&)
32 {
33  line_mixing_data.resize(abs_species.nelem());
34  line_mixing_data_lut.resize(abs_species.nelem());
35 }
36 
37 
38 /* Workspace method: Doxygen documentation will be auto-generated */
39 void line_mixing_dataMatch(// WS Output:
40  ArrayOfArrayOfLineMixingRecord& line_mixing_data,
41  ArrayOfArrayOfIndex& line_mixing_data_lut,
42  // WS Input:
43  const ArrayOfArrayOfLineRecord& abs_lines_per_species,
44  const ArrayOfArrayOfSpeciesTag& abs_species,
45  const String& species_tag,
46  const ArrayOfLineMixingRecord& line_mixing_records,
47  const Verbosity& verbosity)
48 {
51 
52  if (abs_species.nelem() != line_mixing_data.nelem())
53  throw runtime_error( "*line_mixing_data* doesn't match *abs_species*.\n"
54  "Make sure to call line_mixing_dataInit first." );
55  if (abs_species.nelem() != line_mixing_data_lut.nelem())
56  throw runtime_error( "*line_mixing_data_lut* doesn't match *abs_species*.\n"
57  "Make sure to call line_mixing_dataInit first." );
58 
59 
60  // Find index of species_tag in abs_species
61  SpeciesTag this_species( species_tag );
62  Index species_index = -1;
63  for (Index i = 0; species_index == -1 && i < abs_species.nelem(); i++)
64  // We only look at the first SpeciesTag in each group because
65  // line mixing tags can not be combined with other tags
66  if (this_species == abs_species[i][0])
67  species_index = i;
68 
69  if (species_index == -1)
70  {
71  ostringstream os;
72  os << "Can't find tag \"" << species_tag << "\" in *abs_species*.";
73  throw runtime_error(os.str());
74  }
75 
76  line_mixing_data[species_index] = line_mixing_records;
77 
78  ArrayOfIndex matches;
79  line_mixing_data_lut[species_index].resize(abs_lines_per_species[species_index].nelem());
80  line_mixing_data_lut[species_index] = -1;
81 
82  // Now we use the quantum numbers to match the line mixing
83  // data to lines in abs_lines_per_species
84  Index nmatches = 0;
85  for (Index i = 0; i < line_mixing_data[species_index].nelem(); i++)
86  {
87  const LineMixingRecord& this_lmr = line_mixing_data[species_index][i];
88  find_matching_lines(matches,
89  abs_lines_per_species[species_index],
90  this_lmr.Species(),
91  this_lmr.Isotopologue(),
92  this_lmr.Quantum());
93 
94  if (!matches.nelem())
95  {
96  out3 << " Found no matching lines for\n" << this_lmr.Quantum() << "\n";
97  }
98  else if (matches.nelem() == 1)
99  {
100  out3 << " Found matching line for\n" << this_lmr.Quantum() << "\n";
101  line_mixing_data_lut[species_index][matches[0]] = i;
102  nmatches++;
103  }
104  else
105  {
106  ostringstream os;
107  os << " Found multiple lines for\n" << this_lmr.Quantum() << endl
108  << " Matching lines are: " << endl;
109  for (Index m = 0; m < matches.nelem(); m++)
110  os << " " << abs_lines_per_species[species_index][matches[m]] << endl
111  << " " << abs_lines_per_species[species_index][matches[m]].QuantumNumbers()
112  << endl;
113  throw runtime_error(os.str());
114  }
115  }
116 
117  out2 << " Matched " << nmatches << " lines out of " << line_mixing_data[species_index].nelem()
118  << "\n";
119  out2 << " abs_lines_per_species contains " << abs_lines_per_species[species_index].nelem()
120  << " lines for " << species_tag << ".\n";
121 }
122 
123 
124 /* Workspace method: Doxygen documentation will be auto-generated */
125 void ArrayOfLineMixingRecordReadAscii(// Generic Output:
126  ArrayOfLineMixingRecord& line_mixing_records,
127  // Generic Input:
128  const String& filename,
129  const Verbosity& verbosity)
130 {
131  ifstream ifs;
132  open_input_file(ifs, filename);
133 
134  line_mixing_records.resize(0);
135 
136  // Read the line mixing file
137  Index linenr = 0;
138  String line;
139  istringstream is;
140  while (!ifs.eof())
141  {
142  getline(ifs, line);
143  linenr++;
144 
145  line.trim();
146  // Skip empty lines and comments
147  if (!line.nelem()
148  || (line.nelem() && line[0] == '#'))
149  continue;
150 
151  is.clear();
152  is.str(line);
153  try {
154  String species_string;
155  SpeciesTag line_species;
156 
157  is >> species_string;
158  line_species = SpeciesTag(species_string);
159 
160  LineMixingRecord lmr(line_species.Species(), line_species.Isotopologue());
161 
162  Rational r;
163  is >> r; lmr.Quantum().SetLower(QN_v1, r);
164  lmr.Quantum().SetUpper(QN_v1, r);
165  is >> r; lmr.Quantum().SetUpper(QN_N, r);
166  is >> r; lmr.Quantum().SetLower(QN_N, r);
167  is >> r; lmr.Quantum().SetUpper(QN_J, r);
168  is >> r; lmr.Quantum().SetLower(QN_J, r);
169 
170  vector<Numeric> temp_mixing_data;
171  String s;
172  char *c;
173  while (is.good() && is)
174  {
175  is >> s;
176  s.trim();
177  if (s.nelem())
178  {
179  temp_mixing_data.push_back(strtod(s.c_str(), &c));
180  if (c != s.c_str() + s.nelem())
181  throw runtime_error(line);
182  }
183  }
184 
185  lmr.Data() = temp_mixing_data;
186  line_mixing_records.push_back(lmr);
187  } catch (runtime_error e) {
188  ostringstream os;
189 
190  os << "Error parsing line mixing file in line " << linenr << endl;
191  os << e.what();
192  throw runtime_error(os.str());
193  }
194  }
195 
196  CREATE_OUT2;
197  out2 << " Read " << line_mixing_records.nelem() << " lines from " << filename << ".\n";
198 }
QN_J
@ QN_J
Definition: quantum.h:42
QuantumNumbers
Container class for Quantum Numbers.
Definition: quantum.h:58
LineMixingRecord::Data
Vector & Data()
Definition: linemixingrecord.h:45
find_matching_lines
bool find_matching_lines(ArrayOfIndex &matches, const ArrayOfLineRecord &abs_lines, const Index species, const Index isotopologue, const QuantumNumberRecord qr, const LineMatchingCriteria match_criteria)
Find lines matching the given criteria.
Definition: linerecord.cc:2631
absorption.h
Declarations required for the calculation of absorption coefficients.
QN_v1
@ QN_v1
Definition: quantum.h:49
line_mixing_dataInit
void line_mixing_dataInit(ArrayOfArrayOfLineMixingRecord &line_mixing_data, ArrayOfArrayOfIndex &line_mixing_data_lut, const ArrayOfArrayOfSpeciesTag &abs_species, const Verbosity &)
WORKSPACE METHOD: line_mixing_dataInit.
Definition: m_linemixing.cc:25
open_input_file
void open_input_file(ifstream &file, const String &name)
Open a file for reading.
Definition: file.cc:166
ArrayOfLineMixingRecordReadAscii
void ArrayOfLineMixingRecordReadAscii(ArrayOfLineMixingRecord &line_mixing_records, const String &filename, const Verbosity &verbosity)
WORKSPACE METHOD: ArrayOfLineMixingRecordReadAscii.
Definition: m_linemixing.cc:125
LineMixingRecord::Species
Index Species() const
Definition: linemixingrecord.h:39
CREATE_OUT2
#define CREATE_OUT2
Definition: messages.h:213
LineMixingRecord
Definition: linemixingrecord.h:34
LineMixingRecord::Quantum
QuantumNumberRecord & Quantum()
Definition: linemixingrecord.h:42
Array
This can be used to make arrays out of anything.
Definition: array.h:107
SpeciesTag
A tag group can consist of the sum of several of these.
Definition: abs_species_tags.h:46
LineMixingRecord::Isotopologue
Index Isotopologue() const
Definition: linemixingrecord.h:40
CREATE_OUT3
#define CREATE_OUT3
Definition: messages.h:214
my_basic_string
The implementation for String, the ARTS string class.
Definition: mystring.h:64
QN_N
@ QN_N
Definition: quantum.h:43
linemixingrecord.h
LineMixingRecord class for storing line mixing data.
Verbosity
Definition: messages.h:50
my_basic_string::trim
void trim()
Trim leading and trailing whitespace.
Definition: mystring.h:253
my_basic_string::nelem
Index nelem() const
Number of elements.
Definition: mystring.h:278
line_mixing_dataMatch
void line_mixing_dataMatch(ArrayOfArrayOfLineMixingRecord &line_mixing_data, ArrayOfArrayOfIndex &line_mixing_data_lut, const ArrayOfArrayOfLineRecord &abs_lines_per_species, const ArrayOfArrayOfSpeciesTag &abs_species, const String &species_tag, const ArrayOfLineMixingRecord &line_mixing_records, const Verbosity &verbosity)
WORKSPACE METHOD: line_mixing_dataMatch.
Definition: m_linemixing.cc:39
QuantumNumberRecord::SetLower
void SetLower(const Index i, const Rational r)
Set lower quantum number.
Definition: quantum.h:97
SpeciesTag::Isotopologue
Index Isotopologue() const
Isotopologue species index.
Definition: abs_species_tags.h:71
file.h
This file contains basic functions to handle ASCII files.
QuantumNumberRecord::SetUpper
void SetUpper(const Index i, const Rational r)
Set upper quantum number.
Definition: quantum.h:100
Index
INDEX Index
The type to use for all integer numbers and indices.
Definition: matpack.h:35
SpeciesTag::Species
Index Species() const
Molecular species index.
Definition: abs_species_tags.h:66
Array::nelem
Index nelem() const
Number of elements.
Definition: array.h:176
Rational
Definition: rational.h:35
arts.h
The global header file for ARTS.