diff --git a/src/gmt_support.c b/src/gmt_support.c index 9476630b76e..795a07691ff 100644 --- a/src/gmt_support.c +++ b/src/gmt_support.c @@ -2683,6 +2683,7 @@ GMT_LOCAL uint64_t gmtsupport_trace_contour (struct GMT_CTRL *GMT, struct GMT_GR if (n_exits == 0) { /* We have hit a field of NaNs, finish contour */ more = false; *nan_flag = n_nan; + if (n_nan == 0 && GMT->current.map.z_periodic) *nan_flag = 1; /* Dead end at a phase singularity, so also trace the other way */ continue; } else if (n_exits == 3) { /* Saddle point: Turn to the correct side */ @@ -2713,6 +2714,10 @@ GMT_LOCAL uint64_t gmtsupport_trace_contour (struct GMT_CTRL *GMT, struct GMT_GR ij0 = gmt_M_ij0 (G->header, row + d_row[side], col + d_col[side]); /* Non-padded index used for edge array */ edge_word = (unsigned int)(ij0 / 32 + d_side[side] * offset); edge_bit = (unsigned int)(ij0 % 32); + if (!test && (edge[edge_word] & bit[edge_bit])) { /* Ran into an already traced contour */ + more = false; + continue; + } edge[edge_word] |= bit[edge_bit]; if ((side == 0 && row == G->header->n_rows - 1) || (side == 2 && row == 1)) { /* Going out of grid at N or S */ diff --git a/test/baseline/grdcontour.dvc b/test/baseline/grdcontour.dvc index 7735fe26422..a749623d89f 100644 --- a/test/baseline/grdcontour.dvc +++ b/test/baseline/grdcontour.dvc @@ -1,5 +1,6 @@ outs: -- md5: aceec929e8ab2a939a5cfacf0dbf3b4c.dir +- md5: 086ead5b15b5bca2ca31537f94ccf4bf.dir nfiles: 23 path: grdcontour hash: md5 + size: 3965721 diff --git a/test/grdcontour/periodic.sh b/test/grdcontour/periodic.sh index 9f7417cb24c..af79e2e5f47 100755 --- a/test/grdcontour/periodic.sh +++ b/test/grdcontour/periodic.sh @@ -1,16 +1,10 @@ #!/usr/bin/env bash -# GMT_KNOWN_FAILURE -# Update 2020/08/11 PW: Currently, the problem with this script is this: -# When plotting with -Zp, the top plot is mostly OK but the labels for 140 and 160 -# degrees have contours cutting right through them. The bottom plot without -Zp -# plots as expected. I added the debug drawing of the helper lines in red, which -# required the C-code changes to allow a debug pen. +# Test contouring of phase data with and without -Z+p ps=periodic.ps gmt grdmath -Rg -I1 32 22 SBAZ = t.nc # Plot as non-periodic. This plots labels. The pile of blue contours around # 180 occurs because the grid goes rapidly from -180 to +180 here and -Z+p is not used # This is expected and correct. gmt grdcontour t.nc -JG0/0/5.0i -A20+u@.+d0.75p,red -Bgaf -K -Wa1,blue -Gl-90/0/0/0,0/0/90/0 -P -Xc -Y0.3i > $ps -# Plot as periodic with -Zp. Transition from -180 to +180 goes well for contouring -# but lon 140, 160 has labels overdrawn by contour. This is the main issue here. +# Plot as periodic with -Z+p. Transition from -180 to +180 goes well for contouring gmt grdcontour t.nc -J -A20+u@.+d0.75p,red -Wa1,blue -Bgaf -Gl-90/0/0/0,0/0/90/0 -Z+p -O -Y5.2i >> $ps