2016-11-18 18:09:04 +00:00
|
|
|
/*
|
2019-04-15 13:44:45 +00:00
|
|
|
* Copyright 2005-2019 ECMWF.
|
2016-11-18 18:09:04 +00:00
|
|
|
*
|
|
|
|
* 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 <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <pthread.h>
|
|
|
|
|
|
|
|
#include "eccodes.h"
|
|
|
|
#define NUM_THREADS 3
|
|
|
|
|
2017-11-20 11:48:41 +00:00
|
|
|
/*static int DBL_EQUAL(double d1, double d2, double tolerance)
|
2016-11-18 18:09:04 +00:00
|
|
|
{
|
2016-11-18 20:20:59 +00:00
|
|
|
return fabs(d1-d2) <= tolerance;
|
2017-11-20 11:48:41 +00:00
|
|
|
}*/
|
2016-11-18 20:20:59 +00:00
|
|
|
|
|
|
|
static void* process_bufr(void* arg)
|
|
|
|
{
|
2020-01-22 14:57:43 +00:00
|
|
|
FILE* fin = (FILE*)arg;
|
|
|
|
int err = 0;
|
2017-11-20 11:48:41 +00:00
|
|
|
codes_handle* h = NULL;
|
2017-11-21 13:07:17 +00:00
|
|
|
long numSubsets = 0, lVal = 0;
|
2020-01-22 14:57:43 +00:00
|
|
|
size_t size = 0, i = 0;
|
2016-11-18 20:20:59 +00:00
|
|
|
double* dValues = NULL;
|
2017-11-20 11:48:41 +00:00
|
|
|
/* Each thread gets a different message handle */
|
|
|
|
h = codes_handle_new_from_file(NULL, fin, PRODUCT_BUFR, &err);
|
|
|
|
assert(h);
|
2016-11-18 18:09:04 +00:00
|
|
|
|
2017-11-21 13:07:17 +00:00
|
|
|
/* Check expected values for this BUFR file */
|
2020-01-22 14:57:43 +00:00
|
|
|
CODES_CHECK(codes_get_long(h, "numberOfSubsets", &numSubsets), 0);
|
|
|
|
assert(numSubsets == 1);
|
2017-11-21 13:07:17 +00:00
|
|
|
CODES_CHECK(codes_get_long(h, "rectimeSecond", &lVal), 0);
|
2020-01-22 14:57:43 +00:00
|
|
|
assert(lVal == 27);
|
2017-11-20 11:48:41 +00:00
|
|
|
|
2020-01-22 14:57:43 +00:00
|
|
|
CODES_CHECK(codes_set_long(h, "unpack", 1), 0);
|
2016-11-18 18:09:04 +00:00
|
|
|
|
2020-01-22 14:57:43 +00:00
|
|
|
dValues = (double*)malloc(numSubsets * sizeof(double));
|
2016-11-18 20:20:59 +00:00
|
|
|
assert(dValues);
|
|
|
|
size = numSubsets;
|
|
|
|
CODES_CHECK(codes_get_double_array(h, "latitude", dValues, &size), 0);
|
2020-01-22 14:57:43 +00:00
|
|
|
for (i = 0; i < size; ++i) {
|
2017-11-20 11:48:41 +00:00
|
|
|
/* Specific test for latitudes in this BUFR file */
|
2020-01-22 14:57:43 +00:00
|
|
|
assert(dValues[0] < 79 && dValues[0] > 70);
|
2017-11-20 11:48:41 +00:00
|
|
|
}
|
2016-11-18 20:20:59 +00:00
|
|
|
free(dValues);
|
2020-01-22 14:57:43 +00:00
|
|
|
|
2017-11-21 13:07:17 +00:00
|
|
|
/* Some encoding too */
|
2020-01-22 14:57:43 +00:00
|
|
|
CODES_CHECK(codes_set_long(h, "bufrHeaderCentre", 88), 0);
|
2017-11-21 13:07:17 +00:00
|
|
|
CODES_CHECK(codes_set_long(h, "blockNumber", 2), 0);
|
|
|
|
CODES_CHECK(codes_set_long(h, "#3#verticalSignificanceSurfaceObservations", 8), 0);
|
|
|
|
CODES_CHECK(codes_set_long(h, "pack", 1), 0);
|
|
|
|
|
2016-11-18 18:09:04 +00:00
|
|
|
pthread_exit(NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char** argv)
|
|
|
|
{
|
2017-11-20 11:48:41 +00:00
|
|
|
pthread_t thread1, thread2, thread3;
|
2020-01-22 14:57:43 +00:00
|
|
|
int err = 0;
|
|
|
|
FILE* fin = 0;
|
2016-11-18 18:09:04 +00:00
|
|
|
codes_handle* h1 = 0;
|
|
|
|
codes_handle* h2 = 0;
|
2020-01-22 14:57:43 +00:00
|
|
|
fin = fopen("../../data/bufr/syno_multi.bufr", "rb");
|
2017-11-20 11:48:41 +00:00
|
|
|
assert(fin);
|
2016-11-18 18:09:04 +00:00
|
|
|
|
2020-01-22 14:57:43 +00:00
|
|
|
err = pthread_create(&thread1, NULL, process_bufr, (void*)fin);
|
2016-11-21 14:03:17 +00:00
|
|
|
assert(!err);
|
2016-11-18 20:20:59 +00:00
|
|
|
|
2020-01-22 14:57:43 +00:00
|
|
|
err = pthread_create(&thread2, NULL, process_bufr, (void*)fin);
|
2017-11-20 11:48:41 +00:00
|
|
|
assert(!err);
|
|
|
|
|
2020-01-22 14:57:43 +00:00
|
|
|
err = pthread_create(&thread3, NULL, process_bufr, (void*)fin);
|
2016-11-21 14:03:17 +00:00
|
|
|
assert(!err);
|
2016-11-18 20:20:59 +00:00
|
|
|
|
2016-11-21 14:03:17 +00:00
|
|
|
pthread_join(thread1, NULL);
|
|
|
|
pthread_join(thread2, NULL);
|
2017-11-20 11:48:41 +00:00
|
|
|
pthread_join(thread3, NULL);
|
2017-11-21 13:07:17 +00:00
|
|
|
|
2017-11-20 11:48:41 +00:00
|
|
|
fclose(fin);
|
2016-11-18 20:20:59 +00:00
|
|
|
codes_handle_delete(h1);
|
|
|
|
codes_handle_delete(h2);
|
2016-11-18 18:09:04 +00:00
|
|
|
return 0;
|
|
|
|
}
|