def atmos(h):
    """ atmos(altitude): International Standard Atmosphere calculator

        Input:
              h =  altitude in meters 0.0 < h < 84852.
        (will be clipped when outside range, integer input allowed)
        Output:
              [p,rho,T]    (in SI-units: Pa, kg/m3 and K) """

    # Constants

    # Base values and gradient in table from hand-out
    # (but corrected to avoid small discontinuities at borders of layers)
    h0 = [0.0, 11000., 20000., 32000., 47000., 51000., 71000., 86852.]

    p0 = [101325.,                  # Sea level
           22631.7009099,           # 11 km
            5474.71768857,          # 20 km
             867.974468302,         # 32 km
             110.898214043,         # 47 km
              66.939,               # 51 km
               3.9564 ]             # 71 km

    T0 = [288.15,  # Sea level
          216.65,  # 11 km
          216.65,  # 20 km
          228.65,  # 32 km
          270.65,  # 47 km
          270.65,  # 51 km
          214.65]  # 71 km

    # a = lapse rate (temp gradient)
    # integer 0 indicates isothermic layer!
    a  = [-0.0065, # 0-11 km
            0,     # 11-20 km
          0.001,   # 20-32 km
          0.0028,  # 32-47 km
            0,     # 47-51 km
          -0.0028, # 51-71 km
          -0.002]  # 71-   km

    # Clip altitude to maximum!
    h = max(0.0, min(float(h), h0[-1]))

    # Find correct layer
    i = 0
    while h > h0[i+1] and i < len(h0) - 2:
        i = i+1

    # Calculate if sothermic layer
    if a[i] == 0:
        T   = T0[i]
        p   = p0[i]*np.exp(-g0/(R*T)*(h-h0[i]))
        rho = p/(R*T)

    # Calculate for temperature gradient
    else:
        T   = T0[i] + a[i]*(h-h0[i])
        p   = p0[i]*((T/T0[i])**(-g0/(a[i]*R)))
        rho = p/(R*T)

    return p, rho, T
atmos(altitude): International Standard Atmosphere calculator

        Input:
              h =  altitude in meters 0.0 < h < 84852.
        (will be clipped when outside range, integer input allowed)
        Output:
              [p,rho,T]    (in SI-units: Pa, kg/m3 and K)