grib_api: multi.c

- Main Page
- Modules
- Files
- Related Pages
- Examples

# multi.c

multi.c How to decode a grib message containing many fields.

    00001
    00010 /*
    00011  * C Implementation: multi
    00012  *
    00013  * Description: How to decode grib messages containing multiple
    00014  *              fields. Try to turn on and off multi support to
    00015  *              see the difference. Default is OFF.
    00016  *                      For all the tools defalut is multi support ON.
    00017  *
    00018  *
    00019  * Author: Enrico Fucile
    00020  *
    00021  *
    00022  */
    00023 #include <stdio.h>
    00024 #include <stdlib.h>
    00025
    00026 #include "grib_api.h"
    00027
    00028 int main(int argc, char** argv) {
    00029   int err = 0;
    00030   long parameterCategory=0,parameterNumber=0,discipline=0;
    00031   FILE* in = NULL;
    00032   char* filename = "../../data/multi.grib2";
    00033   grib_handle *h = NULL;
    00034
    00035   /* turn on support for multi fields messages */
    00036   grib_multi_support_on(0);
    00037
    00038   /* turn off support for multi fields messages */
    00039   /* grib_multi_support_off(0); */
    00040
    00041   in = fopen(filename,"r");
    00042   if(!in) {
    00043     printf("ERROR: unable to open file %s\n",filename);
    00044     return 1;
    00045   }
    00046
    00047
    00048   while ((h = grib_handle_new_from_file(0,in,&err)) != NULL ) {
    00049
    00050     GRIB_CHECK(err,0);
    00051
    00052     GRIB_CHECK(grib_get_long(h,"discipline",&discipline),0);
    00053     printf("discipline=%ld\n",discipline);
    00054
    00055     GRIB_CHECK(grib_get_long(h,"parameterCategory",&parameterCategory),0);
    00056     printf("parameterCategory=%ld\n",parameterCategory);
    00057
    00058     GRIB_CHECK(grib_get_long(h,"parameterNumber",&parameterNumber),0);
    00059     printf("parameterNumber=%ld\n",parameterNumber);
    00060
    00061     if ( discipline == 0 && parameterCategory==2) {
    00062     if (parameterNumber == 2) printf("-------- u -------\n");
    00063     if (parameterNumber == 3) printf("-------- v -------\n");
    00064     }
    00065   }
    00066
    00067   grib_handle_delete(h);
    00068
    00069   fclose(in);
    00070   return 0;
    00071 }