1 | #include "sopnamsp.h"
|
---|
2 | #include "machdefs.h"
|
---|
3 | #include <stdio.h>
|
---|
4 | #include <stdlib.h>
|
---|
5 | #include "math.h"
|
---|
6 | #include <iostream>
|
---|
7 | #include <string>
|
---|
8 |
|
---|
9 | #include <typeinfo>
|
---|
10 | #include "timing.h"
|
---|
11 | #include "histinit.h"
|
---|
12 | #include "array.h"
|
---|
13 | #include "fitsinoutfile.h"
|
---|
14 | #include "fitsblkrw.h"
|
---|
15 | #include "fitsarrhand.h"
|
---|
16 | #include "fiosinit.h"
|
---|
17 |
|
---|
18 | /* Programme test des classes NFits */
|
---|
19 | /* SOPHYA - R. Ansari (LAL) - Sep 2005 */
|
---|
20 |
|
---|
21 | int tsfitsReadFile(string& flnm);
|
---|
22 |
|
---|
23 | int main(int narg, char* arg[])
|
---|
24 | {
|
---|
25 | cout << " ---- Programme tnfits - Test classes NFits --- " << endl;
|
---|
26 | if ( (narg > 1) && (strcmp(arg[1],"-h")==0) ) {
|
---|
27 | cout << " Usage : tnfits [InputFitsFileName] " << endl;
|
---|
28 | return 1;
|
---|
29 | }
|
---|
30 | int rc = 0;
|
---|
31 | try {
|
---|
32 | SophyaInit();
|
---|
33 | FitsIOServerInit();
|
---|
34 | InitTim();
|
---|
35 | if (narg > 1) { // Lecture fichier entree
|
---|
36 | string flnm = arg[1];
|
---|
37 | cout << "1/=== Lecture fichier FITS : " << flnm << endl;
|
---|
38 | FitsInOutFile fios(flnm, FitsInOutFile::Fits_RO);
|
---|
39 | fios.Print();
|
---|
40 | bool encore = true;
|
---|
41 | while (encore) {
|
---|
42 | cout << " HDU No" << fios.CurrentHDU() << " Type= "
|
---|
43 | << fios.CurrentHDUTypeStr() << endl;
|
---|
44 | DVList dvl;
|
---|
45 | fios.GetHeaderRecords(dvl);
|
---|
46 | cout << dvl;
|
---|
47 | if (fios.CurrentHDUType() == IMAGE_HDU) {
|
---|
48 | long naxes[5] = {0,0,0,0,0};
|
---|
49 | int naxis=5;
|
---|
50 | fios.GetImageHDUInfo(naxis, naxes);
|
---|
51 | cout << "--GetImageHDUInfo() naxis= " << naxis << " : "
|
---|
52 | << naxes[0] << 'x' << naxes[1] << 'x' << naxes[2] << endl;
|
---|
53 | if (naxis == 2) {
|
---|
54 | cout << "---Reading Matrix ... mx= " << endl;
|
---|
55 | Matrix mx(naxes[1], naxes[0]);
|
---|
56 | FitsBlockRW<double>::ReadImageData(fios, mx.Data(), mx.Size());
|
---|
57 | cout << mx;
|
---|
58 | }
|
---|
59 | }
|
---|
60 | else {
|
---|
61 | vector<string> colnames;
|
---|
62 | vector<int> coltypes;
|
---|
63 | vector<long> repcnt;
|
---|
64 | vector<long> width;
|
---|
65 | int ncols = fios.GetColInfo(colnames, coltypes, repcnt, width);
|
---|
66 | cout << " NCols from GetColInfo = " << ncols << endl;
|
---|
67 | for(int kk=0; kk<colnames.size(); kk++) {
|
---|
68 | cout << " kk=" << kk << " ColName= " << colnames[kk]
|
---|
69 | << " Type= " << coltypes[kk]
|
---|
70 | << " Repeat= " << repcnt[kk]
|
---|
71 | << " W= " << width[kk] << endl;
|
---|
72 | }
|
---|
73 | }
|
---|
74 | if (fios.CurrentHDU() < fios.NbHDUs())
|
---|
75 | fios.MoveRelToHDU(1);
|
---|
76 | else encore = false;
|
---|
77 | }
|
---|
78 | } // ---- Fin lecture fichier entree
|
---|
79 | {
|
---|
80 | cout << "2/=== Ecriture BinTable dans toto.fits " << endl;
|
---|
81 | FitsInOutFile fiosc("!toto.fits", FitsInOutFile::Fits_Create);
|
---|
82 | // cout << " CurrHDU-1 : " << fiosc.CurrentHDU()
|
---|
83 | // << " Type=" << fiosc.CurrentHDUType() <<endl;
|
---|
84 | long naxes[5] = {5,5,0,0,0};
|
---|
85 | fiosc.CreateImageHDU(FLOAT_IMG, 2, naxes);
|
---|
86 | float data[100];
|
---|
87 | double data2[100];
|
---|
88 | string sdata[100];
|
---|
89 | MuTyV mtv;
|
---|
90 | for(int kk=0; kk<100; kk++) {
|
---|
91 | data[kk] = kk/5.;
|
---|
92 | data2[kk] = cos(data[kk]);
|
---|
93 | mtv = kk;
|
---|
94 | sdata[kk] = "Str_KK=";
|
---|
95 | sdata[kk] += (string)(mtv);
|
---|
96 | }
|
---|
97 | cout << " CurrHDU-2 : " << fiosc.CurrentHDU()
|
---|
98 | << " Type=" << fiosc.CurrentHDUType() <<endl;
|
---|
99 | FitsBlockRW<float>::WriteImageData(fiosc, data, 25);
|
---|
100 | fiosc.Print();
|
---|
101 | /*
|
---|
102 | char * ttype[2] = {"Col1", "Col2"};
|
---|
103 | char * tform[2] = {"E", "D"};
|
---|
104 | char * tunit[2] = {"", ""};
|
---|
105 | fiosc.CreateTable(BINARY_TBL, "rzbintbl", 2, ttype, tform, tunit);
|
---|
106 | */
|
---|
107 | vector<string> ttype, tform, tunit;
|
---|
108 | ttype.push_back("Col1");
|
---|
109 | ttype.push_back("Col2");
|
---|
110 | ttype.push_back("Col3");
|
---|
111 | tform.push_back("E");
|
---|
112 | tform.push_back("D");
|
---|
113 | tform.push_back("18A");
|
---|
114 | tunit.push_back("");
|
---|
115 | tunit.push_back("");
|
---|
116 | tunit.push_back("");
|
---|
117 | string tblnm = "rzbintbl";
|
---|
118 | fiosc.CreateTable(BINARY_TBL, "rzbintbl", ttype, tform, tunit);
|
---|
119 |
|
---|
120 | // cout << " MovRelToHDU , Type=" << fiosc.MoveRelToHDU(1) << endl;
|
---|
121 | cout << " CurrHDU-3 : " << fiosc.CurrentHDU()
|
---|
122 | << " Type=" << fiosc.CurrentHDUType() <<endl;
|
---|
123 | fiosc.Print();
|
---|
124 | /*
|
---|
125 | cout << " DBG- fios.InsertColumn(1,Col1,E) " << endl;
|
---|
126 | fios.InsertColumn(1,"Col1","E");
|
---|
127 | cout << " DBG- fios.InsertColumn(2,Col2,D) " << endl;
|
---|
128 | fios.InsertColumn(2,"Col2","D");
|
---|
129 | */
|
---|
130 | FitsBlockRW<float>::WriteColumnData(fiosc, 1, 1, 1, data, 100);
|
---|
131 | FitsBlockRW<double>::WriteColumnData(fiosc, 2, 1, 1, data2, 100);
|
---|
132 | FitsBlockRW<string>::WriteColumnData(fiosc, 3, 1, 1, sdata, 100);
|
---|
133 |
|
---|
134 | // Ecriture entete
|
---|
135 | DVList dvl;
|
---|
136 | dvl("toto") = 14; dvl("titi") = 25.5;
|
---|
137 | dvl("tata") = "Bonjour !";
|
---|
138 | dvl("hello") = 88; dvl("Hello") = 77.77;
|
---|
139 | dvl.Comment() = "Blabla ... zone commentaire ds DVList";
|
---|
140 | fiosc.WriteHeaderRecords(dvl);
|
---|
141 | }
|
---|
142 |
|
---|
143 | {
|
---|
144 | cout << "3/=== Ecriture tableaux dans ta.fits " << endl;
|
---|
145 | FitsInOutFile fiosc("!ta.fits", FitsInOutFile::Fits_Create);
|
---|
146 | cout << " TArray<r_4> mxf(100,50,3) , TMatrix<int_4> mxi(60,30) " << endl;
|
---|
147 | TArray<r_4> mxf(100,50,3);
|
---|
148 | mxf = RegularSequence(0., 0.2);
|
---|
149 | mxf.Info()["info1"] = "info1: TArray<r_4>";
|
---|
150 | mxf.Info()["info2"] = "info2: (100,50,3)";
|
---|
151 | mxf.Info()["info3 "] = "info3: mot-cle-avec-blanc";
|
---|
152 | cout << mxf.Info();
|
---|
153 | TMatrix<int_4> mxi(60,30);
|
---|
154 | mxi = RegularSequence();
|
---|
155 | mxi.Info()["MtxNRow"] = mxi.NRows();
|
---|
156 | mxi.Info()["MtxNCol"] = mxi.NCols();
|
---|
157 | mxi.Info()["MtxStr"] = "TMatrix<int_4> mxi(60,30)";
|
---|
158 | fiosc << mxf << mxi ;
|
---|
159 | }
|
---|
160 | {
|
---|
161 | cout << "4/=== Lecture tableaux depuis ta.fits " << endl;
|
---|
162 | FitsInOutFile fiosc("ta.fits", FitsInOutFile::Fits_RO);
|
---|
163 | TArray<r_4> mxf;
|
---|
164 | TMatrix<int_4> mxi;
|
---|
165 | fiosc >> mxf >> mxi ;
|
---|
166 | cout << mxf;
|
---|
167 | cout << " mxf.Info()= " << mxf.Info() << mxi;
|
---|
168 | cout << " mxi.Info()= " << mxi.Info() << mxi;
|
---|
169 | }
|
---|
170 |
|
---|
171 | }
|
---|
172 | catch (PThrowable & exc) {
|
---|
173 | cerr << " tnfits.cc: Catched Exception (PThrowable)" << (string)typeid(exc).name()
|
---|
174 | << "\n...exc.Msg= " << exc.Msg() << endl;
|
---|
175 | rc = 99;
|
---|
176 | }
|
---|
177 | catch (std::exception & e) {
|
---|
178 | cerr << " tnfits.cc: Catched std::exception "
|
---|
179 | << " - what()= " << e.what() << endl;
|
---|
180 | rc = 98;
|
---|
181 | }
|
---|
182 | catch (...) {
|
---|
183 | cerr << " tnfits.cc: some other exception (...) was caught ! " << endl;
|
---|
184 | rc = 97;
|
---|
185 | }
|
---|
186 | PrtTim("End tnfits " );
|
---|
187 | cout << " ---- Programme tnfits.cc- FIN (Rc=" << rc << ") --- " << endl;
|
---|
188 | return rc;
|
---|
189 | }
|
---|