<div dir="ltr">Robert,<br><div class="gmail_extra"><br><div class="gmail_quote">On 18 June 2015 at 06:53, Robert C. Helling <span dir="ltr"><<a href="mailto:helling@atdotde.de" target="_blank">helling@atdotde.de</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div style="word-wrap:break-word">Hi everybody,<div><br></div><div>let me first say this: This code is quite convoluted and has some history over which I tried several times to get it right. Too bad, I failed with it so far. Since yesterday, I have already spent several hours on this and still what I have does not satisfy me (one could say: It is still buggy). In particular, I also came to the conclusion that the whole „postposed“ logic is simply wrong and I threw it out.</div><div><br></div><div>The root of the problem (as with many things with the UI of the planner) is the distinction between segments of the dive and waypoints: The dive is stored in segments, they correspond to intervals of time and we store the depth and the time at the end of the segment and the gas breathed during the segment.</div><div><br></div><div>Waypoints on the other hand are moments of time: „At this time I am at this depth“. At first sight they seem to be identical to the endpoints of segments, but they are not: I believe for example if one associated a gas to a waypoint the correct semantics would be „we switch to that gas at that point in time or we keep breathing this gas“. So while the time and depth come from the segment preceding the waypoint, the gas is that of the following segment.</div><div><br></div><div>Then comes the question „What exactly do we mean when we print a gas in a row of the dive plan?“.</div><div><br></div><div>Note that a row has a depth and a duration and a runtime. In my understanding, a row is therefore like a segment above (actually, it can be several segments as we might not explicitly show transition segments or we join several transition segments into one).</div><div><br></div><div>So, if a row corresponds to a segment at a constant depth (or at least the last part of the segment is at constant depth, the row might include the transition to that depth), then clearly, the gas should be the gas during that segment (or actually it should mean: switch to that gas once your reach that depth). I.e. The gas should be displayed if before (maybe in the transition to that depth that is included in the same row), a different gas was breathed. Actually, it should be displayed if during one of the segments composing a row a different gas was breathed than in the previous row. In particular, we have to print the gas of the current, constant depth segment. (If there are several gases at the same constant depth, every change should trigger a row to be displayed, they should not be joint into one row).</div><div><br></div><div>This is different, however, for transitions. Imagine that the plan is to transition to 9m, switch to EAN80 there and then directly proceed to 6m. In that case, I would expect the EAN80 to be printed in the row with the depth 9m, even though that row as a segment indicates the transition leading to 9m (with still the previous gas being breathed), and the EAN80 being the gas of the following segment. So here, the row (with 9m depth and EAN80 displayed) has more of the meaning of a waypoint (with the gas of the next segment and also the decision about whether at all a gas should be shown being a transition at the end rather at the beginning of the segment).</div></div></blockquote><div><br></div><div>My understanding of how it *should* work is very similar to yours, but with one slight distinction: the gas printed (or implied = same as above) in that segment is the gas to be breathed up to the printed runtime.  This was the intent of my patch last night (Australian time). E.g. copied from my previous email without transitions:</div><div><br></div><div><div><font face="monospace, monospace">depth<span class="" style="white-space:pre"> </span>dur.</font><span style="font-family:monospace,monospace;white-space:pre">    </span><span style="font-family:monospace,monospace">runtime</span><span class="" style="font-family:monospace,monospace;white-space:pre">        </span><span style="font-family:monospace,monospace">gas</span><span class="" style="font-family:monospace,monospace;white-space:pre">    </span></div><div><font face="monospace, monospace">20m<span class="" style="white-space:pre">      </span>1min<span class="" style="white-space:pre">      </span>1min<span class="" style="white-space:pre">      </span>air<span class="" style="white-space:pre">       </span></font></div><div><font face="monospace, monospace">20m<span class="" style="white-space:pre"> </span>5min<span class="" style="white-space:pre">      </span>5min<span class="" style="white-space:pre">              </span></font></div><div><font face="monospace, monospace">20m<span class="" style="white-space:pre"> </span>10min<span class="" style="white-space:pre">     </span>15min<span class="" style="white-space:pre">     </span>EAN80<span class="" style="white-space:pre">     </span></font></div><div><font face="monospace, monospace">20m<span class="" style="white-space:pre"> </span>5min<span class="" style="white-space:pre">      </span>20min<span class="" style="white-space:pre">     </span>air<span class="" style="white-space:pre">       </span></font></div><div><font face="monospace, monospace">9m<span class="" style="white-space:pre">  </span>1min<span class="" style="white-space:pre">      </span>21min<span class="" style="white-space:pre">             </span><-for the segment of 1min duration leading up to the 21min runtime, we are still breathing air</font></div><div><font face="monospace, monospace">6m<span class="" style="white-space:pre"> </span>17min<span class="" style="white-space:pre">     </span>39min<span class="" style="white-space:pre">     </span>EAN80<span class="" style="white-space:pre">     </span><-for the segment of 17min duration leading up to the 39min runtime, we have changed to EAN80</font></div><div><font face="monospace, monospace">0m<span class="" style="white-space:pre">  </span>2min<span class="" style="white-space:pre">      </span>41min<span class="" style="white-space:pre">     </span></font></div></div><div> </div><div>I don't think this is 'wrong', but as you have correctly pointed out, it doesn't explicitly state that the gas change is at 9m, and it is easy to interpret that it should be at 6m.  As there is no stop at 9m, it isn't really missing much.  However, I think a more intuitive output would be:</div><div><br></div><div><div><font face="monospace, monospace">depth<span class="" style="white-space:pre">       </span>dur.</font><span style="font-family:monospace,monospace;white-space:pre">    </span><span style="font-family:monospace,monospace">runtime</span><span class="" style="font-family:monospace,monospace;white-space:pre">        </span><span style="font-family:monospace,monospace">gas</span><span class="" style="font-family:monospace,monospace;white-space:pre">    </span></div><div><font face="monospace, monospace">20m<span class="" style="white-space:pre">      </span>1min<span class="" style="white-space:pre">      </span>1min<span class="" style="white-space:pre">      </span>air<span class="" style="white-space:pre">       </span></font></div><div><font face="monospace, monospace">20m<span class="" style="white-space:pre"> </span>5min<span class="" style="white-space:pre">      </span>5min<span class="" style="white-space:pre">              </span></font></div><div><font face="monospace, monospace">20m<span class="" style="white-space:pre"> </span>10min<span class="" style="white-space:pre">     </span>15min<span class="" style="white-space:pre">     </span>EAN80<span class="" style="white-space:pre">     </span></font></div><div><font face="monospace, monospace">20m<span class="" style="white-space:pre"> </span>5min<span class="" style="white-space:pre">      </span>20min<span class="" style="white-space:pre">     </span>air<span class="" style="white-space:pre">       </span></font></div><div><font face="monospace, monospace">9m<span class="" style="white-space:pre">  </span>1min<span class="" style="white-space:pre">      </span>21min<span class="" style="white-space:pre">             </span><-for the segment of 1min duration leading up to the 21min runtime (we ascend to 9m), we are still breathing air</font></div><div><font face="monospace, monospace">9m<span class="" style="white-space:pre">       </span>0min<span class="" style="white-space:pre">      </span>21min<span class="" style="white-space:pre">     EAN80   </span><-there is zero time at 9m, but this is where to change to EAN80</font></div><div><font face="monospace, monospace">6m<span class="" style="white-space:pre">       </span>17min<span class="" style="white-space:pre">     </span>39min<span class="" style="white-space:pre">     </span><span class="" style="white-space:pre">  </span><-keep breathing EAN80</font></div><div><font face="monospace, monospace">0m<span class="" style="white-space:pre"> </span>2min<span class="" style="white-space:pre">      </span>41min<span class="" style="white-space:pre">     </span></font></div></div><div><br></div><div>Do you think this is a clear and reasonable approach?</div><div><br></div><div>Unless I messed other things up, it should not be hard to do on top of my last patch.  I nearly made the change last night, but messed up table formatting and it was way past my bedtime.  My approach was:</div><div><br></div><div><br></div><div>In the section around line 660 after printing the gas</div><div><div><br></div><div><font face="monospace, monospace"> <span class="" style="white-space:pre">                                 </span>}</font></div><div><font face="monospace, monospace"><span class="" style="white-space:pre">                                   </span>lastprintsetpoint = dp->setpoint;</font></div><div><font face="monospace, monospace"><span class="" style="white-space:pre">                                        </span>lastprintgasmix = gasmix;</font></div><div><b><font face="monospace, monospace">+</font><span style="font-family:monospace,monospace;white-space:pre">                                       gaschange = false;</span></b></div><div><font face="monospace, monospace"> <span class="" style="white-space:pre">                           </span>} else {</font></div><div><font face="monospace, monospace"> <span class="" style="white-space:pre">                                  </span>len += snprintf(buffer + len, sizeof(buffer) - len, "<td>&nbsp;</td>");</font></div><div><font face="monospace, monospace"> <span class="" style="white-space:pre">                         </span>}</font></div></div><div><br></div><div><br></div><div>In the section currently used to print the gas switch line when using the verbatim output around line 680.  Note that this will not be run if there's a real stop so we've already printed the new gas in the table, and set gaschange = false:</div><div><br></div><div><br></div><div><div class="" style="font-family:monospace;white-space:pre;color:rgb(0,0,0)"><br></div><div class="" style="font-family:monospace;white-space:pre;color:rgb(0,0,0)"><a id="l674" href="http://git.subsurface-divelog.org/index.cgi?p=subsurface.git;a=blob;f=planner.c;h=9b2d355faac88b7aa32ddfdf6244cc7918466fed;hb=f66ea4cbb03c126fce3805d778c9f197fb6fa5e8#l674" class="" style="color:rgb(153,153,153);text-decoration:none"> 674</a>                 if (gaschange) {</div><div class="" style="font-family:monospace;white-space:pre;color:rgb(0,0,0)"><a id="l675" href="http://git.subsurface-divelog.org/index.cgi?p=subsurface.git;a=blob;f=planner.c;h=9b2d355faac88b7aa32ddfdf6244cc7918466fed;hb=f66ea4cbb03c126fce3805d778c9f197fb6fa5e8#l675" class="" style="color:rgb(153,153,153);text-decoration:none"> 675</a>                         if(dp->depth == lastdepth && !postponed) {</div><div class="" style="font-family:monospace;white-space:pre;color:rgb(0,0,0)"><a id="l676" href="http://git.subsurface-divelog.org/index.cgi?p=subsurface.git;a=blob;f=planner.c;h=9b2d355faac88b7aa32ddfdf6244cc7918466fed;hb=f66ea4cbb03c126fce3805d778c9f197fb6fa5e8#l676" class="" style="color:rgb(153,153,153);text-decoration:none"> 676</a>                                 postponed = true;</div><div class="" style="font-family:monospace;white-space:pre;color:rgb(0,0,0)"><a id="l677" href="http://git.subsurface-divelog.org/index.cgi?p=subsurface.git;a=blob;f=planner.c;h=9b2d355faac88b7aa32ddfdf6244cc7918466fed;hb=f66ea4cbb03c126fce3805d778c9f197fb6fa5e8#l677" class="" style="color:rgb(153,153,153);text-decoration:none"> 677</a>                         } else {</div><div class="" style="font-family:monospace;white-space:pre;color:rgb(0,0,0)"><a id="l678" href="http://git.subsurface-divelog.org/index.cgi?p=subsurface.git;a=blob;f=planner.c;h=9b2d355faac88b7aa32ddfdf6244cc7918466fed;hb=f66ea4cbb03c126fce3805d778c9f197fb6fa5e8#l678" class="" style="color:rgb(153,153,153);text-decoration:none"> 678</a>                         // gas switch at this waypoint</div><div class="" style="font-family:monospace;white-space:pre;color:rgb(0,0,0)"><a id="l679" href="http://git.subsurface-divelog.org/index.cgi?p=subsurface.git;a=blob;f=planner.c;h=9b2d355faac88b7aa32ddfdf6244cc7918466fed;hb=f66ea4cbb03c126fce3805d778c9f197fb6fa5e8#l679" class="" style="color:rgb(153,153,153);text-decoration:none"> 679</a>                         if (plan_verbatim) {</div><div class="" style="font-family:monospace;white-space:pre;color:rgb(0,0,0)"><a id="l680" href="http://git.subsurface-divelog.org/index.cgi?p=subsurface.git;a=blob;f=planner.c;h=9b2d355faac88b7aa32ddfdf6244cc7918466fed;hb=f66ea4cbb03c126fce3805d778c9f197fb6fa5e8#l680" class="" style="color:rgb(153,153,153);text-decoration:none"> 680</a>                                 if (lastsetpoint >= 0) {</div><div class="" style="font-family:monospace;white-space:pre;color:rgb(0,0,0)"><a id="l681" href="http://git.subsurface-divelog.org/index.cgi?p=subsurface.git;a=blob;f=planner.c;h=9b2d355faac88b7aa32ddfdf6244cc7918466fed;hb=f66ea4cbb03c126fce3805d778c9f197fb6fa5e8#l681" class="" style="color:rgb(153,153,153);text-decoration:none"> 681</a>                                         if (nextdp && nextdp->setpoint)</div><div class="" style="font-family:monospace;white-space:pre;color:rgb(0,0,0)"><a id="l682" href="http://git.subsurface-divelog.org/index.cgi?p=subsurface.git;a=blob;f=planner.c;h=9b2d355faac88b7aa32ddfdf6244cc7918466fed;hb=f66ea4cbb03c126fce3805d778c9f197fb6fa5e8#l682" class="" style="color:rgb(153,153,153);text-decoration:none"> 682</a>                                                 snprintf(temp, sizeof(temp), translate("gettextFromC", "Switch gas to %s (SP = %.1fbar)"), gasname(&newgasmix), (double) nextdp->setpoint / 1000.0);</div><div class="" style="font-family:monospace;white-space:pre;color:rgb(0,0,0)"><a id="l683" href="http://git.subsurface-divelog.org/index.cgi?p=subsurface.git;a=blob;f=planner.c;h=9b2d355faac88b7aa32ddfdf6244cc7918466fed;hb=f66ea4cbb03c126fce3805d778c9f197fb6fa5e8#l683" class="" style="color:rgb(153,153,153);text-decoration:none"> 683</a>                                         else</div><div class="" style="font-family:monospace;white-space:pre;color:rgb(0,0,0)"><a id="l684" href="http://git.subsurface-divelog.org/index.cgi?p=subsurface.git;a=blob;f=planner.c;h=9b2d355faac88b7aa32ddfdf6244cc7918466fed;hb=f66ea4cbb03c126fce3805d778c9f197fb6fa5e8#l684" class="" style="color:rgb(153,153,153);text-decoration:none"> 684</a>                                                 snprintf(temp, sizeof(temp), translate("gettextFromC", "Switch gas to %s"), gasname(&newgasmix));</div><div class="" style="font-family:monospace;white-space:pre;color:rgb(0,0,0)"><a id="l685" href="http://git.subsurface-divelog.org/index.cgi?p=subsurface.git;a=blob;f=planner.c;h=9b2d355faac88b7aa32ddfdf6244cc7918466fed;hb=f66ea4cbb03c126fce3805d778c9f197fb6fa5e8#l685" class="" style="color:rgb(153,153,153);text-decoration:none"> 685</a> </div><div class="" style="font-family:monospace;white-space:pre;color:rgb(0,0,0)"><a id="l686" href="http://git.subsurface-divelog.org/index.cgi?p=subsurface.git;a=blob;f=planner.c;h=9b2d355faac88b7aa32ddfdf6244cc7918466fed;hb=f66ea4cbb03c126fce3805d778c9f197fb6fa5e8#l686" class="" style="color:rgb(153,153,153);text-decoration:none"> 686</a>                                         len += snprintf(buffer + len, sizeof(buffer) - len, "%s<br>", temp);</div><div class="" style="font-family:monospace;white-space:pre;color:rgb(0,0,0)"><a id="l687" href="http://git.subsurface-divelog.org/index.cgi?p=subsurface.git;a=blob;f=planner.c;h=9b2d355faac88b7aa32ddfdf6244cc7918466fed;hb=f66ea4cbb03c126fce3805d778c9f197fb6fa5e8#l687" class="" style="color:rgb(153,153,153);text-decoration:none"> 687</a>                                 }</div><div class="" style="font-family:monospace;white-space:pre;color:rgb(0,0,0)"><a id="l688" href="http://git.subsurface-divelog.org/index.cgi?p=subsurface.git;a=blob;f=planner.c;h=9b2d355faac88b7aa32ddfdf6244cc7918466fed;hb=f66ea4cbb03c126fce3805d778c9f197fb6fa5e8#l688" class="" style="color:rgb(153,153,153);text-decoration:none"> 688</a>                                 gaschange = false;</div><div class="" style="font-family:monospace;white-space:pre;color:rgb(0,0,0)"><a id="l689" href="http://git.subsurface-divelog.org/index.cgi?p=subsurface.git;a=blob;f=planner.c;h=9b2d355faac88b7aa32ddfdf6244cc7918466fed;hb=f66ea4cbb03c126fce3805d778c9f197fb6fa5e8#l689" class="" style="color:rgb(153,153,153);text-decoration:none"> 689</a>                                 postponed = true;</div><div class="" style="font-family:monospace;white-space:pre;color:rgb(0,0,0)">-<a id="l690" href="http://git.subsurface-divelog.org/index.cgi?p=subsurface.git;a=blob;f=planner.c;h=9b2d355faac88b7aa32ddfdf6244cc7918466fed;hb=f66ea4cbb03c126fce3805d778c9f197fb6fa5e8#l690" class="" style="color:rgb(153,153,153);text-decoration:none"> 690</a>                         }</div></div><div class="" style="font-family:monospace;white-space:pre;color:rgb(0,0,0)">+<a id="l690" href="http://git.subsurface-divelog.org/index.cgi?p=subsurface.git;a=blob;f=planner.c;h=9b2d355faac88b7aa32ddfdf6244cc7918466fed;hb=f66ea4cbb03c126fce3805d778c9f197fb6fa5e8#l690" class="" style="color:rgb(153,153,153);text-decoration:none"> 690</a>                         } else {<br></div><div class="" style="font-family:monospace;white-space:pre;color:rgb(0,0,0)">                                     Insert code to print a new line to the table for the gas switch: 0 min duration, and at the same depth and runtime as the last line<br></div><div class="" style="font-family:monospace;white-space:pre;color:rgb(0,0,0)">+                                    gaschange = false;</div><div class="" style="font-family:monospace;white-space:pre;color:rgb(0,0,0)">+                             }</div><div><br></div><div>Sorry for the ugly pseudo-patch formatted email.  I'm at work at the moment.</div><div><br></div><div>The distinction between segments and waypoints is very important, but as your (I assume it is yours) code for the verbatim output demonstrates, cycling through waypoints isn't wrong.</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div style="word-wrap:break-word"><div><div><br></div><div>As I said, The above explanation is what I came up with after spending far too much time on this problem and I am still in the process of implementing this properly.</div></div></div></blockquote><div><br></div><div>If you have worked out a better way then that is excellent</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div style="word-wrap:break-word"><div><div><br></div><div>Best</div><span class=""><font color="#888888"><div>Robert</div><br></font></span></div></div></blockquote></div><br></div></div>