source: Sophya/trunk/SophyaProg/Tests/tnfits.cc@ 4080

Last change on this file since 4080 was 3619, checked in by cmv, 16 years ago

add various #include<> for g++ 4.3 (jaunty 9.04), cmv 05/05/2009

  • Property svn:executable set to *
File size: 7.7 KB
RevLine 
[2821]1#include "sopnamsp.h"
2#include "machdefs.h"
3#include <stdio.h>
4#include <stdlib.h>
[3619]5#include <string.h>
[2821]6#include "math.h"
7#include <iostream>
8#include <string>
9
10#include <typeinfo>
11#include "timing.h"
12#include "histinit.h"
13#include "array.h"
14#include "fitsinoutfile.h"
15#include "fitsblkrw.h"
16#include "fitsarrhand.h"
[2866]17#include "fiosinit.h"
[2821]18
19/* Programme test des classes NFits */
20/* SOPHYA - R. Ansari (LAL) - Sep 2005 */
21
[2935]22int tsfitsReadFile(string& flnm);
23
[2821]24int main(int narg, char* arg[])
25{
26 cout << " ---- Programme tnfits - Test classes NFits --- " << endl;
[2935]27 if ( (narg > 1) && (strcmp(arg[1],"-h")==0) ) {
28 cout << " Usage : tnfits [InputFitsFileName] " << endl;
[2821]29 return 1;
30 }
31 int rc = 0;
32 try {
33 SophyaInit();
[2866]34 FitsIOServerInit();
[2821]35 InitTim();
[2935]36 if (narg > 1) { // Lecture fichier entree
[2821]37 string flnm = arg[1];
38 cout << "1/=== Lecture fichier FITS : " << flnm << endl;
39 FitsInOutFile fios(flnm, FitsInOutFile::Fits_RO);
40 fios.Print();
41 bool encore = true;
42 while (encore) {
43 cout << " HDU No" << fios.CurrentHDU() << " Type= "
44 << fios.CurrentHDUTypeStr() << endl;
45 DVList dvl;
46 fios.GetHeaderRecords(dvl);
47 cout << dvl;
48 if (fios.CurrentHDUType() == IMAGE_HDU) {
[3168]49 LONGLONG naxes[5] = {0,0,0,0,0};
[2821]50 int naxis=5;
51 fios.GetImageHDUInfo(naxis, naxes);
52 cout << "--GetImageHDUInfo() naxis= " << naxis << " : "
53 << naxes[0] << 'x' << naxes[1] << 'x' << naxes[2] << endl;
54 if (naxis == 2) {
55 cout << "---Reading Matrix ... mx= " << endl;
56 Matrix mx(naxes[1], naxes[0]);
57 FitsBlockRW<double>::ReadImageData(fios, mx.Data(), mx.Size());
58 cout << mx;
59 }
60 }
61 else {
62 vector<string> colnames;
63 vector<int> coltypes;
[3168]64 vector<LONGLONG> repcnt, width;
[2821]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 }
[2935]78 } // ---- Fin lecture fichier entree
[2821]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;
[3168]84 LONGLONG naxes[5] = {5,5,0,0,0};
[2821]85 fiosc.CreateImageHDU(FLOAT_IMG, 2, naxes);
86 float data[100];
87 double data2[100];
[2845]88 string sdata[100];
89 MuTyV mtv;
[2821]90 for(int kk=0; kk<100; kk++) {
91 data[kk] = kk/5.;
92 data2[kk] = cos(data[kk]);
[2845]93 mtv = kk;
94 sdata[kk] = "Str_KK=";
95 sdata[kk] += (string)(mtv);
[2821]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");
[2845]110 ttype.push_back("Col3");
[2821]111 tform.push_back("E");
112 tform.push_back("D");
[2845]113 tform.push_back("18A");
[2821]114 tunit.push_back("");
115 tunit.push_back("");
[2845]116 tunit.push_back("");
[2821]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);
[2845]132 FitsBlockRW<string>::WriteColumnData(fiosc, 3, 1, 1, sdata, 100);
133
[2821]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);
[2935]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();
[2821]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;
[2935]167 cout << " mxf.Info()= " << mxf.Info() << mxi;
[2821]168 cout << " mxi.Info()= " << mxi.Info() << mxi;
169 }
170
[3496]171 {
172 cout << "5/=== Ecriture tableau par morceaux dans tamor.fits " << endl;
173 FitsInOutFile fiosc("!tamor.fits", FitsInOutFile::Fits_Create);
174 cout << "5.a/ TArray<int_4> iam(6,4) = RegularSequence(0., 1.) " << endl;
175 TArray<int_4> iam(6,4);
176 iam = RegularSequence(0., 1.);
177 LONGLONG naxes[3] = {6,4,3};
178 int_4 x;
179 fiosc.CreateImageHDU(FitsTypes::ImageType(x), 3, naxes);
180 iam.Info()["Info"] = "Write test of 3 x TArray<r_4>(6,4)";
181 fiosc.WriteHeaderRecords(iam.Info());
182 sa_size_t off[3] = {0,0,0};
183 FitsArrayHandler<int_4> fah(iam);
184 for(int_4 kk=0; kk<3; kk++) {
185 iam += 100;
186 off[2] = kk;
187 cout << "5.b/ Appel fah.WriteAtOffset(fiosc, off) Avec off[2]="
188 << off[2] << endl;
189 fah.WriteAtOffset(fiosc, off);
190 }
191 }
192
193 {
194 cout << "6/=== lecture tableau par morceaux depuis tamor.fits " << endl;
195 FitsInOutFile fiosc("tamor.fits", FitsInOutFile::Fits_RO);
196 TArray<int_4> iam(6,4), iamck(6,4), diff(6,4);
197 iamck = RegularSequence(0., 1.);
198 int rc = 0;
199 int_4 min,max;
200 sa_size_t off[3] = {0,0,0};
201 int rcf[3] = {7,70,700};
202 FitsArrayHandler<int_4> fah(iam);
203 for(int_4 kk=0; kk<3; kk++) {
204 iamck += 100;
205 off[2] = kk;
206 cout << "6.b/ Appel fah.ReadAtOffset(fiosc, off) Avec off[2]="
207 << off[2] << endl;
208 fah.ReadAtOffset(fiosc, off);
209 cout << iam;
210 diff = iam-iamck;
211 diff.MinMax(min, max);
212 if ((min != 0) || (max != 0)) rc += rcf[kk];
213 }
214 cout << "6.b/ fah.ReadAtOffset(tamor.fits ...) Rc= " << rc << endl;
215 }
216
[2821]217 }
218 catch (PThrowable & exc) {
219 cerr << " tnfits.cc: Catched Exception (PThrowable)" << (string)typeid(exc).name()
220 << "\n...exc.Msg= " << exc.Msg() << endl;
221 rc = 99;
222 }
223 catch (std::exception & e) {
224 cerr << " tnfits.cc: Catched std::exception "
225 << " - what()= " << e.what() << endl;
226 rc = 98;
227 }
228 catch (...) {
229 cerr << " tnfits.cc: some other exception (...) was caught ! " << endl;
230 rc = 97;
231 }
232 PrtTim("End tnfits " );
233 cout << " ---- Programme tnfits.cc- FIN (Rc=" << rc << ") --- " << endl;
234 return rc;
235}
Note: See TracBrowser for help on using the repository browser.