#NEWLINE# def filename_to_indices( filename , identifiers = 'tzc' ) : #NEWLINE# #INDENT# ' Find ocurrences of axis indices (e.g. t001, z06, c2)\n    in a filename and returns a list of indices.\n\n    Parameters\n    ----------\n    filename : string\n        filename to be searched for indices\n    identifiers : string or list of strings, optional\n        iterable of N strings preceding axis indices, in that order\n\n    Returns\n    ---------\n    list of int\n        axis indices. Elements default to 0 when index was not found.\n\n    ' #NEWLINE# escaped = [ re . escape ( a ) for a in identifiers ] #NEWLINE# axes = re . findall ( ( ( '(' + '|' . join ( escaped ) ) + ')(\\d+)' ) , filename ) #NEWLINE# if ( len ( axes ) > len ( identifiers ) ) : #NEWLINE# #INDENT# axes = axes [ ( - 3 ) : ] #NEWLINE# #UNINDENT# order = [ a [ 0 ] for a in axes ] #NEWLINE# result = ( [ 0 ] * len ( identifiers ) ) #NEWLINE# for ( i , col ) in enumerate ( identifiers ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# result [ i ] = int ( axes [ order . index ( col ) ] [ 1 ] ) #NEWLINE# #UNINDENT# except ValueError : #NEWLINE# #INDENT# result [ i ] = 0 #NEWLINE# #UNINDENT# #UNINDENT# return order