# Grdtrack : error in min and max values calculation?

**URL:** <https://forum.generic-mapping-tools.org/t/grdtrack-error-in-min-and-max-values-calculation/2653>\
**Category:** Q&A\
**Tags:** gmt\
**Created:** [February 22, 2022, 3:11pm UTC](https://forum.generic-mapping-tools.org/t/grdtrack-error-in-min-and-max-values-calculation/2653 "2022-02-22T15:11:56Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![louisg](https://avatars.discourse-cdn.com/v4/letter/l/b9e5f3/32.png) [@louisg](https://forum.generic-mapping-tools.org/u/louisg)\
**Post date:** [February 22, 2022, 3:11pm UTC](https://forum.generic-mapping-tools.org/t/grdtrack-error-in-min-and-max-values-calculation/2653/1 "2022-02-22T15:11:57Z")

</div>

Dear all,

I use grdtrack with gmt 6.2.0 (on Windows). I wonder if there is an error in grdtrack for min and max calulation.

I tried to plot crossed-profiles with grdtrack, as explained in the [gmt example gallery (n°33)](https://docs.generic-mapping-tools.org/dev/gallery/ex33.html).

In this example a multiple-track profile is plotted with a confidence interval in light grey :

 ![image](https://canada1.discourse-cdn.com/flex047/uploads/gmt/original/2X/f/f76a003c49f5e9d7091fa70b0fea214798ae2c8b.png)

By the way, I think there is a confusion in this example (it is not the main issue of this post, but it is an important point to explain my problem) : the grey enveloppe doesn’t show the upper/lower values encountered, but the **upper / lower bound of the 95% confidence interval**. Indeed, the code to generate this enveloppe is the following:

```
gmt convert stack.txt -o0,5 > env.txt
gmt convert stack.txt -o0,6 -I -T >> env.txt

```

Yet, according to the [grdtrack documentation (see -S argument)](https://docs.generic-mapping-tools.org/6.2/grdtrack.html?highlight=grdtrack#s), columns 5 and 6 corrspond to the lower and upper confidence bounds (and not to the upper/lower values):

> The leading column holds cross distance, while the first four columns in a group hold stacked value, deviation, min value, and max value, respectively. If _method_ is one of **a** | **m** | **p** then we also write the lower and upper confidence bounds (see **+c** )

So I tried to plot the same profile but using minimum and maximum values for the enveloppe. To do so, I used exactly the same code as in the example mentionned above, except that I used **columns 3 and 4** to generate the grey envelope. These columns correspond to the min and max values according to the grdtrack documentation (see link and citation above). So the code I used to generate the envelope is now:

```
gmt convert stack.txt -o0,3 > env.txt
gmt convert stack.txt -o0,4 -I -T >> env.txt

```

**Here appear the issue this post aims to raise:**

At each point of the graph, the minimum value plotted seems to correspond to the lower value among all the minimum values encountered since the origin of the graph (and equivalent for maximum, but with the upper value).

 ![image](https://canada1.discourse-cdn.com/flex047/uploads/gmt/original/2X/9/9b6141017a7a98cfe7b7c340d2df86811dc2ead7.png)  
_(note that to obtain this figure I also changed the min and max of the Y-axis of the example code, to better visualize.)_

Instead of this result, I would expect to obtain an enveloppe with the **local minimum and maximum** values i.e. to get the minimum/maximum value among all the values obtained at a same “distance from the ridge”.

Is it a bug or do I have missed something in the way grdtrack works ?

Thanks in advance for your help.

---

<div class="post-metadata">

**Author:** ![pwessel](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/pwessel/32/30_2.png) [@pwessel](https://forum.generic-mapping-tools.org/u/pwessel)\
**Post date:** [February 22, 2022, 8:10pm UTC](https://forum.generic-mapping-tools.org/t/grdtrack-error-in-min-and-max-values-calculation/2653/2 "2022-02-22T20:10:36Z")

</div>

Thanks for pointing out this bug so clearly. I have submitted a PR to [master](https://github.com/GenericMappingTools/gmt/pull/6369) and expect this to be approved and merged very shortly.

---

<div class="post-metadata">

**Author:** ![louisg](https://avatars.discourse-cdn.com/v4/letter/l/b9e5f3/32.png) [@louisg](https://forum.generic-mapping-tools.org/u/louisg)\
**Post date:** [February 22, 2022, 8:43pm UTC](https://forum.generic-mapping-tools.org/t/grdtrack-error-in-min-and-max-values-calculation/2653/3 "2022-02-22T20:43:27Z")

</div>

Thank you for your feedback.

---

<div class="post-metadata">

**Author:** ![pwessel](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/pwessel/32/30_2.png) [@pwessel](https://forum.generic-mapping-tools.org/u/pwessel)\
**Post date:** [February 22, 2022, 10:40pm UTC](https://forum.generic-mapping-tools.org/t/grdtrack-error-in-min-and-max-values-calculation/2653/4 "2022-02-22T22:40:46Z")

</div>

Now approved and merged into GitHub master.
