Kstars

ekos.cpp
1 /*
2  SPDX-FileCopyrightText: 2017 Jasem Mutlaq <[email protected]>
3 
4  SPDX-License-Identifier: GPL-2.0-or-later
5 */
6 
7 #include "ekos.h"
8 
9 #include <gsl/gsl_fit.h>
10 #include <gsl/gsl_vector.h>
11 #include <gsl/gsl_matrix.h>
12 #include <gsl/gsl_multifit.h>
13 
14 #include <QDebug>
15 
16 namespace Ekos
17 {
18 const QString getGuideStatusString(GuideState state, bool translated)
19 {
20  return translated ? i18n(guideStates[state]) : guideStates[state];
21 }
22 const QString getCaptureStatusString(CaptureState state, bool translated)
23 {
24  return translated ? i18n(captureStates[state]) : captureStates[state];
25 }
26 const QString getFocusStatusString(FocusState state, bool translated)
27 {
28  return translated ? i18n(focusStates[state]) : focusStates[state];
29 }
30 const QString getAlignStatusString(AlignState state, bool translated)
31 {
32  return translated ? i18n(alignStates[state]) : alignStates[state];
33 }
34 const QString getFilterStatusString(FilterState state, bool translated)
35 {
36  return translated ? i18n(filterStates[state]) : filterStates[state];
37 }
38 const QString getSchedulerStatusString(FilterState state, bool translated)
39 {
40  return translated ? i18n(schedulerStates[state]) : schedulerStates[state];
41 }
42 
43 /* Taken from https://codereview.stackexchange.com/questions/71300/wrapper-function-to-do-polynomial-fits-with-gsl */
44 std::vector<double> gsl_polynomial_fit(const double *const data_x, const double *const data_y, const int n,
45  const int order, double &chisq)
46 {
47  int status = 0;
48  std::vector<double> vc;
49  gsl_vector *y, *c;
50  gsl_matrix *X, *cov;
51  y = gsl_vector_alloc(n);
52  c = gsl_vector_alloc(order + 1);
53  X = gsl_matrix_alloc(n, order + 1);
54  cov = gsl_matrix_alloc(order + 1, order + 1);
55 
56  for (int i = 0; i < n; i++)
57  {
58  for (int j = 0; j < order + 1; j++)
59  {
60  gsl_matrix_set(X, i, j, pow(data_x[i], j));
61  }
62  gsl_vector_set(y, i, data_y[i]);
63  }
64 
65  // Must turn off error handler or it aborts on error
66  gsl_set_error_handler_off();
67 
68  gsl_multifit_linear_workspace *work = gsl_multifit_linear_alloc(n, order + 1);
69  status = gsl_multifit_linear(X, y, c, cov, &chisq, work);
70 
71  if (status != GSL_SUCCESS)
72  {
73  qDebug() << Q_FUNC_INFO << "GSL multifit error:" << gsl_strerror(status);
74  return vc;
75  }
76 
77  gsl_multifit_linear_free(work);
78 
79  for (int i = 0; i < order + 1; i++)
80  {
81  vc.push_back(gsl_vector_get(c, i));
82  }
83 
84  gsl_vector_free(y);
85  gsl_vector_free(c);
86  gsl_matrix_free(X);
87  gsl_matrix_free(cov);
88 
89  return vc;
90 }
91 }
92 
93 QDBusArgument &operator<<(QDBusArgument &argument, const Ekos::CommunicationStatus &source)
94 {
95  argument.beginStructure();
96  argument << static_cast<int>(source);
97  argument.endStructure();
98  return argument;
99 }
100 
101 const QDBusArgument &operator>>(const QDBusArgument &argument, Ekos::CommunicationStatus &dest)
102 {
103  int a;
104  argument.beginStructure();
105  argument >> a;
106  argument.endStructure();
107  dest = static_cast<Ekos::CommunicationStatus>(a);
108  return argument;
109 }
110 
111 QDBusArgument &operator<<(QDBusArgument &argument, const Ekos::CaptureState &source)
112 {
113  argument.beginStructure();
114  argument << static_cast<int>(source);
115  argument.endStructure();
116  return argument;
117 }
118 
119 const QDBusArgument &operator>>(const QDBusArgument &argument, Ekos::CaptureState &dest)
120 {
121  int a;
122  argument.beginStructure();
123  argument >> a;
124  argument.endStructure();
125  dest = static_cast<Ekos::CaptureState>(a);
126  return argument;
127 }
128 
129 QDBusArgument &operator<<(QDBusArgument &argument, const Ekos::FocusState &source)
130 {
131  argument.beginStructure();
132  argument << static_cast<int>(source);
133  argument.endStructure();
134  return argument;
135 }
136 
137 const QDBusArgument &operator>>(const QDBusArgument &argument, Ekos::FocusState &dest)
138 {
139  int a;
140  argument.beginStructure();
141  argument >> a;
142  argument.endStructure();
143  dest = static_cast<Ekos::FocusState>(a);
144  return argument;
145 }
146 
147 QDBusArgument &operator<<(QDBusArgument &argument, const Ekos::GuideState &source)
148 {
149  argument.beginStructure();
150  argument << static_cast<int>(source);
151  argument.endStructure();
152  return argument;
153 }
154 
155 const QDBusArgument &operator>>(const QDBusArgument &argument, Ekos::GuideState &dest)
156 {
157  int a;
158  argument.beginStructure();
159  argument >> a;
160  argument.endStructure();
161  dest = static_cast<Ekos::GuideState>(a);
162  return argument;
163 }
164 
165 QDBusArgument &operator<<(QDBusArgument &argument, const Ekos::AlignState &source)
166 {
167  argument.beginStructure();
168  argument << static_cast<int>(source);
169  argument.endStructure();
170  return argument;
171 }
172 
173 const QDBusArgument &operator>>(const QDBusArgument &argument, Ekos::AlignState &dest)
174 {
175  int a;
176  argument.beginStructure();
177  argument >> a;
178  argument.endStructure();
179  dest = static_cast<Ekos::AlignState>(a);
180  return argument;
181 }
182 
183 QDBusArgument &operator<<(QDBusArgument &argument, const Ekos::SchedulerState &source)
184 {
185  argument.beginStructure();
186  argument << static_cast<int>(source);
187  argument.endStructure();
188  return argument;
189 }
190 
191 const QDBusArgument &operator>>(const QDBusArgument &argument, Ekos::SchedulerState &dest)
192 {
193  int a;
194  argument.beginStructure();
195  argument >> a;
196  argument.endStructure();
197  dest = static_cast<Ekos::SchedulerState>(a);
198  return argument;
199 }
Ekos is an advanced Astrophotography tool for Linux. It is based on a modular extensible framework to...
Definition: align.cpp:66
QString i18n(const char *text, const TYPE &arg...)
NETWORKMANAGERQT_EXPORT NetworkManager::Status status()
CaptureState
Capture states.
Definition: ekos.h:91
QDebug operator<<(QDebug d, const QCPVector2D &vec)
Definition: qcustomplot.h:450
void beginStructure()
void endStructure()
QDataStream & operator>>(QDataStream &in, KDateTime &dateTime)
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Fri Aug 19 2022 03:57:50 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.