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
################################################
list( APPEND test_bins
double_cmp
read_any
julian
index
@ -39,6 +40,7 @@ list( APPEND tests1
uerra
)
list( APPEND tests2
double_cmp
bufr_dump
bufrdc_desc_ref
bufrdc_ref

View File

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