From 82c5f6fc29580519c7061dd1b5af08e126bddd09 Mon Sep 17 00:00:00 2001 From: TheFGFSEagle Date: Tue, 1 Mar 2022 01:56:10 +0100 Subject: [PATCH] Now reading data from files --- aircraft/javaprop2jsbcpct.py | 45 +++++++++++++++++++++++++++++++++--- 1 file changed, 42 insertions(+), 3 deletions(-) diff --git a/aircraft/javaprop2jsbcpct.py b/aircraft/javaprop2jsbcpct.py index fb80ce4..65371f5 100755 --- a/aircraft/javaprop2jsbcpct.py +++ b/aircraft/javaprop2jsbcpct.py @@ -2,14 +2,40 @@ #-*- coding:utf-8 -*- 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__": argp = argparse.ArgumentParser(description="javaprop2jsbcpct.py - converts JavaProp propeller data into Cp and Ct tables for a JSBsim propelller") argp.add_argument( "-i", "--input-file", - help="File to read JavaProp data from", - required=True + help="Files to read JavaProp data from (one per blade angle)", + 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( @@ -25,4 +51,17 @@ if __name__ == "__main__": ) 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) +