Method: Ephem::Excerpt::DAFWriter#setup_formats

Defined in:
lib/ephem/excerpt.rb

#setup_formats(nd, ni) ⇒ Object



253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
# File 'lib/ephem/excerpt.rb', line 253

def setup_formats(nd, ni)
  @nd = nd
  @ni = ni

  # Double is always 8 bytes, int is always 4 bytes
  double_size = 8
  int_size = 4

  # Set formats based on endianness
  if @endianness == :little
    @double_format = "E"  # Little-endian double
    @int_format = "l"     # Little-endian signed long (32-bit)
  else
    @double_format = "G"  # Big-endian double
    @int_format = "l>"    # Big-endian signed long (32-bit)
  end

  # Create formats for summary structures
  @summary_control_format =
    "#{@double_format}#{@double_format}#{@double_format}"
  @summary_format = @double_format.to_s * @nd + @int_format.to_s * @ni

  # Calculate segment summary sizes
  @summary_length = double_size * @nd + int_size * @ni

  # Pad to 8 bytes
  @summary_step = @summary_length + (-@summary_length % 8)

  @summaries_per_record = (RECORD_SIZE - 8 * 3) / @summary_step
end