/* * Copyright 2005-2018 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 "grib_api_internal.h" #include "eccodes.h" #include #include extern char *optarg; extern int optind; #define STR_EQUAL(s1, s2) (strcmp((s1), (s2)) == 0) static int get_packing_type_code(const char* packingType) { int result = GRIB_UTIL_PACKING_TYPE_GRID_SIMPLE; if (packingType==NULL) return result; if (STR_EQUAL(packingType, "grid_jpeg")) result = GRIB_UTIL_PACKING_TYPE_JPEG; else if (STR_EQUAL(packingType, "grid_simple")) result = GRIB_UTIL_PACKING_TYPE_GRID_SIMPLE; else if (STR_EQUAL(packingType, "grid_second_order")) result = GRIB_UTIL_PACKING_TYPE_GRID_SECOND_ORDER; return result; } static void test_reduced_gg(int remove_local_def, int edition, const char* packingType, const char* input_filename, const char* output_filename) { /* based on copy_spec_from_ksec */ int err = 0; size_t slen = 32, inlen = 0, outlen = 0; size_t i=0, size=0; int set_spec_flags=0; double* values = NULL; FILE* in = NULL; FILE* out = NULL; const void* buffer = NULL; char gridType[128] = {0,}; codes_handle *handle = 0; codes_handle *finalh = 0; grib_util_grid_spec spec={0,}; grib_util_packing_spec packing_spec={0,}; in = fopen(input_filename,"r"); assert(in); handle = grib_handle_new_from_file(0,in,&err); assert(handle); CODES_CHECK(grib_get_string(handle, "gridType", gridType, &slen),0); if (!STR_EQUAL(gridType, "reduced_gg")) { grib_handle_delete(handle); return; } out = fopen(output_filename,"w"); assert(out); CODES_CHECK(grib_get_size(handle,"values",&inlen), 0); values = (double*)malloc(sizeof(double)*inlen); CODES_CHECK(grib_get_double_array(handle, "values", values,&inlen), 0); for(i=0; i