def check_if_needs_inversion(tomodir):
    """check of we need to run CRTomo in a given tomodir
    """
    required_files = (
        'grid' + os.sep + 'elem.dat',
        'grid' + os.sep + 'elec.dat',
        'exe' + os.sep + 'crtomo.cfg',
    )

    needs_inversion = True

    for filename in required_files:
        if not os.path.isfile(tomodir + os.sep + filename):
            needs_inversion = False

    # check for crmod OR modeling capabilities
    if not os.path.isfile(tomodir + os.sep + 'mod' + os.sep + 'volt.dat'):
        if not check_if_needs_modeling(tomodir):
            print('no volt.dat and no modeling possible')
            needs_inversion = False

    # check if finished
    inv_ctr_file = tomodir + os.sep + 'inv' + os.sep + 'inv.ctr'
    if os.path.isfile(inv_ctr_file):
        inv_lines = open(inv_ctr_file, 'r').readlines()
        print('inv_lines', inv_lines[-1])
        if inv_lines[-1].startswith('***finished***'):
            needs_inversion = False

    return needs_inversion
def check_if_needs_inversion ( tomodir ) : required_files = ( 'grid' + os . sep + 'elem.dat' , 'grid' + os . sep + 'elec.dat' , 'exe' + os . sep + 'crtomo.cfg' , ) needs_inversion = True for filename in required_files : if not os . path . isfile ( tomodir + os . sep + filename ) : needs_inversion = False if not os . path . isfile ( tomodir + os . sep + 'mod' + os . sep + 'volt.dat' ) : if not check_if_needs_modeling ( tomodir ) : print ( 'no volt.dat and no modeling possible' ) needs_inversion = False inv_ctr_file = tomodir + os . sep + 'inv' + os . sep + 'inv.ctr' if os . path . isfile ( inv_ctr_file ) : inv_lines = open ( inv_ctr_file , 'r' ) . readlines ( ) print ( 'inv_lines' , inv_lines [ - 1 ] ) if inv_lines [ - 1 ] . startswith ( '***finished***' ) : needs_inversion = False return needs_inversion
check of we need to run CRTomo in a given tomodir