Now reading data from files

This commit is contained in:
TheFGFSEagle 2022-03-01 01:56:10 +01:00
parent f370f966b3
commit 82c5f6fc29

View File

@ -2,14 +2,40 @@
#-*- coding:utf-8 -*- #-*- coding:utf-8 -*-
import argparse import argparse
import os
def parse_data_files(input_files, blade_angles):
blade_angles = list(map(float, blade_angles))
data = {}
for file, angle in zip(input_files, blade_angles):
with open(file) as f:
content = f.readlines()
content = list(map(lambda s: s.strip().split("\t"), content))[2:]
data[angle] = {}
for line in content:
data[angle][float(line[0])] = {"Ct": float(line[2]), "Cp": float(line[3])}
return data
if __name__ == "__main__": if __name__ == "__main__":
argp = argparse.ArgumentParser(description="javaprop2jsbcpct.py - converts JavaProp propeller data into Cp and Ct tables for a JSBsim propelller") argp = argparse.ArgumentParser(description="javaprop2jsbcpct.py - converts JavaProp propeller data into Cp and Ct tables for a JSBsim propelller")
argp.add_argument( argp.add_argument(
"-i", "--input-file", "-i", "--input-file",
help="File to read JavaProp data from", help="Files to read JavaProp data from (one per blade angle)",
required=True required=True,
nargs="+",
dest="input_files"
)
argp.add_argument(
"-b", "--blade-angle",
help="Blade angles of the JavaProp data files (one per file)",
required=True,
nargs="+",
dest="blade_angles"
) )
argp.add_argument( argp.add_argument(
@ -25,4 +51,17 @@ if __name__ == "__main__":
) )
args = argp.parse_args() args = argp.parse_args()
print(args)
for path in args.input_files:
if not os.path.isfile(path):
print(f"Error: input file {path} not found, exiting")
sys.exit(1)
if len(args.blade_angles) < len(args.input_files):
print("Error: less blade angles than input files")
elif len(args.blade_angles) > len(args.input_files):
args.blade_angles, rest = args.blade_angles[:len(args.input_files)]
print(f"Warning: skipping {len(rest)} blade angles because no corresponding data file was specified")
data = parse_data_files(args.input_files, args.blade_angles)