From be4fce642cb4eb1df5a49e4849333e535d97125e Mon Sep 17 00:00:00 2001 From: Sandor Kertesz Date: Mon, 9 Feb 2015 16:39:14 +0000 Subject: [PATCH] Add C, F90 and python examples ECC-15 --- examples/C/bufr_keys_iterator.c | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/examples/C/bufr_keys_iterator.c b/examples/C/bufr_keys_iterator.c index 48366a8e3..8fffba46a 100644 --- a/examples/C/bufr_keys_iterator.c +++ b/examples/C/bufr_keys_iterator.c @@ -36,6 +36,7 @@ int main(int argc,char* argv[]) codes_handle* h=NULL; long longVal; int err=0, cnt=0; + int keyType; /* To skip certain keys use the combination of these flags: @@ -84,14 +85,34 @@ int main(int argc,char* argv[]) printf("ERROR: Unable to create keys iterator\n"); exit(1); } - + + /* we need to instruct ecCodes to unpack the data values */ + /*CODES_CHECK(codes_set_long(h,"unpack",1),0);*/ + /* loop over the keys */ while(codes_keys_iterator_next(kiter)) { /* get key name*/ const char* name = codes_keys_iterator_get_name(kiter); + printf(" %s=",name); + + CODES_CHECK(codes_get_native_type(h,name,&keyType),0); - printf(" %s\n",name); + /* get key size to see if it is an array */ + CODES_CHECK(codes_get_size(h,name,&klen),0); + + /* not array */ + if(klen ==1 || keyType == CODES_TYPE_STRING) + { + vlen=MAX_VAL_LEN; + bzero(value,vlen); + + codes_get_string(h,name,value,&vlen); + printf("%s\n",value); + } + /* for arrays */ + else + printf("(array of %ld)\n",klen); } /* delete key iterator */