Following is the small python script which post process all the directories inside a given directories and store values of Alpha vs CL in a file “Alpha_CL.dat”.
This is helpful when your are running some polar calculations in CFD++.
Use: script common_name_of_directories
Example: If you have AoA polar calculations with directories name as AoA00, AoA02, AoA04 and so on run the following script as:
script AoA
#!/usr/bin/python2.5
#####################################################################
## Script: Python script to post process CL values for all the ##
## cases in given directory ##
## ##
## Author: A. Khare ##
## Date: 03.03.2011 ##
## ##
#####################################################################
#Import modules
import sys, os, glob, commands
#Check for argument. If argument is not given print the use and exit
if len(sys.argv) != 2:
print "Use: get_cl prefix_for_cases"
exit(1)
wdir = os.getcwd()
#Open file for writing CL values
f = open("Alpha_CL.dat", 'w')
#Reading the prefix and finding out all the directories
list = str(sys.argv[1] + "*")
dir_list = glob.glob(list)
#Loop over all the directories and process CL
for i in dir_list:
j = wdir + '/' + i
os.chdir(j)
alpha = float(commands.getoutput("cat infout1f.inp | grep alpha | head -1 | awk \'{print $2}\'"))
cl = float(commands.getoutput("infout1f 1 | tail -21 | head -1 | awk \'{print $9}\'"))
f.write('%.2f\t%.3f\n' % (alpha, cl))
os.chdir(wdir)
f.close()
#End of script
########################################################################