Skip to content

Instantly share code, notes, and snippets.

@sean0921
Last active December 1, 2020 08:11
Show Gist options
  • Save sean0921/3d503922438887f0472badde9c6d4a1d to your computer and use it in GitHub Desktop.
Save sean0921/3d503922438887f0472badde9c6d4a1d to your computer and use it in GitHub Desktop.
Acadmia Sinica IESWS pzfile (SACPZ) format to ISOLA pzfile format trans script (output is stdout)
#!/usr/bin/env python3
import sys
import re
if __name__ == '__main__':
if len(sys.argv) == 2:
file_open_session = open(sys.argv[1])
file_content = file_open_session.read()
file_content_list = file_content.split(sep='\n')
for i in enumerate(file_content_list,0):
if re.findall('A0',i[1]):
a0_location = i[0]
a0_value = i[1].split(sep=' : ')[1]
if re.findall('SENSITIVITY',i[1]):
sensitivity_location = i[0]
sensitivity_value_reciprocal_string = i[1].split(sep=' : ')[1]
sensitivity_value_reciprocal = float(sensitivity_value_reciprocal_string.split(sep=' ')[0])
sensitivity_value = 1 / sensitivity_value_reciprocal
if re.findall('ZEROS',i[1]):
zeroes_header_location = i[0]
zeroes_how_many_string = i[1].split(sep='\t')[1]
zeroes_how_many = int(zeroes_how_many_string)
if re.findall('POLES',i[1]):
poles_header_location = i[0]
poles_how_many_string = i[1].split(sep='\t')[1]
poles_how_many = int(poles_how_many_string)
print("A0")
print(a0_value)
print("count-->m/sec")
print(sensitivity_value)
print("zeroes")
print(zeroes_how_many-1)
for i in enumerate(file_content_list[zeroes_header_location+2:zeroes_header_location+1+zeroes_how_many],0):
print('\t'.join(i[1].split(sep='\t')[1:]))
print("poles")
print(poles_how_many)
for i in enumerate(file_content_list[poles_header_location+1:poles_header_location+1+poles_how_many],0):
print('\t'.join(i[1].split(sep='\t')[1:]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment