mirror of https://github.com/ecmwf/eccodes.git
Examples: cleanup
This commit is contained in:
parent
986cad5ede
commit
53a870d67b
|
@ -34,7 +34,7 @@ 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;
|
||||||
|
@ -51,7 +51,7 @@ int main(int argc, char* argv[])
|
||||||
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) {
|
||||||
fprintf(stderr, "Error: unable to create handle for message %d\n", cnt);
|
fprintf(stderr, "Error: unable to create handle for message %d\n", cnt);
|
||||||
|
@ -61,11 +61,11 @@ int main(int argc, char* argv[])
|
||||||
|
|
||||||
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
|
||||||
* verticalSoundingSignificance is 4 (see flag table 8001 for details).
|
* verticalSoundingSignificance is 4 (see flag table 8001 for details).
|
||||||
*
|
*
|
||||||
|
@ -76,9 +76,9 @@ int main(int argc, char* argv[])
|
||||||
* condition: verticalSoundingSignificance=4.
|
* condition: verticalSoundingSignificance=4.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* Get the number of the temperature significant levels.*/
|
/* get the number of the temperature significant levels.*/
|
||||||
|
|
||||||
/* 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");
|
||||||
|
@ -86,22 +86,22 @@ int main(int argc, char* argv[])
|
||||||
|
|
||||||
printf("Number of T significant levels: %lu\n", (unsigned long)sigt_len);
|
printf("Number of T significant levels: %lu\n", (unsigned long)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) {
|
||||||
fprintf(stderr, "Error: inconsistent number of geopotential values found!\n");
|
fprintf(stderr, "Error: inconsistent number of geopotential values found!\n");
|
||||||
|
@ -109,32 +109,32 @@ int main(int argc, char* argv[])
|
||||||
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 */
|
||||||
fprintf(stderr, "Error: inconsistent number of temperature values found!\n");
|
fprintf(stderr, "Error: inconsistent number of temperature values found!\n");
|
||||||
free_memory(sigt_pres, sigt_geo, sigt_t, sigt_td);
|
free_memory(sigt_pres, sigt_geo, sigt_t, sigt_td);
|
||||||
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 */
|
||||||
fprintf(stderr, "Error: inconsistent number of dewpoint temperature values found!\n");
|
fprintf(stderr, "Error: inconsistent number of dewpoint temperature values found!\n");
|
||||||
free_memory(sigt_pres, sigt_geo, sigt_t, sigt_td);
|
free_memory(sigt_pres, sigt_geo, sigt_t, sigt_td);
|
||||||
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");
|
||||||
|
|
||||||
|
@ -143,10 +143,8 @@ int main(int argc, char* argv[])
|
||||||
(unsigned long)(i + 1), sigt_pres[i], sigt_geo[i], sigt_t[i], sigt_td[i]);
|
(unsigned long)(i + 1), sigt_pres[i], sigt_geo[i], sigt_t[i], sigt_td[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Delete handle */
|
/* release memory */
|
||||||
codes_handle_delete(h);
|
codes_handle_delete(h);
|
||||||
|
|
||||||
/* Release memory */
|
|
||||||
free_memory(sigt_pres, sigt_geo, sigt_t, sigt_td);
|
free_memory(sigt_pres, sigt_geo, sigt_t, sigt_td);
|
||||||
|
|
||||||
cnt++;
|
cnt++;
|
||||||
|
|
|
@ -68,8 +68,8 @@ int main(int argc, char* argv[])
|
||||||
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);*/
|
||||||
|
|
||||||
/* This is the place where you may wish to modify the message*/
|
/* this is the place where you may wish to modify the message */
|
||||||
/*E.g. we change the centre */
|
/* e.g. we change the centre */
|
||||||
|
|
||||||
/* set bufrHeaderCentre */
|
/* set bufrHeaderCentre */
|
||||||
longVal = 222;
|
longVal = 222;
|
||||||
|
|
|
@ -58,8 +58,8 @@ int main(int argc, char* argv[])
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 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.
|
/* e.g.
|
||||||
CODES_CHECK(codes_set_long(clone_handle, "centre", 250),0);
|
CODES_CHECK(codes_set_long(clone_handle, "centre", 250),0);
|
||||||
etc...
|
etc...
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -58,7 +58,7 @@ int main(int argc, char** argv)
|
||||||
}
|
}
|
||||||
fclose(in);
|
fclose(in);
|
||||||
|
|
||||||
/* Store the filename in the key "file" for this handle */
|
/* store the filename in the key "file" for this handle */
|
||||||
len = strlen(filename);
|
len = strlen(filename);
|
||||||
CODES_CHECK(codes_set_string(h, "file", filename, &len), 0);
|
CODES_CHECK(codes_set_string(h, "file", filename, &len), 0);
|
||||||
|
|
||||||
|
@ -121,7 +121,7 @@ int main(int argc, char** argv)
|
||||||
|
|
||||||
{
|
{
|
||||||
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));
|
||||||
|
@ -131,7 +131,7 @@ 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;
|
||||||
|
|
|
@ -42,14 +42,14 @@ int main(int argc, char* argv[])
|
||||||
|
|
||||||
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) {
|
if (ret) {
|
||||||
fprintf(stderr, "Error: %s\n", codes_get_error_message(ret));
|
fprintf(stderr, "Error: %s\n", codes_get_error_message(ret));
|
||||||
exit(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) {
|
if (ret) {
|
||||||
fprintf(stderr, "Error: %s\n", codes_get_error_message(ret));
|
fprintf(stderr, "Error: %s\n", codes_get_error_message(ret));
|
||||||
|
|
|
@ -30,14 +30,14 @@ 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;
|
||||||
long bitmapPresent = 0;
|
long bitmapPresent = 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]);
|
||||||
|
@ -50,28 +50,28 @@ int main(int argc, char** argv)
|
||||||
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);
|
||||||
|
|
||||||
/* Check if a bitmap applies */
|
/* check if a bitmap applies */
|
||||||
CODES_CHECK(codes_get_long(h, "bitmapPresent", &bitmapPresent), 0);
|
CODES_CHECK(codes_get_long(h, "bitmapPresent", &bitmapPresent), 0);
|
||||||
|
|
||||||
if (bitmapPresent) {
|
if (bitmapPresent) {
|
||||||
/* 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, */
|
/* 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 (bitmapPresent && value == missingValue) printf("missing\n");
|
if (bitmapPresent && value == missingValue) printf("missing\n");
|
||||||
|
@ -81,10 +81,10 @@ int main(int argc, char** argv)
|
||||||
n++;
|
n++;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* At the end the iterator is deleted to free memory. */
|
/* at the end the iterator is deleted to free memory. */
|
||||||
codes_grib_iterator_delete(iter);
|
codes_grib_iterator_delete(iter);
|
||||||
|
|
||||||
/* At the end the codes_handle is deleted to free memory. */
|
/* at the end the codes_handle is deleted to free memory */
|
||||||
codes_handle_delete(h);
|
codes_handle_delete(h);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -57,7 +57,7 @@ int main(int argc, char** argv)
|
||||||
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", (unsigned long)bmp_len);
|
printf("Bitmap is present. Num = %lu\n", (unsigned long)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);
|
||||||
|
@ -65,21 +65,21 @@ int main(int argc, char** argv)
|
||||||
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++;
|
||||||
}
|
}
|
||||||
/* Check number of elements in iterator matches value count */
|
/* check number of elements in iterator matches value count */
|
||||||
assert(n == values_len);
|
assert(n == values_len);
|
||||||
|
|
||||||
codes_grib_iterator_delete(iter);
|
codes_grib_iterator_delete(iter);
|
||||||
|
|
|
@ -31,14 +31,14 @@ 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 |
|
||||||
CODES_KEYS_ITERATOR_SKIP_COMPUTED;
|
CODES_KEYS_ITERATOR_SKIP_COMPUTED;
|
||||||
*/
|
*/
|
||||||
unsigned long key_iterator_filter_flags = CODES_KEYS_ITERATOR_ALL_KEYS |
|
unsigned long key_iterator_filter_flags = CODES_KEYS_ITERATOR_ALL_KEYS |
|
||||||
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 */
|
||||||
|
@ -79,7 +79,7 @@ int main(int argc, char* argv[])
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -51,11 +51,11 @@ int main(int argc, char** argv)
|
||||||
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);
|
||||||
|
|
||||||
|
|
|
@ -46,11 +46,11 @@ int main(int argc, char** argv)
|
||||||
|
|
||||||
if (argc < 2) usage(argv[0]);
|
if (argc < 2) usage(argv[0]);
|
||||||
|
|
||||||
/* 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) {
|
if (!fin) {
|
||||||
perror(fname);
|
perror(fname);
|
||||||
exit(1);
|
exit(1);
|
||||||
|
@ -111,7 +111,7 @@ int main(int argc, char** argv)
|
||||||
}
|
}
|
||||||
|
|
||||||
fname = argv[1];
|
fname = argv[1];
|
||||||
fin = fopen(fname, "r"); /* Open in text mode */
|
fin = fopen(fname, "r"); /* open in text mode */
|
||||||
if (!fin) {
|
if (!fin) {
|
||||||
perror(fname);
|
perror(fname);
|
||||||
exit(1);
|
exit(1);
|
||||||
|
@ -127,9 +127,9 @@ int main(int argc, char** argv)
|
||||||
}
|
}
|
||||||
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) {
|
if (!fin) {
|
||||||
perror(fname);
|
perror(fname);
|
||||||
exit(1);
|
exit(1);
|
||||||
|
|
|
@ -78,7 +78,7 @@ int main(int argc, char** argv)
|
||||||
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);
|
||||||
|
|
||||||
|
|
|
@ -73,7 +73,7 @@ int main(int argc, char** argv)
|
||||||
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];
|
||||||
|
|
|
@ -54,14 +54,14 @@ int main(int argc, char* argv[])
|
||||||
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:
|
||||||
* CODES_SECTION_PRODUCT
|
* CODES_SECTION_PRODUCT
|
||||||
* CODES_SECTION_GRID
|
* CODES_SECTION_GRID
|
||||||
* CODES_SECTION_LOCAL
|
* CODES_SECTION_LOCAL
|
||||||
* CODES_SECTION_DATA
|
* CODES_SECTION_DATA
|
||||||
* CODES_SECTION_BITMAP
|
* CODES_SECTION_BITMAP
|
||||||
* 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') {
|
||||||
|
@ -85,11 +85,10 @@ int main(int argc, char* argv[])
|
||||||
what |= CODES_SECTION_BITMAP;
|
what |= CODES_SECTION_BITMAP;
|
||||||
}
|
}
|
||||||
else if (isspace(what_str[i]) || what_str[i] == ',') {
|
else if (isspace(what_str[i]) || what_str[i] == ',') {
|
||||||
/* 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]);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -76,7 +76,7 @@ int main(int argc, char** argv)
|
||||||
/* set the values (the bitmap will be automatically built) */
|
/* set the values (the bitmap will be automatically built) */
|
||||||
CODES_CHECK(codes_set_double_array(h, "values", values, values_len), 0);
|
CODES_CHECK(codes_set_double_array(h, "values", values, values_len), 0);
|
||||||
|
|
||||||
/* Sanity checks */
|
/* sanity checks */
|
||||||
CODES_CHECK(codes_get_long(h, "numberOfDataPoints", &num_of_data_points), 0);
|
CODES_CHECK(codes_get_long(h, "numberOfDataPoints", &num_of_data_points), 0);
|
||||||
CODES_CHECK(codes_get_long(h, "numberOfCodedValues", &num_of_coded_values), 0);
|
CODES_CHECK(codes_get_long(h, "numberOfCodedValues", &num_of_coded_values), 0);
|
||||||
CODES_CHECK(codes_get_long(h, "numberOfMissing", &num_of_missing), 0);
|
CODES_CHECK(codes_get_long(h, "numberOfMissing", &num_of_missing), 0);
|
||||||
|
|
|
@ -38,7 +38,8 @@ int main(int argc, char** argv)
|
||||||
/* see where that is). The default sample path can be changed by */
|
/* see where that is). The default sample path can be changed by */
|
||||||
/* setting the environment variable ECCODES_SAMPLES_PATH */
|
/* setting the environment variable ECCODES_SAMPLES_PATH */
|
||||||
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;
|
||||||
|
@ -53,7 +54,7 @@ int main(int argc, char** argv)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Here we're changing the data values only, so the number of values */
|
/* here we're changing the data values only, so the number of values */
|
||||||
/* 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 */
|
||||||
|
|
|
@ -58,7 +58,7 @@ int main(int argc, char** argv)
|
||||||
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);
|
||||||
assert(!err);
|
assert(!err);
|
||||||
|
|
|
@ -68,7 +68,7 @@ int main(int argc, char** argv)
|
||||||
|
|
||||||
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);
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,7 @@ int main()
|
||||||
|
|
||||||
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 - requested %lu bytes\n", ni * nj * sizeof(double));
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue