Added Python function codes_new_from_samples which takes the product kind

This commit is contained in:
Shahram Najm 2016-12-22 14:08:28 +00:00
parent 1f1fbc43ca
commit afa06548ef
3 changed files with 26 additions and 2 deletions

View File

@ -20,7 +20,7 @@ from eccodes import *
VERBOSE = 1 # verbose error reporting VERBOSE = 1 # verbose error reporting
def example(input_filename, output_filename): def example(input_filename, output_filename):
ibufr = codes_bufr_new_from_samples('BUFR3') ibufr = codes_new_from_samples('BUFR3', CODES_PRODUCT_BUFR)
f = open(input_filename) f = open(input_filename)
ibufrin = codes_bufr_new_from_file(f) ibufrin = codes_bufr_new_from_file(f)
ivalues=( ivalues=(

View File

@ -48,6 +48,7 @@ from gribapi import grib_set_long as codes_set_long
from gribapi import grib_set_double as codes_set_double from gribapi import grib_set_double as codes_set_double
from gribapi import grib_new_from_samples as codes_grib_new_from_samples from gribapi import grib_new_from_samples as codes_grib_new_from_samples
from gribapi import codes_bufr_new_from_samples from gribapi import codes_bufr_new_from_samples
from gribapi import codes_new_from_samples
from gribapi import codes_bufr_copy_data from gribapi import codes_bufr_copy_data
from gribapi import grib_clone as codes_clone from gribapi import grib_clone as codes_clone
from gribapi import grib_set_double_array as codes_set_double_array from gribapi import grib_set_double_array as codes_set_double_array

View File

@ -763,6 +763,29 @@ def grib_set_double(msgid, key, value):
GRIB_CHECK(_internal.grib_c_set_double(msgid, key, value)) GRIB_CHECK(_internal.grib_c_set_double(msgid, key, value))
@require(samplename=str, product_kind=int)
def codes_new_from_samples(samplename, product_kind):
"""
@brief Create a new valid message from a sample for a given product.
The available samples are picked up from the directory pointed to
by the environment variable ECCODES_SAMPLES_PATH.
To know where the samples directory is run the codes_info tool.\n
\b Examples: \ref grib_samples.py "grib_samples.py"
@param samplename name of the sample to be used
@param product_kind CODES_PRODUCT_GRIB or CODES_PRODUCT_BUFR
@return id of the message loaded in memory
@exception GribInternalError
"""
if product_kind == CODES_PRODUCT_GRIB:
return grib_new_from_samples(samplename)
if product_kind == CODES_PRODUCT_BUFR:
return codes_bufr_new_from_samples(samplename)
raise Exception("Invalid product kind: " + product_kind)
@require(samplename=str) @require(samplename=str)
def grib_new_from_samples(samplename): def grib_new_from_samples(samplename):
""" """
@ -792,7 +815,7 @@ def codes_bufr_new_from_samples(samplename):
by the environment variable ECCODES_SAMPLES_PATH. by the environment variable ECCODES_SAMPLES_PATH.
To know where the samples directory is run the codes_info tool.\n To know where the samples directory is run the codes_info tool.\n
\b Examples: \ref grib_samples.py "grib_samples.py" \b Examples: \ref bufr_copy_data.py "bufr_copy_data.py"
@param samplename name of the BUFR sample to be used @param samplename name of the BUFR sample to be used
@return id of the message loaded in memory @return id of the message loaded in memory