mirror of https://github.com/ecmwf/eccodes.git
Merge branch 'eccodes' of ssh://software.ecmwf.int:7999/grib/grib_api into eccodes
This commit is contained in:
commit
55fa24ad04
|
@ -442,8 +442,13 @@ void grib_parser_include(const char* fname)
|
|||
parse_file = path;
|
||||
}
|
||||
|
||||
grib_context_log(grib_parser_context,GRIB_LOG_DEBUG,"parsing include file %s",parse_file);
|
||||
f = fopen(parse_file,"r");
|
||||
if (strcmp(parse_file,"-")==0) {
|
||||
grib_context_log(grib_parser_context,GRIB_LOG_DEBUG,"parsing standard input");
|
||||
f = stdin; /* read from std input */
|
||||
} else {
|
||||
grib_context_log(grib_parser_context,GRIB_LOG_DEBUG,"parsing include file %s",parse_file);
|
||||
f = fopen(parse_file,"r");
|
||||
}
|
||||
/* for(i = 0; i < top ; i++) printf(" "); */
|
||||
/* printf("PARSING %s\n",parse_file); */
|
||||
|
||||
|
|
|
@ -116,6 +116,10 @@ set values = {
|
|||
EOF
|
||||
${tools_dir}/grib_filter temp.filt $ECCODES_SAMPLES_PATH/GRIB1.tmpl
|
||||
|
||||
# Test reading from stdin
|
||||
echo 'set centre="kwbc";write;' | ${tools_dir}/grib_filter -o temp_filt.grib2 - $ECCODES_SAMPLES_PATH/GRIB2.tmpl
|
||||
result=`${tools_dir}/grib_get -p centre temp_filt.grib2`
|
||||
[ "$result" = "kwbc" ]
|
||||
|
||||
rm -f temp_filt.grib2 temp.filt
|
||||
rm -f ${data_dir}/formatint.rules ${data_dir}/binop.rules
|
||||
|
|
|
@ -27,9 +27,9 @@ rm -f ${outfile}
|
|||
|
||||
count=`${tools_dir}/grib_count ${data_dir}/pad.grib`
|
||||
|
||||
if [ $count != 6 ]
|
||||
then
|
||||
if [ $count != 6 ]; then
|
||||
echo grib_io problem
|
||||
exit 1
|
||||
fi
|
||||
|
||||
${tools_dir}/grib_count -v ${data_dir}/pad.grib >/dev/null
|
||||
|
|
|
@ -45,11 +45,9 @@ endforeach()
|
|||
# Count tools. Same source code, different executable names
|
||||
ecbuild_add_executable( TARGET grib_count
|
||||
SOURCES codes_count.c
|
||||
CONDITION ECCODES_INSTALL_ECMWF_TOOLS
|
||||
LIBS grib_tools )
|
||||
ecbuild_add_executable( TARGET bufr_count
|
||||
SOURCES codes_count.c
|
||||
CONDITION ECCODES_INSTALL_ECMWF_TOOLS
|
||||
LIBS grib_tools )
|
||||
|
||||
# grib_list_keys
|
||||
|
|
|
@ -10,18 +10,18 @@
|
|||
|
||||
#include "grib_api_internal.h"
|
||||
|
||||
void usage(char* prog)
|
||||
void usage(const char* prog)
|
||||
{
|
||||
printf("usage: %s infile1 infile2 ... \n",prog);
|
||||
printf("usage: %s [-v] infile1 infile2 ... \n",prog);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
static int check_file(FILE* in, int message_type, long *count)
|
||||
static int count_messages(FILE* in, int message_type, unsigned long *count)
|
||||
{
|
||||
void* mesg=NULL;
|
||||
size_t size=0;
|
||||
off_t offset=0;
|
||||
int err=0;
|
||||
int err=GRIB_SUCCESS;
|
||||
typedef void* (*wmo_read_proc)(FILE *, int, size_t *, off_t *, int *);
|
||||
wmo_read_proc wmo_read = NULL;
|
||||
grib_context* c=grib_context_get_default();
|
||||
|
@ -44,11 +44,11 @@ static int check_file(FILE* in, int message_type, long *count)
|
|||
|
||||
int main(int argc,char* argv[])
|
||||
{
|
||||
FILE* infh;
|
||||
FILE* infh = NULL;
|
||||
char* filename;
|
||||
int i;
|
||||
int i, verbose=0;
|
||||
int err=0;
|
||||
long n=0,nn=0;
|
||||
unsigned long count_total=0, count_curr=0;
|
||||
int message_type = 0; /* GRIB, BUFR etc */
|
||||
|
||||
if (argc <2) usage(argv[0]);
|
||||
|
@ -56,27 +56,41 @@ 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;
|
||||
|
||||
n=0;
|
||||
count_total=0;
|
||||
for (i=1;i<argc;i++) {
|
||||
if (strcmp(argv[i], "-v")==0) {
|
||||
verbose = 1;
|
||||
if (argc <3) usage(argv[0]);
|
||||
continue;
|
||||
}
|
||||
filename=argv[i];
|
||||
|
||||
infh=fopen(filename,"r");
|
||||
if (!infh) {
|
||||
perror(filename);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
nn=0;
|
||||
err=check_file(infh, message_type, &nn);
|
||||
if (err!=0) {
|
||||
count_curr=0;
|
||||
err=count_messages(infh, message_type, &count_curr);
|
||||
if (err) {
|
||||
fprintf(stderr,"Invalid message(s) found in %s\n", filename);
|
||||
exit(err);
|
||||
#ifdef DONT_EXIT_ON_BAD_APPLE
|
||||
/* If we did not want to fail but warn and continue */
|
||||
fclose(infh);
|
||||
continue;
|
||||
#endif
|
||||
}
|
||||
n+=nn;
|
||||
if (verbose) printf ("%7lu %s\n", count_curr, filename);
|
||||
count_total += count_curr;
|
||||
|
||||
fclose(infh);
|
||||
}
|
||||
printf("%ld\n",n);
|
||||
if (verbose) {
|
||||
printf("%7lu %s\n", count_total, "total");
|
||||
} else {
|
||||
printf("%lu\n", count_total);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue