Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  1. The grib_filter processes sequentially all grib messages contained in the input files and applies the rules to each one of them. Input messages can be written to the output by using the "write" statement. The write statement can be parameterised so that output is sent to multiple files depending on key values used in the output file name. If we write a rules_file containing the only statement:

    Code Block
    write "../data/split/[centre]_[date]_[dataType]_[levelType].grib[editionNumber]";
    
    Applying this rules_file to the "../data/tigge_pf_ecmwf.grib2" grib file we obtain several files in the ../data/split directory containing fields split according to their key values
    Code Block
    > grib_filter rules_file ../data/tigge_pf_ecmwf.grib2
    > ls ../data/split
    ecmf_20060619_pf_sfc.grib2
    ecmf_20060630_pf_sfc.grib2
    ecmf_20070122_pf_pl.grib2
    ecmf_20070122_pf_pt.grib2
    ecmf_20070122_pf_pv.grib2
    ecmf_20070122_pf_sfc.grib2
    


  2. The key values in the file name can also be obtained in a different format by indicating explicitly the type required after a colon.

    • :l for long
    • :d for double
    • :s for string
    The following statement works in a slightly different way from the previous example, including in the output file name the long values for centre and dataType.
    Code Block
    write "../data/split/[centre:l]_[date]_[dataType:l]_[levelType].grib[editionNumber]";
    
    Running the same command again we obtain a different list of files.
    Code Block
    > grib_filter rules_file ../data/tigge_pf_ecmwf.grib2
    > ls ../data/split
    98_20060619_4_sfc.grib2
    98_20060630_4_sfc.grib2
    98_20070122_4_pl.grib2
    98_20070122_4_pt.grib2
    98_20070122_4_pv.grib2
    98_20070122_4_sfc.grib2
    


  3. Other statements are allowed in the grib_filter syntax:

    • if ( condition ) { block of rules } else { block of rules } The condition can be made using ==,!= and joining single block conditions with || and && The statement can be any valid statement also another nested condition
    • set keyname = keyvalue;
    • print "string to print also with key values like in the file name"
    • transient keyname1 = keyname2;
    • comments beginning with #
    A complex example of grib_filter rules is the following to change temperature in a grib edition 1 file.
    Code Block
    # Temperature
    if ( level == 850 && indicatorOfParameter == 11 ) {
        print "found indicatorOfParameter=[indicatorOfParameter] level=[level] date=[date]";
        transient oldtype = type ;
        set identificationOfOriginatingGeneratingSubCentre=98;
        set gribTablesVersionNo = 128;
        set indicatorOfParameter = 130;
        set localDefinitionNumber=1;
        set marsClass="od";
        set marsStream="kwbc";
        # Negatively/Positively Perturbed Forecast
        if ( oldtype == 2 || oldtype == 3 ) {
          set marsType="pf";
          set experimentVersionNumber="4001";
        }
        # Control Forecast
        if ( oldtype == 1 ) {
          set marsType="cf";
          set experimentVersionNumber="0001";
        }
        set numberOfForecastsInEnsemble=11;
        write;
        print "indicatorOfParameter=[indicatorOfParameter] level=[level] date=[date]";
        print;
    }
    


  4. The switch statement is an enhanced version of the if statement. Its syntax is the following:

    Code Block
    switch (key1) {
        case val1:
            # block of rules;
        case val2:
            # block of rules;
        default:
            # block of rules
    }
    
    Each value of each key given as argument to the switch statement is matched against the values specified in the case statements. If there is a match, then the block or rules corresponding to the matching case statement is executed. Otherwise, the default case is executed. The default case is mandatory , even if emptyif the case statements do not cover all the possibilities. The "~" operator can be used to match "anything". Following is an example showing the use of the switch statement:
    Code Block
    processing paramId=[paramId] [shortName] [stepType]
    switch (shortName) {
        case tp :
            set stepType=accum;
        case 10u :
            set typeOfLevel=surface;
        default:
    }
    


...