# Create the compacted file of Skydot frames (HJD - 2451000); only 3 bytes per frame

use strict;
use warnings;
use Compress::Zlib;
use Astro::Time::HJD; 

my $file = gzopen ("skydot_frames.sql.gz", "rb");

open BIN, ">Skydot-Frames.bin";
binmode BIN;

while ($file->gzreadline(my $line))
{
	my ($field, $fname, $camera, $mjd, $obstime, $date_obs, $exptime, $bkg, $bkg_sigma, $pos_sigma, $zp_offset, $zp_sigma,
		$m_lim, $sat_mag, $nobj_det, $nobj_ext, $nmatch, $dmoon, $elev, $azimuth, $mount_ra, $mount_dec, $offst_ra, $offst_dec) = split(';', $line);
	my $jd = $mjd + 2400000.5;
	$jd += Astro::Time::HJD::correction($jd, $mount_ra + $offst_ra, $mount_dec + $offst_dec) - 2451000;
	$jd = sprintf("%07d", 10000*$jd);
	my $b1 = $jd & 0xff;
	my $b2 = $jd >> 8;
	my $buffer = pack("SC", $b2, $b1);
	print BIN $buffer;
}

close BIN;

