1#!/usr/bin/env bash
2# Test that the grid option in blockmean matches the table output to ~EPS
3# If max fractional difference is < 1e-7 we assume it is good and write 1
4# else it is 0.  If any of the 4 outputs fail then the test fails, and
5# the file fail will indicate which one(s) caused the problem.
6
7gmt blockmean @ship_15.txt -I1 -R-115/-105/20/30 -fg -E -o2:5 > dump.txt
8gmt blockmean @ship_15.txt -I1 -R-115/-105/20/30 -fg -E -Gfield_%s.grd -Az,s,l,h
9# Mean z:
10gmt grd2xyz field_z.grd -s -o2 > tmp
11z=$(gmt convert -A dump.txt tmp -o0,4 | awk '{print ($1-$2)/$1}' | gmt math STDIN  -T -Sf ABS UPPER 1e-7 LT =)
12# s:
13gmt grd2xyz field_s.grd -s -o2 > tmp
14s=$(gmt convert -A dump.txt tmp -o1,4 | awk '{print ($1-$2)/$1}' | gmt math STDIN  -T -Sf ABS UPPER 1e-7 LT =)
15# l:
16gmt grd2xyz field_l.grd -s -o2 > tmp
17l=$(gmt convert -A dump.txt tmp -o2,4 | awk '{print ($1-$2)/$1}' | gmt math STDIN  -T -Sf ABS UPPER 1e-7 LT =)
18# h:
19gmt grd2xyz field_h.grd -s -o2 > tmp
20h=$(gmt convert -A dump.txt tmp -o3,4 | awk '{print ($1-$2)/$1}' | gmt math STDIN  -T -Sf ABS UPPER 1e-7 LT =)
21echo $z $s $l $h
22if [ ! "$z $s $l $h" = "1 1 1 1" ] ; then
23 	echo "$z $s $l $h" > fail
24fi
25