[1738] | 1 | // ArchTOIPipe (C) CEA/DAPNIA/SPP IN2P3/LAL
|
---|
| 2 | // Eric Aubourg
|
---|
| 3 | // Christophe Magneville
|
---|
| 4 | // Reza Ansari
|
---|
| 5 | // $Id: fits2ascii.cc,v 1.3 2001-11-08 15:47:44 aubourg Exp $
|
---|
| 6 |
|
---|
[1463] | 7 | #include <unistd.h>
|
---|
| 8 | #include <stdexcept>
|
---|
| 9 | #include "toi.h"
|
---|
| 10 | #include "toiprocessor.h"
|
---|
| 11 | #include "fitstoirdr.h"
|
---|
| 12 | #include "fitstoiwtr.h"
|
---|
| 13 | #include "toimanager.h"
|
---|
| 14 | #include "toiseqbuff.h"
|
---|
| 15 | #include "asciitoiwtr.h"
|
---|
| 16 |
|
---|
| 17 | void usage(void);
|
---|
| 18 | void usage(void) {
|
---|
| 19 | cout<<"fits2ascii [-h] [-s samplemin,samplemax] [-w data_window_size]"
|
---|
| 20 | <<" fitsin asciiout"<<endl;
|
---|
| 21 | return;
|
---|
| 22 | }
|
---|
| 23 |
|
---|
| 24 | ////////////////////////////////////////////////////////////////
|
---|
| 25 | int main(int narg, char** arg) {
|
---|
| 26 |
|
---|
| 27 | TOIManager* mgr = TOIManager::getManager();
|
---|
| 28 |
|
---|
| 29 | //-- Decodage arguments
|
---|
| 30 | long sdeb,sfin;
|
---|
| 31 | int width = 8192;
|
---|
[1476] | 32 | int c;
|
---|
[1463] | 33 | while((c = getopt(narg,arg,"hs:w:")) != -1) {
|
---|
| 34 | switch (c) {
|
---|
| 35 | case 's' :
|
---|
| 36 | sscanf(optarg,"%ld,%ld",&sdeb,&sfin);
|
---|
| 37 | cout<<"Requested Samples from "<<sdeb<<" , "<<sfin<<endl;
|
---|
| 38 | if(sfin>=sdeb) mgr->setRequestedSample(sdeb,sfin);
|
---|
| 39 | else {cout<<"Bad sample interval "<<endl; exit(-2);}
|
---|
| 40 | break;
|
---|
| 41 | case 'w' :
|
---|
| 42 | sscanf(optarg,"%d",&width);
|
---|
| 43 | if(width<=0) width=8192;
|
---|
| 44 | cout<<"Data window size "<<width<<endl;
|
---|
| 45 | break;
|
---|
| 46 | case 'h' :
|
---|
| 47 | usage(); exit(-1);
|
---|
| 48 | }
|
---|
| 49 | }
|
---|
| 50 | if(optind+1>=narg) {usage(); exit(-2);}
|
---|
| 51 |
|
---|
| 52 | /////////////////////////////////////
|
---|
| 53 | try {
|
---|
| 54 | FITSTOIReader r(arg[optind]);
|
---|
| 55 | ASCIITOIWriter w(arg[optind+1]);
|
---|
| 56 |
|
---|
| 57 | int ncol = r.getNOut();
|
---|
| 58 | cout<<"Number of columns in fits file : "<<ncol<<endl;
|
---|
| 59 | if(ncol<=0) exit(-3);
|
---|
| 60 |
|
---|
| 61 | TOISeqBuffered **toi = new TOISeqBuffered *[ncol];
|
---|
[1476] | 62 | int i;
|
---|
| 63 | for(i=0;i<ncol;i++) {
|
---|
[1463] | 64 | string col = r.getOutName(i);
|
---|
| 65 | toi[i] = new TOISeqBuffered(col,width);
|
---|
| 66 | cout<<"...got TOI "<<col<<endl;
|
---|
| 67 | r.addOutput(col,toi[i]);
|
---|
| 68 | w.addInput(col,toi[i]);
|
---|
| 69 | }
|
---|
| 70 |
|
---|
| 71 | r.start();
|
---|
| 72 | w.start();
|
---|
| 73 |
|
---|
| 74 | mgr->joinAll();
|
---|
| 75 |
|
---|
| 76 | r.PrintStatus(cout);
|
---|
| 77 | w.PrintStatus(cout);
|
---|
| 78 |
|
---|
[1476] | 79 | for(i=0;i<ncol;i++) if(toi[i]) delete toi[i];
|
---|
[1463] | 80 | delete toi;
|
---|
| 81 |
|
---|
| 82 | } catch (PThrowable & exc) {
|
---|
| 83 | cout << "\nfits2ascii: Catched Exception \n" << (string)typeid(exc).name()
|
---|
| 84 | << " - Msg= " << exc.Msg() << endl;
|
---|
| 85 | } catch (const std::exception & sex) {
|
---|
| 86 | cout << "\nfits2ascii: Catched std::exception \n"
|
---|
| 87 | << (string)typeid(sex).name() << endl;
|
---|
| 88 | } catch (...) {
|
---|
| 89 | cout << "\nfits2ascii: some other exception was caught ! " << endl;
|
---|
| 90 | }
|
---|
| 91 |
|
---|
| 92 | return(0);
|
---|
| 93 | }
|
---|