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  double *x;
125  double *y;
126  double t;
127 
128  numOfData = 256;
129  vecR = new SgVector(numOfData);
130  vecI = new SgVector(numOfData);
131 
132 
133  for (int i=0; i<numOfData; i++)
134  {
135  t = double(i)/double(numOfData);
136  vecR->setElement(i,
137  1.0*sin(2.0*M_PI*t/0.50) +
138  0.8*sin(2.0*M_PI*t/0.04) +
139  1.8*sin(2.0*M_PI*t/0.12)
140  );
141  vecI->setElement(i,
142  1.0*sin(2.0*M_PI*t/0.32) +
143  1.5*sin(2.0*M_PI*t/0.025) +
144  0.8*sin(2.0*M_PI*t/0.8)
145  );
146  };
147 
148 /*
149  vecR->setElement(0, 1.0);
150  vecR->setElement(1, 1.0);
151  vecR->setElement(2, 1.0);
152  vecR->setElement(3, 1.0);
153  vecR->setElement(4, 1.0);
154  vecR->setElement(5, 1.0);
155  vecR->setElement(6, 1.0);
156  vecR->setElement(7, 1.0);
157 */
158 
159 /*
160  vecR->setElement( 0, 0.056533*cos((-174.916)*DEG2RAD));
161  vecI->setElement( 0, 0.056533*sin((-174.916)*DEG2RAD));
162  vecR->setElement( 1, 0.059263*cos((-129.290)*DEG2RAD));
163  vecI->setElement( 1, 0.059263*sin((-129.290)*DEG2RAD));
164  vecR->setElement( 4, 0.025482*cos(( -13.035)*DEG2RAD));
165  vecI->setElement( 4, 0.025482*sin(( -13.035)*DEG2RAD));
166  vecR->setElement(10, 0.062434*cos(( -75.062)*DEG2RAD));
167  vecI->setElement(10, 0.062434*sin(( -75.062)*DEG2RAD));
168  vecR->setElement(21, 0.051808*cos(( 120.126)*DEG2RAD));
169  vecI->setElement(21, 0.051808*sin(( 120.126)*DEG2RAD));
170  vecR->setElement(29, 0.058286*cos(( 87.796)*DEG2RAD));
171  vecI->setElement(29, 0.058286*sin(( 87.796)*DEG2RAD));
172  vecR->setElement(34, 0.060018*cos(( 129.865)*DEG2RAD));
173  vecI->setElement(34, 0.060018*sin(( 129.865)*DEG2RAD));
174 */
175 /*
176 t207 channel[ 0]: Ref: Amp=(l:0.056533 ) Phase=(l:-174.916 ) Offs=(l: 3.900 )
177 t207 channel[ 1]: Ref: Amp=(l:0.059263 ) Phase=(l:-129.290 ) Offs=(l: 3.100 )
178 t207 channel[ 2]: Ref: Amp=(l:0.025482 ) Phase=(l: -13.035 ) Offs=(l: -0.500 )
179 t207 channel[ 3]: Ref: Amp=(l:0.062434 ) Phase=(l: -75.062 ) Offs=(l: -5.100 )
180 t207 channel[ 4]: Ref: Amp=(l:0.051808 ) Phase=(l: 120.126 ) Offs=(l: -6.200 )
181 t207 channel[ 5]: Ref: Amp=(l:0.058286 ) Phase=(l: 87.796 ) Offs=(l: 5.800 )
182 t207 channel[ 6]: Ref: Amp=(l:0.060018 ) Phase=(l: 129.865 ) Offs=(l: -1.200 )
183 
184 t207 channel[ 0]: Rem: Amp=(l:0.032446 ) Phase=(l:-157.032 ) Offs=(l: 0.900 )
185 t207 channel[ 1]: Rem: Amp=(l:0.032063 ) Phase=(l:-129.068 ) Offs=(l: 1.800 )
186 t207 channel[ 2]: Rem: Amp=(l:0.031816 ) Phase=(l: -26.614 ) Offs=(l: -2.900 )
187 t207 channel[ 3]: Rem: Amp=(l:0.031788 ) Phase=(l:-129.755 ) Offs=(l: -2.900 )
188 t207 channel[ 4]: Rem: Amp=(l:0.030973 ) Phase=(l:-179.681 ) Offs=(l: -4.400 )
189 t207 channel[ 5]: Rem: Amp=(l:0.030735 ) Phase=(l: -22.263 ) Offs=(l: 8.400 )
190 t207 channel[ 6]: Rem: Amp=(l:0.030000 ) Phase=(l: 177.788 ) Offs=(l: -2.200 )
191 */
192 
193 
194 
195 
196  x = new double[numOfData];
197  y = new double[numOfData];
198  for (int i=0; i<numOfData; i++)
199  {
200  x[i] = vecR->getElement(i);
201  y[i] = vecI->getElement(i);
202  };
203  fft(x, y, numOfData, 1);
204 
205 /*
206 for (int i=0; i<numOfData; i++)
207  std::cout << " (" << x[i] << " ," << y[i] << ") ";
208 std::cout << "\n";
209 */
210 
211  int numOfBranches = 7;
212  const char* branchNames[7] = {"OrigR", "OrigI", "Real", "Imag", "Abs", "RevR", "RevI"};
213 
214  carrier_ = new SgPlotCarrier(2, 0, "Four1 testing");
215 
216  for (int i=0; i<numOfBranches; i++)
217  carrier_->createBranch(numOfData, branchNames[i]);
218 
219  carrier_->setNameOfColumn(0, "Freq");
220  carrier_->setNameOfColumn(1, "Four1");
221 
222  // input:
223  branch = carrier_->listOfBranches()->at(0);
224  for (int i=0; i<numOfData; i++)
225  {
226  branch->data()->setElement(i, 0, i);
227  branch->data()->setElement(i, 1, vecR->getElement(i));
228  };
229  branch = carrier_->listOfBranches()->at(1);
230  for (int i=0; i<numOfData; i++)
231  {
232  branch->data()->setElement(i, 0, i);
233  branch->data()->setElement(i, 1, vecI->getElement(i));
234  };
235  //
236  // output:
237  branch = carrier_->listOfBranches()->at(2);
238  for (int i=0; i<numOfData; i++)
239  {
240  branch->data()->setElement(i, 0, i);
241  branch->data()->setElement(i, 1, x[i]);
242  };
243  branch = carrier_->listOfBranches()->at(3);
244  for (int i=0; i<numOfData; i++)
245  {
246  branch->data()->setElement(i, 0, i);
247  branch->data()->setElement(i, 1, y[i]);
248  };
249  branch = carrier_->listOfBranches()->at(4);
250  for (int i=0; i<numOfData; i++)
251  {
252  branch->data()->setElement(i, 0, i);
253  branch->data()->setElement(i, 1, hypot(x[i], y[i]));
254  };
255  //
256  //reverse:
257  fft(x, y, numOfData, -1);
258  branch = carrier_->listOfBranches()->at(5);
259  for (int i=0; i<numOfData; i++)
260  {
261  branch->data()->setElement(i, 0, i);
262  branch->data()->setElement(i, 1, x[i]);
263  };
264  branch = carrier_->listOfBranches()->at(6);
265  for (int i=0; i<numOfData; i++)
266  {
267  branch->data()->setElement(i, 0, i);
268  branch->data()->setElement(i, 1, y[i]);
269  };
270 
271 
272  //
273  //
276 
277  return plot_;
278 };
279 /*=====================================================================================================*/
SgLogger * logger
Definition: SgLogger.cpp:231
void fft(std::complex< double > buf[], int n)
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