2013-04-30 12:51:23 +00:00
|
|
|
/*
|
2020-01-28 14:32:34 +00:00
|
|
|
* (C) Copyright 2005- ECMWF.
|
2013-04-30 12:51:23 +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>
|
2023-04-19 16:57:06 +00:00
|
|
|
#include <time.h>
|
2014-12-23 10:16:21 +00:00
|
|
|
#include "eccodes.h"
|
2013-04-30 12:51:23 +00:00
|
|
|
|
|
|
|
/* See JIRA issue GRIB-361 */
|
|
|
|
int main()
|
|
|
|
{
|
2015-12-22 17:55:45 +00:00
|
|
|
const int ni = 2880;
|
|
|
|
const int nj = 2880;
|
2021-11-30 13:27:22 +00:00
|
|
|
size_t numbytes = 0;
|
2020-01-22 14:57:43 +00:00
|
|
|
double* values;
|
|
|
|
int i = 0;
|
|
|
|
codes_handle* h = NULL;
|
2017-01-17 17:10:22 +00:00
|
|
|
const char* filename = "bigfile.grib";
|
2023-04-19 10:20:27 +00:00
|
|
|
|
|
|
|
#ifndef ECCODES_ON_WINDOWS
|
2023-04-19 09:58:21 +00:00
|
|
|
unsigned int seed = time(NULL);
|
2023-04-19 10:20:27 +00:00
|
|
|
#endif
|
2013-04-30 12:51:23 +00:00
|
|
|
|
2021-11-30 13:27:22 +00:00
|
|
|
numbytes = ni * nj * sizeof(double);
|
|
|
|
values = (double*)malloc(numbytes);
|
2015-12-22 17:55:45 +00:00
|
|
|
if (!values) {
|
2022-12-21 11:23:48 +00:00
|
|
|
fprintf(stderr, "Malloc failed - requested %zu bytes\n", numbytes);
|
2021-11-30 13:27:22 +00:00
|
|
|
return 1;
|
2015-12-22 17:55:45 +00:00
|
|
|
}
|
2013-04-30 12:51:23 +00:00
|
|
|
|
2020-01-22 14:57:43 +00:00
|
|
|
for (i = 0; i < ni * nj; i++) {
|
2023-04-19 10:20:27 +00:00
|
|
|
#ifndef ECCODES_ON_WINDOWS
|
|
|
|
double r = rand_r(&seed) * 1.0 / RAND_MAX;
|
|
|
|
#else
|
|
|
|
double r = rand() * 1.0 / RAND_MAX;
|
|
|
|
#endif
|
2019-10-11 12:35:01 +00:00
|
|
|
values[i] = r;
|
2015-12-22 17:55:45 +00:00
|
|
|
}
|
2013-04-30 12:51:23 +00:00
|
|
|
|
2016-07-19 10:52:55 +00:00
|
|
|
h = codes_grib_handle_new_from_samples(0, "GRIB1");
|
2013-04-30 12:51:23 +00:00
|
|
|
|
2015-12-22 17:55:45 +00:00
|
|
|
CODES_CHECK(codes_set_long(h, "Ni", ni), 0);
|
|
|
|
CODES_CHECK(codes_set_long(h, "Nj", nj), 0);
|
|
|
|
CODES_CHECK(codes_set_long(h, "centre", 86), 0);
|
|
|
|
CODES_CHECK(codes_set_long(h, "process", 100), 0);
|
|
|
|
CODES_CHECK(codes_set_long(h, "indicatorOfTypeOfLevel", 105), 0);
|
|
|
|
CODES_CHECK(codes_set_long(h, "level", 2), 0);
|
|
|
|
CODES_CHECK(codes_set_long(h, "indicatorOfParameter", 1), 0);
|
|
|
|
CODES_CHECK(codes_set_long(h, "table2Version", 1), 0);
|
|
|
|
CODES_CHECK(codes_set_long(h, "dataDate", 20130424), 0);
|
|
|
|
CODES_CHECK(codes_set_long(h, "dataTime", 0), 0);
|
|
|
|
CODES_CHECK(codes_set_long(h, "startStep", 0), 0);
|
|
|
|
CODES_CHECK(codes_set_long(h, "endStep", 0), 0);
|
2013-04-30 12:51:23 +00:00
|
|
|
|
2015-12-22 17:55:45 +00:00
|
|
|
CODES_CHECK(codes_set_long(h, "bitmapPresent", 1), 0);
|
2013-04-30 12:51:23 +00:00
|
|
|
|
2015-12-22 17:55:45 +00:00
|
|
|
CODES_CHECK(codes_set_double(h, "iDirectionIncrementInDegrees", 0.125), 0);
|
|
|
|
CODES_CHECK(codes_set_double(h, "jDirectionIncrementInDegrees", 0.125), 0);
|
2020-01-22 14:57:43 +00:00
|
|
|
CODES_CHECK(codes_set_long(h, "iScansNegatively", 0), 0);
|
|
|
|
CODES_CHECK(codes_set_long(h, "jScansPositively", 1), 0);
|
2013-04-30 12:51:23 +00:00
|
|
|
|
2015-12-22 17:55:45 +00:00
|
|
|
CODES_CHECK(codes_set_double(h, "latitudeOfFirstGridPointInDegrees", -90), 0);
|
|
|
|
CODES_CHECK(codes_set_double(h, "latitudeOfLastGridPointInDegrees", 90), 0);
|
|
|
|
CODES_CHECK(codes_set_double(h, "longitudeOfFirstGridPointInDegrees", -180), 0);
|
|
|
|
CODES_CHECK(codes_set_double(h, "longitudeOfLastGridPointInDegrees", 180), 0);
|
2013-04-30 12:51:23 +00:00
|
|
|
|
2020-01-22 14:57:43 +00:00
|
|
|
CODES_CHECK(codes_set_double_array(h, "values", values, ni * nj), 0);
|
2013-04-30 12:51:23 +00:00
|
|
|
|
2015-12-22 17:55:45 +00:00
|
|
|
codes_write_message(h, filename, "w");
|
2013-04-30 12:51:23 +00:00
|
|
|
|
2015-12-22 17:55:45 +00:00
|
|
|
codes_handle_delete(h);
|
2020-01-22 14:57:43 +00:00
|
|
|
free(values);
|
2013-04-30 12:51:23 +00:00
|
|
|
|
2015-12-22 17:55:45 +00:00
|
|
|
return 0;
|
2013-04-30 12:51:23 +00:00
|
|
|
}
|