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