ARTS  2.4.0(git:4fb77825)
groups.cc
Go to the documentation of this file.
1 /* Copyright (C) 2000-2012
2  Stefan Buehler <sbuehler@ltu.se>
3  Patrick Eriksson <patrick.eriksson@chalmers.se>
4 
5  This program is free software; you can redistribute it and/or modify it
6  under the terms of the GNU General Public License as published by the
7  Free Software Foundation; either version 2, or (at your option) any
8  later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program; if not, write to the Free Software
17  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
18  USA. */
19 
31 #include <map>
32 #include "array.h"
33 #include "arts.h"
34 #include "mystring.h"
35 #include "wsv_aux.h"
36 
39 namespace global_data {
41 map<String, Index> WsvGroupMap;
42 } // namespace global_data
43 
46 
48  valid_keyword_groups.resize(0);
49  valid_keyword_groups.push_back(get_wsv_group_id("String"));
50  valid_keyword_groups.push_back(get_wsv_group_id("Index"));
51  valid_keyword_groups.push_back(get_wsv_group_id("Numeric"));
52  valid_keyword_groups.push_back(get_wsv_group_id("ArrayOfString"));
53  valid_keyword_groups.push_back(get_wsv_group_id("ArrayOfIndex"));
54  valid_keyword_groups.push_back(get_wsv_group_id("Vector"));
55 }
56 
60  for (Index i = 0; i < wsv_group_names.nelem(); ++i) {
62  }
63 }
64 
66 
79 
80  //--------------------< Build the group names array >--------------------
81  // Initialize to empty, just in case.
82  wsv_group_names.resize(0);
83 
84  wsv_group_names.push_back("AbsorptionLines");
85  wsv_group_names.push_back("Agenda");
86  wsv_group_names.push_back("Any");
87  wsv_group_names.push_back("ArrayOfAbsorptionLines");
88  wsv_group_names.push_back("ArrayOfArrayOfAbsorptionLines");
89  wsv_group_names.push_back("ArrayOfAgenda");
90  wsv_group_names.push_back("ArrayOfArrayOfGriddedField1");
91  wsv_group_names.push_back("ArrayOfArrayOfGriddedField2");
92  wsv_group_names.push_back("ArrayOfArrayOfGriddedField3");
93  wsv_group_names.push_back("ArrayOfArrayOfIndex");
94  wsv_group_names.push_back("ArrayOfArrayOfMatrix");
95  wsv_group_names.push_back("ArrayOfPpath");
96  wsv_group_names.push_back("ArrayOfArrayOfPropagationMatrix");
97  wsv_group_names.push_back("ArrayOfArrayOfRadiationVector");
98  wsv_group_names.push_back("ArrayOfArrayOfScatteringMetaData");
99  wsv_group_names.push_back("ArrayOfArrayOfSingleScatteringData");
100  wsv_group_names.push_back("ArrayOfArrayOfSpeciesTag");
101  wsv_group_names.push_back("ArrayOfArrayOfStokesVector");
102  wsv_group_names.push_back("ArrayOfArrayOfString");
103  wsv_group_names.push_back("ArrayOfArrayOfTensor3");
104  wsv_group_names.push_back("ArrayOfArrayOfTensor6");
105  wsv_group_names.push_back("ArrayOfArrayOfTime");
106  wsv_group_names.push_back("ArrayOfArrayOfTransmissionMatrix");
107  wsv_group_names.push_back("ArrayOfArrayOfVector");
108  wsv_group_names.push_back("ArrayOfCIARecord");
109  wsv_group_names.push_back("ArrayOfGriddedField1");
110  wsv_group_names.push_back("ArrayOfGriddedField2");
111  wsv_group_names.push_back("ArrayOfGriddedField3");
112  wsv_group_names.push_back("ArrayOfGriddedField4");
113  wsv_group_names.push_back("ArrayOfIndex");
114  wsv_group_names.push_back("ArrayOfMatrix");
115  wsv_group_names.push_back("ArrayOfPropagationMatrix");
116  wsv_group_names.push_back("ArrayOfQuantumIdentifier");
117  wsv_group_names.push_back("ArrayOfRadiationVector");
118  wsv_group_names.push_back("ArrayOfRetrievalQuantity");
119  wsv_group_names.push_back("ArrayOfScatteringMetaData");
120  wsv_group_names.push_back("ArrayOfSingleScatteringData");
121  wsv_group_names.push_back("ArrayOfSparse");
122  wsv_group_names.push_back("ArrayOfStokesVector");
123  wsv_group_names.push_back("ArrayOfString");
124  wsv_group_names.push_back("ArrayOfTelsemAtlas");
125  wsv_group_names.push_back("ArrayOfTensor3");
126  wsv_group_names.push_back("ArrayOfTensor4");
127  wsv_group_names.push_back("ArrayOfTensor5");
128  wsv_group_names.push_back("ArrayOfTensor6");
129  wsv_group_names.push_back("ArrayOfTensor7");
130  wsv_group_names.push_back("ArrayOfTime");
131  wsv_group_names.push_back("ArrayOfTransmissionMatrix");
132  wsv_group_names.push_back("ArrayOfVector");
133  wsv_group_names.push_back("ArrayOfXsecRecord");
134  wsv_group_names.push_back("CIARecord");
135  wsv_group_names.push_back("CovarianceMatrix");
136  wsv_group_names.push_back("EnergyLevelMap");
137  wsv_group_names.push_back("GasAbsLookup");
138  wsv_group_names.push_back("GridPos");
139  wsv_group_names.push_back("GriddedField1");
140  wsv_group_names.push_back("GriddedField2");
141  wsv_group_names.push_back("GriddedField3");
142  wsv_group_names.push_back("GriddedField4");
143  wsv_group_names.push_back("GriddedField5");
144  wsv_group_names.push_back("GriddedField6");
145  wsv_group_names.push_back("HitranRelaxationMatrixData");
146  wsv_group_names.push_back("Index");
147  wsv_group_names.push_back("MCAntenna");
148  wsv_group_names.push_back("Matrix");
149  wsv_group_names.push_back("Numeric");
150  wsv_group_names.push_back("Ppath");
151  wsv_group_names.push_back("PropagationMatrix");
152  wsv_group_names.push_back("QuantumIdentifier");
153  wsv_group_names.push_back("RadiationVector");
154  wsv_group_names.push_back("Rational");
155  wsv_group_names.push_back("ScatteringMetaData");
156  wsv_group_names.push_back("SingleScatteringData");
157  wsv_group_names.push_back("Sparse");
158  wsv_group_names.push_back("SpeciesAuxData");
159  wsv_group_names.push_back("StokesVector");
160  wsv_group_names.push_back("String");
161  wsv_group_names.push_back("TelsemAtlas");
162  wsv_group_names.push_back("Tensor3");
163  wsv_group_names.push_back("Tensor4");
164  wsv_group_names.push_back("Tensor5");
165  wsv_group_names.push_back("Tensor6");
166  wsv_group_names.push_back("Tensor7");
167  wsv_group_names.push_back("Timer");
168  wsv_group_names.push_back("Time");
169  wsv_group_names.push_back("TessemNN");
170  wsv_group_names.push_back("TransmissionMatrix");
171  wsv_group_names.push_back("Vector");
172  wsv_group_names.push_back("Verbosity");
173 
176 }
177 
178 bool is_valid_keyword_group(const Index group) {
179  for (Index i = 0; i < valid_keyword_groups.nelem(); i++) {
180  if (valid_keyword_groups[i] == group) return true;
181  }
182 
183  return false;
184 }
185 
187  ids.resize(0);
188 
189  Index pos = 0;
190  while (pos < name.nelem()) {
191  switch (name[pos]) {
192  case ' ':
193  case '\r':
194  case '\t':
195  case '#':
196  name.erase(pos, 1);
197  break;
198  default:
199  pos++;
200  }
201  }
202 
203  pos = 0;
204  Index prev = 0;
205  while (pos < name.nelem()) {
206  while (pos < name.nelem() && name[pos] != ',') pos++;
207  Index id = get_wsv_group_id(name.substr(prev, pos - prev));
208  if (id == -1) {
209  ids.resize(0);
210  return;
211  }
212  ids.push_back(id);
213  pos++;
214  prev = pos;
215  }
216 }
217 
218 bool is_agenda_group_id(const Index group) {
219  return (group == get_wsv_group_id("Agenda") ||
220  group == get_wsv_group_id("ArrayOfAgenda"));
221 }
222 
225  map<String, Index>::const_iterator it = WsvGroupMap.find(name);
226  if (it == WsvGroupMap.end())
227  return -1;
228  else
229  return it->second;
230 }
231 
232 String get_array_groups_as_string(bool basetype_is_group,
233  bool return_basetype_only) {
235  String arraygroups;
236 
237  bool first = true;
238  for (Index i = 0; i < wsv_group_names.nelem(); i++) {
239  if (wsv_group_names[i].substr(0, String("ArrayOf").length()) == "ArrayOf") {
240  const String basetype = wsv_group_names[i].substr(
241  String("ArrayOf").length(), wsv_group_names[i].length());
242  bool basetype_exists = (get_wsv_group_id(basetype) != -1);
243 
244  if (return_basetype_only) {
245  // Return only the basetype of the array,
246  // skip arrays whose basetype is not a WSV group
247  if (basetype_exists) {
248  if (!first)
249  arraygroups += ", ";
250  else
251  first = false;
252  arraygroups += basetype;
253  }
254  } else {
255  if (!basetype_is_group || (basetype_is_group && basetype_exists)) {
256  if (!first)
257  arraygroups += ", ";
258  else
259  first = false;
260  arraygroups += wsv_group_names[i];
261  }
262  }
263  }
264  }
265  return arraygroups;
266 }
array.h
This file contains the definition of Array.
define_wsv_group_names
void define_wsv_group_names()
Define the array of workspace variable group names.
Definition: groups.cc:77
define_valid_keyword_groups
void define_valid_keyword_groups()
Definition: groups.cc:47
Array< String >
get_array_groups_as_string
String get_array_groups_as_string(bool basetype_is_group, bool return_basetype_only)
Return string list of array types.
Definition: groups.cc:232
my_basic_string< char >
define_wsv_group_map
void define_wsv_group_map()
Definition: groups.cc:57
get_wsv_group_ids
void get_wsv_group_ids(ArrayOfIndex &ids, String name)
Returns list of ids of the given group names.
Definition: groups.cc:186
is_agenda_group_id
bool is_agenda_group_id(const Index group)
Check if group is an agenda group.
Definition: groups.cc:218
is_valid_keyword_group
bool is_valid_keyword_group(const Index group)
Definition: groups.cc:178
global_data::WsvGroupMap
const map< String, Index > WsvGroupMap
The map associated with wsv_group_names.
Definition: groups.cc:41
my_basic_string::nelem
Index nelem() const
Number of elements.
Definition: mystring.h:246
global_data
Definition: agenda_record.cc:33
String
my_basic_string< char > String
The String type for ARTS.
Definition: mystring.h:280
Index
INDEX Index
The type to use for all integer numbers and indices.
Definition: matpack.h:39
global_data::wsv_group_names
const ArrayOfString wsv_group_names
The names associated with Wsv groups as Strings.
Definition: global_data.h:93
get_wsv_group_id
Index get_wsv_group_id(const String &name)
Returns the id of the given group.
Definition: groups.cc:223
valid_keyword_groups
ArrayOfIndex valid_keyword_groups
Definition: groups.cc:45
Array::nelem
Index nelem() const
Number of elements.
Definition: array.h:195
wsv_aux.h
Auxiliary header stuff related to workspace variable groups.
mystring.h
This file contains the definition of String, the ARTS string class.
arts.h
The global header file for ARTS.