-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathfindManyOrbitProperties.cc
98 lines (79 loc) · 2.83 KB
/
findManyOrbitProperties.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/*******************************************************************************
* *
* findManyOrbitProperties.cc *
* *
* C++ code written by Paul McMillan, 2007- *
* Lund Observatory, Lund University. *
* address: Box 43, SE-221 00 Lund, Sweden *
* e-mail: [email protected] *
* *
*******************************************************************************/
#include "GalPot.h"
#include "OrbitIntegrator.h"
#include <ctime>
int main(int argc,char *argv[])
{
ifstream file,data;
ofstream output;
string potfile = "pot/PJM16_best.Tpot",line;
Potential *Phi;
// Read potential from file
file.open(potfile.c_str());
if(!file){
cerr << "Input file does not exist. Filename: " << potfile << "\n";
return 1;
}
Phi = new GalaxyPotential(file);
file.close();
if(argc<3) {
cerr << "Input: input_file output_file\n";
cerr << "input_file must contain columns: R z v_R v_z v_phi\n";
cerr << " (distance in kpc, velocity in km/s)\n";
cerr << " output is in kpc (distances), km^2/s^2 (energy), kpc km/s (angular momentum)\n";
return 1;
}
// Open file for input
data.open(argv[1]);
if(!file){
cerr << "Input file does not exist. Filename: " << string(argv[1]) << "\n";
return 0;
}
// Open for output
output.open(argv[2]);
// Write header
output << "#MinR MaxR Maxz Minr Maxr MeanR Energy AngMom\n" << std::flush;
// Setup class
Vector <double,6> XV=1.;
OrbitIntegratorWithStats OI(XV, Phi, 10000.);
int nline;
// read file
while(getline(data,line)) {
// Skip commented lines (which start with #)
if(line[0] != '#') {
std::stringstream ss(line);
for(int i=0;i!=5;i++)
if(i<2) ss >> XV[i];
else ss >> XV[i+1];
// Convert input to code coordinates
XV[0] *= Units::kpc;
XV[1] *= Units::kpc;
//XV[2] *= Units::degree;
XV[3] *= Units::kms;
XV[4] *= Units::kms;
XV[5] *= Units::kms;
OI.setup(XV);
// run integration
if(OI.run() == 0) {
// Output results if successful
output << OI.MinR<< ' ' << OI.MaxR<< ' ' << OI.Maxz<< ' '
<< OI.Minr<< ' ' << OI.Maxr<< ' ' << OI.MeanR<< ' '
<< OI.Energy/(Units::kms*Units::kms)<< ' '
<< OI.Lz/(Units::kms*Units::kpc) << '\n' << std::flush;
} else {
cerr << "Failure for line: " << line
<< "\nEnergy=" << OI.Energy/(Units::kms*Units::kms) << '\n';
}
}
}
return 0;
}