eccodes/tests/codes_split_file.sh

86 lines
2.0 KiB
Bash
Raw Permalink Normal View History

2017-10-27 13:31:33 +00:00
#!/bin/sh
2020-01-28 14:32:34 +00:00
# (C) Copyright 2005- ECMWF.
2017-10-27 13:31:33 +00:00
#
# 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
2018-03-13 18:19:20 +00:00
pwd
2020-07-04 14:30:10 +00:00
# Define a common label for all the tmp files
2022-07-22 16:57:02 +00:00
label="codes_split_file_test"
2018-03-13 18:19:20 +00:00
temp=$label.temp.grib
2017-10-27 13:31:33 +00:00
# Do all the work in a temporary directory
temp_dir=tempdir.${label}
2023-08-22 16:40:33 +00:00
rm -rf $temp_dir
2017-10-27 13:31:33 +00:00
mkdir -p $temp_dir
2018-03-13 18:19:20 +00:00
cd $temp_dir
2017-10-27 13:31:33 +00:00
# Test 1: File with 3 messages
# -----------------------------
2018-03-13 18:19:20 +00:00
cp ${data_dir}/mixed.grib ./
input=mixed.grib
2023-08-26 18:33:15 +00:00
${tools_dir}/codes_split_file -v 3 $input
2017-10-27 13:31:33 +00:00
# There should now be 3 new files. Make sure they are valid
${tools_dir}/grib_ls mixed.grib_001
${tools_dir}/grib_ls mixed.grib_002
${tools_dir}/grib_ls mixed.grib_003
2017-10-27 13:31:33 +00:00
2018-03-13 18:19:20 +00:00
total=`${tools_dir}/codes_count mixed.grib_*`
2017-10-27 13:31:33 +00:00
[ $total -eq 14 ]
2018-03-13 18:19:20 +00:00
cat mixed.grib_* > $temp
${tools_dir}/grib_compare $input $temp
2017-10-27 15:28:59 +00:00
2017-10-27 13:31:33 +00:00
# Test 2: File with 248 messages
# -----------------------------
2018-03-13 18:19:20 +00:00
cp ${data_dir}/tigge_ecmwf.grib2 ./
input=tigge_ecmwf.grib2
2017-10-27 13:31:33 +00:00
${tools_dir}/codes_split_file 10 $input
2018-03-13 18:19:20 +00:00
total=`${tools_dir}/codes_count tigge_ecmwf.grib2_[0-9]*`
2017-10-27 13:31:33 +00:00
[ $total -eq 248 ]
cat tigge_ecmwf.grib2_[0-9][0-9][0-9] > $temp
${tools_dir}/grib_compare $input $temp
# Test 3: nchunk=-1 File with 248 messages
# -----------------------------
cp ${data_dir}/tigge_ecmwf.grib2 ./
input=tigge_ecmwf.grib2
${tools_dir}/codes_split_file -1 $input
total=`${tools_dir}/codes_count tigge_ecmwf.grib2_[0-9]*`
[ $total -eq 248 ]
cat tigge_ecmwf.grib2_[0-9][0-9][0-9] > $temp
2018-03-13 18:19:20 +00:00
${tools_dir}/grib_compare $input $temp
2017-10-27 15:28:59 +00:00
2023-08-22 16:40:33 +00:00
# Failing cases
# ----------------
set +e
${tools_dir}/codes_split_file
status=$?
set -e
[ $status -eq 1 ]
2023-08-22 16:44:54 +00:00
set +e
${tools_dir}/codes_split_file 4 $data_dir
status=$?
set -e
[ $status -eq 1 ]
2023-08-26 18:33:15 +00:00
set +e
${tools_dir}/codes_split_file 0 $input
status=$?
set -e
[ $status -eq 1 ]
2017-10-27 13:31:33 +00:00
# Clean up
2018-03-13 18:19:20 +00:00
cd $test_dir
2017-10-27 13:31:33 +00:00
rm -fr $temp_dir