Class: FortranFormatParser::NodeI

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



436
437
438
# File 'ext/fortio/lib/fortio/fortran_format.rb', line 436

def count
  @count
end

#lengthObject

Returns the value of attribute length

Returns:

  • (Object)

    the current value of length



436
437
438
# File 'ext/fortio/lib/fortio/fortran_format.rb', line 436

def length
  @length
end

#precObject

Returns the value of attribute prec

Returns:

  • (Object)

    the current value of prec



436
437
438
# File 'ext/fortio/lib/fortio/fortran_format.rb', line 436

def prec
  @prec
end

Instance Method Details

#count_argsObject



470
471
472
# File 'ext/fortio/lib/fortio/fortran_format.rb', line 470

def count_args
  return count
end

#inspectObject



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