Testing: Added new test for grib ieee element access

This commit is contained in:
Shahram Najm 2016-04-08 13:53:00 +01:00
parent dfb1033a0f
commit 3d232fa190
2 changed files with 42 additions and 45 deletions

View File

@ -10,6 +10,7 @@ execute_process( COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_S
# Build the executables used by test scripts # Build the executables used by test scripts
################################################ ################################################
list( APPEND test_bins list( APPEND test_bins
double_cmp
read_any read_any
julian julian
index index
@ -39,6 +40,7 @@ list( APPEND tests1
uerra uerra
) )
list( APPEND tests2 list( APPEND tests2
double_cmp
bufr_dump bufr_dump
bufrdc_desc_ref bufrdc_desc_ref
bufrdc_ref bufrdc_ref

View File

@ -17,65 +17,60 @@
* Author: Cristian D. Codorean * Author: Cristian D. Codorean
* *
*/ */
#include <stdio.h>
#include <stdlib.h>
#include "grib_api.h" #include "grib_api.h"
void usage(char* prog) { void usage(char* prog) {
printf("usage: %s filename\n",prog); printf("usage: %s filename\n",prog);
exit(1); exit(1);
} }
int main(int argc, char** argv) { int main(int argc, char** argv)
int err = 0,i; {
double *values = NULL; int err = 0,i;
size_t values_len= 0; double *values = NULL;
double element_value=0; size_t values_len= 0;
double element_value=0;
FILE* in = NULL; FILE* in = NULL;
char* filename ; char* filename ;
grib_handle *h = NULL; grib_handle *h = NULL;
if (argc<2) usage(argv[0]); if (argc<2) usage(argv[0]);
filename=argv[1]; filename=argv[1];
in = fopen(filename,"r"); in = fopen(filename,"r");
if(!in) { if(!in) {
printf("ERROR: unable to open file %s\n",filename); printf("ERROR: unable to open file %s\n",filename);
return 1; return 1;
} }
/* create new handle from a message in a file*/ /* create new handle from a message in a file*/
h = grib_handle_new_from_file(0,in,&err); h = grib_handle_new_from_file(0,in,&err);
if (h == NULL) { if (h == NULL) {
printf("Error: unable to create handle from file %s\n",filename); printf("Error: unable to create handle from file %s\n",filename);
} }
/* get the size of the values array */
GRIB_CHECK(grib_get_size(h,"values",&values_len),0);
values = (double*)malloc(values_len*sizeof(double));
/* get the size of the values array*/ /* get data values*/
GRIB_CHECK(grib_get_size(h,"values",&values_len),0); GRIB_CHECK(grib_get_double_array(h,"values",values,&values_len),0);
values = (double*)malloc(values_len*sizeof(double)); if (values_len < 100) exit(1);
/* get data values*/ for (i = 0; i < 100; i++) {
GRIB_CHECK(grib_get_double_array(h,"values",values,&values_len),0); /* get double element */
GRIB_CHECK(grib_get_double_element(h,"values",i,&element_value),0);
if (values_len < 100) exit(1); if (element_value != values[i]) {
exit(1);
}
}
for (i = 0; i < 100; i++) { free(values);
/* get double element */ grib_handle_delete(h);
GRIB_CHECK(grib_get_double_element(h,"values",i,&element_value),0);
if (element_value != values[i]) { fclose(in);
exit(1); return 0;
}
}
free(values);
grib_handle_delete(h);
fclose(in);
return 0;
} }