Class: NCFileWriter::Var
- Inherits:
-
Object
show all
- Includes:
- NC
- Defined in:
- lib/io/netcdf.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
-
#[]=(*argv) ⇒ Object
-
#get_varm(start, count, stride, imap, value) ⇒ Object
-
#initialize(ncfile, name, definition) ⇒ Var
constructor
-
#put(*argv) ⇒ Object
-
#put_var(value) ⇒ Object
-
#put_var1(index, value) ⇒ Object
-
#put_vara(start, count, value) ⇒ Object
-
#put_vars(start, count, stride, value) ⇒ Object
Methods included from NC
nc_decode, nc_put_att_simple, nc_put_var_all
Constructor Details
#initialize(ncfile, name, definition) ⇒ Var
Returns a new instance of Var.
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
|
# File 'lib/io/netcdf.rb', line 363
def initialize (ncfile, name, definition)
@ncfile = ncfile
@file_id = ncfile.file_id
@name = name
@type = definition["type"] || NC_FLOAT
@dims = definition["dim"]
@shape = @dims.map{|key| @ncfile.dim(key).to_i }
dim_ids = @dims.map{|key| @ncfile.dim(key).dim_id }
@var_id = nc_def_var(@file_id, @name, @type, dim_ids)
@attributes = definition.dup
@attributes.delete("type")
@attributes.delete("dim")
@attributes.each do |name, value|
nc_put_att(@file_id, @var_id, name, value)
end
@attributes.freeze
end
|
Instance Attribute Details
#attributes ⇒ Object
Returns the value of attribute attributes.
381
382
383
|
# File 'lib/io/netcdf.rb', line 381
def attributes
@attributes
end
|
#name ⇒ Object
Returns the value of attribute name.
381
382
383
|
# File 'lib/io/netcdf.rb', line 381
def name
@name
end
|
#type ⇒ Object
Returns the value of attribute type.
381
382
383
|
# File 'lib/io/netcdf.rb', line 381
def type
@type
end
|
Instance Method Details
#[]=(*argv) ⇒ Object
383
384
385
|
# File 'lib/io/netcdf.rb', line 383
def []= (*argv)
put(*argv)
end
|
#get_varm(start, count, stride, imap, value) ⇒ Object
447
448
449
|
# File 'lib/io/netcdf.rb', line 447
def get_varm (start, count, stride, imap, value)
return nc_put_varm(@file_id, @var_id, start, count, stride, imap, value)
end
|
#put(*argv) ⇒ Object
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
|
# File 'lib/io/netcdf.rb', line 387
def put (*argv)
value = argv.pop
info = CArray.scan_index(@shape, argv)
case info.type
when CA_REG_ADDRESS
addr = info.index[0]
index = []
(0..@shape.size-1).reverse_each do |i|
index[i] = addr % @shape[i]
addr /= @shape[i]
end
put_var1(index, value)
when CA_REG_FLATTEN
put_var(value)
when CA_REG_POINT
put_var1(info.index, value)
when CA_REG_ALL
put_var(value)
when CA_REG_BLOCK
start = []
count = []
stride = []
info.index.each do |idx|
case idx
when Array
start << idx[0]
count << idx[1]
stride << idx[2]
else
start << idx
count << 1
stride << 1
end
end
if stride.all?{|x| x == 1 }
put_vara(start, count, value)
else
put_vars(start, count, stride, value)
end
else
raise "invalid index"
end
end
|
#put_var(value) ⇒ Object
435
436
437
|
# File 'lib/io/netcdf.rb', line 435
def put_var (value)
return nc_put_var(@file_id, @var_id, value)
end
|
#put_var1(index, value) ⇒ Object
431
432
433
|
# File 'lib/io/netcdf.rb', line 431
def put_var1 (index, value)
return nc_put_var1(@file_id, @var_id, index, value)
end
|
#put_vara(start, count, value) ⇒ Object
439
440
441
|
# File 'lib/io/netcdf.rb', line 439
def put_vara (start, count, value)
return nc_put_vara(@file_id, @var_id, start, count, value)
end
|
#put_vars(start, count, stride, value) ⇒ Object
443
444
445
|
# File 'lib/io/netcdf.rb', line 443
def put_vars (start, count, stride, value)
return nc_put_vars(@file_id, @var_id, start, count, stride, value)
end
|