| [2783] | 1 | #include <stdio.h> | 
|---|
|  | 2 | #include <stdlib.h> | 
|---|
|  | 3 | #include <math.h> | 
|---|
|  | 4 | #include <iostream> | 
|---|
|  | 5 |  | 
|---|
|  | 6 | #include "sopnamsp.h" | 
|---|
|  | 7 | #include "histinit.h" | 
|---|
|  | 8 | #include "dvlist.h" | 
|---|
|  | 9 | #include "fitsswapper.h" | 
|---|
| [2866] | 10 | #include "fiosinit.h" | 
|---|
| [2890] | 11 | #include "swfitsdtable.h" | 
|---|
| [2783] | 12 |  | 
|---|
| [3089] | 13 | #include "datatable.h" | 
|---|
|  | 14 | #include "fitshdtable.h" | 
|---|
|  | 15 |  | 
|---|
| [2783] | 16 | void test_fdtable() ; | 
|---|
| [3089] | 17 | static long NROW = 64; | 
|---|
|  | 18 | static long NPRT = 10; | 
|---|
| [2783] | 19 |  | 
|---|
|  | 20 | int main(int narg, char *arg[]) | 
|---|
|  | 21 | { | 
|---|
|  | 22 | SophyaInit(); | 
|---|
| [2866] | 23 | FitsIOServerInit(); | 
|---|
| [3089] | 24 | if (narg < 3) { | 
|---|
|  | 25 | cout << "Erreur arg/Usage: tswfits NRowTable NPRT" << endl; | 
|---|
|  | 26 | return 1; | 
|---|
|  | 27 | } | 
|---|
|  | 28 | NROW = atoi(arg[1]); | 
|---|
|  | 29 | NPRT = atoi(arg[2]); | 
|---|
| [2783] | 30 | try { | 
|---|
|  | 31 | test_fdtable(); | 
|---|
|  | 32 | } | 
|---|
|  | 33 | catch(PThrowable exc ) { | 
|---|
| [2858] | 34 | cerr << "tswfits-main() , Catched exception: \n" << exc.Msg() << endl; | 
|---|
| [2783] | 35 | } | 
|---|
|  | 36 | catch(std::exception ex) { | 
|---|
| [2858] | 37 | cerr << "tswfits-main() , Catched exception ! " << (string)(ex.what()) << endl; | 
|---|
| [2783] | 38 | } | 
|---|
|  | 39 | catch(...) { | 
|---|
| [2858] | 40 | cerr << "tswfits-main() , Catched ... ! " << endl; | 
|---|
| [2783] | 41 | } | 
|---|
| [3089] | 42 |  | 
|---|
| [2783] | 43 | } | 
|---|
|  | 44 |  | 
|---|
|  | 45 |  | 
|---|
|  | 46 | void test_fdtable() | 
|---|
|  | 47 | { | 
|---|
| [3089] | 48 | cout << "======= test_fdtable:  simple SwapOnFits test ======= " << endl; | 
|---|
| [2783] | 49 | int SWSEGSZ = 4; | 
|---|
|  | 50 | vector<int_8> tags; | 
|---|
|  | 51 | { | 
|---|
| [3089] | 52 | cout << "1/ Creation FITSDataSwapper<double> swout(so) avec swseg.fits " << endl; | 
|---|
| [2858] | 53 | vector<string> ttype, tform, tunit; | 
|---|
|  | 54 | ttype.push_back("D-Col1"); | 
|---|
|  | 55 | tform.push_back("D"); | 
|---|
|  | 56 | tunit.push_back(""); | 
|---|
|  | 57 | //      ttype.push_back("I-Col2"); | 
|---|
|  | 58 | //      tform.push_back("J"); | 
|---|
|  | 59 | //      tunit.push_back(""); | 
|---|
|  | 60 | string tblnm = "SwapMyExt"; | 
|---|
|  | 61 | FitsInOutFile fiosc("!swseg.fits", FitsInOutFile::Fits_Create); | 
|---|
|  | 62 | //      fiosc.MoveAbsToHDU(2); | 
|---|
|  | 63 | cout << " DBG-Appel CreateTable ... " << endl; | 
|---|
|  | 64 | fiosc.CreateTable(BINARY_TBL, "rzbintbl", ttype, tform, tunit); | 
|---|
| [2783] | 65 | cout << " ---- Appel a FITSDataSwapper<double> --- " << endl; | 
|---|
| [2866] | 66 | FITSDataSwapper<double> swout(fiosc, 1); | 
|---|
| [2783] | 67 | SwSegDataBlock<double> swsd(swout, SWSEGSZ, 3); | 
|---|
| [2858] | 68 | //      FITSDataSwapper<int_4> swout(&fiosc, 1); | 
|---|
|  | 69 | //      SwSegDataBlock<int_4> swsd(swout, SWSEGSZ, 3); | 
|---|
| [2783] | 70 | double * fp = swsd.GetSegment(0); | 
|---|
|  | 71 | fp[0] = 6.54321;   fp[1] = 65.4321;  fp[2] = 654.321;  fp[3] = 6543.21; | 
|---|
|  | 72 | fp = swsd.GetSegment(1); | 
|---|
|  | 73 | fp[0] = 2.56789;   fp[1] = 25.6789;  fp[2] = 256.789;  fp[3] = 2567.89; | 
|---|
|  | 74 | fp = swsd.GetSegment(2); | 
|---|
|  | 75 | fp[0] = 12.567;   fp[1] = 225.67;  fp[2] = 3256.7;  fp[3] = 42567.; | 
|---|
|  | 76 | tags = swsd.GetSwapPosTagTable(); | 
|---|
|  | 77 | cout << " Les pos-tags du FITS NbTag=" << tags.size() << endl; | 
|---|
|  | 78 | for (int kk=0; kk<tags.size(); kk++)  cout << tags[kk] << " ," ; | 
|---|
|  | 79 | cout << endl; | 
|---|
|  | 80 | } | 
|---|
|  | 81 | { | 
|---|
| [3089] | 82 | cout << "2/ Creation FITSDataSwapper<double> avec lecture depuis swseg.fits" << endl; | 
|---|
| [2858] | 83 | FitsInOutFile si("swseg.fits", FitsInOutFile::Fits_RO); | 
|---|
|  | 84 | si.MoveAbsToHDU(2); | 
|---|
| [2866] | 85 | FITSDataSwapper<double> swin(si, 1); | 
|---|
| [2783] | 86 | SwSegDataBlock<double> swsd(swin, tags, SWSEGSZ); | 
|---|
| [3089] | 87 | cout <<"2.b/ Recopie ds SegDataBlock<double> depuis SwSegDataBlock<double> et print" << endl; | 
|---|
| [2783] | 88 | SegDataBlock<double> segd; | 
|---|
|  | 89 | segd = swsd; | 
|---|
|  | 90 | segd.Print(cout, 4, "  "); | 
|---|
|  | 91 | } | 
|---|
| [2890] | 92 |  | 
|---|
|  | 93 | { | 
|---|
| [3089] | 94 | cout << " ------------------------------------------------ " << endl; | 
|---|
|  | 95 | cout << "3/ Creation SwFitsDataTable sur myswtable.fits " << endl; | 
|---|
| [2890] | 96 | FitsInOutFile so("!myswtable.fits", FitsInOutFile::Fits_Create); | 
|---|
| [3089] | 97 | SwFitsDataTable dt(so, 45); | 
|---|
| [2890] | 98 | // define table columns | 
|---|
|  | 99 | dt.AddFloatColumn("X0_f"); | 
|---|
|  | 100 | dt.AddFloatColumn("X1_f"); | 
|---|
|  | 101 | dt.AddDoubleColumn("X0X0pX1X1_d"); | 
|---|
| [3089] | 102 | cout << "3.b/ start fill " << endl; | 
|---|
| [2890] | 103 | // Fill the table | 
|---|
|  | 104 | r_8 x[5]; | 
|---|
| [3089] | 105 | int pmod = NROW/50; | 
|---|
|  | 106 | if (pmod < 10) pmod = 10; | 
|---|
|  | 107 | for(int i=0; i<NROW; i++) { | 
|---|
|  | 108 | //      if (i%pmod == 0)  cout << " DBG - i= " << i << endl; | 
|---|
| [2890] | 109 | x[0] = (i%9)-4.;  x[1] = (i/9)-3.;  x[2] = x[0]*x[0]+x[1]*x[1]; | 
|---|
|  | 110 | dt.AddLine(x); | 
|---|
|  | 111 | } | 
|---|
| [3089] | 112 | cout << "3.c/ End fill " << endl; | 
|---|
| [2890] | 113 |  | 
|---|
|  | 114 | // Printing table info | 
|---|
|  | 115 | cout << dt ; | 
|---|
| [3089] | 116 | for(int k = 0; k<NPRT; k++) | 
|---|
|  | 117 | cout << "Line[" << k << "] " << dt.LineToString(k) << endl ; | 
|---|
|  | 118 |  | 
|---|
| [2890] | 119 | } | 
|---|
| [3089] | 120 | { | 
|---|
|  | 121 | cout << " ------------------------------------------------ " << endl; | 
|---|
|  | 122 | cout << "4/ Lecture SwFitsDataTable depuis myswtable.fits " << endl; | 
|---|
|  | 123 | FitsInOutFile si("myswtable.fits", FitsInOutFile::Fits_RO); | 
|---|
|  | 124 | si.SkipEmptyFirstHDU(); | 
|---|
|  | 125 | SwFitsDataTable dt(si,40,false); | 
|---|
|  | 126 | //      si >> dt; | 
|---|
|  | 127 | // Printing table info | 
|---|
|  | 128 | cout << dt ; | 
|---|
|  | 129 | for(int k = 0; k<NPRT; k++) | 
|---|
|  | 130 | cout << "Line[" << k << "] " << dt.LineToString(k) << endl ; | 
|---|
|  | 131 | } | 
|---|
|  | 132 |  | 
|---|
| [2783] | 133 | cout << "============ FIN  test_fdtable ======== ======= " << endl; | 
|---|
|  | 134 | } | 
|---|
|  | 135 |  | 
|---|
|  | 136 |  | 
|---|
|  | 137 |  | 
|---|
|  | 138 |  | 
|---|