# Path: skyfield/api.py
# N = E = +1.0
# S = W = -1.0
# 
# Path: skyfield/data/mpc.py
# MPCORB_URL = 'https://www.minorplanetcenter.net/iau/MPCORB/MPCORB.DAT.gz'
# _MPCORB_COLUMNS = [
#     ('designation_packed', (0, 7)),
#     ('magnitude_H', (8, 13)),
#     ('magnitude_G', (14, 19)),
#     ('epoch_packed', (20, 25)),
#     ('mean_anomaly_degrees', (26, 35)),
#     ('argument_of_perihelion_degrees', (37, 46)),
#     ('longitude_of_ascending_node_degrees', (48, 57)),
#     ('inclination_degrees', (59, 68)),
#     ('eccentricity', (70, 79)),
#     ('mean_daily_motion_degrees', (80, 91)),
#     ('semimajor_axis_au', (92, 103)),
#     ('uncertainty', (105, 106)),
#     ('reference', (107, 116)),
#     ('observations', (117, 122)),
#     ('oppositions', (123, 126)),
#     ('observation_period', (127, 136)),
#     ('rms_residual_arcseconds', (137, 141)),
#     ('coarse_perturbers', (142, 145)),
#     ('precise_perturbers', (146, 149)),
#     ('computer_name', (150, 160)),
#     ('hex_flags', (161, 165)),
#     ('designation', (166, 194)),
#     ('last_observation_date', (194, 202)),
# ]
# _MPCORB_NECESSARY_COLUMNS = {
#     'designation_packed', 'epoch_packed', 'mean_anomaly_degrees',
#     'argument_of_perihelion_degrees', 'longitude_of_ascending_node_degrees',
#     'inclination_degrees', 'eccentricity', 'mean_daily_motion_degrees',
#     'semimajor_axis_au',
# }
# _MPCORB_DTYPES = {
#     # These seem to be ignored by read_fwf()?
#     'epoch_packed': 'category',
#     'uncertainty': 'category',
#     'coarse_perturbers': 'category',
#     'precise_perturbers': 'category',
#     'computer_name': 'category',
# }
# _MPCORB_CONVERTERS = {
#     'designation_packed': str,
#     'hex_flags': str,
# }
# COMET_URL = 'https://www.minorplanetcenter.net/iau/MPCORB/CometEls.txt'
# _COMET_COLUMNS = [
#     ('number', (0, 4)),
#     ('orbit_type', (4, 5)),
#     ('designation_packed', (5, 12)),
#     ('perihelion_year', (14, 18)),
#     ('perihelion_month', (19, 21)),
#     ('perihelion_day', (22, 29)),
#     ('perihelion_distance_au', (30, 39)),
#     ('eccentricity', (41, 49)),
#     ('argument_of_perihelion_degrees', (51, 59)),
#     ('longitude_of_ascending_node_degrees', (61, 69)),
#     ('inclination_degrees', (71, 79)),
#     ('perturbed_epoch_year', (81, 85)),
#     ('perturbed_epoch_month', (85, 87)),
#     ('perturbed_epoch_day', (87, 89)),
#     ('magnitude_g', (91, 95)),
#     ('magnitude_k', (96, 100)),
#     ('designation', (102, 158)),
#     ('reference', (159, 168)),
# ]
# _COMET_FAST_COLUMNS = (
#     'perihelion_year', 'perihelion_month', 'perihelion_day',
#     'perihelion_distance_au', 'eccentricity', 'argument_of_perihelion_degrees',
#     'longitude_of_ascending_node_degrees', 'inclination_degrees',
#     'magnitude_g', 'magnitude_k',
#     'designation', 'reference',
# )
# def load_mpcorb_dataframe(fobj):
# def mpcorb_orbit(row, ts, gm_km3_s2):
#     def n(c):
#     def d(s):
# def load_comets_dataframe(fobj):
# def load_comets_dataframe_slow(fobj):
# def comet_orbit(row, ts, gm_km3_s2):
# def _comet_orbits(rows, ts, gm_km3_s2):
# def unpack(designation_packed):
#     def n(c):


import argparse
import re
import sys
import zlib
from skyfield.api import load
from skyfield.data import mpc
# mpc_make_excerpt.py

"""Search the MPCORB file for minor planets, given their packed designations."""



def main(argv):
    parser = argparse.ArgumentParser(description='Grep MPCORB.DAT.gz')
    parser.add_argument('designations', nargs='+', help='packed designations'
                        ' of the minor planets whose orbits you need')
    args = parser.parse_args(argv)

    designations = [re.escape(d.encode('ascii')) for d in args.designations]
    pattern = rb'^((?:%s) .*\n)' % rb'|'.join(designations)
    r = re.compile(pattern, re.M)


# Path: skyfield/api.py
# N = E = +1.0
# S = W = -1.0
# 
# Path: skyfield/data/mpc.py
# MPCORB_URL = 'https://www.minorplanetcenter.net/iau/MPCORB/MPCORB.DAT.gz'
# _MPCORB_COLUMNS = [
#     ('designation_packed', (0, 7)),
#     ('magnitude_H', (8, 13)),
#     ('magnitude_G', (14, 19)),
#     ('epoch_packed', (20, 25)),
#     ('mean_anomaly_degrees', (26, 35)),
#     ('argument_of_perihelion_degrees', (37, 46)),
#     ('longitude_of_ascending_node_degrees', (48, 57)),
#     ('inclination_degrees', (59, 68)),
#     ('eccentricity', (70, 79)),
#     ('mean_daily_motion_degrees', (80, 91)),
#     ('semimajor_axis_au', (92, 103)),
#     ('uncertainty', (105, 106)),
#     ('reference', (107, 116)),
#     ('observations', (117, 122)),
#     ('oppositions', (123, 126)),
#     ('observation_period', (127, 136)),
#     ('rms_residual_arcseconds', (137, 141)),
#     ('coarse_perturbers', (142, 145)),
#     ('precise_perturbers', (146, 149)),
#     ('computer_name', (150, 160)),
#     ('hex_flags', (161, 165)),
#     ('designation', (166, 194)),
#     ('last_observation_date', (194, 202)),
# ]
# _MPCORB_NECESSARY_COLUMNS = {
#     'designation_packed', 'epoch_packed', 'mean_anomaly_degrees',
#     'argument_of_perihelion_degrees', 'longitude_of_ascending_node_degrees',
#     'inclination_degrees', 'eccentricity', 'mean_daily_motion_degrees',
#     'semimajor_axis_au',
# }
# _MPCORB_DTYPES = {
#     # These seem to be ignored by read_fwf()?
#     'epoch_packed': 'category',
#     'uncertainty': 'category',
#     'coarse_perturbers': 'category',
#     'precise_perturbers': 'category',
#     'computer_name': 'category',
# }
# _MPCORB_CONVERTERS = {
#     'designation_packed': str,
#     'hex_flags': str,
# }
# COMET_URL = 'https://www.minorplanetcenter.net/iau/MPCORB/CometEls.txt'
# _COMET_COLUMNS = [
#     ('number', (0, 4)),
#     ('orbit_type', (4, 5)),
#     ('designation_packed', (5, 12)),
#     ('perihelion_year', (14, 18)),
#     ('perihelion_month', (19, 21)),
#     ('perihelion_day', (22, 29)),
#     ('perihelion_distance_au', (30, 39)),
#     ('eccentricity', (41, 49)),
#     ('argument_of_perihelion_degrees', (51, 59)),
#     ('longitude_of_ascending_node_degrees', (61, 69)),
#     ('inclination_degrees', (71, 79)),
#     ('perturbed_epoch_year', (81, 85)),
#     ('perturbed_epoch_month', (85, 87)),
#     ('perturbed_epoch_day', (87, 89)),
#     ('magnitude_g', (91, 95)),
#     ('magnitude_k', (96, 100)),
#     ('designation', (102, 158)),
#     ('reference', (159, 168)),
# ]
# _COMET_FAST_COLUMNS = (
#     'perihelion_year', 'perihelion_month', 'perihelion_day',
#     'perihelion_distance_au', 'eccentricity', 'argument_of_perihelion_degrees',
#     'longitude_of_ascending_node_degrees', 'inclination_degrees',
#     'magnitude_g', 'magnitude_k',
#     'designation', 'reference',
# )
# def load_mpcorb_dataframe(fobj):
# def mpcorb_orbit(row, ts, gm_km3_s2):
#     def n(c):
#     def d(s):
# def load_comets_dataframe(fobj):
# def load_comets_dataframe_slow(fobj):
# def comet_orbit(row, ts, gm_km3_s2):
# def _comet_orbits(rows, ts, gm_km3_s2):
# def unpack(designation_packed):
#     def n(c):


# Path: design/mpc_make_excerpt.py
import argparse
import re
import sys
import zlib
from skyfield.api import load
from skyfield.data import mpc

# mpc_make_excerpt.py

"""Search the MPCORB file for minor planets, given their packed designations."""



def main(argv):
    parser = argparse.ArgumentParser(description='Grep MPCORB.DAT.gz')
    parser.add_argument('designations', nargs='+', help='packed designations'
                        ' of the minor planets whose orbits you need')
    args = parser.parse_args(argv)

    designations = [re.escape(d.encode('ascii')) for d in args.designations]
    pattern = rb'^((?:%s) .*\n)' % rb'|'.join(designations)
    r = re.compile(pattern, re.M)


    data = load.open(mpc.MPCORB_URL).read()