added metar tools and tests

This commit is contained in:
Enrico Fucile 2015-04-10 12:14:23 +01:00
parent 3e044256f2
commit 79314ecc0f
14 changed files with 190 additions and 14 deletions

View File

@ -23,7 +23,7 @@ install( DIRECTORY budg bufr cdf common grib1 grib2 gts mars tide hdf5 wrap
file( COPY ${definition_files} ${table_files} file( COPY ${definition_files} ${table_files}
DESTINATION ${CMAKE_BINARY_DIR}/share/${PROJECT_NAME}/definitions ) 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 DESTINATION ${CMAKE_BINARY_DIR}/share/${PROJECT_NAME}/definitions
FILES_MATCHING FILES_MATCHING
PATTERN "*.def" PATTERN "*.def"

View File

@ -9204,6 +9204,73 @@ dist_definitionsmars_eswi_DATA = \
mars/eswi/type.table\ mars/eswi/type.table\
mars/eswi/wave_domain.def 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 definitionstidedir = @ECCODES_DEFINITION_PATH@/tide
dist_definitionstide_DATA = \ dist_definitionstide_DATA = \
tide/boot.def\ tide/boot.def\

View File

@ -99,7 +99,7 @@ if(kindOfProduct == 17632522 ){
if(kindOfProduct == `META` ){ if(kindOfProduct == `META` ){
template METAR "metar/boot.def" ; template METAR "metar/boot.def" ;
constant METARstr="METAR"; constant METARstr="METAR";
alias ls.identifier=METARstr; alias identifier=METARstr;
} }
if(kindOfProduct == `TAF ` ){ if(kindOfProduct == `TAF ` ){

View File

@ -54,6 +54,7 @@ if (length(g) == 4) {
} }
} }
alias ls.CCCC=CCCC;
if (substr(g,6,1) is "Z" && is_integer(g,0,6) ) { if (substr(g,6,1) is "Z" && is_integer(g,0,6) ) {
rename(g,YYGGgg); rename(g,YYGGgg);
modify YYGGgg : hidden; 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; day = to_string(YYGGgg,0,2) : dump;
hour = to_string(YYGGgg,2,2) : dump; hour = to_string(YYGGgg,2,2) : dump;
minute = to_string(YYGGgg,4,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" ) { if ( ! isCorrection && g is "COR" ) {
rename(g,cor); rename(g,cor);
alias status=correction; alias status=correction;

View File

@ -291,13 +291,13 @@ static int unpack_string (grib_accessor* a, char* buffer, size_t *len)
if (err) return err; if (err) return err;
if((err=grib_get_string_internal(a->parent->h,self->key,key,&size)) != GRIB_SUCCESS) { 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; return err;
} }
list=(char*)grib_trie_get(dictionary,key); list=(char*)grib_trie_get(dictionary,key);
if (!list) { if (!list) {
grib_trie_delete(dictionary); /* grib_trie_delete(dictionary); */
return GRIB_NOT_FOUND; return GRIB_NOT_FOUND;
} }
@ -310,7 +310,7 @@ static int unpack_string (grib_accessor* a, char* buffer, size_t *len)
end--; end--;
rsize=end-start; rsize=end-start;
if (*len < rsize) { if (*len < rsize) {
grib_trie_delete(dictionary); /* grib_trie_delete(dictionary); */
return GRIB_ARRAY_TOO_SMALL; 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); memcpy(buffer,start,rsize);
buffer[rsize]=0; buffer[rsize]=0;
grib_trie_delete(dictionary); /* grib_trie_delete(dictionary); */
return err; return err;
} }

View File

@ -174,7 +174,7 @@ static size_t string_length(grib_accessor* a){
if (self->length) return self->length; if (self->length) return self->length;
_grib_get_string_length(a,&size); grib_get_string_length(a->parent->h,self->key,&size);
return size; return size;
} }

View File

@ -174,7 +174,7 @@ static size_t string_length(grib_accessor* a){
if (self->length) return self->length; if (self->length) return self->length;
_grib_get_string_length(a,&size); grib_get_string_length(a->parent->h,self->key,&size);
return size; return size;
} }

View File

@ -396,11 +396,8 @@ static grib_accessor* _grib_find_accessor(grib_handle* h, const char* name)
int has_rank(const char* name) { int has_rank(const char* name) {
char* p=(char*)name; char* p=(char*)name;
while (*p!=0) { while (*p!=0 && *p!='#') p++;
if (*p == '#') return 1; return *p ? 1 : 0 ;
p++;
}
return 0;
} }
char* grib_split_name_attribute(grib_context* c,const char* name,char* attribute_name) { char* grib_split_name_attribute(grib_context* c,const char* name,char* attribute_name) {

View File

@ -43,6 +43,8 @@ list( APPEND tests2
bufr_json bufr_json
bufr_ls bufr_ls
gts_ls gts_ls
metar_ls
metar_dump
bufr_set bufr_set
ieee ieee
grib1to2 grib1to2

View File

@ -2,6 +2,7 @@ TESTS = definitions.sh calendar.sh \
bufrdc_desc_ref.sh bufrdc_ref.sh bufr_dump.sh bufr_filter.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 \ bufr_json.sh bufr_compare.sh bufr_copy.sh bufr_count.sh bufr_get.sh bufr_ls.sh bufr_set.sh \
gts_ls.sh \ gts_ls.sh \
metar_ls.sh metar_dump.sh \
ieee.sh grib1to2.sh \ ieee.sh grib1to2.sh \
unit_tests.sh \ unit_tests.sh \
grib2to1.sh badgrib.sh ls.sh filter.sh \ grib2to1.sh badgrib.sh ls.sh filter.sh \

50
tests/metar_dump.sh Executable file
View File

@ -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

50
tests/metar_ls.sh Executable file
View File

@ -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

View File

@ -14,6 +14,7 @@ list( APPEND grib_tools_bins
bufr_filter bufr_ls bufr_dump bufr_set bufr_get bufr_filter bufr_ls bufr_dump bufr_set bufr_get
bufr_copy bufr_compare bufr_index_build 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
) )
list( APPEND grib_tools_bins_ECMWF_ONLY list( APPEND grib_tools_bins_ECMWF_ONLY

View File

@ -19,7 +19,8 @@ bin_PROGRAMS = grib_histogram big2gribex \
gg_sub_area_check grib_to_netcdf grib_to_json \ gg_sub_area_check grib_to_netcdf grib_to_json \
bufr_count bufr_filter bufr_ls bufr_dump bufr_set bufr_get \ bufr_count bufr_filter bufr_ls bufr_dump bufr_set bufr_get \
bufr_copy bufr_compare bufr_index_build \ 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 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_get_SOURCES = gts_get.c
gts_ls_SOURCES = gts_ls.c gts_ls_SOURCES = gts_ls.c
metar_dump_SOURCES = metar_dump.c
metar_ls_SOURCES = metar_ls.c
INCLUDES = -I$(top_builddir)/src INCLUDES = -I$(top_builddir)/src
LDADD = libgrib_tools.la $(top_builddir)/src/libeccodes.la LDADD = libgrib_tools.la $(top_builddir)/src/libeccodes.la