## Initialization
import numpy as np
import matplotlib.pyplot as plt
addpath('C:\Work\_libs\matlab-path\libs\lib_tools\')

clearvars
close_('all')
## Parameters for Karman Trefftz airfoil
U0 = 1

alpha_deg = 0

xc = - 0.2

yc = 0.1

tau = 10

# ---  Display parameters
n = 100

nx = 200
ny = 200

nStreamlines = 21

XLIM = np.array([- 3.5,3.5])
YLIM = np.array([- 3,3])
## Main function call (with grid for contour plots, but not necessary)
Xg,Yg = np.meshgrid(np.linspace(plt.xlim(1),plt.xlim(2),nx),np.linspace(plt.ylim(1),plt.ylim(2),ny))
X_p,Y_p,Cp,Ug,Vg,CP = fProfileKarmanTrefftz_springer(xc,yc,tau,n,U0,alpha_deg,Xg,Yg)
P,PS,SS,TE,chord,IPin,IPout = fProfileStandardize(X_p,Y_p,[])
## Plotting pressure distribution about the airfoil
figure
hold('on')
grid('on')
box('on')
plt.plot((X_p - np.amin(X_p)) / (np.amax(X_p) - np.amin(X_p)),Cp,'k.-')
plt.xlabel('x/c [-]')
plt.ylabel('C_p [-]')
plt.title(sprintf('Karman-Trefftz C_p \alpha = %.1f deg.',alpha_deg))
plt.xlim(np.array([0,1]))
plt.axis('ij')
## Plotting airfoil, streamlines and pressure distribution around the foil
figure
grid('on')
hold('on')
plt.axis('equal')
box('on')
contourf(Xg,Yg,CP,15)
fill(X_p,Y_p,'w')
plt.plot(P(:,1) * chord + np.amin(X_p),P(:,2) * chord,'b.')
plt.plot(P(1,1) * chord + np.amin(X_p),P(1,2) * chord,'bd')
plt.plot(P(2,1) * chord + np.amin(X_p),P(2,2) * chord,'ro')
Y0 = np.linspace(plt.ylim(1),plt.ylim(2),nStreamlines)
X0 = Y0 * 0 + plt.xlim(1)
hlines = streamline(stream2(Xg,Yg,Ug,Vg,X0,Y0))
set(hlines,'Color','k')
plt.ylim(YLIM)
plt.xlim(XLIM)
plt.title('Karman-Trefftz Cp and streamlines')