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
11. ./include.sh
12
13REDIRECT=/dev/null
14temp=loc.padding.grib1
15
16${tools_dir}/grib_set -s setLocalDefinition=1 ${data_dir}/regular_latlon_surface.grib1 $temp
17cat  > $$_f <<EOF
18    if (GRIBEXSection1Problem ) {
19        print "localDefinitionNumber=[localDefinitionNumber] size(GRIBEX-section1)=[GRIBEXSection1Problem] section1Length=[section1Length]";
20        write "problem.grib";
21        assert(0);
22    }
23EOF
24
25# Note: we cannot use -printf "%f\n" as on some unix platforms -printf is not an option
26# for find. So instead we use sed to get to the filename without the fullpath
27localDefinitions=`find ${def_dir}/grib1/ -name 'local.98.*def' | sed -e 's:.*/::' |\
28                awk 'BEGIN {FS=".";} {print $3;}' |\
29                grep -v def |\
30                sed '/245/d' |\
31                sed '/12/d' |\
32                sed '/244/d' |\
33                sed '/192/d' |\
34                xargs`
35
36for l1 in $localDefinitions
37do
38    ${tools_dir}/grib_set -M -s localDefinitionNumber=$l1 $temp locx.grib1
39    ${tools_dir}/grib_filter -M $$_f locx.grib1
40    for l2 in $localDefinitions
41    do
42        if [ $l1 -ne $l2 ]; then
43            #echo "$l1 -> $l2"
44            ${tools_dir}/grib_set -M -s localDefinitionNumber=$l2 locx.grib1 locy.grib1
45            ${tools_dir}/grib_filter -M $$_f locy.grib1
46        fi
47    done
48done
49
50rm -f $$_f locx.grib1 locy.grib1 $temp
51