"""parseMichellFiles.py Parses files from the Michell dewpoint hygrometer into daily files. Michell files have 13 comma-delimited columns followed by 3 status flags: 1 Date 2 Time 3 Dp 4 Temp 5 ppmV 6 ppmW 7 g/Kg 8 g/m^3 9 Pressure 10 Flow 11 RH 12 Temp. diff 13 Status raw file names are MDPyyyymmddhhmm.txt the script assumes current directory contains the raw files, and output files are written to the same directory output file names similar to PSD style but with month/day: mdp0YYMMDD_raw.txt Byron Blomquist, NOAA/ESRL/PSD, Nov 2019 """ import os import string # assume current directory contains raw DataLog_User files, # dump list of data file names into a list variable files = [f for f in os.listdir('.') if f.startswith('MDP')] files.sort() # parse data files and save into txt files DD_prior = '' first = 1 for file in files: print(file) fin = open(file) for n in range(12): # read header lines header = fin.readline() null = fin.readline() # empty line for line in fin: # read data lines sequentially cleanLine = line.strip() fields = cleanLine.split(',') if 'Mesr' in fields[12]: DD = fields[0][0:2] # day of month string MM = fields[0][3:5] YY = fields[0][6:] if DD != DD_prior: # new outp if hour changes or first file if not first: fmdp.close() else: first = 0 DD_prior = fields[0][0:2] # remember current day # open output file, new name begins with mdp0 outp = 'mdp0'+YY+MM+DD+'_raw.txt' fmdp = open(outp, 'w') # first, write header line to outp fmdp.write(header) # then write data line to outp printLine = cleanLine + '\n' # add return character fmdp.write(printLine) # write comma delimited line to output file else: # just write data line to outp printLine = cleanLine + '\n' # add return character fmdp.write(printLine) # write comma delimited line to output file fmdp.close() # end