Class: NCFile

Inherits:
NCObject show all
Includes:
NC
Defined in:
lib/io/netcdf.rb

Instance Attribute Summary collapse

Attributes inherited from NCObject

#attributes

Class Method Summary collapse

Instance Method Summary collapse

Methods included from NC

nc_decode, nc_put_att_simple, nc_put_var_all

Methods inherited from NCObject

#attribute, #get_attributes

Constructor Details

#initialize(file_id) ⇒ NCFile

Returns a new instance of NCFile.



299
300
301
302
303
304
305
306
307
# File 'lib/io/netcdf.rb', line 299

def initialize (file_id)
  @file_id  = file_id
  @dims     = []
  @vars     = []
  @name2dim = {}
  @name2var = {}
  @attributes = get_attributes(@file_id, NC_GLOBAL)
  ()
end

Instance Attribute Details

#dimsObject (readonly)

Returns the value of attribute dims.



309
310
311
# File 'lib/io/netcdf.rb', line 309

def dims
  @dims
end

#file_idObject (readonly)

Returns the value of attribute file_id.



309
310
311
# File 'lib/io/netcdf.rb', line 309

def file_id
  @file_id
end

#varsObject (readonly)

Returns the value of attribute vars.



309
310
311
# File 'lib/io/netcdf.rb', line 309

def vars
  @vars
end

Class Method Details

.open(filename) ⇒ Object



294
295
296
297
# File 'lib/io/netcdf.rb', line 294

def self.open (filename)
  file_id = NC.open(filename)
  return NCFile.new(file_id)
end

Instance Method Details

#[](name) ⇒ Object



337
338
339
# File 'lib/io/netcdf.rb', line 337

def [] (name)
  return @name2var[name]
end

#definitionObject



330
331
332
333
334
335
# File 'lib/io/netcdf.rb', line 330

def definition
  {
    dimensions: @dims.map{|x| [x.name, x.definition] }.to_h,
    variables: @vars.map{|x| [x.name, x.definition] }.to_h
  }.update(@attributes)    
end

#dim(name) ⇒ Object



341
342
343
# File 'lib/io/netcdf.rb', line 341

def dim (name)
  return @name2dim[name]
end

#has_dim?(name) ⇒ Boolean

Returns:

  • (Boolean)


345
346
347
# File 'lib/io/netcdf.rb', line 345

def has_dim?(name)
  return @name2dim.has_key?(name)
end

#has_var?(name) ⇒ Boolean

Returns:

  • (Boolean)


349
350
351
# File 'lib/io/netcdf.rb', line 349

def has_var?(name)
  return @name2var.has_key?(name)
end

#parse_metadataObject



311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
# File 'lib/io/netcdf.rb', line 311

def  ()
  ndims = nc_inq_ndims(@file_id)
  ndims.times do |i|
    dim = NCDim.new(self, i)
    @dims[i] = dim
    @name2dim[dim.name] = dim
  end
  @dims.freeze
  @name2dim.freeze
  nvars = nc_inq_nvars(@file_id)
  nvars.times do |i|
    var = NCVar.new(self, i)
    @vars[i] = var
    @name2var[var.name] = var
  end
  @vars.freeze
  @name2var.freeze
end