1 | // archtoi.cc
|
---|
2 | // Eric Aubourg CEA/DAPNIA/SPP juillet 1999
|
---|
3 |
|
---|
4 |
|
---|
5 | #include <string>
|
---|
6 | #include <iostream.h>
|
---|
7 | #include <fstream.h>
|
---|
8 | #include <iomanip.h>
|
---|
9 |
|
---|
10 | #include "archeopsfile.h"
|
---|
11 | #include "toisvr.h"
|
---|
12 | #include "archtoi.h"
|
---|
13 |
|
---|
14 | using namespace std;
|
---|
15 |
|
---|
16 |
|
---|
17 | ArchTOI::ArchTOI(istream& str)
|
---|
18 | {
|
---|
19 | init();
|
---|
20 | readReq(str);
|
---|
21 | }
|
---|
22 |
|
---|
23 |
|
---|
24 | ArchTOI::ArchTOI(string const& filename)
|
---|
25 | {
|
---|
26 | init();
|
---|
27 | ifstream str(filename.c_str());
|
---|
28 | readReq(str);
|
---|
29 | }
|
---|
30 |
|
---|
31 | void ArchTOI::init()
|
---|
32 | {
|
---|
33 | format = ascii_fmt;
|
---|
34 | undef = "#";
|
---|
35 | allBolos = false;
|
---|
36 | }
|
---|
37 |
|
---|
38 | void ArchTOI::readReq(istream& str)
|
---|
39 | {
|
---|
40 | string line;
|
---|
41 | while (str) {
|
---|
42 | getline(str,line);
|
---|
43 | if (!str) break;
|
---|
44 | if (line[0] == '@') processTOIReq(line);
|
---|
45 | else if (line[0] == '#')
|
---|
46 | if (!processOption(line)) break;
|
---|
47 | }
|
---|
48 | }
|
---|
49 |
|
---|
50 | #define tsttoi(toi) if (key == "@"#toi) kind = toi;
|
---|
51 |
|
---|
52 | void ArchTOI::processTOIReq(string line)
|
---|
53 | {
|
---|
54 | // find TOI kind, index and options
|
---|
55 | TOIKind kind= (TOIKind)-1;
|
---|
56 | int index=0;
|
---|
57 | bool interp=false;
|
---|
58 | bool repet =false;
|
---|
59 | bool flag =false;
|
---|
60 | bool notrig=false;
|
---|
61 | int x = line.find(' ');
|
---|
62 | string key = line.substr(0, x);
|
---|
63 | string opts = (x>0) ? line.substr(x) : string("");
|
---|
64 | tsttoi(sampleNum)
|
---|
65 | else tsttoi(internalTime)
|
---|
66 | else tsttoi(mjd)
|
---|
67 | else tsttoi(boloTens)
|
---|
68 | else tsttoi(boloRaw)
|
---|
69 | else tsttoi(sstDiode)
|
---|
70 | else tsttoi(sstChannel)
|
---|
71 | else tsttoi(sstStarZ)
|
---|
72 | else tsttoi(sstStarF)
|
---|
73 | else tsttoi(gyroRaw)
|
---|
74 | else tsttoi(gpsTime)
|
---|
75 | else tsttoi(longitude)
|
---|
76 | else tsttoi(latitude)
|
---|
77 | else tsttoi(altitude)
|
---|
78 | else tsttoi(tsid)
|
---|
79 | else tsttoi(azimut)
|
---|
80 | else tsttoi(alphaAxis)
|
---|
81 | else tsttoi(deltaAxis)
|
---|
82 | else tsttoi(alphaBolo)
|
---|
83 | else tsttoi(deltaBolo)
|
---|
84 | else {
|
---|
85 | cerr << "*Warning, unrecognized TOI " << line << endl;
|
---|
86 | return;
|
---|
87 | }
|
---|
88 | if (kind == sampleNum) notrig = true;
|
---|
89 | while (opts != "") {
|
---|
90 | if (opts[0] == ' ') {
|
---|
91 | opts = opts.substr(opts.find_first_not_of(' '));
|
---|
92 | if (opts == "") break;
|
---|
93 | }
|
---|
94 | x = opts.find(' ');
|
---|
95 | string opt = opts.substr(0, x);
|
---|
96 | opts = (x>0) ? opts.substr(x) : string("");
|
---|
97 | if (opt[0]>='0' && opt[0]<='9') {
|
---|
98 | index = atoi(opt.c_str());
|
---|
99 | } else if (opt == "notrig") {
|
---|
100 | notrig = true;
|
---|
101 | } else if (opt == "repet") {
|
---|
102 | repet = true; interp = false;
|
---|
103 | } else if (opt == "interp") {
|
---|
104 | interp = true; repet = false;
|
---|
105 | } else if (opt == "flag") {
|
---|
106 | flag = true;
|
---|
107 | }
|
---|
108 | }
|
---|
109 | headertoi.push_back(line);
|
---|
110 | toiflags.push_back(flg((flag?hasflag:0)+((!repet&&!interp)?useNA:0)));
|
---|
111 | svr.AddInfo(kind, index, !notrig, interp);
|
---|
112 | }
|
---|
113 |
|
---|
114 | bool ArchTOI::processOption(string line)
|
---|
115 | {
|
---|
116 | int x = line.find(' ');
|
---|
117 | string key = line.substr(0, x);
|
---|
118 | string arg = (x>0) ? line.substr(x) : string("");
|
---|
119 | if (arg.length()>0 && arg[0] == ' ') {
|
---|
120 | arg = arg.substr(arg.find_first_not_of(' '));
|
---|
121 | }
|
---|
122 | if (key == "#ASCII") {
|
---|
123 | format = ascii_fmt;
|
---|
124 | } else if (key == "#FITS") {
|
---|
125 | format = fits_fmt;
|
---|
126 | } else if (key == "#TRANGE") {
|
---|
127 | double tmin, tmax;
|
---|
128 | sscanf(arg.c_str(), "%lg %lg", &tmin, &tmax);
|
---|
129 | svr.SetTimeInterval(tmin, tmax);
|
---|
130 | } else if (key == "#PATH") {
|
---|
131 | svr.SetDirectory(arg);
|
---|
132 | } else if (key == "#FILE") {
|
---|
133 | svr.AddFile(arg);
|
---|
134 | } else if (key == "#UNDEF") {
|
---|
135 | undef=arg;
|
---|
136 | } else if (key == "#ALLBOLOS") {
|
---|
137 | allBolos=true;
|
---|
138 | } else if (key == "#RECORDER") {
|
---|
139 | svr.OnBoardRecorderFiles(true);
|
---|
140 | } else if (key == "#MJD0") {
|
---|
141 | double t0;
|
---|
142 | sscanf(arg.c_str(), "%lg", &t0);
|
---|
143 | svr.SetMJD0(t0);
|
---|
144 | } else if (key == "#PERECH") {
|
---|
145 | double t0;
|
---|
146 | sscanf(arg.c_str(), "%lg", &t0);
|
---|
147 | svr.SetPerEch(t0);
|
---|
148 | } else if (key == "#END") {
|
---|
149 | return false;
|
---|
150 | } else {
|
---|
151 | cerr << "*Warning, unrecognized option " << line << endl;
|
---|
152 | return true;
|
---|
153 | }
|
---|
154 |
|
---|
155 | headeropt.push_back(line);
|
---|
156 | return true;
|
---|
157 | }
|
---|
158 |
|
---|
159 |
|
---|
160 | void ArchTOI::run(string const& filename)
|
---|
161 | {
|
---|
162 | ofstream str(filename.c_str());
|
---|
163 | run(str);
|
---|
164 | }
|
---|
165 |
|
---|
166 | void ArchTOI::run(ostream& str)
|
---|
167 | {
|
---|
168 | // output header
|
---|
169 | for (list<string>::iterator i = headertoi.begin(); i != headertoi.end(); i++)
|
---|
170 | str << (*i) << '\n';
|
---|
171 | for (list<string>::iterator i = headeropt.begin(); i != headeropt.end(); i++)
|
---|
172 | str << (*i) << '\n';;
|
---|
173 |
|
---|
174 | cout << "starting query" << endl;
|
---|
175 | TOIIter iter = svr.DoQuery();
|
---|
176 | // Normalement, on a un bloc param...
|
---|
177 | block_type_param* blk = iter.lastParam();
|
---|
178 | if (blk) {
|
---|
179 | int nb = blk->param.nb_bolo;
|
---|
180 | for (int i=0; i<nb; i++) {
|
---|
181 | #if version_num > 25
|
---|
182 | if (allBolos) {
|
---|
183 | str << "$BOLO " << i << " "
|
---|
184 | << blk->param.nom_coef[blk->param.bolo[i].numero_nom_coef].bolo_nom << " "
|
---|
185 | << blk->param.bolo[i].bolo_code_util << '\n';
|
---|
186 | } else if (blk->param.bolo[i].bolo_code_util != bolo_hors_service &&
|
---|
187 | blk->param.bolo[i].bolo_code_util != bolo_normal_non_transmis) {
|
---|
188 | str << "$BOLO " << i << " "
|
---|
189 | << blk->param.nom_coef[blk->param.bolo[i].numero_nom_coef].bolo_nom << "\n";
|
---|
190 | }
|
---|
191 | #else
|
---|
192 | str << "$BOLO " << i << " " <<
|
---|
193 | blk->param.bolo[i].bolo_nom << '\n';
|
---|
194 | #endif
|
---|
195 | }
|
---|
196 | }
|
---|
197 | str << "#END" << endl;
|
---|
198 | cout << "processing" << endl;
|
---|
199 | string ofn;
|
---|
200 | while (iter.Next()) {
|
---|
201 | int nn = iter.getSampleIndex();
|
---|
202 | if (nn%200 == 0) {
|
---|
203 | cout << "."; cout.flush();
|
---|
204 | }
|
---|
205 | if (nn%(200*80) == 0) cout << endl;
|
---|
206 | // Si rien de dispo parmi les triggering, alors on passe au suivant
|
---|
207 | bool hasValue = false;
|
---|
208 | for (int i=0; i<toiflags.size(); i++) {
|
---|
209 | if (!iter.isTrig(i)) continue;
|
---|
210 | if (iter.canGetValue(i)) {hasValue=true; break;}
|
---|
211 | }
|
---|
212 | if (!hasValue) continue;
|
---|
213 | for (int i=0; i<toiflags.size(); i++) {
|
---|
214 | double value = iter.getValue(i);
|
---|
215 | bool ok = iter.canGetValue(i);
|
---|
216 | bool isnew = iter.newValue(i);
|
---|
217 | flg flag = toiflags[i];
|
---|
218 | if (flag & hasflag) str << (ok && isnew ? 1 : 0) << " \t";
|
---|
219 | if (((flag & useNA)!=0 && !isnew) || !ok)
|
---|
220 | str << undef << "\t";
|
---|
221 | else
|
---|
222 | str << setprecision(11) << value << " \t";
|
---|
223 | }
|
---|
224 | str << '\n';
|
---|
225 | }
|
---|
226 | str.flush();
|
---|
227 | cout << "\nDone." << endl;
|
---|
228 | }
|
---|
229 |
|
---|