Benutzer:Bk1 168/Koordinaten
Zur Navigation springen
Zur Suche springen
#!/usr/bin/ruby
s = ARGV[0]
unless s.match /([0-9.]+)°*\s*,\s*([0-9.]+)°*/
$stderr.puts "\"#{s}\" does not have correct format."
exit 1
end
class Float
def to_dms
sgn_pos = true
val = self
if self < 0
val = -self
sgn_pos = false
end
deg = val.to_i
minsec = 60 * (val - deg)
min = minsec.to_i
sec = (60 * (minsec - min)).round_to_2dig
return sgn_pos, deg, min, sec
end
def round_to_2dig
val10 = self * 10 + 0.5
int10 = val10.to_i
val = int10 / 10.0
val
end
end
latitude = $1.to_f
longitude = $2.to_f
xf, xd, xm, xs = latitude.to_dms
yf, yd, ym, ys = longitude.to_dms
region = ARGV[1] || 'SE-I'
n_or_s = xf ? 'N' : 'S'
e_or_w = yf ? 'E' : 'W'
print "{{Coordinate|article=/|NS=#{xd}/#{xm}/#{xs}/#{n_or_s} |EW=#{yd}/#{ym}/#{ys}/#{e_or_w} |type=landmark |region=#{region}}}\n"
print "{{Coord|#{xd}|#{xm}|#{xs}|#{n_or_s}|#{yd}|#{ym}|#{ys}|#{e_or_w}|region:SE_type:landmark|display=title}}\n"
if (xf && yf)
printf "%d:%02d:%4.1f %d:%02d:%4.1f\n", xd, xm, xs, yd, ym, ys
end