class EphJpl::Binary

Public Class Methods

new(*args) click to toggle source
# File lib/eph_jpl/binary.rb, line 3
def initialize(*args)
  @bin_path, @target, @center, @jd = *args
  @pos = 0
end

Public Instance Methods

get_binary() click to toggle source
# File lib/eph_jpl/binary.rb, line 8
def get_binary
  begin
    ttl    = get_ttl            # TTL
    cnams  = get_cnams          # CNAM
    sss    = get_sss            # SS
    ncon   = get_ncon           # NCON
    au     = get_au             # AU
    emrat  = get_emrat          # EMRAT
    ipts   = get_ipts           # IPT
    numde  = get_numde          # NUMDE
    ipts  << get_ipts_13        # IPT(Month's libration)
    cnams += get_cnams_2(ncon)  # CNAM(>400)
    cvals  = get_cvals(ncon)    # CVAL(定数値)
    jdepoc = cvals[4]           # JDEPOC
    coeffs, jds_cheb = get_coeffs(sss, ipts)  # Coefficient, JDs(for Chebyshev polynomial)
    return {
      ttl: ttl, cnams: cnams, sss: sss, ncon: ncon, au: au, emrat: emrat,
      numde: numde, ipts: ipts, cvals: cvals, jdepoc: jdepoc,
      coeffs: coeffs, jds_cheb: jds_cheb
    }
  rescue => e
    raise
  end
end

Private Instance Methods

get_au() click to toggle source
AU

@param:  <none>
@return: AU
# File lib/eph_jpl/binary.rb, line 119
def get_au
  recl = 8

  begin
    au = File.binread(@bin_path, recl, @pos).unpack("d*")[0]
    @pos += recl
    return au
  rescue => e
    raise
  end
end
get_cnams() click to toggle source
CNAM

@param:  <none>
@return: Array of CNAM
# File lib/eph_jpl/binary.rb, line 61
def get_cnams
  recl = 6

  begin
    cnams = (0..399).map do |i|
      File.binread(@bin_path, recl, @pos + recl * i).unpack("A*")[0]
    end
    @pos += recl * 400
    return cnams
  rescue => e
    raise
  end
end
get_cnams_2(ncon) click to toggle source
CNAM

@param:  NCON
@return: Array of CNAM
# File lib/eph_jpl/binary.rb, line 219
def get_cnams_2(ncon)
  recl = 6

  begin
    cnams = (0..(ncon - 400 - 1)).map do |i|
      File.binread(@bin_path, recl, @pos + recl * i).unpack("A*")[0]
    end
    @pos += recl * (ncon - 400)
    return cnams
  rescue => e
    raise
  end
end
get_coeffs(sss, ipts) click to toggle source
COEFF

* Set JD(start, end) for Chebyshev polynomial to the array @jd_cheb

@param: Array of SS
@param: Array of IPT
@return: <none>
# File lib/eph_jpl/binary.rb, line 261
def get_coeffs(sss, ipts)
  idx = ((@jd - sss[0]) / sss[2]).floor  # レコードインデックス
  pos = Const::KSIZE * Const::RECL * (2 + idx)
  recl = 8
  coeffs = Array.new

  begin
    items = (0..(Const::KSIZE / 2) - 1).map do |i|
      File.binread(@bin_path, recl, pos + recl * i).unpack("d*")[0]
    end
    jd_cheb = [items.shift, items.shift]
    ipts.each_with_index do |ipt, i|
      n = i == 11 ? 2 : 3  # 要素数
      ary_1 = Array.new
      ipt[2].times do |j|
        ary_0 = Array.new
        n.times do |k|
          ary_0 << items.shift(ipt[1])
        end
        ary_1 << ary_0
      end
      coeffs << ary_1
    end
    return [coeffs, jd_cheb]
  rescue => e
    raise
  end
end
get_cvals(ncon) click to toggle source
CVAL

@param:  NCON
@return: Array of CVAL
# File lib/eph_jpl/binary.rb, line 239
def get_cvals(ncon)
  pos = Const::KSIZE * Const::RECL
  recl = 8

  begin
    return (0..ncon - 1).map do |i|
      File.binread(@bin_path, recl, pos + recl * i).unpack("d*")[0]
    end
  rescue => e
    raise
  end
end
get_emrat() click to toggle source
EMRAT

@param:  <none>
@return: <none>
# File lib/eph_jpl/binary.rb, line 137
def get_emrat
  recl = 8

  begin
    emrat = File.binread(@bin_path, recl, @pos).unpack("d*")[0]
    @pos += recl
    return emrat
  rescue => e
    raise
  end
end
get_ipts() click to toggle source
IPT

@param:  <none>
@return: Array of IPT
# File lib/eph_jpl/binary.rb, line 155
def get_ipts
  recl = 4

  begin
    ipts = (0..11).map do |i|
      ary = (0..2).map do |j|
        File.binread(@bin_path, recl, @pos + recl * j).unpack("I*")[0]
      end
      @pos += recl * 3
      ary
    end
    return ipts
  rescue => e
    raise
  end
end
get_ipts_13() click to toggle source
IPT_13(Month's libration)

@param:  <none>
@return: Array of IPT
# File lib/eph_jpl/binary.rb, line 199
def get_ipts_13
  recl = 4

  begin
    ipts = (0..2).map do |i|
      File.binread(@bin_path, recl, @pos + recl * i).unpack("I*")[0]
    end
    @pos += recl * 3
    return ipts
  rescue => e
    raise
  end
end
get_ncon() click to toggle source
NCON

@param:  <none>
@return: NCON
# File lib/eph_jpl/binary.rb, line 101
def get_ncon
  recl = 4

  begin
    ncon = File.binread(@bin_path, recl, @pos).unpack("I*")[0]
    @pos += recl
    return ncon
  rescue => e
    raise
  end
end
get_numde() click to toggle source
NUMDE

* If NUMDE != 430, raise error!

@param:  <none>
@return: NUMDE
# File lib/eph_jpl/binary.rb, line 180
def get_numde
  recl = 4

  begin
    numde = File.binread(@bin_path, recl, @pos).unpack("I*")[0]
    raise Const::MSG_ERR_8 unless numde == 430
    @pos += recl
    return numde
  rescue => e
    raise
  end
end
get_sss() click to toggle source
SS

@param:  <none>
@return: Array of SS
# File lib/eph_jpl/binary.rb, line 81
def get_sss
  recl = 8

  begin
    sss = (0..2).map do |i|
      File.binread(@bin_path, recl, @pos + recl * i).unpack("d*")[0]
    end
    @pos += recl * 3
    return sss
  rescue => e
    raise
  end
end
get_ttl() click to toggle source
TTL

@param:  <none>
@return: TTL
# File lib/eph_jpl/binary.rb, line 41
def get_ttl
  recl = 84

  begin
    ttl = (0..2).map do |i|
      File.binread(@bin_path, recl, @pos + recl * i).unpack("A*")[0]
    end.join("\n")
    @pos += recl * 3
    return ttl
  rescue => e
    raise
  end
end