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 {
|
---|
42 | {
|
---|
43 | cout << "1/ Creation tableau " << endl;
|
---|
44 | size_t sx = 300;
|
---|
45 | size_t sy = 200;
|
---|
46 | TArray<int_2> ta(sx, sy);
|
---|
47 | TArray<r_4> arr(sx, sy);
|
---|
48 | ta = RegularSequence(0.,0.5);
|
---|
49 | ta.Show();
|
---|
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;
|
---|
53 | POutPersist po("tmf.ppf");
|
---|
54 | po << ta << arr;
|
---|
55 | cout << "3/ ecriture tableau ds tmf.fits " << endl;
|
---|
56 | {
|
---|
57 | MiniFITSFile mff;
|
---|
58 | mff.setDTypeNaxis(MF_Float32, sx, sy);
|
---|
59 | mff.Open("tmf.fits", MF_Write);
|
---|
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) ");
|
---|
68 | mff.WriteI(ta.Data(), sx*sy);
|
---|
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);
|
---|
75 | TimeStamp tsc;
|
---|
76 | string cdtu=tsc.ToString();
|
---|
77 | mff.AddKeyS("DATE", cdtu.c_str(), " File Creation time(YYYY-MM-DDThh:mm:ss UT) ");
|
---|
78 | mff.WriteF(arr.Data(), sx*sy);
|
---|
79 | }
|
---|
80 | cout << "3.c/ FIN ecriture tableau ds tmf.fits " << endl;
|
---|
81 | }
|
---|
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);
|
---|
95 | delete [] data;
|
---|
96 | cout << "5/ FIN ecriture tableau ds tmfb.fits " << endl;
|
---|
97 | }
|
---|
98 | // -------------- Lecture de bytes
|
---|
99 | {
|
---|
100 | cout << "6/ Ouverture/lecture tmfb.fits" << endl;
|
---|
101 | MiniFITSFile mff("tmfb.fits", MF_Read);
|
---|
102 | cout << "6.b/ Type=" << mff.DataTypeToString() << " NAxis1=" << mff.NAxis1()
|
---|
103 | << " NAxis2=" << mff.NAxis2() << endl;
|
---|
104 | size_t sx = mff.NAxis1();
|
---|
105 | size_t sy = mff.NAxis2();
|
---|
106 | uint_1* data = new uint_1[sx*sy];
|
---|
107 | mff.ReadB(data, sx*sy);
|
---|
108 | cout << "7/ FIN lecture depuis tmfb.fits " << endl;
|
---|
109 | TArray<int_2> ta(sx, sy);
|
---|
110 | for(int k=0; k<sy; k++)
|
---|
111 | for(int j=0; j<sx; j++) ta(j, k) = (int_2)data[j+k*sx];
|
---|
112 | POutPersist po("tmfb.ppf");
|
---|
113 | po << ta;
|
---|
114 | cout << "8/ FIN ecriture tableau ds tmfb.ppf " << endl;
|
---|
115 | delete[] data;
|
---|
116 | }
|
---|
117 | }
|
---|
118 | catch (MiniFITSException& exc) {
|
---|
119 | cerr << " tstminifits.cc catched MiniFITSException " << exc.Msg() << endl;
|
---|
120 | rc = 77;
|
---|
121 | }
|
---|
122 | catch (PThrowable& exc) {
|
---|
123 | cerr << " tstminifits.cc catched Exception " << exc.Msg() << endl;
|
---|
124 | rc = 76;
|
---|
125 | }
|
---|
126 | catch (std::exception& sex) {
|
---|
127 | cerr << "\n tstminifits.cc std::exception :"
|
---|
128 | << (string)typeid(sex).name() << "\n msg= "
|
---|
129 | << sex.what() << endl;
|
---|
130 | rc = 78;
|
---|
131 | }
|
---|
132 | catch (...) {
|
---|
133 | cerr << " tstminifits.cc catched unknown (...) exception " << endl;
|
---|
134 | rc = 79;
|
---|
135 | }
|
---|
136 |
|
---|
137 | cout << ">>>> tstminifits.cc ------- FIN ----------- RC=" << rc << endl;
|
---|
138 | PrtTim("FIN tstminifits.cc");
|
---|
139 | return rc;
|
---|
140 |
|
---|
141 | }
|
---|