Class: FortranFormatParser::NodeG

Inherits:
Struct
  • Object
show all
Defined in:
ext/fortio/lib/fortio/fortran_format.rb,
ext/fortio/lib/fortio/fortran_format.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#countObject

Returns the value of attribute count

Returns:

  • (Object)

    the current value of count



572
573
574
# File 'ext/fortio/lib/fortio/fortran_format.rb', line 572

def count
  @count
end

#expObject

Returns the value of attribute exp

Returns:

  • (Object)

    the current value of exp



572
573
574
# File 'ext/fortio/lib/fortio/fortran_format.rb', line 572

def exp
  @exp
end

#lengthObject

Returns the value of attribute length

Returns:

  • (Object)

    the current value of length



572
573
574
# File 'ext/fortio/lib/fortio/fortran_format.rb', line 572

def length
  @length
end

#precObject

Returns the value of attribute prec

Returns:

  • (Object)

    the current value of prec



572
573
574
# File 'ext/fortio/lib/fortio/fortran_format.rb', line 572

def prec
  @prec
end

Instance Method Details

#count_argsObject



592
593
594
# File 'ext/fortio/lib/fortio/fortran_format.rb', line 592

def count_args
  return count
end

#inspectObject



595
596
597
598
599
# File 'ext/fortio/lib/fortio/fortran_format.rb', line 595

def inspect
  count_str = count == 1 ? "" : count.to_s
  exp_str   = (exp.nil? or exp == 2) ? "" :  "E#{exp}"
  return "#{count_str}G#{length}.#{prec}#{exp_str}"
end

#read(io, list, state) ⇒ Object



580
581
582
583
584
585
586
587
588
589
590
591
# File 'ext/fortio/lib/fortio/fortran_format.rb', line 580

def read (io, list, state)
  str = nil
  count.times do
    str = io.read(length)
    if state.zero 
      str = str.gsub(/ /,'0')
    end
    list << str.to_f
  end
rescue
  raise "reading error in fortran format : #{str.dump} for #{self.inspect}"
end

#write(io, list, state) ⇒ Object



574
575
576
577
578
579
# File 'ext/fortio/lib/fortio/fortran_format.rb', line 574

def write (io, list, state)
  count.times do
    str = FortranFormat.write_G(state.sign, state.scale, length, prec, exp, list.shift)
    io << FortranFormat.check_length(length, str)
  end
end