"""parseHedFiles.py Parses data from Hemisphere files saved on the PSD data system. Saves PSAT lines with the following format to an output file. 0023818 $PSAT,HPR,205940.00,218.58,,1.65,N*32 source file names follow the convention: hed0yydddhh_raw.txt output file names follow the convention: hed1yydddhh_raw.txt Byron Blomquist, NOAA/ESRL/PSD3, May 2023 """ import os # assume current directory contains raw hed0 files, # dump list of data file names into a list variable files = [f for f in os.listdir('.') if f.startswith('hed0')] # parse data files and save into txt files for file in files: # open output file, new name begins with gprm outp = 'hed1'+file[4:] fhed1 = open(outp, 'w') print(file) fin = open(file) for line in fin: cleanLine = line.strip() lineOut = cleanLine + '\n' fields = cleanLine.split(',') if '$PSAT' in fields[0]: fhed1.write(lineOut) print(outp+' finished') fhed1.close() # end