/* * 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 #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,}; assert(input_filename); 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; } assert(output_filename); 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; i8) usage(prog); for (i = 1; i < argc; i++) { if (strcmp(argv[i],"-p")==0) { packingType = argv[i+1]; ++i; } else if (strcmp(argv[i],"-e")==0) { edition = atoi( argv[i+1] ); ++i; } else if (strcmp(argv[i],"-r")==0) { remove_local_def = 1; } else { /* Expect 2 filenames */ infile_name = argv[i]; outfile_name = argv[i+1]; break; } } #if 0 printf("DEBUG remove_local_def = %d\n", remove_local_def); printf("DEBUG edition = %d\n", edition); printf("DEBUG packingType = %s\n", packingType); printf("DEBUG infile_name = %s\n", infile_name); printf("DEBUG outfile_name = %s\n", outfile_name); #endif test_regular_ll(remove_local_def, edition, packingType, infile_name, outfile_name); test_reduced_gg(remove_local_def, edition, packingType, infile_name, outfile_name); /*test_grid_complex_spatial_differencing(remove_local_def, edition, packingType, infile_name, outfile_name);*/ return 0; }