create_disp_dat.py 文件源码

python
阅读 29 收藏 0 点赞 0 评论 0

项目:fem 作者: mlp6 项目源码 文件源码
def count_timesteps(outfile):
    """count timesteps written to nodout

    searches for 'time' in lines, and then removes 1 extra entry that occurs
    for t = 0

    grep will be used on linux systems (way faster)

    :param outfile: usually 'nodout'
    :returns: int ts_count

    """
    from sys import platform

    print("Reading number of time steps... ", end="", flush=True)
    if platform == "linux":
        from subprocess import PIPE, Popen
        p = Popen('grep time %s | wc -l' % outfile, shell=True, stdout=PIPE)
        ts_count = int(p.communicate()[0].strip().decode())
    else:
        print("Non-linux OS detected -> using slower python implementation",
              flush=True)
        ts_count = 0
        with open(outfile, 'r') as f:
            for line in f:
                if 'time' in line:
                    ts_count += 1

    ts_count -= 1  # rm extra time count

    print('there are {}.'.format(ts_count), flush=True)

    return ts_count
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号