-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSegmentAscDec.java
More file actions
101 lines (87 loc) · 3.52 KB
/
SegmentAscDec.java
File metadata and controls
101 lines (87 loc) · 3.52 KB
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
99
100
101
/*
* SegmentAscDec.java
*
* Class of segment for describing ascent/descent dive segments. Specialisation of AbstractSegment
*
* @author Guy Wittig
* @version 18-Jun-2006
*
* This program is part of MV-Plan
* Copywrite 2006 Guy Wittig
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* The GNU General Public License can be read at http://www.gnu.org/licenses/licenses.html
*/
package mvplan.segments;
import mvplan.main.Mvplan;
import mvplan.gas.Gas;
import mvplan.prefs.Prefs;
public class SegmentAscDec extends SegmentAbstract
{
/** Ascent (+ve)/ Descent (-ve) rate in msw/sec */
private double rate; // Ascent (+ve)/ Descent (-ve) rate in msw/sec
/**
* Constructor for objects of class SegmentAscDec
* @param gas Gas object for this segment
* @param startDepth Starting depth of segment in m (ft)
* @param endDepth Ending depth of segment in m (ft)
* @param rate Rate of change of depth in m/min (ft/min)
* @param setpoint Setpoint for segment, or 0.0 for open circuit
*/
public SegmentAscDec(double startDepth, double endDepth, double rate, Gas gas, double setpoint)
{
// Init super fields
super();
super.depth=endDepth;
super.gas=gas;
super.setpoint=setpoint;
// Init this class fields
this.rate=rate;
super.time = (endDepth-startDepth)/rate;
if (startDepth < endDepth)
super.type=super.DESCENT;
else
super.type=super.ASCENT;
}
/** Override gasUsed() to determine the gas used in this segment
* @return Gas Used in litres (cuft)
*/
public double gasUsed()
{
if(setpoint>0.0) return(0.0);
double p; // pressure
double d; // depth
double startDepth;
startDepth=depth - rate*time;
// Calculate average depth
d=startDepth+(depth-startDepth)/2.0;
p=(d+Prefs.getPrefs().getPAmb())/Prefs.getPrefs().getPConversion(); // Convert to pressure (atm);
return( p * time * Prefs.getPrefs().getDiveRMV());
}
/** Gets ascent rate for segment
* @return Ascent Rate in m/min (ft/min)
*/
public double getRate() { return rate; }
/** Override toString to return String representation of AscDecSegment
* @return String representation of AscDEcSegment
*/
public String toStringLong()
{
String s;
int timeMins,timeSeconds;
timeMins=(int)time;
timeSeconds = (int)((time - (double)timeMins)*60.0);
if (super.type == SegmentAbstract.ASCENT) s="ASC "; else s="DESC";
return String.format("%1$4s:%2$3.0f"+Prefs.getPrefs().getDepthShortString()+" for %3$02d:%4$02d [%5$3.0f] on %6$s, SP: %7$3.1f, END:%8$3.0f"+Prefs.getPrefs().getDepthShortString(),
s, depth, timeMins, timeSeconds , runTime, gas.toString(), setpoint, getEnd());
}
}