Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

test_grid_io.sh 1.3 KB

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
  1. #!/usr/bin/env bash
  2. #
  3. # Test the C API for i/o involving complex grids. We generate
  4. # two grids (real and imag) and read them in in different ways,
  5. # do multiplexing and demultiplexing, and write them out again
  6. # Output should be identical to input. We use integer z values
  7. # so that all formats can be tested.
  8. function check_if_zero {
  9. gmt grdmath ${2}=$1 ${3}=$1 SUB = diff.nc
  10. N=($(gmt grd2xyz diff.nc -ZTLa | uniq | wc -l))
  11. if [ $N -ne 1 ]; then
  12. echo "check_if_zero: $1 : $2 $3 not equal" >> fail
  13. fi
  14. }
  15. rm -f fail
  16. # Create list of all grdformat codes
  17. gmt grdconvert 2>&1 | awk '{if ($2 == "=") print $1}' | egrep -v 'sd|gd' > codes.lis
  18. while read code; do
  19. echo "Try grid format $code"
  20. if [ $code = "bm" ]; then # For bits we can only store 0s and 1s
  21. extra="2 MOD"
  22. else
  23. extra=""
  24. fi
  25. # Create two different grids with same region and size in this grid format
  26. gmt grdmath -R1/5/1/5 -I1 Y 1 SUB NX MUL X ADD $extra = in_real.grd=${code}
  27. gmt grdmath in_real.grd=${code} NX NY MUL ADD $extra = in_imag.grd=${code}
  28. # Run the test with this codec
  29. testgrdio =$code
  30. # Compare input and output grids
  31. check_if_zero ${code} out_real.grd in_real.grd
  32. check_if_zero ${code} out_imag.grd in_imag.grd
  33. check_if_zero ${code} out_real_after_demux.grd in_real.grd
  34. check_if_zero ${code} out_imag_after_demux.grd in_imag.grd
  35. done < codes.lis
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...