source: Sophya/trunk/ArchTOIPipe/TestPipes/fits2ascii.cc@ 1676

Last change on this file since 1676 was 1476, checked in by ansari, 24 years ago

compil/portage SGI-CC - Reza 23/4/2001

File size: 2.1 KB
Line 
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
11void usage(void);
12void usage(void) {
13 cout<<"fits2ascii [-h] [-s samplemin,samplemax] [-w data_window_size]"
14 <<" fitsin asciiout"<<endl;
15 return;
16}
17
18////////////////////////////////////////////////////////////////
19int main(int narg, char** arg) {
20
21TOIManager* mgr = TOIManager::getManager();
22
23//-- Decodage arguments
24long sdeb,sfin;
25int width = 8192;
26int c;
27while((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}
44if(optind+1>=narg) {usage(); exit(-2);}
45
46/////////////////////////////////////
47try {
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 int i;
57 for(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(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
86return(0);
87}
Note: See TracBrowser for help on using the repository browser.