Line data Source code
1 : /******************************************************************************* 2 : * ALMA - Atacama Large Millimeter Array 3 : * (c) Instituto de Estructura de la Materia, 2011 4 : * (in the framework of the ALMA collaboration). 5 : * All rights reserved. 6 : * 7 : * This library is free software; you can redistribute it and/or 8 : * modify it under the terms of the GNU Lesser General Public 9 : * License as published by the Free Software Foundation; either 10 : * version 2.1 of the License, or (at your option) any later version. 11 : * 12 : * This library 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 GNU 15 : * Lesser General Public License for more details. 16 : * 17 : * You should have received a copy of the GNU Lesser General Public 18 : * License along with this library; if not, write to the Free Software 19 : * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 20 : *******************************************************************************/ 21 : 22 : #include <iostream> 23 : #include <vector> 24 : #include <string> 25 : using namespace std; 26 : 27 : #include <limits> 28 : #include <math.h> 29 : 30 : 31 : #include <atmosphere/ATM/ATMSpectralGrid.h> 32 : 33 : 34 : 35 : #include <iostream> 36 : using namespace atm; 37 : /** \brief A C++ main code to test the <a href="classatm_1_1SpectralGrid.html">SpectralGrid</a> Class 38 : * 39 : * Test 1 is structured as follows: 40 : * - Creates a pointer called "sgPtr1" of objects belonging to the class <a href="classatm_1_1SpectralGrid.html">SpectralGrid</a> 41 : * - Initializes that pointer with a first object created with the <a href="classatm_1_1SpectralGrid.html#a1">this</a> constructor. 42 : * - The pointer has then one element . On this element, several things are checked using the following operators of the class: 43 : * <a href="classatm_1_1SpectralGrid.html#z14_6">getRefFreq(unsigned int spwId)</a>, 44 : * <a href="classatm_1_1SpectralGrid.html#z14_8">getChanSep(unsigned int spwId)</a>, 45 : * <a href="classatm_1_1SpectralGrid.html#z14_0">getNumSpectralWindow()</a>, and 46 : * <a href="classatm_1_1SpectralGrid.html#z14_2">getNumChan(unsigned int spwId)</a>. 47 : * - An rrror message is expected when trying getNumChan(1) because there is no spectral window number 1. 48 : * - Finally, the operators <a href="classatm_1_1SpectralGrid.html#z14_22">isRegular(unsigned int spwId)</a>, 49 : * and <a href="classatm_1_1SpectralGrid.html#z14_25">getAssocSpwId(unsigned int spwId)</a> are tested. 50 : * 51 : * The ouput of this test should be as follows: 52 : * 53 : * <b> 54 : * SpectralGridTest: Test 1: <br> 55 : * SpectralGridTest: Create a pointer with first element construted with SpectralGrid(usigned int numChan, unsigned int refChan, Frequency refFreq, Frequency chanSep):<br> 56 : * SpectralGridTest: Number of channels retrieved: 64 (Value entered to constructor:64)<br> 57 : * SpectralGridTest: Reference frequency retrieved: 9e+10 Hz; SpectralGridTest: Input:90 GHz<br> 58 : * SpectralGridTest: Reference frequency retrieved: 90GHz SpectralGridTest: Input:90 GHz<br> 59 : * SpectralGridTest: Reference channel retrieved: 32 (Value entered to constructor:32)<br> 60 : * SpectralGridTest: Channel separation retrieved: 1e+07 Hz; SpectralGridTest: Input:0.01 GHz<br> 61 : * SpectralGridTest: Channel separation retrieved: 10000 kHz SpectralGridTest: Input:0.01 GHz<br> 62 : * SpectralGridTest: Number of spectral windows: 1<br> 63 : * SpectralGridTest: Number of channels for spectral window identifier 0: 64<br> 64 : * SpectralGrid: ERROR: 1 is a wrong spectral window identifier<br> 65 : * SpectralGridTest: Number of channels for spectral window identifier 1: 0<br> 66 : * SpectralGridTest: the first spectral window is regularily sampled<br> 67 : * SpectralGridTest: First spectral window has no associated spectral windows<br> 68 : * SpectralGridTest: End of Test 1<br> 69 : * </b> 70 : * 71 : * Test 2 starts from the pointer created in Test 1: 72 : * - A new spectral window is added with 128 channels, channel number 32 as the reference channel, reference frequency at 215 GHz, and regular channel separation of 0.02 GHz. 73 : * This new spectral window is added using <a href="classatm_1_1SpectralGrid.html#a11">add(unsigned int numChan, unsigned int refChan, Frequency refFreq, Frequency chanSep)</a> 74 : * - The next step is to verify that nothing has change for spectral window number 0 from Test 1. 75 : * - Finally, spectral window number 1 is tested similarly to spectral window #0. 76 : * - It is also checked that spectral windows with numbers > 1 do not exist. 77 : * 78 : * The ouput of Test 2 should be as follows: 79 : * 80 : * <b> 81 : * SpectralGridTest: Test 2<br> 82 : * SpectralGridTest: New spectral window using add(unsigned int numChan, unsigned int refChan, Frequency refFreq, Frequency chanSep):<br> 83 : * SpectralGridTest: A new spectral window has been appended and got the identifier number:1<br> 84 : * SpectralGridTest: Number of spectral windows: 2<br> 85 : * SpectralGridTest: Number of channels retrieved for spwId 0: 64<br> 86 : * SpectralGridTest: Reference frequency retrieved: 90 GHz<br> 87 : * SpectralGridTest: Channel separation retrieved: 0.01 GHz GHz<br> 88 : * SpectralGridTest: Number of channels retrieved for spwId 1: 128<br> 89 : * SpectralGridTest: Reference frequency retrieved: 215 GHz<br> 90 : * SpectralGridTest: Channel separation retrieved: 0.02 GHz GHz<br> 91 : * SpectralGridTest: the spectral window with id 1 is regularily sampled<br> 92 : * SpectralGridTest: Number of spectral windows: 2<br> 93 : * SpectralGridTest: As expected this spectral window with spwid=1 has no sideband specification<br> 94 : * SpectralGrid: ERROR: 10 is a wrong spectral window identifier<br> 95 : * SpectralGridTest: Spectral window with id=10 does not exist!<br> 96 : * SpectralGridTest: End of Test 2<br> 97 : * </b> 98 : */ 99 : 100 1 : int main() 101 : { 102 : 103 : 104 1 : unsigned int numChan = 64; 105 1 : unsigned int refChan = 32; 106 : 107 2 : Frequency myRefFreq(90.0,"GHz"); 108 2 : Frequency myChanSep(0.01,"GHz"); 109 : 110 : SpectralGrid* sgPtr1; 111 : 112 1 : cout << " SpectralGridTest: Test 1:" <<endl; 113 1 : cout << " SpectralGridTest: Create a pointer with first element construted with SpectralGrid(usigned int numChan, unsigned int refChan, Frequency refFreq, Frequency chanSep):" << endl; 114 1 : sgPtr1 = new SpectralGrid(numChan, refChan, myRefFreq, myChanSep); 115 1 : cout << " SpectralGridTest: Number of channels retrieved: " << sgPtr1->getNumChan() << " (Value entered to constructor:" << numChan << ")" << endl; 116 1 : cout << " SpectralGridTest: Reference frequency retrieved: " 117 1 : << sgPtr1->getRefFreq().get() << " Hz; " 118 1 : << " SpectralGridTest: Input:" << myRefFreq.get("GHz") << " GHz" << endl; 119 1 : cout << " SpectralGridTest: Reference frequency retrieved: " 120 2 : << sgPtr1->getRefFreq().get("GHz")<< "GHz " 121 1 : <<" SpectralGridTest: Input:" << myRefFreq.get("GHz") << " GHz" << endl; 122 1 : cout << " SpectralGridTest: Reference channel retrieved: " << sgPtr1->getRefChan() << " (Value entered to constructor:" << refChan << ")" << endl; 123 1 : cout << " SpectralGridTest: Channel separation retrieved: " 124 1 : << sgPtr1->getChanSep().get() << " Hz; " 125 1 : << " SpectralGridTest: Input:" << myChanSep.get("GHz") << " GHz" << endl; 126 1 : cout << " SpectralGridTest: Channel separation retrieved: " 127 2 : << sgPtr1->getChanSep().get("kHz") << " kHz " 128 1 : << " SpectralGridTest: Input:" << myChanSep.get("GHz") << " GHz" << endl; 129 1 : cout << " SpectralGridTest: Number of spectral windows: " 130 1 : << sgPtr1->getNumSpectralWindow() << endl; 131 1 : cout << " SpectralGridTest: Number of channels for spectral window identifier 0: " 132 1 : << sgPtr1->getNumChan(0) << endl; 133 : // With RHEL 8 the error is flushed in between the cout which is calling the method 134 1 : int res = sgPtr1->getNumChan(1); 135 1 : cout << " SpectralGridTest: Number of channels for spectral window identifier 1: " 136 1 : << res << endl; 137 1 : if(sgPtr1->isRegular(0)){ 138 1 : cout << " SpectralGridTest: the first spectral window is regularily sampled" << endl; 139 : }else{ 140 0 : cout << " SpectralGridTest: the first spectral window is not regularily sampled" << endl; 141 : } 142 1 : if(sgPtr1->getAssocSpwId(0).size()==0){ 143 1 : cout<<" SpectralGridTest: First spectral window has no associated spectral windows" << endl; 144 : }else{ 145 0 : cout<<" SpectralGridTest: First spectral window has associated spectral windows "<<endl; 146 : } 147 1 : cout << " SpectralGridTest: End of Test 1" <<endl; 148 1 : cout << " " << endl; 149 : 150 : 151 : 152 : 153 1 : cout << " SpectralGridTest: Test 2" << endl; 154 1 : cout << " SpectralGridTest: New spectral window using add(unsigned int numChan, unsigned int refChan, Frequency refFreq, Frequency chanSep):" << endl; 155 1 : unsigned int numChan1 = 128; 156 1 : unsigned int refChan1 = 32; 157 2 : Frequency myNewRefFreq(215.0,"GHz"); 158 2 : Frequency myNewChanSep(0.02,"GHz"); 159 1 : unsigned int spwId = sgPtr1->add( numChan1, refChan1, myNewRefFreq, myNewChanSep); 160 1 : cout << " SpectralGridTest: A new spectral window has been appended and got the identifier number:" << spwId << endl; 161 1 : cout << " SpectralGridTest: Number of spectral windows: " 162 1 : << sgPtr1->getNumSpectralWindow() << endl; 163 : 164 1 : spwId=0; 165 1 : cout << " SpectralGridTest: Number of channels retrieved for spwId "<<spwId<<": " 166 1 : << sgPtr1->getNumChan(spwId) << endl; 167 1 : cout << " SpectralGridTest: Reference frequency retrieved: " 168 1 : << sgPtr1->getRefFreq(spwId).get("GHz") << " GHz" << endl; 169 1 : cout << " SpectralGridTest: Channel separation retrieved: " 170 1 : << sgPtr1->getChanSep(spwId).get("GHz") << " GHz " << "GHz" << endl; 171 : 172 1 : spwId=1; 173 1 : cout << " SpectralGridTest: Number of channels retrieved for spwId "<<spwId<<": " 174 1 : << sgPtr1->getNumChan(spwId) << endl; 175 1 : cout << " SpectralGridTest: Reference frequency retrieved: " 176 1 : << sgPtr1->getRefFreq(spwId).get("GHz") << " GHz" << endl; 177 1 : cout << " SpectralGridTest: Channel separation retrieved: " 178 1 : << sgPtr1->getChanSep(spwId).get("GHz") << " GHz " << "GHz" << endl; 179 : 180 1 : if(sgPtr1->isRegular(spwId)){ 181 1 : cout << " SpectralGridTest: the spectral window with id "<<spwId<<" is regularily sampled" << endl; 182 : }else{ 183 0 : cout << " SpectralGridTest: the spectral window with id "<<spwId<<" is not regularily sampled" << endl; 184 : } 185 : 186 1 : cout << " SpectralGridTest: Number of spectral windows: " 187 1 : << sgPtr1->getNumSpectralWindow() << endl; 188 : 189 1 : if(sgPtr1->getSideband(spwId).size()==0) 190 1 : cout << " SpectralGridTest: As expected this spectral window with spwid="<<spwId 191 1 : << " has no sideband specification" << endl; 192 1 : unsigned int id=10; 193 1 : if(sgPtr1->getSideband(id).size()==0) 194 1 : cout << " SpectralGridTest: Spectral window with id="<<id 195 1 : << " does not exist!" << endl; 196 1 : cout << " SpectralGridTest: End of Test 2" <<endl; 197 : 198 : 199 : 200 : 201 : 202 : 203 : 204 1 : cout << " SpectralGridTest: Channel frequency and number for the first spectral window: " << endl; 205 1 : double chFreq[sgPtr1->getNumChan()]; // one dynamic alloc 206 1 : vector<double> chanFreq; 207 1 : chanFreq.reserve(sgPtr1->getNumChan()); // a more versatil dynamic alloc (allowing eg resizing) 208 : 209 65 : for(int i=0; i<(int)sgPtr1->getNumChan(); i++){ 210 64 : chanFreq[i] = sgPtr1->getChanFreq(i).get(); 211 64 : chFreq[i] = chanFreq[i]; 212 64 : cout << "SpectralGridTest: " << i << " channel: " << i-(int)refChan+1 << " freq: " << chanFreq[i] << endl; 213 : } 214 1 : cout << endl; 215 : 216 1 : delete sgPtr1; sgPtr1=0; 217 : 218 : 219 : 220 1 : double refFreq = 90.0E9; 221 : 222 : SpectralGrid* sgPtr2; 223 1 : cout << " SpectralGridTest: Test 2:" <<endl; 224 1 : cout << " SpectralGridTest: Build using SpectralGrid( unsigned int numChan, unsigned int refChan, double* chFreq, string units):" << endl; 225 1 : sgPtr2 = new SpectralGrid( numChan, refChan, chFreq, Frequency::UnitHertz); 226 1 : cout << " SpectralGridTest: Number of channels retrieved: " << sgPtr2->getNumChan() << " Input: " << numChan << endl; 227 1 : cout << " SpectralGridTest: Reference frequency retrieved:" << sgPtr2->getRefFreq().get() << "Hz Initial: none" << endl; 228 1 : cout << " SpectralGridTest: Reference frequency retrieved:" << sgPtr2->getRefFreq().get("MHz") << "MHz Initial: none" << endl; 229 1 : cout << " SpectralGridTest: Reference channel retrieved: " << sgPtr2->getRefChan() << " Input: " << refChan << endl; 230 1 : cout << " SpectralGridTest: Channel separation retrieved: " << sgPtr2->getChanSep().get() << "Hz Initial: none" << endl; 231 1 : cout << " SpectralGridTest: Channel separation retrieved: " << sgPtr2->getChanSep().get("MHz") << "MHz Initial: none" << endl; 232 1 : if(sgPtr2->isRegular()){ 233 1 : cout << " SpectralGridTest: the first spectral window with id 0 is regularily sampled" << endl; 234 : }else{ 235 0 : cout << " SpectralGridTest: the first spectral window with id 0 is not regularily sampled" << endl; 236 : } 237 1 : chFreq[sgPtr2->getNumChan()/4]=chFreq[sgPtr2->getNumChan()/4]+1.; 238 1 : cout << " SpectralGridTest: Add a second irregular spectral window using add( unsigned int numChan, unsigned int refChan, double* chFreq, string units):" << endl; 239 1 : sgPtr2->add( numChan, refChan, chFreq, Frequency::UnitHertz); 240 1 : if(sgPtr2->isRegular()){ 241 1 : cout << " SpectralGridTest: the first spectral window with id 0 is regularily sampled as expected" << endl; 242 : }else{ 243 0 : cout << " SpectralGridTest: the first spectral window with id 0 is not regularily sampled ==> ERROR in the code" << endl; 244 : } 245 1 : if(sgPtr2->isRegular(spwId)){ 246 0 : cout << " SpectralGridTest: the spectral window with id "<<spwId<<" is regularily sampled ==> ERROR in the code" << endl; 247 : }else{ 248 1 : cout << " SpectralGridTest: the spectral window with id "<<spwId<<" is not regularily sampled as expected" << endl; 249 : } 250 1 : delete sgPtr2; sgPtr2=0; 251 : 252 1 : cout << endl; 253 1 : cout << endl; 254 : 255 : SpectralGrid* sgPtr3; 256 : 257 1 : cout << " SpectralGridTest: Test 3:" << endl; 258 1 : cout << " SpectralGridTest: Build using SpectralGrid( unsigned int numChan, double refFreq, double* chFreq, string freqUnits):" << endl; 259 1 : sgPtr3 = new SpectralGrid( numChan, refFreq, chFreq, Frequency::UnitHertz); 260 1 : cout << " SpectralGridTest: Number of channels retrieved: " << sgPtr3->getNumChan() << " Input: " << numChan << endl; 261 1 : cout << " SpectralGridTest: Reference frequency retrieved:" << sgPtr3->getRefFreq().get() << "Hz Initial:" << refFreq << "Hz" << endl; 262 1 : cout << " SpectralGridTest: Reference frequency retrieved:" << sgPtr3->getRefFreq().get("MHz") << "MHz Initial:" << refFreq << "Hz" << endl; 263 1 : cout << " SpectralGridTest: Reference channel retrieved: " << sgPtr3->getRefChan() << " Initial: " << refChan << endl; 264 1 : cout << " SpectralGridTest: Channel separation retrieved: " << sgPtr3->getChanSep().get() << " Initial: none"<< endl; 265 : 266 1 : { double chan=16.123456; 267 1 : cout << " SpectralGridTest: Position (GU) retrieved: " 268 2 : << sgPtr3->getChanNum(refFreq+(sgPtr3->getChanSep().get())*chan) 269 1 : << " SpectralGridTest: Exact: " << chan << endl; 270 : } 271 1 : cout << " SpectralGridTest: Total bandwidth retrieved: " << sgPtr3->getBandwidth().get() 272 1 : << " SpectralGridTest: Initial: "<< (sgPtr3->getChanSep().get())*(numChan-1) << endl; 273 : 274 1 : cout << " SpectralGridTest: Frequency range: from "<< sgPtr3->getMinFreq().get() <<" to "<< sgPtr3->getMaxFreq().get() <<"Hz"<< endl; 275 1 : cout << " SpectralGridTest: Frequency range: from "<< sgPtr3->getMinFreq().get("GHz") <<" to "<< sgPtr3->getMaxFreq().get("GHz") <<"GHz"<< endl; 276 : 277 1 : delete sgPtr3; 278 : 279 1 : cout << endl; 280 1 : cout << endl; 281 : 282 1 : numChan = 128; 283 1 : refChan = 64; 284 2 : Frequency refFreq2(215.0,"GHz"); 285 2 : Frequency chanSep2(0.02,"GHz"); 286 2 : Frequency intermediateFreq(2.0,"GHz"); 287 2 : Frequency bandWidth(1.0,"GHz"); 288 : // SidebandSide sbSide=LSB; 289 : // SidebandType sbType=SSB; 290 : 291 1 : sgPtr1 = new SpectralGrid(numChan, refChan, refFreq2, chanSep2, 292 1 : intermediateFreq, LSB, SSB); 293 : 294 1 : cout << " SpectralGridTest: Number of spectral windows: " << sgPtr1->getNumSpectralWindow() << " Expected: 2" << endl; 295 : 296 3 : for(unsigned int spwId=0; spwId<sgPtr1->getNumSpectralWindow(); spwId++){ 297 2 : cout << " SpectralGridTest: Sideband: " << sgPtr1->getSideband(spwId) << endl; 298 2 : cout << " SpectralGridTest: LO frequency: " << sgPtr1->getLoFrequency(spwId) << "Hz " << endl; 299 2 : cout << " SpectralGridTest: Number of channels retrieved: " << sgPtr1->getNumChan(spwId) << " for spwId " << spwId<<": " 300 2 : << " Input:" << numChan << endl; 301 2 : cout << " SpectralGridTest: Reference frequency retrieved: " << sgPtr1->getRefFreq(spwId).get() 302 2 : << " Input:" << refFreq2.get("GHz") << "GHz" << endl; 303 4 : cout << " SpectralGridTest: Reference frequency retrieved: " << sgPtr1->getRefFreq(spwId).get("GHz")<< "GHz " 304 2 : << " Input:" << refFreq2.get("GHz") << "GHz" << endl; 305 2 : cout << " SpectralGridTest: Reference channel retrieved: " << sgPtr1->getRefChan() 306 2 : << " Input:" << refChan << endl; 307 2 : cout << " SpectralGridTest: Channel separation retrieved: " << sgPtr1->getChanSep(spwId).get() << "Hz " 308 2 : << " Input: |" << chanSep2.get("GHz") << "| GHz" << endl; 309 4 : cout << " SpectralGridTest: Channel separation retrieved: " << sgPtr1->getChanSep(spwId).get("kHz") << "kHz " 310 2 : << " Input: |" << chanSep2.get("GHz") << "| GHz" << endl; 311 2 : cout << " SpectralGridTest: minFreq: " << sgPtr1->getMinFreq(spwId).get("GHz") << " GHz" << endl; 312 2 : cout << " SpectralGridTest: maxFreq: " << sgPtr1->getMaxFreq(spwId).get("GHz") << " GHz" << endl; 313 2 : cout << " SpectralGridTest: Channel (grid units) for the min: " << sgPtr1->getChanNum(spwId,sgPtr1->getMinFreq(spwId).get()) << endl; 314 2 : cout << " SpectralGridTest: Channel (grid units) for the max: " << sgPtr1->getChanNum(spwId,sgPtr1->getMaxFreq(spwId).get()) << endl; 315 : 316 2 : if(sgPtr1->isRegular(spwId)){ 317 2 : cout << " SpectralGridTest: the spectral window with id "<<spwId<<" is regularily sampled" << endl; 318 : }else{ 319 0 : cout << " SpectralGridTest: the spectral window with id "<<spwId<<" is not regularily sampled" << endl; 320 : } 321 : 322 2 : if(sgPtr1->getAssocSpwId(spwId).size()==0){ 323 0 : cout << " SpectralGridTest: the spectral window with id "<< spwId <<" has no associated spectral window" << endl; 324 : }else{ 325 4 : for(unsigned int n=0; n<sgPtr1->getAssocSpwId(spwId).size(); n++){ 326 2 : unsigned int assocSpwId = sgPtr1->getAssocSpwId(spwId)[n]; 327 2 : cout << " SpectralGridTest: the spectral window with id "<< spwId 328 2 : << " has the associated spec. win. with id " << assocSpwId 329 2 : << " (" << sgPtr1->getAssocNature(spwId)[n] << ")" << endl; 330 : 331 258 : for(unsigned int i=0; i<sgPtr1->getNumChan(spwId); i++){ 332 256 : cout << " SpectralGridTest: chan index:" << i << " " 333 512 : << sgPtr1->getSideband(spwId) <<" "<<sgPtr1->getChanFreq(spwId,i).get("GHz")<<"GHz " 334 256 : << sgPtr1->getAssocNature(spwId)[n] <<" "<<sgPtr1->getChanFreq(assocSpwId,i).get("GHz")<<"GHz"<<endl; 335 : } 336 : } 337 : } 338 2 : cout << endl; 339 : 340 : 341 : 342 : } 343 : 344 1 : cout << " SpectralGridTest: TESTBED done" << endl; 345 1 : return 0; 346 2 : } 347 :