From 79314ecc0f899ffb1072e2a8033b4d0ed8e2f91d Mon Sep 17 00:00:00 2001 From: Enrico Fucile Date: Fri, 10 Apr 2015 12:14:23 +0100 Subject: [PATCH] added metar tools and tests --- definitions/CMakeLists.txt | 2 +- definitions/Makefile.am | 67 ++++++++++++++++++++++++++++ definitions/boot.def | 2 +- definitions/metar/boot.def | 4 ++ src/grib_accessor_class_dictionary.c | 8 ++-- src/grib_accessor_class_to_integer.c | 2 +- src/grib_accessor_class_to_string.c | 2 +- src/grib_query.c | 7 +-- tests/CMakeLists.txt | 2 + tests/Makefile.am | 1 + tests/metar_dump.sh | 50 +++++++++++++++++++++ tests/metar_ls.sh | 50 +++++++++++++++++++++ tools/CMakeLists.txt | 1 + tools/Makefile.am | 6 ++- 14 files changed, 190 insertions(+), 14 deletions(-) create mode 100755 tests/metar_dump.sh create mode 100755 tests/metar_ls.sh diff --git a/definitions/CMakeLists.txt b/definitions/CMakeLists.txt index 3f8e07b52..665db8f61 100644 --- a/definitions/CMakeLists.txt +++ b/definitions/CMakeLists.txt @@ -23,7 +23,7 @@ install( DIRECTORY budg bufr cdf common grib1 grib2 gts mars tide hdf5 wrap file( COPY ${definition_files} ${table_files} DESTINATION ${CMAKE_BINARY_DIR}/share/${PROJECT_NAME}/definitions ) -file( COPY budg bufr cdf common grib1 grib2 gts mars metar taf tide hdf5 wrap +file( COPY budg bufr cdf common grib1 grib2 gts mars metar tide hdf5 wrap DESTINATION ${CMAKE_BINARY_DIR}/share/${PROJECT_NAME}/definitions FILES_MATCHING PATTERN "*.def" diff --git a/definitions/Makefile.am b/definitions/Makefile.am index 5974d4a72..c3679d73c 100644 --- a/definitions/Makefile.am +++ b/definitions/Makefile.am @@ -9204,6 +9204,73 @@ dist_definitionsmars_eswi_DATA = \ mars/eswi/type.table\ mars/eswi/wave_domain.def +definitionsmetardir = @ECCODES_DEFINITION_PATH@/metar +dist_definitionsmetar_DATA = \ + metar/CCCC.txt\ + metar/boot.def\ + metar/boot.flexible.def\ + metar/cccc.def\ + metar/clouds.def\ + metar/clouds.table\ + metar/clouds_Trend1.def\ + metar/clouds_Trend2.def\ + metar/clouds_Trend3.def\ + metar/clouds_Trend4.def\ + metar/colour.def\ + metar/direction.table\ + metar/horizontalVisibility.def\ + metar/horizontalVisibility_Trend1.def\ + metar/horizontalVisibility_Trend2.def\ + metar/horizontalVisibility_Trend3.def\ + metar/horizontalVisibility_Trend4.def\ + metar/missing_field.def\ + metar/nsd_cccc.txt\ + metar/present_weather.def\ + metar/present_weather.list\ + metar/present_weather_Trend1.def\ + metar/present_weather_Trend2.def\ + metar/present_weather_Trend3.def\ + metar/present_weather_Trend4.def\ + metar/qnh.def\ + metar/recent_weather.def\ + metar/remark.def\ + metar/runwayDepthOfDeposit.table\ + metar/runwayFrictionCoefficient.table\ + metar/runwayState.def\ + metar/runwayState1.def\ + metar/runwayState2.def\ + metar/runwayState3.def\ + metar/runwayState4.def\ + metar/runwayStateDeposit.table\ + metar/runwayStateExtentOfContamination.table\ + metar/rvr1.def\ + metar/rvr2.def\ + metar/rvr3.def\ + metar/rvr4.def\ + metar/seaState.table\ + metar/sea_state.def\ + metar/temperature.def\ + metar/temperature.list\ + metar/trend1.def\ + metar/trend2.def\ + metar/trend3.def\ + metar/trend4.def\ + metar/weatherCodes-forecasters.txt\ + metar/weatherCodes-full.txt\ + metar/weatherCodes-metar-template.txt\ + metar/weatherCodes-trend-template.txt\ + metar/wind.def\ + metar/wind_Trend1.def\ + metar/wind_Trend2.def\ + metar/wind_Trend3.def\ + metar/wind_Trend4.def\ + metar/wind_shear.def\ + metar/wrong_delayed.def + +definitionsmetar_stationsdir = @ECCODES_DEFINITION_PATH@/metar/stations +dist_definitionsmetar_stations_DATA = \ + metar/stations/nsd_cccc.txt + definitionstidedir = @ECCODES_DEFINITION_PATH@/tide dist_definitionstide_DATA = \ tide/boot.def\ diff --git a/definitions/boot.def b/definitions/boot.def index 04c797b0c..b90c84b4c 100644 --- a/definitions/boot.def +++ b/definitions/boot.def @@ -99,7 +99,7 @@ if(kindOfProduct == 17632522 ){ if(kindOfProduct == `META` ){ template METAR "metar/boot.def" ; constant METARstr="METAR"; - alias ls.identifier=METARstr; + alias identifier=METARstr; } if(kindOfProduct == `TAF ` ){ diff --git a/definitions/metar/boot.def b/definitions/metar/boot.def index d27ae118c..ecae7cdbd 100644 --- a/definitions/metar/boot.def +++ b/definitions/metar/boot.def @@ -54,6 +54,7 @@ if (length(g) == 4) { } } +alias ls.CCCC=CCCC; if (substr(g,6,1) is "Z" && is_integer(g,0,6) ) { rename(g,YYGGgg); modify YYGGgg : hidden; @@ -63,8 +64,11 @@ if (substr(g,6,1) is "Z" && is_integer(g,0,6) ) { day = to_string(YYGGgg,0,2) : dump; hour = to_string(YYGGgg,2,2) : dump; minute = to_string(YYGGgg,4,2) : dump; + meta dateTime sprintf("%s-%s-%s %s:%s",year,month,day,hour,minute); + alias ls.dateTime=dateTime; } + if ( ! isCorrection && g is "COR" ) { rename(g,cor); alias status=correction; diff --git a/src/grib_accessor_class_dictionary.c b/src/grib_accessor_class_dictionary.c index 59dba8b11..e95a313b4 100644 --- a/src/grib_accessor_class_dictionary.c +++ b/src/grib_accessor_class_dictionary.c @@ -291,13 +291,13 @@ static int unpack_string (grib_accessor* a, char* buffer, size_t *len) if (err) return err; if((err=grib_get_string_internal(a->parent->h,self->key,key,&size)) != GRIB_SUCCESS) { - grib_trie_delete(dictionary); + /* grib_trie_delete(dictionary); */ return err; } list=(char*)grib_trie_get(dictionary,key); if (!list) { - grib_trie_delete(dictionary); + /* grib_trie_delete(dictionary); */ return GRIB_NOT_FOUND; } @@ -310,7 +310,7 @@ static int unpack_string (grib_accessor* a, char* buffer, size_t *len) end--; rsize=end-start; if (*len < rsize) { - grib_trie_delete(dictionary); + /* grib_trie_delete(dictionary); */ return GRIB_ARRAY_TOO_SMALL; } @@ -318,7 +318,7 @@ static int unpack_string (grib_accessor* a, char* buffer, size_t *len) memcpy(buffer,start,rsize); buffer[rsize]=0; - grib_trie_delete(dictionary); + /* grib_trie_delete(dictionary); */ return err; } diff --git a/src/grib_accessor_class_to_integer.c b/src/grib_accessor_class_to_integer.c index f76c52b59..1abbb7d8a 100644 --- a/src/grib_accessor_class_to_integer.c +++ b/src/grib_accessor_class_to_integer.c @@ -174,7 +174,7 @@ static size_t string_length(grib_accessor* a){ if (self->length) return self->length; - _grib_get_string_length(a,&size); + grib_get_string_length(a->parent->h,self->key,&size); return size; } diff --git a/src/grib_accessor_class_to_string.c b/src/grib_accessor_class_to_string.c index faa27c3f7..448706efd 100644 --- a/src/grib_accessor_class_to_string.c +++ b/src/grib_accessor_class_to_string.c @@ -174,7 +174,7 @@ static size_t string_length(grib_accessor* a){ if (self->length) return self->length; - _grib_get_string_length(a,&size); + grib_get_string_length(a->parent->h,self->key,&size); return size; } diff --git a/src/grib_query.c b/src/grib_query.c index d655ea617..15a7600d7 100644 --- a/src/grib_query.c +++ b/src/grib_query.c @@ -396,11 +396,8 @@ static grib_accessor* _grib_find_accessor(grib_handle* h, const char* name) int has_rank(const char* name) { char* p=(char*)name; - while (*p!=0) { - if (*p == '#') return 1; - p++; - } - return 0; + while (*p!=0 && *p!='#') p++; + return *p ? 1 : 0 ; } char* grib_split_name_attribute(grib_context* c,const char* name,char* attribute_name) { diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 7baf1ac87..aaf080881 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -43,6 +43,8 @@ list( APPEND tests2 bufr_json bufr_ls gts_ls + metar_ls + metar_dump bufr_set ieee grib1to2 diff --git a/tests/Makefile.am b/tests/Makefile.am index e3c6b3dba..e78f4ac02 100755 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -2,6 +2,7 @@ TESTS = definitions.sh calendar.sh \ bufrdc_desc_ref.sh bufrdc_ref.sh bufr_dump.sh bufr_filter.sh \ bufr_json.sh bufr_compare.sh bufr_copy.sh bufr_count.sh bufr_get.sh bufr_ls.sh bufr_set.sh \ gts_ls.sh \ + metar_ls.sh metar_dump.sh \ ieee.sh grib1to2.sh \ unit_tests.sh \ grib2to1.sh badgrib.sh ls.sh filter.sh \ diff --git a/tests/metar_dump.sh b/tests/metar_dump.sh new file mode 100755 index 000000000..9fa613f10 --- /dev/null +++ b/tests/metar_dump.sh @@ -0,0 +1,50 @@ +#!/bin/sh +# Copyright 2005-2015 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}/metar + +#Define a common label for all the tmp files +label="metar_dump_test" + +#Create log file +fLog=${label}".log" +rm -f $fLog +touch $fLog + +#Define tmp file +fTmp=${label}".tmp.txt" +rm -f $fTmp + +#---------------------------------------------- +# Test default "dump" on all the metar data files +#---------------------------------------------- +export METAR_YEAR=2015 +export METAR_MONTH=4 +metar_file=metar.txt +f=$metar_file + +echo $f >> $fLog +${tools_dir}/metar_dump $f >> $fLog + +#------------------------------------------- +# Test "-p" switch +#------------------------------------------- +ref_dump=$f".dump.ref" +res_dump=$f".dump.test" +REDIRECT=/dev/null + +${tools_dir}/metar_dump $f 2> $REDIRECT > $res_dump + +diff $ref_dump $res_dump >$REDIRECT 2> $REDIRECT + +rm -f $fLog $res_dump diff --git a/tests/metar_ls.sh b/tests/metar_ls.sh new file mode 100755 index 000000000..68e7e1815 --- /dev/null +++ b/tests/metar_ls.sh @@ -0,0 +1,50 @@ +#!/bin/sh +# Copyright 2005-2015 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}/metar + +#Define a common label for all the tmp files +label="metar_ls_test" + +#Create log file +fLog=${label}".log" +rm -f $fLog +touch $fLog + +#Define tmp file +fTmp=${label}".tmp.txt" +rm -f $fTmp + +#---------------------------------------------- +# Test default "ls" on all the metar data files +#---------------------------------------------- +metar_file=metar.txt +f=$metar_file +export METAR_YEAR=2015 +export METAR_MONTH=4 + +echo $f >> $fLog +${tools_dir}/metar_ls $f >> $fLog + +#------------------------------------------- +# Test "-p" switch +#------------------------------------------- +ref_ls=$f".ls.ref" +res_ls=$f".ls.test" +REDIRECT=/dev/null + +${tools_dir}/metar_ls -pCCCC,latitude,longitude,dateTime,elevation,temperature,dewPointTemperature,qnh $f 2> $REDIRECT > $res_ls + +diff $ref_ls $res_ls >$REDIRECT 2> $REDIRECT + +rm -f $fLog $res_ls diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index 38936a8dd..1a31effea 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -14,6 +14,7 @@ list( APPEND grib_tools_bins bufr_filter bufr_ls bufr_dump bufr_set bufr_get bufr_copy bufr_compare bufr_index_build gts_copy gts_dump gts_filter gts_ls + metar_dump metar_ls ) list( APPEND grib_tools_bins_ECMWF_ONLY diff --git a/tools/Makefile.am b/tools/Makefile.am index 98be29fee..1fe172a55 100644 --- a/tools/Makefile.am +++ b/tools/Makefile.am @@ -19,7 +19,8 @@ bin_PROGRAMS = grib_histogram big2gribex \ gg_sub_area_check grib_to_netcdf grib_to_json \ bufr_count bufr_filter bufr_ls bufr_dump bufr_set bufr_get \ bufr_copy bufr_compare bufr_index_build \ - gts_copy gts_dump gts_filter gts_ls + gts_copy gts_dump gts_filter gts_ls \ + metar_dump metar_ls noinst_PROGRAMS = gaussian grib_diff mars_request xref all_keys #compile #dumpload grib_compare_old @@ -73,6 +74,9 @@ gts_filter_SOURCES = gts_filter.c #gts_get_SOURCES = gts_get.c gts_ls_SOURCES = gts_ls.c +metar_dump_SOURCES = metar_dump.c +metar_ls_SOURCES = metar_ls.c + INCLUDES = -I$(top_builddir)/src LDADD = libgrib_tools.la $(top_builddir)/src/libeccodes.la