22"""
33BSD 3-Clause License
44
5- Copyright (c) 2023 , University of Southern California
5+ Copyright (c) 2024 , University of Southern California
66All rights reserved.
77
88Redistribution and use in source and binary forms, with or without
5050BUFFER_LATITUDE = 0.25
5151BUFFER_LONGITUDE = 0.25
5252
53- def get_srf_num_segments (srf_file ):
53+ def get_srf_num_segments (input_file ):
5454 """
55- Returns number of segments in a SRF file
55+ Returns number of segments in a SRF/MRF file
5656 """
57- srf_segments = None
57+ num_segments = None
5858
59- srf = open (srf_file , 'r' )
59+ srf = open (input_file , 'r' )
6060 for line in srf :
6161 if line .startswith ("PLANE" ):
6262 # Found the plane line, read number of segments
63- srf_segments = int (line .split ()[1 ])
63+ num_segments = int (line .split ()[1 ])
6464 break
6565 srf .close ()
6666
67- if srf_segments is None :
67+ if num_segments is None :
6868 print ("ERROR: Could not read number of segments from "
69- "SRF file: %s" % (src_file ))
69+ "input file: %s" % (input_file ))
7070 sys .exit (1 )
7171
7272 # Return number of segments
73- return srf_segments
73+ return num_segments
7474
75- def get_srf_params (srf_file , segment = 0 ):
75+ def get_srf_params (input_file , segment = 0 ):
7676 """
77- Reads fault_len, width, dlen, dwid, and azimuth from the srf_file
77+ Reads fault_len, width, dlen, dwid, and azimuth from the input_file
7878 Segment allows users to specify segment of interest (0-based)
7979 """
80- srf_params1 = None
81- srf_params2 = None
82- srf = open (srf_file , 'r' )
80+ param_line1 = None
81+ param_line2 = None
82+ srf = open (input_file , 'r' )
8383 for line in srf :
8484 if line .startswith ("PLANE" ):
8585 # Found the plane line, read number of segments
86- srf_segments = int (line .split ()[1 ])
87- if srf_segments < segment + 1 :
86+ num_segments = int (line .split ()[1 ])
87+ if num_segments < segment + 1 :
8888 print ("ERROR: Requested parameters from segment %d, "
89- " SRF file only has %d segment(s)!" %
90- (segment + 1 , srf_segments ))
89+ " SRF/MRF file only has %d segment(s)!" %
90+ (segment + 1 , num_segments ))
9191 sys .exit (1 )
9292 for _ in range (segment ):
9393 # Skip lines to get to the segment we want
9494 _ = next (srf )
9595 _ = next (srf )
9696 # The next line should have what we need
97- srf_params1 = next (srf )
98- srf_params2 = next (srf )
97+ param_line1 = next (srf )
98+ param_line2 = next (srf )
9999 break
100100 srf .close ()
101- if srf_params1 is None or srf_params2 is None :
102- print ("ERROR: Cannot determine parameters from SRF file %s" %
103- (srf_file ))
101+ if param_line1 is None or param_line2 is None :
102+ print ("ERROR: Cannot determine parameters from SRF/MRF file %s" %
103+ (input_file ))
104104 sys .exit (1 )
105- srf_params1 = srf_params1 .strip ()
106- srf_params1 = srf_params1 .split ()
107- srf_params2 = srf_params2 .strip ()
108- srf_params2 = srf_params2 .split ()
105+ param_line1 = param_line1 .strip ()
106+ param_line1 = param_line1 .split ()
107+ param_line2 = param_line2 .strip ()
108+ param_line2 = param_line2 .split ()
109109 # Make sure we have the correct number of pieces
110- if len (srf_params1 ) != 6 or len (srf_params2 ) != 5 :
111- print ("ERROR: Cannot parse params from SRF file %s" %
112- (srf_file ))
110+ if len (param_line1 ) != 6 or len (param_line2 ) != 5 :
111+ print ("ERROR: Cannot parse params from SRF/MRF file %s" %
112+ (input_file ))
113113 sys .exit (1 )
114114
115115 # Pick the parameters that we need
116116 params = {}
117- params ["lon" ] = float (srf_params1 [0 ])
118- params ["lat" ] = float (srf_params1 [1 ])
119- params ["dim_len" ] = int (srf_params1 [2 ])
120- params ["dim_wid" ] = int (srf_params1 [3 ])
121- params ["fault_len" ] = float (srf_params1 [4 ])
122- params ["fault_width" ] = float (srf_params1 [5 ])
123- params ["azimuth" ] = int (float (srf_params2 [0 ]))
117+ params ["lon" ] = float (param_line1 [0 ])
118+ params ["lat" ] = float (param_line1 [1 ])
119+ params ["dim_len" ] = int (param_line1 [2 ])
120+ params ["dim_wid" ] = int (param_line1 [3 ])
121+ params ["fault_len" ] = float (param_line1 [4 ])
122+ params ["fault_width" ] = float (param_line1 [5 ])
123+ params ["azimuth" ] = int (float (param_line2 [0 ]))
124124
125125 return params
126126
@@ -138,22 +138,23 @@ def write_simple_stations(station_file, out_file):
138138
139139def get_srf_info (srf_file ):
140140 """
141- This function reads a SRF file and returns version,
141+ This function reads a SRF/MRF file and returns version,
142142 number of segments, and a list with the nstk values
143143 for each segment
144144 """
145145 version = None
146146 num_segments = None
147147 nstk = []
148148
149- # Read SRF file
149+ # Read SRF/MRF file
150150 input_file = open (srf_file , 'r' )
151151 for line in input_file :
152152 line = line .strip ()
153153 # Skip blank lines
154154 if not line :
155155 continue
156- version = int (float (line ))
156+ # First line should contain version number
157+ version = int (float (line .split ()[0 ]))
157158 break
158159
159160 # Read number of segments
@@ -170,7 +171,7 @@ def get_srf_info(srf_file):
170171 break
171172
172173 if num_segments is None or version is None :
173- bband_utils .ParameterError ("Cannot parse SRF file!" )
174+ bband_utils .ParameterError ("Cannot parse SRF/MRF file!" )
174175
175176 # Read nstk for each segment
176177 for line in input_file :
@@ -188,13 +189,13 @@ def get_srf_info(srf_file):
188189
189190 input_file .close ()
190191 if len (nstk ) != num_segments :
191- bband_utils .ParameterError ("Cannot read nstk from SRF file!" )
192+ bband_utils .ParameterError ("Cannot read nstk from SRF/MRF file!" )
192193
193194 return version , num_segments , nstk
194195
195196def read_srf_trace (srf_file , num_segment , nstk ):
196197 """
197- This function reads an SRF file and returns the
198+ This function reads an SRF/MRF file and returns the
198199 top layer trace for the segment specified
199200 """
200201 install = InstallCfg .getInstance ()
@@ -230,12 +231,12 @@ def read_srf_trace(srf_file, num_segment, nstk):
230231
231232def write_fault_trace (srf_file , out_file ):
232233 """
233- This function reads the srf file and outputs a trace file
234+ This function reads the srf/mrf file and outputs a trace file
234235 """
235236 all_points = []
236237
237- # Figure out SRF file version
238- version , num_segments , nstk = get_srf_info (srf_file )
238+ # Figure out SRF/MRF file version
239+ version , num_segments , nstk = get_srf_info (srf_file )
239240
240241 # Reads the points for each segment
241242 for segment in range (0 , num_segments ):
@@ -413,8 +414,8 @@ def set_boundaries_from_stations(station_file, a_input_file):
413414 if a_input_file .endswith (".src" ):
414415 # Read fault information from SRC file
415416 lat1 , lon1 , _ , _ , lat2 , lon2 = calculate_fault_edges_from_src (a_input_file )
416- elif a_input_file .endswith (".srf" ):
417- # Read fault information from SRF file
417+ elif a_input_file .endswith (".srf" ) or a_input_file . endswith ( ".mrf" ) :
418+ # Read fault information from SRF/MRF file
418419 lat1 , lon1 , lat2 , lon2 = calculate_fault_edges_from_srf (a_input_file )
419420 else :
420421 bband_utils .ParameterError ("Cannot determine input_file format!" )
0 commit comments