| [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); | 
|---|
| [3658] | 60 | // Exemple d'ajout d'information dans l'entete FITS | 
|---|
|  | 61 | mff.AddKeyI("CleI_A", 12); | 
|---|
|  | 62 | mff.AddKeyD("CleD_B", 3.1415, " Valeur de Pi"); | 
|---|
|  | 63 | mff.AddKeyS("CleS_C", "Prog. tstminifits", " Cle de type string"); | 
|---|
|  | 64 | // Ajout de date-heure dans l'entete FITS | 
|---|
|  | 65 | TimeStamp tsc; | 
|---|
|  | 66 | string cdtu=tsc.ToString(); | 
|---|
|  | 67 | mff.AddKeyS("DATEOBS", cdtu.c_str(), " Observation Time (YYYY-MM-DDThh:mm:ss UT) "); | 
|---|
| [3537] | 68 | mff.WriteI(ta.Data(), sx*sy); | 
|---|
| [3542] | 69 | } | 
|---|
|  | 70 | cout << "3.b/ ecriture tableau arr (r_4) ds tmf2.fits " << endl; | 
|---|
|  | 71 | { | 
|---|
|  | 72 | MiniFITSFile mff; | 
|---|
|  | 73 | mff.setDTypeNaxis(MF_Int16, sx, sy); | 
|---|
|  | 74 | mff.Open("tmf2.fits", MF_Write); | 
|---|
| [3658] | 75 | TimeStamp tsc; | 
|---|
|  | 76 | string cdtu=tsc.ToString(); | 
|---|
|  | 77 | mff.AddKeyS("DATE", cdtu.c_str(), " File Creation time(YYYY-MM-DDThh:mm:ss UT) "); | 
|---|
| [3542] | 78 | mff.WriteF(arr.Data(), sx*sy); | 
|---|
|  | 79 | } | 
|---|
|  | 80 | cout << "3.c/ FIN ecriture tableau ds tmf.fits " << endl; | 
|---|
|  | 81 | } | 
|---|
| [3537] | 82 | //  --------------  Ecriture de bytes par morceaux | 
|---|
|  | 83 | { | 
|---|
|  | 84 | cout << "4/ Creation tableau uint_1" << endl; | 
|---|
|  | 85 | size_t sx = 178; | 
|---|
|  | 86 | size_t sy = 14; | 
|---|
|  | 87 | uint_1* data = new uint_1[sx]; | 
|---|
|  | 88 | MiniFITSFile mff("tmfb.fits", MF_Write); | 
|---|
|  | 89 |  | 
|---|
|  | 90 | for(int k=0; k<sy; k++) { | 
|---|
|  | 91 | for(int j=0; j<sx; j++) data[j] = (k%8)*3+j; | 
|---|
|  | 92 | mff.WriteB(data, sx); | 
|---|
|  | 93 | } | 
|---|
|  | 94 | mff.setDTypeNaxis(MF_Byte, sx, sy); | 
|---|
| [3692] | 95 | mff.AddKeyI("CleI_A", 12); | 
|---|
|  | 96 | mff.AddKeyD("CleD_B", 3.1415, " Valeur de Pi"); | 
|---|
| [3537] | 97 | delete [] data; | 
|---|
|  | 98 | cout << "5/ FIN ecriture tableau ds tmfb.fits " << endl; | 
|---|
|  | 99 | } | 
|---|
|  | 100 | // -------------- Lecture de bytes | 
|---|
|  | 101 | { | 
|---|
|  | 102 | cout << "6/ Ouverture/lecture tmfb.fits" << endl; | 
|---|
|  | 103 | MiniFITSFile mff("tmfb.fits", MF_Read); | 
|---|
|  | 104 | cout << "6.b/ Type=" << mff.DataTypeToString() << " NAxis1=" << mff.NAxis1() | 
|---|
|  | 105 | << " NAxis2=" << mff.NAxis2() << endl; | 
|---|
|  | 106 | size_t sx = mff.NAxis1(); | 
|---|
|  | 107 | size_t sy = mff.NAxis2(); | 
|---|
|  | 108 | uint_1* data = new uint_1[sx*sy]; | 
|---|
|  | 109 | mff.ReadB(data, sx*sy); | 
|---|
| [3692] | 110 | cout << " ---- mff.GetKey(CleD_B) : "  << mff.GetKey("CleD_B") << endl; | 
|---|
|  | 111 | cout << " ---- mff.GetKey(Non-Existing) : "  << mff.GetKey("NonExisting") << endl; | 
|---|
| [3537] | 112 | cout << "7/ FIN lecture depuis tmfb.fits " << endl; | 
|---|
|  | 113 | TArray<int_2> ta(sx, sy); | 
|---|
|  | 114 | for(int k=0; k<sy; k++) | 
|---|
|  | 115 | for(int j=0; j<sx; j++) ta(j, k) = (int_2)data[j+k*sx]; | 
|---|
|  | 116 | POutPersist po("tmfb.ppf"); | 
|---|
|  | 117 | po << ta; | 
|---|
|  | 118 | cout << "8/ FIN ecriture tableau ds tmfb.ppf " << endl; | 
|---|
|  | 119 | delete[] data; | 
|---|
|  | 120 | } | 
|---|
|  | 121 | } | 
|---|
|  | 122 | catch (MiniFITSException& exc) { | 
|---|
|  | 123 | cerr << " tstminifits.cc catched MiniFITSException " << exc.Msg() << endl; | 
|---|
|  | 124 | rc = 77; | 
|---|
|  | 125 | } | 
|---|
|  | 126 | catch (PThrowable& exc) { | 
|---|
|  | 127 | cerr << " tstminifits.cc catched Exception " << exc.Msg() << endl; | 
|---|
|  | 128 | rc = 76; | 
|---|
|  | 129 | } | 
|---|
|  | 130 | catch (std::exception& sex) { | 
|---|
|  | 131 | cerr << "\n tstminifits.cc std::exception :" | 
|---|
|  | 132 | << (string)typeid(sex).name() << "\n msg= " | 
|---|
|  | 133 | << sex.what() << endl; | 
|---|
|  | 134 | rc = 78; | 
|---|
|  | 135 | } | 
|---|
|  | 136 | catch (...) { | 
|---|
|  | 137 | cerr << " tstminifits.cc catched unknown (...) exception  " << endl; | 
|---|
|  | 138 | rc = 79; | 
|---|
|  | 139 | } | 
|---|
|  | 140 |  | 
|---|
|  | 141 | cout << ">>>> tstminifits.cc ------- FIN ----------- RC=" << rc << endl; | 
|---|
|  | 142 | PrtTim("FIN tstminifits.cc"); | 
|---|
|  | 143 | return rc; | 
|---|
|  | 144 |  | 
|---|
|  | 145 | } | 
|---|