Exemple #1
0
    def __setattr__(self, key, value):

        # Are we trying to set an actual instance attribute of this class?
        if key in ["grib_handle"]:
            object.__setattr__(self, key, value)
            return

        # is the key defined?
        if not c_interface.grib_is_defined(self.grib_handle, key):
            raise ValueError("Key {} not defined".format(key))
        
        # what is the native type of the key?
        key_type = c_interface.grib_get_native_type(self.grib_handle, key)

        if key_type == 1:
            c_interface.grib_set_long(self.grib_handle, key, value)
        elif key_type == 2:
            c_interface.grib_set_double(self.grib_handle, key, value)
        elif key_type == 3:
            c_interface.grib_set_string(self.grib_handle, key, value)
        else:
            raise ValueError("Unhandled key type {}".format(key_type))
Exemple #2
0
 def set_double(self, key, value):
     c_interface.grib_set_double(self.grib_handle, key, value)