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