def writeRawData(filename, data):
    """Write the data into a raw format file.

    Arguments:
        filename (str): file name as regular expression
        data (array): data to write to raw file
    
    Returns:
        str: file name of raw file
    """   
    
    rawfile = open(filename,'wb')
    d = len(data.shape)
    if d <= 2:
        data.transpose([1,0]).tofile(rawfile)
    elif d == 3:
        data.transpose([2,1,0]).tofile(rawfile)
    elif d== 4:
        data.transpose([3,2,1,0]).tofile(rawfile)
    else:
        raise RuntimeError('writeRawData: image dimension %d not supported!' % d)
    
    rawfile.close()
    
    return filename