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