ARTS  2.2.66
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 "arts.h"
33 #include "array.h"
34 #include "mystring.h"
35 #include "wsv_aux.h"
36 
37 
40 namespace global_data {
42 map<String, Index> WsvGroupMap;
43 }
44 
47 
48 
50 {
51  valid_keyword_groups.resize(0);
52  valid_keyword_groups.push_back(get_wsv_group_id("String"));
53  valid_keyword_groups.push_back(get_wsv_group_id("Index"));
54  valid_keyword_groups.push_back(get_wsv_group_id("Numeric"));
55  valid_keyword_groups.push_back(get_wsv_group_id("ArrayOfString"));
56  valid_keyword_groups.push_back(get_wsv_group_id("ArrayOfIndex"));
57  valid_keyword_groups.push_back(get_wsv_group_id("Vector"));
58 }
59 
60 
62 {
65  for ( Index i=0 ; i<wsv_group_names.nelem() ; ++i )
66  {
68  }
69 }
70 
71 
73 
85 {
87 
88  //--------------------< Build the group names array >--------------------
89  // Initialize to empty, just in case.
90  wsv_group_names.resize(0);
91 
92  wsv_group_names.push_back("Any");
93  wsv_group_names.push_back("Index");
94  wsv_group_names.push_back("Numeric");
95  wsv_group_names.push_back("String");
96  wsv_group_names.push_back("Vector");
97  wsv_group_names.push_back("Matrix");
98  wsv_group_names.push_back("Sparse");
99  wsv_group_names.push_back("Tensor3");
100  wsv_group_names.push_back("Tensor4");
101  wsv_group_names.push_back("Tensor5");
102  wsv_group_names.push_back("Tensor6");
103  wsv_group_names.push_back("Tensor7");
104  wsv_group_names.push_back("Timer");
105  wsv_group_names.push_back("Verbosity");
106  wsv_group_names.push_back("ArrayOfIndex");
107  wsv_group_names.push_back("ArrayOfArrayOfIndex");
108  wsv_group_names.push_back("ArrayOfString");
109  wsv_group_names.push_back("ArrayOfVector");
110  wsv_group_names.push_back("ArrayOfArrayOfVector");
111  wsv_group_names.push_back("ArrayOfMatrix");
112  wsv_group_names.push_back("ArrayOfArrayOfMatrix");
113  wsv_group_names.push_back("ArrayOfSparse");
114  wsv_group_names.push_back("ArrayOfTensor3");
115  wsv_group_names.push_back("ArrayOfArrayOfTensor3");
116  wsv_group_names.push_back("ArrayOfTensor4");
117  wsv_group_names.push_back("ArrayOfTensor6");
118  wsv_group_names.push_back("ArrayOfTensor7");
119  wsv_group_names.push_back("ArrayOfArrayOfTensor6");
120  wsv_group_names.push_back("ArrayOfLineMixingRecord");
121  wsv_group_names.push_back("ArrayOfLineRecord");
122  wsv_group_names.push_back("ArrayOfArrayOfLineRecord");
123  wsv_group_names.push_back("ArrayOfLineshapeSpec");
124  wsv_group_names.push_back("ArrayOfArrayOfSpeciesTag");
125  wsv_group_names.push_back("Ppath");
126  wsv_group_names.push_back("Agenda");
127  wsv_group_names.push_back("GridPos");
128  wsv_group_names.push_back("GasAbsLookup");
129  wsv_group_names.push_back("SingleScatteringData");
130  wsv_group_names.push_back("ArrayOfSingleScatteringData");
131  wsv_group_names.push_back("ScatteringMetaData");
132  wsv_group_names.push_back("ArrayOfScatteringMetaData");
133  wsv_group_names.push_back("GriddedField1");
134  wsv_group_names.push_back("GriddedField2");
135  wsv_group_names.push_back("GriddedField3");
136  wsv_group_names.push_back("GriddedField4");
137  wsv_group_names.push_back("GriddedField5");
138  wsv_group_names.push_back("GriddedField6");
139  wsv_group_names.push_back("ArrayOfGriddedField1");
140  wsv_group_names.push_back("ArrayOfGriddedField2");
141  wsv_group_names.push_back("ArrayOfGriddedField3");
142  wsv_group_names.push_back("ArrayOfGriddedField4");
143  wsv_group_names.push_back("ArrayOfArrayOfGriddedField1");
144  wsv_group_names.push_back("ArrayOfArrayOfGriddedField2");
145  wsv_group_names.push_back("ArrayOfArrayOfGriddedField3");
146  wsv_group_names.push_back("ArrayOfArrayOfLineMixingRecord");
147  wsv_group_names.push_back("ArrayOfRetrievalQuantity");
148  wsv_group_names.push_back("MCAntenna");
149  wsv_group_names.push_back("SpeciesAuxData");
150  wsv_group_names.push_back("ArrayOfCIARecord");
151 
154 }
155 
156 
157 bool is_valid_keyword_group(const Index group)
158 {
159  for (Index i = 0; i < valid_keyword_groups.nelem(); i++)
160  {
161  if (valid_keyword_groups[i] == group)
162  return true;
163  }
164 
165  return false;
166 }
167 
169 {
170  ids.resize(0);
171 
172  Index pos = 0;
173  while (pos < name.nelem())
174  {
175  switch (name[pos])
176  {
177  case ' ':
178  case '\r':
179  case '\t':
180  case '#':
181  name.erase(pos, 1);
182  break;
183  default:
184  pos++;
185  }
186  }
187 
188  pos = 0;
189  Index prev = 0;
190  while (pos < name.nelem())
191  {
192  while (pos < name.nelem() && name[pos] != ',') pos ++;
193  Index id = get_wsv_group_id (name.substr(prev, pos-prev));
194  if (id == -1)
195  {
196  ids.resize(0);
197  return;
198  }
199  ids.push_back (id);
200  pos++;
201  prev = pos;
202  }
203 }
204 
206 {
208  map<String, Index>::const_iterator it = WsvGroupMap.find (name);
209  if (it == WsvGroupMap.end())
210  return -1;
211  else
212  return it->second;
213 }
214 
215 String get_array_groups_as_string(bool basetype_is_group, bool return_basetype_only)
216 {
218  String arraygroups;
219 
220  bool first = true;
221  for (Index i = 0; i < wsv_group_names.nelem(); i++)
222  {
223  if (wsv_group_names[i].substr(0, String("ArrayOf").length()) == "ArrayOf")
224  {
225  const String basetype = wsv_group_names[i].substr(String("ArrayOf").length(),
226  wsv_group_names[i].length());
227  bool basetype_exists = (get_wsv_group_id(basetype) != -1);
228 
229  if (return_basetype_only)
230  {
231  // Return only the basetype of the array,
232  // skip arrays whose basetype is not a WSV group
233  if (basetype_exists)
234  {
235  if (!first) arraygroups += ", "; else first = false;
236  arraygroups += basetype;
237  }
238  }
239  else
240  {
241  if (!basetype_is_group || (basetype_is_group && basetype_exists))
242  {
243  if (!first) arraygroups += ", "; else first = false;
244  arraygroups += wsv_group_names[i];
245  }
246  }
247  }
248  }
249  return arraygroups;
250 }
Index get_wsv_group_id(const String &name)
Returns the id of the given group.
Definition: groups.cc:205
INDEX Index
The type to use for all integer numbers and indices.
Definition: matpack.h:35
Index nelem() const
Number of elements.
Definition: array.h:176
String get_array_groups_as_string(bool basetype_is_group, bool return_basetype_only)
Return string list of array types.
Definition: groups.cc:215
This file contains the definition of Array.
The implementation for String, the ARTS string class.
Definition: mystring.h:63
The global header file for ARTS.
bool is_valid_keyword_group(const Index group)
Definition: groups.cc:157
void get_wsv_group_ids(ArrayOfIndex &ids, String name)
Returns list of ids of the given group names.
Definition: groups.cc:168
void define_wsv_group_names()
Define the array of workspace variable group names.
Definition: groups.cc:84
void define_valid_keyword_groups()
Definition: groups.cc:49
void define_wsv_group_map()
Definition: groups.cc:61
Index nelem() const
Number of elements.
Definition: mystring.h:278
This can be used to make arrays out of anything.
Definition: array.h:40
const ArrayOfString wsv_group_names
The names associated with Wsv groups as Strings.
Definition: global_data.h:94
ArrayOfIndex valid_keyword_groups
Definition: groups.cc:46
const map< String, Index > WsvGroupMap
The map associated with wsv_group_names.
Definition: groups.cc:42
my_basic_string< char > String
The String type for ARTS.
Definition: mystring.h:318
This file contains the definition of String, the ARTS string class.
Auxiliary header stuff related to workspace variable groups.