Jump to content

Scuba RDP


Reaper HGN
 Share

Recommended Posts

I am currently working through my DMC. Part of that requires a pretty good understanding of the RDP tables and how to calculate various pressure groups, surface intervals and repetitive dive data. Admittedly I was a little weak in this area, so I thought what better way to really cement the subject, than to program a utility to do the calculations for me. It seems counter intuitive, but if you know a subject well enough to write a program, you end up learning quite a bit about it. Anyway, this script takes the initial dive depth, dive time, surface interval and planned second dive depth. It will then calculate the initial pressure group, the ending pressure group after the surface interval, and the adjusted actual (allowable) bottom time for that second dive.

A couple of caveats. I looked extensively and found that the PADI tables that I used are copyrighted, but the data itself is public domain. So as far as I can tell, its ok to contain the data in the code. Also, I manually input the data (which is quite a bit). There may be some transcription errors, so just be aware of that. Let me know what you think.

;*****************************************
;Dive_Calc.au3 by David Sisson
;*****************************************
#Include <Array.au3>

$i_depth = 50
$i_time = 50
$i_surfaceinterval = "0:39"
$i_depth2 = 30

$i_tabledepth = _GetTableDepth($i_depth)
$s_tablepressuregroup = _GetPressureGroup($i_time, $i_tabledepth)
$s_endingtablepressuregroup = _GetPressureGroupAfterSurfaceInterval($s_tablepressuregroup, $i_surfaceinterval)
$i_tabledepth2 = _GetTableDepth($i_depth2)
$i_adjustedbottomtime = _GetPressureGroup($i_time, $i_tabledepth2, $s_endingtablepressuregroup)

consolewrite ("Dive depth:" & $i_depth & @CRLF)
ConsoleWrite ("Dive table depth:" & $i_tabledepth & @CRLF)
consolewrite ("Dive time:" & $i_time & @CRLF)
ConsoleWrite ("Pressure group:" & $s_tablepressuregroup & @CRLF)
ConsoleWrite ("Surface Interval (minutes):" & _ConvertToMinutes($i_surfaceinterval) & @CRLF)
ConsoleWrite ("Ending pressure group:" & $s_endingtablepressuregroup & @CRLF)
ConsoleWrite ("Second Dive depth:" & $i_depth2 & @CRLF)
ConsoleWrite ("Adjusted actual bottom time:" & $i_adjustedbottomtime & @CRLF)

Func _GetPressureGroup($_time, $_depth, $_pg="")
local $_pressuregroups[26] = ["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"]
local $_suffix = ""
if $_pg <> "" Then
  ;find the index for the pressure group
  for $j = 0 to UBound($_pressuregroups)-1
   if $_pressuregroups[$j] == StringLeft($_pg,1) Then
    $_pgindex = $j
   EndIf
  Next
  $_arraytouse = _GetArrayToUse($_depth)
  $_rnt = $_arraytouse[$_pgindex]
  $_abt = $_arraytouse[UBound($_arraytouse)-1]*1 - $_rnt
  Return $_abt
EndIf
$_arraytouse = _GetArrayToUse($_depth)
for $i = 0 to UBound($_arraytouse)-1
  if $_time <= $_arraytouse[$i] Then
   if StringInStr($_arraytouse[$i],"*") Then $_suffix = ", SS required"
   if StringInStr($_arraytouse[$i],"&") Then $_suffix = ", SS required.  Max limit reached."
   Return $_pressuregroups[$i] & $_suffix
  EndIf
Next
Return ("Too long")
EndFunc

Func _GetTableDepth($_depth)
local $_tabledepths[12] = [35,40,50,60,70,80,90,100,110,120,130,140]
for $i = 0 to UBound($_tabledepths)-1
  ;compare depth to range
  if $_depth <= $_tabledepths[$i]*1 Then Return $_tabledepths[$i]
Next
Return ("Too deep")
EndFunc

Func _GetPressureGroupAfterSurfaceInterval($_pressuregroup, $_surfaceinterval)
local $_pressuregroups[26] = ["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"]
local $_si, $_currentpressuregroup
$_si = _ConvertToMinutes($i_surfaceinterval)
if $_si = 0 Then Return "No additional dives."
$_tablesurfaceintervals = _GetPressureArrayToUse($_pressuregroup)
ReDim $_pressuregroups[ubound($_tablesurfaceintervals)]
_ArrayReverse($_pressuregroups)
  for $i = UBound($_tablesurfaceintervals)-1 to 0 step -1

   if  _ConvertToMinutes($_si)*1 <= _ConvertToMinutes($_tablesurfaceintervals[$i])*1  Then
    $_currentpressuregroup = $_pressuregroups[$i]
   EndIf
  Next
  if $_currentpressuregroup <> "" Then
   Return $_currentpressuregroup
  Else
   Return ("No pressure group")
  EndIf
EndFunc

Func _GetArrayToUse($_depth)
local $_bottomtime35[26] = [10,19,25,29,32,36,40,44,48,52,57,62,67,73,79,85,92,100,108,117,127,139,"152*","168*","188*","205&"]
local $_bottomtime40[26] = [9,16,22,25,27,31,34,37,40,44,48,51,55,60,64,69,74,79,85,91,97,104,"111*","120*","129*","140&"]
local $_bottomtime50[24] = [7,13,17,19,21,24,26,28,31,33,36,39,41,44,47,50,53,57,60,63,"67*","71*","75*","80&"]
local $_bottomtime60[23] = [6,11,14,16,17,19,21,23,25,27,29,31,33,35,37,39,42,44,47,"49*","52*","54*","55&"]
local $_bottomtime70[20] = [5,9,12,13,15,16,18,19,21,22,24,26,27,29,31,33,"35*","36*","38*","40&"]
local $_bottomtime80[18] = [4,8,10,11,13,14,15,17,18,19,21,22,23,25,"26*","28*","29*","30&"]
local $_bottomtime90[17] = [4,7,9,10,11,12,13,15,16,17,18,19,21,"22*","23*","24*","25&"]
local $_bottomtime100[15] = ["3*","6*","8*","9*","10*","11*","12*","13*","14*","15*","16*","17*","18*","19*","20&"]
local $_bottomtime110[13] = ["3*","6*","7*","8*","9*","10*","11*","12*","13*",-9999,"14*","15*","16&"]
local $_bottomtime120[11] = ["3*","5*","6*","7*","8*","9*","10*","11*",-9999,"12*","13&"]
local $_bottomtime130[8] = ["3*","5*","6*","7*",-9999,"8*","9*","10&"]
local $_bottomtime140[6] = [-9999,"4*","5*","6*","7*","8&"]
$_depth = $_depth*1
Select
  Case $_depth = 35
   Return $_bottomtime35
  Case $_depth = 40
   Return $_bottomtime40
  Case $_depth = 50
   Return $_bottomtime50
  Case $_depth = 60
   Return $_bottomtime60
  Case $_depth = 70
   Return $_bottomtime70
  Case $_depth = 80
   Return $_bottomtime80
  Case $_depth = 90
   Return $_bottomtime90
  Case $_depth = 100
   Return $_bottomtime100
  Case $_depth = 110
   Return $_bottomtime110
  Case $_depth = 120
   Return $_bottomtime120
  Case $_depth = 130
   Return $_bottomtime130
  Case $_depth = 140
   Return $_bottomtime140
EndSelect

EndFunc
Func _GetPressureArrayToUse($_startingpressuregroup)
local $_surfaceintervalA[1]  = ["3:00"]
local $_surfaceintervalB[2]  = ["0:47","3:48"]
local $_surfaceintervalC[3]  = ["0:21","1:09","4:10"]
local $_surfaceintervalD[4]  = ["0:08","0:30","1:18","4:19"]
local $_surfaceintervalE[5]  = ["0:07","0:16","0:38","1:27","4:28"]
local $_surfaceintervalF[6]  = ["0:07","0:15","0:24","0:46","1:34","4:35"]
local $_surfaceintervalG[7]  = ["0:06","0:13","0:22","0:31","0:53","1:41","4:42"]
local $_surfaceintervalH[8]  = ["0:05","0:12","0:20","0:28","0:37","0:59","1:47","4:48"]
local $_surfaceintervalI[9]  = ["0:05","0:11","0:18","0:26","0:34","0:43","1:05","1:53","4:54"]
local $_surfaceintervalJ[10] = ["0:05","0:11","0:17","0:24","0:31","0:40","0:49","1:11","1:59","5:00"]
local $_surfaceintervalK[11] = ["0:04","0:10","0:16","0:22","0:29","0:37","0:45","0:54","1:16","2:04","5:05"]
local $_surfaceintervalL[12] = ["0:04","0:09","0:15","0:21","0:27","0:34","0:42","0:50","0:59","1:21","2:09","5:10"]
local $_surfaceintervalM[13] = ["0:04","0:09","0:14","0:19","0:25","0:32","0:39","0:46","0:55","1:04","1:25","2:14","5:15"]
local $_surfaceintervalN[14] = ["0:03","0:08","0:13","0:18","0:24","0:30","0:36","0:43","0:51","0:59","1:08","1:30","2:18","5:19"]
local $_surfaceintervalO[15] = ["0:03","0:08","0:12","0:17","0:23","0:28","0:34","0:41","0:47","0:55","1:03","1:12","1:34","2:23","5:24"]
local $_surfaceintervalP[16] = ["0:03","0:07","0:12","0:16","0:21","0:27","0:32","0:38","0:45","0:51","0:59","1:07","1:16","1:38","2:27","5:28"]
local $_surfaceintervalQ[17] = ["0:03","0:07","0:11","0:16","0:20","0:25","0:30","0:36","0:42","0:48","0:55","1:03","1:11","1:20","1:42","2:30","5:31"]
local $_surfaceintervalR[18] = ["0:03","0:07","0:11","0:15","0:19","0:24","0:29","0:34","0:40","0:46","0:52","0:59","1:07","1:15","1:24","1:46","2:34","5:35"]
local $_surfaceintervalS[19] = ["0:03","0:06","0:10","0:14","0:18","0:23","0:27","0:32","0:38","0:43","0:49","0:56","1:03","1:10","1:18","1:27","1:49","2:38","5:39"]
local $_surfaceintervalT[20] = ["0:02","0:06","0:10","0:13","0:17","0:22","0:26","0:31","0:36","0:41","0:47","0:53","0:59","1:06","1:13","1:22","1:31","1:53","2:41","5:42"]
local $_surfaceintervalU[21] = ["0:02","0:06","0:09","0:13","0:17","0:21","0:25","0:29","0:34","0:39","0:44","0:50","0:56","1:02","1:09","1:17","1:25","1:34","1:56","2:44","5:45"]
local $_surfaceintervalV[22] = ["0:02","0:05","0:09","0:12","0:16","0:20","0:24","0:28","0:33","0:37","0:42","0:47","0:53","0:59","1:05","1:12","1:20","1:38","1:37","1:59","2:47","5:48"]
local $_surfaceintervalW[23] = ["0:02","0:05","0:08","0:12","0:15","0:19","0:23","0:27","0:31","0:36","0:40","0:45","0:50","0:56","1:02","1:08","1:15","1:23","1:31","1:40","2:02","2:50","5:51"]
local $_surfaceintervalX[24] = ["0:02","0:05","0:08","0:11","0:15","0:18","0:22","0:26","0:30","0:34","0:39","0:43","0:48","0:53","0:59","1:05","1:11","1:18","1:26","1:34","1:43","2:05","2:53","5:54"]
local $_surfaceintervalY[25] = ["0:02","0:05","0:08","0:11","0:14","0:18","0:21","0:25","0:29","0:33","0:37","0:41","0:46","0:51","0:56","1:02","1:08","1:14","1:21","1:29","1:37","1:46","2:08","2:56","5:57"]
local $_surfaceintervalZ[26] = ["0:02","0:05","0:8","0:11","0:14","0:17","0:20","0:24","0:28","0:31","0:35","0:40","0:44","0:49","0:54","0:59","1:05","1:11","1:17","1:24","1:31","1:40","1:49","2:11","2:59","6:00"]
$_startingpressuregroup = StringLeft($_startingpressuregroup,1) ; <- removes the SS and limit notes
Select
  Case $_startingpressuregroup = "A"
   Return $_surfaceintervalA
  Case $_startingpressuregroup = "B"
   Return $_surfaceintervalB
  Case $_startingpressuregroup = "C"
   Return $_surfaceintervalC
  Case $_startingpressuregroup = "D"
   Return $_surfaceintervalD
  Case $_startingpressuregroup = "E"
   Return $_surfaceintervalE
  Case $_startingpressuregroup = "F"
   Return $_surfaceintervalF
  Case $_startingpressuregroup = "G"
   Return $_surfaceintervalG
  Case $_startingpressuregroup = "H"
   Return $_surfaceintervalH
  Case $_startingpressuregroup = "I"
   Return $_surfaceintervalI
  Case $_startingpressuregroup = "J"
   Return $_surfaceintervalJ
  Case $_startingpressuregroup = "K"
   Return $_surfaceintervalK
  Case $_startingpressuregroup = "L"
   Return $_surfaceintervalL
  Case $_startingpressuregroup = "M"
   Return $_surfaceintervalM
  Case $_startingpressuregroup = "N"
   Return $_surfaceintervalN
  Case $_startingpressuregroup = "O"
   Return $_surfaceintervalO
  Case $_startingpressuregroup = "P"
   Return $_surfaceintervalP
  Case $_startingpressuregroup = "Q"
   Return $_surfaceintervalQ
  Case $_startingpressuregroup = "R"
   Return $_surfaceintervalR
  Case $_startingpressuregroup = "S"
   Return $_surfaceintervalS
  Case $_startingpressuregroup = "T"
   Return $_surfaceintervalT
  Case $_startingpressuregroup = "U"
   Return $_surfaceintervalU
  Case $_startingpressuregroup = "V"
   Return $_surfaceintervalV
  Case $_startingpressuregroup = "W"
   Return $_surfaceintervalW
  Case $_startingpressuregroup = "X"
   Return $_surfaceintervalX
  Case $_startingpressuregroup = "Y"
   Return $_surfaceintervalY
  Case $_startingpressuregroup = "Z"
   Return $_surfaceintervalZ
EndSelect
EndFunc

Func _ConvertToMinutes($_value)
if StringInStr($_value,":") Then
  $_elements = StringSplit($_value, ":")
  $_totalmin = $_elements[1]*60 + $_elements[2]
  Return $_totalmin
Else
  Return $_value
EndIf
EndFunc
Link to comment
Share on other sites

Good luck on the certification!

It's not an often used function, but your code might be a good candidate for it's use...

If I'm counting right, you could replace over 80 lines with 2 like these:

Return Execute("$_bottomtime" & $_depth)
Return Execute("$_surfaceinterval" & $_startingpressuregroup)
Link to comment
Share on other sites

Good luck on the certification!

It's not an often used function, but your code might be a good candidate for it's use...

If I'm counting right, you could replace over 80 lines with 2 like these:

Return Execute("$_bottomtime" & $_depth)
Return Execute("$_surfaceinterval" & $_startingpressuregroup)

I'm certain you are right, there are a number of inefficiencies. I appreciate you looking. Even though it isn't the best code, I learned a lot with this exercise ;).
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...