File: grib_util_set_spec.sh

package info (click to toggle)
eccodes 2.45.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 154,404 kB
  • sloc: cpp: 162,953; ansic: 26,308; sh: 21,742; f90: 6,854; perl: 6,361; python: 5,172; java: 2,226; javascript: 1,427; yacc: 854; fortran: 543; lex: 359; makefile: 283; xml: 183; awk: 66
file content (169 lines) | stat: -rwxr-xr-x 5,960 bytes parent folder | download
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
#!/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

# --------------------------------------------------
# Regular Lat/Lon Grid
# --------------------------------------------------
infile=${data_dir}/latlon.grib  # edition 1
outfile=out.grib_util_set_spec.grib
tempOut=temp.grib_util_set_spec.grib
grib_util_set_spec=${test_dir}/grib_util_set_spec

rm -f $outfile

# GRIB1 with local definition for MARS. Convert to edition2 and remove local def
$EXEC $grib_util_set_spec -e 2 -r $infile $outfile > /dev/null

res=`${tools_dir}/grib_get -p edition,section2Used,Ni,Nj,numberOfValues,bitsPerValue $outfile`
[ "$res" = "2 0 17 14 238 24" ]

if [ $HAVE_GEOGRAPHY -eq 1 ]; then
  # Check output file geometry
  ${tools_dir}/grib_get_data $outfile > /dev/null
fi

# Remove the local definition from input
${tools_dir}/grib_set -s deleteLocalDefinition=1 $infile $tempOut
$EXEC $grib_util_set_spec $tempOut $outfile > /dev/null

# Add another grib1 local definition (which is not in grib2)
${tools_dir}/grib_set -s setLocalDefinition=1,localDefinitionNumber=5 $infile $tempOut
infile=$tempOut
$EXEC $grib_util_set_spec -r -e 2 $tempOut $outfile > /dev/null
res=`${tools_dir}/grib_get -p edition,section2Used $outfile`
[ "$res" = "2 0" ]

# GRIB2 input with local definition
infile=${data_dir}/regular_latlon_surface.grib2
$EXEC $grib_util_set_spec -r $infile $outfile > /dev/null
grib_check_key_equals $outfile section2Used 0
# GRIB2 input without local definition
infile=$ECCODES_SAMPLES_PATH/GRIB2.tmpl
$EXEC $grib_util_set_spec $infile $outfile > /dev/null
grib_check_key_equals $outfile section2Used 0

# Convert to edition2 and use JPEG for packing
if [ $HAVE_JPEG -eq 1 ]; then
    infile=${data_dir}/latlon.grib
    $EXEC $grib_util_set_spec -e 2 -p grid_jpeg $infile $outfile > /dev/null
    res=`${tools_dir}/grib_get -p edition,section2Used,packingType $outfile`
    [ "$res" = "2 1 grid_jpeg" ]
fi

# CCSDS for packing and different editions
if [ $HAVE_AEC -eq 1 ]; then
    infile=${data_dir}/sample.grib2
    $EXEC $grib_util_set_spec -p grid_ccsds $infile $outfile
    grib_check_key_equals $outfile packingType grid_ccsds

    infile=${data_dir}/latlon.grib #grib1
    $EXEC $grib_util_set_spec -e 2 -p grid_ccsds $infile $outfile > /dev/null
    res=`${tools_dir}/grib_get -p edition,section2Used,packingType $outfile`
    [ "$res" = "2 1 grid_ccsds" ]

    # If we don't convert, then should leave it as grid_simple (No CCSDS in grib1)
    $EXEC $grib_util_set_spec -p grid_ccsds $infile $outfile
    grib_check_key_equals $outfile packingType grid_simple
fi

if [ $ECCODES_ON_WINDOWS -eq 0 ]; then
  infile=$ECCODES_SAMPLES_PATH/GRIB1.tmpl
  $EXEC $grib_util_set_spec -p grid_ieee $infile $outfile
  grib_check_key_equals $outfile 'packingType' 'grid_ieee'
fi

infile=${data_dir}/sample.grib2
$EXEC $grib_util_set_spec -p grid_second_order $infile $outfile
grib_check_key_equals $outfile 'packingType' 'grid_second_order'

infile=${data_dir}/sample.grib2
$EXEC $grib_util_set_spec -p grid_complex $infile $outfile
# $tools_dir/grib_ls $outfile
grib_check_key_equals $outfile 'packingType' 'grid_complex'


# --------------------------------------------------
# Reduced Gaussian Grid N=32 second order packing
# --------------------------------------------------
# The gaussian tests intentionally cause an error so need to stop it failing
unset ECCODES_FAIL_IF_LOG_MESSAGE

infile=${data_dir}/reduced_gaussian_model_level.grib2
outfile=out.grib_util_set_spec.grib
rm -f $outfile

stats_old=`${tools_dir}/grib_get -F%.2f -p min,max $infile`
[ "$stats_old" = "160.25 224.45" ]

$EXEC $grib_util_set_spec -p grid_second_order $infile $outfile

grib_check_key_equals $outfile year 1936

# Check output file. Values are scaled up by 1.1
grib_check_key_equals $outfile packingType grid_second_order
stats_new=`${tools_dir}/grib_get -F%.2f -p min,max $outfile`
[ "$stats_new" = "4.84 246.90" ]

if [ $HAVE_GEOGRAPHY -eq 1 ]; then
  ${tools_dir}/grib_get_data $outfile > /dev/null
  CHECK_TOOL="${tools_dir}/grib_check_gaussian_grid"
  if [ -x $CHECK_TOOL ]; then
    $CHECK_TOOL $outfile
  fi
fi

### Constant field N=32
# ---------------------------
infile=$ECCODES_SAMPLES_PATH/reduced_gg_pl_32_grib2.tmpl
rm -f $outfile

$EXEC $grib_util_set_spec $infile $outfile
grib_check_key_equals $outfile "packingType,const" "grid_simple 0"
if [ $HAVE_GEOGRAPHY -eq 1 ]; then
  ${tools_dir}/grib_get_data $outfile > /dev/null
fi

# CCSDS input
# ---------------------------
if [ $HAVE_AEC -eq 1 ]; then
  infile=${data_dir}/ccsds.grib2
  $EXEC $grib_util_set_spec $infile $outfile
  grib_check_key_equals $outfile packingType grid_ccsds

  $EXEC $grib_util_set_spec -p grid_simple $infile $outfile
  grib_check_key_equals $outfile packingType grid_simple

  $EXEC $grib_util_set_spec -p grid_second_order $infile $outfile
  grib_check_key_equals $outfile packingType grid_second_order
fi

# Second order input/output
# ---------------------------
${tools_dir}/grib_set -r -s packingType=grid_second_order ${data_dir}/sample.grib2 $tempOut
grib_check_key_equals $tempOut packingType grid_second_order
$EXEC $grib_util_set_spec $tempOut $outfile
grib_check_key_equals $outfile packingType grid_second_order

$EXEC $grib_util_set_spec -p grid_second_order ${data_dir}/simple.grib $outfile
grib_check_key_equals $outfile packingType grid_second_order


# Check DEBUG output
# ---------------------------
export ECCODES_DEBUG=-1
$EXEC  $grib_util_set_spec ${data_dir}/sample.grib2 $outfile > $tempOut 2>&1
grep -q "ECCODES DEBUG grib_util:" $tempOut


### Clean up
rm -f $outfile $tempOut
rm -f error.data