| 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 "datatable.h" | 
|---|
| 9 | #include "fitshdtable.h" | 
|---|
| 10 | #include "swfitsdtable.h" | 
|---|
| 11 |  | 
|---|
| 12 | /* | 
|---|
| 13 | Programme de test lecture-ecriture FITS de DataTable | 
|---|
| 14 | + test classe SwFitsDataTable | 
|---|
| 15 | Oct 2005 - Jan 2006 | 
|---|
| 16 | */ | 
|---|
| 17 |  | 
|---|
| 18 | void test_fdtable() ; | 
|---|
| 19 |  | 
|---|
| 20 | int main(int narg, char *arg[]) | 
|---|
| 21 | { | 
|---|
| 22 | SophyaInit(); | 
|---|
| 23 | try { | 
|---|
| 24 | test_fdtable(); | 
|---|
| 25 | } | 
|---|
| 26 | catch(PThrowable exc ) { | 
|---|
| 27 | cerr << "tfitsdt-main() , Catched exception: \n" << exc.Msg() << endl; | 
|---|
| 28 | } | 
|---|
| 29 | catch(std::exception ex) { | 
|---|
| 30 | cerr << "tfitsdt-main() , Catched exception ! " << (string)(ex.what()) << endl; | 
|---|
| 31 | } | 
|---|
| 32 | catch(...) { | 
|---|
| 33 | cerr << "tfitsdt-main() , Catched ... ! " << endl; | 
|---|
| 34 | } | 
|---|
| 35 | } | 
|---|
| 36 |  | 
|---|
| 37 |  | 
|---|
| 38 | void test_fdtable() | 
|---|
| 39 | { | 
|---|
| 40 | int NL = 600; | 
|---|
| 41 | DataTable refdt(100); // Reference DataTable - for tests | 
|---|
| 42 |  | 
|---|
| 43 | cout << "======= test_fdtable: Simple DataTable+FITS test ======= " << endl; | 
|---|
| 44 | { | 
|---|
| 45 | cout << "1/ Creating DataTable / Writing to FITS " << endl; | 
|---|
| 46 | DataTable dt(64); | 
|---|
| 47 | dt.AddIntegerColumn("line"); | 
|---|
| 48 | dt.AddDoubleColumn("x"); | 
|---|
| 49 | dt.AddFloatColumn("f_sin"); | 
|---|
| 50 | dt.AddDoubleColumn("f_x2"); | 
|---|
| 51 | dt.AddStringColumn("str_line"); | 
|---|
| 52 | dt.AddComplexColumn("cmplx_cos_sin"); | 
|---|
| 53 | MuTyV rec[10]; | 
|---|
| 54 | char sbuff[32]; | 
|---|
| 55 | cout << " Filling ... (NLines=" << NL << ")" << endl; | 
|---|
| 56 | for(int k = 0; k<NL; k++) { | 
|---|
| 57 | rec[0] = k; | 
|---|
| 58 | double x = M_PI*k/100.; | 
|---|
| 59 | double fx = sin(x)*cos(x); | 
|---|
| 60 | rec[1] = x+1; | 
|---|
| 61 | rec[2] = sin(x); | 
|---|
| 62 | rec[3] = x*x; | 
|---|
| 63 | sprintf(sbuff, "SL-%d", k); | 
|---|
| 64 | rec[4] = sbuff; | 
|---|
| 65 | double sx = sin(x); | 
|---|
| 66 | double cx = cos(x); | 
|---|
| 67 | rec[5] = complex<r_4>(cx, sx); | 
|---|
| 68 | dt.AddLine(rec); | 
|---|
| 69 | } | 
|---|
| 70 | cout << dt; | 
|---|
| 71 | cout << " Copying dt to refdt (refdt = dt) " << endl; | 
|---|
| 72 | refdt = dt; | 
|---|
| 73 | cout << " Writing dt to fits file dtable.fits ... " << endl; | 
|---|
| 74 | FitsInOutFile fios("!dtable.fits", FitsInOutFile::Fits_Create); | 
|---|
| 75 | fios << dt; | 
|---|
| 76 | cout << " Writing dt to fits as ASCII table with extname= ASC_DTable ... " << endl; | 
|---|
| 77 | fios.SetDef_AscTable(); | 
|---|
| 78 | fios.SetNextExtensionName("ASC_DTable"); | 
|---|
| 79 | fios << dt; | 
|---|
| 80 | cout << "1.b/ Creating SwFitsDataTable (file swdtable.fits) " << endl; | 
|---|
| 81 | FitsInOutFile swf("!swdtable.fits", FitsInOutFile::Fits_Create); | 
|---|
| 82 | SwFitsDataTable swdt(swf, 64); | 
|---|
| 83 | cout << " Copying from DataTable dt ..." << endl; | 
|---|
| 84 | swdt = dt; | 
|---|
| 85 | cout << swdt; | 
|---|
| 86 | } | 
|---|
| 87 | { | 
|---|
| 88 | cout << "2/ Reading DataTable from FITS " << endl; | 
|---|
| 89 | FitsInOutFile fios("dtable.fits", FitsInOutFile::Fits_RO); | 
|---|
| 90 | cout << fios ; | 
|---|
| 91 | fios.MoveToNextHDU(); | 
|---|
| 92 | DataTable dtr; | 
|---|
| 93 | fios >> dtr; | 
|---|
| 94 | cout << dtr; | 
|---|
| 95 | cout << "2.b/  dtr.LineHeaderToString() dtr.LineToString(k)   : " << endl; | 
|---|
| 96 | cout << dtr.LineHeaderToString() << endl; | 
|---|
| 97 | for(int k = 0; k<NL; k+=NL/12) | 
|---|
| 98 | cout << "Line[" << k << "] " << dtr.LineToString(k) << endl ; | 
|---|
| 99 | cout << "2.b/  Reading from ASCII table   " << endl; | 
|---|
| 100 | DataTable dtra; | 
|---|
| 101 | fios >> dtra; | 
|---|
| 102 | cout << dtra; | 
|---|
| 103 | cout << dtra.LineHeaderToString() << endl; | 
|---|
| 104 | for(int k = 0; k<NL; k+=NL/12) | 
|---|
| 105 | cout << "Line[" << k << "] " << dtra.LineToString(k) << endl ; | 
|---|
| 106 |  | 
|---|
| 107 | cout << "2.c/  Reading SwFitsDataTable from  swdtable.fits  " << endl; | 
|---|
| 108 | SwFitsDataTable swdtr; | 
|---|
| 109 | FitsInOutFile swf("swdtable.fits", FitsInOutFile::Fits_RO); | 
|---|
| 110 | swf.MoveAbsToHDU(2); | 
|---|
| 111 | swf >> swdtr; | 
|---|
| 112 | cout << swdtr; | 
|---|
| 113 | cout << swdtr.LineHeaderToString() << endl; | 
|---|
| 114 | for(int k = 0; k<NL; k+=NL/12) | 
|---|
| 115 | cout << "Line[" << k << "] " << swdtr.LineToString(k) << endl ; | 
|---|
| 116 | } | 
|---|
| 117 | cout << "============ FIN  test_fdtable =============== " << endl; | 
|---|
| 118 | } | 
|---|
| 119 |  | 
|---|
| 120 |  | 
|---|
| 121 |  | 
|---|
| 122 |  | 
|---|