Документ взят из кэша поисковой машины. Адрес оригинального документа : http://www.apo.nmsu.edu/Telescopes/TCC/html/tel_mod_8cc_source.html
Дата изменения: Tue Sep 15 02:25:38 2015
Дата индексирования: Sun Apr 10 01:06:20 2016
Кодировка:

Поисковые слова: р п р п р п р п р п р п р п р п р п р п р п
lsst.tcc: src/telMod.cc Source File
lsst.tcc  1.2.2-3-g89ecb63
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
telMod.cc
Go to the documentation of this file.
1 /*
2 * Pointing model block
3 */
4 #include <cstdio>
5 #include <iomanip>
6 #include <sstream>
7 #include <stdexcept>
8 #include "coordConv/physConst.h"
9 #include "tcc/telMod.h"
10 
11 const float RadPerArcsec = coordConv::RadPerDeg / coordConv::ArcsecPerDeg;
12 
13 #define MaxTermNameLen 9 /* maximum term name length */
14 
15 namespace tcc {
16 
17  void TelMod::init() {
18  int errCode = tcsMinit(&_model);
19  if (errCode == 0) {
20  return;
21  } else if (errCode == 1) {
22  throw std::runtime_error("Insufficient room for all terms");
23  }
24  throw std::runtime_error("Unknown error");
25  }
26 
27  void TelMod::loadPath(std::string const &filePath) {
28  init();
29  int retVal = tcsIntpm(filePath.c_str(), &_model);
30  if (retVal == 0) {
31  return;
32  } else if (retVal == -1) {
33  throw std::runtime_error("Unable to initialize model");
34  } else if (retVal == -2) {
35  throw std::runtime_error("Unable to open input file");
36  } else if (retVal == -3) {
37  throw std::runtime_error("I/O error or premature EOF");
38  } else if (retVal == -4) {
39  throw std::runtime_error("Unrecognized record");
40  } else if (retVal == -5) {
41  throw std::runtime_error("Unable to add term to model");
42  }
43  throw std::runtime_error("Unknown error");
44  }
45 
47  std::string const &termName,
48  double termValue
49  ) {
50  if (termName.size() > MaxTermNameLen) {
51  throw std::runtime_error("Invalid term name: too long");
52  }
53  int retVal = tcsAddtrm(termName.c_str(), termValue * RadPerArcsec, &_model);
54  if (retVal > 0) {
55  return retVal;
56  } else if (retVal == -2) {
57  throw std::runtime_error("No room left in model");
58  } else if (retVal == -1) {
59  throw std::runtime_error("Unrecognized term");
60  } else if (retVal == 0) {
61  throw std::runtime_error("No room in repertoire for new generic term");
62  }
63  throw std::runtime_error("Unknown error");
64  }
65 
66  int TelMod::getNumTerms() const {
67  for (int i = 0; i < MAXTRM; ++i) {
68  if (!_model.model[i]) {
69  return i;
70  }
71  }
72  return MAXTRM;
73  }
74 
75  std::vector<std::string> TelMod::getTermNames() const {
76  std::vector<std::string> termNames;
77  for (int i = 0; i < MAXTRM; ++i) {
78  int termInd = _model.model[i] - 1;
79  if (termInd < 0) break;
80  termNames.push_back(_model.coeffn[termInd]);
81  }
82  return termNames;
83  }
84 
86  std::string const &termName
87  ) const {
88  if (termName.size() > MaxTermNameLen) {
89  throw std::runtime_error("Invalid term name: too long");
90  }
91  int coeffInd;
92  double coeffVal;
93  int retVal = tcsQnatrm(
94  const_cast<char *>(termName.c_str()),
95  const_cast<TPMOD *>(&_model),
96  &coeffVal,
97  &coeffInd
98  );
99  if (retVal != 0) {
100  throw std::runtime_error("Term not found in model");
101  }
102  return coeffVal / RadPerArcsec;
103  }
104 
106  std::string const &termName,
107  double termValue
108  ) {
109 
110  int retVal = tcsSterm(termName.c_str(), termValue * RadPerArcsec, &_model);
111  if (retVal == 0) {
112  return;
113  } else if (retVal == -1) {
114  throw std::runtime_error("Term not found in model");
115  }
116  throw std::runtime_error("Unknown error");
117  }
118 
119  std::string TelMod::__repr__() {
120  std::ostringstream os;
121  os << *this;
122  return os.str();
123  }
124 
125  std::ostream &operator<<(std::ostream &os, TelMod const &telMod) {
126  std::vector<std::string> termNames = telMod.getTermNames();
127 
128  std::ios_base::fmtflags f = os.flags(std::ios::right | std::ios::fixed | std::ios::showpos);
129  std::streamsize p = os.precision(4);
130  try {
131  os << "# TelMod telescope pointing model" << std::endl;
132  os << "# (the first two lines are ignored)" << std::endl;
133  for (std::vector<std::string>::const_iterator nameIter = termNames.begin(); nameIter != termNames.end(); ++nameIter) {
134  double val = telMod.getTerm(*nameIter);
135  os << " " << std::setw(9) << std::setiosflags(std::ios::right) << *nameIter
136  << std::setw(9) << val << std::setiosflags(std::ios::left) << std::endl;
137  }
138  os << "END" << std::endl;
139  os.flags(f);
140  os.precision(p);
141  } catch (...) {
142  os.flags(f);
143  os.precision(p);
144  throw;
145  }
146  return os;
147  }
148 
149 }
TPMOD _model
Definition: telMod.h:142
std::string __repr__()
Definition: telMod.cc:119
int getNumTerms() const
Definition: telMod.cc:66
#define MaxTermNameLen
Definition: telMod.cc:13
void setTerm(std::string const &termName, double termValue)
Definition: telMod.cc:105
const float RadPerArcsec
Definition: telMod.cc:11
double getTerm(std::string const &termName) const
Definition: telMod.cc:85
std::ostream & operator<<(std::ostream &os, ChebyshevPolynomial const &cheby)
Definition: cheby.cc:12
std::vector< std::string > getTermNames() const
Definition: telMod.cc:75
int addTerm(std::string const &termName, double termValue)
Definition: telMod.cc:46
void loadPath(std::string const &filePath)
Definition: telMod.cc:27
void init()
Definition: telMod.cc:17