mirror of https://github.com/ecmwf/eccodes.git
Examples: use codes_ prefix
This commit is contained in:
parent
3a9501e73c
commit
66ff19382e
|
@ -135,9 +135,9 @@ int main(int argc, char** argv)
|
||||||
char* name = "reservedNeedNotBePresent";
|
char* name = "reservedNeedNotBePresent";
|
||||||
unsigned char* byte_val = NULL ;
|
unsigned char* byte_val = NULL ;
|
||||||
size_t keySize = 0;
|
size_t keySize = 0;
|
||||||
CODES_CHECK(grib_get_size(h, name, &keySize), 0);
|
CODES_CHECK(codes_get_size(h, name, &keySize), 0);
|
||||||
byte_val = malloc(keySize*sizeof(char));
|
byte_val = malloc(keySize*sizeof(char));
|
||||||
GRIB_CHECK(grib_get_bytes(h, name, byte_val, &keySize), name);
|
GRIB_CHECK(codes_get_bytes(h, name, byte_val, &keySize), name);
|
||||||
}
|
}
|
||||||
|
|
||||||
codes_handle_delete(h);
|
codes_handle_delete(h);
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "grib_api.h"
|
#include "eccodes.h"
|
||||||
|
|
||||||
void usage(char* prog) {
|
void usage(char* prog) {
|
||||||
printf("usage: %s infile\n",prog);
|
printf("usage: %s infile\n",prog);
|
||||||
|
@ -24,8 +24,8 @@ void usage(char* prog) {
|
||||||
|
|
||||||
int main(int argc,char* argv[])
|
int main(int argc,char* argv[])
|
||||||
{
|
{
|
||||||
grib_index* index=NULL;
|
codes_index* index=NULL;
|
||||||
grib_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;
|
||||||
|
@ -42,51 +42,51 @@ 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=grib_index_new(0,"shortName,level,number,step",&ret);
|
index=codes_index_new(0,"shortName,level,number,step",&ret);
|
||||||
if (ret) {printf("error: %s\n",grib_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=grib_index_add_file(index,infile);
|
ret=codes_index_add_file(index,infile);
|
||||||
if (ret) {printf("error: %s\n",grib_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 */
|
||||||
GRIB_CHECK(grib_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 */
|
||||||
GRIB_CHECK(grib_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"*/
|
||||||
GRIB_CHECK(grib_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"*/
|
||||||
GRIB_CHECK(grib_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"*/
|
||||||
GRIB_CHECK(grib_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"*/
|
||||||
GRIB_CHECK(grib_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"*/
|
||||||
GRIB_CHECK(grib_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"*/
|
||||||
GRIB_CHECK(grib_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");
|
||||||
|
@ -96,47 +96,47 @@ int main(int argc,char* argv[])
|
||||||
/* 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] */
|
||||||
grib_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] */
|
||||||
grib_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] */
|
||||||
grib_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] */
|
||||||
grib_index_select_long(index,"step",steps[k]);
|
codes_index_select_long(index,"step",steps[k]);
|
||||||
|
|
||||||
/* create a new grib_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=grib_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) {printf("error: %d\n",ret); exit(ret);}
|
||||||
lenshortName=200;
|
lenshortName=200;
|
||||||
grib_get_string(h,"shortName",oshortName,&lenshortName);
|
codes_get_string(h,"shortName",oshortName,&lenshortName);
|
||||||
grib_get_long(h,"level",&olevel);
|
codes_get_long(h,"level",&olevel);
|
||||||
grib_get_long(h,"number",&onumber);
|
codes_get_long(h,"number",&onumber);
|
||||||
grib_get_long(h,"step",&ostep);
|
codes_get_long(h,"step",&ostep);
|
||||||
printf("shortName=%s ",oshortName);
|
printf("shortName=%s ",oshortName);
|
||||||
printf("level=%ld ",olevel);
|
printf("level=%ld ",olevel);
|
||||||
printf("number=%ld ",onumber);
|
printf("number=%ld ",onumber);
|
||||||
printf("step=%ld \n",ostep);
|
printf("step=%ld \n",ostep);
|
||||||
grib_handle_delete(h);
|
codes_handle_delete(h);
|
||||||
}
|
}
|
||||||
if (ret && ret!=GRIB_END_OF_INDEX ) {printf("error: %s\n",grib_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);
|
||||||
|
|
||||||
grib_index_write(index,"out.gribidx");
|
codes_index_write(index,"out.gribidx");
|
||||||
grib_index_delete(index);
|
codes_index_delete(index);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,7 +34,7 @@ int main(int argc, char** argv)
|
||||||
int n=0;
|
int n=0;
|
||||||
char* filename = NULL;
|
char* filename = NULL;
|
||||||
|
|
||||||
/* Message handle. Required in all the grib_api 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;
|
||||||
|
|
|
@ -76,7 +76,7 @@ int main(int argc, char** argv)
|
||||||
const int NUM = 3;
|
const int NUM = 3;
|
||||||
int index_arr[] = {0, values_len/2, values_len-1};
|
int index_arr[] = {0, values_len/2, values_len-1};
|
||||||
double vals_arr[3] = {0, 0, 0};
|
double vals_arr[3] = {0, 0, 0};
|
||||||
CODES_CHECK(grib_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]);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue