1#!/bin/sh
2# (C) Copyright 2005- ECMWF.
3#
4# This software is licensed under the terms of the Apache Licence Version 2.0
5# which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
6#
7# In applying this licence, ECMWF does not waive the privileges and immunities granted to it by
8# virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
9
10. ./include.sh
11
12# Define a common label for all the tmp files
13label="grib_lambert_conformal_test"
14tempFilter="temp.${label}.filt"
15tempGrib="temp.${label}.grib"
16tempOut="temp.${label}.out"
17
18input=$ECCODES_SAMPLES_PATH/GRIB2.tmpl
19
20# Create a filter
21cat > $tempFilter <<EOF
22 set gridType="lambert";
23 set numberOfDataPoints=294000;
24 set shapeOfTheEarth=6;
25 set Nx=588;
26 set Ny=500;
27 set latitudeOfFirstGridPoint=40442000;
28 set longitudeOfFirstGridPoint=353559000;
29 set LaD=60000000;
30 set LoV=2200000;
31 set Dx=2499000;
32 set Dy=2499000;
33 set Latin1=46401000;
34 set Latin2=46401000;
35 set numberOfValues=294000;
36 write;
37EOF
38
39# Use filter on input to create a new Lambert conformal GRIB
40${tools_dir}/grib_filter -o $tempGrib $tempFilter $input
41if [ ! -f "$tempGrib" ]; then
42   echo 'Failed to create output GRIB from filter' >&2
43   exit 1
44fi
45# Invoke Geoiterator on the newly created GRIB file
46${tools_dir}/grib_get_data $tempGrib > $tempOut
47
48${tools_dir}/grib_ls -l 50,0 $tempGrib
49
50# Oblate earth
51# --------------
52cat > $tempFilter <<EOF
53 set gridType="lambert";
54 set numberOfDataPoints=294000;
55 set Nx=588;
56 set Ny=500;
57 set latitudeOfFirstGridPoint=40442000;
58 set longitudeOfFirstGridPoint=353559000;
59 set LaD=60000000;
60 set LoV=2200000;
61 set Dx=2499000;
62 set Dy=2499000;
63 set Latin1=46401000;
64 set Latin2=46401000;
65 set shapeOfTheEarth=2;  # oblate earth
66 set numberOfValues=294000;
67 write;
68EOF
69
70# Use this filter and the input GRIB to create a new GRIB
71${tools_dir}/grib_filter -o $tempGrib $tempFilter $input
72if [ ! -f "$tempGrib" ]; then
73   echo 'Failed to create output GRIB from filter' >&2
74   exit 1
75fi
76grib_check_key_equals $tempGrib 'earthIsOblate,earthMinorAxisInMetres,earthMajorAxisInMetres' '1 6356775 6378160'
77
78# Invoke Geoiterator on the oblate lambert GRIB
79${tools_dir}/grib_get_data $tempGrib > $tempOut
80
81# Nearest neighbour on the oblate lambert GRIB
82${tools_dir}/grib_ls -l 40.44,353.56 $tempGrib
83
84
85# Clean up
86rm -f $tempFilter $tempGrib $tempOut
87