Skip to content

Instantly share code, notes, and snippets.

@TaylorMutch
Last active November 3, 2015 16:38
Show Gist options
  • Save TaylorMutch/1c8d06ddb44830116964 to your computer and use it in GitHub Desktop.
Save TaylorMutch/1c8d06ddb44830116964 to your computer and use it in GitHub Desktop.
Scans a directory and returns a list of SODAR files that are corrupt (I.e. averaging the data was not done correctly when outputted)
import os
import sys
date_tag = 'SDR'
def main():
if len(sys.argv) < 2:
print('Usage: sdr_file_test.py sodar/path/dir/')
sys.exit(-1)
sdr_dir = sys.argv[1]
if not os.path.exists(sdr_dir):
print('Not a valid directory')
sys.exit(-1)
sdr_dir_list = os.listdir(sdr_dir)
# Filter files without .sdr extension
sdr_files = []
for file in sdr_dir_list:
path = os.path.join(sdr_dir, file)
file_ext = os.path.splitext(path)[1]
if file_ext == '.sdr':
sdr_files.append(path)
# Now we want to go and find some bad files.
print('Checking directory...')
bad_files = []
for file in sdr_files:
with open(file,'r') as f_in:
data = f_in.readlines()
f_in.close()
numLines = len(data)
print('Checking ' + file)
for i in range(0,numLines):
line = data[i]
tag = line[:3]
if tag == date_tag:
try:
time = int(line[4:16])
if time % 500 != 0:
bad_files.append(file + ', line ' + str(i))
break;
except:
bad_files.append(file + ', Syntax Error')
break;
#print(time)
if len(bad_files) == 0:
print('No Bad Files Found')
else:
print('Bad Files Found:')
print('\n'.join(bad_files))
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment