def fdtfile2fieldstring(fdtfile):
    """Make a string of field definitions separated by % (percent sign)
    reading from a fdtfile or just take the string and bring into shape:

        e.g.  1,AA,20,A,NC,NN%1,F4,4,F,NU,DT=E(UNIXTIME)

    :param fdtfile:  fdtfile or field string

    :return: tuple (number of fields, field string)

    """
    if ',' in fdtfile:      # fdt or file name
        fields=fdtfile      # fdt field defn contains commas
                            # file name has no comma
        lines=[line.split(';')[0].rstrip() for line in fields.split('%')]
    else:
        f=open(fdtfile)
        lines=[]
        for line in f.readlines():
            # drop CRLF, take string before ';', cut off trailing blanks
            lines.append(line[:-1].split(';')[0].rstrip())
        f.close()

    fields='%'.join(lines)
    numfields=len(lines)

    return numfields,fields