I wish to generate both and open closed contours. The GMT6.5 grdcontour reference and example explain how to use the ‘%c’ C language printf format specifier with the -D option to generate both contours. Accordingly, I have the following command:
I was expecting an output of two files:
hawaii_contour_3000m_15s_C.txt for the closed contour, and
hawaii_contour_3000m_15s_O.txt for the open.
What I actually got was:
hawaii_contour_3000m_15s_C.txt, and
hawaii_contour_3000m_15s_
The closed contour file was as expected, but the open contour file was incorrectly named and contained no data. Am I using the correct command or is there a bug in the code?
P.S. I use a windows PC and I know that the %c modifier has to be escaped as %%c when it is used in a batch file.
P.P.S. For the GMT developers: The final example in the grdcontour module reference is:
Firstly, I’ve just retried the example script with the remote @AK_gulf_grav.nc file and it works now. Maybe I had an internet connection problem when I tried it earlier.
Secondly, perhaps I’ve misinterpreted what open and closed contours are and what the %c modifier does. I assumed that when grdcontour (with the -D %c modifier) is finding the contour from the elevation data it created two files: a closed contour (with the first and last point duplicated) and an open contour (with no duplicates). If this is not the case, could you explain the difference between open and closed contours?
Further to my last, the reason I need an open contour is that I will be using sphdistance that uses the STRIPACK algorithm. STRIPACK fails if there are duplicate nodes (i.e. closed contours). Sphdistance has the -D option to ignore duplicate nodes, but as the reference documentation states: ‘… it is a very brute-force yet exact comparison that is very slow for large data sets’. Whilst in this (small) example -D is not limiting, I have another project that will be using a large data set. Hence my desire to obtain an open elevation contour to minimise CPU processing time.
Well, in the case of the files created by grdcontour -D it is easy. The duplicates records are the first and last of each segment. So, you have to only delete one of them.
I was afraid that might be my only way of producing the open contours. I was hoping for a more elegant solution than manually deleting the duplicate nodes.
But you could use sort and uniq to delete the duplicate nodes. sort modifies the original order of the file. I don’t know if this affects how STRIPACK works.
I’ve since learnt that I can use GRDMATH LDIST to compute the distance grid and it accepts closed contours. So I no longer need open contours and my original problem has gone away. Thanks Federico for your help.