def write_alarm_msg(radar_name, param_name_unit, date_last, target, tol_abs,
    np_trend, value_trend, tol_trend, nevents, np_last, value_last, fname):
    """
    writes an alarm file

    Parameters
    ----------
    radar_name : str
        Name of the radar being controlled
    param_name_unit : str
        Parameter and units
    date_last : datetime object
        date of the current event
    target, tol_abs : float
        Target value and tolerance
    np_trend : int
        Total number of points in trend
    value_trend, tol_trend : float
        Trend value and tolerance
    nevents: int
        Number of events in trend
    np_last : int
        Number of points in the current event
    value_last : float
        Value of the current event
    fname : str
        Name of file where to store the alarm information

    Returns
    -------
    fname : str
        the name of the file where data has written

    """
    with open(fname, 'w', newline='') as txtfile:
        txtfile.write(
            'Weather radar polarimetric parameters monitoring alarm\n')
        if radar_name is not None:
            txtfile.write('Radar name: ' + radar_name + '\n')
        txtfile.write('Parameter [Unit]: ' + param_name_unit + '\n')
        txtfile.write('Date : ' + date_last.strftime('%Y%m%d') + '\n')
        txtfile.write('Target value: ' + str(target) + ' +/- ' + str(
            tol_abs) + '\n')
        if np_trend > 0:
            txtfile.write('Number of points in trend: ' + str(np_trend) +
                ' in ' + str(nevents) + ' events\n')
            txtfile.write('Trend value: ' + str(value_trend) +
                ' (tolerance: +/- ' + str(tol_trend) + ')\n')
        else:
            txtfile.write('Number of points in trend: NA\n')
            txtfile.write('Trend value: NA\n')
        txtfile.write('Number of points: ' + str(np_last) + '\n')
        txtfile.write('Value: ' + str(value_last) + '\n')
        txtfile.close()
    return fname
