lz在用tecplot进行科研绘图时需要进行批量作图,作为一个非典型懒人,怎么能容忍重复机械的工作呢?所以写了个代码,以后批量绘图就交给机器了

'''
Volume product streamline picture
=======================================
Template file is '6_100.lay',
the volume product files is 'Da_Re_streamline.lay'.
Before running, you should prepare '6_100.lay' and empty
'Da_Re_streamline.lay' s
---------------------------------------
Auther:
ZHOU Lin
Time:
October 9, 2021 22:27:06
Email:
11930579@mail.sustech.edu.cn
Address:
Department of Mechanics and Aerospace Engineering,
Southern University of Science and Technology,
Shenzhen 518055, China
=========================================
Copyright © 1997- ZHOU Lin. All rights reserved.
'''

lst_Da = ['2', '3', '4', '5', '6']
lst_Re = ['100', '110', '120', '130', '140', '150', '160']

for Da in lst_Da:
    for Re in lst_Re:
        filename = Da + '_' + Re + '_streamline.lay'
        with open('6_100.lay') as template:
            information = template.readlines(0)
            line1 = information[1]
            line1364 = information[1364]
            line1365 = information[1365]
            line1 = line1.replace('6_100', Da + '_' + Re)
            line1364 = line1364.replace('100', Re)
            line1365 = line1365.replace('6', Da)
            information[1] = line1
            information[1364] = line1364
            information[1365] = line1365
            with open(filename, 'w') as product:
                s = " ".join(map(str, information))
                product.write(s)
                product.close()
            template.close()
        print(Da + '_' + Re)

更多推荐