Add extra test for setting PV

This commit is contained in:
Shahram Najm 2014-07-01 14:43:26 +01:00
parent 2c7ac55535
commit 2584dd3544
4 changed files with 41 additions and 9 deletions

View File

@ -57,6 +57,7 @@ list( APPEND tests
set_missing
clone
sections_copy
set_pv
)
foreach (test ${tests})
ecbuild_add_test( TARGET c_${test}

View File

@ -2,7 +2,7 @@
AM_CFLAGS = @WARN_PEDANTIC@ @WERROR@
TESTS = iterator.sh get.sh print_data.sh set.sh keys_iterator.sh multi.sh multi_write.sh \
precision.sh list.sh large_grib1.sh get_data.sh sections_copy.sh set_missing.sh clone.sh
precision.sh list.sh large_grib1.sh get_data.sh sections_copy.sh set_missing.sh clone.sh set_pv.sh
noinst_PROGRAMS = nearest set_bitmap iterator get print_data set set_missing keys_iterator \
set_data mars_param values_check box multi multi2 multi_write precision \

View File

@ -16,33 +16,42 @@
*/
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include "grib_api.h"
void usage(const char* prog) {
fprintf(stderr, "usage: %s in out\n",prog);
exit(1);
}
int main(int argc, char** argv)
{
int err = 0;
long PVPresent=1;
long PVPresent=1, NV = 0;
size_t size=0;
double pv[4]={1,2,3,4};
size_t pvsize=4;
FILE* in = NULL;
char* infile = "../../data/regular_latlon_surface.grib1";
char* infile = NULL;
FILE* out = NULL;
char* outfile = "out.grib1";
char* outfile = NULL;
grib_handle *h = NULL;
const void* buffer = NULL;
if (argc != 3) usage(argv[0]);
infile = argv[1];
outfile= argv[2];
in = fopen(infile,"r");
if(!in) {
printf("ERROR: unable to open input file %s\n",infile);
fprintf(stderr, "ERROR: unable to open input file %s\n",infile);
return 1;
}
out = fopen(outfile,"w");
if(!out) {
printf("ERROR: unable to open output file %s\n",outfile);
fprintf(stderr, "ERROR: unable to open output file %s\n",outfile);
fclose(in);
return 1;
}
@ -50,13 +59,16 @@ int main(int argc, char** argv)
/* create a new handle from a message in a file */
h = grib_handle_new_from_file(0,in,&err);
if (h == NULL) {
printf("Error: unable to create handle from file %s\n",infile);
fprintf(stderr, "Error: unable to create handle from file %s\n",infile);
}
GRIB_CHECK(grib_set_long(h,"PVPresent",PVPresent),0);
GRIB_CHECK(grib_set_double_array(h,"pv",pv,pvsize),0);
/* Once we set the pv array, the NV key should be also set */
GRIB_CHECK(grib_get_long(h,"NV",&NV),0);
assert( NV == pvsize );
/* get the coded message in a buffer */
GRIB_CHECK(grib_get_message(h,&buffer,&size),0);

19
examples/C/set_pv.sh Executable file
View File

@ -0,0 +1,19 @@
#!/bin/sh
# Copyright 2005-2014 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
GRIB1=../../data/regular_latlon_surface.grib1
GRIB2=../../samples/regular_ll_sfc_grib2.tmpl
OUT=temp.$$.out
${examples_dir}set_pv $GRIB1 $OUT > /dev/null
${examples_dir}set_pv $GRIB2 $OUT > /dev/null
rm -f $OUT