/* This file is automatically generated by ./errors.pl, do not edit */

/*
 * (C) Copyright 2005- ECMWF.
 *
 * This software is licensed under the terms of the Apache Licence Version 2.0
 * which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
 *
 * In applying this licence, ECMWF does not waive the privileges and immunities granted to it by
 * virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
 */
#include "grib_api_internal.h"

static const char *errors[] = {
!ERRORS go in here
};

const char* grib_get_error_message(int code)
{
    code = -code;
    const int num_errors = int( sizeof(errors)/sizeof(errors[0]) );
    if (code < 0 || code >= num_errors) {
        static char mess[64];
        snprintf(mess, sizeof(mess), "Unknown error %d", code);
        return mess;
    }
    return errors[code];
}

void grib_check(const char* call, const char* file, int line, int e, const char* msg)
{
    grib_context* c=grib_context_get_default();
    if (e) {
        if (file) {
            fprintf(stderr,"%s at line %d: %s failed: %s",
                file,line, call,grib_get_error_message(e));
            if (msg) fprintf(stderr," (%s)",msg);
            printf("\n");
        } else {
            grib_context_log(c,GRIB_LOG_ERROR,"%s",grib_get_error_message(e));
        }
        exit(e);
    }
}
