Varying Permeability Model Decompression

All code copyright 1994-2004 by Eric Maiken.
Extends the 1986 algorithm of D. Yount and D. Hofmann to multiple mixed gases.

Version (mmddyy): 012504

THIS PROGRAM IMPLEMENTS AN OBSOLETE VERSION OF A VPM-BASED DECOMPRESSION ALGORITHM. It precedes the Yount/Maiken/Baker algorithm that was published in 2000. I have edited the code so that it runs in Mathematica V5.0. Unfortunately, to do this, I have barbarically stripped out lots of comments and formatting.

The program is written in a top-down format, with all functions explicitly defined in-line as the calculations progress.

Once the dive mixes, depths, and times are set in the Define Dive  subsection, you can run the notebook either cell-by-cell, or by selecting the rightmost cell bracket and runing the whole program (shift-enter on a PC). The output is a simple table in the  Decompression Schedule  subsection at the bottom of the notebook. 

The program tracks tensions and allowed supersaturations analytically. So, for example, if you remove the ";" line terminator at the definition: ppTotalTable[t] = ppN2Table[t] + ppHeTable[t]; , you will find the analytic expressions for 16 compartments vs. time. This has been done as an example (click --hyperlink!) in the subsection Arrays of Pressure Functions to Track ppHe and ppN2 During Dive Stages 

As another example, the terminator was removed from the list that tracks PssNew at the end of each stage in the subsection Decompression Calculation .

This notebook is a "manual" implementation of the Varying Permeability Model. In other words, you must manually iterate the calculations after selecting which of the Subsubsections of the Ascent Limiting Bubble Constants  subsection applies to your dive.  For any significant decompression dive, only 1 iteration of either the permeable or impermeable subsubsections is required anyway. This corresponds to a constant bubble number calculation with N = Nsafe.

As usual, the VPM applies to a single (nonrepetitive) dive. 

Please send questions, comments, and corrections to: EricMaiken@msn.com

Preliminaries

Off[General::"spell"]
Off[General::"spell1"]

    
\(\(\(Clear[fO2Mix, fN2Mix, fO2DecoMix1, fN2DecoMix1, fO2DecoMix2, 
      fN2DecoMix2, fO2DecoMix3, fN2DecoMix3, fN2DecoMix4, fO2DecoMix4, 
      fN2DecoMix5, fO2DecoMix5, maxPPO2Mix1, maxPPO2Mix2, maxPPO2Mix3, 
      maxPPO2Mix4, maxPPO2Mix5, descentRate, ascentRate, tsurfacedive, start, 
      diveTime, diveDepth, stopIncrement]\)\(
\)\(
\)
    \) (*set\ of\ Buhlmann\ ZHL16\ N2\ half - 
        times*) \)
\(\(\(nZHL16N2 = {4. , 8. , 12.5, 18.5, 27. , 38.3, 64.3, 77. , 109. , 
          146. , 187. , 239. , 305. , 390. , 498. , 635. };\)\(
\)
    \)\)
halftN2 = nZHL16N2;   halftHe = 
      N[halftN2/(√(28/
                  4))];   

nCompartments = Length[halftN2];
pH2OCO2 = N[102/760];
  
  

  
  
pSurface = 
        1. ;
 (*[Atmospheres]*) 

startDepth = 33.  (pSurface - 1. );
fO20 = 0.21;
fN20 = 0.79;

Define Dive

All the dive parameters are defined in this subsubsection. All of the mix gas fractions, depths, ascent / descent rates are hi-lited in red to call attention to their values. 

As many as 5 deco mixes can be specified, with the order 1->5 from deepest to shallowest. If less than 5 mixes are used, then set the deepest mixes equal to the bottom gas fractions.
Note that the helium mix fraction fHe is derived from the nitrogen and oxygen fractions in this calculation: fHe =  1  - fO2  - fN2. All gas switch depths are calculated by the MODs below

To illustrate the mixes the default dive settings are for a single-level 60 min dive on Trimix 19/30 to 200 ft, with nitrox 50/50 and  oxygen deco gasses.

(*This is the decent mix*) 
fO2TravelMix = 
        0.18; (*Oxygen fraction . 
          No checking of ppO2*) 


    fN2TravelMix = 
        0.37 ; (*Nitrogen fraction*) 

 (*fHe = 1 - fO2 - fN2*)

fO2Mix = 
        0.18;  

    fN2Mix = 0.37;

\(\(\( (*This\ is\ the\ deepest\ \((1  
            st)\)\ deco\ mix*) \)\(
\)\( (*usually\ use\ the\ same\ settings\ as\ bottom\ mix*) \)\(
\)\(\(fO2DecoMix1 = 0.18;\)

    \(fN2DecoMix1 = 0.37;\)

    \(\(\(\(maxPPO2Mix1 = 
          1.6\) \);\)\( (*maxPPO2\ controls\ this\ ascent\ gas' 
        s\ Max\ Operating\ Depth\ \((MOD)\)*) \)\)\)\)\)

\(\(\(\(fO2DecoMix2 = 0.18;\)

    \(fN2DecoMix2 = 0.37;\)

    \(\(\(maxPPO2Mix2 = 
          1.6\) \);\)\)\( (*maxPPO2\ controls\ this\ ascent\ gas' 
        s\ Max\ Operating\ Depth*) \)\)\)

\(\(\(\(fO2DecoMix3 = 0.18;\)

    \(fN2DecoMix3 = 0.37;\)

    \(\(\(maxPPO2Mix3 = 
          1.6\) \);\)\)\( (*maxPPO2\ controls\ this\ ascent\ gas' 
        s\ Max\ Operating\ Depth*) \)\)\)

\(\(\(\(fO2DecoMix4 = 0.5;\)

    \(fN2DecoMix4 = 0.5;\)

    \(maxPPO2Mix4 = 1.6;\)\)\( (*maxPPO2\ controls\ this\ ascent\ gas' 
        s\ Max\ Operating\ Depth*) \)\)\)

fO2DecoMix5 = 
        1.0;  

    fN2DecoMix5 = 0.0;  

    maxPPO2Mix5 = 
        1.61;

fO2SurfaceMix = 
      0.21;   
      fN2SurfaceMix = 0.79;

(*Multilevel dive sequence of stage DTMs : DTM = {Depth, 
          Time, {Mix}}, 
      where {Mix} = {fO2, 
            fN2}.*)  (*This multilevel list of dive stage DTM arrays {DTM1, DTM2, ...., 
          DTMn} is entered in array dive*)  (*As an example, 
      a dive depth/
          time is defined for a single level*) 
 (*For a multilevel dive, 
      use DTM arrays to specify sequence*) 

diveDepth = 
        200. ; (*[feet]*) 

    diveTime = 
      120. ;  (*[min]*) 
start = {{startDepth, 
          0.0, {fO20, 
            fN20}}};

 (*list of 1 surface DTM array*) 

    dive = {{diveDepth, 
            diveTime, {fO2Mix, 
              fN2Mix}}} ; (*this array is for a single level : dive = {DTM1}*) 
descentRate = 
        100.  ; (*[feet/
          min]*) 
ascentRate = 
        33.  ; (*[feet/min] magnitude should be < or = 
        to the first stop depth*) 
stopIncrement = 
        10.  ; (*staged ascent steps in[
          feet]*) 
tsurface = 
        0.0 ; (*[min] length of time to track in Plot . 
          nb after surfacing*)

Build DTM List for Descent and Dive

\(\(\(Clear[dtm, depth, descentDepths, descentTime, descentTimes, 
      descentMix, descentList, dropDescentList, pDeepest, pressure, time, 
      mix, ptm, 
      nStages]\)\(
\)\(	\)\(
\)\( (*Build\ descent\ {depth, \ 
          time, \ {mix}}\ list*) \)\(
\)\( (*the\ descent\ partial\ pressures\ are\ calculated\ by\ stages\ rather\ than\ analytically*) \)\(
\)
    \)\)
\(descentTime\  = \ 
      Floor[dive[\([1, 1]\)]\/descentRate]; \  (*approximate\ descent\ time\ to\ first\ dive\ stage*) 


    descentDepths\  = \ 
      N[Table[descentRate\ i, {i, 
            descentTime}]];  (*list\ of\ descent\ depths\ at\ 1\ min\ intervals*) 
descentTimes\  = \ 
      N[Table[i, {i, 
            Length[descentDepths]}]];  (*list\ of\ 1\ min\ descent\ intervals*) 
descentMix\  = \ 
      Table[{fO2TravelMix, 
          fN2TravelMix}, {descentTime}];  (*list\ of\ travel\ mixes*) 
descentList\  = \ 
      Transpose[{descentDepths, descentTimes, 
          descentMix\ }];  (*list\ of\ descent\ Depth, \ Time, \ 
      and\ Mix*) \)
\(\(dropDescentList\  = \ 
        If[Last[descentDepths] === \(First[dive]\)[\([1]\)]\ , 
          Drop[descentList, \(-1\)], 
          descentList];\) (*avoid\ redundancy*) 
\)
\(dtm\  = \ Join[start, dropDescentList, dive]; \  (*list\ of\ depth, \ 
      time, \ mix\ arrays\ through\ last\ dive\ stage*) 


    depth\  = \ \(Transpose[
          dtm]\)[\([1]\)];  (*list\ of\ stage\ depths*) \)
pressure  = (Transpose[dtm][[1]]/33.   +  
            pSurface);   
\(time\  = \ \(Transpose[dtm]\)[\([2]\)]; \  (*list\ of\ stage\ run - 
        times*) 
mix\ \  = \ \(Transpose[
          dtm]\)[\([3]\)];  (*list\ of\ stage\ mixes\ {fO2, 
          fN2}*) 

 (*ptm\  = \ {{\((pAmbient - pH2OCO2)\), \ 
            time, \ {fO2, fN2}}}*) 
ptm\  = \ 
      Transpose[{\((pressure\  - \ pH2OCO2)\), time, mix}]\ ;\ 
 (*p\  == \ 
        alveolar\ pressure*) 
\)
pDeepest  =  
        N[Max[pressure]];   
\(nStages\  = \ \((Length[pressure]\  - \ 
          1)\); \  (*number\ of\ dive\ stages\ including\ descent*) 

    nDStages\  = \ \((nStages\  - 
          0)\);  (*number\ of\ descent\ stages*) 

 (*print\ dive\ profile\ to\ check\ DTM\ definition*) 


    Print["_______Dive_______"];\)
\(\(\(Print["depth, time,   fO2/fN2"];\)\(
\)
    \)\)
\(\(\(TableForm[dtm]\)\(
\)
    \)	\)
Null

Arrays of Pressure Functions to Track ppHe and ppN2 During Dive Stages

\(\(\(Clear[tf, ti, kHe, kN2, pf, po, pN2i, pN2f, \ pN20, pHe0, pHei, 
      pHef, dt, pt, outFactor, ppN2Table, 
      ppHeTable]\)\(
\)\(
\)\( (*PN2[t]\  = \ 
        Table\ of\ N2Pressure[t]\ by\ Stage*) \)\(
\)\( (*PHe[t]\  = \ 
        Table\ of\ HePressure[
            t]\ by\ Stage*) \)\(
\)\( (*Elements : \ \(\(ptm[\([stage]\)]\)[\([alveolar\ \(pressure : \ 1\); \ time : \ 2; \ mix\  = \ 3]\)]\)[\([fO2 : \ 
              1; \ \ fN2 : \ 2]\)]*) \)\(
\)\(
\)
    \) (*Track\ N2\ During\ Dive\ Stages*) \)
\(\(\(Clear[pN2, k, pf, po, ti]\)\(
\)
    \)\)
\(\(Module[{i, 
          ppN2Stage}, 
pN2[
            t] = \ {}; 
po\  = \ 
          ptm[\([1, 3, 2]\)]\ ptm[\([1, 1]\)]; 


        For[i\  = \ 1, 
          i\  <= \ nStages\ , \(i++\), 
	\((
\(AppendTo[
                  pN2[t], 
		ppN2Stage\  = \ \((pf\  - \ \((pf\  - \ 
                                po)\)\ Exp[\(-k\)\ \((t\  - \ 
                                    ti)\)])\) /. {
		pf -> 
                          ptm[\([i + 1, 3, 2]\)]*
                            ptm[\([i + 1, 1]\)], 
		k\  -> 
                          kN2, \ 
		ti\  -> \ 
                          ptm[\([i, 2]\)]
		}];\)
	\(Clear[
                  po];\)
	\(po\  = \ 
                  ppN2Stage /. 
                    t -> ptm[\([i\  + \ 1, 
                          2]\)];\)	
)\)]\ ;
];\)\)
\(\(pN2[
        t];\)
	
 (*Table\ of\ N2\ tensions\ by\ stage\ and\ by\ \(compartment : \ 
          ppN2Table[\([compartment, \ 
              stage]\)]\)*) 
\)
Clear[ppN2Table]
Module[{i}, 
        ppN2Table[t] = 
          Table[pN2[t] /. 
              kN2 -> Log[2] /halftN2[[i]], {i, 1, 
              nCompartments}]];
\(\(ppN2Table[t];\)


 (*Track\ He\ During\ Dive\ Stages*) \)
\(\(\(Clear[pHe, k, pf, po, ti]\)\(
\)
    \)\)
\(\(Module[{i, ppHeStage}, 
po\  = \ 0. ; 
pHe[t] = \ {}; 

        For[i\  = \ 1, 
          i\  <= nStages\ , \(i++\), 
	\((
\(AppendTo[
                  pHe[t], 
		ppHeStage\  = \ \((pf\  - \ \((pf\  - \ 
                                po)\)\ Exp[\(-k\)\ \((t\  - \ 
                                    ti)\)])\) /. {
		pf -> \((1\  - \ 
                                ptm[\([i + 1, 3, 2]\)]\  - \ 
                                ptm[\([i + 1, 3, 1]\)])\)*
                            ptm[\([i + 1, 1]\)], 
		k\  -> 
                          kHe, \ 
		ti\  -> \ 
                          ptm[\([i, 2]\)]
		}];\)
	\(Clear[
                  po];\)
	\(po\  = \ 
                  ppHeStage /. 
                    t -> ptm[\([i\  + \ 1, 
                          2]\)];\)
)\)]\ ;\ 
];\)\)
\(\(pHe[
        t];\)

 (*Table\ of\ He\ Pressure\ by\ Stage\ and\ by\ \(nCompartment : \ \(ppN2Table[\([compartment]\)]\)[\([stage]\)]\)*) \)
Clear[ppHeTable]

    
Module[{i}, 
        ppHeTable[t] = 
          Table[pHe[t] /. kHe -> Log[2]/halftHe[[i]], {i, 1, 
              nCompartments}]];
\(\(ppHeTable[
        t];\)

 (*Build\ list\ of\ total\ inert\ gas\ partial\ pressures\ for\ all\ stages*) \)
Clear[ppTotalTable]

    
\(\(ppTotalTable[t]\  = \ 
        ppN2Table[t]\  + \ ppHeTable[t]\ ;\)

 (*here' 
        s\ a\ clean\ list\ of\ total\ inert\ pps . \ Stages\ are\ columns; \ 
      compartments\ are\ rows*) \)
TableForm[Chop[ppTotalTable[t]]]

Ascent Limiting Bubble Constants
CHECK CELL EVALUATION PROPERTIES

1st Iteration Permeable Range (DEFAULT)
Check Cell Evaluation Setting

This Subsubsection is set as "Evaluatable" by default. If you want to calculate iterations, or do an impermeable calculation, you need to deselect this cell by the menu sequence: Cell->Cell Properties->Cell Evaluatable, and then set the corresponding cell that you want to use as "Evaluatable."

\(\(\(\ \)\( (*VPM\ constants*) \)\(
\)\(
\)\(Clear[γ, γc\ , λ, r0N2, r0He\ , rMinN2, rMinHe, tSkinN2, tSkinHe, pSSminN2, 
      pSSminHe, pSSnewN2, pSSnewHe, pSSnew, tR, IterationTag]


    \(IterationTag\  = \ "1st Iteration";\)


    units\  = \ 
      1000. /101325. ; \  (*with\ \(conversion : \ \(dyne/cm\)/
              um\) = \(1000\ Pa\  = \ 1000/101325  atm\)*) 
γ\  = \ 
      17.9; \  (*dyne/cm*) 
γc\  = \ 
      257; \  (*dyne/cm*) 
λ\  = \ 
      7180. /33. ;  (*\([fsw/\(fsw/atm\)\  = \ atm]\); \ use\ 7500\ ffw*) 

    tR\  = \ 20160. ; \  (*regeneration\ time\ [
          min]*) 


 (*calculate\ max\ allowed\ Nitrogen\ supersaturation\ gradients*) 

    r0N2ata\  = \ 
      1.0\ ;  (*r0\ at\ 1\ Ata\ range\  = \ 
        0.8 - 1.2\ μm . \ Use\ large\ r0\ for\ deco\ dives*) 

    r0N2\  = \ \((\(\(1\)\(\ \)\)\/r0N2ata\  + \((\ pSurface\  - 1.0)\)\/\(2. \ units\ \((γc\  - \ γ)\)\))\)\^\(-1\); \  (*modified\ for\ altitude*) 

    rMinN2o\  = \ \((\(\(1\)\(\ \)\)\/r0N2ata\  + \((\ \ pDeepest\  - \ pSurface)\)\/\(2. \ units\ \((γc\  - \ γ)\)\))\)\^\(-1\);

    \(rMinN2\  = \ 
        rMinN2o + \((r0N2 - rMinN2o)\)\ \((1.  - \ Exp[\(-\ t\)/tR])\) /. 
          t -> diveTime;\)

    \(pSSminN2\  = \ \(\(\ \)\(2. \ γ\ units\ \((γc\  - \ γ)\)\)\)\/\(\(γc\)\(\ \)\(rMinN2\)\(\ \)\);\)


 (*calculate\ max\ allowed\ Helium\ supersaturation\ gradients*) 

    r0Heata\  = \ 0.8; \  (*r0He\ is\ expected\ to\ be\  <= \ r0N2*) 

    r0He\  = \ \ \((\(\(1\)\(\ \)\)\/r0Heata\  + \(\(\ \)\((pSurface\  - 1.0)\)\)\/\(2. \ units\ \((γc\  - \ γ)\)\))\)\^\(-1\)\ ; \  (*modified\ for\ altitude*) 

    rMinHeo\  = \ \ \ \((\(\(1\)\(\ \)\)\/r0Heata\  + \(\(\ \)\((\ pDeepest\  - \ pSurface)\)\)\/\(2. \ units\ \((γc\  - \ γ)\)\))\)\^\(-1\);

    \(rMinHe\  = \ 
        rMinHeo + \((r0He - rMinHeo)\)\ \((1.  - \ Exp[\(-\ t\)/tR])\) /. 
          t -> diveTime;\)

    \(pSSminHe\  = \ \(\(\ \)\(2. \ γ\ units\ \((γc\  - \ γ)\)\)\)\/\(\(γc\)\(\ \)\(rMinHe\)\(\ \)\);\)

 (*calculate\ total\ supersaturation\ gradient\ allowed\ for\ sum\ of\ compartment\ tensions*) 
 (*for\ ea . \ compartment, \ 
      weight\ each\ N2\ and\ He\ gradient\ by\ a\ fraction\ corrosponding\ to\ each\ gas' s\ partial\ tension*) 

    \ \(pSSmin\  = \((\ 
            pSSminN2\ \(Transpose[
                    Evaluate[ppN2Table[t]] /. 
                      t -> Last[
                          time]\ ]\)[\([nStages]\)]\  + 
		pSSminHe\ \(Transpose[Evaluate[ppHeTable[t]] /. 
                      t -> Last[time]\ ]\)[\([nStages]\)])\)/\((\(Transpose[
                Evaluate[ppTotalTable[t]] /. 
                  t -> Last[time]\ ]\)[\([nStages]\)])\);\)


    pSSnew\  = \ 
      pSSmin; \  (*these\ are\ true\ only\ for\ first\ iteration*) 

    pSSnewHe = pSSminHe;

    \(pSSnewN2 = pSSminN2;\)\)\)\)

Iterations Permeable Range
Check Cell Evaluation Setting

This Subsubsection is NOT set as "Evaluatable" by default. If you want to calculate iterations, you need to first run the notebook through the first iteration calculation. Then, deselect the above First Iteration Permeable cell under the menu sequence: Cell->Cell Properties->Cell Evaluatable, and set the following cell as Evaluatable.

Run this cell and the cells below sequentially until tDeco converges. Note the red text below defining tDeco. This must be updated manually for each iteration.

\(\(Clear[pSSnewN2, pSSnewHe, bN2, cN2, bHe, cHe, tDeco, pSSnew, 
        IterationTag];\)
\)
\(\(IterationTag\  = \ "Iterated Calculation";\)
\)
\(tDeco\  = \(\(1\)\(.\)\); \  (*This\ must\ be\ updated\ at\ each\ step\ of\ an\ iterative\ \(calculation!\)*) 

 (*allowed\ Nitrogen\ supersaturation\ gradients*) 

    bN2\  = \ pSSminN2\  + \ 
        Table[\((\ \(λ\ γ\)\/\(γc\ \((tDeco\  + \ halftN2[\([i]\)]\/Log[2])\)\))\), {i, nCompartments}];  (*\([atm]\)*) 

    cN2\  = \ \((\(\(\ \)\(γ\)\)\/γc)\)\^2\ Table[\((\ \(λ\ \((pDeepest\  - \ pSurface)\)\)\/\((tDeco\  + \ halftN2[\([i]\)]\/Log[2])\))\), {i, nCompartments}];  (*\([atm]\)*) 


    pSSnewN2\  = 
      1. \/2. \ \((bN2\  + \ \@\(bN2\^2\  - 4. \ cN2\))\);


 (*allowed\ Helium\ supersaturation\ gradients*) \)
\(bHe\  = \ 
      pSSminHe\  + \ 
        Table[\((\ \(λ\ γ\)\/\(γc\ \((tDeco\  + \ halftHe[\([i]\)]\/Log[2])\)\))\), {i, nCompartments}];  (*\([atm]\)*) 

    cHe\  = \ \((\(\(\ \)\(γ\)\)\/γc)\)\^2\ Table[\((\ \(λ\ \((pDeepest\  - \ pSurface)\)\)\/\((tDeco\  + \ halftHe[\([i]\)]\/Log[2])\))\), {i, nCompartments}];  (*\([atm]\)*) 


    pSSnewHe\  = 
      1. \/2. \ \((bHe\  + \ \@\(bHe\^2\  - 4. \ cHe\))\);


 (*weight\ N2\ and\ He\ gradients\ according\ to\ compartment\ tensions*) \)
\(\(pSSnew\  = \ \((pSSnewN2\ \(Transpose[
                    Evaluate[ppN2Table[t]] /. 
                      t -> Last[
                          time]\ ]\)[\([nStages]\)]\  + 
		pSSnewHe\ \(Transpose[Evaluate[ppHeTable[t]] /. 
                      t -> Last[time]\ ]\)[\([nStages]\)])\)/\((\(Transpose[
                Evaluate[ppTotalTable[t]] /. 
                  t -> Last[time]\ ]\)[\([nStages]\)])\)\ ;\)\)

Impermeable Range
Check Cell Evaluation Setting

For Impermeable range diving (pAmbient ~> 8 or 9 atmospheres)

\(\(Clear[γ, γc, r0N2, r0He, tSkinN2, tSkinHe, pSSminN2, 
        pSSminHe, pSSnewN2, tensionPI, pSSnewHe, pSSnew, pImpermeable, 
        rStarN2, rStarHe, rBarN2, rBarHe, BrN2, BrHe, r0N2ata, r0Heata, 
        IterationTag];\)
\)
\(\(IterationTag\  = \ "Impermeable Calculation";\)
\)
\(units\  = \ 
      1000. /101325. ; \  (*with\ \(conversion : \ \(dyne/cm\)/
              um\) = \(1000\ Pa\  = \ 1000/101325  atm\)*) 
γ\  = \ 
      17.9; \  (*\([dyne/cm]\)*) 
γc\  = \ 
      257; \  (*\([dyne/cm]\)*) 

pImpermeable = 9.2;  (*\([atm]\)*) 

    tensionPI = 
      1. \ pSurface;


\  (*allowed\ Nitrogen\ supersaturation\ gradients*) \)
r0N2ata = 1.2;
r0N2 = 
        (1. /(((1. /r0N2ata) + ((pSurface - 1. )/(2.  units (γc - γ))))));
tSkinN2 = ((units 2.  γ)/r0N2);
\(\(rStarN2 = \(units\ 2. \ \((γc - γ)\)\)\/\(pImpermeable - pSurface + \(units\ 2. \ \((γc - γ)\)\)\/r0N2\);\)
\)
\(\(Module[{l}, 
        l = 
		Last[
            Solve[\((\(pDeepest - pImpermeable + tensionPI\)\/\(units\ 2. \ \((γc - γ)\)\) + 1. \/rStarN2)\)\ rmN2\^3 - 
                  rmN2\^2 - \(tensionPI\ rStarN2\^3\)\/\(units\ 2. \ \((γc - γ)\)\) == 0. , rmN2]
		]; 
	
	
        rMaxN2 = rmN2 /. l;];\)
\)
\(\(rBarN2 = rStarN2\^2\/rMaxN2;\)
\)
\(\(BrN2 = \(units\ 2. \ \((γc - γ)\)\)\/\(tensionPI\ \((rStarN2\/rMaxN2 + rMaxN2\/rStarN2 + 1. )\)\);\)
\)
pSSminN2 = 
        tSkinN2 (1.  - (γ/γ)c) + ((γ )/γ)c (pImpermeable - 
                tensionPI + ((pDeepest - pImpermeable)/(1.  + (rBarN2/BrN2))));
\(\(pSSnewN2 = 
        Table[pSSminN2, {nCompartments}];\)



 (*allowed\ Helium\ supersaturation\ gradients*) \)
r0Heata = 1.0;
r0He = 
        (1. /(((1. /r0Heata) + ((pSurface - 1. )/(2.  units (γc - γ))))));
tSkinHe = ((units 2.  γ)/r0He);
\(\(rStarHe = \(units\ 2. \ \((γc - γ)\)\)\/\(pImpermeable - pSurface + \(units\ 2\ \((γc - γ)\)\)\/r0He\);\)
\)
\(\(Module[{l}, 
        l = 
		Last[
            Solve[\((\(pDeepest - pImpermeable + tensionPI\)\/\(units\ 2. \ \((γc - γ)\)\) + 1. \/rStarHe)\)\ rmHe\^3 - 
                  rmHe\^2 - \(tensionPI\ rStarHe\^3\)\/\(units\ 2. \ \((γc - γ)\)\) == 0. , rmHe]]; 
	
        rMaxHe = rmHe /. l];\)
\)
rBarHe = ((rStarHe^2)/rMaxHe);
BrHe = ((units 2.  (γc - γ))/(tensionPI ((rStarHe/rMaxHe) + (rMaxHe/rStarHe) + 1. )));
\(\(pSSminHe = 
        tSkinHe\ \((1.  - γ\/γc)\) + \(\(\(γ\)\(\ \)\)\/\(\(γc\)\(\ \)\)\) \((pImpermeable - 
                tensionPI + \(pDeepest - pImpermeable\)\/\(1.  + rBarHe\/BrHe\))\);\)
\)
\(\(pSSnewHe = 
        Table[pSSminHe, {nCompartments}];\)



 (*weight\ N2\ and\ He\ gradients\ according\ to\ compartment\ tensions*) \)
\(\(pSSnew = \((pSSnewN2\ \(Transpose[
                    Evaluate[
                      ppN2Table[t] /. 
                        t -> 
                          Last[time]]]\)[[nStages]] + 
              pSSnewHe\ \(Transpose[
                    Evaluate[
                      ppHeTable[t] /. 
                        t -> 
                          Last[time]]]\)[[nStages]])\)/\(Transpose[
              Evaluate[
                ppTotalTable[t] /. 
                  t -> 
                    Last[time]]]\)[[nStages]];\)
		\)
\(	\)

Calculate Ascent to First Stop

\(\(\(
\)\(Clear[stopSelect, lFlag, seriesCeiling, dFirst, 
      ascentTimeList, ascentTime, ascentToStop, ascentDepths, ascentMix, 
      ascentList, ascentDTM, ascentPressures, PN2Ascent, PHeAscent, 
      nAscentStops
]


    stopSelect\  = \ 
      Select[
				33. \ \((\((\(Transpose[
                    Evaluate[
                      ppTotalTable[t] /. 
                        t -> Last[time]\ ]]\)[\([nStages]\)])\)\  - \ 
              pSSnew\  - \ 
              Table[pSurface, {nCompartments}])\), 
				#\  > \ 
            0. \  &];  (*list\ of\ minimum, \ 
      non\ negative\ allowed\ ascent\ depths\ for\ compartments*) 


    lFlag\  = \ Length[stopSelect];

    If[lFlag\  > \ 0, seriesCeiling\  = \ Ceiling[Max[stopSelect]], 
      seriesCeiling\  = \ 
        0.0];  (*define\ ascent\ ceiling\ for\ deco\ and\ nodeco*) 


    dFirstS\  = \ 
      stopIncrement\ Ceiling[
          seriesCeiling/
            stopIncrement]\ ;  (*Depth\ of\ first\ series\ stop\ rounded\ to\ increment*) 


 (*now, \ 
      build\ DTM\ matrix\ for\ ascent\ off\ bottom\ to\ first\ stop*) 


    ascentTime\  = \ 
      If[
		\((\(Last[dtm]\)[\([1]\)]\  - \ dFirstS)\) >= 
          ascentRate, 
		Floor[\((\(Last[dtm]\)[\([1]\)]\  - \ dFirstS)\)/
            ascentRate], 
		1. ];  (*time \((min)\)\ to\ ascend\ to\ first\ \(\(stop\)\(.\)\)*) 


    ascentTimeToStop\  = \ 
      Ceiling[\((\(Last[dtm]\)[\([1]\)]\  - \ dFirstS)\)/
          ascentRate];  (*time \((min)\)\ to\ add\ to\ bottom\ time\ at\ start\ of\ deco\ \(\(stages\)\(.\)\)*) \ 


    ascentDepths\  = \ 
      Table[\((\(Last[dtm]\)[\([1]\)]\  - \ ascentRate\ i)\), {i, 
          ascentTime}];

    \(ascentPressures\  = \ \((1. \  + \ ascentDepths/33. )\);\)

    \(ascentTimeList\  = \ 
        Table[\((\(Last[dtm]\)[\([2]\)] + \ i)\), {i, ascentTime}];\)

    ascentMix\  = \ 
      Table[{fO2Mix, 
          fN2Mix}, {ascentTime}];  (*may\ not\ be\ optimal\ \(mix\ --\) 
        assume\ no\ switch\ ' til\ stop*) 


    ascentDTM\  = \ Transpose[{ascentDepths, ascentTimeList, ascentMix\ }];

    \(ascentList\  = \ 
        Transpose[{ascentPressures, ascentTimeList, ascentMix\ }];\)

    \(nAscentStops\  = \ 
        Length[ascentList];\)


 (*now\ calculate\ in\ and\ out\ gasing\ on\ way\ up\ to\ first\ stop*) 

 (*Start\ with\ tensions\ at\ end\ of\ dive\ stages*) 

    \(pN2Ascent\  = \ 
        Evaluate[\ \(Transpose[ppN2Table[t]]\)[\([nStages]\)] /. 
            t -> \ Last[time]];\)

    \(pHeAscent\  = \ \ Evaluate[\(Transpose[ppHeTable[t]]\)[\([nStages]\)] /. 
            t -> \ Last[time]];\)


    Module[{i}, 

      For[i\  = \ 1, 
        i <= \ \((nAscentStops\ )\), \(i++\), 
\((
	 (*Outgas/ingas\ N2\ up\ to\ first\ stop*) 	
Clear[
            TemppN2Ascent, k, pf, po, 
            ti]; 
TemppN2Ascent\  = \ {}; 

Module[{m}, 	
	
            For[m\  = \ 1, 
              m <= \ nCompartments, \(m++\), 
		AppendTo[
                TemppN2Ascent, 
			\((pf\  - \ \((pf\  - \ 
                            po)\)\ Exp[\(-k\)\ \((t\  - \ 
                                ti)\)])\) /. 
			{pf\  -> \ 
                      ascentList[\([\((i\ )\), 3, 
                            2]\)]\ ascentList[\([\((i)\), 
                            1]\)], 
			po\  -> \ 
                      pN2Ascent[\([m]\)], 
			k\  -> \ 
                      Log[2]/halftN2[\([m]\)], 
			t -> \ 
                      ascentTimeList[\([i]\)]\ , 
			ti\  -> \ \(Last[
                          dtm]\)[\([2]\)]
		}]; 
	
              pN2Ascent[\([m]\)]\  = \ 
                TemppN2Ascent[\([m]\)];	
	]\ \ ; \  (*m\ loop\ over\ compartments*) 
	]; \  (*m\ module*) 

		
	 (*Outgas/
                ingas\ He\ up\ to\ first\ stop*) 	
	
          Clear[TemppHeAscent, k, pf, po, ti]; 
	
          TemppHeAscent\  = \ {}; 
	
          Module[{m}, 
	
            For[m\  = \ 1, 
              m <= \ nCompartments, \(m++\), 
		AppendTo[
                TemppHeAscent, 
			\((pf\  - \ \((pf\  - \ 
                            po)\)\ Exp[\(-k\)\ \((t\  - \ 
                                ti)\)])\) /. 
			{pf\  -> \((1\  - \ 
                            ascentList[\([\((i)\), 3, 1]\)]\  - \ 
                            ascentList[\([\((i)\), 3, 
                                2]\)])\)\ ascentList[\([\((i\ )\), 
                            1]\)], 
			po\  -> \ 
                      pHeAscent[\([m]\)], 
			k\  -> \ 
                      Log[2]/halftHe[\([m]\)], 
			t -> \ 
                      ascentTimeList[\([i]\)]\ , 
			ti\  -> \ \(Last[
                          dtm]\)[\([2]\)]
		}]; 
	
              pHeAscent[\([m]\)]\  = \ 
                TemppHeAscent[\([m]\)];		
	]\ ; \ \  (*m\ loop\ over\ compartments*) 
	]; \ \  (*m\ module*) 
)\)	
]; \ \ \  (*i\ loop\ over\ stops*) 
];  (*\ i\ module*) 			



    pN2Ascent; 	 (*ppN2\ after\ ascent\ to\ 1  st\ stop*) 

    pHeAscent; 	 (*ppHe\ after\ ascent\ to\ 1  st\ stop*) 


    ppTotalAscent\  = \ 
      pN2Ascent + 
        pHeAscent;

 (*recalculate\ ceiling\ to\ adjust\ for\ ascent\ to\ 1 
         st\ stop*) 
 (*this\ is\ not\ entirely\ self\ \(consistent\ --\) 
        but\ is\ ok\ for\ updating\ the\ tensions*) 

    \(Clear[seriesCeiling, dFirstS, lFlag, stopSelect];\)


    \(stopSelect\  = \ 
        Select[
		33. \ \((\((\(Transpose[
                      Evaluate[
                        ppTotalTable[t] /. 
                          t -> Last[time]\ ]]\)[\([nStages]\)])\)\  - \ 
                pSSnew\  - \ 
                Table[pSurface, {nCompartments}])\), 
				#\  > \ 
              0. \  &];\)



    \(lFlag\  = \ Length[stopSelect];\)

    \(If[lFlag\  > \ 0, seriesCeiling\  = \ Ceiling[Max[stopSelect]], 
        seriesCeiling\  = \ 0.0];\)


    \(\(\(dFirstS\  = \ 
        stopIncrement\ Ceiling[
            seriesCeiling/
              stopIncrement]\) \)\(;\)\(\ \)\( (*Depth\ of\ first\ series\ stop\ rounded\ to\ increment*) \)\(
\)\(
\)\)\)\)\)

Build Array of Deco stops and mixes

\(\(\(\(\(Clear[decoM, maxOD1, maxOD2, maxOD3, maxOD4, maxOD5, nStops, 
      decoDepth, decoPressure, decoMix\ , decoPM]\)\(
\)\(
\)
    \) (*list\ of\ deco\ gases*) 

    \(decoM\  = \ {
	{fO2DecoMix1, 
            fN2DecoMix1}, 
{fO2DecoMix2, 
            fN2DecoMix2}, 
{fO2DecoMix3, 
            fN2DecoMix3}, 
{fO2DecoMix4, 
            fN2DecoMix4}, 
{fO2DecoMix5, 
            fN2DecoMix5}
		};\)


 (*determine\ maximum\ operating\ depths\ of\ 5\ deco\ mixes*) 
 (*it' 
          s\ possible\ to\ force\ a\ gas\ mix\ by\ entering\ a\ \(constant : \ maxODn\)\  = \ constant*) 

    maxOD1\  = \ 
      stopIncrement\ Floor[\ 
          33. \/stopIncrement\ \((maxPPO2Mix1\/fO2DecoMix1\  - \ 
                1. )\)]; \  (*Rounds\ MOD\ down\ in\ stopIncrement*) 
		

    maxOD2\  = \ 
      stopIncrement\ Floor[\ 
          33. \/stopIncrement\ \((maxPPO2Mix2\/fO2DecoMix2\  - \ 
                1. )\)];\ 


    \(\(maxOD3\  = \ \ stopIncrement\ Floor[\ \(33. \/stopIncrement\) \((maxPPO2Mix3\/fO2DecoMix3\  - \ 1. )\)]\ ;\)\(
\)
    \)		

    \(\(maxOD4\  = \ \ stopIncrement\ Floor[\ \(33. \/stopIncrement\) \((maxPPO2Mix4\/fO2DecoMix4\  - \ 1. )\)]\ ;\)\(
\)
    \)

    maxOD5\  = \ \ stopIncrement\ Floor[\ \(33. \/stopIncrement\) \((maxPPO2Mix5\/fO2DecoMix5\  - \ 
                1. )\)]\ ;  (*Rounds\ MOD\ down*) 


 (*By\ Analogy\ to\ diveLevels, \ 
      Start\ Building\ Deco\ DTM\ array\ with\ calculation\ of\ Pressure/
          Mix\ list*) 

    nStops\  = \((\(\(\ \)\(dFirstS\)\)\/stopIncrement\  + \ 
          1)\);  (*\(+1\)\ counts\ the\ surface\ desaturation\ as\ the\ last\ deco\ \(stop\ --\) Different\ from\ VPM . bas*) 
	

    decoDepth\  = \ 
      Table[\((dFirstS\  - \ stopIncrement\ i)\), {i, 0, \((nStops\  - 1)\), 
          1}];

    decoPressure\  = \ 
      N[\((decoDepth\/33. \  + \ 
            pSurface)\)]; \  (*Hydrostatic\ pressure\ at\ deco\ stop*) 

 (*list\ of\ deco\ mixes\ determined\ by\ MODs*) 

    decoMix\  = \ 
      Join[
		Table[{fO2Mix, fN2Mix}, {i, \ 
            dFirstS, \((maxOD1\  + \ 
                stopIncrement)\), \(-stopIncrement\)}], 
		Table[{fO2DecoMix1, fN2DecoMix1}, {i, 
            Min[{dFirstS, maxOD1}], \((maxOD2\  + \ 
                stopIncrement)\), \(-stopIncrement\)}], 
		Table[{fO2DecoMix2, fN2DecoMix2}, {i, 
            Min[{dFirstS, maxOD2}], \((maxOD3\  + \ 
                stopIncrement)\), \(-stopIncrement\)}], 
		Table[{fO2DecoMix3, fN2DecoMix3}, {i, 
            Min[{dFirstS, maxOD3}], \((maxOD4\  + \ 
                stopIncrement)\), \(-stopIncrement\)}], 
		Table[{fO2DecoMix4, fN2DecoMix4}, {i, 
            Min[{dFirstS, maxOD4}], \((maxOD5\  + \ 
                stopIncrement)\), \(-stopIncrement\)}], 		
		Table[{fO2DecoMix5, fN2DecoMix5}, {i, Min[{dFirstS, maxOD5}], 
            stopIncrement, \(-stopIncrement\)}], 	
		{{fO2SurfaceMix, 
            fN2SurfaceMix}}
	];\ 


 (*\(decoPM[\([deco\ stage]\)]\)\(\ \)\([\)\([\ 1\  = \ alveolar\ pressure; \ 
          2\  = \ mix[\([1\  = \ fO2; \ 
                2\  = \ 
                  fN2]\)]\ ]\)*) 
 (*now\ we\ just\ need\ to\ solve\ for\ the\ time\ at\ each\ stop*) 

    \(\(decoPM\  = \ 
        Transpose[{\((decoPressure - \ pH2OCO2)\), 
            decoMix\ }]\)\(\ \)\); \)\( (*asymptotic\ alveolar\ pressures*) \)\(
\)\)\)

Decompression Calculation

\(\(\(\(\(Clear[pTo, pN2o, 
      pHeo]\)\(
\)\(
\)\( (*List\ of\ compartment\ ppTotals\ at\ end\ of\ sequence\ of\ dive\ stages\ and\ ascent\ up\ to\ 1  st\ stop*) \)\(
\)
    \) (*these\ are\ the\ initial\ tensions\ for\ calculating\ deco*) 

    \(pTo\  = \ \ pN2Ascent\  + \ pHeAscent;\)

    \(pN2o\  = \ pN2Ascent;\)

    \(pHeo\  = \ \ pHeAscent;\)

 (*compartments\ with\ ppTotal\  > \ 
        pStop\ need\ to\ outgas\ at\ \(\(stop\)\(.\)\)\ *) 
 (*\(the\ situation\ may\ be\ different\ for\ individual\ compartment' 
          s\ ppHe\ and\ ppN2\)\()\)*) 
 (*although\ deco\ times\ are\ set\ by\ ppTotal, \ must\ outgas\ He\ and\ N2\ separately*) 


    \(\(Clear[decoTimes, trackPssNew, tempTrackPssNew, trackPN2o, 
      tempTrackPN2o, trackPHeo\ , tempTrackPHeo]\)\(
\)
    \)

    \(decoTimes\  = \ {};\)

    \(trackPssNew\  = \ {};\)

    \(tempTrackPssNew\  = \ {};\)

    \(trackPN2o\  = \ {};\)

    \(tempTrackPN2o\  = \ {};\)

    \(trackPHeo\  = \ {};\)

    \(\(tempTrackPHeo\  = \ {};\)\(
\)
    \)

    \(Module[{i}, 
\(For[i\  = \ 1, i < \ nStops\ , \(i++\), 

	
            Clear[stopTimes, tStop]; 
	stopTimes\  = \ {}; 
	
            Module[{x, 
                n}, 
	\(For[n\  = \ 1, 
                  n\  <= \ nCompartments\ , \(n++\), 
	
	Clear[x]; 
	
                  x\  = \ 0; \ 
	
                  While[
		\((pSSnew[\([n]\)]\  - 
                          stopIncrement/
                            33. \ \  - \ \((1. \  - \ \ decoPM[\([i\ , 2, 
                                    1]\)])\)\ decoPM[\([i, 1]\)]\  + \ 
                          decoPM[\([i, 
                              1]\)])\)\  <= 
			\((\((\((pN2o[\([n]\)]\  - \ decoPM[\([i, 2, 2]\)]\ decoPM[\([i, 
                                        1]\)]\ )\)\ \ Exp[\(-kN2\)\ ts] /. {kN2 -> Log[2]\/halftN2[\([n]\)], 
                                ts -> 
                                  x})\)\ \  + \ 
		\((\((pHeo[\([n]\)]\  - \((1\  - \ decoPM[\([i, 2, 1]\)]\  - \ decoPM[\([i, 2, 2]\)])\)\ decoPM[\([i, 
                                        1]\)]\ )\)\ Exp[\(-kHe\)\ ts] /. {kHe -> Log[2]\/halftHe[\([n]\)], ts -> x})\))\), 
				\(x++\)
		]; 

	
                  AppendTo[stopTimes, x]; 
	Clear[x];
	];\)
	]; 


	
            tStop\  = \ Max[stopTimes]\ ; 
	
            AppendTo[decoTimes, tStop\ ]; 
	
	
            Clear[TemppN2o, k, pf, po, ti]; 
	
            TemppN2o\  = \ {}; 
	
Module[{m}, 
\(For[m\  = \ 1, 
                  m <= \ nCompartments, \(m++\), 
		AppendTo[
                    TemppN2o, 
			\((pf\  - \ \((pf\  - \ 
                                po)\)\ Exp[\(-k\)\ \((t\  - \ 
                                    ti)\)])\) /. 
			\ {pf\  -> \ 
                          decoPM[\([\((i\ )\), 2, 2]\)]\ decoPM[\([\((i)\), 
                                1]\)], 
			po\  -> \ 
                          pN2o[\([m]\)], 
			k\  -> \ 
                          Log[2]/halftN2[\([m]\)], 
			t -> \ 
                          decoTimes[\([i]\)], 
			ti\  -> \ 
                          0. 
}]; 
			pN2o[\([m]\)]\  = \ TemppN2o[\([m]\)];				
	]\ ;\)\ 
	]; 

	
            Clear[TemppHeo, k, pf, po, ti]; 
	
            TemppHeo\  = \ {}; 
	
Module[{m}, 
\(For[m\  = \ 1, m <= \ nCompartments, \(m++\), 
	
                  AppendTo[
                    TemppHeo, 
			\((pf\  - \ \((pf\  - \ 
                                po)\)\ Exp[\(-k\)\ \((t\  - \ 
                                    ti)\)])\) /. 
				\ {pf\  -> \((1\  - \ decoPM[\([\((i)\), 2, 2]\)]\  - \ 
                                decoPM[\([\((i)\), 2, 
                                    1]\)])\)\ decoPM[\([\((i)\), 
                                1]\)], 
				po\  -> \ 
                          pHeo[\([m]\)], 
				k\  -> \ 
                          Log[2]/halftHe[\([m]\)], 
				t -> \ 
                          decoTimes[\([i]\)]\ , 
				ti\  -> \ 
                          0. 
}]; 
			pHeo[\([m]\)]\  = \ TemppHeo[\([m]\)];		
	]\ ;\)\ 
	]; 
		
	
            Clear[pSSnew]; 	
		
	
            pSSnew\  = \((pSSnewN2\ pN2o\  + \ 
                    pSSnewHe\ pHeo)\)/\((pHeo\  + \ pN2o)\); \ 
				
	
            trackPssNew\  = \ AppendTo[tempTrackPssNew, pSSnew]; 
	
            trackPN2o\  = \ AppendTo[tempTrackPN2o, pN2o]; 
	
            trackPHeo\  = \ 
              AppendTo[tempTrackPHeo, 
                pHeo];
		
];\)\ 
];\)

\  (*a\ list\ of\ all\ the\ compartment\ pSSnew\ for\ each\ stage, \ 
      reflecting\ change\ in\ tensions\ in\ each\ of\ the\ compartments*) 

    TableForm[
      trackPssNew]\  (*\ ";"\ line\ terminator\ removed\ for\ example*) 

    \(\(Length[trackPssNew];\)\(
\)
    \)

    \(\(stopTimes\)\(	\)\);  (*list\ of\ each\ compartment' 
        s\ required\ stop\ times\ after\ last\ stop*) 
\(\(decoTimes\) \); \)\(\ \)\( (*final\ list\ of\ times\ at\ each\ stop*) \)\(
\)\)\)

Construct Output

\(\(\(\(\(Clear[totalTdeco, runTimes, tDecoPTM, decoPTM, tDecoDTM, 
      decoDTM, nDropStages, totalTascent]\)\(
\)
    \)

    \(runTimes\  = \ {};\)

    \(\(Module[{n, i}, 


        Do[
	AppendTo[
            runTimes, \((Last[ascentTimeList]\  + \ 
                Sum[decoTimes[\([n]\)], {n, i}])\)], 
{i, 
            Length[decoTimes]}]
];\)\(
\)
    \)

    totalTDeco\  = \ 
      Apply[Plus, decoTimes]; \  (*Sum\ of\ individual\ decoTimes*) 

    totalAscentTime\ \  = \ totalTDeco\  + ascentTime;


    \(\(If[Length[runTimes] > 0, 
	
        totalTascent = 
          Append[runTimes, runTimes[\([nStops\  - 1]\)]\  + \ tsurface], 
        totalTascent = 
          Append[runTimes, \ Last[ascentTimeList] + \ tsurface]
];\)\(
\)
    \)

    \(\(tDecoPTM\  = \ {\(Transpose[decoPM]\)[\([1]\)], 
          totalTascent, \(Transpose[decoPM]\)[\([2]\)]\ };\)\(
\)
    \)

    decoPTM\  = \ Transpose[tDecoPTM];  (*array\ of\ deco\ pressure, \ 
      time\ and\ mix*) 

    tDecoDTM\  = \ {\((tDecoPTM[\([1]\)]\  - 1. \  + \ pH2OCO2)\)\ 33. , 
        tDecoPTM[\([2]\)], tDecoPTM[\([3]\)]\ };
	

    decoDTM\  = \ Transpose[tDecoDTM]\ ;  (*array\ of\ deco\ pressure, \ 
      time\ and\ mix*) 

 (*avoid\ deco\ runtimes\ redundancy . \ 
          Also\ need\ to\ drop\ corresponding\ stage\ in\ trackPssNew\ and\ decoDepth\ arrays\ *) \ 

    trackPssNew\  = \ 
      If[\((N[Last[\(Transpose[ascentDTM]\)[\([2]\)]]] === 
            N[First[\(Transpose[decoDTM]\)[\([2]\)]]])\), 
        Drop[trackPssNew, 1], trackPssNew]\ ;


    \(\(decoDepth\  = \ 
        If[\((N[Last[\(Transpose[ascentDTM]\)[\([2]\)]]] === 
              N[First[\(Transpose[decoDTM]\)[\([2]\)]]])\), 
          Drop[decoDepth, 1], decoDepth]\ ;\)\(
\)
    \)

    \(\(dropDecoDTM\  = \ 

        If[\((N[Last[\(Transpose[ascentDTM]\)[\([2]\)]]] === 
              N[First[\(Transpose[decoDTM]\)[\([2]\)]]])\), Drop[decoDTM, 1], 
          decoDTM]\ ;\)\(
\)
    \)

    \(\(TotalDiveDTM\  = \ Join[dtm, ascentDTM, dropDecoDTM];\)\(
\)
    \)

    \(\(dive1DTM\  = \ 
        TotalDiveDTM\) \);  (*this\ is\ for\ tracking\ purposes\ used\ for\ repetitive\ diving*) 

\(\(nDropStages\  = \ 
        nStages\) \); \)\(\ \)\( (*drop\ the\ descent\ and\ the\ surface\ then\ pass\ #\ to\ Plot . 
          nb*) \)\(\ \)\( (*check\ for\ multilevel\ dive*) \)\)\)

Decompression Schedule

Print[IterationTag];
Print[totalTDeco, " min Total Decompression"];
Print[totalAscentTime, " min Total Ascent"];
Print["_______Dive_______"];
Print["depth, Run time, fO2/fN2"];
\(\(\(Print[TableForm[TotalDiveDTM]]\)\(
\)\(
\)
    \)\)