#PLOTTING CORRECTION TO SHRAVAN'S KERNEL
	
import timing
kernclock = timing.stopclock() #stopclock object for timing program
tstamp = kernclock.lap
import numpy as np
import matplotlib.pyplot as plt
import functions as fn
from os import getcwd

tstamp('library loading') #printing elapsed time from beginning of runtime

n,l,m = 1,60,0
n_,l_,m_ = n,l,2
nl = fn.find_nl(n,l)
nl_ = fn.find_nl(n_,l_)
s = 22
t = m_-m


#Savitsky golay filter for smoothening
window = 45  #must be odd
order = 3

if(nl == None or nl_ == None):
	print("Mode not found. Exiting."); exit()

#loading required functions
eig_dir = (getcwd() + '/eig_files')
U,V = fn.load_eig(n,l,eig_dir)
U_,V_= fn.load_eig(n_,l_,eig_dir)
import numpy as np
import matplotlib.pyplot as plt
import submatrix
import functions as fn
import sys
import timing
import matplotlib.gridspec as gridspec
plt.ion()

clock1 = timing.stopclock()
tstamp = clock1.lap
#all quantities in cgs
#M_sol = 1.989e33 g
#R_sol = 6.956e10 cm
#B_0 = 10e5 G
#OM = np.sqrt(4*np.pi*R_sol*B_0**2/M_sol)
#rho_0 = M_sol/(4pi R_sol^3/3) = 1.41 ~ 1g/cc (for kernel calculation)

OM = np.loadtxt(
    'OM.dat')  #importing normalising frequency value from file (in Hz (cgs))

field_type = 'mixed'
r = np.loadtxt('r.dat')
r_start, r_end = 0., 1.
start_ind, end_ind = [fn.nearest_index(r, pt) for pt in (r_start, r_end)]
r = r[start_ind:end_ind]

#1 = Low, 2 = High. A=Core, B=Tachocline, C=Surface
A = 1
B = 1
C = 1
import numpy as np
import functions as fn
import scipy.integrate
import get_kernels as gkerns
import h_components as hcomps
import sys
import math
#code snippet for timing the code
import timing
clock2 = timing.stopclock()
tstamp = clock2.lap

OM = np.loadtxt('OM.dat')
R_sol = 6.956e10 #cm
        
def lorentz(n_,n,l_,l,r,beta =0., field_type = 'dipolar'):   
    m = np.arange(-l,l+1,1)    #-l<=m<=l
    m_ = np.arange(-l_,l_+1,1)  #-l_<=m<=l_    
    s = np.array([0,1,2])
    s0 = 1  
    t0 = np.arange(-s0,s0+1)                                       
    #transition radii for mixed field type
    R1 = r[0]
    R2 = r[-1]
    B_mu_t_r = fn.getB_comps(s0,r,R1,R2,field_type)

    get_h = hcomps.getHcomps(s,m_,m,s0,t0,r,B_mu_t_r, beta)

    tstamp()

    H_super = get_h.ret_hcomps()  #- sign due to i in B
import timing
import numpy as np
import matplotlib.pyplot as plt
import functions as fn
from os import getcwd
import get_kernels as gkerns

kernclock = timing.stopclock()
tstamp = kernclock.lap

r = np.loadtxt('r.dat')
r_start = 0.68
r_end = 1.0
start_ind = fn.nearest_index(r, r_start)
end_ind = fn.nearest_index(r, r_end)
r = r[start_ind:end_ind + 1]
OM = np.loadtxt('OM.dat')

# n1,l1 = 4,3
# n2,l2 = 1,10
# n3,l3 = 0,60

n1, l1 = 15, 102
n2, l2 = 15, 50
n3, l3 = 15, 10

omega_list = np.loadtxt('muhz.dat')
omega_nl1 = omega_list[fn.find_nl(n1, l1)]
omega_nl2 = omega_list[fn.find_nl(n2, l2)]
omega_nl3 = omega_list[fn.find_nl(n3, l3)]