| [3537] | 1 | // Utilisation de SOPHYA pour faciliter les tests ...
 | 
|---|
 | 2 | #include "sopnamsp.h"
 | 
|---|
 | 3 | #include "machdefs.h"
 | 
|---|
 | 4 | 
 | 
|---|
 | 5 | // include standard c/c++
 | 
|---|
 | 6 | #include <math.h>
 | 
|---|
 | 7 | #include <stdio.h>
 | 
|---|
 | 8 | 
 | 
|---|
 | 9 | #include <iostream>
 | 
|---|
 | 10 | #include <typeinfo>
 | 
|---|
 | 11 | #include <string>
 | 
|---|
 | 12 | 
 | 
|---|
 | 13 | 
 | 
|---|
 | 14 | #include "pexceptions.h"  // les exceptions SOPHYA
 | 
|---|
 | 15 | 
 | 
|---|
 | 16 | // Include sophya des tableaux 
 | 
|---|
 | 17 | #include "tvector.h" // Pour l'utilisation des classes TArray, TMatrix , TVector
 | 
|---|
 | 18 | #include "fioarr.h"  // Pour IO PPF TArray
 | 
|---|
 | 19 | #include "sopemtx.h"
 | 
|---|
 | 20 | #include "matharr.h"  
 | 
|---|
 | 21 | #include "tarrinit.h" // Pour l'utilisation des classes TArray, TMatrix , TVector
 | 
|---|
 | 22 | 
 | 
|---|
 | 23 | // include sophya mesure ressource CPU/memoire ...
 | 
|---|
 | 24 | #include "resusage.h"
 | 
|---|
 | 25 | #include "ctimer.h"
 | 
|---|
 | 26 | #include "timing.h"
 | 
|---|
 | 27 | 
 | 
|---|
 | 28 | // include mini-fits lib 
 | 
|---|
 | 29 | #include "minifits.h"
 | 
|---|
 | 30 | 
 | 
|---|
 | 31 | int main(int narg, char* arg[])
 | 
|---|
 | 32 | {
 | 
|---|
 | 33 |   // Sophya modules initialization
 | 
|---|
 | 34 |   TArrayInitiator  _inia;
 | 
|---|
 | 35 |   //------- AU LIEU DE ------>  SophyaInit();  
 | 
|---|
 | 36 | 
 | 
|---|
 | 37 |   InitTim();   // Initializing the CPU timer
 | 
|---|
 | 38 | 
 | 
|---|
 | 39 |   cout << " ---------- tstminifits.cc Start ------------- " << endl;
 | 
|---|
 | 40 |   int rc = 0;
 | 
|---|
 | 41 |   try {
 | 
|---|
| [3542] | 42 |     {
 | 
|---|
| [3537] | 43 |     cout << "1/ Creation tableau " << endl;
 | 
|---|
 | 44 |     size_t sx = 300;
 | 
|---|
 | 45 |     size_t sy = 200; 
 | 
|---|
 | 46 |     TArray<int_2> ta(sx, sy);
 | 
|---|
| [3542] | 47 |     TArray<r_4> arr(sx, sy);
 | 
|---|
| [3537] | 48 |     ta = RegularSequence(0.,0.5);
 | 
|---|
 | 49 |     ta.Show();
 | 
|---|
| [3542] | 50 |     arr = RandomSequence(RandomSequence::Gaussian, 510.,30.); 
 | 
|---|
 | 51 |     arr.Show();
 | 
|---|
 | 52 |     cout << "2/ ecriture tableaux ta (int_2) arr (r_4) ds tmf.ppf " << endl;
 | 
|---|
| [3537] | 53 |     POutPersist po("tmf.ppf");
 | 
|---|
| [3542] | 54 |     po << ta << arr;
 | 
|---|
| [3537] | 55 |     cout << "3/ ecriture tableau ds tmf.fits " << endl;
 | 
|---|
| [3542] | 56 |     {
 | 
|---|
| [3537] | 57 |     MiniFITSFile mff;
 | 
|---|
| [3542] | 58 |     mff.setDTypeNaxis(MF_Float32, sx, sy);
 | 
|---|
| [3537] | 59 |     mff.Open("tmf.fits", MF_Write);
 | 
|---|
 | 60 |     mff.WriteI(ta.Data(), sx*sy);
 | 
|---|
| [3542] | 61 |     }
 | 
|---|
 | 62 |     cout << "3.b/ ecriture tableau arr (r_4) ds tmf2.fits " << endl;
 | 
|---|
 | 63 |     {
 | 
|---|
 | 64 |     MiniFITSFile mff;
 | 
|---|
 | 65 |     mff.setDTypeNaxis(MF_Int16, sx, sy);
 | 
|---|
 | 66 |     mff.Open("tmf2.fits", MF_Write);
 | 
|---|
 | 67 |     mff.WriteF(arr.Data(), sx*sy);
 | 
|---|
 | 68 |     }
 | 
|---|
 | 69 |     cout << "3.c/ FIN ecriture tableau ds tmf.fits " << endl;   
 | 
|---|
 | 70 |     }
 | 
|---|
| [3537] | 71 | //  --------------  Ecriture de bytes par morceaux 
 | 
|---|
 | 72 |     {
 | 
|---|
 | 73 |     cout << "4/ Creation tableau uint_1" << endl;
 | 
|---|
 | 74 |     size_t sx = 178; 
 | 
|---|
 | 75 |     size_t sy = 14;
 | 
|---|
 | 76 |     uint_1* data = new uint_1[sx];
 | 
|---|
 | 77 |     MiniFITSFile mff("tmfb.fits", MF_Write);
 | 
|---|
 | 78 | 
 | 
|---|
 | 79 |     for(int k=0; k<sy; k++) {
 | 
|---|
 | 80 |       for(int j=0; j<sx; j++) data[j] = (k%8)*3+j;
 | 
|---|
 | 81 |       mff.WriteB(data, sx);
 | 
|---|
 | 82 |     }
 | 
|---|
 | 83 |     mff.setDTypeNaxis(MF_Byte, sx, sy);
 | 
|---|
 | 84 |     delete [] data;
 | 
|---|
 | 85 |     cout << "5/ FIN ecriture tableau ds tmfb.fits " << endl;   
 | 
|---|
 | 86 |     }
 | 
|---|
 | 87 | // -------------- Lecture de bytes      
 | 
|---|
 | 88 |     {
 | 
|---|
 | 89 |     cout << "6/ Ouverture/lecture tmfb.fits" << endl;
 | 
|---|
 | 90 |     MiniFITSFile mff("tmfb.fits", MF_Read);
 | 
|---|
 | 91 |     cout << "6.b/ Type=" << mff.DataTypeToString() << " NAxis1=" << mff.NAxis1() 
 | 
|---|
 | 92 |     << " NAxis2=" << mff.NAxis2() << endl;
 | 
|---|
 | 93 |     size_t sx = mff.NAxis1(); 
 | 
|---|
 | 94 |     size_t sy = mff.NAxis2();
 | 
|---|
 | 95 |     uint_1* data = new uint_1[sx*sy];
 | 
|---|
 | 96 |     mff.ReadB(data, sx*sy);
 | 
|---|
 | 97 |     cout << "7/ FIN lecture depuis tmfb.fits " << endl;   
 | 
|---|
 | 98 |     TArray<int_2> ta(sx, sy);
 | 
|---|
 | 99 |     for(int k=0; k<sy; k++) 
 | 
|---|
 | 100 |       for(int j=0; j<sx; j++) ta(j, k) = (int_2)data[j+k*sx];
 | 
|---|
 | 101 |     POutPersist po("tmfb.ppf");
 | 
|---|
 | 102 |     po << ta;
 | 
|---|
 | 103 |     cout << "8/ FIN ecriture tableau ds tmfb.ppf " << endl; 
 | 
|---|
 | 104 |     delete[] data;
 | 
|---|
 | 105 |     }
 | 
|---|
 | 106 |   }
 | 
|---|
 | 107 |   catch (MiniFITSException& exc) {
 | 
|---|
 | 108 |     cerr << " tstminifits.cc catched MiniFITSException " << exc.Msg() << endl;
 | 
|---|
 | 109 |     rc = 77;
 | 
|---|
 | 110 |   }  
 | 
|---|
 | 111 |   catch (PThrowable& exc) {
 | 
|---|
 | 112 |     cerr << " tstminifits.cc catched Exception " << exc.Msg() << endl;
 | 
|---|
 | 113 |     rc = 76;
 | 
|---|
 | 114 |   }  
 | 
|---|
 | 115 |   catch (std::exception& sex) {
 | 
|---|
 | 116 |     cerr << "\n tstminifits.cc std::exception :" 
 | 
|---|
 | 117 |          << (string)typeid(sex).name() << "\n msg= " 
 | 
|---|
 | 118 |          << sex.what() << endl;
 | 
|---|
 | 119 |     rc = 78;
 | 
|---|
 | 120 |   }
 | 
|---|
 | 121 |   catch (...) {
 | 
|---|
 | 122 |     cerr << " tstminifits.cc catched unknown (...) exception  " << endl; 
 | 
|---|
 | 123 |     rc = 79; 
 | 
|---|
 | 124 |   } 
 | 
|---|
 | 125 | 
 | 
|---|
 | 126 |   cout << ">>>> tstminifits.cc ------- FIN ----------- RC=" << rc << endl;
 | 
|---|
 | 127 |   PrtTim("FIN tstminifits.cc");
 | 
|---|
 | 128 |   return rc;
 | 
|---|
 | 129 | 
 | 
|---|
 | 130 | }
 | 
|---|