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

Last change on this file since 3399 was 3168, checked in by ansari, 19 years ago

Adaptation prg test au passage a la version ll (LONGLONG) des routines fits , cmv+Reza 02/02/2007

  • Property svn:executable set to *
File size: 6.0 KB
Line 
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
21int tsfitsReadFile(string& flnm);
22
23int 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 LONGLONG 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<LONGLONG> repcnt, width;
64 int ncols = fios.GetColInfo(colnames, coltypes, repcnt, width);
65 cout << " NCols from GetColInfo = " << ncols << endl;
66 for(int kk=0; kk<colnames.size(); kk++) {
67 cout << " kk=" << kk << " ColName= " << colnames[kk]
68 << " Type= " << coltypes[kk]
69 << " Repeat= " << repcnt[kk]
70 << " W= " << width[kk] << endl;
71 }
72 }
73 if (fios.CurrentHDU() < fios.NbHDUs())
74 fios.MoveRelToHDU(1);
75 else encore = false;
76 }
77 } // ---- Fin lecture fichier entree
78 {
79 cout << "2/=== Ecriture BinTable dans toto.fits " << endl;
80 FitsInOutFile fiosc("!toto.fits", FitsInOutFile::Fits_Create);
81 // cout << " CurrHDU-1 : " << fiosc.CurrentHDU()
82 // << " Type=" << fiosc.CurrentHDUType() <<endl;
83 LONGLONG naxes[5] = {5,5,0,0,0};
84 fiosc.CreateImageHDU(FLOAT_IMG, 2, naxes);
85 float data[100];
86 double data2[100];
87 string sdata[100];
88 MuTyV mtv;
89 for(int kk=0; kk<100; kk++) {
90 data[kk] = kk/5.;
91 data2[kk] = cos(data[kk]);
92 mtv = kk;
93 sdata[kk] = "Str_KK=";
94 sdata[kk] += (string)(mtv);
95 }
96 cout << " CurrHDU-2 : " << fiosc.CurrentHDU()
97 << " Type=" << fiosc.CurrentHDUType() <<endl;
98 FitsBlockRW<float>::WriteImageData(fiosc, data, 25);
99 fiosc.Print();
100 /*
101 char * ttype[2] = {"Col1", "Col2"};
102 char * tform[2] = {"E", "D"};
103 char * tunit[2] = {"", ""};
104 fiosc.CreateTable(BINARY_TBL, "rzbintbl", 2, ttype, tform, tunit);
105 */
106 vector<string> ttype, tform, tunit;
107 ttype.push_back("Col1");
108 ttype.push_back("Col2");
109 ttype.push_back("Col3");
110 tform.push_back("E");
111 tform.push_back("D");
112 tform.push_back("18A");
113 tunit.push_back("");
114 tunit.push_back("");
115 tunit.push_back("");
116 string tblnm = "rzbintbl";
117 fiosc.CreateTable(BINARY_TBL, "rzbintbl", ttype, tform, tunit);
118
119 // cout << " MovRelToHDU , Type=" << fiosc.MoveRelToHDU(1) << endl;
120 cout << " CurrHDU-3 : " << fiosc.CurrentHDU()
121 << " Type=" << fiosc.CurrentHDUType() <<endl;
122 fiosc.Print();
123 /*
124 cout << " DBG- fios.InsertColumn(1,Col1,E) " << endl;
125 fios.InsertColumn(1,"Col1","E");
126 cout << " DBG- fios.InsertColumn(2,Col2,D) " << endl;
127 fios.InsertColumn(2,"Col2","D");
128 */
129 FitsBlockRW<float>::WriteColumnData(fiosc, 1, 1, 1, data, 100);
130 FitsBlockRW<double>::WriteColumnData(fiosc, 2, 1, 1, data2, 100);
131 FitsBlockRW<string>::WriteColumnData(fiosc, 3, 1, 1, sdata, 100);
132
133 // Ecriture entete
134 DVList dvl;
135 dvl("toto") = 14; dvl("titi") = 25.5;
136 dvl("tata") = "Bonjour !";
137 dvl("hello") = 88; dvl("Hello") = 77.77;
138 dvl.Comment() = "Blabla ... zone commentaire ds DVList";
139 fiosc.WriteHeaderRecords(dvl);
140 }
141
142 {
143 cout << "3/=== Ecriture tableaux dans ta.fits " << endl;
144 FitsInOutFile fiosc("!ta.fits", FitsInOutFile::Fits_Create);
145 cout << " TArray<r_4> mxf(100,50,3) , TMatrix<int_4> mxi(60,30) " << endl;
146 TArray<r_4> mxf(100,50,3);
147 mxf = RegularSequence(0., 0.2);
148 mxf.Info()["info1"] = "info1: TArray<r_4>";
149 mxf.Info()["info2"] = "info2: (100,50,3)";
150 mxf.Info()["info3 "] = "info3: mot-cle-avec-blanc";
151 cout << mxf.Info();
152 TMatrix<int_4> mxi(60,30);
153 mxi = RegularSequence();
154 mxi.Info()["MtxNRow"] = mxi.NRows();
155 mxi.Info()["MtxNCol"] = mxi.NCols();
156 mxi.Info()["MtxStr"] = "TMatrix<int_4> mxi(60,30)";
157 fiosc << mxf << mxi ;
158 }
159 {
160 cout << "4/=== Lecture tableaux depuis ta.fits " << endl;
161 FitsInOutFile fiosc("ta.fits", FitsInOutFile::Fits_RO);
162 TArray<r_4> mxf;
163 TMatrix<int_4> mxi;
164 fiosc >> mxf >> mxi ;
165 cout << mxf;
166 cout << " mxf.Info()= " << mxf.Info() << mxi;
167 cout << " mxi.Info()= " << mxi.Info() << mxi;
168 }
169
170 }
171 catch (PThrowable & exc) {
172 cerr << " tnfits.cc: Catched Exception (PThrowable)" << (string)typeid(exc).name()
173 << "\n...exc.Msg= " << exc.Msg() << endl;
174 rc = 99;
175 }
176 catch (std::exception & e) {
177 cerr << " tnfits.cc: Catched std::exception "
178 << " - what()= " << e.what() << endl;
179 rc = 98;
180 }
181 catch (...) {
182 cerr << " tnfits.cc: some other exception (...) was caught ! " << endl;
183 rc = 97;
184 }
185 PrtTim("End tnfits " );
186 cout << " ---- Programme tnfits.cc- FIN (Rc=" << rc << ") --- " << endl;
187 return rc;
188}
Note: See TracBrowser for help on using the repository browser.