Class: NumRu::VArrayHE5ZaField

Inherits:
VArray
  • Object
show all
Defined in:
lib/numru/gphys/varrayhdfeos5.rb

Overview

class VArrayHE5Gd

Constant Summary

Constants inherited from VArray

NumRu::VArray::Binary_operators, NumRu::VArray::Binary_operatorsL, NumRu::VArray::Binary_operatorsL_comp, NumRu::VArray::Binary_operatorsL_other, NumRu::VArray::Binary_operators_Uconv, NumRu::VArray::Binary_operators_Unone, NumRu::VArray::Binary_operators_Uop, NumRu::VArray::Math_funcs, NumRu::VArray::Math_funcs_nondim, NumRu::VArray::Math_funcs_radian, NumRu::VArray::NArray_type1_methods, NumRu::VArray::NArray_type2_methods, NumRu::VArray::NArray_type2_methods1, NumRu::VArray::NArray_type2_methods2, NumRu::VArray::NArray_type2_methods3, NumRu::VArray::NArray_type3_methods, NumRu::VArray::Unary_operators

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from VArray

#+@, #[], #[]=, #att_names, #attr_copy, #axis_cyclic?, #axis_cyclic_extendible?, #axis_draw_positive, #axis_modulo, #bin_mean, #bin_sum, #coerce, #convert_units, #copy, #del_att, #get_att, #long_name, #long_name=, #mapped?, #marshal_dump, #marshal_load, #name, #name=, #rename, #rename!, #replace_val, #reshape, #reshape!, #set_att, #sqrt, #to_g1D, #transpose, #units, #units=

Constructor Details

#initialize(aHE5ZaField) ⇒ VArrayHE5ZaField

< initialization redefined > ##



293
294
295
296
297
298
299
300
301
302
303
304
305
306
# File 'lib/numru/gphys/varrayhdfeos5.rb', line 293

def initialize(aHE5ZaField)
  @name = aHE5ZaField.name
  @mapping = nil
  @varray = nil
  if ! aHE5ZaField.is_a?(HE5ZaField)
    raise ArgumentError,"Not a HE5ZaField" 
  end
  @ary = aHE5ZaField
  @attr = Attribute.new
  aHE5ZaField.att_names.each{|name|
    @attr[name.downcase] = aHE5ZaField.get_att(name).to_s 
    @attr["long_name"] = aHE5ZaField.get_att(name).to_s if  name == "Title"  # For SMILES /MLS 
  }
end

Class Method Details

.new2(za, name, ntype, dimensions, vary = nil) ⇒ Object Also known as: def_var



314
315
316
317
318
319
320
321
# File 'lib/numru/gphys/varrayhdfeos5.rb', line 314

def new2(za, name, ntype, dimensions, vary=nil)
  dimensions = dimensions.join(',') 
  va = new( za.def_var(name, ntype, dimensions) )
  if vary
    vary.att_names.each{|name| va.set_att(name, vary.get_att(name))}
  end
  va
end

.write(file, vary, rename = nil, dimnames = nil) ⇒ Object

< additional class methods > ##

Raises:

  • (ArgumentError)


326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
# File 'lib/numru/gphys/varrayhdfeos5.rb', line 326

def write(file, vary, rename=nil, dimnames=nil)
  raise ArgumentError, "1st arg: not a HE5Za" if !file.is_a?(HE5Za)
  raise ArgumentError, "2nd arg: not a VArray" if !vary.is_a?(VArray)
  rank=vary.rank
  if dimnames == nil
    if vary.is_a?(VArrayHE5ZaField)
      dimnames = vary.dim_names
    else
      dimnames=Array.new
      for i in 0...rank
        dimnames[i]='x'+i.to_s
      end
    end
  elsif( rank != dimnames.length)
    raise ArgumentError, 
    "# of dim names does not agree with the rank of the VArray"
  end
  fdimnms = file.dim_names
  begin
    shape = vary.shape
  rescue StandardError, NameError
    shape = vary.shape_ul0
  end
  dims = Array.new
  for i in 0...rank
    nm = dimnames[i]
    if fdimnms.include?(nm)
      dims[i] = nm
    else
      dims[i] = file.defdim(nm.name,shape[i])
    end
  end
  nm = ( rename || vary.name )
  val = vary.val
  newvary = new2(file, nm, vary.typecode, dims, vary)
  newvary.val = val
  return newvary
end

Instance Method Details

#dim_namesObject



415
416
417
# File 'lib/numru/gphys/varrayhdfeos5.rb', line 415

def dim_names
  @ary.dim_names
end

#fileObject



419
420
421
# File 'lib/numru/gphys/varrayhdfeos5.rb', line 419

def file
  @ary.grid
end

#inspectObject



308
309
310
# File 'lib/numru/gphys/varrayhdfeos5.rb', line 308

def inspect
  "<'#{@name}' in '#{@ary.za.file.path}' #{@ary.ntype}#{shape_current.inspect}>"
end

#ntypeObject



390
391
392
# File 'lib/numru/gphys/varrayhdfeos5.rb', line 390

def ntype
  @ary.ntype
end

#rankObject



409
410
411
# File 'lib/numru/gphys/varrayhdfeos5.rb', line 409

def rank
  @ary.rank
end

#shapeObject



385
386
387
# File 'lib/numru/gphys/varrayhdfeos5.rb', line 385

def shape
  raise "The shape method is not available. Use shape_ul0 or shape_current instead."
end

#shape_currentObject



398
399
400
# File 'lib/numru/gphys/varrayhdfeos5.rb', line 398

def shape_current
  @ary.shape_current
end

#shape_ul0Object



394
395
396
# File 'lib/numru/gphys/varrayhdfeos5.rb', line 394

def shape_ul0
  @ary.shape_ul0
end

#totalObject Also known as: length



402
403
404
405
406
# File 'lib/numru/gphys/varrayhdfeos5.rb', line 402

def total
  len = 1
  @ary.shape_current.each{|i| len *= i}
  len
end

#valObject

< redefined instance methods > ##



368
369
370
# File 'lib/numru/gphys/varrayhdfeos5.rb', line 368

def val
  return @ary.get
end

#val=(narray) ⇒ Object



372
373
374
375
376
377
378
379
380
381
382
383
# File 'lib/numru/gphys/varrayhdfeos5.rb', line 372

def val=(narray)
  if narray.is_a?(Numeric)
    @ary.put( narray )
  else
    narray = __check_ary_class(narray)
    slicer = (0...rank).collect{|i|
      (shape_ul0[i] != 0) ? true : 0...narray.shape[i]
    }
    @ary[*slicer] = narray
    narray
  end
end