| 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 |           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 |       cout << "5/=== Ecriture tableau par morceaux dans tamor.fits  " << endl;
 | 
|---|
| 172 |       FitsInOutFile fiosc("!tamor.fits", FitsInOutFile::Fits_Create);
 | 
|---|
| 173 |       cout << "5.a/ TArray<int_4> iam(6,4) = RegularSequence(0., 1.) " << endl;
 | 
|---|
| 174 |       TArray<int_4> iam(6,4);      
 | 
|---|
| 175 |       iam = RegularSequence(0., 1.);
 | 
|---|
| 176 |       LONGLONG naxes[3] = {6,4,3};
 | 
|---|
| 177 |       int_4 x;
 | 
|---|
| 178 |       fiosc.CreateImageHDU(FitsTypes::ImageType(x), 3, naxes);
 | 
|---|
| 179 |       iam.Info()["Info"] = "Write test of 3 x TArray<r_4>(6,4)";
 | 
|---|
| 180 |       fiosc.WriteHeaderRecords(iam.Info());
 | 
|---|
| 181 |       sa_size_t off[3] = {0,0,0};
 | 
|---|
| 182 |       FitsArrayHandler<int_4> fah(iam);
 | 
|---|
| 183 |       for(int_4 kk=0; kk<3; kk++) {
 | 
|---|
| 184 |         iam += 100;
 | 
|---|
| 185 |         off[2] = kk;
 | 
|---|
| 186 |         cout << "5.b/ Appel fah.WriteAtOffset(fiosc, off) Avec off[2]=" 
 | 
|---|
| 187 |              << off[2] << endl;
 | 
|---|
| 188 |         fah.WriteAtOffset(fiosc, off);
 | 
|---|
| 189 |       }
 | 
|---|
| 190 |     }
 | 
|---|
| 191 | 
 | 
|---|
| 192 |     {
 | 
|---|
| 193 |       cout << "6/=== lecture tableau par morceaux depuis tamor.fits  " << endl;
 | 
|---|
| 194 |       FitsInOutFile fiosc("tamor.fits", FitsInOutFile::Fits_RO);
 | 
|---|
| 195 |       TArray<int_4> iam(6,4), iamck(6,4), diff(6,4);      
 | 
|---|
| 196 |       iamck = RegularSequence(0., 1.);
 | 
|---|
| 197 |       int rc = 0;
 | 
|---|
| 198 |       int_4 min,max;
 | 
|---|
| 199 |       sa_size_t off[3] = {0,0,0};
 | 
|---|
| 200 |       int rcf[3] = {7,70,700};
 | 
|---|
| 201 |       FitsArrayHandler<int_4> fah(iam);
 | 
|---|
| 202 |       for(int_4 kk=0; kk<3; kk++) {
 | 
|---|
| 203 |         iamck += 100;
 | 
|---|
| 204 |         off[2] = kk;
 | 
|---|
| 205 |         cout << "6.b/ Appel fah.ReadAtOffset(fiosc, off) Avec off[2]=" 
 | 
|---|
| 206 |              << off[2] << endl;
 | 
|---|
| 207 |         fah.ReadAtOffset(fiosc, off);
 | 
|---|
| 208 |         cout << iam;
 | 
|---|
| 209 |         diff = iam-iamck;
 | 
|---|
| 210 |         diff.MinMax(min, max);
 | 
|---|
| 211 |         if ((min != 0) || (max != 0))  rc += rcf[kk];
 | 
|---|
| 212 |       }
 | 
|---|
| 213 |       cout << "6.b/ fah.ReadAtOffset(tamor.fits ...) Rc= " << rc << endl;
 | 
|---|
| 214 |     }
 | 
|---|
| 215 | 
 | 
|---|
| 216 |   }
 | 
|---|
| 217 |   catch (PThrowable & exc) {
 | 
|---|
| 218 |     cerr << " tnfits.cc: Catched Exception (PThrowable)" << (string)typeid(exc).name() 
 | 
|---|
| 219 |          << "\n...exc.Msg= " << exc.Msg() << endl;
 | 
|---|
| 220 |     rc = 99;
 | 
|---|
| 221 |   }
 | 
|---|
| 222 |   catch (std::exception & e) {
 | 
|---|
| 223 |     cerr << " tnfits.cc: Catched std::exception "  
 | 
|---|
| 224 |          << " - what()= " << e.what() << endl;
 | 
|---|
| 225 |     rc = 98;
 | 
|---|
| 226 |   }
 | 
|---|
| 227 |   catch (...) {
 | 
|---|
| 228 |     cerr << " tnfits.cc: some other exception (...) was caught ! " << endl;
 | 
|---|
| 229 |     rc = 97;
 | 
|---|
| 230 |   }
 | 
|---|
| 231 |   PrtTim("End tnfits " );
 | 
|---|
| 232 |   cout << " ---- Programme tnfits.cc-  FIN  (Rc=" << rc << ") --- " << endl;
 | 
|---|
| 233 |   return rc;
 | 
|---|
| 234 | }
 | 
|---|