Line data Source code
1 : /*******************************************************************************
2 : * ALMA - Atacama Large Millimiter Array
3 : * (c) Instituto de Estructura de la Materia, 2009
4 : *
5 : * This library is free software; you can redistribute it and/or
6 : * modify it under the terms of the GNU Lesser General Public
7 : * License as published by the Free Software Foundation; either
8 : * version 2.1 of the License, or (at your option) any later version.
9 : *
10 : * This library is distributed in the hope that it will be useful,
11 : * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 : * Lesser General Public License for more details.
14 : *
15 : * You should have received a copy of the GNU Lesser General Public
16 : * License along with this library; if not, write to the Free Software
17 : * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 : *
19 : * "@(#) $Id: ATMSpectralGrid.cpp Exp $"
20 : *
21 : * who when what
22 : * -------- -------- ----------------------------------------------
23 : * pardo 24/03/09 created
24 : */
25 :
26 : #include "ATMSpectralGrid.h"
27 :
28 : #include <iostream>
29 : #include <limits>
30 : #include <math.h>
31 : #include <vector>
32 : #include <string>
33 :
34 :
35 :
36 : ATM_NAMESPACE_BEGIN
37 :
38 : // public methods:
39 : // constructors
40 0 : SpectralGrid::SpectralGrid(const Frequency &oneFreq)
41 : {
42 0 : v_chanFreq_.reserve(1);
43 0 : freqUnits_ = Frequency::UnitHertz;
44 0 : v_transfertId_.resize(0); // not sure this is necessary!
45 0 : unsigned int numChan = 1;
46 0 : unsigned int refChan = 0;
47 0 : Frequency chanSep(0.0);
48 0 : add(numChan, refChan, oneFreq, chanSep);
49 0 : std::vector<unsigned int> v_dummyInt;
50 0 : vv_assocSpwId_.push_back(v_dummyInt); // put an empty std::vector
51 0 : std::vector<std::string> v_dummyString;
52 0 : vv_assocNature_.push_back(v_dummyString); // put an empty std::vector
53 0 : }
54 :
55 864 : SpectralGrid::SpectralGrid(unsigned int numChan,
56 : unsigned int refChan,
57 : const Frequency &refFreq,
58 864 : const Frequency &chanSep)
59 : {
60 : // cout << " SpectralGrid constructor" << endl;
61 864 : v_chanFreq_.reserve(numChan);
62 864 : freqUnits_ = Frequency::UnitHertz;
63 864 : v_transfertId_.resize(0); // not sure this is necessary!
64 864 : add(numChan, refChan, refFreq, chanSep);
65 1728 : std::vector<unsigned int> v_dummyInt;
66 864 : vv_assocSpwId_.push_back(v_dummyInt); // put an empty std::vector
67 1728 : std::vector<std::string> v_dummyString;
68 864 : vv_assocNature_.push_back(v_dummyString); // put an empty std::vector
69 864 : }
70 :
71 0 : SpectralGrid::SpectralGrid(unsigned int numChan,
72 : unsigned int refChan,
73 : const Frequency &refFreq,
74 : const Frequency &chanSep,
75 : const Frequency &intermediateFreq,
76 : const SidebandSide &sbSide,
77 0 : const SidebandType &sbType)
78 : {
79 0 : freqUnits_ = Frequency::UnitHertz;
80 0 : v_transfertId_.resize(0); // not sure this is necessary!
81 0 : v_chanFreq_.reserve(numChan);
82 : /* cout << " la" << endl; */
83 0 : add(numChan, refChan, refFreq, chanSep, intermediateFreq, sbSide, sbType);
84 0 : }
85 :
86 0 : SpectralGrid::SpectralGrid(unsigned int numChan,
87 : unsigned int refChan,
88 : double* chanFreq,
89 0 : Frequency::Units freqUnits)
90 : {
91 0 : v_chanFreq_.reserve(numChan);
92 0 : freqUnits_ = Frequency::UnitHertz;
93 0 : v_transfertId_.resize(0); // not sure this is necessary!
94 0 : add(numChan, refChan, chanFreq, freqUnits);
95 0 : }
96 :
97 0 : void SpectralGrid::add(unsigned int numChan,
98 : unsigned int refChan,
99 : const Frequency &refFreq,
100 : const Frequency &chanSep,
101 : const Frequency &intermediateFreq,
102 : const SidebandSide &sbSide,
103 : const SidebandType &sbType)
104 : {
105 :
106 :
107 : double chSep;
108 0 : std::vector<std::string> v_assocNature;
109 0 : std::vector<unsigned int> v_assocSpwId;
110 :
111 0 : unsigned int spwId = v_transfertId_.size();
112 :
113 0 : if(sbSide == LSB) { // LSB tuning
114 : // the LSB:
115 0 : add(numChan, refChan, refFreq, chanSep); // LSB
116 0 : v_sidebandSide_[spwId] = LSB;
117 0 : v_sidebandType_[spwId] = sbType;
118 0 : double loFreq = refFreq.get() + intermediateFreq.get(); // store loFreq for USB
119 0 : v_loFreq_[spwId] = loFreq;
120 0 : v_assocSpwId.push_back(v_numChan_.size());
121 0 : vv_assocSpwId_[vv_assocSpwId_.size() - 1] = v_assocSpwId;
122 0 : v_assocNature.push_back("USB");
123 0 : vv_assocNature_[vv_assocNature_.size() - 1] = v_assocNature;
124 :
125 : // the USB:
126 0 : spwId = v_transfertId_.size();
127 0 : double refFreqUSB = refFreq.get() + 2.*intermediateFreq.get(); // fix refFreq in the image band (refChan is unchanged)
128 0 : chSep = -chanSep.get();
129 0 : add(numChan, refChan, Frequency(refFreqUSB), Frequency(chSep));
130 :
131 0 : v_sidebandSide_[spwId] = USB;
132 0 : v_sidebandType_[spwId] = sbType;
133 0 : v_loFreq_[spwId] = loFreq;
134 :
135 0 : v_assocSpwId[0] = v_numChan_.size() - 2;
136 0 : vv_assocSpwId_[vv_assocSpwId_.size() - 1] = v_assocSpwId;
137 0 : v_assocNature[0] = "LSB";
138 0 : vv_assocNature_[vv_assocNature_.size() - 1] = v_assocNature;
139 :
140 : } else { // USB tuning
141 : // the USB:
142 0 : add(numChan, refChan, refFreq, chanSep);
143 :
144 0 : v_sidebandSide_[spwId] = USB;
145 0 : v_sidebandType_[spwId] = sbType;
146 0 : double loFreq = refFreq.get() - intermediateFreq.get();
147 0 : v_loFreq_[spwId] = loFreq;
148 :
149 0 : v_assocSpwId.push_back(v_numChan_.size());
150 0 : vv_assocSpwId_[vv_assocSpwId_.size() - 1] = v_assocSpwId;
151 0 : v_assocNature.push_back("LSB");
152 0 : vv_assocNature_[vv_assocNature_.size() - 1] = v_assocNature;
153 :
154 : // the LSB:
155 0 : spwId = v_transfertId_.size();
156 0 : double refFreqLSB = refFreq.get() - 2.*intermediateFreq.get(); // fix refFreq in the image band (refChan is unchanged)
157 0 : chSep = -chanSep.get();
158 0 : add(numChan, refChan, Frequency(refFreqLSB), Frequency(chSep));
159 :
160 0 : v_sidebandSide_[spwId] = LSB;
161 0 : v_sidebandType_[spwId] = sbType;
162 0 : v_loFreq_[spwId] = loFreq;
163 :
164 0 : v_assocSpwId[0] = v_numChan_.size() - 2;
165 0 : vv_assocSpwId_[vv_assocSpwId_.size() - 1] = v_assocSpwId;
166 0 : v_assocNature[0] = "USB";
167 0 : vv_assocNature_[vv_assocNature_.size() - 1] = v_assocNature;
168 : }
169 0 : }
170 :
171 864 : unsigned int SpectralGrid::add(unsigned int numChan,
172 : unsigned int refChan,
173 : const Frequency &refFreq,
174 : const Frequency &chanSep)
175 : {
176 864 : freqUnits_ = Frequency::UnitHertz;
177 :
178 864 : unsigned int spwId = v_transfertId_.size();
179 864 : v_loFreq_.push_back(refFreq.get());
180 :
181 864 : if(spwId == 0) {
182 864 : v_transfertId_.push_back(0);
183 : } else {
184 0 : v_transfertId_.push_back(v_transfertId_[spwId - 1] + v_numChan_[spwId - 1]);
185 : }
186 :
187 864 : v_numChan_.push_back(numChan);
188 864 : v_refChan_.push_back(refChan);
189 :
190 864 : v_refFreq_.push_back(refFreq.get(freqUnits_));
191 864 : v_chanSep_.push_back(chanSep.get(freqUnits_));
192 :
193 864 : double* chanFreq = new double[numChan];
194 : {
195 : // CAS-9762 refChan should not be 1-base
196 : // ICT-9490 Change refChan convention so that it is 0-based
197 : // double freqOffset = v_refFreq_[spwId] - v_chanSep_[spwId]
198 : // * (double) (v_refChan_[spwId] - 1.);
199 864 : double freqOffset = v_refFreq_[spwId] - v_chanSep_[spwId]
200 864 : * (double) (v_refChan_[spwId]);
201 :
202 368518 : for(unsigned int i = 0; i < numChan; i++) {
203 367654 : chanFreq[i] = freqOffset + (double) i * v_chanSep_[spwId];
204 : }
205 864 : appendChanFreq(numChan, chanFreq);
206 :
207 864 : if(numChan > 1) {
208 864 : if(chanFreq[0] > chanFreq[1]) {
209 355 : v_minFreq_.push_back(chanFreq[numChan - 1]);
210 355 : v_maxFreq_.push_back(chanFreq[0]);
211 : } else {
212 509 : v_minFreq_.push_back(chanFreq[0]);
213 509 : v_maxFreq_.push_back(chanFreq[numChan - 1]);
214 : }
215 : } else {
216 0 : v_minFreq_.push_back(chanFreq[0]);
217 0 : v_maxFreq_.push_back(chanFreq[0]);
218 : }
219 :
220 864 : v_sidebandSide_ .push_back(NOSB);
221 864 : v_sidebandType_ .push_back(NOTYPE);
222 864 : v_intermediateFrequency_.push_back(0.0);
223 : }
224 1728 : std::vector<unsigned int> v_dummyAssoc;
225 864 : vv_assocSpwId_.push_back(v_dummyAssoc);
226 864 : std::vector<std::string> v_dummyNature;
227 864 : vv_assocNature_.push_back(v_dummyNature);
228 :
229 864 : delete [] chanFreq;
230 1728 : return spwId;
231 : }
232 :
233 864 : void SpectralGrid::appendChanFreq(unsigned int numChan, double* chanFreq)
234 : {
235 :
236 : // unsigned int k=v_chanFreq_.size();
237 368518 : for(unsigned int i = 0; i < numChan; i++) {
238 367654 : v_chanFreq_.push_back(chanFreq[i]); // cout << i << "v_chanFreq_="<<v_chanFreq_[k+i]<<endl;
239 : }
240 864 : }
241 :
242 0 : void SpectralGrid::appendChanFreq(unsigned int numChan, const std::vector<double> &chanFreq)
243 : {
244 :
245 : // unsigned int k=v_chanFreq_.size();
246 0 : for(unsigned int i = 0; i < numChan; i++) {
247 0 : v_chanFreq_.push_back(chanFreq[i]); // cout << i << "v_chanFreq_="<<v_chanFreq_[k+i]<<endl;
248 : }
249 0 : }
250 :
251 0 : unsigned int SpectralGrid::add(unsigned int numChan,
252 : unsigned int refChan,
253 : double* chanFreq,
254 : Frequency::Units freqUnits)
255 : {
256 0 : double fact = 1.0;
257 0 : if(freqUnits == Frequency::UnitGigaHertz) fact = 1.0E9;
258 0 : if(freqUnits == Frequency::UnitMegaHertz) fact = 1.0E6;
259 0 : if(freqUnits == Frequency::UnitKiloHertz) fact = 1.0E3;
260 :
261 0 : unsigned int spwId = v_transfertId_.size();
262 0 : if(spwId == 0) {
263 0 : v_transfertId_.push_back(0);
264 : } else {
265 0 : v_transfertId_.push_back(v_transfertId_[spwId - 1] + v_numChan_[spwId - 1]);
266 : }
267 :
268 0 : v_numChan_.push_back(numChan);
269 0 : v_refChan_.push_back(refChan);
270 :
271 0 : bool regular = true;
272 0 : double minFreq = 1.E30;
273 0 : double maxFreq = 0;
274 0 : double chanSep = 0;
275 0 : if(numChan > 1) chanSep = fact * (chanFreq[1] - chanFreq[0]);
276 :
277 0 : chanFreq[0] = fact * chanFreq[0];
278 0 : for(unsigned int i = 1; i < numChan; i++) {
279 0 : chanFreq[i] = fact * chanFreq[i];
280 0 : if(fabs(chanFreq[i] - chanFreq[i - 1] - chanSep) > 1.0E-12) regular = false;
281 0 : if(chanFreq[i] < minFreq) minFreq = chanFreq[i];
282 0 : if(chanFreq[i] > maxFreq) maxFreq = chanFreq[i];
283 : }
284 0 : appendChanFreq(numChan, chanFreq);
285 :
286 0 : v_refFreq_.push_back(chanFreq[refChan - 1]);
287 0 : if(regular) {
288 0 : v_chanSep_.push_back(chanSep);
289 : } else {
290 0 : v_chanSep_.push_back(0);
291 : }
292 0 : v_sidebandSide_ .push_back(NOSB);
293 0 : v_sidebandType_ .push_back(NOTYPE);
294 0 : v_intermediateFrequency_.push_back(0.0);
295 :
296 0 : return spwId;
297 : }
298 :
299 0 : SpectralGrid::SpectralGrid(unsigned int numChan,
300 : double refFreq,
301 : double* chanFreq,
302 0 : Frequency::Units freqUnits)
303 : {
304 0 : v_chanFreq_.reserve(numChan);
305 0 : freqUnits_ = Frequency::UnitHertz;
306 0 : v_transfertId_.resize(0); // not sure this is necessary!
307 0 : add(numChan, refFreq, chanFreq, freqUnits);
308 0 : std::vector<unsigned int> v_dummyInt;
309 0 : vv_assocSpwId_.push_back(v_dummyInt); // put an empty std::vector
310 0 : std::vector<std::string> v_dummyString;
311 0 : vv_assocNature_.push_back(v_dummyString); // put an empty std::vector
312 0 : }
313 :
314 0 : SpectralGrid::SpectralGrid(double refFreq,
315 : const std::vector<double> &chanFreq,
316 0 : Frequency::Units freqUnits)
317 : {
318 0 : v_chanFreq_.reserve(chanFreq.size());
319 0 : freqUnits_ = Frequency::UnitHertz;
320 0 : v_transfertId_.resize(0); // not sure this is necessary!
321 0 : add(chanFreq.size(), refFreq, chanFreq, freqUnits);
322 0 : std::vector<unsigned int> v_dummyInt;
323 0 : vv_assocSpwId_.push_back(v_dummyInt); // put an empty std::vector
324 0 : std::vector<std::string> v_dummyString;
325 0 : vv_assocNature_.push_back(v_dummyString); // put an empty std::vector
326 0 : }
327 :
328 0 : SpectralGrid::SpectralGrid(const std::vector<double> &chanFreq, Frequency::Units freqUnits)
329 : {
330 0 : v_chanFreq_.reserve(chanFreq.size());
331 0 : freqUnits_ = Frequency::UnitHertz;
332 0 : v_transfertId_.resize(0); // not sure this is necessary!
333 0 : double refFreq = (Frequency(chanFreq[0], freqUnits)).get(Frequency::UnitHertz); // We take the frequency of the first channel as
334 : // reference frequency because it has not been specified
335 0 : add(chanFreq.size(), refFreq, chanFreq, freqUnits);
336 0 : std::vector<unsigned int> v_dummyInt;
337 0 : vv_assocSpwId_.push_back(v_dummyInt); // put an empty std::vector
338 0 : std::vector<std::string> v_dummyString;
339 0 : vv_assocNature_.push_back(v_dummyString); // put an empty std::vector
340 0 : }
341 :
342 0 : SpectralGrid::SpectralGrid(const std::vector<Frequency> &chanFreq)
343 : {
344 0 : v_chanFreq_.reserve(chanFreq.size());
345 0 : freqUnits_ = Frequency::UnitHertz;
346 0 : v_transfertId_.resize(0); // not sure this is necessary!
347 0 : double refFreq = chanFreq[0].get(Frequency::UnitHertz); // We take the frequency of the first channel as
348 : // reference frequency because it has not been specified
349 0 : std::vector<double> chanFreq_double;
350 0 : for(unsigned int i = 0; i < chanFreq.size(); i++) {
351 0 : chanFreq_double.push_back(chanFreq[i].get(Frequency::UnitGigaHertz));
352 : }
353 :
354 0 : add(chanFreq.size(), refFreq, chanFreq_double, Frequency::UnitGigaHertz);
355 0 : std::vector<unsigned int> v_dummyInt;
356 0 : vv_assocSpwId_.push_back(v_dummyInt); // put an empty std::vector
357 0 : std::vector<std::string> v_dummyString;
358 0 : vv_assocNature_.push_back(v_dummyString); // put an empty std::vector
359 0 : }
360 :
361 0 : unsigned int SpectralGrid::add(unsigned int numChan,
362 : double refFreq,
363 : double* chanFreq,
364 : Frequency::Units freqUnits)
365 : {
366 :
367 0 : bool regular = true;
368 0 : double fact = 1.0;
369 0 : if(freqUnits == Frequency::UnitGigaHertz) fact = 1.0E9;
370 0 : if(freqUnits == Frequency::UnitMegaHertz) fact = 1.0E6;
371 0 : if(freqUnits == Frequency::UnitKiloHertz) fact = 1.0E3;
372 :
373 0 : freqUnits_ = Frequency::UnitHertz;
374 :
375 0 : unsigned int spwId = v_transfertId_.size();
376 0 : if(spwId == 0) {
377 0 : v_transfertId_.push_back(0);
378 : } else {
379 0 : v_transfertId_.push_back(v_transfertId_[spwId - 1] + v_numChan_[spwId - 1]);
380 : }
381 :
382 0 : v_numChan_.push_back(numChan);
383 0 : v_refFreq_.push_back(fact * refFreq);
384 :
385 0 : double chanSep = fact * (chanFreq[1] - chanFreq[0]);
386 0 : double minFreq = 1.E30;
387 0 : double maxFreq = 0;
388 :
389 0 : chanFreq[0] = fact * chanFreq[0];
390 0 : for(unsigned int i = 1; i < numChan; i++) {
391 0 : chanFreq[i] = fact * chanFreq[i];
392 0 : if(fabs(chanFreq[i] - chanFreq[i - 1] - chanSep) > 1.0E-12) regular = false;
393 0 : if(chanFreq[i] < minFreq) minFreq = chanFreq[i];
394 0 : if(chanFreq[i] > maxFreq) maxFreq = chanFreq[i];
395 : }
396 0 : appendChanFreq(numChan, chanFreq);
397 0 : v_minFreq_.push_back(minFreq);
398 0 : v_maxFreq_.push_back(maxFreq);
399 :
400 0 : if(numChan > 1) {
401 0 : if(regular) {
402 0 : v_refChan_.push_back((unsigned int) (1. + (refFreq - v_chanFreq_[0]
403 0 : + 1.E-12) / chanSep));
404 0 : v_chanSep_.push_back(chanSep);
405 : } else {
406 0 : v_refChan_.push_back(0);
407 0 : v_chanSep_.push_back(0.0);
408 : }
409 : } else {
410 0 : v_refChan_.push_back(0);
411 0 : v_chanSep_.push_back(0.0);
412 : }
413 0 : v_sidebandSide_ .push_back(NOSB);
414 0 : v_sidebandType_ .push_back(NOTYPE);
415 0 : v_intermediateFrequency_.push_back(0.0);
416 :
417 0 : return spwId;
418 : }
419 :
420 0 : unsigned int SpectralGrid::add(unsigned int numChan,
421 : double refFreq,
422 : const std::vector<double> &chanFreq,
423 : Frequency::Units freqUnits)
424 : {
425 :
426 0 : bool regular = true;
427 0 : double fact = 1.0;
428 0 : if(freqUnits == Frequency::UnitGigaHertz) fact = 1.0E9;
429 0 : if(freqUnits == Frequency::UnitMegaHertz) fact = 1.0E6;
430 0 : if(freqUnits == Frequency::UnitKiloHertz) fact = 1.0E3;
431 :
432 0 : freqUnits_ =Frequency::UnitHertz;
433 :
434 0 : unsigned int spwId = v_transfertId_.size();
435 0 : if(spwId == 0) {
436 0 : v_transfertId_.push_back(0);
437 : } else {
438 0 : v_transfertId_.push_back(v_transfertId_[spwId - 1] + v_numChan_[spwId - 1]);
439 : }
440 :
441 0 : v_numChan_.push_back(numChan);
442 0 : v_refFreq_.push_back(fact * refFreq);
443 :
444 0 : double chanSep = fact * (chanFreq[1] - chanFreq[0]);
445 :
446 0 : std::vector<double> chanFreqHz(numChan);
447 0 : chanFreqHz[0] = fact * chanFreq[0];
448 0 : double minFreq = chanFreqHz[0];
449 0 : double maxFreq = chanFreqHz[0];
450 :
451 0 : for(unsigned int i = 1; i < numChan; i++) {
452 0 : chanFreqHz[i] = fact * chanFreq[i];
453 0 : if(fabs(chanFreqHz[i] - chanFreqHz[i - 1] - chanSep) > 1.0E-12) regular = false;
454 0 : if(chanFreqHz[i] < minFreq) minFreq = chanFreqHz[i];
455 0 : if(chanFreqHz[i] > maxFreq) maxFreq = chanFreqHz[i];
456 : }
457 0 : appendChanFreq(numChan, chanFreqHz);
458 0 : v_minFreq_.push_back(minFreq);
459 0 : v_maxFreq_.push_back(maxFreq);
460 :
461 0 : if(numChan > 1) {
462 0 : if(regular) {
463 0 : v_refChan_.push_back((unsigned int) (1. + (refFreq - v_chanFreq_[0]
464 0 : + 1.E-12) / chanSep));
465 0 : v_chanSep_.push_back(chanSep);
466 : } else {
467 0 : v_refChan_.push_back(0);
468 0 : v_chanSep_.push_back(0.0);
469 : }
470 : } else {
471 0 : v_refChan_.push_back(0);
472 0 : v_chanSep_.push_back(0.0);
473 : }
474 0 : v_sidebandSide_ .push_back(NOSB);
475 0 : v_sidebandType_ .push_back(NOTYPE);
476 0 : v_intermediateFrequency_.push_back(0.0);
477 :
478 0 : return spwId;
479 : }
480 :
481 1976 : SpectralGrid::SpectralGrid(const SpectralGrid & a)
482 : {
483 : // cout << " SpectralGrid copy constructor" << endl;
484 1976 : freqUnits_ = a.freqUnits_;
485 1976 : v_chanFreq_ = a.v_chanFreq_;
486 :
487 1976 : v_numChan_ = a.v_numChan_; // cout << numChan_ << endl;
488 1976 : v_refChan_ = a.v_refChan_; // cout << refChan_ << endl;
489 1976 : v_refFreq_ = a.v_refFreq_; // cout << refChan_ << endl;
490 1976 : v_chanSep_ = a.v_chanSep_; // cout << chanSep_ << endl;
491 1976 : v_maxFreq_ = a.v_maxFreq_; // cout << maxFreq_ << endl;
492 1976 : v_minFreq_ = a.v_minFreq_; // cout << minFreq_ << endl;
493 1976 : v_intermediateFrequency_ = a.v_intermediateFrequency_;
494 1976 : v_loFreq_ = a.v_loFreq_;
495 1976 : v_sidebandSide_ = a.v_sidebandSide_;
496 1976 : v_sidebandType_ = a.v_sidebandType_;
497 1976 : vv_assocSpwId_ = a.vv_assocSpwId_;
498 1976 : vv_assocNature_ = a.vv_assocNature_;
499 1976 : v_transfertId_ = a.v_transfertId_;
500 :
501 : // cout << "v_chanFreq_.size()=" << v_chanFreq_.size() << endl;
502 1976 : }
503 :
504 0 : SpectralGrid::SpectralGrid()
505 : {
506 0 : }
507 :
508 : // destructor
509 2840 : SpectralGrid::~SpectralGrid()
510 : {
511 2840 : }
512 :
513 31226616 : bool SpectralGrid::wrongSpwId(unsigned int spwId) const
514 : {
515 31226616 : if(spwId > (v_transfertId_.size() - 1)) {
516 0 : std::cout << " SpectralGrid: ERROR: " << spwId
517 0 : << " is a wrong spectral window identifier" << std::endl;
518 0 : return (bool) true;
519 : }
520 31226616 : return (bool) false;
521 : }
522 :
523 : // accessors and utilities:
524 15957832 : unsigned int SpectralGrid::getNumSpectralWindow() const
525 : {
526 15957832 : return v_transfertId_.size();
527 : }
528 13160 : unsigned int SpectralGrid::getNumChan() const
529 : {
530 13160 : return v_numChan_[0];
531 : }
532 15957712 : unsigned int SpectralGrid::getNumChan(unsigned int spwId) const
533 : {
534 15957712 : if(wrongSpwId(spwId)) return 0;
535 15957712 : return v_numChan_[spwId];
536 : }
537 :
538 0 : unsigned int SpectralGrid::getRefChan() const
539 : {
540 0 : return v_refChan_[0];
541 : }
542 15 : unsigned int SpectralGrid::getRefChan(unsigned int spwId) const
543 : {
544 15 : if(wrongSpwId(spwId)) return 32767;
545 15 : return v_refChan_[spwId];
546 : }
547 :
548 0 : Frequency SpectralGrid::getRefFreq() const
549 : {
550 0 : return Frequency(v_refFreq_[0], Frequency::UnitHertz);
551 : }
552 0 : Frequency SpectralGrid::getRefFreq(unsigned int spwId) const
553 : {
554 0 : if(wrongSpwId(spwId)) return 32767.;
555 0 : return Frequency(v_refFreq_[spwId], Frequency::UnitHertz);
556 : }
557 :
558 0 : Frequency SpectralGrid::getChanSep() const
559 : {
560 0 : return Frequency(v_chanSep_[0], Frequency::UnitHertz);
561 : }
562 0 : Frequency SpectralGrid::getChanSep(unsigned int spwId) const
563 : {
564 0 : if(wrongSpwId(spwId)) return 32767.;
565 0 : return Frequency(v_chanSep_[spwId], Frequency::UnitHertz);
566 : }
567 :
568 0 : Frequency SpectralGrid::getChanFreq(unsigned int i) const
569 : {
570 0 : return Frequency(v_chanFreq_[i], Frequency::UnitHertz);
571 : }
572 :
573 0 : Frequency SpectralGrid::getChanWidth(unsigned int i) const
574 : {
575 0 : if(i == 0){
576 0 : return getChanFreq(i+1)-getChanFreq(i);
577 : }else{
578 0 : return getChanFreq(i)-getChanFreq(i-1);
579 : }
580 : }
581 :
582 15268784 : Frequency SpectralGrid::getChanFreq(unsigned int spwId, unsigned int chanIdx) const
583 : {
584 15268784 : if(wrongSpwId(spwId)) return 32767.;
585 15268784 : return Frequency(v_chanFreq_[v_transfertId_[spwId] + chanIdx], Frequency::UnitHertz);
586 : }
587 :
588 0 : Frequency SpectralGrid::getChanWidth(unsigned int spwId, unsigned int chanIdx) const
589 : {
590 0 : if(wrongSpwId(spwId)) return 32767.;
591 :
592 0 : unsigned int banda=spwId;
593 0 : unsigned int canalmasuno=chanIdx+1;
594 0 : unsigned int canal=chanIdx;
595 0 : unsigned int canalmenosuno=chanIdx-1;
596 : // cout << "banda,canal-1,canal,canal+1= " << banda << " " << canalmenosuno << " " << canal << " " << canalmasuno << endl;
597 :
598 0 : if(chanIdx == 0){
599 0 : return getChanFreq(spwId,canalmasuno)-getChanFreq(spwId,canal);
600 : }else{
601 : // cout << "ChanFreq(" << banda << "," << canal << ")=" << getChanFreq(banda,canal).get(Frequency::UnitGigaHertz) << endl;
602 : // cout << "ChanFreq(" << banda << "," << canalmenosuno << ")=" << getChanFreq(banda,canalmenosuno).get(Frequency::UnitGigaHertz) << endl;
603 0 : return getChanFreq(banda,canal)-getChanFreq(banda,canalmenosuno);
604 : }
605 : }
606 :
607 0 : std::vector<double> SpectralGrid::getSbChanFreq(unsigned int spwId,
608 : unsigned int chanIdx,
609 : const std::string &units) const
610 : {
611 0 : std::vector<double> v_dummyVector;
612 0 : if(wrongSpwId(spwId)) return v_dummyVector;
613 0 : v_dummyVector.push_back(getChanFreq(spwId, chanIdx).get(units));
614 0 : for(unsigned int n = 0; n < vv_assocNature_[spwId].size(); n++) {
615 0 : if(vv_assocNature_[spwId][n] == "USB" || vv_assocNature_[spwId][n] == "LSB") {
616 0 : unsigned int assocSpwId = vv_assocSpwId_[spwId][n];
617 0 : v_dummyVector.push_back(getChanFreq(assocSpwId, chanIdx).get(units));
618 : }
619 : }
620 0 : return v_dummyVector;
621 : }
622 :
623 105 : std::vector<double> SpectralGrid::getSpectralWindow(unsigned int spwId) const
624 : {
625 105 : std::vector<double> v_chanFreq;
626 105 : if(wrongSpwId(spwId)) return v_chanFreq;
627 105 : v_chanFreq.reserve(v_numChan_[spwId]);
628 210105 : for(unsigned int n = 0; n < v_numChan_[spwId]; n++)
629 210000 : v_chanFreq.push_back(v_chanFreq_[v_transfertId_[spwId] + n]);
630 105 : return v_chanFreq;
631 : }
632 :
633 0 : Frequency SpectralGrid::getMinFreq() const
634 : {
635 0 : return Frequency(v_minFreq_[0], Frequency::UnitHertz);
636 : }
637 0 : Frequency SpectralGrid::getMinFreq(unsigned int spwId) const
638 : {
639 0 : if(wrongSpwId(spwId)) return 32767.;
640 0 : return Frequency(v_minFreq_[spwId], Frequency::UnitHertz);
641 : }
642 :
643 0 : Frequency SpectralGrid::getMaxFreq() const
644 : {
645 0 : return Frequency(v_maxFreq_[0], Frequency::UnitHertz);
646 : }
647 0 : Frequency SpectralGrid::getMaxFreq(unsigned int spwId) const
648 : {
649 0 : if(wrongSpwId(spwId)) return 32767.;
650 0 : return Frequency(v_maxFreq_[spwId], Frequency::UnitHertz);
651 : }
652 :
653 0 : double SpectralGrid::getChanNum(double freq) const
654 : {
655 0 : if(v_numChan_[0] == 1) return 1;
656 0 : if(v_chanSep_[0] == 0.0) { // irregular grid, look for the nearest channel
657 0 : double sep = 1.E30;
658 0 : int k = -1;
659 0 : for(unsigned int i = 0; i < v_numChan_[0]; i++) {
660 0 : if(sep > fabs(v_chanFreq_[v_transfertId_[0] + i] - freq)) {
661 0 : sep = fabs(v_chanFreq_[v_transfertId_[0] + i] - freq);
662 0 : k = i;
663 : }
664 : }
665 0 : return (double) 1 - v_refChan_[0] + k; // channel the nearest
666 : } else { // regular spectral grid
667 0 : return (freq - v_refFreq_[0]) / v_chanSep_[0];
668 : }
669 : }
670 0 : double SpectralGrid::getChanNum(unsigned int spwId, double freq) const
671 : {
672 0 : if(wrongSpwId(spwId)) return 32767.;
673 0 : if(v_numChan_[spwId] == 1) return 1;
674 0 : if(v_chanSep_[spwId] == 0.0) { // irregular grid, look for the nearest channel
675 0 : double sep = 1.E30;
676 0 : int k = -1;
677 0 : for(unsigned int i = 0; i < v_numChan_[spwId]; i++) {
678 0 : if(sep > fabs(v_chanFreq_[v_transfertId_[spwId] + i] - freq)) {
679 0 : sep = fabs(v_chanFreq_[v_transfertId_[spwId] + i] - freq);
680 0 : k = i;
681 : }
682 : }
683 0 : return (double) 1 - v_refChan_[spwId] + k; // channel the nearest
684 : } else { // regular spectral grid
685 0 : return (freq - v_refFreq_[spwId]) / v_chanSep_[spwId];
686 : }
687 : }
688 :
689 0 : Frequency SpectralGrid::getBandwidth() const
690 : {
691 0 : return Frequency(v_maxFreq_[0] - v_minFreq_[0], Frequency::UnitHertz);
692 : }
693 :
694 0 : Frequency SpectralGrid::getBandwidth(unsigned int spwId) const
695 : {
696 0 : if(wrongSpwId(spwId)) return 32767.;
697 0 : return Frequency(v_maxFreq_[spwId] - v_minFreq_[spwId], Frequency::UnitHertz);
698 : }
699 :
700 0 : bool SpectralGrid::isRegular() const
701 : {
702 0 : if(v_chanSep_[0] == 0.0) return false;
703 0 : return true;
704 : }
705 :
706 0 : bool SpectralGrid::isRegular(unsigned int spwId) const
707 : {
708 0 : if(wrongSpwId(spwId)) return false;
709 0 : if(v_chanSep_[spwId] == 0.0) return false;
710 0 : return true;
711 : }
712 :
713 0 : std::string SpectralGrid::getSidebandSide(unsigned int spwId) const
714 : {
715 0 : if(!wrongSpwId(spwId)) {
716 0 : if(vv_assocSpwId_[spwId].size() == 0) {
717 : /* cout << "WARNING: the spectral window with the identifier "<< spwId
718 : << " has no associated spectral window "<< endl; */
719 0 : return "";
720 : }
721 0 : if(v_sidebandSide_[spwId] == NOSB) return "NoSB";
722 0 : if(v_sidebandSide_[spwId] == LSB) return "LSB";
723 0 : if(v_sidebandSide_[spwId] == USB) return "USB";
724 : }
725 0 : return "";
726 : }
727 :
728 0 : std::string SpectralGrid::getSidebandType(unsigned int spwId) const
729 : {
730 0 : if(!wrongSpwId(spwId)) {
731 0 : if(vv_assocSpwId_[spwId].size() == 0) {
732 : /* cout << "WARNING: the spectral window with the identifier "<< spwId
733 : << " has no associated spectral window "<< endl; */
734 : }
735 0 : return "";
736 : if(v_sidebandType_[spwId] == DSB) return " DSB";
737 : if(v_sidebandType_[spwId] == SSB) return " SSB";
738 : if(v_sidebandType_[spwId] == TWOSB) return " 2SB";
739 : }
740 0 : return "";
741 : }
742 :
743 0 : std::string SpectralGrid::getSideband(unsigned int spwId) const
744 : {
745 0 : if(!wrongSpwId(spwId)) {
746 0 : if(vv_assocSpwId_[spwId].size() == 0) {
747 : /* cout << "WARNING: the spectral window with the identifier "<< spwId
748 : << " has no associated spectral window "<< endl; */
749 : }
750 0 : return "";
751 : if(getSidebandSide(spwId) == "NoSB") {
752 : return getSidebandSide(spwId);
753 : } else {
754 : std::string sbTypeSide = getSidebandSide(spwId) + " with type ";
755 : return (sbTypeSide + getSidebandType(spwId));
756 : }
757 : }
758 0 : return "";
759 : }
760 :
761 0 : std::vector<std::string> SpectralGrid::getAssocNature(unsigned int spwId) const
762 : {
763 0 : if(!wrongSpwId(spwId)) {
764 0 : if(vv_assocNature_[spwId].size() == 0) {
765 : /* cout << "WARNING: the spectral window with the identifier "<< spwId
766 : << " has no associated spectral window "<< endl; */
767 : }
768 0 : return vv_assocNature_[spwId];
769 : }
770 0 : std::vector<std::string> v_dummyVector;
771 0 : return v_dummyVector;
772 : }
773 :
774 0 : std::vector<unsigned int> SpectralGrid::getAssocSpwId(unsigned int spwId) const
775 : {
776 0 : if(!wrongSpwId(spwId)) {
777 0 : if(vv_assocSpwId_[spwId].size() == 0) {
778 : /* cout << "WARNING: the spectral window with the identifier "<< spwId
779 : << " has no associated spectral window "<< endl; */
780 : /* cout << "vv_assocSpwId_[" <<spwId<<"]=" << vv_assocSpwId_[spwId][0] << endl; */
781 : }
782 0 : return vv_assocSpwId_[spwId];
783 :
784 : }
785 0 : std::vector<unsigned int> v_dummyVector;
786 0 : return v_dummyVector;
787 : }
788 :
789 0 : std::vector<unsigned int> SpectralGrid::getAssocSpwIds(const std::vector<unsigned int> &spwIds) const
790 : {
791 :
792 : unsigned int spwId;
793 0 : std::vector<unsigned int> assoc_spwIds;
794 :
795 0 : for(unsigned int n = 0; n < spwIds.size(); n++) {
796 :
797 0 : spwId = spwIds[n];
798 :
799 0 : if(!wrongSpwId(spwId)) {
800 0 : if(vv_assocSpwId_[spwId].size() == 0) {
801 : /* cout << "WARNING: the spectral window with the identifier "<< spwId
802 : << " has no associated spectral window "<< endl; */
803 : /* cout << "vv_assocSpwId_[" <<spwId<<"]=" << vv_assocSpwId_[spwId][0] << endl; */
804 : }
805 :
806 0 : assoc_spwIds.push_back((vv_assocSpwId_[spwId])[0]);
807 :
808 : } else {
809 0 : assoc_spwIds.push_back(spwId);
810 : }
811 :
812 : }
813 :
814 0 : return assoc_spwIds;
815 :
816 : }
817 :
818 0 : double SpectralGrid::getLoFrequency() const
819 : {
820 0 : return v_loFreq_[0];
821 : }
822 :
823 0 : double SpectralGrid::getLoFrequency(unsigned int spwId) const
824 : {
825 0 : if(wrongSpwId(spwId)) return 32767.;
826 0 : return v_loFreq_[spwId];
827 : }
828 :
829 : ATM_NAMESPACE_END
830 :
|