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 ? i18n(guideStates[state]) : guideStates[state];
21}
22const QString getCaptureStatusString(CaptureState state, bool translated)
23{
24 return translated ? i18n(captureStates[state]) : captureStates[state];
25}
26const QString getFocusStatusString(FocusState state, bool translated)
27{
28 return translated ? i18n(focusStates[state]) : focusStates[state];
29}
30const QString getAlignStatusString(AlignState state, bool translated)
31{
32 return translated ? i18n(alignStates[state]) : alignStates[state];
33}
34const QString getFilterStatusString(FilterState state, bool translated)
35{
36 return translated ? i18n(filterStates[state]) : filterStates[state];
37}
38const QString getSchedulerStatusString(SchedulerState 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 */
44std::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
67
70
71 if (status != GSL_SUCCESS)
72 {
73 qDebug() << Q_FUNC_INFO << "GSL multifit error:" << gsl_strerror(status);
74 return vc;
75 }
76
78
79 for (int i = 0; i < order + 1; i++)
80 {
81 vc.push_back(gsl_vector_get(c, i));
82 }
83
88
89 return vc;
90}
91}
92
93QDBusArgument &operator<<(QDBusArgument &argument, const Ekos::CommunicationStatus &source)
94{
95 argument.beginStructure();
97 argument.endStructure();
98 return argument;
99}
100
101const 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
112{
113 argument.beginStructure();
115 argument.endStructure();
116 return argument;
117}
118
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
129QDBusArgument &operator<<(QDBusArgument &argument, const Ekos::FocusState &source)
130{
131 argument.beginStructure();
133 argument.endStructure();
134 return argument;
135}
136
137const 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
147QDBusArgument &operator<<(QDBusArgument &argument, const Ekos::GuideState &source)
148{
149 argument.beginStructure();
151 argument.endStructure();
152 return argument;
153}
154
155const 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
166{
167 argument.beginStructure();
169 argument.endStructure();
170 return argument;
171}
172
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
183QDBusArgument &operator<<(QDBusArgument &argument, const Ekos::SchedulerState &source)
184{
185 argument.beginStructure();
187 argument.endStructure();
188 return argument;
189}
190
191const 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}
The SchedulerState class holds all attributes defining the scheduler's state.
QString i18n(const char *text, const TYPE &arg...)
Ekos is an advanced Astrophotography tool for Linux.
Definition align.cpp:78
AlignState
Definition ekos.h:145
CaptureState
Capture states.
Definition ekos.h:92
KCALENDARCORE_EXPORT QDataStream & operator>>(QDataStream &in, const KCalendarCore::Alarm::Ptr &)
NETWORKMANAGERQT_EXPORT NetworkManager::Status status()
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:19:02 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.