import csv


def writeCSV(file,data,cols = None):
    """
    Write CSV file with data typically supplied as a list or np.arrays.

    :param file: file or name of file, 
    :type file: file or str
    :param data: list of numpy.array or two dimensional numpy.array
    :type data: list of numpy.array or two dimensional numpy.array.
    :param cols: boolean list specifying which colums of data are to be written, defaults to None, which means all cols.
    :type cole: truple of booleans or None
    :return: The number of lines of data written
    
    """
    #     Open the file if a name was given as a str.
    if isinstance(file,str):
        file = open(file,"w",newline='')
        
    writer = csv.writer(file)           # Make writer
    #      Read through data writing out what is required.
    for j in range(0,data[0].size):     # Number of elements
        s = []
        for i in range(0,len(data)):    # Number of cole
            if cols == None or cols[i] :
                s.append("{0:12.5e}".format(data[i][j]))

        writer.writerow(s)

    file.close()
    return data[0].size           # Number writer