Kstars

ekos.cpp
1/*
2 SPDX-FileCopyrightText: 2017 Jasem Mutlaq <mutlaqja@ikarustech.com>
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
16namespace Ekos
17{
18const QString getGuideStatusString(GuideState state, bool translated)
19{
20 return translated ? guideStates[state].toString() : guideStates[state].untranslatedText();
21}
22const QString getCaptureStatusString(CaptureState state, bool translated)
23{
24 return translated ? captureStates[state].toString() : captureStates[state].untranslatedText();
25}
26const QString getFocusStatusString(FocusState state, bool translated)
27{
28 return translated ? focusStates[state].toString() : focusStates[state].untranslatedText();
29}
30const QString getAlignStatusString(AlignState state, bool translated)
31{
32 return translated ? alignStates[state].toString() : alignStates[state].untranslatedText();
33}
34const QString getFilterStatusString(FilterState state, bool translated)
35{
36 return translated ? filterStates[state].toString() : filterStates[state].untranslatedText();
37}
38const QString getSchedulerStatusString(SchedulerState state, bool translated)
39{
40 return translated ? schedulerStates[state].toString() : schedulerStates[state].untranslatedText();
41}
42const QString getExtensionStatusString(ExtensionState state, bool translated)
43{
44 return translated ? extensionStates[state].toString() : extensionStates[state].untranslatedText();
45}
46
47/* Taken from https://codereview.stackexchange.com/questions/71300/wrapper-function-to-do-polynomial-fits-with-gsl */
48std::vector<double> gsl_polynomial_fit(const double *const data_x, const double *const data_y, const int n,
49 const int order, double &chisq)
50{
51 int status = 0;
52 std::vector<double> vc;
53 gsl_vector *y, *c;
54 gsl_matrix *X, *cov;
55 y = gsl_vector_alloc(n);
56 c = gsl_vector_alloc(order + 1);
57 X = gsl_matrix_alloc(n, order + 1);
58 cov = gsl_matrix_alloc(order + 1, order + 1);
59
60 for (int i = 0; i < n; i++)
61 {
62 for (int j = 0; j < order + 1; j++)
63 {
64 gsl_matrix_set(X, i, j, pow(data_x[i], j));
65 }
66 gsl_vector_set(y, i, data_y[i]);
67 }
68
69 // Must turn off error handler or it aborts on error
70 gsl_set_error_handler_off();
71
72 gsl_multifit_linear_workspace *work = gsl_multifit_linear_alloc(n, order + 1);
73 status = gsl_multifit_linear(X, y, c, cov, &chisq, work);
74
75 if (status != GSL_SUCCESS)
76 {
77 qDebug() << Q_FUNC_INFO << "GSL multifit error:" << gsl_strerror(status);
78 return vc;
79 }
80
81 gsl_multifit_linear_free(work);
82
83 for (int i = 0; i < order + 1; i++)
84 {
85 vc.push_back(gsl_vector_get(c, i));
86 }
87
88 gsl_vector_free(y);
89 gsl_vector_free(c);
90 gsl_matrix_free(X);
91 gsl_matrix_free(cov);
92
93 return vc;
94}
95}
96
97QDBusArgument &operator<<(QDBusArgument &argument, const Ekos::CommunicationStatus &source)
98{
99 argument.beginStructure();
100 argument << static_cast<int>(source);
101 argument.endStructure();
102 return argument;
103}
104
105const QDBusArgument &operator>>(const QDBusArgument &argument, Ekos::CommunicationStatus &dest)
106{
107 int a;
108 argument.beginStructure();
109 argument >> a;
110 argument.endStructure();
111 dest = static_cast<Ekos::CommunicationStatus>(a);
112 return argument;
113}
114
116{
117 argument.beginStructure();
118 argument << static_cast<int>(source);
119 argument.endStructure();
120 return argument;
121}
122
123const QDBusArgument &operator>>(const QDBusArgument &argument, Ekos::CaptureState &dest)
124{
125 int a;
126 argument.beginStructure();
127 argument >> a;
128 argument.endStructure();
129 dest = static_cast<Ekos::CaptureState>(a);
130 return argument;
131}
132
133QDBusArgument &operator<<(QDBusArgument &argument, const Ekos::FocusState &source)
134{
135 argument.beginStructure();
136 argument << static_cast<int>(source);
137 argument.endStructure();
138 return argument;
139}
140
141const QDBusArgument &operator>>(const QDBusArgument &argument, Ekos::FocusState &dest)
142{
143 int a;
144 argument.beginStructure();
145 argument >> a;
146 argument.endStructure();
147 dest = static_cast<Ekos::FocusState>(a);
148 return argument;
149}
150
151QDBusArgument &operator<<(QDBusArgument &argument, const Ekos::GuideState &source)
152{
153 argument.beginStructure();
154 argument << static_cast<int>(source);
155 argument.endStructure();
156 return argument;
157}
158
159const QDBusArgument &operator>>(const QDBusArgument &argument, Ekos::GuideState &dest)
160{
161 int a;
162 argument.beginStructure();
163 argument >> a;
164 argument.endStructure();
165 dest = static_cast<Ekos::GuideState>(a);
166 return argument;
167}
168
170{
171 argument.beginStructure();
172 argument << static_cast<int>(source);
173 argument.endStructure();
174 return argument;
175}
176
177const QDBusArgument &operator>>(const QDBusArgument &argument, Ekos::AlignState &dest)
178{
179 int a;
180 argument.beginStructure();
181 argument >> a;
182 argument.endStructure();
183 dest = static_cast<Ekos::AlignState>(a);
184 return argument;
185}
186
187QDBusArgument &operator<<(QDBusArgument &argument, const Ekos::SchedulerState &source)
188{
189 argument.beginStructure();
190 argument << static_cast<int>(source);
191 argument.endStructure();
192 return argument;
193}
194
195const QDBusArgument &operator>>(const QDBusArgument &argument, Ekos::SchedulerState &dest)
196{
197 int a;
198 argument.beginStructure();
199 argument >> a;
200 argument.endStructure();
201 dest = static_cast<Ekos::SchedulerState>(a);
202 return argument;
203}
204
205QDBusArgument &operator<<(QDBusArgument &argument, const Ekos::ExtensionState &source)
206{
207 argument.beginStructure();
208 argument << static_cast<int>(source);
209 argument.endStructure();
210 return argument;
211}
212
213const QDBusArgument &operator>>(const QDBusArgument &argument, Ekos::ExtensionState &dest)
214{
215 int a;
216 argument.beginStructure();
217 argument >> a;
218 argument.endStructure();
219 dest = static_cast<Ekos::ExtensionState>(a);
220 return argument;
221}
The SchedulerState class holds all attributes defining the scheduler's state.
Ekos is an advanced Astrophotography tool for Linux.
Definition align.cpp:83
AlignState
Definition ekos.h:145
CaptureState
Capture states.
Definition ekos.h:92
KCALENDARCORE_EXPORT QDataStream & operator>>(QDataStream &in, const KCalendarCore::Alarm::Ptr &)
KCALENDARCORE_EXPORT QDataStream & operator<<(QDataStream &out, const KCalendarCore::Alarm::Ptr &)
NETWORKMANAGERQT_EXPORT NetworkManager::Status status()
void beginStructure()
void endStructure()
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 4 2024 16:38:42 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.