import os
import numpy as np
import matplotlib.pyplot as plt
import pyharm as ph


FILE_IN  = ['./Uloha 1 a 2.txt', './Uloha 3.txt']
NMAX     = range(0, 230, 5)
TOPO     = [False, True]


shcs = ph.shc.Shc.from_file('tbl', './bennu-potential-to225-sgfm.tbl')


for fin in FILE_IN:

    data = np.loadtxt(fin)


    for topo in TOPO:

        lat  = np.ascontiguousarray(np.deg2rad(data[:, 0]).copy())
        lon  = np.ascontiguousarray(np.deg2rad(data[:, 1]).copy())
        if topo:
            r = np.ascontiguousarray(data[:, 2].copy())
        else:
            r = np.full(lat.shape, 283.0)
        pnt = ph.crd.PointSctr.from_arrays(lat, lon, r)

        for nmax in NMAX:

            print(fin, topo, nmax)

            v = ph.shs.point(pnt, shcs, nmax)
            fout = f'{os.path.splitext(fin)[0]}-potential-to{nmax:03}-' + \
                   f'at-topo-{topo}.txt'
            np.savetxt(fout, v)
