"""
Scan all DAT files for KM call signs to find bandwidth and modulation data.
"""
import os, pandas as pd

ULS_DIR = r"D:\FCC_ULS"
KM_CS = {'KFO93','KKO54','KOE34','WIA659','WIA662','WPYA953',
          'WQDU978','WNTK845','WNTK846','WNTU758','WQGL488'}

for fname in os.listdir(ULS_DIR):
    if not fname.upper().endswith('.DAT'):
        continue
    fpath = os.path.join(ULS_DIR, fname)
    try:
        rows = []
        with open(fpath, 'r', encoding='latin-1') as f:
            for line in f:
                fields = line.split('|')
                if len(fields) > 4 and fields[4].strip() in KM_CS:
                    rows.append(fields)
        if rows:
            print(f"\n{fname}: {len(rows)} KM rows")
            # Show all non-empty cols of first row
            for j, v in enumerate(rows[0]):
                if v.strip():
                    print(f"  col[{j:2d}] = '{v.strip()}'")
    except Exception as e:
        print(f"{fname}: ERROR {e}")
