File: bufr_filter

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 (72 lines) | stat: -rwxr-xr-x 1,919 bytes parent folder | download | duplicates (5)
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
#!/bin/sh
set -u
script_dir=`dirname $0`
BUFRDC_TOOL=bufrdc_emoslib_bufr_filter
EMOSLIB_TOOL=emoslib_bufr_filter
ECCODES_TOOL=codes_bufr_filter
result=0 # return code from function
ERR_TOOL_NOT_FOUND=666

the_tool=$ECCODES_TOOL
is_emoslib=0

#########################################################
# Arguments:
#  arguments from the script command line
# Return Value:
#  the global variable 'result' holds the exit code
try_tool()
{
    if [ -f "${script_dir}/$the_tool" ]; then
        ${script_dir}/$the_tool "${@}"
        result=$?
    else
        if command -v $the_tool >/dev/null 2>&1; then
            $the_tool "${@}"
            result=$?
        else
            #echo "Could not find $the_tool. Return error"
            result=$ERR_TOOL_NOT_FOUND
        fi
    fi
}

#########################################################
# Deal with case where no arguments are provided e.g. usage
if [ $# -eq 0 ]; then
    # Give priority to ecCodes over emoslib
    the_tool=$ECCODES_TOOL
    try_tool "${@}"
    if [ $result -eq $ERR_TOOL_NOT_FOUND ]; then
        the_tool=$BUFRDC_TOOL
        try_tool "${@}"
    fi
    exit 0
fi

# Now process arguments. The "-i" switch is specific to emoslib
for i in "$@" ; do
   if [ "$i" = "-i" ]; then is_emoslib=1; fi
done

#########################################################
if [ $is_emoslib -eq 1 ]; then
    pkg='emoslib/bufrdc'
    the_tool=$EMOSLIB_TOOL
    try_tool "${@}"
    if [ $result -eq $ERR_TOOL_NOT_FOUND ]; then
        the_tool=$BUFRDC_TOOL
        try_tool "${@}"
    fi
else
    pkg='ecCodes'
    the_tool=$ECCODES_TOOL
    try_tool "${@}"
fi
if [ $result -eq $ERR_TOOL_NOT_FOUND ]; then
    echo "ERROR: Could not find the executable: $the_tool. Aborting!"  2>&1
    echo "       The arguments you passed in are relevant to $pkg." 2>&1
    echo "       Please make sure you have $pkg installed in your path."  2>&1
    exit 1
fi
exit $result