Namelist.hpp
Go to the documentation of this file.
1 //==============================================================================
2 //
3 // This file is part of GNSSTk, the ARL:UT GNSS Toolkit.
4 //
5 // The GNSSTk is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU Lesser General Public License as published
7 // by the Free Software Foundation; either version 3.0 of the License, or
8 // any later version.
9 //
10 // The GNSSTk 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 Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public
16 // License along with GNSSTk; if not, write to the Free Software Foundation,
17 // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
18 //
19 // This software was developed by Applied Research Laboratories at the
20 // University of Texas at Austin.
21 // Copyright 2004-2022, The Board of Regents of The University of Texas System
22 //
23 //==============================================================================
24 
25 //==============================================================================
26 //
27 // This software was developed by Applied Research Laboratories at the
28 // University of Texas at Austin, under contract to an agency or agencies
29 // within the U.S. Department of Defense. The U.S. Government retains all
30 // rights to use, duplicate, distribute, disclose, or release this software.
31 //
32 // Pursuant to DoD Directive 523024
33 //
34 // DISTRIBUTION STATEMENT A: This software has been approved for public
35 // release, distribution is unlimited.
36 //
37 //==============================================================================
38 
48 #ifndef CLASS_NAMELIST_INCLUDE
49 #define CLASS_NAMELIST_INCLUDE
50 
51 //------------------------------------------------------------------------------------
52 // system includes
53 #include <algorithm>
54 #include <iomanip>
55 #include <ostream>
56 #include <sstream>
57 #include <string>
58 #include <vector>
59 // GNSSTk
60 #include "Matrix.hpp"
61 
62 namespace gnsstk
63 {
64 
65  //---------------------------------------------------------------------------------
66  class Namelist;
67 
86  {
87  public:
88  int wid;
89  int prec;
90  int form;
91  std::string msg;
92  std::string tag;
93  const Namelist &NL;
94  const Vector<double> &V;
95 
98  : wid(12), prec(5), form(1), NL(nl), V(v)
99  {
100  }
101 
104  {
105  wid = w;
106  return *this;
107  }
108 
111  {
112  prec = p;
113  return *this;
114  }
115 
118  {
119  form = 1;
120  return *this;
121  }
122 
125  {
126  form = 2;
127  return *this;
128  }
129 
131  LabeledVector& message(const std::string& m)
132  {
133  msg = m;
134  return *this;
135  }
136 
138  LabeledVector& linetag(const std::string& m)
139  {
140  tag = m;
141  return *this;
142  }
143  };
144 
163  {
164  public:
165  int wid;
166  int prec;
167  int form;
168  int rc;
169  bool sym;
170  bool cln;
171  std::string msg;
172  std::string tag;
173  const Namelist &NLrows;
174  const Namelist &NLcols;
176 
180  : sym(false), cln(false), wid(12), prec(5), form(1), rc(0), M(m),
181  NLrows(nl), NLcols(nl)
182  {
183  }
184 
187  LabeledMatrix(const Namelist& nr, const Namelist& nc,
188  const Matrix<double>& m)
189  : sym(false), cln(false), wid(12), prec(5), form(1), rc(0), M(m),
190  NLrows(nr), NLcols(nc)
191  {
192  }
193 
196  {
197  wid = w;
198  return *this;
199  }
200 
203  {
204  prec = p;
205  return *this;
206  }
207 
210  {
211  form = 1;
212  return *this;
213  }
214 
217  {
218  form = 2;
219  return *this;
220  }
221 
223  LabeledMatrix& symmetric(bool s = true)
224  {
225  sym = s;
226  return *this;
227  }
228 
230  LabeledMatrix& clean(bool s = true)
231  {
232  cln = s;
233  return *this;
234  }
235 
238  {
239  rc = 0;
240  return *this;
241  }
242 
245  {
246  rc = 1;
247  return *this;
248  }
249 
252  {
253  rc = 2;
254  return *this;
255  }
256 
258  LabeledMatrix& message(const std::string& m)
259  {
260  msg = m;
261  return *this;
262  }
263 
265  LabeledMatrix& linetag(const std::string& m)
266  {
267  tag = m;
268  return *this;
269  }
270  };
271 
273  std::ostream& operator<<(std::ostream& os, const LabeledMatrix& lm);
274 
276  std::ostream& operator<<(std::ostream& os, const LabeledVector& lv);
277 
278  //---------------------------------------------------------------------------------
287  class Namelist
288  {
289  friend class SRI;
290  friend std::ostream& operator<<(std::ostream& os, const LabeledMatrix& N);
291  friend std::ostream& operator<<(std::ostream& os, const LabeledVector& N);
292 
293  public:
295  Namelist() {}
296 
298  Namelist(const unsigned int& n);
299 
302  Namelist(const std::vector<std::string>& names);
303 
305  Namelist(const Namelist& names) { labels = names.labels; }
306 
308  ~Namelist() { labels.clear(); }
309 
311  Namelist& operator=(const Namelist& right)
312  {
313  labels = right.labels;
314  return *this;
315  }
316 
319  Namelist& operator+=(const std::string& name);
320 
322  Namelist& operator+=(const Namelist& right)
323  {
324  try
325  {
326  for (unsigned int i = 0; i < right.size(); i++)
327  this->operator+=(right.getName(i));
328  }
329  catch (gnsstk::Exception& e)
330  {
331  GNSSTK_RETHROW(e);
332  }
333  return *this;
334  }
335 
338  Namelist& operator-=(const std::string& name);
339 
342  void swap(const unsigned int& i, const unsigned int& j);
343 
345  void sort();
346 
348  void resize(unsigned int n);
349 
351  void randomize(long seed = 0);
352 
354  void clear() { labels.clear(); }
355 
357  bool valid() const;
358 
360  bool contains(const std::string& name) const;
361 
363  friend bool operator==(const Namelist& N1, const Namelist& N2);
364 
366  friend bool operator!=(const Namelist& N1, const Namelist& N2);
367 
369  friend bool identical(const Namelist& N1, const Namelist& N2);
370 
372  friend Namelist operator&(const Namelist& N1, const Namelist& N2);
373 
375  friend Namelist operator|(const Namelist& N1, const Namelist& N2);
376 
378  friend Namelist operator^(const Namelist& N1, const Namelist& N2);
379 
381  Namelist& operator&=(const Namelist& N);
382 
384  Namelist& operator|=(const Namelist& N);
385 
387  Namelist& operator^=(const Namelist& N);
388 
393  {
394  return LabeledMatrix(*this, m);
395  }
396 
401  {
402  return LabeledVector(*this, v);
403  }
404 
405  // member access
406 
408  inline unsigned int size() const { return labels.size(); }
409 
410  /* std::string& operator[](const unsigned int);
411  Don't do this, b/c it means user could create invalid Namelists,
412  and b/c passing an invalid int would require a throw
413  */
414 
418  std::string getName(const unsigned int in) const;
419 
424  bool setName(const unsigned int in, const std::string& name);
425 
429  int index(const std::string& name) const;
430 
432  friend std::ostream& operator<<(std::ostream& os, const Namelist& N);
433 
434  // member data
435 
437  std::vector<std::string> labels;
438 
439  }; // end class Namelist
440 
441 } // end of namespace gnsstk
442 
443 #endif
gnsstk::LabeledVector::NL
const Namelist & NL
Namelist of names.
Definition: Namelist.hpp:93
gnsstk::LabeledMatrix::scientific
LabeledMatrix & scientific()
Set the format to scientific.
Definition: Namelist.hpp:216
gnsstk::LabeledMatrix::sym
bool sym
if true, print only lower triangle
Definition: Namelist.hpp:169
gnsstk::Namelist::index
int index(const std::string &name) const
Definition: Namelist.cpp:530
gnsstk::Namelist::labels
std::vector< std::string > labels
vector of names (strings)
Definition: Namelist.hpp:437
gnsstk::LabeledMatrix::NLrows
const Namelist & NLrows
Namelist of rows.
Definition: Namelist.hpp:173
gnsstk::Namelist::clear
void clear()
empty the list
Definition: Namelist.hpp:354
gnsstk::Namelist::operator&
friend Namelist operator&(const Namelist &N1, const Namelist &N2)
construct the subset Namelist which is common to the two inputs (AND)
Definition: Namelist.cpp:357
gnsstk::LabeledMatrix::LabeledMatrix
LabeledMatrix(const Namelist &nr, const Namelist &nc, const Matrix< double > &m)
Definition: Namelist.hpp:187
gnsstk::LabeledMatrix::NLcols
const Namelist & NLcols
Namelist of columns.
Definition: Namelist.hpp:174
gnsstk::LabeledVector::fixed
LabeledVector & fixed()
Set the format to fixed.
Definition: Namelist.hpp:117
gnsstk::Namelist::contains
bool contains(const std::string &name) const
does the Namelist contain the input name?
Definition: Namelist.cpp:264
gnsstk::LabeledVector::scientific
LabeledVector & scientific()
Set the format to scientific.
Definition: Namelist.hpp:124
gnsstk::Namelist::resize
void resize(unsigned int n)
resize the list by either truncation or adding default names.
Definition: Namelist.cpp:187
gnsstk::Namelist::operator+=
Namelist & operator+=(const std::string &name)
Definition: Namelist.cpp:114
gnsstk::LabeledMatrix::both
LabeledMatrix & both()
Print labels on both rows and columns.
Definition: Namelist.hpp:237
gnsstk::LabeledVector::LabeledVector
LabeledVector(const Namelist &nl, const Vector< double > &v)
Constructor, defaults are width 12 prec 5 format fixed.
Definition: Namelist.hpp:97
gnsstk::LabeledMatrix::fixed
LabeledMatrix & fixed()
Set the format to fixed.
Definition: Namelist.hpp:209
gnsstk::Namelist::valid
bool valid() const
is the Namelist valid? checks for repeated names
Definition: Namelist.cpp:247
gnsstk::SRI
Definition: SRI.hpp:175
gnsstk::LabeledMatrix::cols
LabeledMatrix & cols()
Print labels on columns only.
Definition: Namelist.hpp:251
gnsstk::Namelist::sort
void sort()
reorder the list by sorting
Definition: Namelist.cpp:173
gnsstk::LabeledMatrix::form
int form
format: 1=fixed, 2=scientific
Definition: Namelist.hpp:167
gnsstk::LabeledVector::wid
int wid
width of fields, in characters
Definition: Namelist.hpp:88
gnsstk::LabeledVector
forward declaration
Definition: Namelist.hpp:85
gnsstk::Namelist::operator!=
friend bool operator!=(const Namelist &N1, const Namelist &N2)
are two Namelists different, ignoring permutations?
Definition: Namelist.cpp:318
gnsstk::Namelist::operator<<
friend std::ostream & operator<<(std::ostream &os, const LabeledMatrix &N)
output ostream operator for LabeledMatrix
Definition: Namelist.cpp:637
gnsstk::Namelist::operator^
friend Namelist operator^(const Namelist &N1, const Namelist &N2)
construct the subset Namelist which is NOT common to two others (XOR)
Definition: Namelist.cpp:387
gnsstk
For Sinex::InputHistory.
Definition: BasicFramework.cpp:50
gnsstk::Namelist::operator|=
Namelist & operator|=(const Namelist &N)
replace this with (this | input)
Definition: Namelist.cpp:425
gnsstk::Namelist::operator&=
Namelist & operator&=(const Namelist &N)
replace this with (this& input)
Definition: Namelist.cpp:402
gnsstk::Exception
Definition: Exception.hpp:151
gnsstk::LabeledVector::tag
std::string tag
text at beginning of each line (row)
Definition: Namelist.hpp:92
gnsstk::LabeledMatrix::setprecision
LabeledMatrix & setprecision(int p)
Set the precision to p digits.
Definition: Namelist.hpp:202
gnsstk::LabeledMatrix::msg
std::string msg
label (name in Namelist) for each row
Definition: Namelist.hpp:171
gnsstk::LabeledMatrix::LabeledMatrix
LabeledMatrix(const Namelist &nl, const Matrix< double > &m)
Definition: Namelist.hpp:179
gnsstk::Namelist::operator==
friend bool operator==(const Namelist &N1, const Namelist &N2)
are two Namelists identical, ignoring permutations?
Definition: Namelist.cpp:282
gnsstk::Matrix< double >
gnsstk::LabeledVector::setw
LabeledVector & setw(int w)
Set the width to w characters.
Definition: Namelist.hpp:103
gnsstk::operator<<
std::ostream & operator<<(std::ostream &s, const ObsEpoch &oe) noexcept
Definition: ObsEpochMap.cpp:54
gnsstk::LabeledVector::setprecision
LabeledVector & setprecision(int p)
Set the precision to p digits.
Definition: Namelist.hpp:110
nl
int nl
Definition: IERS1996NutationData.hpp:44
gnsstk::LabeledVector::message
LabeledVector & message(const std::string &m)
Set the label or name.
Definition: Namelist.hpp:131
gnsstk::Namelist::operator()
LabeledVector operator()(Vector< double > &v)
Definition: Namelist.hpp:400
gnsstk::Namelist::size
unsigned int size() const
return the size of the list.
Definition: Namelist.hpp:408
gnsstk::LabeledVector::msg
std::string msg
label (name in Namelist) for each row
Definition: Namelist.hpp:91
gnsstk::Namelist::operator|
friend Namelist operator|(const Namelist &N1, const Namelist &N2)
merge two Namelists, i.e. construct a non-redundant combination (OR)
Definition: Namelist.cpp:372
gnsstk::Namelist::operator^=
Namelist & operator^=(const Namelist &N)
replace this with (this ^ input)
Definition: Namelist.cpp:447
gnsstk::Namelist::getName
std::string getName(const unsigned int in) const
Definition: Namelist.cpp:485
gnsstk::Namelist::Namelist
Namelist()
empty constructor
Definition: Namelist.hpp:295
gnsstk::LabeledVector::linetag
LabeledVector & linetag(const std::string &m)
Set the tag.
Definition: Namelist.hpp:138
gnsstk::Namelist::Namelist
Namelist(const Namelist &names)
copy constructor
Definition: Namelist.hpp:305
GNSSTK_RETHROW
#define GNSSTK_RETHROW(exc)
Definition: Exception.hpp:369
gnsstk::Vector< double >
gnsstk::Namelist::operator=
Namelist & operator=(const Namelist &right)
operator=
Definition: Namelist.hpp:311
gnsstk::LabeledMatrix
Definition: Namelist.hpp:162
gnsstk::LabeledMatrix::M
const Matrix< double > & M
Matrix to print.
Definition: Namelist.hpp:175
gnsstk::LabeledMatrix::message
LabeledMatrix & message(const std::string &m)
Print the given message.
Definition: Namelist.hpp:258
gnsstk::LabeledMatrix::rc
int rc
label rows only (1) columns only (2) or both (0)
Definition: Namelist.hpp:168
gnsstk::Namelist::operator()
LabeledMatrix operator()(Matrix< double > &m)
Definition: Namelist.hpp:392
gnsstk::LabeledMatrix::clean
LabeledMatrix & clean(bool s=true)
If true, print 0.0 as 0.
Definition: Namelist.hpp:230
gnsstk::LabeledMatrix::symmetric
LabeledMatrix & symmetric(bool s=true)
If true, the matrix is symmetrical, so print only the lower triangle.
Definition: Namelist.hpp:223
gnsstk::Namelist::randomize
void randomize(long seed=0)
randomize the list
Definition: Namelist.cpp:220
gnsstk::LabeledMatrix::tag
std::string tag
text at beginning of each line (row)
Definition: Namelist.hpp:172
gnsstk::LabeledMatrix::rows
LabeledMatrix & rows()
Print labels on rows only.
Definition: Namelist.hpp:244
gnsstk::Namelist
Definition: Namelist.hpp:287
Matrix.hpp
gnsstk::Namelist::operator+=
Namelist & operator+=(const Namelist &right)
add entire Namelist to this using operator+=(string)
Definition: Namelist.hpp:322
gnsstk::LabeledMatrix::wid
int wid
width of fields, in characters
Definition: Namelist.hpp:165
gnsstk::LabeledVector::prec
int prec
precision of fixed, in digits
Definition: Namelist.hpp:89
gnsstk::Namelist::~Namelist
~Namelist()
destructor
Definition: Namelist.hpp:308
gnsstk::LabeledMatrix::prec
int prec
precision of fixed, in digits
Definition: Namelist.hpp:166
gnsstk::LabeledMatrix::linetag
LabeledMatrix & linetag(const std::string &m)
Print the given tag at the beginning of each line.
Definition: Namelist.hpp:265
gnsstk::Namelist::identical
friend bool identical(const Namelist &N1, const Namelist &N2)
are two Namelists exactly identical, even considering permutations?
Definition: Namelist.cpp:331
gnsstk::Namelist::swap
void swap(const unsigned int &i, const unsigned int &j)
Definition: Namelist.cpp:150
gnsstk::LabeledVector::V
const Vector< double > & V
Vector to print.
Definition: Namelist.hpp:94
gnsstk::LabeledMatrix::cln
bool cln
if true, print 0.0 as "0"
Definition: Namelist.hpp:170
gnsstk::LabeledVector::form
int form
format - 0=general, 1=fixed(default), 2=integer
Definition: Namelist.hpp:90
gnsstk::Namelist::setName
bool setName(const unsigned int in, const std::string &name)
Definition: Namelist.cpp:504
gnsstk::LabeledMatrix::setw
LabeledMatrix & setw(int w)
Set the width to w characters.
Definition: Namelist.hpp:195
gnsstk::Namelist::operator-=
Namelist & operator-=(const std::string &name)
Definition: Namelist.cpp:132


gnsstk
Author(s):
autogenerated on Wed Oct 25 2023 02:40:40