write a dataframe as an smp file

    Parameters
    ----------
    dataframe : pandas.DataFrame
    smp_filename : str
        smp file to write
    name_col: str
        the column in the dataframe the marks the site namne
    datetime_col: str
        the column in the dataframe that is a datetime instance
    value_col: str
        the column in the dataframe that is the values
    datetime_format: str
        either 'dd/mm/yyyy' or 'mm/dd/yyy'
    value_format: str
        a python float-compatible format

def dataframe_to_smp(dataframe,smp_filename,name_col="name",
                     datetime_col="datetime",value_col="value",
                     datetime_format="dd/mm/yyyy",
                     value_format="{0:15.6E}",
                     max_name_len=12):
    """ write a dataframe as an smp file

    Parameters
    ----------
    dataframe : pandas.DataFrame
    smp_filename : str
        smp file to write
    name_col: str
        the column in the dataframe the marks the site namne
    datetime_col: str
        the column in the dataframe that is a datetime instance
    value_col: str
        the column in the dataframe that is the values
    datetime_format: str
        either 'dd/mm/yyyy' or 'mm/dd/yyy'
    value_format: str
        a python float-compatible format

    """
    formatters = {"name":lambda x:"{0:<20s}".format(str(x)[:max_name_len]),
                  "value":lambda x:value_format.format(x)}
    if datetime_format.lower().startswith("d"):
        dt_fmt = "%d/%m/%Y    %H:%M:%S"
    elif datetime_format.lower().startswith("m"):
        dt_fmt = "%m/%d/%Y    %H:%M:%S"
    else:
        raise Exception("unrecognized datetime_format: " +\
                        "{0}".format(str(datetime_format)))

    for col in [name_col,datetime_col,value_col]:
        assert col in dataframe.columns

    dataframe.loc[:,"datetime_str"] = dataframe.loc[:,"datetime"].\
        apply(lambda x:x.strftime(dt_fmt))
    if isinstance(smp_filename,str):
        smp_filename = open(smp_filename,'w')
        # need this to remove the leading space that pandas puts in front
        s = dataframe.loc[:,[name_col,"datetime_str",value_col]].\
                to_string(col_space=0,
                          formatters=formatters,
                          justify=None,
                          header=False,
                          index=False)
        for ss in s.split('\n'):
            smp_filename.write("{0:<s}\n".format(ss.strip()))
    dataframe.pop("datetime_str")