eccodes/examples/C/large_grib1.c

73 lines
2.5 KiB
C
Raw Normal View History

2013-04-30 12:51:23 +00:00
/*
2019-04-15 13:44:45 +00:00
* Copyright 2005-2019 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>
#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;
double *values;
int i = 0;
codes_handle *h = NULL;
2017-01-17 17:10:22 +00:00
const char* filename = "bigfile.grib";
2013-04-30 12:51:23 +00:00
2015-12-22 17:55:45 +00:00
values = (double*) malloc(ni*nj*sizeof(double));
if (!values) {
printf ("Malloc failed\n");
exit(1);
}
2013-04-30 12:51:23 +00:00
2015-12-22 17:55:45 +00:00
for (i=0; i<ni*nj; i++) {
double r = rand();
values[i] = 10*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);
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
2015-12-22 17:55:45 +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");
/*printf("Wrote file %s\n", filename);*/
2013-04-30 12:51:23 +00:00
2015-12-22 17:55:45 +00:00
codes_handle_delete(h);
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
}