import numpy as np
    
def fProfileKarmanTrefftz(xc = None,yc = None,tau = None,n = None,varargin = None): 
    # returns Karman-Trefftz profiles, and optionally pressure distribution and velocity field
# AUTHOR: E. Branlard
# INPUT:
#    xc,yc   # Circle Center Location
#    tau     # Tail Angle in deg
#    n       # Number of points along mapped foil surface
# OUTPUT:
#   X and Y coordinates of airfoil
#   Cp : pressure coeff at foil surface
#   Xg,Yg,Ug,Vg,CP : grid points, velocity field and  pressure coeff
# EXAMPLES:
#   [X_p,Y_p]    = fProfileKarmanTrefftz(xc,yc,tau,n);
#   [X_p,Y_p,Cp] = fProfileKarmanTrefftz(xc,yc,tau,n,U0,alpha_deg);
#   [X_p,Y_p,Cp,Ug,Vg,CP] = fProfileKarmanTrefftz(xc,yc,tau,n,U0,alpha_deg,Xg,Yg);
## --- Optional arguments
    bComputeGridVelocity = 0
    bComputeAero = 0
    if len(varargin) > 4:
        bComputeAero = 1
        U0 = varargin[0]
        alpha = varargin[2]
        if len(varargin) > 6:
            bComputeGridVelocity = 1
            Xg = varargin[3]
            Yg = varargin[4]
    
    # Optional outputs
    Cp = []
    U = []
    V = []
    CP = []
    Gamma = []
    ## Main parameters
    a = 1.0
    
    rc = np.sqrt((a - xc) ** 2 + yc ** 2)
    
    beta = np.arcsin(- yc / (rc))
    
    lambda_ = 2 - tau / 180
    ## Coordinates of profile (using transform of the circle)
    vtheta_circ = np.arange(0,2 * np.pi - np.pi / n+2 * np.pi / n,2 * np.pi / n)
    
    z0 = (xc + i * yc)
    
    z_circ = z0 + rc * np.exp(i * vtheta_circ)
    # --- Karman-Trefftz Conformal map - Profile Shape
    Z_profile,dZdz = fConformalMapKarmanTrefftz_springer(z_circ,a,lambda_,False)
    X_profile = real(Z_profile)
    Y_profile = imag(Z_profile)
    ## Aero computation if required
    if bComputeAero:
        ## ---Pressure distribution on the airfoil
        Gamma = 4 * np.pi * rc * U0 * np.sin(beta - alpha * np.pi / 180)
        # Velocity at circle surface
        u_circ,v_circ = fUi_Cylinder2D_springer(real(z_circ),imag(z_circ),xc,yc,rc,U0,alpha,Gamma)
        # Velocities, -Cp on surface
        W_circ = (u_circ - i * v_circ) / dZdz
        U_circ = real(W_circ)
        V_circ = - imag(W_circ)
        Q = np.sqrt(U_circ ** 2 + V_circ ** 2)
        Cp = 1 - (Q / U0) ** 2
        ## Pressure distribution on a grid (using direct transform and a polar grid)
        if bComputeGridVelocity:
            # Inverse Karman Trefftz Conformal map
            Zg = Xg + 1j * Yg
            z,dzdZ = fConformalMapKarmanTrefftz_springer(Zg,a,lambda_,True)
            x = real(z)
            y = imag(z)
            u,v = fUi_Cylinder2D_springer(x,y,xc,yc,rc,U0,alpha,Gamma)
            W = np.multiply((u - np.multiply(1j,v)),dzdZ)
            Ug = real(W)
            Vg = - imag(W)
            Q = np.sqrt(Ug ** 2 + Vg ** 2)
            CP = 1 - (Q / U0) ** 2
    
    ## Standardizing coordinates
# [P PS SS TE chord IPin IPout]=fProfileStandardize(X_profile,Y_profile,[]);
    return X_profile,Y_profile,Cp,Ug,Vg,CP,Gamma