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

Last change on this file since 2386 was 1760, checked in by aubourg, 24 years ago

salete de magique

File size: 2.3 KB
Line 
1// ArchTOIPipe (C) CEA/DAPNIA/SPP IN2P3/LAL
2// Eric Aubourg
3// Christophe Magneville
4// Reza Ansari
5// $Id: fits2ascii.cc,v 1.4 2001-11-13 16:01:38 aubourg Exp $
6
7#include <unistd.h>
8#include "toi.h"
9#include "toiprocessor.h"
10#include "fitstoirdr.h"
11#include "fitstoiwtr.h"
12#include "toimanager.h"
13#include "toiseqbuff.h"
14#include "asciitoiwtr.h"
15#include <stdexcept>
16
17void usage(void);
18void usage(void) {
19 cout<<"fits2ascii [-h] [-s samplemin,samplemax] [-w data_window_size]"
20 <<" fitsin asciiout"<<endl;
21 return;
22}
23
24////////////////////////////////////////////////////////////////
25int main(int narg, char** arg) {
26
27TOIManager* mgr = TOIManager::getManager();
28
29//-- Decodage arguments
30long sdeb,sfin;
31int width = 8192;
32int c;
33while((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}
50if(optind+1>=narg) {usage(); exit(-2);}
51
52/////////////////////////////////////
53try {
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];
62 int i;
63 for(i=0;i<ncol;i++) {
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
79 for(i=0;i<ncol;i++) if(toi[i]) delete toi[i];
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
92return(0);
93}
Note: See TracBrowser for help on using the repository browser.