import subprocess
#import pandas as pd
import argparse
import sys
import os

#import viewdat_cno_lib as vdl

parser = argparse.ArgumentParser(
    description='Apply an elevation mask with t0x2t0x.',
    formatter_class=argparse.ArgumentDefaultsHelpFormatter,
)
parser.add_argument(
    "filenameA",
    default='TitanPlayer_log.txt',
    help="File to process"
)
parser.add_argument(
    "filenameB",
    default='TitanPlayer_log.txt',
    help="File to process"
)
#parser.add_argument(
#    '--t04_list',
#    nargs='+', 
#    default=['BX992_all.T04', 'EB1-5093_all.T04', 'EB1-5095_all.T04',
#             'EB-5081_all.T04', 'P4-05_all.T04'],
#    help="Elevation Mask to apply."
#)
#parser.add_argument(
#    "-n", "--dry_run",
#    action='store_true',
#    help="Don't actually run t0x2t0x, just print the commands."
#)
args = parser.parse_args()

def read_next_epoch(fp):
    line = ""
    while not('[HRPROC]' in line and 'MetaData::SatUsage' in line):
        line = fp.readline()
        if not line:
            return None
    epoch = float(line.split()[1])

    while 'TectonicPlateReport' not in line:
        line = fp.readline()
        if not line:
            return None
    return epoch, epoch_sats

epoch = None
sat_sets = []
readA = True
readB = True
epochA_sats = None
epochB_sats = None
            #while lineB := fileB.readline():
fileA = open(args.filenameA)
fileB = open(args.filenameB)

lineA = fileA.readline()
lineB = fileB.readline()
while lineA and lineB:
    if readA:
        epochA, epochA_sats = read_next_epoch(fileA)
    if readB:
        epochB, epochB_sats = read_next_epoch(fileB)

    if epochA == epochB:
        readA = True
        readB = True
        # TODO Compare
    elif epochA > epochB:


    print('--------------------')
    print(f'A: {lineA.rstrip()}')
    print(f'B: {lineB.rstrip()}')

    #if '[HRPROC]' in line and 'MetaData::SatUsage' in line:
    #    epoch = float(line.split()[1])
    #if 'TectonicPlateReport' in line:
    #    epoch = None
    #    epochA

    if epoch is not None:
        if '[G]' in line or '[R]' in line or '[E]' in line or '[C]' in line:


