Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

making calendars test more readable

  • Loading branch information...
commit d193277d9be8aad4fc9ee1d58af69f45bc031589 1 parent f1bc5af
@DouglasAllen authored
Showing with 45 additions and 21 deletions.
  1. +45 −21 test_libcalendars.rb
View
66 test_libcalendars.rb
@@ -2,6 +2,7 @@
require 'ffi'
y,m,d = Date.today.year, Date.today.month, Date.today.day
+
module Calendars
extend FFI::Library
ffi_lib "libcalendars.so"
@@ -20,44 +21,67 @@ module Calendars
attach_function :iauJd2cal, [ :double, :double, :pointer, :pointer, :pointer, :pointer ], :int
attach_function :iauJdcalf, [ :int, :double, :double, :pointer], :int
end
-
-puts 1
+puts
+puts "Gregorian Calendar to Julian Date"
+puts "input = #{y}, #{m}, #{d}"
mp1 = FFI::MemoryPointer.new(:double, 8)
mp2 = FFI::MemoryPointer.new(:double, 8)
-p cal2jd = Calendars.iauCal2jd(y, m, d, mp1, mp2 )
-puts mp1.get_double, mp2.get_double
+cal2jd = Calendars.iauCal2jd(y, m, d, mp1, mp2 )
+puts "status = #{cal2jd}"
+puts "jd 1 = #{mp1.get_double}", "jd 2 = #{mp2.get_double}"
+puts "jd 1 + jd 2 = #{mp1.get_double + mp2.get_double}"
-puts 2
-p epb = Calendars.iauEpb(mp1.get_double, mp2.get_double)
+puts
+puts "Julian Date to Besselian Epoch"
+puts "input = #{mp1.get_double}, #{mp2.get_double}"
+epb = Calendars.iauEpb(mp1.get_double, mp2.get_double)
+puts "Besselian Epoch = #{epb}"
-puts 3
+puts
+puts "Besselian Epoch to Julian Date"
+puts "input = #{epb}"
mp3 = FFI::MemoryPointer.new(:double, 8)
mp4 = FFI::MemoryPointer.new(:double, 8)
-p Calendars.iauEpb2jd( epb, mp3, mp4 )
-puts mp3.get_double, mp4.get_double
+epb2jd = Calendars.iauEpb2jd( epb, mp3, mp4 )
+puts "jd 1 = #{mp3.get_double}", "jd 2 = #{mp4.get_double}"
+puts "jd 1 + jd 2 = #{mp3.get_double + mp4.get_double}"
-puts 4
-p epj = Calendars.iauEpj(mp3.get_double, mp4.get_double)
+puts
+puts "Julian Date to Julian Epoch"
+puts "input = #{2451545.0}, #{Date.today.jd - 2451545.0}"
+epj = Calendars.iauEpj(2451545.0, Date.today.jd - 2451545.0)
+puts "Julian Epoch = #{epj}"
-puts 5
+puts
+puts "Julian Epoch to Julian Date"
+puts "input = #{epj}"
mp5 = FFI::MemoryPointer.new(:double, 8)
mp6 = FFI::MemoryPointer.new(:double, 8)
-p Calendars.iauEpj2jd( epj, mp5, mp6 )
-puts mp5.get_double, mp6.get_double
+Calendars.iauEpj2jd( epj, mp5, mp6 )
+puts "jd 1 = #{mp5.get_double}", "jd 2 = #{mp6.get_double}"
+puts "jd 1 + jd 2 = #{mp5.get_double + mp6.get_double}"
-puts 6
+puts
+puts "Julian Date to Gregorian year, month, day, and fraction of a day."
+puts "input = #{mp5.get_double}, #{mp6.get_double}"
mp7 = FFI::MemoryPointer.new(:int, 4)
mp8 = FFI::MemoryPointer.new(:int, 4)
mp9 = FFI::MemoryPointer.new(:int, 4)
mp10 = FFI::MemoryPointer.new(:double, 8)
-p jd2cal = Calendars.iauJd2cal( mp5.get_double, mp6.get_double, mp7, mp8, mp9, mp10 )
-puts mp7.get_int, mp8.get_int, mp9.get_int, mp10.get_double
+jd2cal = Calendars.iauJd2cal( mp5.get_double, mp6.get_double, mp7, mp8, mp9, mp10 )
+puts "status = #{jd2cal}"
+puts "year, month, day, fractional day #{mp7.get_int}, #{mp8.get_int}, #{mp9.get_int}, #{mp10.get_double}"
-puts 7
+puts
+puts "Julian Date to Gregorian Calendar formatted"
+ajd = DateTime.now.ajd.to_f
+puts "input = 6, #{ajd}"
mp11 = FFI::MemoryPointer.new(:int, 4)
-p jdcalf = Calendars.iauJdcalf( 6, mp5.get_double, mp6.get_double, mp11)
-p ary = mp11.read_array_of_type(:int, :get_int, 4)
-
+jdcalf = Calendars.iauJdcalf( 6, ajd, 0.0, mp11)
+puts "status = #{jdcalf}"
+ary = mp11.read_array_of_type(:int, :get_int, 4)
+puts "returned array = #{ary}"
+puts
module RCalendars
attr_accessor :jd1, :jd2
def self.get_2jd(y, m, d, jd1, jd2 )
Please sign in to comment.
Something went wrong with that request. Please try again.