<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def wrsamp(record_name, fs, units, sig_name, p_signal=None, d_signal=None, fmt=None, adc_gain=None, baseline=None, comments=None, base_time=None, base_date=None, write_dir=''):
 """ Write a single segment WFDB record, creating a WFDB header file and any associated dat files. Parameters record_name : str The string name of the WFDB record to be written (without any file extensions). fs : int, or float The sampling frequency of the record. units : list A list of strings giving the units of each signal channel. sig_name : A list of strings giving the signal name of each signal channel. p_signal : numpy array, optional An (MxN) 2d numpy array, where M is the signal length. Gives the physical signal values intended to be written. Either p_signal or d_signal must be set, but not both. If p_signal is set, this method will use it to perform analogue-digital conversion, writing the resultant digital values to the dat file(s). If fmt is set, gain and baseline must be set or unset together. If fmt is unset, gain and baseline must both be unset. d_signal : numpy array, optional An (MxN) 2d numpy array, where M is the signal length. Gives the digital signal values intended to be directly written to the dat file(s). The dtype must be an integer type. Either p_signal or d_signal must be set, but not both. In addition, if d_signal is set, fmt, gain and baseline must also all be set. fmt : list, optional A list of strings giving the WFDB format of each file used to store each channel. Accepted formats are: '80','212",'16','24', and '32'. There are other WFDB formats as specified by: https://www.physionet.org/physiotools/wag/signal-5.htm but this library will not write (though it will read) those file types. adc_gain : list, optional A list of numbers specifying the ADC gain. baseline : list, optional A list of integers specifying the digital baseline. comments : list, optional A list of string comments to be written to the header file. base_time : str, optional A string of the record's start time in 24h 'HH:MM:SS(.ms)' format. base_date : str, optional A string of the record's start date in 'DD/MM/YYYY' format. write_dir : str, optional The directory in which to write the files. Notes ----- This is a gateway function, written as a simple method to write WFDB record files using the most common parameters. Therefore not all WFDB fields can be set via this function. For more control over attributes, create a `Record` object, manually set its attributes, and call its `wrsamp` instance method. If you choose this more advanced method, see also the `set_defaults`, `set_d_features`, and `set_p_features` instance methods to help populate attributes. Examples -------- pb_dir='challenge/2015/training') sig_name=['I', 'II'], p_signal=signals, fmt=['16', '16']) """


    # Check input field combinations
    if p_signal is not None and d_signal is not None:
        raise Exception('Must only give one of the inputs: p_signal or d_signal')
    if d_signal is not None:
        if fmt is None or adc_gain is None or baseline is None:
            raise Exception("When using d_signal, must also specify 'fmt', 'gain', and 'baseline' fields.")
    # Depending on whether d_signal or p_signal was used, set other
    # required features.
    if p_signal is not None:
        # Create the Record object
        record = Record(record_name=record_name, p_signal=p_signal, fs=fs,
                        fmt=fmt, units=units, sig_name=sig_name,
                        adc_gain=adc_gain, baseline=baseline,
                        comments=comments, base_time=base_time,
                        base_date=base_date)
        # Compute optimal fields to store the digital signal, carry out adc,
        # and set the fields.
        record.set_d_features(do_adc=1)
    else:
        # Create the Record object
        record = Record(record_name=record_name, d_signal=d_signal, fs=fs,
                        fmt=fmt, units=units, sig_name=sig_name,
                        adc_gain=adc_gain, baseline=baseline,
                        comments=comments, base_time=base_time,
                        base_date=base_date)
        # Use d_signal to set the fields directly
        record.set_d_features()

    # Set default values of any missing field dependencies
    record.set_defaults()
    # Write the record files - header and associated dat
    record.wrsamp(write_dir=write_dir)