mirror of https://github.com/ecmwf/eccodes.git
ecCodes/ECC-1: made all C examples use the codes_ prefix
This commit is contained in:
parent
3cee330d8c
commit
f53142e1c2
|
@ -8,17 +8,17 @@
|
|||
* virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
|
||||
*/
|
||||
|
||||
#include "grib_api.h"
|
||||
#include "eccodes.h"
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
FILE* f;
|
||||
int err=0;
|
||||
char infile[]="../../data/reduced_gaussian_model_level.grib1";
|
||||
grib_handle *h=NULL;
|
||||
grib_box* box;
|
||||
grib_points* points;
|
||||
grib_context* c=grib_context_get_default();
|
||||
codes_handle *h=NULL;
|
||||
codes_box* box;
|
||||
codes_points* points;
|
||||
codes_context* c=codes_context_get_default();
|
||||
double north,west,south,east;
|
||||
double* val;
|
||||
int i;
|
||||
|
@ -34,23 +34,23 @@ int main(int argc, char* argv[])
|
|||
exit(1);
|
||||
}
|
||||
|
||||
h=grib_handle_new_from_file(c,f,&err);
|
||||
h=codes_handle_new_from_file(c,f,&err);
|
||||
if (!h) {
|
||||
printf("unable to create handle from file %s\n",infile);
|
||||
exit(err);
|
||||
}
|
||||
|
||||
box=grib_box_new(h,&err);
|
||||
box=codes_box_new(h,&err);
|
||||
|
||||
if (!box) {
|
||||
printf("unable to create box\n");
|
||||
exit(err);
|
||||
}
|
||||
|
||||
points=grib_box_get_points(box,north,west,south,east,&err);
|
||||
points=codes_box_get_points(box,north,west,south,east,&err);
|
||||
|
||||
val=(double*)malloc(sizeof(double)*points->n);
|
||||
grib_points_get_values(h,points,val);
|
||||
codes_points_get_values(h,points,val);
|
||||
|
||||
for (i=0;i<points->n;i++) {
|
||||
printf("%d -- %.3f %.3f %ld %g\n",i,
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
#include <stdarg.h>
|
||||
#include "grib_api.h"
|
||||
#include "eccodes.h"
|
||||
|
||||
#define STR_EQUAL(s1, s2) (strcmp((s1), (s2)) == 0)
|
||||
|
||||
|
@ -41,7 +41,7 @@ void usage(const char* prog)
|
|||
void error(const char* fmt, ...)
|
||||
{
|
||||
va_list list;
|
||||
va_start(list, fmt);
|
||||
va_start(list,fmt);
|
||||
vfprintf(stderr, fmt, list);
|
||||
va_end(list);
|
||||
|
||||
|
@ -62,7 +62,7 @@ double get_precision(long edition)
|
|||
int process_file(const char* filename)
|
||||
{
|
||||
int err = 0, msg_num = 0;
|
||||
grib_handle *h = NULL;
|
||||
codes_handle *h = NULL;
|
||||
|
||||
FILE* in = fopen(filename, "r");
|
||||
if(!in) {
|
||||
|
@ -71,7 +71,7 @@ int process_file(const char* filename)
|
|||
|
||||
printf("Checking file %s\n", filename);
|
||||
|
||||
while ((h = grib_handle_new_from_file(0,in,&err)) != NULL )
|
||||
while ((h = codes_handle_new_from_file(0,in,&err)) != NULL )
|
||||
{
|
||||
int is_reduced = 0, is_regular = 0, grid_ok = 0;
|
||||
long edition = 0, N = 0, Nj = 0, numberOfDataPoints;
|
||||
|
@ -82,31 +82,31 @@ int process_file(const char* filename)
|
|||
double angular_tolerance, lat1, lon1, lat2, lon2, expected_lon2;
|
||||
double iDirectionIncrementInDegrees;
|
||||
|
||||
if (err != GRIB_SUCCESS) GRIB_CHECK(err,0);
|
||||
if (err != CODES_SUCCESS) CODES_CHECK(err,0);
|
||||
++msg_num;
|
||||
printf("\tProcessing GRIB message #%d\n", msg_num);
|
||||
|
||||
len = 32;
|
||||
GRIB_CHECK(grib_get_string(h,"gridType",gridType,&len),0);
|
||||
CODES_CHECK(codes_get_string(h,"gridType",gridType,&len),0);
|
||||
is_regular = STR_EQUAL(gridType, "regular_gg");
|
||||
is_reduced = STR_EQUAL(gridType, "reduced_gg");
|
||||
grid_ok = is_regular || is_reduced;
|
||||
if( !grid_ok ) {
|
||||
/*error("ERROR: gridType should be Reduced or Regular Gaussian Grid!\n");*/
|
||||
printf("\tWARNING: gridType should be Reduced or Regular Gaussian Grid! Ignoring\n");
|
||||
grib_handle_delete(h);
|
||||
codes_handle_delete(h);
|
||||
continue;
|
||||
}
|
||||
|
||||
GRIB_CHECK(grib_get_long(h,"edition",&edition),0);
|
||||
GRIB_CHECK(grib_get_long(h,"N",&N),0);
|
||||
GRIB_CHECK(grib_get_long(h,"Nj",&Nj),0);
|
||||
GRIB_CHECK(grib_get_long(h,"numberOfDataPoints",&numberOfDataPoints),0);
|
||||
GRIB_CHECK(grib_get_double(h,"latitudeOfFirstGridPointInDegrees", &lat1),0);
|
||||
GRIB_CHECK(grib_get_double(h,"longitudeOfFirstGridPointInDegrees",&lon1),0);
|
||||
GRIB_CHECK(grib_get_double(h,"latitudeOfLastGridPointInDegrees", &lat2),0);
|
||||
GRIB_CHECK(grib_get_double(h,"longitudeOfLastGridPointInDegrees", &lon2),0);
|
||||
GRIB_CHECK(grib_get_double(h,"iDirectionIncrementInDegrees",&iDirectionIncrementInDegrees),0);
|
||||
CODES_CHECK(codes_get_long(h,"edition",&edition),0);
|
||||
CODES_CHECK(codes_get_long(h,"N",&N),0);
|
||||
CODES_CHECK(codes_get_long(h,"Nj",&Nj),0);
|
||||
CODES_CHECK(codes_get_long(h,"numberOfDataPoints",&numberOfDataPoints),0);
|
||||
CODES_CHECK(codes_get_double(h,"latitudeOfFirstGridPointInDegrees", &lat1),0);
|
||||
CODES_CHECK(codes_get_double(h,"longitudeOfFirstGridPointInDegrees",&lon1),0);
|
||||
CODES_CHECK(codes_get_double(h,"latitudeOfLastGridPointInDegrees", &lat2),0);
|
||||
CODES_CHECK(codes_get_double(h,"longitudeOfLastGridPointInDegrees", &lon2),0);
|
||||
CODES_CHECK(codes_get_double(h,"iDirectionIncrementInDegrees",&iDirectionIncrementInDegrees),0);
|
||||
|
||||
angular_tolerance = get_precision(edition);
|
||||
|
||||
|
@ -128,7 +128,7 @@ int process_file(const char* filename)
|
|||
lat1, lat2);
|
||||
}
|
||||
lats = (double*)malloc(sizeof(double)*Nj);
|
||||
GRIB_CHECK(grib_get_gaussian_latitudes(N,lats), 0);
|
||||
CODES_CHECK(codes_get_gaussian_latitudes(N,lats), 0);
|
||||
|
||||
if (!DBL_EQUAL(lats[0], lat1, angular_tolerance)) {
|
||||
error("First latitude %f must be %f\n", lat1, lats[0]);
|
||||
|
@ -140,19 +140,19 @@ int process_file(const char* filename)
|
|||
if (is_reduced) {
|
||||
int pl_sum = 0;
|
||||
size_t i = 0, pl_len = 0;
|
||||
int is_missing = grib_is_missing(h, "Ni", &err);
|
||||
assert(err == GRIB_SUCCESS);
|
||||
int is_missing = codes_is_missing(h, "Ni", &err);
|
||||
assert(err == CODES_SUCCESS);
|
||||
if (!is_missing) {
|
||||
error("ERROR: Ni should be missing!\n");
|
||||
}
|
||||
|
||||
GRIB_CHECK(grib_get_size(h, "pl", &pl_len),0);
|
||||
CODES_CHECK(codes_get_size(h, "pl", &pl_len),0);
|
||||
if (pl_len != 2*N) {
|
||||
error("ERROR: Length of pl array is %ld but should be 2*N (%ld)!\n", pl_len, 2*N);
|
||||
}
|
||||
pl = (long*)malloc(pl_len*sizeof(long));
|
||||
assert(pl);
|
||||
GRIB_CHECK(grib_get_long_array(h, "pl", pl, &pl_len),0);
|
||||
CODES_CHECK(codes_get_long_array(h, "pl", pl, &pl_len),0);
|
||||
|
||||
/* Check pl is symmetric */
|
||||
for(i=0; i<pl_len/2; ++i) {
|
||||
|
@ -174,14 +174,14 @@ int process_file(const char* filename)
|
|||
free(pl);
|
||||
}
|
||||
|
||||
GRIB_CHECK(grib_get_size(h, "values", &numberOfValues),0);
|
||||
CODES_CHECK(codes_get_size(h, "values", &numberOfValues),0);
|
||||
if (numberOfValues != numberOfDataPoints) {
|
||||
error("Number of data points %d different from number of values %d\n",
|
||||
numberOfDataPoints, numberOfValues);
|
||||
}
|
||||
|
||||
free(lats);
|
||||
grib_handle_delete(h);
|
||||
codes_handle_delete(h);
|
||||
}
|
||||
fclose(in);
|
||||
printf("\nFile %s OK\n\n", filename);
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
*
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include "grib_api.h"
|
||||
#include "eccodes.h"
|
||||
|
||||
void usage(char *app)
|
||||
{
|
||||
|
@ -27,7 +27,7 @@ int main(int argc, char *argv[])
|
|||
{
|
||||
FILE *in = NULL;
|
||||
FILE *out = NULL;
|
||||
grib_handle *source_handle = NULL;
|
||||
codes_handle *source_handle = NULL;
|
||||
const void *buffer = NULL;
|
||||
size_t size = 0;
|
||||
int err = 0;
|
||||
|
@ -48,9 +48,9 @@ int main(int argc, char *argv[])
|
|||
}
|
||||
|
||||
/* loop over the messages in the source grib and clone them */
|
||||
while ((source_handle = grib_handle_new_from_file(0,in,&err))!=NULL)
|
||||
while ((source_handle = codes_handle_new_from_file(0,in,&err))!=NULL)
|
||||
{
|
||||
grib_handle *clone_handle = grib_handle_clone(source_handle);
|
||||
codes_handle *clone_handle = codes_handle_clone(source_handle);
|
||||
|
||||
if (clone_handle == NULL) {
|
||||
perror("ERROR: could not clone field");
|
||||
|
@ -59,19 +59,19 @@ int main(int argc, char *argv[])
|
|||
|
||||
/* This is the place where you may wish to modify the clone */
|
||||
/* E.g.
|
||||
GRIB_CHECK(grib_set_long(clone_handle, "centre", 250),0);
|
||||
CODES_CHECK(codes_set_long(clone_handle, "centre", 250),0);
|
||||
etc...
|
||||
*/
|
||||
|
||||
/* get the coded message in a buffer */
|
||||
GRIB_CHECK(grib_get_message(clone_handle,&buffer,&size),0);
|
||||
CODES_CHECK(codes_get_message(clone_handle,&buffer,&size),0);
|
||||
/* write the buffer to a file */
|
||||
if(fwrite(buffer,1,size,out) != size) {
|
||||
perror(argv[1]);
|
||||
return 1;
|
||||
}
|
||||
grib_handle_delete(clone_handle);
|
||||
grib_handle_delete(source_handle);
|
||||
codes_handle_delete(clone_handle);
|
||||
codes_handle_delete(source_handle);
|
||||
}
|
||||
|
||||
fclose(out);
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
#include "grib_api.h"
|
||||
#include "eccodes.h"
|
||||
|
||||
int main(int argc, char * argv[])
|
||||
{
|
||||
|
@ -28,47 +28,47 @@ int main(int argc, char * argv[])
|
|||
double* values;
|
||||
double* result=NULL;
|
||||
double min=1e13,max=-1e13,avg=0;
|
||||
grib_index* index;
|
||||
grib_handle* h=NULL;
|
||||
codes_index* index;
|
||||
codes_handle* h=NULL;
|
||||
|
||||
/* create index of file contents for paramId and number */
|
||||
index = grib_index_new_from_file(0, "eps", "paramId,number",&ret);
|
||||
GRIB_CHECK(ret,0);
|
||||
index = codes_index_new_from_file(0, "eps", "paramId,number",&ret);
|
||||
CODES_CHECK(ret,0);
|
||||
|
||||
/* get size of "paramId" list */
|
||||
GRIB_CHECK(grib_index_get_size(index, "paramId", ¶mIdSize),0);
|
||||
CODES_CHECK(codes_index_get_size(index, "paramId", ¶mIdSize),0);
|
||||
printf("grib contains %ld different parameters\n",paramIdSize);
|
||||
/* allocate memory for "paramId" list */
|
||||
paramId = (char**) malloc(paramIdSize * sizeof(char*));
|
||||
/* get list of "paramId" */
|
||||
GRIB_CHECK(grib_index_get_string(index, "paramId", paramId, ¶mIdSize),0);
|
||||
CODES_CHECK(codes_index_get_string(index, "paramId", paramId, ¶mIdSize),0);
|
||||
|
||||
/* get size of ensemble number list */
|
||||
GRIB_CHECK(grib_index_get_size(index, "number", &numberSize),0);
|
||||
CODES_CHECK(codes_index_get_size(index, "number", &numberSize),0);
|
||||
printf("GRIB contains %ld different ensemble members\n",numberSize);
|
||||
/* allocate memory for ensemble number list */
|
||||
number = (long*) malloc(numberSize * sizeof(long));
|
||||
/* get list of ensemble numbers */
|
||||
GRIB_CHECK(grib_index_get_long(index, "number", number, &numberSize),0);
|
||||
CODES_CHECK(codes_index_get_long(index, "number", number, &numberSize),0);
|
||||
|
||||
/* select T850 with paramId 130 */
|
||||
GRIB_CHECK(grib_index_select_string(index, "paramId", "130"), 0);
|
||||
CODES_CHECK(codes_index_select_string(index, "paramId", "130"), 0);
|
||||
|
||||
/* loop over all members */
|
||||
for (i = 0; i < numberSize; i++) {
|
||||
count++;
|
||||
/* select an individual ensemble number */
|
||||
GRIB_CHECK(grib_index_select_long(index, "number", number[i]), 0);
|
||||
CODES_CHECK(codes_index_select_long(index, "number", number[i]), 0);
|
||||
|
||||
/* create handle for next GRIB message */
|
||||
h=grib_handle_new_from_index(index, &ret);
|
||||
h=codes_handle_new_from_index(index, &ret);
|
||||
if (ret) {
|
||||
printf("Error: %s\n", grib_get_error_message(ret));
|
||||
printf("Error: %s\n", codes_get_error_message(ret));
|
||||
exit(ret);
|
||||
}
|
||||
|
||||
/* get the size of the values array */
|
||||
GRIB_CHECK(grib_get_size(h, "values", &values_len), 0);
|
||||
CODES_CHECK(codes_get_size(h, "values", &values_len), 0);
|
||||
|
||||
/* allocate memory for the GRIB message */
|
||||
values = (double*)malloc(values_len * sizeof(double));
|
||||
|
@ -79,7 +79,7 @@ int main(int argc, char * argv[])
|
|||
}
|
||||
|
||||
/* get data values */
|
||||
GRIB_CHECK(grib_get_double_array(h, "values", values, &values_len), 0);
|
||||
CODES_CHECK(codes_get_double_array(h, "values", values, &values_len), 0);
|
||||
|
||||
/* add up values */
|
||||
for (j = 0; j < values_len; j++)
|
||||
|
@ -87,7 +87,7 @@ int main(int argc, char * argv[])
|
|||
|
||||
/* free memory and GRIB message handle */
|
||||
free(values);
|
||||
GRIB_CHECK(grib_handle_delete(h), 0);
|
||||
CODES_CHECK(codes_handle_delete(h), 0);
|
||||
}
|
||||
|
||||
printf("We considered %d ensemble members\n", count);
|
||||
|
@ -117,7 +117,7 @@ int main(int argc, char * argv[])
|
|||
free(paramId);
|
||||
free(number);
|
||||
free(result);
|
||||
grib_index_delete(index);
|
||||
codes_index_delete(index);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "grib_api.h"
|
||||
#include "eccodes.h"
|
||||
|
||||
void usage(char* prog) {
|
||||
printf("Usage: %s order_by grib_file grib_file ...\n",prog);
|
||||
|
@ -34,8 +34,8 @@ int main(int argc, char** argv)
|
|||
size_t nkeys,nfiles;
|
||||
int i=0;
|
||||
char* keys[]={"step","date","param","levelType"};
|
||||
grib_fieldset* set;
|
||||
grib_handle* h;
|
||||
codes_fieldset* set;
|
||||
codes_handle* h;
|
||||
char param[20]={0,};
|
||||
char date[10]={0,};
|
||||
size_t datelen=10;
|
||||
|
@ -52,31 +52,31 @@ int main(int argc, char** argv)
|
|||
for (i=0;i<nfiles;i++)
|
||||
filenames[i]=(char*)strdup(argv[i+2]);
|
||||
|
||||
set=grib_fieldset_new_from_files(0,filenames,nfiles,keys,nkeys,0,0,&err);
|
||||
GRIB_CHECK(err,0);
|
||||
set=codes_fieldset_new_from_files(0,filenames,nfiles,keys,nkeys,0,0,&err);
|
||||
CODES_CHECK(err,0);
|
||||
|
||||
/* not jet implemented */
|
||||
/* err=grib_fieldset_apply_where(set,"(centre=='ecmf') && number==1 || step==6 "); */
|
||||
/* GRIB_CHECK(err,0); */
|
||||
/* err=codes_fieldset_apply_where(set,"(centre=='ecmf') && number==1 || step==6 "); */
|
||||
/* CODES_CHECK(err,0); */
|
||||
|
||||
grib_fieldset_apply_order_by(set,order_by);
|
||||
GRIB_CHECK(err,0);
|
||||
codes_fieldset_apply_order_by(set,order_by);
|
||||
CODES_CHECK(err,0);
|
||||
|
||||
printf("\nordering by %s\n",order_by);
|
||||
printf("\n%d fields in the fieldset\n",grib_fieldset_count(set));
|
||||
printf("\n%d fields in the fieldset\n",codes_fieldset_count(set));
|
||||
printf("step,date,levelType,levelType\n");
|
||||
while ((h=grib_fieldset_next_handle(set,&err))!=NULL) {
|
||||
GRIB_CHECK(grib_get_long(h,"step",&step),0);
|
||||
GRIB_CHECK(grib_get_string(h,"date",date,&datelen),0);
|
||||
GRIB_CHECK(grib_get_string(h,"param",param,&len),0);
|
||||
GRIB_CHECK(grib_get_long(h,"levelType",&levelType),0);
|
||||
while ((h=codes_fieldset_next_handle(set,&err))!=NULL) {
|
||||
CODES_CHECK(codes_get_long(h,"step",&step),0);
|
||||
CODES_CHECK(codes_get_string(h,"date",date,&datelen),0);
|
||||
CODES_CHECK(codes_get_string(h,"param",param,&len),0);
|
||||
CODES_CHECK(codes_get_long(h,"levelType",&levelType),0);
|
||||
|
||||
printf("%ld %s %ld %s\n",step,date,levelType,param);
|
||||
grib_handle_delete(h);
|
||||
codes_handle_delete(h);
|
||||
}
|
||||
|
||||
grib_fieldset_delete(set);
|
||||
grib_handle_delete(h);
|
||||
codes_fieldset_delete(set);
|
||||
codes_handle_delete(h);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
#include "grib_api.h"
|
||||
#include "eccodes.h"
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
|
@ -42,7 +42,7 @@ int main(int argc, char** argv)
|
|||
|
||||
FILE* in = NULL;
|
||||
const char* filename = "../../data/regular_latlon_surface.grib1";
|
||||
grib_handle *h = NULL;
|
||||
codes_handle *h = NULL;
|
||||
|
||||
in = fopen(filename,"r");
|
||||
if(!in) {
|
||||
|
@ -51,61 +51,61 @@ int main(int argc, char** argv)
|
|||
}
|
||||
|
||||
/* create new handle from a message in a file*/
|
||||
h = grib_handle_new_from_file(0,in,&err);
|
||||
h = codes_handle_new_from_file(0,in,&err);
|
||||
if (h == NULL) {
|
||||
printf("Error: unable to create handle from file %s\n",filename);
|
||||
}
|
||||
|
||||
/* Store the filename in the key "file" for this handle */
|
||||
len = strlen(filename);
|
||||
GRIB_CHECK(grib_set_string(h, "file", filename, &len), 0);
|
||||
CODES_CHECK(codes_set_string(h, "file", filename, &len), 0);
|
||||
|
||||
/* get as a long*/
|
||||
GRIB_CHECK(grib_get_long(h,"Ni",&numberOfPointsAlongAParallel),0);
|
||||
CODES_CHECK(codes_get_long(h,"Ni",&numberOfPointsAlongAParallel),0);
|
||||
printf("numberOfPointsAlongAParallel=%ld\n",numberOfPointsAlongAParallel);
|
||||
|
||||
/* get as a long*/
|
||||
GRIB_CHECK(grib_get_long(h,"Nj",&numberOfPointsAlongAMeridian),0);
|
||||
CODES_CHECK(codes_get_long(h,"Nj",&numberOfPointsAlongAMeridian),0);
|
||||
printf("numberOfPointsAlongAMeridian=%ld\n",numberOfPointsAlongAMeridian);
|
||||
|
||||
/* get as a double*/
|
||||
GRIB_CHECK(grib_get_double(h,"latitudeOfFirstGridPointInDegrees",&latitudeOfFirstGridPointInDegrees),0);
|
||||
CODES_CHECK(codes_get_double(h,"latitudeOfFirstGridPointInDegrees",&latitudeOfFirstGridPointInDegrees),0);
|
||||
printf("latitudeOfFirstGridPointInDegrees=%g\n",latitudeOfFirstGridPointInDegrees);
|
||||
|
||||
/* get as a double*/
|
||||
GRIB_CHECK(grib_get_double(h,"longitudeOfFirstGridPointInDegrees",&longitudeOfFirstGridPointInDegrees),0);
|
||||
CODES_CHECK(codes_get_double(h,"longitudeOfFirstGridPointInDegrees",&longitudeOfFirstGridPointInDegrees),0);
|
||||
printf("longitudeOfFirstGridPointInDegrees=%g\n",longitudeOfFirstGridPointInDegrees);
|
||||
|
||||
/* get as a double*/
|
||||
GRIB_CHECK(grib_get_double(h,"latitudeOfLastGridPointInDegrees",&latitudeOfLastGridPointInDegrees),0);
|
||||
CODES_CHECK(codes_get_double(h,"latitudeOfLastGridPointInDegrees",&latitudeOfLastGridPointInDegrees),0);
|
||||
printf("latitudeOfLastGridPointInDegrees=%g\n",latitudeOfLastGridPointInDegrees);
|
||||
|
||||
/* get as a double*/
|
||||
GRIB_CHECK(grib_get_double(h,"longitudeOfLastGridPointInDegrees",&longitudeOfLastGridPointInDegrees),0);
|
||||
CODES_CHECK(codes_get_double(h,"longitudeOfLastGridPointInDegrees",&longitudeOfLastGridPointInDegrees),0);
|
||||
printf("longitudeOfLastGridPointInDegrees=%g\n",longitudeOfLastGridPointInDegrees);
|
||||
|
||||
/* get as a double*/
|
||||
GRIB_CHECK(grib_get_double(h,"jDirectionIncrementInDegrees",&jDirectionIncrementInDegrees),0);
|
||||
CODES_CHECK(codes_get_double(h,"jDirectionIncrementInDegrees",&jDirectionIncrementInDegrees),0);
|
||||
printf("jDirectionIncrementInDegrees=%g\n",jDirectionIncrementInDegrees);
|
||||
|
||||
/* get as a double*/
|
||||
GRIB_CHECK(grib_get_double(h,"iDirectionIncrementInDegrees",&iDirectionIncrementInDegrees),0);
|
||||
CODES_CHECK(codes_get_double(h,"iDirectionIncrementInDegrees",&iDirectionIncrementInDegrees),0);
|
||||
printf("iDirectionIncrementInDegrees=%g\n",iDirectionIncrementInDegrees);
|
||||
|
||||
/* get as string */
|
||||
GRIB_CHECK(grib_get_length(h, "packingType", &len), 0);
|
||||
CODES_CHECK(codes_get_length(h, "packingType", &len), 0);
|
||||
packingType = (char*)malloc(len*sizeof(char));
|
||||
grib_get_string(h, "packingType", packingType, &len);
|
||||
codes_get_string(h, "packingType", packingType, &len);
|
||||
printf("packingType=%s\n", packingType);
|
||||
free(packingType);
|
||||
|
||||
/* get the size of the values array*/
|
||||
GRIB_CHECK(grib_get_size(h,"values",&values_len),0);
|
||||
CODES_CHECK(codes_get_size(h,"values",&values_len),0);
|
||||
|
||||
values = (double*)malloc(values_len*sizeof(double));
|
||||
|
||||
/* get data values*/
|
||||
GRIB_CHECK(grib_get_double_array(h,"values",values,&values_len),0);
|
||||
CODES_CHECK(codes_get_double_array(h,"values",values,&values_len),0);
|
||||
|
||||
average = 0;
|
||||
for(i = 0; i < values_len; i++)
|
||||
|
@ -121,14 +121,14 @@ int main(int argc, char** argv)
|
|||
int eq = 0;
|
||||
/* Now retrieve the value of the key "file" */
|
||||
char file[256]={0,};
|
||||
GRIB_CHECK(grib_get_length(h, "file", &len),0);
|
||||
CODES_CHECK(codes_get_length(h, "file", &len),0);
|
||||
assert(len == 1+strlen(filename));
|
||||
grib_get_string(h, "file", file, &len);
|
||||
codes_get_string(h, "file", file, &len);
|
||||
eq = strcmp(file, filename);
|
||||
assert( eq == 0 );
|
||||
}
|
||||
|
||||
grib_handle_delete(h);
|
||||
codes_handle_delete(h);
|
||||
fclose(in);
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "grib_api.h"
|
||||
#include "eccodes.h"
|
||||
|
||||
int main (int argc, char **argv)
|
||||
{
|
||||
|
@ -25,7 +25,7 @@ int main (int argc, char **argv)
|
|||
size_t i = 0;
|
||||
FILE *in = NULL;
|
||||
const char *filename = "../../data/reduced_latlon_surface.grib1";
|
||||
grib_handle *h = NULL;
|
||||
codes_handle *h = NULL;
|
||||
long numberOfPoints = 0;
|
||||
const double missing = 9999.0;
|
||||
double *lats, *lons, *values; /* arrays */
|
||||
|
@ -37,14 +37,14 @@ int main (int argc, char **argv)
|
|||
}
|
||||
|
||||
/* create new handle from a message in a file */
|
||||
h = grib_handle_new_from_file (0, in, &err);
|
||||
h = codes_handle_new_from_file (0, in, &err);
|
||||
if (h == NULL) {
|
||||
printf ("Error: unable to create handle from file %s\n", filename);
|
||||
return 1;
|
||||
}
|
||||
|
||||
GRIB_CHECK (grib_get_long (h, "numberOfPoints", &numberOfPoints), 0);
|
||||
GRIB_CHECK (grib_set_double (h, "missingValue", missing), 0);
|
||||
CODES_CHECK (codes_get_long (h, "numberOfPoints", &numberOfPoints), 0);
|
||||
CODES_CHECK (codes_set_double (h, "missingValue", missing), 0);
|
||||
|
||||
lats = (double *) malloc (numberOfPoints * sizeof (double));
|
||||
if (!lats) {
|
||||
|
@ -65,7 +65,7 @@ int main (int argc, char **argv)
|
|||
return 1;
|
||||
}
|
||||
|
||||
GRIB_CHECK (grib_get_data (h, lats, lons, values, NULL), 0);
|
||||
CODES_CHECK (codes_get_data (h, lats, lons, values, NULL), 0);
|
||||
|
||||
for (i = 0; i < numberOfPoints; ++i) {
|
||||
if (values[i] != missing) {
|
||||
|
@ -76,7 +76,7 @@ int main (int argc, char **argv)
|
|||
free (lats);
|
||||
free (lons);
|
||||
free (values);
|
||||
grib_handle_delete (h);
|
||||
codes_handle_delete (h);
|
||||
|
||||
fclose (in);
|
||||
return 0;
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "grib_api.h"
|
||||
#include "eccodes.h"
|
||||
|
||||
void usage(const char* prog) {
|
||||
printf("usage: %s filename\n",prog);
|
||||
|
@ -39,7 +39,7 @@ int main(int argc, char** argv)
|
|||
|
||||
FILE* in = NULL;
|
||||
char* filename ;
|
||||
grib_handle *h = NULL;
|
||||
codes_handle *h = NULL;
|
||||
|
||||
if (argc<2) usage(argv[0]);
|
||||
filename=argv[1];
|
||||
|
@ -51,22 +51,22 @@ int main(int argc, char** argv)
|
|||
}
|
||||
|
||||
/* create new handle from a message in a file*/
|
||||
while((h = grib_handle_new_from_file(0,f,&err)) != NULL) {
|
||||
while((h = codes_handle_new_from_file(0,f,&err)) != NULL) {
|
||||
|
||||
/* get the size of the values array*/
|
||||
GRIB_CHECK(grib_get_size(h,"values",&values_len),0);
|
||||
CODES_CHECK(codes_get_size(h,"values",&values_len),0);
|
||||
|
||||
values = malloc(values_len*sizeof(double));
|
||||
|
||||
/* get data values*/
|
||||
GRIB_CHECK(grib_get_double_array(h,"values",values,&values_len),0);
|
||||
CODES_CHECK(codes_get_double_array(h,"values",values,&values_len),0);
|
||||
|
||||
for(i = 0; i < values_len; i++)
|
||||
printf("%d %.10e\n",i+1,values[i]);
|
||||
|
||||
free(values);
|
||||
|
||||
grib_handle_delete(h);
|
||||
codes_handle_delete(h);
|
||||
}
|
||||
|
||||
fclose(in);
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "grib_api.h"
|
||||
#include "eccodes.h"
|
||||
|
||||
void usage(const char* prog) {
|
||||
printf("Usage: %s grib_file\n",prog);
|
||||
|
@ -35,9 +35,9 @@ int main(int argc, char** argv)
|
|||
char* filename = NULL;
|
||||
|
||||
/* Message handle. Required in all the grib_api calls acting on a message.*/
|
||||
grib_handle *h = NULL;
|
||||
codes_handle *h = NULL;
|
||||
/* Iterator on lat/lon/values.*/
|
||||
grib_iterator* iter=NULL;
|
||||
codes_iterator* iter=NULL;
|
||||
|
||||
if (argc != 2) usage(argv[0]);
|
||||
|
||||
|
@ -50,20 +50,20 @@ int main(int argc, char** argv)
|
|||
}
|
||||
|
||||
/* Loop on all the messages in a file.*/
|
||||
while ((h = grib_handle_new_from_file(0,in,&err)) != NULL ) {
|
||||
while ((h = codes_handle_new_from_file(0,in,&err)) != NULL ) {
|
||||
/* Check of errors after reading a message. */
|
||||
if (err != GRIB_SUCCESS) GRIB_CHECK(err,0);
|
||||
if (err != CODES_SUCCESS) CODES_CHECK(err,0);
|
||||
|
||||
/* Get the double representing the missing value in the field. */
|
||||
GRIB_CHECK(grib_get_double(h,"missingValue",&missingValue),0);
|
||||
CODES_CHECK(codes_get_double(h,"missingValue",&missingValue),0);
|
||||
|
||||
/* A new iterator on lat/lon/values is created from the message handle h. */
|
||||
iter=grib_iterator_new(h,0,&err);
|
||||
if (err != GRIB_SUCCESS) GRIB_CHECK(err,0);
|
||||
iter=codes_iterator_new(h,0,&err);
|
||||
if (err != CODES_SUCCESS) CODES_CHECK(err,0);
|
||||
|
||||
n = 0;
|
||||
/* Loop on all the lat/lon/values. */
|
||||
while(grib_iterator_next(iter,&lat,&lon,&value)) {
|
||||
while(codes_iterator_next(iter,&lat,&lon,&value)) {
|
||||
/* You can now print lat and lon, */
|
||||
printf("- %d - lat=%f lon=%f value=",n,lat,lon);
|
||||
/* decide what to print if a missing value is found. */
|
||||
|
@ -74,10 +74,10 @@ int main(int argc, char** argv)
|
|||
}
|
||||
|
||||
/* At the end the iterator is deleted to free memory. */
|
||||
grib_iterator_delete(iter);
|
||||
codes_iterator_delete(iter);
|
||||
|
||||
/* At the end the grib_handle is deleted to free memory. */
|
||||
grib_handle_delete(h);
|
||||
/* At the end the codes_handle is deleted to free memory. */
|
||||
codes_handle_delete(h);
|
||||
}
|
||||
|
||||
fclose(in);
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
#include "grib_api.h"
|
||||
#include "eccodes.h"
|
||||
|
||||
void usage(char* prog)
|
||||
{
|
||||
|
@ -37,8 +37,8 @@ int main(int argc, char** argv)
|
|||
long bitmapPresent = 0;
|
||||
long *bitmap = NULL;
|
||||
double *values = NULL;
|
||||
grib_handle *h = NULL;
|
||||
grib_iterator* iter=NULL;
|
||||
codes_handle *h = NULL;
|
||||
codes_iterator* iter=NULL;
|
||||
|
||||
if (argc != 2) usage(argv[0]);
|
||||
filename=argv[1];
|
||||
|
@ -48,33 +48,33 @@ int main(int argc, char** argv)
|
|||
return 1;
|
||||
}
|
||||
|
||||
while ((h = grib_handle_new_from_file(0,in,&err)) != NULL )
|
||||
while ((h = codes_handle_new_from_file(0,in,&err)) != NULL )
|
||||
{
|
||||
if (err != GRIB_SUCCESS) GRIB_CHECK(err,0);
|
||||
if (err != CODES_SUCCESS) CODES_CHECK(err,0);
|
||||
|
||||
GRIB_CHECK(grib_get_long(h,"bitmapPresent",&bitmapPresent),0);
|
||||
CODES_CHECK(codes_get_long(h,"bitmapPresent",&bitmapPresent),0);
|
||||
if (bitmapPresent)
|
||||
{
|
||||
GRIB_CHECK(grib_get_size(h,"bitmap",&bmp_len),0);
|
||||
CODES_CHECK(codes_get_size(h,"bitmap",&bmp_len),0);
|
||||
bitmap = (long*)malloc(bmp_len*sizeof(long));
|
||||
GRIB_CHECK(grib_get_long_array(h,"bitmap",bitmap,&bmp_len),0);
|
||||
CODES_CHECK(codes_get_long_array(h,"bitmap",bitmap,&bmp_len),0);
|
||||
printf("Bitmap is present. Num = %ld\n", bmp_len);
|
||||
}
|
||||
/* Sanity check. Number of values must match number in bitmap */
|
||||
GRIB_CHECK(grib_get_size(h,"values",&values_len),0);
|
||||
CODES_CHECK(codes_get_size(h,"values",&values_len),0);
|
||||
values = (double*)malloc(values_len*sizeof(double));
|
||||
GRIB_CHECK(grib_get_double_array(h,"values",values,&values_len),0);
|
||||
CODES_CHECK(codes_get_double_array(h,"values",values,&values_len),0);
|
||||
if (bitmapPresent) {
|
||||
assert(values_len==bmp_len);
|
||||
}
|
||||
|
||||
/* A new iterator on lat/lon/values is created from the message handle h */
|
||||
iter=grib_iterator_new(h,0,&err);
|
||||
if (err != GRIB_SUCCESS) GRIB_CHECK(err,0);
|
||||
iter=codes_iterator_new(h,0,&err);
|
||||
if (err != CODES_SUCCESS) CODES_CHECK(err,0);
|
||||
|
||||
n = 0;
|
||||
/* Loop on all the lat/lon/values. Only print non-missing values */
|
||||
while(grib_iterator_next(iter,&lat,&lon,&value))
|
||||
while(codes_iterator_next(iter,&lat,&lon,&value))
|
||||
{
|
||||
int is_missing_val = (bitmapPresent && bitmap[n] == 0);
|
||||
if (!is_missing_val) {
|
||||
|
@ -85,8 +85,8 @@ int main(int argc, char** argv)
|
|||
/* Check number of elements in iterator matches value count */
|
||||
assert(n == values_len);
|
||||
|
||||
grib_iterator_delete(iter);
|
||||
grib_handle_delete(h);
|
||||
codes_iterator_delete(iter);
|
||||
codes_handle_delete(h);
|
||||
}
|
||||
|
||||
fclose(in);
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
*
|
||||
* Description:
|
||||
* Example on how to use keys_iterator functions and the
|
||||
* grib_keys_iterator structure to get all the available
|
||||
* codes_keys_iterator structure to get all the available
|
||||
* keys in a message.
|
||||
*
|
||||
*/
|
||||
|
@ -24,7 +24,7 @@
|
|||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "grib_api.h"
|
||||
#include "eccodes.h"
|
||||
|
||||
#define MAX_KEY_LEN 255
|
||||
#define MAX_VAL_LEN 1024
|
||||
|
@ -34,10 +34,10 @@ static void usage(char* progname);
|
|||
int main(int argc, char *argv[])
|
||||
{
|
||||
/* To skip read only and not coded keys
|
||||
unsigned long key_iterator_filter_flags=GRIB_KEYS_ITERATOR_SKIP_READ_ONLY ||
|
||||
GRIB_KEYS_ITERATOR_SKIP_COMPUTED;
|
||||
unsigned long key_iterator_filter_flags=CODES_KEYS_ITERATOR_SKIP_READ_ONLY ||
|
||||
CODES_KEYS_ITERATOR_SKIP_COMPUTED;
|
||||
*/
|
||||
unsigned long key_iterator_filter_flags=GRIB_KEYS_ITERATOR_ALL_KEYS;
|
||||
unsigned long key_iterator_filter_flags=CODES_KEYS_ITERATOR_ALL_KEYS;
|
||||
|
||||
/* Choose a namespace. E.g. "ls", "time", "parameter", "geography", "statistics" */
|
||||
char* name_space="ls";
|
||||
|
@ -46,10 +46,10 @@ int main(int argc, char *argv[])
|
|||
/* char* name_space=0; */
|
||||
|
||||
FILE* f;
|
||||
grib_handle* h=NULL;
|
||||
codes_handle* h=NULL;
|
||||
|
||||
int err=0;
|
||||
int grib_count=0;
|
||||
int msg_count=0;
|
||||
|
||||
char value[MAX_VAL_LEN];
|
||||
size_t vlen=MAX_VAL_LEN;
|
||||
|
@ -62,36 +62,36 @@ int main(int argc, char *argv[])
|
|||
exit(1);
|
||||
}
|
||||
|
||||
while((h = grib_handle_new_from_file(0,f,&err)) != NULL)
|
||||
while((h = codes_handle_new_from_file(0,f,&err)) != NULL)
|
||||
{
|
||||
grib_keys_iterator* kiter=NULL;
|
||||
grib_count++;
|
||||
printf("-- GRIB N. %d --\n",grib_count);
|
||||
codes_keys_iterator* kiter=NULL;
|
||||
msg_count++;
|
||||
printf("-- GRIB N. %d --\n",msg_count);
|
||||
if(!h) {
|
||||
printf("ERROR: Unable to create grib handle\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
kiter=grib_keys_iterator_new(h,key_iterator_filter_flags,name_space);
|
||||
kiter=codes_keys_iterator_new(h,key_iterator_filter_flags,name_space);
|
||||
if (!kiter) {
|
||||
printf("ERROR: Unable to create keys iterator\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
while(grib_keys_iterator_next(kiter))
|
||||
while(codes_keys_iterator_next(kiter))
|
||||
{
|
||||
const char* name = grib_keys_iterator_get_name(kiter);
|
||||
const char* name = codes_keys_iterator_get_name(kiter);
|
||||
vlen=MAX_VAL_LEN;
|
||||
bzero(value,vlen);
|
||||
GRIB_CHECK(grib_get_string(h,name,value,&vlen),name);
|
||||
CODES_CHECK(codes_get_string(h,name,value,&vlen),name);
|
||||
printf("%s = %s\n",name,value);
|
||||
|
||||
/* Alternative way of getting the string value */
|
||||
GRIB_CHECK(grib_keys_iterator_get_string(kiter, value, &vlen),0);
|
||||
CODES_CHECK(codes_keys_iterator_get_string(kiter, value, &vlen),0);
|
||||
}
|
||||
|
||||
grib_keys_iterator_delete(kiter);
|
||||
grib_handle_delete(h);
|
||||
codes_keys_iterator_delete(kiter);
|
||||
codes_handle_delete(h);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "grib_api.h"
|
||||
#include "eccodes.h"
|
||||
|
||||
/* See JIRA issue GRIB-361 */
|
||||
int main()
|
||||
|
@ -19,7 +19,7 @@ int main()
|
|||
const int nj = 2880;
|
||||
double *values;
|
||||
int i = 0;
|
||||
grib_handle *h = NULL;
|
||||
codes_handle *h = NULL;
|
||||
char* filename = "bigfile.grib";
|
||||
|
||||
values = (double*) malloc(ni*nj*sizeof(double));
|
||||
|
@ -33,39 +33,39 @@ int main()
|
|||
values[i] = 10*rand;
|
||||
}
|
||||
|
||||
h = grib_handle_new_from_samples(0, "GRIB1");
|
||||
h = codes_handle_new_from_samples(0, "GRIB1");
|
||||
|
||||
GRIB_CHECK(grib_set_long(h, "Ni", ni), 0);
|
||||
GRIB_CHECK(grib_set_long(h, "Nj", nj), 0);
|
||||
GRIB_CHECK(grib_set_long(h, "centre", 86), 0);
|
||||
GRIB_CHECK(grib_set_long(h, "process", 100), 0);
|
||||
GRIB_CHECK(grib_set_long(h, "indicatorOfTypeOfLevel", 105), 0);
|
||||
GRIB_CHECK(grib_set_long(h, "level", 2), 0);
|
||||
GRIB_CHECK(grib_set_long(h, "indicatorOfParameter", 1), 0);
|
||||
GRIB_CHECK(grib_set_long(h, "table2Version", 1), 0);
|
||||
GRIB_CHECK(grib_set_long(h, "dataDate", 20130424), 0);
|
||||
GRIB_CHECK(grib_set_long(h, "dataTime", 0), 0);
|
||||
GRIB_CHECK(grib_set_long(h, "startStep", 0), 0);
|
||||
GRIB_CHECK(grib_set_long(h, "endStep", 0), 0);
|
||||
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);
|
||||
|
||||
GRIB_CHECK(grib_set_long(h, "bitmapPresent", 1), 0);
|
||||
CODES_CHECK(codes_set_long(h, "bitmapPresent", 1), 0);
|
||||
|
||||
GRIB_CHECK(grib_set_double(h, "iDirectionIncrementInDegrees", 0.125), 0);
|
||||
GRIB_CHECK(grib_set_double(h, "jDirectionIncrementInDegrees", 0.125), 0);
|
||||
GRIB_CHECK(grib_set_long(h, "iScansNegatively", 0), 0);
|
||||
GRIB_CHECK(grib_set_long(h, "jScansPositively", 1), 0);
|
||||
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);
|
||||
|
||||
GRIB_CHECK(grib_set_double(h, "latitudeOfFirstGridPointInDegrees", -90), 0);
|
||||
GRIB_CHECK(grib_set_double(h, "latitudeOfLastGridPointInDegrees", 90), 0);
|
||||
GRIB_CHECK(grib_set_double(h, "longitudeOfFirstGridPointInDegrees", -180), 0);
|
||||
GRIB_CHECK(grib_set_double(h, "longitudeOfLastGridPointInDegrees", 180), 0);
|
||||
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);
|
||||
|
||||
GRIB_CHECK(grib_set_double_array(h, "values", values, ni*nj), 0);
|
||||
CODES_CHECK(codes_set_double_array(h, "values", values, ni*nj), 0);
|
||||
|
||||
grib_write_message(h, filename, "w");
|
||||
codes_write_message(h, filename, "w");
|
||||
/*printf("Wrote file %s\n", filename);*/
|
||||
|
||||
grib_handle_delete(h);
|
||||
codes_handle_delete(h);
|
||||
free (values);
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include "grib_api.h"
|
||||
#include "eccodes.h"
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
|
@ -34,7 +34,7 @@ int main(int argc, char** argv)
|
|||
|
||||
FILE* in = NULL;
|
||||
char* filename = "../../data/satellite.grib";
|
||||
grib_handle *h = NULL;
|
||||
codes_handle *h = NULL;
|
||||
|
||||
in = fopen(filename,"r");
|
||||
if(!in) {
|
||||
|
@ -43,34 +43,34 @@ int main(int argc, char** argv)
|
|||
}
|
||||
|
||||
/* create new handle from a message in a file*/
|
||||
h = grib_handle_new_from_file(0,in,&err);
|
||||
h = codes_handle_new_from_file(0,in,&err);
|
||||
if (h == NULL) {
|
||||
printf("Error: unable to create handle from file %s\n",filename);
|
||||
}
|
||||
|
||||
GRIB_CHECK(grib_get_long(h,"numberOfContributingSpectralBands",&numberOfContributingSpectralBands),0);
|
||||
CODES_CHECK(codes_get_long(h,"numberOfContributingSpectralBands",&numberOfContributingSpectralBands),0);
|
||||
assert(numberOfContributingSpectralBands == 3);
|
||||
|
||||
/* Shrink NB to 2 */
|
||||
numberOfContributingSpectralBands = 2;
|
||||
GRIB_CHECK(grib_set_long(h,"numberOfContributingSpectralBands",numberOfContributingSpectralBands),0);
|
||||
CODES_CHECK(codes_set_long(h,"numberOfContributingSpectralBands",numberOfContributingSpectralBands),0);
|
||||
|
||||
/* Expand NB to 9 */
|
||||
numberOfContributingSpectralBands = 9;
|
||||
GRIB_CHECK(grib_set_long(h,"numberOfContributingSpectralBands",numberOfContributingSpectralBands),0);
|
||||
CODES_CHECK(codes_set_long(h,"numberOfContributingSpectralBands",numberOfContributingSpectralBands),0);
|
||||
|
||||
/* get as a long*/
|
||||
GRIB_CHECK(grib_get_long(h,"numberOfContributingSpectralBands",&numberOfContributingSpectralBands),0);
|
||||
CODES_CHECK(codes_get_long(h,"numberOfContributingSpectralBands",&numberOfContributingSpectralBands),0);
|
||||
printf("numberOfContributingSpectralBands=%ld\n",numberOfContributingSpectralBands);
|
||||
|
||||
/* get as a long*/
|
||||
GRIB_CHECK(grib_get_size(h,"scaledValueOfCentralWaveNumber",&count),0);
|
||||
CODES_CHECK(codes_get_size(h,"scaledValueOfCentralWaveNumber",&count),0);
|
||||
printf("count=%ld\n",(long)count);
|
||||
|
||||
assert(count < sizeof(values)/sizeof(values[0]));
|
||||
|
||||
size = count;
|
||||
GRIB_CHECK(grib_get_long_array(h,"scaledValueOfCentralWaveNumber",values,&size),0);
|
||||
CODES_CHECK(codes_get_long_array(h,"scaledValueOfCentralWaveNumber",values,&size),0);
|
||||
assert(size == count);
|
||||
|
||||
for(i=0;i<count;i++) {
|
||||
|
@ -84,18 +84,18 @@ int main(int argc, char** argv)
|
|||
|
||||
size = count;
|
||||
/* size--; */
|
||||
GRIB_CHECK(grib_set_long_array(h,"scaledValueOfCentralWaveNumber",values,size),0);
|
||||
CODES_CHECK(codes_set_long_array(h,"scaledValueOfCentralWaveNumber",values,size),0);
|
||||
assert(size == count);
|
||||
|
||||
/* check what we set */
|
||||
GRIB_CHECK(grib_get_long_array(h,"scaledValueOfCentralWaveNumber",new_values,&size),0);
|
||||
CODES_CHECK(codes_get_long_array(h,"scaledValueOfCentralWaveNumber",new_values,&size),0);
|
||||
assert(size == count);
|
||||
for(i=0;i<count;i++) {
|
||||
printf("Now scaledValueOfCentralWaveNumber %lu = %ld\n",(unsigned long)i,new_values[i]);
|
||||
assert( new_values[i] == (i+1000) );
|
||||
}
|
||||
|
||||
grib_handle_delete(h);
|
||||
codes_handle_delete(h);
|
||||
|
||||
fclose(in);
|
||||
return 0;
|
||||
|
|
|
@ -17,18 +17,18 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "grib_api.h"
|
||||
#include "eccodes.h"
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
grib_string_list* list;
|
||||
grib_string_list* list2;
|
||||
codes_string_list* list;
|
||||
codes_string_list* list2;
|
||||
|
||||
list=grib_util_get_param_id("11.2");
|
||||
list=codes_util_get_param_id("11.2");
|
||||
printf("mars.param=11.2 -> paramId= ");
|
||||
while (list) {
|
||||
printf("%s ",list->value);
|
||||
list2=grib_util_get_param_id("130.128");
|
||||
list2=codes_util_get_param_id("130.128");
|
||||
printf("mars.param=11.2 -> paramId= ");
|
||||
while (list2) {
|
||||
printf("%s ",list2->value);
|
||||
|
@ -40,7 +40,7 @@ int main(int argc, char** argv)
|
|||
printf("\n");
|
||||
|
||||
printf("paramId=130 -> mars.param= ");
|
||||
list=grib_util_get_mars_param("130");
|
||||
list=codes_util_get_mars_param("130");
|
||||
while (list) {
|
||||
printf("%s ",list->value);
|
||||
list=list->next;
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "grib_api.h"
|
||||
#include "eccodes.h"
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
|
@ -29,13 +29,13 @@ int main(int argc, char** argv)
|
|||
long parameterCategory=0,parameterNumber=0,discipline=0;
|
||||
FILE* in = NULL;
|
||||
char* filename = "../../data/multi.grib2";
|
||||
grib_handle *h = NULL;
|
||||
codes_handle *h = NULL;
|
||||
|
||||
/* turn on support for multi fields messages */
|
||||
grib_multi_support_on(0);
|
||||
codes_multi_support_on(0);
|
||||
|
||||
/* turn off support for multi fields messages */
|
||||
/* grib_multi_support_off(0); */
|
||||
/* codes_multi_support_off(0); */
|
||||
|
||||
in = fopen(filename,"r");
|
||||
if(!in) {
|
||||
|
@ -43,24 +43,24 @@ int main(int argc, char** argv)
|
|||
return 1;
|
||||
}
|
||||
|
||||
while ((h = grib_handle_new_from_file(0,in,&err)) != NULL ) {
|
||||
while ((h = codes_handle_new_from_file(0,in,&err)) != NULL ) {
|
||||
|
||||
GRIB_CHECK(err,0);
|
||||
CODES_CHECK(err,0);
|
||||
|
||||
GRIB_CHECK(grib_get_long(h,"discipline",&discipline),0);
|
||||
CODES_CHECK(codes_get_long(h,"discipline",&discipline),0);
|
||||
printf("discipline=%ld\n",discipline);
|
||||
|
||||
GRIB_CHECK(grib_get_long(h,"parameterCategory",¶meterCategory),0);
|
||||
CODES_CHECK(codes_get_long(h,"parameterCategory",¶meterCategory),0);
|
||||
printf("parameterCategory=%ld\n",parameterCategory);
|
||||
|
||||
GRIB_CHECK(grib_get_long(h,"parameterNumber",¶meterNumber),0);
|
||||
CODES_CHECK(codes_get_long(h,"parameterNumber",¶meterNumber),0);
|
||||
printf("parameterNumber=%ld\n",parameterNumber);
|
||||
|
||||
if ( discipline == 0 && parameterCategory==2) {
|
||||
if (parameterNumber == 2) printf("-------- u -------\n");
|
||||
if (parameterNumber == 3) printf("-------- v -------\n");
|
||||
}
|
||||
grib_handle_delete(h);
|
||||
codes_handle_delete(h);
|
||||
}
|
||||
|
||||
fclose(in);
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
#include "grib_api.h"
|
||||
#include "eccodes.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
@ -32,7 +32,7 @@ int main(int argc, char** argv)
|
|||
int i;
|
||||
|
||||
/* turn on support for multi fields messages */
|
||||
grib_multi_support_on(0);
|
||||
codes_multi_support_on(0);
|
||||
|
||||
for(i=1; i<COUNT; ++i) {
|
||||
printf("Pass %d: \n",i);
|
||||
|
@ -46,7 +46,7 @@ void read_data(int num_msgs)
|
|||
int err = 0,i;
|
||||
FILE* fp = NULL;
|
||||
long stepRange = 0;
|
||||
grib_handle *h = NULL;
|
||||
codes_handle *h = NULL;
|
||||
|
||||
fp = fopen(file_path, "r");
|
||||
if(!fp) {
|
||||
|
@ -55,12 +55,12 @@ void read_data(int num_msgs)
|
|||
}
|
||||
printf("Opened GRIB file %s: \n", file_path);
|
||||
for(i=0; i<num_msgs; ++i) {
|
||||
h = grib_handle_new_from_file(0, fp, &err);
|
||||
GRIB_CHECK(err, 0);
|
||||
h = codes_handle_new_from_file(0, fp, &err);
|
||||
CODES_CHECK(err, 0);
|
||||
|
||||
GRIB_CHECK( grib_get_long(h, "stepRange", &stepRange), 0);
|
||||
CODES_CHECK( codes_get_long(h, "stepRange", &stepRange), 0);
|
||||
printf("%d : stepRange=%ld\n", i, stepRange);
|
||||
grib_handle_delete(h);
|
||||
codes_handle_delete(h);
|
||||
/* These tests make sure we always start from 1st field of the grib msg */
|
||||
/* and not where we left off last time */
|
||||
if (i == 0) assert(stepRange == 0); /* 1st field */
|
||||
|
@ -69,6 +69,6 @@ void read_data(int num_msgs)
|
|||
if (i == 3) assert(stepRange == 36); /* 4th field */
|
||||
}
|
||||
/* Must reset this file pointer for the next round */
|
||||
grib_multi_support_reset_file(grib_context_get_default(), fp);
|
||||
codes_multi_support_reset_file(codes_context_get_default(), fp);
|
||||
fclose(fp);
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
#include "grib_api.h"
|
||||
#include "eccodes.h"
|
||||
|
||||
void usage(const char* prog) {
|
||||
printf("usage: %s in.grib out.grib\n",prog);
|
||||
|
@ -32,8 +32,8 @@ int main(int argc, char** argv)
|
|||
long edition, step;
|
||||
char* filename=NULL;
|
||||
char* ofilename=NULL;
|
||||
grib_handle *h = NULL;
|
||||
grib_multi_handle *mh=NULL;
|
||||
codes_handle *h = NULL;
|
||||
codes_multi_handle *mh=NULL;
|
||||
const int start_section = 4; /* Grib2 Product Definition Section */
|
||||
|
||||
if (argc < 3) usage(argv[0]);
|
||||
|
@ -48,16 +48,16 @@ int main(int argc, char** argv)
|
|||
}
|
||||
|
||||
/* new grib handle from input file */
|
||||
h = grib_handle_new_from_file(0,in,&err);
|
||||
GRIB_CHECK(err,0);
|
||||
GRIB_CHECK(grib_get_long(h,"edition",&edition),0);
|
||||
h = codes_handle_new_from_file(0,in,&err);
|
||||
CODES_CHECK(err,0);
|
||||
CODES_CHECK(codes_get_long(h,"edition",&edition),0);
|
||||
if (edition != 2) {
|
||||
fprintf(stderr, "ERROR: Input grib must be edition 2 for multi fields\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/* create a new empty multi field handle */
|
||||
mh=grib_multi_handle_new(0);
|
||||
mh=codes_multi_handle_new(0);
|
||||
if (!mh) {
|
||||
fprintf(stderr,"ERROR: Unable to create multi field handle\n");
|
||||
exit(1);
|
||||
|
@ -65,10 +65,10 @@ int main(int argc, char** argv)
|
|||
|
||||
for (step=12;step<=120;step+=12) {
|
||||
/* set step */
|
||||
grib_set_long(h,"step",step);
|
||||
codes_set_long(h,"step",step);
|
||||
/* append h to mh repeating from section 4 */
|
||||
/* i.e. starting from section 4 all the sections to the end of the message will be copied */
|
||||
grib_multi_handle_append(h, start_section, mh);
|
||||
codes_multi_handle_append(h, start_section, mh);
|
||||
}
|
||||
|
||||
/* open output file */
|
||||
|
@ -79,12 +79,12 @@ int main(int argc, char** argv)
|
|||
}
|
||||
|
||||
/* write multi fields handle to output file */
|
||||
grib_multi_handle_write(mh,of);
|
||||
codes_multi_handle_write(mh,of);
|
||||
fclose(of);
|
||||
|
||||
/* release memory */
|
||||
grib_handle_delete(h);
|
||||
grib_multi_handle_delete(mh);
|
||||
codes_handle_delete(h);
|
||||
codes_multi_handle_delete(mh);
|
||||
|
||||
fclose(in);
|
||||
return 0;
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
* 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.h"
|
||||
#include "eccodes.h"
|
||||
|
||||
void usage(char* prog) {
|
||||
printf("usage: %s in.nc\n",prog);
|
||||
|
@ -18,19 +18,19 @@ int main(int argc,char* argv[]) {
|
|||
|
||||
char* file;
|
||||
int err=0;
|
||||
grib_handle* h;
|
||||
codes_handle* h;
|
||||
char identifier[7]={0,};
|
||||
size_t len=7;
|
||||
grib_context* c=grib_context_get_default();
|
||||
codes_context* c=codes_context_get_default();
|
||||
|
||||
if (argc>2) usage(argv[0]);
|
||||
|
||||
file=argv[1];
|
||||
|
||||
h=grib_handle_new_from_nc_file(c,file,&err);
|
||||
grib_get_string(h,"identifier",identifier,&len);
|
||||
h=codes_handle_new_from_nc_file(c,file,&err);
|
||||
codes_get_string(h,"identifier",identifier,&len);
|
||||
printf("%s\n",identifier);
|
||||
GRIB_CHECK(err,0);
|
||||
CODES_CHECK(err,0);
|
||||
|
||||
return err;
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "grib_api.h"
|
||||
#include "eccodes.h"
|
||||
|
||||
void usage(const char* prog) {
|
||||
printf("Usage: %s grib_file grib_file ...\n",prog);
|
||||
|
@ -31,8 +31,8 @@ int main(int argc, char** argv)
|
|||
long step=0;
|
||||
size_t nfiles;
|
||||
int i=0;
|
||||
grib_fieldset* set=NULL;
|
||||
grib_handle* h=NULL;
|
||||
codes_fieldset* set=NULL;
|
||||
codes_handle* h=NULL;
|
||||
char param[20]={0,};
|
||||
size_t len=20;
|
||||
double lats[4]={0,};
|
||||
|
@ -47,7 +47,7 @@ int main(int argc, char** argv)
|
|||
int mode=0;
|
||||
int count;
|
||||
char** filenames;
|
||||
grib_nearest* nearest=NULL;
|
||||
codes_nearest* nearest=NULL;
|
||||
|
||||
if (argc < 2) usage(argv[0]);
|
||||
|
||||
|
@ -56,35 +56,35 @@ int main(int argc, char** argv)
|
|||
for (i=0;i<nfiles;i++)
|
||||
filenames[i]=(char*)strdup(argv[i+1]);
|
||||
|
||||
set=grib_fieldset_new_from_files(0,filenames,nfiles,0,0,0,order_by,&err);
|
||||
GRIB_CHECK(err,0);
|
||||
set=codes_fieldset_new_from_files(0,filenames,nfiles,0,0,0,order_by,&err);
|
||||
CODES_CHECK(err,0);
|
||||
|
||||
printf("\nordering by %s\n",order_by);
|
||||
printf("\n%d fields in the fieldset\n",grib_fieldset_count(set));
|
||||
printf("\n%d fields in the fieldset\n",codes_fieldset_count(set));
|
||||
printf("n,step,param\n");
|
||||
|
||||
mode=GRIB_NEAREST_SAME_GRID | GRIB_NEAREST_SAME_POINT;
|
||||
mode=CODES_NEAREST_SAME_GRID | CODES_NEAREST_SAME_POINT;
|
||||
count=1;
|
||||
while ((h=grib_fieldset_next_handle(set,&err))!=NULL) {
|
||||
GRIB_CHECK(grib_get_long(h,"step",&step),0);
|
||||
while ((h=codes_fieldset_next_handle(set,&err))!=NULL) {
|
||||
CODES_CHECK(codes_get_long(h,"step",&step),0);
|
||||
len=20;
|
||||
GRIB_CHECK(grib_get_string(h,"param",param,&len),0);
|
||||
CODES_CHECK(codes_get_string(h,"param",param,&len),0);
|
||||
|
||||
printf("%d %ld %s ",count,step,param);
|
||||
if (!nearest) nearest=grib_nearest_new(h,&err);
|
||||
GRIB_CHECK(err,0);
|
||||
GRIB_CHECK(grib_nearest_find(nearest,h,lat,lon,mode,lats,lons,values,distances,indexes,&size),0);
|
||||
if (!nearest) nearest=codes_nearest_new(h,&err);
|
||||
CODES_CHECK(err,0);
|
||||
CODES_CHECK(codes_nearest_find(nearest,h,lat,lon,mode,lats,lons,values,distances,indexes,&size),0);
|
||||
for (i=0;i<4;i++) printf("%d %.2f %.2f %g %g - ",
|
||||
(int)indexes[i],lats[i],lons[i],distances[i],values[i]);
|
||||
printf("\n");
|
||||
|
||||
grib_handle_delete(h);
|
||||
codes_handle_delete(h);
|
||||
count++;
|
||||
}
|
||||
|
||||
if (nearest) grib_nearest_delete(nearest);
|
||||
if (nearest) codes_nearest_delete(nearest);
|
||||
|
||||
if (set) grib_fieldset_delete(set);
|
||||
if (set) codes_fieldset_delete(set);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
#include <grib_api.h>
|
||||
#include <eccodes.h>
|
||||
|
||||
/* This code was generated automatically */
|
||||
|
||||
|
||||
int main(int argc,const char** argv)
|
||||
{
|
||||
grib_handle *h = NULL;
|
||||
codes_handle *h = NULL;
|
||||
size_t size = 0;
|
||||
double* vdouble = NULL;
|
||||
FILE* f = NULL;
|
||||
|
@ -16,113 +16,112 @@ int main(int argc,const char** argv)
|
|||
exit(1);
|
||||
}
|
||||
|
||||
h = grib_handle_new_from_samples(NULL,"GRIB2");
|
||||
h = codes_handle_new_from_samples(NULL,"GRIB2");
|
||||
if(!h) {
|
||||
fprintf(stderr,"Cannot create grib handle\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
GRIB_CHECK(grib_set_long(h,"parametersVersion",1),0);
|
||||
GRIB_CHECK(grib_set_long(h,"truncateLaplacian",0),0);
|
||||
GRIB_CHECK(grib_set_long(h,"truncateDegrees",0),0);
|
||||
GRIB_CHECK(grib_set_long(h,"dummy",1),0);
|
||||
GRIB_CHECK(grib_set_long(h,"changingPrecision",0),0);
|
||||
GRIB_CHECK(grib_set_long(h,"unitsFactor",1),0);
|
||||
GRIB_CHECK(grib_set_long(h,"unitsBias",0),0);
|
||||
GRIB_CHECK(grib_set_long(h,"timeRangeIndicatorFromStepRange",-1),0);
|
||||
GRIB_CHECK(grib_set_long(h,"missingValue",9999),0);
|
||||
CODES_CHECK(codes_set_long(h,"parametersVersion",1),0);
|
||||
CODES_CHECK(codes_set_long(h,"truncateLaplacian",0),0);
|
||||
CODES_CHECK(codes_set_long(h,"truncateDegrees",0),0);
|
||||
CODES_CHECK(codes_set_long(h,"dummy",1),0);
|
||||
CODES_CHECK(codes_set_long(h,"changingPrecision",0),0);
|
||||
CODES_CHECK(codes_set_long(h,"unitsFactor",1),0);
|
||||
CODES_CHECK(codes_set_long(h,"unitsBias",0),0);
|
||||
CODES_CHECK(codes_set_long(h,"timeRangeIndicatorFromStepRange",-1),0);
|
||||
CODES_CHECK(codes_set_long(h,"missingValue",9999),0);
|
||||
|
||||
/* 0 = Meteorological products (grib2/tables/4/0.0.table) */
|
||||
GRIB_CHECK(grib_set_long(h,"discipline",0),0);
|
||||
CODES_CHECK(codes_set_long(h,"discipline",0),0);
|
||||
|
||||
GRIB_CHECK(grib_set_long(h,"editionNumber",2),0);
|
||||
CODES_CHECK(codes_set_long(h,"editionNumber",2),0);
|
||||
|
||||
/* 98 = European Center for Medium-Range Weather Forecasts (grib1/0.table) */
|
||||
GRIB_CHECK(grib_set_long(h,"centre",98),0);
|
||||
CODES_CHECK(codes_set_long(h,"centre",98),0);
|
||||
|
||||
GRIB_CHECK(grib_set_long(h,"subCentre",0),0);
|
||||
CODES_CHECK(codes_set_long(h,"subCentre",0),0);
|
||||
|
||||
/* 4 = Version implemented on 7 November 2007 (grib2/tables/1.0.table) */
|
||||
GRIB_CHECK(grib_set_long(h,"tablesVersion",4),0);
|
||||
CODES_CHECK(codes_set_long(h,"tablesVersion",4),0);
|
||||
|
||||
|
||||
/* 0 = Local tables not used (grib2/tables/4/1.1.table) */
|
||||
GRIB_CHECK(grib_set_long(h,"localTablesVersion",0),0);
|
||||
CODES_CHECK(codes_set_long(h,"localTablesVersion",0),0);
|
||||
|
||||
|
||||
/* 1 = Start of forecast (grib2/tables/4/1.2.table) */
|
||||
GRIB_CHECK(grib_set_long(h,"significanceOfReferenceTime",1),0);
|
||||
CODES_CHECK(codes_set_long(h,"significanceOfReferenceTime",1),0);
|
||||
|
||||
GRIB_CHECK(grib_set_long(h,"year",2007),0);
|
||||
GRIB_CHECK(grib_set_long(h,"month",3),0);
|
||||
GRIB_CHECK(grib_set_long(h,"day",23),0);
|
||||
GRIB_CHECK(grib_set_long(h,"hour",12),0);
|
||||
GRIB_CHECK(grib_set_long(h,"minute",0),0);
|
||||
GRIB_CHECK(grib_set_long(h,"second",0),0);
|
||||
GRIB_CHECK(grib_set_long(h,"dataDate",20070323),0);
|
||||
GRIB_CHECK(grib_set_long(h,"dataTime",1200),0);
|
||||
CODES_CHECK(codes_set_long(h,"year",2007),0);
|
||||
CODES_CHECK(codes_set_long(h,"month",3),0);
|
||||
CODES_CHECK(codes_set_long(h,"day",23),0);
|
||||
CODES_CHECK(codes_set_long(h,"hour",12),0);
|
||||
CODES_CHECK(codes_set_long(h,"minute",0),0);
|
||||
CODES_CHECK(codes_set_long(h,"second",0),0);
|
||||
CODES_CHECK(codes_set_long(h,"dataDate",20070323),0);
|
||||
CODES_CHECK(codes_set_long(h,"dataTime",1200),0);
|
||||
|
||||
/* 0 = Operational products (grib2/tables/4/1.3.table) */
|
||||
GRIB_CHECK(grib_set_long(h,"productionStatusOfProcessedData",0),0);
|
||||
|
||||
CODES_CHECK(codes_set_long(h,"productionStatusOfProcessedData",0),0);
|
||||
|
||||
/* 2 = Analysis and forecast products (grib2/tables/4/1.4.table) */
|
||||
GRIB_CHECK(grib_set_long(h,"typeOfProcessedData",2),0);
|
||||
CODES_CHECK(codes_set_long(h,"typeOfProcessedData",2),0);
|
||||
|
||||
GRIB_CHECK(grib_set_long(h,"selectStepTemplateInterval",1),0);
|
||||
GRIB_CHECK(grib_set_long(h,"selectStepTemplateInstant",1),0);
|
||||
GRIB_CHECK(grib_set_long(h,"grib2LocalSectionPresent",0),0);
|
||||
CODES_CHECK(codes_set_long(h,"selectStepTemplateInterval",1),0);
|
||||
CODES_CHECK(codes_set_long(h,"selectStepTemplateInstant",1),0);
|
||||
CODES_CHECK(codes_set_long(h,"grib2LocalSectionPresent",0),0);
|
||||
|
||||
/* 0 = Specified in Code table 3.1 (grib2/tables/4/3.0.table) */
|
||||
GRIB_CHECK(grib_set_long(h,"sourceOfGridDefinition",0),0);
|
||||
CODES_CHECK(codes_set_long(h,"sourceOfGridDefinition",0),0);
|
||||
|
||||
GRIB_CHECK(grib_set_long(h,"numberOfDataPoints",496),0);
|
||||
GRIB_CHECK(grib_set_long(h,"numberOfOctectsForNumberOfPoints",0),0);
|
||||
CODES_CHECK(codes_set_long(h,"numberOfDataPoints",496),0);
|
||||
CODES_CHECK(codes_set_long(h,"numberOfOctectsForNumberOfPoints",0),0);
|
||||
|
||||
/* 0 = There is no appended list (grib2/tables/4/3.11.table) */
|
||||
GRIB_CHECK(grib_set_long(h,"interpretationOfNumberOfPoints",0),0);
|
||||
CODES_CHECK(codes_set_long(h,"interpretationOfNumberOfPoints",0),0);
|
||||
|
||||
GRIB_CHECK(grib_set_long(h,"PLPresent",0),0);
|
||||
CODES_CHECK(codes_set_long(h,"PLPresent",0),0);
|
||||
|
||||
/* 0 = Latitude/longitude. Also called equidistant cylindrical, or Plate Carree (grib2/tables/4/3.1.table) */
|
||||
GRIB_CHECK(grib_set_long(h,"gridDefinitionTemplateNumber",0),0);
|
||||
CODES_CHECK(codes_set_long(h,"gridDefinitionTemplateNumber",0),0);
|
||||
|
||||
|
||||
/* 0 = Earth assumed spherical with radius = 6,367,470.0 m (grib2/tables/4/3.2.table) */
|
||||
GRIB_CHECK(grib_set_long(h,"shapeOfTheEarth",0),0);
|
||||
CODES_CHECK(codes_set_long(h,"shapeOfTheEarth",0),0);
|
||||
|
||||
GRIB_CHECK(grib_set_missing(h,"scaleFactorOfRadiusOfSphericalEarth"),0);
|
||||
GRIB_CHECK(grib_set_missing(h,"scaledValueOfRadiusOfSphericalEarth"),0);
|
||||
GRIB_CHECK(grib_set_missing(h,"scaleFactorOfEarthMajorAxis"),0);
|
||||
GRIB_CHECK(grib_set_missing(h,"scaledValueOfEarthMajorAxis"),0);
|
||||
GRIB_CHECK(grib_set_missing(h,"scaleFactorOfEarthMinorAxis"),0);
|
||||
GRIB_CHECK(grib_set_missing(h,"scaledValueOfEarthMinorAxis"),0);
|
||||
GRIB_CHECK(grib_set_long(h,"radius",6367470),0);
|
||||
GRIB_CHECK(grib_set_long(h,"Ni",16),0);
|
||||
GRIB_CHECK(grib_set_long(h,"Nj",31),0);
|
||||
GRIB_CHECK(grib_set_long(h,"basicAngleOfTheInitialProductionDomain",0),0);
|
||||
GRIB_CHECK(grib_set_long(h,"mBasicAngle",0),0);
|
||||
GRIB_CHECK(grib_set_long(h,"angleMultiplier",1),0);
|
||||
GRIB_CHECK(grib_set_long(h,"mAngleMultiplier",1000000),0);
|
||||
GRIB_CHECK(grib_set_missing(h,"subdivisionsOfBasicAngle"),0);
|
||||
GRIB_CHECK(grib_set_long(h,"angleDivisor",1000000),0);
|
||||
GRIB_CHECK(grib_set_long(h,"latitudeOfFirstGridPoint",60000000),0);
|
||||
GRIB_CHECK(grib_set_long(h,"longitudeOfFirstGridPoint",0),0);
|
||||
CODES_CHECK(codes_set_missing(h,"scaleFactorOfRadiusOfSphericalEarth"),0);
|
||||
CODES_CHECK(codes_set_missing(h,"scaledValueOfRadiusOfSphericalEarth"),0);
|
||||
CODES_CHECK(codes_set_missing(h,"scaleFactorOfEarthMajorAxis"),0);
|
||||
CODES_CHECK(codes_set_missing(h,"scaledValueOfEarthMajorAxis"),0);
|
||||
CODES_CHECK(codes_set_missing(h,"scaleFactorOfEarthMinorAxis"),0);
|
||||
CODES_CHECK(codes_set_missing(h,"scaledValueOfEarthMinorAxis"),0);
|
||||
CODES_CHECK(codes_set_long(h,"radius",6367470),0);
|
||||
CODES_CHECK(codes_set_long(h,"Ni",16),0);
|
||||
CODES_CHECK(codes_set_long(h,"Nj",31),0);
|
||||
CODES_CHECK(codes_set_long(h,"basicAngleOfTheInitialProductionDomain",0),0);
|
||||
CODES_CHECK(codes_set_long(h,"mBasicAngle",0),0);
|
||||
CODES_CHECK(codes_set_long(h,"angleMultiplier",1),0);
|
||||
CODES_CHECK(codes_set_long(h,"mAngleMultiplier",1000000),0);
|
||||
CODES_CHECK(codes_set_missing(h,"subdivisionsOfBasicAngle"),0);
|
||||
CODES_CHECK(codes_set_long(h,"angleDivisor",1000000),0);
|
||||
CODES_CHECK(codes_set_long(h,"latitudeOfFirstGridPoint",60000000),0);
|
||||
CODES_CHECK(codes_set_long(h,"longitudeOfFirstGridPoint",0),0);
|
||||
|
||||
/* 48 = 00110000
|
||||
(3=1) i direction increments given
|
||||
(4=1) j direction increments given
|
||||
(5=0) Resolved u- and v- components of vector quantities relative to easterly and northerly directions
|
||||
See grib2/tables/[tablesVersion]/3.3.table */
|
||||
GRIB_CHECK(grib_set_long(h,"resolutionAndComponentFlags",48),0);
|
||||
CODES_CHECK(codes_set_long(h,"resolutionAndComponentFlags",48),0);
|
||||
|
||||
GRIB_CHECK(grib_set_long(h,"iDirectionIncrementGiven",1),0);
|
||||
GRIB_CHECK(grib_set_long(h,"jDirectionIncrementGiven",1),0);
|
||||
GRIB_CHECK(grib_set_long(h,"uvRelativeToGrid",0),0);
|
||||
GRIB_CHECK(grib_set_long(h,"latitudeOfLastGridPoint",0),0);
|
||||
GRIB_CHECK(grib_set_long(h,"longitudeOfLastGridPoint",30000000),0);
|
||||
GRIB_CHECK(grib_set_long(h,"iDirectionIncrement",2000000),0);
|
||||
GRIB_CHECK(grib_set_long(h,"jDirectionIncrement",2000000),0);
|
||||
CODES_CHECK(codes_set_long(h,"iDirectionIncrementGiven",1),0);
|
||||
CODES_CHECK(codes_set_long(h,"jDirectionIncrementGiven",1),0);
|
||||
CODES_CHECK(codes_set_long(h,"uvRelativeToGrid",0),0);
|
||||
CODES_CHECK(codes_set_long(h,"latitudeOfLastGridPoint",0),0);
|
||||
CODES_CHECK(codes_set_long(h,"longitudeOfLastGridPoint",30000000),0);
|
||||
CODES_CHECK(codes_set_long(h,"iDirectionIncrement",2000000),0);
|
||||
CODES_CHECK(codes_set_long(h,"jDirectionIncrement",2000000),0);
|
||||
|
||||
/* 0 = 00000000
|
||||
(1=0) Points of first row or column scan in the +i (+x) direction
|
||||
|
@ -130,94 +129,94 @@ int main(int argc,const char** argv)
|
|||
(3=0) Adjacent points in i (x) direction are consecutive
|
||||
(4=0) All rows scan in the same direction
|
||||
See grib2/tables/[tablesVersion]/3.4.table */
|
||||
GRIB_CHECK(grib_set_long(h,"scanningMode",0),0);
|
||||
CODES_CHECK(codes_set_long(h,"scanningMode",0),0);
|
||||
|
||||
GRIB_CHECK(grib_set_long(h,"iScansNegatively",0),0);
|
||||
GRIB_CHECK(grib_set_long(h,"jScansPositively",0),0);
|
||||
GRIB_CHECK(grib_set_long(h,"jPointsAreConsecutive",0),0);
|
||||
GRIB_CHECK(grib_set_long(h,"alternativeRowScanning",0),0);
|
||||
GRIB_CHECK(grib_set_long(h,"iScansPositively",1),0);
|
||||
CODES_CHECK(codes_set_long(h,"iScansNegatively",0),0);
|
||||
CODES_CHECK(codes_set_long(h,"jScansPositively",0),0);
|
||||
CODES_CHECK(codes_set_long(h,"jPointsAreConsecutive",0),0);
|
||||
CODES_CHECK(codes_set_long(h,"alternativeRowScanning",0),0);
|
||||
CODES_CHECK(codes_set_long(h,"iScansPositively",1),0);
|
||||
|
||||
/* ITERATOR */
|
||||
|
||||
|
||||
/* NEAREST */
|
||||
|
||||
GRIB_CHECK(grib_set_long(h,"timeRangeIndicator",0),0);
|
||||
GRIB_CHECK(grib_set_long(h,"NV",0),0);
|
||||
GRIB_CHECK(grib_set_long(h,"neitherPresent",0),0);
|
||||
CODES_CHECK(codes_set_long(h,"timeRangeIndicator",0),0);
|
||||
CODES_CHECK(codes_set_long(h,"NV",0),0);
|
||||
CODES_CHECK(codes_set_long(h,"neitherPresent",0),0);
|
||||
|
||||
/* 0 = Analysis or forecast at a horizontal level or in a horizontal layer at a point in time (grib2/tables/4/4.0.table) */
|
||||
GRIB_CHECK(grib_set_long(h,"productDefinitionTemplateNumber",0),0);
|
||||
CODES_CHECK(codes_set_long(h,"productDefinitionTemplateNumber",0),0);
|
||||
|
||||
|
||||
/* Parameter information */
|
||||
|
||||
|
||||
/* 0 = Temperature (grib2/tables/4/4.1.0.table) */
|
||||
GRIB_CHECK(grib_set_long(h,"parameterCategory",0),0);
|
||||
CODES_CHECK(codes_set_long(h,"parameterCategory",0),0);
|
||||
|
||||
|
||||
/* 0 = Temperature (K) (grib2/tables/4/4.2.0.0.table) */
|
||||
GRIB_CHECK(grib_set_long(h,"parameterNumber",0),0);
|
||||
CODES_CHECK(codes_set_long(h,"parameterNumber",0),0);
|
||||
|
||||
|
||||
/* 0 = Analysis (grib2/tables/4/4.3.table) */
|
||||
GRIB_CHECK(grib_set_long(h,"typeOfGeneratingProcess",0),0);
|
||||
CODES_CHECK(codes_set_long(h,"typeOfGeneratingProcess",0),0);
|
||||
|
||||
GRIB_CHECK(grib_set_long(h,"backgroundProcess",255),0);
|
||||
GRIB_CHECK(grib_set_long(h,"generatingProcessIdentifier",128),0);
|
||||
GRIB_CHECK(grib_set_long(h,"hoursAfterDataCutoff",0),0);
|
||||
GRIB_CHECK(grib_set_long(h,"minutesAfterDataCutoff",0),0);
|
||||
CODES_CHECK(codes_set_long(h,"backgroundProcess",255),0);
|
||||
CODES_CHECK(codes_set_long(h,"generatingProcessIdentifier",128),0);
|
||||
CODES_CHECK(codes_set_long(h,"hoursAfterDataCutoff",0),0);
|
||||
CODES_CHECK(codes_set_long(h,"minutesAfterDataCutoff",0),0);
|
||||
|
||||
/* 1 = Hour (grib2/tables/4/4.4.table) */
|
||||
GRIB_CHECK(grib_set_long(h,"indicatorOfUnitOfTimeRange",1),0);
|
||||
CODES_CHECK(codes_set_long(h,"indicatorOfUnitOfTimeRange",1),0);
|
||||
|
||||
|
||||
/* 1 = Hour (stepUnits.table) */
|
||||
GRIB_CHECK(grib_set_long(h,"stepUnits",1),0);
|
||||
CODES_CHECK(codes_set_long(h,"stepUnits",1),0);
|
||||
|
||||
GRIB_CHECK(grib_set_long(h,"forecastTime",0),0);
|
||||
CODES_CHECK(codes_set_long(h,"forecastTime",0),0);
|
||||
|
||||
/* 1 = Ground or water surface (grib2/tables/4/4.5.table) */
|
||||
GRIB_CHECK(grib_set_long(h,"typeOfFirstFixedSurface",1),0);
|
||||
CODES_CHECK(codes_set_long(h,"typeOfFirstFixedSurface",1),0);
|
||||
|
||||
GRIB_CHECK(grib_set_missing(h,"scaleFactorOfFirstFixedSurface"),0);
|
||||
GRIB_CHECK(grib_set_missing(h,"scaledValueOfFirstFixedSurface"),0);
|
||||
CODES_CHECK(codes_set_missing(h,"scaleFactorOfFirstFixedSurface"),0);
|
||||
CODES_CHECK(codes_set_missing(h,"scaledValueOfFirstFixedSurface"),0);
|
||||
|
||||
/* 255 = Missing (grib2/tables/4/4.5.table) */
|
||||
GRIB_CHECK(grib_set_long(h,"typeOfSecondFixedSurface",255),0);
|
||||
CODES_CHECK(codes_set_long(h,"typeOfSecondFixedSurface",255),0);
|
||||
|
||||
GRIB_CHECK(grib_set_missing(h,"scaleFactorOfSecondFixedSurface"),0);
|
||||
GRIB_CHECK(grib_set_missing(h,"scaledValueOfSecondFixedSurface"),0);
|
||||
GRIB_CHECK(grib_set_long(h,"level",0),0);
|
||||
GRIB_CHECK(grib_set_long(h,"bottomLevel",0),0);
|
||||
GRIB_CHECK(grib_set_long(h,"topLevel",0),0);
|
||||
GRIB_CHECK(grib_set_long(h,"dummyc",0),0);
|
||||
GRIB_CHECK(grib_set_long(h,"PVPresent",0),0);
|
||||
CODES_CHECK(codes_set_missing(h,"scaleFactorOfSecondFixedSurface"),0);
|
||||
CODES_CHECK(codes_set_missing(h,"scaledValueOfSecondFixedSurface"),0);
|
||||
CODES_CHECK(codes_set_long(h,"level",0),0);
|
||||
CODES_CHECK(codes_set_long(h,"bottomLevel",0),0);
|
||||
CODES_CHECK(codes_set_long(h,"topLevel",0),0);
|
||||
CODES_CHECK(codes_set_long(h,"dummyc",0),0);
|
||||
CODES_CHECK(codes_set_long(h,"PVPresent",0),0);
|
||||
|
||||
/* grib 2 Section 5 DATA REPRESENTATION SECTION */
|
||||
|
||||
GRIB_CHECK(grib_set_long(h,"numberOfValues",496),0);
|
||||
CODES_CHECK(codes_set_long(h,"numberOfValues",496),0);
|
||||
|
||||
/* 0 = Grid point data - simple packing (grib2/tables/4/5.0.table) */
|
||||
GRIB_CHECK(grib_set_long(h,"dataRepresentationTemplateNumber",0),0);
|
||||
CODES_CHECK(codes_set_long(h,"dataRepresentationTemplateNumber",0),0);
|
||||
|
||||
GRIB_CHECK(grib_set_long(h,"decimalScaleFactor",0),0);
|
||||
GRIB_CHECK(grib_set_long(h,"bitsPerValue",0),0);
|
||||
CODES_CHECK(codes_set_long(h,"decimalScaleFactor",0),0);
|
||||
CODES_CHECK(codes_set_long(h,"bitsPerValue",0),0);
|
||||
|
||||
/* 0 = Floating point (grib2/tables/4/5.1.table) */
|
||||
GRIB_CHECK(grib_set_long(h,"typeOfOriginalFieldValues",0),0);
|
||||
CODES_CHECK(codes_set_long(h,"typeOfOriginalFieldValues",0),0);
|
||||
|
||||
GRIB_CHECK(grib_set_long(h,"representationMode",0),0);
|
||||
CODES_CHECK(codes_set_long(h,"representationMode",0),0);
|
||||
|
||||
/* grib 2 Section 6 BIT-MAP SECTION */
|
||||
|
||||
|
||||
/* 255 = A bit map does not apply to this product (grib2/tables/4/6.0.table) */
|
||||
GRIB_CHECK(grib_set_long(h,"bitMapIndicator",255),0);
|
||||
CODES_CHECK(codes_set_long(h,"bitMapIndicator",255),0);
|
||||
|
||||
GRIB_CHECK(grib_set_long(h,"bitmapPresent",0),0);
|
||||
CODES_CHECK(codes_set_long(h,"bitmapPresent",0),0);
|
||||
|
||||
/* grib 2 Section 7 data */
|
||||
|
||||
|
@ -353,12 +352,12 @@ int main(int argc,const char** argv)
|
|||
vdouble[ 488] = 1; vdouble[ 489] = 1; vdouble[ 490] = 1; vdouble[ 491] = 1;
|
||||
vdouble[ 492] = 1; vdouble[ 493] = 1; vdouble[ 494] = 1; vdouble[ 495] = 1;
|
||||
|
||||
GRIB_CHECK(grib_set_double_array(h,"values",vdouble,size),0);
|
||||
CODES_CHECK(codes_set_double_array(h,"values",vdouble,size),0);
|
||||
free(vdouble);
|
||||
GRIB_CHECK(grib_set_long(h,"dirty_statistics",1),0);
|
||||
GRIB_CHECK(grib_set_long(h,"changeDecimalPrecision",0),0);
|
||||
GRIB_CHECK(grib_set_long(h,"decimalPrecision",0),0);
|
||||
GRIB_CHECK(grib_set_long(h,"setBitsPerValue",0),0);
|
||||
CODES_CHECK(codes_set_long(h,"dirty_statistics",1),0);
|
||||
CODES_CHECK(codes_set_long(h,"changeDecimalPrecision",0),0);
|
||||
CODES_CHECK(codes_set_long(h,"decimalPrecision",0),0);
|
||||
CODES_CHECK(codes_set_long(h,"setBitsPerValue",0),0);
|
||||
/* Save the message */
|
||||
|
||||
f = fopen(argv[1],"w");
|
||||
|
@ -367,7 +366,7 @@ int main(int argc,const char** argv)
|
|||
exit(1);
|
||||
}
|
||||
|
||||
GRIB_CHECK(grib_get_message(h,&buffer,&size),0);
|
||||
CODES_CHECK(codes_get_message(h,&buffer,&size),0);
|
||||
|
||||
if(fwrite(buffer,1,size,f) != size) {
|
||||
perror(argv[1]);
|
||||
|
@ -379,6 +378,6 @@ int main(int argc,const char** argv)
|
|||
exit(1);
|
||||
}
|
||||
|
||||
grib_handle_delete(h);
|
||||
codes_handle_delete(h);
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "grib_api.h"
|
||||
#include "eccodes.h"
|
||||
|
||||
void usage(const char* prog) {
|
||||
printf("Usage: %s latlon_file grib_orography grib_file grib_file ...\n",prog);
|
||||
|
@ -32,7 +32,7 @@ int main(int argc, char** argv)
|
|||
float lat,lon;
|
||||
double *vlat,*vlon;
|
||||
int npoints=0,i=0,n=0;
|
||||
grib_handle* h;
|
||||
codes_handle* h;
|
||||
double *outlats,*outlons,*values,*lsm_values,*distances;
|
||||
int* indexes;
|
||||
long step=0;
|
||||
|
@ -86,13 +86,13 @@ int main(int argc, char** argv)
|
|||
fname=argv[2];
|
||||
fin=fopen(fname,"r");
|
||||
if(!fin) { perror(fname); exit(1); }
|
||||
h=grib_handle_new_from_file(0,fin,&ret);
|
||||
if (!h || ret!=GRIB_SUCCESS) {printf(" unable to create handle\n");exit(1);}
|
||||
h=codes_handle_new_from_file(0,fin,&ret);
|
||||
if (!h || ret!=CODES_SUCCESS) {printf(" unable to create handle\n");exit(1);}
|
||||
|
||||
grib_nearest_find_multiple(h,1,vlat,vlon,npoints,
|
||||
codes_nearest_find_multiple(h,1,vlat,vlon,npoints,
|
||||
outlats,outlons,lsm_values,distances,indexes);
|
||||
|
||||
grib_handle_delete(h);
|
||||
codes_handle_delete(h);
|
||||
|
||||
fclose(fin);
|
||||
|
||||
|
@ -100,18 +100,18 @@ int main(int argc, char** argv)
|
|||
fname=argv[n];
|
||||
fin=fopen(fname,"r");
|
||||
if(!fin) { perror(fname); exit(1); }
|
||||
while ((h=grib_handle_new_from_file(0,fin,&ret))!=NULL) {
|
||||
grib_get_double_elements(h,"values",indexes,npoints,values);
|
||||
while ((h=codes_handle_new_from_file(0,fin,&ret))!=NULL) {
|
||||
codes_get_double_elements(h,"values",indexes,npoints,values);
|
||||
|
||||
GRIB_CHECK(grib_get_length(h, "date", &len),0);
|
||||
grib_get_string(h,"date",date,&len);
|
||||
GRIB_CHECK(grib_get_length(h, "time", &len),0);
|
||||
grib_get_string(h,"time",time,&len);
|
||||
grib_get_long(h,"step",&step);
|
||||
grib_get_long(h,"parameter",¶meter);
|
||||
CODES_CHECK(codes_get_length(h, "date", &len),0);
|
||||
codes_get_string(h,"date",date,&len);
|
||||
CODES_CHECK(codes_get_length(h, "time", &len),0);
|
||||
codes_get_string(h,"time",time,&len);
|
||||
codes_get_long(h,"step",&step);
|
||||
codes_get_long(h,"parameter",¶meter);
|
||||
|
||||
printf("# %s %s %ld %ld\n",date,time,step,parameter);
|
||||
grib_handle_delete(h);
|
||||
codes_handle_delete(h);
|
||||
for (i=0;i<npoints;i++)
|
||||
printf("%ld %g %g %g %g\n",
|
||||
id[i],outlats[i],outlons[i],
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
#include <math.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include "grib_api.h"
|
||||
#include "eccodes.h"
|
||||
|
||||
#define EPSILON 1e-6
|
||||
#define EXPECTED_MIN 270.466796875
|
||||
|
@ -34,7 +34,7 @@ int main(int argc, char** argv)
|
|||
char* infile = "../../data/regular_latlon_surface.grib1";
|
||||
FILE* out = NULL;
|
||||
char* outfile = "out.grib1";
|
||||
grib_handle *h = NULL;
|
||||
codes_handle *h = NULL;
|
||||
const void* buffer = NULL;
|
||||
double* values1=NULL;
|
||||
double* values2=NULL;
|
||||
|
@ -59,35 +59,35 @@ int main(int argc, char** argv)
|
|||
}
|
||||
|
||||
/* create a new handle from a message in a file */
|
||||
h = grib_handle_new_from_file(0,in,&err);
|
||||
h = codes_handle_new_from_file(0,in,&err);
|
||||
if (h == NULL) {
|
||||
printf("Error: unable to create handle from file %s\n",infile);
|
||||
}
|
||||
|
||||
/* bitsPerValue before changing the packing parameters */
|
||||
GRIB_CHECK(grib_get_long(h,"bitsPerValue",&bitsPerValue1),0);
|
||||
CODES_CHECK(codes_get_long(h,"bitsPerValue",&bitsPerValue1),0);
|
||||
assert(bitsPerValue1 == 16);
|
||||
|
||||
/* get the size of the values array*/
|
||||
GRIB_CHECK(grib_get_size(h,"values",&size),0);
|
||||
CODES_CHECK(codes_get_size(h,"values",&size),0);
|
||||
assert(size == 496);
|
||||
|
||||
values1 = (double*)malloc(size*sizeof(double));
|
||||
/* get data values before changing the packing parameters*/
|
||||
GRIB_CHECK(grib_get_double_array(h,"values",values1,&size),0);
|
||||
CODES_CHECK(codes_get_double_array(h,"values",values1,&size),0);
|
||||
|
||||
/* changing decimal precision to 2 means that 2 decimal digits
|
||||
are preserved when packing. */
|
||||
decimalPrecision=2;
|
||||
GRIB_CHECK(grib_set_long(h,"changeDecimalPrecision",decimalPrecision),0);
|
||||
CODES_CHECK(codes_set_long(h,"changeDecimalPrecision",decimalPrecision),0);
|
||||
|
||||
/* bitsPerValue after changing the packing parameters */
|
||||
GRIB_CHECK(grib_get_long(h,"bitsPerValue",&bitsPerValue2),0);
|
||||
CODES_CHECK(codes_get_long(h,"bitsPerValue",&bitsPerValue2),0);
|
||||
assert(bitsPerValue2 == 12);
|
||||
|
||||
values2 = (double*)malloc(size*sizeof(double));
|
||||
/* get data values after changing the packing parameters*/
|
||||
GRIB_CHECK(grib_get_double_array(h,"values",values2,&size),0);
|
||||
CODES_CHECK(codes_get_double_array(h,"values",values2,&size),0);
|
||||
|
||||
/* computing error */
|
||||
maxa=0;
|
||||
|
@ -110,7 +110,7 @@ int main(int argc, char** argv)
|
|||
assert(fabs(maxv - EXPECTED_MAX) < EPSILON);
|
||||
|
||||
/* get the coded message in a buffer */
|
||||
GRIB_CHECK(grib_get_message(h,&buffer,&size),0);
|
||||
CODES_CHECK(codes_get_message(h,&buffer,&size),0);
|
||||
|
||||
/* write the buffer in a file*/
|
||||
if(fwrite(buffer,1,size,out) != size)
|
||||
|
@ -119,7 +119,7 @@ int main(int argc, char** argv)
|
|||
exit(1);
|
||||
}
|
||||
|
||||
grib_handle_delete(h);
|
||||
codes_handle_delete(h);
|
||||
|
||||
fclose(in);
|
||||
fclose(out);
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "grib_api.h"
|
||||
#include "eccodes.h"
|
||||
|
||||
void usage(const char* prog) {
|
||||
printf("usage: %s filename\n",prog);
|
||||
|
@ -33,7 +33,7 @@ int main(int argc, char** argv)
|
|||
|
||||
FILE* in = NULL;
|
||||
char* filename ;
|
||||
grib_handle *h = NULL;
|
||||
codes_handle *h = NULL;
|
||||
|
||||
if (argc<2) usage(argv[0]);
|
||||
filename=argv[1];
|
||||
|
@ -45,19 +45,19 @@ int main(int argc, char** argv)
|
|||
}
|
||||
|
||||
/* create new handle from a message in a file*/
|
||||
h = grib_handle_new_from_file(0,in,&err);
|
||||
h = codes_handle_new_from_file(0,in,&err);
|
||||
if (h == NULL) {
|
||||
printf("Error: unable to create handle from file %s\n",filename);
|
||||
}
|
||||
|
||||
|
||||
/* get the size of the values array*/
|
||||
GRIB_CHECK(grib_get_size(h,"values",&values_len),0);
|
||||
CODES_CHECK(codes_get_size(h,"values",&values_len),0);
|
||||
|
||||
values = (double*)malloc(values_len*sizeof(double));
|
||||
|
||||
/* get data values*/
|
||||
GRIB_CHECK(grib_get_double_array(h,"values",values,&values_len),0);
|
||||
CODES_CHECK(codes_get_double_array(h,"values",values,&values_len),0);
|
||||
|
||||
for(i = 0; i < values_len; i++)
|
||||
printf("%d %.10e\n",i+1,values[i]);
|
||||
|
@ -65,14 +65,14 @@ int main(int argc, char** argv)
|
|||
free(values);
|
||||
|
||||
|
||||
GRIB_CHECK(grib_get_double(h,"max",&max),0);
|
||||
GRIB_CHECK(grib_get_double(h,"min",&min),0);
|
||||
GRIB_CHECK(grib_get_double(h,"average",&average),0);
|
||||
CODES_CHECK(codes_get_double(h,"max",&max),0);
|
||||
CODES_CHECK(codes_get_double(h,"min",&min),0);
|
||||
CODES_CHECK(codes_get_double(h,"average",&average),0);
|
||||
|
||||
printf("%d values found in %s\n",(int)values_len,filename);
|
||||
printf("max=%.10e min=%.10e average=%.10e\n",max,min,average);
|
||||
|
||||
grib_handle_delete(h);
|
||||
codes_handle_delete(h);
|
||||
|
||||
fclose(in);
|
||||
return 0;
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
* 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.h"
|
||||
#include "eccodes.h"
|
||||
#include <ctype.h>
|
||||
|
||||
void usage(char* prog) {
|
||||
|
@ -21,7 +21,7 @@ void usage(char* prog) {
|
|||
|
||||
int main ( int argc, char* argv[])
|
||||
{
|
||||
grib_handle *hfrom,*hto,*h;
|
||||
codes_handle *hfrom,*hto,*h;
|
||||
FILE *in;
|
||||
char *in_name1, *in_name2, *what_str, *out_name;
|
||||
int i, err=0, what=0;
|
||||
|
@ -39,8 +39,8 @@ int main ( int argc, char* argv[])
|
|||
exit(1);
|
||||
}
|
||||
|
||||
hfrom=grib_handle_new_from_file(0,in,&err);
|
||||
GRIB_CHECK(err,0);
|
||||
hfrom=codes_handle_new_from_file(0,in,&err);
|
||||
CODES_CHECK(err,0);
|
||||
fclose(in);
|
||||
|
||||
in=fopen(in_name2,"r");
|
||||
|
@ -49,39 +49,39 @@ int main ( int argc, char* argv[])
|
|||
exit(1);
|
||||
}
|
||||
|
||||
hto=grib_handle_new_from_file(0,in,&err);
|
||||
GRIB_CHECK(err,0);
|
||||
hto=codes_handle_new_from_file(0,in,&err);
|
||||
CODES_CHECK(err,0);
|
||||
fclose(in);
|
||||
|
||||
/* The sections for the "what" argument are:
|
||||
* GRIB_SECTION_PRODUCT
|
||||
* GRIB_SECTION_GRID
|
||||
* GRIB_SECTION_LOCAL
|
||||
* GRIB_SECTION_DATA
|
||||
* GRIB_SECTION_BITMAP
|
||||
* CODES_SECTION_PRODUCT
|
||||
* CODES_SECTION_GRID
|
||||
* CODES_SECTION_LOCAL
|
||||
* CODES_SECTION_DATA
|
||||
* CODES_SECTION_BITMAP
|
||||
* One can bitwise-OR them to have more than one section copied
|
||||
* E.g. what = GRIB_SECTION_PRODUCT | GRIB_SECTION_LOCAL;
|
||||
* E.g. what = CODES_SECTION_PRODUCT | CODES_SECTION_LOCAL;
|
||||
*/
|
||||
for(i=0; i<strlen(what_str); ++i) {
|
||||
if (what_str[i] == 'p') {
|
||||
printf("Copying the PRODUCT section\n");
|
||||
what |= GRIB_SECTION_PRODUCT;
|
||||
what |= CODES_SECTION_PRODUCT;
|
||||
}
|
||||
else if (what_str[i] == 'g') {
|
||||
printf("Copying the GRID section\n");
|
||||
what |= GRIB_SECTION_GRID;
|
||||
what |= CODES_SECTION_GRID;
|
||||
}
|
||||
else if (what_str[i] == 'l') {
|
||||
printf("Copying the LOCAL section\n");
|
||||
what |= GRIB_SECTION_LOCAL;
|
||||
what |= CODES_SECTION_LOCAL;
|
||||
}
|
||||
else if (what_str[i] == 'd') {
|
||||
printf("Copying the DATA section\n");
|
||||
what |= GRIB_SECTION_DATA;
|
||||
what |= CODES_SECTION_DATA;
|
||||
}
|
||||
else if (what_str[i] == 'b') {
|
||||
printf("Copying the BITMAP section\n");
|
||||
what |= GRIB_SECTION_BITMAP;
|
||||
what |= CODES_SECTION_BITMAP;
|
||||
}
|
||||
else if (isspace(what_str[i]) || what_str[i] == ',') {
|
||||
/* Ignore spaces and comma separator */
|
||||
|
@ -92,14 +92,14 @@ int main ( int argc, char* argv[])
|
|||
}
|
||||
}
|
||||
|
||||
h=grib_util_sections_copy(hfrom,hto,what,&err);
|
||||
GRIB_CHECK(err,0);
|
||||
h=codes_util_sections_copy(hfrom,hto,what,&err);
|
||||
CODES_CHECK(err,0);
|
||||
|
||||
err=grib_write_message(h,out_name,"w");
|
||||
err=codes_write_message(h,out_name,"w");
|
||||
|
||||
grib_handle_delete(hfrom);
|
||||
grib_handle_delete(hto);
|
||||
grib_handle_delete(h);
|
||||
codes_handle_delete(hfrom);
|
||||
codes_handle_delete(hto);
|
||||
codes_handle_delete(h);
|
||||
|
||||
return err;
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "grib_api.h"
|
||||
#include "eccodes.h"
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
|
@ -32,9 +32,9 @@ int main(int argc, char** argv)
|
|||
char* infile = "../../data/regular_latlon_surface.grib1";
|
||||
FILE* out = NULL;
|
||||
char* outfile = "out.grib1";
|
||||
grib_handle *h = NULL;
|
||||
codes_handle *h = NULL;
|
||||
const void* buffer = NULL;
|
||||
size_t str_len = 0; /* See the call to grib_set_string later */
|
||||
size_t str_len = 0; /* See the call to codes_set_string later */
|
||||
|
||||
in = fopen(infile,"r");
|
||||
if(!in) {
|
||||
|
@ -50,29 +50,29 @@ int main(int argc, char** argv)
|
|||
}
|
||||
|
||||
/* create a new handle from a message in a file */
|
||||
h = grib_handle_new_from_file(0,in,&err);
|
||||
h = codes_handle_new_from_file(0,in,&err);
|
||||
if (h == NULL) {
|
||||
printf("Error: unable to create handle from file %s\n",infile);
|
||||
}
|
||||
|
||||
/* set centre as a long */
|
||||
GRIB_CHECK(grib_set_long(h,"centre",centre),0);
|
||||
CODES_CHECK(codes_set_long(h,"centre",centre),0);
|
||||
|
||||
/* set paramId and shortName - normally you would do one or the other */
|
||||
GRIB_CHECK(grib_set_long(h,"paramId", 500004),0);
|
||||
CODES_CHECK(codes_set_long(h,"paramId", 500004),0);
|
||||
/* the value of str_len is not used, it can be anything! */
|
||||
GRIB_CHECK(grib_set_string(h,"shortName", "fis", &str_len),0);
|
||||
CODES_CHECK(codes_set_string(h,"shortName", "fis", &str_len),0);
|
||||
|
||||
/* get centre as a long */
|
||||
GRIB_CHECK(grib_get_long(h,"centre",&long_value),0);
|
||||
CODES_CHECK(codes_get_long(h,"centre",&long_value),0);
|
||||
printf("centre long value=%ld\n",long_value);
|
||||
|
||||
/* get centre as a string */
|
||||
GRIB_CHECK(grib_get_string(h,"centre",string_value,&len),0);
|
||||
CODES_CHECK(codes_get_string(h,"centre",string_value,&len),0);
|
||||
printf("centre string value=%s\n",string_value);
|
||||
|
||||
/* get the coded message in a buffer */
|
||||
GRIB_CHECK(grib_get_message(h,&buffer,&size),0);
|
||||
CODES_CHECK(codes_get_message(h,&buffer,&size),0);
|
||||
|
||||
/* write the buffer in a file*/
|
||||
if(fwrite(buffer,1,size,out) != size)
|
||||
|
@ -81,7 +81,7 @@ int main(int argc, char** argv)
|
|||
exit(1);
|
||||
}
|
||||
|
||||
grib_handle_delete(h);
|
||||
codes_handle_delete(h);
|
||||
fclose(in);
|
||||
fclose(out);
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "grib_api.h"
|
||||
#include "eccodes.h"
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
|
@ -30,7 +30,7 @@ int main(int argc, char** argv)
|
|||
char* infile = "../../data/regular_latlon_surface.grib1";
|
||||
FILE* out = NULL;
|
||||
char* outfile = "out.grib1";
|
||||
grib_handle *h = NULL;
|
||||
codes_handle *h = NULL;
|
||||
const void* buffer = NULL;
|
||||
size_t values_len;
|
||||
double* values;
|
||||
|
@ -50,30 +50,30 @@ int main(int argc, char** argv)
|
|||
return 1;
|
||||
}
|
||||
|
||||
h = grib_handle_new_from_file(0,in,&err);
|
||||
h = codes_handle_new_from_file(0,in,&err);
|
||||
if (h == NULL) {
|
||||
printf("Error: unable to create handle from file %s\n",infile);
|
||||
}
|
||||
|
||||
GRIB_CHECK(grib_set_double(h,"missingValue",missing),0);
|
||||
CODES_CHECK(codes_set_double(h,"missingValue",missing),0);
|
||||
|
||||
/* get the size of the values array*/
|
||||
GRIB_CHECK(grib_get_size(h,"values",&values_len),0);
|
||||
CODES_CHECK(codes_get_size(h,"values",&values_len),0);
|
||||
|
||||
values = (double*)malloc(values_len*sizeof(double));
|
||||
|
||||
/* get data values*/
|
||||
GRIB_CHECK(grib_get_double_array(h,"values",values,&values_len),0);
|
||||
CODES_CHECK(codes_get_double_array(h,"values",values,&values_len),0);
|
||||
|
||||
GRIB_CHECK(grib_set_long(h,"bitmapPresent",1),0);
|
||||
CODES_CHECK(codes_set_long(h,"bitmapPresent",1),0);
|
||||
|
||||
for(i = 0; i < 10; i++)
|
||||
values[i]=missing;
|
||||
|
||||
GRIB_CHECK(grib_set_double_array(h,"values",values,values_len),0);
|
||||
CODES_CHECK(codes_set_double_array(h,"values",values,values_len),0);
|
||||
|
||||
/* get the coded message in a buffer */
|
||||
GRIB_CHECK(grib_get_message(h,&buffer,&size),0);
|
||||
CODES_CHECK(codes_get_message(h,&buffer,&size),0);
|
||||
|
||||
/* write the buffer in a file*/
|
||||
if(fwrite(buffer,1,size,out) != size)
|
||||
|
@ -83,7 +83,7 @@ int main(int argc, char** argv)
|
|||
}
|
||||
|
||||
/* delete handle */
|
||||
grib_handle_delete(h);
|
||||
codes_handle_delete(h);
|
||||
|
||||
fclose(in);
|
||||
fclose(out);
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "grib_api.h"
|
||||
#include "eccodes.h"
|
||||
|
||||
void usage(const char* prog)
|
||||
{
|
||||
|
@ -37,15 +37,15 @@ int main(int argc, char** argv)
|
|||
/* setting the environment variable GRIB_SAMPLES_PATH */
|
||||
const char* sample_filename = "regular_ll_pl_grib1";
|
||||
/* Here is how you can get the samples path */
|
||||
const char* samples_path = grib_samples_path(NULL);
|
||||
grib_handle *h = NULL;
|
||||
const char* samples_path = codes_samples_path(NULL);
|
||||
codes_handle *h = NULL;
|
||||
double d,e;
|
||||
long count;
|
||||
|
||||
if (argc!=2) usage(argv[0]);
|
||||
/* create new handle from message in sample file */
|
||||
printf("Using samples path: %s\n", samples_path);
|
||||
h = grib_handle_new_from_samples(0, sample_filename);
|
||||
h = codes_handle_new_from_samples(0, sample_filename);
|
||||
if (h == NULL) {
|
||||
printf("Error: unable to create handle from sample file %s\n", sample_filename);
|
||||
exit(1);
|
||||
|
@ -55,7 +55,7 @@ int main(int argc, char** argv)
|
|||
/* will be the same as the sample GRIB. */
|
||||
/* But if your data array has a different size, then specify the grid geometry */
|
||||
/* (e.g. keys Ni, Nj etc) and set the correct number of data values */
|
||||
GRIB_CHECK(grib_get_size(h, "values", &values_len),0);
|
||||
CODES_CHECK(codes_get_size(h, "values", &values_len),0);
|
||||
|
||||
values = (double*)malloc(values_len*sizeof(double));
|
||||
d=10e-8;
|
||||
|
@ -69,15 +69,15 @@ int main(int argc, char** argv)
|
|||
count++;
|
||||
}
|
||||
|
||||
GRIB_CHECK(grib_set_long(h,"bitsPerValue",16),0);
|
||||
CODES_CHECK(codes_set_long(h,"bitsPerValue",16),0);
|
||||
|
||||
/* set data values */
|
||||
GRIB_CHECK(grib_set_double_array(h,"values",values,values_len),0);
|
||||
CODES_CHECK(codes_set_double_array(h,"values",values,values_len),0);
|
||||
|
||||
GRIB_CHECK(grib_write_message(h, argv[1], "w"), 0);
|
||||
CODES_CHECK(codes_write_message(h, argv[1], "w"), 0);
|
||||
|
||||
free(values);
|
||||
grib_handle_delete(h);
|
||||
codes_handle_delete(h);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
#include "grib_api.h"
|
||||
#include "eccodes.h"
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
|
@ -27,7 +27,7 @@ int main(int argc, char** argv)
|
|||
char* infile = "../../data/reduced_gaussian_pressure_level.grib2";
|
||||
FILE* out = NULL;
|
||||
char* outfile = "out_surface_level.grib2";
|
||||
grib_handle *h = NULL;
|
||||
codes_handle *h = NULL;
|
||||
const void* buffer = NULL;
|
||||
size_t size=0;
|
||||
char str[]="sfc";
|
||||
|
@ -48,24 +48,24 @@ int main(int argc, char** argv)
|
|||
}
|
||||
|
||||
/* create a new handle from a message in a file */
|
||||
h = grib_handle_new_from_file(0,in,&err);
|
||||
h = codes_handle_new_from_file(0,in,&err);
|
||||
if (h == NULL) {
|
||||
printf("Error: unable to create handle from file %s\n",infile);
|
||||
}
|
||||
|
||||
GRIB_CHECK(grib_set_string(h,"typeOfFirstFixedSurface",str,&str_len),0);
|
||||
GRIB_CHECK(grib_set_missing(h,"scaleFactorOfFirstFixedSurface"),0);
|
||||
GRIB_CHECK(grib_set_missing(h,"scaledValueOfFirstFixedSurface"),0);
|
||||
CODES_CHECK(codes_set_string(h,"typeOfFirstFixedSurface",str,&str_len),0);
|
||||
CODES_CHECK(codes_set_missing(h,"scaleFactorOfFirstFixedSurface"),0);
|
||||
CODES_CHECK(codes_set_missing(h,"scaledValueOfFirstFixedSurface"),0);
|
||||
|
||||
/* See GRIB-490 */
|
||||
GRIB_CHECK(grib_get_long(h,"Ni",&Ni),0);
|
||||
is_missing = grib_is_missing(h, "Ni", &err);
|
||||
GRIB_CHECK(err,0);
|
||||
CODES_CHECK(codes_get_long(h,"Ni",&Ni),0);
|
||||
is_missing = codes_is_missing(h, "Ni", &err);
|
||||
CODES_CHECK(err,0);
|
||||
assert(is_missing == 1);
|
||||
GRIB_CHECK(grib_set_long(h,"Ni", Ni),0);
|
||||
CODES_CHECK(codes_set_long(h,"Ni", Ni),0);
|
||||
|
||||
/* get the coded message in a buffer */
|
||||
GRIB_CHECK(grib_get_message(h,&buffer,&size),0);
|
||||
CODES_CHECK(codes_get_message(h,&buffer,&size),0);
|
||||
|
||||
/* write the buffer in a file*/
|
||||
if(fwrite(buffer,1,size,out) != size)
|
||||
|
@ -75,7 +75,7 @@ int main(int argc, char** argv)
|
|||
}
|
||||
|
||||
/* delete handle */
|
||||
grib_handle_delete(h);
|
||||
codes_handle_delete(h);
|
||||
|
||||
fclose(in);
|
||||
fclose(out);
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
#include "grib_api.h"
|
||||
#include "eccodes.h"
|
||||
|
||||
void usage(const char* prog) {
|
||||
fprintf(stderr, "usage: %s in out\n",prog);
|
||||
|
@ -36,7 +36,7 @@ int main(int argc, char** argv)
|
|||
char* infile = NULL;
|
||||
FILE* out = NULL;
|
||||
char* outfile = NULL;
|
||||
grib_handle *h = NULL;
|
||||
codes_handle *h = NULL;
|
||||
const void* buffer = NULL;
|
||||
|
||||
if (argc != 3) usage(argv[0]);
|
||||
|
@ -57,21 +57,21 @@ int main(int argc, char** argv)
|
|||
}
|
||||
|
||||
/* create a new handle from a message in a file */
|
||||
h = grib_handle_new_from_file(0,in,&err);
|
||||
h = codes_handle_new_from_file(0,in,&err);
|
||||
if (h == NULL) {
|
||||
fprintf(stderr, "Error: unable to create handle from file %s\n",infile);
|
||||
}
|
||||
|
||||
GRIB_CHECK(grib_set_long(h,"PVPresent",PVPresent),0);
|
||||
CODES_CHECK(codes_set_long(h,"PVPresent",PVPresent),0);
|
||||
|
||||
GRIB_CHECK(grib_set_double_array(h,"pv",pv,pvsize),0);
|
||||
CODES_CHECK(codes_set_double_array(h,"pv",pv,pvsize),0);
|
||||
|
||||
/* Once we set the pv array, the NV key should be also set */
|
||||
GRIB_CHECK(grib_get_long(h,"NV",&NV),0);
|
||||
CODES_CHECK(codes_get_long(h,"NV",&NV),0);
|
||||
assert( NV == pvsize );
|
||||
|
||||
/* get the coded message in a buffer */
|
||||
GRIB_CHECK(grib_get_message(h,&buffer,&size),0);
|
||||
CODES_CHECK(codes_get_message(h,&buffer,&size),0);
|
||||
|
||||
/* write the buffer in a file*/
|
||||
if(fwrite(buffer,1,size,out) != size)
|
||||
|
@ -80,7 +80,7 @@ int main(int argc, char** argv)
|
|||
exit(1);
|
||||
}
|
||||
|
||||
grib_handle_delete(h);
|
||||
codes_handle_delete(h);
|
||||
fclose(in);
|
||||
fclose(out);
|
||||
|
||||
|
|
|
@ -7,16 +7,16 @@
|
|||
* 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.h"
|
||||
#include "eccodes.h"
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
FILE* f;
|
||||
int err=0;
|
||||
char infile[]="../../data/reduced_gaussian_model_level.grib1";
|
||||
grib_handle *h=NULL;
|
||||
grib_context* c=grib_context_get_default();
|
||||
grib_values values[2];
|
||||
codes_handle *h=NULL;
|
||||
codes_context* c=codes_context_get_default();
|
||||
codes_values values[2];
|
||||
int nvalues=2;
|
||||
int i;
|
||||
char* name = NULL;
|
||||
|
@ -27,37 +27,37 @@ int main(int argc, char* argv[])
|
|||
exit(1);
|
||||
}
|
||||
|
||||
h=grib_handle_new_from_file(c,f,&err);
|
||||
h=codes_handle_new_from_file(c,f,&err);
|
||||
if (!h) {
|
||||
printf("unable to create handle from file %s\n",infile);
|
||||
exit(err);
|
||||
}
|
||||
fclose(f);
|
||||
|
||||
values[0].type=GRIB_TYPE_LONG;
|
||||
values[0].type=CODES_TYPE_LONG;
|
||||
values[0].name="centre";
|
||||
values[0].long_value=98;
|
||||
|
||||
values[1].type=GRIB_TYPE_LONG;
|
||||
values[1].type=CODES_TYPE_LONG;
|
||||
values[1].name="level";
|
||||
values[1].long_value=2;
|
||||
|
||||
/*GRIB_VALUE_DIFFERENT -> value is different*/
|
||||
err=grib_values_check(h,values,nvalues);
|
||||
/*CODES_VALUE_DIFFERENT -> value is different*/
|
||||
err=codes_values_check(h,values,nvalues);
|
||||
if (err) {
|
||||
for (i=0;i<nvalues;i++) {
|
||||
if (values[i].error==err) name=(char*)values[i].name;
|
||||
}
|
||||
printf("ERROR: \"%s\" %s\n",name,grib_get_error_message(err));
|
||||
printf("ERROR: \"%s\" %s\n",name,codes_get_error_message(err));
|
||||
}
|
||||
|
||||
values[1].name="levelll";
|
||||
err=grib_values_check(h,values,nvalues);
|
||||
err=codes_values_check(h,values,nvalues);
|
||||
if (err) {
|
||||
for (i=0;i<nvalues;i++) {
|
||||
if (values[i].error==err) name=(char*)values[i].name;
|
||||
}
|
||||
printf("ERROR: \"%s\" %s\n",name,grib_get_error_message(err));
|
||||
printf("ERROR: \"%s\" %s\n",name,codes_get_error_message(err));
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
Loading…
Reference in New Issue