mirror of https://github.com/ecmwf/eccodes.git
Applied clang-format (Part 3)
This commit is contained in:
parent
3d188bebbf
commit
42453ffbd7
|
@ -13,53 +13,52 @@
|
||||||
int main(int argc, char* argv[])
|
int main(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
FILE* f;
|
FILE* f;
|
||||||
int err=0;
|
int err = 0;
|
||||||
char infile[]="../../data/reduced_gaussian_model_level.grib1";
|
char infile[] = "../../data/reduced_gaussian_model_level.grib1";
|
||||||
codes_handle *h=NULL;
|
codes_handle* h = NULL;
|
||||||
codes_box* box;
|
codes_box* box;
|
||||||
codes_points* points;
|
codes_points* points;
|
||||||
codes_context* c=codes_context_get_default();
|
codes_context* c = codes_context_get_default();
|
||||||
double north,west,south,east;
|
double north, west, south, east;
|
||||||
double* val;
|
double* val;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
north=60;
|
north = 60;
|
||||||
south=10;
|
south = 10;
|
||||||
west=-10;
|
west = -10;
|
||||||
east=30;
|
east = 30;
|
||||||
|
|
||||||
f=fopen(infile,"rb");
|
f = fopen(infile, "rb");
|
||||||
if (!f) {
|
if (!f) {
|
||||||
perror(infile);
|
perror(infile);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
h=codes_handle_new_from_file(c, f, PRODUCT_GRIB, &err);
|
h = codes_handle_new_from_file(c, f, PRODUCT_GRIB, &err);
|
||||||
if (!h) {
|
if (!h) {
|
||||||
printf("unable to create handle from file %s\n",infile);
|
printf("unable to create handle from file %s\n", infile);
|
||||||
exit(err);
|
exit(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
box=codes_box_new(h,&err);
|
box = codes_box_new(h, &err);
|
||||||
|
|
||||||
if (!box) {
|
if (!box) {
|
||||||
printf("unable to create box\n");
|
printf("unable to create box\n");
|
||||||
exit(err);
|
exit(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
points=codes_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);
|
val = (double*)malloc(sizeof(double) * points->n);
|
||||||
codes_points_get_values(h,points,val);
|
codes_points_get_values(h, points, val);
|
||||||
|
|
||||||
for (i=0;i<points->n;i++) {
|
for (i = 0; i < points->n; i++) {
|
||||||
printf("%d -- %.3f %.3f %ld %g\n",i,
|
printf("%d -- %.3f %.3f %ld %g\n", i,
|
||||||
points->latitudes[i], points->longitudes[i], (long)(points->indexes[i]), val[i]);
|
points->latitudes[i], points->longitudes[i], (long)(points->indexes[i]), val[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
free(val);
|
free(val);
|
||||||
|
|
||||||
fclose(f);
|
fclose(f);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,42 +18,41 @@
|
||||||
#include "eccodes.h"
|
#include "eccodes.h"
|
||||||
|
|
||||||
|
|
||||||
int main(int argc,char* argv[])
|
int main(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
FILE* in = NULL;
|
FILE* in = NULL;
|
||||||
|
|
||||||
/* message handle. Required in all the eccodes calls acting on a message.*/
|
/* message handle. Required in all the eccodes calls acting on a message.*/
|
||||||
codes_handle* h=NULL;
|
codes_handle* h = NULL;
|
||||||
|
|
||||||
char* units= NULL;
|
char* units = NULL;
|
||||||
char* unitsPercent= NULL;
|
char* unitsPercent = NULL;
|
||||||
long longVal;
|
long longVal;
|
||||||
double doubleVal;
|
double doubleVal;
|
||||||
size_t len=0;
|
size_t len = 0;
|
||||||
int err=0;
|
int err = 0;
|
||||||
int cnt=0;
|
int cnt = 0;
|
||||||
const char* infile = "../../data/bufr/syno_multi.bufr";
|
const char* infile = "../../data/bufr/syno_multi.bufr";
|
||||||
|
|
||||||
in=fopen(infile,"rb");
|
in = fopen(infile, "rb");
|
||||||
if (!in) {
|
if (!in) {
|
||||||
printf("ERROR: unable to open file %s\n", infile);
|
printf("ERROR: unable to open file %s\n", infile);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* loop over the messages in the bufr file */
|
/* loop over the messages in the bufr file */
|
||||||
while ((h = codes_handle_new_from_file(NULL, in, PRODUCT_BUFR, &err)) != NULL || err != CODES_SUCCESS)
|
while ((h = codes_handle_new_from_file(NULL, in, PRODUCT_BUFR, &err)) != NULL || err != CODES_SUCCESS) {
|
||||||
{
|
|
||||||
if (h == NULL) {
|
if (h == NULL) {
|
||||||
printf("Error: unable to create handle for message %d\n",cnt);
|
printf("Error: unable to create handle for message %d\n", cnt);
|
||||||
cnt++;
|
cnt++;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("message: %d\n",cnt);
|
printf("message: %d\n", cnt);
|
||||||
|
|
||||||
/* we need to instruct ecCodes to expand the descriptors
|
/* we need to instruct ecCodes to expand the descriptors
|
||||||
i.e. unpack the data values */
|
i.e. unpack the data values */
|
||||||
CODES_CHECK(codes_set_long(h, "unpack", 1),0);
|
CODES_CHECK(codes_set_long(h, "unpack", 1), 0);
|
||||||
|
|
||||||
/* ----------------------------------------------------------------
|
/* ----------------------------------------------------------------
|
||||||
We will read the value and all the attributes available for
|
We will read the value and all the attributes available for
|
||||||
|
@ -61,34 +60,34 @@ int main(int argc,char* argv[])
|
||||||
-------------------------------------------------------------------*/
|
-------------------------------------------------------------------*/
|
||||||
|
|
||||||
/* get the value as double */
|
/* get the value as double */
|
||||||
CODES_CHECK(codes_get_double(h, "airTemperatureAt2M", &doubleVal),0);
|
CODES_CHECK(codes_get_double(h, "airTemperatureAt2M", &doubleVal), 0);
|
||||||
printf(" airTemperatureAt2M: %.2f\n",doubleVal);
|
printf(" airTemperatureAt2M: %.2f\n", doubleVal);
|
||||||
|
|
||||||
/* get the element's code (see BUFR code table B) */
|
/* get the element's code (see BUFR code table B) */
|
||||||
CODES_CHECK(codes_get_long(h, "airTemperatureAt2M->code", &longVal),0);
|
CODES_CHECK(codes_get_long(h, "airTemperatureAt2M->code", &longVal), 0);
|
||||||
printf(" airTemperatureAt2M->code: %ld\n",longVal);
|
printf(" airTemperatureAt2M->code: %ld\n", longVal);
|
||||||
|
|
||||||
/* get the element's units (see BUFR code table B) */
|
/* get the element's units (see BUFR code table B) */
|
||||||
|
|
||||||
/* get the size and allocate memory*/
|
/* get the size and allocate memory*/
|
||||||
CODES_CHECK(codes_get_length(h, "airTemperatureAt2M->units", &len), 0);
|
CODES_CHECK(codes_get_length(h, "airTemperatureAt2M->units", &len), 0);
|
||||||
units = (char*)malloc(len*sizeof(char));
|
units = (char*)malloc(len * sizeof(char));
|
||||||
|
|
||||||
/* get the values*/
|
/* get the values*/
|
||||||
codes_get_string(h, "airTemperatureAt2M->units", units, &len);
|
codes_get_string(h, "airTemperatureAt2M->units", units, &len);
|
||||||
printf(" airTemperatureAt2M->units: %s\n", units);
|
printf(" airTemperatureAt2M->units: %s\n", units);
|
||||||
|
|
||||||
/* get the element's scale (see BUFR code table B) */
|
/* get the element's scale (see BUFR code table B) */
|
||||||
CODES_CHECK(codes_get_long(h, "airTemperatureAt2M->scale", &longVal),0);
|
CODES_CHECK(codes_get_long(h, "airTemperatureAt2M->scale", &longVal), 0);
|
||||||
printf(" airTemperatureAt2M->scale: %ld\n",longVal);
|
printf(" airTemperatureAt2M->scale: %ld\n", longVal);
|
||||||
|
|
||||||
/* get the element's reference (see BUFR code table B) */
|
/* get the element's reference (see BUFR code table B) */
|
||||||
CODES_CHECK(codes_get_long(h, "airTemperatureAt2M->reference", &longVal),0);
|
CODES_CHECK(codes_get_long(h, "airTemperatureAt2M->reference", &longVal), 0);
|
||||||
printf(" airTemperatureAt2M->reference: %ld\n",longVal);
|
printf(" airTemperatureAt2M->reference: %ld\n", longVal);
|
||||||
|
|
||||||
/* get the element's width (see BUFR code table B) */
|
/* get the element's width (see BUFR code table B) */
|
||||||
CODES_CHECK(codes_get_long(h, "airTemperatureAt2M->width", &longVal),0);
|
CODES_CHECK(codes_get_long(h, "airTemperatureAt2M->width", &longVal), 0);
|
||||||
printf(" airTemperatureAt2M->width: %ld\n",longVal);
|
printf(" airTemperatureAt2M->width: %ld\n", longVal);
|
||||||
|
|
||||||
/* -----------------------------------------------------------------
|
/* -----------------------------------------------------------------
|
||||||
The 2m temperature data element in this message has an associated
|
The 2m temperature data element in this message has an associated
|
||||||
|
@ -97,34 +96,34 @@ int main(int argc,char* argv[])
|
||||||
----------------------------------------------------------------- */
|
----------------------------------------------------------------- */
|
||||||
|
|
||||||
/* get the value as long */
|
/* get the value as long */
|
||||||
CODES_CHECK(codes_get_long(h, "airTemperatureAt2M->percentConfidence", &longVal),0);
|
CODES_CHECK(codes_get_long(h, "airTemperatureAt2M->percentConfidence", &longVal), 0);
|
||||||
printf(" airTemperatureAt2M->percentConfidence: %ld\n",longVal);
|
printf(" airTemperatureAt2M->percentConfidence: %ld\n", longVal);
|
||||||
|
|
||||||
/* get the element's code (see BUFR code table B) */
|
/* get the element's code (see BUFR code table B) */
|
||||||
CODES_CHECK(codes_get_long(h, "airTemperatureAt2M->percentConfidence->code", &longVal),0);
|
CODES_CHECK(codes_get_long(h, "airTemperatureAt2M->percentConfidence->code", &longVal), 0);
|
||||||
printf(" airTemperatureAt2M->percentConfidence->code: %ld\n",longVal);
|
printf(" airTemperatureAt2M->percentConfidence->code: %ld\n", longVal);
|
||||||
|
|
||||||
/* get the element's units (see BUFR code table B) */
|
/* get the element's units (see BUFR code table B) */
|
||||||
|
|
||||||
/* get the size and allocate memory*/
|
/* get the size and allocate memory*/
|
||||||
CODES_CHECK(codes_get_length(h, "airTemperatureAt2M->percentConfidence->units", &len), 0);
|
CODES_CHECK(codes_get_length(h, "airTemperatureAt2M->percentConfidence->units", &len), 0);
|
||||||
unitsPercent = (char*)malloc(len*sizeof(char));
|
unitsPercent = (char*)malloc(len * sizeof(char));
|
||||||
|
|
||||||
/* get the values*/
|
/* get the values*/
|
||||||
codes_get_string(h, "airTemperatureAt2M->percentConfidence->units", unitsPercent, &len);
|
codes_get_string(h, "airTemperatureAt2M->percentConfidence->units", unitsPercent, &len);
|
||||||
printf(" airTemperatureAt2M->percentConfidence->units: %s\n", unitsPercent);
|
printf(" airTemperatureAt2M->percentConfidence->units: %s\n", unitsPercent);
|
||||||
|
|
||||||
/* get the element's scale (see BUFR code table B) */
|
/* get the element's scale (see BUFR code table B) */
|
||||||
CODES_CHECK(codes_get_long(h, "airTemperatureAt2M->percentConfidence->scale", &longVal),0);
|
CODES_CHECK(codes_get_long(h, "airTemperatureAt2M->percentConfidence->scale", &longVal), 0);
|
||||||
printf(" airTemperatureAt2M->percentConfidence->scale: %ld\n",longVal);
|
printf(" airTemperatureAt2M->percentConfidence->scale: %ld\n", longVal);
|
||||||
|
|
||||||
/* get the element's reference (see BUFR code table B) */
|
/* get the element's reference (see BUFR code table B) */
|
||||||
CODES_CHECK(codes_get_long(h, "airTemperatureAt2M->percentConfidence->reference", &longVal),0);
|
CODES_CHECK(codes_get_long(h, "airTemperatureAt2M->percentConfidence->reference", &longVal), 0);
|
||||||
printf(" airTemperatureAt2M->percentConfidence->reference: %ld\n",longVal);
|
printf(" airTemperatureAt2M->percentConfidence->reference: %ld\n", longVal);
|
||||||
|
|
||||||
/* get the element's width (see BUFR code table B) */
|
/* get the element's width (see BUFR code table B) */
|
||||||
CODES_CHECK(codes_get_long(h, "airTemperatureAt2M->percentConfidence->width", &longVal),0);
|
CODES_CHECK(codes_get_long(h, "airTemperatureAt2M->percentConfidence->width", &longVal), 0);
|
||||||
printf(" airTemperatureAt2M->percentConfidence->width: %ld\n",longVal);
|
printf(" airTemperatureAt2M->percentConfidence->width: %ld\n", longVal);
|
||||||
|
|
||||||
/* free allocated arrays */
|
/* free allocated arrays */
|
||||||
free(units);
|
free(units);
|
||||||
|
|
|
@ -18,21 +18,21 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include "eccodes.h"
|
#include "eccodes.h"
|
||||||
|
|
||||||
static void usage(const char *app)
|
static void usage(const char* app)
|
||||||
{
|
{
|
||||||
fprintf(stderr,"Usage is: %s input_file ouput_file\n", app);
|
fprintf(stderr, "Usage is: %s input_file ouput_file\n", app);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
FILE *in = NULL;
|
FILE* in = NULL;
|
||||||
FILE *out = NULL;
|
FILE* out = NULL;
|
||||||
|
|
||||||
/* message handle. Required in all the ecCodes calls acting on a message.*/
|
/* message handle. Required in all the ecCodes calls acting on a message.*/
|
||||||
codes_handle *source_handle = NULL;
|
codes_handle* source_handle = NULL;
|
||||||
|
|
||||||
const void *buffer = NULL;
|
const void* buffer = NULL;
|
||||||
size_t size = 0;
|
size_t size = 0;
|
||||||
int i, err = 0;
|
int i, err = 0;
|
||||||
|
|
||||||
if (argc != 3) {
|
if (argc != 3) {
|
||||||
|
@ -40,8 +40,8 @@ int main(int argc, char *argv[])
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
in = fopen(argv[1],"rb");
|
in = fopen(argv[1], "rb");
|
||||||
out = fopen(argv[2],"wb");
|
out = fopen(argv[2], "wb");
|
||||||
|
|
||||||
/* open input and output */
|
/* open input and output */
|
||||||
if (!in || !out) {
|
if (!in || !out) {
|
||||||
|
@ -64,10 +64,9 @@ int main(int argc, char *argv[])
|
||||||
/* create several clones of this message and alter them
|
/* create several clones of this message and alter them
|
||||||
in different ways */
|
in different ways */
|
||||||
|
|
||||||
for(i=0; i < 3; i++) {
|
for (i = 0; i < 3; i++) {
|
||||||
|
|
||||||
/* clone the current handle */
|
/* clone the current handle */
|
||||||
codes_handle *clone_handle = codes_handle_clone(source_handle);
|
codes_handle* clone_handle = codes_handle_clone(source_handle);
|
||||||
|
|
||||||
if (clone_handle == NULL) {
|
if (clone_handle == NULL) {
|
||||||
perror("ERROR: could not clone field");
|
perror("ERROR: could not clone field");
|
||||||
|
@ -77,13 +76,13 @@ int main(int argc, char *argv[])
|
||||||
/* This is the place where you may wish to modify the clone
|
/* This is the place where you may wish to modify the clone
|
||||||
E.g. we change the typicalDay key */
|
E.g. we change the typicalDay key */
|
||||||
|
|
||||||
CODES_CHECK(codes_set_long(clone_handle, "typicalDay", 20+i),0);
|
CODES_CHECK(codes_set_long(clone_handle, "typicalDay", 20 + i), 0);
|
||||||
|
|
||||||
/* get the coded message in a buffer */
|
/* get the coded message in a buffer */
|
||||||
CODES_CHECK(codes_get_message(clone_handle, &buffer, &size),0);
|
CODES_CHECK(codes_get_message(clone_handle, &buffer, &size), 0);
|
||||||
|
|
||||||
/* write the buffer to a file */
|
/* write the buffer to a file */
|
||||||
if(fwrite(buffer, 1, size, out) != size) {
|
if (fwrite(buffer, 1, size, out) != size) {
|
||||||
perror("ERROR: could not write message to file");
|
perror("ERROR: could not write message to file");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,35 +19,35 @@
|
||||||
|
|
||||||
static void usage(const char* progname);
|
static void usage(const char* progname);
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
FILE* f = NULL;
|
FILE* f = NULL;
|
||||||
codes_handle* h = NULL;
|
codes_handle* h = NULL;
|
||||||
codes_handle* ho = NULL;
|
codes_handle* ho = NULL;
|
||||||
long size;
|
long size;
|
||||||
char** keys = NULL;
|
char** keys = NULL;
|
||||||
size_t nkeys=0,i;
|
size_t nkeys = 0, i;
|
||||||
int err=0;
|
int err = 0;
|
||||||
char* outfile = NULL;
|
char* outfile = NULL;
|
||||||
const char* sampleName = "BUFR3";
|
const char* sampleName = "BUFR3";
|
||||||
const long ibitmap[]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
const long ibitmap[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,
|
0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||||
1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,
|
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1,
|
||||||
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
|
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||||
1,1,1,1,0};
|
1, 1, 1, 1, 0 };
|
||||||
|
|
||||||
const long ud[]={307011,7006,10004,222000,101023,31031,1031,1032,101023,33007,
|
const long ud[] = { 307011, 7006, 10004, 222000, 101023, 31031, 1031, 1032, 101023, 33007,
|
||||||
225000,236000,101023,31031,1031,1032,8024,101001,225255,225000,
|
225000, 236000, 101023, 31031, 1031, 1032, 8024, 101001, 225255, 225000,
|
||||||
236000,101023,31031,1031,1032,8024,101001,225255,
|
236000, 101023, 31031, 1031, 1032, 8024, 101001, 225255,
|
||||||
1063,2001,4001,4002,4003,4004,4005,5002,
|
1063, 2001, 4001, 4002, 4003, 4004, 4005, 5002,
|
||||||
6002,7001,7006,11001,11016,11017,11002};
|
6002, 7001, 7006, 11001, 11016, 11017, 11002 };
|
||||||
|
|
||||||
if (argc != 3) usage(argv[0]);
|
if (argc != 3) usage(argv[0]);
|
||||||
|
|
||||||
outfile=argv[2];
|
outfile = argv[2];
|
||||||
|
|
||||||
f = fopen(argv[1],"rb");
|
f = fopen(argv[1], "rb");
|
||||||
if(!f) {
|
if (!f) {
|
||||||
perror(argv[1]);
|
perror(argv[1]);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
@ -58,7 +58,7 @@ int main(int argc, char *argv[])
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
size = sizeof(ibitmap)/sizeof(ibitmap[0]);
|
size = sizeof(ibitmap) / sizeof(ibitmap[0]);
|
||||||
CODES_CHECK(codes_set_long_array(ho, "inputDataPresentIndicator", ibitmap, size), 0);
|
CODES_CHECK(codes_set_long_array(ho, "inputDataPresentIndicator", ibitmap, size), 0);
|
||||||
CODES_CHECK(codes_set_long(ho, "bufrHeaderCentre", 98), 0);
|
CODES_CHECK(codes_set_long(ho, "bufrHeaderCentre", 98), 0);
|
||||||
CODES_CHECK(codes_set_long(ho, "updateSequenceNumber", 1), 0);
|
CODES_CHECK(codes_set_long(ho, "updateSequenceNumber", 1), 0);
|
||||||
|
@ -75,17 +75,16 @@ int main(int argc, char *argv[])
|
||||||
CODES_CHECK(codes_set_long(ho, "observedData", 1), 0);
|
CODES_CHECK(codes_set_long(ho, "observedData", 1), 0);
|
||||||
CODES_CHECK(codes_set_long(ho, "compressedData", 0), 0);
|
CODES_CHECK(codes_set_long(ho, "compressedData", 0), 0);
|
||||||
|
|
||||||
size = sizeof(ud)/sizeof(ud[0]);
|
size = sizeof(ud) / sizeof(ud[0]);
|
||||||
codes_set_long_array(ho,"unexpandedDescriptors",ud,size);
|
codes_set_long_array(ho, "unexpandedDescriptors", ud, size);
|
||||||
|
|
||||||
while((h = codes_handle_new_from_file(0,f,PRODUCT_BUFR,&err)) != NULL)
|
while ((h = codes_handle_new_from_file(0, f, PRODUCT_BUFR, &err)) != NULL) {
|
||||||
{
|
if (!h) {
|
||||||
if(!h) {
|
|
||||||
printf("ERROR: Unable to create BUFR handle\n");
|
printf("ERROR: Unable to create BUFR handle\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
/* codes_copy_key(h,ho,"unexpandedDescriptors",0); */
|
/* codes_copy_key(h,ho,"unexpandedDescriptors",0); */
|
||||||
err = codes_set_long(h,"unpack",1);
|
err = codes_set_long(h, "unpack", 1);
|
||||||
if (err) {
|
if (err) {
|
||||||
printf("ERROR: Unable to unpack BUFR message. Quitting\n");
|
printf("ERROR: Unable to unpack BUFR message. Quitting\n");
|
||||||
printf(" %s\n", codes_get_error_message(err));
|
printf(" %s\n", codes_get_error_message(err));
|
||||||
|
@ -93,9 +92,9 @@ int main(int argc, char *argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
/* err=codes_bufr_copy_data(h,ho); */
|
/* err=codes_bufr_copy_data(h,ho); */
|
||||||
keys=codes_bufr_copy_data_return_copied_keys(h,ho,&nkeys,&err);
|
keys = codes_bufr_copy_data_return_copied_keys(h, ho, &nkeys, &err);
|
||||||
for (i=0;i<nkeys;i++) {
|
for (i = 0; i < nkeys; i++) {
|
||||||
printf("Copied %s\n",keys[i]);
|
printf("Copied %s\n", keys[i]);
|
||||||
free(keys[i]);
|
free(keys[i]);
|
||||||
}
|
}
|
||||||
printf("Total number of copied keys = %lu\n", nkeys);
|
printf("Total number of copied keys = %lu\n", nkeys);
|
||||||
|
@ -104,7 +103,7 @@ int main(int argc, char *argv[])
|
||||||
codes_handle_delete(h);
|
codes_handle_delete(h);
|
||||||
}
|
}
|
||||||
fclose(f);
|
fclose(f);
|
||||||
codes_write_message(ho,outfile,"w");
|
codes_write_message(ho, outfile, "w");
|
||||||
codes_handle_delete(ho);
|
codes_handle_delete(ho);
|
||||||
|
|
||||||
return err;
|
return err;
|
||||||
|
@ -112,6 +111,6 @@ int main(int argc, char *argv[])
|
||||||
|
|
||||||
static void usage(const char* progname)
|
static void usage(const char* progname)
|
||||||
{
|
{
|
||||||
printf("\nUsage: %s bufr_in bufr_out\n",progname);
|
printf("\nUsage: %s bufr_in bufr_out\n", progname);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,57 +17,56 @@
|
||||||
|
|
||||||
#include "eccodes.h"
|
#include "eccodes.h"
|
||||||
|
|
||||||
static void usage(const char* prog) {
|
static void usage(const char* prog)
|
||||||
printf("usage: %s infile\n",prog);
|
{
|
||||||
|
printf("usage: %s infile\n", prog);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc,char* argv[])
|
int main(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
char* filename = NULL;
|
char* filename = NULL;
|
||||||
FILE* in = NULL;
|
FILE* in = NULL;
|
||||||
|
|
||||||
/* message handle. Required in all the ecCodes calls acting on a message.*/
|
/* message handle. Required in all the ecCodes calls acting on a message.*/
|
||||||
codes_handle* h=NULL;
|
codes_handle* h = NULL;
|
||||||
|
|
||||||
double *values = NULL;
|
double* values = NULL;
|
||||||
size_t values_len=0;
|
size_t values_len = 0;
|
||||||
int i, err=0;
|
int i, err = 0;
|
||||||
int cnt=0;
|
int cnt = 0;
|
||||||
|
|
||||||
if (argc!=2) usage(argv[0]);
|
if (argc != 2) usage(argv[0]);
|
||||||
|
|
||||||
filename=argv[1];
|
filename = argv[1];
|
||||||
|
|
||||||
/* open bufr file */
|
/* open bufr file */
|
||||||
in=fopen(filename,"rb");
|
in = fopen(filename, "rb");
|
||||||
if (!in) {
|
if (!in) {
|
||||||
printf("ERROR: unable to open file %s\n", filename);
|
printf("ERROR: unable to open file %s\n", filename);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* loop over the messages in the bufr file */
|
/* loop over the messages in the bufr file */
|
||||||
while ((h = codes_handle_new_from_file(NULL, in, PRODUCT_BUFR, &err)) != NULL || err != CODES_SUCCESS)
|
while ((h = codes_handle_new_from_file(NULL, in, PRODUCT_BUFR, &err)) != NULL || err != CODES_SUCCESS) {
|
||||||
{
|
|
||||||
if (h == NULL) {
|
if (h == NULL) {
|
||||||
printf("Error: unable to create handle for message %d\n",cnt);
|
printf("Error: unable to create handle for message %d\n", cnt);
|
||||||
cnt++;
|
cnt++;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* get the size of the values array*/
|
/* get the size of the values array*/
|
||||||
CODES_CHECK(codes_get_size(h, "numericValues", &values_len),0);
|
CODES_CHECK(codes_get_size(h, "numericValues", &values_len), 0);
|
||||||
printf(" number of expanded values: %lu\n", values_len);
|
printf(" number of expanded values: %lu\n", values_len);
|
||||||
|
|
||||||
/* allocate array for data values */
|
/* allocate array for data values */
|
||||||
values = (double*)malloc(values_len*sizeof(double));
|
values = (double*)malloc(values_len * sizeof(double));
|
||||||
|
|
||||||
/* get the expanded data values*/
|
/* get the expanded data values*/
|
||||||
CODES_CHECK(codes_get_double_array(h, "numericValues", values, &values_len),0);
|
CODES_CHECK(codes_get_double_array(h, "numericValues", values, &values_len), 0);
|
||||||
|
|
||||||
for(i = 0; i < values_len; i++)
|
for (i = 0; i < values_len; i++) {
|
||||||
{
|
printf(" %.10e\n", values[i]);
|
||||||
printf(" %.10e\n",values[i]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
free(values);
|
free(values);
|
||||||
|
|
|
@ -17,63 +17,62 @@
|
||||||
|
|
||||||
#include "eccodes.h"
|
#include "eccodes.h"
|
||||||
|
|
||||||
int main(int argc,char* argv[])
|
int main(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
FILE* in = NULL;
|
FILE* in = NULL;
|
||||||
|
|
||||||
/* message handle. Required in all the eccodes calls acting on a message.*/
|
/* message handle. Required in all the eccodes calls acting on a message.*/
|
||||||
codes_handle* h=NULL;
|
codes_handle* h = NULL;
|
||||||
|
|
||||||
long *descriptors=NULL;
|
long* descriptors = NULL;
|
||||||
double *values = NULL;
|
double* values = NULL;
|
||||||
char* typicalDate= NULL;
|
char* typicalDate = NULL;
|
||||||
long longVal;
|
long longVal;
|
||||||
double doubleVal;
|
double doubleVal;
|
||||||
size_t values_len=0, desc_len=0, len=0;
|
size_t values_len = 0, desc_len = 0, len = 0;
|
||||||
int i, err=0;
|
int i, err = 0;
|
||||||
int cnt=0;
|
int cnt = 0;
|
||||||
const char* infile = "../../data/bufr/syno_multi.bufr";
|
const char* infile = "../../data/bufr/syno_multi.bufr";
|
||||||
|
|
||||||
in=fopen(infile,"rb");
|
in = fopen(infile, "rb");
|
||||||
if (!in) {
|
if (!in) {
|
||||||
printf("ERROR: unable to open file %s\n", infile);
|
printf("ERROR: unable to open file %s\n", infile);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* loop over the messages in the bufr file */
|
/* loop over the messages in the bufr file */
|
||||||
while ((h = codes_handle_new_from_file(NULL, in, PRODUCT_BUFR, &err)) != NULL || err != CODES_SUCCESS)
|
while ((h = codes_handle_new_from_file(NULL, in, PRODUCT_BUFR, &err)) != NULL || err != CODES_SUCCESS) {
|
||||||
{
|
|
||||||
if (h == NULL) {
|
if (h == NULL) {
|
||||||
printf("Error: unable to create handle for message %d\n",cnt);
|
printf("Error: unable to create handle for message %d\n", cnt);
|
||||||
cnt++;
|
cnt++;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("message: %d\n",cnt);
|
printf("message: %d\n", cnt);
|
||||||
|
|
||||||
/* we need to instruct ecCodes to expand the descriptors
|
/* we need to instruct ecCodes to expand the descriptors
|
||||||
i.e. unpack the data values */
|
i.e. unpack the data values */
|
||||||
CODES_CHECK(codes_set_long(h, "unpack", 1),0);
|
CODES_CHECK(codes_set_long(h, "unpack", 1), 0);
|
||||||
|
|
||||||
/* read and print some data values */
|
/* read and print some data values */
|
||||||
|
|
||||||
/* long value */
|
/* long value */
|
||||||
CODES_CHECK(codes_get_long(h, "blockNumber", &longVal),0);
|
CODES_CHECK(codes_get_long(h, "blockNumber", &longVal), 0);
|
||||||
printf(" blockNumber: %ld\n", longVal);
|
printf(" blockNumber: %ld\n", longVal);
|
||||||
|
|
||||||
/* long value */
|
/* long value */
|
||||||
CODES_CHECK(codes_get_long(h, "stationNumber", &longVal),0);
|
CODES_CHECK(codes_get_long(h, "stationNumber", &longVal), 0);
|
||||||
printf(" stationNumber: %ld\n", longVal);
|
printf(" stationNumber: %ld\n", longVal);
|
||||||
|
|
||||||
/* double value */
|
/* double value */
|
||||||
CODES_CHECK(codes_get_double(h, "airTemperatureAt2M", &doubleVal),0);
|
CODES_CHECK(codes_get_double(h, "airTemperatureAt2M", &doubleVal), 0);
|
||||||
printf(" airTemperatureAt2M: %f\n", doubleVal);
|
printf(" airTemperatureAt2M: %f\n", doubleVal);
|
||||||
|
|
||||||
/* ---- string value -----------------*/
|
/* ---- string value -----------------*/
|
||||||
|
|
||||||
/* get the size and allocate memory*/
|
/* get the size and allocate memory*/
|
||||||
CODES_CHECK(codes_get_length(h, "typicalDate", &len), 0);
|
CODES_CHECK(codes_get_length(h, "typicalDate", &len), 0);
|
||||||
typicalDate = (char*)malloc(len*sizeof(char));
|
typicalDate = (char*)malloc(len * sizeof(char));
|
||||||
|
|
||||||
/* get the values*/
|
/* get the values*/
|
||||||
codes_get_string(h, "typicalDate", typicalDate, &len);
|
codes_get_string(h, "typicalDate", typicalDate, &len);
|
||||||
|
@ -82,29 +81,27 @@ int main(int argc,char* argv[])
|
||||||
/* ---- array of long ----------------*/
|
/* ---- array of long ----------------*/
|
||||||
|
|
||||||
/* get the size and allocate memory*/
|
/* get the size and allocate memory*/
|
||||||
CODES_CHECK(codes_get_size(h, "bufrdcExpandedDescriptors", &desc_len),0);
|
CODES_CHECK(codes_get_size(h, "bufrdcExpandedDescriptors", &desc_len), 0);
|
||||||
descriptors = (long*)malloc(desc_len*sizeof(long));
|
descriptors = (long*)malloc(desc_len * sizeof(long));
|
||||||
|
|
||||||
/* get the values */
|
/* get the values */
|
||||||
CODES_CHECK(codes_get_long_array(h, "bufrdcExpandedDescriptors", descriptors, &desc_len),0);
|
CODES_CHECK(codes_get_long_array(h, "bufrdcExpandedDescriptors", descriptors, &desc_len), 0);
|
||||||
printf(" bufrdcExpandedDescriptors:\n");
|
printf(" bufrdcExpandedDescriptors:\n");
|
||||||
for(i = 0; i < desc_len; i++)
|
for (i = 0; i < desc_len; i++) {
|
||||||
{
|
printf(" %ld\n", descriptors[i]);
|
||||||
printf(" %ld\n",descriptors[i]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ---- array of double ---------------*/
|
/* ---- array of double ---------------*/
|
||||||
|
|
||||||
/* get the size and allocate memory*/
|
/* get the size and allocate memory*/
|
||||||
CODES_CHECK(codes_get_size(h, "numericValues", &values_len),0);
|
CODES_CHECK(codes_get_size(h, "numericValues", &values_len), 0);
|
||||||
values = (double*)malloc(values_len*sizeof(double));
|
values = (double*)malloc(values_len * sizeof(double));
|
||||||
|
|
||||||
/* get the values*/
|
/* get the values*/
|
||||||
CODES_CHECK(codes_get_double_array(h, "numericValues", values, &values_len),0);
|
CODES_CHECK(codes_get_double_array(h, "numericValues", values, &values_len), 0);
|
||||||
printf(" numericValues:\n");
|
printf(" numericValues:\n");
|
||||||
for(i = 0; i < values_len; i++)
|
for (i = 0; i < values_len; i++) {
|
||||||
{
|
printf(" %.10e\n", values[i]);
|
||||||
printf(" %.10e\n",values[i]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* free allocated arrays */
|
/* free allocated arrays */
|
||||||
|
|
|
@ -17,34 +17,33 @@
|
||||||
|
|
||||||
#include "eccodes.h"
|
#include "eccodes.h"
|
||||||
|
|
||||||
int main(int argc,char* argv[])
|
int main(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
codes_handle* h=NULL;
|
codes_handle* h = NULL;
|
||||||
|
|
||||||
size_t i=0, size = 0;
|
size_t i = 0, size = 0;
|
||||||
size_t len=0;
|
size_t len = 0;
|
||||||
int err=0, cnt=0;
|
int err = 0, cnt = 0;
|
||||||
char** strArray = NULL; /* array of strings */
|
char** strArray = NULL; /* array of strings */
|
||||||
const char* infile = "../../data/bufr/pgps_110.bufr";
|
const char* infile = "../../data/bufr/pgps_110.bufr";
|
||||||
|
|
||||||
FILE* in = fopen(infile,"rb");
|
FILE* in = fopen(infile, "rb");
|
||||||
if (!in) {
|
if (!in) {
|
||||||
printf("ERROR: unable to open file %s\n", infile);
|
printf("ERROR: unable to open file %s\n", infile);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* loop over the messages in the bufr file */
|
/* loop over the messages in the bufr file */
|
||||||
while ((h = codes_handle_new_from_file(NULL, in, PRODUCT_BUFR, &err)) != NULL || err != CODES_SUCCESS)
|
while ((h = codes_handle_new_from_file(NULL, in, PRODUCT_BUFR, &err)) != NULL || err != CODES_SUCCESS) {
|
||||||
{
|
|
||||||
if (h == NULL) {
|
if (h == NULL) {
|
||||||
printf("Error: unable to create handle for message %d\n",cnt);
|
printf("Error: unable to create handle for message %d\n", cnt);
|
||||||
cnt++;
|
cnt++;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* we need to instruct ecCodes to expand the descriptors
|
/* we need to instruct ecCodes to expand the descriptors
|
||||||
i.e. unpack the data values */
|
i.e. unpack the data values */
|
||||||
CODES_CHECK(codes_set_long(h, "unpack", 1),0);
|
CODES_CHECK(codes_set_long(h, "unpack", 1), 0);
|
||||||
|
|
||||||
/* get the size and allocate memory */
|
/* get the size and allocate memory */
|
||||||
CODES_CHECK(codes_get_size(h, "stationOrSiteName", &len), 0);
|
CODES_CHECK(codes_get_size(h, "stationOrSiteName", &len), 0);
|
||||||
|
@ -54,13 +53,14 @@ int main(int argc,char* argv[])
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
CODES_CHECK(codes_get_string_array(h, "stationOrSiteName", strArray, &size), 0);
|
CODES_CHECK(codes_get_string_array(h, "stationOrSiteName", strArray, &size), 0);
|
||||||
for(i=0; i<size; ++i) {
|
for (i = 0; i < size; ++i) {
|
||||||
printf("%s\n", strArray[i]);
|
printf("%s\n", strArray[i]);
|
||||||
}
|
}
|
||||||
printf("stationOrSiteName string array size = %lu\n", (unsigned long)size);
|
printf("stationOrSiteName string array size = %lu\n", (unsigned long)size);
|
||||||
|
|
||||||
/* free allocated arrays */
|
/* free allocated arrays */
|
||||||
for(i=0; i<size; ++i) free( strArray[i] );
|
for (i = 0; i < size; ++i)
|
||||||
|
free(strArray[i]);
|
||||||
free(strArray);
|
free(strArray);
|
||||||
|
|
||||||
/* delete handle */
|
/* delete handle */
|
||||||
|
|
|
@ -19,82 +19,80 @@
|
||||||
|
|
||||||
#include "eccodes.h"
|
#include "eccodes.h"
|
||||||
|
|
||||||
#define MAX_VAL_LEN 1024
|
#define MAX_VAL_LEN 1024
|
||||||
|
|
||||||
static void usage(const char* prog) {
|
static void usage(const char* prog)
|
||||||
printf("usage: %s infile\n",prog);
|
{
|
||||||
|
printf("usage: %s infile\n", prog);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc,char* argv[])
|
int main(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
char* filename = NULL;
|
char* filename = NULL;
|
||||||
FILE* in = NULL;
|
FILE* in = NULL;
|
||||||
|
|
||||||
/* message handle. Required in all the eccodes calls acting on a message.*/
|
/* message handle. Required in all the eccodes calls acting on a message.*/
|
||||||
codes_handle* h=NULL;
|
codes_handle* h = NULL;
|
||||||
int err=0, cnt=0;
|
int err = 0, cnt = 0;
|
||||||
int keyType = 0;
|
int keyType = 0;
|
||||||
|
|
||||||
char value[MAX_VAL_LEN];
|
char value[MAX_VAL_LEN];
|
||||||
size_t vlen=MAX_VAL_LEN;
|
size_t vlen = MAX_VAL_LEN;
|
||||||
size_t klen=0;
|
size_t klen = 0;
|
||||||
|
|
||||||
if (argc!=2) usage(argv[0]);
|
if (argc != 2) usage(argv[0]);
|
||||||
|
|
||||||
filename=argv[1];
|
filename = argv[1];
|
||||||
|
|
||||||
in=fopen(filename,"rb");
|
in = fopen(filename, "rb");
|
||||||
if (!in) {
|
if (!in) {
|
||||||
printf("ERROR: unable to open file %s\n", filename);
|
printf("ERROR: unable to open file %s\n", filename);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* loop over the messages in the BUFR file */
|
/* loop over the messages in the BUFR file */
|
||||||
while ((h = codes_handle_new_from_file(NULL,in,PRODUCT_BUFR,&err)) != NULL || err != CODES_SUCCESS)
|
while ((h = codes_handle_new_from_file(NULL, in, PRODUCT_BUFR, &err)) != NULL || err != CODES_SUCCESS) {
|
||||||
{
|
codes_bufr_keys_iterator* kiter = NULL;
|
||||||
codes_bufr_keys_iterator* kiter=NULL;
|
|
||||||
if (h == NULL) {
|
if (h == NULL) {
|
||||||
printf("Error: unable to create handle for message %d\n",cnt);
|
printf("Error: unable to create handle for message %d\n", cnt);
|
||||||
cnt++;
|
cnt++;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("message: %d\n",cnt);
|
printf("message: %d\n", cnt);
|
||||||
|
|
||||||
/* we need to instruct ecCodes to unpack the data values */
|
/* we need to instruct ecCodes to unpack the data values */
|
||||||
CODES_CHECK(codes_set_long(h,"unpack",1),0);
|
CODES_CHECK(codes_set_long(h, "unpack", 1), 0);
|
||||||
|
|
||||||
/* get BUFR key iterator */
|
/* get BUFR key iterator */
|
||||||
kiter=codes_bufr_keys_iterator_new(h,0);
|
kiter = codes_bufr_keys_iterator_new(h, 0);
|
||||||
if (!kiter) {
|
if (!kiter) {
|
||||||
printf("ERROR: Unable to create BUFR keys iterator\n");
|
printf("ERROR: Unable to create BUFR keys iterator\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* loop over the keys */
|
/* loop over the keys */
|
||||||
while(codes_bufr_keys_iterator_next(kiter))
|
while (codes_bufr_keys_iterator_next(kiter)) {
|
||||||
{
|
|
||||||
/* get key name */
|
/* get key name */
|
||||||
char* name = codes_bufr_keys_iterator_get_name(kiter);
|
char* name = codes_bufr_keys_iterator_get_name(kiter);
|
||||||
printf(" %s=",name);
|
printf(" %s=", name);
|
||||||
|
|
||||||
CODES_CHECK(codes_get_native_type(h,name,&keyType),0);
|
CODES_CHECK(codes_get_native_type(h, name, &keyType), 0);
|
||||||
|
|
||||||
/* get key size to see if it is an array */
|
/* get key size to see if it is an array */
|
||||||
CODES_CHECK(codes_get_size(h,name,&klen),0);
|
CODES_CHECK(codes_get_size(h, name, &klen), 0);
|
||||||
|
|
||||||
if (klen ==1)
|
if (klen == 1) {
|
||||||
{
|
|
||||||
/* not array */
|
/* not array */
|
||||||
vlen=MAX_VAL_LEN;
|
vlen = MAX_VAL_LEN;
|
||||||
memset(value, 0, vlen);
|
memset(value, 0, vlen);
|
||||||
codes_get_string(h,name,value,&vlen);
|
codes_get_string(h, name, value, &vlen);
|
||||||
printf("%s\n",value);
|
printf("%s\n", value);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
/* for arrays */
|
/* for arrays */
|
||||||
printf("(array of %lu)\n",klen);
|
printf("(array of %lu)\n", klen);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,51 +17,47 @@
|
||||||
#include "eccodes.h"
|
#include "eccodes.h"
|
||||||
|
|
||||||
|
|
||||||
int main(int argc,char* argv[])
|
int main(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
FILE* in = NULL;
|
FILE* in = NULL;
|
||||||
|
|
||||||
/* message handle. Required in all the eccodes calls acting on a message.*/
|
/* message handle. Required in all the eccodes calls acting on a message.*/
|
||||||
codes_handle* h=NULL;
|
codes_handle* h = NULL;
|
||||||
|
|
||||||
double doubleVal;
|
double doubleVal;
|
||||||
int err=0;
|
int err = 0;
|
||||||
int cnt=0;
|
int cnt = 0;
|
||||||
const char* infile = "../../data/bufr/syno_1.bufr";
|
const char* infile = "../../data/bufr/syno_1.bufr";
|
||||||
|
|
||||||
in=fopen(infile,"rb");
|
in = fopen(infile, "rb");
|
||||||
if (!in)
|
if (!in) {
|
||||||
{
|
|
||||||
printf("ERROR: unable to open file %s\n", infile);
|
printf("ERROR: unable to open file %s\n", infile);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* loop over the messages in the bufr file */
|
/* loop over the messages in the bufr file */
|
||||||
while ((h = codes_handle_new_from_file(NULL,in,PRODUCT_BUFR,&err)) != NULL || err != CODES_SUCCESS)
|
while ((h = codes_handle_new_from_file(NULL, in, PRODUCT_BUFR, &err)) != NULL || err != CODES_SUCCESS) {
|
||||||
{
|
|
||||||
if (h == NULL) {
|
if (h == NULL) {
|
||||||
printf("Error: unable to create handle for message %d\n",cnt);
|
printf("Error: unable to create handle for message %d\n", cnt);
|
||||||
cnt++;
|
cnt++;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("message: %d\n",cnt);
|
printf("message: %d\n", cnt);
|
||||||
|
|
||||||
/* we need to instruct ecCodes to expand the descriptors
|
/* we need to instruct ecCodes to expand the descriptors
|
||||||
i.e. unpack the data values */
|
i.e. unpack the data values */
|
||||||
CODES_CHECK(codes_set_long(h,"unpack",1),0);
|
CODES_CHECK(codes_set_long(h, "unpack", 1), 0);
|
||||||
|
|
||||||
/* the value of this key is missing in the message*/
|
/* the value of this key is missing in the message*/
|
||||||
CODES_CHECK(codes_get_double(h,"relativeHumidity",&doubleVal),0);
|
CODES_CHECK(codes_get_double(h, "relativeHumidity", &doubleVal), 0);
|
||||||
printf(" relativeHumidity: %.2f\n",doubleVal);
|
printf(" relativeHumidity: %.2f\n", doubleVal);
|
||||||
|
|
||||||
/* we will print "value missing" */
|
/* we will print "value missing" */
|
||||||
if(doubleVal == CODES_MISSING_DOUBLE)
|
if (doubleVal == CODES_MISSING_DOUBLE) {
|
||||||
{
|
|
||||||
printf(" --> value missing\n");
|
printf(" --> value missing\n");
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
printf(" --> value present\n");
|
printf(" --> value present\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,36 +22,36 @@
|
||||||
|
|
||||||
static void* process_bufr(void* arg)
|
static void* process_bufr(void* arg)
|
||||||
{
|
{
|
||||||
FILE* fin = (FILE*)arg;
|
FILE* fin = (FILE*)arg;
|
||||||
int err = 0;
|
int err = 0;
|
||||||
codes_handle* h = NULL;
|
codes_handle* h = NULL;
|
||||||
long numSubsets = 0, lVal = 0;
|
long numSubsets = 0, lVal = 0;
|
||||||
size_t size = 0, i=0;
|
size_t size = 0, i = 0;
|
||||||
double* dValues = NULL;
|
double* dValues = NULL;
|
||||||
/* Each thread gets a different message handle */
|
/* Each thread gets a different message handle */
|
||||||
h = codes_handle_new_from_file(NULL, fin, PRODUCT_BUFR, &err);
|
h = codes_handle_new_from_file(NULL, fin, PRODUCT_BUFR, &err);
|
||||||
assert(h);
|
assert(h);
|
||||||
|
|
||||||
/* Check expected values for this BUFR file */
|
/* Check expected values for this BUFR file */
|
||||||
CODES_CHECK(codes_get_long(h,"numberOfSubsets", &numSubsets),0);
|
CODES_CHECK(codes_get_long(h, "numberOfSubsets", &numSubsets), 0);
|
||||||
assert( numSubsets == 1 );
|
assert(numSubsets == 1);
|
||||||
CODES_CHECK(codes_get_long(h, "rectimeSecond", &lVal), 0);
|
CODES_CHECK(codes_get_long(h, "rectimeSecond", &lVal), 0);
|
||||||
assert( lVal == 27 );
|
assert(lVal == 27);
|
||||||
|
|
||||||
CODES_CHECK(codes_set_long(h, "unpack", 1),0);
|
CODES_CHECK(codes_set_long(h, "unpack", 1), 0);
|
||||||
|
|
||||||
dValues = (double*)malloc(numSubsets*sizeof(double));
|
dValues = (double*)malloc(numSubsets * sizeof(double));
|
||||||
assert(dValues);
|
assert(dValues);
|
||||||
size = numSubsets;
|
size = numSubsets;
|
||||||
CODES_CHECK(codes_get_double_array(h, "latitude", dValues, &size), 0);
|
CODES_CHECK(codes_get_double_array(h, "latitude", dValues, &size), 0);
|
||||||
for(i=0; i<size; ++i) {
|
for (i = 0; i < size; ++i) {
|
||||||
/* Specific test for latitudes in this BUFR file */
|
/* Specific test for latitudes in this BUFR file */
|
||||||
assert( dValues[0] < 79 && dValues[0] > 70 );
|
assert(dValues[0] < 79 && dValues[0] > 70);
|
||||||
}
|
}
|
||||||
free(dValues);
|
free(dValues);
|
||||||
|
|
||||||
/* Some encoding too */
|
/* Some encoding too */
|
||||||
CODES_CHECK(codes_set_long(h, "bufrHeaderCentre", 88),0);
|
CODES_CHECK(codes_set_long(h, "bufrHeaderCentre", 88), 0);
|
||||||
CODES_CHECK(codes_set_long(h, "blockNumber", 2), 0);
|
CODES_CHECK(codes_set_long(h, "blockNumber", 2), 0);
|
||||||
CODES_CHECK(codes_set_long(h, "#3#verticalSignificanceSurfaceObservations", 8), 0);
|
CODES_CHECK(codes_set_long(h, "#3#verticalSignificanceSurfaceObservations", 8), 0);
|
||||||
CODES_CHECK(codes_set_long(h, "pack", 1), 0);
|
CODES_CHECK(codes_set_long(h, "pack", 1), 0);
|
||||||
|
@ -62,20 +62,20 @@ static void* process_bufr(void* arg)
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
pthread_t thread1, thread2, thread3;
|
pthread_t thread1, thread2, thread3;
|
||||||
int err = 0;
|
int err = 0;
|
||||||
FILE* fin = 0;
|
FILE* fin = 0;
|
||||||
codes_handle* h1 = 0;
|
codes_handle* h1 = 0;
|
||||||
codes_handle* h2 = 0;
|
codes_handle* h2 = 0;
|
||||||
fin = fopen("../../data/bufr/syno_multi.bufr", "rb");
|
fin = fopen("../../data/bufr/syno_multi.bufr", "rb");
|
||||||
assert(fin);
|
assert(fin);
|
||||||
|
|
||||||
err = pthread_create(&thread1, NULL, process_bufr, (void *)fin);
|
err = pthread_create(&thread1, NULL, process_bufr, (void*)fin);
|
||||||
assert(!err);
|
assert(!err);
|
||||||
|
|
||||||
err = pthread_create(&thread2, NULL, process_bufr, (void *)fin);
|
err = pthread_create(&thread2, NULL, process_bufr, (void*)fin);
|
||||||
assert(!err);
|
assert(!err);
|
||||||
|
|
||||||
err = pthread_create(&thread3, NULL, process_bufr, (void *)fin);
|
err = pthread_create(&thread3, NULL, process_bufr, (void*)fin);
|
||||||
assert(!err);
|
assert(!err);
|
||||||
|
|
||||||
pthread_join(thread1, NULL);
|
pthread_join(thread1, NULL);
|
||||||
|
|
|
@ -17,67 +17,67 @@
|
||||||
|
|
||||||
#include "eccodes.h"
|
#include "eccodes.h"
|
||||||
|
|
||||||
static void usage(const char* prog) {
|
static void usage(const char* prog)
|
||||||
printf("usage: %s infile\n",prog);
|
{
|
||||||
|
printf("usage: %s infile\n", prog);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc,char* argv[])
|
int main(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
char* filename = NULL;
|
char* filename = NULL;
|
||||||
FILE* in = NULL;
|
FILE* in = NULL;
|
||||||
|
|
||||||
/* message handle. Required in all the eccodes calls acting on a message.*/
|
/* message handle. Required in all the eccodes calls acting on a message.*/
|
||||||
codes_handle* h=NULL;
|
codes_handle* h = NULL;
|
||||||
long longVal;
|
long longVal;
|
||||||
int err=0, cnt=0;
|
int err = 0, cnt = 0;
|
||||||
|
|
||||||
if (argc!=2) usage(argv[0]);
|
if (argc != 2) usage(argv[0]);
|
||||||
|
|
||||||
filename=argv[1];
|
filename = argv[1];
|
||||||
|
|
||||||
in=fopen(filename,"rb");
|
in = fopen(filename, "rb");
|
||||||
if (!in) {
|
if (!in) {
|
||||||
printf("ERROR: unable to open file %s\n", filename);
|
printf("ERROR: unable to open file %s\n", filename);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* loop over the messages in the bufr file */
|
/* loop over the messages in the bufr file */
|
||||||
while ((h = codes_handle_new_from_file(NULL,in,PRODUCT_BUFR,&err)) != NULL || err != CODES_SUCCESS)
|
while ((h = codes_handle_new_from_file(NULL, in, PRODUCT_BUFR, &err)) != NULL || err != CODES_SUCCESS) {
|
||||||
{
|
|
||||||
if (h == NULL) {
|
if (h == NULL) {
|
||||||
printf("Error: unable to create handle for message %d\n",cnt);
|
printf("Error: unable to create handle for message %d\n", cnt);
|
||||||
cnt++;
|
cnt++;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("message: %d\n",cnt);
|
printf("message: %d\n", cnt);
|
||||||
|
|
||||||
/* get and print some keys form the BUFR header */
|
/* get and print some keys form the BUFR header */
|
||||||
|
|
||||||
CODES_CHECK(codes_get_long(h,"dataCategory",&longVal),0);
|
CODES_CHECK(codes_get_long(h, "dataCategory", &longVal), 0);
|
||||||
printf(" dataCategory: %ld\n",longVal);
|
printf(" dataCategory: %ld\n", longVal);
|
||||||
|
|
||||||
CODES_CHECK(codes_get_long(h,"dataSubCategory",&longVal),0);
|
CODES_CHECK(codes_get_long(h, "dataSubCategory", &longVal), 0);
|
||||||
printf(" dataSubCategory: %ld\n",longVal);
|
printf(" dataSubCategory: %ld\n", longVal);
|
||||||
|
|
||||||
CODES_CHECK(codes_get_long(h,"typicalDate",&longVal),0);
|
CODES_CHECK(codes_get_long(h, "typicalDate", &longVal), 0);
|
||||||
printf(" typicalDate: %ld\n",longVal);
|
printf(" typicalDate: %ld\n", longVal);
|
||||||
|
|
||||||
CODES_CHECK(codes_get_long(h,"bufrHeaderCentre",&longVal),0);
|
CODES_CHECK(codes_get_long(h, "bufrHeaderCentre", &longVal), 0);
|
||||||
printf(" bufrHeaderCentre: %ld\n",longVal);
|
printf(" bufrHeaderCentre: %ld\n", longVal);
|
||||||
|
|
||||||
CODES_CHECK(codes_get_long(h,"bufrHeaderSubCentre",&longVal),0);
|
CODES_CHECK(codes_get_long(h, "bufrHeaderSubCentre", &longVal), 0);
|
||||||
printf(" bufrHeaderSubCentre: %ld\n",longVal);
|
printf(" bufrHeaderSubCentre: %ld\n", longVal);
|
||||||
|
|
||||||
CODES_CHECK(codes_get_long(h,"masterTablesVersionNumber",&longVal),0);
|
CODES_CHECK(codes_get_long(h, "masterTablesVersionNumber", &longVal), 0);
|
||||||
printf(" masterTablesVersionNumber: %ld\n",longVal);
|
printf(" masterTablesVersionNumber: %ld\n", longVal);
|
||||||
|
|
||||||
CODES_CHECK(codes_get_long(h,"localTablesVersionNumber",&longVal),0);
|
CODES_CHECK(codes_get_long(h, "localTablesVersionNumber", &longVal), 0);
|
||||||
printf(" localTablesVersionNumber: %ld\n",longVal);
|
printf(" localTablesVersionNumber: %ld\n", longVal);
|
||||||
|
|
||||||
CODES_CHECK(codes_get_long(h,"numberOfSubsets",&longVal),0);
|
CODES_CHECK(codes_get_long(h, "numberOfSubsets", &longVal), 0);
|
||||||
printf(" numberOfSubsets: %ld\n",longVal);
|
printf(" numberOfSubsets: %ld\n", longVal);
|
||||||
|
|
||||||
/* delete handle */
|
/* delete handle */
|
||||||
codes_handle_delete(h);
|
codes_handle_delete(h);
|
||||||
|
|
|
@ -23,41 +23,40 @@
|
||||||
|
|
||||||
#include "eccodes.h"
|
#include "eccodes.h"
|
||||||
|
|
||||||
int main(int argc,char* argv[])
|
int main(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
FILE* in = NULL;
|
FILE* in = NULL;
|
||||||
|
|
||||||
/* Message handle. Required in all the eccodes calls acting on a message.*/
|
/* Message handle. Required in all the eccodes calls acting on a message.*/
|
||||||
codes_handle* h=NULL;
|
codes_handle* h = NULL;
|
||||||
|
|
||||||
double *lat=NULL, *lon=NULL, *bscatter=NULL;
|
double *lat = NULL, *lon = NULL, *bscatter = NULL;
|
||||||
long numObs=0;
|
long numObs = 0;
|
||||||
size_t len=0;
|
size_t len = 0;
|
||||||
int i, err=0;
|
int i, err = 0;
|
||||||
int cnt=0;
|
int cnt = 0;
|
||||||
const char* infile = "../../data/bufr/asca_139.bufr";
|
const char* infile = "../../data/bufr/asca_139.bufr";
|
||||||
char key_name[128];
|
char key_name[128];
|
||||||
|
|
||||||
in=fopen(infile,"rb");
|
in = fopen(infile, "rb");
|
||||||
if (!in) {
|
if (!in) {
|
||||||
printf("ERROR: unable to open file %s\n", infile);
|
printf("ERROR: unable to open file %s\n", infile);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Loop over the messages in the bufr file */
|
/* Loop over the messages in the bufr file */
|
||||||
while ((h = codes_handle_new_from_file(NULL,in,PRODUCT_BUFR,&err)) != NULL || err != CODES_SUCCESS)
|
while ((h = codes_handle_new_from_file(NULL, in, PRODUCT_BUFR, &err)) != NULL || err != CODES_SUCCESS) {
|
||||||
{
|
|
||||||
if (h == NULL) {
|
if (h == NULL) {
|
||||||
printf("Error: unable to create handle for message %d\n",cnt);
|
printf("Error: unable to create handle for message %d\n", cnt);
|
||||||
cnt++;
|
cnt++;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("message: %d\n",cnt);
|
printf("message: %d\n", cnt);
|
||||||
|
|
||||||
/* We need to instruct ecCodes to expand the descriptors
|
/* We need to instruct ecCodes to expand the descriptors
|
||||||
* i.e. unpack the data values */
|
* i.e. unpack the data values */
|
||||||
CODES_CHECK(codes_set_long(h,"unpack",1),0);
|
CODES_CHECK(codes_set_long(h, "unpack", 1), 0);
|
||||||
|
|
||||||
/* The BUFR file contains a single message with 2016 subsets in a compressed form.
|
/* The BUFR file contains a single message with 2016 subsets in a compressed form.
|
||||||
* It means each subset has exactly the same structure: they store one location with
|
* It means each subset has exactly the same structure: they store one location with
|
||||||
|
@ -67,60 +66,60 @@ int main(int argc,char* argv[])
|
||||||
* we will simply access the key by condition (see below) */
|
* we will simply access the key by condition (see below) */
|
||||||
|
|
||||||
/* Get the total number of subsets. */
|
/* Get the total number of subsets. */
|
||||||
CODES_CHECK(codes_get_long(h,"numberOfSubsets",&numObs),0);
|
CODES_CHECK(codes_get_long(h, "numberOfSubsets", &numObs), 0);
|
||||||
|
|
||||||
printf("Number of values: %ld\n",numObs);
|
printf("Number of values: %ld\n", numObs);
|
||||||
|
|
||||||
/* Get latitude */
|
/* Get latitude */
|
||||||
sprintf(key_name,"latitude");
|
sprintf(key_name, "latitude");
|
||||||
|
|
||||||
/* Check the size (including all the subsets) */
|
/* Check the size (including all the subsets) */
|
||||||
CODES_CHECK(codes_get_size(h,key_name,&len),0);
|
CODES_CHECK(codes_get_size(h, key_name, &len), 0);
|
||||||
if(len != numObs) {
|
if (len != numObs) {
|
||||||
printf("inconsistent number of %s values found!\n",key_name);
|
printf("inconsistent number of %s values found!\n", key_name);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Allocate memory for the values to be read. Each
|
/* Allocate memory for the values to be read. Each
|
||||||
* parameter must have the same number of values. */
|
* parameter must have the same number of values. */
|
||||||
lat = (double*)malloc(numObs*sizeof(double));
|
lat = (double*)malloc(numObs * sizeof(double));
|
||||||
|
|
||||||
/* Get the values (from all the subsets) */
|
/* Get the values (from all the subsets) */
|
||||||
CODES_CHECK(codes_get_double_array(h,key_name,lat,&len),0);
|
CODES_CHECK(codes_get_double_array(h, key_name, lat, &len), 0);
|
||||||
|
|
||||||
/* Get longitude */
|
/* Get longitude */
|
||||||
sprintf(key_name,"longitude");
|
sprintf(key_name, "longitude");
|
||||||
|
|
||||||
/* Check the size (including all the subsets) */
|
/* Check the size (including all the subsets) */
|
||||||
CODES_CHECK(codes_get_size(h,key_name,&len),0);
|
CODES_CHECK(codes_get_size(h, key_name, &len), 0);
|
||||||
if(len != numObs) {
|
if (len != numObs) {
|
||||||
printf("inconsistent number of %s values found!\n",key_name);
|
printf("inconsistent number of %s values found!\n", key_name);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Get the values (from all the subsets) */
|
/* Get the values (from all the subsets) */
|
||||||
lon = (double*)malloc(numObs*sizeof(double));
|
lon = (double*)malloc(numObs * sizeof(double));
|
||||||
CODES_CHECK(codes_get_double_array(h,key_name,lon,&len),0);
|
CODES_CHECK(codes_get_double_array(h, key_name, lon, &len), 0);
|
||||||
|
|
||||||
/* Get backScatter for beam two. We use an access by condition for this key. */
|
/* Get backScatter for beam two. We use an access by condition for this key. */
|
||||||
sprintf(key_name,"/beamIdentifier=2/backscatter");
|
sprintf(key_name, "/beamIdentifier=2/backscatter");
|
||||||
|
|
||||||
/* Check the size (including all the subsets) */
|
/* Check the size (including all the subsets) */
|
||||||
CODES_CHECK(codes_get_size(h,key_name,&len),0);
|
CODES_CHECK(codes_get_size(h, key_name, &len), 0);
|
||||||
if(len != numObs) {
|
if (len != numObs) {
|
||||||
printf("inconsistent number of %s values found!\n",key_name);
|
printf("inconsistent number of %s values found!\n", key_name);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Get the values (from all the subsets) */
|
/* Get the values (from all the subsets) */
|
||||||
bscatter = (double*)malloc(numObs*sizeof(double));
|
bscatter = (double*)malloc(numObs * sizeof(double));
|
||||||
CODES_CHECK(codes_get_double_array(h,key_name,bscatter,&len),0);
|
CODES_CHECK(codes_get_double_array(h, key_name, bscatter, &len), 0);
|
||||||
|
|
||||||
/* Print the values */
|
/* Print the values */
|
||||||
printf("pixel lat lon backscatter \n");
|
printf("pixel lat lon backscatter \n");
|
||||||
printf("-------------------------------\n");
|
printf("-------------------------------\n");
|
||||||
for(i=0; i < numObs; i++) {
|
for (i = 0; i < numObs; i++) {
|
||||||
printf("%4d %.3f %.3f %.3f \n", i+1,lat[i],lon[i],bscatter[i]);
|
printf("%4d %.3f %.3f %.3f \n", i + 1, lat[i], lon[i], bscatter[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Delete handle */
|
/* Delete handle */
|
||||||
|
|
|
@ -24,67 +24,66 @@
|
||||||
|
|
||||||
#include "eccodes.h"
|
#include "eccodes.h"
|
||||||
|
|
||||||
int main(int argc,char* argv[])
|
int main(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
FILE* in = NULL;
|
FILE* in = NULL;
|
||||||
|
|
||||||
/* message handle. Required in all the eccodes calls acting on a message.*/
|
/* message handle. Required in all the eccodes calls acting on a message.*/
|
||||||
codes_handle* h=NULL;
|
codes_handle* h = NULL;
|
||||||
|
|
||||||
long longVal;
|
long longVal;
|
||||||
double doubleVal;
|
double doubleVal;
|
||||||
int err=0;
|
int err = 0;
|
||||||
int cnt=0;
|
int cnt = 0;
|
||||||
const char* infile = "../../data/bufr/syno_multi.bufr";
|
const char* infile = "../../data/bufr/syno_multi.bufr";
|
||||||
|
|
||||||
in=fopen(infile,"rb");
|
in = fopen(infile, "rb");
|
||||||
if (!in) {
|
if (!in) {
|
||||||
printf("ERROR: unable to open file %s\n", infile);
|
printf("ERROR: unable to open file %s\n", infile);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* loop over the messages in the bufr file */
|
/* loop over the messages in the bufr file */
|
||||||
while ((h = codes_handle_new_from_file(NULL,in,PRODUCT_BUFR,&err)) != NULL || err != CODES_SUCCESS)
|
while ((h = codes_handle_new_from_file(NULL, in, PRODUCT_BUFR, &err)) != NULL || err != CODES_SUCCESS) {
|
||||||
{
|
|
||||||
if (h == NULL) {
|
if (h == NULL) {
|
||||||
printf("Error: unable to create handle for message %d\n",cnt);
|
printf("Error: unable to create handle for message %d\n", cnt);
|
||||||
cnt++;
|
cnt++;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("message: %d\n",cnt);
|
printf("message: %d\n", cnt);
|
||||||
|
|
||||||
/* we need to instruct ecCodes to unpack the data values */
|
/* we need to instruct ecCodes to unpack the data values */
|
||||||
CODES_CHECK(codes_set_long(h,"unpack",1),0);
|
CODES_CHECK(codes_set_long(h, "unpack", 1), 0);
|
||||||
|
|
||||||
/* station id*/
|
/* station id*/
|
||||||
CODES_CHECK(codes_get_long(h,"blockNumber",&longVal),0);
|
CODES_CHECK(codes_get_long(h, "blockNumber", &longVal), 0);
|
||||||
printf(" blockNumber: %ld\n",longVal);
|
printf(" blockNumber: %ld\n", longVal);
|
||||||
|
|
||||||
CODES_CHECK(codes_get_long(h,"stationNumber",&longVal),0);
|
CODES_CHECK(codes_get_long(h, "stationNumber", &longVal), 0);
|
||||||
printf(" stationNumber: %ld\n",longVal);
|
printf(" stationNumber: %ld\n", longVal);
|
||||||
|
|
||||||
/* location*/
|
/* location*/
|
||||||
CODES_CHECK(codes_get_double(h,"latitude",&doubleVal),0);
|
CODES_CHECK(codes_get_double(h, "latitude", &doubleVal), 0);
|
||||||
printf(" latitude: %f\n",doubleVal);
|
printf(" latitude: %f\n", doubleVal);
|
||||||
|
|
||||||
CODES_CHECK(codes_get_double(h,"longitude",&doubleVal),0);
|
CODES_CHECK(codes_get_double(h, "longitude", &doubleVal), 0);
|
||||||
printf(" longitude: %f\n",doubleVal);
|
printf(" longitude: %f\n", doubleVal);
|
||||||
|
|
||||||
/* 2m temperature */
|
/* 2m temperature */
|
||||||
CODES_CHECK(codes_get_double(h,"airTemperatureAt2M",&doubleVal),0);
|
CODES_CHECK(codes_get_double(h, "airTemperatureAt2M", &doubleVal), 0);
|
||||||
printf(" airTemperatureAt2M: %f\n",doubleVal);
|
printf(" airTemperatureAt2M: %f\n", doubleVal);
|
||||||
|
|
||||||
/* 2m dewpoint temperature */
|
/* 2m dewpoint temperature */
|
||||||
CODES_CHECK(codes_get_double(h,"dewpointTemperatureAt2M",&doubleVal),0);
|
CODES_CHECK(codes_get_double(h, "dewpointTemperatureAt2M", &doubleVal), 0);
|
||||||
printf(" dewpointTemperatureAt2M: %f\n",doubleVal);
|
printf(" dewpointTemperatureAt2M: %f\n", doubleVal);
|
||||||
|
|
||||||
/* 10 wind */
|
/* 10 wind */
|
||||||
CODES_CHECK(codes_get_double(h,"windSpeedAt10M",&doubleVal),0);
|
CODES_CHECK(codes_get_double(h, "windSpeedAt10M", &doubleVal), 0);
|
||||||
printf(" windSpeedAt10M: %f\n",doubleVal);
|
printf(" windSpeedAt10M: %f\n", doubleVal);
|
||||||
|
|
||||||
CODES_CHECK(codes_get_double(h,"windDirectionAt10M",&doubleVal),0);
|
CODES_CHECK(codes_get_double(h, "windDirectionAt10M", &doubleVal), 0);
|
||||||
printf(" windDirectionAt10M: %f\n",doubleVal);
|
printf(" windDirectionAt10M: %f\n", doubleVal);
|
||||||
|
|
||||||
/* The cloud information is stored in several blocks in the
|
/* The cloud information is stored in several blocks in the
|
||||||
* SYNOP message and the same key means a different thing in different
|
* SYNOP message and the same key means a different thing in different
|
||||||
|
@ -95,24 +94,24 @@ int main(int argc,char* argv[])
|
||||||
* read so we will use the # (occurrence) operator accordingly. */
|
* read so we will use the # (occurrence) operator accordingly. */
|
||||||
|
|
||||||
/* Cloud amount (low and middleclouds) */
|
/* Cloud amount (low and middleclouds) */
|
||||||
CODES_CHECK(codes_get_long(h,"#1#cloudAmount",&longVal),0);
|
CODES_CHECK(codes_get_long(h, "#1#cloudAmount", &longVal), 0);
|
||||||
printf(" cloudAmount (low and middle): %ld\n",longVal);
|
printf(" cloudAmount (low and middle): %ld\n", longVal);
|
||||||
|
|
||||||
/* Height of cloud base */
|
/* Height of cloud base */
|
||||||
CODES_CHECK(codes_get_long(h,"#1#heightOfBaseOfCloud",&longVal),0);
|
CODES_CHECK(codes_get_long(h, "#1#heightOfBaseOfCloud", &longVal), 0);
|
||||||
printf(" heightOfBaseOfCloud: %ld\n",longVal);
|
printf(" heightOfBaseOfCloud: %ld\n", longVal);
|
||||||
|
|
||||||
/* Cloud type (low clouds) */
|
/* Cloud type (low clouds) */
|
||||||
CODES_CHECK(codes_get_long(h,"#1#cloudType",&longVal),0);
|
CODES_CHECK(codes_get_long(h, "#1#cloudType", &longVal), 0);
|
||||||
printf(" cloudType (low): %ld\n",longVal);
|
printf(" cloudType (low): %ld\n", longVal);
|
||||||
|
|
||||||
/* Cloud type (middle clouds) */
|
/* Cloud type (middle clouds) */
|
||||||
CODES_CHECK(codes_get_long(h,"#2#cloudType",&longVal),0);
|
CODES_CHECK(codes_get_long(h, "#2#cloudType", &longVal), 0);
|
||||||
printf(" cloudType (middle): %ld\n",longVal);
|
printf(" cloudType (middle): %ld\n", longVal);
|
||||||
|
|
||||||
/* Cloud type (high clouds) */
|
/* Cloud type (high clouds) */
|
||||||
CODES_CHECK(codes_get_long(h,"#3#cloudType",&longVal),0);
|
CODES_CHECK(codes_get_long(h, "#3#cloudType", &longVal), 0);
|
||||||
printf(" cloudType (high): %ld\n",longVal);
|
printf(" cloudType (high): %ld\n", longVal);
|
||||||
|
|
||||||
/* delete handle */
|
/* delete handle */
|
||||||
codes_handle_delete(h);
|
codes_handle_delete(h);
|
||||||
|
|
|
@ -23,41 +23,40 @@
|
||||||
|
|
||||||
#include "eccodes.h"
|
#include "eccodes.h"
|
||||||
|
|
||||||
int main(int argc,char* argv[])
|
int main(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
FILE* in = NULL;
|
FILE* in = NULL;
|
||||||
|
|
||||||
/* Message handle. Required in all the eccodes calls acting on a message.*/
|
/* Message handle. Required in all the eccodes calls acting on a message.*/
|
||||||
codes_handle* h=NULL;
|
codes_handle* h = NULL;
|
||||||
|
|
||||||
double *sigt_pres=NULL, *sigt_geo=NULL, *sigt_t=NULL;
|
double *sigt_pres = NULL, *sigt_geo = NULL, *sigt_t = NULL;
|
||||||
double *sigt_td=NULL;
|
double* sigt_td = NULL;
|
||||||
size_t sigt_len=0, len=0, i=0;
|
size_t sigt_len = 0, len = 0, i = 0;
|
||||||
int err=0;
|
int err = 0;
|
||||||
int cnt=0;
|
int cnt = 0;
|
||||||
const char* infile = "../../data/bufr/temp_101.bufr";
|
const char* infile = "../../data/bufr/temp_101.bufr";
|
||||||
char key_name[128];
|
char key_name[128];
|
||||||
|
|
||||||
in=fopen(infile,"rb");
|
in = fopen(infile, "rb");
|
||||||
if (!in) {
|
if (!in) {
|
||||||
printf("ERROR: unable to open file %s\n", infile);
|
printf("ERROR: unable to open file %s\n", infile);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Loop over the messages in the bufr file */
|
/* Loop over the messages in the bufr file */
|
||||||
while ((h = codes_handle_new_from_file(NULL,in,PRODUCT_BUFR,&err)) != NULL || err != CODES_SUCCESS)
|
while ((h = codes_handle_new_from_file(NULL, in, PRODUCT_BUFR, &err)) != NULL || err != CODES_SUCCESS) {
|
||||||
{
|
|
||||||
if (h == NULL) {
|
if (h == NULL) {
|
||||||
printf("Error: unable to create handle for message %d\n",cnt);
|
printf("Error: unable to create handle for message %d\n", cnt);
|
||||||
cnt++;
|
cnt++;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("message: %d\n",cnt);
|
printf("message: %d\n", cnt);
|
||||||
|
|
||||||
/* We need to instruct ecCodes to expand the descriptors
|
/* We need to instruct ecCodes to expand the descriptors
|
||||||
i.e. unpack the data values */
|
i.e. unpack the data values */
|
||||||
CODES_CHECK(codes_set_long(h,"unpack",1),0);
|
CODES_CHECK(codes_set_long(h, "unpack", 1), 0);
|
||||||
|
|
||||||
/* In what follows we rely on the fact that for
|
/* In what follows we rely on the fact that for
|
||||||
* temperature significant levels the value of key
|
* temperature significant levels the value of key
|
||||||
|
@ -75,67 +74,65 @@ int main(int argc,char* argv[])
|
||||||
/* We find out the number of temperature significant levels by
|
/* We find out the number of temperature significant levels by
|
||||||
* counting how many pressure values we have on these levels.*/
|
* counting how many pressure values we have on these levels.*/
|
||||||
|
|
||||||
sprintf(key_name,"/verticalSoundingSignificance=4/pressure");
|
sprintf(key_name, "/verticalSoundingSignificance=4/pressure");
|
||||||
CODES_CHECK(codes_get_size(h,key_name,&sigt_len),0);
|
CODES_CHECK(codes_get_size(h, key_name, &sigt_len), 0);
|
||||||
|
|
||||||
printf("Number of T significant levels: %lu\n",sigt_len);
|
printf("Number of T significant levels: %lu\n", sigt_len);
|
||||||
|
|
||||||
/* Allocate memory for the values to be read. Each
|
/* Allocate memory for the values to be read. Each
|
||||||
* parameter must have the same number of values. */
|
* parameter must have the same number of values. */
|
||||||
sigt_pres = (double*)malloc(sigt_len*sizeof(double));
|
sigt_pres = (double*)malloc(sigt_len * sizeof(double));
|
||||||
sigt_geo = (double*)malloc(sigt_len*sizeof(double));
|
sigt_geo = (double*)malloc(sigt_len * sizeof(double));
|
||||||
sigt_t = (double*)malloc(sigt_len*sizeof(double));
|
sigt_t = (double*)malloc(sigt_len * sizeof(double));
|
||||||
sigt_td = (double*)malloc(sigt_len*sizeof(double));
|
sigt_td = (double*)malloc(sigt_len * sizeof(double));
|
||||||
|
|
||||||
/* Get pressure */
|
/* Get pressure */
|
||||||
sprintf(key_name,"/verticalSoundingSignificance=4/pressure");
|
sprintf(key_name, "/verticalSoundingSignificance=4/pressure");
|
||||||
len=sigt_len;
|
len = sigt_len;
|
||||||
CODES_CHECK(codes_get_double_array(h,key_name,sigt_pres,&len),0);
|
CODES_CHECK(codes_get_double_array(h, key_name, sigt_pres, &len), 0);
|
||||||
|
|
||||||
/* Get geopotential */
|
/* Get geopotential */
|
||||||
sprintf(key_name,"/verticalSoundingSignificance=4/nonCoordinateGeopotential");
|
sprintf(key_name, "/verticalSoundingSignificance=4/nonCoordinateGeopotential");
|
||||||
|
|
||||||
/* Check the size */
|
/* Check the size */
|
||||||
CODES_CHECK(codes_get_size(h,key_name,&len),0);
|
CODES_CHECK(codes_get_size(h, key_name, &len), 0);
|
||||||
if(len != sigt_len)
|
if (len != sigt_len) {
|
||||||
{
|
|
||||||
printf("inconsistent number of geopotential values found!\n");
|
printf("inconsistent number of geopotential values found!\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Get the values */
|
/* Get the values */
|
||||||
CODES_CHECK(codes_get_double_array(h,key_name,sigt_geo,&len),0);
|
CODES_CHECK(codes_get_double_array(h, key_name, sigt_geo, &len), 0);
|
||||||
|
|
||||||
/* Get temperature */
|
/* Get temperature */
|
||||||
if(len != sigt_len) /* Check the size */
|
if (len != sigt_len) /* Check the size */
|
||||||
{
|
{
|
||||||
printf("inconsistent number of temperature values found!\n");
|
printf("inconsistent number of temperature values found!\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Get the values */
|
/* Get the values */
|
||||||
sprintf(key_name,"/verticalSoundingSignificance=4/airTemperature");
|
sprintf(key_name, "/verticalSoundingSignificance=4/airTemperature");
|
||||||
CODES_CHECK(codes_get_double_array(h,key_name,sigt_t,&len),0);
|
CODES_CHECK(codes_get_double_array(h, key_name, sigt_t, &len), 0);
|
||||||
|
|
||||||
/* Get dew point */
|
/* Get dew point */
|
||||||
if(len != sigt_len) /* Check the size */
|
if (len != sigt_len) /* Check the size */
|
||||||
{
|
{
|
||||||
printf("inconsistent number of dewpoint temperature values found!\n");
|
printf("inconsistent number of dewpoint temperature values found!\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Get the values */
|
/* Get the values */
|
||||||
sprintf(key_name,"/verticalSoundingSignificance=4/dewpointTemperature");
|
sprintf(key_name, "/verticalSoundingSignificance=4/dewpointTemperature");
|
||||||
CODES_CHECK(codes_get_double_array(h,key_name,sigt_td,&len),0);
|
CODES_CHECK(codes_get_double_array(h, key_name, sigt_td, &len), 0);
|
||||||
|
|
||||||
/* Print the values */
|
/* Print the values */
|
||||||
printf("lev pres geo t td\n");
|
printf("lev pres geo t td\n");
|
||||||
printf("-------------------------------\n");
|
printf("-------------------------------\n");
|
||||||
|
|
||||||
for(i=0; i < sigt_len; i++)
|
for (i = 0; i < sigt_len; i++) {
|
||||||
{
|
|
||||||
printf("%3lu %6.0f %6.0f %.1f %.1f\n",
|
printf("%3lu %6.0f %6.0f %.1f %.1f\n",
|
||||||
i+1,sigt_pres[i],sigt_geo[i],sigt_t[i],sigt_td[i]);
|
i + 1, sigt_pres[i], sigt_geo[i], sigt_t[i], sigt_td[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Delete handle */
|
/* Delete handle */
|
||||||
|
|
|
@ -17,34 +17,35 @@
|
||||||
|
|
||||||
#include "eccodes.h"
|
#include "eccodes.h"
|
||||||
|
|
||||||
static void usage(const char* prog) {
|
static void usage(const char* prog)
|
||||||
printf("usage: %s infile\n",prog);
|
{
|
||||||
|
printf("usage: %s infile\n", prog);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc,char* argv[])
|
int main(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
FILE* in = NULL;
|
FILE* in = NULL;
|
||||||
FILE* out = NULL;
|
FILE* out = NULL;
|
||||||
|
|
||||||
/* message handle. Required in all the eccodes calls acting on a message.*/
|
/* message handle. Required in all the eccodes calls acting on a message.*/
|
||||||
codes_handle* h=NULL;
|
codes_handle* h = NULL;
|
||||||
|
|
||||||
long longVal;
|
long longVal;
|
||||||
/*double doubleVal;*/
|
/*double doubleVal;*/
|
||||||
int err=0;
|
int err = 0;
|
||||||
int cnt=0;
|
int cnt = 0;
|
||||||
size_t size = 0;
|
size_t size = 0;
|
||||||
const char* infile = "../../data/bufr/syno_multi.bufr";
|
const char* infile = "../../data/bufr/syno_multi.bufr";
|
||||||
const void *buffer = NULL;
|
const void* buffer = NULL;
|
||||||
|
|
||||||
if (argc != 2) {
|
if (argc != 2) {
|
||||||
usage(argv[0]);
|
usage(argv[0]);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
in = fopen(infile,"rb");
|
in = fopen(infile, "rb");
|
||||||
out = fopen(argv[1],"wb");
|
out = fopen(argv[1], "wb");
|
||||||
|
|
||||||
if (!in || !out) {
|
if (!in || !out) {
|
||||||
perror("ERROR: unable to open files");
|
perror("ERROR: unable to open files");
|
||||||
|
@ -54,15 +55,14 @@ int main(int argc,char* argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
/* loop over the messages in the bufr file */
|
/* loop over the messages in the bufr file */
|
||||||
while ((h = codes_handle_new_from_file(NULL,in,PRODUCT_BUFR,&err)) != NULL || err != CODES_SUCCESS)
|
while ((h = codes_handle_new_from_file(NULL, in, PRODUCT_BUFR, &err)) != NULL || err != CODES_SUCCESS) {
|
||||||
{
|
|
||||||
if (h == NULL) {
|
if (h == NULL) {
|
||||||
printf("Error: unable to create handle for message %d\n",cnt);
|
printf("Error: unable to create handle for message %d\n", cnt);
|
||||||
cnt++;
|
cnt++;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("message: %d\n",cnt);
|
printf("message: %d\n", cnt);
|
||||||
|
|
||||||
/* we need to instruct ecCodes to expand the descriptors
|
/* we need to instruct ecCodes to expand the descriptors
|
||||||
i.e. unpack the data values */
|
i.e. unpack the data values */
|
||||||
|
@ -72,20 +72,20 @@ int main(int argc,char* argv[])
|
||||||
/*E.g. we change the centre */
|
/*E.g. we change the centre */
|
||||||
|
|
||||||
/* set bufrHeaderCentre */
|
/* set bufrHeaderCentre */
|
||||||
longVal=222;
|
longVal = 222;
|
||||||
CODES_CHECK(codes_set_long(h, "bufrHeaderCentre", longVal),0);
|
CODES_CHECK(codes_set_long(h, "bufrHeaderCentre", longVal), 0);
|
||||||
printf(" set bufrHeaderCentre to: %ld\n",longVal);
|
printf(" set bufrHeaderCentre to: %ld\n", longVal);
|
||||||
|
|
||||||
/* check bufrHeaderCentre */
|
/* check bufrHeaderCentre */
|
||||||
CODES_CHECK(codes_get_long(h,"bufrHeaderCentre",&longVal),0);
|
CODES_CHECK(codes_get_long(h, "bufrHeaderCentre", &longVal), 0);
|
||||||
printf(" bufrHeaderCentre's new value is: %ld\n",longVal);
|
printf(" bufrHeaderCentre's new value is: %ld\n", longVal);
|
||||||
|
|
||||||
|
|
||||||
/* get the modified message in a buffer */
|
/* get the modified message in a buffer */
|
||||||
CODES_CHECK(codes_get_message(h,&buffer,&size),0);
|
CODES_CHECK(codes_get_message(h, &buffer, &size), 0);
|
||||||
|
|
||||||
/* write the buffer to a file */
|
/* write the buffer to a file */
|
||||||
if(fwrite(buffer,1,size,out) != size) {
|
if (fwrite(buffer, 1, size, out) != size) {
|
||||||
perror(argv[0]);
|
perror(argv[0]);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,74 +18,72 @@
|
||||||
#include "eccodes.h"
|
#include "eccodes.h"
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
int main(int argc,char* argv[])
|
int main(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
char key[200]={0,};
|
char key[200] = {0,};
|
||||||
FILE* in = NULL;
|
FILE* in = NULL;
|
||||||
|
|
||||||
/* message handle. Required in all the eccodes calls acting on a message.*/
|
/* message handle. Required in all the eccodes calls acting on a message.*/
|
||||||
codes_handle* h=NULL;
|
codes_handle* h = NULL;
|
||||||
|
|
||||||
long numberOfSubsets=0;
|
long numberOfSubsets = 0;
|
||||||
long longVal;
|
long longVal;
|
||||||
double doubleVal;
|
double doubleVal;
|
||||||
size_t stringLen;
|
size_t stringLen;
|
||||||
char stringVal[100]={0,};
|
char stringVal[100] = {0,};
|
||||||
int i,err=0;
|
int i, err = 0;
|
||||||
int cnt=0;
|
int cnt = 0;
|
||||||
const char* infile = "../../data/bufr/synop_multi_subset.bufr";
|
const char* infile = "../../data/bufr/synop_multi_subset.bufr";
|
||||||
|
|
||||||
in=fopen(infile,"rb");
|
in = fopen(infile, "rb");
|
||||||
if (!in) {
|
if (!in) {
|
||||||
printf("ERROR: unable to open file %s\n", infile);
|
printf("ERROR: unable to open file %s\n", infile);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* loop over the messages in the bufr file */
|
/* loop over the messages in the bufr file */
|
||||||
while ((h = codes_handle_new_from_file(NULL,in,PRODUCT_BUFR,&err)) != NULL || err != CODES_SUCCESS)
|
while ((h = codes_handle_new_from_file(NULL, in, PRODUCT_BUFR, &err)) != NULL || err != CODES_SUCCESS) {
|
||||||
{
|
|
||||||
if (h == NULL) {
|
if (h == NULL) {
|
||||||
printf("Error: unable to create handle for message %d\n",cnt);
|
printf("Error: unable to create handle for message %d\n", cnt);
|
||||||
cnt++;
|
cnt++;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("message: %d\n",cnt);
|
printf("message: %d\n", cnt);
|
||||||
|
|
||||||
/* we need to instruct ecCodes to expand all the descriptors i.e. unpack the data values */
|
/* we need to instruct ecCodes to expand all the descriptors i.e. unpack the data values */
|
||||||
CODES_CHECK(codes_set_long(h,"unpack",1),0);
|
CODES_CHECK(codes_set_long(h, "unpack", 1), 0);
|
||||||
|
|
||||||
/* find out the number of subsets */
|
/* find out the number of subsets */
|
||||||
CODES_CHECK(codes_get_long(h,"numberOfSubsets",&numberOfSubsets),0);
|
CODES_CHECK(codes_get_long(h, "numberOfSubsets", &numberOfSubsets), 0);
|
||||||
printf(" numberOfSubsets: %ld\n",numberOfSubsets);
|
printf(" numberOfSubsets: %ld\n", numberOfSubsets);
|
||||||
|
|
||||||
/* loop over the subsets */
|
/* loop over the subsets */
|
||||||
for(i=1; i <= numberOfSubsets; i++)
|
for (i = 1; i <= numberOfSubsets; i++) {
|
||||||
{
|
sprintf(key, "/subsetNumber=%d/blockNumber", i);
|
||||||
sprintf(key,"/subsetNumber=%d/blockNumber",i);
|
|
||||||
|
|
||||||
printf(" subsetNumber=%d",i);
|
printf(" subsetNumber=%d", i);
|
||||||
/* read and print some data values */
|
/* read and print some data values */
|
||||||
CODES_CHECK(codes_get_long(h,key,&longVal), 0);
|
CODES_CHECK(codes_get_long(h, key, &longVal), 0);
|
||||||
printf(" blockNumber=%ld",longVal);
|
printf(" blockNumber=%ld", longVal);
|
||||||
|
|
||||||
sprintf(key,"/subsetNumber=%d/stationNumber",i);
|
sprintf(key, "/subsetNumber=%d/stationNumber", i);
|
||||||
CODES_CHECK(codes_get_long(h,key,&longVal), 0);
|
CODES_CHECK(codes_get_long(h, key, &longVal), 0);
|
||||||
printf(" stationNumber=%ld",longVal);
|
printf(" stationNumber=%ld", longVal);
|
||||||
|
|
||||||
sprintf(key,"/subsetNumber=%d/stationOrSiteName->units",i);
|
sprintf(key, "/subsetNumber=%d/stationOrSiteName->units", i);
|
||||||
CODES_CHECK(codes_get_length(h,key,&stringLen), 0);
|
CODES_CHECK(codes_get_length(h, key, &stringLen), 0);
|
||||||
assert(stringLen == 10); /* should be "CCITT IA5" */
|
assert(stringLen == 10); /* should be "CCITT IA5" */
|
||||||
|
|
||||||
sprintf(key,"/subsetNumber=%d/stationOrSiteName",i);
|
sprintf(key, "/subsetNumber=%d/stationOrSiteName", i);
|
||||||
CODES_CHECK(codes_get_length(h,key,&stringLen), 0);
|
CODES_CHECK(codes_get_length(h, key, &stringLen), 0);
|
||||||
CODES_CHECK(codes_get_string(h,key,stringVal,&stringLen), 0);
|
CODES_CHECK(codes_get_string(h, key, stringVal, &stringLen), 0);
|
||||||
assert(stringLen > 0 && stringLen < 17);
|
assert(stringLen > 0 && stringLen < 17);
|
||||||
printf(" stationOrSiteName=\"%s\"",stringVal);
|
printf(" stationOrSiteName=\"%s\"", stringVal);
|
||||||
|
|
||||||
sprintf(key,"/subsetNumber=%d/airTemperature",i);
|
sprintf(key, "/subsetNumber=%d/airTemperature", i);
|
||||||
CODES_CHECK(codes_get_double(h,key,&doubleVal),0);
|
CODES_CHECK(codes_get_double(h, key, &doubleVal), 0);
|
||||||
printf(" airTemperature=%g\n",doubleVal);
|
printf(" airTemperature=%g\n", doubleVal);
|
||||||
assert(doubleVal > 265 && doubleVal < 278);
|
assert(doubleVal > 265 && doubleVal < 278);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,57 +21,58 @@
|
||||||
|
|
||||||
#include "eccodes.h"
|
#include "eccodes.h"
|
||||||
|
|
||||||
void usage(char* prog) {
|
void usage(char* prog)
|
||||||
printf("Usage: %s order_by grib_file grib_file ...\n",prog);
|
{
|
||||||
|
printf("Usage: %s order_by grib_file grib_file ...\n", prog);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
int err = 0;
|
int err = 0;
|
||||||
long step,levelType;
|
long step, levelType;
|
||||||
char** filenames;
|
char** filenames;
|
||||||
size_t nkeys,nfiles;
|
size_t nkeys, nfiles;
|
||||||
int i=0;
|
int i = 0;
|
||||||
char* keys[]={"step","date","param","levelType"};
|
char* keys[] = { "step", "date", "param", "levelType" };
|
||||||
codes_fieldset* set;
|
codes_fieldset* set;
|
||||||
codes_handle* h;
|
codes_handle* h;
|
||||||
char param[20]={0,};
|
char param[20] = {0,};
|
||||||
char date[10]={0,};
|
char date[10] = {0,};
|
||||||
size_t datelen=10;
|
size_t datelen = 10;
|
||||||
size_t len=20;
|
size_t len = 20;
|
||||||
char* order_by=0;
|
char* order_by = 0;
|
||||||
|
|
||||||
if (argc != 3) usage(argv[0]);
|
if (argc != 3) usage(argv[0]);
|
||||||
|
|
||||||
nkeys=sizeof(keys)/sizeof(*keys);
|
nkeys = sizeof(keys) / sizeof(*keys);
|
||||||
order_by=strdup(argv[1]);
|
order_by = strdup(argv[1]);
|
||||||
|
|
||||||
nfiles=argc-2;
|
nfiles = argc - 2;
|
||||||
filenames=(char**)malloc(sizeof(char*)*nfiles);
|
filenames = (char**)malloc(sizeof(char*) * nfiles);
|
||||||
for (i=0;i<nfiles;i++)
|
for (i = 0; i < nfiles; i++)
|
||||||
filenames[i]=(char*)strdup(argv[i+2]);
|
filenames[i] = (char*)strdup(argv[i + 2]);
|
||||||
|
|
||||||
set=codes_fieldset_new_from_files(0,filenames,nfiles,keys,nkeys,0,0,&err);
|
set = codes_fieldset_new_from_files(0, filenames, nfiles, keys, nkeys, 0, 0, &err);
|
||||||
CODES_CHECK(err,0);
|
CODES_CHECK(err, 0);
|
||||||
|
|
||||||
/* not jet implemented */
|
/* not jet implemented */
|
||||||
/* err=codes_fieldset_apply_where(set,"(centre=='ecmf') && number==1 || step==6 "); */
|
/* err=codes_fieldset_apply_where(set,"(centre=='ecmf') && number==1 || step==6 "); */
|
||||||
/* CODES_CHECK(err,0); */
|
/* CODES_CHECK(err,0); */
|
||||||
|
|
||||||
codes_fieldset_apply_order_by(set,order_by);
|
codes_fieldset_apply_order_by(set, order_by);
|
||||||
CODES_CHECK(err,0);
|
CODES_CHECK(err, 0);
|
||||||
|
|
||||||
printf("\nordering by %s\n",order_by);
|
printf("\nordering by %s\n", order_by);
|
||||||
printf("\n%d fields in the fieldset\n",codes_fieldset_count(set));
|
printf("\n%d fields in the fieldset\n", codes_fieldset_count(set));
|
||||||
printf("step,date,levelType,levelType\n");
|
printf("step,date,levelType,levelType\n");
|
||||||
while ((h=codes_fieldset_next_handle(set,&err))!=NULL) {
|
while ((h = codes_fieldset_next_handle(set, &err)) != NULL) {
|
||||||
CODES_CHECK(codes_get_long(h,"step",&step),0);
|
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, "date", date, &datelen), 0);
|
||||||
CODES_CHECK(codes_get_string(h,"param",param,&len),0);
|
CODES_CHECK(codes_get_string(h, "param", param, &len), 0);
|
||||||
CODES_CHECK(codes_get_long(h,"levelType",&levelType),0);
|
CODES_CHECK(codes_get_long(h, "levelType", &levelType), 0);
|
||||||
|
|
||||||
printf("%ld %s %ld %s\n",step,date,levelType,param);
|
printf("%ld %s %ld %s\n", step, date, levelType, param);
|
||||||
codes_handle_delete(h);
|
codes_handle_delete(h);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,18 +15,18 @@
|
||||||
* and print the kind of product (e.g. GRIB, BUFR etc)
|
* and print the kind of product (e.g. GRIB, BUFR etc)
|
||||||
*/
|
*/
|
||||||
#include "eccodes.h"
|
#include "eccodes.h"
|
||||||
static void usage(const char *app)
|
static void usage(const char* app)
|
||||||
{
|
{
|
||||||
fprintf(stderr,"Usage: %s file\n", app);
|
fprintf(stderr, "Usage: %s file\n", app);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc,char* argv[])
|
int main(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
FILE* in = NULL;
|
FILE* in = NULL;
|
||||||
codes_handle* h=NULL;
|
codes_handle* h = NULL;
|
||||||
char* kind= NULL;
|
char* kind = NULL;
|
||||||
size_t len=0;
|
size_t len = 0;
|
||||||
int err=0, cnt=0;
|
int err = 0, cnt = 0;
|
||||||
char* infile = NULL;
|
char* infile = NULL;
|
||||||
|
|
||||||
if (argc != 2) {
|
if (argc != 2) {
|
||||||
|
@ -34,23 +34,22 @@ int main(int argc,char* argv[])
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
infile = argv[1];
|
infile = argv[1];
|
||||||
in=fopen(infile,"rb");
|
in = fopen(infile, "rb");
|
||||||
if (!in) {
|
if (!in) {
|
||||||
printf("ERROR: unable to open file %s\n", infile);
|
printf("ERROR: unable to open file %s\n", infile);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
while ((h = codes_handle_new_from_file(NULL,in,PRODUCT_ANY,&err)) != NULL || err != CODES_SUCCESS)
|
while ((h = codes_handle_new_from_file(NULL, in, PRODUCT_ANY, &err)) != NULL || err != CODES_SUCCESS) {
|
||||||
{
|
|
||||||
if (h == NULL) {
|
if (h == NULL) {
|
||||||
printf("Error: unable to create handle for message %d\n",cnt);
|
printf("Error: unable to create handle for message %d\n", cnt);
|
||||||
cnt++;
|
cnt++;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
printf("message: %d\n",cnt);
|
printf("message: %d\n", cnt);
|
||||||
|
|
||||||
CODES_CHECK(codes_get_length(h, "kindOfProduct", &len), 0);
|
CODES_CHECK(codes_get_length(h, "kindOfProduct", &len), 0);
|
||||||
kind = (char*)malloc(len*sizeof(char));
|
kind = (char*)malloc(len * sizeof(char));
|
||||||
|
|
||||||
codes_get_string(h, "kindOfProduct", kind, &len);
|
codes_get_string(h, "kindOfProduct", kind, &len);
|
||||||
printf(" product: %s\n", kind);
|
printf(" product: %s\n", kind);
|
||||||
|
|
|
@ -18,27 +18,27 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include "eccodes.h"
|
#include "eccodes.h"
|
||||||
|
|
||||||
static void usage(const char *app)
|
static void usage(const char* app)
|
||||||
{
|
{
|
||||||
fprintf(stderr,"Usage is: %s input_file ouput_file\n", app);
|
fprintf(stderr, "Usage is: %s input_file ouput_file\n", app);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
FILE *in = NULL;
|
FILE* in = NULL;
|
||||||
FILE *out = NULL;
|
FILE* out = NULL;
|
||||||
codes_handle *source_handle = NULL;
|
codes_handle* source_handle = NULL;
|
||||||
const void *buffer = NULL;
|
const void* buffer = NULL;
|
||||||
size_t size = 0;
|
size_t size = 0;
|
||||||
int err = 0;
|
int err = 0;
|
||||||
|
|
||||||
if (argc != 3) {
|
if (argc != 3) {
|
||||||
usage(argv[0]);
|
usage(argv[0]);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
in = fopen(argv[1],"rb");
|
in = fopen(argv[1], "rb");
|
||||||
out = fopen(argv[2],"wb");
|
out = fopen(argv[2], "wb");
|
||||||
|
|
||||||
if (!in || !out) {
|
if (!in || !out) {
|
||||||
perror("ERROR: unable to open files");
|
perror("ERROR: unable to open files");
|
||||||
|
@ -48,9 +48,8 @@ int main(int argc, char *argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
/* loop over the messages in the source grib and clone them */
|
/* loop over the messages in the source grib and clone them */
|
||||||
while ((source_handle = codes_handle_new_from_file(0, in, PRODUCT_GRIB, &err))!=NULL)
|
while ((source_handle = codes_handle_new_from_file(0, in, PRODUCT_GRIB, &err)) != NULL) {
|
||||||
{
|
codes_handle* clone_handle = codes_handle_clone(source_handle);
|
||||||
codes_handle *clone_handle = codes_handle_clone(source_handle);
|
|
||||||
|
|
||||||
if (clone_handle == NULL) {
|
if (clone_handle == NULL) {
|
||||||
perror("ERROR: could not clone field");
|
perror("ERROR: could not clone field");
|
||||||
|
@ -64,9 +63,9 @@ int main(int argc, char *argv[])
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* get the coded message in a buffer */
|
/* get the coded message in a buffer */
|
||||||
CODES_CHECK(codes_get_message(clone_handle,&buffer,&size),0);
|
CODES_CHECK(codes_get_message(clone_handle, &buffer, &size), 0);
|
||||||
/* write the buffer to a file */
|
/* write the buffer to a file */
|
||||||
if(fwrite(buffer,1,size,out) != size) {
|
if (fwrite(buffer, 1, size, out) != size) {
|
||||||
perror(argv[1]);
|
perror(argv[1]);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,23 +18,23 @@
|
||||||
#include "eccodes.h"
|
#include "eccodes.h"
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
static void usage(const char *prog)
|
static void usage(const char* prog)
|
||||||
{
|
{
|
||||||
fprintf(stderr,"Usage is: %s input_file ouput_file\n", prog);
|
fprintf(stderr, "Usage is: %s input_file ouput_file\n", prog);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
FILE *in = NULL;
|
FILE* in = NULL;
|
||||||
codes_handle *source_handle = NULL;
|
codes_handle* source_handle = NULL;
|
||||||
int err = 0;
|
int err = 0;
|
||||||
|
|
||||||
if (argc != 3) {
|
if (argc != 3) {
|
||||||
usage(argv[0]);
|
usage(argv[0]);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
in = fopen(argv[1],"rb");
|
in = fopen(argv[1], "rb");
|
||||||
|
|
||||||
if (!in) {
|
if (!in) {
|
||||||
perror("ERROR: unable to input file");
|
perror("ERROR: unable to input file");
|
||||||
|
@ -42,16 +42,15 @@ int main(int argc, char *argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
/* loop over the GRIB messages in the source */
|
/* loop over the GRIB messages in the source */
|
||||||
while ((source_handle = codes_handle_new_from_file(0, in, PRODUCT_GRIB, &err))!=NULL)
|
while ((source_handle = codes_handle_new_from_file(0, in, PRODUCT_GRIB, &err)) != NULL) {
|
||||||
{
|
|
||||||
size_t totalLength = 0, size = 0;
|
size_t totalLength = 0, size = 0;
|
||||||
const void* buffer = NULL;
|
const void* buffer = NULL;
|
||||||
codes_handle* new_handle = NULL;
|
codes_handle* new_handle = NULL;
|
||||||
|
|
||||||
CODES_CHECK(codes_get_message_size(source_handle,&totalLength),0);
|
CODES_CHECK(codes_get_message_size(source_handle, &totalLength), 0);
|
||||||
buffer=(unsigned char*)malloc(totalLength*sizeof(char));
|
buffer = (unsigned char*)malloc(totalLength * sizeof(char));
|
||||||
|
|
||||||
CODES_CHECK(codes_get_message(source_handle, &buffer, &size),0);
|
CODES_CHECK(codes_get_message(source_handle, &buffer, &size), 0);
|
||||||
assert(size == totalLength);
|
assert(size == totalLength);
|
||||||
|
|
||||||
new_handle = codes_handle_new_from_message(0, buffer, totalLength);
|
new_handle = codes_handle_new_from_message(0, buffer, totalLength);
|
||||||
|
@ -60,8 +59,8 @@ int main(int argc, char *argv[])
|
||||||
perror("ERROR: could not create GRIB handle from message");
|
perror("ERROR: could not create GRIB handle from message");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
CODES_CHECK(codes_set_long(new_handle, "hour", 18),0);
|
CODES_CHECK(codes_set_long(new_handle, "hour", 18), 0);
|
||||||
CODES_CHECK(codes_write_message(new_handle, argv[2], "w"),0);
|
CODES_CHECK(codes_write_message(new_handle, argv[2], "w"), 0);
|
||||||
|
|
||||||
codes_handle_delete(new_handle);
|
codes_handle_delete(new_handle);
|
||||||
codes_handle_delete(source_handle);
|
codes_handle_delete(source_handle);
|
||||||
|
|
|
@ -17,41 +17,41 @@
|
||||||
|
|
||||||
#include "eccodes.h"
|
#include "eccodes.h"
|
||||||
|
|
||||||
int main(int argc, char * argv[])
|
int main(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
int i, j;
|
int i, j;
|
||||||
int count=0;
|
int count = 0;
|
||||||
size_t paramIdSize, numberSize, values_len=0;
|
size_t paramIdSize, numberSize, values_len = 0;
|
||||||
char** paramId;
|
char** paramId;
|
||||||
long* number;
|
long* number;
|
||||||
double* values;
|
double* values;
|
||||||
double* result=NULL;
|
double* result = NULL;
|
||||||
double min=1e13,max=-1e13,avg=0;
|
double min = 1e13, max = -1e13, avg = 0;
|
||||||
codes_index* index;
|
codes_index* index;
|
||||||
codes_handle* h=NULL;
|
codes_handle* h = NULL;
|
||||||
|
|
||||||
if (argc<2) return 1;
|
if (argc < 2) return 1;
|
||||||
|
|
||||||
/* create index of file contents for paramId and number */
|
/* create index of file contents for paramId and number */
|
||||||
index = codes_index_new_from_file(0, argv[1], "paramId,number",&ret);
|
index = codes_index_new_from_file(0, argv[1], "paramId,number", &ret);
|
||||||
CODES_CHECK(ret,0);
|
CODES_CHECK(ret, 0);
|
||||||
|
|
||||||
/* get size of "paramId" list */
|
/* get size of "paramId" list */
|
||||||
CODES_CHECK(codes_index_get_size(index, "paramId", ¶mIdSize),0);
|
CODES_CHECK(codes_index_get_size(index, "paramId", ¶mIdSize), 0);
|
||||||
printf("grib contains %lu different parameters\n",paramIdSize);
|
printf("grib contains %lu different parameters\n", paramIdSize);
|
||||||
/* allocate memory for "paramId" list */
|
/* allocate memory for "paramId" list */
|
||||||
paramId = (char**) malloc(paramIdSize * sizeof(char*));
|
paramId = (char**)malloc(paramIdSize * sizeof(char*));
|
||||||
/* get list of "paramId" */
|
/* get list of "paramId" */
|
||||||
CODES_CHECK(codes_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 */
|
/* get size of ensemble number list */
|
||||||
CODES_CHECK(codes_index_get_size(index, "number", &numberSize),0);
|
CODES_CHECK(codes_index_get_size(index, "number", &numberSize), 0);
|
||||||
printf("GRIB contains %lu different ensemble members\n",numberSize);
|
printf("GRIB contains %lu different ensemble members\n", numberSize);
|
||||||
/* allocate memory for ensemble number list */
|
/* allocate memory for ensemble number list */
|
||||||
number = (long*) malloc(numberSize * sizeof(long));
|
number = (long*)malloc(numberSize * sizeof(long));
|
||||||
/* get list of ensemble numbers */
|
/* get list of ensemble numbers */
|
||||||
CODES_CHECK(codes_index_get_long(index, "number", number, &numberSize),0);
|
CODES_CHECK(codes_index_get_long(index, "number", number, &numberSize), 0);
|
||||||
|
|
||||||
/* select T850 with paramId 130 */
|
/* select T850 with paramId 130 */
|
||||||
CODES_CHECK(codes_index_select_string(index, "paramId", "130"), 0);
|
CODES_CHECK(codes_index_select_string(index, "paramId", "130"), 0);
|
||||||
|
@ -63,7 +63,7 @@ int main(int argc, char * argv[])
|
||||||
CODES_CHECK(codes_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 */
|
/* create handle for next GRIB message */
|
||||||
h=codes_handle_new_from_index(index, &ret);
|
h = codes_handle_new_from_index(index, &ret);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
printf("Error: %s\n", codes_get_error_message(ret));
|
printf("Error: %s\n", codes_get_error_message(ret));
|
||||||
exit(ret);
|
exit(ret);
|
||||||
|
@ -76,8 +76,8 @@ int main(int argc, char * argv[])
|
||||||
values = (double*)malloc(values_len * sizeof(double));
|
values = (double*)malloc(values_len * sizeof(double));
|
||||||
|
|
||||||
/* allocate memory for result */
|
/* allocate memory for result */
|
||||||
if ( i == 0 ) {
|
if (i == 0) {
|
||||||
result = (double *)calloc(values_len, sizeof(double));
|
result = (double*)calloc(values_len, sizeof(double));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* get data values */
|
/* get data values */
|
||||||
|
@ -106,15 +106,15 @@ int main(int argc, char * argv[])
|
||||||
}
|
}
|
||||||
avg += result[j];
|
avg += result[j];
|
||||||
}
|
}
|
||||||
avg = avg/values_len;
|
avg = avg / values_len;
|
||||||
|
|
||||||
printf("==============================================================================\n");
|
printf("==============================================================================\n");
|
||||||
printf("Stats for ensemble mean of T850\n");
|
printf("Stats for ensemble mean of T850\n");
|
||||||
printf("Min: %f Max: %f Avg: %f\n",min,max,avg);
|
printf("Min: %f Max: %f Avg: %f\n", min, max, avg);
|
||||||
printf("==============================================================================\n");
|
printf("==============================================================================\n");
|
||||||
|
|
||||||
/* finally free all other memory */
|
/* finally free all other memory */
|
||||||
for (i=0;i<paramIdSize;i++)
|
for (i = 0; i < paramIdSize; i++)
|
||||||
free(paramId[i]);
|
free(paramId[i]);
|
||||||
free(paramId);
|
free(paramId);
|
||||||
free(number);
|
free(number);
|
||||||
|
|
|
@ -19,65 +19,65 @@
|
||||||
|
|
||||||
#include "eccodes.h"
|
#include "eccodes.h"
|
||||||
|
|
||||||
int main (int argc, char **argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
int err = 0;
|
int err = 0;
|
||||||
size_t i = 0;
|
size_t i = 0;
|
||||||
FILE *in = NULL;
|
FILE* in = NULL;
|
||||||
const char *filename = "../../data/reduced_latlon_surface.grib1";
|
const char* filename = "../../data/reduced_latlon_surface.grib1";
|
||||||
codes_handle *h = NULL;
|
codes_handle* h = NULL;
|
||||||
long numberOfPoints = 0;
|
long numberOfPoints = 0;
|
||||||
const double missing = 9999.0;
|
const double missing = 9999.0;
|
||||||
double *lats, *lons, *values; /* arrays */
|
double *lats, *lons, *values; /* arrays */
|
||||||
|
|
||||||
in = fopen(filename, "rb");
|
in = fopen(filename, "rb");
|
||||||
if (!in) {
|
if (!in) {
|
||||||
printf ("ERROR: unable to open input file %s\n", filename);
|
printf("ERROR: unable to open input file %s\n", filename);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* create new handle from a message in a file */
|
/* create new handle from a message in a file */
|
||||||
h = codes_handle_new_from_file (0, in, PRODUCT_GRIB, &err);
|
h = codes_handle_new_from_file(0, in, PRODUCT_GRIB, &err);
|
||||||
if (h == NULL) {
|
if (h == NULL) {
|
||||||
printf ("Error: unable to create handle from file %s\n", filename);
|
printf("Error: unable to create handle from file %s\n", filename);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
CODES_CHECK (codes_get_long (h, "numberOfPoints", &numberOfPoints), 0);
|
CODES_CHECK(codes_get_long(h, "numberOfPoints", &numberOfPoints), 0);
|
||||||
CODES_CHECK (codes_set_double (h, "missingValue", missing), 0);
|
CODES_CHECK(codes_set_double(h, "missingValue", missing), 0);
|
||||||
|
|
||||||
lats = (double *) malloc (numberOfPoints * sizeof (double));
|
lats = (double*)malloc(numberOfPoints * sizeof(double));
|
||||||
if (!lats) {
|
if (!lats) {
|
||||||
printf ("unable to allocate %ld bytes\n", (long) (numberOfPoints * sizeof (double)));
|
printf("unable to allocate %ld bytes\n", (long)(numberOfPoints * sizeof(double)));
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
lons = (double *) malloc (numberOfPoints * sizeof (double));
|
lons = (double*)malloc(numberOfPoints * sizeof(double));
|
||||||
if (!lons) {
|
if (!lons) {
|
||||||
printf ("unable to allocate %ld bytes\n", (long) (numberOfPoints * sizeof (double)));
|
printf("unable to allocate %ld bytes\n", (long)(numberOfPoints * sizeof(double)));
|
||||||
free (lats);
|
free(lats);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
values = (double *) malloc (numberOfPoints * sizeof (double));
|
values = (double*)malloc(numberOfPoints * sizeof(double));
|
||||||
if (!values) {
|
if (!values) {
|
||||||
printf ("unable to allocate %ld bytes\n", (long) (numberOfPoints * sizeof (double)));
|
printf("unable to allocate %ld bytes\n", (long)(numberOfPoints * sizeof(double)));
|
||||||
free (lats);
|
free(lats);
|
||||||
free (lons);
|
free(lons);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
CODES_CHECK (codes_grib_get_data (h, lats, lons, values), 0);
|
CODES_CHECK(codes_grib_get_data(h, lats, lons, values), 0);
|
||||||
|
|
||||||
for (i = 0; i < numberOfPoints; ++i) {
|
for (i = 0; i < numberOfPoints; ++i) {
|
||||||
if (values[i] != missing) {
|
if (values[i] != missing) {
|
||||||
printf ("%f %f %f\n", lats[i], lons[i], values[i]);
|
printf("%f %f %f\n", lats[i], lons[i], values[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
free (lats);
|
free(lats);
|
||||||
free (lons);
|
free(lons);
|
||||||
free (values);
|
free(values);
|
||||||
codes_handle_delete (h);
|
codes_handle_delete(h);
|
||||||
|
|
||||||
fclose (in);
|
fclose(in);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,9 +21,9 @@
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
int err = 0;
|
int err = 0;
|
||||||
double *values = NULL;
|
double* values = NULL;
|
||||||
size_t values_len= 0;
|
size_t values_len = 0;
|
||||||
size_t i = 0, len = 0;
|
size_t i = 0, len = 0;
|
||||||
|
|
||||||
double latitudeOfFirstGridPointInDegrees;
|
double latitudeOfFirstGridPointInDegrees;
|
||||||
|
@ -37,23 +37,23 @@ int main(int argc, char** argv)
|
||||||
long numberOfPointsAlongAParallel;
|
long numberOfPointsAlongAParallel;
|
||||||
long numberOfPointsAlongAMeridian;
|
long numberOfPointsAlongAMeridian;
|
||||||
|
|
||||||
double average = 0;
|
double average = 0;
|
||||||
char* packingType = NULL;
|
char* packingType = NULL;
|
||||||
|
|
||||||
FILE* in = NULL;
|
FILE* in = NULL;
|
||||||
const char* filename = "../../data/regular_latlon_surface.grib1";
|
const char* filename = "../../data/regular_latlon_surface.grib1";
|
||||||
codes_handle *h = NULL;
|
codes_handle* h = NULL;
|
||||||
|
|
||||||
in = fopen(filename,"rb");
|
in = fopen(filename, "rb");
|
||||||
if(!in) {
|
if (!in) {
|
||||||
printf("ERROR: unable to open file %s\n",filename);
|
printf("ERROR: unable to open file %s\n", filename);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* create new handle from the first message in the file*/
|
/* create new handle from the first message in the file*/
|
||||||
h = codes_handle_new_from_file(0, in, PRODUCT_GRIB, &err);
|
h = codes_handle_new_from_file(0, in, PRODUCT_GRIB, &err);
|
||||||
if (h == NULL) {
|
if (h == NULL) {
|
||||||
printf("Error: unable to create handle from file %s\n",filename);
|
printf("Error: unable to create handle from file %s\n", filename);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
fclose(in);
|
fclose(in);
|
||||||
|
@ -63,68 +63,68 @@ int main(int argc, char** argv)
|
||||||
CODES_CHECK(codes_set_string(h, "file", filename, &len), 0);
|
CODES_CHECK(codes_set_string(h, "file", filename, &len), 0);
|
||||||
|
|
||||||
/* get as a long*/
|
/* get as a long*/
|
||||||
CODES_CHECK(codes_get_long(h,"Ni",&numberOfPointsAlongAParallel),0);
|
CODES_CHECK(codes_get_long(h, "Ni", &numberOfPointsAlongAParallel), 0);
|
||||||
printf("numberOfPointsAlongAParallel=%ld\n",numberOfPointsAlongAParallel);
|
printf("numberOfPointsAlongAParallel=%ld\n", numberOfPointsAlongAParallel);
|
||||||
|
|
||||||
/* get as a long*/
|
/* get as a long*/
|
||||||
CODES_CHECK(codes_get_long(h,"Nj",&numberOfPointsAlongAMeridian),0);
|
CODES_CHECK(codes_get_long(h, "Nj", &numberOfPointsAlongAMeridian), 0);
|
||||||
printf("numberOfPointsAlongAMeridian=%ld\n",numberOfPointsAlongAMeridian);
|
printf("numberOfPointsAlongAMeridian=%ld\n", numberOfPointsAlongAMeridian);
|
||||||
|
|
||||||
/* get as a double*/
|
/* get as a double*/
|
||||||
CODES_CHECK(codes_get_double(h,"latitudeOfFirstGridPointInDegrees",&latitudeOfFirstGridPointInDegrees),0);
|
CODES_CHECK(codes_get_double(h, "latitudeOfFirstGridPointInDegrees", &latitudeOfFirstGridPointInDegrees), 0);
|
||||||
printf("latitudeOfFirstGridPointInDegrees=%g\n",latitudeOfFirstGridPointInDegrees);
|
printf("latitudeOfFirstGridPointInDegrees=%g\n", latitudeOfFirstGridPointInDegrees);
|
||||||
|
|
||||||
/* get as a double*/
|
/* get as a double*/
|
||||||
CODES_CHECK(codes_get_double(h,"longitudeOfFirstGridPointInDegrees",&longitudeOfFirstGridPointInDegrees),0);
|
CODES_CHECK(codes_get_double(h, "longitudeOfFirstGridPointInDegrees", &longitudeOfFirstGridPointInDegrees), 0);
|
||||||
printf("longitudeOfFirstGridPointInDegrees=%g\n",longitudeOfFirstGridPointInDegrees);
|
printf("longitudeOfFirstGridPointInDegrees=%g\n", longitudeOfFirstGridPointInDegrees);
|
||||||
|
|
||||||
/* get as a double*/
|
/* get as a double*/
|
||||||
CODES_CHECK(codes_get_double(h,"latitudeOfLastGridPointInDegrees",&latitudeOfLastGridPointInDegrees),0);
|
CODES_CHECK(codes_get_double(h, "latitudeOfLastGridPointInDegrees", &latitudeOfLastGridPointInDegrees), 0);
|
||||||
printf("latitudeOfLastGridPointInDegrees=%g\n",latitudeOfLastGridPointInDegrees);
|
printf("latitudeOfLastGridPointInDegrees=%g\n", latitudeOfLastGridPointInDegrees);
|
||||||
|
|
||||||
/* get as a double*/
|
/* get as a double*/
|
||||||
CODES_CHECK(codes_get_double(h,"longitudeOfLastGridPointInDegrees",&longitudeOfLastGridPointInDegrees),0);
|
CODES_CHECK(codes_get_double(h, "longitudeOfLastGridPointInDegrees", &longitudeOfLastGridPointInDegrees), 0);
|
||||||
printf("longitudeOfLastGridPointInDegrees=%g\n",longitudeOfLastGridPointInDegrees);
|
printf("longitudeOfLastGridPointInDegrees=%g\n", longitudeOfLastGridPointInDegrees);
|
||||||
|
|
||||||
/* get as a double*/
|
/* get as a double*/
|
||||||
CODES_CHECK(codes_get_double(h,"jDirectionIncrementInDegrees",&jDirectionIncrementInDegrees),0);
|
CODES_CHECK(codes_get_double(h, "jDirectionIncrementInDegrees", &jDirectionIncrementInDegrees), 0);
|
||||||
printf("jDirectionIncrementInDegrees=%g\n",jDirectionIncrementInDegrees);
|
printf("jDirectionIncrementInDegrees=%g\n", jDirectionIncrementInDegrees);
|
||||||
|
|
||||||
/* get as a double*/
|
/* get as a double*/
|
||||||
CODES_CHECK(codes_get_double(h,"iDirectionIncrementInDegrees",&iDirectionIncrementInDegrees),0);
|
CODES_CHECK(codes_get_double(h, "iDirectionIncrementInDegrees", &iDirectionIncrementInDegrees), 0);
|
||||||
printf("iDirectionIncrementInDegrees=%g\n",iDirectionIncrementInDegrees);
|
printf("iDirectionIncrementInDegrees=%g\n", iDirectionIncrementInDegrees);
|
||||||
|
|
||||||
/* get as string */
|
/* get as string */
|
||||||
CODES_CHECK(codes_get_length(h, "packingType", &len), 0);
|
CODES_CHECK(codes_get_length(h, "packingType", &len), 0);
|
||||||
packingType = (char*)malloc(len*sizeof(char));
|
packingType = (char*)malloc(len * sizeof(char));
|
||||||
codes_get_string(h, "packingType", packingType, &len);
|
codes_get_string(h, "packingType", packingType, &len);
|
||||||
printf("packingType=%s\n", packingType);
|
printf("packingType=%s\n", packingType);
|
||||||
free(packingType);
|
free(packingType);
|
||||||
|
|
||||||
/* get the size of the values array*/
|
/* get the size of the values array*/
|
||||||
CODES_CHECK(codes_get_size(h,"values",&values_len),0);
|
CODES_CHECK(codes_get_size(h, "values", &values_len), 0);
|
||||||
|
|
||||||
values = (double*)malloc(values_len*sizeof(double));
|
values = (double*)malloc(values_len * sizeof(double));
|
||||||
|
|
||||||
/* get data values*/
|
/* get data values*/
|
||||||
CODES_CHECK(codes_get_double_array(h,"values",values,&values_len),0);
|
CODES_CHECK(codes_get_double_array(h, "values", values, &values_len), 0);
|
||||||
|
|
||||||
average = 0;
|
average = 0;
|
||||||
for(i = 0; i < values_len; i++)
|
for (i = 0; i < values_len; i++)
|
||||||
average += values[i];
|
average += values[i];
|
||||||
|
|
||||||
average /=(double)values_len;
|
average /= (double)values_len;
|
||||||
|
|
||||||
free(values);
|
free(values);
|
||||||
|
|
||||||
printf("There are %d values, average is %g\n",(int)values_len,average);
|
printf("There are %d values, average is %g\n", (int)values_len, average);
|
||||||
|
|
||||||
{
|
{
|
||||||
int eq = 0;
|
int eq = 0;
|
||||||
/* Now retrieve the value of the key "file" */
|
/* Now retrieve the value of the key "file" */
|
||||||
char file[256]={0,};
|
char file[256] = {0,};
|
||||||
CODES_CHECK(codes_get_length(h, "file", &len),0);
|
CODES_CHECK(codes_get_length(h, "file", &len), 0);
|
||||||
assert(len == 1+strlen(filename));
|
assert(len == 1 + strlen(filename));
|
||||||
codes_get_string(h, "file", file, &len);
|
codes_get_string(h, "file", file, &len);
|
||||||
eq = strcmp(file, filename);
|
eq = strcmp(file, filename);
|
||||||
if (eq != 0) assert(!"file and filename not equal");
|
if (eq != 0) assert(!"file and filename not equal");
|
||||||
|
@ -132,11 +132,11 @@ int main(int argc, char** argv)
|
||||||
|
|
||||||
{
|
{
|
||||||
/* Example of getting bytes */
|
/* Example of getting bytes */
|
||||||
const char* name = "reservedNeedNotBePresent";
|
const char* name = "reservedNeedNotBePresent";
|
||||||
unsigned char* byte_val = NULL ;
|
unsigned char* byte_val = NULL;
|
||||||
size_t keySize = 0;
|
size_t keySize = 0;
|
||||||
CODES_CHECK(codes_get_size(h, name, &keySize), 0);
|
CODES_CHECK(codes_get_size(h, name, &keySize), 0);
|
||||||
byte_val = (unsigned char*)malloc(keySize*sizeof(char));
|
byte_val = (unsigned char*)malloc(keySize * sizeof(char));
|
||||||
GRIB_CHECK(codes_get_bytes(h, name, byte_val, &keySize), name);
|
GRIB_CHECK(codes_get_bytes(h, name, byte_val, &keySize), name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,125 +17,142 @@
|
||||||
|
|
||||||
#include "eccodes.h"
|
#include "eccodes.h"
|
||||||
|
|
||||||
static void usage(const char* prog) {
|
static void usage(const char* prog)
|
||||||
printf("usage: %s infile\n",prog);
|
{
|
||||||
|
printf("usage: %s infile\n", prog);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc,char* argv[])
|
int main(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
codes_index* index=NULL;
|
codes_index* index = NULL;
|
||||||
codes_handle* h=NULL;
|
codes_handle* h = NULL;
|
||||||
char* infile=NULL;
|
char* infile = NULL;
|
||||||
long *steps,*levels,*numbers; /* arrays */
|
long *steps, *levels, *numbers; /* arrays */
|
||||||
char** shortName=NULL;
|
char** shortName = NULL;
|
||||||
int i,j,k,l;
|
int i, j, k, l;
|
||||||
size_t stepSize,levelSize,shortNameSize,numberSize;
|
size_t stepSize, levelSize, shortNameSize, numberSize;
|
||||||
long ostep,olevel,onumber;
|
long ostep, olevel, onumber;
|
||||||
char oshortName[200];
|
char oshortName[200];
|
||||||
size_t lenshortName=200;
|
size_t lenshortName = 200;
|
||||||
int ret=0,count=0;
|
int ret = 0, count = 0;
|
||||||
|
|
||||||
if (argc != 2) usage(argv[0]);
|
if (argc != 2) usage(argv[0]);
|
||||||
infile=argv[1];
|
infile = argv[1];
|
||||||
|
|
||||||
printf("indexing...\n");
|
printf("indexing...\n");
|
||||||
|
|
||||||
/* Create an index given set of keys*/
|
/* Create an index given set of keys*/
|
||||||
index=codes_index_new(0,"shortName,level,number,step",&ret);
|
index = codes_index_new(0, "shortName,level,number,step", &ret);
|
||||||
if (ret) {printf("error: %s\n",codes_get_error_message(ret)); exit(ret);}
|
if (ret) {
|
||||||
|
printf("error: %s\n", codes_get_error_message(ret));
|
||||||
|
exit(ret);
|
||||||
|
}
|
||||||
|
|
||||||
/* Indexes a file */
|
/* Indexes a file */
|
||||||
ret=codes_index_add_file(index,infile);
|
ret = codes_index_add_file(index, infile);
|
||||||
if (ret) {printf("error: %s\n",codes_get_error_message(ret)); exit(ret);}
|
if (ret) {
|
||||||
|
printf("error: %s\n", codes_get_error_message(ret));
|
||||||
|
exit(ret);
|
||||||
|
}
|
||||||
printf("end indexing...\n");
|
printf("end indexing...\n");
|
||||||
|
|
||||||
/* get the number of distinct values of "step" in the index */
|
/* get the number of distinct values of "step" in the index */
|
||||||
CODES_CHECK(codes_index_get_size(index,"step",&stepSize),0);
|
CODES_CHECK(codes_index_get_size(index, "step", &stepSize), 0);
|
||||||
steps=(long*)malloc(sizeof(long)*stepSize);
|
steps = (long*)malloc(sizeof(long) * stepSize);
|
||||||
if (!steps) exit(1);
|
if (!steps) exit(1);
|
||||||
/* get the list of distinct steps from the index */
|
/* get the list of distinct steps from the index */
|
||||||
/* the list is in ascending order */
|
/* the list is in ascending order */
|
||||||
CODES_CHECK(codes_index_get_long(index,"step",steps,&stepSize),0);
|
CODES_CHECK(codes_index_get_long(index, "step", steps, &stepSize), 0);
|
||||||
printf("stepSize=%ld\n",(long)stepSize);
|
printf("stepSize=%ld\n", (long)stepSize);
|
||||||
for (i=0;i<stepSize;i++) printf("%ld ",steps[i]);
|
for (i = 0; i < stepSize; i++)
|
||||||
|
printf("%ld ", steps[i]);
|
||||||
printf("\n");
|
printf("\n");
|
||||||
|
|
||||||
/*same as for "step"*/
|
/*same as for "step"*/
|
||||||
CODES_CHECK(codes_index_get_size(index,"level",&levelSize),0);
|
CODES_CHECK(codes_index_get_size(index, "level", &levelSize), 0);
|
||||||
levels=(long*)malloc(sizeof(long)*levelSize);
|
levels = (long*)malloc(sizeof(long) * levelSize);
|
||||||
if (!levels) exit(1);
|
if (!levels) exit(1);
|
||||||
/*same as for "step"*/
|
/*same as for "step"*/
|
||||||
CODES_CHECK(codes_index_get_long(index,"level",levels,&levelSize),0);
|
CODES_CHECK(codes_index_get_long(index, "level", levels, &levelSize), 0);
|
||||||
printf("levelSize=%ld\n",(long)levelSize);
|
printf("levelSize=%ld\n", (long)levelSize);
|
||||||
for (i=0;i<levelSize;i++) printf("%ld ",levels[i]);
|
for (i = 0; i < levelSize; i++)
|
||||||
|
printf("%ld ", levels[i]);
|
||||||
printf("\n");
|
printf("\n");
|
||||||
|
|
||||||
/*same as for "step"*/
|
/*same as for "step"*/
|
||||||
CODES_CHECK(codes_index_get_size(index,"number",&numberSize),0);
|
CODES_CHECK(codes_index_get_size(index, "number", &numberSize), 0);
|
||||||
numbers=(long*)malloc(sizeof(long)*numberSize);
|
numbers = (long*)malloc(sizeof(long) * numberSize);
|
||||||
if (!numbers) exit(1);
|
if (!numbers) exit(1);
|
||||||
/*same as for "step"*/
|
/*same as for "step"*/
|
||||||
CODES_CHECK(codes_index_get_long(index,"number",numbers,&numberSize),0);
|
CODES_CHECK(codes_index_get_long(index, "number", numbers, &numberSize), 0);
|
||||||
printf("numberSize=%ld\n",(long)numberSize);
|
printf("numberSize=%ld\n", (long)numberSize);
|
||||||
for (i=0;i<numberSize;i++) printf("%ld ",numbers[i]);
|
for (i = 0; i < numberSize; i++)
|
||||||
|
printf("%ld ", numbers[i]);
|
||||||
printf("\n");
|
printf("\n");
|
||||||
|
|
||||||
/*same as for "step"*/
|
/*same as for "step"*/
|
||||||
CODES_CHECK(codes_index_get_size(index,"shortName",&shortNameSize),0);
|
CODES_CHECK(codes_index_get_size(index, "shortName", &shortNameSize), 0);
|
||||||
shortName=(char**)malloc(sizeof(char*)*shortNameSize);
|
shortName = (char**)malloc(sizeof(char*) * shortNameSize);
|
||||||
if (!shortName) exit(1);
|
if (!shortName) exit(1);
|
||||||
/*same as for "step"*/
|
/*same as for "step"*/
|
||||||
CODES_CHECK(codes_index_get_string(index,"shortName",shortName,&shortNameSize),0);
|
CODES_CHECK(codes_index_get_string(index, "shortName", shortName, &shortNameSize), 0);
|
||||||
printf("shortNameSize=%ld\n",(long)shortNameSize);
|
printf("shortNameSize=%ld\n", (long)shortNameSize);
|
||||||
for (i=0;i<shortNameSize;i++) printf("%s ",shortName[i]);
|
for (i = 0; i < shortNameSize; i++)
|
||||||
|
printf("%s ", shortName[i]);
|
||||||
printf("\n");
|
printf("\n");
|
||||||
|
|
||||||
count=0;
|
count = 0;
|
||||||
/* nested loops on the keys values of the index */
|
/* nested loops on the keys values of the index */
|
||||||
/* different order of the nested loops doesn't affect performance*/
|
/* different order of the nested loops doesn't affect performance*/
|
||||||
for (i=0;i<shortNameSize;i++) {
|
for (i = 0; i < shortNameSize; i++) {
|
||||||
/* select the GRIB with shortName=shortName[i] */
|
/* select the GRIB with shortName=shortName[i] */
|
||||||
codes_index_select_string(index,"shortName",shortName[i]);
|
codes_index_select_string(index, "shortName", shortName[i]);
|
||||||
|
|
||||||
for (l=0;l<levelSize;l++) {
|
for (l = 0; l < levelSize; l++) {
|
||||||
/* select the GRIB with level=levels[i] */
|
/* select the GRIB with level=levels[i] */
|
||||||
codes_index_select_long(index,"level",levels[l]);
|
codes_index_select_long(index, "level", levels[l]);
|
||||||
|
|
||||||
for (j=0;j<numberSize;j++) {
|
for (j = 0; j < numberSize; j++) {
|
||||||
/* select the GRIB with number=numbers[i] */
|
/* select the GRIB with number=numbers[i] */
|
||||||
codes_index_select_long(index,"number",numbers[j]);
|
codes_index_select_long(index, "number", numbers[j]);
|
||||||
|
|
||||||
for (k=0;k<stepSize;k++) {
|
for (k = 0; k < stepSize; k++) {
|
||||||
/* select the GRIB with step=steps[i] */
|
/* select the GRIB with step=steps[i] */
|
||||||
codes_index_select_long(index,"step",steps[k]);
|
codes_index_select_long(index, "step", steps[k]);
|
||||||
|
|
||||||
/* create a new codes_handle from the index with the constraints
|
/* create a new codes_handle from the index with the constraints
|
||||||
imposed by the select statements. It is a loop because
|
imposed by the select statements. It is a loop because
|
||||||
in the index there could be more than one GRIB with those
|
in the index there could be more than one GRIB with those
|
||||||
constraints */
|
constraints */
|
||||||
while ((h=codes_handle_new_from_index(index,&ret))!=NULL){
|
while ((h = codes_handle_new_from_index(index, &ret)) != NULL) {
|
||||||
count++;
|
count++;
|
||||||
if (ret) {printf("error: %d\n",ret); exit(ret);}
|
if (ret) {
|
||||||
lenshortName=200;
|
printf("error: %d\n", ret);
|
||||||
codes_get_string(h,"shortName",oshortName,&lenshortName);
|
exit(ret);
|
||||||
codes_get_long(h,"level",&olevel);
|
}
|
||||||
codes_get_long(h,"number",&onumber);
|
lenshortName = 200;
|
||||||
codes_get_long(h,"step",&ostep);
|
codes_get_string(h, "shortName", oshortName, &lenshortName);
|
||||||
printf("shortName=%s ",oshortName);
|
codes_get_long(h, "level", &olevel);
|
||||||
printf("level=%ld ",olevel);
|
codes_get_long(h, "number", &onumber);
|
||||||
printf("number=%ld ",onumber);
|
codes_get_long(h, "step", &ostep);
|
||||||
printf("step=%ld \n",ostep);
|
printf("shortName=%s ", oshortName);
|
||||||
|
printf("level=%ld ", olevel);
|
||||||
|
printf("number=%ld ", onumber);
|
||||||
|
printf("step=%ld \n", ostep);
|
||||||
codes_handle_delete(h);
|
codes_handle_delete(h);
|
||||||
}
|
}
|
||||||
if (ret && ret!=GRIB_END_OF_INDEX ) {printf("error: %s\n",codes_get_error_message(ret)); exit(ret);}
|
if (ret && ret != GRIB_END_OF_INDEX) {
|
||||||
|
printf("error: %s\n", codes_get_error_message(ret));
|
||||||
|
exit(ret);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
printf(" %d messages selected\n",count);
|
printf(" %d messages selected\n", count);
|
||||||
|
|
||||||
codes_index_write(index,"out.gribidx");
|
codes_index_write(index, "out.gribidx");
|
||||||
codes_index_delete(index);
|
codes_index_delete(index);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -20,57 +20,59 @@
|
||||||
|
|
||||||
#include "eccodes.h"
|
#include "eccodes.h"
|
||||||
|
|
||||||
static void usage(const char* prog) {
|
static void usage(const char* prog)
|
||||||
printf("Usage: %s grib_file\n",prog);
|
{
|
||||||
|
printf("Usage: %s grib_file\n", prog);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
FILE* in = NULL;
|
FILE* in = NULL;
|
||||||
int err = 0;
|
int err = 0;
|
||||||
double lat,lon,value;
|
double lat, lon, value;
|
||||||
double missingValue = 1e+20; /* A value out of range */
|
double missingValue = 1e+20; /* A value out of range */
|
||||||
int n=0;
|
int n = 0;
|
||||||
char* filename = NULL;
|
char* filename = NULL;
|
||||||
|
|
||||||
/* Message handle. Required in all the ecCodes calls acting on a message.*/
|
/* Message handle. Required in all the ecCodes calls acting on a message.*/
|
||||||
codes_handle *h = NULL;
|
codes_handle* h = NULL;
|
||||||
/* Iterator on lat/lon/values.*/
|
/* Iterator on lat/lon/values.*/
|
||||||
codes_iterator* iter=NULL;
|
codes_iterator* iter = NULL;
|
||||||
|
|
||||||
if (argc != 2) usage(argv[0]);
|
if (argc != 2) usage(argv[0]);
|
||||||
|
|
||||||
filename=argv[1];
|
filename = argv[1];
|
||||||
|
|
||||||
in = fopen(filename,"rb");
|
in = fopen(filename, "rb");
|
||||||
if(!in) {
|
if (!in) {
|
||||||
printf("ERROR: unable to open file %s\n", filename);
|
printf("ERROR: unable to open file %s\n", filename);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Loop on all the messages in a file.*/
|
/* Loop on all the messages in a file.*/
|
||||||
while ((h = codes_handle_new_from_file(0, in, PRODUCT_GRIB, &err)) != NULL ) {
|
while ((h = codes_handle_new_from_file(0, in, PRODUCT_GRIB, &err)) != NULL) {
|
||||||
/* Check of errors after reading a message. */
|
/* Check of errors after reading a message. */
|
||||||
if (err != CODES_SUCCESS) CODES_CHECK(err,0);
|
if (err != CODES_SUCCESS) CODES_CHECK(err, 0);
|
||||||
|
|
||||||
/* Set the double representing the missing value in the field. */
|
/* Set the double representing the missing value in the field. */
|
||||||
/* Choose a missingValue that does not correspond to any real value in the data array */
|
/* Choose a missingValue that does not correspond to any real value in the data array */
|
||||||
CODES_CHECK(codes_set_double(h, "missingValue", missingValue),0);
|
CODES_CHECK(codes_set_double(h, "missingValue", missingValue), 0);
|
||||||
|
|
||||||
/* A new iterator on lat/lon/values is created from the message handle h. */
|
/* A new iterator on lat/lon/values is created from the message handle h. */
|
||||||
iter=codes_grib_iterator_new(h,0,&err);
|
iter = codes_grib_iterator_new(h, 0, &err);
|
||||||
if (err != CODES_SUCCESS) CODES_CHECK(err,0);
|
if (err != CODES_SUCCESS) CODES_CHECK(err, 0);
|
||||||
|
|
||||||
n = 0;
|
n = 0;
|
||||||
/* Loop on all the lat/lon/values. */
|
/* Loop on all the lat/lon/values. */
|
||||||
while(codes_grib_iterator_next(iter,&lat,&lon,&value)) {
|
while (codes_grib_iterator_next(iter, &lat, &lon, &value)) {
|
||||||
/* You can now print lat and lon, */
|
/* You can now print lat and lon, */
|
||||||
printf("- %d - lat=%f lon=%f value=",n,lat,lon);
|
printf("- %d - lat=%f lon=%f value=", n, lat, lon);
|
||||||
/* decide what to print if a missing value is found. */
|
/* decide what to print if a missing value is found. */
|
||||||
if (value == missingValue ) printf("missing\n");
|
if (value == missingValue) printf("missing\n");
|
||||||
/* and print the value if is not missing. */
|
/* and print the value if is not missing. */
|
||||||
else printf("%f\n",value);
|
else
|
||||||
|
printf("%f\n", value);
|
||||||
n++;
|
n++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,64 +21,61 @@
|
||||||
|
|
||||||
static void usage(const char* prog)
|
static void usage(const char* prog)
|
||||||
{
|
{
|
||||||
printf("Usage: %s grib_file\n",prog);
|
printf("Usage: %s grib_file\n", prog);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
FILE* in = NULL;
|
FILE* in = NULL;
|
||||||
int err = 0;
|
int err = 0;
|
||||||
double lat,lon,value;
|
double lat, lon, value;
|
||||||
int n=0;
|
int n = 0;
|
||||||
size_t bmp_len = 0, values_len = 0;
|
size_t bmp_len = 0, values_len = 0;
|
||||||
char* filename = NULL;
|
char* filename = NULL;
|
||||||
long bitmapPresent = 0;
|
long bitmapPresent = 0;
|
||||||
long *bitmap = NULL;
|
long* bitmap = NULL;
|
||||||
double *values = NULL;
|
double* values = NULL;
|
||||||
codes_handle *h = NULL;
|
codes_handle* h = NULL;
|
||||||
codes_iterator* iter=NULL;
|
codes_iterator* iter = NULL;
|
||||||
|
|
||||||
if (argc != 2) usage(argv[0]);
|
if (argc != 2) usage(argv[0]);
|
||||||
filename=argv[1];
|
filename = argv[1];
|
||||||
in = fopen(filename,"rb");
|
in = fopen(filename, "rb");
|
||||||
if(!in) {
|
if (!in) {
|
||||||
fprintf(stderr, "ERROR: unable to open file %s\n",filename);
|
fprintf(stderr, "ERROR: unable to open file %s\n", filename);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
while ((h = codes_handle_new_from_file(0, in, PRODUCT_GRIB, &err)) != NULL )
|
while ((h = codes_handle_new_from_file(0, in, PRODUCT_GRIB, &err)) != NULL) {
|
||||||
{
|
if (err != CODES_SUCCESS) CODES_CHECK(err, 0);
|
||||||
if (err != CODES_SUCCESS) CODES_CHECK(err,0);
|
|
||||||
|
|
||||||
CODES_CHECK(codes_get_long(h,"bitmapPresent",&bitmapPresent),0);
|
CODES_CHECK(codes_get_long(h, "bitmapPresent", &bitmapPresent), 0);
|
||||||
if (bitmapPresent)
|
if (bitmapPresent) {
|
||||||
{
|
CODES_CHECK(codes_get_size(h, "bitmap", &bmp_len), 0);
|
||||||
CODES_CHECK(codes_get_size(h,"bitmap",&bmp_len),0);
|
bitmap = (long*)malloc(bmp_len * sizeof(long));
|
||||||
bitmap = (long*)malloc(bmp_len*sizeof(long));
|
CODES_CHECK(codes_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 = %lu\n", bmp_len);
|
printf("Bitmap is present. Num = %lu\n", bmp_len);
|
||||||
}
|
}
|
||||||
/* Sanity check. Number of values must match number in bitmap */
|
/* Sanity check. Number of values must match number in bitmap */
|
||||||
CODES_CHECK(codes_get_size(h,"values",&values_len),0);
|
CODES_CHECK(codes_get_size(h, "values", &values_len), 0);
|
||||||
values = (double*)malloc(values_len*sizeof(double));
|
values = (double*)malloc(values_len * sizeof(double));
|
||||||
CODES_CHECK(codes_get_double_array(h,"values",values,&values_len),0);
|
CODES_CHECK(codes_get_double_array(h, "values", values, &values_len), 0);
|
||||||
if (bitmapPresent) {
|
if (bitmapPresent) {
|
||||||
assert(values_len==bmp_len);
|
assert(values_len == bmp_len);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* A new iterator on lat/lon/values is created from the message handle h */
|
/* A new iterator on lat/lon/values is created from the message handle h */
|
||||||
iter=codes_grib_iterator_new(h,0,&err);
|
iter = codes_grib_iterator_new(h, 0, &err);
|
||||||
if (err != CODES_SUCCESS) CODES_CHECK(err,0);
|
if (err != CODES_SUCCESS) CODES_CHECK(err, 0);
|
||||||
|
|
||||||
n = 0;
|
n = 0;
|
||||||
/* Loop on all the lat/lon/values. Only print non-missing values */
|
/* Loop on all the lat/lon/values. Only print non-missing values */
|
||||||
while(codes_grib_iterator_next(iter,&lat,&lon,&value))
|
while (codes_grib_iterator_next(iter, &lat, &lon, &value)) {
|
||||||
{
|
|
||||||
/* Consult bitmap to see if the n'th value is missing */
|
/* Consult bitmap to see if the n'th value is missing */
|
||||||
int is_missing_val = (bitmapPresent && bitmap[n] == 0);
|
int is_missing_val = (bitmapPresent && bitmap[n] == 0);
|
||||||
if (!is_missing_val) {
|
if (!is_missing_val) {
|
||||||
printf("- %d - lat=%f lon=%f value=%f\n",n,lat,lon,value);
|
printf("- %d - lat=%f lon=%f value=%f\n", n, lat, lon, value);
|
||||||
}
|
}
|
||||||
n++;
|
n++;
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,11 +28,11 @@
|
||||||
|
|
||||||
#include "eccodes.h"
|
#include "eccodes.h"
|
||||||
|
|
||||||
#define MAX_VAL_LEN 1024
|
#define MAX_VAL_LEN 1024
|
||||||
|
|
||||||
static void usage(char* progname);
|
static void usage(char* progname);
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
/* To skip read only and computed keys
|
/* To skip read only and computed keys
|
||||||
unsigned long key_iterator_filter_flags=CODES_KEYS_ITERATOR_SKIP_READ_ONLY |
|
unsigned long key_iterator_filter_flags=CODES_KEYS_ITERATOR_SKIP_READ_ONLY |
|
||||||
|
@ -42,54 +42,52 @@ int main(int argc, char *argv[])
|
||||||
CODES_KEYS_ITERATOR_SKIP_DUPLICATES;
|
CODES_KEYS_ITERATOR_SKIP_DUPLICATES;
|
||||||
|
|
||||||
/* Choose a namespace. E.g. "ls", "time", "parameter", "geography", "statistics" */
|
/* Choose a namespace. E.g. "ls", "time", "parameter", "geography", "statistics" */
|
||||||
const char* name_space="ls";
|
const char* name_space = "ls";
|
||||||
|
|
||||||
/* name_space=NULL to get all the keys */
|
/* name_space=NULL to get all the keys */
|
||||||
/* char* name_space=0; */
|
/* char* name_space=0; */
|
||||||
|
|
||||||
FILE* f = NULL;
|
FILE* f = NULL;
|
||||||
codes_handle* h=NULL;
|
codes_handle* h = NULL;
|
||||||
|
|
||||||
int err=0;
|
int err = 0;
|
||||||
int msg_count=0;
|
int msg_count = 0;
|
||||||
|
|
||||||
char value[MAX_VAL_LEN];
|
char value[MAX_VAL_LEN];
|
||||||
size_t vlen=MAX_VAL_LEN;
|
size_t vlen = MAX_VAL_LEN;
|
||||||
|
|
||||||
if (argc != 2) usage(argv[0]);
|
if (argc != 2) usage(argv[0]);
|
||||||
|
|
||||||
f = fopen(argv[1],"rb");
|
f = fopen(argv[1], "rb");
|
||||||
if(!f) {
|
if (!f) {
|
||||||
perror(argv[1]);
|
perror(argv[1]);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
while((h = codes_handle_new_from_file(0,f,PRODUCT_GRIB,&err)) != NULL)
|
while ((h = codes_handle_new_from_file(0, f, PRODUCT_GRIB, &err)) != NULL) {
|
||||||
{
|
codes_keys_iterator* kiter = NULL;
|
||||||
codes_keys_iterator* kiter=NULL;
|
|
||||||
msg_count++;
|
msg_count++;
|
||||||
printf("-- GRIB N. %d --\n",msg_count);
|
printf("-- GRIB N. %d --\n", msg_count);
|
||||||
if(!h) {
|
if (!h) {
|
||||||
printf("ERROR: Unable to create grib handle\n");
|
printf("ERROR: Unable to create grib handle\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
kiter=codes_keys_iterator_new(h,key_iterator_filter_flags,name_space);
|
kiter = codes_keys_iterator_new(h, key_iterator_filter_flags, name_space);
|
||||||
if (!kiter) {
|
if (!kiter) {
|
||||||
printf("ERROR: Unable to create keys iterator\n");
|
printf("ERROR: Unable to create keys iterator\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
while(codes_keys_iterator_next(kiter))
|
while (codes_keys_iterator_next(kiter)) {
|
||||||
{
|
|
||||||
const char* name = codes_keys_iterator_get_name(kiter);
|
const char* name = codes_keys_iterator_get_name(kiter);
|
||||||
vlen=MAX_VAL_LEN;
|
vlen = MAX_VAL_LEN;
|
||||||
memset(value, 0, vlen);
|
memset(value, 0, vlen);
|
||||||
CODES_CHECK(codes_get_string(h,name,value,&vlen),name);
|
CODES_CHECK(codes_get_string(h, name, value, &vlen), name);
|
||||||
printf("%s = %s\n",name,value);
|
printf("%s = %s\n", name, value);
|
||||||
|
|
||||||
/* Alternative way of getting the string value */
|
/* Alternative way of getting the string value */
|
||||||
CODES_CHECK(codes_keys_iterator_get_string(kiter, value, &vlen),0);
|
CODES_CHECK(codes_keys_iterator_get_string(kiter, value, &vlen), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
codes_keys_iterator_delete(kiter);
|
codes_keys_iterator_delete(kiter);
|
||||||
|
@ -101,6 +99,6 @@ int main(int argc, char *argv[])
|
||||||
|
|
||||||
static void usage(char* progname)
|
static void usage(char* progname)
|
||||||
{
|
{
|
||||||
printf("\nUsage: %s grib_file\n",progname);
|
printf("\nUsage: %s grib_file\n", progname);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,67 +31,67 @@ int main(int argc, char** argv)
|
||||||
long values[1024];
|
long values[1024];
|
||||||
long new_values[1024];
|
long new_values[1024];
|
||||||
|
|
||||||
FILE* in = NULL;
|
FILE* in = NULL;
|
||||||
const char* filename = "../../data/satellite.grib";
|
const char* filename = "../../data/satellite.grib";
|
||||||
codes_handle *h = NULL;
|
codes_handle* h = NULL;
|
||||||
|
|
||||||
in = fopen(filename,"rb");
|
in = fopen(filename, "rb");
|
||||||
if(!in) {
|
if (!in) {
|
||||||
printf("ERROR: unable to open input file %s\n",filename);
|
printf("ERROR: unable to open input file %s\n", filename);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* create new handle from a message in a file*/
|
/* create new handle from a message in a file*/
|
||||||
h = codes_handle_new_from_file(0, in, PRODUCT_GRIB, &err);
|
h = codes_handle_new_from_file(0, in, PRODUCT_GRIB, &err);
|
||||||
if (h == NULL) {
|
if (h == NULL) {
|
||||||
printf("Error: unable to create handle from file %s\n",filename);
|
printf("Error: unable to create handle from file %s\n", filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
CODES_CHECK(codes_get_long(h,"numberOfContributingSpectralBands",&numberOfContributingSpectralBands),0);
|
CODES_CHECK(codes_get_long(h, "numberOfContributingSpectralBands", &numberOfContributingSpectralBands), 0);
|
||||||
assert(numberOfContributingSpectralBands == 3);
|
assert(numberOfContributingSpectralBands == 3);
|
||||||
|
|
||||||
/* Shrink NB to 2 */
|
/* Shrink NB to 2 */
|
||||||
numberOfContributingSpectralBands = 2;
|
numberOfContributingSpectralBands = 2;
|
||||||
CODES_CHECK(codes_set_long(h,"numberOfContributingSpectralBands",numberOfContributingSpectralBands),0);
|
CODES_CHECK(codes_set_long(h, "numberOfContributingSpectralBands", numberOfContributingSpectralBands), 0);
|
||||||
|
|
||||||
/* Expand NB to 9 */
|
/* Expand NB to 9 */
|
||||||
numberOfContributingSpectralBands = 9;
|
numberOfContributingSpectralBands = 9;
|
||||||
CODES_CHECK(codes_set_long(h,"numberOfContributingSpectralBands",numberOfContributingSpectralBands),0);
|
CODES_CHECK(codes_set_long(h, "numberOfContributingSpectralBands", numberOfContributingSpectralBands), 0);
|
||||||
|
|
||||||
/* get as a long*/
|
/* get as a long*/
|
||||||
CODES_CHECK(codes_get_long(h,"numberOfContributingSpectralBands",&numberOfContributingSpectralBands),0);
|
CODES_CHECK(codes_get_long(h, "numberOfContributingSpectralBands", &numberOfContributingSpectralBands), 0);
|
||||||
printf("numberOfContributingSpectralBands=%ld\n",numberOfContributingSpectralBands);
|
printf("numberOfContributingSpectralBands=%ld\n", numberOfContributingSpectralBands);
|
||||||
|
|
||||||
/* get as a long*/
|
/* get as a long*/
|
||||||
CODES_CHECK(codes_get_size(h,"scaledValueOfCentralWaveNumber",&count),0);
|
CODES_CHECK(codes_get_size(h, "scaledValueOfCentralWaveNumber", &count), 0);
|
||||||
printf("count=%ld\n",(long)count);
|
printf("count=%ld\n", (long)count);
|
||||||
|
|
||||||
assert(count < sizeof(values)/sizeof(values[0]));
|
assert(count < sizeof(values) / sizeof(values[0]));
|
||||||
|
|
||||||
size = count;
|
size = count;
|
||||||
CODES_CHECK(codes_get_long_array(h,"scaledValueOfCentralWaveNumber",values,&size),0);
|
CODES_CHECK(codes_get_long_array(h, "scaledValueOfCentralWaveNumber", values, &size), 0);
|
||||||
assert(size == count);
|
assert(size == count);
|
||||||
|
|
||||||
for(i=0;i<count;i++) {
|
for (i = 0; i < count; i++) {
|
||||||
printf("scaledValueOfCentralWaveNumber %lu = %ld\n",(unsigned long)i,values[i]);
|
printf("scaledValueOfCentralWaveNumber %lu = %ld\n", (unsigned long)i, values[i]);
|
||||||
if (i == 0) assert( values[i] == 26870 );
|
if (i == 0) assert(values[i] == 26870);
|
||||||
if (i == 1) assert( values[i] == 9272 );
|
if (i == 1) assert(values[i] == 9272);
|
||||||
}
|
}
|
||||||
|
|
||||||
for(i=0;i<count;i++)
|
for (i = 0; i < count; i++)
|
||||||
values[i] = i+1000;
|
values[i] = i + 1000;
|
||||||
|
|
||||||
size = count;
|
size = count;
|
||||||
/* size--; */
|
/* size--; */
|
||||||
CODES_CHECK(codes_set_long_array(h,"scaledValueOfCentralWaveNumber",values,size),0);
|
CODES_CHECK(codes_set_long_array(h, "scaledValueOfCentralWaveNumber", values, size), 0);
|
||||||
assert(size == count);
|
assert(size == count);
|
||||||
|
|
||||||
/* check what we set */
|
/* check what we set */
|
||||||
CODES_CHECK(codes_get_long_array(h,"scaledValueOfCentralWaveNumber",new_values,&size),0);
|
CODES_CHECK(codes_get_long_array(h, "scaledValueOfCentralWaveNumber", new_values, &size), 0);
|
||||||
assert(size == count);
|
assert(size == count);
|
||||||
for(i=0;i<count;i++) {
|
for (i = 0; i < count; i++) {
|
||||||
printf("Now scaledValueOfCentralWaveNumber %lu = %ld\n",(unsigned long)i,new_values[i]);
|
printf("Now scaledValueOfCentralWaveNumber %lu = %ld\n", (unsigned long)i, new_values[i]);
|
||||||
assert( new_values[i] == (i+1000) );
|
assert(new_values[i] == (i + 1000));
|
||||||
}
|
}
|
||||||
|
|
||||||
codes_handle_delete(h);
|
codes_handle_delete(h);
|
||||||
|
|
|
@ -23,11 +23,11 @@
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
int err = 0;
|
int err = 0;
|
||||||
long parameterCategory=0,parameterNumber=0,discipline=0;
|
long parameterCategory = 0, parameterNumber = 0, discipline = 0;
|
||||||
FILE* in = NULL;
|
FILE* in = NULL;
|
||||||
const char* filename = "../../data/multi.grib2";
|
const char* filename = "../../data/multi.grib2";
|
||||||
codes_handle *h = NULL;
|
codes_handle* h = NULL;
|
||||||
|
|
||||||
/* turn on support for multi fields messages */
|
/* turn on support for multi fields messages */
|
||||||
codes_grib_multi_support_on(0);
|
codes_grib_multi_support_on(0);
|
||||||
|
@ -35,26 +35,25 @@ int main(int argc, char** argv)
|
||||||
/* turn off support for multi fields messages */
|
/* turn off support for multi fields messages */
|
||||||
/* codes_multi_support_off(0); */
|
/* codes_multi_support_off(0); */
|
||||||
|
|
||||||
in = fopen(filename,"rb");
|
in = fopen(filename, "rb");
|
||||||
if(!in) {
|
if (!in) {
|
||||||
printf("ERROR: unable to open file %s\n",filename);
|
printf("ERROR: unable to open file %s\n", filename);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
while ((h = codes_handle_new_from_file(0, in, PRODUCT_GRIB, &err)) != NULL ) {
|
while ((h = codes_handle_new_from_file(0, in, PRODUCT_GRIB, &err)) != NULL) {
|
||||||
|
CODES_CHECK(err, 0);
|
||||||
|
|
||||||
CODES_CHECK(err,0);
|
CODES_CHECK(codes_get_long(h, "discipline", &discipline), 0);
|
||||||
|
printf("discipline=%ld\n", discipline);
|
||||||
|
|
||||||
CODES_CHECK(codes_get_long(h,"discipline",&discipline),0);
|
CODES_CHECK(codes_get_long(h, "parameterCategory", ¶meterCategory), 0);
|
||||||
printf("discipline=%ld\n",discipline);
|
printf("parameterCategory=%ld\n", parameterCategory);
|
||||||
|
|
||||||
CODES_CHECK(codes_get_long(h,"parameterCategory",¶meterCategory),0);
|
CODES_CHECK(codes_get_long(h, "parameterNumber", ¶meterNumber), 0);
|
||||||
printf("parameterCategory=%ld\n",parameterCategory);
|
printf("parameterNumber=%ld\n", parameterNumber);
|
||||||
|
|
||||||
CODES_CHECK(codes_get_long(h,"parameterNumber",¶meterNumber),0);
|
if (discipline == 0 && parameterCategory == 2) {
|
||||||
printf("parameterNumber=%ld\n",parameterNumber);
|
|
||||||
|
|
||||||
if ( discipline == 0 && parameterCategory==2) {
|
|
||||||
if (parameterNumber == 2) printf("-------- u -------\n");
|
if (parameterNumber == 2) printf("-------- u -------\n");
|
||||||
if (parameterNumber == 3) printf("-------- v -------\n");
|
if (parameterNumber == 3) printf("-------- v -------\n");
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,67 +18,68 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include "eccodes.h"
|
#include "eccodes.h"
|
||||||
|
|
||||||
static void usage(const char* prog) {
|
static void usage(const char* prog)
|
||||||
printf("usage: %s in.grib out.grib\n",prog);
|
{
|
||||||
|
printf("usage: %s in.grib out.grib\n", prog);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
int err = 0;
|
int err = 0;
|
||||||
FILE* in = NULL;
|
FILE* in = NULL;
|
||||||
FILE* of = NULL;
|
FILE* of = NULL;
|
||||||
long edition, step;
|
long edition, step;
|
||||||
char* filename=NULL;
|
char* filename = NULL;
|
||||||
char* ofilename=NULL;
|
char* ofilename = NULL;
|
||||||
codes_handle *h = NULL;
|
codes_handle* h = NULL;
|
||||||
codes_multi_handle *mh=NULL;
|
codes_multi_handle* mh = NULL;
|
||||||
const int start_section = 4; /* Grib2 Product Definition Section */
|
const int start_section = 4; /* Grib2 Product Definition Section */
|
||||||
|
|
||||||
if (argc < 3) usage(argv[0]);
|
if (argc < 3) usage(argv[0]);
|
||||||
filename=argv[1];
|
filename = argv[1];
|
||||||
ofilename=argv[2];
|
ofilename = argv[2];
|
||||||
|
|
||||||
/* open input file */
|
/* open input file */
|
||||||
in = fopen(filename,"rb");
|
in = fopen(filename, "rb");
|
||||||
if(!in) {
|
if (!in) {
|
||||||
fprintf(stderr, "ERROR: unable to open input file %s\n",filename);
|
fprintf(stderr, "ERROR: unable to open input file %s\n", filename);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* new grib handle from input file */
|
/* new grib handle from input file */
|
||||||
h = codes_handle_new_from_file(0, in, PRODUCT_GRIB, &err);
|
h = codes_handle_new_from_file(0, in, PRODUCT_GRIB, &err);
|
||||||
CODES_CHECK(err,0);
|
CODES_CHECK(err, 0);
|
||||||
CODES_CHECK(codes_get_long(h,"edition",&edition),0);
|
CODES_CHECK(codes_get_long(h, "edition", &edition), 0);
|
||||||
if (edition != 2) {
|
if (edition != 2) {
|
||||||
fprintf(stderr, "ERROR: Input grib must be edition 2 for multi fields\n");
|
fprintf(stderr, "ERROR: Input grib must be edition 2 for multi fields\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* create a new empty multi field handle */
|
/* create a new empty multi field handle */
|
||||||
mh=codes_grib_multi_handle_new(0);
|
mh = codes_grib_multi_handle_new(0);
|
||||||
if (!mh) {
|
if (!mh) {
|
||||||
fprintf(stderr,"ERROR: Unable to create multi field handle\n");
|
fprintf(stderr, "ERROR: Unable to create multi field handle\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (step=12;step<=120;step+=12) {
|
for (step = 12; step <= 120; step += 12) {
|
||||||
/* set step */
|
/* set step */
|
||||||
codes_set_long(h,"step",step);
|
codes_set_long(h, "step", step);
|
||||||
/* append h to mh repeating from section 4 */
|
/* 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 */
|
/* i.e. starting from section 4 all the sections to the end of the message will be copied */
|
||||||
codes_grib_multi_handle_append(h, start_section, mh);
|
codes_grib_multi_handle_append(h, start_section, mh);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* open output file */
|
/* open output file */
|
||||||
of=fopen(ofilename,"w");
|
of = fopen(ofilename, "w");
|
||||||
if(!of) {
|
if (!of) {
|
||||||
fprintf(stderr, "ERROR: unable to open output file %s\n",ofilename);
|
fprintf(stderr, "ERROR: unable to open output file %s\n", ofilename);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* write multi fields handle to output file */
|
/* write multi fields handle to output file */
|
||||||
codes_grib_multi_handle_write(mh,of);
|
codes_grib_multi_handle_write(mh, of);
|
||||||
fclose(of);
|
fclose(of);
|
||||||
|
|
||||||
/* release memory */
|
/* release memory */
|
||||||
|
|
|
@ -21,64 +21,66 @@
|
||||||
|
|
||||||
#include "eccodes.h"
|
#include "eccodes.h"
|
||||||
|
|
||||||
static void usage(const char* prog) {
|
static void usage(const char* prog)
|
||||||
printf("Usage: %s grib_file grib_file ...\n",prog);
|
{
|
||||||
|
printf("Usage: %s grib_file grib_file ...\n", prog);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
int err = 0;
|
int err = 0;
|
||||||
long step=0;
|
long step = 0;
|
||||||
size_t nfiles;
|
size_t nfiles;
|
||||||
int i=0;
|
int i = 0;
|
||||||
codes_fieldset* set=NULL;
|
codes_fieldset* set = NULL;
|
||||||
codes_handle* h=NULL;
|
codes_handle* h = NULL;
|
||||||
char param[20]={0,};
|
char param[20] = {0,};
|
||||||
size_t len=20;
|
size_t len = 20;
|
||||||
double lats[4]={0,};
|
double lats[4] = {0,};
|
||||||
double lons[4]={0,};
|
double lons[4] = {0,};
|
||||||
double values[4]={0,};
|
double values[4] = {0,};
|
||||||
double distances[4]={0,};
|
double distances[4] = {0,};
|
||||||
int indexes[4]={0,};
|
int indexes[4] = {0,};
|
||||||
char* order_by="param,step";
|
char* order_by = "param,step";
|
||||||
|
|
||||||
size_t size=4;
|
size_t size = 4;
|
||||||
double lat=-40,lon=15;
|
double lat = -40, lon = 15;
|
||||||
int mode=0;
|
int mode = 0;
|
||||||
int count;
|
int count;
|
||||||
char** filenames;
|
char** filenames;
|
||||||
codes_nearest* nearest=NULL;
|
codes_nearest* nearest = NULL;
|
||||||
|
|
||||||
if (argc < 2) usage(argv[0]);
|
if (argc < 2) usage(argv[0]);
|
||||||
|
|
||||||
nfiles=argc-1;
|
nfiles = argc - 1;
|
||||||
filenames=(char**)malloc(sizeof(char*)*nfiles);
|
filenames = (char**)malloc(sizeof(char*) * nfiles);
|
||||||
for (i=0;i<nfiles;i++)
|
for (i = 0; i < nfiles; i++)
|
||||||
filenames[i]=(char*)strdup(argv[i+1]);
|
filenames[i] = (char*)strdup(argv[i + 1]);
|
||||||
|
|
||||||
set=codes_fieldset_new_from_files(0,filenames,nfiles,0,0,0,order_by,&err);
|
set = codes_fieldset_new_from_files(0, filenames, nfiles, 0, 0, 0, order_by, &err);
|
||||||
CODES_CHECK(err,0);
|
CODES_CHECK(err, 0);
|
||||||
|
|
||||||
printf("\nordering by %s\n",order_by);
|
printf("\nordering by %s\n", order_by);
|
||||||
printf("\n%d fields in the fieldset\n",codes_fieldset_count(set));
|
printf("\n%d fields in the fieldset\n", codes_fieldset_count(set));
|
||||||
printf("n,step,param\n");
|
printf("n,step,param\n");
|
||||||
|
|
||||||
mode=CODES_NEAREST_SAME_GRID | CODES_NEAREST_SAME_POINT;
|
mode = CODES_NEAREST_SAME_GRID | CODES_NEAREST_SAME_POINT;
|
||||||
count=1;
|
count = 1;
|
||||||
|
|
||||||
while ((h=codes_fieldset_next_handle(set,&err))!=NULL) {
|
while ((h = codes_fieldset_next_handle(set, &err)) != NULL) {
|
||||||
CODES_CHECK(codes_get_long(h,"step",&step),0);
|
CODES_CHECK(codes_get_long(h, "step", &step), 0);
|
||||||
len=20;
|
len = 20;
|
||||||
CODES_CHECK(codes_get_string(h,"shortName",param,&len),0);
|
CODES_CHECK(codes_get_string(h, "shortName", param, &len), 0);
|
||||||
|
|
||||||
printf("%d %ld %s ",count,step,param);
|
printf("%d %ld %s ", count, step, param);
|
||||||
if (!nearest) nearest=codes_grib_nearest_new(h,&err);
|
if (!nearest) nearest = codes_grib_nearest_new(h, &err);
|
||||||
CODES_CHECK(err,0);
|
CODES_CHECK(err, 0);
|
||||||
CODES_CHECK(codes_grib_nearest_find(nearest,h,lat,lon,mode,lats,lons,values,distances,indexes,&size),0);
|
CODES_CHECK(codes_grib_nearest_find(nearest, h, lat, lon, mode, lats, lons, values, distances, indexes, &size), 0);
|
||||||
printf("\nIdx\tlat\tlon\tdist\tval\n");
|
printf("\nIdx\tlat\tlon\tdist\tval\n");
|
||||||
for (i=0;i<4;i++) printf("%d\t%.2f\t%.2f\t%g\t%g\n",
|
for (i = 0; i < 4; i++)
|
||||||
(int)indexes[i],lats[i],lons[i],distances[i],values[i]);
|
printf("%d\t%.2f\t%.2f\t%g\t%g\n",
|
||||||
|
(int)indexes[i], lats[i], lons[i], distances[i], values[i]);
|
||||||
printf("\n");
|
printf("\n");
|
||||||
|
|
||||||
codes_handle_delete(h);
|
codes_handle_delete(h);
|
||||||
|
|
|
@ -15,8 +15,9 @@
|
||||||
|
|
||||||
#include "eccodes.h"
|
#include "eccodes.h"
|
||||||
|
|
||||||
static void usage(const char* prog) {
|
static void usage(const char* prog)
|
||||||
fprintf(stderr, "Usage: %s latlon_file grib_orography grib_file grib_file ...\n",prog);
|
{
|
||||||
|
fprintf(stderr, "Usage: %s latlon_file grib_orography grib_file grib_file ...\n", prog);
|
||||||
fprintf(stderr, " The latlon_file should have 3 columns: num lat lon\n");
|
fprintf(stderr, " The latlon_file should have 3 columns: num lat lon\n");
|
||||||
fprintf(stderr, " The grib_orography file is treated as the land-sea mask\n");
|
fprintf(stderr, " The grib_orography file is treated as the land-sea mask\n");
|
||||||
fprintf(stderr, "\n");
|
fprintf(stderr, "\n");
|
||||||
|
@ -25,22 +26,22 @@ static void usage(const char* prog) {
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
FILE* fin=0;
|
FILE* fin = 0;
|
||||||
int ret=0;
|
int ret = 0;
|
||||||
char* fname=0;
|
char* fname = 0;
|
||||||
float lat,lon;
|
float lat, lon;
|
||||||
double *vlat,*vlon;
|
double *vlat, *vlon;
|
||||||
int npoints=0,i=0,n=0;
|
int npoints = 0, i = 0, n = 0;
|
||||||
codes_handle* h;
|
codes_handle* h;
|
||||||
double *outlats,*outlons,*values,*lsm_values,*distances;
|
double *outlats, *outlons, *values, *lsm_values, *distances;
|
||||||
int* indexes;
|
int* indexes;
|
||||||
/*long step=0;
|
/*long step=0;
|
||||||
char time[10]={0,};
|
char time[10]={0,};
|
||||||
char date[10]={0,};
|
char date[10]={0,};
|
||||||
long parameter=0;
|
long parameter=0;
|
||||||
size_t len=0;*/
|
size_t len=0;*/
|
||||||
long iid=0;
|
long iid = 0;
|
||||||
long *id=NULL;
|
long* id = NULL;
|
||||||
const int is_lsm = 1;
|
const int is_lsm = 1;
|
||||||
|
|
||||||
if (argc < 2) usage(argv[0]);
|
if (argc < 2) usage(argv[0]);
|
||||||
|
@ -48,64 +49,109 @@ int main(int argc, char** argv)
|
||||||
/* Input lat/lon file should have 3 columns:
|
/* Input lat/lon file should have 3 columns:
|
||||||
* number latitude longitude
|
* number latitude longitude
|
||||||
*/
|
*/
|
||||||
fname=argv[1];
|
fname = argv[1];
|
||||||
fin=fopen(fname,"r"); /* Open in text mode */
|
fin = fopen(fname, "r"); /* Open in text mode */
|
||||||
if(!fin) { perror(fname); exit(1); }
|
if (!fin) {
|
||||||
npoints=0;
|
perror(fname);
|
||||||
while (fscanf(fin,"%ld %g %g",&iid,&lat,&lon) != EOF) npoints++;
|
exit(1);
|
||||||
|
}
|
||||||
|
npoints = 0;
|
||||||
|
while (fscanf(fin, "%ld %g %g", &iid, &lat, &lon) != EOF)
|
||||||
|
npoints++;
|
||||||
fclose(fin);
|
fclose(fin);
|
||||||
|
|
||||||
id=(long*)malloc(npoints*sizeof(long));
|
id = (long*)malloc(npoints * sizeof(long));
|
||||||
if (!id) {printf("unable to allocate %ld bytes\n",(long)(npoints*sizeof(long)));exit(1);}
|
if (!id) {
|
||||||
vlat=(double*)malloc(npoints*sizeof(double));
|
printf("unable to allocate %ld bytes\n", (long)(npoints * sizeof(long)));
|
||||||
if (!vlat) {printf("unable to allocate %ld bytes\n",(long)(npoints*sizeof(double)));exit(1);}
|
exit(1);
|
||||||
vlon=(double*)malloc(npoints*sizeof(double));
|
}
|
||||||
if (!vlon) {printf("unable to allocate %ld bytes\n",(long)(npoints*sizeof(double)));exit(1);}
|
vlat = (double*)malloc(npoints * sizeof(double));
|
||||||
outlats=(double*)malloc(npoints*sizeof(double));
|
if (!vlat) {
|
||||||
if (!outlats) {printf("unable to allocate %ld bytes\n",(long)(npoints*sizeof(double)));exit(1);}
|
printf("unable to allocate %ld bytes\n", (long)(npoints * sizeof(double)));
|
||||||
outlons=(double*)malloc(npoints*sizeof(double));
|
exit(1);
|
||||||
if (!outlons) {printf("unable to allocate %ld bytes\n",(long)(npoints*sizeof(double)));exit(1);}
|
}
|
||||||
values=(double*)malloc(npoints*sizeof(double));
|
vlon = (double*)malloc(npoints * sizeof(double));
|
||||||
if (!values) {printf("unable to allocate %ld bytes\n",(long)(npoints*sizeof(double)));exit(1);}
|
if (!vlon) {
|
||||||
lsm_values=(double*)malloc(npoints*sizeof(double));
|
printf("unable to allocate %ld bytes\n", (long)(npoints * sizeof(double)));
|
||||||
if (!lsm_values) {printf("unable to allocate %ld bytes\n",(long)(npoints*sizeof(double)));exit(1);}
|
exit(1);
|
||||||
distances=(double*)malloc(npoints*sizeof(double));
|
}
|
||||||
if (!distances) {printf("unable to allocate %ld bytes\n",(long)(npoints*sizeof(double)));exit(1);}
|
outlats = (double*)malloc(npoints * sizeof(double));
|
||||||
indexes=(int*)malloc(npoints*sizeof(int));
|
if (!outlats) {
|
||||||
if (!indexes) {printf("unable to allocate %ld bytes\n",(long)(npoints*sizeof(double)));exit(1);}
|
printf("unable to allocate %ld bytes\n", (long)(npoints * sizeof(double)));
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
outlons = (double*)malloc(npoints * sizeof(double));
|
||||||
|
if (!outlons) {
|
||||||
|
printf("unable to allocate %ld bytes\n", (long)(npoints * sizeof(double)));
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
values = (double*)malloc(npoints * sizeof(double));
|
||||||
|
if (!values) {
|
||||||
|
printf("unable to allocate %ld bytes\n", (long)(npoints * sizeof(double)));
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
lsm_values = (double*)malloc(npoints * sizeof(double));
|
||||||
|
if (!lsm_values) {
|
||||||
|
printf("unable to allocate %ld bytes\n", (long)(npoints * sizeof(double)));
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
distances = (double*)malloc(npoints * sizeof(double));
|
||||||
|
if (!distances) {
|
||||||
|
printf("unable to allocate %ld bytes\n", (long)(npoints * sizeof(double)));
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
indexes = (int*)malloc(npoints * sizeof(int));
|
||||||
|
if (!indexes) {
|
||||||
|
printf("unable to allocate %ld bytes\n", (long)(npoints * sizeof(double)));
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
fname=argv[1];
|
fname = argv[1];
|
||||||
fin=fopen(fname,"r"); /* Open in text mode */
|
fin = fopen(fname, "r"); /* Open in text mode */
|
||||||
if(!fin) { perror(fname); exit(1); }
|
if (!fin) {
|
||||||
i=0;
|
perror(fname);
|
||||||
while (fscanf(fin,"%ld %g %g",&iid,&lat,&lon) != EOF) {
|
exit(1);
|
||||||
id[i]=iid;vlat[i]=lat;
|
}
|
||||||
while(lon < 0) lon+=360;
|
i = 0;
|
||||||
vlon[i]=lon;
|
while (fscanf(fin, "%ld %g %g", &iid, &lat, &lon) != EOF) {
|
||||||
|
id[i] = iid;
|
||||||
|
vlat[i] = lat;
|
||||||
|
while (lon < 0)
|
||||||
|
lon += 360;
|
||||||
|
vlon[i] = lon;
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
fclose(fin);
|
fclose(fin);
|
||||||
|
|
||||||
/* The first GRIB file on the arguments is treated as the land-sea mask file */
|
/* The first GRIB file on the arguments is treated as the land-sea mask file */
|
||||||
fname=argv[2];
|
fname = argv[2];
|
||||||
fin=fopen(fname,"rb"); /* Open GRIB in binary mode */
|
fin = fopen(fname, "rb"); /* Open GRIB in binary mode */
|
||||||
if(!fin) { perror(fname); exit(1); }
|
if (!fin) {
|
||||||
h=codes_handle_new_from_file(0,fin,PRODUCT_GRIB, &ret);
|
perror(fname);
|
||||||
if (!h || ret!=CODES_SUCCESS) {printf(" unable to create handle\n");exit(1);}
|
exit(1);
|
||||||
|
}
|
||||||
|
h = codes_handle_new_from_file(0, fin, PRODUCT_GRIB, &ret);
|
||||||
|
if (!h || ret != CODES_SUCCESS) {
|
||||||
|
printf(" unable to create handle\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
codes_grib_nearest_find_multiple(h,is_lsm,vlat,vlon,npoints,
|
codes_grib_nearest_find_multiple(h, is_lsm, vlat, vlon, npoints,
|
||||||
outlats,outlons,lsm_values,distances,indexes);
|
outlats, outlons, lsm_values, distances, indexes);
|
||||||
|
|
||||||
codes_handle_delete(h);
|
codes_handle_delete(h);
|
||||||
|
|
||||||
fclose(fin);
|
fclose(fin);
|
||||||
|
|
||||||
for (n=3;n<=argc-1;n++) {
|
for (n = 3; n <= argc - 1; n++) {
|
||||||
fname=argv[n];
|
fname = argv[n];
|
||||||
fin=fopen(fname,"r");
|
fin = fopen(fname, "r");
|
||||||
if(!fin) { perror(fname); exit(1); }
|
if (!fin) {
|
||||||
while ((h=codes_handle_new_from_file(0,fin,PRODUCT_GRIB,&ret))!=NULL) {
|
perror(fname);
|
||||||
codes_get_double_elements(h,"values",indexes,npoints,values);
|
exit(1);
|
||||||
|
}
|
||||||
|
while ((h = codes_handle_new_from_file(0, fin, PRODUCT_GRIB, &ret)) != NULL) {
|
||||||
|
codes_get_double_elements(h, "values", indexes, npoints, values);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
CODES_CHECK(codes_get_length(h, "date", &len),0);
|
CODES_CHECK(codes_get_length(h, "date", &len),0);
|
||||||
|
@ -117,10 +163,10 @@ int main(int argc, char** argv)
|
||||||
printf("# %s %s %ld %ld\n",date,time,step,parameter);
|
printf("# %s %s %ld %ld\n",date,time,step,parameter);
|
||||||
*/
|
*/
|
||||||
codes_handle_delete(h);
|
codes_handle_delete(h);
|
||||||
for (i=0;i<npoints;i++)
|
for (i = 0; i < npoints; i++)
|
||||||
printf("%ld %.2f %.2f %.2f %.2f %d\n",
|
printf("%ld %.2f %.2f %.2f %.2f %d\n",
|
||||||
id[i],outlats[i],outlons[i],
|
id[i], outlats[i], outlons[i],
|
||||||
lsm_values[i],values[i], indexes[i]);
|
lsm_values[i], values[i], indexes[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
fclose(fin);
|
fclose(fin);
|
||||||
|
|
|
@ -25,44 +25,44 @@
|
||||||
|
|
||||||
#include "eccodes.h"
|
#include "eccodes.h"
|
||||||
|
|
||||||
void usage(const char* prog) {
|
void usage(const char* prog)
|
||||||
printf("usage: %s filename\n",prog);
|
{
|
||||||
|
printf("usage: %s filename\n", prog);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
int err = 0,i;
|
int err = 0, i;
|
||||||
double *values = NULL;
|
double* values = NULL;
|
||||||
double max,min,average;
|
double max, min, average;
|
||||||
size_t values_len= 0;
|
size_t values_len = 0;
|
||||||
|
|
||||||
FILE* in = NULL;
|
FILE* in = NULL;
|
||||||
char* filename ;
|
char* filename;
|
||||||
codes_handle *h = NULL;
|
codes_handle* h = NULL;
|
||||||
|
|
||||||
if (argc<2) usage(argv[0]);
|
if (argc < 2) usage(argv[0]);
|
||||||
filename=argv[1];
|
filename = argv[1];
|
||||||
|
|
||||||
in = fopen(filename,"rb");
|
in = fopen(filename, "rb");
|
||||||
if(!in) {
|
if (!in) {
|
||||||
printf("ERROR: unable to open file %s\n",filename);
|
printf("ERROR: unable to open file %s\n", filename);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* create new handle from a message in a file*/
|
/* create new handle from a message in a file*/
|
||||||
while((h = codes_handle_new_from_file(0,in,&err)) != NULL) {
|
while ((h = codes_handle_new_from_file(0, in, &err)) != NULL) {
|
||||||
|
|
||||||
/* get the size of the values array*/
|
/* get the size of the values array*/
|
||||||
CODES_CHECK(codes_get_size(h,"values",&values_len),0);
|
CODES_CHECK(codes_get_size(h, "values", &values_len), 0);
|
||||||
|
|
||||||
values = malloc(values_len*sizeof(double));
|
values = malloc(values_len * sizeof(double));
|
||||||
|
|
||||||
/* get data values*/
|
/* get data values*/
|
||||||
CODES_CHECK(codes_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++)
|
for (i = 0; i < values_len; i++)
|
||||||
printf("%d %.10e\n",i+1,values[i]);
|
printf("%d %.10e\n", i + 1, values[i]);
|
||||||
|
|
||||||
free(values);
|
free(values);
|
||||||
|
|
||||||
|
|
|
@ -21,39 +21,39 @@
|
||||||
|
|
||||||
#include "eccodes.h"
|
#include "eccodes.h"
|
||||||
|
|
||||||
#define EPSILON 1e-6
|
#define EPSILON 1e-6
|
||||||
#define EXPECTED_MIN 270.466796875
|
#define EXPECTED_MIN 270.466796875
|
||||||
#define EXPECTED_MAX 311.096796875
|
#define EXPECTED_MAX 311.096796875
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
int err = 0;
|
int err = 0;
|
||||||
size_t size=0;
|
size_t size = 0;
|
||||||
|
|
||||||
FILE* in = NULL;
|
FILE* in = NULL;
|
||||||
const char* infile = "../../data/regular_latlon_surface.grib1";
|
const char* infile = "../../data/regular_latlon_surface.grib1";
|
||||||
FILE* out = NULL;
|
FILE* out = NULL;
|
||||||
const char* outfile = "out.precision.grib1";
|
const char* outfile = "out.precision.grib1";
|
||||||
codes_handle *h = NULL;
|
codes_handle* h = NULL;
|
||||||
const void* buffer = NULL;
|
const void* buffer = NULL;
|
||||||
double* values1=NULL;
|
double* values1 = NULL;
|
||||||
double* values2=NULL;
|
double* values2 = NULL;
|
||||||
double maxa=0;
|
double maxa = 0;
|
||||||
double maxv=0,minv=0;
|
double maxv = 0, minv = 0;
|
||||||
double maxr=0,r=0;
|
double maxr = 0, r = 0;
|
||||||
long decimalPrecision;
|
long decimalPrecision;
|
||||||
long bitsPerValue1=0, bitsPerValue2=0;
|
long bitsPerValue1 = 0, bitsPerValue2 = 0;
|
||||||
int i=0;
|
int i = 0;
|
||||||
|
|
||||||
in = fopen(infile,"rb");
|
in = fopen(infile, "rb");
|
||||||
if(!in) {
|
if (!in) {
|
||||||
printf("ERROR: unable to open input file %s\n",infile);
|
printf("ERROR: unable to open input file %s\n", infile);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
out = fopen(outfile,"wb");
|
out = fopen(outfile, "wb");
|
||||||
if(!out) {
|
if (!out) {
|
||||||
printf("ERROR: unable to open output file %s\n",outfile);
|
printf("ERROR: unable to open output file %s\n", outfile);
|
||||||
fclose(in);
|
fclose(in);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -61,60 +61,59 @@ int main(int argc, char** argv)
|
||||||
/* create a new handle from a message in a file */
|
/* create a new handle from a message in a file */
|
||||||
h = codes_handle_new_from_file(0, in, PRODUCT_GRIB, &err);
|
h = codes_handle_new_from_file(0, in, PRODUCT_GRIB, &err);
|
||||||
if (h == NULL) {
|
if (h == NULL) {
|
||||||
printf("Error: unable to create handle from file %s\n",infile);
|
printf("Error: unable to create handle from file %s\n", infile);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* bitsPerValue before changing the packing parameters */
|
/* bitsPerValue before changing the packing parameters */
|
||||||
CODES_CHECK(codes_get_long(h,"bitsPerValue",&bitsPerValue1),0);
|
CODES_CHECK(codes_get_long(h, "bitsPerValue", &bitsPerValue1), 0);
|
||||||
assert(bitsPerValue1 == 16);
|
assert(bitsPerValue1 == 16);
|
||||||
|
|
||||||
/* get the size of the values array*/
|
/* get the size of the values array*/
|
||||||
CODES_CHECK(codes_get_size(h,"values",&size),0);
|
CODES_CHECK(codes_get_size(h, "values", &size), 0);
|
||||||
assert(size == 496);
|
assert(size == 496);
|
||||||
|
|
||||||
values1 = (double*)malloc(size*sizeof(double));
|
values1 = (double*)malloc(size * sizeof(double));
|
||||||
/* get data values before changing the packing parameters*/
|
/* get data values before changing the packing parameters*/
|
||||||
CODES_CHECK(codes_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
|
/* changing decimal precision to 2 means that 2 decimal digits
|
||||||
are preserved when packing. */
|
are preserved when packing. */
|
||||||
decimalPrecision=2;
|
decimalPrecision = 2;
|
||||||
CODES_CHECK(codes_set_long(h,"changeDecimalPrecision",decimalPrecision),0);
|
CODES_CHECK(codes_set_long(h, "changeDecimalPrecision", decimalPrecision), 0);
|
||||||
|
|
||||||
/* bitsPerValue after changing the packing parameters */
|
/* bitsPerValue after changing the packing parameters */
|
||||||
CODES_CHECK(codes_get_long(h,"bitsPerValue",&bitsPerValue2),0);
|
CODES_CHECK(codes_get_long(h, "bitsPerValue", &bitsPerValue2), 0);
|
||||||
assert(bitsPerValue2 == 12);
|
assert(bitsPerValue2 == 12);
|
||||||
|
|
||||||
values2 = (double*)malloc(size*sizeof(double));
|
values2 = (double*)malloc(size * sizeof(double));
|
||||||
/* get data values after changing the packing parameters*/
|
/* get data values after changing the packing parameters*/
|
||||||
CODES_CHECK(codes_get_double_array(h,"values",values2,&size),0);
|
CODES_CHECK(codes_get_double_array(h, "values", values2, &size), 0);
|
||||||
|
|
||||||
/* computing error */
|
/* computing error */
|
||||||
maxa=0;
|
maxa = 0;
|
||||||
maxr=0;
|
maxr = 0;
|
||||||
maxv=values2[0];
|
maxv = values2[0];
|
||||||
minv=maxv;
|
minv = maxv;
|
||||||
for (i=0;i<size;i++) {
|
for (i = 0; i < size; i++) {
|
||||||
double a=fabs(values2[i]-values1[i]);
|
double a = fabs(values2[i] - values1[i]);
|
||||||
if ( values2[i] > maxv ) maxv=values2[i];
|
if (values2[i] > maxv) maxv = values2[i];
|
||||||
if ( values2[i] < minv ) minv=values2[i];
|
if (values2[i] < minv) minv = values2[i];
|
||||||
if ( values2[i] !=0 ) r=fabs((values2[i]-values1[i])/values2[i]);
|
if (values2[i] != 0) r = fabs((values2[i] - values1[i]) / values2[i]);
|
||||||
if ( a > maxa ) maxa=a;
|
if (a > maxa) maxa = a;
|
||||||
if ( r > maxr ) maxr=r;
|
if (r > maxr) maxr = r;
|
||||||
}
|
}
|
||||||
printf("max absolute error = %g\n",maxa);
|
printf("max absolute error = %g\n", maxa);
|
||||||
printf("max relative error = %g\n",maxr);
|
printf("max relative error = %g\n", maxr);
|
||||||
printf("min value = %g\n",minv);
|
printf("min value = %g\n", minv);
|
||||||
printf("max value = %g\n",maxv);
|
printf("max value = %g\n", maxv);
|
||||||
assert(fabs(minv - EXPECTED_MIN) < EPSILON);
|
assert(fabs(minv - EXPECTED_MIN) < EPSILON);
|
||||||
assert(fabs(maxv - EXPECTED_MAX) < EPSILON);
|
assert(fabs(maxv - EXPECTED_MAX) < EPSILON);
|
||||||
|
|
||||||
/* get the coded message in a buffer */
|
/* get the coded message in a buffer */
|
||||||
CODES_CHECK(codes_get_message(h,&buffer,&size),0);
|
CODES_CHECK(codes_get_message(h, &buffer, &size), 0);
|
||||||
|
|
||||||
/* write the buffer in a file*/
|
/* write the buffer in a file*/
|
||||||
if(fwrite(buffer,1,size,out) != size)
|
if (fwrite(buffer, 1, size, out) != size) {
|
||||||
{
|
|
||||||
perror(argv[1]);
|
perror(argv[1]);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,68 +19,69 @@
|
||||||
|
|
||||||
#include "eccodes.h"
|
#include "eccodes.h"
|
||||||
|
|
||||||
static void usage(const char* prog) {
|
static void usage(const char* prog)
|
||||||
printf("usage: %s filename\n",prog);
|
{
|
||||||
|
printf("usage: %s filename\n", prog);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
int err = 0,i;
|
int err = 0, i;
|
||||||
double *values = NULL;
|
double* values = NULL;
|
||||||
double max,min,average;
|
double max, min, average;
|
||||||
size_t values_len= 0;
|
size_t values_len = 0;
|
||||||
|
|
||||||
FILE* in = NULL;
|
FILE* in = NULL;
|
||||||
char* filename ;
|
char* filename;
|
||||||
codes_handle *h = NULL;
|
codes_handle* h = NULL;
|
||||||
|
|
||||||
if (argc<2) usage(argv[0]);
|
if (argc < 2) usage(argv[0]);
|
||||||
filename=argv[1];
|
filename = argv[1];
|
||||||
|
|
||||||
in = fopen(filename,"rb");
|
in = fopen(filename, "rb");
|
||||||
if(!in) {
|
if (!in) {
|
||||||
printf("ERROR: unable to open file %s\n",filename);
|
printf("ERROR: unable to open file %s\n", filename);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* create new handle from a message in a file*/
|
/* create new handle from a message in a file*/
|
||||||
h = codes_handle_new_from_file(0, in, PRODUCT_GRIB, &err);
|
h = codes_handle_new_from_file(0, in, PRODUCT_GRIB, &err);
|
||||||
if (h == NULL) {
|
if (h == NULL) {
|
||||||
printf("Error: unable to create handle from file %s\n",filename);
|
printf("Error: unable to create handle from file %s\n", filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* get the size of the values array*/
|
/* get the size of the values array*/
|
||||||
CODES_CHECK(codes_get_size(h,"values",&values_len),0);
|
CODES_CHECK(codes_get_size(h, "values", &values_len), 0);
|
||||||
|
|
||||||
values = (double*)malloc(values_len*sizeof(double));
|
values = (double*)malloc(values_len * sizeof(double));
|
||||||
|
|
||||||
/* get data values*/
|
/* get data values*/
|
||||||
CODES_CHECK(codes_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++)
|
for (i = 0; i < values_len; i++)
|
||||||
printf("%d %.10e\n",i,values[i]);
|
printf("%d %.10e\n", i, values[i]);
|
||||||
|
|
||||||
free(values);
|
free(values);
|
||||||
|
|
||||||
CODES_CHECK(codes_get_double(h,"max",&max),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, "min", &min), 0);
|
||||||
CODES_CHECK(codes_get_double(h,"average",&average),0);
|
CODES_CHECK(codes_get_double(h, "average", &average), 0);
|
||||||
|
|
||||||
printf("%d values found in %s\n",(int)values_len,filename);
|
printf("%d values found in %s\n", (int)values_len, filename);
|
||||||
printf("max=%.10e min=%.10e average=%.10e\n",max,min,average);
|
printf("max=%.10e min=%.10e average=%.10e\n", max, min, average);
|
||||||
|
|
||||||
{
|
{
|
||||||
/* Example of accessing specific elements from data values */
|
/* Example of accessing specific elements from data values */
|
||||||
double vals_arr[3] = {0, 0, 0};
|
double vals_arr[3] = { 0, 0, 0 };
|
||||||
const int NUM = 3;
|
const int NUM = 3;
|
||||||
int index_arr[3];
|
int index_arr[3];
|
||||||
index_arr[0] = 0; /* first element */
|
index_arr[0] = 0; /* first element */
|
||||||
index_arr[1] = values_len/2; /* middle element */
|
index_arr[1] = values_len / 2; /* middle element */
|
||||||
index_arr[2] = values_len-1; /* last element */
|
index_arr[2] = values_len - 1; /* last element */
|
||||||
|
|
||||||
CODES_CHECK(codes_get_double_elements(h, "values", index_arr, NUM, vals_arr), 0);
|
CODES_CHECK(codes_get_double_elements(h, "values", index_arr, NUM, vals_arr), 0);
|
||||||
for (i=0; i<NUM; ++i){
|
for (i = 0; i < NUM; ++i) {
|
||||||
printf("value at index %d = %.10e\n", index_arr[i], vals_arr[i]);
|
printf("value at index %d = %.10e\n", index_arr[i], vals_arr[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,12 +16,12 @@
|
||||||
#define NUM_THREADS 4
|
#define NUM_THREADS 4
|
||||||
|
|
||||||
/* Return 0 if numbers considered equal, otherwise 1 */
|
/* Return 0 if numbers considered equal, otherwise 1 */
|
||||||
static int compare_doubles(double a,double b,double tolerance)
|
static int compare_doubles(double a, double b, double tolerance)
|
||||||
{
|
{
|
||||||
int ret=0;
|
int ret = 0;
|
||||||
double d=fabs(a-b);
|
double d = fabs(a - b);
|
||||||
if (d > tolerance) {
|
if (d > tolerance) {
|
||||||
ret=1;
|
ret = 1;
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -32,12 +32,12 @@ static void* process_grib(void* threadID)
|
||||||
size_t str_len = 20, i = 0;
|
size_t str_len = 20, i = 0;
|
||||||
long indicatorOfUnitOfTimeRange = 1, step = 0;
|
long indicatorOfUnitOfTimeRange = 1, step = 0;
|
||||||
char mystring[100];
|
char mystring[100];
|
||||||
double* values = NULL;
|
double* values = NULL;
|
||||||
size_t values_len = 0;
|
size_t values_len = 0;
|
||||||
double min=0,max=0,avg=0;
|
double min = 0, max = 0, avg = 0;
|
||||||
const double tol = 1e-6;
|
const double tol = 1e-6;
|
||||||
double pv[4]={1,2,3,4};
|
double pv[4] = { 1, 2, 3, 4 };
|
||||||
const size_t pvsize=4;
|
const size_t pvsize = 4;
|
||||||
ProductKind prod_kind = 0;
|
ProductKind prod_kind = 0;
|
||||||
|
|
||||||
codes_handle* h = codes_grib_handle_new_from_samples(0, "regular_ll_pl_grib2");
|
codes_handle* h = codes_grib_handle_new_from_samples(0, "regular_ll_pl_grib2");
|
||||||
|
@ -46,35 +46,37 @@ static void* process_grib(void* threadID)
|
||||||
assert(prod_kind == PRODUCT_GRIB);
|
assert(prod_kind == PRODUCT_GRIB);
|
||||||
printf("Thread %ld running\n", tid);
|
printf("Thread %ld running\n", tid);
|
||||||
|
|
||||||
CODES_CHECK(codes_set_long(h,"indicatorOfUnitOfTimeRange", indicatorOfUnitOfTimeRange),0);
|
CODES_CHECK(codes_set_long(h, "indicatorOfUnitOfTimeRange", indicatorOfUnitOfTimeRange), 0);
|
||||||
CODES_CHECK(codes_set_string(h,"indicatorOfUnitOfTimeRange", "s", &str_len),0);
|
CODES_CHECK(codes_set_string(h, "indicatorOfUnitOfTimeRange", "s", &str_len), 0);
|
||||||
CODES_CHECK(codes_set_string(h,"stepUnits", "s", &str_len),0);
|
CODES_CHECK(codes_set_string(h, "stepUnits", "s", &str_len), 0);
|
||||||
CODES_CHECK(codes_set_long(h, "endStep", 86400), 0);
|
CODES_CHECK(codes_set_long(h, "endStep", 86400), 0);
|
||||||
CODES_CHECK(codes_set_long(h,"centre", 80),0);
|
CODES_CHECK(codes_set_long(h, "centre", 80), 0);
|
||||||
|
|
||||||
CODES_CHECK(codes_get_long(h,"endStep", &step),0);
|
CODES_CHECK(codes_get_long(h, "endStep", &step), 0);
|
||||||
CODES_CHECK(codes_get_string(h, "indicatorOfUnitOfTimeRange", mystring, &str_len),0);
|
CODES_CHECK(codes_get_string(h, "indicatorOfUnitOfTimeRange", mystring, &str_len), 0);
|
||||||
|
|
||||||
CODES_CHECK(codes_set_long(h,"PVPresent", 1),0);
|
CODES_CHECK(codes_set_long(h, "PVPresent", 1), 0);
|
||||||
CODES_CHECK(codes_set_double_array(h, "pv", pv, pvsize),0);
|
CODES_CHECK(codes_set_double_array(h, "pv", pv, pvsize), 0);
|
||||||
|
|
||||||
CODES_CHECK(codes_get_size(h,"values",&values_len),0);
|
CODES_CHECK(codes_get_size(h, "values", &values_len), 0);
|
||||||
values = (double*)malloc(values_len*sizeof(double));
|
values = (double*)malloc(values_len * sizeof(double));
|
||||||
CODES_CHECK(codes_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++) {
|
for (i = 0; i < values_len; i++) {
|
||||||
if (i%2) values[i] *= 0.94;
|
if (i % 2)
|
||||||
else if (i%3) values[i] *= 0.84;
|
values[i] *= 0.94;
|
||||||
|
else if (i % 3)
|
||||||
|
values[i] *= 0.84;
|
||||||
}
|
}
|
||||||
GRIB_CHECK(grib_set_double_array(h,"values",values,values_len),0);
|
GRIB_CHECK(grib_set_double_array(h, "values", values, values_len), 0);
|
||||||
free(values);
|
free(values);
|
||||||
|
|
||||||
CODES_CHECK(codes_get_double(h, "min", &min),0);
|
CODES_CHECK(codes_get_double(h, "min", &min), 0);
|
||||||
CODES_CHECK(codes_get_double(h, "max", &max),0);
|
CODES_CHECK(codes_get_double(h, "max", &max), 0);
|
||||||
CODES_CHECK(codes_get_double(h, "avg", &avg),0);
|
CODES_CHECK(codes_get_double(h, "avg", &avg), 0);
|
||||||
printf("Thread %ld: min=%g max=%g avg=%g\n", tid, min, max, avg);
|
printf("Thread %ld: min=%g max=%g avg=%g\n", tid, min, max, avg);
|
||||||
assert( compare_doubles(min, 0.84, tol)==0 );
|
assert(compare_doubles(min, 0.84, tol) == 0);
|
||||||
assert( compare_doubles(max, 1.00, tol)==0 );
|
assert(compare_doubles(max, 1.00, tol) == 0);
|
||||||
assert( compare_doubles(avg, 0.916774, tol)==0 );
|
assert(compare_doubles(avg, 0.916774, tol) == 0);
|
||||||
|
|
||||||
codes_handle_delete(h);
|
codes_handle_delete(h);
|
||||||
pthread_exit(NULL);
|
pthread_exit(NULL);
|
||||||
|
@ -84,16 +86,16 @@ int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
pthread_t threads[NUM_THREADS];
|
pthread_t threads[NUM_THREADS];
|
||||||
int error = 0;
|
int error = 0;
|
||||||
long i = 0;
|
long i = 0;
|
||||||
for (i=0; i<NUM_THREADS; ++i) {
|
for (i = 0; i < NUM_THREADS; ++i) {
|
||||||
printf("Creating thread %ld\n", i);
|
printf("Creating thread %ld\n", i);
|
||||||
error = pthread_create(&threads[i], NULL, process_grib, (void *)i);
|
error = pthread_create(&threads[i], NULL, process_grib, (void*)i);
|
||||||
if (error) {
|
if (error) {
|
||||||
assert(0);
|
assert(0);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (i=0; i<NUM_THREADS; ++i) {
|
for (i = 0; i < NUM_THREADS; ++i) {
|
||||||
pthread_join(threads[i], NULL);
|
pthread_join(threads[i], NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,8 +10,9 @@
|
||||||
#include "eccodes.h"
|
#include "eccodes.h"
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
|
||||||
static void usage(const char* prog) {
|
static void usage(const char* prog)
|
||||||
printf("usage: %s in1.grib in2.grib what out.grib\n",prog);
|
{
|
||||||
|
printf("usage: %s in1.grib in2.grib what out.grib\n", prog);
|
||||||
printf("in1.grib The grib in whose sections we are interested, i.e. the source of the sections (read-only)\n");
|
printf("in1.grib The grib in whose sections we are interested, i.e. the source of the sections (read-only)\n");
|
||||||
printf("in2.grib The input grib (read-only)\n");
|
printf("in2.grib The input grib (read-only)\n");
|
||||||
printf("what The section(s) to copy: p(Product), g(Grid), l(Local), d(Data), b(Bitmap)\n");
|
printf("what The section(s) to copy: p(Product), g(Grid), l(Local), d(Data), b(Bitmap)\n");
|
||||||
|
@ -19,38 +20,38 @@ static void usage(const char* prog) {
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main ( int argc, char* argv[])
|
int main(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
codes_handle *hfrom,*hto,*h;
|
codes_handle *hfrom, *hto, *h;
|
||||||
FILE *in;
|
FILE* in;
|
||||||
char *in_name1, *in_name2, *what_str, *out_name;
|
char *in_name1, *in_name2, *what_str, *out_name;
|
||||||
int i, err=0, what=0;
|
int i, err = 0, what = 0;
|
||||||
|
|
||||||
if (argc<5) usage(argv[0]);
|
if (argc < 5) usage(argv[0]);
|
||||||
|
|
||||||
in_name1=argv[1];
|
in_name1 = argv[1];
|
||||||
in_name2=argv[2];
|
in_name2 = argv[2];
|
||||||
what_str=argv[3];
|
what_str = argv[3];
|
||||||
out_name=argv[4];
|
out_name = argv[4];
|
||||||
|
|
||||||
in=fopen(in_name1,"rb");
|
in = fopen(in_name1, "rb");
|
||||||
if (!in) {
|
if (!in) {
|
||||||
perror(in_name1);
|
perror(in_name1);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
hfrom=codes_handle_new_from_file(0, in, PRODUCT_GRIB, &err);
|
hfrom = codes_handle_new_from_file(0, in, PRODUCT_GRIB, &err);
|
||||||
CODES_CHECK(err,0);
|
CODES_CHECK(err, 0);
|
||||||
fclose(in);
|
fclose(in);
|
||||||
|
|
||||||
in=fopen(in_name2,"rb");
|
in = fopen(in_name2, "rb");
|
||||||
if (!in) {
|
if (!in) {
|
||||||
perror(in_name2);
|
perror(in_name2);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
hto=codes_handle_new_from_file(0, in, PRODUCT_GRIB, &err);
|
hto = codes_handle_new_from_file(0, in, PRODUCT_GRIB, &err);
|
||||||
CODES_CHECK(err,0);
|
CODES_CHECK(err, 0);
|
||||||
fclose(in);
|
fclose(in);
|
||||||
|
|
||||||
/* The sections for the "what" argument are:
|
/* The sections for the "what" argument are:
|
||||||
|
@ -62,7 +63,7 @@ int main ( int argc, char* argv[])
|
||||||
* One can bitwise-OR them to have more than one section copied
|
* One can bitwise-OR them to have more than one section copied
|
||||||
* E.g. what = CODES_SECTION_PRODUCT | CODES_SECTION_LOCAL;
|
* E.g. what = CODES_SECTION_PRODUCT | CODES_SECTION_LOCAL;
|
||||||
*/
|
*/
|
||||||
for(i=0; i<strlen(what_str); ++i) {
|
for (i = 0; i < strlen(what_str); ++i) {
|
||||||
if (what_str[i] == 'p') {
|
if (what_str[i] == 'p') {
|
||||||
printf("Copying the PRODUCT section\n");
|
printf("Copying the PRODUCT section\n");
|
||||||
what |= CODES_SECTION_PRODUCT;
|
what |= CODES_SECTION_PRODUCT;
|
||||||
|
@ -87,15 +88,15 @@ int main ( int argc, char* argv[])
|
||||||
/* Ignore spaces and comma separator */
|
/* Ignore spaces and comma separator */
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
fprintf(stderr,"Invalid option: '%c'. Ignoring.\n",
|
fprintf(stderr, "Invalid option: '%c'. Ignoring.\n",
|
||||||
what_str[i]);
|
what_str[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
h=codes_grib_util_sections_copy(hfrom,hto,what,&err);
|
h = codes_grib_util_sections_copy(hfrom, hto, what, &err);
|
||||||
CODES_CHECK(err,0);
|
CODES_CHECK(err, 0);
|
||||||
|
|
||||||
err=codes_write_message(h,out_name,"w");
|
err = codes_write_message(h, out_name, "w");
|
||||||
|
|
||||||
codes_handle_delete(hfrom);
|
codes_handle_delete(hfrom);
|
||||||
codes_handle_delete(hto);
|
codes_handle_delete(hto);
|
||||||
|
|
|
@ -23,61 +23,61 @@
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
int err = 0;
|
int err = 0;
|
||||||
size_t size=0;
|
size_t size = 0;
|
||||||
|
|
||||||
FILE* in = NULL;
|
FILE* in = NULL;
|
||||||
const char* infile = "../../data/regular_latlon_surface.grib1";
|
const char* infile = "../../data/regular_latlon_surface.grib1";
|
||||||
FILE* out = NULL;
|
FILE* out = NULL;
|
||||||
const char* outfile = "out.set_bitmap_c.grib";
|
const char* outfile = "out.set_bitmap_c.grib";
|
||||||
codes_handle *h = NULL;
|
codes_handle* h = NULL;
|
||||||
const void* buffer = NULL;
|
const void* buffer = NULL;
|
||||||
size_t values_len;
|
size_t values_len;
|
||||||
double* values;
|
double* values;
|
||||||
double missing=9999;
|
double missing = 9999;
|
||||||
int i=0;
|
int i = 0;
|
||||||
|
|
||||||
in = fopen(infile, "rb");
|
in = fopen(infile, "rb");
|
||||||
if(!in) {
|
if (!in) {
|
||||||
printf("ERROR: unable to open input file %s\n",infile);
|
printf("ERROR: unable to open input file %s\n", infile);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
out = fopen(outfile, "wb");
|
out = fopen(outfile, "wb");
|
||||||
if(!out) {
|
if (!out) {
|
||||||
printf("ERROR: unable to open output file %s\n",outfile);
|
printf("ERROR: unable to open output file %s\n", outfile);
|
||||||
fclose(in);
|
fclose(in);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
h = codes_handle_new_from_file(0, in, PRODUCT_GRIB, &err);
|
h = codes_handle_new_from_file(0, in, PRODUCT_GRIB, &err);
|
||||||
if (h == NULL) {
|
if (h == NULL) {
|
||||||
printf("Error: unable to create handle from file %s\n",infile);
|
printf("Error: unable to create handle from file %s\n", infile);
|
||||||
}
|
}
|
||||||
|
|
||||||
CODES_CHECK(codes_set_double(h, "missingValue", missing),0);
|
CODES_CHECK(codes_set_double(h, "missingValue", missing), 0);
|
||||||
|
|
||||||
/* get the size of the values array*/
|
/* get the size of the values array*/
|
||||||
CODES_CHECK(codes_get_size(h, "values", &values_len),0);
|
CODES_CHECK(codes_get_size(h, "values", &values_len), 0);
|
||||||
|
|
||||||
values = (double*)malloc(values_len*sizeof(double));
|
values = (double*)malloc(values_len * sizeof(double));
|
||||||
|
|
||||||
/* get data values*/
|
/* get data values*/
|
||||||
CODES_CHECK(codes_get_double_array(h, "values", values, &values_len),0);
|
CODES_CHECK(codes_get_double_array(h, "values", values, &values_len), 0);
|
||||||
|
|
||||||
CODES_CHECK(codes_set_long(h, "bitmapPresent", 1),0);
|
CODES_CHECK(codes_set_long(h, "bitmapPresent", 1), 0);
|
||||||
|
|
||||||
for(i = 0; i < 10; i++) {
|
for (i = 0; i < 10; i++) {
|
||||||
values[i]=missing;
|
values[i] = missing;
|
||||||
}
|
}
|
||||||
|
|
||||||
CODES_CHECK(codes_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 */
|
/* get the coded message in a buffer */
|
||||||
CODES_CHECK(codes_get_message(h, &buffer, &size),0);
|
CODES_CHECK(codes_get_message(h, &buffer, &size), 0);
|
||||||
|
|
||||||
/* write the buffer in a file*/
|
/* write the buffer in a file*/
|
||||||
if(fwrite(buffer, 1, size, out) != size) {
|
if (fwrite(buffer, 1, size, out) != size) {
|
||||||
perror(outfile);
|
perror(outfile);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,15 +23,15 @@
|
||||||
|
|
||||||
static void usage(const char* prog)
|
static void usage(const char* prog)
|
||||||
{
|
{
|
||||||
printf("usage: %s out.grib\n",prog);
|
printf("usage: %s out.grib\n", prog);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
double *values = NULL;
|
double* values = NULL;
|
||||||
size_t values_len= 0;
|
size_t values_len = 0;
|
||||||
|
|
||||||
/* Note: the full name of the sample file is "regular_ll_pl_grib1.tmpl" */
|
/* Note: the full name of the sample file is "regular_ll_pl_grib1.tmpl" */
|
||||||
/* Sample files are stored in the samples directory (use codes_info to */
|
/* Sample files are stored in the samples directory (use codes_info to */
|
||||||
|
@ -40,11 +40,11 @@ int main(int argc, char** argv)
|
||||||
const char* sample_filename = "regular_ll_pl_grib1";
|
const char* sample_filename = "regular_ll_pl_grib1";
|
||||||
/* Here is how you can get the samples path */
|
/* Here is how you can get the samples path */
|
||||||
const char* samples_path = codes_samples_path(NULL);
|
const char* samples_path = codes_samples_path(NULL);
|
||||||
codes_handle *h = NULL;
|
codes_handle* h = NULL;
|
||||||
double d,e;
|
double d, e;
|
||||||
long count;
|
long count;
|
||||||
|
|
||||||
if (argc!=2) usage(argv[0]);
|
if (argc != 2) usage(argv[0]);
|
||||||
/* create new handle from message in sample file */
|
/* create new handle from message in sample file */
|
||||||
printf("Using samples path: %s\n", samples_path);
|
printf("Using samples path: %s\n", samples_path);
|
||||||
h = codes_grib_handle_new_from_samples(0, sample_filename);
|
h = codes_grib_handle_new_from_samples(0, sample_filename);
|
||||||
|
@ -57,24 +57,27 @@ int main(int argc, char** argv)
|
||||||
/* will be the same as the sample GRIB. */
|
/* will be the same as the sample GRIB. */
|
||||||
/* But if your data array has a different size, then specify the grid geometry */
|
/* 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 */
|
/* (e.g. keys Ni, Nj etc) and set the correct number of data values */
|
||||||
CODES_CHECK(codes_get_size(h, "values", &values_len),0);
|
CODES_CHECK(codes_get_size(h, "values", &values_len), 0);
|
||||||
|
|
||||||
values = (double*)malloc(values_len*sizeof(double));
|
values = (double*)malloc(values_len * sizeof(double));
|
||||||
d=10e-8;
|
d = 10e-8;
|
||||||
e=d;
|
e = d;
|
||||||
count=1;
|
count = 1;
|
||||||
for (i=0;i<values_len;i++) {
|
for (i = 0; i < values_len; i++) {
|
||||||
if (count>100) {e*=10; count=1;}
|
if (count > 100) {
|
||||||
values[i]=d;
|
e *= 10;
|
||||||
|
count = 1;
|
||||||
|
}
|
||||||
|
values[i] = d;
|
||||||
/*printf("%g \n",values[i]);*/
|
/*printf("%g \n",values[i]);*/
|
||||||
d+=e;
|
d += e;
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
|
|
||||||
CODES_CHECK(codes_set_long(h,"bitsPerValue",16),0);
|
CODES_CHECK(codes_set_long(h, "bitsPerValue", 16), 0);
|
||||||
|
|
||||||
/* set data values */
|
/* set data values */
|
||||||
CODES_CHECK(codes_set_double_array(h,"values",values,values_len),0);
|
CODES_CHECK(codes_set_double_array(h, "values", values, values_len), 0);
|
||||||
|
|
||||||
CODES_CHECK(codes_write_message(h, argv[1], "w"), 0);
|
CODES_CHECK(codes_write_message(h, argv[1], "w"), 0);
|
||||||
|
|
||||||
|
|
|
@ -21,30 +21,30 @@
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
int err = 0;
|
int err = 0;
|
||||||
long centre=80;
|
long centre = 80;
|
||||||
long long_value=0;
|
long long_value = 0;
|
||||||
char string_value[100];
|
char string_value[100];
|
||||||
size_t len = sizeof(string_value)/sizeof(char);
|
size_t len = sizeof(string_value) / sizeof(char);
|
||||||
size_t size=0;
|
size_t size = 0;
|
||||||
|
|
||||||
FILE* in = NULL;
|
FILE* in = NULL;
|
||||||
const char* infile = "../../data/regular_latlon_surface.grib1";
|
const char* infile = "../../data/regular_latlon_surface.grib1";
|
||||||
FILE* out = NULL;
|
FILE* out = NULL;
|
||||||
const char* outfile = "out.set.grib1";
|
const char* outfile = "out.set.grib1";
|
||||||
codes_handle *h = NULL;
|
codes_handle* h = NULL;
|
||||||
const void* buffer = NULL;
|
const void* buffer = NULL;
|
||||||
size_t str_len = 0; /* See the call to codes_set_string later */
|
size_t str_len = 0; /* See the call to codes_set_string later */
|
||||||
|
|
||||||
in = fopen(infile,"rb");
|
in = fopen(infile, "rb");
|
||||||
if(!in) {
|
if (!in) {
|
||||||
printf("ERROR: unable to open file %s\n",infile);
|
printf("ERROR: unable to open file %s\n", infile);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
out = fopen(outfile,"wb");
|
out = fopen(outfile, "wb");
|
||||||
if(!out) {
|
if (!out) {
|
||||||
printf("ERROR: unable to open file %s\n",outfile);
|
printf("ERROR: unable to open file %s\n", outfile);
|
||||||
fclose(in);
|
fclose(in);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -52,31 +52,30 @@ int main(int argc, char** argv)
|
||||||
/* create a new handle from a message in a file */
|
/* create a new handle from a message in a file */
|
||||||
h = codes_handle_new_from_file(0, in, PRODUCT_GRIB, &err);
|
h = codes_handle_new_from_file(0, in, PRODUCT_GRIB, &err);
|
||||||
if (h == NULL) {
|
if (h == NULL) {
|
||||||
printf("Error: unable to create handle from file %s\n",infile);
|
printf("Error: unable to create handle from file %s\n", infile);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* set centre as a long */
|
/* set centre as a long */
|
||||||
CODES_CHECK(codes_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 */
|
/* set paramId and shortName - normally you would do one or the other */
|
||||||
CODES_CHECK(codes_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! */
|
/* the value of str_len is not used, it can be anything! */
|
||||||
CODES_CHECK(codes_set_string(h,"shortName", "fis", &str_len),0);
|
CODES_CHECK(codes_set_string(h, "shortName", "fis", &str_len), 0);
|
||||||
|
|
||||||
/* get centre as a long */
|
/* get centre as a long */
|
||||||
CODES_CHECK(codes_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);
|
printf("centre long value=%ld\n", long_value);
|
||||||
|
|
||||||
/* get centre as a string */
|
/* get centre as a string */
|
||||||
CODES_CHECK(codes_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);
|
printf("centre string value=%s\n", string_value);
|
||||||
|
|
||||||
/* get the coded message in a buffer */
|
/* get the coded message in a buffer */
|
||||||
CODES_CHECK(codes_get_message(h,&buffer,&size),0);
|
CODES_CHECK(codes_get_message(h, &buffer, &size), 0);
|
||||||
|
|
||||||
/* write the buffer in a file*/
|
/* write the buffer in a file*/
|
||||||
if(fwrite(buffer,1,size,out) != size)
|
if (fwrite(buffer, 1, size, out) != size) {
|
||||||
{
|
|
||||||
perror(argv[1]);
|
perror(argv[1]);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,39 +19,40 @@
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include "eccodes.h"
|
#include "eccodes.h"
|
||||||
|
|
||||||
static void usage(const char* prog) {
|
static void usage(const char* prog)
|
||||||
fprintf(stderr, "usage: %s in out\n",prog);
|
{
|
||||||
|
fprintf(stderr, "usage: %s in out\n", prog);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
int err = 0;
|
int err = 0;
|
||||||
long NV = 0;
|
long NV = 0;
|
||||||
size_t size=0;
|
size_t size = 0;
|
||||||
double pv[4]={1,2,3,4};
|
double pv[4] = { 1, 2, 3, 4 };
|
||||||
size_t pvsize=4;
|
size_t pvsize = 4;
|
||||||
|
|
||||||
FILE* in = NULL;
|
FILE* in = NULL;
|
||||||
char* infile = NULL;
|
char* infile = NULL;
|
||||||
FILE* out = NULL;
|
FILE* out = NULL;
|
||||||
char* outfile = NULL;
|
char* outfile = NULL;
|
||||||
codes_handle *h = NULL;
|
codes_handle* h = NULL;
|
||||||
const void* buffer = NULL;
|
const void* buffer = NULL;
|
||||||
|
|
||||||
if (argc != 3) usage(argv[0]);
|
if (argc != 3) usage(argv[0]);
|
||||||
infile = argv[1];
|
infile = argv[1];
|
||||||
outfile= argv[2];
|
outfile = argv[2];
|
||||||
|
|
||||||
in = fopen(infile, "rb");
|
in = fopen(infile, "rb");
|
||||||
if(!in) {
|
if (!in) {
|
||||||
fprintf(stderr, "ERROR: unable to open input file %s\n",infile);
|
fprintf(stderr, "ERROR: unable to open input file %s\n", infile);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
out = fopen(outfile, "wb");
|
out = fopen(outfile, "wb");
|
||||||
if(!out) {
|
if (!out) {
|
||||||
fprintf(stderr, "ERROR: unable to open output file %s\n",outfile);
|
fprintf(stderr, "ERROR: unable to open output file %s\n", outfile);
|
||||||
fclose(in);
|
fclose(in);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -59,23 +60,22 @@ int main(int argc, char** argv)
|
||||||
/* create a new handle from a message in a file */
|
/* create a new handle from a message in a file */
|
||||||
h = codes_handle_new_from_file(0, in, PRODUCT_GRIB, &err);
|
h = codes_handle_new_from_file(0, in, PRODUCT_GRIB, &err);
|
||||||
if (h == NULL) {
|
if (h == NULL) {
|
||||||
fprintf(stderr, "Error: unable to create handle from file %s\n",infile);
|
fprintf(stderr, "Error: unable to create handle from file %s\n", infile);
|
||||||
}
|
}
|
||||||
|
|
||||||
CODES_CHECK(codes_set_long(h,"PVPresent", 1),0);
|
CODES_CHECK(codes_set_long(h, "PVPresent", 1), 0);
|
||||||
|
|
||||||
CODES_CHECK(codes_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 */
|
/* Once we set the pv array, the NV key should be also set */
|
||||||
CODES_CHECK(codes_get_long(h, "NV", &NV),0);
|
CODES_CHECK(codes_get_long(h, "NV", &NV), 0);
|
||||||
assert( NV == pvsize );
|
assert(NV == pvsize);
|
||||||
|
|
||||||
/* get the coded message in a buffer */
|
/* get the coded message in a buffer */
|
||||||
CODES_CHECK(codes_get_message(h, &buffer, &size),0);
|
CODES_CHECK(codes_get_message(h, &buffer, &size), 0);
|
||||||
|
|
||||||
/* write the buffer in a file*/
|
/* write the buffer in a file*/
|
||||||
if(fwrite(buffer, 1, size, out) != size)
|
if (fwrite(buffer, 1, size, out) != size) {
|
||||||
{
|
|
||||||
perror(argv[1]);
|
perror(argv[1]);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,19 +17,19 @@ int main()
|
||||||
{
|
{
|
||||||
const int ni = 2880;
|
const int ni = 2880;
|
||||||
const int nj = 2880;
|
const int nj = 2880;
|
||||||
double *values;
|
double* values;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
codes_handle *h = NULL;
|
codes_handle* h = NULL;
|
||||||
const char* filename = "bigfile.grib";
|
const char* filename = "bigfile.grib";
|
||||||
|
|
||||||
values = (double*) malloc(ni*nj*sizeof(double));
|
values = (double*)malloc(ni * nj * sizeof(double));
|
||||||
if (!values) {
|
if (!values) {
|
||||||
printf ("Malloc failed\n");
|
printf("Malloc failed\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i=0; i<ni*nj; i++) {
|
for (i = 0; i < ni * nj; i++) {
|
||||||
double r = rand() * 1.0 / RAND_MAX;
|
double r = rand() * 1.0 / RAND_MAX;
|
||||||
values[i] = r;
|
values[i] = r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,21 +52,21 @@ int main()
|
||||||
|
|
||||||
CODES_CHECK(codes_set_double(h, "iDirectionIncrementInDegrees", 0.125), 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_double(h, "jDirectionIncrementInDegrees", 0.125), 0);
|
||||||
CODES_CHECK(codes_set_long(h, "iScansNegatively", 0), 0);
|
CODES_CHECK(codes_set_long(h, "iScansNegatively", 0), 0);
|
||||||
CODES_CHECK(codes_set_long(h, "jScansPositively", 1), 0);
|
CODES_CHECK(codes_set_long(h, "jScansPositively", 1), 0);
|
||||||
|
|
||||||
CODES_CHECK(codes_set_double(h, "latitudeOfFirstGridPointInDegrees", -90), 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, "latitudeOfLastGridPointInDegrees", 90), 0);
|
||||||
CODES_CHECK(codes_set_double(h, "longitudeOfFirstGridPointInDegrees", -180), 0);
|
CODES_CHECK(codes_set_double(h, "longitudeOfFirstGridPointInDegrees", -180), 0);
|
||||||
CODES_CHECK(codes_set_double(h, "longitudeOfLastGridPointInDegrees", 180), 0);
|
CODES_CHECK(codes_set_double(h, "longitudeOfLastGridPointInDegrees", 180), 0);
|
||||||
|
|
||||||
CODES_CHECK(codes_set_double_array(h, "values", values, ni*nj), 0);
|
CODES_CHECK(codes_set_double_array(h, "values", values, ni * nj), 0);
|
||||||
|
|
||||||
codes_write_message(h, filename, "w");
|
codes_write_message(h, filename, "w");
|
||||||
/*printf("Wrote file %s\n", filename);*/
|
/*printf("Wrote file %s\n", filename);*/
|
||||||
|
|
||||||
codes_handle_delete(h);
|
codes_handle_delete(h);
|
||||||
free (values);
|
free(values);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,26 +23,26 @@ int main(int argc, char** argv)
|
||||||
codes_string_list* list;
|
codes_string_list* list;
|
||||||
codes_string_list* list2;
|
codes_string_list* list2;
|
||||||
|
|
||||||
list=codes_grib_util_get_param_id("11.2");
|
list = codes_grib_util_get_param_id("11.2");
|
||||||
printf("mars.param=11.2 -> paramId= ");
|
printf("mars.param=11.2 -> paramId= ");
|
||||||
while (list) {
|
while (list) {
|
||||||
printf("%s ",list->value);
|
printf("%s ", list->value);
|
||||||
list2=codes_grib_util_get_param_id("130.128");
|
list2 = codes_grib_util_get_param_id("130.128");
|
||||||
printf("mars.param=11.2 -> paramId= ");
|
printf("mars.param=11.2 -> paramId= ");
|
||||||
while (list2) {
|
while (list2) {
|
||||||
printf("%s ",list2->value);
|
printf("%s ", list2->value);
|
||||||
list2=list2->next;
|
list2 = list2->next;
|
||||||
}
|
}
|
||||||
list=list->next;
|
list = list->next;
|
||||||
}
|
}
|
||||||
printf("\n");
|
printf("\n");
|
||||||
printf("\n");
|
printf("\n");
|
||||||
|
|
||||||
printf("paramId=130 -> mars.param= ");
|
printf("paramId=130 -> mars.param= ");
|
||||||
list=codes_grib_util_get_mars_param("130");
|
list = codes_grib_util_get_mars_param("130");
|
||||||
while (list) {
|
while (list) {
|
||||||
printf("%s ",list->value);
|
printf("%s ", list->value);
|
||||||
list=list->next;
|
list = list->next;
|
||||||
}
|
}
|
||||||
printf("\n");
|
printf("\n");
|
||||||
|
|
||||||
|
|
|
@ -21,36 +21,36 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
const int NUM_FIELDS = 4;
|
const int NUM_FIELDS = 4;
|
||||||
const int COUNT = 20;
|
const int COUNT = 20;
|
||||||
const char* file_path = "../../data/multi_created.grib2";
|
const char* file_path = "../../data/multi_created.grib2";
|
||||||
|
|
||||||
static void read_data(int num_msgs)
|
static void read_data(int num_msgs)
|
||||||
{
|
{
|
||||||
int err = 0,i;
|
int err = 0, i;
|
||||||
FILE* fp = NULL;
|
FILE* fp = NULL;
|
||||||
long stepRange = 0;
|
long stepRange = 0;
|
||||||
codes_handle *h = NULL;
|
codes_handle* h = NULL;
|
||||||
|
|
||||||
fp = fopen(file_path, "rb");
|
fp = fopen(file_path, "rb");
|
||||||
if(!fp) {
|
if (!fp) {
|
||||||
fprintf(stderr, "ERROR: unable to open grib file %s\n", file_path);
|
fprintf(stderr, "ERROR: unable to open grib file %s\n", file_path);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
printf("Opened GRIB file %s: \n", file_path);
|
printf("Opened GRIB file %s: \n", file_path);
|
||||||
for(i=0; i<num_msgs; ++i) {
|
for (i = 0; i < num_msgs; ++i) {
|
||||||
h = codes_handle_new_from_file(0, fp, PRODUCT_GRIB, &err);
|
h = codes_handle_new_from_file(0, fp, PRODUCT_GRIB, &err);
|
||||||
CODES_CHECK(err, 0);
|
CODES_CHECK(err, 0);
|
||||||
|
|
||||||
CODES_CHECK( codes_get_long(h, "stepRange", &stepRange), 0);
|
CODES_CHECK(codes_get_long(h, "stepRange", &stepRange), 0);
|
||||||
printf("%d : stepRange=%ld\n", i, stepRange);
|
printf("%d : stepRange=%ld\n", i, stepRange);
|
||||||
codes_handle_delete(h);
|
codes_handle_delete(h);
|
||||||
/* These tests make sure we always start from 1st field of the grib msg */
|
/* These tests make sure we always start from 1st field of the grib msg */
|
||||||
/* and not where we left off last time */
|
/* and not where we left off last time */
|
||||||
if (i == 0) assert(stepRange == 0); /* 1st field */
|
if (i == 0) assert(stepRange == 0); /* 1st field */
|
||||||
if (i == 1) assert(stepRange == 12); /* 2nd field */
|
if (i == 1) assert(stepRange == 12); /* 2nd field */
|
||||||
if (i == 2) assert(stepRange == 24); /* 3rd field */
|
if (i == 2) assert(stepRange == 24); /* 3rd field */
|
||||||
if (i == 3) assert(stepRange == 36); /* 4th field */
|
if (i == 3) assert(stepRange == 36); /* 4th field */
|
||||||
}
|
}
|
||||||
/* Must reset this file pointer for the next round */
|
/* Must reset this file pointer for the next round */
|
||||||
codes_grib_multi_support_reset_file(codes_context_get_default(), fp);
|
codes_grib_multi_support_reset_file(codes_context_get_default(), fp);
|
||||||
|
@ -64,8 +64,8 @@ int main(int argc, char** argv)
|
||||||
/* turn on support for multi fields messages */
|
/* turn on support for multi fields messages */
|
||||||
codes_grib_multi_support_on(0);
|
codes_grib_multi_support_on(0);
|
||||||
|
|
||||||
for(i=1; i<COUNT; ++i) {
|
for (i = 1; i < COUNT; ++i) {
|
||||||
printf("Pass %d: \n",i);
|
printf("Pass %d: \n", i);
|
||||||
read_data(NUM_FIELDS);
|
read_data(NUM_FIELDS);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -9,28 +9,29 @@
|
||||||
*/
|
*/
|
||||||
#include "eccodes.h"
|
#include "eccodes.h"
|
||||||
|
|
||||||
void usage(char* prog) {
|
void usage(char* prog)
|
||||||
printf("usage: %s in.nc\n",prog);
|
{
|
||||||
|
printf("usage: %s in.nc\n", prog);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc,char* argv[]) {
|
int main(int argc, char* argv[])
|
||||||
|
{
|
||||||
char* file;
|
char* file;
|
||||||
int err=0;
|
int err = 0;
|
||||||
codes_handle* h;
|
codes_handle* h;
|
||||||
char identifier[7]={0,};
|
char identifier[7] = {0,};
|
||||||
size_t len=7;
|
size_t len = 7;
|
||||||
codes_context* c=codes_context_get_default();
|
codes_context* c = codes_context_get_default();
|
||||||
|
|
||||||
if (argc>2) usage(argv[0]);
|
if (argc > 2) usage(argv[0]);
|
||||||
|
|
||||||
file=argv[1];
|
file = argv[1];
|
||||||
|
|
||||||
h=codes_handle_new_from_nc_file(c,file,&err);
|
h = codes_handle_new_from_nc_file(c, file, &err);
|
||||||
codes_get_string(h,"identifier",identifier,&len);
|
codes_get_string(h, "identifier", identifier, &len);
|
||||||
printf("%s\n",identifier);
|
printf("%s\n", identifier);
|
||||||
CODES_CHECK(err,0);
|
CODES_CHECK(err, 0);
|
||||||
|
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,123 +14,123 @@
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
codes_handle *h = NULL;
|
codes_handle* h = NULL;
|
||||||
size_t size = 0;
|
size_t size = 0;
|
||||||
double* vdouble = NULL;
|
double* vdouble = NULL;
|
||||||
FILE* f = NULL;
|
FILE* f = NULL;
|
||||||
const void* buffer = NULL;
|
const void* buffer = NULL;
|
||||||
|
|
||||||
if(argc != 2) {
|
if (argc != 2) {
|
||||||
fprintf(stderr,"usage: %s out\n",argv[0]);
|
fprintf(stderr, "usage: %s out\n", argv[0]);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
h = codes_grib_handle_new_from_samples(NULL,"GRIB2");
|
h = codes_grib_handle_new_from_samples(NULL, "GRIB2");
|
||||||
if(!h) {
|
if (!h) {
|
||||||
fprintf(stderr,"Cannot create grib handle\n");
|
fprintf(stderr, "Cannot create grib handle\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
CODES_CHECK(codes_set_long(h,"parametersVersion",1),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, "truncateLaplacian", 0), 0);
|
||||||
CODES_CHECK(codes_set_long(h,"truncateDegrees",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, "dummy", 1), 0);
|
||||||
CODES_CHECK(codes_set_long(h,"changingPrecision",0),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, "unitsFactor", 1), 0);
|
||||||
CODES_CHECK(codes_set_long(h,"unitsBias",0),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, "timeRangeIndicatorFromStepRange", -1), 0);
|
||||||
CODES_CHECK(codes_set_long(h,"missingValue",9999),0);
|
CODES_CHECK(codes_set_long(h, "missingValue", 9999), 0);
|
||||||
|
|
||||||
/* 0 = Meteorological products (grib2/tables/4/0.0.table) */
|
/* 0 = Meteorological products (grib2/tables/4/0.0.table) */
|
||||||
CODES_CHECK(codes_set_long(h,"discipline",0),0);
|
CODES_CHECK(codes_set_long(h, "discipline", 0), 0);
|
||||||
|
|
||||||
CODES_CHECK(codes_set_long(h,"editionNumber",2),0);
|
CODES_CHECK(codes_set_long(h, "editionNumber", 2), 0);
|
||||||
|
|
||||||
/* 98 = European Center for Medium-Range Weather Forecasts */
|
/* 98 = European Center for Medium-Range Weather Forecasts */
|
||||||
CODES_CHECK(codes_set_long(h,"centre",98),0);
|
CODES_CHECK(codes_set_long(h, "centre", 98), 0);
|
||||||
|
|
||||||
CODES_CHECK(codes_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) */
|
/* 4 = Version implemented on 7 November 2007 (grib2/tables/1.0.table) */
|
||||||
CODES_CHECK(codes_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) */
|
/* 0 = Local tables not used (grib2/tables/4/1.1.table) */
|
||||||
CODES_CHECK(codes_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) */
|
/* 1 = Start of forecast (grib2/tables/4/1.2.table) */
|
||||||
CODES_CHECK(codes_set_long(h,"significanceOfReferenceTime",1),0);
|
CODES_CHECK(codes_set_long(h, "significanceOfReferenceTime", 1), 0);
|
||||||
|
|
||||||
CODES_CHECK(codes_set_long(h,"year",2007),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, "month", 3), 0);
|
||||||
CODES_CHECK(codes_set_long(h,"day",23),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, "hour", 12), 0);
|
||||||
CODES_CHECK(codes_set_long(h,"minute",0),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, "second", 0), 0);
|
||||||
CODES_CHECK(codes_set_long(h,"dataDate",20070323),0);
|
CODES_CHECK(codes_set_long(h, "dataDate", 20070323), 0);
|
||||||
CODES_CHECK(codes_set_long(h,"dataTime",1200),0);
|
CODES_CHECK(codes_set_long(h, "dataTime", 1200), 0);
|
||||||
|
|
||||||
/* 0 = Operational products (grib2/tables/4/1.3.table) */
|
/* 0 = Operational products (grib2/tables/4/1.3.table) */
|
||||||
CODES_CHECK(codes_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) */
|
/* 2 = Analysis and forecast products (grib2/tables/4/1.4.table) */
|
||||||
CODES_CHECK(codes_set_long(h,"typeOfProcessedData",2),0);
|
CODES_CHECK(codes_set_long(h, "typeOfProcessedData", 2), 0);
|
||||||
|
|
||||||
CODES_CHECK(codes_set_long(h,"selectStepTemplateInterval",1),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, "selectStepTemplateInstant", 1), 0);
|
||||||
CODES_CHECK(codes_set_long(h,"grib2LocalSectionPresent",0),0);
|
CODES_CHECK(codes_set_long(h, "grib2LocalSectionPresent", 0), 0);
|
||||||
|
|
||||||
/* 0 = Specified in Code table 3.1 (grib2/tables/4/3.0.table) */
|
/* 0 = Specified in Code table 3.1 (grib2/tables/4/3.0.table) */
|
||||||
CODES_CHECK(codes_set_long(h,"sourceOfGridDefinition",0),0);
|
CODES_CHECK(codes_set_long(h, "sourceOfGridDefinition", 0), 0);
|
||||||
|
|
||||||
CODES_CHECK(codes_set_long(h,"numberOfDataPoints",496),0);
|
CODES_CHECK(codes_set_long(h, "numberOfDataPoints", 496), 0);
|
||||||
CODES_CHECK(codes_set_long(h,"numberOfOctectsForNumberOfPoints",0),0);
|
CODES_CHECK(codes_set_long(h, "numberOfOctectsForNumberOfPoints", 0), 0);
|
||||||
|
|
||||||
/* 0 = There is no appended list (grib2/tables/4/3.11.table) */
|
/* 0 = There is no appended list (grib2/tables/4/3.11.table) */
|
||||||
CODES_CHECK(codes_set_long(h,"interpretationOfNumberOfPoints",0),0);
|
CODES_CHECK(codes_set_long(h, "interpretationOfNumberOfPoints", 0), 0);
|
||||||
|
|
||||||
CODES_CHECK(codes_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) */
|
/* 0 = Latitude/longitude. Also called equidistant cylindrical, or Plate Carree (grib2/tables/4/3.1.table) */
|
||||||
CODES_CHECK(codes_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) */
|
/* 0 = Earth assumed spherical with radius = 6,367,470.0 m (grib2/tables/4/3.2.table) */
|
||||||
CODES_CHECK(codes_set_long(h,"shapeOfTheEarth",0),0);
|
CODES_CHECK(codes_set_long(h, "shapeOfTheEarth", 0), 0);
|
||||||
|
|
||||||
CODES_CHECK(codes_set_missing(h,"scaleFactorOfRadiusOfSphericalEarth"),0);
|
CODES_CHECK(codes_set_missing(h, "scaleFactorOfRadiusOfSphericalEarth"), 0);
|
||||||
CODES_CHECK(codes_set_missing(h,"scaledValueOfRadiusOfSphericalEarth"),0);
|
CODES_CHECK(codes_set_missing(h, "scaledValueOfRadiusOfSphericalEarth"), 0);
|
||||||
CODES_CHECK(codes_set_missing(h,"scaleFactorOfEarthMajorAxis"),0);
|
CODES_CHECK(codes_set_missing(h, "scaleFactorOfEarthMajorAxis"), 0);
|
||||||
CODES_CHECK(codes_set_missing(h,"scaledValueOfEarthMajorAxis"),0);
|
CODES_CHECK(codes_set_missing(h, "scaledValueOfEarthMajorAxis"), 0);
|
||||||
CODES_CHECK(codes_set_missing(h,"scaleFactorOfEarthMinorAxis"),0);
|
CODES_CHECK(codes_set_missing(h, "scaleFactorOfEarthMinorAxis"), 0);
|
||||||
CODES_CHECK(codes_set_missing(h,"scaledValueOfEarthMinorAxis"),0);
|
CODES_CHECK(codes_set_missing(h, "scaledValueOfEarthMinorAxis"), 0);
|
||||||
CODES_CHECK(codes_set_long(h,"radius",6367470),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, "Ni", 16), 0);
|
||||||
CODES_CHECK(codes_set_long(h,"Nj",31),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, "basicAngleOfTheInitialProductionDomain", 0), 0);
|
||||||
CODES_CHECK(codes_set_long(h,"mBasicAngle",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, "angleMultiplier", 1), 0);
|
||||||
CODES_CHECK(codes_set_long(h,"mAngleMultiplier",1000000),0);
|
CODES_CHECK(codes_set_long(h, "mAngleMultiplier", 1000000), 0);
|
||||||
CODES_CHECK(codes_set_missing(h,"subdivisionsOfBasicAngle"),0);
|
CODES_CHECK(codes_set_missing(h, "subdivisionsOfBasicAngle"), 0);
|
||||||
CODES_CHECK(codes_set_long(h,"angleDivisor",1000000),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, "latitudeOfFirstGridPoint", 60000000), 0);
|
||||||
CODES_CHECK(codes_set_long(h,"longitudeOfFirstGridPoint",0),0);
|
CODES_CHECK(codes_set_long(h, "longitudeOfFirstGridPoint", 0), 0);
|
||||||
|
|
||||||
/* 48 = 00110000
|
/* 48 = 00110000
|
||||||
(3=1) i direction increments given
|
(3=1) i direction increments given
|
||||||
(4=1) j 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
|
(5=0) Resolved u- and v- components of vector quantities relative to easterly and northerly directions
|
||||||
See grib2/tables/[tablesVersion]/3.3.table */
|
See grib2/tables/[tablesVersion]/3.3.table */
|
||||||
CODES_CHECK(codes_set_long(h,"resolutionAndComponentFlags",48),0);
|
CODES_CHECK(codes_set_long(h, "resolutionAndComponentFlags", 48), 0);
|
||||||
|
|
||||||
CODES_CHECK(codes_set_long(h,"iDirectionIncrementGiven",1),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, "jDirectionIncrementGiven", 1), 0);
|
||||||
CODES_CHECK(codes_set_long(h,"uvRelativeToGrid",0),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, "latitudeOfLastGridPoint", 0), 0);
|
||||||
CODES_CHECK(codes_set_long(h,"longitudeOfLastGridPoint",30000000),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, "iDirectionIncrement", 2000000), 0);
|
||||||
CODES_CHECK(codes_set_long(h,"jDirectionIncrement",2000000),0);
|
CODES_CHECK(codes_set_long(h, "jDirectionIncrement", 2000000), 0);
|
||||||
|
|
||||||
/* 0 = 00000000
|
/* 0 = 00000000
|
||||||
(1=0) Points of first row or column scan in the +i (+x) direction
|
(1=0) Points of first row or column scan in the +i (+x) direction
|
||||||
|
@ -138,101 +138,101 @@ int main(int argc, char** argv)
|
||||||
(3=0) Adjacent points in i (x) direction are consecutive
|
(3=0) Adjacent points in i (x) direction are consecutive
|
||||||
(4=0) All rows scan in the same direction
|
(4=0) All rows scan in the same direction
|
||||||
See grib2/tables/[tablesVersion]/3.4.table */
|
See grib2/tables/[tablesVersion]/3.4.table */
|
||||||
CODES_CHECK(codes_set_long(h,"scanningMode",0),0);
|
CODES_CHECK(codes_set_long(h, "scanningMode", 0), 0);
|
||||||
|
|
||||||
CODES_CHECK(codes_set_long(h,"iScansNegatively",0),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, "jScansPositively", 0), 0);
|
||||||
CODES_CHECK(codes_set_long(h,"jPointsAreConsecutive",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, "alternativeRowScanning", 0), 0);
|
||||||
CODES_CHECK(codes_set_long(h,"iScansPositively",1),0);
|
CODES_CHECK(codes_set_long(h, "iScansPositively", 1), 0);
|
||||||
|
|
||||||
/* ITERATOR */
|
/* ITERATOR */
|
||||||
|
|
||||||
|
|
||||||
/* NEAREST */
|
/* NEAREST */
|
||||||
|
|
||||||
CODES_CHECK(codes_set_long(h,"timeRangeIndicator",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, "NV", 0), 0);
|
||||||
CODES_CHECK(codes_set_long(h,"neitherPresent",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) */
|
/* 0 = Analysis or forecast at a horizontal level or in a horizontal layer at a point in time (grib2/tables/4/4.0.table) */
|
||||||
CODES_CHECK(codes_set_long(h,"productDefinitionTemplateNumber",0),0);
|
CODES_CHECK(codes_set_long(h, "productDefinitionTemplateNumber", 0), 0);
|
||||||
|
|
||||||
|
|
||||||
/* Parameter information */
|
/* Parameter information */
|
||||||
|
|
||||||
|
|
||||||
/* 0 = Temperature (grib2/tables/4/4.1.0.table) */
|
/* 0 = Temperature (grib2/tables/4/4.1.0.table) */
|
||||||
CODES_CHECK(codes_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) */
|
/* 0 = Temperature (K) (grib2/tables/4/4.2.0.0.table) */
|
||||||
CODES_CHECK(codes_set_long(h,"parameterNumber",0),0);
|
CODES_CHECK(codes_set_long(h, "parameterNumber", 0), 0);
|
||||||
|
|
||||||
|
|
||||||
/* 0 = Analysis (grib2/tables/4/4.3.table) */
|
/* 0 = Analysis (grib2/tables/4/4.3.table) */
|
||||||
CODES_CHECK(codes_set_long(h,"typeOfGeneratingProcess",0),0);
|
CODES_CHECK(codes_set_long(h, "typeOfGeneratingProcess", 0), 0);
|
||||||
|
|
||||||
CODES_CHECK(codes_set_long(h,"backgroundProcess",255),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, "generatingProcessIdentifier", 128), 0);
|
||||||
CODES_CHECK(codes_set_long(h,"hoursAfterDataCutoff",0),0);
|
CODES_CHECK(codes_set_long(h, "hoursAfterDataCutoff", 0), 0);
|
||||||
CODES_CHECK(codes_set_long(h,"minutesAfterDataCutoff",0),0);
|
CODES_CHECK(codes_set_long(h, "minutesAfterDataCutoff", 0), 0);
|
||||||
|
|
||||||
/* 1 = Hour (grib2/tables/4/4.4.table) */
|
/* 1 = Hour (grib2/tables/4/4.4.table) */
|
||||||
CODES_CHECK(codes_set_long(h,"indicatorOfUnitOfTimeRange",1),0);
|
CODES_CHECK(codes_set_long(h, "indicatorOfUnitOfTimeRange", 1), 0);
|
||||||
|
|
||||||
|
|
||||||
/* 1 = Hour (stepUnits.table) */
|
/* 1 = Hour (stepUnits.table) */
|
||||||
CODES_CHECK(codes_set_long(h,"stepUnits",1),0);
|
CODES_CHECK(codes_set_long(h, "stepUnits", 1), 0);
|
||||||
|
|
||||||
CODES_CHECK(codes_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) */
|
/* 1 = Ground or water surface (grib2/tables/4/4.5.table) */
|
||||||
CODES_CHECK(codes_set_long(h,"typeOfFirstFixedSurface",1),0);
|
CODES_CHECK(codes_set_long(h, "typeOfFirstFixedSurface", 1), 0);
|
||||||
|
|
||||||
CODES_CHECK(codes_set_missing(h,"scaleFactorOfFirstFixedSurface"),0);
|
CODES_CHECK(codes_set_missing(h, "scaleFactorOfFirstFixedSurface"), 0);
|
||||||
CODES_CHECK(codes_set_missing(h,"scaledValueOfFirstFixedSurface"),0);
|
CODES_CHECK(codes_set_missing(h, "scaledValueOfFirstFixedSurface"), 0);
|
||||||
|
|
||||||
/* 255 = Missing (grib2/tables/4/4.5.table) */
|
/* 255 = Missing (grib2/tables/4/4.5.table) */
|
||||||
CODES_CHECK(codes_set_long(h,"typeOfSecondFixedSurface",255),0);
|
CODES_CHECK(codes_set_long(h, "typeOfSecondFixedSurface", 255), 0);
|
||||||
|
|
||||||
CODES_CHECK(codes_set_missing(h,"scaleFactorOfSecondFixedSurface"),0);
|
CODES_CHECK(codes_set_missing(h, "scaleFactorOfSecondFixedSurface"), 0);
|
||||||
CODES_CHECK(codes_set_missing(h,"scaledValueOfSecondFixedSurface"),0);
|
CODES_CHECK(codes_set_missing(h, "scaledValueOfSecondFixedSurface"), 0);
|
||||||
CODES_CHECK(codes_set_long(h,"level",0),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, "bottomLevel", 0), 0);
|
||||||
CODES_CHECK(codes_set_long(h,"topLevel",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, "dummyc", 0), 0);
|
||||||
CODES_CHECK(codes_set_long(h,"PVPresent",0),0);
|
CODES_CHECK(codes_set_long(h, "PVPresent", 0), 0);
|
||||||
|
|
||||||
/* grib 2 Section 5 DATA REPRESENTATION SECTION */
|
/* grib 2 Section 5 DATA REPRESENTATION SECTION */
|
||||||
|
|
||||||
CODES_CHECK(codes_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) */
|
/* 0 = Grid point data - simple packing (grib2/tables/4/5.0.table) */
|
||||||
CODES_CHECK(codes_set_long(h,"dataRepresentationTemplateNumber",0),0);
|
CODES_CHECK(codes_set_long(h, "dataRepresentationTemplateNumber", 0), 0);
|
||||||
|
|
||||||
CODES_CHECK(codes_set_long(h,"decimalScaleFactor",0),0);
|
CODES_CHECK(codes_set_long(h, "decimalScaleFactor", 0), 0);
|
||||||
CODES_CHECK(codes_set_long(h,"bitsPerValue",0),0);
|
CODES_CHECK(codes_set_long(h, "bitsPerValue", 0), 0);
|
||||||
|
|
||||||
/* 0 = Floating point (grib2/tables/4/5.1.table) */
|
/* 0 = Floating point (grib2/tables/4/5.1.table) */
|
||||||
CODES_CHECK(codes_set_long(h,"typeOfOriginalFieldValues",0),0);
|
CODES_CHECK(codes_set_long(h, "typeOfOriginalFieldValues", 0), 0);
|
||||||
|
|
||||||
CODES_CHECK(codes_set_long(h,"representationMode",0),0);
|
CODES_CHECK(codes_set_long(h, "representationMode", 0), 0);
|
||||||
|
|
||||||
/* grib 2 Section 6 BIT-MAP SECTION */
|
/* grib 2 Section 6 BIT-MAP SECTION */
|
||||||
|
|
||||||
|
|
||||||
/* 255 = A bit map does not apply to this product (grib2/tables/4/6.0.table) */
|
/* 255 = A bit map does not apply to this product (grib2/tables/4/6.0.table) */
|
||||||
CODES_CHECK(codes_set_long(h,"bitMapIndicator",255),0);
|
CODES_CHECK(codes_set_long(h, "bitMapIndicator", 255), 0);
|
||||||
|
|
||||||
CODES_CHECK(codes_set_long(h,"bitmapPresent",0),0);
|
CODES_CHECK(codes_set_long(h, "bitmapPresent", 0), 0);
|
||||||
|
|
||||||
/* grib 2 Section 7 data */
|
/* grib 2 Section 7 data */
|
||||||
|
|
||||||
size = 496;
|
size = 496;
|
||||||
vdouble = (double*)calloc(size,sizeof(double));
|
vdouble = (double*)calloc(size, sizeof(double));
|
||||||
if(!vdouble) {
|
if (!vdouble) {
|
||||||
fprintf(stderr,"failed to allocate %lu bytes\n",size*sizeof(double));
|
fprintf(stderr, "failed to allocate %lu bytes\n", size * sizeof(double));
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -361,28 +361,28 @@ int main(int argc, char** argv)
|
||||||
vdouble[ 488] = 1; vdouble[ 489] = 1; vdouble[ 490] = 1; vdouble[ 491] = 1;
|
vdouble[ 488] = 1; vdouble[ 489] = 1; vdouble[ 490] = 1; vdouble[ 491] = 1;
|
||||||
vdouble[ 492] = 1; vdouble[ 493] = 1; vdouble[ 494] = 1; vdouble[ 495] = 1;
|
vdouble[ 492] = 1; vdouble[ 493] = 1; vdouble[ 494] = 1; vdouble[ 495] = 1;
|
||||||
|
|
||||||
CODES_CHECK(codes_set_double_array(h,"values",vdouble,size),0);
|
CODES_CHECK(codes_set_double_array(h, "values", vdouble, size), 0);
|
||||||
free(vdouble);
|
free(vdouble);
|
||||||
CODES_CHECK(codes_set_long(h,"dirty_statistics",1),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, "changeDecimalPrecision", 0), 0);
|
||||||
CODES_CHECK(codes_set_long(h,"decimalPrecision",0),0);
|
CODES_CHECK(codes_set_long(h, "decimalPrecision", 0), 0);
|
||||||
CODES_CHECK(codes_set_long(h,"setBitsPerValue",0),0);
|
CODES_CHECK(codes_set_long(h, "setBitsPerValue", 0), 0);
|
||||||
/* Save the message */
|
/* Save the message */
|
||||||
|
|
||||||
f = fopen(argv[1],"wb");
|
f = fopen(argv[1], "wb");
|
||||||
if(!f) {
|
if (!f) {
|
||||||
perror(argv[1]);
|
perror(argv[1]);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
CODES_CHECK(codes_get_message(h,&buffer,&size),0);
|
CODES_CHECK(codes_get_message(h, &buffer, &size), 0);
|
||||||
|
|
||||||
if(fwrite(buffer,1,size,f) != size) {
|
if (fwrite(buffer, 1, size, f) != size) {
|
||||||
perror(argv[1]);
|
perror(argv[1]);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(fclose(f)) {
|
if (fclose(f)) {
|
||||||
perror(argv[1]);
|
perror(argv[1]);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,26 +23,26 @@ int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
int err = 0, is_missing = 0;
|
int err = 0, is_missing = 0;
|
||||||
|
|
||||||
FILE* in = NULL;
|
FILE* in = NULL;
|
||||||
const char* infile = "../../data/reduced_gaussian_pressure_level.grib2";
|
const char* infile = "../../data/reduced_gaussian_pressure_level.grib2";
|
||||||
FILE* out = NULL;
|
FILE* out = NULL;
|
||||||
const char* outfile = "out_surface_level.grib2";
|
const char* outfile = "out_surface_level.grib2";
|
||||||
codes_handle *h = NULL;
|
codes_handle* h = NULL;
|
||||||
const void* buffer = NULL;
|
const void* buffer = NULL;
|
||||||
size_t size=0;
|
size_t size = 0;
|
||||||
char str[]="sfc";
|
char str[] = "sfc";
|
||||||
size_t str_len=3;
|
size_t str_len = 3;
|
||||||
long Ni = 0;
|
long Ni = 0;
|
||||||
|
|
||||||
in = fopen(infile,"rb");
|
in = fopen(infile, "rb");
|
||||||
if(!in) {
|
if (!in) {
|
||||||
printf("ERROR: unable to open input file %s\n",infile);
|
printf("ERROR: unable to open input file %s\n", infile);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
out = fopen(outfile,"wb");
|
out = fopen(outfile, "wb");
|
||||||
if(!out) {
|
if (!out) {
|
||||||
printf("ERROR: unable to open output file %s\n",outfile);
|
printf("ERROR: unable to open output file %s\n", outfile);
|
||||||
fclose(in);
|
fclose(in);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -50,26 +50,25 @@ int main(int argc, char** argv)
|
||||||
/* create a new handle from a message in a file */
|
/* create a new handle from a message in a file */
|
||||||
h = codes_handle_new_from_file(0, in, PRODUCT_GRIB, &err);
|
h = codes_handle_new_from_file(0, in, PRODUCT_GRIB, &err);
|
||||||
if (h == NULL) {
|
if (h == NULL) {
|
||||||
printf("Error: unable to create handle from file %s\n",infile);
|
printf("Error: unable to create handle from file %s\n", infile);
|
||||||
}
|
}
|
||||||
|
|
||||||
CODES_CHECK(codes_set_string(h,"typeOfFirstFixedSurface",str,&str_len),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, "scaleFactorOfFirstFixedSurface"), 0);
|
||||||
CODES_CHECK(codes_set_missing(h,"scaledValueOfFirstFixedSurface"),0);
|
CODES_CHECK(codes_set_missing(h, "scaledValueOfFirstFixedSurface"), 0);
|
||||||
|
|
||||||
/* See GRIB-490 */
|
/* See GRIB-490 */
|
||||||
CODES_CHECK(codes_get_long(h,"Ni",&Ni),0);
|
CODES_CHECK(codes_get_long(h, "Ni", &Ni), 0);
|
||||||
is_missing = codes_is_missing(h, "Ni", &err);
|
is_missing = codes_is_missing(h, "Ni", &err);
|
||||||
CODES_CHECK(err,0);
|
CODES_CHECK(err, 0);
|
||||||
if (is_missing != 1) assert(!"Ni should be missing");
|
if (is_missing != 1) assert(!"Ni should be missing");
|
||||||
CODES_CHECK(codes_set_long(h,"Ni", Ni),0);
|
CODES_CHECK(codes_set_long(h, "Ni", Ni), 0);
|
||||||
|
|
||||||
/* get the coded message in a buffer */
|
/* get the coded message in a buffer */
|
||||||
CODES_CHECK(codes_get_message(h,&buffer,&size),0);
|
CODES_CHECK(codes_get_message(h, &buffer, &size), 0);
|
||||||
|
|
||||||
/* write the buffer in a file*/
|
/* write the buffer in a file*/
|
||||||
if(fwrite(buffer,1,size,out) != size)
|
if (fwrite(buffer, 1, size, out) != size) {
|
||||||
{
|
|
||||||
perror(argv[1]);
|
perror(argv[1]);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,55 +11,54 @@
|
||||||
|
|
||||||
int main(int argc, char* argv[])
|
int main(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
FILE* f;
|
FILE* f;
|
||||||
int err=0;
|
int err = 0;
|
||||||
char infile[]="../../data/reduced_gaussian_model_level.grib1";
|
char infile[] = "../../data/reduced_gaussian_model_level.grib1";
|
||||||
codes_handle *h=NULL;
|
codes_handle* h = NULL;
|
||||||
codes_context* c=codes_context_get_default();
|
codes_context* c = codes_context_get_default();
|
||||||
codes_values values[2];
|
codes_values values[2];
|
||||||
int nvalues=2;
|
int nvalues = 2;
|
||||||
int i;
|
int i;
|
||||||
char* name = NULL;
|
char* name = NULL;
|
||||||
|
|
||||||
f=fopen(infile,"rb");
|
f = fopen(infile, "rb");
|
||||||
if (!f) {
|
if (!f) {
|
||||||
perror(infile);
|
perror(infile);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
h=codes_handle_new_from_file(c,f,PRODUCT_GRIB,&err);
|
h = codes_handle_new_from_file(c, f, PRODUCT_GRIB, &err);
|
||||||
if (!h) {
|
if (!h) {
|
||||||
printf("unable to create handle from file %s\n",infile);
|
printf("unable to create handle from file %s\n", infile);
|
||||||
exit(err);
|
exit(err);
|
||||||
}
|
}
|
||||||
fclose(f);
|
fclose(f);
|
||||||
|
|
||||||
values[0].type=CODES_TYPE_LONG;
|
values[0].type = CODES_TYPE_LONG;
|
||||||
values[0].name="centre";
|
values[0].name = "centre";
|
||||||
values[0].long_value=98;
|
values[0].long_value = 98;
|
||||||
|
|
||||||
values[1].type=CODES_TYPE_LONG;
|
values[1].type = CODES_TYPE_LONG;
|
||||||
values[1].name="level";
|
values[1].name = "level";
|
||||||
values[1].long_value=2;
|
values[1].long_value = 2;
|
||||||
|
|
||||||
/*CODES_VALUE_DIFFERENT -> value is different*/
|
/*CODES_VALUE_DIFFERENT -> value is different*/
|
||||||
err=codes_values_check(h,values,nvalues);
|
err = codes_values_check(h, values, nvalues);
|
||||||
if (err) {
|
if (err) {
|
||||||
for (i=0;i<nvalues;i++) {
|
for (i = 0; i < nvalues; i++) {
|
||||||
if (values[i].error==err) name=(char*)values[i].name;
|
if (values[i].error == err) name = (char*)values[i].name;
|
||||||
}
|
}
|
||||||
printf("ERROR: \"%s\" %s\n",name,codes_get_error_message(err));
|
printf("ERROR: \"%s\" %s\n", name, codes_get_error_message(err));
|
||||||
}
|
}
|
||||||
|
|
||||||
values[1].name="levelll";
|
values[1].name = "levelll";
|
||||||
err=codes_values_check(h,values,nvalues);
|
err = codes_values_check(h, values, nvalues);
|
||||||
if (err) {
|
if (err) {
|
||||||
for (i=0;i<nvalues;i++) {
|
for (i = 0; i < nvalues; i++) {
|
||||||
if (values[i].error==err) name=(char*)values[i].name;
|
if (values[i].error == err) name = (char*)values[i].name;
|
||||||
}
|
}
|
||||||
printf("ERROR: \"%s\" %s\n",name,codes_get_error_message(err));
|
printf("ERROR: \"%s\" %s\n", name, codes_get_error_message(err));
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue