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

Last change on this file since 2845 was 2845, checked in by ansari, 20 years ago

modifs test nouveau fits suite codage I/O colonnes string et complex - Reza 21/11/2005

  • Property svn:executable set to *
File size: 5.6 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
17/* Programme test des classes NFits */
18/* SOPHYA - R. Ansari (LAL) - Sep 2005 */
19
20int 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 string sdata[100];
85 MuTyV mtv;
86 for(int kk=0; kk<100; kk++) {
87 data[kk] = kk/5.;
88 data2[kk] = cos(data[kk]);
89 mtv = kk;
90 sdata[kk] = "Str_KK=";
91 sdata[kk] += (string)(mtv);
92 }
93 cout << " CurrHDU-2 : " << fiosc.CurrentHDU()
94 << " Type=" << fiosc.CurrentHDUType() <<endl;
95 FitsBlockRW<float>::WriteImageData(fiosc, data, 25);
96 fiosc.Print();
97 /*
98 char * ttype[2] = {"Col1", "Col2"};
99 char * tform[2] = {"E", "D"};
100 char * tunit[2] = {"", ""};
101 fiosc.CreateTable(BINARY_TBL, "rzbintbl", 2, ttype, tform, tunit);
102 */
103 vector<string> ttype, tform, tunit;
104 ttype.push_back("Col1");
105 ttype.push_back("Col2");
106 ttype.push_back("Col3");
107 tform.push_back("E");
108 tform.push_back("D");
109 tform.push_back("18A");
110 tunit.push_back("");
111 tunit.push_back("");
112 tunit.push_back("");
113 string tblnm = "rzbintbl";
114 fiosc.CreateTable(BINARY_TBL, "rzbintbl", ttype, tform, tunit);
115
116 // cout << " MovRelToHDU , Type=" << fiosc.MoveRelToHDU(1) << endl;
117 cout << " CurrHDU-3 : " << fiosc.CurrentHDU()
118 << " Type=" << fiosc.CurrentHDUType() <<endl;
119 fiosc.Print();
120 /*
121 cout << " DBG- fios.InsertColumn(1,Col1,E) " << endl;
122 fios.InsertColumn(1,"Col1","E");
123 cout << " DBG- fios.InsertColumn(2,Col2,D) " << endl;
124 fios.InsertColumn(2,"Col2","D");
125 */
126 FitsBlockRW<float>::WriteColumnData(fiosc, 1, 1, 1, data, 100);
127 FitsBlockRW<double>::WriteColumnData(fiosc, 2, 1, 1, data2, 100);
128 FitsBlockRW<string>::WriteColumnData(fiosc, 3, 1, 1, sdata, 100);
129
130 // Ecriture entete
131 DVList dvl;
132 dvl("toto") = 14; dvl("titi") = 25.5;
133 dvl("tata") = "Bonjour !";
134 dvl("hello") = 88; dvl("Hello") = 77.77;
135 dvl.Comment() = "Blabla ... zone commentaire ds DVList";
136 fiosc.WriteHeaderRecords(dvl);
137 }
138
139 {
140 cout << "3/=== Ecriture tableaux dans ta.fits " << endl;
141 FitsInOutFile fiosc("!ta.fits", FitsInOutFile::Fits_Create);
142 cout << " TArray<r_4> mxf(100,50,3) , TMatrix<int_4> mxi(60,30) " << endl;
143 TArray<r_4> mxf(100,50,3);
144 mxf = RegularSequence(0., 0.2);
145 TMatrix<int_4> mxi(60,30);
146 mxi = RegularSequence();
147 mxi.Info()["MtxNRow"] = mxi.NRows();
148 mxi.Info()["MtxNCol"] = mxi.NCols();
149 mxi.Info()["MtxStr"] = "TMatrix<int_4> mxi(60,30)";
150 fiosc << mxf << mxi ;
151 }
152 {
153 cout << "4/=== Lecture tableaux depuis ta.fits " << endl;
154 FitsInOutFile fiosc("ta.fits", FitsInOutFile::Fits_RO);
155 TArray<r_4> mxf;
156 TMatrix<int_4> mxi;
157 fiosc >> mxf >> mxi ;
158 cout << mxf;
159 cout << " mxi.Info()= " << mxi.Info() << mxi;
160 }
161
162 }
163 catch (PThrowable & exc) {
164 cerr << " tnfits.cc: Catched Exception (PThrowable)" << (string)typeid(exc).name()
165 << "\n...exc.Msg= " << exc.Msg() << endl;
166 rc = 99;
167 }
168 catch (std::exception & e) {
169 cerr << " tnfits.cc: Catched std::exception "
170 << " - what()= " << e.what() << endl;
171 rc = 98;
172 }
173 catch (...) {
174 cerr << " tnfits.cc: some other exception (...) was caught ! " << endl;
175 rc = 97;
176 }
177 PrtTim("End tnfits " );
178 cout << " ---- Programme tnfits.cc- FIN (Rc=" << rc << ") --- " << endl;
179 return rc;
180}
Note: See TracBrowser for help on using the repository browser.