File: grib_complex_spatial_differencing.sh

package info (click to toggle)
eccodes 2.44.2-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 150,248 kB
  • sloc: cpp: 163,056; ansic: 26,308; sh: 21,602; f90: 6,854; perl: 6,363; python: 5,087; java: 2,226; javascript: 1,427; yacc: 854; fortran: 543; lex: 359; makefile: 285; xml: 183; awk: 66
file content (125 lines) | stat: -rwxr-xr-x 4,313 bytes parent folder | download | duplicates (2)
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#!/bin/sh
# (C) Copyright 2005- ECMWF.
#
# This software is licensed under the terms of the Apache Licence Version 2.0
# which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
# 
# In applying this licence, ECMWF does not waive the privileges and immunities granted to it by
# virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
#

. ./include.ctest.sh

label="grib_complex_spatial_differencing_test"
temp=${label}".grib.tmp"
temp1=${label}".1.tmp"
temp2=${label}".2.tmp"
tempLog=${label}.log
tempFilt=${label}.filt


# Test meta-data
res=`${tools_dir}/grib_get -p decimalScaleFactor,bitsPerValue ${data_dir}/gfs.c255.grib2`
[ "$res" = "1 20" ]


# All undefined values
cat >$tempFilt<<EOF
    set values={9999,9999,9999,9999};
    write;
EOF
infile=${data_dir}/gfs.complex.mvmu.grib2
${tools_dir}/grib_filter -o $temp $tempFilt $infile
grib_check_key_equals $temp dataRepresentationTemplateNumber 2
grib_check_key_equals $temp bitsPerValue 0
rm -f $temp


# ECC-523
# ---------
infile=${data_dir}/gfs.complex.mvmu.grib2
grib_check_key_equals $infile 'missingValueManagementUsed,bitmapPresent' '1 0'
grib_check_key_equals $infile 'numberOfMissing,numberOfMissingValues' '556901 556901'


# ECC-511
# ----------
# GRIB2 message from NCEP/GFS with grid_complex_spatial_differencing and
# missingValueManagementUsed. No bitmap but missing values embedded in data
input=${data_dir}/gfs.complex.mvmu.grib2
stats=`${tools_dir}/grib_get -F%.2f -p max,min,avg $input`
[ "$stats" = "2.81 0.00 0.30" ]

# ECC-1926
# ----------
# grid_complex_spatial_differencing with bpv=0
input=$ECCODES_SAMPLES_PATH/GRIB2.tmpl
${tools_dir}/grib_set -rs packingType=grid_complex_spatial_differencing $input $temp1
grib_check_key_equals $temp1 packingType,isConstant 'grid_complex_spatial_differencing 1'
stats1=`${tools_dir}/grib_get -M -F%.0f -n statistics $input`
stats2=`${tools_dir}/grib_get -M -F%.0f -n statistics $temp1`
[ "$stats1" = "$stats2" ]
# From constant grid_complex_spatial_differencing to grib_simple
${tools_dir}/grib_set -rs packingType=grid_simple $temp1 $temp2
grib_check_key_equals $temp2 packingType,isConstant 'grid_simple 1'
${tools_dir}/grib_compare -b totalLength,section5Length,section7Length,dataRepresentationTemplateNumber $temp2 $temp1


# ECC-2060
# ------------
# grib_complex_spatial_differencing with and without bitmap
check_complex_packing() {
  input="$1"
  alg="$2"
  order="$3"

  args="packingType=$alg"
  if [ "$order" -ne 0 ]; then
    args="$args,orderOfSpatialDifferencing=$order"
  fi
  ${tools_dir}/grib_set -s $args $input $temp1 

  grib_check_key_equals $temp1 packingType "$alg"
  stats1=`${tools_dir}/grib_get -M -F%.0f -n statistics $input`
  stats2=`${tools_dir}/grib_get -M -F%.0f -n statistics $temp1`
  [ "$stats1" = "$stats2" ]
  ${tools_dir}/grib_set -rs packingType=grid_simple $temp1 $temp2
  grib_check_key_equals $temp2 packingType "grid_simple"
  ${tools_dir}/grib_compare -R codedValues=0.00001 \
    -b binaryScaleFactor,totalLength,section5Length,section7Length,dataRepresentationTemplateNumber $temp2 $temp1
}

# no bitmap
check_complex_packing ${data_dir}/regular_latlon_surface.grib2 grid_complex_spatial_differencing 2
check_complex_packing ${data_dir}/regular_latlon_surface.grib2 grid_complex_spatial_differencing 1
check_complex_packing ${data_dir}/regular_latlon_surface.grib2 grid_complex 0

# with bitmap
check_complex_packing ${data_dir}/reduced_latlon_surface.grib2 grid_complex_spatial_differencing 2
check_complex_packing ${data_dir}/reduced_latlon_surface.grib2 grid_complex_spatial_differencing 1
check_complex_packing ${data_dir}/reduced_latlon_surface.grib2 grid_complex 0


# Error conditions
# -----------------
input=$ECCODES_SAMPLES_PATH/GRIB2.tmpl
set +e
${tools_dir}/grib_set -s orderOfSpatialDifferencing=4,packingType=grid_complex_spatial_differencing $input $temp 2>$tempLog
status=$?
set -e
[ $status -ne 0 ]
grep -q "Unsupported orderOfSpatialDifferencing" $tempLog
rm -f $tempLog

${tools_dir}/grib_set -s orderOfSpatialDifferencing=3 $data_dir/gfs.complex.mvmu.grib2 $temp
set +e
${tools_dir}/grib_get -p max $temp 2>$tempLog
status=$?
set -e
[ $status -ne 0 ]
grep -q "Unsupported orderOfSpatialDifferencing" $tempLog



# Clean up
rm -f $temp $temp1 $temp2 $tempLog $tempFilt