From 27f37da83be5379a2e6e82b96bec9bb213edc052 Mon Sep 17 00:00:00 2001 From: Shahram Najm Date: Tue, 19 Mar 2019 15:36:25 +0000 Subject: [PATCH] ECC-913: Tools: Add gts_count --- tests/CMakeLists.txt | 1 + tests/bufr_ecc-875.sh | 4 ++++ tests/gts_count.sh | 30 ++++++++++++++++++++++++++++++ tools/CMakeLists.txt | 5 ++++- tools/codes_count.c | 2 ++ 5 files changed, 41 insertions(+), 1 deletion(-) create mode 100755 tests/gts_count.sh diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 262140867..c788da2c5 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -102,6 +102,7 @@ list( APPEND tests_data_reqd bufr_ecc-556 gts_get gts_ls + gts_count gts_compare metar_ls metar_get diff --git a/tests/bufr_ecc-875.sh b/tests/bufr_ecc-875.sh index 1ffbd69c8..f538ddc76 100755 --- a/tests/bufr_ecc-875.sh +++ b/tests/bufr_ecc-875.sh @@ -22,6 +22,10 @@ tempBufr=temp.${label}.bufr # Case 1: # -------------------------------- input=${data_dir}/gts/EGRR20150317121020_00493212.DAT + +numBufrs=`${tools_dir}/bufr_count $input` +[ $numBufrs -eq 94 ] + ${tools_dir}/bufr_copy -g -w numberOfSubsets=9 $input $tempBufr # Remove the first line and the last three ${tools_dir}/gts_ls $tempBufr | sed 1d | sed 9,11d > $tempOut diff --git a/tests/gts_count.sh b/tests/gts_count.sh new file mode 100755 index 000000000..91494ce54 --- /dev/null +++ b/tests/gts_count.sh @@ -0,0 +1,30 @@ +#!/bin/sh +# Copyright 2005-2018 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.sh + +#Enter data dir +cd ${data_dir}/gts + +#Define a common label for all the tmp files +label="gts_count_test" + +#Create log file +fLog=${label}".log" +rm -f $fLog + +#Define tmp file +fTmp=${label}".tmp.txt" + +gts_file=EGRR20150317121020_00493212.DAT +count=`${tools_dir}/gts_count $gts_file` +[ $count -eq 300 ] + +rm -f $fLog diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index 2fac9cda9..d0deedca5 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -64,13 +64,16 @@ foreach( tool ${grib_tools_bins_EXTRA} ) LIBS grib_tools ) endforeach() -# grib_count/bufr_count tools. Same source code, different executable names +# grib_count/bufr_count etc. Same source code, different executable names ecbuild_add_executable( TARGET grib_count SOURCES codes_count.c LIBS grib_tools ) ecbuild_add_executable( TARGET bufr_count SOURCES codes_count.c LIBS grib_tools ) +ecbuild_add_executable( TARGET gts_count + SOURCES codes_count.c + LIBS grib_tools ) # grib to netcdf is optional ecbuild_add_executable( TARGET grib_to_netcdf diff --git a/tools/codes_count.c b/tools/codes_count.c index 67a61db02..a28ca6acb 100644 --- a/tools/codes_count.c +++ b/tools/codes_count.c @@ -31,6 +31,7 @@ static int count_messages(FILE* in, int message_type, unsigned long *count) /* printf("message_type=%d\n", message_type); */ if (message_type == CODES_GRIB) wmo_read=wmo_read_grib_from_file_malloc; else if (message_type == CODES_BUFR) wmo_read=wmo_read_bufr_from_file_malloc; + else if (message_type == CODES_GTS) wmo_read=wmo_read_gts_from_file_malloc; else wmo_read=wmo_read_any_from_file_malloc; if (fail_on_error) @@ -76,6 +77,7 @@ int main(int argc,char* argv[]) if (strstr(argv[0], "grib_count")) message_type = CODES_GRIB; if (strstr(argv[0], "bufr_count")) message_type = CODES_BUFR; + if (strstr(argv[0], "gts_count")) message_type = CODES_GTS; count_total=0; for (i=1;i