convert.rb

Path: convert.rb
Last Update: Tue Aug 30 12:54:51 BST 2005
TopLevel

Author: Matt Foster (mattfoster@clara.co.uk) Copyright: Matt Foster (mattfoster@clara.co.uk) Convert coordinate types on the command line. For help, try convert.rb -h E.g.:

  ruby convert.rb -i 'TG 51410 13177' -o dms
  E 1D 43M 4.52210295347086S
  N 52D 39M 27.2442040793669S

Required files

coord.rb   optparse   ostruct  

Methods

Public Instance methods

[Source]

# File convert.rb, line 36
def get_ll_prefix(phi, lam)
  if lam < 0
    lam_prefix = 'W'
  else
    lam_prefix = 'E'
  end
  if phi < 0
    phi_prefix = 'W'
  else
    phi_prefix = 'N'
  end
  [phi_prefix, lam_prefix]
end

[Source]

# File convert.rb, line 76
def put_dd(phi, lam)
  # Now prettify the output.
  lam_o = Coordinate.new(lam.rad_to_deg).to_dd
  phi_o = Coordinate.new(phi.rad_to_deg).to_dd

  phi_prefix, lam_prefix = get_ll_prefix(phi, lam)

  puts "#{phi_prefix} #{phi_o.abs}D"
  puts "#{lam_prefix} #{lam_o.abs}D"
end

[Source]

# File convert.rb, line 65
def put_dm(phi, lam)
  # Now prettify the output.
  lam_o = Coordinate.new(lam.rad_to_deg).to_dm
  phi_o = Coordinate.new(phi.rad_to_deg).to_dm

  phi_prefix, lam_prefix = get_ll_prefix(phi, lam)

  puts "#{phi_prefix} #{phi_o[0].abs}D #{phi_o[1]}M"
  puts "#{lam_prefix} #{lam_o[0].abs}D #{lam_o[1]}M"
end

[Source]

# File convert.rb, line 50
def put_dms(phi, lam)
  # Now prettify the output.
  if phi.class != Coordinate and lam.class != Coordinate
    phi_o = Coordinate.new(phi.rad_to_deg).to_dms
    lam_o = Coordinate.new(lam.rad_to_deg).to_dms
  else
    phi_o = phi.to_dms
    lam_o = lam.to_dms
  end
  phi_prefix, lam_prefix = get_ll_prefix(phi_o[0], lam_o[0])

  puts "#{lam_prefix} #{lam_o[0].abs}D #{lam_o[1]}M #{lam_o[2]}S"
  puts "#{phi_prefix} #{phi_o[0].abs}D #{phi_o[1]}M #{phi_o[2]}S"
end

[Source]

# File convert.rb, line 91
def put_en(e, n)
  puts "E #{e}, N #{n}"
end

[Source]

# File convert.rb, line 87
def put_ng(p, ee, nn)
  puts "#{p} #{ee} #{nn}"
end

[Source]

# File convert.rb, line 18
def split_coord(c)
  if c.length % 2 != 0
    puts 'Error expected an even length coord set.'
    puts p
    exit(1)
  elsif c.class != String
    puts 'Expected string input.'
    puts p
    exit(1)
  end
   
  # Split the input coordinate in two.
  e = c[0..c.length/2-1]
  n = c[c.length/2..-1]

  [e.to_i, n.to_i]
end

[Validate]