Jpp  debug
the software that should make you happy
UNESCO.cc
Go to the documentation of this file.
1 #include <iostream>
2 #include <iomanip>
3 #include <string>
4 
5 #include "TROOT.h"
6 #include "TFile.h"
7 #include "TH1D.h"
8 #include "TH2D.h"
9 
10 #include "JAcoustics/JUNESCO.hh"
11 
12 #include "Jeep/JPrint.hh"
13 #include "Jeep/JParser.hh"
14 #include "Jeep/JMessage.hh"
15 
16 namespace {
17 
18  using namespace JPP;
19 
20  const char* const mackenzie_t = "Mackenzie";
21  const char* const coppens_t = "Coppens";
22  const char* const unesco_t = "UNESCO";
23  const char* const delgrosso_t = "DelGrosso";
24 
25  /**
26  * Get sound velocity.
27  *
28  * \param D depth [m]
29  * \param S salinity [ppk]
30  * \param T temperature [C]
31  * \param model model
32  * \return sound velocity [m/s]
33  */
34  inline double getVelocity(const double D, const double S, const double T, const std::string& model)
35  {
36  const double latitude = 36.0 + 16.0/60.0; // [deg]
37  const double P = getPressure(D, latitude, true); // [MPa]
38 
39  if (model == mackenzie_t)
40  return getVelocityMackenzie(D, S, T);
41  else if (model == coppens_t)
42  return getVelocityCoppens(D, S, T);
43  else if (model == unesco_t)
44  return getVelocityUNESCO(P * 1e1, S, T);
45  else if (model == delgrosso_t)
46  return getVelocityDelGrosso(P * 1e1, S, T);
47  else
48  return 0.0;
49  }
50 }
51 
52 /**
53  * \file
54  *
55  * Example program to plot UNESCO sound velocity.
56  * \author mdejong
57  */
58 int main(int argc, char **argv)
59 {
60  using namespace std;
61  using namespace JPP;
62 
63  string outputFile;
64  double D;
65  double S;
66  double T;
67  string model;
68  int debug;
69 
70  try {
71 
72  JParser<> zap("Example program to plot UNESCO sound velocity.");
73 
74  zap['o'] = make_field(outputFile);
75  zap['D'] = make_field(D, "Depth [m]");
76  zap['S'] = make_field(S, "Salinity [ppk]") = 38.7;
77  zap['T'] = make_field(T, "Temperature [C]") = 14.0;
78  zap['M'] = make_field(model, "model") = mackenzie_t, coppens_t, unesco_t, delgrosso_t;
79  zap['d'] = make_field(debug) = 2;
80 
81  zap(argc, argv);
82  }
83  catch(const exception &error) {
84  FATAL(error.what() << endl);
85  }
86 
87 
88  const double Z[] = { 2000.0, 3450.0 };
89 
90  STATUS("Velocity "
91  << setw(10) << left << model << right << ' '
92  << FIXED(9,2) << getVelocity(Z[0], S, T, model) << ' '
93  << SCIENTIFIC(12,3) << (getVelocity(Z[0], S, T, model) - getVelocity(Z[1], S, T, model)) / (Z[1] - Z[0]) << ' '
94  << FIXED(9,2) << -Z[0] << endl);
95 
96  TFile out(outputFile.c_str(), "recreate");
97 
98  TH1D h1(MAKE_CSTRING("h1 [" << model << "]"), NULL, 1000, 2000.0, 3500);
99  TH2D h2(MAKE_CSTRING("h2 [" << model << "]"), NULL, 1000, 10.0, 20.0, 1000, 25.0, 40.0);
100 
101  for (Int_t ix = 1; ix <= h1.GetXaxis()->GetNbins(); ++ix) {
102 
103  const Double_t D = h1.GetXaxis()->GetBinCenter(ix);
104  const double V = getVelocity(D, S, T, model);
105 
106  h1.SetBinContent(ix, V);
107  }
108 
109  for (Int_t ix = 1; ix <= h2.GetXaxis()->GetNbins(); ++ix) {
110  for (Int_t iy = 1; iy <= h2.GetXaxis()->GetNbins(); ++iy) {
111 
112  const Double_t T = h2.GetXaxis()->GetBinCenter(ix);
113  const Double_t S = h2.GetYaxis()->GetBinCenter(iy);
114 
115  const double V = getVelocity(D, S, T, model);
116 
117  h2.SetBinContent(ix, iy, V);
118  }
119  }
120 
121  out.Write();
122  out.Close();
123 }
string outputFile
General purpose messaging.
#define STATUS(A)
Definition: JMessage.hh:63
#define FATAL(A)
Definition: JMessage.hh:67
int debug
debug level
Definition: JSirene.cc:69
Utility class to parse command line options.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:2158
I/O formatting auxiliaries.
#define MAKE_CSTRING(A)
Make C-string.
Definition: JPrint.hh:136
Sound velocity according UNESCO equation.
int main(int argc, char **argv)
Definition: UNESCO.cc:58
Utility class to parse command line options.
Definition: JParser.hh:1714
double getPressure(const double z, const double phi, const bool option=true)
Get pressure.
Definition: JUNESCO.hh:259
double getVelocityDelGrosso(const double p, const double S, const double T)
Get sound velocity.
Definition: JUNESCO.hh:182
double getVelocityCoppens(const double D, const double S, const double T)
Get sound velocity.
Definition: JUNESCO.hh:71
double getVelocityMackenzie(const double D, const double S, const double T)
Get sound velocity.
Definition: JUNESCO.hh:46
double getVelocityUNESCO(const double P, const double S, const double T)
Get sound velocity.
Definition: JUNESCO.hh:95
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Definition: JSTDTypes.hh:14
Auxiliary data structure for floating point format specification.
Definition: JManip.hh:448
Auxiliary data structure for floating point format specification.
Definition: JManip.hh:488