| 1 | // ArchTOIPipe           (C)     CEA/DAPNIA/SPP IN2P3/LAL
 | 
|---|
| 2 | //                               Eric Aubourg
 | 
|---|
| 3 | //                               Christophe Magneville
 | 
|---|
| 4 | //                               Reza Ansari
 | 
|---|
| 5 | // $Id: sfftc.cc,v 1.3 2001-11-13 16:01:39 aubourg Exp $
 | 
|---|
| 6 | 
 | 
|---|
| 7 | /*   Test de processeurs ds simtoipr.cc   - Reza Avril 2001
 | 
|---|
| 8 | 
 | 
|---|
| 9 | ----------------   Exemple d'appel  ---------------------
 | 
|---|
| 10 | csh> sfftc -start 104385384 -end 104399964 
 | 
|---|
| 11 |             -intoi boloMuV_27 -wtoi 8192 -wfft 4096 inputbolo.fits sfftc.fits sfftc.ppf
 | 
|---|
| 12 | */
 | 
|---|
| 13 | 
 | 
|---|
| 14 | 
 | 
|---|
| 15 | 
 | 
|---|
| 16 | #include "machdefs.h"
 | 
|---|
| 17 | #include <math.h>
 | 
|---|
| 18 | #include "array.h"
 | 
|---|
| 19 | #include <unistd.h>
 | 
|---|
| 20 | #include "toi.h"
 | 
|---|
| 21 | #include "toiprocessor.h"
 | 
|---|
| 22 | #include "fitstoirdr.h"
 | 
|---|
| 23 | #include "fitstoiwtr.h"
 | 
|---|
| 24 | #include "toimanager.h"
 | 
|---|
| 25 | #include "simtoipr.h"
 | 
|---|
| 26 | #include "toiseqbuff.h"
 | 
|---|
| 27 | #include "timing.h"
 | 
|---|
| 28 | #include "sambainit.h"
 | 
|---|
| 29 | #include <stdexcept>
 | 
|---|
| 30 | 
 | 
|---|
| 31 | void Usage(bool fgerr)
 | 
|---|
| 32 | {
 | 
|---|
| 33 |   cout << endl;
 | 
|---|
| 34 |   if (fgerr) {
 | 
|---|
| 35 |     cout << " sfftc : Argument Error ! sfftc -h for usage " << endl; 
 | 
|---|
| 36 |     exit(1);
 | 
|---|
| 37 |   }
 | 
|---|
| 38 |   else {
 | 
|---|
| 39 |     cout << "\n Usage : sfftc [-dbg] [-start snb] [-end sne] \n" 
 | 
|---|
| 40 |          << "         [-wtoi sz] [-wfft sz] [-keepfft n] \n"
 | 
|---|
| 41 |          << "         inFitsName outFitsName  outPPFName \n" 
 | 
|---|
| 42 |          << "   -dbg : sets TOISeqBuffered debug level to 1 \n"
 | 
|---|
| 43 |          << "   -start snb : sets the start sample num \n"
 | 
|---|
| 44 |          << "   -end sne : sets the end sample num \n"
 | 
|---|
| 45 |          << "   -intoi toiName : select input TOI name (def boloMuV_27)\n"
 | 
|---|
| 46 |          << "   -wtoi sz : sets TOISeqBuff buffer size (def= 8192)\n"
 | 
|---|
| 47 |          << "   -wfft sz : sets Fourier filter width \n"
 | 
|---|
| 48 |          << "   -keepfft n : Keeps n spectra  \n" 
 | 
|---|
| 49 |          << endl;
 | 
|---|
| 50 |     exit(0);
 | 
|---|
| 51 |   }
 | 
|---|
| 52 | }
 | 
|---|
| 53 | 
 | 
|---|
| 54 | int main(int narg, char** arg) {
 | 
|---|
| 55 | 
 | 
|---|
| 56 |   if ((narg > 1) && (strcmp(arg[1],"-h") == 0) ) Usage(false);
 | 
|---|
| 57 | 
 | 
|---|
| 58 |   cout << "sfftc starting - Decoding arguments " << " narg=" << narg << endl;
 | 
|---|
| 59 | 
 | 
|---|
| 60 |   bool fgdbg = false;
 | 
|---|
| 61 |   bool fgsetstart = false;
 | 
|---|
| 62 |   int wtoi = 8192;
 | 
|---|
| 63 |   int wfft = 4096;
 | 
|---|
| 64 |   int keepfft = 0;
 | 
|---|
| 65 |   int nmax = 10;
 | 
|---|
| 66 |   int istart = 0;
 | 
|---|
| 67 |   int iend = 0;
 | 
|---|
| 68 |   string infile;
 | 
|---|
| 69 |   string outfile;
 | 
|---|
| 70 |   string outppfname;
 | 
|---|
| 71 |   string intoi = "boloMuV_27";
 | 
|---|
| 72 | 
 | 
|---|
| 73 |   if (narg < 4) Usage(true);
 | 
|---|
| 74 |   int ko=1;
 | 
|---|
| 75 |   // decoding arguments 
 | 
|---|
| 76 |   for(int ia=1; ia<narg; ia++) {
 | 
|---|
| 77 |     if (strcmp(arg[ia],"-start") == 0) {
 | 
|---|
| 78 |       if (ia == narg-1) Usage(true);  // -start est suivi d'un argument 
 | 
|---|
| 79 |       istart = atoi(arg[ia+1]); ia++;
 | 
|---|
| 80 |       fgsetstart = true;
 | 
|---|
| 81 |     }    
 | 
|---|
| 82 |     else if (strcmp(arg[ia],"-end") == 0) {
 | 
|---|
| 83 |       if (ia == narg-1) Usage(true);  
 | 
|---|
| 84 |       iend = atoi(arg[ia+1]); ia++;
 | 
|---|
| 85 |     }    
 | 
|---|
| 86 |     else if (strcmp(arg[ia],"-wtoi") == 0) {
 | 
|---|
| 87 |       if (ia == narg-1) Usage(true);  
 | 
|---|
| 88 |       wtoi = atoi(arg[ia+1]); ia++;
 | 
|---|
| 89 |     }    
 | 
|---|
| 90 |     else if (strcmp(arg[ia],"-wfft") == 0) {
 | 
|---|
| 91 |       if (ia == narg-1) Usage(true);  
 | 
|---|
| 92 |       wfft = atoi(arg[ia+1]); ia++;
 | 
|---|
| 93 |     }    
 | 
|---|
| 94 |     else if (strcmp(arg[ia],"-keepfft") == 0) {
 | 
|---|
| 95 |       if (ia == narg-1) Usage(true);  
 | 
|---|
| 96 |       keepfft = atoi(arg[ia+1]); ia++;
 | 
|---|
| 97 |     }    
 | 
|---|
| 98 |     else if (strcmp(arg[ia],"-intoi") == 0) {
 | 
|---|
| 99 |       if (ia == narg-1) Usage(true);  
 | 
|---|
| 100 |       intoi = arg[ia+1]; ia++;
 | 
|---|
| 101 |     }    
 | 
|---|
| 102 |     else if (strcmp(arg[ia],"-dbg") == 0)  fgdbg = true;
 | 
|---|
| 103 | 
 | 
|---|
| 104 |     else { ko = ia; break; }  // Debut des noms
 | 
|---|
| 105 |   }
 | 
|---|
| 106 | 
 | 
|---|
| 107 |   if (iend < istart) iend = istart+wtoi*(nmax+5);
 | 
|---|
| 108 |   if ((narg-ko) < 3)  Usage(true); 
 | 
|---|
| 109 |   infile = arg[ko];
 | 
|---|
| 110 |   outfile = arg[ko+1];
 | 
|---|
| 111 |   outppfname = arg[ko+2];
 | 
|---|
| 112 | 
 | 
|---|
| 113 |   cout << " Initializing SOPHYA ... " << endl;
 | 
|---|
| 114 |   SophyaInit();
 | 
|---|
| 115 |   InitTim();
 | 
|---|
| 116 | 
 | 
|---|
| 117 |   cout << ">>>> sfftc: Infile= " << infile << " outFile=" 
 | 
|---|
| 118 |        << outfile << endl; 
 | 
|---|
| 119 |   cout << ">>>> Window Size WTOI= " << wtoi << " WFFT= " << wfft
 | 
|---|
| 120 |        << "  iStart= " << istart << " iEnd= " << iend << endl;
 | 
|---|
| 121 |   cout << ">>>> InTOIName= " << intoi << endl;
 | 
|---|
| 122 | 
 | 
|---|
| 123 |   try {
 | 
|---|
| 124 |     TOIManager* mgr = TOIManager::getManager();
 | 
|---|
| 125 |   
 | 
|---|
| 126 |     //  mgr->setRequestedSample(11680920,11710584);
 | 
|---|
| 127 |     //  mgr->setRequestedSample(104121000, 104946120);
 | 
|---|
| 128 |     if (fgsetstart) 
 | 
|---|
| 129 |       mgr->setRequestedSample(istart, iend);
 | 
|---|
| 130 |   
 | 
|---|
| 131 |     //    FITSTOIReader r("/data/Archeops/bolo11.fits); 
 | 
|---|
| 132 |     FITSTOIReader r(infile); 
 | 
|---|
| 133 |     cout << "reader created" << endl;
 | 
|---|
| 134 |     //    FITSTOIWriter w("/data/Archeops/rz.fits");
 | 
|---|
| 135 |     FITSTOIWriter w(outfile);
 | 
|---|
| 136 |     cout << "fits writer created" << endl;
 | 
|---|
| 137 | 
 | 
|---|
| 138 | 
 | 
|---|
| 139 |     int w1 = wtoi;
 | 
|---|
| 140 |     TOISeqBuffered * toiin = new TOISeqBuffered("f2in", w1);
 | 
|---|
| 141 |     if (fgdbg) toiin->setDebugLevel(1);
 | 
|---|
| 142 |     TOISeqBuffered * toiout = new TOISeqBuffered("out", w1);
 | 
|---|
| 143 |     if (fgdbg) toiout->setDebugLevel(1);
 | 
|---|
| 144 |     TOISeqBuffered * toiincopie = new TOISeqBuffered("incopie", w1);
 | 
|---|
| 145 |     if (fgdbg) toiincopie->setDebugLevel(1);
 | 
|---|
| 146 |     
 | 
|---|
| 147 |   
 | 
|---|
| 148 |     cout << " Connecting to FitsReader ... " << endl;
 | 
|---|
| 149 |     r.addOutput(intoi, toiin);
 | 
|---|
| 150 | 
 | 
|---|
| 151 |     Vector fcoef(wfft/2);
 | 
|---|
| 152 |     fcoef = RegularSequence(1., -2./wfft);
 | 
|---|
| 153 |     cout << " Creating Fourier Filter ... " << endl;
 | 
|---|
| 154 |     SimpleFourierFilter sfft(fcoef);
 | 
|---|
| 155 |     sfft.KeepSpectra(outppfname, keepfft);
 | 
|---|
| 156 |     cout << " Connecting Fourier Filter ... " << endl;
 | 
|---|
| 157 |     sfft.addInput("in",toiin);
 | 
|---|
| 158 |     sfft.addOutput("out", toiout);
 | 
|---|
| 159 |     sfft.addOutput("incopie", toiincopie);
 | 
|---|
| 160 | 
 | 
|---|
| 161 |     cout << " Connecting to output (FitsWriter) " << endl;
 | 
|---|
| 162 |     
 | 
|---|
| 163 |     //    w.setOutFlags(true);
 | 
|---|
| 164 |     w.addInput("in", toiincopie);
 | 
|---|
| 165 |     w.addInput("out", toiout);
 | 
|---|
| 166 | 
 | 
|---|
| 167 | 
 | 
|---|
| 168 |     cout << " ------ FITSReaderTOI::PrintStatus() : ----- " << endl;
 | 
|---|
| 169 |     r.PrintStatus(cout);  
 | 
|---|
| 170 |     cout << " ------ SimpleFourierFilter::PrintStatus() : ----- " << endl;
 | 
|---|
| 171 |     sfft.PrintStatus(cout);  
 | 
|---|
| 172 |     cout << "----- FITSWriterTOI::PrintStatus() : ----- " << endl;
 | 
|---|
| 173 |     w.PrintStatus(cout);  
 | 
|---|
| 174 | 
 | 
|---|
| 175 |     PrtTim("starting threads");
 | 
|---|
| 176 |     r.start();
 | 
|---|
| 177 |     sfft.start();
 | 
|---|
| 178 |     w.start();
 | 
|---|
| 179 | 
 | 
|---|
| 180 |     /*   
 | 
|---|
| 181 |     for(int jj=0; jj<3; jj++) {
 | 
|---|
| 182 |       cout << *toiin; 
 | 
|---|
| 183 |       cout << *toiout; 
 | 
|---|
| 184 |       cout << *toiincopie; 
 | 
|---|
| 185 |       sleep(1);
 | 
|---|
| 186 |     }
 | 
|---|
| 187 |     */
 | 
|---|
| 188 |     
 | 
|---|
| 189 |     
 | 
|---|
| 190 | 
 | 
|---|
| 191 |     mgr->joinAll();
 | 
|---|
| 192 |     PrtTim("End threads");
 | 
|---|
| 193 | 
 | 
|---|
| 194 |     //    cout << " ------ FITSReaderTOI::PrintStatus() : ----- " << endl;
 | 
|---|
| 195 |     //    r.PrintStatus(cout);  
 | 
|---|
| 196 |     //    cout << "----- FITSWriterTOI::PrintStatus() : ----- " << endl;
 | 
|---|
| 197 |     //    w.PrintStatus(cout);  
 | 
|---|
| 198 | 
 | 
|---|
| 199 |     cout << " ------ toiin, toiout and toiincopie Status information ------- " << endl;
 | 
|---|
| 200 |     cout << *toiin; 
 | 
|---|
| 201 |     cout << *toiout;
 | 
|---|
| 202 |     cout << *toiincopie; 
 | 
|---|
| 203 |     
 | 
|---|
| 204 |     cout << sfft ; 
 | 
|---|
| 205 | 
 | 
|---|
| 206 |   }
 | 
|---|
| 207 |   catch (PThrowable & exc) {
 | 
|---|
| 208 |     cerr << "\n sfftc: Catched Exception \n" << (string)typeid(exc).name() 
 | 
|---|
| 209 |          << " - Msg= " << exc.Msg() << endl;
 | 
|---|
| 210 |   }
 | 
|---|
| 211 |   catch (const std::exception & sex) {
 | 
|---|
| 212 |     cerr << "\n sfftc: Catched std::exception \n" 
 | 
|---|
| 213 |          << (string)typeid(sex).name() << endl; 
 | 
|---|
| 214 |   }
 | 
|---|
| 215 |   catch (...) {
 | 
|---|
| 216 |     cerr << "\n sfftc: some other exception was caught ! " << endl;
 | 
|---|
| 217 |   }
 | 
|---|
| 218 | 
 | 
|---|
| 219 |   return(0);
 | 
|---|
| 220 | }
 | 
|---|