General Purpose Geodetic Library
NsTestFour1Dialog.cpp
Go to the documentation of this file.
1 /*
2  *
3  * This file is a part of nuSolve. nuSolve is a part of CALC/SOLVE system
4  * and is designed to perform data analyis of a geodetic VLBI session.
5  * Copyright (C) 2010-2020 Sergei Bolotin.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #include "nuSolve.h"
23 #include "NsTestFour1Dialog.h"
24 
25 #include <iostream>
26 #include <stdlib.h>
27 
28 
29 #include <SgCubicSpline.h>
30 #include <SgGuiPlotter.h>
31 #include <SgLogger.h>
32 #include <SgMJD.h>
33 #include <SgMathSupport.h>
34 #include <SgVector.h>
35 
36 #if QT_VERSION >= 0x050000
37 # include <QtWidgets/QLabel>
38 # include <QtWidgets/QGroupBox>
39 # include <QtWidgets/QBoxLayout>
40 # include <QtWidgets/QPushButton>
41 # include <QtWidgets/QFrame>
42 #else
43 # include <QtGui/QLabel>
44 # include <QtGui/QGroupBox>
45 # include <QtGui/QBoxLayout>
46 # include <QtGui/QPushButton>
47 # include <QtGui/QFrame>
48 #endif
49 
50 
51 
52 /*=======================================================================================================
53 *
54 * METHODS:
55 *
56 *======================================================================================================*/
57 NsTestFour1Dialog::NsTestFour1Dialog(QWidget *parent, Qt::WindowFlags flags)
58  : QDialog(parent, flags)
59 {
60  QBoxLayout *Layout, *SubLayout;
61  QSize BtnSize;
62 
63  Layout = new QVBoxLayout(this);
64  Layout->addWidget(testPlot(), 10);
65  SubLayout = new QHBoxLayout();
66  Layout->addLayout(SubLayout);
67  SubLayout->addStretch(1);
68 
69  QPushButton *Ok=new QPushButton("OK", this);
70  QPushButton *Cancel=new QPushButton("Cancel", this);
71  Ok->setDefault(true);
72 
73  Cancel->setMinimumSize((BtnSize=Cancel->sizeHint()));
74  Ok ->setMinimumSize(BtnSize);
75 
76  SubLayout->addWidget(Ok);
77  SubLayout->addWidget(Cancel);
78 
79  connect(Ok, SIGNAL(clicked()), SLOT(accept()));
80  connect(Cancel, SIGNAL(clicked()), SLOT(reject()));
81  setWindowTitle("Test Dialog");
82 };
83 
84 
85 
87 {
88  if (carrier_)
89  {
90  delete carrier_;
91  carrier_ = NULL;
92  }
93 };
94 
95 
96 
98 {
99  QDialog::accept();
101  ": accept selected");
102  deleteLater();
103 };
104 
105 
106 
107 //
109 {
110  QDialog::reject();
112  ": reject selected");
113  deleteLater();
114 };
115 
116 
117 
118 //
120 {
121  SgPlotBranch *branch;
122  int numOfData;
123  SgVector *vecR, *vecI;
124  std::complex<double> *x_a;
125  std::complex<double> *x_a_rev;
126  std::complex<double> *x_A;
127  double t;
128 
129  numOfData = 256;
130  vecR = new SgVector(numOfData);
131  vecI = new SgVector(numOfData);
132 
133 
134  for (int i=0; i<numOfData; i++)
135  {
136  t = double(i)/double(numOfData);
137  vecR->setElement(i,
138  1.0*sin(2.0*M_PI*t/0.50) +
139  0.8*sin(2.0*M_PI*t/0.04) +
140  1.8*sin(2.0*M_PI*t/0.12)
141  );
142  vecI->setElement(i,
143  1.0*sin(2.0*M_PI*t/0.32) +
144  1.5*sin(2.0*M_PI*t/0.025) +
145  0.8*sin(2.0*M_PI*t/0.8)
146  );
147  };
148 
149 /*
150  vecR->setElement(0, 1.0);
151  vecR->setElement(1, 1.0);
152  vecR->setElement(2, 1.0);
153  vecR->setElement(3, 1.0);
154  vecR->setElement(4, 1.0);
155  vecR->setElement(5, 1.0);
156  vecR->setElement(6, 1.0);
157  vecR->setElement(7, 1.0);
158 */
159 
160 /*
161  vecR->setElement( 0, 0.056533*cos((-174.916)*DEG2RAD));
162  vecI->setElement( 0, 0.056533*sin((-174.916)*DEG2RAD));
163  vecR->setElement( 1, 0.059263*cos((-129.290)*DEG2RAD));
164  vecI->setElement( 1, 0.059263*sin((-129.290)*DEG2RAD));
165  vecR->setElement( 4, 0.025482*cos(( -13.035)*DEG2RAD));
166  vecI->setElement( 4, 0.025482*sin(( -13.035)*DEG2RAD));
167  vecR->setElement(10, 0.062434*cos(( -75.062)*DEG2RAD));
168  vecI->setElement(10, 0.062434*sin(( -75.062)*DEG2RAD));
169  vecR->setElement(21, 0.051808*cos(( 120.126)*DEG2RAD));
170  vecI->setElement(21, 0.051808*sin(( 120.126)*DEG2RAD));
171  vecR->setElement(29, 0.058286*cos(( 87.796)*DEG2RAD));
172  vecI->setElement(29, 0.058286*sin(( 87.796)*DEG2RAD));
173  vecR->setElement(34, 0.060018*cos(( 129.865)*DEG2RAD));
174  vecI->setElement(34, 0.060018*sin(( 129.865)*DEG2RAD));
175 */
176 /*
177 t207 channel[ 0]: Ref: Amp=(l:0.056533 ) Phase=(l:-174.916 ) Offs=(l: 3.900 )
178 t207 channel[ 1]: Ref: Amp=(l:0.059263 ) Phase=(l:-129.290 ) Offs=(l: 3.100 )
179 t207 channel[ 2]: Ref: Amp=(l:0.025482 ) Phase=(l: -13.035 ) Offs=(l: -0.500 )
180 t207 channel[ 3]: Ref: Amp=(l:0.062434 ) Phase=(l: -75.062 ) Offs=(l: -5.100 )
181 t207 channel[ 4]: Ref: Amp=(l:0.051808 ) Phase=(l: 120.126 ) Offs=(l: -6.200 )
182 t207 channel[ 5]: Ref: Amp=(l:0.058286 ) Phase=(l: 87.796 ) Offs=(l: 5.800 )
183 t207 channel[ 6]: Ref: Amp=(l:0.060018 ) Phase=(l: 129.865 ) Offs=(l: -1.200 )
184 
185 t207 channel[ 0]: Rem: Amp=(l:0.032446 ) Phase=(l:-157.032 ) Offs=(l: 0.900 )
186 t207 channel[ 1]: Rem: Amp=(l:0.032063 ) Phase=(l:-129.068 ) Offs=(l: 1.800 )
187 t207 channel[ 2]: Rem: Amp=(l:0.031816 ) Phase=(l: -26.614 ) Offs=(l: -2.900 )
188 t207 channel[ 3]: Rem: Amp=(l:0.031788 ) Phase=(l:-129.755 ) Offs=(l: -2.900 )
189 t207 channel[ 4]: Rem: Amp=(l:0.030973 ) Phase=(l:-179.681 ) Offs=(l: -4.400 )
190 t207 channel[ 5]: Rem: Amp=(l:0.030735 ) Phase=(l: -22.263 ) Offs=(l: 8.400 )
191 t207 channel[ 6]: Rem: Amp=(l:0.030000 ) Phase=(l: 177.788 ) Offs=(l: -2.200 )
192 */
193 
194 
195  x_a = new std::complex<double>[numOfData];
196  x_a_rev = new std::complex<double>[numOfData];
197  x_A = new std::complex<double>[numOfData];
198 
199  for (int i=0; i<numOfData; i++)
200  {
201  x_a[i] = std::complex<double>(vecR->getElement(i), vecI->getElement(i));
202  x_A[i] = x_a_rev[i] = 0.0;
203  };
204 // fft(x, y, numOfData, 1);
205  fft(x_a, x_A, numOfData, FFT_Forward);
206  fft(x_A, x_a_rev, numOfData, FFT_Inverse);
207 
208 
209  int numOfBranches = 7;
210  const char* branchNames[7] = {"OrigR", "OrigI", "Real", "Imag", "Abs", "RevR", "RevI"};
211 
212  carrier_ = new SgPlotCarrier(2, 0, "Four1 testing");
213 
214  for (int i=0; i<numOfBranches; i++)
215  carrier_->createBranch(numOfData, branchNames[i]);
216 
217  carrier_->setNameOfColumn(0, "Freq");
218  carrier_->setNameOfColumn(1, "Four1");
219 
220  // input:
221  branch = carrier_->listOfBranches()->at(0);
222  for (int i=0; i<numOfData; i++)
223  {
224  branch->data()->setElement(i, 0, i);
225  branch->data()->setElement(i, 1, vecR->getElement(i));
226  };
227  branch = carrier_->listOfBranches()->at(1);
228  for (int i=0; i<numOfData; i++)
229  {
230  branch->data()->setElement(i, 0, i);
231  branch->data()->setElement(i, 1, vecI->getElement(i));
232  };
233  //
234  // output:
235  branch = carrier_->listOfBranches()->at(2);
236  for (int i=0; i<numOfData; i++)
237  {
238  branch->data()->setElement(i, 0, i);
239  branch->data()->setElement(i, 1, x_A[i].real());
240  };
241  branch = carrier_->listOfBranches()->at(3);
242  for (int i=0; i<numOfData; i++)
243  {
244  branch->data()->setElement(i, 0, i);
245  branch->data()->setElement(i, 1, x_A[i].imag());
246  };
247  branch = carrier_->listOfBranches()->at(4);
248  for (int i=0; i<numOfData; i++)
249  {
250  branch->data()->setElement(i, 0, i);
251  branch->data()->setElement(i, 1, abs(x_A[i]));
252  };
253  //
254  branch = carrier_->listOfBranches()->at(5);
255  for (int i=0; i<numOfData; i++)
256  {
257  branch->data()->setElement(i, 0, i);
258  branch->data()->setElement(i, 1, x_a_rev[i].real());
259  };
260  branch = carrier_->listOfBranches()->at(6);
261  for (int i=0; i<numOfData; i++)
262  {
263  branch->data()->setElement(i, 0, i);
264  branch->data()->setElement(i, 1, x_a_rev[i].imag());
265  };
266 
267  delete[] x_a;
268  delete[] x_a_rev;
269  delete[] x_A;
270 
271  //
272  //
275 
276  return plot_;
277 };
278 /*=====================================================================================================*/
SgLogger * logger
Definition: SgLogger.cpp:231
void fft(std::complex< double > x_a[], std::complex< double > x_A[], unsigned int n, FFT_Direction dir)
@ FFT_Inverse
Definition: SgMathSupport.h:82
@ FFT_Forward
Definition: SgMathSupport.h:82
SgPlot::OutputFormat getPlotterOutputFormat() const
Definition: NsSetup.h:654
const QString & getPath2PlotterOutput() const
Definition: NsSetup.h:486
SgPlotCarrier * carrier_
NsTestFour1Dialog(QWidget *parent=0, Qt::WindowFlags flags=0)
QString className() const
virtual void write(LogLevel, quint32, const QString &, bool=false)
Definition: SgLogger.cpp:88
void setElement(unsigned int i, unsigned int j, double d)
Definition: SgMatrix.h:402
SgMatrix * data()
Definition: SgGuiPlotter.h:83
void createBranch(unsigned int numberOfRows, const QString &branchName, bool hasExtKeys=false)
QList< SgPlotBranch * > * listOfBranches()
Definition: SgGuiPlotter.h:163
void setNameOfColumn(unsigned int, const QString &)
void setOutputFormat(OutputFormat fmt)
Definition: SgGuiPlotter.h:625
void setElement(unsigned int i, double d)
Definition: SgVector.h:348
double getElement(unsigned int i) const
Definition: SgVector.h:362
NsSetup setup
Definition: nuSolve.cpp:61