AnalyzeO2 <- function (o2) { # This code is written for the R language. http://www.R-Project.org # # This function calculates the Working Depth (imperial or feet) for # a particular oxygen partial pressure in a scuba cylinder. # Calculations are based on the PADI/DSAT equations. # # The first section prints out the range of Working Depths for the # scuba tank along with hypoxia warnings. This includes the Maximum # Working Depth and the Contingent Working Depth. # # The second section prints out in table format, the conversion from # actual depth to Equvalent Air Depth (EAD) and the associated PO2 for # use with the Recreational Dive Planner. # # Author: Stephen Quashnick # Date: 20060120 # Version: 20060120-02 # # USAGE: AnalyzeO2(0.21) # Enter partial pressure of O2 as a decimal i.e. 0.21 # # This section determine the Working Depth for the O2 mix. # options(digits=3) o2 <- (trunc(o2*100))/100 # Truncates extra digits for safety and leaves only two digit decimal number. maxdepth <- as.double(format(((1.4/o2)-1)*33, digits=getOption("digits"))) mindepth <- as.double(format(((0.16/o2)-1)*33, digits=getOption("digits"))) maxcontingentdepth <- as.double(format(((1.6/o2)-1)*33, digits=getOption("digits"))) mincontingentdepth <- as.double(format(((0.12/o2)-1)*33, digits=getOption("digits"))) if (mindepth > -0.001) { cat("EANx",o2*100," is hypoxic above ",mindepth,"fsw!\n", sep="") } if (mincontingentdepth > -0.001) { cat("EANx",o2*100," above ",mincontingentdepth,"fsw may result in unconciousness!\n", sep="") } if (mindepth < 0.001) { mindepth <- c(0) } if (mincontingentdepth < 0.001) { mincontingentdepth <- c(0) } cat("\nThe Working Depth range for EANx",o2*100," is ",mindepth," to ",maxdepth," fsw.\n", sep="") cat("The Contigent Working Depth range for EANx",o2*100," is ",mincontingentdepth," to ",maxcontingentdepth," fsw.\n\n", sep="") # # Print Depth, EAD and PO2 in Chart format # Depth <- seq(mincontingentdepth, maxcontingentdepth, by=10) PO2 <- (trunc(as.double(format(c(((Depth+33)/33)*o2), digits=getOption("digits")))*100))/100 EAD <- trunc(as.double(format(c((((1-o2)/0.79)*(Depth+33))-33), digits=getOption("digits")))) Line <- c(2:length(Depth)) cat(" \tEAD @\n", sep="") cat("Depth\tEANx",o2*100,"\tPO2\n", sep="") cat("(fsw)\t(fsw)\t(ata)\n", sep="") for (i in Line) { if (EAD[i] < 0 ) { EAD[i] <- c(0) } cat(Depth[i],"\t",EAD[i],"\t",PO2[i],"\n", sep="") } }