Class: NCObject
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
Instance Method Summary collapse
- #attribute(name) ⇒ Object
- #get_attributes(file_id, var_id) ⇒ Object
- #get_attributes!(file_id, var_id) ⇒ Object
Methods included from NC
nc_decode, nc_put_att_simple, nc_put_var_all
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
81 82 83 |
# File 'lib/io/netcdf.rb', line 81 def attributes @attributes end |
Instance Method Details
#attribute(name) ⇒ Object
77 78 79 |
# File 'lib/io/netcdf.rb', line 77 def attribute (name) return @attributes[name] end |
#get_attributes(file_id, var_id) ⇒ Object
47 48 49 50 51 52 53 54 55 56 |
# File 'lib/io/netcdf.rb', line 47 def get_attributes (file_id, var_id) attrs = {} varnatts = nc_inq_varnatts(file_id, var_id) varnatts.times do |i| attname = nc_inq_attname(file_id, var_id, i) value = nc_get_att(file_id, var_id, attname) attrs[attname] = value end return attrs.freeze end |
#get_attributes!(file_id, var_id) ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/io/netcdf.rb', line 58 def get_attributes! (file_id, var_id) attrs = {} varnatts = nc_inq_varnatts(file_id, var_id) varnatts.times do |i| attname = nc_inq_attname(file_id, var_id, i) type = nc_inq_atttype(file_id, var_id, attname) case type when NC_CHAR value = nc_get_att(file_id, var_id, attname) else len = nc_inq_attlen(file_id, var_id, attname) value = CArray.new(NC.ca_type(type), [len]) nc_get_att(file_id, var_id, attname, value) end attrs[attname] = value end return attrs.freeze end |