Jpp 20.0.0-rc.2
the software that should make you happy
Loading...
Searching...
No Matches
JSeaBird.cc
Go to the documentation of this file.
1#include <string>
2#include <iostream>
3#include <iomanip>
4#include <fstream>
5
6#include "TROOT.h"
7#include "TFile.h"
8#include "TH1D.h"
9#include "TGraph.h"
10
11#include "JROOT/JGraph.hh"
12#include "JROOT/JRootToolkit.hh"
13
15#include "JAcoustics/JUNESCO.hh"
16
17#include "JTools/JRange.hh"
18
19#include "Jeep/JParser.hh"
20#include "Jeep/JMessage.hh"
21
22namespace {
23
24 /**
25 * Auxiliary data structure for Sea-Bird data.
26 */
27 struct seabird {
28 /**
29 * Default constructor.
30 */
31 seabird()
32 {}
33
34
35 /**
36 * Read object from input.
37 *
38 * \param in input stream
39 * \param object object
40 * \return input stream
41 */
42 friend inline std::istream& operator>>(std::istream& in, seabird& object)
43 {
44 double x;
45
46 return in >> object.P
47 >> object.T
48 >> object.C
49 >> object.n
50 >> object.rho
51 >> object.S
52 >> object.z
53 >> object.v
54 >> object.va
55 >> x;
56 }
57
58
59 /**
60 * Write object to output.
61 *
62 * \param out output stream
63 * \param object object
64 * \return output stream
65 */
66 friend inline std::ostream& operator<<(std::ostream& out, const seabird& object)
67 {
68 return out << object.P << ' '
69 << object.T << ' '
70 << object.C << ' '
71 << object.n << ' '
72 << object.rho << ' '
73 << object.S << ' '
74 << object.z << ' '
75 << object.v << ' '
76 << object.va;
77 }
78
79 double P;
80 double T;
81 double C;
82 int n;
83 double rho;
84 double S;
85 double z;
86 double v;
87 double va;
88 };
89}
90
91
92/**
93 */
94int main(int argc, char **argv)
95{
96 using namespace std;
97 using namespace JPP;
98
100
101 string inputFile;
102 string outputFile;
103 JSoundVelocity V = getSoundVelocity; // default sound velocity
104 range_type D;
105 bool option;
106 int debug;
107
108 try {
109
110 JParser<> zap;
111
112 zap['f'] = make_field(inputFile);
113 zap['o'] = make_field(outputFile) = "seabird.root";
114 zap['V'] = make_field(V) = JPARSER::initialised();
115 zap['D'] = make_field(D) = range_type(2500.0, 3450);
116 zap['O'] = make_field(option);
117 zap['d'] = make_field(debug) = 2;
118
119 zap(argc, argv);
120 }
121 catch(const exception &error) {
122 FATAL(error.what() << endl);
123 }
124
125
126 V.set(-D.getUpperLimit());
127
128 const double latitude = 36.0 + 16.0/60.0;
129 const double g = getGravity(latitude);
130
131 DEBUG("Latitude " << FIXED(7,3) << latitude << endl);
132 DEBUG("Gravitational constant [m/s^2] " << FIXED(7,3) << g << endl);
133
134 ifstream in(inputFile.c_str());
135
136 while (in.peek() == '#') {
137 in.ignore(numeric_limits<streamsize>::max(), '\n');
138 }
139
140 JGraph_t ga;
141 JGraph_t gb;
142 JGraph_t gc;
143 JGraph_t gd;
144
145 TH1D hz("hz", NULL, 101, -2.5, +2.5);
146 TH1D h1("v1 [DelGrosso]", NULL, 101, -1.0, +1.0);
147 TH1D h2("v2 [KM3NeT]", NULL, 101, -1.0, +1.0);
148
149 {
150 for (seabird object; in >> object; ) {
151
152 const double z = getDepth(object.P * 1.0e-2, latitude, option);
153 const double v1 = getVelocityDelGrosso(object.P * 0.1, object.S, object.T);
154 const double v2 = V(D.getUpperLimit() - object.z);
155 const double P = getPressure(object.z, latitude, option);
156
157 if (debug >= debug_t) {
158
159 cout << FIXED(9,3) << object.P << ' ';
160
161 cout << FIXED(9,3) << object.z << ' '
162 << FIXED(9,6) << object.v << ' ';
163
164 cout << FIXED(9,6) << v1 << ' '
165 << FIXED(9,6) << v2 << ' ';
166
167 cout << FIXED(9,4) << object.rho << ' ';
168
169 cout << FIXED(9,6) << P << ' ';
170 cout << FIXED(9,3) << z << ' ';
171 cout << endl;
172 }
173
174 if (D(object.z)) {
175 hz.Fill(object.z - z);
176 h1.Fill(object.v - v1);
177 h2.Fill(object.v - v2);
178 }
179
180 ga.put(object.z, object.v);
181 gb.put(object.z, v1);
182 gc.put(object.z, object.v - v1);
183 gd.put(object.z, object.v - v2);
184 }
185 }
186
187
188 TFile out(outputFile.c_str(), "recreate");
189
190 out << hz << h1 << h2;
191
192 out << JGraph(ga, "ga");
193 out << JGraph(gb, "gb");
194 out << JGraph(gc, "gc");
195 out << JGraph(gd, "gd");
196
197 out.Write();
198 out.Close();
199}
string outputFile
std::istream & operator>>(std::istream &in, JAANET::JHead &header)
Read header from input.
Definition JHead.hh:1850
General purpose messaging.
#define DEBUG(A)
Message macros.
Definition JMessage.hh:62
#define FATAL(A)
Definition JMessage.hh:67
int debug
debug level
Definition JSirene.cc:72
Utility class to parse command line options.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition JParser.hh:2142
Auxiliary class to define a range between two values.
int main(int argc, char **argv)
Definition JSeaBird.cc:94
Sound velocity.
Sound velocity according UNESCO equation.
Utility class to parse command line options.
Definition JParser.hh:1698
Range of values.
Definition JRange.hh:42
T getUpperLimit() const
Get upper limit.
Definition JRange.hh:213
std::ostream & operator<<(std::ostream &stream, const CLBCommonHeader &header)
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
const int n
Definition JPolint.hh:791
Auxiliary data structure for floating point format specification.
Definition JManip.hh:448
Implementation for depth dependend velocity of sound.
JSoundVelocity & set(const double z0)
Set depth.
Empty structure for specification of parser element that is initialised (i.e. does not require input)...
Definition JParser.hh:68
Auxiliary data structure to build TGraph.
Definition JGraph.hh:44