1 | #include "sopnamsp.h"
|
---|
2 | #include "machdefs.h"
|
---|
3 | #include <stdio.h>
|
---|
4 | #include <stdlib.h>
|
---|
5 | #include "math.h"
|
---|
6 | #include <iostream>
|
---|
7 | #include <string>
|
---|
8 | #include <vector>
|
---|
9 |
|
---|
10 | #include <typeinfo>
|
---|
11 | #include "timing.h"
|
---|
12 | #include "ctimer.h"
|
---|
13 | #include "timestamp.h"
|
---|
14 | #include "histinit.h"
|
---|
15 | #include "pexceptions.h"
|
---|
16 | #include "ppfwrapstlv.h"
|
---|
17 |
|
---|
18 | /* Programme test de la classe TimeStamp */
|
---|
19 | /* SOPHYA - R. Ansari (LAL) - Mars 2005 */
|
---|
20 |
|
---|
21 | int main(int narg, char* arg[])
|
---|
22 | {
|
---|
23 | cout << " ---- Programme ttimestamp.cc - Test classe TimeStamp --- " << endl;
|
---|
24 | int rc = 0;
|
---|
25 | try {
|
---|
26 | SophyaInit();
|
---|
27 | // PPRegister(FIO_SphereECP<r_8>);
|
---|
28 | // DObjRegister(FIO_SphereECP<r_8>, SphereECP<r_8>);
|
---|
29 |
|
---|
30 | InitTim();
|
---|
31 | cout << " Sizeof(TimeStamp=) " << sizeof(TimeStamp) << endl;
|
---|
32 | TimeStamp ts;
|
---|
33 | cout << "ts: Now : " << ts << "(->double: " << (double)ts << " )" << endl;
|
---|
34 | TimeStamp ts2("26/8/1974","14:22:35.65");
|
---|
35 | cout << "ts2: 26/8/1974 14:22:35.65 : " << ts2
|
---|
36 | << " double->TimeStamp: " << TimeStamp(ts2.ToDays()) << endl;
|
---|
37 | TimeStamp ts3("08/05/1905","00:00:00");
|
---|
38 | cout << "ts3: 8/05/1905 , 00:00:00 : " << ts3 << " (double): "
|
---|
39 | << (double)ts3 << " double->TimeStamp: " << TimeStamp(ts3.ToDays()) << endl;
|
---|
40 | TimeStamp ts4("01/01/1901","03:00:20");
|
---|
41 | cout << "ts3: 01/01/1901 , 03:00:20 : " << ts4 << " (double): "
|
---|
42 | << (double)ts4 << " double->TimeStamp: " << TimeStamp(ts4.ToDays()) << endl;
|
---|
43 |
|
---|
44 | TimeStamp ts5("01/12/1899","00:00:00");
|
---|
45 | cout << "ts5: 01/12/1899 , 00:00:00 : " << ts5 << " (double): "
|
---|
46 | << (double)ts5 << " double->TimeStamp: " << TimeStamp(ts5.ToDays()) << endl;
|
---|
47 | TimeStamp ts6("01/12/1899","15:30:00");
|
---|
48 | cout << "ts6: 01/12/1899 , 15:30:00 : " << ts6 << " (double): "
|
---|
49 | << (double)ts6 << " double->TimeStamp: " << TimeStamp(ts6.ToDays()) << endl;
|
---|
50 |
|
---|
51 | cout << " ts.ToString(bool, bool) test : " << endl;
|
---|
52 | cout << " ts.ToString()= " << ts.ToString() << endl;
|
---|
53 | cout << " ts.ToString(FmtDateOnly)= " << ts.ToString(TimeStamp::FmtDateOnly) << endl;
|
---|
54 | cout << " ts.ToString(FmtTimeOnly)= " << ts.ToString(TimeStamp::FmtTimeOnly) << endl;
|
---|
55 | cout << " ts.ToString(FmtDateTime)= " << ts.ToString(TimeStamp::FmtDateTime) << endl;
|
---|
56 |
|
---|
57 | TimeStamp ts12("1974-08-26T14:22:35.65");
|
---|
58 | cout << "ts12: 1974-08-26T14:22:35.65 : " << ts12
|
---|
59 | << " double->TimeStamp: " << TimeStamp(ts12.ToDays()) << endl;
|
---|
60 | TimeStamp ts13("1905-05-08T00:00:00");
|
---|
61 | cout << "ts13: 1905-05-08T00:00:00 " << ts13 << " (double): "
|
---|
62 | << (double)ts13 << " double->TimeStamp: " << TimeStamp(ts13.ToDays()) << endl;
|
---|
63 |
|
---|
64 | double diff;
|
---|
65 | diff = ts12.ToDays()-ts2.ToDays();
|
---|
66 | if (fabs(diff) > 1.e-6) {
|
---|
67 | cout << "ttimestamp/Erreur Diff t12-t2 : Rc+=1 " << endl;
|
---|
68 | rc += 1;
|
---|
69 | }
|
---|
70 | diff = ts13.ToDays()-ts3.ToDays();
|
---|
71 | if (fabs(diff) > 1.e-6) {
|
---|
72 | cout << "ttimestamp/Erreur Diff t13-t3 : Rc+=2 " << endl;
|
---|
73 | rc += 2;
|
---|
74 | }
|
---|
75 | TimeStamp tsa("1901-1-1T14:0:0");
|
---|
76 | diff = tsa.ToDays()-38./24.;
|
---|
77 | if (fabs(diff) > 1.e-6) {
|
---|
78 | cout << "ttimestamp/Erreur Diff tsa-38/24. : Rc+=4 " << endl;
|
---|
79 | rc += 4;
|
---|
80 | }
|
---|
81 | tsa.Set("1901-02-07T18:00:00");
|
---|
82 | diff = tsa.ToDays()-38.75;
|
---|
83 | if (fabs(diff) > 1.e-6) {
|
---|
84 | cout << "ttimestamp/Erreur Diff tsa-38.75 : Rc+=8 " << endl;
|
---|
85 | rc += 8;
|
---|
86 | }
|
---|
87 | tsa.Set("2004-08-24T18:00:00");
|
---|
88 | TimeStamp tsb("2004-09-03T21:00:00");
|
---|
89 | diff = tsb.ToDays()-tsa.ToDays();
|
---|
90 | if (fabs(diff-10.125) > 1.e-6) {
|
---|
91 | cout << "ttimestamp/Erreur Diff tsb-tsa : Rc+=16 " << endl;
|
---|
92 | rc += 16;
|
---|
93 | }
|
---|
94 | if (rc == 0)
|
---|
95 | cout << "ttimestamp/Info CheckDiffs OK (Rc=" << rc << ")" << endl;
|
---|
96 | else
|
---|
97 | cout << "ttimestamp/Erreur Pb Diffs (Rc=" << rc << ")" << endl;
|
---|
98 |
|
---|
99 | cout << "ttimestamp/Info: Test PPF , vector<TimeStamp> " << endl;
|
---|
100 | vector<TimeStamp> vts, vtsr;
|
---|
101 | vts.push_back(ts);
|
---|
102 | vts.push_back(ts2);
|
---|
103 | vts.push_back(ts3);
|
---|
104 | {
|
---|
105 | POutPersist so("tts.ppf");
|
---|
106 | so << vts;
|
---|
107 | }
|
---|
108 | cout << "ttimestamp/Info: Reading from tts.ppf " << endl;
|
---|
109 | PInPersist si("tts.ppf");
|
---|
110 |
|
---|
111 | si >> vtsr;
|
---|
112 | for(int kk=0; kk<vtsr.size(); kk++) {
|
---|
113 | cout << " vtsr[" << kk << "] : " << vtsr[kk] << endl;
|
---|
114 | diff = vtsr[kk].ToDays()-vts[kk].ToDays();
|
---|
115 | if (fabs(diff) > 1.e-6) {
|
---|
116 | cout << "ttimestamp/Erreur Diff vtsr[kk]-vts[kk] : Rc+=32 " << endl;
|
---|
117 | rc += 32;
|
---|
118 | }
|
---|
119 | }
|
---|
120 | if (rc >= 32)
|
---|
121 | cout << "ttimestamp/Info Pb Diffs vector<TimeStamp>/PPF (Rc="
|
---|
122 | << rc << ")" << endl;
|
---|
123 | else
|
---|
124 | cout << "ttimestamp/Erreur Diffs vector<TimeStamp>/PPF OK" << endl;
|
---|
125 |
|
---|
126 | cout << " ---- Mesure de temps ---- " << endl;
|
---|
127 | Timer tm(false);
|
---|
128 | for(int i=0;i<100000;i++) {
|
---|
129 | TimeStamp tsl;
|
---|
130 | }
|
---|
131 | cout << "P1- Apres 100000 TimeStamp ts \n" << tm << endl;
|
---|
132 | for(int i=0;i<100000;i++) {
|
---|
133 | TimeStamp tsl(2009+i/365,10,i%30, 15,45,0.);
|
---|
134 | }
|
---|
135 | cout << "P2- Apres 100000 TimeStamp ts(y,m,d,h,m,s) \n" << tm << endl;
|
---|
136 |
|
---|
137 | double days;
|
---|
138 | for(int i=0;i<100000;i++) {
|
---|
139 | TimeStamp tsl;
|
---|
140 | TimeStamp tsl2(2009+i/365,10,i%30, 15,45,0.);
|
---|
141 | days += tsl2.ToDays()-tsl.ToDays();
|
---|
142 | }
|
---|
143 | cout << "P3- Apres 100000 TimeStamp t1-ts(y,m,d,h,m,s) \n" << tm << endl;
|
---|
144 |
|
---|
145 | }
|
---|
146 | catch (PThrowable & exc) {
|
---|
147 | cerr << " ttimestamp.cc: Catched Exception (PThrowable)" << (string)typeid(exc).name()
|
---|
148 | << " - Msg= " << exc.Msg() << endl;
|
---|
149 | rc = 99;
|
---|
150 | }
|
---|
151 | catch (std::exception & e) {
|
---|
152 | cerr << " ttimestamp.cc: Catched std::xception "
|
---|
153 | << " - what()= " << e.what() << endl;
|
---|
154 | rc = 98;
|
---|
155 | }
|
---|
156 | catch (...) {
|
---|
157 | cerr << " ttimestamp.cc: some other exception (...) was caught ! " << endl;
|
---|
158 | rc = 97;
|
---|
159 | }
|
---|
160 | PrtTim("End ttimestamp " );
|
---|
161 | cout << " ---- Programme ttimestamp.cc- FIN (Rc=" << rc << ") --- " << endl;
|
---|
162 | return rc;
|
---|
163 | }
|
---|