Class: FortranFormatParser::NodeI
- Inherits:
-
Struct
- Object
- Struct
- FortranFormatParser::NodeI
- Defined in:
- ext/fortio/lib/fortio/fortran_format.rb,
ext/fortio/lib/fortio/fortran_format.rb
Instance Attribute Summary collapse
-
#count ⇒ Object
Returns the value of attribute count.
-
#length ⇒ Object
Returns the value of attribute length.
-
#prec ⇒ Object
Returns the value of attribute prec.
Instance Method Summary collapse
- #count_args ⇒ Object
- #inspect ⇒ Object
- #read(io, list, state) ⇒ Object
- #write(io, list, state) ⇒ Object
Instance Attribute Details
#count ⇒ Object
Returns the value of attribute count
436 437 438 |
# File 'ext/fortio/lib/fortio/fortran_format.rb', line 436 def count @count end |
#length ⇒ Object
Returns the value of attribute length
436 437 438 |
# File 'ext/fortio/lib/fortio/fortran_format.rb', line 436 def length @length end |
#prec ⇒ Object
Returns the value of attribute prec
436 437 438 |
# File 'ext/fortio/lib/fortio/fortran_format.rb', line 436 def prec @prec end |
Instance Method Details
#count_args ⇒ Object
470 471 472 |
# File 'ext/fortio/lib/fortio/fortran_format.rb', line 470 def count_args return count end |
#inspect ⇒ Object
473 474 475 476 477 478 479 480 |
# File 'ext/fortio/lib/fortio/fortran_format.rb', line 473 def inspect count_str = count == 1 ? "" : count.to_s if prec return "#{count_str}I#{length}.#{prec}" else return "#{count_str}I#{length}" end end |
#read(io, list, state) ⇒ Object
457 458 459 460 461 462 463 464 465 466 467 468 469 |
# File 'ext/fortio/lib/fortio/fortran_format.rb', line 457 def read (io, list, state) str = nil count.times do str = io.read(length) if state.zero list << str.gsub(/ /,'0').to_i else list << Integer(str) end end rescue raise "reading error in fortran format : #{str.dump} for #{self.inspect}" end |
#write(io, list, state) ⇒ Object
438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 |
# File 'ext/fortio/lib/fortio/fortran_format.rb', line 438 def write (io, list, state) if prec if state.sign fmt = "%#{length-prec}s%+0#{prec-1}i" else fmt = "%#{length-prec}s%0#{prec}i" end else if state.sign fmt = "%s%+#{length-1}i" else fmt = "%s%#{length}i" end end count.times do str = format(fmt, "", list.shift) io << FortranFormat.check_length(length, str) end end |