tools/grib_ls.c
/*
 A new handle is available from the current input file and can be processed here.
 The handle available in this function is in the set of messages satisfying the constraint
 of the -w option. They are not to be skipped.
*/
A new handle is available from the current input file and can be processed here.
The handle available in this function is in the set of messages satisfying the constraint
of the -w option. They are not to be skipped.
A new handle is available from the current input file and can be processed here . The handle available in this function is in the set of messages satisfying the constraint of the - w option . They are not to be skipped .
int grib_tool_new_handle_action(grib_runtime_options* options, grib_handle* h)
{
    size_t size = 4;
    double v    = 0;
    int err     = 0;
    int i;
    if (!options->skip) {
        if (options->set_values_count != 0)
            err = grib_set_values(h, options->set_values, options->set_values_count);
        if (err != GRIB_SUCCESS && options->fail)
            exit(err);
    }
    if (options->latlon) {
        double min;
        err = 0;
        if (!nearest)
            nearest = grib_nearest_new(h, &err);
        if (err == GRIB_NOT_IMPLEMENTED) {
            char grid_type[100];
            size_t grid_type_len = 100;
            int err1             = grib_get_string(h, "gridType", grid_type, &grid_type_len);
            if (err1 == GRIB_SUCCESS) {
                fprintf(stderr, "Nearest neighbour functionality is not supported for grid type: %s\n", grid_type);
            }
        }
        GRIB_CHECK_NOLINE(err, 0);
        {
            int nn_flag = 0;
            if (options->latlon_mask) {
                nn_flag = mode; 
            }
            GRIB_CHECK_NOLINE(grib_nearest_find(nearest, h, lat, lon, nn_flag,
                                                options->lats, options->lons, options->values,
                                                options->distances, options->indexes, &size),
                              0);
        }
        if (!options->latlon_mask) {
            min                 = options->distances[0];
            options->latlon_idx = 0;
            for (i = 1; i < LATLON_SIZE; i++) {
                if (min > options->distances[i]) {
                    min                 = options->distances[i];
                    options->latlon_idx = i;
                }
            }
        }
        if (json_latlon) {
            char* s             = "\n[\n";
            double missingValue = 9999;
            char value[MAX_STRING_LEN];
            size_t len = MAX_STRING_LEN;
            printf("%s", new_handle);
            printf("{\n");
            print_key_values(options, h);
            printf("\n, \"selected\" : %d", options->latlon_idx);
            printf(", \"method\" : ");
            if (options->latlon_mask)
                printf("\"nearest_land\"");
            else
                printf("\"nearest\"");
            printf("\n, \"neighbours\" : ");
            for (i = 0; i < LATLON_SIZE; i++) {
                printf("%s", s);
                len = MAX_STRING_LEN;
                printf(
                    "{\"index\" : %d, \"latitude\" : %g, \"longitude\" : %g, \"distance\" : %g, "
                    "\"distance_unit\" : \"km\", ",
                    (int)options->indexes[i], options->lats[i], options->lons[i],
                    options->distances[i]);
                if (grib_get_double_element(h, "values", options->indexes[i], &v) == GRIB_SUCCESS) {
                    if (v == missingValue)
                        printf("\"value\" : null ");
                    else
                        printf("\"value\" : %g ", v);
                }
                if (grib_get_string(h, "units", value, &len) == GRIB_SUCCESS)
                    printf(", \"unit\" : \"%s\"", value);
                if (options->latlon_mask)
                    printf(", \"mask_value\" : %.2f", options->mask_values[i]);
                printf("}");
                s = "\n,";
            }
            printf("\n]");
            printf("\n}");
        }
    }
    if (!json_latlon && options->json_output) {
        if (options->current_infile && options->current_infile->name) {
            size_t len = strlen(options->current_infile->name);
            grib_set_string(h, "file", options->current_infile->name, &len);
        }
        if (!first_handle && options->handle_count > 1) {
            fprintf(stdout, ",\n");
        }
        if (options->json_output && first_handle) {
            fprintf(stdout, "{ \"messages\" : [ \n");
            first_handle = 0;
        }
    }
    new_handle = "\n,";
    return 0;
}
int grib_tool_new_handle_action ( grib_runtime_options * options , grib_handle * h ) { size_t size = 4 ; double v = 0 ; int err = 0 ; int i ; if ( ! options -> skip ) { if ( options -> set_values_count != 0 ) err = grib_set_values ( h , options -> set_values , options -> set_values_count ) ; if ( err != GRIB_SUCCESS && options -> fail ) exit ( err ) ; } if ( options -> latlon ) { double min ; err = 0 ; if ( ! nearest ) nearest = grib_nearest_new ( h , & err ) ; if ( err == GRIB_NOT_IMPLEMENTED ) { char grid_type [ 100 ] ; size_t grid_type_len = 100 ; int err1 = grib_get_string ( h , " " , grid_type , & grid_type_len ) ; if ( err1 == GRIB_SUCCESS ) { fprintf ( stderr , " \n " , grid_type ) ; } } GRIB_CHECK_NOLINE ( err , 0 ) ; { int nn_flag = 0 ; if ( options -> latlon_mask ) { nn_flag = mode ; } GRIB_CHECK_NOLINE ( grib_nearest_find ( nearest , h , lat , lon , nn_flag , options -> lats , options -> lons , options -> values , options -> distances , options -> indexes , & size ) , 0 ) ; } if ( ! options -> latlon_mask ) { min = options -> distances [ 0 ] ; options -> latlon_idx = 0 ; for ( i = 1 ; i < LATLON_SIZE ; i ++ ) { if ( min > options -> distances [ i ] ) { min = options -> distances [ i ] ; options -> latlon_idx = i ; } } } if ( json_latlon ) { char * s = " \n \n " ; double missingValue = 9999 ; char value [ MAX_STRING_LEN ] ; size_t len = MAX_STRING_LEN ; printf ( " " , new_handle ) ; printf ( " \n " ) ; print_key_values ( options , h ) ; printf ( " \n \" \" " , options -> latlon_idx ) ; printf ( " \" \" " ) ; if ( options -> latlon_mask ) printf ( " \" \" " ) ; else printf ( " \" \" " ) ; printf ( " \n \" \" " ) ; for ( i = 0 ; i < LATLON_SIZE ; i ++ ) { printf ( " " , s ) ; len = MAX_STRING_LEN ; printf ( " \" \" \" \" \" \" \" \" " " \" \" \" \" " , ( int ) options -> indexes [ i ] , options -> lats [ i ] , options -> lons [ i ] , options -> distances [ i ] ) ; if ( grib_get_double_element ( h , " " , options -> indexes [ i ] , & v ) == GRIB_SUCCESS ) { if ( v == missingValue ) printf ( " \" \" " ) ; else printf ( " \" \" " , v ) ; } if ( grib_get_string ( h , " " , value , & len ) == GRIB_SUCCESS ) printf ( " \" \" \" \" " , value ) ; if ( options -> latlon_mask ) printf ( " \" \" " , options -> mask_values [ i ] ) ; printf ( " " ) ; s = " \n " ; } printf ( " \n " ) ; printf ( " \n " ) ; } } if ( ! json_latlon && options -> json_output ) { if ( options -> current_infile && options -> current_infile -> name ) { size_t len = strlen ( options -> current_infile -> name ) ; grib_set_string ( h , " " , options -> current_infile -> name , & len ) ; } if ( ! first_handle && options -> handle_count > 1 ) { fprintf ( stdout , " \n " ) ; } if ( options -> json_output && first_handle ) { fprintf ( stdout , " \" \" \n " ) ; first_handle = 0 ; } } new_handle = " \n " ; return 0 ; }
A new handle is available from the current input file and can be processed here.
A new handle is available from the current input file and can be processed here .
/* ECC-638 */