source: Sophya/trunk/Poubelle/archTOI.old/archtoi.cc@ 342

Last change on this file since 342 was 342, checked in by ansari, 26 years ago

archtoi 2 aout 99

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