Skip to content

FIX: check whether -C and -E use different unit in grdtrack #8728

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 16, 2025

Conversation

Dengda98
Copy link
Contributor

bug description

  1. In grdtrack module, -C and -E use different default units for geographic grids (meter for -C, kilometer for -E). Users might comfused about the result if they did't explicitly set units.

  2. Also, it seems that -C and -E cannot use different units, even if I explicity set them. For example,

     $ gmt grdtrack -G@earth_relief_30m -C10d/0.1/5 -E125/33/146/46+i10k | head -n5
     > Cross profile number -L0-000 at  125.000/033.000 az=-45.1
     152.120545696   2.11440582896   -555983.596548  143.502762578   -4493.94584719
     -104.038158968  -52.8958698548  -544862.587853  143.502762578   -4172.34066777
     -15.7830363619  13.8917296377   -533750.674146  80.1535161628   25.4353068519
     104.739638124   45.5743008564   -522618.396532  37.7551090445   1373.92989473

    while the result seems fine if I set the same unit,

     $ gmt grdtrack -G@earth_relief_30m -C10d/0.1/5 -E125/33/146/46+i0.1d | head -n5
     > Cross profile number -L0-0 at  125.000/033.000 az=-45.1
     120.595820698   36.4509628442   -5.00004763636  132.358684312   36.0413484424
     120.687607339   36.3835507254   -4.90002198049  132.358684312   24.5587581626
     120.779234893   36.3160685085   -4.79999733063  132.413174504   11.9851527852
     120.870703862   36.2485164875   -4.69997368705  132.467483417   -0.153214879891

What's changed

Not perfect solution, I just add an if statement to check whether they are the different unit. After recompiling, same command above will return error,

$ gmt grdtrack -G@earth_relief_30m -C10d/0.1/5 -E125/33/146/46+i10k | head -n5
grdtrack [ERROR]: Option -C and -E shoule take the same unit, but received d (-C) and k (-E). Recommend you explicitly set the same unit for -C and -E.

@joa-quim
Copy link
Member

Ideally we should allow to give different units in -C and -E, that is, to fix the bug. But I agree that at least we must prevent the bug. The situation is even worst since using the default units in -C (meters) and not specifying them also gives a wrong result.

C:\v>grdtrack -G@earth_relief_30m -C10k/0.1/5 -E125/33/146/46+i10k | head -n5
> Cross profile number -L0-000 at  125.000/033.000 az=-45.1
124.961987936   33.0317175099   -4.99879866781  134.848764621   -76.7744074835
124.962748445   33.0310832727   -4.89882247286  134.848764621   -76.7793602104
124.963508944   33.0304490308   -4.79884628695  134.849179173   -76.7842964579
124.964269431   33.0298147843   -4.69887011009  134.849593714   -76.7892161242

C:\v>grdtrack -G@earth_relief_30m -C10000/0.1/5 -E125/33/146/46+i10k | head -n5
> Cross profile number -L0-000 at  125.000/033.000 az=-45.1
67.725100627    53.4634275505   -5008.40682804  93.24866069     229.590712253
67.7266088084   53.463376577    -5008.3065395   93.24866069     229.699727907
67.7281169861   53.4633255845   -5008.20625097  93.2498724778   229.808730684
67.7296251602   53.463274573    -5008.10596244  93.2510842626   229.917719599

Could you please also add information to this limitation to the documentation?

/* Check whether -C and -E use different unit */
if (Ctrl->C.active && Ctrl->C.unit != Ctrl->E.unit){
GMT_Report (API, GMT_MSG_ERROR,
"Option -C and -E shoule take the same unit, but received %c (-C) and %c (-E). "
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please rephrase this to:
"Sorry but a current limitation obliges that options -C and -E must have the same unit, but received %c (-C) and %c (-E). "
"You must explicitly set the same unit for -C and -E.\n", Ctrl->C.unit, Ctrl->E.unit);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for delay response. Maybe you can edit it later ?

@joa-quim joa-quim merged commit 49e57ae into GenericMappingTools:master May 16, 2025
10 of 13 checks passed
joa-quim added a commit that referenced this pull request May 16, 2025
@joa-quim
Copy link
Member

No problem. I added it directly to master.

@Dengda98 Dengda98 deleted the fix_grdtrack_-E branch May 17, 2025 02:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants