-
Notifications
You must be signed in to change notification settings - Fork 406
Add a -T option that can be used with -Fxm (like in gmtregress). #8861
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
+213
−10
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| #!/usr/bin/env bash | ||
| # Testing gmt trend1d -T option for equidistant output | ||
| # | ||
| # Test written by Claude | ||
|
|
||
| # Test 1: Linear fit y = 2x, evaluate at specified points | ||
| cat << EOF > input.txt | ||
| 1 2 | ||
| 2 4 | ||
| 3 6 | ||
| 4 8 | ||
| 5 10 | ||
| EOF | ||
|
|
||
| # Expected output: model evaluated at x = 0, 1, 2, 3, 4, 5, 6 | ||
| cat << EOF > expected1.txt | ||
| 0 0 | ||
| 1 2 | ||
| 2 4 | ||
| 3 6 | ||
| 4 8 | ||
| 5 10 | ||
| 6 12 | ||
| EOF | ||
|
|
||
| gmt trend1d input.txt -Fxm -Np1 -T0/6/1 > result1.txt | ||
| diff -q result1.txt expected1.txt --strip-trailing-cr || exit 1 | ||
|
|
||
| # Test 2: Linear fit with only increment (uses data range 1-5) | ||
| cat << EOF > expected2.txt | ||
| 1 2 | ||
| 2 4 | ||
| 3 6 | ||
| 4 8 | ||
| 5 10 | ||
| EOF | ||
|
|
||
| gmt trend1d input.txt -Fxm -Np1 -T1 > result2.txt | ||
| diff -q result2.txt expected2.txt --strip-trailing-cr || exit 1 | ||
|
|
||
| # Test 3: Quadratic fit y = x^2 | ||
| cat << EOF > input_quad.txt | ||
| 0 0 | ||
| 1 1 | ||
| 2 4 | ||
| 3 9 | ||
| 4 16 | ||
| EOF | ||
|
|
||
| cat << EOF > expected3.txt | ||
| 0 0 | ||
| 0.5 0.25 | ||
| 1 1 | ||
| 1.5 2.25 | ||
| 2 4 | ||
| 2.5 6.25 | ||
| 3 9 | ||
| 3.5 12.25 | ||
| 4 16 | ||
| EOF | ||
|
|
||
| gmt trend1d input_quad.txt -Fxm -Np2 -T0/4/0.5 > result3.txt | ||
| diff -q result3.txt expected3.txt --strip-trailing-cr || exit 1 | ||
|
|
||
| # Test 4: Fourier fit y = cos(pi*x/2), period = 4 | ||
| cat << EOF > input_fourier.txt | ||
| 0 1 | ||
| 1 0 | ||
| 2 -1 | ||
| 3 0 | ||
| 4 1 | ||
| EOF | ||
|
|
||
| # Expected: cos(pi*x/2) evaluated at x = 0, 0.5, 1, 1.5, 2, 2.5, 3, 3.5, 4 | ||
| # Use numerical comparison due to floating-point precision | ||
| gmt trend1d input_fourier.txt -Fxm -Nc1+o0+l4 -T0/4/0.5 > result4.txt | ||
| awk 'BEGIN {pi=3.14159265358979; tol=1e-10} | ||
| { | ||
| expected = cos(pi*$1/2) | ||
| diff = ($2 - expected) | ||
| if (diff < 0) diff = -diff | ||
| if (diff > tol) {print "FAIL: x="$1" got "$2" expected "expected; exit 1} | ||
| }' result4.txt || exit 1 | ||
|
|
||
| # Test 5: Validation - should fail with -Fy and -T | ||
| if gmt trend1d input.txt -Fxy -Np1 -T1/5/1 2>/dev/null; then | ||
| echo "FAIL: -Fy with -T should have failed" | ||
| exit 1 | ||
| fi | ||
|
|
||
| # Test 6: Validation - should fail with -Fr and -T | ||
| if gmt trend1d input.txt -Fxr -Np1 -T1/5/1 2>/dev/null; then | ||
| echo "FAIL: -Fr with -T should have failed" | ||
| exit 1 | ||
| fi | ||
|
|
||
| # Clean up | ||
| rm -f input.txt input_quad.txt input_fourier.txt expected*.txt result*.txt | ||
|
|
||
| echo "All trend1d -T tests passed" |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.