fixed readlines bug

This commit is contained in:
Beale John Henry
2025-01-19 22:43:01 +01:00
parent c5868683f6
commit 753f0665c3

View File

@@ -27,22 +27,23 @@ import os
import numpy as np
from sys import exit
def concatenate_files( input_file_lst, output, label ):
def concatenate_files( cwd, input_file_lst, output_name, label ):
output_file = "{0}_{1}.lst".format( output, label )
output_file = "{0}/{1}_{2}.lst".format( cwd, output_name, label )
lines = 0
# create output file
with open( output_file, "w" ) as output:
output = open( output_file, "w" )
# loop through input list - read and write to output file
for lst_file_pwd in input_file_lst.lst_pwd:
# loop through input list - read and write to output file
for lst_file_pwd in input_file_lst.lst_pwd:
lst_file = open( lst_file_pwd, "r" )
for line in lst_file:
lines = lines + 1
output.write( line )
# open and write to output file
with open( lst_file_pwd, "r" ) as lst_file:
lines = lines + len( lst_file.readlines() )
output.write( lst_file.read() )
lst_file.close()
lst_file.close()
output.close()
@@ -127,7 +128,7 @@ def generate_lst_df( run_lst, endstation, label, pgroup, jfj ):
return lst_df
def main( run_lst, endstation, label, pgroup, output_file, jfj ):
def main( cwd, run_lst, endstation, label, pgroup, output_file, jfj ):
# make df of lst files
lst_df = generate_lst_df( run_lst, endstation, label, pgroup, jfj )
@@ -138,7 +139,7 @@ def main( run_lst, endstation, label, pgroup, output_file, jfj ):
exit()
# concatinate all lst file in lst_df
concatenate_files( lst_df, output_file, label )
concatenate_files( cwd, lst_df, output_file, label )
def range_of_runs(arg):
return list(map(int, arg.split(',')))
@@ -192,6 +193,8 @@ if __name__ == "__main__":
default=None
)
args = parser.parse_args()
# run geom converter
cwd = os.getcwd()
# JFJ on/off non-JFJ light/dark logic\
if args.label != "off" and args.label != "on" and args.label != "light" and args.label != "dark":
print( "label flag (-l) must = either 'on' or 'off' with JFJ = True, or 'light' or 'dark' and JFJ = False." )
@@ -218,10 +221,9 @@ if __name__ == "__main__":
print( "appending {0} lst files from runs {1}".format( args.label, run_lst ) )
# make default name
if not args.output:
output_name = "-".join( str(e) for e in run_lst )
output_name = "run{0}".format( output_name )
run_number = "-".join( str(e) for e in run_lst )
output_name = "run{0}".format( run_number.zfill(4) )
else:
output_name = args.output
# run main
main( run_lst, args.endstation, args.label, args.pgroup, output_name, args.jfj )
print( "done" )
main( cwd, run_lst, args.endstation, args.label, args.pgroup, output_name, args.jfj )